@fluixi-css/core 1.0.0-next.2 → 1.0.0-next.3

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Fluixi CSS engine — a fast, CSS-first utility engine (compile, transform, theming, source maps).",
4
4
  "license": "MIT",
5
5
  "author": "fluixi",
6
- "version": "1.0.0-next.2",
6
+ "version": "1.0.0-next.3",
7
7
  "private": false,
8
8
  "sideEffects": false,
9
9
  "repository": {
@@ -158,9 +158,16 @@ export function parseAtom(raw, ctx = {}) {
158
158
  const colon = arbProp.indexOf(':');
159
159
  if (colon <= 0)
160
160
  return null;
161
+ // The head must be a real CSS property or custom property. Scanners pull
162
+ // `[...]` runs out of JS/TS too (array/object literals like
163
+ // `[...prev, { value } as T]`); rejecting a non-property head keeps those
164
+ // from emitting broken rules that later crash the CSS parser.
165
+ const property = arbProp.slice(0, colon);
166
+ if (!/^-{0,2}[a-zA-Z][a-zA-Z0-9-]*$/.test(property))
167
+ return null;
161
168
  return {
162
169
  kind: 'arbitrary-property',
163
- property: arbProp.slice(0, colon),
170
+ property,
164
171
  value: decodeUnderscores(arbProp.slice(colon + 1)),
165
172
  modifier,
166
173
  important,
@@ -1 +1 @@
1
- {"version":3,"file":"atom.js","sourceRoot":"","sources":["../../../src/engine/atom.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,6EAA6E;AAC7E,uEAAuE;AACvE,kFAAkF;AAClF,gFAAgF;AAChF,4CAA4C;AAqD5C,kFAAkF;AAClF,sBAAsB;AACtB,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,GAAW;IACxD,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GA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AK,IAAI,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACtD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;AACzE,CAAC","sourcesContent":["// Parses one raw utility (e.g. `md:hover:-bg-red-500/50!` or `[&_p]:text-[13px]`)\n// into a structured Atom in a single pass. Splitting is bracket/paren aware,\n// so `:` `/` `-` inside arbitrary values are left alone — no regex, no\n// backtracking. Which part is the root and which is the value can't be known from\n// the string alone (`text-red-500` vs `grid-cols-3`), so that split is resolved\n// against the registry through AtomContext.\n\nexport type AtomModifier =\n | { kind: 'named'; value: string }\n | { kind: 'arbitrary'; value: string };\n\nexport type AtomValue =\n | { kind: 'named'; value: string; fraction: string | null }\n | { kind: 'arbitrary'; value: string; dataType: string | null };\n\nexport type Variant =\n | { kind: 'static'; root: string }\n | {\n kind: 'functional';\n root: string;\n value: { kind: 'named'; value: string } | { kind: 'arbitrary'; value: string; dataType: string | null } | null;\n modifier: AtomModifier | null;\n }\n | { kind: 'arbitrary'; selector: string; relative: boolean };\n\nexport type Atom =\n | {\n kind: 'arbitrary-property';\n property: string;\n value: string;\n modifier: AtomModifier | null;\n important: boolean;\n variants: Variant[];\n raw: string;\n }\n | { kind: 'static'; root: string; important: boolean; variants: Variant[]; raw: string }\n | {\n kind: 'functional';\n root: string;\n value: AtomValue | null;\n modifier: AtomModifier | null;\n important: boolean;\n negative: boolean;\n variants: Variant[];\n raw: string;\n };\n\nexport interface AtomContext {\n /** A bare utility with no value: `flex`, `block`, `italic`. */\n isRule?(root: string): boolean;\n /** A utility root that takes a value: `bg`, `text`, `p`, `grid-cols`. */\n isDynamicRule?(root: string): boolean;\n /** A variant with no value: `hover`, `md`, `dark`, `first`. */\n isVariant?(root: string): boolean;\n /** A variant root that takes a value: `group`, `aria`, `data`, `supports`. */\n isDynamicVariant?(root: string): boolean;\n}\n\n// Split on `sep` at depth 0 only; `[...]` and `(...)` are opaque, and `\\` escapes\n// the next character.\nexport function splitAtTopLevel(input: string, sep: string): string[] {\n const out: string[] = [];\n let depthBracket = 0;\n let depthParen = 0;\n let start = 0;\n for (let i = 0; i < input.length; i++) {\n const c = input[i];\n if (c === '\\\\') {\n i++; // skip the escaped char\n continue;\n }\n if (c === '[') depthBracket++;\n else if (c === ']') depthBracket = Math.max(0, depthBracket - 1);\n else if (c === '(') depthParen++;\n else if (c === ')') depthParen = Math.max(0, depthParen - 1);\n else if (c === sep && depthBracket === 0 && depthParen === 0) {\n out.push(input.slice(start, i));\n start = i + 1;\n }\n }\n out.push(input.slice(start));\n return out;\n}\n\n// Content of a `[...]` or `(...)` wrapper, or null when `s` isn't wrapped.\nfunction unwrap(s: string, open: '[' | '('): string | null {\n const close = open === '[' ? ']' : ')';\n return s.length >= 2 && s[0] === open && s[s.length - 1] === close ? s.slice(1, -1) : null;\n}\n\nfunction parseModifier(raw: string): AtomModifier | null {\n if (!raw) return null;\n const arb = unwrap(raw, '[');\n if (arb !== null) return { kind: 'arbitrary', value: arb };\n // `(--name)` is shorthand for the custom property it references.\n const paren = unwrap(raw, '(');\n if (paren !== null) return { kind: 'arbitrary', value: `var(${paren})` };\n return { kind: 'named', value: raw };\n}\n\nfunction splitModifier(base: string): { base: string; modifier: AtomModifier | null } {\n const parts = splitAtTopLevel(base, '/');\n if (parts.length === 1) return { base, modifier: null };\n const modifier = parseModifier(parts.slice(1).join('/'));\n return { base: parts[0], modifier };\n}\n\n// In arbitrary values `_` stands in for a space; `\\_` is a literal underscore.\nexport function decodeUnderscores(value: string): string {\n // `_` → space, `\\_` → literal `_`. But a URL may legitimately contain underscores,\n // so leave the inside of `url(...)` verbatim (the split keeps url() at odd indices).\n return value\n .split(/(url\\([^)]*\\))/g)\n .map((part, i) => (i % 2 === 1 ? part : part.replace(/\\\\_/g, '\\0').replace(/_/g, ' ').replace(/\\0/g, '_')))\n .join('');\n}\n\n// An arbitrary value may lead with a `type:` hint, e.g. `[length:12px]`.\nfunction parseArbitraryValue(body: string): { value: string; dataType: string | null } {\n const colon = body.indexOf(':');\n if (colon > 0) {\n const maybeType = body.slice(0, colon);\n if (/^[a-z-]+$/.test(maybeType)) {\n return { dataType: maybeType, value: decodeUnderscores(body.slice(colon + 1)) };\n }\n }\n return { dataType: null, value: decodeUnderscores(body) };\n}\n\n// The `(--name)` shorthand, optionally typed: `(length:--size)`. The custom\n// property name keeps its underscores.\nfunction parseParenValue(paren: string): { value: string; dataType: string | null } {\n const colon = paren.indexOf(':');\n if (colon > 0 && /^[a-z-]+$/.test(paren.slice(0, colon))) {\n return { dataType: paren.slice(0, colon), value: `var(${paren.slice(colon + 1)})` };\n }\n return { dataType: null, value: `var(${paren})` };\n}\n\nexport function parseVariant(raw: string, ctx: AtomContext = {}): Variant | null {\n if (!raw) return null;\n\n // `[&:hover]`, `[@media(...)]` — the selector is written out; a `&` means it's\n // relative to the element.\n const arb = unwrap(raw, '[');\n if (arb !== null) {\n return { kind: 'arbitrary', selector: arb, relative: arb.includes('&') };\n }\n\n const { base, modifier } = splitModifier(raw);\n\n // A variant carrying a value: `group-hover`, `data-[open]`, `supports-[display:grid]`.\n const dash = base.indexOf('-');\n if (dash > 0) {\n const root = base.slice(0, dash);\n const rest = base.slice(dash + 1);\n if (ctx.isDynamicVariant?.(root) || ctx.isDynamicVariant?.(root + '-')) {\n // A variant's `[...]` is a raw condition/attribute, not a typed value.\n const arbVal = unwrap(rest, '[');\n const value =\n arbVal !== null\n ? { kind: 'arbitrary' as const, value: arbVal, dataType: null }\n : { kind: 'named' as const, value: rest };\n return { kind: 'functional', root, value, modifier };\n }\n }\n\n return { kind: 'functional', root: base, value: null, modifier };\n}\n\n// Returns null for structurally invalid input (empty or dangling segments).\n// Without a context the root/value split falls back to the first dash, which is\n// enough to test the scanner on its own.\nexport function parseAtom(raw: string, ctx: AtomContext = {}): Atom | null {\n if (!raw) return null;\n\n const segments = splitAtTopLevel(raw, ':');\n const utility = segments.pop();\n if (utility === undefined || utility === '') return null;\n\n const variants: Variant[] = [];\n for (const seg of segments) {\n if (seg === '') return null; // dangling `::`\n const v = parseVariant(seg, ctx);\n if (!v) return null;\n variants.push(v);\n }\n // Written left-to-right (outermost first), stored innermost-first so consumers\n // can wrap the declaration outward.\n variants.reverse();\n\n // `!` marks important, accepted on either end.\n let body = utility;\n let important = false;\n if (body.endsWith('!')) {\n important = true;\n body = body.slice(0, -1);\n } else if (body.startsWith('!')) {\n important = true;\n body = body.slice(1);\n }\n if (body === '') return null;\n\n // Split off a trailing `/modifier` once, up front — it applies uniformly to\n // arbitrary-property, static, and functional atoms.\n const { base: core0, modifier } = splitModifier(body);\n\n // Arbitrary property: `[color:red]`, `[--my-var:0]` (optionally with modifier).\n const arbProp = unwrap(core0, '[');\n if (arbProp !== null && arbProp.includes(':')) {\n const colon = arbProp.indexOf(':');\n if (colon <= 0) return null;\n return {\n kind: 'arbitrary-property',\n property: arbProp.slice(0, colon),\n value: decodeUnderscores(arbProp.slice(colon + 1)),\n modifier,\n important,\n variants,\n raw,\n };\n }\n\n // Negative.\n let negative = false;\n let base = core0;\n if (base[0] === '-') {\n negative = true;\n base = base.slice(1);\n if (base === '') return null;\n }\n\n // Static utility (only when unambiguous: no negative/modifier).\n if (!negative && modifier === null && ctx.isRule?.(base)) {\n return { kind: 'static', root: base, important, variants, raw };\n }\n\n // Functional: split root ↔ value. Prefer the longest known functional root;\n // fall back to the first-dash split when no context is supplied.\n const { root, valueStr } = splitRootValue(base, ctx);\n if (root === '') return null;\n\n let value: AtomValue | null = null;\n if (valueStr !== null && valueStr !== '') {\n const arbVal = unwrap(valueStr, '[');\n if (arbVal !== null) {\n value = { kind: 'arbitrary', ...parseArbitraryValue(arbVal) };\n } else {\n const paren = unwrap(valueStr, '(');\n value =\n paren !== null\n ? { kind: 'arbitrary', ...parseParenValue(paren) }\n : { kind: 'named', value: valueStr, fraction: null };\n }\n } else if (ctx.isRule?.(base)) {\n // A bare root that is registered static (reached here due to a modifier).\n return { kind: 'static', root: base, important, variants, raw };\n }\n\n return { kind: 'functional', root, value, modifier, important, negative, variants, raw };\n}\n\n// Splits `bg-red-500` into a root and value. The longest registered root wins\n// (`grid-cols-3` → `grid-cols` + `3`); with no context, split at the first dash.\nfunction splitRootValue(base: string, ctx: AtomContext): { root: string; valueStr: string | null } {\n if (ctx.isDynamicRule) {\n // The whole class is itself the longest possible root (`rounded-t`, `border-x`);\n // prefer it before splitting off a shorter registered prefix (`rounded` + `t`).\n if (ctx.isDynamicRule(base)) return { root: base, valueStr: null };\n const dashes: number[] = [];\n for (let i = 0; i < base.length; i++) if (base[i] === '-') dashes.push(i);\n for (let d = dashes.length - 1; d >= 0; d--) {\n const idx = dashes[d];\n const root = base.slice(0, idx);\n if (ctx.isDynamicRule(root)) return { root, valueStr: base.slice(idx + 1) };\n }\n }\n const first = base.indexOf('-');\n if (first <= 0) return { root: base, valueStr: null };\n return { root: base.slice(0, first), valueStr: base.slice(first + 1) };\n}\n"]}
1
+ {"version":3,"file":"atom.js","sourceRoot":"","sources":["../../../src/engine/atom.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,6EAA6E;AAC7E,uEAAuE;AACvE,kFAAkF;AAClF,gFAAgF;AAChF,4CAA4C;AAqD5C,kFAAkF;AAClF,sBAAsB;AACtB,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,GAAW;IACxD,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAA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,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACtD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;AACzE,CAAC","sourcesContent":["// Parses one raw utility (e.g. `md:hover:-bg-red-500/50!` or `[&_p]:text-[13px]`)\n// into a structured Atom in a single pass. Splitting is bracket/paren aware,\n// so `:` `/` `-` inside arbitrary values are left alone — no regex, no\n// backtracking. Which part is the root and which is the value can't be known from\n// the string alone (`text-red-500` vs `grid-cols-3`), so that split is resolved\n// against the registry through AtomContext.\n\nexport type AtomModifier =\n | { kind: 'named'; value: string }\n | { kind: 'arbitrary'; value: string };\n\nexport type AtomValue =\n | { kind: 'named'; value: string; fraction: string | null }\n | { kind: 'arbitrary'; value: string; dataType: string | null };\n\nexport type Variant =\n | { kind: 'static'; root: string }\n | {\n kind: 'functional';\n root: string;\n value: { kind: 'named'; value: string } | { kind: 'arbitrary'; value: string; dataType: string | null } | null;\n modifier: AtomModifier | null;\n }\n | { kind: 'arbitrary'; selector: string; relative: boolean };\n\nexport type Atom =\n | {\n kind: 'arbitrary-property';\n property: string;\n value: string;\n modifier: AtomModifier | null;\n important: boolean;\n variants: Variant[];\n raw: string;\n }\n | { kind: 'static'; root: string; important: boolean; variants: Variant[]; raw: string }\n | {\n kind: 'functional';\n root: string;\n value: AtomValue | null;\n modifier: AtomModifier | null;\n important: boolean;\n negative: boolean;\n variants: Variant[];\n raw: string;\n };\n\nexport interface AtomContext {\n /** A bare utility with no value: `flex`, `block`, `italic`. */\n isRule?(root: string): boolean;\n /** A utility root that takes a value: `bg`, `text`, `p`, `grid-cols`. */\n isDynamicRule?(root: string): boolean;\n /** A variant with no value: `hover`, `md`, `dark`, `first`. */\n isVariant?(root: string): boolean;\n /** A variant root that takes a value: `group`, `aria`, `data`, `supports`. */\n isDynamicVariant?(root: string): boolean;\n}\n\n// Split on `sep` at depth 0 only; `[...]` and `(...)` are opaque, and `\\` escapes\n// the next character.\nexport function splitAtTopLevel(input: string, sep: string): string[] {\n const out: string[] = [];\n let depthBracket = 0;\n let depthParen = 0;\n let start = 0;\n for (let i = 0; i < input.length; i++) {\n const c = input[i];\n if (c === '\\\\') {\n i++; // skip the escaped char\n continue;\n }\n if (c === '[') depthBracket++;\n else if (c === ']') depthBracket = Math.max(0, depthBracket - 1);\n else if (c === '(') depthParen++;\n else if (c === ')') depthParen = Math.max(0, depthParen - 1);\n else if (c === sep && depthBracket === 0 && depthParen === 0) {\n out.push(input.slice(start, i));\n start = i + 1;\n }\n }\n out.push(input.slice(start));\n return out;\n}\n\n// Content of a `[...]` or `(...)` wrapper, or null when `s` isn't wrapped.\nfunction unwrap(s: string, open: '[' | '('): string | null {\n const close = open === '[' ? ']' : ')';\n return s.length >= 2 && s[0] === open && s[s.length - 1] === close ? s.slice(1, -1) : null;\n}\n\nfunction parseModifier(raw: string): AtomModifier | null {\n if (!raw) return null;\n const arb = unwrap(raw, '[');\n if (arb !== null) return { kind: 'arbitrary', value: arb };\n // `(--name)` is shorthand for the custom property it references.\n const paren = unwrap(raw, '(');\n if (paren !== null) return { kind: 'arbitrary', value: `var(${paren})` };\n return { kind: 'named', value: raw };\n}\n\nfunction splitModifier(base: string): { base: string; modifier: AtomModifier | null } {\n const parts = splitAtTopLevel(base, '/');\n if (parts.length === 1) return { base, modifier: null };\n const modifier = parseModifier(parts.slice(1).join('/'));\n return { base: parts[0], modifier };\n}\n\n// In arbitrary values `_` stands in for a space; `\\_` is a literal underscore.\nexport function decodeUnderscores(value: string): string {\n // `_` → space, `\\_` → literal `_`. But a URL may legitimately contain underscores,\n // so leave the inside of `url(...)` verbatim (the split keeps url() at odd indices).\n return value\n .split(/(url\\([^)]*\\))/g)\n .map((part, i) => (i % 2 === 1 ? part : part.replace(/\\\\_/g, '\\0').replace(/_/g, ' ').replace(/\\0/g, '_')))\n .join('');\n}\n\n// An arbitrary value may lead with a `type:` hint, e.g. `[length:12px]`.\nfunction parseArbitraryValue(body: string): { value: string; dataType: string | null } {\n const colon = body.indexOf(':');\n if (colon > 0) {\n const maybeType = body.slice(0, colon);\n if (/^[a-z-]+$/.test(maybeType)) {\n return { dataType: maybeType, value: decodeUnderscores(body.slice(colon + 1)) };\n }\n }\n return { dataType: null, value: decodeUnderscores(body) };\n}\n\n// The `(--name)` shorthand, optionally typed: `(length:--size)`. The custom\n// property name keeps its underscores.\nfunction parseParenValue(paren: string): { value: string; dataType: string | null } {\n const colon = paren.indexOf(':');\n if (colon > 0 && /^[a-z-]+$/.test(paren.slice(0, colon))) {\n return { dataType: paren.slice(0, colon), value: `var(${paren.slice(colon + 1)})` };\n }\n return { dataType: null, value: `var(${paren})` };\n}\n\nexport function parseVariant(raw: string, ctx: AtomContext = {}): Variant | null {\n if (!raw) return null;\n\n // `[&:hover]`, `[@media(...)]` — the selector is written out; a `&` means it's\n // relative to the element.\n const arb = unwrap(raw, '[');\n if (arb !== null) {\n return { kind: 'arbitrary', selector: arb, relative: arb.includes('&') };\n }\n\n const { base, modifier } = splitModifier(raw);\n\n // A variant carrying a value: `group-hover`, `data-[open]`, `supports-[display:grid]`.\n const dash = base.indexOf('-');\n if (dash > 0) {\n const root = base.slice(0, dash);\n const rest = base.slice(dash + 1);\n if (ctx.isDynamicVariant?.(root) || ctx.isDynamicVariant?.(root + '-')) {\n // A variant's `[...]` is a raw condition/attribute, not a typed value.\n const arbVal = unwrap(rest, '[');\n const value =\n arbVal !== null\n ? { kind: 'arbitrary' as const, value: arbVal, dataType: null }\n : { kind: 'named' as const, value: rest };\n return { kind: 'functional', root, value, modifier };\n }\n }\n\n return { kind: 'functional', root: base, value: null, modifier };\n}\n\n// Returns null for structurally invalid input (empty or dangling segments).\n// Without a context the root/value split falls back to the first dash, which is\n// enough to test the scanner on its own.\nexport function parseAtom(raw: string, ctx: AtomContext = {}): Atom | null {\n if (!raw) return null;\n\n const segments = splitAtTopLevel(raw, ':');\n const utility = segments.pop();\n if (utility === undefined || utility === '') return null;\n\n const variants: Variant[] = [];\n for (const seg of segments) {\n if (seg === '') return null; // dangling `::`\n const v = parseVariant(seg, ctx);\n if (!v) return null;\n variants.push(v);\n }\n // Written left-to-right (outermost first), stored innermost-first so consumers\n // can wrap the declaration outward.\n variants.reverse();\n\n // `!` marks important, accepted on either end.\n let body = utility;\n let important = false;\n if (body.endsWith('!')) {\n important = true;\n body = body.slice(0, -1);\n } else if (body.startsWith('!')) {\n important = true;\n body = body.slice(1);\n }\n if (body === '') return null;\n\n // Split off a trailing `/modifier` once, up front — it applies uniformly to\n // arbitrary-property, static, and functional atoms.\n const { base: core0, modifier } = splitModifier(body);\n\n // Arbitrary property: `[color:red]`, `[--my-var:0]` (optionally with modifier).\n const arbProp = unwrap(core0, '[');\n if (arbProp !== null && arbProp.includes(':')) {\n const colon = arbProp.indexOf(':');\n if (colon <= 0) return null;\n // The head must be a real CSS property or custom property. Scanners pull\n // `[...]` runs out of JS/TS too (array/object literals like\n // `[...prev, { value } as T]`); rejecting a non-property head keeps those\n // from emitting broken rules that later crash the CSS parser.\n const property = arbProp.slice(0, colon);\n if (!/^-{0,2}[a-zA-Z][a-zA-Z0-9-]*$/.test(property)) return null;\n return {\n kind: 'arbitrary-property',\n property,\n value: decodeUnderscores(arbProp.slice(colon + 1)),\n modifier,\n important,\n variants,\n raw,\n };\n }\n\n // Negative.\n let negative = false;\n let base = core0;\n if (base[0] === '-') {\n negative = true;\n base = base.slice(1);\n if (base === '') return null;\n }\n\n // Static utility (only when unambiguous: no negative/modifier).\n if (!negative && modifier === null && ctx.isRule?.(base)) {\n return { kind: 'static', root: base, important, variants, raw };\n }\n\n // Functional: split root ↔ value. Prefer the longest known functional root;\n // fall back to the first-dash split when no context is supplied.\n const { root, valueStr } = splitRootValue(base, ctx);\n if (root === '') return null;\n\n let value: AtomValue | null = null;\n if (valueStr !== null && valueStr !== '') {\n const arbVal = unwrap(valueStr, '[');\n if (arbVal !== null) {\n value = { kind: 'arbitrary', ...parseArbitraryValue(arbVal) };\n } else {\n const paren = unwrap(valueStr, '(');\n value =\n paren !== null\n ? { kind: 'arbitrary', ...parseParenValue(paren) }\n : { kind: 'named', value: valueStr, fraction: null };\n }\n } else if (ctx.isRule?.(base)) {\n // A bare root that is registered static (reached here due to a modifier).\n return { kind: 'static', root: base, important, variants, raw };\n }\n\n return { kind: 'functional', root, value, modifier, important, negative, variants, raw };\n}\n\n// Splits `bg-red-500` into a root and value. The longest registered root wins\n// (`grid-cols-3` → `grid-cols` + `3`); with no context, split at the first dash.\nfunction splitRootValue(base: string, ctx: AtomContext): { root: string; valueStr: string | null } {\n if (ctx.isDynamicRule) {\n // The whole class is itself the longest possible root (`rounded-t`, `border-x`);\n // prefer it before splitting off a shorter registered prefix (`rounded` + `t`).\n if (ctx.isDynamicRule(base)) return { root: base, valueStr: null };\n const dashes: number[] = [];\n for (let i = 0; i < base.length; i++) if (base[i] === '-') dashes.push(i);\n for (let d = dashes.length - 1; d >= 0; d--) {\n const idx = dashes[d];\n const root = base.slice(0, idx);\n if (ctx.isDynamicRule(root)) return { root, valueStr: base.slice(idx + 1) };\n }\n }\n const first = base.indexOf('-');\n if (first <= 0) return { root: base, valueStr: null };\n return { root: base.slice(0, first), valueStr: base.slice(first + 1) };\n}\n"]}
@@ -79,19 +79,19 @@ export function compile(input, options = {}) {
79
79
  }
80
80
  // The `--flx-ui-*` bridge, if requested — its `var()` refs must survive the
81
81
  // token tree-shake, so fold them into the used set.
82
- const uiBlock = options.emitUiTokens ? emitUiTheme(reg.theme) : null;
82
+ const uiBlocks = options.emitUiTokens ? emitUiTheme(reg.theme) : null;
83
83
  // Emit only the tokens the compiled rules (and any UI bridge) actually reference.
84
84
  const nodes = [];
85
85
  if (options.emitTokens !== false) {
86
86
  const used = collectVarRefs(rules);
87
- if (uiBlock)
88
- collectVarRefs([uiBlock], used);
87
+ if (uiBlocks)
88
+ collectVarRefs(uiBlocks, used);
89
89
  const tokens = emitTheme(reg.theme, ':root', used);
90
90
  if (tokens.nodes.length)
91
91
  nodes.push(tokens);
92
92
  }
93
- if (uiBlock && uiBlock.nodes.length)
94
- nodes.push(uiBlock);
93
+ if (uiBlocks)
94
+ nodes.push(...uiBlocks.filter((b) => b.nodes.length));
95
95
  nodes.push(...rules);
96
96
  return { css: stringify(nodes, { minify: options.minify }), classes: [...classes], sources, registry: reg };
97
97
  }
@@ -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,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,e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,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAErE,kFAAkF;IAClF,MAAM,KAAK,GAAc,EAAE,CAAC;IAC5B,IAAI,OAAO,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,OAAO;YAAE,cAAc,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,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,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"]}
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,EAAyB,MAAM,OAAO,CAAC;AACv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* 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 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 if (uiBlocks) nodes.push(...uiBlocks.filter((b) => b.nodes.length));\n nodes.push(...rules);\n\n return { css: stringify(nodes, { minify: options.minify }), classes: [...classes], sources, registry: reg };\n}\n"]}
@@ -51,28 +51,19 @@ export function transform(input, options = {}) {
51
51
  if (compiled)
52
52
  rules.push(...compiled);
53
53
  }
54
- const uiBlock = options.emitUiTokens ? emitUiTheme(reg.theme) : null;
55
- const generated = [];
56
- if (options.emitTokens !== false) {
57
- const used = collectVarRefs(rules);
58
- if (uiBlock)
59
- collectVarRefs([uiBlock], used);
60
- const tokens = emitTheme(reg.theme, ':root', used);
61
- if (tokens.nodes.length)
62
- generated.push(tokens);
63
- }
64
- if (uiBlock && uiBlock.nodes.length)
65
- generated.push(uiBlock);
66
- generated.push(...rules);
54
+ const uiBlocks = options.emitUiTokens ? emitUiTheme(reg.theme) : null;
55
+ // Pass the author CSS through first (expanding `@apply`), remembering where the
56
+ // `@fluixi` marker sits so the generated block splices in at that point. Building
57
+ // it up front lets the token tree-shake also see the author's own `var()` refs —
58
+ // a hand-written or `@apply`-injected `var(--color-x)` must keep `--color-x`
59
+ // alive, else the token is stripped and the reference resolves to nothing.
67
60
  const from = (_e = options.from) !== null && _e !== void 0 ? _e : '<input>';
68
- const nodes = [];
69
- let injected = false;
61
+ const authorNodes = [];
62
+ let markerAt = -1;
70
63
  for (const node of parseCss(input).children) {
71
64
  if (node.type === 'atrule' && node.name === MARKER) {
72
- if (!injected) {
73
- nodes.push(...generated);
74
- injected = true;
75
- }
65
+ if (markerAt < 0)
66
+ markerAt = authorNodes.length;
76
67
  continue;
77
68
  }
78
69
  if (node.type === 'atrule' && node.name && CONSUMED.has(node.name))
@@ -81,11 +72,25 @@ export function transform(input, options = {}) {
81
72
  const end = (_g = node.loc) === null || _g === void 0 ? void 0 : _g.end;
82
73
  if (start && end && typeof start.offset === 'number' && typeof end.offset === 'number') {
83
74
  const text = expandApply(input.slice(start.offset, end.offset), reg);
84
- nodes.push(raw(text, { source: from, line: start.line, column: Math.max(0, start.column - 1) }));
75
+ authorNodes.push(raw(text, { source: from, line: start.line, column: Math.max(0, start.column - 1) }));
85
76
  }
86
77
  }
87
- if (!injected)
88
- nodes.push(...generated);
78
+ const generated = [];
79
+ if (options.emitTokens !== false) {
80
+ const used = collectVarRefs(rules);
81
+ if (uiBlocks)
82
+ collectVarRefs(uiBlocks, used);
83
+ collectVarRefs(authorNodes, used); // keep tokens the author CSS references by hand / via @apply
84
+ const tokens = emitTheme(reg.theme, ':root', used);
85
+ if (tokens.nodes.length)
86
+ generated.push(tokens);
87
+ }
88
+ if (uiBlocks)
89
+ generated.push(...uiBlocks.filter((b) => b.nodes.length));
90
+ generated.push(...rules);
91
+ const nodes = markerAt >= 0
92
+ ? [...authorNodes.slice(0, markerAt), ...generated, ...authorNodes.slice(markerAt)]
93
+ : [...authorNodes, ...generated];
89
94
  const resetFrom = (_h = options.resetFrom) !== null && _h !== void 0 ? _h : 'fluixi:reset.css';
90
95
  if (options.reset)
91
96
  nodes.unshift(raw(options.reset, { source: resetFrom, line: 1, column: 0 }));
@@ -1 +1 @@
1
- {"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/engine/transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAgB,GAAG,EAAE,SAAS,EAAE,gBAAgB,EAAE,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;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,uEAAuE;AACvE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC3E,4EAA4E;AAC5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AAE,OAAO,CAAC,MAAM;KACxB,CAAC;IACF,OAAO,GAAG;QACR,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE;QACpE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;AACpE,CAAC","sourcesContent":["import type { RawSourceMap } from 'source-map';\nimport { parseCss } from '../css-parser';\nimport { expandApply } from './apply';\nimport { type AstNode, raw, stringify, stringifyWithMap } from './ast';\nimport { parseAtom } from './atom';\nimport { compileAtom } from './compile';\nimport { createRegistry } from './defaults';\nimport { loadDirectives } from './directives';\nimport { Registry } from './registry';\nimport { scanAtoms } from './scanner';\nimport { parseSources, resolveSourceFiles, scanSourceFiles } from './source';\nimport { registerBreakpointVariants } from './variants';\nimport { collectVarRefs, emitTheme, loadTheme } from './theme-source';\nimport { emitUiTheme } from './ui-preset';\n\n// Directives consumed to build the registry — dropped from the output.\nconst CONSUMED = new Set(['theme', 'utility', 'custom-variant', 'source']);\n// The at-rule that marks where generated tokens + utilities are spliced in.\nconst MARKER = 'fluixi';\n\nexport interface TransformOptions {\n registry?: Registry;\n classes?: string[];\n sources?: string[];\n base?: string;\n /**\n * Shared base CSS whose `@theme` / `@utility` / `@custom-variant` are loaded\n * into the registry *before* the input's, so a per-route sheet inherits (and\n * can override) the global theme + custom utilities without redefining them.\n * Only the directives feed the registry — the base CSS itself isn't emitted.\n */\n theme?: string;\n /** Filename of the input CSS, recorded in the source map. */\n from?: string;\n emitTokens?: boolean;\n emitUiTokens?: boolean;\n /** Reset CSS to prepend at the top of the sheet (baseline, before everything). */\n reset?: string;\n /** Source name recorded for the reset in the map. Default `fluixi:reset.css`. */\n resetFrom?: string;\n /** Produce a source map keyed to the passed-through author CSS. */\n sourceMap?: boolean;\n minify?: boolean;\n}\n\nexport interface TransformStats {\n /** Wall-clock milliseconds for this transform. */\n ms: number;\n /** Class tokens scanned (given + `@source` + inline). */\n scanned: number;\n /** Utility rules generated. */\n utilities: number;\n /** Output CSS byte length. */\n bytes: number;\n /** Files scanned via `@source`. */\n sources: number;\n}\n\nexport interface TransformResult {\n css: string;\n map?: RawSourceMap;\n classes: string[];\n sources: string[];\n stats: TransformStats;\n registry: Registry;\n}\n\n// Processes a whole stylesheet: the author's CSS passes through untouched (and\n// mapped back to source), the `@theme`/`@utility`/`@custom-variant`/`@source`\n// directives are consumed, and an `@fluixi;` marker is replaced by the generated\n// token `:root` + utilities. With no marker the generated block is appended.\nexport function transform(input: string, options: TransformOptions = {}): TransformResult {\n const started = performance.now();\n const reg = options.registry ?? createRegistry();\n if (options.theme) loadTheme(options.theme, reg.theme);\n loadTheme(input, reg.theme); // the input's own @theme overrides the base\n registerBreakpointVariants(reg); // pick up any @theme breakpoint overrides\n if (options.theme) loadDirectives(options.theme, reg);\n loadDirectives(input, reg);\n\n const classes = new Set<string>(options.classes ?? []);\n for (const s of options.sources ?? []) for (const c of scanAtoms(s)) classes.add(c);\n const parsed = parseSources(input);\n for (const c of parsed.inline) classes.add(c);\n let sources: string[] = [];\n if (parsed.patterns.length) {\n sources = resolveSourceFiles(parsed, 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 const uiBlock = options.emitUiTokens ? emitUiTheme(reg.theme) : null;\n\n const generated: 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) generated.push(tokens);\n }\n if (uiBlock && uiBlock.nodes.length) generated.push(uiBlock);\n generated.push(...rules);\n\n const from = options.from ?? '<input>';\n const nodes: AstNode[] = [];\n let injected = false;\n for (const node of parseCss(input).children) {\n if (node.type === 'atrule' && node.name === MARKER) {\n if (!injected) {\n nodes.push(...generated);\n injected = true;\n }\n continue;\n }\n if (node.type === 'atrule' && node.name && CONSUMED.has(node.name)) continue;\n\n const start = node.loc?.start;\n const end = node.loc?.end;\n if (start && end && typeof start.offset === 'number' && typeof end.offset === 'number') {\n const text = expandApply(input.slice(start.offset, end.offset), reg);\n nodes.push(raw(text, { source: from, line: start.line, column: Math.max(0, start.column - 1) }));\n }\n }\n if (!injected) nodes.push(...generated);\n const resetFrom = options.resetFrom ?? 'fluixi:reset.css';\n if (options.reset) nodes.unshift(raw(options.reset, { source: resetFrom, line: 1, column: 0 }));\n\n let css: string;\n let map: RawSourceMap | undefined;\n if (options.sourceMap) {\n const out = stringifyWithMap(nodes, { minify: options.minify });\n css = out.css;\n out.map.setSourceContent(from, input);\n if (options.reset) out.map.setSourceContent(resetFrom, options.reset);\n const json = out.map.toJSON();\n json.file = from;\n map = json;\n } else {\n css = stringify(nodes, { minify: options.minify });\n }\n\n const stats: TransformStats = {\n ms: performance.now() - started,\n scanned: classes.size,\n utilities: rules.length,\n bytes: css.length,\n sources: sources.length,\n };\n return map\n ? { css, map, classes: [...classes], sources, stats, registry: reg }\n : { css, classes: [...classes], sources, stats, registry: reg };\n}\n"]}
1
+ {"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/engine/transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAgB,GAAG,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,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{ expandApply } from './apply';\nimport { type AstNode, raw, stringify, stringifyWithMap } from './ast';\nimport { parseAtom } from './atom';\nimport { compileAtom } from './compile';\nimport { createRegistry } from './defaults';\nimport { loadDirectives } from './directives';\nimport { Registry } from './registry';\nimport { scanAtoms } from './scanner';\nimport { parseSources, resolveSourceFiles, scanSourceFiles } from './source';\nimport { registerBreakpointVariants } from './variants';\nimport { collectVarRefs, emitTheme, loadTheme } from './theme-source';\nimport { emitUiTheme } from './ui-preset';\n\n// Directives consumed to build the registry — dropped from the output.\nconst CONSUMED = new Set(['theme', 'utility', 'custom-variant', 'source']);\n// The at-rule that marks where generated tokens + utilities are spliced in.\nconst MARKER = 'fluixi';\n\nexport interface TransformOptions {\n registry?: Registry;\n classes?: string[];\n sources?: string[];\n base?: string;\n /**\n * Shared base CSS whose `@theme` / `@utility` / `@custom-variant` are loaded\n * into the registry *before* the input's, so a per-route sheet inherits (and\n * can override) the global theme + custom utilities without redefining them.\n * Only the directives feed the registry — the base CSS itself isn't emitted.\n */\n theme?: string;\n /** Filename of the input CSS, recorded in the source map. */\n from?: string;\n emitTokens?: boolean;\n emitUiTokens?: boolean;\n /** Reset CSS to prepend at the top of the sheet (baseline, before everything). */\n reset?: string;\n /** Source name recorded for the reset in the map. Default `fluixi:reset.css`. */\n resetFrom?: string;\n /** Produce a source map keyed to the passed-through author CSS. */\n sourceMap?: boolean;\n minify?: boolean;\n}\n\nexport interface TransformStats {\n /** Wall-clock milliseconds for this transform. */\n ms: number;\n /** Class tokens scanned (given + `@source` + inline). */\n scanned: number;\n /** Utility rules generated. */\n utilities: number;\n /** Output CSS byte length. */\n bytes: number;\n /** Files scanned via `@source`. */\n sources: number;\n}\n\nexport interface TransformResult {\n css: string;\n map?: RawSourceMap;\n classes: string[];\n sources: string[];\n stats: TransformStats;\n registry: Registry;\n}\n\n// Processes a whole stylesheet: the author's CSS passes through untouched (and\n// mapped back to source), the `@theme`/`@utility`/`@custom-variant`/`@source`\n// directives are consumed, and an `@fluixi;` marker is replaced by the generated\n// token `:root` + utilities. With no marker the generated block is appended.\nexport function transform(input: string, options: TransformOptions = {}): TransformResult {\n const started = performance.now();\n const reg = options.registry ?? createRegistry();\n if (options.theme) loadTheme(options.theme, reg.theme);\n loadTheme(input, reg.theme); // the input's own @theme overrides the base\n registerBreakpointVariants(reg); // pick up any @theme breakpoint overrides\n if (options.theme) loadDirectives(options.theme, reg);\n loadDirectives(input, reg);\n\n const classes = new Set<string>(options.classes ?? []);\n for (const s of options.sources ?? []) for (const c of scanAtoms(s)) classes.add(c);\n const parsed = parseSources(input);\n for (const c of parsed.inline) classes.add(c);\n let sources: string[] = [];\n if (parsed.patterns.length) {\n sources = resolveSourceFiles(parsed, 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 const uiBlocks = options.emitUiTokens ? emitUiTheme(reg.theme) : null;\n\n // Pass the author CSS through first (expanding `@apply`), remembering where the\n // `@fluixi` marker sits so the generated block splices in at that point. Building\n // it up front lets the token tree-shake also see the author's own `var()` refs —\n // a hand-written or `@apply`-injected `var(--color-x)` must keep `--color-x`\n // alive, else the token is stripped and the reference resolves to nothing.\n const from = options.from ?? '<input>';\n const authorNodes: AstNode[] = [];\n let markerAt = -1;\n for (const node of parseCss(input).children) {\n if (node.type === 'atrule' && node.name === MARKER) {\n if (markerAt < 0) markerAt = authorNodes.length;\n continue;\n }\n if (node.type === 'atrule' && node.name && CONSUMED.has(node.name)) continue;\n\n const start = node.loc?.start;\n const end = node.loc?.end;\n if (start && end && typeof start.offset === 'number' && typeof end.offset === 'number') {\n const text = expandApply(input.slice(start.offset, end.offset), reg);\n authorNodes.push(raw(text, { source: from, line: start.line, column: Math.max(0, start.column - 1) }));\n }\n }\n\n const generated: AstNode[] = [];\n if (options.emitTokens !== false) {\n const used = collectVarRefs(rules);\n if (uiBlocks) collectVarRefs(uiBlocks, used);\n collectVarRefs(authorNodes, used); // keep tokens the author CSS references by hand / via @apply\n const tokens = emitTheme(reg.theme, ':root', used);\n if (tokens.nodes.length) generated.push(tokens);\n }\n if (uiBlocks) generated.push(...uiBlocks.filter((b) => b.nodes.length));\n generated.push(...rules);\n\n const nodes: AstNode[] =\n markerAt >= 0\n ? [...authorNodes.slice(0, markerAt), ...generated, ...authorNodes.slice(markerAt)]\n : [...authorNodes, ...generated];\n const resetFrom = options.resetFrom ?? 'fluixi:reset.css';\n if (options.reset) nodes.unshift(raw(options.reset, { source: resetFrom, line: 1, column: 0 }));\n\n let css: string;\n let map: RawSourceMap | undefined;\n if (options.sourceMap) {\n const out = stringifyWithMap(nodes, { minify: options.minify });\n css = out.css;\n out.map.setSourceContent(from, input);\n if (options.reset) out.map.setSourceContent(resetFrom, options.reset);\n const json = out.map.toJSON();\n json.file = from;\n map = json;\n } else {\n css = stringify(nodes, { minify: options.minify });\n }\n\n const stats: TransformStats = {\n ms: performance.now() - started,\n scanned: classes.size,\n utilities: rules.length,\n bytes: css.length,\n sources: sources.length,\n };\n return map\n ? { css, map, classes: [...classes], sources, stats, registry: reg }\n : { css, classes: [...classes], sources, stats, registry: reg };\n}\n"]}
@@ -1,4 +1,23 @@
1
1
  import { type Declaration, type StyleRule } from './ast';
2
2
  import { Theme } from './theme';
3
+ /** The primitive + scale bridges (non-colour and the raw scale refs). */
3
4
  export declare function uiTokenBridges(theme: Theme): Declaration[];
4
- export declare function emitUiTheme(theme: Theme, selector?: string): StyleRule;
5
+ /** The structural semantic layer — emitted only when the theme drives colour. */
6
+ export declare function uiSemanticLayer(theme: Theme): Declaration[];
7
+ export interface EmitUiOptions {
8
+ /** Root scope for the bridges + semantic layer. */
9
+ selector?: string;
10
+ /**
11
+ * Dark scope. The scale bridges + semantic layer are re-emitted here so the
12
+ * `var()` refs re-resolve against the theme's dark-scoped `--color-*` values.
13
+ * Emitted only when the theme drives colour. Pass `null` to skip.
14
+ */
15
+ darkSelector?: string | null;
16
+ }
17
+ /**
18
+ * The bridges as sibling top-level rules, ready to prepend to the compiled sheet:
19
+ * `:root` (primitives + scales + semantic layer) and, when the theme drives
20
+ * colour, a dark-scope re-emit of the colour half so its `var()` refs re-resolve
21
+ * against the theme's dark-scoped `--color-*` values.
22
+ */
23
+ export declare function emitUiTheme(theme: Theme, options?: EmitUiOptions): StyleRule[];
@@ -2,8 +2,18 @@ import { decl, rule } from './ast';
2
2
  // Bridges a fluixi-css theme to the `--flx-ui-*` custom properties the Fluixi UI
3
3
  // components read (`@fluixi-ui/tokens`). Each bridge emits `--flx-ui-x: var(--src)`
4
4
  // so a fluixi-css theme *drives* the UI — change the theme, the components follow —
5
- // without copying any values across. A bridge is emitted only when its source
6
- // token exists, so the UI's own defaults stand in for anything the theme omits.
5
+ // without copying any values across. A primitive bridge is emitted only when its
6
+ // source token exists, so the UI's own defaults stand in for anything the theme omits.
7
+ //
8
+ // Colour is the driven half: when the theme supplies the functional scales
9
+ // (`--color-accent-1..12` / `--color-gray-1..12`), this also emits the UI's whole
10
+ // *semantic* layer (`--flx-ui-color-primary`, …). That layer is purely structural —
11
+ // every var references a scale/alias var, never a concrete colour — so it carries no
12
+ // palette data across the package boundary; `@fluixi-ui/tokens` still owns the
13
+ // default values. The semantic layer is re-emitted in a dark scope because
14
+ // custom-property substitution freezes at the declaring element: a `:root`-only
15
+ // `--flx-ui-color-primary: var(--flx-ui-accent-9)` would inherit light's *resolved*
16
+ // colour into a dark subtree instead of re-resolving against the dark scale.
7
17
  // UI space scale ↔ the `--spacing` base (space-4 = 1rem = 0.25rem × 4).
8
18
  const SPACE_STEPS = [0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24];
9
19
  // UI font-size keys ↔ fluixi `--text-*` keys (the UI's `md` is fluixi's `base`).
@@ -20,6 +30,46 @@ const FONT_SIZE = [
20
30
  const RADIUS = ['sm', 'md', 'lg', 'xl'];
21
31
  const SHADOW = ['sm', 'md', 'lg', 'xl'];
22
32
  const BREAKPOINT = ['sm', 'md', 'lg', 'xl', '2xl'];
33
+ // The UI's semantic layer, mirrored from `@fluixi-ui/tokens` (`semanticColors`).
34
+ // Structural only — refs into the scales/aliases the bridge (or the UI's own
35
+ // defaults) provide. `color-primary-fg` and `color-overlay` are intentionally
36
+ // omitted: they're concrete kit defaults, not scale-derived, so the UI package
37
+ // keeps ownership of them.
38
+ const SEMANTIC = [
39
+ ['color-bg', 'gray-1'],
40
+ ['color-bg-subtle', 'gray-2'],
41
+ ['color-bg-muted', 'gray-3'],
42
+ ['color-fg', 'gray-12'],
43
+ ['color-fg-muted', 'gray-11'],
44
+ ['color-border', 'gray-6'],
45
+ ['color-border-strong', 'gray-7'],
46
+ ['color-focus-ring', 'accent-8'],
47
+ ['color-primary', 'accent-9'],
48
+ ['color-primary-hover', 'accent-10'],
49
+ ['color-primary-active', 'accent-11'],
50
+ ['color-primary-subtle', 'accent-3'],
51
+ ['color-danger', 'danger-solid'],
52
+ ['color-danger-fg', 'danger-fg'],
53
+ ['color-danger-subtle', 'danger-subtle'],
54
+ ['color-success', 'success-solid'],
55
+ ['color-success-fg', 'success-fg'],
56
+ ['color-success-subtle', 'success-subtle'],
57
+ ['color-warning', 'warning-solid'],
58
+ ['color-warning-fg', 'warning-fg'],
59
+ ['color-warning-subtle', 'warning-subtle'],
60
+ ];
61
+ // Optional status-colour bridges: a theme may drive the UI's danger/success/
62
+ // warning solids by supplying `--color-danger` / `--color-success` / `--color-warning`.
63
+ const STATUS = [
64
+ ['danger-solid', '--color-danger'],
65
+ ['success-solid', '--color-success'],
66
+ ['warning-solid', '--color-warning'],
67
+ ];
68
+ /** True once the theme supplies enough of the functional scales to drive colour. */
69
+ function hasColorScales(theme) {
70
+ return theme.has('--color-accent-9') || theme.has('--color-gray-1');
71
+ }
72
+ /** The primitive + scale bridges (non-colour and the raw scale refs). */
23
73
  export function uiTokenBridges(theme) {
24
74
  const out = [];
25
75
  const bridge = (flx, source) => {
@@ -39,18 +89,46 @@ export function uiTokenBridges(theme) {
39
89
  bridge(`shadow-${k}`, `--shadow-${k}`);
40
90
  for (const k of BREAKPOINT)
41
91
  bridge(`breakpoint-${k}`, `--breakpoint-${k}`);
42
- // The functional colour scales are opt-in: a project supplies a Radix-style
43
- // `--color-accent-1..12` / `--color-gray-1..12` in its theme and the UI's
44
- // semantic colours (`--flx-ui-color-primary`, …) follow. Absent them, the UI's
45
- // built-in scales stand.
92
+ // Functional colour scales are opt-in: supply a Radix-style 1..12 ramp and the
93
+ // UI's semantic colours follow. Absent them, the UI's built-in scales stand.
46
94
  for (let i = 1; i <= 12; i++) {
47
95
  bridge(`accent-${i}`, `--color-accent-${i}`);
48
96
  bridge(`gray-${i}`, `--color-gray-${i}`);
49
97
  }
98
+ for (const [flx, source] of STATUS)
99
+ bridge(flx, source);
50
100
  return out;
51
101
  }
52
- // The bridges as a `:root { … }` rule, ready to prepend to the compiled sheet.
53
- export function emitUiTheme(theme, selector = ':root') {
54
- return rule(selector, uiTokenBridges(theme));
102
+ /** The structural semantic layer — emitted only when the theme drives colour. */
103
+ export function uiSemanticLayer(theme) {
104
+ if (!hasColorScales(theme))
105
+ return [];
106
+ return SEMANTIC.map(([name, ref]) => decl(`--flx-ui-${name}`, `var(--flx-ui-${ref})`));
107
+ }
108
+ /**
109
+ * The bridges as sibling top-level rules, ready to prepend to the compiled sheet:
110
+ * `:root` (primitives + scales + semantic layer) and, when the theme drives
111
+ * colour, a dark-scope re-emit of the colour half so its `var()` refs re-resolve
112
+ * against the theme's dark-scoped `--color-*` values.
113
+ */
114
+ export function emitUiTheme(theme, options = {}) {
115
+ const { selector = ':root', darkSelector = "[data-theme='dark']" } = options;
116
+ const out = [rule(selector, [...uiTokenBridges(theme), ...uiSemanticLayer(theme)])];
117
+ if (darkSelector && hasColorScales(theme)) {
118
+ // Re-emit only the colour half in the dark scope (primitives don't flip).
119
+ const darkColor = [];
120
+ for (let i = 1; i <= 12; i++) {
121
+ if (theme.has(`--color-accent-${i}`))
122
+ darkColor.push(decl(`--flx-ui-accent-${i}`, `var(--color-accent-${i})`));
123
+ if (theme.has(`--color-gray-${i}`))
124
+ darkColor.push(decl(`--flx-ui-gray-${i}`, `var(--color-gray-${i})`));
125
+ }
126
+ for (const [flx, source] of STATUS)
127
+ if (theme.has(source))
128
+ darkColor.push(decl(`--flx-ui-${flx}`, `var(${source})`));
129
+ darkColor.push(...uiSemanticLayer(theme));
130
+ out.push(rule(darkSelector, darkColor));
131
+ }
132
+ return out;
55
133
  }
56
134
  //# sourceMappingURL=ui-preset.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ui-preset.js","sourceRoot":"","sources":["../../../src/engine/ui-preset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,IAAI,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAGrE,iFAAiF;AACjF,oFAAoF;AACpF,oFAAoF;AACpF,8EAA8E;AAC9E,gFAAgF;AAEhF,wEAAwE;AACxE,MAAM,WAAW,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAEjE,iFAAiF;AACjF,MAAM,SAAS,GAAuB;IACpC,CAAC,IAAI,EAAE,IAAI,CAAC;IACZ,CAAC,IAAI,EAAE,IAAI,CAAC;IACZ,CAAC,IAAI,EAAE,MAAM,CAAC;IACd,CAAC,IAAI,EAAE,IAAI,CAAC;IACZ,CAAC,IAAI,EAAE,IAAI,CAAC;IACZ,CAAC,KAAK,EAAE,KAAK,CAAC;IACd,CAAC,KAAK,EAAE,KAAK,CAAC;IACd,CAAC,KAAK,EAAE,KAAK,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACx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,CAAC,CAAC;IAE3E,4EAA4E;IAC5E,0EAA0E;IAC1E,+EAA+E;IAC/E,yBAAyB;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,kBAAkB,CAAC,EAAE,CAAC,CAAC;QAC7C,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,WAAW,CAAC,KAAY,EAAE,QAAQ,GAAG,OAAO;IAC1D,OAAO,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { type Declaration, type StyleRule, decl, rule } from './ast';\nimport { Theme } from './theme';\n\n// Bridges a fluixi-css theme to the `--flx-ui-*` custom properties the Fluixi UI\n// components read (`@fluixi-ui/tokens`). Each bridge emits `--flx-ui-x: var(--src)`\n// so a fluixi-css theme *drives* the UI — change the theme, the components follow —\n// without copying any values across. A bridge is emitted only when its source\n// token exists, so the UI's own defaults stand in for anything the theme omits.\n\n// UI space scale ↔ the `--spacing` base (space-4 = 1rem = 0.25rem × 4).\nconst SPACE_STEPS = [0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24];\n\n// UI font-size keys ↔ fluixi `--text-*` keys (the UI's `md` is fluixi's `base`).\nconst FONT_SIZE: [string, string][] = [\n ['xs', 'xs'],\n ['sm', 'sm'],\n ['md', 'base'],\n ['lg', 'lg'],\n ['xl', 'xl'],\n ['2xl', '2xl'],\n ['3xl', '3xl'],\n ['4xl', '4xl'],\n];\n\nconst RADIUS = ['sm', 'md', 'lg', 'xl'];\nconst SHADOW = ['sm', 'md', 'lg', 'xl'];\nconst BREAKPOINT = ['sm', 'md', 'lg', 'xl', '2xl'];\n\nexport function uiTokenBridges(theme: Theme): Declaration[] {\n const out: Declaration[] = [];\n const bridge = (flx: string, source: string) => {\n if (theme.has(source)) out.push(decl(`--flx-ui-${flx}`, `var(${source})`));\n };\n\n if (theme.has('--spacing')) {\n for (const n of SPACE_STEPS) {\n out.push(decl(`--flx-ui-space-${n}`, n === 0 ? '0px' : `calc(var(--spacing) * ${n})`));\n }\n }\n\n for (const k of RADIUS) bridge(`radius-${k}`, `--radius-${k}`);\n for (const [flx, key] of FONT_SIZE) bridge(`font-size-${flx}`, `--text-${key}`);\n for (const k of SHADOW) bridge(`shadow-${k}`, `--shadow-${k}`);\n for (const k of BREAKPOINT) bridge(`breakpoint-${k}`, `--breakpoint-${k}`);\n\n // The functional colour scales are opt-in: a project supplies a Radix-style\n // `--color-accent-1..12` / `--color-gray-1..12` in its theme and the UI's\n // semantic colours (`--flx-ui-color-primary`, …) follow. Absent them, the UI's\n // built-in scales stand.\n for (let i = 1; i <= 12; i++) {\n bridge(`accent-${i}`, `--color-accent-${i}`);\n bridge(`gray-${i}`, `--color-gray-${i}`);\n }\n\n return out;\n}\n\n// The bridges as a `:root { … }` rule, ready to prepend to the compiled sheet.\nexport function emitUiTheme(theme: Theme, selector = ':root'): StyleRule {\n return rule(selector, uiTokenBridges(theme));\n}\n"]}
1
+ {"version":3,"file":"ui-preset.js","sourceRoot":"","sources":["../../../src/engine/ui-preset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkD,IAAI,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAGnF,iFAAiF;AACjF,oFAAoF;AACpF,oFAAoF;AACpF,iFAAiF;AACjF,uFAAuF;AACvF,EAAE;AACF,2EAA2E;AAC3E,kFAAkF;AAClF,oFAAoF;AACpF,qFAAqF;AACrF,+EAA+E;AAC/E,2EAA2E;AAC3E,gFAAgF;AAChF,oFAAoF;AACpF,6EAA6E;AAE7E,wEAAwE;AACxE,MAAM,WAAW,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,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,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1C,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { type AstNode, type Declaration, type StyleRule, decl, rule } from './ast';\nimport { Theme } from './theme';\n\n// Bridges a fluixi-css theme to the `--flx-ui-*` custom properties the Fluixi UI\n// components read (`@fluixi-ui/tokens`). Each bridge emits `--flx-ui-x: var(--src)`\n// so a fluixi-css theme *drives* the UI — change the theme, the components follow —\n// without copying any values across. A primitive bridge is emitted only when its\n// source token exists, so the UI's own defaults stand in for anything the theme omits.\n//\n// Colour is the driven half: when the theme supplies the functional scales\n// (`--color-accent-1..12` / `--color-gray-1..12`), this also emits the UI's whole\n// *semantic* layer (`--flx-ui-color-primary`, …). That layer is purely structural —\n// every var references a scale/alias var, never a concrete colour — so it carries no\n// palette data across the package boundary; `@fluixi-ui/tokens` still owns the\n// default values. The semantic layer is re-emitted in a dark scope because\n// custom-property substitution freezes at the declaring element: a `:root`-only\n// `--flx-ui-color-primary: var(--flx-ui-accent-9)` would inherit light's *resolved*\n// colour into a dark subtree instead of re-resolving against the dark scale.\n\n// UI space scale ↔ the `--spacing` base (space-4 = 1rem = 0.25rem × 4).\nconst SPACE_STEPS = [0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24];\n\n// UI font-size keys ↔ fluixi `--text-*` keys (the UI's `md` is fluixi's `base`).\nconst FONT_SIZE: [string, string][] = [\n ['xs', 'xs'],\n ['sm', 'sm'],\n ['md', 'base'],\n ['lg', 'lg'],\n ['xl', 'xl'],\n ['2xl', '2xl'],\n ['3xl', '3xl'],\n ['4xl', '4xl'],\n];\n\nconst RADIUS = ['sm', 'md', 'lg', 'xl'];\nconst SHADOW = ['sm', 'md', 'lg', 'xl'];\nconst BREAKPOINT = ['sm', 'md', 'lg', 'xl', '2xl'];\n\n// The UI's semantic layer, mirrored from `@fluixi-ui/tokens` (`semanticColors`).\n// Structural only — refs into the scales/aliases the bridge (or the UI's own\n// defaults) provide. `color-primary-fg` and `color-overlay` are intentionally\n// omitted: they're concrete kit defaults, not scale-derived, so the UI package\n// keeps ownership of them.\nconst SEMANTIC: [string, string][] = [\n ['color-bg', 'gray-1'],\n ['color-bg-subtle', 'gray-2'],\n ['color-bg-muted', 'gray-3'],\n ['color-fg', 'gray-12'],\n ['color-fg-muted', 'gray-11'],\n ['color-border', 'gray-6'],\n ['color-border-strong', 'gray-7'],\n ['color-focus-ring', 'accent-8'],\n ['color-primary', 'accent-9'],\n ['color-primary-hover', 'accent-10'],\n ['color-primary-active', 'accent-11'],\n ['color-primary-subtle', 'accent-3'],\n ['color-danger', 'danger-solid'],\n ['color-danger-fg', 'danger-fg'],\n ['color-danger-subtle', 'danger-subtle'],\n ['color-success', 'success-solid'],\n ['color-success-fg', 'success-fg'],\n ['color-success-subtle', 'success-subtle'],\n ['color-warning', 'warning-solid'],\n ['color-warning-fg', 'warning-fg'],\n ['color-warning-subtle', 'warning-subtle'],\n];\n\n// Optional status-colour bridges: a theme may drive the UI's danger/success/\n// warning solids by supplying `--color-danger` / `--color-success` / `--color-warning`.\nconst STATUS: [string, string][] = [\n ['danger-solid', '--color-danger'],\n ['success-solid', '--color-success'],\n ['warning-solid', '--color-warning'],\n];\n\n/** True once the theme supplies enough of the functional scales to drive colour. */\nfunction hasColorScales(theme: Theme): boolean {\n return theme.has('--color-accent-9') || theme.has('--color-gray-1');\n}\n\n/** The primitive + scale bridges (non-colour and the raw scale refs). */\nexport function uiTokenBridges(theme: Theme): Declaration[] {\n const out: Declaration[] = [];\n const bridge = (flx: string, source: string) => {\n if (theme.has(source)) out.push(decl(`--flx-ui-${flx}`, `var(${source})`));\n };\n\n if (theme.has('--spacing')) {\n for (const n of SPACE_STEPS) {\n out.push(decl(`--flx-ui-space-${n}`, n === 0 ? '0px' : `calc(var(--spacing) * ${n})`));\n }\n }\n\n for (const k of RADIUS) bridge(`radius-${k}`, `--radius-${k}`);\n for (const [flx, key] of FONT_SIZE) bridge(`font-size-${flx}`, `--text-${key}`);\n for (const k of SHADOW) bridge(`shadow-${k}`, `--shadow-${k}`);\n for (const k of BREAKPOINT) bridge(`breakpoint-${k}`, `--breakpoint-${k}`);\n\n // Functional colour scales are opt-in: supply a Radix-style 1..12 ramp and the\n // UI's semantic colours follow. Absent them, the UI's built-in scales stand.\n for (let i = 1; i <= 12; i++) {\n bridge(`accent-${i}`, `--color-accent-${i}`);\n bridge(`gray-${i}`, `--color-gray-${i}`);\n }\n for (const [flx, source] of STATUS) bridge(flx, source);\n\n return out;\n}\n\n/** The structural semantic layer — emitted only when the theme drives colour. */\nexport function uiSemanticLayer(theme: Theme): Declaration[] {\n if (!hasColorScales(theme)) return [];\n return SEMANTIC.map(([name, ref]) => decl(`--flx-ui-${name}`, `var(--flx-ui-${ref})`));\n}\n\nexport interface EmitUiOptions {\n /** Root scope for the bridges + semantic layer. */\n selector?: string;\n /**\n * Dark scope. The scale bridges + semantic layer are re-emitted here so the\n * `var()` refs re-resolve against the theme's dark-scoped `--color-*` values.\n * Emitted only when the theme drives colour. Pass `null` to skip.\n */\n darkSelector?: string | null;\n}\n\n/**\n * The bridges as sibling top-level rules, ready to prepend to the compiled sheet:\n * `:root` (primitives + scales + semantic layer) and, when the theme drives\n * colour, a dark-scope re-emit of the colour half so its `var()` refs re-resolve\n * against the theme's dark-scoped `--color-*` values.\n */\nexport function emitUiTheme(theme: Theme, options: EmitUiOptions = {}): StyleRule[] {\n const { selector = ':root', darkSelector = \"[data-theme='dark']\" } = options;\n\n const out: StyleRule[] = [rule(selector, [...uiTokenBridges(theme), ...uiSemanticLayer(theme)])];\n\n if (darkSelector && hasColorScales(theme)) {\n // Re-emit only the colour half in the dark scope (primitives don't flip).\n const darkColor: AstNode[] = [];\n for (let i = 1; i <= 12; i++) {\n if (theme.has(`--color-accent-${i}`)) darkColor.push(decl(`--flx-ui-accent-${i}`, `var(--color-accent-${i})`));\n if (theme.has(`--color-gray-${i}`)) darkColor.push(decl(`--flx-ui-gray-${i}`, `var(--color-gray-${i})`));\n }\n for (const [flx, source] of STATUS) if (theme.has(source)) darkColor.push(decl(`--flx-ui-${flx}`, `var(${source})`));\n darkColor.push(...uiSemanticLayer(theme));\n out.push(rule(darkSelector, darkColor));\n }\n\n return out;\n}\n"]}