rnwind 0.0.9 → 0.0.10
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/lib/cjs/core/parser/tw-parser.cjs +43 -1
- package/lib/cjs/core/parser/tw-parser.cjs.map +1 -1
- package/lib/cjs/core/parser/tw-parser.d.ts +20 -0
- package/lib/cjs/core/style-builder/build-style.cjs +12 -3
- package/lib/cjs/core/style-builder/build-style.cjs.map +1 -1
- package/lib/cjs/core/style-builder/build-style.d.ts +3 -1
- package/lib/cjs/core/style-builder/union-builder.cjs +9 -1
- package/lib/cjs/core/style-builder/union-builder.cjs.map +1 -1
- package/lib/cjs/core/style-builder/union-builder.d.ts +7 -0
- package/lib/cjs/runtime/hooks/use-scheme.cjs +8 -5
- package/lib/cjs/runtime/hooks/use-scheme.cjs.map +1 -1
- package/lib/cjs/runtime/index.cjs +1 -0
- package/lib/cjs/runtime/index.cjs.map +1 -1
- package/lib/cjs/runtime/index.d.ts +1 -1
- package/lib/cjs/runtime/lookup-css.cjs +27 -0
- package/lib/cjs/runtime/lookup-css.cjs.map +1 -1
- package/lib/cjs/runtime/lookup-css.d.ts +18 -0
- package/lib/cjs/testing/index.cjs +1 -1
- package/lib/cjs/testing/index.cjs.map +1 -1
- package/lib/esm/core/parser/color.mjs +1 -1
- package/lib/esm/core/parser/tw-parser.d.ts +20 -0
- package/lib/esm/core/parser/tw-parser.mjs +44 -2
- package/lib/esm/core/parser/tw-parser.mjs.map +1 -1
- package/lib/esm/core/style-builder/build-style.d.ts +3 -1
- package/lib/esm/core/style-builder/build-style.mjs +12 -3
- package/lib/esm/core/style-builder/build-style.mjs.map +1 -1
- package/lib/esm/core/style-builder/union-builder.d.ts +7 -0
- package/lib/esm/core/style-builder/union-builder.mjs +9 -1
- package/lib/esm/core/style-builder/union-builder.mjs.map +1 -1
- package/lib/esm/runtime/hooks/use-scheme.mjs +8 -5
- package/lib/esm/runtime/hooks/use-scheme.mjs.map +1 -1
- package/lib/esm/runtime/index.d.ts +1 -1
- package/lib/esm/runtime/index.mjs +1 -1
- package/lib/esm/runtime/index.mjs.map +1 -1
- package/lib/esm/runtime/lookup-css.d.ts +18 -0
- package/lib/esm/runtime/lookup-css.mjs +26 -1
- package/lib/esm/runtime/lookup-css.mjs.map +1 -1
- package/lib/esm/testing/index.mjs +2 -2
- package/lib/esm/testing/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/parser/tw-parser.ts +53 -1
- package/src/core/style-builder/build-style.ts +12 -1
- package/src/core/style-builder/union-builder.ts +10 -1
- package/src/runtime/hooks/use-scheme.ts +8 -4
- package/src/runtime/index.ts +1 -0
- package/src/runtime/lookup-css.ts +28 -0
- package/src/testing/index.ts +3 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ThemeTable } from '../../core/types'
|
|
2
2
|
import { useRnwind } from '../components/rnwind-provider'
|
|
3
|
+
import { getThemeTokens } from '../lookup-css'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Synthetic scheme name applied when tokens aren't declared under any
|
|
@@ -20,10 +21,13 @@ const BASE_SCHEME = 'base'
|
|
|
20
21
|
*/
|
|
21
22
|
export function useTheme(): ThemeTable {
|
|
22
23
|
const { scheme, tables } = useRnwind()
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
// The build registers token tables on the manifest so `useColor` works out
|
|
25
|
+
// of the box; an explicit `tables` prop layers on top (the prop wins).
|
|
26
|
+
const registered = getThemeTokens()
|
|
27
|
+
const base = { ...registered[BASE_SCHEME], ...tables[BASE_SCHEME] }
|
|
28
|
+
const schemeTable = { ...registered[scheme], ...tables[scheme] }
|
|
29
|
+
// Base tokens apply everywhere (CSS `:root` cascade); the active scheme's
|
|
30
|
+
// own entries override on overlap.
|
|
27
31
|
if (Object.keys(schemeTable).length === 0) return base
|
|
28
32
|
return { ...base, ...schemeTable }
|
|
29
33
|
}
|
package/src/runtime/index.ts
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import type { RnwindState } from './components/rnwind-provider'
|
|
19
|
+
import type { ThemeTables } from '../core/types'
|
|
19
20
|
|
|
20
21
|
/** Empty sentinel returned when the input is null / undefined / empty. */
|
|
21
22
|
const EMPTY_STYLES: readonly unknown[] = []
|
|
@@ -62,6 +63,8 @@ const cache = {
|
|
|
62
63
|
atoms: Object.create(null) as Partial<Record<string, SchemeAtomsRecord>>,
|
|
63
64
|
breakpoints: Object.create(null) as Partial<Record<string, number>>,
|
|
64
65
|
breakpointList: [] as readonly BreakpointEntry[],
|
|
66
|
+
/** Per-scheme theme token tables (`--color-*`, `--spacing-*`, …) the manifest registers for `useColor` / `useToken` / `useSize`. */
|
|
67
|
+
themeTokens: {} as ThemeTables,
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
/**
|
|
@@ -553,6 +556,30 @@ export function getBreakpoints(): readonly BreakpointEntry[] {
|
|
|
553
556
|
return cache.breakpointList
|
|
554
557
|
}
|
|
555
558
|
|
|
559
|
+
/**
|
|
560
|
+
* Register the per-scheme theme token tables the manifest module emits at
|
|
561
|
+
* load time — the data source for `useColor` / `useToken` / `useSize`. The
|
|
562
|
+
* build lowers `--color-*` tokens to sRGB before registering them, so these
|
|
563
|
+
* are RN-safe. Replaces the prior tables; bumps `atomVersion` so a theme HMR
|
|
564
|
+
* cycle re-resolves. The build registers tokens here so the hooks work out of
|
|
565
|
+
* the box, without the user manually threading a `tables` prop on the provider.
|
|
566
|
+
* @param tables Scheme name → (token name → value) map.
|
|
567
|
+
*/
|
|
568
|
+
export function registerThemeTokens(tables: ThemeTables): void {
|
|
569
|
+
cache.themeTokens = tables
|
|
570
|
+
atomVersion += 1
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* The manifest-registered theme token tables. The provider merges these under
|
|
575
|
+
* any explicit `tables` prop (the prop wins), so `useColor` resolves from the
|
|
576
|
+
* build by default.
|
|
577
|
+
* @returns Registered per-scheme token tables.
|
|
578
|
+
*/
|
|
579
|
+
export function getThemeTokens(): ThemeTables {
|
|
580
|
+
return cache.themeTokens
|
|
581
|
+
}
|
|
582
|
+
|
|
556
583
|
/**
|
|
557
584
|
* Sentinel name returned by {@link activeBreakpointFor} ONLY when no
|
|
558
585
|
* breakpoints are registered at all (bundle without rnwind-transformed
|
|
@@ -635,6 +662,7 @@ export function __resetLookupCssState(): void {
|
|
|
635
662
|
for (const key of Object.keys(cache.atoms)) delete cache.atoms[key]
|
|
636
663
|
for (const key of Object.keys(cache.breakpoints)) delete cache.breakpoints[key]
|
|
637
664
|
cache.breakpointList = []
|
|
665
|
+
cache.themeTokens = {}
|
|
638
666
|
windowHeightProvider = null
|
|
639
667
|
schemeLoader = null
|
|
640
668
|
WARNED_MISSING_INSETS = false
|
package/src/testing/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
__resetLookupCssState,
|
|
18
18
|
registerAtoms,
|
|
19
19
|
registerBreakpoints,
|
|
20
|
+
registerThemeTokens,
|
|
20
21
|
registerSchemeLoader,
|
|
21
22
|
} from '../runtime/lookup-css'
|
|
22
23
|
import { __resetResolveState, registerGradients, registerHaptics, registerMolecules } from '../runtime/resolve'
|
|
@@ -159,6 +160,7 @@ function evaluateGeneratedFile(filePath: string): void {
|
|
|
159
160
|
'registerBreakpoints',
|
|
160
161
|
'registerGradients',
|
|
161
162
|
'registerHaptics',
|
|
163
|
+
'registerThemeTokens',
|
|
162
164
|
'registerSchemeLoader',
|
|
163
165
|
'require',
|
|
164
166
|
body,
|
|
@@ -169,6 +171,7 @@ function evaluateGeneratedFile(filePath: string): void {
|
|
|
169
171
|
registerBreakpoints,
|
|
170
172
|
registerGradients,
|
|
171
173
|
registerHaptics,
|
|
174
|
+
registerThemeTokens,
|
|
172
175
|
registerSchemeLoader,
|
|
173
176
|
() => {},
|
|
174
177
|
)
|