npm.io
0.1.0 • Published 2 weeks ago

@polotno/html-export

Licence
SEE LICENSE IN LICENSE.md
Version
0.1.0
Deps
2
Size
44 kB
Vulns
0
Weekly
0

@polotno/html-export

Export Polotno designs to HTML.

Usage

import { jsonToHTML } from '@polotno/html-export';

const html = await jsonToHTML(store.toJSON());

jsonToHTML accepts plain design JSON — no editor or store required. Options:

  • elementHook({ dom, element }) — post-process each element's virtual node.
  • textOverflow'change-font-size' (default) | 'resize' | 'ellipsis'; what happens when text is taller than its box. The default shrinks the font to fit — the same default polotno-node exports use (shrinking needs a live DOM for measurement; under jsdom it is a no-op). store.toHTML() forwards the live editor flag ('resize' by default) instead.
  • textSplitAllowedboolean, default false; whether shrink-to-fit measurement may wrap a long word mid-word. By default a word wider than the box shrinks the font instead of splitting. Mirrors the editor's setTextSplitAllowed flag (forwarded automatically by store.toHTML()).

Node

The exporter is browser-first and needs a DOM. In Node, run it under jsdom — the same setup this package's own test suite uses. Per-line text backgrounds need real Range.getClientRects measurement and fall back to a legacy overlay under jsdom; for full-fidelity rendering in Node use polotno-node.