@kbach/react-native 1.0.0-beta.15 → 1.0.0-beta.16

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.
@@ -1,186 +0,0 @@
1
- import {
2
- getGlobalDarkMode,
3
- getGlobalThemeMode,
4
- seedDefaultMode,
5
- setGlobalThemeMode,
6
- subscribeGlobalDarkMode,
7
- toggleGlobalDarkMode
8
- } from "./chunk-RBJXE32L.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,14 +0,0 @@
1
- import {
2
- resolveStyle
3
- } from "./chunk-JMNJCPGK.mjs";
4
- import {
5
- createJsxFunctions
6
- } from "./chunk-EMZ47OSG.mjs";
7
-
8
- // src/jsx-runtime.tsx
9
- var { jsx, jsxs } = createJsxFunctions(resolveStyle);
10
-
11
- export {
12
- jsx,
13
- jsxs
14
- };
package/dist/index.mjs DELETED
@@ -1,38 +0,0 @@
1
- import {
2
- ThemeProvider,
3
- applyKbachConfig,
4
- resolveKbachConfig,
5
- useColors,
6
- useTheme
7
- } from "./chunk-TDWBXJH5.mjs";
8
- import {
9
- resolveStyle
10
- } from "./chunk-JMNJCPGK.mjs";
11
- import {
12
- getGlobalDarkMode,
13
- getGlobalThemeMode,
14
- setGlobalThemeMode,
15
- subscribeGlobalDarkMode,
16
- toggleGlobalDarkMode
17
- } from "./chunk-RBJXE32L.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,18 +0,0 @@
1
- import {
2
- jsx,
3
- jsxs
4
- } from "./chunk-UNZ6PQVO.mjs";
5
- import "./chunk-JMNJCPGK.mjs";
6
- import {
7
- Fragment,
8
- createJsxDEV
9
- } from "./chunk-EMZ47OSG.mjs";
10
- import "./chunk-RBJXE32L.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,15 +0,0 @@
1
- import {
2
- jsx,
3
- jsxs
4
- } from "./chunk-UNZ6PQVO.mjs";
5
- import "./chunk-JMNJCPGK.mjs";
6
- import {
7
- Fragment
8
- } from "./chunk-EMZ47OSG.mjs";
9
- import "./chunk-RBJXE32L.mjs";
10
- import "./chunk-HK6PDJJK.mjs";
11
- export {
12
- Fragment,
13
- jsx,
14
- jsxs
15
- };
File without changes