@fluixi-css/core 0.1.0-next.0 → 1.0.0-next.2

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 (67) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/reset.css +178 -147
  3. package/dist/src/css-parser.cjs +6 -1
  4. package/dist/src/css-parser.cjs.map +1 -1
  5. package/dist/src/css-parser.js +6 -2
  6. package/dist/src/css-parser.js.map +1 -1
  7. package/dist/src/css-parser.mjs +6 -1
  8. package/dist/src/css-parser.mjs.map +1 -1
  9. package/dist/src/engine/apply.d.ts +2 -0
  10. package/dist/src/engine/apply.js +75 -0
  11. package/dist/src/engine/apply.js.map +1 -0
  12. package/dist/src/engine/ast.js +25 -2
  13. package/dist/src/engine/ast.js.map +1 -1
  14. package/dist/src/engine/atom.js +6 -1
  15. package/dist/src/engine/atom.js.map +1 -1
  16. package/dist/src/engine/compile.js +48 -10
  17. package/dist/src/engine/compile.js.map +1 -1
  18. package/dist/src/engine/directives.js +89 -20
  19. package/dist/src/engine/directives.js.map +1 -1
  20. package/dist/src/engine/index.d.ts +4 -0
  21. package/dist/src/engine/index.js +10 -0
  22. package/dist/src/engine/index.js.map +1 -1
  23. package/dist/src/engine/log.d.ts +6 -0
  24. package/dist/src/engine/log.js +42 -0
  25. package/dist/src/engine/log.js.map +1 -0
  26. package/dist/src/engine/registry.d.ts +5 -4
  27. package/dist/src/engine/registry.js +2 -2
  28. package/dist/src/engine/registry.js.map +1 -1
  29. package/dist/src/engine/scanner.js +34 -6
  30. package/dist/src/engine/scanner.js.map +1 -1
  31. package/dist/src/engine/transform.d.ts +22 -0
  32. package/dist/src/engine/transform.js +36 -9
  33. package/dist/src/engine/transform.js.map +1 -1
  34. package/dist/src/engine/utilities/backgrounds.js +11 -0
  35. package/dist/src/engine/utilities/backgrounds.js.map +1 -1
  36. package/dist/src/engine/utilities/borders.js +60 -1
  37. package/dist/src/engine/utilities/borders.js.map +1 -1
  38. package/dist/src/engine/utilities/filters.d.ts +2 -0
  39. package/dist/src/engine/utilities/filters.js +86 -0
  40. package/dist/src/engine/utilities/filters.js.map +1 -0
  41. package/dist/src/engine/utilities/gradients.d.ts +2 -0
  42. package/dist/src/engine/utilities/gradients.js +40 -0
  43. package/dist/src/engine/utilities/gradients.js.map +1 -0
  44. package/dist/src/engine/utilities/index.js +8 -0
  45. package/dist/src/engine/utilities/index.js.map +1 -1
  46. package/dist/src/engine/utilities/layout.js +25 -0
  47. package/dist/src/engine/utilities/layout.js.map +1 -1
  48. package/dist/src/engine/utilities/spacing.js +25 -1
  49. package/dist/src/engine/utilities/spacing.js.map +1 -1
  50. package/dist/src/engine/utilities/transforms.d.ts +2 -0
  51. package/dist/src/engine/utilities/transforms.js +63 -0
  52. package/dist/src/engine/utilities/transforms.js.map +1 -0
  53. package/dist/src/engine/utilities/transitions.d.ts +2 -0
  54. package/dist/src/engine/utilities/transitions.js +61 -0
  55. package/dist/src/engine/utilities/transitions.js.map +1 -0
  56. package/dist/src/engine/utilities/typography.js +7 -0
  57. package/dist/src/engine/utilities/typography.js.map +1 -1
  58. package/dist/src/engine/variants.d.ts +1 -0
  59. package/dist/src/engine/variants.js +37 -11
  60. package/dist/src/engine/variants.js.map +1 -1
  61. package/dist/src/index.cjs +1038 -199
  62. package/dist/src/index.cjs.map +1 -1
  63. package/dist/src/index.mjs +1036 -200
  64. package/dist/src/index.mjs.map +1 -1
  65. package/dist/tsconfig.tsbuildinfo +1 -1
  66. package/package.json +1 -1
  67. package/reset.css +178 -147
@@ -0,0 +1,2 @@
1
+ import type { Registry } from './registry';
2
+ export declare function expandApply(css: string, reg: Registry): string;
@@ -0,0 +1,75 @@
1
+ import { stringify } from './ast';
2
+ import { parseAtom } from './atom';
3
+ import { compileAtom, escapeClass } from './compile';
4
+ // `@apply a b c;` — inline the declarations those utilities produce into the
5
+ // surrounding rule. Operates on author-CSS text (which `transform` passes through
6
+ // verbatim), replacing each `@apply` at-rule in place. Flat utilities inline as
7
+ // declarations; utilities that need their own selector (variants like `hover:` /
8
+ // `group-hover:`, child-combinators like `space-x`, at-rule variants like `md:`)
9
+ // emit a nested rule with `&` bound to the applying selector.
10
+ const APPLY_RE = /@apply\s+([^;{}]+);/g;
11
+ export function expandApply(css, reg) {
12
+ if (!css.includes('@apply'))
13
+ return css;
14
+ return css.replace(APPLY_RE, (_match, listRaw) => {
15
+ let list = listRaw.trim();
16
+ // A trailing `!important` marks every inlined declaration (Tailwind semantics).
17
+ let important = false;
18
+ const bang = list.match(/!important\s*$/);
19
+ if (bang) {
20
+ important = true;
21
+ list = list.slice(0, bang.index).trim();
22
+ }
23
+ const decls = [];
24
+ const rules = [];
25
+ for (const token of list.split(/\s+/)) {
26
+ if (!token)
27
+ continue;
28
+ const out = compileForApply(token, reg, important);
29
+ if (!out)
30
+ continue;
31
+ if (out.decls)
32
+ decls.push(...out.decls);
33
+ if (out.rule)
34
+ rules.push(out.rule);
35
+ }
36
+ // Flat declarations first, then nested rules — same order as authored.
37
+ return [...decls, ...rules].join(' ');
38
+ });
39
+ }
40
+ function compileForApply(cls, reg, important) {
41
+ const atom = parseAtom(cls, reg);
42
+ if (!atom)
43
+ return null;
44
+ const compiled = compileAtom(atom, reg);
45
+ if (!compiled || compiled.length === 0)
46
+ return null;
47
+ const classSelector = '.' + escapeClass(atom.raw);
48
+ // A plain utility — one rule on the class itself with only declarations — inlines
49
+ // straight into the applying rule.
50
+ if (compiled.length === 1 && compiled[0].kind === 'rule' && compiled[0].selector === classSelector) {
51
+ const flat = compiled[0].nodes;
52
+ if (flat.every((n) => n.kind === 'declaration')) {
53
+ return { decls: flat.map((n) => declText(n, important)) };
54
+ }
55
+ }
56
+ // Everything else keeps its structure but nests: swap the class's own selector
57
+ // for `&`, so `hover:` → `&:hover`, `group-hover:` → `.group:hover &`, `md:` →
58
+ // `@media(...) { & { … } }`.
59
+ if (important)
60
+ markImportant(compiled);
61
+ const text = stringify(compiled, { minify: false }).split(classSelector).join('&');
62
+ return { rule: text };
63
+ }
64
+ function declText(d, important) {
65
+ return `${d.property}: ${d.value}${important || d.important ? ' !important' : ''};`;
66
+ }
67
+ function markImportant(nodes) {
68
+ for (const n of nodes) {
69
+ if (n.kind === 'declaration')
70
+ n.important = true;
71
+ else if (n.kind === 'rule' || n.kind === 'at-rule')
72
+ markImportant(n.nodes);
73
+ }
74
+ }
75
+ //# sourceMappingURL=apply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../src/engine/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGrD,6EAA6E;AAC7E,kFAAkF;AAClF,gFAAgF;AAChF,iFAAiF;AACjF,iFAAiF;AACjF,8DAA8D;AAC9D,MAAM,QAAQ,GAAG,sBAAsB,CAAC;AAExC,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,GAAa;IACpD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,GAAG,CAAC;IACxC,OAAO,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAe,EAAE,EAAE;QACvD,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC1B,gFAAgF;QAChF,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC1C,IAAI,IAAI,EAAE,CAAC;YACT,SAAS,GAAG,IAAI,CAAC;YACjB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1C,CAAC;QAED,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B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ass } from './compile';\nimport type { Registry } from './registry';\n\n// `@apply a b c;` — inline the declarations those utilities produce into the\n// surrounding rule. Operates on author-CSS text (which `transform` passes through\n// verbatim), replacing each `@apply` at-rule in place. Flat utilities inline as\n// declarations; utilities that need their own selector (variants like `hover:` /\n// `group-hover:`, child-combinators like `space-x`, at-rule variants like `md:`)\n// emit a nested rule with `&` bound to the applying selector.\nconst APPLY_RE = /@apply\\s+([^;{}]+);/g;\n\nexport function expandApply(css: string, reg: Registry): string {\n if (!css.includes('@apply')) return css;\n return css.replace(APPLY_RE, (_match, listRaw: string) => {\n let list = listRaw.trim();\n // A trailing `!important` marks every inlined declaration (Tailwind semantics).\n let important = false;\n const bang = list.match(/!important\\s*$/);\n if (bang) {\n important = true;\n list = list.slice(0, bang.index).trim();\n }\n\n const decls: string[] = [];\n const rules: string[] = [];\n for (const token of list.split(/\\s+/)) {\n if (!token) continue;\n const out = compileForApply(token, reg, important);\n if (!out) continue;\n if (out.decls) decls.push(...out.decls);\n if (out.rule) rules.push(out.rule);\n }\n // Flat declarations first, then nested rules — same order as authored.\n return [...decls, ...rules].join(' ');\n });\n}\n\ninterface ApplyOutput {\n decls?: string[];\n rule?: string;\n}\n\nfunction compileForApply(cls: string, reg: Registry, important: boolean): ApplyOutput | null {\n const atom = parseAtom(cls, reg);\n if (!atom) return null;\n const compiled = compileAtom(atom, reg);\n if (!compiled || compiled.length === 0) return null;\n\n const classSelector = '.' + escapeClass(atom.raw);\n\n // A plain utility — one rule on the class itself with only declarations — inlines\n // straight into the applying rule.\n if (compiled.length === 1 && compiled[0].kind === 'rule' && compiled[0].selector === classSelector) {\n const flat = compiled[0].nodes;\n if (flat.every((n) => n.kind === 'declaration')) {\n return { decls: flat.map((n) => declText(n as Declaration, important)) };\n }\n }\n\n // Everything else keeps its structure but nests: swap the class's own selector\n // for `&`, so `hover:` → `&:hover`, `group-hover:` → `.group:hover &`, `md:` →\n // `@media(...) { & { … } }`.\n if (important) markImportant(compiled);\n const text = stringify(compiled, { minify: false }).split(classSelector).join('&');\n return { rule: text };\n}\n\nfunction declText(d: Declaration, important: boolean): string {\n return `${d.property}: ${d.value}${important || d.important ? ' !important' : ''};`;\n}\n\nfunction markImportant(nodes: AstNode[]): void {\n for (const n of nodes) {\n if (n.kind === 'declaration') n.important = true;\n else if (n.kind === 'rule' || n.kind === 'at-rule') markImportant(n.nodes);\n }\n}\n"]}
@@ -48,6 +48,26 @@ class Writer {
48
48
  });
49
49
  }
50
50
  }
51
+ // Emit verbatim text (a passed-through author slice or the reset) mapping each
52
+ // of its lines to consecutive source lines — so multi-line blocks are covered,
53
+ // not just their first line.
54
+ emitMapped(text, loc) {
55
+ if (!this.map) {
56
+ this.emit(text);
57
+ return;
58
+ }
59
+ const lines = text.split('\n');
60
+ for (let i = 0; i < lines.length; i++) {
61
+ this.map.addMapping({
62
+ source: loc.source,
63
+ original: { line: loc.line + i, column: i === 0 ? loc.column : 0 },
64
+ generated: { line: this.line, column: this.column },
65
+ });
66
+ this.emit(lines[i]);
67
+ if (i < lines.length - 1)
68
+ this.emit('\n');
69
+ }
70
+ }
51
71
  }
52
72
  export function stringify(nodes, options = {}) {
53
73
  const w = new Writer();
@@ -76,8 +96,11 @@ function write(node, depth, opts, w) {
76
96
  }
77
97
  if (node.kind === 'raw') {
78
98
  w.emit(pad);
79
- w.mark(node.loc);
80
- w.emit(`${node.text}${nl}`);
99
+ if (node.loc)
100
+ w.emitMapped(node.text, node.loc);
101
+ else
102
+ w.emit(node.text);
103
+ w.emit(nl);
81
104
  return;
82
105
  }
83
106
  const header = node.kind === 'rule' ? node.selector : `@${node.name}${node.params ? ' ' + node.params : ''}`;
@@ -1 +1 @@
1
- {"version":3,"file":"ast.js","sourceRoot":"","sources":["../../../src/engine/ast.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,4EAA4E;AAC5E,uBAAuB;AAEvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AA4ChD,MAAM,UAAU,IAAI,CAAC,Q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GAAG,IAAI,CAAC,QAAQ,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;QAC3D,OAAO;IACT,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACxB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACZ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;QAC5B,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAC7G,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;IACtC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK;QAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,EAAE,EAAE,CAAC,CAAC;AACzB,CAAC","sourcesContent":["// A tiny CSS AST the compiler builds and stringifies. Deliberately smaller than\n// the full css-parser tree: utilities only ever produce declarations, style\n// rules, and at-rules.\n\nimport { SourceMapGenerator } from 'source-map';\n\n// Where a node came from in an input file. `line` is 1-based, `column` 0-based\n// (the source-map convention). Set on passthrough nodes so `stringify` can emit\n// a source map; generated utilities have no meaningful origin and leave it unset.\nexport interface SourceLoc {\n source: string;\n line: number;\n column: number;\n}\n\nexport interface Declaration {\n kind: 'declaration';\n property: string;\n value: string;\n important: boolean;\n loc?: SourceLoc;\n}\n\nexport interface StyleRule {\n kind: 'rule';\n selector: string;\n nodes: AstNode[];\n loc?: SourceLoc;\n}\n\nexport interface AtRule {\n kind: 'at-rule';\n name: string;\n params: string;\n nodes: AstNode[];\n loc?: SourceLoc;\n}\n\n// Verbatim CSS the transform passes through from the input (author rules the\n// engine doesn't model structurally). Emitted as-is; carries its origin `loc`.\nexport interface RawNode {\n kind: 'raw';\n text: string;\n loc?: SourceLoc;\n}\n\nexport type AstNode = Declaration | StyleRule | AtRule | RawNode;\n\nexport function decl(property: string, value: string, important = false, loc?: SourceLoc): Declaration {\n return loc ? { kind: 'declaration', property, value, important, loc } : { kind: 'declaration', property, value, important };\n}\n\nexport function rule(selector: string, nodes: AstNode[], loc?: SourceLoc): StyleRule {\n return loc ? { kind: 'rule', selector, nodes, loc } : { kind: 'rule', selector, nodes };\n}\n\nexport function atRule(name: string, params: string, nodes: AstNode[], loc?: SourceLoc): AtRule {\n return loc ? { kind: 'at-rule', name, params, nodes, loc } : { kind: 'at-rule', name, params, nodes };\n}\n\nexport function raw(text: string, loc?: SourceLoc): RawNode {\n return loc ? { kind: 'raw', text, loc } : { kind: 'raw', text };\n}\n\nexport interface StringifyOptions {\n minify?: boolean;\n}\n\n// Accumulates the output string while tracking the current line/column, so a node\n// carrying a `loc` can be mapped to its origin. Without a map it's just a string\n// builder — `stringify` and `stringifyWithMap` share one write path.\nclass Writer {\n css = '';\n private line = 1;\n private column = 0;\n\n constructor(readonly map?: SourceMapGenerator) {}\n\n emit(text: string): void {\n this.css += text;\n let nl = text.indexOf('\\n');\n if (nl === -1) {\n this.column += text.length;\n return;\n }\n let last = 0;\n while (nl !== -1) {\n this.line++;\n last = nl + 1;\n nl = text.indexOf('\\n', last);\n }\n this.column = text.length - last;\n }\n\n mark(loc: SourceLoc | undefined): void {\n if (this.map && loc) {\n this.map.addMapping({\n source: loc.source,\n original: { line: loc.line, column: loc.column },\n generated: { line: this.line, column: this.column },\n });\n }\n }\n}\n\nexport function stringify(nodes: AstNode[], options: StringifyOptions = {}): string {\n const w = new Writer();\n for (const node of nodes) write(node, options.minify ? -1 : 0, options, w);\n return w.css;\n}\n\n// Like {@link stringify} but also returns a source map keyed on each node's `loc`.\nexport function stringifyWithMap(\n nodes: AstNode[],\n options: StringifyOptions = {},\n): { css: string; map: SourceMapGenerator } {\n const w = new Writer(new SourceMapGenerator());\n for (const node of nodes) write(node, options.minify ? -1 : 0, options, w);\n return { css: w.css, map: w.map! };\n}\n\nfunction write(node: AstNode, depth: number, opts: StringifyOptions, w: Writer): void {\n const minify = depth < 0;\n const pad = minify ? '' : ' '.repeat(depth);\n const nl = minify ? '' : '\\n';\n const sp = minify ? '' : ' ';\n\n if (node.kind === 'declaration') {\n const bang = node.important ? `${sp}!important` : '';\n w.emit(pad);\n w.mark(node.loc);\n w.emit(`${node.property}:${sp}${node.value}${bang};${nl}`);\n return;\n }\n\n if (node.kind === 'raw') {\n w.emit(pad);\n w.mark(node.loc);\n w.emit(`${node.text}${nl}`);\n return;\n }\n\n const header = node.kind === 'rule' ? node.selector : `@${node.name}${node.params ? ' ' + node.params : ''}`;\n w.emit(pad);\n w.mark(node.loc);\n w.emit(`${header}${sp}{${nl}`);\n const inner = minify ? -1 : depth + 1;\n for (const child of node.nodes) write(child, inner, opts, w);\n w.emit(`${pad}}${nl}`);\n}\n"]}
1
+ {"version":3,"file":"ast.js","sourceRoot":"","sources":["../../../src/engine/ast.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,4EAA4E;AAC5E,uBAAuB;AAEvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CA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C,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;;YAC3C,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACX,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAC7G,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;IACtC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK;QAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,EAAE,EAAE,CAAC,CAAC;AACzB,CAAC","sourcesContent":["// A tiny CSS AST the compiler builds and stringifies. Deliberately smaller than\n// the full css-parser tree: utilities only ever produce declarations, style\n// rules, and at-rules.\n\nimport { SourceMapGenerator } from 'source-map';\n\n// Where a node came from in an input file. `line` is 1-based, `column` 0-based\n// (the source-map convention). Set on passthrough nodes so `stringify` can emit\n// a source map; generated utilities have no meaningful origin and leave it unset.\nexport interface SourceLoc {\n source: string;\n line: number;\n column: number;\n}\n\nexport interface Declaration {\n kind: 'declaration';\n property: string;\n value: string;\n important: boolean;\n loc?: SourceLoc;\n}\n\nexport interface StyleRule {\n kind: 'rule';\n selector: string;\n nodes: AstNode[];\n loc?: SourceLoc;\n}\n\nexport interface AtRule {\n kind: 'at-rule';\n name: string;\n params: string;\n nodes: AstNode[];\n loc?: SourceLoc;\n}\n\n// Verbatim CSS the transform passes through from the input (author rules the\n// engine doesn't model structurally). Emitted as-is; carries its origin `loc`.\nexport interface RawNode {\n kind: 'raw';\n text: string;\n loc?: SourceLoc;\n}\n\nexport type AstNode = Declaration | StyleRule | AtRule | RawNode;\n\nexport function decl(property: string, value: string, important = false, loc?: SourceLoc): Declaration {\n return loc ? { kind: 'declaration', property, value, important, loc } : { kind: 'declaration', property, value, important };\n}\n\nexport function rule(selector: string, nodes: AstNode[], loc?: SourceLoc): StyleRule {\n return loc ? { kind: 'rule', selector, nodes, loc } : { kind: 'rule', selector, nodes };\n}\n\nexport function atRule(name: string, params: string, nodes: AstNode[], loc?: SourceLoc): AtRule {\n return loc ? { kind: 'at-rule', name, params, nodes, loc } : { kind: 'at-rule', name, params, nodes };\n}\n\nexport function raw(text: string, loc?: SourceLoc): RawNode {\n return loc ? { kind: 'raw', text, loc } : { kind: 'raw', text };\n}\n\nexport interface StringifyOptions {\n minify?: boolean;\n}\n\n// Accumulates the output string while tracking the current line/column, so a node\n// carrying a `loc` can be mapped to its origin. Without a map it's just a string\n// builder — `stringify` and `stringifyWithMap` share one write path.\nclass Writer {\n css = '';\n private line = 1;\n private column = 0;\n\n constructor(readonly map?: SourceMapGenerator) {}\n\n emit(text: string): void {\n this.css += text;\n let nl = text.indexOf('\\n');\n if (nl === -1) {\n this.column += text.length;\n return;\n }\n let last = 0;\n while (nl !== -1) {\n this.line++;\n last = nl + 1;\n nl = text.indexOf('\\n', last);\n }\n this.column = text.length - last;\n }\n\n mark(loc: SourceLoc | undefined): void {\n if (this.map && loc) {\n this.map.addMapping({\n source: loc.source,\n original: { line: loc.line, column: loc.column },\n generated: { line: this.line, column: this.column },\n });\n }\n }\n\n // Emit verbatim text (a passed-through author slice or the reset) mapping each\n // of its lines to consecutive source lines — so multi-line blocks are covered,\n // not just their first line.\n emitMapped(text: string, loc: SourceLoc): void {\n if (!this.map) {\n this.emit(text);\n return;\n }\n const lines = text.split('\\n');\n for (let i = 0; i < lines.length; i++) {\n this.map.addMapping({\n source: loc.source,\n original: { line: loc.line + i, column: i === 0 ? loc.column : 0 },\n generated: { line: this.line, column: this.column },\n });\n this.emit(lines[i]);\n if (i < lines.length - 1) this.emit('\\n');\n }\n }\n}\n\nexport function stringify(nodes: AstNode[], options: StringifyOptions = {}): string {\n const w = new Writer();\n for (const node of nodes) write(node, options.minify ? -1 : 0, options, w);\n return w.css;\n}\n\n// Like {@link stringify} but also returns a source map keyed on each node's `loc`.\nexport function stringifyWithMap(\n nodes: AstNode[],\n options: StringifyOptions = {},\n): { css: string; map: SourceMapGenerator } {\n const w = new Writer(new SourceMapGenerator());\n for (const node of nodes) write(node, options.minify ? -1 : 0, options, w);\n return { css: w.css, map: w.map! };\n}\n\nfunction write(node: AstNode, depth: number, opts: StringifyOptions, w: Writer): void {\n const minify = depth < 0;\n const pad = minify ? '' : ' '.repeat(depth);\n const nl = minify ? '' : '\\n';\n const sp = minify ? '' : ' ';\n\n if (node.kind === 'declaration') {\n const bang = node.important ? `${sp}!important` : '';\n w.emit(pad);\n w.mark(node.loc);\n w.emit(`${node.property}:${sp}${node.value}${bang};${nl}`);\n return;\n }\n\n if (node.kind === 'raw') {\n w.emit(pad);\n if (node.loc) w.emitMapped(node.text, node.loc);\n else w.emit(node.text);\n w.emit(nl);\n return;\n }\n\n const header = node.kind === 'rule' ? node.selector : `@${node.name}${node.params ? ' ' + node.params : ''}`;\n w.emit(pad);\n w.mark(node.loc);\n w.emit(`${header}${sp}{${nl}`);\n const inner = minify ? -1 : depth + 1;\n for (const child of node.nodes) write(child, inner, opts, w);\n w.emit(`${pad}}${nl}`);\n}\n"]}
@@ -59,7 +59,12 @@ function splitModifier(base) {
59
59
  }
60
60
  // In arbitrary values `_` stands in for a space; `\_` is a literal underscore.
61
61
  export function decodeUnderscores(value) {
62
- return value.replace(/\\_/g, '\0').replace(/_/g, ' ').replace(/\0/g, '_');
62
+ // `_` → space, `\_` → literal `_`. But a URL may legitimately contain underscores,
63
+ // so leave the inside of `url(...)` verbatim (the split keeps url() at odd indices).
64
+ return value
65
+ .split(/(url\([^)]*\))/g)
66
+ .map((part, i) => (i % 2 === 1 ? part : part.replace(/\\_/g, '\0').replace(/_/g, ' ').replace(/\0/g, '_')))
67
+ .join('');
63
68
  }
64
69
  // An arbitrary value may lead with a `type:` hint, e.g. `[length:12px]`.
65
70
  function parseArbitraryValue(body) {
@@ -1 +1 @@
1
- {"version":3,"file":"atom.js","sourceRoot":"","sources":["../../../src/engine/atom.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,6EAA6E;AAC7E,uEAAuE;AACvE,kFAAkF;AAClF,gFAAgF;AAChF,4CAA4C;AAqD5C,kFAAkF;AAClF,sBAAsB;AACtB,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,GAAW;IACxD,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACnB,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YACf,CAAC,EAAE,CAAC,CAAC,wBAAwB;YAC7B,SAAS;QACX,CAAC;QACD,IAAI,CAAC,KAAK,GAAG;YAAE,YAAY,EAAE,CAAC;aACzB,IAAI,CAAC,KAAK,GAAG;YAAE,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAA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AC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE;YAAE,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG;gBAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC1E,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACtB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YAChC,IAAI,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC;gBAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC;QAC9E,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACtD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;AACzE,CAAC","sourcesContent":["// Parses one raw utility (e.g. `md:hover:-bg-red-500/50!` or `[&_p]:text-[13px]`)\n// into a structured Atom in a single pass. Splitting is bracket/paren aware,\n// so `:` `/` `-` inside arbitrary values are left alone — no regex, no\n// backtracking. Which part is the root and which is the value can't be known from\n// the string alone (`text-red-500` vs `grid-cols-3`), so that split is resolved\n// against the registry through AtomContext.\n\nexport type AtomModifier =\n | { kind: 'named'; value: string }\n | { kind: 'arbitrary'; value: string };\n\nexport type AtomValue =\n | { kind: 'named'; value: string; fraction: string | null }\n | { kind: 'arbitrary'; value: string; dataType: string | null };\n\nexport type Variant =\n | { kind: 'static'; root: string }\n | {\n kind: 'functional';\n root: string;\n value: { kind: 'named'; value: string } | { kind: 'arbitrary'; value: string; dataType: string | null } | null;\n modifier: AtomModifier | null;\n }\n | { kind: 'arbitrary'; selector: string; relative: boolean };\n\nexport type Atom =\n | {\n kind: 'arbitrary-property';\n property: string;\n value: string;\n modifier: AtomModifier | null;\n important: boolean;\n variants: Variant[];\n raw: string;\n }\n | { kind: 'static'; root: string; important: boolean; variants: Variant[]; raw: string }\n | {\n kind: 'functional';\n root: string;\n value: AtomValue | null;\n modifier: AtomModifier | null;\n important: boolean;\n negative: boolean;\n variants: Variant[];\n raw: string;\n };\n\nexport interface AtomContext {\n /** A bare utility with no value: `flex`, `block`, `italic`. */\n isRule?(root: string): boolean;\n /** A utility root that takes a value: `bg`, `text`, `p`, `grid-cols`. */\n isDynamicRule?(root: string): boolean;\n /** A variant with no value: `hover`, `md`, `dark`, `first`. */\n isVariant?(root: string): boolean;\n /** A variant root that takes a value: `group`, `aria`, `data`, `supports`. */\n isDynamicVariant?(root: string): boolean;\n}\n\n// Split on `sep` at depth 0 only; `[...]` and `(...)` are opaque, and `\\` escapes\n// the next character.\nexport function splitAtTopLevel(input: string, sep: string): string[] {\n const out: string[] = [];\n let depthBracket = 0;\n let depthParen = 0;\n let start = 0;\n for (let i = 0; i < input.length; i++) {\n const c = input[i];\n if (c === '\\\\') {\n i++; // skip the escaped char\n continue;\n }\n if (c === '[') depthBracket++;\n else if (c === ']') depthBracket = Math.max(0, depthBracket - 1);\n else if (c === '(') depthParen++;\n else if (c === ')') depthParen = Math.max(0, depthParen - 1);\n else if (c === sep && depthBracket === 0 && depthParen === 0) {\n out.push(input.slice(start, i));\n start = i + 1;\n }\n }\n out.push(input.slice(start));\n return out;\n}\n\n// Content of a `[...]` or `(...)` wrapper, or null when `s` isn't wrapped.\nfunction unwrap(s: string, open: '[' | '('): string | null {\n const close = open === '[' ? ']' : ')';\n return s.length >= 2 && s[0] === open && s[s.length - 1] === close ? s.slice(1, -1) : null;\n}\n\nfunction parseModifier(raw: string): AtomModifier | null {\n if (!raw) return null;\n const arb = unwrap(raw, '[');\n if (arb !== null) return { kind: 'arbitrary', value: arb };\n // `(--name)` is shorthand for the custom property it references.\n const paren = unwrap(raw, '(');\n if (paren !== null) return { kind: 'arbitrary', value: `var(${paren})` };\n return { kind: 'named', value: raw };\n}\n\nfunction splitModifier(base: string): { base: string; modifier: AtomModifier | null } {\n const parts = splitAtTopLevel(base, '/');\n if (parts.length === 1) return { base, modifier: null };\n const modifier = parseModifier(parts.slice(1).join('/'));\n return { base: parts[0], modifier };\n}\n\n// In arbitrary values `_` stands in for a space; `\\_` is a literal underscore.\nexport function decodeUnderscores(value: string): string {\n return value.replace(/\\\\_/g, '\\0').replace(/_/g, ' ').replace(/\\0/g, '_');\n}\n\n// An arbitrary value may lead with a `type:` hint, e.g. `[length:12px]`.\nfunction parseArbitraryValue(body: string): { value: string; dataType: string | null } {\n const colon = body.indexOf(':');\n if (colon > 0) {\n const maybeType = body.slice(0, colon);\n if (/^[a-z-]+$/.test(maybeType)) {\n return { dataType: maybeType, value: decodeUnderscores(body.slice(colon + 1)) };\n }\n }\n return { dataType: null, value: decodeUnderscores(body) };\n}\n\n// The `(--name)` shorthand, optionally typed: `(length:--size)`. The custom\n// property name keeps its underscores.\nfunction parseParenValue(paren: string): { value: string; dataType: string | null } {\n const colon = paren.indexOf(':');\n if (colon > 0 && /^[a-z-]+$/.test(paren.slice(0, colon))) {\n return { dataType: paren.slice(0, colon), value: `var(${paren.slice(colon + 1)})` };\n }\n return { dataType: null, value: `var(${paren})` };\n}\n\nexport function parseVariant(raw: string, ctx: AtomContext = {}): Variant | null {\n if (!raw) return null;\n\n // `[&:hover]`, `[@media(...)]` — the selector is written out; a `&` means it's\n // relative to the element.\n const arb = unwrap(raw, '[');\n if (arb !== null) {\n return { kind: 'arbitrary', selector: arb, relative: arb.includes('&') };\n }\n\n const { base, modifier } = splitModifier(raw);\n\n // A variant carrying a value: `group-hover`, `data-[open]`, `supports-[display:grid]`.\n const dash = base.indexOf('-');\n if (dash > 0) {\n const root = base.slice(0, dash);\n const rest = base.slice(dash + 1);\n if (ctx.isDynamicVariant?.(root) || ctx.isDynamicVariant?.(root + '-')) {\n // A variant's `[...]` is a raw condition/attribute, not a typed value.\n const arbVal = unwrap(rest, '[');\n const value =\n arbVal !== null\n ? { kind: 'arbitrary' as const, value: arbVal, dataType: null }\n : { kind: 'named' as const, value: rest };\n return { kind: 'functional', root, value, modifier };\n }\n }\n\n return { kind: 'functional', root: base, value: null, modifier };\n}\n\n// Returns null for structurally invalid input (empty or dangling segments).\n// Without a context the root/value split falls back to the first dash, which is\n// enough to test the scanner on its own.\nexport function parseAtom(raw: string, ctx: AtomContext = {}): Atom | null {\n if (!raw) return null;\n\n const segments = splitAtTopLevel(raw, ':');\n const utility = segments.pop();\n if (utility === undefined || utility === '') return null;\n\n const variants: Variant[] = [];\n for (const seg of segments) {\n if (seg === '') return null; // dangling `::`\n const v = parseVariant(seg, ctx);\n if (!v) return null;\n variants.push(v);\n }\n // Written left-to-right (outermost first), stored innermost-first so consumers\n // can wrap the declaration outward.\n variants.reverse();\n\n // `!` marks important, accepted on either end.\n let body = utility;\n let important = false;\n if (body.endsWith('!')) {\n important = true;\n body = body.slice(0, -1);\n } else if (body.startsWith('!')) {\n important = true;\n body = body.slice(1);\n }\n if (body === '') return null;\n\n // Split off a trailing `/modifier` once, up front — it applies uniformly to\n // arbitrary-property, static, and functional atoms.\n const { base: core0, modifier } = splitModifier(body);\n\n // Arbitrary property: `[color:red]`, `[--my-var:0]` (optionally with modifier).\n const arbProp = unwrap(core0, '[');\n if (arbProp !== null && arbProp.includes(':')) {\n const colon = arbProp.indexOf(':');\n if (colon <= 0) return null;\n return {\n kind: 'arbitrary-property',\n property: arbProp.slice(0, colon),\n value: decodeUnderscores(arbProp.slice(colon + 1)),\n modifier,\n important,\n variants,\n raw,\n };\n }\n\n // Negative.\n let negative = false;\n let base = core0;\n if (base[0] === '-') {\n negative = true;\n base = base.slice(1);\n if (base === '') return null;\n }\n\n // Static utility (only when unambiguous: no negative/modifier).\n if (!negative && modifier === null && ctx.isRule?.(base)) {\n return { kind: 'static', root: base, important, variants, raw };\n }\n\n // Functional: split root ↔ value. Prefer the longest known functional root;\n // fall back to the first-dash split when no context is supplied.\n const { root, valueStr } = splitRootValue(base, ctx);\n if (root === '') return null;\n\n let value: AtomValue | null = null;\n if (valueStr !== null && valueStr !== '') {\n const arbVal = unwrap(valueStr, '[');\n if (arbVal !== null) {\n value = { kind: 'arbitrary', ...parseArbitraryValue(arbVal) };\n } else {\n const paren = unwrap(valueStr, '(');\n value =\n paren !== null\n ? { kind: 'arbitrary', ...parseParenValue(paren) }\n : { kind: 'named', value: valueStr, fraction: null };\n }\n } else if (ctx.isRule?.(base)) {\n // A bare root that is registered static (reached here due to a modifier).\n return { kind: 'static', root: base, important, variants, raw };\n }\n\n return { kind: 'functional', root, value, modifier, important, negative, variants, raw };\n}\n\n// Splits `bg-red-500` into a root and value. The longest registered root wins\n// (`grid-cols-3` → `grid-cols` + `3`); with no context, split at the first dash.\nfunction splitRootValue(base: string, ctx: AtomContext): { root: string; valueStr: string | null } {\n if (ctx.isDynamicRule) {\n // The whole class is itself the longest possible root (`rounded-t`, `border-x`);\n // prefer it before splitting off a shorter registered prefix (`rounded` + `t`).\n if (ctx.isDynamicRule(base)) return { root: base, valueStr: null };\n const dashes: number[] = [];\n for (let i = 0; i < base.length; i++) if (base[i] === '-') dashes.push(i);\n for (let d = dashes.length - 1; d >= 0; d--) {\n const idx = dashes[d];\n const root = base.slice(0, idx);\n if (ctx.isDynamicRule(root)) return { root, valueStr: base.slice(idx + 1) };\n }\n }\n const first = base.indexOf('-');\n if (first <= 0) return { root: base, valueStr: null };\n return { root: base.slice(0, first), valueStr: base.slice(first + 1) };\n}\n"]}
1
+ {"version":3,"file":"atom.js","sourceRoot":"","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,CAAC;YAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACtB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YAChC,IAAI,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC;gBAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC;QAC9E,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACtD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;AACzE,CAAC","sourcesContent":["// Parses one raw utility (e.g. `md:hover:-bg-red-500/50!` or `[&_p]:text-[13px]`)\n// into a structured Atom in a single pass. Splitting is bracket/paren aware,\n// so `:` `/` `-` inside arbitrary values are left alone — no regex, no\n// backtracking. Which part is the root and which is the value can't be known from\n// the string alone (`text-red-500` vs `grid-cols-3`), so that split is resolved\n// against the registry through AtomContext.\n\nexport type AtomModifier =\n | { kind: 'named'; value: string }\n | { kind: 'arbitrary'; value: string };\n\nexport type AtomValue =\n | { kind: 'named'; value: string; fraction: string | null }\n | { kind: 'arbitrary'; value: string; dataType: string | null };\n\nexport type Variant =\n | { kind: 'static'; root: string }\n | {\n kind: 'functional';\n root: string;\n value: { kind: 'named'; value: string } | { kind: 'arbitrary'; value: string; dataType: string | null } | null;\n modifier: AtomModifier | null;\n }\n | { kind: 'arbitrary'; selector: string; relative: boolean };\n\nexport type Atom =\n | {\n kind: 'arbitrary-property';\n property: string;\n value: string;\n modifier: AtomModifier | null;\n important: boolean;\n variants: Variant[];\n raw: string;\n }\n | { kind: 'static'; root: string; important: boolean; variants: Variant[]; raw: string }\n | {\n kind: 'functional';\n root: string;\n value: AtomValue | null;\n modifier: AtomModifier | null;\n important: boolean;\n negative: boolean;\n variants: Variant[];\n raw: string;\n };\n\nexport interface AtomContext {\n /** A bare utility with no value: `flex`, `block`, `italic`. */\n isRule?(root: string): boolean;\n /** A utility root that takes a value: `bg`, `text`, `p`, `grid-cols`. */\n isDynamicRule?(root: string): boolean;\n /** A variant with no value: `hover`, `md`, `dark`, `first`. */\n isVariant?(root: string): boolean;\n /** A variant root that takes a value: `group`, `aria`, `data`, `supports`. */\n isDynamicVariant?(root: string): boolean;\n}\n\n// Split on `sep` at depth 0 only; `[...]` and `(...)` are opaque, and `\\` escapes\n// the next character.\nexport function splitAtTopLevel(input: string, sep: string): string[] {\n const out: string[] = [];\n let depthBracket = 0;\n let depthParen = 0;\n let start = 0;\n for (let i = 0; i < input.length; i++) {\n const c = input[i];\n if (c === '\\\\') {\n i++; // skip the escaped char\n continue;\n }\n if (c === '[') depthBracket++;\n else if (c === ']') depthBracket = Math.max(0, depthBracket - 1);\n else if (c === '(') depthParen++;\n else if (c === ')') depthParen = Math.max(0, depthParen - 1);\n else if (c === sep && depthBracket === 0 && depthParen === 0) {\n out.push(input.slice(start, i));\n start = i + 1;\n }\n }\n out.push(input.slice(start));\n return out;\n}\n\n// Content of a `[...]` or `(...)` wrapper, or null when `s` isn't wrapped.\nfunction unwrap(s: string, open: '[' | '('): string | null {\n const close = open === '[' ? ']' : ')';\n return s.length >= 2 && s[0] === open && s[s.length - 1] === close ? s.slice(1, -1) : null;\n}\n\nfunction parseModifier(raw: string): AtomModifier | null {\n if (!raw) return null;\n const arb = unwrap(raw, '[');\n if (arb !== null) return { kind: 'arbitrary', value: arb };\n // `(--name)` is shorthand for the custom property it references.\n const paren = unwrap(raw, '(');\n if (paren !== null) return { kind: 'arbitrary', value: `var(${paren})` };\n return { kind: 'named', value: raw };\n}\n\nfunction splitModifier(base: string): { base: string; modifier: AtomModifier | null } {\n const parts = splitAtTopLevel(base, '/');\n if (parts.length === 1) return { base, modifier: null };\n const modifier = parseModifier(parts.slice(1).join('/'));\n return { base: parts[0], modifier };\n}\n\n// In arbitrary values `_` stands in for a space; `\\_` is a literal underscore.\nexport function decodeUnderscores(value: string): string {\n // `_` → space, `\\_` → literal `_`. But a URL may legitimately contain underscores,\n // so leave the inside of `url(...)` verbatim (the split keeps url() at odd indices).\n return value\n .split(/(url\\([^)]*\\))/g)\n .map((part, i) => (i % 2 === 1 ? part : part.replace(/\\\\_/g, '\\0').replace(/_/g, ' ').replace(/\\0/g, '_')))\n .join('');\n}\n\n// An arbitrary value may lead with a `type:` hint, e.g. `[length:12px]`.\nfunction parseArbitraryValue(body: string): { value: string; dataType: string | null } {\n const colon = body.indexOf(':');\n if (colon > 0) {\n const maybeType = body.slice(0, colon);\n if (/^[a-z-]+$/.test(maybeType)) {\n return { dataType: maybeType, value: decodeUnderscores(body.slice(colon + 1)) };\n }\n }\n return { dataType: null, value: decodeUnderscores(body) };\n}\n\n// The `(--name)` shorthand, optionally typed: `(length:--size)`. The custom\n// property name keeps its underscores.\nfunction parseParenValue(paren: string): { value: string; dataType: string | null } {\n const colon = paren.indexOf(':');\n if (colon > 0 && /^[a-z-]+$/.test(paren.slice(0, colon))) {\n return { dataType: paren.slice(0, colon), value: `var(${paren.slice(colon + 1)})` };\n }\n return { dataType: null, value: `var(${paren})` };\n}\n\nexport function parseVariant(raw: string, ctx: AtomContext = {}): Variant | null {\n if (!raw) return null;\n\n // `[&:hover]`, `[@media(...)]` — the selector is written out; a `&` means it's\n // relative to the element.\n const arb = unwrap(raw, '[');\n if (arb !== null) {\n return { kind: 'arbitrary', selector: arb, relative: arb.includes('&') };\n }\n\n const { base, modifier } = splitModifier(raw);\n\n // A variant carrying a value: `group-hover`, `data-[open]`, `supports-[display:grid]`.\n const dash = base.indexOf('-');\n if (dash > 0) {\n const root = base.slice(0, dash);\n const rest = base.slice(dash + 1);\n if (ctx.isDynamicVariant?.(root) || ctx.isDynamicVariant?.(root + '-')) {\n // A variant's `[...]` is a raw condition/attribute, not a typed value.\n const arbVal = unwrap(rest, '[');\n const value =\n arbVal !== null\n ? { kind: 'arbitrary' as const, value: arbVal, dataType: null }\n : { kind: 'named' as const, value: rest };\n return { kind: 'functional', root, value, modifier };\n }\n }\n\n return { kind: 'functional', root: base, value: null, modifier };\n}\n\n// Returns null for structurally invalid input (empty or dangling segments).\n// Without a context the root/value split falls back to the first dash, which is\n// enough to test the scanner on its own.\nexport function parseAtom(raw: string, ctx: AtomContext = {}): Atom | null {\n if (!raw) return null;\n\n const segments = splitAtTopLevel(raw, ':');\n const utility = segments.pop();\n if (utility === undefined || utility === '') return null;\n\n const variants: Variant[] = [];\n for (const seg of segments) {\n if (seg === '') return null; // dangling `::`\n const v = parseVariant(seg, ctx);\n if (!v) return null;\n variants.push(v);\n }\n // Written left-to-right (outermost first), stored innermost-first so consumers\n // can wrap the declaration outward.\n variants.reverse();\n\n // `!` marks important, accepted on either end.\n let body = utility;\n let important = false;\n if (body.endsWith('!')) {\n important = true;\n body = body.slice(0, -1);\n } else if (body.startsWith('!')) {\n important = true;\n body = body.slice(1);\n }\n if (body === '') return null;\n\n // Split off a trailing `/modifier` once, up front — it applies uniformly to\n // arbitrary-property, static, and functional atoms.\n const { base: core0, modifier } = splitModifier(body);\n\n // Arbitrary property: `[color:red]`, `[--my-var:0]` (optionally with modifier).\n const arbProp = unwrap(core0, '[');\n if (arbProp !== null && arbProp.includes(':')) {\n const colon = arbProp.indexOf(':');\n if (colon <= 0) return null;\n return {\n kind: 'arbitrary-property',\n property: arbProp.slice(0, colon),\n value: decodeUnderscores(arbProp.slice(colon + 1)),\n modifier,\n important,\n variants,\n raw,\n };\n }\n\n // Negative.\n let negative = false;\n let base = core0;\n if (base[0] === '-') {\n negative = true;\n base = base.slice(1);\n if (base === '') return null;\n }\n\n // Static utility (only when unambiguous: no negative/modifier).\n if (!negative && modifier === null && ctx.isRule?.(base)) {\n return { kind: 'static', root: base, important, variants, raw };\n }\n\n // Functional: split root ↔ value. Prefer the longest known functional root;\n // fall back to the first-dash split when no context is supplied.\n const { root, valueStr } = splitRootValue(base, ctx);\n if (root === '') return null;\n\n let value: AtomValue | null = null;\n if (valueStr !== null && valueStr !== '') {\n const arbVal = unwrap(valueStr, '[');\n if (arbVal !== null) {\n value = { kind: 'arbitrary', ...parseArbitraryValue(arbVal) };\n } else {\n const paren = unwrap(valueStr, '(');\n value =\n paren !== null\n ? { kind: 'arbitrary', ...parseParenValue(paren) }\n : { kind: 'named', value: valueStr, fraction: null };\n }\n } else if (ctx.isRule?.(base)) {\n // A bare root that is registered static (reached here due to a modifier).\n return { kind: 'static', root: base, important, variants, raw };\n }\n\n return { kind: 'functional', root, value, modifier, important, negative, variants, raw };\n}\n\n// Splits `bg-red-500` into a root and value. The longest registered root wins\n// (`grid-cols-3` → `grid-cols` + `3`); with no context, split at the first dash.\nfunction splitRootValue(base: string, ctx: AtomContext): { root: string; valueStr: string | null } {\n if (ctx.isDynamicRule) {\n // The whole class is itself the longest possible root (`rounded-t`, `border-x`);\n // prefer it before splitting off a shorter registered prefix (`rounded` + `t`).\n if (ctx.isDynamicRule(base)) return { root: base, valueStr: null };\n const dashes: number[] = [];\n for (let i = 0; i < base.length; i++) if (base[i] === '-') dashes.push(i);\n for (let d = dashes.length - 1; d >= 0; d--) {\n const idx = dashes[d];\n const root = base.slice(0, idx);\n if (ctx.isDynamicRule(root)) return { root, valueStr: base.slice(idx + 1) };\n }\n }\n const first = base.indexOf('-');\n if (first <= 0) return { root: base, valueStr: null };\n return { root: base.slice(0, first), valueStr: base.slice(first + 1) };\n}\n"]}
@@ -2,12 +2,23 @@ import { atRule, decl, rule } from './ast';
2
2
  // Turns a parsed atom into CSS. Returns null when the utility or any of its
3
3
  // variants aren't registered, so an unknown class simply produces nothing.
4
4
  export function compileAtom(atom, reg) {
5
- const declarations = declarationsFor(atom, reg);
6
- if (!declarations || declarations.length === 0)
5
+ const produced = producedFor(atom, reg);
6
+ if (!produced || produced.length === 0)
7
7
  return null;
8
- if (atom.important)
9
- for (const d of declarations)
8
+ const flat = [];
9
+ const nested = [];
10
+ for (const node of produced) {
11
+ if (node.kind === 'declaration')
12
+ flat.push(node);
13
+ else
14
+ nested.push(node);
15
+ }
16
+ if (atom.important) {
17
+ for (const d of flat)
10
18
  d.important = true;
19
+ for (const n of nested)
20
+ markImportant(n.nodes);
21
+ }
11
22
  let selector = '.' + escapeClass(atom.raw);
12
23
  const atRules = [];
13
24
  for (const variant of atom.variants) {
@@ -19,18 +30,33 @@ export function compileAtom(atom, reg) {
19
30
  if (wrap.atRule)
20
31
  atRules.push(wrap.atRule);
21
32
  }
22
- let node = rule(selector, declarations);
33
+ // Flat declarations sit on the utility's own selector; nested rules weave that
34
+ // selector into their `&` (`space-x-4` → `.space-x-4 > :not([hidden]) ~ …`).
35
+ let nodes = [];
36
+ if (flat.length)
37
+ nodes.push(rule(selector, flat));
38
+ for (const n of nested)
39
+ nodes.push(rule(substitute(n.selector, selector), n.nodes));
23
40
  for (const ar of atRules)
24
- node = atRule(ar.name, ar.params, [node]);
25
- return [node];
41
+ nodes = [atRule(ar.name, ar.params, nodes)];
42
+ return nodes;
43
+ }
44
+ function markImportant(nodes) {
45
+ for (const n of nodes) {
46
+ if (n.kind === 'declaration')
47
+ n.important = true;
48
+ else if (n.kind === 'rule' || n.kind === 'at-rule')
49
+ markImportant(n.nodes);
50
+ }
26
51
  }
27
- function declarationsFor(atom, reg) {
52
+ function producedFor(atom, reg) {
28
53
  if (atom.kind === 'arbitrary-property') {
29
54
  return [decl(atom.property, atom.value)];
30
55
  }
31
56
  if (atom.kind === 'static') {
32
- const decls = reg.getRule(atom.root);
33
- return decls ? decls.map((d) => (Object.assign({}, d))) : null;
57
+ // Clone: static templates are shared, and `!important` / `&`-weaving mutate.
58
+ const products = reg.getRule(atom.root);
59
+ return products ? products.map(cloneProduct) : null;
34
60
  }
35
61
  const handler = reg.getDynamicRule(atom.root);
36
62
  if (!handler)
@@ -42,6 +68,18 @@ function declarationsFor(atom, reg) {
42
68
  theme: reg.theme,
43
69
  });
44
70
  }
71
+ function cloneProduct(n) {
72
+ return n.kind === 'declaration' ? Object.assign({}, n) : cloneNode(n);
73
+ }
74
+ function cloneNode(n) {
75
+ if (n.kind === 'declaration')
76
+ return Object.assign({}, n);
77
+ if (n.kind === 'rule')
78
+ return rule(n.selector, n.nodes.map(cloneNode));
79
+ if (n.kind === 'at-rule')
80
+ return atRule(n.name, n.params, n.nodes.map(cloneNode));
81
+ return Object.assign({}, n);
82
+ }
45
83
  function resolveVariant(variant, reg) {
46
84
  if (variant.kind === 'arbitrary')
47
85
  return arbitraryVariant(variant.selector);
@@ -1 +1 @@
1
- {"version":3,"file":"compile.js","sourceRoot":"","sources":["../../../src/engine/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAI3E,4EAA4E;AAC5E,2EAA2E;AAC3E,MAAM,UAAU,WAAW,CAAC,IAAU,EAAE,GAAa;IACnD,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAChD,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5D,IAAI,IAAI,CAAC,SAAS;QAAE,KAAK,MAAM,CAAC,IAAI,YAAY;YAAE,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC;IAErE,IAAI,QAAQ,GAAG,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAuC,EAAE,CAAC;IAEvD,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,EAAE,G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AC;QAC1D,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;IACtC,CAAC;IACD,MAAM,GAAG,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC1C,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC;AAC3D,CAAC;AAED,SAAS,qBAAqB,CAAC,CAAS;IACtC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,UAAU,CAAC,QAAgB,EAAE,OAAe;IACnD,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAED,iFAAiF;AACjF,oEAAoE;AACpE,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import { type AstNode, type Declaration, atRule, decl, rule } from './ast';\nimport type { Atom, Variant } from './atom';\nimport { type Registry, type VariantWrap } from './registry';\n\n// Turns a parsed atom into CSS. Returns null when the utility or any of its\n// variants aren't registered, so an unknown class simply produces nothing.\nexport function compileAtom(atom: Atom, reg: Registry): AstNode[] | null {\n const declarations = declarationsFor(atom, reg);\n if (!declarations || declarations.length === 0) return null;\n if (atom.important) for (const d of declarations) d.important = true;\n\n let selector = '.' + escapeClass(atom.raw);\n const atRules: { name: string; params: string }[] = [];\n\n for (const variant of atom.variants) {\n const wrap = resolveVariant(variant, reg);\n if (!wrap) return null;\n if (wrap.selector) selector = substitute(wrap.selector, selector);\n if (wrap.atRule) atRules.push(wrap.atRule);\n }\n\n let node: AstNode = rule(selector, declarations);\n for (const ar of atRules) node = atRule(ar.name, ar.params, [node]);\n return [node];\n}\n\nfunction declarationsFor(atom: Atom, reg: Registry): Declaration[] | null {\n if (atom.kind === 'arbitrary-property') {\n return [decl(atom.property, atom.value)];\n }\n if (atom.kind === 'static') {\n const decls = reg.getRule(atom.root);\n return decls ? decls.map((d) => ({ ...d })) : null;\n }\n const handler = reg.getDynamicRule(atom.root);\n if (!handler) return null;\n return handler({\n value: atom.value,\n modifier: atom.modifier,\n negative: atom.negative,\n theme: reg.theme,\n });\n}\n\nfunction resolveVariant(variant: Variant, reg: Registry): VariantWrap | null {\n if (variant.kind === 'arbitrary') return arbitraryVariant(variant.selector);\n if (variant.kind === 'static') return reg.getVariant(variant.root);\n // functional: a null value means it's really a static variant (hover, md, …).\n if (variant.value === null) return reg.getVariant(variant.root);\n const handler = reg.getDynamicVariant(variant.root);\n return handler ? handler(variant.value, variant.modifier) : null;\n}\n\n// `[&_p]` → `& p`, `[.parent_&]` → `.parent &`, `[@media(...)]` → an at-rule.\n// A bare selector with no `&` is attached to the element.\nfunction arbitraryVariant(source: string): VariantWrap {\n if (source[0] === '@') {\n const cut = source.search(/[\\s(]/);\n const name = cut === -1 ? source.slice(1) : source.slice(1, cut);\n const params = cut === -1 ? '' : source.slice(cut).trim();\n return { atRule: { name, params } };\n }\n const sel = spacesFromUnderscores(source);\n return { selector: sel.includes('&') ? sel : `&${sel}` };\n}\n\nfunction spacesFromUnderscores(s: string): string {\n return s.replace(/\\\\_/g, '\\0').replace(/_/g, ' ').replace(/\\0/g, '_');\n}\n\nfunction substitute(template: string, current: string): string {\n return template.replace(/&/g, current);\n}\n\n// Backslash-escape everything outside [A-Za-z0-9_-] so a utility name is a valid\n// class selector (`hover:bg-red-500/50` → `hover\\:bg-red-500\\/50`).\nexport function escapeClass(name: string): string {\n return name.replace(/[^a-zA-Z0-9_-]/g, (c) => '\\\\' + c);\n}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AE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC;AAC3D,CAAC;AAED,SAAS,qBAAqB,CAAC,CAAS;IACtC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,UAAU,CAAC,QAAgB,EAAE,OAAe;IACnD,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAED,iFAAiF;AACjF,oEAAoE;AACpE,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import { type AstNode, type Declaration, type StyleRule, atRule, decl, rule } from './ast';\nimport type { Atom, Variant } from './atom';\nimport { type Registry, type RuleProduct, type VariantWrap } from './registry';\n\n// Turns a parsed atom into CSS. Returns null when the utility or any of its\n// variants aren't registered, so an unknown class simply produces nothing.\nexport function compileAtom(atom: Atom, reg: Registry): AstNode[] | null {\n const produced = producedFor(atom, reg);\n if (!produced || produced.length === 0) return null;\n\n const flat: Declaration[] = [];\n const nested: StyleRule[] = [];\n for (const node of produced) {\n if (node.kind === 'declaration') flat.push(node);\n else nested.push(node);\n }\n\n if (atom.important) {\n for (const d of flat) d.important = true;\n for (const n of nested) markImportant(n.nodes);\n }\n\n let selector = '.' + escapeClass(atom.raw);\n const atRules: { name: string; params: string }[] = [];\n\n for (const variant of atom.variants) {\n const wrap = resolveVariant(variant, reg);\n if (!wrap) return null;\n if (wrap.selector) selector = substitute(wrap.selector, selector);\n if (wrap.atRule) atRules.push(wrap.atRule);\n }\n\n // Flat declarations sit on the utility's own selector; nested rules weave that\n // selector into their `&` (`space-x-4` → `.space-x-4 > :not([hidden]) ~ …`).\n let nodes: AstNode[] = [];\n if (flat.length) nodes.push(rule(selector, flat));\n for (const n of nested) nodes.push(rule(substitute(n.selector, selector), n.nodes));\n\n for (const ar of atRules) nodes = [atRule(ar.name, ar.params, nodes)];\n return nodes;\n}\n\nfunction markImportant(nodes: AstNode[]): void {\n for (const n of nodes) {\n if (n.kind === 'declaration') n.important = true;\n else if (n.kind === 'rule' || n.kind === 'at-rule') markImportant(n.nodes);\n }\n}\n\nfunction producedFor(atom: Atom, reg: Registry): RuleProduct[] | null {\n if (atom.kind === 'arbitrary-property') {\n return [decl(atom.property, atom.value)];\n }\n if (atom.kind === 'static') {\n // Clone: static templates are shared, and `!important` / `&`-weaving mutate.\n const products = reg.getRule(atom.root);\n return products ? products.map(cloneProduct) : null;\n }\n const handler = reg.getDynamicRule(atom.root);\n if (!handler) return null;\n return handler({\n value: atom.value,\n modifier: atom.modifier,\n negative: atom.negative,\n theme: reg.theme,\n });\n}\n\nfunction cloneProduct(n: RuleProduct): RuleProduct {\n return n.kind === 'declaration' ? { ...n } : (cloneNode(n) as StyleRule);\n}\n\nfunction cloneNode(n: AstNode): AstNode {\n if (n.kind === 'declaration') return { ...n };\n if (n.kind === 'rule') return rule(n.selector, n.nodes.map(cloneNode));\n if (n.kind === 'at-rule') return atRule(n.name, n.params, n.nodes.map(cloneNode));\n return { ...n };\n}\n\nfunction resolveVariant(variant: Variant, reg: Registry): VariantWrap | null {\n if (variant.kind === 'arbitrary') return arbitraryVariant(variant.selector);\n if (variant.kind === 'static') return reg.getVariant(variant.root);\n // functional: a null value means it's really a static variant (hover, md, …).\n if (variant.value === null) return reg.getVariant(variant.root);\n const handler = reg.getDynamicVariant(variant.root);\n return handler ? handler(variant.value, variant.modifier) : null;\n}\n\n// `[&_p]` → `& p`, `[.parent_&]` → `.parent &`, `[@media(...)]` → an at-rule.\n// A bare selector with no `&` is attached to the element.\nfunction arbitraryVariant(source: string): VariantWrap {\n if (source[0] === '@') {\n const cut = source.search(/[\\s(]/);\n const name = cut === -1 ? source.slice(1) : source.slice(1, cut);\n const params = cut === -1 ? '' : source.slice(cut).trim();\n return { atRule: { name, params } };\n }\n const sel = spacesFromUnderscores(source);\n return { selector: sel.includes('&') ? sel : `&${sel}` };\n}\n\nfunction spacesFromUnderscores(s: string): string {\n return s.replace(/\\\\_/g, '\\0').replace(/_/g, ' ').replace(/\\0/g, '_');\n}\n\nfunction substitute(template: string, current: string): string {\n return template.replace(/&/g, current);\n}\n\n// Backslash-escape everything outside [A-Za-z0-9_-] so a utility name is a valid\n// class selector (`hover:bg-red-500/50` → `hover\\:bg-red-500\\/50`).\nexport function escapeClass(name: string): string {\n return name.replace(/[^a-zA-Z0-9_-]/g, (c) => '\\\\' + c);\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { parseCss } from '../css-parser';
2
- import { decl } from './ast';
2
+ import { decl, rule } from './ast';
3
3
  import { splitAtTopLevel } from './atom';
4
4
  // Reads `@utility` and `@custom-variant` blocks from CSS and registers them into
5
5
  // the registry — the CSS-first way to add utilities and variants, alongside
@@ -22,34 +22,60 @@ function registerUtility(atRule, reg) {
22
22
  const name = ((_a = atRule.preludeText) !== null && _a !== void 0 ? _a : '').trim();
23
23
  if (!name || !atRule.block)
24
24
  return;
25
- const decls = atRule.block.children
26
- .filter((c) => c.type === 'declaration')
27
- .map((d) => { var _a; return decl(d.property, ((_a = d.rawValue) !== null && _a !== void 0 ? _a : '').trim(), d.important === true); });
28
- if (decls.length === 0)
25
+ // Flat declarations plus any nested rules (`&:hover`, `&::-webkit-scrollbar`);
26
+ // the nested `&` is later woven with the utility's own selector by the compiler.
27
+ const products = toProducts(atRule.block.children);
28
+ if (products.length === 0)
29
29
  return;
30
30
  // A trailing `-*` marks a functional utility: `tab-*` handles `tab-2`, `tab-[3]`.
31
31
  if (name.endsWith('-*')) {
32
32
  const root = name.slice(0, -2);
33
33
  if (root)
34
- reg.dynamicRule(root, (ctx) => resolveDeclarations(decls, ctx));
34
+ reg.dynamicRule(root, (ctx) => resolveProducts(products, ctx));
35
35
  return;
36
36
  }
37
- reg.rule(name, decls);
37
+ reg.rule(name, products);
38
38
  }
39
- // Applies a functional utility's declaration templates to one atom. `--value()`
40
- // is required — if it can't resolve, the whole utility is dropped (returns null).
41
- // `--modifier()` is optional — a declaration using it is skipped when there's no
42
- // matching modifier, so `text-lg` and `text-lg/7` share one definition.
43
- function resolveDeclarations(templates, ctx) {
39
+ function toProducts(children) {
40
+ var _a, _b, _c, _d;
41
+ const out = [];
42
+ for (const c of children) {
43
+ if (c.type === 'declaration') {
44
+ const d = c;
45
+ out.push(decl(d.property, ((_a = d.rawValue) !== null && _a !== void 0 ? _a : '').trim(), d.important === true));
46
+ }
47
+ else if (c.type === 'rule') {
48
+ const r = c;
49
+ // The parser splits a rule's own declarations from its nested rules; a
50
+ // utility body wants both, declarations first.
51
+ const kids = [...((_b = r.declarations) !== null && _b !== void 0 ? _b : []), ...((_c = r.children) !== null && _c !== void 0 ? _c : [])];
52
+ out.push(rule(((_d = r.rawSelector) !== null && _d !== void 0 ? _d : '').trim(), toProducts(kids)));
53
+ }
54
+ }
55
+ return out;
56
+ }
57
+ // Applies a functional utility's templates to one atom, walking nested rules too.
58
+ // `--value()` is required — if it can't resolve, the whole utility is dropped
59
+ // (returns null). `--modifier()` is optional — a declaration using it is skipped
60
+ // when there's no matching modifier, so `text-lg` and `text-lg/7` share one def.
61
+ function resolveProducts(templates, ctx) {
44
62
  const out = [];
45
63
  for (const t of templates) {
46
- const withValue = replaceFn(t.value, '--value', (args) => resolveValue(args, ctx));
47
- if (withValue === null)
48
- return null;
49
- const withModifier = replaceFn(withValue, '--modifier', (args) => resolveModifier(args, ctx));
50
- if (withModifier === null)
51
- continue;
52
- out.push(Object.assign(Object.assign({}, t), { value: withModifier }));
64
+ if (t.kind === 'declaration') {
65
+ const withValue = replaceFn(t.value, '--value', (args) => resolveValue(args, ctx));
66
+ if (withValue === null)
67
+ return null;
68
+ const withModifier = replaceFn(withValue, '--modifier', (args) => resolveModifier(args, ctx));
69
+ if (withModifier === null)
70
+ continue;
71
+ out.push(Object.assign(Object.assign({}, t), { value: withModifier }));
72
+ }
73
+ else {
74
+ const inner = resolveProducts(t.nodes, ctx);
75
+ if (inner === null)
76
+ return null;
77
+ out.push(rule(t.selector, inner));
78
+ }
53
79
  }
54
80
  return out.length ? out : null;
55
81
  }
@@ -169,7 +195,15 @@ function registerVariant(atRule, reg) {
169
195
  const prelude = ((_a = atRule.preludeText) !== null && _a !== void 0 ? _a : '').trim();
170
196
  if (!prelude)
171
197
  return;
172
- // `name (condition)` shorthand — the block form isn't supported yet.
198
+ // Block form: `@custom-variant name { &:hover { @slot } }` — the prelude is just
199
+ // the name and the block describes the wrapping, marked by `@slot`.
200
+ if (atRule.block) {
201
+ const wrap = blockToWrap(atRule.block.children);
202
+ if (prelude && wrap)
203
+ reg.variant(prelude, wrap);
204
+ return;
205
+ }
206
+ // Shorthand: `@custom-variant name (condition)`.
173
207
  const paren = prelude.indexOf('(');
174
208
  if (paren === -1 || !prelude.endsWith(')'))
175
209
  return;
@@ -179,6 +213,41 @@ function registerVariant(atRule, reg) {
179
213
  return;
180
214
  reg.variant(name, wrapFor(condition));
181
215
  }
216
+ // Walk the single path down to `@slot`, collecting the selector (nested rules,
217
+ // combined by `&` substitution) and/or the wrapping at-rule (`@media`, `@supports`).
218
+ // Supports one selector level, one at-rule level, or both nested.
219
+ function blockToWrap(children) {
220
+ var _a, _b, _c;
221
+ let selector;
222
+ let at;
223
+ let node = firstBlockChild(children);
224
+ while (node) {
225
+ if (node.type === 'rule') {
226
+ const sel = ((_a = node.rawSelector) !== null && _a !== void 0 ? _a : '').trim();
227
+ selector = selector ? sel.replace(/&/g, selector) : sel;
228
+ node = firstBlockChild((_b = node.children) !== null && _b !== void 0 ? _b : []);
229
+ }
230
+ else if (node.type === 'atrule') {
231
+ const ar = node;
232
+ if (ar.name === 'slot')
233
+ break;
234
+ at = { name: ar.name, params: ((_c = ar.preludeText) !== null && _c !== void 0 ? _c : '').trim() };
235
+ node = ar.block ? firstBlockChild(ar.block.children) : undefined;
236
+ }
237
+ else {
238
+ node = undefined;
239
+ }
240
+ }
241
+ const wrap = {};
242
+ if (selector)
243
+ wrap.selector = selector.includes('&') ? selector : `&${selector}`;
244
+ if (at)
245
+ wrap.atRule = at;
246
+ return wrap.selector || wrap.atRule ? wrap : null;
247
+ }
248
+ function firstBlockChild(children) {
249
+ return children.find((c) => c.type === 'rule' || c.type === 'atrule');
250
+ }
182
251
  function wrapFor(condition) {
183
252
  if (condition[0] === '@') {
184
253
  const cut = condition.search(/[\s(]/);