commit a16f175460b50ecfcfd2a519cbbe62413e5dbe52
parent 55c3783474b16b5adfa126654063054792d228dc
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Mon, 26 Aug 2024 08:17:58 +0000
themes: add theme and color mode utils
Diffstat:
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/themes/src/utils.ts b/themes/src/utils.ts
@@ -1,4 +1,4 @@
-import type { HslTuple, ThemeDaisy, ThemeLayers } from "./types";
+import type { ColorMode, HslTuple, ThemeDaisy, ThemeKey, ThemeLayers } from "./types";
export const hsl = (c: HslTuple): string => `${c[0]}deg ${c[1]}% ${c[2]}%`;
@@ -12,7 +12,26 @@ export const write_daisy = (obj_c: ThemeDaisy): Record<string, string> => Object
Object.entries(obj_c).map(([key, val]) => [key, hsl_css(val)])
);
-export const write_layers = ({ layer_0: { surface: l0_s, glyphs: l0_g }, layer_1: { surface: l1_s, glyphs: l1_g }, layer_2: { surface: l2_s, glyphs: l2_g }}: ThemeLayers): Record<string, string> => ({
+export const parse_theme_key = (key?: string): ThemeKey => {
+ switch (key) {
+ case "os":
+ return key;
+ default:
+ return "os";
+ };
+};
+
+export const parse_color_mode = (color_mode?: string): ColorMode => {
+ switch (color_mode) {
+ case "light":
+ case "dark":
+ return color_mode;
+ default:
+ return "light";
+ };
+};
+
+export const write_layers = ({ layer_0: { surface: l0_s, glyphs: l0_g }, layer_1: { surface: l1_s, glyphs: l1_g }, layer_2: { surface: l2_s, glyphs: l2_g } }: ThemeLayers): Record<string, string> => ({
"--layer-0-surface": hsl(l0_s._),
"--layer-0-surface_a": hsl(l0_s._a),
"--layer-0-surface-edge": hsl(l0_s.edge),