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

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.
package/README.md CHANGED
@@ -172,6 +172,81 @@ dark mode — this palette's own convention is 1 = lightest, 12 = darkest, so
172
172
  that's the same visual weight relative to its own background, no manual
173
173
  `colors.blue[isDark ? 7 : 6]` needed.
174
174
 
175
+ ## Arbitrary math: `calc()`, `clamp()`, `min()`, `max()`
176
+
177
+ ```tsx
178
+ <View className="p-[calc(16px+8px)]" /> // -> padding: 24
179
+ <View className="w-[clamp(1rem,2rem,3rem)]" /> // -> width: 32
180
+ ```
181
+
182
+ Resolves at **build/resolve time**, not runtime — every operand must be a
183
+ constant `px`/`rem` length (or a bare number). This works because native has
184
+ no CSS engine to evaluate a real `calc()` string at paint time, so the only
185
+ way to support it at all is to compute the answer ourselves.
186
+
187
+ A **percentage- or viewport-relative** expression (`calc(50%-0.5rem)`,
188
+ `calc(10vw+8px)`) can't be reduced this way — it genuinely needs the
189
+ parent's actual layout size, which doesn't exist until paint time on
190
+ native. These already work fine on web (real CSS); on native the
191
+ declaration is dropped and a `console.warn` explains why (dev builds only),
192
+ rather than silently shipping an invalid value into the style object. Use a
193
+ fraction utility (`w-1/2`) for relative sizing on native instead — see
194
+ `resolvers/spacing.rs`'s `fraction_percent` — or resolve the value in JS.
195
+
196
+ ## Unknown-class warnings (typo detection)
197
+
198
+ ```tsx
199
+ <View className="flexx-center" /> // real Kbach classes never have to guess — a typo warns
200
+ ```
201
+
202
+ ```
203
+ Kbach: "flexx-center" doesn't match any known Kbach utility — typo? (skipped) (from className "flexx-center")
204
+ ```
205
+
206
+ On native/dev-client builds, a class that doesn't match *any* Kbach
207
+ utility on *any* platform gets a `console.warn` (dev builds only, printed
208
+ once per unique message) instead of silently doing nothing — the same
209
+ signal `@kbach/react`'s Vite plugin already gives you at build time on
210
+ web, just at resolve time here instead. A real utility this engine simply
211
+ doesn't support on native yet (`grid-cols-3`, `scale-150`, `blur`, ...)
212
+ never warns — that's an intentional, documented platform gap (see
213
+ `resolve_style.rs`'s own doc comment), not a typo, so it stays silent the
214
+ same way it always has.
215
+
216
+ Not available in Expo Go's pure-JS fallback engine today — that engine has
217
+ no web-shaped resolver to check "is this a real Kbach utility at all"
218
+ against, only the (smaller) native-supported subset, so it can't
219
+ distinguish a genuine typo from a real-but-native-unsupported class
220
+ without a much larger port. A real dev-client/CLI build always gets this
221
+ check.
222
+
223
+ ## Dynamic tokens
224
+
225
+ The native counterpart to a real CSS custom property — `var(--x)` already
226
+ works in a `className` on Expo Web with zero help from this package (real
227
+ CSS, resolved by the browser). This gives native the same className syntax:
228
+
229
+ ```tsx
230
+ import { setDynamicToken, useDynamicToken } from '@kbach/react-native';
231
+
232
+ setDynamicToken('sidebar-width', '240px'); // updates every subscribed element, on both platforms
233
+ <View className="w-[var(--sidebar-width)]" />
234
+
235
+ // Reading the raw value in JS, reactively:
236
+ function Sidebar() {
237
+ const width = useDynamicToken('sidebar-width'); // '240px' | undefined
238
+ }
239
+ ```
240
+
241
+ On web, `setDynamicToken` writes the real CSS custom property to the DOM —
242
+ every element using it repaints instantly via the browser's own CSS engine,
243
+ no React re-render involved. On native, the className is substituted with
244
+ the token's current value before every resolve, and an element referencing
245
+ a token re-renders/repaints on its own when that specific token changes
246
+ (same `key`-remount mechanism `dark:` and `sm:`/`md:`/... already use — see
247
+ `jsxRuntimeCore.ts`'s own doc comments). An unregistered token name falls
248
+ through to the same native invalid-value warning above.
249
+
175
250
  ## License
176
251
 
177
252
  MIT
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getTheme
3
- } from "./chunk-3ED4FIO2.mjs";
3
+ } from "./chunk-OGFB3OXS.mjs";
4
4
 
5
5
  // src/darkModeStore.ts
6
6
  import { Appearance } from "react-native";
@@ -63,11 +63,45 @@ function seedDefaultMode(fallback) {
63
63
  notify();
64
64
  }
65
65
 
66
+ // src/dynamicTokens.ts
67
+ var tokens = /* @__PURE__ */ new Map();
68
+ var listeners2 = /* @__PURE__ */ new Set();
69
+ var version = 0;
70
+ function applyToDom2(name, value) {
71
+ if (typeof document === "undefined") return;
72
+ document.documentElement.style.setProperty(`--${name}`, value);
73
+ }
74
+ function notify2() {
75
+ version++;
76
+ for (const listener of listeners2) listener();
77
+ }
78
+ function setDynamicToken(name, value) {
79
+ tokens.set(name, value);
80
+ applyToDom2(name, value);
81
+ notify2();
82
+ }
83
+ function getDynamicToken(name) {
84
+ return tokens.get(name);
85
+ }
86
+ function deleteDynamicToken(name) {
87
+ if (!tokens.delete(name)) return;
88
+ if (typeof document !== "undefined") document.documentElement.style.removeProperty(`--${name}`);
89
+ notify2();
90
+ }
91
+ function subscribeDynamicTokens(listener) {
92
+ listeners2.add(listener);
93
+ return () => listeners2.delete(listener);
94
+ }
95
+
66
96
  export {
67
97
  getGlobalDarkMode,
68
98
  getGlobalThemeMode,
69
99
  setGlobalThemeMode,
70
100
  toggleGlobalDarkMode,
71
101
  subscribeGlobalDarkMode,
72
- seedDefaultMode
102
+ seedDefaultMode,
103
+ setDynamicToken,
104
+ getDynamicToken,
105
+ deleteDynamicToken,
106
+ subscribeDynamicTokens
73
107
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  resolveClassName
3
- } from "./chunk-3ED4FIO2.mjs";
3
+ } from "./chunk-OGFB3OXS.mjs";
4
4
 
5
5
  // src/jsxRuntimeCoreWeb.ts
6
6
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";