@fluixi-css/core 1.0.0-next.4 → 1.0.0-next.5
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.
- package/dist/package.json +1 -1
- package/dist/src/css-parser.cjs +11 -3
- package/dist/src/css-parser.cjs.map +1 -1
- package/dist/src/css-parser.d.ts +2 -0
- package/dist/src/css-parser.js +10 -5
- package/dist/src/css-parser.js.map +1 -1
- package/dist/src/css-parser.mjs +11 -3
- package/dist/src/css-parser.mjs.map +1 -1
- package/dist/src/engine/apply.js +5 -69
- package/dist/src/engine/apply.js.map +1 -1
- package/dist/src/engine/index.d.ts +1 -0
- package/dist/src/engine/index.js +11 -4
- package/dist/src/engine/index.js.map +1 -1
- package/dist/src/engine/registry.d.ts +7 -0
- package/dist/src/engine/registry.js +9 -0
- package/dist/src/engine/registry.js.map +1 -1
- package/dist/src/engine/style.d.ts +65 -0
- package/dist/src/engine/style.js +284 -0
- package/dist/src/engine/style.js.map +1 -0
- package/dist/src/engine/transform.d.ts +6 -0
- package/dist/src/engine/transform.js +11 -5
- package/dist/src/engine/transform.js.map +1 -1
- package/dist/src/engine/ui-preset.d.ts +2 -0
- package/dist/src/engine/ui-preset.js +2 -0
- package/dist/src/engine/ui-preset.js.map +1 -1
- package/dist/src/index.cjs +2209 -1851
- package/dist/src/index.cjs.map +1 -1
- package/dist/src/index.mjs +2202 -1852
- package/dist/src/index.mjs.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/src/engine/apply.js
CHANGED
|
@@ -1,75 +1,11 @@
|
|
|
1
1
|
import { stringify } from './ast';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
// `@apply
|
|
5
|
-
//
|
|
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;
|
|
2
|
+
import { applyUtilities, parseStyle } from './style';
|
|
3
|
+
// `@apply a b c;` in author CSS that `transform` passes through: the slice is parsed, the
|
|
4
|
+
// `@apply` at-rules are expanded on the AST (`style.ts`), and the result is printed again.
|
|
5
|
+
// A slice without `@apply` is returned as written.
|
|
11
6
|
export function expandApply(css, reg) {
|
|
12
7
|
if (!css.includes('@apply'))
|
|
13
8
|
return css;
|
|
14
|
-
return
|
|
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
|
-
}
|
|
9
|
+
return stringify(applyUtilities(parseStyle(css), reg)).trimEnd();
|
|
74
10
|
}
|
|
75
11
|
//# sourceMappingURL=apply.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../src/engine/apply.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../src/engine/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErD,0FAA0F;AAC1F,2FAA2F;AAC3F,mDAAmD;AACnD,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,GAAa;IACpD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,GAAG,CAAC;IACxC,OAAO,SAAS,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AACnE,CAAC","sourcesContent":["import { stringify } from './ast';\nimport type { Registry } from './registry';\nimport { applyUtilities, parseStyle } from './style';\n\n// `@apply a b c;` in author CSS that `transform` passes through: the slice is parsed, the\n// `@apply` at-rules are expanded on the AST (`style.ts`), and the result is printed again.\n// A slice without `@apply` is returned as written.\nexport function expandApply(css: string, reg: Registry): string {\n if (!css.includes('@apply')) return css;\n return stringify(applyUtilities(parseStyle(css), reg)).trimEnd();\n}\n"]}
|
|
@@ -14,6 +14,7 @@ export * from './utilities';
|
|
|
14
14
|
export * from './scanner';
|
|
15
15
|
export * from './source';
|
|
16
16
|
export * from './ui-preset';
|
|
17
|
+
export * from './style';
|
|
17
18
|
export * from './transform';
|
|
18
19
|
import { type StringifyOptions } from './ast';
|
|
19
20
|
import { Registry } from './registry';
|
package/dist/src/engine/index.js
CHANGED
|
@@ -14,8 +14,9 @@ export * from './utilities';
|
|
|
14
14
|
export * from './scanner';
|
|
15
15
|
export * from './source';
|
|
16
16
|
export * from './ui-preset';
|
|
17
|
+
export * from './style';
|
|
17
18
|
export * from './transform';
|
|
18
|
-
import { stringify } from './ast';
|
|
19
|
+
import { atRule, stringify } from './ast';
|
|
19
20
|
import { parseAtom } from './atom';
|
|
20
21
|
import { compileAtom } from './compile';
|
|
21
22
|
import { createRegistry } from './defaults';
|
|
@@ -23,7 +24,7 @@ import { scanAtoms } from './scanner';
|
|
|
23
24
|
import { loadDirectives } from './directives';
|
|
24
25
|
import { parseSources, resolveSourceFiles, scanSourceFiles } from './source';
|
|
25
26
|
import { collectVarRefs, emitTheme, loadTheme } from './theme-source';
|
|
26
|
-
import { emitUiTheme } from './ui-preset';
|
|
27
|
+
import { emitUiTheme, UI_TOKENS_LAYER } from './ui-preset';
|
|
27
28
|
import { registerBreakpointVariants } from './variants';
|
|
28
29
|
// Parse, compile and stringify a set of utility classes. Unknown or malformed
|
|
29
30
|
// classes are skipped.
|
|
@@ -90,8 +91,14 @@ export function compile(input, options = {}) {
|
|
|
90
91
|
if (tokens.nodes.length)
|
|
91
92
|
nodes.push(tokens);
|
|
92
93
|
}
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
// In the tokens layer, where fluixi-ui's own defaults live: later in the cascade than those, so
|
|
95
|
+
// the theme still drives them, and below `flx.skin`, so a skin's tokens win. Unlayered, the
|
|
96
|
+
// bridge beat every layer and a skin's radii, sizes and shadows never applied.
|
|
97
|
+
if (uiBlocks) {
|
|
98
|
+
const blocks = uiBlocks.filter((b) => b.nodes.length);
|
|
99
|
+
if (blocks.length)
|
|
100
|
+
nodes.push(atRule('layer', UI_TOKENS_LAYER, blocks));
|
|
101
|
+
}
|
|
95
102
|
nodes.push(...rules);
|
|
96
103
|
return { css: stringify(nodes, { minify: options.minify }), classes: [...classes], sources, registry: reg };
|
|
97
104
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/engine/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,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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AAG,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QACnD,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM;YAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IACD,gGAAgG;IAChG,4FAA4F;IAC5F,+EAA+E;IAC/E,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACtD,IAAI,MAAM,CAAC,MAAM;YAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1E,CAAC;IACD,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 './style';\nexport * from './transform';\n\nimport { type AstNode, atRule, 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, UI_TOKENS_LAYER } 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 uiBlocks = 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 (uiBlocks) collectVarRefs(uiBlocks, used);\n const tokens = emitTheme(reg.theme, ':root', used);\n if (tokens.nodes.length) nodes.push(tokens);\n }\n // In the tokens layer, where fluixi-ui's own defaults live: later in the cascade than those, so\n // the theme still drives them, and below `flx.skin`, so a skin's tokens win. Unlayered, the\n // bridge beat every layer and a skin's radii, sizes and shadows never applied.\n if (uiBlocks) {\n const blocks = uiBlocks.filter((b) => b.nodes.length);\n if (blocks.length) nodes.push(atRule('layer', UI_TOKENS_LAYER, blocks));\n }\n nodes.push(...rules);\n\n return { css: stringify(nodes, { minify: options.minify }), classes: [...classes], sources, registry: reg };\n}\n"]}
|
|
@@ -36,6 +36,13 @@ export declare class Registry implements AtomContext {
|
|
|
36
36
|
dynamicRule(name: string, handler: DynamicRuleFn): this;
|
|
37
37
|
variant(name: string, wrap: VariantWrap): this;
|
|
38
38
|
dynamicVariant(name: string, handler: DynamicVariantFn): this;
|
|
39
|
+
/** Every registered name, for tools that list them (completion, a utility reference). */
|
|
40
|
+
names(): {
|
|
41
|
+
rules: string[];
|
|
42
|
+
dynamicRules: string[];
|
|
43
|
+
variants: string[];
|
|
44
|
+
dynamicVariants: string[];
|
|
45
|
+
};
|
|
39
46
|
isRule: (root: string) => boolean;
|
|
40
47
|
isDynamicRule: (root: string) => boolean;
|
|
41
48
|
isVariant: (root: string) => boolean;
|
|
@@ -29,6 +29,15 @@ export class Registry {
|
|
|
29
29
|
this.dynamicVariants.set(name, handler);
|
|
30
30
|
return this;
|
|
31
31
|
}
|
|
32
|
+
/** Every registered name, for tools that list them (completion, a utility reference). */
|
|
33
|
+
names() {
|
|
34
|
+
return {
|
|
35
|
+
rules: [...this.rules.keys()],
|
|
36
|
+
dynamicRules: [...this.dynamicRules.keys()],
|
|
37
|
+
variants: [...this.variants.keys()],
|
|
38
|
+
dynamicVariants: [...this.dynamicVariants.keys()],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
32
41
|
getRule(root) {
|
|
33
42
|
var _a;
|
|
34
43
|
return (_a = this.rules.get(root)) !== null && _a !== void 0 ? _a : null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/engine/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AA6BhC,+EAA+E;AAC/E,+CAA+C;AAC/C,MAAM,OAAO,QAAQ;IAQnB,YAAY,QAAe,IAAI,KAAK,EAAE;QAL9B,UAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;QACzC,iBAAY,GAAG,IAAI,GAAG,EAAyB,CAAC;QAChD,aAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;QAC1C,oBAAe,GAAG,IAAI,GAAG,EAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/engine/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AA6BhC,+EAA+E;AAC/E,+CAA+C;AAC/C,MAAM,OAAO,QAAQ;IAQnB,YAAY,QAAe,IAAI,KAAK,EAAE;QAL9B,UAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;QACzC,iBAAY,GAAG,IAAI,GAAG,EAAyB,CAAC;QAChD,aAAQ,GAAG,IAAI,GAAG,EAAuB,C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C,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;YAC3C,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,eAAe,EAAE,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;SAClD,CAAC;IACJ,CAAC;IAOD,OAAO,CAAC,IAAY;;QAClB,OAAO,MAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,mCAAI,IAAI,CAAC;IACtC,CAAC;IACD,cAAc,CAAC,IAAY;;QACzB,OAAO,MAAA,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,mCAAI,IAAI,CAAC;IAC7C,CAAC;IACD,UAAU,CAAC,IAAY;;QACrB,OAAO,MAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,mCAAI,IAAI,CAAC;IACzC,CAAC;IACD,iBAAiB,CAAC,IAAY;;QAC5B,OAAO,MAAA,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,mCAAI,IAAI,CAAC;IAChD,CAAC;CACF","sourcesContent":["import type { Declaration, StyleRule } from './ast';\nimport type { AtomContext, AtomModifier, AtomValue } from './atom';\nimport { Theme } from './theme';\n\nexport interface RuleContext {\n value: AtomValue | null;\n modifier: AtomModifier | null;\n negative: boolean;\n theme: Theme;\n}\n\n// A utility produces declarations on its own selector, and/or nested rules whose\n// `&` is woven with that selector — the latter is how child-combinator utilities\n// like `space-x`/`divide-y` reach `& > * + *`.\nexport type RuleProduct = Declaration | StyleRule;\nexport type DynamicRuleFn = (ctx: RuleContext) => RuleProduct[] | null;\n\n// A variant either narrows the selector (`&:hover`, `.group:hover &`) or wraps\n// the rule in an at-rule (`@media`, `@supports`). It may do both.\nexport interface VariantWrap {\n selector?: string;\n atRule?: { name: string; params: string };\n}\n\nexport type VariantValue =\n | { kind: 'named'; value: string }\n | { kind: 'arbitrary'; value: string; dataType: string | null }\n | null;\n\nexport type DynamicVariantFn = (value: VariantValue, modifier: AtomModifier | null) => VariantWrap | null;\n\n// Holds the theme plus the rule and variant tables, and answers the keyword vs\n// value-taking questions the atom parser asks.\nexport class Registry implements AtomContext {\n readonly theme: Theme;\n\n private rules = new Map<string, RuleProduct[]>();\n private dynamicRules = new Map<string, DynamicRuleFn>();\n private variants = new Map<string, VariantWrap>();\n private dynamicVariants = new Map<string, DynamicVariantFn>();\n\n constructor(theme: Theme = new Theme()) {\n this.theme = theme;\n }\n\n rule(name: string, products: RuleProduct[]): this {\n this.rules.set(name, products);\n return this;\n }\n\n dynamicRule(name: string, handler: DynamicRuleFn): this {\n this.dynamicRules.set(name, handler);\n return this;\n }\n\n variant(name: string, wrap: VariantWrap): this {\n this.variants.set(name, wrap);\n return this;\n }\n\n dynamicVariant(name: string, handler: DynamicVariantFn): this {\n this.dynamicVariants.set(name, handler);\n return this;\n }\n\n /** Every registered name, for tools that list them (completion, a utility reference). */\n names(): { rules: string[]; dynamicRules: string[]; variants: string[]; dynamicVariants: string[] } {\n return {\n rules: [...this.rules.keys()],\n dynamicRules: [...this.dynamicRules.keys()],\n variants: [...this.variants.keys()],\n dynamicVariants: [...this.dynamicVariants.keys()],\n };\n }\n\n isRule = (root: string): boolean => this.rules.has(root);\n isDynamicRule = (root: string): boolean => this.dynamicRules.has(root);\n isVariant = (root: string): boolean => this.variants.has(root);\n isDynamicVariant = (root: string): boolean => this.dynamicVariants.has(root);\n\n getRule(root: string): RuleProduct[] | null {\n return this.rules.get(root) ?? null;\n }\n getDynamicRule(root: string): DynamicRuleFn | null {\n return this.dynamicRules.get(root) ?? null;\n }\n getVariant(name: string): VariantWrap | null {\n return this.variants.get(name) ?? null;\n }\n getDynamicVariant(root: string): DynamicVariantFn | null {\n return this.dynamicVariants.get(root) ?? null;\n }\n}\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type AstNode } from './ast';
|
|
2
|
+
import type { Registry } from './registry';
|
|
3
|
+
/** Parses author CSS into the engine's AST, in source order. */
|
|
4
|
+
export declare function parseStyle(css: string, from?: string): AstNode[];
|
|
5
|
+
/**
|
|
6
|
+
* Replaces each `@apply a b c` with what those utilities produce: flat declarations in place,
|
|
7
|
+
* and a nested rule (`&` standing for the applying selector) for a utility that needs a
|
|
8
|
+
* selector of its own (`hover:`, `group-hover:`, `space-x-*`, `md:`). Unknown classes are
|
|
9
|
+
* skipped. `applied` collects the utilities used.
|
|
10
|
+
*/
|
|
11
|
+
export declare function applyUtilities(nodes: AstNode[], reg: Registry, applied?: Set<string>): AstNode[];
|
|
12
|
+
/** Splits a selector list on its top-level commas (not those inside `:is(…)`, `[…]` or quotes). */
|
|
13
|
+
export declare function splitSelectorList(selector: string): string[];
|
|
14
|
+
/** The selector a nested rule stands for, given its parent's: `&` replaced, or a descendant. */
|
|
15
|
+
export declare function resolveNested(child: string, parent: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves CSS nesting into plain rules, keeping the cascade: a rule's declarations stay
|
|
18
|
+
* together until a nested rule interrupts them, and the ones after it follow it. Grouping
|
|
19
|
+
* at-rules nested in a rule wrap a rule on the parent's selector.
|
|
20
|
+
*/
|
|
21
|
+
export declare function flattenNesting(nodes: AstNode[], parent?: string | null): AstNode[];
|
|
22
|
+
/**
|
|
23
|
+
* What every stylesheet of one project shares: the registry (theme, utilities, variants,
|
|
24
|
+
* custom definitions) and the theme tokens the processed CSS refers to, so the global sheet
|
|
25
|
+
* keeps them however they are reached. One per build, made by whoever orchestrates it.
|
|
26
|
+
*/
|
|
27
|
+
export interface CssContext {
|
|
28
|
+
registry: Registry;
|
|
29
|
+
/** Custom properties referenced by CSS processed in this context (`--spacing`, `--color-…`). */
|
|
30
|
+
usedTokens: Set<string>;
|
|
31
|
+
}
|
|
32
|
+
export interface CssContextOptions {
|
|
33
|
+
/** The project's theme CSS: its `@theme`, `@utility` and `@custom-variant` feed the registry. */
|
|
34
|
+
theme?: string;
|
|
35
|
+
registry?: Registry;
|
|
36
|
+
}
|
|
37
|
+
export declare function createCssContext(options?: CssContextOptions): CssContext;
|
|
38
|
+
export interface ProcessOptions {
|
|
39
|
+
/** File the CSS came from, for source locations. */
|
|
40
|
+
from?: string;
|
|
41
|
+
/** Resolve nesting into plain selectors (what scoping needs). Default `true`. */
|
|
42
|
+
flatten?: boolean;
|
|
43
|
+
minify?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface ProcessResult {
|
|
46
|
+
ast: AstNode[];
|
|
47
|
+
css: string;
|
|
48
|
+
/** Utilities `@apply` used. */
|
|
49
|
+
applied: string[];
|
|
50
|
+
/** Context directives found and left out: they belong in the project's theme CSS. */
|
|
51
|
+
ignored: string[];
|
|
52
|
+
/**
|
|
53
|
+
* `@reference "…"` targets, in order. A stylesheet processed on its own names the CSS whose
|
|
54
|
+
* theme and utilities it relies on; the orchestrator, which reads files, builds the context
|
|
55
|
+
* from them. The referenced CSS is never emitted.
|
|
56
|
+
*/
|
|
57
|
+
references: string[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Processes one stylesheet in a shared context, exactly as the project's own CSS would be:
|
|
61
|
+
* `@apply` expanded with the context's utilities, theme values resolved, nesting flattened.
|
|
62
|
+
* It never emits the utility layer or the theme tokens; the tokens it refers to are recorded
|
|
63
|
+
* in `ctx.usedTokens` for the global sheet to keep.
|
|
64
|
+
*/
|
|
65
|
+
export declare function processCss(input: string | AstNode[], ctx: CssContext, options?: ProcessOptions): ProcessResult;
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// Author CSS as an AST, and what @fluixi-css does to it: `@apply` expanded in place, and,
|
|
2
|
+
// for CSS that is about to be scoped, nesting resolved into plain selectors.
|
|
3
|
+
//
|
|
4
|
+
// Every caller (the project stylesheet through `transform`, a component's `<style>`, a `css``
|
|
5
|
+
// literal) goes through these functions with one shared registry, so a utility means the same
|
|
6
|
+
// thing wherever it is used and nothing here emits the utility layer itself.
|
|
7
|
+
import { parseCss } from '../css-parser';
|
|
8
|
+
import { atRule, decl, raw, rule, stringify } from './ast';
|
|
9
|
+
import { parseAtom } from './atom';
|
|
10
|
+
import { compileAtom, escapeClass } from './compile';
|
|
11
|
+
import { createRegistry } from './defaults';
|
|
12
|
+
import { loadDirectives } from './directives';
|
|
13
|
+
import { collectVarRefs, loadTheme } from './theme-source';
|
|
14
|
+
import { registerBreakpointVariants } from './variants';
|
|
15
|
+
// ─── Parser tree → engine AST ────────────────────────────────────────────────
|
|
16
|
+
const offsetOf = (node) => { var _a, _b; return (_b = (_a = node.loc) === null || _a === void 0 ? void 0 : _a.start.offset) !== null && _b !== void 0 ? _b : 0; };
|
|
17
|
+
function locOf(node, source) {
|
|
18
|
+
if (!source || !node.loc)
|
|
19
|
+
return undefined;
|
|
20
|
+
return { source, line: node.loc.start.line, column: Math.max(0, node.loc.start.column - 1) };
|
|
21
|
+
}
|
|
22
|
+
/** Parses author CSS into the engine's AST, in source order. */
|
|
23
|
+
export function parseStyle(css, from) {
|
|
24
|
+
const sheet = parseCss(css, { includeSourceMaps: true, includeComments: false });
|
|
25
|
+
return convertAll(sheet.children, from);
|
|
26
|
+
}
|
|
27
|
+
function convertAll(nodes, from) {
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const node of nodes) {
|
|
30
|
+
const converted = convert(node, from);
|
|
31
|
+
if (converted)
|
|
32
|
+
out.push(converted);
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
function convert(node, from) {
|
|
37
|
+
var _a, _b, _c, _d, _e;
|
|
38
|
+
switch (node.type) {
|
|
39
|
+
case 'declaration': {
|
|
40
|
+
const d = node;
|
|
41
|
+
return decl(d.property, (_a = d.rawValue) !== null && _a !== void 0 ? _a : '', d.important, locOf(d, from));
|
|
42
|
+
}
|
|
43
|
+
case 'rule': {
|
|
44
|
+
const r = node;
|
|
45
|
+
// The parser keeps declarations and nested rules apart; the source offsets put them
|
|
46
|
+
// back in the order they were written, which is the order they cascade in.
|
|
47
|
+
const children = [...((_b = r.declarations) !== null && _b !== void 0 ? _b : []), ...((_c = r.children) !== null && _c !== void 0 ? _c : [])];
|
|
48
|
+
children.sort((a, b) => offsetOf(a) - offsetOf(b));
|
|
49
|
+
return rule(((_d = r.rawSelector) !== null && _d !== void 0 ? _d : '').trim(), convertAll(children, from), locOf(r, from));
|
|
50
|
+
}
|
|
51
|
+
case 'keyframe': {
|
|
52
|
+
const k = node;
|
|
53
|
+
return rule(k.selector, convertAll(k.declarations, from), locOf(k, from));
|
|
54
|
+
}
|
|
55
|
+
case 'atrule': {
|
|
56
|
+
const a = node;
|
|
57
|
+
const params = ((_e = a.preludeText) !== null && _e !== void 0 ? _e : '').trim();
|
|
58
|
+
// A statement (`@import`, `@apply` before expansion has a block of its own only when
|
|
59
|
+
// nested): no block means no braces in the output either.
|
|
60
|
+
if (!a.block)
|
|
61
|
+
return a.name === 'apply' ? atRule('apply', params, [], locOf(a, from)) : raw(`@${a.name}${params ? ' ' + params : ''};`, locOf(a, from));
|
|
62
|
+
return atRule(a.name, params, convertAll(a.block.children, from), locOf(a, from));
|
|
63
|
+
}
|
|
64
|
+
default:
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// ─── @apply ──────────────────────────────────────────────────────────────────
|
|
69
|
+
/**
|
|
70
|
+
* Replaces each `@apply a b c` with what those utilities produce: flat declarations in place,
|
|
71
|
+
* and a nested rule (`&` standing for the applying selector) for a utility that needs a
|
|
72
|
+
* selector of its own (`hover:`, `group-hover:`, `space-x-*`, `md:`). Unknown classes are
|
|
73
|
+
* skipped. `applied` collects the utilities used.
|
|
74
|
+
*/
|
|
75
|
+
export function applyUtilities(nodes, reg, applied = new Set()) {
|
|
76
|
+
const out = [];
|
|
77
|
+
for (const node of nodes) {
|
|
78
|
+
if (node.kind === 'at-rule' && node.name === 'apply') {
|
|
79
|
+
// What it expands to was written on the @apply line, as far as a source map can tell.
|
|
80
|
+
out.push(...expandOne(node.params, reg, applied).map((n) => withLoc(n, node.loc)));
|
|
81
|
+
}
|
|
82
|
+
else if (node.kind === 'rule' || node.kind === 'at-rule') {
|
|
83
|
+
out.push(Object.assign(Object.assign({}, node), { nodes: applyUtilities(node.nodes, reg, applied) }));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
out.push(node);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
function expandOne(params, reg, applied) {
|
|
92
|
+
let list = params.trim();
|
|
93
|
+
// A trailing `!important` marks every inlined declaration (Tailwind semantics).
|
|
94
|
+
let important = false;
|
|
95
|
+
const bang = list.match(/!important\s*$/);
|
|
96
|
+
if (bang) {
|
|
97
|
+
important = true;
|
|
98
|
+
list = list.slice(0, bang.index).trim();
|
|
99
|
+
}
|
|
100
|
+
const decls = [];
|
|
101
|
+
const nested = [];
|
|
102
|
+
for (const token of list.split(/\s+/)) {
|
|
103
|
+
if (!token)
|
|
104
|
+
continue;
|
|
105
|
+
const atom = parseAtom(token, reg);
|
|
106
|
+
if (!atom)
|
|
107
|
+
continue;
|
|
108
|
+
const compiled = compileAtom(atom, reg);
|
|
109
|
+
if (!compiled || compiled.length === 0)
|
|
110
|
+
continue;
|
|
111
|
+
applied.add(token);
|
|
112
|
+
if (important)
|
|
113
|
+
markImportant(compiled);
|
|
114
|
+
const own = '.' + escapeClass(atom.raw);
|
|
115
|
+
// A plain utility, one rule on its own class with only declarations, inlines.
|
|
116
|
+
const only = compiled[0];
|
|
117
|
+
if (compiled.length === 1 && only.kind === 'rule' && only.selector === own && only.nodes.every((n) => n.kind === 'declaration')) {
|
|
118
|
+
decls.push(...only.nodes.map((n) => (Object.assign({}, n))));
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
// Anything else keeps its structure, with the utility's class replaced by `&`.
|
|
122
|
+
nested.push(...compiled.map((n) => toNesting(n, own)));
|
|
123
|
+
}
|
|
124
|
+
// Flat declarations first, then the nested rules: the order the author's line implies.
|
|
125
|
+
return [...decls, ...nested];
|
|
126
|
+
}
|
|
127
|
+
function withLoc(node, loc) {
|
|
128
|
+
var _a;
|
|
129
|
+
if (!loc)
|
|
130
|
+
return node;
|
|
131
|
+
if (node.kind === 'rule' || node.kind === 'at-rule')
|
|
132
|
+
return Object.assign(Object.assign({}, node), { loc: (_a = node.loc) !== null && _a !== void 0 ? _a : loc, nodes: node.nodes.map((n) => withLoc(n, loc)) });
|
|
133
|
+
return node.loc ? node : Object.assign(Object.assign({}, node), { loc });
|
|
134
|
+
}
|
|
135
|
+
function toNesting(node, own) {
|
|
136
|
+
if (node.kind === 'rule')
|
|
137
|
+
return Object.assign(Object.assign({}, node), { selector: node.selector.split(own).join('&'), nodes: node.nodes.map((n) => toNesting(n, own)) });
|
|
138
|
+
if (node.kind === 'at-rule')
|
|
139
|
+
return Object.assign(Object.assign({}, node), { nodes: node.nodes.map((n) => toNesting(n, own)) });
|
|
140
|
+
return node;
|
|
141
|
+
}
|
|
142
|
+
function markImportant(nodes) {
|
|
143
|
+
for (const n of nodes) {
|
|
144
|
+
if (n.kind === 'declaration')
|
|
145
|
+
n.important = true;
|
|
146
|
+
else if (n.kind === 'rule' || n.kind === 'at-rule')
|
|
147
|
+
markImportant(n.nodes);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// ─── Nesting → plain selectors ───────────────────────────────────────────────
|
|
151
|
+
// At-rules whose body is more stylesheet: nesting is resolved through them. Everything else
|
|
152
|
+
// (`@keyframes`, `@font-face`, `@property`, …) is left exactly as written.
|
|
153
|
+
const GROUPING = new Set(['media', 'supports', 'container', 'layer', 'document', 'scope', 'starting-style']);
|
|
154
|
+
/** Splits a selector list on its top-level commas (not those inside `:is(…)`, `[…]` or quotes). */
|
|
155
|
+
export function splitSelectorList(selector) {
|
|
156
|
+
const parts = [];
|
|
157
|
+
let depth = 0;
|
|
158
|
+
let quote = '';
|
|
159
|
+
let start = 0;
|
|
160
|
+
for (let i = 0; i < selector.length; i++) {
|
|
161
|
+
const c = selector[i];
|
|
162
|
+
if (quote) {
|
|
163
|
+
if (c === '\\')
|
|
164
|
+
i++;
|
|
165
|
+
else if (c === quote)
|
|
166
|
+
quote = '';
|
|
167
|
+
}
|
|
168
|
+
else if (c === '"' || c === "'")
|
|
169
|
+
quote = c;
|
|
170
|
+
else if (c === '\\')
|
|
171
|
+
i++;
|
|
172
|
+
else if (c === '(' || c === '[')
|
|
173
|
+
depth++;
|
|
174
|
+
else if (c === ')' || c === ']')
|
|
175
|
+
depth--;
|
|
176
|
+
else if (c === ',' && depth === 0) {
|
|
177
|
+
parts.push(selector.slice(start, i).trim());
|
|
178
|
+
start = i + 1;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
parts.push(selector.slice(start).trim());
|
|
182
|
+
return parts.filter(Boolean);
|
|
183
|
+
}
|
|
184
|
+
/** The selector a nested rule stands for, given its parent's: `&` replaced, or a descendant. */
|
|
185
|
+
export function resolveNested(child, parent) {
|
|
186
|
+
const parents = splitSelectorList(parent);
|
|
187
|
+
const out = [];
|
|
188
|
+
for (const c of splitSelectorList(child)) {
|
|
189
|
+
for (const p of parents)
|
|
190
|
+
out.push(c.includes('&') ? c.split('&').join(p) : `${p} ${c}`);
|
|
191
|
+
}
|
|
192
|
+
return out.join(', ');
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Resolves CSS nesting into plain rules, keeping the cascade: a rule's declarations stay
|
|
196
|
+
* together until a nested rule interrupts them, and the ones after it follow it. Grouping
|
|
197
|
+
* at-rules nested in a rule wrap a rule on the parent's selector.
|
|
198
|
+
*/
|
|
199
|
+
export function flattenNesting(nodes, parent = null) {
|
|
200
|
+
const out = [];
|
|
201
|
+
for (const node of nodes) {
|
|
202
|
+
if (node.kind === 'rule') {
|
|
203
|
+
const selector = parent === null ? node.selector : resolveNested(node.selector, parent);
|
|
204
|
+
out.push(...flattenRule(selector, node.nodes, node.loc));
|
|
205
|
+
}
|
|
206
|
+
else if (node.kind === 'at-rule' && GROUPING.has(node.name)) {
|
|
207
|
+
out.push(Object.assign(Object.assign({}, node), { nodes: parent === null ? flattenNesting(node.nodes) : flattenRule(parent, node.nodes, node.loc) }));
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
out.push(node);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
215
|
+
function flattenRule(selector, children, loc) {
|
|
216
|
+
const out = [];
|
|
217
|
+
let pending = [];
|
|
218
|
+
const flush = () => {
|
|
219
|
+
if (pending.length)
|
|
220
|
+
out.push(rule(selector, pending, loc));
|
|
221
|
+
pending = [];
|
|
222
|
+
};
|
|
223
|
+
for (const child of children) {
|
|
224
|
+
if (child.kind === 'declaration' || child.kind === 'raw') {
|
|
225
|
+
pending.push(child);
|
|
226
|
+
}
|
|
227
|
+
else if (child.kind === 'rule') {
|
|
228
|
+
flush();
|
|
229
|
+
out.push(...flattenRule(resolveNested(child.selector, selector), child.nodes, child.loc));
|
|
230
|
+
}
|
|
231
|
+
else if (GROUPING.has(child.name)) {
|
|
232
|
+
flush();
|
|
233
|
+
out.push(Object.assign(Object.assign({}, child), { nodes: flattenRule(selector, child.nodes, child.loc) }));
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
flush();
|
|
237
|
+
out.push(child);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
flush();
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
export function createCssContext(options = {}) {
|
|
244
|
+
var _a;
|
|
245
|
+
const registry = (_a = options.registry) !== null && _a !== void 0 ? _a : createRegistry();
|
|
246
|
+
if (options.theme) {
|
|
247
|
+
loadTheme(options.theme, registry.theme);
|
|
248
|
+
registerBreakpointVariants(registry);
|
|
249
|
+
loadDirectives(options.theme, registry);
|
|
250
|
+
}
|
|
251
|
+
return { registry, usedTokens: new Set() };
|
|
252
|
+
}
|
|
253
|
+
// Directives that define the context; component CSS does not get to change it.
|
|
254
|
+
const CONTEXT_DIRECTIVES = new Set(['theme', 'utility', 'custom-variant', 'source', 'fluixi']);
|
|
255
|
+
/**
|
|
256
|
+
* Processes one stylesheet in a shared context, exactly as the project's own CSS would be:
|
|
257
|
+
* `@apply` expanded with the context's utilities, theme values resolved, nesting flattened.
|
|
258
|
+
* It never emits the utility layer or the theme tokens; the tokens it refers to are recorded
|
|
259
|
+
* in `ctx.usedTokens` for the global sheet to keep.
|
|
260
|
+
*/
|
|
261
|
+
export function processCss(input, ctx, options = {}) {
|
|
262
|
+
const parsed = typeof input === 'string' ? parseStyle(input, options.from) : input;
|
|
263
|
+
const ignored = [];
|
|
264
|
+
const references = [];
|
|
265
|
+
const kept = parsed.filter((n) => {
|
|
266
|
+
const reference = n.kind === 'raw' ? n.text.match(/^@reference\s+(["'])(.+)\1\s*;$/) : null;
|
|
267
|
+
if (reference) {
|
|
268
|
+
references.push(reference[2]);
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
if (n.kind === 'at-rule' && CONTEXT_DIRECTIVES.has(n.name)) {
|
|
272
|
+
ignored.push(n.name);
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
return true;
|
|
276
|
+
});
|
|
277
|
+
const applied = new Set();
|
|
278
|
+
let ast = applyUtilities(kept, ctx.registry, applied);
|
|
279
|
+
if (options.flatten !== false)
|
|
280
|
+
ast = flattenNesting(ast);
|
|
281
|
+
collectVarRefs(ast, ctx.usedTokens);
|
|
282
|
+
return { ast, css: stringify(ast, { minify: options.minify }), applied: [...applied], ignored, references };
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=style.js.map
|