1+ import type { StyleDescriptor } from "../../../../compiler" ;
12import { isStyleDescriptorArray } from "../../../utils" ;
23import type { StyleFunctionResolver } from "../resolve" ;
34import { shorthandHandler } from "./_handler" ;
@@ -9,6 +10,27 @@ const blurRadius = ["blurRadius", "number"] as const;
910const spreadDistance = [ "spreadDistance" , "number" ] as const ;
1011// const inset = ["inset", "string"] as const;
1112
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+
1234const handler = shorthandHandler (
1335 [
1436 [ offsetX , offsetY , blurRadius , spreadDistance , color ] ,
@@ -33,26 +55,10 @@ export const boxShadow: StyleFunctionResolver = (
3355 if ( ! isStyleDescriptorArray ( args ) ) {
3456 return args ;
3557 } else {
36- return args
37- . flatMap ( ( shadows ) => {
58+ return deepFlattenToArrayOfStyleDescriptors ( args )
59+ . map ( ( shadows ) => {
3860 if ( shadows === undefined ) {
3961 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- }
5662 } else {
5763 return omitTransparentShadows (
5864 handler ( resolveValue , shadows , get , options ) ,
0 commit comments