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

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.
@@ -31,6 +31,76 @@ 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 value = rest.slice(prefix.length);
48
+ const entry = theme.colors[value];
49
+ if (typeof entry === "object" && entry !== null) {
50
+ return { prefix: `${important}${prefix}`, light: entry.light, dark: entry.dark };
51
+ }
52
+ }
53
+ return null;
54
+ }
55
+ function substituteModeAwareColorToken(token, theme, colorScheme) {
56
+ const segments = token.split(":");
57
+ const base = segments.pop() ?? token;
58
+ const modifierPrefix = segments.length > 0 ? `${segments.join(":")}:` : "";
59
+ const found = findModeAwareColor(base, theme);
60
+ if (found === null) return token;
61
+ const hex = colorScheme === "dark" ? found.dark : found.light;
62
+ return `${modifierPrefix}${found.prefix}[${hex}]`;
63
+ }
64
+ function classStringUsesModeAwareColor(classString, theme) {
65
+ return classString.split(/\s+/).some((rawToken) => {
66
+ if (!rawToken) return false;
67
+ const segments = rawToken.split(":");
68
+ const base = segments.pop() ?? rawToken;
69
+ return findModeAwareColor(base, theme) !== null;
70
+ });
71
+ }
72
+ function hexToRgb(hex) {
73
+ const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
74
+ if (!m) return null;
75
+ let h = m[1];
76
+ if (h.length === 3) h = h.split("").map((c) => c + c).join("");
77
+ const n = parseInt(h, 16);
78
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
79
+ }
80
+ function splitOpacity(value) {
81
+ const slash = value.lastIndexOf("/");
82
+ if (slash === -1) return [value, null];
83
+ const opacityText = value.slice(slash + 1);
84
+ const n = Number(opacityText);
85
+ if (opacityText !== "" && Number.isInteger(n) && n >= 0 && n <= 100) {
86
+ return [value.slice(0, slash), n];
87
+ }
88
+ return [value, null];
89
+ }
90
+ function colorValue(theme, parsed) {
91
+ const value = parsed.value;
92
+ if (value === null) return null;
93
+ if (parsed.isArbitrary) return value;
94
+ const [name, opacity] = splitOpacity(value);
95
+ const hex = lookupHex(theme, name);
96
+ if (hex === null) return null;
97
+ if (opacity === null) return hex;
98
+ const rgb = hexToRgb(hex);
99
+ if (rgb === null) return hex;
100
+ return `rgba(${rgb.join(",")},${opacity / 100})`;
101
+ }
102
+
103
+ // src/jsxRuntimeCore.ts
34
104
  var import_dynamicTokens = require("./dynamicTokens");
35
105
 
36
106
  // src/jsEngine/calc.ts
@@ -774,6 +844,9 @@ var DARK_MODIFIER_RE = /(^|\s|:)dark:/;
774
844
  var BREAKPOINT_MODIFIER_RE = /(^|\s|:)(sm|md|lg|xl|2xl):|(^|\s|:)(min|max)-\[[^\]]*\]:/;
775
845
  var HOVER_MODIFIER_RE = /(^|\s|:)hover:/;
776
846
  var FOCUS_MODIFIER_RE = /(^|\s|:)focus:/;
847
+ function usesModeAwareColor(classStrRaw) {
848
+ return classStringUsesModeAwareColor(classStrRaw, (0, import_theme.getTheme)());
849
+ }
777
850
  function ReactiveElement({
778
851
  hostType,
779
852
  hostRest,
@@ -865,7 +938,7 @@ function processElement(resolveStyle2, type, rawProps, key, isStaticChildren) {
865
938
  if (typeof classStrRaw !== "string") {
866
939
  return makeElement(isStaticChildren, type, rawProps, key);
867
940
  }
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)) {
941
+ 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
942
  return (0, import_jsx_runtime.jsx)(
870
943
  ReactiveElement,
871
944
  { hostType: type, hostRest: rest, classStrRaw, userStyle, resolveStyle: resolveStyle2, elementKey: key, isStaticChildren },
@@ -888,7 +961,7 @@ function createJsxFunctions(resolveStyle2) {
888
961
 
889
962
  // src/nativeBridge.ts
890
963
  var import_react_native2 = require("react-native");
891
- var import_theme = require("./theme");
964
+ var import_theme2 = require("./theme");
892
965
  var import_darkModeStore2 = require("./darkModeStore");
893
966
 
894
967
  // src/jsEngine/shared.ts
@@ -1366,65 +1439,6 @@ function resolve2(parsed, theme) {
1366
1439
  }
1367
1440
  }
1368
1441
 
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
1442
  // src/jsEngine/resolvers/border.ts
1429
1443
  function radiusSize(key) {
1430
1444
  switch (key) {
@@ -2207,7 +2221,7 @@ var cachedForThemeJson = null;
2207
2221
  function resolveStyle(classString, pressed = false) {
2208
2222
  const colorScheme = (0, import_darkModeStore2.getGlobalDarkMode)() ? "dark" : "light";
2209
2223
  const width = import_react_native2.Dimensions.get("window").width;
2210
- const themeJson = (0, import_theme.getThemeJson)();
2224
+ const themeJson = (0, import_theme2.getThemeJson)();
2211
2225
  if (themeJson !== cachedForThemeJson) {
2212
2226
  resolveStyleCache.clear();
2213
2227
  cachedForThemeJson = themeJson;
@@ -2223,7 +2237,7 @@ function resolveStyle(classString, pressed = false) {
2223
2237
  function resolveStyleUncached(classString, pressed, colorScheme, width, themeJson) {
2224
2238
  const KbachModule = import_react_native2.TurboModuleRegistry.get("KbachModule");
2225
2239
  if (!KbachModule) {
2226
- const { style: style2, warnings: warnings2 } = resolveStyleJsWithWarnings(classString, (0, import_theme.getTheme)(), colorScheme, pressed, width);
2240
+ const { style: style2, warnings: warnings2 } = resolveStyleJsWithWarnings(classString, (0, import_theme2.getTheme)(), colorScheme, pressed, width);
2227
2241
  warnIfDev(classString, warnings2);
2228
2242
  return style2;
2229
2243
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbach/react-native",
3
- "version": "1.0.0-beta.41",
3
+ "version": "1.0.0-beta.42",
4
4
  "description": "Kbach's utility-class styling engine for React Native — the same class names as @kbach/react, resolved to a StyleSheet-ready style object via a Kotlin/JNI TurboModule (native), the same WASM engine @kbach/react uses (Expo Web / react-native-web), or a pure-JS fallback engine (Expo Go). Ships its own native Android module — one npm install, no separate native package. Beta. Native is Android-only (no iOS bridge yet); works with the React Native CLI, an Expo dev client, AND Expo Go (a reduced-coverage pure-JS fallback, since Expo Go can't load any custom native module).",
5
5
  "keywords": [
6
6
  "css",