@@ -37,30 +37,32 @@ import type { StyleDescriptor, StyleFunction } from "./compiler.types";
37
37
import { parseEasingFunction , parseIterationCount } from "./keyframes" ;
38
38
import { toRNProperty } from "./selectors" ;
39
39
import type { StylesheetBuilder } from "./stylesheet" ;
40
- import { isValid , validProperties , validPropertiesLoose } from "./valid" ;
40
+
41
+ const CommaSeparator = Symbol ( "CommaSeparator" ) ;
41
42
42
43
type DeclarationType < P extends Declaration [ "property" ] > = Extract <
43
44
Declaration ,
44
45
{ property : P }
45
46
> ;
46
47
47
- type Parser < K extends ( typeof validProperties ) [ number ] > = (
48
- declaration : Extract < Declaration , { property : K } > ,
48
+ type Parser < T extends Declaration [ "property" ] > = (
49
+ declaration : Extract < Declaration , { property : T } > ,
49
50
builder : StylesheetBuilder ,
50
51
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
51
52
) => StyleDescriptor | void ;
52
53
53
54
const propertyRename : Record < string , string > = { } ;
54
55
55
- const runtimeShorthands = new Set ( [
56
+ const needsRuntimeParsing = new Set ( [
56
57
"animation" ,
57
58
"text-shadow" ,
58
59
"transform" ,
60
+ "box-shadow" ,
59
61
"border" ,
60
62
] ) ;
61
63
62
64
const parsers : {
63
- [ K in ( typeof validProperties ) [ number ] ] : Parser < K > ;
65
+ [ K in Declaration [ "property" ] ] ? : Parser < K > ;
64
66
} = {
65
67
"align-content" : parseAlignContent ,
66
68
"align-items" : parseAlignItems ,
@@ -189,7 +191,6 @@ const parsers: {
189
191
"padding-left" : parseSizeDeclaration ,
190
192
"padding-right" : parseSizeDeclaration ,
191
193
"padding-top" : parseSizeDeclaration ,
192
- "pointer-events" : parsePointerEvents ,
193
194
"position" : parsePosition ,
194
195
"right" : parseSizeDeclaration ,
195
196
"rotate" : parseRotate ,
@@ -218,6 +219,12 @@ const parsers: {
218
219
"z-index" : parseZIndex ,
219
220
} ;
220
221
222
+ // This is missing LightningCSS types
223
+ ( parsers as Record < string , Parser < Declaration [ "property" ] > > ) [ "pointer-events" ] =
224
+ parsePointerEvents as Parser < Declaration [ "property" ] > ;
225
+
226
+ const validProperties = new Set ( Object . keys ( parsers ) ) ;
227
+
221
228
export function parseDeclaration (
222
229
declaration : Declaration ,
223
230
builder : StylesheetBuilder ,
@@ -783,7 +790,7 @@ export function parseDeclarationUnparsed(
783
790
) {
784
791
let property = declaration . value . propertyId . property ;
785
792
786
- if ( ! isValid ( declaration . value . propertyId ) ) {
793
+ if ( ! ( property in parsers ) ) {
787
794
builder . addWarning ( "property" , property ) ;
788
795
return ;
789
796
}
@@ -799,7 +806,7 @@ export function parseDeclarationUnparsed(
799
806
/**
800
807
* Unparsed shorthand properties need to be parsed at runtime
801
808
*/
802
- if ( runtimeShorthands . has ( property ) ) {
809
+ if ( needsRuntimeParsing . has ( property ) ) {
803
810
let args = parseUnparsed ( declaration . value . value , builder ) ;
804
811
if ( ! isStyleDescriptorArray ( args ) ) {
805
812
args = [ args ] ;
@@ -833,7 +840,7 @@ export function parseDeclarationCustom(
833
840
) {
834
841
const property = declaration . value . name ;
835
842
if (
836
- validPropertiesLoose . has ( property ) ||
843
+ validProperties . has ( property ) ||
837
844
property . startsWith ( "--" ) ||
838
845
property . startsWith ( "-rn-" )
839
846
) {
@@ -856,9 +863,21 @@ export function reduceParseUnparsed(
856
863
857
864
if ( result . length === 0 ) {
858
865
return undefined ;
859
- } else {
860
- return result ;
861
866
}
867
+
868
+ let currentGroup : StyleDescriptor [ ] = [ ] ;
869
+ const groups : StyleDescriptor [ ] [ ] = [ currentGroup ] ;
870
+
871
+ for ( const value of result ) {
872
+ if ( ( value as unknown ) === CommaSeparator ) {
873
+ currentGroup = [ ] ;
874
+ groups . push ( currentGroup ) ;
875
+ } else {
876
+ currentGroup . push ( value ) ;
877
+ }
878
+ }
879
+
880
+ return groups . length === 1 ? groups [ 0 ] : groups ;
862
881
}
863
882
864
883
export function unparsedFunction (
@@ -1004,6 +1023,8 @@ export function parseUnparsed(
1004
1023
return `${ round ( tokenOrValue . value . value * 100 ) } %` ;
1005
1024
case "dimension" :
1006
1025
return parseDimension ( tokenOrValue . value , builder ) ;
1026
+ case "comma" :
1027
+ return CommaSeparator as unknown as StyleDescriptor ;
1007
1028
case "at-keyword" :
1008
1029
case "hash" :
1009
1030
case "id-hash" :
@@ -1013,7 +1034,6 @@ export function parseUnparsed(
1013
1034
case "comment" :
1014
1035
case "colon" :
1015
1036
case "semicolon" :
1016
- case "comma" :
1017
1037
case "include-match" :
1018
1038
case "dash-match" :
1019
1039
case "prefix-match" :
@@ -1997,29 +2017,20 @@ export function parseTextAlign(
1997
2017
}
1998
2018
1999
2019
export function parseBoxShadow (
2000
- { value } : DeclarationType < "box-shadow" > ,
2001
- builder : StylesheetBuilder ,
2020
+ _ : DeclarationType < "box-shadow" > ,
2021
+ _builder : StylesheetBuilder ,
2002
2022
) {
2003
- if ( value . length > 1 ) {
2004
- builder . addWarning ( "value" , "multiple box shadows" ) ;
2005
- return ;
2006
- }
2007
-
2008
- const boxShadow = value [ 0 ] ;
2009
-
2010
- if ( ! boxShadow ) {
2011
- return ;
2012
- }
2023
+ return undefined ;
2013
2024
2014
- builder . addDescriptor ( "shadowColor" , parseColor ( boxShadow . color , builder ) ) ;
2015
- builder . addDescriptor ( "shadowRadius" , parseLength ( boxShadow . spread , builder ) ) ;
2016
- // builder.addDescriptor("style" ,
2017
- // ["shadowOffsetWidth"] ,
2018
- // parseLength(boxShadow.xOffset, options, ["", "") ,
2019
- // );
2020
- // builder.addDescriptor("style" ,
2021
- // ["shadowOffset", "height"] ,
2022
- // parseLength(boxShadow.yOffset, builder ),
2025
+ // return value.map(
2026
+ // (shadow): BoxShadowValue => ({
2027
+ // color: parseColor(shadow.color, builder) ,
2028
+ // offsetX: parseLength(shadow.xOffset, builder) as number ,
2029
+ // offsetY: parseLength(shadow.yOffset, builder) as number ,
2030
+ // blurRadius: parseLength(shadow.blur, builder) as number,
2031
+ // spreadDistance: parseLength(shadow.spread, builder) as number ,
2032
+ // inset: shadow.inset ,
2033
+ // } ),
2023
2034
// );
2024
2035
}
2025
2036
0 commit comments