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
|
@@ -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
|
-
|
|
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
|
/**
|