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