| 48 | } |
| 49 | |
| 50 | export function parseCSSShorthand(value: string): { |
| 51 | values: Array<CoreTypes.LengthType>; |
| 52 | color: string; |
| 53 | inset: boolean; |
| 54 | } { |
| 55 | const parts = value.trim().split(WHITE_SPACE_RE); |
| 56 | const first = parts[0]; |
| 57 | |
| 58 | if (['', 'none', 'unset'].includes(first)) { |
| 59 | return null; |
| 60 | } |
| 61 | |
| 62 | const invalidColors = ['inset', 'unset']; |
| 63 | const inset = parts.includes('inset'); |
| 64 | const last = parts[parts.length - 1]; |
| 65 | let color = 'black'; |
| 66 | if (first && !isLength(first) && !invalidColors.includes(first)) { |
| 67 | color = first; |
| 68 | } else if (last && !isLength(last) && !invalidColors.includes(last)) { |
| 69 | color = last; |
| 70 | } |
| 71 | |
| 72 | const values = parts |
| 73 | .filter((n) => !invalidColors.includes(n)) |
| 74 | .filter((n) => n !== color) |
| 75 | .map((val) => { |
| 76 | try { |
| 77 | return Length.parse(val); |
| 78 | } catch (err) { |
| 79 | return CoreTypes.zeroLength; |
| 80 | } |
| 81 | }); |
| 82 | |
| 83 | return { |
| 84 | inset, |
| 85 | color, |
| 86 | values, |
| 87 | }; |
| 88 | } |