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 @@
11<script setup lang="ts">
2import { useMediaQuery } from '@vueuse/core'
3import { computed, onMounted, ref } from 'vue'
2import { refDebounced, useMediaQuery } from '@vueuse/core'
3import { computed, onMounted, onUnmounted, ref } from 'vue'
44import {
55 DEFAULT_THEME,
66 resolveThemeColors
@@ -9,7 +9,9 @@ import type {
99 ManaTheme,
1010 ThemeRepoEntry
1111} from '../../../../ext/themeRepos/types'
12import { SEARCH_DEBOUNCE_MS, STATUS_TICK_MS } from '../extrepo/constants'
1213import { screens } from './screens'
14import ThemeFilterMenu from './ThemeFilterMenu.vue'
1315import ThemePreview from './ThemePreview.vue'
1416import ThemeRow from './ThemeRow.vue'
1517
@@ -22,6 +24,7 @@ type ThemeFile = {
2224 theme?: { name?: string; colors?: { values?: Record<string, string> } }
2325}
2426type LoadedTheme = ManaTheme & { raw: string }
27type ThemeGroup = { author: string; themes: LoadedTheme[] }
2528
2629const props = withDefaults(defineProps<{ themes?: ThemeRepoEntry[] }>(), {
2730 themes: () => []
@@ -40,24 +43,92 @@ const previewTheme = computed(
4043 DEFAULT_THEME
4144)
4245const 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}
4395
44async function fetchJson<T>(url: string): Promise<T> {
45 const res = await fetch(url)
96function isGroupOpen(author: string): boolean {
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)
46114 if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
47115 return res.json()
48116}
49117
50async function loadRepo(entry: ThemeRepoEntry): Promise<LoadedTheme[]> {
118async function loadRepo(
119 entry: ThemeRepoEntry,
120 noCache = false
121): Promise<LoadedTheme[]> {
51122 if (!entry.raw) return []
52123
53 const index = await fetchJson<{ themes?: ThemeIndexEntry[] }>(entry.raw)
54 const loaded = await Promise.all(
124 const index = await fetchJson<{ themes?: ThemeIndexEntry[] }>(entry.raw, true)
125 const results = await Promise.allSettled(
55126 (index.themes ?? [])
56127 .filter((item): item is ThemeIndexEntry & { url: string } =>
57128 Boolean(item.url)
58129 )
59130 .map(async item => {
60 const file = await fetchJson<ThemeFile>(item.url)
131 const file = await fetchJson<ThemeFile>(item.url, noCache)
61132 const values = file.theme?.colors?.values
62133 const name = item.name ?? file.theme?.name
63134 return values && name
@@ -73,27 +144,106 @@ async function loadRepo(entry: ThemeRepoEntry): Promise<LoadedTheme[]> {
73144 })
74145 )
75146
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)
77150}
78151
79onMounted(async () => {
80 if (props.themes.length === 0) return
81
82 loading.value = true
83 const results = await Promise.allSettled(props.themes.map(loadRepo))
152async function fetchThemes(noCache = false): Promise<{
153 themes: LoadedTheme[]
154 failed: boolean
155}> {
156 const results = await Promise.allSettled(
157 props.themes.map(entry => loadRepo(entry, noCache))
158 )
84159 const unique = new Map<string, LoadedTheme>()
85160 for (
86161 const theme of results.flatMap(r => r.status === 'fulfilled' ? r.value : [])
87162 ) {
88163 unique.set(theme.raw, theme)
89164 }
90 themes.value = [...unique.values()].sort((a, b) =>
91 a.name.localeCompare(b.name)
92 )
93 loadFailed.value = results.some(r => r.status === 'rejected')
94 loading.value = false
165 return {
166 themes: [...unique.values()].sort((a, b) => a.name.localeCompare(b.name)),
167 failed: results.some(r => r.status === 'rejected')
168 }
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'
95224})
96225
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
97247function showScreen(delta: number): void {
98248 screenIndex.value = (screenIndex.value + delta + screens.length) %
99249 screens.length
@@ -106,6 +256,33 @@ function toggleTheme(theme: LoadedTheme): void {
106256
107257<template>
108258 <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
109286 <div v-if="themes.length" class="theme-showcase">
110287 <div class="theme-stage">
111288 <ThemePreview
@@ -121,24 +298,60 @@ function toggleTheme(theme: LoadedTheme): void {
121298 class="theme-list"
122299 :class="{ 'theme-list-open': isPhone && selectedKey }"
123300 >
124 <template v-for="theme in themes" :key="theme.raw">
125 <ThemeRow
126 :theme="theme"
127 :selected="theme.raw === selectedKey"
128 @select="toggleTheme(theme)"
129 />
130 <div
131 v-if="isPhone && theme.raw === selectedKey"
132 class="theme-dropdown"
301 <p
302 v-if="isSearching && filteredGroups.length === 0"
303 class="theme-repos-empty"
304 >
305 No themes match your search.
306 </p>
307 <div
308 v-for="group in filteredGroups"
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)"
133317 >
134 <ThemePreview
135 :theme="theme"
136 :screen="screen"
137 @prev="showScreen(-1)"
138 @next="showScreen(1)"
318 <span class="theme-group-title">
319 <span class="theme-group-name">{{ group.author }}</span>
320 <span
321 class="theme-group-count"
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) }"
139330 />
140 </div>
141 </template>
331 </button>
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>
142355 </div>
143356 </div>
144357 </div>
@@ -158,6 +371,83 @@ function toggleTheme(theme: LoadedTheme): void {
158371 border-radius: var(--radius-xl, 12px);
159372 overflow: hidden;
160373}
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}
161451.theme-showcase {
162452 display: grid;
163453 grid-template-columns: minmax(220px, 0.82fr) minmax(0, 1.18fr);
@@ -186,7 +476,66 @@ function toggleTheme(theme: LoadedTheme): void {
186476 justify-content: flex-start;
187477 overflow-y: auto;
188478}
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 {
190539 border-top: 1px solid var(--vp-c-divider);
191540}
192541.theme-dropdown {
docs/.vitepress/theme/components/themerepo/ThemeRow.vue +123 −117
@@ -1,9 +1,18 @@
11<script setup lang="ts">
22import { computed } from 'vue'
3import { IDENTITY_COLORS } from '../../../../ext/themeRepos/defaults'
34import type { ManaTheme } from '../../../../ext/themeRepos/types'
45import { useCopy } from '../extrepo/useCopy'
56
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)
716defineEmits<{ select: [] }>()
817
918const { copiedKey, copy } = useCopy()
@@ -14,38 +23,49 @@ const addThemeLink = computed(() =>
1423 : undefined
1524)
1625
17const swatches = computed(() =>
18 Object.entries(props.theme.colors)
26function formatColor(color: string): string {
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)
1938 .sort(([a], [b]) => a.localeCompare(b))
20 .map(([key, color]) => ({ key, color }))
21)
39 .map(([key, color]) => ({ key, color: formatColor(color) }))
40})
2241</script>
2342
2443<template>
2544 <div
2645 class="theme-row"
2746 :class="{ 'theme-row-selected': selected }"
47 role="button"
48 tabindex="0"
49 :aria-pressed="selected"
2850 @click="$emit('select')"
51 @keydown.enter.self.prevent="$emit('select')"
52 @keydown.space.self.prevent="$emit('select')"
2953 >
3054 <div class="theme-row-body">
31 <div class="theme-row-text">
32 <button
33 type="button"
34 class="theme-row-name"
35 :aria-pressed="selected"
36 :title="selected
37 ? 'Show default preview'
38 : `Preview ${theme.name}`"
39 >
40 {{ theme.name }}
41 </button>
42 <span v-if="theme.author" class="theme-row-author">
43 {{ theme.author }}
44 </span>
45 </div>
55 <button
56 type="button"
57 class="theme-row-name"
58 :aria-pressed="selected"
59 :title="selected
60 ? 'Show default preview'
61 : `Preview ${theme.name}`"
62 >
63 {{ theme.name }}
64 </button>
4665 <button
4766 type="button"
4867 class="theme-shades"
68 :class="{ 'theme-shades-big': bigSwatches }"
4969 :aria-pressed="selected"
5070 :aria-label="`Preview ${theme.name}`"
5171 >
@@ -53,43 +73,60 @@ const swatches = computed(() =>
5373 v-for="swatch in swatches"
5474 :key="swatch.key"
5575 class="theme-shade"
56 :style="{ backgroundColor: swatch.color }"
76 :class="{ 'theme-shade-big': bigSwatches }"
77 :style="bigSwatches
78 ? undefined
79 : { backgroundColor: swatch.color }"
5780 :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>
5992 </button>
6093 </div>
6194
62 <a
63 v-if="addThemeLink"
64 class="theme-install"
65 :href="addThemeLink"
66 :aria-label="`Add ${theme.name} to Mana`"
67 :title="`Add ${theme.name} to Mana`"
68 @click.stop
69 >
70 <span class="theme-install-icon i-lucide:download" />
71 <span class="theme-install-label">Install</span>
72 </a>
95 <div class="theme-row-actions">
96 <a
97 v-if="addThemeLink"
98 class="ext-btn ext-btn-install"
99 :href="addThemeLink"
100 :aria-label="`Add ${theme.name} to Mana`"
101 :title="`Add ${theme.name} to Mana`"
102 @click.stop
103 >
104 <span class="i-lucide:download" />
105 <span class="ext-btn-install-label">Install</span>
106 </a>
73107
74 <button
75 v-if="theme.raw"
76 type="button"
77 class="theme-copy"
78 :class="{ 'theme-copy-done': copiedKey === theme.raw }"
79 :aria-label="copiedKey === theme.raw
80 ? `Copied ${theme.name} URL`
81 : `Copy ${theme.name} URL`"
82 :title="copiedKey === theme.raw
83 ? 'Copied!'
84 : `Copy ${theme.name} JSON URL`"
85 @click.stop="copy(theme.raw, theme.raw)"
86 >
87 <span v-if="copiedKey === theme.raw" class="i-lucide:check" />
88 <span v-else class="i-lucide:copy" />
89 </button>
108 <button
109 v-if="theme.raw"
110 type="button"
111 class="ext-btn ext-btn-copy"
112 :class="{ 'theme-copy-done': copiedKey === theme.raw }"
113 :aria-label="copiedKey === theme.raw
114 ? `Copied ${theme.name} URL`
115 : `Copy ${theme.name} URL`"
116 :title="copiedKey === theme.raw
117 ? 'Copied!'
118 : `Copy ${theme.name} JSON URL`"
119 @click.stop="copy(theme.raw, theme.raw)"
120 >
121 <span v-if="copiedKey === theme.raw" class="i-lucide:check" />
122 <span v-else class="i-lucide:copy" />
123 </button>
124 </div>
90125 </div>
91126</template>
92127
128<style scoped src="../extrepo/repoRowShared.css"></style>
129
93130<style scoped>
94131.theme-row {
95132 display: flex;
@@ -103,6 +140,10 @@ const swatches = computed(() =>
103140.theme-row:hover {
104141 background-color: var(--vp-c-bg-soft);
105142}
143.theme-row:focus-visible {
144 outline: 2px solid var(--vp-c-brand-1);
145 outline-offset: -2px;
146}
106147.theme-row-selected {
107148 border-left-color: var(--vp-c-brand-1);
108149 background-color: var(--vp-c-bg-soft);
@@ -114,11 +155,11 @@ const swatches = computed(() =>
114155 flex-direction: column;
115156 gap: 6px;
116157}
117.theme-row-text {
118 min-width: 0;
158.theme-row-actions {
119159 display: flex;
120 flex-direction: column;
121 gap: 1px;
160 align-items: center;
161 gap: 6px;
162 flex-shrink: 0;
122163}
123164.theme-row-name {
124165 min-width: 0;
@@ -136,14 +177,6 @@ const swatches = computed(() =>
136177 text-overflow: ellipsis;
137178 cursor: pointer;
138179}
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}
147180.theme-shades {
148181 width: 100%;
149182 display: flex;
@@ -159,69 +192,42 @@ const swatches = computed(() =>
159192 flex: 1;
160193 height: 100%;
161194}
162.theme-copy {
163 flex-shrink: 0;
195.theme-shades-big {
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;
164206 display: flex;
165 align-items: center;
166 justify-content: center;
167 width: 32px;
168 height: 32px;
169 padding: 0;
170 border-radius: 8px;
207 flex-direction: column;
208 border-radius: 6px;
209 overflow: hidden;
171210 border: 1px solid var(--vp-c-divider);
172211 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;
176212}
177.theme-copy:hover {
178 border-color: var(--vp-c-brand-1);
179 color: var(--vp-c-brand-1);
213.theme-shade-fill {
214 width: 100%;
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;
180228}
181229.theme-copy-done {
182230 border-color: var(--vp-c-brand-1);
183231 color: var(--vp-c-brand-1);
184232}
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}
227233</style>
docs/ext/themeRepos/defaults.ts +7
@@ -21,6 +21,13 @@ export const DEFAULT_THEME: ManaTheme = {
2121 }
2222}
2323
24export const IDENTITY_COLORS = [
25 'accent',
26 'background',
27 'secondaryBackground',
28 'tertiaryBackground'
29] as const
30
2431export const resolveThemeColors = (
2532 colors?: Record<string, string>
2633): Record<string, string> => ({ ...DEFAULT_THEME.colors, ...(colors ?? {}) })