move theme code to own file
This commit is contained in:
parent
44b66c37fc
commit
52e09ae5ef
1 changed files with 50 additions and 21 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Reference in a new issue