rnwind 0.0.1 → 0.0.3
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/animation.cjs +427 -0
- package/lib/cjs/core/parser/animation.cjs.map +1 -0
- package/lib/cjs/core/parser/animation.d.ts +126 -0
- package/lib/cjs/core/parser/border-dispatcher.cjs +180 -0
- package/lib/cjs/core/parser/border-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/border-dispatcher.d.ts +15 -0
- package/lib/cjs/core/parser/case-convert.cjs +15 -0
- package/lib/cjs/core/parser/case-convert.cjs.map +1 -0
- package/lib/cjs/core/parser/case-convert.d.ts +6 -0
- package/lib/cjs/core/parser/color-properties-dispatcher.cjs +84 -0
- package/lib/cjs/core/parser/color-properties-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/color-properties-dispatcher.d.ts +19 -0
- package/lib/cjs/core/parser/color.cjs +193 -0
- package/lib/cjs/core/parser/color.cjs.map +1 -0
- package/lib/cjs/core/parser/color.d.ts +12 -0
- package/lib/cjs/core/parser/constants.cjs +21 -0
- package/lib/cjs/core/parser/constants.cjs.map +1 -0
- package/lib/cjs/core/parser/constants.d.ts +8 -0
- package/lib/cjs/core/parser/declaration.cjs +347 -0
- package/lib/cjs/core/parser/declaration.cjs.map +1 -0
- package/lib/cjs/core/parser/declaration.d.ts +15 -0
- package/lib/cjs/core/parser/gradient.cjs +132 -0
- package/lib/cjs/core/parser/gradient.cjs.map +1 -0
- package/lib/cjs/core/parser/gradient.d.ts +59 -0
- package/lib/cjs/core/parser/haptics.cjs +73 -0
- package/lib/cjs/core/parser/haptics.cjs.map +1 -0
- package/lib/cjs/core/parser/haptics.d.ts +47 -0
- package/lib/cjs/core/parser/index.d.ts +8 -0
- package/lib/cjs/core/parser/keyframes.cjs +95 -0
- package/lib/cjs/core/parser/keyframes.cjs.map +1 -0
- package/lib/cjs/core/parser/keyframes.d.ts +26 -0
- package/lib/cjs/core/parser/layout-dispatcher.cjs +120 -0
- package/lib/cjs/core/parser/layout-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/layout-dispatcher.d.ts +14 -0
- package/lib/cjs/core/parser/length.cjs +110 -0
- package/lib/cjs/core/parser/length.cjs.map +1 -0
- package/lib/cjs/core/parser/length.d.ts +51 -0
- package/lib/cjs/core/parser/motion-dispatcher.cjs +77 -0
- package/lib/cjs/core/parser/motion-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/motion-dispatcher.d.ts +11 -0
- package/lib/cjs/core/parser/property.cjs +22 -0
- package/lib/cjs/core/parser/property.cjs.map +1 -0
- package/lib/cjs/core/parser/property.d.ts +8 -0
- package/lib/cjs/core/parser/safe-area.cjs +404 -0
- package/lib/cjs/core/parser/safe-area.cjs.map +1 -0
- package/lib/cjs/core/parser/safe-area.d.ts +39 -0
- package/lib/cjs/core/parser/selector.cjs +22 -0
- package/lib/cjs/core/parser/selector.cjs.map +1 -0
- package/lib/cjs/core/parser/selector.d.ts +11 -0
- package/lib/cjs/core/parser/shorthand.cjs +188 -0
- package/lib/cjs/core/parser/shorthand.cjs.map +1 -0
- package/lib/cjs/core/parser/shorthand.d.ts +67 -0
- package/lib/cjs/core/parser/text-truncate.cjs +78 -0
- package/lib/cjs/core/parser/text-truncate.cjs.map +1 -0
- package/lib/cjs/core/parser/text-truncate.d.ts +44 -0
- package/lib/cjs/core/parser/theme-vars.cjs +467 -0
- package/lib/cjs/core/parser/theme-vars.cjs.map +1 -0
- package/lib/cjs/core/parser/theme-vars.d.ts +82 -0
- package/lib/cjs/core/parser/tokens.cjs +486 -0
- package/lib/cjs/core/parser/tokens.cjs.map +1 -0
- package/lib/cjs/core/parser/tokens.d.ts +45 -0
- package/lib/cjs/core/parser/transform.cjs +198 -0
- package/lib/cjs/core/parser/transform.cjs.map +1 -0
- package/lib/cjs/core/parser/transform.d.ts +36 -0
- package/lib/cjs/core/parser/tw-parser.cjs +1680 -0
- package/lib/cjs/core/parser/tw-parser.cjs.map +1 -0
- package/lib/cjs/core/parser/tw-parser.d.ts +210 -0
- package/lib/cjs/core/parser/types.d.ts +37 -0
- package/lib/cjs/core/parser/typography-dispatcher.cjs +108 -0
- package/lib/cjs/core/parser/typography-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/typography-dispatcher.d.ts +11 -0
- package/lib/cjs/core/parser/typography.cjs +97 -0
- package/lib/cjs/core/parser/typography.cjs.map +1 -0
- package/lib/cjs/core/parser/typography.d.ts +43 -0
- package/lib/cjs/core/style-builder/build-style.cjs +444 -0
- package/lib/cjs/core/style-builder/build-style.cjs.map +1 -0
- package/lib/cjs/core/style-builder/build-style.d.ts +54 -0
- package/lib/cjs/core/style-builder/index.d.ts +3 -0
- package/lib/cjs/core/style-builder/union-builder.cjs +326 -0
- package/lib/cjs/core/style-builder/union-builder.cjs.map +1 -0
- package/lib/cjs/core/style-builder/union-builder.d.ts +128 -0
- package/lib/cjs/core/types.d.ts +14 -0
- package/lib/cjs/metro/dts.cjs +127 -0
- package/lib/cjs/metro/dts.cjs.map +1 -0
- package/lib/cjs/metro/dts.d.ts +16 -0
- package/lib/cjs/metro/index.cjs +19 -0
- package/lib/cjs/metro/index.cjs.map +1 -0
- package/lib/cjs/metro/index.d.ts +9 -0
- package/lib/cjs/metro/resolver.cjs +47 -0
- package/lib/cjs/metro/resolver.cjs.map +1 -0
- package/lib/cjs/metro/resolver.d.ts +22 -0
- package/lib/cjs/metro/state.cjs +301 -0
- package/lib/cjs/metro/state.cjs.map +1 -0
- package/lib/cjs/metro/state.d.ts +88 -0
- package/lib/cjs/metro/transform-ast.cjs +1472 -0
- package/lib/cjs/metro/transform-ast.cjs.map +1 -0
- package/lib/cjs/metro/transform-ast.d.ts +88 -0
- package/lib/cjs/metro/transformer.cjs +372 -0
- package/lib/cjs/metro/transformer.cjs.map +1 -0
- package/lib/cjs/metro/transformer.d.ts +47 -0
- package/lib/cjs/metro/warn-unknown-classes.cjs +86 -0
- package/lib/cjs/metro/warn-unknown-classes.cjs.map +1 -0
- package/lib/cjs/metro/warn-unknown-classes.d.ts +21 -0
- package/lib/cjs/metro/with-config.cjs +196 -0
- package/lib/cjs/metro/with-config.cjs.map +1 -0
- package/lib/cjs/metro/with-config.d.ts +79 -0
- package/lib/cjs/runtime/chain-handlers.cjs +37 -0
- package/lib/cjs/runtime/chain-handlers.cjs.map +1 -0
- package/lib/cjs/runtime/chain-handlers.d.ts +33 -0
- package/lib/cjs/runtime/components/rnwind-provider.cjs +98 -0
- package/lib/cjs/runtime/components/rnwind-provider.cjs.map +1 -0
- package/lib/cjs/runtime/components/rnwind-provider.d.ts +84 -0
- package/lib/cjs/runtime/gradient-types.d.ts +58 -0
- package/lib/cjs/runtime/haptics.cjs +113 -0
- package/lib/cjs/runtime/haptics.cjs.map +1 -0
- package/lib/cjs/runtime/haptics.d.ts +48 -0
- package/lib/cjs/runtime/hooks/use-css.cjs +21 -0
- package/lib/cjs/runtime/hooks/use-css.cjs.map +1 -0
- package/lib/cjs/runtime/hooks/use-css.d.ts +11 -0
- package/lib/cjs/runtime/hooks/use-interact.cjs +46 -0
- package/lib/cjs/runtime/hooks/use-interact.cjs.map +1 -0
- package/lib/cjs/runtime/hooks/use-interact.d.ts +42 -0
- package/lib/cjs/runtime/hooks/use-scheme.cjs +68 -0
- package/lib/cjs/runtime/hooks/use-scheme.cjs.map +1 -0
- package/lib/cjs/runtime/hooks/use-scheme.d.ts +34 -0
- package/lib/cjs/runtime/index.cjs +45 -0
- package/lib/cjs/runtime/index.cjs.map +1 -0
- package/lib/cjs/runtime/index.d.ts +27 -0
- package/lib/cjs/runtime/interactive-box.cjs +35 -0
- package/lib/cjs/runtime/interactive-box.cjs.map +1 -0
- package/lib/cjs/runtime/interactive-box.d.ts +40 -0
- package/lib/cjs/runtime/lookup-css.cjs +542 -0
- package/lib/cjs/runtime/lookup-css.cjs.map +1 -0
- package/lib/cjs/runtime/lookup-css.d.ts +164 -0
- package/lib/cjs/runtime/types.d.ts +29 -0
- package/lib/cjs/testing/index.cjs +367 -0
- package/lib/cjs/testing/index.cjs.map +1 -0
- package/lib/cjs/testing/index.d.ts +145 -0
- package/lib/esm/core/parser/animation.d.ts +126 -0
- package/lib/esm/core/parser/animation.mjs +408 -0
- package/lib/esm/core/parser/animation.mjs.map +1 -0
- package/lib/esm/core/parser/border-dispatcher.d.ts +15 -0
- package/lib/esm/core/parser/border-dispatcher.mjs +178 -0
- package/lib/esm/core/parser/border-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/case-convert.d.ts +6 -0
- package/lib/esm/core/parser/case-convert.mjs +13 -0
- package/lib/esm/core/parser/case-convert.mjs.map +1 -0
- package/lib/esm/core/parser/color-properties-dispatcher.d.ts +19 -0
- package/lib/esm/core/parser/color-properties-dispatcher.mjs +82 -0
- package/lib/esm/core/parser/color-properties-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/color.d.ts +12 -0
- package/lib/esm/core/parser/color.mjs +191 -0
- package/lib/esm/core/parser/color.mjs.map +1 -0
- package/lib/esm/core/parser/constants.d.ts +8 -0
- package/lib/esm/core/parser/constants.mjs +13 -0
- package/lib/esm/core/parser/constants.mjs.map +1 -0
- package/lib/esm/core/parser/declaration.d.ts +15 -0
- package/lib/esm/core/parser/declaration.mjs +345 -0
- package/lib/esm/core/parser/declaration.mjs.map +1 -0
- package/lib/esm/core/parser/gradient.d.ts +59 -0
- package/lib/esm/core/parser/gradient.mjs +130 -0
- package/lib/esm/core/parser/gradient.mjs.map +1 -0
- package/lib/esm/core/parser/haptics.d.ts +47 -0
- package/lib/esm/core/parser/haptics.mjs +71 -0
- package/lib/esm/core/parser/haptics.mjs.map +1 -0
- package/lib/esm/core/parser/index.d.ts +8 -0
- package/lib/esm/core/parser/keyframes.d.ts +26 -0
- package/lib/esm/core/parser/keyframes.mjs +91 -0
- package/lib/esm/core/parser/keyframes.mjs.map +1 -0
- package/lib/esm/core/parser/layout-dispatcher.d.ts +14 -0
- package/lib/esm/core/parser/layout-dispatcher.mjs +118 -0
- package/lib/esm/core/parser/layout-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/length.d.ts +51 -0
- package/lib/esm/core/parser/length.mjs +104 -0
- package/lib/esm/core/parser/length.mjs.map +1 -0
- package/lib/esm/core/parser/motion-dispatcher.d.ts +11 -0
- package/lib/esm/core/parser/motion-dispatcher.mjs +75 -0
- package/lib/esm/core/parser/motion-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/property.d.ts +8 -0
- package/lib/esm/core/parser/property.mjs +20 -0
- package/lib/esm/core/parser/property.mjs.map +1 -0
- package/lib/esm/core/parser/safe-area.d.ts +39 -0
- package/lib/esm/core/parser/safe-area.mjs +402 -0
- package/lib/esm/core/parser/safe-area.mjs.map +1 -0
- package/lib/esm/core/parser/selector.d.ts +11 -0
- package/lib/esm/core/parser/selector.mjs +20 -0
- package/lib/esm/core/parser/selector.mjs.map +1 -0
- package/lib/esm/core/parser/shorthand.d.ts +67 -0
- package/lib/esm/core/parser/shorthand.mjs +180 -0
- package/lib/esm/core/parser/shorthand.mjs.map +1 -0
- package/lib/esm/core/parser/text-truncate.d.ts +44 -0
- package/lib/esm/core/parser/text-truncate.mjs +75 -0
- package/lib/esm/core/parser/text-truncate.mjs.map +1 -0
- package/lib/esm/core/parser/theme-vars.d.ts +82 -0
- package/lib/esm/core/parser/theme-vars.mjs +461 -0
- package/lib/esm/core/parser/theme-vars.mjs.map +1 -0
- package/lib/esm/core/parser/tokens.d.ts +45 -0
- package/lib/esm/core/parser/tokens.mjs +480 -0
- package/lib/esm/core/parser/tokens.mjs.map +1 -0
- package/lib/esm/core/parser/transform.d.ts +36 -0
- package/lib/esm/core/parser/transform.mjs +193 -0
- package/lib/esm/core/parser/transform.mjs.map +1 -0
- package/lib/esm/core/parser/tw-parser.d.ts +210 -0
- package/lib/esm/core/parser/tw-parser.mjs +1678 -0
- package/lib/esm/core/parser/tw-parser.mjs.map +1 -0
- package/lib/esm/core/parser/types.d.ts +37 -0
- package/lib/esm/core/parser/typography-dispatcher.d.ts +11 -0
- package/lib/esm/core/parser/typography-dispatcher.mjs +106 -0
- package/lib/esm/core/parser/typography-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/typography.d.ts +43 -0
- package/lib/esm/core/parser/typography.mjs +91 -0
- package/lib/esm/core/parser/typography.mjs.map +1 -0
- package/lib/esm/core/style-builder/build-style.d.ts +54 -0
- package/lib/esm/core/style-builder/build-style.mjs +442 -0
- package/lib/esm/core/style-builder/build-style.mjs.map +1 -0
- package/lib/esm/core/style-builder/index.d.ts +3 -0
- package/lib/esm/core/style-builder/union-builder.d.ts +128 -0
- package/lib/esm/core/style-builder/union-builder.mjs +324 -0
- package/lib/esm/core/style-builder/union-builder.mjs.map +1 -0
- package/lib/esm/core/types.d.ts +14 -0
- package/lib/esm/metro/dts.d.ts +16 -0
- package/lib/esm/metro/dts.mjs +125 -0
- package/lib/esm/metro/dts.mjs.map +1 -0
- package/lib/esm/metro/index.d.ts +9 -0
- package/lib/esm/metro/index.mjs +6 -0
- package/lib/esm/metro/index.mjs.map +1 -0
- package/lib/esm/metro/resolver.d.ts +22 -0
- package/lib/esm/metro/resolver.mjs +43 -0
- package/lib/esm/metro/resolver.mjs.map +1 -0
- package/lib/esm/metro/state.d.ts +88 -0
- package/lib/esm/metro/state.mjs +291 -0
- package/lib/esm/metro/state.mjs.map +1 -0
- package/lib/esm/metro/transform-ast.d.ts +88 -0
- package/lib/esm/metro/transform-ast.mjs +1451 -0
- package/lib/esm/metro/transform-ast.mjs.map +1 -0
- package/lib/esm/metro/transformer.d.ts +47 -0
- package/lib/esm/metro/transformer.mjs +349 -0
- package/lib/esm/metro/transformer.mjs.map +1 -0
- package/lib/esm/metro/warn-unknown-classes.d.ts +21 -0
- package/lib/esm/metro/warn-unknown-classes.mjs +84 -0
- package/lib/esm/metro/warn-unknown-classes.mjs.map +1 -0
- package/lib/esm/metro/with-config.d.ts +79 -0
- package/lib/esm/metro/with-config.mjs +194 -0
- package/lib/esm/metro/with-config.mjs.map +1 -0
- package/lib/esm/runtime/chain-handlers.d.ts +33 -0
- package/lib/esm/runtime/chain-handlers.mjs +34 -0
- package/lib/esm/runtime/chain-handlers.mjs.map +1 -0
- package/lib/esm/runtime/components/rnwind-provider.d.ts +84 -0
- package/lib/esm/runtime/components/rnwind-provider.mjs +94 -0
- package/lib/esm/runtime/components/rnwind-provider.mjs.map +1 -0
- package/lib/esm/runtime/gradient-types.d.ts +58 -0
- package/lib/esm/runtime/haptics.d.ts +48 -0
- package/lib/esm/runtime/haptics.mjs +110 -0
- package/lib/esm/runtime/haptics.mjs.map +1 -0
- package/lib/esm/runtime/hooks/use-css.d.ts +11 -0
- package/lib/esm/runtime/hooks/use-css.mjs +19 -0
- package/lib/esm/runtime/hooks/use-css.mjs.map +1 -0
- package/lib/esm/runtime/hooks/use-interact.d.ts +42 -0
- package/lib/esm/runtime/hooks/use-interact.mjs +44 -0
- package/lib/esm/runtime/hooks/use-interact.mjs.map +1 -0
- package/lib/esm/runtime/hooks/use-scheme.d.ts +34 -0
- package/lib/esm/runtime/hooks/use-scheme.mjs +63 -0
- package/lib/esm/runtime/hooks/use-scheme.mjs.map +1 -0
- package/lib/esm/runtime/index.d.ts +27 -0
- package/lib/esm/runtime/index.mjs +18 -0
- package/lib/esm/runtime/index.mjs.map +1 -0
- package/lib/esm/runtime/interactive-box.d.ts +40 -0
- package/lib/esm/runtime/interactive-box.mjs +33 -0
- package/lib/esm/runtime/interactive-box.mjs.map +1 -0
- package/lib/esm/runtime/lookup-css.d.ts +164 -0
- package/lib/esm/runtime/lookup-css.mjs +531 -0
- package/lib/esm/runtime/lookup-css.mjs.map +1 -0
- package/lib/esm/runtime/types.d.ts +29 -0
- package/lib/esm/testing/index.d.ts +145 -0
- package/lib/esm/testing/index.mjs +344 -0
- package/lib/esm/testing/index.mjs.map +1 -0
- package/package.json +80 -13
- package/preset.css +1171 -0
- package/src/core/parser/animation.ts +404 -0
- package/src/core/parser/border-dispatcher.ts +176 -0
- package/src/core/parser/case-convert.ts +10 -0
- package/src/core/parser/color-properties-dispatcher.ts +78 -0
- package/src/core/parser/color.ts +191 -0
- package/src/core/parser/constants.ts +11 -0
- package/src/core/parser/declaration.ts +340 -0
- package/src/core/parser/gradient.ts +148 -0
- package/src/core/parser/haptics.ts +88 -0
- package/src/core/parser/index.ts +8 -0
- package/src/core/parser/keyframes.ts +84 -0
- package/src/core/parser/layout-dispatcher.ts +111 -0
- package/src/core/parser/length.ts +114 -0
- package/src/core/parser/motion-dispatcher.ts +89 -0
- package/src/core/parser/property.ts +15 -0
- package/src/core/parser/safe-area.ts +404 -0
- package/src/core/parser/selector.ts +17 -0
- package/src/core/parser/shorthand.ts +182 -0
- package/src/core/parser/text-truncate.ts +79 -0
- package/src/core/parser/theme-vars.ts +465 -0
- package/src/core/parser/tokens.ts +456 -0
- package/src/core/parser/transform.ts +195 -0
- package/src/core/parser/tw-parser.ts +1828 -0
- package/src/core/parser/types.ts +45 -0
- package/src/core/parser/typography-dispatcher.ts +97 -0
- package/src/core/parser/typography.ts +83 -0
- package/src/core/style-builder/build-style.ts +500 -0
- package/src/core/style-builder/index.ts +3 -0
- package/src/core/style-builder/union-builder.ts +328 -0
- package/src/core/types.ts +15 -0
- package/src/metro/dts.ts +128 -0
- package/src/metro/index.ts +9 -0
- package/src/metro/resolver.ts +42 -0
- package/src/metro/state.ts +305 -0
- package/src/metro/transform-ast.ts +1729 -0
- package/src/metro/transformer.ts +372 -0
- package/src/metro/warn-unknown-classes.ts +79 -0
- package/src/metro/with-config.ts +251 -0
- package/src/runtime/chain-handlers.ts +47 -0
- package/src/runtime/components/rnwind-provider.tsx +144 -0
- package/src/runtime/gradient-types.ts +60 -0
- package/src/runtime/haptics.ts +120 -0
- package/src/runtime/hooks/use-css.ts +16 -0
- package/src/runtime/hooks/use-interact.ts +65 -0
- package/src/runtime/hooks/use-scheme.ts +63 -0
- package/src/runtime/index.ts +54 -0
- package/src/runtime/interactive-box.tsx +57 -0
- package/src/runtime/lookup-css.ts +628 -0
- package/src/runtime/types.ts +32 -0
- package/src/testing/index.ts +507 -0
- package/src/types/tailwindcss-node.d.ts +33 -0
- package/src/index.ts +0 -1
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight extractor for user-declared `@theme` and `@variant` blocks
|
|
3
|
+
* inside `:root` / `@layer theme`. Used by the parser to resolve
|
|
4
|
+
* `var(--x)` references that Tailwind's `theme(inline)` leaves
|
|
5
|
+
* unresolved (it only inlines its own known tokens, not user-added ones).
|
|
6
|
+
*
|
|
7
|
+
* Kept regex-free — a linear paren-balanced scan handles nesting without
|
|
8
|
+
* the backtracking risks of `{[^}]*}` patterns. CSS comment blocks are
|
|
9
|
+
* stripped before scanning so slash-star-sequences inside declaration
|
|
10
|
+
* values don't confuse the parser.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `@custom-variant <name> ...content-up-to-semicolon...;`
|
|
15
|
+
* The `[^;]+` class is constant-width relative to its input (one char
|
|
16
|
+
* per step, no alternation backtracking), so sonarjs/slow-regex doesn't
|
|
17
|
+
* apply — the flagged pattern is a false positive.
|
|
18
|
+
*/
|
|
19
|
+
// eslint-disable-next-line sonarjs/slow-regex
|
|
20
|
+
const CUSTOM_VARIANT_WITH_SELECTOR = /@custom-variant\s+([A-Za-z][A-Za-z0-9_-]*)\s+([^;]+);/g
|
|
21
|
+
/** Bare `.classname` occurrences (one capture group per class). */
|
|
22
|
+
const CLASS_IN_SELECTOR = /\.([A-Za-z_][\w-]*)/g
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* One iteration step of the block walker — decides whether the next
|
|
26
|
+
* interesting token is a declaration, a nested block, or the end of
|
|
27
|
+
* scope. Kept small to keep {@link walkBlocks} below the cognitive
|
|
28
|
+
* complexity threshold.
|
|
29
|
+
*/
|
|
30
|
+
interface WalkStep {
|
|
31
|
+
/** Next scan index, or `-1` to terminate the outer loop. */
|
|
32
|
+
next: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Recursively descend into `{ ... }` blocks, collecting `--x: y;`
|
|
37
|
+
* declarations under the active scheme. When we hit `@variant <name> {`,
|
|
38
|
+
* the child scope's scheme becomes `<name>` until that block closes.
|
|
39
|
+
* @param source Pre-stripped CSS source.
|
|
40
|
+
* @param start Start index of the block body (0 for top-level).
|
|
41
|
+
* @param scheme Active scheme name for declarations inside this scope.
|
|
42
|
+
* @param table Destination table, mutated in place.
|
|
43
|
+
*/
|
|
44
|
+
function walkBlocks(source: string, start: number, scheme: string, table: ThemeSchemeTable): void {
|
|
45
|
+
let index = start
|
|
46
|
+
while (index < source.length) {
|
|
47
|
+
const step = nextWalkStep(source, index, scheme, table)
|
|
48
|
+
if (step.next === -1) return
|
|
49
|
+
index = step.next
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Decide the next action at `index`: declaration, nested block, or EOF.
|
|
55
|
+
* @param source Pre-stripped CSS.
|
|
56
|
+
* @param index Current scan index.
|
|
57
|
+
* @param scheme Active scheme name.
|
|
58
|
+
* @param table Destination table.
|
|
59
|
+
* @returns Step descriptor with the next scan index (or -1 for EOF).
|
|
60
|
+
*/
|
|
61
|
+
function nextWalkStep(source: string, index: number, scheme: string, table: ThemeSchemeTable): WalkStep {
|
|
62
|
+
// Find the next TOP-LEVEL `--` (outside any `( ... )`). That's the only
|
|
63
|
+
// place a custom-property declaration can start. `--foo` that appears
|
|
64
|
+
// inside `var(--foo)` or `calc(... --value(integer) ...)` is part of a
|
|
65
|
+
// value, not a new declaration — accidentally treating it as one would
|
|
66
|
+
// splice into the `@theme` block's declaration list and produce broken
|
|
67
|
+
// CSS that Tailwind rejects downstream.
|
|
68
|
+
const atIndex = findTopLevelDoubleDash(source, index)
|
|
69
|
+
const openIndex = source.indexOf('{', index)
|
|
70
|
+
const closeIndex = source.indexOf('}', index)
|
|
71
|
+
const blockClose = closeIndex === -1 ? Number.POSITIVE_INFINITY : closeIndex
|
|
72
|
+
if (isDeclarationNext(atIndex, openIndex, blockClose)) {
|
|
73
|
+
return { next: consumeDeclaration(source, atIndex, scheme, table) }
|
|
74
|
+
}
|
|
75
|
+
if (openIndex !== -1 && openIndex < blockClose) {
|
|
76
|
+
return { next: enterBlock(source, index, openIndex, scheme, table) }
|
|
77
|
+
}
|
|
78
|
+
return { next: -1 }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Find the next `--` in `source` that's not inside a `( ... )` group.
|
|
83
|
+
* Stops early if we hit an unmatched `}` (end of the containing block)
|
|
84
|
+
* — a `--` inside a nested block isn't our concern either.
|
|
85
|
+
* @param source Pre-stripped CSS source.
|
|
86
|
+
* @param from Start index to scan from.
|
|
87
|
+
* @returns Index of the next top-level `--`, or `-1` when none.
|
|
88
|
+
*/
|
|
89
|
+
function findTopLevelDoubleDash(source: string, from: number): number {
|
|
90
|
+
let parenDepth = 0
|
|
91
|
+
for (let index = from; index < source.length - 1; index += 1) {
|
|
92
|
+
const ch = source.codePointAt(index)
|
|
93
|
+
if (ch === 40 /* ( */) {
|
|
94
|
+
parenDepth += 1
|
|
95
|
+
continue
|
|
96
|
+
}
|
|
97
|
+
if (ch === 41 /* ) */) {
|
|
98
|
+
if (parenDepth > 0) parenDepth -= 1
|
|
99
|
+
continue
|
|
100
|
+
}
|
|
101
|
+
if (ch === 125 /* } */ && parenDepth === 0) return -1
|
|
102
|
+
if (ch === 45 /* - */ && parenDepth === 0 && source.codePointAt(index + 1) === 45) {
|
|
103
|
+
return index
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return -1
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Whether the next action at the current scan position is a declaration.
|
|
111
|
+
* @param atIndex Index of the next `--`.
|
|
112
|
+
* @param openIndex Index of the next `{`.
|
|
113
|
+
* @param blockClose Index of the next `}` (or `+Infinity` when absent).
|
|
114
|
+
* @returns True when a declaration should be consumed next.
|
|
115
|
+
*/
|
|
116
|
+
function isDeclarationNext(atIndex: number, openIndex: number, blockClose: number): boolean {
|
|
117
|
+
if (atIndex === -1 || atIndex >= blockClose) return false
|
|
118
|
+
return openIndex === -1 || atIndex < openIndex
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Handle a nested `{ ... }` block: recurse with the right scheme, then
|
|
123
|
+
* skip past the matching closing brace.
|
|
124
|
+
* @param source Pre-stripped CSS.
|
|
125
|
+
* @param index Scan position at the start of the header.
|
|
126
|
+
* @param openIndex Index of the opening brace.
|
|
127
|
+
* @param scheme Scheme active in the parent scope.
|
|
128
|
+
* @param table Destination table.
|
|
129
|
+
* @returns Index past the matching closing brace.
|
|
130
|
+
*/
|
|
131
|
+
function enterBlock(source: string, index: number, openIndex: number, scheme: string, table: ThemeSchemeTable): number {
|
|
132
|
+
const header = source.slice(index, openIndex).trim()
|
|
133
|
+
// Skip blocks that define utilities / at-rules that carry declarations
|
|
134
|
+
// meant for a downstream compiler, not custom-property values for the
|
|
135
|
+
// active theme scheme. `@utility name-*` bodies contain Tailwind v4's
|
|
136
|
+
// `--value(...)` meta-syntax which would otherwise confuse the
|
|
137
|
+
// top-level declaration walker and spill into the extracted theme.
|
|
138
|
+
if (isNonThemeAtRule(header)) return skipMatchingBrace(source, openIndex + 1)
|
|
139
|
+
const childScheme = variantNameOf(header) ?? scheme
|
|
140
|
+
walkBlocks(source, openIndex + 1, childScheme, table)
|
|
141
|
+
return skipMatchingBrace(source, openIndex + 1)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Whether a block header belongs to an at-rule whose body should be
|
|
146
|
+
* ignored by the theme-var extractor. `@utility` / `@media` / `@keyframes`
|
|
147
|
+
* / `@supports` / `@container` bodies contain property declarations that
|
|
148
|
+
* are NOT custom-property definitions for the active theme.
|
|
149
|
+
* @param header Text between the outer statement and the opening brace.
|
|
150
|
+
* @returns `true` when the block body should be skipped.
|
|
151
|
+
*/
|
|
152
|
+
function isNonThemeAtRule(header: string): boolean {
|
|
153
|
+
const trimmed = header.trimStart()
|
|
154
|
+
if (!trimmed.startsWith('@')) return false
|
|
155
|
+
const match = /^@([A-Za-z-]+)/.exec(trimmed)
|
|
156
|
+
if (!match) return false
|
|
157
|
+
const name = match[1]!
|
|
158
|
+
return name === 'utility' || name === 'keyframes' || name === 'media' || name === 'supports' || name === 'container'
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Consume one `--name: value;` declaration starting at `start`. Commits
|
|
163
|
+
* the name/value pair into the active scheme's map and returns the index
|
|
164
|
+
* just past the terminating `;`.
|
|
165
|
+
* @param source CSS source.
|
|
166
|
+
* @param start Index of the `--`.
|
|
167
|
+
* @param scheme Active scheme.
|
|
168
|
+
* @param table Destination table.
|
|
169
|
+
* @returns Next scan index.
|
|
170
|
+
*/
|
|
171
|
+
function consumeDeclaration(source: string, start: number, scheme: string, table: ThemeSchemeTable): number {
|
|
172
|
+
const colon = source.indexOf(':', start)
|
|
173
|
+
if (colon === -1) return source.length
|
|
174
|
+
const name = source.slice(start, colon).trim()
|
|
175
|
+
const end = source.indexOf(';', colon)
|
|
176
|
+
const stop = end === -1 ? source.indexOf('}', colon) : end
|
|
177
|
+
if (stop === -1) return source.length
|
|
178
|
+
const value = source.slice(colon + 1, stop).trim()
|
|
179
|
+
if (name.startsWith('--')) {
|
|
180
|
+
const bucket = table.get(scheme) ?? new Map()
|
|
181
|
+
bucket.set(name, value)
|
|
182
|
+
table.set(scheme, bucket)
|
|
183
|
+
}
|
|
184
|
+
return stop + 1
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Walk forward through the source tracking brace depth; return the index
|
|
189
|
+
* just past the matching `}` for the opener at `start - 1`.
|
|
190
|
+
* @param source CSS source.
|
|
191
|
+
* @param start Index just past the opening brace.
|
|
192
|
+
* @returns Index past the matching closer (or source.length on imbalance).
|
|
193
|
+
*/
|
|
194
|
+
function skipMatchingBrace(source: string, start: number): number {
|
|
195
|
+
let depth = 1
|
|
196
|
+
for (let index = start; index < source.length; index += 1) {
|
|
197
|
+
const ch = source[index]
|
|
198
|
+
if (ch === '{') depth += 1
|
|
199
|
+
else if (ch === '}') {
|
|
200
|
+
depth -= 1
|
|
201
|
+
if (depth === 0) return index + 1
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return source.length
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* If `header` text (right before an opening brace) names a variant
|
|
209
|
+
* (`@variant <name>`), return that name. Otherwise null.
|
|
210
|
+
* @param header Text between the previous statement and the next `{`.
|
|
211
|
+
* @returns Variant name, or null when this block isn't a `@variant`.
|
|
212
|
+
*/
|
|
213
|
+
function variantNameOf(header: string): string | null {
|
|
214
|
+
const match = /^@variant\s+([A-Za-z][A-Za-z0-9_-]*)/.exec(header)
|
|
215
|
+
if (!match) return null
|
|
216
|
+
return match[1] ?? null
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Emit `@custom-variant` declarations for every scheme the user declared
|
|
221
|
+
* but hasn't manually registered. Makes Tailwind accept `light:*` /
|
|
222
|
+
* `dark:*` / etc. as valid class-name prefixes.
|
|
223
|
+
* @param css Stripped CSS source used to detect already-declared variants.
|
|
224
|
+
* @param schemes Non-base scheme names from the extracted table.
|
|
225
|
+
* @returns Zero or more `@custom-variant ... ;` lines.
|
|
226
|
+
*/
|
|
227
|
+
function buildCustomVariantDeclarations(css: string, schemes: readonly string[]): string[] {
|
|
228
|
+
if (schemes.length === 0) return []
|
|
229
|
+
const existing = new Set<string>()
|
|
230
|
+
for (const match of css.matchAll(CUSTOM_VARIANT_REGEX)) existing.add(match[1]!)
|
|
231
|
+
const out: string[] = []
|
|
232
|
+
for (const name of schemes) {
|
|
233
|
+
if (!existing.has(name)) out.push(`@custom-variant ${name} (&:where(.${name}, .${name} *));`)
|
|
234
|
+
}
|
|
235
|
+
return out
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Re-publish variant-scoped tokens into a flat theme block so Tailwind
|
|
240
|
+
* sees every custom-property name it needs. Values come from the base
|
|
241
|
+
* scheme first, with the FIRST declared non-base scheme layering on top
|
|
242
|
+
* — Tailwind only cares about token shape (color vs length), not the
|
|
243
|
+
* exact value, since rnwind does per-scheme substitution at walk time.
|
|
244
|
+
* @param table Extracted scheme → var-name → value table.
|
|
245
|
+
* @param schemes Non-base scheme names (sorted by declaration order).
|
|
246
|
+
* @returns A single `@theme { ... }` block or `null` when there are no tokens.
|
|
247
|
+
*/
|
|
248
|
+
function buildUnifiedThemeBlock(table: ThemeSchemeTable, schemes: readonly string[]): string | null {
|
|
249
|
+
const unifiedVars = new Map<string, string>()
|
|
250
|
+
const baseTokens = table.get(BASE_SCHEME)
|
|
251
|
+
if (baseTokens) for (const [k, v] of baseTokens) unifiedVars.set(k, v)
|
|
252
|
+
if (schemes.length > 0) {
|
|
253
|
+
const firstTokens = table.get(schemes[0]!)
|
|
254
|
+
if (firstTokens) for (const [k, v] of firstTokens) unifiedVars.set(k, v)
|
|
255
|
+
}
|
|
256
|
+
if (unifiedVars.size === 0) return null
|
|
257
|
+
const decls = [...unifiedVars].map(([name, value]) => ` ${name}: ${value};`).join('\n')
|
|
258
|
+
return `@theme {\n${decls}\n}`
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const CUSTOM_VARIANT_REGEX = /@custom-variant\s+([A-Za-z][A-Za-z0-9_-]*)\b/g
|
|
262
|
+
const VARIANT_OPEN_REGEX = /@variant\s+[A-Za-z0-9_-]+\s*\{/g
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Strip every `@variant <name> { ... }` block (including nested braces)
|
|
266
|
+
* from a CSS source.
|
|
267
|
+
* @param css Raw CSS.
|
|
268
|
+
* @returns CSS without variant blocks.
|
|
269
|
+
*/
|
|
270
|
+
function stripVariantBlocks(css: string): string {
|
|
271
|
+
let out = ''
|
|
272
|
+
let cursor = 0
|
|
273
|
+
VARIANT_OPEN_REGEX.lastIndex = 0
|
|
274
|
+
let match: RegExpExecArray | null
|
|
275
|
+
while ((match = VARIANT_OPEN_REGEX.exec(css)) !== null) {
|
|
276
|
+
const openEnd = match.index + match[0].length
|
|
277
|
+
const closeIndex = findMatchingBrace(css, openEnd)
|
|
278
|
+
if (closeIndex === -1) break
|
|
279
|
+
out += css.slice(cursor, match.index)
|
|
280
|
+
cursor = closeIndex + 1
|
|
281
|
+
VARIANT_OPEN_REGEX.lastIndex = cursor
|
|
282
|
+
}
|
|
283
|
+
out += css.slice(cursor)
|
|
284
|
+
return out
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Walk forward from `start` tracking brace depth; return the index of the
|
|
289
|
+
* matching `}` for the opener just before `start`.
|
|
290
|
+
* @param source Source string.
|
|
291
|
+
* @param start Index just past the opening `{`.
|
|
292
|
+
* @returns Index of matching `}`, or `-1` on imbalance.
|
|
293
|
+
*/
|
|
294
|
+
function findMatchingBrace(source: string, start: number): number {
|
|
295
|
+
let depth = 1
|
|
296
|
+
for (let index = start; index < source.length; index += 1) {
|
|
297
|
+
const ch = source[index]
|
|
298
|
+
if (ch === '{') depth += 1
|
|
299
|
+
else if (ch === '}') {
|
|
300
|
+
depth -= 1
|
|
301
|
+
if (depth === 0) return index
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return -1
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Drop CSS comment blocks from a source. Keeps the token-declaration
|
|
309
|
+
* scanner simple — comments can contain braces / `--` sequences that
|
|
310
|
+
* would otherwise fool it.
|
|
311
|
+
* @param css Raw CSS source.
|
|
312
|
+
* @returns Source with every comment block removed.
|
|
313
|
+
*/
|
|
314
|
+
function stripComments(css: string): string {
|
|
315
|
+
let out = ''
|
|
316
|
+
let index = 0
|
|
317
|
+
while (index < css.length) {
|
|
318
|
+
const open = css.indexOf('/*', index)
|
|
319
|
+
if (open === -1) {
|
|
320
|
+
out += css.slice(index)
|
|
321
|
+
break
|
|
322
|
+
}
|
|
323
|
+
out += css.slice(index, open)
|
|
324
|
+
const close = css.indexOf('*/', open + 2)
|
|
325
|
+
if (close === -1) break
|
|
326
|
+
index = close + 2
|
|
327
|
+
}
|
|
328
|
+
return out
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** Scheme name → (var name → value). The base scheme key is `'base'`. */
|
|
332
|
+
export type ThemeSchemeTable = Map<string, Map<string, string>>
|
|
333
|
+
|
|
334
|
+
/** Synthetic scheme name used for tokens declared outside any `@variant`. */
|
|
335
|
+
export const BASE_SCHEME = 'base'
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Extract user-declared theme tokens from a CSS source. Scans for:
|
|
339
|
+
* - classic v4 `@theme` blocks (`@theme { --x: y; ... }`)
|
|
340
|
+
* - `@variant <name> { --x: y; ... }` inside any surrounding block
|
|
341
|
+
*
|
|
342
|
+
* Both flavors contribute to the returned table: vars outside any
|
|
343
|
+
* `@variant` go under `'base'`; vars inside `@variant <name>` go under
|
|
344
|
+
* `<name>`.
|
|
345
|
+
*
|
|
346
|
+
* Not a full CSS parser — just enough to recognise the token-declaration
|
|
347
|
+
* shape Tailwind v4 users actually write.
|
|
348
|
+
* @param css Theme CSS source.
|
|
349
|
+
* @returns Scheme → var-name → value map.
|
|
350
|
+
*/
|
|
351
|
+
export function extractThemeVars(css: string): ThemeSchemeTable {
|
|
352
|
+
const table: ThemeSchemeTable = new Map()
|
|
353
|
+
const stripped = stripComments(css)
|
|
354
|
+
walkBlocks(stripped, 0, BASE_SCHEME, table)
|
|
355
|
+
return table
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Build a `<class-in-selector> → <scheme-name>` alias map from any
|
|
360
|
+
* `@custom-variant <name> (<selector>);` declarations in the theme CSS.
|
|
361
|
+
*
|
|
362
|
+
* Tailwind compiles `dark:opacity-100` to a nested rule whose selector is
|
|
363
|
+
* the user's declared variant selector. When the user writes
|
|
364
|
+
* `@custom-variant dark (&:where(.scheme-dark, .scheme-dark *));`, the
|
|
365
|
+
* generated rule references `.scheme-dark` instead of the literal `.dark`
|
|
366
|
+
* class rnwind's selector matcher defaults to. This alias map lets the
|
|
367
|
+
* parser map those custom selector classes back to their scheme name.
|
|
368
|
+
* @param css Theme CSS source.
|
|
369
|
+
* @returns Class-name → scheme-name map. Empty when no `@custom-variant`
|
|
370
|
+
* declarations are present (rnwind's auto-generated defaults already
|
|
371
|
+
* use the literal scheme name and don't need an alias).
|
|
372
|
+
*/
|
|
373
|
+
export function extractSchemeAliases(css: string): Map<string, string> {
|
|
374
|
+
const aliases = new Map<string, string>()
|
|
375
|
+
const stripped = stripComments(css)
|
|
376
|
+
for (const match of stripped.matchAll(CUSTOM_VARIANT_WITH_SELECTOR)) {
|
|
377
|
+
const schemeName = match[1]!
|
|
378
|
+
const selectorBody = match[2]!
|
|
379
|
+
for (const cls of selectorBody.matchAll(CLASS_IN_SELECTOR)) {
|
|
380
|
+
const className = cls[1]!
|
|
381
|
+
if (className === schemeName) continue
|
|
382
|
+
aliases.set(className, schemeName)
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return aliases
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** Single class token (`.scheme-dark`) — non-global so `.test` is stateless. */
|
|
389
|
+
const CLASS_TOKEN = /\.[A-Za-z_][\w-]*/
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Whether a `@custom-variant` selector body targets an ancestor *class*
|
|
393
|
+
* container (`&:where(.scheme-dark, .scheme-dark *)`, `.dark`). That's
|
|
394
|
+
* the only shape rnwind resolves as a runtime scheme — the parser's
|
|
395
|
+
* nested-rule matcher keys schemes off `.class` selectors. Pseudo-class
|
|
396
|
+
* / `@media` / `@supports` custom-variants (`&:hover`, `@supports
|
|
397
|
+
* (display: grid)`) carry no class and are ordinary Tailwind variants,
|
|
398
|
+
* not schemes.
|
|
399
|
+
* @param selector Selector body captured after the variant name.
|
|
400
|
+
* @returns True when the selector contains at least one class token.
|
|
401
|
+
*/
|
|
402
|
+
function isSchemeSelector(selector: string): boolean {
|
|
403
|
+
return CLASS_TOKEN.test(selector)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Collect every scheme name declared via `@custom-variant <name>
|
|
408
|
+
* (<class-selector>);` in first-appearance order.
|
|
409
|
+
*
|
|
410
|
+
* A scheme can be declared this way WITHOUT a matching `@variant <name>
|
|
411
|
+
* { … }` override block — its values then come entirely from the base
|
|
412
|
+
* `@theme`. That's Tailwind v4's standard shape: light defaults sit in
|
|
413
|
+
* `@theme` and only `@variant dark { … }` overrides them. Such a scheme
|
|
414
|
+
* still has to register so the runtime can switch to it, but
|
|
415
|
+
* {@link extractThemeVars} (which only sees `@variant` blocks) never
|
|
416
|
+
* surfaces it. The parser unions these names into its declared-scheme
|
|
417
|
+
* list so the base-only scheme isn't dropped.
|
|
418
|
+
*
|
|
419
|
+
* Only class-container selectors count — `@custom-variant` is Tailwind's
|
|
420
|
+
* general variant mechanism, so hover / focus / media / supports
|
|
421
|
+
* variants must NOT inflate the scheme list (or the generated `Scheme`
|
|
422
|
+
* union). See {@link isSchemeSelector}.
|
|
423
|
+
* @param css Theme CSS source.
|
|
424
|
+
* @returns Ordered, de-duplicated `@custom-variant` scheme names.
|
|
425
|
+
*/
|
|
426
|
+
export function extractCustomVariantSchemes(css: string): string[] {
|
|
427
|
+
const stripped = stripComments(css)
|
|
428
|
+
const seen = new Set<string>()
|
|
429
|
+
const out: string[] = []
|
|
430
|
+
for (const match of stripped.matchAll(CUSTOM_VARIANT_WITH_SELECTOR)) {
|
|
431
|
+
const name = match[1]!
|
|
432
|
+
const selector = match[2]!
|
|
433
|
+
if (name === BASE_SCHEME || seen.has(name)) continue
|
|
434
|
+
if (!isSchemeSelector(selector)) continue
|
|
435
|
+
seen.add(name)
|
|
436
|
+
out.push(name)
|
|
437
|
+
}
|
|
438
|
+
return out
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Rewrite the theme CSS so Tailwind's compiler accepts it:
|
|
443
|
+
* 1. Strip every `@variant <name> { ... }` block — Tailwind rejects
|
|
444
|
+
* them inline because `@variant` is a rnwind concept, not a Tailwind
|
|
445
|
+
* at-rule. The scheme-scoped vars are preserved in the extracted
|
|
446
|
+
* {@link ThemeSchemeTable} and substituted at walk time.
|
|
447
|
+
* 2. Prepend `@custom-variant <name> (&:where(.<name>, .<name> *));`
|
|
448
|
+
* for every scheme name we saw, so Tailwind accepts `light:bg-*`,
|
|
449
|
+
* `dark:bg-*`, etc. as valid class-name prefixes without the user
|
|
450
|
+
* having to duplicate the variant declaration.
|
|
451
|
+
* @param css Theme CSS source.
|
|
452
|
+
* @param table Scheme → var-name → value table from {@link extractThemeVars}.
|
|
453
|
+
* @returns CSS ready to feed `@tailwindcss/node`'s compiler.
|
|
454
|
+
*/
|
|
455
|
+
export function compileReadyTheme(css: string, table: ThemeSchemeTable): string {
|
|
456
|
+
const schemes = [...table.keys()].filter((name) => name !== BASE_SCHEME)
|
|
457
|
+
const stripped = stripVariantBlocks(css)
|
|
458
|
+
const prelude: string[] = []
|
|
459
|
+
const customVariants = buildCustomVariantDeclarations(stripped, schemes)
|
|
460
|
+
if (customVariants.length > 0) prelude.push(...customVariants)
|
|
461
|
+
const themeBlock = buildUnifiedThemeBlock(table, schemes)
|
|
462
|
+
if (themeBlock) prelude.push(themeBlock)
|
|
463
|
+
if (prelude.length === 0) return stripped
|
|
464
|
+
return `${prelude.join('\n')}\n${stripped}`
|
|
465
|
+
}
|