@pairdraw/dom-css 0.0.0-stage → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) 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 +1599 -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 +88 -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 +412 -0
  91. package/src/export/components/react/props.ts +151 -0
  92. package/src/export/components/react/radix.ts +52 -0
  93. package/src/export/components/react/shared.ts +76 -0
  94. package/src/export/components/references.ts +212 -0
  95. package/src/export/components/repeats.ts +128 -0
  96. package/src/export/components/shaders.ts +125 -0
  97. package/src/export/components/styling.ts +31 -0
  98. package/src/export/components/tree.ts +72 -0
  99. package/src/export/components/vue.ts +517 -0
  100. package/src/export/css.ts +57 -0
  101. package/src/export/grid.ts +42 -0
  102. package/src/export/html.ts +163 -0
  103. package/src/export/index.ts +44 -0
  104. package/src/export/projection.ts +581 -0
  105. package/src/export/storybook/component.ts +334 -0
  106. package/src/export/storybook/export.ts +430 -0
  107. package/src/export/storybook/groups.ts +161 -0
  108. package/src/export/storybook/module.ts +319 -0
  109. package/src/export/storybook/names.ts +51 -0
  110. package/src/export/tailwind-jsx.ts +156 -0
  111. package/src/export/text.ts +415 -0
  112. package/src/import/css-text.ts +4 -0
  113. package/src/import/css-values.ts +31 -0
  114. package/src/import/flow.ts +248 -0
  115. package/src/import/html.ts +88 -0
  116. package/src/import/jsx/core.ts +130 -0
  117. package/src/import/jsx/dev-runtime.ts +8 -0
  118. package/src/import/jsx/runtime.ts +76 -0
  119. package/src/import/scene-graph.ts +582 -0
  120. package/src/import/style-attribute.ts +25 -0
  121. package/src/import/tailwind.ts +54 -0
  122. package/src/import/text.ts +518 -0
  123. package/src/index.ts +51 -0
  124. package/src/runtime/browser/runtime.ts +301 -0
  125. package/src/runtime/headless/runtime.ts +99 -0
  126. package/src/runtime/headless/styles.ts +330 -0
  127. package/src/runtime/index.ts +11 -0
  128. package/src/tokens/conditions.ts +66 -0
  129. package/src/tokens/cssom-validator.ts +8 -0
  130. package/src/tokens/custom-properties.ts +331 -0
  131. package/src/tokens/expression.ts +128 -0
  132. package/src/tokens/formula.ts +140 -0
  133. package/src/tokens/index.ts +43 -0
  134. package/src/tokens/names.ts +161 -0
  135. package/src/tokens/references.ts +201 -0
  136. package/src/tokens/stylesheet.ts +304 -0
  137. package/src/tokens/validate.ts +86 -0
  138. package/src/tokens/values.ts +44 -0
  139. package/src/types.ts +59 -0
@@ -0,0 +1,594 @@
1
+ import { DesignDocument, DesignElement, DesignNode, DesignStyleDeclaration, DesignText } from "./types.js";
2
+ import { COMPONENT_STYLINGS, ComponentStyling, ExportHTMLBundle, ExportHTMLBundleOptions, ExportHTMLFile, SceneGraphToDesignOptions, TailwindStylesheetId, TailwindStylesheetLoader, VectorElementRenderer, WebFontFaceAsset, WebFontFaceRequest, WebFontFaceResolver, exportHTMLBundle, sceneGraphToDesignDocument, sceneNodeToDesignDocument, serializeHTML } from "./styling.js";
3
+ import { ThemeNamespace } from "twirlwind";
4
+ import { Behaviour } from "@pairdraw/scene-graph/behaviours";
5
+ import { es } from "@pairdraw/emit";
6
+ import { CSSStyleSheetLike } from "@acemir/cssom";
7
+ import { ComponentPropertyDefinition, SceneGraph, SceneNode, TokenUnit, Variable, VariableCollection, VariableCollectionMode } from "@pairdraw/scene-graph";
8
+ //#region src/export/tailwind-jsx.d.ts
9
+ /** Engine services the projection takes, such as drawing vector layers as SVG. */
10
+ type ProjectionServices = Pick<SceneGraphToDesignOptions, 'vectorElement'>;
11
+ /** Print a design document as Tailwind JSX, one top-level element per block. */
12
+ declare function designDocumentToTailwindJSX(document: DesignDocument): string;
13
+ /** Tailwind JSX for scene nodes, separated by blank lines. */
14
+ declare function sceneNodesToTailwindJSX(graph: SceneGraph, nodeIds: string[], options?: ProjectionServices): string;
15
+ /** Tailwind JSX with the layer behind each element, in the order elements open. */
16
+ interface TailwindJSXWithLayers {
17
+ code: string;
18
+ /** One entry per JSX element in pre-order; `null` for an element no layer produced. */
19
+ layerIds: Array<string | null>;
20
+ }
21
+ declare function sceneNodesToTailwindJSXWithLayers(graph: SceneGraph, nodeIds: string[], { vectorElement }?: ProjectionServices): TailwindJSXWithLayers;
22
+ //#endregion
23
+ //#region src/behaviours/args.d.ts
24
+ /** A variant property a boolean value draws, as the component's boolean prop. */
25
+ interface BooleanArg {
26
+ /** The prop's name, as Reka and Radix call it: `checked`, `pressed`, `open`, `disabled`. */
27
+ name: string;
28
+ on: string;
29
+ off: string;
30
+ }
31
+ /** The props a component with a behaviour has, read from the variant properties that draw it. */
32
+ interface BehaviourArgs {
33
+ /** Boolean props by the name of the variant property that draws them. */
34
+ booleans: Map<string, BooleanArg>;
35
+ /**
36
+ * The variant property that draws interaction states. States follow the pointer and focus,
37
+ * so they are not props; `rest` is the value shown without one, and `disabled` the value the
38
+ * disabled prop shows, if the set draws it.
39
+ */
40
+ states?: {
41
+ property: string;
42
+ rest: string;
43
+ disabled?: string;
44
+ };
45
+ /**
46
+ * The variant property that draws a field with text, which the field shows while its input
47
+ * has text rather than taking as a prop.
48
+ */
49
+ filled?: {
50
+ property: string;
51
+ on: string;
52
+ off: string;
53
+ };
54
+ }
55
+ /**
56
+ * The props of a component set with a behaviour. Only variant properties become props here,
57
+ * since each variant is drawn; a boolean value becomes a boolean prop when its property offers
58
+ * exactly its on and off values.
59
+ */
60
+ declare function behaviourArgs(graph: SceneGraph, set: SceneNode): BehaviourArgs | null;
61
+ //#endregion
62
+ //#region src/behaviours/states/types.d.ts
63
+ /**
64
+ * What must hold on a control's root for a variant to show. Reka and Radix set `data-state`
65
+ * and `data-disabled` themselves; the browser sets the interactions; a generated component
66
+ * sets `data-*` from its props for every other variant property.
67
+ */
68
+ type StateCondition = {
69
+ type: 'state';
70
+ value: string;
71
+ } | {
72
+ type: 'disabled';
73
+ } |
74
+ /** `within` when focus lands on a layer inside the control, such as a field's input. */
75
+ {
76
+ type: 'interaction';
77
+ state: 'hover' | 'pressed' | 'focus';
78
+ within?: boolean;
79
+ } |
80
+ /** A field whose input holds text. */
81
+ {
82
+ type: 'filled';
83
+ } | {
84
+ type: 'prop';
85
+ name: string;
86
+ value: string;
87
+ };
88
+ /** What a variant changes on a layer, and the conditions that show that variant. */
89
+ interface StateRule {
90
+ conditions: StateCondition[];
91
+ /**
92
+ * The layer the conditions test when it is not the control's root, such as a tab trigger
93
+ * that Reka and Radix mark active itself: the layer the rule styles, or one around it.
94
+ */
95
+ on?: StateElement;
96
+ /** The part of the layer the rule styles: an input's placeholder, or a number input's spinner. */
97
+ pseudo?: 'placeholder' | '-webkit-inner-spin-button';
98
+ style: DesignStyleDeclaration;
99
+ }
100
+ /** A layer of the merged markup: its rest style and what each other variant changes. */
101
+ interface StateElement {
102
+ type: 'element';
103
+ /** The layer path below the variant, with the text when variants label a layer differently. */
104
+ key: string;
105
+ /** What the layer draws other than its own box, such as an instance or an icon (`layerKind`). */
106
+ kind: string | undefined;
107
+ /** The layer's name, for class names. */
108
+ name: string;
109
+ tagName: string;
110
+ attrs: Record<string, string>;
111
+ base: DesignStyleDeclaration;
112
+ rules: StateRule[];
113
+ /** The shader the layer fills with at rest, as the projection keeps it. */
114
+ shader?: DesignElement['shader'];
115
+ children: StateNode[];
116
+ }
117
+ type StateNode = StateElement | DesignText;
118
+ interface StateStyles {
119
+ /** The set's name, for the root's class name. */
120
+ name: string;
121
+ /** The variant drawing the rest state, which the merged tree starts from. */
122
+ restId: string;
123
+ root: StateElement;
124
+ }
125
+ //#endregion
126
+ //#region src/export/components/icons.d.ts
127
+ /**
128
+ * Where generated components take their icons from: Iconify, which draws every set, or one
129
+ * set's own package. An icon the chosen package does not have stays an Iconify icon.
130
+ */
131
+ declare const ICON_PACKAGES: readonly ["iconify", "lucide", "heroicons", "react-icons", "fontawesome"];
132
+ type IconPackage = (typeof ICON_PACKAGES)[number];
133
+ declare function isIconPackage(value: unknown): value is IconPackage;
134
+ type IconFramework = 'react' | 'vue';
135
+ /** The packages a framework's components can take icons from; react-icons is React's alone. */
136
+ declare function iconPackagesFor(framework: IconFramework): IconPackage[];
137
+ //#endregion
138
+ //#region src/export/components/model.d.ts
139
+ /** A generated component's files, and what its stories need to know about it. */
140
+ interface GeneratedComponent {
141
+ /**
142
+ * The component's files. A file of JSX lists the layer each of its JSX elements draws, in the
143
+ * order they open, `null` for an element no layer drew, such as a shader's canvas.
144
+ */
145
+ files: {
146
+ path: string;
147
+ content: string;
148
+ layerIds?: (string | null)[];
149
+ }[];
150
+ /** How stories import it: its path next to them, and whether it's a named export. */
151
+ entry: {
152
+ path: string;
153
+ named: boolean;
154
+ };
155
+ /** The prop a story sets the value with, if the component has one. */
156
+ valueArg: string | null;
157
+ /** Whether that prop takes a list of the value, as Radix's slider does. */
158
+ valueList?: boolean;
159
+ }
160
+ /** How a generator writes a component. */
161
+ interface ComponentGeneratorOptions {
162
+ /** A stylesheet beside the component, by default, or Tailwind utilities in its markup. */
163
+ styling?: ComponentStyling;
164
+ /** The package icons come from; Iconify by default, and for any icon the package lacks. */
165
+ icons?: IconPackage;
166
+ }
167
+ //#endregion
168
+ //#region src/export/components/layers.d.ts
169
+ /** The frameworks a layer can be generated as a component for. */
170
+ declare const LAYER_COMPONENT_FRAMEWORKS: readonly ["vue", "react"];
171
+ type LayerComponentFramework = (typeof LAYER_COMPONENT_FRAMEWORKS)[number];
172
+ /** A layer as a component: its name and the files that make it up. */
173
+ interface LayerComponent {
174
+ name: string;
175
+ layerId: string;
176
+ files: GeneratedComponent['files'];
177
+ }
178
+ /**
179
+ * Each layer as a Vue or React component, as the Storybook export generates a component set's:
180
+ * a component set with its variants as props and its behaviour's parts, and any other layer as
181
+ * a plain component of the elements it draws. Names stay distinct across the layers.
182
+ */
183
+ declare function layerComponents(graph: SceneGraph, layerIds: readonly string[], framework: LayerComponentFramework, options?: Pick<SceneGraphToDesignOptions, 'vectorElement'> & ComponentGeneratorOptions): Promise<LayerComponent[]>;
184
+ /** Layers as HTML and the stylesheet that styles it, and the images it points at. */
185
+ interface LayerMarkup {
186
+ html: string;
187
+ /** The layer each element of `html` draws, in the order they open, `null` for none. */
188
+ layerIds: (string | null)[];
189
+ css: string;
190
+ images: ExportHTMLFile[];
191
+ }
192
+ /**
193
+ * Layers as indented HTML with a readable class per layer and one stylesheet, as the generated
194
+ * components draw them, or with Tailwind utilities in place of the classes and no stylesheet.
195
+ * Images are files under `assetBasePath` rather than inlined.
196
+ */
197
+ declare function layerMarkup(graph: SceneGraph, layerIds: readonly string[], options?: Pick<SceneGraphToDesignOptions, 'vectorElement'> & ComponentGeneratorOptions & {
198
+ assetBasePath?: string;
199
+ }): Promise<LayerMarkup>;
200
+ //#endregion
201
+ //#region src/tokens/conditions.d.ts
202
+ /** What a feature is tested against: a keyword such as `dark`, or a length such as `640px`. */
203
+ type FeatureValue = {
204
+ type: 'keyword';
205
+ name: string;
206
+ } | {
207
+ type: 'dimension';
208
+ value: number;
209
+ unit: string;
210
+ };
211
+ /** An at-rule that tests one feature: `@media (prefers-color-scheme: dark)`. */
212
+ interface FeatureCondition {
213
+ rule: 'media' | 'container';
214
+ /** `prefers-color-scheme`, lowercase. */
215
+ feature: string;
216
+ value: FeatureValue;
217
+ }
218
+ /**
219
+ * Reads a condition with css-tree, so spacing, case and comments do not change what it tests, and
220
+ * only what CSS calls whitespace separates its parts. Undefined for anything but one `@media` or
221
+ * unnamed `@container` rule testing one feature: a selector, `@media screen`, or
222
+ * `@media (a: b) and (c: d)`.
223
+ */
224
+ declare function parseFeatureCondition(css: string): FeatureCondition | undefined;
225
+ /** The condition as the stylesheet writes it: `@media (max-width: 640px)`. */
226
+ declare function featureConditionCSS({ rule, feature, value }: FeatureCondition): string;
227
+ //#endregion
228
+ //#region src/tokens/custom-properties.d.ts
229
+ /** One custom property a stylesheet declares: `--brand: #ff5b2e`. */
230
+ interface CustomPropertyDeclaration {
231
+ /** The property without its leading `--`. */
232
+ name: string;
233
+ /** The value as written, trimmed, without `!important`. */
234
+ value: string;
235
+ /** Where the trimmed value sits in the source, so a write-back replaces only it. */
236
+ start: number;
237
+ end: number;
238
+ }
239
+ /**
240
+ * A block of custom properties and the scope it applies in. The base set is `:root`, `html`,
241
+ * `:host`, or Tailwind's `@theme`; every other scope is a mode's condition, as the token
242
+ * stylesheet writes it: a selector such as `[data-theme="dark"]` or `.dark`, or an at-rule
243
+ * prelude such as `@media (prefers-color-scheme: dark)` around a `:root` block.
244
+ */
245
+ interface CustomPropertyScope {
246
+ /** Null for the base set. */
247
+ condition: string | null;
248
+ /** The attribute and value a lone `[name="value"]` selector switches on. */
249
+ attribute?: {
250
+ name: string;
251
+ value: string;
252
+ };
253
+ /**
254
+ * `Collection: Mode` from a comment just above a mode's block, as the token stylesheet writes
255
+ * it. A comment is a label only where its mode is the one the condition names, such as `Dark`
256
+ * above `.dark`, or where the condition names none, such as `@media (min-width: 40rem)`.
257
+ */
258
+ label?: {
259
+ collection: string;
260
+ mode: string;
261
+ };
262
+ declarations: CustomPropertyDeclaration[];
263
+ /** The offset of the block's closing brace, where new declarations go. */
264
+ insertAt: number;
265
+ /** The indentation of the block's declarations. */
266
+ indent: string;
267
+ }
268
+ interface CustomPropertySheet {
269
+ scopes: CustomPropertyScope[];
270
+ /** Selectors and at-rules that declare custom properties but name no mode, as written. */
271
+ skipped: string[];
272
+ }
273
+ /**
274
+ * The mode a condition names by itself: the value of `[data-theme="dark"]`, the class of `.dark`,
275
+ * or the scheme of `@media (prefers-color-scheme: dark)`. Undefined for other conditions.
276
+ */
277
+ declare function modeConditionName(condition: string, attribute?: CustomPropertyScope['attribute']): string | undefined;
278
+ /**
279
+ * The custom properties a stylesheet declares, by the scope they apply in: the inverse of
280
+ * `buildTokenStylesheet`. It reads the base set, selector modes, and `:root` blocks inside
281
+ * `@media`, `@supports`, and `@container`, also inside `@layer`; a scope it cannot read as a mode,
282
+ * such as `.card .title` or a selector inside a media query, is listed in `skipped`.
283
+ */
284
+ declare function readCustomProperties(css: string): CustomPropertySheet;
285
+ /**
286
+ * A mode's condition in the form `readCustomProperties` gives it, so conditions written
287
+ * differently compare equal: `:root[data-theme=dark]` and `[data-theme="dark"]`, or
288
+ * `@media (prefers-color-scheme:dark)` and `@media (prefers-color-scheme: dark)`.
289
+ */
290
+ declare function modeConditionKey(condition: string): string;
291
+ //#endregion
292
+ //#region src/tokens/validate.d.ts
293
+ type Parse = (cssText: string) => CSSStyleSheetLike;
294
+ /**
295
+ * Token strings come from documents, so each one is parsed in place before it is written. A value
296
+ * or condition that closes its rule early parses to a different number of rules and fails.
297
+ */
298
+ declare function createTokenValidator(parse: Parse): {
299
+ declaration: (name: string, value: string) => boolean;
300
+ /**
301
+ * A custom property name without its `--`: one word to the CSS value tokenizer, which splits
302
+ * on spaces, colons, commas and slashes, and one declaration to the parser. It starts with a
303
+ * letter, digit or underscore, so `--` is never doubled into `----`.
304
+ */
305
+ name(name: string): boolean;
306
+ /** A selector, or a `@media`, `@supports` or `@container` prelude, that wraps exactly one rule. */
307
+ condition(condition: string): boolean;
308
+ };
309
+ type TokenValidator = ReturnType<typeof createTokenValidator>;
310
+ //#endregion
311
+ //#region src/tokens/expression.d.ts
312
+ /**
313
+ * What a piece of a CSS value is. A finished `var(--name)` is one `reference`; while it is typed
314
+ * it reads as a `function`, a `paren` and a `property`, the custom property name.
315
+ */
316
+ type CSSValueTokenKind = 'reference' | 'property' | 'function' | 'paren' | 'number' | 'operator' | 'separator' | 'string' | 'keyword';
317
+ interface CSSValueToken {
318
+ kind: CSSValueTokenKind;
319
+ text: string;
320
+ from: number;
321
+ to: number;
322
+ }
323
+ /**
324
+ * The tokens of one CSS value, such as `clamp(1rem, 4vw, var(--space-md))`, in order and with
325
+ * their source ranges. Reading tolerates half-typed values: an unclosed function still gives
326
+ * its name and its `(`.
327
+ */
328
+ declare function cssValueTokens(source: string): CSSValueToken[];
329
+ /** The custom property a token names, in `var(--name)` or as a bare `--name`. */
330
+ declare function cssTokenProperty(token: CSSValueToken): string | undefined;
331
+ type CSSExpressionProblem = {
332
+ kind: 'unclosed';
333
+ } | {
334
+ kind: 'syntax';
335
+ } | {
336
+ kind: 'negated-reference';
337
+ property: string;
338
+ } | {
339
+ kind: 'unknown-token';
340
+ name: string;
341
+ } | {
342
+ kind: 'invalid';
343
+ property: string;
344
+ };
345
+ /**
346
+ * Why a CSS expression cannot stand in for a token, if it cannot. The token validator checks it
347
+ * is one declaration; then it must name only tokens that exist and suit the token's unit, which
348
+ * `supports` checks where a browser can type values. A value holding `var()` passes that last
349
+ * check until it is used, so only its names are checked.
350
+ */
351
+ declare function cssExpressionProblem(css: string, unit: TokenUnit, tokens: ReadonlySet<string>, validator: TokenValidator, supports?: (property: string, value: string) => boolean): CSSExpressionProblem | undefined;
352
+ //#endregion
353
+ //#region src/tokens/names.d.ts
354
+ /** Every variable, collection by collection, in each collection's own order. */
355
+ declare function collectionVariables(source: Pick<SceneGraph, 'variables' | 'variableCollections'>): Variable[];
356
+ /**
357
+ * Lowercase words joined by `-`, keeping digits on their word, as Tailwind keys do: `Text/2xl`
358
+ * is `text-2xl`, `Heading/H1` is `heading-h1`, `brandPrimary` is `brand-primary`. es-toolkit's
359
+ * `kebabCase` splits digits off (`text-2-xl`), which no design system writes.
360
+ */
361
+ declare function tokenSlug(text: string): string;
362
+ /** The Tailwind namespace a token belongs to, from its type, its scopes, then its leading name segment. */
363
+ declare function variableNamespace(variable: Variable): ThemeNamespace | undefined;
364
+ /**
365
+ * The custom property a code snippet names, without `--`: `var(--brand)`, `var(--brand, red)`
366
+ * and `--brand` all name `brand`. A snippet that is anything else, such as a Tailwind class,
367
+ * names none.
368
+ */
369
+ declare function parseCSSName(snippet: string | undefined): string | undefined;
370
+ /** The name `codeSyntax.WEB` gives the token, if it gives one. */
371
+ declare function explicitCSSName(variable: Variable): string | undefined;
372
+ /**
373
+ * `Gray/50` as COLOR is `color-gray-50`; `Space/small` is `spacing-small`. A group the next segment
374
+ * repeats is said once, so `Gap/gap-1` is `gap-1`, as kits that mirror Tailwind classes name them. Two tokens can derive
375
+ * the same name, so stylesheet output takes names from `variableCSSNames`, which makes them unique.
376
+ */
377
+ declare function deriveCSSName(variable: Variable): string;
378
+ /**
379
+ * Document-wide custom property names, without `--`. The first token whose `WEB` snippet claims
380
+ * a name keeps it; later claimants, which Figma files do contain, and derived names that collide
381
+ * take a derived name with a numeric suffix, in iteration order.
382
+ */
383
+ declare function variableCSSNames(variables: Iterable<Variable>): Map<string, string>;
384
+ /** The `WEB` snippet that names a token in Figma's Dev Mode and here. */
385
+ declare function cssNameCodeSyntax(name: string): string;
386
+ /**
387
+ * The variable name a custom property reads as: a Tailwind namespace becomes the group, so
388
+ * `color-gray-50` is `color/gray-50` and `radius-md` is `radius/md`; any other name stays as it
389
+ * is. Variables made this way keep the property in their `WEB` code syntax, so the stylesheet
390
+ * writes the same name back.
391
+ */
392
+ declare function cssNameVariableName(name: string): string;
393
+ //#endregion
394
+ //#region src/tokens/stylesheet.d.ts
395
+ type TokenStylesheetFormat = 'css' | 'tailwind';
396
+ type TokenStylesheetIssue = {
397
+ message: string;
398
+ variableId?: string;
399
+ collectionId?: string;
400
+ modeId?: string;
401
+ };
402
+ type TokenStylesheetOptions = {
403
+ format: TokenStylesheetFormat;
404
+ /** Write only these tokens. Names still come from every token, so aliases outside resolve. */
405
+ include?: (variable: Variable) => boolean;
406
+ };
407
+ type TokenStylesheet = {
408
+ css: string;
409
+ issues: TokenStylesheetIssue[];
410
+ };
411
+ type TokenSource = Pick<SceneGraph, 'variables' | 'variableCollections'>;
412
+ /** The attribute a collection's manual modes are switched by, unless it names its own. */
413
+ declare function defaultModeAttributeName(collection: VariableCollection): string;
414
+ /** The attribute that puts an element in a mode with no condition of its own: `data-theme`. */
415
+ declare function modeAttribute(collection: VariableCollection, mode: VariableCollectionMode): {
416
+ name: string;
417
+ value: string;
418
+ };
419
+ /** The scope a mode applies in when it names none: `[data-theme="dark"]` for Theme / Dark. */
420
+ declare function defaultModeCondition(collection: VariableCollection, mode: VariableCollectionMode): string;
421
+ /**
422
+ * Variables as a stylesheet of custom properties. The default mode of every collection is the
423
+ * base set, in `:root` or, for Tailwind, in `@theme` when the token has a Tailwind namespace;
424
+ * every other mode overrides the values that differ, under its condition. Aliases stay `var()`
425
+ * references, and number formulas `calc()` over them; both are declared again in each mode that
426
+ * changes what they point to.
427
+ */
428
+ declare function buildTokenStylesheet(source: TokenSource, { format, include }: TokenStylesheetOptions, validate: TokenValidator): TokenStylesheet;
429
+ /**
430
+ * Browsers check token strings with their own CSS parser. Elsewhere, in the CLI and MCP, the CSS
431
+ * object model package loads on first use; its browser build exports nothing, so it is never
432
+ * the browser path.
433
+ */
434
+ declare function loadTokenValidator(): Promise<TokenValidator>;
435
+ declare function tokenStylesheet(source: TokenSource, options: TokenStylesheetOptions): Promise<TokenStylesheet>;
436
+ //#endregion
437
+ //#region src/tokens/values.d.ts
438
+ /**
439
+ * A property that takes values in each token unit, where a browser checks or computes a CSS
440
+ * expression written for the token: `scale` takes any plain number, `width` any length.
441
+ */
442
+ declare const TOKEN_UNIT_PROPERTY: Record<TokenUnit, string>;
443
+ /**
444
+ * The unit a FLOAT token is written in. An explicit unit wins; opacity and font weights are
445
+ * unitless; every other number is a pixel length, which is what the canvas draws.
446
+ */
447
+ declare function variableUnit(variable: Variable): TokenUnit;
448
+ /** A stored number written in its unit: 24 as `rem` is `1.5rem`, 150 as `ms` is `150ms`. */
449
+ declare function tokenNumberToCSS(value: number, unit: TokenUnit): string;
450
+ //#endregion
451
+ //#region src/behaviours/controls.d.ts
452
+ /** A boolean value of a control and the property that draws it. */
453
+ interface BooleanModel {
454
+ definition: ComponentPropertyDefinition;
455
+ on?: string;
456
+ off?: string;
457
+ /** The value as the document's instance draws it. */
458
+ designed: boolean;
459
+ }
460
+ /** The variant property that draws a control's interaction states. */
461
+ interface StatesModel {
462
+ name: string;
463
+ values: NonNullable<Behaviour['states']>;
464
+ /** The value the instance shows at rest. */
465
+ rest: string | undefined;
466
+ /** Whether the document's instance is drawn disabled. */
467
+ designedDisabled: boolean;
468
+ }
469
+ /** An instance with a behaviour below a root layer: its values, states, and bound layers. */
470
+ interface ControlModel {
471
+ /** The instance's layer path below the root. */
472
+ path: string;
473
+ kind: Behaviour['kind'];
474
+ behaviour: Behaviour;
475
+ booleans: Record<string, BooleanModel>;
476
+ states: StatesModel | null;
477
+ /** Each bound part's slot frame, by part id, as a layer path below the root. */
478
+ parts: Record<string, string>;
479
+ /** Each bound text value's text layer, by value id, as a layer path below the root. */
480
+ texts: Record<string, {
481
+ path: string;
482
+ designed: string;
483
+ }>;
484
+ /** The children of the items slot that are controls themselves, in order. */
485
+ items: ControlModel[];
486
+ /**
487
+ * Layers the control decides to show, which the design may hide: tab panels, or a
488
+ * collapsible's content, as layer paths below the root.
489
+ */
490
+ reveal: string[];
491
+ /** For tabs, each panel's layer path, in order. */
492
+ panels: string[];
493
+ /** For tabs, each trigger's layer path, in order. */
494
+ triggers: string[];
495
+ }
496
+ /**
497
+ * The controls below a root layer, by layer path, outermost first. Items of a group are listed
498
+ * both in the group's `items` and on their own, since each keeps its own state. Preview runs
499
+ * them as live islands; export generates components from them.
500
+ */
501
+ declare function behaviourControls(graph: SceneGraph, rootId: string): Map<string, ControlModel>;
502
+ /** A control's boolean value, if the behaviour binds it. */
503
+ declare function booleanOf(control: ControlModel, valueId: string): BooleanModel | undefined;
504
+ //#endregion
505
+ //#region src/behaviours/reset.d.ts
506
+ /**
507
+ * Element styles a native `<button>` adds, cleared so the design's own styles show. Preview
508
+ * and generated components render control roots and triggers as buttons for their semantics.
509
+ */
510
+ declare const BUTTON_RESET: Record<string, string>;
511
+ /**
512
+ * Element styles an input or textarea adds, cleared so the field's text layer it replaces
513
+ * keeps its look. Preview and generated components both draw a field's text as one.
514
+ */
515
+ declare const INPUT_RESET: Record<string, string>;
516
+ //#endregion
517
+ //#region src/behaviours/roles.d.ts
518
+ /** What a layer below a root is to the controls in it. */
519
+ type ControlRole = {
520
+ type: 'root';
521
+ control: ControlModel;
522
+ } | {
523
+ type: 'part';
524
+ control: ControlModel;
525
+ part: string;
526
+ } | {
527
+ type: 'item';
528
+ group: ControlModel;
529
+ control: ControlModel;
530
+ index: number;
531
+ } | {
532
+ type: 'trigger';
533
+ control: ControlModel;
534
+ index: number;
535
+ } | {
536
+ type: 'panel';
537
+ control: ControlModel;
538
+ index: number;
539
+ } | {
540
+ type: 'text';
541
+ control: ControlModel;
542
+ valueId: string;
543
+ };
544
+ /**
545
+ * Each layer's role by layer path: control roots, their parts, items of groups, tab triggers
546
+ * and panels, and the text layers that become inputs. Items of a group take the item role in
547
+ * place of their root role, since the group drives them.
548
+ */
549
+ declare function controlRoles(controls: ReadonlyMap<string, ControlModel>): Map<string, ControlRole>;
550
+ /** The group a control is an item of, if any. */
551
+ declare function groupOf(roles: ReadonlyMap<string, ControlRole>, control: ControlModel): ControlModel | undefined;
552
+ //#endregion
553
+ //#region src/behaviours/states/model.d.ts
554
+ /**
555
+ * A component set's variants as one markup tree with a rest style per layer and a rule per
556
+ * variant holding only what that variant changes, under the conditions that show it. Layers
557
+ * only some variants draw stay in the tree, hidden where absent.
558
+ *
559
+ * `null` when no variant shows the rest state, since every look then depends on a condition.
560
+ */
561
+ declare function stateStyles(graph: SceneGraph, set: SceneNode, options?: Pick<SceneGraphToDesignOptions, 'vectorElement'>): StateStyles | null;
562
+ //#endregion
563
+ //#region src/behaviours/states/css.d.ts
564
+ interface StateStylesheet {
565
+ /** The merged markup, each layer carrying its class and no inline style. */
566
+ document: DesignDocument;
567
+ css: string;
568
+ }
569
+ /** The selector part a condition adds to the control's root. */
570
+ declare function conditionSelector(condition: StateCondition): string;
571
+ /**
572
+ * The state styles as a stylesheet with a readable class per layer. A rule with more
573
+ * conditions comes later and has a more specific selector, so a combined variant wins over
574
+ * each of its parts. The sheet is built with the CSS object model, which rejects an invalid
575
+ * selector and prints the declarations.
576
+ */
577
+ declare function stateStylesToCSS(styles: StateStyles): Promise<StateStylesheet>;
578
+ //#endregion
579
+ //#region src/behaviours/states/tailwind.d.ts
580
+ interface StateTailwindOptions {
581
+ /** Custom properties declared in `@theme`; a `var()` naming one becomes its utility. */
582
+ themeVariables?: readonly string[];
583
+ }
584
+ /**
585
+ * Each element's Tailwind utilities for the state styles: rest utilities, and each variant's
586
+ * changes behind the variants that show it. More stacked variants make a more specific
587
+ * selector, so a combined variant wins over each of its parts.
588
+ */
589
+ declare function stateTailwindClasses(styles: StateStyles, options?: StateTailwindOptions): Map<StateElement, string>;
590
+ /** The state styles as Tailwind utilities on each element of the merged markup. */
591
+ declare function stateStylesToTailwind(styles: StateStyles, options?: StateTailwindOptions): DesignDocument;
592
+ //#endregion
593
+ export { BUTTON_RESET, type BehaviourArgs, type BooleanArg, type BooleanModel, COMPONENT_STYLINGS, type CSSExpressionProblem, type CSSValueToken, type CSSValueTokenKind, type ComponentStyling, type ControlModel, type ControlRole, type CustomPropertyDeclaration, type CustomPropertyScope, type CustomPropertySheet, type DesignDocument, type DesignElement, type DesignNode, type ExportHTMLBundle, type ExportHTMLBundleOptions, type ExportHTMLFile, type FeatureCondition, ICON_PACKAGES, INPUT_RESET, type IconFramework, type IconPackage, LAYER_COMPONENT_FRAMEWORKS, type LayerComponent, type LayerComponentFramework, type LayerMarkup, type SceneGraphToDesignOptions, type StateCondition, type StateElement, type StateNode, type StateRule, type StateStyles, type StateStylesheet, type StateTailwindOptions, type StatesModel, TOKEN_UNIT_PROPERTY, type TailwindJSXWithLayers, type TailwindStylesheetId, type TailwindStylesheetLoader, type TokenStylesheet, type TokenStylesheetFormat, type TokenStylesheetIssue, type TokenStylesheetOptions, type TokenValidator, type VectorElementRenderer, type WebFontFaceAsset, type WebFontFaceRequest, type WebFontFaceResolver, behaviourArgs, behaviourControls, booleanOf, buildTokenStylesheet, collectionVariables, conditionSelector, controlRoles, createTokenValidator, cssExpressionProblem, cssNameCodeSyntax, cssNameVariableName, cssTokenProperty, cssValueTokens, defaultModeAttributeName, defaultModeCondition, deriveCSSName, designDocumentToTailwindJSX, explicitCSSName, exportHTMLBundle, featureConditionCSS, groupOf, iconPackagesFor, isIconPackage, layerComponents, layerMarkup, loadTokenValidator, modeAttribute, modeConditionKey, modeConditionName, parseCSSName, parseFeatureCondition, readCustomProperties, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers, serializeHTML, stateStyles, stateStylesToCSS, stateStylesToTailwind, stateTailwindClasses, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit };
594
+ //# sourceMappingURL=export.d.ts.map
package/dist/export.js ADDED
@@ -0,0 +1,13 @@
1
+ import { TOKEN_UNIT_PROPERTY, buildTokenStylesheet, collectionVariables, createTokenValidator, cssNameCodeSyntax, cssNameVariableName, defaultModeAttributeName, defaultModeCondition, deriveCSSName, explicitCSSName, loadTokenValidator, modeAttribute, parseCSSName, sceneGraphToDesignDocument, sceneNodeToDesignDocument, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit } from "./chunks/behaviours/states/layers.js";
2
+ import { serializeHTML, stateStylesToTailwind, stateTailwindClasses } from "./chunks/behaviours/states/tailwind.js";
3
+ import { exportHTMLBundle } from "./chunks/export/bundle.js";
4
+ import { behaviourArgs } from "./chunks/behaviours/args.js";
5
+ import { BUTTON_RESET, INPUT_RESET } from "./chunks/behaviours/reset.js";
6
+ import { stateStyles } from "./chunks/behaviours/states/model.js";
7
+ import { conditionSelector, stateStylesToCSS } from "./chunks/behaviours/states/css.js";
8
+ import { COMPONENT_STYLINGS, LAYER_COMPONENT_FRAMEWORKS, layerComponents, layerMarkup } from "./chunks/export/components/layers.js";
9
+ import { ICON_PACKAGES, iconPackagesFor, isIconPackage } from "./chunks/export/components/icons.js";
10
+ import { cssExpressionProblem, cssTokenProperty, cssValueTokens, designDocumentToTailwindJSX, featureConditionCSS, modeConditionKey, modeConditionName, parseFeatureCondition, readCustomProperties, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers } from "./chunks/export/index.js";
11
+ import { behaviourControls, booleanOf } from "./chunks/behaviours/controls.js";
12
+ import { controlRoles, groupOf } from "./chunks/behaviours/roles.js";
13
+ export { BUTTON_RESET, COMPONENT_STYLINGS, ICON_PACKAGES, INPUT_RESET, LAYER_COMPONENT_FRAMEWORKS, TOKEN_UNIT_PROPERTY, behaviourArgs, behaviourControls, booleanOf, buildTokenStylesheet, collectionVariables, conditionSelector, controlRoles, createTokenValidator, cssExpressionProblem, cssNameCodeSyntax, cssNameVariableName, cssTokenProperty, cssValueTokens, defaultModeAttributeName, defaultModeCondition, deriveCSSName, designDocumentToTailwindJSX, explicitCSSName, exportHTMLBundle, featureConditionCSS, groupOf, iconPackagesFor, isIconPackage, layerComponents, layerMarkup, loadTokenValidator, modeAttribute, modeConditionKey, modeConditionName, parseCSSName, parseFeatureCondition, readCustomProperties, sceneGraphToDesignDocument, sceneNodeToDesignDocument, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers, serializeHTML, stateStyles, stateStylesToCSS, stateStylesToTailwind, stateTailwindClasses, tokenNumberToCSS, tokenSlug, tokenStylesheet, variableCSSNames, variableNamespace, variableUnit };