@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
@@ -2,9 +2,8 @@ import {
2
2
  Fragment,
3
3
  jsx,
4
4
  jsxs
5
- } from "./chunk-YOC3SHF5.mjs";
6
- import "./chunk-H5Z24XX5.mjs";
7
- import "./chunk-HK6PDJJK.mjs";
5
+ } from "./chunk-6F44N62F.mjs";
6
+ import "./chunk-R7E5D3D6.mjs";
8
7
  export {
9
8
  Fragment,
10
9
  jsx,
@@ -0,0 +1,334 @@
1
+ import { ThemeConfig, ContainerConfig } from './theme';
2
+ import { ThemeMode } from './darkModeStore';
3
+ import * as React from 'react';
4
+ import { ReactNode } from 'react';
5
+ import { PressableProps, TextProps } from 'react-native';
6
+
7
+ /**
8
+ * A `kbach.config.js`-style theme customization — same shape as
9
+ * @kbach/react's `KbachConfig`, minus @kbach/react's own PER-COLOR
10
+ * `{ light, dark }` object form in `extend.colors` specifically (real
11
+ * mode-aware colors here are written via the grouped `dark` key instead —
12
+ * see `KbachConfig.extend.colors`'s own doc comment below): aliasing/
13
+ * opacity math on an individual color value here only ever operates on
14
+ * plain hex (`brand: 'blue-6'`, `brandSoft: 'brand/30'`), matching
15
+ * `jsEngine/resolvers/color.ts`'s `lookupHex`'s own Plain-only convention
16
+ * — a reference to an EXISTING color that happens to be mode-aware
17
+ * (`theme.colors` can hold those, for `useColors()`; see `theme.ts`'s own
18
+ * `ColorEntry` doc comment) just doesn't resolve as an alias, falling
19
+ * through to "literal CSS value" the same way an unknown name would. A
20
+ * config object goes in, a resolved `ThemeConfig` comes out, via one PURE
21
+ * function (`resolveKbachConfig`) — no plugins, no live-update store,
22
+ * nothing to keep "in sync."
23
+ */
24
+ interface KbachConfig {
25
+ darkMode?: ThemeConfig['darkMode'];
26
+ /**
27
+ * REPLACES the named section of `defaultTheme` entirely — use `extend` to
28
+ * add instead of replace. `container` isn't here (only under `extend`
29
+ * below) — see @kbach/react's identical `KbachConfig.theme` doc comment
30
+ * for why.
31
+ */
32
+ theme?: Partial<Pick<ThemeConfig, 'colors' | 'spacing' | 'screens' | 'fontFamily'>>;
33
+ /** Merges INTO `defaultTheme` (or `theme` above, if also supplied) — the common case. */
34
+ extend?: {
35
+ /**
36
+ * A value is either a literal hex color, or a REFERENCE to another
37
+ * color name, optionally with an opacity suffix. Two things can be
38
+ * referenced: a BUILT-IN palette color, always available regardless of
39
+ * ordering (`accent: 'orange-5'`, `accentSoft: 'orange-5/50'`), or a
40
+ * custom color defined EARLIER in this same object (`{ brand:
41
+ * '#ff6b35', brandSoft: 'brand/30' }` — `brandSoft` resolves to
42
+ * `brand`'s own value at 30% opacity). A string that doesn't match any
43
+ * known color name is treated as a literal CSS value instead.
44
+ *
45
+ * `dark` is a reserved key, not a color name: a parallel map of
46
+ * dark-mode overrides for any of the OTHER names in this same object —
47
+ * `{ surface: 'gray-2', card: 'white', dark: { surface: 'gray-11',
48
+ * card: 'gray-9' } }` makes `surface`/`card` mode-aware
49
+ * (`{ light, dark }` entries in the resolved theme), while `brand`
50
+ * (never mentioned under `dark`) stays a plain, mode-independent
51
+ * color. A name under `dark` with no matching top-level (light) entry
52
+ * is skipped — mode-aware colors need both sides written out, and
53
+ * inventing a "light" value out of nowhere would be worse than just
54
+ * not creating the entry at all. References inside `dark` resolve
55
+ * against the built-in palette and OTHER entries within `dark` itself
56
+ * (not against the light-side custom colors) — the same
57
+ * "self-contained, ordering-independent-of-the-other-side" resolution
58
+ * the light side already gets, just mirrored.
59
+ */
60
+ colors?: {
61
+ [colorName: string]: string | Record<string, string> | undefined;
62
+ dark?: Record<string, string>;
63
+ };
64
+ spacing?: Record<string, number>;
65
+ screens?: Record<string, number>;
66
+ /**
67
+ * Named font stacks, e.g. `{ display: '"Cal Sans", sans-serif' }` —
68
+ * adds to (or overrides one of) `defaultTheme.fontFamily`'s three
69
+ * names. Write it as a real web-shaped fallback stack even though this
70
+ * is the React Native package — native's own resolver strips it down
71
+ * to a single bare name at resolve time (RN's `fontFamily` prop can't
72
+ * take a fallback list), so the SAME config still works unmodified on
73
+ * Expo Web, which needs the full stack.
74
+ */
75
+ fontFamily?: Record<string, string>;
76
+ /** `{ center: true, padding: '2rem' }` — see `ContainerConfig`'s own doc comment. */
77
+ container?: ContainerConfig;
78
+ };
79
+ }
80
+ /** Merges a `KbachConfig` into `defaultTheme` — a pure function, no side effects. */
81
+ declare function resolveKbachConfig(config: KbachConfig): ThemeConfig;
82
+ /**
83
+ * `resolveKbachConfig()` + `setTheme()` in one call — the usual entry point
84
+ * from app code. Also re-syncs the DOM (Expo Web only) to the CURRENT
85
+ * dark-mode state right after `setTheme()` — see
86
+ * `resyncDomWithActiveTheme`'s own doc comment for why this is required,
87
+ * not optional.
88
+ */
89
+ declare function applyKbachConfig(config: KbachConfig): ThemeConfig;
90
+
91
+ interface ThemeState {
92
+ mode: ThemeMode;
93
+ isDark: boolean;
94
+ setMode: (mode: ThemeMode) => void;
95
+ toggle: () => void;
96
+ }
97
+ /**
98
+ * The one hook for reading and writing Kbach's dark-mode state. Reads
99
+ * `darkModeStore.ts`'s global store directly via `useSyncExternalStore` —
100
+ * that module-level store, not React Context, is the actual source of
101
+ * truth (every provider used to just mirror it into a Context value), so
102
+ * this works from ANY component, with or without a `<ThemeProvider>`
103
+ * mounted anywhere in the tree. `<ThemeProvider>` still exists, but purely
104
+ * as an optional convenience for seeding an app's initial `defaultMode` —
105
+ * see its own doc comment. No server-snapshot argument (unlike
106
+ * @kbach/react's web version) — React Native has no SSR concept at all,
107
+ * so there's no third argument for `useSyncExternalStore` to need.
108
+ */
109
+ declare function useTheme(): ThemeState;
110
+
111
+ /**
112
+ * The exact shape `@react-native-async-storage/async-storage`'s default
113
+ * export already has — pass it directly as `persist`. Any other async
114
+ * key-value store (MMKV, SecureStore, a custom backend, ...) works too, as
115
+ * long as it exposes these two methods with this signature. Kept minimal
116
+ * on purpose: `ThemeProvider` never imports a storage library itself (see
117
+ * `darkModeStore.ts`'s own doc comment on why this package forces no real
118
+ * native dependency on consumers who don't want persistence) — deliberately
119
+ * NOT a `boolean`-only option that reaches for AsyncStorage internally,
120
+ * since Metro resolves every `require()`/`import` target at BUNDLE time
121
+ * regardless of try/catch, so a library-internal "if installed, use it"
122
+ * check can't actually degrade gracefully when the package is absent — an
123
+ * injected adapter sidesteps that entirely.
124
+ */
125
+ interface ThemeStorageAdapter {
126
+ getItem(key: string): Promise<string | null>;
127
+ setItem(key: string, value: string): Promise<void>;
128
+ }
129
+ interface ThemeProviderProps {
130
+ children: ReactNode;
131
+ /**
132
+ * Applied once, on this provider's first mount, but ONLY if nothing has
133
+ * made an explicit mode choice yet (see
134
+ * `darkModeStore.ts::seedDefaultMode`) — an explicit prior choice always
135
+ * wins over a component's own default. If `persist` is also set and a
136
+ * persisted mode is found, the persisted mode wins over this fallback.
137
+ */
138
+ defaultMode?: ThemeMode;
139
+ /**
140
+ * Opt-in persistence across app launches — `false` by default (this
141
+ * package never persists on its own; see `darkModeStore.ts`'s doc
142
+ * comment). Pass a storage adapter to enable it:
143
+ * ```tsx
144
+ * import AsyncStorage from '@react-native-async-storage/async-storage';
145
+ * <ThemeProvider persist={AsyncStorage}>...
146
+ * ```
147
+ * The persisted value (if any) is read once on mount and applied via the
148
+ * same "don't clobber a real choice already in flight" guard
149
+ * `seedDefaultMode`/`defaultMode` uses; every later explicit mode change
150
+ * is written back automatically for as long as this provider stays
151
+ * mounted.
152
+ */
153
+ persist?: ThemeStorageAdapter | false;
154
+ }
155
+ /**
156
+ * Optional — `useTheme()` reads `darkModeStore.ts`'s global store directly
157
+ * and works anywhere without this mounted at all. The only thing this
158
+ * component does is seed that store's initial `defaultMode` once, for apps
159
+ * that want to declare a startup default in JSX rather than calling
160
+ * `setGlobalThemeMode()` imperatively before their first render. It
161
+ * renders `children` as-is — no Context.Provider, since there's no value
162
+ * left to distribute; `useTheme()` never reads from Context.
163
+ *
164
+ * Because the store is global, MULTIPLE mounted providers would each try
165
+ * to seed the exact same store rather than getting their own scoped
166
+ * state — mounting more than one is very likely a mistake, so this warns
167
+ * once in dev.
168
+ */
169
+ declare function ThemeProvider({ children, defaultMode, persist }: ThemeProviderProps): React.JSX.Element;
170
+
171
+ interface ColorScale {
172
+ /** `colors.blue[6]` -> raw value */
173
+ readonly [shade: number]: string;
174
+ /** `colors.blue['6/50']` -> shade 6 at 50% opacity */
175
+ readonly [key: string]: string;
176
+ }
177
+ type ColorsAPI = {
178
+ /** `colors.white`, `colors.blue` (a shade family), ... */
179
+ readonly [name: string]: string | ColorScale;
180
+ } & {
181
+ /** Applies an opacity (0–100) to any color string this hook can return. */
182
+ readonly alpha: (color: string, opacity?: number) => string;
183
+ /**
184
+ * Same lookup dot/bracket access does (`colors.get('brand')` ===
185
+ * `colors.brand`), typed as plain `string` instead of `string |
186
+ * ColorScale` — use this whenever the result goes somewhere that expects
187
+ * a real `string` (a native style prop, a chart library) and hits a type
188
+ * error otherwise. The wider union on every OTHER property here isn't a
189
+ * bug: a flat custom color (`brand`) and a shade-family prefix (`blue`)
190
+ * are served by the exact same object, and TypeScript has no way to
191
+ * statically know which one any given key names — `kbach.config.js`'s
192
+ * colors are plain runtime JS, not a type declaration this package could
193
+ * inspect ahead of time. A name with no matching theme entry falls back
194
+ * to the name itself, unresolved — the same "not a known color name ->
195
+ * literal value" convention `kbach.config.js`'s own color aliasing
196
+ * already uses (see `config.ts`'s `resolveColorEntry`), never an error.
197
+ */
198
+ readonly get: (name: string) => string;
199
+ };
200
+ /**
201
+ * Resolved theme colors as real values — for anywhere you need an actual
202
+ * color (a chart library prop, a raw SVG `fill`), not a `className`. Ported
203
+ * from old-kbach's `useColors()`, adapted to this engine's flat
204
+ * `"blue-6"`-keyed palette (`colors.blue[6]` looks up `"blue-6"`).
205
+ *
206
+ * Any color — a shade-family entry like `"blue-6"` or a standalone name —
207
+ * can be defined in the theme as either a plain string (static, same in
208
+ * both modes) or a `{ light, dark }` pair — fully manual, no automatic
209
+ * shade-shifting or other assumption about what a "dark variant" should
210
+ * be; see `resolveEntry`'s own doc comment for how a `{ light, dark }`
211
+ * entry resolves on this platform specifically.
212
+ *
213
+ * ```ts
214
+ * const colors = useColors();
215
+ * colors.blue[6]; // "#2563eb" — static, same value in both modes
216
+ * colors.blue['6/50']; // same, at 50% opacity
217
+ * colors.brand; // resolves per isDark if defined as { light, dark }
218
+ * colors.get('brand'); // same value as colors.brand, typed as plain `string`
219
+ * ```
220
+ */
221
+ declare function useColors(): ColorsAPI;
222
+
223
+ /**
224
+ * Reads a dynamic token's CURRENT value reactively — the JS-value
225
+ * counterpart to using `var(--name)` directly in a `className` (see
226
+ * `jsxRuntimeCore.ts`'s own `substituteDynamicTokens`/`ReactiveElement` for
227
+ * how that path stays live). Useful when a component needs the raw value
228
+ * itself (e.g. to drive an Animated value, or a calculation), not just a
229
+ * resolved style. Subscribes to the store's shared version counter (same
230
+ * one every token change bumps — see `dynamicTokens.ts`'s own doc comment
231
+ * on why there's no per-token subscription), so this re-renders on ANY
232
+ * token change, then re-reads just the one name it was asked for.
233
+ */
234
+ declare function useDynamicToken(name: string): string | undefined;
235
+
236
+ /**
237
+ * A tiny class-name composer — combine strings, arrays, and objects (with
238
+ * boolean values) into one space-separated className, skipping anything
239
+ * falsy. Matches the widely-used `clsx` npm package's public API and
240
+ * behavior exactly (a from-scratch reimplementation, not a fork or a thin
241
+ * wrapper around it) — this package ships its own copy so using it adds
242
+ * zero runtime dependencies, and so it works identically whether or not
243
+ * `clsx`/`classnames` happens to already be installed.
244
+ *
245
+ * Kbach class strings never NEED this — a Kbach `className` is just a
246
+ * plain string, composable with plain JS (`"bg-" + color + "-6"`,
247
+ * `[base, active && "opacity-100"].join(" ")`, see this package's own
248
+ * README) with no special API required. This exists purely as an
249
+ * ergonomic convenience for the common "several conditional classes on one
250
+ * element" shape, for anyone who'd rather write it declaratively:
251
+ *
252
+ * ```ts
253
+ * clsx("px-4 py-2", isActive && "bg-blue-6", { "opacity-50": disabled });
254
+ * // "px-4 py-2 bg-blue-6" (when isActive is true and disabled is false)
255
+ * ```
256
+ *
257
+ * Identical to `@kbach/react`'s own `clsx.ts` — deliberately duplicated
258
+ * rather than factored into a shared package, since this is genuinely all
259
+ * there is to it and a whole extra published package for one ~20-line
260
+ * function would be more ceremony than the thing itself.
261
+ */
262
+ /** Anything `clsx` accepts as one argument — recursively, for arrays. */
263
+ type ClassValue = ClassArray | ClassDictionary | string | number | bigint | boolean | null | undefined;
264
+ /** A key is kept (as a literal class name) only when its value is truthy — `{ "opacity-50": disabled }`. */
265
+ interface ClassDictionary {
266
+ [className: string]: unknown;
267
+ }
268
+ type ClassArray = ClassValue[];
269
+ /**
270
+ * Joins every truthy piece across all arguments with a single space,
271
+ * skipping falsy values (`false`, `null`, `undefined`, `0`, `""`, `NaN`)
272
+ * entirely — they contribute nothing, not even an extra space. Arrays are
273
+ * flattened (recursively, to any depth); a plain object keeps only the
274
+ * keys whose value is truthy.
275
+ */
276
+ declare function clsx(...inputs: ClassValue[]): string;
277
+
278
+ /**
279
+ * On Expo Web, `react-native-web` renders a bare `<View>`/`<Text>` as a
280
+ * plain `<div>`/`<span>` by default — confirmed directly in its own
281
+ * source (`exports/View/index.js`, `exports/Text/index.js`). That's
282
+ * NOTHING to do with Kbach: this package's jsx-runtime never reads or
283
+ * substitutes the JSX element type at all (`processElement` in
284
+ * `jsxRuntimeCore(.web).ts` only ever destructures `className`/`style`,
285
+ * passing `type` straight through unchanged) — whatever tag shows up is
286
+ * exactly whatever component the app wrote.
287
+ *
288
+ * `react-native-web` already has a real fix for this that nothing here
289
+ * needs to add: an `accessibilityRole`/`role` prop on ANY host component
290
+ * makes it render the matching real HTML element instead
291
+ * (`propsToAccessibilityComponent`, react-native-web's own
292
+ * AccessibilityUtil) — `button` -> `<button>`, `header` (+ `aria-level`,
293
+ * web-only) -> `<h1>`-`<h6>`, `paragraph` -> `<p>`, and so on. These
294
+ * components are JUST that prop, pre-set on the right underlying
295
+ * component — nothing Kbach-specific, and writing
296
+ * `<Pressable accessibilityRole="button">` directly instead of `<Button>`
297
+ * behaves identically. `className` keeps working on every one of these
298
+ * exactly like it does on a bare `Pressable`/`Text`.
299
+ *
300
+ * Deliberately NOT a `Div` or an `Input`: a plain `<View>` already IS the
301
+ * right generic container (there's no more-semantic alternative to ask
302
+ * for), and `<TextInput>` already renders a real `<input>` (or
303
+ * `<textarea>` when `multiline`) by default — react-native-web's own
304
+ * TextInput component picks that unconditionally, with no role needed at
305
+ * all. Only the cases that actually need a role to stop defaulting to
306
+ * `<div>`/`<span>` are here.
307
+ */
308
+ type ButtonProps = PressableProps;
309
+ /**
310
+ * A real `<button>` on Expo Web, a real accessible button on native —
311
+ * `<Pressable accessibilityRole="button">`, nothing else changed. Not the
312
+ * same thing as React Native's OWN built-in `Button` (a fixed-chrome,
313
+ * barely-styleable native control) — this is a styleable `Pressable`,
314
+ * matching how every other interactive element in a Kbach app is built.
315
+ */
316
+ declare const Button: React.ForwardRefExoticComponent<PressableProps & React.RefAttributes<any>>;
317
+ type ParagraphProps = TextProps;
318
+ /** A real `<p>` on Expo Web — `<Text role="paragraph">`, nothing else changed. */
319
+ declare const Paragraph: React.ForwardRefExoticComponent<TextProps & React.RefAttributes<any>>;
320
+ type HeadingProps = TextProps;
321
+ /** A real `<h1>` on Expo Web — `<Text accessibilityRole="header">` + the web-only level hint, nothing else changed. */
322
+ declare const H1: React.ForwardRefExoticComponent<TextProps & React.RefAttributes<any>>;
323
+ /** A real `<h2>` on Expo Web — see `H1`'s own doc comment. */
324
+ declare const H2: React.ForwardRefExoticComponent<TextProps & React.RefAttributes<any>>;
325
+ /** A real `<h3>` on Expo Web — see `H1`'s own doc comment. */
326
+ declare const H3: React.ForwardRefExoticComponent<TextProps & React.RefAttributes<any>>;
327
+ /** A real `<h4>` on Expo Web — see `H1`'s own doc comment. */
328
+ declare const H4: React.ForwardRefExoticComponent<TextProps & React.RefAttributes<any>>;
329
+ /** A real `<h5>` on Expo Web — see `H1`'s own doc comment. */
330
+ declare const H5: React.ForwardRefExoticComponent<TextProps & React.RefAttributes<any>>;
331
+ /** A real `<h6>` on Expo Web — see `H1`'s own doc comment. */
332
+ declare const H6: React.ForwardRefExoticComponent<TextProps & React.RefAttributes<any>>;
333
+
334
+ export { Button as B, type ClassArray as C, H1 as H, type KbachConfig as K, Paragraph as P, ThemeProvider as T, type ButtonProps as a, type ClassDictionary as b, type ClassValue as c, type ColorScale as d, type ColorsAPI as e, H2 as f, H3 as g, H4 as h, H5 as i, H6 as j, type HeadingProps as k, type ParagraphProps as l, type ThemeProviderProps as m, type ThemeState as n, type ThemeStorageAdapter as o, applyKbachConfig as p, clsx as q, resolveKbachConfig as r, useDynamicToken as s, useTheme as t, useColors as u };
@@ -0,0 +1,79 @@
1
+ /**
2
+ * A plain hex value (static — same in both modes), or a `{ light, dark }`
3
+ * pair a caller sets manually in their own theme. Fully opt-in per color:
4
+ * nothing here picks a "dark variant" automatically. Only `useColors()`
5
+ * (a JS-value read, not a `className`) understands this shape — utility
6
+ * CLASS resolution (`bg-blue-6`) on native/Expo Go stays plain-string-only,
7
+ * same as it always was (dark mode for a CLASS is the separate `dark:`
8
+ * modifier, gated live at resolve time — see `resolve_style.rs`); a
9
+ * mode-aware entry referenced directly by a class name just doesn't
10
+ * resolve there, mirroring `resolvers/color.rs`'s own `lookup_hex`
11
+ * (`ColorValue::Plain` only, `ModeAware` -> `None`) exactly, same as it
12
+ * would on the web engine too.
13
+ */
14
+ type ColorEntry = string | {
15
+ light: string;
16
+ dark: string;
17
+ };
18
+ /**
19
+ * Real Tailwind's `theme.container` config, mirroring
20
+ * `packages/core-engine/src/theme.rs`'s `ContainerConfig` exactly. `center`/
21
+ * `padding` DO reach native now (unlike the max-width breakpoint ladder,
22
+ * which is a `css.rs`-only concept with nothing to generate on native at
23
+ * all) — `resolvers::layout::resolve`'s `"container"` arm is shared by both
24
+ * dispatchers, and `margin`/`padding` are ordinary RN style properties.
25
+ */
26
+ interface ContainerConfig {
27
+ center?: boolean;
28
+ padding?: string;
29
+ }
30
+ interface ThemeConfig {
31
+ colors: Record<string, ColorEntry>;
32
+ spacing: Record<string, number>;
33
+ screens: Record<string, number>;
34
+ /**
35
+ * e.g. "sans" -> "Inter, sans-serif". Optional, matching the Rust
36
+ * engine's own `#[serde(default)]`. Write it as a real web-shaped
37
+ * fallback stack even on this native-first package — native's own
38
+ * resolver strips it down to a single bare name at resolve time (RN's
39
+ * `fontFamily` prop can't take a fallback list — see
40
+ * `resolvers/mod.rs`'s `first_font_name`), so the SAME config still
41
+ * works unmodified on Expo Web, which needs the full stack.
42
+ */
43
+ fontFamily?: Record<string, string>;
44
+ darkMode: 'attribute' | 'class' | 'media';
45
+ /** Optional, matching `ContainerConfig`'s own `#[serde(default)]` on the Rust side. */
46
+ container?: ContainerConfig;
47
+ }
48
+ declare const defaultTheme: ThemeConfig;
49
+ /**
50
+ * Idempotent by CONTENT, not just a plain assignment — deliberately, not a
51
+ * micro-optimization. The babel plugin (`babel-plugin.js`) injects
52
+ * `applyKbachConfig(require('kbach.config.js'))` at the top of EVERY user
53
+ * file, not just one entry point, so it re-runs on every single file
54
+ * Metro (re-)executes. Editing `kbach.config.js` itself under Expo Fast
55
+ * Refresh forces Metro to invalidate and re-execute every file that
56
+ * requires it — which, because of that injection, is the entire app, not
57
+ * just the file you're looking at. A plain unconditional reassignment here
58
+ * would hand every one of those re-executions a BRAND NEW theme object
59
+ * (`resolveKbachConfig` always builds one fresh) even when the config's
60
+ * actual content hasn't changed, which in turn invalidates every
61
+ * `useColors()` call's `useMemo` (keyed on this object's identity) and
62
+ * re-evaluates `usesModeAwareColor()` for every reactive element
63
+ * (jsxRuntimeCore.ts) across the whole tree, all at once, right as Fast
64
+ * Refresh is already mid-teardown/rebuild for that same app-wide
65
+ * invalidation — reported live as "Unable to find node on an unmounted
66
+ * component," a known-flaky class of React Native Fast Refresh race that
67
+ * this amount of simultaneous churn measurably worsens. Comparing against
68
+ * the JSON serialization this function already computes (previously only
69
+ * for the JNI boundary, see `getThemeJson`) costs nothing new — it's the
70
+ * same computation the old code did unconditionally — it just skips the
71
+ * assignment (and therefore the reference change every downstream
72
+ * consumer sees) when the content is unchanged.
73
+ */
74
+ declare function setTheme(theme: ThemeConfig): void;
75
+ declare function getTheme(): ThemeConfig;
76
+ /** Memoized JSON serialization of the active theme — passed across the JNI boundary. */
77
+ declare function getThemeJson(): string;
78
+
79
+ export { type ColorEntry, type ContainerConfig, type ThemeConfig, defaultTheme, getTheme, getThemeJson, setTheme };
@@ -1,3 +1,32 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/theme.ts
21
+ var theme_exports = {};
22
+ __export(theme_exports, {
23
+ defaultTheme: () => defaultTheme,
24
+ getTheme: () => getTheme,
25
+ getThemeJson: () => getThemeJson,
26
+ setTheme: () => setTheme
27
+ });
28
+ module.exports = __toCommonJS(theme_exports);
29
+
1
30
  // src/generatedPalette.ts
2
31
  var PALETTE = {
3
32
  "amber-1": "#fffbeb",
@@ -114,6 +143,30 @@ var PALETTE = {
114
143
  "lime-7": "#65a30d",
115
144
  "lime-8": "#4d7c0f",
116
145
  "lime-9": "#3f6212",
146
+ "mauve-1": "#fafafa",
147
+ "mauve-10": "#1d161e",
148
+ "mauve-11": "#0c090c",
149
+ "mauve-12": "#070507",
150
+ "mauve-2": "#f3f1f3",
151
+ "mauve-3": "#e7e4e7",
152
+ "mauve-4": "#d7d0d7",
153
+ "mauve-5": "#a89ea9",
154
+ "mauve-6": "#79697b",
155
+ "mauve-7": "#594c5b",
156
+ "mauve-8": "#463947",
157
+ "mauve-9": "#2a212c",
158
+ "mist-1": "#f9fbfb",
159
+ "mist-10": "#161b1d",
160
+ "mist-11": "#090b0c",
161
+ "mist-12": "#050607",
162
+ "mist-2": "#f1f3f3",
163
+ "mist-3": "#e3e7e8",
164
+ "mist-4": "#d0d6d8",
165
+ "mist-5": "#9ca8ab",
166
+ "mist-6": "#67787c",
167
+ "mist-7": "#4b585b",
168
+ "mist-8": "#394447",
169
+ "mist-9": "#22292b",
117
170
  "neutral-1": "#fafafa",
118
171
  "neutral-10": "#171717",
119
172
  "neutral-11": "#0a0a0a",
@@ -126,6 +179,18 @@ var PALETTE = {
126
179
  "neutral-7": "#525252",
127
180
  "neutral-8": "#404040",
128
181
  "neutral-9": "#262626",
182
+ "olive-1": "#fbfbf9",
183
+ "olive-10": "#1d1d16",
184
+ "olive-11": "#0c0c09",
185
+ "olive-12": "#070705",
186
+ "olive-2": "#f4f4f0",
187
+ "olive-3": "#e8e8e3",
188
+ "olive-4": "#d8d8d0",
189
+ "olive-5": "#abab9c",
190
+ "olive-6": "#7c7c67",
191
+ "olive-7": "#5b5b4b",
192
+ "olive-8": "#474739",
193
+ "olive-9": "#2b2b22",
129
194
  "orange-1": "#fff7ed",
130
195
  "orange-10": "#7c2d12",
131
196
  "orange-11": "#431407",
@@ -223,6 +288,18 @@ var PALETTE = {
223
288
  "stone-7": "#57534e",
224
289
  "stone-8": "#44403c",
225
290
  "stone-9": "#292524",
291
+ "taupe-1": "#fbfaf9",
292
+ "taupe-10": "#1d1816",
293
+ "taupe-11": "#0c0a09",
294
+ "taupe-12": "#070605",
295
+ "taupe-2": "#f3f1f1",
296
+ "taupe-3": "#e8e4e3",
297
+ "taupe-4": "#d8d2d0",
298
+ "taupe-5": "#aba09c",
299
+ "taupe-6": "#7c6d67",
300
+ "taupe-7": "#5b4f4b",
301
+ "taupe-8": "#473c39",
302
+ "taupe-9": "#2b2422",
226
303
  "teal-1": "#f0fdfa",
227
304
  "teal-10": "#134e4a",
228
305
  "teal-11": "#042f2e",
@@ -346,22 +423,33 @@ var defaultTheme = {
346
423
  // Empty by default, matching real Tailwind's own defaults.
347
424
  container: {}
348
425
  };
349
- var activeTheme = defaultTheme;
350
- var activeThemeJson = JSON.stringify(defaultTheme);
426
+ var GLOBAL_STATE_KEY = "__kbachReactNativeThemeState__";
427
+ function getThemeState() {
428
+ const g = globalThis;
429
+ let state = g[GLOBAL_STATE_KEY];
430
+ if (!state) {
431
+ state = { theme: defaultTheme, json: JSON.stringify(defaultTheme) };
432
+ g[GLOBAL_STATE_KEY] = state;
433
+ }
434
+ return state;
435
+ }
351
436
  function setTheme(theme) {
352
- activeTheme = theme;
353
- activeThemeJson = JSON.stringify(theme);
437
+ const json = JSON.stringify(theme);
438
+ const state = getThemeState();
439
+ if (json === state.json) return;
440
+ state.theme = theme;
441
+ state.json = json;
354
442
  }
355
443
  function getTheme() {
356
- return activeTheme;
444
+ return getThemeState().theme;
357
445
  }
358
446
  function getThemeJson() {
359
- return activeThemeJson;
447
+ return getThemeState().json;
360
448
  }
361
-
362
- export {
449
+ // Annotate the CommonJS export names for ESM import in node:
450
+ 0 && (module.exports = {
363
451
  defaultTheme,
364
- setTheme,
365
452
  getTheme,
366
- getThemeJson
367
- };
453
+ getThemeJson,
454
+ setTheme
455
+ });
package/llms.txt ADDED
@@ -0,0 +1,38 @@
1
+ # @kbach/react-native
2
+
3
+ > React Native and Expo: class names turned into React Native styles when each element renders. Part of Kbach.
4
+
5
+ ## Rules for AI assistants
6
+
7
+ Kbach rules. Follow them in every class you write.
8
+
9
+ 1. Color shades go from 1 (lightest) to 12 (darkest). Never use 50 to 950.
10
+ Convert: 50→1 100→2 200→3 300→4 400→5 500→6 600→7 700→8 800→9 900→10 950→11.
11
+ Write bg-blue-6, text-gray-11, border-slate-3. Never bg-blue-500.
12
+ 2. Color families: amber blue cyan emerald fuchsia gray green indigo lime
13
+ mauve mist neutral olive orange pink purple red rose sky slate stone taupe
14
+ teal violet yellow zinc. Single colors: white black transparent current
15
+ gold silver bronze copper coal.
16
+ 3. Every other class follows Tailwind CSS v4.3 names and values: spacing in
17
+ steps of 4px (p-4 is 16px), variants such as hover:, md: and dark:,
18
+ values in square brackets, a slash for opacity (bg-black/50).
19
+ Gradients: bg-linear-to-r from-* via-* to-*.
20
+ 4. There is no tailwind.config.js, no @tailwind, no @import "tailwindcss",
21
+ no @theme and no @apply. Settings go in kbach.config.js
22
+ (export default { darkMode, theme, extend }). Custom animations go in
23
+ extend.keyframes and extend.animation and are used as animate-<name>.
24
+ 5. Plain HTML page: put <script>window.kbachConfig = { ... }</script> BEFORE
25
+ <script src="https://cdn.jsdelivr.net/npm/@kbach/browser"></script>.
26
+ A theme button calls Kbach.toggle() and needs darkMode: 'class' or
27
+ 'attribute' in that config.
28
+ 6. React with Vite: import { kbach } from '@kbach/react/vite' and add kbach()
29
+ to plugins; import './kbach.css' once in the entry file. Write every class
30
+ in full: never build one from pieces like 'bg-' + color.
31
+ 7. React Native: '@kbach/react-native/babel-plugin' must be in
32
+ babel.config.js. On a phone there is no grid, no gradients, no filters, no
33
+ transitions or animations, no group-*, peer-*, before: or after:. Use
34
+ flex-row for rows (a View is a column). Values in brackets: px or rem only.
35
+ 8. Dark mode switches use useTheme() from '@kbach/react' or
36
+ '@kbach/react-native': { mode, isDark, setMode, toggle }.
37
+
38
+ Full documentation: https://kbach.vercel.app