@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
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Native port of @kbach/react's darkModeStore.ts — same architecture (a
3
+ * single module-level store is the real source of truth;
4
+ * ThemeProvider/useTheme are a thin, OPTIONAL wrapper around it; every
5
+ * function here works standalone with no provider mounted anywhere), with
6
+ * two real platform differences from the web version:
7
+ *
8
+ * 1. No persistence. There's no React-Native-builtin equivalent of
9
+ * localStorage — adding one would mean forcing a real native dependency
10
+ * (e.g. @react-native-async-storage/async-storage) on every consumer,
11
+ * even ones that don't want it. The mode always starts at 'system' on a
12
+ * fresh app launch. If you want persistence, read your own storage at
13
+ * startup (before your first render) and call setGlobalThemeMode() with
14
+ * the result — same "seed once, no built-in write-back" shape as
15
+ * seedDefaultMode() below, just driven by your own storage instead of
16
+ * one this package picks for you.
17
+ * 2. `applyToDom` below IS needed here, unlike what an earlier version of
18
+ * this file's own comment claimed ("no DOM to apply the resolved mode
19
+ * to") — that reasoning only holds for real native (Android/iOS), where
20
+ * nativeBridge.ts's resolveStyle() reads getGlobalDarkMode() directly on
21
+ * every call, no DOM involved at all. This file is ALSO used by Expo
22
+ * Web, though (no `.web.ts` sibling — Metro has nothing to swap in), and
23
+ * Expo Web resolves `dark:` classes to REAL CSS with `[data-theme=
24
+ * "dark"]`-style selectors (see nativeBridge.web.ts) that only ever
25
+ * match if something writes that attribute to the DOM — nothing did,
26
+ * which is exactly why toggling the mode changed `useTheme()`'s own
27
+ * state (a consumer reading `mode`/`isDark` directly, e.g. for a label,
28
+ * updated correctly) while every `dark:`-prefixed style silently never
29
+ * applied. `typeof document === 'undefined'` is what makes one function
30
+ * safe on both platforms: real native's Hermes has no `document` global
31
+ * at all (not even `undefined` as a defined-but-empty value — genuinely
32
+ * unset, which `typeof` can check without throwing), so this always
33
+ * no-ops there, while Expo Web's react-native-web renders into a real
34
+ * browser DOM where it's needed.
35
+ */
36
+ type ThemeMode = 'light' | 'dark' | 'system';
37
+ /**
38
+ * Re-applies the CURRENT `isDark` value to the DOM (Expo Web only — a
39
+ * genuine no-op on real native, same as `applyToDom` itself) under whatever
40
+ * `getTheme().darkMode` strategy is active right now, with no change to
41
+ * `mode`/`isDark` themselves, so it deliberately does NOT `notify()`.
42
+ * Mirrors @kbach/react's identical `resyncDomWithActiveTheme` — see that
43
+ * one's own doc comment for the full race it fixes: this module's initial
44
+ * `applyToDom(isDark)` call (above) runs at IMPORT time against whichever
45
+ * `darkMode` strategy `defaultTheme` had at that moment, which on Expo Web
46
+ * is BEFORE an app's own `applyKbachConfig({darkMode: 'attribute'})` call
47
+ * (in config.ts) has had a chance to switch it — without this, that config
48
+ * call would silently never get its `dark:` classes to apply on initial
49
+ * load, even though `useTheme().isDark` already reads correctly.
50
+ */
51
+ declare function resyncDomWithActiveTheme(): void;
52
+ declare function getGlobalDarkMode(): boolean;
53
+ declare function getGlobalThemeMode(): ThemeMode;
54
+ /** Explicit user choice — takes priority over any later `<ThemeProvider defaultMode>` seed (see `seedDefaultMode` below). Not persisted; see this module's own doc comment. */
55
+ declare function setGlobalThemeMode(nextMode: ThemeMode): void;
56
+ declare function toggleGlobalDarkMode(): void;
57
+ declare function subscribeGlobalDarkMode(listener: () => void): () => void;
58
+ /**
59
+ * Applies `fallback` as the initial mode, but ONLY if nothing has made an
60
+ * explicit choice yet — called once by `<ThemeProvider defaultMode>` on
61
+ * mount, never exported for direct use elsewhere. Unlike the web store,
62
+ * there's no persisted-value check here (nothing to check); the only
63
+ * thing that can beat a seed is a `setGlobalThemeMode()` call that
64
+ * happened first (e.g. your own storage-restore logic run before the
65
+ * provider mounts).
66
+ */
67
+ declare function seedDefaultMode(fallback: ThemeMode): void;
68
+ /** Exported for tests only — resets every module-level field back to its as-if-just-imported state. */
69
+ declare function _resetForTests(): void;
70
+ /** Exported for tests only — removes the Appearance change subscription so a test's mock doesn't leak into the next one. */
71
+ declare function _unsubscribeForTests(): void;
72
+
73
+ export { type ThemeMode, _resetForTests, _unsubscribeForTests, getGlobalDarkMode, getGlobalThemeMode, resyncDomWithActiveTheme, seedDefaultMode, setGlobalThemeMode, subscribeGlobalDarkMode, toggleGlobalDarkMode };
@@ -0,0 +1,118 @@
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/darkModeStore.ts
21
+ var darkModeStore_exports = {};
22
+ __export(darkModeStore_exports, {
23
+ _resetForTests: () => _resetForTests,
24
+ _unsubscribeForTests: () => _unsubscribeForTests,
25
+ getGlobalDarkMode: () => getGlobalDarkMode,
26
+ getGlobalThemeMode: () => getGlobalThemeMode,
27
+ resyncDomWithActiveTheme: () => resyncDomWithActiveTheme,
28
+ seedDefaultMode: () => seedDefaultMode,
29
+ setGlobalThemeMode: () => setGlobalThemeMode,
30
+ subscribeGlobalDarkMode: () => subscribeGlobalDarkMode,
31
+ toggleGlobalDarkMode: () => toggleGlobalDarkMode
32
+ });
33
+ module.exports = __toCommonJS(darkModeStore_exports);
34
+ var import_react_native = require("react-native");
35
+ var import_theme = require("./theme");
36
+ var listeners = /* @__PURE__ */ new Set();
37
+ function systemPrefersDark() {
38
+ return import_react_native.Appearance.getColorScheme() === "dark";
39
+ }
40
+ function resolveIsDark(m) {
41
+ return m === "system" ? systemPrefersDark() : m === "dark";
42
+ }
43
+ function applyToDom(dark) {
44
+ if (typeof document === "undefined") return;
45
+ const root = document.documentElement;
46
+ const strategy = (0, import_theme.getTheme)().darkMode;
47
+ root.classList.toggle("dark", strategy === "class" && dark);
48
+ root.classList.toggle("light", strategy === "class" && !dark);
49
+ if (strategy === "attribute") {
50
+ root.setAttribute("data-theme", dark ? "dark" : "light");
51
+ } else {
52
+ root.removeAttribute("data-theme");
53
+ }
54
+ }
55
+ var mode = "system";
56
+ var isDark = resolveIsDark(mode);
57
+ applyToDom(isDark);
58
+ var hasExplicitChoice = false;
59
+ var subscription = import_react_native.Appearance.addChangeListener(({ colorScheme }) => {
60
+ if (mode !== "system") return;
61
+ isDark = colorScheme === "dark";
62
+ applyToDom(isDark);
63
+ notify();
64
+ });
65
+ function notify() {
66
+ for (const listener of listeners) listener();
67
+ }
68
+ function resyncDomWithActiveTheme() {
69
+ applyToDom(isDark);
70
+ }
71
+ function getGlobalDarkMode() {
72
+ return isDark;
73
+ }
74
+ function getGlobalThemeMode() {
75
+ return mode;
76
+ }
77
+ function setGlobalThemeMode(nextMode) {
78
+ mode = nextMode;
79
+ isDark = resolveIsDark(nextMode);
80
+ hasExplicitChoice = true;
81
+ applyToDom(isDark);
82
+ notify();
83
+ }
84
+ function toggleGlobalDarkMode() {
85
+ setGlobalThemeMode(isDark ? "light" : "dark");
86
+ }
87
+ function subscribeGlobalDarkMode(listener) {
88
+ listeners.add(listener);
89
+ return () => listeners.delete(listener);
90
+ }
91
+ function seedDefaultMode(fallback) {
92
+ if (hasExplicitChoice || mode === fallback) return;
93
+ mode = fallback;
94
+ isDark = resolveIsDark(fallback);
95
+ applyToDom(isDark);
96
+ notify();
97
+ }
98
+ function _resetForTests() {
99
+ mode = "system";
100
+ isDark = resolveIsDark(mode);
101
+ hasExplicitChoice = false;
102
+ listeners.clear();
103
+ }
104
+ function _unsubscribeForTests() {
105
+ subscription.remove();
106
+ }
107
+ // Annotate the CommonJS export names for ESM import in node:
108
+ 0 && (module.exports = {
109
+ _resetForTests,
110
+ _unsubscribeForTests,
111
+ getGlobalDarkMode,
112
+ getGlobalThemeMode,
113
+ resyncDomWithActiveTheme,
114
+ seedDefaultMode,
115
+ setGlobalThemeMode,
116
+ subscribeGlobalDarkMode,
117
+ toggleGlobalDarkMode
118
+ });
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Cross-platform runtime-settable style values — the native counterpart to
3
+ * a real CSS custom property. Real `var(--sidebar-width)` already works on
4
+ * Expo Web today with ZERO code here (raw CSS text, resolved by the
5
+ * browser's own engine — see `jsxRuntimeCoreWeb.ts`, which does no
6
+ * className rewriting at all). Native has no such thing: RN's style system
7
+ * needs an actual JS-computed value at render time, so this module exists
8
+ * to give `var(--x)` an equivalent that works there too — same
9
+ * "module-level store is the real source of truth, no Context required"
10
+ * architecture as `darkModeStore.ts`, and `setDynamicToken` ALSO writes the
11
+ * real CSS custom property to the DOM when one exists (mirroring that
12
+ * file's own `applyToDom`), so a single call updates both platforms
13
+ * identically: instantly via native CSS reactivity on web, via this
14
+ * store's subscribers (see `jsxRuntimeCore.ts`'s `ReactiveElement`, which
15
+ * substitutes a registered token's current value into the className
16
+ * string before every resolve) on native.
17
+ *
18
+ * Deliberately ONE listener set shared by every token, not per-token
19
+ * subscriptions — same trade-off `darkModeStore.ts` already makes for
20
+ * "any relevant change re-renders every subscribed element" simplicity.
21
+ * An unrelated token's change still re-renders every subscribed element
22
+ * (there's no per-token filtering), but `substituteDynamicTokens` in
23
+ * `jsxRuntimeCore.ts` re-reads each token's CURRENT value fresh on every
24
+ * one of those re-renders, so the resolved style stays correct regardless
25
+ * — the redundant re-render is a cheap, accepted trade-off, not a bug.
26
+ */
27
+ /**
28
+ * `name` is the bare token name, WITHOUT the leading `--` (matching how
29
+ * `getDynamicToken`/`var(--name)` substitution both address it).
30
+ *
31
+ * `notify()` below is synchronous and immediately re-renders every
32
+ * already-mounted `ReactiveElement` subscribed via `useSyncExternalStore`
33
+ * (jsxRuntimeCore.ts) — safe when called from a component's own render
34
+ * body (React explicitly allows a component updating external state during
35
+ * its OWN render), a real hazard called from anywhere else with no fixed
36
+ * point in the render lifecycle: module-top-level code in particular runs
37
+ * whenever Metro's inline-requires first evaluates that module, which can
38
+ * land in the middle of React rendering a completely unrelated component
39
+ * elsewhere in the tree — the "Cannot update a component while rendering a
40
+ * different component" class of bug. Reported from a QA pass. Call it
41
+ * synchronously from your app's ROOT component's render (before any
42
+ * consumer has mounted), guarded so it only fires once — see this
43
+ * package's own AGENTS.md section 8 for the full Bad/Good example.
44
+ */
45
+ declare function setDynamicToken(name: string, value: string): void;
46
+ declare function getDynamicToken(name: string): string | undefined;
47
+ declare function deleteDynamicToken(name: string): void;
48
+ declare function subscribeDynamicTokens(listener: () => void): () => void;
49
+ declare function getDynamicTokensVersion(): number;
50
+ /** Exported for tests only — resets every module-level field back to its as-if-just-imported state. */
51
+ declare function _resetForTests(): void;
52
+
53
+ export { _resetForTests, deleteDynamicToken, getDynamicToken, getDynamicTokensVersion, setDynamicToken, subscribeDynamicTokens };
@@ -0,0 +1,75 @@
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/dynamicTokens.ts
21
+ var dynamicTokens_exports = {};
22
+ __export(dynamicTokens_exports, {
23
+ _resetForTests: () => _resetForTests,
24
+ deleteDynamicToken: () => deleteDynamicToken,
25
+ getDynamicToken: () => getDynamicToken,
26
+ getDynamicTokensVersion: () => getDynamicTokensVersion,
27
+ setDynamicToken: () => setDynamicToken,
28
+ subscribeDynamicTokens: () => subscribeDynamicTokens
29
+ });
30
+ module.exports = __toCommonJS(dynamicTokens_exports);
31
+ var tokens = /* @__PURE__ */ new Map();
32
+ var listeners = /* @__PURE__ */ new Set();
33
+ var version = 0;
34
+ function applyToDom(name, value) {
35
+ if (typeof document === "undefined") return;
36
+ document.documentElement.style.setProperty(`--${name}`, value);
37
+ }
38
+ function notify() {
39
+ version++;
40
+ for (const listener of listeners) listener();
41
+ }
42
+ function setDynamicToken(name, value) {
43
+ tokens.set(name, value);
44
+ applyToDom(name, value);
45
+ notify();
46
+ }
47
+ function getDynamicToken(name) {
48
+ return tokens.get(name);
49
+ }
50
+ function deleteDynamicToken(name) {
51
+ if (!tokens.delete(name)) return;
52
+ if (typeof document !== "undefined") document.documentElement.style.removeProperty(`--${name}`);
53
+ notify();
54
+ }
55
+ function subscribeDynamicTokens(listener) {
56
+ listeners.add(listener);
57
+ return () => listeners.delete(listener);
58
+ }
59
+ function getDynamicTokensVersion() {
60
+ return version;
61
+ }
62
+ function _resetForTests() {
63
+ tokens.clear();
64
+ listeners.clear();
65
+ version = 0;
66
+ }
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ _resetForTests,
70
+ deleteDynamicToken,
71
+ getDynamicToken,
72
+ getDynamicTokensVersion,
73
+ setDynamicToken,
74
+ subscribeDynamicTokens
75
+ });
package/dist/index.d.ts CHANGED
@@ -1,83 +1,103 @@
1
- export { C as ColorEntry, a as ColorScale, b as ColorsAPI, c as ContainerConfig, K as KbachConfig, T as ThemeConfig, d as ThemeMode, e as ThemeProvider, f as ThemeProviderProps, g as ThemeState, h as applyKbachConfig, i as defaultTheme, j as getGlobalDarkMode, k as getGlobalThemeMode, l as getTheme, r as resolveKbachConfig, s as setGlobalThemeMode, m as setTheme, n as subscribeGlobalDarkMode, t as toggleGlobalDarkMode, u as useColors, o as useTheme } from './useColors-CeP5_HvM.js';
1
+ export { ColorEntry, ContainerConfig, ThemeConfig, defaultTheme, getTheme, setTheme } from './theme';
2
+ export { B as Button, a as ButtonProps, C as ClassArray, b as ClassDictionary, c as ClassValue, d as ColorScale, e as ColorsAPI, H as H1, f as H2, g as H3, h as H4, i as H5, j as H6, k as HeadingProps, K as KbachConfig, P as Paragraph, l as ParagraphProps, T as ThemeProvider, m as ThemeProviderProps, n as ThemeState, o as ThemeStorageAdapter, p as applyKbachConfig, q as clsx, r as resolveKbachConfig, u as useColors, s as useDynamicToken, t as useTheme } from './semanticElements-Bk3TB-vt.js';
3
+ export { ThemeMode, getGlobalDarkMode, getGlobalThemeMode, setGlobalThemeMode, subscribeGlobalDarkMode, toggleGlobalDarkMode } from './darkModeStore';
4
+ export { deleteDynamicToken, getDynamicToken, setDynamicToken, subscribeDynamicTokens } from './dynamicTokens';
2
5
  import 'react';
6
+ import 'react-native';
3
7
 
4
8
  type StyleValue = string | number | {
5
9
  width: number;
6
10
  height: number;
7
- };
11
+ } | Array<Record<string, string | number>>;
8
12
  interface StyleObject {
9
13
  [key: string]: StyleValue;
10
14
  }
15
+ declare function resolveStyle(classString: string, pressed?: boolean): StyleObject;
16
+
17
+ export { type StyleObject, resolveStyle };
18
+
11
19
  /**
12
- * Calls the Rust engine via the KbachModule TurboModule (see
13
- * apps/native-sandbox/android/.../KbachModule.kt and
14
- * packages/core-engine/src/resolve_style.rs) and returns a plain style
15
- * object ready for RN's `style` prop. Synchronous — no async init step,
16
- * unlike the web/WASM path, since JSI-backed TurboModule methods are
17
- * available as soon as the module is loaded.
18
- *
19
- * Reads `getGlobalDarkMode()` (darkModeStore.ts) fresh on every call (no
20
- * caching) so `dark:` resolves correctly whenever this runs. That store —
21
- * not a direct `Appearance.getColorScheme()` read, which this function
22
- * used prior to `<ThemeProvider>` support — is what makes an explicit
23
- * `setGlobalThemeMode('dark')`/`toggle()` override actually affect
24
- * rendering; the store itself falls back to tracking `Appearance` live
25
- * whenever the mode is `'system'` (its own default), so nothing regresses
26
- * for apps that never touch the override API at all. This function itself
27
- * has no subscription of its own, so nothing re-renders just because the
28
- * store's value changed — call `useTheme()` (its `isDark`) somewhere in
29
- * the tree for that, NOT React Native's own `useColorScheme()`, which only
30
- * reflects the raw OS setting and would miss an explicit override entirely.
20
+ * Ambient module augmentation adding `className?: string` to React
21
+ * Native's own component prop types — without this, `<View
22
+ * className="...">` type-checks fine at RUNTIME (the babel plugin/
23
+ * jsx-runtime accept `className` on ANY host element regardless of its
24
+ * declared prop type — see jsxRuntimeCore.ts's own `processElement` doc
25
+ * comment) but fails `tsc`/editor type-checking, since `ViewProps`/
26
+ * `TextProps`/etc. (react-native's own types) have no `className` field at
27
+ * all. Confirmed as a real, reported gap: nothing in this package shipped
28
+ * this augmentation before, so a React Native CLI project running `tsc`
29
+ * (or just seeing red squiggles in-editor) hit "Property 'className' does
30
+ * not exist on type ... ViewProps ..." on every styled element.
31
31
  *
32
- * Phase 11 originally shipped with live in-place theme switching unverified
33
- * (a `uiMode` toggle triggered a re-render but `Appearance.getColorScheme()`
34
- * kept returning a stale value). Root-caused in Phase 12 while debugging an
35
- * unrelated `active:` failure: `apps/native-sandbox` has its own separate
36
- * `node_modules/react-native` (excluded from the npm workspace since Phase
37
- * 5), while `packages/react-native` resolved `react-native` hierarchically
38
- * up to a *different* copy at the repo root — two physical module
39
- * instances, so a `useColorScheme()` subscription and an
40
- * `Appearance.getColorScheme()` read were silently talking to two separate
41
- * copies of the Appearance module. Fixed by forcing a single instance via
42
- * `resolver.resolveRequest` in apps/native-sandbox/metro.config.js; live
43
- * theme switching (and `active:`, the bug that surfaced this) both verified
44
- * working after the fix — see Phase 12. Still relevant here: darkModeStore.ts
45
- * itself calls `Appearance.addChangeListener`, so the same dual-instance
46
- * failure mode would silently break the 'system' fallback path too if that
47
- * metro.config.js fix ever regressed.
32
+ * A plain `.d.ts` file has no effect on its own unless something actually
33
+ * pulls it into a consumer's type-checking. A side-effect `import
34
+ * './rnClassNameTypes'` from index.ts was the first thing tried here, but
35
+ * tsup's dts rollup (rollup-plugin-dts) tree-shakes a side-effect-only
36
+ * import with nothing it can trace a type reference through — confirmed by
37
+ * hand that this wasn't even consistent (survived one build, silently
38
+ * vanished from an immediately-following clean rebuild of the identical
39
+ * source). `scripts/append-classname-types.mjs` appends this file's own
40
+ * text onto the end of the built `dist/index.d.ts`/`dist/index.web.d.ts`
41
+ * directly as a deterministic post-build step instead — see that script's
42
+ * own doc comment. Anyone who imports ANYTHING from '@kbach/react-native'
43
+ * gets it with no extra tsconfig step needed either way. Same underlying
44
+ * problem (and the interface-merge half of this fix) nativewind — a React
45
+ * Native styling library solving this identical className-typing problem —
46
+ * also has to solve.
48
47
  *
49
- * `pressed` gates the `active:` modifier — unlike `colorScheme`, there's no
50
- * system-level getter for "is this element currently pressed"; only RN's
51
- * `Pressable` ever knows this, so it's passed in directly by the caller
52
- * (jsx-runtime, from Pressable's own style-function callback) rather than
53
- * queried here. Defaults to `false` for every other element type.
54
- *
55
- * `width` gates `sm:`/`md:`/`lg:`/`xl:`/`2xl:` against the active theme's
56
- * `screens` scale (resolve_style.rs's `native_modifier_state`) — read fresh
57
- * from `Dimensions.get('window').width` on every call, the same "no
58
- * caching, no store" choice `colorScheme`/`pressed` already make, and for
59
- * the same reason: unlike dark mode there's no explicit-override concept to
60
- * preserve here (nobody manually overrides their screen width), so a plain
61
- * synchronous read is enough — no need for the subscribable store
62
- * darkModeStore.ts is for. As with `colorScheme`, this function has no
63
- * subscription of its own, so rotating/resizing the window doesn't
64
- * re-render anything by itself — call RN's own `useWindowDimensions()`
65
- * somewhere in the tree for that (same role `useColorScheme()` plays for
66
- * `dark:` in apps/native-sandbox/App.tsx).
67
- *
68
- * Falls back to `./jsEngine` (a pure-JS, no-WASM/no-native reimplementation
69
- * of this same resolution logic — see that directory's own doc comments)
70
- * when `KbachModule` isn't registered at all — Expo Go, which can never
71
- * load ANY custom native module (not even Expo's own Modules API), so the
72
- * TurboModule this file otherwise depends on simply doesn't exist there.
73
- * `TurboModuleRegistry.get` (not `.getEnforcing`, which throws) is what
74
- * makes this detectable at all — `get` returns `null`/`undefined` instead.
75
- * A real dev-client/CLI build always has the module registered, so this
76
- * fallback only ever activates in Expo Go itself; everywhere else behaves
77
- * exactly as before. The JS engine covers a strict subset of what the
78
- * native/WASM engines resolve (see jsEngine/resolveUtilityNative.ts) — an
79
- * intentional, documented parity gap, not a bug.
48
+ * Every interface below is `export interface XProps extends Readonly<...>
49
+ * {}` in react-native's own generated types (RN >= ~0.81's Flow-to-TS
50
+ * generation, `types_generated/`) — an otherwise-empty body, so merging a
51
+ * member in is exactly as safe as against a hand-written interface.
52
+ * Deliberately NOT listed here: `ImageProps`, `TouchableOpacityProps`,
53
+ * `ModalProps` — these are `export type X = Readonly<...>` TYPE ALIASES in
54
+ * the same generated types, which TypeScript cannot declaration-merge into
55
+ * at all (confirmed by hand: attempting it is a flat "Duplicate identifier"
56
+ * compile error, not a silent no-op). They don't need an entry anyway —
57
+ * confirmed against a real `tsc` run (RN 0.87) that `className` on
58
+ * `Image`/`TouchableOpacity`/`TouchableHighlight`/`Modal`/`SafeAreaView`
59
+ * ALL already type-check cleanly once `ViewProps` and
60
+ * `TouchableWithoutFeedbackProps` below are augmented — each of those
61
+ * components' real prop type composes one or the other somewhere in its
62
+ * own `Omit<...> & ...` chain (`SafeAreaView` in particular turned out to
63
+ * reuse `ViewProps` directly, with no separate props type of its own at
64
+ * all), so the merged `className` field flows through without needing its
65
+ * own dedicated entry.
80
66
  */
81
- declare function resolveStyle(classString: string, pressed?: boolean): StyleObject;
67
+ export {};
82
68
 
83
- export { type StyleObject, resolveStyle };
69
+ declare module 'react-native' {
70
+ interface ViewProps {
71
+ className?: string;
72
+ }
73
+ interface TextProps {
74
+ className?: string;
75
+ }
76
+ interface ScrollViewProps {
77
+ className?: string;
78
+ }
79
+ interface PressableProps {
80
+ className?: string;
81
+ }
82
+ interface TextInputProps {
83
+ className?: string;
84
+ }
85
+ interface TouchableHighlightProps {
86
+ className?: string;
87
+ }
88
+ interface TouchableWithoutFeedbackProps {
89
+ className?: string;
90
+ }
91
+ interface SwitchProps {
92
+ className?: string;
93
+ }
94
+ interface KeyboardAvoidingViewProps {
95
+ className?: string;
96
+ }
97
+ interface FlatListProps<ItemT> {
98
+ className?: string;
99
+ }
100
+ interface SectionListProps<ItemT, SectionT> {
101
+ className?: string;
102
+ }
103
+ }