MCPcopy Index your code
hub / github.com/darkreader/darkreader / handleRawColorValue

Function handleRawColorValue

src/inject/dynamic-theme/variables.ts:812–840  ·  view source on GitHub ↗
(
    input: string,
    theme: Theme,
    modifyFunction: (rgb: RGBA, theme: Theme, useRegisteredVarColor?: boolean) => string,
)

Source from the content-addressed store, hash-verified

810}
811
812function handleRawColorValue(
813 input: string,
814 theme: Theme,
815 modifyFunction: (rgb: RGBA, theme: Theme, useRegisteredVarColor?: boolean) => string,
816) {
817 const {isRaw, color} = parseRawColorValue(input);
818
819 const rgb = parseColorWithCache(color);
820 if (rgb) {
821 const outputColor = modifyFunction(rgb, theme, !isRaw);
822
823 // If it's raw, we need to convert it back to the "raw" format.
824 if (isRaw) {
825 // This should technically never fail(returning an empty string),
826 // but just to be safe, we will return outputColor.
827 const outputInRGB = parseColorWithCache(outputColor);
828 return (
829 outputInRGB ? (
830 Number.isNaN(outputInRGB.a) || outputInRGB.a === 1 ?
831 `${outputInRGB.r}, ${outputInRGB.g}, ${outputInRGB.b}` :
832 `${outputInRGB.r}, ${outputInRGB.g}, ${outputInRGB.b}, ${outputInRGB.a}`
833 ) :
834 outputColor
835 );
836 }
837 return outputColor;
838 }
839 return color;
840}
841
842function tryModifyBgColor(color: string, theme: Theme) {
843 return handleRawColorValue(color, theme, modifyBackgroundColor);

Callers 3

tryModifyBgColorFunction · 0.85
tryModifyTextColorFunction · 0.85
tryModifyBorderColorFunction · 0.85

Calls 2

parseColorWithCacheFunction · 0.90
parseRawColorValueFunction · 0.85

Tested by

no test coverage detected