@kbach/react-native 1.0.0-beta.14 → 1.0.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,9 +2,8 @@ import {
2
2
  Fragment,
3
3
  jsx,
4
4
  jsxs
5
- } from "./chunk-6QFPLRSP.mjs";
6
- import "./chunk-ZB2UU6EO.mjs";
7
- import "./chunk-HK6PDJJK.mjs";
5
+ } from "./chunk-6ML62O2R.mjs";
6
+ import "./chunk-3ED4FIO2.mjs";
8
7
  export {
9
8
  Fragment,
10
9
  jsx,
@@ -0,0 +1,54 @@
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
+ declare function setTheme(theme: ThemeConfig): void;
50
+ declare function getTheme(): ThemeConfig;
51
+ /** Memoized JSON serialization of the active theme — passed across the JNI boundary. */
52
+ declare function getThemeJson(): string;
53
+
54
+ 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",
@@ -358,10 +387,10 @@ function getTheme() {
358
387
  function getThemeJson() {
359
388
  return activeThemeJson;
360
389
  }
361
-
362
- export {
390
+ // Annotate the CommonJS export names for ESM import in node:
391
+ 0 && (module.exports = {
363
392
  defaultTheme,
364
- setTheme,
365
393
  getTheme,
366
- getThemeJson
367
- };
394
+ getThemeJson,
395
+ setTheme
396
+ });
@@ -1,57 +1,8 @@
1
+ import { ThemeConfig, ContainerConfig } from './theme';
2
+ import { ThemeMode } from './darkModeStore';
1
3
  import * as react from 'react';
2
4
  import { ReactNode } from 'react';
3
5
 
4
- /**
5
- * A plain hex value (static — same in both modes), or a `{ light, dark }`
6
- * pair a caller sets manually in their own theme. Fully opt-in per color:
7
- * nothing here picks a "dark variant" automatically. Only `useColors()`
8
- * (a JS-value read, not a `className`) understands this shape — utility
9
- * CLASS resolution (`bg-blue-6`) on native/Expo Go stays plain-string-only,
10
- * same as it always was (dark mode for a CLASS is the separate `dark:`
11
- * modifier, gated live at resolve time — see `resolve_style.rs`); a
12
- * mode-aware entry referenced directly by a class name just doesn't
13
- * resolve there, mirroring `resolvers/color.rs`'s own `lookup_hex`
14
- * (`ColorValue::Plain` only, `ModeAware` -> `None`) exactly, same as it
15
- * would on the web engine too.
16
- */
17
- type ColorEntry = string | {
18
- light: string;
19
- dark: string;
20
- };
21
- /**
22
- * Real Tailwind's `theme.container` config, mirroring
23
- * `packages/core-engine/src/theme.rs`'s `ContainerConfig` exactly. `center`/
24
- * `padding` DO reach native now (unlike the max-width breakpoint ladder,
25
- * which is a `css.rs`-only concept with nothing to generate on native at
26
- * all) — `resolvers::layout::resolve`'s `"container"` arm is shared by both
27
- * dispatchers, and `margin`/`padding` are ordinary RN style properties.
28
- */
29
- interface ContainerConfig {
30
- center?: boolean;
31
- padding?: string;
32
- }
33
- interface ThemeConfig {
34
- colors: Record<string, ColorEntry>;
35
- spacing: Record<string, number>;
36
- screens: Record<string, number>;
37
- /**
38
- * e.g. "sans" -> "Inter, sans-serif". Optional, matching the Rust
39
- * engine's own `#[serde(default)]`. Write it as a real web-shaped
40
- * fallback stack even on this native-first package — native's own
41
- * resolver strips it down to a single bare name at resolve time (RN's
42
- * `fontFamily` prop can't take a fallback list — see
43
- * `resolvers/mod.rs`'s `first_font_name`), so the SAME config still
44
- * works unmodified on Expo Web, which needs the full stack.
45
- */
46
- fontFamily?: Record<string, string>;
47
- darkMode: 'attribute' | 'class' | 'media';
48
- /** Optional, matching `ContainerConfig`'s own `#[serde(default)]` on the Rust side. */
49
- container?: ContainerConfig;
50
- }
51
- declare const defaultTheme: ThemeConfig;
52
- declare function setTheme(theme: ThemeConfig): void;
53
- declare function getTheme(): ThemeConfig;
54
-
55
6
  /**
56
7
  * A `kbach.config.js`-style theme customization — same shape as
57
8
  * @kbach/react's `KbachConfig`, minus mode-aware `{ light, dark }` color
@@ -109,49 +60,6 @@ declare function resolveKbachConfig(config: KbachConfig): ThemeConfig;
109
60
  /** `resolveKbachConfig()` + `setTheme()` in one call — the usual entry point from app code. */
110
61
  declare function applyKbachConfig(config: KbachConfig): ThemeConfig;
111
62
 
112
- /**
113
- * Native port of @kbach/react's darkModeStore.ts — same architecture (a
114
- * single module-level store is the real source of truth;
115
- * ThemeProvider/useTheme are a thin, OPTIONAL wrapper around it; every
116
- * function here works standalone with no provider mounted anywhere), with
117
- * two real platform differences from the web version:
118
- *
119
- * 1. No persistence. There's no React-Native-builtin equivalent of
120
- * localStorage — adding one would mean forcing a real native dependency
121
- * (e.g. @react-native-async-storage/async-storage) on every consumer,
122
- * even ones that don't want it. The mode always starts at 'system' on a
123
- * fresh app launch. If you want persistence, read your own storage at
124
- * startup (before your first render) and call setGlobalThemeMode() with
125
- * the result — same "seed once, no built-in write-back" shape as
126
- * seedDefaultMode() below, just driven by your own storage instead of
127
- * one this package picks for you.
128
- * 2. `applyToDom` below IS needed here, unlike what an earlier version of
129
- * this file's own comment claimed ("no DOM to apply the resolved mode
130
- * to") — that reasoning only holds for real native (Android/iOS), where
131
- * nativeBridge.ts's resolveStyle() reads getGlobalDarkMode() directly on
132
- * every call, no DOM involved at all. This file is ALSO used by Expo
133
- * Web, though (no `.web.ts` sibling — Metro has nothing to swap in), and
134
- * Expo Web resolves `dark:` classes to REAL CSS with `[data-theme=
135
- * "dark"]`-style selectors (see nativeBridge.web.ts) that only ever
136
- * match if something writes that attribute to the DOM — nothing did,
137
- * which is exactly why toggling the mode changed `useTheme()`'s own
138
- * state (a consumer reading `mode`/`isDark` directly, e.g. for a label,
139
- * updated correctly) while every `dark:`-prefixed style silently never
140
- * applied. `typeof document === 'undefined'` is what makes one function
141
- * safe on both platforms: real native's Hermes has no `document` global
142
- * at all (not even `undefined` as a defined-but-empty value — genuinely
143
- * unset, which `typeof` can check without throwing), so this always
144
- * no-ops there, while Expo Web's react-native-web renders into a real
145
- * browser DOM where it's needed.
146
- */
147
- type ThemeMode = 'light' | 'dark' | 'system';
148
- declare function getGlobalDarkMode(): boolean;
149
- declare function getGlobalThemeMode(): ThemeMode;
150
- /** Explicit user choice — takes priority over any later `<ThemeProvider defaultMode>` seed (see `seedDefaultMode` below). Not persisted; see this module's own doc comment. */
151
- declare function setGlobalThemeMode(nextMode: ThemeMode): void;
152
- declare function toggleGlobalDarkMode(): void;
153
- declare function subscribeGlobalDarkMode(listener: () => void): () => void;
154
-
155
63
  interface ThemeState {
156
64
  mode: ThemeMode;
157
65
  isDark: boolean;
@@ -236,4 +144,4 @@ type ColorsAPI = {
236
144
  */
237
145
  declare function useColors(): ColorsAPI;
238
146
 
239
- export { type ColorEntry as C, type KbachConfig as K, type ThemeConfig as T, type ColorScale as a, type ColorsAPI as b, type ContainerConfig as c, type ThemeMode as d, ThemeProvider as e, type ThemeProviderProps as f, type ThemeState as g, applyKbachConfig as h, defaultTheme as i, getGlobalDarkMode as j, getGlobalThemeMode as k, getTheme as l, setTheme as m, subscribeGlobalDarkMode as n, useTheme as o, resolveKbachConfig as r, setGlobalThemeMode as s, toggleGlobalDarkMode as t, useColors as u };
147
+ export { type ColorScale as C, type KbachConfig as K, ThemeProvider as T, type ColorsAPI as a, type ThemeProviderProps as b, type ThemeState as c, applyKbachConfig as d, useTheme as e, resolveKbachConfig as r, useColors as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbach/react-native",
3
- "version": "1.0.0-beta.14",
3
+ "version": "1.0.0-beta.16",
4
4
  "description": "Kbach's utility-class styling engine for React Native — the same class names as @kbach/react, resolved to a StyleSheet-ready style object via a Kotlin/JNI TurboModule (native), the same WASM engine @kbach/react uses (Expo Web / react-native-web), or a pure-JS fallback engine (Expo Go). Ships its own native Android module — one npm install, no separate native package. Beta. Native is Android-only (no iOS bridge yet); works with the React Native CLI, an Expo dev client, AND Expo Go (a reduced-coverage pure-JS fallback, since Expo Go can't load any custom native module).",
5
5
  "keywords": [
6
6
  "css",
@@ -37,7 +37,6 @@
37
37
  ],
38
38
  "source": "./src/index.ts",
39
39
  "main": "./dist/index.js",
40
- "module": "./dist/index.mjs",
41
40
  "types": "./dist/index.d.ts",
42
41
  "exports": {
43
42
  ".": {
@@ -51,7 +50,6 @@
51
50
  "import": "./dist/index.web.mjs",
52
51
  "require": "./dist/index.web.js"
53
52
  },
54
- "import": "./dist/index.mjs",
55
53
  "require": "./dist/index.js"
56
54
  },
57
55
  "./jsx-runtime": {
@@ -65,7 +63,6 @@
65
63
  "import": "./dist/jsx-runtime.web.mjs",
66
64
  "require": "./dist/jsx-runtime.web.js"
67
65
  },
68
- "import": "./dist/jsx-runtime.mjs",
69
66
  "require": "./dist/jsx-runtime.js"
70
67
  },
71
68
  "./jsx-dev-runtime": {
@@ -79,14 +76,13 @@
79
76
  "import": "./dist/jsx-dev-runtime.web.mjs",
80
77
  "require": "./dist/jsx-dev-runtime.web.js"
81
78
  },
82
- "import": "./dist/jsx-dev-runtime.mjs",
83
79
  "require": "./dist/jsx-dev-runtime.js"
84
80
  },
85
81
  "./babel-plugin": "./src/babel-plugin.js"
86
82
  },
87
83
  "scripts": {
88
- "build": "tsup",
89
- "dev": "tsup --watch",
84
+ "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsup",
85
+ "dev": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsup --watch",
90
86
  "test": "vitest run --passWithNoTests",
91
87
  "lint": "tsc --noEmit",
92
88
  "generate:colors": "node ../core-engine/scripts/generate-palette.mjs src/generatedPalette.ts",
@@ -1,84 +0,0 @@
1
- import {
2
- getGlobalDarkMode,
3
- subscribeGlobalDarkMode
4
- } from "./chunk-RBJXE32L.mjs";
5
-
6
- // src/jsxRuntimeCore.ts
7
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
- import { Fragment, useSyncExternalStore } from "react";
9
- import { Pressable } from "react-native";
10
- function makeElement(isStaticChildren, type, props, key) {
11
- return (isStaticChildren ? _jsxs : _jsx)(type, props, key);
12
- }
13
- function resolvedStyleFor(resolveStyle, classStrRaw, userStyle, pressed) {
14
- const resolved = resolveStyle(classStrRaw, pressed);
15
- if (userStyle === void 0) {
16
- return resolved;
17
- }
18
- if (typeof userStyle === "function") {
19
- return [resolved, userStyle({ pressed })];
20
- }
21
- return [resolved, userStyle];
22
- }
23
- var DARK_MODIFIER_RE = /(^|\s)dark:/;
24
- function darkModeKeySuffix(classStrRaw) {
25
- return DARK_MODIFIER_RE.test(classStrRaw) ? `:kb-dark-${getGlobalDarkMode()}` : "";
26
- }
27
- function DarkAwareElement({
28
- hostType,
29
- hostRest,
30
- classStrRaw,
31
- userStyle,
32
- resolveStyle,
33
- elementKey,
34
- isStaticChildren
35
- }) {
36
- useSyncExternalStore(subscribeGlobalDarkMode, getGlobalDarkMode);
37
- const finalStyle = hostType === Pressable ? (state) => resolvedStyleFor(resolveStyle, classStrRaw, userStyle, state.pressed) : resolvedStyleFor(resolveStyle, classStrRaw, userStyle, false);
38
- const suffix = darkModeKeySuffix(classStrRaw);
39
- const finalKey = suffix ? `${elementKey ?? ""}${suffix}` : elementKey;
40
- return makeElement(isStaticChildren, hostType, { ...hostRest, style: finalStyle }, finalKey);
41
- }
42
- function processElement(resolveStyle, type, rawProps, key, isStaticChildren) {
43
- if (type === null || typeof type === "symbol" || !rawProps) {
44
- return makeElement(isStaticChildren, type, rawProps ?? {}, key);
45
- }
46
- const { className: classStrRaw, style: userStyle, ...rest } = rawProps;
47
- if (typeof classStrRaw !== "string") {
48
- return makeElement(isStaticChildren, type, rawProps, key);
49
- }
50
- if (DARK_MODIFIER_RE.test(classStrRaw)) {
51
- return _jsx(
52
- DarkAwareElement,
53
- { hostType: type, hostRest: rest, classStrRaw, userStyle, resolveStyle, elementKey: key, isStaticChildren },
54
- key
55
- );
56
- }
57
- const finalStyle = type === Pressable ? (state) => resolvedStyleFor(resolveStyle, classStrRaw, userStyle, state.pressed) : resolvedStyleFor(resolveStyle, classStrRaw, userStyle, false);
58
- return makeElement(isStaticChildren, type, { ...rest, style: finalStyle }, key);
59
- }
60
- function createJsxFunctions(resolveStyle) {
61
- function jsx(type, props, key) {
62
- return processElement(resolveStyle, type, props, key, false);
63
- }
64
- function jsxs(type, props, key) {
65
- return processElement(resolveStyle, type, props, key, true);
66
- }
67
- return { jsx, jsxs };
68
- }
69
- function createJsxDEV(jsx, jsxs) {
70
- return function jsxDEV(type, props, key, isStaticChildren, source, self) {
71
- const element = (isStaticChildren ? jsxs : jsx)(type, props, key);
72
- if (source && element && typeof element === "object" && Object.isExtensible(element)) {
73
- element._source = source;
74
- element._self = self;
75
- }
76
- return element;
77
- };
78
- }
79
-
80
- export {
81
- Fragment,
82
- createJsxFunctions,
83
- createJsxDEV
84
- };