@kbach/react-native 1.0.0-beta.8 → 1.0.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 +495 -0
  2. package/LICENSE +21 -0
  3. package/README.md +209 -249
  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-7CNURQSH.mjs +112 -0
  8. package/dist/{chunk-OIW7OQWO.mjs → chunk-HYQFT32E.mjs} +2 -2
  9. package/dist/chunk-MUPEQJRT.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 -71
  15. package/dist/index.js +1433 -606
  16. package/dist/index.web.d.ts +91 -1
  17. package/dist/index.web.js +323 -428
  18. package/dist/index.web.mjs +297 -11
  19. package/dist/jsx-dev-runtime.d.ts +2 -2
  20. package/dist/jsx-dev-runtime.js +1540 -589
  21. package/dist/jsx-dev-runtime.web.d.ts +2 -2
  22. package/dist/jsx-dev-runtime.web.js +20 -340
  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 +1530 -579
  26. package/dist/jsx-runtime.web.d.ts +3 -3
  27. package/dist/jsx-runtime.web.js +17 -340
  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-4BXM3QUV.mjs → theme.js} +120 -17
  32. package/llms.txt +38 -0
  33. package/package.json +15 -13
  34. package/src/babel-plugin.js +144 -2
  35. package/dist/ThemeContext-Dc5AC-m0.d.mts +0 -98
  36. package/dist/ThemeContext-Dc5AC-m0.d.ts +0 -98
  37. package/dist/chunk-CGU7UM2F.mjs +0 -66
  38. package/dist/chunk-DLIXI5OW.mjs +0 -53
  39. package/dist/chunk-JR3BLUAV.mjs +0 -1204
  40. package/dist/chunk-JS5KIGAB.mjs +0 -192
  41. package/dist/chunk-KV3ZIXSH.mjs +0 -14
  42. package/dist/chunk-Z664AKW7.mjs +0 -54
  43. package/dist/index.d.mts +0 -84
  44. package/dist/index.mjs +0 -34
  45. package/dist/index.web.d.mts +0 -15
  46. package/dist/jsx-dev-runtime.d.mts +0 -10
  47. package/dist/jsx-dev-runtime.mjs +0 -18
  48. package/dist/jsx-dev-runtime.web.d.mts +0 -10
  49. package/dist/jsx-runtime.d.mts +0 -7
  50. package/dist/jsx-runtime.mjs +0 -15
  51. package/dist/jsx-runtime.web.d.mts +0 -7
@@ -1,34 +1,320 @@
1
1
  import {
2
- ThemeProvider,
3
- useGlobalDarkMode,
4
- useTheme
5
- } from "./chunk-CGU7UM2F.mjs";
6
- import {
2
+ deleteDynamicToken,
3
+ getDynamicToken,
7
4
  getGlobalDarkMode,
8
5
  getGlobalThemeMode,
6
+ resyncDomWithActiveTheme,
7
+ seedDefaultMode,
8
+ setDynamicToken,
9
9
  setGlobalThemeMode,
10
+ subscribeDynamicTokens,
10
11
  subscribeGlobalDarkMode,
11
12
  toggleGlobalDarkMode
12
- } from "./chunk-Z664AKW7.mjs";
13
- import {
14
- resolveClassName
15
- } from "./chunk-JS5KIGAB.mjs";
13
+ } from "./chunk-7CNURQSH.mjs";
16
14
  import {
17
15
  defaultTheme,
18
16
  getTheme,
17
+ resolveClassName,
19
18
  setTheme
20
- } from "./chunk-4BXM3QUV.mjs";
19
+ } from "./chunk-MUPEQJRT.mjs";
20
+
21
+ // src/config.ts
22
+ function parseHexRgb(hex) {
23
+ const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
24
+ if (!m) return null;
25
+ let h = m[1];
26
+ if (h.length === 3) h = h.split("").map((c) => c + c).join("");
27
+ const n = parseInt(h, 16);
28
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
29
+ }
30
+ function applyOpacityToHex(hex, opacityText) {
31
+ const rgb = parseHexRgb(hex);
32
+ if (!rgb) return hex;
33
+ const a = Number(opacityText) / 100;
34
+ const clamped = Number.isFinite(a) ? Math.min(1, Math.max(0, a)) : 1;
35
+ return `rgba(${rgb.join(",")},${clamped})`;
36
+ }
37
+ function resolveColorEntry(value, lookup) {
38
+ const slash = value.indexOf("/");
39
+ const name = slash === -1 ? value : value.slice(0, slash);
40
+ const opacity = slash === -1 ? void 0 : value.slice(slash + 1);
41
+ const base = lookup(name);
42
+ if (base === void 0) return value;
43
+ return opacity === void 0 ? base : applyOpacityToHex(base, opacity);
44
+ }
45
+ function resolveColors(extend, existing) {
46
+ const { dark: darkExtend, ...lightExtend } = extend;
47
+ const resolvedLight = {};
48
+ const lookupLight = (name) => {
49
+ const found = resolvedLight[name] ?? existing[name];
50
+ return typeof found === "string" ? found : void 0;
51
+ };
52
+ for (const [name, value] of Object.entries(lightExtend)) {
53
+ if (typeof value !== "string") continue;
54
+ resolvedLight[name] = resolveColorEntry(value, lookupLight);
55
+ }
56
+ const result = { ...resolvedLight };
57
+ if (darkExtend) {
58
+ const resolvedDark = {};
59
+ const lookupDark = (name) => {
60
+ const found = resolvedDark[name] ?? existing[name];
61
+ return typeof found === "string" ? found : void 0;
62
+ };
63
+ for (const [name, value] of Object.entries(darkExtend)) {
64
+ resolvedDark[name] = resolveColorEntry(value, lookupDark);
65
+ }
66
+ for (const [name, darkValue] of Object.entries(resolvedDark)) {
67
+ const lightValue = resolvedLight[name];
68
+ if (lightValue === void 0) continue;
69
+ result[name] = { light: lightValue, dark: darkValue };
70
+ }
71
+ }
72
+ return result;
73
+ }
74
+ function resolveKbachConfig(config) {
75
+ let theme = { ...defaultTheme, ...config.theme };
76
+ if (config.extend?.colors) {
77
+ theme = { ...theme, colors: { ...theme.colors, ...resolveColors(config.extend.colors, theme.colors) } };
78
+ }
79
+ if (config.extend?.spacing) {
80
+ theme = { ...theme, spacing: { ...theme.spacing, ...config.extend.spacing } };
81
+ }
82
+ if (config.extend?.screens) {
83
+ theme = { ...theme, screens: { ...theme.screens, ...config.extend.screens } };
84
+ }
85
+ if (config.extend?.fontFamily) {
86
+ theme = { ...theme, fontFamily: { ...theme.fontFamily, ...config.extend.fontFamily } };
87
+ }
88
+ if (config.extend?.container) {
89
+ theme = { ...theme, container: { ...theme.container, ...config.extend.container } };
90
+ }
91
+ if (config.darkMode) {
92
+ theme = { ...theme, darkMode: config.darkMode };
93
+ }
94
+ return theme;
95
+ }
96
+ function applyKbachConfig(config) {
97
+ const theme = resolveKbachConfig(config);
98
+ setTheme(theme);
99
+ resyncDomWithActiveTheme();
100
+ return theme;
101
+ }
102
+
103
+ // src/useTheme.ts
104
+ import { useMemo, useSyncExternalStore } from "react";
105
+ function useTheme() {
106
+ const isDark = useSyncExternalStore(subscribeGlobalDarkMode, getGlobalDarkMode);
107
+ const mode = useSyncExternalStore(subscribeGlobalDarkMode, getGlobalThemeMode);
108
+ return useMemo(
109
+ () => ({ mode, isDark, setMode: setGlobalThemeMode, toggle: toggleGlobalDarkMode }),
110
+ [mode, isDark]
111
+ );
112
+ }
113
+
114
+ // src/ThemeProvider.tsx
115
+ import { useEffect, useRef } from "react";
116
+ import { Fragment, jsx } from "react/jsx-runtime";
117
+ var PERSIST_STORAGE_KEY = "kbach-theme";
118
+ function isThemeMode(value) {
119
+ return value === "light" || value === "dark" || value === "system";
120
+ }
121
+ var mountedProviderCount = 0;
122
+ var warnedMultipleProviders = false;
123
+ function ThemeProvider({ children, defaultMode = "system", persist = false }) {
124
+ useEffect(() => {
125
+ mountedProviderCount++;
126
+ if (mountedProviderCount > 1 && !warnedMultipleProviders) {
127
+ warnedMultipleProviders = true;
128
+ console.warn(
129
+ "[Kbach] Multiple <ThemeProvider> instances are mounted at once.\nDark mode is one global store \u2014 useTheme() reads it everywhere, not scoped per provider \u2014 so their defaultMode/persist seeds will fight over the same state.\nMount exactly one <ThemeProvider>, as high in the tree as convenient."
130
+ );
131
+ }
132
+ return () => {
133
+ mountedProviderCount--;
134
+ };
135
+ }, []);
136
+ const seeded = useRef(false);
137
+ useEffect(() => {
138
+ if (seeded.current) return;
139
+ seeded.current = true;
140
+ if (!persist) {
141
+ seedDefaultMode(defaultMode);
142
+ return;
143
+ }
144
+ let cancelled = false;
145
+ persist.getItem(PERSIST_STORAGE_KEY).then((stored) => {
146
+ if (cancelled) return;
147
+ if (isThemeMode(stored)) seedDefaultMode(stored);
148
+ else seedDefaultMode(defaultMode);
149
+ }).catch(() => {
150
+ if (!cancelled) seedDefaultMode(defaultMode);
151
+ });
152
+ return () => {
153
+ cancelled = true;
154
+ };
155
+ }, []);
156
+ useEffect(() => {
157
+ if (!persist) return;
158
+ return subscribeGlobalDarkMode(() => {
159
+ persist.setItem(PERSIST_STORAGE_KEY, getGlobalThemeMode()).catch(() => {
160
+ });
161
+ });
162
+ }, [persist]);
163
+ return /* @__PURE__ */ jsx(Fragment, { children });
164
+ }
165
+
166
+ // src/useColors.ts
167
+ import { useMemo as useMemo2 } from "react";
168
+ function parseHexRgb2(hex) {
169
+ const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
170
+ if (!m) return null;
171
+ let h = m[1];
172
+ if (h.length === 3) h = h.split("").map((c) => c + c).join("");
173
+ const n = parseInt(h, 16);
174
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
175
+ }
176
+ function applyOpacity(color, opacity) {
177
+ const a = Math.max(0, Math.min(1, opacity / 100));
178
+ if (color.startsWith("#")) {
179
+ const rgb = parseHexRgb2(color);
180
+ return rgb ? `rgba(${rgb.join(",")},${a})` : color;
181
+ }
182
+ if (color.startsWith("rgb(")) return color.replace("rgb(", "rgba(").replace(")", `,${a})`);
183
+ if (color.startsWith("rgba(")) return color.replace(/,\s*[\d.]+\)$/, `,${a})`);
184
+ return color;
185
+ }
186
+ function resolveEntry(entry, isDark) {
187
+ return typeof entry === "string" ? entry : isDark ? entry.dark : entry.light;
188
+ }
189
+ function makeColorsProxy(theme, isDark) {
190
+ const alpha = (color, opacity) => opacity === void 0 ? color : applyOpacity(color, opacity);
191
+ const cache = /* @__PURE__ */ new Map();
192
+ function resolveNamed(key) {
193
+ let name = key;
194
+ let opacity;
195
+ if (key.includes("/")) {
196
+ const slash = key.indexOf("/");
197
+ name = key.slice(0, slash);
198
+ opacity = Number(key.slice(slash + 1));
199
+ }
200
+ const entry = theme.colors[name];
201
+ if (entry === void 0) return void 0;
202
+ const value = resolveEntry(entry, isDark);
203
+ return opacity === void 0 ? value : applyOpacity(value, opacity);
204
+ }
205
+ function makeFamilyProxy(family) {
206
+ return new Proxy({}, {
207
+ get(_, prop) {
208
+ const key = String(prop);
209
+ if (key === "then") return void 0;
210
+ return resolveNamed(`${family}-${key}`);
211
+ }
212
+ });
213
+ }
214
+ const get = (name) => resolveNamed(name) ?? name;
215
+ return new Proxy({ alpha, get }, {
216
+ get(_, prop) {
217
+ const key = String(prop);
218
+ if (key === "then") return void 0;
219
+ if (key === "alpha") return alpha;
220
+ if (key === "get") return get;
221
+ const direct = resolveNamed(key);
222
+ if (direct !== void 0) return direct;
223
+ if (!cache.has(key)) cache.set(key, makeFamilyProxy(key));
224
+ return cache.get(key);
225
+ }
226
+ });
227
+ }
228
+ function useColors() {
229
+ const { isDark } = useTheme();
230
+ const theme = getTheme();
231
+ return useMemo2(() => makeColorsProxy(theme, isDark), [theme, isDark]);
232
+ }
233
+
234
+ // src/useDynamicToken.ts
235
+ import { useSyncExternalStore as useSyncExternalStore2 } from "react";
236
+ function useDynamicToken(name) {
237
+ return useSyncExternalStore2(subscribeDynamicTokens, () => getDynamicToken(name));
238
+ }
239
+
240
+ // src/clsx.ts
241
+ function clsx(...inputs) {
242
+ let out = "";
243
+ for (const input of inputs) {
244
+ const piece = resolveClassValue(input);
245
+ if (piece) out = out ? `${out} ${piece}` : piece;
246
+ }
247
+ return out;
248
+ }
249
+ function resolveClassValue(value) {
250
+ if (!value) return "";
251
+ const type = typeof value;
252
+ if (type === "string" || type === "number" || type === "bigint") return String(value);
253
+ if (Array.isArray(value)) return clsx(...value);
254
+ if (type === "object") {
255
+ let out = "";
256
+ for (const key in value) {
257
+ if (Object.prototype.hasOwnProperty.call(value, key) && value[key]) {
258
+ out = out ? `${out} ${key}` : key;
259
+ }
260
+ }
261
+ return out;
262
+ }
263
+ return "";
264
+ }
265
+
266
+ // src/semanticElements.tsx
267
+ import * as React from "react";
268
+ import { Pressable, Text } from "react-native";
269
+ import { jsx as jsx2 } from "react/jsx-runtime";
270
+ var Button = React.forwardRef(function Button2(props, ref) {
271
+ return /* @__PURE__ */ jsx2(Pressable, { ref, accessibilityRole: "button", ...props });
272
+ });
273
+ var PARAGRAPH_ROLE = "paragraph";
274
+ var Paragraph = React.forwardRef(function Paragraph2(props, ref) {
275
+ return /* @__PURE__ */ jsx2(Text, { ref, role: PARAGRAPH_ROLE, ...props });
276
+ });
277
+ function makeHeading(level) {
278
+ const extra = { "aria-level": level };
279
+ const Heading = React.forwardRef(function Heading2(props, ref) {
280
+ return /* @__PURE__ */ jsx2(Text, { ref, accessibilityRole: "header", ...extra, ...props });
281
+ });
282
+ Heading.displayName = `H${level}`;
283
+ return Heading;
284
+ }
285
+ var H1 = makeHeading(1);
286
+ var H2 = makeHeading(2);
287
+ var H3 = makeHeading(3);
288
+ var H4 = makeHeading(4);
289
+ var H5 = makeHeading(5);
290
+ var H6 = makeHeading(6);
21
291
  export {
292
+ Button,
293
+ H1,
294
+ H2,
295
+ H3,
296
+ H4,
297
+ H5,
298
+ H6,
299
+ Paragraph,
22
300
  ThemeProvider,
301
+ applyKbachConfig,
302
+ clsx,
23
303
  defaultTheme,
304
+ deleteDynamicToken,
305
+ getDynamicToken,
24
306
  getGlobalDarkMode,
25
307
  getGlobalThemeMode,
26
308
  getTheme,
27
309
  resolveClassName,
310
+ resolveKbachConfig,
311
+ setDynamicToken,
28
312
  setGlobalThemeMode,
29
313
  setTheme,
314
+ subscribeDynamicTokens,
30
315
  subscribeGlobalDarkMode,
31
316
  toggleGlobalDarkMode,
32
- useGlobalDarkMode,
317
+ useColors,
318
+ useDynamicToken,
33
319
  useTheme
34
320
  };
@@ -1,10 +1,10 @@
1
- import * as react from 'react';
1
+ import * as React from 'react';
2
2
  export { Fragment } from 'react';
3
3
 
4
4
  declare const jsxDEV: (type: unknown, props: Record<string, unknown> | null, key?: string, isStaticChildren?: boolean, source?: {
5
5
  fileName: string;
6
6
  lineNumber: number;
7
7
  columnNumber: number;
8
- }, self?: unknown) => react.ReactElement;
8
+ }, self?: unknown) => React.ReactElement;
9
9
 
10
10
  export { jsxDEV };