rnwind 0.0.1 → 0.0.2
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 +164 -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 +100 -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 +96 -0
- package/lib/cjs/core/parser/length.cjs.map +1 -0
- package/lib/cjs/core/parser/length.d.ts +48 -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 +156 -0
- package/lib/cjs/core/parser/shorthand.cjs.map +1 -0
- package/lib/cjs/core/parser/shorthand.d.ts +61 -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 +414 -0
- package/lib/cjs/core/parser/theme-vars.cjs.map +1 -0
- package/lib/cjs/core/parser/theme-vars.d.ts +61 -0
- package/lib/cjs/core/parser/tokens.cjs +304 -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 +1567 -0
- package/lib/cjs/core/parser/tw-parser.cjs.map +1 -0
- package/lib/cjs/core/parser/tw-parser.d.ts +194 -0
- package/lib/cjs/core/parser/types.d.ts +37 -0
- package/lib/cjs/core/parser/typography-dispatcher.cjs +93 -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 +397 -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 +251 -0
- package/lib/cjs/metro/state.cjs.map +1 -0
- package/lib/cjs/metro/state.d.ts +72 -0
- package/lib/cjs/metro/transform-ast.cjs +1255 -0
- package/lib/cjs/metro/transform-ast.cjs.map +1 -0
- package/lib/cjs/metro/transform-ast.d.ts +73 -0
- package/lib/cjs/metro/transformer.cjs +345 -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 +57 -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 +162 -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 +98 -0
- package/lib/esm/core/parser/layout-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/length.d.ts +48 -0
- package/lib/esm/core/parser/length.mjs +90 -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 +61 -0
- package/lib/esm/core/parser/shorthand.mjs +148 -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 +61 -0
- package/lib/esm/core/parser/theme-vars.mjs +409 -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 +298 -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 +194 -0
- package/lib/esm/core/parser/tw-parser.mjs +1565 -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 +91 -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 +395 -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 +72 -0
- package/lib/esm/metro/state.mjs +243 -0
- package/lib/esm/metro/state.mjs.map +1 -0
- package/lib/esm/metro/transform-ast.d.ts +73 -0
- package/lib/esm/metro/transform-ast.mjs +1234 -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 +322 -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 +57 -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 +79 -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 +157 -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 +92 -0
- package/src/core/parser/length.ts +100 -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 +152 -0
- package/src/core/parser/text-truncate.ts +79 -0
- package/src/core/parser/theme-vars.ts +412 -0
- package/src/core/parser/tokens.ts +286 -0
- package/src/core/parser/transform.ts +195 -0
- package/src/core/parser/tw-parser.ts +1709 -0
- package/src/core/parser/types.ts +45 -0
- package/src/core/parser/typography-dispatcher.ts +83 -0
- package/src/core/parser/typography.ts +83 -0
- package/src/core/style-builder/build-style.ts +442 -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 +257 -0
- package/src/metro/transform-ast.ts +1498 -0
- package/src/metro/transformer.ts +347 -0
- package/src/metro/warn-unknown-classes.ts +79 -0
- package/src/metro/with-config.ts +229 -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,298 @@
|
|
|
1
|
+
import { BARE_NUMBER_REGEX, REM_TO_PX, LENGTH_PX_REGEX, LENGTH_REM_REGEX, CALC_RATIO_REGEX, CALC_MUL_REGEX } from './constants.mjs';
|
|
2
|
+
import { cssColorToString } from './color.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extract the fallback clause of a `var(--name, fallback)` by walking the
|
|
6
|
+
* string with paren-depth tracking. Linear-time; safe on nested
|
|
7
|
+
* `var(--a, var(--b, var(--c, 1rem)))` without regex backtracking.
|
|
8
|
+
* @param text CSS value already trimmed.
|
|
9
|
+
* @returns Fallback text, or `null` when `text` is not a `var(..., ...)`
|
|
10
|
+
* with a fallback.
|
|
11
|
+
*/
|
|
12
|
+
function extractVariableFallback(text) {
|
|
13
|
+
if (!text.startsWith('var(') || !text.endsWith(')'))
|
|
14
|
+
return null;
|
|
15
|
+
const inner = text.slice(4, -1);
|
|
16
|
+
let depth = 0;
|
|
17
|
+
for (let index = 0; index < inner.length; index += 1) {
|
|
18
|
+
const ch = inner[index];
|
|
19
|
+
if (ch === '(')
|
|
20
|
+
depth += 1;
|
|
21
|
+
else if (ch === ')')
|
|
22
|
+
depth -= 1;
|
|
23
|
+
else if (ch === ',' && depth === 0)
|
|
24
|
+
return inner.slice(index + 1).trim();
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Find the matching `)` for the opening `var(` whose body starts at
|
|
30
|
+
* `start`. Returns `-1` when the parens are unbalanced.
|
|
31
|
+
* @param text Source text.
|
|
32
|
+
* @param start Index just past the opening `var(`.
|
|
33
|
+
* @returns Index of the matching `)`, or `-1`.
|
|
34
|
+
*/
|
|
35
|
+
function findBalancedParenEnd(text, start) {
|
|
36
|
+
let depth = 1;
|
|
37
|
+
for (let index = start; index < text.length; index += 1) {
|
|
38
|
+
const ch = text[index];
|
|
39
|
+
if (ch === '(')
|
|
40
|
+
depth += 1;
|
|
41
|
+
else if (ch === ')') {
|
|
42
|
+
depth -= 1;
|
|
43
|
+
if (depth === 0)
|
|
44
|
+
return index;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return -1;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Resolve a `var(…)` body (the bit between parentheses). Reads the
|
|
51
|
+
* variable name, then either returns the table lookup or recurses into
|
|
52
|
+
* the fallback clause. When neither resolves, re-wraps as `var(…)` so
|
|
53
|
+
* downstream coercion still sees a well-formed reference.
|
|
54
|
+
* @param body Text between the outer parentheses of a `var()` call.
|
|
55
|
+
* @param table var → value map.
|
|
56
|
+
* @returns Substituted text fragment.
|
|
57
|
+
*/
|
|
58
|
+
function resolveVariableBody(body, table) {
|
|
59
|
+
let depth = 0;
|
|
60
|
+
let commaIndex = -1;
|
|
61
|
+
for (const [index, ch] of [...body].entries()) {
|
|
62
|
+
if (ch === '(')
|
|
63
|
+
depth += 1;
|
|
64
|
+
else if (ch === ')')
|
|
65
|
+
depth -= 1;
|
|
66
|
+
else if (ch === ',' && depth === 0) {
|
|
67
|
+
commaIndex = index;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const rawName = (commaIndex === -1 ? body : body.slice(0, commaIndex)).trim();
|
|
72
|
+
const fallback = commaIndex === -1 ? null : body.slice(commaIndex + 1).trim();
|
|
73
|
+
const resolved = table.get(rawName);
|
|
74
|
+
if (resolved !== undefined)
|
|
75
|
+
return resolved;
|
|
76
|
+
if (fallback !== null)
|
|
77
|
+
return substitutePass(fallback, table);
|
|
78
|
+
return `var(${body})`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* One pass of left-to-right `var(...)` substitution. Separate from the
|
|
82
|
+
* fixed-point driver so the recursion depth stays bounded.
|
|
83
|
+
* @param text Value text to scan.
|
|
84
|
+
* @param table var → value map.
|
|
85
|
+
* @returns Value text after one pass.
|
|
86
|
+
*/
|
|
87
|
+
function substitutePass(text, table) {
|
|
88
|
+
let out = '';
|
|
89
|
+
let index = 0;
|
|
90
|
+
while (index < text.length) {
|
|
91
|
+
const head = text.indexOf('var(', index);
|
|
92
|
+
if (head === -1) {
|
|
93
|
+
out += text.slice(index);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
out += text.slice(index, head);
|
|
97
|
+
const end = findBalancedParenEnd(text, head + 4);
|
|
98
|
+
if (end === -1) {
|
|
99
|
+
out += text.slice(head);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
const body = text.slice(head + 4, end);
|
|
103
|
+
out += resolveVariableBody(body, table);
|
|
104
|
+
index = end + 1;
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Serialize a list of `TokenOrValue` nodes into a CSS-ish value string.
|
|
110
|
+
* Preserves the CSS form closely enough for downstream numeric coercion.
|
|
111
|
+
* @param tokens Token list from an unparsed declaration or custom-property body.
|
|
112
|
+
* @returns Concatenated CSS-value fragment.
|
|
113
|
+
*/
|
|
114
|
+
function serializeTokens(tokens) {
|
|
115
|
+
let out = '';
|
|
116
|
+
for (const token of tokens)
|
|
117
|
+
out += serializeToken(token);
|
|
118
|
+
return out.trim();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Serialize one `TokenOrValue` node back to CSS text. Handles the shapes
|
|
122
|
+
* Tailwind v4 actually emits in utility-class bodies: raw tokens, `var()`
|
|
123
|
+
* references, and numeric functions (`calc()`).
|
|
124
|
+
* @param token One token node.
|
|
125
|
+
* @returns CSS-value fragment.
|
|
126
|
+
*/
|
|
127
|
+
function serializeToken(token) {
|
|
128
|
+
switch (token.type) {
|
|
129
|
+
case 'token': {
|
|
130
|
+
return serializeRawToken(token.value);
|
|
131
|
+
}
|
|
132
|
+
case 'var': {
|
|
133
|
+
const head = token.value.name.ident;
|
|
134
|
+
const { fallback } = token.value;
|
|
135
|
+
if (!fallback || fallback.length === 0)
|
|
136
|
+
return `var(${head})`;
|
|
137
|
+
return `var(${head}, ${serializeTokens(fallback)})`;
|
|
138
|
+
}
|
|
139
|
+
case 'function': {
|
|
140
|
+
return `${token.value.name}(${serializeTokens(token.value.arguments)})`;
|
|
141
|
+
}
|
|
142
|
+
case 'length': {
|
|
143
|
+
return `${token.value.value}${token.value.unit}`;
|
|
144
|
+
}
|
|
145
|
+
case 'dashed-ident': {
|
|
146
|
+
return token.value;
|
|
147
|
+
}
|
|
148
|
+
case 'angle': {
|
|
149
|
+
return `${token.value.value}${token.value.type}`;
|
|
150
|
+
}
|
|
151
|
+
case 'time': {
|
|
152
|
+
const unit = token.value.type === 'milliseconds' ? 'ms' : 's';
|
|
153
|
+
return `${token.value.value}${unit}`;
|
|
154
|
+
}
|
|
155
|
+
case 'resolution': {
|
|
156
|
+
return `${token.value.value}${token.value.type}`;
|
|
157
|
+
}
|
|
158
|
+
case 'color': {
|
|
159
|
+
// Pre-resolved CSS color (`oklch(...)`, `rgb(...)`, etc.) — render
|
|
160
|
+
// it back to a hex/rgba string RN can read.
|
|
161
|
+
return cssColorToString(token.value);
|
|
162
|
+
}
|
|
163
|
+
case 'env':
|
|
164
|
+
case 'unresolved-color':
|
|
165
|
+
case 'url':
|
|
166
|
+
case 'animation-name': {
|
|
167
|
+
return '';
|
|
168
|
+
}
|
|
169
|
+
default: {
|
|
170
|
+
return '';
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Serialize a raw `Token` back to CSS text. `TokenOrValue` with
|
|
176
|
+
* `type === 'token'` wraps one of these; the discriminated union lets
|
|
177
|
+
* TypeScript narrow per branch without casts.
|
|
178
|
+
* @param token Raw token.
|
|
179
|
+
* @returns CSS text fragment.
|
|
180
|
+
*/
|
|
181
|
+
function serializeRawToken(token) {
|
|
182
|
+
switch (token.type) {
|
|
183
|
+
case 'ident':
|
|
184
|
+
case 'at-keyword':
|
|
185
|
+
case 'string':
|
|
186
|
+
case 'unquoted-url':
|
|
187
|
+
case 'function': {
|
|
188
|
+
return token.value;
|
|
189
|
+
}
|
|
190
|
+
case 'hash':
|
|
191
|
+
case 'id-hash': {
|
|
192
|
+
return `#${token.value}`;
|
|
193
|
+
}
|
|
194
|
+
case 'number': {
|
|
195
|
+
return String(token.value);
|
|
196
|
+
}
|
|
197
|
+
case 'percentage': {
|
|
198
|
+
return `${token.value * 100}%`;
|
|
199
|
+
}
|
|
200
|
+
case 'dimension': {
|
|
201
|
+
return `${token.value}${token.unit}`;
|
|
202
|
+
}
|
|
203
|
+
case 'white-space': {
|
|
204
|
+
return ' ';
|
|
205
|
+
}
|
|
206
|
+
case 'delim': {
|
|
207
|
+
return token.value;
|
|
208
|
+
}
|
|
209
|
+
case 'comma': {
|
|
210
|
+
return ',';
|
|
211
|
+
}
|
|
212
|
+
case 'colon':
|
|
213
|
+
case 'semicolon':
|
|
214
|
+
case 'parenthesis-block':
|
|
215
|
+
case 'square-bracket-block':
|
|
216
|
+
case 'curly-bracket-block':
|
|
217
|
+
case 'cdo':
|
|
218
|
+
case 'cdc':
|
|
219
|
+
case 'include-match':
|
|
220
|
+
case 'dash-match':
|
|
221
|
+
case 'prefix-match':
|
|
222
|
+
case 'suffix-match':
|
|
223
|
+
case 'substring-match':
|
|
224
|
+
case 'comment':
|
|
225
|
+
case 'bad-url':
|
|
226
|
+
case 'bad-string': {
|
|
227
|
+
return '';
|
|
228
|
+
}
|
|
229
|
+
default: {
|
|
230
|
+
return '';
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Coerce the flat serialization of an unparsed value into an RN scalar.
|
|
236
|
+
* Handles the shapes Tailwind v4 actually emits: bare numbers, pixel /
|
|
237
|
+
* rem lengths, calc ratios, and `var(--x, fallback)` where we recurse into
|
|
238
|
+
* the fallback. Anything else passes through as a string.
|
|
239
|
+
* @param text Serialized CSS value.
|
|
240
|
+
* @returns Coerced primitive, or `null` when unrepresentable.
|
|
241
|
+
*/
|
|
242
|
+
function coerceUnparsedValue(text) {
|
|
243
|
+
const trimmed = text.trim();
|
|
244
|
+
if (trimmed.length === 0)
|
|
245
|
+
return null;
|
|
246
|
+
if (BARE_NUMBER_REGEX.test(trimmed))
|
|
247
|
+
return Number(trimmed);
|
|
248
|
+
const px = LENGTH_PX_REGEX.exec(trimmed);
|
|
249
|
+
if (px)
|
|
250
|
+
return Number(px[1]);
|
|
251
|
+
const rem = LENGTH_REM_REGEX.exec(trimmed);
|
|
252
|
+
if (rem)
|
|
253
|
+
return Number(rem[1]) * REM_TO_PX;
|
|
254
|
+
const fallback = extractVariableFallback(trimmed);
|
|
255
|
+
if (fallback !== null)
|
|
256
|
+
return coerceUnparsedValue(fallback);
|
|
257
|
+
const calcRatio = CALC_RATIO_REGEX.exec(trimmed);
|
|
258
|
+
if (calcRatio) {
|
|
259
|
+
const right = Number(calcRatio[2]);
|
|
260
|
+
if (right === 0)
|
|
261
|
+
return null;
|
|
262
|
+
return Number(calcRatio[1]) / right;
|
|
263
|
+
}
|
|
264
|
+
const calcMul = CALC_MUL_REGEX.exec(trimmed);
|
|
265
|
+
if (calcMul) {
|
|
266
|
+
// Unit-aware multiply: `calc(0.5rem * 2)` → 16 (rem scaled to px).
|
|
267
|
+
// Regex captures `(number)(unit?) * (number)` — the unit is implicit
|
|
268
|
+
// in the match position; rebuild via the full match text.
|
|
269
|
+
const unitMatch = /^calc\(\s*-?\d+(?:\.\d+)?(rem|px)?/.exec(trimmed);
|
|
270
|
+
const unit = unitMatch?.[1];
|
|
271
|
+
const base = Number(calcMul[1]) * Number(calcMul[2]);
|
|
272
|
+
return unit === 'rem' ? base * REM_TO_PX : base;
|
|
273
|
+
}
|
|
274
|
+
return trimmed;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Substitute every `var(--name [, fallback])` reference in `text` with
|
|
278
|
+
* the value from `table` (or the fallback clause when the name misses).
|
|
279
|
+
* Paren-balanced so nested `var(…)` refs don't confuse the scanner.
|
|
280
|
+
* Iterates to a fixed point so multi-hop substitutions land in one call
|
|
281
|
+
* (with a safety cap so a malformed self-referential token can't loop).
|
|
282
|
+
* @param text Raw CSS value.
|
|
283
|
+
* @param table var name → resolved value map.
|
|
284
|
+
* @returns Substituted text.
|
|
285
|
+
*/
|
|
286
|
+
function substituteThemeVars(text, table) {
|
|
287
|
+
let current = text;
|
|
288
|
+
for (let pass = 0; pass < 8; pass += 1) {
|
|
289
|
+
const next = substitutePass(current, table);
|
|
290
|
+
if (next === current)
|
|
291
|
+
return next;
|
|
292
|
+
current = next;
|
|
293
|
+
}
|
|
294
|
+
return current;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export { coerceUnparsedValue, serializeRawToken, serializeToken, serializeTokens, substituteThemeVars };
|
|
298
|
+
//# sourceMappingURL=tokens.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.mjs","sources":["../../../../../src/core/parser/tokens.ts"],"sourcesContent":["import type { Token, TokenOrValue } from 'lightningcss'\nimport { BARE_NUMBER_REGEX, CALC_MUL_REGEX, CALC_RATIO_REGEX, LENGTH_PX_REGEX, LENGTH_REM_REGEX, REM_TO_PX } from './constants'\nimport { cssColorToString } from './color'\nimport type { RNStyleValue } from './types'\n\n/**\n * Extract the fallback clause of a `var(--name, fallback)` by walking the\n * string with paren-depth tracking. Linear-time; safe on nested\n * `var(--a, var(--b, var(--c, 1rem)))` without regex backtracking.\n * @param text CSS value already trimmed.\n * @returns Fallback text, or `null` when `text` is not a `var(..., ...)`\n * with a fallback.\n */\nfunction extractVariableFallback(text: string): string | null {\n if (!text.startsWith('var(') || !text.endsWith(')')) return null\n const inner = text.slice(4, -1)\n let depth = 0\n for (let index = 0; index < inner.length; index += 1) {\n const ch = inner[index]\n if (ch === '(') depth += 1\n else if (ch === ')') depth -= 1\n else if (ch === ',' && depth === 0) return inner.slice(index + 1).trim()\n }\n return null\n}\n\n/**\n * Find the matching `)` for the opening `var(` whose body starts at\n * `start`. Returns `-1` when the parens are unbalanced.\n * @param text Source text.\n * @param start Index just past the opening `var(`.\n * @returns Index of the matching `)`, or `-1`.\n */\nfunction findBalancedParenEnd(text: string, start: number): number {\n let depth = 1\n for (let index = start; index < text.length; index += 1) {\n const ch = text[index]\n if (ch === '(') depth += 1\n else if (ch === ')') {\n depth -= 1\n if (depth === 0) return index\n }\n }\n return -1\n}\n\n/**\n * Resolve a `var(…)` body (the bit between parentheses). Reads the\n * variable name, then either returns the table lookup or recurses into\n * the fallback clause. When neither resolves, re-wraps as `var(…)` so\n * downstream coercion still sees a well-formed reference.\n * @param body Text between the outer parentheses of a `var()` call.\n * @param table var → value map.\n * @returns Substituted text fragment.\n */\nfunction resolveVariableBody(body: string, table: ReadonlyMap<string, string>): string {\n let depth = 0\n let commaIndex = -1\n for (const [index, ch] of [...body].entries()) {\n if (ch === '(') depth += 1\n else if (ch === ')') depth -= 1\n else if (ch === ',' && depth === 0) {\n commaIndex = index\n break\n }\n }\n const rawName = (commaIndex === -1 ? body : body.slice(0, commaIndex)).trim()\n const fallback = commaIndex === -1 ? null : body.slice(commaIndex + 1).trim()\n const resolved = table.get(rawName)\n if (resolved !== undefined) return resolved\n if (fallback !== null) return substitutePass(fallback, table)\n return `var(${body})`\n}\n\n/**\n * One pass of left-to-right `var(...)` substitution. Separate from the\n * fixed-point driver so the recursion depth stays bounded.\n * @param text Value text to scan.\n * @param table var → value map.\n * @returns Value text after one pass.\n */\nfunction substitutePass(text: string, table: ReadonlyMap<string, string>): string {\n let out = ''\n let index = 0\n while (index < text.length) {\n const head = text.indexOf('var(', index)\n if (head === -1) {\n out += text.slice(index)\n break\n }\n out += text.slice(index, head)\n const end = findBalancedParenEnd(text, head + 4)\n if (end === -1) {\n out += text.slice(head)\n break\n }\n const body = text.slice(head + 4, end)\n out += resolveVariableBody(body, table)\n index = end + 1\n }\n return out\n}\n\n/**\n * Serialize a list of `TokenOrValue` nodes into a CSS-ish value string.\n * Preserves the CSS form closely enough for downstream numeric coercion.\n * @param tokens Token list from an unparsed declaration or custom-property body.\n * @returns Concatenated CSS-value fragment.\n */\nexport function serializeTokens(tokens: readonly TokenOrValue[]): string {\n let out = ''\n for (const token of tokens) out += serializeToken(token)\n return out.trim()\n}\n\n/**\n * Serialize one `TokenOrValue` node back to CSS text. Handles the shapes\n * Tailwind v4 actually emits in utility-class bodies: raw tokens, `var()`\n * references, and numeric functions (`calc()`).\n * @param token One token node.\n * @returns CSS-value fragment.\n */\nexport function serializeToken(token: TokenOrValue): string {\n switch (token.type) {\n case 'token': {\n return serializeRawToken(token.value)\n }\n case 'var': {\n const head = token.value.name.ident\n const { fallback } = token.value\n if (!fallback || fallback.length === 0) return `var(${head})`\n return `var(${head}, ${serializeTokens(fallback)})`\n }\n case 'function': {\n return `${token.value.name}(${serializeTokens(token.value.arguments)})`\n }\n case 'length': {\n return `${token.value.value}${token.value.unit}`\n }\n case 'dashed-ident': {\n return token.value\n }\n case 'angle': {\n return `${token.value.value}${token.value.type}`\n }\n case 'time': {\n const unit = token.value.type === 'milliseconds' ? 'ms' : 's'\n return `${token.value.value}${unit}`\n }\n case 'resolution': {\n return `${token.value.value}${token.value.type}`\n }\n case 'color': {\n // Pre-resolved CSS color (`oklch(...)`, `rgb(...)`, etc.) — render\n // it back to a hex/rgba string RN can read.\n return cssColorToString(token.value)\n }\n case 'env':\n case 'unresolved-color':\n case 'url':\n case 'animation-name': {\n return ''\n }\n default: {\n return ''\n }\n }\n}\n\n/**\n * Serialize a raw `Token` back to CSS text. `TokenOrValue` with\n * `type === 'token'` wraps one of these; the discriminated union lets\n * TypeScript narrow per branch without casts.\n * @param token Raw token.\n * @returns CSS text fragment.\n */\nexport function serializeRawToken(token: Token): string {\n switch (token.type) {\n case 'ident':\n case 'at-keyword':\n case 'string':\n case 'unquoted-url':\n case 'function': {\n return token.value\n }\n case 'hash':\n case 'id-hash': {\n return `#${token.value}`\n }\n case 'number': {\n return String(token.value)\n }\n case 'percentage': {\n return `${token.value * 100}%`\n }\n case 'dimension': {\n return `${token.value}${token.unit}`\n }\n case 'white-space': {\n return ' '\n }\n case 'delim': {\n return token.value\n }\n case 'comma': {\n return ','\n }\n case 'colon':\n case 'semicolon':\n case 'parenthesis-block':\n case 'square-bracket-block':\n case 'curly-bracket-block':\n case 'cdo':\n case 'cdc':\n case 'include-match':\n case 'dash-match':\n case 'prefix-match':\n case 'suffix-match':\n case 'substring-match':\n case 'comment':\n case 'bad-url':\n case 'bad-string': {\n return ''\n }\n default: {\n return ''\n }\n }\n}\n\n/**\n * Coerce the flat serialization of an unparsed value into an RN scalar.\n * Handles the shapes Tailwind v4 actually emits: bare numbers, pixel /\n * rem lengths, calc ratios, and `var(--x, fallback)` where we recurse into\n * the fallback. Anything else passes through as a string.\n * @param text Serialized CSS value.\n * @returns Coerced primitive, or `null` when unrepresentable.\n */\nexport function coerceUnparsedValue(text: string): RNStyleValue | null {\n const trimmed = text.trim()\n if (trimmed.length === 0) return null\n if (BARE_NUMBER_REGEX.test(trimmed)) return Number(trimmed)\n const px = LENGTH_PX_REGEX.exec(trimmed)\n if (px) return Number(px[1])\n const rem = LENGTH_REM_REGEX.exec(trimmed)\n if (rem) return Number(rem[1]) * REM_TO_PX\n const fallback = extractVariableFallback(trimmed)\n if (fallback !== null) return coerceUnparsedValue(fallback)\n const calcRatio = CALC_RATIO_REGEX.exec(trimmed)\n if (calcRatio) {\n const right = Number(calcRatio[2])\n if (right === 0) return null\n return Number(calcRatio[1]) / right\n }\n const calcMul = CALC_MUL_REGEX.exec(trimmed)\n if (calcMul) {\n // Unit-aware multiply: `calc(0.5rem * 2)` → 16 (rem scaled to px).\n // Regex captures `(number)(unit?) * (number)` — the unit is implicit\n // in the match position; rebuild via the full match text.\n const unitMatch = /^calc\\(\\s*-?\\d+(?:\\.\\d+)?(rem|px)?/.exec(trimmed)\n const unit = unitMatch?.[1]\n const base = Number(calcMul[1]) * Number(calcMul[2])\n return unit === 'rem' ? base * REM_TO_PX : base\n }\n return trimmed\n}\n\n/**\n * Substitute every `var(--name [, fallback])` reference in `text` with\n * the value from `table` (or the fallback clause when the name misses).\n * Paren-balanced so nested `var(…)` refs don't confuse the scanner.\n * Iterates to a fixed point so multi-hop substitutions land in one call\n * (with a safety cap so a malformed self-referential token can't loop).\n * @param text Raw CSS value.\n * @param table var name → resolved value map.\n * @returns Substituted text.\n */\nexport function substituteThemeVars(text: string, table: ReadonlyMap<string, string>): string {\n let current = text\n for (let pass = 0; pass < 8; pass += 1) {\n const next = substitutePass(current, table)\n if (next === current) return next\n current = next\n }\n return current\n}\n"],"names":[],"mappings":";;;AAKA;;;;;;;AAOG;AACH,SAAS,uBAAuB,CAAC,IAAY,EAAA;AAC3C,IAAA,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,IAAI;IAChE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;IAC/B,IAAI,KAAK,GAAG,CAAC;AACb,IAAA,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE;AACpD,QAAA,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC;QACvB,IAAI,EAAE,KAAK,GAAG;YAAE,KAAK,IAAI,CAAC;aACrB,IAAI,EAAE,KAAK,GAAG;YAAE,KAAK,IAAI,CAAC;AAC1B,aAAA,IAAI,EAAE,KAAK,GAAG,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE;IAC1E;AACA,IAAA,OAAO,IAAI;AACb;AAEA;;;;;;AAMG;AAC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CAAC;IAChD,IAAI,SAAS,EAAE;QACb,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAClC,IAAI,KAAK,KAAK,CAAC;AAAE,YAAA,OAAO,IAAI;QAC5B,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;IACrC;IACA,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC;IAC5C,IAAI,OAAO,EAAE;;;;QAIX,MAAM,SAAS,GAAG,oCAAoC,CAAC,IAAI,CAAC,OAAO,CAAC;AACpE,QAAA,MAAM,IAAI,GAAG,SAAS,GAAG,CAAC,CAAC;AAC3B,QAAA,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACpD,QAAA,OAAO,IAAI,KAAK,KAAK,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI;IACjD;AACA,IAAA,OAAO,OAAO;AAChB;AAEA;;;;;;;;;AASG;AACG,SAAU,mBAAmB,CAAC,IAAY,EAAE,KAAkC,EAAA;IAClF,IAAI,OAAO,GAAG,IAAI;AAClB,IAAA,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE;QACtC,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC;QAC3C,IAAI,IAAI,KAAK,OAAO;AAAE,YAAA,OAAO,IAAI;QACjC,OAAO,GAAG,IAAI;IAChB;AACA,IAAA,OAAO,OAAO;AAChB;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Rotate, Scale, Transform, Translate } from 'lightningcss';
|
|
2
|
+
import type { RNEntry } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Convert lightningcss's typed `transform: ...` value into RN's
|
|
5
|
+
* `transform: [{ op: value }, ...]` array. RN supports a restricted subset
|
|
6
|
+
* of CSS transforms — this function picks out the ones it actually
|
|
7
|
+
* handles and drops the rest.
|
|
8
|
+
*
|
|
9
|
+
* Reanimated v4's CSS engine reads this same array shape, so the output
|
|
10
|
+
* is drop-in for both static RN `style` props and `Animated.View` styles.
|
|
11
|
+
* @param fns Typed transform function list.
|
|
12
|
+
* @returns Zero-or-one RN entry with the `transform` array.
|
|
13
|
+
*/
|
|
14
|
+
export declare function transformFunctionsToEntries(fns: readonly Transform[]): readonly RNEntry[];
|
|
15
|
+
/**
|
|
16
|
+
* Convert Tailwind v4's typed `rotate: ...` (individual property) into
|
|
17
|
+
* the RN transform array. Tailwind's `rotate-*` utilities emit this
|
|
18
|
+
* property rather than the classic `transform: rotate(...)` shorthand.
|
|
19
|
+
* @param value Typed rotate value.
|
|
20
|
+
* @returns Zero-or-one RN entry.
|
|
21
|
+
*/
|
|
22
|
+
export declare function rotateToEntries(value: Rotate | 'none'): readonly RNEntry[];
|
|
23
|
+
/**
|
|
24
|
+
* Convert Tailwind v4's typed `translate: ...` into the RN transform
|
|
25
|
+
* array. Both axes are emitted as separate ops so each is independently
|
|
26
|
+
* animatable by Reanimated.
|
|
27
|
+
* @param value Typed translate value.
|
|
28
|
+
* @returns Zero-or-one RN entry.
|
|
29
|
+
*/
|
|
30
|
+
export declare function translateToEntries(value: Translate | 'none'): readonly RNEntry[];
|
|
31
|
+
/**
|
|
32
|
+
* Convert Tailwind v4's typed `scale: ...` into the RN transform array.
|
|
33
|
+
* @param value Typed scale value.
|
|
34
|
+
* @returns Zero-or-one RN entry.
|
|
35
|
+
*/
|
|
36
|
+
export declare function scaleToEntries(value: Scale | 'none'): readonly RNEntry[];
|
|
@@ -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,KAAK,QAAQ,EAAE;AACb,YAAA,OAAO,CAAC,EAAE,MAAM,EAAE,0BAA0B,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3D;QACA,KAAK,YAAY,EAAE;AACjB,YAAA,OAAO,CAAC,EAAE,UAAU,EAAE,uBAAuB,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5D;QACA,KAAK,YAAY,EAAE;AACjB,YAAA,OAAO,CAAC,EAAE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