(value: string)
| 687 | } |
| 688 | |
| 689 | export function getShadowModifierWithInfo(value: string): CSSValueModifierWithInfo | null { |
| 690 | try { |
| 691 | let index = 0; |
| 692 | const colorMatches = getMatches(/(^|\s)(?!calc)([a-z]+\(.+?\)|#[0-9a-f]+|[a-z]+)(.*?(inset|outset)?($|,))/ig, value, 2); |
| 693 | let notParsed = 0; |
| 694 | const modifiers = colorMatches.map((match, i) => { |
| 695 | const prefixIndex = index; |
| 696 | const matchIndex = value.indexOf(match, index); |
| 697 | const matchEnd = matchIndex + match.length; |
| 698 | index = matchEnd; |
| 699 | const rgb = parseColorWithCache(match); |
| 700 | if (!rgb) { |
| 701 | notParsed++; |
| 702 | return () => value.substring(prefixIndex, matchEnd); |
| 703 | } |
| 704 | return (theme: Theme) => `${value.substring(prefixIndex, matchIndex)}${modifyShadowColor(rgb, theme)}${i === colorMatches.length - 1 ? value.substring(matchEnd) : ''}`; |
| 705 | }); |
| 706 | |
| 707 | return (theme: Theme) => { |
| 708 | const modified = modifiers.map((modify) => modify(theme)).join(''); |
| 709 | return { |
| 710 | matchesLength: colorMatches.length, |
| 711 | unparsableMatchesLength: notParsed, |
| 712 | result: modified, |
| 713 | }; |
| 714 | }; |
| 715 | } catch (err) { |
| 716 | logWarn(`Unable to parse shadow ${value}`, err); |
| 717 | return null; |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | export function getShadowModifier(value: string): CSSValueModifier | null { |
| 722 | const shadowModifier = getShadowModifierWithInfo(value); |
no test coverage detected