@kbach/react-native 1.0.0-beta.2 → 1.0.0-beta.20
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/README.md +220 -87
- package/android/build.gradle +36 -0
- package/android/src/main/AndroidManifest.xml +14 -0
- package/android/src/main/java/com/kbachnative/KbachModule.kt +83 -0
- package/android/src/main/java/com/kbachnative/KbachPackage.kt +54 -0
- package/android/src/main/jniLibs/arm64-v8a/libkbach_core_engine.so +0 -0
- package/android/src/main/jniLibs/x86_64/libkbach_core_engine.so +0 -0
- package/dist/chunk-45GOGUHJ.mjs +107 -0
- package/dist/chunk-MJWWZJMH.mjs +40 -0
- package/dist/chunk-OGFB3OXS.mjs +552 -0
- package/dist/darkModeStore.d.ts +58 -0
- package/dist/darkModeStore.js +112 -0
- package/dist/dynamicTokens.d.ts +35 -0
- package/dist/dynamicTokens.js +75 -0
- package/dist/index.d.ts +53 -102
- package/dist/index.js +1578 -385
- package/dist/index.web.d.ts +18 -0
- package/dist/index.web.js +436 -0
- package/dist/index.web.mjs +210 -0
- package/dist/jsx-dev-runtime.d.ts +3 -12
- package/dist/jsx-dev-runtime.js +1565 -344
- package/dist/jsx-dev-runtime.web.d.ts +10 -0
- package/dist/jsx-dev-runtime.web.js +271 -0
- package/dist/jsx-dev-runtime.web.mjs +29 -0
- package/dist/jsx-runtime.d.ts +3 -23
- package/dist/jsx-runtime.js +1556 -336
- package/dist/jsx-runtime.web.d.ts +7 -0
- package/dist/jsx-runtime.web.js +252 -0
- package/dist/{jsx-runtime.mjs → jsx-runtime.web.mjs} +2 -2
- package/dist/theme.d.ts +54 -0
- package/dist/{chunk-YHF3QLRL.mjs → theme.js} +94 -72
- package/dist/useDynamicToken-Dr15c88t.d.ts +160 -0
- package/package.json +62 -14
- package/react-native.config.js +29 -0
- package/specs/NativeKbachModule.ts +31 -0
- package/src/babel-plugin.js +74 -2
- package/dist/chunk-SVMYVXY6.mjs +0 -44
- package/dist/index.d.mts +0 -148
- package/dist/index.mjs +0 -80
- package/dist/jsx-dev-runtime.d.mts +0 -19
- package/dist/jsx-dev-runtime.mjs +0 -20
- package/dist/jsx-runtime.d.mts +0 -27
package/dist/jsx-runtime.js
CHANGED
|
@@ -25,349 +25,219 @@ __export(jsx_runtime_exports, {
|
|
|
25
25
|
jsxs: () => jsxs
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(jsx_runtime_exports);
|
|
28
|
+
|
|
29
|
+
// src/jsxRuntimeCore.ts
|
|
28
30
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
29
31
|
var import_react = require("react");
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var
|
|
32
|
+
var import_react_native = require("react-native");
|
|
33
|
+
var import_darkModeStore = require("./darkModeStore");
|
|
34
|
+
var import_dynamicTokens = require("./dynamicTokens");
|
|
35
|
+
var import_theme = require("./theme");
|
|
34
36
|
|
|
35
|
-
// src/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
"pink-3": "#fbcfe8",
|
|
181
|
-
"pink-4": "#f9a8d4",
|
|
182
|
-
"pink-5": "#f472b6",
|
|
183
|
-
"pink-6": "#ec4899",
|
|
184
|
-
"pink-7": "#db2777",
|
|
185
|
-
"pink-8": "#be185d",
|
|
186
|
-
"pink-9": "#9d174d",
|
|
187
|
-
"purple-1": "#faf5ff",
|
|
188
|
-
"purple-10": "#581c87",
|
|
189
|
-
"purple-11": "#3b0764",
|
|
190
|
-
"purple-12": "#23043c",
|
|
191
|
-
"purple-2": "#f3e8ff",
|
|
192
|
-
"purple-3": "#e9d5ff",
|
|
193
|
-
"purple-4": "#d8b4fe",
|
|
194
|
-
"purple-5": "#c084fc",
|
|
195
|
-
"purple-6": "#a855f7",
|
|
196
|
-
"purple-7": "#9333ea",
|
|
197
|
-
"purple-8": "#7e22ce",
|
|
198
|
-
"purple-9": "#6b21a8",
|
|
199
|
-
"red-1": "#fef2f2",
|
|
200
|
-
"red-10": "#7f1d1d",
|
|
201
|
-
"red-11": "#450a0a",
|
|
202
|
-
"red-12": "#280606",
|
|
203
|
-
"red-2": "#fee2e2",
|
|
204
|
-
"red-3": "#fecaca",
|
|
205
|
-
"red-4": "#fca5a5",
|
|
206
|
-
"red-5": "#f87171",
|
|
207
|
-
"red-6": "#ef4444",
|
|
208
|
-
"red-7": "#dc2626",
|
|
209
|
-
"red-8": "#b91c1c",
|
|
210
|
-
"red-9": "#991b1b",
|
|
211
|
-
"rose-1": "#fff1f2",
|
|
212
|
-
"rose-10": "#881337",
|
|
213
|
-
"rose-11": "#4c0519",
|
|
214
|
-
"rose-12": "#2d030e",
|
|
215
|
-
"rose-2": "#ffe4e6",
|
|
216
|
-
"rose-3": "#fecdd3",
|
|
217
|
-
"rose-4": "#fda4af",
|
|
218
|
-
"rose-5": "#fb7185",
|
|
219
|
-
"rose-6": "#f43f5e",
|
|
220
|
-
"rose-7": "#e11d48",
|
|
221
|
-
"rose-8": "#be123c",
|
|
222
|
-
"rose-9": "#9f1239",
|
|
223
|
-
"silver": "#c0c0c0",
|
|
224
|
-
"sky-1": "#f0f9ff",
|
|
225
|
-
"sky-10": "#0c4a6e",
|
|
226
|
-
"sky-11": "#082f49",
|
|
227
|
-
"sky-12": "#041b2b",
|
|
228
|
-
"sky-2": "#e0f2fe",
|
|
229
|
-
"sky-3": "#bae6fd",
|
|
230
|
-
"sky-4": "#7dd3fc",
|
|
231
|
-
"sky-5": "#38bdf8",
|
|
232
|
-
"sky-6": "#0ea5e9",
|
|
233
|
-
"sky-7": "#0284c7",
|
|
234
|
-
"sky-8": "#0369a1",
|
|
235
|
-
"sky-9": "#075985",
|
|
236
|
-
"slate-1": "#f8fafc",
|
|
237
|
-
"slate-10": "#0f172a",
|
|
238
|
-
"slate-11": "#020617",
|
|
239
|
-
"slate-12": "#01020a",
|
|
240
|
-
"slate-2": "#f1f5f9",
|
|
241
|
-
"slate-3": "#e2e8f0",
|
|
242
|
-
"slate-4": "#cbd5e1",
|
|
243
|
-
"slate-5": "#94a3b8",
|
|
244
|
-
"slate-6": "#64748b",
|
|
245
|
-
"slate-7": "#475569",
|
|
246
|
-
"slate-8": "#334155",
|
|
247
|
-
"slate-9": "#1e293b",
|
|
248
|
-
"stone-1": "#fafaf9",
|
|
249
|
-
"stone-10": "#1c1917",
|
|
250
|
-
"stone-11": "#0c0a09",
|
|
251
|
-
"stone-12": "#070605",
|
|
252
|
-
"stone-2": "#f5f5f4",
|
|
253
|
-
"stone-3": "#e7e5e4",
|
|
254
|
-
"stone-4": "#d6d3d1",
|
|
255
|
-
"stone-5": "#a8a29e",
|
|
256
|
-
"stone-6": "#78716c",
|
|
257
|
-
"stone-7": "#57534e",
|
|
258
|
-
"stone-8": "#44403c",
|
|
259
|
-
"stone-9": "#292524",
|
|
260
|
-
"teal-1": "#f0fdfa",
|
|
261
|
-
"teal-10": "#134e4a",
|
|
262
|
-
"teal-11": "#042f2e",
|
|
263
|
-
"teal-12": "#021c1b",
|
|
264
|
-
"teal-2": "#ccfbf1",
|
|
265
|
-
"teal-3": "#99f6e4",
|
|
266
|
-
"teal-4": "#5eead4",
|
|
267
|
-
"teal-5": "#2dd4bf",
|
|
268
|
-
"teal-6": "#14b8a6",
|
|
269
|
-
"teal-7": "#0d9488",
|
|
270
|
-
"teal-8": "#0f766e",
|
|
271
|
-
"teal-9": "#115e59",
|
|
272
|
-
"transparent": "transparent",
|
|
273
|
-
"violet-1": "#f5f3ff",
|
|
274
|
-
"violet-10": "#4c1d95",
|
|
275
|
-
"violet-11": "#2e1065",
|
|
276
|
-
"violet-12": "#1c0a3d",
|
|
277
|
-
"violet-2": "#ede9fe",
|
|
278
|
-
"violet-3": "#ddd6fe",
|
|
279
|
-
"violet-4": "#c4b5fd",
|
|
280
|
-
"violet-5": "#a78bfa",
|
|
281
|
-
"violet-6": "#8b5cf6",
|
|
282
|
-
"violet-7": "#7c3aed",
|
|
283
|
-
"violet-8": "#6d28d9",
|
|
284
|
-
"violet-9": "#5b21b6",
|
|
285
|
-
"white": "#ffffff",
|
|
286
|
-
"yellow-1": "#fefce8",
|
|
287
|
-
"yellow-10": "#713f12",
|
|
288
|
-
"yellow-11": "#422006",
|
|
289
|
-
"yellow-12": "#271304",
|
|
290
|
-
"yellow-2": "#fef9c3",
|
|
291
|
-
"yellow-3": "#fef08a",
|
|
292
|
-
"yellow-4": "#fde047",
|
|
293
|
-
"yellow-5": "#facc15",
|
|
294
|
-
"yellow-6": "#eab308",
|
|
295
|
-
"yellow-7": "#ca8a04",
|
|
296
|
-
"yellow-8": "#a16207",
|
|
297
|
-
"yellow-9": "#854d0e",
|
|
298
|
-
"zinc-1": "#fafafa",
|
|
299
|
-
"zinc-10": "#18181b",
|
|
300
|
-
"zinc-11": "#09090b",
|
|
301
|
-
"zinc-12": "#050506",
|
|
302
|
-
"zinc-2": "#f4f4f5",
|
|
303
|
-
"zinc-3": "#e4e4e7",
|
|
304
|
-
"zinc-4": "#d4d4d8",
|
|
305
|
-
"zinc-5": "#a1a1aa",
|
|
306
|
-
"zinc-6": "#71717a",
|
|
307
|
-
"zinc-7": "#52525b",
|
|
308
|
-
"zinc-8": "#3f3f46",
|
|
309
|
-
"zinc-9": "#27272a"
|
|
37
|
+
// src/jsEngine/calc.ts
|
|
38
|
+
function reduceConstantMath(raw) {
|
|
39
|
+
const trimmed = raw.trim();
|
|
40
|
+
const calc = stripCall(trimmed, "calc");
|
|
41
|
+
if (calc !== null) {
|
|
42
|
+
return new Evaluator(calc).parseExprToEnd();
|
|
43
|
+
}
|
|
44
|
+
const clamp = stripCall(trimmed, "clamp");
|
|
45
|
+
if (clamp !== null) {
|
|
46
|
+
const args = splitTopLevelCommas(clamp);
|
|
47
|
+
if (args.length !== 3) return null;
|
|
48
|
+
const [min2, preferred, max2] = args.map((a) => new Evaluator(a).parseExprToEnd());
|
|
49
|
+
if (min2 === null || preferred === null || max2 === null) return null;
|
|
50
|
+
return Math.max(min2, Math.min(preferred, max2));
|
|
51
|
+
}
|
|
52
|
+
const min = stripCall(trimmed, "min");
|
|
53
|
+
if (min !== null) {
|
|
54
|
+
const values = splitTopLevelCommas(min).map((a) => new Evaluator(a).parseExprToEnd());
|
|
55
|
+
return values.some((v) => v === null) ? null : Math.min(...values);
|
|
56
|
+
}
|
|
57
|
+
const max = stripCall(trimmed, "max");
|
|
58
|
+
if (max !== null) {
|
|
59
|
+
const values = splitTopLevelCommas(max).map((a) => new Evaluator(a).parseExprToEnd());
|
|
60
|
+
return values.some((v) => v === null) ? null : Math.max(...values);
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
function stripCall(raw, name) {
|
|
65
|
+
if (!raw.startsWith(name)) return null;
|
|
66
|
+
const afterName = raw.slice(name.length).trimStart();
|
|
67
|
+
if (!afterName.startsWith("(") || !afterName.endsWith(")")) return null;
|
|
68
|
+
return afterName.slice(1, -1);
|
|
69
|
+
}
|
|
70
|
+
function splitTopLevelCommas(s) {
|
|
71
|
+
const parts = [];
|
|
72
|
+
let depth = 0;
|
|
73
|
+
let start = 0;
|
|
74
|
+
for (let i = 0; i < s.length; i++) {
|
|
75
|
+
const ch = s[i];
|
|
76
|
+
if (ch === "(") depth++;
|
|
77
|
+
else if (ch === ")") depth--;
|
|
78
|
+
else if (ch === "," && depth === 0) {
|
|
79
|
+
parts.push(s.slice(start, i).trim());
|
|
80
|
+
start = i + 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
parts.push(s.slice(start).trim());
|
|
84
|
+
return parts;
|
|
85
|
+
}
|
|
86
|
+
var Evaluator = class {
|
|
87
|
+
constructor(s) {
|
|
88
|
+
this.pos = 0;
|
|
89
|
+
this.s = s;
|
|
90
|
+
}
|
|
91
|
+
parseExprToEnd() {
|
|
92
|
+
const value = this.expr();
|
|
93
|
+
if (value === null) return null;
|
|
94
|
+
this.skipWs();
|
|
95
|
+
return this.pos === this.s.length ? value : null;
|
|
96
|
+
}
|
|
97
|
+
skipWs() {
|
|
98
|
+
while (this.pos < this.s.length && /\s/.test(this.s[this.pos])) this.pos++;
|
|
99
|
+
}
|
|
100
|
+
peek() {
|
|
101
|
+
this.skipWs();
|
|
102
|
+
return this.s[this.pos];
|
|
103
|
+
}
|
|
104
|
+
expr() {
|
|
105
|
+
let value = this.term();
|
|
106
|
+
if (value === null) return null;
|
|
107
|
+
for (; ; ) {
|
|
108
|
+
const ch = this.peek();
|
|
109
|
+
if (ch === "+") {
|
|
110
|
+
this.pos++;
|
|
111
|
+
const rhs = this.term();
|
|
112
|
+
if (rhs === null) return null;
|
|
113
|
+
value += rhs;
|
|
114
|
+
} else if (ch === "-") {
|
|
115
|
+
this.pos++;
|
|
116
|
+
const rhs = this.term();
|
|
117
|
+
if (rhs === null) return null;
|
|
118
|
+
value -= rhs;
|
|
119
|
+
} else {
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
term() {
|
|
125
|
+
let value = this.factor();
|
|
126
|
+
if (value === null) return null;
|
|
127
|
+
for (; ; ) {
|
|
128
|
+
const ch = this.peek();
|
|
129
|
+
if (ch === "*") {
|
|
130
|
+
this.pos++;
|
|
131
|
+
const rhs = this.factor();
|
|
132
|
+
if (rhs === null) return null;
|
|
133
|
+
value *= rhs;
|
|
134
|
+
} else if (ch === "/") {
|
|
135
|
+
this.pos++;
|
|
136
|
+
const divisor = this.factor();
|
|
137
|
+
if (divisor === null || divisor === 0) return null;
|
|
138
|
+
value /= divisor;
|
|
139
|
+
} else {
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
factor() {
|
|
145
|
+
const ch = this.peek();
|
|
146
|
+
if (ch === void 0) return null;
|
|
147
|
+
if (ch === "(") {
|
|
148
|
+
this.pos++;
|
|
149
|
+
const value = this.expr();
|
|
150
|
+
if (value === null || this.peek() !== ")") return null;
|
|
151
|
+
this.pos++;
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
if (ch === "-") {
|
|
155
|
+
this.pos++;
|
|
156
|
+
const value = this.factor();
|
|
157
|
+
return value === null ? null : -value;
|
|
158
|
+
}
|
|
159
|
+
return this.numberWithUnit();
|
|
160
|
+
}
|
|
161
|
+
numberWithUnit() {
|
|
162
|
+
this.skipWs();
|
|
163
|
+
const start = this.pos;
|
|
164
|
+
while (this.pos < this.s.length && (/[0-9]/.test(this.s[this.pos]) || this.s[this.pos] === ".")) this.pos++;
|
|
165
|
+
if (this.pos === start) return null;
|
|
166
|
+
const n = Number(this.s.slice(start, this.pos));
|
|
167
|
+
if (!Number.isFinite(n)) return null;
|
|
168
|
+
const unitStart = this.pos;
|
|
169
|
+
while (this.pos < this.s.length && /[a-zA-Z]/.test(this.s[this.pos])) this.pos++;
|
|
170
|
+
const unit = this.s.slice(unitStart, this.pos);
|
|
171
|
+
switch (unit) {
|
|
172
|
+
case "":
|
|
173
|
+
return n;
|
|
174
|
+
case "px":
|
|
175
|
+
return n;
|
|
176
|
+
case "rem":
|
|
177
|
+
return n * 16;
|
|
178
|
+
default:
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
310
182
|
};
|
|
311
183
|
|
|
312
|
-
// src/
|
|
313
|
-
var
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
"
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
184
|
+
// src/layoutCalc.ts
|
|
185
|
+
var PERCENT_CALC_TOKEN_RE = /^(w|h)-\[calc\(([^)]+)\)\]$/;
|
|
186
|
+
function parsePercentRelativeCalc(token) {
|
|
187
|
+
const m = PERCENT_CALC_TOKEN_RE.exec(token);
|
|
188
|
+
if (!m) return null;
|
|
189
|
+
const property = m[1] === "w" ? "width" : "height";
|
|
190
|
+
const inner = m[2].replace(/_/g, " ").trim();
|
|
191
|
+
let mm = /^(-?[\d.]+)%\s*([+-])\s*(.+)$/.exec(inner);
|
|
192
|
+
if (mm) {
|
|
193
|
+
const percentCoefficient = Number(mm[1]);
|
|
194
|
+
const magnitude = reduceConstantMath(`calc(${mm[3].trim()})`);
|
|
195
|
+
if (!Number.isFinite(percentCoefficient) || magnitude === null) return null;
|
|
196
|
+
return { property, percentCoefficient, constantPx: mm[2] === "+" ? magnitude : -magnitude };
|
|
197
|
+
}
|
|
198
|
+
mm = /^(.+?)\s*([+-])\s*(-?[\d.]+)%$/.exec(inner);
|
|
199
|
+
if (mm) {
|
|
200
|
+
const constantPx = reduceConstantMath(`calc(${mm[1].trim()})`);
|
|
201
|
+
const percentMagnitude = Number(mm[3]);
|
|
202
|
+
if (constantPx === null || !Number.isFinite(percentMagnitude)) return null;
|
|
203
|
+
return { property, percentCoefficient: mm[2] === "+" ? percentMagnitude : -percentMagnitude, constantPx };
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
function resolvePercentRelativeCalc(basisPx, calc) {
|
|
208
|
+
return basisPx * calc.percentCoefficient / 100 + calc.constantPx;
|
|
332
209
|
}
|
|
333
210
|
|
|
334
|
-
// src/
|
|
335
|
-
var
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
return
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
var mode = "system";
|
|
344
|
-
var isDark = resolveIsDark(mode);
|
|
345
|
-
var subscription = import_react_native.Appearance.addChangeListener(({ colorScheme }) => {
|
|
346
|
-
if (mode !== "system") return;
|
|
347
|
-
isDark = colorScheme === "dark";
|
|
348
|
-
notify();
|
|
349
|
-
});
|
|
350
|
-
function notify() {
|
|
351
|
-
for (const listener of listeners) listener();
|
|
211
|
+
// src/jsxRuntimeCore.ts
|
|
212
|
+
var DYNAMIC_TOKEN_MATCH_RE = /var\(--([a-zA-Z0-9-]+)\)/g;
|
|
213
|
+
function substituteDynamicTokens(classStrRaw) {
|
|
214
|
+
if (!classStrRaw.includes("var(--")) return classStrRaw;
|
|
215
|
+
return classStrRaw.replace(DYNAMIC_TOKEN_MATCH_RE, (whole, name) => {
|
|
216
|
+
const value = (0, import_dynamicTokens.getDynamicToken)(name);
|
|
217
|
+
return value ?? whole;
|
|
218
|
+
});
|
|
352
219
|
}
|
|
353
|
-
|
|
354
|
-
|
|
220
|
+
var PERCENT_RELATIVE_CALC_HINT_RE = /[wh]-\[calc\([^)]*%[^)]*\)\]/;
|
|
221
|
+
function extractPercentRelativeCalcs(classStrRaw) {
|
|
222
|
+
const found = [];
|
|
223
|
+
for (const token of classStrRaw.split(/\s+/)) {
|
|
224
|
+
const parsed = parsePercentRelativeCalc(token);
|
|
225
|
+
if (parsed) found.push(parsed);
|
|
226
|
+
}
|
|
227
|
+
return found;
|
|
355
228
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
function resolveStyle(classString, pressed = false) {
|
|
359
|
-
const KbachModule = import_react_native2.TurboModuleRegistry.getEnforcing("KbachModule");
|
|
360
|
-
const colorScheme = getGlobalDarkMode() ? "dark" : "light";
|
|
361
|
-
const json = KbachModule.resolveStyle(classString, getThemeJson(), colorScheme, pressed);
|
|
362
|
-
return JSON.parse(json);
|
|
229
|
+
function stripPercentRelativeCalcTokens(classStrRaw) {
|
|
230
|
+
return classStrRaw.split(/\s+/).filter((token) => token && parsePercentRelativeCalc(token) === null).join(" ");
|
|
363
231
|
}
|
|
364
|
-
|
|
365
|
-
// src/jsx-runtime.tsx
|
|
366
232
|
function makeElement(isStaticChildren, type, props, key) {
|
|
367
233
|
return (isStaticChildren ? import_jsx_runtime.jsxs : import_jsx_runtime.jsx)(type, props, key);
|
|
368
234
|
}
|
|
369
|
-
function resolvedStyleFor(classStrRaw, userStyle, pressed) {
|
|
370
|
-
const
|
|
235
|
+
function resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, pressed, layoutOverrides) {
|
|
236
|
+
const cleaned = stripPercentRelativeCalcTokens(substituteDynamicTokens(classStrRaw));
|
|
237
|
+
const resolved = resolveStyle2(cleaned, pressed);
|
|
238
|
+
if (layoutOverrides) {
|
|
239
|
+
Object.assign(resolved, layoutOverrides);
|
|
240
|
+
}
|
|
371
241
|
if (userStyle === void 0) {
|
|
372
242
|
return resolved;
|
|
373
243
|
}
|
|
@@ -376,7 +246,77 @@ function resolvedStyleFor(classStrRaw, userStyle, pressed) {
|
|
|
376
246
|
}
|
|
377
247
|
return [resolved, userStyle];
|
|
378
248
|
}
|
|
379
|
-
|
|
249
|
+
var DARK_MODIFIER_RE = /(^|\s)dark:/;
|
|
250
|
+
var BREAKPOINT_MODIFIER_RE = /(^|\s)(sm|md|lg|xl|2xl):/;
|
|
251
|
+
var BREAKPOINT_MODIFIER_MATCH_RE = /(?:^|\s)(sm|md|lg|xl|2xl):/g;
|
|
252
|
+
function darkModeKeySuffix(classStrRaw) {
|
|
253
|
+
return DARK_MODIFIER_RE.test(classStrRaw) ? `:kb-dark-${(0, import_darkModeStore.getGlobalDarkMode)()}` : "";
|
|
254
|
+
}
|
|
255
|
+
function breakpointKeySuffix(classStrRaw, width) {
|
|
256
|
+
const matches = classStrRaw.match(BREAKPOINT_MODIFIER_MATCH_RE);
|
|
257
|
+
if (!matches) {
|
|
258
|
+
return "";
|
|
259
|
+
}
|
|
260
|
+
const screens = (0, import_theme.getTheme)().screens;
|
|
261
|
+
const present = Array.from(new Set(matches.map((m) => m.trim().slice(0, -1))));
|
|
262
|
+
const state = present.map((name) => screens[name] !== void 0 && width >= screens[name] ? "1" : "0").join("");
|
|
263
|
+
return `:kb-bp-${state}`;
|
|
264
|
+
}
|
|
265
|
+
function dynamicTokenKeySuffix(classStrRaw) {
|
|
266
|
+
const matches = classStrRaw.match(DYNAMIC_TOKEN_MATCH_RE);
|
|
267
|
+
if (!matches) return "";
|
|
268
|
+
const values = matches.map((m) => (0, import_dynamicTokens.getDynamicToken)(m.slice("var(--".length, -1)) ?? "");
|
|
269
|
+
return `:kb-dt-${values.join("|")}`;
|
|
270
|
+
}
|
|
271
|
+
function percentCalcKeySuffix(percentCalcs, measuredBasis) {
|
|
272
|
+
if (percentCalcs.length === 0) return "";
|
|
273
|
+
const values = percentCalcs.map((calc) => {
|
|
274
|
+
const basis = measuredBasis?.[calc.property];
|
|
275
|
+
return basis === void 0 ? "pending" : resolvePercentRelativeCalc(basis, calc);
|
|
276
|
+
});
|
|
277
|
+
return `:kb-pc-${values.join("|")}`;
|
|
278
|
+
}
|
|
279
|
+
function ReactiveElement({
|
|
280
|
+
hostType,
|
|
281
|
+
hostRest,
|
|
282
|
+
classStrRaw,
|
|
283
|
+
userStyle,
|
|
284
|
+
resolveStyle: resolveStyle2,
|
|
285
|
+
elementKey,
|
|
286
|
+
isStaticChildren
|
|
287
|
+
}) {
|
|
288
|
+
(0, import_react.useSyncExternalStore)(import_darkModeStore.subscribeGlobalDarkMode, import_darkModeStore.getGlobalDarkMode);
|
|
289
|
+
(0, import_react.useSyncExternalStore)(import_dynamicTokens.subscribeDynamicTokens, import_dynamicTokens.getDynamicTokensVersion);
|
|
290
|
+
const { width } = (0, import_react_native.useWindowDimensions)();
|
|
291
|
+
const [measuredBasis, setMeasuredBasis] = (0, import_react.useState)(null);
|
|
292
|
+
const measure = (0, import_react.useCallback)((e) => {
|
|
293
|
+
const { width: w, height: h } = e.nativeEvent.layout;
|
|
294
|
+
setMeasuredBasis((prev) => prev && prev.width === w && prev.height === h ? prev : { width: w, height: h });
|
|
295
|
+
}, []);
|
|
296
|
+
const percentCalcs = extractPercentRelativeCalcs(classStrRaw);
|
|
297
|
+
let layoutOverrides;
|
|
298
|
+
let hostRestWithLayout = hostRest;
|
|
299
|
+
if (percentCalcs.length > 0) {
|
|
300
|
+
layoutOverrides = {};
|
|
301
|
+
for (const calc of percentCalcs) {
|
|
302
|
+
const basis = measuredBasis?.[calc.property];
|
|
303
|
+
layoutOverrides[calc.property] = basis === void 0 ? "100%" : resolvePercentRelativeCalc(basis, calc);
|
|
304
|
+
}
|
|
305
|
+
const userOnLayout = hostRest.onLayout;
|
|
306
|
+
hostRestWithLayout = {
|
|
307
|
+
...hostRest,
|
|
308
|
+
onLayout: userOnLayout ? (e) => {
|
|
309
|
+
measure(e);
|
|
310
|
+
userOnLayout(e);
|
|
311
|
+
} : measure
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
const finalStyle = hostType === import_react_native.Pressable ? (state) => resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, state.pressed, layoutOverrides) : resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, false, layoutOverrides);
|
|
315
|
+
const suffix = darkModeKeySuffix(classStrRaw) + breakpointKeySuffix(classStrRaw, width) + dynamicTokenKeySuffix(classStrRaw) + percentCalcKeySuffix(percentCalcs, measuredBasis);
|
|
316
|
+
const finalKey = suffix ? `${elementKey ?? ""}${suffix}` : elementKey;
|
|
317
|
+
return makeElement(isStaticChildren, hostType, { ...hostRestWithLayout, style: finalStyle }, finalKey);
|
|
318
|
+
}
|
|
319
|
+
function processElement(resolveStyle2, type, rawProps, key, isStaticChildren) {
|
|
380
320
|
if (type === null || typeof type === "symbol" || !rawProps) {
|
|
381
321
|
return makeElement(isStaticChildren, type, rawProps ?? {}, key);
|
|
382
322
|
}
|
|
@@ -384,15 +324,1295 @@ function processElement(type, rawProps, key, isStaticChildren) {
|
|
|
384
324
|
if (typeof classStrRaw !== "string") {
|
|
385
325
|
return makeElement(isStaticChildren, type, rawProps, key);
|
|
386
326
|
}
|
|
387
|
-
|
|
327
|
+
if (DARK_MODIFIER_RE.test(classStrRaw) || BREAKPOINT_MODIFIER_RE.test(classStrRaw) || classStrRaw.includes("var(--") || PERCENT_RELATIVE_CALC_HINT_RE.test(classStrRaw)) {
|
|
328
|
+
return (0, import_jsx_runtime.jsx)(
|
|
329
|
+
ReactiveElement,
|
|
330
|
+
{ hostType: type, hostRest: rest, classStrRaw, userStyle, resolveStyle: resolveStyle2, elementKey: key, isStaticChildren },
|
|
331
|
+
key
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
const finalStyle = type === import_react_native.Pressable ? (state) => resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, state.pressed) : resolvedStyleFor(resolveStyle2, classStrRaw, userStyle, false);
|
|
388
335
|
return makeElement(isStaticChildren, type, { ...rest, style: finalStyle }, key);
|
|
389
336
|
}
|
|
390
|
-
function
|
|
391
|
-
|
|
337
|
+
function createJsxFunctions(resolveStyle2) {
|
|
338
|
+
function jsx2(type, props, key) {
|
|
339
|
+
return processElement(resolveStyle2, type, props, key, false);
|
|
340
|
+
}
|
|
341
|
+
function jsxs2(type, props, key) {
|
|
342
|
+
return processElement(resolveStyle2, type, props, key, true);
|
|
343
|
+
}
|
|
344
|
+
return { jsx: jsx2, jsxs: jsxs2 };
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/nativeBridge.ts
|
|
348
|
+
var import_react_native2 = require("react-native");
|
|
349
|
+
var import_theme2 = require("./theme");
|
|
350
|
+
var import_darkModeStore2 = require("./darkModeStore");
|
|
351
|
+
|
|
352
|
+
// src/jsEngine/parser.ts
|
|
353
|
+
var VALUE_PREFIXES = [
|
|
354
|
+
"bg-opacity-",
|
|
355
|
+
"text-opacity-",
|
|
356
|
+
"bg-blend-",
|
|
357
|
+
"text-shadow-",
|
|
358
|
+
"bg-",
|
|
359
|
+
"text-",
|
|
360
|
+
"border-x-",
|
|
361
|
+
"border-y-",
|
|
362
|
+
"border-t-",
|
|
363
|
+
"border-r-",
|
|
364
|
+
"border-b-",
|
|
365
|
+
"border-l-",
|
|
366
|
+
"border-",
|
|
367
|
+
"caret-",
|
|
368
|
+
"accent-",
|
|
369
|
+
"fill-",
|
|
370
|
+
"stroke-width-",
|
|
371
|
+
"stroke-",
|
|
372
|
+
"resize-",
|
|
373
|
+
"touch-",
|
|
374
|
+
"will-change-",
|
|
375
|
+
"scroll-mx-",
|
|
376
|
+
"scroll-my-",
|
|
377
|
+
"scroll-mt-",
|
|
378
|
+
"scroll-mr-",
|
|
379
|
+
"scroll-mb-",
|
|
380
|
+
"scroll-ml-",
|
|
381
|
+
"scroll-m-",
|
|
382
|
+
"scroll-px-",
|
|
383
|
+
"scroll-py-",
|
|
384
|
+
"scroll-pt-",
|
|
385
|
+
"scroll-pr-",
|
|
386
|
+
"scroll-pb-",
|
|
387
|
+
"scroll-pl-",
|
|
388
|
+
"scroll-p-",
|
|
389
|
+
"px-",
|
|
390
|
+
"py-",
|
|
391
|
+
"pt-",
|
|
392
|
+
"pr-",
|
|
393
|
+
"pb-",
|
|
394
|
+
"pl-",
|
|
395
|
+
"p-",
|
|
396
|
+
"mx-",
|
|
397
|
+
"my-",
|
|
398
|
+
"mt-",
|
|
399
|
+
"mr-",
|
|
400
|
+
"mb-",
|
|
401
|
+
"ml-",
|
|
402
|
+
"m-",
|
|
403
|
+
"gap-x-",
|
|
404
|
+
"gap-y-",
|
|
405
|
+
"gap-",
|
|
406
|
+
"min-w-",
|
|
407
|
+
"max-w-",
|
|
408
|
+
"w-",
|
|
409
|
+
"min-h-",
|
|
410
|
+
"max-h-",
|
|
411
|
+
"h-",
|
|
412
|
+
"size-",
|
|
413
|
+
"basis-",
|
|
414
|
+
"rounded-tl-",
|
|
415
|
+
"rounded-tr-",
|
|
416
|
+
"rounded-br-",
|
|
417
|
+
"rounded-bl-",
|
|
418
|
+
"rounded-t-",
|
|
419
|
+
"rounded-r-",
|
|
420
|
+
"rounded-b-",
|
|
421
|
+
"rounded-l-",
|
|
422
|
+
"rounded-",
|
|
423
|
+
"ring-offset-",
|
|
424
|
+
"ring-",
|
|
425
|
+
"outline-offset-",
|
|
426
|
+
"outline-",
|
|
427
|
+
"shadow-",
|
|
428
|
+
"opacity-",
|
|
429
|
+
"duration-",
|
|
430
|
+
"delay-",
|
|
431
|
+
"ease-",
|
|
432
|
+
"cursor-",
|
|
433
|
+
"mix-blend-",
|
|
434
|
+
"animate-",
|
|
435
|
+
"leading-",
|
|
436
|
+
"tracking-",
|
|
437
|
+
"font-",
|
|
438
|
+
"z-",
|
|
439
|
+
"inset-",
|
|
440
|
+
"top-",
|
|
441
|
+
"right-",
|
|
442
|
+
"bottom-",
|
|
443
|
+
"left-",
|
|
444
|
+
"divide-color-",
|
|
445
|
+
"space-x-",
|
|
446
|
+
"space-y-",
|
|
447
|
+
"flex-",
|
|
448
|
+
"grow-",
|
|
449
|
+
"shrink-",
|
|
450
|
+
"order-",
|
|
451
|
+
"grid-cols-",
|
|
452
|
+
"grid-rows-",
|
|
453
|
+
"grid-flow-",
|
|
454
|
+
"auto-cols-",
|
|
455
|
+
"auto-rows-",
|
|
456
|
+
"col-span-",
|
|
457
|
+
"col-start-",
|
|
458
|
+
"col-end-",
|
|
459
|
+
"col-",
|
|
460
|
+
"row-span-",
|
|
461
|
+
"row-start-",
|
|
462
|
+
"row-end-",
|
|
463
|
+
"row-",
|
|
464
|
+
"place-items-",
|
|
465
|
+
"place-content-",
|
|
466
|
+
"place-self-",
|
|
467
|
+
"justify-items-",
|
|
468
|
+
"justify-self-",
|
|
469
|
+
"scale-x-",
|
|
470
|
+
"scale-y-",
|
|
471
|
+
"scale-",
|
|
472
|
+
"rotate-",
|
|
473
|
+
"translate-x-",
|
|
474
|
+
"translate-y-",
|
|
475
|
+
"skew-x-",
|
|
476
|
+
"skew-y-",
|
|
477
|
+
"origin-",
|
|
478
|
+
"blur-",
|
|
479
|
+
"brightness-",
|
|
480
|
+
"contrast-",
|
|
481
|
+
"grayscale-",
|
|
482
|
+
"hue-rotate-",
|
|
483
|
+
"invert-",
|
|
484
|
+
"saturate-",
|
|
485
|
+
"sepia-",
|
|
486
|
+
"drop-shadow-",
|
|
487
|
+
"filter-",
|
|
488
|
+
"backdrop-blur-",
|
|
489
|
+
"backdrop-brightness-",
|
|
490
|
+
"backdrop-contrast-",
|
|
491
|
+
"backdrop-grayscale-",
|
|
492
|
+
"backdrop-hue-rotate-",
|
|
493
|
+
"backdrop-invert-",
|
|
494
|
+
"backdrop-opacity-",
|
|
495
|
+
"backdrop-saturate-",
|
|
496
|
+
"backdrop-sepia-",
|
|
497
|
+
"backdrop-filter-",
|
|
498
|
+
"decoration-",
|
|
499
|
+
"underline-offset-",
|
|
500
|
+
"indent-",
|
|
501
|
+
"from-",
|
|
502
|
+
"via-",
|
|
503
|
+
"to-"
|
|
504
|
+
];
|
|
505
|
+
var ARBITRARY_PROPERTY_SENTINEL = "[arbitrary-property]";
|
|
506
|
+
function isSafeArbitraryValue(value) {
|
|
507
|
+
return !value.includes("{") && !value.includes("}") && !value.includes(";");
|
|
508
|
+
}
|
|
509
|
+
function splitRespectingBrackets(token) {
|
|
510
|
+
const parts = [];
|
|
511
|
+
let depth = 0;
|
|
512
|
+
let start = 0;
|
|
513
|
+
for (let i = 0; i < token.length; i++) {
|
|
514
|
+
const ch = token[i];
|
|
515
|
+
if (ch === "[") depth += 1;
|
|
516
|
+
else if (ch === "]") depth -= 1;
|
|
517
|
+
else if (ch === ":" && depth <= 0) {
|
|
518
|
+
parts.push(token.slice(start, i));
|
|
519
|
+
start = i + 1;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
parts.push(token.slice(start));
|
|
523
|
+
return parts;
|
|
524
|
+
}
|
|
525
|
+
function parseClass(token) {
|
|
526
|
+
const parts = splitRespectingBrackets(token);
|
|
527
|
+
let base = parts.pop() ?? token;
|
|
528
|
+
const modifiers = parts;
|
|
529
|
+
const important = base.startsWith("!");
|
|
530
|
+
if (important) {
|
|
531
|
+
base = base.slice(1);
|
|
532
|
+
}
|
|
533
|
+
const negative = base.startsWith("-");
|
|
534
|
+
if (negative) {
|
|
535
|
+
base = base.slice(1);
|
|
536
|
+
}
|
|
537
|
+
if (base.length >= 2 && base.startsWith("[") && base.endsWith("]")) {
|
|
538
|
+
const raw = base.slice(1, -1);
|
|
539
|
+
const colonIdx = raw.indexOf(":");
|
|
540
|
+
if (colonIdx !== -1) {
|
|
541
|
+
const property = raw.slice(0, colonIdx);
|
|
542
|
+
const rawValue = raw.slice(colonIdx + 1);
|
|
543
|
+
if (property !== "" && rawValue !== "" && isSafeArbitraryValue(raw)) {
|
|
544
|
+
const value = rawValue.replace(/_/g, " ");
|
|
545
|
+
return {
|
|
546
|
+
modifiers,
|
|
547
|
+
utility: ARBITRARY_PROPERTY_SENTINEL,
|
|
548
|
+
value: `${property}:${value}`,
|
|
549
|
+
isArbitrary: true,
|
|
550
|
+
important,
|
|
551
|
+
negative,
|
|
552
|
+
original: token
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
for (const prefix of VALUE_PREFIXES) {
|
|
558
|
+
if (!base.startsWith(prefix)) continue;
|
|
559
|
+
const value = base.slice(prefix.length);
|
|
560
|
+
if (value === "") continue;
|
|
561
|
+
if (value.length >= 2 && value.startsWith("[") && value.endsWith("]")) {
|
|
562
|
+
const raw = value.slice(1, -1);
|
|
563
|
+
if (!isSafeArbitraryValue(raw)) {
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
const spaced = raw.replace(/_/g, " ");
|
|
567
|
+
return {
|
|
568
|
+
modifiers,
|
|
569
|
+
utility: prefix.slice(0, -1),
|
|
570
|
+
value: spaced,
|
|
571
|
+
isArbitrary: true,
|
|
572
|
+
important,
|
|
573
|
+
negative,
|
|
574
|
+
original: token
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
return {
|
|
578
|
+
modifiers,
|
|
579
|
+
utility: prefix.slice(0, -1),
|
|
580
|
+
value,
|
|
581
|
+
isArbitrary: false,
|
|
582
|
+
important,
|
|
583
|
+
negative,
|
|
584
|
+
original: token
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
return {
|
|
588
|
+
modifiers,
|
|
589
|
+
utility: base,
|
|
590
|
+
value: null,
|
|
591
|
+
isArbitrary: false,
|
|
592
|
+
important,
|
|
593
|
+
negative,
|
|
594
|
+
original: token
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// src/jsEngine/shared.ts
|
|
599
|
+
function decl(property, value) {
|
|
600
|
+
return { property, value };
|
|
601
|
+
}
|
|
602
|
+
function spacingPx(theme, value) {
|
|
603
|
+
const fromTable = theme.spacing[value];
|
|
604
|
+
if (fromTable !== void 0) return fromTable;
|
|
605
|
+
const n = Number(value);
|
|
606
|
+
return Number.isFinite(n) && value.trim() !== "" ? n * 4 : void 0;
|
|
607
|
+
}
|
|
608
|
+
function resolveLength(theme, parsed) {
|
|
609
|
+
if (parsed.negative) return null;
|
|
610
|
+
const value = parsed.value;
|
|
611
|
+
if (value === null) return null;
|
|
612
|
+
if (parsed.isArbitrary) return value;
|
|
613
|
+
if (value === "full") return "100%";
|
|
614
|
+
if (value === "auto") return "auto";
|
|
615
|
+
const px = spacingPx(theme, value);
|
|
616
|
+
return px === void 0 ? null : `${px}px`;
|
|
617
|
+
}
|
|
618
|
+
function resolveNegatableLength(theme, parsed) {
|
|
619
|
+
if (!parsed.negative) return resolveLength(theme, parsed);
|
|
620
|
+
if (parsed.isArbitrary) return null;
|
|
621
|
+
const value = parsed.value;
|
|
622
|
+
if (value === null) return null;
|
|
623
|
+
const px = spacingPx(theme, value);
|
|
624
|
+
if (px === void 0) return null;
|
|
625
|
+
if (px === 0) return "0px";
|
|
626
|
+
return `-${px}px`;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// src/jsEngine/resolvers/layout.ts
|
|
630
|
+
function negateRaw(value, negative) {
|
|
631
|
+
return negative ? `-${value}` : value;
|
|
632
|
+
}
|
|
633
|
+
function resolve(parsed, theme) {
|
|
634
|
+
switch (parsed.utility) {
|
|
635
|
+
case "flex":
|
|
636
|
+
return parsed.value === null ? [decl("display", "flex")] : null;
|
|
637
|
+
case "grid":
|
|
638
|
+
return [decl("display", "grid")];
|
|
639
|
+
case "block":
|
|
640
|
+
return [decl("display", "block")];
|
|
641
|
+
case "inline-block":
|
|
642
|
+
return [decl("display", "inline-block")];
|
|
643
|
+
case "inline":
|
|
644
|
+
return [decl("display", "inline")];
|
|
645
|
+
case "inline-flex":
|
|
646
|
+
return [decl("display", "inline-flex")];
|
|
647
|
+
case "inline-grid":
|
|
648
|
+
return [decl("display", "inline-grid")];
|
|
649
|
+
case "contents":
|
|
650
|
+
return [decl("display", "contents")];
|
|
651
|
+
case "flow-root":
|
|
652
|
+
return [decl("display", "flow-root")];
|
|
653
|
+
case "hidden":
|
|
654
|
+
return [decl("display", "none")];
|
|
655
|
+
case "@container":
|
|
656
|
+
return [decl("container-type", "inline-size")];
|
|
657
|
+
case "items-center":
|
|
658
|
+
return [decl("align-items", "center")];
|
|
659
|
+
case "items-start":
|
|
660
|
+
return [decl("align-items", "flex-start")];
|
|
661
|
+
case "items-end":
|
|
662
|
+
return [decl("align-items", "flex-end")];
|
|
663
|
+
case "items-baseline":
|
|
664
|
+
return [decl("align-items", "baseline")];
|
|
665
|
+
case "items-stretch":
|
|
666
|
+
return [decl("align-items", "stretch")];
|
|
667
|
+
case "justify-center":
|
|
668
|
+
return [decl("justify-content", "center")];
|
|
669
|
+
case "justify-start":
|
|
670
|
+
return [decl("justify-content", "flex-start")];
|
|
671
|
+
case "justify-end":
|
|
672
|
+
return [decl("justify-content", "flex-end")];
|
|
673
|
+
case "justify-between":
|
|
674
|
+
return [decl("justify-content", "space-between")];
|
|
675
|
+
case "justify-around":
|
|
676
|
+
return [decl("justify-content", "space-around")];
|
|
677
|
+
case "justify-evenly":
|
|
678
|
+
return [decl("justify-content", "space-evenly")];
|
|
679
|
+
case "content-start":
|
|
680
|
+
return [decl("align-content", "flex-start")];
|
|
681
|
+
case "content-end":
|
|
682
|
+
return [decl("align-content", "flex-end")];
|
|
683
|
+
case "content-center":
|
|
684
|
+
return [decl("align-content", "center")];
|
|
685
|
+
case "content-between":
|
|
686
|
+
return [decl("align-content", "space-between")];
|
|
687
|
+
case "content-around":
|
|
688
|
+
return [decl("align-content", "space-around")];
|
|
689
|
+
case "content-evenly":
|
|
690
|
+
return [decl("align-content", "space-evenly")];
|
|
691
|
+
case "content-stretch":
|
|
692
|
+
return [decl("align-content", "stretch")];
|
|
693
|
+
case "self-auto":
|
|
694
|
+
return [decl("align-self", "auto")];
|
|
695
|
+
case "self-center":
|
|
696
|
+
return [decl("align-self", "center")];
|
|
697
|
+
case "self-start":
|
|
698
|
+
return [decl("align-self", "flex-start")];
|
|
699
|
+
case "self-end":
|
|
700
|
+
return [decl("align-self", "flex-end")];
|
|
701
|
+
case "self-stretch":
|
|
702
|
+
return [decl("align-self", "stretch")];
|
|
703
|
+
case "self-baseline":
|
|
704
|
+
return [decl("align-self", "baseline")];
|
|
705
|
+
case "overflow-hidden":
|
|
706
|
+
return [decl("overflow", "hidden")];
|
|
707
|
+
case "overflow-auto":
|
|
708
|
+
return [decl("overflow", "auto")];
|
|
709
|
+
case "overflow-scroll":
|
|
710
|
+
return [decl("overflow", "scroll")];
|
|
711
|
+
case "overflow-visible":
|
|
712
|
+
return [decl("overflow", "visible")];
|
|
713
|
+
case "static":
|
|
714
|
+
return [decl("position", "static")];
|
|
715
|
+
case "relative":
|
|
716
|
+
return [decl("position", "relative")];
|
|
717
|
+
case "absolute":
|
|
718
|
+
return [decl("position", "absolute")];
|
|
719
|
+
case "fixed":
|
|
720
|
+
return [decl("position", "fixed")];
|
|
721
|
+
case "sticky":
|
|
722
|
+
return [decl("position", "sticky")];
|
|
723
|
+
case "z":
|
|
724
|
+
return parsed.value === null ? null : [decl("z-index", negateRaw(parsed.value, parsed.negative))];
|
|
725
|
+
case "order":
|
|
726
|
+
return parsed.value === null ? null : [decl("order", negateRaw(parsed.value, parsed.negative))];
|
|
727
|
+
case "grow":
|
|
728
|
+
return [decl("flex-grow", parsed.value ?? "1")];
|
|
729
|
+
case "shrink":
|
|
730
|
+
return [decl("flex-shrink", parsed.value ?? "1")];
|
|
731
|
+
// top/right/bottom/left/inset support real Tailwind's negative-value
|
|
732
|
+
// convention ("-top-4") — see resolveNegatableLength's own doc comment.
|
|
733
|
+
case "top": {
|
|
734
|
+
const v = resolveNegatableLength(theme, parsed);
|
|
735
|
+
return v === null ? null : [decl("top", v)];
|
|
736
|
+
}
|
|
737
|
+
case "right": {
|
|
738
|
+
const v = resolveNegatableLength(theme, parsed);
|
|
739
|
+
return v === null ? null : [decl("right", v)];
|
|
740
|
+
}
|
|
741
|
+
case "bottom": {
|
|
742
|
+
const v = resolveNegatableLength(theme, parsed);
|
|
743
|
+
return v === null ? null : [decl("bottom", v)];
|
|
744
|
+
}
|
|
745
|
+
case "left": {
|
|
746
|
+
const v = resolveNegatableLength(theme, parsed);
|
|
747
|
+
return v === null ? null : [decl("left", v)];
|
|
748
|
+
}
|
|
749
|
+
case "inset": {
|
|
750
|
+
const v = resolveNegatableLength(theme, parsed);
|
|
751
|
+
return v === null ? null : [decl("inset", v)];
|
|
752
|
+
}
|
|
753
|
+
case "aspect-square":
|
|
754
|
+
return [decl("aspect-ratio", "1 / 1")];
|
|
755
|
+
case "aspect-video":
|
|
756
|
+
return [decl("aspect-ratio", "16 / 9")];
|
|
757
|
+
default:
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
function resolveFlex(parsed, web) {
|
|
762
|
+
if (parsed.utility !== "flex") return null;
|
|
763
|
+
const value = parsed.value;
|
|
764
|
+
if (value === null) return null;
|
|
765
|
+
if (parsed.isArbitrary) return [decl("flex", value)];
|
|
766
|
+
switch (value) {
|
|
767
|
+
case "row":
|
|
768
|
+
return [decl("flex-direction", "row")];
|
|
769
|
+
case "col":
|
|
770
|
+
return [decl("flex-direction", "column")];
|
|
771
|
+
case "row-reverse":
|
|
772
|
+
return [decl("flex-direction", "row-reverse")];
|
|
773
|
+
case "col-reverse":
|
|
774
|
+
return [decl("flex-direction", "column-reverse")];
|
|
775
|
+
case "wrap":
|
|
776
|
+
return [decl("flex-wrap", "wrap")];
|
|
777
|
+
case "wrap-reverse":
|
|
778
|
+
return [decl("flex-wrap", "wrap-reverse")];
|
|
779
|
+
case "nowrap":
|
|
780
|
+
return [decl("flex-wrap", "nowrap")];
|
|
781
|
+
case "1":
|
|
782
|
+
return [decl("flex", "1")];
|
|
783
|
+
case "auto":
|
|
784
|
+
return [decl("flex", web ? "auto" : "1")];
|
|
785
|
+
case "initial":
|
|
786
|
+
return [decl("flex", web ? "initial" : "1")];
|
|
787
|
+
case "none":
|
|
788
|
+
return [decl("flex", web ? "none" : "0")];
|
|
789
|
+
case "grow":
|
|
790
|
+
return [decl("flex-grow", "1")];
|
|
791
|
+
case "grow-0":
|
|
792
|
+
return [decl("flex-grow", "0")];
|
|
793
|
+
case "shrink":
|
|
794
|
+
return [decl("flex-shrink", "1")];
|
|
795
|
+
case "shrink-0":
|
|
796
|
+
return [decl("flex-shrink", "0")];
|
|
797
|
+
default:
|
|
798
|
+
return null;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// src/jsEngine/resolvers/spacing.ts
|
|
803
|
+
function namedSize(key) {
|
|
804
|
+
switch (key) {
|
|
805
|
+
case "sm":
|
|
806
|
+
return "24rem";
|
|
807
|
+
case "md":
|
|
808
|
+
return "28rem";
|
|
809
|
+
case "lg":
|
|
810
|
+
return "32rem";
|
|
811
|
+
case "xl":
|
|
812
|
+
return "36rem";
|
|
813
|
+
case "2xl":
|
|
814
|
+
return "42rem";
|
|
815
|
+
case "3xl":
|
|
816
|
+
return "48rem";
|
|
817
|
+
case "4xl":
|
|
818
|
+
return "56rem";
|
|
819
|
+
case "5xl":
|
|
820
|
+
return "64rem";
|
|
821
|
+
case "6xl":
|
|
822
|
+
return "72rem";
|
|
823
|
+
case "7xl":
|
|
824
|
+
return "80rem";
|
|
825
|
+
case "8xl":
|
|
826
|
+
return "88rem";
|
|
827
|
+
case "9xl":
|
|
828
|
+
return "96rem";
|
|
829
|
+
default:
|
|
830
|
+
return null;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
function fractionPercent(value) {
|
|
834
|
+
const slashIdx = value.indexOf("/");
|
|
835
|
+
if (slashIdx === -1) return null;
|
|
836
|
+
const numStr = value.slice(0, slashIdx);
|
|
837
|
+
const denStr = value.slice(slashIdx + 1);
|
|
838
|
+
const num = Number(numStr);
|
|
839
|
+
const den = Number(denStr);
|
|
840
|
+
if (!Number.isFinite(num) || !Number.isFinite(den) || numStr.trim() === "" || denStr.trim() === "") return null;
|
|
841
|
+
if (den === 0) return null;
|
|
842
|
+
const pct = num / den * 100;
|
|
843
|
+
const formatted = pct.toFixed(6);
|
|
844
|
+
const trimmed = formatted.replace(/0+$/, "").replace(/\.$/, "");
|
|
845
|
+
return `${trimmed}%`;
|
|
846
|
+
}
|
|
847
|
+
function cssSizeKeyword(key) {
|
|
848
|
+
switch (key) {
|
|
849
|
+
case "min":
|
|
850
|
+
return "min-content";
|
|
851
|
+
case "max":
|
|
852
|
+
return "max-content";
|
|
853
|
+
case "fit":
|
|
854
|
+
return "fit-content";
|
|
855
|
+
default:
|
|
856
|
+
return null;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
function resolveSize(theme, parsed) {
|
|
860
|
+
if (!parsed.isArbitrary && parsed.value !== null) {
|
|
861
|
+
const named = namedSize(parsed.value);
|
|
862
|
+
if (named !== null) return named;
|
|
863
|
+
const kw = cssSizeKeyword(parsed.value);
|
|
864
|
+
if (kw !== null) return kw;
|
|
865
|
+
const fraction = fractionPercent(parsed.value);
|
|
866
|
+
if (fraction !== null) return fraction;
|
|
867
|
+
}
|
|
868
|
+
return resolveLength(theme, parsed);
|
|
869
|
+
}
|
|
870
|
+
function resolve2(parsed, theme) {
|
|
871
|
+
const length = () => resolveLength(theme, parsed);
|
|
872
|
+
const size = () => resolveSize(theme, parsed);
|
|
873
|
+
const negatableLength = () => resolveNegatableLength(theme, parsed);
|
|
874
|
+
switch (parsed.utility) {
|
|
875
|
+
case "p": {
|
|
876
|
+
const v = length();
|
|
877
|
+
return v === null ? null : [decl("padding", v)];
|
|
878
|
+
}
|
|
879
|
+
case "px": {
|
|
880
|
+
const v = length();
|
|
881
|
+
return v === null ? null : [decl("padding-left", v), decl("padding-right", v)];
|
|
882
|
+
}
|
|
883
|
+
case "py": {
|
|
884
|
+
const v = length();
|
|
885
|
+
return v === null ? null : [decl("padding-top", v), decl("padding-bottom", v)];
|
|
886
|
+
}
|
|
887
|
+
case "pt": {
|
|
888
|
+
const v = length();
|
|
889
|
+
return v === null ? null : [decl("padding-top", v)];
|
|
890
|
+
}
|
|
891
|
+
case "pr": {
|
|
892
|
+
const v = length();
|
|
893
|
+
return v === null ? null : [decl("padding-right", v)];
|
|
894
|
+
}
|
|
895
|
+
case "pb": {
|
|
896
|
+
const v = length();
|
|
897
|
+
return v === null ? null : [decl("padding-bottom", v)];
|
|
898
|
+
}
|
|
899
|
+
case "pl": {
|
|
900
|
+
const v = length();
|
|
901
|
+
return v === null ? null : [decl("padding-left", v)];
|
|
902
|
+
}
|
|
903
|
+
case "m": {
|
|
904
|
+
const v = negatableLength();
|
|
905
|
+
return v === null ? null : [decl("margin", v)];
|
|
906
|
+
}
|
|
907
|
+
case "mx": {
|
|
908
|
+
const v = negatableLength();
|
|
909
|
+
return v === null ? null : [decl("margin-left", v), decl("margin-right", v)];
|
|
910
|
+
}
|
|
911
|
+
case "my": {
|
|
912
|
+
const v = negatableLength();
|
|
913
|
+
return v === null ? null : [decl("margin-top", v), decl("margin-bottom", v)];
|
|
914
|
+
}
|
|
915
|
+
case "mt": {
|
|
916
|
+
const v = negatableLength();
|
|
917
|
+
return v === null ? null : [decl("margin-top", v)];
|
|
918
|
+
}
|
|
919
|
+
case "mr": {
|
|
920
|
+
const v = negatableLength();
|
|
921
|
+
return v === null ? null : [decl("margin-right", v)];
|
|
922
|
+
}
|
|
923
|
+
case "mb": {
|
|
924
|
+
const v = negatableLength();
|
|
925
|
+
return v === null ? null : [decl("margin-bottom", v)];
|
|
926
|
+
}
|
|
927
|
+
case "ml": {
|
|
928
|
+
const v = negatableLength();
|
|
929
|
+
return v === null ? null : [decl("margin-left", v)];
|
|
930
|
+
}
|
|
931
|
+
case "gap": {
|
|
932
|
+
const v = length();
|
|
933
|
+
return v === null ? null : [decl("gap", v)];
|
|
934
|
+
}
|
|
935
|
+
case "gap-x": {
|
|
936
|
+
const v = length();
|
|
937
|
+
return v === null ? null : [decl("column-gap", v)];
|
|
938
|
+
}
|
|
939
|
+
case "gap-y": {
|
|
940
|
+
const v = length();
|
|
941
|
+
return v === null ? null : [decl("row-gap", v)];
|
|
942
|
+
}
|
|
943
|
+
case "w": {
|
|
944
|
+
const v = size();
|
|
945
|
+
return v === null ? null : [decl("width", v)];
|
|
946
|
+
}
|
|
947
|
+
case "h": {
|
|
948
|
+
const v = size();
|
|
949
|
+
return v === null ? null : [decl("height", v)];
|
|
950
|
+
}
|
|
951
|
+
case "min-w": {
|
|
952
|
+
const v = size();
|
|
953
|
+
return v === null ? null : [decl("min-width", v)];
|
|
954
|
+
}
|
|
955
|
+
case "max-w": {
|
|
956
|
+
const v = size();
|
|
957
|
+
return v === null ? null : [decl("max-width", v)];
|
|
958
|
+
}
|
|
959
|
+
case "min-h": {
|
|
960
|
+
const v = size();
|
|
961
|
+
return v === null ? null : [decl("min-height", v)];
|
|
962
|
+
}
|
|
963
|
+
case "max-h": {
|
|
964
|
+
const v = size();
|
|
965
|
+
return v === null ? null : [decl("max-height", v)];
|
|
966
|
+
}
|
|
967
|
+
case "size": {
|
|
968
|
+
const v = size();
|
|
969
|
+
return v === null ? null : [decl("width", v), decl("height", v)];
|
|
970
|
+
}
|
|
971
|
+
case "basis": {
|
|
972
|
+
const v = size();
|
|
973
|
+
return v === null ? null : [decl("flex-basis", v)];
|
|
974
|
+
}
|
|
975
|
+
default:
|
|
976
|
+
return null;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
// src/jsEngine/resolvers/color.ts
|
|
981
|
+
function lookupHex(theme, key) {
|
|
982
|
+
const entry = theme.colors[key];
|
|
983
|
+
return typeof entry === "string" ? entry : null;
|
|
984
|
+
}
|
|
985
|
+
function hexToRgb(hex) {
|
|
986
|
+
const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
|
|
987
|
+
if (!m) return null;
|
|
988
|
+
let h = m[1];
|
|
989
|
+
if (h.length === 3) h = h.split("").map((c) => c + c).join("");
|
|
990
|
+
const n = parseInt(h, 16);
|
|
991
|
+
return [n >> 16 & 255, n >> 8 & 255, n & 255];
|
|
992
|
+
}
|
|
993
|
+
function splitOpacity(value) {
|
|
994
|
+
const slash = value.lastIndexOf("/");
|
|
995
|
+
if (slash === -1) return [value, null];
|
|
996
|
+
const opacityText = value.slice(slash + 1);
|
|
997
|
+
const n = Number(opacityText);
|
|
998
|
+
if (opacityText !== "" && Number.isInteger(n) && n >= 0 && n <= 100) {
|
|
999
|
+
return [value.slice(0, slash), n];
|
|
1000
|
+
}
|
|
1001
|
+
return [value, null];
|
|
1002
|
+
}
|
|
1003
|
+
function colorValue(theme, parsed) {
|
|
1004
|
+
const value = parsed.value;
|
|
1005
|
+
if (value === null) return null;
|
|
1006
|
+
if (parsed.isArbitrary) return value;
|
|
1007
|
+
const [name, opacity] = splitOpacity(value);
|
|
1008
|
+
const hex = lookupHex(theme, name);
|
|
1009
|
+
if (hex === null) return null;
|
|
1010
|
+
if (opacity === null) return hex;
|
|
1011
|
+
const rgb = hexToRgb(hex);
|
|
1012
|
+
if (rgb === null) return hex;
|
|
1013
|
+
return `rgba(${rgb.join(",")},${opacity / 100})`;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// src/jsEngine/resolvers/border.ts
|
|
1017
|
+
function radiusSize(key) {
|
|
1018
|
+
switch (key) {
|
|
1019
|
+
case "none":
|
|
1020
|
+
return "0px";
|
|
1021
|
+
case "sm":
|
|
1022
|
+
return "0.125rem";
|
|
1023
|
+
case "md":
|
|
1024
|
+
return "0.375rem";
|
|
1025
|
+
case "lg":
|
|
1026
|
+
return "0.5rem";
|
|
1027
|
+
case "xl":
|
|
1028
|
+
return "0.75rem";
|
|
1029
|
+
case "2xl":
|
|
1030
|
+
return "1rem";
|
|
1031
|
+
case "3xl":
|
|
1032
|
+
return "1.5rem";
|
|
1033
|
+
case "full":
|
|
1034
|
+
return "9999px";
|
|
1035
|
+
default:
|
|
1036
|
+
return null;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
function borderSideProperty(side) {
|
|
1040
|
+
switch (side) {
|
|
1041
|
+
case "t":
|
|
1042
|
+
return "border-top";
|
|
1043
|
+
case "r":
|
|
1044
|
+
return "border-right";
|
|
1045
|
+
case "b":
|
|
1046
|
+
return "border-bottom";
|
|
1047
|
+
case "l":
|
|
1048
|
+
return "border-left";
|
|
1049
|
+
default:
|
|
1050
|
+
return null;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
function borderValue(theme, parsed) {
|
|
1054
|
+
const value = parsed.value;
|
|
1055
|
+
if (value === null) return null;
|
|
1056
|
+
if (!parsed.isArbitrary) {
|
|
1057
|
+
const side = borderSideProperty(value);
|
|
1058
|
+
if (side !== null) {
|
|
1059
|
+
return [decl(`${side}-width`, "1px"), decl(`${side}-style`, "solid")];
|
|
1060
|
+
}
|
|
1061
|
+
if (value === "collapse") return [decl("border-collapse", "collapse")];
|
|
1062
|
+
if (value === "separate") return [decl("border-collapse", "separate")];
|
|
1063
|
+
}
|
|
1064
|
+
if (parsed.isArbitrary) {
|
|
1065
|
+
return [decl("border-width", value)];
|
|
1066
|
+
}
|
|
1067
|
+
if (Number.isFinite(Number(value)) && value.trim() !== "") {
|
|
1068
|
+
const v = resolveLength(theme, parsed);
|
|
1069
|
+
return v === null ? null : [decl("border-width", v)];
|
|
1070
|
+
}
|
|
1071
|
+
if (value === "solid" || value === "dashed" || value === "dotted" || value === "double" || value === "hidden" || value === "none") {
|
|
1072
|
+
return [decl("border-style", value)];
|
|
1073
|
+
}
|
|
1074
|
+
const color = colorValue(theme, parsed);
|
|
1075
|
+
return color === null ? null : [decl("border-color", color)];
|
|
1076
|
+
}
|
|
1077
|
+
function borderSideValue(theme, parsed, sideProperty) {
|
|
1078
|
+
const value = parsed.value;
|
|
1079
|
+
if (value === null) return null;
|
|
1080
|
+
if (parsed.isArbitrary) return [decl(`${sideProperty}-width`, value)];
|
|
1081
|
+
if (Number.isFinite(Number(value)) && value.trim() !== "") {
|
|
1082
|
+
const v = resolveLength(theme, parsed);
|
|
1083
|
+
return v === null ? null : [decl(`${sideProperty}-width`, v)];
|
|
1084
|
+
}
|
|
1085
|
+
if (value === "solid" || value === "dashed" || value === "dotted" || value === "double" || value === "hidden" || value === "none") {
|
|
1086
|
+
return [decl(`${sideProperty}-style`, value)];
|
|
1087
|
+
}
|
|
1088
|
+
const color = colorValue(theme, parsed);
|
|
1089
|
+
return color === null ? null : [decl(`${sideProperty}-color`, color)];
|
|
1090
|
+
}
|
|
1091
|
+
function borderAxisValue(theme, parsed, sideA, sideB) {
|
|
1092
|
+
const value = parsed.value;
|
|
1093
|
+
if (value === null) return null;
|
|
1094
|
+
if (parsed.isArbitrary) return [decl(`${sideA}-width`, value), decl(`${sideB}-width`, value)];
|
|
1095
|
+
if (Number.isFinite(Number(value)) && value.trim() !== "") {
|
|
1096
|
+
const v = resolveLength(theme, parsed);
|
|
1097
|
+
return v === null ? null : [decl(`${sideA}-width`, v), decl(`${sideB}-width`, v)];
|
|
1098
|
+
}
|
|
1099
|
+
if (value === "solid" || value === "dashed" || value === "dotted" || value === "double" || value === "hidden" || value === "none") {
|
|
1100
|
+
return [decl(`${sideA}-style`, value), decl(`${sideB}-style`, value)];
|
|
1101
|
+
}
|
|
1102
|
+
const color = colorValue(theme, parsed);
|
|
1103
|
+
return color === null ? null : [decl(`${sideA}-color`, color), decl(`${sideB}-color`, color)];
|
|
1104
|
+
}
|
|
1105
|
+
function radiusProperties(side) {
|
|
1106
|
+
switch (side) {
|
|
1107
|
+
case "t":
|
|
1108
|
+
return ["border-top-left-radius", "border-top-right-radius"];
|
|
1109
|
+
case "r":
|
|
1110
|
+
return ["border-top-right-radius", "border-bottom-right-radius"];
|
|
1111
|
+
case "b":
|
|
1112
|
+
return ["border-bottom-right-radius", "border-bottom-left-radius"];
|
|
1113
|
+
case "l":
|
|
1114
|
+
return ["border-top-left-radius", "border-bottom-left-radius"];
|
|
1115
|
+
case "tl":
|
|
1116
|
+
return ["border-top-left-radius"];
|
|
1117
|
+
case "tr":
|
|
1118
|
+
return ["border-top-right-radius"];
|
|
1119
|
+
case "br":
|
|
1120
|
+
return ["border-bottom-right-radius"];
|
|
1121
|
+
case "bl":
|
|
1122
|
+
return ["border-bottom-left-radius"];
|
|
1123
|
+
default:
|
|
1124
|
+
return null;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
function resolveRadiusValue(theme, parsed) {
|
|
1128
|
+
if (!parsed.isArbitrary && parsed.value !== null) {
|
|
1129
|
+
const size = radiusSize(parsed.value);
|
|
1130
|
+
if (size !== null) return size;
|
|
1131
|
+
}
|
|
1132
|
+
return resolveLength(theme, parsed);
|
|
1133
|
+
}
|
|
1134
|
+
function resolveRadiusSide(theme, parsed, side) {
|
|
1135
|
+
const properties = radiusProperties(side);
|
|
1136
|
+
if (properties === null) return null;
|
|
1137
|
+
const value = resolveRadiusValue(theme, parsed);
|
|
1138
|
+
if (value === null) return null;
|
|
1139
|
+
return properties.map((p) => decl(p, value));
|
|
1140
|
+
}
|
|
1141
|
+
var OUTLINE_STYLES = ["solid", "dashed", "dotted", "double"];
|
|
1142
|
+
function outlineWidthValue(key) {
|
|
1143
|
+
switch (key) {
|
|
1144
|
+
case "0":
|
|
1145
|
+
return "0px";
|
|
1146
|
+
case "1":
|
|
1147
|
+
return "1px";
|
|
1148
|
+
case "2":
|
|
1149
|
+
return "2px";
|
|
1150
|
+
case "4":
|
|
1151
|
+
return "4px";
|
|
1152
|
+
case "8":
|
|
1153
|
+
return "8px";
|
|
1154
|
+
default:
|
|
1155
|
+
return null;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
function outlineValue(theme, parsed) {
|
|
1159
|
+
const value = parsed.value;
|
|
1160
|
+
if (value === null) return null;
|
|
1161
|
+
if (parsed.isArbitrary) return [decl("outline-width", value)];
|
|
1162
|
+
const w = outlineWidthValue(value);
|
|
1163
|
+
if (w !== null) return [decl("outline-width", w)];
|
|
1164
|
+
if (OUTLINE_STYLES.includes(value)) return [decl("outline-style", value)];
|
|
1165
|
+
const color = colorValue(theme, parsed);
|
|
1166
|
+
return color === null ? null : [decl("outline-color", color)];
|
|
1167
|
+
}
|
|
1168
|
+
function outlineOffsetValue(parsed) {
|
|
1169
|
+
const value = parsed.value;
|
|
1170
|
+
if (value === null) return null;
|
|
1171
|
+
if (parsed.isArbitrary) return [decl("outline-offset", value)];
|
|
1172
|
+
const w = outlineWidthValue(value);
|
|
1173
|
+
return w === null ? null : [decl("outline-offset", w)];
|
|
1174
|
+
}
|
|
1175
|
+
var RING_BOX_SHADOW = "var(--kb-ring-inset,) 0 0 0 var(--kb-ring-offset-width, 0px) var(--kb-ring-offset-color, #fff), var(--kb-ring-inset,) 0 0 0 calc(var(--kb-ring-width, 0px) + var(--kb-ring-offset-width, 0px)) var(--kb-ring-color, rgba(59,130,246,0.5))";
|
|
1176
|
+
function ringWidth(key) {
|
|
1177
|
+
switch (key) {
|
|
1178
|
+
case "0":
|
|
1179
|
+
return "0px";
|
|
1180
|
+
case "1":
|
|
1181
|
+
return "1px";
|
|
1182
|
+
case "2":
|
|
1183
|
+
return "2px";
|
|
1184
|
+
case "4":
|
|
1185
|
+
return "4px";
|
|
1186
|
+
case "8":
|
|
1187
|
+
return "8px";
|
|
1188
|
+
default:
|
|
1189
|
+
return null;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
function ringValue(theme, parsed) {
|
|
1193
|
+
const value = parsed.value;
|
|
1194
|
+
if (value === null) return null;
|
|
1195
|
+
if (value === "inset") {
|
|
1196
|
+
return [decl("--kb-ring-inset", "inset"), decl("box-shadow", RING_BOX_SHADOW)];
|
|
1197
|
+
}
|
|
1198
|
+
if (!parsed.isArbitrary) {
|
|
1199
|
+
const w = ringWidth(value);
|
|
1200
|
+
if (w !== null) return [decl("--kb-ring-width", w), decl("box-shadow", RING_BOX_SHADOW)];
|
|
1201
|
+
}
|
|
1202
|
+
const color = colorValue(theme, parsed);
|
|
1203
|
+
if (color === null) return null;
|
|
1204
|
+
return [decl("--kb-ring-color", color), decl("box-shadow", RING_BOX_SHADOW)];
|
|
1205
|
+
}
|
|
1206
|
+
function ringOffsetValue(theme, parsed) {
|
|
1207
|
+
const value = parsed.value;
|
|
1208
|
+
if (value === null) return null;
|
|
1209
|
+
if (!parsed.isArbitrary) {
|
|
1210
|
+
const w = ringWidth(value);
|
|
1211
|
+
if (w !== null) return [decl("--kb-ring-offset-width", w), decl("box-shadow", RING_BOX_SHADOW)];
|
|
1212
|
+
}
|
|
1213
|
+
const color = colorValue(theme, parsed);
|
|
1214
|
+
if (color === null) return null;
|
|
1215
|
+
return [decl("--kb-ring-offset-color", color), decl("box-shadow", RING_BOX_SHADOW)];
|
|
1216
|
+
}
|
|
1217
|
+
var RADIUS_SIDES = /* @__PURE__ */ new Set(["t", "r", "b", "l", "tl", "tr", "br", "bl"]);
|
|
1218
|
+
function resolve3(parsed, theme) {
|
|
1219
|
+
switch (parsed.utility) {
|
|
1220
|
+
case "border":
|
|
1221
|
+
if (parsed.value === null) return [decl("border-width", "1px"), decl("border-style", "solid")];
|
|
1222
|
+
return borderValue(theme, parsed);
|
|
1223
|
+
case "border-t":
|
|
1224
|
+
return borderSideValue(theme, parsed, "border-top");
|
|
1225
|
+
case "border-r":
|
|
1226
|
+
return borderSideValue(theme, parsed, "border-right");
|
|
1227
|
+
case "border-b":
|
|
1228
|
+
return borderSideValue(theme, parsed, "border-bottom");
|
|
1229
|
+
case "border-l":
|
|
1230
|
+
return borderSideValue(theme, parsed, "border-left");
|
|
1231
|
+
case "border-x":
|
|
1232
|
+
return borderAxisValue(theme, parsed, "border-left", "border-right");
|
|
1233
|
+
case "border-y":
|
|
1234
|
+
return borderAxisValue(theme, parsed, "border-top", "border-bottom");
|
|
1235
|
+
case "rounded": {
|
|
1236
|
+
if (parsed.value === null) return [decl("border-radius", "0.25rem")];
|
|
1237
|
+
const value = parsed.value;
|
|
1238
|
+
if (!parsed.isArbitrary) {
|
|
1239
|
+
const size = radiusSize(value);
|
|
1240
|
+
if (size !== null) return [decl("border-radius", size)];
|
|
1241
|
+
}
|
|
1242
|
+
const v = resolveLength(theme, parsed);
|
|
1243
|
+
return v === null ? null : [decl("border-radius", v)];
|
|
1244
|
+
}
|
|
1245
|
+
case "ring":
|
|
1246
|
+
if (parsed.value === null) return [decl("--kb-ring-width", "3px"), decl("box-shadow", RING_BOX_SHADOW)];
|
|
1247
|
+
return ringValue(theme, parsed);
|
|
1248
|
+
case "ring-offset":
|
|
1249
|
+
return ringOffsetValue(theme, parsed);
|
|
1250
|
+
case "outline":
|
|
1251
|
+
if (parsed.value === null) return [decl("outline-style", "solid")];
|
|
1252
|
+
if (parsed.value === "none") return [decl("outline", "none")];
|
|
1253
|
+
return outlineValue(theme, parsed);
|
|
1254
|
+
case "outline-offset":
|
|
1255
|
+
return outlineOffsetValue(parsed);
|
|
1256
|
+
default:
|
|
1257
|
+
if (parsed.utility.startsWith("rounded-") && RADIUS_SIDES.has(parsed.utility.slice("rounded-".length))) {
|
|
1258
|
+
return resolveRadiusSide(theme, parsed, parsed.utility.slice("rounded-".length));
|
|
1259
|
+
}
|
|
1260
|
+
return null;
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
// src/jsEngine/resolvers/typography.ts
|
|
1265
|
+
function textSize(key) {
|
|
1266
|
+
switch (key) {
|
|
1267
|
+
case "xs":
|
|
1268
|
+
return "0.75rem";
|
|
1269
|
+
case "sm":
|
|
1270
|
+
return "0.875rem";
|
|
1271
|
+
case "base":
|
|
1272
|
+
return "1rem";
|
|
1273
|
+
case "lg":
|
|
1274
|
+
return "1.125rem";
|
|
1275
|
+
case "xl":
|
|
1276
|
+
return "1.25rem";
|
|
1277
|
+
case "2xl":
|
|
1278
|
+
return "1.5rem";
|
|
1279
|
+
case "3xl":
|
|
1280
|
+
return "1.875rem";
|
|
1281
|
+
case "4xl":
|
|
1282
|
+
return "2.25rem";
|
|
1283
|
+
default:
|
|
1284
|
+
return null;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
function lineHeightSize(key) {
|
|
1288
|
+
switch (key) {
|
|
1289
|
+
case "3":
|
|
1290
|
+
return "0.75rem";
|
|
1291
|
+
case "4":
|
|
1292
|
+
return "1rem";
|
|
1293
|
+
case "5":
|
|
1294
|
+
return "1.25rem";
|
|
1295
|
+
case "6":
|
|
1296
|
+
return "1.5rem";
|
|
1297
|
+
case "7":
|
|
1298
|
+
return "1.75rem";
|
|
1299
|
+
case "8":
|
|
1300
|
+
return "2rem";
|
|
1301
|
+
case "9":
|
|
1302
|
+
return "2.25rem";
|
|
1303
|
+
case "10":
|
|
1304
|
+
return "2.5rem";
|
|
1305
|
+
default:
|
|
1306
|
+
return null;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
function textAlign(key) {
|
|
1310
|
+
switch (key) {
|
|
1311
|
+
case "left":
|
|
1312
|
+
return "left";
|
|
1313
|
+
case "center":
|
|
1314
|
+
return "center";
|
|
1315
|
+
case "right":
|
|
1316
|
+
return "right";
|
|
1317
|
+
case "justify":
|
|
1318
|
+
return "justify";
|
|
1319
|
+
default:
|
|
1320
|
+
return null;
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
function fontWeight(key) {
|
|
1324
|
+
switch (key) {
|
|
1325
|
+
case "thin":
|
|
1326
|
+
return "100";
|
|
1327
|
+
case "normal":
|
|
1328
|
+
return "400";
|
|
1329
|
+
case "medium":
|
|
1330
|
+
return "500";
|
|
1331
|
+
case "semibold":
|
|
1332
|
+
return "600";
|
|
1333
|
+
case "bold":
|
|
1334
|
+
return "700";
|
|
1335
|
+
case "extrabold":
|
|
1336
|
+
return "800";
|
|
1337
|
+
default:
|
|
1338
|
+
return null;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
// src/jsEngine/resolvers/effects.ts
|
|
1343
|
+
function nativeShadowValue(key) {
|
|
1344
|
+
switch (key) {
|
|
1345
|
+
case "sm":
|
|
1346
|
+
return { offsetY: 1, radius: 2, opacity: 0.05, elevation: 1 };
|
|
1347
|
+
case "DEFAULT":
|
|
1348
|
+
return { offsetY: 1, radius: 3, opacity: 0.1, elevation: 2 };
|
|
1349
|
+
case "md":
|
|
1350
|
+
return { offsetY: 4, radius: 6, opacity: 0.1, elevation: 4 };
|
|
1351
|
+
case "lg":
|
|
1352
|
+
return { offsetY: 10, radius: 15, opacity: 0.1, elevation: 8 };
|
|
1353
|
+
case "xl":
|
|
1354
|
+
return { offsetY: 20, radius: 25, opacity: 0.1, elevation: 12 };
|
|
1355
|
+
case "2xl":
|
|
1356
|
+
return { offsetY: 25, radius: 50, opacity: 0.25, elevation: 16 };
|
|
1357
|
+
case "none":
|
|
1358
|
+
return { offsetY: 0, radius: 0, opacity: 0, elevation: 0 };
|
|
1359
|
+
default:
|
|
1360
|
+
return null;
|
|
1361
|
+
}
|
|
392
1362
|
}
|
|
393
|
-
function
|
|
394
|
-
|
|
1363
|
+
function nativeShadowDeclarations(parsed) {
|
|
1364
|
+
if (parsed.utility !== "shadow" || parsed.isArbitrary) return null;
|
|
1365
|
+
const key = parsed.value ?? "DEFAULT";
|
|
1366
|
+
const s = nativeShadowValue(key);
|
|
1367
|
+
if (s === null) return null;
|
|
1368
|
+
return [
|
|
1369
|
+
decl("shadow-color", "#000000"),
|
|
1370
|
+
decl("shadow-offset-x", "0"),
|
|
1371
|
+
decl("shadow-offset-y", String(s.offsetY)),
|
|
1372
|
+
decl("shadow-opacity", String(s.opacity)),
|
|
1373
|
+
decl("shadow-radius", String(s.radius)),
|
|
1374
|
+
decl("elevation", String(s.elevation))
|
|
1375
|
+
];
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
// src/jsEngine/resolveUtilityNative.ts
|
|
1379
|
+
function resolveTypographyNative(parsed) {
|
|
1380
|
+
switch (parsed.utility) {
|
|
1381
|
+
case "font": {
|
|
1382
|
+
if (parsed.value === null) return null;
|
|
1383
|
+
const w = fontWeight(parsed.value);
|
|
1384
|
+
return w === null ? null : [decl("font-weight", w)];
|
|
1385
|
+
}
|
|
1386
|
+
case "uppercase":
|
|
1387
|
+
return [decl("text-transform", "uppercase")];
|
|
1388
|
+
case "lowercase":
|
|
1389
|
+
return [decl("text-transform", "lowercase")];
|
|
1390
|
+
case "capitalize":
|
|
1391
|
+
return [decl("text-transform", "capitalize")];
|
|
1392
|
+
case "underline":
|
|
1393
|
+
return [decl("text-decoration-line", "underline")];
|
|
1394
|
+
case "line-through":
|
|
1395
|
+
return [decl("text-decoration-line", "line-through")];
|
|
1396
|
+
case "no-underline":
|
|
1397
|
+
return [decl("text-decoration-line", "none")];
|
|
1398
|
+
case "italic":
|
|
1399
|
+
return [decl("font-style", "italic")];
|
|
1400
|
+
case "not-italic":
|
|
1401
|
+
return [decl("font-style", "normal")];
|
|
1402
|
+
default:
|
|
1403
|
+
return null;
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
function resolveLeadingTrackingNative(parsed) {
|
|
1407
|
+
const value = parsed.value;
|
|
1408
|
+
if (value === null) return null;
|
|
1409
|
+
if (parsed.utility === "leading") {
|
|
1410
|
+
if (parsed.isArbitrary) return [decl("line-height", value)];
|
|
1411
|
+
const v = lineHeightSize(value);
|
|
1412
|
+
return v === null ? null : [decl("line-height", v)];
|
|
1413
|
+
}
|
|
1414
|
+
if (parsed.utility === "tracking" && parsed.isArbitrary) {
|
|
1415
|
+
return [decl("letter-spacing", value)];
|
|
1416
|
+
}
|
|
1417
|
+
return null;
|
|
1418
|
+
}
|
|
1419
|
+
function nativeHexColor(parsed, theme) {
|
|
1420
|
+
return colorValue(theme, parsed);
|
|
1421
|
+
}
|
|
1422
|
+
function resolveTextNative(parsed, theme) {
|
|
1423
|
+
if (!parsed.isArbitrary && parsed.value !== null) {
|
|
1424
|
+
const size = textSize(parsed.value);
|
|
1425
|
+
if (size !== null) return [decl("font-size", size)];
|
|
1426
|
+
const align = textAlign(parsed.value);
|
|
1427
|
+
if (align !== null) return [decl("text-align", align)];
|
|
1428
|
+
}
|
|
1429
|
+
const hex = nativeHexColor(parsed, theme);
|
|
1430
|
+
return hex === null ? null : [decl("color", hex)];
|
|
1431
|
+
}
|
|
1432
|
+
function resolveColorNative(parsed, theme) {
|
|
1433
|
+
switch (parsed.utility) {
|
|
1434
|
+
case "bg": {
|
|
1435
|
+
const hex = nativeHexColor(parsed, theme);
|
|
1436
|
+
return hex === null ? null : [decl("background-color", hex)];
|
|
1437
|
+
}
|
|
1438
|
+
case "text":
|
|
1439
|
+
return resolveTextNative(parsed, theme);
|
|
1440
|
+
default:
|
|
1441
|
+
return null;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
function resolveUtilityNative(parsed, theme) {
|
|
1445
|
+
return resolveFlex(parsed, false) ?? resolve(parsed, theme) ?? resolve2(parsed, theme) ?? resolve3(parsed, theme) ?? resolveColorNative(parsed, theme) ?? resolveLeadingTrackingNative(parsed) ?? resolveTypographyNative(parsed) ?? nativeShadowDeclarations(parsed);
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
// src/jsEngine/resolveStyle.ts
|
|
1449
|
+
var RESPONSIVE_BREAKPOINTS = /* @__PURE__ */ new Set(["sm", "md", "lg", "xl", "2xl"]);
|
|
1450
|
+
function nativeModifierState(modifier, theme, colorScheme, pressed, width) {
|
|
1451
|
+
if (modifier === "dark") return colorScheme === "dark";
|
|
1452
|
+
if (modifier === "active") return pressed;
|
|
1453
|
+
if (RESPONSIVE_BREAKPOINTS.has(modifier)) {
|
|
1454
|
+
const minWidth = theme.screens[modifier];
|
|
1455
|
+
if (minWidth === void 0) return null;
|
|
1456
|
+
return width >= minWidth;
|
|
1457
|
+
}
|
|
1458
|
+
return null;
|
|
395
1459
|
}
|
|
1460
|
+
function kebabToCamel(s) {
|
|
1461
|
+
return s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
1462
|
+
}
|
|
1463
|
+
var NUMERIC_LENGTH_PROPS = /* @__PURE__ */ new Set([
|
|
1464
|
+
"padding",
|
|
1465
|
+
"padding-top",
|
|
1466
|
+
"padding-right",
|
|
1467
|
+
"padding-bottom",
|
|
1468
|
+
"padding-left",
|
|
1469
|
+
"margin",
|
|
1470
|
+
"margin-top",
|
|
1471
|
+
"margin-right",
|
|
1472
|
+
"margin-bottom",
|
|
1473
|
+
"margin-left",
|
|
1474
|
+
"gap",
|
|
1475
|
+
"column-gap",
|
|
1476
|
+
"row-gap",
|
|
1477
|
+
"width",
|
|
1478
|
+
"height",
|
|
1479
|
+
"min-width",
|
|
1480
|
+
"max-width",
|
|
1481
|
+
"min-height",
|
|
1482
|
+
"max-height",
|
|
1483
|
+
"top",
|
|
1484
|
+
"right",
|
|
1485
|
+
"bottom",
|
|
1486
|
+
"left",
|
|
1487
|
+
"inset",
|
|
1488
|
+
"border-radius",
|
|
1489
|
+
"border-width",
|
|
1490
|
+
"font-size",
|
|
1491
|
+
"z-index",
|
|
1492
|
+
"line-height",
|
|
1493
|
+
"letter-spacing",
|
|
1494
|
+
"flex",
|
|
1495
|
+
"flex-grow",
|
|
1496
|
+
"flex-shrink",
|
|
1497
|
+
"order",
|
|
1498
|
+
"flex-basis",
|
|
1499
|
+
"shadow-opacity",
|
|
1500
|
+
"shadow-radius",
|
|
1501
|
+
"elevation",
|
|
1502
|
+
// Per-side border width + per-corner radius — see resolvers/border.ts's
|
|
1503
|
+
// new borderSideValue/borderAxisValue/resolveRadiusSide additions; RN's
|
|
1504
|
+
// style system wants plain numbers for these exactly like the generic
|
|
1505
|
+
// "border-width"/"border-radius" forms above.
|
|
1506
|
+
"border-top-width",
|
|
1507
|
+
"border-right-width",
|
|
1508
|
+
"border-bottom-width",
|
|
1509
|
+
"border-left-width",
|
|
1510
|
+
"border-top-left-radius",
|
|
1511
|
+
"border-top-right-radius",
|
|
1512
|
+
"border-bottom-right-radius",
|
|
1513
|
+
"border-bottom-left-radius",
|
|
1514
|
+
"outline-width",
|
|
1515
|
+
"outline-offset"
|
|
1516
|
+
]);
|
|
1517
|
+
function isPlainPercentage(value) {
|
|
1518
|
+
if (!value.endsWith("%")) return false;
|
|
1519
|
+
let digits = value.slice(0, -1);
|
|
1520
|
+
if (digits.startsWith("-")) digits = digits.slice(1);
|
|
1521
|
+
return digits.length > 0 && /^[0-9.]+$/.test(digits);
|
|
1522
|
+
}
|
|
1523
|
+
function rnStyleValue(property, value) {
|
|
1524
|
+
if (!NUMERIC_LENGTH_PROPS.has(property)) {
|
|
1525
|
+
return { value, warning: null };
|
|
1526
|
+
}
|
|
1527
|
+
let px = null;
|
|
1528
|
+
if (value.endsWith("px")) {
|
|
1529
|
+
const n = Number(value.slice(0, -2));
|
|
1530
|
+
px = Number.isFinite(n) ? n : null;
|
|
1531
|
+
} else if (value.endsWith("rem")) {
|
|
1532
|
+
const n = Number(value.slice(0, -3));
|
|
1533
|
+
px = Number.isFinite(n) ? n * 16 : null;
|
|
1534
|
+
} else {
|
|
1535
|
+
const n = Number(value);
|
|
1536
|
+
px = value.trim() !== "" && Number.isFinite(n) ? n : null;
|
|
1537
|
+
}
|
|
1538
|
+
if (px !== null) return { value: px, warning: null };
|
|
1539
|
+
if (isPlainPercentage(value)) {
|
|
1540
|
+
return { value, warning: null };
|
|
1541
|
+
}
|
|
1542
|
+
const reduced = reduceConstantMath(value);
|
|
1543
|
+
if (reduced !== null) {
|
|
1544
|
+
return { value: reduced, warning: null };
|
|
1545
|
+
}
|
|
1546
|
+
const warning = `Kbach: "${value}" is not a valid native value for "${property}" \u2014 dropped. calc()/clamp()/min()/max() only resolve on native when every operand is a constant px/rem length (no %, vw, vh, var(), or other viewport/CSS-variable units \u2014 those need real layout/DOM, which doesn't exist on native at paint time). Use a plain px/rem calc, a fraction utility (e.g. w-1/2), or resolve this value in JS instead.`;
|
|
1547
|
+
return { value: null, warning };
|
|
1548
|
+
}
|
|
1549
|
+
function resolveStyleJsWithWarnings(classString, theme, colorScheme, pressed, width) {
|
|
1550
|
+
const style = {};
|
|
1551
|
+
const warnings = [];
|
|
1552
|
+
let shadowOffset = null;
|
|
1553
|
+
for (const token of classString.split(/\s+/).filter(Boolean)) {
|
|
1554
|
+
const parsed = parseClass(token);
|
|
1555
|
+
const allModifiersHold = parsed.modifiers.every(
|
|
1556
|
+
(m) => nativeModifierState(m, theme, colorScheme, pressed, width) === true
|
|
1557
|
+
);
|
|
1558
|
+
if (!allModifiersHold) continue;
|
|
1559
|
+
const decls = resolveUtilityNative(parsed, theme);
|
|
1560
|
+
if (decls === null) continue;
|
|
1561
|
+
for (const d of decls) {
|
|
1562
|
+
if (d.property.startsWith("__")) {
|
|
1563
|
+
continue;
|
|
1564
|
+
}
|
|
1565
|
+
if (d.property === "shadow-offset-x" || d.property === "shadow-offset-y") {
|
|
1566
|
+
const n = Number(d.value);
|
|
1567
|
+
if (!Number.isFinite(n)) continue;
|
|
1568
|
+
if (shadowOffset === null) shadowOffset = {};
|
|
1569
|
+
shadowOffset[d.property === "shadow-offset-x" ? "width" : "height"] = n;
|
|
1570
|
+
continue;
|
|
1571
|
+
}
|
|
1572
|
+
const { value, warning } = rnStyleValue(d.property, d.value);
|
|
1573
|
+
if (warning !== null) warnings.push(warning);
|
|
1574
|
+
if (value !== null) style[kebabToCamel(d.property)] = value;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
if (shadowOffset !== null) {
|
|
1578
|
+
style.shadowOffset = { width: shadowOffset.width ?? 0, height: shadowOffset.height ?? 0 };
|
|
1579
|
+
}
|
|
1580
|
+
return { style, warnings };
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// src/nativeBridge.ts
|
|
1584
|
+
function resolveStyle(classString, pressed = false) {
|
|
1585
|
+
const colorScheme = (0, import_darkModeStore2.getGlobalDarkMode)() ? "dark" : "light";
|
|
1586
|
+
const width = import_react_native2.Dimensions.get("window").width;
|
|
1587
|
+
const KbachModule = import_react_native2.TurboModuleRegistry.get("KbachModule");
|
|
1588
|
+
if (!KbachModule) {
|
|
1589
|
+
const { style: style2, warnings: warnings2 } = resolveStyleJsWithWarnings(classString, (0, import_theme2.getTheme)(), colorScheme, pressed, width);
|
|
1590
|
+
warnIfDev(classString, warnings2);
|
|
1591
|
+
return style2;
|
|
1592
|
+
}
|
|
1593
|
+
const json = KbachModule.resolveStyle(classString, (0, import_theme2.getThemeJson)(), colorScheme, pressed, width);
|
|
1594
|
+
const style = JSON.parse(json);
|
|
1595
|
+
const warnings = style.__kbachWarnings;
|
|
1596
|
+
if (warnings !== void 0) {
|
|
1597
|
+
delete style.__kbachWarnings;
|
|
1598
|
+
warnIfDev(classString, warnings);
|
|
1599
|
+
}
|
|
1600
|
+
return style;
|
|
1601
|
+
}
|
|
1602
|
+
var warnedMessages = /* @__PURE__ */ new Set();
|
|
1603
|
+
function warnIfDev(classString, warnings) {
|
|
1604
|
+
if (warnings.length === 0) return;
|
|
1605
|
+
if (typeof __DEV__ !== "undefined" && !__DEV__) return;
|
|
1606
|
+
for (const warning of warnings) {
|
|
1607
|
+
const message = `${warning} (from className "${classString}")`;
|
|
1608
|
+
if (warnedMessages.has(message)) continue;
|
|
1609
|
+
warnedMessages.add(message);
|
|
1610
|
+
console.warn(message);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
// src/jsx-runtime.tsx
|
|
1615
|
+
var { jsx, jsxs } = createJsxFunctions(resolveStyle);
|
|
396
1616
|
// Annotate the CommonJS export names for ESM import in node:
|
|
397
1617
|
0 && (module.exports = {
|
|
398
1618
|
Fragment,
|