uncial 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ <script lang="ts">
2
+ import SunIcon from 'phosphor-svelte/lib/SunIcon';
3
+ import MoonIcon from 'phosphor-svelte/lib/MoonIcon';
4
+ import MonitorIcon from 'phosphor-svelte/lib/MonitorIcon';
5
+ import { theme } from './theme.svelte.js';
6
+
7
+ $effect(() => {
8
+ theme.init();
9
+ });
10
+
11
+ const labels: Record<typeof theme.mode, string> = {
12
+ system: 'System theme (auto)',
13
+ light: 'Light theme',
14
+ dark: 'Dark theme',
15
+ };
16
+ </script>
17
+
18
+ <button
19
+ type="button"
20
+ class="btn btn-ghost btn-sm btn-square"
21
+ onclick={() => theme.cycle()}
22
+ aria-label={labels[theme.mode]}
23
+ title={labels[theme.mode]}
24
+ >
25
+ {#if theme.mode === 'light'}
26
+ <SunIcon size={18} weight="bold" />
27
+ {:else if theme.mode === 'dark'}
28
+ <MoonIcon size={18} weight="bold" />
29
+ {:else}
30
+ <MonitorIcon size={18} weight="bold" />
31
+ {/if}
32
+ </button>
@@ -0,0 +1,3 @@
1
+ declare const ThemeSwitcher: import("svelte").Component<Record<string, never>, {}, "">;
2
+ type ThemeSwitcher = ReturnType<typeof ThemeSwitcher>;
3
+ export default ThemeSwitcher;
@@ -0,0 +1,8 @@
1
+ type ThemeMode = 'system' | 'light' | 'dark';
2
+ export declare const theme: {
3
+ readonly mode: ThemeMode;
4
+ apply: () => void;
5
+ cycle: () => void;
6
+ init: () => void;
7
+ };
8
+ export {};
@@ -0,0 +1,56 @@
1
+ const STORAGE_KEY = 'uncial-theme';
2
+ function createThemeState() {
3
+ let mode = $state('system');
4
+ function load() {
5
+ if (typeof window === 'undefined')
6
+ return 'system';
7
+ const stored = localStorage.getItem(STORAGE_KEY);
8
+ if (stored === 'light' || stored === 'dark' || stored === 'system')
9
+ return stored;
10
+ return 'system';
11
+ }
12
+ function apply() {
13
+ if (typeof document === 'undefined')
14
+ return;
15
+ const root = document.documentElement;
16
+ if (mode === 'light') {
17
+ root.dataset.theme = 'vellum';
18
+ }
19
+ else if (mode === 'dark') {
20
+ root.dataset.theme = 'vellum-dark';
21
+ }
22
+ else {
23
+ delete root.dataset.theme;
24
+ }
25
+ }
26
+ function save() {
27
+ if (typeof localStorage === 'undefined')
28
+ return;
29
+ localStorage.setItem(STORAGE_KEY, mode);
30
+ }
31
+ function cycle() {
32
+ if (mode === 'system')
33
+ mode = 'light';
34
+ else if (mode === 'light')
35
+ mode = 'dark';
36
+ else
37
+ mode = 'system';
38
+ apply();
39
+ save();
40
+ }
41
+ function init() {
42
+ if (typeof window === 'undefined')
43
+ return;
44
+ mode = load();
45
+ apply();
46
+ }
47
+ return {
48
+ get mode() {
49
+ return mode;
50
+ },
51
+ apply,
52
+ cycle,
53
+ init,
54
+ };
55
+ }
56
+ export const theme = createThemeState();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uncial",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "packageManager": "bun@1.3.10",
5
5
  "license": "MIT",
6
6
  "repository": {