The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as NodeFS from "node:fs"; |
| 2 | |
| 3 | import { |
| 4 | createMobileThemeVariables, |
| 5 | type MobileThemeVariable, |
| 6 | type MobileThemeAppearance, |
| 7 | type MobileThemeVariables, |
| 8 | } from "./mobileTheme"; |
| 9 | |
| 10 | import { T3_CHAT_THEME } from "@t3tools/shared/themePalettes"; |
| 11 | |
| 12 | const MOBILE_THEME_VARIABLE_NAMES = Object.keys( |
| 13 | createMobileThemeVariables(T3_CHAT_THEME.colors, "light"), |
| 14 | ) as ReadonlyArray<MobileThemeVariable>; |
| 15 | |
| 16 | export function readDefaultMobileThemeVariables( |
| 17 | appearance: MobileThemeAppearance, |
| 18 | ): MobileThemeVariables { |
| 19 | return readGeneratedMobileThemeVariables(appearance); |
| 20 | } |
| 21 | |
| 22 | export function readGeneratedMobileThemeVariables(themeName: string): MobileThemeVariables { |
| 23 | const stylesheet = NodeFS.readFileSync( |
| 24 | new URL("../../generated-uniwind-themes.css", import.meta.url), |
| 25 | "utf8", |
| 26 | ); |
| 27 | const variant = new RegExp(`@variant ${themeName} \\{([\\s\\S]*?)\\n \\}`, "u").exec( |
| 28 | stylesheet, |
| 29 | )?.[1]; |
| 30 | if (variant === undefined) throw new Error(`Missing generated ${themeName} theme.`); |
| 31 | |
| 32 | return Object.fromEntries( |
| 33 | Array.from(variant.matchAll(/(--color-[a-z0-9-]+):\s*([^;]+);/gu), ([, name, value]) => [ |
| 34 | name, |
| 35 | (value ?? "").trim(), |
| 36 | ]).filter(([name]) => |
| 37 | MOBILE_THEME_VARIABLE_NAMES.includes(name as (typeof MOBILE_THEME_VARIABLE_NAMES)[number]), |
| 38 | ), |
| 39 | ) as MobileThemeVariables; |
| 40 | } |