@teacss/config 0.7.1 → 0.8.0

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/README.md CHANGED
@@ -79,9 +79,31 @@ Repeated declarations append; imported relative paths rebase per item.
79
79
  Old `@preset`, malformed lists and nested configuration directives fail.
80
80
 
81
81
  With Standard enabled, `@primary "red,blue";` enables DOM selections through
82
- `data-css-primary`. The same syntax applies to neutral, focused, success, warning,
83
- failure and general. Focused follows neutral unless a configured palette is
84
- selected. Repeated/imported lists union; sources are complete physical palettes
82
+ `data-css-primary`. The same syntax applies to neutral, success, warning,
83
+ failure and general. Focused follows neutral by default; the site binds it once
84
+ with `@custom focused "primary";` or a palette target. `@focused` lists are removed. Repeated/imported lists union; sources are complete physical palettes
85
85
  with no role dependencies. `@custom` defines base values, `@custom dark` color
86
- overrides. Whole-theme variants are removed. Configuration failures retain
86
+ overrides. Whole-theme variants are removed. Configuration failures retain original alias source ranges and
87
87
  import/preset dependency paths for editor and development-server recovery.
88
+
89
+ ### Color alias statements
90
+
91
+ `@custom office "indigo";` expands all 12 scale steps plus `000` into
92
+ `var(--color-indigo-<step>)` references (`000` has a white fallback). It registers
93
+ in the entry and followed imports, never through `@source`. Color utilities,
94
+ alpha and conditions consume the alias normally. Mode blocks override base
95
+ values regardless of their position; within a base or mode block, later values win.
96
+
97
+ Names use lowercase kebab-case and cannot end in a numeric segment. Non-role
98
+ aliases cannot reuse built-in palettes, prior aliases or a complete custom base
99
+ palette formed before the statement. Sparse earlier declarations and later
100
+ per-step overrides are allowed. Targets must have all 12 effective steps in
101
+ base and modes and cannot be aliases or roles; only `focused` may follow
102
+ `primary` or `neutral`, including rebound roles. Targets may be declared later.
103
+ Seven role names can be rebound repeatedly, with the last binding winning.
104
+ Alias names never become selectable role-list candidates.
105
+
106
+ `customToTheme(blocks, themeKeys)` retains its low-level patch interface.
107
+ The shared semantic compiler `resolveCustomTheme(blocks, baseline)` validates
108
+ against resolved preset values and palette identities and reports
109
+ `EntryConfigError.diagnostics` with original file/range locations.
package/dist/index.d.ts CHANGED
@@ -1,18 +1,81 @@
1
1
  import { Preset, UserConfig, UserConfigDefaults } from "@teacss/core";
2
+ //#region src/scanCustom.d.ts
3
+ export interface ScannedCustomDeclaration {
4
+ property: string;
5
+ value: string;
6
+ /** Property-name offsets in the original source (`end` is exclusive). */
7
+ start: number;
8
+ end: number;
9
+ /** Offset of the declaration's `:` separator. */
10
+ colon: number;
11
+ /** Trimmed value offsets in the original source (`valueEnd` is exclusive). */
12
+ valueStart: number;
13
+ valueEnd: number;
14
+ }
15
+ export interface ScannedCustomBlock {
16
+ mode?: string;
17
+ declarations: ScannedCustomDeclaration[];
18
+ /** Offset of the at-rule's `@` (for block-level diagnostics). */
19
+ start: number;
20
+ /** Offsets of the block's opening and closing braces. */
21
+ open: number;
22
+ close: number;
23
+ }
24
+ export interface ScannedTopLevelAtRule {
25
+ /** Included only by the nested diagnostic scan. */
26
+ depth?: number;
27
+ /** At-rule name without the leading `@`. */
28
+ name: string;
29
+ /** Trimmed text between the name and its terminator/opening brace. */
30
+ prelude: string;
31
+ /** Full at-rule offsets in the original source (`end` is exclusive). */
32
+ start: number;
33
+ end: number;
34
+ terminator: ";" | "block" | "eof";
35
+ }
36
+ /** Return string values from exact, top-level at-rules such as `@presets "…"`. */
37
+ export declare function scanQuotedDirectives(css: string, directive: string): string[];
38
+ /** Whether an exact at-rule name occurs at the top level outside strings/comments. */
39
+ export declare function hasTopLevelDirective(css: string, directive: string): boolean;
40
+ /** Scan complete top-level at-rules without matching text in comments, strings, or nested CSS. */
41
+ export declare function scanTopLevelAtRules(css: string, includeNested?: boolean): ScannedTopLevelAtRule[];
42
+ /** Scan top-level `@custom` blocks without treating strings, comments, or nested CSS as directives. */
43
+ export declare function scanCustomBlocks(css: string): ScannedCustomBlock[];
44
+ //#endregion
45
+ //#region src/customAlias.d.ts
46
+ interface EntrySourceRange {
47
+ file?: string;
48
+ start: number;
49
+ end: number;
50
+ }
51
+ interface EntryColorAlias {
52
+ name: string;
53
+ family: string;
54
+ statement: EntrySourceRange;
55
+ nameRange: EntrySourceRange;
56
+ familyRange: EntrySourceRange;
57
+ }
58
+ //#endregion
2
59
  //#region src/entry-lists.d.ts
3
- export declare const ROLE_DIRECTIVES: readonly ["primary", "neutral", "focused", "success", "warning", "failure", "general"];
4
- export type ColorRole = (typeof ROLE_DIRECTIVES)[number];
60
+ export declare const ROLE_DIRECTIVES: readonly ["primary", "neutral", "success", "warning", "failure", "general"];
61
+ export type ColorRole = (typeof ROLE_DIRECTIVES)[number] | "focused";
5
62
  export type RolePalettes = Partial<Record<ColorRole, readonly string[]>>;
6
63
  export interface EntryDiagnostic {
64
+ file?: string;
7
65
  start: number;
8
66
  end: number;
9
67
  message: string;
10
68
  }
69
+ /** @internal Shared build/editor rejection with original source locations. */
70
+ export declare class EntryConfigError extends SyntaxError {
71
+ readonly diagnostics: EntryDiagnostic[];
72
+ constructor(diagnostics: EntryDiagnostic[]);
73
+ }
11
74
  /** Literal module names: commas separate items; CSS escapes are not decoded. */
12
75
  export declare function parseEntryList(prelude: string): string[];
13
76
  /** Recoverable diagnostics for editors; build callers reject these before loading. */
14
77
  export declare function diagnoseEntry(css: string): EntryDiagnostic[];
15
- export declare function assertEntryDirectives(css: string): void;
78
+ export declare function assertEntryDirectives(css: string, file?: string): void;
16
79
  //#endregion
17
80
  //#region src/parseEntry.d.ts
18
81
  export interface EntrySource {
@@ -28,6 +91,8 @@ export interface EntryCustomDecl {
28
91
  value: string;
29
92
  }
30
93
  export interface EntryCustomBlock {
94
+ /** A statement's identity and original source, alongside its expansion. */
95
+ alias?: EntryColorAlias;
31
96
  /** Mode name, or undefined for the base block. */
32
97
  mode?: string;
33
98
  declarations: EntryCustomDecl[];
@@ -55,7 +120,7 @@ export interface EntryConfig {
55
120
  rolePalettes?: RolePalettes;
56
121
  /** `@source "<glob>"` entries (`!`-prefixed → exclude). */
57
122
  sources: EntrySource[];
58
- /** `@custom {}` / `@custom <mode> {}` blocks, in source order. */
123
+ /** Custom blocks and expanded alias statements, in source order. */
59
124
  custom: EntryCustomBlock[];
60
125
  /** `@shortcut <name> "<expansion>"` entries, in source order. */
61
126
  shortcuts: EntryShortcut[];
@@ -71,7 +136,7 @@ export interface EntryConfig {
71
136
  * are ignored. Resolving the returned data (loading presets, scanning sources,
72
137
  * registering `@custom`) lives in the config/integration layer.
73
138
  */
74
- export declare function parseEntry(css: string): EntryConfig;
139
+ export declare function parseEntry(css: string, /** @internal Original source identity for diagnostics. */ file?: string): EntryConfig;
75
140
  //#endregion
76
141
  //#region src/customToTheme.d.ts
77
142
  export interface CustomToThemeResult {
@@ -137,6 +202,18 @@ export interface CustomDiagnostic {
137
202
  /** Position-aware custom-property diagnostics shared by builds and editors. */
138
203
  export declare function diagnoseCustom(css: string, themeKeys: string[]): CustomDiagnostic[];
139
204
  //#endregion
205
+ //#region src/resolveCustomTheme.d.ts
206
+ /** @internal Preset identity stays separate from mutable application values. */
207
+ export interface CustomThemeBaseline {
208
+ theme: Record<string, any>;
209
+ physicalPalettes?: readonly string[];
210
+ aliases?: readonly string[];
211
+ }
212
+ /** Pure semantic compiler shared by entry resolution and temporary editor configs. */
213
+ export declare function resolveCustomTheme(blocks: EntryCustomBlock[], baseline: CustomThemeBaseline): CustomToThemeResult & {
214
+ aliases: readonly string[];
215
+ };
216
+ //#endregion
140
217
  //#region src/resolveEntryConfig.d.ts
141
218
  export interface ResolveEntryResult {
142
219
  /** UserConfig assembled from the entry — feed straight to `createGenerator`. */
@@ -182,49 +259,6 @@ declare function getPresetSourcesFromError(error: unknown): string[];
182
259
  */
183
260
  export declare function resolvePresets<Theme extends object = object>(specifiers: string[], base: string): Promise<Preset<Theme>[]>;
184
261
  //#endregion
185
- //#region src/scanCustom.d.ts
186
- export interface ScannedCustomDeclaration {
187
- property: string;
188
- value: string;
189
- /** Property-name offsets in the original source (`end` is exclusive). */
190
- start: number;
191
- end: number;
192
- /** Offset of the declaration's `:` separator. */
193
- colon: number;
194
- /** Trimmed value offsets in the original source (`valueEnd` is exclusive). */
195
- valueStart: number;
196
- valueEnd: number;
197
- }
198
- export interface ScannedCustomBlock {
199
- mode?: string;
200
- declarations: ScannedCustomDeclaration[];
201
- /** Offset of the at-rule's `@` (for block-level diagnostics). */
202
- start: number;
203
- /** Offsets of the block's opening and closing braces. */
204
- open: number;
205
- close: number;
206
- }
207
- export interface ScannedTopLevelAtRule {
208
- /** Included only by the nested diagnostic scan. */
209
- depth?: number;
210
- /** At-rule name without the leading `@`. */
211
- name: string;
212
- /** Trimmed text between the name and its terminator/opening brace. */
213
- prelude: string;
214
- /** Full at-rule offsets in the original source (`end` is exclusive). */
215
- start: number;
216
- end: number;
217
- terminator: ";" | "block" | "eof";
218
- }
219
- /** Return string values from exact, top-level at-rules such as `@presets "…"`. */
220
- export declare function scanQuotedDirectives(css: string, directive: string): string[];
221
- /** Whether an exact at-rule name occurs at the top level outside strings/comments. */
222
- export declare function hasTopLevelDirective(css: string, directive: string): boolean;
223
- /** Scan complete top-level at-rules without matching text in comments, strings, or nested CSS. */
224
- export declare function scanTopLevelAtRules(css: string, includeNested?: boolean): ScannedTopLevelAtRule[];
225
- /** Scan top-level `@custom` blocks without treating strings, comments, or nested CSS as directives. */
226
- export declare function scanCustomBlocks(css: string): ScannedCustomBlock[];
227
- //#endregion
228
262
  //#region src/index.d.ts
229
263
  export interface LoadConfigResult<U> {
230
264
  config: U;
@@ -250,4 +284,4 @@ export declare function loadConfig<U extends UserConfig>(cwd?: string, configOrP
250
284
  */
251
285
  export declare function createRecoveryConfigLoader<U extends UserConfig>(): (cwd?: string, configOrPath?: string | U, defaults?: UserConfigDefaults) => Promise<LoadConfigResult<U>>;
252
286
  //#endregion
253
- export { getPresetSourcesFromError as getConfigSourcesFromError };
287
+ export { type EntryColorAlias, type EntrySourceRange, getPresetSourcesFromError as getConfigSourcesFromError };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{createRequire as e}from"node:module";import*as t from"node:fs";import n,{existsSync as r,readFileSync as i,realpathSync as a}from"node:fs";import{dirname as o,extname as s,isAbsolute as c,join as l,relative as u,resolve as d,sep as f}from"node:path";import p from"node:process";import{consola as m}from"consola";import{expandClassGroups as h,mergeDeep as g,resolveConfig as _,splitClassTokens as v}from"@teacss/core";import{glob as ee}from"tinyglobby";import{Buffer as y}from"node:buffer";import{readFile as b,stat as te}from"node:fs/promises";import{fileURLToPath as x,pathToFileURL as ne}from"node:url";const re=[`100`,`150`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`850`,`900`,`950`],ie=new Set(re);function ae(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function oe(e){return Object.keys(e).filter(t=>{if(t===`modes`||t===`defaultMode`||t===`rolePalettes`)return!1;let n=e[t];return typeof n!=`object`||!n?!1:t===`colors`||Object.values(n).every(e=>e==null||typeof e==`string`||typeof e==`number`||Array.isArray(e))})}function S(e){return e.map(e=>({key:e,prefix:e===`colors`||e===`semanticColors`?`color`:ae(e),twoLevel:e===`colors`,semanticColor:e===`semanticColors`})).sort((e,t)=>t.prefix.length-e.prefix.length)}function C(e,t,n){Object.defineProperty(e,t,{value:n,configurable:!0,enumerable:!0,writable:!0})}function w(e,t){let n=Object.hasOwn(e,t)?e[t]:void 0;if(typeof n==`object`&&n&&!Array.isArray(n))return n;let r={};return C(e,t,r),r}function T(e,t){let n=t.filter(t=>e===t.prefix||e.startsWith(`${t.prefix}-`)),r=n.find(e=>e.key===`colors`),i=n.find(e=>e.semanticColor);if(r&&i){let t=e===`color`?``:e.slice(6),n=t.lastIndexOf(`-`),a=n>0?t.slice(0,n):``,o=n>0?t.slice(n+1):``;return a&&ie.has(o)?{ok:!0,nsKey:r.key,twoLevel:!0,rest:t,colorName:a,step:o}:a&&/^\d+$/.test(o)?{ok:!1,reason:`illegal-color-step`}:t?{ok:!0,nsKey:i.key,twoLevel:!1,rest:t}:{ok:!1,reason:`unknown-prefix`}}let a=n[0];if(!a)return{ok:!1,reason:`unknown-prefix`};let o=e===a.prefix?``:e.slice(a.prefix.length+1);if(a.twoLevel){let e=o.lastIndexOf(`-`),t=e>0?o.slice(0,e):``,n=e>0?o.slice(e+1):``;return!t||!ie.has(n)?{ok:!1,reason:`illegal-color-step`}:{ok:!0,nsKey:a.key,twoLevel:!0,rest:o,colorName:t,step:n}}return{ok:!0,nsKey:a.key,twoLevel:!1,rest:o}}function E(e,t){let n=S(t),r={},i=[],a=e=>{let t=T(e.startsWith(`--`)?e.slice(2):e,n);return t.ok||i.push(e),t},o=(e,t,n)=>{let r=w(e,t.nsKey);t.twoLevel?C(w(r,t.colorName),t.step,n):C(r,t.rest||`DEFAULT`,n)};for(let t of e){let e=t.mode?w(w(r,`modes`),t.mode):r;for(let{property:n,value:r}of t.declarations){let t=a(n);t.ok&&o(e,t,r)}}return{theme:r,unknown:i}}const se=/[A-Za-z0-9-]/,ce=/[\w-]/;function D(e,t,n){let r=e.indexOf(`*/`,t+2);return r<0||r>=n?n:r+2}function O(e,t,n){let r=e[t];for(let i=t+1;i<n;i++)if(e[i]===`\\`)i++;else if(e[i]===r)return i+1;return n}function k(e,t,n){let r=``;for(let i=t;i<n;i++)if(e[i]===`/`&&e[i+1]===`*`)i=D(e,i,n)-1,r+=` `;else if(e[i]===`"`||e[i]===`'`){let t=O(e,i,n);r+=e.slice(i,t),i=t-1}else r+=e[i];return r.trim()}function le(e,t){let n=[],r=t.startsWith(`@`)?t.slice(1):t;for(let t of A(e)){if(t.name!==r||t.terminator!==`;`)continue;let e=t.prelude[0];if(e!==`"`&&e!==`'`)continue;let i=O(t.prelude,0,t.prelude.length);i!==t.prelude.length||i<=1||t.prelude[i-1]!==e||n.push(t.prelude.slice(1,i-1))}return n}function ue(e,t){let n=t.startsWith(`@`)?t.slice(1):t;return A(e).some(e=>e.name===n)}function de(e,t){for(let n=t;n<e.length;n++)if(e[n]===`/`&&e[n+1]===`*`)n=D(e,n,e.length)-1;else if(e[n]===`"`||e[n]===`'`)n=O(e,n,e.length)-1;else if(e[n]===`{`)return n;else if(e[n]===`;`||e[n]===`}`)return-1;return-1}function fe(e,t){let n=1;for(let r=t+1;r<e.length;r++)if(e[r]===`/`&&e[r+1]===`*`)r=D(e,r,e.length)-1;else if(e[r]===`"`||e[r]===`'`)r=O(e,r,e.length)-1;else if(e[r]===`{`)n++;else if(e[r]===`}`&&--n===0)return r;return-1}function A(e,t=!1){let n=[],r=0;for(let i=0;i<e.length;i++){if(e[i]===`/`&&e[i+1]===`*`){i=D(e,i,e.length)-1;continue}if(e[i]===`"`||e[i]===`'`){i=O(e,i,e.length)-1;continue}if(e[i]===`{`){r++;continue}if(e[i]===`}`){r=Math.max(0,r-1);continue}if(!t&&r!==0||e[i]!==`@`)continue;let a=i,o=a+1;for(;ce.test(e[o]??``);)o++;if(o===a+1)continue;let s=e.slice(a+1,o),c=[],l=!1;for(let u=o;u<e.length;u++){let d=e[u];if(d===`/`&&e[u+1]===`*`)u=D(e,u,e.length)-1;else if(d===`"`||d===`'`)u=O(e,u,e.length)-1;else if(d===`(`)c.push(`)`);else if(d===`[`)c.push(`]`);else if(d===c.at(-1))c.pop();else if(c.length===0&&d===`;`){n.push({name:s,prelude:k(e,o,u),start:a,end:u+1,terminator:`;`,...t?{depth:r}:{}}),i=u,l=!0;break}else if(c.length===0&&d===`{`){let c=fe(e,u);(c>=0||t)&&(n.push({name:s,prelude:k(e,o,u),start:a,end:c<0?e.length:c+1,terminator:`block`,...t?{depth:r}:{}}),i=t?u:c,t&&r++,l=!0);break}}if(!l){n.push({name:s,prelude:k(e,o,e.length),start:a,end:e.length,terminator:`eof`,...t?{depth:r}:{}});break}}return n}function pe(e,t,n){let r=[];for(let i=t;i<n;i++){let t=e[i];if(t===`/`&&e[i+1]===`*`)i=D(e,i,n)-1;else if(t===`"`||t===`'`)i=O(e,i,n)-1;else if(t===`(`)r.push(`)`);else if(t===`[`)r.push(`]`);else if(t===`{`)r.push(`}`);else if(t===r.at(-1))r.pop();else if(t===`;`&&r.length===0)return i}return n}function me(e,t,n){let r=[];for(let i=t;i<n;){for(;i<n;)if(/\s/.test(e[i]))i++;else if(e[i]===`/`&&e[i+1]===`*`)i=D(e,i,n);else break;let t=pe(e,i,n);if(e[i]!==`-`||e[i+1]!==`-`){i=t+1;continue}let a=i+2;for(;a<n&&se.test(e[a]);)a++;if(a===i+2){i=t+1;continue}let o=a;for(;o<n;)if(/\s/.test(e[o]))o++;else if(e[o]===`/`&&e[o+1]===`*`)o=D(e,o,n);else break;if(e[o]!==`:`){i=t+1;continue}let s=o+1,c=e.slice(s,t),l=c.trim(),u=s+c.length-c.trimStart().length,d=u+l.length;r.push({property:e.slice(i,a),value:l,start:i,end:a,colon:o,valueStart:u,valueEnd:d}),i=t+1}return r}function j(e){let t=[];for(let n of A(e)){if(n.name!==`custom`||n.terminator!==`block`)continue;let r=de(e,n.start+7);if(r<0)continue;let i=n.end-1;t.push({mode:n.prelude||void 0,declarations:me(e,r+1,i),start:n.start,open:r,close:i})}return t}const M=[`primary`,`neutral`,`focused`,`success`,`warning`,`failure`,`general`];function N(e){let t=e[0];if(t!==`"`&&t!==`'`)throw Error(`expected one quoted comma-separated list`);let n=1;for(;n<e.length;n++)if(e[n]===`\\`)n++;else if(e[n]===t)break;if(n!==e.length-1||e[n]!==t)throw Error(`expected one complete quoted list without extra arguments`);let r=e.slice(1,-1);if(r.includes(`\\,`))throw Error(`commas cannot be escaped; re-export the preset from a path without commas`);let i=r.split(`,`).map(e=>e.trim());if(i.some(e=>!e))throw Error(`empty lists, empty items and trailing commas are not allowed`);return i}function P(e){let t=[];for(let n of A(e,!0)){let e,r=M.includes(n.name);if(n.name===`preset`)e=`@preset was removed; use @presets "standard,official";`;else if(n.name===`custom`&&n.prelude.split(/\s+/)[0]===`theme`)e=`named themes were removed; use global / mode @custom values and data-css-<role> palette selectors`;else if(n.name===`presets`||r){if(n.depth)e=`configuration directives must be top-level`;else if(n.terminator!==`;`)e=`expected a quoted list ending with a semicolon, without a block`;else try{let t=N(n.prelude);r&&t.some(e=>!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(e))&&(e=`palette names must use lowercase kebab-case`)}catch(t){e=t.message}}e&&t.push({start:n.start,end:n.end,message:`@${n.name}: ${e}`})}return t}function F(e){let t=P(e);if(t.length)throw SyntaxError(t.map(e=>e.message).join(`
2
- `))}let he;function ge(){return he??=import(`jiti`).then(({createJiti:e})=>({createJiti:e,transformer:e(import.meta.url,{fsCache:!1,interopDefault:!0,moduleCache:!1})}))}const I=new Map,L=new WeakMap,R=16777216,z=new Map;let B=0;const V={icons:`@teacss/preset-icons`,official:`@teacss/preset-official`,standard:`@teacss/preset-standard`};function _e(t,n){try{return n.resolve(t)}catch(r){let i;try{i=n.resolve(`teacss/package.json`)}catch{throw r}return e(i).resolve(t)}}function ve(t,n){if(t.startsWith(`.`)||c(t))return d(n,t);let r=e(d(n,`_`)),i=Object.hasOwn(V,t)?V[t]:void 0;return i?_e(i,r):r.resolve(t)}function H(e){return e.startsWith(`.`)||c(e)}function U(e){try{return a(e)}catch{return d(e)}}function W(e,t){let n=o(e),i=[];for(;;){if(t.has(n)){let e=t.get(n);for(let n of i)t.set(n,e);return e}if(i.push(n),r(d(n,`package.json`))){for(let e of i)t.set(e,n);return n}let e=o(n);if(e===n){for(let e of i)t.set(e,void 0);return}n=e}}function ye(e,t){let n=u(t,e);return n===``||!c(n)&&n!==`..`&&!n.startsWith(`..${f}`)}function G(e,t,n){let r=W(e,n);return t.packageRoot===void 0?r===void 0&&ye(e,t.fallbackRoot):r===t.packageRoot}function K(e,t,n,r,i){if(!e||n.has(e)||(n.add(e),!c(e.filename)))return;let a=U(e.filename);if(G(a,r,i)){t.add(a);for(let a of e.children)K(a,t,n,r,i)}}function be(e){if(!e||typeof e!=`object`)return;let t,n,r;try{t=Reflect.get(e,`path`),n=Reflect.get(e,`url`),r=Reflect.get(e,`message`)}catch{return}if(typeof t==`string`&&c(t))return U(t);if(typeof n==`string`&&n.startsWith(`file:`))return U(x(n));if(typeof r!=`string`)return;let i=/Cannot find module ['"]([^'"]+)['"] from ['"]([^'"]+)['"]/.exec(r),a=/Cannot find module ['"]([^'"]+)['"][\s\S]*?Require stack:\s*\n- ([^\n]+)/.exec(r),s=i??a;if(!s)return;let l=s[1],u=s[2];if(l&&u&&(l.startsWith(`.`)||c(l)))return U(c(l)?l:d(o(u),l))}async function xe(e,t){let n=I.get(e)??Promise.resolve(),r,i=new Promise(e=>{r=e}),a=n.then(()=>i);I.set(e,a),await n;try{return{evaluation:t()}}finally{r(),I.get(e)===a&&I.delete(e)}}function Se(e){return()=>({visitor:{AwaitExpression(t){t.getFunctionParent()||(e.hasTopLevelAwait=!0)},CallExpression(t){t.node.callee?.type===`Identifier`&&t.node.callee.name===`jitiImport`&&(e.hasDynamicImport=!0);let n=t.node.arguments?.[0];if(t.node.callee?.type!==`Identifier`||t.node.callee.name!==`require`)return;let r=n?.type===`StringLiteral`&&typeof n.value==`string`;r&&e.dependencies.add(n.value),typeof t.node.start==`number`&&(r?t.getFunctionParent()?e.hasNestedRequire=!0:e.hasTopLevelRequire=!0:e.hasNonLiteralRequire=!0)},ForOfStatement(t){t.node.await&&!t.getFunctionParent()&&(e.hasTopLevelAwait=!0)}}})}function q(e,t,n){if(e.hasDynamicImport)throw Error(`Dynamic imports are not supported in local preset modules: "${t}". Use static imports so TeaCSS can track and reload the complete graph.`);if(e.hasNonLiteralRequire)throw Error(`CommonJS require() specifiers must be string literals in local preset modules: "${t}".`);if(e.hasNestedRequire)throw Error(`CommonJS require() is only supported at module top level in local preset modules: "${t}".`);if(e.hasTopLevelRequire&&e.hasTopLevelAwait)throw Error(`CommonJS require() cannot be combined with top-level await in a local preset module: "${t}". Use a static import instead.`);if(t!==n&&e.hasTopLevelAwait)throw Error(`Top-level await is only supported in the local preset entry module: "${t}".`)}const J=Symbol(`uncacheable transform option`);function Y(e,t=new Set){if(e===null)return`n`;if(typeof e==`string`)return`s${JSON.stringify(e)}`;if(typeof e==`boolean`)return e?`b1`:`b0`;if(typeof e==`number`)return Number.isNaN(e)?`dNaN`:e===1/0?`dInfinity`:e===-1/0?`d-Infinity`:Object.is(e,-0)?`d-0`:`d${JSON.stringify(e)}`;if(e===void 0)return`u`;if(typeof e!=`object`||t.has(e))throw J;t.add(e);try{if(Array.isArray(e)){for(let t of Reflect.ownKeys(e)){if(t===`length`)continue;if(typeof t!=`string`)throw J;let n=Number(t),r=Object.getOwnPropertyDescriptor(e,t);if(!Number.isSafeInteger(n)||n<0||String(n)!==t||n>=e.length||!r?.enumerable||!(`value`in r))throw J}let n=Array.from({length:e.length},(n,r)=>{let i=Object.getOwnPropertyDescriptor(e,String(r));return i&&`value`in i?Y(i.value,t):`h`});return`a${e.length}[${n.join(`,`)}]`}if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw J;return`o{${Reflect.ownKeys(e).map(t=>{if(typeof t!=`string`)throw J;let n=Object.getOwnPropertyDescriptor(e,t);if(!n?.enumerable||!(`value`in n))throw J;return[t,n.value]}).sort(([e],[t])=>e.localeCompare(t)).map(([e,n])=>`${JSON.stringify(e)}:${Y(n,t)}`).join(`,`)}}`}finally{t.delete(e)}}function Ce(e,t){return{...t,async:!1,interopDefault:t.interopDefault??!0,jsx:t.jsx??e.options.jsx,retainLines:t.retainLines??e.options.transformOptions?.retainLines}}function we(e){if(!(e&&Object.getPrototypeOf(e)===Object.prototype&&Reflect.ownKeys(e).length===0))return e}function Te(e){try{return Y({babel:we(e.babel),interopDefault:e.interopDefault,jsx:e.jsx,retainLines:e.retainLines,ts:e.ts})}catch{return}}function Ee(e,t,n,r){let i=y.byteLength(e)+y.byteLength(t)+y.byteLength(n);for(let e of r.dependencies)i+=y.byteLength(e);return i}function De(e,t){let n=z.get(e);n&&(B-=n.bytes,z.delete(e));let r=Ee(e,t.source,t.code,t.facts);if(!(r>R))for(z.set(e,{...t,bytes:r}),B+=r;z.size>256||B>R;){let e=z.keys().next();if(e.done)break;let t=z.get(e.value);z.delete(e.value),t&&(B-=t.bytes)}}function Oe(e){return{...e,dependencies:Array.from(e.dependencies)}}function ke(e,t,n,r,i,a){let o=t.filename?U(t.filename):n,s=Ce(e,t),c=Te(s),l=c===void 0?void 0:`${o}\0${c}`,u=l===void 0?void 0:z.get(l);if(l!==void 0&&u?.source===s.source)return z.delete(l),z.set(l,u),G(o,r,i)&&q(u.facts,o,n),{code:u.code,dependencies:u.facts.dependencies};let d=c===void 0?void 0:{filename:o,mode:c,source:s.source},f=d===void 0?void 0:a?.read(d);if(l!==void 0&&f){let e={...f.facts,dependencies:new Set(f.facts.dependencies)};return De(l,{code:f.code,facts:e,source:s.source}),G(o,r,i)&&q(e,o,n),{code:f.code,dependencies:e.dependencies}}let p={dependencies:new Set,hasDynamicImport:!1,hasNestedRequire:!1,hasNonLiteralRequire:!1,hasTopLevelAwait:!1,hasTopLevelRequire:!1},m=Se(p),h=Error.prepareStackTrace,g=Error.stackTraceLimit;try{let t=e.transform({...s,babel:{...s.babel,plugins:[...Array.isArray(s.babel?.plugins)?s.babel.plugins:[],m]}});return l!==void 0&&De(l,{code:t,facts:p,source:s.source}),G(o,r,i)&&q(p,o,n),d!==void 0&&a?.write(d,{code:t,facts:Oe(p)}),{code:t,dependencies:p.dependencies}}finally{Error.prepareStackTrace=h,Error.stackTraceLimit=g}}const Ae=/\.[cm]?[jt]sx?$/;function je(e,t,n){let r=U(c(n)?n:d(o(t),n));if(s(r))return[r];let i=Array.from(new Set([``,...e.options.extensions??[],`.json`])),a=[r,d(r,`index`)].flatMap(e=>i.map(t=>`${e}${t}`));return a.push(d(r,`package.json`)),a}function Me(t,n,r){if(r.startsWith(`node:`))return[];try{let i=H(r)?t.esmResolve(r,{parentURL:ne(n).href,try:!0}):e(n).resolve(r);if(!i)return H(r)?je(t,n,r):[];let a=i.startsWith(`file:`)?x(i):i;return c(a)?[U(a)]:[]}catch{return H(r)?je(t,n,r):[]}}async function Ne(e,t,n,r,i,a,o){let c=[e],l;for(let u=0;u<c.length;u++){let d=c[u];if(!d||!Ae.test(s(d)))continue;let f;try{f=await b(d,`utf8`)}catch(e){if(e.code===`ENOENT`)continue;throw e}d===e&&(l=f);let{dependencies:p}=ke(n,{source:f,filename:d,async:d===e,ts:/\.[cm]?tsx?$/.test(d)},e,r,i,o);for(let e of p)for(let n of Me(t,d,e))!a.has(n)&&G(n,r,i)&&(a.add(n),c.push(n))}return l}async function Pe(e,t){try{let{createPresetTransformDiskCache:n}=await import(`./presetTransformDiskCache-BNUNLsPo.js`);return n(e,import.meta.url,t)}catch{return}}function X(e,t){if(!e||typeof e!=`object`)return;let n=L.get(e)??[];L.set(e,Array.from(new Set([...n,...t])))}function Z(e){return e&&typeof e==`object`?[...L.get(e)??[]]:[]}async function Fe(t,n,r){let i=U(t),a=e(i),s=Object.create(null),c=new Set([i]),l=new Map,u={packageRoot:W(i,l),fallbackRoot:o(i)},[{createJiti:d,transformer:f},p]=await Promise.all([ge(),Pe(i,r)]),m=d(i,{fsCache:!1,interopDefault:!0,moduleCache:!1,tryNative:!1,transform:e=>{let{code:t}=ke(f,e,i,u,l,p);return{code:t}}}),h=()=>{let e=new Set;for(let t of Object.values(s))K(t,c,e,u,l);for(let t of c)K(a.cache[t],c,e,u,l)};try{let e=await Ne(i,m,f,u,l,c,p)??await b(i,`utf8`),{evaluation:t}=await xe(u.packageRoot??u.fallbackRoot,()=>{for(let e of c)delete a.cache[e];return m.evalModule(e,{async:!0,cache:s,filename:i,forceTranspile:!0})}),r=await t,o=r?.__esModule?r.default:r;if(o==null)throw Error(`@presets "${n}" has no default export (expected a Preset or preset factory)`);let d=typeof o==`function`?await o():o;return h(),{preset:d,sources:Array.from(c)}}catch(e){h();let t=be(e);throw X(e,t&&G(t,u,l)?[...c,t]:Array.from(c)),e}}async function Ie(e){let t=await te(e),n=ne(e);return n.searchParams.set(`version`,`${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`),(await import(n.href)).default}async function Le(e,t){let n=[],r=new Set,i={protectedSlotsByDirectory:new Map};for(let a of e){let e;try{e=ve(a,t);let o;if(H(a)){let t=await Fe(e,a,i);for(let e of t.sources)r.add(e);n.push(t.preset);continue}if(r.add(U(e)),o=await Ie(e),o==null)throw Error(`@presets "${a}" has no default export (expected a Preset or preset factory)`);n.push(typeof o==`function`?await o():o)}catch(t){throw X(t,e!==void 0&&H(a)?[...r,U(e)]:r),t}}return{presets:n,sources:Array.from(r)}}async function Re(e,t){return(await Le(e,t)).presets}function ze(e){let t=e,n=/^url\(\s*([^)]*?)\s*\)$/i.exec(t);if(n)t=n[1];else if(/^url\(/i.test(t))return;let r=t[0];if(r===`"`||r===`'`){if(t.length<2||t[t.length-1]!==r)return;let e=t.slice(1,-1);return e.includes(r)?void 0:e}return n?t:void 0}function Be(e){return!(!e||e.startsWith(`//`)||/^[a-z][\w+.-]*:/i.test(e))}function Ve(e){return e.split(`\\`).join(`/`)}function He(e,t,n,r){if(!Be(e)||c(e)||!r&&!e.startsWith(`./`)&&!e.startsWith(`../`))return e;let i=Ve(u(n,d(t,e)));return i.startsWith(`.`)?i:`./${i}`}function Ue(e,t){if(t.length===0)return e;t.sort((e,t)=>e.start-t.start);let n=``,r=0;for(let i of t)n+=e.slice(r,i.start)+i.replacement,r=i.end;return n+e.slice(r)}function We(e,t,n){if(t===n)return e;let r=[];for(let i of A(e)){if(i.terminator!==`;`||i.name!==`presets`&&i.name!==`source`)continue;let a=i.prelude[0];if(a!==`"`&&a!==`'`||i.prelude[i.prelude.length-1]!==a)continue;if(i.name===`presets`){let e=N(i.prelude).map(e=>{let r=He(e,t,n,!1);if(r.includes(`,`))throw SyntaxError(`@presets: rebased module paths cannot contain commas; re-export from a path without commas`);return r});r.push({start:i.start,end:i.end,replacement:`@presets ${a}${e.join(`,`)}${a};`});continue}let o=i.prelude.slice(1,-1).trim(),s=i.name===`source`&&o.startsWith(`!`),c=s?o.slice(1):o,l=He(c,t,n,i.name===`source`);if(l===c)continue;let u=e.slice(i.start,i.end).replace(i.prelude,`${a}${s?`!`:``}${l}${a}`);r.push({start:i.start,end:i.end,replacement:u})}return Ue(e,r)}function Ge(e,n,r,i,a,s){if(F(e),a>32)return e;let c=[];for(let l of A(e)){if(l.name!==`import`||l.terminator!==`;`)continue;let e=ze(l.prelude);if(e===void 0||!Be(e))continue;let u=d(n,e);if(!s?.has(u))try{if(!t.statSync(u).isFile())continue}catch{continue}if(r.has(u)){c.push({start:l.start,end:l.end,replacement:``});continue}r.add(u),i.push(u);let f=o(u),p=Ge(s?.get(u)??t.readFileSync(u,`utf8`),f,r,i,a+1,s);p=We(p,f,n),c.push({start:l.start,end:l.end,replacement:p})}return Ue(e,c)}function Ke(e,t,n,r){let i=[],a=new Set(n?[d(t,n)]:[]);try{return{css:Ge(e,t,a,i,0,r),files:i}}catch(e){throw X(e,i),e}}function Q(e){return e?e.split(/\s+/)[0]===`theme`?{kind:`invalid`}:{kind:`mode`,mode:e}:{kind:`base`}}function qe(e){let t,n=0,r=null;for(let i=0;i<e.length;i++){let a=e[i];if(r)a===`\\`?i++:a===r&&(r=null);else if(a===`"`||a===`'`)r=a;else if(a===`/`&&e[i+1]===`*`){let r=e.indexOf(`*/`,i+2),a=r<0?e.length:r+2;(t??=[]).push(e.slice(n,i),` `),n=a,i=a-1}}return t?`${t.join(``)}${e.slice(n)}`:e}function Je(e){let t=e[0];if(t===`"`||t===`'`)for(let n=1;n<e.length;n++){let r=e[n];if(r===`\\`)n++;else if(r===t)return n===e.length-1?e.slice(1,n):void 0}}function $(e){let t=A(e),n=[],r={},i=[],a=[],o=[],s=!1,c=!1;for(let e of t){if(e.name===`custom`&&e.terminator===`block`?s=!0:e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`&&(c=!0),e.terminator!==`;`)continue;if(M.includes(e.name)){try{let t=e.name,n=N(e.prelude);r[t]=[...new Set([...r[t]??[],...n])].sort()}catch{}continue}if(e.name===`shortcut`){let t=e.prelude.search(/\s/);if(t<=0)continue;let n=e.prelude.slice(0,t);if(!/^[A-Za-z_][\w-]*$/.test(n))continue;let r=Je(e.prelude.slice(t).trimStart())?.trim();r&&a.push({name:n,expansion:r});continue}if(e.name!==`presets`&&e.name!==`source`&&e.name!==`safelist`)continue;let t=Je(e.prelude)?.trim();if(!t)continue;if(e.name===`presets`){try{n.push(...N(e.prelude))}catch{}continue}if(e.name===`safelist`){o.push(t);continue}let l=t.startsWith(`!`),u=l?t.slice(1):t;u&&i.push({glob:u,exclude:l})}let l=s?j(e).flatMap(({mode:e,declarations:t})=>{let n=Q(e);return n.kind===`invalid`?[]:[{mode:n.kind===`base`?void 0:n.mode,declarations:t.map(({property:e,value:t})=>({property:e,value:qe(t).trim()}))}]}):[];return{presets:n,...Object.keys(r).length?{rolePalettes:r}:{},sources:i,custom:l,shortcuts:a,safelist:o,hasTeacss:c}}async function Ye(e,t,n,r){let a=e.filter(e=>!e.exclude).map(e=>e.glob);if(a.length===0)return{shortcuts:[],safelist:[],files:[]};let o=e.filter(e=>e.exclude).map(e=>e.glob),s=await ee(a,{cwd:t,absolute:!0,ignore:o,expandDirectories:!1}),c=new Set(n),l=s.filter(e=>e.endsWith(`.css`)&&!c.has(e)).sort(),u=[],d=[];for(let e of l){let t;try{t=r?.get(e)??i(e,`utf8`)}catch(e){if(e.code===`ENOENT`)continue;throw e}if(!t.includes(`@shortcut`)&&!t.includes(`@safelist`))continue;let n=$(t);u.push(...n.shortcuts),d.push(...n.safelist)}return{shortcuts:u,safelist:d,files:l}}async function Xe(e,t,n,r){let i=Ke(e,t,n,r),a=$(i.css),[o,s]=await Promise.all([a.presets.length?Le(a.presets,t):{presets:[],sources:[]},Ye(a.sources,t,i.files,r)]).catch(e=>{throw X(e,i.files),e}),c=o.presets,l={},u=[],d=Object.freeze(Object.fromEntries(Object.entries(a.rolePalettes??{}).map(([e,t])=>[e,Object.freeze([...t])]))),f={name:`@teacss/config/role-palettes`,configResolved(e){Object.defineProperty(e,Symbol.for(`@teacss/config/role-palettes`),{value:d,configurable:!0})}};await _({presets:c,configResolved(e){if({theme:l,unknown:u}=E(a.custom,oe(e.theme)),a.rolePalettes&&!e.presets.some(e=>e.name===`@teacss/preset-standard`))throw TypeError(`Role palette directives require an explicitly enabled Standard preset`);e.theme=g(e.theme,l),a.rolePalettes&&f.configResolved?.(e)}}).catch(e=>{throw X(e,[...i.files,...s.files,...o.sources]),e});let p=[...a.sources.filter(e=>!e.exclude).map(e=>e.glob),...a.sources.filter(e=>e.exclude).map(e=>`!${e.glob}`)],m=[...s.shortcuts,...a.shortcuts],ee=Object.fromEntries(m.map(({name:e,expansion:t})=>[e,t])),y=[...new Set([...s.safelist,...a.safelist].flatMap(e=>v(h(e))))];return{config:{presets:a.rolePalettes?[...c,f]:c,theme:l,...a.sources.length?{content:{filesystem:p}}:{},...m.length?{shortcuts:ee}:{},...y.length?{safelist:y}:{}},unknown:u,hasTeacss:i.files.length===0?a.hasTeacss:$(e).hasTeacss,sources:[...i.files,...s.files,...o.sources]}}const Ze=re.join(` `);function Qe(e,t){switch(t){case`unknown-prefix`:return`@custom var "${e}" matches no theme namespace — not registered (emitted as a plain :root var).`;case`illegal-color-step`:return`@custom var "${e}" has an illegal color step — palette steps are ${Ze}.`;case`removed-theme`:return`@custom ${e}: named themes were removed; use global / mode values and data-css-<role> palette selectors.`}}function $e(e,t){let n=S(t),r=[],i=j(e);for(let e of i){if(Q(e.mode).kind===`invalid`){r.push({property:e.mode,start:e.start,end:e.open,reason:`removed-theme`,message:Qe(e.mode,`removed-theme`)});continue}for(let t of e.declarations){let{property:e,start:i,end:a}=t,o=T(e.slice(2),n);o.ok||r.push({property:e,start:i,end:a,reason:o.reason,message:Qe(e,o.reason)})}}return r}const et=Object.freeze([`package.json`,`index.css`,`src/index.css`]),[tt,...nt]=et;function rt(e){let t=e instanceof Error?`${e.name}:${e.message}`:`${typeof e}:${String(e)}`,r=Array.from(new Set(Z(e))).sort().map(e=>{try{let t=n.statSync(e);return`${e}:${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`}catch(t){let n=t.code;return`${e}:${n===`ENOENT`?`missing`:`unreadable:${n??String(t)}`}`}});return JSON.stringify([t,r])}function it(e,t){let n={...e};for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(t,e)?.enumerable)continue;let r=Reflect.get(t,e);r!==void 0&&Object.defineProperty(n,e,{value:r,configurable:!0,enumerable:!0,writable:!0})}return n}function at(e){try{let t=n.readFileSync(e,`utf8`);return t.includes(`@teacss`)?A(t).some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`):!1}catch(e){if(e.code===`ENOENT`)return!1;throw e}}function ot(e){try{let t=JSON.parse(n.readFileSync(l(e,tt),`utf8`))?.teacss?.entry;return typeof t==`string`?t:void 0}catch(e){if(e.code===`ENOENT`)return;throw e}}function st(e){let t=ot(e);if(t){let r=d(e,t);if(n.existsSync(r)&&n.statSync(r).isFile())return r}for(let t of nt){let r=l(e,t);if(n.existsSync(r)&&n.statSync(r).isFile()&&at(r))return r}}async function ct(e=p.cwd(),t=e,r={}){if(typeof t!=`string`)return{config:it(r,t),sources:[]};let i=d(e,t),a=n.existsSync(i)&&n.statSync(i).isFile()?i:st(i);if(!a)return{config:{...r},sources:[]};let s;try{s=await Xe(n.readFileSync(a,`utf8`),o(a),a)}catch(e){throw X(e,[a]),e}let{config:c}=s,l=it(r,c);return c.presets?.length||(r.presets?.length?l.presets=r.presets:m.warn(`[@teacss/config] "${a}" declares no @presets — no utilities will be generated. Add one, e.g. \`@presets "standard";\``)),{config:l,sources:Array.from(new Set([a,...s.sources]))}}function lt(){let e=new Map,t=new Map,n=new Map,r=new Map,i=new WeakMap,a=new WeakMap,o=new WeakMap,s=new WeakMap,c=(e,n)=>e?t.get(e):n?a.get(n):void 0,l=(e,t)=>e?n.get(e):t?o.get(t):void 0,u=async(e,t)=>{for(;;){let n=c(e,t),r=l(e,t);if(!r)return;let i=await r;if(c(e,t)===n)return i}};return(c=p.cwd(),l=c,f={})=>{let h=typeof l==`string`?d(c,l):void 0,g=typeof l==`object`&&l?l:void 0,_=h?(t.get(h)??0)+1:g?(a.get(g)??0)+1:0;h?t.set(h,_):g&&a.set(g,_);let v=ct(c,l,f).then(n=>(h&&t.get(h)===_?(e.set(h,n),r.delete(h)):g&&a.get(g)===_&&(i.set(g,n),s.delete(g)),n),async n=>{let o=h?t.get(h)===_:!g||a.get(g)===_;if(!o){let e=await u(h,g);if(e)return e}let c=h?e.get(h):g?i.get(g):void 0;if(!c)throw n;if(o){let e=rt(n);e!==(h?r.get(h):g?s.get(g):void 0)&&(m.error(`[@teacss/config] Error resolving config from the CSS entry:`,n),h?r.set(h,e):g&&s.set(g,e));let t=Array.from(new Set([...c.sources,...Z(n)]));return t.length===c.sources.length?c:{...c,sources:t}}return c});return h?n.set(h,v):g&&o.set(g,v),v}}export{M as ROLE_DIRECTIVES,F as assertEntryDirectives,S as buildNamespaces,T as classifyCustomVar,lt as createRecoveryConfigLoader,E as customToTheme,$e as diagnoseCustom,P as diagnoseEntry,et as entryDiscoveryFiles,st as findEntry,Z as getConfigSourcesFromError,ue as hasTopLevelDirective,ct as loadConfig,Q as parseCustomPrelude,$ as parseEntry,N as parseEntryList,Xe as resolveEntryConfig,Re as resolvePresets,oe as scaleThemeKeys,j as scanCustomBlocks,le as scanQuotedDirectives,A as scanTopLevelAtRules};
1
+ import{createRequire as e}from"node:module";import*as t from"node:fs";import n,{existsSync as r,readFileSync as i,realpathSync as a}from"node:fs";import{dirname as o,extname as s,isAbsolute as c,join as l,relative as u,resolve as d,sep as f}from"node:path";import p from"node:process";import{consola as m}from"consola";import{expandClassGroups as h,mergeDeep as g,resolveConfig as _,splitClassTokens as v}from"@teacss/core";import{glob as ee}from"tinyglobby";import{Buffer as y}from"node:buffer";import{readFile as b,stat as x}from"node:fs/promises";import{fileURLToPath as te,pathToFileURL as ne}from"node:url";const S=[`000`,`100`,`150`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`850`,`900`,`950`],re=new Set(S);function ie(e){if(e.terminator!==`;`)return`expected @custom <name> "<family>"; without a mode or block`;let t=/^(\S+)\s+(["'])([^"']*)\2$/.exec(e.prelude);if(!t)return`expected one name and one complete quoted target without extra arguments`;if(!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(t[1])||/^\d+$/.test(t[1].split(`-`).at(-1)))return`alias names must use lowercase kebab-case with a nonnumeric final segment`;if(!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(t[3]))return`target must be one lowercase kebab-case palette name, without a list`}function C(e,t,n){if(ie(t))return;let r=e.slice(t.start,t.end).replace(/(["'])(?:\\.|(?!\1)[\s\S])*?\1|\/\*[\s\S]*?\*\//g,e=>e.startsWith(`/*`)?e.replace(/[^\r\n]/g,` `):e),i=/^@custom\s+(\S+)\s+(["'])([^"']*)\2\s*;$/.exec(r);if(!i)return;let a=t.start+r.indexOf(i[1],7),o=t.start+r.indexOf(i[2],a-t.start+i[1].length)+1;return{name:i[1],family:i[3],statement:{file:n,start:t.start,end:t.end},nameRange:{file:n,start:a,end:a+i[1].length},familyRange:{file:n,start:o,end:o+i[3].length}}}function ae(e){return S.map(t=>({property:`--color-${e.name}-${t}`,value:`var(--color-${e.family}-${t}${t===`000`?`, white`:``})`}))}const oe=/[A-Za-z0-9-]/,se=/[\w-]/;function w(e,t,n){let r=e.indexOf(`*/`,t+2);return r<0||r>=n?n:r+2}function T(e,t,n){let r=e[t];for(let i=t+1;i<n;i++)if(e[i]===`\\`)i++;else if(e[i]===r)return i+1;return n}function E(e,t,n){let r=``;for(let i=t;i<n;i++)if(e[i]===`/`&&e[i+1]===`*`)i=w(e,i,n)-1,r+=` `;else if(e[i]===`"`||e[i]===`'`){let t=T(e,i,n);r+=e.slice(i,t),i=t-1}else r+=e[i];return r.trim()}function ce(e,t){let n=[],r=t.startsWith(`@`)?t.slice(1):t;for(let t of D(e)){if(t.name!==r||t.terminator!==`;`)continue;let e=t.prelude[0];if(e!==`"`&&e!==`'`)continue;let i=T(t.prelude,0,t.prelude.length);i!==t.prelude.length||i<=1||t.prelude[i-1]!==e||n.push(t.prelude.slice(1,i-1))}return n}function le(e,t){let n=t.startsWith(`@`)?t.slice(1):t;return D(e).some(e=>e.name===n)}function ue(e,t){for(let n=t;n<e.length;n++)if(e[n]===`/`&&e[n+1]===`*`)n=w(e,n,e.length)-1;else if(e[n]===`"`||e[n]===`'`)n=T(e,n,e.length)-1;else if(e[n]===`{`)return n;else if(e[n]===`;`||e[n]===`}`)return-1;return-1}function de(e,t){let n=1;for(let r=t+1;r<e.length;r++)if(e[r]===`/`&&e[r+1]===`*`)r=w(e,r,e.length)-1;else if(e[r]===`"`||e[r]===`'`)r=T(e,r,e.length)-1;else if(e[r]===`{`)n++;else if(e[r]===`}`&&--n===0)return r;return-1}function D(e,t=!1){let n=[],r=0;for(let i=0;i<e.length;i++){if(e[i]===`/`&&e[i+1]===`*`){i=w(e,i,e.length)-1;continue}if(e[i]===`"`||e[i]===`'`){i=T(e,i,e.length)-1;continue}if(e[i]===`{`){r++;continue}if(e[i]===`}`){r=Math.max(0,r-1);continue}if(!t&&r!==0||e[i]!==`@`)continue;let a=i,o=a+1;for(;se.test(e[o]??``);)o++;if(o===a+1)continue;let s=e.slice(a+1,o),c=[],l=!1;for(let u=o;u<e.length;u++){let d=e[u];if(d===`/`&&e[u+1]===`*`)u=w(e,u,e.length)-1;else if(d===`"`||d===`'`)u=T(e,u,e.length)-1;else if(d===`(`)c.push(`)`);else if(d===`[`)c.push(`]`);else if(d===c.at(-1))c.pop();else if(c.length===0&&d===`;`){n.push({name:s,prelude:E(e,o,u),start:a,end:u+1,terminator:`;`,...t?{depth:r}:{}}),i=u,l=!0;break}else if(c.length===0&&d===`{`){let c=de(e,u);(c>=0||t)&&(n.push({name:s,prelude:E(e,o,u),start:a,end:c<0?e.length:c+1,terminator:`block`,...t?{depth:r}:{}}),i=t?u:c,t&&r++,l=!0);break}}if(!l){n.push({name:s,prelude:E(e,o,e.length),start:a,end:e.length,terminator:`eof`,...t?{depth:r}:{}});break}}return n}function fe(e,t,n){let r=[];for(let i=t;i<n;i++){let t=e[i];if(t===`/`&&e[i+1]===`*`)i=w(e,i,n)-1;else if(t===`"`||t===`'`)i=T(e,i,n)-1;else if(t===`(`)r.push(`)`);else if(t===`[`)r.push(`]`);else if(t===`{`)r.push(`}`);else if(t===r.at(-1))r.pop();else if(t===`;`&&r.length===0)return i}return n}function pe(e,t,n){let r=[];for(let i=t;i<n;){for(;i<n;)if(/\s/.test(e[i]))i++;else if(e[i]===`/`&&e[i+1]===`*`)i=w(e,i,n);else break;let t=fe(e,i,n);if(e[i]!==`-`||e[i+1]!==`-`){i=t+1;continue}let a=i+2;for(;a<n&&oe.test(e[a]);)a++;if(a===i+2){i=t+1;continue}let o=a;for(;o<n;)if(/\s/.test(e[o]))o++;else if(e[o]===`/`&&e[o+1]===`*`)o=w(e,o,n);else break;if(e[o]!==`:`){i=t+1;continue}let s=o+1,c=e.slice(s,t),l=c.trim(),u=s+c.length-c.trimStart().length,d=u+l.length;r.push({property:e.slice(i,a),value:l,start:i,end:a,colon:o,valueStart:u,valueEnd:d}),i=t+1}return r}function O(e){let t=[];for(let n of D(e)){if(n.name!==`custom`||n.terminator!==`block`)continue;let r=ue(e,n.start+7);if(r<0)continue;let i=n.end-1;t.push({mode:n.prelude||void 0,declarations:pe(e,r+1,i),start:n.start,open:r,close:i})}return t}const k=[`primary`,`neutral`,`success`,`warning`,`failure`,`general`];var A=class extends SyntaxError{diagnostics;constructor(e){super(e.map(e=>e.message).join(`
2
+ `)),this.diagnostics=e,this.name=`EntryConfigError`}};function j(e){let t=e[0];if(t!==`"`&&t!==`'`)throw Error(`expected one quoted comma-separated list`);let n=1;for(;n<e.length;n++)if(e[n]===`\\`)n++;else if(e[n]===t)break;if(n!==e.length-1||e[n]!==t)throw Error(`expected one complete quoted list without extra arguments`);let r=e.slice(1,-1);if(r.includes(`\\,`))throw Error(`commas cannot be escaped; re-export the preset from a path without commas`);let i=r.split(`,`).map(e=>e.trim());if(i.some(e=>!e))throw Error(`empty lists, empty items and trailing commas are not allowed`);return i}function me(e){let t=[];for(let n of D(e,!0)){let e,r=k.includes(n.name);if(n.name===`preset`)e=`@preset was removed; use @presets "standard,official";`;else if(n.name===`focused`)e=`removed; the site binds focus once with @custom focused "<family>";`;else if(n.name===`custom`&&n.terminator===`block`&&n.prelude.split(/\s+/)[0]===`theme`)e=`named themes were removed; use global / mode @custom values and data-css-<role> palette selectors`;else if(n.name===`custom`&&n.terminator!==`block`)e=n.depth?`configuration directives must be top-level`:ie(n);else if(n.name===`presets`||r){if(n.depth)e=`configuration directives must be top-level`;else if(n.terminator!==`;`)e=`expected a quoted list ending with a semicolon, without a block`;else try{let t=j(n.prelude);r&&t.some(e=>!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(e))&&(e=`palette names must use lowercase kebab-case`)}catch(t){e=t.message}}e&&t.push({start:n.start,end:n.end,message:`@${n.name}: ${e}`})}return t}function he(e,t){let n=me(e);if(n.length)throw new A(n.map(e=>({...e,file:t})))}let ge;function _e(){return ge??=import(`jiti`).then(({createJiti:e})=>({createJiti:e,transformer:e(import.meta.url,{fsCache:!1,interopDefault:!0,moduleCache:!1})}))}const M=new Map,N=new WeakMap,ve=16777216,P=new Map;let F=0;const ye={icons:`@teacss/preset-icons`,official:`@teacss/preset-official`,standard:`@teacss/preset-standard`};function be(t,n){try{return n.resolve(t)}catch(r){let i;try{i=n.resolve(`teacss/package.json`)}catch{throw r}return e(i).resolve(t)}}function xe(t,n){if(t.startsWith(`.`)||c(t))return d(n,t);let r=e(d(n,`_`)),i=Object.hasOwn(ye,t)?ye[t]:void 0;return i?be(i,r):r.resolve(t)}function I(e){return e.startsWith(`.`)||c(e)}function L(e){try{return a(e)}catch{return d(e)}}function Se(e,t){let n=o(e),i=[];for(;;){if(t.has(n)){let e=t.get(n);for(let n of i)t.set(n,e);return e}if(i.push(n),r(d(n,`package.json`))){for(let e of i)t.set(e,n);return n}let e=o(n);if(e===n){for(let e of i)t.set(e,void 0);return}n=e}}function Ce(e,t){let n=u(t,e);return n===``||!c(n)&&n!==`..`&&!n.startsWith(`..${f}`)}function R(e,t,n){let r=Se(e,n);return t.packageRoot===void 0?r===void 0&&Ce(e,t.fallbackRoot):r===t.packageRoot}function z(e,t,n,r,i){if(!e||n.has(e)||(n.add(e),!c(e.filename)))return;let a=L(e.filename);if(R(a,r,i)){t.add(a);for(let a of e.children)z(a,t,n,r,i)}}function we(e){if(!e||typeof e!=`object`)return;let t,n,r;try{t=Reflect.get(e,`path`),n=Reflect.get(e,`url`),r=Reflect.get(e,`message`)}catch{return}if(typeof t==`string`&&c(t))return L(t);if(typeof n==`string`&&n.startsWith(`file:`))return L(te(n));if(typeof r!=`string`)return;let i=/Cannot find module ['"]([^'"]+)['"] from ['"]([^'"]+)['"]/.exec(r),a=/Cannot find module ['"]([^'"]+)['"][\s\S]*?Require stack:\s*\n- ([^\n]+)/.exec(r),s=i??a;if(!s)return;let l=s[1],u=s[2];if(l&&u&&(l.startsWith(`.`)||c(l)))return L(c(l)?l:d(o(u),l))}async function Te(e,t){let n=M.get(e)??Promise.resolve(),r,i=new Promise(e=>{r=e}),a=n.then(()=>i);M.set(e,a),await n;try{return{evaluation:t()}}finally{r(),M.get(e)===a&&M.delete(e)}}function Ee(e){return()=>({visitor:{AwaitExpression(t){t.getFunctionParent()||(e.hasTopLevelAwait=!0)},CallExpression(t){t.node.callee?.type===`Identifier`&&t.node.callee.name===`jitiImport`&&(e.hasDynamicImport=!0);let n=t.node.arguments?.[0];if(t.node.callee?.type!==`Identifier`||t.node.callee.name!==`require`)return;let r=n?.type===`StringLiteral`&&typeof n.value==`string`;r&&e.dependencies.add(n.value),typeof t.node.start==`number`&&(r?t.getFunctionParent()?e.hasNestedRequire=!0:e.hasTopLevelRequire=!0:e.hasNonLiteralRequire=!0)},ForOfStatement(t){t.node.await&&!t.getFunctionParent()&&(e.hasTopLevelAwait=!0)}}})}function B(e,t,n){if(e.hasDynamicImport)throw Error(`Dynamic imports are not supported in local preset modules: "${t}". Use static imports so TeaCSS can track and reload the complete graph.`);if(e.hasNonLiteralRequire)throw Error(`CommonJS require() specifiers must be string literals in local preset modules: "${t}".`);if(e.hasNestedRequire)throw Error(`CommonJS require() is only supported at module top level in local preset modules: "${t}".`);if(e.hasTopLevelRequire&&e.hasTopLevelAwait)throw Error(`CommonJS require() cannot be combined with top-level await in a local preset module: "${t}". Use a static import instead.`);if(t!==n&&e.hasTopLevelAwait)throw Error(`Top-level await is only supported in the local preset entry module: "${t}".`)}const V=Symbol(`uncacheable transform option`);function H(e,t=new Set){if(e===null)return`n`;if(typeof e==`string`)return`s${JSON.stringify(e)}`;if(typeof e==`boolean`)return e?`b1`:`b0`;if(typeof e==`number`)return Number.isNaN(e)?`dNaN`:e===1/0?`dInfinity`:e===-1/0?`d-Infinity`:Object.is(e,-0)?`d-0`:`d${JSON.stringify(e)}`;if(e===void 0)return`u`;if(typeof e!=`object`||t.has(e))throw V;t.add(e);try{if(Array.isArray(e)){for(let t of Reflect.ownKeys(e)){if(t===`length`)continue;if(typeof t!=`string`)throw V;let n=Number(t),r=Object.getOwnPropertyDescriptor(e,t);if(!Number.isSafeInteger(n)||n<0||String(n)!==t||n>=e.length||!r?.enumerable||!(`value`in r))throw V}let n=Array.from({length:e.length},(n,r)=>{let i=Object.getOwnPropertyDescriptor(e,String(r));return i&&`value`in i?H(i.value,t):`h`});return`a${e.length}[${n.join(`,`)}]`}if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw V;return`o{${Reflect.ownKeys(e).map(t=>{if(typeof t!=`string`)throw V;let n=Object.getOwnPropertyDescriptor(e,t);if(!n?.enumerable||!(`value`in n))throw V;return[t,n.value]}).sort(([e],[t])=>e.localeCompare(t)).map(([e,n])=>`${JSON.stringify(e)}:${H(n,t)}`).join(`,`)}}`}finally{t.delete(e)}}function De(e,t){return{...t,async:!1,interopDefault:t.interopDefault??!0,jsx:t.jsx??e.options.jsx,retainLines:t.retainLines??e.options.transformOptions?.retainLines}}function Oe(e){if(!(e&&Object.getPrototypeOf(e)===Object.prototype&&Reflect.ownKeys(e).length===0))return e}function ke(e){try{return H({babel:Oe(e.babel),interopDefault:e.interopDefault,jsx:e.jsx,retainLines:e.retainLines,ts:e.ts})}catch{return}}function Ae(e,t,n,r){let i=y.byteLength(e)+y.byteLength(t)+y.byteLength(n);for(let e of r.dependencies)i+=y.byteLength(e);return i}function je(e,t){let n=P.get(e);n&&(F-=n.bytes,P.delete(e));let r=Ae(e,t.source,t.code,t.facts);if(!(r>ve))for(P.set(e,{...t,bytes:r}),F+=r;P.size>256||F>ve;){let e=P.keys().next();if(e.done)break;let t=P.get(e.value);P.delete(e.value),t&&(F-=t.bytes)}}function Me(e){return{...e,dependencies:Array.from(e.dependencies)}}function Ne(e,t,n,r,i,a){let o=t.filename?L(t.filename):n,s=De(e,t),c=ke(s),l=c===void 0?void 0:`${o}\0${c}`,u=l===void 0?void 0:P.get(l);if(l!==void 0&&u?.source===s.source)return P.delete(l),P.set(l,u),R(o,r,i)&&B(u.facts,o,n),{code:u.code,dependencies:u.facts.dependencies};let d=c===void 0?void 0:{filename:o,mode:c,source:s.source},f=d===void 0?void 0:a?.read(d);if(l!==void 0&&f){let e={...f.facts,dependencies:new Set(f.facts.dependencies)};return je(l,{code:f.code,facts:e,source:s.source}),R(o,r,i)&&B(e,o,n),{code:f.code,dependencies:e.dependencies}}let p={dependencies:new Set,hasDynamicImport:!1,hasNestedRequire:!1,hasNonLiteralRequire:!1,hasTopLevelAwait:!1,hasTopLevelRequire:!1},m=Ee(p),h=Error.prepareStackTrace,g=Error.stackTraceLimit;try{let t=e.transform({...s,babel:{...s.babel,plugins:[...Array.isArray(s.babel?.plugins)?s.babel.plugins:[],m]}});return l!==void 0&&je(l,{code:t,facts:p,source:s.source}),R(o,r,i)&&B(p,o,n),d!==void 0&&a?.write(d,{code:t,facts:Me(p)}),{code:t,dependencies:p.dependencies}}finally{Error.prepareStackTrace=h,Error.stackTraceLimit=g}}const Pe=/\.[cm]?[jt]sx?$/;function Fe(e,t,n){let r=L(c(n)?n:d(o(t),n));if(s(r))return[r];let i=Array.from(new Set([``,...e.options.extensions??[],`.json`])),a=[r,d(r,`index`)].flatMap(e=>i.map(t=>`${e}${t}`));return a.push(d(r,`package.json`)),a}function Ie(t,n,r){if(r.startsWith(`node:`))return[];try{let i=I(r)?t.esmResolve(r,{parentURL:ne(n).href,try:!0}):e(n).resolve(r);if(!i)return I(r)?Fe(t,n,r):[];let a=i.startsWith(`file:`)?te(i):i;return c(a)?[L(a)]:[]}catch{return I(r)?Fe(t,n,r):[]}}async function Le(e,t,n,r,i,a,o){let c=[e],l;for(let u=0;u<c.length;u++){let d=c[u];if(!d||!Pe.test(s(d)))continue;let f;try{f=await b(d,`utf8`)}catch(e){if(e.code===`ENOENT`)continue;throw e}d===e&&(l=f);let{dependencies:p}=Ne(n,{source:f,filename:d,async:d===e,ts:/\.[cm]?tsx?$/.test(d)},e,r,i,o);for(let e of p)for(let n of Ie(t,d,e))!a.has(n)&&R(n,r,i)&&(a.add(n),c.push(n))}return l}async function Re(e,t){try{let{createPresetTransformDiskCache:n}=await import(`./presetTransformDiskCache-BNUNLsPo.js`);return n(e,import.meta.url,t)}catch{return}}function U(e,t){if(!e||typeof e!=`object`)return;let n=N.get(e)??[];N.set(e,Array.from(new Set([...n,...t])))}function W(e){return e&&typeof e==`object`?[...N.get(e)??[]]:[]}async function ze(t,n,r){let i=L(t),a=e(i),s=Object.create(null),c=new Set([i]),l=new Map,u={packageRoot:Se(i,l),fallbackRoot:o(i)},[{createJiti:d,transformer:f},p]=await Promise.all([_e(),Re(i,r)]),m=d(i,{fsCache:!1,interopDefault:!0,moduleCache:!1,tryNative:!1,transform:e=>{let{code:t}=Ne(f,e,i,u,l,p);return{code:t}}}),h=()=>{let e=new Set;for(let t of Object.values(s))z(t,c,e,u,l);for(let t of c)z(a.cache[t],c,e,u,l)};try{let e=await Le(i,m,f,u,l,c,p)??await b(i,`utf8`),{evaluation:t}=await Te(u.packageRoot??u.fallbackRoot,()=>{for(let e of c)delete a.cache[e];return m.evalModule(e,{async:!0,cache:s,filename:i,forceTranspile:!0})}),r=await t,o=r?.__esModule?r.default:r;if(o==null)throw Error(`@presets "${n}" has no default export (expected a Preset or preset factory)`);let d=typeof o==`function`?await o():o;return h(),{preset:d,sources:Array.from(c)}}catch(e){h();let t=we(e);throw U(e,t&&R(t,u,l)?[...c,t]:Array.from(c)),e}}async function Be(e){let t=await x(e),n=ne(e);return n.searchParams.set(`version`,`${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`),(await import(n.href)).default}async function Ve(e,t){let n=[],r=new Set,i={protectedSlotsByDirectory:new Map};for(let a of e){let e;try{e=xe(a,t);let o;if(I(a)){let t=await ze(e,a,i);for(let e of t.sources)r.add(e);n.push(t.preset);continue}if(r.add(L(e)),o=await Be(e),o==null)throw Error(`@presets "${a}" has no default export (expected a Preset or preset factory)`);n.push(typeof o==`function`?await o():o)}catch(t){throw U(t,e!==void 0&&I(a)?[...r,L(e)]:r),t}}return{presets:n,sources:Array.from(r)}}async function He(e,t){return(await Ve(e,t)).presets}function Ue(e){let t=e,n=/^url\(\s*([^)]*?)\s*\)$/i.exec(t);if(n)t=n[1];else if(/^url\(/i.test(t))return;let r=t[0];if(r===`"`||r===`'`){if(t.length<2||t[t.length-1]!==r)return;let e=t.slice(1,-1);return e.includes(r)?void 0:e}return n?t:void 0}function We(e){return!(!e||e.startsWith(`//`)||/^[a-z][\w+.-]*:/i.test(e))}function Ge(e){return e.split(`\\`).join(`/`)}function Ke(e,t,n,r){if(!We(e)||c(e)||!r&&!e.startsWith(`./`)&&!e.startsWith(`../`))return e;let i=Ge(u(n,d(t,e)));return i.startsWith(`.`)?i:`./${i}`}function qe(e,t){if(t.length===0)return e;t.sort((e,t)=>e.start-t.start);let n=``,r=0;for(let i of t)n+=e.slice(r,i.start)+i.replacement,r=i.end;return n+e.slice(r)}function Je(e,t,n){if(t===n)return e;let r=[];for(let i of D(e)){if(i.terminator!==`;`||i.name!==`presets`&&i.name!==`source`)continue;let a=i.prelude[0];if(a!==`"`&&a!==`'`||i.prelude[i.prelude.length-1]!==a)continue;if(i.name===`presets`){let e=j(i.prelude).map(e=>{let r=Ke(e,t,n,!1);if(r.includes(`,`))throw SyntaxError(`@presets: rebased module paths cannot contain commas; re-export from a path without commas`);return r});r.push({start:i.start,end:i.end,replacement:`@presets ${a}${e.join(`,`)}${a};`});continue}let o=i.prelude.slice(1,-1).trim(),s=i.name===`source`&&o.startsWith(`!`),c=s?o.slice(1):o,l=Ke(c,t,n,i.name===`source`);if(l===c)continue;let u=e.slice(i.start,i.end).replace(i.prelude,`${a}${s?`!`:``}${l}${a}`);r.push({start:i.start,end:i.end,replacement:u})}return qe(e,r)}function Ye(e,n,r,i,a,s,c,l){if(he(e,l),s>32){for(let t of D(e)){if(t.name!==`custom`||t.terminator!==`;`)continue;let n=C(e,t,l);n&&a.push(n)}return e}let u=[];for(let f of D(e)){if(f.name===`custom`&&f.terminator===`;`){let t=C(e,f,l);t&&a.push(t)}if(f.name!==`import`||f.terminator!==`;`)continue;let p=Ue(f.prelude);if(p===void 0||!We(p))continue;let m=d(n,p);if(!c?.has(m))try{if(!t.statSync(m).isFile())continue}catch{continue}if(r.has(m)){u.push({start:f.start,end:f.end,replacement:``});continue}r.add(m),i.push(m);let h=o(m),g=Ye(c?.get(m)??t.readFileSync(m,`utf8`),h,r,i,a,s+1,c,m);g=Je(g,h,n),u.push({start:f.start,end:f.end,replacement:g})}return qe(e,u)}function Xe(e,t,n,r){let i=[],a=[],o=new Set(n?[d(t,n)]:[]);try{return{css:Ye(e,t,o,i,a,0,r,n?d(t,n):void 0),files:i,aliases:a}}catch(e){throw U(e,i),e}}function G(e){return e?e.split(/\s+/)[0]===`theme`?{kind:`invalid`}:{kind:`mode`,mode:e}:{kind:`base`}}function Ze(e){let t,n=0,r=null;for(let i=0;i<e.length;i++){let a=e[i];if(r)a===`\\`?i++:a===r&&(r=null);else if(a===`"`||a===`'`)r=a;else if(a===`/`&&e[i+1]===`*`){let r=e.indexOf(`*/`,i+2),a=r<0?e.length:r+2;(t??=[]).push(e.slice(n,i),` `),n=a,i=a-1}}return t?`${t.join(``)}${e.slice(n)}`:e}function Qe(e){let t=e[0];if(t===`"`||t===`'`)for(let n=1;n<e.length;n++){let r=e[n];if(r===`\\`)n++;else if(r===t)return n===e.length-1?e.slice(1,n):void 0}}function K(e,t){let n=D(e),r=[],i={},a=[],o=[],s=[],c=[],l=!1;for(let u of n){if(u.name===`teacss`&&u.prelude===``&&u.terminator!==`block`&&(l=!0),u.terminator!==`;`)continue;if(u.name===`custom`){let n=C(e,u,t);n&&c.push({start:u.start,block:{alias:n,declarations:ae(n)}});continue}if(k.includes(u.name)){try{let e=u.name,t=j(u.prelude);i[e]=[...new Set([...i[e]??[],...t])].sort()}catch{}continue}if(u.name===`shortcut`){let e=u.prelude.search(/\s/);if(e<=0)continue;let t=u.prelude.slice(0,e);if(!/^[A-Za-z_][\w-]*$/.test(t))continue;let n=Qe(u.prelude.slice(e).trimStart())?.trim();n&&o.push({name:t,expansion:n});continue}if(u.name!==`presets`&&u.name!==`source`&&u.name!==`safelist`)continue;let n=Qe(u.prelude)?.trim();if(!n)continue;if(u.name===`presets`){try{r.push(...j(u.prelude))}catch{}continue}if(u.name===`safelist`){s.push(n);continue}let d=n.startsWith(`!`),f=d?n.slice(1):n;f&&a.push({glob:f,exclude:d})}c.push(...O(e).flatMap(({start:e,mode:t,declarations:n})=>{let r=G(t);return r.kind===`invalid`?[]:[{start:e,block:{mode:r.kind===`base`?void 0:r.mode,declarations:n.map(({property:e,value:t})=>({property:e,value:Ze(t).trim()}))}}]}));let u=c.sort((e,t)=>e.start-t.start).map(({block:e})=>e);return{presets:r,...Object.keys(i).length?{rolePalettes:i}:{},sources:a,custom:u,shortcuts:o,safelist:s,hasTeacss:l}}function $e(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function et(e){return Object.keys(e).filter(t=>{if(t===`modes`||t===`defaultMode`||t===`rolePalettes`)return!1;let n=e[t];return typeof n!=`object`||!n?!1:t===`colors`||Object.values(n).every(e=>e==null||typeof e==`string`||typeof e==`number`||Array.isArray(e))})}function q(e){return e.map(e=>({key:e,prefix:e===`colors`||e===`semanticColors`?`color`:$e(e),twoLevel:e===`colors`,semanticColor:e===`semanticColors`})).sort((e,t)=>t.prefix.length-e.prefix.length)}function J(e,t,n){Object.defineProperty(e,t,{value:n,configurable:!0,enumerable:!0,writable:!0})}function Y(e,t){let n=Object.hasOwn(e,t)?e[t]:void 0;if(typeof n==`object`&&n&&!Array.isArray(n))return n;let r={};return J(e,t,r),r}function X(e,t){let n=t.filter(t=>e===t.prefix||e.startsWith(`${t.prefix}-`)),r=n.find(e=>e.key===`colors`),i=n.find(e=>e.semanticColor);if(r&&i){let t=e===`color`?``:e.slice(6),n=t.lastIndexOf(`-`),a=n>0?t.slice(0,n):``,o=n>0?t.slice(n+1):``;return a&&re.has(o)?{ok:!0,nsKey:r.key,twoLevel:!0,rest:t,colorName:a,step:o}:a&&/^\d+$/.test(o)?{ok:!1,reason:`illegal-color-step`}:t?{ok:!0,nsKey:i.key,twoLevel:!1,rest:t}:{ok:!1,reason:`unknown-prefix`}}let a=n[0];if(!a)return{ok:!1,reason:`unknown-prefix`};let o=e===a.prefix?``:e.slice(a.prefix.length+1);if(a.twoLevel){let e=o.lastIndexOf(`-`),t=e>0?o.slice(0,e):``,n=e>0?o.slice(e+1):``;return!t||!re.has(n)?{ok:!1,reason:`illegal-color-step`}:{ok:!0,nsKey:a.key,twoLevel:!0,rest:o,colorName:t,step:n}}return{ok:!0,nsKey:a.key,twoLevel:!1,rest:o}}function Z(e,t){let n=q(t),r={},i=[],a=e=>{let t=X(e.startsWith(`--`)?e.slice(2):e,n);return t.ok||i.push(e),t},o=(e,t,n)=>{let r=Y(e,t.nsKey);t.twoLevel?J(Y(r,t.colorName),t.step,n):J(r,t.rest||`DEFAULT`,n)};for(let t of e){let e=t.mode?Y(Y(r,`modes`),t.mode):r;for(let{property:n,value:r}of t.declarations){let t=a(n);t.ok&&o(e,t,r)}}return{theme:r,unknown:i}}function Q(e,t){return e!=null&&Object.hasOwn(e,t)?e[t]:void 0}function $(e,t){let n=Q(e,t);return S.filter(e=>e!==`000`).every(e=>{let t=Q(n,e);return typeof t==`string`&&!!t.trim()&&t!==`initial`})}function tt(e,t){let n=et(t.theme),r=e.filter(e=>!e.alias),i=g(g({},t.theme),Z(r,n).theme),a=new Set([...t.aliases??[],...e.flatMap(e=>e.alias?[e.alias.name]:[])]),o=new Set(t.aliases),s=new Set(t.physicalPalettes),c=new Set([...k,`focused`]),l=[],u=[],d=(e,t)=>u.push({...e,message:`@custom: ${t}`});for(let r of e){let e=r.alias;if(!e){l.push(r);continue}let{name:u,family:f}=e,p=g(g({},t.theme),Z(l,n).theme);!c.has(u)&&(s.has(u)||o.has(u)||$(p.colors,u))&&d(e.nameRange,`${u} is already a palette or alias`),o.add(u),(u!==`focused`||f!==`primary`&&f!==`neutral`)&&(c.has(f)?d(e.familyRange,`role ${f} cannot be a target (only focused may follow primary or neutral)`):a.has(f)?d(e.familyRange,`${f} is an alias and cannot be a target`):(!$(i.colors,f)||Object.values(i.modes??{}).some(e=>!$(g(g({},i.colors??{}),Q(e,`colors`)??{}),f)))&&d(e.familyRange,`${f} must provide all 12 steps in every mode`))}if(u.length)throw new A(u);return{...Z(e,n),aliases:Object.freeze([...a])}}async function nt(e,t,n,r){let a=e.filter(e=>!e.exclude).map(e=>e.glob);if(a.length===0)return{shortcuts:[],safelist:[],files:[]};let o=e.filter(e=>e.exclude).map(e=>e.glob),s=await ee(a,{cwd:t,absolute:!0,ignore:o,expandDirectories:!1}),c=new Set(n),l=s.filter(e=>e.endsWith(`.css`)&&!c.has(e)).sort(),u=[],d=[];for(let e of l){let t;try{t=r?.get(e)??i(e,`utf8`)}catch(e){if(e.code===`ENOENT`)continue;throw e}if(!t.includes(`@shortcut`)&&!t.includes(`@safelist`))continue;let n=K(t);u.push(...n.shortcuts),d.push(...n.safelist)}return{shortcuts:u,safelist:d,files:l}}async function rt(e,t,n,r){let i=Xe(e,t,n,r),a=K(i.css),o=0;for(let e of a.custom)e.alias&&=i.aliases[o++];let[s,c]=await Promise.all([a.presets.length?Ve(a.presets,t):{presets:[],sources:[]},nt(a.sources,t,i.files,r)]).catch(e=>{throw U(e,i.files),e}),l=s.presets,u={},d=[],f=[],p=Object.freeze(Object.fromEntries(Object.entries(a.rolePalettes??{}).map(([e,t])=>[e,Object.freeze([...t])]))),m={name:`@teacss/config/role-palettes`,configResolved(e){Object.defineProperty(e,Symbol.for(`@teacss/config/role-palettes`),{value:p,configurable:!0}),Object.defineProperty(e,Symbol.for(`@teacss/config/color-aliases`),{value:f,configurable:!0})}};await _({presets:l,configResolved(e){let t=e;if({theme:u,unknown:d,aliases:f}=tt(a.custom,{theme:e.theme,physicalPalettes:t[Symbol.for(`@teacss/preset-standard/physical-palettes`)],aliases:t[Symbol.for(`@teacss/config/color-aliases`)]}),a.rolePalettes&&!e.presets.some(e=>e.name===`@teacss/preset-standard`))throw TypeError(`Role palette directives require an explicitly enabled Standard preset`);e.theme=g(e.theme,u),(a.rolePalettes||f.length)&&m.configResolved?.(e)}}).catch(e=>{throw U(e,[...i.files,...c.files,...s.sources]),e});let ee=[...a.sources.filter(e=>!e.exclude).map(e=>e.glob),...a.sources.filter(e=>e.exclude).map(e=>`!${e.glob}`)],y=[...c.shortcuts,...a.shortcuts],b=Object.fromEntries(y.map(({name:e,expansion:t})=>[e,t])),x=[...new Set([...c.safelist,...a.safelist].flatMap(e=>v(h(e))))];return{config:{presets:a.rolePalettes||f.length?[...l,m]:l,theme:u,...a.sources.length?{content:{filesystem:ee}}:{},...y.length?{shortcuts:b}:{},...x.length?{safelist:x}:{}},unknown:d,hasTeacss:i.files.length===0?a.hasTeacss:K(e).hasTeacss,sources:[...i.files,...c.files,...s.sources]}}const it=S.join(` `);function at(e,t){switch(t){case`unknown-prefix`:return`@custom var "${e}" matches no theme namespace — not registered (emitted as a plain :root var).`;case`illegal-color-step`:return`@custom var "${e}" has an illegal color step — palette steps are ${it}.`;case`removed-theme`:return`@custom ${e}: named themes were removed; use global / mode values and data-css-<role> palette selectors.`}}function ot(e,t){let n=q(t),r=[],i=O(e);for(let e of i){if(G(e.mode).kind===`invalid`){r.push({property:e.mode,start:e.start,end:e.open,reason:`removed-theme`,message:at(e.mode,`removed-theme`)});continue}for(let t of e.declarations){let{property:e,start:i,end:a}=t,o=X(e.slice(2),n);o.ok||r.push({property:e,start:i,end:a,reason:o.reason,message:at(e,o.reason)})}}return r}const st=Object.freeze([`package.json`,`index.css`,`src/index.css`]),[ct,...lt]=st;function ut(e){let t=e instanceof Error?`${e.name}:${e.message}`:`${typeof e}:${String(e)}`,r=Array.from(new Set(W(e))).sort().map(e=>{try{let t=n.statSync(e);return`${e}:${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`}catch(t){let n=t.code;return`${e}:${n===`ENOENT`?`missing`:`unreadable:${n??String(t)}`}`}});return JSON.stringify([t,r])}function dt(e,t){let n={...e};for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(t,e)?.enumerable)continue;let r=Reflect.get(t,e);r!==void 0&&Object.defineProperty(n,e,{value:r,configurable:!0,enumerable:!0,writable:!0})}return n}function ft(e){try{let t=n.readFileSync(e,`utf8`);return t.includes(`@teacss`)?D(t).some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`):!1}catch(e){if(e.code===`ENOENT`)return!1;throw e}}function pt(e){try{let t=JSON.parse(n.readFileSync(l(e,ct),`utf8`))?.teacss?.entry;return typeof t==`string`?t:void 0}catch(e){if(e.code===`ENOENT`)return;throw e}}function mt(e){let t=pt(e);if(t){let r=d(e,t);if(n.existsSync(r)&&n.statSync(r).isFile())return r}for(let t of lt){let r=l(e,t);if(n.existsSync(r)&&n.statSync(r).isFile()&&ft(r))return r}}async function ht(e=p.cwd(),t=e,r={}){if(typeof t!=`string`)return{config:dt(r,t),sources:[]};let i=d(e,t),a=n.existsSync(i)&&n.statSync(i).isFile()?i:mt(i);if(!a)return{config:{...r},sources:[]};let s;try{s=await rt(n.readFileSync(a,`utf8`),o(a),a)}catch(e){throw U(e,[a]),e}let{config:c}=s,l=dt(r,c);return c.presets?.length||(r.presets?.length?l.presets=r.presets:m.warn(`[@teacss/config] "${a}" declares no @presets — no utilities will be generated. Add one, e.g. \`@presets "standard";\``)),{config:l,sources:Array.from(new Set([a,...s.sources]))}}function gt(){let e=new Map,t=new Map,n=new Map,r=new Map,i=new WeakMap,a=new WeakMap,o=new WeakMap,s=new WeakMap,c=(e,n)=>e?t.get(e):n?a.get(n):void 0,l=(e,t)=>e?n.get(e):t?o.get(t):void 0,u=async(e,t)=>{for(;;){let n=c(e,t),r=l(e,t);if(!r)return;let i=await r;if(c(e,t)===n)return i}};return(c=p.cwd(),l=c,f={})=>{let h=typeof l==`string`?d(c,l):void 0,g=typeof l==`object`&&l?l:void 0,_=h?(t.get(h)??0)+1:g?(a.get(g)??0)+1:0;h?t.set(h,_):g&&a.set(g,_);let v=ht(c,l,f).then(n=>(h&&t.get(h)===_?(e.set(h,n),r.delete(h)):g&&a.get(g)===_&&(i.set(g,n),s.delete(g)),n),async n=>{let o=h?t.get(h)===_:!g||a.get(g)===_;if(!o){let e=await u(h,g);if(e)return e}let c=h?e.get(h):g?i.get(g):void 0;if(!c)throw n;if(o){let e=ut(n);e!==(h?r.get(h):g?s.get(g):void 0)&&(m.error(`[@teacss/config] Error resolving config from the CSS entry:`,n),h?r.set(h,e):g&&s.set(g,e));let t=Array.from(new Set([...c.sources,...W(n)]));return t.length===c.sources.length?c:{...c,sources:t}}return c});return h?n.set(h,v):g&&o.set(g,v),v}}export{A as EntryConfigError,k as ROLE_DIRECTIVES,he as assertEntryDirectives,q as buildNamespaces,X as classifyCustomVar,gt as createRecoveryConfigLoader,Z as customToTheme,ot as diagnoseCustom,me as diagnoseEntry,st as entryDiscoveryFiles,mt as findEntry,W as getConfigSourcesFromError,le as hasTopLevelDirective,ht as loadConfig,G as parseCustomPrelude,K as parseEntry,j as parseEntryList,tt as resolveCustomTheme,rt as resolveEntryConfig,He as resolvePresets,et as scaleThemeKeys,O as scanCustomBlocks,ce as scanQuotedDirectives,D as scanTopLevelAtRules};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teacss/config",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "TeaCSS config loader — discovers the CSS entry and resolves its directives into a config (no teacss.config file).",
5
5
  "homepage": "https://css.teasim.com",
6
6
  "funding": "https://github.com/sponsors/billgo",
@@ -22,7 +22,7 @@
22
22
  "dev": "tsdown --watch"
23
23
  },
24
24
  "dependencies": {
25
- "@teacss/core": "0.7.1",
25
+ "@teacss/core": "0.8.0",
26
26
  "consola": "^3.4.2",
27
27
  "jiti": "^2.7.0",
28
28
  "tinyglobby": "^0.2.17"