@pairdraw/dom-css 0.0.0-stage → 0.16.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.
- package/LICENSE +21 -0
- package/README.md +219 -2
- package/dist/browser.d.ts +29 -0
- package/dist/browser.js +2 -0
- package/dist/chunks/behaviours/args.js +59 -0
- package/dist/chunks/behaviours/args.js.map +1 -0
- package/dist/chunks/behaviours/controls.js +109 -0
- package/dist/chunks/behaviours/controls.js.map +1 -0
- package/dist/chunks/behaviours/reset.js +40 -0
- package/dist/chunks/behaviours/reset.js.map +1 -0
- package/dist/chunks/behaviours/roles.js +51 -0
- package/dist/chunks/behaviours/roles.js.map +1 -0
- package/dist/chunks/behaviours/states/conditions.js +103 -0
- package/dist/chunks/behaviours/states/conditions.js.map +1 -0
- package/dist/chunks/behaviours/states/css.js +172 -0
- package/dist/chunks/behaviours/states/css.js.map +1 -0
- package/dist/chunks/behaviours/states/layers.js +1736 -0
- package/dist/chunks/behaviours/states/layers.js.map +1 -0
- package/dist/chunks/behaviours/states/model.js +144 -0
- package/dist/chunks/behaviours/states/model.js.map +1 -0
- package/dist/chunks/behaviours/states/tailwind.js +198 -0
- package/dist/chunks/behaviours/states/tailwind.js.map +1 -0
- package/dist/chunks/browser.js +1352 -0
- package/dist/chunks/browser.js.map +1 -0
- package/dist/chunks/export/bundle.js +337 -0
- package/dist/chunks/export/bundle.js.map +1 -0
- package/dist/chunks/export/components/drawn.js +60 -0
- package/dist/chunks/export/components/drawn.js.map +1 -0
- package/dist/chunks/export/components/fields.js +178 -0
- package/dist/chunks/export/components/fields.js.map +1 -0
- package/dist/chunks/export/components/groups.js +297 -0
- package/dist/chunks/export/components/groups.js.map +1 -0
- package/dist/chunks/export/components/icons.js +260 -0
- package/dist/chunks/export/components/icons.js.map +1 -0
- package/dist/chunks/export/components/layers.js +1594 -0
- package/dist/chunks/export/components/layers.js.map +1 -0
- package/dist/chunks/export/index.js +477 -0
- package/dist/chunks/export/index.js.map +1 -0
- package/dist/chunks/export/storybook/component.js +448 -0
- package/dist/chunks/export/storybook/component.js.map +1 -0
- package/dist/chunks/export/storybook/export.js +410 -0
- package/dist/chunks/export/storybook/export.js.map +1 -0
- package/dist/chunks/import/html.js +406 -0
- package/dist/chunks/import/html.js.map +1 -0
- package/dist/chunks/import/jsx/dev-runtime.js +37 -0
- package/dist/chunks/import/jsx/dev-runtime.js.map +1 -0
- package/dist/chunks/tokens/cssom-validator.js +10 -0
- package/dist/chunks/tokens/cssom-validator.js.map +1 -0
- package/dist/export.d.ts +594 -0
- package/dist/export.js +13 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +7 -0
- package/dist/jsx-dev-runtime.d.ts +8 -0
- package/dist/jsx-dev-runtime.js +3 -0
- package/dist/jsx-runtime.d.ts +20 -0
- package/dist/jsx-runtime.js +3 -0
- package/dist/rolldown-runtime.js +13 -0
- package/dist/runtime.d.ts +10 -0
- package/dist/scene-graph.d.ts +2 -0
- package/dist/scene-graph.js +2 -0
- package/dist/scene-graph2.d.ts +10 -0
- package/dist/styling.d.ts +93 -0
- package/dist/tailwind.d.ts +39 -0
- package/dist/types.d.ts +89 -0
- package/package.json +73 -4
- package/src/behaviours/args.ts +85 -0
- package/src/behaviours/controls.ts +195 -0
- package/src/behaviours/index.ts +11 -0
- package/src/behaviours/reset.ts +37 -0
- package/src/behaviours/roles.ts +44 -0
- package/src/behaviours/states/conditions.ts +105 -0
- package/src/behaviours/states/css.ts +123 -0
- package/src/behaviours/states/index.ts +4 -0
- package/src/behaviours/states/layers.ts +205 -0
- package/src/behaviours/states/model.ts +175 -0
- package/src/behaviours/states/names.ts +39 -0
- package/src/behaviours/states/tailwind.ts +148 -0
- package/src/behaviours/states/types.ts +56 -0
- package/src/browser.ts +146 -0
- package/src/cssom.d.ts +38 -0
- package/src/export/bundle.ts +461 -0
- package/src/export/components/drawn.ts +73 -0
- package/src/export/components/fields.ts +178 -0
- package/src/export/components/groups.ts +78 -0
- package/src/export/components/icons.ts +230 -0
- package/src/export/components/layers.ts +121 -0
- package/src/export/components/model.ts +544 -0
- package/src/export/components/properties.ts +167 -0
- package/src/export/components/react/fields.ts +129 -0
- package/src/export/components/react/index.ts +606 -0
- package/src/export/components/react/shared.ts +76 -0
- package/src/export/components/references.ts +212 -0
- package/src/export/components/repeats.ts +128 -0
- package/src/export/components/shaders.ts +125 -0
- package/src/export/components/styling.ts +31 -0
- package/src/export/components/tree.ts +72 -0
- package/src/export/components/vue.ts +517 -0
- package/src/export/css.ts +57 -0
- package/src/export/grid.ts +42 -0
- package/src/export/html.ts +163 -0
- package/src/export/index.ts +44 -0
- package/src/export/projection.ts +581 -0
- package/src/export/storybook/component.ts +334 -0
- package/src/export/storybook/export.ts +430 -0
- package/src/export/storybook/groups.ts +161 -0
- package/src/export/storybook/module.ts +319 -0
- package/src/export/storybook/names.ts +51 -0
- package/src/export/tailwind-jsx.ts +156 -0
- package/src/export/text.ts +415 -0
- package/src/import/css-text.ts +4 -0
- package/src/import/css-values.ts +31 -0
- package/src/import/flow.ts +248 -0
- package/src/import/html.ts +88 -0
- package/src/import/jsx/core.ts +130 -0
- package/src/import/jsx/dev-runtime.ts +8 -0
- package/src/import/jsx/runtime.ts +76 -0
- package/src/import/scene-graph.ts +582 -0
- package/src/import/style-attribute.ts +25 -0
- package/src/import/tailwind.ts +54 -0
- package/src/import/text.ts +518 -0
- package/src/index.ts +51 -0
- package/src/runtime/browser/runtime.ts +301 -0
- package/src/runtime/headless/runtime.ts +99 -0
- package/src/runtime/headless/styles.ts +330 -0
- package/src/runtime/index.ts +11 -0
- package/src/tokens/conditions.ts +66 -0
- package/src/tokens/cssom-validator.ts +8 -0
- package/src/tokens/custom-properties.ts +331 -0
- package/src/tokens/expression.ts +128 -0
- package/src/tokens/formula.ts +140 -0
- package/src/tokens/index.ts +43 -0
- package/src/tokens/names.ts +161 -0
- package/src/tokens/references.ts +201 -0
- package/src/tokens/stylesheet.ts +304 -0
- package/src/tokens/validate.ts +86 -0
- package/src/tokens/values.ts +44 -0
- package/src/types.ts +59 -0
|
@@ -0,0 +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/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 await requestFrame(iframeDocument)\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 * 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 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 { 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 { parseCSSAlignSelf, parseCSSNumber, parseCSSShadows } from '@pairdraw/scene-graph/css'\nimport { computeImageHash } from '@pairdraw/scene-graph/images'\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 ParentFlow\n} from './flow'\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\nexport interface DesignDocumentToSceneGraphOptions {\n pageName?: string\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\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 if (fills.length > 0) node.fills = fills\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 }\n\n const effects = parseCSSShadows(pickStyle(style, 'box-shadow'))\n if (effects.length > 0) node.effects = 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 = parseCSSShadows(pickStyle(style, 'text-shadow'))\n if (effects.length > 0) node.effects = 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 = rich.text.slice(0, 32) || '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: text.slice(0, 32) || '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\nfunction hasBoxStyle(style: DesignStyleDeclaration): boolean {\n return [\n 'aspect-ratio',\n 'background-color',\n 'border-color',\n 'border-style',\n 'border-width',\n 'border-top-style',\n 'border-top-width',\n 'border-right-style',\n 'border-right-width',\n 'border-bottom-style',\n 'border-bottom-width',\n 'border-left-style',\n 'border-left-width',\n 'border-radius',\n 'box-shadow',\n 'display',\n 'height',\n 'padding',\n 'padding-top',\n 'padding-right',\n 'padding-bottom',\n 'padding-left',\n 'padding-block',\n 'padding-inline',\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 ].some((property) => pickStyle(style, property) !== undefined)\n}\n\nfunction hasContent(element: DesignElement): boolean {\n return element.children.some((child) => child.type !== 'text' || child.text.trim().length > 0)\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 if (display === 'none') 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 name: element.attrs.id || element.attrs.class || element.tagName,\n clipsContent: false\n })\n applyElementStyle(graph, node, element, style)\n // A box without content keeps its own size, as an image does, unless it declares a layout.\n const flow = hasContent(element) || flowOf(display) === 'flex' ? flowOf(display) : null\n if (flow) {\n applyContainerLayout(node, element, style, flow)\n if (flow === 'flex') applyFlexGap(node, style)\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 (flow !== 'flex' && holdsRichText(element)) {\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 for (const child of element.children) {\n createDesignNode(graph, node.id, child, flow ?? 'none', inheritedTextStyle(element, style))\n }\n\n return node\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, node, parentFlow)\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 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 document.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\nfunction styleStringToDeclaration(style: string): DesignStyleDeclaration | undefined {\n const entries = style\n .split(';')\n .map((declaration) => declaration.split(':'))\n .filter((parts): parts is [string, string, ...string[]] => parts.length >= 2)\n .map(([property, ...value]) => [property.trim().toLowerCase(), value.join(':').trim()] as const)\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'\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 designDocumentToSce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+BACpB,OACA,YACA,UAA8C,CAAC,GAC1B;CAErB,OAAO,2BAA2B,MADX,mCAAmC,OAAO,YAAY,OAAO,GACxC,OAAO;AACrD"}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { tokenStylesheet } from "../behaviours/states/layers.js";
|
|
2
|
+
import { mergeClassNames, serializeHTML, splitWhitespace } from "../behaviours/states/tailwind.js";
|
|
3
|
+
import { isValid, toUint8Array } from "js-base64";
|
|
4
|
+
import { parseFragment, serialize } from "parse5";
|
|
5
|
+
import { normalizeFontFamily } from "@pairdraw/scene-graph/font-style";
|
|
6
|
+
//#region src/export/bundle.ts
|
|
7
|
+
const RESET_CSS = "*,*::before,*::after{box-sizing:border-box}html,body{margin:0;padding:0}body{font-family:system-ui,sans-serif;background:#fff}";
|
|
8
|
+
function styleToCSS(style) {
|
|
9
|
+
return Object.entries(style).filter(([, value]) => value !== "").map(([property, value]) => `${property}: ${value}`).join("; ");
|
|
10
|
+
}
|
|
11
|
+
function cloneNode(node) {
|
|
12
|
+
if (node.type === "text") return { ...node };
|
|
13
|
+
return {
|
|
14
|
+
...node,
|
|
15
|
+
attrs: { ...node.attrs },
|
|
16
|
+
inlineStyle: node.inlineStyle ? { ...node.inlineStyle } : void 0,
|
|
17
|
+
children: node.children.map(cloneNode)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function standaloneStyleForNode(node, parent, origin) {
|
|
21
|
+
const style = { ...node.inlineStyle };
|
|
22
|
+
const source = node.sourceSceneNode;
|
|
23
|
+
if (!source) return style;
|
|
24
|
+
style.position = "absolute";
|
|
25
|
+
style.left = `${source.x - (parent ? 0 : origin.minX)}px`;
|
|
26
|
+
style.top = `${source.y - (parent ? 0 : origin.minY)}px`;
|
|
27
|
+
return style;
|
|
28
|
+
}
|
|
29
|
+
function standaloneNode(node, origin, parent) {
|
|
30
|
+
if (node.type === "text") return cloneNode(node);
|
|
31
|
+
const standalone = {
|
|
32
|
+
...node,
|
|
33
|
+
attrs: { ...node.attrs },
|
|
34
|
+
inlineStyle: standaloneStyleForNode(node, parent, origin),
|
|
35
|
+
children: []
|
|
36
|
+
};
|
|
37
|
+
standalone.children = node.children.map((child) => standaloneNode(child, origin, node));
|
|
38
|
+
return standalone;
|
|
39
|
+
}
|
|
40
|
+
function nodeBounds(node) {
|
|
41
|
+
if (node.type === "text" || !node.sourceSceneNode) return void 0;
|
|
42
|
+
return {
|
|
43
|
+
minX: node.sourceSceneNode.x,
|
|
44
|
+
minY: node.sourceSceneNode.y,
|
|
45
|
+
width: node.sourceSceneNode.width,
|
|
46
|
+
height: node.sourceSceneNode.height
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function standaloneSize(document) {
|
|
50
|
+
const bounds = document.children.map(nodeBounds).filter((value) => value !== void 0);
|
|
51
|
+
const minX = bounds.length > 0 ? Math.min(...bounds.map((bound) => bound.minX)) : 0;
|
|
52
|
+
const minY = bounds.length > 0 ? Math.min(...bounds.map((bound) => bound.minY)) : 0;
|
|
53
|
+
const maxX = bounds.length > 0 ? Math.max(...bounds.map((bound) => bound.minX + bound.width)) : 1;
|
|
54
|
+
const maxY = bounds.length > 0 ? Math.max(...bounds.map((bound) => bound.minY + bound.height)) : 1;
|
|
55
|
+
return {
|
|
56
|
+
minX,
|
|
57
|
+
minY,
|
|
58
|
+
width: Math.max(1, maxX - minX),
|
|
59
|
+
height: Math.max(1, maxY - minY)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function standaloneDocument(document, size) {
|
|
63
|
+
return {
|
|
64
|
+
...document,
|
|
65
|
+
children: document.children.map((node) => standaloneNode(node, size))
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function cssClassName(index) {
|
|
69
|
+
return `op-${index.toString(36)}`;
|
|
70
|
+
}
|
|
71
|
+
function extractInlineStyles(node, rules, nextIndex) {
|
|
72
|
+
if (node.type === "text") return node;
|
|
73
|
+
const children = node.children.map((child) => extractInlineStyles(child, rules, nextIndex));
|
|
74
|
+
if (!node.inlineStyle || Object.keys(node.inlineStyle).length === 0) return {
|
|
75
|
+
...node,
|
|
76
|
+
children
|
|
77
|
+
};
|
|
78
|
+
const className = cssClassName(nextIndex.value);
|
|
79
|
+
nextIndex.value += 1;
|
|
80
|
+
rules.push(`.${className}{${styleToCSS(node.inlineStyle)}}`);
|
|
81
|
+
return {
|
|
82
|
+
...node,
|
|
83
|
+
attrs: {
|
|
84
|
+
...node.attrs,
|
|
85
|
+
class: mergeClassNames(node.attrs.class, className) ?? className
|
|
86
|
+
},
|
|
87
|
+
inlineStyle: void 0,
|
|
88
|
+
children
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function isElement(node) {
|
|
92
|
+
return "attrs" in node && "tagName" in node;
|
|
93
|
+
}
|
|
94
|
+
function walkParseTree(node, visit) {
|
|
95
|
+
if (isElement(node)) visit(node);
|
|
96
|
+
if ("childNodes" in node) for (const child of node.childNodes) walkParseTree(child, visit);
|
|
97
|
+
}
|
|
98
|
+
function classNamesFromHTML(html) {
|
|
99
|
+
const fragment = parseFragment(html);
|
|
100
|
+
const classes = /* @__PURE__ */ new Set();
|
|
101
|
+
walkParseTree(fragment, (element) => {
|
|
102
|
+
const classAttr = element.attrs.find((attr) => attr.name === "class");
|
|
103
|
+
if (!classAttr) return;
|
|
104
|
+
for (const className of splitWhitespace(classAttr.value)) classes.add(className);
|
|
105
|
+
});
|
|
106
|
+
return [...classes];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The stylesheet for the tokens the document references, in the format the page needs: plain
|
|
110
|
+
* custom properties for inline styles, `@theme` for Tailwind, so token utilities compile.
|
|
111
|
+
*/
|
|
112
|
+
async function tokenCSS(document, format) {
|
|
113
|
+
const { tokens, sourceGraph } = document;
|
|
114
|
+
if (!tokens || !sourceGraph || tokens.used.size === 0) return "";
|
|
115
|
+
const variables = tokens.stylesheetVariables();
|
|
116
|
+
const { css } = await tokenStylesheet(sourceGraph, {
|
|
117
|
+
format,
|
|
118
|
+
include: (variable) => variables.has(variable.id)
|
|
119
|
+
});
|
|
120
|
+
return css;
|
|
121
|
+
}
|
|
122
|
+
async function readInstalledTailwindStylesheet(id) {
|
|
123
|
+
const { readFile } = await import(
|
|
124
|
+
/* @vite-ignore */
|
|
125
|
+
"node:fs/promises"
|
|
126
|
+
);
|
|
127
|
+
return readFile(new URL(import.meta.resolve(id)), "utf8");
|
|
128
|
+
}
|
|
129
|
+
async function compileTailwindClasses(classNames, tokens, load = readInstalledTailwindStylesheet) {
|
|
130
|
+
if (classNames.length === 0) return "";
|
|
131
|
+
const [{ compile }, themeCSS, utilitiesCSS] = await Promise.all([
|
|
132
|
+
import("tailwindcss"),
|
|
133
|
+
load("tailwindcss/theme.css"),
|
|
134
|
+
load("tailwindcss/utilities.css")
|
|
135
|
+
]);
|
|
136
|
+
return (await compile(`${themeCSS}\n${tokens}\n${utilitiesCSS}`)).build(classNames);
|
|
137
|
+
}
|
|
138
|
+
function collectFontRequests(node, fonts) {
|
|
139
|
+
if (node.type === "text") return;
|
|
140
|
+
const source = node.sourceSceneNode;
|
|
141
|
+
if (source?.type === "TEXT") {
|
|
142
|
+
const family = normalizeFontFamily(source.fontFamily);
|
|
143
|
+
const style = source.italic ? "italic" : "normal";
|
|
144
|
+
const key = `${family}|${source.fontWeight}|${style}`;
|
|
145
|
+
fonts.set(key, {
|
|
146
|
+
family,
|
|
147
|
+
weight: source.fontWeight,
|
|
148
|
+
style
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
for (const child of node.children) collectFontRequests(child, fonts);
|
|
152
|
+
}
|
|
153
|
+
function serializeFontWeight(weight) {
|
|
154
|
+
return Array.isArray(weight) ? weight.join(" ") : String(weight);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* A relative file path as a URL that points at it: each folder and file name percent-encoded,
|
|
158
|
+
* so a page named `Card #1` finds `Card #1.assets/` rather than reading `#1` as a fragment.
|
|
159
|
+
*/
|
|
160
|
+
function assetURL(path) {
|
|
161
|
+
return path.split("/").map(encodeURIComponent).join("/");
|
|
162
|
+
}
|
|
163
|
+
function fontSourceValue(asset, from) {
|
|
164
|
+
const path = from && asset.path.startsWith(`${from}/`) ? asset.path.slice(from.length + 1) : asset.path;
|
|
165
|
+
return [
|
|
166
|
+
"url(",
|
|
167
|
+
JSON.stringify(assetURL(path)),
|
|
168
|
+
") format(",
|
|
169
|
+
JSON.stringify(asset.format),
|
|
170
|
+
")"
|
|
171
|
+
].join("");
|
|
172
|
+
}
|
|
173
|
+
function fontFaceCSS(FontFaceRule, asset, options) {
|
|
174
|
+
const rule = new FontFaceRule();
|
|
175
|
+
rule.style.setProperty("font-family", JSON.stringify(asset.family));
|
|
176
|
+
rule.style.setProperty("src", fontSourceValue(asset, options.from));
|
|
177
|
+
rule.style.setProperty("font-weight", serializeFontWeight(asset.weight));
|
|
178
|
+
rule.style.setProperty("font-style", asset.style);
|
|
179
|
+
rule.style.setProperty("font-display", options.display ?? asset.display ?? "swap");
|
|
180
|
+
if (asset.stretch) rule.style.setProperty("font-stretch", asset.stretch);
|
|
181
|
+
if (asset.unicodeRange && asset.unicodeRange.length > 0) rule.style.setProperty("unicode-range", asset.unicodeRange.join(","));
|
|
182
|
+
return rule.cssText;
|
|
183
|
+
}
|
|
184
|
+
/** Every font face a document's text uses, once each. */
|
|
185
|
+
function designFontRequests(document) {
|
|
186
|
+
const requests = /* @__PURE__ */ new Map();
|
|
187
|
+
for (const child of document.children) collectFontRequests(child, requests);
|
|
188
|
+
return [...requests.values()];
|
|
189
|
+
}
|
|
190
|
+
/** `@font-face` rules for font files, as a stylesheet in the folder `options.from`. */
|
|
191
|
+
async function fontFaceStylesheet(assets, options) {
|
|
192
|
+
if (assets.length === 0) return "";
|
|
193
|
+
const cssom = await import("@acemir/cssom");
|
|
194
|
+
return assets.map((asset) => fontFaceCSS(cssom.CSSFontFaceRule, asset, options)).join("");
|
|
195
|
+
}
|
|
196
|
+
async function fontFaceAssets(document, options) {
|
|
197
|
+
if (options.fonts === "none" || options.assets !== "external") return {
|
|
198
|
+
css: "",
|
|
199
|
+
files: []
|
|
200
|
+
};
|
|
201
|
+
const assets = await options.fonts(designFontRequests(document), `${options.assetBasePath}/fonts`);
|
|
202
|
+
return {
|
|
203
|
+
css: await fontFaceStylesheet(assets, { from: options.assetBasePath }),
|
|
204
|
+
files: assets
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function dataImageParts(value) {
|
|
208
|
+
if (!value.startsWith("data:image/")) return void 0;
|
|
209
|
+
const markerIndex = value.indexOf(";base64,");
|
|
210
|
+
if (markerIndex === -1) return void 0;
|
|
211
|
+
const base64 = value.slice(markerIndex + 8);
|
|
212
|
+
if (!isValid(base64)) return void 0;
|
|
213
|
+
return {
|
|
214
|
+
mime: value.slice(5, markerIndex),
|
|
215
|
+
base64
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function extensionForMime(mime) {
|
|
219
|
+
if (mime === "image/jpeg") return "jpg";
|
|
220
|
+
if (mime === "image/webp") return "webp";
|
|
221
|
+
if (mime === "image/gif") return "gif";
|
|
222
|
+
if (mime === "image/svg+xml") return "svg";
|
|
223
|
+
return "png";
|
|
224
|
+
}
|
|
225
|
+
/** Inline images moved into files under `assetBasePath`, the HTML pointing at them. */
|
|
226
|
+
function extractImageAssets(html, assetBasePath) {
|
|
227
|
+
const fragment = parseFragment(html);
|
|
228
|
+
const files = [];
|
|
229
|
+
const sources = /* @__PURE__ */ new Map();
|
|
230
|
+
walkParseTree(fragment, (element) => {
|
|
231
|
+
const src = element.attrs.find((attr) => attr.name === "src");
|
|
232
|
+
if (!src) return;
|
|
233
|
+
const parts = dataImageParts(src.value);
|
|
234
|
+
if (!parts) return;
|
|
235
|
+
const cachedPath = sources.get(src.value);
|
|
236
|
+
if (cachedPath) {
|
|
237
|
+
src.value = assetURL(cachedPath);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const path = `${assetBasePath}/images/image-${sources.size + 1}.${extensionForMime(parts.mime)}`;
|
|
241
|
+
sources.set(src.value, path);
|
|
242
|
+
files.push({
|
|
243
|
+
path,
|
|
244
|
+
content: toUint8Array(parts.base64)
|
|
245
|
+
});
|
|
246
|
+
src.value = assetURL(path);
|
|
247
|
+
});
|
|
248
|
+
return {
|
|
249
|
+
html: serialize(fragment),
|
|
250
|
+
files
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
function stylesheetLink(path) {
|
|
254
|
+
return `<link rel="stylesheet" href="${assetURL(path)}">`;
|
|
255
|
+
}
|
|
256
|
+
function styleTag(css) {
|
|
257
|
+
return css ? `<style>${css}</style>` : "";
|
|
258
|
+
}
|
|
259
|
+
async function exportStandaloneHTML(document, options) {
|
|
260
|
+
const size = standaloneSize(document);
|
|
261
|
+
const doc = standaloneDocument(document, size);
|
|
262
|
+
const stageCSS = `.op-stage{position:relative;width:${size.width}px;height:${size.height}px;overflow:hidden;background:transparent}`;
|
|
263
|
+
let body;
|
|
264
|
+
let css = `${RESET_CSS}${stageCSS}`;
|
|
265
|
+
if (options.style === "tailwind") {
|
|
266
|
+
body = serializeHTML(doc, { style: "tailwind" });
|
|
267
|
+
css += await compileTailwindClasses(classNamesFromHTML(body), await tokenCSS(document, "tailwind"), options.loadTailwindStylesheet);
|
|
268
|
+
} else {
|
|
269
|
+
css += await tokenCSS(document, "css");
|
|
270
|
+
const rules = [];
|
|
271
|
+
const index = { value: 0 };
|
|
272
|
+
const styledDocument = {
|
|
273
|
+
...doc,
|
|
274
|
+
children: doc.children.map((node) => extractInlineStyles(node, rules, index))
|
|
275
|
+
};
|
|
276
|
+
body = serializeHTML(styledDocument);
|
|
277
|
+
css += rules.join("");
|
|
278
|
+
}
|
|
279
|
+
if (options.assets === "external") {
|
|
280
|
+
const [extracted, fonts] = await Promise.all([Promise.resolve(extractImageAssets(body, options.assetBasePath)), fontFaceAssets(document, options)]);
|
|
281
|
+
body = extracted.html;
|
|
282
|
+
const cssPath = `${options.assetBasePath}/pairdraw.css`;
|
|
283
|
+
return {
|
|
284
|
+
entrypoint: "index.html",
|
|
285
|
+
files: [
|
|
286
|
+
{
|
|
287
|
+
path: "index.html",
|
|
288
|
+
content: `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">${stylesheetLink(cssPath)}</head><body><main data-pairdraw-html="standalone" class="op-stage">${body}</main></body></html>`
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
path: cssPath,
|
|
292
|
+
content: `${fonts.css}${css}`
|
|
293
|
+
},
|
|
294
|
+
...fonts.files,
|
|
295
|
+
...extracted.files
|
|
296
|
+
]
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
entrypoint: "index.html",
|
|
301
|
+
files: [{
|
|
302
|
+
path: "index.html",
|
|
303
|
+
content: `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">${styleTag(css)}</head><body><main data-pairdraw-html="standalone" class="op-stage">${body}</main></body></html>`
|
|
304
|
+
}]
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
async function exportHTMLBundle(document, options = {}) {
|
|
308
|
+
const resolvedOptions = {
|
|
309
|
+
html: options.html ?? "fragment",
|
|
310
|
+
style: options.style ?? "inline",
|
|
311
|
+
assets: options.assets ?? "inline",
|
|
312
|
+
fonts: options.fonts ?? "none",
|
|
313
|
+
assetBasePath: options.assetBasePath ?? "assets",
|
|
314
|
+
loadTailwindStylesheet: options.loadTailwindStylesheet
|
|
315
|
+
};
|
|
316
|
+
if (resolvedOptions.html === "standalone") return exportStandaloneHTML(document, resolvedOptions);
|
|
317
|
+
const fragment = serializeHTML(document, { style: resolvedOptions.style });
|
|
318
|
+
if (resolvedOptions.assets !== "external") return {
|
|
319
|
+
entrypoint: "index.html",
|
|
320
|
+
files: [{
|
|
321
|
+
path: "index.html",
|
|
322
|
+
content: fragment
|
|
323
|
+
}]
|
|
324
|
+
};
|
|
325
|
+
const extracted = extractImageAssets(fragment, resolvedOptions.assetBasePath);
|
|
326
|
+
return {
|
|
327
|
+
entrypoint: "index.html",
|
|
328
|
+
files: [{
|
|
329
|
+
path: "index.html",
|
|
330
|
+
content: extracted.html
|
|
331
|
+
}, ...extracted.files]
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
//#endregion
|
|
335
|
+
export { designFontRequests, exportHTMLBundle, extractImageAssets, fontFaceStylesheet };
|
|
336
|
+
|
|
337
|
+
//# sourceMappingURL=bundle.js.map
|