rnwind 0.0.10 → 0.0.11

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.
@@ -124,6 +124,8 @@ export declare class TailwindParser {
124
124
  private readonly config;
125
125
  private readonly scanner;
126
126
  private compiler;
127
+ /** Full resolved base theme (built-in palette + user `@theme`), colors lowered to sRGB. Source for `useColor` / `useToken`. */
128
+ private baseThemeTokens;
127
129
  private readonly themeSchemes;
128
130
  private readonly schemeAliases;
129
131
  /**
@@ -124,6 +124,8 @@ export declare class TailwindParser {
124
124
  private readonly config;
125
125
  private readonly scanner;
126
126
  private compiler;
127
+ /** Full resolved base theme (built-in palette + user `@theme`), colors lowered to sRGB. Source for `useColor` / `useToken`. */
128
+ private baseThemeTokens;
127
129
  private readonly themeSchemes;
128
130
  private readonly schemeAliases;
129
131
  /**
@@ -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