src/render/document.browser.ts
17 lines and 1 functions in DrDustinEdwards/enarratio, at commit 4c5695a on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| createDocument | 8 to 17 | 2 | 0% | WatchCRAP 6 | Critical0% |
Imports
It imports no other module of this repo. No module of this repo imports it.
Source
/**
* The browser's own document for Observable Plot to draw into, where a real one exists. Chosen
* by the `browser` condition of the `#document` import in package.json, which drops linkedom
* from client bundles. Runtimes that set that condition without having a document (some Worker
* bundlers do) are listed before it in package.json and get the server version; if one slips
* through, this says so rather than failing inside Plot.
*/
export function createDocument(): Document {
const real = (globalThis as { document?: Document }).document;
if (!real?.implementation) {
throw new Error(
"Enarratio's browser build needs a document, and this runtime has none. Bundle for the server " +
"(without the 'browser' condition) so Enarratio can use linkedom.",
);
}
return real.implementation.createHTMLDocument("");
}