@pairdraw/dom-css 0.21.1 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/behaviours/states/layers.js +78 -12
- package/dist/chunks/behaviours/states/layers.js.map +1 -1
- package/dist/chunks/browser.js +373 -37
- package/dist/chunks/browser.js.map +1 -1
- package/dist/chunks/import/html.js +66 -11
- package/dist/chunks/import/html.js.map +1 -1
- package/dist/chunks/import/jsx/source/ast.js +207 -0
- package/dist/chunks/import/jsx/source/ast.js.map +1 -0
- package/dist/chunks/import/jsx/source/candidates.js +74 -0
- package/dist/chunks/import/jsx/source/candidates.js.map +1 -0
- package/dist/chunks/import/jsx/source/evaluate.js +213 -0
- package/dist/chunks/import/jsx/source/evaluate.js.map +1 -0
- package/dist/chunks/import/jsx/source/index.js +448 -0
- package/dist/chunks/import/jsx/source/index.js.map +1 -0
- package/dist/export.d.ts +15 -2
- package/dist/export.js +2 -2
- package/dist/index.d.ts +66 -1
- package/dist/index.js +5 -2
- package/package.json +5 -3
- package/src/cssom/browser.ts +63 -0
- package/src/export/css.ts +28 -1
- package/src/export/index.ts +1 -0
- package/src/export/projection.ts +69 -10
- package/src/import/flow.ts +127 -6
- package/src/import/jsx/source/ast.ts +267 -0
- package/src/import/jsx/source/candidates.ts +72 -0
- package/src/import/jsx/source/evaluate.ts +300 -0
- package/src/import/jsx/source/index.ts +36 -0
- package/src/import/jsx/source/render.ts +543 -0
- package/src/import/jsx/source/report.ts +49 -0
- package/src/import/scene-graph.ts +19 -7
- package/src/index.ts +10 -0
- package/src/runtime/browser/runtime.ts +13 -5
- package/src/runtime/browser/sandbox.ts +176 -27
- package/src/runtime/css/scan.ts +45 -0
- package/src/runtime/css/url.ts +92 -0
- package/src/runtime/headless/styles.ts +71 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","names":["resolveBrowserDocument","bytesFromDataURL"],"sources":["../../src/runtime/browser/sandbox.ts","../../src/runtime/browser/runtime.ts","../../src/import/css-values.ts","../../src/import/flow.ts","../../src/import/css-text.ts","../../src/import/background-pictures.ts","../../src/import/fonts.ts","../../src/import/stacking.ts","../../src/import/text.ts","../../src/import/scene-graph.ts","../../src/import/jsx/core.ts","../../src/browser.ts"],"sourcesContent":["import type { DesignDocument, DesignElement, DesignNode } from '#dom-css/types'\n\n/**\n * What a styling sandbox inserts, with nothing the browser would execute: imported markup reaches\n * the frame as a design document, and an attribute such as `onerror` on an image runs there just as\n * it would on a page. A sandboxed iframe has no `allow-scripts`, so a script that got in is blocked\n * and reported; the shadow root is the app's own document, where it would really run.\n *\n * This is the executable-markup half of the sandbox copy. The network half, which rewrites fetchable\n * addresses so a sandbox never loads a remote resource, walks the same tree: when both are present\n * they are one pass over the nodes, and no pass may keep a `srcdoc`, which this one always drops.\n */\n\n/** Elements that hold a document or code of their own, which the sandbox shows as a plain box. */\nconst CODE_TAGS: ReadonlySet<string> = new Set(['script', 'style'])\n\n/** Elements that load another document; their fallback content stays, the element does not. */\nconst EMBEDDED_TAGS: ReadonlySet<string> = new Set([\n 'applet',\n 'embed',\n 'frame',\n 'frameset',\n 'iframe',\n 'object'\n])\n\n/**\n * `value` without the characters a browser ignores inside a URL scheme: controls and space, so\n * `java\\tscript:` runs as `javascript:`.\n */\nfunction withoutSchemeNoise(value: string): string {\n let plain = ''\n for (const char of value) if (char.charCodeAt(0) > 0x20) plain += char\n return plain\n}\n\n/** A URL a browser runs as script or reads as a document of its own. */\nconst EXECUTABLE_URL = /^(?:javascript|vbscript|data:text\\/html)/i\n\n/** Whether the browser would run this attribute: an event handler or an executable URL. */\nfunction executableAttribute(name: string, value: string): boolean {\n const attribute = name.toLowerCase()\n if (attribute.startsWith('on') || attribute === 'srcdoc') return true\n return EXECUTABLE_URL.test(withoutSchemeNoise(value))\n}\n\nfunction sandboxedNode(node: DesignNode): DesignNode {\n if (node.type === 'text') return node\n const tagName = node.tagName.toLowerCase()\n const attrs = Object.fromEntries(\n Object.entries(node.attrs).filter(([name, value]) => !executableAttribute(name, value))\n )\n const element: DesignElement = {\n ...node,\n tagName: CODE_TAGS.has(tagName) || EMBEDDED_TAGS.has(tagName) ? 'div' : node.tagName,\n attrs,\n children: CODE_TAGS.has(tagName) ? [] : node.children.map(sandboxedNode)\n }\n return element\n}\n\n/**\n * `document` as the styling sandbox inserts it: the same layers, with every executable attribute,\n * embedded document, and code element replaced by something inert. A replaced element keeps the\n * attributes that decide its box where the browser draws one; a layer's own styles still come from\n * the captured stylesheet, so reading computed styles answers the same question.\n */\nexport function sandboxedDesignDocument(document: DesignDocument): DesignDocument {\n return { ...document, children: document.children.map(sandboxedNode) }\n}\n","import { serializeHTML } from '#dom-css/export/html'\nimport type {\n CSSComputeOptions,\n CSSRuntime,\n DesignDocument,\n DesignElement,\n DesignNode\n} from '#dom-css/types'\n\nimport { sandboxedDesignDocument } from './sandbox'\n\nexport interface BrowserCSSRuntimeOptions {\n document?: Document\n sandbox?: 'shadow-root' | 'iframe'\n}\n\nconst DEFAULT_COMPUTED_PROPERTIES = [\n 'align-items',\n 'aspect-ratio',\n 'background-color',\n 'background-clip',\n 'background-image',\n 'background-origin',\n 'border-bottom-color',\n 'border-bottom-style',\n 'border-bottom-left-radius',\n 'border-bottom-right-radius',\n 'border-bottom-width',\n 'border-left-color',\n 'border-left-style',\n 'border-left-width',\n 'border-radius',\n 'border-right-color',\n 'border-right-style',\n 'border-right-width',\n 'border-top-color',\n 'border-top-style',\n 'border-top-left-radius',\n 'border-top-right-radius',\n 'border-top-width',\n 'box-shadow',\n 'box-sizing',\n 'color',\n 'column-gap',\n 'display',\n 'align-self',\n 'bottom',\n 'flex-direction',\n 'flex-wrap',\n 'font-family',\n 'font-size',\n 'font-style',\n 'font-weight',\n 'gap',\n 'height',\n 'justify-content',\n 'letter-spacing',\n 'left',\n 'line-height',\n 'max-height',\n 'max-width',\n 'min-height',\n 'isolation',\n 'min-width',\n 'object-fit',\n 'opacity',\n 'overflow',\n 'padding-bottom',\n 'padding-left',\n 'padding-right',\n 'padding-top',\n 'position',\n 'right',\n 'row-gap',\n 'text-align',\n 'text-decoration-line',\n 'text-shadow',\n 'text-transform',\n 'top',\n 'white-space',\n 'width',\n 'z-index'\n] as const\n\nfunction resolveBrowserDocument(documentOverride: Document | undefined): Document {\n if (documentOverride) return documentOverride\n if (typeof document === 'undefined') {\n throw new TypeError('Browser CSS runtime requires a DOM document')\n }\n return document\n}\n\nfunction attributesToRecord(element: Element): Record<string, string> {\n const attrs: Record<string, string> = {}\n for (const attr of Array.from(element.attributes)) {\n // Event handlers draw nothing, and the styled copy of the markup must not run them.\n if (attr.name.toLowerCase().startsWith('on')) continue\n attrs[attr.name] = attr.value\n }\n return attrs\n}\n\nfunction styleToRecord(style: CSSStyleDeclaration): Record<string, string> | undefined {\n const entries: Record<string, string> = {}\n for (const property of Array.from(style)) {\n const value = style.getPropertyValue(property)\n if (value) entries[property] = value\n }\n return Object.keys(entries).length > 0 ? entries : undefined\n}\n\nconst NON_RENDERED_TAGS = new Set(['head', 'link', 'meta', 'script', 'style', 'template', 'title'])\n\nfunction domNodeToDesignNode(node: Node): DesignNode | null {\n if (node.nodeType === 3) {\n const text = node.textContent ?? ''\n return text.length > 0 ? { type: 'text', text } : null\n }\n\n if (node.nodeType !== 1) return null\n\n const element = node as Element\n if (NON_RENDERED_TAGS.has(element.tagName.toLowerCase())) return null\n const children = Array.from(element.childNodes)\n .map(domNodeToDesignNode)\n .filter((child): child is DesignNode => child !== null)\n const style = 'style' in element ? (element.style as CSSStyleDeclaration) : undefined\n\n return {\n type: 'element',\n tagName: element.tagName.toLowerCase(),\n attrs: attributesToRecord(element),\n children,\n inlineStyle: style ? styleToRecord(style) : undefined\n }\n}\n\nfunction parseHTMLWithDocument(browserDocument: Document, html: string): DesignDocument {\n const Parser = browserDocument.defaultView?.DOMParser\n if (!Parser) throw new TypeError('Browser CSS runtime requires DOMParser')\n const parser = new Parser()\n const parsed = parser.parseFromString(html, 'text/html')\n return {\n type: 'document',\n children: Array.from(parsed.body.childNodes)\n .map(domNodeToDesignNode)\n .filter((node): node is DesignNode => node !== null)\n }\n}\n\nfunction collectElementPairs(\n designNode: DesignNode,\n domNode: Node,\n pairs: [DesignElement, Element][]\n): void {\n if (designNode.type === 'text') return\n const view = domNode.ownerDocument?.defaultView\n if (!view || !(domNode instanceof view.Element)) return\n\n pairs.push([designNode, domNode])\n\n const elementChildren = designNode.children.filter(\n (child): child is DesignElement => child.type === 'element'\n )\n const domChildren = Array.from(domNode.children)\n for (const [index, child] of elementChildren.entries()) {\n const domChild = domChildren.at(index)\n if (domChild) collectElementPairs(child, domChild, pairs)\n }\n}\n\nfunction computedStyleToRecord(\n style: CSSStyleDeclaration,\n options: CSSComputeOptions\n): Record<string, string> {\n const entries: Record<string, string> = {}\n const properties = options.includeBrowserDefaults\n ? Array.from(style)\n : DEFAULT_COMPUTED_PROPERTIES\n\n for (const property of properties) {\n const value = style.getPropertyValue(property)\n if (value) entries[property] = value\n }\n\n return entries\n}\n\nfunction requestFrame(browserDocument: Document): Promise<void> {\n const requestAnimationFrame = browserDocument.defaultView?.requestAnimationFrame\n if (!requestAnimationFrame) return Promise.resolve()\n return new Promise((resolve) => {\n requestAnimationFrame(() => resolve())\n })\n}\n\nfunction applySandboxHostStyle(element: HTMLElement): void {\n element.style.cssText = [\n 'position: fixed',\n 'left: -100000px',\n 'top: 0',\n 'width: 1000px',\n 'height: auto',\n 'visibility: hidden',\n 'pointer-events: none',\n 'contain: layout style paint'\n ].join(';')\n}\n\nasync function computeStylesInShadowRoot(\n browserDocument: Document,\n designDocument: DesignDocument,\n cssText: string,\n options: CSSComputeOptions\n): Promise<DesignDocument> {\n const host = browserDocument.createElement('div')\n applySandboxHostStyle(host)\n\n const shadow = host.attachShadow({ mode: 'open' })\n const style = browserDocument.createElement('style')\n style.textContent = cssText\n shadow.append(style)\n\n const content = browserDocument.createElement('div')\n content.innerHTML = serializeHTML(sandboxedDesignDocument(designDocument))\n shadow.append(content)\n browserDocument.body.append(host)\n\n try {\n await requestFrame(browserDocument)\n return copyComputedStyles(designDocument, content, options)\n } finally {\n host.remove()\n }\n}\n\nasync function computeStylesInIframe(\n browserDocument: Document,\n designDocument: DesignDocument,\n cssText: string,\n options: CSSComputeOptions\n): Promise<DesignDocument> {\n const iframe = browserDocument.createElement('iframe')\n applySandboxHostStyle(iframe)\n // Same origin so its styles can be read, without scripts so imported markup never runs.\n iframe.setAttribute('sandbox', 'allow-same-origin')\n browserDocument.body.append(iframe)\n\n try {\n const iframeDocument = iframe.contentDocument\n if (!iframeDocument) throw new TypeError('Browser CSS runtime could not create iframe document')\n iframeDocument.open()\n iframeDocument.write(`<!doctype html><html><head></head><body></body></html>`)\n iframeDocument.close()\n\n const style = iframeDocument.createElement('style')\n style.textContent = cssText\n iframeDocument.head.append(style)\n\n const content = iframeDocument.createElement('div')\n content.innerHTML = serializeHTML(sandboxedDesignDocument(designDocument))\n iframeDocument.body.append(content)\n\n // The sandbox sits offscreen, where WebKit never runs an animation frame of its own; the\n // page's frame lays the iframe out too, and the page is visible whenever a person pastes.\n await requestFrame(browserDocument)\n return copyComputedStyles(designDocument, content, options)\n } finally {\n iframe.remove()\n }\n}\n\nfunction copyComputedStyles(\n designDocument: DesignDocument,\n content: Element,\n options: CSSComputeOptions\n): DesignDocument {\n const view = content.ownerDocument.defaultView\n if (!view) throw new TypeError('Browser CSS runtime requires getComputedStyle')\n\n const nextDocument = structuredClone(designDocument)\n const pairs: [DesignElement, Element][] = []\n const domChildren = Array.from(content.childNodes)\n for (const [index, child] of nextDocument.children.entries()) {\n const domChild = domChildren.at(index)\n if (domChild) collectElementPairs(child, domChild, pairs)\n }\n\n for (const [designElement, domElement] of pairs) {\n designElement.computedStyle = computedStyleToRecord(view.getComputedStyle(domElement), options)\n }\n\n return nextDocument\n}\n\nexport function createBrowserCSSRuntime(options: BrowserCSSRuntimeOptions = {}): CSSRuntime {\n const browserDocument = resolveBrowserDocument(options.document)\n const sandbox = options.sandbox ?? 'shadow-root'\n\n return {\n kind: 'browser',\n parseHTML: (html) => parseHTMLWithDocument(browserDocument, html),\n serializeHTML,\n computeStyles: (designDocument, cssText = '', computeOptions = {}) =>\n sandbox === 'iframe'\n ? computeStylesInIframe(browserDocument, designDocument, cssText, computeOptions)\n : computeStylesInShadowRoot(browserDocument, designDocument, cssText, computeOptions)\n }\n}\n","import type { Fill, Stroke } from '@pairdraw/scene-graph'\nimport { parseCSSColor, parseCSSNumber } from '@pairdraw/scene-graph/css'\n\nimport type { DesignStyleDeclaration } from '../types'\n\nexport function colorToFillFromCSS(value: string | undefined): Fill[] {\n const color = parseCSSColor(value)\n if (!color) return []\n return [{ type: 'SOLID', color, opacity: color.a, visible: true }]\n}\n\nexport function colorToStrokeFromCSS(\n colorValue: string | undefined,\n weightValue: string | undefined\n): Stroke[] {\n const color = parseCSSColor(colorValue)\n const weight = parseCSSNumber(weightValue)\n if (!color || weight === null || weight <= 0) return []\n return [{ type: 'SOLID', color, weight, opacity: color.a, visible: true, align: 'INSIDE' }]\n}\n\nexport function pickStyle(elementStyle: DesignStyleDeclaration | undefined, property: string) {\n return elementStyle?.[property]\n}\n\nexport function mergedStyle(node: {\n inlineStyle?: DesignStyleDeclaration\n computedStyle?: DesignStyleDeclaration\n}) {\n return { ...node.inlineStyle, ...node.computedStyle }\n}\n","import { pick } from 'es-toolkit'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport {\n parseCSSAlignItems,\n parseCSSFlexDirection,\n parseCSSJustifyContent,\n parseCSSNumber\n} from '@pairdraw/scene-graph/css'\nimport {\n autoLayoutSizingFields,\n fillSizingFields,\n layoutSizing,\n textAutoResizeFor\n} from '@pairdraw/scene-graph/layout'\n\nimport type { DesignElement, DesignStyleDeclaration } from '../types'\nimport { pickStyle } from './css-values'\n\n/**\n * How CSS lays an element and its children out, mapped onto auto layout: block flow stacks\n * children vertically and stretches block-level ones across, a flex container is a stack in its\n * direction that stretches items across by default, and inline-level content hugs.\n */\nexport type FlowKind = 'block' | 'flex' | 'inline'\n\n/** The layout a child is placed in: its parent's flow, or none at the top of the page. */\nexport type ParentFlow = FlowKind | 'none'\n\n/** Tags browsers lay out in a line by default. */\nexport const INLINE_TAGS = new Set([\n 'a',\n 'abbr',\n 'b',\n 'code',\n 'del',\n 'em',\n 'i',\n 'ins',\n 'kbd',\n 'label',\n 'mark',\n 's',\n 'small',\n 'span',\n 'strong',\n 'sub',\n 'sup',\n 'u'\n])\nconst INLINE_BLOCK_TAGS = new Set(['button', 'img', 'input', 'select', 'textarea'])\n/** Elements browsers center their text in by default. */\nconst CENTERED_TAGS = new Set(['button'])\n\n/** What a run of text takes from its element: the properties CSS inherits, and decoration. */\nconst TEXT_PROPERTIES = [\n 'color',\n 'font-family',\n 'font-size',\n 'font-style',\n 'font-weight',\n 'letter-spacing',\n 'line-height',\n 'text-align',\n 'text-decoration-line',\n 'text-shadow',\n 'text-transform',\n 'white-space'\n]\n\n/**\n * The style a run of text directly inside an element takes from it. The element's own box,\n * position, and opacity stay on the element, so the text is neither placed nor faded twice.\n */\nexport function inheritedTextStyle(\n element: DesignElement,\n style: DesignStyleDeclaration\n): DesignStyleDeclaration {\n const inherited = pick(style, TEXT_PROPERTIES)\n if (!inherited['text-align'] && CENTERED_TAGS.has(element.tagName.toLowerCase())) {\n inherited['text-align'] = 'center'\n }\n return inherited\n}\n\n/** The element's `display`, or the one browsers give its tag by default. */\nexport function elementDisplay(element: DesignElement, style: DesignStyleDeclaration): string {\n const display = pickStyle(style, 'display')?.trim().toLowerCase()\n if (display) return display\n const tag = element.tagName.toLowerCase()\n if (INLINE_TAGS.has(tag)) return 'inline'\n return INLINE_BLOCK_TAGS.has(tag) ? 'inline-block' : 'block'\n}\n\n/**\n * The flow an element lays its own children out in. An `inline-block` sits in a line but holds\n * a block of its own, so only a plain `inline` element lays its children out in a line.\n */\nexport function flowOf(display: string): FlowKind {\n if (display === 'flex' || display === 'inline-flex') return 'flex'\n return display === 'inline' ? 'inline' : 'block'\n}\n\n/** Whether the element sits in a line rather than on its own row, so it hugs its content. */\nfunction isInlineLevel(display: string): boolean {\n return display.startsWith('inline')\n}\n\nfunction textAlignAxis(element: DesignElement, style: DesignStyleDeclaration) {\n const align = pickStyle(style, 'text-align')?.trim().toLowerCase()\n if (align === 'center') return 'CENTER'\n if (align === 'right' || align === 'end') return 'MAX'\n if (align) return 'MIN'\n return CENTERED_TAGS.has(element.tagName.toLowerCase()) ? 'CENTER' : 'MIN'\n}\n\n/** The auto layout an element's own flow gives its children. */\nexport function applyContainerLayout(\n node: SceneNode,\n element: DesignElement,\n style: DesignStyleDeclaration,\n flow: FlowKind\n): void {\n if (flow === 'flex') {\n node.layoutMode = parseCSSFlexDirection(pickStyle(style, 'flex-direction')) ?? 'HORIZONTAL'\n node.primaryAxisAlign = parseCSSJustifyContent(pickStyle(style, 'justify-content')) ?? 'MIN'\n // Flex items stretch across the container unless `align-items` says otherwise.\n node.counterAxisAlign = parseCSSAlignItems(pickStyle(style, 'align-items')) ?? 'STRETCH'\n node.layoutWrap = pickStyle(style, 'flex-wrap') === 'wrap' ? 'WRAP' : 'NO_WRAP'\n return\n }\n if (flow === 'block') {\n node.layoutMode = 'VERTICAL'\n // Browsers center a button's content both ways.\n if (CENTERED_TAGS.has(element.tagName.toLowerCase())) {\n node.primaryAxisAlign = 'CENTER'\n node.counterAxisAlign = 'CENTER'\n }\n return\n }\n // Inline content runs in a line, aligned by `text-align`.\n node.layoutMode = 'HORIZONTAL'\n node.primaryAxisAlign = textAlignAxis(element, style)\n node.counterAxisAlign = 'CENTER'\n}\n\nfunction grows(style: DesignStyleDeclaration): boolean {\n const grow = parseCSSNumber(pickStyle(style, 'flex-grow'))\n if (grow !== null) return grow > 0\n const flex = pickStyle(style, 'flex')?.trim().split(/\\s+/)[0]\n if (flex === 'auto') return true\n const shorthand = parseCSSNumber(flex)\n return shorthand !== null && shorthand > 0\n}\n\nfunction isFullSize(style: DesignStyleDeclaration, property: 'width' | 'height'): boolean {\n return pickStyle(style, property)?.trim() === '100%'\n}\n\ninterface BoxSize {\n fixedWidth: boolean\n fixedHeight: boolean\n}\n\n/** Fill from the parent's flow: block children across, growing items along, `100%` either way. */\nfunction applyParentFill(\n graph: SceneGraph,\n node: SceneNode,\n style: DesignStyleDeclaration,\n display: string,\n parentFlow: ParentFlow,\n { fixedWidth, fixedHeight }: BoxSize\n): void {\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const parentLayout = parent?.layoutMode ?? 'NONE'\n if (!parent || parentLayout === 'NONE' || node.layoutPositioning === 'ABSOLUTE') return\n const fill = (axis: 'HORIZONTAL' | 'VERTICAL') =>\n Object.assign(node, fillSizingFields(parentLayout, axis))\n const mainAxis = parentLayout === 'VERTICAL' ? 'VERTICAL' : 'HORIZONTAL'\n // A box sized to its content, as an inline-block, a flex item, or an absolute box is, has no\n // width of its own for block children to fill; they size it instead.\n const block = parentFlow === 'block' && !isInlineLevel(display) && !fixedWidth\n if (block && hasDefiniteWidth(graph, parent)) fill('HORIZONTAL')\n if (parentFlow === 'flex' && grows(style)) fill(mainAxis)\n if (isFullSize(style, 'width')) fill('HORIZONTAL')\n if (isFullSize(style, 'height')) fill('VERTICAL')\n if (parentFlow === 'flex') keepFixedCrossSize(node, parent, mainAxis, { fixedWidth, fixedHeight })\n}\n\n/** An item with its own cross size keeps it in a stretching flex container, as in CSS. */\nfunction keepFixedCrossSize(\n node: SceneNode,\n parent: SceneNode,\n mainAxis: 'HORIZONTAL' | 'VERTICAL',\n { fixedWidth, fixedHeight }: BoxSize\n): void {\n const crossFixed = mainAxis === 'VERTICAL' ? fixedWidth : fixedHeight\n const inheritsStretch = node.layoutAlignSelf === 'AUTO' && parent.counterAxisAlign === 'STRETCH'\n if (crossFixed && inheritsStretch) node.layoutAlignSelf = 'MIN'\n}\n\nfunction hasDefiniteWidth(graph: SceneGraph, node: SceneNode): boolean {\n return layoutSizing(graph, node, 'HORIZONTAL') !== 'HUG'\n}\n\n/**\n * Whether CSS keeps the text on its lines however narrow its box, and the text starts at the\n * box's start edge, so its own width places it as the box does. A box narrower than the text\n * clips it rather than breaking it, which wrapping text measured in other fonts would do.\n */\nfunction staysOnItsLines(style: DesignStyleDeclaration): boolean {\n const whiteSpace = pickStyle(style, 'white-space')?.trim()\n const align = pickStyle(style, 'text-align')?.trim() ?? 'start'\n return (whiteSpace === 'nowrap' || whiteSpace === 'pre') && ['start', 'left'].includes(align)\n}\n\n/**\n * Text wraps where its width is fixed or fills a parent with a width of its own, and hugs its\n * content otherwise. It is measured when the document is laid out.\n */\nfunction applyTextSizing(graph: SceneGraph, node: SceneNode, size: BoxSize): void {\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const fillsWidth =\n parent !== undefined &&\n hasDefiniteWidth(graph, parent) &&\n layoutSizing(graph, node, 'HORIZONTAL') === 'FILL'\n const wraps = size.fixedWidth || fillsWidth\n node.textAutoResize = wraps ? textAutoResizeFor(false, !size.fixedHeight) : 'WIDTH_AND_HEIGHT'\n // Wrapping text starts at its content's width.\n if (!size.fixedWidth) node.width = 0\n if (!size.fixedHeight) node.height = 0\n}\n\n/**\n * How a child sizes in its parent's flow, as CSS sizes it: an explicit size is fixed, block-level\n * children of block flow and items of a stretching flex container fill across, a growing flex\n * item fills along, `100%` fills, and everything else hugs. Text that fills its width wraps.\n */\nexport function applyFlowSizing(\n graph: SceneGraph,\n node: SceneNode,\n style: DesignStyleDeclaration,\n display: string,\n parentFlow: ParentFlow\n): void {\n const size: BoxSize = {\n fixedWidth: parseCSSNumber(pickStyle(style, 'width')) !== null,\n fixedHeight: parseCSSNumber(pickStyle(style, 'height')) !== null\n }\n if (node.layoutMode !== 'NONE' && node.layoutMode !== 'GRID') {\n const own = (fixed: boolean) => (fixed ? 'FIXED' : 'HUG')\n Object.assign(\n node,\n autoLayoutSizingFields(node.layoutMode, own(size.fixedWidth), own(size.fixedHeight))\n )\n }\n if (node.type === 'TEXT' && staysOnItsLines(style)) {\n applyTextSizing(graph, node, { fixedWidth: false, fixedHeight: size.fixedHeight })\n return\n }\n applyParentFill(graph, node, style, display, parentFlow, size)\n if (node.type === 'TEXT') applyTextSizing(graph, node, size)\n}\n","export function mergeCSSText(...parts: Array<string | undefined>): string | undefined {\n const text = parts.map((part) => part?.trim()).filter((part): part is string => !!part)\n return text.length > 0 ? text.join('\\n') : undefined\n}\n","import { toUint8Array } from 'js-base64'\n\nimport type { Fill, SceneGraph } from '@pairdraw/scene-graph'\nimport { TRANSPARENT } from '@pairdraw/scene-graph/constants'\nimport { parseCSSBackgroundImages, splitCSSValue } from '@pairdraw/scene-graph/css'\nimport { computeImageHash, imageSize } from '@pairdraw/scene-graph/images'\nimport type { Matrix, Rect, Size, Vector } from '@pairdraw/scene-graph/primitives'\n\nimport type { DesignStyleDeclaration } from '../types'\nimport { colorToFillFromCSS, pickStyle } from './css-values'\n\nconst REPEAT_KEYWORDS = new Set(['repeat', 'no-repeat', 'repeat-x', 'repeat-y', 'space', 'round'])\nconst BOX_KEYWORDS = new Set(['border-box', 'padding-box', 'content-box'])\nconst ATTACHMENT_KEYWORDS = new Set(['scroll', 'fixed', 'local'])\nconst GRADIENT_PREFIXES = [\n 'linear-gradient(',\n 'radial-gradient(',\n 'conic-gradient(',\n 'repeating-linear-gradient(',\n 'repeating-radial-gradient(',\n 'repeating-conic-gradient('\n]\n\n/** Splits a CSS value list at its top-level commas, keeping functions whole. */\nfunction splitLayers(value: string): string[] {\n const layers: string[] = []\n let depth = 0\n let start = 0\n for (let index = 0; index < value.length; index++) {\n const character = value[index]\n if (character === '(') depth++\n else if (character === ')') depth = Math.max(0, depth - 1)\n else if (character === ',' && depth === 0) {\n layers.push(value.slice(start, index).trim())\n start = index + 1\n }\n }\n const last = value.slice(start).trim()\n if (last) layers.push(last)\n return layers\n}\n\n/** The value a property list gives layer `index`, repeating its last entry as CSS does. */\nfunction at(list: readonly string[], index: number): string | undefined {\n return list[Math.min(index, list.length - 1)]\n}\n\n/** One CSS background layer as the properties that place its picture. */\nexport interface BackgroundLayer {\n image: string\n size: string\n position: string\n repeat: string\n origin: string\n clip: string\n /** A gradient parsed from the longhand, which has no image URL. */\n gradient?: Fill\n}\n\n/** Splits a value into its `url(...)` and gradient functions and the words around them. */\nfunction splitBackgroundFunctions(value: string): { image: string; rest: string } {\n let image = ''\n let depth = 0\n let start = -1\n let end = -1\n for (let index = 0; index < value.length; index++) {\n const character = value[index]\n if (character === '(') {\n if (depth === 0) start = index\n depth++\n } else if (character === ')') {\n depth--\n if (depth === 0) end = index\n } else if (depth === 0 && character === ' ') {\n continue\n }\n if (depth === 0 && end !== -1) {\n const name = value.slice(0, start).trim().split(/[\\s,]/).pop() ?? ''\n const candidate = `${name}${value.slice(start, end + 1)}`\n if (name === 'url' || GRADIENT_PREFIXES.some((prefix) => candidate.startsWith(prefix))) {\n image = candidate\n const before = value.slice(0, start).trim().split(/\\s+/)\n const after = value.slice(end + 1).trim()\n return { image, rest: [...before.slice(0, -1), after].join(' ').trim() }\n }\n start = -1\n end = -1\n }\n }\n return { image, rest: value }\n}\n\nfunction parseShorthand(layer: string): BackgroundLayer {\n const { image, rest } = splitBackgroundFunctions(layer)\n const [positionPart = '', sizePart = ''] = rest.split('/')\n const words = splitCSSValue(positionPart.toLowerCase())\n const sizes = splitCSSValue(sizePart.toLowerCase())\n const result: BackgroundLayer = {\n image,\n size: 'auto',\n position: '0% 0%',\n repeat: 'repeat',\n origin: 'padding-box',\n clip: 'border-box'\n }\n const places: string[] = []\n let sawOrigin = false\n let sawClip = false\n for (const word of words) {\n if (REPEAT_KEYWORDS.has(word)) result.repeat = word\n else if (BOX_KEYWORDS.has(word)) {\n // The first of the two box words is the origin, the second the clip.\n if (!sawOrigin) {\n result.origin = word\n sawOrigin = true\n } else {\n result.clip = word\n sawClip = true\n }\n } else if (ATTACHMENT_KEYWORDS.has(word)) continue\n else if (/^[\\d.+-]/.test(word) || ['left', 'right', 'center', 'top', 'bottom'].includes(word)) {\n places.push(word)\n }\n }\n const sizing = sizes.filter((word) => !REPEAT_KEYWORDS.has(word) && !BOX_KEYWORDS.has(word))\n if (sizing.length > 0) result.size = sizing.slice(0, 2).join(' ')\n for (const word of sizes) {\n if (REPEAT_KEYWORDS.has(word)) {\n result.repeat = word\n } else if (BOX_KEYWORDS.has(word)) {\n if (!sawOrigin) {\n result.origin = word\n sawOrigin = true\n } else {\n result.clip = word\n sawClip = true\n }\n }\n }\n if (!sawClip && sawOrigin) result.clip = result.origin\n if (places.length === 1) result.position = places[0]\n else if (places.length >= 2) result.position = places.slice(-2).join(' ')\n return result\n}\n\n/** The background layers of an element, top layer first, from the shorthand or the longhands. */\nexport function backgroundLayers(\n style: DesignStyleDeclaration,\n width = 1,\n height = 1\n): BackgroundLayer[] {\n const shorthand = splitLayers(pickStyle(style, 'background') ?? '')\n if (shorthand.length > 0) {\n return shorthand.map((layer) => parseShorthand(layer))\n }\n const parsed = parseCSSBackgroundImages(pickStyle(style, 'background-image'), width, height)\n const sizes = splitLayers(pickStyle(style, 'background-size') ?? '')\n const positions = splitLayers(pickStyle(style, 'background-position') ?? '')\n const repeats = splitLayers(pickStyle(style, 'background-repeat') ?? '')\n const origins = splitLayers(pickStyle(style, 'background-origin') ?? '')\n const clips = splitLayers(pickStyle(style, 'background-clip') ?? '')\n return parsed.map((layer, index) => ({\n image: layer.kind === 'image' ? `url(${layer.url})` : '',\n gradient: layer.kind === 'gradient' ? layer.fill : undefined,\n size: at(sizes, index) ?? 'auto',\n position: at(positions, index) ?? '0% 0%',\n repeat: at(repeats, index) ?? 'repeat',\n origin: at(origins, index) ?? 'padding-box',\n clip: at(clips, index) ?? 'border-box'\n }))\n}\n\n/** A length or percentage of `total`, as one value of `background-size` or `-position` gives. */\nfunction lengthOf(value: string | undefined, total: number): number | null {\n if (!value) return null\n const trimmed = value.trim()\n const percent = /^(-?[\\d.]+)%$/.exec(trimmed)\n if (percent) {\n const share = Number.parseFloat(percent[1])\n return Number.isFinite(share) ? (total * share) / 100 : null\n }\n const pixels = /^(-?[\\d.]+)(?:px)?$/.exec(trimmed)\n if (!pixels) return null\n const number = Number.parseFloat(pixels[1])\n return Number.isFinite(number) ? number : null\n}\n\n/** The size `background-size` draws a picture of `natural` size at in `box`. */\nfunction pictureSize(size: string, box: Size, natural: Size): Size {\n const sizing = size.trim().toLowerCase()\n if (sizing === 'cover' || sizing === 'contain') {\n const scale = (sizing === 'cover' ? Math.max : Math.min)(\n box.width / natural.width,\n box.height / natural.height\n )\n return { width: natural.width * scale, height: natural.height * scale }\n }\n const [across, down = 'auto'] = splitCSSValue(sizing)\n const width = across === 'auto' ? null : lengthOf(across, box.width)\n const height = down === 'auto' ? null : lengthOf(down, box.height)\n if (width === null && height === null) return natural\n if (width === null && height !== null) {\n return { width: (height * natural.width) / natural.height, height }\n }\n if (width !== null && height === null) {\n return { width, height: (width * natural.height) / natural.width }\n }\n return { width: width ?? natural.width, height: height ?? natural.height }\n}\n\nconst POSITION_KEYWORDS: Partial<Record<string, string>> = {\n left: '0%',\n top: '0%',\n center: '50%',\n right: '100%',\n bottom: '100%'\n}\n\n/** Where `background-position` puts a picture of `size` in `box`: a percentage of the room left. */\nfunction pictureOffset(position: string, box: Size, size: Size): Vector {\n const values = splitCSSValue(position.trim().toLowerCase()).map(\n (value) => POSITION_KEYWORDS[value] ?? value\n )\n const [across = '50%', down = '50%'] = values\n const along = (value: string, room: number, total: number) => {\n if (value.endsWith('%')) {\n const number = Number.parseFloat(value)\n return Number.isFinite(number) ? (room * number) / 100 : room / 2\n }\n return lengthOf(value, total) ?? room / 2\n }\n return {\n x: along(across, box.width - size.width, box.width),\n y: along(down, box.height - size.height, box.height)\n }\n}\n\nfunction cropTransform(area: Rect, picture: Rect): Matrix {\n return {\n m00: area.width / picture.width,\n m01: 0,\n m02: (area.x - picture.x) / picture.width,\n m10: 0,\n m11: area.height / picture.height,\n m12: (area.y - picture.y) / picture.height\n }\n}\n\nfunction cropFill(imageHash: string, imageTransform: Matrix): Fill {\n return {\n type: 'IMAGE',\n imageHash,\n imageScaleMode: 'CROP',\n imageTransform,\n color: TRANSPARENT,\n opacity: 1,\n visible: true\n }\n}\n\nfunction borderWidth(style: DesignStyleDeclaration, side: string): number {\n const raw = pickStyle(style, `border-${side}-width`) ?? pickStyle(style, 'border-width')\n const parsed = lengthOf(raw, 0)\n return parsed === null || parsed < 0 ? 0 : parsed\n}\n\nfunction paddingWidth(style: DesignStyleDeclaration, side: string): number {\n const parsed = lengthOf(pickStyle(style, `padding-${side}`), 0)\n return parsed === null || parsed < 0 ? 0 : parsed\n}\n\ninterface Insets {\n top: number\n right: number\n bottom: number\n left: number\n}\n\nfunction boxInsets(box: string, style: DesignStyleDeclaration): Insets {\n const border = {\n top: borderWidth(style, 'top'),\n right: borderWidth(style, 'right'),\n bottom: borderWidth(style, 'bottom'),\n left: borderWidth(style, 'left')\n }\n if (box === 'padding-box') return border\n if (box !== 'content-box') return { top: 0, right: 0, bottom: 0, left: 0 }\n return {\n top: border.top + paddingWidth(style, 'top'),\n right: border.right + paddingWidth(style, 'right'),\n bottom: border.bottom + paddingWidth(style, 'bottom'),\n left: border.left + paddingWidth(style, 'left')\n }\n}\n\nfunction insetArea(node: Size, insets: Insets): Rect {\n return {\n x: insets.left,\n y: insets.top,\n width: Math.max(0, node.width - insets.left - insets.right),\n height: Math.max(0, node.height - insets.top - insets.bottom)\n }\n}\n\n/** One background layer, in the order CSS paints it: the bottom layer first. */\nexport interface BackgroundLayerPaint {\n fill: Fill\n /** The area a picture covers, when it covers only part of its layer. */\n area?: Rect\n /** Whether the layer is a picture, which a layer of its own behind the children draws. */\n picture: boolean\n}\n\nexport interface BackgroundPaint {\n /** Fills in CSS paint order bottom-first, the color first, when every layer covers its box. */\n fills: Fill[]\n /**\n * Every background layer in CSS paint order when one picture covers part of its box, so layers\n * that stay fills and layers that need their own still paint in the order CSS gives them.\n */\n layers: BackgroundLayerPaint[]\n}\n\n/** Adds a layer's picture to the stack, at the area it shows when it covers part of its box. */\nfunction placePicture(\n graph: SceneGraph,\n node: Size,\n style: DesignStyleDeclaration,\n layer: BackgroundLayer,\n stack: BackgroundLayerPaint[]\n): void {\n const images = parseCSSBackgroundImages(layer.image, node.width, node.height)\n for (const image of images) {\n if (image.kind === 'gradient') {\n stack.push({ fill: image.fill, picture: false })\n continue\n }\n const bytes = bytesFromDataURL(image.url)\n if (!bytes) continue\n const natural = imageSize(bytes)\n if (!natural || natural.width <= 0 || natural.height <= 0) continue\n const imageHash = computeImageHash(bytes)\n graph.images.set(imageHash, bytes)\n const origin = insetArea(node, boxInsets(layer.origin, style))\n const size = pictureSize(layer.size, origin, natural)\n if (size.width <= 0 || size.height <= 0) continue\n const clip = insetArea(node, boxInsets(layer.clip, style))\n const tiles =\n layer.repeat !== 'no-repeat' &&\n layer.repeat !== 'space' &&\n layer.repeat !== 'round' &&\n (layer.size.trim() === 'auto' || layer.size.trim() === 'auto auto')\n if (tiles) {\n stack.push({\n fill: {\n type: 'IMAGE',\n imageHash,\n imageScaleMode: 'TILE',\n color: TRANSPARENT,\n opacity: 1,\n visible: true\n },\n picture: true\n })\n continue\n }\n const offset = pictureOffset(layer.position, origin, size)\n const picture = { x: origin.x + offset.x, y: origin.y + offset.y, ...size }\n const left = Math.max(clip.x, picture.x)\n const top = Math.max(clip.y, picture.y)\n const right = Math.min(clip.x + clip.width, picture.x + picture.width)\n const bottom = Math.min(clip.y + clip.height, picture.y + picture.height)\n if (right <= left || bottom <= top) continue\n const area = { x: left, y: top, width: right - left, height: bottom - top }\n const fill = cropFill(imageHash, cropTransform(area, picture))\n if (\n area.x <= 0.5 &&\n area.y <= 0.5 &&\n area.width >= node.width - 1 &&\n area.height >= node.height - 1\n ) {\n stack.push({ fill, picture: true })\n } else {\n stack.push({ area, fill, picture: true })\n }\n }\n}\n\n/**\n * Reads an element's background layers: the color, gradients, tiles and pictures placed where\n * `background-size`, `-position`, `-repeat`, `-origin`, and `-clip` put them, bottom layer first.\n * Every layer stays a fill while all of them cover the box; as soon as one covers part of it, the\n * whole stack becomes layers of their own, so CSS paint order survives across the two kinds.\n */\nexport function backgroundPaint(\n graph: SceneGraph,\n style: DesignStyleDeclaration,\n node: Size\n): BackgroundPaint {\n const color = fillFromColor(style)\n const layers = backgroundLayers(style, node.width, node.height).reverse()\n const stack: BackgroundLayerPaint[] = []\n for (const layer of layers) {\n if (layer.gradient) {\n stack.push({ fill: layer.gradient, picture: false })\n continue\n }\n placePicture(graph, node, style, layer, stack)\n }\n if (stack.every((layer) => layer.area === undefined)) {\n const fills = stack.map((layer) => layer.fill)\n return { fills: color ? [color, ...fills] : fills, layers: [] }\n }\n return { fills: color ? [color] : [], layers: stack }\n}\n\nfunction fillFromColor(style: DesignStyleDeclaration): Fill | null {\n const fills = colorToFillFromCSS(pickStyle(style, 'background-color'))\n return fills[0] ?? null\n}\n\nfunction bytesFromDataURL(value: string | undefined): Uint8Array | null {\n const match = value ? /^data:[^,]*;base64,([\\s\\S]*)$/.exec(value.trim()) : null\n if (!match) return null\n try {\n return toUint8Array(match[1])\n } catch {\n return null\n }\n}\n","import {\n GENERIC_FONT_FAMILIES_BY_CLASS,\n genericFontFamilyClass,\n parseCSSFontFamilies,\n type GenericFontClass\n} from '@pairdraw/scene-graph/css'\n\nexport interface FontStackOptions {\n /**\n * Whether the document can draw a family, such as the font service answering. Without it every\n * concrete family is taken as available, as a headless import has no faces to ask.\n */\n isAvailable?: (family: string) => boolean\n}\n\nfunction defaultFamily(kind: GenericFontClass, options: FontStackOptions): string {\n const candidates = GENERIC_FONT_FAMILIES_BY_CLASS[kind]\n return (\n (options.isAvailable ? candidates.find((family) => options.isAvailable?.(family)) : null) ??\n candidates[0]\n )\n}\n\n/**\n * The family a CSS `font-family` stack asks a document to draw: the first concrete family the\n * font service can provide; a generic keyword maps to a concrete face of its class. Null when the\n * list has no family.\n */\nexport function resolveFontFamilyStack(\n value: string | undefined,\n options: FontStackOptions = {}\n): string | null {\n for (const family of parseCSSFontFamilies(value)) {\n const kind = genericFontFamilyClass(family)\n if (kind) return defaultFamily(kind, options)\n if (options.isAvailable && !options.isAvailable(family)) continue\n return family\n }\n return null\n}\n","import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport type { DesignStyleDeclaration } from '../types'\nimport { pickStyle } from './css-values'\n\n/** A child the parent paints out of tree order, by its `z-index`. */\ninterface StackedChild {\n id: string\n z: number\n}\n\n/** A child as the builder made it, with the style that decides where CSS paints it. */\nexport interface PaintedChild {\n layer: SceneNode\n style: DesignStyleDeclaration\n}\n\nfunction isPositioned(style: DesignStyleDeclaration): boolean {\n const position = pickStyle(style, 'position')?.trim()\n return position !== undefined && position !== 'static'\n}\n\nfunction zIndexOf(style: DesignStyleDeclaration): number | null {\n if (!isPositioned(style)) return null\n const value = pickStyle(style, 'z-index')?.trim()\n if (!value || value === 'auto') return null\n const z = Number.parseInt(value, 10)\n return Number.isInteger(z) ? z : null\n}\n\n/** Whether a box starts a stacking context of its own, as CSS decides it for the common cases. */\nfunction formsStackingContext(style: DesignStyleDeclaration): boolean {\n const value = (property: string) => pickStyle(style, property)?.trim()\n const position = value('position')\n const opacity = Number.parseFloat(value('opacity') ?? '1')\n return (\n zIndexOf(style) !== null ||\n position === 'fixed' ||\n position === 'sticky' ||\n opacity < 1 ||\n (value('transform') ?? 'none') !== 'none' ||\n (value('filter') ?? 'none') !== 'none' ||\n value('isolation') === 'isolate' ||\n (value('mix-blend-mode') ?? 'normal') !== 'normal'\n )\n}\n\n/**\n * Puts a container's children in the order CSS paints them: negative layers first, lowest\n * first, then the boxes in the flow as they were, then positioned ones, lowest first and in tree\n * order at the same level. A container that is not a stacking context paints its negative layers\n * under its own background, which a layer's fills cannot go under, so its fills move to a layer\n * of their own above those children.\n */\nexport function applyStacking(\n graph: SceneGraph,\n parent: SceneNode,\n style: DesignStyleDeclaration,\n parts: readonly PaintedChild[]\n): void {\n if (parts.length === 0) return\n const children: StackedChild[] = []\n let flowAfter = false\n for (const { layer, style: childStyle } of parts) {\n const movable = layer.layoutPositioning === 'ABSOLUTE' || parent.layoutMode === 'NONE'\n if (!isPositioned(childStyle) || !movable) {\n // A positioned box before a box in the flow is painted out of tree order.\n if (children.some((child) => child.z === 0)) flowAfter = true\n continue\n }\n children.push({ id: layer.id, z: zIndexOf(childStyle) ?? 0 })\n }\n if (!flowAfter && children.every((child) => child.z === 0)) return\n\n const below = children.filter((child) => child.z < 0).toSorted((a, b) => a.z - b.z)\n // Sorted stably, so positioned boxes at the same level keep their tree order.\n const above = children.filter((child) => child.z >= 0).toSorted((a, b) => a.z - b.z)\n const moved = new Set(children.map((child) => child.id))\n const order = [\n ...below.map((child) => child.id),\n ...parent.childIds.filter((id) => !moved.has(id)),\n ...above.map((child) => child.id)\n ]\n for (const [index, id] of order.entries()) graph.insertChildAt(id, parent.id, index)\n\n if (below.length > 0 && !formsStackingContext(style)) liftBackground(graph, parent, below.length)\n}\n\n/** Moves a container's fills into a layer of its own at `index`, its size and corners. */\nfunction liftBackground(graph: SceneGraph, parent: SceneNode, index: number): void {\n if (!parent.fills.some((fill) => fill.visible)) return\n const background = graph.createNode('RECTANGLE', parent.id, {\n name: 'background',\n x: 0,\n y: 0,\n width: parent.width,\n height: parent.height,\n fills: parent.fills,\n cornerRadius: parent.cornerRadius,\n topLeftRadius: parent.topLeftRadius,\n topRightRadius: parent.topRightRadius,\n bottomRightRadius: parent.bottomRightRadius,\n bottomLeftRadius: parent.bottomLeftRadius,\n independentCorners: parent.independentCorners,\n layoutPositioning: parent.layoutMode === 'NONE' ? 'AUTO' : 'ABSOLUTE'\n })\n graph.insertChildAt(background.id, parent.id, index)\n graph.updateNode(parent.id, { fills: [] })\n}\n","import { countBy } from 'es-toolkit/array'\nimport { isEqual } from 'es-toolkit/predicate'\n\nimport type {\n CharacterStyleOverride,\n HyperlinkTarget,\n SceneNode,\n StyleRun,\n TextParagraphStyle\n} from '@pairdraw/scene-graph'\nimport {\n parseCSSColor,\n parseCSSFontFamily,\n parseCSSLetterSpacing,\n parseCSSLineHeight,\n parseCSSNumber\n} from '@pairdraw/scene-graph/css'\n\nimport type { DesignElement, DesignNode, DesignStyleDeclaration } from '../types'\nimport { colorToFillFromCSS, mergedStyle, pickStyle } from './css-values'\n\n/** The character styles a text layer and its runs take from CSS. */\nexport type CSSCharacterStyle = Pick<\n SceneNode,\n | 'fontFamily'\n | 'fontSize'\n | 'fontWeight'\n | 'italic'\n | 'letterSpacing'\n | 'lineHeight'\n | 'fills'\n | 'textDecoration'\n | 'textDecorationStyle'\n | 'textDecorationThickness'\n | 'textDecorationFills'\n | 'textDecorationSkipInk'\n | 'textUnderlineOffset'\n | 'textCase'\n>\n\n/** A character's style and the link it is part of. */\ntype CharacterOfText = CSSCharacterStyle & { hyperlink?: HyperlinkTarget }\n\n/**\n * What characters take from the elements around them: the properties CSS inherits, and the\n * decoration, which CSS draws through descendants.\n */\nconst CHARACTER_PROPERTIES = [\n 'color',\n 'font-family',\n 'font-size',\n 'font-style',\n 'font-weight',\n 'letter-spacing',\n 'line-height',\n 'white-space',\n 'text-transform',\n 'text-decoration-line',\n 'text-decoration-style',\n 'text-decoration-color',\n 'text-decoration-thickness',\n 'text-underline-offset',\n 'text-decoration-skip-ink'\n]\n\nconst TEXT_BLOCK_TAGS = new Set(['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'])\n\n/** What browsers' default stylesheet gives inline formatting elements that CSS does not set. */\nconst FORMATTING_DEFAULTS: Record<string, DesignStyleDeclaration> = {\n b: { 'font-weight': '700' },\n strong: { 'font-weight': '700' },\n i: { 'font-style': 'italic' },\n em: { 'font-style': 'italic' },\n u: { 'text-decoration-line': 'underline' },\n ins: { 'text-decoration-line': 'underline' },\n s: { 'text-decoration-line': 'line-through' },\n del: { 'text-decoration-line': 'line-through' }\n}\nconst LIST_TAGS = new Set(['ul', 'ol'])\n\n/** Lengths CSS gives as a number of pixels, or `null` for keywords such as `auto`. */\nfunction pixels(value: string | undefined): number | null {\n const trimmed = value?.trim()\n if (!trimmed || !/^-?[\\d.]+(px)?$/.test(trimmed)) return null\n return parseCSSNumber(trimmed)\n}\n\nfunction decorationLine(value: string | undefined): SceneNode['textDecoration'] {\n if (value?.includes('underline')) return 'UNDERLINE'\n if (value?.includes('line-through')) return 'STRIKETHROUGH'\n return 'NONE'\n}\n\nfunction decorationStyle(value: string | undefined): SceneNode['textDecorationStyle'] {\n const style = value?.trim().toLowerCase()\n if (style === 'dotted') return 'DOTTED'\n if (style === 'wavy') return 'WAVY'\n return 'SOLID'\n}\n\nfunction textCaseFromCSS(value: string | undefined): SceneNode['textCase'] {\n if (value === 'uppercase') return 'UPPER'\n if (value === 'lowercase') return 'LOWER'\n if (value === 'capitalize') return 'TITLE'\n return 'ORIGINAL'\n}\n\n/** The character style of CSS declarations, over `base` for what they leave out. */\nexport function characterStyleFromCSS(\n style: DesignStyleDeclaration,\n base: CSSCharacterStyle\n): CSSCharacterStyle {\n const fills = colorToFillFromCSS(pickStyle(style, 'color'))\n const family = parseCSSFontFamily(pickStyle(style, 'font-family'))\n const decorationColor = pickStyle(style, 'text-decoration-color')\n const decorationFills = parseCSSColor(decorationColor) ? colorToFillFromCSS(decorationColor) : []\n const line = pickStyle(style, 'text-decoration-line')\n const fontStyle = pickStyle(style, 'font-style')\n const lineHeight = pickStyle(style, 'line-height')\n // `normal` is automatic, a null; a value CSS writes some other way keeps the base.\n const parsedLineHeight = parseCSSLineHeight(lineHeight)\n const textTransform = pickStyle(style, 'text-transform')\n return {\n fontFamily: family || base.fontFamily,\n fontSize: parseCSSNumber(pickStyle(style, 'font-size')) ?? base.fontSize,\n fontWeight: parseCSSNumber(pickStyle(style, 'font-weight')) ?? base.fontWeight,\n italic: fontStyle === undefined ? base.italic : fontStyle === 'italic',\n letterSpacing: parseCSSLetterSpacing(pickStyle(style, 'letter-spacing')) ?? base.letterSpacing,\n lineHeight: parsedLineHeight === undefined ? base.lineHeight : parsedLineHeight,\n fills: fills.length > 0 ? fills : base.fills,\n textDecoration: line === undefined ? base.textDecoration : decorationLine(line),\n textDecorationStyle:\n pickStyle(style, 'text-decoration-style') === undefined\n ? base.textDecorationStyle\n : decorationStyle(pickStyle(style, 'text-decoration-style')),\n textDecorationFills: decorationColor === undefined ? base.textDecorationFills : decorationFills,\n textDecorationThickness:\n pickStyle(style, 'text-decoration-thickness') === undefined\n ? base.textDecorationThickness\n : pixels(pickStyle(style, 'text-decoration-thickness')),\n textUnderlineOffset:\n pickStyle(style, 'text-underline-offset') === undefined\n ? base.textUnderlineOffset\n : pixels(pickStyle(style, 'text-underline-offset')),\n textDecorationSkipInk:\n pickStyle(style, 'text-decoration-skip-ink') === undefined\n ? base.textDecorationSkipInk\n : pickStyle(style, 'text-decoration-skip-ink') !== 'none',\n textCase: textTransform === undefined ? base.textCase : textCaseFromCSS(textTransform)\n }\n}\n\n/** What the characters inside `element` take from it and the elements around it. */\nfunction characterDeclarations(\n element: DesignElement,\n around: DesignStyleDeclaration\n): DesignStyleDeclaration {\n const own = { ...FORMATTING_DEFAULTS[element.tagName.toLowerCase()], ...mergedStyle(element) }\n const inherited: DesignStyleDeclaration = {}\n for (const property of CHARACTER_PROPERTIES) {\n const value = pickStyle(own, property) ?? pickStyle(around, property)\n if (value !== undefined) inherited[property] = value\n }\n return inherited\n}\n\n/** Whether the element holds only characters: text, inline elements, and line breaks. */\nexport function isInlineContent(\n element: DesignElement,\n isInlineElement: (element: DesignElement) => boolean\n): boolean {\n return element.children.every(\n (child) =>\n child.type === 'text' ||\n child.tagName.toLowerCase() === 'br' ||\n (isInlineElement(child) && isInlineContent(child, isInlineElement))\n )\n}\n\nfunction isWhitespace(node: DesignNode): boolean {\n return node.type === 'text' && node.text.trim() === ''\n}\n\nfunction isList(\n element: DesignElement,\n isListPlain: (element: DesignElement) => boolean,\n isPlain: (element: DesignElement) => boolean\n): boolean {\n if (!LIST_TAGS.has(element.tagName.toLowerCase()) || !isListPlain(element)) return false\n return element.children.every(\n (child) =>\n isWhitespace(child) ||\n (child.type === 'element' && child.tagName.toLowerCase() === 'li' && isListItem(child))\n )\n\n function isListItem(item: DesignElement): boolean {\n return item.children.every(\n (child) =>\n child.type === 'text' ||\n child.tagName.toLowerCase() === 'br' ||\n isList(child, isPlain, isPlain) ||\n (!LIST_TAGS.has(child.tagName.toLowerCase()) && isPlain(child))\n )\n }\n}\n\n/**\n * Whether the element holds text in blocks, as Figma keeps it in one layer: it is a list, or\n * holds only paragraphs, headings, and lists of characters with no box of their own.\n */\nexport function holdsTextBlocks(\n element: DesignElement,\n isPlain: (element: DesignElement) => boolean,\n isInlineElement: (element: DesignElement) => boolean\n): boolean {\n if (LIST_TAGS.has(element.tagName.toLowerCase())) return isList(element, () => true, isPlain)\n const blocks = element.children.filter((child) => !isWhitespace(child))\n return (\n blocks.length > 0 &&\n blocks.every(\n (child) =>\n child.type === 'element' &&\n (isList(child, isPlain, isPlain) ||\n (TEXT_BLOCK_TAGS.has(child.tagName.toLowerCase()) &&\n isPlain(child) &&\n isInlineContent(child, isInlineElement)))\n )\n )\n}\n\n/** Text with its runs and paragraphs, as one text layer holds it. */\nexport interface RichText {\n text: string\n styleRuns: StyleRun[]\n textParagraphs: TextParagraphStyle[]\n /** The space after each paragraph, from the margins between blocks. */\n spaceAfter: number[]\n /** Each paragraph's first-line indent. */\n indents: number[]\n /** Whether the outermost list puts its markers outside the text, with no indent of its own. */\n hangingList: boolean\n}\n\ninterface Collector {\n base: CSSCharacterStyle\n text: string\n styles: CharacterOfText[]\n /** The link the characters added now are part of. */\n link: HyperlinkTarget | null\n paragraphs: TextParagraphStyle[]\n spaceAfter: number[]\n indents: number[]\n /** Space collected from margins since the last paragraph ended. */\n pending: number\n hangingList: boolean | undefined\n}\n\nfunction preservesWhitespace(style: DesignStyleDeclaration): boolean {\n const whiteSpace = pickStyle(style, 'white-space')\n return whiteSpace === 'pre' || whiteSpace === 'pre-wrap' || whiteSpace === 'pre-line'\n}\n\nfunction appendCharacters(collector: Collector, text: string, style: CharacterOfText): void {\n const styled = collector.link ? { ...style, hyperlink: collector.link } : style\n collector.text += text\n collector.styles.push(...Array.from({ length: text.length }, () => styled))\n}\n\n/** Where a link element goes, for an `<a>` with an `href`. */\nexport function elementLink(element: DesignElement): HyperlinkTarget | null {\n if (element.tagName.toLowerCase() !== 'a' || !Object.hasOwn(element.attrs, 'href')) return null\n const href = element.attrs.href.trim()\n return href ? { type: 'URL', value: href } : null\n}\n\n/**\n * Characters of `text` in `style`. A line break inside a block starts a paragraph of the\n * block's kind, as text in Figma breaks into paragraphs at every newline.\n */\nfunction addCharacters(collector: Collector, text: string, style: DesignStyleDeclaration): void {\n const value = preservesWhitespace(style) ? text : text.replaceAll(/\\s+/g, ' ')\n const characterStyle = characterStyleFromCSS(style, collector.base)\n for (const [index, line] of value.split('\\n').entries()) {\n if (index > 0) {\n const paragraph = collector.paragraphs.at(-1)\n if (paragraph) {\n collector.spaceAfter.push(0)\n collector.paragraphs.push({ ...paragraph })\n collector.indents.push(0)\n }\n appendCharacters(collector, '\\n', characterStyle)\n }\n appendCharacters(collector, line, characterStyle)\n }\n}\n\nfunction addInline(\n collector: Collector,\n nodes: readonly DesignNode[],\n style: DesignStyleDeclaration\n) {\n for (const node of nodes) {\n if (node.type === 'text') addCharacters(collector, node.text, style)\n else if (isBreak(node)) addCharacters(collector, '\\n', { ...style, 'white-space': 'pre' })\n else if (!LIST_TAGS.has(node.tagName.toLowerCase())) {\n const around = collector.link\n collector.link = elementLink(node) ?? around\n addInline(collector, node.children, characterDeclarations(node, style))\n collector.link = around\n }\n }\n}\n\nfunction isBreak(node: DesignNode): boolean {\n return node.type === 'element' && node.tagName.toLowerCase() === 'br'\n}\n\nfunction margin(element: DesignElement, side: 'top' | 'bottom'): number {\n return Math.max(0, pixels(pickStyle(mergedStyle(element), `margin-${side}`)) ?? 0)\n}\n\n/** Starts a paragraph, ending the one before with the space collected since it. */\nfunction startParagraph(collector: Collector, style: TextParagraphStyle, indent: number): void {\n if (collector.paragraphs.length > 0) {\n collector.spaceAfter.push(collector.pending)\n appendCharacters(collector, '\\n', collector.styles.at(-1) ?? collector.base)\n }\n collector.pending = 0\n collector.paragraphs.push(style)\n collector.indents.push(indent)\n}\n\n/** A paragraph's characters, trimmed of the spaces that CSS drops at a block's edges. */\nfunction addParagraph(\n collector: Collector,\n nodes: readonly DesignNode[],\n style: DesignStyleDeclaration,\n paragraph: TextParagraphStyle,\n indent: number\n): void {\n startParagraph(collector, paragraph, indent)\n // A line break that ends a block adds no line: it gives an empty block its height.\n const content = isBreak(nodes.at(-1) ?? { type: 'text', text: '' }) ? nodes.slice(0, -1) : nodes\n addTrimmed(collector, content, style)\n}\n\n/** Inline content, trimmed of the spaces CSS drops at a block's edges unless it keeps them. */\nfunction addTrimmed(\n collector: Collector,\n nodes: readonly DesignNode[],\n style: DesignStyleDeclaration\n): void {\n const start = collector.text.length\n addInline(collector, nodes, style)\n if (preservesWhitespace(style)) return\n const added = collector.text.slice(start)\n const leading = added.length - added.trimStart().length\n const trimmed = added.trim()\n collector.text = collector.text.slice(0, start) + trimmed\n collector.styles = [\n ...collector.styles.slice(0, start),\n ...collector.styles.slice(start + leading, start + leading + trimmed.length)\n ]\n}\n\nfunction addList(\n collector: Collector,\n list: DesignElement,\n around: DesignStyleDeclaration,\n level: number\n): void {\n const listStyle = characterDeclarations(list, around)\n collector.pending = Math.max(collector.pending, margin(list, 'top'))\n if (level === 1 && collector.hangingList === undefined) {\n collector.hangingList = pixels(pickStyle(mergedStyle(list), 'padding-inline-start')) === 0\n }\n const listType = list.tagName.toLowerCase() === 'ol' ? 'ORDERED' : 'UNORDERED'\n for (const item of list.children) {\n if (item.type !== 'element') continue\n const itemStyle = characterDeclarations(item, listStyle)\n const inline = item.children.filter(\n (child) => child.type === 'text' || !LIST_TAGS.has(child.tagName.toLowerCase())\n )\n collector.pending = Math.max(collector.pending, margin(item, 'top'))\n // An item holding only a nested list, as a skipped level is written, is no paragraph.\n if (inline.some((child) => !isWhitespace(child))) {\n addParagraph(collector, inline, itemStyle, { listType, indentation: level }, 0)\n }\n for (const child of item.children) {\n if (child.type === 'element' && LIST_TAGS.has(child.tagName.toLowerCase())) {\n addList(collector, child, itemStyle, level + 1)\n }\n }\n collector.pending = Math.max(collector.pending, margin(item, 'bottom'))\n }\n collector.pending = Math.max(collector.pending, margin(list, 'bottom'))\n}\n\n/** Runs of characters whose style differs from the text's own. */\nfunction styleRunsFrom(styles: readonly CharacterOfText[], base: CSSCharacterStyle): StyleRun[] {\n const runs: StyleRun[] = []\n for (const [index, style] of styles.entries()) {\n const override: CharacterStyleOverride = {}\n for (const key of Object.keys(style) as (keyof CharacterOfText)[]) {\n const own = key === 'hyperlink' ? undefined : base[key]\n if (!isEqual(style[key], own)) Object.assign(override, { [key]: style[key] })\n }\n const previous = runs.at(-1)\n if (\n previous &&\n previous.start + previous.length === index &&\n isEqual(previous.style, override)\n ) {\n previous.length++\n } else if (Object.keys(override).length > 0) {\n runs.push({ start: index, length: 1, style: override })\n }\n }\n return runs\n}\n\nfunction richTextFrom(collector: Collector): RichText {\n return {\n text: collector.text,\n styleRuns: styleRunsFrom(collector.styles, collector.base),\n textParagraphs: collector.paragraphs,\n spaceAfter: collector.spaceAfter,\n indents: collector.indents,\n hangingList: collector.hangingList ?? false\n }\n}\n\nfunction collector(base: CSSCharacterStyle, link: HyperlinkTarget | null): Collector {\n return {\n base,\n text: '',\n styles: [],\n link,\n paragraphs: [],\n spaceAfter: [],\n indents: [],\n pending: 0,\n hangingList: undefined\n }\n}\n\n/** An element of inline content as one paragraph of text, its spans as runs. */\nexport function inlineRichText(\n element: DesignElement,\n style: DesignStyleDeclaration,\n base: CSSCharacterStyle\n): RichText {\n // A link the element is itself, as an `<a>` holding spans, links all its characters.\n const text = collector(base, elementLink(element))\n addTrimmed(text, element.children, characterDeclarations(element, style))\n return richTextFrom(text)\n}\n\n/** An element of text blocks as paragraphs of one text, its spans as runs. */\nexport function blockRichText(\n element: DesignElement,\n style: DesignStyleDeclaration,\n base: CSSCharacterStyle\n): RichText {\n const text = collector(base, elementLink(element))\n const around = characterDeclarations(element, style)\n const blocks = LIST_TAGS.has(element.tagName.toLowerCase()) ? [element] : element.children\n for (const block of blocks) {\n if (block.type !== 'element') continue\n if (LIST_TAGS.has(block.tagName.toLowerCase())) {\n addList(text, block, around, 1)\n continue\n }\n text.pending = Math.max(text.pending, margin(block, 'top'))\n const blockStyle = characterDeclarations(block, around)\n const indent = Math.max(0, pixels(pickStyle(mergedStyle(block), 'text-indent')) ?? 0)\n addParagraph(text, block.children, blockStyle, { listType: 'NONE', indentation: 0 }, indent)\n text.pending = Math.max(text.pending, margin(block, 'bottom'))\n }\n return richTextFrom(text)\n}\n\n/** The value most gaps of a kind share, which the text holds; the others are the paragraphs'. */\nfunction sharedValue(values: readonly number[]): number {\n const counts = countBy(values, String)\n const shared = Object.entries(counts)\n .toSorted((a, b) => b[1] - a[1])\n .at(0)\n return shared ? Number(shared[0]) : 0\n}\n\n/** Paragraph styles with the spacing and indents of the text's blocks, by Figma's rules. */\nexport function applyParagraphs(node: SceneNode, rich: RichText): void {\n const { textParagraphs: paragraphs, spaceAfter, indents } = rich\n const betweenItems = (index: number) =>\n paragraphs[index]?.listType !== 'NONE' && paragraphs[index + 1]?.listType !== 'NONE'\n const gaps = spaceAfter.map((space, index) => ({ space, list: betweenItems(index) }))\n node.paragraphSpacing = sharedValue(gaps.filter((gap) => !gap.list).map((gap) => gap.space))\n node.listSpacing = sharedValue(gaps.filter((gap) => gap.list).map((gap) => gap.space))\n node.paragraphIndent = sharedValue(\n indents.filter((_, index) => paragraphs[index]?.listType === 'NONE')\n )\n node.hangingList = rich.hangingList\n const styles = paragraphs.map((paragraph, index) => {\n const style: TextParagraphStyle = { ...paragraph }\n const gap = gaps.at(index)\n const field = gap?.list ? 'listSpacing' : 'paragraphSpacing'\n if (gap && gap.space !== node[field]) style[field] = gap.space\n if (paragraph.listType === 'NONE' && indents[index] !== node.paragraphIndent) {\n style.paragraphIndent = indents[index]\n }\n return style\n })\n const plain = styles.every(\n (style) => style.listType === 'NONE' && Object.keys(style).length === 2\n )\n node.textParagraphs = plain ? [] : styles\n}\n","import { pick } from 'es-toolkit'\nimport { isValid, toUint8Array } from 'js-base64'\n\nimport {\n SceneGraph,\n type Effect,\n type ImageScaleMode,\n type SceneNode,\n type Stroke\n} from '@pairdraw/scene-graph'\nimport { TRANSPARENT } from '@pairdraw/scene-graph/constants'\nimport { parseCSSAlignSelf, parseCSSNumber, parseCSSShadows } from '@pairdraw/scene-graph/css'\nimport { normalizeEffects } from '@pairdraw/scene-graph/effects'\nimport { blurRadiusForSigma } from '@pairdraw/scene-graph/geometry'\nimport { computeImageHash } from '@pairdraw/scene-graph/images'\nimport { textLayerName } from '@pairdraw/scene-graph/node-defaults'\n\nimport type { DesignDocument, DesignElement, DesignNode, DesignStyleDeclaration } from '../types'\nimport type { BackgroundLayerPaint } from './background-pictures'\nimport { backgroundPaint } from './background-pictures'\nimport { colorToStrokeFromCSS, mergedStyle, pickStyle } from './css-values'\nimport {\n applyContainerLayout,\n applyFlowSizing,\n elementDisplay,\n flowOf,\n inheritedTextStyle,\n type FlowKind,\n type ParentFlow\n} from './flow'\nimport { resolveFontFamilyStack } from './fonts'\nimport type { PaintedChild } from './stacking'\nimport { applyStacking } from './stacking'\nimport {\n blockRichText,\n characterStyleFromCSS,\n elementLink,\n holdsTextBlocks,\n inlineRichText,\n isInlineContent,\n applyParagraphs,\n type CSSCharacterStyle\n} from './text'\n\nconst DOM_CSS_PLUGIN_ID = 'pairdraw-dom-css'\nconst IMAGE_SOURCE_URL_KEY = 'image-source-url'\n\n/**\n * CSS shadows as the layer's effects, each blurred as the browser blurs it: CSS blurs a shadow\n * by half its blur length, which the canvas draws from the radius that gives that sigma.\n */\nfunction cssShadows(value: string | undefined) {\n return parseCSSShadows(value).map((effect): Effect => {\n if (effect.type !== 'DROP_SHADOW' && effect.type !== 'INNER_SHADOW') return effect\n return { ...effect, radius: blurRadiusForSigma(effect.radius / 2) }\n })\n}\n\nexport interface DesignDocumentToSceneGraphOptions {\n pageName?: string\n /**\n * The family a CSS `font-family` stack should draw, given the stack's families; null keeps it.\n * Hosts with a font service pass one that skips faces the document cannot draw; without it the\n * first concrete family wins and a generic keyword maps to a concrete face of its class.\n */\n resolveFontFamily?: (value: string) => string | null\n}\n\n/**\n * The document with every element's font stack resolved to the family its text layer draws, so\n * the per-character CSS parse sees a concrete name instead of a generic keyword.\n */\nfunction withResolvedFontFamilies(\n node: DesignNode,\n resolve: (value: string) => string | null\n): DesignNode {\n if (node.type !== 'element') return node\n const resolved = (\n style: DesignStyleDeclaration | undefined\n ): DesignStyleDeclaration | undefined => {\n const stack = style?.['font-family']\n const family = stack === undefined ? null : resolve(stack)\n return family && family !== stack ? { ...style, 'font-family': family } : style\n }\n const computedStyle = resolved(node.computedStyle)\n const inlineStyle = resolved(node.inlineStyle)\n const next: DesignElement = {\n ...node,\n children: node.children.map((child) => withResolvedFontFamilies(child, resolve))\n }\n if (computedStyle) next.computedStyle = computedStyle\n if (inlineStyle) next.inlineStyle = inlineStyle\n return next\n}\n\nfunction textContent(node: DesignNode): string {\n if (node.type === 'text') return node.text\n return node.children.map(textContent).join('')\n}\n\nfunction isTextLikeElement(node: DesignElement): boolean {\n return [\n 'span',\n 'p',\n 'label',\n 'strong',\n 'em',\n 'button',\n 'a',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6'\n ].includes(node.tagName.toLowerCase())\n}\n\nfunction firstCSSNumber(style: DesignStyleDeclaration, ...properties: string[]): number | null {\n for (const property of properties) {\n const parsed = parseCSSNumber(pickStyle(style, property))\n if (parsed !== null) return parsed\n }\n return null\n}\n\n/**\n * Puts one background layer behind the children, at the area a picture shows or over the whole\n * box. Layers are added bottom-first, so each new one paints above the last.\n */\nfunction addBackgroundLayer(\n graph: SceneGraph,\n parent: SceneNode,\n layer: BackgroundLayerPaint\n): void {\n // A layer that covers the box follows its corners; one at a picture's own area does not.\n const corners =\n layer.area === undefined\n ? {\n cornerRadius: parent.cornerRadius,\n topLeftRadius: parent.topLeftRadius,\n topRightRadius: parent.topRightRadius,\n bottomRightRadius: parent.bottomRightRadius,\n bottomLeftRadius: parent.bottomLeftRadius,\n independentCorners: parent.independentCorners\n }\n : {}\n const background = graph.createNode('RECTANGLE', parent.id, {\n name: layer.picture ? 'background image' : 'background',\n ...(layer.area ?? { x: 0, y: 0, width: parent.width, height: parent.height }),\n fills: [layer.fill],\n ...corners,\n layoutPositioning: parent.layoutMode === 'NONE' ? 'AUTO' : 'ABSOLUTE'\n })\n graph.insertChildAt(background.id, parent.id, parent.childIds.length)\n}\n\nfunction aspectRatioFromCSS(value: string | undefined): number | null {\n if (!value || value === 'auto') return null\n const parts = value\n .split('/')\n .map((part) => Number.parseFloat(part.trim()))\n .filter(Number.isFinite)\n if (parts.length === 1 && parts[0] > 0) return parts[0]\n if (parts.length === 2 && parts[0] > 0 && parts[1] > 0) return parts[0] / parts[1]\n return null\n}\n\nfunction setNodeBox(node: SceneNode, style: DesignStyleDeclaration): void {\n const width = firstCSSNumber(style, 'width')\n const height = firstCSSNumber(style, 'height')\n const minWidth = firstCSSNumber(style, 'min-width')\n const maxWidth = firstCSSNumber(style, 'max-width')\n const minHeight = firstCSSNumber(style, 'min-height')\n const maxHeight = firstCSSNumber(style, 'max-height')\n const aspectRatio = aspectRatioFromCSS(pickStyle(style, 'aspect-ratio'))\n if (width !== null) node.width = width\n if (height !== null) node.height = height\n if (height === null && width !== null && aspectRatio !== null) node.height = width / aspectRatio\n if (width === null && height !== null && aspectRatio !== null) node.width = height * aspectRatio\n if (minWidth !== null) node.minWidth = minWidth\n if (maxWidth !== null) node.maxWidth = maxWidth\n if (minHeight !== null) node.minHeight = minHeight\n if (maxHeight !== null) node.maxHeight = maxHeight\n}\n\nfunction firstStrokeColor(style: DesignStyleDeclaration) {\n return (\n pickStyle(style, 'border-color') ??\n pickStyle(style, 'border-top-color') ??\n pickStyle(style, 'border-right-color') ??\n pickStyle(style, 'border-bottom-color') ??\n pickStyle(style, 'border-left-color')\n )\n}\n\nfunction strokeWeightFromStyle(style: DesignStyleDeclaration) {\n const borderWidth = firstCSSNumber(style, 'border-width')\n if (borderWidth !== null) return borderWidth\n\n const sideWeights = [\n firstCSSNumber(style, 'border-top-width'),\n firstCSSNumber(style, 'border-right-width'),\n firstCSSNumber(style, 'border-bottom-width'),\n firstCSSNumber(style, 'border-left-width')\n ].filter((weight): weight is number => weight !== null)\n if (sideWeights.length === 0) return null\n return Math.max(...sideWeights)\n}\n\nfunction borderStyleFromCSS(style: DesignStyleDeclaration): string | undefined {\n return (\n pickStyle(style, 'border-style') ??\n pickStyle(style, 'border-top-style') ??\n pickStyle(style, 'border-right-style') ??\n pickStyle(style, 'border-bottom-style') ??\n pickStyle(style, 'border-left-style')\n )\n}\n\nfunction dashPatternFromCSS(style: DesignStyleDeclaration, strokeWeight: number): number[] {\n const borderStyle = borderStyleFromCSS(style)\n if (borderStyle === 'dashed') return [strokeWeight * 3, strokeWeight * 2]\n if (borderStyle === 'dotted') return [strokeWeight, strokeWeight]\n return []\n}\n\nfunction setBorderWeights(node: SceneNode, style: DesignStyleDeclaration, stroke: Stroke): void {\n const top = firstCSSNumber(style, 'border-top-width') ?? stroke.weight\n const right = firstCSSNumber(style, 'border-right-width') ?? stroke.weight\n const bottom = firstCSSNumber(style, 'border-bottom-width') ?? stroke.weight\n const left = firstCSSNumber(style, 'border-left-width') ?? stroke.weight\n node.borderTopWeight = top\n node.borderRightWeight = right\n node.borderBottomWeight = bottom\n node.borderLeftWeight = left\n node.independentStrokeWeights = [top, right, bottom, left].some(\n (weight) => weight !== stroke.weight\n )\n}\n\nfunction applyCornerRadii(node: SceneNode, style: DesignStyleDeclaration): void {\n const cornerRadius = firstCSSNumber(style, 'border-radius')\n const topLeft = firstCSSNumber(style, 'border-top-left-radius')\n const topRight = firstCSSNumber(style, 'border-top-right-radius')\n const bottomRight = firstCSSNumber(style, 'border-bottom-right-radius')\n const bottomLeft = firstCSSNumber(style, 'border-bottom-left-radius')\n\n if (cornerRadius !== null) node.cornerRadius = cornerRadius\n if (topLeft === null && topRight === null && bottomRight === null && bottomLeft === null) return\n\n const fallback = cornerRadius ?? 0\n node.topLeftRadius = topLeft ?? fallback\n node.topRightRadius = topRight ?? fallback\n node.bottomRightRadius = bottomRight ?? fallback\n node.bottomLeftRadius = bottomLeft ?? fallback\n node.independentCorners = [\n node.topLeftRadius,\n node.topRightRadius,\n node.bottomRightRadius,\n node.bottomLeftRadius\n ].some((radius) => radius !== fallback)\n}\n\nfunction applyFlexGap(node: SceneNode, style: DesignStyleDeclaration): void {\n const gap = firstCSSNumber(style, 'gap')\n const rowGap = firstCSSNumber(style, 'row-gap')\n const columnGap = firstCSSNumber(style, 'column-gap')\n const isHorizontal = node.layoutMode === 'HORIZONTAL'\n const isWrapped = node.layoutWrap === 'WRAP'\n\n node.itemSpacing = (isHorizontal ? columnGap : rowGap) ?? gap ?? 0\n node.counterAxisSpacing = (isHorizontal ? rowGap : columnGap) ?? (isWrapped ? (gap ?? 0) : 0)\n}\n\nfunction applyPositioning(node: SceneNode, style: DesignStyleDeclaration): void {\n const position = pickStyle(style, 'position')\n if (position === 'absolute' || position === 'fixed') node.layoutPositioning = 'ABSOLUTE'\n\n const left = firstCSSNumber(style, 'left')\n const top = firstCSSNumber(style, 'top')\n if (left !== null) node.x = left\n if (top !== null) node.y = top\n}\n\n/**\n * What CSS adds outside an explicit size: padding and borders, unless `box-sizing: border-box`\n * puts them inside it as auto layout does.\n */\nfunction contentBoxExtras(style: DesignStyleDeclaration): { width: number; height: number } {\n if (pickStyle(style, 'box-sizing')?.trim() === 'border-box') return { width: 0, height: 0 }\n // A border takes room once it has a style other than none, its CSS default, whatever its color.\n const borderStyle = borderStyleFromCSS(style)\n const bordered = borderStyle !== undefined && borderStyle !== 'none' && borderStyle !== 'hidden'\n const side = (name: 'top' | 'right' | 'bottom' | 'left', axis: 'block' | 'inline') =>\n (firstCSSNumber(style, `padding-${name}`, `padding-${axis}`, 'padding') ?? 0) +\n (bordered ? (firstCSSNumber(style, `border-${name}-width`, 'border-width') ?? 0) : 0)\n return {\n width: side('left', 'inline') + side('right', 'inline'),\n height: side('top', 'block') + side('bottom', 'block')\n }\n}\n\n/** Explicit sizes count the padding and borders CSS places outside them. */\nfunction applyBoxSizing(node: SceneNode, style: DesignStyleDeclaration): void {\n const extras = contentBoxExtras(style)\n const width = firstCSSNumber(style, 'width')\n const height = firstCSSNumber(style, 'height')\n // A size `aspect-ratio` derives from the other is a content size too.\n const ratio = aspectRatioFromCSS(pickStyle(style, 'aspect-ratio')) !== null\n if (extras.width > 0) {\n if (width !== null || (ratio && height !== null)) node.width += extras.width\n if (node.minWidth !== null) node.minWidth += extras.width\n if (node.maxWidth !== null) node.maxWidth += extras.width\n }\n if (extras.height > 0) {\n if (height !== null || (ratio && width !== null)) node.height += extras.height\n if (node.minHeight !== null) node.minHeight += extras.height\n if (node.maxHeight !== null) node.maxHeight += extras.height\n }\n}\n\nfunction applyPadding(node: SceneNode, style: DesignStyleDeclaration): void {\n node.paddingTop = firstCSSNumber(style, 'padding-top', 'padding-block', 'padding') ?? 0\n node.paddingRight = firstCSSNumber(style, 'padding-right', 'padding-inline', 'padding') ?? 0\n node.paddingBottom = firstCSSNumber(style, 'padding-bottom', 'padding-block', 'padding') ?? 0\n node.paddingLeft = firstCSSNumber(style, 'padding-left', 'padding-inline', 'padding') ?? 0\n}\n\nfunction imageScaleModeFromObjectFit(value: string | undefined): ImageScaleMode | null {\n if (value === 'contain' || value === 'scale-down') return 'FIT'\n if (value === 'cover') return 'FILL'\n return null\n}\n\nfunction bytesFromDataURL(value: string | undefined): Uint8Array | null {\n if (!value?.startsWith('data:')) return null\n const commaIndex = value.indexOf(',')\n if (commaIndex === -1) return null\n const metadata = value.slice(0, commaIndex)\n const body = value.slice(commaIndex + 1)\n // Invalid Base64 in imported HTML drops that image instead of the whole import.\n if (!metadata.endsWith(';base64') || !isValid(body)) return null\n return toUint8Array(body)\n}\n\nfunction applyImageFill(\n graph: SceneGraph,\n node: SceneNode,\n element: DesignElement,\n style: DesignStyleDeclaration\n): void {\n if (element.tagName.toLowerCase() !== 'img') return\n const source = element.attrs.src\n const bytes = bytesFromDataURL(source)\n if (!bytes) {\n if (source) {\n node.pluginData = [\n ...node.pluginData,\n { pluginId: DOM_CSS_PLUGIN_ID, key: IMAGE_SOURCE_URL_KEY, value: source }\n ]\n }\n return\n }\n\n const imageHash = computeImageHash(bytes)\n graph.images.set(imageHash, bytes)\n node.fills = [\n {\n type: 'IMAGE',\n imageHash,\n imageScaleMode: imageScaleModeFromObjectFit(pickStyle(style, 'object-fit')) ?? 'FILL',\n color: TRANSPARENT,\n opacity: 1,\n visible: true\n }\n ]\n}\n\nfunction applyElementStyle(\n graph: SceneGraph,\n node: SceneNode,\n element: DesignElement,\n style: DesignStyleDeclaration\n): void {\n setNodeBox(node, style)\n applyBoxSizing(node, style)\n applyPositioning(node, style)\n applyPadding(node, style)\n\n const background = backgroundPaint(graph, style, node)\n if (background.fills.length > 0) node.fills = background.fills\n for (const layer of background.layers) addBackgroundLayer(graph, node, layer)\n applyImageFill(graph, node, element, style)\n\n const strokes = colorToStrokeFromCSS(\n firstStrokeColor(style),\n strokeWeightFromStyle(style)?.toString()\n )\n if (strokes.length > 0) {\n const dashPattern = dashPatternFromCSS(style, strokes[0].weight)\n if (dashPattern.length > 0) {\n strokes[0].dashPattern = dashPattern\n node.dashPattern = dashPattern\n }\n node.strokes = strokes\n setBorderWeights(node, style, strokes[0])\n // A CSS border takes room: content sits inside it, as auto layout with strokes included does.\n node.strokesIncludedInLayout = true\n }\n\n const effects = cssShadows(pickStyle(style, 'box-shadow'))\n if (effects.length > 0) node.effects = normalizeEffects(effects)\n\n const opacity = parseCSSNumber(pickStyle(style, 'opacity'))\n if (opacity !== null) node.opacity = opacity\n\n applyCornerRadii(node, style)\n\n const overflow = pickStyle(style, 'overflow')\n if (overflow === 'hidden' || overflow === 'clip') node.clipsContent = true\n\n const alignSelf = parseCSSAlignSelf(pickStyle(style, 'align-self')) ?? 'AUTO'\n if (alignSelf !== 'AUTO') node.layoutAlignSelf = alignSelf\n}\n\nconst CHARACTER_FIELDS = [\n 'fontFamily',\n 'fontSize',\n 'fontWeight',\n 'italic',\n 'letterSpacing',\n 'lineHeight',\n 'fills',\n 'textDecoration',\n 'textDecorationStyle',\n 'textDecorationThickness',\n 'textDecorationFills',\n 'textDecorationSkipInk',\n 'textUnderlineOffset',\n 'textCase'\n] as const satisfies readonly (keyof CSSCharacterStyle)[]\n\nfunction applyTextStyle(node: SceneNode, style: DesignStyleDeclaration): void {\n setNodeBox(node, style)\n applyPositioning(node, style)\n Object.assign(node, characterStyleFromCSS(style, pick(node, CHARACTER_FIELDS)))\n\n const opacity = parseCSSNumber(pickStyle(style, 'opacity'))\n if (opacity !== null) node.opacity = opacity\n\n const effects = cssShadows(pickStyle(style, 'text-shadow'))\n if (effects.length > 0) node.effects = normalizeEffects(effects)\n\n const textAlign = pickStyle(style, 'text-align')?.toUpperCase()\n if (textAlign === 'CENTER' || textAlign === 'RIGHT' || textAlign === 'JUSTIFIED') {\n node.textAlignHorizontal = textAlign\n }\n\n if (pickStyle(style, 'white-space') === 'nowrap') node.maxLines = 1\n}\n\n/**\n * Text and inline elements, or blocks of text, as one text layer: spans become runs, blocks\n * paragraphs, and lists list paragraphs, as Figma holds rich text.\n */\nfunction createRichTextNode(\n graph: SceneGraph,\n parentId: string,\n element: DesignElement,\n style: DesignStyleDeclaration,\n display: string,\n parentFlow: ParentFlow\n): SceneNode {\n const node = graph.createNode('TEXT', parentId, { name: 'Text' })\n applyTextStyle(node, style)\n const blocks = holdsTextBlocks(element, isPlainElement, isInlineElement)\n const base = pick(node, CHARACTER_FIELDS)\n const rich = blocks ? blockRichText(element, style, base) : inlineRichText(element, style, base)\n node.text = rich.text\n node.name = textLayerName('TEXT', rich.text)\n node.styleRuns = rich.styleRuns\n if (blocks) applyParagraphs(node, rich)\n applyFlowSizing(graph, node, style, display, parentFlow)\n return node\n}\n\n/** Whether an element draws nothing of its own, so its text can join the text around it. */\nfunction isPlainElement(element: DesignElement): boolean {\n return !hasBoxStyle(mergedStyle(element))\n}\n\nfunction isInlineElement(element: DesignElement): boolean {\n const style = mergedStyle(element)\n return elementDisplay(element, style) === 'inline' && !hasBoxStyle(style)\n}\n\n/** Whether the element's children are text in one layer: inline content, or text blocks. */\nfunction holdsRichText(element: DesignElement): boolean {\n if (!element.children.some((child) => child.type === 'element')) return false\n if (holdsTextBlocks(element, isPlainElement, isInlineElement)) return true\n return isInlineContent(element, isInlineElement)\n}\n\nfunction createTextNode(\n graph: SceneGraph,\n parentId: string,\n text: string,\n style: DesignStyleDeclaration,\n display: string,\n parentFlow: ParentFlow\n) {\n const node = graph.createNode('TEXT', parentId, { name: textLayerName('TEXT', text), text })\n applyTextStyle(node, style)\n applyFlowSizing(graph, node, style, display, parentFlow)\n return node\n}\n\n/** A link of text alone links all of it. */\nfunction linkText(node: SceneNode, element: DesignElement): void {\n const hyperlink = elementLink(element)\n if (hyperlink && node.text.length > 0) {\n node.styleRuns = [{ start: 0, length: node.text.length, style: { hyperlink } }]\n }\n}\n\nconst BOX_PROPERTIES = [\n 'aspect-ratio',\n 'background-color',\n 'border-radius',\n 'box-shadow',\n 'display',\n 'height',\n 'width',\n 'min-width',\n 'max-width',\n 'min-height',\n 'max-height',\n 'object-fit',\n 'overflow',\n 'position',\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'flex-wrap',\n 'align-self'\n]\n\nconst PADDING_PROPERTIES = [\n 'padding',\n 'padding-top',\n 'padding-right',\n 'padding-bottom',\n 'padding-left',\n 'padding-block',\n 'padding-inline'\n]\n\nconst BORDER_SIDES = ['top', 'right', 'bottom', 'left'] as const\n\n/** Whether every length of a value is zero, as `0`, `0px`, and `0 0` are. */\nfunction isZeroLength(value: string): boolean {\n return value\n .trim()\n .split(/\\s+/)\n .every((part) => parseCSSNumber(part) === 0)\n}\n\n/** Whether any side's border draws: it has a style other than none and a width other than zero. */\nfunction drawsBorder(style: DesignStyleDeclaration): boolean {\n return BORDER_SIDES.some((side) => {\n const borderStyle = pickStyle(style, `border-${side}-style`) ?? pickStyle(style, 'border-style')\n if (borderStyle === undefined || borderStyle === 'none' || borderStyle === 'hidden')\n return false\n // A styled border without a width is CSS's medium one.\n const width = pickStyle(style, `border-${side}-width`) ?? pickStyle(style, 'border-width')\n return width === undefined || !isZeroLength(width)\n })\n}\n\n/**\n * Whether the element is a box rather than a run of the text around it. Padding and borders of\n * no size, which resets such as Tailwind's give every element, leave it a run.\n */\nfunction hasBoxStyle(style: DesignStyleDeclaration): boolean {\n if (BOX_PROPERTIES.some((property) => pickStyle(style, property) !== undefined)) return true\n if (\n PADDING_PROPERTIES.some((property) => {\n const value = pickStyle(style, property)\n return value !== undefined && !isZeroLength(value)\n })\n ) {\n return true\n }\n return drawsBorder(style)\n}\n\nfunction hasContent(element: DesignElement): boolean {\n return element.children.some((child) => child.type !== 'text' || child.text.trim().length > 0)\n}\n\n/** Whether a child sits in a line of its parent's content or leaves it, rather than a block. */\nfunction isInLine(node: DesignNode): boolean {\n if (node.type === 'text' || node.tagName.toLowerCase() === 'br') return true\n const style = mergedStyle(node)\n const display = elementDisplay(node, style)\n const position = pickStyle(style, 'position')\n return (\n display.startsWith('inline') ||\n display === 'none' ||\n position === 'absolute' ||\n position === 'fixed'\n )\n}\n\n/**\n * Whether a block holds inline content with boxes in it, such as a paragraph with a styled\n * `<code>`, which CSS lays out in lines rather than stacking each run and box.\n */\nfunction holdsInlineBoxes(element: DesignElement): boolean {\n return (\n element.children.some((child) => child.type === 'element') && element.children.every(isInLine)\n )\n}\n\n/** The flow a box lays its children out in, and whether they are one text instead. */\nfunction containerFlow(element: DesignElement, display: string) {\n // A box without content keeps its own size, as an image does, unless it declares a layout.\n const own = hasContent(element) || flowOf(display) === 'flex' ? flowOf(display) : null\n const richText = own !== 'flex' && holdsRichText(element)\n // Inline content that cannot be one text runs in lines that wrap at the block's width.\n const lines = own === 'block' && !richText && holdsInlineBoxes(element)\n const flow: FlowKind | null = lines ? 'inline' : own\n return { flow, richText, lines }\n}\n\n/** Builds a container's children and orders them the way CSS paints them. */\nfunction paintChildren(\n graph: SceneGraph,\n node: SceneNode,\n element: DesignElement,\n style: DesignStyleDeclaration,\n flow: ParentFlow\n): void {\n const children = flow === 'flex' ? element.children.toSorted(byFlexOrder) : element.children\n const painted: PaintedChild[] = []\n for (const child of children) {\n const layer = createDesignNode(graph, node.id, child, flow, inheritedTextStyle(element, style))\n if (layer) painted.push({ layer, style: child.type === 'element' ? mergedStyle(child) : {} })\n }\n applyStacking(graph, node, style, painted)\n}\n\nfunction createElementNode(\n graph: SceneGraph,\n parentId: string,\n element: DesignElement,\n parentFlow: ParentFlow\n): SceneNode | null {\n const style = mergedStyle(element)\n const display = elementDisplay(element, style)\n // A line break between boxes draws nothing; rich text reads it as a new line.\n if (display === 'none' || element.tagName.toLowerCase() === 'br') return null\n if (\n isTextLikeElement(element) &&\n !hasBoxStyle(style) &&\n element.children.every((child) => child.type === 'text')\n ) {\n const text = createTextNode(graph, parentId, textContent(element), style, display, parentFlow)\n linkText(text, element)\n return text\n }\n if (!hasBoxStyle(style) && holdsRichText(element)) {\n return createRichTextNode(graph, parentId, element, style, display, parentFlow)\n }\n\n const node = graph.createNode('FRAME', parentId, {\n // The HTML export writes each layer's own name as `data-name`.\n name: element.attrs['data-name'] || element.attrs.id || element.attrs.class || element.tagName,\n clipsContent: false\n })\n applyElementStyle(graph, node, element, style)\n const { flow, richText, lines } = containerFlow(element, display)\n if (flow) {\n applyContainerLayout(node, element, style, flow)\n if (flow === 'flex') applyFlexGap(node, style)\n if (lines) node.layoutWrap = 'WRAP'\n }\n applyFlowSizing(graph, node, style, display, parentFlow)\n\n // Blocks of text in a box's own flow are one text; a flex box's children are items.\n if (richText) {\n const textStyle = inheritedTextStyle(element, style)\n const textDisplay = flow === 'inline' ? 'inline' : 'block'\n createRichTextNode(graph, node.id, element, textStyle, textDisplay, flow ?? 'none')\n return node\n }\n paintChildren(graph, node, element, style, flow ?? 'none')\n\n return node\n}\n\nfunction flexOrder(node: DesignNode): number {\n return node.type === 'element' ? (parseCSSNumber(pickStyle(mergedStyle(node), 'order')) ?? 0) : 0\n}\n\n/** Flex items in the order CSS places them: by `order`, then as written. */\nfunction byFlexOrder(a: DesignNode, b: DesignNode): number {\n return flexOrder(a) - flexOrder(b)\n}\n\nfunction createDesignNode(\n graph: SceneGraph,\n parentId: string,\n node: DesignNode,\n parentFlow: ParentFlow,\n inheritedStyle: DesignStyleDeclaration = {}\n): SceneNode | null {\n if (node.type === 'text') {\n if (node.text.trim().length === 0) return null\n // Text runs in block flow and flex containers are blocks of their own, as CSS boxes them.\n const display = parentFlow === 'inline' ? 'inline' : 'block'\n return createTextNode(graph, parentId, node.text, inheritedStyle, display, parentFlow)\n }\n\n return createElementNode(graph, parentId, withFieldText(node), parentFlow)\n}\n\n/** Input types whose value is text a person reads in the field. */\nconst TEXT_INPUT_TYPES = new Set([\n '',\n 'text',\n 'email',\n 'search',\n 'url',\n 'tel',\n 'number',\n 'password'\n])\n\n/**\n * A text field with the text a browser draws in it, its value or else its placeholder, as a\n * child: an `<input>` holds no content of its own. A password shows as dots.\n */\nfunction withFieldText(element: DesignElement): DesignElement {\n if (element.tagName.toLowerCase() !== 'input' || element.children.length > 0) return element\n const type = Object.hasOwn(element.attrs, 'type') ? element.attrs.type.trim().toLowerCase() : ''\n if (!TEXT_INPUT_TYPES.has(type)) return element\n const value = element.attrs.value || element.attrs.placeholder\n if (!value) return element\n const text = type === 'password' && element.attrs.value ? '•'.repeat(value.length) : value\n return { ...element, children: [{ type: 'text', text }] }\n}\n\nfunction fitPageToChildren(page: SceneNode, graph: SceneGraph): void {\n const children = graph.getChildren(page.id)\n if (children.length === 0) return\n page.width = Math.max(...children.map((child) => child.x + child.width))\n page.height = Math.max(...children.map((child) => child.y + child.height))\n}\n\nexport function designDocumentToSceneGraph(\n document: DesignDocument,\n options: DesignDocumentToSceneGraphOptions = {}\n): SceneGraph {\n const resolve = options.resolveFontFamily ?? resolveFontFamilyStack\n const resolved: DesignDocument = {\n ...document,\n children: document.children.map((child) => withResolvedFontFamilies(child, resolve))\n }\n const graph = new SceneGraph()\n const page = graph.getPages().find((node) => node.type === 'CANVAS') ?? graph.addPage('DesignDOM')\n\n page.name = options.pageName ?? 'DesignDOM'\n\n for (const child of resolved.children) {\n createDesignNode(graph, page.id, child, 'none')\n }\n\n fitPageToChildren(page, graph)\n return graph\n}\n\nexport type { DesignDocumentToSceneGraphOptions as ToSceneGraphOptions }\n","import type { DesignDocument, DesignNode, DesignStyleDeclaration } from '#dom-css/types'\n\nexport const Fragment = Symbol.for('pairdraw.dom-css.fragment')\n\ntype JSXComponent = (props: JSXElementProps) => JSXChild\nexport type JSXTag = string | JSXComponent | typeof Fragment\nexport type JSXStyleValue = string | number | null | undefined\nexport type JSXStyleObject = Record<string, JSXStyleValue>\nexport type JSXStyleInput = string | JSXStyleObject\nexport type JSXChild = DesignNode | JSXChild[] | string | number | boolean | null | undefined\n\nexport interface JSXElementProps {\n children?: JSXChild\n class?: string\n className?: string\n style?: JSXStyleInput\n key?: string | number\n [name: string]: unknown\n}\n\nfunction cssPropertyName(name: string) {\n if (name.startsWith('--')) return name\n return name.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`)\n}\n\nfunction styleObjectToDeclaration(style: JSXStyleObject): DesignStyleDeclaration | undefined {\n const entries = Object.entries(style)\n .filter(\n (entry): entry is [string, string | number] => entry[1] !== null && entry[1] !== undefined\n )\n .map(([property, value]) => [cssPropertyName(property), String(value)] as const)\n .filter(([, value]) => value.length > 0)\n\n if (entries.length === 0) return undefined\n return Object.fromEntries(entries)\n}\n\n/** Declarations split at `;` outside quotes and parentheses, so `url(data:…;base64,…)` stays whole. */\nfunction splitDeclarations(style: string): string[] {\n const declarations: string[] = []\n let depth = 0\n let quote: string | null = null\n let start = 0\n for (let index = 0; index < style.length; index++) {\n const character = style[index]\n if (quote) {\n if (character === '\\\\') index++\n else if (character === quote) quote = null\n } else if (character === '\"' || character === \"'\") quote = character\n else if (character === '(') depth++\n else if (character === ')') depth = Math.max(0, depth - 1)\n else if (character === ';' && depth === 0) {\n declarations.push(style.slice(start, index))\n start = index + 1\n }\n }\n declarations.push(style.slice(start))\n return declarations\n}\n\nfunction styleStringToDeclaration(style: string): DesignStyleDeclaration | undefined {\n const entries = splitDeclarations(style)\n .map((declaration) => {\n const colon = declaration.indexOf(':')\n if (colon === -1) return ['', ''] as const\n const property = declaration.slice(0, colon).trim()\n return [property.toLowerCase(), declaration.slice(colon + 1).trim()] as const\n })\n .filter(([property, value]) => property.length > 0 && value.length > 0)\n\n if (entries.length === 0) return undefined\n return Object.fromEntries(entries)\n}\n\nfunction styleToDeclaration(style: JSXStyleInput | undefined): DesignStyleDeclaration | undefined {\n if (typeof style === 'string') return styleStringToDeclaration(style)\n if (style) return styleObjectToDeclaration(style)\n return undefined\n}\n\nfunction attributeValue(value: unknown): string | undefined {\n if (value === null || value === undefined || value === false) return undefined\n if (value === true) return ''\n if (typeof value === 'string') return value\n if (typeof value === 'number' || typeof value === 'bigint') return String(value)\n return undefined\n}\n\nfunction propsToAttrs(props: JSXElementProps): Record<string, string> {\n const attrs: Record<string, string> = {}\n const classValue = props.class ?? props.className\n if (classValue) attrs.class = classValue\n\n for (const [name, value] of Object.entries(props)) {\n if (name === 'children' || name === 'class' || name === 'className' || name === 'style') {\n continue\n }\n if (name === 'key' || name.startsWith('on')) continue\n const attr = attributeValue(value)\n if (attr !== undefined) attrs[name] = attr\n }\n\n return attrs\n}\n\nfunction normalizeChild(child: JSXChild, nodes: DesignNode[]): void {\n if (child === null || child === undefined || typeof child === 'boolean') return\n if (Array.isArray(child)) {\n for (const item of child) normalizeChild(item, nodes)\n return\n }\n if (typeof child === 'string' || typeof child === 'number') {\n nodes.push({ type: 'text', text: String(child) })\n return\n }\n nodes.push(child)\n}\n\nfunction normalizeJSXChildren(children: JSXChild): DesignNode[] {\n const nodes: DesignNode[] = []\n normalizeChild(children, nodes)\n return nodes\n}\n\nexport function jsx(tag: JSXTag, props: JSXElementProps = {}): DesignNode | DesignNode[] {\n if (tag === Fragment) return normalizeJSXChildren(props.children)\n if (typeof tag === 'function') return normalizeJSXChildren(tag(props))\n\n return {\n type: 'element',\n tagName: tag,\n attrs: propsToAttrs(props),\n inlineStyle: styleToDeclaration(props.style),\n children: normalizeJSXChildren(props.children)\n }\n}\n\nexport const jsxs = jsx\n\nexport function jsxToDesignDocumentCore(input: JSXChild): DesignDocument {\n return {\n type: 'document',\n children: normalizeJSXChildren(input)\n }\n}\n\nexport namespace JSX {\n export type Element = DesignNode | DesignNode[]\n export interface ElementChildrenAttribute {\n children: unknown\n }\n export interface IntrinsicElements {\n [tagName: string]: JSXElementProps\n }\n}\n","import type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { mergeCSSText } from './import/css-text'\nimport { jsxToDesignDocumentCore, type JSXChild } from './import/jsx/core'\nexport { resolveFontFamilyStack, type FontStackOptions } from './import/fonts'\nimport { designDocumentToSceneGraph, type ToSceneGraphOptions } from './import/scene-graph'\nimport type { CompileTailwindCSSOptions } from './import/tailwind'\nimport { createBrowserCSSRuntime, type BrowserCSSRuntimeOptions } from './runtime/browser/runtime'\nimport type { CSSComputeOptions, DesignDocument } from './types'\n\nexport { Fragment, jsx, jsxs } from './import/jsx/core'\nexport type { JSXChild, JSXElementProps, JSXStyleInput, JSXTag } from './import/jsx/core'\n\nexport interface BrowserToDesignDocumentOptions extends BrowserCSSRuntimeOptions {\n cssText?: string\n compute?: CSSComputeOptions\n signal?: AbortSignal\n}\n\nexport type BrowserHTMLToDesignDocumentOptions = BrowserToDesignDocumentOptions\n\nexport interface BrowserHTMLToSceneGraphOptions\n extends BrowserToDesignDocumentOptions, ToSceneGraphOptions {}\n\nexport interface BrowserTailwindHTMLToDesignDocumentOptions\n extends Omit<BrowserHTMLToDesignDocumentOptions, 'cssText'>, CompileTailwindCSSOptions {}\n\nexport interface BrowserTailwindHTMLToSceneGraphOptions\n extends BrowserTailwindHTMLToDesignDocumentOptions, ToSceneGraphOptions {}\n\nexport interface BrowserToSceneGraphOptions\n extends BrowserToDesignDocumentOptions, ToSceneGraphOptions {}\n\nexport interface BrowserTailwindToDesignDocumentOptions\n extends Omit<BrowserToDesignDocumentOptions, 'cssText'>, CompileTailwindCSSOptions {}\n\nexport interface BrowserTailwindToSceneGraphOptions\n extends BrowserTailwindToDesignDocumentOptions, ToSceneGraphOptions {}\n\nfunction createRuntime(options: BrowserCSSRuntimeOptions) {\n return createBrowserCSSRuntime({ sandbox: 'iframe', ...options })\n}\n\nasync function compileBrowserTailwindCSS(\n candidates: string | Iterable<string>,\n options: CompileTailwindCSSOptions\n): Promise<string> {\n const { compileTailwindCSS } = await import('./import/tailwind')\n return compileTailwindCSS(candidates, options)\n}\n\nfunction resolveBrowserDocument(documentOverride: Document | undefined): Document {\n if (documentOverride) return documentOverride\n if (typeof document === 'undefined') {\n throw new TypeError('Browser DOM/CSS helpers require a DOM document')\n }\n return document\n}\n\nfunction extractEmbeddedCSSText(html: string, browserDocument: Document): string | undefined {\n const Parser = browserDocument.defaultView?.DOMParser\n if (!Parser) throw new TypeError('Browser DOM/CSS helpers require DOMParser')\n const parsed = new Parser().parseFromString(html, 'text/html')\n const styles = Array.from(parsed.querySelectorAll('style'))\n .map((style) => (style.textContent ? style.textContent.trim() : ''))\n .filter((css): css is string => !!css)\n return styles.length > 0 ? styles.join('\\n') : undefined\n}\n\nexport async function browserHTMLToDesignDocument(\n html: string,\n options: BrowserHTMLToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n options.signal?.throwIfAborted()\n const browserDocument = resolveBrowserDocument(options.document)\n const runtime = createRuntime({ ...options, document: browserDocument })\n const document = runtime.parseHTML(html)\n const cssText = mergeCSSText(extractEmbeddedCSSText(html, browserDocument), options.cssText)\n return runtime.computeStyles(document, cssText, options.compute)\n}\n\nexport async function browserHTMLToSceneGraph(\n html: string,\n options: BrowserHTMLToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await browserHTMLToDesignDocument(html, options)\n options.signal?.throwIfAborted()\n const graph = designDocumentToSceneGraph(document, options)\n options.signal?.throwIfAborted()\n return graph\n}\n\nexport async function browserTailwindHTMLToDesignDocument(\n html: string,\n candidates: string | Iterable<string>,\n options: BrowserTailwindHTMLToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const cssText = await compileBrowserTailwindCSS(candidates, options)\n return browserHTMLToDesignDocument(html, { ...options, cssText })\n}\n\nexport async function browserTailwindHTMLToSceneGraph(\n html: string,\n candidates: string | Iterable<string>,\n options: BrowserTailwindHTMLToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await browserTailwindHTMLToDesignDocument(html, candidates, options)\n options.signal?.throwIfAborted()\n const graph = designDocumentToSceneGraph(document, options)\n options.signal?.throwIfAborted()\n return graph\n}\n\nexport async function browserJSXToDesignDocument(\n input: JSXChild,\n options: BrowserToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const document = jsxToDesignDocumentCore(input)\n const runtime = createRuntime(options)\n return runtime.computeStyles(document, options.cssText, options.compute)\n}\n\nexport async function browserJSXToSceneGraph(\n input: JSXChild,\n options: BrowserToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await browserJSXToDesignDocument(input, options)\n return designDocumentToSceneGraph(document, options)\n}\n\nexport async function browserTailwindJSXToDesignDocument(\n input: JSXChild,\n candidates: string | Iterable<string>,\n options: BrowserTailwindToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const cssText = await compileBrowserTailwindCSS(candidates, options)\n return browserJSXToDesignDocument(input, { ...options, cssText })\n}\n\nexport async function browserTailwindJSXToSceneGraph(\n input: JSXChild,\n candidates: string | Iterable<string>,\n options: BrowserTailwindToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await browserTailwindJSXToDesignDocument(input, candidates, options)\n return designDocumentToSceneGraph(document, options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAM,4BAAiC,IAAI,IAAI,CAAC,UAAU,OAAO,CAAC;;AAGlE,MAA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,CAAC,GAClB;CAErB,OAAO,2BAA2B,MADX,2BAA2B,OAAO,OAAO,GACpB,OAAO;AACrD;AAEA,eAAsB,mCACpB,OACA,YACA,UAAkD,CAAC,GAC1B;CACzB,MAAM,UAAU,MAAM,0BAA0B,YAAY,OAAO;CACnE,OAAO,2BAA2B,OAAO;EAAE,GAAG;EAAS;CAAQ,CAAC;AAClE;AAEA,eAAsB,+BACpB,OACA,YACA,UAA8C,CAAC,GAC1B;CAErB,OAAO,2BAA2B,MADX,mCAAmC,OAAO,YAAY,OAAO,GACxC,OAAO;AACrD"}
|
|
1
|
+
{"version":3,"file":"browser.js","names":["splitDeclarations","resolveBrowserDocument","bytesFromDataURL"],"sources":["../../src/runtime/css/scan.ts","../../src/runtime/css/url.ts","../../src/runtime/browser/sandbox.ts","../../src/runtime/browser/runtime.ts","../../src/import/css-values.ts","../../src/import/flow.ts","../../src/import/css-text.ts","../../src/import/background-pictures.ts","../../src/import/fonts.ts","../../src/import/stacking.ts","../../src/import/text.ts","../../src/import/scene-graph.ts","../../src/import/jsx/core.ts","../../src/browser.ts"],"sourcesContent":["/** Where a CSS scan stopped, and the quote or parenthesis it left open. */\nexport interface CSSScan {\n /** The index whose visit asked to stop, or -1 when the text ended first. */\n stop: number\n quote: boolean\n depth: number\n}\n\n/**\n * Visits each character outside quotes with its parenthesis depth after the character, so a\n * caller can find a matching parenthesis or split at a top-level separator. An escaped character\n * inside a quote is skipped, as CSS reads it.\n */\nexport function scanCSS(\n text: string,\n from: number,\n visit: (character: string, index: number, depth: number) => boolean | undefined\n): CSSScan {\n let quote = ''\n let depth = 0\n for (let index = from; index < text.length; index++) {\n const character = text[index]\n if (quote) {\n if (character === '\\\\') index += 1\n else if (character === quote) quote = ''\n continue\n }\n if (character === '\"' || character === \"'\") {\n quote = character\n continue\n }\n if (character === '(') {\n depth += 1\n continue\n }\n if (character === ')') depth -= 1\n if (visit(character, index, depth)) return { stop: index, quote: quote !== '', depth }\n }\n return { stop: -1, quote: quote !== '', depth }\n}\n\n/** The index of the `)` closing a function whose arguments start at `from`, or -1 when unclosed. */\nexport function closingParen(css: string, from: number): number {\n return scanCSS(css, from, (_character, _index, depth) => depth < 0).stop\n}\n","import { scanCSS } from './scan'\n\n/**\n * CSS spellings that a plain text match misses: `\\72` is `r`, and a comment splits `url` in two.\n * The styling sandbox decides on the decoded text, so an escaped or commented spelling cannot\n * make it load a resource.\n */\nconst CSS_ESCAPE = /\\\\([0-9a-f]{1,6})\\s?/gi\nconst CSS_COMMENT = /\\/\\*[\\s\\S]*?\\*\\//g\n\n/** A stylesheet value with its comments removed and its escapes decoded, as CSS parses it. */\nexport function decodedCSS(text: string): string {\n return text.replace(CSS_COMMENT, '').replace(CSS_ESCAPE, (_, hex: string) => {\n const code = Number.parseInt(hex, 16)\n return code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : ''\n })\n}\n\n/** Whether a declaration or rule loads a picture, in any spelling CSS allows. */\nexport function mentionsURL(text: string): boolean {\n return /url\\s*\\(/i.test(decodedCSS(text))\n}\n\n/** Whether text can load anything: `url()`, `image-set()`, or a stylesheet import. */\nexport function mentionsResource(text: string): boolean {\n return /url\\s*\\(|image-set\\s*\\(|@import/i.test(decodedCSS(text))\n}\n\n/** A resource that loads nothing over the network: an inline value or a document fragment. */\nconst LOCAL_RESOURCE = /^(?:data:|#|about:blank$)/i\n\nexport function isLocalResource(value: string): boolean {\n return LOCAL_RESOURCE.test(value.trim())\n}\n\n/** Every resource the text names is local, so keeping it cannot fetch anything. */\nexport function resourcesAreLocal(text: string): boolean {\n const decoded = decodedCSS(text)\n if (/@import/i.test(decoded)) return false\n for (const match of decoded.matchAll(/url\\(\\s*(?:\"([^\"]*)\"|'([^']*)'|([^)]*))\\s*\\)/gi)) {\n if (!isLocalResource(match[1] || match[2] || match[3] || '')) return false\n }\n for (const match of decoded.matchAll(/image-set\\s*\\(([^)]*)\\)/gi)) {\n for (const candidate of match[1].matchAll(/\"([^\"]*)\"|'([^']*)'/g)) {\n if (!isLocalResource(candidate[1] || candidate[2] || '')) return false\n }\n }\n return true\n}\n\n/**\n * A declaration list split on semicolons outside quotes and parentheses; null when a quote or\n * parenthesis is unclosed, so a malformed style fails closed instead of being cut into fragments.\n */\nexport function splitDeclarations(text: string): string[] | null {\n const parts: string[] = []\n let start = 0\n const scan = scanCSS(text, 0, (character, index, depth) => {\n if (character !== ';' || depth !== 0) return\n parts.push(text.slice(start, index))\n start = index + 1\n })\n if (scan.quote || scan.depth !== 0) return null\n parts.push(text.slice(start))\n return parts\n}\n\n/** A declaration list with every part that can load a resource dropped. */\nexport function withoutResourceDeclarations(text: string): string {\n const parts = splitDeclarations(decodedCSS(text).replace(/@import[^;{}]*;?/gi, ''))\n if (!parts) return ''\n return parts\n .map((part) => part.trim())\n .filter((part) => part.length > 0 && (!mentionsResource(part) || resourcesAreLocal(part)))\n .join('; ')\n}\n\n/**\n * A pasted stylesheet with its resource-loading declarations and imports removed, keeping the\n * rules that only style. A block the flat scan cannot take apart is dropped whole.\n */\nexport function withoutResourceRules(cssText: string): string {\n const cleaned = decodedCSS(cssText)\n .replace(/@import[^;{}]*;?/gi, '')\n .replace(/([^{}]*)\\{([^{}]*)\\}/g, (_, selector: string, body: string) => {\n const declarations = withoutResourceDeclarations(body)\n return declarations.length > 0 ? `${selector.trim()} { ${declarations} }` : ''\n })\n // Nested at-rules or malformed blocks may survive the flat scan; fail closed rather than leave\n // a spelling the scan did not understand in the styling document.\n return resourcesAreLocal(cleaned) ? cleaned : ''\n}\n","import { serializeHTML } from '#dom-css/export/html'\nimport { closingParen } from '#dom-css/runtime/css/scan'\nimport {\n decodedCSS,\n isLocalResource,\n mentionsResource,\n resourcesAreLocal,\n withoutResourceDeclarations,\n withoutResourceRules\n} from '#dom-css/runtime/css/url'\nimport type {\n DesignDocument,\n DesignElement,\n DesignNode,\n DesignStyleDeclaration,\n DesignText\n} from '#dom-css/types'\n\n/** Elements that hold a document or code of their own; a script is emptied, a style is cleaned. */\nconst CODE_TAGS: ReadonlySet<string> = new Set(['script', 'style'])\n\n/** Elements that load another document; their fallback content stays, the element does not. */\nconst EMBEDDED_TAGS: ReadonlySet<string> = new Set([\n 'applet',\n 'embed',\n 'frame',\n 'frameset',\n 'iframe',\n 'object'\n])\n\n/**\n * `value` without the characters a browser ignores inside a URL scheme: controls and space, so\n * `java\\tscript:` runs as `javascript:`.\n */\nfunction withoutSchemeNoise(value: string): string {\n let plain = ''\n for (const char of value) if (char.charCodeAt(0) > 0x20) plain += char\n return plain\n}\n\n/** A URL a browser runs as script or reads as a document of its own. */\nconst EXECUTABLE_URL = /^(?:javascript|vbscript|data:text\\/html)/i\n\n/** Whether the browser would run this attribute: an event handler or an executable URL. */\nfunction executableAttribute(name: string, value: string): boolean {\n const attribute = name.toLowerCase()\n if (attribute.startsWith('on') || attribute === 'srcdoc') return true\n return EXECUTABLE_URL.test(withoutSchemeNoise(value))\n}\n\n/**\n * The styling sandbox inserts pasted code into a live document, where every external address it\n * names is fetched: image sources, frames, stylesheets, inline `url()`s, and a pasted stylesheet's\n * rules. This module builds the markup and CSS the sandbox may see, and only that: the design\n * document keeps the original addresses, so the importer still records an image's source as its\n * asset reference.\n */\nexport interface SandboxContent {\n html: string\n css: string\n}\n\n/** `url(...)` in a style attribute, an inline style value, or a stylesheet rule. */\nconst URL_FUNCTION = /url\\(\\s*(?:\"([^\"]*)\"|'([^']*)'|([^)]*))\\s*\\)/gi\n\n/** A stylesheet loaded from elsewhere; the sanitizer drops it too, but not from JSX or CSS text. */\nconst CSS_IMPORT = /@import[^;]*;?/gi\n\n/** Attributes naming a resource the sandbox would load as soon as the element is live. */\nconst URL_ATTRIBUTES: Record<string, boolean> = {\n src: true,\n srcset: true,\n imagesrcset: true,\n poster: true,\n background: true,\n srcdoc: true,\n data: true,\n action: true,\n formaction: true,\n cite: true,\n ping: true,\n manifest: true,\n longdesc: true,\n profile: true,\n usemap: true\n}\n\n/** Elements whose `href` addresses another document; everywhere else `href` may stay a link. */\nconst LINK_ELEMENTS: Record<string, boolean> = { a: true, area: true }\n\n/** The replacement for an address the sandbox must not fetch: a valid, local, empty resource. */\nconst INERT_URL = 'url(\"data:,\")'\n\n/** Every candidate address in a comma-separated `srcset` is local, so none of them is fetched. */\nfunction isLocalSrcset(value: string): boolean {\n return value.split(',').every((candidate) => {\n const address = candidate.trim().split(/\\s+/)[0]\n return !address || isLocalResource(address)\n })\n}\n\n/** A quoted image candidate, as `image-set(\"…\" 1x)` takes instead of a `url()`. */\nconst QUOTED_CANDIDATE = /\"([^\"]*)\"|'([^']*)'/g\n\n/** `image-set(...)` and its WebKit spelling, whose arguments may hold quoted image sources. */\nconst IMAGE_SET_OPEN = /(?:-webkit-)?image-set\\s*\\(/gi\n\n/** A quoted value that is local, or the inert one; an image-set candidate without `url()`. */\nfunction localCandidate(token: string, double?: string, single?: string): string {\n return isLocalResource(double || single || '') ? token : '\"data:,\"'\n}\n\n/** Every quoted source inside each `image-set(...)`, rewritten when it is not local. */\nfunction withLocalImageSets(css: string): string {\n let result = ''\n let last = 0\n for (const match of css.matchAll(IMAGE_SET_OPEN)) {\n const start = match.index + match[0].length\n const end = closingParen(css, start)\n if (end === -1) break\n result +=\n css.slice(last, start) + css.slice(start, end).replace(QUOTED_CANDIDATE, localCandidate)\n last = end\n }\n return result + css.slice(last)\n}\n\n/** Style text and stylesheets with every fetchable resource replaced, so a pasted rule loads none. */\nfunction withLocalResources(value: string): string {\n const urls = value.replace(\n URL_FUNCTION,\n (match, double: string, single: string, bare: string) => {\n const target = double || single || bare\n return isLocalResource(target) ? match : INERT_URL\n }\n )\n return withLocalImageSets(urls)\n}\n\n/** A pasted stylesheet, without its imports and with only local resources it may load. */\nfunction sandboxCSS(cssText: string): string {\n return withLocalResources(decodedCSS(cssText).replace(CSS_IMPORT, ''))\n}\n\nfunction sandboxStyle(\n style: DesignStyleDeclaration | undefined\n): DesignStyleDeclaration | undefined {\n return (\n style &&\n Object.fromEntries(\n Object.entries(style).filter(\n ([, value]) => !mentionsResource(value) || resourcesAreLocal(value)\n )\n )\n )\n}\n\nfunction sandboxAttribute(element: DesignElement, name: string, value: string): string {\n const lower = name.toLowerCase()\n if (lower === 'style') return withoutResourceDeclarations(value)\n if (lower === 'srcset' || lower === 'imagesrcset') return isLocalSrcset(value) ? value : ''\n if (lower === 'href' || lower === 'xlink:href') {\n return LINK_ELEMENTS[element.tagName.toLowerCase()] || isLocalResource(value) ? value : ''\n }\n if (URL_ATTRIBUTES[lower]) return isLocalResource(value) ? value : ''\n // SVG paints images, filters, masks, and clip paths through `url()` in their own attributes.\n if (mentionsResource(value)) return resourcesAreLocal(value) ? value : ''\n return value\n}\n\nfunction sandboxChildren(element: DesignElement): DesignNode[] {\n const tagName = element.tagName.toLowerCase()\n // A `<style>` element is applied when inserted; HTML parsing drops it and reads its text as CSS,\n // but a JSX paste can bring one, so its text gets the same rule.\n if (tagName === 'style') {\n // The live `<style>` reads only its own text; an element child would serialize its text as\n // raw CSS, so only text children stay and each is cleaned as a stylesheet.\n return element.children\n .filter((child): child is DesignText => child.type === 'text')\n .map((child) => ({ ...child, text: withoutResourceRules(child.text) }))\n }\n if (CODE_TAGS.has(tagName)) return []\n return element.children.map(sandboxNode)\n}\n\nfunction sandboxNode(node: DesignNode): DesignNode {\n if (node.type === 'text') return node\n const tagName = node.tagName.toLowerCase()\n const attrs = Object.fromEntries(\n Object.entries(node.attrs)\n .filter(([name, value]) => !executableAttribute(name, value))\n .map(([name, value]) => [name, sandboxAttribute(node, name, value)])\n )\n return {\n ...node,\n // A script or an embedded document becomes a plain box; the element's own styles still apply.\n tagName:\n (CODE_TAGS.has(tagName) && tagName !== 'style') || EMBEDDED_TAGS.has(tagName)\n ? 'div'\n : node.tagName,\n attrs,\n inlineStyle: sandboxStyle(node.inlineStyle),\n children: sandboxChildren(node),\n ...(node.shader?.frame && !isLocalResource(node.shader.frame)\n ? { shader: { ...node.shader, frame: undefined } }\n : {})\n }\n}\n\n/** The design document as the styling sandbox may see it: same tree, no fetchable address. */\nfunction sandboxDocument(document: DesignDocument): DesignDocument {\n return { ...document, children: document.children.map(sandboxNode) }\n}\n\n/** Exactly what a styling sandbox inserts: the markup it assigns, and the CSS it applies. */\nexport function sandboxContent(document: DesignDocument, cssText: string): SandboxContent {\n return { html: serializeHTML(sandboxDocument(document)), css: sandboxCSS(cssText) }\n}\n","import { serializeHTML } from '#dom-css/export/html'\nimport type {\n CSSComputeOptions,\n CSSRuntime,\n DesignDocument,\n DesignElement,\n DesignNode\n} from '#dom-css/types'\n\nimport { sandboxContent } from './sandbox'\n\nexport interface BrowserCSSRuntimeOptions {\n document?: Document\n sandbox?: 'shadow-root' | 'iframe'\n}\n\nconst DEFAULT_COMPUTED_PROPERTIES = [\n 'align-items',\n 'aspect-ratio',\n 'background-color',\n 'background-clip',\n 'background-image',\n 'background-origin',\n 'border-bottom-color',\n 'border-bottom-style',\n 'border-bottom-left-radius',\n 'border-bottom-right-radius',\n 'border-bottom-width',\n 'border-left-color',\n 'border-left-style',\n 'border-left-width',\n 'border-radius',\n 'border-right-color',\n 'border-right-style',\n 'border-right-width',\n 'border-top-color',\n 'border-top-style',\n 'border-top-left-radius',\n 'border-top-right-radius',\n 'border-top-width',\n 'box-shadow',\n 'box-sizing',\n 'color',\n 'column-gap',\n 'display',\n 'align-self',\n 'bottom',\n 'flex-direction',\n 'flex-wrap',\n 'font-family',\n 'font-size',\n 'font-style',\n 'font-weight',\n 'gap',\n 'grid-column',\n 'grid-row',\n 'grid-template-columns',\n 'grid-template-rows',\n 'height',\n 'justify-content',\n 'letter-spacing',\n 'left',\n 'line-height',\n 'max-height',\n 'max-width',\n 'min-height',\n 'isolation',\n 'min-width',\n 'object-fit',\n 'opacity',\n 'overflow',\n 'padding-bottom',\n 'padding-left',\n 'padding-right',\n 'padding-top',\n 'position',\n 'right',\n 'row-gap',\n 'text-align',\n 'text-decoration-line',\n 'text-shadow',\n 'text-transform',\n 'top',\n 'white-space',\n 'width',\n 'z-index'\n] as const\n\nfunction resolveBrowserDocument(documentOverride: Document | undefined): Document {\n if (documentOverride) return documentOverride\n if (typeof document === 'undefined') {\n throw new TypeError('Browser CSS runtime requires a DOM document')\n }\n return document\n}\n\nfunction attributesToRecord(element: Element): Record<string, string> {\n const attrs: Record<string, string> = {}\n for (const attr of Array.from(element.attributes)) {\n // Event handlers draw nothing, and the styled copy of the markup must not run them.\n if (attr.name.toLowerCase().startsWith('on')) continue\n attrs[attr.name] = attr.value\n }\n return attrs\n}\n\nfunction styleToRecord(style: CSSStyleDeclaration): Record<string, string> | undefined {\n const entries: Record<string, string> = {}\n for (const property of Array.from(style)) {\n const value = style.getPropertyValue(property)\n if (value) entries[property] = value\n }\n return Object.keys(entries).length > 0 ? entries : undefined\n}\n\nconst NON_RENDERED_TAGS = new Set(['head', 'link', 'meta', 'script', 'style', 'template', 'title'])\n\nfunction domNodeToDesignNode(node: Node): DesignNode | null {\n if (node.nodeType === 3) {\n const text = node.textContent ?? ''\n return text.length > 0 ? { type: 'text', text } : null\n }\n\n if (node.nodeType !== 1) return null\n\n const element = node as Element\n if (NON_RENDERED_TAGS.has(element.tagName.toLowerCase())) return null\n const children = Array.from(element.childNodes)\n .map(domNodeToDesignNode)\n .filter((child): child is DesignNode => child !== null)\n const style = 'style' in element ? (element.style as CSSStyleDeclaration) : undefined\n\n return {\n type: 'element',\n tagName: element.tagName.toLowerCase(),\n attrs: attributesToRecord(element),\n children,\n inlineStyle: style ? styleToRecord(style) : undefined\n }\n}\n\nfunction parseHTMLWithDocument(browserDocument: Document, html: string): DesignDocument {\n const Parser = browserDocument.defaultView?.DOMParser\n if (!Parser) throw new TypeError('Browser CSS runtime requires DOMParser')\n const parser = new Parser()\n const parsed = parser.parseFromString(html, 'text/html')\n return {\n type: 'document',\n children: Array.from(parsed.body.childNodes)\n .map(domNodeToDesignNode)\n .filter((node): node is DesignNode => node !== null)\n }\n}\n\nfunction collectElementPairs(\n designNode: DesignNode,\n domNode: Node,\n pairs: [DesignElement, Element][]\n): void {\n if (designNode.type === 'text') return\n const view = domNode.ownerDocument?.defaultView\n if (!view || !(domNode instanceof view.Element)) return\n\n pairs.push([designNode, domNode])\n\n const elementChildren = designNode.children.filter(\n (child): child is DesignElement => child.type === 'element'\n )\n const domChildren = Array.from(domNode.children)\n for (const [index, child] of elementChildren.entries()) {\n const domChild = domChildren.at(index)\n if (domChild) collectElementPairs(child, domChild, pairs)\n }\n}\n\nfunction computedStyleToRecord(\n style: CSSStyleDeclaration,\n options: CSSComputeOptions\n): Record<string, string> {\n const entries: Record<string, string> = {}\n const properties = options.includeBrowserDefaults\n ? Array.from(style)\n : DEFAULT_COMPUTED_PROPERTIES\n\n for (const property of properties) {\n const value = style.getPropertyValue(property)\n if (value) entries[property] = value\n }\n\n return entries\n}\n\nfunction requestFrame(browserDocument: Document): Promise<void> {\n const requestAnimationFrame = browserDocument.defaultView?.requestAnimationFrame\n if (!requestAnimationFrame) return Promise.resolve()\n return new Promise((resolve) => {\n requestAnimationFrame(() => resolve())\n })\n}\n\nfunction applySandboxHostStyle(element: HTMLElement): void {\n element.style.cssText = [\n 'position: fixed',\n 'left: -100000px',\n 'top: 0',\n 'width: 1000px',\n 'height: auto',\n 'visibility: hidden',\n 'pointer-events: none',\n 'contain: layout style paint'\n ].join(';')\n}\n\nasync function computeStylesInShadowRoot(\n browserDocument: Document,\n designDocument: DesignDocument,\n cssText: string,\n options: CSSComputeOptions\n): Promise<DesignDocument> {\n const host = browserDocument.createElement('div')\n applySandboxHostStyle(host)\n\n // The sandbox is a live document: only addresses that load nothing may reach it.\n const sandbox = sandboxContent(designDocument, cssText)\n const shadow = host.attachShadow({ mode: 'open' })\n const style = browserDocument.createElement('style')\n style.textContent = sandbox.css\n shadow.append(style)\n\n const content = browserDocument.createElement('div')\n content.innerHTML = sandbox.html\n shadow.append(content)\n browserDocument.body.append(host)\n\n try {\n await requestFrame(browserDocument)\n return copyComputedStyles(designDocument, content, options)\n } finally {\n host.remove()\n }\n}\n\nasync function computeStylesInIframe(\n browserDocument: Document,\n designDocument: DesignDocument,\n cssText: string,\n options: CSSComputeOptions\n): Promise<DesignDocument> {\n const iframe = browserDocument.createElement('iframe')\n applySandboxHostStyle(iframe)\n // Same origin so its styles can be read, without scripts so imported markup never runs.\n iframe.setAttribute('sandbox', 'allow-same-origin')\n browserDocument.body.append(iframe)\n\n try {\n const iframeDocument = iframe.contentDocument\n if (!iframeDocument) throw new TypeError('Browser CSS runtime could not create iframe document')\n iframeDocument.open()\n iframeDocument.write(`<!doctype html><html><head></head><body></body></html>`)\n iframeDocument.close()\n\n // The iframe is a live document: only addresses that load nothing may reach it.\n const sandbox = sandboxContent(designDocument, cssText)\n const style = iframeDocument.createElement('style')\n style.textContent = sandbox.css\n iframeDocument.head.append(style)\n\n const content = iframeDocument.createElement('div')\n content.innerHTML = sandbox.html\n iframeDocument.body.append(content)\n\n // The sandbox sits offscreen, where WebKit never runs an animation frame of its own; the\n // page's frame lays the iframe out too, and the page is visible whenever a person pastes.\n await requestFrame(browserDocument)\n return copyComputedStyles(designDocument, content, options)\n } finally {\n iframe.remove()\n }\n}\n\nfunction copyComputedStyles(\n designDocument: DesignDocument,\n content: Element,\n options: CSSComputeOptions\n): DesignDocument {\n const view = content.ownerDocument.defaultView\n if (!view) throw new TypeError('Browser CSS runtime requires getComputedStyle')\n\n const nextDocument = structuredClone(designDocument)\n const pairs: [DesignElement, Element][] = []\n const domChildren = Array.from(content.childNodes)\n for (const [index, child] of nextDocument.children.entries()) {\n const domChild = domChildren.at(index)\n if (domChild) collectElementPairs(child, domChild, pairs)\n }\n\n for (const [designElement, domElement] of pairs) {\n designElement.computedStyle = computedStyleToRecord(view.getComputedStyle(domElement), options)\n }\n\n return nextDocument\n}\n\nexport function createBrowserCSSRuntime(options: BrowserCSSRuntimeOptions = {}): CSSRuntime {\n const browserDocument = resolveBrowserDocument(options.document)\n const sandbox = options.sandbox ?? 'shadow-root'\n\n return {\n kind: 'browser',\n parseHTML: (html) => parseHTMLWithDocument(browserDocument, html),\n serializeHTML,\n computeStyles: (designDocument, cssText = '', computeOptions = {}) =>\n sandbox === 'iframe'\n ? computeStylesInIframe(browserDocument, designDocument, cssText, computeOptions)\n : computeStylesInShadowRoot(browserDocument, designDocument, cssText, computeOptions)\n }\n}\n","import type { Fill, Stroke } from '@pairdraw/scene-graph'\nimport { parseCSSColor, parseCSSNumber } from '@pairdraw/scene-graph/css'\n\nimport type { DesignStyleDeclaration } from '../types'\n\nexport function colorToFillFromCSS(value: string | undefined): Fill[] {\n const color = parseCSSColor(value)\n if (!color) return []\n return [{ type: 'SOLID', color, opacity: color.a, visible: true }]\n}\n\nexport function colorToStrokeFromCSS(\n colorValue: string | undefined,\n weightValue: string | undefined\n): Stroke[] {\n const color = parseCSSColor(colorValue)\n const weight = parseCSSNumber(weightValue)\n if (!color || weight === null || weight <= 0) return []\n return [{ type: 'SOLID', color, weight, opacity: color.a, visible: true, align: 'INSIDE' }]\n}\n\nexport function pickStyle(elementStyle: DesignStyleDeclaration | undefined, property: string) {\n return elementStyle?.[property]\n}\n\nexport function mergedStyle(node: {\n inlineStyle?: DesignStyleDeclaration\n computedStyle?: DesignStyleDeclaration\n}) {\n return { ...node.inlineStyle, ...node.computedStyle }\n}\n","import { pick } from 'es-toolkit'\n\nimport type { GridTrack, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport {\n parseCSSAlignItems,\n parseCSSFlexDirection,\n parseCSSJustifyContent,\n parseCSSNumber,\n splitCSSValue\n} from '@pairdraw/scene-graph/css'\nimport {\n autoLayoutSizingFields,\n fillSizingFields,\n layoutSizing,\n textAutoResizeFor\n} from '@pairdraw/scene-graph/layout'\n\nimport type { DesignElement, DesignStyleDeclaration } from '../types'\nimport { pickStyle } from './css-values'\n\n/**\n * How CSS lays an element and its children out, mapped onto auto layout: block flow stacks\n * children vertically and stretches block-level ones across, a flex container is a stack in its\n * direction that stretches items across by default, and inline-level content hugs.\n */\nexport type FlowKind = 'block' | 'flex' | 'grid' | 'inline'\n\n/** The layout a child is placed in: its parent's flow, or none at the top of the page. */\nexport type ParentFlow = FlowKind | 'none'\n\n/** Tags browsers lay out in a line by default. */\nexport const INLINE_TAGS = new Set([\n 'a',\n 'abbr',\n 'b',\n 'code',\n 'del',\n 'em',\n 'i',\n 'ins',\n 'kbd',\n 'label',\n 'mark',\n 's',\n 'small',\n 'span',\n 'strong',\n 'sub',\n 'sup',\n 'u'\n])\nconst INLINE_BLOCK_TAGS = new Set(['button', 'img', 'input', 'select', 'textarea'])\n/** Elements browsers center their text in by default. */\nconst CENTERED_TAGS = new Set(['button'])\n\n/** What a run of text takes from its element: the properties CSS inherits, and decoration. */\nconst TEXT_PROPERTIES = [\n 'color',\n 'font-family',\n 'font-size',\n 'font-style',\n 'font-weight',\n 'letter-spacing',\n 'line-height',\n 'text-align',\n 'text-decoration-line',\n 'text-shadow',\n 'text-transform',\n 'white-space'\n]\n\n/**\n * The style a run of text directly inside an element takes from it. The element's own box,\n * position, and opacity stay on the element, so the text is neither placed nor faded twice.\n */\nexport function inheritedTextStyle(\n element: DesignElement,\n style: DesignStyleDeclaration\n): DesignStyleDeclaration {\n const inherited = pick(style, TEXT_PROPERTIES)\n if (!inherited['text-align'] && CENTERED_TAGS.has(element.tagName.toLowerCase())) {\n inherited['text-align'] = 'center'\n }\n return inherited\n}\n\n/** The element's `display`, or the one browsers give its tag by default. */\nexport function elementDisplay(element: DesignElement, style: DesignStyleDeclaration): string {\n const display = pickStyle(style, 'display')?.trim().toLowerCase()\n if (display) return display\n const tag = element.tagName.toLowerCase()\n if (INLINE_TAGS.has(tag)) return 'inline'\n return INLINE_BLOCK_TAGS.has(tag) ? 'inline-block' : 'block'\n}\n\n/**\n * The flow an element lays its own children out in. An `inline-block` sits in a line but holds\n * a block of its own, so only a plain `inline` element lays its children out in a line.\n */\nexport function flowOf(display: string): FlowKind {\n if (display === 'flex' || display === 'inline-flex') return 'flex'\n if (display === 'grid' || display === 'inline-grid') return 'grid'\n return display === 'inline' ? 'inline' : 'block'\n}\n\n/** The most tracks a `repeat()` may expand to, so one value cannot grow a document. */\nconst MAX_GRID_TRACKS = 24\n\n/** One column or row track of a grid, as CSS sizes it. */\nfunction gridTrack(token: string): GridTrack | null {\n const value = token.trim().toLowerCase()\n if (value === 'auto' || value === 'min-content' || value === 'max-content') {\n return { sizing: 'AUTO', value: 0 }\n }\n if (value.startsWith('fit-content(')) return { sizing: 'AUTO', value: 0 }\n if (value.startsWith('minmax(')) {\n const bounds = value.slice('minmax('.length, -1).split(',')\n // A minimum the track cannot exceed keeps the track's smallest size; the maximum sizes it.\n return gridTrack(bounds.at(1) ?? bounds.at(0) ?? '')\n }\n const fraction = /^([\\d.]+)fr$/.exec(value)\n if (fraction) return { sizing: 'FR', value: Number(fraction[1]) }\n const length = /^(-?[\\d.]+)(px|rem|em)$/.exec(value)\n if (length) return { sizing: 'FIXED', value: Number(length[1]) }\n if (/^-?[\\d.]+$/.test(value)) return { sizing: 'FIXED', value: Number(value) }\n return null\n}\n\n/**\n * The tracks a `grid-template-columns` or `grid-template-rows` value names. `undefined` when the\n * value has a track this document cannot place, as `auto-fit` needs a width known at layout time\n * and a percentage track a container size; the caller then keeps the content in block flow.\n */\nexport function gridTracks(value: string | undefined): GridTrack[] | undefined {\n const trimmed = value?.trim()\n if (!trimmed || trimmed === 'none' || trimmed === 'subgrid') return undefined\n const tracks: GridTrack[] = []\n for (const token of splitCSSValue(trimmed)) {\n const repeat = /^repeat\\(\\s*([^,]+),\\s*(.+)\\)$/i.exec(token)\n if (repeat) {\n const count = Number(repeat[1])\n if (!Number.isInteger(count) || count < 1 || count > MAX_GRID_TRACKS) return undefined\n const inner = gridTracks(repeat[2])\n if (!inner || inner.length === 0) return undefined\n for (let index = 0; index < count; index++) tracks.push(...inner)\n continue\n }\n const track = gridTrack(token)\n if (!track) return undefined\n tracks.push(track)\n }\n return tracks.length > 0 && tracks.length <= MAX_GRID_TRACKS ? tracks : undefined\n}\n\n/** The lines `grid-column` or `grid-row` names: a start line and a span, or a bare span. */\nexport function gridLines(value: string | undefined): { start: number; span: number } | null {\n const trimmed = value?.trim().toLowerCase()\n if (!trimmed) return null\n const span = /^span\\s+(\\d+)$/.exec(trimmed)\n if (span) return { start: 0, span: Number(span[1]) }\n const lines = /^(\\d+)\\s*\\/\\s*(?:span\\s+)?(\\d+)$/.exec(trimmed)\n if (lines) {\n const start = Number(lines[1])\n const end = Number(lines[2])\n return { start, span: Math.max(1, end - start) }\n }\n return null\n}\n\n/** Whether the element sits in a line rather than on its own row, so it hugs its content. */\nfunction isInlineLevel(display: string): boolean {\n return display.startsWith('inline')\n}\n\n/** Where a grid places a child, from `grid-column` and `grid-row`. */\nexport function applyGridPlacement(node: SceneNode, style: DesignStyleDeclaration): void {\n const column = gridLines(pickStyle(style, 'grid-column') ?? gridColumnShorthand(style))\n const row = gridLines(pickStyle(style, 'grid-row') ?? gridRowShorthand(style))\n if (!column && !row) return\n node.gridPosition = {\n column: column?.start ?? 0,\n row: row?.start ?? 0,\n columnSpan: Math.max(1, column?.span ?? 1),\n rowSpan: Math.max(1, row?.span ?? 1)\n }\n}\n\n/** `grid-area: 2 / 1 / 4 / 3`, as a start line and a span on each axis. */\nfunction gridColumnShorthand(style: DesignStyleDeclaration): string | undefined {\n const heading = gridAreaLines(style)\n if (!heading) return undefined\n return `${heading.startColumn} / ${heading.endColumn}`\n}\n\nfunction gridRowShorthand(style: DesignStyleDeclaration): string | undefined {\n const heading = gridAreaLines(style)\n if (!heading) return undefined\n return `${heading.startRow} / ${heading.endRow}`\n}\n\nfunction gridAreaLines(style: DesignStyleDeclaration) {\n const parts = pickStyle(style, 'grid-area')\n ?.trim()\n .split(/\\s*\\/\\s*/)\n if (!parts || parts.length < 2) return null\n const startRow = parts.at(0) ?? ''\n const startColumn = parts.at(1) ?? ''\n return {\n startRow,\n startColumn,\n endRow: parts.at(2) ?? startRow,\n endColumn: parts.at(3) ?? startColumn\n }\n}\n\nfunction textAlignAxis(element: DesignElement, style: DesignStyleDeclaration) {\n const align = pickStyle(style, 'text-align')?.trim().toLowerCase()\n if (align === 'center') return 'CENTER'\n if (align === 'right' || align === 'end') return 'MAX'\n if (align) return 'MIN'\n return CENTERED_TAGS.has(element.tagName.toLowerCase()) ? 'CENTER' : 'MIN'\n}\n\n/** The auto layout an element's own flow gives its children. */\nexport function applyContainerLayout(\n node: SceneNode,\n element: DesignElement,\n style: DesignStyleDeclaration,\n flow: FlowKind\n): void {\n if (flow === 'flex') {\n node.layoutMode = parseCSSFlexDirection(pickStyle(style, 'flex-direction')) ?? 'HORIZONTAL'\n node.primaryAxisAlign = parseCSSJustifyContent(pickStyle(style, 'justify-content')) ?? 'MIN'\n // Flex items stretch across the container unless `align-items` says otherwise.\n node.counterAxisAlign = parseCSSAlignItems(pickStyle(style, 'align-items')) ?? 'STRETCH'\n node.layoutWrap = pickStyle(style, 'flex-wrap') === 'wrap' ? 'WRAP' : 'NO_WRAP'\n return\n }\n if (flow === 'grid') {\n const columns = gridTracks(pickStyle(style, 'grid-template-columns'))\n // Tracks the document cannot place, such as `auto-fit`, keep the content in block flow.\n if (columns) {\n node.layoutMode = 'GRID'\n node.gridTemplateColumns = columns\n const rows = gridTracks(pickStyle(style, 'grid-template-rows'))\n if (rows) node.gridTemplateRows = rows\n return\n }\n }\n if (flow === 'grid' || flow === 'block') {\n node.layoutMode = 'VERTICAL'\n // Browsers center a button's content both ways.\n if (CENTERED_TAGS.has(element.tagName.toLowerCase())) {\n node.primaryAxisAlign = 'CENTER'\n node.counterAxisAlign = 'CENTER'\n }\n return\n }\n // Inline content runs in a line, aligned by `text-align`.\n node.layoutMode = 'HORIZONTAL'\n node.primaryAxisAlign = textAlignAxis(element, style)\n node.counterAxisAlign = 'CENTER'\n}\n\nfunction grows(style: DesignStyleDeclaration): boolean {\n const grow = parseCSSNumber(pickStyle(style, 'flex-grow'))\n if (grow !== null) return grow > 0\n const flex = pickStyle(style, 'flex')?.trim().split(/\\s+/)[0]\n if (flex === 'auto') return true\n const shorthand = parseCSSNumber(flex)\n return shorthand !== null && shorthand > 0\n}\n\nfunction isFullSize(style: DesignStyleDeclaration, property: 'width' | 'height'): boolean {\n return pickStyle(style, property)?.trim() === '100%'\n}\n\ninterface BoxSize {\n fixedWidth: boolean\n fixedHeight: boolean\n}\n\n/** Fill from the parent's flow: block children across, growing items along, `100%` either way. */\nfunction applyParentFill(\n graph: SceneGraph,\n node: SceneNode,\n style: DesignStyleDeclaration,\n display: string,\n parentFlow: ParentFlow,\n { fixedWidth, fixedHeight }: BoxSize\n): void {\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const parentLayout = parent?.layoutMode ?? 'NONE'\n if (!parent || parentLayout === 'NONE' || node.layoutPositioning === 'ABSOLUTE') return\n const fill = (axis: 'HORIZONTAL' | 'VERTICAL') =>\n Object.assign(node, fillSizingFields(parentLayout, axis))\n const mainAxis = parentLayout === 'VERTICAL' ? 'VERTICAL' : 'HORIZONTAL'\n // A box sized to its content, as an inline-block, a flex item, or an absolute box is, has no\n // width of its own for block children to fill; they size it instead.\n const block = parentFlow === 'block' && !isInlineLevel(display) && !fixedWidth\n if (block && hasDefiniteWidth(graph, parent)) fill('HORIZONTAL')\n // A grid item sits in its cell at its own size; only an explicit 100% fills it.\n if (parentFlow === 'flex' && grows(style)) fill(mainAxis)\n if (isFullSize(style, 'width')) fill('HORIZONTAL')\n if (isFullSize(style, 'height')) fill('VERTICAL')\n if (parentFlow === 'flex') keepFixedCrossSize(node, parent, mainAxis, { fixedWidth, fixedHeight })\n}\n\n/** An item with its own cross size keeps it in a stretching flex container, as in CSS. */\nfunction keepFixedCrossSize(\n node: SceneNode,\n parent: SceneNode,\n mainAxis: 'HORIZONTAL' | 'VERTICAL',\n { fixedWidth, fixedHeight }: BoxSize\n): void {\n const crossFixed = mainAxis === 'VERTICAL' ? fixedWidth : fixedHeight\n const inheritsStretch = node.layoutAlignSelf === 'AUTO' && parent.counterAxisAlign === 'STRETCH'\n if (crossFixed && inheritsStretch) node.layoutAlignSelf = 'MIN'\n}\n\nfunction hasDefiniteWidth(graph: SceneGraph, node: SceneNode): boolean {\n return layoutSizing(graph, node, 'HORIZONTAL') !== 'HUG'\n}\n\n/**\n * Whether CSS keeps the text on its lines however narrow its box, and the text starts at the\n * box's start edge, so its own width places it as the box does. A box narrower than the text\n * clips it rather than breaking it, which wrapping text measured in other fonts would do.\n */\nfunction staysOnItsLines(style: DesignStyleDeclaration): boolean {\n const whiteSpace = pickStyle(style, 'white-space')?.trim()\n const align = pickStyle(style, 'text-align')?.trim() ?? 'start'\n return (whiteSpace === 'nowrap' || whiteSpace === 'pre') && ['start', 'left'].includes(align)\n}\n\n/**\n * Text wraps where its width is fixed or fills a parent with a width of its own, and hugs its\n * content otherwise. It is measured when the document is laid out.\n */\nfunction applyTextSizing(graph: SceneGraph, node: SceneNode, size: BoxSize): void {\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const fillsWidth =\n parent !== undefined &&\n hasDefiniteWidth(graph, parent) &&\n layoutSizing(graph, node, 'HORIZONTAL') === 'FILL'\n const wraps = size.fixedWidth || fillsWidth\n node.textAutoResize = wraps ? textAutoResizeFor(false, !size.fixedHeight) : 'WIDTH_AND_HEIGHT'\n // Wrapping text starts at its content's width.\n if (!size.fixedWidth) node.width = 0\n if (!size.fixedHeight) node.height = 0\n}\n\n/**\n * How a child sizes in its parent's flow, as CSS sizes it: an explicit size is fixed, block-level\n * children of block flow and items of a stretching flex container fill across, a growing flex\n * item fills along, `100%` fills, and everything else hugs. Text that fills its width wraps.\n */\nexport function applyFlowSizing(\n graph: SceneGraph,\n node: SceneNode,\n style: DesignStyleDeclaration,\n display: string,\n parentFlow: ParentFlow\n): void {\n const size: BoxSize = {\n fixedWidth: parseCSSNumber(pickStyle(style, 'width')) !== null,\n fixedHeight: parseCSSNumber(pickStyle(style, 'height')) !== null\n }\n if (node.layoutMode !== 'NONE') {\n const own = (fixed: boolean) => (fixed ? 'FIXED' : 'HUG')\n // A grid frame sizes itself like a row: its primary axis is the width its columns add up to.\n const direction = node.layoutMode === 'GRID' ? 'HORIZONTAL' : node.layoutMode\n Object.assign(\n node,\n autoLayoutSizingFields(direction, own(size.fixedWidth), own(size.fixedHeight))\n )\n }\n if (node.type === 'TEXT' && staysOnItsLines(style)) {\n applyTextSizing(graph, node, { fixedWidth: false, fixedHeight: size.fixedHeight })\n return\n }\n applyParentFill(graph, node, style, display, parentFlow, size)\n if (node.type === 'TEXT') applyTextSizing(graph, node, size)\n}\n","export function mergeCSSText(...parts: Array<string | undefined>): string | undefined {\n const text = parts.map((part) => part?.trim()).filter((part): part is string => !!part)\n return text.length > 0 ? text.join('\\n') : undefined\n}\n","import { toUint8Array } from 'js-base64'\n\nimport type { Fill, SceneGraph } from '@pairdraw/scene-graph'\nimport { TRANSPARENT } from '@pairdraw/scene-graph/constants'\nimport { parseCSSBackgroundImages, splitCSSValue } from '@pairdraw/scene-graph/css'\nimport { computeImageHash, imageSize } from '@pairdraw/scene-graph/images'\nimport type { Matrix, Rect, Size, Vector } from '@pairdraw/scene-graph/primitives'\n\nimport type { DesignStyleDeclaration } from '../types'\nimport { colorToFillFromCSS, pickStyle } from './css-values'\n\nconst REPEAT_KEYWORDS = new Set(['repeat', 'no-repeat', 'repeat-x', 'repeat-y', 'space', 'round'])\nconst BOX_KEYWORDS = new Set(['border-box', 'padding-box', 'content-box'])\nconst ATTACHMENT_KEYWORDS = new Set(['scroll', 'fixed', 'local'])\nconst GRADIENT_PREFIXES = [\n 'linear-gradient(',\n 'radial-gradient(',\n 'conic-gradient(',\n 'repeating-linear-gradient(',\n 'repeating-radial-gradient(',\n 'repeating-conic-gradient('\n]\n\n/** Splits a CSS value list at its top-level commas, keeping functions whole. */\nfunction splitLayers(value: string): string[] {\n const layers: string[] = []\n let depth = 0\n let start = 0\n for (let index = 0; index < value.length; index++) {\n const character = value[index]\n if (character === '(') depth++\n else if (character === ')') depth = Math.max(0, depth - 1)\n else if (character === ',' && depth === 0) {\n layers.push(value.slice(start, index).trim())\n start = index + 1\n }\n }\n const last = value.slice(start).trim()\n if (last) layers.push(last)\n return layers\n}\n\n/** The value a property list gives layer `index`, repeating its last entry as CSS does. */\nfunction at(list: readonly string[], index: number): string | undefined {\n return list[Math.min(index, list.length - 1)]\n}\n\n/** One CSS background layer as the properties that place its picture. */\nexport interface BackgroundLayer {\n image: string\n size: string\n position: string\n repeat: string\n origin: string\n clip: string\n /** A gradient parsed from the longhand, which has no image URL. */\n gradient?: Fill\n}\n\n/** Splits a value into its `url(...)` and gradient functions and the words around them. */\nfunction splitBackgroundFunctions(value: string): { image: string; rest: string } {\n let image = ''\n let depth = 0\n let start = -1\n let end = -1\n for (let index = 0; index < value.length; index++) {\n const character = value[index]\n if (character === '(') {\n if (depth === 0) start = index\n depth++\n } else if (character === ')') {\n depth--\n if (depth === 0) end = index\n } else if (depth === 0 && character === ' ') {\n continue\n }\n if (depth === 0 && end !== -1) {\n const name = value.slice(0, start).trim().split(/[\\s,]/).pop() ?? ''\n const candidate = `${name}${value.slice(start, end + 1)}`\n if (name === 'url' || GRADIENT_PREFIXES.some((prefix) => candidate.startsWith(prefix))) {\n image = candidate\n const before = value.slice(0, start).trim().split(/\\s+/)\n const after = value.slice(end + 1).trim()\n return { image, rest: [...before.slice(0, -1), after].join(' ').trim() }\n }\n start = -1\n end = -1\n }\n }\n return { image, rest: value }\n}\n\nfunction parseShorthand(layer: string): BackgroundLayer {\n const { image, rest } = splitBackgroundFunctions(layer)\n const [positionPart = '', sizePart = ''] = rest.split('/')\n const words = splitCSSValue(positionPart.toLowerCase())\n const sizes = splitCSSValue(sizePart.toLowerCase())\n const result: BackgroundLayer = {\n image,\n size: 'auto',\n position: '0% 0%',\n repeat: 'repeat',\n origin: 'padding-box',\n clip: 'border-box'\n }\n const places: string[] = []\n let sawOrigin = false\n let sawClip = false\n for (const word of words) {\n if (REPEAT_KEYWORDS.has(word)) result.repeat = word\n else if (BOX_KEYWORDS.has(word)) {\n // The first of the two box words is the origin, the second the clip.\n if (!sawOrigin) {\n result.origin = word\n sawOrigin = true\n } else {\n result.clip = word\n sawClip = true\n }\n } else if (ATTACHMENT_KEYWORDS.has(word)) continue\n else if (/^[\\d.+-]/.test(word) || ['left', 'right', 'center', 'top', 'bottom'].includes(word)) {\n places.push(word)\n }\n }\n const sizing = sizes.filter((word) => !REPEAT_KEYWORDS.has(word) && !BOX_KEYWORDS.has(word))\n if (sizing.length > 0) result.size = sizing.slice(0, 2).join(' ')\n for (const word of sizes) {\n if (REPEAT_KEYWORDS.has(word)) {\n result.repeat = word\n } else if (BOX_KEYWORDS.has(word)) {\n if (!sawOrigin) {\n result.origin = word\n sawOrigin = true\n } else {\n result.clip = word\n sawClip = true\n }\n }\n }\n if (!sawClip && sawOrigin) result.clip = result.origin\n if (places.length === 1) result.position = places[0]\n else if (places.length >= 2) result.position = places.slice(-2).join(' ')\n return result\n}\n\n/** The background layers of an element, top layer first, from the shorthand or the longhands. */\nexport function backgroundLayers(\n style: DesignStyleDeclaration,\n width = 1,\n height = 1\n): BackgroundLayer[] {\n const shorthand = splitLayers(pickStyle(style, 'background') ?? '')\n if (shorthand.length > 0) {\n return shorthand.map((layer) => parseShorthand(layer))\n }\n const parsed = parseCSSBackgroundImages(pickStyle(style, 'background-image'), width, height)\n const sizes = splitLayers(pickStyle(style, 'background-size') ?? '')\n const positions = splitLayers(pickStyle(style, 'background-position') ?? '')\n const repeats = splitLayers(pickStyle(style, 'background-repeat') ?? '')\n const origins = splitLayers(pickStyle(style, 'background-origin') ?? '')\n const clips = splitLayers(pickStyle(style, 'background-clip') ?? '')\n return parsed.map((layer, index) => ({\n image: layer.kind === 'image' ? `url(${layer.url})` : '',\n gradient: layer.kind === 'gradient' ? layer.fill : undefined,\n size: at(sizes, index) ?? 'auto',\n position: at(positions, index) ?? '0% 0%',\n repeat: at(repeats, index) ?? 'repeat',\n origin: at(origins, index) ?? 'padding-box',\n clip: at(clips, index) ?? 'border-box'\n }))\n}\n\n/** A length or percentage of `total`, as one value of `background-size` or `-position` gives. */\nfunction lengthOf(value: string | undefined, total: number): number | null {\n if (!value) return null\n const trimmed = value.trim()\n const percent = /^(-?[\\d.]+)%$/.exec(trimmed)\n if (percent) {\n const share = Number.parseFloat(percent[1])\n return Number.isFinite(share) ? (total * share) / 100 : null\n }\n const pixels = /^(-?[\\d.]+)(?:px)?$/.exec(trimmed)\n if (!pixels) return null\n const number = Number.parseFloat(pixels[1])\n return Number.isFinite(number) ? number : null\n}\n\n/** The size `background-size` draws a picture of `natural` size at in `box`. */\nfunction pictureSize(size: string, box: Size, natural: Size): Size {\n const sizing = size.trim().toLowerCase()\n if (sizing === 'cover' || sizing === 'contain') {\n const scale = (sizing === 'cover' ? Math.max : Math.min)(\n box.width / natural.width,\n box.height / natural.height\n )\n return { width: natural.width * scale, height: natural.height * scale }\n }\n const [across, down = 'auto'] = splitCSSValue(sizing)\n const width = across === 'auto' ? null : lengthOf(across, box.width)\n const height = down === 'auto' ? null : lengthOf(down, box.height)\n if (width === null && height === null) return natural\n if (width === null && height !== null) {\n return { width: (height * natural.width) / natural.height, height }\n }\n if (width !== null && height === null) {\n return { width, height: (width * natural.height) / natural.width }\n }\n return { width: width ?? natural.width, height: height ?? natural.height }\n}\n\nconst POSITION_KEYWORDS: Partial<Record<string, string>> = {\n left: '0%',\n top: '0%',\n center: '50%',\n right: '100%',\n bottom: '100%'\n}\n\n/** Where `background-position` puts a picture of `size` in `box`: a percentage of the room left. */\nfunction pictureOffset(position: string, box: Size, size: Size): Vector {\n const values = splitCSSValue(position.trim().toLowerCase()).map(\n (value) => POSITION_KEYWORDS[value] ?? value\n )\n const [across = '50%', down = '50%'] = values\n const along = (value: string, room: number, total: number) => {\n if (value.endsWith('%')) {\n const number = Number.parseFloat(value)\n return Number.isFinite(number) ? (room * number) / 100 : room / 2\n }\n return lengthOf(value, total) ?? room / 2\n }\n return {\n x: along(across, box.width - size.width, box.width),\n y: along(down, box.height - size.height, box.height)\n }\n}\n\nfunction cropTransform(area: Rect, picture: Rect): Matrix {\n return {\n m00: area.width / picture.width,\n m01: 0,\n m02: (area.x - picture.x) / picture.width,\n m10: 0,\n m11: area.height / picture.height,\n m12: (area.y - picture.y) / picture.height\n }\n}\n\nfunction cropFill(imageHash: string, imageTransform: Matrix): Fill {\n return {\n type: 'IMAGE',\n imageHash,\n imageScaleMode: 'CROP',\n imageTransform,\n color: TRANSPARENT,\n opacity: 1,\n visible: true\n }\n}\n\nfunction borderWidth(style: DesignStyleDeclaration, side: string): number {\n const raw = pickStyle(style, `border-${side}-width`) ?? pickStyle(style, 'border-width')\n const parsed = lengthOf(raw, 0)\n return parsed === null || parsed < 0 ? 0 : parsed\n}\n\nfunction paddingWidth(style: DesignStyleDeclaration, side: string): number {\n const parsed = lengthOf(pickStyle(style, `padding-${side}`), 0)\n return parsed === null || parsed < 0 ? 0 : parsed\n}\n\ninterface Insets {\n top: number\n right: number\n bottom: number\n left: number\n}\n\nfunction boxInsets(box: string, style: DesignStyleDeclaration): Insets {\n const border = {\n top: borderWidth(style, 'top'),\n right: borderWidth(style, 'right'),\n bottom: borderWidth(style, 'bottom'),\n left: borderWidth(style, 'left')\n }\n if (box === 'padding-box') return border\n if (box !== 'content-box') return { top: 0, right: 0, bottom: 0, left: 0 }\n return {\n top: border.top + paddingWidth(style, 'top'),\n right: border.right + paddingWidth(style, 'right'),\n bottom: border.bottom + paddingWidth(style, 'bottom'),\n left: border.left + paddingWidth(style, 'left')\n }\n}\n\nfunction insetArea(node: Size, insets: Insets): Rect {\n return {\n x: insets.left,\n y: insets.top,\n width: Math.max(0, node.width - insets.left - insets.right),\n height: Math.max(0, node.height - insets.top - insets.bottom)\n }\n}\n\n/** One background layer, in the order CSS paints it: the bottom layer first. */\nexport interface BackgroundLayerPaint {\n fill: Fill\n /** The area a picture covers, when it covers only part of its layer. */\n area?: Rect\n /** Whether the layer is a picture, which a layer of its own behind the children draws. */\n picture: boolean\n}\n\nexport interface BackgroundPaint {\n /** Fills in CSS paint order bottom-first, the color first, when every layer covers its box. */\n fills: Fill[]\n /**\n * Every background layer in CSS paint order when one picture covers part of its box, so layers\n * that stay fills and layers that need their own still paint in the order CSS gives them.\n */\n layers: BackgroundLayerPaint[]\n}\n\n/** Adds a layer's picture to the stack, at the area it shows when it covers part of its box. */\nfunction placePicture(\n graph: SceneGraph,\n node: Size,\n style: DesignStyleDeclaration,\n layer: BackgroundLayer,\n stack: BackgroundLayerPaint[]\n): void {\n const images = parseCSSBackgroundImages(layer.image, node.width, node.height)\n for (const image of images) {\n if (image.kind === 'gradient') {\n stack.push({ fill: image.fill, picture: false })\n continue\n }\n const bytes = bytesFromDataURL(image.url)\n if (!bytes) continue\n const natural = imageSize(bytes)\n if (!natural || natural.width <= 0 || natural.height <= 0) continue\n const imageHash = computeImageHash(bytes)\n graph.images.set(imageHash, bytes)\n const origin = insetArea(node, boxInsets(layer.origin, style))\n const size = pictureSize(layer.size, origin, natural)\n if (size.width <= 0 || size.height <= 0) continue\n const clip = insetArea(node, boxInsets(layer.clip, style))\n const tiles =\n layer.repeat !== 'no-repeat' &&\n layer.repeat !== 'space' &&\n layer.repeat !== 'round' &&\n (layer.size.trim() === 'auto' || layer.size.trim() === 'auto auto')\n if (tiles) {\n stack.push({\n fill: {\n type: 'IMAGE',\n imageHash,\n imageScaleMode: 'TILE',\n color: TRANSPARENT,\n opacity: 1,\n visible: true\n },\n picture: true\n })\n continue\n }\n const offset = pictureOffset(layer.position, origin, size)\n const picture = { x: origin.x + offset.x, y: origin.y + offset.y, ...size }\n const left = Math.max(clip.x, picture.x)\n const top = Math.max(clip.y, picture.y)\n const right = Math.min(clip.x + clip.width, picture.x + picture.width)\n const bottom = Math.min(clip.y + clip.height, picture.y + picture.height)\n if (right <= left || bottom <= top) continue\n const area = { x: left, y: top, width: right - left, height: bottom - top }\n const fill = cropFill(imageHash, cropTransform(area, picture))\n if (\n area.x <= 0.5 &&\n area.y <= 0.5 &&\n area.width >= node.width - 1 &&\n area.height >= node.height - 1\n ) {\n stack.push({ fill, picture: true })\n } else {\n stack.push({ area, fill, picture: true })\n }\n }\n}\n\n/**\n * Reads an element's background layers: the color, gradients, tiles and pictures placed where\n * `background-size`, `-position`, `-repeat`, `-origin`, and `-clip` put them, bottom layer first.\n * Every layer stays a fill while all of them cover the box; as soon as one covers part of it, the\n * whole stack becomes layers of their own, so CSS paint order survives across the two kinds.\n */\nexport function backgroundPaint(\n graph: SceneGraph,\n style: DesignStyleDeclaration,\n node: Size\n): BackgroundPaint {\n const color = fillFromColor(style)\n const layers = backgroundLayers(style, node.width, node.height).reverse()\n const stack: BackgroundLayerPaint[] = []\n for (const layer of layers) {\n if (layer.gradient) {\n stack.push({ fill: layer.gradient, picture: false })\n continue\n }\n placePicture(graph, node, style, layer, stack)\n }\n if (stack.every((layer) => layer.area === undefined)) {\n const fills = stack.map((layer) => layer.fill)\n return { fills: color ? [color, ...fills] : fills, layers: [] }\n }\n return { fills: color ? [color] : [], layers: stack }\n}\n\nfunction fillFromColor(style: DesignStyleDeclaration): Fill | null {\n const fills = colorToFillFromCSS(pickStyle(style, 'background-color'))\n return fills[0] ?? null\n}\n\nfunction bytesFromDataURL(value: string | undefined): Uint8Array | null {\n const match = value ? /^data:[^,]*;base64,([\\s\\S]*)$/.exec(value.trim()) : null\n if (!match) return null\n try {\n return toUint8Array(match[1])\n } catch {\n return null\n }\n}\n","import {\n GENERIC_FONT_FAMILIES_BY_CLASS,\n genericFontFamilyClass,\n parseCSSFontFamilies,\n type GenericFontClass\n} from '@pairdraw/scene-graph/css'\n\nexport interface FontStackOptions {\n /**\n * Whether the document can draw a family, such as the font service answering. Without it every\n * concrete family is taken as available, as a headless import has no faces to ask.\n */\n isAvailable?: (family: string) => boolean\n}\n\nfunction defaultFamily(kind: GenericFontClass, options: FontStackOptions): string {\n const candidates = GENERIC_FONT_FAMILIES_BY_CLASS[kind]\n return (\n (options.isAvailable ? candidates.find((family) => options.isAvailable?.(family)) : null) ??\n candidates[0]\n )\n}\n\n/**\n * The family a CSS `font-family` stack asks a document to draw: the first concrete family the\n * font service can provide; a generic keyword maps to a concrete face of its class. Null when the\n * list has no family.\n */\nexport function resolveFontFamilyStack(\n value: string | undefined,\n options: FontStackOptions = {}\n): string | null {\n for (const family of parseCSSFontFamilies(value)) {\n const kind = genericFontFamilyClass(family)\n if (kind) return defaultFamily(kind, options)\n if (options.isAvailable && !options.isAvailable(family)) continue\n return family\n }\n return null\n}\n","import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport type { DesignStyleDeclaration } from '../types'\nimport { pickStyle } from './css-values'\n\n/** A child the parent paints out of tree order, by its `z-index`. */\ninterface StackedChild {\n id: string\n z: number\n}\n\n/** A child as the builder made it, with the style that decides where CSS paints it. */\nexport interface PaintedChild {\n layer: SceneNode\n style: DesignStyleDeclaration\n}\n\nfunction isPositioned(style: DesignStyleDeclaration): boolean {\n const position = pickStyle(style, 'position')?.trim()\n return position !== undefined && position !== 'static'\n}\n\nfunction zIndexOf(style: DesignStyleDeclaration): number | null {\n if (!isPositioned(style)) return null\n const value = pickStyle(style, 'z-index')?.trim()\n if (!value || value === 'auto') return null\n const z = Number.parseInt(value, 10)\n return Number.isInteger(z) ? z : null\n}\n\n/** Whether a box starts a stacking context of its own, as CSS decides it for the common cases. */\nfunction formsStackingContext(style: DesignStyleDeclaration): boolean {\n const value = (property: string) => pickStyle(style, property)?.trim()\n const position = value('position')\n const opacity = Number.parseFloat(value('opacity') ?? '1')\n return (\n zIndexOf(style) !== null ||\n position === 'fixed' ||\n position === 'sticky' ||\n opacity < 1 ||\n (value('transform') ?? 'none') !== 'none' ||\n (value('filter') ?? 'none') !== 'none' ||\n value('isolation') === 'isolate' ||\n (value('mix-blend-mode') ?? 'normal') !== 'normal'\n )\n}\n\n/**\n * Puts a container's children in the order CSS paints them: negative layers first, lowest\n * first, then the boxes in the flow as they were, then positioned ones, lowest first and in tree\n * order at the same level. A container that is not a stacking context paints its negative layers\n * under its own background, which a layer's fills cannot go under, so its fills move to a layer\n * of their own above those children.\n */\nexport function applyStacking(\n graph: SceneGraph,\n parent: SceneNode,\n style: DesignStyleDeclaration,\n parts: readonly PaintedChild[]\n): void {\n if (parts.length === 0) return\n const children: StackedChild[] = []\n let flowAfter = false\n for (const { layer, style: childStyle } of parts) {\n const movable = layer.layoutPositioning === 'ABSOLUTE' || parent.layoutMode === 'NONE'\n if (!isPositioned(childStyle) || !movable) {\n // A positioned box before a box in the flow is painted out of tree order.\n if (children.some((child) => child.z === 0)) flowAfter = true\n continue\n }\n children.push({ id: layer.id, z: zIndexOf(childStyle) ?? 0 })\n }\n if (!flowAfter && children.every((child) => child.z === 0)) return\n\n const below = children.filter((child) => child.z < 0).toSorted((a, b) => a.z - b.z)\n // Sorted stably, so positioned boxes at the same level keep their tree order.\n const above = children.filter((child) => child.z >= 0).toSorted((a, b) => a.z - b.z)\n const moved = new Set(children.map((child) => child.id))\n const order = [\n ...below.map((child) => child.id),\n ...parent.childIds.filter((id) => !moved.has(id)),\n ...above.map((child) => child.id)\n ]\n for (const [index, id] of order.entries()) graph.insertChildAt(id, parent.id, index)\n\n if (below.length > 0 && !formsStackingContext(style)) liftBackground(graph, parent, below.length)\n}\n\n/** Moves a container's fills into a layer of its own at `index`, its size and corners. */\nfunction liftBackground(graph: SceneGraph, parent: SceneNode, index: number): void {\n if (!parent.fills.some((fill) => fill.visible)) return\n const background = graph.createNode('RECTANGLE', parent.id, {\n name: 'background',\n x: 0,\n y: 0,\n width: parent.width,\n height: parent.height,\n fills: parent.fills,\n cornerRadius: parent.cornerRadius,\n topLeftRadius: parent.topLeftRadius,\n topRightRadius: parent.topRightRadius,\n bottomRightRadius: parent.bottomRightRadius,\n bottomLeftRadius: parent.bottomLeftRadius,\n independentCorners: parent.independentCorners,\n layoutPositioning: parent.layoutMode === 'NONE' ? 'AUTO' : 'ABSOLUTE'\n })\n graph.insertChildAt(background.id, parent.id, index)\n graph.updateNode(parent.id, { fills: [] })\n}\n","import { countBy } from 'es-toolkit/array'\nimport { isEqual } from 'es-toolkit/predicate'\n\nimport type {\n CharacterStyleOverride,\n HyperlinkTarget,\n SceneNode,\n StyleRun,\n TextParagraphStyle\n} from '@pairdraw/scene-graph'\nimport {\n parseCSSColor,\n parseCSSFontFamily,\n parseCSSLetterSpacing,\n parseCSSLineHeight,\n parseCSSNumber\n} from '@pairdraw/scene-graph/css'\n\nimport type { DesignElement, DesignNode, DesignStyleDeclaration } from '../types'\nimport { colorToFillFromCSS, mergedStyle, pickStyle } from './css-values'\n\n/** The character styles a text layer and its runs take from CSS. */\nexport type CSSCharacterStyle = Pick<\n SceneNode,\n | 'fontFamily'\n | 'fontSize'\n | 'fontWeight'\n | 'italic'\n | 'letterSpacing'\n | 'lineHeight'\n | 'fills'\n | 'textDecoration'\n | 'textDecorationStyle'\n | 'textDecorationThickness'\n | 'textDecorationFills'\n | 'textDecorationSkipInk'\n | 'textUnderlineOffset'\n | 'textCase'\n>\n\n/** A character's style and the link it is part of. */\ntype CharacterOfText = CSSCharacterStyle & { hyperlink?: HyperlinkTarget }\n\n/**\n * What characters take from the elements around them: the properties CSS inherits, and the\n * decoration, which CSS draws through descendants.\n */\nconst CHARACTER_PROPERTIES = [\n 'color',\n 'font-family',\n 'font-size',\n 'font-style',\n 'font-weight',\n 'letter-spacing',\n 'line-height',\n 'white-space',\n 'text-transform',\n 'text-decoration-line',\n 'text-decoration-style',\n 'text-decoration-color',\n 'text-decoration-thickness',\n 'text-underline-offset',\n 'text-decoration-skip-ink'\n]\n\nconst TEXT_BLOCK_TAGS = new Set(['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'])\n\n/** What browsers' default stylesheet gives inline formatting elements that CSS does not set. */\nconst FORMATTING_DEFAULTS: Record<string, DesignStyleDeclaration> = {\n b: { 'font-weight': '700' },\n strong: { 'font-weight': '700' },\n i: { 'font-style': 'italic' },\n em: { 'font-style': 'italic' },\n u: { 'text-decoration-line': 'underline' },\n ins: { 'text-decoration-line': 'underline' },\n s: { 'text-decoration-line': 'line-through' },\n del: { 'text-decoration-line': 'line-through' }\n}\nconst LIST_TAGS = new Set(['ul', 'ol'])\n\n/** Lengths CSS gives as a number of pixels, or `null` for keywords such as `auto`. */\nfunction pixels(value: string | undefined): number | null {\n const trimmed = value?.trim()\n if (!trimmed || !/^-?[\\d.]+(px)?$/.test(trimmed)) return null\n return parseCSSNumber(trimmed)\n}\n\nfunction decorationLine(value: string | undefined): SceneNode['textDecoration'] {\n if (value?.includes('underline')) return 'UNDERLINE'\n if (value?.includes('line-through')) return 'STRIKETHROUGH'\n return 'NONE'\n}\n\nfunction decorationStyle(value: string | undefined): SceneNode['textDecorationStyle'] {\n const style = value?.trim().toLowerCase()\n if (style === 'dotted') return 'DOTTED'\n if (style === 'wavy') return 'WAVY'\n return 'SOLID'\n}\n\nfunction textCaseFromCSS(value: string | undefined): SceneNode['textCase'] {\n if (value === 'uppercase') return 'UPPER'\n if (value === 'lowercase') return 'LOWER'\n if (value === 'capitalize') return 'TITLE'\n return 'ORIGINAL'\n}\n\n/** The character style of CSS declarations, over `base` for what they leave out. */\nexport function characterStyleFromCSS(\n style: DesignStyleDeclaration,\n base: CSSCharacterStyle\n): CSSCharacterStyle {\n const fills = colorToFillFromCSS(pickStyle(style, 'color'))\n const family = parseCSSFontFamily(pickStyle(style, 'font-family'))\n const decorationColor = pickStyle(style, 'text-decoration-color')\n const decorationFills = parseCSSColor(decorationColor) ? colorToFillFromCSS(decorationColor) : []\n const line = pickStyle(style, 'text-decoration-line')\n const fontStyle = pickStyle(style, 'font-style')\n const lineHeight = pickStyle(style, 'line-height')\n // `normal` is automatic, a null; a value CSS writes some other way keeps the base.\n const parsedLineHeight = parseCSSLineHeight(lineHeight)\n const textTransform = pickStyle(style, 'text-transform')\n return {\n fontFamily: family || base.fontFamily,\n fontSize: parseCSSNumber(pickStyle(style, 'font-size')) ?? base.fontSize,\n fontWeight: parseCSSNumber(pickStyle(style, 'font-weight')) ?? base.fontWeight,\n italic: fontStyle === undefined ? base.italic : fontStyle === 'italic',\n letterSpacing: parseCSSLetterSpacing(pickStyle(style, 'letter-spacing')) ?? base.letterSpacing,\n lineHeight: parsedLineHeight === undefined ? base.lineHeight : parsedLineHeight,\n fills: fills.length > 0 ? fills : base.fills,\n textDecoration: line === undefined ? base.textDecoration : decorationLine(line),\n textDecorationStyle:\n pickStyle(style, 'text-decoration-style') === undefined\n ? base.textDecorationStyle\n : decorationStyle(pickStyle(style, 'text-decoration-style')),\n textDecorationFills: decorationColor === undefined ? base.textDecorationFills : decorationFills,\n textDecorationThickness:\n pickStyle(style, 'text-decoration-thickness') === undefined\n ? base.textDecorationThickness\n : pixels(pickStyle(style, 'text-decoration-thickness')),\n textUnderlineOffset:\n pickStyle(style, 'text-underline-offset') === undefined\n ? base.textUnderlineOffset\n : pixels(pickStyle(style, 'text-underline-offset')),\n textDecorationSkipInk:\n pickStyle(style, 'text-decoration-skip-ink') === undefined\n ? base.textDecorationSkipInk\n : pickStyle(style, 'text-decoration-skip-ink') !== 'none',\n textCase: textTransform === undefined ? base.textCase : textCaseFromCSS(textTransform)\n }\n}\n\n/** What the characters inside `element` take from it and the elements around it. */\nfunction characterDeclarations(\n element: DesignElement,\n around: DesignStyleDeclaration\n): DesignStyleDeclaration {\n const own = { ...FORMATTING_DEFAULTS[element.tagName.toLowerCase()], ...mergedStyle(element) }\n const inherited: DesignStyleDeclaration = {}\n for (const property of CHARACTER_PROPERTIES) {\n const value = pickStyle(own, property) ?? pickStyle(around, property)\n if (value !== undefined) inherited[property] = value\n }\n return inherited\n}\n\n/** Whether the element holds only characters: text, inline elements, and line breaks. */\nexport function isInlineContent(\n element: DesignElement,\n isInlineElement: (element: DesignElement) => boolean\n): boolean {\n return element.children.every(\n (child) =>\n child.type === 'text' ||\n child.tagName.toLowerCase() === 'br' ||\n (isInlineElement(child) && isInlineContent(child, isInlineElement))\n )\n}\n\nfunction isWhitespace(node: DesignNode): boolean {\n return node.type === 'text' && node.text.trim() === ''\n}\n\nfunction isList(\n element: DesignElement,\n isListPlain: (element: DesignElement) => boolean,\n isPlain: (element: DesignElement) => boolean\n): boolean {\n if (!LIST_TAGS.has(element.tagName.toLowerCase()) || !isListPlain(element)) return false\n return element.children.every(\n (child) =>\n isWhitespace(child) ||\n (child.type === 'element' && child.tagName.toLowerCase() === 'li' && isListItem(child))\n )\n\n function isListItem(item: DesignElement): boolean {\n return item.children.every(\n (child) =>\n child.type === 'text' ||\n child.tagName.toLowerCase() === 'br' ||\n isList(child, isPlain, isPlain) ||\n (!LIST_TAGS.has(child.tagName.toLowerCase()) && isPlain(child))\n )\n }\n}\n\n/**\n * Whether the element holds text in blocks, as Figma keeps it in one layer: it is a list, or\n * holds only paragraphs, headings, and lists of characters with no box of their own.\n */\nexport function holdsTextBlocks(\n element: DesignElement,\n isPlain: (element: DesignElement) => boolean,\n isInlineElement: (element: DesignElement) => boolean\n): boolean {\n if (LIST_TAGS.has(element.tagName.toLowerCase())) return isList(element, () => true, isPlain)\n const blocks = element.children.filter((child) => !isWhitespace(child))\n return (\n blocks.length > 0 &&\n blocks.every(\n (child) =>\n child.type === 'element' &&\n (isList(child, isPlain, isPlain) ||\n (TEXT_BLOCK_TAGS.has(child.tagName.toLowerCase()) &&\n isPlain(child) &&\n isInlineContent(child, isInlineElement)))\n )\n )\n}\n\n/** Text with its runs and paragraphs, as one text layer holds it. */\nexport interface RichText {\n text: string\n styleRuns: StyleRun[]\n textParagraphs: TextParagraphStyle[]\n /** The space after each paragraph, from the margins between blocks. */\n spaceAfter: number[]\n /** Each paragraph's first-line indent. */\n indents: number[]\n /** Whether the outermost list puts its markers outside the text, with no indent of its own. */\n hangingList: boolean\n}\n\ninterface Collector {\n base: CSSCharacterStyle\n text: string\n styles: CharacterOfText[]\n /** The link the characters added now are part of. */\n link: HyperlinkTarget | null\n paragraphs: TextParagraphStyle[]\n spaceAfter: number[]\n indents: number[]\n /** Space collected from margins since the last paragraph ended. */\n pending: number\n hangingList: boolean | undefined\n}\n\nfunction preservesWhitespace(style: DesignStyleDeclaration): boolean {\n const whiteSpace = pickStyle(style, 'white-space')\n return whiteSpace === 'pre' || whiteSpace === 'pre-wrap' || whiteSpace === 'pre-line'\n}\n\nfunction appendCharacters(collector: Collector, text: string, style: CharacterOfText): void {\n const styled = collector.link ? { ...style, hyperlink: collector.link } : style\n collector.text += text\n collector.styles.push(...Array.from({ length: text.length }, () => styled))\n}\n\n/** Where a link element goes, for an `<a>` with an `href`. */\nexport function elementLink(element: DesignElement): HyperlinkTarget | null {\n if (element.tagName.toLowerCase() !== 'a' || !Object.hasOwn(element.attrs, 'href')) return null\n const href = element.attrs.href.trim()\n return href ? { type: 'URL', value: href } : null\n}\n\n/**\n * Characters of `text` in `style`. A line break inside a block starts a paragraph of the\n * block's kind, as text in Figma breaks into paragraphs at every newline.\n */\nfunction addCharacters(collector: Collector, text: string, style: DesignStyleDeclaration): void {\n const value = preservesWhitespace(style) ? text : text.replaceAll(/\\s+/g, ' ')\n const characterStyle = characterStyleFromCSS(style, collector.base)\n for (const [index, line] of value.split('\\n').entries()) {\n if (index > 0) {\n const paragraph = collector.paragraphs.at(-1)\n if (paragraph) {\n collector.spaceAfter.push(0)\n collector.paragraphs.push({ ...paragraph })\n collector.indents.push(0)\n }\n appendCharacters(collector, '\\n', characterStyle)\n }\n appendCharacters(collector, line, characterStyle)\n }\n}\n\nfunction addInline(\n collector: Collector,\n nodes: readonly DesignNode[],\n style: DesignStyleDeclaration\n) {\n for (const node of nodes) {\n if (node.type === 'text') addCharacters(collector, node.text, style)\n else if (isBreak(node)) addCharacters(collector, '\\n', { ...style, 'white-space': 'pre' })\n else if (!LIST_TAGS.has(node.tagName.toLowerCase())) {\n const around = collector.link\n collector.link = elementLink(node) ?? around\n addInline(collector, node.children, characterDeclarations(node, style))\n collector.link = around\n }\n }\n}\n\nfunction isBreak(node: DesignNode): boolean {\n return node.type === 'element' && node.tagName.toLowerCase() === 'br'\n}\n\nfunction margin(element: DesignElement, side: 'top' | 'bottom'): number {\n return Math.max(0, pixels(pickStyle(mergedStyle(element), `margin-${side}`)) ?? 0)\n}\n\n/** Starts a paragraph, ending the one before with the space collected since it. */\nfunction startParagraph(collector: Collector, style: TextParagraphStyle, indent: number): void {\n if (collector.paragraphs.length > 0) {\n collector.spaceAfter.push(collector.pending)\n appendCharacters(collector, '\\n', collector.styles.at(-1) ?? collector.base)\n }\n collector.pending = 0\n collector.paragraphs.push(style)\n collector.indents.push(indent)\n}\n\n/** A paragraph's characters, trimmed of the spaces that CSS drops at a block's edges. */\nfunction addParagraph(\n collector: Collector,\n nodes: readonly DesignNode[],\n style: DesignStyleDeclaration,\n paragraph: TextParagraphStyle,\n indent: number\n): void {\n startParagraph(collector, paragraph, indent)\n // A line break that ends a block adds no line: it gives an empty block its height.\n const content = isBreak(nodes.at(-1) ?? { type: 'text', text: '' }) ? nodes.slice(0, -1) : nodes\n addTrimmed(collector, content, style)\n}\n\n/** Inline content, trimmed of the spaces CSS drops at a block's edges unless it keeps them. */\nfunction addTrimmed(\n collector: Collector,\n nodes: readonly DesignNode[],\n style: DesignStyleDeclaration\n): void {\n const start = collector.text.length\n addInline(collector, nodes, style)\n if (preservesWhitespace(style)) return\n const added = collector.text.slice(start)\n const leading = added.length - added.trimStart().length\n const trimmed = added.trim()\n collector.text = collector.text.slice(0, start) + trimmed\n collector.styles = [\n ...collector.styles.slice(0, start),\n ...collector.styles.slice(start + leading, start + leading + trimmed.length)\n ]\n}\n\nfunction addList(\n collector: Collector,\n list: DesignElement,\n around: DesignStyleDeclaration,\n level: number\n): void {\n const listStyle = characterDeclarations(list, around)\n collector.pending = Math.max(collector.pending, margin(list, 'top'))\n if (level === 1 && collector.hangingList === undefined) {\n collector.hangingList = pixels(pickStyle(mergedStyle(list), 'padding-inline-start')) === 0\n }\n const listType = list.tagName.toLowerCase() === 'ol' ? 'ORDERED' : 'UNORDERED'\n for (const item of list.children) {\n if (item.type !== 'element') continue\n const itemStyle = characterDeclarations(item, listStyle)\n const inline = item.children.filter(\n (child) => child.type === 'text' || !LIST_TAGS.has(child.tagName.toLowerCase())\n )\n collector.pending = Math.max(collector.pending, margin(item, 'top'))\n // An item holding only a nested list, as a skipped level is written, is no paragraph.\n if (inline.some((child) => !isWhitespace(child))) {\n addParagraph(collector, inline, itemStyle, { listType, indentation: level }, 0)\n }\n for (const child of item.children) {\n if (child.type === 'element' && LIST_TAGS.has(child.tagName.toLowerCase())) {\n addList(collector, child, itemStyle, level + 1)\n }\n }\n collector.pending = Math.max(collector.pending, margin(item, 'bottom'))\n }\n collector.pending = Math.max(collector.pending, margin(list, 'bottom'))\n}\n\n/** Runs of characters whose style differs from the text's own. */\nfunction styleRunsFrom(styles: readonly CharacterOfText[], base: CSSCharacterStyle): StyleRun[] {\n const runs: StyleRun[] = []\n for (const [index, style] of styles.entries()) {\n const override: CharacterStyleOverride = {}\n for (const key of Object.keys(style) as (keyof CharacterOfText)[]) {\n const own = key === 'hyperlink' ? undefined : base[key]\n if (!isEqual(style[key], own)) Object.assign(override, { [key]: style[key] })\n }\n const previous = runs.at(-1)\n if (\n previous &&\n previous.start + previous.length === index &&\n isEqual(previous.style, override)\n ) {\n previous.length++\n } else if (Object.keys(override).length > 0) {\n runs.push({ start: index, length: 1, style: override })\n }\n }\n return runs\n}\n\nfunction richTextFrom(collector: Collector): RichText {\n return {\n text: collector.text,\n styleRuns: styleRunsFrom(collector.styles, collector.base),\n textParagraphs: collector.paragraphs,\n spaceAfter: collector.spaceAfter,\n indents: collector.indents,\n hangingList: collector.hangingList ?? false\n }\n}\n\nfunction collector(base: CSSCharacterStyle, link: HyperlinkTarget | null): Collector {\n return {\n base,\n text: '',\n styles: [],\n link,\n paragraphs: [],\n spaceAfter: [],\n indents: [],\n pending: 0,\n hangingList: undefined\n }\n}\n\n/** An element of inline content as one paragraph of text, its spans as runs. */\nexport function inlineRichText(\n element: DesignElement,\n style: DesignStyleDeclaration,\n base: CSSCharacterStyle\n): RichText {\n // A link the element is itself, as an `<a>` holding spans, links all its characters.\n const text = collector(base, elementLink(element))\n addTrimmed(text, element.children, characterDeclarations(element, style))\n return richTextFrom(text)\n}\n\n/** An element of text blocks as paragraphs of one text, its spans as runs. */\nexport function blockRichText(\n element: DesignElement,\n style: DesignStyleDeclaration,\n base: CSSCharacterStyle\n): RichText {\n const text = collector(base, elementLink(element))\n const around = characterDeclarations(element, style)\n const blocks = LIST_TAGS.has(element.tagName.toLowerCase()) ? [element] : element.children\n for (const block of blocks) {\n if (block.type !== 'element') continue\n if (LIST_TAGS.has(block.tagName.toLowerCase())) {\n addList(text, block, around, 1)\n continue\n }\n text.pending = Math.max(text.pending, margin(block, 'top'))\n const blockStyle = characterDeclarations(block, around)\n const indent = Math.max(0, pixels(pickStyle(mergedStyle(block), 'text-indent')) ?? 0)\n addParagraph(text, block.children, blockStyle, { listType: 'NONE', indentation: 0 }, indent)\n text.pending = Math.max(text.pending, margin(block, 'bottom'))\n }\n return richTextFrom(text)\n}\n\n/** The value most gaps of a kind share, which the text holds; the others are the paragraphs'. */\nfunction sharedValue(values: readonly number[]): number {\n const counts = countBy(values, String)\n const shared = Object.entries(counts)\n .toSorted((a, b) => b[1] - a[1])\n .at(0)\n return shared ? Number(shared[0]) : 0\n}\n\n/** Paragraph styles with the spacing and indents of the text's blocks, by Figma's rules. */\nexport function applyParagraphs(node: SceneNode, rich: RichText): void {\n const { textParagraphs: paragraphs, spaceAfter, indents } = rich\n const betweenItems = (index: number) =>\n paragraphs[index]?.listType !== 'NONE' && paragraphs[index + 1]?.listType !== 'NONE'\n const gaps = spaceAfter.map((space, index) => ({ space, list: betweenItems(index) }))\n node.paragraphSpacing = sharedValue(gaps.filter((gap) => !gap.list).map((gap) => gap.space))\n node.listSpacing = sharedValue(gaps.filter((gap) => gap.list).map((gap) => gap.space))\n node.paragraphIndent = sharedValue(\n indents.filter((_, index) => paragraphs[index]?.listType === 'NONE')\n )\n node.hangingList = rich.hangingList\n const styles = paragraphs.map((paragraph, index) => {\n const style: TextParagraphStyle = { ...paragraph }\n const gap = gaps.at(index)\n const field = gap?.list ? 'listSpacing' : 'paragraphSpacing'\n if (gap && gap.space !== node[field]) style[field] = gap.space\n if (paragraph.listType === 'NONE' && indents[index] !== node.paragraphIndent) {\n style.paragraphIndent = indents[index]\n }\n return style\n })\n const plain = styles.every(\n (style) => style.listType === 'NONE' && Object.keys(style).length === 2\n )\n node.textParagraphs = plain ? [] : styles\n}\n","import { pick } from 'es-toolkit'\nimport { decode, isValid, toUint8Array } from 'js-base64'\n\nimport {\n SceneGraph,\n type Effect,\n type ImageScaleMode,\n type SceneNode,\n type Stroke\n} from '@pairdraw/scene-graph'\nimport { TRANSPARENT } from '@pairdraw/scene-graph/constants'\nimport { parseCSSAlignSelf, parseCSSNumber, parseCSSShadows } from '@pairdraw/scene-graph/css'\nimport { normalizeEffects } from '@pairdraw/scene-graph/effects'\nimport { blurRadiusForSigma } from '@pairdraw/scene-graph/geometry'\nimport { computeImageHash } from '@pairdraw/scene-graph/images'\nimport { textLayerName } from '@pairdraw/scene-graph/node-defaults'\n\nimport type { DesignDocument, DesignElement, DesignNode, DesignStyleDeclaration } from '../types'\nimport type { BackgroundLayerPaint } from './background-pictures'\nimport { backgroundPaint } from './background-pictures'\nimport { colorToStrokeFromCSS, mergedStyle, pickStyle } from './css-values'\nimport {\n applyContainerLayout,\n applyFlowSizing,\n applyGridPlacement,\n elementDisplay,\n flowOf,\n inheritedTextStyle,\n type FlowKind,\n type ParentFlow\n} from './flow'\nimport { resolveFontFamilyStack } from './fonts'\nimport type { PaintedChild } from './stacking'\nimport { applyStacking } from './stacking'\nimport {\n blockRichText,\n characterStyleFromCSS,\n elementLink,\n holdsTextBlocks,\n inlineRichText,\n isInlineContent,\n applyParagraphs,\n type CSSCharacterStyle\n} from './text'\n\nconst DOM_CSS_PLUGIN_ID = 'pairdraw-dom-css'\nconst IMAGE_SOURCE_URL_KEY = 'image-source-url'\n\n/**\n * CSS shadows as the layer's effects, each blurred as the browser blurs it: CSS blurs a shadow\n * by half its blur length, which the canvas draws from the radius that gives that sigma.\n */\nfunction cssShadows(value: string | undefined) {\n return parseCSSShadows(value).map((effect): Effect => {\n if (effect.type !== 'DROP_SHADOW' && effect.type !== 'INNER_SHADOW') return effect\n return { ...effect, radius: blurRadiusForSigma(effect.radius / 2) }\n })\n}\n\nexport interface DesignDocumentToSceneGraphOptions {\n pageName?: string\n /**\n * The family a CSS `font-family` stack should draw, given the stack's families; null keeps it.\n * Hosts with a font service pass one that skips faces the document cannot draw; without it the\n * first concrete family wins and a generic keyword maps to a concrete face of its class.\n */\n resolveFontFamily?: (value: string) => string | null\n}\n\n/**\n * The document with every element's font stack resolved to the family its text layer draws, so\n * the per-character CSS parse sees a concrete name instead of a generic keyword.\n */\nfunction withResolvedFontFamilies(\n node: DesignNode,\n resolve: (value: string) => string | null\n): DesignNode {\n if (node.type !== 'element') return node\n const resolved = (\n style: DesignStyleDeclaration | undefined\n ): DesignStyleDeclaration | undefined => {\n const stack = style?.['font-family']\n const family = stack === undefined ? null : resolve(stack)\n return family && family !== stack ? { ...style, 'font-family': family } : style\n }\n const computedStyle = resolved(node.computedStyle)\n const inlineStyle = resolved(node.inlineStyle)\n const next: DesignElement = {\n ...node,\n children: node.children.map((child) => withResolvedFontFamilies(child, resolve))\n }\n if (computedStyle) next.computedStyle = computedStyle\n if (inlineStyle) next.inlineStyle = inlineStyle\n return next\n}\n\nfunction textContent(node: DesignNode): string {\n if (node.type === 'text') return node.text\n return node.children.map(textContent).join('')\n}\n\nfunction isTextLikeElement(node: DesignElement): boolean {\n return [\n 'span',\n 'p',\n 'label',\n 'strong',\n 'em',\n 'button',\n 'a',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6'\n ].includes(node.tagName.toLowerCase())\n}\n\nfunction firstCSSNumber(style: DesignStyleDeclaration, ...properties: string[]): number | null {\n for (const property of properties) {\n const parsed = parseCSSNumber(pickStyle(style, property))\n if (parsed !== null) return parsed\n }\n return null\n}\n\n/**\n * Puts one background layer behind the children, at the area a picture shows or over the whole\n * box. Layers are added bottom-first, so each new one paints above the last.\n */\nfunction addBackgroundLayer(\n graph: SceneGraph,\n parent: SceneNode,\n layer: BackgroundLayerPaint\n): void {\n // A layer that covers the box follows its corners; one at a picture's own area does not.\n const corners =\n layer.area === undefined\n ? {\n cornerRadius: parent.cornerRadius,\n topLeftRadius: parent.topLeftRadius,\n topRightRadius: parent.topRightRadius,\n bottomRightRadius: parent.bottomRightRadius,\n bottomLeftRadius: parent.bottomLeftRadius,\n independentCorners: parent.independentCorners\n }\n : {}\n const background = graph.createNode('RECTANGLE', parent.id, {\n name: layer.picture ? 'background image' : 'background',\n ...(layer.area ?? { x: 0, y: 0, width: parent.width, height: parent.height }),\n fills: [layer.fill],\n ...corners,\n layoutPositioning: parent.layoutMode === 'NONE' ? 'AUTO' : 'ABSOLUTE'\n })\n graph.insertChildAt(background.id, parent.id, parent.childIds.length)\n}\n\nfunction aspectRatioFromCSS(value: string | undefined): number | null {\n if (!value || value === 'auto') return null\n const parts = value\n .split('/')\n .map((part) => Number.parseFloat(part.trim()))\n .filter(Number.isFinite)\n if (parts.length === 1 && parts[0] > 0) return parts[0]\n if (parts.length === 2 && parts[0] > 0 && parts[1] > 0) return parts[0] / parts[1]\n return null\n}\n\nfunction setNodeBox(node: SceneNode, style: DesignStyleDeclaration): void {\n const width = firstCSSNumber(style, 'width')\n const height = firstCSSNumber(style, 'height')\n const minWidth = firstCSSNumber(style, 'min-width')\n const maxWidth = firstCSSNumber(style, 'max-width')\n const minHeight = firstCSSNumber(style, 'min-height')\n const maxHeight = firstCSSNumber(style, 'max-height')\n const aspectRatio = aspectRatioFromCSS(pickStyle(style, 'aspect-ratio'))\n if (width !== null) node.width = width\n if (height !== null) node.height = height\n if (height === null && width !== null && aspectRatio !== null) node.height = width / aspectRatio\n if (width === null && height !== null && aspectRatio !== null) node.width = height * aspectRatio\n if (minWidth !== null) node.minWidth = minWidth\n if (maxWidth !== null) node.maxWidth = maxWidth\n if (minHeight !== null) node.minHeight = minHeight\n if (maxHeight !== null) node.maxHeight = maxHeight\n}\n\nfunction firstStrokeColor(style: DesignStyleDeclaration) {\n return (\n pickStyle(style, 'border-color') ??\n pickStyle(style, 'border-top-color') ??\n pickStyle(style, 'border-right-color') ??\n pickStyle(style, 'border-bottom-color') ??\n pickStyle(style, 'border-left-color')\n )\n}\n\nfunction strokeWeightFromStyle(style: DesignStyleDeclaration) {\n const borderWidth = firstCSSNumber(style, 'border-width')\n if (borderWidth !== null) return borderWidth\n\n const sideWeights = [\n firstCSSNumber(style, 'border-top-width'),\n firstCSSNumber(style, 'border-right-width'),\n firstCSSNumber(style, 'border-bottom-width'),\n firstCSSNumber(style, 'border-left-width')\n ].filter((weight): weight is number => weight !== null)\n if (sideWeights.length === 0) return null\n return Math.max(...sideWeights)\n}\n\nfunction borderStyleFromCSS(style: DesignStyleDeclaration): string | undefined {\n return (\n pickStyle(style, 'border-style') ??\n pickStyle(style, 'border-top-style') ??\n pickStyle(style, 'border-right-style') ??\n pickStyle(style, 'border-bottom-style') ??\n pickStyle(style, 'border-left-style')\n )\n}\n\nfunction dashPatternFromCSS(style: DesignStyleDeclaration, strokeWeight: number): number[] {\n const borderStyle = borderStyleFromCSS(style)\n if (borderStyle === 'dashed') return [strokeWeight * 3, strokeWeight * 2]\n if (borderStyle === 'dotted') return [strokeWeight, strokeWeight]\n return []\n}\n\nfunction setBorderWeights(node: SceneNode, style: DesignStyleDeclaration, stroke: Stroke): void {\n const top = firstCSSNumber(style, 'border-top-width') ?? stroke.weight\n const right = firstCSSNumber(style, 'border-right-width') ?? stroke.weight\n const bottom = firstCSSNumber(style, 'border-bottom-width') ?? stroke.weight\n const left = firstCSSNumber(style, 'border-left-width') ?? stroke.weight\n node.borderTopWeight = top\n node.borderRightWeight = right\n node.borderBottomWeight = bottom\n node.borderLeftWeight = left\n node.independentStrokeWeights = [top, right, bottom, left].some(\n (weight) => weight !== stroke.weight\n )\n}\n\nfunction applyCornerRadii(node: SceneNode, style: DesignStyleDeclaration): void {\n const cornerRadius = firstCSSNumber(style, 'border-radius')\n const topLeft = firstCSSNumber(style, 'border-top-left-radius')\n const topRight = firstCSSNumber(style, 'border-top-right-radius')\n const bottomRight = firstCSSNumber(style, 'border-bottom-right-radius')\n const bottomLeft = firstCSSNumber(style, 'border-bottom-left-radius')\n\n if (cornerRadius !== null) node.cornerRadius = cornerRadius\n if (topLeft === null && topRight === null && bottomRight === null && bottomLeft === null) return\n\n const fallback = cornerRadius ?? 0\n node.topLeftRadius = topLeft ?? fallback\n node.topRightRadius = topRight ?? fallback\n node.bottomRightRadius = bottomRight ?? fallback\n node.bottomLeftRadius = bottomLeft ?? fallback\n node.independentCorners = [\n node.topLeftRadius,\n node.topRightRadius,\n node.bottomRightRadius,\n node.bottomLeftRadius\n ].some((radius) => radius !== fallback)\n}\n\nfunction applyAutoLayoutGap(node: SceneNode, style: DesignStyleDeclaration): void {\n const gap = firstCSSNumber(style, 'gap')\n const rowGap = firstCSSNumber(style, 'row-gap')\n const columnGap = firstCSSNumber(style, 'column-gap')\n if (node.layoutMode === 'GRID') {\n node.gridColumnGap = columnGap ?? gap ?? 0\n node.gridRowGap = rowGap ?? gap ?? 0\n return\n }\n const isHorizontal = node.layoutMode === 'HORIZONTAL'\n const isWrapped = node.layoutWrap === 'WRAP'\n\n node.itemSpacing = (isHorizontal ? columnGap : rowGap) ?? gap ?? 0\n node.counterAxisSpacing = (isHorizontal ? rowGap : columnGap) ?? (isWrapped ? (gap ?? 0) : 0)\n}\n\nfunction applyPositioning(node: SceneNode, style: DesignStyleDeclaration): void {\n const position = pickStyle(style, 'position')\n if (position === 'absolute' || position === 'fixed') node.layoutPositioning = 'ABSOLUTE'\n\n const left = firstCSSNumber(style, 'left')\n const top = firstCSSNumber(style, 'top')\n if (left !== null) node.x = left\n if (top !== null) node.y = top\n}\n\n/**\n * What CSS adds outside an explicit size: padding and borders, unless `box-sizing: border-box`\n * puts them inside it as auto layout does.\n */\nfunction contentBoxExtras(style: DesignStyleDeclaration): { width: number; height: number } {\n if (pickStyle(style, 'box-sizing')?.trim() === 'border-box') return { width: 0, height: 0 }\n // A border takes room once it has a style other than none, its CSS default, whatever its color.\n const borderStyle = borderStyleFromCSS(style)\n const bordered = borderStyle !== undefined && borderStyle !== 'none' && borderStyle !== 'hidden'\n const side = (name: 'top' | 'right' | 'bottom' | 'left', axis: 'block' | 'inline') =>\n (firstCSSNumber(style, `padding-${name}`, `padding-${axis}`, 'padding') ?? 0) +\n (bordered ? (firstCSSNumber(style, `border-${name}-width`, 'border-width') ?? 0) : 0)\n return {\n width: side('left', 'inline') + side('right', 'inline'),\n height: side('top', 'block') + side('bottom', 'block')\n }\n}\n\n/** Explicit sizes count the padding and borders CSS places outside them. */\nfunction applyBoxSizing(node: SceneNode, style: DesignStyleDeclaration): void {\n const extras = contentBoxExtras(style)\n const width = firstCSSNumber(style, 'width')\n const height = firstCSSNumber(style, 'height')\n // A size `aspect-ratio` derives from the other is a content size too.\n const ratio = aspectRatioFromCSS(pickStyle(style, 'aspect-ratio')) !== null\n if (extras.width > 0) {\n if (width !== null || (ratio && height !== null)) node.width += extras.width\n if (node.minWidth !== null) node.minWidth += extras.width\n if (node.maxWidth !== null) node.maxWidth += extras.width\n }\n if (extras.height > 0) {\n if (height !== null || (ratio && width !== null)) node.height += extras.height\n if (node.minHeight !== null) node.minHeight += extras.height\n if (node.maxHeight !== null) node.maxHeight += extras.height\n }\n}\n\nfunction applyPadding(node: SceneNode, style: DesignStyleDeclaration): void {\n node.paddingTop = firstCSSNumber(style, 'padding-top', 'padding-block', 'padding') ?? 0\n node.paddingRight = firstCSSNumber(style, 'padding-right', 'padding-inline', 'padding') ?? 0\n node.paddingBottom = firstCSSNumber(style, 'padding-bottom', 'padding-block', 'padding') ?? 0\n node.paddingLeft = firstCSSNumber(style, 'padding-left', 'padding-inline', 'padding') ?? 0\n}\n\nfunction imageScaleModeFromObjectFit(value: string | undefined): ImageScaleMode | null {\n if (value === 'contain' || value === 'scale-down') return 'FIT'\n if (value === 'cover') return 'FILL'\n return null\n}\n\nfunction bytesFromDataURL(value: string | undefined): Uint8Array | null {\n if (!value?.startsWith('data:')) return null\n const commaIndex = value.indexOf(',')\n if (commaIndex === -1) return null\n const metadata = value.slice(0, commaIndex)\n const body = value.slice(commaIndex + 1)\n // Invalid Base64 in imported HTML drops that image instead of the whole import.\n if (!metadata.endsWith(';base64') || !isValid(body)) return null\n return toUint8Array(body)\n}\n\nfunction applyImageFill(\n graph: SceneGraph,\n node: SceneNode,\n element: DesignElement,\n style: DesignStyleDeclaration\n): void {\n if (element.tagName.toLowerCase() !== 'img') return\n // The styling pass keeps an address it must not load as a data attribute; it is still the node's\n // image source, so a paste keeps the picture even when it cannot be fetched.\n const kept = element.attrs['data-image-source-b64']\n const source = element.attrs.src || (kept && isValid(kept) ? decode(kept) : undefined)\n const bytes = bytesFromDataURL(source)\n if (!bytes) {\n if (source) {\n node.pluginData = [\n ...node.pluginData,\n { pluginId: DOM_CSS_PLUGIN_ID, key: IMAGE_SOURCE_URL_KEY, value: source }\n ]\n }\n return\n }\n\n const imageHash = computeImageHash(bytes)\n graph.images.set(imageHash, bytes)\n node.fills = [\n {\n type: 'IMAGE',\n imageHash,\n imageScaleMode: imageScaleModeFromObjectFit(pickStyle(style, 'object-fit')) ?? 'FILL',\n color: TRANSPARENT,\n opacity: 1,\n visible: true\n }\n ]\n}\n\nfunction applyElementStyle(\n graph: SceneGraph,\n node: SceneNode,\n element: DesignElement,\n style: DesignStyleDeclaration\n): void {\n setNodeBox(node, style)\n applyBoxSizing(node, style)\n applyPositioning(node, style)\n applyPadding(node, style)\n applyGridPlacement(node, style)\n\n const background = backgroundPaint(graph, style, node)\n if (background.fills.length > 0) node.fills = background.fills\n for (const layer of background.layers) addBackgroundLayer(graph, node, layer)\n applyImageFill(graph, node, element, style)\n\n const strokes = colorToStrokeFromCSS(\n firstStrokeColor(style),\n strokeWeightFromStyle(style)?.toString()\n )\n if (strokes.length > 0) {\n const dashPattern = dashPatternFromCSS(style, strokes[0].weight)\n if (dashPattern.length > 0) {\n strokes[0].dashPattern = dashPattern\n node.dashPattern = dashPattern\n }\n node.strokes = strokes\n setBorderWeights(node, style, strokes[0])\n // A CSS border takes room: content sits inside it, as auto layout with strokes included does.\n node.strokesIncludedInLayout = true\n }\n\n const effects = cssShadows(pickStyle(style, 'box-shadow'))\n if (effects.length > 0) node.effects = normalizeEffects(effects)\n\n const opacity = parseCSSNumber(pickStyle(style, 'opacity'))\n if (opacity !== null) node.opacity = opacity\n\n applyCornerRadii(node, style)\n\n const overflow = pickStyle(style, 'overflow')\n if (overflow === 'hidden' || overflow === 'clip') node.clipsContent = true\n\n const alignSelf = parseCSSAlignSelf(pickStyle(style, 'align-self')) ?? 'AUTO'\n if (alignSelf !== 'AUTO') node.layoutAlignSelf = alignSelf\n}\n\nconst CHARACTER_FIELDS = [\n 'fontFamily',\n 'fontSize',\n 'fontWeight',\n 'italic',\n 'letterSpacing',\n 'lineHeight',\n 'fills',\n 'textDecoration',\n 'textDecorationStyle',\n 'textDecorationThickness',\n 'textDecorationFills',\n 'textDecorationSkipInk',\n 'textUnderlineOffset',\n 'textCase'\n] as const satisfies readonly (keyof CSSCharacterStyle)[]\n\nfunction applyTextStyle(node: SceneNode, style: DesignStyleDeclaration): void {\n setNodeBox(node, style)\n applyPositioning(node, style)\n Object.assign(node, characterStyleFromCSS(style, pick(node, CHARACTER_FIELDS)))\n\n const opacity = parseCSSNumber(pickStyle(style, 'opacity'))\n if (opacity !== null) node.opacity = opacity\n\n const effects = cssShadows(pickStyle(style, 'text-shadow'))\n if (effects.length > 0) node.effects = normalizeEffects(effects)\n\n const textAlign = pickStyle(style, 'text-align')?.toUpperCase()\n if (textAlign === 'CENTER' || textAlign === 'RIGHT' || textAlign === 'JUSTIFIED') {\n node.textAlignHorizontal = textAlign\n }\n\n if (pickStyle(style, 'white-space') === 'nowrap') node.maxLines = 1\n}\n\n/**\n * Text and inline elements, or blocks of text, as one text layer: spans become runs, blocks\n * paragraphs, and lists list paragraphs, as Figma holds rich text.\n */\nfunction createRichTextNode(\n graph: SceneGraph,\n parentId: string,\n element: DesignElement,\n style: DesignStyleDeclaration,\n display: string,\n parentFlow: ParentFlow\n): SceneNode {\n const node = graph.createNode('TEXT', parentId, { name: 'Text' })\n applyTextStyle(node, style)\n const blocks = holdsTextBlocks(element, isPlainElement, isInlineElement)\n const base = pick(node, CHARACTER_FIELDS)\n const rich = blocks ? blockRichText(element, style, base) : inlineRichText(element, style, base)\n node.text = rich.text\n node.name = textLayerName('TEXT', rich.text)\n node.styleRuns = rich.styleRuns\n if (blocks) applyParagraphs(node, rich)\n applyFlowSizing(graph, node, style, display, parentFlow)\n return node\n}\n\n/** Whether an element draws nothing of its own, so its text can join the text around it. */\nfunction isPlainElement(element: DesignElement): boolean {\n return !hasBoxStyle(mergedStyle(element))\n}\n\nfunction isInlineElement(element: DesignElement): boolean {\n const style = mergedStyle(element)\n return elementDisplay(element, style) === 'inline' && !hasBoxStyle(style)\n}\n\n/** Whether the element's children are text in one layer: inline content, or text blocks. */\nfunction holdsRichText(element: DesignElement): boolean {\n if (!element.children.some((child) => child.type === 'element')) return false\n if (holdsTextBlocks(element, isPlainElement, isInlineElement)) return true\n return isInlineContent(element, isInlineElement)\n}\n\nfunction createTextNode(\n graph: SceneGraph,\n parentId: string,\n text: string,\n style: DesignStyleDeclaration,\n display: string,\n parentFlow: ParentFlow\n) {\n const node = graph.createNode('TEXT', parentId, { name: textLayerName('TEXT', text), text })\n applyTextStyle(node, style)\n applyFlowSizing(graph, node, style, display, parentFlow)\n return node\n}\n\n/** A link of text alone links all of it. */\nfunction linkText(node: SceneNode, element: DesignElement): void {\n const hyperlink = elementLink(element)\n if (hyperlink && node.text.length > 0) {\n node.styleRuns = [{ start: 0, length: node.text.length, style: { hyperlink } }]\n }\n}\n\nconst BOX_PROPERTIES = [\n 'aspect-ratio',\n 'background-color',\n 'border-radius',\n 'box-shadow',\n 'display',\n 'height',\n 'width',\n 'min-width',\n 'max-width',\n 'min-height',\n 'max-height',\n 'object-fit',\n 'overflow',\n 'position',\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'flex-wrap',\n 'align-self'\n]\n\nconst PADDING_PROPERTIES = [\n 'padding',\n 'padding-top',\n 'padding-right',\n 'padding-bottom',\n 'padding-left',\n 'padding-block',\n 'padding-inline'\n]\n\nconst BORDER_SIDES = ['top', 'right', 'bottom', 'left'] as const\n\n/** Whether every length of a value is zero, as `0`, `0px`, and `0 0` are. */\nfunction isZeroLength(value: string): boolean {\n return value\n .trim()\n .split(/\\s+/)\n .every((part) => parseCSSNumber(part) === 0)\n}\n\n/** Whether any side's border draws: it has a style other than none and a width other than zero. */\nfunction drawsBorder(style: DesignStyleDeclaration): boolean {\n return BORDER_SIDES.some((side) => {\n const borderStyle = pickStyle(style, `border-${side}-style`) ?? pickStyle(style, 'border-style')\n if (borderStyle === undefined || borderStyle === 'none' || borderStyle === 'hidden')\n return false\n // A styled border without a width is CSS's medium one.\n const width = pickStyle(style, `border-${side}-width`) ?? pickStyle(style, 'border-width')\n return width === undefined || !isZeroLength(width)\n })\n}\n\n/**\n * Whether the element is a box rather than a run of the text around it. Padding and borders of\n * no size, which resets such as Tailwind's give every element, leave it a run.\n */\nfunction hasBoxStyle(style: DesignStyleDeclaration): boolean {\n if (BOX_PROPERTIES.some((property) => pickStyle(style, property) !== undefined)) return true\n if (\n PADDING_PROPERTIES.some((property) => {\n const value = pickStyle(style, property)\n return value !== undefined && !isZeroLength(value)\n })\n ) {\n return true\n }\n return drawsBorder(style)\n}\n\nfunction hasContent(element: DesignElement): boolean {\n return element.children.some((child) => child.type !== 'text' || child.text.trim().length > 0)\n}\n\n/** Whether a child sits in a line of its parent's content or leaves it, rather than a block. */\nfunction isInLine(node: DesignNode): boolean {\n if (node.type === 'text' || node.tagName.toLowerCase() === 'br') return true\n const style = mergedStyle(node)\n const display = elementDisplay(node, style)\n const position = pickStyle(style, 'position')\n return (\n display.startsWith('inline') ||\n display === 'none' ||\n position === 'absolute' ||\n position === 'fixed'\n )\n}\n\n/**\n * Whether a block holds inline content with boxes in it, such as a paragraph with a styled\n * `<code>`, which CSS lays out in lines rather than stacking each run and box.\n */\nfunction holdsInlineBoxes(element: DesignElement): boolean {\n return (\n element.children.some((child) => child.type === 'element') && element.children.every(isInLine)\n )\n}\n\n/** The flow a box lays its children out in, and whether they are one text instead. */\nfunction containerFlow(element: DesignElement, display: string) {\n // A box without content keeps its own size, as an image does, unless it declares a layout.\n const flowKind = flowOf(display)\n const own = hasContent(element) || flowKind === 'flex' || flowKind === 'grid' ? flowKind : null\n const richText = own !== 'flex' && own !== 'grid' && holdsRichText(element)\n // Inline content that cannot be one text runs in lines that wrap at the block's width.\n const lines = own === 'block' && !richText && holdsInlineBoxes(element)\n const flow: FlowKind | null = lines ? 'inline' : own\n return { flow, richText, lines }\n}\n\n/** Builds a container's children and orders them the way CSS paints them. */\nfunction paintChildren(\n graph: SceneGraph,\n node: SceneNode,\n element: DesignElement,\n style: DesignStyleDeclaration,\n flow: ParentFlow\n): void {\n const children =\n flow === 'flex' || flow === 'grid' ? element.children.toSorted(byFlexOrder) : element.children\n const painted: PaintedChild[] = []\n for (const child of children) {\n const layer = createDesignNode(graph, node.id, child, flow, inheritedTextStyle(element, style))\n if (layer) painted.push({ layer, style: child.type === 'element' ? mergedStyle(child) : {} })\n }\n applyStacking(graph, node, style, painted)\n}\n\nfunction createElementNode(\n graph: SceneGraph,\n parentId: string,\n element: DesignElement,\n parentFlow: ParentFlow\n): SceneNode | null {\n const style = mergedStyle(element)\n const display = elementDisplay(element, style)\n // A line break between boxes draws nothing; rich text reads it as a new line.\n if (display === 'none' || element.tagName.toLowerCase() === 'br') return null\n if (\n isTextLikeElement(element) &&\n !hasBoxStyle(style) &&\n element.children.every((child) => child.type === 'text')\n ) {\n const text = createTextNode(graph, parentId, textContent(element), style, display, parentFlow)\n linkText(text, element)\n return text\n }\n if (!hasBoxStyle(style) && holdsRichText(element)) {\n return createRichTextNode(graph, parentId, element, style, display, parentFlow)\n }\n\n const node = graph.createNode('FRAME', parentId, {\n // The HTML export writes each layer's own name as `data-name`.\n name: element.attrs['data-name'] || element.attrs.id || element.attrs.class || element.tagName,\n clipsContent: false\n })\n applyElementStyle(graph, node, element, style)\n const { flow, richText, lines } = containerFlow(element, display)\n if (flow) {\n applyContainerLayout(node, element, style, flow)\n if (flow === 'flex' || flow === 'grid') applyAutoLayoutGap(node, style)\n if (lines) node.layoutWrap = 'WRAP'\n }\n applyFlowSizing(graph, node, style, display, parentFlow)\n\n // Blocks of text in a box's own flow are one text; a flex box's children are items.\n if (richText) {\n const textStyle = inheritedTextStyle(element, style)\n const textDisplay = flow === 'inline' ? 'inline' : 'block'\n createRichTextNode(graph, node.id, element, textStyle, textDisplay, flow ?? 'none')\n return node\n }\n paintChildren(graph, node, element, style, flow ?? 'none')\n\n return node\n}\n\nfunction flexOrder(node: DesignNode): number {\n return node.type === 'element' ? (parseCSSNumber(pickStyle(mergedStyle(node), 'order')) ?? 0) : 0\n}\n\n/** Flex items in the order CSS places them: by `order`, then as written. */\nfunction byFlexOrder(a: DesignNode, b: DesignNode): number {\n return flexOrder(a) - flexOrder(b)\n}\n\nfunction createDesignNode(\n graph: SceneGraph,\n parentId: string,\n node: DesignNode,\n parentFlow: ParentFlow,\n inheritedStyle: DesignStyleDeclaration = {}\n): SceneNode | null {\n if (node.type === 'text') {\n if (node.text.trim().length === 0) return null\n // Text runs in block flow and flex containers are blocks of their own, as CSS boxes them.\n const display = parentFlow === 'inline' ? 'inline' : 'block'\n return createTextNode(graph, parentId, node.text, inheritedStyle, display, parentFlow)\n }\n\n return createElementNode(graph, parentId, withFieldText(node), parentFlow)\n}\n\n/** Input types whose value is text a person reads in the field. */\nconst TEXT_INPUT_TYPES = new Set([\n '',\n 'text',\n 'email',\n 'search',\n 'url',\n 'tel',\n 'number',\n 'password'\n])\n\n/**\n * A text field with the text a browser draws in it, its value or else its placeholder, as a\n * child: an `<input>` holds no content of its own. A password shows as dots.\n */\nfunction withFieldText(element: DesignElement): DesignElement {\n if (element.tagName.toLowerCase() !== 'input' || element.children.length > 0) return element\n const type = Object.hasOwn(element.attrs, 'type') ? element.attrs.type.trim().toLowerCase() : ''\n if (!TEXT_INPUT_TYPES.has(type)) return element\n const value = element.attrs.value || element.attrs.placeholder\n if (!value) return element\n const text = type === 'password' && element.attrs.value ? '•'.repeat(value.length) : value\n return { ...element, children: [{ type: 'text', text }] }\n}\n\nfunction fitPageToChildren(page: SceneNode, graph: SceneGraph): void {\n const children = graph.getChildren(page.id)\n if (children.length === 0) return\n page.width = Math.max(...children.map((child) => child.x + child.width))\n page.height = Math.max(...children.map((child) => child.y + child.height))\n}\n\nexport function designDocumentToSceneGraph(\n document: DesignDocument,\n options: DesignDocumentToSceneGraphOptions = {}\n): SceneGraph {\n const resolve = options.resolveFontFamily ?? resolveFontFamilyStack\n const resolved: DesignDocument = {\n ...document,\n children: document.children.map((child) => withResolvedFontFamilies(child, resolve))\n }\n const graph = new SceneGraph()\n const page = graph.getPages().find((node) => node.type === 'CANVAS') ?? graph.addPage('DesignDOM')\n\n page.name = options.pageName ?? 'DesignDOM'\n\n for (const child of resolved.children) {\n createDesignNode(graph, page.id, child, 'none')\n }\n\n fitPageToChildren(page, graph)\n return graph\n}\n\nexport type { DesignDocumentToSceneGraphOptions as ToSceneGraphOptions }\n","import type { DesignDocument, DesignNode, DesignStyleDeclaration } from '#dom-css/types'\n\nexport const Fragment = Symbol.for('pairdraw.dom-css.fragment')\n\ntype JSXComponent = (props: JSXElementProps) => JSXChild\nexport type JSXTag = string | JSXComponent | typeof Fragment\nexport type JSXStyleValue = string | number | null | undefined\nexport type JSXStyleObject = Record<string, JSXStyleValue>\nexport type JSXStyleInput = string | JSXStyleObject\nexport type JSXChild = DesignNode | JSXChild[] | string | number | boolean | null | undefined\n\nexport interface JSXElementProps {\n children?: JSXChild\n class?: string\n className?: string\n style?: JSXStyleInput\n key?: string | number\n [name: string]: unknown\n}\n\nfunction cssPropertyName(name: string) {\n if (name.startsWith('--')) return name\n return name.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`)\n}\n\nfunction styleObjectToDeclaration(style: JSXStyleObject): DesignStyleDeclaration | undefined {\n const entries = Object.entries(style)\n .filter(\n (entry): entry is [string, string | number] => entry[1] !== null && entry[1] !== undefined\n )\n .map(([property, value]) => [cssPropertyName(property), String(value)] as const)\n .filter(([, value]) => value.length > 0)\n\n if (entries.length === 0) return undefined\n return Object.fromEntries(entries)\n}\n\n/** Declarations split at `;` outside quotes and parentheses, so `url(data:…;base64,…)` stays whole. */\nfunction splitDeclarations(style: string): string[] {\n const declarations: string[] = []\n let depth = 0\n let quote: string | null = null\n let start = 0\n for (let index = 0; index < style.length; index++) {\n const character = style[index]\n if (quote) {\n if (character === '\\\\') index++\n else if (character === quote) quote = null\n } else if (character === '\"' || character === \"'\") quote = character\n else if (character === '(') depth++\n else if (character === ')') depth = Math.max(0, depth - 1)\n else if (character === ';' && depth === 0) {\n declarations.push(style.slice(start, index))\n start = index + 1\n }\n }\n declarations.push(style.slice(start))\n return declarations\n}\n\nfunction styleStringToDeclaration(style: string): DesignStyleDeclaration | undefined {\n const entries = splitDeclarations(style)\n .map((declaration) => {\n const colon = declaration.indexOf(':')\n if (colon === -1) return ['', ''] as const\n const property = declaration.slice(0, colon).trim()\n return [property.toLowerCase(), declaration.slice(colon + 1).trim()] as const\n })\n .filter(([property, value]) => property.length > 0 && value.length > 0)\n\n if (entries.length === 0) return undefined\n return Object.fromEntries(entries)\n}\n\nfunction styleToDeclaration(style: JSXStyleInput | undefined): DesignStyleDeclaration | undefined {\n if (typeof style === 'string') return styleStringToDeclaration(style)\n if (style) return styleObjectToDeclaration(style)\n return undefined\n}\n\nfunction attributeValue(value: unknown): string | undefined {\n if (value === null || value === undefined || value === false) return undefined\n if (value === true) return ''\n if (typeof value === 'string') return value\n if (typeof value === 'number' || typeof value === 'bigint') return String(value)\n return undefined\n}\n\nfunction propsToAttrs(props: JSXElementProps): Record<string, string> {\n const attrs: Record<string, string> = {}\n const classValue = props.class ?? props.className\n if (classValue) attrs.class = classValue\n\n for (const [name, value] of Object.entries(props)) {\n if (name === 'children' || name === 'class' || name === 'className' || name === 'style') {\n continue\n }\n if (name === 'key' || name.startsWith('on')) continue\n const attr = attributeValue(value)\n if (attr !== undefined) attrs[name] = attr\n }\n\n return attrs\n}\n\nfunction normalizeChild(child: JSXChild, nodes: DesignNode[]): void {\n if (child === null || child === undefined || typeof child === 'boolean') return\n if (Array.isArray(child)) {\n for (const item of child) normalizeChild(item, nodes)\n return\n }\n if (typeof child === 'string' || typeof child === 'number') {\n nodes.push({ type: 'text', text: String(child) })\n return\n }\n nodes.push(child)\n}\n\nfunction normalizeJSXChildren(children: JSXChild): DesignNode[] {\n const nodes: DesignNode[] = []\n normalizeChild(children, nodes)\n return nodes\n}\n\nexport function jsx(tag: JSXTag, props: JSXElementProps = {}): DesignNode | DesignNode[] {\n if (tag === Fragment) return normalizeJSXChildren(props.children)\n if (typeof tag === 'function') return normalizeJSXChildren(tag(props))\n\n return {\n type: 'element',\n tagName: tag,\n attrs: propsToAttrs(props),\n inlineStyle: styleToDeclaration(props.style),\n children: normalizeJSXChildren(props.children)\n }\n}\n\nexport const jsxs = jsx\n\nexport function jsxToDesignDocumentCore(input: JSXChild): DesignDocument {\n return {\n type: 'document',\n children: normalizeJSXChildren(input)\n }\n}\n\nexport namespace JSX {\n export type Element = DesignNode | DesignNode[]\n export interface ElementChildrenAttribute {\n children: unknown\n }\n export interface IntrinsicElements {\n [tagName: string]: JSXElementProps\n }\n}\n","import type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { mergeCSSText } from './import/css-text'\nimport { jsxToDesignDocumentCore, type JSXChild } from './import/jsx/core'\nexport { resolveFontFamilyStack, type FontStackOptions } from './import/fonts'\nimport { designDocumentToSceneGraph, type ToSceneGraphOptions } from './import/scene-graph'\nimport type { CompileTailwindCSSOptions } from './import/tailwind'\nimport { createBrowserCSSRuntime, type BrowserCSSRuntimeOptions } from './runtime/browser/runtime'\nimport type { CSSComputeOptions, DesignDocument } from './types'\n\nexport { Fragment, jsx, jsxs } from './import/jsx/core'\nexport type { JSXChild, JSXElementProps, JSXStyleInput, JSXTag } from './import/jsx/core'\n\nexport interface BrowserToDesignDocumentOptions extends BrowserCSSRuntimeOptions {\n cssText?: string\n compute?: CSSComputeOptions\n signal?: AbortSignal\n}\n\nexport type BrowserHTMLToDesignDocumentOptions = BrowserToDesignDocumentOptions\n\nexport interface BrowserHTMLToSceneGraphOptions\n extends BrowserToDesignDocumentOptions, ToSceneGraphOptions {}\n\nexport interface BrowserTailwindHTMLToDesignDocumentOptions\n extends Omit<BrowserHTMLToDesignDocumentOptions, 'cssText'>, CompileTailwindCSSOptions {}\n\nexport interface BrowserTailwindHTMLToSceneGraphOptions\n extends BrowserTailwindHTMLToDesignDocumentOptions, ToSceneGraphOptions {}\n\nexport interface BrowserToSceneGraphOptions\n extends BrowserToDesignDocumentOptions, ToSceneGraphOptions {}\n\nexport interface BrowserTailwindToDesignDocumentOptions\n extends Omit<BrowserToDesignDocumentOptions, 'cssText'>, CompileTailwindCSSOptions {}\n\nexport interface BrowserTailwindToSceneGraphOptions\n extends BrowserTailwindToDesignDocumentOptions, ToSceneGraphOptions {}\n\nfunction createRuntime(options: BrowserCSSRuntimeOptions) {\n return createBrowserCSSRuntime({ sandbox: 'iframe', ...options })\n}\n\nasync function compileBrowserTailwindCSS(\n candidates: string | Iterable<string>,\n options: CompileTailwindCSSOptions\n): Promise<string> {\n const { compileTailwindCSS } = await import('./import/tailwind')\n return compileTailwindCSS(candidates, options)\n}\n\nfunction resolveBrowserDocument(documentOverride: Document | undefined): Document {\n if (documentOverride) return documentOverride\n if (typeof document === 'undefined') {\n throw new TypeError('Browser DOM/CSS helpers require a DOM document')\n }\n return document\n}\n\nfunction extractEmbeddedCSSText(html: string, browserDocument: Document): string | undefined {\n const Parser = browserDocument.defaultView?.DOMParser\n if (!Parser) throw new TypeError('Browser DOM/CSS helpers require DOMParser')\n const parsed = new Parser().parseFromString(html, 'text/html')\n const styles = Array.from(parsed.querySelectorAll('style'))\n .map((style) => (style.textContent ? style.textContent.trim() : ''))\n .filter((css): css is string => !!css)\n return styles.length > 0 ? styles.join('\\n') : undefined\n}\n\nexport async function browserHTMLToDesignDocument(\n html: string,\n options: BrowserHTMLToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n options.signal?.throwIfAborted()\n const browserDocument = resolveBrowserDocument(options.document)\n const runtime = createRuntime({ ...options, document: browserDocument })\n const document = runtime.parseHTML(html)\n const cssText = mergeCSSText(extractEmbeddedCSSText(html, browserDocument), options.cssText)\n return runtime.computeStyles(document, cssText, options.compute)\n}\n\nexport async function browserHTMLToSceneGraph(\n html: string,\n options: BrowserHTMLToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await browserHTMLToDesignDocument(html, options)\n options.signal?.throwIfAborted()\n const graph = designDocumentToSceneGraph(document, options)\n options.signal?.throwIfAborted()\n return graph\n}\n\nexport async function browserTailwindHTMLToDesignDocument(\n html: string,\n candidates: string | Iterable<string>,\n options: BrowserTailwindHTMLToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const cssText = await compileBrowserTailwindCSS(candidates, options)\n return browserHTMLToDesignDocument(html, { ...options, cssText })\n}\n\nexport async function browserTailwindHTMLToSceneGraph(\n html: string,\n candidates: string | Iterable<string>,\n options: BrowserTailwindHTMLToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await browserTailwindHTMLToDesignDocument(html, candidates, options)\n options.signal?.throwIfAborted()\n const graph = designDocumentToSceneGraph(document, options)\n options.signal?.throwIfAborted()\n return graph\n}\n\nexport async function browserJSXToDesignDocument(\n input: JSXChild,\n options: BrowserToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const document = jsxToDesignDocumentCore(input)\n const runtime = createRuntime(options)\n return runtime.computeStyles(document, options.cssText, options.compute)\n}\n\nexport async function browserJSXToSceneGraph(\n input: JSXChild,\n options: BrowserToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await browserJSXToDesignDocument(input, options)\n return designDocumentToSceneGraph(document, options)\n}\n\nexport async function browserTailwindJSXToDesignDocument(\n input: JSXChild,\n candidates: string | Iterable<string>,\n options: BrowserTailwindToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const cssText = await compileBrowserTailwindCSS(candidates, options)\n return browserJSXToDesignDocument(input, { ...options, cssText })\n}\n\nexport async function browserTailwindJSXToSceneGraph(\n input: JSXChild,\n candidates: string | Iterable<string>,\n options: BrowserTailwindToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await browserTailwindJSXToDesignDocument(input, candidates, options)\n return designDocumentToSceneGraph(document, options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAaA,SAAgB,QACd,MACA,MACA,OACS;CACT,IAAI,QAAQ;CACZ,IAAI,QAAQ;CACZ,KAAK,IAAI,QAAQ,MAAM,QAAQ,KAAK,QAAQ,SAAS;EACnD,MAAM,YAAY,KAAK;EACvB,IAAI,OAAO;GACT,IAAI,cAAc,MAAM,SAAS;QAC5B,IAAI,cAAc,OAAO,QAAQ;GACtC;EACF;EACA,IAAI,cAAc,QAAO,cAAc,KAAK;GAC1C,QAAQ;GACR;EACF;EACA,IAAI,cAAc,KAAK;GACrB,SAAS;GACT;EACF;EACA,IAAI,cAAc,KAAK,SAAS;EAChC,IAAI,MAAM,WAAW,OAAO,KAAK,GAAG,OAAO;GAAE,MAAM;GAAO,OAAO,UAAU;GAAI;EAAM;CACvF;CACA,OAAO;EAAE,MAAM;EAAI,OAAO,UAAU;EAAI;CAAM;AAChD;;AAGA,SAAgB,aAAa,KAAa,MAAsB;CAC9D,OAAO,QAAQ,KAAK,OAAO,YAAY,QAAQ,UAAU,QAAQ,CAAC,CAAC,CAAC;AACtE;;;;;;;;ACrCA,MAAM,aAAa;AACnB,MAAM,cAAc;;AAGpB,SAAgB,WAAW,MAAsB;CAC/C,OAAO,KAAK,QAAQ,aAAa,EAAE,CAAC,CAAC,QAAQ,aAAa,GAAG,QAAgB;EAC3E,MAAM,OAAO,OAAO,SAAS,KAAK,E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