@pairdraw/dom-css 0.19.2 → 0.20.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"browser.js","names":["resolveBrowserDocument"],"sources":["../../src/runtime/browser/runtime.ts","../../src/import/css-values.ts","../../src/import/flow.ts","../../src/import/css-text.ts","../../src/import/fonts.ts","../../src/import/text.ts","../../src/import/scene-graph.ts","../../src/import/jsx/core.ts","../../src/browser.ts"],"sourcesContent":["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\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-image',\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 '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] 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(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(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 { DEFAULT_FONT_FAMILY } from '@pairdraw/scene-graph/constants'\nimport { parseCSSFontFamilies } from '@pairdraw/scene-graph/css'\n\n/** CSS generic families, by the concrete face class they stand for. */\nconst GENERIC_FAMILIES: Record<string, 'sans-serif' | 'serif' | 'monospace' | undefined> = {\n 'sans-serif': 'sans-serif',\n 'ui-sans-serif': 'sans-serif',\n 'system-ui': 'sans-serif',\n '-apple-system': 'sans-serif',\n blinkmacsystemfont: 'sans-serif',\n serif: 'serif',\n 'ui-serif': 'serif',\n monospace: 'monospace',\n 'ui-monospace': 'monospace'\n}\n\n/** Known system faces of each class, best first. The app bundles Inter for sans-serif. */\nconst DEFAULT_FAMILIES = {\n 'sans-serif': [DEFAULT_FONT_FAMILY],\n serif: ['Georgia', 'Times New Roman', 'Times'],\n monospace: ['Menlo', 'SF Mono', 'Consolas', 'Courier New']\n} as const satisfies Record<'sans-serif' | 'serif' | 'monospace', readonly string[]>\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(\n kind: 'sans-serif' | 'serif' | 'monospace',\n options: FontStackOptions\n): string {\n const candidates = DEFAULT_FAMILIES[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 generic = GENERIC_FAMILIES[family.trim().toLowerCase()]\n if (generic) return defaultFamily(generic, options)\n if (options.isAvailable && !options.isAvailable(family)) continue\n return family\n }\n return null\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 Fill,\n type ImageScaleMode,\n type SceneNode,\n type Stroke\n} from '@pairdraw/scene-graph'\nimport { TRANSPARENT } from '@pairdraw/scene-graph/constants'\nimport {\n parseCSSAlignSelf,\n parseCSSBackgroundImages,\n parseCSSNumber,\n parseCSSShadows\n} 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 { colorToFillFromCSS, 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 {\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) =>\n effect.type === 'SHADER' ? effect : { ...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\nfunction fillsFromStyle(style: DesignStyleDeclaration, property: string): Fill[] {\n return colorToFillFromCSS(pickStyle(style, property))\n}\n\n/**\n * The `background-image` layers as fills, bottom-first as Pairdraw paints them: CSS paints the\n * first layer on top, so the list reverses. A `url()` layer becomes an image fill when its\n * bytes are inline; a remote address is skipped, as an unfetchable background paints nothing.\n */\nfunction backgroundFills(\n graph: SceneGraph,\n node: SceneNode,\n style: DesignStyleDeclaration\n): Fill[] {\n const layers = parseCSSBackgroundImages(\n pickStyle(style, 'background-image'),\n node.width,\n node.height\n )\n const fills: Fill[] = []\n for (const layer of layers) {\n if (layer.kind === 'gradient') {\n fills.push(layer.fill)\n continue\n }\n const bytes = bytesFromDataURL(layer.url)\n if (!bytes) continue\n const imageHash = computeImageHash(bytes)\n graph.images.set(imageHash, bytes)\n fills.push({\n type: 'IMAGE',\n imageHash,\n imageScaleMode: 'FILL',\n color: { ...TRANSPARENT },\n opacity: 1,\n visible: true\n })\n }\n return fills.reverse()\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.push({\n pluginId: DOM_CSS_PLUGIN_ID,\n key: IMAGE_SOURCE_URL_KEY,\n 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 fills = fillsFromStyle(style, 'background-color')\n const background = backgroundFills(graph, node, style)\n if (fills.length > 0 || background.length > 0) node.fills = [...fills, ...background]\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\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 const children = flow === 'flex' ? element.children.toSorted(byFlexOrder) : element.children\n for (const child of children) {\n createDesignNode(graph, node.id, child, flow ?? 'none', inheritedTextStyle(element, style))\n }\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,8BAA8B;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;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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":["resolveBrowserDocument"],"sources":["../../src/runtime/browser/runtime.ts","../../src/import/css-values.ts","../../src/import/flow.ts","../../src/import/css-text.ts","../../src/import/fonts.ts","../../src/import/text.ts","../../src/import/scene-graph.ts","../../src/import/jsx/core.ts","../../src/browser.ts"],"sourcesContent":["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\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-image',\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 '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] 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(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(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 {\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 { 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 Fill,\n type ImageScaleMode,\n type SceneNode,\n type Stroke\n} from '@pairdraw/scene-graph'\nimport { TRANSPARENT } from '@pairdraw/scene-graph/constants'\nimport {\n parseCSSAlignSelf,\n parseCSSBackgroundImages,\n parseCSSNumber,\n parseCSSShadows\n} 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 { colorToFillFromCSS, 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 {\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\nfunction fillsFromStyle(style: DesignStyleDeclaration, property: string): Fill[] {\n return colorToFillFromCSS(pickStyle(style, property))\n}\n\n/**\n * The `background-image` layers as fills, bottom-first as Pairdraw paints them: CSS paints the\n * first layer on top, so the list reverses. A `url()` layer becomes an image fill when its\n * bytes are inline; a remote address is skipped, as an unfetchable background paints nothing.\n */\nfunction backgroundFills(\n graph: SceneGraph,\n node: SceneNode,\n style: DesignStyleDeclaration\n): Fill[] {\n const layers = parseCSSBackgroundImages(\n pickStyle(style, 'background-image'),\n node.width,\n node.height\n )\n const fills: Fill[] = []\n for (const layer of layers) {\n if (layer.kind === 'gradient') {\n fills.push(layer.fill)\n continue\n }\n const bytes = bytesFromDataURL(layer.url)\n if (!bytes) continue\n const imageHash = computeImageHash(bytes)\n graph.images.set(imageHash, bytes)\n fills.push({\n type: 'IMAGE',\n imageHash,\n imageScaleMode: 'FILL',\n color: { ...TRANSPARENT },\n opacity: 1,\n visible: true\n })\n }\n return fills.reverse()\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 fills = fillsFromStyle(style, 'background-color')\n const background = backgroundFills(graph, node, style)\n if (fills.length > 0 || background.length > 0) node.fills = [...fills, ...background]\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\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 const children = flow === 'flex' ? element.children.toSorted(byFlexOrder) : element.children\n for (const child of children) {\n createDesignNode(graph, node.id, child, flow ?? 'none', inheritedTextStyle(element, style))\n }\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,8BAA8B;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAASA,yBAAuB,kBAAkD;CAChF,IAAI,kBAAkB,OAAO;CAC7B,IAAI,OAAO,aAAa,aACtB,MAAM,IAAI,UAAU,6CAA6C;CAEnE,OAAO;AACT;AAEA,SAAS,mBAAmB,S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