@pairdraw/dom-css 0.17.0 → 0.19.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/behaviours/states/layers.js +352 -38
- package/dist/chunks/behaviours/states/layers.js.map +1 -1
- package/dist/chunks/browser.js +52 -10
- package/dist/chunks/browser.js.map +1 -1
- package/dist/chunks/export/bundle.js +14 -14
- package/dist/chunks/export/bundle.js.map +1 -1
- package/dist/chunks/export/components/groups.js +1 -1
- package/dist/chunks/export/storybook/component.js +47 -17
- package/dist/chunks/export/storybook/component.js.map +1 -1
- package/dist/chunks/export/storybook/export.js +64 -22
- package/dist/chunks/export/storybook/export.js.map +1 -1
- package/dist/chunks/import/html.js.map +1 -1
- package/dist/export.d.ts +7 -10
- package/dist/export.js +2 -2
- package/dist/styling.d.ts +6 -1
- package/package.json +3 -3
- package/src/cssom/types.ts +22 -0
- package/src/export/bundle.ts +17 -21
- package/src/export/css.ts +191 -17
- package/src/export/index.ts +1 -0
- package/src/export/position.ts +111 -0
- package/src/export/projection.ts +40 -37
- package/src/export/storybook/component.ts +69 -14
- package/src/export/storybook/export.ts +104 -23
- package/src/export/text.ts +51 -2
- package/src/import/scene-graph.ts +64 -8
- package/src/import/style-attribute.ts +1 -1
- package/src/runtime/browser/runtime.ts +3 -1
- package/src/runtime/headless/styles.ts +6 -6
- package/src/tokens/references.ts +16 -2
- package/src/tokens/stylesheet.ts +33 -1
- package/src/tokens/validate.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.js","names":[],"sources":["../../../../src/export/storybook/groups.ts","../../../../src/export/storybook/export.ts"],"sourcesContent":["import { behaviourArgs } from '#dom-css/behaviours/args'\nimport { uniq } from 'es-toolkit/array'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { restingVariant } from '@pairdraw/scene-graph/components'\nimport { deriveSlashVariantProperties } from '@pairdraw/scene-graph/variant-properties'\n\nimport type { StoryProp } from './module'\nimport { claimName } from './names'\n\ninterface StoryVariant {\n values: string[]\n node: SceneNode\n}\n\n/** One story file: a component set, a standalone component, or slash-named siblings. */\nexport interface StoryGroup {\n page: SceneNode\n title: string\n name: string\n props: StoryProp[]\n variants: StoryVariant[]\n /** Layer the story file links to, when the group has a layer of its own. */\n linkNode?: string\n /**\n * The component set or standalone component the group shows, which may generate a component\n * of its own; slash-named components grouped together have none.\n */\n set?: SceneNode\n}\n\nfunction isExported(node: SceneNode): boolean {\n return node.visible && !node.internalOnly\n}\n\n/** Variants whose property values collide are told apart by layer name instead. */\nfunction distinctVariants(group: StoryGroup): StoryGroup {\n const keys = group.variants.map((variant) => JSON.stringify(variant.values))\n if (new Set(keys).size === keys.length) return group\n const taken = new Set<string>()\n return {\n ...group,\n variants: group.variants.map((variant) => ({\n ...variant,\n values: [claimName(variant.node.name, taken, { separator: ' ' })]\n })),\n props: [{ name: 'Variant', options: [...taken] }]\n }\n}\n\nfunction componentSetGroup(\n graph: SceneGraph,\n page: SceneNode,\n section: string,\n set: SceneNode\n): StoryGroup {\n const definitions = set.componentPropertyDefinitions.filter((def) => def.type === 'VARIANT')\n // The variant at its default values opens the file as its Default story.\n const first = restingVariant(graph, set)\n const components = graph\n .getChildren(set.id)\n .filter((child) => child.type === 'COMPONENT' && isExported(child))\n const variants = [\n ...components.filter((component) => component === first),\n ...components.filter((component) => component !== first)\n ].map((component) => ({\n values: definitions.map((def) => component.componentPropertyValues[def.name] ?? ''),\n node: component\n }))\n const args = behaviourArgs(graph, set)\n const props = definitions.map((def, index): StoryProp => {\n const options = uniq([\n ...(def.variantOptions ?? []),\n ...variants.map((v) => v.values[index] ?? '')\n ])\n const boolean = args?.booleans.get(def.name)\n if (boolean) return { name: def.name, options, control: { type: 'boolean', ...boolean } }\n if (args?.states?.property === def.name)\n return {\n name: def.name,\n options,\n control: { type: 'state', rest: args.states.rest, disabled: args.states.disabled }\n }\n return { name: def.name, options }\n })\n return distinctVariants({\n page,\n title: `${section}/${set.name}`,\n name: set.name,\n props,\n variants,\n linkNode: set.name,\n set\n })\n}\n\nfunction componentGroup(page: SceneNode, section: string, component: SceneNode): StoryGroup {\n return {\n page,\n title: `${section}/${component.name}`,\n name: component.name,\n props: [],\n variants: [{ values: [], node: component }],\n linkNode: component.name,\n // A standalone component generates a component of its own too, as a set does.\n set: component\n }\n}\n\n/** `Button/Primary`, `Button/Secondary` → one `Button` group with a derived variant property. */\nfunction slashGroups(\n page: SceneNode,\n section: string,\n prefix: string,\n components: SceneNode[]\n): StoryGroup[] {\n const derived = deriveSlashVariantProperties(components, () => '')\n if (!derived) return components.map((component) => componentGroup(page, section, component))\n const props = derived.definitions.map((def) => ({\n name: def.name,\n options: def.variantOptions ?? []\n }))\n const variants = components.map((component) => {\n const values = derived.variants.get(component.id)?.componentPropertyValues ?? {}\n return { values: props.map((prop) => values[prop.name] ?? ''), node: component }\n })\n return [distinctVariants({ page, title: `${section}/${prefix}`, name: prefix, props, variants })]\n}\n\n/**\n * The story files a page produces, in layer order, titled under `section`, the page's name by\n * default. Instances are never exported.\n */\nexport function collectGroups(\n graph: SceneGraph,\n page: SceneNode,\n section = page.name\n): StoryGroup[] {\n const groups: StoryGroup[] = []\n const slashed = new Map<string, SceneNode[]>()\n const visit = (node: SceneNode) => {\n if (!isExported(node) || node.type === 'INSTANCE') return\n if (node.type === 'COMPONENT_SET') {\n const group = componentSetGroup(graph, page, section, node)\n if (group.variants.length > 0) groups.push(group)\n return\n }\n if (node.type === 'COMPONENT') {\n const [prefix, ...rest] = node.name.split('/')\n const name = prefix.trim()\n if (rest.length === 0 || !name) groups.push(componentGroup(page, section, node))\n else slashed.set(name, [...(slashed.get(name) ?? []), node])\n return\n }\n for (const child of graph.getChildren(node.id)) visit(child)\n }\n for (const child of graph.getChildren(page.id)) visit(child)\n for (const [prefix, components] of slashed)\n groups.push(...slashGroups(page, section, prefix, components))\n return groups\n}\n","import { PLACEMENT } from '#dom-css/behaviours/states/layers'\nimport { tokenStylesheet } from '#dom-css/tokens/stylesheet'\nimport type { DesignDocument, DesignNode, DesignStyleDeclaration } from '#dom-css/types'\nimport { compact } from 'es-toolkit/array'\nimport { omit } from 'es-toolkit/object'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport {\n designFontRequests,\n fontFaceStylesheet,\n type ExportHTMLFile,\n type WebFontFaceRequest,\n type WebFontFaceResolver\n} from '../bundle'\nimport { componentModel, type ComponentGenerator, type ComponentModel } from '../components/model'\nimport { reactComponent } from '../components/react'\nimport type { ComponentReferences } from '../components/references'\nimport type { ComponentStyling } from '../components/styling'\nimport { vueComponent } from '../components/vue'\nimport { serializeHTML, serializeNode } from '../html'\nimport { sceneNodeToDesignDocument, type VectorElementRenderer } from '../projection'\nimport { printComponentStories } from './component'\nimport { collectGroups, type StoryGroup } from './groups'\nimport {\n printStoryModule,\n STORYBOOK_PACKAGES,\n type StoryDesign,\n type StorybookFramework\n} from './module'\nimport { claimName, fileTags, identifierName, storyId, VARIANT_TAG } from './names'\n\nexport { STORYBOOK_FRAMEWORKS, type StorybookFramework } from './module'\n\n/** Frameworks whose stories render generated components; HTML stories stay static. */\nconst GENERATORS: Partial<Record<StorybookFramework, ComponentGenerator>> = {\n vue: vueComponent,\n react: reactComponent\n}\n\nexport interface ExportStorybookOptions {\n framework?: StorybookFramework\n /**\n * How Vue and React components are styled: a stylesheet beside each, by default, or Tailwind\n * utilities in their markup, which needs Tailwind set up in the Storybook project.\n */\n styling?: ComponentStyling\n /** Limit the export to one page. Defaults to every page. */\n pageId?: string\n /**\n * The document's name, which titles its stories, such as `Pricing/Plan picker`, with each\n * page's name between when it has several. Without it, stories are titled by page.\n */\n document?: string\n /** Repository-relative `.fig`/`.pen` path; adds a `pairdraw://` design link to stories. */\n linkPath?: string\n /** Renders a variant to PNG; each story then shows it next to the link as its design. */\n renderDesignImage?: (nodeId: string) => Promise<Uint8Array>\n /** Draws vector layers as inline SVG, from the engine's SVG export. */\n vectorElement?: VectorElementRenderer\n /**\n * How each story file is written, which a caller decides, such as from rules a user wrote:\n * which stories it has and its title. Every file is written as `variants` by default.\n */\n plan?: (target: StoryTarget) => StoryPlan\n /**\n * Finds the font files the stories' text uses, which ship with them in `fonts/` and load\n * before a story shows, so its text draws in the document's fonts. Without it, text uses\n * whatever fonts Storybook's page has.\n */\n fonts?: WebFontFaceResolver\n /**\n * The folder a document's shared files go in, its fonts and design tokens, which must differ\n * for each document exported into the same place; `pairdraw/<document>` by default.\n */\n folder?: string\n}\n\n/** How a story file shows its component: every variant, Default alone, a gallery, or not. */\nexport const STORY_MODES = ['variants', 'single', 'gallery', 'none'] as const\nexport type StoryMode = (typeof STORY_MODES)[number]\n\n/** A story file the export would write, as a plan reads it. */\nexport interface StoryTarget {\n /** The document's name, when the export knows it. */\n document: string | undefined\n page: string\n /** The component set's or component's name, or a slash-named group's prefix. */\n name: string\n /** The title the file has unless the plan gives another. */\n title: string\n}\n\n/** What a plan says about a story file; anything it leaves out stays as it would be. */\nexport interface StoryPlan {\n stories?: StoryMode\n title?: string\n /**\n * Whether a Vue or React export generates a component for the file, as it does by default,\n * or keeps static stories of its variants.\n */\n generate?: boolean\n}\n\nexport interface StorybookFile extends ExportHTMLFile {\n /** Name of the page the file was generated from. */\n page: string\n}\n\n/** Layers whose name no other layer carries; the link scheme can only address those. */\nfunction uniqueLayerNames(graph: SceneGraph): Set<string> {\n const counts = new Map<string, number>()\n for (const node of graph.getAllNodes()) counts.set(node.name, (counts.get(node.name) ?? 0) + 1)\n return new Set([...counts].filter(([, count]) => count === 1).map(([name]) => name))\n}\n\ninterface ModuleContext {\n graph: SceneGraph\n framework: StorybookFramework\n linkPath?: string\n uniqueNames: Set<string>\n /** Export name of each story, by variant index. */\n storyNames: string[]\n /** Import path of each variant's design image, by variant index. */\n images: string[]\n vectorElement?: VectorElementRenderer\n mode: Exclude<StoryMode, 'none'>\n /** Stylesheets every story file imports, such as the fonts its text uses. */\n styles: string[]\n}\n\nfunction designLink(\n context: Pick<ModuleContext, 'linkPath' | 'uniqueNames'>,\n ...candidates: (string | undefined)[]\n): StoryDesign[] {\n const node = candidates.find((name) => name !== undefined && context.uniqueNames.has(name))\n if (!context.linkPath || !node) return []\n const url = `pairdraw://open?file=${encodeURIComponent(context.linkPath)}&node=${encodeURIComponent(node)}`\n return [{ type: 'link', url }]\n}\n\n/** Story export names, which also name the design images. */\nfunction storyNames(group: StoryGroup): string[] {\n // Named apart from the module's own types, `Story` and `Args`.\n const taken = new Set(['story', 'args'])\n const key = (name: string) => name.toLowerCase()\n return group.variants.map((variant, index) => {\n // The first variant, the one the design shows at rest, is the file's Default story.\n const text = index === 0 || group.props.length === 0 ? 'Default' : variant.values.join(' ')\n return claimName(identifierName(text, 'Variant'), taken, { key })\n })\n}\n\nfunction storyLabel(group: StoryGroup, values: string[], index: number): string {\n if (index === 0 || group.props.length === 0) return 'Default'\n return group.props.map((prop, i) => `${prop.name}=${values[i] ?? ''}`).join(', ')\n}\n\n/**\n * A variant drawn on its own, as a story shows it: its root, placed nowhere in particular, hugs\n * its content where the design gives it no width, rather than filling the story's canvas, and sizes include padding and\n * borders, which no page reset around the story says.\n */\nfunction standalone(document: DesignDocument): DesignDocument {\n const visit = (node: DesignNode, root: boolean) => {\n if (node.type !== 'element') return\n // A variant's root drops where the set places it, which is not where the story draws it,\n // and stays the containing block of the layers placed inside it.\n const placed = root && Object.hasOwn(node.inlineStyle ?? {}, 'position')\n const style: DesignStyleDeclaration = root\n ? { ...omit({ ...node.inlineStyle }, PLACEMENT), ...(placed ? { position: 'relative' } : {}) }\n : { ...node.inlineStyle }\n const has = (property: string) => Object.hasOwn(style, property)\n if ((has('width') || has('height')) && !has('box-sizing')) style['box-sizing'] = 'border-box'\n if (root && !has('width')) style.width = 'fit-content'\n node.inlineStyle = style\n for (const child of node.children) visit(child, false)\n }\n for (const child of document.children) visit(child, true)\n return document\n}\n\nfunction storyModule(group: StoryGroup, context: ModuleContext): string {\n return printStoryModule({\n framework: context.framework,\n title: group.title,\n tags: fileTags(group.page.name),\n styles: context.styles,\n name: group.name,\n props: group.props,\n variants: group.variants.map((variant) => ({\n values: variant.values,\n html: serializeHTML(\n standalone(\n sceneNodeToDesignDocument(context.graph, variant.node.id, {\n includeSourceIds: false,\n vectorElement: context.vectorElement\n })\n )\n )\n })),\n metaDesign: designLink(context, group.linkNode),\n images: context.images,\n gallery:\n context.mode === 'gallery'\n ? group.variants.map((variant) => ({\n values: variant.values,\n label: serializeNode({ type: 'text', text: variant.values.join(', ') || group.name })\n }))\n : null,\n stories: (context.mode === 'variants' ? group.variants : group.variants.slice(0, 1)).map(\n (variant, i) => ({\n exportName: context.storyNames[i] ?? '',\n label: storyLabel(group, variant.values, i),\n tags: i === 0 ? [] : [VARIANT_TAG],\n values: variant.values,\n design: [\n ...designLink(context, variant.node.name, group.linkNode),\n ...(context.images[i] ? [{ type: 'image' as const, variant: i }] : [])\n ]\n })\n )\n })\n}\n\n/** A story file to write: its group, the page it comes from, and its claimed file name. */\ninterface StoryEntry {\n page: SceneNode\n group: StoryGroup\n file: string\n mode: Exclude<StoryMode, 'none'>\n generate: boolean\n}\n\n/**\n * Every group's story file, with names claimed on every page so a one-page export picks the\n * same names as a full one, kept for the pages the export covers.\n */\nfunction storyEntries(\n graph: SceneGraph,\n { pageId, document, plan }: Pick<ExportStorybookOptions, 'pageId' | 'document' | 'plan'>\n): StoryEntry[] {\n const takenFiles = new Set<string>()\n const takenIds = new Set<string>()\n const entries: StoryEntry[] = []\n const pages = graph.getPages()\n // Pages without components, such as an empty first page, add no level to the titles.\n const storied = pages.filter((page) => collectGroups(graph, page).length > 0)\n const section = (page: SceneNode) => {\n if (document === undefined) return page.name\n return storied.length > 1 ? `${document}/${page.name}` : document\n }\n for (const page of pages) {\n for (const group of collectGroups(graph, page, section(page))) {\n const planned = plan?.({ document, page: page.name, name: group.name, title: group.title })\n const mode = planned?.stories ?? 'variants'\n if (mode === 'none') continue\n // Storybook ids ignore case and punctuation, so `Library/Card` and `library/card` collide.\n group.title = claimName(planned?.title ?? group.title, takenIds, {\n separator: ' ',\n key: storyId\n })\n // File names are compared ignoring case for case-insensitive file systems.\n const file = claimName(identifierName(group.name, 'Component'), takenFiles, {\n key: (name) => name.toLowerCase()\n })\n const generate = planned?.generate ?? true\n if (!pageId || page.id === pageId) entries.push({ page, group, file, mode, generate })\n }\n }\n return entries\n}\n\n/**\n * The component each entry's set generates, by set id, built twice: first alone, so each\n * knows its props, then knowing all the others, so an instance of one uses it rather than\n * drawing its layers.\n */\nfunction generatedModels(\n graph: SceneGraph,\n entries: readonly StoryEntry[],\n vectorElement: VectorElementRenderer | undefined\n): Map<string, ComponentModel> {\n // Components are imported by their files' names, so the two always match. A group's item\n // component gets a file of its own, named apart from every story file.\n const taken = new Set(entries.map((entry) => entry.file.toLowerCase()))\n const itemNames = new Map(\n entries.map((entry) => [\n entry.file,\n claimName(`${entry.file}Item`, taken, { key: (name) => name.toLowerCase() })\n ])\n )\n const model = (set: SceneNode, file: string, references?: ComponentReferences) =>\n componentModel(graph, set, {\n vectorElement,\n references,\n name: file,\n itemName: itemNames.get(file)\n })\n const alone = new Map<string, ComponentModel>()\n for (const { group, file, generate } of entries) {\n const component = generate && group.set && model(group.set, file)\n if (group.set && component) alone.set(group.set.id, component)\n }\n const models = new Map<string, ComponentModel>()\n for (const { group, file } of entries) {\n const component = group.set && alone.has(group.set.id) && model(group.set, file, alone)\n if (group.set && component) models.set(group.set.id, component)\n }\n return models\n}\n\n/** The folder a document's shared files go in, unless the caller names one. */\nfunction documentFolder(graph: SceneGraph, options: ExportStorybookOptions): string {\n if (options.folder) return options.folder\n const page = options.pageId ? graph.getNode(options.pageId)?.name : undefined\n const named = compact([options.document ?? 'document', page]).map((name) => storyId(name))\n return `pairdraw/${named.join('-')}`\n}\n\n/**\n * The font files the entries' text uses, and the stylesheet that loads them. Faces load\n * before text draws, so a story never shows a fallback font first.\n */\nasync function storyFonts(\n graph: SceneGraph,\n entries: readonly StoryEntry[],\n options: ExportStorybookOptions,\n folder: string\n): Promise<ExportHTMLFile[]> {\n if (!options.fonts) return []\n const requests = new Map<string, WebFontFaceRequest>()\n for (const { group } of entries)\n for (const variant of group.variants)\n for (const request of designFontRequests(\n sceneNodeToDesignDocument(graph, variant.node.id, { includeSourceIds: false })\n ))\n requests.set(`${request.family}|${request.weight}|${request.style ?? 'normal'}`, request)\n if (requests.size === 0) return []\n const assets = await options.fonts([...requests.values()], `${folder}/fonts`)\n if (assets.length === 0) return []\n const css = await fontFaceStylesheet(assets, { from: folder, display: 'block' })\n return [...assets, { path: `${folder}/fonts.css`, content: css }]\n}\n\n/**\n * The document's design tokens as custom properties, which stories' styles refer to as\n * `var(--…)` wherever the design binds a variable, so they resolve as the design draws them.\n */\nasync function storyTokens(graph: SceneGraph, folder: string): Promise<ExportHTMLFile[]> {\n if (graph.variables.size === 0) return []\n const { css } = await tokenStylesheet(graph, { format: 'css' })\n return css ? [{ path: `${folder}/tokens.css`, content: css }] : []\n}\n\n/**\n * Generate one CSF3 `.stories.ts` file per component or component set, plus a\n * `<Name>.design/` folder of variant images when `renderDesignImage` is given.\n */\nexport async function exportStorybook(\n graph: SceneGraph,\n options: ExportStorybookOptions = {}\n): Promise<StorybookFile[]> {\n const framework = options.framework ?? 'react'\n const uniqueNames = uniqueLayerNames(graph)\n const files: StorybookFile[] = []\n const add = (page: SceneNode, path: string, content: string | Uint8Array) =>\n files.push({ path, content, page: page.name })\n\n const entries = storyEntries(graph, options)\n const folder = documentFolder(graph, options)\n const shared = [\n ...(await storyFonts(graph, entries, options, folder)),\n ...(await storyTokens(graph, folder))\n ]\n const firstPage = entries.at(0)?.page\n if (firstPage) for (const file of shared) add(firstPage, file.path, file.content)\n // Every story file loads the document's fonts and tokens.\n const styles = shared.filter((file) => file.path.endsWith('.css')).map((file) => `./${file.path}`)\n const generate = GENERATORS[framework]\n const models = generate ? generatedModels(graph, entries, options.vectorElement) : new Map()\n\n for (const { page, group, file, mode } of entries) {\n const component = group.set && models.get(group.set.id)\n if (generate && component) {\n const generated = await generate(component, { styling: options.styling })\n for (const item of generated.files) add(page, item.path, item.content)\n const design = designLink({ linkPath: options.linkPath, uniqueNames }, group.linkNode)\n add(\n page,\n `${file}.stories.ts`,\n printComponentStories({\n storybook: STORYBOOK_PACKAGES[framework],\n title: group.title,\n tags: fileTags(group.page.name),\n styles,\n component,\n generated,\n // A gallery lays out static variants; a generated component's stories are its states.\n single: mode === 'single',\n design: design.flatMap((entry) =>\n entry.type === 'link' ? [{ name: 'Pairdraw', type: 'link', url: entry.url }] : []\n )\n })\n )\n continue\n }\n\n // Only the stories a file keeps get design images; a gallery or Default alone keeps one.\n const names = storyNames(group).slice(0, mode === 'variants' ? undefined : 1)\n const render = options.renderDesignImage\n const images = render ? names.map((name) => `${file}.design/${name}.png`) : []\n if (render) {\n for (const [i, variant] of group.variants.slice(0, names.length).entries())\n add(page, images[i] ?? '', await render(variant.node.id))\n }\n const context = {\n ...options,\n graph,\n framework,\n uniqueNames,\n storyNames: names,\n images,\n mode,\n styles\n }\n add(page, `${file}.stories.ts`, storyModule(group, context))\n }\n return files\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,SAAS,WAAW,MAA0B;CAC5C,OAAO,KAAK,WAAW,CAAC,KAAK;AAC/B;;AAGA,SAAS,iBAAiB,OAA+B;CACvD,MAAM,OAAO,MAAM,SAAS,KAAK,YAAY,KAAK,UAAU,QAAQ,MAAM,CAAC;CAC3E,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC,SAAS,KAAK,QAAQ,OAAO;CAC/C,MAAM,wBAAQ,IAAI,IAAY;CAC9B,OAAO;EACL,GAAG;EACH,UAAU,MAAM,SAAS,KAAK,aAAa;GACzC,GAAG;GACH,QAAQ,CAAC,UAAU,QAAQ,KAAK,MAAM,OAAO,EAAE,WAAW,IAAI,CAAC,CAAC;EAClE,EAAE;EACF,OAAO,CAAC;GAAE,MAAM;GAAW,SAAS,CAAC,GAAG,KAAK;EAAE,CAAC;CAClD;AACF;AAE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AAM,SAAS,WAAW,EAAE,SAAS,QAAQ,QAAQ,CAAC;GACxE,KAAK,MAAM,QAAQ,UAAU,OAAO,IAAI,MAAM,KAAK,MAAM,KAAK,OAAO;GACrE,MAAM,SAAS,WAAW;IAAE,UAAU,QAAQ;IAAU;GAAY,GAAG,MAAM,QAAQ;GACrF,IACE,MACA,GAAG,KAAK,cACR,sBAAsB;IACpB,WAAW,mBAAmB;IAC9B,OAAO,MAAM;IACb,MAAM,SAAS,MAAM,KAAK,IAAI;IAC9B;IACA;IACA;IAEA,QAAQ,SAAS;IACjB,QAAQ,OAAO,SAAS,UACtB,MAAM,SAAS,SAAS,CAAC;KAAE,MAAM;KAAY,MAAM;KAAQ,KAAK,MAAM;IAAI,CAAC,IAAI,CAAC,CAClF;GACF,CAAC,CACH;GACA;EACF;EAGA,MAAM,QAAQ,WAAW,KAAK,CAAC,CAAC,MAAM,GAAG,SAAS,aAAa,KAAA,IAAY,CAAC;EAC5E,MAAM,SAAS,QAAQ;EACvB,MAAM,SAAS,SAAS,MAAM,KAAK,SAAS,GAAG,KAAK,UAAU,KAAK,KAAK,IAAI,CAAC;EAC7E,IAAI,QACF,KAAK,MAAM,CAAC,GAAG,YAAY,MAAM,SAAS,MAAM,GAAG,MAAM,MAAM,CAAC,CAAC,QAAQ,GACvE,IAAI,MAAM,OAAO,MAAM,IAAI,MAAM,OAAO,QAAQ,KAAK,EAAE,CAAC;EAE5D,MAAM,UAAU;GACd,GAAG;GACH;GACA;GACA;GACA,YAAY;GACZ;GACA;GACA;EACF;EACA,IAAI,MAAM,GAAG,KAAK,cAAc,YAAY,OAAO,OAAO,CAAC;CAC7D;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"export.js","names":[],"sources":["../../../../src/export/storybook/groups.ts","../../../../src/export/storybook/export.ts"],"sourcesContent":["import { behaviourArgs } from '#dom-css/behaviours/args'\nimport { uniq } from 'es-toolkit/array'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { restingVariant } from '@pairdraw/scene-graph/components'\nimport { deriveSlashVariantProperties } from '@pairdraw/scene-graph/variant-properties'\n\nimport type { StoryProp } from './module'\nimport { claimName } from './names'\n\ninterface StoryVariant {\n values: string[]\n node: SceneNode\n}\n\n/** One story file: a component set, a standalone component, or slash-named siblings. */\nexport interface StoryGroup {\n page: SceneNode\n title: string\n name: string\n props: StoryProp[]\n variants: StoryVariant[]\n /** Layer the story file links to, when the group has a layer of its own. */\n linkNode?: string\n /**\n * The component set or standalone component the group shows, which may generate a component\n * of its own; slash-named components grouped together have none.\n */\n set?: SceneNode\n}\n\nfunction isExported(node: SceneNode): boolean {\n return node.visible && !node.internalOnly\n}\n\n/** Variants whose property values collide are told apart by layer name instead. */\nfunction distinctVariants(group: StoryGroup): StoryGroup {\n const keys = group.variants.map((variant) => JSON.stringify(variant.values))\n if (new Set(keys).size === keys.length) return group\n const taken = new Set<string>()\n return {\n ...group,\n variants: group.variants.map((variant) => ({\n ...variant,\n values: [claimName(variant.node.name, taken, { separator: ' ' })]\n })),\n props: [{ name: 'Variant', options: [...taken] }]\n }\n}\n\nfunction componentSetGroup(\n graph: SceneGraph,\n page: SceneNode,\n section: string,\n set: SceneNode\n): StoryGroup {\n const definitions = set.componentPropertyDefinitions.filter((def) => def.type === 'VARIANT')\n // The variant at its default values opens the file as its Default story.\n const first = restingVariant(graph, set)\n const components = graph\n .getChildren(set.id)\n .filter((child) => child.type === 'COMPONENT' && isExported(child))\n const variants = [\n ...components.filter((component) => component === first),\n ...components.filter((component) => component !== first)\n ].map((component) => ({\n values: definitions.map((def) => component.componentPropertyValues[def.name] ?? ''),\n node: component\n }))\n const args = behaviourArgs(graph, set)\n const props = definitions.map((def, index): StoryProp => {\n const options = uniq([\n ...(def.variantOptions ?? []),\n ...variants.map((v) => v.values[index] ?? '')\n ])\n const boolean = args?.booleans.get(def.name)\n if (boolean) return { name: def.name, options, control: { type: 'boolean', ...boolean } }\n if (args?.states?.property === def.name)\n return {\n name: def.name,\n options,\n control: { type: 'state', rest: args.states.rest, disabled: args.states.disabled }\n }\n return { name: def.name, options }\n })\n return distinctVariants({\n page,\n title: `${section}/${set.name}`,\n name: set.name,\n props,\n variants,\n linkNode: set.name,\n set\n })\n}\n\nfunction componentGroup(page: SceneNode, section: string, component: SceneNode): StoryGroup {\n return {\n page,\n title: `${section}/${component.name}`,\n name: component.name,\n props: [],\n variants: [{ values: [], node: component }],\n linkNode: component.name,\n // A standalone component generates a component of its own too, as a set does.\n set: component\n }\n}\n\n/** `Button/Primary`, `Button/Secondary` → one `Button` group with a derived variant property. */\nfunction slashGroups(\n page: SceneNode,\n section: string,\n prefix: string,\n components: SceneNode[]\n): StoryGroup[] {\n const derived = deriveSlashVariantProperties(components, () => '')\n if (!derived) return components.map((component) => componentGroup(page, section, component))\n const props = derived.definitions.map((def) => ({\n name: def.name,\n options: def.variantOptions ?? []\n }))\n const variants = components.map((component) => {\n const values = derived.variants.get(component.id)?.componentPropertyValues ?? {}\n return { values: props.map((prop) => values[prop.name] ?? ''), node: component }\n })\n return [distinctVariants({ page, title: `${section}/${prefix}`, name: prefix, props, variants })]\n}\n\n/**\n * The story files a page produces, in layer order, titled under `section`, the page's name by\n * default. Instances are never exported.\n */\nexport function collectGroups(\n graph: SceneGraph,\n page: SceneNode,\n section = page.name\n): StoryGroup[] {\n const groups: StoryGroup[] = []\n const slashed = new Map<string, SceneNode[]>()\n const visit = (node: SceneNode) => {\n if (!isExported(node) || node.type === 'INSTANCE') return\n if (node.type === 'COMPONENT_SET') {\n const group = componentSetGroup(graph, page, section, node)\n if (group.variants.length > 0) groups.push(group)\n return\n }\n if (node.type === 'COMPONENT') {\n const [prefix, ...rest] = node.name.split('/')\n const name = prefix.trim()\n if (rest.length === 0 || !name) groups.push(componentGroup(page, section, node))\n else slashed.set(name, [...(slashed.get(name) ?? []), node])\n return\n }\n for (const child of graph.getChildren(node.id)) visit(child)\n }\n for (const child of graph.getChildren(page.id)) visit(child)\n for (const [prefix, components] of slashed)\n groups.push(...slashGroups(page, section, prefix, components))\n return groups\n}\n","import { PLACEMENT } from '#dom-css/behaviours/states/layers'\nimport { tokenStylesheet } from '#dom-css/tokens/stylesheet'\nimport type { DesignDocument, DesignNode, DesignStyleDeclaration } from '#dom-css/types'\nimport { compact } from 'es-toolkit/array'\nimport { omit } from 'es-toolkit/object'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport {\n designFontRequests,\n fontFaceStylesheet,\n type ExportHTMLFile,\n type WebFontFaceRequest,\n type WebFontFaceResolver\n} from '../bundle'\nimport { componentModel, type ComponentGenerator, type ComponentModel } from '../components/model'\nimport { reactComponent } from '../components/react'\nimport type { ComponentReferences } from '../components/references'\nimport type { ComponentStyling } from '../components/styling'\nimport { vueComponent } from '../components/vue'\nimport { serializeHTML, serializeNode } from '../html'\nimport { sceneNodeToDesignDocument, type VectorElementRenderer } from '../projection'\nimport { componentStories, printComponentStories, type StoryValues } from './component'\nimport { collectGroups, type StoryGroup } from './groups'\nimport {\n printStoryModule,\n STORYBOOK_PACKAGES,\n type StoryDesign,\n type StorybookFramework\n} from './module'\nimport { claimName, fileTags, identifierName, storyId, VARIANT_TAG } from './names'\n\nexport { STORYBOOK_FRAMEWORKS, type StorybookFramework } from './module'\n\n/** Frameworks whose stories render generated components; HTML stories stay static. */\nconst GENERATORS: Partial<Record<StorybookFramework, ComponentGenerator>> = {\n vue: vueComponent,\n react: reactComponent\n}\n\nexport interface ExportStorybookOptions {\n framework?: StorybookFramework\n /**\n * How Vue and React components are styled: a stylesheet beside each, by default, or Tailwind\n * utilities in their markup, which needs Tailwind set up in the Storybook project.\n */\n styling?: ComponentStyling\n /** Limit the export to one page. Defaults to every page. */\n pageId?: string\n /**\n * The document's name, which titles its stories, such as `Pricing/Plan picker`, with each\n * page's name between when it has several. Without it, stories are titled by page.\n */\n document?: string\n /** Repository-relative `.fig`/`.pen` path; adds a `pairdraw://` design link to stories. */\n linkPath?: string\n /** Renders a variant to PNG; each story then shows it next to the link as its design. */\n renderDesignImage?: (nodeId: string) => Promise<Uint8Array>\n /** Draws vector layers as inline SVG, from the engine's SVG export. */\n vectorElement?: VectorElementRenderer\n /**\n * How each story file is written, which a caller decides, such as from rules a user wrote:\n * which stories it has and its title. Every file is written as `variants` by default.\n */\n plan?: (target: StoryTarget) => StoryPlan\n /**\n * Finds the font files the stories' text uses, which ship with them in `fonts/` and load\n * before a story shows, so its text draws in the document's fonts. Without it, text uses\n * whatever fonts Storybook's page has.\n */\n fonts?: WebFontFaceResolver\n /**\n * The folder a document's shared files go in, its fonts and design tokens, which must differ\n * for each document exported into the same place; `pairdraw/<document>` by default.\n */\n folder?: string\n}\n\n/** How a story file shows its component: every variant, Default alone, a gallery, or not. */\nexport const STORY_MODES = ['variants', 'single', 'gallery', 'none'] as const\nexport type StoryMode = (typeof STORY_MODES)[number]\n\n/** A story file the export would write, as a plan reads it. */\nexport interface StoryTarget {\n /** The document's name, when the export knows it. */\n document: string | undefined\n page: string\n /** The component set's or component's name, or a slash-named group's prefix. */\n name: string\n /** The title the file has unless the plan gives another. */\n title: string\n}\n\n/** What a plan says about a story file; anything it leaves out stays as it would be. */\nexport interface StoryPlan {\n stories?: StoryMode\n title?: string\n /**\n * Whether a Vue or React export generates a component for the file, as it does by default,\n * or keeps static stories of its variants.\n */\n generate?: boolean\n}\n\nexport interface StorybookFile extends ExportHTMLFile {\n /** Name of the page the file was generated from. */\n page: string\n}\n\n/** Layers whose name no other layer carries; the link scheme can only address those. */\nfunction uniqueLayerNames(graph: SceneGraph): Set<string> {\n const counts = new Map<string, number>()\n for (const node of graph.getAllNodes()) counts.set(node.name, (counts.get(node.name) ?? 0) + 1)\n return new Set([...counts].filter(([, count]) => count === 1).map(([name]) => name))\n}\n\ninterface ModuleContext {\n graph: SceneGraph\n framework: StorybookFramework\n linkPath?: string\n uniqueNames: Set<string>\n /** Export name of each story, by variant index. */\n storyNames: string[]\n /** Import path of each variant's design image, by variant index. */\n images: string[]\n vectorElement?: VectorElementRenderer\n mode: Exclude<StoryMode, 'none'>\n /** Stylesheets every story file imports, such as the fonts its text uses. */\n styles: string[]\n}\n\nfunction designLink(\n context: Pick<ModuleContext, 'linkPath' | 'uniqueNames'>,\n ...candidates: (string | undefined)[]\n): StoryDesign[] {\n const node = candidates.find((name) => name !== undefined && context.uniqueNames.has(name))\n if (!context.linkPath || !node) return []\n const url = `pairdraw://open?file=${encodeURIComponent(context.linkPath)}&node=${encodeURIComponent(node)}`\n return [{ type: 'link', url }]\n}\n\n/** Story export names, which also name the design images. */\nfunction storyNames(group: StoryGroup): string[] {\n // Named apart from the module's own types, `Story` and `Args`.\n const taken = new Set(['story', 'args'])\n const key = (name: string) => name.toLowerCase()\n return group.variants.map((variant, index) => {\n // The first variant, the one the design shows at rest, is the file's Default story.\n const text = index === 0 || group.props.length === 0 ? 'Default' : variant.values.join(' ')\n return claimName(identifierName(text, 'Variant'), taken, { key })\n })\n}\n\nfunction storyLabel(group: StoryGroup, values: string[], index: number): string {\n if (index === 0 || group.props.length === 0) return 'Default'\n return group.props.map((prop, i) => `${prop.name}=${values[i] ?? ''}`).join(', ')\n}\n\n/**\n * A variant drawn on its own, as a story shows it: its root, placed nowhere in particular, hugs\n * its content where the design gives it no width, rather than filling the story's canvas, and sizes include padding and\n * borders, which no page reset around the story says.\n */\nfunction standalone(document: DesignDocument): DesignDocument {\n const visit = (node: DesignNode, root: boolean) => {\n if (node.type !== 'element') return\n // A variant's root drops where the set places it, which is not where the story draws it,\n // and stays the containing block of the layers placed inside it.\n const placed = root && Object.hasOwn(node.inlineStyle ?? {}, 'position')\n const style: DesignStyleDeclaration = root\n ? { ...omit({ ...node.inlineStyle }, PLACEMENT), ...(placed ? { position: 'relative' } : {}) }\n : { ...node.inlineStyle }\n const has = (property: string) => Object.hasOwn(style, property)\n if ((has('width') || has('height')) && !has('box-sizing')) style['box-sizing'] = 'border-box'\n if (root && !has('width')) style.width = 'fit-content'\n node.inlineStyle = style\n for (const child of node.children) visit(child, false)\n }\n for (const child of document.children) visit(child, true)\n return document\n}\n\nfunction storyModule(group: StoryGroup, context: ModuleContext): string {\n return printStoryModule({\n framework: context.framework,\n title: group.title,\n tags: fileTags(group.page.name),\n styles: context.styles,\n name: group.name,\n props: group.props,\n variants: group.variants.map((variant) => ({\n values: variant.values,\n html: serializeHTML(\n standalone(\n sceneNodeToDesignDocument(context.graph, variant.node.id, {\n includeSourceIds: false,\n vectorElement: context.vectorElement\n })\n )\n )\n })),\n metaDesign: designLink(context, group.linkNode),\n images: context.images,\n gallery:\n context.mode === 'gallery'\n ? group.variants.map((variant) => ({\n values: variant.values,\n label: serializeNode({ type: 'text', text: variant.values.join(', ') || group.name })\n }))\n : null,\n stories: (context.mode === 'variants' ? group.variants : group.variants.slice(0, 1)).map(\n (variant, i) => ({\n exportName: context.storyNames[i] ?? '',\n label: storyLabel(group, variant.values, i),\n tags: i === 0 ? [] : [VARIANT_TAG],\n values: variant.values,\n design: [\n ...designLink(context, variant.node.name, group.linkNode),\n ...(context.images[i] ? [{ type: 'image' as const, variant: i }] : [])\n ]\n })\n )\n })\n}\n\n/** A story file to write: its group, the page it comes from, and its claimed file name. */\ninterface StoryEntry {\n page: SceneNode\n group: StoryGroup\n file: string\n mode: Exclude<StoryMode, 'none'>\n generate: boolean\n}\n\n/**\n * Every group's story file, with names claimed on every page so a one-page export picks the\n * same names as a full one, kept for the pages the export covers.\n */\nfunction storyEntries(\n graph: SceneGraph,\n { pageId, document, plan }: Pick<ExportStorybookOptions, 'pageId' | 'document' | 'plan'>\n): StoryEntry[] {\n const takenFiles = new Set<string>()\n const takenIds = new Set<string>()\n const entries: StoryEntry[] = []\n const pages = graph.getPages()\n // Pages without components, such as an empty first page, add no level to the titles.\n const storied = pages.filter((page) => collectGroups(graph, page).length > 0)\n const section = (page: SceneNode) => {\n if (document === undefined) return page.name\n return storied.length > 1 ? `${document}/${page.name}` : document\n }\n for (const page of pages) {\n for (const group of collectGroups(graph, page, section(page))) {\n const planned = plan?.({ document, page: page.name, name: group.name, title: group.title })\n const mode = planned?.stories ?? 'variants'\n if (mode === 'none') continue\n // Storybook ids ignore case and punctuation, so `Library/Card` and `library/card` collide.\n group.title = claimName(planned?.title ?? group.title, takenIds, {\n separator: ' ',\n key: storyId\n })\n // File names are compared ignoring case for case-insensitive file systems.\n const file = claimName(identifierName(group.name, 'Component'), takenFiles, {\n key: (name) => name.toLowerCase()\n })\n const generate = planned?.generate ?? true\n if (!pageId || page.id === pageId) entries.push({ page, group, file, mode, generate })\n }\n }\n return entries\n}\n\n/**\n * The variant a generated component's story draws: the one whose variant property values match\n * the story's args over the component's rest values. A state no single variant draws, such as\n * a text field's words, has none.\n */\nfunction variantForStory(\n group: StoryGroup,\n component: ComponentModel,\n values: StoryValues\n): StoryGroup['variants'][number] | undefined {\n const args = component.args\n // The variant property values the component shows at rest, and with the story's args set.\n const shown = (story: StoryValues): Record<string, string> => {\n const record: Record<string, string> = {}\n for (const prop of component.props)\n record[prop.property] = String(story[prop.name] ?? prop.default)\n for (const [property, boolean] of args.booleans)\n record[property] = (story[boolean.name] ?? false) ? boolean.on : boolean.off\n if (args.states)\n record[args.states.property] =\n story['disabled'] === true && args.states.disabled !== undefined\n ? args.states.disabled\n : args.states.rest\n if (args.filled) record[args.filled.property] = args.filled.off\n return record\n }\n const target = shown(values)\n return group.variants.find((variant) =>\n Object.entries(target).every(\n ([property, value]) => variant.node.componentPropertyValues[property] === value\n )\n )\n}\n\n/**\n * The component each entry's set generates, by set id, built twice: first alone, so each\n * knows its props, then knowing all the others, so an instance of one uses it rather than\n * drawing its layers.\n */\nfunction generatedModels(\n graph: SceneGraph,\n entries: readonly StoryEntry[],\n vectorElement: VectorElementRenderer | undefined\n): Map<string, ComponentModel> {\n // Components are imported by their files' names, so the two always match. A group's item\n // component gets a file of its own, named apart from every story file.\n const taken = new Set(entries.map((entry) => entry.file.toLowerCase()))\n const itemNames = new Map(\n entries.map((entry) => [\n entry.file,\n claimName(`${entry.file}Item`, taken, { key: (name) => name.toLowerCase() })\n ])\n )\n const model = (set: SceneNode, file: string, references?: ComponentReferences) =>\n componentModel(graph, set, {\n vectorElement,\n references,\n name: file,\n itemName: itemNames.get(file)\n })\n const alone = new Map<string, ComponentModel>()\n for (const { group, file, generate } of entries) {\n const component = generate && group.set && model(group.set, file)\n if (group.set && component) alone.set(group.set.id, component)\n }\n const models = new Map<string, ComponentModel>()\n for (const { group, file } of entries) {\n const component = group.set && alone.has(group.set.id) && model(group.set, file, alone)\n if (group.set && component) models.set(group.set.id, component)\n }\n return models\n}\n\n/** The folder a document's shared files go in, unless the caller names one. */\nfunction documentFolder(graph: SceneGraph, options: ExportStorybookOptions): string {\n if (options.folder) return options.folder\n const page = options.pageId ? graph.getNode(options.pageId)?.name : undefined\n const named = compact([options.document ?? 'document', page]).map((name) => storyId(name))\n return `pairdraw/${named.join('-')}`\n}\n\n/**\n * The font files the entries' text uses, and the stylesheet that loads them. Faces load\n * before text draws, so a story never shows a fallback font first.\n */\nasync function storyFonts(\n graph: SceneGraph,\n entries: readonly StoryEntry[],\n options: ExportStorybookOptions,\n folder: string\n): Promise<ExportHTMLFile[]> {\n if (!options.fonts) return []\n const requests = new Map<string, WebFontFaceRequest>()\n for (const { group } of entries)\n for (const variant of group.variants)\n for (const request of designFontRequests(\n sceneNodeToDesignDocument(graph, variant.node.id, { includeSourceIds: false })\n ))\n requests.set(`${request.family}|${request.weight}|${request.style ?? 'normal'}`, request)\n if (requests.size === 0) return []\n const assets = await options.fonts([...requests.values()], `${folder}/fonts`)\n if (assets.length === 0) return []\n const css = fontFaceStylesheet(assets, { from: folder, display: 'block' })\n return [...assets, { path: `${folder}/fonts.css`, content: css }]\n}\n\n/**\n * The document's design tokens as custom properties, which stories' styles refer to as\n * `var(--…)` wherever the design binds a variable, so they resolve as the design draws them.\n */\nasync function storyTokens(graph: SceneGraph, folder: string): Promise<ExportHTMLFile[]> {\n if (graph.variables.size === 0) return []\n const { css } = await tokenStylesheet(graph, { format: 'css' })\n return css ? [{ path: `${folder}/tokens.css`, content: css }] : []\n}\n\n/** What writing one generated component's stories needs from the export around it. */\ninterface GeneratedContext {\n options: ExportStorybookOptions\n framework: StorybookFramework\n uniqueNames: Set<string>\n styles: string[]\n add: (page: SceneNode, path: string, content: string | Uint8Array) => void\n entry: StoryEntry\n}\n\n/** A generated component's files: its component, design images, and state stories. */\nasync function addGeneratedStories(\n component: ComponentModel,\n generate: ComponentGenerator,\n { options, framework, uniqueNames, styles, add, entry }: GeneratedContext\n): Promise<void> {\n const { page, group, file, mode } = entry\n const generated = await generate(component, { styling: options.styling })\n for (const item of generated.files) add(page, item.path, item.content)\n const design = designLink({ linkPath: options.linkPath, uniqueNames }, group.linkNode)\n // Each state story shows the variant that draws it, as static stories show their own.\n const states = componentStories(\n component,\n generated.valueArg,\n generated.valueList ?? false\n ).slice(0, mode === 'single' ? 1 : undefined)\n const designs = new Map<string, string>()\n const render = options.renderDesignImage\n if (render) {\n for (const state of states) {\n const variant = variantForStory(group, component, state.values)\n if (!variant) continue\n const path = `${file}.design/${state.name}.png`\n add(page, path, await render(variant.node.id))\n designs.set(state.name, `./${path}`)\n }\n }\n add(\n page,\n `${file}.stories.ts`,\n printComponentStories({\n storybook: STORYBOOK_PACKAGES[framework],\n title: group.title,\n tags: fileTags(group.page.name),\n styles,\n component,\n generated,\n // A gallery lays out static variants; a generated component's stories are its states.\n single: mode === 'single',\n design: design.flatMap((link) =>\n link.type === 'link' ? [{ name: 'Pairdraw', type: 'link', url: link.url }] : []\n ),\n designs\n })\n )\n}\n\n/**\n * Generate one CSF3 `.stories.ts` file per component or component set, plus a\n * `<Name>.design/` folder of variant images when `renderDesignImage` is given.\n */\nexport async function exportStorybook(\n graph: SceneGraph,\n options: ExportStorybookOptions = {}\n): Promise<StorybookFile[]> {\n const framework = options.framework ?? 'react'\n const uniqueNames = uniqueLayerNames(graph)\n const files: StorybookFile[] = []\n const add = (page: SceneNode, path: string, content: string | Uint8Array) =>\n files.push({ path, content, page: page.name })\n\n const entries = storyEntries(graph, options)\n const folder = documentFolder(graph, options)\n const shared = [\n ...(await storyFonts(graph, entries, options, folder)),\n ...(await storyTokens(graph, folder))\n ]\n const firstPage = entries.at(0)?.page\n if (firstPage) for (const file of shared) add(firstPage, file.path, file.content)\n // Every story file loads the document's fonts and tokens.\n const styles = shared.filter((file) => file.path.endsWith('.css')).map((file) => `./${file.path}`)\n const generate = GENERATORS[framework]\n const models = generate ? generatedModels(graph, entries, options.vectorElement) : new Map()\n\n for (const entry of entries) {\n const { page, group, file, mode } = entry\n const component = group.set && models.get(group.set.id)\n if (generate && component) {\n const context: GeneratedContext = {\n options,\n framework,\n uniqueNames,\n styles,\n add,\n entry\n }\n await addGeneratedStories(component, generate, context)\n continue\n }\n\n // Only the stories a file keeps get design images; a gallery or Default alone keeps one.\n const names = storyNames(group).slice(0, mode === 'variants' ? undefined : 1)\n const render = options.renderDesignImage\n const images = render ? names.map((name) => `${file}.design/${name}.png`) : []\n if (render) {\n for (const [i, variant] of group.variants.slice(0, names.length).entries())\n add(page, images[i] ?? '', await render(variant.node.id))\n }\n const context = {\n ...options,\n graph,\n framework,\n uniqueNames,\n storyNames: names,\n images,\n mode,\n styles\n }\n add(page, `${file}.stories.ts`, storyModule(group, context))\n }\n return files\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,SAAS,WAAW,MAA0B;CAC5C,OAAO,KAAK,WAAW,CAAC,KAAK;AAC/B;;AAGA,SAAS,iBAAiB,OAA+B;CACvD,MAAM,OAAO,MAAM,SAAS,KAAK,YAAY,KAAK,UAAU,QAAQ,MAAM,CAAC;CAC3E,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC,SAAS,KAAK,QAAQ,OAAO;CAC/C,MAAM,wBAAQ,IAAI,IAAY;CAC9B,OAAO;EACL,GAAG;EACH,UAAU,MAAM,SAAS,KAAK,aAAa;GACzC,GAAG;GACH,QAAQ,CAAC,UAAU,QAAQ,KAAK,MAAM,OAAO,EAAE,WAAW,IAAI,CAAC,CAAC;EAClE,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D;CACA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.js","names":["parse","parse"],"sources":["../../../src/import/style-attribute.ts","../../../src/runtime/headless/styles.ts","../../../src/runtime/headless/runtime.ts","../../../src/runtime/index.ts","../../../src/import/tailwind.ts","../../../src/import/html.ts"],"sourcesContent":["import { parse } from '@acemir/cssom'\nimport type { CSSStyleRuleLike } from '@acemir/cssom'\n\nimport type { DesignStyleDeclaration } from '../types'\n\nfunction firstStyleRule(cssText: string): CSSStyleRuleLike | null {\n const [rule] = parse(cssText).cssRules\n if (!rule || typeof rule !== 'object' || !('style' in rule)) return null\n return rule as CSSStyleRuleLike\n}\n\nexport function parseStyleAttribute(value: string | undefined): DesignStyleDeclaration | undefined {\n if (!value) return undefined\n\n const rule = firstStyleRule(`*{${value}}`)\n if (!rule) return undefined\n\n const style: DesignStyleDeclaration = {}\n for (const property of Array.from(rule.style)) {\n const propertyValue = rule.style.getPropertyValue(property)\n if (propertyValue) style[property] = propertyValue\n }\n\n return Object.keys(style).length > 0 ? style : undefined\n}\n","import type {\n DesignDocument,\n DesignElement,\n DesignNode,\n DesignStyleDeclaration\n} from '#dom-css/types'\nimport {\n parse,\n type CSSGroupingRuleLike,\n type CSSStyleDeclarationLike,\n type CSSStyleRuleLike\n} from '@acemir/cssom'\n\nimport { tryParseColor } from '@pairdraw/scene-graph/color'\nimport { parseCSSNumber, splitCSSValue } from '@pairdraw/scene-graph/css'\n\ninterface HeadlessCSSRule {\n selector: string\n specificity: number\n order: number\n /** Declared values with `var()` unresolved, so each element resolves them in its own scope. */\n declarations: DesignStyleDeclaration\n}\n\ninterface ParsedHeadlessCSS {\n rules: HeadlessCSSRule[]\n customProperties: DesignStyleDeclaration\n}\n\ninterface AncestorContext {\n element: DesignElement\n parent: AncestorContext | null\n}\n\nconst INHERITED_PROPERTIES = new Set([\n 'color',\n 'font-family',\n 'font-size',\n 'font-weight',\n 'line-height'\n])\n\n/** Declared values as written, before custom properties and shorthands are resolved. */\nfunction declarationsOf(style: CSSStyleDeclarationLike): DesignStyleDeclaration {\n const result: DesignStyleDeclaration = {}\n for (const property of Array.from({ length: style.length }, (_, index) => style[index])) {\n const value = style.getPropertyValue(property).trim()\n if (property && value) result[property] = value\n }\n return result\n}\n\nfunction resolveDeclarations(\n declarations: DesignStyleDeclaration,\n customProperties: DesignStyleDeclaration\n): DesignStyleDeclaration {\n const resolved: DesignStyleDeclaration = {}\n for (const [property, value] of Object.entries(declarations)) {\n const resolvedValue = resolveCSSValue(value, customProperties)\n if (resolvedValue) resolved[property] = resolvedValue\n }\n return expandStyleShorthands(resolved)\n}\n\n/** Adds the custom properties a declaration block sets, resolved against those already in scope. */\nfunction declareCustomProperties(\n scope: DesignStyleDeclaration,\n declarations: DesignStyleDeclaration\n): void {\n for (const [name, value] of Object.entries(declarations)) {\n if (!name.startsWith('--')) continue\n const resolved = resolveCSSValue(value, scope)\n if (resolved) scope[name] = resolved\n }\n}\n\nfunction isStyleRule(rule: unknown): rule is CSSStyleRuleLike {\n return (\n typeof rule === 'object' &&\n rule !== null &&\n 'selectorText' in rule &&\n 'style' in rule &&\n typeof rule.selectorText === 'string'\n )\n}\n\nfunction isGroupingRule(rule: unknown): rule is CSSGroupingRuleLike {\n return (\n typeof rule === 'object' && rule !== null && 'cssRules' in rule && Array.isArray(rule.cssRules)\n )\n}\n\nfunction collectStyleRules(rules: unknown[]): CSSStyleRuleLike[] {\n return rules.flatMap((rule) => {\n if (isStyleRule(rule)) return [rule]\n if (isGroupingRule(rule)) return collectStyleRules(rule.cssRules)\n return []\n })\n}\n\nfunction parseRules(cssText: string): ParsedHeadlessCSS {\n let order = 0\n const sheet = parse(cssText)\n const styleRules = collectStyleRules(sheet.cssRules)\n const customProperties = collectCustomProperties(styleRules)\n const rules = styleRules.flatMap((rule) => {\n const declarations = declarationsOf(rule.style)\n return rule.selectorText\n .split(',')\n .map((selector) => selector.trim())\n .filter((selector) => selector.length > 0)\n .map((selector) => ({\n selector,\n specificity: selectorSpecificity(selector),\n order: order++,\n declarations\n }))\n })\n return { rules, customProperties }\n}\n\nfunction collectCustomProperties(rules: CSSStyleRuleLike[]): DesignStyleDeclaration {\n const customProperties: DesignStyleDeclaration = {}\n for (const rule of rules) {\n if (!rule.selectorText.split(',').some((selector) => selector.trim() === ':root')) continue\n declareCustomProperties(customProperties, declarationsOf(rule.style))\n }\n return customProperties\n}\n\nfunction resolveCSSValue(value: string, customProperties: DesignStyleDeclaration): string {\n return resolveSimpleCalc(resolveVariables(value, customProperties))\n}\n\nconst CUSTOM_PROPERTY_NAME = /^--[\\w-]+$/\n\n/** `var()` references as their values; a fallback can hold parentheses and other `var()`s. */\nfunction resolveVariables(value: string, customProperties: DesignStyleDeclaration): string {\n let result = ''\n let index = 0\n for (;;) {\n const start = value.indexOf('var(', index)\n const end = start === -1 ? -1 : closingParenthesis(value, start + 3)\n if (end === -1) return result + value.slice(index)\n const inner = value.slice(start + 4, end)\n const comma = inner.indexOf(',')\n const name = (comma === -1 ? inner : inner.slice(0, comma)).trim()\n const declared: string | undefined = Object.hasOwn(customProperties, name)\n ? customProperties[name]\n : undefined\n const fallback = comma === -1 ? '' : inner.slice(comma + 1).trim()\n result += value.slice(index, start)\n result += CUSTOM_PROPERTY_NAME.test(name)\n ? (declared ?? resolveVariables(fallback, customProperties))\n : value.slice(start, end + 1)\n index = end + 1\n }\n}\n\n/** The index of the `)` closing the `(` at `open`, or -1 when it is never closed. */\nfunction closingParenthesis(value: string, open: number): number {\n let depth = 0\n for (let index = open; index < value.length; index++) {\n if (value[index] === '(') depth++\n else if (value[index] === ')' && --depth === 0) return index\n }\n return -1\n}\n\n/** `calc()` of a product, with the length on either side, as pixels. */\nfunction resolveSimpleCalc(value: string): string {\n const calc = /^calc\\(\\s*([-\\d.]+)(rem|px)?\\s*\\*\\s*([-\\d.]+)(rem|px)?\\s*\\)$/.exec(value)\n if (!calc?.[1] || !calc[3] || (calc[2] && calc[4])) return value\n\n const left = Number.parseFloat(calc[1])\n const right = Number.parseFloat(calc[3])\n // An unmatched group is undefined at run time, though the match array types it as a string.\n const unit = calc[2] || calc[4] || 'px'\n if (!Number.isFinite(left) || !Number.isFinite(right)) return value\n return `${unit === 'rem' ? left * right * 16 : left * right}px`\n}\n\nconst BORDER_STYLES = new Set([\n 'none',\n 'hidden',\n 'dotted',\n 'dashed',\n 'solid',\n 'double',\n 'groove',\n 'ridge',\n 'inset',\n 'outset'\n])\n\n/**\n * Shorthands as the longhands they set, in declaration order, so a later declaration wins over\n * an earlier one whether it is a shorthand, a logical side, or a single side, as in CSS.\n */\nfunction expandStyleShorthands(style: DesignStyleDeclaration): DesignStyleDeclaration {\n const result: DesignStyleDeclaration = {}\n for (const [property, value] of Object.entries(style)) {\n result[property] = value\n Object.assign(result, longhandsOf(property, value))\n }\n return result\n}\n\nfunction longhandsOf(property: string, value: string): DesignStyleDeclaration {\n if (property === 'margin' || property === 'padding') return boxSides(property, value)\n const logical = /^(margin|padding)-(inline|block)$/u.exec(property)\n if (logical) return logicalSides(property, value, logical[2] === 'inline')\n if (property === 'border') return borderLonghands(value)\n if (property === 'background') {\n const color = splitCSSValue(value).find(isColor)\n return color ? { 'background-color': color } : {}\n }\n return {}\n}\n\nfunction boxSides(property: string, value: string): DesignStyleDeclaration {\n const [top, right = top, bottom = top, left = right] = splitCSSValue(value)\n if (!top || !right || !bottom || !left) return {}\n return {\n [`${property}-top`]: top,\n [`${property}-right`]: right,\n [`${property}-bottom`]: bottom,\n [`${property}-left`]: left\n }\n}\n\n/** `padding-inline` and `padding-block` as the sides they set in left-to-right, horizontal text. */\nfunction logicalSides(property: string, value: string, inline: boolean): DesignStyleDeclaration {\n const box = property.slice(0, property.lastIndexOf('-'))\n const [first, second = first] = splitCSSValue(value)\n if (!first || !second) return {}\n const [start, end] = inline ? ['left', 'right'] : ['top', 'bottom']\n return { [`${box}-${start}`]: first, [`${box}-${end}`]: second }\n}\n\nfunction borderLonghands(value: string): DesignStyleDeclaration {\n const parts = splitCSSValue(value)\n const longhands: DesignStyleDeclaration = {}\n const color = parts.find(isColor)\n const width = parts.find((part) => parseCSSNumber(part) !== null)\n const style = parts.find((part) => BORDER_STYLES.has(part.toLowerCase()))\n if (color) longhands['border-color'] = color\n if (width) longhands['border-width'] = width\n if (style) longhands['border-style'] = style.toLowerCase()\n return longhands\n}\n\n/** Any CSS color, including `transparent`, which a shorthand may set on purpose. */\nfunction isColor(value: string): boolean {\n return tryParseColor(value) !== null\n}\n\nfunction classList(element: DesignElement): Set<string> {\n const className = 'class' in element.attrs ? element.attrs.class : ''\n return new Set(className.split(/\\s+/).filter((name) => name.length > 0))\n}\n\nfunction elementId(element: DesignElement): string | undefined {\n return 'id' in element.attrs ? element.attrs.id : undefined\n}\n\nfunction selectorSpecificity(selector: string): number {\n const idCount = selector.match(/#[\\w-]+/g)?.length ?? 0\n const classCount = selector.match(/\\.[\\w-]+/g)?.length ?? 0\n // A tag counts once per compound; the universal selector, alone or as in `*.card`, counts zero.\n const tagCount = selector.split(/[\\s>]+/).filter((part) => /^[a-z]/iu.test(part)).length\n return idCount * 100 + classCount * 10 + tagCount\n}\n\nfunction matchesSimpleSelector(element: DesignElement, selector: string): boolean {\n if (selector.includes(':') || selector.includes('[')) return false\n\n const idMatch = selector.match(/#([\\w-]+)/)\n if (idMatch?.[1] && elementId(element) !== idMatch[1]) return false\n\n const classes = selector.match(/\\.[\\w-]+/g) ?? []\n const elementClasses = classList(element)\n if (!classes.every((name) => elementClasses.has(name.slice(1)))) return false\n\n const tag = selector.replace(/#[\\w-]+/g, '').replace(/\\.[\\w-]+/g, '')\n // The universal selector, as Tailwind's preflight uses for `box-sizing`, matches any element.\n return tag.length === 0 || tag === '*' || element.tagName.toLowerCase() === tag.toLowerCase()\n}\n\ninterface SelectorStep {\n compound: string\n /** How this compound relates to the one after it: `>` for a parent, ` ` for any ancestor. */\n combinator: '>' | ' '\n}\n\n/** A complex selector as its compounds, rightmost last; `null` when a combinator lacks a side. */\nfunction selectorSteps(selector: string): SelectorStep[] | null {\n const tokens = selector\n .replaceAll('>', ' > ')\n .split(/\\s+/)\n .filter((token) => token.length > 0)\n const steps: SelectorStep[] = []\n let pending: '>' | null = null\n for (const token of tokens) {\n if (token === '>') {\n if (pending || steps.length === 0) return null\n pending = '>'\n continue\n }\n const previous = steps.at(-1)\n if (previous) previous.combinator = pending ?? ' '\n steps.push({ compound: token, combinator: ' ' })\n pending = null\n }\n return pending ? null : steps\n}\n\nfunction matchesSelector(\n element: DesignElement,\n selector: string,\n parent: AncestorContext | null\n): boolean {\n const steps = selectorSteps(selector)\n return steps !== null && matchesSteps(element, steps, steps.length - 1, parent)\n}\n\n/** Whether the element matches the compound at `index` and some ancestors match those before. */\nfunction matchesSteps(\n element: DesignElement,\n steps: SelectorStep[],\n index: number,\n parent: AncestorContext | null\n): boolean {\n const step = steps.at(index)\n if (!step || !matchesSimpleSelector(element, step.compound)) return false\n if (index === 0) return true\n const previous = steps.at(index - 1)\n if (!previous) return false\n if (previous.combinator === '>') {\n return parent !== null && matchesSteps(parent.element, steps, index - 1, parent.parent)\n }\n for (let ancestor = parent; ancestor; ancestor = ancestor.parent) {\n if (matchesSteps(ancestor.element, steps, index - 1, ancestor.parent)) return true\n }\n return false\n}\n\nfunction applyComputedStyles(\n node: DesignNode,\n rules: HeadlessCSSRule[],\n parent: AncestorContext | null,\n inheritedStyle: DesignStyleDeclaration,\n inheritedCustomProperties: DesignStyleDeclaration\n): DesignNode {\n if (node.type === 'text') return node\n\n const computedStyle: DesignStyleDeclaration = pickInheritedStyle(inheritedStyle)\n const matchingRules = rules\n .filter((rule) => matchesSelector(node, rule.selector, parent))\n .sort((left, right) => left.specificity - right.specificity || left.order - right.order)\n\n // Custom properties cascade and inherit like any property, so `var()` resolves per element.\n const customProperties = { ...inheritedCustomProperties }\n for (const rule of matchingRules) declareCustomProperties(customProperties, rule.declarations)\n declareCustomProperties(customProperties, node.inlineStyle ?? {})\n\n for (const rule of matchingRules) {\n Object.assign(computedStyle, resolveDeclarations(rule.declarations, customProperties))\n }\n Object.assign(computedStyle, resolveDeclarations(node.inlineStyle ?? {}, customProperties))\n\n const context = { element: node, parent }\n return {\n ...node,\n computedStyle: Object.keys(computedStyle).length > 0 ? computedStyle : undefined,\n children: node.children.map((child) =>\n applyComputedStyles(child, rules, context, computedStyle, customProperties)\n )\n }\n}\n\nfunction pickInheritedStyle(style: DesignStyleDeclaration): DesignStyleDeclaration {\n const inherited: DesignStyleDeclaration = {}\n for (const property of INHERITED_PROPERTIES) {\n const value = style[property]\n if (value) inherited[property] = value\n }\n return inherited\n}\n\nexport function computeHeadlessStyles(document: DesignDocument, cssText = ''): DesignDocument {\n const stylesheetText = [document.stylesheets?.map((sheet) => sheet.cssText).join('\\n'), cssText]\n .filter((text): text is string => !!text)\n .join('\\n')\n const { rules, customProperties } = parseRules(stylesheetText)\n // A fragment has no document element, so `:root` reaches its elements through inheritance only.\n const rootStyle: DesignStyleDeclaration = {}\n for (const rule of rules.filter(({ selector }) => selector === ':root')) {\n Object.assign(rootStyle, resolveDeclarations(rule.declarations, customProperties))\n }\n\n return {\n ...document,\n children: document.children.map((child) =>\n applyComputedStyles(child, rules, null, rootStyle, customProperties)\n )\n }\n}\n","import { serializeHTML } from '#dom-css/export/html'\nimport { INLINE_TAGS } from '#dom-css/import/flow'\nimport { parseStyleAttribute } from '#dom-css/import/style-attribute'\nimport type { CSSRuntime, DesignDocument, DesignElement, DesignNode } from '#dom-css/types'\nimport { parseFragment, type DefaultTreeAdapterTypes } from 'parse5'\n\nimport { computeHeadlessStyles } from './styles'\n\nfunction attrsToRecord(attrs: DefaultTreeAdapterTypes.Element['attrs']): Record<string, string> {\n const result: Record<string, string> = {}\n for (const attr of attrs) result[attr.name] = attr.value\n return result\n}\n\nfunction isTextNode(\n node: DefaultTreeAdapterTypes.ChildNode\n): node is DefaultTreeAdapterTypes.TextNode {\n return node.nodeName === '#text'\n}\n\nconst NON_RENDERED_TAGS = new Set(['head', 'link', 'meta', 'script', 'style', 'template', 'title'])\n\nfunction isInlineElement(node: DefaultTreeAdapterTypes.ChildNode | undefined): boolean {\n return node !== undefined && 'tagName' in node && INLINE_TAGS.has(node.tagName.toLowerCase())\n}\n\n/**\n * Text, and the spaces in or beside inline elements, which CSS draws among their words; spaces\n * between blocks lay nothing out, so they are left out.\n */\nfunction keepsText(\n node: DefaultTreeAdapterTypes.TextNode,\n siblings: readonly DefaultTreeAdapterTypes.ChildNode[],\n index: number,\n inInline: boolean\n): boolean {\n if (node.value.trim().length > 0) return true\n return (\n node.value.length > 0 &&\n (inInline || isInlineElement(siblings[index - 1]) || isInlineElement(siblings[index + 1]))\n )\n}\n\nfunction childrenToDesignNodes(\n nodes: readonly DefaultTreeAdapterTypes.ChildNode[],\n inInline: boolean\n): DesignNode[] {\n return nodes\n .map((node, index) => childToDesignNode(node, index, nodes, inInline))\n .filter((child): child is DesignNode => child !== null)\n}\n\nfunction childToDesignNode(\n node: DefaultTreeAdapterTypes.ChildNode,\n index: number,\n siblings: readonly DefaultTreeAdapterTypes.ChildNode[],\n inInline: boolean\n): DesignNode | null {\n if (isTextNode(node)) {\n return keepsText(node, siblings, index, inInline) ? { type: 'text', text: node.value } : null\n }\n\n if (!('tagName' in node)) return null\n if (NON_RENDERED_TAGS.has(node.tagName.toLowerCase())) return null\n\n const attrs = attrsToRecord(node.attrs)\n const element: DesignElement = {\n type: 'element',\n tagName: node.tagName.toLowerCase(),\n attrs,\n children: childrenToDesignNodes(node.childNodes, isInlineElement(node))\n }\n\n const inlineStyle = parseStyleAttribute(attrs.style)\n if (inlineStyle) element.inlineStyle = inlineStyle\n\n return element\n}\n\nfunction parseHTML(html: string): DesignDocument {\n const fragment = parseFragment(html)\n return {\n type: 'document',\n children: childrenToDesignNodes(fragment.childNodes, false)\n }\n}\n\nexport function createHeadlessCSSRuntime(): CSSRuntime {\n return {\n kind: 'headless',\n parseHTML,\n serializeHTML(document: DesignDocument) {\n return serializeHTML(document)\n },\n async computeStyles(document: DesignDocument, cssText = '') {\n return computeHeadlessStyles(document, cssText)\n }\n }\n}\n","import type { CSSRuntime } from '../types'\nimport { createBrowserCSSRuntime } from './browser/runtime'\nimport { createHeadlessCSSRuntime } from './headless/runtime'\n\nexport { createBrowserCSSRuntime } from './browser/runtime'\nexport type { BrowserCSSRuntimeOptions } from './browser/runtime'\nexport { createHeadlessCSSRuntime } from './headless/runtime'\n\nexport function createCSSRuntime(): CSSRuntime {\n return typeof document !== 'undefined' ? createBrowserCSSRuntime() : createHeadlessCSSRuntime()\n}\n","import { compile } from 'tailwindcss'\n\nexport interface CompileTailwindCSSOptions {\n css?: string\n base?: string\n loadStylesheet?: (id: string, base: string) => Promise<string>\n}\n\nconst DEFAULT_TAILWIND_CSS = '@import \"tailwindcss\";'\n\nexport async function compileTailwindCSS(\n classes: string | Iterable<string>,\n options: CompileTailwindCSSOptions = {}\n): Promise<string> {\n const compiler = await compile(tailwindCompilerCSS(options.css), {\n base: options.base,\n loadStylesheet: async (id, base) => {\n const content = options.loadStylesheet\n ? await options.loadStylesheet(id, base)\n : await loadTailwindStylesheet(id)\n return { path: id, base, content }\n }\n })\n return compiler.build(normalizeClasses(classes))\n}\n\nfunction tailwindCompilerCSS(css: string | undefined): string {\n const trimmed = css?.trim()\n if (!trimmed) return DEFAULT_TAILWIND_CSS\n if (containsTailwindImport(trimmed)) return trimmed\n return `${DEFAULT_TAILWIND_CSS}\\n${trimmed}`\n}\n\nfunction containsTailwindImport(css: string): boolean {\n const withoutComments = css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n return /^\\s*@import\\s+(?:\"tailwindcss(?:\\/[^\"]*)?\"|'tailwindcss(?:\\/[^']*)?')/m.test(\n withoutComments\n )\n}\n\nfunction normalizeClasses(classes: string | Iterable<string>): string[] {\n const classNames = typeof classes === 'string' ? [classes] : Array.from(classes)\n return classNames\n .flatMap((className) => className.split(/\\s+/))\n .map((className) => className.trim())\n .filter((className) => className.length > 0)\n}\n\nasync function loadTailwindStylesheet(id: string): Promise<string> {\n const stylesheet = id === 'tailwindcss' ? 'tailwindcss/index.css' : id\n const url = new URL(import.meta.resolve(stylesheet))\n const { readFile } = await import(/* @vite-ignore */ 'node:fs/promises')\n return readFile(url, 'utf8')\n}\n","import { parse, type DefaultTreeAdapterTypes } from 'parse5'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { createCSSRuntime } from '../runtime'\nimport type { CSSComputeOptions, CSSRuntime, DesignDocument } from '../types'\nimport { mergeCSSText } from './css-text'\nimport { designDocumentToSceneGraph, type ToSceneGraphOptions } from './scene-graph'\nimport { compileTailwindCSS, type CompileTailwindCSSOptions } from './tailwind'\n\nexport interface HTMLToDesignDocumentOptions {\n cssText?: string\n runtime?: CSSRuntime\n compute?: CSSComputeOptions\n}\n\nexport interface HTMLToSceneGraphOptions extends HTMLToDesignDocumentOptions, ToSceneGraphOptions {}\n\nexport interface TailwindHTMLToDesignDocumentOptions\n extends Omit<HTMLToDesignDocumentOptions, 'cssText'>, CompileTailwindCSSOptions {}\n\nexport interface TailwindHTMLToSceneGraphOptions\n extends TailwindHTMLToDesignDocumentOptions, ToSceneGraphOptions {}\n\nfunction runtimeForOptions(runtime: CSSRuntime | undefined) {\n return runtime ?? createCSSRuntime()\n}\n\nfunction getChildNodes(node: DefaultTreeAdapterTypes.Node): DefaultTreeAdapterTypes.ChildNode[] {\n return 'childNodes' in node ? node.childNodes : []\n}\n\nfunction textContent(node: DefaultTreeAdapterTypes.Node): string {\n if (node.nodeName === '#text' && 'value' in node) return node.value\n return getChildNodes(node).map(textContent).join('')\n}\n\nfunction collectStyleText(node: DefaultTreeAdapterTypes.Node, styles: string[]): void {\n if ('tagName' in node && node.tagName.toLowerCase() === 'style') {\n const css = textContent(node).trim()\n if (css) styles.push(css)\n return\n }\n\n for (const child of getChildNodes(node)) collectStyleText(child, styles)\n}\n\nfunction extractEmbeddedCSSText(html: string): string | undefined {\n const styles: string[] = []\n collectStyleText(parse(html), styles)\n return styles.length > 0 ? styles.join('\\n') : undefined\n}\n\nexport async function htmlToDesignDocument(\n html: string,\n options: HTMLToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const runtime = runtimeForOptions(options.runtime)\n const document = runtime.parseHTML(html)\n const cssText = mergeCSSText(extractEmbeddedCSSText(html), options.cssText)\n return runtime.computeStyles(document, cssText, options.compute)\n}\n\nexport async function htmlToSceneGraph(\n html: string,\n options: HTMLToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await htmlToDesignDocument(html, options)\n return designDocumentToSceneGraph(document, options)\n}\n\nexport async function tailwindHTMLToDesignDocument(\n html: string,\n candidates: string | Iterable<string>,\n options: TailwindHTMLToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const cssText = await compileTailwindCSS(candidates, options)\n return htmlToDesignDocument(html, { ...options, cssText })\n}\n\nexport async function tailwindHTMLToSceneGraph(\n html: string,\n candidates: string | Iterable<string>,\n options: TailwindHTMLToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await tailwindHTMLToDesignDocument(html, candidates, options)\n return designDocumentToSceneGraph(document, options)\n}\n"],"mappings":";;;;;;;;;AAKA,SAAS,eAAe,SAA0C;CAChE,MAAM,CAAC,QAAQA,QAAM,OAAO,CAAC,CAAC;CAC9B,IAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,EAAE,WAAW,OAAO,OAAO;CACpE,OAAO;AACT;AAEA,SAAgB,oBAAoB,OAA+D;CACjG,IAAI,CAAC,OAAO,OAAO,KAAA;CAEnB,MAAM,OAAO,eAAe,KAAK,MAAM,EAAE;CACzC,IAAI,CAAC,MAAM,OAAO,KAAA;CAElB,MAAM,QAAgC,CAAC;CACvC,KAAK,MAAM,YAAY,MAAM,KAAK,KAAK,KAAK,GAAG;EAC7C,MAAM,gBAAgB,KAAK,MAAM,iBAAiB,QAAQ;EAC1D,IAAI,eAAe,MAAM,YAAY;CACvC;CAEA,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,IAAI,QAAQ,KAAA;AACjD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AK,IAAI,IAAI,KAAA;AACjD;AAEA,eAAsB,qBACpB,MACA,UAAuC,CAAC,GACf;CACzB,MAAM,UAAU,kBAAkB,QAAQ,OAAO;CACjD,MAAM,WAAW,QAAQ,UAAU,IAAI;CACvC,MAAM,UAAU,aAAa,uBAAuB,IAAI,GAAG,QAAQ,OAAO;CAC1E,OAAO,QAAQ,cAAc,UAAU,SAAS,QAAQ,OAAO;AACjE;AAEA,eAAsB,iBACpB,MACA,UAAmC,CAAC,GACf;CACrB,MAAM,WAAW,MAAM,qBAAqB,MAAM,OAAO;CACzD,OAAO,2BAA2B,UAAU,OAAO;AACrD;AAEA,eAAsB,6BACpB,MACA,YACA,UAA+C,CAAC,GACvB;CACzB,MAAM,UAAU,MAAM,mBAAmB,YAAY,OAAO;CAC5D,OAAO,qBAAqB,MAAM;EAAE,GAAG;EAAS;CAAQ,CAAC;AAC3D;AAEA,eAAsB,yBACpB,MACA,YACA,UAA2C,CAAC,GACvB;CACrB,MAAM,WAAW,MAAM,6BAA6B,MAAM,YAAY,OAAO;CAC7E,OAAO,2BAA2B,UAAU,OAAO;AACrD"}
|
|
1
|
+
{"version":3,"file":"html.js","names":["parse","parse"],"sources":["../../../src/import/style-attribute.ts","../../../src/runtime/headless/styles.ts","../../../src/runtime/headless/runtime.ts","../../../src/runtime/index.ts","../../../src/import/tailwind.ts","../../../src/import/html.ts"],"sourcesContent":["import { parse } from '@acemir/cssom'\n\nimport type { CSSStyleRuleLike } from '../cssom/types'\nimport type { DesignStyleDeclaration } from '../types'\n\nfunction firstStyleRule(cssText: string): CSSStyleRuleLike | null {\n const [rule] = parse(cssText).cssRules\n if (!rule || typeof rule !== 'object' || !('style' in rule)) return null\n return rule as CSSStyleRuleLike\n}\n\nexport function parseStyleAttribute(value: string | undefined): DesignStyleDeclaration | undefined {\n if (!value) return undefined\n\n const rule = firstStyleRule(`*{${value}}`)\n if (!rule) return undefined\n\n const style: DesignStyleDeclaration = {}\n for (const property of Array.from(rule.style)) {\n const propertyValue = rule.style.getPropertyValue(property)\n if (propertyValue) style[property] = propertyValue\n }\n\n return Object.keys(style).length > 0 ? style : undefined\n}\n","import type {\n CSSGroupingRuleLike,\n CSSStyleDeclarationLike,\n CSSStyleRuleLike\n} from '#dom-css/cssom/types'\nimport type {\n DesignDocument,\n DesignElement,\n DesignNode,\n DesignStyleDeclaration\n} from '#dom-css/types'\nimport { parse } from '@acemir/cssom'\n\nimport { tryParseColor } from '@pairdraw/scene-graph/color'\nimport { parseCSSNumber, splitCSSValue } from '@pairdraw/scene-graph/css'\n\ninterface HeadlessCSSRule {\n selector: string\n specificity: number\n order: number\n /** Declared values with `var()` unresolved, so each element resolves them in its own scope. */\n declarations: DesignStyleDeclaration\n}\n\ninterface ParsedHeadlessCSS {\n rules: HeadlessCSSRule[]\n customProperties: DesignStyleDeclaration\n}\n\ninterface AncestorContext {\n element: DesignElement\n parent: AncestorContext | null\n}\n\nconst INHERITED_PROPERTIES = new Set([\n 'color',\n 'font-family',\n 'font-size',\n 'font-weight',\n 'line-height'\n])\n\n/** Declared values as written, before custom properties and shorthands are resolved. */\nfunction declarationsOf(style: CSSStyleDeclarationLike): DesignStyleDeclaration {\n const result: DesignStyleDeclaration = {}\n for (const property of Array.from({ length: style.length }, (_, index) => style[index])) {\n const value = style.getPropertyValue(property).trim()\n if (property && value) result[property] = value\n }\n return result\n}\n\nfunction resolveDeclarations(\n declarations: DesignStyleDeclaration,\n customProperties: DesignStyleDeclaration\n): DesignStyleDeclaration {\n const resolved: DesignStyleDeclaration = {}\n for (const [property, value] of Object.entries(declarations)) {\n const resolvedValue = resolveCSSValue(value, customProperties)\n if (resolvedValue) resolved[property] = resolvedValue\n }\n return expandStyleShorthands(resolved)\n}\n\n/** Adds the custom properties a declaration block sets, resolved against those already in scope. */\nfunction declareCustomProperties(\n scope: DesignStyleDeclaration,\n declarations: DesignStyleDeclaration\n): void {\n for (const [name, value] of Object.entries(declarations)) {\n if (!name.startsWith('--')) continue\n const resolved = resolveCSSValue(value, scope)\n if (resolved) scope[name] = resolved\n }\n}\n\nfunction isStyleRule(rule: unknown): rule is CSSStyleRuleLike {\n return (\n typeof rule === 'object' &&\n rule !== null &&\n 'selectorText' in rule &&\n 'style' in rule &&\n typeof rule.selectorText === 'string'\n )\n}\n\nfunction isGroupingRule(rule: unknown): rule is CSSGroupingRuleLike {\n return (\n typeof rule === 'object' && rule !== null && 'cssRules' in rule && Array.isArray(rule.cssRules)\n )\n}\n\nfunction collectStyleRules(rules: unknown[]): CSSStyleRuleLike[] {\n return rules.flatMap((rule) => {\n if (isStyleRule(rule)) return [rule]\n if (isGroupingRule(rule)) return collectStyleRules(rule.cssRules)\n return []\n })\n}\n\nfunction parseRules(cssText: string): ParsedHeadlessCSS {\n let order = 0\n const sheet = parse(cssText)\n const styleRules = collectStyleRules(sheet.cssRules)\n const customProperties = collectCustomProperties(styleRules)\n const rules = styleRules.flatMap((rule) => {\n const declarations = declarationsOf(rule.style)\n return rule.selectorText\n .split(',')\n .map((selector) => selector.trim())\n .filter((selector) => selector.length > 0)\n .map((selector) => ({\n selector,\n specificity: selectorSpecificity(selector),\n order: order++,\n declarations\n }))\n })\n return { rules, customProperties }\n}\n\nfunction collectCustomProperties(rules: CSSStyleRuleLike[]): DesignStyleDeclaration {\n const customProperties: DesignStyleDeclaration = {}\n for (const rule of rules) {\n if (!rule.selectorText.split(',').some((selector) => selector.trim() === ':root')) continue\n declareCustomProperties(customProperties, declarationsOf(rule.style))\n }\n return customProperties\n}\n\nfunction resolveCSSValue(value: string, customProperties: DesignStyleDeclaration): string {\n return resolveSimpleCalc(resolveVariables(value, customProperties))\n}\n\nconst CUSTOM_PROPERTY_NAME = /^--[\\w-]+$/\n\n/** `var()` references as their values; a fallback can hold parentheses and other `var()`s. */\nfunction resolveVariables(value: string, customProperties: DesignStyleDeclaration): string {\n let result = ''\n let index = 0\n for (;;) {\n const start = value.indexOf('var(', index)\n const end = start === -1 ? -1 : closingParenthesis(value, start + 3)\n if (end === -1) return result + value.slice(index)\n const inner = value.slice(start + 4, end)\n const comma = inner.indexOf(',')\n const name = (comma === -1 ? inner : inner.slice(0, comma)).trim()\n const declared: string | undefined = Object.hasOwn(customProperties, name)\n ? customProperties[name]\n : undefined\n const fallback = comma === -1 ? '' : inner.slice(comma + 1).trim()\n result += value.slice(index, start)\n result += CUSTOM_PROPERTY_NAME.test(name)\n ? (declared ?? resolveVariables(fallback, customProperties))\n : value.slice(start, end + 1)\n index = end + 1\n }\n}\n\n/** The index of the `)` closing the `(` at `open`, or -1 when it is never closed. */\nfunction closingParenthesis(value: string, open: number): number {\n let depth = 0\n for (let index = open; index < value.length; index++) {\n if (value[index] === '(') depth++\n else if (value[index] === ')' && --depth === 0) return index\n }\n return -1\n}\n\n/** `calc()` of a product, with the length on either side, as pixels. */\nfunction resolveSimpleCalc(value: string): string {\n const calc = /^calc\\(\\s*([-\\d.]+)(rem|px)?\\s*\\*\\s*([-\\d.]+)(rem|px)?\\s*\\)$/.exec(value)\n if (!calc?.[1] || !calc[3] || (calc[2] && calc[4])) return value\n\n const left = Number.parseFloat(calc[1])\n const right = Number.parseFloat(calc[3])\n // An unmatched group is undefined at run time, though the match array types it as a string.\n const unit = calc[2] || calc[4] || 'px'\n if (!Number.isFinite(left) || !Number.isFinite(right)) return value\n return `${unit === 'rem' ? left * right * 16 : left * right}px`\n}\n\nconst BORDER_STYLES = new Set([\n 'none',\n 'hidden',\n 'dotted',\n 'dashed',\n 'solid',\n 'double',\n 'groove',\n 'ridge',\n 'inset',\n 'outset'\n])\n\n/**\n * Shorthands as the longhands they set, in declaration order, so a later declaration wins over\n * an earlier one whether it is a shorthand, a logical side, or a single side, as in CSS.\n */\nfunction expandStyleShorthands(style: DesignStyleDeclaration): DesignStyleDeclaration {\n const result: DesignStyleDeclaration = {}\n for (const [property, value] of Object.entries(style)) {\n result[property] = value\n Object.assign(result, longhandsOf(property, value))\n }\n return result\n}\n\nfunction longhandsOf(property: string, value: string): DesignStyleDeclaration {\n if (property === 'margin' || property === 'padding') return boxSides(property, value)\n const logical = /^(margin|padding)-(inline|block)$/u.exec(property)\n if (logical) return logicalSides(property, value, logical[2] === 'inline')\n if (property === 'border') return borderLonghands(value)\n if (property === 'background') {\n const color = splitCSSValue(value).find(isColor)\n return color ? { 'background-color': color } : {}\n }\n return {}\n}\n\nfunction boxSides(property: string, value: string): DesignStyleDeclaration {\n const [top, right = top, bottom = top, left = right] = splitCSSValue(value)\n if (!top || !right || !bottom || !left) return {}\n return {\n [`${property}-top`]: top,\n [`${property}-right`]: right,\n [`${property}-bottom`]: bottom,\n [`${property}-left`]: left\n }\n}\n\n/** `padding-inline` and `padding-block` as the sides they set in left-to-right, horizontal text. */\nfunction logicalSides(property: string, value: string, inline: boolean): DesignStyleDeclaration {\n const box = property.slice(0, property.lastIndexOf('-'))\n const [first, second = first] = splitCSSValue(value)\n if (!first || !second) return {}\n const [start, end] = inline ? ['left', 'right'] : ['top', 'bottom']\n return { [`${box}-${start}`]: first, [`${box}-${end}`]: second }\n}\n\nfunction borderLonghands(value: string): DesignStyleDeclaration {\n const parts = splitCSSValue(value)\n const longhands: DesignStyleDeclaration = {}\n const color = parts.find(isColor)\n const width = parts.find((part) => parseCSSNumber(part) !== null)\n const style = parts.find((part) => BORDER_STYLES.has(part.toLowerCase()))\n if (color) longhands['border-color'] = color\n if (width) longhands['border-width'] = width\n if (style) longhands['border-style'] = style.toLowerCase()\n return longhands\n}\n\n/** Any CSS color, including `transparent`, which a shorthand may set on purpose. */\nfunction isColor(value: string): boolean {\n return tryParseColor(value) !== null\n}\n\nfunction classList(element: DesignElement): Set<string> {\n const className = 'class' in element.attrs ? element.attrs.class : ''\n return new Set(className.split(/\\s+/).filter((name) => name.length > 0))\n}\n\nfunction elementId(element: DesignElement): string | undefined {\n return 'id' in element.attrs ? element.attrs.id : undefined\n}\n\nfunction selectorSpecificity(selector: string): number {\n const idCount = selector.match(/#[\\w-]+/g)?.length ?? 0\n const classCount = selector.match(/\\.[\\w-]+/g)?.length ?? 0\n // A tag counts once per compound; the universal selector, alone or as in `*.card`, counts zero.\n const tagCount = selector.split(/[\\s>]+/).filter((part) => /^[a-z]/iu.test(part)).length\n return idCount * 100 + classCount * 10 + tagCount\n}\n\nfunction matchesSimpleSelector(element: DesignElement, selector: string): boolean {\n if (selector.includes(':') || selector.includes('[')) return false\n\n const idMatch = selector.match(/#([\\w-]+)/)\n if (idMatch?.[1] && elementId(element) !== idMatch[1]) return false\n\n const classes = selector.match(/\\.[\\w-]+/g) ?? []\n const elementClasses = classList(element)\n if (!classes.every((name) => elementClasses.has(name.slice(1)))) return false\n\n const tag = selector.replace(/#[\\w-]+/g, '').replace(/\\.[\\w-]+/g, '')\n // The universal selector, as Tailwind's preflight uses for `box-sizing`, matches any element.\n return tag.length === 0 || tag === '*' || element.tagName.toLowerCase() === tag.toLowerCase()\n}\n\ninterface SelectorStep {\n compound: string\n /** How this compound relates to the one after it: `>` for a parent, ` ` for any ancestor. */\n combinator: '>' | ' '\n}\n\n/** A complex selector as its compounds, rightmost last; `null` when a combinator lacks a side. */\nfunction selectorSteps(selector: string): SelectorStep[] | null {\n const tokens = selector\n .replaceAll('>', ' > ')\n .split(/\\s+/)\n .filter((token) => token.length > 0)\n const steps: SelectorStep[] = []\n let pending: '>' | null = null\n for (const token of tokens) {\n if (token === '>') {\n if (pending || steps.length === 0) return null\n pending = '>'\n continue\n }\n const previous = steps.at(-1)\n if (previous) previous.combinator = pending ?? ' '\n steps.push({ compound: token, combinator: ' ' })\n pending = null\n }\n return pending ? null : steps\n}\n\nfunction matchesSelector(\n element: DesignElement,\n selector: string,\n parent: AncestorContext | null\n): boolean {\n const steps = selectorSteps(selector)\n return steps !== null && matchesSteps(element, steps, steps.length - 1, parent)\n}\n\n/** Whether the element matches the compound at `index` and some ancestors match those before. */\nfunction matchesSteps(\n element: DesignElement,\n steps: SelectorStep[],\n index: number,\n parent: AncestorContext | null\n): boolean {\n const step = steps.at(index)\n if (!step || !matchesSimpleSelector(element, step.compound)) return false\n if (index === 0) return true\n const previous = steps.at(index - 1)\n if (!previous) return false\n if (previous.combinator === '>') {\n return parent !== null && matchesSteps(parent.element, steps, index - 1, parent.parent)\n }\n for (let ancestor = parent; ancestor; ancestor = ancestor.parent) {\n if (matchesSteps(ancestor.element, steps, index - 1, ancestor.parent)) return true\n }\n return false\n}\n\nfunction applyComputedStyles(\n node: DesignNode,\n rules: HeadlessCSSRule[],\n parent: AncestorContext | null,\n inheritedStyle: DesignStyleDeclaration,\n inheritedCustomProperties: DesignStyleDeclaration\n): DesignNode {\n if (node.type === 'text') return node\n\n const computedStyle: DesignStyleDeclaration = pickInheritedStyle(inheritedStyle)\n const matchingRules = rules\n .filter((rule) => matchesSelector(node, rule.selector, parent))\n .sort((left, right) => left.specificity - right.specificity || left.order - right.order)\n\n // Custom properties cascade and inherit like any property, so `var()` resolves per element.\n const customProperties = { ...inheritedCustomProperties }\n for (const rule of matchingRules) declareCustomProperties(customProperties, rule.declarations)\n declareCustomProperties(customProperties, node.inlineStyle ?? {})\n\n for (const rule of matchingRules) {\n Object.assign(computedStyle, resolveDeclarations(rule.declarations, customProperties))\n }\n Object.assign(computedStyle, resolveDeclarations(node.inlineStyle ?? {}, customProperties))\n\n const context = { element: node, parent }\n return {\n ...node,\n computedStyle: Object.keys(computedStyle).length > 0 ? computedStyle : undefined,\n children: node.children.map((child) =>\n applyComputedStyles(child, rules, context, computedStyle, customProperties)\n )\n }\n}\n\nfunction pickInheritedStyle(style: DesignStyleDeclaration): DesignStyleDeclaration {\n const inherited: DesignStyleDeclaration = {}\n for (const property of INHERITED_PROPERTIES) {\n const value = style[property]\n if (value) inherited[property] = value\n }\n return inherited\n}\n\nexport function computeHeadlessStyles(document: DesignDocument, cssText = ''): DesignDocument {\n const stylesheetText = [document.stylesheets?.map((sheet) => sheet.cssText).join('\\n'), cssText]\n .filter((text): text is string => !!text)\n .join('\\n')\n const { rules, customProperties } = parseRules(stylesheetText)\n // A fragment has no document element, so `:root` reaches its elements through inheritance only.\n const rootStyle: DesignStyleDeclaration = {}\n for (const rule of rules.filter(({ selector }) => selector === ':root')) {\n Object.assign(rootStyle, resolveDeclarations(rule.declarations, customProperties))\n }\n\n return {\n ...document,\n children: document.children.map((child) =>\n applyComputedStyles(child, rules, null, rootStyle, customProperties)\n )\n }\n}\n","import { serializeHTML } from '#dom-css/export/html'\nimport { INLINE_TAGS } from '#dom-css/import/flow'\nimport { parseStyleAttribute } from '#dom-css/import/style-attribute'\nimport type { CSSRuntime, DesignDocument, DesignElement, DesignNode } from '#dom-css/types'\nimport { parseFragment, type DefaultTreeAdapterTypes } from 'parse5'\n\nimport { computeHeadlessStyles } from './styles'\n\nfunction attrsToRecord(attrs: DefaultTreeAdapterTypes.Element['attrs']): Record<string, string> {\n const result: Record<string, string> = {}\n for (const attr of attrs) result[attr.name] = attr.value\n return result\n}\n\nfunction isTextNode(\n node: DefaultTreeAdapterTypes.ChildNode\n): node is DefaultTreeAdapterTypes.TextNode {\n return node.nodeName === '#text'\n}\n\nconst NON_RENDERED_TAGS = new Set(['head', 'link', 'meta', 'script', 'style', 'template', 'title'])\n\nfunction isInlineElement(node: DefaultTreeAdapterTypes.ChildNode | undefined): boolean {\n return node !== undefined && 'tagName' in node && INLINE_TAGS.has(node.tagName.toLowerCase())\n}\n\n/**\n * Text, and the spaces in or beside inline elements, which CSS draws among their words; spaces\n * between blocks lay nothing out, so they are left out.\n */\nfunction keepsText(\n node: DefaultTreeAdapterTypes.TextNode,\n siblings: readonly DefaultTreeAdapterTypes.ChildNode[],\n index: number,\n inInline: boolean\n): boolean {\n if (node.value.trim().length > 0) return true\n return (\n node.value.length > 0 &&\n (inInline || isInlineElement(siblings[index - 1]) || isInlineElement(siblings[index + 1]))\n )\n}\n\nfunction childrenToDesignNodes(\n nodes: readonly DefaultTreeAdapterTypes.ChildNode[],\n inInline: boolean\n): DesignNode[] {\n return nodes\n .map((node, index) => childToDesignNode(node, index, nodes, inInline))\n .filter((child): child is DesignNode => child !== null)\n}\n\nfunction childToDesignNode(\n node: DefaultTreeAdapterTypes.ChildNode,\n index: number,\n siblings: readonly DefaultTreeAdapterTypes.ChildNode[],\n inInline: boolean\n): DesignNode | null {\n if (isTextNode(node)) {\n return keepsText(node, siblings, index, inInline) ? { type: 'text', text: node.value } : null\n }\n\n if (!('tagName' in node)) return null\n if (NON_RENDERED_TAGS.has(node.tagName.toLowerCase())) return null\n\n const attrs = attrsToRecord(node.attrs)\n const element: DesignElement = {\n type: 'element',\n tagName: node.tagName.toLowerCase(),\n attrs,\n children: childrenToDesignNodes(node.childNodes, isInlineElement(node))\n }\n\n const inlineStyle = parseStyleAttribute(attrs.style)\n if (inlineStyle) element.inlineStyle = inlineStyle\n\n return element\n}\n\nfunction parseHTML(html: string): DesignDocument {\n const fragment = parseFragment(html)\n return {\n type: 'document',\n children: childrenToDesignNodes(fragment.childNodes, false)\n }\n}\n\nexport function createHeadlessCSSRuntime(): CSSRuntime {\n return {\n kind: 'headless',\n parseHTML,\n serializeHTML(document: DesignDocument) {\n return serializeHTML(document)\n },\n async computeStyles(document: DesignDocument, cssText = '') {\n return computeHeadlessStyles(document, cssText)\n }\n }\n}\n","import type { CSSRuntime } from '../types'\nimport { createBrowserCSSRuntime } from './browser/runtime'\nimport { createHeadlessCSSRuntime } from './headless/runtime'\n\nexport { createBrowserCSSRuntime } from './browser/runtime'\nexport type { BrowserCSSRuntimeOptions } from './browser/runtime'\nexport { createHeadlessCSSRuntime } from './headless/runtime'\n\nexport function createCSSRuntime(): CSSRuntime {\n return typeof document !== 'undefined' ? createBrowserCSSRuntime() : createHeadlessCSSRuntime()\n}\n","import { compile } from 'tailwindcss'\n\nexport interface CompileTailwindCSSOptions {\n css?: string\n base?: string\n loadStylesheet?: (id: string, base: string) => Promise<string>\n}\n\nconst DEFAULT_TAILWIND_CSS = '@import \"tailwindcss\";'\n\nexport async function compileTailwindCSS(\n classes: string | Iterable<string>,\n options: CompileTailwindCSSOptions = {}\n): Promise<string> {\n const compiler = await compile(tailwindCompilerCSS(options.css), {\n base: options.base,\n loadStylesheet: async (id, base) => {\n const content = options.loadStylesheet\n ? await options.loadStylesheet(id, base)\n : await loadTailwindStylesheet(id)\n return { path: id, base, content }\n }\n })\n return compiler.build(normalizeClasses(classes))\n}\n\nfunction tailwindCompilerCSS(css: string | undefined): string {\n const trimmed = css?.trim()\n if (!trimmed) return DEFAULT_TAILWIND_CSS\n if (containsTailwindImport(trimmed)) return trimmed\n return `${DEFAULT_TAILWIND_CSS}\\n${trimmed}`\n}\n\nfunction containsTailwindImport(css: string): boolean {\n const withoutComments = css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n return /^\\s*@import\\s+(?:\"tailwindcss(?:\\/[^\"]*)?\"|'tailwindcss(?:\\/[^']*)?')/m.test(\n withoutComments\n )\n}\n\nfunction normalizeClasses(classes: string | Iterable<string>): string[] {\n const classNames = typeof classes === 'string' ? [classes] : Array.from(classes)\n return classNames\n .flatMap((className) => className.split(/\\s+/))\n .map((className) => className.trim())\n .filter((className) => className.length > 0)\n}\n\nasync function loadTailwindStylesheet(id: string): Promise<string> {\n const stylesheet = id === 'tailwindcss' ? 'tailwindcss/index.css' : id\n const url = new URL(import.meta.resolve(stylesheet))\n const { readFile } = await import(/* @vite-ignore */ 'node:fs/promises')\n return readFile(url, 'utf8')\n}\n","import { parse, type DefaultTreeAdapterTypes } from 'parse5'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { createCSSRuntime } from '../runtime'\nimport type { CSSComputeOptions, CSSRuntime, DesignDocument } from '../types'\nimport { mergeCSSText } from './css-text'\nimport { designDocumentToSceneGraph, type ToSceneGraphOptions } from './scene-graph'\nimport { compileTailwindCSS, type CompileTailwindCSSOptions } from './tailwind'\n\nexport interface HTMLToDesignDocumentOptions {\n cssText?: string\n runtime?: CSSRuntime\n compute?: CSSComputeOptions\n}\n\nexport interface HTMLToSceneGraphOptions extends HTMLToDesignDocumentOptions, ToSceneGraphOptions {}\n\nexport interface TailwindHTMLToDesignDocumentOptions\n extends Omit<HTMLToDesignDocumentOptions, 'cssText'>, CompileTailwindCSSOptions {}\n\nexport interface TailwindHTMLToSceneGraphOptions\n extends TailwindHTMLToDesignDocumentOptions, ToSceneGraphOptions {}\n\nfunction runtimeForOptions(runtime: CSSRuntime | undefined) {\n return runtime ?? createCSSRuntime()\n}\n\nfunction getChildNodes(node: DefaultTreeAdapterTypes.Node): DefaultTreeAdapterTypes.ChildNode[] {\n return 'childNodes' in node ? node.childNodes : []\n}\n\nfunction textContent(node: DefaultTreeAdapterTypes.Node): string {\n if (node.nodeName === '#text' && 'value' in node) return node.value\n return getChildNodes(node).map(textContent).join('')\n}\n\nfunction collectStyleText(node: DefaultTreeAdapterTypes.Node, styles: string[]): void {\n if ('tagName' in node && node.tagName.toLowerCase() === 'style') {\n const css = textContent(node).trim()\n if (css) styles.push(css)\n return\n }\n\n for (const child of getChildNodes(node)) collectStyleText(child, styles)\n}\n\nfunction extractEmbeddedCSSText(html: string): string | undefined {\n const styles: string[] = []\n collectStyleText(parse(html), styles)\n return styles.length > 0 ? styles.join('\\n') : undefined\n}\n\nexport async function htmlToDesignDocument(\n html: string,\n options: HTMLToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const runtime = runtimeForOptions(options.runtime)\n const document = runtime.parseHTML(html)\n const cssText = mergeCSSText(extractEmbeddedCSSText(html), options.cssText)\n return runtime.computeStyles(document, cssText, options.compute)\n}\n\nexport async function htmlToSceneGraph(\n html: string,\n options: HTMLToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await htmlToDesignDocument(html, options)\n return designDocumentToSceneGraph(document, options)\n}\n\nexport async function tailwindHTMLToDesignDocument(\n html: string,\n candidates: string | Iterable<string>,\n options: TailwindHTMLToDesignDocumentOptions = {}\n): Promise<DesignDocument> {\n const cssText = await compileTailwindCSS(candidates, options)\n return htmlToDesignDocument(html, { ...options, cssText })\n}\n\nexport async function tailwindHTMLToSceneGraph(\n html: string,\n candidates: string | Iterable<string>,\n options: TailwindHTMLToSceneGraphOptions = {}\n): Promise<SceneGraph> {\n const document = await tailwindHTMLToDesignDocument(html, candidates, options)\n return designDocumentToSceneGraph(document, options)\n}\n"],"mappings":";;;;;;;;;AAKA,SAAS,eAAe,SAA0C;CAChE,MAAM,CAAC,QAAQA,QAAM,OAAO,CAAC,CAAC;CAC9B,IAAI,CAAC,QAAQ,OAAO,SAAS,YAAY,EAAE,WAAW,OAAO,OAAO;CACpE,OAAO;AACT;AAEA,SAAgB,oBAAoB,OAA+D;CACjG,IAAI,CAAC,OAAO,OAAO,KAAA;CAEnB,MAAM,OAAO,eAAe,KAAK,MAAM,EAAE;CACzC,IAAI,CAAC,MAAM,OAAO,KAAA;CAElB,MAAM,QAAgC,CAAC;CACvC,KAAK,MAAM,YAAY,MAAM,KAAK,KAAK,KAAK,GAAG;EAC7C,MAAM,gBAAgB,KAAK,MAAM,iBAAiB,QAAQ;EAC1D,IAAI,eAAe,MAAM,YAAY;CACvC;CAEA,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,IAAI,QAAQ,KAAA;AACjD;;;ACUA,MAAM,uCAAuB,IAAI,IAAI;CACnC;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAS,eAAe,OAAwD;CAC9E,MAAM,SAAiC,CAAC;CACxC,KAAK,MAAM,YAAY,MAAM,KAAK,EAAE,QAAQ,MAAM,OAAO,IAAI,GAAG,UAAU,MAAM,MAAM,GAAG;EACvF,MAAM,QAAQ,MAAM,iBAAiB,QAAQ,CAAC,CAAC,KAAK;EACpD,IAAI,YAAY,OAAO,OAAO,YAAY;CAC5C;CACA,OAAO;AACT;AAEA,SAAS,oBACP,cACA,kBACwB;CACxB,MAAM,WAAmC,CAAC;CAC1C,KAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,YAAY,GAAG;EAC5D,MAAM,gBAAgB,gBAAgB,OAAO,gBAAgB;EAC7D,IAAI,eAAe,SAAS,YAAY;CAC1C;CACA,OAAO,sBAAsB,QAAQ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pB,MACA,YACA,UAA2C,CAAC,GACvB;CACrB,MAAM,WAAW,MAAM,6BAA6B,MAAM,YAAY,OAAO;CAC7E,OAAO,2BAA2B,UAAU,OAAO;AACrD"}
|
package/dist/export.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { DesignDocument, DesignElement, DesignNode, DesignStyleDeclaration, DesignText } from "./types.js";
|
|
2
|
-
import { COMPONENT_STYLINGS, ComponentStyling, ExportHTMLBundle, ExportHTMLBundleOptions, ExportHTMLFile, SceneGraphToDesignOptions, TailwindStylesheetId, TailwindStylesheetLoader, VectorElementRenderer, WebFontFaceAsset, WebFontFaceRequest, WebFontFaceResolver, exportHTMLBundle, sceneGraphToDesignDocument, sceneNodeToDesignDocument, serializeHTML } from "./styling.js";
|
|
2
|
+
import { COMPONENT_STYLINGS, ComponentStyling, ExportHTMLBundle, ExportHTMLBundleOptions, ExportHTMLFile, SceneGraphToDesignOptions, TailwindStylesheetId, TailwindStylesheetLoader, VectorElementRenderer, WebFontFaceAsset, WebFontFaceRequest, WebFontFaceResolver, exportHTMLBundle, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToDesignDocument, serializeHTML } from "./styling.js";
|
|
3
3
|
import { ThemeNamespace } from "twirlwind";
|
|
4
4
|
import { Behaviour } from "@pairdraw/scene-graph/behaviours";
|
|
5
5
|
import { es } from "@pairdraw/emit";
|
|
6
|
-
import { CSSStyleSheetLike } from "@acemir/cssom";
|
|
7
6
|
import { ComponentPropertyDefinition, SceneGraph, SceneNode, TokenUnit, Variable, VariableCollection, VariableCollectionMode } from "@pairdraw/scene-graph";
|
|
8
7
|
//#region src/export/tailwind-jsx.d.ts
|
|
9
8
|
/** Engine services the projection takes, such as drawing vector layers as SVG. */
|
|
@@ -289,6 +288,11 @@ declare function readCustomProperties(css: string): CustomPropertySheet;
|
|
|
289
288
|
*/
|
|
290
289
|
declare function modeConditionKey(condition: string): string;
|
|
291
290
|
//#endregion
|
|
291
|
+
//#region src/cssom/types.d.ts
|
|
292
|
+
interface CSSStyleSheetLike {
|
|
293
|
+
cssRules: unknown[];
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
292
296
|
//#region src/tokens/validate.d.ts
|
|
293
297
|
type Parse = (cssText: string) => CSSStyleSheetLike;
|
|
294
298
|
/**
|
|
@@ -418,13 +422,6 @@ declare function modeAttribute(collection: VariableCollection, mode: VariableCol
|
|
|
418
422
|
};
|
|
419
423
|
/** The scope a mode applies in when it names none: `[data-theme="dark"]` for Theme / Dark. */
|
|
420
424
|
declare function defaultModeCondition(collection: VariableCollection, mode: VariableCollectionMode): string;
|
|
421
|
-
/**
|
|
422
|
-
* Variables as a stylesheet of custom properties. The default mode of every collection is the
|
|
423
|
-
* base set, in `:root` or, for Tailwind, in `@theme` when the token has a Tailwind namespace;
|
|
424
|
-
* every other mode overrides the values that differ, under its condition. Aliases stay `var()`
|
|
425
|
-
* references, and number formulas `calc()` over them; both are declared again in each mode that
|
|
426
|
-
* changes what they point to.
|
|
427
|
-
*/
|
|
428
425
|
declare function buildTokenStylesheet(source: TokenSource, { format, include }: TokenStylesheetOptions, validate: TokenValidator): TokenStylesheet;
|
|
429
426
|
/**
|
|
430
427
|
* Browsers check token strings with their own CSS parser. Elsewhere, in the CLI and MCP, the CSS
|
|
@@ -590,5 +587,5 @@ declare function stateTailwindClasses(styles: StateStyles, options?: StateTailwi
|
|
|
590
587
|
/** The state styles as Tailwind utilities on each element of the merged markup. */
|
|
591
588
|
declare function stateStylesToTailwind(styles: StateStyles, options?: StateTailwindOptions): DesignDocument;
|
|
592
589
|
//#endregion
|
|
593
|
-
export { BUTTON_RESET, type BehaviourArgs, type BooleanArg, type BooleanModel, COMPONENT_STYLINGS, type CSSExpressionProblem, type CSSValueToken, type CSSValueTokenKind, type ComponentStyling, type ControlModel, type ControlRole, type CustomPropertyDeclaration, type CustomPropertyScope, type CustomPropertySheet, type DesignDocument, type DesignElement, type DesignNode, type ExportHTMLBundle, type ExportHTMLBundleOptions, type ExportHTMLFile, type FeatureCondition, ICON_PACKAGES, INPUT_RESET, type IconFramework, type IconPackage, LAYER_COMPONENT_FRAMEWORKS, type LayerComponent, type LayerComponentFramework, type LayerMarkup, type SceneGraphToDesignOptions, type StateCondition, type StateElement, type StateNode, type StateRule, type StateStyles, type StateStylesheet, type StateTailwindOptions, type StatesModel, TOKEN_UNIT_PROPERTY, type TailwindJSXWithLayers, type TailwindStylesheetId, type TailwindStylesheetLoader, type TokenStylesheet, type TokenStylesheetFormat, type TokenStylesheetIssue, type TokenStylesheetOptions, type TokenValidator, type VectorElementRenderer, type WebFontFaceAsset, type WebFontFaceRequest, type WebFontFaceResolver, behaviourArgs, behaviourControls, booleanOf, buildTokenStylesheet, collectionVariables, conditionSelector, controlRoles, createTokenValidator, cssExpressionProblem, cssNameCodeSyntax, cssNameVariableName, cssTokenProperty, cssValueTokens, defaultModeAttributeName, defaultModeCondition, deriveCSSName, designDocumentToTailwindJSX, explicitCSSName, exportHTMLBundle, featureConditionCSS, groupOf, iconPackagesFor, isIconPackage, layerComponents, layerMarkup, loadTokenValidator, modeAttribute, modeConditionKey, modeConditionName, parseCSSName, parseFeatureCondition, readCustomProperties, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers, serializeHTML, stateStyles, stateStylesToCSS, stateStylesToTailwind, stateTailwindClasses, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit };
|
|
590
|
+
export { BUTTON_RESET, type BehaviourArgs, type BooleanArg, type BooleanModel, COMPONENT_STYLINGS, type CSSExpressionProblem, type CSSValueToken, type CSSValueTokenKind, type ComponentStyling, type ControlModel, type ControlRole, type CustomPropertyDeclaration, type CustomPropertyScope, type CustomPropertySheet, type DesignDocument, type DesignElement, type DesignNode, type ExportHTMLBundle, type ExportHTMLBundleOptions, type ExportHTMLFile, type FeatureCondition, ICON_PACKAGES, INPUT_RESET, type IconFramework, type IconPackage, LAYER_COMPONENT_FRAMEWORKS, type LayerComponent, type LayerComponentFramework, type LayerMarkup, type SceneGraphToDesignOptions, type StateCondition, type StateElement, type StateNode, type StateRule, type StateStyles, type StateStylesheet, type StateTailwindOptions, type StatesModel, TOKEN_UNIT_PROPERTY, type TailwindJSXWithLayers, type TailwindStylesheetId, type TailwindStylesheetLoader, type TokenStylesheet, type TokenStylesheetFormat, type TokenStylesheetIssue, type TokenStylesheetOptions, type TokenValidator, type VectorElementRenderer, type WebFontFaceAsset, type WebFontFaceRequest, type WebFontFaceResolver, behaviourArgs, behaviourControls, booleanOf, buildTokenStylesheet, collectionVariables, conditionSelector, controlRoles, createTokenValidator, cssExpressionProblem, cssNameCodeSyntax, cssNameVariableName, cssTokenProperty, cssValueTokens, defaultModeAttributeName, defaultModeCondition, deriveCSSName, designDocumentToTailwindJSX, explicitCSSName, exportHTMLBundle, featureConditionCSS, groupOf, iconPackagesFor, isIconPackage, layerComponents, layerMarkup, loadTokenValidator, modeAttribute, modeConditionKey, modeConditionName, parseCSSName, parseFeatureCondition, readCustomProperties, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToDesignDocument, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers, serializeHTML, stateStyles, stateStylesToCSS, stateStylesToTailwind, stateTailwindClasses, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit };
|
|
594
591
|
//# sourceMappingURL=export.d.ts.map
|
package/dist/export.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TOKEN_UNIT_PROPERTY, buildTokenStylesheet, collectionVariables, createTokenValidator, cssNameCodeSyntax, cssNameVariableName, defaultModeAttributeName, defaultModeCondition, deriveCSSName, explicitCSSName, loadTokenValidator, modeAttribute, parseCSSName, sceneGraphToDesignDocument, sceneNodeToDesignDocument, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit } from "./chunks/behaviours/states/layers.js";
|
|
1
|
+
import { TOKEN_UNIT_PROPERTY, buildTokenStylesheet, collectionVariables, createTokenValidator, cssNameCodeSyntax, cssNameVariableName, defaultModeAttributeName, defaultModeCondition, deriveCSSName, explicitCSSName, loadTokenValidator, modeAttribute, parseCSSName, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToDesignDocument, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit } from "./chunks/behaviours/states/layers.js";
|
|
2
2
|
import { serializeHTML, stateStylesToTailwind, stateTailwindClasses } from "./chunks/behaviours/states/tailwind.js";
|
|
3
3
|
import { exportHTMLBundle } from "./chunks/export/bundle.js";
|
|
4
4
|
import { behaviourArgs } from "./chunks/behaviours/args.js";
|
|
@@ -10,4 +10,4 @@ import { ICON_PACKAGES, iconPackagesFor, isIconPackage } from "./chunks/export/c
|
|
|
10
10
|
import { cssExpressionProblem, cssTokenProperty, cssValueTokens, designDocumentToTailwindJSX, featureConditionCSS, modeConditionKey, modeConditionName, parseFeatureCondition, readCustomProperties, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers } from "./chunks/export/index.js";
|
|
11
11
|
import { behaviourControls, booleanOf } from "./chunks/behaviours/controls.js";
|
|
12
12
|
import { controlRoles, groupOf } from "./chunks/behaviours/roles.js";
|
|
13
|
-
export { BUTTON_RESET, COMPONENT_STYLINGS, ICON_PACKAGES, INPUT_RESET, LAYER_COMPONENT_FRAMEWORKS, TOKEN_UNIT_PROPERTY, behaviourArgs, behaviourControls, booleanOf, buildTokenStylesheet, collectionVariables, conditionSelector, controlRoles, createTokenValidator, cssExpressionProblem, cssNameCodeSyntax, cssNameVariableName, cssTokenProperty, cssValueTokens, defaultModeAttributeName, defaultModeCondition, deriveCSSName, designDocumentToTailwindJSX, explicitCSSName, exportHTMLBundle, featureConditionCSS, groupOf, iconPackagesFor, isIconPackage, layerComponents, layerMarkup, loadTokenValidator, modeAttribute, modeConditionKey, modeConditionName, parseCSSName, parseFeatureCondition, readCustomProperties, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers, serializeHTML, stateStyles, stateStylesToCSS, stateStylesToTailwind, stateTailwindClasses, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit };
|
|
13
|
+
export { BUTTON_RESET, COMPONENT_STYLINGS, ICON_PACKAGES, INPUT_RESET, LAYER_COMPONENT_FRAMEWORKS, TOKEN_UNIT_PROPERTY, behaviourArgs, behaviourControls, booleanOf, buildTokenStylesheet, collectionVariables, conditionSelector, controlRoles, createTokenValidator, cssExpressionProblem, cssNameCodeSyntax, cssNameVariableName, cssTokenProperty, cssValueTokens, defaultModeAttributeName, defaultModeCondition, deriveCSSName, designDocumentToTailwindJSX, explicitCSSName, exportHTMLBundle, featureConditionCSS, groupOf, iconPackagesFor, isIconPackage, layerComponents, layerMarkup, loadTokenValidator, modeAttribute, modeConditionKey, modeConditionName, parseCSSName, parseFeatureCondition, readCustomProperties, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToDesignDocument, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers, serializeHTML, stateStyles, stateStylesToCSS, stateStylesToTailwind, stateTailwindClasses, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit };
|
package/dist/styling.d.ts
CHANGED
|
@@ -22,6 +22,11 @@ interface SceneGraphToDesignOptions {
|
|
|
22
22
|
declare function sceneGraphToDesignDocument(graph: SceneGraph, options?: SceneGraphToDesignOptions): DesignDocument;
|
|
23
23
|
/** Project one node, including its own box, instead of the children of a root. */
|
|
24
24
|
declare function sceneNodeToDesignDocument(graph: SceneGraph, nodeId: string, options?: Omit<SceneGraphToDesignOptions, 'rootId'>): DesignDocument;
|
|
25
|
+
/**
|
|
26
|
+
* Project several nodes, including each own box, through one token collector: the document then
|
|
27
|
+
* declares the tokens every root references, not only those of the last one.
|
|
28
|
+
*/
|
|
29
|
+
declare function sceneNodesToDesignDocument(graph: SceneGraph, nodeIds: readonly string[], options?: Omit<SceneGraphToDesignOptions, 'rootId'>): DesignDocument;
|
|
25
30
|
//#endregion
|
|
26
31
|
//#region src/export/bundle.d.ts
|
|
27
32
|
/** A font face the exported text uses. */
|
|
@@ -89,5 +94,5 @@ declare function serializeHTML(document: DesignDocument, options?: SerializeHTML
|
|
|
89
94
|
declare const COMPONENT_STYLINGS: readonly ["css", "tailwind"];
|
|
90
95
|
type ComponentStyling = (typeof COMPONENT_STYLINGS)[number];
|
|
91
96
|
//#endregion
|
|
92
|
-
export { COMPONENT_STYLINGS, ComponentStyling, ExportHTMLBundle, ExportHTMLBundleOptions, ExportHTMLFile, SceneGraphToDesignOptions, SerializeHTMLOptions, TailwindStylesheetId, TailwindStylesheetLoader, VectorElementRenderer, WebFontFaceAsset, WebFontFaceRequest, WebFontFaceResolver, exportHTMLBundle, sceneGraphToDesignDocument, sceneNodeToDesignDocument, serializeHTML, serializeNode };
|
|
97
|
+
export { COMPONENT_STYLINGS, ComponentStyling, ExportHTMLBundle, ExportHTMLBundleOptions, ExportHTMLFile, SceneGraphToDesignOptions, SerializeHTMLOptions, TailwindStylesheetId, TailwindStylesheetLoader, VectorElementRenderer, WebFontFaceAsset, WebFontFaceRequest, WebFontFaceResolver, exportHTMLBundle, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToDesignDocument, serializeHTML, serializeNode };
|
|
93
98
|
//# sourceMappingURL=styling.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pairdraw/dom-css",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0-beta.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@acemir/cssom": "^0.9.31",
|
|
14
|
-
"@pairdraw/emit": "^0.
|
|
14
|
+
"@pairdraw/emit": "^0.19.0-beta.1",
|
|
15
15
|
"css-tree": "^3.2.1",
|
|
16
16
|
"cssesc": "^3.0.0",
|
|
17
17
|
"dedent": "^1.7.2",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"twirlwind": "^0.4.1"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@pairdraw/scene-graph": "^0.
|
|
27
|
+
"@pairdraw/scene-graph": "^0.19.0-beta.1"
|
|
28
28
|
},
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CSS object model shapes this package reads, its own so a consumer never needs the types of
|
|
3
|
+
* the CSS parser it loads at runtime: the browser's, or `@acemir/cssom` where there is none.
|
|
4
|
+
*/
|
|
5
|
+
export interface CSSStyleDeclarationLike {
|
|
6
|
+
readonly length: number
|
|
7
|
+
readonly [index: number]: string
|
|
8
|
+
getPropertyValue(property: string): string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface CSSStyleRuleLike {
|
|
12
|
+
selectorText: string
|
|
13
|
+
style: CSSStyleDeclarationLike
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface CSSGroupingRuleLike {
|
|
17
|
+
cssRules: unknown[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface CSSStyleSheetLike {
|
|
21
|
+
cssRules: unknown[]
|
|
22
|
+
}
|
package/src/export/bundle.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { CSSFontFaceRule } from '@acemir/cssom'
|
|
2
1
|
import { isValid, toUint8Array } from 'js-base64'
|
|
3
2
|
import { parseFragment, serialize, type DefaultTreeAdapterTypes } from 'parse5'
|
|
4
3
|
|
|
@@ -276,22 +275,21 @@ interface FontFaceCSSOptions {
|
|
|
276
275
|
display?: string
|
|
277
276
|
}
|
|
278
277
|
|
|
279
|
-
function fontFaceCSS(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
)
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
rule.style.setProperty('font-style', asset.style)
|
|
289
|
-
rule.style.setProperty('font-display', options.display ?? asset.display ?? 'swap')
|
|
290
|
-
if (asset.stretch) rule.style.setProperty('font-stretch', asset.stretch)
|
|
278
|
+
function fontFaceCSS(asset: WebFontFaceAsset, options: FontFaceCSSOptions): string {
|
|
279
|
+
const declarations: [property: string, value: string][] = [
|
|
280
|
+
['font-family', JSON.stringify(asset.family)],
|
|
281
|
+
['src', fontSourceValue(asset, options.from)],
|
|
282
|
+
['font-weight', serializeFontWeight(asset.weight)],
|
|
283
|
+
['font-style', asset.style],
|
|
284
|
+
['font-display', options.display ?? asset.display ?? 'swap']
|
|
285
|
+
]
|
|
286
|
+
if (asset.stretch) declarations.push(['font-stretch', asset.stretch])
|
|
291
287
|
if (asset.unicodeRange && asset.unicodeRange.length > 0) {
|
|
292
|
-
|
|
288
|
+
declarations.push(['unicode-range', asset.unicodeRange.join(',')])
|
|
293
289
|
}
|
|
294
|
-
|
|
290
|
+
// Written out rather than serialized by a CSS object model, which a browser bundle cannot load.
|
|
291
|
+
const body = declarations.map(([property, value]) => ` ${property}: ${value};`).join('\n')
|
|
292
|
+
return `@font-face {\n${body}\n}\n`
|
|
295
293
|
}
|
|
296
294
|
|
|
297
295
|
/** Every font face a document's text uses, once each. */
|
|
@@ -302,14 +300,12 @@ export function designFontRequests(document: DesignDocument): WebFontFaceRequest
|
|
|
302
300
|
}
|
|
303
301
|
|
|
304
302
|
/** `@font-face` rules for font files, as a stylesheet in the folder `options.from`. */
|
|
305
|
-
export
|
|
303
|
+
export function fontFaceStylesheet(
|
|
306
304
|
assets: readonly WebFontFaceAsset[],
|
|
307
305
|
options: FontFaceCSSOptions
|
|
308
|
-
):
|
|
306
|
+
): string {
|
|
309
307
|
if (assets.length === 0) return ''
|
|
310
|
-
|
|
311
|
-
const cssom = await import('@acemir/cssom')
|
|
312
|
-
return assets.map((asset) => fontFaceCSS(cssom.CSSFontFaceRule, asset, options)).join('')
|
|
308
|
+
return assets.map((asset) => fontFaceCSS(asset, options)).join('')
|
|
313
309
|
}
|
|
314
310
|
|
|
315
311
|
async function fontFaceAssets(
|
|
@@ -320,7 +316,7 @@ async function fontFaceAssets(
|
|
|
320
316
|
const assets = await options.fonts(designFontRequests(document), `${options.assetBasePath}/fonts`)
|
|
321
317
|
// The page's stylesheet sits in the asset folder, beside the fonts' own folder.
|
|
322
318
|
return {
|
|
323
|
-
css:
|
|
319
|
+
css: fontFaceStylesheet(assets, { from: options.assetBasePath }),
|
|
324
320
|
files: assets
|
|
325
321
|
}
|
|
326
322
|
}
|