@fluixi-css/core 1.0.0-next.1 → 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 (48) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/reset.css +174 -152
  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/compile.js +48 -10
  15. package/dist/src/engine/compile.js.map +1 -1
  16. package/dist/src/engine/directives.js +45 -19
  17. package/dist/src/engine/directives.js.map +1 -1
  18. package/dist/src/engine/index.d.ts +4 -0
  19. package/dist/src/engine/index.js +6 -0
  20. package/dist/src/engine/index.js.map +1 -1
  21. package/dist/src/engine/log.d.ts +6 -0
  22. package/dist/src/engine/log.js +42 -0
  23. package/dist/src/engine/log.js.map +1 -0
  24. package/dist/src/engine/registry.d.ts +5 -4
  25. package/dist/src/engine/registry.js +2 -2
  26. package/dist/src/engine/registry.js.map +1 -1
  27. package/dist/src/engine/transform.d.ts +22 -0
  28. package/dist/src/engine/transform.js +34 -9
  29. package/dist/src/engine/transform.js.map +1 -1
  30. package/dist/src/engine/utilities/backgrounds.js +11 -0
  31. package/dist/src/engine/utilities/backgrounds.js.map +1 -1
  32. package/dist/src/engine/utilities/borders.js +60 -1
  33. package/dist/src/engine/utilities/borders.js.map +1 -1
  34. package/dist/src/engine/utilities/layout.js +25 -0
  35. package/dist/src/engine/utilities/layout.js.map +1 -1
  36. package/dist/src/engine/utilities/spacing.js +25 -1
  37. package/dist/src/engine/utilities/spacing.js.map +1 -1
  38. package/dist/src/engine/utilities/typography.js +7 -0
  39. package/dist/src/engine/utilities/typography.js.map +1 -1
  40. package/dist/src/engine/variants.js +25 -6
  41. package/dist/src/engine/variants.js.map +1 -1
  42. package/dist/src/index.cjs +619 -179
  43. package/dist/src/index.cjs.map +1 -1
  44. package/dist/src/index.mjs +618 -180
  45. package/dist/src/index.mjs.map +1 -1
  46. package/dist/tsconfig.tsbuildinfo +1 -1
  47. package/package.json +1 -1
  48. package/reset.css +174 -152
@@ -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,UA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QAAQ,CAAC,CAAc,EAAE,SAAkB;IAClD,OAAO,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,KAAK,GAAG,SAAS,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC;AACtF,CAAC;AAED,SAAS,aAAa,CAAC,KAAgB;IACrC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,CAAC,IAAI,KAAK,aAAa;YAAE,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC;aAC5C,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS;YAAE,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC7E,CAAC;AACH,CAAC","sourcesContent":["import { type AstNode, type Declaration, stringify } from './ast';\nimport { parseAtom } from './atom';\nimport { compileAtom, escapeClass } 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,QAAgB,EAAE,KAAa,EAAE,SAAS,GAAG,KAAK,EAAE,GAAe;IACtF,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAC9H,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,QAAgB,EAAE,KAAgB,EAAE,GAAe;IACtE,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAC1F,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,IAAY,EAAE,MAAc,EAAE,KAAgB,EAAE,GAAe;IACpF,OAAO,GAAG,CAAC,CAAC,CAAC,E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7G,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,CAAC;AA4ChD,MAAM,UAAU,IAAI,CAAC,QAAgB,EAAE,KAAa,EAAE,SAAS,GAAG,KAAK,EAAE,GAAe;IACtF,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAC9H,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,QAAgB,EAAE,KAAgB,EAAE,GAAe;IACtE,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAC1F,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,IAAY,EAAE,MAAc,EAAE,KAAgB,EAAE,GAAe;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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"]}
@@ -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 +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C,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}\n"]}
1
+ {"version":3,"file":"compile.js","sourceRoot":"","sources":["../../../src/engine/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAI3F,4EAA4E;AAC5E,2EAA2E;AAC3E,MAAM,UAAU,WAAW,CAAC,IAAU,EAAE,GAAa;IACnD,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACxC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEpD,MAAM,IAAI,GAAkB,EAAE,CAAC;IAC/B,MAAM,MAAM,GAAgB,EAAE,CAAC;IAC/B,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;Q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AO,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
  }
@@ -1 +1 @@
1
- {"version":3,"file":"directives.js","sourceRoot":"","sources":["../../../src/engine/directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAoB,IAAI,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,eAAe,EAA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AAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AACpD,CAAC;AAED,SAAS,eAAe,CAAC,QAAsB;IAC7C,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,OAAO,CAAC,SAAiB;IAChC,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtC,MAAM,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QACrE,MAAM,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QAC7D,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC;IAC1C,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE,EAAE,CAAC;AAC7E,CAAC","sourcesContent":["import { parseCss } from '../css-parser';\nimport type { CssAstNode, CssAtRule, CssDeclaration, CssRule } from '../types/css-parser';\nimport { type Declaration, decl } from './ast';\nimport { splitAtTopLevel } from './atom';\nimport type { Registry, RuleContext, VariantWrap } from './registry';\n\n// Reads `@utility` and `@custom-variant` blocks from CSS and registers them into\n// the registry — the CSS-first way to add utilities and variants, alongside\n// `@theme` for tokens. Call after loadTheme so functional utilities can resolve\n// against the theme.\nexport function loadDirectives(css: string, reg: Registry): Registry {\n const sheet = parseCss(css);\n for (const node of sheet.children) {\n if (node.type !== 'atrule') continue;\n if (node.name === 'utility') registerUtility(node, reg);\n else if (node.name === 'custom-variant') registerVariant(node, reg);\n }\n return reg;\n}\n\nfunction registerUtility(atRule: CssAtRule, reg: Registry): void {\n const name = (atRule.preludeText ?? '').trim();\n if (!name || !atRule.block) return;\n\n const decls = atRule.block.children\n .filter((c): c is CssDeclaration => c.type === 'declaration')\n .map((d) => decl(d.property, (d.rawValue ?? '').trim(), d.important === true));\n if (decls.length === 0) return;\n\n // A trailing `-*` marks a functional utility: `tab-*` handles `tab-2`, `tab-[3]`.\n if (name.endsWith('-*')) {\n const root = name.slice(0, -2);\n if (root) reg.dynamicRule(root, (ctx) => resolveDeclarations(decls, ctx));\n return;\n }\n reg.rule(name, decls);\n}\n\n// Applies a functional utility's declaration templates to one atom. `--value()`\n// is required — if it can't resolve, the whole utility is dropped (returns null).\n// `--modifier()` is optional — a declaration using it is skipped when there's no\n// matching modifier, so `text-lg` and `text-lg/7` share one definition.\nfunction resolveDeclarations(templates: Declaration[], ctx: RuleContext): Declaration[] | null {\n const out: Declaration[] = [];\n for (const t of templates) {\n const withValue = replaceFn(t.value, '--value', (args) => resolveValue(args, ctx));\n if (withValue === null) return null;\n const withModifier = replaceFn(withValue, '--modifier', (args) => resolveModifier(args, ctx));\n if (withModifier === null) continue;\n out.push({ ...t, value: withModifier });\n }\n return out.length ? out : null;\n}\n\nfunction resolveValue(args: string, ctx: RuleContext): string | null {\n const value = ctx.value;\n if (!value) return null;\n for (const arg of splitArgs(args)) {\n const themed = fromTheme(arg, value.kind === 'named' ? value.value : null, ctx);\n if (themed !== null) return themed;\n if (value.kind === 'named') {\n const lit = fromNamed(arg, value.value);\n if (lit !== null) return lit;\n } else {\n const arb = fromArbitrary(arg, value.value, value.dataType);\n if (arb !== null) return arb;\n }\n }\n return null;\n}\n\nfunction resolveModifier(args: string, ctx: RuleContext): string | null {\n const modifier = ctx.modifier;\n if (!modifier) return null;\n for (const arg of splitArgs(args)) {\n const themed = fromTheme(arg, modifier.kind === 'named' ? modifier.value : null, ctx);\n if (themed !== null) return themed;\n if (modifier.kind === 'named') {\n const lit = fromNamed(arg, modifier.value);\n if (lit !== null) return lit;\n } else {\n const arb = fromArbitrary(arg, modifier.value, null);\n if (arb !== null) return arb;\n }\n }\n return null;\n}\n\n// `--foo` / `--foo-*` names a theme namespace; the atom's named value keys into\n// it (`--value(--tab-size)` + `tab-2` → `var(--tab-size-2)`).\nfunction fromTheme(arg: string, key: string | null, ctx: RuleContext): string | null {\n if (key === null || !arg.startsWith('--')) return null;\n const ns = arg.replace(/-?\\*$/, '').slice(2);\n return ns ? ctx.theme.resolve(ns, key) : null;\n}\n\n// A bare value against a data-type keyword (`integer`, `number`, `percentage`) or a\n// quoted literal (`'inline'`).\nfunction fromNamed(arg: string, value: string): string | null {\n if (isQuoted(arg)) return arg.slice(1, -1) === value ? value : null;\n const rx = NUMERIC[arg];\n return rx ? (rx.test(value) ? value : null) : null;\n}\n\n// An arbitrary value against `[*]` (anything) or a typed bracket (`[integer]`,\n// `[length]`), gated on the value's own `type:` hint when it carries one.\nfunction fromArbitrary(arg: string, value: string, dataType: string | null): string | null {\n if (arg[0] !== '[' || arg[arg.length - 1] !== ']') return null;\n const want = arg.slice(1, -1);\n if (want === '*') return value;\n if (dataType !== null) return dataType === want ? value : null;\n // Untyped arbitrary: validate against the simple numeric types we can check.\n const rx = NUMERIC[want];\n return rx ? (rx.test(value) ? value : null) : value;\n}\n\nconst NUMERIC: Record<string, RegExp> = {\n integer: /^-?\\d+$/,\n number: /^-?\\d*\\.?\\d+$/,\n percentage: /^-?\\d*\\.?\\d+%$/,\n};\n\nfunction isQuoted(s: string): boolean {\n return s.length >= 2 && (s[0] === '\"' || s[0] === \"'\") && s[s.length - 1] === s[0];\n}\n\nfunction splitArgs(args: string): string[] {\n return splitAtTopLevel(args, ',').map((a) => a.trim()).filter((a) => a !== '');\n}\n\n// Replaces every `name(...)` call in `input` (parens balanced, even when nested in\n// `calc(...)`) with `resolve`'s result. Returns null if any call fails to resolve.\nfunction replaceFn(input: string, name: string, resolve: (args: string) => string | null): string | null {\n const token = name + '(';\n let out = '';\n let i = 0;\n for (;;) {\n const start = input.indexOf(token, i);\n if (start === -1) return out + input.slice(i);\n out += input.slice(i, start);\n let depth = 0;\n let j = start + token.length - 1;\n for (; j < input.length; j++) {\n if (input[j] === '(') depth++;\n else if (input[j] === ')' && --depth === 0) break;\n }\n if (j >= input.length) return null; // unbalanced\n const resolved = resolve(input.slice(start + token.length, j));\n if (resolved === null) return null;\n out += resolved;\n i = j + 1;\n }\n}\n\nfunction registerVariant(atRule: CssAtRule, reg: Registry): void {\n const prelude = (atRule.preludeText ?? '').trim();\n if (!prelude) return;\n\n // Block form: `@custom-variant name { &:hover { @slot } }` — the prelude is just\n // the name and the block describes the wrapping, marked by `@slot`.\n if (atRule.block) {\n const wrap = blockToWrap(atRule.block.children);\n if (prelude && wrap) reg.variant(prelude, wrap);\n return;\n }\n\n // Shorthand: `@custom-variant name (condition)`.\n const paren = prelude.indexOf('(');\n if (paren === -1 || !prelude.endsWith(')')) return;\n\n const name = prelude.slice(0, paren).trim();\n const condition = prelude.slice(paren + 1, -1).trim();\n if (!name || !condition) return;\n\n reg.variant(name, wrapFor(condition));\n}\n\n// Walk the single path down to `@slot`, collecting the selector (nested rules,\n// combined by `&` substitution) and/or the wrapping at-rule (`@media`, `@supports`).\n// Supports one selector level, one at-rule level, or both nested.\nfunction blockToWrap(children: CssAstNode[]): VariantWrap | null {\n let selector: string | undefined;\n let at: { name: string; params: string } | undefined;\n let node: CssAstNode | undefined = firstBlockChild(children);\n\n while (node) {\n if (node.type === 'rule') {\n const sel = ((node as CssRule).rawSelector ?? '').trim();\n selector = selector ? sel.replace(/&/g, selector) : sel;\n node = firstBlockChild((node as CssRule).children ?? []);\n } else if (node.type === 'atrule') {\n const ar = node as CssAtRule;\n if (ar.name === 'slot') break;\n at = { name: ar.name, params: (ar.preludeText ?? '').trim() };\n node = ar.block ? firstBlockChild(ar.block.children) : undefined;\n } else {\n node = undefined;\n }\n }\n\n const wrap: VariantWrap = {};\n if (selector) wrap.selector = selector.includes('&') ? selector : `&${selector}`;\n if (at) wrap.atRule = at;\n return wrap.selector || wrap.atRule ? wrap : null;\n}\n\nfunction firstBlockChild(children: CssAstNode[]): CssAstNode | undefined {\n return children.find((c) => c.type === 'rule' || c.type === 'atrule');\n}\n\nfunction wrapFor(condition: string): VariantWrap {\n if (condition[0] === '@') {\n const cut = condition.search(/[\\s(]/);\n const at = cut === -1 ? condition.slice(1) : condition.slice(1, cut);\n const params = cut === -1 ? '' : condition.slice(cut).trim();\n return { atRule: { name: at, params } };\n }\n return { selector: condition.includes('&') ? condition : `&${condition}` };\n}\n"]}
1
+ {"version":3,"file":"directives.js","sourceRoot":"","sources":["../../../src/engine/directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAGzC,iFAAiF;AACjF,4EAA4E;AAC5E,gFAAgF;AAChF,qBAAqB;AACrB,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,GAAa;IACvD,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC5B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QAClC,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ;YAAE,SAAS;QACrC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;YAAE,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;aACnD,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAgB;YAAE,eAAe,CAAC,IAAI,EAAE,GAAG,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AAC;QAC7D,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC;IAC1C,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE,EAAE,CAAC;AAC7E,CAAC","sourcesContent":["import { parseCss } from '../css-parser';\nimport type { CssAstNode, CssAtRule, CssDeclaration, CssRule } from '../types/css-parser';\nimport { decl, rule } from './ast';\nimport { splitAtTopLevel } from './atom';\nimport type { Registry, RuleContext, RuleProduct, VariantWrap } from './registry';\n\n// Reads `@utility` and `@custom-variant` blocks from CSS and registers them into\n// the registry — the CSS-first way to add utilities and variants, alongside\n// `@theme` for tokens. Call after loadTheme so functional utilities can resolve\n// against the theme.\nexport function loadDirectives(css: string, reg: Registry): Registry {\n const sheet = parseCss(css);\n for (const node of sheet.children) {\n if (node.type !== 'atrule') continue;\n if (node.name === 'utility') registerUtility(node, reg);\n else if (node.name === 'custom-variant') registerVariant(node, reg);\n }\n return reg;\n}\n\nfunction registerUtility(atRule: CssAtRule, reg: Registry): void {\n const name = (atRule.preludeText ?? '').trim();\n if (!name || !atRule.block) return;\n\n // Flat declarations plus any nested rules (`&:hover`, `&::-webkit-scrollbar`);\n // the nested `&` is later woven with the utility's own selector by the compiler.\n const products = toProducts(atRule.block.children);\n if (products.length === 0) return;\n\n // A trailing `-*` marks a functional utility: `tab-*` handles `tab-2`, `tab-[3]`.\n if (name.endsWith('-*')) {\n const root = name.slice(0, -2);\n if (root) reg.dynamicRule(root, (ctx) => resolveProducts(products, ctx));\n return;\n }\n reg.rule(name, products);\n}\n\nfunction toProducts(children: CssAstNode[]): RuleProduct[] {\n const out: RuleProduct[] = [];\n for (const c of children) {\n if (c.type === 'declaration') {\n const d = c as CssDeclaration;\n out.push(decl(d.property, (d.rawValue ?? '').trim(), d.important === true));\n } else if (c.type === 'rule') {\n const r = c as CssRule;\n // The parser splits a rule's own declarations from its nested rules; a\n // utility body wants both, declarations first.\n const kids: CssAstNode[] = [...(r.declarations ?? []), ...(r.children ?? [])];\n out.push(rule((r.rawSelector ?? '').trim(), toProducts(kids)));\n }\n }\n return out;\n}\n\n// Applies a functional utility's templates to one atom, walking nested rules too.\n// `--value()` is required — if it can't resolve, the whole utility is dropped\n// (returns null). `--modifier()` is optional — a declaration using it is skipped\n// when there's no matching modifier, so `text-lg` and `text-lg/7` share one def.\nfunction resolveProducts(templates: RuleProduct[], ctx: RuleContext): RuleProduct[] | null {\n const out: RuleProduct[] = [];\n for (const t of templates) {\n if (t.kind === 'declaration') {\n const withValue = replaceFn(t.value, '--value', (args) => resolveValue(args, ctx));\n if (withValue === null) return null;\n const withModifier = replaceFn(withValue, '--modifier', (args) => resolveModifier(args, ctx));\n if (withModifier === null) continue;\n out.push({ ...t, value: withModifier });\n } else {\n const inner = resolveProducts(t.nodes as RuleProduct[], ctx);\n if (inner === null) return null;\n out.push(rule(t.selector, inner));\n }\n }\n return out.length ? out : null;\n}\n\nfunction resolveValue(args: string, ctx: RuleContext): string | null {\n const value = ctx.value;\n if (!value) return null;\n for (const arg of splitArgs(args)) {\n const themed = fromTheme(arg, value.kind === 'named' ? value.value : null, ctx);\n if (themed !== null) return themed;\n if (value.kind === 'named') {\n const lit = fromNamed(arg, value.value);\n if (lit !== null) return lit;\n } else {\n const arb = fromArbitrary(arg, value.value, value.dataType);\n if (arb !== null) return arb;\n }\n }\n return null;\n}\n\nfunction resolveModifier(args: string, ctx: RuleContext): string | null {\n const modifier = ctx.modifier;\n if (!modifier) return null;\n for (const arg of splitArgs(args)) {\n const themed = fromTheme(arg, modifier.kind === 'named' ? modifier.value : null, ctx);\n if (themed !== null) return themed;\n if (modifier.kind === 'named') {\n const lit = fromNamed(arg, modifier.value);\n if (lit !== null) return lit;\n } else {\n const arb = fromArbitrary(arg, modifier.value, null);\n if (arb !== null) return arb;\n }\n }\n return null;\n}\n\n// `--foo` / `--foo-*` names a theme namespace; the atom's named value keys into\n// it (`--value(--tab-size)` + `tab-2` → `var(--tab-size-2)`).\nfunction fromTheme(arg: string, key: string | null, ctx: RuleContext): string | null {\n if (key === null || !arg.startsWith('--')) return null;\n const ns = arg.replace(/-?\\*$/, '').slice(2);\n return ns ? ctx.theme.resolve(ns, key) : null;\n}\n\n// A bare value against a data-type keyword (`integer`, `number`, `percentage`) or a\n// quoted literal (`'inline'`).\nfunction fromNamed(arg: string, value: string): string | null {\n if (isQuoted(arg)) return arg.slice(1, -1) === value ? value : null;\n const rx = NUMERIC[arg];\n return rx ? (rx.test(value) ? value : null) : null;\n}\n\n// An arbitrary value against `[*]` (anything) or a typed bracket (`[integer]`,\n// `[length]`), gated on the value's own `type:` hint when it carries one.\nfunction fromArbitrary(arg: string, value: string, dataType: string | null): string | null {\n if (arg[0] !== '[' || arg[arg.length - 1] !== ']') return null;\n const want = arg.slice(1, -1);\n if (want === '*') return value;\n if (dataType !== null) return dataType === want ? value : null;\n // Untyped arbitrary: validate against the simple numeric types we can check.\n const rx = NUMERIC[want];\n return rx ? (rx.test(value) ? value : null) : value;\n}\n\nconst NUMERIC: Record<string, RegExp> = {\n integer: /^-?\\d+$/,\n number: /^-?\\d*\\.?\\d+$/,\n percentage: /^-?\\d*\\.?\\d+%$/,\n};\n\nfunction isQuoted(s: string): boolean {\n return s.length >= 2 && (s[0] === '\"' || s[0] === \"'\") && s[s.length - 1] === s[0];\n}\n\nfunction splitArgs(args: string): string[] {\n return splitAtTopLevel(args, ',').map((a) => a.trim()).filter((a) => a !== '');\n}\n\n// Replaces every `name(...)` call in `input` (parens balanced, even when nested in\n// `calc(...)`) with `resolve`'s result. Returns null if any call fails to resolve.\nfunction replaceFn(input: string, name: string, resolve: (args: string) => string | null): string | null {\n const token = name + '(';\n let out = '';\n let i = 0;\n for (;;) {\n const start = input.indexOf(token, i);\n if (start === -1) return out + input.slice(i);\n out += input.slice(i, start);\n let depth = 0;\n let j = start + token.length - 1;\n for (; j < input.length; j++) {\n if (input[j] === '(') depth++;\n else if (input[j] === ')' && --depth === 0) break;\n }\n if (j >= input.length) return null; // unbalanced\n const resolved = resolve(input.slice(start + token.length, j));\n if (resolved === null) return null;\n out += resolved;\n i = j + 1;\n }\n}\n\nfunction registerVariant(atRule: CssAtRule, reg: Registry): void {\n const prelude = (atRule.preludeText ?? '').trim();\n if (!prelude) return;\n\n // Block form: `@custom-variant name { &:hover { @slot } }` — the prelude is just\n // the name and the block describes the wrapping, marked by `@slot`.\n if (atRule.block) {\n const wrap = blockToWrap(atRule.block.children);\n if (prelude && wrap) reg.variant(prelude, wrap);\n return;\n }\n\n // Shorthand: `@custom-variant name (condition)`.\n const paren = prelude.indexOf('(');\n if (paren === -1 || !prelude.endsWith(')')) return;\n\n const name = prelude.slice(0, paren).trim();\n const condition = prelude.slice(paren + 1, -1).trim();\n if (!name || !condition) return;\n\n reg.variant(name, wrapFor(condition));\n}\n\n// Walk the single path down to `@slot`, collecting the selector (nested rules,\n// combined by `&` substitution) and/or the wrapping at-rule (`@media`, `@supports`).\n// Supports one selector level, one at-rule level, or both nested.\nfunction blockToWrap(children: CssAstNode[]): VariantWrap | null {\n let selector: string | undefined;\n let at: { name: string; params: string } | undefined;\n let node: CssAstNode | undefined = firstBlockChild(children);\n\n while (node) {\n if (node.type === 'rule') {\n const sel = ((node as CssRule).rawSelector ?? '').trim();\n selector = selector ? sel.replace(/&/g, selector) : sel;\n node = firstBlockChild((node as CssRule).children ?? []);\n } else if (node.type === 'atrule') {\n const ar = node as CssAtRule;\n if (ar.name === 'slot') break;\n at = { name: ar.name, params: (ar.preludeText ?? '').trim() };\n node = ar.block ? firstBlockChild(ar.block.children) : undefined;\n } else {\n node = undefined;\n }\n }\n\n const wrap: VariantWrap = {};\n if (selector) wrap.selector = selector.includes('&') ? selector : `&${selector}`;\n if (at) wrap.atRule = at;\n return wrap.selector || wrap.atRule ? wrap : null;\n}\n\nfunction firstBlockChild(children: CssAstNode[]): CssAstNode | undefined {\n return children.find((c) => c.type === 'rule' || c.type === 'atrule');\n}\n\nfunction wrapFor(condition: string): VariantWrap {\n if (condition[0] === '@') {\n const cut = condition.search(/[\\s(]/);\n const at = cut === -1 ? condition.slice(1) : condition.slice(1, cut);\n const params = cut === -1 ? '' : condition.slice(cut).trim();\n return { atRule: { name: at, params } };\n }\n return { selector: condition.includes('&') ? condition : `&${condition}` };\n}\n"]}
@@ -1,5 +1,7 @@
1
+ export * from './apply';
1
2
  export * from './ast';
2
3
  export * from './atom';
4
+ export * from './log';
3
5
  export * from './theme';
4
6
  export * from './theme-source';
5
7
  export * from './directives';
@@ -25,6 +27,8 @@ export interface CompileOptions {
25
27
  sources?: string[];
26
28
  /** Base directory for resolving `@source` globs. Default `process.cwd()`. */
27
29
  base?: string;
30
+ /** Shared base CSS (`@theme`/`@utility`/`@custom-variant`) loaded before `input`. */
31
+ theme?: string;
28
32
  /** Prepend `:root { …tokens }`. Default true. */
29
33
  emitTokens?: boolean;
30
34
  /** Also emit the `--flx-ui-*` bridge that drives Fluixi UI from the theme. */
@@ -1,5 +1,7 @@
1
+ export * from './apply';
1
2
  export * from './ast';
2
3
  export * from './atom';
4
+ export * from './log';
3
5
  export * from './theme';
4
6
  export * from './theme-source';
5
7
  export * from './directives';
@@ -42,10 +44,14 @@ export function compileClasses(classes, reg, options) {
42
44
  export function compile(input, options = {}) {
43
45
  var _a, _b, _c, _d;
44
46
  const reg = (_a = options.registry) !== null && _a !== void 0 ? _a : createRegistry();
47
+ if (options.theme)
48
+ loadTheme(options.theme, reg.theme);
45
49
  loadTheme(input, reg.theme);
46
50
  // Re-seed the named breakpoint variants so a `@theme` breakpoint override reaches
47
51
  // `sm:`/`md:`/… (they baked the default value at registry-creation time).
48
52
  registerBreakpointVariants(reg);
53
+ if (options.theme)
54
+ loadDirectives(options.theme, reg);
49
55
  loadDirectives(input, reg);
50
56
  const classes = new Set((_b = options.classes) !== null && _b !== void 0 ? _b : []);
51
57
  for (const source of (_c = options.sources) !== null && _c !== void 0 ? _c : []) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/engine/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAE5B,OAAO,EAAgB,SAAS,EAAyB,MAAM,OAAO,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAExD,8EAA8E;AAC9E,uBAAuB;AACvB,MAAM,UAAU,cAAc,CAAC,OAAiB,EAAE,GAAa,EAAE,OAA0B;IACzF,MAAM,KAAK,GAAc,EAAE,CAAC;IAC5B,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM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K,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;IAErB,OAAO,EAAE,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;AAC9G,CAAC","sourcesContent":["export * from './ast';\nexport * from './atom';\nexport * from './theme';\nexport * from './theme-source';\nexport * from './directives';\nexport * from './registry';\nexport * from './compile';\nexport * from './defaults';\nexport * from './theme-defaults';\nexport * from './variants';\nexport * from './utilities';\nexport * from './scanner';\nexport * from './source';\nexport * from './ui-preset';\nexport * from './transform';\n\nimport { type AstNode, stringify, type StringifyOptions } from './ast';\nimport { parseAtom } from './atom';\nimport { compileAtom } from './compile';\nimport { createRegistry } from './defaults';\nimport { Registry } from './registry';\nimport { scanAtoms } from './scanner';\nimport { loadDirectives } from './directives';\nimport { parseSources, resolveSourceFiles, scanSourceFiles } from './source';\nimport { collectVarRefs, emitTheme, loadTheme } from './theme-source';\nimport { emitUiTheme } from './ui-preset';\nimport { registerBreakpointVariants } from './variants';\n\n// Parse, compile and stringify a set of utility classes. Unknown or malformed\n// classes are skipped.\nexport function compileClasses(classes: string[], reg: Registry, options?: StringifyOptions): string {\n const nodes: AstNode[] = [];\n for (const cls of classes) {\n const atom = parseAtom(cls, reg);\n if (!atom) continue;\n const compiled = compileAtom(atom, reg);\n if (compiled) nodes.push(...compiled);\n }\n return stringify(nodes, options);\n}\n\nexport interface CompileOptions {\n /** An existing registry; defaults to {@link createRegistry}. */\n registry?: Registry;\n /** Classes to compile directly. */\n classes?: string[];\n /** Raw source texts to scan for classes. */\n sources?: string[];\n /** Base directory for resolving `@source` globs. Default `process.cwd()`. */\n base?: string;\n /** Prepend `:root { …tokens }`. Default true. */\n emitTokens?: boolean;\n /** Also emit the `--flx-ui-*` bridge that drives Fluixi UI from the theme. */\n emitUiTokens?: boolean;\n minify?: boolean;\n}\n\nexport interface CompileResult {\n css: string;\n classes: string[];\n /** Absolute paths of the files scanned via `@source` — watch deps for a plugin. */\n sources: string[];\n registry: Registry;\n}\n\n// The one-call entry: merge `@theme` tokens from `input`, gather classes (given\n// and/or scanned), and emit the token `:root` plus the rules they need.\nexport function compile(input: string, options: CompileOptions = {}): CompileResult {\n const reg = options.registry ?? createRegistry();\n loadTheme(input, reg.theme);\n // Re-seed the named breakpoint variants so a `@theme` breakpoint override reaches\n // `sm:`/`md:`/… (they baked the default value at registry-creation time).\n registerBreakpointVariants(reg);\n loadDirectives(input, reg);\n\n const classes = new Set<string>(options.classes ?? []);\n for (const source of options.sources ?? []) {\n for (const c of scanAtoms(source)) classes.add(c);\n }\n\n // `@source` directives pull classes from files on disk.\n const parsedSources = parseSources(input);\n for (const c of parsedSources.inline) classes.add(c);\n let sources: string[] = [];\n if (parsedSources.patterns.length) {\n sources = resolveSourceFiles(parsedSources, options.base ?? process.cwd());\n for (const c of scanSourceFiles(sources)) classes.add(c);\n }\n\n const rules: AstNode[] = [];\n for (const cls of classes) {\n const atom = parseAtom(cls, reg);\n if (!atom) continue;\n const compiled = compileAtom(atom, reg);\n if (compiled) rules.push(...compiled);\n }\n\n // The `--flx-ui-*` bridge, if requested — its `var()` refs must survive the\n // token tree-shake, so fold them into the used set.\n const uiBlock = options.emitUiTokens ? emitUiTheme(reg.theme) : null;\n\n // Emit only the tokens the compiled rules (and any UI bridge) actually reference.\n const nodes: AstNode[] = [];\n if (options.emitTokens !== false) {\n const used = collectVarRefs(rules);\n if (uiBlock) collectVarRefs([uiBlock], used);\n const tokens = emitTheme(reg.theme, ':root', used);\n if (tokens.nodes.length) nodes.push(tokens);\n }\n if (uiBlock && uiBlock.nodes.length) nodes.push(uiBlock);\n nodes.push(...rules);\n\n return { css: stringify(nodes, { minify: options.minify }), classes: [...classes], sources, registry: reg };\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/engine/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,MAAM,CAAC,CAAC;IAC9C,CAAC;IACD,IAAI,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzD,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;IAErB,OAAO,EAAE,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;AAC9G,CAAC","sourcesContent":["export * from './apply';\nexport * from './ast';\nexport * from './atom';\nexport * from './log';\nexport * from './theme';\nexport * from './theme-source';\nexport * from './directives';\nexport * from './registry';\nexport * from './compile';\nexport * from './defaults';\nexport * from './theme-defaults';\nexport * from './variants';\nexport * from './utilities';\nexport * from './scanner';\nexport * from './source';\nexport * from './ui-preset';\nexport * from './transform';\n\nimport { type AstNode, stringify, type StringifyOptions } from './ast';\nimport { parseAtom } from './atom';\nimport { compileAtom } from './compile';\nimport { createRegistry } from './defaults';\nimport { Registry } from './registry';\nimport { scanAtoms } from './scanner';\nimport { loadDirectives } from './directives';\nimport { parseSources, resolveSourceFiles, scanSourceFiles } from './source';\nimport { collectVarRefs, emitTheme, loadTheme } from './theme-source';\nimport { emitUiTheme } from './ui-preset';\nimport { registerBreakpointVariants } from './variants';\n\n// Parse, compile and stringify a set of utility classes. Unknown or malformed\n// classes are skipped.\nexport function compileClasses(classes: string[], reg: Registry, options?: StringifyOptions): string {\n const nodes: AstNode[] = [];\n for (const cls of classes) {\n const atom = parseAtom(cls, reg);\n if (!atom) continue;\n const compiled = compileAtom(atom, reg);\n if (compiled) nodes.push(...compiled);\n }\n return stringify(nodes, options);\n}\n\nexport interface CompileOptions {\n /** An existing registry; defaults to {@link createRegistry}. */\n registry?: Registry;\n /** Classes to compile directly. */\n classes?: string[];\n /** Raw source texts to scan for classes. */\n sources?: string[];\n /** Base directory for resolving `@source` globs. Default `process.cwd()`. */\n base?: string;\n /** Shared base CSS (`@theme`/`@utility`/`@custom-variant`) loaded before `input`. */\n theme?: string;\n /** Prepend `:root { …tokens }`. Default true. */\n emitTokens?: boolean;\n /** Also emit the `--flx-ui-*` bridge that drives Fluixi UI from the theme. */\n emitUiTokens?: boolean;\n minify?: boolean;\n}\n\nexport interface CompileResult {\n css: string;\n classes: string[];\n /** Absolute paths of the files scanned via `@source` — watch deps for a plugin. */\n sources: string[];\n registry: Registry;\n}\n\n// The one-call entry: merge `@theme` tokens from `input`, gather classes (given\n// and/or scanned), and emit the token `:root` plus the rules they need.\nexport function compile(input: string, options: CompileOptions = {}): CompileResult {\n const reg = options.registry ?? createRegistry();\n if (options.theme) loadTheme(options.theme, reg.theme);\n loadTheme(input, reg.theme);\n // Re-seed the named breakpoint variants so a `@theme` breakpoint override reaches\n // `sm:`/`md:`/… (they baked the default value at registry-creation time).\n registerBreakpointVariants(reg);\n if (options.theme) loadDirectives(options.theme, reg);\n loadDirectives(input, reg);\n\n const classes = new Set<string>(options.classes ?? []);\n for (const source of options.sources ?? []) {\n for (const c of scanAtoms(source)) classes.add(c);\n }\n\n // `@source` directives pull classes from files on disk.\n const parsedSources = parseSources(input);\n for (const c of parsedSources.inline) classes.add(c);\n let sources: string[] = [];\n if (parsedSources.patterns.length) {\n sources = resolveSourceFiles(parsedSources, options.base ?? process.cwd());\n for (const c of scanSourceFiles(sources)) classes.add(c);\n }\n\n const rules: AstNode[] = [];\n for (const cls of classes) {\n const atom = parseAtom(cls, reg);\n if (!atom) continue;\n const compiled = compileAtom(atom, reg);\n if (compiled) rules.push(...compiled);\n }\n\n // The `--flx-ui-*` bridge, if requested — its `var()` refs must survive the\n // token tree-shake, so fold them into the used set.\n const uiBlock = options.emitUiTokens ? emitUiTheme(reg.theme) : null;\n\n // Emit only the tokens the compiled rules (and any UI bridge) actually reference.\n const nodes: AstNode[] = [];\n if (options.emitTokens !== false) {\n const used = collectVarRefs(rules);\n if (uiBlock) collectVarRefs([uiBlock], used);\n const tokens = emitTheme(reg.theme, ':root', used);\n if (tokens.nodes.length) nodes.push(tokens);\n }\n if (uiBlock && uiBlock.nodes.length) nodes.push(uiBlock);\n nodes.push(...rules);\n\n return { css: stringify(nodes, { minify: options.minify }), classes: [...classes], sources, registry: reg };\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import type { TransformStats } from './transform';
2
+ export interface FormatLogOptions {
3
+ /** Emit ANSI colours. Default true. */
4
+ color?: boolean;
5
+ }
6
+ export declare function formatBuildLog(label: string, stats: TransformStats, options?: FormatLogOptions): string;