@kbach/react-native 1.0.0-beta.9 → 1.1.1-beta.0

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.
Files changed (51) hide show
  1. package/AGENTS.md +504 -0
  2. package/LICENSE +21 -0
  3. package/README.md +206 -70
  4. package/THIRD_PARTY_NOTICES.md +41 -0
  5. package/android/src/main/jniLibs/arm64-v8a/libkbach_core_engine.so +0 -0
  6. package/android/src/main/jniLibs/x86_64/libkbach_core_engine.so +0 -0
  7. package/dist/{chunk-YOC3SHF5.mjs → chunk-6F44N62F.mjs} +2 -2
  8. package/dist/chunk-FSO4WVCH.mjs +112 -0
  9. package/dist/chunk-R7E5D3D6.mjs +623 -0
  10. package/dist/darkModeStore.d.ts +73 -0
  11. package/dist/darkModeStore.js +118 -0
  12. package/dist/dynamicTokens.d.ts +53 -0
  13. package/dist/dynamicTokens.js +75 -0
  14. package/dist/index.d.ts +90 -70
  15. package/dist/index.js +1369 -611
  16. package/dist/index.web.d.ts +91 -1
  17. package/dist/index.web.js +204 -441
  18. package/dist/index.web.mjs +294 -12
  19. package/dist/jsx-dev-runtime.d.ts +2 -2
  20. package/dist/jsx-dev-runtime.js +1600 -603
  21. package/dist/jsx-dev-runtime.web.d.ts +2 -2
  22. package/dist/jsx-dev-runtime.web.js +20 -355
  23. package/dist/jsx-dev-runtime.web.mjs +18 -6
  24. package/dist/jsx-runtime.d.ts +3 -3
  25. package/dist/jsx-runtime.js +1590 -593
  26. package/dist/jsx-runtime.web.d.ts +3 -3
  27. package/dist/jsx-runtime.web.js +17 -355
  28. package/dist/jsx-runtime.web.mjs +2 -3
  29. package/dist/semanticElements-Bk3TB-vt.d.ts +334 -0
  30. package/dist/theme.d.ts +79 -0
  31. package/dist/{chunk-HK6PDJJK.mjs → theme.js} +99 -11
  32. package/llms.txt +38 -0
  33. package/package.json +15 -13
  34. package/src/babel-plugin.js +95 -25
  35. package/dist/chunk-DLIXI5OW.mjs +0 -53
  36. package/dist/chunk-DOWW44F7.mjs +0 -14
  37. package/dist/chunk-H5Z24XX5.mjs +0 -192
  38. package/dist/chunk-SY5OAY2C.mjs +0 -1211
  39. package/dist/chunk-X4UQCEOE.mjs +0 -186
  40. package/dist/chunk-Z664AKW7.mjs +0 -54
  41. package/dist/index.d.mts +0 -83
  42. package/dist/index.mjs +0 -38
  43. package/dist/index.web.d.mts +0 -15
  44. package/dist/jsx-dev-runtime.d.mts +0 -10
  45. package/dist/jsx-dev-runtime.mjs +0 -18
  46. package/dist/jsx-dev-runtime.web.d.mts +0 -10
  47. package/dist/jsx-runtime.d.mts +0 -7
  48. package/dist/jsx-runtime.mjs +0 -15
  49. package/dist/jsx-runtime.web.d.mts +0 -7
  50. package/dist/useColors-CeP5_HvM.d.mts +0 -230
  51. package/dist/useColors-CeP5_HvM.d.ts +0 -230
@@ -1,186 +0,0 @@
1
- import {
2
- getGlobalDarkMode,
3
- getGlobalThemeMode,
4
- seedDefaultMode,
5
- setGlobalThemeMode,
6
- subscribeGlobalDarkMode,
7
- toggleGlobalDarkMode
8
- } from "./chunk-Z664AKW7.mjs";
9
- import {
10
- defaultTheme,
11
- getTheme,
12
- setTheme
13
- } from "./chunk-HK6PDJJK.mjs";
14
-
15
- // src/config.ts
16
- function parseHexRgb(hex) {
17
- const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
18
- if (!m) return null;
19
- let h = m[1];
20
- if (h.length === 3) h = h.split("").map((c) => c + c).join("");
21
- const n = parseInt(h, 16);
22
- return [n >> 16 & 255, n >> 8 & 255, n & 255];
23
- }
24
- function applyOpacityToHex(hex, opacityText) {
25
- const rgb = parseHexRgb(hex);
26
- if (!rgb) return hex;
27
- const a = Number(opacityText) / 100;
28
- const clamped = Number.isFinite(a) ? Math.min(1, Math.max(0, a)) : 1;
29
- return `rgba(${rgb.join(",")},${clamped})`;
30
- }
31
- function resolveColorEntry(value, lookup) {
32
- const slash = value.indexOf("/");
33
- const name = slash === -1 ? value : value.slice(0, slash);
34
- const opacity = slash === -1 ? void 0 : value.slice(slash + 1);
35
- const base = lookup(name);
36
- if (base === void 0) return value;
37
- return opacity === void 0 ? base : applyOpacityToHex(base, opacity);
38
- }
39
- function resolveColors(extend, existing) {
40
- const resolved = {};
41
- const lookup = (name) => {
42
- const found = resolved[name] ?? existing[name];
43
- return typeof found === "string" ? found : void 0;
44
- };
45
- for (const [name, value] of Object.entries(extend)) {
46
- resolved[name] = resolveColorEntry(value, lookup);
47
- }
48
- return resolved;
49
- }
50
- function resolveKbachConfig(config) {
51
- let theme = { ...defaultTheme, ...config.theme };
52
- if (config.extend?.colors) {
53
- theme = { ...theme, colors: { ...theme.colors, ...resolveColors(config.extend.colors, theme.colors) } };
54
- }
55
- if (config.extend?.spacing) {
56
- theme = { ...theme, spacing: { ...theme.spacing, ...config.extend.spacing } };
57
- }
58
- if (config.extend?.screens) {
59
- theme = { ...theme, screens: { ...theme.screens, ...config.extend.screens } };
60
- }
61
- if (config.extend?.fontFamily) {
62
- theme = { ...theme, fontFamily: { ...theme.fontFamily, ...config.extend.fontFamily } };
63
- }
64
- if (config.extend?.container) {
65
- theme = { ...theme, container: { ...theme.container, ...config.extend.container } };
66
- }
67
- if (config.darkMode) {
68
- theme = { ...theme, darkMode: config.darkMode };
69
- }
70
- return theme;
71
- }
72
- function applyKbachConfig(config) {
73
- const theme = resolveKbachConfig(config);
74
- setTheme(theme);
75
- return theme;
76
- }
77
-
78
- // src/useTheme.ts
79
- import { useMemo, useSyncExternalStore } from "react";
80
- function useTheme() {
81
- const isDark = useSyncExternalStore(subscribeGlobalDarkMode, getGlobalDarkMode);
82
- const mode = useSyncExternalStore(subscribeGlobalDarkMode, getGlobalThemeMode);
83
- return useMemo(
84
- () => ({ mode, isDark, setMode: setGlobalThemeMode, toggle: toggleGlobalDarkMode }),
85
- [mode, isDark]
86
- );
87
- }
88
-
89
- // src/ThemeProvider.tsx
90
- import { useEffect, useRef } from "react";
91
- import { Fragment, jsx } from "react/jsx-runtime";
92
- var mountedProviderCount = 0;
93
- var warnedMultipleProviders = false;
94
- function ThemeProvider({ children, defaultMode = "system" }) {
95
- useEffect(() => {
96
- mountedProviderCount++;
97
- if (mountedProviderCount > 1 && !warnedMultipleProviders) {
98
- warnedMultipleProviders = true;
99
- console.warn(
100
- "[kbach] Multiple <ThemeProvider> instances are mounted at once. Dark-mode state is one global store useTheme() reads everywhere, not scoped per-provider, so their defaultMode seeds will fight over the same state."
101
- );
102
- }
103
- return () => {
104
- mountedProviderCount--;
105
- };
106
- }, []);
107
- const seeded = useRef(false);
108
- useEffect(() => {
109
- if (seeded.current) return;
110
- seeded.current = true;
111
- seedDefaultMode(defaultMode);
112
- }, []);
113
- return /* @__PURE__ */ jsx(Fragment, { children });
114
- }
115
-
116
- // src/useColors.ts
117
- function parseHexRgb2(hex) {
118
- const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
119
- if (!m) return null;
120
- let h = m[1];
121
- if (h.length === 3) h = h.split("").map((c) => c + c).join("");
122
- const n = parseInt(h, 16);
123
- return [n >> 16 & 255, n >> 8 & 255, n & 255];
124
- }
125
- function applyOpacity(color, opacity) {
126
- const a = Math.max(0, Math.min(1, opacity / 100));
127
- if (color.startsWith("#")) {
128
- const rgb = parseHexRgb2(color);
129
- return rgb ? `rgba(${rgb.join(",")},${a})` : color;
130
- }
131
- if (color.startsWith("rgb(")) return color.replace("rgb(", "rgba(").replace(")", `,${a})`);
132
- if (color.startsWith("rgba(")) return color.replace(/,\s*[\d.]+\)$/, `,${a})`);
133
- return color;
134
- }
135
- function resolveEntry(entry, isDark) {
136
- return typeof entry === "string" ? entry : isDark ? entry.dark : entry.light;
137
- }
138
- function makeColorsProxy(theme, isDark) {
139
- const alpha = (color, opacity) => opacity === void 0 ? color : applyOpacity(color, opacity);
140
- const cache = /* @__PURE__ */ new Map();
141
- function resolveNamed(key) {
142
- let name = key;
143
- let opacity;
144
- if (key.includes("/")) {
145
- const slash = key.indexOf("/");
146
- name = key.slice(0, slash);
147
- opacity = Number(key.slice(slash + 1));
148
- }
149
- const entry = theme.colors[name];
150
- if (entry === void 0) return void 0;
151
- const value = resolveEntry(entry, isDark);
152
- return opacity === void 0 ? value : applyOpacity(value, opacity);
153
- }
154
- function makeFamilyProxy(family) {
155
- return new Proxy({}, {
156
- get(_, prop) {
157
- const key = String(prop);
158
- if (key === "then") return void 0;
159
- return resolveNamed(`${family}-${key}`);
160
- }
161
- });
162
- }
163
- return new Proxy({ alpha }, {
164
- get(_, prop) {
165
- const key = String(prop);
166
- if (key === "then") return void 0;
167
- if (key === "alpha") return alpha;
168
- const direct = resolveNamed(key);
169
- if (direct !== void 0) return direct;
170
- if (!cache.has(key)) cache.set(key, makeFamilyProxy(key));
171
- return cache.get(key);
172
- }
173
- });
174
- }
175
- function useColors() {
176
- const { isDark } = useTheme();
177
- return makeColorsProxy(getTheme(), isDark);
178
- }
179
-
180
- export {
181
- resolveKbachConfig,
182
- applyKbachConfig,
183
- useTheme,
184
- ThemeProvider,
185
- useColors
186
- };
@@ -1,54 +0,0 @@
1
- // src/darkModeStore.ts
2
- import { Appearance } from "react-native";
3
- var listeners = /* @__PURE__ */ new Set();
4
- function systemPrefersDark() {
5
- return Appearance.getColorScheme() === "dark";
6
- }
7
- function resolveIsDark(m) {
8
- return m === "system" ? systemPrefersDark() : m === "dark";
9
- }
10
- var mode = "system";
11
- var isDark = resolveIsDark(mode);
12
- var hasExplicitChoice = false;
13
- var subscription = Appearance.addChangeListener(({ colorScheme }) => {
14
- if (mode !== "system") return;
15
- isDark = colorScheme === "dark";
16
- notify();
17
- });
18
- function notify() {
19
- for (const listener of listeners) listener();
20
- }
21
- function getGlobalDarkMode() {
22
- return isDark;
23
- }
24
- function getGlobalThemeMode() {
25
- return mode;
26
- }
27
- function setGlobalThemeMode(nextMode) {
28
- mode = nextMode;
29
- isDark = resolveIsDark(nextMode);
30
- hasExplicitChoice = true;
31
- notify();
32
- }
33
- function toggleGlobalDarkMode() {
34
- setGlobalThemeMode(isDark ? "light" : "dark");
35
- }
36
- function subscribeGlobalDarkMode(listener) {
37
- listeners.add(listener);
38
- return () => listeners.delete(listener);
39
- }
40
- function seedDefaultMode(fallback) {
41
- if (hasExplicitChoice || mode === fallback) return;
42
- mode = fallback;
43
- isDark = resolveIsDark(fallback);
44
- notify();
45
- }
46
-
47
- export {
48
- getGlobalDarkMode,
49
- getGlobalThemeMode,
50
- setGlobalThemeMode,
51
- toggleGlobalDarkMode,
52
- subscribeGlobalDarkMode,
53
- seedDefaultMode
54
- };
package/dist/index.d.mts DELETED
@@ -1,83 +0,0 @@
1
- export { C as ColorEntry, a as ColorScale, b as ColorsAPI, c as ContainerConfig, K as KbachConfig, T as ThemeConfig, d as ThemeMode, e as ThemeProvider, f as ThemeProviderProps, g as ThemeState, h as applyKbachConfig, i as defaultTheme, j as getGlobalDarkMode, k as getGlobalThemeMode, l as getTheme, r as resolveKbachConfig, s as setGlobalThemeMode, m as setTheme, n as subscribeGlobalDarkMode, t as toggleGlobalDarkMode, u as useColors, o as useTheme } from './useColors-CeP5_HvM.mjs';
2
- import 'react';
3
-
4
- type StyleValue = string | number | {
5
- width: number;
6
- height: number;
7
- };
8
- interface StyleObject {
9
- [key: string]: StyleValue;
10
- }
11
- /**
12
- * Calls the Rust engine via the KbachModule TurboModule (see
13
- * apps/native-sandbox/android/.../KbachModule.kt and
14
- * packages/core-engine/src/resolve_style.rs) and returns a plain style
15
- * object ready for RN's `style` prop. Synchronous — no async init step,
16
- * unlike the web/WASM path, since JSI-backed TurboModule methods are
17
- * available as soon as the module is loaded.
18
- *
19
- * Reads `getGlobalDarkMode()` (darkModeStore.ts) fresh on every call (no
20
- * caching) so `dark:` resolves correctly whenever this runs. That store —
21
- * not a direct `Appearance.getColorScheme()` read, which this function
22
- * used prior to `<ThemeProvider>` support — is what makes an explicit
23
- * `setGlobalThemeMode('dark')`/`toggle()` override actually affect
24
- * rendering; the store itself falls back to tracking `Appearance` live
25
- * whenever the mode is `'system'` (its own default), so nothing regresses
26
- * for apps that never touch the override API at all. This function itself
27
- * has no subscription of its own, so nothing re-renders just because the
28
- * store's value changed — call `useTheme()` (its `isDark`) somewhere in
29
- * the tree for that, NOT React Native's own `useColorScheme()`, which only
30
- * reflects the raw OS setting and would miss an explicit override entirely.
31
- *
32
- * Phase 11 originally shipped with live in-place theme switching unverified
33
- * (a `uiMode` toggle triggered a re-render but `Appearance.getColorScheme()`
34
- * kept returning a stale value). Root-caused in Phase 12 while debugging an
35
- * unrelated `active:` failure: `apps/native-sandbox` has its own separate
36
- * `node_modules/react-native` (excluded from the npm workspace since Phase
37
- * 5), while `packages/react-native` resolved `react-native` hierarchically
38
- * up to a *different* copy at the repo root — two physical module
39
- * instances, so a `useColorScheme()` subscription and an
40
- * `Appearance.getColorScheme()` read were silently talking to two separate
41
- * copies of the Appearance module. Fixed by forcing a single instance via
42
- * `resolver.resolveRequest` in apps/native-sandbox/metro.config.js; live
43
- * theme switching (and `active:`, the bug that surfaced this) both verified
44
- * working after the fix — see Phase 12. Still relevant here: darkModeStore.ts
45
- * itself calls `Appearance.addChangeListener`, so the same dual-instance
46
- * failure mode would silently break the 'system' fallback path too if that
47
- * metro.config.js fix ever regressed.
48
- *
49
- * `pressed` gates the `active:` modifier — unlike `colorScheme`, there's no
50
- * system-level getter for "is this element currently pressed"; only RN's
51
- * `Pressable` ever knows this, so it's passed in directly by the caller
52
- * (jsx-runtime, from Pressable's own style-function callback) rather than
53
- * queried here. Defaults to `false` for every other element type.
54
- *
55
- * `width` gates `sm:`/`md:`/`lg:`/`xl:`/`2xl:` against the active theme's
56
- * `screens` scale (resolve_style.rs's `native_modifier_state`) — read fresh
57
- * from `Dimensions.get('window').width` on every call, the same "no
58
- * caching, no store" choice `colorScheme`/`pressed` already make, and for
59
- * the same reason: unlike dark mode there's no explicit-override concept to
60
- * preserve here (nobody manually overrides their screen width), so a plain
61
- * synchronous read is enough — no need for the subscribable store
62
- * darkModeStore.ts is for. As with `colorScheme`, this function has no
63
- * subscription of its own, so rotating/resizing the window doesn't
64
- * re-render anything by itself — call RN's own `useWindowDimensions()`
65
- * somewhere in the tree for that (same role `useColorScheme()` plays for
66
- * `dark:` in apps/native-sandbox/App.tsx).
67
- *
68
- * Falls back to `./jsEngine` (a pure-JS, no-WASM/no-native reimplementation
69
- * of this same resolution logic — see that directory's own doc comments)
70
- * when `KbachModule` isn't registered at all — Expo Go, which can never
71
- * load ANY custom native module (not even Expo's own Modules API), so the
72
- * TurboModule this file otherwise depends on simply doesn't exist there.
73
- * `TurboModuleRegistry.get` (not `.getEnforcing`, which throws) is what
74
- * makes this detectable at all — `get` returns `null`/`undefined` instead.
75
- * A real dev-client/CLI build always has the module registered, so this
76
- * fallback only ever activates in Expo Go itself; everywhere else behaves
77
- * exactly as before. The JS engine covers a strict subset of what the
78
- * native/WASM engines resolve (see jsEngine/resolveUtilityNative.ts) — an
79
- * intentional, documented parity gap, not a bug.
80
- */
81
- declare function resolveStyle(classString: string, pressed?: boolean): StyleObject;
82
-
83
- export { type StyleObject, resolveStyle };
package/dist/index.mjs DELETED
@@ -1,38 +0,0 @@
1
- import {
2
- ThemeProvider,
3
- applyKbachConfig,
4
- resolveKbachConfig,
5
- useColors,
6
- useTheme
7
- } from "./chunk-X4UQCEOE.mjs";
8
- import {
9
- resolveStyle
10
- } from "./chunk-SY5OAY2C.mjs";
11
- import {
12
- getGlobalDarkMode,
13
- getGlobalThemeMode,
14
- setGlobalThemeMode,
15
- subscribeGlobalDarkMode,
16
- toggleGlobalDarkMode
17
- } from "./chunk-Z664AKW7.mjs";
18
- import {
19
- defaultTheme,
20
- getTheme,
21
- setTheme
22
- } from "./chunk-HK6PDJJK.mjs";
23
- export {
24
- ThemeProvider,
25
- applyKbachConfig,
26
- defaultTheme,
27
- getGlobalDarkMode,
28
- getGlobalThemeMode,
29
- getTheme,
30
- resolveKbachConfig,
31
- resolveStyle,
32
- setGlobalThemeMode,
33
- setTheme,
34
- subscribeGlobalDarkMode,
35
- toggleGlobalDarkMode,
36
- useColors,
37
- useTheme
38
- };
@@ -1,15 +0,0 @@
1
- export { C as ColorEntry, a as ColorScale, b as ColorsAPI, c as ContainerConfig, K as KbachConfig, T as ThemeConfig, d as ThemeMode, e as ThemeProvider, f as ThemeProviderProps, g as ThemeState, h as applyKbachConfig, i as defaultTheme, j as getGlobalDarkMode, k as getGlobalThemeMode, l as getTheme, r as resolveKbachConfig, s as setGlobalThemeMode, m as setTheme, n as subscribeGlobalDarkMode, t as toggleGlobalDarkMode, u as useColors, o as useTheme } from './useColors-CeP5_HvM.mjs';
2
- import 'react';
3
-
4
- /**
5
- * Resolves `classString` to CSS via the WASM engine, injects every returned
6
- * rule into a shared `<style data-kbach-rn>` tag (cascade-order-safe — see
7
- * cssInjector.web.ts), and returns the class string to use as
8
- * `dataSet={{ kb: <returned value> }}`. MUST use the returned value, not the
9
- * original input — mode-aware color names (e.g. `bg-surface`) expand into a
10
- * literal light/dark pair, and the generated rules target that expanded
11
- * text, not the original.
12
- */
13
- declare function resolveClassName(classString: string): string;
14
-
15
- export { resolveClassName };
@@ -1,10 +0,0 @@
1
- import * as react from 'react';
2
- export { Fragment } from 'react';
3
-
4
- declare const jsxDEV: (type: unknown, props: Record<string, unknown> | null, key?: string, isStaticChildren?: boolean, source?: {
5
- fileName: string;
6
- lineNumber: number;
7
- columnNumber: number;
8
- }, self?: unknown) => react.ReactElement;
9
-
10
- export { jsxDEV };
@@ -1,18 +0,0 @@
1
- import {
2
- jsx,
3
- jsxs
4
- } from "./chunk-DOWW44F7.mjs";
5
- import "./chunk-SY5OAY2C.mjs";
6
- import "./chunk-Z664AKW7.mjs";
7
- import {
8
- Fragment,
9
- createJsxDEV
10
- } from "./chunk-DLIXI5OW.mjs";
11
- import "./chunk-HK6PDJJK.mjs";
12
-
13
- // src/jsx-dev-runtime.tsx
14
- var jsxDEV = createJsxDEV(jsx, jsxs);
15
- export {
16
- Fragment,
17
- jsxDEV
18
- };
@@ -1,10 +0,0 @@
1
- import * as react from 'react';
2
- export { Fragment } from 'react';
3
-
4
- declare const jsxDEV: (type: unknown, props: Record<string, unknown> | null, key?: string, isStaticChildren?: boolean, source?: {
5
- fileName: string;
6
- lineNumber: number;
7
- columnNumber: number;
8
- }, self?: unknown) => react.ReactElement;
9
-
10
- export { jsxDEV };
@@ -1,7 +0,0 @@
1
- import * as react from 'react';
2
- export { Fragment, JSX } from 'react';
3
-
4
- declare const jsx: (type: unknown, props: Record<string, unknown> | null, key?: string) => react.ReactElement;
5
- declare const jsxs: (type: unknown, props: Record<string, unknown> | null, key?: string) => react.ReactElement;
6
-
7
- export { jsx, jsxs };
@@ -1,15 +0,0 @@
1
- import {
2
- jsx,
3
- jsxs
4
- } from "./chunk-DOWW44F7.mjs";
5
- import "./chunk-SY5OAY2C.mjs";
6
- import "./chunk-Z664AKW7.mjs";
7
- import {
8
- Fragment
9
- } from "./chunk-DLIXI5OW.mjs";
10
- import "./chunk-HK6PDJJK.mjs";
11
- export {
12
- Fragment,
13
- jsx,
14
- jsxs
15
- };
@@ -1,7 +0,0 @@
1
- import * as react from 'react';
2
- export { Fragment, JSX } from 'react';
3
-
4
- declare const jsx: (type: unknown, props: Record<string, unknown> | null, key?: string) => react.ReactElement;
5
- declare const jsxs: (type: unknown, props: Record<string, unknown> | null, key?: string) => react.ReactElement;
6
-
7
- export { jsx, jsxs };