move theme code to own file

This commit is contained in:
Vinzenz Schroeter 2024-04-14 13:32:34 +02:00
commit 52e09ae5ef

View file

@ -1,6 +1,7 @@
import useWebSocket from 'react-use-websocket';
import {useEffect, useRef} from 'react';
import './ClientScreen.css';
import {getTheme} from "./theme.ts";
const pixelsPerRow = 352;
const pixelsPerCol = 160;
@ -12,9 +13,6 @@ function getIndexes(bitIndex: number) {
};
}
// @ts-ignore
const rootElement = document.querySelector(':root')!;
function normalizeColor(context: CanvasRenderingContext2D, color: string) {
context.fillStyle = color;
context.fillRect(0, 0, 1, 1);
@ -26,9 +24,9 @@ function drawPixelsToCanvas(pixels: Uint8Array, canvas: HTMLCanvasElement) {
if (!drawContext)
throw new Error('could not get draw context');
const rootStyle = getComputedStyle(rootElement);
const colorPrimary = normalizeColor(drawContext, rootStyle.getPropertyValue('--color-primary'));
const colorBackground = normalizeColor(drawContext, rootStyle.getPropertyValue('--color-background'));
const theme = getTheme();
const colorPrimary = normalizeColor(drawContext, theme.primary);
const colorBackground = normalizeColor(drawContext, theme.background);
const imageData = drawContext.getImageData(0, 0, canvas.width, canvas.height, {colorSpace: 'srgb'});
const data = imageData.data;