@kbach/react-native 1.0.0-beta.55 → 1.0.0-beta.56

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getTheme
3
- } from "./chunk-CAD43NRG.mjs";
3
+ } from "./chunk-4WQ2DOOC.mjs";
4
4
 
5
5
  // src/darkModeStore.ts
6
6
  import { Appearance } from "react-native";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  resolveClassName
3
- } from "./chunk-CAD43NRG.mjs";
3
+ } from "./chunk-4WQ2DOOC.mjs";
4
4
 
5
5
  // src/jsxRuntimeCoreWeb.ts
6
6
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
package/dist/index.js CHANGED
@@ -302,14 +302,68 @@ function normalizeMathWhitespace(raw) {
302
302
  }
303
303
  return out;
304
304
  }
305
+ var TYPE_HINTS = /* @__PURE__ */ new Set([
306
+ "color",
307
+ "length",
308
+ "size",
309
+ "line-width",
310
+ "percentage",
311
+ "number",
312
+ "integer",
313
+ "image",
314
+ "url",
315
+ "position",
316
+ "bg-size",
317
+ "family-name",
318
+ "absolute-size",
319
+ "relative-size",
320
+ "angle",
321
+ "shadow",
322
+ "any"
323
+ ]);
324
+ function splitTypeHint(raw) {
325
+ const i = raw.indexOf(":");
326
+ if (i > 0 && i < raw.length - 1 && TYPE_HINTS.has(raw.slice(0, i))) return [raw.slice(0, i), raw.slice(i + 1)];
327
+ return [null, raw];
328
+ }
329
+ function parenVarShorthand(value) {
330
+ const m = /^\((?:([a-z-]+):)?--([A-Za-z0-9_-]+)\)(\/.*)?$/.exec(value);
331
+ if (!m) return null;
332
+ const [, hint, name, tail = ""] = m;
333
+ if (hint !== void 0 && !TYPE_HINTS.has(hint)) return null;
334
+ return hint ? `[${hint}:var(--${name})]${tail}` : `[var(--${name})]${tail}`;
335
+ }
336
+ function splitArbitraryOpacity(value) {
337
+ if (value.startsWith("[")) {
338
+ const i = value.lastIndexOf("]/");
339
+ if (i !== -1) {
340
+ const pct = value.slice(i + 2);
341
+ if (/^\d+$/.test(pct) && Number(pct) <= 100) return [value.slice(0, i + 1), Number(pct)];
342
+ }
343
+ }
344
+ return [value, null];
345
+ }
346
+ var COLOR_FUNCTIONS = ["rgb(", "rgba(", "hsl(", "hsla(", "hwb(", "lab(", "lch(", "oklab(", "oklch(", "color(", "color-mix(", "var("];
347
+ function looksLikeColor(value) {
348
+ return value.startsWith("#") || COLOR_FUNCTIONS.some((f) => value.startsWith(f)) || /^[A-Za-z]+$/.test(value);
349
+ }
350
+ function colorWithOpacity(color, pct) {
351
+ const m = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.exec(color);
352
+ if (m) {
353
+ const h = m[1].length === 3 ? m[1].split("").map((c) => c + c).join("") : m[1];
354
+ const [r, g, b] = [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
355
+ return `rgba(${r},${g},${b},${pct / 100})`;
356
+ }
357
+ return `color-mix(in srgb, ${color} ${pct}%, transparent)`;
358
+ }
305
359
  function splitRespectingBrackets(token) {
306
360
  const parts = [];
307
361
  let depth = 0;
308
362
  let start = 0;
309
363
  for (let i = 0; i < token.length; i++) {
310
364
  const ch = token[i];
311
- if (ch === "[") depth += 1;
312
- else if (ch === "]") depth -= 1;
365
+ if (ch === "[" || ch === "(") depth += 1;
366
+ else if (ch === "]" || ch === ")") depth -= 1;
313
367
  else if (ch === ":" && depth <= 0) {
314
368
  parts.push(token.slice(start, i));
315
369
  start = i + 1;
@@ -322,9 +376,11 @@ function parseClass(token) {
322
376
  const parts = splitRespectingBrackets(token);
323
377
  let base = parts.pop() ?? token;
324
378
  const modifiers = parts;
325
- const important = base.startsWith("!");
326
- if (important) {
379
+ const important = base.startsWith("!") || base.length > 1 && base.endsWith("!");
380
+ if (base.startsWith("!")) {
327
381
  base = base.slice(1);
382
+ } else if (important) {
383
+ base = base.slice(0, -1);
328
384
  }
329
385
  const negative = base.startsWith("-");
330
386
  if (negative) {
@@ -352,18 +408,26 @@ function parseClass(token) {
352
408
  }
353
409
  for (const prefix of VALUE_PREFIXES) {
354
410
  if (!base.startsWith(prefix)) continue;
355
- const value = base.slice(prefix.length);
356
- if (value === "") continue;
411
+ const written = base.slice(prefix.length);
412
+ if (written === "") continue;
413
+ const [value, arbitraryOpacity] = splitArbitraryOpacity(parenVarShorthand(written) ?? written);
357
414
  if (value.length >= 2 && value.startsWith("[") && value.endsWith("]")) {
358
415
  const raw = value.slice(1, -1);
359
416
  if (!isSafeArbitraryValue(raw)) {
360
417
  continue;
361
418
  }
362
419
  const spaced = normalizeMathWhitespace(raw.replace(/_/g, " "));
420
+ let [typeHint, hinted] = splitTypeHint(spaced);
421
+ if (arbitraryOpacity !== null) {
422
+ if (!(typeHint === "color" || typeHint === null && looksLikeColor(hinted))) continue;
423
+ hinted = colorWithOpacity(hinted, arbitraryOpacity);
424
+ typeHint = "color";
425
+ }
363
426
  return {
364
427
  modifiers,
365
428
  utility: prefix.slice(0, -1),
366
- value: spaced,
429
+ value: hinted,
430
+ typeHint,
367
431
  isArbitrary: true,
368
432
  important,
369
433
  negative,
@@ -373,7 +437,8 @@ function parseClass(token) {
373
437
  return {
374
438
  modifiers,
375
439
  utility: prefix.slice(0, -1),
376
- value,
440
+ // a named value keeps its own /opacity (`bg-blue-6/50`)
441
+ value: arbitraryOpacity === null ? value : `${value}/${arbitraryOpacity}`,
377
442
  isArbitrary: false,
378
443
  important,
379
444
  negative,
@@ -461,6 +526,8 @@ function resolvePercent(parsed) {
461
526
  function negateRaw(value, negative) {
462
527
  return negative ? `-${value}` : value;
463
528
  }
529
+ var WHOLE = /^\d+$/;
530
+ var PLAIN_NUMBER = /^(?:\d+\.?\d*|\.\d+)$/;
464
531
  function overflowAxisValue(property, value) {
465
532
  switch (value) {
466
533
  case "auto":
@@ -591,14 +658,29 @@ function resolve(parsed, theme) {
591
658
  return [decl("position", "fixed")];
592
659
  case "sticky":
593
660
  return [decl("position", "sticky")];
594
- case "z":
595
- return parsed.value === null ? null : [decl("z-index", negateRaw(parsed.value, parsed.negative))];
596
- case "order":
597
- return parsed.value === null ? null : [decl("order", negateRaw(parsed.value, parsed.negative))];
661
+ // Only real values, mirroring layout.rs: a whole number, z-auto, the
662
+ // order-first/-last/-none keywords, or an arbitrary [...]. Anything
663
+ // else used to pass straight through (z-banana -> z-index: banana).
664
+ case "z": {
665
+ const v = parsed.value;
666
+ if (v === null || !(parsed.isArbitrary || v === "auto" || WHOLE.test(v))) return null;
667
+ return [decl("z-index", negateRaw(v, parsed.negative))];
668
+ }
669
+ case "order": {
670
+ const v = parsed.value;
671
+ if (v === null) return null;
672
+ if (v === "first") return [decl("order", "-9999")];
673
+ if (v === "last") return [decl("order", "9999")];
674
+ if (v === "none") return [decl("order", "0")];
675
+ if (!(parsed.isArbitrary || WHOLE.test(v))) return null;
676
+ return [decl("order", negateRaw(v, parsed.negative))];
677
+ }
598
678
  case "grow":
599
- return [decl("flex-grow", parsed.value ?? "1")];
600
- case "shrink":
601
- return [decl("flex-shrink", parsed.value ?? "1")];
679
+ case "shrink": {
680
+ const v = parsed.value ?? "1";
681
+ if (!(parsed.isArbitrary || PLAIN_NUMBER.test(v))) return null;
682
+ return [decl(parsed.utility === "grow" ? "flex-grow" : "flex-shrink", v)];
683
+ }
602
684
  // top/right/bottom/left/inset support real Tailwind's negative-value
603
685
  // convention ("-top-4") AND its percentage-fraction scale ("top-1/2",
604
686
  // "-inset-1/3") — see resolveNegatableSize's own doc comment.
@@ -936,7 +1018,27 @@ var LENGTH_UNITS = ["px", "rem", "em", "%", "vh", "vw"];
936
1018
  function looksLikeLength(value) {
937
1019
  const unit = LENGTH_UNITS.find((u) => value.endsWith(u));
938
1020
  const withoutUnit = unit ? value.slice(0, value.length - unit.length) : value;
939
- return withoutUnit !== "" && Number.isFinite(Number(withoutUnit));
1021
+ if (withoutUnit !== "" && Number.isFinite(Number(withoutUnit))) return true;
1022
+ if (!["calc(", "clamp(", "min(", "max("].some((f) => value.startsWith(f))) return false;
1023
+ return MATH_LENGTH_UNIT.test(value);
1024
+ }
1025
+ 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])/;
1026
+ function isLength(parsed, value) {
1027
+ switch (parsed.typeHint ?? null) {
1028
+ case null:
1029
+ return looksLikeLength(value);
1030
+ case "length":
1031
+ case "size":
1032
+ case "line-width":
1033
+ case "percentage":
1034
+ case "number":
1035
+ case "integer":
1036
+ case "absolute-size":
1037
+ case "relative-size":
1038
+ return true;
1039
+ default:
1040
+ return false;
1041
+ }
940
1042
  }
941
1043
 
942
1044
  // src/jsEngine/resolvers/border.ts
@@ -1007,7 +1109,7 @@ function borderValue(theme, parsed) {
1007
1109
  if (value === "separate") return [decl("border-collapse", "separate")];
1008
1110
  }
1009
1111
  if (parsed.isArbitrary) {
1010
- if (looksLikeLength(value)) return [decl("border-width", value)];
1112
+ if (isLength(parsed, value)) return [decl("border-width", value)];
1011
1113
  const color2 = colorValue(theme, parsed);
1012
1114
  return color2 === null ? null : [decl("border-color", color2)];
1013
1115
  }
@@ -1025,7 +1127,7 @@ function borderSideValue(theme, parsed, sideProperty) {
1025
1127
  const value = parsed.value;
1026
1128
  if (value === null) return null;
1027
1129
  if (parsed.isArbitrary) {
1028
- if (looksLikeLength(value)) return [decl(`${sideProperty}-width`, value)];
1130
+ if (isLength(parsed, value)) return [decl(`${sideProperty}-width`, value)];
1029
1131
  const color2 = colorValue(theme, parsed);
1030
1132
  return color2 === null ? null : [decl(`${sideProperty}-color`, color2)];
1031
1133
  }
@@ -1043,7 +1145,7 @@ function borderAxisValue(theme, parsed, sideA, sideB) {
1043
1145
  const value = parsed.value;
1044
1146
  if (value === null) return null;
1045
1147
  if (parsed.isArbitrary) {
1046
- if (looksLikeLength(value)) return [decl(`${sideA}-width`, value), decl(`${sideB}-width`, value)];
1148
+ if (isLength(parsed, value)) return [decl(`${sideA}-width`, value), decl(`${sideB}-width`, value)];
1047
1149
  const color2 = colorValue(theme, parsed);
1048
1150
  return color2 === null ? null : [decl(`${sideA}-color`, color2), decl(`${sideB}-color`, color2)];
1049
1151
  }
@@ -1101,7 +1203,7 @@ function outlineValue(theme, parsed) {
1101
1203
  const value = parsed.value;
1102
1204
  if (value === null) return null;
1103
1205
  if (parsed.isArbitrary) {
1104
- if (looksLikeLength(value)) return [decl("outline-width", value)];
1206
+ if (isLength(parsed, value)) return [decl("outline-width", value)];
1105
1207
  const color2 = colorValue(theme, parsed);
1106
1208
  return color2 === null ? null : [decl("outline-color", color2)];
1107
1209
  }
@@ -1319,7 +1421,12 @@ function scaleFactor(parsed) {
1319
1421
  }
1320
1422
  function angle(parsed) {
1321
1423
  if (parsed.value === null) return null;
1322
- if (parsed.isArbitrary) return parsed.value;
1424
+ if (parsed.isArbitrary) {
1425
+ if (!parsed.negative) return parsed.value;
1426
+ if (parsed.value.startsWith("-")) return parsed.value.slice(1);
1427
+ if (/^[\d.]/.test(parsed.value)) return `-${parsed.value}`;
1428
+ return `calc(${parsed.value} * -1)`;
1429
+ }
1323
1430
  const n = Number(parsed.value);
1324
1431
  if (!Number.isFinite(n)) return null;
1325
1432
  return `${parsed.negative ? -n : n}deg`;
@@ -1452,7 +1559,7 @@ function resolveTextNative(parsed, theme) {
1452
1559
  if (size !== null) return [decl("font-size", size)];
1453
1560
  const align = textAlign(parsed.value);
1454
1561
  if (align !== null) return [decl("text-align", align)];
1455
- } else if (parsed.isArbitrary && parsed.value !== null && looksLikeLength(parsed.value)) {
1562
+ } else if (parsed.isArbitrary && parsed.value !== null && isLength(parsed, parsed.value)) {
1456
1563
  return [decl("font-size", parsed.value)];
1457
1564
  }
1458
1565
  const hex = nativeHexColor(parsed, theme);
@@ -1646,6 +1753,13 @@ function nativeModifierState(modifier, theme, colorScheme, pressed, width) {
1646
1753
  const px = reduceConstantMath(`calc(${modifier.slice(5, -1).trim()})`);
1647
1754
  return px === null ? null : width <= px;
1648
1755
  }
1756
+ const screen = (name) => Object.prototype.hasOwnProperty.call(theme.screens, name) ? theme.screens[name] : void 0;
1757
+ const custom = screen(modifier);
1758
+ if (typeof custom === "number") return width >= custom;
1759
+ if (modifier.startsWith("max-")) {
1760
+ const max = screen(modifier.slice(4));
1761
+ if (typeof max === "number") return width < max;
1762
+ }
1649
1763
  return null;
1650
1764
  }
1651
1765
  function kebabToCamel(s) {
@@ -1809,7 +1923,7 @@ function resolveStyleJsWithWarnings(classString, theme, colorScheme, pressed, wi
1809
1923
  if (d.property.startsWith("__")) {
1810
1924
  continue;
1811
1925
  }
1812
- if (d.property.startsWith("--") || d.value.includes("var(") || d.property === "outline" || d.property === "object-position" || d.property === "container-type") {
1926
+ if (d.property.startsWith("--") || d.value.includes("var(") || d.property === "outline" || d.property === "object-position" || d.property === "container-type" || d.property === "container-name") {
1813
1927
  continue;
1814
1928
  }
1815
1929
  if (d.property === "shadow-offset-x" || d.property === "shadow-offset-y") {