Commit 18dadc7435

18dadc74352ac1d942379c0d4740a346f19269d2

parent: 41de9c2074

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-11-03 15:40 UTC

b

Layout: unified · split

docs/.vitepress/theme/components/themerepo/ThemeFilterMenu.vue added +273
@@ -0,0 +1,273 @@
1<script setup lang="ts">
2import { NuInputHighlight, NuInputHorizontalRadioGroup } from '@nolebase/ui'
3import { computed, nextTick, onMounted, onUnmounted, ref } from 'vue'
4import MenuHelp from '../settings/MenuHelp.vue'
5import MenuTitle from '../settings/MenuTitle.vue'
6
7const props = defineProps<{ modelValue: boolean; bigSwatches?: boolean }>()
8const emit = defineEmits<{
9 'update:modelValue': [value: boolean]
10 'update:big-swatches': [value: boolean]
11}>()
12
13const rootRef = ref<HTMLElement>()
14const btnRef = ref<HTMLElement>()
15const menuRef = ref<HTMLElement>()
16const open = ref(false)
17const menuStyle = ref<Record<string, string>>({})
18let raf = 0
19
20function updatePosition() {
21 if (!btnRef.value) return
22 const viewportMargin = 12
23 const menuWidth = menuRef.value?.offsetWidth ?? 260
24 const btnRect = btnRef.value.getBoundingClientRect()
25 const maxLeft = Math.max(
26 viewportMargin,
27 window.innerWidth - viewportMargin - menuWidth
28 )
29 const left = Math.min(
30 Math.max(btnRect.right - menuWidth, viewportMargin),
31 maxLeft
32 )
33 const maxTop = Math.max(viewportMargin, window.innerHeight - viewportMargin)
34 const top = Math.min(btnRect.bottom + 6, maxTop)
35 menuStyle.value = { top: `${top}px`, left: `${left}px` }
36}
37
38function toggle() {
39 open.value = !open.value
40 if (open.value) void nextTick(updatePosition)
41}
42
43function onDocClick(e: MouseEvent) {
44 const target = e.target as Node
45 if (
46 rootRef.value && !rootRef.value.contains(target) &&
47 menuRef.value && !menuRef.value.contains(target)
48 ) {
49 open.value = false
50 }
51}
52
53function onReposition() {
54 if (!open.value || raf) return
55 raf = requestAnimationFrame(() => {
56 raf = 0
57 updatePosition()
58 })
59}
60
61onMounted(() => {
62 document.addEventListener('click', onDocClick, true)
63 window.addEventListener('resize', onReposition, { passive: true })
64 window.addEventListener('scroll', onReposition, {
65 capture: true,
66 passive: true
67 })
68})
69
70onUnmounted(() => {
71 document.removeEventListener('click', onDocClick, true)
72 window.removeEventListener('resize', onReposition)
73 window.removeEventListener('scroll', onReposition, true)
74 if (raf) cancelAnimationFrame(raf)
75})
76
77const menuTitleElementRef = ref<HTMLDivElement>()
78const isMenuHelpPoppedUp = ref(false)
79const bigMenuTitleElementRef = ref<HTMLDivElement>()
80const isBigMenuHelpPoppedUp = ref(false)
81
82const options = [
83 {
84 value: 'main',
85 title: 'Main',
86 ariaLabel: 'Main colors only',
87 text: 'MAIN',
88 name: 'Swatches'
89 },
90 {
91 value: 'all',
92 title: 'All',
93 ariaLabel: 'All colors',
94 text: 'ALL',
95 name: 'Swatches'
96 }
97]
98
99const bigOptions = [
100 {
101 value: 'on',
102 title: 'On',
103 ariaLabel: 'Big swatches on',
104 text: 'ON',
105 name: 'BigSwatches'
106 },
107 {
108 value: 'off',
109 title: 'Off',
110 ariaLabel: 'Big swatches off',
111 text: 'OFF',
112 name: 'BigSwatches'
113 }
114]
115
116const swatchMode = computed({
117 get: () => props.modelValue ? 'main' : 'all',
118 set: (value: string) => emit('update:modelValue', value === 'main')
119})
120
121const bigMode = computed({
122 get: () => props.bigSwatches ? 'on' : 'off',
123 set: (value: string) => emit('update:big-swatches', value === 'on')
124})
125</script>
126
127<template>
128 <div ref="rootRef" class="theme-settings">
129 <button
130 ref="btnRef"
131 type="button"
132 class="theme-settings-btn"
133 aria-haspopup="true"
134 :aria-expanded="open"
135 aria-label="Filters"
136 @click="toggle"
137 >
138 <span class="i-lucide:settings" />
139 </button>
140
141 <Teleport to="body">
142 <div
143 v-show="open"
144 ref="menuRef"
145 class="theme-settings-menu VPMenu"
146 :style="menuStyle"
147 >
148 <div class="theme-filter" role="radiogroup">
149 <div ref="menuTitleElementRef" relative flex items-center mb-2>
150 <MenuTitle
151 title="Swatches"
152 aria-label="Swatches"
153 flex="1"
154 pr-4
155 >
156 <template #icon>
157 <span i-lucide:palette mr-1 aria-hidden="true" />
158 </template>
159 </MenuTitle>
160 <MenuHelp
161 v-model:is-popped-up="isMenuHelpPoppedUp"
162 :menu-title-element-ref="menuTitleElementRef"
163 >
164 <h4 text-md mb-1 font-semibold>Swatches</h4>
165 <p text="sm" mb-2 max-w-100>
166 Show main colors or all the colors
167 </p>
168 </MenuHelp>
169 </div>
170 <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md">
171 <NuInputHorizontalRadioGroup
172 v-model="swatchMode"
173 bg="$vp-nolebase-enhanced-readabilities-menu-background-color"
174 text="sm $vp-nolebase-enhanced-readabilities-menu-text-color"
175 :options="options"
176 />
177 </NuInputHighlight>
178 </div>
179 <div class="theme-filter" role="radiogroup">
180 <div ref="bigMenuTitleElementRef" relative flex items-center mb-2>
181 <MenuTitle
182 title="Big swatches"
183 aria-label="Big swatches"
184 flex="1"
185 pr-4
186 >
187 <template #icon>
188 <span i-lucide:layout-grid mr-1 aria-hidden="true" />
189 </template>
190 </MenuTitle>
191 <MenuHelp
192 v-model:is-popped-up="isBigMenuHelpPoppedUp"
193 :menu-title-element-ref="bigMenuTitleElementRef"
194 >
195 <h4 text-md mb-1 font-semibold>Big swatches</h4>
196 <p text="sm" mb-2 max-w-100>
197 Shows each color as a larger tile with its hex value underneath.
198 </p>
199 </MenuHelp>
200 </div>
201 <NuInputHighlight :active="isBigMenuHelpPoppedUp" class="rounded-md">
202 <NuInputHorizontalRadioGroup
203 v-model="bigMode"
204 bg="$vp-nolebase-enhanced-readabilities-menu-background-color"
205 text="sm $vp-nolebase-enhanced-readabilities-menu-text-color"
206 :options="bigOptions"
207 />
208 </NuInputHighlight>
209 </div>
210 </div>
211 </Teleport>
212 </div>
213</template>
214
215<style scoped>
216.theme-settings {
217 position: relative;
218 flex-shrink: 0;
219}
220.theme-settings-btn {
221 display: flex;
222 align-items: center;
223 justify-content: center;
224 width: 30px;
225 height: 30px;
226 padding: 0;
227 border: none;
228 border-radius: 0;
229 background: transparent;
230 color: var(--vp-c-text-1);
231 opacity: 0.55;
232 cursor: pointer;
233 transition: opacity 0.25s, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
234}
235.theme-settings-btn:hover,
236.theme-settings-btn[aria-expanded="true"] {
237 color: var(--vp-c-text-1);
238 opacity: 1;
239 background: transparent;
240}
241.theme-settings-btn:active {
242 transform: scale(0.94);
243}
244.theme-settings-btn span {
245 font-size: 15px;
246}
247html.effects-disabled .theme-settings-btn {
248 transition: none;
249}
250html.effects-disabled .theme-settings-btn:active {
251 transform: none;
252}
253.theme-settings-menu {
254 --vp-nolebase-enhanced-readabilities-menu-background-color: var(
255 --wk-c-menu-bg
256 );
257 --vp-nolebase-enhanced-readabilities-menu-text-color: var(--vp-c-text-1);
258 position: fixed;
259 z-index: 100;
260 width: 260px;
261 max-width: calc(100vw - 24px);
262 max-height: calc(100vh - 24px);
263 overflow-y: auto;
264 padding: 12px;
265 border-radius: 12px;
266 border: 1px solid var(--vp-c-divider);
267 background-color: var(--vp-c-bg-elv);
268 box-shadow: var(--vp-shadow-3, 0 4px 16px rgba(0, 0, 0, 0.3));
269}
270.theme-settings-menu > * + * {
271 margin-top: 14px;
272}
273</style>
docs/.vitepress/theme/components/themerepo/ThemeRepos.vue +385 −36
@@ -1,6 +1,6 @@
1<script setup lang="ts"> 1<script setup lang="ts">
2import { useMediaQuery } from '@vueuse/core' 2import { refDebounced, useMediaQuery } from '@vueuse/core'
3import { computed, onMounted, ref } from 'vue' 3import { computed, onMounted, onUnmounted, ref } from 'vue'
4import { 4import {
5 DEFAULT_THEME, 5 DEFAULT_THEME,
6 resolveThemeColors 6 resolveThemeColors
@@ -9,7 +9,9 @@ import type {
9 ManaTheme, 9 ManaTheme,
10 ThemeRepoEntry 10 ThemeRepoEntry
11} from '../../../../ext/themeRepos/types' 11} from '../../../../ext/themeRepos/types'
12import { SEARCH_DEBOUNCE_MS, STATUS_TICK_MS } from '../extrepo/constants'
12import { screens } from './screens' 13import { screens } from './screens'
14import ThemeFilterMenu from './ThemeFilterMenu.vue'
13import ThemePreview from './ThemePreview.vue' 15import ThemePreview from './ThemePreview.vue'
14import ThemeRow from './ThemeRow.vue' 16import ThemeRow from './ThemeRow.vue'
15 17
@@ -22,6 +24,7 @@ type ThemeFile = {
22 theme?: { name?: string; colors?: { values?: Record<string, string> } } 24 theme?: { name?: string; colors?: { values?: Record<string, string> } }
23} 25}
24type LoadedTheme = ManaTheme & { raw: string } 26type LoadedTheme = ManaTheme & { raw: string }
27type ThemeGroup = { author: string; themes: LoadedTheme[] }
25 28
26const props = withDefaults(defineProps<{ themes?: ThemeRepoEntry[] }>(), { 29const props = withDefaults(defineProps<{ themes?: ThemeRepoEntry[] }>(), {
27 themes: () => [] 30 themes: () => []
@@ -40,24 +43,92 @@ const previewTheme = computed(
40 DEFAULT_THEME 43 DEFAULT_THEME
41) 44)
42const screen = computed(() => screens[screenIndex.value] ?? screens[0]) 45const screen = computed(() => screens[screenIndex.value] ?? screens[0])
46const groups = computed<ThemeGroup[]>(() => {
47 const byAuthor = new Map<string, LoadedTheme[]>()
48 for (const theme of themes.value) {
49 const author = theme.author?.trim() || 'Unknown'
50 const list = byAuthor.get(author)
51 if (list) list.push(theme)
52 else byAuthor.set(author, [theme])
53 }
54 return [...byAuthor.entries()]
55 .map(([author, list]) => ({
56 author,
57 themes: [...list].sort((a, b) => a.name.localeCompare(b.name))
58 }))
59 .sort((a, b) => a.author.localeCompare(b.author))
60})
61
62const openGroups = ref<Set<string>>(new Set())
63const knownAuthors = new Set<string>()
64const query = ref('')
65const debouncedQuery = refDebounced(query, SEARCH_DEBOUNCE_MS)
66const mainColorsOnly = ref(true)
67const bigSwatches = ref(true)
68
69const isSearching = computed(() => debouncedQuery.value.trim().length > 0)
70const filteredGroups = computed<ThemeGroup[]>(() => {
71 const q = debouncedQuery.value.trim().toLowerCase()
72 if (!q) return groups.value
73 return groups.value
74 .map(group => ({
75 author: group.author,
76 themes: group.themes.filter(theme =>
77 theme.name.toLowerCase().includes(q) ||
78 group.author.toLowerCase().includes(q)
79 )
80 }))
81 .filter(group => group.themes.length > 0)
82})
83const searchPlaceholder = computed(() =>
84 themes.value.length
85 ? `Search themes (${themes.value.length})…`
86 : 'Search themes…'
87)
88
89function toggleGroup(author: string): void {
90 const next = new Set(openGroups.value)
91 if (next.has(author)) next.delete(author)
92 else next.add(author)
93 openGroups.value = next
94}
43 95
44async function fetchJson<T>(url: string): Promise<T> { 96function isGroupOpen(author: string): boolean {
45 const res = await fetch(url) 97 return isSearching.value || openGroups.value.has(author)
98}
99
100function applyThemes(list: LoadedTheme[]): void {
101 themes.value = list
102 const next = new Set(openGroups.value)
103 for (const group of groups.value) {
104 if (!knownAuthors.has(group.author)) {
105 knownAuthors.add(group.author)
106 next.add(group.author)
107 }
108 }
109 openGroups.value = next
110}
111
112async function fetchJson<T>(url: string, noCache = false): Promise<T> {
113 const res = await fetch(url, noCache ? { cache: 'no-cache' } : undefined)
46 if (!res.ok) throw new Error(`${res.status} ${res.statusText}`) 114 if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
47 return res.json() 115 return res.json()
48} 116}
49 117
50async function loadRepo(entry: ThemeRepoEntry): Promise<LoadedTheme[]> { 118async function loadRepo(
119 entry: ThemeRepoEntry,
120 noCache = false
121): Promise<LoadedTheme[]> {
51 if (!entry.raw) return [] 122 if (!entry.raw) return []
52 123
53 const index = await fetchJson<{ themes?: ThemeIndexEntry[] }>(entry.raw) 124 const index = await fetchJson<{ themes?: ThemeIndexEntry[] }>(entry.raw, true)
54 const loaded = await Promise.all( 125 const results = await Promise.allSettled(
55 (index.themes ?? []) 126 (index.themes ?? [])
56 .filter((item): item is ThemeIndexEntry & { url: string } => 127 .filter((item): item is ThemeIndexEntry & { url: string } =>
57 Boolean(item.url) 128 Boolean(item.url)
58 ) 129 )
59 .map(async item => { 130 .map(async item => {
60 const file = await fetchJson<ThemeFile>(item.url) 131 const file = await fetchJson<ThemeFile>(item.url, noCache)
61 const values = file.theme?.colors?.values 132 const values = file.theme?.colors?.values
62 const name = item.name ?? file.theme?.name 133 const name = item.name ?? file.theme?.name
63 return values && name 134 return values && name
@@ -73,27 +144,106 @@ async function loadRepo(entry: ThemeRepoEntry): Promise<LoadedTheme[]> {
73 }) 144 })
74 ) 145 )
75 146
76 return loaded.filter((theme): theme is LoadedTheme => theme !== null) 147 return results
148 .map(result => result.status === 'fulfilled' ? result.value : null)
149 .filter((theme): theme is LoadedTheme => theme !== null)
77} 150}
78 151
79onMounted(async () => { 152async function fetchThemes(noCache = false): Promise<{
80 if (props.themes.length === 0) return 153 themes: LoadedTheme[]
81 154 failed: boolean
82 loading.value = true 155}> {
83 const results = await Promise.allSettled(props.themes.map(loadRepo)) 156 const results = await Promise.allSettled(
157 props.themes.map(entry => loadRepo(entry, noCache))
158 )
84 const unique = new Map<string, LoadedTheme>() 159 const unique = new Map<string, LoadedTheme>()
85 for ( 160 for (
86 const theme of results.flatMap(r => r.status === 'fulfilled' ? r.value : []) 161 const theme of results.flatMap(r => r.status === 'fulfilled' ? r.value : [])
87 ) { 162 ) {
88 unique.set(theme.raw, theme) 163 unique.set(theme.raw, theme)
89 } 164 }
90 themes.value = [...unique.values()].sort((a, b) => 165 return {
91 a.name.localeCompare(b.name) 166 themes: [...unique.values()].sort((a, b) => a.name.localeCompare(b.name)),
92 ) 167 failed: results.some(r => r.status === 'rejected')
93 loadFailed.value = results.some(r => r.status === 'rejected') 168 }
94 loading.value = false 169}
170
171async function load(): Promise<void> {
172 if (props.themes.length === 0) return
173
174 loadFailed.value = false
175 try {
176 const result = await fetchThemes()
177 applyThemes(result.themes)
178 loadFailed.value = result.failed
179 } finally {
180 loading.value = false
181 }
182}
183
184const refreshing = ref(false)
185const refreshFailed = ref(false)
186const ticked = ref(false)
187let tickTimer: ReturnType<typeof setTimeout> | undefined
188
189onUnmounted(() => {
190 if (tickTimer) clearTimeout(tickTimer)
191})
192
193async function refresh(): Promise<void> {
194 if (refreshing.value) return
195
196 refreshing.value = true
197 refreshFailed.value = false
198 try {
199 const result = await fetchThemes(true)
200 if (result.failed || result.themes.length === 0) {
201 refreshFailed.value = true
202 return
203 }
204 applyThemes(result.themes)
205 } finally {
206 refreshing.value = false
207 }
208}
209
210const busy = computed(() => loading.value || refreshing.value)
211const failed = computed(() => loadFailed.value || refreshFailed.value)
212const statusIcon = computed(() => {
213 if (busy.value) return 'i-lucide:loader-circle'
214 if (failed.value) return 'i-lucide:x'
215 if (ticked.value) return 'i-lucide:check'
216 return 'i-lucide:refresh-cw'
217})
218const statusTitle = computed(() => {
219 if (loading.value) return 'Loading themes…'
220 if (refreshing.value) return 'Refreshing themes…'
221 if (failed.value) return 'Loading failed — click to retry'
222 if (ticked.value) return 'Themes refreshed'
223 return 'Refresh themes'
95}) 224})
96 225
226async function onStatusClick(): Promise<void> {
227 if (busy.value) return
228 if (loadFailed.value) {
229 loading.value = true
230 await load()
231 return
232 }
233
234 ticked.value = false
235 if (tickTimer) clearTimeout(tickTimer)
236 await refresh()
237 if (!refreshFailed.value) {
238 ticked.value = true
239 tickTimer = setTimeout(() => {
240 ticked.value = false
241 }, STATUS_TICK_MS)
242 }
243}
244
245onMounted(load)
246
97function showScreen(delta: number): void { 247function showScreen(delta: number): void {
98 screenIndex.value = (screenIndex.value + delta + screens.length) % 248 screenIndex.value = (screenIndex.value + delta + screens.length) %
99 screens.length 249 screens.length
@@ -106,6 +256,33 @@ function toggleTheme(theme: LoadedTheme): void {
106 256
107<template> 257<template>
108 <div class="theme-repos"> 258 <div class="theme-repos">
259 <div class="theme-toolbar">
260 <div class="theme-search">
261 <span class="i-lucide:search" />
262 <input v-model="query" type="text" :placeholder="searchPlaceholder" />
263 </div>
264 <button
265 type="button"
266 class="theme-status-btn"
267 :class="{
268 spinning: busy,
269 'is-failed': !busy && failed,
270 'is-ok': !busy && !failed && ticked
271 }"
272 :disabled="busy"
273 :title="statusTitle"
274 aria-label="Reload theme data"
275 @click="onStatusClick"
276 >
277 <span :class="statusIcon" />
278 </button>
279 <ThemeFilterMenu
280 v-model="mainColorsOnly"
281 :big-swatches="bigSwatches"
282 @update:big-swatches="bigSwatches = $event"
283 />
284 </div>
285
109 <div v-if="themes.length" class="theme-showcase"> 286 <div v-if="themes.length" class="theme-showcase">
110 <div class="theme-stage"> 287 <div class="theme-stage">
111 <ThemePreview 288 <ThemePreview
@@ -121,24 +298,60 @@ function toggleTheme(theme: LoadedTheme): void {
121 class="theme-list" 298 class="theme-list"
122 :class="{ 'theme-list-open': isPhone && selectedKey }" 299 :class="{ 'theme-list-open': isPhone && selectedKey }"
123 > 300 >
124 <template v-for="theme in themes" :key="theme.raw"> 301 <p
125 <ThemeRow 302 v-if="isSearching && filteredGroups.length === 0"
126 :theme="theme" 303 class="theme-repos-empty"
127 :selected="theme.raw === selectedKey" 304 >
128 @select="toggleTheme(theme)" 305 No themes match your search.
129 /> 306 </p>
130 <div 307 <div
131 v-if="isPhone && theme.raw === selectedKey" 308 v-for="group in filteredGroups"
132 class="theme-dropdown" 309 :key="group.author"
310 class="theme-group"
311 >
312 <button
313 type="button"
314 class="theme-group-row"
315 :aria-expanded="isGroupOpen(group.author)"
316 @click="toggleGroup(group.author)"
133 > 317 >
134 <ThemePreview 318 <span class="theme-group-title">
135 :theme="theme" 319 <span class="theme-group-name">{{ group.author }}</span>
136 :screen="screen" 320 <span
137 @prev="showScreen(-1)" 321 class="theme-group-count"
138 @next="showScreen(1)" 322 :title="`${group.themes.length} theme${
323 group.themes.length === 1 ? '' : 's'
324 }`"
325 >{{ group.themes.length }}</span>
326 </span>
327 <span
328 class="theme-group-toggle i-lucide:chevron-down"
329 :class="{ open: isGroupOpen(group.author) }"
139 /> 330 />
140 </div> 331 </button>
141 </template> 332 <template v-if="isGroupOpen(group.author)">
333 <template v-for="theme in group.themes" :key="theme.raw">
334 <ThemeRow
335 :theme="theme"
336 :selected="theme.raw === selectedKey"
337 :main-only="mainColorsOnly"
338 :big-swatches="bigSwatches"
339 @select="toggleTheme(theme)"
340 />
341 <div
342 v-if="isPhone && theme.raw === selectedKey"
343 class="theme-dropdown"
344 >
345 <ThemePreview
346 :theme="theme"
347 :screen="screen"
348 @prev="showScreen(-1)"
349 @next="showScreen(1)"
350 />
351 </div>
352 </template>
353 </template>
354 </div>
142 </div> 355 </div>
143 </div> 356 </div>
144 </div> 357 </div>
@@ -158,6 +371,83 @@ function toggleTheme(theme: LoadedTheme): void {
158 border-radius: var(--radius-xl, 12px); 371 border-radius: var(--radius-xl, 12px);
159 overflow: hidden; 372 overflow: hidden;
160} 373}
374.theme-toolbar {
375 display: flex;
376 flex-wrap: nowrap;
377 align-items: center;
378 gap: 8px;
379 padding: 10px;
380 background-color: var(--vp-c-bg-soft);
381 border-bottom: 1px solid var(--vp-c-divider);
382}
383.theme-search {
384 display: flex;
385 align-items: center;
386 gap: 6px;
387 flex: 1 1 auto;
388 min-width: 0;
389 padding: 6px 10px;
390 border-radius: 8px;
391 border: 1px solid var(--vp-c-divider);
392 background-color: var(--vp-c-bg);
393 color: var(--vp-c-text-2);
394}
395.theme-search input {
396 flex: 1;
397 min-width: 0;
398 border: none;
399 outline: none;
400 background: transparent;
401 color: var(--vp-c-text-1);
402 font-size: 13px;
403}
404.theme-search > span {
405 flex-shrink: 0;
406}
407.theme-status-btn {
408 display: flex;
409 align-items: center;
410 justify-content: center;
411 flex-shrink: 0;
412 width: 30px;
413 height: 30px;
414 padding: 0;
415 border: none;
416 border-radius: 0;
417 background: transparent;
418 color: var(--vp-c-text-1);
419 opacity: 0.55;
420 cursor: pointer;
421 transition: opacity 0.25s;
422}
423.theme-status-btn:hover:not(:disabled) {
424 opacity: 1;
425}
426.theme-status-btn:disabled {
427 cursor: default;
428}
429.theme-status-btn span {
430 font-size: 15px;
431}
432.theme-status-btn.spinning span {
433 animation: theme-spin 1s linear infinite;
434}
435.theme-status-btn.is-failed {
436 color: var(--vp-c-red-2, #e5484d);
437 opacity: 1;
438}
439.theme-status-btn.is-ok {
440 color: var(--vp-c-green-1, #3dd68c);
441 opacity: 1;
442}
443@keyframes theme-spin {
444 to {
445 transform: rotate(360deg);
446 }
447}
448html.effects-disabled .theme-status-btn.spinning span {
449 animation: none;
450}
161.theme-showcase { 451.theme-showcase {
162 display: grid; 452 display: grid;
163 grid-template-columns: minmax(220px, 0.82fr) minmax(0, 1.18fr); 453 grid-template-columns: minmax(220px, 0.82fr) minmax(0, 1.18fr);
@@ -186,7 +476,66 @@ function toggleTheme(theme: LoadedTheme): void {
186 justify-content: flex-start; 476 justify-content: flex-start;
187 overflow-y: auto; 477 overflow-y: auto;
188} 478}
189.theme-list > .theme-row:not(:first-child) { 479.theme-group + .theme-group {
480 border-top: 1px solid var(--vp-c-divider);
481}
482.theme-group-row {
483 display: flex;
484 align-items: center;
485 justify-content: space-between;
486 gap: 12px;
487 width: 100%;
488 padding: 10px 14px;
489 border: none;
490 background-color: var(--vp-c-bg-soft);
491 color: var(--vp-c-text-1);
492 font: inherit;
493 text-align: left;
494 cursor: pointer;
495}
496.theme-group-title {
497 display: flex;
498 align-items: center;
499 gap: 8px;
500 min-width: 0;
501}
502.theme-group-name {
503 min-width: 0;
504 font-size: 14px;
505 font-weight: 600;
506 color: var(--vp-c-text-1);
507 white-space: nowrap;
508 overflow: hidden;
509 text-overflow: ellipsis;
510}
511.theme-group-toggle {
512 color: var(--vp-c-text-1);
513 font-size: 18px;
514 transition: color 0.2s, transform 0.2s;
515}
516.theme-group-row:hover .theme-group-toggle {
517 color: var(--vp-c-brand-1);
518}
519.theme-group-toggle.open {
520 transform: rotate(180deg);
521}
522.theme-group-count {
523 display: inline-flex;
524 align-items: center;
525 justify-content: center;
526 min-width: 20px;
527 padding: 1px 6px;
528 border-radius: 6px;
529 border: 1px solid var(--vp-c-divider);
530 background-color: var(--vp-c-bg);
531 color: var(--vp-c-text-2);
532 font-size: 11px;
533 font-weight: 600;
534 line-height: 16px;
535 font-variant-numeric: tabular-nums;
536 flex-shrink: 0;
537}
538.theme-group .theme-row + .theme-row {
190 border-top: 1px solid var(--vp-c-divider); 539 border-top: 1px solid var(--vp-c-divider);
191} 540}
192.theme-dropdown { 541.theme-dropdown {
docs/.vitepress/theme/components/themerepo/ThemeRow.vue +123 −117
@@ -1,9 +1,18 @@
1<script setup lang="ts"> 1<script setup lang="ts">
2import { computed } from 'vue' 2import { computed } from 'vue'
3import { IDENTITY_COLORS } from '../../../../ext/themeRepos/defaults'
3import type { ManaTheme } from '../../../../ext/themeRepos/types' 4import type { ManaTheme } from '../../../../ext/themeRepos/types'
4import { useCopy } from '../extrepo/useCopy' 5import { useCopy } from '../extrepo/useCopy'
5 6
6const props = defineProps<{ theme: ManaTheme; selected: boolean }>() 7const props = withDefaults(
8 defineProps<{
9 theme: ManaTheme
10 selected: boolean
11 mainOnly?: boolean
12 bigSwatches?: boolean
13 }>(),
14 { mainOnly: false, bigSwatches: false }
15)
7defineEmits<{ select: [] }>() 16defineEmits<{ select: [] }>()
8 17
9const { copiedKey, copy } = useCopy() 18const { copiedKey, copy } = useCopy()
@@ -14,38 +23,49 @@ const addThemeLink = computed(() =>
14 : undefined 23 : undefined
15) 24)
16 25
17const swatches = computed(() => 26function formatColor(color: string): string {
18 Object.entries(props.theme.colors) 27 return /^#[0-9a-f]{6}ff$/i.test(color) ? color.slice(0, 7) : color
28}
29
30const swatches = computed(() => {
31 const colors = props.theme.colors
32 if (props.mainOnly) {
33 return IDENTITY_COLORS
34 .filter(key => colors[key])
35 .map(key => ({ key, color: formatColor(colors[key]) }))
36 }
37 return Object.entries(colors)
19 .sort(([a], [b]) => a.localeCompare(b)) 38 .sort(([a], [b]) => a.localeCompare(b))
20 .map(([key, color]) => ({ key, color })) 39 .map(([key, color]) => ({ key, color: formatColor(color) }))
21) 40})
22</script> 41</script>
23 42
24<template> 43<template>
25 <div 44 <div
26 class="theme-row" 45 class="theme-row"
27 :class="{ 'theme-row-selected': selected }" 46 :class="{ 'theme-row-selected': selected }"
47 role="button"
48 tabindex="0"
49 :aria-pressed="selected"
28 @click="$emit('select')" 50 @click="$emit('select')"
51 @keydown.enter.self.prevent="$emit('select')"
52 @keydown.space.self.prevent="$emit('select')"
29 > 53 >
30 <div class="theme-row-body"> 54 <div class="theme-row-body">
31 <div class="theme-row-text"> 55 <button
32 <button 56 type="button"
33 type="button" 57 class="theme-row-name"
34 class="theme-row-name" 58 :aria-pressed="selected"
35 :aria-pressed="selected" 59 :title="selected
36 :title="selected 60 ? 'Show default preview'
37 ? 'Show default preview' 61 : `Preview ${theme.name}`"
38 : `Preview ${theme.name}`" 62 >
39 > 63 {{ theme.name }}
40 {{ theme.name }} 64 </button>
41 </button>
42 <span v-if="theme.author" class="theme-row-author">
43 {{ theme.author }}
44 </span>
45 </div>
46 <button 65 <button
47 type="button" 66 type="button"
48 class="theme-shades" 67 class="theme-shades"
68 :class="{ 'theme-shades-big': bigSwatches }"
49 :aria-pressed="selected" 69 :aria-pressed="selected"
50 :aria-label="`Preview ${theme.name}`" 70 :aria-label="`Preview ${theme.name}`"
51 > 71 >
@@ -53,43 +73,60 @@ const swatches = computed(() =>
53 v-for="swatch in swatches" 73 v-for="swatch in swatches"
54 :key="swatch.key" 74 :key="swatch.key"
55 class="theme-shade" 75 class="theme-shade"
56 :style="{ backgroundColor: swatch.color }" 76 :class="{ 'theme-shade-big': bigSwatches }"
77 :style="bigSwatches
78 ? undefined
79 : { backgroundColor: swatch.color }"
57 :title="`${swatch.key}: ${swatch.color}`" 80 :title="`${swatch.key}: ${swatch.color}`"
58 /> 81 >
82 <template v-if="bigSwatches">
83 <span
84 class="theme-shade-fill"
85 :style="{ backgroundColor: swatch.color }"
86 />
87 <span class="theme-shade-hex">{{
88 swatch.color.replace('#', '')
89 }}</span>
90 </template>
91 </span>
59 </button> 92 </button>
60 </div> 93 </div>
61 94
62 <a 95 <div class="theme-row-actions">
63 v-if="addThemeLink" 96 <a
64 class="theme-install" 97 v-if="addThemeLink"
65 :href="addThemeLink" 98 class="ext-btn ext-btn-install"
66 :aria-label="`Add ${theme.name} to Mana`" 99 :href="addThemeLink"
67 :title="`Add ${theme.name} to Mana`" 100 :aria-label="`Add ${theme.name} to Mana`"
68 @click.stop 101 :title="`Add ${theme.name} to Mana`"
69 > 102 @click.stop
70 <span class="theme-install-icon i-lucide:download" /> 103 >
71 <span class="theme-install-label">Install</span> 104 <span class="i-lucide:download" />
72 </a> 105 <span class="ext-btn-install-label">Install</span>
106 </a>
73 107
74 <button 108 <button
75 v-if="theme.raw" 109 v-if="theme.raw"
76 type="button" 110 type="button"
77 class="theme-copy" 111 class="ext-btn ext-btn-copy"
78 :class="{ 'theme-copy-done': copiedKey === theme.raw }" 112 :class="{ 'theme-copy-done': copiedKey === theme.raw }"
79 :aria-label="copiedKey === theme.raw 113 :aria-label="copiedKey === theme.raw
80 ? `Copied ${theme.name} URL` 114 ? `Copied ${theme.name} URL`
81 : `Copy ${theme.name} URL`" 115 : `Copy ${theme.name} URL`"
82 :title="copiedKey === theme.raw 116 :title="copiedKey === theme.raw
83 ? 'Copied!' 117 ? 'Copied!'
84 : `Copy ${theme.name} JSON URL`" 118 : `Copy ${theme.name} JSON URL`"
85 @click.stop="copy(theme.raw, theme.raw)" 119 @click.stop="copy(theme.raw, theme.raw)"
86 > 120 >
87 <span v-if="copiedKey === theme.raw" class="i-lucide:check" /> 121 <span v-if="copiedKey === theme.raw" class="i-lucide:check" />
88 <span v-else class="i-lucide:copy" /> 122 <span v-else class="i-lucide:copy" />
89 </button> 123 </button>
124 </div>
90 </div> 125 </div>
91</template> 126</template>
92 127
128<style scoped src="../extrepo/repoRowShared.css"></style>
129
93<style scoped> 130<style scoped>
94.theme-row { 131.theme-row {
95 display: flex; 132 display: flex;
@@ -103,6 +140,10 @@ const swatches = computed(() =>
103.theme-row:hover { 140.theme-row:hover {
104 background-color: var(--vp-c-bg-soft); 141 background-color: var(--vp-c-bg-soft);
105} 142}
143.theme-row:focus-visible {
144 outline: 2px solid var(--vp-c-brand-1);
145 outline-offset: -2px;
146}
106.theme-row-selected { 147.theme-row-selected {
107 border-left-color: var(--vp-c-brand-1); 148 border-left-color: var(--vp-c-brand-1);
108 background-color: var(--vp-c-bg-soft); 149 background-color: var(--vp-c-bg-soft);
@@ -114,11 +155,11 @@ const swatches = computed(() =>
114 flex-direction: column; 155 flex-direction: column;
115 gap: 6px; 156 gap: 6px;
116} 157}
117.theme-row-text { 158.theme-row-actions {
118 min-width: 0;
119 display: flex; 159 display: flex;
120 flex-direction: column; 160 align-items: center;
121 gap: 1px; 161 gap: 6px;
162 flex-shrink: 0;
122} 163}
123.theme-row-name { 164.theme-row-name {
124 min-width: 0; 165 min-width: 0;
@@ -136,14 +177,6 @@ const swatches = computed(() =>
136 text-overflow: ellipsis; 177 text-overflow: ellipsis;
137 cursor: pointer; 178 cursor: pointer;
138} 179}
139.theme-row-author {
140 font-size: 12px;
141 line-height: 1.3;
142 color: var(--vp-c-text-3);
143 white-space: nowrap;
144 overflow: hidden;
145 text-overflow: ellipsis;
146}
147.theme-shades { 180.theme-shades {
148 width: 100%; 181 width: 100%;
149 display: flex; 182 display: flex;
@@ -159,69 +192,42 @@ const swatches = computed(() =>
159 flex: 1; 192 flex: 1;
160 height: 100%; 193 height: 100%;
161} 194}
162.theme-copy { 195.theme-shades-big {
163 flex-shrink: 0; 196 height: auto;
197 gap: 6px;
198 border-radius: 0;
199 overflow-x: auto;
200 overflow-y: hidden;
201}
202.theme-shade-big {
203 flex: 1 0 48px;
204 min-width: 48px;
205 height: auto;
164 display: flex; 206 display: flex;
165 align-items: center; 207 flex-direction: column;
166 justify-content: center; 208 border-radius: 6px;
167 width: 32px; 209 overflow: hidden;
168 height: 32px;
169 padding: 0;
170 border-radius: 8px;
171 border: 1px solid var(--vp-c-divider); 210 border: 1px solid var(--vp-c-divider);
172 background-color: var(--vp-c-bg); 211 background-color: var(--vp-c-bg);
173 color: var(--vp-c-text-1);
174 cursor: pointer;
175 transition: border-color 0.2s, color 0.2s;
176} 212}
177.theme-copy:hover { 213.theme-shade-fill {
178 border-color: var(--vp-c-brand-1); 214 width: 100%;
179 color: var(--vp-c-brand-1); 215 height: 42px;
216}
217.theme-shade-hex {
218 display: block;
219 padding: 4px 2px;
220 font-size: 10px;
221 line-height: 1.2;
222 text-align: center;
223 color: var(--vp-c-text-2);
224 font-variant-numeric: tabular-nums;
225 white-space: nowrap;
226 overflow: hidden;
227 text-overflow: ellipsis;
180} 228}
181.theme-copy-done { 229.theme-copy-done {
182 border-color: var(--vp-c-brand-1); 230 border-color: var(--vp-c-brand-1);
183 color: var(--vp-c-brand-1); 231 color: var(--vp-c-brand-1);
184} 232}
185.theme-copy span {
186 font-size: 15px;
187}
188.theme-install {
189 flex-shrink: 0;
190 display: flex;
191 align-items: center;
192 justify-content: center;
193 gap: 5px;
194 height: 32px;
195 padding: 0 10px;
196 border-radius: 8px;
197 border: 1px solid var(--vp-button-brand-border);
198 background-color: var(--vp-button-brand-bg);
199 color: var(--vp-button-brand-text) !important;
200 font-size: 13px;
201 font-weight: 600;
202 line-height: 1;
203 text-decoration: none !important;
204 transition: filter 0.2s, border-color 0.2s;
205}
206.theme-install:hover {
207 filter: brightness(1.08);
208 border-color: var(--vp-button-brand-hover-border);
209}
210.theme-install-icon {
211 font-size: 15px;
212}
213.theme-install-label {
214 white-space: nowrap;
215}
216
217@media (max-width: 767px) {
218 .theme-install {
219 width: 32px;
220 padding: 0;
221 gap: 0;
222 }
223 .theme-install-label {
224 display: none;
225 }
226}
227</style> 233</style>
docs/ext/themeRepos/defaults.ts +7
@@ -21,6 +21,13 @@ export const DEFAULT_THEME: ManaTheme = {
21 } 21 }
22} 22}
23 23
24export const IDENTITY_COLORS = [
25 'accent',
26 'background',
27 'secondaryBackground',
28 'tertiaryBackground'
29] as const
30
24export const resolveThemeColors = ( 31export const resolveThemeColors = (
25 colors?: Record<string, string> 32 colors?: Record<string, string>
26): Record<string, string> => ({ ...DEFAULT_THEME.colors, ...(colors ?? {}) }) 33): Record<string, string> => ({ ...DEFAULT_THEME.colors, ...(colors ?? {}) })