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

Function domParseColor

src/utils/color.ts:681–693  ·  view source on GitHub ↗
($color: string)

Source from the content-addressed store, hash-verified

679let context: CanvasRenderingContext2D;
680
681function domParseColor($color: string) {
682 if (!context) {
683 canvas = document.createElement('canvas');
684 canvas.width = 1;
685 canvas.height = 1;
686 context = canvas.getContext('2d', {willReadFrequently: true})!;
687 }
688 context.fillStyle = $color;
689 context.fillRect(0, 0, 1, 1);
690 const d = context.getImageData(0, 0, 1, 1).data;
691 const color = `rgba(${d[0]}, ${d[1]}, ${d[2]}, ${(d[3] / 255).toFixed(2)})`;
692 return parseRGB(color);
693}

Callers 1

parseFunction · 0.85

Calls 1

parseRGBFunction · 0.85

Tested by

no test coverage detected