rnwind 0.0.9 → 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 +126 -3
- package/lib/cjs/core/parser/tw-parser.cjs.map +1 -1
- package/lib/cjs/core/parser/tw-parser.d.ts +22 -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 +22 -0
- package/lib/esm/core/parser/tw-parser.mjs +107 -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 +118 -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
|
@@ -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
|
/**
|
|
@@ -148,6 +169,42 @@ class TailwindParser {
|
|
|
148
169
|
merged.set(k, v);
|
|
149
170
|
return merged;
|
|
150
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Build the per-scheme theme token tables for `registerThemeTokens` —
|
|
174
|
+
* the data source for `useColor` / `useToken` / `useSize`. Emits one table
|
|
175
|
+
* per scheme the user wrote tokens under (`base` + each variant block /
|
|
176
|
+
* `.dark` override). `--color-*` values are lowered to sRGB (matching the
|
|
177
|
+
* className path) using `resolver` so a wide-gamut or `var()`-referencing
|
|
178
|
+
* token resolves to an RN-renderable string; other tokens pass through.
|
|
179
|
+
* @param resolver Full compiled `:root` table, for resolving `var()` refs.
|
|
180
|
+
* @returns Scheme → (token name → value) map.
|
|
181
|
+
*/
|
|
182
|
+
buildThemeTokens(resolver) {
|
|
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.
|
|
191
|
+
for (const scheme of this.themeSchemes.keys()) {
|
|
192
|
+
if (scheme === themeVars.BASE_SCHEME)
|
|
193
|
+
continue;
|
|
194
|
+
const userTable = this.themeSchemes.get(scheme);
|
|
195
|
+
if (!userTable || userTable.size === 0)
|
|
196
|
+
continue;
|
|
197
|
+
const schemeResolver = new Map(resolver);
|
|
198
|
+
for (const [k, v] of this.effectiveVars(scheme))
|
|
199
|
+
schemeResolver.set(k, v);
|
|
200
|
+
const table = {};
|
|
201
|
+
for (const [name, raw] of userTable) {
|
|
202
|
+
table[name] = name.startsWith('--color-') ? lowerColorToken(raw, schemeResolver) : raw;
|
|
203
|
+
}
|
|
204
|
+
out[scheme] = table;
|
|
205
|
+
}
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
151
208
|
/**
|
|
152
209
|
* Build the Tailwind compiler on first use and cache it. The theme CSS
|
|
153
210
|
* gets a `theme(inline)` modifier on its `@import 'tailwindcss'` so
|
|
@@ -159,7 +216,7 @@ class TailwindParser {
|
|
|
159
216
|
return this.compiler;
|
|
160
217
|
const ready = themeVars.compileReadyTheme(this.config.themeCss, this.themeSchemes);
|
|
161
218
|
try {
|
|
162
|
-
this.compiler = await
|
|
219
|
+
this.compiler = await tailwindNode.compile(withInlineTheme(ready), {
|
|
163
220
|
base: process.cwd(),
|
|
164
221
|
onDependency: () => { },
|
|
165
222
|
});
|
|
@@ -167,6 +224,13 @@ class TailwindParser {
|
|
|
167
224
|
catch (error) {
|
|
168
225
|
throw wrapThemeError(error);
|
|
169
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);
|
|
170
234
|
return this.compiler;
|
|
171
235
|
}
|
|
172
236
|
/**
|
|
@@ -339,7 +403,65 @@ class TailwindParser {
|
|
|
339
403
|
if (!referencedKeyframes.has(name))
|
|
340
404
|
keyframes$1.delete(name);
|
|
341
405
|
}
|
|
342
|
-
|
|
406
|
+
const themeTokens = this.buildThemeTokens(compiledTheme);
|
|
407
|
+
return { atoms, keyframes: keyframes$1, propertyDefaults, gradientAtoms, hapticAtoms, candidates: [...candidates], schemes, breakpoints, themeTokens };
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Lower a `--color-*` token value to an RN-renderable sRGB string, matching
|
|
412
|
+
* the className path: resolve any `var()` ref via `resolver`, then lower a
|
|
413
|
+
* wide-gamut form (`oklch(…)`, `lab(…)`, `color(p3 …)`) to sRGB. Hex / rgb /
|
|
414
|
+
* named colors pass through unchanged.
|
|
415
|
+
* @param raw Raw token value.
|
|
416
|
+
* @param resolver Var name → value table for resolving `var()` references.
|
|
417
|
+
* @returns RN-safe color string.
|
|
418
|
+
*/
|
|
419
|
+
function lowerColorToken(raw, resolver) {
|
|
420
|
+
const substituted = tokens.substituteThemeVars(raw, resolver);
|
|
421
|
+
return color.normalizeColorString(substituted) ?? substituted;
|
|
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;
|
|
343
465
|
}
|
|
344
466
|
}
|
|
345
467
|
/**
|
|
@@ -388,6 +510,7 @@ function emptyOutput() {
|
|
|
388
510
|
candidates: [],
|
|
389
511
|
schemes: [themeVars.BASE_SCHEME],
|
|
390
512
|
breakpoints: new Map(),
|
|
513
|
+
themeTokens: {},
|
|
391
514
|
};
|
|
392
515
|
}
|
|
393
516
|
/**
|