import { CoreTypes } from '../../core-types' ; import { Color } from '../../color' ; import { Length , zeroLength } from './style-properties' ; export interface CSSShadow { inset : boolean ; offsetX : CoreTypes . LengthType ; offsetY : CoreTypes . LengthType ; blurRadius ? : CoreTypes . LengthType ; spreadRadius ? : CoreTypes . LengthType ; color : Color ; } /**
 * Matches whitespace except if the whitespace is contained in parenthesis - ex. rgb(a), hsl color.
 */ const PARTS_RE = /\s(?![^(]*\))/ ; /**
 * Matches a Length value with or without a unit
 */ const LENGTH_RE = /^-?[0-9]+[a-zA-Z%]*?$/ ; /**
 * Checks if the value is a Length or 0
 */ const isLength = ( v ) => v === '0' || LENGTH_RE . test ( v ) ; param value export function parseCSSShadow ( value ) { const parts = value . trim ( ) . split ( PARTS_RE ) ; const inset = parts . includes ( 'inset' ) ; const first = parts [ 0 ] ; const last = parts [ parts . length - 1 ] ; if ( first === 'none' ) { return null ; } let colorRaw = 'black' ; if ( ! isLength ( first ) && first !== 'inset' ) { colorRaw = first ; } else if ( ! isLength ( last ) ) { colorRaw = last ; } const nums = parts . filter ( ( n ) => n !== 'inset' ) . filter ( ( n ) => n !== colorRaw ) . map ( ( val ) => { try { return Length . parse ( val ) ; } catch ( err ) { return zeroLength ; } } ) ; const [ offsetX , offsetY , blurRadius , spreadRadius ] = nums ; return { inset , offsetX : offsetX , offsetY : offsetY , blurRadius : blurRadius , spreadRadius : spreadRadius , color : new Color ( colorRaw ) , } ; }