Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

mobileTheme.test-support.ts

20 lines748 Bytes

1import * as NodeFS from "node:fs";
2​
3import type { MobileThemeAppearance, MobileThemeVariables } from "./mobileTheme";
4​
5export function readDefaultMobileThemeVariables(
6 appearance: MobileThemeAppearance,
7): MobileThemeVariables {
8 const stylesheet = NodeFS.readFileSync(new URL("../../global.css", import.meta.url), "utf8");
9 const variant = new RegExp(`@variant ${appearance} \\{([\\s\\S]*?)\\n \\}`, "u").exec(
10 stylesheet,
11 )?.[1];
12 if (variant === undefined) throw new Error(`Missing default ${appearance} theme in global.css.`);
13​
14 return Object.fromEntries(
15 Array.from(variant.matchAll(/(--color-[a-z0-9-]+):\s*([^;]+);/gu), ([, name, value]) => [
16 name,
17 (value ?? "").trim(),
18 ]),
19 ) as MobileThemeVariables;