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,193 @@
|
|
|
1
|
+
import { lengthToPx } from './length.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Map a single typed transform function into zero-or-more RN transform
|
|
5
|
+
* operations. Compound ops (like `translate`, `scale`, `skew`) expand
|
|
6
|
+
* into per-axis entries the way RN expects them.
|
|
7
|
+
* @param fn Typed transform function.
|
|
8
|
+
* @returns RN transform operations.
|
|
9
|
+
*/
|
|
10
|
+
function mapTransformFunction(fn) {
|
|
11
|
+
switch (fn.type) {
|
|
12
|
+
case 'rotate':
|
|
13
|
+
case 'rotateZ': {
|
|
14
|
+
return [{ rotate: angleToString(fn.value) }];
|
|
15
|
+
}
|
|
16
|
+
case 'rotateX': {
|
|
17
|
+
return [{ rotateX: angleToString(fn.value) }];
|
|
18
|
+
}
|
|
19
|
+
case 'rotateY': {
|
|
20
|
+
return [{ rotateY: angleToString(fn.value) }];
|
|
21
|
+
}
|
|
22
|
+
case 'scale': {
|
|
23
|
+
const [x, y] = fn.value;
|
|
24
|
+
return [{ scaleX: numberOrPercentageToNumber(x) }, { scaleY: numberOrPercentageToNumber(y) }];
|
|
25
|
+
}
|
|
26
|
+
case 'scaleX': {
|
|
27
|
+
return [{ scaleX: numberOrPercentageToNumber(fn.value) }];
|
|
28
|
+
}
|
|
29
|
+
case 'scaleY': {
|
|
30
|
+
return [{ scaleY: numberOrPercentageToNumber(fn.value) }];
|
|
31
|
+
}
|
|
32
|
+
case 'translateX': {
|
|
33
|
+
return [{ translateX: lengthOrPercentToNumber(fn.value) }];
|
|
34
|
+
}
|
|
35
|
+
case 'translateY': {
|
|
36
|
+
return [{ translateY: lengthOrPercentToNumber(fn.value) }];
|
|
37
|
+
}
|
|
38
|
+
case 'translate': {
|
|
39
|
+
const [x, y] = fn.value;
|
|
40
|
+
const out = [{ translateX: lengthOrPercentToNumber(x) }];
|
|
41
|
+
if (y)
|
|
42
|
+
out.push({ translateY: lengthOrPercentToNumber(y) });
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
case 'translate3d': {
|
|
46
|
+
const [x, y] = fn.value;
|
|
47
|
+
return [{ translateX: lengthOrPercentToNumber(x) }, { translateY: lengthOrPercentToNumber(y) }];
|
|
48
|
+
}
|
|
49
|
+
case 'skew': {
|
|
50
|
+
const [x, y] = fn.value;
|
|
51
|
+
const out = [{ skewX: angleToString(x) }];
|
|
52
|
+
if (y)
|
|
53
|
+
out.push({ skewY: angleToString(y) });
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
case 'skewX': {
|
|
57
|
+
return [{ skewX: angleToString(fn.value) }];
|
|
58
|
+
}
|
|
59
|
+
case 'skewY': {
|
|
60
|
+
return [{ skewY: angleToString(fn.value) }];
|
|
61
|
+
}
|
|
62
|
+
default: {
|
|
63
|
+
// RN doesn't have a direct equivalent for `matrix()` / `matrix3d()` /
|
|
64
|
+
// `perspective()` at the transform-op level — skip silently. Tailwind's
|
|
65
|
+
// generated transforms stay within rotate/translate/scale/skew.
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Serialize a typed angle into the CSS degree string RN accepts
|
|
72
|
+
* (`'45deg'`, `'0.5turn'` → `'180deg'`).
|
|
73
|
+
* @param angle Typed angle.
|
|
74
|
+
* @returns Degree string.
|
|
75
|
+
*/
|
|
76
|
+
function angleToString(angle) {
|
|
77
|
+
switch (angle.type) {
|
|
78
|
+
case 'deg': {
|
|
79
|
+
return `${formatNumber(angle.value)}deg`;
|
|
80
|
+
}
|
|
81
|
+
case 'rad': {
|
|
82
|
+
return `${formatNumber((angle.value * 180) / Math.PI)}deg`;
|
|
83
|
+
}
|
|
84
|
+
case 'grad': {
|
|
85
|
+
return `${formatNumber((angle.value * 360) / 400)}deg`;
|
|
86
|
+
}
|
|
87
|
+
case 'turn': {
|
|
88
|
+
return `${formatNumber(angle.value * 360)}deg`;
|
|
89
|
+
}
|
|
90
|
+
default: {
|
|
91
|
+
return '0deg';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Convert a `NumberOrPercentage` to a plain number. Percentages become
|
|
97
|
+
* their fractional equivalent (e.g. `50%` → `0.5`).
|
|
98
|
+
* @param value Typed value.
|
|
99
|
+
* @returns Plain number.
|
|
100
|
+
*/
|
|
101
|
+
function numberOrPercentageToNumber(value) {
|
|
102
|
+
if (value.type === 'percentage')
|
|
103
|
+
return value.value;
|
|
104
|
+
return value.value;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Convert a length-or-percentage used by translate into the shape RN
|
|
108
|
+
* accepts (`number` for px, `string` for `%`). Percentages stay as
|
|
109
|
+
* strings so RN layout can resolve them against the element size.
|
|
110
|
+
* @param value Typed length or percentage.
|
|
111
|
+
* @returns RN-style translate value.
|
|
112
|
+
*/
|
|
113
|
+
function lengthOrPercentToNumber(value) {
|
|
114
|
+
if (value.type === 'dimension')
|
|
115
|
+
return lengthToPx(value.value);
|
|
116
|
+
if (value.type === 'value')
|
|
117
|
+
return lengthToPx(value.value);
|
|
118
|
+
if (value.type === 'percentage')
|
|
119
|
+
return `${formatNumber(value.value * 100)}%`;
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Render a number without trailing IEEE noise.
|
|
124
|
+
* @param value Number to format.
|
|
125
|
+
* @returns Compact string form.
|
|
126
|
+
*/
|
|
127
|
+
function formatNumber(value) {
|
|
128
|
+
const rounded = Math.round(value * 10_000) / 10_000;
|
|
129
|
+
return String(rounded);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Convert lightningcss's typed `transform: ...` value into RN's
|
|
133
|
+
* `transform: [{ op: value }, ...]` array. RN supports a restricted subset
|
|
134
|
+
* of CSS transforms — this function picks out the ones it actually
|
|
135
|
+
* handles and drops the rest.
|
|
136
|
+
*
|
|
137
|
+
* Reanimated v4's CSS engine reads this same array shape, so the output
|
|
138
|
+
* is drop-in for both static RN `style` props and `Animated.View` styles.
|
|
139
|
+
* @param fns Typed transform function list.
|
|
140
|
+
* @returns Zero-or-one RN entry with the `transform` array.
|
|
141
|
+
*/
|
|
142
|
+
function transformFunctionsToEntries(fns) {
|
|
143
|
+
const ops = [];
|
|
144
|
+
for (const fn of fns) {
|
|
145
|
+
const mapped = mapTransformFunction(fn);
|
|
146
|
+
if (mapped)
|
|
147
|
+
ops.push(...mapped);
|
|
148
|
+
}
|
|
149
|
+
if (ops.length === 0)
|
|
150
|
+
return [];
|
|
151
|
+
return [['transform', ops]];
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Convert Tailwind v4's typed `rotate: ...` (individual property) into
|
|
155
|
+
* the RN transform array. Tailwind's `rotate-*` utilities emit this
|
|
156
|
+
* property rather than the classic `transform: rotate(...)` shorthand.
|
|
157
|
+
* @param value Typed rotate value.
|
|
158
|
+
* @returns Zero-or-one RN entry.
|
|
159
|
+
*/
|
|
160
|
+
function rotateToEntries(value) {
|
|
161
|
+
if (value === 'none')
|
|
162
|
+
return [];
|
|
163
|
+
return [['transform', [{ rotate: angleToString(value.angle) }]]];
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Convert Tailwind v4's typed `translate: ...` into the RN transform
|
|
167
|
+
* array. Both axes are emitted as separate ops so each is independently
|
|
168
|
+
* animatable by Reanimated.
|
|
169
|
+
* @param value Typed translate value.
|
|
170
|
+
* @returns Zero-or-one RN entry.
|
|
171
|
+
*/
|
|
172
|
+
function translateToEntries(value) {
|
|
173
|
+
if (value === 'none')
|
|
174
|
+
return [];
|
|
175
|
+
const ops = [{ translateX: lengthOrPercentToNumber(value.x) }];
|
|
176
|
+
const yNumber = lengthOrPercentToNumber(value.y);
|
|
177
|
+
if (yNumber !== 0)
|
|
178
|
+
ops.push({ translateY: yNumber });
|
|
179
|
+
return [['transform', ops]];
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Convert Tailwind v4's typed `scale: ...` into the RN transform array.
|
|
183
|
+
* @param value Typed scale value.
|
|
184
|
+
* @returns Zero-or-one RN entry.
|
|
185
|
+
*/
|
|
186
|
+
function scaleToEntries(value) {
|
|
187
|
+
if (value === 'none')
|
|
188
|
+
return [];
|
|
189
|
+
return [['transform', [{ scaleX: numberOrPercentageToNumber(value.x) }, { scaleY: numberOrPercentageToNumber(value.y) }]]];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export { rotateToEntries, scaleToEntries, transformFunctionsToEntries, translateToEntries };
|
|
193
|
+
//# sourceMappingURL=transform.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.mjs","sources":["../../../../../src/core/parser/transform.ts"],"sourcesContent":["import type { Angle, LengthValue, NumberOrPercentage, Rotate, Scale, Transform, Translate } from 'lightningcss'\nimport type { RNEntry } from './types'\nimport { lengthToPx } from './length'\n\ntype RnTransformRecord = Record<string, string | number>\n\ntype DimensionPercent =\n | { type: 'dimension'; value: LengthValue }\n | { type: 'percentage'; value: number }\n | { type: 'calc'; value: unknown }\n\n/**\n * Map a single typed transform function into zero-or-more RN transform\n * operations. Compound ops (like `translate`, `scale`, `skew`) expand\n * into per-axis entries the way RN expects them.\n * @param fn Typed transform function.\n * @returns RN transform operations.\n */\nfunction mapTransformFunction(fn: Transform): RnTransformRecord[] | null {\n switch (fn.type) {\n case 'rotate':\n case 'rotateZ': {\n return [{ rotate: angleToString(fn.value) }]\n }\n case 'rotateX': {\n return [{ rotateX: angleToString(fn.value) }]\n }\n case 'rotateY': {\n return [{ rotateY: angleToString(fn.value) }]\n }\n case 'scale': {\n const [x, y] = fn.value\n return [{ scaleX: numberOrPercentageToNumber(x) }, { scaleY: numberOrPercentageToNumber(y) }]\n }\n case 'scaleX': {\n return [{ scaleX: numberOrPercentageToNumber(fn.value) }]\n }\n case 'scaleY': {\n return [{ scaleY: numberOrPercentageToNumber(fn.value) }]\n }\n case 'translateX': {\n return [{ translateX: lengthOrPercentToNumber(fn.value) }]\n }\n case 'translateY': {\n return [{ translateY: lengthOrPercentToNumber(fn.value) }]\n }\n case 'translate': {\n const [x, y] = fn.value\n const out: RnTransformRecord[] = [{ translateX: lengthOrPercentToNumber(x) }]\n if (y) out.push({ translateY: lengthOrPercentToNumber(y) })\n return out\n }\n case 'translate3d': {\n const [x, y] = fn.value\n return [{ translateX: lengthOrPercentToNumber(x) }, { translateY: lengthOrPercentToNumber(y) }]\n }\n case 'skew': {\n const [x, y] = fn.value\n const out: RnTransformRecord[] = [{ skewX: angleToString(x) }]\n if (y) out.push({ skewY: angleToString(y) })\n return out\n }\n case 'skewX': {\n return [{ skewX: angleToString(fn.value) }]\n }\n case 'skewY': {\n return [{ skewY: angleToString(fn.value) }]\n }\n default: {\n // RN doesn't have a direct equivalent for `matrix()` / `matrix3d()` /\n // `perspective()` at the transform-op level — skip silently. Tailwind's\n // generated transforms stay within rotate/translate/scale/skew.\n return null\n }\n }\n}\n\n/**\n * Serialize a typed angle into the CSS degree string RN accepts\n * (`'45deg'`, `'0.5turn'` → `'180deg'`).\n * @param angle Typed angle.\n * @returns Degree string.\n */\nfunction angleToString(angle: Angle): string {\n switch (angle.type) {\n case 'deg': {\n return `${formatNumber(angle.value)}deg`\n }\n case 'rad': {\n return `${formatNumber((angle.value * 180) / Math.PI)}deg`\n }\n case 'grad': {\n return `${formatNumber((angle.value * 360) / 400)}deg`\n }\n case 'turn': {\n return `${formatNumber(angle.value * 360)}deg`\n }\n default: {\n return '0deg'\n }\n }\n}\n\n/**\n * Convert a `NumberOrPercentage` to a plain number. Percentages become\n * their fractional equivalent (e.g. `50%` → `0.5`).\n * @param value Typed value.\n * @returns Plain number.\n */\nfunction numberOrPercentageToNumber(value: NumberOrPercentage): number {\n if (value.type === 'percentage') return value.value\n return value.value\n}\n\n/**\n * Convert a length-or-percentage used by translate into the shape RN\n * accepts (`number` for px, `string` for `%`). Percentages stay as\n * strings so RN layout can resolve them against the element size.\n * @param value Typed length or percentage.\n * @returns RN-style translate value.\n */\nfunction lengthOrPercentToNumber(value: DimensionPercent | { type: 'value'; value: LengthValue }): number | string {\n if (value.type === 'dimension') return lengthToPx(value.value)\n if (value.type === 'value') return lengthToPx(value.value)\n if (value.type === 'percentage') return `${formatNumber(value.value * 100)}%`\n return 0\n}\n\n/**\n * Render a number without trailing IEEE noise.\n * @param value Number to format.\n * @returns Compact string form.\n */\nfunction formatNumber(value: number): string {\n const rounded = Math.round(value * 10_000) / 10_000\n return String(rounded)\n}\n\n/**\n * Convert lightningcss's typed `transform: ...` value into RN's\n * `transform: [{ op: value }, ...]` array. RN supports a restricted subset\n * of CSS transforms — this function picks out the ones it actually\n * handles and drops the rest.\n *\n * Reanimated v4's CSS engine reads this same array shape, so the output\n * is drop-in for both static RN `style` props and `Animated.View` styles.\n * @param fns Typed transform function list.\n * @returns Zero-or-one RN entry with the `transform` array.\n */\nexport function transformFunctionsToEntries(fns: readonly Transform[]): readonly RNEntry[] {\n const ops: RnTransformRecord[] = []\n for (const fn of fns) {\n const mapped = mapTransformFunction(fn)\n if (mapped) ops.push(...mapped)\n }\n if (ops.length === 0) return []\n return [['transform', ops]]\n}\n\n/**\n * Convert Tailwind v4's typed `rotate: ...` (individual property) into\n * the RN transform array. Tailwind's `rotate-*` utilities emit this\n * property rather than the classic `transform: rotate(...)` shorthand.\n * @param value Typed rotate value.\n * @returns Zero-or-one RN entry.\n */\nexport function rotateToEntries(value: Rotate | 'none'): readonly RNEntry[] {\n if (value === 'none') return []\n return [['transform', [{ rotate: angleToString(value.angle) }]]]\n}\n\n/**\n * Convert Tailwind v4's typed `translate: ...` into the RN transform\n * array. Both axes are emitted as separate ops so each is independently\n * animatable by Reanimated.\n * @param value Typed translate value.\n * @returns Zero-or-one RN entry.\n */\nexport function translateToEntries(value: Translate | 'none'): readonly RNEntry[] {\n if (value === 'none') return []\n const ops: RnTransformRecord[] = [{ translateX: lengthOrPercentToNumber(value.x) }]\n const yNumber = lengthOrPercentToNumber(value.y)\n if (yNumber !== 0) ops.push({ translateY: yNumber })\n return [['transform', ops]]\n}\n\n/**\n * Convert Tailwind v4's typed `scale: ...` into the RN transform array.\n * @param value Typed scale value.\n * @returns Zero-or-one RN entry.\n */\nexport function scaleToEntries(value: Scale | 'none'): readonly RNEntry[] {\n if (value === 'none') return []\n return [['transform', [{ scaleX: numberOrPercentageToNumber(value.x) }, { scaleY: numberOrPercentageToNumber(value.y) }]]]\n}\n"],"names":[],"mappings":";;AAWA;;;;;;AAMG;AACH,SAAS,oBAAoB,CAAC,EAAa,EAAA;AACzC,IAAA,QAAQ,EAAE,CAAC,IAAI;AACb,QAAA,KAAK,QAAQ;QACb,KAAK,SAAS,EAAE;AACd,YAAA,OAAO,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9C;QACA,KAAK,SAAS,EAAE;AACd,YAAA,OAAO,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/C;QACA,KAAK,SAAS,EAAE;AACd,YAAA,OAAO,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/C;QACA,KAAK,OAAO,EAAE;YACZ,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK;AACvB,YAAA,OAAO,CAAC,EAAE,MAAM,EAAE,0BAA0B,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,0BAA0B,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/F;QACA,KAAK,QAAQ,EAAE;AACb,YAAA,OAAO,CAAC,EAAE,MAAM,EAAE,0BAA0B,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3D;QACA,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,KAAK,MAAM;AAAE,QAAA,OAAO,EAAE;AAC/B,IAAA,MAAM,GAAG,GAAwB,CAAC,EAAE,UAAU,EAAE,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IACnF,MAAM,OAAO,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,IAAI,OAAO,KAAK,CAAC;QAAE,GAAG,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AACpD,IAAA,OAAO,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AAC7B;AAEA;;;;AAIG;AACG,SAAU,cAAc,CAAC,KAAqB,EAAA;IAClD,IAAI,KAAK,KAAK,MAAM;AAAE,QAAA,OAAO,EAAE;AAC/B,IAAA,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,0BAA0B,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,0BAA0B,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5H;;;;"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { type SourceEntry } from '@tailwindcss/oxide';
|
|
2
|
+
import { type GradientAtomInfo } from './gradient';
|
|
3
|
+
import { type HapticRequest } from './haptics';
|
|
4
|
+
import type { RNStyle } from './types';
|
|
5
|
+
/** Parser configuration — one instance per Metro session, theme CSS fixed. */
|
|
6
|
+
export interface TailwindParserConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Theme CSS passed to `@tailwindcss/node`'s compiler. Typically the
|
|
9
|
+
* user's `global.css`. We append `theme(inline)` to the tailwindcss
|
|
10
|
+
* import so Tailwind resolves every `var(--theme-token)` at compile
|
|
11
|
+
* time — that gives lightningcss fully-typed values (integers / rems /
|
|
12
|
+
* colors) instead of unresolved `var()` references.
|
|
13
|
+
*/
|
|
14
|
+
themeCss: string;
|
|
15
|
+
/**
|
|
16
|
+
* Glob sources the oxide Scanner walks at project-scan time
|
|
17
|
+
* (`parseProject()`). Typically
|
|
18
|
+
* `[{ base: projectRoot, pattern: '**\/*.{ts,tsx,js,jsx}', negated: false }]`
|
|
19
|
+
* plus negated globs for `node_modules` and the rnwind cache dir.
|
|
20
|
+
*
|
|
21
|
+
* When omitted, the scanner has no sources and `parseProject()`
|
|
22
|
+
* returns an empty result — `parseAtoms()` (per-file, content-driven)
|
|
23
|
+
* still works without sources.
|
|
24
|
+
*/
|
|
25
|
+
sources?: readonly SourceEntry[];
|
|
26
|
+
}
|
|
27
|
+
/** Per-call inputs — Metro hands us file content + filename; we derive the extension. */
|
|
28
|
+
export interface ParseOptions {
|
|
29
|
+
content: string;
|
|
30
|
+
extension: string;
|
|
31
|
+
}
|
|
32
|
+
/** One parsed keyframe step — offset plus the RN style at that offset. */
|
|
33
|
+
export interface KeyframeStep {
|
|
34
|
+
offset: string;
|
|
35
|
+
style: RNStyle;
|
|
36
|
+
}
|
|
37
|
+
/** One parsed `@keyframes` animation block. */
|
|
38
|
+
export interface KeyframeBlock {
|
|
39
|
+
name: string;
|
|
40
|
+
steps: KeyframeStep[];
|
|
41
|
+
}
|
|
42
|
+
/** Interactive variant ('active' / 'focus') an `active:`/`focus:` atom carries. */
|
|
43
|
+
export type InteractiveStateTag = 'active' | 'focus';
|
|
44
|
+
/**
|
|
45
|
+
* Per-scheme resolved style for a single utility class. Keys are scheme
|
|
46
|
+
* names declared via `@variant <name>` in the theme CSS (or the synthetic
|
|
47
|
+
* `'base'` scheme for themes without variants). Values are the RN style
|
|
48
|
+
* object under that scheme.
|
|
49
|
+
*
|
|
50
|
+
* The reserved `__state` key is set on `active:` / `focus:` atoms so
|
|
51
|
+
* the build-side style-builder can tag the atom for `precomputeHoist`
|
|
52
|
+
* — which routes interactive atoms into the stated-hoist's 4-state
|
|
53
|
+
* precompute. Standard atoms have no `__state`.
|
|
54
|
+
*/
|
|
55
|
+
export type SchemedStyle = Readonly<Record<string, RNStyle>> & {
|
|
56
|
+
/** Interactive-state gate set by `active:` / `focus:` variants. */
|
|
57
|
+
readonly __state?: InteractiveStateTag;
|
|
58
|
+
};
|
|
59
|
+
/** Full result of one `parseAtoms` call. */
|
|
60
|
+
export interface ParsedOutput {
|
|
61
|
+
/** Resolved RN style per utility class, per declared scheme. */
|
|
62
|
+
atoms: Map<string, SchemedStyle>;
|
|
63
|
+
/** `@keyframes <name> { ... }` blocks the candidates pulled in. */
|
|
64
|
+
keyframes: Map<string, KeyframeBlock>;
|
|
65
|
+
/** `@property --x { initial-value: y }` declared custom-property defaults. */
|
|
66
|
+
propertyDefaults: Map<string, string>;
|
|
67
|
+
/**
|
|
68
|
+
* Gradient metadata per atom, for atoms that play a role in a
|
|
69
|
+
* Tailwind v4 gradient (`from-*`, `via-*`, `to-*`, `bg-gradient-to-*`,
|
|
70
|
+
* `bg-linear-to-*`). The transformer reads this map to extract
|
|
71
|
+
* `colors / start / end` props at JSX-rewrite time. Regular non-
|
|
72
|
+
* gradient atoms don't appear here.
|
|
73
|
+
*/
|
|
74
|
+
gradientAtoms: Map<string, GradientAtomInfo>;
|
|
75
|
+
/**
|
|
76
|
+
* Haptic metadata per atom for classes that emit a
|
|
77
|
+
* `--rnwind-haptic` marker. The transformer reads this map to
|
|
78
|
+
* strip the atom from the className and wire a mount-time or
|
|
79
|
+
* press-time call into the `onHaptics` callback registered on
|
|
80
|
+
* `<SchemeProvider>`.
|
|
81
|
+
*/
|
|
82
|
+
hapticAtoms: Map<string, HapticRequest>;
|
|
83
|
+
/** Candidates oxide surfaced, in document order. */
|
|
84
|
+
candidates: readonly string[];
|
|
85
|
+
/** Every scheme the theme declares (or `['base']` when there are no `@variant` blocks). */
|
|
86
|
+
schemes: readonly string[];
|
|
87
|
+
/**
|
|
88
|
+
* Responsive breakpoint name → minimum-width threshold (px). Pulled from
|
|
89
|
+
* `--breakpoint-*` tokens in the compiled `:root` block, so both
|
|
90
|
+
* Tailwind defaults (`sm`, `md`, `lg`, `xl`, `2xl`) and any user
|
|
91
|
+
* override (e.g. `--breakpoint-3xl: 120rem`) land here. Used by the
|
|
92
|
+
* style-builder to emit `registerBreakpoints({...})` in the manifest
|
|
93
|
+
* so the runtime can filter `md:*` / `lg:*` atoms based on the
|
|
94
|
+
* provider's `windowWidth`.
|
|
95
|
+
*/
|
|
96
|
+
breakpoints: ReadonlyMap<string, number>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Parses one source file's Tailwind usage into RN-ready style objects.
|
|
100
|
+
*
|
|
101
|
+
* Pipeline:
|
|
102
|
+
* 1. `@tailwindcss/oxide` Scanner finds every Tailwind candidate.
|
|
103
|
+
* 2. `@tailwindcss/node` compiler emits CSS for those candidates with
|
|
104
|
+
* theme tokens inlined.
|
|
105
|
+
* 3. lightningcss `transform` + typed visitor walks the emitted CSS:
|
|
106
|
+
* - `style` rules → per-class RN-style object.
|
|
107
|
+
* - `@keyframes` rules → per-name step map (Reanimated-ready).
|
|
108
|
+
* - `@property` rules → custom-property initial values.
|
|
109
|
+
*
|
|
110
|
+
* One instance holds one Scanner + one lazily-built compiler so repeated
|
|
111
|
+
* calls share upstream state. Theme CSS is fixed at construction — theme
|
|
112
|
+
* edits require a new parser.
|
|
113
|
+
*/
|
|
114
|
+
export declare class TailwindParser {
|
|
115
|
+
private readonly config;
|
|
116
|
+
private readonly scanner;
|
|
117
|
+
private compiler;
|
|
118
|
+
private readonly themeSchemes;
|
|
119
|
+
private readonly schemeAliases;
|
|
120
|
+
/**
|
|
121
|
+
* Scheme names declared via `@custom-variant <name> …;`. A scheme
|
|
122
|
+
* listed here but absent from {@link themeSchemes} (no `@variant`
|
|
123
|
+
* override block) draws its values from the base `@theme` — the
|
|
124
|
+
* standard Tailwind v4 "light defaults + dark override" shape.
|
|
125
|
+
*/
|
|
126
|
+
private readonly customVariantSchemes;
|
|
127
|
+
/**
|
|
128
|
+
* Memoise `resolveCandidates` results by candidate-list fingerprint.
|
|
129
|
+
* Fast Refresh hits this on every save: oxide's scan is cheap, but
|
|
130
|
+
* the LightningCSS visitor walk over the compiled CSS is ~2ms per
|
|
131
|
+
* file. A file whose `className` literals didn't change returns the
|
|
132
|
+
* SAME candidate set, so the second `parseAtoms` call returns the
|
|
133
|
+
* cached `ParsedOutput` — zero compile, zero visitor walk.
|
|
134
|
+
*
|
|
135
|
+
* Theme CSS changes build a new `TailwindParser` (from
|
|
136
|
+
* `getRnwindState` detecting the hash shift), so this cache is
|
|
137
|
+
* naturally invalidated — no stale-theme values leak through.
|
|
138
|
+
*/
|
|
139
|
+
private readonly parseCache;
|
|
140
|
+
/**
|
|
141
|
+
* Build a parser bound to a theme CSS source. `@theme` and
|
|
142
|
+
* `@variant` blocks are extracted eagerly into a scheme table the
|
|
143
|
+
* visitor consults when resolving `var(--x)` references.
|
|
144
|
+
* @param config Parser configuration.
|
|
145
|
+
*/
|
|
146
|
+
constructor(config: TailwindParserConfig);
|
|
147
|
+
/**
|
|
148
|
+
* Schemes declared by the user — the union of every `@custom-variant
|
|
149
|
+
* <name>` declaration and every `@variant <name>` block, or just
|
|
150
|
+
* `['base']` for themes without any. Used to decide how many
|
|
151
|
+
* per-scheme buckets the per-atom resolver fills. Exposed publicly so
|
|
152
|
+
* Metro integration can hand the names to the `.d.ts` generator
|
|
153
|
+
* without a full parse.
|
|
154
|
+
*
|
|
155
|
+
* Both sources matter. `@variant` blocks alone miss the common
|
|
156
|
+
* Tailwind v4 shape where the light palette sits in the base `@theme`
|
|
157
|
+
* and only `@variant dark` overrides it: there `light` exists solely
|
|
158
|
+
* as a `@custom-variant` and would otherwise be dropped, collapsing
|
|
159
|
+
* every themed atom to a single bucket that can't switch.
|
|
160
|
+
* `@custom-variant` order wins (it's where users enumerate their
|
|
161
|
+
* schemes); any `@variant`-only scheme is appended after.
|
|
162
|
+
* @returns Scheme names.
|
|
163
|
+
*/
|
|
164
|
+
get declaredSchemes(): readonly string[];
|
|
165
|
+
/**
|
|
166
|
+
* Build an effective var table for one scheme — base vars overridden by
|
|
167
|
+
* variant vars. When the scheme IS `'base'` (no variants declared), the
|
|
168
|
+
* base table is returned unchanged.
|
|
169
|
+
* @param scheme Scheme name.
|
|
170
|
+
* @returns Effective var name → value lookup for the scheme.
|
|
171
|
+
*/
|
|
172
|
+
private effectiveVars;
|
|
173
|
+
/**
|
|
174
|
+
* Build the Tailwind compiler on first use and cache it. The theme CSS
|
|
175
|
+
* gets a `theme(inline)` modifier on its `@import 'tailwindcss'` so
|
|
176
|
+
* lightningcss sees resolved colors/lengths instead of `var()` refs.
|
|
177
|
+
* @returns Cached compiler instance.
|
|
178
|
+
*/
|
|
179
|
+
private ensureCompiler;
|
|
180
|
+
/**
|
|
181
|
+
* Parse one file's Tailwind usage into the full typed result.
|
|
182
|
+
* @param options Source content + extension.
|
|
183
|
+
* @param options.content Raw source text to scan for Tailwind candidates.
|
|
184
|
+
* @param options.extension File extension (`tsx`, `ts`, `jsx`, `js`) — feeds oxide's tokenizer.
|
|
185
|
+
* @returns RN atoms, keyframes, property defaults, candidates list.
|
|
186
|
+
*/
|
|
187
|
+
parseAtoms({ content, extension }: ParseOptions): Promise<ParsedOutput>;
|
|
188
|
+
/**
|
|
189
|
+
* Scan every source file the Scanner was configured to watch via
|
|
190
|
+
* `sources` and resolve the union of candidates in one pass. Used by
|
|
191
|
+
* `UnionBuilder` at Metro startup (and on first worker access) to
|
|
192
|
+
* populate the complete atom registry before ANY per-file transform
|
|
193
|
+
* has run — so scheme files never ship a partial view of the theme.
|
|
194
|
+
*
|
|
195
|
+
* Hot-reload path uses `parseAtoms` for the per-file delta; this one
|
|
196
|
+
* only runs once per parser instance (and whenever the parser is
|
|
197
|
+
* rebuilt due to a theme CSS change).
|
|
198
|
+
* @returns Full RN atoms, keyframes, property defaults for every
|
|
199
|
+
* candidate discovered across the configured sources.
|
|
200
|
+
*/
|
|
201
|
+
parseProject(): Promise<ParsedOutput>;
|
|
202
|
+
/**
|
|
203
|
+
* Compile + typed-visit the given candidate class names. Shared
|
|
204
|
+
* implementation for both `parseAtoms` (single file) and
|
|
205
|
+
* `parseProject` (whole project).
|
|
206
|
+
* @param candidates Class-name candidates the oxide Scanner produced.
|
|
207
|
+
* @returns Fully-typed parser result.
|
|
208
|
+
*/
|
|
209
|
+
private resolveCandidates;
|
|
210
|
+
}
|