@kbach/react-native 1.0.0-beta.9 → 1.0.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.
- package/AGENTS.md +495 -0
- package/LICENSE +21 -0
- package/README.md +198 -70
- package/THIRD_PARTY_NOTICES.md +41 -0
- package/android/src/main/jniLibs/arm64-v8a/libkbach_core_engine.so +0 -0
- package/android/src/main/jniLibs/x86_64/libkbach_core_engine.so +0 -0
- package/dist/chunk-7CNURQSH.mjs +112 -0
- package/dist/{chunk-YOC3SHF5.mjs → chunk-HYQFT32E.mjs} +2 -2
- package/dist/chunk-MUPEQJRT.mjs +623 -0
- package/dist/darkModeStore.d.ts +73 -0
- package/dist/darkModeStore.js +118 -0
- package/dist/dynamicTokens.d.ts +53 -0
- package/dist/dynamicTokens.js +75 -0
- package/dist/index.d.ts +90 -70
- package/dist/index.js +1300 -610
- package/dist/index.web.d.ts +91 -1
- package/dist/index.web.js +204 -441
- package/dist/index.web.mjs +294 -12
- package/dist/jsx-dev-runtime.d.ts +2 -2
- package/dist/jsx-dev-runtime.js +1532 -603
- package/dist/jsx-dev-runtime.web.d.ts +2 -2
- package/dist/jsx-dev-runtime.web.js +20 -355
- package/dist/jsx-dev-runtime.web.mjs +18 -6
- package/dist/jsx-runtime.d.ts +3 -3
- package/dist/jsx-runtime.js +1522 -593
- package/dist/jsx-runtime.web.d.ts +3 -3
- package/dist/jsx-runtime.web.js +17 -355
- package/dist/jsx-runtime.web.mjs +2 -3
- package/dist/semanticElements-Bk3TB-vt.d.ts +334 -0
- package/dist/theme.d.ts +79 -0
- package/dist/{chunk-HK6PDJJK.mjs → theme.js} +99 -11
- package/llms.txt +38 -0
- package/package.json +15 -13
- package/src/babel-plugin.js +95 -25
- package/dist/chunk-DLIXI5OW.mjs +0 -53
- package/dist/chunk-DOWW44F7.mjs +0 -14
- package/dist/chunk-H5Z24XX5.mjs +0 -192
- package/dist/chunk-SY5OAY2C.mjs +0 -1211
- package/dist/chunk-X4UQCEOE.mjs +0 -186
- package/dist/chunk-Z664AKW7.mjs +0 -54
- package/dist/index.d.mts +0 -83
- package/dist/index.mjs +0 -38
- package/dist/index.web.d.mts +0 -15
- package/dist/jsx-dev-runtime.d.mts +0 -10
- package/dist/jsx-dev-runtime.mjs +0 -18
- package/dist/jsx-dev-runtime.web.d.mts +0 -10
- package/dist/jsx-runtime.d.mts +0 -7
- package/dist/jsx-runtime.mjs +0 -15
- package/dist/jsx-runtime.web.d.mts +0 -7
- package/dist/useColors-CeP5_HvM.d.mts +0 -230
- package/dist/useColors-CeP5_HvM.d.ts +0 -230
package/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# @kbach/react-native
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Utility-class styling for React Native — the same class names as
|
|
4
|
+
[`@kbach/react`](https://www.npmjs.com/package/@kbach/react), resolved to a
|
|
5
|
+
`StyleSheet`-ready style object instead of CSS.
|
|
6
6
|
|
|
7
|
-
>
|
|
8
|
-
>
|
|
7
|
+
> Native is Android-only (no iOS bridge yet) — on iOS, every
|
|
8
|
+
> build (dev client, CLI, EAS) runs the same reduced-coverage JS-fallback
|
|
9
|
+
> engine as Expo Go, not the full native engine. Ships a prebuilt native
|
|
10
|
+
> module — no Rust toolchain or manual linking.
|
|
9
11
|
|
|
10
12
|
## Install
|
|
11
13
|
|
|
@@ -13,115 +15,241 @@ resolved to a `StyleSheet`-ready style object instead of injected CSS.
|
|
|
13
15
|
npm install @kbach/react-native
|
|
14
16
|
```
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
Or skip straight to a working setup: `npx @kbach/cli init` detects Expo
|
|
19
|
+
or React Native CLI, installs this package, and patches
|
|
20
|
+
`babel.config.js` for you (on React Native CLI, it'll even offer to run
|
|
21
|
+
the native rebuild) — see [`@kbach/cli`](https://www.npmjs.com/package/@kbach/cli).
|
|
22
|
+
The steps below are what it automates, and still the fallback it prints
|
|
23
|
+
if your `babel.config.js`'s shape is too unusual for it to edit safely.
|
|
24
|
+
|
|
25
|
+
## Setup
|
|
26
|
+
|
|
27
|
+
The babel plugin (below) is **required on every target, including Expo
|
|
28
|
+
Go** — it's the only thing that makes `className` get intercepted at all;
|
|
29
|
+
without it, `className` is just an unrecognized prop RN silently ignores
|
|
30
|
+
(no styling, no warning). What differs per target is what happens *after*
|
|
31
|
+
that:
|
|
32
|
+
|
|
33
|
+
| Target | Setup |
|
|
34
|
+
| :-- | :-- |
|
|
35
|
+
| **Expo Go** | Add the babel plugin (below). A pure-JS fallback engine loads automatically after that — no other setup. |
|
|
36
|
+
| **Expo Web** / `react-native-web` | Add the babel plugin (below). Resolves through the same CSS engine `@kbach/react` uses after that — no other setup. |
|
|
37
|
+
| **Expo dev client / prebuild / EAS** | Add the babel plugin (below), then `npx expo prebuild && npx expo run:android`. |
|
|
38
|
+
| **React Native CLI** | Add the babel plugin (below), then restart Metro with `--reset-cache` and rebuild the app. |
|
|
39
|
+
|
|
40
|
+
The babel plugin, added to your existing `babel.config.js`:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
// Expo — keep the function form your project already has:
|
|
44
|
+
module.exports = function (api) {
|
|
45
|
+
api.cache(true);
|
|
46
|
+
return {
|
|
47
|
+
presets: ['babel-preset-expo'],
|
|
48
|
+
plugins: ['@kbach/react-native/babel-plugin'],
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
```
|
|
17
52
|
|
|
18
53
|
```js
|
|
19
|
-
//
|
|
54
|
+
// React Native CLI:
|
|
20
55
|
module.exports = {
|
|
21
56
|
presets: ['module:@react-native/babel-preset'],
|
|
22
57
|
plugins: ['@kbach/react-native/babel-plugin'],
|
|
23
58
|
};
|
|
24
59
|
```
|
|
25
60
|
|
|
26
|
-
|
|
61
|
+
A plain JS reload isn't enough after adding the plugin or editing
|
|
62
|
+
`kbach.config.js` — Metro's transform cache doesn't reliably pick up a
|
|
63
|
+
babel config change on its own. Restart with `--reset-cache` (`npx
|
|
64
|
+
react-native start --reset-cache` / `npx expo start --clear`).
|
|
65
|
+
|
|
66
|
+
Then write classes:
|
|
27
67
|
|
|
28
|
-
|
|
68
|
+
```tsx
|
|
69
|
+
import { View, Text } from 'react-native';
|
|
29
70
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
shadows. Doesn't cover grid, transforms, filters, gradients, or DOM-only
|
|
35
|
-
typography — same scope native itself excludes.
|
|
71
|
+
<View className="flex-1 items-center justify-center bg-white dark:bg-black">
|
|
72
|
+
<Text className="text-lg font-bold">Hello Kbach</Text>
|
|
73
|
+
</View>;
|
|
74
|
+
```
|
|
36
75
|
|
|
37
|
-
|
|
76
|
+
## Theme
|
|
38
77
|
|
|
39
|
-
|
|
78
|
+
Optional. Create `kbach.config.js` at your project root — the babel plugin
|
|
79
|
+
picks it up automatically, no import or `applyKbachConfig()` call needed:
|
|
40
80
|
|
|
41
81
|
```js
|
|
42
|
-
//
|
|
82
|
+
// kbach.config.js
|
|
43
83
|
module.exports = {
|
|
44
|
-
|
|
45
|
-
|
|
84
|
+
extend: {
|
|
85
|
+
colors: {
|
|
86
|
+
brand: '#ff6b35',
|
|
87
|
+
surface: 'gray-2',
|
|
88
|
+
dark: { surface: 'gray-11' }, // makes `bg-surface` mode-aware
|
|
89
|
+
},
|
|
90
|
+
},
|
|
46
91
|
};
|
|
47
92
|
```
|
|
48
93
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
npx expo run:android
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Requires the New Architecture enabled (`"newArchEnabled": true` in
|
|
55
|
-
`app.json`, on by default in current Expo SDKs). EAS Build works the same
|
|
56
|
-
way, no extra config.
|
|
94
|
+
It's plain JavaScript — **quote any key containing a hyphen**
|
|
95
|
+
(`'surface-dim': '#121318'`).
|
|
57
96
|
|
|
58
|
-
|
|
97
|
+
Full config reference (colors, spacing, breakpoints, fonts, dark mode) is
|
|
98
|
+
in [AGENTS.md](https://github.com/semsakadanupol/kbach/blob/main/AGENTS.md).
|
|
59
99
|
|
|
60
|
-
|
|
61
|
-
`@kbach/react` uses on the DOM, with full modifier support (`hover:`,
|
|
62
|
-
`focus:`, `group-hover:`, container queries, etc.), not just the
|
|
63
|
-
`dark:`/`active:`/responsive subset native supports.
|
|
100
|
+
## Dark mode
|
|
64
101
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
not the visiting browser — so a user in dark mode can briefly see the light
|
|
68
|
-
version on first paint. Defer preference-dependent classes until mounted:
|
|
102
|
+
Zero setup on every target. `dark:` classes react to the OS setting;
|
|
103
|
+
`useTheme()` gives you a manual toggle:
|
|
69
104
|
|
|
70
105
|
```tsx
|
|
71
|
-
|
|
72
|
-
useEffect(() => setMounted(true), []);
|
|
106
|
+
import { useTheme } from '@kbach/react-native';
|
|
73
107
|
|
|
74
|
-
|
|
108
|
+
const { mode, isDark, setMode, toggle } = useTheme();
|
|
75
109
|
```
|
|
76
110
|
|
|
77
|
-
|
|
111
|
+
Works anywhere, no provider. `<ThemeProvider>` is optional — for seeding a
|
|
112
|
+
startup default and opt-in persistence (`<ThemeProvider persist={AsyncStorage}>`).
|
|
113
|
+
Mount at most one — a second instance logs a dev warning, since dark mode
|
|
114
|
+
is one global store, not scoped per provider.
|
|
115
|
+
|
|
116
|
+
## Dynamic values
|
|
117
|
+
|
|
118
|
+
For a value that changes at runtime without touching component state —
|
|
119
|
+
a live accent color, a user-picked theme:
|
|
78
120
|
|
|
79
121
|
```tsx
|
|
80
|
-
import {
|
|
122
|
+
import { setDynamicToken, useDynamicToken } from '@kbach/react-native';
|
|
81
123
|
|
|
82
|
-
|
|
83
|
-
const { mode, isDark, setMode, toggle } = useTheme();
|
|
84
|
-
return <Pressable onPress={toggle}><Text>{mode}</Text></Pressable>;
|
|
85
|
-
}
|
|
86
|
-
```
|
|
124
|
+
setDynamicToken('accent', '#8b5cf6');
|
|
87
125
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
126
|
+
<View className="bg-[var(--accent)]" />; // updates instantly, everywhere it's used
|
|
127
|
+
const accent = useDynamicToken('accent'); // '#8b5cf6' | undefined, reactive
|
|
128
|
+
```
|
|
91
129
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
130
|
+
Call `setDynamicToken` from a component's own render (guarded to fire
|
|
131
|
+
once), not from module top-level — see
|
|
132
|
+
[AGENTS.md §8](https://github.com/semsakadanupol/kbach/blob/main/packages/react-native/AGENTS.md)
|
|
133
|
+
for why and the exact pattern.
|
|
95
134
|
|
|
96
|
-
##
|
|
135
|
+
## Colors as values
|
|
97
136
|
|
|
98
|
-
For
|
|
99
|
-
native shadow color:
|
|
137
|
+
For a real color string rather than a class — a chart prop, a shadow color:
|
|
100
138
|
|
|
101
139
|
```tsx
|
|
102
140
|
import { useColors } from '@kbach/react-native';
|
|
103
141
|
|
|
104
142
|
const colors = useColors();
|
|
105
|
-
colors.blue[6];
|
|
106
|
-
colors.blue['6/50'];
|
|
143
|
+
colors.blue[6]; // '#2563eb'
|
|
144
|
+
colors.blue['6/50']; // same at 50% opacity
|
|
145
|
+
colors.get('brand'); // a custom color, typed as plain `string`
|
|
107
146
|
```
|
|
108
147
|
|
|
109
|
-
|
|
110
|
-
`{ light, dark }` pair — fully manual, resolved per the current dark-mode
|
|
111
|
-
state:
|
|
148
|
+
## Semantic HTML on web
|
|
112
149
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
150
|
+
On Expo Web, `<View>`/`<Text>` render as a plain `<div>`/`<span>` by
|
|
151
|
+
default (`react-native-web`'s own choice, not this package's). For a real
|
|
152
|
+
`<button>`/`<h1>`-`<h6>`/`<p>` instead, use these — each is just the
|
|
153
|
+
right underlying component with its semantic role pre-set, so `className`
|
|
154
|
+
keeps working exactly like it does on a bare `Pressable`/`Text`:
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
import { Button, H1, Paragraph } from '@kbach/react-native';
|
|
158
|
+
|
|
159
|
+
<H1 className="text-2xl font-bold">Page title</H1>
|
|
160
|
+
<Paragraph className="text-sm text-gray-7">Body copy.</Paragraph>
|
|
161
|
+
<Button className="px-4 py-2 rounded bg-blue-6" onPress={...}>Save</Button>
|
|
118
162
|
```
|
|
119
163
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
`
|
|
164
|
+
## What differs on native
|
|
165
|
+
|
|
166
|
+
React Native has no CSS cascade, so a fixed subset of modifiers is
|
|
167
|
+
supported — `dark:`, `sm:`–`2xl:`, `active:`, `hover:`, `focus:`,
|
|
168
|
+
`disabled:`, and `data-[…]:`/`aria-[…]:`. `group-*`/`peer-*`/`has-[…]` and
|
|
169
|
+
container queries parse without error but do not apply. When two classes
|
|
170
|
+
set the same property the more-specific one wins regardless of source
|
|
171
|
+
order (`dark:bg-black bg-white` → black in dark mode).
|
|
172
|
+
|
|
173
|
+
`hover:` only fires for pointer-capable input (mouse/trackpad) — it's
|
|
174
|
+
inert on pure touch, so don't expect it to do anything on a phone/tablet
|
|
175
|
+
with no attached pointer.
|
|
176
|
+
|
|
177
|
+
`disabled:`/`aria-[…]:`/`data-[…]:` read that exact element's own props —
|
|
178
|
+
never a parent's, since there's no `group-disabled:`-style cascade to
|
|
179
|
+
inherit through. `<Pressable disabled><Text className="disabled:text-gray-5">`
|
|
180
|
+
does nothing to the `Text`, silently, because `Text` never received a
|
|
181
|
+
`disabled` prop of its own; the prop has to be repeated on whichever
|
|
182
|
+
element the modifier is written on:
|
|
183
|
+
`<Pressable disabled><Text disabled className="disabled:text-gray-5">`.
|
|
184
|
+
|
|
185
|
+
Expo Go, and iOS in ANY build type (no native engine there yet — see the
|
|
186
|
+
callout at the top), cover the same documented subset of utilities (no
|
|
187
|
+
grid, filters, gradients, or DOM-only typography). Expo Web and a real
|
|
188
|
+
**Android** dev-client/CLI build cover the full set.
|
|
189
|
+
|
|
190
|
+
A malformed or misused value fails safely — a deduped, dev-only
|
|
191
|
+
`console.warn` naming the offending class and the fix, never a crash or
|
|
192
|
+
silently-wrong output. Confirmed across CSS-injection attempts, invalid
|
|
193
|
+
`calc()` operands, and double-mounting.
|
|
194
|
+
|
|
195
|
+
`clsx()` — this package's own bundled copy, `import { clsx } from
|
|
196
|
+
'@kbach/react-native'` — composes conditional class strings the same way
|
|
197
|
+
the standalone `clsx` package does. You don't need it for `dark:`/`sm:`/
|
|
198
|
+
etc. (those work as plain classes), but it's there for `isActive &&
|
|
199
|
+
'bg-blue-6'`-style composition.
|
|
200
|
+
|
|
201
|
+
See [this package's own AGENTS.md](https://github.com/semsakadanupol/kbach/blob/main/packages/react-native/AGENTS.md)
|
|
202
|
+
for the complete reference — modifier list, `calc()`/`min()`/`max()`/
|
|
203
|
+
`clamp()` support, dynamic tokens, monorepo setup, and failure modes; see
|
|
204
|
+
the [root AGENTS.md](https://github.com/semsakadanupol/kbach/blob/main/AGENTS.md)
|
|
205
|
+
for `kbach.config.js` and how the underlying engine is built.
|
|
206
|
+
|
|
207
|
+
<!-- kbach:ai-rules:start -->
|
|
208
|
+
## For AI assistants
|
|
209
|
+
|
|
210
|
+
AI models learned Tailwind CSS, not Kbach. Give your assistant these rules (they're also in `llms.txt` in this package, and `npx @kbach/cli ai` writes them into your project's `AGENTS.md`):
|
|
211
|
+
|
|
212
|
+
```text
|
|
213
|
+
Kbach rules. Follow them in every class you write.
|
|
214
|
+
|
|
215
|
+
1. Color shades go from 1 (lightest) to 12 (darkest). Never use 50 to 950.
|
|
216
|
+
Convert: 50→1 100→2 200→3 300→4 400→5 500→6 600→7 700→8 800→9 900→10 950→11.
|
|
217
|
+
Write bg-blue-6, text-gray-11, border-slate-3. Never bg-blue-500.
|
|
218
|
+
2. Color families: amber blue cyan emerald fuchsia gray green indigo lime
|
|
219
|
+
mauve mist neutral olive orange pink purple red rose sky slate stone taupe
|
|
220
|
+
teal violet yellow zinc. Single colors: white black transparent current
|
|
221
|
+
gold silver bronze copper coal.
|
|
222
|
+
3. Every other class follows Tailwind CSS v4.3 names and values: spacing in
|
|
223
|
+
steps of 4px (p-4 is 16px), variants such as hover:, md: and dark:,
|
|
224
|
+
values in square brackets, a slash for opacity (bg-black/50).
|
|
225
|
+
Gradients: bg-linear-to-r from-* via-* to-*.
|
|
226
|
+
4. There is no tailwind.config.js, no @tailwind, no @import "tailwindcss",
|
|
227
|
+
no @theme and no @apply. Settings go in kbach.config.js
|
|
228
|
+
(export default { darkMode, theme, extend }). Custom animations go in
|
|
229
|
+
extend.keyframes and extend.animation and are used as animate-<name>.
|
|
230
|
+
5. Plain HTML page: put <script>window.kbachConfig = { ... }</script> BEFORE
|
|
231
|
+
<script src="https://cdn.jsdelivr.net/npm/@kbach/browser"></script>.
|
|
232
|
+
A theme button calls Kbach.toggle() and needs darkMode: 'class' or
|
|
233
|
+
'attribute' in that config.
|
|
234
|
+
6. React with Vite: import { kbach } from '@kbach/react/vite' and add kbach()
|
|
235
|
+
to plugins; import './kbach.css' once in the entry file. Write every class
|
|
236
|
+
in full: never build one from pieces like 'bg-' + color.
|
|
237
|
+
7. React Native: '@kbach/react-native/babel-plugin' must be in
|
|
238
|
+
babel.config.js. On a phone there is no grid, no gradients, no filters, no
|
|
239
|
+
transitions or animations, no group-*, peer-*, before: or after:. Use
|
|
240
|
+
flex-row for rows (a View is a column). Values in brackets: px or rem only.
|
|
241
|
+
8. Dark mode switches use useTheme() from '@kbach/react' or
|
|
242
|
+
'@kbach/react-native': { mode, isDark, setMode, toggle }.
|
|
243
|
+
|
|
244
|
+
Full documentation: https://kbach.vercel.app
|
|
245
|
+
```
|
|
246
|
+
<!-- kbach:ai-rules:end -->
|
|
124
247
|
|
|
125
248
|
## License
|
|
126
249
|
|
|
127
250
|
MIT
|
|
251
|
+
|
|
252
|
+
Tailwind CSS is a trademark of Tailwind Labs Inc. Kbach is an independent
|
|
253
|
+
project and is not affiliated with, sponsored by, or endorsed by Tailwind Labs.
|
|
254
|
+
See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for the Tailwind CSS
|
|
255
|
+
license notice.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!-- GENERATED from the repo root THIRD_PARTY_NOTICES.md by packages/core-engine/scripts/generate-notices.mjs. Edit the root file, then regenerate. -->
|
|
2
|
+
|
|
3
|
+
# Third-party notices
|
|
4
|
+
|
|
5
|
+
Kbach is MIT-licensed (see `LICENSE`). It also contains material from the
|
|
6
|
+
project below, used under that project's license.
|
|
7
|
+
|
|
8
|
+
## Tailwind CSS
|
|
9
|
+
|
|
10
|
+
Kbach uses Tailwind CSS-compatible utility class names, and some of its
|
|
11
|
+
default theme values (for example the spacing formula and the shadow, radius,
|
|
12
|
+
blur, and line-height scales) are derived from Tailwind CSS.
|
|
13
|
+
|
|
14
|
+
Tailwind CSS is a trademark of Tailwind Labs Inc. Kbach is an independent
|
|
15
|
+
project and is not affiliated with, sponsored by, or endorsed by Tailwind Labs.
|
|
16
|
+
|
|
17
|
+
Source: https://github.com/tailwindlabs/tailwindcss
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
MIT License
|
|
21
|
+
|
|
22
|
+
Copyright (c) Tailwind Labs, Inc.
|
|
23
|
+
|
|
24
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
25
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
26
|
+
in the Software without restriction, including without limitation the rights
|
|
27
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
28
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
29
|
+
furnished to do so, subject to the following conditions:
|
|
30
|
+
|
|
31
|
+
The above copyright notice and this permission notice shall be included in all
|
|
32
|
+
copies or substantial portions of the Software.
|
|
33
|
+
|
|
34
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
35
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
36
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
37
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
38
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
39
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
40
|
+
SOFTWARE.
|
|
41
|
+
```
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getTheme
|
|
3
|
+
} from "./chunk-MUPEQJRT.mjs";
|
|
4
|
+
|
|
5
|
+
// src/darkModeStore.ts
|
|
6
|
+
import { Appearance } from "react-native";
|
|
7
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
8
|
+
function systemPrefersDark() {
|
|
9
|
+
return Appearance.getColorScheme() === "dark";
|
|
10
|
+
}
|
|
11
|
+
function resolveIsDark(m) {
|
|
12
|
+
return m === "system" ? systemPrefersDark() : m === "dark";
|
|
13
|
+
}
|
|
14
|
+
function applyToDom(dark) {
|
|
15
|
+
if (typeof document === "undefined") return;
|
|
16
|
+
const root = document.documentElement;
|
|
17
|
+
const strategy = getTheme().darkMode;
|
|
18
|
+
root.classList.toggle("dark", strategy === "class" && dark);
|
|
19
|
+
root.classList.toggle("light", strategy === "class" && !dark);
|
|
20
|
+
if (strategy === "attribute") {
|
|
21
|
+
root.setAttribute("data-theme", dark ? "dark" : "light");
|
|
22
|
+
} else {
|
|
23
|
+
root.removeAttribute("data-theme");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
var mode = "system";
|
|
27
|
+
var isDark = resolveIsDark(mode);
|
|
28
|
+
applyToDom(isDark);
|
|
29
|
+
var hasExplicitChoice = false;
|
|
30
|
+
var subscription = Appearance.addChangeListener(({ colorScheme }) => {
|
|
31
|
+
if (mode !== "system") return;
|
|
32
|
+
isDark = colorScheme === "dark";
|
|
33
|
+
applyToDom(isDark);
|
|
34
|
+
notify();
|
|
35
|
+
});
|
|
36
|
+
function notify() {
|
|
37
|
+
for (const listener of listeners) listener();
|
|
38
|
+
}
|
|
39
|
+
function resyncDomWithActiveTheme() {
|
|
40
|
+
applyToDom(isDark);
|
|
41
|
+
}
|
|
42
|
+
function getGlobalDarkMode() {
|
|
43
|
+
return isDark;
|
|
44
|
+
}
|
|
45
|
+
function getGlobalThemeMode() {
|
|
46
|
+
return mode;
|
|
47
|
+
}
|
|
48
|
+
function setGlobalThemeMode(nextMode) {
|
|
49
|
+
mode = nextMode;
|
|
50
|
+
isDark = resolveIsDark(nextMode);
|
|
51
|
+
hasExplicitChoice = true;
|
|
52
|
+
applyToDom(isDark);
|
|
53
|
+
notify();
|
|
54
|
+
}
|
|
55
|
+
function toggleGlobalDarkMode() {
|
|
56
|
+
setGlobalThemeMode(isDark ? "light" : "dark");
|
|
57
|
+
}
|
|
58
|
+
function subscribeGlobalDarkMode(listener) {
|
|
59
|
+
listeners.add(listener);
|
|
60
|
+
return () => listeners.delete(listener);
|
|
61
|
+
}
|
|
62
|
+
function seedDefaultMode(fallback) {
|
|
63
|
+
if (hasExplicitChoice || mode === fallback) return;
|
|
64
|
+
mode = fallback;
|
|
65
|
+
isDark = resolveIsDark(fallback);
|
|
66
|
+
applyToDom(isDark);
|
|
67
|
+
notify();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/dynamicTokens.ts
|
|
71
|
+
var tokens = /* @__PURE__ */ new Map();
|
|
72
|
+
var listeners2 = /* @__PURE__ */ new Set();
|
|
73
|
+
var version = 0;
|
|
74
|
+
function applyToDom2(name, value) {
|
|
75
|
+
if (typeof document === "undefined") return;
|
|
76
|
+
document.documentElement.style.setProperty(`--${name}`, value);
|
|
77
|
+
}
|
|
78
|
+
function notify2() {
|
|
79
|
+
version++;
|
|
80
|
+
for (const listener of listeners2) listener();
|
|
81
|
+
}
|
|
82
|
+
function setDynamicToken(name, value) {
|
|
83
|
+
tokens.set(name, value);
|
|
84
|
+
applyToDom2(name, value);
|
|
85
|
+
notify2();
|
|
86
|
+
}
|
|
87
|
+
function getDynamicToken(name) {
|
|
88
|
+
return tokens.get(name);
|
|
89
|
+
}
|
|
90
|
+
function deleteDynamicToken(name) {
|
|
91
|
+
if (!tokens.delete(name)) return;
|
|
92
|
+
if (typeof document !== "undefined") document.documentElement.style.removeProperty(`--${name}`);
|
|
93
|
+
notify2();
|
|
94
|
+
}
|
|
95
|
+
function subscribeDynamicTokens(listener) {
|
|
96
|
+
listeners2.add(listener);
|
|
97
|
+
return () => listeners2.delete(listener);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export {
|
|
101
|
+
resyncDomWithActiveTheme,
|
|
102
|
+
getGlobalDarkMode,
|
|
103
|
+
getGlobalThemeMode,
|
|
104
|
+
setGlobalThemeMode,
|
|
105
|
+
toggleGlobalDarkMode,
|
|
106
|
+
subscribeGlobalDarkMode,
|
|
107
|
+
seedDefaultMode,
|
|
108
|
+
setDynamicToken,
|
|
109
|
+
getDynamicToken,
|
|
110
|
+
deleteDynamicToken,
|
|
111
|
+
subscribeDynamicTokens
|
|
112
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveClassName
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MUPEQJRT.mjs";
|
|
4
4
|
|
|
5
5
|
// src/jsxRuntimeCoreWeb.ts
|
|
6
6
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -18,7 +18,7 @@ function processElement(resolveClassName2, type, rawProps, key, isStaticChildren
|
|
|
18
18
|
}
|
|
19
19
|
const resolved = resolveClassName2(classStrRaw);
|
|
20
20
|
const dataSet = { ...userDataSet, kb: resolved };
|
|
21
|
-
return makeElement(isStaticChildren, type, { ...rest, dataSet }, key);
|
|
21
|
+
return makeElement(isStaticChildren, type, { ...rest, className: classStrRaw, dataSet }, key);
|
|
22
22
|
}
|
|
23
23
|
function createJsxFunctionsWeb(resolveClassName2) {
|
|
24
24
|
function jsx2(type, props, key) {
|