refactor: convert WebGL renderer to TypeScript

This commit is contained in:
sjg
2026-08-01 12:07:02 +02:00
parent a58553ba66
commit 9ac6d7f82c
4 changed files with 231 additions and 151 deletions
@@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>
//
// SPDX-License-Identifier: GPL-2.0-or-later
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import vm from "node:vm";
test("WebGL color helpers normalize CSS and HSL colors", async () => {
const window = {};
const context = vm.createContext({
window,
document: {
body: { appendChild() {} },
createElement: () => ({ style: {} }),
},
getComputedStyle: () => ({ color: "rgb(0, 0, 0)" }),
Map,
Math,
Number,
String,
parseInt,
});
const source = await readFile(
new URL("../../assets/web/generated/webgl-renderer.js", import.meta.url),
"utf8",
);
new vm.Script(source).runInContext(context);
assert.deepEqual(Array.from(window.trxParseCssColor("#ff800080")), [1, 128 / 255, 0, 128 / 255]);
assert.deepEqual(Array.from(window.trxHslToRgba(0, 100, 50)), [1, 0, 0, 1]);
});