@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
package/AGENTS.md ADDED
@@ -0,0 +1,504 @@
1
+ # `@kbach/react-native` — reference for AI assistants
2
+
3
+ The React Native binding of [Kbach](https://github.com/semsakadanupol/kbach)
4
+ — the same Tailwind-v4-shaped class-name vocabulary as `@kbach/react`,
5
+ resolved to a **`StyleSheet`-ready style object at render time** via a
6
+ shared Rust core (JNI on Android, WASM on Expo Web, a pure-JS fallback on
7
+ Expo Go and iOS). This file covers `@kbach/react-native` only; for the
8
+ cross-package overview, `kbach.config.js` reference, the color palette,
9
+ and how the underlying engine is built, see the repo root's
10
+ [AGENTS.md](https://github.com/semsakadanupol/kbach/blob/main/AGENTS.md).
11
+
12
+ > **Before writing a single class here, know these three things —
13
+ > Tailwind familiarity actively misleads on all three:**
14
+ >
15
+ > 1. Color shades are `1`–`12` (lightest→darkest), not Tailwind's
16
+ > `50`–`950` — `bg-blue-500` resolves to nothing; the real class is
17
+ > `bg-blue-6`. Full palette: root AGENTS.md §7.
18
+ > 2. `group-*`, `peer-*`, `has-[…]`, container queries, grid, and pseudo-
19
+ > elements (`before:`/`after:`) are real Tailwind syntax that PARSES
20
+ > here but applies **zero style, with no warning** — native has no
21
+ > cascade/DOM to support them. See §4's "Not supported" list. A typo
22
+ > DOES warn; an unsupported-but-valid utility does not — don't assume
23
+ > silence means it worked.
24
+ > 3. The babel plugin (§1 below) is required on **every** target,
25
+ > including Expo Go — without it `className` does literally nothing,
26
+ > silently, no error. This is the single most common real setup bug
27
+ > reported against this package.
28
+
29
+ ---
30
+
31
+ ## 1. Install + setup
32
+
33
+ ```sh
34
+ npx @kbach/cli init
35
+ ```
36
+
37
+ Automates everything below — installs `@kbach/react-native`, patches (or
38
+ creates) `babel.config.js` via a format-preserving codemod (handles both
39
+ Expo's function-export form and React Native CLI's plain object-export
40
+ form), and on React Native CLI offers to run the native rebuild right
41
+ there. Safe to re-run at any time (idempotent — reports "already has the
42
+ kbach babel plugin" rather than duplicating the entry). See
43
+ [`packages/cli/AGENTS.md`](../cli/AGENTS.md) for exactly what it detects
44
+ and changes, and what it does when the codemod can't safely apply
45
+ (prints the same manual snippet shown below, rather than guessing).
46
+
47
+ The manual steps below are both the CLI's own fallback and the accurate
48
+ reference for what it actually does — start here if you're wiring this
49
+ up by hand, or the CLI reported it couldn't:
50
+
51
+ ```sh
52
+ npm install @kbach/react-native@beta
53
+ ```
54
+
55
+ The babel plugin is **required on every target, including Expo Go** — it
56
+ injects the per-file `@jsxImportSource @kbach/react-native` pragma
57
+ (babel-plugin.js) that routes `className` through this package's
58
+ jsx-runtime instead of `react/jsx-runtime`; nothing else makes
59
+ interception happen. Confirmed as a real, reported doc bug: the table
60
+ below used to say "None" for Expo Go/Expo Web, and a from-scratch repro
61
+ (fresh Expo project, README's own example, zero babel config, Expo Go on
62
+ a real emulator) showed `className` doing nothing at all — no styling, no
63
+ warning, no error — exactly as this mechanism predicts. What differs per
64
+ target is what happens *after* the plugin is in place:
65
+
66
+ | Target | Setup |
67
+ | :-- | :-- |
68
+ | **Expo Go** | Babel plugin. A pure-JS fallback engine loads automatically after that (reduced utility coverage) — no other setup. |
69
+ | **Expo Web** / `react-native-web` | Babel plugin. Uses the same WASM CSS engine as `@kbach/react` after that — no other setup. |
70
+ | **Expo dev client / prebuild / EAS** | Babel plugin, then `npx expo prebuild && npx expo run:android`. Full native engine. |
71
+ | **React Native CLI** | Babel plugin, then restart Metro with `--reset-cache` and rebuild the Android app. |
72
+
73
+ Babel plugin — added to the existing `babel.config.js` (keep the function
74
+ form Expo generates; only add the `plugins` entry):
75
+
76
+ ```js
77
+ module.exports = function (api) {
78
+ api.cache(true);
79
+ return {
80
+ presets: ['babel-preset-expo'],
81
+ plugins: ['@kbach/react-native/babel-plugin'],
82
+ };
83
+ };
84
+ ```
85
+
86
+ React Native CLI uses `presets: ['module:@react-native/babel-preset']` and
87
+ a plain object export.
88
+
89
+ **Native is Android-only** (no iOS bridge yet) — on iOS, every build
90
+ (dev client, CLI, EAS) runs the same reduced-coverage JS-fallback engine
91
+ as Expo Go, not the full native engine (see §3's engine table).
92
+
93
+ ## 2. What the babel plugin does
94
+
95
+ Per user source file (never `node_modules`, never Metro/Expo virtual
96
+ modules, never `kbach.config.js` itself):
97
+
98
+ 1. Prepends a `// @jsxImportSource @kbach/react-native` comment so the JSX
99
+ transform routes `className` through this package's jsx-runtime.
100
+ 2. Prepends `require('@kbach/react-native').applyKbachConfig(require('<abs
101
+ path>/kbach.config.js'))` if that file exists at the project root — so
102
+ the config is applied before the app's first render with **no import or
103
+ call in app code**.
104
+
105
+ A dev-server restart is required after changing `kbach.config.js` or the
106
+ babel config — for the babel config specifically, a plain restart isn't
107
+ reliably enough (Metro's transform cache doesn't always invalidate on a
108
+ babel config change on its own); use `--reset-cache` (`npx react-native
109
+ start --reset-cache` / `npx expo start --clear`).
110
+
111
+ ## 3. How resolution works
112
+
113
+ `className` on a host element (`View`, `Text`, `Pressable`, …) is
114
+ intercepted by the jsx-runtime and resolved to a style object. One of three
115
+ engines does the work, chosen automatically:
116
+
117
+ | Runtime | Engine | Mechanism |
118
+ | :-- | :-- | :-- |
119
+ | Android dev-client / CLI build | **Rust via JNI** (`KbachModule` TurboModule, prebuilt `.so`) | `resolveStyle(classString, themeJson, colorScheme, pressed, width)` → JSON style object. |
120
+ | Expo Web / `react-native-web` | **Rust via WASM** (`generate_css_attr`) | Emits real CSS rules into a `<style>` tag; element gets `dataSet={{ kb }}` and rules target `[data-kb~="…"]`. Full modifier set. |
121
+ | Expo Go | **Pure-JS fallback** (`jsEngine/`) | A partial TS port of the native resolver. No custom native module can load in Expo Go. |
122
+ | iOS — ANY build (dev-client, CLI, EAS) | **Pure-JS fallback** (`jsEngine/`) | Same reduced-coverage path as Expo Go, since there's no iOS native module at all yet (`TurboModuleRegistry.get('KbachModule')` returns `null` on iOS, so `resolveStyle` falls through to the JS engine — see nativeBridge.ts). Not specific to Expo Go; a real iOS dev-client/CLI build is on this row too. |
123
+
124
+ Resolution is memoized per `(classString, pressed, colorScheme, width,
125
+ theme)`.
126
+
127
+ **Variant groups (1.1.1-beta.0):** `className="flex active:(bg-blue-6 opacity-50)"`
128
+ resolves as `active:bg-blue-6 active:opacity-50`, with no build step: every
129
+ engine expands groups before resolving (Rust's `groups.rs` on Android and Expo
130
+ Web; `src/jsEngine/groups.ts` on Expo Go / iOS, a port held to the same cases
131
+ as the Rust one by `groups.test.ts`, which reads
132
+ `core-engine/tests/variant-groups.json`; `jsEngine/parity.test.ts` compares the
133
+ two engines on grouped strings, light and dark, pressed or not). Root
134
+ AGENTS.md §8.2 has the syntax.
135
+
136
+ ## 4. Modifiers on native
137
+
138
+ Native has no selector/cascade engine. Two groups:
139
+
140
+ **Resolved in the engine from live parameters:**
141
+ - `dark:` — current OS/app color scheme; `not-dark:` is the other one.
142
+ - `sm:` `md:` `lg:` `xl:` `2xl:` — window width vs `theme.screens`, plus
143
+ any breakpoint a config adds (`3xl:`, `tablet:`), and `max-<name>:`
144
+ (strictly below that width). `not-<name>:` / `not-max-<name>:` flip
145
+ either one.
146
+ - `min-[500px]:` / `max-[30rem]:` — arbitrary width breakpoints (constant
147
+ px/rem only). `max-[…]` is strictly below its width, like `max-<name>:`;
148
+ through core-engine 1.0.0-beta.18 it also held at exactly that width.
149
+ - `active:` — `Pressable` press state (via its style-callback).
150
+
151
+ **Resolved in `jsxRuntimeCore.ts` from React props, before the engine sees
152
+ the string:**
153
+ - `hover:` — `onHoverIn`/`onHoverOut` — only fires for pointer-capable
154
+ input (mouse/trackpad); inert on pure touch.
155
+ - `focus:` — `onFocus`/`onBlur`.
156
+ - `disabled:` — the element's own `disabled` prop.
157
+ - `data-[key=value]:` / `data-[key]:` / `aria-[…]:` / static `aria-*`
158
+ shortcuts — the element's own `data-*` / `aria-*` props.
159
+
160
+ A satisfied prop-based modifier is rewritten to an internal `_kbon` marker
161
+ (one per satisfied modifier) so it still contributes to specificity.
162
+
163
+ **Prop-based modifiers never inherit from an ancestor.** `disabled:` /
164
+ `aria-[…]:` / `data-[…]:` read `hostRest` off THAT exact element's own
165
+ props (`propBasedModifierState` in jsxRuntimeCore.ts) — there is no
166
+ `group-disabled:`-style cascade on native to inherit one through. Confirmed
167
+ as a real footgun (reported after two independent hits building a demo
168
+ app): `<Pressable disabled><Text className="disabled:text-gray-5">` does
169
+ nothing at all, silently — `Text` never received a `disabled` prop, so
170
+ `propBasedModifierState` returns `null` for it (no opinion), the modifier
171
+ is treated as never-satisfied, and nothing warns. The prop has to be
172
+ repeated on whichever element actually carries the modifier:
173
+ `<Pressable disabled><Text disabled className="disabled:text-gray-5">`.
174
+
175
+ **Not supported** (parse without error, never apply): `group-*`, `peer-*`,
176
+ `has-[…]`, container queries, `*:` / `**:`, `before:` / `after:` and other
177
+ pseudo-elements.
178
+
179
+ **Specificity / class order.** When two classes set the same property, the
180
+ one with more satisfied modifiers wins **regardless of source order** —
181
+ `dark:bg-black bg-white` and `bg-white dark:bg-black` both resolve to black
182
+ in dark mode, matching web. Equal specificity falls back to last-token-wins.
183
+ `transform-none` is an exception: it clears all transforms above it in
184
+ source order regardless of specificity.
185
+
186
+ Chaining composes and is order-independent (`dark:sm:` ≡ `sm:dark:`); every
187
+ named condition must hold.
188
+
189
+ ## 5. Expo Go coverage gap
190
+
191
+ The JS fallback covers: layout, spacing, border/radius, plain colors,
192
+ font-weight, text-transform/decoration, line-height, letter-spacing,
193
+ shadows, and the RN-representable transforms (`translate-x/y`,
194
+ `scale`/`scale-x/y`, `rotate`/`rotate-x/y/z`, `skew-x/y`, `transform-none`,
195
+ `backface-*`).
196
+
197
+ Not covered: grid, filters, gradients, DOM-only typography, and transforms
198
+ with no RN equivalent (`translate-z`, `scale-z`, `perspective*`, `origin`,
199
+ `transform-gpu/cpu`). Same scope native itself excludes. Typo warnings are
200
+ also unavailable in Expo Go (no full-vocabulary resolver to check against).
201
+
202
+ This is also exactly what iOS gets in every build type (§3) — the coverage
203
+ gap isn't Expo-Go-specific, it's "whatever the JS-fallback engine covers."
204
+
205
+ Measured 2026-11-17 against every class in the docs' reference tables
206
+ (1,048), the JS fallback matches the Rust engine except: the `object-*`
207
+ classes (no `objectFit`), the small container sizes `3xs`/`2xs`/`xs` on
208
+ `w-`/`min-w-`/`max-w-`/`basis-` (no value), and `container`. The other
209
+ differences are properties React Native ignores anyway (`float`, `columns`,
210
+ `break-*`, `clear`, `visibility`, `isolation`, logical `rounded-s`/`border-s`
211
+ with `"0.5rem"`/`"1px"` strings), which the Rust engine returns and the JS
212
+ one doesn't.
213
+
214
+ Within that scope it must match the Rust native engine exactly.
215
+ `src/jsEngine/parity.test.ts` runs class strings through both (Rust via
216
+ `packages/core-engine/dist-node`, so core-engine must be built first) and
217
+ fails on any difference. Extend its `CASES` whenever a native-reaching
218
+ resolver changes in either engine; the 2026-11 Tailwind v4 pass (exact-px
219
+ border widths, `px`, two-axis `translate-*`/`skew-*`, `rotate-none`/
220
+ `scale-none`, `flex-N`, formula `leading-N`, `rounded-xs`/`rounded-4xl`)
221
+ and the Tailwind v4.3 values (`rounded-sm`, the `shadow-*` scale, outlines)
222
+ are covered there. See root AGENTS.md §8.1 for what's web-only by design.
223
+
224
+ **Rings (`ring-*`, `ring-offset-*`) apply no style on native**, on purpose:
225
+ they're a `var()`-built CSS `box-shadow`. Both engines also drop every CSS
226
+ custom property and `var()`-containing value before building the RN style
227
+ (it used to leak through as keys like `KbRingWidth`). Use `border-*` or
228
+ `shadow-*` for a native focus/selection outline. Text sizes on native set
229
+ `fontSize` only (no Tailwind default line-height); add `leading-*` for an
230
+ explicit native line height.
231
+
232
+ ## 6. Dark mode
233
+
234
+ Zero setup on all targets. On native `dark:` is resolved from a live
235
+ parameter every render — no build step to keep in sync. Expo Web defaults
236
+ to the `'attribute'` strategy.
237
+
238
+ ```tsx
239
+ import { useTheme } from '@kbach/react-native';
240
+ const { mode, isDark, setMode, toggle } = useTheme();
241
+ ```
242
+
243
+ No provider required. `<ThemeProvider>` optionally seeds a startup
244
+ `defaultMode` and enables persistence:
245
+
246
+ ```tsx
247
+ import AsyncStorage from '@react-native-async-storage/async-storage';
248
+ <ThemeProvider persist={AsyncStorage}><App /></ThemeProvider>;
249
+ ```
250
+
251
+ Mount at most one — dark mode is one global store, not scoped per
252
+ provider, so a second mounted instance logs a dev-only warning (they'd
253
+ fight over the same `defaultMode`/`persist` seed).
254
+
255
+ `persist` takes any `{ getItem, setItem }` async store. The persisted mode
256
+ is read once on mount and wins over `defaultMode`; later changes are
257
+ written back. This package never imports a storage library itself.
258
+
259
+ Outside React: `getGlobalDarkMode()` / `toggleGlobalDarkMode()` /
260
+ `setGlobalThemeMode()`.
261
+
262
+ ## 7. `calc()` / `min()` / `max()` / `clamp()`
263
+
264
+ - **Constant** px/rem/bare-number expressions are reduced at resolve time:
265
+ `p-[calc(16px+8px)]` → `padding: 24`. No spaces or underscores are
266
+ required around operators; `calc(16px+8px)` is fine.
267
+ - **Viewport-relative** (`calc(10vw+8px)`): no such unit on native — the
268
+ declaration is dropped and a dev-only `console.warn` explains why.
269
+ - **Percentage-relative `width`/`height`** (`w-[calc(100%-3rem)]`,
270
+ `w-[min(50%,20rem)]`, `w-[clamp(16rem,50%,32rem)]`): supported via a
271
+ one-frame measure-then-snap — renders at `100%`, measures via
272
+ `onLayout`, then corrects to the computed number; re-measures on layout
273
+ changes. Narrow shapes only: `calc()` = one percent term + one constant
274
+ term; `min`/`max` args each a plain percent OR a constant expression (not
275
+ mixed); `clamp` exactly three args; `width`/`height` only.
276
+ - **Literal spaces are illegal inside `[...]`** on any Tailwind-family
277
+ engine (a space splits the class token). Use underscores if you want them
278
+ for readability: `w-[calc(100%_-_3rem)]`.
279
+
280
+ ### 7.1 Arbitrary values elsewhere — same px/rem-only rule
281
+
282
+ Not just `calc()`: any arbitrary value RN needs as a plain number (font
283
+ size, spacing, radii, ...) follows the identical rule. `text-[20px]` and
284
+ `text-[1.5rem]` work (`rem` × 16, same as everywhere else); `text-[2em]`,
285
+ `text-[50%]`, `text-[10vh]`/`text-[10vw]` don't — `em` needs the parent's
286
+ own cascaded font-size and `%`/viewport units need real layout, neither
287
+ of which exists at native resolve time — dropped with the same dev-only
288
+ `console.warn`, never a crash. Identical on Expo Go's JS-fallback engine
289
+ (`jsEngine/resolveStyle.ts` mirrors `resolve_style.rs`'s `rn_style_value`
290
+ exactly). Web (including Expo Web) has none of this restriction — real
291
+ CSS resolves every unit natively.
292
+
293
+ **`text-[…]` specifically needs `< 1.0.0-beta.52` excluded** — every
294
+ arbitrary `text-[…]` value, including a plain `text-[10px]`, silently
295
+ resolved nothing at all on native/Expo Go before that version (see §13).
296
+
297
+ ## 8. Dynamic tokens (native counterpart to CSS custom properties)
298
+
299
+ ```tsx
300
+ import { setDynamicToken, useDynamicToken } from '@kbach/react-native';
301
+
302
+ setDynamicToken('sidebar-width', '240px');
303
+ <View className="w-[var(--sidebar-width)]" />;
304
+ const w = useDynamicToken('sidebar-width'); // '240px' | undefined, reactive
305
+ ```
306
+
307
+ On web `setDynamicToken` writes a real CSS custom property (browser
308
+ repaints, no re-render). On native the token value is substituted into the
309
+ class string before each resolve, and subscribed elements re-render on
310
+ change. `var(--x)` in a `className` already works unaided on Expo Web.
311
+
312
+ **Call `setDynamicToken` synchronously from a render body, not from module
313
+ top-level.** It calls `notify()` synchronously (dynamicTokens.ts), which
314
+ synchronously re-renders every already-mounted `ReactiveElement` subscribed
315
+ via `useSyncExternalStore` — safe when nothing is subscribed yet, a real
316
+ hazard once something is. Module-top-level code runs whenever Metro's
317
+ inline-requires first evaluates that module, which is NOT a fixed point in
318
+ the app's lifecycle — it can land in the middle of React rendering some
319
+ unrelated component elsewhere in the tree, which is exactly the "Cannot
320
+ update a component while rendering a different component" class of bug:
321
+
322
+ ```tsx
323
+ // Bad — races Metro inline-requires; can fire mid-render of an unrelated component.
324
+ setDynamicToken('accent', '#8b5cf6');
325
+
326
+ // Good — call synchronously in your ROOT component's own render, before any
327
+ // consumer mounts; guard so it only ever fires once (unguarded, every
328
+ // re-render would call notify() again, wastefully re-rendering every
329
+ // subscribed element for no value change).
330
+ function RootLayout({ children }) {
331
+ if (getDynamicToken('accent') === undefined) {
332
+ setDynamicToken('accent', '#8b5cf6');
333
+ }
334
+ return <ThemeProvider>{children}</ThemeProvider>;
335
+ }
336
+ ```
337
+
338
+ ## 9. Reading colors as values
339
+
340
+ ```tsx
341
+ import { useColors } from '@kbach/react-native';
342
+
343
+ const colors = useColors();
344
+ colors.blue[6]; // '#2563eb'
345
+ colors.blue['6/50']; // 50% opacity
346
+ colors.alpha(colors.blue[6], 30);
347
+ colors.get('brand'); // a custom color, typed as plain `string`
348
+ ```
349
+
350
+ `colors.blue[6]` returns the same value in both light and dark mode
351
+ unless `blue-6` itself is defined in the theme as a `{ light, dark }` pair
352
+ (§6.1 of the root AGENTS.md) — define a color as mode-aware in
353
+ `kbach.config.js` if you want it to differ by mode.
354
+
355
+ `colors.brand` (a custom flat color) is typed `string | ColorScale`
356
+ because the same object also serves shade families and TS can't tell them
357
+ apart statically — use `colors.get(name)` when you need a guaranteed
358
+ `string`.
359
+
360
+ ## 10. Unknown-class warnings
361
+
362
+ On a native dev-client/CLI build, a class matching no Kbach utility on any
363
+ platform emits a one-time `console.warn` (dev only), with a "did you
364
+ mean" when there is one: a Tailwind shade mapped to Kbach's
365
+ (`bg-blue-500` → `bg-blue-6`) or a one-character typo fix (core-engine
366
+ suggest.rs). A real utility native
367
+ just doesn't support yet (`grid-cols-3`, `blur`, …) stays silent — that's a
368
+ documented platform gap, not a typo. Not available in Expo Go.
369
+
370
+ A malformed or misused value fails the same safe way — a deduped, dev-only
371
+ `console.warn` naming the offending class and the fix, never a crash or
372
+ silently-wrong output. Confirmed across CSS-injection attempts in an
373
+ arbitrary value, invalid `calc()` operands, and double-mounted providers.
374
+
375
+ ## 11. Monorepo / workspace installs
376
+
377
+ If `@kbach/react-native` is a workspace/hoisted dependency, Metro can end
378
+ up with **two physical copies of `react-native` / `react`** — different
379
+ files resolve to different module instances, and a dark-mode toggle can
380
+ silently do nothing. Force a single instance in your app's
381
+ `metro.config.js` via `resolver.resolveRequest`, pointing `react-native`
382
+ and `react` at `projectRoot/node_modules/...`. A plain non-monorepo
383
+ `npm install` never hits this.
384
+
385
+ ## 12. Exports
386
+
387
+ `setTheme`, `getTheme`, `defaultTheme`, `resolveStyle`, `resolveKbachConfig`,
388
+ `applyKbachConfig`, `useTheme`, `ThemeProvider`, `useColors`,
389
+ `setDynamicToken`, `getDynamicToken`, `deleteDynamicToken`,
390
+ `subscribeDynamicTokens`, `useDynamicToken`, `clsx`, `getGlobalDarkMode`,
391
+ `getGlobalThemeMode`, `setGlobalThemeMode`, `toggleGlobalDarkMode`,
392
+ `subscribeGlobalDarkMode`, `Button`, `Paragraph`, `H1`, `H2`, `H3`, `H4`,
393
+ `H5`, `H6` (§14). Types: `ThemeConfig`, `ColorEntry`, `ContainerConfig`,
394
+ `StyleObject`, `KbachConfig`, `ThemeState`, `ThemeProviderProps`,
395
+ `ThemeStorageAdapter`, `ThemeMode`, `ColorsAPI`, `ColorScale`,
396
+ `ClassValue`, `ClassDictionary`, `ClassArray`, `ButtonProps`, `ParagraphProps`,
397
+ `HeadingProps`. The docs site's `tests/e2e/api-reference.mjs` fails when an
398
+ export here is missing from the React Native API page.
399
+
400
+ Subpath exports: `@kbach/react-native/babel-plugin`,
401
+ `@kbach/react-native/jsx-runtime`, `@kbach/react-native/jsx-dev-runtime`.
402
+
403
+ ## 13. Common failure modes
404
+
405
+ - **`bg-<custom>` renders nothing** — the color is mode-aware
406
+ (`{light,dark}` / `dark:` block) and the app is on a stale
407
+ `@kbach/react-native` (`< 1.0.0-beta.36`). Update.
408
+ - **A `dark:` variant loses to a plain class** — stale
409
+ `@kbach/react-native` (`< 1.0.0-beta.37`); class-order independence
410
+ landed there. Update.
411
+ - **`useColors().brand` type error** — assign via `colors.get('brand')`
412
+ (`< beta.36` has no `.get`).
413
+ - **Dark toggle does nothing in a monorepo** — duplicate `react-native` /
414
+ `react` instances; add the `metro.config.js` `resolveRequest` override
415
+ (§11).
416
+ - **Rust change not reflected on a real Android build** — stale prebuilt
417
+ `.so`; the maintainer must re-run `build:android` and republish.
418
+ - **`kbach.config.js` "does nothing" / Metro bundling error** — an
419
+ unquoted hyphenated key (`surface-dim:` instead of `'surface-dim':`).
420
+ Quote it.
421
+ - **TypeScript error on `className`** (`Property 'className' does not
422
+ exist on type ... ViewProps ...`) — fixed in `>= 1.0.0-beta.46`; update.
423
+ - **`className` does absolutely nothing — no styling, no warning, no
424
+ error, on any target including Expo Go** — the babel plugin (§1) is
425
+ missing. It's required on every target, not just Android/dev-client
426
+ builds; without it nothing routes `className` through this package's
427
+ jsx-runtime at all, so RN just silently ignores the unrecognized prop.
428
+ - **`useColors().get('yourCustomColor')` returns the literal name, not
429
+ the color, on Expo Web — icons/fills using it render invisible** —
430
+ stale `@kbach/react-native` (`< 1.0.0-beta.53`). Root cause: on web,
431
+ this package loads as two separate module instances in the same
432
+ bundle — a bare `import` resolves through package.json's `import`
433
+ condition, but the babel plugin's injected
434
+ `require('@kbach/react-native').applyKbachConfig(...)` always resolves
435
+ through `require` — so `kbach.config.js`'s custom colors landed in one
436
+ instance's theme state while every component's own `useColors()` read
437
+ the other, untouched one. Fixed by routing `theme.ts`'s active-theme
438
+ state through a `globalThis`-backed slot instead of a plain
439
+ module-scope variable, so both instances share it regardless of which
440
+ one set it. Update.
441
+ - **`ERROR [Error: Unable to find node on an unmounted component.]` on
442
+ Expo Fast Refresh, especially right after editing `kbach.config.js`** —
443
+ stale `@kbach/react-native` (`< 1.0.0-beta.51`). Root cause: the babel
444
+ plugin (§1) injects `applyKbachConfig(require('kbach.config.js'))` into
445
+ *every* user file, so editing that config forces Metro to re-execute the
446
+ entire app (every file requires it), not just the screen you're on;
447
+ before beta.51, `setTheme` (`theme.ts`) handed every one of those
448
+ redundant re-applications a brand-new theme object even when the config
449
+ content hadn't changed, invalidating every `useColors()` memo and
450
+ reactive-element check across the whole tree simultaneously, right as
451
+ Fast Refresh was already mid-teardown — worsening this normally-rare
452
+ React Native Fast Refresh race. `setTheme` is idempotent by content
453
+ since beta.51 (compares against the theme's own JSON serialization
454
+ before replacing it); update.
455
+ - **`text-[10px]` (or any other arbitrary `text-[…]` value) does nothing
456
+ on native or Expo Go** — stale `@kbach/react-native` (`< 1.0.0-beta.52`).
457
+ The native dispatcher's `resolve_text_native` (`resolvers/mod.rs`) never
458
+ got the arbitrary-value length check `color::resolve_text` (web) already
459
+ had — an arbitrary value skipped the font-size/align lookup entirely and
460
+ fell straight through to color resolution, which correctly rejected
461
+ "10px" as not a real color and silently dropped the whole declaration.
462
+ Fixed identically in both the Rust native dispatcher and its Expo Go JS-
463
+ fallback mirror (`jsEngine/resolveUtilityNative.ts`) in beta.52; update.
464
+ Web (including Expo Web) was never affected.
465
+
466
+ ## 14. Semantic HTML on Expo Web
467
+
468
+ On Expo Web, `react-native-web` renders a bare `<View>`/`<Text>` as a
469
+ plain `<div>`/`<span>` by default — confirmed directly in its own source.
470
+ That's **not** a Kbach limitation: this package's jsx-runtime never reads
471
+ or substitutes the JSX element type at all, so whatever tag shows up is
472
+ exactly whatever component the app wrote.
473
+
474
+ `react-native-web` already has a real fix for this that this package
475
+ never gets in the way of: an `accessibilityRole`/`role` prop on ANY host
476
+ component makes it render the matching real HTML element instead —
477
+ `accessibilityRole="button"` → `<button>`, `accessibilityRole="header"` +
478
+ `aria-level` (web-only; real native has no heading-LEVEL concept, only
479
+ `header` itself) → `<h1>`-`<h6>`, `role="paragraph"` → `<p>`, and so on
480
+ (`react-native-web`'s own `propsToAccessibilityComponent`). `role` covers
481
+ every value in React Native's own typed `Role` union (`button`,
482
+ `heading`, `list`, `listitem`, `navigation`, `main`, `form`, `article`,
483
+ `banner`, `contentinfo`, `complementary`, `region`, ...); `"paragraph"`
484
+ is the one react-native-web additionally supports that isn't in that
485
+ union at all.
486
+
487
+ This package exports a handful of convenience components that are just
488
+ that prop, pre-set on the right underlying component — nothing beyond
489
+ that, and writing `<Pressable accessibilityRole="button">` directly
490
+ instead of `<Button>` behaves identically:
491
+
492
+ ```tsx
493
+ import { Button, Paragraph, H1, H2, H3, H4, H5, H6 } from '@kbach/react-native';
494
+
495
+ <Button className="px-4 py-2 rounded bg-blue-6" onPress={...}>Save</Button>
496
+ <H1 className="text-2xl font-bold">Page title</H1>
497
+ <Paragraph className="text-sm text-gray-7">Body copy.</Paragraph>
498
+ ```
499
+
500
+ `className` keeps working on every one of these exactly like it does on
501
+ a bare `Pressable`/`Text`. No `Div` or `Input` here on purpose: a plain
502
+ `<View>` already is the right generic container, and `<TextInput>`
503
+ already renders a real `<input>` (or `<textarea>` when `multiline`) by
504
+ default, with no role needed at all.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 semsakadanupol
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.