rnwind 0.0.10 → 0.0.12
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/normalize-classname.cjs +3 -1
- package/lib/cjs/core/normalize-classname.cjs.map +1 -1
- package/lib/cjs/core/parser/border-dispatcher.cjs +20 -10
- package/lib/cjs/core/parser/border-dispatcher.cjs.map +1 -1
- package/lib/cjs/core/parser/color-properties-dispatcher.cjs +7 -5
- package/lib/cjs/core/parser/color-properties-dispatcher.cjs.map +1 -1
- package/lib/cjs/core/parser/color.cjs +194 -10
- package/lib/cjs/core/parser/color.cjs.map +1 -1
- package/lib/cjs/core/parser/color.d.ts +18 -3
- package/lib/cjs/core/parser/declaration.cjs +62 -4
- package/lib/cjs/core/parser/declaration.cjs.map +1 -1
- package/lib/cjs/core/parser/layout-dispatcher.cjs +32 -2
- package/lib/cjs/core/parser/layout-dispatcher.cjs.map +1 -1
- package/lib/cjs/core/parser/shorthand.cjs +10 -3
- package/lib/cjs/core/parser/shorthand.cjs.map +1 -1
- package/lib/cjs/core/parser/tokens.cjs +9 -0
- package/lib/cjs/core/parser/tokens.cjs.map +1 -1
- package/lib/cjs/core/parser/tw-parser.cjs +89 -2
- package/lib/cjs/core/parser/tw-parser.cjs.map +1 -1
- package/lib/cjs/core/parser/tw-parser.d.ts +2 -0
- package/lib/cjs/core/parser/typography-dispatcher.cjs +15 -8
- package/lib/cjs/core/parser/typography-dispatcher.cjs.map +1 -1
- package/lib/cjs/core/style-builder/union-builder.cjs +81 -2
- package/lib/cjs/core/style-builder/union-builder.cjs.map +1 -1
- package/lib/cjs/core/style-builder/union-builder.d.ts +28 -0
- package/lib/cjs/metro/state.cjs +74 -13
- package/lib/cjs/metro/state.cjs.map +1 -1
- package/lib/cjs/metro/state.d.ts +18 -0
- package/lib/cjs/metro/transformer.cjs +10 -4
- package/lib/cjs/metro/transformer.cjs.map +1 -1
- package/lib/cjs/metro/with-config.cjs +57 -0
- package/lib/cjs/metro/with-config.cjs.map +1 -1
- package/lib/cjs/metro/with-config.d.ts +12 -0
- package/lib/cjs/metro/wrap-imports.cjs +36 -1
- package/lib/cjs/metro/wrap-imports.cjs.map +1 -1
- package/lib/cjs/runtime/hooks/use-scheme.cjs +14 -7
- package/lib/cjs/runtime/hooks/use-scheme.cjs.map +1 -1
- package/lib/cjs/runtime/resolve.cjs +6 -2
- package/lib/cjs/runtime/resolve.cjs.map +1 -1
- package/lib/cjs/runtime/resolve.d.ts +5 -1
- package/lib/esm/core/normalize-classname.mjs +3 -1
- package/lib/esm/core/normalize-classname.mjs.map +1 -1
- package/lib/esm/core/parser/border-dispatcher.mjs +21 -11
- package/lib/esm/core/parser/border-dispatcher.mjs.map +1 -1
- package/lib/esm/core/parser/color-properties-dispatcher.mjs +8 -6
- package/lib/esm/core/parser/color-properties-dispatcher.mjs.map +1 -1
- package/lib/esm/core/parser/color.d.ts +18 -3
- package/lib/esm/core/parser/color.mjs +195 -12
- package/lib/esm/core/parser/color.mjs.map +1 -1
- package/lib/esm/core/parser/declaration.mjs +63 -5
- package/lib/esm/core/parser/declaration.mjs.map +1 -1
- package/lib/esm/core/parser/layout-dispatcher.mjs +32 -2
- package/lib/esm/core/parser/layout-dispatcher.mjs.map +1 -1
- package/lib/esm/core/parser/shorthand.mjs +11 -4
- package/lib/esm/core/parser/shorthand.mjs.map +1 -1
- package/lib/esm/core/parser/tokens.mjs +10 -1
- package/lib/esm/core/parser/tokens.mjs.map +1 -1
- package/lib/esm/core/parser/tw-parser.d.ts +2 -0
- package/lib/esm/core/parser/tw-parser.mjs +69 -0
- package/lib/esm/core/parser/tw-parser.mjs.map +1 -1
- package/lib/esm/core/parser/typography-dispatcher.mjs +15 -8
- package/lib/esm/core/parser/typography-dispatcher.mjs.map +1 -1
- package/lib/esm/core/style-builder/union-builder.d.ts +28 -0
- package/lib/esm/core/style-builder/union-builder.mjs +82 -3
- package/lib/esm/core/style-builder/union-builder.mjs.map +1 -1
- package/lib/esm/metro/state.d.ts +18 -0
- package/lib/esm/metro/state.mjs +75 -14
- package/lib/esm/metro/state.mjs.map +1 -1
- package/lib/esm/metro/transformer.mjs +10 -4
- package/lib/esm/metro/transformer.mjs.map +1 -1
- package/lib/esm/metro/with-config.d.ts +12 -0
- package/lib/esm/metro/with-config.mjs +58 -2
- package/lib/esm/metro/with-config.mjs.map +1 -1
- package/lib/esm/metro/wrap-imports.mjs +36 -1
- package/lib/esm/metro/wrap-imports.mjs.map +1 -1
- package/lib/esm/runtime/hooks/use-scheme.mjs +14 -7
- package/lib/esm/runtime/hooks/use-scheme.mjs.map +1 -1
- package/lib/esm/runtime/resolve.d.ts +5 -1
- package/lib/esm/runtime/resolve.mjs +6 -2
- package/lib/esm/runtime/resolve.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/normalize-classname.ts +4 -1
- package/src/core/parser/border-dispatcher.ts +22 -11
- package/src/core/parser/color-properties-dispatcher.ts +7 -5
- package/src/core/parser/color.ts +182 -11
- package/src/core/parser/declaration.ts +61 -5
- package/src/core/parser/layout-dispatcher.ts +34 -2
- package/src/core/parser/shorthand.ts +9 -3
- package/src/core/parser/tokens.ts +10 -1
- package/src/core/parser/tw-parser.ts +71 -1
- package/src/core/parser/typography-dispatcher.ts +15 -6
- package/src/core/style-builder/union-builder.ts +83 -3
- package/src/metro/state.ts +117 -12
- package/src/metro/transformer.ts +9 -4
- package/src/metro/with-config.ts +59 -1
- package/src/metro/wrap-imports.ts +36 -1
- package/src/runtime/hooks/use-scheme.ts +13 -6
- package/src/runtime/resolve.ts +6 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as tailwindNode from '@tailwindcss/node';
|
|
1
2
|
import { compile } from '@tailwindcss/node';
|
|
2
3
|
import { Scanner } from '@tailwindcss/oxide';
|
|
3
4
|
import { formatHex } from 'culori';
|
|
@@ -59,6 +60,8 @@ class TailwindParser {
|
|
|
59
60
|
config;
|
|
60
61
|
scanner;
|
|
61
62
|
compiler;
|
|
63
|
+
/** Full resolved base theme (built-in palette + user `@theme`), colors lowered to sRGB. Source for `useColor` / `useToken`. */
|
|
64
|
+
baseThemeTokens = null;
|
|
62
65
|
themeSchemes;
|
|
63
66
|
schemeAliases;
|
|
64
67
|
/**
|
|
@@ -158,7 +161,16 @@ class TailwindParser {
|
|
|
158
161
|
*/
|
|
159
162
|
buildThemeTokens(resolver) {
|
|
160
163
|
const out = {};
|
|
164
|
+
// BASE: the full resolved theme (built-in palette + user `@theme`). The
|
|
165
|
+
// runtime merges this under the active scheme, so `useColor('pink-500')`
|
|
166
|
+
// and `useColor('<your-token>')` both resolve in every scheme.
|
|
167
|
+
if (this.baseThemeTokens)
|
|
168
|
+
out[BASE_SCHEME] = this.baseThemeTokens;
|
|
169
|
+
// VARIANTS: only the per-scheme overrides the user wrote (`.dark { … }` /
|
|
170
|
+
// `@variant dark { … }`) — they layer on top of base at runtime.
|
|
161
171
|
for (const scheme of this.themeSchemes.keys()) {
|
|
172
|
+
if (scheme === BASE_SCHEME)
|
|
173
|
+
continue;
|
|
162
174
|
const userTable = this.themeSchemes.get(scheme);
|
|
163
175
|
if (!userTable || userTable.size === 0)
|
|
164
176
|
continue;
|
|
@@ -192,6 +204,13 @@ class TailwindParser {
|
|
|
192
204
|
catch (error) {
|
|
193
205
|
throw wrapThemeError(error);
|
|
194
206
|
}
|
|
207
|
+
// Load the resolved design system ONCE to capture the FULL theme — the
|
|
208
|
+
// built-in palette (`pink-500`, …) plus the user's `@theme` tokens — so
|
|
209
|
+
// `useColor` / `useToken` resolve any theme value, not just the utilities
|
|
210
|
+
// a class happened to use (Tailwind tree-shakes `:root`, so the compiled
|
|
211
|
+
// CSS alone never carries the full palette). Best-effort: a load failure
|
|
212
|
+
// just narrows the hooks to the user's own tokens.
|
|
213
|
+
this.baseThemeTokens = await loadBaseThemeTokens(ready);
|
|
195
214
|
return this.compiler;
|
|
196
215
|
}
|
|
197
216
|
/**
|
|
@@ -381,6 +400,50 @@ function lowerColorToken(raw, resolver) {
|
|
|
381
400
|
const substituted = substituteThemeVars(raw, resolver);
|
|
382
401
|
return normalizeColorString(substituted) ?? substituted;
|
|
383
402
|
}
|
|
403
|
+
/** Theme token families excluded from the registered base table — pure Tailwind internals with no `useColor`/`useToken` value. */
|
|
404
|
+
const INTERNAL_TOKEN_PREFIXES = ['--tw-', '--default-'];
|
|
405
|
+
/**
|
|
406
|
+
* `@tailwindcss/node`'s `__unstable__loadDesignSystem` — exists at runtime but
|
|
407
|
+
* isn't in the package's published types, so it's accessed through a narrowed
|
|
408
|
+
* cast rather than a named import. Returns `undefined` when the (unstable) API
|
|
409
|
+
* isn't present, so {@link loadBaseThemeTokens} degrades gracefully.
|
|
410
|
+
*/
|
|
411
|
+
const loadDesignSystem = tailwindNode.__unstable__loadDesignSystem;
|
|
412
|
+
/**
|
|
413
|
+
* Load the FULL resolved Tailwind theme (built-in palette + the user's
|
|
414
|
+
* `@theme`) via the design-system API and flatten it to an RN-safe token
|
|
415
|
+
* table — `--color-*` values lowered to sRGB, everything else passed through.
|
|
416
|
+
* This is what lets `useColor` / `useToken` resolve ANY theme token, including
|
|
417
|
+
* built-ins a class never used (Tailwind tree-shakes the compiled `:root`, so
|
|
418
|
+
* the compiled CSS alone can't supply the full palette). Internal `--tw-*` /
|
|
419
|
+
* `--default-*` families are dropped. Returns `null` on any failure so the
|
|
420
|
+
* caller degrades to the user's own `@theme` tokens.
|
|
421
|
+
* @param themeCss Compile-ready theme CSS (variants stripped, custom-variants added).
|
|
422
|
+
* @returns Flattened base token table, or null.
|
|
423
|
+
*/
|
|
424
|
+
async function loadBaseThemeTokens(themeCss) {
|
|
425
|
+
if (typeof loadDesignSystem !== 'function')
|
|
426
|
+
return null;
|
|
427
|
+
try {
|
|
428
|
+
const design = await loadDesignSystem(themeCss, { base: process.cwd() });
|
|
429
|
+
const entries = design.theme?.entries?.();
|
|
430
|
+
if (!entries)
|
|
431
|
+
return null;
|
|
432
|
+
const table = {};
|
|
433
|
+
for (const [name, entry] of entries) {
|
|
434
|
+
const raw = entry?.value;
|
|
435
|
+
if (typeof raw !== 'string')
|
|
436
|
+
continue;
|
|
437
|
+
if (INTERNAL_TOKEN_PREFIXES.some((prefix) => name.startsWith(prefix)))
|
|
438
|
+
continue;
|
|
439
|
+
table[name] = name.startsWith('--color-') ? (normalizeColorString(raw) ?? raw) : raw;
|
|
440
|
+
}
|
|
441
|
+
return table;
|
|
442
|
+
}
|
|
443
|
+
catch {
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
384
447
|
/**
|
|
385
448
|
* Wrap an error from `@tailwindcss/node`'s compiler or `lightningcss`'s
|
|
386
449
|
* transform with a `rnwind:` prefix so the user sees a clear "this came
|
|
@@ -1145,6 +1208,12 @@ function parseRgbaExpression(text) {
|
|
|
1145
1208
|
if (typeof alphaText === 'string') {
|
|
1146
1209
|
opacity = alphaText.endsWith('%') ? Number(alphaText.slice(0, -1)) / 100 : Number(alphaText);
|
|
1147
1210
|
}
|
|
1211
|
+
// CSS Color 4: a `none` (or otherwise non-numeric) alpha parses to NaN here.
|
|
1212
|
+
// Its used value when compositing is 0 (fully transparent) — and crucially
|
|
1213
|
+
// RN throws on a NaN `shadowOpacity`, so collapse any non-finite alpha to 0
|
|
1214
|
+
// before it can reach a numeric style prop.
|
|
1215
|
+
if (!Number.isFinite(opacity))
|
|
1216
|
+
opacity = 0;
|
|
1148
1217
|
const hex = `#${[r, g, b]
|
|
1149
1218
|
.map((n) => Math.max(0, Math.min(255, Math.round(Number(n))))
|
|
1150
1219
|
.toString(16)
|