MCPcopy
hub / github.com/darkreader/darkreader / getShadowModifierWithInfo

Function getShadowModifierWithInfo

src/inject/dynamic-theme/modify-css.ts:689–719  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

687}
688
689export 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
721export function getShadowModifier(value: string): CSSValueModifier | null {
722 const shadowModifier = getShadowModifierWithInfo(value);

Callers 2

modifyMethod · 0.90
getShadowModifierFunction · 0.85

Calls 4

getMatchesFunction · 0.90
parseColorWithCacheFunction · 0.90
modifyShadowColorFunction · 0.90
logWarnFunction · 0.90

Tested by

no test coverage detected