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