@pairdraw/dom-css 0.0.0-stage → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +219 -2
  3. package/dist/browser.d.ts +29 -0
  4. package/dist/browser.js +2 -0
  5. package/dist/chunks/behaviours/args.js +59 -0
  6. package/dist/chunks/behaviours/args.js.map +1 -0
  7. package/dist/chunks/behaviours/controls.js +109 -0
  8. package/dist/chunks/behaviours/controls.js.map +1 -0
  9. package/dist/chunks/behaviours/reset.js +40 -0
  10. package/dist/chunks/behaviours/reset.js.map +1 -0
  11. package/dist/chunks/behaviours/roles.js +51 -0
  12. package/dist/chunks/behaviours/roles.js.map +1 -0
  13. package/dist/chunks/behaviours/states/conditions.js +103 -0
  14. package/dist/chunks/behaviours/states/conditions.js.map +1 -0
  15. package/dist/chunks/behaviours/states/css.js +172 -0
  16. package/dist/chunks/behaviours/states/css.js.map +1 -0
  17. package/dist/chunks/behaviours/states/layers.js +1736 -0
  18. package/dist/chunks/behaviours/states/layers.js.map +1 -0
  19. package/dist/chunks/behaviours/states/model.js +144 -0
  20. package/dist/chunks/behaviours/states/model.js.map +1 -0
  21. package/dist/chunks/behaviours/states/tailwind.js +198 -0
  22. package/dist/chunks/behaviours/states/tailwind.js.map +1 -0
  23. package/dist/chunks/browser.js +1352 -0
  24. package/dist/chunks/browser.js.map +1 -0
  25. package/dist/chunks/export/bundle.js +337 -0
  26. package/dist/chunks/export/bundle.js.map +1 -0
  27. package/dist/chunks/export/components/drawn.js +60 -0
  28. package/dist/chunks/export/components/drawn.js.map +1 -0
  29. package/dist/chunks/export/components/fields.js +178 -0
  30. package/dist/chunks/export/components/fields.js.map +1 -0
  31. package/dist/chunks/export/components/groups.js +297 -0
  32. package/dist/chunks/export/components/groups.js.map +1 -0
  33. package/dist/chunks/export/components/icons.js +260 -0
  34. package/dist/chunks/export/components/icons.js.map +1 -0
  35. package/dist/chunks/export/components/layers.js +1594 -0
  36. package/dist/chunks/export/components/layers.js.map +1 -0
  37. package/dist/chunks/export/index.js +477 -0
  38. package/dist/chunks/export/index.js.map +1 -0
  39. package/dist/chunks/export/storybook/component.js +448 -0
  40. package/dist/chunks/export/storybook/component.js.map +1 -0
  41. package/dist/chunks/export/storybook/export.js +410 -0
  42. package/dist/chunks/export/storybook/export.js.map +1 -0
  43. package/dist/chunks/import/html.js +406 -0
  44. package/dist/chunks/import/html.js.map +1 -0
  45. package/dist/chunks/import/jsx/dev-runtime.js +37 -0
  46. package/dist/chunks/import/jsx/dev-runtime.js.map +1 -0
  47. package/dist/chunks/tokens/cssom-validator.js +10 -0
  48. package/dist/chunks/tokens/cssom-validator.js.map +1 -0
  49. package/dist/export.d.ts +594 -0
  50. package/dist/export.js +13 -0
  51. package/dist/index.d.ts +115 -0
  52. package/dist/index.js +7 -0
  53. package/dist/jsx-dev-runtime.d.ts +8 -0
  54. package/dist/jsx-dev-runtime.js +3 -0
  55. package/dist/jsx-runtime.d.ts +20 -0
  56. package/dist/jsx-runtime.js +3 -0
  57. package/dist/rolldown-runtime.js +13 -0
  58. package/dist/runtime.d.ts +10 -0
  59. package/dist/scene-graph.d.ts +2 -0
  60. package/dist/scene-graph.js +2 -0
  61. package/dist/scene-graph2.d.ts +10 -0
  62. package/dist/styling.d.ts +93 -0
  63. package/dist/tailwind.d.ts +39 -0
  64. package/dist/types.d.ts +89 -0
  65. package/package.json +73 -4
  66. package/src/behaviours/args.ts +85 -0
  67. package/src/behaviours/controls.ts +195 -0
  68. package/src/behaviours/index.ts +11 -0
  69. package/src/behaviours/reset.ts +37 -0
  70. package/src/behaviours/roles.ts +44 -0
  71. package/src/behaviours/states/conditions.ts +105 -0
  72. package/src/behaviours/states/css.ts +123 -0
  73. package/src/behaviours/states/index.ts +4 -0
  74. package/src/behaviours/states/layers.ts +205 -0
  75. package/src/behaviours/states/model.ts +175 -0
  76. package/src/behaviours/states/names.ts +39 -0
  77. package/src/behaviours/states/tailwind.ts +148 -0
  78. package/src/behaviours/states/types.ts +56 -0
  79. package/src/browser.ts +146 -0
  80. package/src/cssom.d.ts +38 -0
  81. package/src/export/bundle.ts +461 -0
  82. package/src/export/components/drawn.ts +73 -0
  83. package/src/export/components/fields.ts +178 -0
  84. package/src/export/components/groups.ts +78 -0
  85. package/src/export/components/icons.ts +230 -0
  86. package/src/export/components/layers.ts +121 -0
  87. package/src/export/components/model.ts +544 -0
  88. package/src/export/components/properties.ts +167 -0
  89. package/src/export/components/react/fields.ts +129 -0
  90. package/src/export/components/react/index.ts +606 -0
  91. package/src/export/components/react/shared.ts +76 -0
  92. package/src/export/components/references.ts +212 -0
  93. package/src/export/components/repeats.ts +128 -0
  94. package/src/export/components/shaders.ts +125 -0
  95. package/src/export/components/styling.ts +31 -0
  96. package/src/export/components/tree.ts +72 -0
  97. package/src/export/components/vue.ts +517 -0
  98. package/src/export/css.ts +57 -0
  99. package/src/export/grid.ts +42 -0
  100. package/src/export/html.ts +163 -0
  101. package/src/export/index.ts +44 -0
  102. package/src/export/projection.ts +581 -0
  103. package/src/export/storybook/component.ts +334 -0
  104. package/src/export/storybook/export.ts +430 -0
  105. package/src/export/storybook/groups.ts +161 -0
  106. package/src/export/storybook/module.ts +319 -0
  107. package/src/export/storybook/names.ts +51 -0
  108. package/src/export/tailwind-jsx.ts +156 -0
  109. package/src/export/text.ts +415 -0
  110. package/src/import/css-text.ts +4 -0
  111. package/src/import/css-values.ts +31 -0
  112. package/src/import/flow.ts +248 -0
  113. package/src/import/html.ts +88 -0
  114. package/src/import/jsx/core.ts +130 -0
  115. package/src/import/jsx/dev-runtime.ts +8 -0
  116. package/src/import/jsx/runtime.ts +76 -0
  117. package/src/import/scene-graph.ts +582 -0
  118. package/src/import/style-attribute.ts +25 -0
  119. package/src/import/tailwind.ts +54 -0
  120. package/src/import/text.ts +518 -0
  121. package/src/index.ts +51 -0
  122. package/src/runtime/browser/runtime.ts +301 -0
  123. package/src/runtime/headless/runtime.ts +99 -0
  124. package/src/runtime/headless/styles.ts +330 -0
  125. package/src/runtime/index.ts +11 -0
  126. package/src/tokens/conditions.ts +66 -0
  127. package/src/tokens/cssom-validator.ts +8 -0
  128. package/src/tokens/custom-properties.ts +331 -0
  129. package/src/tokens/expression.ts +128 -0
  130. package/src/tokens/formula.ts +140 -0
  131. package/src/tokens/index.ts +43 -0
  132. package/src/tokens/names.ts +161 -0
  133. package/src/tokens/references.ts +201 -0
  134. package/src/tokens/stylesheet.ts +304 -0
  135. package/src/tokens/validate.ts +86 -0
  136. package/src/tokens/values.ts +44 -0
  137. package/src/types.ts +59 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groups.js","names":[],"sources":["../../../../src/export/components/references.ts","../../../../src/export/components/repeats.ts","../../../../src/export/components/groups.ts"],"sourcesContent":["import { layerKind } from '#dom-css/behaviours/states/layers'\nimport type { StateElement } from '#dom-css/behaviours/states/types'\nimport type { DesignStyleDeclaration } from '#dom-css/types'\nimport { isEmptyObject } from 'es-toolkit/predicate'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { behaviourOwner, findLayerByPath } from '@pairdraw/scene-graph/behaviours'\nimport { findComponentPropertyTargets } from '@pairdraw/scene-graph/components'\nimport { isIconModified, isNamedIcon, readIcon } from '@pairdraw/scene-graph/icons'\nimport { instanceMainComponent } from '@pairdraw/scene-graph/instances'\n\nimport { drawsAsMain } from './drawn'\nimport type { ComponentModel } from './model'\n\n/** A prop a reference sets on the component it uses: a variant or text value, or `disabled`. */\ninterface ReferenceProp {\n name: string\n value: string | boolean\n}\n\n/**\n * Another generated component used where the design places an instance of it, with the values\n * the instance shows. Its own layers are the component's, so they are not drawn here.\n */\nexport interface ComponentReference {\n type: 'reference'\n /** The layer it draws, which code links back to. */\n layerId?: string\n /** The component's identifier and file name. */\n component: string\n /** The class the parent's state styles place it by. */\n className: string\n props: ReferenceProp[]\n /** The two-way value the instance is drawn with, when it is on. */\n model: string | null\n}\n\n/** An icon from a set, drawn by the framework's Iconify component. */\nexport interface IconReference {\n type: 'icon'\n /** The layer it draws, which code links back to. */\n layerId?: string\n /** `prefix:name`. */\n icon: string\n className: string\n}\n\n/**\n * How a parent places a layer, as opposed to how the layer looks. A component used in place of\n * a layer keeps its own look and state styles; the parent only places it.\n */\nconst PLACEMENT =\n /^(position|inset|left|top|right|bottom|(min-|max-)?(width|height)|margin(-.+)?|flex(-(grow|shrink|basis))?|align-self|justify-self|order|grid-(area|column|row)(-.+)?|transform(-origin)?|rotate|translate|scale|z-index)$/\n\n/** Whether a declaration places a layer rather than drawing it. */\nexport const isPlacement = (property: string) => PLACEMENT.test(property)\n\n/** Whether a declaration hides or shows a layer by state, which the parent decides too. */\nconst isVisibility = (property: string, value: string) =>\n property === 'display' && (value === 'none' || value === 'revert')\n\n/** Keeps only where the parent places a layer, and whether a state shows it. */\nexport function placementOnly(element: StateElement): void {\n const placement = (style: DesignStyleDeclaration): DesignStyleDeclaration =>\n Object.fromEntries(\n Object.entries(style).filter(\n ([property, value]) => isPlacement(property) || isVisibility(property, value)\n )\n )\n element.base = placement(element.base)\n element.rules = element.rules\n .map((rule) => ({ ...rule, style: placement(rule.style) }))\n .filter((rule) => !isEmptyObject(rule.style))\n}\n\n/** Generated components by the id of the set they come from, which instances refer to. */\nexport type ComponentReferences = ReadonlyMap<string, ComponentModel>\n\n/** The set a component belongs to, or the component itself when it stands alone. */\nfunction ownerId(graph: SceneGraph, component: SceneNode): string {\n const parent = component.parentId ? graph.getNode(component.parentId) : undefined\n return parent?.type === 'COMPONENT_SET' ? parent.id : component.id\n}\n\n/**\n * The words an instance shows for a text property: an assignment that overrides the default,\n * else what its bound text layer reads, which a direct edit changes, else the assignment.\n */\nexport function shownText(\n graph: SceneGraph,\n instance: SceneNode,\n propertyId: string\n): string | undefined {\n const assigned = instance.componentPropertyAssignments[propertyId]\n const main = instanceMainComponent(graph, instance)\n const owner = main && behaviourOwner(graph, main)\n const definition = owner?.componentPropertyDefinitions.find((item) => item.id === propertyId)\n if (typeof assigned === 'string' && assigned !== definition?.defaultValue) return assigned\n const target = findComponentPropertyTargets(graph, instance, propertyId).find(\n (item) => item.field === 'TEXT' && item.node.type === 'TEXT'\n )\n return target?.node.text ?? (typeof assigned === 'string' ? assigned : undefined)\n}\n\n/**\n * What `instance` sets on `component`: the values it is drawn with that differ from defaults,\n * and whether it is drawn on: its model, or for a group's item the value that marks it chosen.\n */\nexport function referenceValues(\n graph: SceneGraph,\n instance: SceneNode,\n component: ComponentModel\n): Pick<ComponentReference, 'props' | 'model'> {\n const values = instanceMainComponent(graph, instance)?.componentPropertyValues ?? {}\n const props: ReferenceProp[] = []\n let model: string | null = null\n for (const [property, arg] of component.args.booleans) {\n if (values[property] !== arg.on) continue\n const on = arg.name === component.model || (component.valueProp && arg.name !== 'disabled')\n if (on) model = arg.name\n else props.push({ name: arg.name, value: true })\n }\n const states = component.args.states\n if (states?.disabled && values[states.property] === states.disabled)\n props.push({ name: 'disabled', value: true })\n for (const prop of component.props) {\n const value = values[prop.property]\n if (Object.hasOwn(values, prop.property) && value !== prop.default)\n props.push({ name: prop.name, value })\n }\n for (const text of component.texts) {\n const value = shownText(graph, instance, text.id)\n if (value !== undefined && value !== text.default) props.push({ name: text.name, value })\n }\n for (const prop of component.booleans) {\n const assignments = instance.componentPropertyAssignments\n const value = Object.hasOwn(assignments, prop.id)\n ? assignments[prop.id] === 'true'\n : prop.default\n if (value !== prop.default) props.push({ name: prop.name, value })\n }\n return { props, model }\n}\n\n/** A used layer, before the parent's class name for it is known. */\nexport type UsedLayer = Omit<ComponentReference, 'className'> | Omit<IconReference, 'className'>\n\n/**\n * What the layer at `element` uses in place of drawing itself, if anything, read from the first\n * variant that draws it as that element: the rest state, or the one that shows it, such as open\n * content.\n */\nfunction usedLayer(\n graph: SceneGraph,\n variantIds: readonly string[],\n element: StateElement,\n references: ComponentReferences\n): UsedLayer | null {\n const path = element.key.split('\\0')[0] ?? ''\n // The variant's layer at that path drawn as this element is: a frame, or that instance or icon.\n const node = variantIds\n .map((id) => findLayerByPath(graph, id, path))\n .find((found) => found !== undefined && layerKind(graph, found) === element.kind)\n if (!node) return null\n const main = node.type === 'INSTANCE' ? instanceMainComponent(graph, node) : undefined\n // An instance changed beyond its properties draws its own layers, which the component's\n // props could not reproduce.\n const component =\n main && drawsAsMain(graph, node, main) ? references.get(ownerId(graph, main)) : undefined\n if (component)\n return {\n type: 'reference',\n component: component.name,\n ...referenceValues(graph, node, component)\n }\n const icon = readIcon(node)\n return icon && isNamedIcon(icon) && !isIconModified(graph, node)\n ? { type: 'icon', icon: icon.name }\n : null\n}\n\n/**\n * The layers of a set's merged markup that are used rather than drawn: instances of other\n * generated components, and icons from a set, read from the variants in order, the rest state\n * first. Their own layers are dropped from the markup and the styles, which belong to the\n * component or the icon.\n */\nexport function referencedLayers(\n graph: SceneGraph,\n root: StateElement,\n variantIds: readonly string[],\n references: ComponentReferences,\n /** Layers already used otherwise, such as a group's items. */\n taken: ReadonlyMap<StateElement, unknown> = new Map()\n): Map<StateElement, UsedLayer> {\n const used = new Map<StateElement, UsedLayer>()\n const visit = (element: StateElement) => {\n for (const child of element.children) {\n if (child.type !== 'element' || taken.has(child)) continue\n const layer = usedLayer(graph, variantIds, child, references)\n if (!layer) {\n visit(child)\n continue\n }\n used.set(child, layer)\n child.children = []\n if (layer.type === 'reference') placementOnly(child)\n }\n }\n visit(root)\n return used\n}\n","import { difference } from '#dom-css/behaviours/states/model'\nimport type { StateElement, StateNode } from '#dom-css/behaviours/states/types'\nimport type { DesignStyleDeclaration } from '#dom-css/types'\nimport { isEmptyObject } from 'es-toolkit/predicate'\nimport { kebabCase } from 'es-toolkit/string'\n\nimport { claimName } from '../storybook/names'\nimport { isPlacement } from './references'\n\n/** A layer drawn once per value, such as a tab's trigger or its panel, and the value it is. */\nexport interface RepeatedPart {\n part: string\n value: string\n}\n\n/**\n * The string a component chooses among, such as the open tab, and the one it starts on, or\n * none, as a radio group with no item chosen.\n */\nexport interface ChoiceModel {\n options: string[]\n default: string | null\n}\n\n/** The words a layer reads, joined across its text. */\nexport function textOf(node: StateNode): string {\n if (node.type === 'text') return node.text\n return node.children.map(textOf).join(' ')\n}\n\nconst elementsOf = (element: StateElement | undefined) =>\n (element?.children ?? []).filter((child): child is StateElement => child.type === 'element')\n\n/**\n * The value each label stands for: the label as a slug, such as `account`, apart from the\n * others, or its position when it has no words.\n */\nexport function slugValues(labels: readonly string[]): string[] {\n const taken = new Set<string>()\n return labels.map((label, index) => claimName(kebabCase(label) || String(index), taken))\n}\n\n/**\n * Tabs' triggers, the layers in its list, and its panels, the layers in its panels slot, each\n * with the value of the tab it belongs to, matched by position. The tabs start on the first.\n */\nexport function tabParts(parts: ReadonlyMap<StateElement, string>): {\n repeated: Map<StateElement, RepeatedPart>\n choice: ChoiceModel | null\n} {\n const partElement = (id: string) => [...parts].find(([, part]) => part === id)?.[0]\n const triggers = elementsOf(partElement('list'))\n const values = slugValues(triggers.map(textOf))\n const repeated = new Map<StateElement, RepeatedPart>()\n for (const [index, trigger] of triggers.entries())\n repeated.set(trigger, { part: 'trigger', value: values[index] ?? String(index) })\n for (const [index, panel] of elementsOf(partElement('panels')).entries()) {\n const value = values.at(index)\n if (value !== undefined) repeated.set(panel, { part: 'content', value })\n }\n const first = values.at(0)\n return { repeated, choice: first === undefined ? null : { options: values, default: first } }\n}\n\n/** How `drawn` looks different from `base`, leaving out where each is placed. */\nfunction lookChange(\n base: DesignStyleDeclaration,\n drawn: DesignStyleDeclaration\n): DesignStyleDeclaration {\n const changed = Object.entries(difference(base, drawn))\n return Object.fromEntries(changed.filter(([property]) => !isPlacement(property)))\n}\n\n/** `base` with `change` applied, where `unset` drops a declaration. */\nfunction applied(\n base: DesignStyleDeclaration,\n change: DesignStyleDeclaration\n): DesignStyleDeclaration {\n return Object.fromEntries([\n ...Object.entries(base).filter(([property]) => change[property] !== 'unset'),\n ...Object.entries(change).filter(([, value]) => value !== 'unset')\n ])\n}\n\n/** The layer of `into` where `from` has `child`: the same name, and the same one of that name. */\nfunction counterpart(\n child: StateElement,\n from: StateElement,\n into: StateElement\n): StateElement | undefined {\n const named = (element: StateElement) =>\n elementsOf(element).filter((item) => item.name === child.name)\n return named(into).at(named(from).indexOf(child))\n}\n\n/**\n * Tabs draw the first trigger chosen and the others not. Every trigger rests with the look of\n * the others and takes the first one's, layer by layer, while Reka or Radix marks it active;\n * each keeps its own place. A layer is matched across triggers by name, and one without a\n * counterpart keeps its own styles.\n */\nexport function activeTriggers(repeated: ReadonlyMap<StateElement, RepeatedPart>): void {\n const triggers = [...repeated].filter(([, item]) => item.part === 'trigger').map(([el]) => el)\n const first = triggers.at(0)\n const second = triggers.at(1)\n if (!first || !second) return\n // The two looks as drawn, before the first trigger rests with the others' look.\n const [active, inactive] = structuredClone([first, second])\n for (const trigger of triggers) {\n const visit = (layer: StateElement, drawn: StateElement, other: StateElement) => {\n if (trigger === first) layer.base = applied(layer.base, lookChange(drawn.base, other.base))\n // From the layer's own rest, so a trigger drawn apart still takes the chosen look.\n const look = lookChange(layer.base, drawn.base)\n if (!isEmptyObject(look))\n layer.rules.push({\n conditions: [{ type: 'state', value: 'active' }],\n on: trigger,\n style: look\n })\n for (const child of elementsOf(layer)) {\n const drawnChild = counterpart(child, layer, drawn)\n const otherChild = counterpart(child, layer, other)\n if (drawnChild && otherChild) visit(child, drawnChild, otherChild)\n }\n }\n visit(trigger, active, inactive)\n }\n}\n","import type { StateElement } from '#dom-css/behaviours/states/types'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { behaviourOwner, findLayerByPath } from '@pairdraw/scene-graph/behaviours'\nimport { instanceMainComponent } from '@pairdraw/scene-graph/instances'\n\nimport type { ComponentModel } from './model'\nimport { placementOnly, referenceValues, shownText, type UsedLayer } from './references'\nimport { slugValues, textOf, type ChoiceModel } from './repeats'\n\n/** Groups whose items are their own primitive inside the group, as Reka and Radix have them. */\nexport const GROUP_ITEMS = {\n radioGroup: 'radioGroupItem',\n toggleGroup: 'toggleGroupItem',\n accordion: 'accordionItem'\n} as const\n\nexport type GroupKind = keyof typeof GROUP_ITEMS\nexport type ItemKind = (typeof GROUP_ITEMS)[GroupKind]\n\nexport const isGroup = (kind: string): kind is GroupKind => Object.hasOwn(GROUP_ITEMS, kind)\n\n/** Builds the component of a group's items, named for the group. */\nexport type ItemBuilder = (owner: SceneNode) => ComponentModel | null\n\n/**\n * A group's items: the component they share, generated as the group's item primitive, and\n * each item in the items slot as a use of it with the value it stands for. The group chooses\n * among those values, starting on the item the design draws on, or none.\n */\nexport function groupItems(\n graph: SceneGraph,\n variantIds: readonly string[],\n itemsElement: StateElement | undefined,\n build: ItemBuilder\n): { item: ComponentModel; used: Map<StateElement, UsedLayer>; choice: ChoiceModel } | null {\n const elements = (itemsElement?.children ?? []).filter(\n (child): child is StateElement => child.type === 'element'\n )\n const instances = elements.map((element) => {\n const path = element.key.split('\\0')[0] ?? ''\n const node = variantIds\n .map((id) => findLayerByPath(graph, id, path))\n .find((found) => found?.type === 'INSTANCE')\n const main = node && instanceMainComponent(graph, node)\n return node && main ? { node, owner: behaviourOwner(graph, main) } : null\n })\n const owner = instances.find((instance) => instance?.owner)?.owner\n const item = owner && build(owner)\n if (!owner || !item) return null\n\n // An item is named by its label property when it has one, else by the words it reads.\n const label = item.texts.at(0)\n const values = slugValues(\n elements.map((element, index) => {\n const node = instances[index]?.node\n return (label && node && shownText(graph, node, label.id)) || textOf(element)\n })\n )\n const used = new Map<StateElement, UsedLayer>()\n let chosen: string | null = null\n for (const [index, element] of elements.entries()) {\n const instance = instances[index]\n const value = values.at(index)\n if (instance?.owner?.id !== owner.id || value === undefined) continue\n const { props, model } = referenceValues(graph, instance.node, item)\n if (model) chosen ??= value\n used.set(element, {\n type: 'reference',\n component: item.name,\n props: [{ name: 'value', value }, ...props],\n model: null\n })\n element.children = []\n placementOnly(element)\n }\n return { item, used, choice: { options: values, default: chosen } }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmDA,MAAM,YACJ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OAAO,CAAC;IAAE,MAAM;IAAS;GAAM,GAAG,GAAG,KAAK;GAC1C,OAAO;EACT,CAAC;EACD,QAAQ,WAAW,CAAC;EACpB,cAAc,OAAO;CACvB;CACA,OAAO;EAAE;EAAM;EAAM,QAAQ;GAAE,SAAS;GAAQ,SAAS;EAAO;CAAE;AACpE"}
@@ -0,0 +1,260 @@
1
+ import { claimName } from "../../behaviours/states/css.js";
2
+ import { groupBy } from "es-toolkit/array";
3
+ import { upperFirst } from "es-toolkit/string";
4
+ import { es } from "@pairdraw/emit";
5
+ //#region src/export/components/icons.ts
6
+ /**
7
+ * Where generated components take their icons from: Iconify, which draws every set, or one
8
+ * set's own package. An icon the chosen package does not have stays an Iconify icon.
9
+ */
10
+ const ICON_PACKAGES = [
11
+ "iconify",
12
+ "lucide",
13
+ "heroicons",
14
+ "react-icons",
15
+ "fontawesome"
16
+ ];
17
+ function isIconPackage(value) {
18
+ return ICON_PACKAGES.some((id) => id === value);
19
+ }
20
+ /** The packages a framework's components can take icons from; react-icons is React's alone. */
21
+ function iconPackagesFor(framework) {
22
+ return ICON_PACKAGES.filter((id) => id !== "react-icons" || framework === "react");
23
+ }
24
+ /** `arrow-down-0-1` → `ArrowDown01`, as the icon packages name their exports. */
25
+ function pascalName(name) {
26
+ return name.split("-").filter((part) => part.length > 0).map(upperFirst).join("");
27
+ }
28
+ const one = (source, imported) => ({
29
+ source,
30
+ imported,
31
+ local: imported
32
+ });
33
+ function lucide(name, framework) {
34
+ return one(framework === "react" ? "lucide-react" : "lucide-vue-next", `Lucide${pascalName(name)}`);
35
+ }
36
+ /** Heroicons 2 names on Iconify: `x` outline, `x-solid`, `x-20-solid` mini, `x-16-solid` micro. */
37
+ const HEROICON_STYLES = [
38
+ {
39
+ suffix: "-20-solid",
40
+ folder: "20/solid",
41
+ reactIcons: "HiMini"
42
+ },
43
+ {
44
+ suffix: "-16-solid",
45
+ folder: "16/solid",
46
+ reactIcons: "HiMicro"
47
+ },
48
+ {
49
+ suffix: "-solid",
50
+ folder: "24/solid",
51
+ reactIcons: "Hi"
52
+ }
53
+ ];
54
+ function heroicon(name) {
55
+ const style = HEROICON_STYLES.find(({ suffix }) => name.endsWith(suffix));
56
+ if (!style) return {
57
+ base: name,
58
+ folder: "24/outline",
59
+ reactIcons: "HiOutline"
60
+ };
61
+ return {
62
+ base: name.slice(0, -style.suffix.length),
63
+ ...style
64
+ };
65
+ }
66
+ /** Iconify sets that `react-icons` ships, by the module and the prefix of its export names. */
67
+ const REACT_ICONS_SETS = {
68
+ lucide: {
69
+ module: "lu",
70
+ prefix: "Lu"
71
+ },
72
+ tabler: {
73
+ module: "tb",
74
+ prefix: "Tb"
75
+ },
76
+ feather: {
77
+ module: "fi",
78
+ prefix: "Fi"
79
+ },
80
+ ri: {
81
+ module: "ri",
82
+ prefix: "Ri"
83
+ },
84
+ bi: {
85
+ module: "bs",
86
+ prefix: "Bs"
87
+ },
88
+ ph: {
89
+ module: "pi",
90
+ prefix: "Pi"
91
+ },
92
+ "radix-icons": {
93
+ module: "rx",
94
+ prefix: "Rx"
95
+ },
96
+ "simple-icons": {
97
+ module: "si",
98
+ prefix: "Si"
99
+ },
100
+ "fa6-solid": {
101
+ module: "fa6",
102
+ prefix: "Fa"
103
+ },
104
+ "fa6-brands": {
105
+ module: "fa6",
106
+ prefix: "Fa"
107
+ },
108
+ "fa6-regular": {
109
+ module: "fa6",
110
+ prefix: "FaReg"
111
+ }
112
+ };
113
+ function reactIcon(prefix, name) {
114
+ if (prefix === "heroicons") {
115
+ const { base, reactIcons } = heroicon(name);
116
+ return one("react-icons/hi2", `${reactIcons}${pascalName(base)}`);
117
+ }
118
+ const set = REACT_ICONS_SETS[prefix];
119
+ return set ? one(`react-icons/${set.module}`, `${set.prefix}${pascalName(name)}`) : null;
120
+ }
121
+ /** Font Awesome's free packages by the Iconify sets of versions 5 and 6. */
122
+ const FONTAWESOME_STYLES = {
123
+ "fa6-solid": {
124
+ source: "@fortawesome/free-solid-svg-icons",
125
+ suffix: ""
126
+ },
127
+ "fa-solid": {
128
+ source: "@fortawesome/free-solid-svg-icons",
129
+ suffix: ""
130
+ },
131
+ "fa6-regular": {
132
+ source: "@fortawesome/free-regular-svg-icons",
133
+ suffix: "Regular"
134
+ },
135
+ "fa-regular": {
136
+ source: "@fortawesome/free-regular-svg-icons",
137
+ suffix: "Regular"
138
+ },
139
+ "fa6-brands": {
140
+ source: "@fortawesome/free-brands-svg-icons",
141
+ suffix: ""
142
+ },
143
+ "fa-brands": {
144
+ source: "@fortawesome/free-brands-svg-icons",
145
+ suffix: ""
146
+ }
147
+ };
148
+ function fontAwesome(prefix, name, framework) {
149
+ const style = FONTAWESOME_STYLES[prefix];
150
+ if (!style) return null;
151
+ const imported = `fa${pascalName(name)}`;
152
+ return {
153
+ type: "fontawesome",
154
+ import: {
155
+ source: style.source,
156
+ imported,
157
+ local: `${imported}${style.suffix}`
158
+ },
159
+ component: one(framework === "react" ? "@fortawesome/react-fontawesome" : "@fortawesome/vue-fontawesome", "FontAwesomeIcon")
160
+ };
161
+ }
162
+ /**
163
+ * How `icon`, an Iconify `prefix:name`, is drawn from `iconPackage` in a component for
164
+ * `framework`; null when that package lacks the icon's set, so Iconify draws it.
165
+ */
166
+ function iconDrawing(icon, iconPackage, framework) {
167
+ const separator = icon.indexOf(":");
168
+ if (separator <= 0) return null;
169
+ const prefix = icon.slice(0, separator);
170
+ const name = icon.slice(separator + 1);
171
+ if (!name) return null;
172
+ switch (iconPackage) {
173
+ case "lucide": return prefix === "lucide" ? {
174
+ type: "component",
175
+ import: lucide(name, framework)
176
+ } : null;
177
+ case "heroicons": {
178
+ if (prefix !== "heroicons") return null;
179
+ const { base, folder } = heroicon(name);
180
+ const source = `@heroicons/${framework}/${folder}`;
181
+ return {
182
+ type: "component",
183
+ import: one(source, `${pascalName(base)}Icon`)
184
+ };
185
+ }
186
+ case "react-icons": {
187
+ const found = framework === "react" ? reactIcon(prefix, name) : null;
188
+ return found ? {
189
+ type: "component",
190
+ import: found
191
+ } : null;
192
+ }
193
+ case "fontawesome": return fontAwesome(prefix, name, framework);
194
+ default: return null;
195
+ }
196
+ }
197
+ /** The components a component's markup uses in place of its layers. */
198
+ function referencedComponents(node, found) {
199
+ if (node.type === "reference") found.push(node.component);
200
+ if (node.type === "element") for (const child of node.children) referencedComponents(child, found);
201
+ return found;
202
+ }
203
+ /**
204
+ * Names the icons a component imports apart from every other name its code knows: the
205
+ * component itself, its group item, the components it uses, and `reserved`, such as Iconify's.
206
+ * A layer named `Bell Icon` holding Heroicons' bell would otherwise import `BellIcon` beside
207
+ * declaring it; the import is aliased instead, and each module's icon keeps one name.
208
+ */
209
+ function iconNamer(component, reserved) {
210
+ const taken = /* @__PURE__ */ new Set([
211
+ component.name,
212
+ ...component.item ? [component.item.name] : [],
213
+ ...referencedComponents(component.tree, []),
214
+ ...reserved
215
+ ]);
216
+ const locals = /* @__PURE__ */ new Map();
217
+ const named = (entry) => {
218
+ const key = `${entry.source}\0${entry.imported}`;
219
+ let local = locals.get(key);
220
+ if (local === void 0) {
221
+ local = claimName(entry.local, taken);
222
+ locals.set(key, local);
223
+ }
224
+ return {
225
+ ...entry,
226
+ local
227
+ };
228
+ };
229
+ return (drawing) => drawing.type === "fontawesome" ? {
230
+ ...drawing,
231
+ import: named(drawing.import),
232
+ component: named(drawing.component)
233
+ } : {
234
+ ...drawing,
235
+ import: named(drawing.import)
236
+ };
237
+ }
238
+ /** Every import a component's icons need, one declaration per module, in a stable order. */
239
+ function iconImportDeclarations(imports) {
240
+ const byLocal = new Map(imports.map((entry) => [entry.local, entry]));
241
+ const bySource = groupBy([...byLocal.values()], (entry) => entry.source);
242
+ return Object.keys(bySource).sort().map((source) => ({
243
+ type: "ImportDeclaration",
244
+ importKind: "value",
245
+ specifiers: (bySource[source] ?? []).toSorted((a, b) => a.local.localeCompare(b.local)).map((entry) => ({
246
+ type: "ImportSpecifier",
247
+ imported: es.identifier(entry.imported),
248
+ local: es.identifier(entry.local)
249
+ })),
250
+ source: es.string(source)
251
+ }));
252
+ }
253
+ /** The imports a drawing needs. */
254
+ function drawingImports(drawing) {
255
+ return drawing.type === "fontawesome" ? [drawing.import, drawing.component] : [drawing.import];
256
+ }
257
+ //#endregion
258
+ export { ICON_PACKAGES, drawingImports, iconDrawing, iconImportDeclarations, iconNamer, iconPackagesFor, isIconPackage };
259
+
260
+ //# sourceMappingURL=icons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icons.js","names":[],"sources":["../../../../src/export/components/icons.ts"],"sourcesContent":["import { groupBy } from 'es-toolkit/array'\nimport { upperFirst } from 'es-toolkit/string'\n\nimport { es } from '@pairdraw/emit'\n\nimport { claimName } from '../storybook/names'\nimport type { ComponentModel, ComponentNode } from './model'\n\n/**\n * Where generated components take their icons from: Iconify, which draws every set, or one\n * set's own package. An icon the chosen package does not have stays an Iconify icon.\n */\nexport const ICON_PACKAGES = [\n 'iconify',\n 'lucide',\n 'heroicons',\n 'react-icons',\n 'fontawesome'\n] as const\nexport type IconPackage = (typeof ICON_PACKAGES)[number]\n\nexport function isIconPackage(value: unknown): value is IconPackage {\n return ICON_PACKAGES.some((id) => id === value)\n}\n\nexport type IconFramework = 'react' | 'vue'\n\n/** The packages a framework's components can take icons from; react-icons is React's alone. */\nexport function iconPackagesFor(framework: IconFramework): IconPackage[] {\n return ICON_PACKAGES.filter((id) => id !== 'react-icons' || framework === 'react')\n}\n\n/** One name a module exports, and the name the component's script knows it by. */\nexport interface IconImport {\n source: string\n imported: string\n local: string\n}\n\n/**\n * How a component draws an icon from a package: as the icon's own component, or, for Font\n * Awesome, as `FontAwesomeIcon` given the icon's definition.\n */\nexport type IconDrawing =\n | { type: 'component'; import: IconImport }\n | { type: 'fontawesome'; import: IconImport; component: IconImport }\n\n/** `arrow-down-0-1` → `ArrowDown01`, as the icon packages name their exports. */\nfunction pascalName(name: string): string {\n return name\n .split('-')\n .filter((part) => part.length > 0)\n .map(upperFirst)\n .join('')\n}\n\nconst one = (source: string, imported: string): IconImport => ({\n source,\n imported,\n local: imported\n})\n\nfunction lucide(name: string, framework: IconFramework): IconImport {\n // Each Lucide package also exports every icon prefixed, apart from any component of the design.\n return one(\n framework === 'react' ? 'lucide-react' : 'lucide-vue-next',\n `Lucide${pascalName(name)}`\n )\n}\n\n/** Heroicons 2 names on Iconify: `x` outline, `x-solid`, `x-20-solid` mini, `x-16-solid` micro. */\nconst HEROICON_STYLES = [\n { suffix: '-20-solid', folder: '20/solid', reactIcons: 'HiMini' },\n { suffix: '-16-solid', folder: '16/solid', reactIcons: 'HiMicro' },\n { suffix: '-solid', folder: '24/solid', reactIcons: 'Hi' }\n] as const\n\nfunction heroicon(name: string): { base: string; folder: string; reactIcons: string } {\n const style = HEROICON_STYLES.find(({ suffix }) => name.endsWith(suffix))\n if (!style) return { base: name, folder: '24/outline', reactIcons: 'HiOutline' }\n return { base: name.slice(0, -style.suffix.length), ...style }\n}\n\n/** Iconify sets that `react-icons` ships, by the module and the prefix of its export names. */\nconst REACT_ICONS_SETS: Partial<Record<string, { module: string; prefix: string }>> = {\n lucide: { module: 'lu', prefix: 'Lu' },\n tabler: { module: 'tb', prefix: 'Tb' },\n feather: { module: 'fi', prefix: 'Fi' },\n ri: { module: 'ri', prefix: 'Ri' },\n bi: { module: 'bs', prefix: 'Bs' },\n ph: { module: 'pi', prefix: 'Pi' },\n 'radix-icons': { module: 'rx', prefix: 'Rx' },\n 'simple-icons': { module: 'si', prefix: 'Si' },\n 'fa6-solid': { module: 'fa6', prefix: 'Fa' },\n 'fa6-brands': { module: 'fa6', prefix: 'Fa' },\n 'fa6-regular': { module: 'fa6', prefix: 'FaReg' }\n}\n\nfunction reactIcon(prefix: string, name: string): IconImport | null {\n if (prefix === 'heroicons') {\n const { base, reactIcons } = heroicon(name)\n return one('react-icons/hi2', `${reactIcons}${pascalName(base)}`)\n }\n const set = REACT_ICONS_SETS[prefix]\n return set ? one(`react-icons/${set.module}`, `${set.prefix}${pascalName(name)}`) : null\n}\n\n/** Font Awesome's free packages by the Iconify sets of versions 5 and 6. */\nconst FONTAWESOME_STYLES: Partial<Record<string, { source: string; suffix: string }>> = {\n 'fa6-solid': { source: '@fortawesome/free-solid-svg-icons', suffix: '' },\n 'fa-solid': { source: '@fortawesome/free-solid-svg-icons', suffix: '' },\n 'fa6-regular': { source: '@fortawesome/free-regular-svg-icons', suffix: 'Regular' },\n 'fa-regular': { source: '@fortawesome/free-regular-svg-icons', suffix: 'Regular' },\n 'fa6-brands': { source: '@fortawesome/free-brands-svg-icons', suffix: '' },\n 'fa-brands': { source: '@fortawesome/free-brands-svg-icons', suffix: '' }\n}\n\nfunction fontAwesome(prefix: string, name: string, framework: IconFramework): IconDrawing | null {\n const style = FONTAWESOME_STYLES[prefix]\n if (!style) return null\n const imported = `fa${pascalName(name)}`\n return {\n type: 'fontawesome',\n // Solid and regular share names, so a regular icon is known by a name of its own.\n import: { source: style.source, imported, local: `${imported}${style.suffix}` },\n component: one(\n framework === 'react' ? '@fortawesome/react-fontawesome' : '@fortawesome/vue-fontawesome',\n 'FontAwesomeIcon'\n )\n }\n}\n\n/**\n * How `icon`, an Iconify `prefix:name`, is drawn from `iconPackage` in a component for\n * `framework`; null when that package lacks the icon's set, so Iconify draws it.\n */\nexport function iconDrawing(\n icon: string,\n iconPackage: IconPackage,\n framework: IconFramework\n): IconDrawing | null {\n const separator = icon.indexOf(':')\n if (separator <= 0) return null\n const prefix = icon.slice(0, separator)\n const name = icon.slice(separator + 1)\n if (!name) return null\n switch (iconPackage) {\n case 'lucide':\n return prefix === 'lucide' ? { type: 'component', import: lucide(name, framework) } : null\n case 'heroicons': {\n if (prefix !== 'heroicons') return null\n const { base, folder } = heroicon(name)\n const source = `@heroicons/${framework}/${folder}`\n return { type: 'component', import: one(source, `${pascalName(base)}Icon`) }\n }\n case 'react-icons': {\n // react-icons is React's alone.\n const found = framework === 'react' ? reactIcon(prefix, name) : null\n return found ? { type: 'component', import: found } : null\n }\n case 'fontawesome':\n return fontAwesome(prefix, name, framework)\n default:\n return null\n }\n}\n\n/** The components a component's markup uses in place of its layers. */\nfunction referencedComponents(node: ComponentNode, found: string[]): string[] {\n if (node.type === 'reference') found.push(node.component)\n if (node.type === 'element') for (const child of node.children) referencedComponents(child, found)\n return found\n}\n\n/**\n * Names the icons a component imports apart from every other name its code knows: the\n * component itself, its group item, the components it uses, and `reserved`, such as Iconify's.\n * A layer named `Bell Icon` holding Heroicons' bell would otherwise import `BellIcon` beside\n * declaring it; the import is aliased instead, and each module's icon keeps one name.\n */\nexport function iconNamer(\n component: ComponentModel,\n reserved: readonly string[]\n): (drawing: IconDrawing) => IconDrawing {\n const taken = new Set([\n component.name,\n ...(component.item ? [component.item.name] : []),\n ...referencedComponents(component.tree, []),\n ...reserved\n ])\n const locals = new Map<string, string>()\n const named = (entry: IconImport): IconImport => {\n const key = `${entry.source}\\0${entry.imported}`\n let local = locals.get(key)\n if (local === undefined) {\n local = claimName(entry.local, taken)\n locals.set(key, local)\n }\n return { ...entry, local }\n }\n return (drawing) =>\n drawing.type === 'fontawesome'\n ? { ...drawing, import: named(drawing.import), component: named(drawing.component) }\n : { ...drawing, import: named(drawing.import) }\n}\n\n/** Every import a component's icons need, one declaration per module, in a stable order. */\nexport function iconImportDeclarations(imports: readonly IconImport[]): es.SyntaxNode[] {\n const byLocal = new Map(imports.map((entry) => [entry.local, entry]))\n const bySource = groupBy([...byLocal.values()], (entry) => entry.source)\n return Object.keys(bySource)\n .sort()\n .map((source) => ({\n type: 'ImportDeclaration',\n importKind: 'value',\n specifiers: (bySource[source] ?? [])\n .toSorted((a, b) => a.local.localeCompare(b.local))\n .map((entry) => ({\n type: 'ImportSpecifier',\n imported: es.identifier(entry.imported),\n local: es.identifier(entry.local)\n })),\n source: es.string(source)\n }))\n}\n\n/** The imports a drawing needs. */\nexport function drawingImports(drawing: IconDrawing): IconImport[] {\n return drawing.type === 'fontawesome' ? [drawing.import, drawing.component] : [drawing.import]\n}\n"],"mappings":";;;;;;;;;AAYA,MAAa,gBAAgB;CAC3B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