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,180 @@
|
|
|
1
|
+
import { cssColorToString } from './color.mjs';
|
|
2
|
+
import { lengthPercentageOrAutoToValue, dimensionPercentageToNumber, gapValueToValue } from './length.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Expand `margin` / `padding` shorthand (`{top, right, bottom, left}`) to
|
|
6
|
+
* RN entries. Collapses progressively for a smaller emitted style:
|
|
7
|
+
* - all four equal → single `padding` / `margin`
|
|
8
|
+
* - matching axes → `paddingHorizontal` + `paddingVertical`
|
|
9
|
+
* - one matching axis → that axis collapsed, opposite axis as longhands
|
|
10
|
+
* - otherwise → four longhands
|
|
11
|
+
* @param property `'padding'` or `'margin'`.
|
|
12
|
+
* @param value Typed shorthand record.
|
|
13
|
+
* @returns RN entries.
|
|
14
|
+
*/
|
|
15
|
+
function expandFourSided(property, value) {
|
|
16
|
+
const top = lengthPercentageOrAutoToValue(value.top);
|
|
17
|
+
const right = lengthPercentageOrAutoToValue(value.right);
|
|
18
|
+
const bottom = lengthPercentageOrAutoToValue(value.bottom);
|
|
19
|
+
const left = lengthPercentageOrAutoToValue(value.left);
|
|
20
|
+
if (top === null || right === null || bottom === null || left === null)
|
|
21
|
+
return [];
|
|
22
|
+
if (top === right && right === bottom && bottom === left)
|
|
23
|
+
return [[property, top]];
|
|
24
|
+
const horizontalEqual = left === right;
|
|
25
|
+
const verticalEqual = top === bottom;
|
|
26
|
+
if (horizontalEqual && verticalEqual) {
|
|
27
|
+
return [
|
|
28
|
+
[`${property}Vertical`, top],
|
|
29
|
+
[`${property}Horizontal`, left],
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
if (horizontalEqual) {
|
|
33
|
+
return [
|
|
34
|
+
[`${property}Top`, top],
|
|
35
|
+
[`${property}Bottom`, bottom],
|
|
36
|
+
[`${property}Horizontal`, left],
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
if (verticalEqual) {
|
|
40
|
+
return [
|
|
41
|
+
[`${property}Vertical`, top],
|
|
42
|
+
[`${property}Right`, right],
|
|
43
|
+
[`${property}Left`, left],
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
return [
|
|
47
|
+
[`${property}Top`, top],
|
|
48
|
+
[`${property}Right`, right],
|
|
49
|
+
[`${property}Bottom`, bottom],
|
|
50
|
+
[`${property}Left`, left],
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Expand `padding-inline` / `margin-inline` (logical property) into RN's
|
|
55
|
+
* physical pair. RN has no RTL-aware logical props at the style-object
|
|
56
|
+
* level, so we lower at compile time. When both sides match, emit the
|
|
57
|
+
* single `paddingHorizontal` / `marginHorizontal` shorthand for a more
|
|
58
|
+
* compact style.
|
|
59
|
+
* @param property `'padding'` or `'margin'`.
|
|
60
|
+
* @param value Typed inline shorthand.
|
|
61
|
+
* @returns RN entries.
|
|
62
|
+
*/
|
|
63
|
+
function expandLogicalInline(property, value) {
|
|
64
|
+
const start = lengthPercentageOrAutoToValue(value.inlineStart);
|
|
65
|
+
const end = lengthPercentageOrAutoToValue(value.inlineEnd);
|
|
66
|
+
if (start === null || end === null)
|
|
67
|
+
return [];
|
|
68
|
+
if (start === end)
|
|
69
|
+
return [[`${property}Horizontal`, start]];
|
|
70
|
+
return [
|
|
71
|
+
[`${property}Left`, start],
|
|
72
|
+
[`${property}Right`, end],
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Expand `padding-block` / `margin-block` (logical property) into RN's
|
|
77
|
+
* physical pair. When both sides match, emit `paddingVertical` /
|
|
78
|
+
* `marginVertical` for a more compact style.
|
|
79
|
+
* @param property `'padding'` or `'margin'`.
|
|
80
|
+
* @param value Typed block shorthand.
|
|
81
|
+
* @returns RN entries.
|
|
82
|
+
*/
|
|
83
|
+
function expandLogicalBlock(property, value) {
|
|
84
|
+
const start = lengthPercentageOrAutoToValue(value.blockStart);
|
|
85
|
+
const end = lengthPercentageOrAutoToValue(value.blockEnd);
|
|
86
|
+
if (start === null || end === null)
|
|
87
|
+
return [];
|
|
88
|
+
if (start === end)
|
|
89
|
+
return [[`${property}Vertical`, start]];
|
|
90
|
+
return [
|
|
91
|
+
[`${property}Top`, start],
|
|
92
|
+
[`${property}Bottom`, end],
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Expand a `border-radius` shorthand into RN corner entries. Each corner
|
|
97
|
+
* is a 2-tuple `[x, y]` in lightningcss; RN exposes one radius per corner
|
|
98
|
+
* so we use the x-axis. When all four corners match, collapse to the
|
|
99
|
+
* single `borderRadius` key.
|
|
100
|
+
* @param value Typed `BorderRadius` record.
|
|
101
|
+
* @returns RN entries.
|
|
102
|
+
*/
|
|
103
|
+
function expandBorderRadius(value) {
|
|
104
|
+
const corners = [
|
|
105
|
+
['borderTopLeftRadius', dimensionPercentageToNumber(value.topLeft[0])],
|
|
106
|
+
['borderTopRightRadius', dimensionPercentageToNumber(value.topRight[0])],
|
|
107
|
+
['borderBottomRightRadius', dimensionPercentageToNumber(value.bottomRight[0])],
|
|
108
|
+
['borderBottomLeftRadius', dimensionPercentageToNumber(value.bottomLeft[0])],
|
|
109
|
+
];
|
|
110
|
+
const [first] = corners;
|
|
111
|
+
if (first?.[1] == null)
|
|
112
|
+
return [];
|
|
113
|
+
if (corners.every(([, v]) => v === first[1]))
|
|
114
|
+
return [['borderRadius', first[1]]];
|
|
115
|
+
return corners.filter((entry) => entry[1] !== null);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Expand a `border-color` shorthand into RN longhands. When all four
|
|
119
|
+
* sides match, collapse to a single `borderColor`; otherwise emit per-side
|
|
120
|
+
* props.
|
|
121
|
+
* @param value Typed `BorderColor` record.
|
|
122
|
+
* @returns RN entries.
|
|
123
|
+
*/
|
|
124
|
+
function expandBorderColor(value) {
|
|
125
|
+
const top = cssColorToString(value.top);
|
|
126
|
+
const right = cssColorToString(value.right);
|
|
127
|
+
const bottom = cssColorToString(value.bottom);
|
|
128
|
+
const left = cssColorToString(value.left);
|
|
129
|
+
if (top === right && right === bottom && bottom === left)
|
|
130
|
+
return [['borderColor', top]];
|
|
131
|
+
return [
|
|
132
|
+
['borderTopColor', top],
|
|
133
|
+
['borderRightColor', right],
|
|
134
|
+
['borderBottomColor', bottom],
|
|
135
|
+
['borderLeftColor', left],
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Expand `gap` shorthand (`{row, column}`) into RN entries. When both
|
|
140
|
+
* axes equal the same value collapse to the single `gap` key; otherwise
|
|
141
|
+
* emit `rowGap` + `columnGap`.
|
|
142
|
+
* @param value Typed `Gap` record.
|
|
143
|
+
* @returns RN entries.
|
|
144
|
+
*/
|
|
145
|
+
function expandGap(value) {
|
|
146
|
+
const row = gapValueToValue(value.row);
|
|
147
|
+
const column = gapValueToValue(value.column);
|
|
148
|
+
if (row === null || column === null)
|
|
149
|
+
return [];
|
|
150
|
+
if (row === column)
|
|
151
|
+
return [['gap', row]];
|
|
152
|
+
return [
|
|
153
|
+
['rowGap', row],
|
|
154
|
+
['columnGap', column],
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Convert `Flex` shorthand to RN entries. When the shape matches `flex:
|
|
159
|
+
* 1` (`{grow:1, shrink:1, basis: 0%}`), emit the single `flex` key RN
|
|
160
|
+
* understands. Otherwise expand to the three longhands.
|
|
161
|
+
* @param value Typed `Flex` record.
|
|
162
|
+
* @returns RN entries.
|
|
163
|
+
*/
|
|
164
|
+
function flexToEntries(value) {
|
|
165
|
+
const basis = lengthPercentageOrAutoToValue(value.basis);
|
|
166
|
+
if (basis === null)
|
|
167
|
+
return [];
|
|
168
|
+
if (value.grow === 1 && value.shrink === 1 && basis === '0%')
|
|
169
|
+
return [['flex', 1]];
|
|
170
|
+
const entries = [
|
|
171
|
+
['flexGrow', value.grow],
|
|
172
|
+
['flexShrink', value.shrink],
|
|
173
|
+
];
|
|
174
|
+
if (basis !== 'auto')
|
|
175
|
+
entries.push(['flexBasis', basis]);
|
|
176
|
+
return entries;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { expandBorderColor, expandBorderRadius, expandFourSided, expandGap, expandLogicalBlock, expandLogicalInline, flexToEntries };
|
|
180
|
+
//# sourceMappingURL=shorthand.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shorthand.mjs","sources":["../../../../../src/core/parser/shorthand.ts"],"sourcesContent":["import type {\n BorderColor,\n BorderRadius,\n Flex,\n Gap,\n Margin,\n MarginBlock,\n MarginInline,\n Padding,\n PaddingBlock,\n PaddingInline,\n} from 'lightningcss'\nimport { cssColorToString } from './color'\nimport { dimensionPercentageToNumber, gapValueToValue, lengthPercentageOrAutoToValue } from './length'\nimport type { RNEntry } from './types'\n\n/**\n * Expand `margin` / `padding` shorthand (`{top, right, bottom, left}`) to\n * RN entries. Collapses progressively for a smaller emitted style:\n * - all four equal → single `padding` / `margin`\n * - matching axes → `paddingHorizontal` + `paddingVertical`\n * - one matching axis → that axis collapsed, opposite axis as longhands\n * - otherwise → four longhands\n * @param property `'padding'` or `'margin'`.\n * @param value Typed shorthand record.\n * @returns RN entries.\n */\nexport function expandFourSided(property: 'padding' | 'margin', value: Padding | Margin): readonly RNEntry[] {\n const top = lengthPercentageOrAutoToValue(value.top)\n const right = lengthPercentageOrAutoToValue(value.right)\n const bottom = lengthPercentageOrAutoToValue(value.bottom)\n const left = lengthPercentageOrAutoToValue(value.left)\n if (top === null || right === null || bottom === null || left === null) return []\n if (top === right && right === bottom && bottom === left) return [[property, top]]\n const horizontalEqual = left === right\n const verticalEqual = top === bottom\n if (horizontalEqual && verticalEqual) {\n return [\n [`${property}Vertical`, top],\n [`${property}Horizontal`, left],\n ]\n }\n if (horizontalEqual) {\n return [\n [`${property}Top`, top],\n [`${property}Bottom`, bottom],\n [`${property}Horizontal`, left],\n ]\n }\n if (verticalEqual) {\n return [\n [`${property}Vertical`, top],\n [`${property}Right`, right],\n [`${property}Left`, left],\n ]\n }\n return [\n [`${property}Top`, top],\n [`${property}Right`, right],\n [`${property}Bottom`, bottom],\n [`${property}Left`, left],\n ]\n}\n\n/**\n * Expand `padding-inline` / `margin-inline` (logical property) into RN's\n * physical pair. RN has no RTL-aware logical props at the style-object\n * level, so we lower at compile time. When both sides match, emit the\n * single `paddingHorizontal` / `marginHorizontal` shorthand for a more\n * compact style.\n * @param property `'padding'` or `'margin'`.\n * @param value Typed inline shorthand.\n * @returns RN entries.\n */\nexport function expandLogicalInline(property: 'padding' | 'margin', value: PaddingInline | MarginInline): readonly RNEntry[] {\n const start = lengthPercentageOrAutoToValue(value.inlineStart)\n const end = lengthPercentageOrAutoToValue(value.inlineEnd)\n if (start === null || end === null) return []\n if (start === end) return [[`${property}Horizontal`, start]]\n return [\n [`${property}Left`, start],\n [`${property}Right`, end],\n ]\n}\n\n/**\n * Expand `padding-block` / `margin-block` (logical property) into RN's\n * physical pair. When both sides match, emit `paddingVertical` /\n * `marginVertical` for a more compact style.\n * @param property `'padding'` or `'margin'`.\n * @param value Typed block shorthand.\n * @returns RN entries.\n */\nexport function expandLogicalBlock(property: 'padding' | 'margin', value: PaddingBlock | MarginBlock): readonly RNEntry[] {\n const start = lengthPercentageOrAutoToValue(value.blockStart)\n const end = lengthPercentageOrAutoToValue(value.blockEnd)\n if (start === null || end === null) return []\n if (start === end) return [[`${property}Vertical`, start]]\n return [\n [`${property}Top`, start],\n [`${property}Bottom`, end],\n ]\n}\n\n/**\n * Expand a `border-radius` shorthand into RN corner entries. Each corner\n * is a 2-tuple `[x, y]` in lightningcss; RN exposes one radius per corner\n * so we use the x-axis. When all four corners match, collapse to the\n * single `borderRadius` key.\n * @param value Typed `BorderRadius` record.\n * @returns RN entries.\n */\nexport function expandBorderRadius(value: BorderRadius): readonly RNEntry[] {\n const corners: Array<[string, number | string | null]> = [\n ['borderTopLeftRadius', dimensionPercentageToNumber(value.topLeft[0])],\n ['borderTopRightRadius', dimensionPercentageToNumber(value.topRight[0])],\n ['borderBottomRightRadius', dimensionPercentageToNumber(value.bottomRight[0])],\n ['borderBottomLeftRadius', dimensionPercentageToNumber(value.bottomLeft[0])],\n ]\n const [first] = corners\n if (first?.[1] == null) return []\n if (corners.every(([, v]) => v === first[1])) return [['borderRadius', first[1]]]\n return corners.filter((entry): entry is [string, number | string] => entry[1] !== null)\n}\n\n/**\n * Expand a `border-color` shorthand into RN longhands. When all four\n * sides match, collapse to a single `borderColor`; otherwise emit per-side\n * props.\n * @param value Typed `BorderColor` record.\n * @returns RN entries.\n */\nexport function expandBorderColor(value: BorderColor): readonly RNEntry[] {\n const top = cssColorToString(value.top)\n const right = cssColorToString(value.right)\n const bottom = cssColorToString(value.bottom)\n const left = cssColorToString(value.left)\n if (top === right && right === bottom && bottom === left) return [['borderColor', top]]\n return [\n ['borderTopColor', top],\n ['borderRightColor', right],\n ['borderBottomColor', bottom],\n ['borderLeftColor', left],\n ]\n}\n\n/**\n * Expand `gap` shorthand (`{row, column}`) into RN entries. When both\n * axes equal the same value collapse to the single `gap` key; otherwise\n * emit `rowGap` + `columnGap`.\n * @param value Typed `Gap` record.\n * @returns RN entries.\n */\nexport function expandGap(value: Gap): readonly RNEntry[] {\n const row = gapValueToValue(value.row)\n const column = gapValueToValue(value.column)\n if (row === null || column === null) return []\n if (row === column) return [['gap', row]]\n return [\n ['rowGap', row],\n ['columnGap', column],\n ]\n}\n\n/**\n * Convert `Flex` shorthand to RN entries. When the shape matches `flex:\n * 1` (`{grow:1, shrink:1, basis: 0%}`), emit the single `flex` key RN\n * understands. Otherwise expand to the three longhands.\n * @param value Typed `Flex` record.\n * @returns RN entries.\n */\nexport function flexToEntries(value: Flex): readonly RNEntry[] {\n const basis = lengthPercentageOrAutoToValue(value.basis)\n if (basis === null) return []\n if (value.grow === 1 && value.shrink === 1 && basis === '0%') return [['flex', 1]]\n const entries: RNEntry[] = [\n ['flexGrow', value.grow],\n ['flexShrink', value.shrink],\n ]\n if (basis !== 'auto') entries.push(['flexBasis', basis])\n return entries\n}\n"],"names":[],"mappings":";;;AAgBA;;;;;;;;;;AAUG;AACG,SAAU,eAAe,CAAC,QAA8B,EAAE,KAAuB,EAAA;IACrF,MAAM,GAAG,GAAG,6BAA6B,CAAC,KAAK,CAAC,GAAG,CAAC;IACpD,MAAM,KAAK,GAAG,6BAA6B,CAAC,KAAK,CAAC,KAAK,CAAC;IACxD,MAAM,MAAM,GAAG,6BAA6B,CAAC,KAAK,CAAC,MAAM,CAAC;IAC1D,MAAM,IAAI,GAAG,6BAA6B,CAAC,KAAK,CAAC,IAAI,CAAC;AACtD,IAAA,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI;AAAE,QAAA,OAAO,EAAE;IACjF,IAAI,GAAG,KAAK,KAAK,IAAI,KAAK,KAAK,MAAM,IAAI,MAAM,KAAK,IAAI;AAAE,QAAA,OAAO,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AAClF,IAAA,MAAM,eAAe,GAAG,IAAI,KAAK,KAAK;AACtC,IAAA,MAAM,aAAa,GAAG,GAAG,KAAK,MAAM;AACpC,IAAA,IAAI,eAAe,IAAI,aAAa,EAAE;QACpC,OAAO;AACL,YAAA,CAAC,CAAA,EAAG,QAAQ,CAAA,QAAA,CAAU,EAAE,GAAG,CAAC;AAC5B,YAAA,CAAC,CAAA,EAAG,QAAQ,CAAA,UAAA,CAAY,EAAE,IAAI,CAAC;SAChC;IACH;IACA,IAAI,eAAe,EAAE;QACnB,OAAO;AACL,YAAA,CAAC,CAAA,EAAG,QAAQ,CAAA,GAAA,CAAK,EAAE,GAAG,CAAC;AACvB,YAAA,CAAC,CAAA,EAAG,QAAQ,CAAA,MAAA,CAAQ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EAAE,GAAG,CAAC;QACf,CAAC,WAAW,EAAE,MAAM,CAAC;KACtB;AACH;AAEA;;;;;;AAMG;AACG,SAAU,aAAa,CAAC,KAAW,EAAA;IACvC,MAAM,KAAK,GAAG,6BAA6B,CAAC,KAAK,CAAC,KAAK,CAAC;IACxD,IAAI,KAAK,KAAK,IAAI;AAAE,QAAA,OAAO,EAAE;AAC7B,IAAA,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI;AAAE,QAAA,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAClF,IAAA,MAAM,OAAO,GAAc;AACzB,QAAA,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC;AACxB,QAAA,CAAC,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC;KAC7B;IACD,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;AACxD,IAAA,OAAO,OAAO;AAChB;;;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text-truncate atom detector.
|
|
3
|
+
*
|
|
4
|
+
* React Native's `<Text>` exposes two props that cover every case
|
|
5
|
+
* Tailwind's text-truncation utilities express:
|
|
6
|
+
*
|
|
7
|
+
* numberOfLines — clamp after N lines (1 for single-line ellipsis)
|
|
8
|
+
* ellipsizeMode — 'tail' (ellipsis) or 'clip' at the truncation point
|
|
9
|
+
*
|
|
10
|
+
* rnwind treats the Tailwind classes as **metadata**: the transformer
|
|
11
|
+
* strips the truncate atoms from the JSX site's className and emits
|
|
12
|
+
* `numberOfLines={N}` / `ellipsizeMode="tail"` props on the element.
|
|
13
|
+
*
|
|
14
|
+
* Covered atoms:
|
|
15
|
+
* truncate → { numberOfLines: 1, ellipsizeMode: 'tail' }
|
|
16
|
+
* text-ellipsis → { ellipsizeMode: 'tail' }
|
|
17
|
+
* text-clip → { ellipsizeMode: 'clip' }
|
|
18
|
+
* line-clamp-<N> → { numberOfLines: <N> }
|
|
19
|
+
* line-clamp-none → { numberOfLines: 0 } (reset — overrides prior)
|
|
20
|
+
*
|
|
21
|
+
* Detection is pure name matching — no CSS inspection — because every
|
|
22
|
+
* relevant piece of data lives in the class name itself.
|
|
23
|
+
*/
|
|
24
|
+
/** Text-truncate metadata produced by a single atom. */
|
|
25
|
+
export interface TextTruncateInfo {
|
|
26
|
+
readonly numberOfLines?: number;
|
|
27
|
+
readonly ellipsizeMode?: 'tail' | 'clip';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Inspect one class-name token and return the text-truncate metadata it
|
|
31
|
+
* contributes, or `null` when the atom isn't a truncate utility.
|
|
32
|
+
* @param atom Single class-name token (no variant prefix).
|
|
33
|
+
* @returns The atom's contribution, or null.
|
|
34
|
+
*/
|
|
35
|
+
declare function detectTextTruncate(atom: string): TextTruncateInfo | null;
|
|
36
|
+
/**
|
|
37
|
+
* Fast pre-check — returns true when ANY atom in the list could be a
|
|
38
|
+
* truncate utility, false when none can. Lets callers skip the
|
|
39
|
+
* allocation of the merge pass for the common "no truncate" case.
|
|
40
|
+
* @param atoms Tokenised atom list from a literal className.
|
|
41
|
+
* @returns Whether to run the full per-atom detection.
|
|
42
|
+
*/
|
|
43
|
+
declare function mayContainTextTruncate(atoms: readonly string[]): boolean;
|
|
44
|
+
export { detectTextTruncate, mayContainTextTruncate };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text-truncate atom detector.
|
|
3
|
+
*
|
|
4
|
+
* React Native's `<Text>` exposes two props that cover every case
|
|
5
|
+
* Tailwind's text-truncation utilities express:
|
|
6
|
+
*
|
|
7
|
+
* numberOfLines — clamp after N lines (1 for single-line ellipsis)
|
|
8
|
+
* ellipsizeMode — 'tail' (ellipsis) or 'clip' at the truncation point
|
|
9
|
+
*
|
|
10
|
+
* rnwind treats the Tailwind classes as **metadata**: the transformer
|
|
11
|
+
* strips the truncate atoms from the JSX site's className and emits
|
|
12
|
+
* `numberOfLines={N}` / `ellipsizeMode="tail"` props on the element.
|
|
13
|
+
*
|
|
14
|
+
* Covered atoms:
|
|
15
|
+
* truncate → { numberOfLines: 1, ellipsizeMode: 'tail' }
|
|
16
|
+
* text-ellipsis → { ellipsizeMode: 'tail' }
|
|
17
|
+
* text-clip → { ellipsizeMode: 'clip' }
|
|
18
|
+
* line-clamp-<N> → { numberOfLines: <N> }
|
|
19
|
+
* line-clamp-none → { numberOfLines: 0 } (reset — overrides prior)
|
|
20
|
+
*
|
|
21
|
+
* Detection is pure name matching — no CSS inspection — because every
|
|
22
|
+
* relevant piece of data lives in the class name itself.
|
|
23
|
+
*/
|
|
24
|
+
/** Regex matching `line-clamp-<N>` with a positive-integer N. */
|
|
25
|
+
const LINE_CLAMP_RE = /^line-clamp-(\d+)$/;
|
|
26
|
+
/** Regex matching Tailwind v4's `line-clamp-[<value>]` arbitrary form. */
|
|
27
|
+
const LINE_CLAMP_ARBITRARY_RE = /^line-clamp-\[([^\]]+)\]$/;
|
|
28
|
+
/**
|
|
29
|
+
* Inspect one class-name token and return the text-truncate metadata it
|
|
30
|
+
* contributes, or `null` when the atom isn't a truncate utility.
|
|
31
|
+
* @param atom Single class-name token (no variant prefix).
|
|
32
|
+
* @returns The atom's contribution, or null.
|
|
33
|
+
*/
|
|
34
|
+
function detectTextTruncate(atom) {
|
|
35
|
+
if (atom === 'truncate')
|
|
36
|
+
return { numberOfLines: 1, ellipsizeMode: 'tail' };
|
|
37
|
+
if (atom === 'text-ellipsis')
|
|
38
|
+
return { ellipsizeMode: 'tail' };
|
|
39
|
+
if (atom === 'text-clip')
|
|
40
|
+
return { ellipsizeMode: 'clip' };
|
|
41
|
+
if (atom === 'line-clamp-none')
|
|
42
|
+
return { numberOfLines: 0 };
|
|
43
|
+
const numeric = LINE_CLAMP_RE.exec(atom);
|
|
44
|
+
if (numeric)
|
|
45
|
+
return { numberOfLines: Number(numeric[1]) };
|
|
46
|
+
const arbitrary = LINE_CLAMP_ARBITRARY_RE.exec(atom);
|
|
47
|
+
if (arbitrary) {
|
|
48
|
+
const n = Number.parseInt(arbitrary[1], 10);
|
|
49
|
+
if (Number.isFinite(n) && n >= 0)
|
|
50
|
+
return { numberOfLines: n };
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Fast pre-check — returns true when ANY atom in the list could be a
|
|
56
|
+
* truncate utility, false when none can. Lets callers skip the
|
|
57
|
+
* allocation of the merge pass for the common "no truncate" case.
|
|
58
|
+
* @param atoms Tokenised atom list from a literal className.
|
|
59
|
+
* @returns Whether to run the full per-atom detection.
|
|
60
|
+
*/
|
|
61
|
+
function mayContainTextTruncate(atoms) {
|
|
62
|
+
for (const atom of atoms) {
|
|
63
|
+
if (atom === 'truncate' ||
|
|
64
|
+
atom === 'text-ellipsis' ||
|
|
65
|
+
atom === 'text-clip' ||
|
|
66
|
+
atom === 'line-clamp-none' ||
|
|
67
|
+
atom.startsWith('line-clamp-')) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { detectTextTruncate, mayContainTextTruncate };
|
|
75
|
+
//# sourceMappingURL=text-truncate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-truncate.mjs","sources":["../../../../../src/core/parser/text-truncate.ts"],"sourcesContent":["/**\n * Text-truncate atom detector.\n *\n * React Native's `<Text>` exposes two props that cover every case\n * Tailwind's text-truncation utilities express:\n *\n * numberOfLines — clamp after N lines (1 for single-line ellipsis)\n * ellipsizeMode — 'tail' (ellipsis) or 'clip' at the truncation point\n *\n * rnwind treats the Tailwind classes as **metadata**: the transformer\n * strips the truncate atoms from the JSX site's className and emits\n * `numberOfLines={N}` / `ellipsizeMode=\"tail\"` props on the element.\n *\n * Covered atoms:\n * truncate → { numberOfLines: 1, ellipsizeMode: 'tail' }\n * text-ellipsis → { ellipsizeMode: 'tail' }\n * text-clip → { ellipsizeMode: 'clip' }\n * line-clamp-<N> → { numberOfLines: <N> }\n * line-clamp-none → { numberOfLines: 0 } (reset — overrides prior)\n *\n * Detection is pure name matching — no CSS inspection — because every\n * relevant piece of data lives in the class name itself.\n */\n\n/** Text-truncate metadata produced by a single atom. */\nexport interface TextTruncateInfo {\n readonly numberOfLines?: number\n readonly ellipsizeMode?: 'tail' | 'clip'\n}\n\n/** Regex matching `line-clamp-<N>` with a positive-integer N. */\nconst LINE_CLAMP_RE = /^line-clamp-(\\d+)$/\n/** Regex matching Tailwind v4's `line-clamp-[<value>]` arbitrary form. */\nconst LINE_CLAMP_ARBITRARY_RE = /^line-clamp-\\[([^\\]]+)\\]$/\n\n/**\n * Inspect one class-name token and return the text-truncate metadata it\n * contributes, or `null` when the atom isn't a truncate utility.\n * @param atom Single class-name token (no variant prefix).\n * @returns The atom's contribution, or null.\n */\nfunction detectTextTruncate(atom: string): TextTruncateInfo | null {\n if (atom === 'truncate') return { numberOfLines: 1, ellipsizeMode: 'tail' }\n if (atom === 'text-ellipsis') return { ellipsizeMode: 'tail' }\n if (atom === 'text-clip') return { ellipsizeMode: 'clip' }\n if (atom === 'line-clamp-none') return { numberOfLines: 0 }\n const numeric = LINE_CLAMP_RE.exec(atom)\n if (numeric) return { numberOfLines: Number(numeric[1]) }\n const arbitrary = LINE_CLAMP_ARBITRARY_RE.exec(atom)\n if (arbitrary) {\n const n = Number.parseInt(arbitrary[1]!, 10)\n if (Number.isFinite(n) && n >= 0) return { numberOfLines: n }\n }\n return null\n}\n\n/**\n * Fast pre-check — returns true when ANY atom in the list could be a\n * truncate utility, false when none can. Lets callers skip the\n * allocation of the merge pass for the common \"no truncate\" case.\n * @param atoms Tokenised atom list from a literal className.\n * @returns Whether to run the full per-atom detection.\n */\nfunction mayContainTextTruncate(atoms: readonly string[]): boolean {\n for (const atom of atoms) {\n if (\n atom === 'truncate' ||\n atom === 'text-ellipsis' ||\n atom === 'text-clip' ||\n atom === 'line-clamp-none' ||\n atom.startsWith('line-clamp-')\n ) {\n return true\n }\n }\n return false\n}\n\nexport { detectTextTruncate, mayContainTextTruncate }\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AAQH;AACA,MAAM,aAAa,GAAG,oBAAoB;AAC1C;AACA,MAAM,uBAAuB,GAAG,2BAA2B;AAE3D;;;;;AAKG;AACH,SAAS,kBAAkB,CAAC,IAAY,EAAA;IACtC,IAAI,IAAI,KAAK,UAAU;QAAE,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE;IAC3E,IAAI,IAAI,KAAK,eAAe;AAAE,QAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE;IAC9D,IAAI,IAAI,KAAK,WAAW;AAAE,QAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE;IAC1D,IAAI,IAAI,KAAK,iBAAiB;AAAE,QAAA,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE;IAC3D,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;AACxC,IAAA,IAAI,OAAO;QAAE,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;IACzD,MAAM,SAAS,GAAG,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC;IACpD,IAAI,SAAS,EAAE;AACb,QAAA,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAE,EAAE,EAAE,CAAC;QAC5C,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;AAAE,YAAA,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE;IAC/D;AACA,IAAA,OAAO,IAAI;AACb;AAEA;;;;;;AAMG;AACH,SAAS,sBAAsB,CAAC,KAAwB,EAAA;AACtD,IAAA,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,IACE,IAAI,KAAK,UAAU;AACnB,YAAA,IAAI,KAAK,eAAe;AACxB,YAAA,IAAI,KAAK,WAAW;AACpB,YAAA,IAAI,KAAK,iBAAiB;AAC1B,YAAA,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,EAC9B;AACA,YAAA,OAAO,IAAI;QACb;IACF;AACA,IAAA,OAAO,KAAK;AACd;;;;"}
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
/** Scheme name → (var name → value). The base scheme key is `'base'`. */
|
|
13
|
+
export type ThemeSchemeTable = Map<string, Map<string, string>>;
|
|
14
|
+
/** Synthetic scheme name used for tokens declared outside any `@variant`. */
|
|
15
|
+
export declare const BASE_SCHEME = "base";
|
|
16
|
+
/**
|
|
17
|
+
* Extract user-declared theme tokens from a CSS source. Scans for:
|
|
18
|
+
* - classic v4 `@theme` blocks (`@theme { --x: y; ... }`)
|
|
19
|
+
* - `@variant <name> { --x: y; ... }` inside any surrounding block
|
|
20
|
+
*
|
|
21
|
+
* Both flavors contribute to the returned table: vars outside any
|
|
22
|
+
* `@variant` go under `'base'`; vars inside `@variant <name>` go under
|
|
23
|
+
* `<name>`.
|
|
24
|
+
*
|
|
25
|
+
* Not a full CSS parser — just enough to recognise the token-declaration
|
|
26
|
+
* shape Tailwind v4 users actually write.
|
|
27
|
+
* @param css Theme CSS source.
|
|
28
|
+
* @returns Scheme → var-name → value map.
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractThemeVars(css: string): ThemeSchemeTable;
|
|
31
|
+
/**
|
|
32
|
+
* Build a `<class-in-selector> → <scheme-name>` alias map from any
|
|
33
|
+
* `@custom-variant <name> (<selector>);` declarations in the theme CSS.
|
|
34
|
+
*
|
|
35
|
+
* Tailwind compiles `dark:opacity-100` to a nested rule whose selector is
|
|
36
|
+
* the user's declared variant selector. When the user writes
|
|
37
|
+
* `@custom-variant dark (&:where(.scheme-dark, .scheme-dark *));`, the
|
|
38
|
+
* generated rule references `.scheme-dark` instead of the literal `.dark`
|
|
39
|
+
* class rnwind's selector matcher defaults to. This alias map lets the
|
|
40
|
+
* parser map those custom selector classes back to their scheme name.
|
|
41
|
+
* @param css Theme CSS source.
|
|
42
|
+
* @returns Class-name → scheme-name map. Empty when no `@custom-variant`
|
|
43
|
+
* declarations are present (rnwind's auto-generated defaults already
|
|
44
|
+
* use the literal scheme name and don't need an alias).
|
|
45
|
+
*/
|
|
46
|
+
export declare function extractSchemeAliases(css: string): Map<string, string>;
|
|
47
|
+
/**
|
|
48
|
+
* Collect every scheme name declared via `@custom-variant <name>
|
|
49
|
+
* (<class-selector>);` in first-appearance order.
|
|
50
|
+
*
|
|
51
|
+
* A scheme can be declared this way WITHOUT a matching `@variant <name>
|
|
52
|
+
* { … }` override block — its values then come entirely from the base
|
|
53
|
+
* `@theme`. That's Tailwind v4's standard shape: light defaults sit in
|
|
54
|
+
* `@theme` and only `@variant dark { … }` overrides them. Such a scheme
|
|
55
|
+
* still has to register so the runtime can switch to it, but
|
|
56
|
+
* {@link extractThemeVars} (which only sees `@variant` blocks) never
|
|
57
|
+
* surfaces it. The parser unions these names into its declared-scheme
|
|
58
|
+
* list so the base-only scheme isn't dropped.
|
|
59
|
+
*
|
|
60
|
+
* Only class-container selectors count — `@custom-variant` is Tailwind's
|
|
61
|
+
* general variant mechanism, so hover / focus / media / supports
|
|
62
|
+
* variants must NOT inflate the scheme list (or the generated `Scheme`
|
|
63
|
+
* union). See {@link isSchemeSelector}.
|
|
64
|
+
* @param css Theme CSS source.
|
|
65
|
+
* @returns Ordered, de-duplicated `@custom-variant` scheme names.
|
|
66
|
+
*/
|
|
67
|
+
export declare function extractCustomVariantSchemes(css: string): string[];
|
|
68
|
+
/**
|
|
69
|
+
* Rewrite the theme CSS so Tailwind's compiler accepts it:
|
|
70
|
+
* 1. Strip every `@variant <name> { ... }` block — Tailwind rejects
|
|
71
|
+
* them inline because `@variant` is a rnwind concept, not a Tailwind
|
|
72
|
+
* at-rule. The scheme-scoped vars are preserved in the extracted
|
|
73
|
+
* {@link ThemeSchemeTable} and substituted at walk time.
|
|
74
|
+
* 2. Prepend `@custom-variant <name> (&:where(.<name>, .<name> *));`
|
|
75
|
+
* for every scheme name we saw, so Tailwind accepts `light:bg-*`,
|
|
76
|
+
* `dark:bg-*`, etc. as valid class-name prefixes without the user
|
|
77
|
+
* having to duplicate the variant declaration.
|
|
78
|
+
* @param css Theme CSS source.
|
|
79
|
+
* @param table Scheme → var-name → value table from {@link extractThemeVars}.
|
|
80
|
+
* @returns CSS ready to feed `@tailwindcss/node`'s compiler.
|
|
81
|
+
*/
|
|
82
|
+
export declare function compileReadyTheme(css: string, table: ThemeSchemeTable): string;
|