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.
- package/lib/cjs/core/parser/tw-parser.cjs +83 -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/esm/core/parser/tw-parser.d.ts +2 -0
- package/lib/esm/core/parser/tw-parser.mjs +63 -0
- package/lib/esm/core/parser/tw-parser.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/parser/tw-parser.ts +66 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var tailwindNode = require('@tailwindcss/node');
|
|
4
4
|
var oxide = require('@tailwindcss/oxide');
|
|
5
5
|
var culori = require('culori');
|
|
6
6
|
var lightningcss = require('lightningcss');
|
|
@@ -14,6 +14,25 @@ var themeVars = require('./theme-vars.cjs');
|
|
|
14
14
|
var tokens = require('./tokens.cjs');
|
|
15
15
|
var color = require('./color.cjs');
|
|
16
16
|
|
|
17
|
+
function _interopNamespaceDefault(e) {
|
|
18
|
+
var n = Object.create(null);
|
|
19
|
+
if (e) {
|
|
20
|
+
Object.keys(e).forEach(function (k) {
|
|
21
|
+
if (k !== 'default') {
|
|
22
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
23
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return e[k]; }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
n.default = e;
|
|
31
|
+
return Object.freeze(n);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var tailwindNode__namespace = /*#__PURE__*/_interopNamespaceDefault(tailwindNode);
|
|
35
|
+
|
|
17
36
|
/**
|
|
18
37
|
* Default LightningCSS transform options for TailwindParser's visitor.
|
|
19
38
|
* Its taken from official Tailwind source:
|
|
@@ -61,6 +80,8 @@ class TailwindParser {
|
|
|
61
80
|
config;
|
|
62
81
|
scanner;
|
|
63
82
|
compiler;
|
|
83
|
+
/** Full resolved base theme (built-in palette + user `@theme`), colors lowered to sRGB. Source for `useColor` / `useToken`. */
|
|
84
|
+
baseThemeTokens = null;
|
|
64
85
|
themeSchemes;
|
|
65
86
|
schemeAliases;
|
|
66
87
|
/**
|
|
@@ -160,7 +181,16 @@ class TailwindParser {
|
|
|
160
181
|
*/
|
|
161
182
|
buildThemeTokens(resolver) {
|
|
162
183
|
const out = {};
|
|
184
|
+
// BASE: the full resolved theme (built-in palette + user `@theme`). The
|
|
185
|
+
// runtime merges this under the active scheme, so `useColor('pink-500')`
|
|
186
|
+
// and `useColor('<your-token>')` both resolve in every scheme.
|
|
187
|
+
if (this.baseThemeTokens)
|
|
188
|
+
out[themeVars.BASE_SCHEME] = this.baseThemeTokens;
|
|
189
|
+
// VARIANTS: only the per-scheme overrides the user wrote (`.dark { … }` /
|
|
190
|
+
// `@variant dark { … }`) — they layer on top of base at runtime.
|
|
163
191
|
for (const scheme of this.themeSchemes.keys()) {
|
|
192
|
+
if (scheme === themeVars.BASE_SCHEME)
|
|
193
|
+
continue;
|
|
164
194
|
const userTable = this.themeSchemes.get(scheme);
|
|
165
195
|
if (!userTable || userTable.size === 0)
|
|
166
196
|
continue;
|
|
@@ -186,7 +216,7 @@ class TailwindParser {
|
|
|
186
216
|
return this.compiler;
|
|
187
217
|
const ready = themeVars.compileReadyTheme(this.config.themeCss, this.themeSchemes);
|
|
188
218
|
try {
|
|
189
|
-
this.compiler = await
|
|
219
|
+
this.compiler = await tailwindNode.compile(withInlineTheme(ready), {
|
|
190
220
|
base: process.cwd(),
|
|
191
221
|
onDependency: () => { },
|
|
192
222
|
});
|
|
@@ -194,6 +224,13 @@ class TailwindParser {
|
|
|
194
224
|
catch (error) {
|
|
195
225
|
throw wrapThemeError(error);
|
|
196
226
|
}
|
|
227
|
+
// Load the resolved design system ONCE to capture the FULL theme — the
|
|
228
|
+
// built-in palette (`pink-500`, …) plus the user's `@theme` tokens — so
|
|
229
|
+
// `useColor` / `useToken` resolve any theme value, not just the utilities
|
|
230
|
+
// a class happened to use (Tailwind tree-shakes `:root`, so the compiled
|
|
231
|
+
// CSS alone never carries the full palette). Best-effort: a load failure
|
|
232
|
+
// just narrows the hooks to the user's own tokens.
|
|
233
|
+
this.baseThemeTokens = await loadBaseThemeTokens(ready);
|
|
197
234
|
return this.compiler;
|
|
198
235
|
}
|
|
199
236
|
/**
|
|
@@ -383,6 +420,50 @@ function lowerColorToken(raw, resolver) {
|
|
|
383
420
|
const substituted = tokens.substituteThemeVars(raw, resolver);
|
|
384
421
|
return color.normalizeColorString(substituted) ?? substituted;
|
|
385
422
|
}
|
|
423
|
+
/** Theme token families excluded from the registered base table — pure Tailwind internals with no `useColor`/`useToken` value. */
|
|
424
|
+
const INTERNAL_TOKEN_PREFIXES = ['--tw-', '--default-'];
|
|
425
|
+
/**
|
|
426
|
+
* `@tailwindcss/node`'s `__unstable__loadDesignSystem` — exists at runtime but
|
|
427
|
+
* isn't in the package's published types, so it's accessed through a narrowed
|
|
428
|
+
* cast rather than a named import. Returns `undefined` when the (unstable) API
|
|
429
|
+
* isn't present, so {@link loadBaseThemeTokens} degrades gracefully.
|
|
430
|
+
*/
|
|
431
|
+
const loadDesignSystem = tailwindNode__namespace.__unstable__loadDesignSystem;
|
|
432
|
+
/**
|
|
433
|
+
* Load the FULL resolved Tailwind theme (built-in palette + the user's
|
|
434
|
+
* `@theme`) via the design-system API and flatten it to an RN-safe token
|
|
435
|
+
* table — `--color-*` values lowered to sRGB, everything else passed through.
|
|
436
|
+
* This is what lets `useColor` / `useToken` resolve ANY theme token, including
|
|
437
|
+
* built-ins a class never used (Tailwind tree-shakes the compiled `:root`, so
|
|
438
|
+
* the compiled CSS alone can't supply the full palette). Internal `--tw-*` /
|
|
439
|
+
* `--default-*` families are dropped. Returns `null` on any failure so the
|
|
440
|
+
* caller degrades to the user's own `@theme` tokens.
|
|
441
|
+
* @param themeCss Compile-ready theme CSS (variants stripped, custom-variants added).
|
|
442
|
+
* @returns Flattened base token table, or null.
|
|
443
|
+
*/
|
|
444
|
+
async function loadBaseThemeTokens(themeCss) {
|
|
445
|
+
if (typeof loadDesignSystem !== 'function')
|
|
446
|
+
return null;
|
|
447
|
+
try {
|
|
448
|
+
const design = await loadDesignSystem(themeCss, { base: process.cwd() });
|
|
449
|
+
const entries = design.theme?.entries?.();
|
|
450
|
+
if (!entries)
|
|
451
|
+
return null;
|
|
452
|
+
const table = {};
|
|
453
|
+
for (const [name, entry] of entries) {
|
|
454
|
+
const raw = entry?.value;
|
|
455
|
+
if (typeof raw !== 'string')
|
|
456
|
+
continue;
|
|
457
|
+
if (INTERNAL_TOKEN_PREFIXES.some((prefix) => name.startsWith(prefix)))
|
|
458
|
+
continue;
|
|
459
|
+
table[name] = name.startsWith('--color-') ? (color.normalizeColorString(raw) ?? raw) : raw;
|
|
460
|
+
}
|
|
461
|
+
return table;
|
|
462
|
+
}
|
|
463
|
+
catch {
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
386
467
|
/**
|
|
387
468
|
* Wrap an error from `@tailwindcss/node`'s compiler or `lightningcss`'s
|
|
388
469
|
* transform with a `rnwind:` prefix so the user sees a clear "this came
|