@kbach/react-native 1.0.0-beta.55 → 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.
@@ -33,402 +33,6 @@ 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/resolvers/color.ts
37
- function lookupHex(theme, key) {
38
- const entry = theme.colors[key];
39
- return typeof entry === "string" ? entry : null;
40
- }
41
- var MODE_AWARE_COLOR_PREFIXES = ["bg-", "text-", "border-"];
42
- function findModeAwareColor(base, theme) {
43
- const important = base.startsWith("!") ? "!" : "";
44
- const rest = important ? base.slice(1) : base;
45
- for (const prefix of MODE_AWARE_COLOR_PREFIXES) {
46
- if (!rest.startsWith(prefix)) continue;
47
- const [name, opacity] = splitOpacity(rest.slice(prefix.length));
48
- const entry = theme.colors[name];
49
- if (typeof entry === "object" && entry !== null) {
50
- return { prefix: `${important}${prefix}`, opacity, light: entry.light, dark: entry.dark };
51
- }
52
- }
53
- return null;
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})`;
60
- }
61
- function substituteModeAwareColorToken(token, theme, colorScheme) {
62
- const segments = token.split(":");
63
- const base = segments.pop() ?? token;
64
- const modifierPrefix = segments.length > 0 ? `${segments.join(":")}:` : "";
65
- const found = findModeAwareColor(base, theme);
66
- if (found === null) return token;
67
- const hex = colorScheme === "dark" ? found.dark : found.light;
68
- return `${modifierPrefix}${found.prefix}[${applyOpacityToHex(hex, found.opacity)}]`;
69
- }
70
- function classStringUsesModeAwareColor(classString, theme) {
71
- return classString.split(/\s+/).some((rawToken) => {
72
- if (!rawToken) return false;
73
- const segments = rawToken.split(":");
74
- const base = segments.pop() ?? rawToken;
75
- return findModeAwareColor(base, theme) !== null;
76
- });
77
- }
78
- function hexToRgb(hex) {
79
- const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
80
- if (!m) return null;
81
- let h = m[1];
82
- if (h.length === 3) h = h.split("").map((c) => c + c).join("");
83
- const n = parseInt(h, 16);
84
- return [n >> 16 & 255, n >> 8 & 255, n & 255];
85
- }
86
- function splitOpacity(value) {
87
- const slash = value.lastIndexOf("/");
88
- if (slash === -1) return [value, null];
89
- const opacityText = value.slice(slash + 1);
90
- const n = Number(opacityText);
91
- if (opacityText !== "" && Number.isInteger(n) && n >= 0 && n <= 100) {
92
- return [value.slice(0, slash), n];
93
- }
94
- return [value, null];
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
- return withoutUnit !== "" && Number.isFinite(Number(withoutUnit));
113
- }
114
-
115
- // src/jsxRuntimeCore.ts
116
- var import_dynamicTokens = require("./dynamicTokens");
117
-
118
- // src/jsEngine/calc.ts
119
- function reduceConstantMath(raw) {
120
- const trimmed = raw.trim();
121
- const calc = stripCall(trimmed, "calc");
122
- if (calc !== null) {
123
- return new Evaluator(calc).parseExprToEnd();
124
- }
125
- const clamp = stripCall(trimmed, "clamp");
126
- if (clamp !== null) {
127
- const args = splitTopLevelCommas(clamp);
128
- if (args.length !== 3) return null;
129
- const [min2, preferred, max2] = args.map((a) => new Evaluator(a).parseExprToEnd());
130
- if (min2 === null || preferred === null || max2 === null) return null;
131
- return Math.max(min2, Math.min(preferred, max2));
132
- }
133
- const min = stripCall(trimmed, "min");
134
- if (min !== null) {
135
- const values = splitTopLevelCommas(min).map((a) => new Evaluator(a).parseExprToEnd());
136
- return values.some((v) => v === null) ? null : Math.min(...values);
137
- }
138
- const max = stripCall(trimmed, "max");
139
- if (max !== null) {
140
- const values = splitTopLevelCommas(max).map((a) => new Evaluator(a).parseExprToEnd());
141
- return values.some((v) => v === null) ? null : Math.max(...values);
142
- }
143
- return null;
144
- }
145
- function stripCall(raw, name) {
146
- if (!raw.startsWith(name)) return null;
147
- const afterName = raw.slice(name.length).trimStart();
148
- if (!afterName.startsWith("(") || !afterName.endsWith(")")) return null;
149
- return afterName.slice(1, -1);
150
- }
151
- function splitTopLevelCommas(s) {
152
- const parts = [];
153
- let depth = 0;
154
- let start = 0;
155
- for (let i = 0; i < s.length; i++) {
156
- const ch = s[i];
157
- if (ch === "(") depth++;
158
- else if (ch === ")") depth--;
159
- else if (ch === "," && depth === 0) {
160
- parts.push(s.slice(start, i).trim());
161
- start = i + 1;
162
- }
163
- }
164
- parts.push(s.slice(start).trim());
165
- return parts;
166
- }
167
- var Evaluator = class {
168
- constructor(s) {
169
- this.pos = 0;
170
- this.s = s;
171
- }
172
- parseExprToEnd() {
173
- const value = this.expr();
174
- if (value === null) return null;
175
- this.skipWs();
176
- return this.pos === this.s.length ? value : null;
177
- }
178
- skipWs() {
179
- while (this.pos < this.s.length && /\s/.test(this.s[this.pos])) this.pos++;
180
- }
181
- peek() {
182
- this.skipWs();
183
- return this.s[this.pos];
184
- }
185
- expr() {
186
- let value = this.term();
187
- if (value === null) return null;
188
- for (; ; ) {
189
- const ch = this.peek();
190
- if (ch === "+") {
191
- this.pos++;
192
- const rhs = this.term();
193
- if (rhs === null) return null;
194
- value += rhs;
195
- } else if (ch === "-") {
196
- this.pos++;
197
- const rhs = this.term();
198
- if (rhs === null) return null;
199
- value -= rhs;
200
- } else {
201
- return value;
202
- }
203
- }
204
- }
205
- term() {
206
- let value = this.factor();
207
- if (value === null) return null;
208
- for (; ; ) {
209
- const ch = this.peek();
210
- if (ch === "*") {
211
- this.pos++;
212
- const rhs = this.factor();
213
- if (rhs === null) return null;
214
- value *= rhs;
215
- } else if (ch === "/") {
216
- this.pos++;
217
- const divisor = this.factor();
218
- if (divisor === null || divisor === 0) return null;
219
- value /= divisor;
220
- } else {
221
- return value;
222
- }
223
- }
224
- }
225
- factor() {
226
- const ch = this.peek();
227
- if (ch === void 0) return null;
228
- if (ch === "(") {
229
- this.pos++;
230
- const value = this.expr();
231
- if (value === null || this.peek() !== ")") return null;
232
- this.pos++;
233
- return value;
234
- }
235
- if (ch === "-") {
236
- this.pos++;
237
- const value = this.factor();
238
- return value === null ? null : -value;
239
- }
240
- return this.numberWithUnit();
241
- }
242
- numberWithUnit() {
243
- this.skipWs();
244
- const start = this.pos;
245
- while (this.pos < this.s.length && (/[0-9]/.test(this.s[this.pos]) || this.s[this.pos] === ".")) this.pos++;
246
- if (this.pos === start) return null;
247
- const n = Number(this.s.slice(start, this.pos));
248
- if (!Number.isFinite(n)) return null;
249
- const unitStart = this.pos;
250
- while (this.pos < this.s.length && /[a-zA-Z]/.test(this.s[this.pos])) this.pos++;
251
- const unit = this.s.slice(unitStart, this.pos);
252
- switch (unit) {
253
- case "":
254
- return n;
255
- case "px":
256
- return n;
257
- case "rem":
258
- return n * 16;
259
- default:
260
- return null;
261
- }
262
- }
263
- };
264
-
265
- // src/layoutCalc.ts
266
- var NEG = (v) => ({ percent: -v.percent, px: -v.px });
267
- var ADD = (a, b) => ({ percent: a.percent + b.percent, px: a.px + b.px });
268
- var SUB = (a, b) => ({ percent: a.percent - b.percent, px: a.px - b.px });
269
- function MUL(a, b) {
270
- if (a.percent === 0) return { percent: b.percent * a.px, px: b.px * a.px };
271
- if (b.percent === 0) return { percent: a.percent * b.px, px: a.px * b.px };
272
- return null;
273
- }
274
- function DIV(a, b) {
275
- if (b.percent !== 0 || b.px === 0) return null;
276
- return { percent: a.percent / b.px, px: a.px / b.px };
277
- }
278
- var PercentAwareEvaluator = class {
279
- constructor(s) {
280
- this.pos = 0;
281
- this.s = s;
282
- }
283
- parseExprToEnd() {
284
- const value = this.expr();
285
- if (value === null) return null;
286
- this.skipWs();
287
- return this.pos === this.s.length ? value : null;
288
- }
289
- skipWs() {
290
- while (this.pos < this.s.length && /\s/.test(this.s[this.pos])) this.pos++;
291
- }
292
- peek() {
293
- this.skipWs();
294
- return this.s[this.pos];
295
- }
296
- expr() {
297
- let value = this.term();
298
- if (value === null) return null;
299
- for (; ; ) {
300
- const ch = this.peek();
301
- if (ch === "+") {
302
- this.pos++;
303
- const rhs = this.term();
304
- if (rhs === null) return null;
305
- value = ADD(value, rhs);
306
- } else if (ch === "-") {
307
- this.pos++;
308
- const rhs = this.term();
309
- if (rhs === null) return null;
310
- value = SUB(value, rhs);
311
- } else {
312
- return value;
313
- }
314
- }
315
- }
316
- term() {
317
- let value = this.factor();
318
- if (value === null) return null;
319
- for (; ; ) {
320
- const ch = this.peek();
321
- if (ch === "*") {
322
- this.pos++;
323
- const rhs = this.factor();
324
- if (rhs === null) return null;
325
- const result = MUL(value, rhs);
326
- if (result === null) return null;
327
- value = result;
328
- } else if (ch === "/") {
329
- this.pos++;
330
- const rhs = this.factor();
331
- if (rhs === null) return null;
332
- const result = DIV(value, rhs);
333
- if (result === null) return null;
334
- value = result;
335
- } else {
336
- return value;
337
- }
338
- }
339
- }
340
- factor() {
341
- const ch = this.peek();
342
- if (ch === void 0) return null;
343
- if (ch === "(") {
344
- this.pos++;
345
- const value = this.expr();
346
- if (value === null || this.peek() !== ")") return null;
347
- this.pos++;
348
- return value;
349
- }
350
- if (ch === "-") {
351
- this.pos++;
352
- const value = this.factor();
353
- return value === null ? null : NEG(value);
354
- }
355
- return this.numberWithUnit();
356
- }
357
- numberWithUnit() {
358
- this.skipWs();
359
- const start = this.pos;
360
- while (this.pos < this.s.length && (/[0-9]/.test(this.s[this.pos]) || this.s[this.pos] === ".")) this.pos++;
361
- if (this.pos === start) return null;
362
- const n = Number(this.s.slice(start, this.pos));
363
- if (!Number.isFinite(n)) return null;
364
- if (this.s[this.pos] === "%") {
365
- this.pos++;
366
- return { percent: n, px: 0 };
367
- }
368
- const unitStart = this.pos;
369
- while (this.pos < this.s.length && /[a-zA-Z]/.test(this.s[this.pos])) this.pos++;
370
- const unit = this.s.slice(unitStart, this.pos);
371
- switch (unit) {
372
- case "":
373
- return { percent: 0, px: n };
374
- case "px":
375
- return { percent: 0, px: n };
376
- case "rem":
377
- return { percent: 0, px: n * 16 };
378
- default:
379
- return null;
380
- }
381
- }
382
- };
383
- var PERCENT_TOKEN_OUTER_RE = /^(w|h)-\[(.+)\]$/;
384
- function parsePercentRelativeCalc(token) {
385
- const m = PERCENT_TOKEN_OUTER_RE.exec(token);
386
- if (!m) return null;
387
- const property = m[1] === "w" ? "width" : "height";
388
- const inner = stripCall(m[2].replace(/_/g, " ").trim(), "calc");
389
- if (inner === null) return null;
390
- const result = new PercentAwareEvaluator(inner).parseExprToEnd();
391
- if (result === null || result.percent === 0) return null;
392
- return { property, percentCoefficient: result.percent, constantPx: result.px };
393
- }
394
- function resolvePercentRelativeCalc(basisPx, calc) {
395
- return basisPx * calc.percentCoefficient / 100 + calc.constantPx;
396
- }
397
- function parsePercentRelativeMinMaxClamp(token) {
398
- const m = PERCENT_TOKEN_OUTER_RE.exec(token);
399
- if (!m) return null;
400
- const property = m[1] === "w" ? "width" : "height";
401
- const spaced = m[2].replace(/_/g, " ");
402
- let kind;
403
- let inner;
404
- if ((inner = stripCall(spaced, "min")) !== null) kind = "min";
405
- else if ((inner = stripCall(spaced, "max")) !== null) kind = "max";
406
- else if ((inner = stripCall(spaced, "clamp")) !== null) kind = "clamp";
407
- else return null;
408
- const args = splitTopLevelCommas(inner);
409
- if (kind === "clamp" && args.length !== 3) return null;
410
- if (kind !== "clamp" && args.length < 1) return null;
411
- const operands = args.map((arg) => new PercentAwareEvaluator(arg.trim()).parseExprToEnd());
412
- if (operands.some((o) => o === null)) return null;
413
- const resolved = operands;
414
- if (!resolved.some((o) => o.percent !== 0)) return null;
415
- return {
416
- property,
417
- resolve(basisPx) {
418
- const values = resolved.map((o) => basisPx * o.percent / 100 + o.px);
419
- if (kind === "min") return Math.min(...values);
420
- if (kind === "max") return Math.max(...values);
421
- const [min, preferred, max] = values;
422
- return Math.max(min, Math.min(preferred, max));
423
- }
424
- };
425
- }
426
- function parsePercentRelativeExpr(token) {
427
- const calc = parsePercentRelativeCalc(token);
428
- if (calc) return { property: calc.property, resolve: (basisPx) => resolvePercentRelativeCalc(basisPx, calc) };
429
- return parsePercentRelativeMinMaxClamp(token);
430
- }
431
-
432
36
  // src/jsEngine/parser.ts
433
37
  var VALUE_PREFIXES = [
434
38
  "bg-opacity-",
@@ -515,6 +119,7 @@ var VALUE_PREFIXES = [
515
119
  "leading-",
516
120
  "tracking-",
517
121
  "font-",
122
+ "align-",
518
123
  "z-",
519
124
  "inset-x-",
520
125
  "inset-y-",
@@ -607,151 +212,708 @@ var ARBITRARY_PROPERTY_SENTINEL = "[arbitrary-property]";
607
212
  function isSafeArbitraryValue(value) {
608
213
  return !value.includes("{") && !value.includes("}") && !value.includes(";");
609
214
  }
610
- function normalizeMathWhitespace(raw) {
611
- if (!(raw.startsWith("calc(") || raw.startsWith("min(") || raw.startsWith("max(") || raw.startsWith("clamp("))) {
612
- return raw;
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;
267
+ }
268
+ i++;
269
+ }
270
+ return out;
271
+ }
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, " "));
298
+ }
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];
303
+ }
304
+ function parenVarShorthand(value) {
305
+ const m = /^\((?:([a-z-]+):)?--([A-Za-z0-9_-]+)\)(\/.*)?$/.exec(value);
306
+ if (!m) return null;
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];
322
+ }
323
+ }
324
+ }
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;
336
+ }
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;
340
+ }
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
+ }
383
+ }
384
+ rest = rest.slice(close + 1);
385
+ }
386
+ return out + rest;
387
+ }
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);
391
+ }
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)})`;
398
+ }
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
+ }
413
+ }
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);
426
+ }
427
+ const negative = base.startsWith("-");
428
+ if (negative) {
429
+ base = base.slice(1);
430
+ }
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
+ };
448
+ }
449
+ }
450
+ }
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;
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
+ };
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
+ };
498
+ }
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 };
525
+ }
613
526
  }
614
- const chars = Array.from(raw);
615
- let out = "";
616
- let i = 0;
617
- let prevEndsValue = false;
618
- while (i < chars.length) {
619
- const c = chars[i];
620
- if (c === "v" && chars[i + 1] === "a" && chars[i + 2] === "r" && chars[i + 3] === "(") {
621
- const start = i;
622
- let depth = 0;
623
- while (i < chars.length) {
624
- if (chars[i] === "(") depth++;
625
- else if (chars[i] === ")") {
626
- depth--;
627
- if (depth === 0) {
628
- i++;
629
- break;
630
- }
631
- }
632
- i++;
527
+ return null;
528
+ }
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, "_");
533
+ }
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());
553
+ if (!m) return null;
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];
558
+ }
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];
564
+ }
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);
573
+ }
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;
598
+ }
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;
633
688
  }
634
- out += chars.slice(start, i).join("");
635
- prevEndsValue = true;
636
- continue;
637
689
  }
638
- if (c === "+" || c === "-") {
639
- if (prevEndsValue) {
640
- out += ` ${c} `;
641
- i++;
642
- while (i < chars.length && /\s/.test(chars[i])) i++;
643
- prevEndsValue = false;
644
- continue;
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;
645
708
  }
646
- out += c;
647
- prevEndsValue = false;
648
- } else if (c === "(" || c === ",") {
649
- out += c;
650
- if (c === ",") out += " ";
651
- prevEndsValue = false;
652
- } else if (c === ")") {
653
- out += c;
654
- prevEndsValue = true;
655
- } else if (/\s/.test(c)) {
656
- } else if (c === "*" || c === "/") {
657
- out += c;
658
- prevEndsValue = false;
659
- } else {
660
- out += c;
661
- prevEndsValue = true;
662
709
  }
663
- i++;
664
710
  }
665
- return out;
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;
725
+ }
726
+ return this.numberWithUnit();
727
+ }
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;
666
759
  }
667
- function splitRespectingBrackets(token) {
668
- const parts = [];
669
- let depth = 0;
670
- let start = 0;
671
- for (let i = 0; i < token.length; i++) {
672
- const ch = token[i];
673
- if (ch === "[") depth += 1;
674
- else if (ch === "]") depth -= 1;
675
- else if (ch === ":" && depth <= 0) {
676
- parts.push(token.slice(start, i));
677
- start = i + 1;
678
- }
679
- }
680
- parts.push(token.slice(start));
681
- return parts;
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 };
682
763
  }
683
- function parseClass(token) {
684
- const parts = splitRespectingBrackets(token);
685
- let base = parts.pop() ?? token;
686
- const modifiers = parts;
687
- const important = base.startsWith("!");
688
- if (important) {
689
- base = base.slice(1);
764
+ var PercentAwareEvaluator = class {
765
+ constructor(s) {
766
+ this.pos = 0;
767
+ this.s = s;
690
768
  }
691
- const negative = base.startsWith("-");
692
- if (negative) {
693
- base = base.slice(1);
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;
694
774
  }
695
- if (base.length >= 2 && base.startsWith("[") && base.endsWith("]")) {
696
- const raw = base.slice(1, -1);
697
- const colonIdx = raw.indexOf(":");
698
- if (colonIdx !== -1) {
699
- const property = raw.slice(0, colonIdx);
700
- const rawValue = raw.slice(colonIdx + 1);
701
- if (property !== "" && rawValue !== "" && isSafeArbitraryValue(raw)) {
702
- const value = normalizeMathWhitespace(rawValue.replace(/_/g, " "));
703
- return {
704
- modifiers,
705
- utility: ARBITRARY_PROPERTY_SENTINEL,
706
- value: `${property}:${value}`,
707
- isArbitrary: true,
708
- important,
709
- negative,
710
- original: token
711
- };
775
+ skipWs() {
776
+ while (this.pos < this.s.length && /\s/.test(this.s[this.pos])) this.pos++;
777
+ }
778
+ peek() {
779
+ this.skipWs();
780
+ return this.s[this.pos];
781
+ }
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;
712
799
  }
713
800
  }
714
801
  }
715
- for (const prefix of VALUE_PREFIXES) {
716
- if (!base.startsWith(prefix)) continue;
717
- const value = base.slice(prefix.length);
718
- if (value === "") continue;
719
- if (value.length >= 2 && value.startsWith("[") && value.endsWith("]")) {
720
- const raw = value.slice(1, -1);
721
- if (!isSafeArbitraryValue(raw)) {
722
- continue;
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;
723
823
  }
724
- const spaced = normalizeMathWhitespace(raw.replace(/_/g, " "));
725
- return {
726
- modifiers,
727
- utility: prefix.slice(0, -1),
728
- value: spaced,
729
- isArbitrary: true,
730
- important,
731
- negative,
732
- original: token
733
- };
734
824
  }
735
- return {
736
- modifiers,
737
- utility: prefix.slice(0, -1),
738
- value,
739
- isArbitrary: false,
740
- important,
741
- negative,
742
- original: token
743
- };
744
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;
745
901
  return {
746
- modifiers,
747
- utility: base,
748
- value: null,
749
- isArbitrary: false,
750
- important,
751
- negative,
752
- original: token
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
+ }
753
910
  };
754
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
+ }
755
917
 
756
918
  // src/jsxRuntimeCore.ts
757
919
  var DYNAMIC_TOKEN_MATCH_RE = /var\(--([a-zA-Z0-9-]+)\)/g;
@@ -1036,6 +1198,11 @@ function resolveNegatableSize(theme, parsed) {
1036
1198
  }
1037
1199
  return resolveNegatableLength(theme, parsed);
1038
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
+ }
1039
1206
  function resolvePercent(parsed) {
1040
1207
  if (parsed.negative) return null;
1041
1208
  const value = parsed.value;
@@ -1050,6 +1217,8 @@ function resolvePercent(parsed) {
1050
1217
  function negateRaw(value, negative) {
1051
1218
  return negative ? `-${value}` : value;
1052
1219
  }
1220
+ var WHOLE = /^\d+$/;
1221
+ var PLAIN_NUMBER = /^(?:\d+\.?\d*|\.\d+)$/;
1053
1222
  function overflowAxisValue(property, value) {
1054
1223
  switch (value) {
1055
1224
  case "auto":
@@ -1180,14 +1349,29 @@ function resolve(parsed, theme) {
1180
1349
  return [decl("position", "fixed")];
1181
1350
  case "sticky":
1182
1351
  return [decl("position", "sticky")];
1183
- case "z":
1184
- return parsed.value === null ? null : [decl("z-index", negateRaw(parsed.value, parsed.negative))];
1185
- case "order":
1186
- return parsed.value === null ? null : [decl("order", negateRaw(parsed.value, parsed.negative))];
1352
+ // Only real values, mirroring layout.rs: a whole number, z-auto, the
1353
+ // order-first/-last/-none keywords, or an arbitrary [...]. Anything
1354
+ // else used to pass straight through (z-banana -> z-index: banana).
1355
+ case "z": {
1356
+ const v = parsed.value;
1357
+ if (v === null || !(parsed.isArbitrary || v === "auto" || WHOLE.test(v))) return null;
1358
+ return [decl("z-index", negateRaw(v, parsed.negative))];
1359
+ }
1360
+ case "order": {
1361
+ const v = parsed.value;
1362
+ if (v === null) return null;
1363
+ if (v === "first") return [decl("order", "-9999")];
1364
+ if (v === "last") return [decl("order", "9999")];
1365
+ if (v === "none") return [decl("order", "0")];
1366
+ if (!(parsed.isArbitrary || WHOLE.test(v))) return null;
1367
+ return [decl("order", negateRaw(v, parsed.negative))];
1368
+ }
1187
1369
  case "grow":
1188
- return [decl("flex-grow", parsed.value ?? "1")];
1189
- case "shrink":
1190
- return [decl("flex-shrink", parsed.value ?? "1")];
1370
+ case "shrink": {
1371
+ const v = parsed.value ?? "1";
1372
+ if (!(parsed.isArbitrary || PLAIN_NUMBER.test(v))) return null;
1373
+ return [decl(parsed.utility === "grow" ? "flex-grow" : "flex-shrink", v)];
1374
+ }
1191
1375
  // top/right/bottom/left/inset support real Tailwind's negative-value
1192
1376
  // convention ("-top-4") AND its percentage-fraction scale ("top-1/2",
1193
1377
  // "-inset-1/3") — see resolveNegatableSize's own doc comment.
@@ -1244,8 +1428,10 @@ function resolve(parsed, theme) {
1244
1428
  return [decl("aspect-ratio", "16 / 9")];
1245
1429
  case "auto":
1246
1430
  return [decl("aspect-ratio", "auto")];
1247
- default:
1248
- return null;
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
+ }
1249
1435
  }
1250
1436
  }
1251
1437
  default:
@@ -1525,7 +1711,7 @@ function borderValue(theme, parsed) {
1525
1711
  if (value === "separate") return [decl("border-collapse", "separate")];
1526
1712
  }
1527
1713
  if (parsed.isArbitrary) {
1528
- if (looksLikeLength(value)) return [decl("border-width", value)];
1714
+ if (isLength(parsed, value)) return [decl("border-width", value)];
1529
1715
  const color2 = colorValue(theme, parsed);
1530
1716
  return color2 === null ? null : [decl("border-color", color2)];
1531
1717
  }
@@ -1543,7 +1729,7 @@ function borderSideValue(theme, parsed, sideProperty) {
1543
1729
  const value = parsed.value;
1544
1730
  if (value === null) return null;
1545
1731
  if (parsed.isArbitrary) {
1546
- if (looksLikeLength(value)) return [decl(`${sideProperty}-width`, value)];
1732
+ if (isLength(parsed, value)) return [decl(`${sideProperty}-width`, value)];
1547
1733
  const color2 = colorValue(theme, parsed);
1548
1734
  return color2 === null ? null : [decl(`${sideProperty}-color`, color2)];
1549
1735
  }
@@ -1561,7 +1747,7 @@ function borderAxisValue(theme, parsed, sideA, sideB) {
1561
1747
  const value = parsed.value;
1562
1748
  if (value === null) return null;
1563
1749
  if (parsed.isArbitrary) {
1564
- if (looksLikeLength(value)) return [decl(`${sideA}-width`, value), decl(`${sideB}-width`, value)];
1750
+ if (isLength(parsed, value)) return [decl(`${sideA}-width`, value), decl(`${sideB}-width`, value)];
1565
1751
  const color2 = colorValue(theme, parsed);
1566
1752
  return color2 === null ? null : [decl(`${sideA}-color`, color2), decl(`${sideB}-color`, color2)];
1567
1753
  }
@@ -1619,7 +1805,7 @@ function outlineValue(theme, parsed) {
1619
1805
  const value = parsed.value;
1620
1806
  if (value === null) return null;
1621
1807
  if (parsed.isArbitrary) {
1622
- if (looksLikeLength(value)) return [decl("outline-width", value)];
1808
+ if (isLength(parsed, value)) return [decl("outline-width", value)];
1623
1809
  const color2 = colorValue(theme, parsed);
1624
1810
  return color2 === null ? null : [decl("outline-color", color2)];
1625
1811
  }
@@ -1632,9 +1818,9 @@ function outlineValue(theme, parsed) {
1632
1818
  function outlineOffsetValue(parsed) {
1633
1819
  const value = parsed.value;
1634
1820
  if (value === null) return null;
1635
- if (parsed.isArbitrary) return [decl("outline-offset", value)];
1636
- const w = outlineWidthValue(value);
1637
- return w === null ? null : [decl("outline-offset", w)];
1821
+ const v = parsed.isArbitrary ? value : outlineWidthValue(value);
1822
+ if (v === null) return null;
1823
+ return [decl("outline-offset", parsed.negative ? negate(v) : v)];
1638
1824
  }
1639
1825
  var RADIUS_SIDES = /* @__PURE__ */ new Set(["t", "r", "b", "l", "tl", "tr", "br", "bl"]);
1640
1826
  function resolve3(parsed, theme) {
@@ -1727,6 +1913,55 @@ function lineHeightSize(key) {
1727
1913
  const n = Number(key);
1728
1914
  return Number.isFinite(n) && n >= 0 ? `${n * 0.25}rem` : null;
1729
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
+ }
1730
1965
  function textAlign(key) {
1731
1966
  switch (key) {
1732
1967
  case "left":
@@ -1830,14 +2065,20 @@ function nativeShadowDeclarations(parsed) {
1830
2065
 
1831
2066
  // src/jsEngine/resolvers/transform.ts
1832
2067
  function scaleFactor(parsed) {
1833
- if (parsed.value === null) return null;
2068
+ if (parsed.value === null || parsed.value.trim() === "") return null;
1834
2069
  const n = Number(parsed.value);
1835
2070
  if (!Number.isFinite(n)) return null;
1836
- return parsed.isArbitrary ? n : n / 100;
2071
+ const factor = parsed.isArbitrary ? n : n / 100;
2072
+ return parsed.negative ? -factor : factor;
1837
2073
  }
1838
2074
  function angle(parsed) {
1839
2075
  if (parsed.value === null) return null;
1840
- if (parsed.isArbitrary) return parsed.value;
2076
+ if (parsed.isArbitrary) {
2077
+ if (!parsed.negative) return parsed.value;
2078
+ if (parsed.value.startsWith("-")) return parsed.value.slice(1);
2079
+ if (/^[\d.]/.test(parsed.value)) return `-${parsed.value}`;
2080
+ return `calc(${parsed.value} * -1)`;
2081
+ }
1841
2082
  const n = Number(parsed.value);
1842
2083
  if (!Number.isFinite(n)) return null;
1843
2084
  return `${parsed.negative ? -n : n}deg`;
@@ -1921,6 +2162,10 @@ function resolveTypographyNative(parsed, theme) {
1921
2162
  case "font": {
1922
2163
  if (parsed.value === null) return null;
1923
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
+ }
1924
2169
  return [decl("font-family", firstFontName(parsed.value))];
1925
2170
  }
1926
2171
  const w = fontWeight(parsed.value);
@@ -1968,10 +2213,21 @@ function resolveTextNative(parsed, theme) {
1968
2213
  if (!parsed.isArbitrary && parsed.value !== null) {
1969
2214
  const size = textSize(parsed.value);
1970
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
+ }
1971
2221
  const align = textAlign(parsed.value);
1972
2222
  if (align !== null) return [decl("text-align", align)];
1973
- } else if (parsed.isArbitrary && parsed.value !== null && looksLikeLength(parsed.value)) {
1974
- return [decl("font-size", parsed.value)];
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;
1975
2231
  }
1976
2232
  const hex = nativeHexColor(parsed, theme);
1977
2233
  return hex === null ? null : [decl("color", hex)];
@@ -2015,7 +2271,27 @@ function nativeModifierState(modifier, theme, colorScheme, pressed, width) {
2015
2271
  }
2016
2272
  if (modifier.startsWith("max-[") && modifier.endsWith("]")) {
2017
2273
  const px = reduceConstantMath(`calc(${modifier.slice(5, -1).trim()})`);
2018
- return px === null ? null : width <= px;
2274
+ return px === null ? null : width < px;
2275
+ }
2276
+ const screen = (name) => Object.prototype.hasOwnProperty.call(theme.screens, name) ? theme.screens[name] : void 0;
2277
+ const custom = screen(modifier);
2278
+ if (typeof custom === "number") return width >= custom;
2279
+ if (modifier.startsWith("max-")) {
2280
+ const max = screen(modifier.slice(4));
2281
+ if (typeof max === "number") return width < max;
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
+ }
2019
2295
  }
2020
2296
  return null;
2021
2297
  }
@@ -2114,6 +2390,11 @@ function sanitizeForWarning(value) {
2114
2390
  return `${escaped.slice(0, MAX_CHARS)}\u2026`;
2115
2391
  }
2116
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
+ }
2117
2398
  if (property === "aspect-ratio") {
2118
2399
  if (value.trim() === "auto") return { value: null, warning: null };
2119
2400
  const parts = value.split("/").map((s) => s.trim());
@@ -2180,7 +2461,7 @@ function resolveStyleJsWithWarnings(classString, theme, colorScheme, pressed, wi
2180
2461
  if (d.property.startsWith("__")) {
2181
2462
  continue;
2182
2463
  }
2183
- if (d.property.startsWith("--") || d.value.includes("var(") || d.property === "outline" || d.property === "object-position" || d.property === "container-type") {
2464
+ if (d.property.startsWith("--") || d.value.includes("var(") || d.property === "outline" || d.property === "object-position" || d.property === "container-type" || d.property === "container-name") {
2184
2465
  continue;
2185
2466
  }
2186
2467
  if (d.property === "shadow-offset-x" || d.property === "shadow-offset-y") {