@pairdraw/dom-css 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,7 +57,7 @@ const GALLERY = es.parseModule(dedent`
57
57
 
58
58
  export const Gallery: Story = { name: 'Gallery', render: () => $render }
59
59
  `);
60
- const IMAGE = es.parseModule(`const $name = new URL($path, import.meta.url).href`);
60
+ const IMAGE$1 = es.parseModule(`const $name = new URL($path, import.meta.url).href`);
61
61
  const STORY$1 = es.parseModule(`export const $name: Story = $story`);
62
62
  const STYLESHEET = es.parseModule(`import '$path'`);
63
63
  /** The Storybook renderer package each framework's stories import their types from. */
@@ -182,7 +182,7 @@ function printStoryModule(data) {
182
182
  $argTypes: argTypes$1(data),
183
183
  $render: rendered(data.framework, "variantHTML(args)")
184
184
  }).body;
185
- const images = data.images.flatMap((path, i) => es.fill(IMAGE, {
185
+ const images = data.images.flatMap((path, i) => es.fill(IMAGE$1, {
186
186
  $name: es.identifier(imageName(i)),
187
187
  $path: es.string(`./${path}`)
188
188
  }).body);
@@ -237,6 +237,7 @@ const MODULE = es.parseModule(dedent`
237
237
  const IMPORT_DEFAULT = es.parseModule(`import $Component from '$path'`);
238
238
  const IMPORT_NAMED = es.parseModule(`import { $Component } from '$path'`);
239
239
  const STORY = es.parseModule(`export const $name: Story = $story`);
240
+ const IMAGE = es.parseModule(`const $name = new URL($path, import.meta.url).href`);
240
241
  /**
241
242
  * What clicking a control does, as Reka marks it: the role to find it by, the element that
242
243
  * changes, and the `data-state` it ends in.
@@ -368,18 +369,19 @@ function argTypes(component, model, list) {
368
369
  ]);
369
370
  }
370
371
  /** A story per state worth seeing: at rest, each boolean on, disabled, and each prop value. */
371
- function stories(component, model, list) {
372
+ function componentStories(component, model, list) {
372
373
  const taken = /* @__PURE__ */ new Set([
373
374
  component.name,
374
375
  "meta",
375
376
  "Story"
376
377
  ]);
377
378
  let first = true;
378
- const story = (label, args, play) => {
379
+ const story = (label, values, args, play) => {
379
380
  const variant = !first;
380
381
  first = false;
381
382
  return {
382
383
  name: claimName(identifierName(label, "Story"), taken),
384
+ values,
383
385
  story: es.object([
384
386
  ...variant ? [["tags", es.array([es.string(VARIANT_TAG)])]] : [],
385
387
  ...args.length > 0 ? [["args", es.object(args)]] : [],
@@ -390,13 +392,13 @@ function stories(component, model, list) {
390
392
  const { range } = component;
391
393
  const boolean = !component.choice && !range && !component.text;
392
394
  return [
393
- story("Default", [], playOf(component)),
394
- ...component.model && model && boolean ? [story(component.model, [[model, TRUE]])] : [],
395
- ...range && model ? [["Minimum", range.min], ["Maximum", range.max]].filter(([, value]) => value !== range.default).map(([label, value]) => story(label, [[model, numberArg(value, list)]])) : [],
396
- ...component.choice && model ? component.choice.options.filter((option) => option !== component.choice?.default).map((option) => story(option, [[model, es.string(option)]])) : [],
397
- ...component.disabled ? [story("Disabled", [["disabled", TRUE]])] : [],
398
- ...component.props.flatMap((prop) => prop.options.filter((option) => option !== prop.default).map((option) => story(option, [[prop.name, es.string(option)]]))),
399
- ...component.booleans.map((prop) => story(`${prop.property} ${prop.default ? "off" : "on"}`, [[prop.name, prop.default ? FALSE : TRUE]]))
395
+ story("Default", {}, [], playOf(component)),
396
+ ...component.model && model && boolean ? [story(component.model, { [model]: true }, [[model, TRUE]])] : [],
397
+ ...range && model ? [["Minimum", range.min], ["Maximum", range.max]].filter(([, value]) => value !== range.default).map(([label, value]) => story(label, { [model]: value }, [[model, numberArg(value, list)]])) : [],
398
+ ...component.choice && model ? component.choice.options.filter((option) => option !== component.choice?.default).map((option) => story(option, { [model]: option }, [[model, es.string(option)]])) : [],
399
+ ...component.disabled ? [story("Disabled", { disabled: true }, [["disabled", TRUE]])] : [],
400
+ ...component.props.flatMap((prop) => prop.options.filter((option) => option !== prop.default).map((option) => story(option, { [prop.name]: option }, [[prop.name, es.string(option)]]))),
401
+ ...component.booleans.map((prop) => story(`${prop.property} ${prop.default ? "off" : "on"}`, { [prop.name]: !prop.default }, [[prop.name, prop.default ? FALSE : TRUE]]))
400
402
  ];
401
403
  }
402
404
  /** CSF3 stories for a generated component, with a play function that operates it. */
@@ -422,11 +424,38 @@ function printComponentStories(data) {
422
424
  $Component: es.identifier(component.name),
423
425
  $path: es.string(entry.path)
424
426
  }).body;
425
- const all = stories(component, model, list);
426
- const exported = (data.single ? all.slice(0, 1) : all).flatMap((item) => es.fill(STORY, {
427
- $name: es.identifier(item.name),
428
- $story: item.story
429
- }).body);
427
+ const all = componentStories(component, model, list);
428
+ const kept = data.single ? all.slice(0, 1) : all;
429
+ const images = kept.flatMap((item, index) => {
430
+ const path = data.designs?.get(item.name);
431
+ return path ? es.fill(IMAGE, {
432
+ $name: es.identifier(`design${index}`),
433
+ $path: es.string(path)
434
+ }).body : [];
435
+ });
436
+ const exported = kept.flatMap((item, index) => {
437
+ const parameters = es.object([["design", es.array([es.object([
438
+ ["name", es.string("Design")],
439
+ ["type", es.string("image")],
440
+ ["url", es.identifier(`design${index}`)]
441
+ ])])]]);
442
+ const story = data.designs?.has(item.name) ? {
443
+ ...item.story,
444
+ properties: [...es.children(item.story, "properties"), {
445
+ type: "Property",
446
+ kind: "init",
447
+ key: es.identifier("parameters"),
448
+ value: parameters,
449
+ computed: false,
450
+ method: false,
451
+ shorthand: false
452
+ }]
453
+ } : item.story;
454
+ return es.fill(STORY, {
455
+ $name: es.identifier(item.name),
456
+ $story: story
457
+ }).body;
458
+ });
430
459
  const [types, expectImport, ...rest] = body;
431
460
  const imports = playOf(component) ? [types, expectImport] : [types];
432
461
  const module = es.printModule({
@@ -437,12 +466,13 @@ function printComponentStories(data) {
437
466
  ...stylesheets(data.styles),
438
467
  ...componentImport,
439
468
  ...rest,
469
+ ...images,
440
470
  ...exported
441
471
  ])
442
472
  });
443
473
  return `${HEADER}\n${module}\n`;
444
474
  }
445
475
  //#endregion
446
- export { STORYBOOK_FRAMEWORKS, STORYBOOK_PACKAGES, printComponentStories, printStoryModule };
476
+ export { STORYBOOK_FRAMEWORKS, STORYBOOK_PACKAGES, componentStories, printComponentStories, printStoryModule };
447
477
 
448
478
  //# sourceMappingURL=component.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"component.js","names":["HEADER","MODULE","STORY","argTypes"],"sources":["../../../../src/export/storybook/module.ts","../../../../src/export/storybook/component.ts"],"sourcesContent":["import dedent from 'dedent'\n\nimport { es } from '@pairdraw/emit'\n\nexport const STORYBOOK_FRAMEWORKS = ['react', 'vue', 'html'] as const\nexport type StorybookFramework = (typeof STORYBOOK_FRAMEWORKS)[number]\n\n/** Tells readers the file is generated; nothing parses it. */\nconst HEADER = '// Generated by Pairdraw. Re-export to update; edits are overwritten.'\n\n/**\n * How a variant property is controlled. A boolean value's property becomes a boolean arg that\n * picks its on or off variant; the interaction-state property is left to each story, with a\n * `disabled` arg picking its disabled variant when the set draws one.\n */\ntype StoryControl =\n | { type: 'boolean'; name: string; on: string; off: string }\n | { type: 'state'; rest: string; disabled?: string }\n\nexport interface StoryProp {\n name: string\n options: string[]\n control?: StoryControl\n}\n\n/** Everything a story module varies by; the TypeScript around it is a fixed template. */\nexport interface StoryModuleData {\n framework: StorybookFramework\n title: string\n /** Tags on the whole file, which its stories inherit. */\n tags: string[]\n /** Stylesheets the file imports, such as the fonts its text uses. */\n styles: string[]\n /** Group name used in the missing-variant error. */\n name: string\n props: StoryProp[]\n variants: { values: string[]; html: string }[]\n metaDesign: StoryDesign[]\n /** Import path of each design image, by variant index. */\n images: string[]\n /** Every variant laid out in one story, each with its label as escaped HTML, if a gallery. */\n gallery: { values: string[]; label: string }[] | null\n stories: {\n exportName: string\n label: string\n values: string[]\n design: StoryDesign[]\n tags: string[]\n }[]\n}\n\nexport type StoryDesign =\n | { type: 'link'; url: string }\n /** Refers to the design image of the variant with this index. */\n | { type: 'image'; variant: number }\n\nconst MODULE = es.parseModule(dedent`\n import type { Meta, StoryObj } from '$storybook'\n\n type Args = $Args\n\n const variants: Record<string, string> = $variants\n\n function variantHTML(args: Args): string {\n const key = JSON.stringify($key)\n const html = variants[key]\n if (html === undefined) throw new Error($missing + key)\n return html\n }\n\n const meta = {\n title: $title,\n tags: $tags,\n parameters: $parameters,\n args: $args,\n argTypes: $argTypes,\n render: (args) => $render\n } satisfies Meta<Args>\n\n export default meta\n type Story = StoryObj<Args>\n`)\n\nconst GALLERY = es.parseModule(dedent`\n const labels: [string, string][] = $labels\n\n function galleryHTML(): string {\n const items = labels.map(\n ([key, label]) =>\n '<figure style=\"margin: 0; display: flex; flex-direction: column; align-items: center; gap: 8px\">' +\n (variants[key] ?? '') +\n '<figcaption style=\"font: 12px system-ui, sans-serif; color: #6b7280\">' +\n label +\n '</figcaption></figure>'\n )\n return (\n '<div style=\"display: flex; flex-wrap: wrap; align-items: flex-end; gap: 24px\">' +\n items.join('') +\n '</div>'\n )\n }\n\n export const Gallery: Story = { name: 'Gallery', render: () => $render }\n`)\n\nconst IMAGE = es.parseModule(`const $name = new URL($path, import.meta.url).href`)\nconst STORY = es.parseModule(`export const $name: Story = $story`)\nconst STYLESHEET = es.parseModule(`import '$path'`)\n\n/** The Storybook renderer package each framework's stories import their types from. */\nexport const STORYBOOK_PACKAGES: Record<StorybookFramework, string> = {\n react: '@storybook/react-vite',\n vue: '@storybook/vue3-vite',\n html: '@storybook/html-vite'\n}\n\n/** How each framework renders a string of HTML, `$html`, as a story. */\nconst FRAMEWORKS: Record<StorybookFramework, { imports: es.SyntaxNode[]; render: es.SyntaxNode }> =\n {\n react: {\n imports: es.parseModule(`import { createElement } from 'react'`).body,\n render: es.parseExpression(\n `createElement('div', { dangerouslySetInnerHTML: { __html: $html } })`\n )\n },\n vue: {\n imports: es.parseModule(`import { h } from 'vue'`).body,\n render: es.parseExpression(`{ setup: () => () => h('div', { innerHTML: $html }) }`)\n },\n html: {\n imports: [],\n render: es.parseExpression('$html')\n }\n }\n\nconst rendered = (framework: StorybookFramework, html: string) =>\n es.fill(FRAMEWORKS[framework].render, { $html: es.parseExpression(html) })\n\nconst imageName = (variant: number) => `design${variant}`\n\nconst BOOLEAN = es.parseType('boolean')\nconst CONDITION = es.parseExpression('$test ? $then : $else')\nconst boolean = (value: boolean) => es.parseExpression(String(value))\n\nfunction argRef(name: string): es.SyntaxNode {\n return {\n type: 'MemberExpression',\n object: es.identifier('args'),\n property: es.string(name),\n computed: true,\n optional: false\n }\n}\n\n/** The `disabled` arg a state property adds, unless a boolean value already takes the name. */\nfunction disabledArg(data: StoryModuleData): { property: string; value: string } | null {\n if (\n data.props.some((prop) => prop.control?.type === 'boolean' && prop.control.name === 'disabled')\n )\n return null\n for (const prop of data.props)\n if (prop.control?.type === 'state' && prop.control.disabled !== undefined)\n return { property: prop.name, value: prop.control.disabled }\n return null\n}\n\n/** The arg a prop is set by: a boolean prop's own name, otherwise the property's. */\nconst argName = (prop: StoryProp) =>\n prop.control?.type === 'boolean' ? prop.control.name : prop.name\n\n/** The variant value a prop shows, as an expression over `args`. */\nfunction propValue(data: StoryModuleData, prop: StoryProp): es.SyntaxNode {\n const control = prop.control\n if (control?.type === 'boolean')\n return es.fill(CONDITION, {\n $test: argRef(control.name),\n $then: es.string(control.on),\n $else: es.string(control.off)\n })\n const disabled = disabledArg(data)\n if (disabled?.property === prop.name)\n return es.fill(CONDITION, {\n $test: argRef('disabled'),\n $then: es.string(disabled.value),\n $else: argRef(prop.name)\n })\n return argRef(prop.name)\n}\n\nfunction argsObject(data: StoryModuleData, values: string[]): es.SyntaxNode {\n const entries = data.props.map((prop, i): [string, es.SyntaxNode] => {\n const value = values[i] ?? ''\n if (prop.control?.type === 'boolean')\n return [prop.control.name, boolean(value === prop.control.on)]\n // A disabled story says so through `disabled`, so clearing it shows the rest state.\n if (prop.control?.type === 'state' && value === disabledArg(data)?.value)\n return [prop.name, es.string(prop.control.rest)]\n return [prop.name, es.string(value)]\n })\n const disabled = disabledArg(data)\n if (disabled) {\n const index = data.props.findIndex((prop) => prop.name === disabled.property)\n entries.push(['disabled', boolean(values[index] === disabled.value)])\n }\n return es.object(entries)\n}\n\nfunction argTypes(data: StoryModuleData): es.SyntaxNode {\n const entries = data.props.map((prop): [string, es.SyntaxNode] => {\n if (prop.control?.type === 'boolean')\n return [prop.control.name, es.object([['control', es.string('boolean')]])]\n if (prop.control?.type === 'state')\n return [prop.name, es.object([['table', es.object([['disable', boolean(true)]])]])]\n return [\n prop.name,\n es.object([\n ['control', es.string('select')],\n ['options', es.array(prop.options.map(es.string))]\n ])\n ]\n })\n if (disabledArg(data)) entries.push(['disabled', es.object([['control', es.string('boolean')]])])\n return es.object(entries)\n}\n\nfunction parameters(design: StoryDesign[]): es.SyntaxNode {\n const entries = design.map((entry) =>\n entry.type === 'link'\n ? es.object([\n ['name', es.string('Pairdraw')],\n ['type', es.string('link')],\n ['url', es.string(entry.url)]\n ])\n : es.object([\n ['name', es.string('Design')],\n ['type', es.string('image')],\n ['url', es.identifier(imageName(entry.variant))]\n ])\n )\n return es.object([['design', es.array(entries)]])\n}\n\nconst NO_ARGS = es.parseType('Record<string, never>')\n\nfunction argsType(data: StoryModuleData): es.SyntaxNode {\n if (data.props.length === 0) return NO_ARGS\n const entries = data.props.map((prop): [string, es.SyntaxNode] => [\n argName(prop),\n prop.control?.type === 'boolean' ? BOOLEAN : es.stringUnionType(prop.options)\n ])\n if (disabledArg(data)) entries.push(['disabled', BOOLEAN])\n return es.objectType(entries)\n}\n\n/** `import './fonts/kit/fonts.css'` for each stylesheet, which the bundler loads with the stories. */\nexport const stylesheets = (paths: readonly string[]) =>\n paths.flatMap((path) => es.fill(STYLESHEET, { $path: es.string(path) }).body)\n\n/** Print a CSF3 story module for one component or component set. */\nexport function printStoryModule(data: StoryModuleData): string {\n const framework = FRAMEWORKS[data.framework]\n const [storybookImport, ...body] = es.fill(MODULE, {\n $storybook: es.string(STORYBOOK_PACKAGES[data.framework]),\n $Args: argsType(data),\n $variants: es.object(\n data.variants.map((variant) => [JSON.stringify(variant.values), es.string(variant.html)])\n ),\n $key: es.array(data.props.map((prop) => propValue(data, prop))),\n $missing: es.string(`${data.name} has no variant `),\n $title: es.string(data.title),\n $tags: es.array(data.tags.map(es.string)),\n $parameters: data.metaDesign.length > 0 ? parameters(data.metaDesign) : es.OMIT,\n $args: argsObject(data, data.variants[0]?.values ?? []),\n $argTypes: argTypes(data),\n $render: rendered(data.framework, 'variantHTML(args)')\n }).body\n const images = data.images.flatMap(\n (path, i) =>\n es.fill(IMAGE, { $name: es.identifier(imageName(i)), $path: es.string(`./${path}`) }).body\n )\n const stories = data.stories.flatMap(\n (story) =>\n es.fill(STORY, {\n $name: es.identifier(story.exportName),\n $story: es.object([\n ['name', es.string(story.label)],\n ...(story.tags.length > 0\n ? [['tags', es.array(story.tags.map(es.string))] as const]\n : []),\n ...(story.design.length > 0 ? [['parameters', parameters(story.design)] as const] : []),\n ['args', argsObject(data, story.values)]\n ])\n }).body\n )\n const gallery = data.gallery\n ? es.fill(GALLERY, {\n $labels: es.array(\n data.gallery.map((item) =>\n es.array([es.string(JSON.stringify(item.values)), es.string(item.label)])\n )\n ),\n $render: rendered(data.framework, 'galleryHTML()')\n }).body\n : []\n const module = es.printModule({\n type: 'Program',\n sourceType: 'module',\n body: [\n storybookImport,\n ...framework.imports,\n ...stylesheets(data.styles),\n ...images,\n ...body,\n ...stories,\n ...gallery\n ]\n })\n return `${HEADER}\\n${module}\\n`\n}\n","import dedent from 'dedent'\nimport { compact } from 'es-toolkit/array'\n\nimport { es } from '@pairdraw/emit'\n\nimport type {\n ComponentModel,\n ComponentNode,\n GeneratedComponent,\n GeneratedKind\n} from '../components/model'\nimport { stylesheets } from './module'\nimport { claimName, identifierName, VARIANT_TAG } from './names'\n\n/** Tells readers the file is generated; nothing parses it. */\nconst HEADER = '// Generated by Pairdraw. Re-export to update; edits are overwritten.'\n\nconst MODULE = es.parseModule(dedent`\n import type { Meta, StoryObj } from '$storybook'\n import { expect } from 'storybook/test'\n\n const meta = {\n title: $title,\n tags: $tags,\n component: $Component,\n parameters: $parameters,\n args: $args,\n argTypes: $argTypes\n } satisfies Meta<typeof $Component>\n\n export default meta\n type Story = StoryObj<typeof meta>\n`)\n\nconst IMPORT_DEFAULT = es.parseModule(`import $Component from '$path'`)\nconst IMPORT_NAMED = es.parseModule(`import { $Component } from '$path'`)\n\nconst STORY = es.parseModule(`export const $name: Story = $story`)\n\n/**\n * What clicking a control does, as Reka marks it: the role to find it by, the element that\n * changes, and the `data-state` it ends in.\n */\nconst INTERACTIONS: Partial<Record<GeneratedKind, { role: string; state: string }>> = {\n switch: { role: 'switch', state: 'checked' },\n checkbox: { role: 'checkbox', state: 'checked' },\n toggle: { role: 'button', state: 'on' },\n collapsible: { role: 'button', state: 'open' }\n}\n\nconst PLAY = es.parseExpression(dedent`\n async ({ canvas, userEvent }) => {\n const control = canvas.getByRole($role)\n await userEvent.click(control)\n await expect(control).toHaveAttribute('data-state', $state)\n }\n`)\n\n/** A slider's Home key moves it to its minimum, as Reka and Radix both handle it. */\nconst SLIDER_PLAY = es.parseExpression(dedent`\n async ({ canvas, userEvent }) => {\n const thumb = canvas.getByRole('slider')\n thumb.focus()\n await userEvent.keyboard('{Home}')\n await expect(thumb).toHaveAttribute('aria-valuenow', $min)\n }\n`)\n\n/**\n * A stepper steps a number field. Both Reka's and the native field's steppers are named by\n * what they do, where a key would only step Reka's input, not a native number input.\n */\nconst NUMBER_PLAY = es.parseExpression(dedent`\n async ({ canvas, userEvent }) => {\n await userEvent.click(canvas.getByRole('button', { name: $stepper }))\n await expect(canvas.getByRole('spinbutton')).toHaveDisplayValue($value)\n }\n`)\n\n/** Whether the component draws a part, such as a number field's increment. */\nfunction drawsPart(node: ComponentNode, part: string): boolean {\n return (\n node.type === 'element' &&\n (node.part === part || node.children.some((child) => drawsPart(child, part)))\n )\n}\n\n/** Typing replaces a text field's words. */\nconst TEXT_PLAY = es.parseExpression(dedent`\n async ({ canvas, userEvent }) => {\n const field = canvas.getByRole('textbox')\n await userEvent.clear(field)\n await userEvent.type(field, 'Hello')\n await expect(field).toHaveValue('Hello')\n }\n`)\n\n/** The play function that operates a generated component, if it has one. */\nfunction playOf(component: ComponentModel): es.SyntaxNode | undefined {\n const interaction = INTERACTIONS[component.kind]\n if (interaction)\n return es.fill(PLAY, {\n $role: es.string(interaction.role),\n $state: es.string(interaction.state)\n })\n const { range } = component\n if (component.kind === 'slider' && range)\n return es.fill(SLIDER_PLAY, { $min: es.string(String(range.min)) })\n if (component.kind === 'numberField' && range) {\n const up = range.default + range.step <= range.max\n const part = up ? 'increment' : 'decrement'\n if (!drawsPart(component.tree, part)) return undefined\n return es.fill(NUMBER_PLAY, {\n $stepper: es.string(up ? 'Increase' : 'Decrease'),\n $value: es.string(String(up ? range.default + range.step : range.default - range.step))\n })\n }\n if (component.kind === 'textField' || component.kind === 'textarea') return TEXT_PLAY\n return undefined\n}\n\nexport interface ComponentStoriesData {\n /** The Storybook renderer package the stories import their types from. */\n storybook: string\n title: string\n /** Tags on the whole file, which its stories inherit. */\n tags: string[]\n /** Stylesheets the file imports, such as the fonts its text uses. */\n styles: string[]\n /** Only the Default story, as a plan can ask for. */\n single?: boolean\n component: ComponentModel\n generated: Pick<GeneratedComponent, 'entry' | 'valueArg' | 'valueList'>\n /** Design links for the whole file, as `parameters.design` entries. */\n design: { name: string; type: string; url: string }[]\n}\n\nconst FALSE = es.parseExpression('false')\nconst TRUE = es.parseExpression('true')\n\n/** A number model's value as its prop takes it: on its own, or in a list for a slider. */\nconst numberArg = (value: number, list: boolean) =>\n list ? es.array([es.number(value)]) : es.number(value)\n\n/**\n * A model's value at rest: off, the option a choice starts on, none for an open choice, the\n * number a range starts at, or the words a field starts with.\n */\nfunction restValue(component: ComponentModel, list: boolean): es.SyntaxNode | null {\n if (component.range) return numberArg(component.range.default, list)\n if (component.text) return es.string(component.text.default)\n if (!component.choice) return FALSE\n return component.choice.default === null ? null : es.string(component.choice.default)\n}\n\nfunction restArgs(\n component: ComponentModel,\n model: string | null,\n list: boolean\n): [string, es.SyntaxNode][] {\n const rest = restValue(component, list)\n return [\n ...(model && rest ? [[model, rest] as [string, es.SyntaxNode]] : []),\n ...(component.disabled ? [['disabled', FALSE] as [string, es.SyntaxNode]] : []),\n ...component.props.map((prop): [string, es.SyntaxNode] => [prop.name, es.string(prop.default)]),\n ...component.texts.map((text): [string, es.SyntaxNode] => [text.name, es.string(text.default)]),\n ...component.booleans.map((prop): [string, es.SyntaxNode] => [\n prop.name,\n prop.default ? TRUE : FALSE\n ])\n ]\n}\n\n/** The control a model's value gets: a choice's options, a range, text, or a boolean. */\nfunction modelControl(component: ComponentModel, list: boolean): es.SyntaxNode {\n const control = (type: string) => es.object([['control', es.string(type)]])\n const { choice, range } = component\n if (choice)\n return es.object([\n ['control', es.string('select')],\n ['options', es.array(choice.options.map(es.string))]\n ])\n // A slider's list of values is edited as one, not as a range.\n if (range && list) return control('object')\n if (range)\n return es.object([\n [\n 'control',\n es.object([\n ['type', es.string('range')],\n ['min', es.number(range.min)],\n ['max', es.number(range.max)],\n ['step', es.number(range.step)]\n ])\n ]\n ])\n return control(component.text ? 'text' : 'boolean')\n}\n\nfunction argTypes(component: ComponentModel, model: string | null, list: boolean): es.SyntaxNode {\n const boolean = es.object([['control', es.string('boolean')]])\n const select = (options: readonly string[]) =>\n es.object([\n ['control', es.string('select')],\n ['options', es.array(options.map(es.string))]\n ])\n return es.object([\n ...(model ? [[model, modelControl(component, list)] as [string, es.SyntaxNode]] : []),\n ...(component.disabled ? [['disabled', boolean] as [string, es.SyntaxNode]] : []),\n ...component.props.map((prop): [string, es.SyntaxNode] => [prop.name, select(prop.options)]),\n ...component.texts.map((text): [string, es.SyntaxNode] => [\n text.name,\n es.object([['control', es.string('text')]])\n ]),\n ...component.booleans.map((prop): [string, es.SyntaxNode] => [prop.name, boolean])\n ])\n}\n\n/** A story per state worth seeing: at rest, each boolean on, disabled, and each prop value. */\nfunction stories(\n component: ComponentModel,\n model: string | null,\n list: boolean\n): { name: string; story: es.SyntaxNode }[] {\n // Stories are named apart from the component the file imports and the module's own names.\n const taken = new Set([component.name, 'meta', 'Story'])\n let first = true\n const story = (label: string, args: [string, es.SyntaxNode][], play?: es.SyntaxNode) => {\n // Every story after the first, Default, is another state, tagged so Storybook can hide it.\n const variant = !first\n first = false\n return {\n name: claimName(identifierName(label, 'Story'), taken),\n story: es.object([\n ...(variant\n ? [['tags', es.array([es.string(VARIANT_TAG)])] as [string, es.SyntaxNode]]\n : []),\n ...(args.length > 0 ? [['args', es.object(args)] as [string, es.SyntaxNode]] : []),\n ...(play ? [['play', play] as [string, es.SyntaxNode]] : [])\n ])\n }\n }\n const { range } = component\n const boolean = !component.choice && !range && !component.text\n return [\n story('Default', [], playOf(component)),\n ...(component.model && model && boolean ? [story(component.model, [[model, TRUE]])] : []),\n // A range gets a story at each end it does not start at.\n ...(range && model\n ? (\n [\n ['Minimum', range.min],\n ['Maximum', range.max]\n ] as const\n )\n .filter(([, value]) => value !== range.default)\n .map(([label, value]) => story(label, [[model, numberArg(value, list)]]))\n : []),\n // A choice gets a story per option it does not start on, such as each other tab.\n ...(component.choice && model\n ? component.choice.options\n .filter((option) => option !== component.choice?.default)\n .map((option) => story(option, [[model, es.string(option)]]))\n : []),\n ...(component.disabled ? [story('Disabled', [['disabled', TRUE]])] : []),\n ...component.props.flatMap((prop) =>\n prop.options\n .filter((option) => option !== prop.default)\n .map((option) => story(option, [[prop.name, es.string(option)]]))\n ),\n // A boolean gets a story drawn the other way, such as an icon shown that is hidden at rest.\n ...component.booleans.map((prop) =>\n story(`${prop.property} ${prop.default ? 'off' : 'on'}`, [\n [prop.name, prop.default ? FALSE : TRUE]\n ])\n )\n ]\n}\n\n/** CSF3 stories for a generated component, with a play function that operates it. */\nexport function printComponentStories(data: ComponentStoriesData): string {\n const { component } = data\n const parameters =\n data.design.length > 0\n ? es.object([\n [\n 'design',\n es.array(\n data.design.map((entry) =>\n es.object([\n ['name', es.string(entry.name)],\n ['type', es.string(entry.type)],\n ['url', es.string(entry.url)]\n ])\n )\n )\n ]\n ])\n : es.OMIT\n const { entry, valueArg: model } = data.generated\n const list = data.generated.valueList ?? false\n const body = es.fill(MODULE, {\n $storybook: es.string(data.storybook),\n $Component: es.identifier(component.name),\n $title: es.string(data.title),\n $tags: es.array(data.tags.map(es.string)),\n $parameters: parameters,\n $args: es.object(restArgs(component, model, list)),\n $argTypes: argTypes(component, model, list)\n }).body\n const componentImport = es.fill(entry.named ? IMPORT_NAMED : IMPORT_DEFAULT, {\n $Component: es.identifier(component.name),\n $path: es.string(entry.path)\n }).body\n const all = stories(component, model, list)\n const exported = (data.single ? all.slice(0, 1) : all).flatMap(\n (item) => es.fill(STORY, { $name: es.identifier(item.name), $story: item.story }).body\n )\n // Only a control with a play function uses `expect`.\n const [types, expectImport, ...rest] = body\n const imports = playOf(component) ? [types, expectImport] : [types]\n const module = es.printModule({\n type: 'Program',\n sourceType: 'module',\n body: compact([\n ...imports,\n ...stylesheets(data.styles),\n ...componentImport,\n ...rest,\n ...exported\n ])\n })\n return `${HEADER}\\n${module}\\n`\n}\n"],"mappings":";;;;;AAIA,MAAa,uBAAuB;CAAC;CAAS;CAAO;AAAM;;AAI3D,MAAMA,WAAS;AAgDf,MAAMC,WAAS,GAAG,YAAY,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;CAyBnC;AAED,MAAM,UAAU,GAAG,YAAY,MAAM;;;;;;;;;;;;;;;;;;;;CAoBpC;AAED,MAAM,QAAQ,GAAG,YAAY,oDAAoD;AACjF,MAAMC,UAAQ,GAAG,YAAY,oCAAoC;AACjE,MAAM,aAAa,GAAG,YAAY,gBAAgB;;AAGlD,MAAa,qBAAyD;CACpE,OAAO;CACP,KAAK;CACL,MAAM;AACR;;AAGA,MAAM,aACJ;CACE,OAAO;EACL,SAAS,GAAG,YAAY,uCAAuC,CAAC,CAAC;EACjE,QAAQ,GAAG,gBACT,sEACF;CACF;CACA,KAAK;EACH,SAAS,GAAG,YAAY,yBAAyB,CAAC,CAAC;EACnD,QAAQ,GAAG,gBAAgB,uDAAuD;CACpF;CACA,MAAM;EACJ,SAAS,CAAC;EACV,QAAQ,GAAG,g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AG,KAAK,OAAO;EAAE,OAAO,GAAG,WAAW,KAAK,IAAI;EAAG,QAAQ,KAAK;CAAM,CAAC,CAAC,CAAC,IACpF;CAEA,MAAM,CAAC,OAAO,cAAc,GAAG,QAAQ;CACvC,MAAM,UAAU,OAAO,SAAS,IAAI,CAAC,OAAO,YAAY,IAAI,CAAC,KAAK;CAClE,MAAM,SAAS,GAAG,YAAY;EAC5B,MAAM;EACN,YAAY;EACZ,MAAM,QAAQ;GACZ,GAAG;GACH,GAAG,YAAY,KAAK,MAAM;GAC1B,GAAG;GACH,GAAG;GACH,GAAG;EACL,CAAC;CACH,CAAC;CACD,OAAO,GAAG,OAAO,IAAI,OAAO;AAC9B"}
1
+ {"version":3,"file":"component.js","names":["HEADER","MODULE","IMAGE","STORY","argTypes"],"sources":["../../../../src/export/storybook/module.ts","../../../../src/export/storybook/component.ts"],"sourcesContent":["import dedent from 'dedent'\n\nimport { es } from '@pairdraw/emit'\n\nexport const STORYBOOK_FRAMEWORKS = ['react', 'vue', 'html'] as const\nexport type StorybookFramework = (typeof STORYBOOK_FRAMEWORKS)[number]\n\n/** Tells readers the file is generated; nothing parses it. */\nconst HEADER = '// Generated by Pairdraw. Re-export to update; edits are overwritten.'\n\n/**\n * How a variant property is controlled. A boolean value's property becomes a boolean arg that\n * picks its on or off variant; the interaction-state property is left to each story, with a\n * `disabled` arg picking its disabled variant when the set draws one.\n */\ntype StoryControl =\n | { type: 'boolean'; name: string; on: string; off: string }\n | { type: 'state'; rest: string; disabled?: string }\n\nexport interface StoryProp {\n name: string\n options: string[]\n control?: StoryControl\n}\n\n/** Everything a story module varies by; the TypeScript around it is a fixed template. */\nexport interface StoryModuleData {\n framework: StorybookFramework\n title: string\n /** Tags on the whole file, which its stories inherit. */\n tags: string[]\n /** Stylesheets the file imports, such as the fonts its text uses. */\n styles: string[]\n /** Group name used in the missing-variant error. */\n name: string\n props: StoryProp[]\n variants: { values: string[]; html: string }[]\n metaDesign: StoryDesign[]\n /** Import path of each design image, by variant index. */\n images: string[]\n /** Every variant laid out in one story, each with its label as escaped HTML, if a gallery. */\n gallery: { values: string[]; label: string }[] | null\n stories: {\n exportName: string\n label: string\n values: string[]\n design: StoryDesign[]\n tags: string[]\n }[]\n}\n\nexport type StoryDesign =\n | { type: 'link'; url: string }\n /** Refers to the design image of the variant with this index. */\n | { type: 'image'; variant: number }\n\nconst MODULE = es.parseModule(dedent`\n import type { Meta, StoryObj } from '$storybook'\n\n type Args = $Args\n\n const variants: Record<string, string> = $variants\n\n function variantHTML(args: Args): string {\n const key = JSON.stringify($key)\n const html = variants[key]\n if (html === undefined) throw new Error($missing + key)\n return html\n }\n\n const meta = {\n title: $title,\n tags: $tags,\n parameters: $parameters,\n args: $args,\n argTypes: $argTypes,\n render: (args) => $render\n } satisfies Meta<Args>\n\n export default meta\n type Story = StoryObj<Args>\n`)\n\nconst GALLERY = es.parseModule(dedent`\n const labels: [string, string][] = $labels\n\n function galleryHTML(): string {\n const items = labels.map(\n ([key, label]) =>\n '<figure style=\"margin: 0; display: flex; flex-direction: column; align-items: center; gap: 8px\">' +\n (variants[key] ?? '') +\n '<figcaption style=\"font: 12px system-ui, sans-serif; color: #6b7280\">' +\n label +\n '</figcaption></figure>'\n )\n return (\n '<div style=\"display: flex; flex-wrap: wrap; align-items: flex-end; gap: 24px\">' +\n items.join('') +\n '</div>'\n )\n }\n\n export const Gallery: Story = { name: 'Gallery', render: () => $render }\n`)\n\nconst IMAGE = es.parseModule(`const $name = new URL($path, import.meta.url).href`)\nconst STORY = es.parseModule(`export const $name: Story = $story`)\nconst STYLESHEET = es.parseModule(`import '$path'`)\n\n/** The Storybook renderer package each framework's stories import their types from. */\nexport const STORYBOOK_PACKAGES: Record<StorybookFramework, string> = {\n react: '@storybook/react-vite',\n vue: '@storybook/vue3-vite',\n html: '@storybook/html-vite'\n}\n\n/** How each framework renders a string of HTML, `$html`, as a story. */\nconst FRAMEWORKS: Record<StorybookFramework, { imports: es.SyntaxNode[]; render: es.SyntaxNode }> =\n {\n react: {\n imports: es.parseModule(`import { createElement } from 'react'`).body,\n render: es.parseExpression(\n `createElement('div', { dangerouslySetInnerHTML: { __html: $html } })`\n )\n },\n vue: {\n imports: es.parseModule(`import { h } from 'vue'`).body,\n render: es.parseExpression(`{ setup: () => () => h('div', { innerHTML: $html }) }`)\n },\n html: {\n imports: [],\n render: es.parseExpression('$html')\n }\n }\n\nconst rendered = (framework: StorybookFramework, html: string) =>\n es.fill(FRAMEWORKS[framework].render, { $html: es.parseExpression(html) })\n\nconst imageName = (variant: number) => `design${variant}`\n\nconst BOOLEAN = es.parseType('boolean')\nconst CONDITION = es.parseExpression('$test ? $then : $else')\nconst boolean = (value: boolean) => es.parseExpression(String(value))\n\nfunction argRef(name: string): es.SyntaxNode {\n return {\n type: 'MemberExpression',\n object: es.identifier('args'),\n property: es.string(name),\n computed: true,\n optional: false\n }\n}\n\n/** The `disabled` arg a state property adds, unless a boolean value already takes the name. */\nfunction disabledArg(data: StoryModuleData): { property: string; value: string } | null {\n if (\n data.props.some((prop) => prop.control?.type === 'boolean' && prop.control.name === 'disabled')\n )\n return null\n for (const prop of data.props)\n if (prop.control?.type === 'state' && prop.control.disabled !== undefined)\n return { property: prop.name, value: prop.control.disabled }\n return null\n}\n\n/** The arg a prop is set by: a boolean prop's own name, otherwise the property's. */\nconst argName = (prop: StoryProp) =>\n prop.control?.type === 'boolean' ? prop.control.name : prop.name\n\n/** The variant value a prop shows, as an expression over `args`. */\nfunction propValue(data: StoryModuleData, prop: StoryProp): es.SyntaxNode {\n const control = prop.control\n if (control?.type === 'boolean')\n return es.fill(CONDITION, {\n $test: argRef(control.name),\n $then: es.string(control.on),\n $else: es.string(control.off)\n })\n const disabled = disabledArg(data)\n if (disabled?.property === prop.name)\n return es.fill(CONDITION, {\n $test: argRef('disabled'),\n $then: es.string(disabled.value),\n $else: argRef(prop.name)\n })\n return argRef(prop.name)\n}\n\nfunction argsObject(data: StoryModuleData, values: string[]): es.SyntaxNode {\n const entries = data.props.map((prop, i): [string, es.SyntaxNode] => {\n const value = values[i] ?? ''\n if (prop.control?.type === 'boolean')\n return [prop.control.name, boolean(value === prop.control.on)]\n // A disabled story says so through `disabled`, so clearing it shows the rest state.\n if (prop.control?.type === 'state' && value === disabledArg(data)?.value)\n return [prop.name, es.string(prop.control.rest)]\n return [prop.name, es.string(value)]\n })\n const disabled = disabledArg(data)\n if (disabled) {\n const index = data.props.findIndex((prop) => prop.name === disabled.property)\n entries.push(['disabled', boolean(values[index] === disabled.value)])\n }\n return es.object(entries)\n}\n\nfunction argTypes(data: StoryModuleData): es.SyntaxNode {\n const entries = data.props.map((prop): [string, es.SyntaxNode] => {\n if (prop.control?.type === 'boolean')\n return [prop.control.name, es.object([['control', es.string('boolean')]])]\n if (prop.control?.type === 'state')\n return [prop.name, es.object([['table', es.object([['disable', boolean(true)]])]])]\n return [\n prop.name,\n es.object([\n ['control', es.string('select')],\n ['options', es.array(prop.options.map(es.string))]\n ])\n ]\n })\n if (disabledArg(data)) entries.push(['disabled', es.object([['control', es.string('boolean')]])])\n return es.object(entries)\n}\n\nfunction parameters(design: StoryDesign[]): es.SyntaxNode {\n const entries = design.map((entry) =>\n entry.type === 'link'\n ? es.object([\n ['name', es.string('Pairdraw')],\n ['type', es.string('link')],\n ['url', es.string(entry.url)]\n ])\n : es.object([\n ['name', es.string('Design')],\n ['type', es.string('image')],\n ['url', es.identifier(imageName(entry.variant))]\n ])\n )\n return es.object([['design', es.array(entries)]])\n}\n\nconst NO_ARGS = es.parseType('Record<string, never>')\n\nfunction argsType(data: StoryModuleData): es.SyntaxNode {\n if (data.props.length === 0) return NO_ARGS\n const entries = data.props.map((prop): [string, es.SyntaxNode] => [\n argName(prop),\n prop.control?.type === 'boolean' ? BOOLEAN : es.stringUnionType(prop.options)\n ])\n if (disabledArg(data)) entries.push(['disabled', BOOLEAN])\n return es.objectType(entries)\n}\n\n/** `import './fonts/kit/fonts.css'` for each stylesheet, which the bundler loads with the stories. */\nexport const stylesheets = (paths: readonly string[]) =>\n paths.flatMap((path) => es.fill(STYLESHEET, { $path: es.string(path) }).body)\n\n/** Print a CSF3 story module for one component or component set. */\nexport function printStoryModule(data: StoryModuleData): string {\n const framework = FRAMEWORKS[data.framework]\n const [storybookImport, ...body] = es.fill(MODULE, {\n $storybook: es.string(STORYBOOK_PACKAGES[data.framework]),\n $Args: argsType(data),\n $variants: es.object(\n data.variants.map((variant) => [JSON.stringify(variant.values), es.string(variant.html)])\n ),\n $key: es.array(data.props.map((prop) => propValue(data, prop))),\n $missing: es.string(`${data.name} has no variant `),\n $title: es.string(data.title),\n $tags: es.array(data.tags.map(es.string)),\n $parameters: data.metaDesign.length > 0 ? parameters(data.metaDesign) : es.OMIT,\n $args: argsObject(data, data.variants[0]?.values ?? []),\n $argTypes: argTypes(data),\n $render: rendered(data.framework, 'variantHTML(args)')\n }).body\n const images = data.images.flatMap(\n (path, i) =>\n es.fill(IMAGE, { $name: es.identifier(imageName(i)), $path: es.string(`./${path}`) }).body\n )\n const stories = data.stories.flatMap(\n (story) =>\n es.fill(STORY, {\n $name: es.identifier(story.exportName),\n $story: es.object([\n ['name', es.string(story.label)],\n ...(story.tags.length > 0\n ? [['tags', es.array(story.tags.map(es.string))] as const]\n : []),\n ...(story.design.length > 0 ? [['parameters', parameters(story.design)] as const] : []),\n ['args', argsObject(data, story.values)]\n ])\n }).body\n )\n const gallery = data.gallery\n ? es.fill(GALLERY, {\n $labels: es.array(\n data.gallery.map((item) =>\n es.array([es.string(JSON.stringify(item.values)), es.string(item.label)])\n )\n ),\n $render: rendered(data.framework, 'galleryHTML()')\n }).body\n : []\n const module = es.printModule({\n type: 'Program',\n sourceType: 'module',\n body: [\n storybookImport,\n ...framework.imports,\n ...stylesheets(data.styles),\n ...images,\n ...body,\n ...stories,\n ...gallery\n ]\n })\n return `${HEADER}\\n${module}\\n`\n}\n","import dedent from 'dedent'\nimport { compact } from 'es-toolkit/array'\n\nimport { es } from '@pairdraw/emit'\n\nimport type {\n ComponentModel,\n ComponentNode,\n GeneratedComponent,\n GeneratedKind\n} from '../components/model'\nimport { stylesheets } from './module'\nimport { claimName, identifierName, VARIANT_TAG } from './names'\n\n/** Tells readers the file is generated; nothing parses it. */\nconst HEADER = '// Generated by Pairdraw. Re-export to update; edits are overwritten.'\n\nconst MODULE = es.parseModule(dedent`\n import type { Meta, StoryObj } from '$storybook'\n import { expect } from 'storybook/test'\n\n const meta = {\n title: $title,\n tags: $tags,\n component: $Component,\n parameters: $parameters,\n args: $args,\n argTypes: $argTypes\n } satisfies Meta<typeof $Component>\n\n export default meta\n type Story = StoryObj<typeof meta>\n`)\n\nconst IMPORT_DEFAULT = es.parseModule(`import $Component from '$path'`)\nconst IMPORT_NAMED = es.parseModule(`import { $Component } from '$path'`)\n\nconst STORY = es.parseModule(`export const $name: Story = $story`)\n\nconst IMAGE = es.parseModule(`const $name = new URL($path, import.meta.url).href`)\n\n/**\n * What clicking a control does, as Reka marks it: the role to find it by, the element that\n * changes, and the `data-state` it ends in.\n */\nconst INTERACTIONS: Partial<Record<GeneratedKind, { role: string; state: string }>> = {\n switch: { role: 'switch', state: 'checked' },\n checkbox: { role: 'checkbox', state: 'checked' },\n toggle: { role: 'button', state: 'on' },\n collapsible: { role: 'button', state: 'open' }\n}\n\nconst PLAY = es.parseExpression(dedent`\n async ({ canvas, userEvent }) => {\n const control = canvas.getByRole($role)\n await userEvent.click(control)\n await expect(control).toHaveAttribute('data-state', $state)\n }\n`)\n\n/** A slider's Home key moves it to its minimum, as Reka and Radix both handle it. */\nconst SLIDER_PLAY = es.parseExpression(dedent`\n async ({ canvas, userEvent }) => {\n const thumb = canvas.getByRole('slider')\n thumb.focus()\n await userEvent.keyboard('{Home}')\n await expect(thumb).toHaveAttribute('aria-valuenow', $min)\n }\n`)\n\n/**\n * A stepper steps a number field. Both Reka's and the native field's steppers are named by\n * what they do, where a key would only step Reka's input, not a native number input.\n */\nconst NUMBER_PLAY = es.parseExpression(dedent`\n async ({ canvas, userEvent }) => {\n await userEvent.click(canvas.getByRole('button', { name: $stepper }))\n await expect(canvas.getByRole('spinbutton')).toHaveDisplayValue($value)\n }\n`)\n\n/** Whether the component draws a part, such as a number field's increment. */\nfunction drawsPart(node: ComponentNode, part: string): boolean {\n return (\n node.type === 'element' &&\n (node.part === part || node.children.some((child) => drawsPart(child, part)))\n )\n}\n\n/** Typing replaces a text field's words. */\nconst TEXT_PLAY = es.parseExpression(dedent`\n async ({ canvas, userEvent }) => {\n const field = canvas.getByRole('textbox')\n await userEvent.clear(field)\n await userEvent.type(field, 'Hello')\n await expect(field).toHaveValue('Hello')\n }\n`)\n\n/** The play function that operates a generated component, if it has one. */\nfunction playOf(component: ComponentModel): es.SyntaxNode | undefined {\n const interaction = INTERACTIONS[component.kind]\n if (interaction)\n return es.fill(PLAY, {\n $role: es.string(interaction.role),\n $state: es.string(interaction.state)\n })\n const { range } = component\n if (component.kind === 'slider' && range)\n return es.fill(SLIDER_PLAY, { $min: es.string(String(range.min)) })\n if (component.kind === 'numberField' && range) {\n const up = range.default + range.step <= range.max\n const part = up ? 'increment' : 'decrement'\n if (!drawsPart(component.tree, part)) return undefined\n return es.fill(NUMBER_PLAY, {\n $stepper: es.string(up ? 'Increase' : 'Decrease'),\n $value: es.string(String(up ? range.default + range.step : range.default - range.step))\n })\n }\n if (component.kind === 'textField' || component.kind === 'textarea') return TEXT_PLAY\n return undefined\n}\n\nexport interface ComponentStoriesData {\n /** The Storybook renderer package the stories import their types from. */\n storybook: string\n title: string\n /** Tags on the whole file, which its stories inherit. */\n tags: string[]\n /** Stylesheets the file imports, such as the fonts its text uses. */\n styles: string[]\n /** Only the Default story, as a plan can ask for. */\n single?: boolean\n component: ComponentModel\n generated: Pick<GeneratedComponent, 'entry' | 'valueArg' | 'valueList'>\n /** Design links for the whole file, as `parameters.design` entries. */\n design: { name: string; type: string; url: string }[]\n /** Design image per story, by story name: the path relative to the story file. */\n designs?: Map<string, string>\n}\n\n/** The prop values a story sets over the component's rest values. */\nexport type StoryValues = Record<string, string | number | boolean>\n\nconst FALSE = es.parseExpression('false')\nconst TRUE = es.parseExpression('true')\n\n/** A number model's value as its prop takes it: on its own, or in a list for a slider. */\nconst numberArg = (value: number, list: boolean) =>\n list ? es.array([es.number(value)]) : es.number(value)\n\n/**\n * A model's value at rest: off, the option a choice starts on, none for an open choice, the\n * number a range starts at, or the words a field starts with.\n */\nfunction restValue(component: ComponentModel, list: boolean): es.SyntaxNode | null {\n if (component.range) return numberArg(component.range.default, list)\n if (component.text) return es.string(component.text.default)\n if (!component.choice) return FALSE\n return component.choice.default === null ? null : es.string(component.choice.default)\n}\n\nfunction restArgs(\n component: ComponentModel,\n model: string | null,\n list: boolean\n): [string, es.SyntaxNode][] {\n const rest = restValue(component, list)\n return [\n ...(model && rest ? [[model, rest] as [string, es.SyntaxNode]] : []),\n ...(component.disabled ? [['disabled', FALSE] as [string, es.SyntaxNode]] : []),\n ...component.props.map((prop): [string, es.SyntaxNode] => [prop.name, es.string(prop.default)]),\n ...component.texts.map((text): [string, es.SyntaxNode] => [text.name, es.string(text.default)]),\n ...component.booleans.map((prop): [string, es.SyntaxNode] => [\n prop.name,\n prop.default ? TRUE : FALSE\n ])\n ]\n}\n\n/** The control a model's value gets: a choice's options, a range, text, or a boolean. */\nfunction modelControl(component: ComponentModel, list: boolean): es.SyntaxNode {\n const control = (type: string) => es.object([['control', es.string(type)]])\n const { choice, range } = component\n if (choice)\n return es.object([\n ['control', es.string('select')],\n ['options', es.array(choice.options.map(es.string))]\n ])\n // A slider's list of values is edited as one, not as a range.\n if (range && list) return control('object')\n if (range)\n return es.object([\n [\n 'control',\n es.object([\n ['type', es.string('range')],\n ['min', es.number(range.min)],\n ['max', es.number(range.max)],\n ['step', es.number(range.step)]\n ])\n ]\n ])\n return control(component.text ? 'text' : 'boolean')\n}\n\nfunction argTypes(component: ComponentModel, model: string | null, list: boolean): es.SyntaxNode {\n const boolean = es.object([['control', es.string('boolean')]])\n const select = (options: readonly string[]) =>\n es.object([\n ['control', es.string('select')],\n ['options', es.array(options.map(es.string))]\n ])\n return es.object([\n ...(model ? [[model, modelControl(component, list)] as [string, es.SyntaxNode]] : []),\n ...(component.disabled ? [['disabled', boolean] as [string, es.SyntaxNode]] : []),\n ...component.props.map((prop): [string, es.SyntaxNode] => [prop.name, select(prop.options)]),\n ...component.texts.map((text): [string, es.SyntaxNode] => [\n text.name,\n es.object([['control', es.string('text')]])\n ]),\n ...component.booleans.map((prop): [string, es.SyntaxNode] => [prop.name, boolean])\n ])\n}\n\n/** A story per state worth seeing: at rest, each boolean on, disabled, and each prop value. */\nexport function componentStories(\n component: ComponentModel,\n model: string | null,\n list: boolean\n): { name: string; values: StoryValues; story: es.SyntaxNode }[] {\n // Stories are named apart from the component the file imports and the module's own names.\n const taken = new Set([component.name, 'meta', 'Story'])\n let first = true\n const story = (\n label: string,\n values: StoryValues,\n args: [string, es.SyntaxNode][],\n play?: es.SyntaxNode\n ) => {\n // Every story after the first, Default, is another state, tagged so Storybook can hide it.\n const variant = !first\n first = false\n return {\n name: claimName(identifierName(label, 'Story'), taken),\n values,\n story: es.object([\n ...(variant\n ? [['tags', es.array([es.string(VARIANT_TAG)])] as [string, es.SyntaxNode]]\n : []),\n ...(args.length > 0 ? [['args', es.object(args)] as [string, es.SyntaxNode]] : []),\n ...(play ? [['play', play] as [string, es.SyntaxNode]] : [])\n ])\n }\n }\n const { range } = component\n const boolean = !component.choice && !range && !component.text\n return [\n story('Default', {}, [], playOf(component)),\n ...(component.model && model && boolean\n ? [story(component.model, { [model]: true }, [[model, TRUE]])]\n : []),\n // A range gets a story at each end it does not start at.\n ...(range && model\n ? (\n [\n ['Minimum', range.min],\n ['Maximum', range.max]\n ] as const\n )\n .filter(([, value]) => value !== range.default)\n .map(([label, value]) =>\n story(label, { [model]: value }, [[model, numberArg(value, list)]])\n )\n : []),\n // A choice gets a story per option it does not start on, such as each other tab.\n ...(component.choice && model\n ? component.choice.options\n .filter((option) => option !== component.choice?.default)\n .map((option) => story(option, { [model]: option }, [[model, es.string(option)]]))\n : []),\n ...(component.disabled ? [story('Disabled', { disabled: true }, [['disabled', TRUE]])] : []),\n ...component.props.flatMap((prop) =>\n prop.options\n .filter((option) => option !== prop.default)\n .map((option) => story(option, { [prop.name]: option }, [[prop.name, es.string(option)]]))\n ),\n // A boolean gets a story drawn the other way, such as an icon shown that is hidden at rest.\n ...component.booleans.map((prop) =>\n story(`${prop.property} ${prop.default ? 'off' : 'on'}`, { [prop.name]: !prop.default }, [\n [prop.name, prop.default ? FALSE : TRUE]\n ])\n )\n ]\n}\n\n/** CSF3 stories for a generated component, with a play function that operates it. */\nexport function printComponentStories(data: ComponentStoriesData): string {\n const { component } = data\n const parameters =\n data.design.length > 0\n ? es.object([\n [\n 'design',\n es.array(\n data.design.map((entry) =>\n es.object([\n ['name', es.string(entry.name)],\n ['type', es.string(entry.type)],\n ['url', es.string(entry.url)]\n ])\n )\n )\n ]\n ])\n : es.OMIT\n const { entry, valueArg: model } = data.generated\n const list = data.generated.valueList ?? false\n const body = es.fill(MODULE, {\n $storybook: es.string(data.storybook),\n $Component: es.identifier(component.name),\n $title: es.string(data.title),\n $tags: es.array(data.tags.map(es.string)),\n $parameters: parameters,\n $args: es.object(restArgs(component, model, list)),\n $argTypes: argTypes(component, model, list)\n }).body\n const componentImport = es.fill(entry.named ? IMPORT_NAMED : IMPORT_DEFAULT, {\n $Component: es.identifier(component.name),\n $path: es.string(entry.path)\n }).body\n const all = componentStories(component, model, list)\n const kept = data.single ? all.slice(0, 1) : all\n // Each story's design image is a URL const, so Vite bundles the file it points at.\n const images = kept.flatMap((item, index) => {\n const path = data.designs?.get(item.name)\n return path\n ? es.fill(IMAGE, { $name: es.identifier(`design${index}`), $path: es.string(path) }).body\n : []\n })\n const exported = kept.flatMap((item, index) => {\n const parameters = es.object([\n [\n 'design',\n es.array([\n es.object([\n ['name', es.string('Design')],\n ['type', es.string('image')],\n ['url', es.identifier(`design${index}`)]\n ])\n ])\n ]\n ])\n const story = data.designs?.has(item.name)\n ? {\n ...item.story,\n properties: [\n ...es.children(item.story, 'properties'),\n {\n type: 'Property',\n kind: 'init',\n key: es.identifier('parameters'),\n value: parameters,\n computed: false,\n method: false,\n shorthand: false\n }\n ]\n }\n : item.story\n return es.fill(STORY, { $name: es.identifier(item.name), $story: story }).body\n })\n // Only a control with a play function uses `expect`.\n const [types, expectImport, ...rest] = body\n const imports = playOf(component) ? [types, expectImport] : [types]\n const module = es.printModule({\n type: 'Program',\n sourceType: 'module',\n body: compact([\n ...imports,\n ...stylesheets(data.styles),\n ...componentImport,\n ...rest,\n ...images,\n ...exported\n ])\n })\n return `${HEADER}\\n${module}\\n`\n}\n"],"mappings":";;;;;AAIA,MAAa,uBAAuB;CAAC;CAAS;CAAO;AAAM;;AAI3D,MAAMA,WAAS;AAgDf,MAAMC,WAAS,GAAG,YAAY,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;CAyBnC;AAED,MAAM,UAAU,GAAG,YAAY,MAAM;;;;;;;;;;;;;;;;;;;;CAoBpC;AAED,MAAMC,UAAQ,GAAG,YAAY,oDAAoD;AACjF,MAAMC,UAAQ,GAAG,YAAY,oCAAoC;AACjE,MAAM,aAAa,GAAG,YAAY,gBAAgB;;AAGlD,MAAa,qBAAyD;CACpE,OAAO;CACP,KAAK;CACL,MAAM;AACR;;AAGA,MAAM,aACJ;CACE,OAAO;EACL,SAAS,GAAG,YAAY,uCAAuC,CAAC,CAAC;EACjE,QAAQ,GAAG,gBACT,sEACF;CACF;CACA,KAAK;EACH,SAAS,GAAG,YAAY,yBAAyB,CAAC,CAAC;EACnD,QAAQ,GAAG,gBAAgB,uDAAuD;CACpF;CACA,MAAM;EACJ,SAAS,CAAC;EACV,QAAQ,GAAG,gBAAgB,OAAO;CACpC;AACF;AAEF,MAAM,YAAY,WAA+B,SAC/C,GAAG,KAAK,WAAW,UAAU,CAAC,QAAQ,EAAE,OAAO,GAAG,gBAAgB,IAAI,EAAE,CAAC;AAE3E,MAAM,aAAa,YAAoB,S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CAAC;CACD,OAAO,GAAG,OAAO,IAAI,OAAO;AAC9B"}
@@ -4,7 +4,7 @@ import { designFontRequests, fontFaceStylesheet } from "../bundle.js";
4
4
  import { behaviourArgs } from "../../behaviours/args.js";
5
5
  import { VARIANT_TAG, claimName, fileTags, identifierName, storyId } from "../../behaviours/states/css.js";
6
6
  import { componentModel, reactComponent, vueComponent } from "../components/layers.js";
7
- import { STORYBOOK_PACKAGES, printComponentStories, printStoryModule } from "./component.js";
7
+ import { STORYBOOK_PACKAGES, componentStories, printComponentStories, printStoryModule } from "./component.js";
8
8
  import { compact, uniq } from "es-toolkit/array";
9
9
  import { omit } from "es-toolkit/object";
10
10
  import { restingVariant } from "@pairdraw/scene-graph/components";
@@ -277,6 +277,24 @@ function storyEntries(graph, { pageId, document, plan }) {
277
277
  return entries;
278
278
  }
279
279
  /**
280
+ * The variant a generated component's story draws: the one whose variant property values match
281
+ * the story's args over the component's rest values. A state no single variant draws, such as
282
+ * a text field's words, has none.
283
+ */
284
+ function variantForStory(group, component, values) {
285
+ const args = component.args;
286
+ const shown = (story) => {
287
+ const record = {};
288
+ for (const prop of component.props) record[prop.property] = String(story[prop.name] ?? prop.default);
289
+ for (const [property, boolean] of args.booleans) record[property] = story[boolean.name] ?? false ? boolean.on : boolean.off;
290
+ if (args.states) record[args.states.property] = story["disabled"] === true && args.states.disabled !== void 0 ? args.states.disabled : args.states.rest;
291
+ if (args.filled) record[args.filled.property] = args.filled.off;
292
+ return record;
293
+ };
294
+ const target = shown(values);
295
+ return group.variants.find((variant) => Object.entries(target).every(([property, value]) => variant.node.componentPropertyValues[property] === value));
296
+ }
297
+ /**
280
298
  * The component each entry's set generates, by set id, built twice: first alone, so each
281
299
  * knows its props, then knowing all the others, so an instance of one uses it rather than
282
300
  * drawing its layers.
@@ -340,6 +358,41 @@ async function storyTokens(graph, folder) {
340
358
  content: css
341
359
  }] : [];
342
360
  }
361
+ /** A generated component's files: its component, design images, and state stories. */
362
+ async function addGeneratedStories(component, generate, { options, framework, uniqueNames, styles, add, entry }) {
363
+ const { page, group, file, mode } = entry;
364
+ const generated = await generate(component, { styling: options.styling });
365
+ for (const item of generated.files) add(page, item.path, item.content);
366
+ const design = designLink({
367
+ linkPath: options.linkPath,
368
+ uniqueNames
369
+ }, group.linkNode);
370
+ const states = componentStories(component, generated.valueArg, generated.valueList ?? false).slice(0, mode === "single" ? 1 : void 0);
371
+ const designs = /* @__PURE__ */ new Map();
372
+ const render = options.renderDesignImage;
373
+ if (render) for (const state of states) {
374
+ const variant = variantForStory(group, component, state.values);
375
+ if (!variant) continue;
376
+ const path = `${file}.design/${state.name}.png`;
377
+ add(page, path, await render(variant.node.id));
378
+ designs.set(state.name, `./${path}`);
379
+ }
380
+ add(page, `${file}.stories.ts`, printComponentStories({
381
+ storybook: STORYBOOK_PACKAGES[framework],
382
+ title: group.title,
383
+ tags: fileTags(group.page.name),
384
+ styles,
385
+ component,
386
+ generated,
387
+ single: mode === "single",
388
+ design: design.flatMap((link) => link.type === "link" ? [{
389
+ name: "Pairdraw",
390
+ type: "link",
391
+ url: link.url
392
+ }] : []),
393
+ designs
394
+ }));
395
+ }
343
396
  /**
344
397
  * Generate one CSF3 `.stories.ts` file per component or component set, plus a
345
398
  * `<Name>.design/` folder of variant images when `renderDesignImage` is given.
@@ -361,29 +414,18 @@ async function exportStorybook(graph, options = {}) {
361
414
  const styles = shared.filter((file) => file.path.endsWith(".css")).map((file) => `./${file.path}`);
362
415
  const generate = GENERATORS[framework];
363
416
  const models = generate ? generatedModels(graph, entries, options.vectorElement) : /* @__PURE__ */ new Map();
364
- for (const { page, group, file, mode } of entries) {
417
+ for (const entry of entries) {
418
+ const { page, group, file, mode } = entry;
365
419
  const component = group.set && models.get(group.set.id);
366
420
  if (generate && component) {
367
- const generated = await generate(component, { styling: options.styling });
368
- for (const item of generated.files) add(page, item.path, item.content);
369
- const design = designLink({
370
- linkPath: options.linkPath,
371
- uniqueNames
372
- }, group.linkNode);
373
- add(page, `${file}.stories.ts`, printComponentStories({
374
- storybook: STORYBOOK_PACKAGES[framework],
375
- title: group.title,
376
- tags: fileTags(group.page.name),
421
+ await addGeneratedStories(component, generate, {
422
+ options,
423
+ framework,
424
+ uniqueNames,
377
425
  styles,
378
- component,
379
- generated,
380
- single: mode === "single",
381
- design: design.flatMap((entry) => entry.type === "link" ? [{
382
- name: "Pairdraw",
383
- type: "link",
384
- url: entry.url
385
- }] : [])
386
- }));
426
+ add,
427
+ entry
428
+ });
387
429
  continue;
388
430
  }
389
431
  const names = storyNames(group).slice(0, mode === "variants" ? void 0 : 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 = 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;AAEA,SAAS,kBACP,OACA,MACA,SACA,KACY;CACZ,MAAM,cAAc,IAAI,6BAA6B,QAAQ,QAAQ,IAAI,SAAS,SAAS;CAE3F,MAAM,QAAQ,eAAe,OAAO,GAAG;CACvC,MAAM,aAAa,MAChB,YAAY,IAAI,EAAE,CAAC,CACnB,QAAQ,UAAU,MAAM,SAAS,eAAe,WAAW,KAAK,CAAC;CACpE,MAAM,WAAW,CACf,GAAG,WAAW,QAAQ,cAAc,cAAc,KAAK,GACvD,GAAG,WAAW,QAAQ,cAAc,cAAc,KAAK,CACzD,CAAC,CAAC,KAAK,eAAe;EACpB,QAAQ,YAAY,KAAK,QAAQ,UAAU,wBAAwB,IAAI,SAAS,EAAE;EAClF,MAAM;CACR,EAAE;CACF,MAAM,OAAO,cAAc,OAAO,GAAG;CACrC,MAAM,QAAQ,YAAY,KAAK,KAAK,UAAqB;EACvD,MAAM,UAAU,KAAK,CACnB,GAAI,IAAI,kBAAkB,C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,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,EAAE;EACF,OAAO,CAAC;GAAE,MAAM;GAAW,SAAS,CAAC,GAAG,KAAK;EAAE,CAAC;CAClD;AACF;AAEA,SAAS,kBACP,OACA,MACA,SACA,KACY;CACZ,MAAM,cAAc,IAAI,6BAA6B,QAAQ,QAAQ,IAAI,SAAS,SAAS;CAE3F,MAAM,QAAQ,eAAe,OAAO,GAAG;CACvC,MAAM,aAAa,MAChB,YAAY,IAAI,EAAE,CAAC,CACnB,QAAQ,UAAU,MAAM,SAAS,eAAe,WAAW,KAAK,CAAC;CACpE,MAAM,WAAW,CACf,GAAG,WAAW,QAAQ,cAAc,cAAc,KAAK,GACvD,GAAG,WAAW,QAAQ,cAAc,cAAc,KAAK,CACzD,CAAC,CAAC,KAAK,eAAe;EACpB,QAAQ,YAAY,KAAK,QAAQ,UAAU,wBAAwB,IAAI,SAAS,EAAE;EAClF,MAAM;CACR,EAAE;CACF,MAAM,OAAO,cAAc,OAAO,GAAG;CACrC,MAAM,QAAQ,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