rnwind 0.0.8 → 0.0.9
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/color.cjs +33 -1
- package/lib/cjs/core/parser/color.cjs.map +1 -1
- package/lib/cjs/core/parser/color.d.ts +10 -0
- package/lib/cjs/core/parser/declaration.cjs +121 -9
- package/lib/cjs/core/parser/declaration.cjs.map +1 -1
- package/lib/cjs/core/parser/gradient.cjs +46 -12
- package/lib/cjs/core/parser/gradient.cjs.map +1 -1
- package/lib/cjs/core/parser/gradient.d.ts +2 -1
- package/lib/cjs/core/parser/keyframes.cjs +27 -12
- package/lib/cjs/core/parser/keyframes.cjs.map +1 -1
- package/lib/cjs/core/parser/keyframes.d.ts +11 -0
- package/lib/cjs/core/parser/layout-dispatcher.cjs +33 -10
- package/lib/cjs/core/parser/layout-dispatcher.cjs.map +1 -1
- package/lib/cjs/core/parser/length.cjs +17 -1
- package/lib/cjs/core/parser/length.cjs.map +1 -1
- package/lib/cjs/core/parser/safe-area.cjs +24 -3
- package/lib/cjs/core/parser/safe-area.cjs.map +1 -1
- package/lib/cjs/core/parser/theme-vars.cjs +58 -8
- package/lib/cjs/core/parser/theme-vars.cjs.map +1 -1
- package/lib/cjs/core/parser/tokens.cjs +77 -9
- package/lib/cjs/core/parser/tokens.cjs.map +1 -1
- package/lib/cjs/core/parser/tokens.d.ts +9 -0
- package/lib/cjs/core/parser/transform.cjs +18 -9
- package/lib/cjs/core/parser/transform.cjs.map +1 -1
- package/lib/cjs/core/parser/tw-parser.cjs +93 -33
- package/lib/cjs/core/parser/tw-parser.cjs.map +1 -1
- package/lib/cjs/core/parser/typography-dispatcher.cjs +19 -1
- package/lib/cjs/core/parser/typography-dispatcher.cjs.map +1 -1
- package/lib/cjs/core/parser/typography.cjs +15 -18
- package/lib/cjs/core/parser/typography.cjs.map +1 -1
- package/lib/cjs/core/parser/typography.d.ts +5 -5
- package/lib/cjs/core/style-builder/union-builder.cjs +0 -10
- package/lib/cjs/core/style-builder/union-builder.cjs.map +1 -1
- package/lib/cjs/core/style-builder/union-builder.d.ts +0 -8
- package/lib/cjs/metro/dts.cjs +6 -1
- package/lib/cjs/metro/dts.cjs.map +1 -1
- package/lib/cjs/metro/transformer.cjs +42 -77
- package/lib/cjs/metro/transformer.cjs.map +1 -1
- package/lib/cjs/metro/with-config.cjs +9 -29
- package/lib/cjs/metro/with-config.cjs.map +1 -1
- package/lib/cjs/runtime/hooks/use-scheme.cjs +9 -6
- package/lib/cjs/runtime/hooks/use-scheme.cjs.map +1 -1
- package/lib/cjs/runtime/hooks/use-scheme.d.ts +7 -4
- package/lib/cjs/runtime/index.cjs +1 -1
- package/lib/cjs/runtime/index.cjs.map +1 -1
- package/lib/cjs/runtime/index.d.ts +1 -1
- package/lib/cjs/runtime/lookup-css.cjs +14 -0
- package/lib/cjs/runtime/lookup-css.cjs.map +1 -1
- package/lib/cjs/runtime/lookup-css.d.ts +11 -0
- package/lib/cjs/runtime/resolve.cjs +8 -6
- package/lib/cjs/runtime/resolve.cjs.map +1 -1
- package/lib/cjs/runtime/wrap.cjs +50 -57
- package/lib/cjs/runtime/wrap.cjs.map +1 -1
- package/lib/cjs/runtime/wrap.d.ts +10 -4
- package/lib/esm/core/parser/color.d.ts +10 -0
- package/lib/esm/core/parser/color.mjs +33 -2
- package/lib/esm/core/parser/color.mjs.map +1 -1
- package/lib/esm/core/parser/declaration.mjs +122 -10
- package/lib/esm/core/parser/declaration.mjs.map +1 -1
- package/lib/esm/core/parser/gradient.d.ts +2 -1
- package/lib/esm/core/parser/gradient.mjs +45 -11
- package/lib/esm/core/parser/gradient.mjs.map +1 -1
- package/lib/esm/core/parser/keyframes.d.ts +11 -0
- package/lib/esm/core/parser/keyframes.mjs +27 -12
- package/lib/esm/core/parser/keyframes.mjs.map +1 -1
- package/lib/esm/core/parser/layout-dispatcher.mjs +33 -10
- package/lib/esm/core/parser/layout-dispatcher.mjs.map +1 -1
- package/lib/esm/core/parser/length.mjs +17 -1
- package/lib/esm/core/parser/length.mjs.map +1 -1
- package/lib/esm/core/parser/safe-area.mjs +24 -3
- package/lib/esm/core/parser/safe-area.mjs.map +1 -1
- package/lib/esm/core/parser/theme-vars.mjs +58 -8
- package/lib/esm/core/parser/theme-vars.mjs.map +1 -1
- package/lib/esm/core/parser/tokens.d.ts +9 -0
- package/lib/esm/core/parser/tokens.mjs +77 -10
- package/lib/esm/core/parser/tokens.mjs.map +1 -1
- package/lib/esm/core/parser/transform.mjs +18 -9
- package/lib/esm/core/parser/transform.mjs.map +1 -1
- package/lib/esm/core/parser/tw-parser.mjs +95 -35
- package/lib/esm/core/parser/tw-parser.mjs.map +1 -1
- package/lib/esm/core/parser/typography-dispatcher.mjs +19 -1
- package/lib/esm/core/parser/typography-dispatcher.mjs.map +1 -1
- package/lib/esm/core/parser/typography.d.ts +5 -5
- package/lib/esm/core/parser/typography.mjs +15 -18
- package/lib/esm/core/parser/typography.mjs.map +1 -1
- package/lib/esm/core/style-builder/union-builder.d.ts +0 -8
- package/lib/esm/core/style-builder/union-builder.mjs +0 -10
- package/lib/esm/core/style-builder/union-builder.mjs.map +1 -1
- package/lib/esm/metro/dts.mjs +6 -1
- package/lib/esm/metro/dts.mjs.map +1 -1
- package/lib/esm/metro/transformer.mjs +42 -77
- package/lib/esm/metro/transformer.mjs.map +1 -1
- package/lib/esm/metro/with-config.mjs +10 -30
- package/lib/esm/metro/with-config.mjs.map +1 -1
- package/lib/esm/runtime/hooks/use-scheme.d.ts +7 -4
- package/lib/esm/runtime/hooks/use-scheme.mjs +9 -6
- package/lib/esm/runtime/hooks/use-scheme.mjs.map +1 -1
- package/lib/esm/runtime/index.d.ts +1 -1
- package/lib/esm/runtime/index.mjs +1 -1
- package/lib/esm/runtime/index.mjs.map +1 -1
- package/lib/esm/runtime/lookup-css.d.ts +11 -0
- package/lib/esm/runtime/lookup-css.mjs +14 -1
- package/lib/esm/runtime/lookup-css.mjs.map +1 -1
- package/lib/esm/runtime/resolve.mjs +9 -7
- package/lib/esm/runtime/resolve.mjs.map +1 -1
- package/lib/esm/runtime/wrap.d.ts +10 -4
- package/lib/esm/runtime/wrap.mjs +50 -57
- package/lib/esm/runtime/wrap.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/parser/color.ts +32 -1
- package/src/core/parser/declaration.ts +119 -10
- package/src/core/parser/gradient.ts +48 -11
- package/src/core/parser/keyframes.ts +31 -3
- package/src/core/parser/layout-dispatcher.ts +32 -9
- package/src/core/parser/length.ts +18 -1
- package/src/core/parser/safe-area.ts +23 -2
- package/src/core/parser/theme-vars.ts +75 -8
- package/src/core/parser/tokens.ts +76 -9
- package/src/core/parser/transform.ts +19 -8
- package/src/core/parser/tw-parser.ts +95 -30
- package/src/core/parser/typography-dispatcher.ts +20 -1
- package/src/core/parser/typography.ts +15 -15
- package/src/core/style-builder/union-builder.ts +0 -11
- package/src/metro/dts.ts +6 -1
- package/src/metro/transformer.ts +42 -78
- package/src/metro/with-config.ts +10 -29
- package/src/runtime/hooks/use-scheme.ts +9 -6
- package/src/runtime/index.ts +1 -1
- package/src/runtime/lookup-css.ts +14 -0
- package/src/runtime/resolve.ts +9 -7
- package/src/runtime/wrap.tsx +57 -61
|
@@ -12,6 +12,7 @@ var property = require('./property.cjs');
|
|
|
12
12
|
var selector = require('./selector.cjs');
|
|
13
13
|
var themeVars = require('./theme-vars.cjs');
|
|
14
14
|
var tokens = require('./tokens.cjs');
|
|
15
|
+
var color = require('./color.cjs');
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Default LightningCSS transform options for TailwindParser's visitor.
|
|
@@ -283,7 +284,8 @@ class TailwindParser {
|
|
|
283
284
|
// surface their role + resolved colour so the transformer
|
|
284
285
|
// can rewrite `<LinearGradient className="...">` into
|
|
285
286
|
// `colors={...}` / `start={...}` / `end={...}` props.
|
|
286
|
-
const
|
|
287
|
+
const gradientTable = schemeTables.get(themeVars.BASE_SCHEME) ?? schemeTables.get(schemes[0] ?? themeVars.BASE_SCHEME);
|
|
288
|
+
const gradient$1 = gradient.detectGradientAtom(rule.value.declarations.declarations, gradientTable);
|
|
287
289
|
if (gradient$1)
|
|
288
290
|
gradientAtoms.set(className, gradient$1);
|
|
289
291
|
// Haptics may live on the rule directly OR inside a
|
|
@@ -304,8 +306,8 @@ class TailwindParser {
|
|
|
304
306
|
const steps = [];
|
|
305
307
|
const baseTable = schemeTables.get(themeVars.BASE_SCHEME) ?? schemeTables.get(schemes[0] ?? themeVars.BASE_SCHEME);
|
|
306
308
|
for (const frame of rule.value.keyframes) {
|
|
307
|
-
const
|
|
308
|
-
if (
|
|
309
|
+
const offsets = keyframes.keyframeSelectorOffsets(frame.selectors);
|
|
310
|
+
if (offsets.length === 0)
|
|
309
311
|
continue;
|
|
310
312
|
const style = {};
|
|
311
313
|
const frameDecls = frame.declarations.declarations ?? [];
|
|
@@ -313,7 +315,10 @@ class TailwindParser {
|
|
|
313
315
|
for (const [key, value] of declaration.declarationToRnEntries(decl, baseTable))
|
|
314
316
|
style[key] = value;
|
|
315
317
|
}
|
|
316
|
-
|
|
318
|
+
// One frame can carry several offsets (`0%, 100% { … }`); emit a
|
|
319
|
+
// step for each so the terminal frame isn't lost.
|
|
320
|
+
for (const offset of offsets)
|
|
321
|
+
steps.push({ offset, style });
|
|
317
322
|
}
|
|
318
323
|
keyframes$1.set(name, { name, steps });
|
|
319
324
|
},
|
|
@@ -454,8 +459,8 @@ function processStyleRule(declarations, className, ctx, nestedRules = []) {
|
|
|
454
459
|
ctx.referencedKeyframes.add(animationRef);
|
|
455
460
|
}
|
|
456
461
|
applyComposedTransform(bucket, ctx.schemes, ruleLocalVars);
|
|
457
|
-
applyComposedShadow(bucket, ctx.schemes, ruleLocalVars);
|
|
458
|
-
applyComposedRing(bucket, ctx.schemes, ruleLocalVars);
|
|
462
|
+
applyComposedShadow(bucket, ctx.schemes, ruleLocalVars, ruleSchemeTables);
|
|
463
|
+
applyComposedRing(bucket, ctx.schemes, ruleLocalVars, ruleSchemeTables);
|
|
459
464
|
// Phase 2: nested rules — three orthogonal flavours, dispatched on
|
|
460
465
|
// the lightningcss node `type`:
|
|
461
466
|
// - `media`: Tailwind v4 responsive variants (`sm:`, `md:`, …) wrap
|
|
@@ -600,7 +605,7 @@ function applyMediaRule(nested, className, bucket, ctx, ruleSchemeTables, ruleLo
|
|
|
600
605
|
for (const [k, v] of collectRuleLocalVars(decls))
|
|
601
606
|
nestedLocalVars.set(k, v);
|
|
602
607
|
applyComposedTransformToScheme(schemeBucket, nestedLocalVars);
|
|
603
|
-
applyComposedShadowToScheme(schemeBucket, nestedLocalVars);
|
|
608
|
+
applyComposedShadowToScheme(schemeBucket, nestedLocalVars, table);
|
|
604
609
|
bucket[scheme] = schemeBucket;
|
|
605
610
|
}
|
|
606
611
|
}
|
|
@@ -637,7 +642,7 @@ function applyInteractiveNestedRule(nested, bucket, ctx, ruleSchemeTables, ruleL
|
|
|
637
642
|
for (const [k, v] of collectRuleLocalVars(decls))
|
|
638
643
|
nestedLocalVars.set(k, v);
|
|
639
644
|
applyComposedTransformToScheme(schemeBucket, nestedLocalVars);
|
|
640
|
-
applyComposedShadowToScheme(schemeBucket, nestedLocalVars);
|
|
645
|
+
applyComposedShadowToScheme(schemeBucket, nestedLocalVars, table);
|
|
641
646
|
bucket[scheme] = schemeBucket;
|
|
642
647
|
}
|
|
643
648
|
}
|
|
@@ -703,7 +708,7 @@ function applyNestedSchemeRule(nested, bucket, ctx, ruleSchemeTables, ruleLocalV
|
|
|
703
708
|
for (const [k, v] of collectRuleLocalVars(innerDecls))
|
|
704
709
|
nestedLocalVars.set(k, v);
|
|
705
710
|
applyComposedTransformToScheme(schemeBucket, nestedLocalVars);
|
|
706
|
-
applyComposedShadowToScheme(schemeBucket, nestedLocalVars);
|
|
711
|
+
applyComposedShadowToScheme(schemeBucket, nestedLocalVars, table);
|
|
707
712
|
bucket[targetScheme] = schemeBucket;
|
|
708
713
|
}
|
|
709
714
|
/**
|
|
@@ -804,12 +809,13 @@ function applyComposedTransformToScheme(style, ruleLocalVars) {
|
|
|
804
809
|
* prop.
|
|
805
810
|
* @param style Scheme-specific style map.
|
|
806
811
|
* @param ruleLocalVars Combined outer+nested `--tw-*` vars.
|
|
812
|
+
* @param table Per-scheme var table for resolving `var(--color-x)` in colors.
|
|
807
813
|
*/
|
|
808
|
-
function applyComposedShadowToScheme(style, ruleLocalVars) {
|
|
814
|
+
function applyComposedShadowToScheme(style, ruleLocalVars, table) {
|
|
809
815
|
const rawShadow = ruleLocalVars.get('--tw-shadow');
|
|
810
816
|
const rawShadowColor = ruleLocalVars.get('--tw-shadow-color');
|
|
811
817
|
if (!rawShadow && rawShadowColor) {
|
|
812
|
-
const color = resolveCustomColorString(rawShadowColor);
|
|
818
|
+
const color = resolveCustomColorString(rawShadowColor, table);
|
|
813
819
|
if (!color)
|
|
814
820
|
return;
|
|
815
821
|
delete style.boxShadow;
|
|
@@ -838,8 +844,9 @@ function applyComposedShadowToScheme(style, ruleLocalVars) {
|
|
|
838
844
|
* @param bucket Per-scheme style map for the atom.
|
|
839
845
|
* @param schemes Scheme names active for this parse.
|
|
840
846
|
* @param ruleLocalVars Rule-local `--tw-*` vars.
|
|
847
|
+
* @param schemeTables Per-scheme var tables for resolving `var(--color-x)`.
|
|
841
848
|
*/
|
|
842
|
-
function applyComposedShadow(bucket, schemes, ruleLocalVars) {
|
|
849
|
+
function applyComposedShadow(bucket, schemes, ruleLocalVars, schemeTables) {
|
|
843
850
|
const rawShadow = ruleLocalVars.get('--tw-shadow');
|
|
844
851
|
const rawShadowColor = ruleLocalVars.get('--tw-shadow-color');
|
|
845
852
|
// Color-only utility (`shadow-red-50`, `shadow-gray-200`, …): emit
|
|
@@ -848,10 +855,11 @@ function applyComposedShadow(bucket, schemes, ruleLocalVars) {
|
|
|
848
855
|
// where setting `--tw-shadow-color` swaps in a solid color). Offset /
|
|
849
856
|
// blur / elevation come from the partner size utility's atom.
|
|
850
857
|
if (!rawShadow && rawShadowColor) {
|
|
851
|
-
const color = resolveCustomColorString(rawShadowColor);
|
|
852
|
-
if (!color)
|
|
853
|
-
return;
|
|
854
858
|
for (const scheme of schemes) {
|
|
859
|
+
// Resolve per scheme — a custom token may differ between light/dark.
|
|
860
|
+
const color = resolveCustomColorString(rawShadowColor, schemeTables.get(scheme));
|
|
861
|
+
if (!color)
|
|
862
|
+
continue;
|
|
855
863
|
const style = bucket[scheme] ?? {};
|
|
856
864
|
delete style.boxShadow;
|
|
857
865
|
style.shadowColor = color;
|
|
@@ -884,35 +892,62 @@ function applyComposedShadow(bucket, schemes, ruleLocalVars) {
|
|
|
884
892
|
* @param bucket Per-scheme style map for the atom.
|
|
885
893
|
* @param schemes Scheme names active for this parse.
|
|
886
894
|
* @param ruleLocalVars Rule-local `--tw-*` vars.
|
|
895
|
+
* @param schemeTables Per-scheme var tables for resolving `var(--color-x)`.
|
|
887
896
|
*/
|
|
888
|
-
function applyComposedRing(bucket, schemes, ruleLocalVars) {
|
|
897
|
+
function applyComposedRing(bucket, schemes, ruleLocalVars, schemeTables) {
|
|
889
898
|
const ringColor = ruleLocalVars.get('--tw-ring-color');
|
|
890
899
|
if (!ringColor)
|
|
891
900
|
return;
|
|
892
|
-
const color = resolveCustomColorString(ringColor);
|
|
893
|
-
if (!color)
|
|
894
|
-
return;
|
|
895
901
|
for (const scheme of schemes) {
|
|
902
|
+
// Resolve per scheme — a custom token may differ between light/dark.
|
|
903
|
+
const color = resolveCustomColorString(ringColor, schemeTables.get(scheme));
|
|
904
|
+
if (!color)
|
|
905
|
+
continue;
|
|
896
906
|
const style = bucket[scheme] ?? {};
|
|
897
907
|
if (!('borderColor' in style))
|
|
898
908
|
style.borderColor = color;
|
|
899
909
|
bucket[scheme] = style;
|
|
900
910
|
}
|
|
901
911
|
}
|
|
912
|
+
/**
|
|
913
|
+
* Tailwind composable shadow/inset-shadow alpha defaults. Their `100%` lives
|
|
914
|
+
* in an `@property` initial-value (not the rule's local vars), so after the
|
|
915
|
+
* `@supports` color-mix is unwrapped, `var(--tw-shadow-alpha)` is left dangling
|
|
916
|
+
* and the shadow color fails to resolve. Seed the default; a `/<opacity>`
|
|
917
|
+
* modifier still wins because the in-rule table value overrides it.
|
|
918
|
+
*/
|
|
919
|
+
const COMPOSABLE_ALPHA_DEFAULTS = new Map([
|
|
920
|
+
['--tw-shadow-alpha', '100%'],
|
|
921
|
+
['--tw-inset-shadow-alpha', '100%'],
|
|
922
|
+
]);
|
|
902
923
|
/**
|
|
903
924
|
* Resolve a CSS color string (`oklch(0.971 0.013 17.38)`, `#ff0000`,
|
|
904
925
|
* `rgb(0 0 0 / 0.1)`) to the hex string RN's `shadowColor` accepts.
|
|
905
926
|
* Wraps culori's parser via {@link parseCssColorToHex}.
|
|
906
|
-
*
|
|
927
|
+
*
|
|
928
|
+
* Custom `@theme` color tokens arrive as `var(--color-x)` (only the default
|
|
929
|
+
* palette is `theme(inline)`-d), so `table` is substituted FIRST — without it
|
|
930
|
+
* `shadow-<token>` / `ring-<token>` silently drop the color (culori can't
|
|
931
|
+
* parse a bare `var()`). The table is per-scheme so a token that differs
|
|
932
|
+
* between light/dark resolves to the right value for each.
|
|
933
|
+
* @param raw Raw color text from a `--tw-shadow-color` / `--tw-ring-color` prop.
|
|
934
|
+
* @param table Per-scheme var table for resolving `var(--color-x)` references.
|
|
907
935
|
* @returns `#rrggbb` string, or null when culori can't parse it.
|
|
908
936
|
*/
|
|
909
|
-
function resolveCustomColorString(raw) {
|
|
910
|
-
const
|
|
911
|
-
|
|
937
|
+
function resolveCustomColorString(raw, table) {
|
|
938
|
+
const seeded = new Map([...COMPOSABLE_ALPHA_DEFAULTS, ...(table ?? [])]);
|
|
939
|
+
const substituted = tokens.substituteThemeVars(raw, seeded);
|
|
940
|
+
// `coerceUnparsedValue` collapses Tailwind's opacity shape
|
|
941
|
+
// `color-mix(in oklab, <color> <pct>%, transparent)` (emitted by
|
|
942
|
+
// `shadow-<token>` / `ring-<token>`) to a flat rgba/hex and unwraps
|
|
943
|
+
// `var(…, fallback)`. Modern spaces (`oklch(…)`) then lower via
|
|
944
|
+
// `normalizeColorString`; anything still un-RN-safe falls to culori.
|
|
945
|
+
const coerced = tokens.coerceUnparsedValue(unwrapVariableFallback(substituted).trim());
|
|
946
|
+
if (typeof coerced !== 'string' || coerced.length === 0 || coerced.startsWith('var('))
|
|
912
947
|
return null;
|
|
913
|
-
if (
|
|
914
|
-
return
|
|
915
|
-
return parseCssColorToHex(
|
|
948
|
+
if (coerced.startsWith('#') || coerced.startsWith('rgb') || coerced.startsWith('hsl'))
|
|
949
|
+
return coerced;
|
|
950
|
+
return color.normalizeColorString(coerced) ?? parseCssColorToHex(coerced);
|
|
916
951
|
}
|
|
917
952
|
/**
|
|
918
953
|
* Parse any CSS color expression into an `#rrggbb` string via culori.
|
|
@@ -1018,6 +1053,12 @@ function parseShadowColor(expr) {
|
|
|
1018
1053
|
return rgba;
|
|
1019
1054
|
if (working.startsWith('#'))
|
|
1020
1055
|
return { color: working, opacity: 1 };
|
|
1056
|
+
// Named (`red`) / modern (`hsl(…)`, `oklch(…)`) colors — culori → sRGB hex.
|
|
1057
|
+
// Without this they fell to the default black at 0.1 alpha, silently losing
|
|
1058
|
+
// the user's `shadow-[0_2px_4px_red]` color.
|
|
1059
|
+
const hex = formatHexSafe(working);
|
|
1060
|
+
if (hex)
|
|
1061
|
+
return { color: hex, opacity: 1 };
|
|
1021
1062
|
return { color: '#000', opacity: 0.1 };
|
|
1022
1063
|
}
|
|
1023
1064
|
/**
|
|
@@ -1222,8 +1263,8 @@ function resolveLengthExpression(text) {
|
|
|
1222
1263
|
if (evaluated.unit === '%')
|
|
1223
1264
|
return `${stripTrailingZeros(evaluated.value)}%`;
|
|
1224
1265
|
if (evaluated.unit === 'rem')
|
|
1225
|
-
return evaluated.value * 16;
|
|
1226
|
-
return evaluated.value;
|
|
1266
|
+
return roundTransformValue(evaluated.value * 16);
|
|
1267
|
+
return roundTransformValue(evaluated.value);
|
|
1227
1268
|
}
|
|
1228
1269
|
/**
|
|
1229
1270
|
* Evaluate a CSS length expression to a `{value, unit}` pair.
|
|
@@ -1450,19 +1491,38 @@ function parseArithmeticFactor(tokens, cursor) {
|
|
|
1450
1491
|
return number_;
|
|
1451
1492
|
}
|
|
1452
1493
|
/**
|
|
1453
|
-
* Resolve a scale factor expressed as a percentage (`150%`)
|
|
1494
|
+
* Resolve a scale factor expressed as a percentage (`150%`), number (`1.5`),
|
|
1495
|
+
* or a `calc()` expression. Tailwind emits NEGATIVE scale utilities as a calc
|
|
1496
|
+
* (`-scale-x-100` → `calc(100% * -1)`), so a plain percent/number regex
|
|
1497
|
+
* silently dropped them — `-scale-*` (the horizontal-flip idiom) rendered
|
|
1498
|
+
* nothing. Fall back to the shared arithmetic evaluator, reading `%` as a
|
|
1499
|
+
* fraction (`100%` → 1) and rounding off f32 noise.
|
|
1454
1500
|
* @param text Raw value.
|
|
1455
|
-
* @returns Scale number (e.g. 1.5 for 150%), or null.
|
|
1501
|
+
* @returns Scale number (e.g. 1.5 for 150%, -1 for `calc(100% * -1)`), or null.
|
|
1456
1502
|
*/
|
|
1457
1503
|
function resolveNumberOrPercent(text) {
|
|
1458
1504
|
const trimmed = text.trim();
|
|
1459
1505
|
const percent = /^(-?\d+(?:\.\d+)?)%$/.exec(trimmed);
|
|
1460
1506
|
if (percent)
|
|
1461
|
-
return Number(percent[1]) / 100;
|
|
1507
|
+
return roundTransformValue(Number(percent[1]) / 100);
|
|
1462
1508
|
const bare = /^-?\d+(?:\.\d+)?$/.exec(trimmed);
|
|
1463
1509
|
if (bare)
|
|
1464
|
-
return Number(trimmed);
|
|
1465
|
-
|
|
1510
|
+
return roundTransformValue(Number(trimmed));
|
|
1511
|
+
const evaluated = evaluateLengthExpr(trimmed);
|
|
1512
|
+
if (!evaluated || evaluated.unit === 'rem')
|
|
1513
|
+
return null;
|
|
1514
|
+
return roundTransformValue(evaluated.unit === '%' ? evaluated.value / 100 : evaluated.value);
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Round a composed-transform numeric value to 4 decimals. lightningcss
|
|
1518
|
+
* serializes arbitrary literals (`scale-x-[0.333]`) back as noisy f32 text
|
|
1519
|
+
* (`0.3330000042915344`), and the resolvers `Number()` that verbatim — round
|
|
1520
|
+
* so the RN `transform` array stays clean.
|
|
1521
|
+
* @param value Raw number.
|
|
1522
|
+
* @returns Rounded number.
|
|
1523
|
+
*/
|
|
1524
|
+
function roundTransformValue(value) {
|
|
1525
|
+
return Math.round(value * 10_000) / 10_000;
|
|
1466
1526
|
}
|
|
1467
1527
|
/**
|
|
1468
1528
|
* Extract the angle from Tailwind's `skewX(12deg)` / `skewY(-5deg)` /
|