tailwind-variants 3.2.1 → 3.3.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.
@@ -0,0 +1,677 @@
1
+ 'use strict';
2
+
3
+ var chunk2BFDQGZN_cjs = require('./chunk-2BFDQGZN.cjs');
4
+
5
+ // src/internal/default-config.ts
6
+ var defaultConfig = {
7
+ twMerge: true,
8
+ twMergeConfig: {}
9
+ };
10
+
11
+ // src/internal/cache.ts
12
+ var VARIANT_CACHE_LIMIT = 256;
13
+ var OVERRIDE_CACHE_LIMIT = 128;
14
+ var CACHE_MISS = /* @__PURE__ */ Symbol("tv-cache-miss");
15
+ var hasClassOverride = (props) => (props == null ? void 0 : props.class) != null && props.class !== "" || (props == null ? void 0 : props.className) != null && props.className !== "";
16
+ var serializeFingerprintValue = (value) => {
17
+ if (value === void 0) return "";
18
+ if (value === null) return "null";
19
+ if (typeof value === "string") return value;
20
+ if (typeof value === "boolean") return value ? "true" : "false";
21
+ if (typeof value === "number") return value === 0 ? "0" : String(value);
22
+ if (typeof value === "bigint") return String(value);
23
+ const mapped = chunk2BFDQGZN_cjs.falsyToString(value);
24
+ const mappedType = typeof mapped;
25
+ if (mappedType === "string" || mappedType === "number" || mappedType === "boolean" || mappedType === "bigint") {
26
+ return String(mapped);
27
+ }
28
+ if (mappedType === "object") {
29
+ try {
30
+ return JSON.stringify(mapped);
31
+ } catch {
32
+ return null;
33
+ }
34
+ }
35
+ return null;
36
+ };
37
+ var appendSignatureValue = (out, value) => {
38
+ if (value === void 0) return out;
39
+ if (value === null) return out + "null";
40
+ const type = typeof value;
41
+ if (type === "string" || type === "number" || type === "boolean" || type === "bigint") {
42
+ return out + String(value);
43
+ }
44
+ if (Array.isArray(value)) {
45
+ return out + value.join("\0");
46
+ }
47
+ try {
48
+ return out + JSON.stringify(value);
49
+ } catch {
50
+ return out + "?";
51
+ }
52
+ };
53
+ var buildPropsFingerprint = (variantKeys, defaultVariants, props, slotProps) => {
54
+ let fingerprint = "";
55
+ const seen = /* @__PURE__ */ Object.create(null);
56
+ for (let i = 0; i < variantKeys.length; i++) {
57
+ const key = variantKeys[i];
58
+ seen[key] = 1;
59
+ let value = defaultVariants[key];
60
+ if (props && props[key] !== void 0) value = props[key];
61
+ if (slotProps && slotProps[key] !== void 0) value = slotProps[key];
62
+ const serialized = serializeFingerprintValue(value);
63
+ if (serialized === null) return null;
64
+ fingerprint += key + ":" + serialized + ";";
65
+ }
66
+ const extras = [];
67
+ for (const key in defaultVariants) {
68
+ if (key === "class" || key === "className" || seen[key]) continue;
69
+ seen[key] = 1;
70
+ extras.push(key);
71
+ }
72
+ if (props) {
73
+ for (const key in props) {
74
+ if (key === "class" || key === "className" || seen[key] || props[key] === void 0) continue;
75
+ seen[key] = 1;
76
+ extras.push(key);
77
+ }
78
+ }
79
+ if (slotProps) {
80
+ for (const key in slotProps) {
81
+ if (key === "class" || key === "className" || seen[key] || slotProps[key] === void 0) {
82
+ continue;
83
+ }
84
+ seen[key] = 1;
85
+ extras.push(key);
86
+ }
87
+ }
88
+ if (extras.length > 1) extras.sort();
89
+ for (let i = 0; i < extras.length; i++) {
90
+ const key = extras[i];
91
+ let value = defaultVariants[key];
92
+ if (props && props[key] !== void 0) value = props[key];
93
+ if (slotProps && slotProps[key] !== void 0) value = slotProps[key];
94
+ const serialized = serializeFingerprintValue(value);
95
+ if (serialized === null) return null;
96
+ fingerprint += key + ":" + serialized + ";";
97
+ }
98
+ return fingerprint;
99
+ };
100
+ var buildCompoundsSignature = (compoundVariants, compoundSlots) => {
101
+ let signature = "";
102
+ for (let i = 0; i < compoundVariants.length; i++) {
103
+ const { conditionKeys, source } = compoundVariants[i];
104
+ for (let j = 0; j < conditionKeys.length; j++) {
105
+ const key = conditionKeys[j];
106
+ signature += key + "=";
107
+ signature = appendSignatureValue(signature, source[key]);
108
+ signature += ",";
109
+ }
110
+ signature += "c=";
111
+ signature = appendSignatureValue(signature, source.class);
112
+ signature += "|cn=";
113
+ signature = appendSignatureValue(signature, source.className);
114
+ signature += ";";
115
+ }
116
+ for (let i = 0; i < compoundSlots.length; i++) {
117
+ const { conditionKeys, source } = compoundSlots[i];
118
+ for (let j = 0; j < conditionKeys.length; j++) {
119
+ const key = conditionKeys[j];
120
+ signature += key + "=";
121
+ signature = appendSignatureValue(signature, source[key]);
122
+ signature += ",";
123
+ }
124
+ if (Array.isArray(source.slots)) {
125
+ signature += "slots=" + source.slots.join(",") + ",";
126
+ }
127
+ signature += "c=";
128
+ signature = appendSignatureValue(signature, source.class);
129
+ signature += "|cn=";
130
+ signature = appendSignatureValue(signature, source.className);
131
+ signature += ";";
132
+ }
133
+ return signature;
134
+ };
135
+ var createResultCache = (limit = VARIANT_CACHE_LIMIT) => {
136
+ let primary = /* @__PURE__ */ new Map();
137
+ let secondary = null;
138
+ return {
139
+ get(key) {
140
+ let value = primary.get(key);
141
+ if (value !== void 0 || primary.has(key)) return value;
142
+ if (secondary) {
143
+ value = secondary.get(key);
144
+ if (value !== void 0 || secondary.has(key)) {
145
+ primary.set(key, value);
146
+ return value;
147
+ }
148
+ }
149
+ return CACHE_MISS;
150
+ },
151
+ set(key, value) {
152
+ if (primary.size >= limit) {
153
+ secondary = primary;
154
+ primary = /* @__PURE__ */ new Map();
155
+ }
156
+ primary.set(key, value);
157
+ }
158
+ };
159
+ };
160
+ var createNestedOverrideCache = (limit = OVERRIDE_CACHE_LIMIT) => {
161
+ let primary = /* @__PURE__ */ new Map();
162
+ let secondary = null;
163
+ let size = 0;
164
+ return {
165
+ get(coreKey, overrideKey) {
166
+ const primaryInner = primary.get(coreKey);
167
+ if (primaryInner) {
168
+ const value = primaryInner.get(overrideKey);
169
+ if (value !== void 0 || primaryInner.has(overrideKey)) return value;
170
+ }
171
+ if (secondary) {
172
+ const secondaryInner = secondary.get(coreKey);
173
+ if (secondaryInner) {
174
+ const value = secondaryInner.get(overrideKey);
175
+ if (value !== void 0 || secondaryInner.has(overrideKey)) {
176
+ let promoteInner = primary.get(coreKey);
177
+ if (!promoteInner) {
178
+ promoteInner = /* @__PURE__ */ new Map();
179
+ primary.set(coreKey, promoteInner);
180
+ }
181
+ if (!promoteInner.has(overrideKey)) size++;
182
+ promoteInner.set(overrideKey, value);
183
+ return value;
184
+ }
185
+ }
186
+ }
187
+ return CACHE_MISS;
188
+ },
189
+ set(coreKey, overrideKey, value) {
190
+ if (size >= limit) {
191
+ secondary = primary;
192
+ primary = /* @__PURE__ */ new Map();
193
+ size = 0;
194
+ }
195
+ let inner = primary.get(coreKey);
196
+ if (!inner) {
197
+ inner = /* @__PURE__ */ new Map();
198
+ primary.set(coreKey, inner);
199
+ }
200
+ if (!inner.has(overrideKey)) size++;
201
+ inner.set(overrideKey, value);
202
+ }
203
+ };
204
+ };
205
+ var createLazyOverrideMerge = (cn, config) => {
206
+ let cache = null;
207
+ return (core, props) => {
208
+ if (!hasClassOverride(props)) return core;
209
+ const classVal = props.class;
210
+ const classNameVal = props.className;
211
+ if (classVal != null && classVal !== "" && typeof classVal !== "string" || classNameVal != null && classNameVal !== "" && typeof classNameVal !== "string") {
212
+ return cn(config, core, classVal, classNameVal);
213
+ }
214
+ cache ??= createNestedOverrideCache();
215
+ const coreKey = core ?? "";
216
+ const overrideKey = (typeof classVal === "string" ? classVal : "") + "\0" + (typeof classNameVal === "string" ? classNameVal : "");
217
+ const cached = cache.get(coreKey, overrideKey);
218
+ if (cached !== CACHE_MISS) return cached;
219
+ const merged = cn(config, core, classVal, classNameVal);
220
+ cache.set(coreKey, overrideKey, merged);
221
+ return merged;
222
+ };
223
+ };
224
+
225
+ // src/internal/state.ts
226
+ function createState() {
227
+ let cachedTwMerge = null;
228
+ let cachedTwMergeConfig = {};
229
+ let didTwMergeConfigChange = false;
230
+ return {
231
+ get cachedTwMerge() {
232
+ return cachedTwMerge;
233
+ },
234
+ set cachedTwMerge(value) {
235
+ cachedTwMerge = value;
236
+ },
237
+ get cachedTwMergeConfig() {
238
+ return cachedTwMergeConfig;
239
+ },
240
+ set cachedTwMergeConfig(value) {
241
+ cachedTwMergeConfig = value;
242
+ },
243
+ get didTwMergeConfigChange() {
244
+ return didTwMergeConfigChange;
245
+ },
246
+ set didTwMergeConfigChange(value) {
247
+ didTwMergeConfigChange = value;
248
+ },
249
+ reset() {
250
+ cachedTwMerge = null;
251
+ cachedTwMergeConfig = {};
252
+ didTwMergeConfigChange = false;
253
+ }
254
+ };
255
+ }
256
+ var state = createState();
257
+
258
+ // src/internal/resolve-options.ts
259
+ var synchronizeTwMergeConfig = (config) => {
260
+ if (!chunk2BFDQGZN_cjs.isEmptyObject(config.twMergeConfig) && !chunk2BFDQGZN_cjs.isEqual(config.twMergeConfig, state.cachedTwMergeConfig)) {
261
+ state.didTwMergeConfigChange = true;
262
+ state.cachedTwMergeConfig = config.twMergeConfig;
263
+ }
264
+ };
265
+ var compileVariants = (variants, variantKeys) => {
266
+ const compiledVariants = [];
267
+ for (let i = 0; i < variantKeys.length; i++) {
268
+ const key = variantKeys[i];
269
+ const values = variants[key];
270
+ compiledVariants.push({ key, values, isEmpty: chunk2BFDQGZN_cjs.isEmptyObject(values) });
271
+ }
272
+ return compiledVariants;
273
+ };
274
+ var compileCompoundVariants = (compoundVariants) => {
275
+ if (!Array.isArray(compoundVariants) || compoundVariants.length === 0) return [];
276
+ const result = [];
277
+ for (let i = 0; i < compoundVariants.length; i++) {
278
+ const compoundVariant = compoundVariants[i];
279
+ const conditionKeys = [];
280
+ for (const key in compoundVariant) {
281
+ if (key !== "class" && key !== "className") {
282
+ conditionKeys.push(key);
283
+ }
284
+ }
285
+ result.push({ conditionKeys, source: compoundVariant });
286
+ }
287
+ return result;
288
+ };
289
+ var compileCompoundSlots = (compoundSlots) => {
290
+ if (!Array.isArray(compoundSlots) || compoundSlots.length === 0) return [];
291
+ const result = [];
292
+ for (let i = 0; i < compoundSlots.length; i++) {
293
+ const compoundSlot = compoundSlots[i];
294
+ const conditionKeys = [];
295
+ for (const key in compoundSlot) {
296
+ if (key !== "slots" && key !== "class" && key !== "className") {
297
+ conditionKeys.push(key);
298
+ }
299
+ }
300
+ result.push({ conditionKeys, source: compoundSlot });
301
+ }
302
+ return result;
303
+ };
304
+ var indexCompoundSlotsBySlot = (compiledCompoundSlots) => {
305
+ const index = {};
306
+ for (let i = 0; i < compiledCompoundSlots.length; i++) {
307
+ const compoundSlot = compiledCompoundSlots[i];
308
+ const slots = compoundSlot.source.slots;
309
+ if (!Array.isArray(slots)) continue;
310
+ for (let j = 0; j < slots.length; j++) {
311
+ const slotKey = slots[j];
312
+ if (!index[slotKey]) index[slotKey] = [];
313
+ index[slotKey].push(compoundSlot);
314
+ }
315
+ }
316
+ return index;
317
+ };
318
+ var resolveOptions = (options, configProp) => {
319
+ const {
320
+ extend = null,
321
+ slots: slotProps = {},
322
+ variants: variantsProps = {},
323
+ compoundVariants: compoundVariantsProps = [],
324
+ compoundSlots: compoundSlotsProps = [],
325
+ defaultVariants: defaultVariantsProps = {}
326
+ } = options;
327
+ const config = { ...defaultConfig, ...configProp };
328
+ const hasSlots = options.slots !== void 0;
329
+ const base = (extend == null ? void 0 : extend.base) ? chunk2BFDQGZN_cjs.cx(extend.base, options == null ? void 0 : options.base) : options == null ? void 0 : options.base;
330
+ const variants = (extend == null ? void 0 : extend.variants) && !chunk2BFDQGZN_cjs.isEmptyObject(extend.variants) ? chunk2BFDQGZN_cjs.mergeObjects(variantsProps, extend.variants) : variantsProps;
331
+ const defaultVariants = (extend == null ? void 0 : extend.defaultVariants) && !chunk2BFDQGZN_cjs.isEmptyObject(extend.defaultVariants) ? { ...extend.defaultVariants, ...defaultVariantsProps } : defaultVariantsProps;
332
+ synchronizeTwMergeConfig(config);
333
+ const isExtendedSlotsEmpty = !(extend == null ? void 0 : extend.slots) || chunk2BFDQGZN_cjs.isEmptyObject(extend.slots);
334
+ const componentBase = hasSlots ? isExtendedSlotsEmpty && (extend == null ? void 0 : extend.base) ? chunk2BFDQGZN_cjs.cx(options == null ? void 0 : options.base, extend.base) : typeof (options == null ? void 0 : options.base) === "string" || (options == null ? void 0 : options.base) == null ? options.base : chunk2BFDQGZN_cjs.cx(options.base) : void 0;
335
+ const componentSlots = hasSlots ? {
336
+ base: componentBase,
337
+ ...slotProps
338
+ } : {};
339
+ const slots = isExtendedSlotsEmpty ? componentSlots : chunk2BFDQGZN_cjs.joinObjects(
340
+ { ...extend == null ? void 0 : extend.slots },
341
+ chunk2BFDQGZN_cjs.isEmptyObject(componentSlots) ? { base: options == null ? void 0 : options.base } : componentSlots
342
+ );
343
+ const compoundVariants = !(extend == null ? void 0 : extend.compoundVariants) || chunk2BFDQGZN_cjs.isEmptyObject(extend.compoundVariants) ? compoundVariantsProps : chunk2BFDQGZN_cjs.flatMergeArrays(extend == null ? void 0 : extend.compoundVariants, compoundVariantsProps);
344
+ const compoundSlots = !(extend == null ? void 0 : extend.compoundSlots) || chunk2BFDQGZN_cjs.isEmptyObject(extend.compoundSlots) ? compoundSlotsProps : chunk2BFDQGZN_cjs.flatMergeArrays(extend == null ? void 0 : extend.compoundSlots, compoundSlotsProps);
345
+ const variantKeys = Object.keys(variants);
346
+ const deferredError = compoundVariants && !Array.isArray(compoundVariants) ? new TypeError(
347
+ `The "compoundVariants" prop must be an array. Received: ${typeof compoundVariants}`
348
+ ) : compoundSlots && !Array.isArray(compoundSlots) ? new TypeError(
349
+ `The "compoundSlots" prop must be an array. Received: ${typeof compoundSlots}`
350
+ ) : null;
351
+ const mode = hasSlots || !isExtendedSlotsEmpty ? "slots" : variantKeys.length === 0 ? "plain" : "variants";
352
+ return {
353
+ config,
354
+ extend,
355
+ base,
356
+ variants,
357
+ defaultVariants,
358
+ slots,
359
+ compoundVariants,
360
+ compoundSlots,
361
+ compiledVariants: null,
362
+ compiledCompoundVariants: null,
363
+ compiledCompoundSlots: null,
364
+ compiledCompoundSlotsBySlot: null,
365
+ deferredError,
366
+ mode,
367
+ slotKeys: null,
368
+ variantKeys
369
+ };
370
+ };
371
+ var compileResolvedOptions = (resolved) => {
372
+ if (resolved.compiledVariants !== null) return resolved;
373
+ resolved.compiledVariants = compileVariants(resolved.variants, resolved.variantKeys);
374
+ resolved.compiledCompoundVariants = compileCompoundVariants(resolved.compoundVariants);
375
+ resolved.compiledCompoundSlots = compileCompoundSlots(resolved.compoundSlots);
376
+ resolved.compiledCompoundSlotsBySlot = indexCompoundSlotsBySlot(resolved.compiledCompoundSlots);
377
+ resolved.slotKeys = resolved.slots && typeof resolved.slots === "object" ? Object.keys(resolved.slots) : [];
378
+ return resolved;
379
+ };
380
+
381
+ // src/internal/class-resolver.ts
382
+ var EMPTY_ARRAY = [];
383
+ var variantClassesScratch = [];
384
+ var compoundClassesScratch = [];
385
+ var compoundVariantBySlotScratch = [];
386
+ var compoundSlotClassesScratch = [];
387
+ var getCompleteProps = (defaultVariants, props, slotProps) => {
388
+ const result = {};
389
+ for (const key in defaultVariants) {
390
+ result[key] = defaultVariants[key];
391
+ }
392
+ if (props) {
393
+ for (const key in props) {
394
+ if (props[key] !== void 0) result[key] = props[key];
395
+ }
396
+ }
397
+ if (slotProps) {
398
+ for (const key in slotProps) {
399
+ if (slotProps[key] !== void 0) result[key] = slotProps[key];
400
+ }
401
+ }
402
+ return result;
403
+ };
404
+ var isNullishOrFalse = (value) => value == null || value === false;
405
+ var matchesCompoundValue = (expected, actual) => {
406
+ if (!Array.isArray(expected)) {
407
+ return expected === actual || isNullishOrFalse(expected) && isNullishOrFalse(actual);
408
+ }
409
+ for (let i = 0; i < expected.length; i++) {
410
+ const expectedValue = expected[i];
411
+ if (expectedValue === actual || isNullishOrFalse(expectedValue) && isNullishOrFalse(actual)) {
412
+ return true;
413
+ }
414
+ }
415
+ return false;
416
+ };
417
+ var getVariantValue = (variant, defaultVariants, props, slotProps) => {
418
+ if (variant.isEmpty) return null;
419
+ const variantProp = (slotProps == null ? void 0 : slotProps[variant.key]) ?? (props == null ? void 0 : props[variant.key]);
420
+ if (variantProp === null) return null;
421
+ const variantKey = chunk2BFDQGZN_cjs.falsyToString(variantProp);
422
+ if (typeof variantKey === "object") return null;
423
+ const defaultVariantProp = defaultVariants == null ? void 0 : defaultVariants[variant.key];
424
+ const key = variantKey != null ? variantKey : chunk2BFDQGZN_cjs.falsyToString(defaultVariantProp);
425
+ return variant.values[key || "false"];
426
+ };
427
+ var matchesConditions = (compound, completeProps) => {
428
+ const { conditionKeys, source } = compound;
429
+ for (let i = 0; i < conditionKeys.length; i++) {
430
+ const key = conditionKeys[i];
431
+ if (!matchesCompoundValue(source[key], completeProps[key])) return false;
432
+ }
433
+ return true;
434
+ };
435
+ var pushCompoundClassForSlot = (result, slotKey, classValue) => {
436
+ if (typeof classValue === "string") {
437
+ if (slotKey === "base") result.push(classValue);
438
+ } else if (classValue && typeof classValue === "object" && classValue[slotKey]) {
439
+ result.push(classValue[slotKey]);
440
+ }
441
+ };
442
+ var getVariantClassNames = (variants, defaultVariants, props) => {
443
+ const result = variantClassesScratch;
444
+ result.length = 0;
445
+ for (let i = 0; i < variants.length; i++) {
446
+ const value = getVariantValue(variants[i], defaultVariants, props);
447
+ if (value) result.push(value);
448
+ }
449
+ return result;
450
+ };
451
+ var getVariantClassNamesBySlot = (slotKey, variants, defaultVariants, props, slotProps) => {
452
+ const result = variantClassesScratch;
453
+ result.length = 0;
454
+ for (let i = 0; i < variants.length; i++) {
455
+ const variantValue = getVariantValue(variants[i], defaultVariants, props, slotProps);
456
+ const value = slotKey === "base" && typeof variantValue === "string" ? variantValue : variantValue && variantValue[slotKey];
457
+ if (value) result.push(value);
458
+ }
459
+ return result;
460
+ };
461
+ var getCompoundVariantClasses = (compoundVariants, completeProps) => {
462
+ const result = compoundClassesScratch;
463
+ result.length = 0;
464
+ for (let i = 0; i < compoundVariants.length; i++) {
465
+ const compoundVariant = compoundVariants[i];
466
+ if (!matchesConditions(compoundVariant, completeProps)) continue;
467
+ if (compoundVariant.source.class) result.push(compoundVariant.source.class);
468
+ if (compoundVariant.source.className) result.push(compoundVariant.source.className);
469
+ }
470
+ return result;
471
+ };
472
+ var getCompoundVariantClassesBySlot = (slotKey, compoundVariants, completeProps) => {
473
+ const result = compoundVariantBySlotScratch;
474
+ result.length = 0;
475
+ for (let i = 0; i < compoundVariants.length; i++) {
476
+ const compoundVariant = compoundVariants[i];
477
+ if (!matchesConditions(compoundVariant, completeProps)) continue;
478
+ pushCompoundClassForSlot(result, slotKey, compoundVariant.source.class);
479
+ pushCompoundClassForSlot(result, slotKey, compoundVariant.source.className);
480
+ }
481
+ return result;
482
+ };
483
+ var getCompoundSlotClasses = (compoundSlotsForKey, completeProps) => {
484
+ const result = compoundSlotClassesScratch;
485
+ result.length = 0;
486
+ for (let i = 0; i < compoundSlotsForKey.length; i++) {
487
+ const compoundSlot = compoundSlotsForKey[i];
488
+ if (!matchesConditions(compoundSlot, completeProps)) continue;
489
+ if (compoundSlot.source.class) result.push(compoundSlot.source.class);
490
+ if (compoundSlot.source.className) result.push(compoundSlot.source.className);
491
+ }
492
+ return result;
493
+ };
494
+ var createPlainResolver = (resolved, cn) => {
495
+ const { base, config } = resolved;
496
+ let core = CACHE_MISS;
497
+ const mergeOverride = createLazyOverrideMerge(cn, config);
498
+ return ((props) => {
499
+ if (core === CACHE_MISS) {
500
+ core = cn(config, base);
501
+ }
502
+ return mergeOverride(core, props);
503
+ });
504
+ };
505
+ var createVariantResolver = (resolved, cn) => {
506
+ const { base, config, defaultVariants, deferredError, variantKeys } = resolved;
507
+ let compiledCompoundVariants = resolved.compiledCompoundVariants;
508
+ let compiledVariants = resolved.compiledVariants;
509
+ let compiledCompoundSlots = EMPTY_ARRAY;
510
+ let cache = null;
511
+ const mergeOverride = createLazyOverrideMerge(cn, config);
512
+ let coldInvokesRemaining = 1;
513
+ const computeCore = (props) => {
514
+ const compoundClasses = compiledCompoundVariants.length > 0 ? getCompoundVariantClasses(
515
+ compiledCompoundVariants,
516
+ getCompleteProps(defaultVariants, props)
517
+ ) : void 0;
518
+ return cn(
519
+ config,
520
+ base,
521
+ getVariantClassNames(compiledVariants, defaultVariants, props),
522
+ compoundClasses
523
+ );
524
+ };
525
+ return ((props) => {
526
+ if (deferredError) throw deferredError;
527
+ if (compiledVariants === null || compiledCompoundVariants === null) {
528
+ compileResolvedOptions(resolved);
529
+ compiledVariants = resolved.compiledVariants;
530
+ compiledCompoundVariants = resolved.compiledCompoundVariants;
531
+ compiledCompoundSlots = resolved.compiledCompoundSlots ?? EMPTY_ARRAY;
532
+ }
533
+ let core;
534
+ if (coldInvokesRemaining > 0) {
535
+ coldInvokesRemaining--;
536
+ core = computeCore(props);
537
+ } else {
538
+ cache ??= createResultCache();
539
+ const propsFingerprint = buildPropsFingerprint(variantKeys, defaultVariants, props);
540
+ if (propsFingerprint !== null) {
541
+ const compoundsSig = compiledCompoundVariants.length > 0 || compiledCompoundSlots.length > 0 ? buildCompoundsSignature(compiledCompoundVariants, compiledCompoundSlots) : "";
542
+ const cacheKey = propsFingerprint + "#" + compoundsSig;
543
+ const cached = cache.get(cacheKey);
544
+ if (cached !== CACHE_MISS) {
545
+ core = cached;
546
+ } else {
547
+ core = computeCore(props);
548
+ cache.set(cacheKey, core);
549
+ }
550
+ } else {
551
+ core = computeCore(props);
552
+ }
553
+ }
554
+ return mergeOverride(core, props);
555
+ });
556
+ };
557
+ var createSlotsResolver = (resolved, cn) => {
558
+ const { config, defaultVariants, deferredError, slots, variantKeys } = resolved;
559
+ let currentProps;
560
+ let currentCompoundsSig = "";
561
+ let useResultCache = false;
562
+ let coldParentInvokesRemaining = 1;
563
+ let slotsFns = null;
564
+ return ((props) => {
565
+ if (deferredError) throw deferredError;
566
+ if (slotsFns === null) {
567
+ if (resolved.compiledVariants === null || resolved.compiledCompoundVariants === null || resolved.compiledCompoundSlots === null || resolved.compiledCompoundSlotsBySlot === null || resolved.slotKeys === null) {
568
+ compileResolvedOptions(resolved);
569
+ }
570
+ const variants = resolved.compiledVariants;
571
+ const compoundVariants = resolved.compiledCompoundVariants;
572
+ const compoundSlots = resolved.compiledCompoundSlots;
573
+ const compoundSlotsBySlot = resolved.compiledCompoundSlotsBySlot;
574
+ const keys = resolved.slotKeys;
575
+ const hasCompounds = compoundVariants.length > 0 || compoundSlots.length > 0;
576
+ let cache = null;
577
+ const mergeOverride = createLazyOverrideMerge(cn, config);
578
+ const nextSlotsFns = {};
579
+ for (let i = 0; i < keys.length; i++) {
580
+ const slotKey = keys[i];
581
+ const compoundSlotsForKey = compoundSlotsBySlot[slotKey] ?? EMPTY_ARRAY;
582
+ const computeCore = (propsRef, slotProps) => {
583
+ const completeProps = hasCompounds ? getCompleteProps(defaultVariants, propsRef, slotProps) : void 0;
584
+ const compoundVariantClasses = completeProps ? getCompoundVariantClassesBySlot(slotKey, compoundVariants, completeProps) : void 0;
585
+ const compoundSlotClasses = completeProps ? getCompoundSlotClasses(compoundSlotsForKey, completeProps) : void 0;
586
+ return cn(
587
+ config,
588
+ slots[slotKey],
589
+ getVariantClassNamesBySlot(slotKey, variants, defaultVariants, propsRef, slotProps),
590
+ compoundVariantClasses,
591
+ compoundSlotClasses
592
+ );
593
+ };
594
+ nextSlotsFns[slotKey] = (slotProps) => {
595
+ const propsRef = currentProps;
596
+ let core;
597
+ if (!useResultCache) {
598
+ core = computeCore(propsRef, slotProps);
599
+ } else {
600
+ cache ??= createResultCache();
601
+ const propsFingerprint = buildPropsFingerprint(
602
+ variantKeys,
603
+ defaultVariants,
604
+ propsRef,
605
+ slotProps
606
+ );
607
+ if (propsFingerprint !== null) {
608
+ const cacheKey = slotKey + "|" + propsFingerprint + "#" + currentCompoundsSig;
609
+ const cached = cache.get(cacheKey);
610
+ if (cached !== CACHE_MISS) {
611
+ core = cached;
612
+ } else {
613
+ core = computeCore(propsRef, slotProps);
614
+ cache.set(cacheKey, core);
615
+ }
616
+ } else {
617
+ core = computeCore(propsRef, slotProps);
618
+ }
619
+ }
620
+ return mergeOverride(core, slotProps);
621
+ };
622
+ }
623
+ slotsFns = nextSlotsFns;
624
+ }
625
+ currentProps = props;
626
+ if (coldParentInvokesRemaining > 0) {
627
+ coldParentInvokesRemaining--;
628
+ useResultCache = false;
629
+ currentCompoundsSig = "";
630
+ } else {
631
+ useResultCache = true;
632
+ const compoundVariants = resolved.compiledCompoundVariants;
633
+ const compoundSlots = resolved.compiledCompoundSlots;
634
+ currentCompoundsSig = compoundVariants && compoundSlots && (compoundVariants.length > 0 || compoundSlots.length > 0) ? buildCompoundsSignature(compoundVariants, compoundSlots) : "";
635
+ }
636
+ return slotsFns;
637
+ });
638
+ };
639
+ var createClassResolver = (resolved, cn) => {
640
+ if (resolved.mode === "plain") return createPlainResolver(resolved, cn);
641
+ let resolver;
642
+ return ((props) => {
643
+ resolver ??= resolved.mode === "slots" ? createSlotsResolver(resolved, cn) : createVariantResolver(resolved, cn);
644
+ return resolver(props);
645
+ });
646
+ };
647
+
648
+ // src/internal/tv.ts
649
+ var attachComponentMetadata = (component, resolved) => {
650
+ component.variantKeys = resolved.variantKeys;
651
+ component.extend = resolved.extend;
652
+ component.base = resolved.base;
653
+ component.slots = resolved.slots;
654
+ component.variants = resolved.variants;
655
+ component.defaultVariants = resolved.defaultVariants;
656
+ component.compoundSlots = resolved.compoundSlots;
657
+ component.compoundVariants = resolved.compoundVariants;
658
+ };
659
+ var getTailwindVariants = (cn) => {
660
+ const tv = (options, configProp) => {
661
+ const resolved = resolveOptions(options, configProp);
662
+ const component = createClassResolver(resolved, cn);
663
+ attachComponentMetadata(component, resolved);
664
+ return component;
665
+ };
666
+ const createTV = (configProp) => {
667
+ return (options, config) => tv(options, config ? chunk2BFDQGZN_cjs.mergeObjects(configProp, config) : configProp);
668
+ };
669
+ return {
670
+ tv,
671
+ createTV
672
+ };
673
+ };
674
+
675
+ exports.defaultConfig = defaultConfig;
676
+ exports.getTailwindVariants = getTailwindVariants;
677
+ exports.state = state;