@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.
@@ -10,13 +10,13 @@ import {
10
10
  subscribeDynamicTokens,
11
11
  subscribeGlobalDarkMode,
12
12
  toggleGlobalDarkMode
13
- } from "./chunk-YYCSHELO.mjs";
13
+ } from "./chunk-45OSRKPS.mjs";
14
14
  import {
15
15
  defaultTheme,
16
16
  getTheme,
17
17
  resolveClassName,
18
18
  setTheme
19
- } from "./chunk-A3PV4XGK.mjs";
19
+ } from "./chunk-BTIGG7K2.mjs";
20
20
 
21
21
  // src/config.ts
22
22
  function parseHexRgb(hex) {
@@ -30,6 +30,82 @@ var import_jsx_runtime = require("react/jsx-runtime");
30
30
  var import_react = require("react");
31
31
  var import_react_native = require("react-native");
32
32
  var import_darkModeStore = require("./darkModeStore");
33
+ var import_theme = require("./theme");
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
+
108
+ // src/jsxRuntimeCore.ts
33
109
  var import_dynamicTokens = require("./dynamicTokens");
34
110
 
35
111
  // src/jsEngine/calc.ts
@@ -773,6 +849,9 @@ var DARK_MODIFIER_RE = /(^|\s|:)dark:/;
773
849
  var BREAKPOINT_MODIFIER_RE = /(^|\s|:)(sm|md|lg|xl|2xl):|(^|\s|:)(min|max)-\[[^\]]*\]:/;
774
850
  var HOVER_MODIFIER_RE = /(^|\s|:)hover:/;
775
851
  var FOCUS_MODIFIER_RE = /(^|\s|:)focus:/;
852
+ function usesModeAwareColor(classStrRaw) {
853
+ return classStringUsesModeAwareColor(classStrRaw, (0, import_theme.getTheme)());
854
+ }
776
855
  function ReactiveElement({
777
856
  hostType,
778
857
  hostRest,
@@ -864,7 +943,7 @@ function processElement(resolveStyle2, type, rawProps, key, isStaticChildren) {
864
943
  if (typeof classStrRaw !== "string") {
865
944
  return makeElement(isStaticChildren, type, rawProps, key);
866
945
  }
867
- 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)) {
946
+ 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)) {
868
947
  return (0, import_jsx_runtime.jsx)(
869
948
  ReactiveElement,
870
949
  { hostType: type, hostRest: rest, classStrRaw, userStyle, resolveStyle: resolveStyle2, elementKey: key, isStaticChildren },
@@ -897,7 +976,7 @@ function createJsxDEV(jsx2, jsxs2) {
897
976
 
898
977
  // src/nativeBridge.ts
899
978
  var import_react_native2 = require("react-native");
900
- var import_theme = require("./theme");
979
+ var import_theme2 = require("./theme");
901
980
  var import_darkModeStore2 = require("./darkModeStore");
902
981
 
903
982
  // src/jsEngine/shared.ts
@@ -1375,65 +1454,6 @@ function resolve2(parsed, theme) {
1375
1454
  }
1376
1455
  }
1377
1456
 
1378
- // src/jsEngine/resolvers/color.ts
1379
- function lookupHex(theme, key) {
1380
- const entry = theme.colors[key];
1381
- return typeof entry === "string" ? entry : null;
1382
- }
1383
- var MODE_AWARE_COLOR_PREFIXES = ["bg-", "text-", "border-"];
1384
- function findModeAwareColor(base, theme) {
1385
- const important = base.startsWith("!") ? "!" : "";
1386
- const rest = important ? base.slice(1) : base;
1387
- for (const prefix of MODE_AWARE_COLOR_PREFIXES) {
1388
- if (!rest.startsWith(prefix)) continue;
1389
- const value = rest.slice(prefix.length);
1390
- const entry = theme.colors[value];
1391
- if (typeof entry === "object" && entry !== null) {
1392
- return { prefix: `${important}${prefix}`, light: entry.light, dark: entry.dark };
1393
- }
1394
- }
1395
- return null;
1396
- }
1397
- function substituteModeAwareColorToken(token, theme, colorScheme) {
1398
- const segments = token.split(":");
1399
- const base = segments.pop() ?? token;
1400
- const modifierPrefix = segments.length > 0 ? `${segments.join(":")}:` : "";
1401
- const found = findModeAwareColor(base, theme);
1402
- if (found === null) return token;
1403
- const hex = colorScheme === "dark" ? found.dark : found.light;
1404
- return `${modifierPrefix}${found.prefix}[${hex}]`;
1405
- }
1406
- function hexToRgb(hex) {
1407
- const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
1408
- if (!m) return null;
1409
- let h = m[1];
1410
- if (h.length === 3) h = h.split("").map((c) => c + c).join("");
1411
- const n = parseInt(h, 16);
1412
- return [n >> 16 & 255, n >> 8 & 255, n & 255];
1413
- }
1414
- function splitOpacity(value) {
1415
- const slash = value.lastIndexOf("/");
1416
- if (slash === -1) return [value, null];
1417
- const opacityText = value.slice(slash + 1);
1418
- const n = Number(opacityText);
1419
- if (opacityText !== "" && Number.isInteger(n) && n >= 0 && n <= 100) {
1420
- return [value.slice(0, slash), n];
1421
- }
1422
- return [value, null];
1423
- }
1424
- function colorValue(theme, parsed) {
1425
- const value = parsed.value;
1426
- if (value === null) return null;
1427
- if (parsed.isArbitrary) return value;
1428
- const [name, opacity] = splitOpacity(value);
1429
- const hex = lookupHex(theme, name);
1430
- if (hex === null) return null;
1431
- if (opacity === null) return hex;
1432
- const rgb = hexToRgb(hex);
1433
- if (rgb === null) return hex;
1434
- return `rgba(${rgb.join(",")},${opacity / 100})`;
1435
- }
1436
-
1437
1457
  // src/jsEngine/resolvers/border.ts
1438
1458
  function radiusSize(key) {
1439
1459
  switch (key) {
@@ -2216,7 +2236,7 @@ var cachedForThemeJson = null;
2216
2236
  function resolveStyle(classString, pressed = false) {
2217
2237
  const colorScheme = (0, import_darkModeStore2.getGlobalDarkMode)() ? "dark" : "light";
2218
2238
  const width = import_react_native2.Dimensions.get("window").width;
2219
- const themeJson = (0, import_theme.getThemeJson)();
2239
+ const themeJson = (0, import_theme2.getThemeJson)();
2220
2240
  if (themeJson !== cachedForThemeJson) {
2221
2241
  resolveStyleCache.clear();
2222
2242
  cachedForThemeJson = themeJson;
@@ -2232,7 +2252,7 @@ function resolveStyle(classString, pressed = false) {
2232
2252
  function resolveStyleUncached(classString, pressed, colorScheme, width, themeJson) {
2233
2253
  const KbachModule = import_react_native2.TurboModuleRegistry.get("KbachModule");
2234
2254
  if (!KbachModule) {
2235
- const { style: style2, warnings: warnings2 } = resolveStyleJsWithWarnings(classString, (0, import_theme.getTheme)(), colorScheme, pressed, width);
2255
+ const { style: style2, warnings: warnings2 } = resolveStyleJsWithWarnings(classString, (0, import_theme2.getTheme)(), colorScheme, pressed, width);
2236
2256
  warnIfDev(classString, warnings2);
2237
2257
  return style2;
2238
2258
  }