@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,477 @@
1
+ import { TOKEN_UNIT_PROPERTY, ownLayerName, parseCSSName, sceneNodeToDesignDocument, tokenSlug } from "../behaviours/states/layers.js";
2
+ import { mergeClassNames, serializeTailwindClasses } from "../behaviours/states/tailwind.js";
3
+ import { SHADER_UTILITIES, shaderEffectAttributes } from "./components/layers.js";
4
+ import valueParser from "postcss-value-parser";
5
+ import { jsx } from "@pairdraw/emit";
6
+ import { parse, toPlainObject } from "css-tree";
7
+ //#region src/export/tailwind-jsx.ts
8
+ /** HTML attribute names that JSX spells differently. */
9
+ const JSX_ATTRIBUTE_NAMES = {
10
+ class: "className",
11
+ for: "htmlFor",
12
+ "xlink:href": "xlinkHref"
13
+ };
14
+ /** React spells SVG's dashed attributes in camel case, such as `fillRule`; data and ARIA stay. */
15
+ function jsxAttributeName(name) {
16
+ const named = JSX_ATTRIBUTE_NAMES[name];
17
+ if (named) return named;
18
+ if (name.startsWith("data-") || name.startsWith("aria-")) return name;
19
+ return name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
20
+ }
21
+ /**
22
+ * Scene text layers become paragraphs, whose margins Tailwind's preflight removes; text laid
23
+ * out in blocks keeps the `<div>` that holds them.
24
+ */
25
+ function tagName(node) {
26
+ return node.sourceSceneNode?.type === "TEXT" && node.tagName === "span" ? "p" : node.tagName;
27
+ }
28
+ function attributes(node, themeVariables) {
29
+ const { class: className, ...attrs } = node.attrs;
30
+ return [
31
+ ["data-name", node.sourceSceneNode && ownLayerName(node.sourceSceneNode)],
32
+ ...Object.entries(attrs),
33
+ ["className", mergeClassNames(className, serializeTailwindClasses(node, themeVariables))]
34
+ ].flatMap(([key, value]) => value === void 0 ? [] : [jsx.attribute(jsxAttributeName(key), jsx.stringValue(value))]);
35
+ }
36
+ /**
37
+ * A layer's shader as the `shaders` library's `<Shader>`, each effect a child with the preset's
38
+ * props, with telemetry off as every Pairdraw export has it.
39
+ */
40
+ function shaderElement(preset, depth) {
41
+ const effect = (at) => (component) => jsx.element(component.type, shaderEffectAttributes(component), (component.children ?? []).map(effect(at + 1)), at);
42
+ return jsx.element("Shader", [jsx.attribute("className", jsx.stringValue(SHADER_UTILITIES)), jsx.attribute("disableTelemetry", null)], preset.components.map(effect(depth + 1)), depth);
43
+ }
44
+ /** How many elements a shader prints, which no layer produced. */
45
+ function shaderElementCount(components = []) {
46
+ return components.reduce((count, component) => count + 1 + shaderElementCount(component.children), 0);
47
+ }
48
+ function element(node, depth, themeVariables) {
49
+ const children = [...node.shader ? [shaderElement(node.shader.preset, depth + 1)] : [], ...node.children.map((child) => jsxNode(child, depth + 1, themeVariables))];
50
+ const inline = children.length === 1 && node.children[0]?.type === "text";
51
+ return jsx.element(tagName(node), attributes(node, themeVariables), children, depth, inline);
52
+ }
53
+ function jsxNode(node, depth, themeVariables) {
54
+ return node.type === "text" ? jsx.text(node.text) : element(node, depth, themeVariables);
55
+ }
56
+ /** Print a design document as Tailwind JSX, one top-level element per block. */
57
+ function designDocumentToTailwindJSX(document) {
58
+ const themeVariables = document.tokens?.themeVariables() ?? [];
59
+ return document.children.map((node) => jsx.printJSX(jsxNode(node, 0, themeVariables))).join("\n\n");
60
+ }
61
+ /** Tailwind JSX for scene nodes, separated by blank lines. */
62
+ function sceneNodesToTailwindJSX(graph, nodeIds, options = {}) {
63
+ return sceneNodesToTailwindJSXWithLayers(graph, nodeIds, options).code;
64
+ }
65
+ function collectLayerIds(node, layerIds) {
66
+ if (node.type === "text") return;
67
+ layerIds.push(node.sourceSceneNodeId ?? node.sourceSceneNode?.id ?? null);
68
+ if (node.shader) {
69
+ const count = 1 + shaderElementCount(node.shader.preset.components);
70
+ for (let index = 0; index < count; index++) layerIds.push(null);
71
+ }
72
+ for (const child of node.children) collectLayerIds(child, layerIds);
73
+ }
74
+ function sceneNodesToTailwindJSXWithLayers(graph, nodeIds, { vectorElement } = {}) {
75
+ const layerIds = [];
76
+ const blocks = [];
77
+ for (const id of nodeIds) {
78
+ const document = sceneNodeToDesignDocument(graph, id, {
79
+ includeSourceIds: false,
80
+ vectorElement
81
+ });
82
+ const code = designDocumentToTailwindJSX(document);
83
+ if (!code) continue;
84
+ blocks.push(code);
85
+ for (const node of document.children) collectLayerIds(node, layerIds);
86
+ }
87
+ return {
88
+ code: blocks.join("\n\n"),
89
+ layerIds
90
+ };
91
+ }
92
+ //#endregion
93
+ //#region src/tokens/conditions.ts
94
+ /** The one feature a prelude tests, when it tests exactly one and nothing else. */
95
+ function onlyFeature(nodes) {
96
+ const [node] = nodes;
97
+ if (nodes.length !== 1) return void 0;
98
+ if (node.type === "Feature") return node;
99
+ if (node.type === "Condition") return onlyFeature(node.children);
100
+ if (node.type === "MediaQueryList") return onlyFeature(node.children);
101
+ if (node.type === "MediaQuery" && !node.modifier && !node.mediaType && node.condition) return onlyFeature([node.condition]);
102
+ }
103
+ function featureValue(node) {
104
+ if (node?.type === "Identifier") return {
105
+ type: "keyword",
106
+ name: node.name.toLowerCase()
107
+ };
108
+ if (node?.type !== "Dimension") return void 0;
109
+ const value = Number(node.value);
110
+ return Number.isFinite(value) ? {
111
+ type: "dimension",
112
+ value,
113
+ unit: node.unit.toLowerCase()
114
+ } : void 0;
115
+ }
116
+ /**
117
+ * Reads a condition with css-tree, so spacing, case and comments do not change what it tests, and
118
+ * only what CSS calls whitespace separates its parts. Undefined for anything but one `@media` or
119
+ * unnamed `@container` rule testing one feature: a selector, `@media screen`, or
120
+ * `@media (a: b) and (c: d)`.
121
+ */
122
+ function parseFeatureCondition(css) {
123
+ const errors = [];
124
+ const sheet = parse(`${css}{}`, {
125
+ list: false,
126
+ positions: false,
127
+ onParseError: (error) => errors.push(error)
128
+ });
129
+ if (errors.length > 0 || sheet.type !== "StyleSheet" || sheet.children.length !== 1) return void 0;
130
+ const [rule] = sheet.children;
131
+ if (rule.type !== "Atrule" || rule.prelude?.type !== "AtrulePrelude") return void 0;
132
+ const name = rule.name.toLowerCase();
133
+ if (name !== "media" && name !== "container") return void 0;
134
+ const feature = onlyFeature(rule.prelude.children);
135
+ const value = feature && featureValue(feature.value);
136
+ return feature && value ? {
137
+ rule: name,
138
+ feature: feature.name.toLowerCase(),
139
+ value
140
+ } : void 0;
141
+ }
142
+ /** The condition as the stylesheet writes it: `@media (max-width: 640px)`. */
143
+ function featureConditionCSS({ rule, feature, value }) {
144
+ return `@${rule} (${feature}: ${value.type === "keyword" ? value.name : `${value.value}${value.unit}`})`;
145
+ }
146
+ //#endregion
147
+ //#region src/tokens/custom-properties.ts
148
+ /** Labels are one line, `Collection: Mode`, as `buildTokenStylesheet` writes above each mode. */
149
+ const LABEL = /^ ([^:\n]+?): ([^\n]+?) $/;
150
+ const ROOT_PSEUDO_CLASSES = /* @__PURE__ */ new Set(["root", "host"]);
151
+ const CONDITION_AT_RULES = /* @__PURE__ */ new Set([
152
+ "media",
153
+ "supports",
154
+ "container"
155
+ ]);
156
+ function textOf(reader, node) {
157
+ const { loc } = node;
158
+ return loc ? reader.css.slice(loc.start.offset, loc.end.offset) : "";
159
+ }
160
+ /** `:root`, `html`, or `:host`, alone. */
161
+ function isRootSimple(node) {
162
+ if (node?.type === "TypeSelector") return node.name.toLowerCase() === "html";
163
+ return node?.type === "PseudoClassSelector" && ROOT_PSEUDO_CLASSES.has(node.name.toLowerCase()) && !node.children;
164
+ }
165
+ function isRootSelector(selector) {
166
+ return selector.children.length === 1 && isRootSimple(selector.children[0]);
167
+ }
168
+ /**
169
+ * A selector with the root it is written on taken off, `:root.dark` as `.dark`, or undefined for
170
+ * one with a combinator, which scopes part of a page rather than switching a mode.
171
+ */
172
+ function modeSelector(reader, selector) {
173
+ if (selector.children.some((node) => node.type === "Combinator")) return void 0;
174
+ const parts = isRootSimple(selector.children[0]) ? selector.children.slice(1) : selector.children;
175
+ const first = parts.at(0);
176
+ const last = parts.at(-1);
177
+ if (!first?.loc || !last?.loc) return void 0;
178
+ return reader.css.slice(first.loc.start.offset, last.loc.end.offset);
179
+ }
180
+ function attributeOf(selector) {
181
+ const parts = isRootSimple(selector.children[0]) ? selector.children.slice(1) : selector.children;
182
+ const only = parts.at(0);
183
+ if (parts.length !== 1 || only?.type !== "AttributeSelector" || only.matcher !== "=") return;
184
+ const value = only.value?.type === "String" ? only.value.value : only.value?.name;
185
+ return value === void 0 ? void 0 : {
186
+ name: only.name.name,
187
+ value
188
+ };
189
+ }
190
+ /**
191
+ * The mode a condition names by itself: the value of `[data-theme="dark"]`, the class of `.dark`,
192
+ * or the scheme of `@media (prefers-color-scheme: dark)`. Undefined for other conditions.
193
+ */
194
+ function modeConditionName(condition, attribute) {
195
+ if (attribute) return attribute.value;
196
+ const className = /^\.(-?[_a-z][\w-]*)$/i.exec(condition)?.[1];
197
+ if (className) return className;
198
+ const feature = parseFeatureCondition(condition);
199
+ if (feature?.feature === "prefers-color-scheme" && feature.value.type === "keyword") return feature.value.name;
200
+ }
201
+ /**
202
+ * The comment just above a mode's block as its label. An ordinary comment such as
203
+ * `/* TODO: fix later *\/` above `.dark` is none: its mode is not the one `.dark` names.
204
+ */
205
+ function labelBefore(reader, start, scope) {
206
+ if (scope.condition === null) return void 0;
207
+ const comment = reader.comments.findLast((candidate) => candidate.end <= start);
208
+ if (!comment || reader.css.slice(comment.end, start).trim() !== "") return void 0;
209
+ const match = LABEL.exec(comment.text);
210
+ if (!match) return void 0;
211
+ const [, collection, mode] = match;
212
+ const named = modeConditionName(scope.condition, scope.attribute);
213
+ return named === void 0 || tokenSlug(named) === tokenSlug(mode) || scope.attribute?.name === `data-${tokenSlug(collection)}` ? {
214
+ collection,
215
+ mode
216
+ } : void 0;
217
+ }
218
+ /** The whitespace a line starts with. */
219
+ function indentAt(css, offset) {
220
+ const lineStart = css.lastIndexOf("\n", offset - 1) + 1;
221
+ return /^[ \t]*/.exec(css.slice(lineStart))?.[0] ?? "";
222
+ }
223
+ function declarationsOf(reader, block) {
224
+ const declarations = [];
225
+ for (const node of block) {
226
+ if (node.type !== "Declaration" || !node.property.startsWith("--")) continue;
227
+ const { loc } = node.value;
228
+ if (!loc || node.property.length <= 2 || node.property.includes("*")) continue;
229
+ const raw = reader.css.slice(loc.start.offset, loc.end.offset);
230
+ const value = raw.trim();
231
+ if (!value) continue;
232
+ const start = loc.start.offset + (raw.length - raw.trimStart().length);
233
+ declarations.push({
234
+ name: node.property.slice(2),
235
+ value,
236
+ start,
237
+ end: start + value.length
238
+ });
239
+ }
240
+ return declarations;
241
+ }
242
+ function declaresCustomProperties(nodes) {
243
+ return nodes.some((node) => {
244
+ if (node.type === "Declaration") return node.property.startsWith("--");
245
+ if (node.type === "Rule") return declaresCustomProperties(node.block.children);
246
+ if (node.type === "Atrule") return declaresCustomProperties(node.block?.children ?? []);
247
+ return false;
248
+ });
249
+ }
250
+ /**
251
+ * A block's contents read as declarations. css-tree reads the block of an at-rule it does not
252
+ * know, such as Tailwind's `@theme`, as rules, which turns declarations before a nested
253
+ * `@keyframes` into one rule with a raw prelude.
254
+ */
255
+ function declarationList(reader, block) {
256
+ if (block.type !== "Block" || !block.loc) return [];
257
+ const start = block.loc.start.offset + 1;
258
+ const list = toPlainObject(parse(reader.css.slice(start, block.loc.end.offset - 1), {
259
+ context: "declarationList",
260
+ positions: true,
261
+ offset: start
262
+ }));
263
+ return list.type === "DeclarationList" ? list.children : [];
264
+ }
265
+ function addScope(reader, block, scope, labelAt, children = block.type === "Block" ? block.children : []) {
266
+ if (block.type !== "Block" || !block.loc) return;
267
+ const declarations = declarationsOf(reader, children);
268
+ const first = declarations.at(0);
269
+ if (!first) return;
270
+ reader.sheet.scopes.push({
271
+ condition: scope.condition,
272
+ ...scope.attribute ? { attribute: scope.attribute } : {},
273
+ label: labelBefore(reader, labelAt, scope),
274
+ declarations,
275
+ insertAt: block.loc.end.offset - 1,
276
+ indent: indentAt(reader.css, first.start)
277
+ });
278
+ }
279
+ /** A rule at the top of the sheet or of a `@layer`: the base set, or a mode by its selector. */
280
+ function readRule(reader, rule) {
281
+ if (!declaresCustomProperties(rule.block.children)) return;
282
+ const start = rule.loc?.start.offset ?? 0;
283
+ if (rule.prelude.type !== "SelectorList") {
284
+ reader.sheet.skipped.push(textOf(reader, rule.prelude));
285
+ return;
286
+ }
287
+ const selectors = rule.prelude.children.filter((node) => node.type === "Selector");
288
+ if (selectors.some(isRootSelector)) {
289
+ addScope(reader, rule.block, { condition: null }, start);
290
+ return;
291
+ }
292
+ const conditions = selectors.map((selector) => modeSelector(reader, selector));
293
+ if (conditions.length === 0 || conditions.some((condition) => condition === void 0)) {
294
+ reader.sheet.skipped.push(textOf(reader, rule.prelude));
295
+ return;
296
+ }
297
+ const attribute = selectors.length === 1 ? attributeOf(selectors[0]) : void 0;
298
+ const condition = attribute ? `[${attribute.name}="${attribute.value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}"]` : conditions.join(", ");
299
+ addScope(reader, rule.block, {
300
+ condition,
301
+ attribute
302
+ }, start);
303
+ }
304
+ /** `@media (prefers-color-scheme: dark)` written the way the token stylesheet writes it. */
305
+ function atRuleCondition(reader, rule) {
306
+ const prelude = rule.prelude ? textOf(reader, rule.prelude).replaceAll(/\s+/g, " ").trim() : "";
307
+ const written = `@${rule.name.toLowerCase()} ${prelude}`;
308
+ const feature = parseFeatureCondition(written);
309
+ return feature ? featureConditionCSS(feature) : written;
310
+ }
311
+ function readAtRule(reader, rule) {
312
+ const name = rule.name.toLowerCase();
313
+ const children = rule.block?.children ?? [];
314
+ const start = rule.loc?.start.offset ?? 0;
315
+ if (name === "layer") {
316
+ readNodes(reader, children);
317
+ return;
318
+ }
319
+ if (!rule.block) return;
320
+ if (!CONDITION_AT_RULES.has(name)) {
321
+ const declared = declarationList(reader, rule.block);
322
+ if (!declaresCustomProperties(declared)) return;
323
+ if (name === "theme") addScope(reader, rule.block, { condition: null }, start, declared);
324
+ else reader.sheet.skipped.push(textOf(reader, rule).split("{")[0].trim());
325
+ return;
326
+ }
327
+ if (!declaresCustomProperties(children)) return;
328
+ const condition = atRuleCondition(reader, rule);
329
+ for (const child of children) {
330
+ if (child.type === "Rule" && child.prelude.type === "SelectorList") {
331
+ const selectors = child.prelude.children.filter((node) => node.type === "Selector");
332
+ if (selectors.length > 0 && selectors.every(isRootSelector)) {
333
+ addScope(reader, child.block, { condition }, start);
334
+ continue;
335
+ }
336
+ }
337
+ if (declaresCustomProperties([child])) reader.sheet.skipped.push(`${condition} ${textOf(reader, child).split("{")[0].trim()}`);
338
+ }
339
+ }
340
+ function readNodes(reader, nodes) {
341
+ for (const node of nodes) if (node.type === "Rule") readRule(reader, node);
342
+ else if (node.type === "Atrule") readAtRule(reader, node);
343
+ }
344
+ /**
345
+ * The custom properties a stylesheet declares, by the scope they apply in: the inverse of
346
+ * `buildTokenStylesheet`. It reads the base set, selector modes, and `:root` blocks inside
347
+ * `@media`, `@supports`, and `@container`, also inside `@layer`; a scope it cannot read as a mode,
348
+ * such as `.card .title` or a selector inside a media query, is listed in `skipped`.
349
+ */
350
+ function readCustomProperties(css) {
351
+ const comments = [];
352
+ const reader = {
353
+ css,
354
+ comments,
355
+ sheet: {
356
+ scopes: [],
357
+ skipped: []
358
+ }
359
+ };
360
+ const sheet = toPlainObject(parse(css, {
361
+ positions: true,
362
+ onComment: (text, loc) => comments.push({
363
+ text,
364
+ start: loc.start.offset,
365
+ end: loc.end.offset
366
+ })
367
+ }));
368
+ if (sheet.type === "StyleSheet") readNodes(reader, sheet.children);
369
+ return reader.sheet;
370
+ }
371
+ /**
372
+ * A mode's condition in the form `readCustomProperties` gives it, so conditions written
373
+ * differently compare equal: `:root[data-theme=dark]` and `[data-theme="dark"]`, or
374
+ * `@media (prefers-color-scheme:dark)` and `@media (prefers-color-scheme: dark)`.
375
+ */
376
+ function modeConditionKey(condition) {
377
+ const trimmed = condition.trim();
378
+ const probe = trimmed.startsWith("@") ? `${trimmed} { :root { --probe: 0 } }` : `${trimmed} { --probe: 0 }`;
379
+ try {
380
+ return readCustomProperties(probe).scopes[0]?.condition ?? trimmed;
381
+ } catch {
382
+ return trimmed;
383
+ }
384
+ }
385
+ //#endregion
386
+ //#region src/tokens/expression.ts
387
+ const OPERATORS = /* @__PURE__ */ new Set([
388
+ "+",
389
+ "-",
390
+ "*",
391
+ "/"
392
+ ]);
393
+ /** `var(--name)` with nothing else inside, which an editor can show as the variable it names. */
394
+ function isReference(node) {
395
+ if (node.value !== "var" || node.unclosed || node.nodes.length !== 1) return false;
396
+ const [argument] = node.nodes;
397
+ return argument.type === "word" && argument.value.startsWith("--");
398
+ }
399
+ function wordKind(word) {
400
+ if (word.startsWith("--")) return "property";
401
+ if (OPERATORS.has(word)) return "operator";
402
+ return valueParser.unit(word) ? "number" : "keyword";
403
+ }
404
+ /**
405
+ * The tokens of one CSS value, such as `clamp(1rem, 4vw, var(--space-md))`, in order and with
406
+ * their source ranges. Reading tolerates half-typed values: an unclosed function still gives
407
+ * its name and its `(`.
408
+ */
409
+ function cssValueTokens(source) {
410
+ const tokens = [];
411
+ const push = (kind, from, to) => tokens.push({
412
+ kind,
413
+ text: source.slice(from, to),
414
+ from,
415
+ to
416
+ });
417
+ const walk = (nodes) => {
418
+ for (const node of nodes) if (node.type === "function") {
419
+ if (isReference(node)) {
420
+ push("reference", node.sourceIndex, node.sourceEndIndex);
421
+ continue;
422
+ }
423
+ const open = node.sourceIndex + node.value.length;
424
+ if (node.value) push("function", node.sourceIndex, open);
425
+ push("paren", open, open + 1);
426
+ walk(node.nodes);
427
+ if (!node.unclosed) push("paren", node.sourceEndIndex - 1, node.sourceEndIndex);
428
+ } else if (node.type === "word") push(wordKind(node.value), node.sourceIndex, node.sourceEndIndex);
429
+ else if (node.type === "div") push(node.value === "/" ? "operator" : "separator", node.sourceIndex, node.sourceEndIndex);
430
+ else if (node.type === "string") push("string", node.sourceIndex, node.sourceEndIndex);
431
+ };
432
+ walk(valueParser(source).nodes);
433
+ return tokens;
434
+ }
435
+ /** The custom property a token names, in `var(--name)` or as a bare `--name`. */
436
+ function cssTokenProperty(token) {
437
+ if (token.kind !== "reference" && token.kind !== "property") return void 0;
438
+ const name = parseCSSName(token.text);
439
+ return name ? `--${name}` : void 0;
440
+ }
441
+ function hasUnclosedFunction(nodes) {
442
+ return nodes.some((node) => node.type === "function" && (node.unclosed || hasUnclosedFunction(node.nodes)));
443
+ }
444
+ /**
445
+ * Why a CSS expression cannot stand in for a token, if it cannot. The token validator checks it
446
+ * is one declaration; then it must name only tokens that exist and suit the token's unit, which
447
+ * `supports` checks where a browser can type values. A value holding `var()` passes that last
448
+ * check until it is used, so only its names are checked.
449
+ */
450
+ function cssExpressionProblem(css, unit, tokens, validator, supports) {
451
+ if (!validator.declaration("token", css)) return hasUnclosedFunction(valueParser(css).nodes) ? { kind: "unclosed" } : { kind: "syntax" };
452
+ const parsed = cssValueTokens(css);
453
+ const negated = parsed.findIndex((token) => token.kind === "function" && token.text === "-var");
454
+ if (negated !== -1) {
455
+ const property = parsed.slice(negated).map(cssTokenProperty).find(Boolean);
456
+ if (property) return {
457
+ kind: "negated-reference",
458
+ property
459
+ };
460
+ }
461
+ for (const token of parsed) {
462
+ const name = cssTokenProperty(token);
463
+ if (name && !tokens.has(name)) return {
464
+ kind: "unknown-token",
465
+ name
466
+ };
467
+ }
468
+ const property = TOKEN_UNIT_PROPERTY[unit];
469
+ return !supports || supports(property, css) ? void 0 : {
470
+ kind: "invalid",
471
+ property
472
+ };
473
+ }
474
+ //#endregion
475
+ export { cssExpressionProblem, cssTokenProperty, cssValueTokens, designDocumentToTailwindJSX, featureConditionCSS, modeConditionKey, modeConditionName, parseFeatureCondition, readCustomProperties, sceneNodesToTailwindJSX, sceneNodesToTailwindJSXWithLayers };
476
+
477
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/export/tailwind-jsx.ts","../../../src/tokens/conditions.ts","../../../src/tokens/custom-properties.ts","../../../src/tokens/expression.ts"],"sourcesContent":["import { jsx, type SyntaxNode } from '@pairdraw/emit'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\nimport type { ShaderComponent, ShaderPreset } from '@pairdraw/scene-graph/shaders'\n\nimport type { DesignDocument, DesignElement, DesignNode } from '../types'\nimport { shaderEffectAttributes } from './components/shaders'\nimport { SHADER_UTILITIES } from './components/styling'\nimport { mergeClassNames, serializeTailwindClasses } from './html'\nimport {\n ownLayerName,\n sceneNodeToDesignDocument,\n type SceneGraphToDesignOptions\n} from './projection'\n\n/** Engine services the projection takes, such as drawing vector layers as SVG. */\ntype ProjectionServices = Pick<SceneGraphToDesignOptions, 'vectorElement'>\n\n/** HTML attribute names that JSX spells differently. */\nconst JSX_ATTRIBUTE_NAMES: Record<string, string> = {\n class: 'className',\n for: 'htmlFor',\n 'xlink:href': 'xlinkHref'\n}\n\n/** React spells SVG's dashed attributes in camel case, such as `fillRule`; data and ARIA stay. */\nfunction jsxAttributeName(name: string): string {\n const named = JSX_ATTRIBUTE_NAMES[name]\n if (named) return named\n if (name.startsWith('data-') || name.startsWith('aria-')) return name\n return name.replace(/-([a-z])/g, (_, letter: string) => letter.toUpperCase())\n}\n\n/**\n * Scene text layers become paragraphs, whose margins Tailwind's preflight removes; text laid\n * out in blocks keeps the `<div>` that holds them.\n */\nfunction tagName(node: DesignElement): string {\n return node.sourceSceneNode?.type === 'TEXT' && node.tagName === 'span' ? 'p' : node.tagName\n}\n\nfunction attributes(node: DesignElement, themeVariables: readonly string[]): SyntaxNode[] {\n const { class: className, ...attrs } = node.attrs\n const entries: [string, string | undefined][] = [\n ['data-name', node.sourceSceneNode && ownLayerName(node.sourceSceneNode)],\n ...Object.entries(attrs),\n ['className', mergeClassNames(className, serializeTailwindClasses(node, themeVariables))]\n ]\n return entries.flatMap(([key, value]) =>\n value === undefined ? [] : [jsx.attribute(jsxAttributeName(key), jsx.stringValue(value))]\n )\n}\n\n/**\n * A layer's shader as the `shaders` library's `<Shader>`, each effect a child with the preset's\n * props, with telemetry off as every Pairdraw export has it.\n */\nfunction shaderElement(preset: ShaderPreset, depth: number): SyntaxNode {\n const effect =\n (at: number) =>\n (component: ShaderComponent): SyntaxNode =>\n jsx.element(\n component.type,\n shaderEffectAttributes(component),\n (component.children ?? []).map(effect(at + 1)),\n at\n )\n return jsx.element(\n 'Shader',\n [\n jsx.attribute('className', jsx.stringValue(SHADER_UTILITIES)),\n jsx.attribute('disableTelemetry', null)\n ],\n preset.components.map(effect(depth + 1)),\n depth\n )\n}\n\n/** How many elements a shader prints, which no layer produced. */\nfunction shaderElementCount(components: readonly ShaderComponent[] = []): number {\n return components.reduce(\n (count, component) => count + 1 + shaderElementCount(component.children),\n 0\n )\n}\n\nfunction element(\n node: DesignElement,\n depth: number,\n themeVariables: readonly string[]\n): SyntaxNode {\n const children = [\n ...(node.shader ? [shaderElement(node.shader.preset, depth + 1)] : []),\n ...node.children.map((child) => jsxNode(child, depth + 1, themeVariables))\n ]\n // A lone text child stays on the element's line.\n const inline = children.length === 1 && node.children[0]?.type === 'text'\n return jsx.element(tagName(node), attributes(node, themeVariables), children, depth, inline)\n}\n\nfunction jsxNode(node: DesignNode, depth: number, themeVariables: readonly string[]): SyntaxNode {\n return node.type === 'text' ? jsx.text(node.text) : element(node, depth, themeVariables)\n}\n\n/** Print a design document as Tailwind JSX, one top-level element per block. */\nexport function designDocumentToTailwindJSX(document: DesignDocument): string {\n const themeVariables = document.tokens?.themeVariables() ?? []\n return document.children\n .map((node) => jsx.printJSX(jsxNode(node, 0, themeVariables)))\n .join('\\n\\n')\n}\n\n/** Tailwind JSX for scene nodes, separated by blank lines. */\nexport function sceneNodesToTailwindJSX(\n graph: SceneGraph,\n nodeIds: string[],\n options: ProjectionServices = {}\n): string {\n return sceneNodesToTailwindJSXWithLayers(graph, nodeIds, options).code\n}\n\n/** Tailwind JSX with the layer behind each element, in the order elements open. */\nexport interface TailwindJSXWithLayers {\n code: string\n /** One entry per JSX element in pre-order; `null` for an element no layer produced. */\n layerIds: Array<string | null>\n}\n\nfunction collectLayerIds(node: DesignNode, layerIds: Array<string | null>): void {\n if (node.type === 'text') return\n layerIds.push(node.sourceSceneNodeId ?? node.sourceSceneNode?.id ?? null)\n if (node.shader) {\n const count = 1 + shaderElementCount(node.shader.preset.components)\n for (let index = 0; index < count; index++) layerIds.push(null)\n }\n for (const child of node.children) collectLayerIds(child, layerIds)\n}\n\nexport function sceneNodesToTailwindJSXWithLayers(\n graph: SceneGraph,\n nodeIds: string[],\n { vectorElement }: ProjectionServices = {}\n): TailwindJSXWithLayers {\n const layerIds: Array<string | null> = []\n const blocks: string[] = []\n for (const id of nodeIds) {\n const document = sceneNodeToDesignDocument(graph, id, {\n includeSourceIds: false,\n vectorElement\n })\n const code = designDocumentToTailwindJSX(document)\n if (!code) continue\n blocks.push(code)\n for (const node of document.children) collectLayerIds(node, layerIds)\n }\n return { code: blocks.join('\\n\\n'), layerIds }\n}\n","// eslint-disable-next-line pairdraw/no-mixed-case-acronym-identifiers -- Upstream export spelling.\nimport { parse, type CssNodePlain as CSSNodePlain, type FeaturePlain } from 'css-tree'\n\n/** What a feature is tested against: a keyword such as `dark`, or a length such as `640px`. */\ntype FeatureValue =\n | { type: 'keyword'; name: string }\n | { type: 'dimension'; value: number; unit: string }\n\n/** An at-rule that tests one feature: `@media (prefers-color-scheme: dark)`. */\nexport interface FeatureCondition {\n rule: 'media' | 'container'\n /** `prefers-color-scheme`, lowercase. */\n feature: string\n value: FeatureValue\n}\n\n/** The one feature a prelude tests, when it tests exactly one and nothing else. */\nfunction onlyFeature(nodes: readonly CSSNodePlain[]): FeaturePlain | undefined {\n const [node] = nodes\n if (nodes.length !== 1) return undefined\n if (node.type === 'Feature') return node\n if (node.type === 'Condition') return onlyFeature(node.children)\n if (node.type === 'MediaQueryList') return onlyFeature(node.children)\n if (node.type === 'MediaQuery' && !node.modifier && !node.mediaType && node.condition)\n return onlyFeature([node.condition])\n return undefined\n}\n\nfunction featureValue(node: FeaturePlain['value']): FeatureValue | undefined {\n if (node?.type === 'Identifier') return { type: 'keyword', name: node.name.toLowerCase() }\n if (node?.type !== 'Dimension') return undefined\n const value = Number(node.value)\n return Number.isFinite(value)\n ? { type: 'dimension', value, unit: node.unit.toLowerCase() }\n : undefined\n}\n\n/**\n * Reads a condition with css-tree, so spacing, case and comments do not change what it tests, and\n * only what CSS calls whitespace separates its parts. Undefined for anything but one `@media` or\n * unnamed `@container` rule testing one feature: a selector, `@media screen`, or\n * `@media (a: b) and (c: d)`.\n */\nexport function parseFeatureCondition(css: string): FeatureCondition | undefined {\n const errors: unknown[] = []\n const sheet = parse(`${css}{}`, {\n list: false,\n positions: false,\n onParseError: (error) => errors.push(error)\n })\n if (errors.length > 0 || sheet.type !== 'StyleSheet' || sheet.children.length !== 1)\n return undefined\n const [rule] = sheet.children\n if (rule.type !== 'Atrule' || rule.prelude?.type !== 'AtrulePrelude') return undefined\n const name = rule.name.toLowerCase()\n if (name !== 'media' && name !== 'container') return undefined\n const feature = onlyFeature(rule.prelude.children)\n const value = feature && featureValue(feature.value)\n return feature && value ? { rule: name, feature: feature.name.toLowerCase(), value } : undefined\n}\n\n/** The condition as the stylesheet writes it: `@media (max-width: 640px)`. */\nexport function featureConditionCSS({ rule, feature, value }: FeatureCondition): string {\n const written = value.type === 'keyword' ? value.name : `${value.value}${value.unit}`\n return `@${rule} (${feature}: ${written})`\n}\n","import {\n parse,\n toPlainObject,\n // eslint-disable-next-line pairdraw/no-mixed-case-acronym-identifiers -- Upstream export spelling.\n type CssNodePlain as CSSNodePlain,\n type SelectorPlain\n} from 'css-tree'\n\nimport { featureConditionCSS, parseFeatureCondition } from './conditions'\nimport { tokenSlug } from './names'\n\n/** One custom property a stylesheet declares: `--brand: #ff5b2e`. */\nexport interface CustomPropertyDeclaration {\n /** The property without its leading `--`. */\n name: string\n /** The value as written, trimmed, without `!important`. */\n value: string\n /** Where the trimmed value sits in the source, so a write-back replaces only it. */\n start: number\n end: number\n}\n\n/**\n * A block of custom properties and the scope it applies in. The base set is `:root`, `html`,\n * `:host`, or Tailwind's `@theme`; every other scope is a mode's condition, as the token\n * stylesheet writes it: a selector such as `[data-theme=\"dark\"]` or `.dark`, or an at-rule\n * prelude such as `@media (prefers-color-scheme: dark)` around a `:root` block.\n */\nexport interface CustomPropertyScope {\n /** Null for the base set. */\n condition: string | null\n /** The attribute and value a lone `[name=\"value\"]` selector switches on. */\n attribute?: { name: string; value: string }\n /**\n * `Collection: Mode` from a comment just above a mode's block, as the token stylesheet writes\n * it. A comment is a label only where its mode is the one the condition names, such as `Dark`\n * above `.dark`, or where the condition names none, such as `@media (min-width: 40rem)`.\n */\n label?: { collection: string; mode: string }\n declarations: CustomPropertyDeclaration[]\n /** The offset of the block's closing brace, where new declarations go. */\n insertAt: number\n /** The indentation of the block's declarations. */\n indent: string\n}\n\nexport interface CustomPropertySheet {\n scopes: CustomPropertyScope[]\n /** Selectors and at-rules that declare custom properties but name no mode, as written. */\n skipped: string[]\n}\n\ninterface Comment {\n text: string\n start: number\n end: number\n}\n\ninterface Reader {\n css: string\n comments: Comment[]\n sheet: CustomPropertySheet\n}\n\n/** Labels are one line, `Collection: Mode`, as `buildTokenStylesheet` writes above each mode. */\nconst LABEL = /^ ([^:\\n]+?): ([^\\n]+?) $/\n\nconst ROOT_PSEUDO_CLASSES = new Set(['root', 'host'])\nconst CONDITION_AT_RULES = new Set(['media', 'supports', 'container'])\n\nfunction textOf(reader: Reader, node: CSSNodePlain): string {\n const { loc } = node\n return loc ? reader.css.slice(loc.start.offset, loc.end.offset) : ''\n}\n\n/** `:root`, `html`, or `:host`, alone. */\nfunction isRootSimple(node: CSSNodePlain | undefined): boolean {\n if (node?.type === 'TypeSelector') return node.name.toLowerCase() === 'html'\n return (\n node?.type === 'PseudoClassSelector' &&\n ROOT_PSEUDO_CLASSES.has(node.name.toLowerCase()) &&\n !node.children\n )\n}\n\nfunction isRootSelector(selector: SelectorPlain): boolean {\n return selector.children.length === 1 && isRootSimple(selector.children[0])\n}\n\n/**\n * A selector with the root it is written on taken off, `:root.dark` as `.dark`, or undefined for\n * one with a combinator, which scopes part of a page rather than switching a mode.\n */\nfunction modeSelector(reader: Reader, selector: SelectorPlain): string | undefined {\n if (selector.children.some((node) => node.type === 'Combinator')) return undefined\n const parts = isRootSimple(selector.children[0]) ? selector.children.slice(1) : selector.children\n const first = parts.at(0)\n const last = parts.at(-1)\n if (!first?.loc || !last?.loc) return undefined\n return reader.css.slice(first.loc.start.offset, last.loc.end.offset)\n}\n\nfunction attributeOf(selector: SelectorPlain): CustomPropertyScope['attribute'] {\n const parts = isRootSimple(selector.children[0]) ? selector.children.slice(1) : selector.children\n const only = parts.at(0)\n if (parts.length !== 1 || only?.type !== 'AttributeSelector' || only.matcher !== '=') {\n return undefined\n }\n const value = only.value?.type === 'String' ? only.value.value : only.value?.name\n return value === undefined ? undefined : { name: only.name.name, value }\n}\n\n/**\n * The mode a condition names by itself: the value of `[data-theme=\"dark\"]`, the class of `.dark`,\n * or the scheme of `@media (prefers-color-scheme: dark)`. Undefined for other conditions.\n */\nexport function modeConditionName(\n condition: string,\n attribute?: CustomPropertyScope['attribute']\n): string | undefined {\n if (attribute) return attribute.value\n const className = /^\\.(-?[_a-z][\\w-]*)$/i.exec(condition)?.[1]\n if (className) return className\n const feature = parseFeatureCondition(condition)\n if (feature?.feature === 'prefers-color-scheme' && feature.value.type === 'keyword')\n return feature.value.name\n return undefined\n}\n\n/**\n * The comment just above a mode's block as its label. An ordinary comment such as\n * `/* TODO: fix later *\\/` above `.dark` is none: its mode is not the one `.dark` names.\n */\nfunction labelBefore(\n reader: Reader,\n start: number,\n scope: Pick<CustomPropertyScope, 'condition' | 'attribute'>\n): CustomPropertyScope['label'] {\n if (scope.condition === null) return undefined\n const comment = reader.comments.findLast((candidate) => candidate.end <= start)\n if (!comment || reader.css.slice(comment.end, start).trim() !== '') return undefined\n const match = LABEL.exec(comment.text)\n if (!match) return undefined\n const [, collection, mode] = match\n const named = modeConditionName(scope.condition, scope.attribute)\n const fits =\n named === undefined ||\n tokenSlug(named) === tokenSlug(mode) ||\n scope.attribute?.name === `data-${tokenSlug(collection)}`\n return fits ? { collection, mode } : undefined\n}\n\n/** The whitespace a line starts with. */\nfunction indentAt(css: string, offset: number): string {\n const lineStart = css.lastIndexOf('\\n', offset - 1) + 1\n return /^[ \\t]*/.exec(css.slice(lineStart))?.[0] ?? ''\n}\n\nfunction declarationsOf(reader: Reader, block: CSSNodePlain[]): CustomPropertyDeclaration[] {\n const declarations: CustomPropertyDeclaration[] = []\n for (const node of block) {\n if (node.type !== 'Declaration' || !node.property.startsWith('--')) continue\n const { loc } = node.value\n // Tailwind's `--color-*: initial` resets a namespace; it declares no property.\n if (!loc || node.property.length <= 2 || node.property.includes('*')) continue\n const raw = reader.css.slice(loc.start.offset, loc.end.offset)\n const value = raw.trim()\n if (!value) continue\n const start = loc.start.offset + (raw.length - raw.trimStart().length)\n declarations.push({ name: node.property.slice(2), value, start, end: start + value.length })\n }\n return declarations\n}\n\nfunction declaresCustomProperties(nodes: readonly CSSNodePlain[]): boolean {\n return nodes.some((node) => {\n if (node.type === 'Declaration') return node.property.startsWith('--')\n if (node.type === 'Rule') return declaresCustomProperties(node.block.children)\n if (node.type === 'Atrule') return declaresCustomProperties(node.block?.children ?? [])\n return false\n })\n}\n\n/**\n * A block's contents read as declarations. css-tree reads the block of an at-rule it does not\n * know, such as Tailwind's `@theme`, as rules, which turns declarations before a nested\n * `@keyframes` into one rule with a raw prelude.\n */\nfunction declarationList(reader: Reader, block: CSSNodePlain): CSSNodePlain[] {\n if (block.type !== 'Block' || !block.loc) return []\n const start = block.loc.start.offset + 1\n const list = toPlainObject(\n parse(reader.css.slice(start, block.loc.end.offset - 1), {\n context: 'declarationList',\n positions: true,\n offset: start\n })\n )\n return list.type === 'DeclarationList' ? list.children : []\n}\n\nfunction addScope(\n reader: Reader,\n block: CSSNodePlain,\n scope: Pick<CustomPropertyScope, 'condition' | 'attribute'>,\n labelAt: number,\n children: CSSNodePlain[] = block.type === 'Block' ? block.children : []\n) {\n if (block.type !== 'Block' || !block.loc) return\n const declarations = declarationsOf(reader, children)\n const first = declarations.at(0)\n if (!first) return\n reader.sheet.scopes.push({\n condition: scope.condition,\n ...(scope.attribute ? { attribute: scope.attribute } : {}),\n label: labelBefore(reader, labelAt, scope),\n declarations,\n insertAt: block.loc.end.offset - 1,\n indent: indentAt(reader.css, first.start)\n })\n}\n\n/** A rule at the top of the sheet or of a `@layer`: the base set, or a mode by its selector. */\nfunction readRule(reader: Reader, rule: Extract<CSSNodePlain, { type: 'Rule' }>) {\n if (!declaresCustomProperties(rule.block.children)) return\n const start = rule.loc?.start.offset ?? 0\n if (rule.prelude.type !== 'SelectorList') {\n reader.sheet.skipped.push(textOf(reader, rule.prelude))\n return\n }\n const selectors = rule.prelude.children.filter((node) => node.type === 'Selector')\n if (selectors.some(isRootSelector)) {\n addScope(reader, rule.block, { condition: null }, start)\n return\n }\n const conditions = selectors.map((selector) => modeSelector(reader, selector))\n if (conditions.length === 0 || conditions.some((condition) => condition === undefined)) {\n reader.sheet.skipped.push(textOf(reader, rule.prelude))\n return\n }\n const attribute = selectors.length === 1 ? attributeOf(selectors[0]) : undefined\n const condition = attribute\n ? `[${attribute.name}=\"${attribute.value.replaceAll('\\\\', '\\\\\\\\').replaceAll('\"', '\\\\\"')}\"]`\n : conditions.join(', ')\n addScope(reader, rule.block, { condition, attribute }, start)\n}\n\n/** `@media (prefers-color-scheme: dark)` written the way the token stylesheet writes it. */\nfunction atRuleCondition(reader: Reader, rule: Extract<CSSNodePlain, { type: 'Atrule' }>) {\n const prelude = rule.prelude ? textOf(reader, rule.prelude).replaceAll(/\\s+/g, ' ').trim() : ''\n const written = `@${rule.name.toLowerCase()} ${prelude}`\n const feature = parseFeatureCondition(written)\n return feature ? featureConditionCSS(feature) : written\n}\n\nfunction readAtRule(reader: Reader, rule: Extract<CSSNodePlain, { type: 'Atrule' }>) {\n const name = rule.name.toLowerCase()\n const children = rule.block?.children ?? []\n const start = rule.loc?.start.offset ?? 0\n if (name === 'layer') {\n readNodes(reader, children)\n return\n }\n if (!rule.block) return\n if (!CONDITION_AT_RULES.has(name)) {\n const declared = declarationList(reader, rule.block)\n if (!declaresCustomProperties(declared)) return\n if (name === 'theme') addScope(reader, rule.block, { condition: null }, start, declared)\n else reader.sheet.skipped.push(textOf(reader, rule).split('{')[0].trim())\n return\n }\n if (!declaresCustomProperties(children)) return\n const condition = atRuleCondition(reader, rule)\n for (const child of children) {\n if (child.type === 'Rule' && child.prelude.type === 'SelectorList') {\n const selectors = child.prelude.children.filter((node) => node.type === 'Selector')\n if (selectors.length > 0 && selectors.every(isRootSelector)) {\n // A comment above the at-rule labels it, as the stylesheet writes one above each mode.\n addScope(reader, child.block, { condition }, start)\n continue\n }\n }\n if (declaresCustomProperties([child]))\n reader.sheet.skipped.push(`${condition} ${textOf(reader, child).split('{')[0].trim()}`)\n }\n}\n\nfunction readNodes(reader: Reader, nodes: readonly CSSNodePlain[]) {\n for (const node of nodes) {\n if (node.type === 'Rule') readRule(reader, node)\n else if (node.type === 'Atrule') readAtRule(reader, node)\n }\n}\n\n/**\n * The custom properties a stylesheet declares, by the scope they apply in: the inverse of\n * `buildTokenStylesheet`. It reads the base set, selector modes, and `:root` blocks inside\n * `@media`, `@supports`, and `@container`, also inside `@layer`; a scope it cannot read as a mode,\n * such as `.card .title` or a selector inside a media query, is listed in `skipped`.\n */\nexport function readCustomProperties(css: string): CustomPropertySheet {\n const comments: Comment[] = []\n const reader: Reader = { css, comments, sheet: { scopes: [], skipped: [] } }\n // Plain objects from a full parse: with `list: false`, css-tree leaves rule preludes raw.\n const sheet = toPlainObject(\n parse(css, {\n positions: true,\n onComment: (text, loc) =>\n comments.push({ text, start: loc.start.offset, end: loc.end.offset })\n })\n )\n if (sheet.type === 'StyleSheet') readNodes(reader, sheet.children)\n return reader.sheet\n}\n\n/**\n * A mode's condition in the form `readCustomProperties` gives it, so conditions written\n * differently compare equal: `:root[data-theme=dark]` and `[data-theme=\"dark\"]`, or\n * `@media (prefers-color-scheme:dark)` and `@media (prefers-color-scheme: dark)`.\n */\nexport function modeConditionKey(condition: string): string {\n const trimmed = condition.trim()\n const probe = trimmed.startsWith('@')\n ? `${trimmed} { :root { --probe: 0 } }`\n : `${trimmed} { --probe: 0 }`\n try {\n return readCustomProperties(probe).scopes[0]?.condition ?? trimmed\n } catch {\n return trimmed\n }\n}\n","import valueParser, { type Node } from 'postcss-value-parser'\n\nimport type { TokenUnit } from '@pairdraw/scene-graph'\n\nimport { parseCSSName } from './names'\nimport type { TokenValidator } from './validate'\nimport { TOKEN_UNIT_PROPERTY } from './values'\n\n/**\n * What a piece of a CSS value is. A finished `var(--name)` is one `reference`; while it is typed\n * it reads as a `function`, a `paren` and a `property`, the custom property name.\n */\nexport type CSSValueTokenKind =\n | 'reference'\n | 'property'\n | 'function'\n | 'paren'\n | 'number'\n | 'operator'\n | 'separator'\n | 'string'\n | 'keyword'\n\nexport interface CSSValueToken {\n kind: CSSValueTokenKind\n text: string\n from: number\n to: number\n}\n\nconst OPERATORS = new Set(['+', '-', '*', '/'])\n\n/** `var(--name)` with nothing else inside, which an editor can show as the variable it names. */\nfunction isReference(node: valueParser.FunctionNode) {\n if (node.value !== 'var' || node.unclosed || node.nodes.length !== 1) return false\n const [argument] = node.nodes\n return argument.type === 'word' && argument.value.startsWith('--')\n}\n\nfunction wordKind(word: string): CSSValueTokenKind {\n if (word.startsWith('--')) return 'property'\n if (OPERATORS.has(word)) return 'operator'\n return valueParser.unit(word) ? 'number' : 'keyword'\n}\n\n/**\n * The tokens of one CSS value, such as `clamp(1rem, 4vw, var(--space-md))`, in order and with\n * their source ranges. Reading tolerates half-typed values: an unclosed function still gives\n * its name and its `(`.\n */\nexport function cssValueTokens(source: string): CSSValueToken[] {\n const tokens: CSSValueToken[] = []\n const push = (kind: CSSValueTokenKind, from: number, to: number) =>\n tokens.push({ kind, text: source.slice(from, to), from, to })\n const walk = (nodes: Node[]) => {\n for (const node of nodes) {\n if (node.type === 'function') {\n if (isReference(node)) {\n push('reference', node.sourceIndex, node.sourceEndIndex)\n continue\n }\n const open = node.sourceIndex + node.value.length\n if (node.value) push('function', node.sourceIndex, open)\n push('paren', open, open + 1)\n walk(node.nodes)\n if (!node.unclosed) push('paren', node.sourceEndIndex - 1, node.sourceEndIndex)\n } else if (node.type === 'word') {\n push(wordKind(node.value), node.sourceIndex, node.sourceEndIndex)\n } else if (node.type === 'div') {\n push(node.value === '/' ? 'operator' : 'separator', node.sourceIndex, node.sourceEndIndex)\n } else if (node.type === 'string') {\n push('string', node.sourceIndex, node.sourceEndIndex)\n }\n }\n }\n walk(valueParser(source).nodes)\n return tokens\n}\n\n/** The custom property a token names, in `var(--name)` or as a bare `--name`. */\nexport function cssTokenProperty(token: CSSValueToken): string | undefined {\n if (token.kind !== 'reference' && token.kind !== 'property') return undefined\n const name = parseCSSName(token.text)\n return name ? `--${name}` : undefined\n}\n\nfunction hasUnclosedFunction(nodes: Node[]): boolean {\n return nodes.some(\n (node) => node.type === 'function' && (node.unclosed || hasUnclosedFunction(node.nodes))\n )\n}\n\nexport type CSSExpressionProblem =\n | { kind: 'unclosed' }\n | { kind: 'syntax' }\n | { kind: 'negated-reference'; property: string }\n | { kind: 'unknown-token'; name: string }\n | { kind: 'invalid'; property: string }\n\n/**\n * Why a CSS expression cannot stand in for a token, if it cannot. The token validator checks it\n * is one declaration; then it must name only tokens that exist and suit the token's unit, which\n * `supports` checks where a browser can type values. A value holding `var()` passes that last\n * check until it is used, so only its names are checked.\n */\nexport function cssExpressionProblem(\n css: string,\n unit: TokenUnit,\n tokens: ReadonlySet<string>,\n validator: TokenValidator,\n supports?: (property: string, value: string) => boolean\n): CSSExpressionProblem | undefined {\n if (!validator.declaration('token', css))\n return hasUnclosedFunction(valueParser(css).nodes) ? { kind: 'unclosed' } : { kind: 'syntax' }\n const parsed = cssValueTokens(css)\n // `-var(--x)` reads as a function named `-var`: CSS negates a value only inside calc().\n const negated = parsed.findIndex((token) => token.kind === 'function' && token.text === '-var')\n if (negated !== -1) {\n const property = parsed.slice(negated).map(cssTokenProperty).find(Boolean)\n if (property) return { kind: 'negated-reference', property }\n }\n for (const token of parsed) {\n const name = cssTokenProperty(token)\n if (name && !tokens.has(name)) return { kind: 'unknown-token', name }\n }\n const property = TOKEN_UNIT_PROPERTY[unit]\n return !supports || supports(property, css) ? undefined : { kind: 'invalid', property }\n}\n"],"mappings":";;;;;;;;AAkBA,MAAM,sBAA8C;CAClD,OAAO;CACP,KAAK;CACL,cAAc;AAChB;;AAGA,SAAS,iBAAiB,MAAsB;CAC9C,MAAM,QAAQ,oBAAoB;CAClC,IAAI,OAAO,OAAO;CAClB,IAAI,KAAK,WAAW,OAAO,KAAK,KAAK,WAAW,OAAO,GAAG,OAAO;CACjE,OAAO,KAAK,QAAQ,cAAc,GAAG,WAAmB,OAAO,YAAY,CAAC;AAC9E;;;;;AAMA,SAAS,QAAQ,MAA6B;CAC5C,OAAO,KAAK,iBAAiB,SAAS,UAAU,KAAK,YAAY,SAAS,MAAM,KAAK;AACvF;AAEA,SAAS,WAAW,MAAqB,gBAAiD;CACxF,MAAM,EAAE,OAAO,WAAW,GAAG,UAAU,KAAK;CAM5C,OAAO;EAJL,CAAC,aAAa,KAAK,mBAAmB,aAAa,KAAK,eAAe,CAAC;EACxE,GAAG,OAAO,QAAQ,KAAK;EACvB,CAAC,aAAa,gBAAgB,WAAW,yBAAyB,MAAM,cAAc,CAAC,CAAC;CAE7E,CAAC,CAAC,SAAS,CAA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