@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,6 +1,363 @@
1
- import {
2
- getThemeJson
3
- } from "./chunk-HK6PDJJK.mjs";
1
+ // src/generatedPalette.ts
2
+ var PALETTE = {
3
+ "amber-1": "#fffbeb",
4
+ "amber-10": "#78350f",
5
+ "amber-11": "#451a03",
6
+ "amber-12": "#291002",
7
+ "amber-2": "#fef3c7",
8
+ "amber-3": "#fde68a",
9
+ "amber-4": "#fcd34d",
10
+ "amber-5": "#fbbf24",
11
+ "amber-6": "#f59e0b",
12
+ "amber-7": "#d97706",
13
+ "amber-8": "#b45309",
14
+ "amber-9": "#92400e",
15
+ "black": "#000000",
16
+ "blue-1": "#eff6ff",
17
+ "blue-10": "#1e3a8a",
18
+ "blue-11": "#172554",
19
+ "blue-12": "#0d1633",
20
+ "blue-2": "#dbeafe",
21
+ "blue-3": "#bfdbfe",
22
+ "blue-4": "#93c5fd",
23
+ "blue-5": "#60a5fa",
24
+ "blue-6": "#3b82f6",
25
+ "blue-7": "#2563eb",
26
+ "blue-8": "#1d4ed8",
27
+ "blue-9": "#1e40af",
28
+ "bronze": "#cd7f32",
29
+ "coal": "#1c1c1c",
30
+ "copper": "#b87333",
31
+ "current": "currentColor",
32
+ "cyan-1": "#ecfeff",
33
+ "cyan-10": "#164e63",
34
+ "cyan-11": "#083344",
35
+ "cyan-12": "#041e28",
36
+ "cyan-2": "#cffafe",
37
+ "cyan-3": "#a5f3fc",
38
+ "cyan-4": "#67e8f9",
39
+ "cyan-5": "#22d3ee",
40
+ "cyan-6": "#06b6d4",
41
+ "cyan-7": "#0891b2",
42
+ "cyan-8": "#0e7490",
43
+ "cyan-9": "#155e75",
44
+ "emerald-1": "#ecfdf5",
45
+ "emerald-10": "#064e3b",
46
+ "emerald-11": "#022c22",
47
+ "emerald-12": "#011a14",
48
+ "emerald-2": "#d1fae5",
49
+ "emerald-3": "#a7f3d0",
50
+ "emerald-4": "#6ee7b7",
51
+ "emerald-5": "#34d399",
52
+ "emerald-6": "#10b981",
53
+ "emerald-7": "#059669",
54
+ "emerald-8": "#047857",
55
+ "emerald-9": "#065f46",
56
+ "fuchsia-1": "#fdf4ff",
57
+ "fuchsia-10": "#701a75",
58
+ "fuchsia-11": "#4a044e",
59
+ "fuchsia-12": "#2d022f",
60
+ "fuchsia-2": "#fae8ff",
61
+ "fuchsia-3": "#f5d0fe",
62
+ "fuchsia-4": "#f0abfc",
63
+ "fuchsia-5": "#e879f9",
64
+ "fuchsia-6": "#d946ef",
65
+ "fuchsia-7": "#c026d3",
66
+ "fuchsia-8": "#a21caf",
67
+ "fuchsia-9": "#86198f",
68
+ "gold": "#d4af37",
69
+ "gray-1": "#f9fafb",
70
+ "gray-10": "#111827",
71
+ "gray-11": "#030712",
72
+ "gray-12": "#020409",
73
+ "gray-2": "#f3f4f6",
74
+ "gray-3": "#e5e7eb",
75
+ "gray-4": "#d1d5db",
76
+ "gray-5": "#9ca3af",
77
+ "gray-6": "#6b7280",
78
+ "gray-7": "#4b5563",
79
+ "gray-8": "#374151",
80
+ "gray-9": "#1f2937",
81
+ "green-1": "#f0fdf4",
82
+ "green-10": "#14532d",
83
+ "green-11": "#052e16",
84
+ "green-12": "#031b0d",
85
+ "green-2": "#dcfce7",
86
+ "green-3": "#bbf7d0",
87
+ "green-4": "#86efac",
88
+ "green-5": "#4ade80",
89
+ "green-6": "#22c55e",
90
+ "green-7": "#16a34a",
91
+ "green-8": "#15803d",
92
+ "green-9": "#166534",
93
+ "indigo-1": "#eef2ff",
94
+ "indigo-10": "#312e81",
95
+ "indigo-11": "#1e1b4b",
96
+ "indigo-12": "#12102d",
97
+ "indigo-2": "#e0e7ff",
98
+ "indigo-3": "#c7d2fe",
99
+ "indigo-4": "#a5b4fc",
100
+ "indigo-5": "#818cf8",
101
+ "indigo-6": "#6366f1",
102
+ "indigo-7": "#4f46e5",
103
+ "indigo-8": "#4338ca",
104
+ "indigo-9": "#3730a3",
105
+ "lime-1": "#f7fee7",
106
+ "lime-10": "#365314",
107
+ "lime-11": "#1a2e05",
108
+ "lime-12": "#0f1b03",
109
+ "lime-2": "#ecfccb",
110
+ "lime-3": "#d9f99d",
111
+ "lime-4": "#bef264",
112
+ "lime-5": "#a3e635",
113
+ "lime-6": "#84cc16",
114
+ "lime-7": "#65a30d",
115
+ "lime-8": "#4d7c0f",
116
+ "lime-9": "#3f6212",
117
+ "neutral-1": "#fafafa",
118
+ "neutral-10": "#171717",
119
+ "neutral-11": "#0a0a0a",
120
+ "neutral-12": "#050505",
121
+ "neutral-2": "#f5f5f5",
122
+ "neutral-3": "#e5e5e5",
123
+ "neutral-4": "#d4d4d4",
124
+ "neutral-5": "#a3a3a3",
125
+ "neutral-6": "#737373",
126
+ "neutral-7": "#525252",
127
+ "neutral-8": "#404040",
128
+ "neutral-9": "#262626",
129
+ "orange-1": "#fff7ed",
130
+ "orange-10": "#7c2d12",
131
+ "orange-11": "#431407",
132
+ "orange-12": "#270c04",
133
+ "orange-2": "#ffedd5",
134
+ "orange-3": "#fed7aa",
135
+ "orange-4": "#fdba74",
136
+ "orange-5": "#fb923c",
137
+ "orange-6": "#f97316",
138
+ "orange-7": "#ea580c",
139
+ "orange-8": "#c2410c",
140
+ "orange-9": "#9a3412",
141
+ "pink-1": "#fdf2f8",
142
+ "pink-10": "#831843",
143
+ "pink-11": "#500724",
144
+ "pink-12": "#300415",
145
+ "pink-2": "#fce7f3",
146
+ "pink-3": "#fbcfe8",
147
+ "pink-4": "#f9a8d4",
148
+ "pink-5": "#f472b6",
149
+ "pink-6": "#ec4899",
150
+ "pink-7": "#db2777",
151
+ "pink-8": "#be185d",
152
+ "pink-9": "#9d174d",
153
+ "purple-1": "#faf5ff",
154
+ "purple-10": "#581c87",
155
+ "purple-11": "#3b0764",
156
+ "purple-12": "#23043c",
157
+ "purple-2": "#f3e8ff",
158
+ "purple-3": "#e9d5ff",
159
+ "purple-4": "#d8b4fe",
160
+ "purple-5": "#c084fc",
161
+ "purple-6": "#a855f7",
162
+ "purple-7": "#9333ea",
163
+ "purple-8": "#7e22ce",
164
+ "purple-9": "#6b21a8",
165
+ "red-1": "#fef2f2",
166
+ "red-10": "#7f1d1d",
167
+ "red-11": "#450a0a",
168
+ "red-12": "#280606",
169
+ "red-2": "#fee2e2",
170
+ "red-3": "#fecaca",
171
+ "red-4": "#fca5a5",
172
+ "red-5": "#f87171",
173
+ "red-6": "#ef4444",
174
+ "red-7": "#dc2626",
175
+ "red-8": "#b91c1c",
176
+ "red-9": "#991b1b",
177
+ "rose-1": "#fff1f2",
178
+ "rose-10": "#881337",
179
+ "rose-11": "#4c0519",
180
+ "rose-12": "#2d030e",
181
+ "rose-2": "#ffe4e6",
182
+ "rose-3": "#fecdd3",
183
+ "rose-4": "#fda4af",
184
+ "rose-5": "#fb7185",
185
+ "rose-6": "#f43f5e",
186
+ "rose-7": "#e11d48",
187
+ "rose-8": "#be123c",
188
+ "rose-9": "#9f1239",
189
+ "silver": "#c0c0c0",
190
+ "sky-1": "#f0f9ff",
191
+ "sky-10": "#0c4a6e",
192
+ "sky-11": "#082f49",
193
+ "sky-12": "#041b2b",
194
+ "sky-2": "#e0f2fe",
195
+ "sky-3": "#bae6fd",
196
+ "sky-4": "#7dd3fc",
197
+ "sky-5": "#38bdf8",
198
+ "sky-6": "#0ea5e9",
199
+ "sky-7": "#0284c7",
200
+ "sky-8": "#0369a1",
201
+ "sky-9": "#075985",
202
+ "slate-1": "#f8fafc",
203
+ "slate-10": "#0f172a",
204
+ "slate-11": "#020617",
205
+ "slate-12": "#01020a",
206
+ "slate-2": "#f1f5f9",
207
+ "slate-3": "#e2e8f0",
208
+ "slate-4": "#cbd5e1",
209
+ "slate-5": "#94a3b8",
210
+ "slate-6": "#64748b",
211
+ "slate-7": "#475569",
212
+ "slate-8": "#334155",
213
+ "slate-9": "#1e293b",
214
+ "stone-1": "#fafaf9",
215
+ "stone-10": "#1c1917",
216
+ "stone-11": "#0c0a09",
217
+ "stone-12": "#070605",
218
+ "stone-2": "#f5f5f4",
219
+ "stone-3": "#e7e5e4",
220
+ "stone-4": "#d6d3d1",
221
+ "stone-5": "#a8a29e",
222
+ "stone-6": "#78716c",
223
+ "stone-7": "#57534e",
224
+ "stone-8": "#44403c",
225
+ "stone-9": "#292524",
226
+ "teal-1": "#f0fdfa",
227
+ "teal-10": "#134e4a",
228
+ "teal-11": "#042f2e",
229
+ "teal-12": "#021c1b",
230
+ "teal-2": "#ccfbf1",
231
+ "teal-3": "#99f6e4",
232
+ "teal-4": "#5eead4",
233
+ "teal-5": "#2dd4bf",
234
+ "teal-6": "#14b8a6",
235
+ "teal-7": "#0d9488",
236
+ "teal-8": "#0f766e",
237
+ "teal-9": "#115e59",
238
+ "transparent": "transparent",
239
+ "violet-1": "#f5f3ff",
240
+ "violet-10": "#4c1d95",
241
+ "violet-11": "#2e1065",
242
+ "violet-12": "#1c0a3d",
243
+ "violet-2": "#ede9fe",
244
+ "violet-3": "#ddd6fe",
245
+ "violet-4": "#c4b5fd",
246
+ "violet-5": "#a78bfa",
247
+ "violet-6": "#8b5cf6",
248
+ "violet-7": "#7c3aed",
249
+ "violet-8": "#6d28d9",
250
+ "violet-9": "#5b21b6",
251
+ "white": "#ffffff",
252
+ "yellow-1": "#fefce8",
253
+ "yellow-10": "#713f12",
254
+ "yellow-11": "#422006",
255
+ "yellow-12": "#271304",
256
+ "yellow-2": "#fef9c3",
257
+ "yellow-3": "#fef08a",
258
+ "yellow-4": "#fde047",
259
+ "yellow-5": "#facc15",
260
+ "yellow-6": "#eab308",
261
+ "yellow-7": "#ca8a04",
262
+ "yellow-8": "#a16207",
263
+ "yellow-9": "#854d0e",
264
+ "zinc-1": "#fafafa",
265
+ "zinc-10": "#18181b",
266
+ "zinc-11": "#09090b",
267
+ "zinc-12": "#050506",
268
+ "zinc-2": "#f4f4f5",
269
+ "zinc-3": "#e4e4e7",
270
+ "zinc-4": "#d4d4d8",
271
+ "zinc-5": "#a1a1aa",
272
+ "zinc-6": "#71717a",
273
+ "zinc-7": "#52525b",
274
+ "zinc-8": "#3f3f46",
275
+ "zinc-9": "#27272a"
276
+ };
277
+
278
+ // src/theme.ts
279
+ var defaultTheme = {
280
+ colors: PALETTE,
281
+ // Real Tailwind's default spacing scale in full — every step is exactly
282
+ // `n * 4px`, including the fractional `.5` steps (`1.5` -> 6px, `2.5` ->
283
+ // 10px, `3.5` -> 14px) and the "px" literal (a bare 1px). Only the
284
+ // "usual stops", though — `jsEngine/shared.ts`'s `spacingPx` (and the
285
+ // native Rust dispatcher's own `spacing_px`) falls back to Tailwind v4's
286
+ // live `n * 4px` formula for any bare numeric step not listed here
287
+ // (`p-0.25`, `w-13`, ...), so this table names the common values and
288
+ // gives a theme override something to target, not the full resolvable
289
+ // set. Mirrors @kbach/react's theme.ts exactly.
290
+ spacing: {
291
+ "0": 0,
292
+ "px": 1,
293
+ "0.5": 2,
294
+ "1": 4,
295
+ "1.5": 6,
296
+ "2": 8,
297
+ "2.5": 10,
298
+ "3": 12,
299
+ "3.5": 14,
300
+ "4": 16,
301
+ "5": 20,
302
+ "6": 24,
303
+ "7": 28,
304
+ "8": 32,
305
+ "9": 36,
306
+ "10": 40,
307
+ "11": 44,
308
+ "12": 48,
309
+ "14": 56,
310
+ "16": 64,
311
+ "20": 80,
312
+ "24": 96,
313
+ "28": 112,
314
+ "32": 128,
315
+ "36": 144,
316
+ "40": 160,
317
+ "44": 176,
318
+ "48": 192,
319
+ "52": 208,
320
+ "56": 224,
321
+ "60": 240,
322
+ "64": 256,
323
+ "72": 288,
324
+ "80": 320,
325
+ "96": 384
326
+ },
327
+ screens: {
328
+ sm: 640,
329
+ md: 768,
330
+ lg: 1024,
331
+ xl: 1280,
332
+ "2xl": 1536
333
+ },
334
+ // Byte-for-byte the same three stacks
335
+ // packages/core-engine/src/resolvers/typography.rs's `font_family_value`
336
+ // falls back to. On native these three still effectively no-op (see
337
+ // `first_font_name`'s own doc comment for why a generic CSS keyword
338
+ // isn't a real loadable font) — only a caller-configured custom name
339
+ // changes native rendering; Expo Web uses the full stack as-is.
340
+ fontFamily: {
341
+ sans: 'ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',
342
+ serif: 'ui-serif, Georgia, Cambria, "Times New Roman", Times, serif',
343
+ mono: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace'
344
+ },
345
+ darkMode: "attribute",
346
+ // Empty by default, matching real Tailwind's own defaults.
347
+ container: {}
348
+ };
349
+ var activeTheme = defaultTheme;
350
+ var activeThemeJson = JSON.stringify(defaultTheme);
351
+ function setTheme(theme) {
352
+ activeTheme = theme;
353
+ activeThemeJson = JSON.stringify(theme);
354
+ }
355
+ function getTheme() {
356
+ return activeTheme;
357
+ }
358
+ function getThemeJson() {
359
+ return activeThemeJson;
360
+ }
4
361
 
5
362
  // src/wasmGlue.generated.ts
6
363
  function generate_css_attr(class_string, theme_json) {
@@ -188,5 +545,8 @@ function resolveClassName(classString) {
188
545
  }
189
546
 
190
547
  export {
548
+ defaultTheme,
549
+ setTheme,
550
+ getTheme,
191
551
  resolveClassName
192
552
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  resolveClassName
3
- } from "./chunk-AXGAYOQ7.mjs";
3
+ } from "./chunk-3ED4FIO2.mjs";
4
4
 
5
5
  // src/jsxRuntimeCoreWeb.ts
6
6
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getTheme
3
- } from "./chunk-HK6PDJJK.mjs";
3
+ } from "./chunk-3ED4FIO2.mjs";
4
4
 
5
5
  // src/darkModeStore.ts
6
6
  import { Appearance } from "react-native";
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Native port of @kbach/react's darkModeStore.ts — same architecture (a
3
+ * single module-level store is the real source of truth;
4
+ * ThemeProvider/useTheme are a thin, OPTIONAL wrapper around it; every
5
+ * function here works standalone with no provider mounted anywhere), with
6
+ * two real platform differences from the web version:
7
+ *
8
+ * 1. No persistence. There's no React-Native-builtin equivalent of
9
+ * localStorage — adding one would mean forcing a real native dependency
10
+ * (e.g. @react-native-async-storage/async-storage) on every consumer,
11
+ * even ones that don't want it. The mode always starts at 'system' on a
12
+ * fresh app launch. If you want persistence, read your own storage at
13
+ * startup (before your first render) and call setGlobalThemeMode() with
14
+ * the result — same "seed once, no built-in write-back" shape as
15
+ * seedDefaultMode() below, just driven by your own storage instead of
16
+ * one this package picks for you.
17
+ * 2. `applyToDom` below IS needed here, unlike what an earlier version of
18
+ * this file's own comment claimed ("no DOM to apply the resolved mode
19
+ * to") — that reasoning only holds for real native (Android/iOS), where
20
+ * nativeBridge.ts's resolveStyle() reads getGlobalDarkMode() directly on
21
+ * every call, no DOM involved at all. This file is ALSO used by Expo
22
+ * Web, though (no `.web.ts` sibling — Metro has nothing to swap in), and
23
+ * Expo Web resolves `dark:` classes to REAL CSS with `[data-theme=
24
+ * "dark"]`-style selectors (see nativeBridge.web.ts) that only ever
25
+ * match if something writes that attribute to the DOM — nothing did,
26
+ * which is exactly why toggling the mode changed `useTheme()`'s own
27
+ * state (a consumer reading `mode`/`isDark` directly, e.g. for a label,
28
+ * updated correctly) while every `dark:`-prefixed style silently never
29
+ * applied. `typeof document === 'undefined'` is what makes one function
30
+ * safe on both platforms: real native's Hermes has no `document` global
31
+ * at all (not even `undefined` as a defined-but-empty value — genuinely
32
+ * unset, which `typeof` can check without throwing), so this always
33
+ * no-ops there, while Expo Web's react-native-web renders into a real
34
+ * browser DOM where it's needed.
35
+ */
36
+ type ThemeMode = 'light' | 'dark' | 'system';
37
+ declare function getGlobalDarkMode(): boolean;
38
+ declare function getGlobalThemeMode(): ThemeMode;
39
+ /** Explicit user choice — takes priority over any later `<ThemeProvider defaultMode>` seed (see `seedDefaultMode` below). Not persisted; see this module's own doc comment. */
40
+ declare function setGlobalThemeMode(nextMode: ThemeMode): void;
41
+ declare function toggleGlobalDarkMode(): void;
42
+ declare function subscribeGlobalDarkMode(listener: () => void): () => void;
43
+ /**
44
+ * Applies `fallback` as the initial mode, but ONLY if nothing has made an
45
+ * explicit choice yet — called once by `<ThemeProvider defaultMode>` on
46
+ * mount, never exported for direct use elsewhere. Unlike the web store,
47
+ * there's no persisted-value check here (nothing to check); the only
48
+ * thing that can beat a seed is a `setGlobalThemeMode()` call that
49
+ * happened first (e.g. your own storage-restore logic run before the
50
+ * provider mounts).
51
+ */
52
+ declare function seedDefaultMode(fallback: ThemeMode): void;
53
+ /** Exported for tests only — resets every module-level field back to its as-if-just-imported state. */
54
+ declare function _resetForTests(): void;
55
+ /** Exported for tests only — removes the Appearance change subscription so a test's mock doesn't leak into the next one. */
56
+ declare function _unsubscribeForTests(): void;
57
+
58
+ export { type ThemeMode, _resetForTests, _unsubscribeForTests, getGlobalDarkMode, getGlobalThemeMode, seedDefaultMode, setGlobalThemeMode, subscribeGlobalDarkMode, toggleGlobalDarkMode };
@@ -1,4 +1,6 @@
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-C6jyCLuG.mjs';
1
+ export { ColorEntry, ContainerConfig, ThemeConfig, defaultTheme, getTheme, setTheme } from './theme';
2
+ export { C as ColorScale, a as ColorsAPI, K as KbachConfig, T as ThemeProvider, b as ThemeProviderProps, c as ThemeState, d as applyKbachConfig, r as resolveKbachConfig, u as useColors, e as useTheme } from './useColors-Br8QhIlE.js';
3
+ export { ThemeMode, getGlobalDarkMode, getGlobalThemeMode, setGlobalThemeMode, subscribeGlobalDarkMode, toggleGlobalDarkMode } from './darkModeStore';
2
4
  import 'react';
3
5
 
4
6
  type StyleValue = string | number | {
@@ -1,4 +1,6 @@
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-C6jyCLuG.mjs';
1
+ export { ColorEntry, ContainerConfig, ThemeConfig, defaultTheme, getTheme, setTheme } from './theme';
2
+ export { C as ColorScale, a as ColorsAPI, K as KbachConfig, T as ThemeProvider, b as ThemeProviderProps, c as ThemeState, d as applyKbachConfig, r as resolveKbachConfig, u as useColors, e as useTheme } from './useColors-Br8QhIlE.js';
3
+ export { ThemeMode, getGlobalDarkMode, getGlobalThemeMode, setGlobalThemeMode, subscribeGlobalDarkMode, toggleGlobalDarkMode } from './darkModeStore';
2
4
  import 'react';
3
5
 
4
6
  /**
@@ -1,25 +1,182 @@
1
- import {
2
- ThemeProvider,
3
- applyKbachConfig,
4
- resolveKbachConfig,
5
- useColors,
6
- useTheme
7
- } from "./chunk-TDWBXJH5.mjs";
8
- import {
9
- resolveClassName
10
- } from "./chunk-AXGAYOQ7.mjs";
11
1
  import {
12
2
  getGlobalDarkMode,
13
3
  getGlobalThemeMode,
4
+ seedDefaultMode,
14
5
  setGlobalThemeMode,
15
6
  subscribeGlobalDarkMode,
16
7
  toggleGlobalDarkMode
17
- } from "./chunk-RBJXE32L.mjs";
8
+ } from "./chunk-XGQWM65X.mjs";
18
9
  import {
19
10
  defaultTheme,
20
11
  getTheme,
12
+ resolveClassName,
21
13
  setTheme
22
- } from "./chunk-HK6PDJJK.mjs";
14
+ } from "./chunk-3ED4FIO2.mjs";
15
+
16
+ // src/config.ts
17
+ function parseHexRgb(hex) {
18
+ const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
19
+ if (!m) return null;
20
+ let h = m[1];
21
+ if (h.length === 3) h = h.split("").map((c) => c + c).join("");
22
+ const n = parseInt(h, 16);
23
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
24
+ }
25
+ function applyOpacityToHex(hex, opacityText) {
26
+ const rgb = parseHexRgb(hex);
27
+ if (!rgb) return hex;
28
+ const a = Number(opacityText) / 100;
29
+ const clamped = Number.isFinite(a) ? Math.min(1, Math.max(0, a)) : 1;
30
+ return `rgba(${rgb.join(",")},${clamped})`;
31
+ }
32
+ function resolveColorEntry(value, lookup) {
33
+ const slash = value.indexOf("/");
34
+ const name = slash === -1 ? value : value.slice(0, slash);
35
+ const opacity = slash === -1 ? void 0 : value.slice(slash + 1);
36
+ const base = lookup(name);
37
+ if (base === void 0) return value;
38
+ return opacity === void 0 ? base : applyOpacityToHex(base, opacity);
39
+ }
40
+ function resolveColors(extend, existing) {
41
+ const resolved = {};
42
+ const lookup = (name) => {
43
+ const found = resolved[name] ?? existing[name];
44
+ return typeof found === "string" ? found : void 0;
45
+ };
46
+ for (const [name, value] of Object.entries(extend)) {
47
+ resolved[name] = resolveColorEntry(value, lookup);
48
+ }
49
+ return resolved;
50
+ }
51
+ function resolveKbachConfig(config) {
52
+ let theme = { ...defaultTheme, ...config.theme };
53
+ if (config.extend?.colors) {
54
+ theme = { ...theme, colors: { ...theme.colors, ...resolveColors(config.extend.colors, theme.colors) } };
55
+ }
56
+ if (config.extend?.spacing) {
57
+ theme = { ...theme, spacing: { ...theme.spacing, ...config.extend.spacing } };
58
+ }
59
+ if (config.extend?.screens) {
60
+ theme = { ...theme, screens: { ...theme.screens, ...config.extend.screens } };
61
+ }
62
+ if (config.extend?.fontFamily) {
63
+ theme = { ...theme, fontFamily: { ...theme.fontFamily, ...config.extend.fontFamily } };
64
+ }
65
+ if (config.extend?.container) {
66
+ theme = { ...theme, container: { ...theme.container, ...config.extend.container } };
67
+ }
68
+ if (config.darkMode) {
69
+ theme = { ...theme, darkMode: config.darkMode };
70
+ }
71
+ return theme;
72
+ }
73
+ function applyKbachConfig(config) {
74
+ const theme = resolveKbachConfig(config);
75
+ setTheme(theme);
76
+ return theme;
77
+ }
78
+
79
+ // src/useTheme.ts
80
+ import { useMemo, useSyncExternalStore } from "react";
81
+ function useTheme() {
82
+ const isDark = useSyncExternalStore(subscribeGlobalDarkMode, getGlobalDarkMode);
83
+ const mode = useSyncExternalStore(subscribeGlobalDarkMode, getGlobalThemeMode);
84
+ return useMemo(
85
+ () => ({ mode, isDark, setMode: setGlobalThemeMode, toggle: toggleGlobalDarkMode }),
86
+ [mode, isDark]
87
+ );
88
+ }
89
+
90
+ // src/ThemeProvider.tsx
91
+ import { useEffect, useRef } from "react";
92
+ import { Fragment, jsx } from "react/jsx-runtime";
93
+ var mountedProviderCount = 0;
94
+ var warnedMultipleProviders = false;
95
+ function ThemeProvider({ children, defaultMode = "system" }) {
96
+ useEffect(() => {
97
+ mountedProviderCount++;
98
+ if (mountedProviderCount > 1 && !warnedMultipleProviders) {
99
+ warnedMultipleProviders = true;
100
+ console.warn(
101
+ "[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."
102
+ );
103
+ }
104
+ return () => {
105
+ mountedProviderCount--;
106
+ };
107
+ }, []);
108
+ const seeded = useRef(false);
109
+ useEffect(() => {
110
+ if (seeded.current) return;
111
+ seeded.current = true;
112
+ seedDefaultMode(defaultMode);
113
+ }, []);
114
+ return /* @__PURE__ */ jsx(Fragment, { children });
115
+ }
116
+
117
+ // src/useColors.ts
118
+ function parseHexRgb2(hex) {
119
+ const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
120
+ if (!m) return null;
121
+ let h = m[1];
122
+ if (h.length === 3) h = h.split("").map((c) => c + c).join("");
123
+ const n = parseInt(h, 16);
124
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
125
+ }
126
+ function applyOpacity(color, opacity) {
127
+ const a = Math.max(0, Math.min(1, opacity / 100));
128
+ if (color.startsWith("#")) {
129
+ const rgb = parseHexRgb2(color);
130
+ return rgb ? `rgba(${rgb.join(",")},${a})` : color;
131
+ }
132
+ if (color.startsWith("rgb(")) return color.replace("rgb(", "rgba(").replace(")", `,${a})`);
133
+ if (color.startsWith("rgba(")) return color.replace(/,\s*[\d.]+\)$/, `,${a})`);
134
+ return color;
135
+ }
136
+ function resolveEntry(entry, isDark) {
137
+ return typeof entry === "string" ? entry : isDark ? entry.dark : entry.light;
138
+ }
139
+ function makeColorsProxy(theme, isDark) {
140
+ const alpha = (color, opacity) => opacity === void 0 ? color : applyOpacity(color, opacity);
141
+ const cache = /* @__PURE__ */ new Map();
142
+ function resolveNamed(key) {
143
+ let name = key;
144
+ let opacity;
145
+ if (key.includes("/")) {
146
+ const slash = key.indexOf("/");
147
+ name = key.slice(0, slash);
148
+ opacity = Number(key.slice(slash + 1));
149
+ }
150
+ const entry = theme.colors[name];
151
+ if (entry === void 0) return void 0;
152
+ const value = resolveEntry(entry, isDark);
153
+ return opacity === void 0 ? value : applyOpacity(value, opacity);
154
+ }
155
+ function makeFamilyProxy(family) {
156
+ return new Proxy({}, {
157
+ get(_, prop) {
158
+ const key = String(prop);
159
+ if (key === "then") return void 0;
160
+ return resolveNamed(`${family}-${key}`);
161
+ }
162
+ });
163
+ }
164
+ return new Proxy({ alpha }, {
165
+ get(_, prop) {
166
+ const key = String(prop);
167
+ if (key === "then") return void 0;
168
+ if (key === "alpha") return alpha;
169
+ const direct = resolveNamed(key);
170
+ if (direct !== void 0) return direct;
171
+ if (!cache.has(key)) cache.set(key, makeFamilyProxy(key));
172
+ return cache.get(key);
173
+ }
174
+ });
175
+ }
176
+ function useColors() {
177
+ const { isDark } = useTheme();
178
+ return makeColorsProxy(getTheme(), isDark);
179
+ }
23
180
  export {
24
181
  ThemeProvider,
25
182
  applyKbachConfig,