/** * Injectable platform seam for the handful of DOM factories the Tier-2 * modules need (parse/serialize/create — never layout or measurement). * * - In the browser (and under jsdom) the defaults below read the globals * lazily, so importing @polotno/core in plain Node never crashes. * - Node consumers that don't want global DOM shims (pdf-export/pptx-export * run on linkedom) call `setPlatform(...)` once at their entry point. * - This is module-level state by design: one process, one platform — the * same contract Konva uses for its environment config. Implementations * must handle every mime they may be asked for at DOCUMENT level (core * wraps fragments itself — see parseHtmlDocument); pdf-export routes * text/html to linkedom and XML to xmldom, so co-imported exporters stay * functional regardless of import order. * * Layout-dependent modules (measure-html.ts, text-html.ts) intentionally do * NOT go through this seam: no DOM polyfill implements real layout, so they * require a browser (or a jsdom environment that accepts their fallbacks). * * ## The portable subset — what a node parsed here is allowed to have * * A browser DOM is the superset, so code written against it compiles, passes in * the editor, and then does NOTHING in an export. Each of these was a shipped * bug, none of them threw where it was written: * * - **`element.style`** — absent on xmldom. Read and write the `style` * ATTRIBUTE (`./style-attribute.ts`). * - **`getElementsByTagName('*')`** — returns an EMPTY list on linkedom. Walk * `childNodes`. * - **`querySelector` / `querySelectorAll`** — absent on xmldom. Use * `getElementsByTagName`. * - **`ownerSVGElement`, `parentElement`, `children`** and the rest of the * convenience accessors — absent or partial. Walk `parentNode` / `childNodes`. * * `getElementsByTagName(name)`, `getElementById`, `getAttribute`, * `setAttribute`, `createElementNS`, `insertBefore` and `cloneNode` are safe on * all three. * Adding to this list is cheaper than finding instance five. */ export interface PlatformDOMParser { parseFromString(source: string, mimeType: string): any; } export interface PlatformXMLSerializer { serializeToString(node: any): string; } export interface CorePlatform { createDOMParser(): PlatformDOMParser; createXMLSerializer(): PlatformXMLSerializer; /** Used for 'img' | 'canvas' | 'video' elements. */ createElement(tagName: string): any; } export declare function setPlatform(overrides: Partial): void; export declare const platform: CorePlatform; /** * Parse an HTML FRAGMENT into a full Document. The fragment is wrapped in a * document skeleton here, once: native DOMParser handles bare fragments, but * linkedom (the Node exporters' parser) does no fragment tree-construction — * a bare '

a

' would yield an empty body. Platform implementations * therefore only ever need document-level text/html parsing. */ export declare function parseHtmlDocument(html: string): any;