11import  {  parse ,  type  CssNode ,  type  Value  }  from  'css-tree' 
22import  {  color_to_token  }  from  './colors.js' 
3- import  type  {  ColorToken ,   ColorValue  }  from  './types.js' 
3+ import  type  {  ColorValue  }  from  './types.js' 
44import  {  namedColors  as  named_colors ,  systemColors  as  system_colors ,  colorFunctions  as  color_functions  }  from  '@projectwallace/css-analyzer' 
55
6- type  CssLength  =  { 
6+ export   type  CssLength  =  { 
77	value : number 
88	unit : string 
99} 
1010
11- export  type  DestructuredShadow  =  { 
11+ export  type  ShadowValue  =  { 
1212	color : ColorValue  |  undefined 
1313	offsetX : CssLength  |  undefined 
1414	offsetY : CssLength  |  undefined 
@@ -17,7 +17,7 @@ export type DestructuredShadow = {
1717	inset : boolean  |  undefined 
1818} 
1919
20- function  create_destructured ( ) : DestructuredShadow  { 
20+ function  create_destructured ( ) : ShadowValue  { 
2121	return  { 
2222		color : undefined , 
2323		offsetX : undefined , 
@@ -28,10 +28,10 @@ function create_destructured(): DestructuredShadow {
2828	} 
2929} 
3030
31- export  function  destructure_box_shadow ( value : string ) : null  |  DestructuredShadow [ ]  { 
31+ export  function  destructure_box_shadow ( value : string ) : null  |  ShadowValue [ ]  { 
3232	let  ast  =  parse ( value ,  { 
3333		context : 'value' , 
34- 		positions : true 
34+ 		positions : true , 
3535	} )  as  Value 
3636
3737	function  generate ( node : CssNode )  { 
@@ -42,7 +42,7 @@ export function destructure_box_shadow(value: string): null | DestructuredShadow
4242	} 
4343
4444	let  current_shadow  =  create_destructured ( ) 
45- 	let  destructured : DestructuredShadow [ ]  =  [ current_shadow ] 
45+ 	let  destructured : ShadowValue [ ]  =  [ current_shadow ] 
4646
4747	if  ( ast . children . size  <  2 )  { 
4848		return  null 
@@ -59,15 +59,17 @@ export function destructure_box_shadow(value: string): null | DestructuredShadow
5959				} 
6060				current_shadow . color  =  color_token 
6161			} 
62- 		} 
63- 		else  if  ( node . type  ===  'Dimension'  ||  ( node . type  ===  'Number'  &&  node . value  ===  '0' ) )  { 
64- 			let  length  =  node . type  ===  'Dimension'  ? { 
65- 				value : Number ( node . value ) , 
66- 				unit : node . unit 
67- 			}  : { 
68- 				value : 0 , 
69- 				unit : 'px' , 
70- 			} 
62+ 		}  else  if  ( node . type  ===  'Dimension'  ||  ( node . type  ===  'Number'  &&  node . value  ===  '0' ) )  { 
63+ 			let  length  = 
64+ 				node . type  ===  'Dimension' 
65+ 					? { 
66+ 							value : Number ( node . value ) , 
67+ 							unit : node . unit , 
68+ 					  } 
69+ 					: { 
70+ 							value : 0 , 
71+ 							unit : 'px' , 
72+ 					  } 
7173
7274			if  ( ! current_shadow . offsetX )  { 
7375				current_shadow . offsetX  =  length 
@@ -78,8 +80,7 @@ export function destructure_box_shadow(value: string): null | DestructuredShadow
7880			}  else  if  ( ! current_shadow . spread )  { 
7981				current_shadow . spread  =  length 
8082			} 
81- 		} 
82- 		else  if  ( node . type  ===  'Function' )  { 
83+ 		}  else  if  ( node . type  ===  'Function' )  { 
8384			if  ( color_functions . has ( node . name ) )  { 
8485				let  color_token  =  color_to_token ( generate ( node ) ) 
8586				if  ( color_token  ===  null )  { 
@@ -93,15 +94,13 @@ export function destructure_box_shadow(value: string): null | DestructuredShadow
9394				} 
9495				current_shadow . color  =  color_token 
9596			} 
96- 		} 
97- 		else  if  ( node . type  ===  'Hash' )  { 
97+ 		}  else  if  ( node . type  ===  'Hash' )  { 
9898			let  color_token  =  color_to_token ( generate ( node ) ) 
9999			if  ( color_token  ===  null )  { 
100100				return 
101101			} 
102102			current_shadow . color  =  color_token 
103- 		} 
104- 		else  if  ( node . type  ===  'Operator'  &&  node . value  ===  ',' )  { 
103+ 		}  else  if  ( node . type  ===  'Operator'  &&  node . value  ===  ',' )  { 
105104			// Start a new shadow, but only after we've made sure that the current shadow is valid 
106105			complete_shadow_token ( current_shadow ) 
107106			current_shadow  =  create_destructured ( ) 
@@ -116,15 +115,15 @@ export function destructure_box_shadow(value: string): null | DestructuredShadow
116115
117116const  DIMENSION_ZERO  =  { 
118117	value : 0 , 
119- 	unit : 'px' 
118+ 	unit : 'px' , 
120119} 
121120
122121/** 
123122 * @description  
124123 * According to the spec every shadow MUST have an offsetX, offsetY, blur, spread and color, 
125124 * only the inset is optional and defaults to false. 
126125 */ 
127- function  complete_shadow_token ( token : DestructuredShadow )  { 
126+ function  complete_shadow_token ( token : ShadowValue )  { 
128127	if  ( ! token . offsetX )  { 
129128		token . offsetX  =  DIMENSION_ZERO 
130129	} 
0 commit comments