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
package/dist/core.js ADDED
@@ -0,0 +1,1026 @@
1
+ /**
2
+ * The platform-independent part of NitroWind: it turns a class string into
3
+ * NitroUI props and never touches native code, so it runs in tests and tools.
4
+ */
5
+ import { applyCSSTokenResets, applyRawDeclaration, CSSParseError, classifyRawDeclaration, detectCustomClassCycles, formatLocation, parseCSS, } from './css';
6
+ import { evaluateMathInString, hasMathFunction, hasViewportUnit } from './math';
7
+ import { createStore } from './store';
8
+ import { createTokens, parseBreakpointLength, tailwindTokens } from './tokens';
9
+ import { createThemeTransitionController } from './transition';
10
+ import { applyUtility, classifyUtility, createDraft, extractUtilityVariableNames, finalizeDraft, utilityUsesViewport, } from './utilities';
11
+ import { createVariableRegistry, extractCSSVariableNames } from './variables';
12
+ import { VERSION } from './version';
13
+ const RESERVED_THEME_NAMES = new Set([
14
+ 'system',
15
+ 'ios',
16
+ 'android',
17
+ 'sm',
18
+ 'md',
19
+ 'lg',
20
+ 'xl',
21
+ '2xl',
22
+ 'portrait',
23
+ 'landscape',
24
+ 'motion-reduce',
25
+ 'motion-safe',
26
+ ]);
27
+ function validateThemeName(name) {
28
+ if (!name || /[\s:[\]]/.test(name)) {
29
+ throw new Error(`[nitrowind] Invalid theme name "${name}"`);
30
+ }
31
+ if (RESERVED_THEME_NAMES.has(name) || name.startsWith('min-') || name.startsWith('max-')) {
32
+ throw new Error(`[nitrowind] Theme name "${name}" clashes with a reserved variant name`);
33
+ }
34
+ }
35
+ function buildThemes(configured) {
36
+ const result = {
37
+ light: Object.freeze({ colorScheme: 'light' }),
38
+ dark: Object.freeze({ colorScheme: 'dark' }),
39
+ };
40
+ if (!configured)
41
+ return Object.freeze(result);
42
+ for (const [name, definition] of Object.entries(configured)) {
43
+ validateThemeName(name);
44
+ if (name === 'light' && definition.colorScheme !== 'light') {
45
+ throw new Error('[nitrowind] Built-in theme "light" must have colorScheme "light"');
46
+ }
47
+ if (name === 'dark' && definition.colorScheme !== 'dark') {
48
+ throw new Error('[nitrowind] Built-in theme "dark" must have colorScheme "dark"');
49
+ }
50
+ if (definition.colorScheme !== 'light' && definition.colorScheme !== 'dark') {
51
+ throw new Error(`[nitrowind] Invalid colorScheme "${String(definition.colorScheme)}" for theme "${name}"`);
52
+ }
53
+ result[name] = Object.freeze({ ...definition });
54
+ }
55
+ return Object.freeze(result);
56
+ }
57
+ const VARIANTS = {
58
+ dark: (context) => context.colorScheme === 'dark',
59
+ light: (context) => context.colorScheme !== 'dark',
60
+ ios: (context) => context.platform === 'ios',
61
+ android: (context) => context.platform === 'android',
62
+ portrait: (context) => context.viewport !== undefined && context.viewport.height >= context.viewport.width,
63
+ landscape: (context) => context.viewport !== undefined && context.viewport.width > context.viewport.height,
64
+ 'motion-reduce': (context) => context.reducedMotion === true,
65
+ 'motion-safe': (context) => context.reducedMotion !== true,
66
+ };
67
+ const COLOR_SCHEME_VARIANTS = new Set(['dark', 'light']);
68
+ const ORIENTATION_VARIANTS = new Set(['portrait', 'landscape']);
69
+ const MOTION_VARIANTS = new Set(['motion-reduce', 'motion-safe']);
70
+ /**
71
+ * Precedence sort comparator: earlier classes are applied first, later classes win.
72
+ * Utility rank (1) beats component rank (0). Within each rank, Tier 2 (theme-name) beats
73
+ * Tier 1 (breakpoint), which beats Tier 0 (unconditional/other). Inside Tier 1 (and Tier 2),
74
+ * `max-*` sort largest-first, then `min` sort smallest-first.
75
+ */
76
+ export function compareClassPrecedence(a, b) {
77
+ const rankA = a.rank ?? 1;
78
+ const rankB = b.rank ?? 1;
79
+ if (rankA !== rankB)
80
+ return rankA - rankB;
81
+ if (a.tier !== b.tier)
82
+ return a.tier - b.tier;
83
+ if (a.breakpointRank !== b.breakpointRank) {
84
+ if (a.breakpointRank === null)
85
+ return -1;
86
+ if (b.breakpointRank === null)
87
+ return 1;
88
+ if (a.breakpointRank.group !== b.breakpointRank.group)
89
+ return a.breakpointRank.group - b.breakpointRank.group;
90
+ if (a.breakpointRank.primary !== b.breakpointRank.primary)
91
+ return a.breakpointRank.primary - b.breakpointRank.primary;
92
+ if (a.breakpointRank.hasMax !== b.breakpointRank.hasMax)
93
+ return a.breakpointRank.hasMax - b.breakpointRank.hasMax;
94
+ if (a.breakpointRank.secondary !== b.breakpointRank.secondary) {
95
+ return a.breakpointRank.secondary - b.breakpointRank.secondary;
96
+ }
97
+ }
98
+ return a.position - b.position;
99
+ }
100
+ function hasOwn(record, key) {
101
+ return Object.prototype.hasOwnProperty.call(record, key);
102
+ }
103
+ function parseBreakpointVariant(variant, breakpoints) {
104
+ if (variant.startsWith('min-[') && variant.endsWith(']')) {
105
+ const value = parseBreakpointLength(variant.slice(5, -1));
106
+ return value === null ? null : { kind: 'min', value };
107
+ }
108
+ if (variant.startsWith('max-[') && variant.endsWith(']')) {
109
+ const value = parseBreakpointLength(variant.slice(5, -1));
110
+ return value === null ? null : { kind: 'max', value };
111
+ }
112
+ if (variant.startsWith('max-')) {
113
+ const name = variant.slice(4);
114
+ return hasOwn(breakpoints, name) ? { kind: 'max', value: breakpoints[name] } : null;
115
+ }
116
+ if (variant.startsWith('min-')) {
117
+ const name = variant.slice(4);
118
+ return hasOwn(breakpoints, name) ? { kind: 'min', value: breakpoints[name] } : null;
119
+ }
120
+ if (hasOwn(breakpoints, variant)) {
121
+ return { kind: 'min', value: breakpoints[variant] };
122
+ }
123
+ return null;
124
+ }
125
+ function computeBreakpointRank(conditions) {
126
+ if (conditions.length === 0)
127
+ return null;
128
+ let maxMin = -Infinity;
129
+ let minMax = Infinity;
130
+ for (const cond of conditions) {
131
+ if (cond.kind === 'min' && cond.value > maxMin)
132
+ maxMin = cond.value;
133
+ if (cond.kind === 'max' && cond.value < minMax)
134
+ minMax = cond.value;
135
+ }
136
+ const hasMin = maxMin !== -Infinity;
137
+ const hasMax = minMax !== Infinity;
138
+ if (!hasMin) {
139
+ return { group: 0, primary: -minMax, hasMax: 1, secondary: 0 };
140
+ }
141
+ return { group: 1, primary: maxMin, hasMax: hasMax ? 1 : 0, secondary: hasMax ? -minMax : 0 };
142
+ }
143
+ /** Splits `dark:ios:!bg-red-500` into variant prefixes and the bare utility, ignoring `:` inside brackets or parentheses. */
144
+ function splitRawClass(raw) {
145
+ const parts = [];
146
+ let bracketDepth = 0;
147
+ let parenDepth = 0;
148
+ let start = 0;
149
+ for (let i = 0; i < raw.length; i++) {
150
+ const char = raw[i];
151
+ if (char === '[')
152
+ bracketDepth++;
153
+ else if (char === ']')
154
+ bracketDepth = Math.max(0, bracketDepth - 1);
155
+ else if (char === '(')
156
+ parenDepth++;
157
+ else if (char === ')')
158
+ parenDepth = Math.max(0, parenDepth - 1);
159
+ else if (char === ':' && bracketDepth === 0 && parenDepth === 0) {
160
+ parts.push(raw.slice(start, i));
161
+ start = i + 1;
162
+ }
163
+ }
164
+ let utility = raw.slice(start);
165
+ // Important modifiers have no meaning here: later classes already win.
166
+ if (utility.startsWith('!'))
167
+ utility = utility.slice(1);
168
+ else if (utility.endsWith('!'))
169
+ utility = utility.slice(0, -1);
170
+ return [parts, utility];
171
+ }
172
+ function classifyVariants(variants, tokens, customThemeNames) {
173
+ const bpConditions = [];
174
+ const themeVariants = [];
175
+ const otherVariants = [];
176
+ let unknownVariant = null;
177
+ for (const variant of variants) {
178
+ if (VARIANTS[variant] !== undefined) {
179
+ otherVariants.push(variant);
180
+ }
181
+ else if (customThemeNames.has(variant)) {
182
+ themeVariants.push(variant);
183
+ }
184
+ else {
185
+ const bp = parseBreakpointVariant(variant, tokens.breakpoints);
186
+ if (bp !== null) {
187
+ bpConditions.push(bp);
188
+ }
189
+ else if (unknownVariant === null) {
190
+ unknownVariant = variant;
191
+ }
192
+ }
193
+ }
194
+ const breakpointRank = computeBreakpointRank(bpConditions);
195
+ const tier = themeVariants.length > 0 ? 2 : breakpointRank !== null ? 1 : 0;
196
+ return { breakpoints: bpConditions, themeVariants, otherVariants, unknownVariant, breakpointRank, tier };
197
+ }
198
+ function buildParsedUtility(raw, variants, utility, rank, position, tokens, customThemeNames) {
199
+ const classified = classifyVariants(variants, tokens, customThemeNames);
200
+ return {
201
+ kind: 'utility',
202
+ raw,
203
+ variants,
204
+ ...classified,
205
+ utility,
206
+ variables: extractUtilityVariableNames(utility, tokens),
207
+ usesViewport: utilityUsesViewport(utility),
208
+ rank,
209
+ position,
210
+ };
211
+ }
212
+ function buildParsedDeclaration(raw, variants, property, value, rank, position, tokens, customThemeNames) {
213
+ const classified = classifyVariants(variants, tokens, customThemeNames);
214
+ return {
215
+ kind: 'declaration',
216
+ raw,
217
+ variants,
218
+ ...classified,
219
+ utility: '',
220
+ property,
221
+ value,
222
+ variables: extractCSSVariableNames(value),
223
+ usesViewport: hasViewportUnit(value),
224
+ rank,
225
+ position,
226
+ };
227
+ }
228
+ function expandCustomClassEntries(entries, enclosingVariants, ctx) {
229
+ for (const entry of entries) {
230
+ if (entry.kind === 'variant') {
231
+ expandCustomClassEntries(entry.entries, [...enclosingVariants, entry.variant], ctx);
232
+ continue;
233
+ }
234
+ if (entry.kind === 'declaration') {
235
+ ctx.out.push(buildParsedDeclaration(`${ctx.rawOrigin} (${entry.property}: ${entry.value})`, [...enclosingVariants], entry.property, entry.value, ctx.rank, ctx.out.length, ctx.tokens, ctx.customThemeNames));
236
+ continue;
237
+ }
238
+ if (entry.kind === 'apply') {
239
+ for (const applied of entry.classes) {
240
+ const [applyVariants, applyUtility] = splitRawClass(applied);
241
+ const combinedVariants = [...enclosingVariants, ...applyVariants];
242
+ if (Object.prototype.hasOwnProperty.call(ctx.customClasses, applyUtility)) {
243
+ if (ctx.visiting.has(applyUtility))
244
+ continue;
245
+ ctx.visiting.add(applyUtility);
246
+ expandCustomClassEntries(ctx.customClasses[applyUtility].entries, combinedVariants, ctx);
247
+ ctx.visiting.delete(applyUtility);
248
+ }
249
+ else {
250
+ ctx.out.push(buildParsedUtility(`${ctx.rawOrigin} (@apply ${applied})`, combinedVariants, applyUtility, ctx.rank, ctx.out.length, ctx.tokens, ctx.customThemeNames));
251
+ }
252
+ }
253
+ }
254
+ }
255
+ }
256
+ function parseClassList(className, tokens, customThemeNames, customClasses) {
257
+ const out = [];
258
+ for (const raw of className.split(/\s+/)) {
259
+ if (!raw)
260
+ continue;
261
+ const [variants, utility] = splitRawClass(raw);
262
+ if (customClasses !== undefined && Object.prototype.hasOwnProperty.call(customClasses, utility)) {
263
+ const outerClassified = classifyVariants(variants, tokens, customThemeNames);
264
+ if (outerClassified.unknownVariant !== null) {
265
+ out.push(buildParsedUtility(raw, variants, utility, 1, out.length, tokens, customThemeNames));
266
+ continue;
267
+ }
268
+ const def = customClasses[utility];
269
+ const rank = def.rank === 'utility' ? 1 : 0;
270
+ expandCustomClassEntries(def.entries, variants, {
271
+ rawOrigin: raw,
272
+ rank,
273
+ tokens,
274
+ customThemeNames,
275
+ customClasses,
276
+ out,
277
+ visiting: new Set([utility]),
278
+ });
279
+ continue;
280
+ }
281
+ out.push(buildParsedUtility(raw, variants, utility, 1, out.length, tokens, customThemeNames));
282
+ }
283
+ return out.sort(compareClassPrecedence);
284
+ }
285
+ function isDevelopment() {
286
+ const dev = globalThis.__DEV__;
287
+ return dev !== false;
288
+ }
289
+ const EMPTY = Object.freeze({});
290
+ const EMPTY_STRINGS = Object.freeze([]);
291
+ const EMPTY_NUMBERS = Object.freeze([]);
292
+ const NO_DEPENDENCIES = Object.freeze({
293
+ colorScheme: false,
294
+ themes: EMPTY_STRINGS,
295
+ reducedMotion: false,
296
+ breakpoints: EMPTY_NUMBERS,
297
+ variables: EMPTY_STRINGS,
298
+ orientation: false,
299
+ viewport: false,
300
+ });
301
+ const MAX_SIGNATURES_PER_CLASS = 16;
302
+ function freezeResult(draft) {
303
+ const result = {};
304
+ if (Object.keys(draft.layout).length > 0)
305
+ result.layout = Object.freeze(draft.layout);
306
+ if (Object.keys(draft.style).length > 0)
307
+ result.style = Object.freeze(draft.style);
308
+ if (Object.keys(draft.text).length > 0)
309
+ result.text = Object.freeze(draft.text);
310
+ return Object.freeze(result);
311
+ }
312
+ const FALLBACK_ENVIRONMENT = {
313
+ platform: 'ios',
314
+ getColorScheme: () => 'light',
315
+ setColorScheme: () => { },
316
+ subscribeColorScheme: () => () => { },
317
+ getViewportSize: () => undefined,
318
+ subscribeViewportSize: () => () => { },
319
+ native: undefined,
320
+ };
321
+ let defaultEnvironment = FALLBACK_ENVIRONMENT;
322
+ /** Each instance's variable registry, for internal callers that need more than the public interface. */
323
+ const registries = new WeakMap();
324
+ /** Each instance's CSS custom classes, for `cn()` precedence and deduplication. */
325
+ const customClassesByInstance = new WeakMap();
326
+ let configured = false;
327
+ function mergeThemesWithCSS(cssConfig, jsThemes) {
328
+ const cssThemes = cssConfig?.themes;
329
+ if (!cssThemes || Object.keys(cssThemes).length === 0)
330
+ return jsThemes;
331
+ const merged = {};
332
+ const allNames = new Set([...Object.keys(cssThemes), ...Object.keys(jsThemes ?? {})]);
333
+ for (const name of allNames) {
334
+ const cssEntry = cssThemes[name];
335
+ const jsEntry = jsThemes?.[name];
336
+ const colorScheme = jsEntry?.colorScheme ??
337
+ cssEntry?.colorScheme ??
338
+ (name === 'light' ? 'light' : name === 'dark' ? 'dark' : undefined);
339
+ if (colorScheme === undefined) {
340
+ const message = `Custom theme "@variant ${name}" must declare "color-scheme: light;" or "color-scheme: dark;" (or provide colorScheme in JS themes)`;
341
+ if (cssEntry?.location) {
342
+ throw new CSSParseError(message, cssEntry.location);
343
+ }
344
+ throw new Error(`[nitrowind] ${message}`);
345
+ }
346
+ const variables = cssEntry?.variables || jsEntry?.variables ? { ...cssEntry?.variables, ...jsEntry?.variables } : undefined;
347
+ merged[name] = variables !== undefined ? { colorScheme, variables } : { colorScheme };
348
+ }
349
+ return merged;
350
+ }
351
+ /** Creates an independent NitroWind instance with its own tokens, themes, store and caches. */
352
+ export function createNitroWind(config = {}) {
353
+ const isDev = isDevelopment();
354
+ const cssConfig = typeof config.css === 'string'
355
+ ? parseCSS(config.css, {
356
+ onWarning: isDev
357
+ ? (warning) => {
358
+ // Variable parity is validated below against the final merged shared + theme layers.
359
+ if (warning.code === 'variable-parity')
360
+ return;
361
+ console.warn(`[nitrowind] ${warning.message} (${formatLocation(warning)})`);
362
+ }
363
+ : undefined,
364
+ })
365
+ : config.css;
366
+ const cssBaseTokens = cssConfig !== undefined
367
+ ? createTokens(cssConfig.tokens, applyCSSTokenResets(tailwindTokens, cssConfig.tokenResets))
368
+ : tailwindTokens;
369
+ const tokens = createTokens(config.tokens, cssBaseTokens);
370
+ const themes = buildThemes(mergeThemesWithCSS(cssConfig, config.themes));
371
+ const mergedVariables = cssConfig?.variables || config.variables ? { ...cssConfig?.variables, ...config.variables } : undefined;
372
+ const variables = createVariableRegistry(mergedVariables, themes, isDev);
373
+ const initialTheme = config.initialTheme ?? 'system';
374
+ if (initialTheme !== 'system' && !Object.prototype.hasOwnProperty.call(themes, initialTheme)) {
375
+ throw new Error(`[nitrowind] Unregistered initialTheme "${initialTheme}"`);
376
+ }
377
+ const baseEnvironment = config.environment ?? defaultEnvironment;
378
+ const environment = config.native !== undefined ? { ...baseEnvironment, native: config.native } : baseEnvironment;
379
+ if (environment.native !== undefined && environment.native.version !== VERSION && isDevelopment()) {
380
+ console.warn(`[nitrowind] Version mismatch: nitrowind@${VERSION} was configured with nitrowind-native@${environment.native.version}. Keep both packages on the same version.`);
381
+ }
382
+ const store = createStore(environment, themes, initialTheme);
383
+ const transitions = createThemeTransitionController(environment, store, themes, config.transition, isDevelopment);
384
+ const customClasses = cssConfig?.customClasses;
385
+ if (customClasses !== undefined) {
386
+ detectCustomClassCycles(customClasses);
387
+ }
388
+ const customThemeNames = new Set(Object.keys(themes).filter((name) => name !== 'light' && name !== 'dark'));
389
+ const unknownClasses = config.unknownClasses ?? (isDevelopment() ? 'warn' : 'ignore');
390
+ const parsedCache = new Map();
391
+ const dependencyCache = new Map();
392
+ const resultCache = new Map();
393
+ const warned = new Set();
394
+ function reportUnknown(raw, reason) {
395
+ if (unknownClasses === 'ignore')
396
+ return;
397
+ const message = `[nitrowind] ${reason}: "${raw}"`;
398
+ if (unknownClasses === 'throw')
399
+ throw new Error(message);
400
+ if (!warned.has(raw)) {
401
+ warned.add(raw);
402
+ console.warn(message);
403
+ }
404
+ }
405
+ function reportVariableError(raw, theme, error) {
406
+ if (unknownClasses === 'ignore')
407
+ return;
408
+ let message;
409
+ switch (error.kind) {
410
+ case 'missing':
411
+ message = `[nitrowind] Missing CSS variable "${error.variable ?? ''}" in theme "${theme}" (used by "${raw}")`;
412
+ break;
413
+ case 'cycle':
414
+ message = `[nitrowind] Cyclic CSS variable "${error.variable ?? ''}" in theme "${theme}" (used by "${raw}")`;
415
+ break;
416
+ case 'calc':
417
+ message = error.variable
418
+ ? `[nitrowind] Cannot evaluate CSS math in variable "${error.variable}" in theme "${theme}" (used by "${raw}"): ${error.reason ?? error.value ?? 'invalid expression'}`
419
+ : `[nitrowind] Cannot evaluate CSS math in "${raw}": ${error.reason ?? error.value ?? 'invalid expression'}`;
420
+ break;
421
+ case 'invalid':
422
+ message = `[nitrowind] Invalid ${error.expected ?? 'value'} "${error.value ?? ''}" for CSS variable "${error.variable ?? ''}" in theme "${theme}" (used by "${raw}")`;
423
+ break;
424
+ }
425
+ if (unknownClasses === 'throw')
426
+ throw new Error(message);
427
+ const key = error.variable !== undefined ? `var:${error.variable}:${theme}` : `raw:${raw}`;
428
+ if (!warned.has(key)) {
429
+ warned.add(key);
430
+ console.warn(message);
431
+ }
432
+ }
433
+ function resolveThemeAndScheme(context) {
434
+ const registered = context.theme !== undefined ? themes[context.theme] : undefined;
435
+ const colorScheme = context.colorScheme ?? registered?.colorScheme ?? 'light';
436
+ const theme = context.theme ?? colorScheme;
437
+ return { theme, colorScheme };
438
+ }
439
+ function parse(className) {
440
+ let parsed = parsedCache.get(className);
441
+ if (parsed === undefined) {
442
+ parsed = parseClassList(className, tokens, customThemeNames, customClasses);
443
+ parsedCache.set(className, parsed);
444
+ }
445
+ return parsed;
446
+ }
447
+ function dependencies(className) {
448
+ if (!className)
449
+ return NO_DEPENDENCIES;
450
+ let deps = dependencyCache.get(className);
451
+ if (deps === undefined) {
452
+ let colorScheme = false;
453
+ let themeSet;
454
+ let reducedMotion = false;
455
+ let bpSet;
456
+ let varSet;
457
+ let orientation = false;
458
+ let viewport = false;
459
+ for (const parsed of parse(className)) {
460
+ for (const variant of parsed.otherVariants) {
461
+ if (COLOR_SCHEME_VARIANTS.has(variant))
462
+ colorScheme = true;
463
+ else if (ORIENTATION_VARIANTS.has(variant))
464
+ orientation = true;
465
+ else if (MOTION_VARIANTS.has(variant))
466
+ reducedMotion = true;
467
+ }
468
+ for (const themeVariant of parsed.themeVariants) {
469
+ if (themeSet === undefined)
470
+ themeSet = new Set();
471
+ themeSet.add(themeVariant);
472
+ }
473
+ for (const bp of parsed.breakpoints) {
474
+ if (bpSet === undefined)
475
+ bpSet = new Set();
476
+ bpSet.add(bp.value);
477
+ }
478
+ for (const variable of parsed.variables) {
479
+ if (varSet === undefined)
480
+ varSet = new Set();
481
+ varSet.add(variable);
482
+ }
483
+ if (parsed.usesViewport)
484
+ viewport = true;
485
+ }
486
+ if (!colorScheme &&
487
+ !reducedMotion &&
488
+ !orientation &&
489
+ !viewport &&
490
+ themeSet === undefined &&
491
+ bpSet === undefined &&
492
+ varSet === undefined) {
493
+ deps = NO_DEPENDENCIES;
494
+ }
495
+ else {
496
+ const themeList = themeSet ? Object.freeze([...themeSet].sort()) : EMPTY_STRINGS;
497
+ const breakpoints = bpSet ? Object.freeze([...bpSet].sort((a, b) => a - b)) : EMPTY_NUMBERS;
498
+ const variableList = varSet ? Object.freeze([...varSet].sort()) : EMPTY_STRINGS;
499
+ deps = Object.freeze({
500
+ colorScheme,
501
+ themes: themeList,
502
+ reducedMotion,
503
+ breakpoints,
504
+ variables: variableList,
505
+ orientation,
506
+ viewport,
507
+ });
508
+ }
509
+ dependencyCache.set(className, deps);
510
+ }
511
+ return deps;
512
+ }
513
+ function signature(className, context = {}) {
514
+ const deps = dependencies(className);
515
+ if (!deps.colorScheme &&
516
+ deps.themes.length === 0 &&
517
+ !deps.reducedMotion &&
518
+ deps.breakpoints.length === 0 &&
519
+ deps.variables.length === 0 &&
520
+ !deps.orientation &&
521
+ !deps.viewport) {
522
+ return '';
523
+ }
524
+ const parts = [];
525
+ let resolvedTheme;
526
+ if (deps.colorScheme || deps.themes.length > 0 || deps.variables.length > 0) {
527
+ resolvedTheme = resolveThemeAndScheme(context);
528
+ if (deps.colorScheme)
529
+ parts.push(`s:${resolvedTheme.colorScheme}`);
530
+ if (deps.themes.length > 0) {
531
+ parts.push(`t:${deps.themes.includes(resolvedTheme.theme) ? resolvedTheme.theme : ''}`);
532
+ }
533
+ }
534
+ if (deps.reducedMotion)
535
+ parts.push(`m:${context.reducedMotion === true ? 'reduce' : 'safe'}`);
536
+ if (deps.breakpoints.length > 0) {
537
+ if (context.viewport === undefined) {
538
+ parts.push('b:-');
539
+ }
540
+ else {
541
+ const width = context.viewport.width;
542
+ let bucket = 0;
543
+ for (const bp of deps.breakpoints) {
544
+ if (width >= bp)
545
+ bucket++;
546
+ else
547
+ break;
548
+ }
549
+ parts.push(`b:${bucket}`);
550
+ }
551
+ }
552
+ let varsUseViewport = false;
553
+ if (deps.variables.length > 0) {
554
+ const theme = resolvedTheme.theme;
555
+ const varParts = deps.variables.map((name) => {
556
+ const expanded = variables.expandVariable(name, theme, context.variables, {
557
+ outerScope: context.outerVariables,
558
+ });
559
+ if (expanded.ok && hasViewportUnit(expanded.value))
560
+ varsUseViewport = true;
561
+ return expanded.ok ? `${name}=${JSON.stringify(expanded.value)}` : `${name}=${expanded.kind}`;
562
+ });
563
+ parts.push(`v:${varParts.join(',')}`);
564
+ }
565
+ if (deps.orientation) {
566
+ if (context.viewport === undefined) {
567
+ parts.push('o:-');
568
+ }
569
+ else {
570
+ parts.push(context.viewport.height >= context.viewport.width ? 'o:p' : 'o:l');
571
+ }
572
+ }
573
+ if (deps.viewport || varsUseViewport) {
574
+ if (context.viewport === undefined) {
575
+ parts.push('vp:-');
576
+ }
577
+ else {
578
+ parts.push(`vp:${context.viewport.width}x${context.viewport.height}`);
579
+ }
580
+ }
581
+ return parts.join('|');
582
+ }
583
+ function resolve(className, context = {}) {
584
+ if (!className)
585
+ return EMPTY;
586
+ const deps = dependencies(className);
587
+ const sig = signature(className, context);
588
+ const { theme, colorScheme } = resolveThemeAndScheme(context);
589
+ const cacheKey = deps.variables.length > 0 && unknownClasses !== 'ignore'
590
+ ? `${context.platform ?? ''}|${theme}|${sig}`
591
+ : `${context.platform ?? ''}|${sig}`;
592
+ let bySignature = resultCache.get(className);
593
+ const cached = bySignature?.get(cacheKey);
594
+ if (cached !== undefined)
595
+ return cached;
596
+ const effectiveContext = {
597
+ platform: context.platform,
598
+ theme,
599
+ colorScheme,
600
+ reducedMotion: context.reducedMotion,
601
+ viewport: context.viewport,
602
+ variables: context.variables,
603
+ outerVariables: context.outerVariables,
604
+ };
605
+ const draft = createDraft();
606
+ let currentRaw = '';
607
+ let hadVariableError = false;
608
+ let missingViewport = false;
609
+ const resolveExpandedMath = (value, vars, variable) => {
610
+ if (!hasMathFunction(value))
611
+ return { value, variables: vars };
612
+ const evaluated = evaluateMathInString(value, effectiveContext.viewport);
613
+ if (evaluated.ok)
614
+ return { value: evaluated.value, variables: vars };
615
+ if (evaluated.reason === 'missing-viewport') {
616
+ missingViewport = true;
617
+ return null;
618
+ }
619
+ hadVariableError = true;
620
+ reportVariableError(currentRaw, theme, {
621
+ kind: 'calc',
622
+ variable,
623
+ value,
624
+ reason: evaluated.message,
625
+ });
626
+ return null;
627
+ };
628
+ const varResolver = {
629
+ expand(expr) {
630
+ const result = variables.expandExpression(expr, theme, context.variables, {
631
+ outerScope: context.outerVariables,
632
+ });
633
+ if (!result.ok) {
634
+ hadVariableError = true;
635
+ reportVariableError(currentRaw, theme, result);
636
+ return null;
637
+ }
638
+ return resolveExpandedMath(result.value, result.variables, result.variables[0]);
639
+ },
640
+ tryVariable(name) {
641
+ if (variables.lookupRaw(name, theme, context.variables, context.outerVariables) === undefined)
642
+ return null;
643
+ const result = variables.expandVariable(name, theme, context.variables, {
644
+ outerScope: context.outerVariables,
645
+ });
646
+ if (!result.ok) {
647
+ hadVariableError = true;
648
+ reportVariableError(currentRaw, theme, result);
649
+ return null;
650
+ }
651
+ return resolveExpandedMath(result.value, result.variables, result.variables[0] ?? name);
652
+ },
653
+ reportError(error) {
654
+ hadVariableError = true;
655
+ reportVariableError(currentRaw, theme, error);
656
+ },
657
+ hasError() {
658
+ return hadVariableError;
659
+ },
660
+ isMissingViewport() {
661
+ return missingViewport;
662
+ },
663
+ };
664
+ // Classes are pre-sorted by tier, breakpoint rank, and position so later classes override earlier ones.
665
+ for (const parsed of parse(className)) {
666
+ if (parsed.unknownVariant !== null) {
667
+ reportUnknown(parsed.raw, `Unsupported variant "${parsed.unknownVariant}"`);
668
+ continue;
669
+ }
670
+ let matches = true;
671
+ for (const variant of parsed.otherVariants) {
672
+ if (!VARIANTS[variant](effectiveContext)) {
673
+ matches = false;
674
+ break;
675
+ }
676
+ }
677
+ if (!matches)
678
+ continue;
679
+ for (const themeVariant of parsed.themeVariants) {
680
+ if (theme !== themeVariant) {
681
+ matches = false;
682
+ break;
683
+ }
684
+ }
685
+ if (!matches)
686
+ continue;
687
+ if (parsed.breakpoints.length > 0) {
688
+ if (effectiveContext.viewport === undefined)
689
+ continue;
690
+ const width = effectiveContext.viewport.width;
691
+ for (const bp of parsed.breakpoints) {
692
+ if (bp.kind === 'min' ? width < bp.value : width >= bp.value) {
693
+ matches = false;
694
+ break;
695
+ }
696
+ }
697
+ if (!matches)
698
+ continue;
699
+ }
700
+ currentRaw = parsed.raw;
701
+ hadVariableError = false;
702
+ missingViewport = false;
703
+ if (parsed.kind === 'declaration') {
704
+ if (!applyRawDeclaration(parsed.property, parsed.value, draft, varResolver, effectiveContext.viewport) &&
705
+ !hadVariableError &&
706
+ !missingViewport) {
707
+ reportUnknown(parsed.raw, 'Unsupported declaration');
708
+ }
709
+ }
710
+ else if (!applyUtility(parsed.utility, draft, tokens, varResolver, effectiveContext.viewport) &&
711
+ !hadVariableError &&
712
+ !missingViewport) {
713
+ reportUnknown(parsed.raw, 'Unsupported class');
714
+ }
715
+ }
716
+ finalizeDraft(draft);
717
+ const result = freezeResult(draft);
718
+ if (bySignature === undefined) {
719
+ bySignature = new Map();
720
+ resultCache.set(className, bySignature);
721
+ }
722
+ else if (bySignature.size >= MAX_SIGNATURES_PER_CLASS) {
723
+ const oldest = bySignature.keys().next().value;
724
+ if (oldest !== undefined)
725
+ bySignature.delete(oldest);
726
+ }
727
+ bySignature.set(cacheKey, result);
728
+ return result;
729
+ }
730
+ function setTheme(preference, options) {
731
+ return transitions.setTheme(preference, options);
732
+ }
733
+ function getTheme() {
734
+ return store.getTheme();
735
+ }
736
+ function subscribeTheme(listener) {
737
+ return store.subscribeTheme(() => listener(store.getTheme()));
738
+ }
739
+ function getCSSVariable(name, theme) {
740
+ return variables.getCSSVariable(name, theme ?? store.getTheme().theme);
741
+ }
742
+ function updateCSSVariables(updates, options) {
743
+ const activeTheme = store.getTheme().theme;
744
+ const subscribedThemes = [...store.getSubscribedVariableThemes()];
745
+ const affectedByTheme = variables.update(updates, activeTheme, options?.theme, subscribedThemes);
746
+ const activeAffected = affectedByTheme.get(activeTheme);
747
+ if (activeAffected !== undefined && activeAffected.size > 0) {
748
+ store.notifyVariables(activeAffected);
749
+ }
750
+ for (const theme of subscribedThemes) {
751
+ const scopedAffected = affectedByTheme.get(theme);
752
+ if (scopedAffected !== undefined && scopedAffected.size > 0) {
753
+ store.notifyVariables(scopedAffected, theme);
754
+ }
755
+ }
756
+ }
757
+ const nitroWind = {
758
+ tokens,
759
+ themes,
760
+ environment,
761
+ store,
762
+ setTheme,
763
+ getTheme,
764
+ subscribeTheme,
765
+ getCSSVariable,
766
+ updateCSSVariables,
767
+ resolve,
768
+ dependencies,
769
+ signature,
770
+ };
771
+ registries.set(nitroWind, variables);
772
+ if (customClasses !== undefined) {
773
+ customClassesByInstance.set(nitroWind, customClasses);
774
+ }
775
+ return nitroWind;
776
+ }
777
+ /**
778
+ * Internal: `getCSSVariable` inside a variable scope, whose merged values win over the theme's.
779
+ * `useCSSVariable` calls it; the public `getCSSVariable` never sees a scope.
780
+ */
781
+ export function getScopedCSSVariable(nitroWind, name, theme, scope, outerScope) {
782
+ const registry = registries.get(nitroWind);
783
+ return registry !== undefined
784
+ ? registry.getCSSVariable(name, theme, scope, outerScope)
785
+ : nitroWind.getCSSVariable(name, theme);
786
+ }
787
+ /** Internal: returns true if any of `names` currently expands to a value using `vw` or `vh`. */
788
+ export function variablesUseViewport(nitroWind, names, theme, scope, outerScope) {
789
+ const registry = registries.get(nitroWind);
790
+ if (registry === undefined)
791
+ return false;
792
+ for (const name of names) {
793
+ const value = registry.getCSSVariable(name, theme, scope, outerScope);
794
+ if (value !== undefined && hasViewportUnit(value))
795
+ return true;
796
+ }
797
+ return false;
798
+ }
799
+ let instance = createNitroWind();
800
+ /** Registers the runtime's default environment (NitroUI in apps). */
801
+ export function setDefaultEnvironment(environment) {
802
+ defaultEnvironment = environment;
803
+ if (!configured) {
804
+ instance = createNitroWind({ environment });
805
+ }
806
+ }
807
+ /**
808
+ * Replaces the shared instance used by `className`, `tw` and `useTw`.
809
+ * Call it once in your entry file, before the first render.
810
+ */
811
+ export function configure(config) {
812
+ configured = true;
813
+ instance = createNitroWind(config);
814
+ return instance;
815
+ }
816
+ /** The shared instance. */
817
+ export function getNitroWind() {
818
+ return instance;
819
+ }
820
+ /** Switches the active theme preference on the shared instance (`'system'` or a registered theme name). */
821
+ export function setTheme(preference, options) {
822
+ return getNitroWind().setTheme(preference, options);
823
+ }
824
+ /** Returns `{ theme, colorScheme, preference }` from the shared instance. */
825
+ export function getTheme() {
826
+ return getNitroWind().getTheme();
827
+ }
828
+ /** Subscribes to theme changes on the shared instance. */
829
+ export function subscribeTheme(listener) {
830
+ return getNitroWind().subscribeTheme(listener);
831
+ }
832
+ /** Returns the active theme's expanded value for a CSS variable on the shared instance. */
833
+ export function getCSSVariable(name) {
834
+ return getNitroWind().getCSSVariable(name);
835
+ }
836
+ /** Merges runtime CSS variable updates into the shared layer or a specific theme on the shared instance. */
837
+ export function updateCSSVariables(variables, options) {
838
+ getNitroWind().updateCSSVariables(variables, options);
839
+ }
840
+ /**
841
+ * Compiles classes to `{ layout, style, text }` outside of JSX, for example to pass
842
+ * `tw('p-4').layout` to a component that takes NitroUI props.
843
+ * Theme and scheme variants read the store once at call time; prefer `useTw` in components.
844
+ */
845
+ export function tw(className) {
846
+ const nitroWind = getNitroWind();
847
+ const deps = nitroWind.dependencies(className);
848
+ const needsTheme = deps.colorScheme || deps.themes.length > 0 || deps.variables.length > 0;
849
+ const themeState = needsTheme ? nitroWind.store.getTheme() : undefined;
850
+ const reducedMotion = deps.reducedMotion ? nitroWind.store.getReducedMotion() : undefined;
851
+ const viewport = deps.breakpoints.length > 0 || deps.orientation || deps.viewport || deps.variables.length > 0
852
+ ? nitroWind.store.getViewportSize()
853
+ : undefined;
854
+ return nitroWind.resolve(className, {
855
+ platform: nitroWind.environment.platform,
856
+ theme: themeState?.theme,
857
+ colorScheme: themeState?.colorScheme,
858
+ reducedMotion,
859
+ viewport,
860
+ });
861
+ }
862
+ function flattenClassValues(values, out) {
863
+ for (const value of values) {
864
+ if (!value)
865
+ continue;
866
+ if (Array.isArray(value)) {
867
+ flattenClassValues(value, out);
868
+ }
869
+ else {
870
+ for (const token of value.split(/\s+/)) {
871
+ if (token)
872
+ out.push(token);
873
+ }
874
+ }
875
+ }
876
+ }
877
+ /** Splits a raw class token into its canonical variant key and bare utility (without `!`). */
878
+ function splitVariantAndUtility(raw) {
879
+ const variants = [];
880
+ let bracketDepth = 0;
881
+ let parenDepth = 0;
882
+ let start = 0;
883
+ for (let i = 0; i < raw.length; i++) {
884
+ const char = raw[i];
885
+ if (char === '[')
886
+ bracketDepth++;
887
+ else if (char === ']')
888
+ bracketDepth = Math.max(0, bracketDepth - 1);
889
+ else if (char === '(')
890
+ parenDepth++;
891
+ else if (char === ')')
892
+ parenDepth = Math.max(0, parenDepth - 1);
893
+ else if (char === ':' && bracketDepth === 0 && parenDepth === 0) {
894
+ variants.push(raw.slice(start, i));
895
+ start = i + 1;
896
+ }
897
+ }
898
+ let utility = raw.slice(start);
899
+ if (utility.startsWith('!'))
900
+ utility = utility.slice(1);
901
+ else if (utility.endsWith('!'))
902
+ utility = utility.slice(0, -1);
903
+ const variantKey = variants.length === 0 ? '' : variants.length === 1 ? variants[0] : variants.sort().join(':');
904
+ return [variantKey, utility];
905
+ }
906
+ function collectCustomUtilityConflicts(def, tokens, customClasses, visiting = new Set()) {
907
+ const conflicts = [];
908
+ let opaque = false;
909
+ for (const entry of def.entries) {
910
+ if (entry.kind === 'variant') {
911
+ opaque = true;
912
+ continue;
913
+ }
914
+ if (entry.kind === 'declaration') {
915
+ const conflict = classifyRawDeclaration(entry.property);
916
+ if (conflict === null)
917
+ opaque = true;
918
+ else
919
+ conflicts.push(conflict);
920
+ continue;
921
+ }
922
+ for (const applied of entry.classes) {
923
+ const [variants, util] = splitRawClass(applied);
924
+ if (variants.length > 0) {
925
+ opaque = true;
926
+ continue;
927
+ }
928
+ if (Object.prototype.hasOwnProperty.call(customClasses, util)) {
929
+ if (visiting.has(util))
930
+ continue;
931
+ visiting.add(util);
932
+ const nested = collectCustomUtilityConflicts(customClasses[util], tokens, customClasses, visiting);
933
+ visiting.delete(util);
934
+ if (nested.opaque)
935
+ opaque = true;
936
+ for (const c of nested.conflicts)
937
+ conflicts.push(c);
938
+ }
939
+ else {
940
+ const conflict = classifyUtility(util, tokens);
941
+ if (conflict === null)
942
+ opaque = true;
943
+ else
944
+ conflicts.push(conflict);
945
+ }
946
+ }
947
+ }
948
+ return { conflicts, opaque };
949
+ }
950
+ /**
951
+ * Joins class names, skipping falsy values, enforcing component-vs-utility rank
952
+ * (`.class` / `@layer components` always precede utilities and `@utility`), and
953
+ * deduplicating conflicting utilities under the same variant so later classes win.
954
+ */
955
+ export function cn(...values) {
956
+ const rawTokens = [];
957
+ flattenClassValues(values, rawTokens);
958
+ if (rawTokens.length <= 1)
959
+ return rawTokens[0] ?? '';
960
+ const nitroWind = getNitroWind();
961
+ const tokens = nitroWind.tokens;
962
+ const customClasses = customClassesByInstance.get(nitroWind);
963
+ const superseded = new Set();
964
+ const seenComponents = new Set();
965
+ const seenCustomUtilities = new Set();
966
+ const keptComponents = [];
967
+ const keptUtilities = [];
968
+ for (let i = rawTokens.length - 1; i >= 0; i--) {
969
+ const raw = rawTokens[i];
970
+ const [variantKey, utility] = splitVariantAndUtility(raw);
971
+ const customDef = customClasses !== undefined && Object.prototype.hasOwnProperty.call(customClasses, utility)
972
+ ? customClasses[utility]
973
+ : undefined;
974
+ if (customDef !== undefined && customDef.rank === 'component') {
975
+ const compKey = `${variantKey}\0${utility}`;
976
+ if (seenComponents.has(compKey))
977
+ continue;
978
+ seenComponents.add(compKey);
979
+ keptComponents.push(raw);
980
+ continue;
981
+ }
982
+ if (customDef !== undefined && customDef.rank === 'utility') {
983
+ const customKey = `${variantKey}\0${utility}`;
984
+ if (seenCustomUtilities.has(customKey))
985
+ continue;
986
+ const { conflicts, opaque } = collectCustomUtilityConflicts(customDef, tokens, customClasses, new Set([utility]));
987
+ if (!opaque && conflicts.length > 0 && conflicts.every((c) => superseded.has(`${variantKey}\0${c.group}`))) {
988
+ continue;
989
+ }
990
+ seenCustomUtilities.add(customKey);
991
+ keptUtilities.push(raw);
992
+ for (const conflict of conflicts) {
993
+ superseded.add(`${variantKey}\0${conflict.group}`);
994
+ if (conflict.overrides !== undefined) {
995
+ for (const overridden of conflict.overrides) {
996
+ superseded.add(`${variantKey}\0${overridden}`);
997
+ }
998
+ }
999
+ }
1000
+ continue;
1001
+ }
1002
+ const conflict = classifyUtility(utility, tokens);
1003
+ if (conflict === null) {
1004
+ keptUtilities.push(raw);
1005
+ continue;
1006
+ }
1007
+ const key = `${variantKey}\0${conflict.group}`;
1008
+ if (superseded.has(key))
1009
+ continue;
1010
+ keptUtilities.push(raw);
1011
+ superseded.add(key);
1012
+ if (conflict.overrides !== undefined) {
1013
+ for (const overridden of conflict.overrides) {
1014
+ superseded.add(`${variantKey}\0${overridden}`);
1015
+ }
1016
+ }
1017
+ }
1018
+ keptComponents.reverse();
1019
+ keptUtilities.reverse();
1020
+ if (keptComponents.length === 0)
1021
+ return keptUtilities.join(' ');
1022
+ if (keptUtilities.length === 0)
1023
+ return keptComponents.join(' ');
1024
+ return `${keptComponents.join(' ')} ${keptUtilities.join(' ')}`;
1025
+ }
1026
+ //# sourceMappingURL=core.js.map