react-native-css 3.0.0-preview.0 → 3.0.0-preview.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/dist/commonjs/babel/index.js +6 -2
- package/dist/commonjs/babel/index.js.map +1 -1
- package/dist/commonjs/compiler/atRules.js +3 -1
- package/dist/commonjs/compiler/atRules.js.map +1 -1
- package/dist/commonjs/compiler/declarations.js +114 -35
- package/dist/commonjs/compiler/declarations.js.map +1 -1
- package/dist/commonjs/compiler/stylesheet.js +5 -0
- package/dist/commonjs/compiler/stylesheet.js.map +1 -1
- package/dist/commonjs/jest/index.js +0 -1
- package/dist/commonjs/jest/index.js.map +1 -1
- package/dist/commonjs/runtime/native/api.js +21 -2
- package/dist/commonjs/runtime/native/api.js.map +1 -1
- package/dist/commonjs/runtime/native/reactivity.js +1 -5
- package/dist/commonjs/runtime/native/reactivity.js.map +1 -1
- package/dist/commonjs/runtime/native/styles/line-height.js +25 -0
- package/dist/commonjs/runtime/native/styles/line-height.js.map +1 -0
- package/dist/commonjs/runtime/native/styles/resolve.js +2 -0
- package/dist/commonjs/runtime/native/styles/resolve.js.map +1 -1
- package/dist/commonjs/runtime/native/styles/shorthands/box-shadow.js +19 -11
- package/dist/commonjs/runtime/native/styles/shorthands/box-shadow.js.map +1 -1
- package/dist/commonjs/runtime/native/styles/units.js +10 -8
- package/dist/commonjs/runtime/native/styles/units.js.map +1 -1
- package/dist/commonjs/runtime/web/api.js +18 -0
- package/dist/commonjs/runtime/web/api.js.map +1 -1
- package/dist/commonjs/style-collection/root.js +1 -0
- package/dist/commonjs/style-collection/root.js.map +1 -1
- package/dist/module/babel/index.js +2 -2
- package/dist/module/babel/index.js.map +1 -1
- package/dist/module/compiler/atRules.js +3 -1
- package/dist/module/compiler/atRules.js.map +1 -1
- package/dist/module/compiler/declarations.js +109 -35
- package/dist/module/compiler/declarations.js.map +1 -1
- package/dist/module/compiler/stylesheet.js +5 -0
- package/dist/module/compiler/stylesheet.js.map +1 -1
- package/dist/module/jest/index.js +1 -2
- package/dist/module/jest/index.js.map +1 -1
- package/dist/module/runtime/native/api.js +21 -3
- package/dist/module/runtime/native/api.js.map +1 -1
- package/dist/module/runtime/native/reactivity.js +0 -4
- package/dist/module/runtime/native/reactivity.js.map +1 -1
- package/dist/module/runtime/native/styles/line-height.js +20 -0
- package/dist/module/runtime/native/styles/line-height.js.map +1 -0
- package/dist/module/runtime/native/styles/resolve.js +2 -0
- package/dist/module/runtime/native/styles/resolve.js.map +1 -1
- package/dist/module/runtime/native/styles/shorthands/box-shadow.js +19 -11
- package/dist/module/runtime/native/styles/shorthands/box-shadow.js.map +1 -1
- package/dist/module/runtime/native/styles/units.js +11 -8
- package/dist/module/runtime/native/styles/units.js.map +1 -1
- package/dist/module/runtime/web/api.js +18 -1
- package/dist/module/runtime/web/api.js.map +1 -1
- package/dist/module/style-collection/root.js +1 -0
- package/dist/module/style-collection/root.js.map +1 -1
- package/dist/typescript/commonjs/src/babel/index.d.ts +3 -0
- package/dist/typescript/commonjs/src/babel/index.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/atRules.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/declarations.d.ts +15 -4
- package/dist/typescript/commonjs/src/compiler/declarations.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/compiler/stylesheet.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/jest/index.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/api.d.ts +13 -1
- package/dist/typescript/commonjs/src/runtime/native/api.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts +0 -2
- package/dist/typescript/commonjs/src/runtime/native/reactivity.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/styles/line-height.d.ts +3 -0
- package/dist/typescript/commonjs/src/runtime/native/styles/line-height.d.ts.map +1 -0
- package/dist/typescript/commonjs/src/runtime/native/styles/resolve.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/styles/shorthands/box-shadow.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/native/styles/units.d.ts.map +1 -1
- package/dist/typescript/commonjs/src/runtime/web/api.d.ts +8 -2
- package/dist/typescript/commonjs/src/runtime/web/api.d.ts.map +1 -1
- package/dist/typescript/module/src/babel/index.d.ts +3 -0
- package/dist/typescript/module/src/babel/index.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/atRules.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/declarations.d.ts +15 -4
- package/dist/typescript/module/src/compiler/declarations.d.ts.map +1 -1
- package/dist/typescript/module/src/compiler/stylesheet.d.ts.map +1 -1
- package/dist/typescript/module/src/jest/index.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/api.d.ts +13 -1
- package/dist/typescript/module/src/runtime/native/api.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/reactivity.d.ts +0 -2
- package/dist/typescript/module/src/runtime/native/reactivity.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/styles/line-height.d.ts +3 -0
- package/dist/typescript/module/src/runtime/native/styles/line-height.d.ts.map +1 -0
- package/dist/typescript/module/src/runtime/native/styles/resolve.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/styles/shorthands/box-shadow.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/native/styles/units.d.ts.map +1 -1
- package/dist/typescript/module/src/runtime/web/api.d.ts +8 -2
- package/dist/typescript/module/src/runtime/web/api.d.ts.map +1 -1
- package/package.json +9 -10
- package/src/babel/index.ts +2 -2
- package/src/compiler/atRules.ts +2 -0
- package/src/compiler/declarations.ts +156 -46
- package/src/compiler/stylesheet.ts +6 -0
- package/src/jest/index.ts +1 -2
- package/src/runtime/native/{api.ts → api.tsx} +31 -4
- package/src/runtime/native/reactivity.ts +0 -4
- package/src/runtime/native/styles/line-height.ts +25 -0
- package/src/runtime/native/styles/resolve.ts +2 -0
- package/src/runtime/native/styles/shorthands/box-shadow.ts +24 -18
- package/src/runtime/native/styles/units.ts +13 -8
- package/src/runtime/web/{api.ts → api.tsx} +28 -2
- package/src/style-collection/root.ts +2 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// cSpell:ignore rcap,vmin,svmin,lvmin,dvmin,cqmin,vmax,svmax,lvmax,dvmax,cqmax,currentcolor,oklab,oklch,prophoto
|
|
1
|
+
// cSpell:ignore rcap,vmin,svmin,lvmin,dvmin,cqmin,vmax,svmax,lvmax,dvmax,cqmax,currentcolor,oklab,oklch,prophoto,squircle,oldstyle,nums
|
|
2
2
|
|
|
3
3
|
import Color from "colorjs.io";
|
|
4
4
|
import type {
|
|
@@ -63,15 +63,15 @@ const propertyRename: Record<string, string> = {
|
|
|
63
63
|
"background-image": "experimental_backgroundImage",
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
// TODO: We need a better way to handle this
|
|
67
66
|
const unparsedRuntimeParsing = new Set([
|
|
68
67
|
"animation",
|
|
69
68
|
"border",
|
|
70
69
|
"box-shadow",
|
|
70
|
+
"line-height",
|
|
71
|
+
"rotate",
|
|
72
|
+
"scale",
|
|
71
73
|
"text-shadow",
|
|
72
74
|
"transform",
|
|
73
|
-
"scale",
|
|
74
|
-
"rotate",
|
|
75
75
|
"translate",
|
|
76
76
|
]);
|
|
77
77
|
|
|
@@ -91,6 +91,7 @@ const parsers: {
|
|
|
91
91
|
"animation-play-state": addAnimationValue,
|
|
92
92
|
"animation-timing-function": addAnimationValue,
|
|
93
93
|
"aspect-ratio": parseAspectRatio,
|
|
94
|
+
"backface-visibility": parseBackfaceVisibility,
|
|
94
95
|
"background-color": parseColorDeclaration,
|
|
95
96
|
"background-image": parseBackgroundImage,
|
|
96
97
|
"block-size": parseSizeDeclaration,
|
|
@@ -146,8 +147,9 @@ const parsers: {
|
|
|
146
147
|
"border-top-style": parseBorderStyleDeclaration,
|
|
147
148
|
"border-top-width": parseBorderSideWidthDeclaration,
|
|
148
149
|
"border-width": parseBorderWidth,
|
|
149
|
-
"bottom":
|
|
150
|
+
"bottom": parseSizeWithAutoDeclaration,
|
|
150
151
|
"box-shadow": parseBoxShadow,
|
|
152
|
+
"box-sizing": parseBoxSizing,
|
|
151
153
|
"caret-color": parseColorOrAutoDeclaration,
|
|
152
154
|
"color": parseFontColorDeclaration,
|
|
153
155
|
"column-gap": parseGap,
|
|
@@ -155,10 +157,11 @@ const parsers: {
|
|
|
155
157
|
"container-name": parseContainerName,
|
|
156
158
|
"container-type": parseContainerType,
|
|
157
159
|
"display": parseDisplay,
|
|
160
|
+
"direction": parseDirection,
|
|
158
161
|
"fill": parseSVGPaint,
|
|
159
162
|
"filter": parseFilter,
|
|
160
163
|
"flex": parseFlex,
|
|
161
|
-
"flex-basis":
|
|
164
|
+
"flex-basis": parseLengthPercentageDeclaration,
|
|
162
165
|
"flex-direction": ({ value }) => value,
|
|
163
166
|
"flex-flow": parseFlexFlow,
|
|
164
167
|
"flex-grow": ({ value }) => value,
|
|
@@ -171,30 +174,30 @@ const parsers: {
|
|
|
171
174
|
"font-variant-caps": parseFontVariantCapsDeclaration,
|
|
172
175
|
"font-weight": parseFontWeightDeclaration,
|
|
173
176
|
"gap": parseGap,
|
|
174
|
-
"height":
|
|
175
|
-
"inline-size":
|
|
177
|
+
"height": parseSizeWithAutoDeclaration,
|
|
178
|
+
"inline-size": parseSizeWithAutoDeclaration,
|
|
176
179
|
"inset": parseInset,
|
|
177
180
|
"inset-block": parseInsetBlock,
|
|
178
|
-
"inset-block-end":
|
|
179
|
-
"inset-block-start":
|
|
181
|
+
"inset-block-end": parseLengthPercentageDeclaration,
|
|
182
|
+
"inset-block-start": parseLengthPercentageDeclaration,
|
|
180
183
|
"inset-inline": parseInsetInline,
|
|
181
|
-
"inset-inline-end":
|
|
182
|
-
"inset-inline-start":
|
|
184
|
+
"inset-inline-end": parseLengthPercentageDeclaration,
|
|
185
|
+
"inset-inline-start": parseLengthPercentageDeclaration,
|
|
183
186
|
"justify-content": parseJustifyContent,
|
|
184
|
-
"left":
|
|
187
|
+
"left": parseSizeWithAutoDeclaration,
|
|
185
188
|
"letter-spacing": parseLetterSpacing,
|
|
186
189
|
"line-height": parseLineHeightDeclaration,
|
|
187
190
|
"margin": parseMargin,
|
|
188
191
|
"margin-block": parseMarginBlock,
|
|
189
192
|
"margin-block-end": parseLengthPercentageOrAutoDeclaration,
|
|
190
193
|
"margin-block-start": parseLengthPercentageOrAutoDeclaration,
|
|
191
|
-
"margin-bottom":
|
|
194
|
+
"margin-bottom": parseSizeWithAutoDeclaration,
|
|
192
195
|
"margin-inline": parseMarginInline,
|
|
193
196
|
"margin-inline-end": parseLengthPercentageOrAutoDeclaration,
|
|
194
197
|
"margin-inline-start": parseLengthPercentageOrAutoDeclaration,
|
|
195
|
-
"margin-left":
|
|
196
|
-
"margin-right":
|
|
197
|
-
"margin-top":
|
|
198
|
+
"margin-left": parseSizeWithAutoDeclaration,
|
|
199
|
+
"margin-right": parseSizeWithAutoDeclaration,
|
|
200
|
+
"margin-top": parseSizeWithAutoDeclaration,
|
|
198
201
|
"max-block-size": parseSizeDeclaration,
|
|
199
202
|
"max-height": parseSizeDeclaration,
|
|
200
203
|
"max-inline-size": parseSizeDeclaration,
|
|
@@ -203,21 +206,24 @@ const parsers: {
|
|
|
203
206
|
"min-height": parseSizeDeclaration,
|
|
204
207
|
"min-inline-size": parseSizeDeclaration,
|
|
205
208
|
"min-width": parseSizeDeclaration,
|
|
206
|
-
"opacity": ({ value }) => value,
|
|
209
|
+
"opacity": ({ value }) => round(value),
|
|
210
|
+
"outline-color": parseColorDeclaration,
|
|
211
|
+
"outline-style": parseOutlineStyle,
|
|
212
|
+
"outline-width": parseBorderSideWidthDeclaration,
|
|
207
213
|
"overflow": parseOverflow,
|
|
208
214
|
"padding": parsePadding,
|
|
209
215
|
"padding-block": parsePaddingBlock,
|
|
210
|
-
"padding-block-end":
|
|
211
|
-
"padding-block-start":
|
|
216
|
+
"padding-block-end": parseLengthPercentageDeclaration,
|
|
217
|
+
"padding-block-start": parseLengthPercentageDeclaration,
|
|
212
218
|
"padding-bottom": parseSizeDeclaration,
|
|
213
219
|
"padding-inline": parsePaddingInline,
|
|
214
|
-
"padding-inline-end":
|
|
215
|
-
"padding-inline-start":
|
|
220
|
+
"padding-inline-end": parseLengthPercentageDeclaration,
|
|
221
|
+
"padding-inline-start": parseLengthPercentageDeclaration,
|
|
216
222
|
"padding-left": parseSizeDeclaration,
|
|
217
223
|
"padding-right": parseSizeDeclaration,
|
|
218
224
|
"padding-top": parseSizeDeclaration,
|
|
219
225
|
"position": parsePosition,
|
|
220
|
-
"right":
|
|
226
|
+
"right": parseSizeWithAutoDeclaration,
|
|
221
227
|
"rotate": parseRotate,
|
|
222
228
|
"row-gap": parseGap,
|
|
223
229
|
"scale": parseScale,
|
|
@@ -230,7 +236,7 @@ const parsers: {
|
|
|
230
236
|
"text-decoration-style": parseTextDecorationStyle,
|
|
231
237
|
"text-shadow": parseTextShadow,
|
|
232
238
|
"text-transform": ({ value }) => value.case,
|
|
233
|
-
"top":
|
|
239
|
+
"top": parseSizeWithAutoDeclaration,
|
|
234
240
|
"transform": parseTransform,
|
|
235
241
|
"transition": addTransitionValue,
|
|
236
242
|
"transition-delay": addTransitionValue,
|
|
@@ -241,7 +247,7 @@ const parsers: {
|
|
|
241
247
|
"user-select": parseUserSelect,
|
|
242
248
|
"vertical-align": parseVerticalAlign,
|
|
243
249
|
"visibility": parseVisibility,
|
|
244
|
-
"width":
|
|
250
|
+
"width": parseSizeWithAutoDeclaration,
|
|
245
251
|
"z-index": parseZIndex,
|
|
246
252
|
};
|
|
247
253
|
|
|
@@ -611,8 +617,11 @@ function parseMarginBlock(
|
|
|
611
617
|
"margin-block-start": parseLengthPercentageOrAuto(
|
|
612
618
|
value.blockStart,
|
|
613
619
|
builder,
|
|
620
|
+
{ allowAuto: true },
|
|
614
621
|
),
|
|
615
|
-
"margin-block-end": parseLengthPercentageOrAuto(value.blockEnd, builder
|
|
622
|
+
"margin-block-end": parseLengthPercentageOrAuto(value.blockEnd, builder, {
|
|
623
|
+
allowAuto: true,
|
|
624
|
+
}),
|
|
616
625
|
});
|
|
617
626
|
}
|
|
618
627
|
|
|
@@ -624,8 +633,11 @@ function parseMarginInline(
|
|
|
624
633
|
"margin-inline-start": parseLengthPercentageOrAuto(
|
|
625
634
|
value.inlineStart,
|
|
626
635
|
builder,
|
|
636
|
+
{ allowAuto: true },
|
|
627
637
|
),
|
|
628
|
-
"margin-inline-end": parseLengthPercentageOrAuto(value.inlineEnd, builder
|
|
638
|
+
"margin-inline-end": parseLengthPercentageOrAuto(value.inlineEnd, builder, {
|
|
639
|
+
allowAuto: true,
|
|
640
|
+
}),
|
|
629
641
|
});
|
|
630
642
|
}
|
|
631
643
|
|
|
@@ -971,17 +983,31 @@ export function parseCustomDeclaration(
|
|
|
971
983
|
parseUnparsed(declaration.value.value, builder, property),
|
|
972
984
|
);
|
|
973
985
|
} else if (property === "-rn-ripple-style") {
|
|
974
|
-
|
|
975
|
-
property
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
986
|
+
if (
|
|
987
|
+
parseUnparsed(declaration.value.value, builder, property) === "borderless"
|
|
988
|
+
) {
|
|
989
|
+
builder.addDescriptor(property, true);
|
|
990
|
+
}
|
|
991
|
+
} else if (property === "-rn-ripple-layer") {
|
|
992
|
+
if (
|
|
993
|
+
parseUnparsed(declaration.value.value, builder, property) === "foreground"
|
|
994
|
+
) {
|
|
995
|
+
builder.addDescriptor(property, true);
|
|
996
|
+
}
|
|
979
997
|
} else if (property === "object-fit") {
|
|
980
998
|
// https://github.com/parcel-bundler/lightningcss/issues/1046
|
|
981
999
|
parseObjectFit(declaration.value, builder);
|
|
982
1000
|
} else if (property === "object-position") {
|
|
983
1001
|
// https://github.com/parcel-bundler/lightningcss/issues/1047
|
|
984
1002
|
parseObjectPosition(declaration.value, builder);
|
|
1003
|
+
} else if (property === "outline-offset") {
|
|
1004
|
+
// https://github.com/parcel-bundler/lightningcss/issues/1048
|
|
1005
|
+
builder.addDescriptor(
|
|
1006
|
+
property,
|
|
1007
|
+
parseUnparsed(declaration.value.value, builder, property),
|
|
1008
|
+
);
|
|
1009
|
+
} else if (property === "corner-shape") {
|
|
1010
|
+
parseCornerShape(declaration.value, builder);
|
|
985
1011
|
} else if (
|
|
986
1012
|
validProperties.has(property) ||
|
|
987
1013
|
property.startsWith("--") ||
|
|
@@ -1457,6 +1483,13 @@ export function parseSizeDeclaration(
|
|
|
1457
1483
|
return parseSize(declaration.value, builder);
|
|
1458
1484
|
}
|
|
1459
1485
|
|
|
1486
|
+
export function parseSizeWithAutoDeclaration(
|
|
1487
|
+
declaration: { value: Size | MaxSize },
|
|
1488
|
+
builder: StylesheetBuilder,
|
|
1489
|
+
) {
|
|
1490
|
+
return parseSize(declaration.value, builder, { allowAuto: true });
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1460
1493
|
export function parsePointerEvents(
|
|
1461
1494
|
{ value }: { value: string },
|
|
1462
1495
|
builder: StylesheetBuilder,
|
|
@@ -1709,13 +1742,20 @@ export function parseColor(cssColor: CssColor, builder: StylesheetBuilder) {
|
|
|
1709
1742
|
}
|
|
1710
1743
|
}
|
|
1711
1744
|
|
|
1712
|
-
export function
|
|
1745
|
+
export function parseLengthPercentageDeclaration(
|
|
1713
1746
|
value: { value: LengthPercentageOrAuto },
|
|
1714
1747
|
builder: StylesheetBuilder,
|
|
1715
1748
|
) {
|
|
1716
1749
|
return parseLengthPercentageOrAuto(value.value, builder);
|
|
1717
1750
|
}
|
|
1718
1751
|
|
|
1752
|
+
export function parseLengthPercentageOrAutoDeclaration(
|
|
1753
|
+
value: { value: LengthPercentageOrAuto },
|
|
1754
|
+
builder: StylesheetBuilder,
|
|
1755
|
+
) {
|
|
1756
|
+
return parseLengthPercentageOrAuto(value.value, builder, { allowAuto: true });
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1719
1759
|
export function parseLengthPercentageOrAuto(
|
|
1720
1760
|
lengthPercentageOrAuto: LengthPercentageOrAuto,
|
|
1721
1761
|
builder: StylesheetBuilder,
|
|
@@ -1788,6 +1828,7 @@ export function parseAlignContent(
|
|
|
1788
1828
|
"stretch",
|
|
1789
1829
|
"space-between",
|
|
1790
1830
|
"space-around",
|
|
1831
|
+
"space-evenly",
|
|
1791
1832
|
]);
|
|
1792
1833
|
|
|
1793
1834
|
let value: string | undefined;
|
|
@@ -2007,7 +2048,11 @@ export function parsePosition(
|
|
|
2007
2048
|
{ value }: DeclarationType<"position">,
|
|
2008
2049
|
builder: StylesheetBuilder,
|
|
2009
2050
|
) {
|
|
2010
|
-
if (
|
|
2051
|
+
if (
|
|
2052
|
+
value.type === "absolute" ||
|
|
2053
|
+
value.type === "relative" ||
|
|
2054
|
+
value.type === "static"
|
|
2055
|
+
) {
|
|
2011
2056
|
return value.type;
|
|
2012
2057
|
}
|
|
2013
2058
|
|
|
@@ -2097,16 +2142,7 @@ function parseBorderBlockStyle(
|
|
|
2097
2142
|
}
|
|
2098
2143
|
|
|
2099
2144
|
export function parseBorderSideWidthDeclaration(
|
|
2100
|
-
declaration:
|
|
2101
|
-
| "border-block-end-width"
|
|
2102
|
-
| "border-block-start-width"
|
|
2103
|
-
| "border-bottom-width"
|
|
2104
|
-
| "border-inline-end-width"
|
|
2105
|
-
| "border-inline-start-width"
|
|
2106
|
-
| "border-left-width"
|
|
2107
|
-
| "border-right-width"
|
|
2108
|
-
| "border-top-width"
|
|
2109
|
-
>,
|
|
2145
|
+
declaration: Extract<Declaration, { value: BorderSideWidth }>,
|
|
2110
2146
|
builder: StylesheetBuilder,
|
|
2111
2147
|
) {
|
|
2112
2148
|
builder.addDescriptor(
|
|
@@ -2154,7 +2190,12 @@ export function parseLineHeightDeclaration(
|
|
|
2154
2190
|
declaration: DeclarationType<"line-height">,
|
|
2155
2191
|
builder: StylesheetBuilder,
|
|
2156
2192
|
) {
|
|
2157
|
-
|
|
2193
|
+
builder.addDescriptor("line-height", [
|
|
2194
|
+
{},
|
|
2195
|
+
"lineHeight",
|
|
2196
|
+
[parseLineHeight(declaration.value, builder)],
|
|
2197
|
+
1,
|
|
2198
|
+
]);
|
|
2158
2199
|
}
|
|
2159
2200
|
|
|
2160
2201
|
export function parseLineHeight(
|
|
@@ -2359,12 +2400,24 @@ export function parseBoxShadow(
|
|
|
2359
2400
|
}
|
|
2360
2401
|
}
|
|
2361
2402
|
|
|
2403
|
+
export function parseBoxSizing(
|
|
2404
|
+
declaration: DeclarationType<"box-sizing">,
|
|
2405
|
+
builder: StylesheetBuilder,
|
|
2406
|
+
) {
|
|
2407
|
+
if (["border-box", "content-box"].includes(declaration.value)) {
|
|
2408
|
+
return declaration.value;
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
builder.addWarning("value", declaration.value);
|
|
2412
|
+
return undefined;
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2362
2415
|
export function parseDisplay(
|
|
2363
2416
|
{ value }: DeclarationType<"display">,
|
|
2364
2417
|
builder: StylesheetBuilder,
|
|
2365
2418
|
) {
|
|
2366
2419
|
if (value.type === "keyword") {
|
|
2367
|
-
if (value.value === "none") {
|
|
2420
|
+
if (value.value === "none" || value.value === "contents") {
|
|
2368
2421
|
return value.value;
|
|
2369
2422
|
} else {
|
|
2370
2423
|
builder.addWarning("value", value.value);
|
|
@@ -2416,6 +2469,19 @@ export function parseDisplay(
|
|
|
2416
2469
|
}
|
|
2417
2470
|
}
|
|
2418
2471
|
|
|
2472
|
+
export function parseDirection(
|
|
2473
|
+
declaration: DeclarationType<"direction">,
|
|
2474
|
+
builder: StylesheetBuilder,
|
|
2475
|
+
) {
|
|
2476
|
+
if (["ltr", "rtl"].includes(declaration.value)) {
|
|
2477
|
+
builder.addDescriptor("direction", declaration.value);
|
|
2478
|
+
builder.addDescriptor("--__rn-css-direction", declaration.value);
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
builder.addWarning("value", declaration.value);
|
|
2482
|
+
return;
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2419
2485
|
export function parseAspectRatio({
|
|
2420
2486
|
value,
|
|
2421
2487
|
}: DeclarationType<"aspect-ratio">): StyleDescriptor {
|
|
@@ -2433,6 +2499,18 @@ export function parseAspectRatio({
|
|
|
2433
2499
|
}
|
|
2434
2500
|
}
|
|
2435
2501
|
|
|
2502
|
+
export function parseBackfaceVisibility(
|
|
2503
|
+
{ value }: DeclarationType<"backface-visibility">,
|
|
2504
|
+
builder: StylesheetBuilder,
|
|
2505
|
+
): StyleDescriptor {
|
|
2506
|
+
if (["visible", "hidden"].includes(value)) {
|
|
2507
|
+
return value;
|
|
2508
|
+
} else {
|
|
2509
|
+
builder.addWarning("value", value);
|
|
2510
|
+
return;
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2436
2514
|
export function parseDimension(
|
|
2437
2515
|
{ unit, value }: Extract<Token, { type: "dimension" }>,
|
|
2438
2516
|
builder: StylesheetBuilder,
|
|
@@ -3031,6 +3109,19 @@ function parseObjectPosition(
|
|
|
3031
3109
|
]);
|
|
3032
3110
|
}
|
|
3033
3111
|
|
|
3112
|
+
function parseCornerShape(
|
|
3113
|
+
declaration: CustomProperty,
|
|
3114
|
+
builder: StylesheetBuilder,
|
|
3115
|
+
) {
|
|
3116
|
+
const shape = parseUnparsed(declaration.value, builder, "corner-shape");
|
|
3117
|
+
|
|
3118
|
+
if (shape === "round") {
|
|
3119
|
+
builder.addDescriptor("borderCurve", "circular");
|
|
3120
|
+
} else if (shape === "squircle") {
|
|
3121
|
+
builder.addDescriptor("borderCurve", "continuous");
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
|
|
3034
3125
|
function parseVisibility(
|
|
3035
3126
|
declaration: DeclarationType<"visibility">,
|
|
3036
3127
|
builder: StylesheetBuilder,
|
|
@@ -3044,6 +3135,25 @@ function parseVisibility(
|
|
|
3044
3135
|
}
|
|
3045
3136
|
}
|
|
3046
3137
|
|
|
3138
|
+
function parseOutlineStyle(
|
|
3139
|
+
declaration: DeclarationType<"outline-style">,
|
|
3140
|
+
builder: StylesheetBuilder,
|
|
3141
|
+
) {
|
|
3142
|
+
const allowed = ["solid", "dotted", "dashed"];
|
|
3143
|
+
|
|
3144
|
+
if (
|
|
3145
|
+
declaration.value.type !== "auto" &&
|
|
3146
|
+
allowed.includes(declaration.value.value)
|
|
3147
|
+
) {
|
|
3148
|
+
builder.addDescriptor("outlineStyle", declaration.value.value);
|
|
3149
|
+
} else {
|
|
3150
|
+
builder.addWarning(
|
|
3151
|
+
"value",
|
|
3152
|
+
declaration.value.type === "auto" ? "auto" : declaration.value.value,
|
|
3153
|
+
);
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
|
|
3047
3157
|
function parseFilter(
|
|
3048
3158
|
declaration: DeclarationType<"filter">,
|
|
3049
3159
|
builder: StylesheetBuilder,
|
|
@@ -568,6 +568,12 @@ export class StylesheetBuilder {
|
|
|
568
568
|
: [value];
|
|
569
569
|
// Append extra media queries if they exist
|
|
570
570
|
this.shared[type][name].push(variableValue);
|
|
571
|
+
|
|
572
|
+
if (type === "rootVariables" && name === "__rn-css-em") {
|
|
573
|
+
const remName = "__rn-css-rem";
|
|
574
|
+
this.shared[type][remName] ??= [];
|
|
575
|
+
this.shared[type][remName].push(variableValue);
|
|
576
|
+
}
|
|
571
577
|
}
|
|
572
578
|
}
|
|
573
579
|
}
|
package/src/jest/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { inspect } from "node:util";
|
|
|
5
5
|
import { compile, type CompilerOptions } from "react-native-css/compiler";
|
|
6
6
|
import { StyleCollection } from "react-native-css/style-collection";
|
|
7
7
|
|
|
8
|
-
import { colorScheme, dimensions
|
|
8
|
+
import { colorScheme, dimensions } from "../runtime/native/reactivity";
|
|
9
9
|
|
|
10
10
|
declare global {
|
|
11
11
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
@@ -21,7 +21,6 @@ export const testID = "react-native-css";
|
|
|
21
21
|
beforeEach(() => {
|
|
22
22
|
StyleCollection.styles.clear();
|
|
23
23
|
dimensions.set(Dimensions.get("window"));
|
|
24
|
-
rem.set(14);
|
|
25
24
|
Appearance.setColorScheme(null);
|
|
26
25
|
colorScheme.set(null);
|
|
27
26
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
-
import { useContext, useState } from "react";
|
|
2
|
+
import { useContext, useMemo, useState, type PropsWithChildren } from "react";
|
|
3
3
|
import { Appearance } from "react-native";
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { StyleDescriptor } from "../../compiler";
|
|
6
6
|
import type {
|
|
7
7
|
ColorScheme,
|
|
8
8
|
Props,
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
VariableContext,
|
|
19
19
|
type Effect,
|
|
20
20
|
type Getter,
|
|
21
|
+
type VariableContextValue,
|
|
21
22
|
} from "./reactivity";
|
|
22
23
|
import { resolveValue } from "./styles/resolve";
|
|
23
24
|
|
|
@@ -102,7 +103,33 @@ export function useNativeVariable(name: string) {
|
|
|
102
103
|
return resolveValue([{}, "var", [name]], effect.get, { inheritedVariables });
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
/**
|
|
107
|
+
* @deprecated Use `<VariableContextProvider />` instead.
|
|
108
|
+
*/
|
|
105
109
|
export function vars(variables: Record<string, StyleDescriptor>) {
|
|
106
|
-
(
|
|
107
|
-
|
|
110
|
+
return Object.assign(
|
|
111
|
+
{ [VAR_SYMBOL]: "inline" },
|
|
112
|
+
Object.fromEntries(
|
|
113
|
+
Object.entries(variables).map(([k, v]) => [k.replace(/^--/, ""), v]),
|
|
114
|
+
),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function VariableContextProvider(
|
|
119
|
+
props: PropsWithChildren<{ value: Record<`--${string}`, StyleDescriptor> }>,
|
|
120
|
+
) {
|
|
121
|
+
const inheritedVariables = useContext(VariableContext);
|
|
122
|
+
|
|
123
|
+
const value: VariableContextValue = useMemo(
|
|
124
|
+
() => ({
|
|
125
|
+
...inheritedVariables,
|
|
126
|
+
...Object.fromEntries(
|
|
127
|
+
Object.entries(props.value).map(([k, v]) => [k.replace(/^--/, ""), v]),
|
|
128
|
+
),
|
|
129
|
+
[VAR_SYMBOL]: true,
|
|
130
|
+
}),
|
|
131
|
+
[inheritedVariables, props.value],
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
return <VariableContext value={value}>{props.children}</VariableContext>;
|
|
108
135
|
}
|
|
@@ -189,10 +189,6 @@ export const VariableContext = createContext<VariableContextValue>({
|
|
|
189
189
|
[VAR_SYMBOL]: true,
|
|
190
190
|
});
|
|
191
191
|
|
|
192
|
-
/** Units *********************************************************************/
|
|
193
|
-
|
|
194
|
-
export const rem = observable(14);
|
|
195
|
-
|
|
196
192
|
/** Pseudo Classes ************************************************************/
|
|
197
193
|
|
|
198
194
|
export const hoverFamily = weakFamily(() => observable(false));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { StyleFunctionResolver } from "./resolve";
|
|
2
|
+
|
|
3
|
+
export const lineHeight: StyleFunctionResolver = (resolve, func) => {
|
|
4
|
+
const value = resolve(func[2]);
|
|
5
|
+
|
|
6
|
+
if (typeof value !== "number") {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let emValue = resolve([{}, "var", ["__rn-css-em"]]);
|
|
11
|
+
|
|
12
|
+
if (typeof emValue !== "number") {
|
|
13
|
+
emValue = resolve([{}, "var", ["__rn-css-rem"]]);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof emValue !== "number") {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return round(value * emValue);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function round(number: number) {
|
|
24
|
+
return Math.round((number + Number.EPSILON) * 100) / 100;
|
|
25
|
+
}
|
|
@@ -10,6 +10,7 @@ import { type Getter, type VariableContextValue } from "../reactivity";
|
|
|
10
10
|
import type { calculateProps } from "./calculate-props";
|
|
11
11
|
import { transformKeys } from "./defaults";
|
|
12
12
|
import * as functions from "./functions";
|
|
13
|
+
import { lineHeight } from "./line-height";
|
|
13
14
|
import * as shorthands from "./shorthands";
|
|
14
15
|
import { em, rem, vh, vw } from "./units";
|
|
15
16
|
import { varResolver } from "./variables";
|
|
@@ -37,6 +38,7 @@ const functionResolvers = {
|
|
|
37
38
|
...shorthands,
|
|
38
39
|
...functions,
|
|
39
40
|
animationName: shorthands.animation,
|
|
41
|
+
lineHeight,
|
|
40
42
|
em,
|
|
41
43
|
rem,
|
|
42
44
|
vh,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StyleDescriptor } from "../../../../compiler";
|
|
1
2
|
import { isStyleDescriptorArray } from "../../../utils";
|
|
2
3
|
import type { StyleFunctionResolver } from "../resolve";
|
|
3
4
|
import { shorthandHandler } from "./_handler";
|
|
@@ -9,6 +10,27 @@ const blurRadius = ["blurRadius", "number"] as const;
|
|
|
9
10
|
const spreadDistance = ["spreadDistance", "number"] as const;
|
|
10
11
|
// const inset = ["inset", "string"] as const;
|
|
11
12
|
|
|
13
|
+
function deepFlattenToArrayOfStyleDescriptors(
|
|
14
|
+
arr: StyleDescriptor[],
|
|
15
|
+
): StyleDescriptor[] {
|
|
16
|
+
const result: StyleDescriptor[] = [];
|
|
17
|
+
const stack = [arr];
|
|
18
|
+
while (stack.length > 0) {
|
|
19
|
+
const current = stack.pop();
|
|
20
|
+
if (Array.isArray(current)) {
|
|
21
|
+
if (current.length > 0 && Array.isArray(current[0])) {
|
|
22
|
+
for (let i = current.length - 1; i >= 0; i--) {
|
|
23
|
+
const elem = current[i];
|
|
24
|
+
if (isStyleDescriptorArray(elem)) stack.push(elem);
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
result.push(current);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
12
34
|
const handler = shorthandHandler(
|
|
13
35
|
[
|
|
14
36
|
[offsetX, offsetY, blurRadius, spreadDistance, color],
|
|
@@ -33,26 +55,10 @@ export const boxShadow: StyleFunctionResolver = (
|
|
|
33
55
|
if (!isStyleDescriptorArray(args)) {
|
|
34
56
|
return args;
|
|
35
57
|
} else {
|
|
36
|
-
return args
|
|
37
|
-
.
|
|
58
|
+
return deepFlattenToArrayOfStyleDescriptors(args)
|
|
59
|
+
.map((shadows) => {
|
|
38
60
|
if (shadows === undefined) {
|
|
39
61
|
return [];
|
|
40
|
-
} else if (isStyleDescriptorArray(shadows)) {
|
|
41
|
-
if (shadows.length === 0) {
|
|
42
|
-
return [];
|
|
43
|
-
} else if (Array.isArray(shadows[0])) {
|
|
44
|
-
return shadows
|
|
45
|
-
.map((shadow) => {
|
|
46
|
-
return omitTransparentShadows(
|
|
47
|
-
handler(resolveValue, shadow, get, options),
|
|
48
|
-
);
|
|
49
|
-
})
|
|
50
|
-
.filter((v) => v !== undefined);
|
|
51
|
-
} else {
|
|
52
|
-
return omitTransparentShadows(
|
|
53
|
-
handler(resolveValue, shadows, get, options),
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
62
|
} else {
|
|
57
63
|
return omitTransparentShadows(
|
|
58
64
|
handler(resolveValue, shadows, get, options),
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { rem as remObs, vh as vhObs, vw as vwObs } from "../reactivity";
|
|
1
|
+
import { vh as vhObs, vw as vwObs } from "../reactivity";
|
|
3
2
|
import type { StyleFunctionResolver } from "./resolve";
|
|
4
3
|
|
|
5
|
-
export const em: StyleFunctionResolver = (resolve, func
|
|
6
|
-
|
|
4
|
+
export const em: StyleFunctionResolver = (resolve, func) => {
|
|
5
|
+
const value = func[2];
|
|
7
6
|
|
|
8
7
|
if (typeof value !== "number") {
|
|
9
8
|
return;
|
|
@@ -12,14 +11,14 @@ export const em: StyleFunctionResolver = (resolve, func, get) => {
|
|
|
12
11
|
let emValue = resolve([{}, "var", ["__rn-css-em"]]);
|
|
13
12
|
|
|
14
13
|
if (typeof emValue !== "number") {
|
|
15
|
-
emValue =
|
|
14
|
+
emValue = resolve([{}, "var", ["__rn-css-rem"]]);
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
if (typeof emValue !== "number") {
|
|
19
18
|
return;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
return round(
|
|
21
|
+
return round(value * emValue);
|
|
23
22
|
};
|
|
24
23
|
|
|
25
24
|
export const vw: StyleFunctionResolver = (_, func, get) => {
|
|
@@ -42,14 +41,20 @@ export const vh: StyleFunctionResolver = (_, func, get) => {
|
|
|
42
41
|
return round((value / 100) * get(vhObs));
|
|
43
42
|
};
|
|
44
43
|
|
|
45
|
-
export const rem: StyleFunctionResolver = (
|
|
44
|
+
export const rem: StyleFunctionResolver = (resolve, func) => {
|
|
46
45
|
const value = func[2];
|
|
47
46
|
|
|
48
47
|
if (typeof value !== "number") {
|
|
49
48
|
return;
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
const remValue = resolve([{}, "var", ["__rn-css-rem"]]);
|
|
52
|
+
|
|
53
|
+
if (typeof remValue === "number") {
|
|
54
|
+
return round(value * remValue);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return;
|
|
53
58
|
};
|
|
54
59
|
|
|
55
60
|
function round(number: number) {
|