@stacksjs/defaults 0.75.672 → 0.75.674
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.
- package/ai/skills/stacks-dashboard/SKILL.md +19 -5
- package/ide/vscode/package.json +1 -1
- package/package.json +7 -7
- package/resources/components/Dashboard/Home/DashboardHome.stx +8 -8
- package/resources/components/Dashboard/MobileSidebar.stx +1 -1
- package/resources/components/Dashboard/Settings/AppearanceSettingsDashboard.stx +19 -3
- package/resources/components/Dashboard/Settings/DashboardThemePicker.stx +218 -0
- package/resources/components/Dashboard/UI/ActivityTable.stx +7 -7
- package/resources/components/Dashboard/UI/Button.stx +6 -3
- package/resources/components/Dashboard/UI/Card.stx +1 -1
- package/resources/components/Dashboard/UI/Drawer.stx +1 -1
- package/resources/components/Dashboard/UI/Modal.stx +1 -0
- package/resources/components/Dashboard/UI/PageHeader.stx +1 -1
- package/resources/components/Dashboard/UI/QuickLinks.stx +7 -5
- package/resources/components/Dashboard/UI/ServiceHealth.stx +6 -6
- package/resources/components/Dashboard/UI/StatsCard.stx +5 -5
- package/resources/components/Dashboard/UI/Table.stx +1 -1
- package/styles/dashboard-theme.css +248 -0
- package/views/dashboard/composables/dashboard-theme-bootstrap.ts +11 -0
- package/views/dashboard/composables/dashboard-themes.ts +180 -0
- package/views/dashboard/composables/useAppearance.ts +21 -9
- package/views/dashboard/composables/useDashboardThemes.ts +79 -0
- package/views/dashboard/layouts/default.stx +45 -42
- package/views/dashboard/layouts/guest.stx +11 -1
|
@@ -772,7 +772,7 @@ function cellClass(column: DashboardTableColumn, index: number): string {
|
|
|
772
772
|
}
|
|
773
773
|
</script>
|
|
774
774
|
|
|
775
|
-
<div class="overflow-hidden relative bg-white dark:bg-neutral-900" :class="framed() ? 'border border-stone-200/80 rounded-xl dark:border-neutral-700 shadow-sm' : ''">
|
|
775
|
+
<div data-dashboard-table :data-dashboard-framed="String(framed())" class="overflow-hidden relative bg-white dark:bg-neutral-900" :class="framed() ? 'border border-stone-200/80 rounded-xl dark:border-neutral-700 shadow-sm' : ''">
|
|
776
776
|
<div :if="loading()" class="flex absolute inset-0 z-30 items-center justify-center bg-white/80 dark:bg-neutral-900/80 backdrop-blur-sm" role="status">
|
|
777
777
|
<span aria-hidden="true" class="mr-2 h-5 w-5 text-blue-500 animate-spin i-hugeicons-loading-03"></span>
|
|
778
778
|
<span class="text-neutral-500 text-sm dark:text-neutral-400">Loading</span>
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
html[data-dashboard-layout] {
|
|
2
|
+
color-scheme: light;
|
|
3
|
+
--dashboard-overview-gradient:
|
|
4
|
+
radial-gradient(ellipse at 85% 0%, color-mix(in srgb, var(--dashboard-hero-start) 90%, white), transparent 65%),
|
|
5
|
+
linear-gradient(155deg, var(--dashboard-hero-start), var(--dashboard-hero-end));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
html[data-dashboard-layout].dark {
|
|
9
|
+
color-scheme: dark;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
html[data-dashboard-layout] body {
|
|
13
|
+
color: var(--dashboard-text);
|
|
14
|
+
font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
html[data-dashboard-layout] [data-stx-content][data-dashboard-content],
|
|
18
|
+
html[data-dashboard-layout] body[data-dashboard-guest] {
|
|
19
|
+
background: var(--dashboard-canvas);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
html[data-dashboard-layout] [data-dashboard-mobile-bar],
|
|
23
|
+
html[data-dashboard-layout] [data-dashboard-overlay],
|
|
24
|
+
html[data-dashboard-layout] :is([data-dashboard-card="default"], [data-dashboard-card="elevated"]),
|
|
25
|
+
html[data-dashboard-layout] [data-dashboard-table] {
|
|
26
|
+
background: var(--dashboard-surface);
|
|
27
|
+
border-color: var(--dashboard-border);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
html[data-dashboard-layout] [data-dashboard-card="outline"] {
|
|
31
|
+
border-color: var(--dashboard-border);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
html[data-dashboard-layout] [data-dashboard-card="ghost"] {
|
|
35
|
+
background: var(--dashboard-surface-muted);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
html[data-dashboard-layout] [data-dashboard-card="vibrancy"] {
|
|
39
|
+
background: color-mix(in srgb, var(--dashboard-surface) 75%, transparent);
|
|
40
|
+
border-color: var(--dashboard-border);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
html[data-dashboard-layout] [data-dashboard-card],
|
|
44
|
+
html[data-dashboard-layout] [data-dashboard-framed="true"],
|
|
45
|
+
html[data-dashboard-layout] [data-dashboard-overlay="modal"] {
|
|
46
|
+
border-radius: var(--dashboard-radius);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
html[data-dashboard-layout] [data-dashboard-card] > :is(header, footer),
|
|
50
|
+
html[data-dashboard-layout] [data-dashboard-table] :is(thead, th, td) {
|
|
51
|
+
border-color: var(--dashboard-border);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
html[data-dashboard-layout] [data-dashboard-card] > footer,
|
|
55
|
+
html[data-dashboard-layout] [data-dashboard-table] thead {
|
|
56
|
+
background: var(--dashboard-surface-muted);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
html[data-dashboard-layout] [data-dashboard-ink],
|
|
60
|
+
html[data-dashboard-layout] [data-dashboard-page-heading] h1,
|
|
61
|
+
html[data-dashboard-layout] [data-dashboard-card] > header h3 {
|
|
62
|
+
color: var(--dashboard-text);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
html[data-dashboard-layout] [data-dashboard-page-heading] h1 {
|
|
66
|
+
letter-spacing: -.025em;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
html[data-dashboard-layout] [data-dashboard-muted],
|
|
70
|
+
html[data-dashboard-layout] [data-dashboard-page-heading] p,
|
|
71
|
+
html[data-dashboard-layout] [data-dashboard-card] > header p {
|
|
72
|
+
color: var(--dashboard-muted);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
html[data-dashboard-layout] [data-dashboard-button]:focus-visible,
|
|
76
|
+
html[data-dashboard-layout] [data-sidebar-item]:focus-visible {
|
|
77
|
+
outline: 2px solid var(--dashboard-accent);
|
|
78
|
+
outline-offset: 2px;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
html[data-dashboard-layout] [data-dashboard-button="primary"] {
|
|
82
|
+
color: var(--dashboard-accent-text);
|
|
83
|
+
background: linear-gradient(180deg, color-mix(in srgb, var(--dashboard-accent-fill) 94%, white), var(--dashboard-accent-fill));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
html[data-dashboard-layout] [data-dashboard-button="primary"]:hover {
|
|
87
|
+
background: var(--dashboard-accent-fill);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
html[data-dashboard-layout] [data-dashboard-button="secondary"] {
|
|
91
|
+
color: var(--dashboard-text);
|
|
92
|
+
background: var(--dashboard-surface);
|
|
93
|
+
border-color: var(--dashboard-border);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
html[data-dashboard-layout] [data-dashboard-button="secondary"]:hover {
|
|
97
|
+
background: var(--dashboard-surface-muted);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
html[data-dashboard-layout] [data-dashboard-hero] {
|
|
101
|
+
align-items: center;
|
|
102
|
+
padding: clamp(1rem, 4vw, 2rem);
|
|
103
|
+
border-radius: var(--dashboard-radius);
|
|
104
|
+
background: var(--dashboard-overview-gradient);
|
|
105
|
+
box-shadow: 0 8px 24px rgb(0 0 0 / .12);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
html[data-dashboard-layout] [data-dashboard-hero] [data-dashboard-page-heading] h1 {
|
|
109
|
+
color: var(--dashboard-hero-text);
|
|
110
|
+
font-size: clamp(1.5rem, 3vw, 2rem);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
html[data-dashboard-layout] [data-dashboard-hero] [data-dashboard-page-heading] p {
|
|
114
|
+
color: var(--dashboard-hero-text);
|
|
115
|
+
opacity: .87;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
html[data-dashboard-layout] [data-stx-sidebar] {
|
|
119
|
+
color: var(--dashboard-text);
|
|
120
|
+
background: var(--dashboard-window);
|
|
121
|
+
border-color: var(--dashboard-border);
|
|
122
|
+
-webkit-backdrop-filter: none;
|
|
123
|
+
backdrop-filter: none;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
html[data-dashboard-layout] .stx-sidebar-rim {
|
|
127
|
+
display: none;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
html[data-dashboard-layout] [data-sidebar-selection="accent"] {
|
|
131
|
+
--stx-sidebar-accent: var(--dashboard-accent-fill);
|
|
132
|
+
--stx-sidebar-on-selection: var(--dashboard-accent-text);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
html[data-dashboard-layout] [data-sidebar-item] {
|
|
136
|
+
color: inherit;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
html[data-dashboard-layout] [data-sidebar-item]:hover {
|
|
140
|
+
background-color: var(--dashboard-surface-muted);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
html[data-dashboard-layout] [data-sidebar-section-header] {
|
|
144
|
+
color: var(--dashboard-muted);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@media (min-width: 1024px) {
|
|
148
|
+
html[data-dashboard-layout="inset"]:has([data-dashboard-content]),
|
|
149
|
+
html[data-dashboard-layout="inset"]:has([data-dashboard-content]) body {
|
|
150
|
+
height: 100%;
|
|
151
|
+
overflow: hidden;
|
|
152
|
+
background: var(--dashboard-window);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
html[data-dashboard-layout="inset"] [data-stx-content][data-dashboard-content] {
|
|
156
|
+
margin-block: 8px;
|
|
157
|
+
margin-right: 8px;
|
|
158
|
+
min-height: 0;
|
|
159
|
+
height: calc(100dvh - 16px);
|
|
160
|
+
overflow-y: auto;
|
|
161
|
+
border-radius: var(--dashboard-radius);
|
|
162
|
+
box-shadow: 0 0 0 .5px var(--dashboard-border), 0 10px 40px rgb(0 0 0 / .14);
|
|
163
|
+
scrollbar-width: thin;
|
|
164
|
+
scrollbar-color: var(--dashboard-border) transparent;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
html[data-dashboard-navigation="tiles"] [data-sidebar-item] {
|
|
169
|
+
min-height: 34px;
|
|
170
|
+
margin-inline: 3px;
|
|
171
|
+
width: calc(100% - 6px);
|
|
172
|
+
border-radius: 8px;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
html[data-dashboard-navigation="tiles"] [data-sidebar-selection][data-window-key] [data-sidebar-item][data-active="true"],
|
|
176
|
+
html[data-dashboard-navigation="tiles"] [data-sidebar-selection][data-window-key] [data-sidebar-item][data-active="true"]:hover {
|
|
177
|
+
background: color-mix(in srgb, var(--dashboard-accent) 17%, var(--dashboard-window));
|
|
178
|
+
color: var(--dashboard-text);
|
|
179
|
+
font-weight: 600;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
html[data-dashboard-navigation="tiles"] [data-sidebar-selection][data-window-key="false"] [data-sidebar-item][data-active="true"] {
|
|
183
|
+
background: var(--dashboard-surface-muted);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
html[data-dashboard-navigation="tiles"] [data-sidebar-item] span:has(> [data-sidebar-icon]) {
|
|
187
|
+
display: grid;
|
|
188
|
+
place-items: center;
|
|
189
|
+
flex: 0 0 24px;
|
|
190
|
+
width: 24px;
|
|
191
|
+
height: 24px;
|
|
192
|
+
border-radius: 7px;
|
|
193
|
+
background: linear-gradient(160deg, color-mix(in srgb, var(--dashboard-tile, var(--dashboard-accent-fill)) 75%, white), var(--dashboard-tile, var(--dashboard-accent-fill)));
|
|
194
|
+
box-shadow: inset 0 1px 0 rgb(255 255 255 / .28), 0 1px 3px rgb(0 0 0 / .22);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
html[data-dashboard-navigation="tiles"] [data-sidebar-selection][data-window-key] [data-sidebar-item] [data-sidebar-icon] {
|
|
198
|
+
width: 14px;
|
|
199
|
+
height: 14px;
|
|
200
|
+
color: white;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
html[data-dashboard-navigation="tiles"] [data-sidebar-selection][data-window-key] [data-sidebar-item][data-active="true"] :is([data-sidebar-count], [data-sidebar-chevron]) {
|
|
204
|
+
color: var(--dashboard-muted);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
html[data-dashboard-theme="system-cleaner"] [data-section-id="library"] { --dashboard-tile: #2863bb; }
|
|
208
|
+
html[data-dashboard-theme="system-cleaner"] [data-section-id="app"] { --dashboard-tile: #b64a27; }
|
|
209
|
+
html[data-dashboard-theme="system-cleaner"] [data-section-id="data"] { --dashboard-tile: #126a83; }
|
|
210
|
+
html[data-dashboard-theme="system-cleaner"] [data-section-id="content"] { --dashboard-tile: #18794b; }
|
|
211
|
+
html[data-dashboard-theme="system-cleaner"] [data-section-id="commerce"] { --dashboard-tile: #2863bb; }
|
|
212
|
+
html[data-dashboard-theme="system-cleaner"] [data-section-id="analytics"] { --dashboard-tile: #b64a27; }
|
|
213
|
+
html[data-dashboard-theme="system-cleaner"] [data-section-id="marketing"] { --dashboard-tile: #a12d79; }
|
|
214
|
+
html[data-dashboard-theme="system-cleaner"] [data-section-id="management"] { --dashboard-tile: #4d579f; }
|
|
215
|
+
|
|
216
|
+
html[data-dashboard-overview="immersive"]:has([data-dashboard-overview-page]) body {
|
|
217
|
+
background: var(--dashboard-overview-gradient) fixed;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
html[data-dashboard-overview="immersive"]:has([data-dashboard-overview-page]) :is([data-dashboard-content], [data-dashboard-web-sidebar], [data-dashboard-mobile-bar]) {
|
|
221
|
+
--dashboard-canvas: transparent;
|
|
222
|
+
--dashboard-window: transparent;
|
|
223
|
+
--dashboard-text: var(--dashboard-hero-text);
|
|
224
|
+
--dashboard-muted: color-mix(in srgb, var(--dashboard-hero-text) 82%, transparent);
|
|
225
|
+
--dashboard-surface: color-mix(in srgb, var(--dashboard-hero-text) 9%, transparent);
|
|
226
|
+
--dashboard-surface-muted: color-mix(in srgb, var(--dashboard-hero-text) 16%, transparent);
|
|
227
|
+
--dashboard-border: color-mix(in srgb, var(--dashboard-hero-text) 24%, transparent);
|
|
228
|
+
--dashboard-accent: var(--dashboard-hero-text);
|
|
229
|
+
color: var(--dashboard-text);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
html[data-dashboard-overview="immersive"] [data-dashboard-content]:has([data-dashboard-overview-page]),
|
|
233
|
+
html[data-dashboard-overview="immersive"] [data-dashboard-hero] {
|
|
234
|
+
box-shadow: none;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
html[data-dashboard-overview="immersive"] [data-dashboard-hero] {
|
|
238
|
+
background: transparent;
|
|
239
|
+
padding-inline: 0;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
html[data-dashboard-overview="immersive"]:has([data-dashboard-overview-page]) [data-dashboard-mobile-bar] > :is(button, span) {
|
|
243
|
+
color: inherit;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
html[data-dashboard-overview="immersive"] [data-dashboard-overview-page] [data-dashboard-button="secondary"] {
|
|
247
|
+
border-radius: 999px;
|
|
248
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { applyDashboardTheme, readDashboardThemes, resolveDashboardTheme } from './dashboard-themes'
|
|
2
|
+
|
|
3
|
+
const root = document.documentElement
|
|
4
|
+
try {
|
|
5
|
+
const { active, installed } = readDashboardThemes(window.localStorage)
|
|
6
|
+
applyDashboardTheme(root, resolveDashboardTheme(active, installed))
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
// The browser can refuse access to localStorage itself.
|
|
10
|
+
applyDashboardTheme(root)
|
|
11
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
export const DASHBOARD_THEME_STORAGE_KEY = 'stacks-dashboard-themes'
|
|
2
|
+
export const ORIGINAL_DASHBOARD_THEME = 'original'
|
|
3
|
+
export const MAX_THEME_FILE_SIZE = 16_384
|
|
4
|
+
const MAX_INSTALLED_THEMES = 24
|
|
5
|
+
|
|
6
|
+
const paletteKeys = [
|
|
7
|
+
'window', 'canvas', 'surface', 'surfaceMuted', 'text', 'muted', 'border',
|
|
8
|
+
'accent', 'accentFill', 'accentText', 'heroStart', 'heroEnd', 'heroText',
|
|
9
|
+
] as const
|
|
10
|
+
|
|
11
|
+
type ThemePalette = Record<typeof paletteKeys[number], string>
|
|
12
|
+
|
|
13
|
+
export interface DashboardTheme {
|
|
14
|
+
version: 1
|
|
15
|
+
id: string
|
|
16
|
+
name: string
|
|
17
|
+
description?: string
|
|
18
|
+
layout: 'flush' | 'inset'
|
|
19
|
+
navigation: 'plain' | 'tiles'
|
|
20
|
+
overview: 'panel' | 'immersive'
|
|
21
|
+
radius: number
|
|
22
|
+
light: ThemePalette
|
|
23
|
+
dark: ThemePalette
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface DashboardThemePreferences {
|
|
27
|
+
active: string
|
|
28
|
+
installed: DashboardTheme[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const SYSTEM_CLEANER_THEME: DashboardTheme = {
|
|
32
|
+
version: 1,
|
|
33
|
+
id: 'system-cleaner',
|
|
34
|
+
name: 'System Cleaner',
|
|
35
|
+
description: 'A macOS-style window with colored navigation tiles and a violet overview.',
|
|
36
|
+
layout: 'inset',
|
|
37
|
+
navigation: 'tiles',
|
|
38
|
+
overview: 'immersive',
|
|
39
|
+
radius: 14,
|
|
40
|
+
light: {
|
|
41
|
+
window: '#e7e7ec',
|
|
42
|
+
canvas: '#f5f5f7',
|
|
43
|
+
surface: '#ffffff',
|
|
44
|
+
surfaceMuted: '#eeeef1',
|
|
45
|
+
text: '#1d1d1f',
|
|
46
|
+
muted: '#55555b',
|
|
47
|
+
border: '#d9d9e0',
|
|
48
|
+
accent: '#692bc7',
|
|
49
|
+
accentFill: '#6d28d9',
|
|
50
|
+
accentText: '#ffffff',
|
|
51
|
+
heroStart: '#6a2fb8',
|
|
52
|
+
heroEnd: '#27114e',
|
|
53
|
+
heroText: '#ffffff',
|
|
54
|
+
},
|
|
55
|
+
dark: {
|
|
56
|
+
window: '#111113',
|
|
57
|
+
canvas: '#1a1a1c',
|
|
58
|
+
surface: '#242426',
|
|
59
|
+
surfaceMuted: '#2c2c2e',
|
|
60
|
+
text: '#f5f5f7',
|
|
61
|
+
muted: '#b8b8bf',
|
|
62
|
+
border: '#3b3b42',
|
|
63
|
+
accent: '#c48bff',
|
|
64
|
+
accentFill: '#7a2fe0',
|
|
65
|
+
accentText: '#ffffff',
|
|
66
|
+
heroStart: '#542593',
|
|
67
|
+
heroEnd: '#200d3b',
|
|
68
|
+
heroText: '#ffffff',
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const BUNDLED_DASHBOARD_THEMES: readonly DashboardTheme[] = [SYSTEM_CLEANER_THEME]
|
|
73
|
+
|
|
74
|
+
function record(value: unknown): Record<string, unknown> {
|
|
75
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : {}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function readPalette(value: unknown, mode: string): ThemePalette {
|
|
79
|
+
const input = record(value)
|
|
80
|
+
const palette = {} as ThemePalette
|
|
81
|
+
for (const key of paletteKeys) {
|
|
82
|
+
const color = input[key]
|
|
83
|
+
if (typeof color !== 'string' || color.length !== 7 || !/^#[\da-f]{6}$/i.test(color))
|
|
84
|
+
throw new Error(`Use a six-digit hex color for ${mode}.${key}.`)
|
|
85
|
+
palette[key] = color.toLowerCase()
|
|
86
|
+
}
|
|
87
|
+
return palette
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function parseDashboardTheme(value: unknown): DashboardTheme {
|
|
91
|
+
const { version, id, name, description, layout, navigation, overview = 'panel', radius, light, dark } = record(value)
|
|
92
|
+
if (version !== 1)
|
|
93
|
+
throw new Error('Set the theme version to 1.')
|
|
94
|
+
if (typeof id !== 'string' || id !== id.trim() || !/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(id) || id.length > 48)
|
|
95
|
+
throw new Error('Use a theme ID of up to 48 lowercase letters, digits, and hyphens. Start with a letter.')
|
|
96
|
+
if (id === ORIGINAL_DASHBOARD_THEME || BUNDLED_DASHBOARD_THEMES.some(theme => theme.id === id))
|
|
97
|
+
throw new Error('Choose a new ID. That ID belongs to a bundled theme.')
|
|
98
|
+
if (typeof name !== 'string' || !name.trim() || name.length > 64)
|
|
99
|
+
throw new Error('Enter a theme name of up to 64 characters.')
|
|
100
|
+
if (description !== undefined && (typeof description !== 'string' || description.length > 180))
|
|
101
|
+
throw new Error('Keep the description to 180 characters or fewer.')
|
|
102
|
+
if (layout !== 'flush' && layout !== 'inset')
|
|
103
|
+
throw new Error('Choose either flush or inset for layout.')
|
|
104
|
+
if (navigation !== 'plain' && navigation !== 'tiles')
|
|
105
|
+
throw new Error('Choose either plain or tiles for navigation.')
|
|
106
|
+
if (overview !== 'panel' && overview !== 'immersive')
|
|
107
|
+
throw new Error('Choose either panel or immersive for overview.')
|
|
108
|
+
if (typeof radius !== 'number' || !Number.isInteger(radius) || radius < 0 || radius > 24)
|
|
109
|
+
throw new Error('Set the radius to a whole number from 0 to 24.')
|
|
110
|
+
return { version, id, name: name.trim(), description: description?.trim(), layout, navigation, overview, radius, light: readPalette(light, 'light'), dark: readPalette(dark, 'dark') }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function resolveDashboardTheme(id: unknown, installed: readonly DashboardTheme[]): DashboardTheme | undefined {
|
|
114
|
+
return BUNDLED_DASHBOARD_THEMES.find(theme => theme.id === id) ?? installed.find(theme => theme.id === id)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function readDashboardThemes(storage: Pick<Storage, 'getItem'>): DashboardThemePreferences {
|
|
118
|
+
const installed = new Map<string, DashboardTheme>()
|
|
119
|
+
try {
|
|
120
|
+
const saved = record(JSON.parse(storage.getItem(DASHBOARD_THEME_STORAGE_KEY) || '{}'))
|
|
121
|
+
if (Array.isArray(saved.installed)) {
|
|
122
|
+
for (const input of saved.installed.slice(0, MAX_INSTALLED_THEMES)) {
|
|
123
|
+
try {
|
|
124
|
+
const theme = parseDashboardTheme(input)
|
|
125
|
+
installed.set(theme.id, theme)
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// An outdated or damaged installation should not hide valid themes.
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const themes = [...installed.values()]
|
|
133
|
+
return { active: resolveDashboardTheme(saved.active, themes)?.id ?? ORIGINAL_DASHBOARD_THEME, installed: themes }
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return { active: ORIGINAL_DASHBOARD_THEME, installed: [] }
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function installDashboardTheme(prefs: DashboardThemePreferences, theme: DashboardTheme): DashboardThemePreferences {
|
|
141
|
+
const index = prefs.installed.findIndex(installed => installed.id === theme.id)
|
|
142
|
+
const installed = [...prefs.installed]
|
|
143
|
+
if (index === -1) {
|
|
144
|
+
if (installed.length >= MAX_INSTALLED_THEMES)
|
|
145
|
+
throw new Error(`Remove an installed theme first. This browser can store ${MAX_INSTALLED_THEMES} themes.`)
|
|
146
|
+
installed.push(theme)
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
installed[index] = theme
|
|
150
|
+
}
|
|
151
|
+
return { active: theme.id, installed }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function colorProperty(key: string): string {
|
|
155
|
+
return `--dashboard-${key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)}`
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function dashboardThemeColor(theme: DashboardTheme, key: keyof ThemePalette): string {
|
|
159
|
+
return `light-dark(${theme.light[key]}, ${theme.dark[key]})`
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function applyDashboardTheme(root: HTMLElement, theme?: DashboardTheme): void {
|
|
163
|
+
root.dataset.dashboardTheme = theme?.id ?? ORIGINAL_DASHBOARD_THEME
|
|
164
|
+
if (theme) {
|
|
165
|
+
root.dataset.dashboardLayout = theme.layout
|
|
166
|
+
root.dataset.dashboardNavigation = theme.navigation
|
|
167
|
+
root.dataset.dashboardOverview = theme.overview
|
|
168
|
+
root.style.setProperty('--dashboard-radius', `${theme.radius}px`)
|
|
169
|
+
for (const key of paletteKeys)
|
|
170
|
+
root.style.setProperty(colorProperty(key), dashboardThemeColor(theme, key))
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
delete root.dataset.dashboardLayout
|
|
174
|
+
delete root.dataset.dashboardNavigation
|
|
175
|
+
delete root.dataset.dashboardOverview
|
|
176
|
+
root.style.removeProperty('--dashboard-radius')
|
|
177
|
+
for (const key of paletteKeys)
|
|
178
|
+
root.style.removeProperty(colorProperty(key))
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -189,9 +189,10 @@ export function sidebarThemeFor(style: SidebarStyle, knownThemes: Record<string,
|
|
|
189
189
|
* under `APPEARANCE_STORAGE_KEY`.
|
|
190
190
|
*/
|
|
191
191
|
export const appearanceStore = defineStore('appearance', () => {
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
const
|
|
192
|
+
const saved = readStoredAppearance()
|
|
193
|
+
const sidebarStyle = state(saved.sidebarStyle)
|
|
194
|
+
const colorMode = state(saved.colorMode)
|
|
195
|
+
const hiddenSections = state(saved.hiddenSections)
|
|
195
196
|
|
|
196
197
|
function snapshot(): AppearancePreferences {
|
|
197
198
|
return {
|
|
@@ -201,6 +202,19 @@ export const appearanceStore = defineStore('appearance', () => {
|
|
|
201
202
|
}
|
|
202
203
|
}
|
|
203
204
|
|
|
205
|
+
function persist(): void {
|
|
206
|
+
if (typeof window === 'undefined')
|
|
207
|
+
return
|
|
208
|
+
try {
|
|
209
|
+
// Save during the interaction so an immediate navigation sees the new
|
|
210
|
+
// value in the synchronous appearance bootstrap.
|
|
211
|
+
window.localStorage.setItem(APPEARANCE_STORAGE_KEY, JSON.stringify(snapshot()))
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
// The appearance still works in this document if storage is disabled.
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
204
218
|
/**
|
|
205
219
|
* Write the preferences onto `<html>`, where the shell CSS reads them.
|
|
206
220
|
*
|
|
@@ -238,6 +252,7 @@ export const appearanceStore = defineStore('appearance', () => {
|
|
|
238
252
|
if (!isSidebarStyle(style))
|
|
239
253
|
return
|
|
240
254
|
sidebarStyle.set(style)
|
|
255
|
+
persist()
|
|
241
256
|
apply()
|
|
242
257
|
}
|
|
243
258
|
|
|
@@ -245,6 +260,7 @@ export const appearanceStore = defineStore('appearance', () => {
|
|
|
245
260
|
if (!isColorMode(mode))
|
|
246
261
|
return
|
|
247
262
|
colorMode.set(mode)
|
|
263
|
+
persist()
|
|
248
264
|
apply()
|
|
249
265
|
}
|
|
250
266
|
|
|
@@ -253,6 +269,7 @@ export const appearanceStore = defineStore('appearance', () => {
|
|
|
253
269
|
if (!visible)
|
|
254
270
|
next.push(id)
|
|
255
271
|
hiddenSections.set(next)
|
|
272
|
+
persist()
|
|
256
273
|
}
|
|
257
274
|
|
|
258
275
|
function isSectionHidden(id: string): boolean {
|
|
@@ -263,6 +280,7 @@ export const appearanceStore = defineStore('appearance', () => {
|
|
|
263
280
|
sidebarStyle.set(DEFAULT_APPEARANCE.sidebarStyle)
|
|
264
281
|
colorMode.set(DEFAULT_APPEARANCE.colorMode)
|
|
265
282
|
hiddenSections.set([])
|
|
283
|
+
persist()
|
|
266
284
|
apply()
|
|
267
285
|
}
|
|
268
286
|
|
|
@@ -277,12 +295,6 @@ export const appearanceStore = defineStore('appearance', () => {
|
|
|
277
295
|
reset,
|
|
278
296
|
apply,
|
|
279
297
|
}
|
|
280
|
-
}, {
|
|
281
|
-
persist: {
|
|
282
|
-
storage: 'localStorage',
|
|
283
|
-
key: APPEARANCE_STORAGE_KEY,
|
|
284
|
-
pick: ['sidebarStyle', 'colorMode', 'hiddenSections'],
|
|
285
|
-
},
|
|
286
298
|
})
|
|
287
299
|
|
|
288
300
|
/*
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { DashboardThemePreferences } from './dashboard-themes'
|
|
2
|
+
import { defineStore, derived, state } from '@stacksjs/stx'
|
|
3
|
+
import {
|
|
4
|
+
applyDashboardTheme,
|
|
5
|
+
DASHBOARD_THEME_STORAGE_KEY,
|
|
6
|
+
installDashboardTheme,
|
|
7
|
+
ORIGINAL_DASHBOARD_THEME,
|
|
8
|
+
parseDashboardTheme,
|
|
9
|
+
readDashboardThemes,
|
|
10
|
+
resolveDashboardTheme,
|
|
11
|
+
} from './dashboard-themes'
|
|
12
|
+
|
|
13
|
+
function read(): DashboardThemePreferences {
|
|
14
|
+
try {
|
|
15
|
+
if (typeof window !== 'undefined')
|
|
16
|
+
return readDashboardThemes(window.localStorage)
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Storage access can be disabled by the browser.
|
|
20
|
+
}
|
|
21
|
+
return { active: ORIGINAL_DASHBOARD_THEME, installed: [] }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const dashboardThemeStore = defineStore('dashboard-themes', () => {
|
|
25
|
+
const preferences = state(read())
|
|
26
|
+
const active = derived(() => preferences().active)
|
|
27
|
+
const installed = derived(() => preferences().installed)
|
|
28
|
+
|
|
29
|
+
function apply(next: DashboardThemePreferences): void {
|
|
30
|
+
preferences.set(next)
|
|
31
|
+
if (typeof document !== 'undefined')
|
|
32
|
+
applyDashboardTheme(document.documentElement, resolveDashboardTheme(next.active, next.installed))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (typeof window !== 'undefined') {
|
|
36
|
+
window.addEventListener('storage', (event) => {
|
|
37
|
+
if (event.key === DASHBOARD_THEME_STORAGE_KEY || event.key === null)
|
|
38
|
+
apply(read())
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function save(next: DashboardThemePreferences): void {
|
|
43
|
+
try {
|
|
44
|
+
window.localStorage.setItem(DASHBOARD_THEME_STORAGE_KEY, JSON.stringify(next))
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new Error('The browser could not save your dashboard themes.')
|
|
48
|
+
}
|
|
49
|
+
apply(next)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function select(id: string): void {
|
|
53
|
+
const current = read()
|
|
54
|
+
if (id === ORIGINAL_DASHBOARD_THEME || resolveDashboardTheme(id, current.installed))
|
|
55
|
+
save({ ...current, active: id })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function install(value: unknown): string {
|
|
59
|
+
const theme = parseDashboardTheme(value)
|
|
60
|
+
save(installDashboardTheme(read(), theme))
|
|
61
|
+
return theme.name
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function remove(id: string): void {
|
|
65
|
+
const current = read()
|
|
66
|
+
if (!current.installed.some(theme => theme.id === id))
|
|
67
|
+
return
|
|
68
|
+
save({
|
|
69
|
+
active: current.active === id ? ORIGINAL_DASHBOARD_THEME : current.active,
|
|
70
|
+
installed: current.installed.filter(theme => theme.id !== id),
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return { active, installed, select, install, remove, sync: () => apply(read()) }
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
export function useDashboardThemes(): typeof dashboardThemeStore {
|
|
78
|
+
return dashboardThemeStore
|
|
79
|
+
}
|