@kbach/react-native 1.0.0-beta.41 → 1.0.0-beta.43

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,10 +1,10 @@
1
- import "./chunk-YYCSHELO.mjs";
1
+ import "./chunk-45OSRKPS.mjs";
2
2
  import {
3
3
  Fragment,
4
4
  jsx,
5
5
  jsxs
6
- } from "./chunk-3AY4XSVY.mjs";
7
- import "./chunk-A3PV4XGK.mjs";
6
+ } from "./chunk-ZURXKRQE.mjs";
7
+ import "./chunk-BTIGG7K2.mjs";
8
8
 
9
9
  // src/jsxRuntimeCore.ts
10
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
@@ -31,6 +31,82 @@ var import_jsx_runtime = require("react/jsx-runtime");
31
31
  var import_react = require("react");
32
32
  var import_react_native = require("react-native");
33
33
  var import_darkModeStore = require("./darkModeStore");
34
+ var import_theme = require("./theme");
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
+
109
+ // src/jsxRuntimeCore.ts
34
110
  var import_dynamicTokens = require("./dynamicTokens");
35
111
 
36
112
  // src/jsEngine/calc.ts
@@ -774,6 +850,9 @@ var DARK_MODIFIER_RE = /(^|\s|:)dark:/;
774
850
  var BREAKPOINT_MODIFIER_RE = /(^|\s|:)(sm|md|lg|xl|2xl):|(^|\s|:)(min|max)-\[[^\]]*\]:/;
775
851
  var HOVER_MODIFIER_RE = /(^|\s|:)hover:/;
776
852
  var FOCUS_MODIFIER_RE = /(^|\s|:)focus:/;
853
+ function usesModeAwareColor(classStrRaw) {
854
+ return classStringUsesModeAwareColor(classStrRaw, (0, import_theme.getTheme)());
855
+ }
777
856
  function ReactiveElement({
778
857
  hostType,
779
858
  hostRest,
@@ -865,7 +944,7 @@ function processElement(resolveStyle2, type, rawProps, key, isStaticChildren) {
865
944
  if (typeof classStrRaw !== "string") {
866
945
  return makeElement(isStaticChildren, type, rawProps, key);
867
946
  }
868
- if (DARK_MODIFIER_RE.test(classStrRaw) || BREAKPOINT_MODIFIER_RE.test(classStrRaw) || HOVER_MODIFIER_RE.test(classStrRaw) || FOCUS_MODIFIER_RE.test(classStrRaw) || classStrRaw.includes("var(--") || PERCENT_RELATIVE_CALC_HINT_RE.test(classStrRaw)) {
947
+ if (DARK_MODIFIER_RE.test(classStrRaw) || BREAKPOINT_MODIFIER_RE.test(classStrRaw) || HOVER_MODIFIER_RE.test(classStrRaw) || FOCUS_MODIFIER_RE.test(classStrRaw) || classStrRaw.includes("var(--") || PERCENT_RELATIVE_CALC_HINT_RE.test(classStrRaw) || usesModeAwareColor(classStrRaw)) {
869
948
  return (0, import_jsx_runtime.jsx)(
870
949
  ReactiveElement,
871
950
  { hostType: type, hostRest: rest, classStrRaw, userStyle, resolveStyle: resolveStyle2, elementKey: key, isStaticChildren },
@@ -888,7 +967,7 @@ function createJsxFunctions(resolveStyle2) {
888
967
 
889
968
  // src/nativeBridge.ts
890
969
  var import_react_native2 = require("react-native");
891
- var import_theme = require("./theme");
970
+ var import_theme2 = require("./theme");
892
971
  var import_darkModeStore2 = require("./darkModeStore");
893
972
 
894
973
  // src/jsEngine/shared.ts
@@ -1366,65 +1445,6 @@ function resolve2(parsed, theme) {
1366
1445
  }
1367
1446
  }
1368
1447
 
1369
- // src/jsEngine/resolvers/color.ts
1370
- function lookupHex(theme, key) {
1371
- const entry = theme.colors[key];
1372
- return typeof entry === "string" ? entry : null;
1373
- }
1374
- var MODE_AWARE_COLOR_PREFIXES = ["bg-", "text-", "border-"];
1375
- function findModeAwareColor(base, theme) {
1376
- const important = base.startsWith("!") ? "!" : "";
1377
- const rest = important ? base.slice(1) : base;
1378
- for (const prefix of MODE_AWARE_COLOR_PREFIXES) {
1379
- if (!rest.startsWith(prefix)) continue;
1380
- const value = rest.slice(prefix.length);
1381
- const entry = theme.colors[value];
1382
- if (typeof entry === "object" && entry !== null) {
1383
- return { prefix: `${important}${prefix}`, light: entry.light, dark: entry.dark };
1384
- }
1385
- }
1386
- return null;
1387
- }
1388
- function substituteModeAwareColorToken(token, theme, colorScheme) {
1389
- const segments = token.split(":");
1390
- const base = segments.pop() ?? token;
1391
- const modifierPrefix = segments.length > 0 ? `${segments.join(":")}:` : "";
1392
- const found = findModeAwareColor(base, theme);
1393
- if (found === null) return token;
1394
- const hex = colorScheme === "dark" ? found.dark : found.light;
1395
- return `${modifierPrefix}${found.prefix}[${hex}]`;
1396
- }
1397
- function hexToRgb(hex) {
1398
- const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
1399
- if (!m) return null;
1400
- let h = m[1];
1401
- if (h.length === 3) h = h.split("").map((c) => c + c).join("");
1402
- const n = parseInt(h, 16);
1403
- return [n >> 16 & 255, n >> 8 & 255, n & 255];
1404
- }
1405
- function splitOpacity(value) {
1406
- const slash = value.lastIndexOf("/");
1407
- if (slash === -1) return [value, null];
1408
- const opacityText = value.slice(slash + 1);
1409
- const n = Number(opacityText);
1410
- if (opacityText !== "" && Number.isInteger(n) && n >= 0 && n <= 100) {
1411
- return [value.slice(0, slash), n];
1412
- }
1413
- return [value, null];
1414
- }
1415
- function colorValue(theme, parsed) {
1416
- const value = parsed.value;
1417
- if (value === null) return null;
1418
- if (parsed.isArbitrary) return value;
1419
- const [name, opacity] = splitOpacity(value);
1420
- const hex = lookupHex(theme, name);
1421
- if (hex === null) return null;
1422
- if (opacity === null) return hex;
1423
- const rgb = hexToRgb(hex);
1424
- if (rgb === null) return hex;
1425
- return `rgba(${rgb.join(",")},${opacity / 100})`;
1426
- }
1427
-
1428
1448
  // src/jsEngine/resolvers/border.ts
1429
1449
  function radiusSize(key) {
1430
1450
  switch (key) {
@@ -2207,7 +2227,7 @@ var cachedForThemeJson = null;
2207
2227
  function resolveStyle(classString, pressed = false) {
2208
2228
  const colorScheme = (0, import_darkModeStore2.getGlobalDarkMode)() ? "dark" : "light";
2209
2229
  const width = import_react_native2.Dimensions.get("window").width;
2210
- const themeJson = (0, import_theme.getThemeJson)();
2230
+ const themeJson = (0, import_theme2.getThemeJson)();
2211
2231
  if (themeJson !== cachedForThemeJson) {
2212
2232
  resolveStyleCache.clear();
2213
2233
  cachedForThemeJson = themeJson;
@@ -2223,7 +2243,7 @@ function resolveStyle(classString, pressed = false) {
2223
2243
  function resolveStyleUncached(classString, pressed, colorScheme, width, themeJson) {
2224
2244
  const KbachModule = import_react_native2.TurboModuleRegistry.get("KbachModule");
2225
2245
  if (!KbachModule) {
2226
- const { style: style2, warnings: warnings2 } = resolveStyleJsWithWarnings(classString, (0, import_theme.getTheme)(), colorScheme, pressed, width);
2246
+ const { style: style2, warnings: warnings2 } = resolveStyleJsWithWarnings(classString, (0, import_theme2.getTheme)(), colorScheme, pressed, width);
2227
2247
  warnIfDev(classString, warnings2);
2228
2248
  return style2;
2229
2249
  }