@kbach/react-native 1.0.0-beta.56 → 1.0.0-beta.58
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/AGENTS.md +17 -4
- package/README.md +40 -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-APVTYFEK.mjs +623 -0
- package/dist/{chunk-YDA2XA35.mjs → chunk-PLSCNADJ.mjs} +1 -1
- package/dist/{chunk-VWGUF2NB.mjs → chunk-T6YWFA2C.mjs} +1 -1
- package/dist/index.js +210 -43
- package/dist/index.web.js +1 -1
- package/dist/index.web.mjs +2 -2
- package/dist/jsx-dev-runtime.js +924 -757
- package/dist/jsx-dev-runtime.web.js +1 -1
- package/dist/jsx-dev-runtime.web.mjs +3 -3
- package/dist/jsx-runtime.js +924 -757
- package/dist/jsx-runtime.web.js +1 -1
- package/dist/jsx-runtime.web.mjs +2 -2
- package/dist/theme.js +48 -0
- package/llms.txt +37 -0
- package/package.json +2 -1
- package/dist/chunk-4WQ2DOOC.mjs +0 -575
package/dist/jsx-runtime.js
CHANGED
|
@@ -33,810 +33,887 @@ var import_react_native = require("react-native");
|
|
|
33
33
|
var import_darkModeStore = require("./darkModeStore");
|
|
34
34
|
var import_theme = require("./theme");
|
|
35
35
|
|
|
36
|
-
// src/jsEngine/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
// src/jsEngine/parser.ts
|
|
37
|
+
var VALUE_PREFIXES = [
|
|
38
|
+
"bg-opacity-",
|
|
39
|
+
"text-opacity-",
|
|
40
|
+
"bg-blend-",
|
|
41
|
+
"text-shadow-",
|
|
42
|
+
"bg-",
|
|
43
|
+
"text-",
|
|
44
|
+
"border-x-",
|
|
45
|
+
"border-y-",
|
|
46
|
+
"border-t-",
|
|
47
|
+
"border-r-",
|
|
48
|
+
"border-b-",
|
|
49
|
+
"border-l-",
|
|
50
|
+
"border-",
|
|
51
|
+
"caret-",
|
|
52
|
+
"accent-",
|
|
53
|
+
"fill-",
|
|
54
|
+
"stroke-width-",
|
|
55
|
+
"stroke-",
|
|
56
|
+
"resize-",
|
|
57
|
+
"touch-",
|
|
58
|
+
"will-change-",
|
|
59
|
+
"scroll-mx-",
|
|
60
|
+
"scroll-my-",
|
|
61
|
+
"scroll-mt-",
|
|
62
|
+
"scroll-mr-",
|
|
63
|
+
"scroll-mb-",
|
|
64
|
+
"scroll-ml-",
|
|
65
|
+
"scroll-m-",
|
|
66
|
+
"scroll-px-",
|
|
67
|
+
"scroll-py-",
|
|
68
|
+
"scroll-pt-",
|
|
69
|
+
"scroll-pr-",
|
|
70
|
+
"scroll-pb-",
|
|
71
|
+
"scroll-pl-",
|
|
72
|
+
"scroll-p-",
|
|
73
|
+
"px-",
|
|
74
|
+
"py-",
|
|
75
|
+
"pt-",
|
|
76
|
+
"pr-",
|
|
77
|
+
"pb-",
|
|
78
|
+
"pl-",
|
|
79
|
+
"p-",
|
|
80
|
+
"mx-",
|
|
81
|
+
"my-",
|
|
82
|
+
"mt-",
|
|
83
|
+
"mr-",
|
|
84
|
+
"mb-",
|
|
85
|
+
"ml-",
|
|
86
|
+
"m-",
|
|
87
|
+
"gap-x-",
|
|
88
|
+
"gap-y-",
|
|
89
|
+
"gap-",
|
|
90
|
+
"min-w-",
|
|
91
|
+
"max-w-",
|
|
92
|
+
"w-",
|
|
93
|
+
"min-h-",
|
|
94
|
+
"max-h-",
|
|
95
|
+
"h-",
|
|
96
|
+
"size-",
|
|
97
|
+
"basis-",
|
|
98
|
+
"rounded-tl-",
|
|
99
|
+
"rounded-tr-",
|
|
100
|
+
"rounded-br-",
|
|
101
|
+
"rounded-bl-",
|
|
102
|
+
"rounded-t-",
|
|
103
|
+
"rounded-r-",
|
|
104
|
+
"rounded-b-",
|
|
105
|
+
"rounded-l-",
|
|
106
|
+
"rounded-",
|
|
107
|
+
"ring-offset-",
|
|
108
|
+
"ring-",
|
|
109
|
+
"outline-offset-",
|
|
110
|
+
"outline-",
|
|
111
|
+
"shadow-",
|
|
112
|
+
"opacity-",
|
|
113
|
+
"duration-",
|
|
114
|
+
"delay-",
|
|
115
|
+
"ease-",
|
|
116
|
+
"cursor-",
|
|
117
|
+
"mix-blend-",
|
|
118
|
+
"animate-",
|
|
119
|
+
"leading-",
|
|
120
|
+
"tracking-",
|
|
121
|
+
"font-",
|
|
122
|
+
"align-",
|
|
123
|
+
"z-",
|
|
124
|
+
"inset-x-",
|
|
125
|
+
"inset-y-",
|
|
126
|
+
"inset-",
|
|
127
|
+
"top-",
|
|
128
|
+
"right-",
|
|
129
|
+
"bottom-",
|
|
130
|
+
"left-",
|
|
131
|
+
"start-",
|
|
132
|
+
"end-",
|
|
133
|
+
"overflow-x-",
|
|
134
|
+
"overflow-y-",
|
|
135
|
+
"overscroll-x-",
|
|
136
|
+
"overscroll-y-",
|
|
137
|
+
"overscroll-",
|
|
138
|
+
"aspect-",
|
|
139
|
+
"divide-color-",
|
|
140
|
+
"space-x-",
|
|
141
|
+
"space-y-",
|
|
142
|
+
"flex-",
|
|
143
|
+
"grow-",
|
|
144
|
+
"shrink-",
|
|
145
|
+
"order-",
|
|
146
|
+
"grid-cols-",
|
|
147
|
+
"grid-rows-",
|
|
148
|
+
"grid-flow-",
|
|
149
|
+
"auto-cols-",
|
|
150
|
+
"auto-rows-",
|
|
151
|
+
"col-span-",
|
|
152
|
+
"col-start-",
|
|
153
|
+
"col-end-",
|
|
154
|
+
"col-",
|
|
155
|
+
"row-span-",
|
|
156
|
+
"row-start-",
|
|
157
|
+
"row-end-",
|
|
158
|
+
"row-",
|
|
159
|
+
"place-items-",
|
|
160
|
+
"place-content-",
|
|
161
|
+
"place-self-",
|
|
162
|
+
"justify-items-",
|
|
163
|
+
"justify-self-",
|
|
164
|
+
"scale-x-",
|
|
165
|
+
"scale-y-",
|
|
166
|
+
"scale-z-",
|
|
167
|
+
"scale-",
|
|
168
|
+
"rotate-x-",
|
|
169
|
+
"rotate-y-",
|
|
170
|
+
"rotate-z-",
|
|
171
|
+
"rotate-",
|
|
172
|
+
// Bare 'translate-'/'skew-' (both axes) after their per-axis forms, same
|
|
173
|
+
// longer-before-shorter rule as resolvers/parser.rs.
|
|
174
|
+
"translate-x-",
|
|
175
|
+
"translate-y-",
|
|
176
|
+
"translate-z-",
|
|
177
|
+
"translate-",
|
|
178
|
+
"skew-x-",
|
|
179
|
+
"skew-y-",
|
|
180
|
+
"skew-",
|
|
181
|
+
"perspective-origin-",
|
|
182
|
+
"perspective-",
|
|
183
|
+
"origin-",
|
|
184
|
+
"blur-",
|
|
185
|
+
"brightness-",
|
|
186
|
+
"contrast-",
|
|
187
|
+
"grayscale-",
|
|
188
|
+
"hue-rotate-",
|
|
189
|
+
"invert-",
|
|
190
|
+
"saturate-",
|
|
191
|
+
"sepia-",
|
|
192
|
+
"drop-shadow-",
|
|
193
|
+
"filter-",
|
|
194
|
+
"backdrop-blur-",
|
|
195
|
+
"backdrop-brightness-",
|
|
196
|
+
"backdrop-contrast-",
|
|
197
|
+
"backdrop-grayscale-",
|
|
198
|
+
"backdrop-hue-rotate-",
|
|
199
|
+
"backdrop-invert-",
|
|
200
|
+
"backdrop-opacity-",
|
|
201
|
+
"backdrop-saturate-",
|
|
202
|
+
"backdrop-sepia-",
|
|
203
|
+
"backdrop-filter-",
|
|
204
|
+
"decoration-",
|
|
205
|
+
"underline-offset-",
|
|
206
|
+
"indent-",
|
|
207
|
+
"from-",
|
|
208
|
+
"via-",
|
|
209
|
+
"to-"
|
|
210
|
+
];
|
|
211
|
+
var ARBITRARY_PROPERTY_SENTINEL = "[arbitrary-property]";
|
|
212
|
+
function isSafeArbitraryValue(value) {
|
|
213
|
+
return !value.includes("{") && !value.includes("}") && !value.includes(";");
|
|
40
214
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
215
|
+
function normalizeMathWhitespace(raw) {
|
|
216
|
+
if (!(raw.startsWith("calc(") || raw.startsWith("min(") || raw.startsWith("max(") || raw.startsWith("clamp("))) {
|
|
217
|
+
return raw;
|
|
218
|
+
}
|
|
219
|
+
const chars = Array.from(raw);
|
|
220
|
+
let out = "";
|
|
221
|
+
let i = 0;
|
|
222
|
+
let prevEndsValue = false;
|
|
223
|
+
while (i < chars.length) {
|
|
224
|
+
const c = chars[i];
|
|
225
|
+
if (c === "v" && chars[i + 1] === "a" && chars[i + 2] === "r" && chars[i + 3] === "(") {
|
|
226
|
+
const start = i;
|
|
227
|
+
let depth = 0;
|
|
228
|
+
while (i < chars.length) {
|
|
229
|
+
if (chars[i] === "(") depth++;
|
|
230
|
+
else if (chars[i] === ")") {
|
|
231
|
+
depth--;
|
|
232
|
+
if (depth === 0) {
|
|
233
|
+
i++;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
i++;
|
|
238
|
+
}
|
|
239
|
+
out += chars.slice(start, i).join("");
|
|
240
|
+
prevEndsValue = true;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (c === "+" || c === "-") {
|
|
244
|
+
if (prevEndsValue) {
|
|
245
|
+
out += ` ${c} `;
|
|
246
|
+
i++;
|
|
247
|
+
while (i < chars.length && /\s/.test(chars[i])) i++;
|
|
248
|
+
prevEndsValue = false;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
out += c;
|
|
252
|
+
prevEndsValue = false;
|
|
253
|
+
} else if (c === "(" || c === ",") {
|
|
254
|
+
out += c;
|
|
255
|
+
if (c === ",") out += " ";
|
|
256
|
+
prevEndsValue = false;
|
|
257
|
+
} else if (c === ")") {
|
|
258
|
+
out += c;
|
|
259
|
+
prevEndsValue = true;
|
|
260
|
+
} else if (/\s/.test(c)) {
|
|
261
|
+
} else if (c === "*" || c === "/") {
|
|
262
|
+
out += c;
|
|
263
|
+
prevEndsValue = false;
|
|
264
|
+
} else {
|
|
265
|
+
out += c;
|
|
266
|
+
prevEndsValue = true;
|
|
51
267
|
}
|
|
268
|
+
i++;
|
|
52
269
|
}
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
function applyOpacityToHex(hex, opacity) {
|
|
56
|
-
if (opacity === null) return hex;
|
|
57
|
-
const rgb = hexToRgb(hex);
|
|
58
|
-
if (rgb === null) return hex;
|
|
59
|
-
return `rgba(${rgb.join(",")},${opacity / 100})`;
|
|
270
|
+
return out;
|
|
60
271
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
272
|
+
var TYPE_HINTS = /* @__PURE__ */ new Set([
|
|
273
|
+
"color",
|
|
274
|
+
"length",
|
|
275
|
+
"size",
|
|
276
|
+
"line-width",
|
|
277
|
+
"percentage",
|
|
278
|
+
"number",
|
|
279
|
+
"integer",
|
|
280
|
+
"image",
|
|
281
|
+
"url",
|
|
282
|
+
"position",
|
|
283
|
+
"bg-size",
|
|
284
|
+
"family-name",
|
|
285
|
+
"generic-name",
|
|
286
|
+
"absolute-size",
|
|
287
|
+
"relative-size",
|
|
288
|
+
"angle",
|
|
289
|
+
"shadow",
|
|
290
|
+
"any"
|
|
291
|
+
]);
|
|
292
|
+
function arbitraryModifier(modifier) {
|
|
293
|
+
const bracketed = parenVarShorthand(modifier) ?? modifier;
|
|
294
|
+
if (!(bracketed.length > 2 && bracketed.startsWith("[") && bracketed.endsWith("]"))) return null;
|
|
295
|
+
const raw = bracketed.slice(1, -1);
|
|
296
|
+
if (!isSafeArbitraryValue(raw)) return null;
|
|
297
|
+
return normalizeMathWhitespace(raw.replace(/_/g, " "));
|
|
69
298
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const base = segments.pop() ?? rawToken;
|
|
75
|
-
return findModeAwareColor(base, theme) !== null;
|
|
76
|
-
});
|
|
299
|
+
function splitTypeHint(raw) {
|
|
300
|
+
const i = raw.indexOf(":");
|
|
301
|
+
if (i > 0 && i < raw.length - 1 && TYPE_HINTS.has(raw.slice(0, i))) return [raw.slice(0, i), raw.slice(i + 1)];
|
|
302
|
+
return [null, raw];
|
|
77
303
|
}
|
|
78
|
-
function
|
|
79
|
-
const m =
|
|
304
|
+
function parenVarShorthand(value) {
|
|
305
|
+
const m = /^\((?:([a-z-]+):)?--([A-Za-z0-9_-]+)\)(\/.*)?$/.exec(value);
|
|
80
306
|
if (!m) return null;
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
function colorValue(theme, parsed) {
|
|
97
|
-
const value = parsed.value;
|
|
98
|
-
if (value === null) return null;
|
|
99
|
-
if (parsed.isArbitrary) return value;
|
|
100
|
-
const [name, opacity] = splitOpacity(value);
|
|
101
|
-
const hex = lookupHex(theme, name);
|
|
102
|
-
if (hex === null) return null;
|
|
103
|
-
if (opacity === null) return hex;
|
|
104
|
-
const rgb = hexToRgb(hex);
|
|
105
|
-
if (rgb === null) return hex;
|
|
106
|
-
return `rgba(${rgb.join(",")},${opacity / 100})`;
|
|
107
|
-
}
|
|
108
|
-
var LENGTH_UNITS = ["px", "rem", "em", "%", "vh", "vw"];
|
|
109
|
-
function looksLikeLength(value) {
|
|
110
|
-
const unit = LENGTH_UNITS.find((u) => value.endsWith(u));
|
|
111
|
-
const withoutUnit = unit ? value.slice(0, value.length - unit.length) : value;
|
|
112
|
-
if (withoutUnit !== "" && Number.isFinite(Number(withoutUnit))) return true;
|
|
113
|
-
if (!["calc(", "clamp(", "min(", "max("].some((f) => value.startsWith(f))) return false;
|
|
114
|
-
return MATH_LENGTH_UNIT.test(value);
|
|
115
|
-
}
|
|
116
|
-
var MATH_LENGTH_UNIT = /\d(?:px|rem|em|%|vh|vw|vmin|vmax|dvh|dvw|svh|svw|lvh|lvw|ch|ex|lh|cqw|cqh|cqi|cqb)(?![A-Za-z])/;
|
|
117
|
-
function isLength(parsed, value) {
|
|
118
|
-
switch (parsed.typeHint ?? null) {
|
|
119
|
-
case null:
|
|
120
|
-
return looksLikeLength(value);
|
|
121
|
-
case "length":
|
|
122
|
-
case "size":
|
|
123
|
-
case "line-width":
|
|
124
|
-
case "percentage":
|
|
125
|
-
case "number":
|
|
126
|
-
case "integer":
|
|
127
|
-
case "absolute-size":
|
|
128
|
-
case "relative-size":
|
|
129
|
-
return true;
|
|
130
|
-
default:
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// src/jsxRuntimeCore.ts
|
|
136
|
-
var import_dynamicTokens = require("./dynamicTokens");
|
|
137
|
-
|
|
138
|
-
// src/jsEngine/calc.ts
|
|
139
|
-
function reduceConstantMath(raw) {
|
|
140
|
-
const trimmed = raw.trim();
|
|
141
|
-
const calc = stripCall(trimmed, "calc");
|
|
142
|
-
if (calc !== null) {
|
|
143
|
-
return new Evaluator(calc).parseExprToEnd();
|
|
144
|
-
}
|
|
145
|
-
const clamp = stripCall(trimmed, "clamp");
|
|
146
|
-
if (clamp !== null) {
|
|
147
|
-
const args = splitTopLevelCommas(clamp);
|
|
148
|
-
if (args.length !== 3) return null;
|
|
149
|
-
const [min2, preferred, max2] = args.map((a) => new Evaluator(a).parseExprToEnd());
|
|
150
|
-
if (min2 === null || preferred === null || max2 === null) return null;
|
|
151
|
-
return Math.max(min2, Math.min(preferred, max2));
|
|
152
|
-
}
|
|
153
|
-
const min = stripCall(trimmed, "min");
|
|
154
|
-
if (min !== null) {
|
|
155
|
-
const values = splitTopLevelCommas(min).map((a) => new Evaluator(a).parseExprToEnd());
|
|
156
|
-
return values.some((v) => v === null) ? null : Math.min(...values);
|
|
157
|
-
}
|
|
158
|
-
const max = stripCall(trimmed, "max");
|
|
159
|
-
if (max !== null) {
|
|
160
|
-
const values = splitTopLevelCommas(max).map((a) => new Evaluator(a).parseExprToEnd());
|
|
161
|
-
return values.some((v) => v === null) ? null : Math.max(...values);
|
|
162
|
-
}
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
function stripCall(raw, name) {
|
|
166
|
-
if (!raw.startsWith(name)) return null;
|
|
167
|
-
const afterName = raw.slice(name.length).trimStart();
|
|
168
|
-
if (!afterName.startsWith("(") || !afterName.endsWith(")")) return null;
|
|
169
|
-
return afterName.slice(1, -1);
|
|
170
|
-
}
|
|
171
|
-
function splitTopLevelCommas(s) {
|
|
172
|
-
const parts = [];
|
|
173
|
-
let depth = 0;
|
|
174
|
-
let start = 0;
|
|
175
|
-
for (let i = 0; i < s.length; i++) {
|
|
176
|
-
const ch = s[i];
|
|
177
|
-
if (ch === "(") depth++;
|
|
178
|
-
else if (ch === ")") depth--;
|
|
179
|
-
else if (ch === "," && depth === 0) {
|
|
180
|
-
parts.push(s.slice(start, i).trim());
|
|
181
|
-
start = i + 1;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
parts.push(s.slice(start).trim());
|
|
185
|
-
return parts;
|
|
186
|
-
}
|
|
187
|
-
var Evaluator = class {
|
|
188
|
-
constructor(s) {
|
|
189
|
-
this.pos = 0;
|
|
190
|
-
this.s = s;
|
|
191
|
-
}
|
|
192
|
-
parseExprToEnd() {
|
|
193
|
-
const value = this.expr();
|
|
194
|
-
if (value === null) return null;
|
|
195
|
-
this.skipWs();
|
|
196
|
-
return this.pos === this.s.length ? value : null;
|
|
197
|
-
}
|
|
198
|
-
skipWs() {
|
|
199
|
-
while (this.pos < this.s.length && /\s/.test(this.s[this.pos])) this.pos++;
|
|
200
|
-
}
|
|
201
|
-
peek() {
|
|
202
|
-
this.skipWs();
|
|
203
|
-
return this.s[this.pos];
|
|
204
|
-
}
|
|
205
|
-
expr() {
|
|
206
|
-
let value = this.term();
|
|
207
|
-
if (value === null) return null;
|
|
208
|
-
for (; ; ) {
|
|
209
|
-
const ch = this.peek();
|
|
210
|
-
if (ch === "+") {
|
|
211
|
-
this.pos++;
|
|
212
|
-
const rhs = this.term();
|
|
213
|
-
if (rhs === null) return null;
|
|
214
|
-
value += rhs;
|
|
215
|
-
} else if (ch === "-") {
|
|
216
|
-
this.pos++;
|
|
217
|
-
const rhs = this.term();
|
|
218
|
-
if (rhs === null) return null;
|
|
219
|
-
value -= rhs;
|
|
220
|
-
} else {
|
|
221
|
-
return value;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
term() {
|
|
226
|
-
let value = this.factor();
|
|
227
|
-
if (value === null) return null;
|
|
228
|
-
for (; ; ) {
|
|
229
|
-
const ch = this.peek();
|
|
230
|
-
if (ch === "*") {
|
|
231
|
-
this.pos++;
|
|
232
|
-
const rhs = this.factor();
|
|
233
|
-
if (rhs === null) return null;
|
|
234
|
-
value *= rhs;
|
|
235
|
-
} else if (ch === "/") {
|
|
236
|
-
this.pos++;
|
|
237
|
-
const divisor = this.factor();
|
|
238
|
-
if (divisor === null || divisor === 0) return null;
|
|
239
|
-
value /= divisor;
|
|
240
|
-
} else {
|
|
241
|
-
return value;
|
|
307
|
+
const [, hint, name, tail = ""] = m;
|
|
308
|
+
if (hint !== void 0 && !TYPE_HINTS.has(hint)) return null;
|
|
309
|
+
return hint ? `[${hint}:var(--${name})]${tail}` : `[var(--${name})]${tail}`;
|
|
310
|
+
}
|
|
311
|
+
function splitBracketModifier(value) {
|
|
312
|
+
if (!value.startsWith("[")) return [value, null];
|
|
313
|
+
let depth = 0;
|
|
314
|
+
for (let i = 0; i < value.length; i++) {
|
|
315
|
+
const ch = value[i];
|
|
316
|
+
if (ch === "[") depth += 1;
|
|
317
|
+
else if (ch === "]") {
|
|
318
|
+
depth -= 1;
|
|
319
|
+
if (depth === 0) {
|
|
320
|
+
const after = value.slice(i + 1);
|
|
321
|
+
return after.startsWith("/") && after.length > 1 ? [value.slice(0, i + 1), after.slice(1)] : [value, null];
|
|
242
322
|
}
|
|
243
323
|
}
|
|
244
324
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
this.pos++;
|
|
257
|
-
const value = this.factor();
|
|
258
|
-
return value === null ? null : -value;
|
|
325
|
+
return [value, null];
|
|
326
|
+
}
|
|
327
|
+
function trimNumber(n) {
|
|
328
|
+
return `${Math.round(n * 1e6) / 1e6}`;
|
|
329
|
+
}
|
|
330
|
+
function parseAlpha(modifier) {
|
|
331
|
+
const raw = arbitraryModifier(modifier);
|
|
332
|
+
if (raw !== null) {
|
|
333
|
+
if (raw.endsWith("%")) {
|
|
334
|
+
const n3 = strictNumber(raw.slice(0, -1));
|
|
335
|
+
return n3 !== null && n3 >= 0 && n3 <= 100 ? { fraction: n3 / 100 } : null;
|
|
259
336
|
}
|
|
260
|
-
|
|
337
|
+
const n2 = strictNumber(raw);
|
|
338
|
+
if (n2 !== null) return n2 >= 0 && n2 <= 1 ? { fraction: n2 } : null;
|
|
339
|
+
return raw.startsWith("var(") || raw.startsWith("calc(") ? { raw } : null;
|
|
261
340
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
341
|
+
if (!/^(?:\d+\.?\d*|\.\d+)$/.test(modifier)) return null;
|
|
342
|
+
const n = Number(modifier);
|
|
343
|
+
return n <= 100 ? { fraction: n / 100 } : null;
|
|
344
|
+
}
|
|
345
|
+
function strictNumber(text) {
|
|
346
|
+
return /^[+-]?(?:\d+\.?\d*|\.\d+)$/.test(text) ? Number(text) : null;
|
|
347
|
+
}
|
|
348
|
+
function expandThemeFunctions(raw) {
|
|
349
|
+
if (!raw.includes("--spacing(") && !raw.includes("--alpha(")) return raw;
|
|
350
|
+
let out = "";
|
|
351
|
+
let rest = raw;
|
|
352
|
+
for (; ; ) {
|
|
353
|
+
const found = ["--spacing(", "--alpha("].map((name) => ({ name, at: rest.indexOf(name) })).filter((f) => f.at !== -1).sort((a, b) => a.at - b.at)[0];
|
|
354
|
+
if (found === void 0) break;
|
|
355
|
+
const argsFrom = found.at + found.name.length;
|
|
356
|
+
let depth = 1;
|
|
357
|
+
let close = -1;
|
|
358
|
+
for (let i = argsFrom; i < rest.length; i++) {
|
|
359
|
+
if (rest[i] === "(") depth += 1;
|
|
360
|
+
else if (rest[i] === ")") {
|
|
361
|
+
depth -= 1;
|
|
362
|
+
if (depth === 0) {
|
|
363
|
+
close = i;
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (close === -1) break;
|
|
369
|
+
const arg = expandThemeFunctions(rest.slice(argsFrom, close).trim());
|
|
370
|
+
out += rest.slice(0, found.at);
|
|
371
|
+
if (found.name === "--spacing(") {
|
|
372
|
+
const n = strictNumber(arg);
|
|
373
|
+
out += n !== null ? `${trimNumber(n * 4)}px` : `calc(4px * ${arg})`;
|
|
374
|
+
} else {
|
|
375
|
+
const slash = arg.lastIndexOf("/");
|
|
376
|
+
if (slash === -1) {
|
|
377
|
+
out += arg;
|
|
378
|
+
} else {
|
|
379
|
+
const alpha = arg.slice(slash + 1).trim();
|
|
380
|
+
const n = strictNumber(alpha);
|
|
381
|
+
out += `color-mix(in srgb, ${arg.slice(0, slash).trim()} ${n !== null ? `${trimNumber(n * 100)}%` : alpha}, transparent)`;
|
|
382
|
+
}
|
|
281
383
|
}
|
|
384
|
+
rest = rest.slice(close + 1);
|
|
282
385
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
// src/layoutCalc.ts
|
|
286
|
-
var NEG = (v) => ({ percent: -v.percent, px: -v.px });
|
|
287
|
-
var ADD = (a, b) => ({ percent: a.percent + b.percent, px: a.px + b.px });
|
|
288
|
-
var SUB = (a, b) => ({ percent: a.percent - b.percent, px: a.px - b.px });
|
|
289
|
-
function MUL(a, b) {
|
|
290
|
-
if (a.percent === 0) return { percent: b.percent * a.px, px: b.px * a.px };
|
|
291
|
-
if (b.percent === 0) return { percent: a.percent * b.px, px: a.px * b.px };
|
|
292
|
-
return null;
|
|
386
|
+
return out + rest;
|
|
293
387
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
return
|
|
388
|
+
var COLOR_FUNCTIONS = ["rgb(", "rgba(", "hsl(", "hsla(", "hwb(", "lab(", "lch(", "oklab(", "oklch(", "color(", "color-mix(", "var("];
|
|
389
|
+
function looksLikeColor(value) {
|
|
390
|
+
return value.startsWith("#") || COLOR_FUNCTIONS.some((f) => value.startsWith(f)) || /^[A-Za-z]+$/.test(value);
|
|
297
391
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
392
|
+
function colorWithOpacity(color, alpha) {
|
|
393
|
+
const m = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.exec(color);
|
|
394
|
+
if (m && "fraction" in alpha) {
|
|
395
|
+
const h = m[1].length === 3 ? m[1].split("").map((c) => c + c).join("") : m[1];
|
|
396
|
+
const [r, g, b] = [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
|
|
397
|
+
return `rgba(${r},${g},${b},${trimNumber(alpha.fraction)})`;
|
|
302
398
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
399
|
+
return `color-mix(in srgb, ${color} ${"fraction" in alpha ? `${trimNumber(alpha.fraction * 100)}%` : alpha.raw}, transparent)`;
|
|
400
|
+
}
|
|
401
|
+
function splitRespectingBrackets(token) {
|
|
402
|
+
const parts = [];
|
|
403
|
+
let depth = 0;
|
|
404
|
+
let start = 0;
|
|
405
|
+
for (let i = 0; i < token.length; i++) {
|
|
406
|
+
const ch = token[i];
|
|
407
|
+
if (ch === "[" || ch === "(") depth += 1;
|
|
408
|
+
else if (ch === "]" || ch === ")") depth -= 1;
|
|
409
|
+
else if (ch === ":" && depth <= 0) {
|
|
410
|
+
parts.push(token.slice(start, i));
|
|
411
|
+
start = i + 1;
|
|
412
|
+
}
|
|
308
413
|
}
|
|
309
|
-
|
|
310
|
-
|
|
414
|
+
parts.push(token.slice(start));
|
|
415
|
+
return parts;
|
|
416
|
+
}
|
|
417
|
+
function parseClass(token) {
|
|
418
|
+
const parts = splitRespectingBrackets(token);
|
|
419
|
+
let base = parts.pop() ?? token;
|
|
420
|
+
const modifiers = parts;
|
|
421
|
+
const important = base.startsWith("!") || base.length > 1 && base.endsWith("!");
|
|
422
|
+
if (base.startsWith("!")) {
|
|
423
|
+
base = base.slice(1);
|
|
424
|
+
} else if (important) {
|
|
425
|
+
base = base.slice(0, -1);
|
|
311
426
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
427
|
+
const negative = base.startsWith("-");
|
|
428
|
+
if (negative) {
|
|
429
|
+
base = base.slice(1);
|
|
315
430
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
431
|
+
if (base.length >= 2 && base.startsWith("[") && base.endsWith("]")) {
|
|
432
|
+
const raw = base.slice(1, -1);
|
|
433
|
+
const colonIdx = raw.indexOf(":");
|
|
434
|
+
if (colonIdx !== -1) {
|
|
435
|
+
const property = raw.slice(0, colonIdx);
|
|
436
|
+
const rawValue = raw.slice(colonIdx + 1);
|
|
437
|
+
if (property !== "" && rawValue !== "" && isSafeArbitraryValue(raw)) {
|
|
438
|
+
const value = normalizeMathWhitespace(expandThemeFunctions(rawValue.replace(/_/g, " ")));
|
|
439
|
+
return {
|
|
440
|
+
modifiers,
|
|
441
|
+
utility: ARBITRARY_PROPERTY_SENTINEL,
|
|
442
|
+
value: `${property}:${value}`,
|
|
443
|
+
isArbitrary: true,
|
|
444
|
+
important,
|
|
445
|
+
negative,
|
|
446
|
+
original: token
|
|
447
|
+
};
|
|
333
448
|
}
|
|
334
449
|
}
|
|
335
450
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const result = MUL(value, rhs);
|
|
346
|
-
if (result === null) return null;
|
|
347
|
-
value = result;
|
|
348
|
-
} else if (ch === "/") {
|
|
349
|
-
this.pos++;
|
|
350
|
-
const rhs = this.factor();
|
|
351
|
-
if (rhs === null) return null;
|
|
352
|
-
const result = DIV(value, rhs);
|
|
353
|
-
if (result === null) return null;
|
|
354
|
-
value = result;
|
|
355
|
-
} else {
|
|
356
|
-
return value;
|
|
451
|
+
for (const prefix of VALUE_PREFIXES) {
|
|
452
|
+
if (!base.startsWith(prefix)) continue;
|
|
453
|
+
const written = base.slice(prefix.length);
|
|
454
|
+
if (written === "") continue;
|
|
455
|
+
const [value, tail] = splitBracketModifier(parenVarShorthand(written) ?? written);
|
|
456
|
+
if (value.length >= 2 && value.startsWith("[") && value.endsWith("]")) {
|
|
457
|
+
const raw = value.slice(1, -1);
|
|
458
|
+
if (!isSafeArbitraryValue(raw)) {
|
|
459
|
+
continue;
|
|
357
460
|
}
|
|
461
|
+
const spaced = normalizeMathWhitespace(expandThemeFunctions(raw.replace(/_/g, " ")));
|
|
462
|
+
let [typeHint, hinted] = splitTypeHint(spaced);
|
|
463
|
+
let modifier = null;
|
|
464
|
+
if (tail !== null) {
|
|
465
|
+
const isColor = typeHint === "color" || typeHint === null && looksLikeColor(hinted);
|
|
466
|
+
const alpha = isColor ? parseAlpha(tail) : null;
|
|
467
|
+
if (alpha !== null) {
|
|
468
|
+
hinted = colorWithOpacity(hinted, alpha);
|
|
469
|
+
typeHint = "color";
|
|
470
|
+
} else if (prefix === "text-") {
|
|
471
|
+
modifier = tail;
|
|
472
|
+
} else {
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return {
|
|
477
|
+
modifiers,
|
|
478
|
+
utility: prefix.slice(0, -1),
|
|
479
|
+
value: hinted,
|
|
480
|
+
typeHint,
|
|
481
|
+
isArbitrary: true,
|
|
482
|
+
important,
|
|
483
|
+
negative,
|
|
484
|
+
original: token,
|
|
485
|
+
modifier
|
|
486
|
+
};
|
|
358
487
|
}
|
|
488
|
+
return {
|
|
489
|
+
modifiers,
|
|
490
|
+
utility: prefix.slice(0, -1),
|
|
491
|
+
// a named value keeps its own /opacity (`bg-blue-6/50`)
|
|
492
|
+
value: tail === null ? value : `${value}/${tail}`,
|
|
493
|
+
isArbitrary: false,
|
|
494
|
+
important,
|
|
495
|
+
negative,
|
|
496
|
+
original: token
|
|
497
|
+
};
|
|
359
498
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
if (
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
if (
|
|
385
|
-
|
|
386
|
-
return { percent: n, px: 0 };
|
|
387
|
-
}
|
|
388
|
-
const unitStart = this.pos;
|
|
389
|
-
while (this.pos < this.s.length && /[a-zA-Z]/.test(this.s[this.pos])) this.pos++;
|
|
390
|
-
const unit = this.s.slice(unitStart, this.pos);
|
|
391
|
-
switch (unit) {
|
|
392
|
-
case "":
|
|
393
|
-
return { percent: 0, px: n };
|
|
394
|
-
case "px":
|
|
395
|
-
return { percent: 0, px: n };
|
|
396
|
-
case "rem":
|
|
397
|
-
return { percent: 0, px: n * 16 };
|
|
398
|
-
default:
|
|
399
|
-
return null;
|
|
499
|
+
return {
|
|
500
|
+
modifiers,
|
|
501
|
+
utility: base,
|
|
502
|
+
value: null,
|
|
503
|
+
isArbitrary: false,
|
|
504
|
+
important,
|
|
505
|
+
negative,
|
|
506
|
+
original: token
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// src/jsEngine/resolvers/color.ts
|
|
511
|
+
function lookupHex(theme, key) {
|
|
512
|
+
const entry = theme.colors[key];
|
|
513
|
+
return typeof entry === "string" ? entry : null;
|
|
514
|
+
}
|
|
515
|
+
var MODE_AWARE_COLOR_PREFIXES = ["bg-", "text-", "border-"];
|
|
516
|
+
function findModeAwareColor(base, theme) {
|
|
517
|
+
const important = base.startsWith("!") ? "!" : "";
|
|
518
|
+
const rest = important ? base.slice(1) : base;
|
|
519
|
+
for (const prefix of MODE_AWARE_COLOR_PREFIXES) {
|
|
520
|
+
if (!rest.startsWith(prefix)) continue;
|
|
521
|
+
const [name, opacity] = splitOpacity(rest.slice(prefix.length));
|
|
522
|
+
const entry = theme.colors[name];
|
|
523
|
+
if (typeof entry === "object" && entry !== null) {
|
|
524
|
+
return { prefix: `${important}${prefix}`, opacity, light: entry.light, dark: entry.dark };
|
|
400
525
|
}
|
|
401
526
|
}
|
|
402
|
-
|
|
403
|
-
var PERCENT_TOKEN_OUTER_RE = /^(w|h)-\[(.+)\]$/;
|
|
404
|
-
function parsePercentRelativeCalc(token) {
|
|
405
|
-
const m = PERCENT_TOKEN_OUTER_RE.exec(token);
|
|
406
|
-
if (!m) return null;
|
|
407
|
-
const property = m[1] === "w" ? "width" : "height";
|
|
408
|
-
const inner = stripCall(m[2].replace(/_/g, " ").trim(), "calc");
|
|
409
|
-
if (inner === null) return null;
|
|
410
|
-
const result = new PercentAwareEvaluator(inner).parseExprToEnd();
|
|
411
|
-
if (result === null || result.percent === 0) return null;
|
|
412
|
-
return { property, percentCoefficient: result.percent, constantPx: result.px };
|
|
527
|
+
return null;
|
|
413
528
|
}
|
|
414
|
-
function
|
|
415
|
-
|
|
529
|
+
function applyOpacityToHex(hex, opacity) {
|
|
530
|
+
if (opacity === null) return hex;
|
|
531
|
+
if (hexToRgb(hex) === null) return hex;
|
|
532
|
+
return colorWithOpacity(hex.trim(), opacity).replace(/ /g, "_");
|
|
416
533
|
}
|
|
417
|
-
function
|
|
418
|
-
const
|
|
534
|
+
function substituteModeAwareColorToken(token, theme, colorScheme) {
|
|
535
|
+
const segments = token.split(":");
|
|
536
|
+
const base = segments.pop() ?? token;
|
|
537
|
+
const modifierPrefix = segments.length > 0 ? `${segments.join(":")}:` : "";
|
|
538
|
+
const found = findModeAwareColor(base, theme);
|
|
539
|
+
if (found === null) return token;
|
|
540
|
+
const hex = colorScheme === "dark" ? found.dark : found.light;
|
|
541
|
+
return `${modifierPrefix}${found.prefix}[${applyOpacityToHex(hex, found.opacity)}]`;
|
|
542
|
+
}
|
|
543
|
+
function classStringUsesModeAwareColor(classString, theme) {
|
|
544
|
+
return classString.split(/\s+/).some((rawToken) => {
|
|
545
|
+
if (!rawToken) return false;
|
|
546
|
+
const segments = rawToken.split(":");
|
|
547
|
+
const base = segments.pop() ?? rawToken;
|
|
548
|
+
return findModeAwareColor(base, theme) !== null;
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
function hexToRgb(hex) {
|
|
552
|
+
const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
|
|
419
553
|
if (!m) return null;
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
if ((inner = stripCall(spaced, "min")) !== null) kind = "min";
|
|
425
|
-
else if ((inner = stripCall(spaced, "max")) !== null) kind = "max";
|
|
426
|
-
else if ((inner = stripCall(spaced, "clamp")) !== null) kind = "clamp";
|
|
427
|
-
else return null;
|
|
428
|
-
const args = splitTopLevelCommas(inner);
|
|
429
|
-
if (kind === "clamp" && args.length !== 3) return null;
|
|
430
|
-
if (kind !== "clamp" && args.length < 1) return null;
|
|
431
|
-
const operands = args.map((arg) => new PercentAwareEvaluator(arg.trim()).parseExprToEnd());
|
|
432
|
-
if (operands.some((o) => o === null)) return null;
|
|
433
|
-
const resolved = operands;
|
|
434
|
-
if (!resolved.some((o) => o.percent !== 0)) return null;
|
|
435
|
-
return {
|
|
436
|
-
property,
|
|
437
|
-
resolve(basisPx) {
|
|
438
|
-
const values = resolved.map((o) => basisPx * o.percent / 100 + o.px);
|
|
439
|
-
if (kind === "min") return Math.min(...values);
|
|
440
|
-
if (kind === "max") return Math.max(...values);
|
|
441
|
-
const [min, preferred, max] = values;
|
|
442
|
-
return Math.max(min, Math.min(preferred, max));
|
|
443
|
-
}
|
|
444
|
-
};
|
|
554
|
+
let h = m[1];
|
|
555
|
+
if (h.length === 3) h = h.split("").map((c) => c + c).join("");
|
|
556
|
+
const n = parseInt(h, 16);
|
|
557
|
+
return [n >> 16 & 255, n >> 8 & 255, n & 255];
|
|
445
558
|
}
|
|
446
|
-
function
|
|
447
|
-
const
|
|
448
|
-
if (
|
|
449
|
-
|
|
559
|
+
function splitOpacity(value) {
|
|
560
|
+
const slash = value.indexOf("/");
|
|
561
|
+
if (slash === -1) return [value, null];
|
|
562
|
+
const alpha = parseAlpha(value.slice(slash + 1));
|
|
563
|
+
return alpha === null ? [value, null] : [value.slice(0, slash), alpha];
|
|
450
564
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
"text-",
|
|
460
|
-
"border-x-",
|
|
461
|
-
"border-y-",
|
|
462
|
-
"border-t-",
|
|
463
|
-
"border-r-",
|
|
464
|
-
"border-b-",
|
|
465
|
-
"border-l-",
|
|
466
|
-
"border-",
|
|
467
|
-
"caret-",
|
|
468
|
-
"accent-",
|
|
469
|
-
"fill-",
|
|
470
|
-
"stroke-width-",
|
|
471
|
-
"stroke-",
|
|
472
|
-
"resize-",
|
|
473
|
-
"touch-",
|
|
474
|
-
"will-change-",
|
|
475
|
-
"scroll-mx-",
|
|
476
|
-
"scroll-my-",
|
|
477
|
-
"scroll-mt-",
|
|
478
|
-
"scroll-mr-",
|
|
479
|
-
"scroll-mb-",
|
|
480
|
-
"scroll-ml-",
|
|
481
|
-
"scroll-m-",
|
|
482
|
-
"scroll-px-",
|
|
483
|
-
"scroll-py-",
|
|
484
|
-
"scroll-pt-",
|
|
485
|
-
"scroll-pr-",
|
|
486
|
-
"scroll-pb-",
|
|
487
|
-
"scroll-pl-",
|
|
488
|
-
"scroll-p-",
|
|
489
|
-
"px-",
|
|
490
|
-
"py-",
|
|
491
|
-
"pt-",
|
|
492
|
-
"pr-",
|
|
493
|
-
"pb-",
|
|
494
|
-
"pl-",
|
|
495
|
-
"p-",
|
|
496
|
-
"mx-",
|
|
497
|
-
"my-",
|
|
498
|
-
"mt-",
|
|
499
|
-
"mr-",
|
|
500
|
-
"mb-",
|
|
501
|
-
"ml-",
|
|
502
|
-
"m-",
|
|
503
|
-
"gap-x-",
|
|
504
|
-
"gap-y-",
|
|
505
|
-
"gap-",
|
|
506
|
-
"min-w-",
|
|
507
|
-
"max-w-",
|
|
508
|
-
"w-",
|
|
509
|
-
"min-h-",
|
|
510
|
-
"max-h-",
|
|
511
|
-
"h-",
|
|
512
|
-
"size-",
|
|
513
|
-
"basis-",
|
|
514
|
-
"rounded-tl-",
|
|
515
|
-
"rounded-tr-",
|
|
516
|
-
"rounded-br-",
|
|
517
|
-
"rounded-bl-",
|
|
518
|
-
"rounded-t-",
|
|
519
|
-
"rounded-r-",
|
|
520
|
-
"rounded-b-",
|
|
521
|
-
"rounded-l-",
|
|
522
|
-
"rounded-",
|
|
523
|
-
"ring-offset-",
|
|
524
|
-
"ring-",
|
|
525
|
-
"outline-offset-",
|
|
526
|
-
"outline-",
|
|
527
|
-
"shadow-",
|
|
528
|
-
"opacity-",
|
|
529
|
-
"duration-",
|
|
530
|
-
"delay-",
|
|
531
|
-
"ease-",
|
|
532
|
-
"cursor-",
|
|
533
|
-
"mix-blend-",
|
|
534
|
-
"animate-",
|
|
535
|
-
"leading-",
|
|
536
|
-
"tracking-",
|
|
537
|
-
"font-",
|
|
538
|
-
"z-",
|
|
539
|
-
"inset-x-",
|
|
540
|
-
"inset-y-",
|
|
541
|
-
"inset-",
|
|
542
|
-
"top-",
|
|
543
|
-
"right-",
|
|
544
|
-
"bottom-",
|
|
545
|
-
"left-",
|
|
546
|
-
"start-",
|
|
547
|
-
"end-",
|
|
548
|
-
"overflow-x-",
|
|
549
|
-
"overflow-y-",
|
|
550
|
-
"overscroll-x-",
|
|
551
|
-
"overscroll-y-",
|
|
552
|
-
"overscroll-",
|
|
553
|
-
"aspect-",
|
|
554
|
-
"divide-color-",
|
|
555
|
-
"space-x-",
|
|
556
|
-
"space-y-",
|
|
557
|
-
"flex-",
|
|
558
|
-
"grow-",
|
|
559
|
-
"shrink-",
|
|
560
|
-
"order-",
|
|
561
|
-
"grid-cols-",
|
|
562
|
-
"grid-rows-",
|
|
563
|
-
"grid-flow-",
|
|
564
|
-
"auto-cols-",
|
|
565
|
-
"auto-rows-",
|
|
566
|
-
"col-span-",
|
|
567
|
-
"col-start-",
|
|
568
|
-
"col-end-",
|
|
569
|
-
"col-",
|
|
570
|
-
"row-span-",
|
|
571
|
-
"row-start-",
|
|
572
|
-
"row-end-",
|
|
573
|
-
"row-",
|
|
574
|
-
"place-items-",
|
|
575
|
-
"place-content-",
|
|
576
|
-
"place-self-",
|
|
577
|
-
"justify-items-",
|
|
578
|
-
"justify-self-",
|
|
579
|
-
"scale-x-",
|
|
580
|
-
"scale-y-",
|
|
581
|
-
"scale-z-",
|
|
582
|
-
"scale-",
|
|
583
|
-
"rotate-x-",
|
|
584
|
-
"rotate-y-",
|
|
585
|
-
"rotate-z-",
|
|
586
|
-
"rotate-",
|
|
587
|
-
// Bare 'translate-'/'skew-' (both axes) after their per-axis forms, same
|
|
588
|
-
// longer-before-shorter rule as resolvers/parser.rs.
|
|
589
|
-
"translate-x-",
|
|
590
|
-
"translate-y-",
|
|
591
|
-
"translate-z-",
|
|
592
|
-
"translate-",
|
|
593
|
-
"skew-x-",
|
|
594
|
-
"skew-y-",
|
|
595
|
-
"skew-",
|
|
596
|
-
"perspective-origin-",
|
|
597
|
-
"perspective-",
|
|
598
|
-
"origin-",
|
|
599
|
-
"blur-",
|
|
600
|
-
"brightness-",
|
|
601
|
-
"contrast-",
|
|
602
|
-
"grayscale-",
|
|
603
|
-
"hue-rotate-",
|
|
604
|
-
"invert-",
|
|
605
|
-
"saturate-",
|
|
606
|
-
"sepia-",
|
|
607
|
-
"drop-shadow-",
|
|
608
|
-
"filter-",
|
|
609
|
-
"backdrop-blur-",
|
|
610
|
-
"backdrop-brightness-",
|
|
611
|
-
"backdrop-contrast-",
|
|
612
|
-
"backdrop-grayscale-",
|
|
613
|
-
"backdrop-hue-rotate-",
|
|
614
|
-
"backdrop-invert-",
|
|
615
|
-
"backdrop-opacity-",
|
|
616
|
-
"backdrop-saturate-",
|
|
617
|
-
"backdrop-sepia-",
|
|
618
|
-
"backdrop-filter-",
|
|
619
|
-
"decoration-",
|
|
620
|
-
"underline-offset-",
|
|
621
|
-
"indent-",
|
|
622
|
-
"from-",
|
|
623
|
-
"via-",
|
|
624
|
-
"to-"
|
|
625
|
-
];
|
|
626
|
-
var ARBITRARY_PROPERTY_SENTINEL = "[arbitrary-property]";
|
|
627
|
-
function isSafeArbitraryValue(value) {
|
|
628
|
-
return !value.includes("{") && !value.includes("}") && !value.includes(";");
|
|
565
|
+
function colorValue(theme, parsed) {
|
|
566
|
+
const value = parsed.value;
|
|
567
|
+
if (value === null) return null;
|
|
568
|
+
if (parsed.isArbitrary) return value;
|
|
569
|
+
const [name, opacity] = splitOpacity(value);
|
|
570
|
+
const hex = lookupHex(theme, name);
|
|
571
|
+
if (hex === null) return null;
|
|
572
|
+
return opacity === null ? hex : colorWithOpacity(hex, opacity);
|
|
629
573
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
574
|
+
var LENGTH_UNITS = ["px", "rem", "em", "%", "vh", "vw"];
|
|
575
|
+
function looksLikeLength(value) {
|
|
576
|
+
const unit = LENGTH_UNITS.find((u) => value.endsWith(u));
|
|
577
|
+
const withoutUnit = unit ? value.slice(0, value.length - unit.length) : value;
|
|
578
|
+
if (withoutUnit !== "" && Number.isFinite(Number(withoutUnit))) return true;
|
|
579
|
+
if (!["calc(", "clamp(", "min(", "max("].some((f) => value.startsWith(f))) return false;
|
|
580
|
+
return MATH_LENGTH_UNIT.test(value);
|
|
581
|
+
}
|
|
582
|
+
var MATH_LENGTH_UNIT = /\d(?:px|rem|em|%|vh|vw|vmin|vmax|dvh|dvw|svh|svw|lvh|lvw|ch|ex|lh|cqw|cqh|cqi|cqb)(?![A-Za-z])/;
|
|
583
|
+
function isLength(parsed, value) {
|
|
584
|
+
switch (parsed.typeHint ?? null) {
|
|
585
|
+
case null:
|
|
586
|
+
return looksLikeLength(value);
|
|
587
|
+
case "length":
|
|
588
|
+
case "size":
|
|
589
|
+
case "line-width":
|
|
590
|
+
case "percentage":
|
|
591
|
+
case "number":
|
|
592
|
+
case "integer":
|
|
593
|
+
case "absolute-size":
|
|
594
|
+
case "relative-size":
|
|
595
|
+
return true;
|
|
596
|
+
default:
|
|
597
|
+
return false;
|
|
633
598
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// src/jsxRuntimeCore.ts
|
|
602
|
+
var import_dynamicTokens = require("./dynamicTokens");
|
|
603
|
+
|
|
604
|
+
// src/jsEngine/calc.ts
|
|
605
|
+
function reduceConstantMath(raw) {
|
|
606
|
+
const trimmed = raw.trim();
|
|
607
|
+
const calc = stripCall(trimmed, "calc");
|
|
608
|
+
if (calc !== null) {
|
|
609
|
+
return new Evaluator(calc).parseExprToEnd();
|
|
610
|
+
}
|
|
611
|
+
const clamp = stripCall(trimmed, "clamp");
|
|
612
|
+
if (clamp !== null) {
|
|
613
|
+
const args = splitTopLevelCommas(clamp);
|
|
614
|
+
if (args.length !== 3) return null;
|
|
615
|
+
const [min2, preferred, max2] = args.map((a) => new Evaluator(a).parseExprToEnd());
|
|
616
|
+
if (min2 === null || preferred === null || max2 === null) return null;
|
|
617
|
+
return Math.max(min2, Math.min(preferred, max2));
|
|
618
|
+
}
|
|
619
|
+
const min = stripCall(trimmed, "min");
|
|
620
|
+
if (min !== null) {
|
|
621
|
+
const values = splitTopLevelCommas(min).map((a) => new Evaluator(a).parseExprToEnd());
|
|
622
|
+
return values.some((v) => v === null) ? null : Math.min(...values);
|
|
623
|
+
}
|
|
624
|
+
const max = stripCall(trimmed, "max");
|
|
625
|
+
if (max !== null) {
|
|
626
|
+
const values = splitTopLevelCommas(max).map((a) => new Evaluator(a).parseExprToEnd());
|
|
627
|
+
return values.some((v) => v === null) ? null : Math.max(...values);
|
|
628
|
+
}
|
|
629
|
+
return null;
|
|
630
|
+
}
|
|
631
|
+
function stripCall(raw, name) {
|
|
632
|
+
if (!raw.startsWith(name)) return null;
|
|
633
|
+
const afterName = raw.slice(name.length).trimStart();
|
|
634
|
+
if (!afterName.startsWith("(") || !afterName.endsWith(")")) return null;
|
|
635
|
+
return afterName.slice(1, -1);
|
|
636
|
+
}
|
|
637
|
+
function splitTopLevelCommas(s) {
|
|
638
|
+
const parts = [];
|
|
639
|
+
let depth = 0;
|
|
640
|
+
let start = 0;
|
|
641
|
+
for (let i = 0; i < s.length; i++) {
|
|
642
|
+
const ch = s[i];
|
|
643
|
+
if (ch === "(") depth++;
|
|
644
|
+
else if (ch === ")") depth--;
|
|
645
|
+
else if (ch === "," && depth === 0) {
|
|
646
|
+
parts.push(s.slice(start, i).trim());
|
|
647
|
+
start = i + 1;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
parts.push(s.slice(start).trim());
|
|
651
|
+
return parts;
|
|
652
|
+
}
|
|
653
|
+
var Evaluator = class {
|
|
654
|
+
constructor(s) {
|
|
655
|
+
this.pos = 0;
|
|
656
|
+
this.s = s;
|
|
657
|
+
}
|
|
658
|
+
parseExprToEnd() {
|
|
659
|
+
const value = this.expr();
|
|
660
|
+
if (value === null) return null;
|
|
661
|
+
this.skipWs();
|
|
662
|
+
return this.pos === this.s.length ? value : null;
|
|
663
|
+
}
|
|
664
|
+
skipWs() {
|
|
665
|
+
while (this.pos < this.s.length && /\s/.test(this.s[this.pos])) this.pos++;
|
|
666
|
+
}
|
|
667
|
+
peek() {
|
|
668
|
+
this.skipWs();
|
|
669
|
+
return this.s[this.pos];
|
|
670
|
+
}
|
|
671
|
+
expr() {
|
|
672
|
+
let value = this.term();
|
|
673
|
+
if (value === null) return null;
|
|
674
|
+
for (; ; ) {
|
|
675
|
+
const ch = this.peek();
|
|
676
|
+
if (ch === "+") {
|
|
677
|
+
this.pos++;
|
|
678
|
+
const rhs = this.term();
|
|
679
|
+
if (rhs === null) return null;
|
|
680
|
+
value += rhs;
|
|
681
|
+
} else if (ch === "-") {
|
|
682
|
+
this.pos++;
|
|
683
|
+
const rhs = this.term();
|
|
684
|
+
if (rhs === null) return null;
|
|
685
|
+
value -= rhs;
|
|
686
|
+
} else {
|
|
687
|
+
return value;
|
|
653
688
|
}
|
|
654
|
-
out += chars.slice(start, i).join("");
|
|
655
|
-
prevEndsValue = true;
|
|
656
|
-
continue;
|
|
657
689
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
690
|
+
}
|
|
691
|
+
term() {
|
|
692
|
+
let value = this.factor();
|
|
693
|
+
if (value === null) return null;
|
|
694
|
+
for (; ; ) {
|
|
695
|
+
const ch = this.peek();
|
|
696
|
+
if (ch === "*") {
|
|
697
|
+
this.pos++;
|
|
698
|
+
const rhs = this.factor();
|
|
699
|
+
if (rhs === null) return null;
|
|
700
|
+
value *= rhs;
|
|
701
|
+
} else if (ch === "/") {
|
|
702
|
+
this.pos++;
|
|
703
|
+
const divisor = this.factor();
|
|
704
|
+
if (divisor === null || divisor === 0) return null;
|
|
705
|
+
value /= divisor;
|
|
706
|
+
} else {
|
|
707
|
+
return value;
|
|
665
708
|
}
|
|
666
|
-
out += c;
|
|
667
|
-
prevEndsValue = false;
|
|
668
|
-
} else if (c === "(" || c === ",") {
|
|
669
|
-
out += c;
|
|
670
|
-
if (c === ",") out += " ";
|
|
671
|
-
prevEndsValue = false;
|
|
672
|
-
} else if (c === ")") {
|
|
673
|
-
out += c;
|
|
674
|
-
prevEndsValue = true;
|
|
675
|
-
} else if (/\s/.test(c)) {
|
|
676
|
-
} else if (c === "*" || c === "/") {
|
|
677
|
-
out += c;
|
|
678
|
-
prevEndsValue = false;
|
|
679
|
-
} else {
|
|
680
|
-
out += c;
|
|
681
|
-
prevEndsValue = true;
|
|
682
709
|
}
|
|
683
|
-
i++;
|
|
684
710
|
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
"family-name",
|
|
700
|
-
"absolute-size",
|
|
701
|
-
"relative-size",
|
|
702
|
-
"angle",
|
|
703
|
-
"shadow",
|
|
704
|
-
"any"
|
|
705
|
-
]);
|
|
706
|
-
function splitTypeHint(raw) {
|
|
707
|
-
const i = raw.indexOf(":");
|
|
708
|
-
if (i > 0 && i < raw.length - 1 && TYPE_HINTS.has(raw.slice(0, i))) return [raw.slice(0, i), raw.slice(i + 1)];
|
|
709
|
-
return [null, raw];
|
|
710
|
-
}
|
|
711
|
-
function parenVarShorthand(value) {
|
|
712
|
-
const m = /^\((?:([a-z-]+):)?--([A-Za-z0-9_-]+)\)(\/.*)?$/.exec(value);
|
|
713
|
-
if (!m) return null;
|
|
714
|
-
const [, hint, name, tail = ""] = m;
|
|
715
|
-
if (hint !== void 0 && !TYPE_HINTS.has(hint)) return null;
|
|
716
|
-
return hint ? `[${hint}:var(--${name})]${tail}` : `[var(--${name})]${tail}`;
|
|
717
|
-
}
|
|
718
|
-
function splitArbitraryOpacity(value) {
|
|
719
|
-
if (value.startsWith("[")) {
|
|
720
|
-
const i = value.lastIndexOf("]/");
|
|
721
|
-
if (i !== -1) {
|
|
722
|
-
const pct = value.slice(i + 2);
|
|
723
|
-
if (/^\d+$/.test(pct) && Number(pct) <= 100) return [value.slice(0, i + 1), Number(pct)];
|
|
711
|
+
factor() {
|
|
712
|
+
const ch = this.peek();
|
|
713
|
+
if (ch === void 0) return null;
|
|
714
|
+
if (ch === "(") {
|
|
715
|
+
this.pos++;
|
|
716
|
+
const value = this.expr();
|
|
717
|
+
if (value === null || this.peek() !== ")") return null;
|
|
718
|
+
this.pos++;
|
|
719
|
+
return value;
|
|
720
|
+
}
|
|
721
|
+
if (ch === "-") {
|
|
722
|
+
this.pos++;
|
|
723
|
+
const value = this.factor();
|
|
724
|
+
return value === null ? null : -value;
|
|
724
725
|
}
|
|
726
|
+
return this.numberWithUnit();
|
|
725
727
|
}
|
|
726
|
-
|
|
728
|
+
numberWithUnit() {
|
|
729
|
+
this.skipWs();
|
|
730
|
+
const start = this.pos;
|
|
731
|
+
while (this.pos < this.s.length && (/[0-9]/.test(this.s[this.pos]) || this.s[this.pos] === ".")) this.pos++;
|
|
732
|
+
if (this.pos === start) return null;
|
|
733
|
+
const n = Number(this.s.slice(start, this.pos));
|
|
734
|
+
if (!Number.isFinite(n)) return null;
|
|
735
|
+
const unitStart = this.pos;
|
|
736
|
+
while (this.pos < this.s.length && /[a-zA-Z]/.test(this.s[this.pos])) this.pos++;
|
|
737
|
+
const unit = this.s.slice(unitStart, this.pos);
|
|
738
|
+
switch (unit) {
|
|
739
|
+
case "":
|
|
740
|
+
return n;
|
|
741
|
+
case "px":
|
|
742
|
+
return n;
|
|
743
|
+
case "rem":
|
|
744
|
+
return n * 16;
|
|
745
|
+
default:
|
|
746
|
+
return null;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
// src/layoutCalc.ts
|
|
752
|
+
var NEG = (v) => ({ percent: -v.percent, px: -v.px });
|
|
753
|
+
var ADD = (a, b) => ({ percent: a.percent + b.percent, px: a.px + b.px });
|
|
754
|
+
var SUB = (a, b) => ({ percent: a.percent - b.percent, px: a.px - b.px });
|
|
755
|
+
function MUL(a, b) {
|
|
756
|
+
if (a.percent === 0) return { percent: b.percent * a.px, px: b.px * a.px };
|
|
757
|
+
if (b.percent === 0) return { percent: a.percent * b.px, px: a.px * b.px };
|
|
758
|
+
return null;
|
|
727
759
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
return
|
|
760
|
+
function DIV(a, b) {
|
|
761
|
+
if (b.percent !== 0 || b.px === 0) return null;
|
|
762
|
+
return { percent: a.percent / b.px, px: a.px / b.px };
|
|
731
763
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
const [r, g, b] = [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
|
|
737
|
-
return `rgba(${r},${g},${b},${pct / 100})`;
|
|
764
|
+
var PercentAwareEvaluator = class {
|
|
765
|
+
constructor(s) {
|
|
766
|
+
this.pos = 0;
|
|
767
|
+
this.s = s;
|
|
738
768
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
let start = 0;
|
|
745
|
-
for (let i = 0; i < token.length; i++) {
|
|
746
|
-
const ch = token[i];
|
|
747
|
-
if (ch === "[" || ch === "(") depth += 1;
|
|
748
|
-
else if (ch === "]" || ch === ")") depth -= 1;
|
|
749
|
-
else if (ch === ":" && depth <= 0) {
|
|
750
|
-
parts.push(token.slice(start, i));
|
|
751
|
-
start = i + 1;
|
|
752
|
-
}
|
|
769
|
+
parseExprToEnd() {
|
|
770
|
+
const value = this.expr();
|
|
771
|
+
if (value === null) return null;
|
|
772
|
+
this.skipWs();
|
|
773
|
+
return this.pos === this.s.length ? value : null;
|
|
753
774
|
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
function parseClass(token) {
|
|
758
|
-
const parts = splitRespectingBrackets(token);
|
|
759
|
-
let base = parts.pop() ?? token;
|
|
760
|
-
const modifiers = parts;
|
|
761
|
-
const important = base.startsWith("!") || base.length > 1 && base.endsWith("!");
|
|
762
|
-
if (base.startsWith("!")) {
|
|
763
|
-
base = base.slice(1);
|
|
764
|
-
} else if (important) {
|
|
765
|
-
base = base.slice(0, -1);
|
|
775
|
+
skipWs() {
|
|
776
|
+
while (this.pos < this.s.length && /\s/.test(this.s[this.pos])) this.pos++;
|
|
766
777
|
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
778
|
+
peek() {
|
|
779
|
+
this.skipWs();
|
|
780
|
+
return this.s[this.pos];
|
|
770
781
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
const
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
const
|
|
779
|
-
return
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
782
|
+
expr() {
|
|
783
|
+
let value = this.term();
|
|
784
|
+
if (value === null) return null;
|
|
785
|
+
for (; ; ) {
|
|
786
|
+
const ch = this.peek();
|
|
787
|
+
if (ch === "+") {
|
|
788
|
+
this.pos++;
|
|
789
|
+
const rhs = this.term();
|
|
790
|
+
if (rhs === null) return null;
|
|
791
|
+
value = ADD(value, rhs);
|
|
792
|
+
} else if (ch === "-") {
|
|
793
|
+
this.pos++;
|
|
794
|
+
const rhs = this.term();
|
|
795
|
+
if (rhs === null) return null;
|
|
796
|
+
value = SUB(value, rhs);
|
|
797
|
+
} else {
|
|
798
|
+
return value;
|
|
788
799
|
}
|
|
789
800
|
}
|
|
790
801
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
if (
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
802
|
+
term() {
|
|
803
|
+
let value = this.factor();
|
|
804
|
+
if (value === null) return null;
|
|
805
|
+
for (; ; ) {
|
|
806
|
+
const ch = this.peek();
|
|
807
|
+
if (ch === "*") {
|
|
808
|
+
this.pos++;
|
|
809
|
+
const rhs = this.factor();
|
|
810
|
+
if (rhs === null) return null;
|
|
811
|
+
const result = MUL(value, rhs);
|
|
812
|
+
if (result === null) return null;
|
|
813
|
+
value = result;
|
|
814
|
+
} else if (ch === "/") {
|
|
815
|
+
this.pos++;
|
|
816
|
+
const rhs = this.factor();
|
|
817
|
+
if (rhs === null) return null;
|
|
818
|
+
const result = DIV(value, rhs);
|
|
819
|
+
if (result === null) return null;
|
|
820
|
+
value = result;
|
|
821
|
+
} else {
|
|
822
|
+
return value;
|
|
807
823
|
}
|
|
808
|
-
return {
|
|
809
|
-
modifiers,
|
|
810
|
-
utility: prefix.slice(0, -1),
|
|
811
|
-
value: hinted,
|
|
812
|
-
typeHint,
|
|
813
|
-
isArbitrary: true,
|
|
814
|
-
important,
|
|
815
|
-
negative,
|
|
816
|
-
original: token
|
|
817
|
-
};
|
|
818
824
|
}
|
|
819
|
-
return {
|
|
820
|
-
modifiers,
|
|
821
|
-
utility: prefix.slice(0, -1),
|
|
822
|
-
// a named value keeps its own /opacity (`bg-blue-6/50`)
|
|
823
|
-
value: arbitraryOpacity === null ? value : `${value}/${arbitraryOpacity}`,
|
|
824
|
-
isArbitrary: false,
|
|
825
|
-
important,
|
|
826
|
-
negative,
|
|
827
|
-
original: token
|
|
828
|
-
};
|
|
829
825
|
}
|
|
826
|
+
factor() {
|
|
827
|
+
const ch = this.peek();
|
|
828
|
+
if (ch === void 0) return null;
|
|
829
|
+
if (ch === "(") {
|
|
830
|
+
this.pos++;
|
|
831
|
+
const value = this.expr();
|
|
832
|
+
if (value === null || this.peek() !== ")") return null;
|
|
833
|
+
this.pos++;
|
|
834
|
+
return value;
|
|
835
|
+
}
|
|
836
|
+
if (ch === "-") {
|
|
837
|
+
this.pos++;
|
|
838
|
+
const value = this.factor();
|
|
839
|
+
return value === null ? null : NEG(value);
|
|
840
|
+
}
|
|
841
|
+
return this.numberWithUnit();
|
|
842
|
+
}
|
|
843
|
+
numberWithUnit() {
|
|
844
|
+
this.skipWs();
|
|
845
|
+
const start = this.pos;
|
|
846
|
+
while (this.pos < this.s.length && (/[0-9]/.test(this.s[this.pos]) || this.s[this.pos] === ".")) this.pos++;
|
|
847
|
+
if (this.pos === start) return null;
|
|
848
|
+
const n = Number(this.s.slice(start, this.pos));
|
|
849
|
+
if (!Number.isFinite(n)) return null;
|
|
850
|
+
if (this.s[this.pos] === "%") {
|
|
851
|
+
this.pos++;
|
|
852
|
+
return { percent: n, px: 0 };
|
|
853
|
+
}
|
|
854
|
+
const unitStart = this.pos;
|
|
855
|
+
while (this.pos < this.s.length && /[a-zA-Z]/.test(this.s[this.pos])) this.pos++;
|
|
856
|
+
const unit = this.s.slice(unitStart, this.pos);
|
|
857
|
+
switch (unit) {
|
|
858
|
+
case "":
|
|
859
|
+
return { percent: 0, px: n };
|
|
860
|
+
case "px":
|
|
861
|
+
return { percent: 0, px: n };
|
|
862
|
+
case "rem":
|
|
863
|
+
return { percent: 0, px: n * 16 };
|
|
864
|
+
default:
|
|
865
|
+
return null;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
var PERCENT_TOKEN_OUTER_RE = /^(w|h)-\[(.+)\]$/;
|
|
870
|
+
function parsePercentRelativeCalc(token) {
|
|
871
|
+
const m = PERCENT_TOKEN_OUTER_RE.exec(token);
|
|
872
|
+
if (!m) return null;
|
|
873
|
+
const property = m[1] === "w" ? "width" : "height";
|
|
874
|
+
const inner = stripCall(m[2].replace(/_/g, " ").trim(), "calc");
|
|
875
|
+
if (inner === null) return null;
|
|
876
|
+
const result = new PercentAwareEvaluator(inner).parseExprToEnd();
|
|
877
|
+
if (result === null || result.percent === 0) return null;
|
|
878
|
+
return { property, percentCoefficient: result.percent, constantPx: result.px };
|
|
879
|
+
}
|
|
880
|
+
function resolvePercentRelativeCalc(basisPx, calc) {
|
|
881
|
+
return basisPx * calc.percentCoefficient / 100 + calc.constantPx;
|
|
882
|
+
}
|
|
883
|
+
function parsePercentRelativeMinMaxClamp(token) {
|
|
884
|
+
const m = PERCENT_TOKEN_OUTER_RE.exec(token);
|
|
885
|
+
if (!m) return null;
|
|
886
|
+
const property = m[1] === "w" ? "width" : "height";
|
|
887
|
+
const spaced = m[2].replace(/_/g, " ");
|
|
888
|
+
let kind;
|
|
889
|
+
let inner;
|
|
890
|
+
if ((inner = stripCall(spaced, "min")) !== null) kind = "min";
|
|
891
|
+
else if ((inner = stripCall(spaced, "max")) !== null) kind = "max";
|
|
892
|
+
else if ((inner = stripCall(spaced, "clamp")) !== null) kind = "clamp";
|
|
893
|
+
else return null;
|
|
894
|
+
const args = splitTopLevelCommas(inner);
|
|
895
|
+
if (kind === "clamp" && args.length !== 3) return null;
|
|
896
|
+
if (kind !== "clamp" && args.length < 1) return null;
|
|
897
|
+
const operands = args.map((arg) => new PercentAwareEvaluator(arg.trim()).parseExprToEnd());
|
|
898
|
+
if (operands.some((o) => o === null)) return null;
|
|
899
|
+
const resolved = operands;
|
|
900
|
+
if (!resolved.some((o) => o.percent !== 0)) return null;
|
|
830
901
|
return {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
902
|
+
property,
|
|
903
|
+
resolve(basisPx) {
|
|
904
|
+
const values = resolved.map((o) => basisPx * o.percent / 100 + o.px);
|
|
905
|
+
if (kind === "min") return Math.min(...values);
|
|
906
|
+
if (kind === "max") return Math.max(...values);
|
|
907
|
+
const [min, preferred, max] = values;
|
|
908
|
+
return Math.max(min, Math.min(preferred, max));
|
|
909
|
+
}
|
|
838
910
|
};
|
|
839
911
|
}
|
|
912
|
+
function parsePercentRelativeExpr(token) {
|
|
913
|
+
const calc = parsePercentRelativeCalc(token);
|
|
914
|
+
if (calc) return { property: calc.property, resolve: (basisPx) => resolvePercentRelativeCalc(basisPx, calc) };
|
|
915
|
+
return parsePercentRelativeMinMaxClamp(token);
|
|
916
|
+
}
|
|
840
917
|
|
|
841
918
|
// src/jsxRuntimeCore.ts
|
|
842
919
|
var DYNAMIC_TOKEN_MATCH_RE = /var\(--([a-zA-Z0-9-]+)\)/g;
|
|
@@ -1121,6 +1198,11 @@ function resolveNegatableSize(theme, parsed) {
|
|
|
1121
1198
|
}
|
|
1122
1199
|
return resolveNegatableLength(theme, parsed);
|
|
1123
1200
|
}
|
|
1201
|
+
function negate(value) {
|
|
1202
|
+
const numeric = (v) => /^[\d.]/.test(v);
|
|
1203
|
+
if (value.startsWith("-")) return numeric(value.slice(1)) ? value.slice(1) : `calc(${value} * -1)`;
|
|
1204
|
+
return numeric(value) ? `-${value}` : `calc(${value} * -1)`;
|
|
1205
|
+
}
|
|
1124
1206
|
function resolvePercent(parsed) {
|
|
1125
1207
|
if (parsed.negative) return null;
|
|
1126
1208
|
const value = parsed.value;
|
|
@@ -1346,8 +1428,10 @@ function resolve(parsed, theme) {
|
|
|
1346
1428
|
return [decl("aspect-ratio", "16 / 9")];
|
|
1347
1429
|
case "auto":
|
|
1348
1430
|
return [decl("aspect-ratio", "auto")];
|
|
1349
|
-
default:
|
|
1350
|
-
|
|
1431
|
+
default: {
|
|
1432
|
+
const m = /^(\d+(?:\.\d*)?|\.\d+)\/(\d+(?:\.\d*)?|\.\d+)$/.exec(value);
|
|
1433
|
+
return m ? [decl("aspect-ratio", `${m[1]} / ${m[2]}`)] : null;
|
|
1434
|
+
}
|
|
1351
1435
|
}
|
|
1352
1436
|
}
|
|
1353
1437
|
default:
|
|
@@ -1734,9 +1818,9 @@ function outlineValue(theme, parsed) {
|
|
|
1734
1818
|
function outlineOffsetValue(parsed) {
|
|
1735
1819
|
const value = parsed.value;
|
|
1736
1820
|
if (value === null) return null;
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
return
|
|
1821
|
+
const v = parsed.isArbitrary ? value : outlineWidthValue(value);
|
|
1822
|
+
if (v === null) return null;
|
|
1823
|
+
return [decl("outline-offset", parsed.negative ? negate(v) : v)];
|
|
1740
1824
|
}
|
|
1741
1825
|
var RADIUS_SIDES = /* @__PURE__ */ new Set(["t", "r", "b", "l", "tl", "tr", "br", "bl"]);
|
|
1742
1826
|
function resolve3(parsed, theme) {
|
|
@@ -1829,6 +1913,55 @@ function lineHeightSize(key) {
|
|
|
1829
1913
|
const n = Number(key);
|
|
1830
1914
|
return Number.isFinite(n) && n >= 0 ? `${n * 0.25}rem` : null;
|
|
1831
1915
|
}
|
|
1916
|
+
function leadingNamed(key) {
|
|
1917
|
+
switch (key) {
|
|
1918
|
+
case "none":
|
|
1919
|
+
return 1;
|
|
1920
|
+
case "tight":
|
|
1921
|
+
return 1.25;
|
|
1922
|
+
case "snug":
|
|
1923
|
+
return 1.375;
|
|
1924
|
+
case "normal":
|
|
1925
|
+
return 1.5;
|
|
1926
|
+
case "relaxed":
|
|
1927
|
+
return 1.625;
|
|
1928
|
+
case "loose":
|
|
1929
|
+
return 2;
|
|
1930
|
+
default:
|
|
1931
|
+
return null;
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
function splitSizeLeading(value) {
|
|
1935
|
+
const i = value.indexOf("/");
|
|
1936
|
+
if (i === -1) return null;
|
|
1937
|
+
const size = textSize(value.slice(0, i));
|
|
1938
|
+
const leading = value.slice(i + 1);
|
|
1939
|
+
return size === null || leading === "" ? null : [size, leading];
|
|
1940
|
+
}
|
|
1941
|
+
function sizeLeadingNative(size, leading) {
|
|
1942
|
+
const rem = (n) => {
|
|
1943
|
+
const unit = size.endsWith("rem") ? "rem" : size.endsWith("px") ? "px" : null;
|
|
1944
|
+
if (unit === null) return null;
|
|
1945
|
+
const number = size.slice(0, -unit.length);
|
|
1946
|
+
const s = Number(number);
|
|
1947
|
+
return number.trim() !== "" && Number.isFinite(s) ? `${s * n}${unit}` : null;
|
|
1948
|
+
};
|
|
1949
|
+
const arbitrary = arbitraryModifier(leading);
|
|
1950
|
+
if (arbitrary !== null) {
|
|
1951
|
+
if (arbitrary.startsWith("var(")) return null;
|
|
1952
|
+
const n = Number(arbitrary);
|
|
1953
|
+
return arbitrary.trim() !== "" && Number.isFinite(n) ? rem(n) : arbitrary;
|
|
1954
|
+
}
|
|
1955
|
+
const scale = lineHeightSize(leading);
|
|
1956
|
+
if (scale !== null) return scale;
|
|
1957
|
+
const m = leadingNamed(leading);
|
|
1958
|
+
return m === null ? null : rem(m);
|
|
1959
|
+
}
|
|
1960
|
+
function arbitraryFontIsWeight(parsed, value) {
|
|
1961
|
+
const hint = parsed.typeHint ?? null;
|
|
1962
|
+
if (hint !== null) return hint === "number" || hint === "integer";
|
|
1963
|
+
return value.trim() !== "" && Number.isFinite(Number(value)) || value.startsWith("var(") && value.endsWith(")") && !value.includes(",");
|
|
1964
|
+
}
|
|
1832
1965
|
function textAlign(key) {
|
|
1833
1966
|
switch (key) {
|
|
1834
1967
|
case "left":
|
|
@@ -1932,10 +2065,11 @@ function nativeShadowDeclarations(parsed) {
|
|
|
1932
2065
|
|
|
1933
2066
|
// src/jsEngine/resolvers/transform.ts
|
|
1934
2067
|
function scaleFactor(parsed) {
|
|
1935
|
-
if (parsed.value === null) return null;
|
|
2068
|
+
if (parsed.value === null || parsed.value.trim() === "") return null;
|
|
1936
2069
|
const n = Number(parsed.value);
|
|
1937
2070
|
if (!Number.isFinite(n)) return null;
|
|
1938
|
-
|
|
2071
|
+
const factor = parsed.isArbitrary ? n : n / 100;
|
|
2072
|
+
return parsed.negative ? -factor : factor;
|
|
1939
2073
|
}
|
|
1940
2074
|
function angle(parsed) {
|
|
1941
2075
|
if (parsed.value === null) return null;
|
|
@@ -2028,6 +2162,10 @@ function resolveTypographyNative(parsed, theme) {
|
|
|
2028
2162
|
case "font": {
|
|
2029
2163
|
if (parsed.value === null) return null;
|
|
2030
2164
|
if (parsed.isArbitrary) {
|
|
2165
|
+
if (arbitraryFontIsWeight(parsed, parsed.value)) {
|
|
2166
|
+
const n = Number(parsed.value);
|
|
2167
|
+
return /^\d+$/.test(parsed.value) && n % 100 === 0 && n >= 100 && n <= 900 ? [decl("font-weight", parsed.value)] : null;
|
|
2168
|
+
}
|
|
2031
2169
|
return [decl("font-family", firstFontName(parsed.value))];
|
|
2032
2170
|
}
|
|
2033
2171
|
const w = fontWeight(parsed.value);
|
|
@@ -2075,10 +2213,21 @@ function resolveTextNative(parsed, theme) {
|
|
|
2075
2213
|
if (!parsed.isArbitrary && parsed.value !== null) {
|
|
2076
2214
|
const size = textSize(parsed.value);
|
|
2077
2215
|
if (size !== null) return [decl("font-size", size)];
|
|
2216
|
+
const sized = splitSizeLeading(parsed.value);
|
|
2217
|
+
if (sized !== null) {
|
|
2218
|
+
const lh = sizeLeadingNative(sized[0], sized[1]);
|
|
2219
|
+
return lh === null ? null : [decl("font-size", sized[0]), decl("line-height", lh)];
|
|
2220
|
+
}
|
|
2078
2221
|
const align = textAlign(parsed.value);
|
|
2079
2222
|
if (align !== null) return [decl("text-align", align)];
|
|
2080
|
-
} else if (parsed.isArbitrary && parsed.value !== null
|
|
2081
|
-
|
|
2223
|
+
} else if (parsed.isArbitrary && parsed.value !== null) {
|
|
2224
|
+
const leading = parsed.modifier ?? null;
|
|
2225
|
+
if (isLength(parsed, parsed.value)) {
|
|
2226
|
+
if (leading === null) return [decl("font-size", parsed.value)];
|
|
2227
|
+
const lh = sizeLeadingNative(parsed.value, leading);
|
|
2228
|
+
return lh === null ? null : [decl("font-size", parsed.value), decl("line-height", lh)];
|
|
2229
|
+
}
|
|
2230
|
+
if (leading !== null) return null;
|
|
2082
2231
|
}
|
|
2083
2232
|
const hex = nativeHexColor(parsed, theme);
|
|
2084
2233
|
return hex === null ? null : [decl("color", hex)];
|
|
@@ -2122,7 +2271,7 @@ function nativeModifierState(modifier, theme, colorScheme, pressed, width) {
|
|
|
2122
2271
|
}
|
|
2123
2272
|
if (modifier.startsWith("max-[") && modifier.endsWith("]")) {
|
|
2124
2273
|
const px = reduceConstantMath(`calc(${modifier.slice(5, -1).trim()})`);
|
|
2125
|
-
return px === null ? null : width
|
|
2274
|
+
return px === null ? null : width < px;
|
|
2126
2275
|
}
|
|
2127
2276
|
const screen = (name) => Object.prototype.hasOwnProperty.call(theme.screens, name) ? theme.screens[name] : void 0;
|
|
2128
2277
|
const custom = screen(modifier);
|
|
@@ -2131,6 +2280,19 @@ function nativeModifierState(modifier, theme, colorScheme, pressed, width) {
|
|
|
2131
2280
|
const max = screen(modifier.slice(4));
|
|
2132
2281
|
if (typeof max === "number") return width < max;
|
|
2133
2282
|
}
|
|
2283
|
+
if (modifier.startsWith("min-")) {
|
|
2284
|
+
const min = screen(modifier.slice(4));
|
|
2285
|
+
if (typeof min === "number") return width >= min;
|
|
2286
|
+
}
|
|
2287
|
+
if (modifier.startsWith("not-")) {
|
|
2288
|
+
const rest = modifier.slice(4);
|
|
2289
|
+
if (rest === "dark") return colorScheme !== "dark";
|
|
2290
|
+
const isBreakpoint = (name) => typeof screen(name) === "number";
|
|
2291
|
+
if (isBreakpoint(rest) || (rest.startsWith("max-") || rest.startsWith("min-")) && isBreakpoint(rest.slice(4))) {
|
|
2292
|
+
const holds = nativeModifierState(rest, theme, colorScheme, pressed, width);
|
|
2293
|
+
return holds === null ? null : !holds;
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2134
2296
|
return null;
|
|
2135
2297
|
}
|
|
2136
2298
|
function kebabToCamel(s) {
|
|
@@ -2228,6 +2390,11 @@ function sanitizeForWarning(value) {
|
|
|
2228
2390
|
return `${escaped.slice(0, MAX_CHARS)}\u2026`;
|
|
2229
2391
|
}
|
|
2230
2392
|
function rnStyleValue(property, value) {
|
|
2393
|
+
if (value.startsWith("color-mix(in srgb, ") && value.endsWith(", transparent)")) {
|
|
2394
|
+
const inner = value.slice("color-mix(in srgb, ".length, -", transparent)".length);
|
|
2395
|
+
const space = inner.lastIndexOf(" ");
|
|
2396
|
+
if (space !== -1) return rnStyleValue(property, inner.slice(0, space));
|
|
2397
|
+
}
|
|
2231
2398
|
if (property === "aspect-ratio") {
|
|
2232
2399
|
if (value.trim() === "auto") return { value: null, warning: null };
|
|
2233
2400
|
const parts = value.split("/").map((s) => s.trim());
|