1
- import { CoreTypes } from '../../core-types' ;
2
1
import { Color } from '../../color' ;
3
- import { Length } from './style-properties' ;
2
+ import { CoreTypes } from '../../core-types' ;
3
+ import { parseCSSShorthand } from './css-utils' ;
4
4
5
5
export interface ShadowCSSValues {
6
6
inset : boolean ;
@@ -11,57 +11,6 @@ export interface ShadowCSSValues {
11
11
color : Color ;
12
12
}
13
13
14
- /**
15
- * Matches whitespace except if the whitespace is contained in parenthesis - ex. rgb(a), hsl color.
16
- */
17
- const PARTS_RE = / \s (? ! [ ^ ( ] * \) ) / ;
18
-
19
- /**
20
- * Matches a Length value with or without a unit
21
- */
22
- const LENGTH_RE = / ^ - ? [ 0 - 9 ] + [ a - z A - Z % ] * ?$ / ;
23
-
24
- /**
25
- * Checks if the value is a Length or 0
26
- */
27
- const isLength = ( v ) => v === '0' || LENGTH_RE . test ( v ) ;
28
-
29
- export function parseCSSShorthand ( value : string ) : {
30
- values : Array < CoreTypes . LengthType > ;
31
- color : string ;
32
- inset : boolean ;
33
- } {
34
- const parts = value . trim ( ) . split ( PARTS_RE ) ;
35
- const inset = parts . includes ( 'inset' ) ;
36
- const first = parts [ 0 ] ;
37
- const last = parts [ parts . length - 1 ] ;
38
-
39
- if ( first === 'none' ) {
40
- return null ;
41
- }
42
-
43
- let color = 'black' ;
44
- if ( first && ! isLength ( first ) && first !== 'inset' ) {
45
- color = first ;
46
- } else if ( last && ! isLength ( last ) ) {
47
- color = last ;
48
- }
49
- const values = parts
50
- . filter ( ( n ) => n !== 'inset' )
51
- . filter ( ( n ) => n !== color )
52
- . map ( ( val ) => {
53
- try {
54
- return Length . parse ( val ) ;
55
- } catch ( err ) {
56
- return CoreTypes . zeroLength ;
57
- }
58
- } ) ;
59
- return {
60
- inset,
61
- color,
62
- values,
63
- } ;
64
- }
65
14
/**
66
15
* Parse a string into ShadowCSSValues
67
16
* Supports any valid css box/text shadow combination.
@@ -80,6 +29,6 @@ export function parseCSSShadow(value: string): ShadowCSSValues {
80
29
offsetY : offsetY ,
81
30
blurRadius : blurRadius ,
82
31
spreadRadius : spreadRadius ,
83
- color : new Color ( data . color ) ,
32
+ color : data . color ? new Color ( data . color ) : undefined ,
84
33
} ;
85
34
}
0 commit comments