@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.
@@ -32,402 +32,6 @@ 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/resolvers/color.ts
36
- function lookupHex(theme, key) {
37
- const entry = theme.colors[key];
38
- return typeof entry === "string" ? entry : null;
39
- }
40
- var MODE_AWARE_COLOR_PREFIXES = ["bg-", "text-", "border-"];
41
- function findModeAwareColor(base, theme) {
42
- const important = base.startsWith("!") ? "!" : "";
43
- const rest = important ? base.slice(1) : base;
44
- for (const prefix of MODE_AWARE_COLOR_PREFIXES) {
45
- if (!rest.startsWith(prefix)) continue;
46
- const [name, opacity] = splitOpacity(rest.slice(prefix.length));
47
- const entry = theme.colors[name];
48
- if (typeof entry === "object" && entry !== null) {
49
- return { prefix: `${important}${prefix}`, opacity, light: entry.light, dark: entry.dark };
50
- }
51
- }
52
- return null;
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})`;
59
- }
60
- function substituteModeAwareColorToken(token, theme, colorScheme) {
61
- const segments = token.split(":");
62
- const base = segments.pop() ?? token;
63
- const modifierPrefix = segments.length > 0 ? `${segments.join(":")}:` : "";
64
- const found = findModeAwareColor(base, theme);
65
- if (found === null) return token;
66
- const hex = colorScheme === "dark" ? found.dark : found.light;
67
- return `${modifierPrefix}${found.prefix}[${applyOpacityToHex(hex, found.opacity)}]`;
68
- }
69
- function classStringUsesModeAwareColor(classString, theme) {
70
- return classString.split(/\s+/).some((rawToken) => {
71
- if (!rawToken) return false;
72
- const segments = rawToken.split(":");
73
- const base = segments.pop() ?? rawToken;
74
- return findModeAwareColor(base, theme) !== null;
75
- });
76
- }
77
- function hexToRgb(hex) {
78
- const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
79
- if (!m) return null;
80
- let h = m[1];
81
- if (h.length === 3) h = h.split("").map((c) => c + c).join("");
82
- const n = parseInt(h, 16);
83
- return [n >> 16 & 255, n >> 8 & 255, n & 255];
84
- }
85
- function splitOpacity(value) {
86
- const slash = value.lastIndexOf("/");
87
- if (slash === -1) return [value, null];
88
- const opacityText = value.slice(slash + 1);
89
- const n = Number(opacityText);
90
- if (opacityText !== "" && Number.isInteger(n) && n >= 0 && n <= 100) {
91
- return [value.slice(0, slash), n];
92
- }
93
- return [value, null];
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
- return withoutUnit !== "" && Number.isFinite(Number(withoutUnit));
112
- }
113
-
114
- // src/jsxRuntimeCore.ts
115
- var import_dynamicTokens = require("./dynamicTokens");
116
-
117
- // src/jsEngine/calc.ts
118
- function reduceConstantMath(raw) {
119
- const trimmed = raw.trim();
120
- const calc = stripCall(trimmed, "calc");
121
- if (calc !== null) {
122
- return new Evaluator(calc).parseExprToEnd();
123
- }
124
- const clamp = stripCall(trimmed, "clamp");
125
- if (clamp !== null) {
126
- const args = splitTopLevelCommas(clamp);
127
- if (args.length !== 3) return null;
128
- const [min2, preferred, max2] = args.map((a) => new Evaluator(a).parseExprToEnd());
129
- if (min2 === null || preferred === null || max2 === null) return null;
130
- return Math.max(min2, Math.min(preferred, max2));
131
- }
132
- const min = stripCall(trimmed, "min");
133
- if (min !== null) {
134
- const values = splitTopLevelCommas(min).map((a) => new Evaluator(a).parseExprToEnd());
135
- return values.some((v) => v === null) ? null : Math.min(...values);
136
- }
137
- const max = stripCall(trimmed, "max");
138
- if (max !== null) {
139
- const values = splitTopLevelCommas(max).map((a) => new Evaluator(a).parseExprToEnd());
140
- return values.some((v) => v === null) ? null : Math.max(...values);
141
- }
142
- return null;
143
- }
144
- function stripCall(raw, name) {
145
- if (!raw.startsWith(name)) return null;
146
- const afterName = raw.slice(name.length).trimStart();
147
- if (!afterName.startsWith("(") || !afterName.endsWith(")")) return null;
148
- return afterName.slice(1, -1);
149
- }
150
- function splitTopLevelCommas(s) {
151
- const parts = [];
152
- let depth = 0;
153
- let start = 0;
154
- for (let i = 0; i < s.length; i++) {
155
- const ch = s[i];
156
- if (ch === "(") depth++;
157
- else if (ch === ")") depth--;
158
- else if (ch === "," && depth === 0) {
159
- parts.push(s.slice(start, i).trim());
160
- start = i + 1;
161
- }
162
- }
163
- parts.push(s.slice(start).trim());
164
- return parts;
165
- }
166
- var Evaluator = class {
167
- constructor(s) {
168
- this.pos = 0;
169
- this.s = s;
170
- }
171
- parseExprToEnd() {
172
- const value = this.expr();
173
- if (value === null) return null;
174
- this.skipWs();
175
- return this.pos === this.s.length ? value : null;
176
- }
177
- skipWs() {
178
- while (this.pos < this.s.length && /\s/.test(this.s[this.pos])) this.pos++;
179
- }
180
- peek() {
181
- this.skipWs();
182
- return this.s[this.pos];
183
- }
184
- expr() {
185
- let value = this.term();
186
- if (value === null) return null;
187
- for (; ; ) {
188
- const ch = this.peek();
189
- if (ch === "+") {
190
- this.pos++;
191
- const rhs = this.term();
192
- if (rhs === null) return null;
193
- value += rhs;
194
- } else if (ch === "-") {
195
- this.pos++;
196
- const rhs = this.term();
197
- if (rhs === null) return null;
198
- value -= rhs;
199
- } else {
200
- return value;
201
- }
202
- }
203
- }
204
- term() {
205
- let value = this.factor();
206
- if (value === null) return null;
207
- for (; ; ) {
208
- const ch = this.peek();
209
- if (ch === "*") {
210
- this.pos++;
211
- const rhs = this.factor();
212
- if (rhs === null) return null;
213
- value *= rhs;
214
- } else if (ch === "/") {
215
- this.pos++;
216
- const divisor = this.factor();
217
- if (divisor === null || divisor === 0) return null;
218
- value /= divisor;
219
- } else {
220
- return value;
221
- }
222
- }
223
- }
224
- factor() {
225
- const ch = this.peek();
226
- if (ch === void 0) return null;
227
- if (ch === "(") {
228
- this.pos++;
229
- const value = this.expr();
230
- if (value === null || this.peek() !== ")") return null;
231
- this.pos++;
232
- return value;
233
- }
234
- if (ch === "-") {
235
- this.pos++;
236
- const value = this.factor();
237
- return value === null ? null : -value;
238
- }
239
- return this.numberWithUnit();
240
- }
241
- numberWithUnit() {
242
- this.skipWs();
243
- const start = this.pos;
244
- while (this.pos < this.s.length && (/[0-9]/.test(this.s[this.pos]) || this.s[this.pos] === ".")) this.pos++;
245
- if (this.pos === start) return null;
246
- const n = Number(this.s.slice(start, this.pos));
247
- if (!Number.isFinite(n)) return null;
248
- const unitStart = this.pos;
249
- while (this.pos < this.s.length && /[a-zA-Z]/.test(this.s[this.pos])) this.pos++;
250
- const unit = this.s.slice(unitStart, this.pos);
251
- switch (unit) {
252
- case "":
253
- return n;
254
- case "px":
255
- return n;
256
- case "rem":
257
- return n * 16;
258
- default:
259
- return null;
260
- }
261
- }
262
- };
263
-
264
- // src/layoutCalc.ts
265
- var NEG = (v) => ({ percent: -v.percent, px: -v.px });
266
- var ADD = (a, b) => ({ percent: a.percent + b.percent, px: a.px + b.px });
267
- var SUB = (a, b) => ({ percent: a.percent - b.percent, px: a.px - b.px });
268
- function MUL(a, b) {
269
- if (a.percent === 0) return { percent: b.percent * a.px, px: b.px * a.px };
270
- if (b.percent === 0) return { percent: a.percent * b.px, px: a.px * b.px };
271
- return null;
272
- }
273
- function DIV(a, b) {
274
- if (b.percent !== 0 || b.px === 0) return null;
275
- return { percent: a.percent / b.px, px: a.px / b.px };
276
- }
277
- var PercentAwareEvaluator = class {
278
- constructor(s) {
279
- this.pos = 0;
280
- this.s = s;
281
- }
282
- parseExprToEnd() {
283
- const value = this.expr();
284
- if (value === null) return null;
285
- this.skipWs();
286
- return this.pos === this.s.length ? value : null;
287
- }
288
- skipWs() {
289
- while (this.pos < this.s.length && /\s/.test(this.s[this.pos])) this.pos++;
290
- }
291
- peek() {
292
- this.skipWs();
293
- return this.s[this.pos];
294
- }
295
- expr() {
296
- let value = this.term();
297
- if (value === null) return null;
298
- for (; ; ) {
299
- const ch = this.peek();
300
- if (ch === "+") {
301
- this.pos++;
302
- const rhs = this.term();
303
- if (rhs === null) return null;
304
- value = ADD(value, rhs);
305
- } else if (ch === "-") {
306
- this.pos++;
307
- const rhs = this.term();
308
- if (rhs === null) return null;
309
- value = SUB(value, rhs);
310
- } else {
311
- return value;
312
- }
313
- }
314
- }
315
- term() {
316
- let value = this.factor();
317
- if (value === null) return null;
318
- for (; ; ) {
319
- const ch = this.peek();
320
- if (ch === "*") {
321
- this.pos++;
322
- const rhs = this.factor();
323
- if (rhs === null) return null;
324
- const result = MUL(value, rhs);
325
- if (result === null) return null;
326
- value = result;
327
- } else if (ch === "/") {
328
- this.pos++;
329
- const rhs = this.factor();
330
- if (rhs === null) return null;
331
- const result = DIV(value, rhs);
332
- if (result === null) return null;
333
- value = result;
334
- } else {
335
- return value;
336
- }
337
- }
338
- }
339
- factor() {
340
- const ch = this.peek();
341
- if (ch === void 0) return null;
342
- if (ch === "(") {
343
- this.pos++;
344
- const value = this.expr();
345
- if (value === null || this.peek() !== ")") return null;
346
- this.pos++;
347
- return value;
348
- }
349
- if (ch === "-") {
350
- this.pos++;
351
- const value = this.factor();
352
- return value === null ? null : NEG(value);
353
- }
354
- return this.numberWithUnit();
355
- }
356
- numberWithUnit() {
357
- this.skipWs();
358
- const start = this.pos;
359
- while (this.pos < this.s.length && (/[0-9]/.test(this.s[this.pos]) || this.s[this.pos] === ".")) this.pos++;
360
- if (this.pos === start) return null;
361
- const n = Number(this.s.slice(start, this.pos));
362
- if (!Number.isFinite(n)) return null;
363
- if (this.s[this.pos] === "%") {
364
- this.pos++;
365
- return { percent: n, px: 0 };
366
- }
367
- const unitStart = this.pos;
368
- while (this.pos < this.s.length && /[a-zA-Z]/.test(this.s[this.pos])) this.pos++;
369
- const unit = this.s.slice(unitStart, this.pos);
370
- switch (unit) {
371
- case "":
372
- return { percent: 0, px: n };
373
- case "px":
374
- return { percent: 0, px: n };
375
- case "rem":
376
- return { percent: 0, px: n * 16 };
377
- default:
378
- return null;
379
- }
380
- }
381
- };
382
- var PERCENT_TOKEN_OUTER_RE = /^(w|h)-\[(.+)\]$/;
383
- function parsePercentRelativeCalc(token) {
384
- const m = PERCENT_TOKEN_OUTER_RE.exec(token);
385
- if (!m) return null;
386
- const property = m[1] === "w" ? "width" : "height";
387
- const inner = stripCall(m[2].replace(/_/g, " ").trim(), "calc");
388
- if (inner === null) return null;
389
- const result = new PercentAwareEvaluator(inner).parseExprToEnd();
390
- if (result === null || result.percent === 0) return null;
391
- return { property, percentCoefficient: result.percent, constantPx: result.px };
392
- }
393
- function resolvePercentRelativeCalc(basisPx, calc) {
394
- return basisPx * calc.percentCoefficient / 100 + calc.constantPx;
395
- }
396
- function parsePercentRelativeMinMaxClamp(token) {
397
- const m = PERCENT_TOKEN_OUTER_RE.exec(token);
398
- if (!m) return null;
399
- const property = m[1] === "w" ? "width" : "height";
400
- const spaced = m[2].replace(/_/g, " ");
401
- let kind;
402
- let inner;
403
- if ((inner = stripCall(spaced, "min")) !== null) kind = "min";
404
- else if ((inner = stripCall(spaced, "max")) !== null) kind = "max";
405
- else if ((inner = stripCall(spaced, "clamp")) !== null) kind = "clamp";
406
- else return null;
407
- const args = splitTopLevelCommas(inner);
408
- if (kind === "clamp" && args.length !== 3) return null;
409
- if (kind !== "clamp" && args.length < 1) return null;
410
- const operands = args.map((arg) => new PercentAwareEvaluator(arg.trim()).parseExprToEnd());
411
- if (operands.some((o) => o === null)) return null;
412
- const resolved = operands;
413
- if (!resolved.some((o) => o.percent !== 0)) return null;
414
- return {
415
- property,
416
- resolve(basisPx) {
417
- const values = resolved.map((o) => basisPx * o.percent / 100 + o.px);
418
- if (kind === "min") return Math.min(...values);
419
- if (kind === "max") return Math.max(...values);
420
- const [min, preferred, max] = values;
421
- return Math.max(min, Math.min(preferred, max));
422
- }
423
- };
424
- }
425
- function parsePercentRelativeExpr(token) {
426
- const calc = parsePercentRelativeCalc(token);
427
- if (calc) return { property: calc.property, resolve: (basisPx) => resolvePercentRelativeCalc(basisPx, calc) };
428
- return parsePercentRelativeMinMaxClamp(token);
429
- }
430
-
431
35
  // src/jsEngine/parser.ts
432
36
  var VALUE_PREFIXES = [
433
37
  "bg-opacity-",
@@ -514,6 +118,7 @@ var VALUE_PREFIXES = [
514
118
  "leading-",
515
119
  "tracking-",
516
120
  "font-",
121
+ "align-",
517
122
  "z-",
518
123
  "inset-x-",
519
124
  "inset-y-",
@@ -606,151 +211,708 @@ var ARBITRARY_PROPERTY_SENTINEL = "[arbitrary-property]";
606
211
  function isSafeArbitraryValue(value) {
607
212
  return !value.includes("{") && !value.includes("}") && !value.includes(";");
608
213
  }
609
- function normalizeMathWhitespace(raw) {
610
- if (!(raw.startsWith("calc(") || raw.startsWith("min(") || raw.startsWith("max(") || raw.startsWith("clamp("))) {
611
- return raw;
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;
266
+ }
267
+ i++;
268
+ }
269
+ return out;
270
+ }
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, " "));
297
+ }
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];
302
+ }
303
+ function parenVarShorthand(value) {
304
+ const m = /^\((?:([a-z-]+):)?--([A-Za-z0-9_-]+)\)(\/.*)?$/.exec(value);
305
+ if (!m) return null;
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];
321
+ }
322
+ }
323
+ }
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;
335
+ }
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;
339
+ }
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
+ }
382
+ }
383
+ rest = rest.slice(close + 1);
384
+ }
385
+ return out + rest;
386
+ }
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);
390
+ }
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)})`;
397
+ }
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
+ }
412
+ }
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);
425
+ }
426
+ const negative = base.startsWith("-");
427
+ if (negative) {
428
+ base = base.slice(1);
429
+ }
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
+ };
447
+ }
448
+ }
449
+ }
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;
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
+ };
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
+ };
497
+ }
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 };
524
+ }
612
525
  }
613
- const chars = Array.from(raw);
614
- let out = "";
615
- let i = 0;
616
- let prevEndsValue = false;
617
- while (i < chars.length) {
618
- const c = chars[i];
619
- if (c === "v" && chars[i + 1] === "a" && chars[i + 2] === "r" && chars[i + 3] === "(") {
620
- const start = i;
621
- let depth = 0;
622
- while (i < chars.length) {
623
- if (chars[i] === "(") depth++;
624
- else if (chars[i] === ")") {
625
- depth--;
626
- if (depth === 0) {
627
- i++;
628
- break;
629
- }
630
- }
631
- i++;
526
+ return null;
527
+ }
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, "_");
532
+ }
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());
552
+ if (!m) return null;
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];
557
+ }
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];
563
+ }
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);
572
+ }
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;
597
+ }
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;
632
687
  }
633
- out += chars.slice(start, i).join("");
634
- prevEndsValue = true;
635
- continue;
636
688
  }
637
- if (c === "+" || c === "-") {
638
- if (prevEndsValue) {
639
- out += ` ${c} `;
640
- i++;
641
- while (i < chars.length && /\s/.test(chars[i])) i++;
642
- prevEndsValue = false;
643
- continue;
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;
644
707
  }
645
- out += c;
646
- prevEndsValue = false;
647
- } else if (c === "(" || c === ",") {
648
- out += c;
649
- if (c === ",") out += " ";
650
- prevEndsValue = false;
651
- } else if (c === ")") {
652
- out += c;
653
- prevEndsValue = true;
654
- } else if (/\s/.test(c)) {
655
- } else if (c === "*" || c === "/") {
656
- out += c;
657
- prevEndsValue = false;
658
- } else {
659
- out += c;
660
- prevEndsValue = true;
661
708
  }
662
- i++;
663
709
  }
664
- return out;
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;
724
+ }
725
+ return this.numberWithUnit();
726
+ }
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;
665
758
  }
666
- function splitRespectingBrackets(token) {
667
- const parts = [];
668
- let depth = 0;
669
- let start = 0;
670
- for (let i = 0; i < token.length; i++) {
671
- const ch = token[i];
672
- if (ch === "[") depth += 1;
673
- else if (ch === "]") depth -= 1;
674
- else if (ch === ":" && depth <= 0) {
675
- parts.push(token.slice(start, i));
676
- start = i + 1;
677
- }
678
- }
679
- parts.push(token.slice(start));
680
- return parts;
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 };
681
762
  }
682
- function parseClass(token) {
683
- const parts = splitRespectingBrackets(token);
684
- let base = parts.pop() ?? token;
685
- const modifiers = parts;
686
- const important = base.startsWith("!");
687
- if (important) {
688
- base = base.slice(1);
763
+ var PercentAwareEvaluator = class {
764
+ constructor(s) {
765
+ this.pos = 0;
766
+ this.s = s;
689
767
  }
690
- const negative = base.startsWith("-");
691
- if (negative) {
692
- base = base.slice(1);
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;
693
773
  }
694
- if (base.length >= 2 && base.startsWith("[") && base.endsWith("]")) {
695
- const raw = base.slice(1, -1);
696
- const colonIdx = raw.indexOf(":");
697
- if (colonIdx !== -1) {
698
- const property = raw.slice(0, colonIdx);
699
- const rawValue = raw.slice(colonIdx + 1);
700
- if (property !== "" && rawValue !== "" && isSafeArbitraryValue(raw)) {
701
- const value = normalizeMathWhitespace(rawValue.replace(/_/g, " "));
702
- return {
703
- modifiers,
704
- utility: ARBITRARY_PROPERTY_SENTINEL,
705
- value: `${property}:${value}`,
706
- isArbitrary: true,
707
- important,
708
- negative,
709
- original: token
710
- };
774
+ skipWs() {
775
+ while (this.pos < this.s.length && /\s/.test(this.s[this.pos])) this.pos++;
776
+ }
777
+ peek() {
778
+ this.skipWs();
779
+ return this.s[this.pos];
780
+ }
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;
711
798
  }
712
799
  }
713
800
  }
714
- for (const prefix of VALUE_PREFIXES) {
715
- if (!base.startsWith(prefix)) continue;
716
- const value = base.slice(prefix.length);
717
- if (value === "") continue;
718
- if (value.length >= 2 && value.startsWith("[") && value.endsWith("]")) {
719
- const raw = value.slice(1, -1);
720
- if (!isSafeArbitraryValue(raw)) {
721
- continue;
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;
722
822
  }
723
- const spaced = normalizeMathWhitespace(raw.replace(/_/g, " "));
724
- return {
725
- modifiers,
726
- utility: prefix.slice(0, -1),
727
- value: spaced,
728
- isArbitrary: true,
729
- important,
730
- negative,
731
- original: token
732
- };
733
823
  }
734
- return {
735
- modifiers,
736
- utility: prefix.slice(0, -1),
737
- value,
738
- isArbitrary: false,
739
- important,
740
- negative,
741
- original: token
742
- };
743
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;
744
900
  return {
745
- modifiers,
746
- utility: base,
747
- value: null,
748
- isArbitrary: false,
749
- important,
750
- negative,
751
- original: token
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
+ }
752
909
  };
753
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
+ }
754
916
 
755
917
  // src/jsxRuntimeCore.ts
756
918
  var DYNAMIC_TOKEN_MATCH_RE = /var\(--([a-zA-Z0-9-]+)\)/g;
@@ -1045,6 +1207,11 @@ function resolveNegatableSize(theme, parsed) {
1045
1207
  }
1046
1208
  return resolveNegatableLength(theme, parsed);
1047
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
+ }
1048
1215
  function resolvePercent(parsed) {
1049
1216
  if (parsed.negative) return null;
1050
1217
  const value = parsed.value;
@@ -1059,6 +1226,8 @@ function resolvePercent(parsed) {
1059
1226
  function negateRaw(value, negative) {
1060
1227
  return negative ? `-${value}` : value;
1061
1228
  }
1229
+ var WHOLE = /^\d+$/;
1230
+ var PLAIN_NUMBER = /^(?:\d+\.?\d*|\.\d+)$/;
1062
1231
  function overflowAxisValue(property, value) {
1063
1232
  switch (value) {
1064
1233
  case "auto":
@@ -1189,14 +1358,29 @@ function resolve(parsed, theme) {
1189
1358
  return [decl("position", "fixed")];
1190
1359
  case "sticky":
1191
1360
  return [decl("position", "sticky")];
1192
- case "z":
1193
- return parsed.value === null ? null : [decl("z-index", negateRaw(parsed.value, parsed.negative))];
1194
- case "order":
1195
- return parsed.value === null ? null : [decl("order", negateRaw(parsed.value, parsed.negative))];
1361
+ // Only real values, mirroring layout.rs: a whole number, z-auto, the
1362
+ // order-first/-last/-none keywords, or an arbitrary [...]. Anything
1363
+ // else used to pass straight through (z-banana -> z-index: banana).
1364
+ case "z": {
1365
+ const v = parsed.value;
1366
+ if (v === null || !(parsed.isArbitrary || v === "auto" || WHOLE.test(v))) return null;
1367
+ return [decl("z-index", negateRaw(v, parsed.negative))];
1368
+ }
1369
+ case "order": {
1370
+ const v = parsed.value;
1371
+ if (v === null) return null;
1372
+ if (v === "first") return [decl("order", "-9999")];
1373
+ if (v === "last") return [decl("order", "9999")];
1374
+ if (v === "none") return [decl("order", "0")];
1375
+ if (!(parsed.isArbitrary || WHOLE.test(v))) return null;
1376
+ return [decl("order", negateRaw(v, parsed.negative))];
1377
+ }
1196
1378
  case "grow":
1197
- return [decl("flex-grow", parsed.value ?? "1")];
1198
- case "shrink":
1199
- return [decl("flex-shrink", parsed.value ?? "1")];
1379
+ case "shrink": {
1380
+ const v = parsed.value ?? "1";
1381
+ if (!(parsed.isArbitrary || PLAIN_NUMBER.test(v))) return null;
1382
+ return [decl(parsed.utility === "grow" ? "flex-grow" : "flex-shrink", v)];
1383
+ }
1200
1384
  // top/right/bottom/left/inset support real Tailwind's negative-value
1201
1385
  // convention ("-top-4") AND its percentage-fraction scale ("top-1/2",
1202
1386
  // "-inset-1/3") — see resolveNegatableSize's own doc comment.
@@ -1253,8 +1437,10 @@ function resolve(parsed, theme) {
1253
1437
  return [decl("aspect-ratio", "16 / 9")];
1254
1438
  case "auto":
1255
1439
  return [decl("aspect-ratio", "auto")];
1256
- default:
1257
- return null;
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
+ }
1258
1444
  }
1259
1445
  }
1260
1446
  default:
@@ -1534,7 +1720,7 @@ function borderValue(theme, parsed) {
1534
1720
  if (value === "separate") return [decl("border-collapse", "separate")];
1535
1721
  }
1536
1722
  if (parsed.isArbitrary) {
1537
- if (looksLikeLength(value)) return [decl("border-width", value)];
1723
+ if (isLength(parsed, value)) return [decl("border-width", value)];
1538
1724
  const color2 = colorValue(theme, parsed);
1539
1725
  return color2 === null ? null : [decl("border-color", color2)];
1540
1726
  }
@@ -1552,7 +1738,7 @@ function borderSideValue(theme, parsed, sideProperty) {
1552
1738
  const value = parsed.value;
1553
1739
  if (value === null) return null;
1554
1740
  if (parsed.isArbitrary) {
1555
- if (looksLikeLength(value)) return [decl(`${sideProperty}-width`, value)];
1741
+ if (isLength(parsed, value)) return [decl(`${sideProperty}-width`, value)];
1556
1742
  const color2 = colorValue(theme, parsed);
1557
1743
  return color2 === null ? null : [decl(`${sideProperty}-color`, color2)];
1558
1744
  }
@@ -1570,7 +1756,7 @@ function borderAxisValue(theme, parsed, sideA, sideB) {
1570
1756
  const value = parsed.value;
1571
1757
  if (value === null) return null;
1572
1758
  if (parsed.isArbitrary) {
1573
- if (looksLikeLength(value)) return [decl(`${sideA}-width`, value), decl(`${sideB}-width`, value)];
1759
+ if (isLength(parsed, value)) return [decl(`${sideA}-width`, value), decl(`${sideB}-width`, value)];
1574
1760
  const color2 = colorValue(theme, parsed);
1575
1761
  return color2 === null ? null : [decl(`${sideA}-color`, color2), decl(`${sideB}-color`, color2)];
1576
1762
  }
@@ -1628,7 +1814,7 @@ function outlineValue(theme, parsed) {
1628
1814
  const value = parsed.value;
1629
1815
  if (value === null) return null;
1630
1816
  if (parsed.isArbitrary) {
1631
- if (looksLikeLength(value)) return [decl("outline-width", value)];
1817
+ if (isLength(parsed, value)) return [decl("outline-width", value)];
1632
1818
  const color2 = colorValue(theme, parsed);
1633
1819
  return color2 === null ? null : [decl("outline-color", color2)];
1634
1820
  }
@@ -1641,9 +1827,9 @@ function outlineValue(theme, parsed) {
1641
1827
  function outlineOffsetValue(parsed) {
1642
1828
  const value = parsed.value;
1643
1829
  if (value === null) return null;
1644
- if (parsed.isArbitrary) return [decl("outline-offset", value)];
1645
- const w = outlineWidthValue(value);
1646
- return w === null ? null : [decl("outline-offset", w)];
1830
+ const v = parsed.isArbitrary ? value : outlineWidthValue(value);
1831
+ if (v === null) return null;
1832
+ return [decl("outline-offset", parsed.negative ? negate(v) : v)];
1647
1833
  }
1648
1834
  var RADIUS_SIDES = /* @__PURE__ */ new Set(["t", "r", "b", "l", "tl", "tr", "br", "bl"]);
1649
1835
  function resolve3(parsed, theme) {
@@ -1736,6 +1922,55 @@ function lineHeightSize(key) {
1736
1922
  const n = Number(key);
1737
1923
  return Number.isFinite(n) && n >= 0 ? `${n * 0.25}rem` : null;
1738
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
+ }
1739
1974
  function textAlign(key) {
1740
1975
  switch (key) {
1741
1976
  case "left":
@@ -1839,14 +2074,20 @@ function nativeShadowDeclarations(parsed) {
1839
2074
 
1840
2075
  // src/jsEngine/resolvers/transform.ts
1841
2076
  function scaleFactor(parsed) {
1842
- if (parsed.value === null) return null;
2077
+ if (parsed.value === null || parsed.value.trim() === "") return null;
1843
2078
  const n = Number(parsed.value);
1844
2079
  if (!Number.isFinite(n)) return null;
1845
- return parsed.isArbitrary ? n : n / 100;
2080
+ const factor = parsed.isArbitrary ? n : n / 100;
2081
+ return parsed.negative ? -factor : factor;
1846
2082
  }
1847
2083
  function angle(parsed) {
1848
2084
  if (parsed.value === null) return null;
1849
- if (parsed.isArbitrary) return parsed.value;
2085
+ if (parsed.isArbitrary) {
2086
+ if (!parsed.negative) return parsed.value;
2087
+ if (parsed.value.startsWith("-")) return parsed.value.slice(1);
2088
+ if (/^[\d.]/.test(parsed.value)) return `-${parsed.value}`;
2089
+ return `calc(${parsed.value} * -1)`;
2090
+ }
1850
2091
  const n = Number(parsed.value);
1851
2092
  if (!Number.isFinite(n)) return null;
1852
2093
  return `${parsed.negative ? -n : n}deg`;
@@ -1930,6 +2171,10 @@ function resolveTypographyNative(parsed, theme) {
1930
2171
  case "font": {
1931
2172
  if (parsed.value === null) return null;
1932
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
+ }
1933
2178
  return [decl("font-family", firstFontName(parsed.value))];
1934
2179
  }
1935
2180
  const w = fontWeight(parsed.value);
@@ -1977,10 +2222,21 @@ function resolveTextNative(parsed, theme) {
1977
2222
  if (!parsed.isArbitrary && parsed.value !== null) {
1978
2223
  const size = textSize(parsed.value);
1979
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
+ }
1980
2230
  const align = textAlign(parsed.value);
1981
2231
  if (align !== null) return [decl("text-align", align)];
1982
- } else if (parsed.isArbitrary && parsed.value !== null && looksLikeLength(parsed.value)) {
1983
- return [decl("font-size", parsed.value)];
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;
1984
2240
  }
1985
2241
  const hex = nativeHexColor(parsed, theme);
1986
2242
  return hex === null ? null : [decl("color", hex)];
@@ -2024,7 +2280,27 @@ function nativeModifierState(modifier, theme, colorScheme, pressed, width) {
2024
2280
  }
2025
2281
  if (modifier.startsWith("max-[") && modifier.endsWith("]")) {
2026
2282
  const px = reduceConstantMath(`calc(${modifier.slice(5, -1).trim()})`);
2027
- return px === null ? null : width <= px;
2283
+ return px === null ? null : width < px;
2284
+ }
2285
+ const screen = (name) => Object.prototype.hasOwnProperty.call(theme.screens, name) ? theme.screens[name] : void 0;
2286
+ const custom = screen(modifier);
2287
+ if (typeof custom === "number") return width >= custom;
2288
+ if (modifier.startsWith("max-")) {
2289
+ const max = screen(modifier.slice(4));
2290
+ if (typeof max === "number") return width < max;
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
+ }
2028
2304
  }
2029
2305
  return null;
2030
2306
  }
@@ -2123,6 +2399,11 @@ function sanitizeForWarning(value) {
2123
2399
  return `${escaped.slice(0, MAX_CHARS)}\u2026`;
2124
2400
  }
2125
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
+ }
2126
2407
  if (property === "aspect-ratio") {
2127
2408
  if (value.trim() === "auto") return { value: null, warning: null };
2128
2409
  const parts = value.split("/").map((s) => s.trim());
@@ -2189,7 +2470,7 @@ function resolveStyleJsWithWarnings(classString, theme, colorScheme, pressed, wi
2189
2470
  if (d.property.startsWith("__")) {
2190
2471
  continue;
2191
2472
  }
2192
- if (d.property.startsWith("--") || d.value.includes("var(") || d.property === "outline" || d.property === "object-position" || d.property === "container-type") {
2473
+ if (d.property.startsWith("--") || d.value.includes("var(") || d.property === "outline" || d.property === "object-position" || d.property === "container-type" || d.property === "container-name") {
2193
2474
  continue;
2194
2475
  }
2195
2476
  if (d.property === "shadow-offset-x" || d.property === "shadow-offset-y") {