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.
Files changed (47) hide show
  1. package/lib/cjs/core/parser/tw-parser.cjs +43 -1
  2. package/lib/cjs/core/parser/tw-parser.cjs.map +1 -1
  3. package/lib/cjs/core/parser/tw-parser.d.ts +20 -0
  4. package/lib/cjs/core/style-builder/build-style.cjs +12 -3
  5. package/lib/cjs/core/style-builder/build-style.cjs.map +1 -1
  6. package/lib/cjs/core/style-builder/build-style.d.ts +3 -1
  7. package/lib/cjs/core/style-builder/union-builder.cjs +9 -1
  8. package/lib/cjs/core/style-builder/union-builder.cjs.map +1 -1
  9. package/lib/cjs/core/style-builder/union-builder.d.ts +7 -0
  10. package/lib/cjs/runtime/hooks/use-scheme.cjs +8 -5
  11. package/lib/cjs/runtime/hooks/use-scheme.cjs.map +1 -1
  12. package/lib/cjs/runtime/index.cjs +1 -0
  13. package/lib/cjs/runtime/index.cjs.map +1 -1
  14. package/lib/cjs/runtime/index.d.ts +1 -1
  15. package/lib/cjs/runtime/lookup-css.cjs +27 -0
  16. package/lib/cjs/runtime/lookup-css.cjs.map +1 -1
  17. package/lib/cjs/runtime/lookup-css.d.ts +18 -0
  18. package/lib/cjs/testing/index.cjs +1 -1
  19. package/lib/cjs/testing/index.cjs.map +1 -1
  20. package/lib/esm/core/parser/color.mjs +1 -1
  21. package/lib/esm/core/parser/tw-parser.d.ts +20 -0
  22. package/lib/esm/core/parser/tw-parser.mjs +44 -2
  23. package/lib/esm/core/parser/tw-parser.mjs.map +1 -1
  24. package/lib/esm/core/style-builder/build-style.d.ts +3 -1
  25. package/lib/esm/core/style-builder/build-style.mjs +12 -3
  26. package/lib/esm/core/style-builder/build-style.mjs.map +1 -1
  27. package/lib/esm/core/style-builder/union-builder.d.ts +7 -0
  28. package/lib/esm/core/style-builder/union-builder.mjs +9 -1
  29. package/lib/esm/core/style-builder/union-builder.mjs.map +1 -1
  30. package/lib/esm/runtime/hooks/use-scheme.mjs +8 -5
  31. package/lib/esm/runtime/hooks/use-scheme.mjs.map +1 -1
  32. package/lib/esm/runtime/index.d.ts +1 -1
  33. package/lib/esm/runtime/index.mjs +1 -1
  34. package/lib/esm/runtime/index.mjs.map +1 -1
  35. package/lib/esm/runtime/lookup-css.d.ts +18 -0
  36. package/lib/esm/runtime/lookup-css.mjs +26 -1
  37. package/lib/esm/runtime/lookup-css.mjs.map +1 -1
  38. package/lib/esm/testing/index.mjs +2 -2
  39. package/lib/esm/testing/index.mjs.map +1 -1
  40. package/package.json +1 -1
  41. package/src/core/parser/tw-parser.ts +53 -1
  42. package/src/core/style-builder/build-style.ts +12 -1
  43. package/src/core/style-builder/union-builder.ts +10 -1
  44. package/src/runtime/hooks/use-scheme.ts +8 -4
  45. package/src/runtime/index.ts +1 -0
  46. package/src/runtime/lookup-css.ts +28 -0
  47. package/src/testing/index.ts +3 -0
@@ -148,6 +148,33 @@ class TailwindParser {
148
148
  merged.set(k, v);
149
149
  return merged;
150
150
  }
151
+ /**
152
+ * Build the per-scheme theme token tables for `registerThemeTokens` —
153
+ * the data source for `useColor` / `useToken` / `useSize`. Emits one table
154
+ * per scheme the user wrote tokens under (`base` + each variant block /
155
+ * `.dark` override). `--color-*` values are lowered to sRGB (matching the
156
+ * className path) using `resolver` so a wide-gamut or `var()`-referencing
157
+ * token resolves to an RN-renderable string; other tokens pass through.
158
+ * @param resolver Full compiled `:root` table, for resolving `var()` refs.
159
+ * @returns Scheme → (token name → value) map.
160
+ */
161
+ buildThemeTokens(resolver) {
162
+ const out = {};
163
+ for (const scheme of this.themeSchemes.keys()) {
164
+ const userTable = this.themeSchemes.get(scheme);
165
+ if (!userTable || userTable.size === 0)
166
+ continue;
167
+ const schemeResolver = new Map(resolver);
168
+ for (const [k, v] of this.effectiveVars(scheme))
169
+ schemeResolver.set(k, v);
170
+ const table = {};
171
+ for (const [name, raw] of userTable) {
172
+ table[name] = name.startsWith('--color-') ? lowerColorToken(raw, schemeResolver) : raw;
173
+ }
174
+ out[scheme] = table;
175
+ }
176
+ return out;
177
+ }
151
178
  /**
152
179
  * Build the Tailwind compiler on first use and cache it. The theme CSS
153
180
  * gets a `theme(inline)` modifier on its `@import 'tailwindcss'` so
@@ -339,9 +366,23 @@ class TailwindParser {
339
366
  if (!referencedKeyframes.has(name))
340
367
  keyframes$1.delete(name);
341
368
  }
342
- return { atoms, keyframes: keyframes$1, propertyDefaults, gradientAtoms, hapticAtoms, candidates: [...candidates], schemes, breakpoints };
369
+ const themeTokens = this.buildThemeTokens(compiledTheme);
370
+ return { atoms, keyframes: keyframes$1, propertyDefaults, gradientAtoms, hapticAtoms, candidates: [...candidates], schemes, breakpoints, themeTokens };
343
371
  }
344
372
  }
373
+ /**
374
+ * Lower a `--color-*` token value to an RN-renderable sRGB string, matching
375
+ * the className path: resolve any `var()` ref via `resolver`, then lower a
376
+ * wide-gamut form (`oklch(…)`, `lab(…)`, `color(p3 …)`) to sRGB. Hex / rgb /
377
+ * named colors pass through unchanged.
378
+ * @param raw Raw token value.
379
+ * @param resolver Var name → value table for resolving `var()` references.
380
+ * @returns RN-safe color string.
381
+ */
382
+ function lowerColorToken(raw, resolver) {
383
+ const substituted = tokens.substituteThemeVars(raw, resolver);
384
+ return color.normalizeColorString(substituted) ?? substituted;
385
+ }
345
386
  /**
346
387
  * Wrap an error from `@tailwindcss/node`'s compiler or `lightningcss`'s
347
388
  * transform with a `rnwind:` prefix so the user sees a clear "this came
@@ -388,6 +429,7 @@ function emptyOutput() {
388
429
  candidates: [],
389
430
  schemes: [themeVars.BASE_SCHEME],
390
431
  breakpoints: new Map(),
432
+ themeTokens: {},
391
433
  };
392
434
  }
393
435
  /**