nitrowind 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +21 -0
  3. package/README.md +51 -2
  4. package/css.d.ts +6 -0
  5. package/dist/color.d.ts +24 -0
  6. package/dist/color.d.ts.map +1 -0
  7. package/dist/color.js +158 -0
  8. package/dist/color.js.map +1 -0
  9. package/dist/core.d.ts +121 -0
  10. package/dist/core.d.ts.map +1 -0
  11. package/dist/core.js +1026 -0
  12. package/dist/core.js.map +1 -0
  13. package/dist/css/compile.d.ts +18 -0
  14. package/dist/css/compile.d.ts.map +1 -0
  15. package/dist/css/compile.js +1018 -0
  16. package/dist/css/compile.js.map +1 -0
  17. package/dist/css/declarations.d.ts +18 -0
  18. package/dist/css/declarations.d.ts.map +1 -0
  19. package/dist/css/declarations.js +1173 -0
  20. package/dist/css/declarations.js.map +1 -0
  21. package/dist/css/index.d.ts +7 -0
  22. package/dist/css/index.d.ts.map +1 -0
  23. package/dist/css/index.js +7 -0
  24. package/dist/css/index.js.map +1 -0
  25. package/dist/css/parser.d.ts +9 -0
  26. package/dist/css/parser.d.ts.map +1 -0
  27. package/dist/css/parser.js +188 -0
  28. package/dist/css/parser.js.map +1 -0
  29. package/dist/css/tokenizer.d.ts +14 -0
  30. package/dist/css/tokenizer.d.ts.map +1 -0
  31. package/dist/css/tokenizer.js +200 -0
  32. package/dist/css/tokenizer.js.map +1 -0
  33. package/dist/css/types.d.ts +128 -0
  34. package/dist/css/types.d.ts.map +1 -0
  35. package/dist/css/types.js +19 -0
  36. package/dist/css/types.js.map +1 -0
  37. package/dist/css/values.d.ts +37 -0
  38. package/dist/css/values.d.ts.map +1 -0
  39. package/dist/css/values.js +343 -0
  40. package/dist/css/values.js.map +1 -0
  41. package/dist/environment.d.ts +5 -0
  42. package/dist/environment.d.ts.map +1 -0
  43. package/dist/environment.js +99 -0
  44. package/dist/environment.js.map +1 -0
  45. package/dist/hooks.d.ts +22 -0
  46. package/dist/hooks.d.ts.map +1 -0
  47. package/dist/hooks.js +140 -0
  48. package/dist/hooks.js.map +1 -0
  49. package/dist/index.d.ts +26 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +16 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/jsx-dev-runtime.d.ts +17 -0
  54. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  55. package/dist/jsx-dev-runtime.js +12 -0
  56. package/dist/jsx-dev-runtime.js.map +1 -0
  57. package/dist/jsx-namespace.d.ts +29 -0
  58. package/dist/jsx-namespace.d.ts.map +1 -0
  59. package/dist/jsx-namespace.js +2 -0
  60. package/dist/jsx-namespace.js.map +1 -0
  61. package/dist/jsx-runtime.d.ts +22 -0
  62. package/dist/jsx-runtime.d.ts.map +1 -0
  63. package/dist/jsx-runtime.js +21 -0
  64. package/dist/jsx-runtime.js.map +1 -0
  65. package/dist/math.d.ts +50 -0
  66. package/dist/math.d.ts.map +1 -0
  67. package/dist/math.js +442 -0
  68. package/dist/math.js.map +1 -0
  69. package/dist/plugin.d.ts +45 -0
  70. package/dist/plugin.d.ts.map +1 -0
  71. package/dist/plugin.js +172 -0
  72. package/dist/plugin.js.map +1 -0
  73. package/dist/props.d.ts +29 -0
  74. package/dist/props.d.ts.map +1 -0
  75. package/dist/props.js +163 -0
  76. package/dist/props.js.map +1 -0
  77. package/dist/scope.d.ts +99 -0
  78. package/dist/scope.d.ts.map +1 -0
  79. package/dist/scope.js +228 -0
  80. package/dist/scope.js.map +1 -0
  81. package/dist/store.d.ts +18 -0
  82. package/dist/store.d.ts.map +1 -0
  83. package/dist/store.js +244 -0
  84. package/dist/store.js.map +1 -0
  85. package/dist/tokens/index.d.ts +12 -0
  86. package/dist/tokens/index.d.ts.map +1 -0
  87. package/dist/tokens/index.js +237 -0
  88. package/dist/tokens/index.js.map +1 -0
  89. package/dist/tokens/tailwind.generated.d.ts +3 -0
  90. package/dist/tokens/tailwind.generated.d.ts.map +1 -0
  91. package/dist/tokens/tailwind.generated.js +610 -0
  92. package/dist/tokens/tailwind.generated.js.map +1 -0
  93. package/dist/tokens/types.d.ts +95 -0
  94. package/dist/tokens/types.d.ts.map +1 -0
  95. package/dist/tokens/types.js +2 -0
  96. package/dist/tokens/types.js.map +1 -0
  97. package/dist/transform.d.ts +22 -0
  98. package/dist/transform.d.ts.map +1 -0
  99. package/dist/transform.js +79 -0
  100. package/dist/transform.js.map +1 -0
  101. package/dist/transition.d.ts +7 -0
  102. package/dist/transition.d.ts.map +1 -0
  103. package/dist/transition.js +355 -0
  104. package/dist/transition.js.map +1 -0
  105. package/dist/types.d.ts +214 -0
  106. package/dist/types.d.ts.map +1 -0
  107. package/dist/types.js +2 -0
  108. package/dist/types.js.map +1 -0
  109. package/dist/utilities.d.ts +109 -0
  110. package/dist/utilities.d.ts.map +1 -0
  111. package/dist/utilities.js +2000 -0
  112. package/dist/utilities.js.map +1 -0
  113. package/dist/variables.d.ts +65 -0
  114. package/dist/variables.d.ts.map +1 -0
  115. package/dist/variables.js +408 -0
  116. package/dist/variables.js.map +1 -0
  117. package/dist/version.d.ts +3 -0
  118. package/dist/version.d.ts.map +1 -0
  119. package/dist/version.js +3 -0
  120. package/dist/version.js.map +1 -0
  121. package/dist/withNitroWind.d.ts +11 -0
  122. package/dist/withNitroWind.d.ts.map +1 -0
  123. package/dist/withNitroWind.js +27 -0
  124. package/dist/withNitroWind.js.map +1 -0
  125. package/package.json +89 -4
  126. package/src/color.ts +164 -0
  127. package/src/core.ts +1248 -0
  128. package/src/css/compile.ts +1198 -0
  129. package/src/css/declarations.ts +1141 -0
  130. package/src/css/index.ts +22 -0
  131. package/src/css/parser.ts +196 -0
  132. package/src/css/tokenizer.ts +227 -0
  133. package/src/css/types.ts +178 -0
  134. package/src/css/values.ts +330 -0
  135. package/src/environment.ts +112 -0
  136. package/src/hooks.ts +190 -0
  137. package/src/index.ts +61 -0
  138. package/src/jsx-dev-runtime.ts +43 -0
  139. package/src/jsx-namespace.ts +23 -0
  140. package/src/jsx-runtime.ts +39 -0
  141. package/src/math.ts +488 -0
  142. package/src/plugin.ts +230 -0
  143. package/src/props.ts +173 -0
  144. package/src/scope.ts +331 -0
  145. package/src/store.ts +288 -0
  146. package/src/tokens/index.ts +252 -0
  147. package/src/tokens/tailwind.generated.ts +613 -0
  148. package/src/tokens/types.ts +99 -0
  149. package/src/transform.ts +115 -0
  150. package/src/transition.ts +414 -0
  151. package/src/types.ts +248 -0
  152. package/src/utilities.ts +1992 -0
  153. package/src/variables.ts +509 -0
  154. package/src/version.ts +2 -0
  155. package/src/withNitroWind.ts +36 -0
@@ -0,0 +1,1018 @@
1
+ import { tailwindTokens } from '../tokens/tailwind.generated';
2
+ import { hasVarCall } from '../variables';
3
+ import { validateRawDeclaration } from './declarations';
4
+ import { parseStylesheet } from './parser';
5
+ import { CSSParseError, } from './types';
6
+ import { parseCSSBoxShadows, parseCSSBreakpoint, parseCSSColor, parseCSSDropShadows, parseCSSFontWeight, parseCSSLength, parseCSSLengthOrPercent, parseCSSLineHeight, parseCSSRatio, parseImportSpecifier, resolveRelativeImportKey, } from './values';
7
+ const PRESET_IMPORTS = new Set(['tailwindcss', 'nitrowind', 'uniwind']);
8
+ const ALL_TOKEN_NAMESPACES = [
9
+ 'colors',
10
+ 'fontSize',
11
+ 'fontWeight',
12
+ 'leading',
13
+ 'radius',
14
+ 'shadow',
15
+ 'insetShadow',
16
+ 'dropShadow',
17
+ 'container',
18
+ 'aspect',
19
+ 'breakpoints',
20
+ 'spacingScale',
21
+ ];
22
+ /** Ordered longest-prefix first so `--inset-shadow-` matches before `--shadow-`, etc. */
23
+ const TOKEN_PREFIXES = [
24
+ { prefix: '--inset-shadow-', namespace: 'insetShadow' },
25
+ { prefix: '--drop-shadow-', namespace: 'dropShadow' },
26
+ { prefix: '--font-weight-', namespace: 'fontWeight' },
27
+ { prefix: '--breakpoint-', namespace: 'breakpoints' },
28
+ { prefix: '--container-', namespace: 'container' },
29
+ { prefix: '--spacing-', namespace: 'spacingScale' },
30
+ { prefix: '--leading-', namespace: 'leading' },
31
+ { prefix: '--shadow-', namespace: 'shadow' },
32
+ { prefix: '--radius-', namespace: 'radius' },
33
+ { prefix: '--aspect-', namespace: 'aspect' },
34
+ { prefix: '--color-', namespace: 'colors' },
35
+ { prefix: '--text-', namespace: 'fontSize' },
36
+ ];
37
+ function matchTokenVariable(name) {
38
+ if (!name.startsWith('--'))
39
+ return null;
40
+ for (const { prefix, namespace } of TOKEN_PREFIXES) {
41
+ if (!name.startsWith(prefix))
42
+ continue;
43
+ const suffix = name.slice(prefix.length);
44
+ if (!suffix)
45
+ return null;
46
+ if (namespace === 'fontSize') {
47
+ if (suffix.startsWith('shadow-'))
48
+ return null;
49
+ if (suffix.endsWith('--line-height')) {
50
+ const sizeKey = suffix.slice(0, -'--line-height'.length);
51
+ return sizeKey ? { namespace: 'fontSize', key: sizeKey, lineHeightFor: sizeKey } : null;
52
+ }
53
+ if (suffix.includes('--'))
54
+ return null;
55
+ }
56
+ return { namespace, key: suffix };
57
+ }
58
+ return null;
59
+ }
60
+ function getNamespaceBucket(state, namespace) {
61
+ switch (namespace) {
62
+ case 'colors':
63
+ return state.colors;
64
+ case 'fontSize':
65
+ return state.fontSize;
66
+ case 'fontWeight':
67
+ return state.fontWeight;
68
+ case 'leading':
69
+ return state.leading;
70
+ case 'radius':
71
+ return state.radius;
72
+ case 'shadow':
73
+ return state.shadow;
74
+ case 'insetShadow':
75
+ return state.insetShadow;
76
+ case 'dropShadow':
77
+ return state.dropShadow;
78
+ case 'container':
79
+ return state.container;
80
+ case 'aspect':
81
+ return state.aspect;
82
+ case 'breakpoints':
83
+ return state.breakpoints;
84
+ case 'spacingScale':
85
+ return state.spacingScale;
86
+ }
87
+ }
88
+ function deleteVariablesForPrefix(variables, varPrefix) {
89
+ for (const key of Object.keys(variables)) {
90
+ if (key.startsWith(varPrefix))
91
+ delete variables[key];
92
+ }
93
+ }
94
+ function clearNamespace(state, namespace, varPrefix) {
95
+ state.resetNamespaces.add(namespace);
96
+ state.resetKeys.delete(namespace);
97
+ state.resetPrefixes.delete(namespace);
98
+ const bucket = getNamespaceBucket(state, namespace);
99
+ for (const key of Object.keys(bucket))
100
+ delete bucket[key];
101
+ if (namespace === 'fontSize') {
102
+ state.inlineLineHeights.clear();
103
+ state.varLineHeights.clear();
104
+ }
105
+ if (varPrefix !== undefined) {
106
+ deleteVariablesForPrefix(state.variables, varPrefix);
107
+ }
108
+ }
109
+ function clearNamespacePrefix(state, namespace, keyPrefix, varPrefix) {
110
+ let set = state.resetPrefixes.get(namespace);
111
+ if (set === undefined) {
112
+ set = new Set();
113
+ state.resetPrefixes.set(namespace, set);
114
+ }
115
+ set.add(keyPrefix);
116
+ const bucket = getNamespaceBucket(state, namespace);
117
+ for (const key of Object.keys(bucket)) {
118
+ if (key.startsWith(keyPrefix))
119
+ delete bucket[key];
120
+ }
121
+ deleteVariablesForPrefix(state.variables, varPrefix);
122
+ }
123
+ function clearNamespaceKey(state, namespace, key, varName) {
124
+ let set = state.resetKeys.get(namespace);
125
+ if (set === undefined) {
126
+ set = new Set();
127
+ state.resetKeys.set(namespace, set);
128
+ }
129
+ set.add(key);
130
+ const bucket = getNamespaceBucket(state, namespace);
131
+ delete bucket[key];
132
+ if (namespace === 'fontSize') {
133
+ state.inlineLineHeights.delete(key);
134
+ state.varLineHeights.delete(key);
135
+ }
136
+ delete state.variables[varName];
137
+ }
138
+ function unmarkResetKey(state, namespace, key) {
139
+ state.resetKeys.get(namespace)?.delete(key);
140
+ }
141
+ function applyInitialReset(state, property, location) {
142
+ if (property === '--*') {
143
+ for (const ns of ALL_TOKEN_NAMESPACES) {
144
+ clearNamespace(state, ns);
145
+ }
146
+ for (const spec of TOKEN_PREFIXES) {
147
+ deleteVariablesForPrefix(state.variables, spec.prefix);
148
+ }
149
+ return true;
150
+ }
151
+ for (const { prefix, namespace } of TOKEN_PREFIXES) {
152
+ if (!property.startsWith(prefix))
153
+ continue;
154
+ const suffix = property.slice(prefix.length);
155
+ if (suffix === '*') {
156
+ clearNamespace(state, namespace, prefix);
157
+ return true;
158
+ }
159
+ if (suffix.endsWith('-*')) {
160
+ const keyPrefix = suffix.slice(0, -1); // e.g. 'red-'
161
+ clearNamespacePrefix(state, namespace, keyPrefix, `${prefix}${keyPrefix}`);
162
+ return true;
163
+ }
164
+ if (namespace === 'fontSize' && suffix.startsWith('shadow-'))
165
+ return false;
166
+ if (namespace === 'fontSize' && suffix.endsWith('--line-height')) {
167
+ const sizeKey = suffix.slice(0, -'--line-height'.length);
168
+ if (!sizeKey)
169
+ return false;
170
+ state.inlineLineHeights.delete(sizeKey);
171
+ state.varLineHeights.delete(sizeKey);
172
+ delete state.variables[property];
173
+ const existing = state.fontSize[sizeKey];
174
+ if (existing && typeof existing === 'object') {
175
+ state.fontSize[sizeKey] = { fontSize: existing.fontSize };
176
+ }
177
+ return true;
178
+ }
179
+ clearNamespaceKey(state, namespace, suffix, property);
180
+ return true;
181
+ }
182
+ state.warn('unsupported-declaration', `Unsupported initial reset "${property}: initial"`, location);
183
+ return true;
184
+ }
185
+ function registerVarBackedToken(state, property, value, location, fromVariant = false) {
186
+ if (property === '--spacing') {
187
+ state.spacing = 'var(--spacing)';
188
+ return;
189
+ }
190
+ const matched = matchTokenVariable(property);
191
+ if (matched === null)
192
+ return;
193
+ const { namespace, key, lineHeightFor } = matched;
194
+ unmarkResetKey(state, namespace, key);
195
+ if (namespace === 'breakpoints') {
196
+ if (fromVariant) {
197
+ state.warn('unsupported-declaration', `Breakpoint "${property}" cannot be scoped to @variant; declare it in @theme or :root`, location);
198
+ return;
199
+ }
200
+ const bp = parseCSSBreakpoint(value);
201
+ if (bp === null) {
202
+ state.warn('invalid-token-value', `Invalid breakpoint length "${value}" for "${property}"`, location);
203
+ return;
204
+ }
205
+ state.breakpoints[key] = bp;
206
+ return;
207
+ }
208
+ if (namespace === 'fontSize') {
209
+ if (lineHeightFor !== undefined) {
210
+ state.varLineHeights.add(lineHeightFor);
211
+ state.inlineLineHeights.delete(lineHeightFor);
212
+ const existing = state.fontSize[lineHeightFor];
213
+ if (existing !== undefined) {
214
+ const fontSize = typeof existing === 'string' ? existing : existing.fontSize;
215
+ state.fontSize[lineHeightFor] = { fontSize, lineHeight: `var(${property})` };
216
+ }
217
+ else if (!state.resetNamespaces.has('fontSize') && !state.resetKeys.get('fontSize')?.has(lineHeightFor)) {
218
+ const fallback = tailwindTokens.fontSize[lineHeightFor];
219
+ if (fallback !== undefined) {
220
+ const fontSize = typeof fallback === 'string' ? fallback : fallback.fontSize;
221
+ state.fontSize[lineHeightFor] = { fontSize, lineHeight: `var(${property})` };
222
+ }
223
+ }
224
+ return;
225
+ }
226
+ state.inlineLineHeights.delete(key);
227
+ const lhVar = `--text-${key}--line-height`;
228
+ if (state.varLineHeights.has(key)) {
229
+ state.fontSize[key] = { fontSize: `var(${property})`, lineHeight: `var(${lhVar})` };
230
+ }
231
+ else {
232
+ state.fontSize[key] = `var(${property})`;
233
+ }
234
+ return;
235
+ }
236
+ const bucket = getNamespaceBucket(state, namespace);
237
+ bucket[key] = `var(${property})`;
238
+ }
239
+ function registerInlineToken(state, property, value, location) {
240
+ const isVarExpr = hasVarCall(value);
241
+ if (property === '--spacing') {
242
+ if (isVarExpr) {
243
+ state.spacing = value;
244
+ return;
245
+ }
246
+ const len = parseCSSLength(value);
247
+ if (len === null) {
248
+ state.warn('invalid-token-value', `Invalid spacing value "${value}" for "--spacing"`, location);
249
+ return;
250
+ }
251
+ state.spacing = len;
252
+ return;
253
+ }
254
+ const matched = matchTokenVariable(property);
255
+ if (matched === null)
256
+ return;
257
+ const { namespace, key, lineHeightFor } = matched;
258
+ unmarkResetKey(state, namespace, key);
259
+ if (namespace === 'fontSize' && lineHeightFor !== undefined) {
260
+ state.varLineHeights.delete(lineHeightFor);
261
+ state.inlineLineHeights.set(lineHeightFor, { raw: value, location });
262
+ return;
263
+ }
264
+ if (isVarExpr && namespace !== 'breakpoints') {
265
+ if (namespace === 'fontSize') {
266
+ state.varLineHeights.delete(key);
267
+ state.fontSize[key] = value;
268
+ }
269
+ else {
270
+ getNamespaceBucket(state, namespace)[key] = value;
271
+ }
272
+ return;
273
+ }
274
+ switch (namespace) {
275
+ case 'colors': {
276
+ const color = parseCSSColor(value);
277
+ if (color === null) {
278
+ state.warn('invalid-token-value', `Invalid color "${value}" for "${property}"`, location);
279
+ return;
280
+ }
281
+ state.colors[key] = color;
282
+ return;
283
+ }
284
+ case 'fontSize': {
285
+ const len = parseCSSLength(value);
286
+ if (len === null) {
287
+ state.warn('invalid-token-value', `Invalid font size "${value}" for "${property}"`, location);
288
+ return;
289
+ }
290
+ state.varLineHeights.delete(key);
291
+ state.fontSize[key] = { fontSize: len };
292
+ return;
293
+ }
294
+ case 'fontWeight': {
295
+ const weight = parseCSSFontWeight(value);
296
+ if (weight === null) {
297
+ state.warn('invalid-token-value', `Invalid font weight "${value}" for "${property}"`, location);
298
+ return;
299
+ }
300
+ state.fontWeight[key] = weight;
301
+ return;
302
+ }
303
+ case 'leading': {
304
+ const lh = parseCSSLineHeight(value);
305
+ if (lh === null) {
306
+ state.warn('invalid-token-value', `Invalid line height "${value}" for "${property}"`, location);
307
+ return;
308
+ }
309
+ state.leading[key] = lh.kind === 'points' ? { points: lh.value } : lh.value;
310
+ return;
311
+ }
312
+ case 'radius': {
313
+ const len = parseCSSLength(value);
314
+ if (len === null) {
315
+ state.warn('invalid-token-value', `Invalid radius "${value}" for "${property}"`, location);
316
+ return;
317
+ }
318
+ state.radius[key] = len;
319
+ return;
320
+ }
321
+ case 'spacingScale': {
322
+ const len = parseCSSLengthOrPercent(value);
323
+ if (len === null) {
324
+ state.warn('invalid-token-value', `Invalid spacing "${value}" for "${property}"`, location);
325
+ return;
326
+ }
327
+ state.spacingScale[key] = len;
328
+ return;
329
+ }
330
+ case 'shadow': {
331
+ const shadows = parseCSSBoxShadows(value, false);
332
+ if (shadows === null) {
333
+ state.warn('invalid-token-value', `Invalid box-shadow "${value}" for "${property}"`, location);
334
+ return;
335
+ }
336
+ state.shadow[key] = shadows;
337
+ return;
338
+ }
339
+ case 'insetShadow': {
340
+ const shadows = parseCSSBoxShadows(value, true);
341
+ if (shadows === null) {
342
+ state.warn('invalid-token-value', `Invalid inset box-shadow "${value}" for "${property}"`, location);
343
+ return;
344
+ }
345
+ state.insetShadow[key] = shadows;
346
+ return;
347
+ }
348
+ case 'dropShadow': {
349
+ const shadows = parseCSSDropShadows(value);
350
+ if (shadows === null) {
351
+ state.warn('invalid-token-value', `Invalid drop-shadow "${value}" for "${property}"`, location);
352
+ return;
353
+ }
354
+ state.dropShadow[key] = shadows;
355
+ return;
356
+ }
357
+ case 'container': {
358
+ const len = parseCSSLength(value);
359
+ if (len === null) {
360
+ state.warn('invalid-token-value', `Invalid container width "${value}" for "${property}"`, location);
361
+ return;
362
+ }
363
+ state.container[key] = len;
364
+ return;
365
+ }
366
+ case 'aspect': {
367
+ const ratio = parseCSSRatio(value);
368
+ if (ratio === null) {
369
+ state.warn('invalid-token-value', `Invalid aspect ratio "${value}" for "${property}"`, location);
370
+ return;
371
+ }
372
+ state.aspect[key] = ratio;
373
+ return;
374
+ }
375
+ case 'breakpoints': {
376
+ const bp = parseCSSBreakpoint(value);
377
+ if (bp === null) {
378
+ state.warn('invalid-token-value', `Invalid breakpoint length "${value}" for "${property}"`, location);
379
+ return;
380
+ }
381
+ state.breakpoints[key] = bp;
382
+ return;
383
+ }
384
+ }
385
+ }
386
+ function compileThemeBlock(state, node) {
387
+ const mode = node.prelude.trim().toLowerCase();
388
+ const isInline = mode === 'inline';
389
+ if (mode !== '' && !isInline) {
390
+ state.warn('unsupported-at-rule', `Unsupported @theme modifier "${node.prelude}"`, node.location);
391
+ return;
392
+ }
393
+ if (!node.nodes) {
394
+ state.warn('unsupported-at-rule', 'Expected "{ ... }" block for @theme', node.location);
395
+ return;
396
+ }
397
+ for (const child of node.nodes) {
398
+ if (child.kind !== 'declaration') {
399
+ state.warn(child.kind === 'at-rule' ? 'unsupported-at-rule' : 'unsupported-rule', `Unexpected ${child.kind === 'at-rule' ? `@${child.name}` : child.selector} inside @theme`, child.location);
400
+ continue;
401
+ }
402
+ compileThemeDeclaration(state, child, isInline);
403
+ }
404
+ }
405
+ function compileThemeDeclaration(state, decl, isInline) {
406
+ const { property, value, location } = decl;
407
+ if (!property.startsWith('--')) {
408
+ state.warn('unsupported-declaration', `Expected CSS variable ("--*") inside @theme, got "${property}"`, location);
409
+ return;
410
+ }
411
+ if (value.trim().toLowerCase() === 'initial') {
412
+ applyInitialReset(state, property, location);
413
+ return;
414
+ }
415
+ if (isInline) {
416
+ registerInlineToken(state, property, value, location);
417
+ return;
418
+ }
419
+ state.variables[property] = value;
420
+ registerVarBackedToken(state, property, value, location);
421
+ }
422
+ function compileImport(state, node, currentFile, options) {
423
+ const specifier = parseImportSpecifier(node.prelude);
424
+ if (specifier === null) {
425
+ state.warn('unresolved-import', `Invalid @import specifier "${node.prelude}"`, node.location);
426
+ return;
427
+ }
428
+ if (PRESET_IMPORTS.has(specifier)) {
429
+ state.imports.push(specifier);
430
+ return;
431
+ }
432
+ const isRelative = specifier.startsWith('./') || specifier.startsWith('../');
433
+ if (!options.resolveImport) {
434
+ const hint = isRelative
435
+ ? `Relative @import "${specifier}" cannot be resolved without a "resolveImport" hook or the "nitrowind/plugin" bundler plugin`
436
+ : `Unsupported @import "${specifier}"`;
437
+ state.warn('unresolved-import', hint, node.location);
438
+ return;
439
+ }
440
+ const resolved = options.resolveImport(specifier, currentFile);
441
+ const importedCss = typeof resolved === 'string' ? resolved : resolved.css;
442
+ const importedFile = typeof resolved === 'string'
443
+ ? resolveRelativeImportKey(specifier, currentFile)
444
+ : (resolved.filename ?? resolveRelativeImportKey(specifier, currentFile));
445
+ if (state.importStack.includes(importedFile)) {
446
+ const chain = [...state.importStack, importedFile].join(' -> ');
447
+ throw new CSSParseError(`Circular @import detected: ${chain}`, node.location);
448
+ }
449
+ state.imports.push(specifier);
450
+ state.importStack.push(importedFile);
451
+ try {
452
+ const ast = parseStylesheet(importedCss, { filename: importedFile });
453
+ compileNodes(state, ast.nodes, importedFile, options);
454
+ }
455
+ finally {
456
+ state.importStack.pop();
457
+ }
458
+ }
459
+ function compileVariantBlock(state, node) {
460
+ const themeName = node.prelude.trim();
461
+ if (!themeName || /[\s:[\]]/.test(themeName)) {
462
+ throw new CSSParseError(`Invalid theme name "${themeName}" in @variant`, node.location);
463
+ }
464
+ if (!node.nodes) {
465
+ state.warn('unsupported-at-rule', `Expected "{ ... }" block for @variant ${themeName}`, node.location);
466
+ return;
467
+ }
468
+ let entry = state.themes[themeName];
469
+ if (entry === undefined) {
470
+ entry = {
471
+ colorScheme: themeName === 'light' ? 'light' : themeName === 'dark' ? 'dark' : undefined,
472
+ variables: {},
473
+ location: node.location,
474
+ };
475
+ state.themes[themeName] = entry;
476
+ }
477
+ for (const child of node.nodes) {
478
+ if (child.kind !== 'declaration') {
479
+ state.warn(child.kind === 'at-rule' ? 'unsupported-at-rule' : 'unsupported-rule', `Unexpected ${child.kind === 'at-rule' ? `@${child.name}` : child.selector} inside @variant ${themeName}`, child.location);
480
+ continue;
481
+ }
482
+ const propLower = child.property.toLowerCase();
483
+ if (propLower === 'color-scheme') {
484
+ const scheme = child.value.trim().toLowerCase();
485
+ if (scheme !== 'light' && scheme !== 'dark') {
486
+ throw new CSSParseError(`Invalid color-scheme "${child.value}" for @variant ${themeName}; expected "light" or "dark"`, child.location);
487
+ }
488
+ if (themeName === 'light' && scheme !== 'light') {
489
+ throw new CSSParseError('Built-in theme "light" must have color-scheme "light"', child.location);
490
+ }
491
+ if (themeName === 'dark' && scheme !== 'dark') {
492
+ throw new CSSParseError('Built-in theme "dark" must have color-scheme "dark"', child.location);
493
+ }
494
+ entry.colorScheme = scheme;
495
+ continue;
496
+ }
497
+ if (!child.property.startsWith('--')) {
498
+ state.warn('unsupported-declaration', `Unsupported property "${child.property}" inside @variant ${themeName}`, child.location);
499
+ continue;
500
+ }
501
+ entry.variables[child.property] = child.value;
502
+ if (!state.themeVarLocations.has(child.property)) {
503
+ state.themeVarLocations.set(child.property, child.location);
504
+ }
505
+ registerVarBackedToken(state, child.property, child.value, child.location, true);
506
+ }
507
+ }
508
+ function compileRootRule(state, rule) {
509
+ for (const child of rule.nodes) {
510
+ if (child.kind === 'at-rule' && child.name === 'variant') {
511
+ compileVariantBlock(state, child);
512
+ continue;
513
+ }
514
+ if (child.kind === 'declaration') {
515
+ if (!child.property.startsWith('--')) {
516
+ state.warn('unsupported-declaration', `Unsupported property "${child.property}" inside :root`, child.location);
517
+ continue;
518
+ }
519
+ state.variables[child.property] = child.value;
520
+ registerVarBackedToken(state, child.property, child.value, child.location);
521
+ continue;
522
+ }
523
+ state.warn(child.kind === 'at-rule' ? 'unsupported-at-rule' : 'unsupported-rule', `Unexpected ${child.kind === 'at-rule' ? `@${child.name}` : child.selector} inside :root`, child.location);
524
+ }
525
+ }
526
+ const CLASS_SELECTOR_RE = /^\.(-?[A-Za-z_][A-Za-z0-9_-]*)$/;
527
+ const UTILITY_NAME_RE = /^-?[A-Za-z0-9_][A-Za-z0-9_-]*$/;
528
+ function extractBareClassName(rawToken) {
529
+ let bracketDepth = 0;
530
+ let parenDepth = 0;
531
+ let start = 0;
532
+ for (let i = 0; i < rawToken.length; i++) {
533
+ const ch = rawToken[i];
534
+ if (ch === '[')
535
+ bracketDepth++;
536
+ else if (ch === ']')
537
+ bracketDepth = Math.max(0, bracketDepth - 1);
538
+ else if (ch === '(')
539
+ parenDepth++;
540
+ else if (ch === ')')
541
+ parenDepth = Math.max(0, parenDepth - 1);
542
+ else if (ch === ':' && bracketDepth === 0 && parenDepth === 0) {
543
+ start = i + 1;
544
+ }
545
+ }
546
+ let bare = rawToken.slice(start);
547
+ if (bare.startsWith('!'))
548
+ bare = bare.slice(1);
549
+ else if (bare.endsWith('!'))
550
+ bare = bare.slice(0, -1);
551
+ return bare;
552
+ }
553
+ function compileCustomClassBody(state, nodes, applyLocations) {
554
+ const entries = [];
555
+ for (const child of nodes) {
556
+ if (child.kind === 'at-rule') {
557
+ if (child.name === 'apply') {
558
+ if (child.nodes !== undefined) {
559
+ state.warn('unsupported-at-rule', 'Unexpected "{ ... }" block on @apply', child.location);
560
+ continue;
561
+ }
562
+ const classes = child.prelude.split(/\s+/).filter(Boolean);
563
+ if (classes.length === 0)
564
+ continue;
565
+ for (const cls of classes) {
566
+ const target = extractBareClassName(cls);
567
+ if (target && !applyLocations.has(target)) {
568
+ applyLocations.set(target, child.location);
569
+ }
570
+ }
571
+ entries.push({ kind: 'apply', classes });
572
+ continue;
573
+ }
574
+ if (child.name === 'variant') {
575
+ const variant = child.prelude.trim();
576
+ if (!variant || /[\s:]/.test(variant)) {
577
+ state.warn('unsupported-at-rule', `Unsupported @variant "${child.prelude}"`, child.location);
578
+ continue;
579
+ }
580
+ if (!child.nodes) {
581
+ state.warn('unsupported-at-rule', `Expected "{ ... }" block for @variant ${variant}`, child.location);
582
+ continue;
583
+ }
584
+ const nested = compileCustomClassBody(state, child.nodes, applyLocations);
585
+ if (nested.length > 0) {
586
+ entries.push({ kind: 'variant', variant, entries: nested });
587
+ }
588
+ continue;
589
+ }
590
+ state.warn('unsupported-at-rule', `Unsupported at-rule "@${child.name}" inside custom class`, child.location);
591
+ continue;
592
+ }
593
+ if (child.kind === 'rule') {
594
+ state.warn('unsupported-rule', `Unsupported nested selector "${child.selector}"`, child.location);
595
+ continue;
596
+ }
597
+ const validated = validateRawDeclaration(child.property, child.value);
598
+ if (!validated.ok) {
599
+ state.warn('unsupported-declaration', validated.reason, child.location);
600
+ continue;
601
+ }
602
+ if (!validated.noop) {
603
+ entries.push({
604
+ kind: 'declaration',
605
+ property: child.property.toLowerCase(),
606
+ value: child.value.trim(),
607
+ });
608
+ }
609
+ }
610
+ return entries;
611
+ }
612
+ function registerCustomClass(state, className, rank, entries, applyLocations) {
613
+ let target = state.customClasses[className];
614
+ if (target === undefined) {
615
+ target = { rank, entries: [], applyLocations: new Map() };
616
+ state.customClasses[className] = target;
617
+ }
618
+ else if (rank === 'utility') {
619
+ target.rank = 'utility';
620
+ }
621
+ for (const entry of entries) {
622
+ target.entries.push(entry);
623
+ }
624
+ for (const [applied, loc] of applyLocations) {
625
+ if (!target.applyLocations.has(applied)) {
626
+ target.applyLocations.set(applied, loc);
627
+ }
628
+ }
629
+ }
630
+ function compileCustomClassRule(state, rule, rank) {
631
+ const parts = rule.selector
632
+ .split(',')
633
+ .map((part) => part.trim())
634
+ .filter(Boolean);
635
+ const validNames = [];
636
+ for (const part of parts) {
637
+ const match = CLASS_SELECTOR_RE.exec(part);
638
+ if (match) {
639
+ validNames.push(match[1]);
640
+ }
641
+ else {
642
+ state.warn('unsupported-rule', `Unsupported selector "${part}"`, rule.location);
643
+ }
644
+ }
645
+ if (validNames.length === 0)
646
+ return;
647
+ const applyLocations = new Map();
648
+ const compiled = compileCustomClassBody(state, rule.nodes, applyLocations);
649
+ for (const name of validNames) {
650
+ registerCustomClass(state, name, rank, compiled, applyLocations);
651
+ }
652
+ }
653
+ function compileUtilityBlock(state, node) {
654
+ const name = node.prelude.trim();
655
+ if (!UTILITY_NAME_RE.test(name)) {
656
+ state.warn('unsupported-at-rule', `Unsupported @utility name "${node.prelude}"`, node.location);
657
+ return;
658
+ }
659
+ if (!node.nodes) {
660
+ state.warn('unsupported-at-rule', `Expected "{ ... }" block for @utility ${name}`, node.location);
661
+ return;
662
+ }
663
+ const applyLocations = new Map();
664
+ const compiled = compileCustomClassBody(state, node.nodes, applyLocations);
665
+ registerCustomClass(state, name, 'utility', compiled, applyLocations);
666
+ }
667
+ function collectApplyTargets(entries, out) {
668
+ for (const entry of entries) {
669
+ if (entry.kind === 'apply') {
670
+ for (const cls of entry.classes) {
671
+ const bare = extractBareClassName(cls);
672
+ if (bare)
673
+ out.add(bare);
674
+ }
675
+ }
676
+ else if (entry.kind === 'variant') {
677
+ collectApplyTargets(entry.entries, out);
678
+ }
679
+ }
680
+ }
681
+ /**
682
+ * Validates that no custom class transitively `@apply`s itself.
683
+ * Throws `CSSParseError` (with source location when available) on the first cycle found.
684
+ */
685
+ export function detectCustomClassCycles(customClasses, applyLocations) {
686
+ const state = new Map();
687
+ const stack = [];
688
+ const visit = (name) => {
689
+ state.set(name, 'visiting');
690
+ stack.push(name);
691
+ const def = customClasses[name];
692
+ if (def !== undefined) {
693
+ const targets = new Set();
694
+ collectApplyTargets(def.entries, targets);
695
+ for (const target of targets) {
696
+ if (!Object.prototype.hasOwnProperty.call(customClasses, target))
697
+ continue;
698
+ const targetState = state.get(target);
699
+ if (targetState === 'visiting') {
700
+ const cycleStart = stack.indexOf(target);
701
+ const chain = [...stack.slice(cycleStart), target].join(' -> ');
702
+ const loc = applyLocations?.[name]?.get(target) ?? { line: 1, column: 1 };
703
+ throw new CSSParseError(`Circular @apply detected: ${chain}`, loc);
704
+ }
705
+ if (targetState === undefined) {
706
+ visit(target);
707
+ }
708
+ }
709
+ }
710
+ stack.pop();
711
+ state.set(name, 'done');
712
+ };
713
+ for (const name of Object.keys(customClasses)) {
714
+ if (state.get(name) === undefined)
715
+ visit(name);
716
+ }
717
+ }
718
+ function compileLayerBlock(state, node) {
719
+ const layerName = node.prelude.trim().toLowerCase();
720
+ if (layerName === 'components' || layerName === 'utilities') {
721
+ if (!node.nodes) {
722
+ state.warn('unsupported-at-rule', `Expected "{ ... }" block for @layer ${layerName}`, node.location);
723
+ return;
724
+ }
725
+ const rank = layerName === 'utilities' ? 'utility' : 'component';
726
+ for (const child of node.nodes) {
727
+ if (child.kind === 'rule') {
728
+ compileCustomClassRule(state, child, rank);
729
+ continue;
730
+ }
731
+ if (child.kind === 'at-rule' && child.name === 'utility') {
732
+ compileUtilityBlock(state, child);
733
+ continue;
734
+ }
735
+ state.warn(child.kind === 'at-rule' ? 'unsupported-at-rule' : 'unsupported-declaration', `Unexpected ${child.kind === 'at-rule' ? `@${child.name}` : child.property} inside @layer ${layerName}`, child.location);
736
+ }
737
+ return;
738
+ }
739
+ if (layerName !== 'theme') {
740
+ state.warn('unsupported-at-rule', `Unsupported @layer "${node.prelude}"`, node.location);
741
+ return;
742
+ }
743
+ if (!node.nodes) {
744
+ state.warn('unsupported-at-rule', 'Expected "{ ... }" block for @layer theme', node.location);
745
+ return;
746
+ }
747
+ for (const child of node.nodes) {
748
+ if (child.kind === 'rule' && child.selector.trim() === ':root') {
749
+ compileRootRule(state, child);
750
+ continue;
751
+ }
752
+ if (child.kind === 'at-rule' && child.name === 'variant') {
753
+ compileVariantBlock(state, child);
754
+ continue;
755
+ }
756
+ state.warn(child.kind === 'at-rule'
757
+ ? 'unsupported-at-rule'
758
+ : child.kind === 'rule'
759
+ ? 'unsupported-rule'
760
+ : 'unsupported-declaration', `Unexpected ${child.kind === 'at-rule' ? `@${child.name}` : child.kind === 'rule' ? child.selector : child.property} inside @layer theme`, child.location);
761
+ }
762
+ }
763
+ function validateVariableParity(state) {
764
+ if (state.themeVarLocations.size === 0)
765
+ return;
766
+ const themeNames = ['light', 'dark', ...Object.keys(state.themes).filter((t) => t !== 'light' && t !== 'dark')];
767
+ for (const varName of [...state.themeVarLocations.keys()].sort()) {
768
+ if (Object.prototype.hasOwnProperty.call(state.variables, varName))
769
+ continue;
770
+ const missing = themeNames.filter((themeName) => !Object.prototype.hasOwnProperty.call(state.themes[themeName]?.variables ?? {}, varName));
771
+ if (missing.length > 0) {
772
+ const location = state.themeVarLocations.get(varName);
773
+ state.warn('variable-parity', `CSS variable "${varName}" is declared in some @variant themes with no :root/@theme fallback and is missing in: ${missing.join(', ')}`, location);
774
+ }
775
+ }
776
+ }
777
+ function compileNodes(state, nodes, currentFile, options) {
778
+ for (const node of nodes) {
779
+ if (node.kind === 'at-rule') {
780
+ if (node.name === 'import') {
781
+ compileImport(state, node, currentFile, options);
782
+ continue;
783
+ }
784
+ if (node.name === 'theme') {
785
+ compileThemeBlock(state, node);
786
+ continue;
787
+ }
788
+ if (node.name === 'layer') {
789
+ compileLayerBlock(state, node);
790
+ continue;
791
+ }
792
+ if (node.name === 'variant') {
793
+ compileVariantBlock(state, node);
794
+ continue;
795
+ }
796
+ if (node.name === 'utility') {
797
+ compileUtilityBlock(state, node);
798
+ continue;
799
+ }
800
+ state.warn('unsupported-at-rule', `Unsupported at-rule "@${node.name}"`, node.location);
801
+ continue;
802
+ }
803
+ if (node.kind === 'rule') {
804
+ if (node.selector.trim() === ':root') {
805
+ compileRootRule(state, node);
806
+ continue;
807
+ }
808
+ compileCustomClassRule(state, node, 'component');
809
+ continue;
810
+ }
811
+ state.warn('unsupported-declaration', `Unexpected top-level declaration "${node.property}"`, node.location);
812
+ }
813
+ }
814
+ function finalizeInlineLineHeights(state) {
815
+ for (const [sizeKey, pending] of state.inlineLineHeights) {
816
+ let existing = state.fontSize[sizeKey];
817
+ if (existing === undefined &&
818
+ !state.resetNamespaces.has('fontSize') &&
819
+ !state.resetKeys.get('fontSize')?.has(sizeKey)) {
820
+ existing = tailwindTokens.fontSize[sizeKey];
821
+ }
822
+ if (existing === undefined)
823
+ continue;
824
+ if (hasVarCall(pending.raw)) {
825
+ const fontSize = typeof existing === 'string' ? existing : existing.fontSize;
826
+ state.fontSize[sizeKey] = { fontSize, lineHeight: pending.raw };
827
+ continue;
828
+ }
829
+ const parsed = parseCSSLineHeight(pending.raw);
830
+ if (parsed === null) {
831
+ state.warn('invalid-token-value', `Invalid line height "${pending.raw}" for "--text-${sizeKey}--line-height"`, pending.location);
832
+ continue;
833
+ }
834
+ if (typeof existing === 'string') {
835
+ state.fontSize[sizeKey] = { fontSize: existing, lineHeight: parsed.value };
836
+ }
837
+ else if (parsed.kind === 'multiplier' && typeof existing.fontSize === 'number') {
838
+ const lineHeight = Math.round(existing.fontSize * parsed.value * 1000) / 1000;
839
+ state.fontSize[sizeKey] = { fontSize: existing.fontSize, lineHeight };
840
+ }
841
+ else {
842
+ state.fontSize[sizeKey] = { fontSize: existing.fontSize, lineHeight: parsed.value };
843
+ }
844
+ }
845
+ }
846
+ function buildTokensConfig(state) {
847
+ const extend = {};
848
+ if (state.spacing !== undefined)
849
+ extend.spacing = state.spacing;
850
+ if (Object.keys(state.spacingScale).length > 0)
851
+ extend.spacingScale = state.spacingScale;
852
+ if (Object.keys(state.colors).length > 0)
853
+ extend.colors = state.colors;
854
+ if (Object.keys(state.fontSize).length > 0)
855
+ extend.fontSize = state.fontSize;
856
+ if (Object.keys(state.fontWeight).length > 0)
857
+ extend.fontWeight = state.fontWeight;
858
+ if (Object.keys(state.leading).length > 0)
859
+ extend.leading = state.leading;
860
+ if (Object.keys(state.radius).length > 0)
861
+ extend.radius = state.radius;
862
+ if (Object.keys(state.shadow).length > 0)
863
+ extend.shadow = state.shadow;
864
+ if (Object.keys(state.insetShadow).length > 0)
865
+ extend.insetShadow = state.insetShadow;
866
+ if (Object.keys(state.dropShadow).length > 0)
867
+ extend.dropShadow = state.dropShadow;
868
+ if (Object.keys(state.container).length > 0)
869
+ extend.container = state.container;
870
+ if (Object.keys(state.aspect).length > 0)
871
+ extend.aspect = state.aspect;
872
+ if (Object.keys(state.breakpoints).length > 0)
873
+ extend.breakpoints = state.breakpoints;
874
+ return Object.keys(extend).length > 0 ? { extend } : {};
875
+ }
876
+ function buildTokenResets(state) {
877
+ const namespaces = [...state.resetNamespaces];
878
+ const keys = {};
879
+ for (const [ns, set] of state.resetKeys) {
880
+ if (set.size > 0)
881
+ keys[ns] = [...set];
882
+ }
883
+ const prefixes = {};
884
+ for (const [ns, set] of state.resetPrefixes) {
885
+ if (set.size > 0)
886
+ prefixes[ns] = [...set];
887
+ }
888
+ const hasNs = namespaces.length > 0;
889
+ const hasKeys = Object.keys(keys).length > 0;
890
+ const hasPrefixes = Object.keys(prefixes).length > 0;
891
+ if (!hasNs && !hasKeys && !hasPrefixes)
892
+ return undefined;
893
+ return {
894
+ ...(hasNs ? { namespaces } : {}),
895
+ ...(hasKeys ? { keys } : {}),
896
+ ...(hasPrefixes ? { prefixes } : {}),
897
+ };
898
+ }
899
+ /**
900
+ * Parses a NitroWind / Tailwind v4 CSS stylesheet into a plain, JSON-serializable
901
+ * `NitroWindCSSConfig` containing tokens, token resets, shared variables, themes, and warnings.
902
+ */
903
+ export function parseCSS(css, options = {}) {
904
+ const warnings = [];
905
+ const state = {
906
+ imports: [],
907
+ warnings,
908
+ variables: {},
909
+ themes: {},
910
+ customClasses: {},
911
+ themeVarLocations: new Map(),
912
+ resetNamespaces: new Set(),
913
+ resetKeys: new Map(),
914
+ resetPrefixes: new Map(),
915
+ spacingScale: {},
916
+ colors: {},
917
+ fontSize: {},
918
+ inlineLineHeights: new Map(),
919
+ varLineHeights: new Set(),
920
+ fontWeight: {},
921
+ leading: {},
922
+ radius: {},
923
+ shadow: {},
924
+ insetShadow: {},
925
+ dropShadow: {},
926
+ container: {},
927
+ aspect: {},
928
+ breakpoints: {},
929
+ importStack: [options.filename ?? '<entry>'],
930
+ warn(code, message, location) {
931
+ const warning = location.file !== undefined
932
+ ? { code, message, line: location.line, column: location.column, file: location.file }
933
+ : { code, message, line: location.line, column: location.column };
934
+ warnings.push(warning);
935
+ options.onWarning?.(warning);
936
+ if (options.strict) {
937
+ throw new CSSParseError(message, location);
938
+ }
939
+ },
940
+ };
941
+ const ast = parseStylesheet(css, { filename: options.filename });
942
+ compileNodes(state, ast.nodes, options.filename, options);
943
+ finalizeInlineLineHeights(state);
944
+ validateVariableParity(state);
945
+ const themes = {};
946
+ for (const [name, entry] of Object.entries(state.themes)) {
947
+ themes[name] = {
948
+ ...(entry.colorScheme !== undefined ? { colorScheme: entry.colorScheme } : {}),
949
+ variables: entry.variables,
950
+ ...(entry.location !== undefined ? { location: entry.location } : {}),
951
+ };
952
+ }
953
+ const customClasses = {};
954
+ const applyLocations = {};
955
+ for (const [name, entry] of Object.entries(state.customClasses)) {
956
+ customClasses[name] = { rank: entry.rank, entries: entry.entries };
957
+ applyLocations[name] = entry.applyLocations;
958
+ }
959
+ const hasCustomClasses = Object.keys(customClasses).length > 0;
960
+ if (hasCustomClasses) {
961
+ detectCustomClassCycles(customClasses, applyLocations);
962
+ }
963
+ const tokenResets = buildTokenResets(state);
964
+ return {
965
+ imports: state.imports,
966
+ tokens: buildTokensConfig(state),
967
+ ...(tokenResets !== undefined ? { tokenResets } : {}),
968
+ variables: state.variables,
969
+ themes,
970
+ ...(hasCustomClasses ? { customClasses } : {}),
971
+ warnings: state.warnings,
972
+ };
973
+ }
974
+ /**
975
+ * Applies `initial` token resets from CSS (`--<ns>-*: initial;`, `--<ns>-<prefix>-*: initial;`,
976
+ * `--<ns>-<key>: initial;`) onto a base `Tokens` object without mutating `base`.
977
+ */
978
+ export function applyCSSTokenResets(base, resets) {
979
+ if (!resets)
980
+ return base;
981
+ const next = { ...base };
982
+ const cloneGroup = (ns) => {
983
+ const current = next[ns];
984
+ const copy = current ? { ...current } : {};
985
+ next[ns] = copy;
986
+ return copy;
987
+ };
988
+ if (resets.namespaces) {
989
+ for (const ns of resets.namespaces) {
990
+ ;
991
+ next[ns] = {};
992
+ }
993
+ }
994
+ if (resets.prefixes) {
995
+ for (const [ns, prefixes] of Object.entries(resets.prefixes)) {
996
+ if (!prefixes || prefixes.length === 0)
997
+ continue;
998
+ const group = cloneGroup(ns);
999
+ for (const key of Object.keys(group)) {
1000
+ if (prefixes.some((prefix) => key.startsWith(prefix))) {
1001
+ delete group[key];
1002
+ }
1003
+ }
1004
+ }
1005
+ }
1006
+ if (resets.keys) {
1007
+ for (const [ns, keys] of Object.entries(resets.keys)) {
1008
+ if (!keys || keys.length === 0)
1009
+ continue;
1010
+ const group = cloneGroup(ns);
1011
+ for (const key of keys) {
1012
+ delete group[key];
1013
+ }
1014
+ }
1015
+ }
1016
+ return next;
1017
+ }
1018
+ //# sourceMappingURL=compile.js.map