@kbach/ui 0.1.0-beta.7 → 1.0.0-beta.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.
@@ -1,4027 +0,0 @@
1
- // src/vite-plugin.ts
2
- import { readFileSync, writeFileSync, unlinkSync, readdirSync, statSync } from "fs";
3
- import { join, relative } from "path";
4
- import processImport from "process";
5
-
6
- // src/core/platform.ts
7
- var isWeb = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
8
- var isNative = !isWeb && (typeof globalThis.HermesInternal !== "undefined" || typeof globalThis.__fbBatchedBridge !== "undefined" || typeof navigator !== "undefined" && navigator.product === "ReactNative" || typeof globalThis.__REACT_NATIVE__ !== "undefined" || typeof globalThis.nativeFabricUIManager !== "undefined" || typeof globalThis.__turboModuleProxy !== "undefined" || typeof globalThis.RN$Bridgeless !== "undefined" || typeof globalThis.nativePerformanceNow !== "undefined");
9
- var _resolveTargetOverride = null;
10
- function setCSSGenMode(on) {
11
- _resolveTargetOverride = on ? "web" : null;
12
- }
13
- function getEffectiveIsWeb() {
14
- if (_resolveTargetOverride) return _resolveTargetOverride === "web";
15
- return isWeb || !isNative;
16
- }
17
- function toNativeValue(raw) {
18
- if (/^-?\d+(\.\d+)?px$/.test(raw)) return parseFloat(raw);
19
- if (/^-?\d+(\.\d+)?rem$/.test(raw)) return parseFloat(raw) * 16;
20
- if (/^-?\d+(\.\d+)?em$/.test(raw)) return parseFloat(raw) * 16;
21
- if (/^-?\d+(\.\d+)?$/.test(raw)) return parseFloat(raw);
22
- return raw;
23
- }
24
- function escapeCSSSelector(cls) {
25
- const escaped = cls.replace(/[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g, "\\$&");
26
- if (!/^[0-9]/.test(escaped)) return escaped;
27
- const hex = escaped.charCodeAt(0).toString(16);
28
- return `\\${hex} ${escaped.slice(1)}`;
29
- }
30
-
31
- // src/core/reset.ts
32
- var RESET_STYLE_ID = "kbach-reset";
33
- var BASE_RESET = [
34
- // border-style: solid means border-N utilities show a visible border without an extra border-solid class.
35
- // border-width: 0 keeps all elements borderless by default.
36
- "*, *::before, *::after { box-sizing: border-box; border-width: 0; border-style: solid; border-color: currentColor; }",
37
- "body { margin: 0; padding: 0; }",
38
- "h1, h2, h3, h4, h5, h6 { margin: 0; font-size: inherit; font-weight: inherit; }",
39
- "p { margin: 0; }",
40
- "a { color: inherit; text-decoration: none; }",
41
- "ul, ol { margin: 0; padding: 0; list-style: none; }",
42
- "img, video, svg { display: block; max-width: 100%; }",
43
- // appearance: none is deliberately NOT applied to checkbox/radio/select below —
44
- // stripping it hides their native checkmark/arrow with nothing rendered in its
45
- // place, leaving an invisible checkbox or an arrow-less <select> that looks like
46
- // plain text. Text-like inputs, textarea, and button don't have that problem
47
- // (their native chrome is just a skin around content utilities can fully
48
- // restyle), so they keep the blank-canvas treatment.
49
- // :where() wraps the :not() exclusions so they contribute ZERO specificity
50
- // (unlike a bare `input:not([type='checkbox']):not([type='radio'])`, whose
51
- // two :not([attr]) clauses each add a class-level specificity point — (0,2,1)
52
- // total, MORE than any single utility class (0,1,0)). Without :where(), this
53
- // reset's `color: inherit` always won the cascade over a text-* color
54
- // utility applied directly to a <input>/<textarea> regardless of source
55
- // order, since author rules only override on a tie or higher specificity —
56
- // confirmed on a real app: a TextInput's own text color utility resolved
57
- // and injected correctly, class and all, but silently never painted.
58
- "input:where(:not([type='checkbox']):not([type='radio'])), textarea { appearance: none; -webkit-appearance: none; background: transparent; padding: 0; margin: 0; font: inherit; color: inherit; line-height: inherit; }",
59
- // Native checkbox/radio/range still get typography + spacing normalized, and
60
- // accent-color re-themes their native indicator to the current text color
61
- // instead of the browser/OS default blue, so they stay on-brand without
62
- // needing to be rebuilt from scratch.
63
- "input[type='checkbox'], input[type='radio'], input[type='range'] { margin: 0; font: inherit; accent-color: currentColor; }",
64
- // select keeps its native chrome (border/background/arrow are all part of the
65
- // same OS-drawn widget that appearance: none would blank out) — only typography
66
- // and spacing are normalized so it still matches surrounding text.
67
- "select { margin: 0; font: inherit; color: inherit; line-height: inherit; }",
68
- "button { appearance: none; -webkit-appearance: none; background: transparent; padding: 0; margin: 0; font: inherit; color: inherit; cursor: pointer; line-height: inherit; text-align: inherit; }",
69
- "button, [role='button'] { cursor: pointer; }",
70
- ":disabled { cursor: default; }",
71
- "textarea { resize: vertical; }",
72
- // Firefox renders placeholders at ~54% opacity by default; every other browser uses 1 —
73
- // normalize to 1 so placeholder color is consistent and fully controlled by the placeholder: modifier.
74
- "::placeholder { opacity: 1; }",
75
- "input[type='number']::-webkit-inner-spin-button, input[type='number']::-webkit-outer-spin-button { margin: 0; }",
76
- "input[type='search']::-webkit-search-decoration, input[type='search']::-webkit-search-cancel-button { -webkit-appearance: none; }",
77
- "fieldset { padding: 0; margin: 0; }",
78
- "table { border-collapse: collapse; border-spacing: 0; }"
79
- ].join("\n");
80
-
81
- // src/core/theme.ts
82
- var defaultColors = {
83
- transparent: "transparent",
84
- current: "currentColor",
85
- black: "#000000",
86
- white: "#ffffff",
87
- slate: {
88
- 1: "#f8fafc",
89
- 2: "#f1f5f9",
90
- 3: "#e2e8f0",
91
- 4: "#cbd5e1",
92
- 5: "#94a3b8",
93
- 6: "#64748b",
94
- 7: "#475569",
95
- 8: "#334155",
96
- 9: "#1e293b",
97
- 10: "#0f172a",
98
- 11: "#020617",
99
- 12: "#01020a"
100
- },
101
- gray: {
102
- 1: "#f9fafb",
103
- 2: "#f3f4f6",
104
- 3: "#e5e7eb",
105
- 4: "#d1d5db",
106
- 5: "#9ca3af",
107
- 6: "#6b7280",
108
- 7: "#4b5563",
109
- 8: "#374151",
110
- 9: "#1f2937",
111
- 10: "#111827",
112
- 11: "#030712",
113
- 12: "#020409"
114
- },
115
- zinc: {
116
- 1: "#fafafa",
117
- 2: "#f4f4f5",
118
- 3: "#e4e4e7",
119
- 4: "#d4d4d8",
120
- 5: "#a1a1aa",
121
- 6: "#71717a",
122
- 7: "#52525b",
123
- 8: "#3f3f46",
124
- 9: "#27272a",
125
- 10: "#18181b",
126
- 11: "#09090b",
127
- 12: "#050506"
128
- },
129
- neutral: {
130
- 1: "#fafafa",
131
- 2: "#f5f5f5",
132
- 3: "#e5e5e5",
133
- 4: "#d4d4d4",
134
- 5: "#a3a3a3",
135
- 6: "#737373",
136
- 7: "#525252",
137
- 8: "#404040",
138
- 9: "#262626",
139
- 10: "#171717",
140
- 11: "#0a0a0a",
141
- 12: "#050505"
142
- },
143
- stone: {
144
- 1: "#fafaf9",
145
- 2: "#f5f5f4",
146
- 3: "#e7e5e4",
147
- 4: "#d6d3d1",
148
- 5: "#a8a29e",
149
- 6: "#78716c",
150
- 7: "#57534e",
151
- 8: "#44403c",
152
- 9: "#292524",
153
- 10: "#1c1917",
154
- 11: "#0c0a09",
155
- 12: "#070605"
156
- },
157
- red: {
158
- 1: "#fef2f2",
159
- 2: "#fee2e2",
160
- 3: "#fecaca",
161
- 4: "#fca5a5",
162
- 5: "#f87171",
163
- 6: "#ef4444",
164
- 7: "#dc2626",
165
- 8: "#b91c1c",
166
- 9: "#991b1b",
167
- 10: "#7f1d1d",
168
- 11: "#450a0a",
169
- 12: "#280606"
170
- },
171
- orange: {
172
- 1: "#fff7ed",
173
- 2: "#ffedd5",
174
- 3: "#fed7aa",
175
- 4: "#fdba74",
176
- 5: "#fb923c",
177
- 6: "#f97316",
178
- 7: "#ea580c",
179
- 8: "#c2410c",
180
- 9: "#9a3412",
181
- 10: "#7c2d12",
182
- 11: "#431407",
183
- 12: "#270c04"
184
- },
185
- amber: {
186
- 1: "#fffbeb",
187
- 2: "#fef3c7",
188
- 3: "#fde68a",
189
- 4: "#fcd34d",
190
- 5: "#fbbf24",
191
- 6: "#f59e0b",
192
- 7: "#d97706",
193
- 8: "#b45309",
194
- 9: "#92400e",
195
- 10: "#78350f",
196
- 11: "#451a03",
197
- 12: "#291002"
198
- },
199
- yellow: {
200
- 1: "#fefce8",
201
- 2: "#fef9c3",
202
- 3: "#fef08a",
203
- 4: "#fde047",
204
- 5: "#facc15",
205
- 6: "#eab308",
206
- 7: "#ca8a04",
207
- 8: "#a16207",
208
- 9: "#854d0e",
209
- 10: "#713f12",
210
- 11: "#422006",
211
- 12: "#271304"
212
- },
213
- lime: {
214
- 1: "#f7fee7",
215
- 2: "#ecfccb",
216
- 3: "#d9f99d",
217
- 4: "#bef264",
218
- 5: "#a3e635",
219
- 6: "#84cc16",
220
- 7: "#65a30d",
221
- 8: "#4d7c0f",
222
- 9: "#3f6212",
223
- 10: "#365314",
224
- 11: "#1a2e05",
225
- 12: "#0f1b03"
226
- },
227
- green: {
228
- 1: "#f0fdf4",
229
- 2: "#dcfce7",
230
- 3: "#bbf7d0",
231
- 4: "#86efac",
232
- 5: "#4ade80",
233
- 6: "#22c55e",
234
- 7: "#16a34a",
235
- 8: "#15803d",
236
- 9: "#166534",
237
- 10: "#14532d",
238
- 11: "#052e16",
239
- 12: "#031b0d"
240
- },
241
- emerald: {
242
- 1: "#ecfdf5",
243
- 2: "#d1fae5",
244
- 3: "#a7f3d0",
245
- 4: "#6ee7b7",
246
- 5: "#34d399",
247
- 6: "#10b981",
248
- 7: "#059669",
249
- 8: "#047857",
250
- 9: "#065f46",
251
- 10: "#064e3b",
252
- 11: "#022c22",
253
- 12: "#011a14"
254
- },
255
- teal: {
256
- 1: "#f0fdfa",
257
- 2: "#ccfbf1",
258
- 3: "#99f6e4",
259
- 4: "#5eead4",
260
- 5: "#2dd4bf",
261
- 6: "#14b8a6",
262
- 7: "#0d9488",
263
- 8: "#0f766e",
264
- 9: "#115e59",
265
- 10: "#134e4a",
266
- 11: "#042f2e",
267
- 12: "#021c1b"
268
- },
269
- cyan: {
270
- 1: "#ecfeff",
271
- 2: "#cffafe",
272
- 3: "#a5f3fc",
273
- 4: "#67e8f9",
274
- 5: "#22d3ee",
275
- 6: "#06b6d4",
276
- 7: "#0891b2",
277
- 8: "#0e7490",
278
- 9: "#155e75",
279
- 10: "#164e63",
280
- 11: "#083344",
281
- 12: "#041e28"
282
- },
283
- sky: {
284
- 1: "#f0f9ff",
285
- 2: "#e0f2fe",
286
- 3: "#bae6fd",
287
- 4: "#7dd3fc",
288
- 5: "#38bdf8",
289
- 6: "#0ea5e9",
290
- 7: "#0284c7",
291
- 8: "#0369a1",
292
- 9: "#075985",
293
- 10: "#0c4a6e",
294
- 11: "#082f49",
295
- 12: "#041b2b"
296
- },
297
- blue: {
298
- 1: "#eff6ff",
299
- 2: "#dbeafe",
300
- 3: "#bfdbfe",
301
- 4: "#93c5fd",
302
- 5: "#60a5fa",
303
- 6: "#3b82f6",
304
- 7: "#2563eb",
305
- 8: "#1d4ed8",
306
- 9: "#1e40af",
307
- 10: "#1e3a8a",
308
- 11: "#172554",
309
- 12: "#0d1633"
310
- },
311
- indigo: {
312
- 1: "#eef2ff",
313
- 2: "#e0e7ff",
314
- 3: "#c7d2fe",
315
- 4: "#a5b4fc",
316
- 5: "#818cf8",
317
- 6: "#6366f1",
318
- 7: "#4f46e5",
319
- 8: "#4338ca",
320
- 9: "#3730a3",
321
- 10: "#312e81",
322
- 11: "#1e1b4b",
323
- 12: "#12102d"
324
- },
325
- violet: {
326
- 1: "#f5f3ff",
327
- 2: "#ede9fe",
328
- 3: "#ddd6fe",
329
- 4: "#c4b5fd",
330
- 5: "#a78bfa",
331
- 6: "#8b5cf6",
332
- 7: "#7c3aed",
333
- 8: "#6d28d9",
334
- 9: "#5b21b6",
335
- 10: "#4c1d95",
336
- 11: "#2e1065",
337
- 12: "#1c0a3d"
338
- },
339
- purple: {
340
- 1: "#faf5ff",
341
- 2: "#f3e8ff",
342
- 3: "#e9d5ff",
343
- 4: "#d8b4fe",
344
- 5: "#c084fc",
345
- 6: "#a855f7",
346
- 7: "#9333ea",
347
- 8: "#7e22ce",
348
- 9: "#6b21a8",
349
- 10: "#581c87",
350
- 11: "#3b0764",
351
- 12: "#23043c"
352
- },
353
- fuchsia: {
354
- 1: "#fdf4ff",
355
- 2: "#fae8ff",
356
- 3: "#f5d0fe",
357
- 4: "#f0abfc",
358
- 5: "#e879f9",
359
- 6: "#d946ef",
360
- 7: "#c026d3",
361
- 8: "#a21caf",
362
- 9: "#86198f",
363
- 10: "#701a75",
364
- 11: "#4a044e",
365
- 12: "#2d022f"
366
- },
367
- pink: {
368
- 1: "#fdf2f8",
369
- 2: "#fce7f3",
370
- 3: "#fbcfe8",
371
- 4: "#f9a8d4",
372
- 5: "#f472b6",
373
- 6: "#ec4899",
374
- 7: "#db2777",
375
- 8: "#be185d",
376
- 9: "#9d174d",
377
- 10: "#831843",
378
- 11: "#500724",
379
- 12: "#300415"
380
- },
381
- rose: {
382
- 1: "#fff1f2",
383
- 2: "#ffe4e6",
384
- 3: "#fecdd3",
385
- 4: "#fda4af",
386
- 5: "#fb7185",
387
- 6: "#f43f5e",
388
- 7: "#e11d48",
389
- 8: "#be123c",
390
- 9: "#9f1239",
391
- 10: "#881337",
392
- 11: "#4c0519",
393
- 12: "#2d030e"
394
- }
395
- };
396
- var defaultTheme = {
397
- colors: defaultColors,
398
- // 1 unit = 4px
399
- spacing: {
400
- px: 1,
401
- 0: 0,
402
- "0.5": 2,
403
- 1: 4,
404
- "1.5": 6,
405
- 2: 8,
406
- "2.5": 10,
407
- 3: 12,
408
- "3.5": 14,
409
- 4: 16,
410
- 5: 20,
411
- 6: 24,
412
- 7: 28,
413
- 8: 32,
414
- 9: 36,
415
- 10: 40,
416
- 11: 44,
417
- 12: 48,
418
- 14: 56,
419
- 16: 64,
420
- 20: 80,
421
- 24: 96,
422
- 28: 112,
423
- 32: 128,
424
- 36: 144,
425
- 40: 160,
426
- 44: 176,
427
- 48: 192,
428
- 52: 208,
429
- 56: 224,
430
- 60: 240,
431
- 64: 256,
432
- 72: 288,
433
- 80: 320,
434
- 96: 384,
435
- auto: "auto",
436
- full: "100%",
437
- "1/2": "50%",
438
- "1/3": "33.333333%",
439
- "2/3": "66.666667%",
440
- "1/4": "25%",
441
- "3/4": "75%",
442
- // Dynamic viewport unit — see the comment on the 'screen' standalone utilities
443
- // in utilities.ts for why dvh beats vh on mobile. Used by h-screen (w-screen
444
- // has its own standalone entry so it never reaches this spacing lookup).
445
- screen: "100dvh",
446
- min: "min-content",
447
- max: "max-content",
448
- fit: "fit-content"
449
- },
450
- fontSize: {
451
- xs: 12,
452
- sm: 14,
453
- base: 16,
454
- lg: 18,
455
- xl: 20,
456
- "2xl": 24,
457
- "3xl": 30,
458
- "4xl": 36,
459
- "5xl": 48,
460
- "6xl": 60,
461
- "7xl": 72,
462
- "8xl": 96,
463
- "9xl": 128
464
- },
465
- fontFamily: {
466
- sans: "System",
467
- mono: "Courier New",
468
- serif: "Georgia"
469
- },
470
- fontWeight: {
471
- thin: "100",
472
- extralight: "200",
473
- light: "300",
474
- normal: "400",
475
- medium: "500",
476
- semibold: "600",
477
- bold: "700",
478
- extrabold: "800",
479
- black: "900"
480
- },
481
- borderRadius: {
482
- none: 0,
483
- sm: 2,
484
- DEFAULT: 4,
485
- md: 6,
486
- lg: 8,
487
- xl: 12,
488
- "2xl": 16,
489
- "3xl": 24,
490
- full: 9999
491
- },
492
- borderWidth: {
493
- DEFAULT: 1,
494
- 0: 0,
495
- 2: 2,
496
- 4: 4,
497
- 8: 8
498
- },
499
- opacity: {
500
- 0: 0,
501
- 5: 0.05,
502
- 10: 0.1,
503
- 15: 0.15,
504
- 20: 0.2,
505
- 25: 0.25,
506
- 30: 0.3,
507
- 40: 0.4,
508
- 50: 0.5,
509
- 60: 0.6,
510
- 70: 0.7,
511
- 75: 0.75,
512
- 80: 0.8,
513
- 90: 0.9,
514
- 95: 0.95,
515
- 100: 1
516
- },
517
- lineHeight: {
518
- none: 1,
519
- tight: 1.25,
520
- snug: 1.375,
521
- normal: 1.5,
522
- relaxed: 1.625,
523
- loose: 2,
524
- // Pixel values stored as strings; styleValueToCSS passes them through, toNativeValue strips the unit
525
- 3: "12px",
526
- 4: "16px",
527
- 5: "20px",
528
- 6: "24px",
529
- 7: "28px",
530
- 8: "32px",
531
- 9: "36px",
532
- 10: "40px"
533
- },
534
- letterSpacing: {
535
- tighter: -0.8,
536
- tight: -0.4,
537
- normal: 0,
538
- wide: 0.4,
539
- wider: 0.8,
540
- widest: 1.6
541
- },
542
- zIndex: {
543
- auto: "auto",
544
- 0: 0,
545
- 10: 10,
546
- 20: 20,
547
- 30: 30,
548
- 40: 40,
549
- 50: 50
550
- },
551
- flex: {
552
- 1: 1,
553
- auto: "auto",
554
- // CSS: flex: auto = 1 1 auto; native: mapped to 1 in resolver
555
- initial: "initial",
556
- // CSS: flex: initial = 0 1 auto; native: mapped to 1
557
- none: "none"
558
- // CSS: flex: none = 0 0 auto; native: mapped to 0
559
- },
560
- // Each preset carries BOTH React Native's shadow*/elevation properties
561
- // (used on native) and a `boxShadow` string (used on web) — see the
562
- // `shadow` resolver in resolvers/effects.ts, which picks one or the other
563
- // via getEffectiveIsWeb() and strips the rest. The boxShadow values are
564
- // Tailwind's own default shadow scale verbatim (same offsets/blur/spread/
565
- // opacity), so shadow-sm/md/lg/xl/2xl look the same as their Tailwind
566
- // counterparts on web — the native shadowOffset/shadowRadius/shadowOpacity
567
- // numbers were tuned independently for RN's elevation model and don't need
568
- // to (and can't exactly) match the CSS values pixel-for-pixel.
569
- shadow: {
570
- sm: {
571
- shadowColor: "#000",
572
- shadowOffset: { width: 0, height: 1 },
573
- shadowOpacity: 0.05,
574
- shadowRadius: 2,
575
- elevation: 1,
576
- boxShadow: "0 1px 2px 0 rgb(0 0 0 / 0.05)"
577
- },
578
- DEFAULT: {
579
- shadowColor: "#000",
580
- shadowOffset: { width: 0, height: 2 },
581
- shadowOpacity: 0.1,
582
- shadowRadius: 4,
583
- elevation: 2,
584
- boxShadow: "0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)"
585
- },
586
- md: {
587
- shadowColor: "#000",
588
- shadowOffset: { width: 0, height: 4 },
589
- shadowOpacity: 0.1,
590
- shadowRadius: 8,
591
- elevation: 3,
592
- boxShadow: "0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)"
593
- },
594
- lg: {
595
- shadowColor: "#000",
596
- shadowOffset: { width: 0, height: 8 },
597
- shadowOpacity: 0.1,
598
- shadowRadius: 15,
599
- elevation: 4,
600
- boxShadow: "0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)"
601
- },
602
- xl: {
603
- shadowColor: "#000",
604
- shadowOffset: { width: 0, height: 16 },
605
- shadowOpacity: 0.1,
606
- shadowRadius: 24,
607
- elevation: 6,
608
- boxShadow: "0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)"
609
- },
610
- "2xl": {
611
- shadowColor: "#000",
612
- shadowOffset: { width: 0, height: 24 },
613
- shadowOpacity: 0.25,
614
- shadowRadius: 48,
615
- elevation: 8,
616
- boxShadow: "0 25px 50px -12px rgb(0 0 0 / 0.25)"
617
- },
618
- // Web-only — React Native has no inset-shadow equivalent (shadow*/
619
- // elevation only ever draw an outer shadow), so the native side of this
620
- // preset is intentionally empty rather than approximating something RN
621
- // can't actually do.
622
- inner: {
623
- boxShadow: "inset 0 2px 4px 0 rgb(0 0 0 / 0.05)"
624
- },
625
- none: {
626
- shadowColor: "transparent",
627
- shadowOffset: { width: 0, height: 0 },
628
- shadowOpacity: 0,
629
- shadowRadius: 0,
630
- elevation: 0,
631
- boxShadow: "0 0 #0000"
632
- }
633
- },
634
- screens: {
635
- sm: 576,
636
- // small tablets / large phones (landscape)
637
- md: 768,
638
- // tablets (iPad and up)
639
- lg: 1024,
640
- // large tablets (iPad Pro)
641
- xl: 1280,
642
- // desktop
643
- "2xl": 1536
644
- },
645
- // Empty by default — the 4 built-in presets (spin/ping/pulse/bounce) are handled
646
- // directly in the `animate` resolver, not through this theme table. This exists so
647
- // user-defined ones (kbach.config.js theme.extend.keyframes/animation) merge in
648
- // alongside them without needing to redeclare the built-ins.
649
- keyframes: {},
650
- animation: {}
651
- };
652
-
653
- // src/core/colorValue.ts
654
- function isModeAwareColor(v) {
655
- return typeof v === "object" && v !== null && "light" in v && "dark" in v;
656
- }
657
- function splitColorShadeRef(ref) {
658
- const lastDash = ref.lastIndexOf("-");
659
- if (lastDash <= 0) return null;
660
- return { name: ref.slice(0, lastDash), shade: ref.slice(lastDash + 1) };
661
- }
662
-
663
- // src/core/resolvers/color.ts
664
- function pickModeAwareFallback(v) {
665
- return isModeAwareColor(v) ? v.light : v;
666
- }
667
- function resolveColor(value, colors, isArbitrary) {
668
- if (isArbitrary) return value;
669
- const slashIdx = value.indexOf("/");
670
- const colorPart = slashIdx > 0 ? value.slice(0, slashIdx) : value;
671
- const opacityPart = slashIdx > 0 ? value.slice(slashIdx + 1) : null;
672
- let hex = null;
673
- if (colorPart.startsWith("[") && colorPart.endsWith("]")) {
674
- hex = colorPart.slice(1, -1);
675
- } else if (colorPart in colors) {
676
- const entry = colors[colorPart];
677
- if (typeof entry === "string") hex = entry;
678
- else if (isModeAwareColor(entry)) hex = pickModeAwareFallback(entry);
679
- else if (typeof entry === "object" && "6" in entry) hex = pickModeAwareFallback(entry["6"]);
680
- } else {
681
- const split = splitColorShadeRef(colorPart);
682
- if (split) {
683
- const scale = colors[split.name];
684
- if (scale && typeof scale === "object" && !isModeAwareColor(scale) && split.shade in scale) {
685
- const shadeVal = scale[split.shade];
686
- hex = shadeVal !== void 0 ? pickModeAwareFallback(shadeVal) : null;
687
- }
688
- }
689
- }
690
- if (!hex) return null;
691
- if (!opacityPart) {
692
- if (!getEffectiveIsWeb() && hex.startsWith("#") && hex.length === 9) {
693
- return hexToRgba(hex, Math.round(parseInt(hex.slice(7, 9), 16) / 255 * 1e3) / 1e3);
694
- }
695
- return hex;
696
- }
697
- let alpha;
698
- if (opacityPart.startsWith("[") && opacityPart.endsWith("]")) {
699
- const v = parseFloat(opacityPart.slice(1, -1));
700
- alpha = v > 1 ? v / 100 : v;
701
- } else {
702
- alpha = parseFloat(opacityPart) / 100;
703
- }
704
- if (isNaN(alpha)) return hex;
705
- if (alpha < 0) alpha = 0;
706
- else if (alpha > 1) alpha = 1;
707
- return hexToRgba(hex, alpha);
708
- }
709
- function parseHexRgb(hex) {
710
- const h = hex.replace("#", "");
711
- if (h.length === 3 || h.length === 4) {
712
- return [
713
- parseInt(h[0] + h[0], 16),
714
- parseInt(h[1] + h[1], 16),
715
- parseInt(h[2] + h[2], 16)
716
- ];
717
- }
718
- if (h.length === 6 || h.length === 8) {
719
- return [
720
- parseInt(h.slice(0, 2), 16),
721
- parseInt(h.slice(2, 4), 16),
722
- parseInt(h.slice(4, 6), 16)
723
- ];
724
- }
725
- return null;
726
- }
727
- function hexToRgba(hex, alpha) {
728
- const rgb = parseHexRgb(hex);
729
- if (!rgb) return hex;
730
- const [r, g, b] = rgb;
731
- return `rgba(${r},${g},${b},${alpha})`;
732
- }
733
- function withOpacityVar(color, varName) {
734
- if (!color.startsWith("#")) return color;
735
- const rgb = parseHexRgb(color);
736
- if (!rgb) return color;
737
- const [r, g, b] = rgb;
738
- return `rgba(${r},${g},${b},var(${varName},1))`;
739
- }
740
- var colorResolvers = {
741
- // ── Background ─────────────────────────────────────────────────────────────
742
- bg: ({ value, isArbitrary }, { colors }) => {
743
- const color = resolveColor(value, colors, isArbitrary);
744
- if (!color) return null;
745
- return { backgroundColor: getEffectiveIsWeb() ? withOpacityVar(color, "--bg-opacity") : color };
746
- },
747
- "bg-opacity": ({ value, isArbitrary }, _) => {
748
- if (!getEffectiveIsWeb()) return null;
749
- const n = parseFloat(value);
750
- if (isNaN(n)) return null;
751
- const v = isArbitrary ? n > 1 ? n / 100 : n : n / 100;
752
- return { "--bg-opacity": v };
753
- },
754
- // ── Background gradient (CSS variable gradient stops, web-only) ──────────
755
- "bg-gradient-to": ({ value }) => {
756
- if (!getEffectiveIsWeb()) return null;
757
- const directions = {
758
- t: "to top",
759
- tr: "to top right",
760
- r: "to right",
761
- br: "to bottom right",
762
- b: "to bottom",
763
- bl: "to bottom left",
764
- l: "to left",
765
- tl: "to top left"
766
- };
767
- const dir = directions[value];
768
- if (!dir) return null;
769
- return {
770
- backgroundImage: `linear-gradient(${dir}, var(--kb-gradient-from, transparent), var(--kb-gradient-stops, transparent))`
771
- };
772
- },
773
- from: ({ value, isArbitrary }, { colors }) => {
774
- if (!getEffectiveIsWeb()) return null;
775
- const color = resolveColor(value, colors, isArbitrary);
776
- if (!color) return null;
777
- return {
778
- "--kb-gradient-from": color,
779
- "--kb-gradient-stops": `var(--kb-gradient-from), var(--kb-gradient-to, transparent)`
780
- };
781
- },
782
- via: ({ value, isArbitrary }, { colors }) => {
783
- if (!getEffectiveIsWeb()) return null;
784
- const color = resolveColor(value, colors, isArbitrary);
785
- if (!color) return null;
786
- return {
787
- "--kb-gradient-via": color,
788
- "--kb-gradient-stops": `var(--kb-gradient-from), var(--kb-gradient-via), var(--kb-gradient-to, transparent)`
789
- };
790
- },
791
- to: ({ value, isArbitrary }, { colors }) => {
792
- if (!getEffectiveIsWeb()) return null;
793
- const color = resolveColor(value, colors, isArbitrary);
794
- if (!color) return null;
795
- return { "--kb-gradient-to": color };
796
- },
797
- // ── Tint color (native-only, for Image and icon components) ──────────────
798
- tint: ({ value, isArbitrary }, { colors }) => {
799
- if (getEffectiveIsWeb()) return null;
800
- const color = resolveColor(value, colors, isArbitrary);
801
- return color ? { tintColor: color } : null;
802
- },
803
- // ── Caret color (web-only) ────────────────────────────────────────────────
804
- caret: ({ value, isArbitrary }, { colors }) => {
805
- if (!getEffectiveIsWeb()) return null;
806
- if (value === "auto" || value === "transparent") return { caretColor: value };
807
- const color = resolveColor(value, colors, isArbitrary);
808
- return color ? { caretColor: color } : null;
809
- },
810
- // ── Accent color (web-only) ───────────────────────────────────────────────
811
- accent: ({ value, isArbitrary }, { colors }) => {
812
- if (!getEffectiveIsWeb()) return null;
813
- if (value === "auto") return { accentColor: "auto" };
814
- const color = resolveColor(value, colors, isArbitrary);
815
- return color ? { accentColor: color } : null;
816
- }
817
- };
818
-
819
- // src/core/resolvers/spacing.ts
820
- function resolveSpacing(value, negative, spacing, isArbitrary) {
821
- if (isArbitrary) {
822
- const resolved = getEffectiveIsWeb() ? value : toNativeValue(value);
823
- if (negative) {
824
- if (typeof resolved === "number") return -resolved;
825
- if (typeof resolved === "string") {
826
- if (resolved.startsWith("-")) return resolved.slice(1);
827
- if (/^\d/.test(resolved)) return `-${resolved}`;
828
- if (/^(calc|var|min|max|clamp|env)\s*\(/.test(resolved)) return `calc(-1 * (${resolved}))`;
829
- }
830
- }
831
- return resolved;
832
- }
833
- const raw = spacing[value];
834
- if (raw === void 0) return null;
835
- if (typeof raw === "number") return negative ? -raw : raw;
836
- if (raw === "auto") return "auto";
837
- if (negative && typeof raw === "string" && raw.endsWith("%")) {
838
- return `-${raw}`;
839
- }
840
- return raw;
841
- }
842
- function resolveSizing(value, spacing, isArbitrary) {
843
- if (isArbitrary) return getEffectiveIsWeb() ? value : toNativeValue(value);
844
- const raw = spacing[value];
845
- if (raw !== void 0) return raw;
846
- if (/^\d+\/\d+$/.test(value)) {
847
- const [num, den] = value.split("/").map(Number);
848
- if (!den) return null;
849
- return `${(num / den * 100).toFixed(6)}%`;
850
- }
851
- return null;
852
- }
853
- function makeSpacingResolver(prop) {
854
- return ({ value, negative, isArbitrary }, { spacing }) => {
855
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
856
- return v !== null ? { [prop]: v } : null;
857
- };
858
- }
859
- var PADDING_MARGIN_PROPS = {
860
- p: "padding",
861
- px: "paddingHorizontal",
862
- py: "paddingVertical",
863
- pt: "paddingTop",
864
- pr: "paddingRight",
865
- pb: "paddingBottom",
866
- pl: "paddingLeft",
867
- m: "margin",
868
- mx: "marginHorizontal",
869
- my: "marginVertical",
870
- mt: "marginTop",
871
- mr: "marginRight",
872
- mb: "marginBottom",
873
- ml: "marginLeft"
874
- };
875
- var spacingResolvers = {
876
- // ── Sizing ─────────────────────────────────────────────────────────────────
877
- w: ({ value, isArbitrary }, { spacing }) => {
878
- const v = resolveSizing(value, spacing, isArbitrary);
879
- return v !== null ? { width: v } : null;
880
- },
881
- h: ({ value, isArbitrary }, { spacing }) => {
882
- const v = resolveSizing(value, spacing, isArbitrary);
883
- return v !== null ? { height: v } : null;
884
- },
885
- "min-w": ({ value, isArbitrary }, { spacing }) => {
886
- const v = resolveSizing(value, spacing, isArbitrary);
887
- return v !== null ? { minWidth: v } : null;
888
- },
889
- "min-h": ({ value, isArbitrary }, { spacing }) => {
890
- const v = resolveSizing(value, spacing, isArbitrary);
891
- return v !== null ? { minHeight: v } : null;
892
- },
893
- "max-w": ({ value, isArbitrary }, { spacing }) => {
894
- const v = resolveSizing(value, spacing, isArbitrary);
895
- return v !== null ? { maxWidth: v } : null;
896
- },
897
- "max-h": ({ value, isArbitrary }, { spacing }) => {
898
- const v = resolveSizing(value, spacing, isArbitrary);
899
- return v !== null ? { maxHeight: v } : null;
900
- },
901
- // ── Size shorthand (sets width AND height in one utility) ────────────────
902
- size: ({ value, isArbitrary }, { spacing }) => {
903
- const v = resolveSizing(value, spacing, isArbitrary);
904
- return v !== null ? { width: v, height: v } : null;
905
- },
906
- // ── Flex basis ─────────────────────────────────────────────────────────────
907
- basis: ({ value, isArbitrary }, { spacing }) => {
908
- const v = resolveSizing(value, spacing, isArbitrary);
909
- return v !== null ? { flexBasis: v } : null;
910
- },
911
- // ── Gap ────────────────────────────────────────────────────────────────────
912
- gap: ({ value, negative, isArbitrary }, { spacing }) => {
913
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
914
- return v !== null ? { gap: v } : null;
915
- },
916
- "gap-x": ({ value, negative, isArbitrary }, { spacing }) => {
917
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
918
- return v !== null ? { columnGap: v } : null;
919
- },
920
- "gap-y": ({ value, negative, isArbitrary }, { spacing }) => {
921
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
922
- return v !== null ? { rowGap: v } : null;
923
- },
924
- // ── Position ───────────────────────────────────────────────────────────────
925
- top: ({ value, negative, isArbitrary }, { spacing }) => {
926
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
927
- return v !== null ? { top: v } : null;
928
- },
929
- right: ({ value, negative, isArbitrary }, { spacing }) => {
930
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
931
- return v !== null ? { right: v } : null;
932
- },
933
- bottom: ({ value, negative, isArbitrary }, { spacing }) => {
934
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
935
- return v !== null ? { bottom: v } : null;
936
- },
937
- left: ({ value, negative, isArbitrary }, { spacing }) => {
938
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
939
- return v !== null ? { left: v } : null;
940
- },
941
- inset: ({ value, negative, isArbitrary }, { spacing }) => {
942
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
943
- return v !== null ? { top: v, right: v, bottom: v, left: v } : null;
944
- },
945
- "inset-x": ({ value, negative, isArbitrary }, { spacing }) => {
946
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
947
- return v !== null ? { left: v, right: v } : null;
948
- },
949
- "inset-y": ({ value, negative, isArbitrary }, { spacing }) => {
950
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
951
- return v !== null ? { top: v, bottom: v } : null;
952
- },
953
- // ── Translate ──────────────────────────────────────────────────────────────
954
- "translate-x": ({ value, negative, isArbitrary }, { spacing }) => {
955
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
956
- if (v === null) return null;
957
- if (getEffectiveIsWeb()) return { transform: `translateX(${typeof v === "number" ? `${v}px` : v})` };
958
- if (typeof v === "string") {
959
- const n = parseFloat(v);
960
- return isNaN(n) ? null : { transform: [{ translateX: n }] };
961
- }
962
- return { transform: [{ translateX: v }] };
963
- },
964
- "translate-y": ({ value, negative, isArbitrary }, { spacing }) => {
965
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
966
- if (v === null) return null;
967
- if (getEffectiveIsWeb()) return { transform: `translateY(${typeof v === "number" ? `${v}px` : v})` };
968
- if (typeof v === "string") {
969
- const n = parseFloat(v);
970
- return isNaN(n) ? null : { transform: [{ translateY: n }] };
971
- }
972
- return { transform: [{ translateY: v }] };
973
- },
974
- // ── Space between ─────────────────────────────────────────────────────────
975
- // On web: emits __spaceX/__spaceY markers → resolver generates > * + * CSS rules.
976
- // On native (RN 0.71+): uses columnGap/rowGap directly.
977
- "space-x": ({ value, negative, isArbitrary }, { spacing }) => {
978
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
979
- if (v === null) return null;
980
- if (getEffectiveIsWeb()) return { __spaceX: v };
981
- return { columnGap: v };
982
- },
983
- "space-y": ({ value, negative, isArbitrary }, { spacing }) => {
984
- const v = resolveSpacing(value, negative, spacing, isArbitrary);
985
- if (v === null) return null;
986
- if (getEffectiveIsWeb()) return { __spaceY: v };
987
- return { rowGap: v };
988
- }
989
- };
990
- for (const [utility, prop] of Object.entries(PADDING_MARGIN_PROPS)) {
991
- spacingResolvers[utility] = makeSpacingResolver(prop);
992
- }
993
-
994
- // src/core/resolvers/border.ts
995
- function resolveRadius(value, radii, isArbitrary) {
996
- if (isArbitrary) return getEffectiveIsWeb() ? value : toNativeValue(value);
997
- const key = value === "" ? "DEFAULT" : value;
998
- return radii[key] ?? null;
999
- }
1000
- function makeBorderSideResolver(widthProp, colorProp) {
1001
- return ({ value, isArbitrary }, { colors, borderWidth }) => {
1002
- if (!value) return { [widthProp]: 1 };
1003
- if (isArbitrary) {
1004
- const w2 = toNativeValue(value);
1005
- if (typeof w2 === "number") return { [widthProp]: getEffectiveIsWeb() ? value : w2 };
1006
- return { [colorProp]: value };
1007
- }
1008
- const color = resolveColor(value, colors, false);
1009
- if (color) return { [colorProp]: color };
1010
- const w = borderWidth[value];
1011
- return w !== void 0 ? { [widthProp]: w } : null;
1012
- };
1013
- }
1014
- var BORDER_SIDE_PROPS = {
1015
- "border-t": ["borderTopWidth", "borderTopColor"],
1016
- "border-r": ["borderRightWidth", "borderRightColor"],
1017
- "border-b": ["borderBottomWidth", "borderBottomColor"],
1018
- "border-l": ["borderLeftWidth", "borderLeftColor"]
1019
- };
1020
- var borderResolvers = {
1021
- // ── Border width ───────────────────────────────────────────────────────────
1022
- border: ({ value, isArbitrary }, { colors, borderWidth, spacing }) => {
1023
- if (!value) return { borderWidth: borderWidth["DEFAULT"] ?? 1 };
1024
- if (isArbitrary) {
1025
- const w2 = toNativeValue(value);
1026
- if (typeof w2 === "number") return { borderWidth: getEffectiveIsWeb() ? value : w2 };
1027
- return { borderColor: value };
1028
- }
1029
- const color = resolveColor(value, colors, false);
1030
- if (color) return { borderColor: color };
1031
- const w = borderWidth[value] ?? spacing[value];
1032
- if (w !== void 0) {
1033
- const numW = typeof w === "number" ? w : parseFloat(String(w));
1034
- if (isNaN(numW)) return null;
1035
- return { borderWidth: numW };
1036
- }
1037
- return null;
1038
- },
1039
- // border-t/-r/-b/-l generated below via makeBorderSideResolver() — see BORDER_SIDE_PROPS.
1040
- // ── Border radius ──────────────────────────────────────────────────────────
1041
- rounded: ({ value, isArbitrary }, { borderRadius }) => {
1042
- const r = resolveRadius(value, borderRadius, isArbitrary);
1043
- return r !== null ? { borderRadius: r } : null;
1044
- },
1045
- "rounded-t": ({ value, isArbitrary }, { borderRadius }) => {
1046
- const r = resolveRadius(value, borderRadius, isArbitrary);
1047
- return r !== null ? { borderTopLeftRadius: r, borderTopRightRadius: r } : null;
1048
- },
1049
- "rounded-r": ({ value, isArbitrary }, { borderRadius }) => {
1050
- const r = resolveRadius(value, borderRadius, isArbitrary);
1051
- return r !== null ? { borderTopRightRadius: r, borderBottomRightRadius: r } : null;
1052
- },
1053
- "rounded-b": ({ value, isArbitrary }, { borderRadius }) => {
1054
- const r = resolveRadius(value, borderRadius, isArbitrary);
1055
- return r !== null ? { borderBottomLeftRadius: r, borderBottomRightRadius: r } : null;
1056
- },
1057
- "rounded-l": ({ value, isArbitrary }, { borderRadius }) => {
1058
- const r = resolveRadius(value, borderRadius, isArbitrary);
1059
- return r !== null ? { borderTopLeftRadius: r, borderBottomLeftRadius: r } : null;
1060
- },
1061
- "rounded-tl": ({ value, isArbitrary }, { borderRadius }) => {
1062
- const r = resolveRadius(value, borderRadius, isArbitrary);
1063
- return r !== null ? { borderTopLeftRadius: r } : null;
1064
- },
1065
- "rounded-tr": ({ value, isArbitrary }, { borderRadius }) => {
1066
- const r = resolveRadius(value, borderRadius, isArbitrary);
1067
- return r !== null ? { borderTopRightRadius: r } : null;
1068
- },
1069
- "rounded-bl": ({ value, isArbitrary }, { borderRadius }) => {
1070
- const r = resolveRadius(value, borderRadius, isArbitrary);
1071
- return r !== null ? { borderBottomLeftRadius: r } : null;
1072
- },
1073
- "rounded-br": ({ value, isArbitrary }, { borderRadius }) => {
1074
- const r = resolveRadius(value, borderRadius, isArbitrary);
1075
- return r !== null ? { borderBottomRightRadius: r } : null;
1076
- },
1077
- // ── Outline extended (web-only) ───────────────────────────────────────────
1078
- outline: ({ value, isArbitrary }, { colors }) => {
1079
- if (!getEffectiveIsWeb()) return null;
1080
- if (!value) return { outline: "2px solid transparent", outlineOffset: "2px" };
1081
- if (value === "none") return { outline: "none", outlineOffset: "0" };
1082
- if (isArbitrary) {
1083
- if (/^\d/.test(value) || value.startsWith("calc(")) return { outlineWidth: value };
1084
- return { outlineColor: value };
1085
- }
1086
- const widths = { "0": "0px", "1": "1px", "2": "2px", "4": "4px", "8": "8px" };
1087
- if (value in widths) return { outlineWidth: widths[value] };
1088
- const color = resolveColor(value, colors, false);
1089
- return color ? { outlineColor: color } : null;
1090
- },
1091
- "outline-offset": ({ value, isArbitrary }) => {
1092
- if (!getEffectiveIsWeb()) return null;
1093
- if (isArbitrary) return { outlineOffset: value };
1094
- const offsets = { "0": "0px", "1": "1px", "2": "2px", "4": "4px", "8": "8px" };
1095
- return offsets[value] ? { outlineOffset: offsets[value] } : null;
1096
- },
1097
- // ── Divide (child combinator CSS, web-only) ───────────────────────────────
1098
- // These return special __divide* markers that resolver.ts converts to
1099
- // .cls > * + * { border-... } CSS rules. No inline style is applied.
1100
- "divide-x": ({ value, isArbitrary }) => {
1101
- if (!getEffectiveIsWeb()) return null;
1102
- if (value === "reverse") return null;
1103
- if (!value) return { __divideX: 1 };
1104
- const n = parseFloat(value);
1105
- return isNaN(n) ? null : { __divideX: n };
1106
- },
1107
- "divide-y": ({ value, isArbitrary }) => {
1108
- if (!getEffectiveIsWeb()) return null;
1109
- if (value === "reverse") return null;
1110
- if (!value) return { __divideY: 1 };
1111
- const n = parseFloat(value);
1112
- return isNaN(n) ? null : { __divideY: n };
1113
- },
1114
- divide: ({ value, isArbitrary }, { colors }) => {
1115
- if (!getEffectiveIsWeb()) return null;
1116
- if (isArbitrary) return { __divideColor: value };
1117
- const styleTokens = {
1118
- solid: "solid",
1119
- dashed: "dashed",
1120
- dotted: "dotted",
1121
- double: "double",
1122
- none: "none"
1123
- };
1124
- if (value in styleTokens) return { __divideStyle: styleTokens[value] };
1125
- const color = resolveColor(value, colors, false);
1126
- return color ? { __divideColor: color } : null;
1127
- },
1128
- // ── Ring ───────────────────────────────────────────────────────────────────
1129
- // Web: box-shadow outline ring (doesn't affect layout).
1130
- // Native: React Native has no box-shadow, so this falls back to borderWidth/
1131
- // borderColor — the closest visual approximation (used by other RN Tailwind-
1132
- // likes for the same reason). Unlike the web ring, this DOES affect layout,
1133
- // and it shares its properties with the `border` utility — combining
1134
- // `border-*` and `ring-*` on the same native element means whichever class
1135
- // comes later wins, since both ultimately set borderWidth/borderColor.
1136
- ring: ({ value, isArbitrary }, { colors }) => {
1137
- const onWeb = getEffectiveIsWeb();
1138
- const DEFAULT_COLOR = "rgba(59, 130, 246, 0.5)";
1139
- const DEFAULT_WIDTH = 3;
1140
- const asNative = (w, color2) => w === 0 ? { borderWidth: 0 } : { borderWidth: w, borderColor: color2 };
1141
- if (!value) {
1142
- return onWeb ? { boxShadow: `0 0 0 ${DEFAULT_WIDTH}px ${DEFAULT_COLOR}` } : asNative(DEFAULT_WIDTH, DEFAULT_COLOR);
1143
- }
1144
- if (value === "inset") {
1145
- return onWeb ? { boxShadow: `inset 0 0 0 ${DEFAULT_WIDTH}px ${DEFAULT_COLOR}` } : asNative(DEFAULT_WIDTH, DEFAULT_COLOR);
1146
- }
1147
- const widthTokens = { "0": 0, "1": 1, "2": 2, "4": 4, "8": 8 };
1148
- if (!isArbitrary && value in widthTokens) {
1149
- const w = widthTokens[value];
1150
- return onWeb ? { boxShadow: w === 0 ? "none" : `0 0 0 ${w}px ${DEFAULT_COLOR}` } : asNative(w, DEFAULT_COLOR);
1151
- }
1152
- if (isArbitrary) {
1153
- const numMatch = /^(\d+(?:\.\d+)?)(px|rem|em|vw|vh)?$/.exec(value);
1154
- if (numMatch) {
1155
- const unit = numMatch[2] ?? "px";
1156
- if (onWeb) return { boxShadow: `0 0 0 ${numMatch[1]}${unit} ${DEFAULT_COLOR}` };
1157
- return unit === "px" ? asNative(parseFloat(numMatch[1]), DEFAULT_COLOR) : null;
1158
- }
1159
- return onWeb ? { boxShadow: value.replace(/_/g, " ") } : null;
1160
- }
1161
- const color = resolveColor(value, colors, false);
1162
- if (color) {
1163
- return onWeb ? { boxShadow: `0 0 0 ${DEFAULT_WIDTH}px ${color}` } : asNative(DEFAULT_WIDTH, color);
1164
- }
1165
- return null;
1166
- },
1167
- // Web-only, unlike `ring` above: this stacks a second box-shadow layer to
1168
- // create a gap between the element and the ring. There's no native
1169
- // equivalent to approximate that with (a border can't create a gap outside
1170
- // its own element without an extra wrapper view), so this stays a no-op
1171
- // on native rather than rendering a misleading half-translation.
1172
- "ring-offset": ({ value, isArbitrary }, _theme) => {
1173
- if (!getEffectiveIsWeb()) return null;
1174
- const DEFAULT_RING_COLOR = "rgba(59, 130, 246, 0.5)";
1175
- const DEFAULT_RING_WIDTH = 3;
1176
- const offsetTokens = { "0": 0, "1": 1, "2": 2, "4": 4, "8": 8 };
1177
- let offsetWidth;
1178
- if (!isArbitrary) {
1179
- offsetWidth = value in offsetTokens ? offsetTokens[value] : null;
1180
- } else {
1181
- offsetWidth = /^-?\d+(\.\d+)?$/.test(value) ? parseFloat(value) : value;
1182
- }
1183
- if (offsetWidth === null || typeof offsetWidth === "number" && isNaN(offsetWidth)) return null;
1184
- const isZero = offsetWidth === 0 || offsetWidth === "0";
1185
- const offsetCss = typeof offsetWidth === "number" ? `${offsetWidth}px` : offsetWidth;
1186
- return {
1187
- boxShadow: isZero ? `0 0 0 ${DEFAULT_RING_WIDTH}px ${DEFAULT_RING_COLOR}` : `0 0 0 ${offsetCss} #fff, 0 0 0 calc(${offsetCss} + ${DEFAULT_RING_WIDTH}px) ${DEFAULT_RING_COLOR}`
1188
- };
1189
- }
1190
- };
1191
- for (const [utility, [widthProp, colorProp]] of Object.entries(BORDER_SIDE_PROPS)) {
1192
- borderResolvers[utility] = makeBorderSideResolver(widthProp, colorProp);
1193
- }
1194
-
1195
- // src/core/resolvers/filters.ts
1196
- var FILTER_COMPOSE = "var(--kb-blur,) var(--kb-brightness,) var(--kb-contrast,) var(--kb-grayscale,) var(--kb-hue-rotate,) var(--kb-invert,) var(--kb-saturate,) var(--kb-sepia,) var(--kb-drop-shadow,)";
1197
- var BACKDROP_FILTER_COMPOSE = "var(--kb-backdrop-blur,) var(--kb-backdrop-brightness,) var(--kb-backdrop-contrast,) var(--kb-backdrop-grayscale,) var(--kb-backdrop-hue-rotate,) var(--kb-backdrop-invert,) var(--kb-backdrop-opacity,) var(--kb-backdrop-saturate,) var(--kb-backdrop-sepia,)";
1198
- var filterResolvers = {
1199
- // ── CSS Filters (composable via CSS variables, web-only) ─────────────────
1200
- blur: ({ value, isArbitrary }) => {
1201
- if (!getEffectiveIsWeb()) return null;
1202
- const sizes = {
1203
- "": "blur(8px)",
1204
- sm: "blur(4px)",
1205
- md: "blur(12px)",
1206
- lg: "blur(16px)",
1207
- xl: "blur(24px)",
1208
- "2xl": "blur(40px)",
1209
- "3xl": "blur(64px)"
1210
- };
1211
- if (value === "none") return { "--kb-blur": "", filter: FILTER_COMPOSE };
1212
- const v = isArbitrary ? `blur(${value})` : sizes[value];
1213
- return v !== void 0 ? { "--kb-blur": v, filter: FILTER_COMPOSE } : null;
1214
- },
1215
- brightness: ({ value, isArbitrary }) => {
1216
- if (!getEffectiveIsWeb()) return null;
1217
- const v = isArbitrary ? `brightness(${value})` : `brightness(${parseFloat(value) / 100})`;
1218
- return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-brightness": v, filter: FILTER_COMPOSE };
1219
- },
1220
- contrast: ({ value, isArbitrary }) => {
1221
- if (!getEffectiveIsWeb()) return null;
1222
- const v = isArbitrary ? `contrast(${value})` : `contrast(${parseFloat(value) / 100})`;
1223
- return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-contrast": v, filter: FILTER_COMPOSE };
1224
- },
1225
- grayscale: ({ value, isArbitrary }) => {
1226
- if (!getEffectiveIsWeb()) return null;
1227
- const v = isArbitrary ? `grayscale(${value})` : value === "0" ? "grayscale(0)" : "grayscale(100%)";
1228
- return { "--kb-grayscale": v, filter: FILTER_COMPOSE };
1229
- },
1230
- "hue-rotate": ({ value, negative, isArbitrary }) => {
1231
- if (!getEffectiveIsWeb()) return null;
1232
- const deg = isArbitrary ? value : `${(negative ? -1 : 1) * parseFloat(value)}deg`;
1233
- if (isNaN(parseFloat(deg)) && !isArbitrary) return null;
1234
- return { "--kb-hue-rotate": `hue-rotate(${deg})`, filter: FILTER_COMPOSE };
1235
- },
1236
- invert: ({ value, isArbitrary }) => {
1237
- if (!getEffectiveIsWeb()) return null;
1238
- const v = isArbitrary ? `invert(${value})` : value === "0" ? "invert(0)" : "invert(100%)";
1239
- return { "--kb-invert": v, filter: FILTER_COMPOSE };
1240
- },
1241
- saturate: ({ value, isArbitrary }) => {
1242
- if (!getEffectiveIsWeb()) return null;
1243
- const v = isArbitrary ? `saturate(${value})` : `saturate(${parseFloat(value) / 100})`;
1244
- return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-saturate": v, filter: FILTER_COMPOSE };
1245
- },
1246
- sepia: ({ value, isArbitrary }) => {
1247
- if (!getEffectiveIsWeb()) return null;
1248
- const v = isArbitrary ? `sepia(${value})` : value === "0" ? "sepia(0)" : "sepia(100%)";
1249
- return { "--kb-sepia": v, filter: FILTER_COMPOSE };
1250
- },
1251
- "drop-shadow": ({ value, isArbitrary }) => {
1252
- if (!getEffectiveIsWeb()) return null;
1253
- if (isArbitrary) return { "--kb-drop-shadow": `drop-shadow(${value.replace(/_/g, " ")})`, filter: FILTER_COMPOSE };
1254
- const presets = {
1255
- "": "drop-shadow(0 1px 2px rgb(0 0 0/0.1)) drop-shadow(0 1px 1px rgb(0 0 0/0.06))",
1256
- sm: "drop-shadow(0 1px 1px rgb(0 0 0/0.05))",
1257
- md: "drop-shadow(0 4px 3px rgb(0 0 0/0.07)) drop-shadow(0 2px 2px rgb(0 0 0/0.06))",
1258
- lg: "drop-shadow(0 10px 8px rgb(0 0 0/0.04)) drop-shadow(0 4px 3px rgb(0 0 0/0.1))",
1259
- xl: "drop-shadow(0 20px 13px rgb(0 0 0/0.03)) drop-shadow(0 8px 5px rgb(0 0 0/0.08))",
1260
- "2xl": "drop-shadow(0 25px 25px rgb(0 0 0/0.15))",
1261
- none: "drop-shadow(0 0 #0000)"
1262
- };
1263
- const v = presets[value];
1264
- return v !== void 0 ? { "--kb-drop-shadow": v, filter: FILTER_COMPOSE } : null;
1265
- },
1266
- // Arbitrary full filter string: filter-[blur(4px)_grayscale(1)]
1267
- filter: ({ value, isArbitrary }) => {
1268
- if (!getEffectiveIsWeb()) return null;
1269
- if (isArbitrary) return { filter: value.replace(/_/g, " ") };
1270
- if (value === "none") return { filter: "none" };
1271
- return null;
1272
- },
1273
- // ── Backdrop Filters (composable via CSS variables, web-only) ────────────
1274
- "backdrop-blur": ({ value, isArbitrary }) => {
1275
- if (!getEffectiveIsWeb()) return null;
1276
- const sizes = {
1277
- "": "blur(8px)",
1278
- sm: "blur(4px)",
1279
- md: "blur(12px)",
1280
- lg: "blur(16px)",
1281
- xl: "blur(24px)",
1282
- "2xl": "blur(40px)",
1283
- "3xl": "blur(64px)"
1284
- };
1285
- if (value === "none") return { "--kb-backdrop-blur": "", backdropFilter: BACKDROP_FILTER_COMPOSE };
1286
- const v = isArbitrary ? `blur(${value})` : sizes[value];
1287
- return v !== void 0 ? { "--kb-backdrop-blur": v, backdropFilter: BACKDROP_FILTER_COMPOSE } : null;
1288
- },
1289
- "backdrop-brightness": ({ value, isArbitrary }) => {
1290
- if (!getEffectiveIsWeb()) return null;
1291
- const v = isArbitrary ? `brightness(${value})` : `brightness(${parseFloat(value) / 100})`;
1292
- return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-backdrop-brightness": v, backdropFilter: BACKDROP_FILTER_COMPOSE };
1293
- },
1294
- "backdrop-contrast": ({ value, isArbitrary }) => {
1295
- if (!getEffectiveIsWeb()) return null;
1296
- const v = isArbitrary ? `contrast(${value})` : `contrast(${parseFloat(value) / 100})`;
1297
- return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-backdrop-contrast": v, backdropFilter: BACKDROP_FILTER_COMPOSE };
1298
- },
1299
- "backdrop-grayscale": ({ value, isArbitrary }) => {
1300
- if (!getEffectiveIsWeb()) return null;
1301
- const v = isArbitrary ? `grayscale(${value})` : value === "0" ? "grayscale(0)" : "grayscale(100%)";
1302
- return { "--kb-backdrop-grayscale": v, backdropFilter: BACKDROP_FILTER_COMPOSE };
1303
- },
1304
- "backdrop-hue-rotate": ({ value, negative, isArbitrary }) => {
1305
- if (!getEffectiveIsWeb()) return null;
1306
- const deg = isArbitrary ? value : `${(negative ? -1 : 1) * parseFloat(value)}deg`;
1307
- if (isNaN(parseFloat(deg)) && !isArbitrary) return null;
1308
- return { "--kb-backdrop-hue-rotate": `hue-rotate(${deg})`, backdropFilter: BACKDROP_FILTER_COMPOSE };
1309
- },
1310
- "backdrop-invert": ({ value, isArbitrary }) => {
1311
- if (!getEffectiveIsWeb()) return null;
1312
- const v = isArbitrary ? `invert(${value})` : value === "0" ? "invert(0)" : "invert(100%)";
1313
- return { "--kb-backdrop-invert": v, backdropFilter: BACKDROP_FILTER_COMPOSE };
1314
- },
1315
- "backdrop-opacity": ({ value, isArbitrary }) => {
1316
- if (!getEffectiveIsWeb()) return null;
1317
- const v = isArbitrary ? `opacity(${value})` : `opacity(${parseFloat(value) / 100})`;
1318
- return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-backdrop-opacity": v, backdropFilter: BACKDROP_FILTER_COMPOSE };
1319
- },
1320
- "backdrop-saturate": ({ value, isArbitrary }) => {
1321
- if (!getEffectiveIsWeb()) return null;
1322
- const v = isArbitrary ? `saturate(${value})` : `saturate(${parseFloat(value) / 100})`;
1323
- return isNaN(parseFloat(value)) && !isArbitrary ? null : { "--kb-backdrop-saturate": v, backdropFilter: BACKDROP_FILTER_COMPOSE };
1324
- },
1325
- "backdrop-sepia": ({ value, isArbitrary }) => {
1326
- if (!getEffectiveIsWeb()) return null;
1327
- const v = isArbitrary ? `sepia(${value})` : value === "0" ? "sepia(0)" : "sepia(100%)";
1328
- return { "--kb-backdrop-sepia": v, backdropFilter: BACKDROP_FILTER_COMPOSE };
1329
- },
1330
- "backdrop-filter": ({ value, isArbitrary }) => {
1331
- if (!getEffectiveIsWeb()) return null;
1332
- if (isArbitrary) return { backdropFilter: value.replace(/_/g, " ") };
1333
- if (value === "none") return { backdropFilter: "none" };
1334
- return null;
1335
- },
1336
- // ── Mix / background blend mode (web-only) ───────────────────────────────
1337
- "mix-blend": ({ value }) => {
1338
- if (!getEffectiveIsWeb()) return null;
1339
- const modes = [
1340
- "normal",
1341
- "multiply",
1342
- "screen",
1343
- "overlay",
1344
- "darken",
1345
- "lighten",
1346
- "color-dodge",
1347
- "color-burn",
1348
- "hard-light",
1349
- "soft-light",
1350
- "difference",
1351
- "exclusion",
1352
- "hue",
1353
- "saturation",
1354
- "color",
1355
- "luminosity",
1356
- "plus-lighter"
1357
- ];
1358
- return modes.includes(value) ? { mixBlendMode: value } : null;
1359
- },
1360
- "bg-blend": ({ value }) => {
1361
- if (!getEffectiveIsWeb()) return null;
1362
- const modes = [
1363
- "normal",
1364
- "multiply",
1365
- "screen",
1366
- "overlay",
1367
- "darken",
1368
- "lighten",
1369
- "color-dodge",
1370
- "color-burn",
1371
- "hard-light",
1372
- "soft-light",
1373
- "difference",
1374
- "exclusion",
1375
- "hue",
1376
- "saturation",
1377
- "color",
1378
- "luminosity"
1379
- ];
1380
- return modes.includes(value) ? { backgroundBlendMode: value } : null;
1381
- },
1382
- // ── Will-change (web-only) ─────────────────────────────────────────────────
1383
- "will-change": ({ value, isArbitrary }) => {
1384
- if (!getEffectiveIsWeb()) return null;
1385
- if (isArbitrary) return { willChange: value.replace(/_/g, ", ") };
1386
- const presets = {
1387
- auto: "auto",
1388
- scroll: "scroll-position",
1389
- contents: "contents",
1390
- transform: "transform"
1391
- };
1392
- return presets[value] ? { willChange: presets[value] } : null;
1393
- }
1394
- };
1395
-
1396
- // src/core/resolvers/layout.ts
1397
- var _standalone = null;
1398
- var _standaloneWeb = null;
1399
- function buildStandalone(web) {
1400
- return {
1401
- // Display
1402
- // React Native only supports display:'flex'|'none'. Setting 'flex' explicitly is
1403
- // a no-op normally, but is needed to re-show an element that was hidden via `hidden`.
1404
- // `grid`, `contents`, `flow-root` have no native equivalent and stay null there.
1405
- // The inline-* family (inline, inline-block, inline-flex, inline-grid) falls back
1406
- // to 'flex' on native instead — like plain `flex`, this is a no-op most of the
1407
- // time, but without it these utilities couldn't re-show a `hidden` element on
1408
- // native either (null → no style applied → still display:'none').
1409
- flex: { display: "flex" },
1410
- block: web ? { display: "block" } : null,
1411
- "inline-block": { display: web ? "inline-block" : "flex" },
1412
- inline: { display: web ? "inline" : "flex" },
1413
- grid: web ? { display: "grid" } : null,
1414
- "inline-flex": { display: web ? "inline-flex" : "flex" },
1415
- "inline-grid": { display: web ? "inline-grid" : "flex" },
1416
- hidden: { display: "none" },
1417
- contents: web ? { display: "contents" } : null,
1418
- "flow-root": web ? { display: "flow-root" } : null,
1419
- // Flex direction, wrap, grow/shrink, and alignment (both web and native) —
1420
- // every one of these is meaningless without the element also being a flex
1421
- // container. React Native Views are ALWAYS flex containers by default, so
1422
- // on native this was already true for free; on web a plain <div> defaults
1423
- // to display:block, so e.g. `items-center` alone silently did nothing.
1424
- // Folding `display: 'flex'` into these on web closes that native/web gap —
1425
- // `flex-1 items-center justify-center` now behaves the same on both,
1426
- // without also needing a separate `flex` class.
1427
- "flex-row": { flexDirection: "row", ...web ? { display: "flex" } : {} },
1428
- "flex-col": { flexDirection: "column", ...web ? { display: "flex" } : {} },
1429
- "flex-row-reverse": { flexDirection: "row-reverse", ...web ? { display: "flex" } : {} },
1430
- "flex-col-reverse": { flexDirection: "column-reverse", ...web ? { display: "flex" } : {} },
1431
- // Flex wrap (both)
1432
- "flex-wrap": { flexWrap: "wrap", ...web ? { display: "flex" } : {} },
1433
- "flex-wrap-reverse": { flexWrap: "wrap-reverse", ...web ? { display: "flex" } : {} },
1434
- "flex-nowrap": { flexWrap: "nowrap", ...web ? { display: "flex" } : {} },
1435
- // Flex grow / shrink (both) — deliberately NOT folding in display:flex
1436
- // like the container-level properties above. flex-grow/flex-shrink are
1437
- // item-level: they already take effect purely via the PARENT already
1438
- // being a flex container, with zero dependency on this element's own
1439
- // display. Forcing display:flex here would instead be an unrelated side
1440
- // effect on THIS element's own children (turning what may be an ordinary
1441
- // block stack into a flex row) — exactly the kind of surprise the
1442
- // container-level properties above can never cause, since those are
1443
- // no-ops without display:flex to begin with.
1444
- "flex-grow": { flexGrow: 1 },
1445
- "flex-grow-0": { flexGrow: 0 },
1446
- "flex-shrink": { flexShrink: 1 },
1447
- "flex-shrink-0": { flexShrink: 0 },
1448
- // Align items (both)
1449
- "items-start": { alignItems: "flex-start", ...web ? { display: "flex" } : {} },
1450
- "items-end": { alignItems: "flex-end", ...web ? { display: "flex" } : {} },
1451
- "items-center": { alignItems: "center", ...web ? { display: "flex" } : {} },
1452
- "items-baseline": { alignItems: "baseline", ...web ? { display: "flex" } : {} },
1453
- "items-stretch": { alignItems: "stretch", ...web ? { display: "flex" } : {} },
1454
- // Justify content (both)
1455
- "justify-start": { justifyContent: "flex-start", ...web ? { display: "flex" } : {} },
1456
- "justify-end": { justifyContent: "flex-end", ...web ? { display: "flex" } : {} },
1457
- "justify-center": { justifyContent: "center", ...web ? { display: "flex" } : {} },
1458
- "justify-between": { justifyContent: "space-between", ...web ? { display: "flex" } : {} },
1459
- "justify-around": { justifyContent: "space-around", ...web ? { display: "flex" } : {} },
1460
- "justify-evenly": { justifyContent: "space-evenly", ...web ? { display: "flex" } : {} },
1461
- // Align content (both)
1462
- "content-start": { alignContent: "flex-start", ...web ? { display: "flex" } : {} },
1463
- "content-end": { alignContent: "flex-end", ...web ? { display: "flex" } : {} },
1464
- "content-center": { alignContent: "center", ...web ? { display: "flex" } : {} },
1465
- "content-between": { alignContent: "space-between", ...web ? { display: "flex" } : {} },
1466
- "content-around": { alignContent: "space-around", ...web ? { display: "flex" } : {} },
1467
- "content-evenly": { alignContent: "space-evenly", ...web ? { display: "flex" } : {} },
1468
- "content-stretch": { alignContent: "stretch", ...web ? { display: "flex" } : {} },
1469
- // Align self (both)
1470
- "self-auto": { alignSelf: "auto" },
1471
- "self-start": { alignSelf: "flex-start" },
1472
- "self-end": { alignSelf: "flex-end" },
1473
- "self-center": { alignSelf: "center" },
1474
- "self-stretch": { alignSelf: "stretch" },
1475
- "self-baseline": { alignSelf: "baseline" },
1476
- // Text align (both)
1477
- "text-left": { textAlign: "left" },
1478
- "text-right": { textAlign: "right" },
1479
- "text-center": { textAlign: "center" },
1480
- "text-justify": { textAlign: "justify" },
1481
- // Font weight shortcuts (both)
1482
- "font-thin": { fontWeight: "100" },
1483
- "font-extralight": { fontWeight: "200" },
1484
- "font-light": { fontWeight: "300" },
1485
- "font-normal": { fontWeight: "400" },
1486
- "font-medium": { fontWeight: "500" },
1487
- "font-semibold": { fontWeight: "600" },
1488
- "font-bold": { fontWeight: "700" },
1489
- "font-extrabold": { fontWeight: "800" },
1490
- "font-black": { fontWeight: "900" },
1491
- // Text decoration (overline is web-only)
1492
- underline: { textDecorationLine: "underline" },
1493
- overline: web ? { textDecorationLine: "overline" } : null,
1494
- "line-through": { textDecorationLine: "line-through" },
1495
- "no-underline": { textDecorationLine: "none" },
1496
- // Text transform (both)
1497
- uppercase: { textTransform: "uppercase" },
1498
- lowercase: { textTransform: "lowercase" },
1499
- capitalize: { textTransform: "capitalize" },
1500
- "normal-case": { textTransform: "none" },
1501
- // Font style (both)
1502
- italic: { fontStyle: "italic" },
1503
- "non-italic": { fontStyle: "normal" },
1504
- // Position (fixed/sticky/static are web-only; RN only supports relative/absolute)
1505
- relative: { position: "relative" },
1506
- absolute: { position: "absolute" },
1507
- fixed: web ? { position: "fixed" } : null,
1508
- sticky: web ? { position: "sticky" } : null,
1509
- static: web ? { position: "static" } : null,
1510
- // Visibility (no `visibility` prop on native; use opacity instead)
1511
- visible: web ? { visibility: "visible" } : null,
1512
- invisible: web ? { visibility: "hidden" } : { opacity: 0 },
1513
- // Overflow (RN supports 'hidden' | 'visible' | 'scroll'; not 'auto')
1514
- "overflow-hidden": { overflow: "hidden" },
1515
- "overflow-visible": { overflow: "visible" },
1516
- "overflow-scroll": { overflow: "scroll" },
1517
- "overflow-auto": web ? { overflow: "auto" } : { overflow: "scroll" },
1518
- // overflowX / overflowY are web-only
1519
- "overflow-x-hidden": web ? { overflowX: "hidden" } : null,
1520
- "overflow-x-scroll": web ? { overflowX: "scroll" } : null,
1521
- "overflow-x-auto": web ? { overflowX: "auto" } : null,
1522
- "overflow-y-hidden": web ? { overflowY: "hidden" } : null,
1523
- "overflow-y-scroll": web ? { overflowY: "scroll" } : null,
1524
- "overflow-y-auto": web ? { overflowY: "auto" } : null,
1525
- // Object fit (web-only; use resizeMode prop on RN Image)
1526
- "object-contain": web ? { objectFit: "contain" } : null,
1527
- "object-cover": web ? { objectFit: "cover" } : null,
1528
- "object-fill": web ? { objectFit: "fill" } : null,
1529
- "object-none": web ? { objectFit: "none" } : null,
1530
- "object-scale-down": web ? { objectFit: "scale-down" } : null,
1531
- // Border style (both)
1532
- "border-solid": { borderStyle: "solid" },
1533
- "border-dashed": { borderStyle: "dashed" },
1534
- "border-dotted": { borderStyle: "dotted" },
1535
- "border-none": { borderWidth: 0 },
1536
- // Border sides default width (both)
1537
- "border-t": { borderTopWidth: 1 },
1538
- "border-r": { borderRightWidth: 1 },
1539
- "border-b": { borderBottomWidth: 1 },
1540
- "border-l": { borderLeftWidth: 1 },
1541
- // Cursor (web-only)
1542
- "cursor-auto": web ? { cursor: "auto" } : null,
1543
- "cursor-default": web ? { cursor: "default" } : null,
1544
- "cursor-pointer": web ? { cursor: "pointer" } : null,
1545
- "cursor-wait": web ? { cursor: "wait" } : null,
1546
- "cursor-text": web ? { cursor: "text" } : null,
1547
- "cursor-move": web ? { cursor: "move" } : null,
1548
- "cursor-not-allowed": web ? { cursor: "not-allowed" } : null,
1549
- // User select (web-only)
1550
- "select-none": web ? { userSelect: "none" } : null,
1551
- "select-text": web ? { userSelect: "text" } : null,
1552
- "select-all": web ? { userSelect: "all" } : null,
1553
- "select-auto": web ? { userSelect: "auto" } : null,
1554
- // Pointer events (both)
1555
- "pointer-events-none": { pointerEvents: "none" },
1556
- "pointer-events-auto": { pointerEvents: "auto" },
1557
- // Whitespace (web-only; RN Text uses numberOfLines prop instead)
1558
- "whitespace-normal": web ? { whiteSpace: "normal" } : null,
1559
- "whitespace-nowrap": web ? { whiteSpace: "nowrap" } : null,
1560
- "whitespace-pre": web ? { whiteSpace: "pre" } : null,
1561
- "whitespace-pre-wrap": web ? { whiteSpace: "pre-wrap" } : null,
1562
- "whitespace-pre-line": web ? { whiteSpace: "pre-line" } : null,
1563
- // Word break (web-only)
1564
- "break-normal": web ? { overflowWrap: "normal", wordBreak: "normal" } : null,
1565
- "break-words": web ? { overflowWrap: "break-word" } : null,
1566
- "break-all": web ? { wordBreak: "break-all" } : null,
1567
- // Misc web-only
1568
- truncate: web ? { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } : null,
1569
- "box-border": web ? { boxSizing: "border-box" } : null,
1570
- "box-content": web ? { boxSizing: "content-box" } : null,
1571
- "appearance-none": web ? { appearance: "none" } : null,
1572
- "outline-none": web ? { outline: "none", outlineOffset: "0" } : null,
1573
- outline: web ? { outline: "2px solid transparent", outlineOffset: "2px" } : null,
1574
- resize: web ? { resize: "both" } : null,
1575
- "resize-none": web ? { resize: "none" } : null,
1576
- "resize-y": web ? { resize: "vertical" } : null,
1577
- "resize-x": web ? { resize: "horizontal" } : null,
1578
- antialiased: web ? { WebkitFontSmoothing: "antialiased", MozOsxFontSmoothing: "grayscale" } : null,
1579
- "subpixel-antialiased": web ? { WebkitFontSmoothing: "subpixel-antialiased", MozOsxFontSmoothing: "auto" } : null,
1580
- "overflow-ellipsis": web ? { textOverflow: "ellipsis" } : null,
1581
- "sr-only": web ? {
1582
- position: "absolute",
1583
- width: 1,
1584
- height: 1,
1585
- padding: 0,
1586
- margin: -1,
1587
- overflow: "hidden",
1588
- clip: "rect(0,0,0,0)",
1589
- whiteSpace: "nowrap",
1590
- border: 0
1591
- } : null,
1592
- "not-sr-only": web ? {
1593
- position: "static",
1594
- width: "auto",
1595
- height: "auto",
1596
- padding: 0,
1597
- margin: 0,
1598
- overflow: "visible",
1599
- clip: "auto",
1600
- whiteSpace: "normal"
1601
- } : null,
1602
- // Lists (web-only)
1603
- "list-none": web ? { listStyleType: "none" } : null,
1604
- "list-disc": web ? { listStyleType: "disc" } : null,
1605
- "list-decimal": web ? { listStyleType: "decimal" } : null,
1606
- // Background clip (web-only)
1607
- "bg-clip-border": web ? { backgroundClip: "border-box" } : null,
1608
- "bg-clip-padding": web ? { backgroundClip: "padding-box" } : null,
1609
- "bg-clip-content": web ? { backgroundClip: "content-box" } : null,
1610
- "bg-clip-text": web ? { backgroundClip: "text", WebkitBackgroundClip: "text" } : null,
1611
- // Background image
1612
- "bg-none": web ? { backgroundImage: "none" } : null,
1613
- // Background size (web-only)
1614
- "bg-auto": web ? { backgroundSize: "auto" } : null,
1615
- "bg-cover": web ? { backgroundSize: "cover" } : null,
1616
- "bg-contain": web ? { backgroundSize: "contain" } : null,
1617
- // Background position (web-only)
1618
- "bg-center": web ? { backgroundPosition: "center" } : null,
1619
- "bg-top": web ? { backgroundPosition: "top" } : null,
1620
- "bg-bottom": web ? { backgroundPosition: "bottom" } : null,
1621
- "bg-left": web ? { backgroundPosition: "left" } : null,
1622
- "bg-right": web ? { backgroundPosition: "right" } : null,
1623
- "bg-left-top": web ? { backgroundPosition: "left top" } : null,
1624
- "bg-left-bottom": web ? { backgroundPosition: "left bottom" } : null,
1625
- "bg-right-top": web ? { backgroundPosition: "right top" } : null,
1626
- "bg-right-bottom": web ? { backgroundPosition: "right bottom" } : null,
1627
- // Background repeat (web-only)
1628
- "bg-repeat": web ? { backgroundRepeat: "repeat" } : null,
1629
- "bg-no-repeat": web ? { backgroundRepeat: "no-repeat" } : null,
1630
- "bg-repeat-x": web ? { backgroundRepeat: "repeat-x" } : null,
1631
- "bg-repeat-y": web ? { backgroundRepeat: "repeat-y" } : null,
1632
- "bg-repeat-round": web ? { backgroundRepeat: "round" } : null,
1633
- "bg-repeat-space": web ? { backgroundRepeat: "space" } : null,
1634
- // Background attachment (web-only)
1635
- "bg-fixed": web ? { backgroundAttachment: "fixed" } : null,
1636
- "bg-local": web ? { backgroundAttachment: "local" } : null,
1637
- "bg-scroll": web ? { backgroundAttachment: "scroll" } : null,
1638
- // Object position (web-only)
1639
- "object-center": web ? { objectPosition: "center" } : null,
1640
- "object-top": web ? { objectPosition: "top" } : null,
1641
- "object-bottom": web ? { objectPosition: "bottom" } : null,
1642
- "object-left": web ? { objectPosition: "left" } : null,
1643
- "object-right": web ? { objectPosition: "right" } : null,
1644
- "object-left-top": web ? { objectPosition: "left top" } : null,
1645
- "object-left-bottom": web ? { objectPosition: "left bottom" } : null,
1646
- "object-right-top": web ? { objectPosition: "right top" } : null,
1647
- "object-right-bottom": web ? { objectPosition: "right bottom" } : null,
1648
- // Table (web-only)
1649
- table: web ? { display: "table" } : null,
1650
- "table-auto": web ? { tableLayout: "auto" } : null,
1651
- "table-fixed": web ? { tableLayout: "fixed" } : null,
1652
- "caption-top": web ? { captionSide: "top" } : null,
1653
- "caption-bottom": web ? { captionSide: "bottom" } : null,
1654
- "border-collapse": web ? { borderCollapse: "collapse" } : null,
1655
- "border-separate": web ? { borderCollapse: "separate" } : null,
1656
- // List style position (web-only)
1657
- "list-inside": web ? { listStylePosition: "inside" } : null,
1658
- "list-outside": web ? { listStylePosition: "outside" } : null,
1659
- // Font variant numeric (web-only)
1660
- "normal-nums": web ? { fontVariantNumeric: "normal" } : null,
1661
- ordinal: web ? { fontVariantNumeric: "ordinal" } : null,
1662
- "slashed-zero": web ? { fontVariantNumeric: "slashed-zero" } : null,
1663
- "lining-nums": web ? { fontVariantNumeric: "lining-nums" } : null,
1664
- "oldstyle-nums": web ? { fontVariantNumeric: "oldstyle-nums" } : null,
1665
- "proportional-nums": web ? { fontVariantNumeric: "proportional-nums" } : null,
1666
- "tabular-nums": web ? { fontVariantNumeric: "tabular-nums" } : null,
1667
- "diagonal-fractions": web ? { fontVariantNumeric: "diagonal-fractions" } : null,
1668
- "stacked-fractions": web ? { fontVariantNumeric: "stacked-fractions" } : null,
1669
- // Isolation (web-only)
1670
- isolate: web ? { isolation: "isolate" } : null,
1671
- "isolation-auto": web ? { isolation: "auto" } : null,
1672
- // Backface visibility (both iOS and Android)
1673
- "backface-visible": { backfaceVisibility: "visible" },
1674
- "backface-hidden": { backfaceVisibility: "hidden" },
1675
- // CSS filters — standalone = default/full effect (web-only)
1676
- grayscale: web ? { "--kb-grayscale": "grayscale(100%)", filter: FILTER_COMPOSE } : null,
1677
- invert: web ? { "--kb-invert": "invert(100%)", filter: FILTER_COMPOSE } : null,
1678
- sepia: web ? { "--kb-sepia": "sepia(100%)", filter: FILTER_COMPOSE } : null,
1679
- // Divide none
1680
- "divide-none": web ? { __divideX: 0, __divideY: 0 } : null,
1681
- // Group / peer markers (no-op: no style emitted; just ensures isKnownUtility returns true)
1682
- group: web ? {} : null,
1683
- peer: web ? {} : null,
1684
- // Text-wrap (web-only)
1685
- "text-wrap": web ? { textWrap: "wrap" } : null,
1686
- "text-nowrap": web ? { textWrap: "nowrap" } : null,
1687
- "text-balance": web ? { textWrap: "balance" } : null,
1688
- "text-pretty": web ? { textWrap: "pretty" } : null,
1689
- // Screen sizing — dvw/dvh (dynamic viewport units) instead of vw/vh: on mobile
1690
- // browsers, vh/vw are pinned to the LARGEST viewport size (address bar hidden),
1691
- // so `h-screen` overflows behind the address bar when it's shown. dvh/dvw track
1692
- // the actual visible viewport as browser chrome shows/hides. Desktop behavior
1693
- // is unchanged since there's no dynamic chrome to account for.
1694
- // (vw/dvw values are web-only; vh/dvh values work cross-platform via spacing scale for h-*)
1695
- "w-screen": web ? { width: "100dvw" } : null,
1696
- "min-h-screen": { minHeight: "100dvh" },
1697
- "max-h-screen": { maxHeight: "100dvh" },
1698
- "min-w-screen": web ? { minWidth: "100dvw" } : null,
1699
- "max-w-screen": web ? { maxWidth: "100dvw" } : null,
1700
- // max-w named container sizes (mirrors Tailwind's container scale)
1701
- "max-w-none": { maxWidth: "none" },
1702
- "max-w-xs": { maxWidth: 320 },
1703
- "max-w-sm": { maxWidth: 384 },
1704
- "max-w-md": { maxWidth: 448 },
1705
- "max-w-lg": { maxWidth: 512 },
1706
- "max-w-xl": { maxWidth: 576 },
1707
- "max-w-2xl": { maxWidth: 672 },
1708
- "max-w-3xl": { maxWidth: 768 },
1709
- "max-w-4xl": { maxWidth: 896 },
1710
- "max-w-5xl": { maxWidth: 1024 },
1711
- "max-w-6xl": { maxWidth: 1152 },
1712
- "max-w-7xl": { maxWidth: 1280 },
1713
- "max-w-prose": web ? { maxWidth: "65ch" } : null,
1714
- // Extended cursors (web-only)
1715
- "cursor-grab": web ? { cursor: "grab" } : null,
1716
- "cursor-grabbing": web ? { cursor: "grabbing" } : null,
1717
- "cursor-zoom-in": web ? { cursor: "zoom-in" } : null,
1718
- "cursor-zoom-out": web ? { cursor: "zoom-out" } : null,
1719
- "cursor-crosshair": web ? { cursor: "crosshair" } : null,
1720
- "cursor-help": web ? { cursor: "help" } : null,
1721
- "cursor-none": web ? { cursor: "none" } : null,
1722
- // Overflow clip (web-only)
1723
- "overflow-clip": web ? { overflow: "clip" } : null,
1724
- "overflow-x-clip": web ? { overflowX: "clip" } : null,
1725
- "overflow-y-clip": web ? { overflowY: "clip" } : null,
1726
- // Scroll behavior (web-only)
1727
- "scroll-smooth": web ? { scrollBehavior: "smooth" } : null,
1728
- "scroll-auto": web ? { scrollBehavior: "auto" } : null,
1729
- // Float (web-only)
1730
- "float-left": web ? { float: "left" } : null,
1731
- "float-right": web ? { float: "right" } : null,
1732
- "float-start": web ? { float: "inline-start" } : null,
1733
- "float-end": web ? { float: "inline-end" } : null,
1734
- "float-none": web ? { float: "none" } : null,
1735
- // Clear (web-only)
1736
- "clear-left": web ? { clear: "left" } : null,
1737
- "clear-right": web ? { clear: "right" } : null,
1738
- "clear-both": web ? { clear: "both" } : null,
1739
- "clear-start": web ? { clear: "inline-start" } : null,
1740
- "clear-end": web ? { clear: "inline-end" } : null,
1741
- "clear-none": web ? { clear: "none" } : null,
1742
- // Vertical align (web-only)
1743
- "align-baseline": web ? { verticalAlign: "baseline" } : null,
1744
- "align-top": web ? { verticalAlign: "top" } : null,
1745
- "align-middle": web ? { verticalAlign: "middle" } : null,
1746
- "align-bottom": web ? { verticalAlign: "bottom" } : null,
1747
- "align-text-top": web ? { verticalAlign: "text-top" } : null,
1748
- "align-text-bottom": web ? { verticalAlign: "text-bottom" } : null,
1749
- "align-sub": web ? { verticalAlign: "sub" } : null,
1750
- "align-super": web ? { verticalAlign: "super" } : null,
1751
- // Touch action (web-only)
1752
- "touch-auto": web ? { touchAction: "auto" } : null,
1753
- "touch-none": web ? { touchAction: "none" } : null,
1754
- "touch-pan-x": web ? { touchAction: "pan-x" } : null,
1755
- "touch-pan-y": web ? { touchAction: "pan-y" } : null,
1756
- "touch-pan-left": web ? { touchAction: "pan-left" } : null,
1757
- "touch-pan-right": web ? { touchAction: "pan-right" } : null,
1758
- "touch-pan-up": web ? { touchAction: "pan-up" } : null,
1759
- "touch-pan-down": web ? { touchAction: "pan-down" } : null,
1760
- "touch-pinch-zoom": web ? { touchAction: "pinch-zoom" } : null,
1761
- "touch-manipulation": web ? { touchAction: "manipulation" } : null
1762
- };
1763
- }
1764
- function getStandalone() {
1765
- const web = getEffectiveIsWeb();
1766
- if (!_standalone || _standaloneWeb !== web) {
1767
- _standalone = buildStandalone(web);
1768
- _standaloneWeb = web;
1769
- }
1770
- return _standalone;
1771
- }
1772
- var layoutResolvers = {
1773
- // ── Grid (responsive column count: grid-1 … grid-12, or arbitrary) ───────
1774
- grid: ({ value, isArbitrary }) => {
1775
- if (!value) return null;
1776
- if (isArbitrary) return { display: "grid", gridTemplateColumns: value };
1777
- const n = parseInt(value, 10);
1778
- if (isNaN(n) || n < 1 || n > 12) return null;
1779
- return { display: "grid", gridTemplateColumns: `repeat(${n}, minmax(0, 1fr))` };
1780
- },
1781
- // ── Grid template columns/rows (Tailwind-style aliases, web-only) ──────────
1782
- "grid-cols": ({ value, isArbitrary }) => {
1783
- if (!getEffectiveIsWeb()) return null;
1784
- if (!value) return null;
1785
- if (isArbitrary) return { display: "grid", gridTemplateColumns: value };
1786
- if (value === "none") return { display: "grid", gridTemplateColumns: "none" };
1787
- const n = parseInt(value, 10);
1788
- if (isNaN(n) || n < 1 || n > 12) return null;
1789
- return { display: "grid", gridTemplateColumns: `repeat(${n}, minmax(0, 1fr))` };
1790
- },
1791
- "grid-rows": ({ value, isArbitrary }) => {
1792
- if (!getEffectiveIsWeb()) return null;
1793
- if (!value) return null;
1794
- if (isArbitrary) return { gridTemplateRows: value };
1795
- if (value === "none") return { gridTemplateRows: "none" };
1796
- const n = parseInt(value, 10);
1797
- if (isNaN(n) || n < 1) return null;
1798
- return { gridTemplateRows: `repeat(${n}, minmax(0, 1fr))` };
1799
- },
1800
- // ── Grid auto flow (web-only) ─────────────────────────────────────────────
1801
- "grid-flow": ({ value }) => {
1802
- if (!getEffectiveIsWeb()) return null;
1803
- const flows = {
1804
- row: "row",
1805
- col: "column",
1806
- dense: "dense",
1807
- "row-dense": "row dense",
1808
- "col-dense": "column dense"
1809
- };
1810
- const flow = flows[value];
1811
- return flow ? { gridAutoFlow: flow } : null;
1812
- },
1813
- // ── Grid auto sizing (web-only) ───────────────────────────────────────────
1814
- "auto-cols": ({ value, isArbitrary }) => {
1815
- if (!getEffectiveIsWeb()) return null;
1816
- if (isArbitrary) return { gridAutoColumns: value };
1817
- const presets = {
1818
- auto: "auto",
1819
- min: "min-content",
1820
- max: "max-content",
1821
- fr: "minmax(0, 1fr)"
1822
- };
1823
- const v = presets[value];
1824
- return v ? { gridAutoColumns: v } : null;
1825
- },
1826
- "auto-rows": ({ value, isArbitrary }) => {
1827
- if (!getEffectiveIsWeb()) return null;
1828
- if (isArbitrary) return { gridAutoRows: value };
1829
- const presets = {
1830
- auto: "auto",
1831
- min: "min-content",
1832
- max: "max-content",
1833
- fr: "minmax(0, 1fr)"
1834
- };
1835
- const v = presets[value];
1836
- return v ? { gridAutoRows: v } : null;
1837
- },
1838
- // ── Grid column placement (web-only) ──────────────────────────────────────
1839
- "col-span": ({ value }) => {
1840
- if (!getEffectiveIsWeb()) return null;
1841
- if (value === "full") return { gridColumn: "1 / -1" };
1842
- const n = parseInt(value, 10);
1843
- return isNaN(n) ? null : { gridColumn: `span ${n} / span ${n}` };
1844
- },
1845
- "col-start": ({ value, isArbitrary }) => {
1846
- if (!getEffectiveIsWeb()) return null;
1847
- if (value === "auto") return { gridColumnStart: "auto" };
1848
- if (isArbitrary) return { gridColumnStart: value };
1849
- const n = parseInt(value, 10);
1850
- return isNaN(n) ? null : { gridColumnStart: n };
1851
- },
1852
- "col-end": ({ value, isArbitrary }) => {
1853
- if (!getEffectiveIsWeb()) return null;
1854
- if (value === "auto") return { gridColumnEnd: "auto" };
1855
- if (isArbitrary) return { gridColumnEnd: value };
1856
- const n = parseInt(value, 10);
1857
- return isNaN(n) ? null : { gridColumnEnd: n };
1858
- },
1859
- col: ({ value, isArbitrary }) => {
1860
- if (!getEffectiveIsWeb()) return null;
1861
- if (!value || value === "auto") return { gridColumn: "auto" };
1862
- if (isArbitrary) return { gridColumn: value };
1863
- return null;
1864
- },
1865
- // ── Grid row placement (web-only) ─────────────────────────────────────────
1866
- "row-span": ({ value }) => {
1867
- if (!getEffectiveIsWeb()) return null;
1868
- if (value === "full") return { gridRow: "1 / -1" };
1869
- const n = parseInt(value, 10);
1870
- return isNaN(n) ? null : { gridRow: `span ${n} / span ${n}` };
1871
- },
1872
- "row-start": ({ value, isArbitrary }) => {
1873
- if (!getEffectiveIsWeb()) return null;
1874
- if (value === "auto") return { gridRowStart: "auto" };
1875
- if (isArbitrary) return { gridRowStart: value };
1876
- const n = parseInt(value, 10);
1877
- return isNaN(n) ? null : { gridRowStart: n };
1878
- },
1879
- "row-end": ({ value, isArbitrary }) => {
1880
- if (!getEffectiveIsWeb()) return null;
1881
- if (value === "auto") return { gridRowEnd: "auto" };
1882
- if (isArbitrary) return { gridRowEnd: value };
1883
- const n = parseInt(value, 10);
1884
- return isNaN(n) ? null : { gridRowEnd: n };
1885
- },
1886
- row: ({ value, isArbitrary }) => {
1887
- if (!getEffectiveIsWeb()) return null;
1888
- if (!value || value === "auto") return { gridRow: "auto" };
1889
- if (isArbitrary) return { gridRow: value };
1890
- return null;
1891
- },
1892
- // ── Grid alignment (web-only) ──────────────────────────────────────────────
1893
- // place-items is shorthand for align-items + justify-items on a grid container
1894
- "place-items": ({ value }) => {
1895
- if (!getEffectiveIsWeb()) return null;
1896
- const map = {
1897
- start: "start",
1898
- end: "end",
1899
- center: "center",
1900
- stretch: "stretch",
1901
- baseline: "baseline"
1902
- };
1903
- return map[value] ? { placeItems: map[value] } : null;
1904
- },
1905
- // place-content is shorthand for align-content + justify-content on a grid container
1906
- "place-content": ({ value }) => {
1907
- if (!getEffectiveIsWeb()) return null;
1908
- const map = {
1909
- start: "start",
1910
- end: "end",
1911
- center: "center",
1912
- stretch: "stretch",
1913
- between: "space-between",
1914
- around: "space-around",
1915
- evenly: "space-evenly",
1916
- baseline: "baseline"
1917
- };
1918
- return map[value] ? { placeContent: map[value] } : null;
1919
- },
1920
- // justify-items controls inline-axis alignment of grid items within their cells
1921
- "justify-items": ({ value }) => {
1922
- if (!getEffectiveIsWeb()) return null;
1923
- const map = {
1924
- start: "start",
1925
- end: "end",
1926
- center: "center",
1927
- stretch: "stretch"
1928
- };
1929
- return map[value] ? { justifyItems: map[value] } : null;
1930
- },
1931
- // place-self is shorthand for align-self + justify-self on a grid item
1932
- "place-self": ({ value }) => {
1933
- if (!getEffectiveIsWeb()) return null;
1934
- const map = {
1935
- auto: "auto",
1936
- start: "start",
1937
- end: "end",
1938
- center: "center",
1939
- stretch: "stretch"
1940
- };
1941
- return map[value] ? { placeSelf: map[value] } : null;
1942
- },
1943
- // justify-self controls inline-axis self-alignment of a grid item
1944
- "justify-self": ({ value }) => {
1945
- if (!getEffectiveIsWeb()) return null;
1946
- const map = {
1947
- auto: "auto",
1948
- start: "start",
1949
- end: "end",
1950
- center: "center",
1951
- stretch: "stretch"
1952
- };
1953
- return map[value] ? { justifySelf: map[value] } : null;
1954
- },
1955
- // ── Flex ───────────────────────────────────────────────────────────────────
1956
- // flex-1/flex-auto/flex-none/grow/shrink are item-level sizing properties —
1957
- // deliberately NOT implying display:flex here. See the "Flex grow / shrink"
1958
- // comment in the standalone table above for why: these already work via the
1959
- // PARENT's flex context regardless of this element's own display, so
1960
- // forcing display:flex here would only be a surprising, unrelated side
1961
- // effect on this element's OWN children.
1962
- flex: ({ value, isArbitrary }, { flex }) => {
1963
- if (!value) return { display: "flex" };
1964
- if (isArbitrary) {
1965
- const v = parseFloat(value);
1966
- return isNaN(v) ? null : { flex: v };
1967
- }
1968
- if (value in flex) {
1969
- const v = flex[value];
1970
- if (typeof v === "string" && !getEffectiveIsWeb()) {
1971
- if (v === "auto" || v === "initial") return { flex: 1 };
1972
- if (v === "none") return { flex: 0 };
1973
- return null;
1974
- }
1975
- return { flex: v };
1976
- }
1977
- const n = parseFloat(value);
1978
- return isNaN(n) ? null : { flex: n };
1979
- },
1980
- grow: ({ value }, _) => {
1981
- if (!value) return { flexGrow: 1 };
1982
- const n = parseFloat(value);
1983
- return { flexGrow: isNaN(n) ? 1 : n };
1984
- },
1985
- shrink: ({ value }, _) => {
1986
- if (!value) return { flexShrink: 1 };
1987
- const n = parseFloat(value);
1988
- return { flexShrink: isNaN(n) ? 1 : n };
1989
- },
1990
- order: ({ value, negative }, _) => {
1991
- const n = parseInt(value, 10);
1992
- return isNaN(n) ? null : { order: negative ? -n : n };
1993
- },
1994
- // ── Z-index ────────────────────────────────────────────────────────────────
1995
- z: ({ value, isArbitrary }, { zIndex }) => {
1996
- if (isArbitrary) {
1997
- const n2 = parseInt(value);
1998
- return isNaN(n2) ? null : { zIndex: n2 };
1999
- }
2000
- const v = zIndex[value];
2001
- if (v !== void 0) {
2002
- if (v === "auto") return getEffectiveIsWeb() ? { zIndex: "auto" } : null;
2003
- return { zIndex: v };
2004
- }
2005
- const n = parseInt(value);
2006
- return isNaN(n) ? null : { zIndex: n };
2007
- },
2008
- // ── Aspect ratio ───────────────────────────────────────────────────────────
2009
- aspect: ({ value, isArbitrary }) => {
2010
- if (isArbitrary) return { aspectRatio: value };
2011
- const presets = { auto: "auto", square: 1, video: 16 / 9 };
2012
- if (!(value in presets)) return null;
2013
- const v = presets[value];
2014
- if (v === "auto") return getEffectiveIsWeb() ? { aspectRatio: "auto" } : null;
2015
- return { aspectRatio: v };
2016
- },
2017
- // ── Columns (web-only) ─────────────────────────────────────────────────────
2018
- columns: ({ value, isArbitrary }) => {
2019
- if (!getEffectiveIsWeb()) return null;
2020
- if (isArbitrary) return { columnCount: value };
2021
- if (value === "auto") return { columnCount: "auto" };
2022
- const n = parseInt(value, 10);
2023
- if (!isNaN(n)) return { columnCount: n };
2024
- const widths = {
2025
- "3xs": "16rem",
2026
- "2xs": "18rem",
2027
- xs: "20rem",
2028
- sm: "24rem",
2029
- md: "28rem",
2030
- lg: "32rem",
2031
- xl: "36rem",
2032
- "2xl": "42rem",
2033
- "3xl": "48rem",
2034
- "4xl": "56rem",
2035
- "5xl": "64rem",
2036
- "6xl": "72rem",
2037
- "7xl": "80rem"
2038
- };
2039
- return widths[value] ? { columnWidth: widths[value] } : null;
2040
- }
2041
- };
2042
-
2043
- // src/core/resolvers/typography.ts
2044
- function resolveFontSize(value, fontSizes, isArbitrary) {
2045
- if (isArbitrary) return getEffectiveIsWeb() ? value : toNativeValue(value);
2046
- return fontSizes[value] ?? null;
2047
- }
2048
- var typographyResolvers = {
2049
- // ── Text ───────────────────────────────────────────────────────────────────
2050
- text: ({ value, isArbitrary }, { colors, fontSize }) => {
2051
- const size = resolveFontSize(value, fontSize, false);
2052
- if (!isArbitrary && size !== null) return { fontSize: size };
2053
- if (isArbitrary) {
2054
- if (/^\d/.test(value) || /^(calc|min|max|clamp)/.test(value)) {
2055
- return { fontSize: getEffectiveIsWeb() ? value : toNativeValue(value) };
2056
- }
2057
- return { color: getEffectiveIsWeb() ? withOpacityVar(value, "--text-opacity") : value };
2058
- }
2059
- const color = resolveColor(value, colors, false);
2060
- if (!color) return null;
2061
- return { color: getEffectiveIsWeb() ? withOpacityVar(color, "--text-opacity") : color };
2062
- },
2063
- "text-opacity": ({ value, isArbitrary }, _) => {
2064
- if (!getEffectiveIsWeb()) return null;
2065
- const n = parseFloat(value);
2066
- if (isNaN(n)) return null;
2067
- const v = isArbitrary ? n > 1 ? n / 100 : n : n / 100;
2068
- return { "--text-opacity": v };
2069
- },
2070
- // ── Text decoration advanced (web-only) ───────────────────────────────────
2071
- decoration: ({ value, isArbitrary }, { colors }) => {
2072
- if (!getEffectiveIsWeb()) return null;
2073
- if (isArbitrary) {
2074
- if (/^\d/.test(value) || value.startsWith("calc(")) return { textDecorationThickness: value };
2075
- return { textDecorationColor: value };
2076
- }
2077
- const thickTokens = {
2078
- auto: "auto",
2079
- "from-font": "from-font",
2080
- "0": "0px",
2081
- "1": "1px",
2082
- "2": "2px",
2083
- "4": "4px",
2084
- "8": "8px"
2085
- };
2086
- if (value in thickTokens) return { textDecorationThickness: thickTokens[value] };
2087
- const styleTokens = {
2088
- solid: "solid",
2089
- dashed: "dashed",
2090
- dotted: "dotted",
2091
- double: "double",
2092
- wavy: "wavy"
2093
- };
2094
- if (value in styleTokens) return { textDecorationStyle: styleTokens[value] };
2095
- const color = resolveColor(value, colors, false);
2096
- return color ? { textDecorationColor: color } : null;
2097
- },
2098
- "underline-offset": ({ value, isArbitrary }) => {
2099
- if (!getEffectiveIsWeb()) return null;
2100
- if (isArbitrary) return { textUnderlineOffset: value };
2101
- const offsets = {
2102
- auto: "auto",
2103
- "0": "0px",
2104
- "1": "1px",
2105
- "2": "2px",
2106
- "4": "4px",
2107
- "8": "8px"
2108
- };
2109
- return offsets[value] ? { textUnderlineOffset: offsets[value] } : null;
2110
- },
2111
- // ── Content (web-only — for before:/after: pseudo-elements, which don't exist on native) ──
2112
- // Arbitrary value carries its own quotes from the bracket syntax (content-['*'] parses to
2113
- // the literal string 'you can see it' quotes included), so it passes straight through as a
2114
- // valid `content: '*'` CSS value with no extra wrapping needed.
2115
- content: ({ value, isArbitrary }) => {
2116
- if (!getEffectiveIsWeb()) return null;
2117
- if (isArbitrary) return { content: value };
2118
- const presets = { none: "none" };
2119
- return value in presets ? { content: presets[value] } : null;
2120
- },
2121
- // ── Font ───────────────────────────────────────────────────────────────────
2122
- font: ({ value, isArbitrary }, { fontFamily, fontWeight }) => {
2123
- if (isArbitrary) return { fontFamily: value };
2124
- if (value in fontFamily) {
2125
- const ff = fontFamily[value];
2126
- return { fontFamily: Array.isArray(ff) ? ff.join(", ") : ff };
2127
- }
2128
- if (value in fontWeight) return { fontWeight: String(fontWeight[value]) };
2129
- return null;
2130
- },
2131
- // ── Line height ────────────────────────────────────────────────────────────
2132
- leading: ({ value, isArbitrary }, { lineHeight }) => {
2133
- if (isArbitrary) return { lineHeight: getEffectiveIsWeb() ? value : toNativeValue(value) };
2134
- const v = lineHeight[value];
2135
- if (v === void 0) return null;
2136
- if (typeof v === "string" && !getEffectiveIsWeb()) return { lineHeight: toNativeValue(v) };
2137
- return { lineHeight: v };
2138
- },
2139
- // ── Letter spacing ─────────────────────────────────────────────────────────
2140
- tracking: ({ value, isArbitrary }, { letterSpacing }) => {
2141
- if (isArbitrary) return { letterSpacing: getEffectiveIsWeb() ? value : toNativeValue(value) };
2142
- const v = letterSpacing[value];
2143
- return v !== void 0 ? { letterSpacing: v } : null;
2144
- },
2145
- // ── Line-clamp (web-only) ─────────────────────────────────────────────────
2146
- "line-clamp": ({ value }) => {
2147
- if (!getEffectiveIsWeb()) return null;
2148
- if (value === "none") return { overflow: "visible", display: "block", WebkitLineClamp: "unset" };
2149
- const n = parseInt(value, 10);
2150
- if (isNaN(n) || n < 1) return null;
2151
- return {
2152
- overflow: "hidden",
2153
- display: "-webkit-box",
2154
- WebkitBoxOrient: "vertical",
2155
- WebkitLineClamp: n
2156
- };
2157
- }
2158
- };
2159
-
2160
- // src/core/resolvers/transform.ts
2161
- var transformResolvers = {
2162
- // ── Transform extras (web-only) ───────────────────────────────────────────
2163
- "skew-x": ({ value, negative, isArbitrary }) => {
2164
- const deg = isArbitrary ? value : `${(negative ? -1 : 1) * parseFloat(value)}deg`;
2165
- if (!isArbitrary && isNaN(parseFloat(value))) return null;
2166
- return getEffectiveIsWeb() ? { transform: `skewX(${deg})` } : { transform: [{ skewX: deg }] };
2167
- },
2168
- "skew-y": ({ value, negative, isArbitrary }) => {
2169
- const deg = isArbitrary ? value : `${(negative ? -1 : 1) * parseFloat(value)}deg`;
2170
- if (!isArbitrary && isNaN(parseFloat(value))) return null;
2171
- return getEffectiveIsWeb() ? { transform: `skewY(${deg})` } : { transform: [{ skewY: deg }] };
2172
- },
2173
- // Arbitrary full transform string: transform-[rotate(45deg)_scale(1.5)]
2174
- transform: ({ value, isArbitrary }) => {
2175
- if (!getEffectiveIsWeb()) return null;
2176
- if (isArbitrary) return { transform: value.replace(/_/g, " ") };
2177
- if (value === "none") return { transform: "none" };
2178
- return null;
2179
- },
2180
- // Transform origin
2181
- origin: ({ value, isArbitrary }) => {
2182
- if (!getEffectiveIsWeb()) return null;
2183
- if (isArbitrary) return { transformOrigin: value.replace(/_/g, " ") };
2184
- const origins = {
2185
- center: "center",
2186
- top: "top",
2187
- "top-right": "top right",
2188
- right: "right",
2189
- "bottom-right": "bottom right",
2190
- bottom: "bottom",
2191
- "bottom-left": "bottom left",
2192
- left: "left",
2193
- "top-left": "top left"
2194
- };
2195
- return origins[value] ? { transformOrigin: origins[value] } : null;
2196
- },
2197
- // ── Scale ──────────────────────────────────────────────────────────────────
2198
- // Non-arbitrary: scale-150 → value='150' → 150/100 = 1.5
2199
- // Arbitrary: scale-[1.5] → value='1.5' → used as-is (already the factor)
2200
- scale: ({ value, isArbitrary }) => {
2201
- const n = isArbitrary ? parseFloat(value) : parseFloat(value) / 100;
2202
- if (isNaN(n)) return null;
2203
- return getEffectiveIsWeb() ? { transform: `scale(${n})` } : { transform: [{ scale: n }] };
2204
- },
2205
- "scale-x": ({ value, isArbitrary }) => {
2206
- const n = isArbitrary ? parseFloat(value) : parseFloat(value) / 100;
2207
- if (isNaN(n)) return null;
2208
- return getEffectiveIsWeb() ? { transform: `scaleX(${n})` } : { transform: [{ scaleX: n }] };
2209
- },
2210
- "scale-y": ({ value, isArbitrary }) => {
2211
- const n = isArbitrary ? parseFloat(value) : parseFloat(value) / 100;
2212
- if (isNaN(n)) return null;
2213
- return getEffectiveIsWeb() ? { transform: `scaleY(${n})` } : { transform: [{ scaleY: n }] };
2214
- },
2215
- // ── Rotate ─────────────────────────────────────────────────────────────────
2216
- rotate: ({ value, negative, isArbitrary }) => {
2217
- if (isArbitrary) {
2218
- const finalValue = negative ? `-${value}` : value;
2219
- return getEffectiveIsWeb() ? { transform: `rotate(${finalValue})` } : { transform: [{ rotate: finalValue }] };
2220
- }
2221
- const deg = parseFloat(value);
2222
- if (isNaN(deg)) return null;
2223
- const finalDeg = negative ? -deg : deg;
2224
- return getEffectiveIsWeb() ? { transform: `rotate(${finalDeg}deg)` } : { transform: [{ rotate: `${finalDeg}deg` }] };
2225
- },
2226
- // ── Perspective transform (cross-platform: iOS, Android, web) ────────────
2227
- perspective: ({ value, isArbitrary }) => {
2228
- if (isArbitrary) {
2229
- const numPx = parseFloat(value);
2230
- if (getEffectiveIsWeb()) return { transform: `perspective(${value})` };
2231
- return isNaN(numPx) ? null : { transform: [{ perspective: numPx }] };
2232
- }
2233
- if (value === "none") return getEffectiveIsWeb() ? { transform: "none" } : null;
2234
- const n = parseFloat(value);
2235
- if (isNaN(n)) return null;
2236
- return getEffectiveIsWeb() ? { transform: `perspective(${n}px)` } : { transform: [{ perspective: n }] };
2237
- }
2238
- };
2239
-
2240
- // src/core/resolvers/effects.ts
2241
- function keyframeDeclToCSS(decl) {
2242
- return Object.entries(decl).map(([prop, val]) => `${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${val}`).join("; ");
2243
- }
2244
- function buildKeyframeCSS(name, steps) {
2245
- const body = Object.entries(steps).map(([selector, decl]) => `${selector} { ${keyframeDeclToCSS(decl)} }`).join(" ");
2246
- return `@keyframes ${name} { ${body} }`;
2247
- }
2248
- var BUILTIN_ANIMATIONS = {
2249
- none: { animation: "none" },
2250
- spin: {
2251
- animation: "kb-spin 1s linear infinite",
2252
- __keyframe: "@keyframes kb-spin { from { transform: rotate(0deg) } to { transform: rotate(360deg) } }"
2253
- },
2254
- ping: {
2255
- animation: "kb-ping 1s cubic-bezier(0,0,0.2,1) infinite",
2256
- __keyframe: "@keyframes kb-ping { 75%, 100% { transform: scale(2); opacity: 0 } }"
2257
- },
2258
- pulse: {
2259
- animation: "kb-pulse 2s cubic-bezier(0.4,0,0.6,1) infinite",
2260
- __keyframe: "@keyframes kb-pulse { 0%, 100% { opacity: 1 } 50% { opacity: .5 } }"
2261
- },
2262
- bounce: {
2263
- animation: "kb-bounce 1s infinite",
2264
- __keyframe: "@keyframes kb-bounce { 0%, 100% { transform: translateY(-25%); animation-timing-function: cubic-bezier(0.8,0,1,1) } 50% { transform: none; animation-timing-function: cubic-bezier(0,0,0.2,1) } }"
2265
- }
2266
- };
2267
- function buildAnimationValue(animation, keyframes) {
2268
- const words = animation.trim().split(/\s+/);
2269
- const name = words[0];
2270
- if (!name) return { animation };
2271
- const builtin = BUILTIN_ANIMATIONS[name];
2272
- if (builtin?.__keyframe) {
2273
- const kbName = builtin.animation.split(/\s+/, 1)[0];
2274
- return { animation: [kbName, ...words.slice(1)].join(" "), __keyframe: builtin.__keyframe };
2275
- }
2276
- const steps = keyframes?.[name];
2277
- return steps ? { animation, __keyframe: buildKeyframeCSS(name, steps) } : { animation };
2278
- }
2279
- var effectResolvers = {
2280
- // ── Opacity ────────────────────────────────────────────────────────────────
2281
- opacity: ({ value, isArbitrary }, { opacity }) => {
2282
- if (isArbitrary) {
2283
- const v2 = parseFloat(value);
2284
- return isNaN(v2) ? null : { opacity: v2 > 1 ? v2 / 100 : v2 };
2285
- }
2286
- const v = opacity[value];
2287
- if (v !== void 0) return { opacity: v };
2288
- const n = parseFloat(value);
2289
- return isNaN(n) ? null : { opacity: n > 1 ? n / 100 : n };
2290
- },
2291
- // ── Shadow ─────────────────────────────────────────────────────────────────
2292
- // Presets carry BOTH a web `boxShadow` string and native's shadow*/elevation
2293
- // properties (theme.ts) — picked apart here rather than left for
2294
- // styleValueToCSS's RN_ONLY_PROPS filter to sort out, since shadowOffset is
2295
- // an object (filtered out as "not a flat style value" regardless of
2296
- // platform) and boxShadow would otherwise leak into native's style prop as
2297
- // an RN doesn't understand (silently ignored there, but better to not hand
2298
- // native a property that was never meant for it — same branch-on-platform
2299
- // pattern as bg-opacity/transition/animate above).
2300
- shadow: ({ value }, { shadow }) => {
2301
- const key = value === "" ? "DEFAULT" : value;
2302
- const preset = shadow[key];
2303
- if (!preset) return null;
2304
- if (getEffectiveIsWeb()) {
2305
- return preset.boxShadow !== void 0 ? { boxShadow: preset.boxShadow } : null;
2306
- }
2307
- const { boxShadow, ...native } = preset;
2308
- return Object.keys(native).length > 0 ? native : null;
2309
- },
2310
- // ── Animations (CSS keyframe animations, web-only) ────────────────────────
2311
- // Each variant injects a @keyframes rule once via the __keyframe marker.
2312
- // resolver.ts detects __keyframe, injects the rule, then strips the marker
2313
- // so it never reaches element inline styles.
2314
- animate: ({ value, isArbitrary }, theme) => {
2315
- if (!getEffectiveIsWeb()) return null;
2316
- if (isArbitrary) return buildAnimationValue(value.replace(/_/g, " "), theme.keyframes);
2317
- if (value in BUILTIN_ANIMATIONS) return BUILTIN_ANIMATIONS[value];
2318
- const custom = theme.animation?.[value];
2319
- return custom ? buildAnimationValue(custom, theme.keyframes) : null;
2320
- },
2321
- // ── Transition (web-only; use Animated API on native) ─────────────────────
2322
- transition: ({ value }) => {
2323
- if (!getEffectiveIsWeb()) return null;
2324
- const presets = {
2325
- "": "color 150ms, background-color 150ms, border-color 150ms, text-decoration-color 150ms, fill 150ms, stroke 150ms, opacity 150ms, box-shadow 150ms, transform 150ms, filter 150ms, backdrop-filter 150ms",
2326
- all: "all 150ms",
2327
- none: "none",
2328
- colors: "color 150ms, background-color 150ms, border-color 150ms",
2329
- opacity: "opacity 150ms",
2330
- shadow: "box-shadow 150ms",
2331
- transform: "transform 150ms"
2332
- };
2333
- const v = presets[value];
2334
- return v !== void 0 ? { transition: v } : null;
2335
- },
2336
- duration: ({ value, isArbitrary }) => {
2337
- if (!getEffectiveIsWeb()) return null;
2338
- if (!isArbitrary && isNaN(parseFloat(value))) return null;
2339
- const ms = isArbitrary ? value : `${value}ms`;
2340
- return { transitionDuration: ms };
2341
- },
2342
- delay: ({ value, isArbitrary }) => {
2343
- if (!getEffectiveIsWeb()) return null;
2344
- if (!isArbitrary && isNaN(parseFloat(value))) return null;
2345
- const ms = isArbitrary ? value : `${value}ms`;
2346
- return { transitionDelay: ms };
2347
- },
2348
- ease: ({ value, isArbitrary }) => {
2349
- if (!getEffectiveIsWeb()) return null;
2350
- if (isArbitrary) return { transitionTimingFunction: value };
2351
- const presets = {
2352
- linear: "linear",
2353
- in: "cubic-bezier(0.4, 0, 1, 1)",
2354
- out: "cubic-bezier(0, 0, 0.2, 1)",
2355
- "in-out": "cubic-bezier(0.4, 0, 0.2, 1)"
2356
- };
2357
- const v = presets[value];
2358
- return v !== void 0 ? { transitionTimingFunction: v } : null;
2359
- }
2360
- };
2361
-
2362
- // src/core/resolvers/misc.ts
2363
- var miscResolvers = {
2364
- // ── Arbitrary CSS property (web-only): [property:value] with no utility prefix ──
2365
- // e.g. [mask-type:luminance], [--my-var:10px]. parser.ts already isolates this case
2366
- // as utility: '' — it's ALSO how a stray, prefix-less negative bracket ("-[10px]",
2367
- // presumably a typo) parses, which is why this only fires when the arbitrary value
2368
- // itself contains a "property:value" pair; anything else (no colon) still resolves
2369
- // to null exactly as before this resolver existed, rather than guessing a property.
2370
- //
2371
- // Only the FIRST colon splits property from value — the value itself may contain
2372
- // more colons (a URL's "http://…") and must stay intact: [background:url(http://x/a.png)].
2373
- // camelToKebab() in resolver.ts is a no-op on an already-kebab-case (or "--"-prefixed
2374
- // custom property) key, so it can be used as the style object key as-written with no
2375
- // extra case conversion — it only needs to look like a plausible CSS property name.
2376
- "": ({ value, isArbitrary, negative }) => {
2377
- if (!getEffectiveIsWeb() || !isArbitrary || !value) return null;
2378
- if (negative) return null;
2379
- const colonIdx = value.indexOf(":");
2380
- if (colonIdx <= 0) return null;
2381
- const prop = value.slice(0, colonIdx).trim();
2382
- const cssValue = value.slice(colonIdx + 1).trim();
2383
- if (!cssValue || !/^(--[\w-]+|[a-zA-Z-]+)$/.test(prop)) return null;
2384
- return { [prop]: cssValue };
2385
- },
2386
- // ── SVG stroke/fill (web-only) ────────────────────────────────────────────
2387
- // Native is intentionally excluded: react-native-svg's <Path>/<Circle>/etc.
2388
- // take stroke/fill as component PROPS, not style entries, so there's no
2389
- // reliable way to apply a resolved color through the `style` prop there.
2390
- // `stroke-{n}` sets strokeWidth (a plain number, unlike a color) — same
2391
- // color-first-then-numeric-fallback disambiguation `border` uses above.
2392
- stroke: ({ value, isArbitrary }, { colors }) => {
2393
- if (!getEffectiveIsWeb()) return null;
2394
- if (!value) return null;
2395
- if (value === "none") return { stroke: "none" };
2396
- if (isArbitrary) {
2397
- const w = toNativeValue(value);
2398
- return typeof w === "number" ? { strokeWidth: w } : { stroke: value };
2399
- }
2400
- const color = resolveColor(value, colors, false);
2401
- if (color) return { stroke: color };
2402
- const n = parseFloat(value);
2403
- return isNaN(n) ? null : { strokeWidth: n };
2404
- },
2405
- fill: ({ value, isArbitrary }, { colors }) => {
2406
- if (!getEffectiveIsWeb()) return null;
2407
- if (!value) return null;
2408
- if (value === "none") return { fill: "none" };
2409
- if (isArbitrary) return { fill: value };
2410
- const color = resolveColor(value, colors, false);
2411
- return color ? { fill: color } : null;
2412
- },
2413
- // ── Text shadow (cross-platform: iOS, Android, web) ─────────────────────
2414
- // Named presets give cross-platform shadow; arbitrary is web-only.
2415
- "text-shadow": ({ value, isArbitrary }, { colors }) => {
2416
- if (value === "none") {
2417
- return getEffectiveIsWeb() ? { textShadow: "none" } : { textShadowColor: "transparent", textShadowOffset: { width: 0, height: 0 }, textShadowRadius: 0 };
2418
- }
2419
- const webPresets = {
2420
- "": "0 2px 4px rgba(0,0,0,0.3)",
2421
- sm: "0 1px 2px rgba(0,0,0,0.3)",
2422
- md: "0 4px 6px rgba(0,0,0,0.3)",
2423
- lg: "0 8px 16px rgba(0,0,0,0.5)",
2424
- xl: "0 16px 32px rgba(0,0,0,0.5)"
2425
- };
2426
- const nativePresets = {
2427
- "": { textShadowColor: "rgba(0,0,0,0.3)", textShadowOffset: { width: 0, height: 2 }, textShadowRadius: 4 },
2428
- sm: { textShadowColor: "rgba(0,0,0,0.3)", textShadowOffset: { width: 0, height: 1 }, textShadowRadius: 2 },
2429
- md: { textShadowColor: "rgba(0,0,0,0.3)", textShadowOffset: { width: 0, height: 4 }, textShadowRadius: 6 },
2430
- lg: { textShadowColor: "rgba(0,0,0,0.5)", textShadowOffset: { width: 0, height: 8 }, textShadowRadius: 16 },
2431
- xl: { textShadowColor: "rgba(0,0,0,0.5)", textShadowOffset: { width: 0, height: 16 }, textShadowRadius: 32 }
2432
- };
2433
- if (value in webPresets) {
2434
- if (getEffectiveIsWeb()) return { textShadow: webPresets[value] };
2435
- return nativePresets[value] ?? null;
2436
- }
2437
- if (isArbitrary) {
2438
- return getEffectiveIsWeb() ? { textShadow: value.replace(/_/g, " ") } : null;
2439
- }
2440
- const color = resolveColor(value, colors, false);
2441
- if (color) {
2442
- return getEffectiveIsWeb() ? { textShadow: `0 2px 4px ${color}` } : { textShadowColor: color };
2443
- }
2444
- return null;
2445
- }
2446
- };
2447
-
2448
- // src/core/utilities.ts
2449
- var RESOLVERS = {
2450
- ...colorResolvers,
2451
- ...spacingResolvers,
2452
- ...borderResolvers,
2453
- ...layoutResolvers,
2454
- ...typographyResolvers,
2455
- ...filterResolvers,
2456
- ...transformResolvers,
2457
- ...effectResolvers,
2458
- ...miscResolvers
2459
- };
2460
- var NAMED_GROUP_PEER_MARKER_RE = /^(group|peer)\/.+$/;
2461
- function resolveUtility(parsed, theme) {
2462
- if (!parsed.value) {
2463
- if (parsed.utility in PLUGIN_STANDALONE) return PLUGIN_STANDALONE[parsed.utility] ?? null;
2464
- if (parsed.utility in getStandalone()) return getStandalone()[parsed.utility] ?? null;
2465
- if (NAMED_GROUP_PEER_MARKER_RE.test(parsed.utility)) return getEffectiveIsWeb() ? {} : null;
2466
- }
2467
- const resolver = PLUGIN_RESOLVERS[parsed.utility] ?? RESOLVERS[parsed.utility];
2468
- if (resolver) return resolver(parsed, theme);
2469
- return null;
2470
- }
2471
- var PLUGIN_STANDALONE = {};
2472
- var PLUGIN_RESOLVERS = {};
2473
- function clearPluginUtilities() {
2474
- for (const key of Object.keys(PLUGIN_STANDALONE)) delete PLUGIN_STANDALONE[key];
2475
- for (const key of Object.keys(PLUGIN_RESOLVERS)) delete PLUGIN_RESOLVERS[key];
2476
- _sortedPrefixes = null;
2477
- _standaloneNames = null;
2478
- }
2479
- function getPluginStandaloneMap() {
2480
- return PLUGIN_STANDALONE;
2481
- }
2482
- var _sortedPrefixes = null;
2483
- var _standaloneNames = null;
2484
- function getBuiltinUtilityPrefixes() {
2485
- if (!_sortedPrefixes) {
2486
- const all = [.../* @__PURE__ */ new Set([...Object.keys(RESOLVERS), ...Object.keys(PLUGIN_RESOLVERS)])];
2487
- _sortedPrefixes = all.sort((a, b) => b.length - a.length);
2488
- }
2489
- return _sortedPrefixes;
2490
- }
2491
- function getBuiltinStandaloneNames() {
2492
- if (!_standaloneNames) {
2493
- _standaloneNames = /* @__PURE__ */ new Set([...Object.keys(getStandalone()), ...Object.keys(PLUGIN_STANDALONE)]);
2494
- }
2495
- return _standaloneNames;
2496
- }
2497
-
2498
- // src/core/devWarn.ts
2499
- function kbachWarn(message) {
2500
- console.warn(
2501
- "%c[kbach]%c " + message,
2502
- "color:#8b5cf6;font-weight:700",
2503
- "color:inherit;font-weight:400"
2504
- );
2505
- }
2506
-
2507
- // src/core/cache.ts
2508
- var LRUCache = class {
2509
- constructor(capacity = 1e4, onEvict) {
2510
- this.capacity = capacity;
2511
- if (capacity <= 0) throw new Error("LRUCache: capacity must be a positive integer");
2512
- this.cache = /* @__PURE__ */ new Map();
2513
- this.onEvict = onEvict;
2514
- }
2515
- get(key) {
2516
- if (!this.cache.has(key)) return void 0;
2517
- const value = this.cache.get(key);
2518
- this.cache.delete(key);
2519
- this.cache.set(key, value);
2520
- return value;
2521
- }
2522
- set(key, value) {
2523
- if (this.cache.has(key)) {
2524
- this.cache.delete(key);
2525
- } else if (this.cache.size >= this.capacity) {
2526
- const oldestKey = this.cache.keys().next().value;
2527
- const oldestValue = this.cache.get(oldestKey);
2528
- this.cache.delete(oldestKey);
2529
- this.onEvict?.(oldestKey, oldestValue);
2530
- }
2531
- this.cache.set(key, value);
2532
- return this;
2533
- }
2534
- has(key) {
2535
- return this.cache.has(key);
2536
- }
2537
- delete(key) {
2538
- return this.cache.delete(key);
2539
- }
2540
- clear() {
2541
- this.cache.clear();
2542
- }
2543
- get size() {
2544
- return this.cache.size;
2545
- }
2546
- };
2547
-
2548
- // src/core/registry.ts
2549
- var BUILTIN_MODIFIERS = {
2550
- // ── Mode ─────────────────────────────────────────────────────────────────
2551
- dark: { order: 60, darkScheme: "dark", jsBehavior: "mode", jsMatch: (d) => d },
2552
- "not-light": { order: 60, darkScheme: "dark", jsBehavior: "mode", jsMatch: (d) => d },
2553
- light: { order: 60, darkScheme: "light", jsBehavior: "mode", jsMatch: (d) => !d },
2554
- "not-dark": { order: 60, darkScheme: "light", jsBehavior: "mode", jsMatch: (d) => !d },
2555
- // ── Interactive — JS state + CSS pseudo ───────────────────────────────────
2556
- hover: { order: 10, pseudo: ":hover", jsBehavior: "interactive", jsMatch: (_, s) => !!s.hover },
2557
- "not-hover": { order: 10, pseudo: ":not(:hover)", jsBehavior: "interactive", jsMatch: (_, s) => !s.hover },
2558
- focus: { order: 20, pseudo: ":focus", jsBehavior: "interactive", jsMatch: (_, s) => !!s.focus },
2559
- "not-focus": { order: 20, pseudo: ":not(:focus)", jsBehavior: "interactive", jsMatch: (_, s) => !s.focus },
2560
- active: { order: 30, pseudo: ":active", jsBehavior: "interactive", jsMatch: (_, s) => !!s.active || !!s.pressed },
2561
- "not-active": { order: 30, pseudo: ":not(:active)", jsBehavior: "interactive", jsMatch: (_, s) => !s.active && !s.pressed },
2562
- pressed: { order: 30, pseudo: ":active", jsBehavior: "interactive", jsMatch: (_, s) => !!s.pressed || !!s.active },
2563
- "not-pressed": { order: 30, pseudo: ":not(:active)", jsBehavior: "interactive", jsMatch: (_, s) => !s.pressed && !s.active },
2564
- disabled: { order: 40, pseudo: ":disabled", jsBehavior: "interactive", jsMatch: (_, s) => !!s.disabled },
2565
- "not-disabled": { order: 40, pseudo: ":not(:disabled)", jsBehavior: "interactive", jsMatch: (_, s) => !s.disabled },
2566
- checked: { order: 35, pseudo: ":checked", jsBehavior: "interactive", jsMatch: (_, s) => !!s.checked },
2567
- "not-checked": { order: 35, pseudo: ":not(:checked)", jsBehavior: "interactive", jsMatch: (_, s) => !s.checked },
2568
- visited: { order: 5, pseudo: ":visited", jsBehavior: "interactive", jsMatch: (_, s) => !!s.visited },
2569
- "not-visited": { order: 5, pseudo: ":not(:visited)", jsBehavior: "interactive", jsMatch: (_, s) => !s.visited },
2570
- placeholder: { order: 0, pseudo: "::placeholder", jsBehavior: "interactive", jsMatch: (_, s) => !!s.placeholder },
2571
- // ── CSS-only pseudo-classes (structural) ──────────────────────────────────
2572
- first: { order: 0, pseudo: ":first-child", jsBehavior: "css-only", forcesImportant: true },
2573
- last: { order: 0, pseudo: ":last-child", jsBehavior: "css-only", forcesImportant: true },
2574
- odd: { order: 0, pseudo: ":nth-child(odd)", jsBehavior: "css-only", forcesImportant: true },
2575
- even: { order: 0, pseudo: ":nth-child(even)", jsBehavior: "css-only", forcesImportant: true },
2576
- only: { order: 0, pseudo: ":only-child", jsBehavior: "css-only", forcesImportant: true },
2577
- "focus-within": { order: 15, pseudo: ":focus-within", jsBehavior: "css-only", forcesImportant: true },
2578
- "focus-visible": { order: 25, pseudo: ":focus-visible", jsBehavior: "css-only", forcesImportant: true },
2579
- // ── CSS-only pseudo-elements ───────────────────────────────────────────────
2580
- before: { order: 0, pseudo: "::before", jsBehavior: "css-only" },
2581
- after: { order: 0, pseudo: "::after", jsBehavior: "css-only" },
2582
- selection: { order: 0, pseudo: "::selection", jsBehavior: "css-only" },
2583
- "first-letter": { order: 0, pseudo: "::first-letter", jsBehavior: "css-only" },
2584
- "first-line": { order: 0, pseudo: "::first-line", jsBehavior: "css-only" },
2585
- marker: { order: 0, pseudo: "::marker", jsBehavior: "css-only" },
2586
- // ── Group / peer ancestor selectors (CSS-only) ─────────────────────────────
2587
- "group-hover": { order: 10, ancestorSelector: ".group:hover ", jsBehavior: "css-only", forcesImportant: true },
2588
- "group-focus": { order: 20, ancestorSelector: ".group:focus ", jsBehavior: "css-only", forcesImportant: true },
2589
- "peer-hover": { order: 10, ancestorSelector: ".peer:hover ~ ", jsBehavior: "css-only", forcesImportant: true },
2590
- "peer-focus": { order: 20, ancestorSelector: ".peer:focus ~ ", jsBehavior: "css-only", forcesImportant: true },
2591
- // ── Responsive — both CSS (@media min-width) and JS (breakpoints set) ──────
2592
- sm: { order: 50, isResponsive: true, jsBehavior: "responsive", jsMatch: (_, __, bp) => bp.has("sm") },
2593
- md: { order: 50, isResponsive: true, jsBehavior: "responsive", jsMatch: (_, __, bp) => bp.has("md") },
2594
- lg: { order: 50, isResponsive: true, jsBehavior: "responsive", jsMatch: (_, __, bp) => bp.has("lg") },
2595
- xl: { order: 50, isResponsive: true, jsBehavior: "responsive", jsMatch: (_, __, bp) => bp.has("xl") },
2596
- "2xl": { order: 50, isResponsive: true, jsBehavior: "responsive", jsMatch: (_, __, bp) => bp.has("2xl") },
2597
- // ── Print media (CSS-only) ─────────────────────────────────────────────────
2598
- print: { order: 70, mediaQuery: "print", jsBehavior: "css-only", forcesImportant: true },
2599
- // ── Orientation / accessibility media (CSS-only) ───────────────────────────
2600
- landscape: { order: 70, mediaQuery: "(orientation: landscape)", jsBehavior: "css-only", forcesImportant: true },
2601
- portrait: { order: 70, mediaQuery: "(orientation: portrait)", jsBehavior: "css-only", forcesImportant: true },
2602
- "motion-reduce": { order: 70, mediaQuery: "(prefers-reduced-motion: reduce)", jsBehavior: "css-only", forcesImportant: true },
2603
- "motion-safe": { order: 70, mediaQuery: "(prefers-reduced-motion: no-preference)", jsBehavior: "css-only", forcesImportant: true },
2604
- "contrast-more": { order: 70, mediaQuery: "(prefers-contrast: more)", jsBehavior: "css-only", forcesImportant: true },
2605
- "contrast-less": { order: 70, mediaQuery: "(prefers-contrast: less)", jsBehavior: "css-only", forcesImportant: true },
2606
- // ── Directionality (CSS-only) ──────────────────────────────────────────────
2607
- rtl: { order: 80, dirSelector: '[dir="rtl"] ', jsBehavior: "css-only", forcesImportant: true },
2608
- ltr: { order: 80, dirSelector: '[dir="ltr"] ', jsBehavior: "css-only", forcesImportant: true }
2609
- };
2610
- var _pluginModifiers = {};
2611
- var _allNames = null;
2612
- var _interactiveNames = null;
2613
- var _modeNames = null;
2614
- var _responsiveNames = null;
2615
- function _invalidate() {
2616
- _allNames = null;
2617
- _interactiveNames = null;
2618
- _modeNames = null;
2619
- _responsiveNames = null;
2620
- }
2621
- function registerModifier(name, def) {
2622
- if (process.env.NODE_ENV !== "production" && name in BUILTIN_MODIFIERS) {
2623
- kbachWarn(`"${name}" is built-in \u2014 pick another modifier name`);
2624
- return;
2625
- }
2626
- _pluginModifiers[name] = def;
2627
- _invalidate();
2628
- }
2629
- function clearPluginModifiers() {
2630
- for (const k of Object.keys(_pluginModifiers)) delete _pluginModifiers[k];
2631
- _invalidate();
2632
- }
2633
- var NAMED_GROUP_PEER_RE = /^(group|peer)-(hover|focus)\/(.+)$/;
2634
- var _namedModifierCache = new LRUCache(1e4);
2635
- function getNamedGroupPeerModifier(name) {
2636
- const cached = _namedModifierCache.get(name);
2637
- if (cached) return cached;
2638
- const m = NAMED_GROUP_PEER_RE.exec(name);
2639
- if (!m) return void 0;
2640
- const [, kind, trigger, groupName] = m;
2641
- const escapedName = escapeCSSSelector(groupName);
2642
- const pseudo = trigger === "hover" ? ":hover" : ":focus";
2643
- const combinator = kind === "group" ? " " : " ~ ";
2644
- const def = {
2645
- // Matches the plain group-hover/group-focus/peer-hover/peer-focus order below.
2646
- order: trigger === "hover" ? 10 : 20,
2647
- ancestorSelector: `.${kind}\\/${escapedName}${pseudo}${combinator}`,
2648
- jsBehavior: "css-only",
2649
- forcesImportant: true
2650
- };
2651
- _namedModifierCache.set(name, def);
2652
- return def;
2653
- }
2654
- function getModifier(name) {
2655
- return BUILTIN_MODIFIERS[name] ?? _pluginModifiers[name] ?? getNamedGroupPeerModifier(name);
2656
- }
2657
- function isKnownModifier(name) {
2658
- return name in BUILTIN_MODIFIERS || name in _pluginModifiers || NAMED_GROUP_PEER_RE.test(name);
2659
- }
2660
- function getModifierOrder(bucketKey) {
2661
- if (bucketKey === "base") return -1;
2662
- let max = 0;
2663
- for (const mod of bucketKey.split(":")) {
2664
- const order = getModifier(mod)?.order ?? 0;
2665
- if (order > max) max = order;
2666
- }
2667
- return max;
2668
- }
2669
-
2670
- // src/core/parser.ts
2671
- var UNSAFE_ARBITRARY_VALUE = /[{};\\]|\/\*|\*\//;
2672
- function isSafeArbitraryValue(value) {
2673
- if (!UNSAFE_ARBITRARY_VALUE.test(value)) return true;
2674
- if (process.env.NODE_ENV !== "production") {
2675
- kbachWarn(`Unsafe arbitrary value rejected: "${value}"`);
2676
- }
2677
- return false;
2678
- }
2679
- function parseClass(className) {
2680
- const trimmed = className.trim();
2681
- if (!trimmed) return null;
2682
- const modifiers = [];
2683
- let remaining = trimmed;
2684
- while (true) {
2685
- const colonIdx = findOuterColon(remaining);
2686
- if (colonIdx === -1) break;
2687
- const candidate = remaining.slice(0, colonIdx);
2688
- if (!isKnownModifier(candidate)) break;
2689
- modifiers.push(candidate);
2690
- remaining = remaining.slice(colonIdx + 1);
2691
- }
2692
- let important = false;
2693
- if (remaining.startsWith("!") && remaining.length > 1) {
2694
- important = true;
2695
- remaining = remaining.slice(1);
2696
- }
2697
- let negative = false;
2698
- if (remaining.startsWith("-") && remaining.length > 1 && remaining[1] !== "-") {
2699
- negative = true;
2700
- remaining = remaining.slice(1);
2701
- }
2702
- let bracketDepth = 0;
2703
- let bracketStart = -1;
2704
- for (let i = remaining.length - 1; i >= 0; i--) {
2705
- if (remaining[i] === "]") bracketDepth++;
2706
- else if (remaining[i] === "[") {
2707
- bracketDepth--;
2708
- if (bracketDepth === 0) {
2709
- bracketStart = i;
2710
- break;
2711
- }
2712
- }
2713
- }
2714
- if (bracketStart > 0 && remaining[bracketStart - 1] === "-" && remaining.endsWith("]")) {
2715
- const utility = remaining.slice(0, bracketStart - 1);
2716
- const value = remaining.slice(bracketStart + 1, -1).replace(/_/g, " ");
2717
- if (!isSafeArbitraryValue(value)) return null;
2718
- return { original: trimmed, modifiers, negative, important, utility, value, isArbitrary: true };
2719
- }
2720
- if (remaining.endsWith("]") && bracketStart === -1) {
2721
- if (process.env.NODE_ENV !== "production") {
2722
- kbachWarn(`Unbalanced brackets: "${trimmed}"`);
2723
- }
2724
- }
2725
- if (remaining.startsWith("[") && remaining.endsWith("]")) {
2726
- const value = remaining.slice(1, -1).replace(/_/g, " ");
2727
- if (!isSafeArbitraryValue(value)) return null;
2728
- return { original: trimmed, modifiers, negative, important, utility: "", value, isArbitrary: true };
2729
- }
2730
- if (getBuiltinStandaloneNames().has(remaining)) {
2731
- return { original: trimmed, modifiers, negative, important, utility: remaining, value: "", isArbitrary: false };
2732
- }
2733
- for (const prefix of getBuiltinUtilityPrefixes()) {
2734
- if (remaining === prefix) {
2735
- return { original: trimmed, modifiers, negative, important, utility: prefix, value: "", isArbitrary: false };
2736
- }
2737
- if (remaining.startsWith(prefix + "-")) {
2738
- const value = remaining.slice(prefix.length + 1);
2739
- return { original: trimmed, modifiers, negative, important, utility: prefix, value, isArbitrary: false };
2740
- }
2741
- }
2742
- const firstDash = remaining.indexOf("-");
2743
- if (firstDash > 0) {
2744
- return {
2745
- original: trimmed,
2746
- modifiers,
2747
- negative,
2748
- important,
2749
- utility: remaining.slice(0, firstDash),
2750
- value: remaining.slice(firstDash + 1),
2751
- isArbitrary: false
2752
- };
2753
- }
2754
- return { original: trimmed, modifiers, negative, important, utility: remaining, value: "", isArbitrary: false };
2755
- }
2756
- function splitClassTokens(classString) {
2757
- const tokens = [];
2758
- let current = "";
2759
- let depth = 0;
2760
- let parenDepth = 0;
2761
- for (let i = 0; i < classString.length; i++) {
2762
- const ch = classString[i];
2763
- if (ch === "[") {
2764
- depth++;
2765
- current += ch;
2766
- continue;
2767
- }
2768
- if (ch === "]") {
2769
- depth--;
2770
- current += ch;
2771
- continue;
2772
- }
2773
- if (ch === "(") {
2774
- parenDepth++;
2775
- current += ch;
2776
- continue;
2777
- }
2778
- if (ch === ")") {
2779
- parenDepth--;
2780
- current += ch;
2781
- continue;
2782
- }
2783
- if (/\s/.test(ch)) {
2784
- if (depth === 0 && parenDepth === 0) {
2785
- if (current) {
2786
- tokens.push(current);
2787
- current = "";
2788
- }
2789
- }
2790
- } else {
2791
- current += ch;
2792
- }
2793
- }
2794
- if (current) tokens.push(current);
2795
- return tokens;
2796
- }
2797
- function parseClasses(classString) {
2798
- const results = [];
2799
- for (const token of splitClassTokens(classString)) {
2800
- const parsed = parseClass(token);
2801
- if (parsed) results.push(parsed);
2802
- }
2803
- return results;
2804
- }
2805
- function findOuterColon(s) {
2806
- let depth = 0;
2807
- for (let i = 0; i < s.length; i++) {
2808
- const ch = s[i];
2809
- if (ch === "[") depth++;
2810
- else if (ch === "]") depth--;
2811
- else if (ch === ":" && depth === 0) return i;
2812
- }
2813
- return -1;
2814
- }
2815
-
2816
- // src/core/globalSingleton.ts
2817
- function getGlobalSingleton(key, create) {
2818
- const symbolKey = /* @__PURE__ */ Symbol.for(`__kbach_${key}__`);
2819
- const g = globalThis;
2820
- let value = g[symbolKey];
2821
- if (value === void 0) {
2822
- value = create();
2823
- g[symbolKey] = value;
2824
- }
2825
- return value;
2826
- }
2827
-
2828
- // src/core/responsiveStore.ts
2829
- var store = getGlobalSingleton("responsiveStore", () => ({
2830
- width: 0,
2831
- notifiedWidth: 0,
2832
- screens: {},
2833
- listeners: /* @__PURE__ */ new Set()
2834
- }));
2835
-
2836
- // src/core/modeAwareColors.ts
2837
- var _modeAwareMapCache = /* @__PURE__ */ new WeakMap();
2838
- function buildModeAwareMap(colors) {
2839
- const map = /* @__PURE__ */ new Map();
2840
- for (const [name, entry] of Object.entries(colors)) {
2841
- if (isModeAwareColor(entry)) {
2842
- map.set(name, entry);
2843
- } else if (entry && typeof entry === "object") {
2844
- for (const [shade, val] of Object.entries(entry)) {
2845
- if (isModeAwareColor(val)) map.set(`${name}-${shade}`, val);
2846
- }
2847
- }
2848
- }
2849
- return map;
2850
- }
2851
- function getModeAwareMap(colors) {
2852
- let map = _modeAwareMapCache.get(colors);
2853
- if (!map) {
2854
- map = buildModeAwareMap(colors);
2855
- _modeAwareMapCache.set(colors, map);
2856
- }
2857
- return map;
2858
- }
2859
- function expandModeAwareColorClasses(classString, colors) {
2860
- const map = getModeAwareMap(colors);
2861
- if (map.size === 0) return classString;
2862
- const tokens = splitClassTokens(classString);
2863
- let changed = false;
2864
- const out = [];
2865
- for (const token of tokens) {
2866
- const parsed = parseClass(token);
2867
- if (!parsed || parsed.isArbitrary) {
2868
- out.push(token);
2869
- continue;
2870
- }
2871
- const slashIdx = parsed.value.indexOf("/");
2872
- const colorPart = slashIdx > 0 ? parsed.value.slice(0, slashIdx) : parsed.value;
2873
- const opacitySuffix = slashIdx > 0 ? parsed.value.slice(slashIdx) : "";
2874
- const pair = map.get(colorPart);
2875
- if (!pair) {
2876
- out.push(token);
2877
- continue;
2878
- }
2879
- changed = true;
2880
- const bang = parsed.important ? "!" : "";
2881
- const modPrefix = parsed.modifiers.map((m) => `${m}:`).join("");
2882
- const explicitScheme = parsed.modifiers.map((m) => getModifier(m)?.darkScheme).find((s) => s);
2883
- if (explicitScheme) {
2884
- const side = explicitScheme === "dark" ? pair.dark : pair.light;
2885
- out.push(`${bang}${modPrefix}${parsed.utility}-[${side}]${opacitySuffix}`);
2886
- continue;
2887
- }
2888
- out.push(`${bang}${modPrefix}${parsed.utility}-[${pair.light}]${opacitySuffix}`);
2889
- out.push(`${bang}dark:${modPrefix}${parsed.utility}-[${pair.dark}]${opacitySuffix}`);
2890
- }
2891
- return changed ? out.join(" ") : classString;
2892
- }
2893
-
2894
- // src/core/resolver.ts
2895
- var _fontFamilyHolder = getGlobalSingleton("defaultFontFamily", () => ({ value: void 0 }));
2896
- function setDefaultFontFamily(font) {
2897
- _fontFamilyHolder.value = font;
2898
- }
2899
- var _styleEl = null;
2900
- var _ruleIndexByKey = /* @__PURE__ */ new Map();
2901
- var _sheetKeys = [];
2902
- var _ruleOrderByKey = /* @__PURE__ */ new Map();
2903
- function evictInjectedRule(rule) {
2904
- const idx = _ruleIndexByKey.get(rule);
2905
- _ruleIndexByKey.delete(rule);
2906
- _ruleOrderByKey.delete(rule);
2907
- if (idx === void 0) return;
2908
- const sheet = _styleEl?.sheet;
2909
- if (!sheet) return;
2910
- try {
2911
- sheet.deleteRule(idx);
2912
- } catch {
2913
- return;
2914
- }
2915
- _sheetKeys.splice(idx, 1);
2916
- for (const [key, i] of _ruleIndexByKey) {
2917
- if (i > idx) _ruleIndexByKey.set(key, i - 1);
2918
- }
2919
- }
2920
- var _injectedRules = new LRUCache(5e4, evictInjectedRule);
2921
- var _runtimeCSSHolder = getGlobalSingleton("runtimeCSSDisabled", () => ({ value: false }));
2922
- function isRuntimeCSSDisabled() {
2923
- return _runtimeCSSHolder.value;
2924
- }
2925
- function getStyleEl() {
2926
- if (_styleEl) return _styleEl;
2927
- _styleEl = document.createElement("style");
2928
- _styleEl.setAttribute("data-kbach", "");
2929
- document.head.appendChild(_styleEl);
2930
- return _styleEl;
2931
- }
2932
- var _globalStyleEl = null;
2933
- function getGlobalStyleEl() {
2934
- if (_globalStyleEl) return _globalStyleEl;
2935
- _globalStyleEl = document.createElement("style");
2936
- _globalStyleEl.setAttribute("data-kbach-global", "");
2937
- document.head.insertBefore(_globalStyleEl, getStyleEl());
2938
- return _globalStyleEl;
2939
- }
2940
- function injectGlobalStyles(theme) {
2941
- if (typeof document === "undefined" || isRuntimeCSSDisabled()) return;
2942
- const rules = document.getElementById(RESET_STYLE_ID) ? [] : [BASE_RESET];
2943
- const ff = theme.fontFamily;
2944
- if (ff?.sans && ff.sans !== "System") {
2945
- const family = Array.isArray(ff.sans) ? ff.sans.join(", ") : ff.sans;
2946
- rules.push(`body { font-family: ${family}; }`);
2947
- }
2948
- getGlobalStyleEl().textContent = rules.join("\n");
2949
- }
2950
- function buildDivideDecls(styles, forceImportant) {
2951
- const imp = forceImportant ? " !important" : "";
2952
- const parts = [];
2953
- if ("__divideX" in styles) {
2954
- const w = Number(styles.__divideX);
2955
- parts.push(`border-left-width: ${w}px${imp}`, `border-right-width: 0px${imp}`);
2956
- }
2957
- if ("__divideY" in styles) {
2958
- const w = Number(styles.__divideY);
2959
- parts.push(`border-top-width: ${w}px${imp}`, `border-bottom-width: 0px${imp}`);
2960
- }
2961
- if ("__divideColor" in styles) parts.push(`border-color: ${String(styles.__divideColor)}${imp}`);
2962
- if ("__divideStyle" in styles) parts.push(`border-style: ${String(styles.__divideStyle)}${imp}`);
2963
- return parts.join("; ");
2964
- }
2965
- function buildSpaceDecls(styles, forceImportant) {
2966
- const imp = forceImportant ? " !important" : "";
2967
- const parts = [];
2968
- if ("__spaceX" in styles) {
2969
- const v = styles.__spaceX;
2970
- const val = typeof v === "number" ? `${v}px` : String(v);
2971
- parts.push(`margin-left: ${val}${imp}`);
2972
- }
2973
- if ("__spaceY" in styles) {
2974
- const v = styles.__spaceY;
2975
- const val = typeof v === "number" ? `${v}px` : String(v);
2976
- parts.push(`margin-top: ${val}${imp}`);
2977
- }
2978
- return parts.join("; ");
2979
- }
2980
- var RN_ONLY_PROPS = /* @__PURE__ */ new Set([
2981
- "shadowColor",
2982
- "shadowOffset",
2983
- "shadowOpacity",
2984
- "shadowRadius",
2985
- "elevation",
2986
- "includeFontPadding",
2987
- "textAlignVertical",
2988
- "writingDirection",
2989
- "textShadowColor",
2990
- "textShadowOffset",
2991
- "textShadowRadius",
2992
- "tintColor",
2993
- "__divideX",
2994
- "__divideY",
2995
- "__divideColor",
2996
- "__divideStyle",
2997
- "__keyframe",
2998
- "__spaceX",
2999
- "__spaceY"
3000
- ]);
3001
- var CSS_UNITLESS = /* @__PURE__ */ new Set([
3002
- "opacity",
3003
- "fontWeight",
3004
- "flex",
3005
- "flexGrow",
3006
- "flexShrink",
3007
- "order",
3008
- "zIndex",
3009
- "aspectRatio",
3010
- "columnCount",
3011
- "lineHeight",
3012
- "gridColumnStart",
3013
- "gridColumnEnd",
3014
- "gridRowStart",
3015
- "gridRowEnd"
3016
- ]);
3017
- var RN_SHORTHAND_EXPAND = {
3018
- marginHorizontal: ["margin-left", "margin-right"],
3019
- marginVertical: ["margin-top", "margin-bottom"],
3020
- paddingHorizontal: ["padding-left", "padding-right"],
3021
- paddingVertical: ["padding-top", "padding-bottom"]
3022
- };
3023
- function styleValueToCSS(styles, forceImportant = false) {
3024
- const parts = [];
3025
- for (const [prop, val] of Object.entries(styles)) {
3026
- if (val === void 0 || val === null || typeof val === "object" || RN_ONLY_PROPS.has(prop)) continue;
3027
- let cssVal;
3028
- if (typeof val === "number") {
3029
- const isCustomProp = prop.startsWith("--");
3030
- cssVal = val === 0 || isCustomProp || CSS_UNITLESS.has(prop) ? String(val) : `${val}px`;
3031
- } else {
3032
- cssVal = String(val);
3033
- }
3034
- const imp = forceImportant || prop === "display" && (cssVal === "grid" || cssVal === "inline-grid") || prop === "position" && (cssVal === "sticky" || cssVal === "fixed" || cssVal === "static") ? " !important" : "";
3035
- if (prop in RN_SHORTHAND_EXPAND) {
3036
- const [p1, p2] = RN_SHORTHAND_EXPAND[prop];
3037
- parts.push(`${p1}: ${cssVal}${imp}`, `${p2}: ${cssVal}${imp}`);
3038
- continue;
3039
- }
3040
- parts.push(`${camelToKebab(prop)}: ${cssVal}${imp}`);
3041
- }
3042
- return parts.join("; ");
3043
- }
3044
- function camelToKebab(str) {
3045
- return str.replace(/([A-Z])/g, "-$1").toLowerCase();
3046
- }
3047
- function buildClassCSSRules(cls, bucketKey, styles, darkMode, important, screens) {
3048
- const rules = [];
3049
- if ("__keyframe" in styles && typeof styles.__keyframe === "string") {
3050
- rules.push(styles.__keyframe);
3051
- }
3052
- const isDivide = "__divideX" in styles || "__divideY" in styles || "__divideColor" in styles || "__divideStyle" in styles;
3053
- const isSpace = "__spaceX" in styles || "__spaceY" in styles;
3054
- const isChildCombinator = isDivide || isSpace;
3055
- const escaped = escapeCSSSelector(cls);
3056
- const childSuffix = isChildCombinator ? " > * + *" : "";
3057
- if (bucketKey === "base") {
3058
- const decls2 = isDivide ? buildDivideDecls(styles, important) : isSpace ? buildSpaceDecls(styles, important) : styleValueToCSS(styles, important);
3059
- if (!decls2) return rules;
3060
- rules.push(`.${escaped}${childSuffix} { ${decls2} }`);
3061
- return rules;
3062
- }
3063
- const mods = bucketKey.split(":");
3064
- let darkScheme;
3065
- let needsImportant = important;
3066
- const pseudoParts = [];
3067
- const ancestorParts = [];
3068
- const dirParts = [];
3069
- const mediaWrappers = [];
3070
- let minWidth = 0;
3071
- for (const mod of mods) {
3072
- const def = getModifier(mod);
3073
- if (!def) continue;
3074
- if (def.darkScheme) darkScheme = def.darkScheme;
3075
- if (def.pseudo) pseudoParts.push(def.pseudo);
3076
- if (def.ancestorSelector) {
3077
- ancestorParts.push(def.ancestorSelector);
3078
- needsImportant = true;
3079
- }
3080
- if (def.dirSelector) {
3081
- dirParts.push(def.dirSelector);
3082
- needsImportant = true;
3083
- }
3084
- if (def.mediaQuery) {
3085
- mediaWrappers.push(`@media ${def.mediaQuery}`);
3086
- needsImportant = true;
3087
- }
3088
- if (def.isResponsive) {
3089
- const w = screens[mod] ?? 0;
3090
- if (w > minWidth) minWidth = w;
3091
- }
3092
- if (def.forcesImportant) needsImportant = true;
3093
- }
3094
- const pseudoSuffix = pseudoParts.join("");
3095
- const elementSelector = `.${escaped}${pseudoSuffix}${childSuffix}`;
3096
- const ancestorPrefix = ancestorParts.join("");
3097
- const dirPrefix = dirParts.join("");
3098
- const selector = `${dirPrefix}${ancestorPrefix}${elementSelector}`;
3099
- const decls = isDivide ? buildDivideDecls(styles, needsImportant) : isSpace ? buildSpaceDecls(styles, needsImportant) : styleValueToCSS(styles, needsImportant);
3100
- if (!decls) return rules;
3101
- let rule;
3102
- if (darkScheme === "dark") {
3103
- if (darkMode === "media") rule = `@media (prefers-color-scheme: dark) { ${selector} { ${decls} } }`;
3104
- else if (darkMode === "class") rule = `.dark ${selector} { ${decls} }`;
3105
- else rule = `[data-theme="dark"] ${selector} { ${decls} }`;
3106
- } else if (darkScheme === "light") {
3107
- if (darkMode === "media") rule = `@media (prefers-color-scheme: light) { ${selector} { ${decls} } }`;
3108
- else if (darkMode === "class") rule = `.light ${selector} { ${decls} }`;
3109
- else rule = `[data-theme="light"] ${selector} { ${decls} }`;
3110
- } else {
3111
- rule = `${selector} { ${decls} }`;
3112
- }
3113
- for (const mw of mediaWrappers) rule = `${mw} { ${rule} }`;
3114
- if (minWidth > 0) rule = `@media (min-width: ${minWidth}px) { ${rule} }`;
3115
- rules.push(rule);
3116
- return rules;
3117
- }
3118
- function generateClassCSS(classString, theme, darkMode = "attribute", screens = {}) {
3119
- const rules = [];
3120
- for (const parsed of parseClasses(expandModeAwareColorClasses(classString, theme.colors))) {
3121
- const styles = resolveUtility(parsed, theme);
3122
- if (!styles) continue;
3123
- const bucketKey = parsed.modifiers.length === 0 ? "base" : parsed.modifiers.join(":");
3124
- rules.push(...buildClassCSSRules(parsed.original, bucketKey, styles, darkMode, parsed.important, screens));
3125
- }
3126
- return rules.join("\n");
3127
- }
3128
-
3129
- // src/core/config.ts
3130
- function deepMerge(base, override) {
3131
- const result = { ...base };
3132
- for (const key of Object.keys(override)) {
3133
- const baseVal = base[key];
3134
- const overVal = override[key];
3135
- if (baseVal !== null && typeof baseVal === "object" && !Array.isArray(baseVal) && overVal !== null && typeof overVal === "object" && !Array.isArray(overVal)) {
3136
- result[key] = deepMerge(
3137
- baseVal,
3138
- overVal
3139
- );
3140
- } else if (overVal !== void 0) {
3141
- result[key] = overVal;
3142
- }
3143
- }
3144
- return result;
3145
- }
3146
- var configStore = getGlobalSingleton("configStore", () => ({
3147
- resolved: null,
3148
- listeners: /* @__PURE__ */ new Set()
3149
- }));
3150
- function resolveColorRefs(colors) {
3151
- const MAX_DEPTH = 5;
3152
- function resolveChain(raw, side) {
3153
- let current = raw;
3154
- for (let i = 0; i < MAX_DEPTH; i++) {
3155
- const next = resolveOneRef(current, side);
3156
- if (!next || next === current) break;
3157
- current = next;
3158
- }
3159
- return current;
3160
- }
3161
- function resolveOneRef(ref, side) {
3162
- const slashIdx = ref.indexOf("/");
3163
- if (slashIdx > 0) {
3164
- const baseName = ref.slice(0, slashIdx);
3165
- const opacity = Number(ref.slice(slashIdx + 1));
3166
- if (!Number.isFinite(opacity)) return null;
3167
- let baseRef;
3168
- const entry2 = colors[baseName];
3169
- if (typeof entry2 === "string") {
3170
- baseRef = entry2;
3171
- } else if (isModeAwareColor(entry2)) {
3172
- if (!side) return null;
3173
- baseRef = entry2[side];
3174
- } else if (entry2 && typeof entry2 === "object" && "6" in entry2) {
3175
- const v = entry2["6"];
3176
- baseRef = typeof v === "string" ? v : void 0;
3177
- }
3178
- if (baseRef === void 0) return null;
3179
- const baseHex = resolveChain(baseRef, side);
3180
- const a = opacity > 1 ? opacity / 100 : opacity;
3181
- return hexToRgba(baseHex, a);
3182
- }
3183
- const split = splitColorShadeRef(ref);
3184
- if (!split) return null;
3185
- const { name, shade } = split;
3186
- if (!/^\d+$/.test(shade)) return null;
3187
- const entry = colors[name];
3188
- if (!entry || typeof entry !== "object" || isModeAwareColor(entry)) return null;
3189
- const target = entry[shade];
3190
- return typeof target === "string" ? target : null;
3191
- }
3192
- function resolveValue(val) {
3193
- return typeof val === "string" ? resolveChain(val, null) : { light: resolveChain(val.light, "light"), dark: resolveChain(val.dark, "dark") };
3194
- }
3195
- const out = {};
3196
- for (const [key, val] of Object.entries(colors)) {
3197
- if (typeof val === "string" || isModeAwareColor(val)) {
3198
- out[key] = resolveValue(val);
3199
- } else {
3200
- const shades = {};
3201
- for (const [shade, v] of Object.entries(val)) {
3202
- shades[shade] = resolveValue(v);
3203
- }
3204
- out[key] = shades;
3205
- }
3206
- }
3207
- return out;
3208
- }
3209
- function buildConfig(userConfig) {
3210
- let theme = { ...defaultTheme };
3211
- if (userConfig.theme) {
3212
- theme = { ...theme, ...userConfig.theme };
3213
- }
3214
- if (userConfig.extend) {
3215
- const extendConfig = userConfig.extend;
3216
- const { theme: nestedTheme, ...directKeys } = extendConfig;
3217
- const extSources = [];
3218
- if (nestedTheme) extSources.push(nestedTheme);
3219
- if (Object.keys(directKeys).length) extSources.push(directKeys);
3220
- for (const ext of extSources) {
3221
- for (const [key, value] of Object.entries(ext)) {
3222
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
3223
- if (process.env.NODE_ENV !== "production") {
3224
- kbachWarn(`extend.${key} should be an object, got ${typeof value} \u2014 skipped`);
3225
- }
3226
- continue;
3227
- }
3228
- if (value !== null && typeof value === "object" && !Array.isArray(value)) {
3229
- theme[key] = deepMerge(
3230
- theme[key] ?? {},
3231
- value
3232
- );
3233
- }
3234
- }
3235
- }
3236
- }
3237
- theme = { ...theme, colors: resolveColorRefs(theme.colors) };
3238
- const resolved = {
3239
- darkMode: userConfig.darkMode ?? "attribute",
3240
- theme,
3241
- plugins: userConfig.plugins ?? []
3242
- };
3243
- if (userConfig.plugins !== void 0) {
3244
- clearPluginUtilities();
3245
- clearPluginModifiers();
3246
- }
3247
- const pluginAPI = makePluginAPI(resolved.theme);
3248
- for (const plugin of resolved.plugins) {
3249
- plugin(pluginAPI);
3250
- }
3251
- const rawSans = theme.fontFamily?.sans;
3252
- const sansFontValue = Array.isArray(rawSans) ? rawSans[0] : rawSans;
3253
- const nativeSansFont = sansFontValue?.split(",")[0]?.trim().replace(/^['"]|['"]$/g, "");
3254
- setDefaultFontFamily(nativeSansFont && nativeSansFont !== "System" ? nativeSansFont : void 0);
3255
- injectGlobalStyles(resolved.theme);
3256
- return resolved;
3257
- }
3258
- function _selectorToModifierDef(selector) {
3259
- const s = selector.trim();
3260
- if (s.startsWith("@media ")) {
3261
- return { mediaQuery: s.slice(7), jsBehavior: "css-only", forcesImportant: true };
3262
- }
3263
- if (s.startsWith("::") || s.startsWith(":") && !s.includes(" ") && !s.includes("&") && !s.includes("(")) {
3264
- return { pseudo: s, jsBehavior: "css-only", forcesImportant: true };
3265
- }
3266
- return { ancestorSelector: s.endsWith(" ") ? s : `${s} `, jsBehavior: "css-only", forcesImportant: true };
3267
- }
3268
- function makePluginAPI(theme) {
3269
- const standalone = getPluginStandaloneMap();
3270
- return {
3271
- addUtility(name, styles) {
3272
- standalone[name] = styles;
3273
- },
3274
- addVariant(name, selectorOrDef) {
3275
- const def = typeof selectorOrDef === "string" ? _selectorToModifierDef(selectorOrDef) : selectorOrDef;
3276
- registerModifier(name, def);
3277
- },
3278
- theme(path, defaultValue) {
3279
- const parts = path.replace(/\[([^\]]+)\]/g, ".$1").split(".");
3280
- let current = theme;
3281
- for (const part of parts) {
3282
- if (current === null || typeof current !== "object") return defaultValue;
3283
- current = current[part];
3284
- }
3285
- return current ?? defaultValue;
3286
- },
3287
- e(className) {
3288
- return className.replace(/[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g, "\\$&");
3289
- }
3290
- };
3291
- }
3292
-
3293
- // src/core/generateTypesDts.ts
3294
- var HEADER = `// AUTO-GENERATED by Kbach from your kbach.config.js \u2014 do not edit by hand.
3295
- // Regenerated automatically every time your dev server / Metro picks up a
3296
- // change to that file. Safe (and recommended) to add to .gitignore.
3297
- //
3298
- // Gives useColors()/useSpacing() full autocomplete and typo-catching for your
3299
- // custom colors/spacing keys with zero manual setup \u2014 see KbachCustomColors'
3300
- // doc comment in @kbach/ui if you'd rather hand-author this instead.
3301
- import '@kbach/ui';
3302
- `;
3303
- var IDENT_RE = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
3304
- function propKey(name) {
3305
- return IDENT_RE.test(name) ? name : JSON.stringify(name);
3306
- }
3307
- function generateKbachTypesDts(theme) {
3308
- const colorLines = [];
3309
- for (const [name, value] of Object.entries(theme.colors)) {
3310
- if (name in defaultColors) continue;
3311
- const isFlat = typeof value === "string" || isModeAwareColor(value);
3312
- colorLines.push(` ${propKey(name)}: ${isFlat ? "string" : "ColorScale"};`);
3313
- }
3314
- const spacingLines = [];
3315
- for (const key of Object.keys(theme.spacing)) {
3316
- if (key in defaultTheme.spacing) continue;
3317
- spacingLines.push(` ${propKey(key)}: true;`);
3318
- }
3319
- if (colorLines.length === 0 && spacingLines.length === 0) return "";
3320
- const body = [
3321
- colorLines.length > 0 ? ` interface KbachCustomColors {
3322
- ${colorLines.join("\n")}
3323
- }` : null,
3324
- spacingLines.length > 0 ? ` interface KbachCustomSpacing {
3325
- ${spacingLines.join("\n")}
3326
- }` : null
3327
- ].filter((s) => s !== null).join("\n\n");
3328
- return `${HEADER}
3329
- declare module '@kbach/ui' {
3330
- ${body}
3331
- }
3332
- `;
3333
- }
3334
-
3335
- // src/vite-plugin.ts
3336
- var process2 = processImport;
3337
- function normPath(p) {
3338
- const fwd = p.replace(/\\/g, "/");
3339
- return process2.platform === "win32" ? fwd.toLowerCase() : fwd;
3340
- }
3341
- setCSSGenMode(true);
3342
- var useColor = !!process2.stdout?.isTTY && !process2.env.NO_COLOR;
3343
- var paint = (code, s) => useColor ? `\x1B[${code}m${s}\x1B[0m` : s;
3344
- var purple = (s) => paint("35", s);
3345
- var yellow = (s) => paint("33", s);
3346
- var dim = (s) => paint("2", s);
3347
- var bold = (s) => paint("1", s);
3348
- var TAG = () => `${bold(purple("[kbach]"))}`;
3349
- function warn(message) {
3350
- console.warn(`${TAG()} ${yellow(message)}`);
3351
- }
3352
- function warnBlock(header, ...lines) {
3353
- console.warn([`${TAG()} ${yellow(header)}`, ...lines].join("\n"));
3354
- }
3355
- function log(message) {
3356
- console.log(`${TAG()} ${message}`);
3357
- }
3358
- function findLineCol(code, needle) {
3359
- const index = code.indexOf(needle);
3360
- if (index === -1) return null;
3361
- let line = 1;
3362
- let lastNewline = -1;
3363
- for (let i = 0; i < index; i++) {
3364
- if (code.charCodeAt(i) === 10) {
3365
- line++;
3366
- lastNewline = i;
3367
- }
3368
- }
3369
- return { line, column: index - lastNewline };
3370
- }
3371
- function warnAt(message, root, filePath, code, needle) {
3372
- const pos = findLineCol(code, needle);
3373
- const relPath = relative(root, filePath).replace(/\\/g, "/");
3374
- const location = pos ? `${relPath}:${pos.line}:${pos.column}` : relPath;
3375
- console.warn(`${TAG()} ${yellow(message)}
3376
- ${dim("at")} ${location}`);
3377
- }
3378
- var KBACH_START = "/* kbach:start */";
3379
- var KBACH_END = "/* kbach:end */";
3380
- var GROUPS = [
3381
- ["Layout", /^(flex(?!-\d|-auto|-none|-initial|-1)|flex-(col|row|wrap|nowrap)|grid|block|inline|hidden|table|contents|overflow|items-|justify-|self-|place-|grow|shrink|float-|clear-|static|fixed|absolute|relative|sticky|z-|top-|right-|bottom-|left-|inset|aspect)/],
3382
- ["Sizing", /^(w-|h-|min-w-|max-w-|min-h-|max-h-|size-|flex-1|flex-auto|flex-none|flex-initial|basis-)/],
3383
- ["Spacing", /^(p-|px-|py-|pt-|pb-|pl-|pr-|m-|mx-|my-|mt-|mb-|ml-|mr-|gap-|space-)/],
3384
- ["Typography", /^(text-(xs|sm|base|lg|\dxl)|font-|leading-|tracking-|uppercase|lowercase|capitalize|normal-case|italic|not-italic|underline|overline|line-through|no-underline|truncate|whitespace-|text-(left|center|right|justify|start|end)|list-|align-|line-clamp)/],
3385
- ["Colors", /^(bg-|text-|color-|fill-|stroke-|caret-|accent-)/],
3386
- ["Borders", /^(border|rounded|ring|outline|divide)/],
3387
- ["Effects", /^(shadow|opacity|blur|brightness|contrast|grayscale|transition|duration|ease|delay|animate|scale|rotate|translate|transform|cursor|pointer|select-)/]
3388
- ];
3389
- var GROUP_ORDER = ["Layout", "Sizing", "Spacing", "Typography", "Colors", "Borders", "Effects", "Utilities", "Dark Mode", "Responsive"];
3390
- function classifyToken(token, responsiveRe) {
3391
- if (/^dark:/.test(token)) return "Dark Mode";
3392
- if (responsiveRe.test(token)) return "Responsive";
3393
- const parsed = parseClass(token);
3394
- const base = parsed ? parsed.value ? `${parsed.utility}-${parsed.value}` : parsed.utility : token;
3395
- for (const [label, re] of GROUPS) {
3396
- if (re.test(base)) return label;
3397
- }
3398
- return "Utilities";
3399
- }
3400
- function buildColorVarMap(theme, usedCSS) {
3401
- const usedHexValues = /* @__PURE__ */ new Set();
3402
- const hexRe = /#[0-9a-fA-F]{3,8}\b/g;
3403
- let hm;
3404
- while ((hm = hexRe.exec(usedCSS)) !== null) usedHexValues.add(hm[0].toLowerCase());
3405
- const replacements = /* @__PURE__ */ new Map();
3406
- const declarations = /* @__PURE__ */ new Map();
3407
- for (const [name, shades] of Object.entries(theme.colors ?? {})) {
3408
- const entries = typeof shades === "string" ? [[name, shades]] : Object.entries(shades).map(([s, v]) => [`${name}-${s}`, v]);
3409
- for (const [fullName, val] of entries) {
3410
- if (typeof val !== "string" || !/^#[0-9a-fA-F]{3,8}$/.test(val)) continue;
3411
- if (usedHexValues.has(val.toLowerCase())) {
3412
- const varName = `--color-${fullName}`;
3413
- replacements.set(val, `var(${varName})`);
3414
- declarations.set(varName, val);
3415
- }
3416
- const rgb = parseHexRgb(val);
3417
- if (!rgb) continue;
3418
- const triplet = `${rgb[0]},${rgb[1]},${rgb[2]}`;
3419
- const rgbaPrefix = `rgba(${triplet},`;
3420
- if (usedCSS.includes(rgbaPrefix)) {
3421
- const rgbVarName = `--color-${fullName}-rgb`;
3422
- replacements.set(rgbaPrefix, `rgba(var(${rgbVarName}),`);
3423
- declarations.set(rgbVarName, triplet);
3424
- }
3425
- }
3426
- }
3427
- return { replacements, declarations };
3428
- }
3429
- var SPACING_PROPS = /* @__PURE__ */ new Set([
3430
- "padding",
3431
- "padding-top",
3432
- "padding-right",
3433
- "padding-bottom",
3434
- "padding-left",
3435
- "margin",
3436
- "margin-top",
3437
- "margin-right",
3438
- "margin-bottom",
3439
- "margin-left",
3440
- "gap",
3441
- "column-gap",
3442
- "row-gap",
3443
- "width",
3444
- "height",
3445
- "min-width",
3446
- "min-height",
3447
- "max-width",
3448
- "max-height",
3449
- "top",
3450
- "right",
3451
- "bottom",
3452
- "left",
3453
- "flex-basis"
3454
- ]);
3455
- function buildSpacingVarMap(theme, usedCSS) {
3456
- const pxToKey = /* @__PURE__ */ new Map();
3457
- for (const [key, val] of Object.entries(theme.spacing ?? {})) {
3458
- if (typeof val === "number" && !pxToKey.has(val)) pxToKey.set(val, key);
3459
- }
3460
- const replacements = /* @__PURE__ */ new Map();
3461
- const declarations = /* @__PURE__ */ new Map();
3462
- const varNameFor = (key) => `--spacing-${key.replace(/\./g, "_")}`;
3463
- const declRe = /([a-z-]+): (\d+(?:\.\d+)?)px/g;
3464
- let m;
3465
- while ((m = declRe.exec(usedCSS)) !== null) {
3466
- const [, prop, numStr] = m;
3467
- if (!SPACING_PROPS.has(prop)) continue;
3468
- const key = pxToKey.get(parseFloat(numStr));
3469
- if (key === void 0) continue;
3470
- const varName = varNameFor(key);
3471
- replacements.set(`${prop}: ${numStr}px`, `${prop}: var(${varName})`);
3472
- declarations.set(varName, `${numStr}px`);
3473
- }
3474
- const transformRe = /(translateX|translateY)\((\d+(?:\.\d+)?)px\)/g;
3475
- while ((m = transformRe.exec(usedCSS)) !== null) {
3476
- const [, fn, numStr] = m;
3477
- const key = pxToKey.get(parseFloat(numStr));
3478
- if (key === void 0) continue;
3479
- const varName = varNameFor(key);
3480
- replacements.set(`${fn}(${numStr}px)`, `${fn}(var(${varName}))`);
3481
- declarations.set(varName, `${numStr}px`);
3482
- }
3483
- return { replacements, declarations };
3484
- }
3485
- function prettifyCSS(css) {
3486
- const out = [];
3487
- let depth = 0;
3488
- let current = "";
3489
- for (const ch of css) {
3490
- if (ch === "{") {
3491
- const selector = current.trim();
3492
- if (selector) out.push(`${" ".repeat(depth)}${selector} {`);
3493
- depth++;
3494
- current = "";
3495
- } else if (ch === "}") {
3496
- const decl = current.trim();
3497
- if (decl) out.push(`${" ".repeat(depth)}${decl};`);
3498
- depth = Math.max(0, depth - 1);
3499
- out.push(`${" ".repeat(depth)}}`);
3500
- current = "";
3501
- } else if (ch === ";") {
3502
- const decl = current.trim();
3503
- if (decl) out.push(`${" ".repeat(depth)}${decl};`);
3504
- current = "";
3505
- } else {
3506
- current += ch;
3507
- }
3508
- }
3509
- const trailing = current.trim();
3510
- if (trailing) out.push(trailing);
3511
- return out.join("\n");
3512
- }
3513
- var RESPONSIVE_MEDIA_RE = /^@media \(min-width: (\d+)px\) \{ (.+) \}$/;
3514
- function mergeResponsiveMediaBlocks(items) {
3515
- const byWidth = /* @__PURE__ */ new Map();
3516
- const widthOrder = [];
3517
- const unwrapped = [];
3518
- for (const { raw } of items) {
3519
- for (const line of raw.split("\n")) {
3520
- if (!line.trim()) continue;
3521
- const m = RESPONSIVE_MEDIA_RE.exec(line);
3522
- if (!m) {
3523
- unwrapped.push(line);
3524
- continue;
3525
- }
3526
- const width = Number(m[1]);
3527
- if (!byWidth.has(width)) {
3528
- byWidth.set(width, []);
3529
- widthOrder.push(width);
3530
- }
3531
- byWidth.get(width).push(m[2]);
3532
- }
3533
- }
3534
- widthOrder.sort((a, b) => a - b);
3535
- const merged = widthOrder.map((w) => `@media (min-width: ${w}px) { ${byWidth.get(w).join(" ")} }`);
3536
- return [...unwrapped, ...merged];
3537
- }
3538
- function formatKbachCSS(tokenCSS, theme, responsiveRe) {
3539
- const allRaw = [...tokenCSS.values()].filter(Boolean).join("\n");
3540
- const colorVars = buildColorVarMap(theme, allRaw);
3541
- const spacingVars = buildSpacingVarMap(theme, allRaw);
3542
- const replacements = new Map([...colorVars.replacements, ...spacingVars.replacements]);
3543
- const declarations = new Map([...colorVars.declarations, ...spacingVars.declarations]);
3544
- const sortedReplacements = [...replacements].sort(([a], [b]) => b.length - a.length);
3545
- const varPatternRes = sortedReplacements.map(
3546
- ([pattern, replacement]) => [new RegExp(`(?<!\\\\)${pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`, "g"), replacement]
3547
- );
3548
- function applyVars(css) {
3549
- for (const [re, replacement] of varPatternRes)
3550
- css = css.replace(re, () => replacement);
3551
- return css;
3552
- }
3553
- const groups = new Map(GROUP_ORDER.map((g) => [g, []]));
3554
- for (const [token, css] of tokenCSS) {
3555
- if (!css) continue;
3556
- const label = classifyToken(token, responsiveRe);
3557
- if (!groups.has(label)) groups.set(label, []);
3558
- const parsedToken = parseClass(token);
3559
- const bucketKey = parsedToken && parsedToken.modifiers.length > 0 ? parsedToken.modifiers.join(":") : "base";
3560
- groups.get(label).push({ order: getModifierOrder(bucketKey), raw: applyVars(css) });
3561
- }
3562
- const out = ["/* Generated by Kbach \u2014 do not edit */"];
3563
- if (declarations.size > 0) {
3564
- out.push("\n:root {");
3565
- for (const [varName, val] of declarations) out.push(` ${varName}: ${val};`);
3566
- out.push("}");
3567
- }
3568
- const globalCSS = buildThemeGlobal(theme);
3569
- if (globalCSS) out.push(`
3570
- /* Global */
3571
- ${prettifyCSS(globalCSS)}`);
3572
- for (const label of GROUP_ORDER) {
3573
- const items = groups.get(label) ?? [];
3574
- if (!items.length) continue;
3575
- const sorted = [...items].sort((a, b) => a.order - b.order);
3576
- out.push(`
3577
- /* ${label} */`);
3578
- const rendered = label === "Responsive" ? mergeResponsiveMediaBlocks(sorted).map(prettifyCSS) : sorted.map((it) => prettifyCSS(it.raw));
3579
- out.push(rendered.join("\n\n"));
3580
- }
3581
- return out.join("\n");
3582
- }
3583
- function buildThemeGlobal(theme) {
3584
- const lines = [BASE_RESET];
3585
- const ff = theme.fontFamily;
3586
- if (ff?.sans && ff.sans !== "System") {
3587
- const family = Array.isArray(ff.sans) ? ff.sans.join(", ") : ff.sans;
3588
- lines.push(`body { font-family: ${family}; }`);
3589
- }
3590
- return lines.join("\n");
3591
- }
3592
- var SKIP_DIRS = /* @__PURE__ */ new Set([
3593
- "node_modules",
3594
- "dist",
3595
- "build",
3596
- "out",
3597
- ".next",
3598
- ".nuxt",
3599
- ".output",
3600
- ".git",
3601
- ".svn",
3602
- ".cache",
3603
- "coverage",
3604
- "__pycache__"
3605
- ]);
3606
- function findKbachCSS(root) {
3607
- const found = [];
3608
- function scan(dir, depth) {
3609
- if (depth > 10) return;
3610
- let entries;
3611
- try {
3612
- entries = readdirSync(dir);
3613
- } catch {
3614
- return;
3615
- }
3616
- for (const entry of entries) {
3617
- if (entry.startsWith(".") || SKIP_DIRS.has(entry)) continue;
3618
- const full = join(dir, entry);
3619
- try {
3620
- const st = statSync(full);
3621
- if (st.isDirectory()) scan(full, depth + 1);
3622
- else if (entry === "kbach.css") found.push(full);
3623
- } catch {
3624
- }
3625
- }
3626
- }
3627
- scan(root, 0);
3628
- if (found.length === 0) return null;
3629
- found.sort((a, b) => a.split(/[\\/]/g).length - b.split(/[\\/]/g).length);
3630
- if (found.length > 1) {
3631
- warnBlock(
3632
- `Multiple kbach.css found, using the shallowest \u2014 remove the rest:`,
3633
- ...found.map((f) => dim(` ${f}`))
3634
- );
3635
- }
3636
- return found[0];
3637
- }
3638
- function writeKbachToFile(filePath, css) {
3639
- let existing = "";
3640
- try {
3641
- existing = readFileSync(filePath, "utf-8");
3642
- } catch {
3643
- }
3644
- const block = `${KBACH_START}
3645
- ${css}
3646
- ${KBACH_END}`;
3647
- const start = existing.indexOf(KBACH_START);
3648
- const end = existing.indexOf(KBACH_END);
3649
- const next = start !== -1 && end !== -1 && end > start ? existing.slice(0, start) + block + existing.slice(end + KBACH_END.length) : existing ? `${existing}
3650
-
3651
- ${block}` : block;
3652
- if (next === existing) return false;
3653
- writeFileSync(filePath, next, "utf-8");
3654
- return true;
3655
- }
3656
- function writeKbachTypesDts(root, theme) {
3657
- const filePath = join(root, "kbach-types.d.ts");
3658
- const content = generateKbachTypesDts(theme);
3659
- let existing = null;
3660
- try {
3661
- existing = readFileSync(filePath, "utf-8");
3662
- } catch {
3663
- }
3664
- if (content === (existing ?? "")) return;
3665
- try {
3666
- if (content === "") {
3667
- unlinkSync(filePath);
3668
- } else {
3669
- const isNew = existing === null;
3670
- writeFileSync(filePath, content, "utf-8");
3671
- if (isNew) {
3672
- log(`Generated kbach-types.d.ts \u2014 gives useColors()/useSpacing() autocomplete for your custom colors/spacing keys. Safe to add to .gitignore.`);
3673
- }
3674
- }
3675
- } catch {
3676
- }
3677
- }
3678
- function toNumericScreens(screens) {
3679
- const out = {};
3680
- for (const [k, v] of Object.entries(screens)) {
3681
- out[k] = typeof v === "number" ? v : parseInt(String(v), 10);
3682
- }
3683
- return out;
3684
- }
3685
- function pushTemplateLiteralBody(body, into) {
3686
- const interpolationRe = /\$\{(?:[^{}]|\{[^{}]*\})*\}/g;
3687
- let im;
3688
- while ((im = interpolationRe.exec(body)) !== null) {
3689
- pushClassLikeStrings(im[0], into);
3690
- }
3691
- pushTokens(body.replace(/\$\{(?:[^{}]|\{[^{}]*\})*\}/g, () => "$"), into);
3692
- }
3693
- function pushClassLikeStrings(text, into) {
3694
- const quotedStringRe = /(["'`])((?:(?!\1).)*)\1/g;
3695
- let qm;
3696
- while ((qm = quotedStringRe.exec(text)) !== null) {
3697
- const [, quote, content] = qm;
3698
- if (quote === "`") pushTemplateLiteralBody(content, into);
3699
- else pushTokens(content, into);
3700
- }
3701
- }
3702
- function extractClassStrings(code) {
3703
- const found = /* @__PURE__ */ new Set();
3704
- const simpleRe = /(?:className|kb)=(["'])((?:(?!\1).)*)\1/g;
3705
- let m;
3706
- while ((m = simpleRe.exec(code)) !== null) pushTokens(m[2], found);
3707
- const jsxExprRe = /(?:className|kb)=\{/g;
3708
- while ((m = jsxExprRe.exec(code)) !== null) {
3709
- let depth = 1;
3710
- let i = m.index + m[0].length;
3711
- let block = "";
3712
- while (i < code.length && depth > 0) {
3713
- const ch = code[i];
3714
- if (ch === "{") depth++;
3715
- else if (ch === "}") {
3716
- if (--depth === 0) break;
3717
- }
3718
- block += ch;
3719
- i++;
3720
- }
3721
- jsxExprRe.lastIndex = i + 1;
3722
- pushClassLikeStrings(block, found);
3723
- }
3724
- const classComposerCallRe = /(?:clsx|cn|classnames|cx|kb)\(/g;
3725
- while ((m = classComposerCallRe.exec(code)) !== null) {
3726
- let depth = 1;
3727
- let i = m.index + m[0].length;
3728
- let block = "";
3729
- while (i < code.length && depth > 0) {
3730
- const ch = code[i];
3731
- if (ch === "(") depth++;
3732
- else if (ch === ")") {
3733
- if (--depth === 0) break;
3734
- }
3735
- block += ch;
3736
- i++;
3737
- }
3738
- classComposerCallRe.lastIndex = i + 1;
3739
- pushClassLikeStrings(block, found);
3740
- }
3741
- const styledCallRe = /\bstyled\(/g;
3742
- while ((m = styledCallRe.exec(code)) !== null) {
3743
- let depth = 1;
3744
- let i = m.index + m[0].length;
3745
- let block = "";
3746
- while (i < code.length && depth > 0) {
3747
- const ch = code[i];
3748
- if (ch === "(") depth++;
3749
- else if (ch === ")") {
3750
- if (--depth === 0) break;
3751
- }
3752
- block += ch;
3753
- i++;
3754
- }
3755
- styledCallRe.lastIndex = i + 1;
3756
- pushClassLikeStrings(block, found);
3757
- }
3758
- const templateRe = /`([^`]{1,2000})`/g;
3759
- while ((m = templateRe.exec(code)) !== null) pushTemplateLiteralBody(m[1], found);
3760
- return [...found];
3761
- }
3762
- var NOT_A_CLASS_NAME_RE = /[${}]|-$|^[?:&|!"'=<>]+$/;
3763
- function pushTokens(str, into) {
3764
- for (const tok of splitClassTokens(str)) {
3765
- if (tok && !NOT_A_CLASS_NAME_RE.test(tok)) into.add(tok);
3766
- }
3767
- }
3768
- var MAX_SCAN_DEPTH = 10;
3769
- function scanDir(dir, onFile, depth = 0) {
3770
- if (depth > MAX_SCAN_DEPTH) return;
3771
- let entries;
3772
- try {
3773
- entries = readdirSync(dir);
3774
- } catch (err) {
3775
- if (err.code !== "ENOENT") {
3776
- warn(`Can't read ${dir}: ${err.message}`);
3777
- }
3778
- return;
3779
- }
3780
- for (const entry of entries) {
3781
- if (entry.startsWith(".") || entry === "node_modules") continue;
3782
- const full = join(dir, entry);
3783
- try {
3784
- const st = statSync(full);
3785
- if (st.isDirectory()) scanDir(full, onFile, depth + 1);
3786
- else if (/\.(tsx?|jsx?)$/.test(entry)) onFile(full, readFileSync(full, "utf-8"));
3787
- } catch (err) {
3788
- warn(`Can't process ${full}: ${err.message}`);
3789
- }
3790
- }
3791
- }
3792
- var CSS_CLASS_SELECTOR_RE = /\.(-?[a-zA-Z_][a-zA-Z0-9_-]*)/g;
3793
- var CSS_FILE_RE = /\.(css|scss|sass|less)$/;
3794
- function scanCssFileInto(filePath, into) {
3795
- try {
3796
- const text = readFileSync(filePath, "utf-8");
3797
- let m;
3798
- CSS_CLASS_SELECTOR_RE.lastIndex = 0;
3799
- while ((m = CSS_CLASS_SELECTOR_RE.exec(text)) !== null) into.add(m[1]);
3800
- } catch {
3801
- }
3802
- }
3803
- function scanCssSelectorsInto(dir, into, depth = 0) {
3804
- if (depth > MAX_SCAN_DEPTH) return;
3805
- let entries;
3806
- try {
3807
- entries = readdirSync(dir);
3808
- } catch {
3809
- return;
3810
- }
3811
- for (const entry of entries) {
3812
- if (entry.startsWith(".") || entry === "node_modules") continue;
3813
- const full = join(dir, entry);
3814
- try {
3815
- const st = statSync(full);
3816
- if (st.isDirectory()) scanCssSelectorsInto(full, into, depth + 1);
3817
- else if (CSS_FILE_RE.test(entry)) scanCssFileInto(full, into);
3818
- } catch {
3819
- }
3820
- }
3821
- }
3822
- function stripModifierPrefix(token) {
3823
- return token.replace(/^(?:[a-zA-Z0-9_/-]+:)+/, "");
3824
- }
3825
- var DEFAULT_SCAN_DIRS = ["src", "app", "pages", "components", "views", "layouts"];
3826
- function kbach(userConfigOrOptions) {
3827
- const isOptions = userConfigOrOptions != null && ("framework" in userConfigOrOptions || "include" in userConfigOrOptions || "safelist" in userConfigOrOptions);
3828
- const userConfig = isOptions ? userConfigOrOptions.framework : userConfigOrOptions;
3829
- const includeDirs = (isOptions ? userConfigOrOptions.include : void 0) ?? DEFAULT_SCAN_DIRS;
3830
- const safelist = (isOptions ? userConfigOrOptions.safelist : void 0) ?? [];
3831
- const cfg = buildConfig(userConfig ?? {});
3832
- const screens = toNumericScreens(cfg.theme.screens ?? {});
3833
- const screenKeys = Object.keys(cfg.theme.screens ?? {});
3834
- const responsivePattern = screenKeys.length ? screenKeys.map((k) => k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|") : "sm|md|lg|xl|2xl";
3835
- const responsiveRe = new RegExp(`^(${responsivePattern}):`);
3836
- let root = process2.cwd();
3837
- let mainCSSFile = null;
3838
- const fileTokens = /* @__PURE__ */ new Map();
3839
- const tokenCSS = /* @__PURE__ */ new Map();
3840
- const projectCssClasses = /* @__PURE__ */ new Set();
3841
- const warnedTokens = /* @__PURE__ */ new Set();
3842
- function checkUnknownToken(tok, filePath, code) {
3843
- if (process2.env.NODE_ENV === "production" || warnedTokens.has(tok) || tok.startsWith("__")) return;
3844
- const parsed = parseClass(tok);
3845
- if (parsed && resolveUtility(parsed, cfg.theme) !== null) return;
3846
- const base = stripModifierPrefix(tok);
3847
- if (!base || projectCssClasses.has(base)) return;
3848
- warnedTokens.add(tok);
3849
- warnAt(`Unknown class "${tok}" \u2014 no Kbach utility or project CSS rule matches it. Typo?`, root, filePath, code, tok);
3850
- }
3851
- function processFile(filePath, code) {
3852
- const key = normPath(filePath);
3853
- const tokens = /* @__PURE__ */ new Set();
3854
- for (const tok of extractClassStrings(code)) {
3855
- tokens.add(tok);
3856
- if (!tokenCSS.has(tok)) {
3857
- tokenCSS.set(tok, generateClassCSS(tok, cfg.theme, cfg.darkMode, screens));
3858
- }
3859
- checkUnknownToken(tok, filePath, code);
3860
- }
3861
- fileTokens.set(key, tokens);
3862
- }
3863
- const SAFELIST_KEY = "\0kbach-safelist";
3864
- function processSafelist() {
3865
- if (safelist.length === 0) return;
3866
- const tokens = new Set(safelist);
3867
- for (const tok of tokens) {
3868
- if (!tokenCSS.has(tok)) {
3869
- tokenCSS.set(tok, generateClassCSS(tok, cfg.theme, cfg.darkMode, screens));
3870
- }
3871
- }
3872
- fileTokens.set(SAFELIST_KEY, tokens);
3873
- }
3874
- function scanProjectCssSelectors() {
3875
- for (const dir of includeDirs) scanCssSelectorsInto(join(root, dir), projectCssClasses);
3876
- }
3877
- function isWithinIncludeDirs(file) {
3878
- const nf = normPath(file);
3879
- return includeDirs.some((dir) => {
3880
- const base = normPath(join(root, dir));
3881
- return nf === base || nf.startsWith(base.endsWith("/") ? base : `${base}/`);
3882
- });
3883
- }
3884
- function buildTokenCSSView() {
3885
- const active = /* @__PURE__ */ new Set();
3886
- for (const tokens of fileTokens.values()) for (const t of tokens) active.add(t);
3887
- const view = /* @__PURE__ */ new Map();
3888
- for (const tok of active) {
3889
- const css = tokenCSS.get(tok);
3890
- if (css !== void 0) view.set(tok, css);
3891
- }
3892
- return view;
3893
- }
3894
- function initialScan() {
3895
- for (const dir of includeDirs) {
3896
- scanDir(join(root, dir), processFile);
3897
- }
3898
- }
3899
- function generateCSS() {
3900
- return formatKbachCSS(buildTokenCSSView(), cfg.theme, responsiveRe);
3901
- }
3902
- function syncMainCSSFile(server) {
3903
- const active = /* @__PURE__ */ new Set();
3904
- for (const tokens of fileTokens.values()) for (const t of tokens) active.add(t);
3905
- for (const tok of tokenCSS.keys()) {
3906
- if (!active.has(tok)) tokenCSS.delete(tok);
3907
- }
3908
- if (mainCSSFile) {
3909
- const changed = writeKbachToFile(mainCSSFile, generateCSS());
3910
- if (changed) server.watcher.emit("change", mainCSSFile);
3911
- }
3912
- }
3913
- return {
3914
- name: "kbach",
3915
- enforce: "pre",
3916
- // Without this, Vite only discovers @kbach/ui needs pre-bundling once it
3917
- // actually crawls into an import of it — typically the FIRST page load — and
3918
- // has to stop, optimize it, and force a full reload mid-render. That reload
3919
- // can land in the middle of a render pass (React hooks resolving against a
3920
- // module graph that's being swapped out from under it), which is what an
3921
- // "Invalid hook call" / hook-related crash on first load only usually is.
3922
- // Declaring it here upfront means Vite pre-bundles it during its initial
3923
- // dependency scan, before any page ever requests it — no mid-render reload.
3924
- config() {
3925
- return {
3926
- optimizeDeps: {
3927
- include: ["@kbach/ui", "@kbach/ui/jsx-runtime", "@kbach/ui/jsx-dev-runtime"]
3928
- }
3929
- };
3930
- },
3931
- configResolved(resolved) {
3932
- root = resolved.root;
3933
- writeKbachTypesDts(root, cfg.theme);
3934
- const names = new Set(resolved.plugins.map((p) => p.name));
3935
- if (names.has("react-router") && names.has("vite:react-refresh")) {
3936
- warnBlock(
3937
- "@vitejs/plugin-react + reactRouter() conflict \u2014 page will crash before styles apply.",
3938
- dim(' Both inject Fast Refresh ("RefreshRuntime already declared").'),
3939
- dim(" Fix: remove react() from vite.config.ts \u2014 tsconfig jsxImportSource is enough.")
3940
- );
3941
- }
3942
- },
3943
- // When any JS/TS file imports kbach.css, prepend a disableRuntimeCSS() call
3944
- // so styles come solely from the static stylesheet — no duplicate injection.
3945
- //
3946
- // Anchored to the START of a source line (^\s*, with the m flag) rather than a
3947
- // bare \bimport\b anywhere in the file — disableRuntimeCSS() sets a globalThis
3948
- // flag with no way to re-enable it, so a false match here doesn't just misfire
3949
- // once, it silently kills ALL runtime CSS injection for the rest of that page's
3950
- // JS lifetime, including on completely unrelated components. A real import
3951
- // statement is always the first token on its line (give or take whitespace);
3952
- // this same text appearing as part of a STRING — e.g. a docs site's own code
3953
- // sample literally showing `import "./kbach.css";` as example text, which is
3954
- // exactly what happened here — is never positioned that way, since something
3955
- // always precedes it syntactically (a quote, JSX braces, an array bracket, …).
3956
- transform(code, id) {
3957
- if (!/\.(tsx?|jsx?|mjs?)$/.test(id)) return;
3958
- if (!/^\s*import\b[^;]*['"][^'"]*kbach\.css['"]/im.test(code)) return;
3959
- warn(`disableRuntimeCSS() auto-triggered by an import in ${id.replace(/\\/g, "/")}`);
3960
- return {
3961
- code: `import { disableRuntimeCSS } from '@kbach/ui';
3962
- disableRuntimeCSS();
3963
- ${code}`,
3964
- map: null
3965
- };
3966
- },
3967
- buildStart() {
3968
- mainCSSFile = findKbachCSS(root);
3969
- scanProjectCssSelectors();
3970
- initialScan();
3971
- processSafelist();
3972
- if (mainCSSFile) writeKbachToFile(mainCSSFile, generateCSS());
3973
- },
3974
- // Vite's `handleHotUpdate` hook only fires for `type === "update"` (plain
3975
- // file edits) — it's never called for file create/delete, which land on
3976
- // the watcher's own 'add'/'unlink' events instead (confirmed against
3977
- // vite's own onHMRUpdate/handleHMRUpdate: the hook loop is gated on
3978
- // `type === "update"`). Without also listening on those two events here,
3979
- // creating a new file with new Kbach classes never adds them to
3980
- // kbach.css, and deleting a file never removes its classes, until a full
3981
- // dev-server restart. configureServer gives access to the raw watcher so
3982
- // both cases can share the same sync logic as a plain edit.
3983
- configureServer(server) {
3984
- const onAddOrUnlink = (file, isUnlink) => {
3985
- if (file.includes("node_modules")) return;
3986
- if (!isWithinIncludeDirs(file)) return;
3987
- if (CSS_FILE_RE.test(file)) {
3988
- if (!isUnlink) scanCssFileInto(file, projectCssClasses);
3989
- return;
3990
- }
3991
- if (!/\.(tsx?|jsx?)$/.test(file)) return;
3992
- if (isUnlink) {
3993
- fileTokens.delete(normPath(file));
3994
- } else {
3995
- try {
3996
- processFile(file, readFileSync(file, "utf-8"));
3997
- } catch {
3998
- fileTokens.delete(normPath(file));
3999
- }
4000
- }
4001
- syncMainCSSFile(server);
4002
- };
4003
- server.watcher.on("add", (file) => onAddOrUnlink(file, false));
4004
- server.watcher.on("unlink", (file) => onAddOrUnlink(file, true));
4005
- },
4006
- handleHotUpdate({ file, server }) {
4007
- if (file.includes("node_modules")) return;
4008
- if (!isWithinIncludeDirs(file)) return;
4009
- if (CSS_FILE_RE.test(file)) {
4010
- scanCssFileInto(file, projectCssClasses);
4011
- return;
4012
- }
4013
- if (!/\.(tsx?|jsx?)$/.test(file)) return;
4014
- try {
4015
- processFile(file, readFileSync(file, "utf-8"));
4016
- } catch {
4017
- fileTokens.delete(normPath(file));
4018
- }
4019
- syncMainCSSFile(server);
4020
- }
4021
- };
4022
- }
4023
- export {
4024
- extractClassStrings,
4025
- formatKbachCSS,
4026
- kbach
4027
- };