@kbach/react-native 1.0.0-beta.54 → 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.
@@ -10,13 +10,13 @@ import {
10
10
  subscribeDynamicTokens,
11
11
  subscribeGlobalDarkMode,
12
12
  toggleGlobalDarkMode
13
- } from "./chunk-NPDSBCXR.mjs";
13
+ } from "./chunk-VWGUF2NB.mjs";
14
14
  import {
15
15
  defaultTheme,
16
16
  getTheme,
17
17
  resolveClassName,
18
18
  setTheme
19
- } from "./chunk-MLBH2JYH.mjs";
19
+ } from "./chunk-4WQ2DOOC.mjs";
20
20
 
21
21
  // src/config.ts
22
22
  function parseHexRgb(hex) {
@@ -108,7 +108,27 @@ var LENGTH_UNITS = ["px", "rem", "em", "%", "vh", "vw"];
108
108
  function looksLikeLength(value) {
109
109
  const unit = LENGTH_UNITS.find((u) => value.endsWith(u));
110
110
  const withoutUnit = unit ? value.slice(0, value.length - unit.length) : value;
111
- return withoutUnit !== "" && Number.isFinite(Number(withoutUnit));
111
+ if (withoutUnit !== "" && Number.isFinite(Number(withoutUnit))) return true;
112
+ if (!["calc(", "clamp(", "min(", "max("].some((f) => value.startsWith(f))) return false;
113
+ return MATH_LENGTH_UNIT.test(value);
114
+ }
115
+ var MATH_LENGTH_UNIT = /\d(?:px|rem|em|%|vh|vw|vmin|vmax|dvh|dvw|svh|svw|lvh|lvw|ch|ex|lh|cqw|cqh|cqi|cqb)(?![A-Za-z])/;
116
+ function isLength(parsed, value) {
117
+ switch (parsed.typeHint ?? null) {
118
+ case null:
119
+ return looksLikeLength(value);
120
+ case "length":
121
+ case "size":
122
+ case "line-width":
123
+ case "percentage":
124
+ case "number":
125
+ case "integer":
126
+ case "absolute-size":
127
+ case "relative-size":
128
+ return true;
129
+ default:
130
+ return false;
131
+ }
112
132
  }
113
133
 
114
134
  // src/jsxRuntimeCore.ts
@@ -663,14 +683,68 @@ function normalizeMathWhitespace(raw) {
663
683
  }
664
684
  return out;
665
685
  }
686
+ var TYPE_HINTS = /* @__PURE__ */ new Set([
687
+ "color",
688
+ "length",
689
+ "size",
690
+ "line-width",
691
+ "percentage",
692
+ "number",
693
+ "integer",
694
+ "image",
695
+ "url",
696
+ "position",
697
+ "bg-size",
698
+ "family-name",
699
+ "absolute-size",
700
+ "relative-size",
701
+ "angle",
702
+ "shadow",
703
+ "any"
704
+ ]);
705
+ function splitTypeHint(raw) {
706
+ const i = raw.indexOf(":");
707
+ if (i > 0 && i < raw.length - 1 && TYPE_HINTS.has(raw.slice(0, i))) return [raw.slice(0, i), raw.slice(i + 1)];
708
+ return [null, raw];
709
+ }
710
+ function parenVarShorthand(value) {
711
+ const m = /^\((?:([a-z-]+):)?--([A-Za-z0-9_-]+)\)(\/.*)?$/.exec(value);
712
+ if (!m) return null;
713
+ const [, hint, name, tail = ""] = m;
714
+ if (hint !== void 0 && !TYPE_HINTS.has(hint)) return null;
715
+ return hint ? `[${hint}:var(--${name})]${tail}` : `[var(--${name})]${tail}`;
716
+ }
717
+ function splitArbitraryOpacity(value) {
718
+ if (value.startsWith("[")) {
719
+ const i = value.lastIndexOf("]/");
720
+ if (i !== -1) {
721
+ const pct = value.slice(i + 2);
722
+ if (/^\d+$/.test(pct) && Number(pct) <= 100) return [value.slice(0, i + 1), Number(pct)];
723
+ }
724
+ }
725
+ return [value, null];
726
+ }
727
+ var COLOR_FUNCTIONS = ["rgb(", "rgba(", "hsl(", "hsla(", "hwb(", "lab(", "lch(", "oklab(", "oklch(", "color(", "color-mix(", "var("];
728
+ function looksLikeColor(value) {
729
+ return value.startsWith("#") || COLOR_FUNCTIONS.some((f) => value.startsWith(f)) || /^[A-Za-z]+$/.test(value);
730
+ }
731
+ function colorWithOpacity(color, pct) {
732
+ const m = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.exec(color);
733
+ if (m) {
734
+ const h = m[1].length === 3 ? m[1].split("").map((c) => c + c).join("") : m[1];
735
+ const [r, g, b] = [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
736
+ return `rgba(${r},${g},${b},${pct / 100})`;
737
+ }
738
+ return `color-mix(in srgb, ${color} ${pct}%, transparent)`;
739
+ }
666
740
  function splitRespectingBrackets(token) {
667
741
  const parts = [];
668
742
  let depth = 0;
669
743
  let start = 0;
670
744
  for (let i = 0; i < token.length; i++) {
671
745
  const ch = token[i];
672
- if (ch === "[") depth += 1;
673
- else if (ch === "]") depth -= 1;
746
+ if (ch === "[" || ch === "(") depth += 1;
747
+ else if (ch === "]" || ch === ")") depth -= 1;
674
748
  else if (ch === ":" && depth <= 0) {
675
749
  parts.push(token.slice(start, i));
676
750
  start = i + 1;
@@ -683,9 +757,11 @@ function parseClass(token) {
683
757
  const parts = splitRespectingBrackets(token);
684
758
  let base = parts.pop() ?? token;
685
759
  const modifiers = parts;
686
- const important = base.startsWith("!");
687
- if (important) {
760
+ const important = base.startsWith("!") || base.length > 1 && base.endsWith("!");
761
+ if (base.startsWith("!")) {
688
762
  base = base.slice(1);
763
+ } else if (important) {
764
+ base = base.slice(0, -1);
689
765
  }
690
766
  const negative = base.startsWith("-");
691
767
  if (negative) {
@@ -713,18 +789,26 @@ function parseClass(token) {
713
789
  }
714
790
  for (const prefix of VALUE_PREFIXES) {
715
791
  if (!base.startsWith(prefix)) continue;
716
- const value = base.slice(prefix.length);
717
- if (value === "") continue;
792
+ const written = base.slice(prefix.length);
793
+ if (written === "") continue;
794
+ const [value, arbitraryOpacity] = splitArbitraryOpacity(parenVarShorthand(written) ?? written);
718
795
  if (value.length >= 2 && value.startsWith("[") && value.endsWith("]")) {
719
796
  const raw = value.slice(1, -1);
720
797
  if (!isSafeArbitraryValue(raw)) {
721
798
  continue;
722
799
  }
723
800
  const spaced = normalizeMathWhitespace(raw.replace(/_/g, " "));
801
+ let [typeHint, hinted] = splitTypeHint(spaced);
802
+ if (arbitraryOpacity !== null) {
803
+ if (!(typeHint === "color" || typeHint === null && looksLikeColor(hinted))) continue;
804
+ hinted = colorWithOpacity(hinted, arbitraryOpacity);
805
+ typeHint = "color";
806
+ }
724
807
  return {
725
808
  modifiers,
726
809
  utility: prefix.slice(0, -1),
727
- value: spaced,
810
+ value: hinted,
811
+ typeHint,
728
812
  isArbitrary: true,
729
813
  important,
730
814
  negative,
@@ -734,7 +818,8 @@ function parseClass(token) {
734
818
  return {
735
819
  modifiers,
736
820
  utility: prefix.slice(0, -1),
737
- value,
821
+ // a named value keeps its own /opacity (`bg-blue-6/50`)
822
+ value: arbitraryOpacity === null ? value : `${value}/${arbitraryOpacity}`,
738
823
  isArbitrary: false,
739
824
  important,
740
825
  negative,
@@ -1059,6 +1144,8 @@ function resolvePercent(parsed) {
1059
1144
  function negateRaw(value, negative) {
1060
1145
  return negative ? `-${value}` : value;
1061
1146
  }
1147
+ var WHOLE = /^\d+$/;
1148
+ var PLAIN_NUMBER = /^(?:\d+\.?\d*|\.\d+)$/;
1062
1149
  function overflowAxisValue(property, value) {
1063
1150
  switch (value) {
1064
1151
  case "auto":
@@ -1189,14 +1276,29 @@ function resolve(parsed, theme) {
1189
1276
  return [decl("position", "fixed")];
1190
1277
  case "sticky":
1191
1278
  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))];
1279
+ // Only real values, mirroring layout.rs: a whole number, z-auto, the
1280
+ // order-first/-last/-none keywords, or an arbitrary [...]. Anything
1281
+ // else used to pass straight through (z-banana -> z-index: banana).
1282
+ case "z": {
1283
+ const v = parsed.value;
1284
+ if (v === null || !(parsed.isArbitrary || v === "auto" || WHOLE.test(v))) return null;
1285
+ return [decl("z-index", negateRaw(v, parsed.negative))];
1286
+ }
1287
+ case "order": {
1288
+ const v = parsed.value;
1289
+ if (v === null) return null;
1290
+ if (v === "first") return [decl("order", "-9999")];
1291
+ if (v === "last") return [decl("order", "9999")];
1292
+ if (v === "none") return [decl("order", "0")];
1293
+ if (!(parsed.isArbitrary || WHOLE.test(v))) return null;
1294
+ return [decl("order", negateRaw(v, parsed.negative))];
1295
+ }
1196
1296
  case "grow":
1197
- return [decl("flex-grow", parsed.value ?? "1")];
1198
- case "shrink":
1199
- return [decl("flex-shrink", parsed.value ?? "1")];
1297
+ case "shrink": {
1298
+ const v = parsed.value ?? "1";
1299
+ if (!(parsed.isArbitrary || PLAIN_NUMBER.test(v))) return null;
1300
+ return [decl(parsed.utility === "grow" ? "flex-grow" : "flex-shrink", v)];
1301
+ }
1200
1302
  // top/right/bottom/left/inset support real Tailwind's negative-value
1201
1303
  // convention ("-top-4") AND its percentage-fraction scale ("top-1/2",
1202
1304
  // "-inset-1/3") — see resolveNegatableSize's own doc comment.
@@ -1534,7 +1636,7 @@ function borderValue(theme, parsed) {
1534
1636
  if (value === "separate") return [decl("border-collapse", "separate")];
1535
1637
  }
1536
1638
  if (parsed.isArbitrary) {
1537
- if (looksLikeLength(value)) return [decl("border-width", value)];
1639
+ if (isLength(parsed, value)) return [decl("border-width", value)];
1538
1640
  const color2 = colorValue(theme, parsed);
1539
1641
  return color2 === null ? null : [decl("border-color", color2)];
1540
1642
  }
@@ -1552,7 +1654,7 @@ function borderSideValue(theme, parsed, sideProperty) {
1552
1654
  const value = parsed.value;
1553
1655
  if (value === null) return null;
1554
1656
  if (parsed.isArbitrary) {
1555
- if (looksLikeLength(value)) return [decl(`${sideProperty}-width`, value)];
1657
+ if (isLength(parsed, value)) return [decl(`${sideProperty}-width`, value)];
1556
1658
  const color2 = colorValue(theme, parsed);
1557
1659
  return color2 === null ? null : [decl(`${sideProperty}-color`, color2)];
1558
1660
  }
@@ -1570,7 +1672,7 @@ function borderAxisValue(theme, parsed, sideA, sideB) {
1570
1672
  const value = parsed.value;
1571
1673
  if (value === null) return null;
1572
1674
  if (parsed.isArbitrary) {
1573
- if (looksLikeLength(value)) return [decl(`${sideA}-width`, value), decl(`${sideB}-width`, value)];
1675
+ if (isLength(parsed, value)) return [decl(`${sideA}-width`, value), decl(`${sideB}-width`, value)];
1574
1676
  const color2 = colorValue(theme, parsed);
1575
1677
  return color2 === null ? null : [decl(`${sideA}-color`, color2), decl(`${sideB}-color`, color2)];
1576
1678
  }
@@ -1628,7 +1730,7 @@ function outlineValue(theme, parsed) {
1628
1730
  const value = parsed.value;
1629
1731
  if (value === null) return null;
1630
1732
  if (parsed.isArbitrary) {
1631
- if (looksLikeLength(value)) return [decl("outline-width", value)];
1733
+ if (isLength(parsed, value)) return [decl("outline-width", value)];
1632
1734
  const color2 = colorValue(theme, parsed);
1633
1735
  return color2 === null ? null : [decl("outline-color", color2)];
1634
1736
  }
@@ -1846,7 +1948,12 @@ function scaleFactor(parsed) {
1846
1948
  }
1847
1949
  function angle(parsed) {
1848
1950
  if (parsed.value === null) return null;
1849
- if (parsed.isArbitrary) return parsed.value;
1951
+ if (parsed.isArbitrary) {
1952
+ if (!parsed.negative) return parsed.value;
1953
+ if (parsed.value.startsWith("-")) return parsed.value.slice(1);
1954
+ if (/^[\d.]/.test(parsed.value)) return `-${parsed.value}`;
1955
+ return `calc(${parsed.value} * -1)`;
1956
+ }
1850
1957
  const n = Number(parsed.value);
1851
1958
  if (!Number.isFinite(n)) return null;
1852
1959
  return `${parsed.negative ? -n : n}deg`;
@@ -1979,7 +2086,7 @@ function resolveTextNative(parsed, theme) {
1979
2086
  if (size !== null) return [decl("font-size", size)];
1980
2087
  const align = textAlign(parsed.value);
1981
2088
  if (align !== null) return [decl("text-align", align)];
1982
- } else if (parsed.isArbitrary && parsed.value !== null && looksLikeLength(parsed.value)) {
2089
+ } else if (parsed.isArbitrary && parsed.value !== null && isLength(parsed, parsed.value)) {
1983
2090
  return [decl("font-size", parsed.value)];
1984
2091
  }
1985
2092
  const hex = nativeHexColor(parsed, theme);
@@ -2026,6 +2133,13 @@ function nativeModifierState(modifier, theme, colorScheme, pressed, width) {
2026
2133
  const px = reduceConstantMath(`calc(${modifier.slice(5, -1).trim()})`);
2027
2134
  return px === null ? null : width <= px;
2028
2135
  }
2136
+ const screen = (name) => Object.prototype.hasOwnProperty.call(theme.screens, name) ? theme.screens[name] : void 0;
2137
+ const custom = screen(modifier);
2138
+ if (typeof custom === "number") return width >= custom;
2139
+ if (modifier.startsWith("max-")) {
2140
+ const max = screen(modifier.slice(4));
2141
+ if (typeof max === "number") return width < max;
2142
+ }
2029
2143
  return null;
2030
2144
  }
2031
2145
  function kebabToCamel(s) {
@@ -2189,7 +2303,7 @@ function resolveStyleJsWithWarnings(classString, theme, colorScheme, pressed, wi
2189
2303
  if (d.property.startsWith("__")) {
2190
2304
  continue;
2191
2305
  }
2192
- if (d.property.startsWith("--") || d.value.includes("var(") || d.property === "outline" || d.property === "object-position" || d.property === "container-type") {
2306
+ if (d.property.startsWith("--") || d.value.includes("var(") || d.property === "outline" || d.property === "object-position" || d.property === "container-type" || d.property === "container-name") {
2193
2307
  continue;
2194
2308
  }
2195
2309
  if (d.property === "shadow-offset-x" || d.property === "shadow-offset-y") {