@@ -37,30 +37,32 @@ import type { StyleDescriptor, StyleFunction } from "./compiler.types";
3737import { parseEasingFunction , parseIterationCount } from "./keyframes" ;
3838import { toRNProperty } from "./selectors" ;
3939import type { StylesheetBuilder } from "./stylesheet" ;
40- import { isValid , validProperties , validPropertiesLoose } from "./valid" ;
40+
41+ const CommaSeparator = Symbol ( "CommaSeparator" ) ;
4142
4243type DeclarationType < P extends Declaration [ "property" ] > = Extract <
4344 Declaration ,
4445 { property : P }
4546> ;
4647
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 } > ,
4950 builder : StylesheetBuilder ,
5051 // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
5152) => StyleDescriptor | void ;
5253
5354const propertyRename : Record < string , string > = { } ;
5455
55- const runtimeShorthands = new Set ( [
56+ const needsRuntimeParsing = new Set ( [
5657 "animation" ,
5758 "text-shadow" ,
5859 "transform" ,
60+ "box-shadow" ,
5961 "border" ,
6062] ) ;
6163
6264const parsers : {
63- [ K in ( typeof validProperties ) [ number ] ] : Parser < K > ;
65+ [ K in Declaration [ "property" ] ] ? : Parser < K > ;
6466} = {
6567 "align-content" : parseAlignContent ,
6668 "align-items" : parseAlignItems ,
@@ -189,7 +191,6 @@ const parsers: {
189191 "padding-left" : parseSizeDeclaration ,
190192 "padding-right" : parseSizeDeclaration ,
191193 "padding-top" : parseSizeDeclaration ,
192- "pointer-events" : parsePointerEvents ,
193194 "position" : parsePosition ,
194195 "right" : parseSizeDeclaration ,
195196 "rotate" : parseRotate ,
@@ -218,6 +219,12 @@ const parsers: {
218219 "z-index" : parseZIndex ,
219220} ;
220221
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+
221228export function parseDeclaration (
222229 declaration : Declaration ,
223230 builder : StylesheetBuilder ,
@@ -783,7 +790,7 @@ export function parseDeclarationUnparsed(
783790) {
784791 let property = declaration . value . propertyId . property ;
785792
786- if ( ! isValid ( declaration . value . propertyId ) ) {
793+ if ( ! ( property in parsers ) ) {
787794 builder . addWarning ( "property" , property ) ;
788795 return ;
789796 }
@@ -799,7 +806,7 @@ export function parseDeclarationUnparsed(
799806 /**
800807 * Unparsed shorthand properties need to be parsed at runtime
801808 */
802- if ( runtimeShorthands . has ( property ) ) {
809+ if ( needsRuntimeParsing . has ( property ) ) {
803810 let args = parseUnparsed ( declaration . value . value , builder ) ;
804811 if ( ! isStyleDescriptorArray ( args ) ) {
805812 args = [ args ] ;
@@ -833,7 +840,7 @@ export function parseDeclarationCustom(
833840) {
834841 const property = declaration . value . name ;
835842 if (
836- validPropertiesLoose . has ( property ) ||
843+ validProperties . has ( property ) ||
837844 property . startsWith ( "--" ) ||
838845 property . startsWith ( "-rn-" )
839846 ) {
@@ -856,9 +863,21 @@ export function reduceParseUnparsed(
856863
857864 if ( result . length === 0 ) {
858865 return undefined ;
859- } else {
860- return result ;
861866 }
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 ;
862881}
863882
864883export function unparsedFunction (
@@ -1004,6 +1023,8 @@ export function parseUnparsed(
10041023 return `${ round ( tokenOrValue . value . value * 100 ) } %` ;
10051024 case "dimension" :
10061025 return parseDimension ( tokenOrValue . value , builder ) ;
1026+ case "comma" :
1027+ return CommaSeparator as unknown as StyleDescriptor ;
10071028 case "at-keyword" :
10081029 case "hash" :
10091030 case "id-hash" :
@@ -1013,7 +1034,6 @@ export function parseUnparsed(
10131034 case "comment" :
10141035 case "colon" :
10151036 case "semicolon" :
1016- case "comma" :
10171037 case "include-match" :
10181038 case "dash-match" :
10191039 case "prefix-match" :
@@ -1997,29 +2017,20 @@ export function parseTextAlign(
19972017}
19982018
19992019export function parseBoxShadow (
2000- { value } : DeclarationType < "box-shadow" > ,
2001- builder : StylesheetBuilder ,
2020+ _ : DeclarationType < "box-shadow" > ,
2021+ _builder : StylesheetBuilder ,
20022022) {
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 ;
20132024
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+ // } ),
20232034 // );
20242035}
20252036
0 commit comments