@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.
- package/dist/jsx-dev-runtime.js +77 -63
- package/dist/jsx-dev-runtime.web.js +3 -2
- package/dist/jsx-runtime.js +77 -63
- package/package.json +1 -1
package/dist/jsx-dev-runtime.js
CHANGED
|
@@ -30,6 +30,76 @@ 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 value = rest.slice(prefix.length);
|
|
47
|
+
const entry = theme.colors[value];
|
|
48
|
+
if (typeof entry === "object" && entry !== null) {
|
|
49
|
+
return { prefix: `${important}${prefix}`, light: entry.light, dark: entry.dark };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function substituteModeAwareColorToken(token, theme, colorScheme) {
|
|
55
|
+
const segments = token.split(":");
|
|
56
|
+
const base = segments.pop() ?? token;
|
|
57
|
+
const modifierPrefix = segments.length > 0 ? `${segments.join(":")}:` : "";
|
|
58
|
+
const found = findModeAwareColor(base, theme);
|
|
59
|
+
if (found === null) return token;
|
|
60
|
+
const hex = colorScheme === "dark" ? found.dark : found.light;
|
|
61
|
+
return `${modifierPrefix}${found.prefix}[${hex}]`;
|
|
62
|
+
}
|
|
63
|
+
function classStringUsesModeAwareColor(classString, theme) {
|
|
64
|
+
return classString.split(/\s+/).some((rawToken) => {
|
|
65
|
+
if (!rawToken) return false;
|
|
66
|
+
const segments = rawToken.split(":");
|
|
67
|
+
const base = segments.pop() ?? rawToken;
|
|
68
|
+
return findModeAwareColor(base, theme) !== null;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function hexToRgb(hex) {
|
|
72
|
+
const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
|
|
73
|
+
if (!m) return null;
|
|
74
|
+
let h = m[1];
|
|
75
|
+
if (h.length === 3) h = h.split("").map((c) => c + c).join("");
|
|
76
|
+
const n = parseInt(h, 16);
|
|
77
|
+
return [n >> 16 & 255, n >> 8 & 255, n & 255];
|
|
78
|
+
}
|
|
79
|
+
function splitOpacity(value) {
|
|
80
|
+
const slash = value.lastIndexOf("/");
|
|
81
|
+
if (slash === -1) return [value, null];
|
|
82
|
+
const opacityText = value.slice(slash + 1);
|
|
83
|
+
const n = Number(opacityText);
|
|
84
|
+
if (opacityText !== "" && Number.isInteger(n) && n >= 0 && n <= 100) {
|
|
85
|
+
return [value.slice(0, slash), n];
|
|
86
|
+
}
|
|
87
|
+
return [value, null];
|
|
88
|
+
}
|
|
89
|
+
function colorValue(theme, parsed) {
|
|
90
|
+
const value = parsed.value;
|
|
91
|
+
if (value === null) return null;
|
|
92
|
+
if (parsed.isArbitrary) return value;
|
|
93
|
+
const [name, opacity] = splitOpacity(value);
|
|
94
|
+
const hex = lookupHex(theme, name);
|
|
95
|
+
if (hex === null) return null;
|
|
96
|
+
if (opacity === null) return hex;
|
|
97
|
+
const rgb = hexToRgb(hex);
|
|
98
|
+
if (rgb === null) return hex;
|
|
99
|
+
return `rgba(${rgb.join(",")},${opacity / 100})`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/jsxRuntimeCore.ts
|
|
33
103
|
var import_dynamicTokens = require("./dynamicTokens");
|
|
34
104
|
|
|
35
105
|
// src/jsEngine/calc.ts
|
|
@@ -773,6 +843,9 @@ var DARK_MODIFIER_RE = /(^|\s|:)dark:/;
|
|
|
773
843
|
var BREAKPOINT_MODIFIER_RE = /(^|\s|:)(sm|md|lg|xl|2xl):|(^|\s|:)(min|max)-\[[^\]]*\]:/;
|
|
774
844
|
var HOVER_MODIFIER_RE = /(^|\s|:)hover:/;
|
|
775
845
|
var FOCUS_MODIFIER_RE = /(^|\s|:)focus:/;
|
|
846
|
+
function usesModeAwareColor(classStrRaw) {
|
|
847
|
+
return classStringUsesModeAwareColor(classStrRaw, (0, import_theme.getTheme)());
|
|
848
|
+
}
|
|
776
849
|
function ReactiveElement({
|
|
777
850
|
hostType,
|
|
778
851
|
hostRest,
|
|
@@ -864,7 +937,7 @@ function processElement(resolveStyle2, type, rawProps, key, isStaticChildren) {
|
|
|
864
937
|
if (typeof classStrRaw !== "string") {
|
|
865
938
|
return makeElement(isStaticChildren, type, rawProps, key);
|
|
866
939
|
}
|
|
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)) {
|
|
940
|
+
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
941
|
return (0, import_jsx_runtime.jsx)(
|
|
869
942
|
ReactiveElement,
|
|
870
943
|
{ hostType: type, hostRest: rest, classStrRaw, userStyle, resolveStyle: resolveStyle2, elementKey: key, isStaticChildren },
|
|
@@ -897,7 +970,7 @@ function createJsxDEV(jsx2, jsxs2) {
|
|
|
897
970
|
|
|
898
971
|
// src/nativeBridge.ts
|
|
899
972
|
var import_react_native2 = require("react-native");
|
|
900
|
-
var
|
|
973
|
+
var import_theme2 = require("./theme");
|
|
901
974
|
var import_darkModeStore2 = require("./darkModeStore");
|
|
902
975
|
|
|
903
976
|
// src/jsEngine/shared.ts
|
|
@@ -1375,65 +1448,6 @@ function resolve2(parsed, theme) {
|
|
|
1375
1448
|
}
|
|
1376
1449
|
}
|
|
1377
1450
|
|
|
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
1451
|
// src/jsEngine/resolvers/border.ts
|
|
1438
1452
|
function radiusSize(key) {
|
|
1439
1453
|
switch (key) {
|
|
@@ -2216,7 +2230,7 @@ var cachedForThemeJson = null;
|
|
|
2216
2230
|
function resolveStyle(classString, pressed = false) {
|
|
2217
2231
|
const colorScheme = (0, import_darkModeStore2.getGlobalDarkMode)() ? "dark" : "light";
|
|
2218
2232
|
const width = import_react_native2.Dimensions.get("window").width;
|
|
2219
|
-
const themeJson = (0,
|
|
2233
|
+
const themeJson = (0, import_theme2.getThemeJson)();
|
|
2220
2234
|
if (themeJson !== cachedForThemeJson) {
|
|
2221
2235
|
resolveStyleCache.clear();
|
|
2222
2236
|
cachedForThemeJson = themeJson;
|
|
@@ -2232,7 +2246,7 @@ function resolveStyle(classString, pressed = false) {
|
|
|
2232
2246
|
function resolveStyleUncached(classString, pressed, colorScheme, width, themeJson) {
|
|
2233
2247
|
const KbachModule = import_react_native2.TurboModuleRegistry.get("KbachModule");
|
|
2234
2248
|
if (!KbachModule) {
|
|
2235
|
-
const { style: style2, warnings: warnings2 } = resolveStyleJsWithWarnings(classString, (0,
|
|
2249
|
+
const { style: style2, warnings: warnings2 } = resolveStyleJsWithWarnings(classString, (0, import_theme2.getTheme)(), colorScheme, pressed, width);
|
|
2236
2250
|
warnIfDev(classString, warnings2);
|
|
2237
2251
|
return style2;
|
|
2238
2252
|
}
|