MCPcopy
hub / github.com/darkreader/darkreader / getGradientModifier

Function getGradientModifier

src/inject/dynamic-theme/modify-css.ts:448–482  ·  view source on GitHub ↗
(gradient: ParsedGradient)

Source from the content-addressed store, hash-verified

446 .sort((a, b) => a.index > b.index ? 1 : -1);
447
448 const getGradientModifier = (gradient: ParsedGradient) => {
449 const {typeGradient, match, hasComma} = gradient;
450
451 const partsRegex = /([^\(\),]+(\([^\(\)]*(\([^\(\)]*\)*[^\(\)]*)?\))?([^\(\), ]|( (?!calc)))*),?/g;
452 const colorStopRegex = /^(from|color-stop|to)\(([^\(\)]*?,\s*)?(.*?)\)$/;
453
454 const parts = getMatches(partsRegex, match, 1).map((part) => {
455 part = part.trim();
456
457 let rgb = parseColorWithCache(part);
458 if (rgb) {
459 return (theme: Theme) => modifyGradientColor(rgb!, theme);
460 }
461
462 const space = part.lastIndexOf(' ');
463 rgb = parseColorWithCache(part.substring(0, space));
464 if (rgb) {
465 return (theme: Theme) => `${modifyGradientColor(rgb!, theme)} ${part.substring(space + 1)}`;
466 }
467
468 const colorStopMatch = part.match(colorStopRegex);
469 if (colorStopMatch) {
470 rgb = parseColorWithCache(colorStopMatch[3]);
471 if (rgb) {
472 return (theme: Theme) => `${colorStopMatch[1]}(${colorStopMatch[2] ? `${colorStopMatch[2]}, ` : ''}${modifyGradientColor(rgb!, theme)})`;
473 }
474 }
475
476 return () => part;
477 });
478
479 return (theme: Theme) => {
480 return `${typeGradient}(${parts.map((modify) => modify(theme)).join(', ')})${hasComma ? ', ' : ''}`;
481 };
482 };
483
484 const getURLModifier = (urlValue: string) => {
485 if (!didTryLoadCache) {

Callers 1

getBgImageModifierFunction · 0.85

Calls 3

getMatchesFunction · 0.90
parseColorWithCacheFunction · 0.90
modifyGradientColorFunction · 0.90

Tested by

no test coverage detected