@kbach/react 0.6.51 → 1.0.0-beta.1

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.
@@ -0,0 +1,446 @@
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: {
281
+ ...PALETTE,
282
+ surface: { light: "#f9fafb", dark: "#111827" }
283
+ },
284
+ // Real Tailwind's default spacing scale in full — every step is exactly
285
+ // `n * 4px` (Tailwind's base spacing unit), including the fractional
286
+ // `.5` steps (`1.5` -> 6px, `2.5` -> 10px, `3.5` -> 14px) and the "px"
287
+ // literal (a bare 1px, for `p-px`-style hairline spacing). Previously
288
+ // this only had {0,1,2,4,6,8} — a handful of spot-checked values, not
289
+ // the real scale — so anything else (`p-3`, `w-5`, `border-2`, `gap-10`,
290
+ // ...) silently failed to resolve (an unknown spacing key returns `None`
291
+ // the same way an unknown class does, with no error). "0" itself is
292
+ // still needed explicitly (not derivable as "any number * 4") for the
293
+ // same reason it always was: `sticky top-0` needs an actual "0" key to
294
+ // resolve at all, not just fall through as unresolvable.
295
+ spacing: {
296
+ "0": 0,
297
+ "px": 1,
298
+ "0.5": 2,
299
+ "1": 4,
300
+ "1.5": 6,
301
+ "2": 8,
302
+ "2.5": 10,
303
+ "3": 12,
304
+ "3.5": 14,
305
+ "4": 16,
306
+ "5": 20,
307
+ "6": 24,
308
+ "7": 28,
309
+ "8": 32,
310
+ "9": 36,
311
+ "10": 40,
312
+ "11": 44,
313
+ "12": 48,
314
+ "14": 56,
315
+ "16": 64,
316
+ "20": 80,
317
+ "24": 96,
318
+ "28": 112,
319
+ "32": 128,
320
+ "36": 144,
321
+ "40": 160,
322
+ "44": 176,
323
+ "48": 192,
324
+ "52": 208,
325
+ "56": 224,
326
+ "60": 240,
327
+ "64": 256,
328
+ "72": 288,
329
+ "80": 320,
330
+ "96": 384
331
+ },
332
+ screens: {
333
+ sm: 640,
334
+ md: 768,
335
+ lg: 1024,
336
+ xl: 1280,
337
+ "2xl": 1536
338
+ },
339
+ darkMode: "attribute"
340
+ };
341
+ var activeTheme = defaultTheme;
342
+ var activeThemeJson = JSON.stringify(defaultTheme);
343
+ function setTheme(theme) {
344
+ activeTheme = theme;
345
+ activeThemeJson = JSON.stringify(theme);
346
+ }
347
+ function getTheme() {
348
+ return activeTheme;
349
+ }
350
+ function getThemeJson() {
351
+ return activeThemeJson;
352
+ }
353
+
354
+ // src/reset.ts
355
+ var RESET_STYLE_ID = "kbach-reset";
356
+ var RESET_RULES = [
357
+ // border-style: solid means border-N utilities show a visible border without an extra border-solid class.
358
+ // border-width: 0 keeps all elements borderless by default.
359
+ { css: "*, *::before, *::after { box-sizing: border-box; border-width: 0; border-style: solid; border-color: currentColor; }" },
360
+ { css: "body { margin: 0; padding: 0; }" },
361
+ { css: "h1, h2, h3, h4, h5, h6 { margin: 0; font-size: inherit; font-weight: inherit; }", tags: ["h1", "h2", "h3", "h4", "h5", "h6"] },
362
+ { css: "p { margin: 0; }", tags: ["p"] },
363
+ { css: "a { color: inherit; text-decoration: none; }", tags: ["a"] },
364
+ { css: "ul, ol { margin: 0; padding: 0; list-style: none; }", tags: ["ul", "ol"] },
365
+ // svg here only covers a literal <svg> tag in JSX — an icon imported as
366
+ // a component (e.g. `<ArrowIcon />`) never appears as the text "svg" in
367
+ // source, so this rule won't be pulled in by that usage alone. Same
368
+ // caveat applies to every tag-gated rule below: detection is a literal
369
+ // source-text scan (see vite-plugin/scan.ts's scanUsedTags), not a real
370
+ // DOM/type check.
371
+ { css: "img, video, svg { display: block; max-width: 100%; }", tags: ["img", "video", "svg"] },
372
+ // appearance: none is deliberately NOT applied to checkbox/radio/select below —
373
+ // stripping it hides their native checkmark/arrow with nothing rendered in its
374
+ // place, leaving an invisible checkbox or an arrow-less <select> that looks like
375
+ // plain text. Text-like inputs, textarea, and button don't have that problem
376
+ // (their native chrome is just a skin around content utilities can fully
377
+ // restyle), so they keep the blank-canvas treatment.
378
+ // :where() wraps the :not() exclusions so they contribute ZERO specificity
379
+ // (unlike a bare `input:not([type='checkbox']):not([type='radio'])`, whose
380
+ // two :not([attr]) clauses each add a class-level specificity point — (0,2,1)
381
+ // total, MORE than any single utility class (0,1,0)). Without :where(), this
382
+ // reset's `color: inherit` always won the cascade over a text-* color
383
+ // utility applied directly to a <input>/<textarea> regardless of source
384
+ // order, since author rules only override on a tie or higher specificity —
385
+ // confirmed on a real app: a TextInput's own text color utility resolved
386
+ // and injected correctly, class and all, but silently never painted.
387
+ {
388
+ css: "input:where(:not([type='checkbox']):not([type='radio'])), textarea { appearance: none; -webkit-appearance: none; background: transparent; padding: 0; margin: 0; font: inherit; color: inherit; line-height: inherit; }",
389
+ tags: ["input", "textarea"]
390
+ },
391
+ // Native checkbox/radio/range still get typography + spacing normalized, and
392
+ // accent-color re-themes their native indicator to the current text color
393
+ // instead of the browser/OS default blue, so they stay on-brand without
394
+ // needing to be rebuilt from scratch. Wrapped in :where() for the exact
395
+ // same reason as the input:not(...) exclusions above — a bare
396
+ // `input[type='range']` attribute selector has specificity (0,1,1),
397
+ // MORE than any single utility class (0,1,0), so an `accent-*` utility
398
+ // (Phase 23) applied directly to a checkbox/radio/range would resolve and
399
+ // inject correctly but silently never paint, losing the cascade to this
400
+ // reset regardless of source order — confirmed by hand via
401
+ // getComputedStyle on a real `accent-red-6` range input, which reported
402
+ // `currentColor`'s inherited value instead. `:where()` zeroes this
403
+ // selector's specificity contribution entirely, so any `accent-*`
404
+ // utility trivially wins once applied.
405
+ {
406
+ css: ":where(input[type='checkbox'], input[type='radio'], input[type='range']) { margin: 0; font: inherit; accent-color: currentColor; }",
407
+ tags: ["input"]
408
+ },
409
+ // select keeps its native chrome (border/background/arrow are all part of the
410
+ // same OS-drawn widget that appearance: none would blank out) — only typography
411
+ // and spacing are normalized so it still matches surrounding text.
412
+ { css: "select { margin: 0; font: inherit; color: inherit; line-height: inherit; }", tags: ["select"] },
413
+ { css: "button { appearance: none; -webkit-appearance: none; background: transparent; padding: 0; margin: 0; font: inherit; color: inherit; cursor: pointer; line-height: inherit; text-align: inherit; }", tags: ["button"] },
414
+ // Also covers any element opted into the button role (`role="button"` on
415
+ // a <div>/<span>) — but only when a literal <button> tag is ALSO
416
+ // somewhere in the scanned source, since detection here is purely
417
+ // tag-name-based; a project using role="button" exclusively, with no
418
+ // real <button> anywhere, won't pull this rule in. Acceptable tradeoff
419
+ // for this project's scope (rare pattern) — cheap enough that scanning
420
+ // for it separately isn't worth the added complexity.
421
+ { css: "button, [role='button'] { cursor: pointer; }", tags: ["button"] },
422
+ { css: ":disabled { cursor: default; }", tags: ["button", "input", "select", "textarea"] },
423
+ { css: "textarea { resize: vertical; }", tags: ["textarea"] },
424
+ // Firefox renders placeholders at ~54% opacity by default; every other browser uses 1 —
425
+ // normalize to 1 so placeholder color is consistent and fully controlled by the placeholder: modifier.
426
+ { css: "::placeholder { opacity: 1; }", tags: ["input", "textarea"] },
427
+ { css: "input[type='number']::-webkit-inner-spin-button, input[type='number']::-webkit-outer-spin-button { margin: 0; }", tags: ["input"] },
428
+ { css: "input[type='search']::-webkit-search-decoration, input[type='search']::-webkit-search-cancel-button { -webkit-appearance: none; }", tags: ["input"] },
429
+ { css: "fieldset { padding: 0; margin: 0; }", tags: ["fieldset"] },
430
+ { css: "table { border-collapse: collapse; border-spacing: 0; }", tags: ["table"] }
431
+ ];
432
+ var BASE_RESET = RESET_RULES.map((r) => r.css).join("\n");
433
+ function buildResetCSS(usedTags) {
434
+ if (!usedTags) return BASE_RESET;
435
+ return RESET_RULES.filter((r) => !r.tags || r.tags.some((t) => usedTags.has(t))).map((r) => r.css).join("\n");
436
+ }
437
+
438
+ export {
439
+ defaultTheme,
440
+ setTheme,
441
+ getTheme,
442
+ getThemeJson,
443
+ RESET_STYLE_ID,
444
+ BASE_RESET,
445
+ buildResetCSS
446
+ };
@@ -0,0 +1,100 @@
1
+ import {
2
+ BASE_RESET,
3
+ RESET_STYLE_ID,
4
+ getThemeJson
5
+ } from "./chunk-FOQWQDF4.mjs";
6
+
7
+ // src/wasmLoader.ts
8
+ import init, { generate_css as wasmGenerateCss } from "@kbach/core-engine";
9
+ var readyPromise = null;
10
+ var ready = false;
11
+ function initKbach() {
12
+ if (!readyPromise) {
13
+ readyPromise = init().then(() => {
14
+ ready = true;
15
+ });
16
+ }
17
+ return readyPromise;
18
+ }
19
+ function isKbachReady() {
20
+ return ready;
21
+ }
22
+ function generateCss(classString, themeJson) {
23
+ if (!ready) {
24
+ throw new Error(
25
+ "[kbach] generateCss() was called before initKbach() resolved. Call `await initKbach()` once at startup (e.g. before rendering your app) before using kb()."
26
+ );
27
+ }
28
+ return wasmGenerateCss(classString, themeJson);
29
+ }
30
+
31
+ // src/kb.ts
32
+ var runtimeCSSDisabled = false;
33
+ function disableRuntimeCSS() {
34
+ runtimeCSSDisabled = true;
35
+ }
36
+ function isRuntimeCSSDisabled() {
37
+ return runtimeCSSDisabled;
38
+ }
39
+ var styleEl = null;
40
+ var sheetKeys = [];
41
+ var ruleOrderByKey = /* @__PURE__ */ new Map();
42
+ function getStyleEl() {
43
+ if (styleEl) return styleEl;
44
+ styleEl = document.createElement("style");
45
+ styleEl.setAttribute("data-kbach", "");
46
+ document.head.appendChild(styleEl);
47
+ return styleEl;
48
+ }
49
+ function findInsertionIndex(order) {
50
+ let lo = 0;
51
+ let hi = sheetKeys.length;
52
+ while (lo < hi) {
53
+ const mid = lo + hi >>> 1;
54
+ if (ruleOrderByKey.get(sheetKeys[mid]) > order) hi = mid;
55
+ else lo = mid + 1;
56
+ }
57
+ return lo;
58
+ }
59
+ function injectRule(rule, order) {
60
+ if (ruleOrderByKey.has(rule)) return;
61
+ const sheet = getStyleEl().sheet;
62
+ if (!sheet) return;
63
+ const idx = findInsertionIndex(order);
64
+ try {
65
+ sheet.insertRule(rule, idx);
66
+ } catch {
67
+ return;
68
+ }
69
+ sheetKeys.splice(idx, 0, rule);
70
+ ruleOrderByKey.set(rule, order);
71
+ }
72
+ var resetChecked = false;
73
+ function ensureResetInjected() {
74
+ if (resetChecked) return;
75
+ resetChecked = true;
76
+ if (document.getElementById(RESET_STYLE_ID)) return;
77
+ const el = document.createElement("style");
78
+ el.id = RESET_STYLE_ID;
79
+ el.textContent = BASE_RESET;
80
+ document.head.insertBefore(el, document.head.firstChild);
81
+ }
82
+ function kb(classString) {
83
+ const json = generateCss(classString, getThemeJson());
84
+ const { className, rules } = JSON.parse(json);
85
+ if (!runtimeCSSDisabled) {
86
+ ensureResetInjected();
87
+ for (const { rule, order } of rules) {
88
+ injectRule(rule, order);
89
+ }
90
+ }
91
+ return className;
92
+ }
93
+
94
+ export {
95
+ initKbach,
96
+ isKbachReady,
97
+ disableRuntimeCSS,
98
+ isRuntimeCSSDisabled,
99
+ kb
100
+ };
@@ -0,0 +1,117 @@
1
+ export { T as ThemeConfig, d as defaultTheme, g as getTheme, s as setTheme } from './theme-BKAb78KP.mjs';
2
+ import * as react from 'react';
3
+ import { ReactNode } from 'react';
4
+
5
+ /**
6
+ * Loads and instantiates the Rust/WASM core engine. Call once at startup
7
+ * (e.g. before `ReactDOM.createRoot(...).render(...)`) and await it — every
8
+ * subsequent call returns the same memoized promise, so it's safe to call
9
+ * again from multiple entry points.
10
+ */
11
+ declare function initKbach(): Promise<void>;
12
+ declare function isKbachReady(): boolean;
13
+
14
+ declare function disableRuntimeCSS(): void;
15
+ declare function isRuntimeCSSDisabled(): boolean;
16
+ /**
17
+ * Resolves a Kbach class string via the Rust/WASM engine, cascade-order-safe
18
+ * injects the resulting CSS rules into a single `<style data-kbach>` tag,
19
+ * and returns the class string unchanged for use as `className`.
20
+ *
21
+ * Must be called after `await initKbach()` resolves — see wasmLoader.ts.
22
+ */
23
+ declare function kb(classString: string): string;
24
+
25
+ /**
26
+ * Renders Kbach's base browser-default reset (borderless button/input,
27
+ * visible checkbox/radio, no arrow-less <select>, etc.) as a plain <style>
28
+ * tag so it's part of the page's initial HTML.
29
+ *
30
+ * Runtime-only setups (no Vite plugin / static kbach.css) otherwise only get
31
+ * this reset once kb()'s first call injects it — fine for a plain CSR app,
32
+ * but under SSR the server has no JS to run it, so the first paint ships
33
+ * with raw browser defaults (e.g. the native button border) until
34
+ * hydration catches up. Render this once, as high in <head> as your
35
+ * framework allows, to close that gap.
36
+ *
37
+ * Skips rendering entirely once disableRuntimeCSS() has fired — the Vite
38
+ * plugin calls it automatically wherever kbach.css gets imported (see
39
+ * vite-plugin/format.ts's own BASE_RESET inlining), and that static file
40
+ * already has this exact reset. No isNative check (unlike old-kbach's
41
+ * version of this component): @kbach/react is a web-only package now, so
42
+ * there's no cross-platform import path for this component to guard against.
43
+ */
44
+ declare function KbachReset(): react.JSX.Element | null;
45
+
46
+ /**
47
+ * Port of old-kbach's dark-mode architecture (`packages/ui/src/core/
48
+ * darkModeStore.ts` + `ThemeProvider.tsx`), simplified for this package's
49
+ * web-only scope: a single module-level store is the actual source of
50
+ * truth, and `<ThemeProvider>`/`useTheme()` (see `ThemeProvider.tsx`) are a
51
+ * thin, OPTIONAL React wrapper around it — every function here works
52
+ * standalone, with no provider mounted anywhere, which is the whole point:
53
+ * a plain script, an event handler, or a component that never wants
54
+ * Context can call `toggleGlobalDarkMode()` directly.
55
+ */
56
+ type ThemeMode = 'light' | 'dark' | 'system';
57
+ declare function getGlobalDarkMode(): boolean;
58
+ declare function getGlobalThemeMode(): ThemeMode;
59
+ /** Explicit user choice — persisted, and takes priority over any later `<ThemeProvider defaultMode>` seed (see `seedDefaultMode` below). */
60
+ declare function setGlobalThemeMode(nextMode: ThemeMode): void;
61
+ declare function toggleGlobalDarkMode(): void;
62
+ declare function subscribeGlobalDarkMode(listener: () => void): () => void;
63
+
64
+ /**
65
+ * Reactive read of the global dark-mode store — works with or without a
66
+ * `<ThemeProvider>` mounted anywhere in the tree, since it subscribes to
67
+ * `darkModeStore.ts` directly. `useSyncExternalStore`'s SSR snapshot always
68
+ * returns `false` (light), matching `applyToDom`'s own server no-op — the
69
+ * server and the client's very first render agree, so there's no
70
+ * hydration-mismatch warning; the real value (if different) applies on the
71
+ * client immediately after.
72
+ */
73
+ declare function useGlobalDarkMode(): boolean;
74
+
75
+ interface ThemeProviderProps {
76
+ children: ReactNode;
77
+ /**
78
+ * Applied once, on this provider's first mount, but ONLY if the user has
79
+ * no persisted preference already (see `darkModeStore.ts::seedDefaultMode`)
80
+ * — an explicit prior choice always wins over a component's own default.
81
+ */
82
+ defaultMode?: ThemeMode;
83
+ }
84
+ /**
85
+ * Optional React Context wrapper around `darkModeStore.ts`'s single global
86
+ * store — port of old-kbach's `ThemeProvider` (`packages/ui/src/
87
+ * ThemeProvider.tsx`), same "provider is a thin wrapper around a global
88
+ * store, not the source of truth itself" shape, simplified to this
89
+ * package's web-only scope (no native `useColorScheme()`/`windowWidth`
90
+ * branch, no `disablePersistence` prop — persistence is always on, since
91
+ * `darkModeStore.ts` already guards every `localStorage` access for
92
+ * environments where it's unavailable).
93
+ *
94
+ * Because the store is global, MULTIPLE mounted providers share the exact
95
+ * same `mode`/`isDark` state rather than each getting their own scoped
96
+ * value — mounting more than one is very likely a mistake (each fighting
97
+ * over the same state via a different `defaultMode`), so this warns once
98
+ * in dev, matching old-kbach's identical guard.
99
+ */
100
+ declare function ThemeProvider({ children, defaultMode }: ThemeProviderProps): react.JSX.Element;
101
+
102
+ interface ThemeContextValue {
103
+ mode: ThemeMode;
104
+ isDark: boolean;
105
+ setMode: (mode: ThemeMode) => void;
106
+ toggle: () => void;
107
+ }
108
+ /**
109
+ * Requires a `<ThemeProvider>` ancestor — throws otherwise, since a
110
+ * component that destructures `{ mode, setMode }` genuinely needs Context
111
+ * (unlike a component that just wants the dark/light boolean, which should
112
+ * reach for `useGlobalDarkMode()` instead and never needs a provider at
113
+ * all).
114
+ */
115
+ declare function useTheme(): ThemeContextValue;
116
+
117
+ export { KbachReset, type ThemeContextValue, type ThemeMode, ThemeProvider, type ThemeProviderProps, disableRuntimeCSS, getGlobalDarkMode, getGlobalThemeMode, initKbach, isKbachReady, isRuntimeCSSDisabled, kb, setGlobalThemeMode, subscribeGlobalDarkMode, toggleGlobalDarkMode, useGlobalDarkMode, useTheme };