299 lines
8.4 KiB
Svelte
299 lines
8.4 KiB
Svelte
<script lang="ts">
|
|
import Icon from "$lib/components/ui/Icon.svelte";
|
|
import { THEMES, theme, setTheme, themeStorageUnavailable } from "$lib/theme";
|
|
let {
|
|
compact = false,
|
|
tiles = false,
|
|
}: { compact?: boolean; tiles?: boolean } = $props();
|
|
function move(event: KeyboardEvent) {
|
|
const steps: Record<string, number> = {
|
|
ArrowRight: 1,
|
|
ArrowDown: 1,
|
|
ArrowLeft: -1,
|
|
ArrowUp: -1,
|
|
};
|
|
const step = steps[event.key];
|
|
if (!step && event.key !== "Home" && event.key !== "End") return;
|
|
event.preventDefault();
|
|
const group = (event.currentTarget as HTMLElement).closest(
|
|
".choices",
|
|
) as HTMLElement;
|
|
const buttons = [...group.querySelectorAll<HTMLButtonElement>("button")];
|
|
const current = buttons.indexOf(
|
|
document.activeElement as HTMLButtonElement,
|
|
);
|
|
const next =
|
|
event.key === "Home"
|
|
? 0
|
|
: event.key === "End"
|
|
? buttons.length - 1
|
|
: (current + step + buttons.length) % buttons.length;
|
|
buttons[next]?.focus();
|
|
}
|
|
</script>
|
|
|
|
<div
|
|
class="choices"
|
|
class:compact
|
|
class:tiles
|
|
role="group"
|
|
aria-label="外观主题"
|
|
>
|
|
{#each THEMES as item (item.id)}
|
|
<button
|
|
class="choice"
|
|
class:selected={$theme === item.id}
|
|
aria-pressed={$theme === item.id}
|
|
onkeydown={move}
|
|
onclick={(event) => setTheme(item.id, event)}
|
|
>
|
|
<span class="preview" data-theme={item.id} aria-hidden="true"
|
|
><span class="rail"></span><span class="list"
|
|
><i></i><i></i><i></i>{#if tiles}<i></i>{/if}</span
|
|
><span class="stage"
|
|
><i></i><b
|
|
>{#if tiles}<em></em>{/if}</b
|
|
></span
|
|
>{#if tiles}<span class="preview-text"></span>{/if}</span
|
|
>
|
|
<span class="copy"
|
|
><strong
|
|
>{tiles && item.id === "night"
|
|
? item.name + " "
|
|
: item.name}{#if tiles && item.id === "night"}<span
|
|
class="mg-tag theme-default">默认</span
|
|
>{/if}</strong
|
|
><small>{tiles ? item.tone : item.english + " · " + item.tone}</small>{#if !tiles}<span
|
|
>{item.description}</span
|
|
>{/if}</span
|
|
>
|
|
<span class="check" class:tile-check={tiles} aria-hidden="true"
|
|
>{#if $theme === item.id}<Icon name="check" size={14} />{/if}</span
|
|
>
|
|
</button>
|
|
{/each}
|
|
</div>
|
|
{#if $themeStorageUnavailable && !compact}<p class="notice" role="status">
|
|
浏览器禁止本地存储:本次有效,其他操作不受影响
|
|
</p>{/if}
|
|
|
|
<style>
|
|
.choices {
|
|
display: grid;
|
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
|
gap: 10px;
|
|
}
|
|
.choices.tiles {
|
|
--choice-check-width: 0px;
|
|
--choice-hover-background: var(--bg-2);
|
|
--choice-display: flex;
|
|
--choice-box-sizing: border-box;
|
|
--choice-gap: 6px;
|
|
--choice-copy-gap: 6px;
|
|
--choice-tone-align: stretch;
|
|
--choice-preview-art: var(--theme-preview-art);
|
|
--choice-preview-radius: 8px;
|
|
--choice-art-border: 0;
|
|
--choice-dock-radius: 3px;
|
|
--choice-dock-width: 100%;
|
|
--choice-radius: 12px;
|
|
--choice-name-size: var(--manage-theme-name-size);
|
|
--choice-name-line: var(--manage-theme-line);
|
|
--choice-tone-font: var(--manage-theme-tone-size)/var(--manage-theme-line)
|
|
var(--font);
|
|
--choice-selected: color-mix(in srgb, var(--gold) 60%, transparent);
|
|
--choice-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 14%, transparent);
|
|
}
|
|
.tiles .preview {
|
|
--choice-art-shadow: 0 0 0 1px var(--line-2);
|
|
--choice-dock-border: 1px solid var(--line-2);
|
|
--choice-dock-background: var(--bg-3);
|
|
color: var(--tx-1);
|
|
}
|
|
.tile-check {
|
|
display: none;
|
|
}
|
|
.tiles .copy {
|
|
flex-direction: column;
|
|
}
|
|
.choices.compact {
|
|
--choice-box-sizing: border-box;
|
|
--choice-description-size: var(--theme-pop-note-size);
|
|
--choice-description-line: var(--theme-choice-description-line);
|
|
--choice-gap: var(--theme-choice-gap);
|
|
--choice-radius: var(--theme-choice-radius);
|
|
--choice-border: transparent;
|
|
--choice-hover-background: rgb(var(--ink) / .04);
|
|
--choice-hover-border: var(--line-2);
|
|
--choice-selected: color-mix(in srgb, var(--gold) 55%, transparent);
|
|
--choice-selected-bg: color-mix(in srgb, var(--gold) 8%, transparent);
|
|
--choice-tone-font: var(--theme-choice-english-font);
|
|
--choice-preview-radius: var(--theme-choice-preview-radius);
|
|
--choice-preview-art: var(--theme-preview-art);
|
|
--choice-art-shadow: 0 0 0 1px var(--line-2);
|
|
--choice-art-border: 0;
|
|
--choice-dock-radius: 3px;
|
|
--choice-dock-width: 100%;
|
|
--choice-dock-border: 1px solid var(--line-2);
|
|
--choice-dock-background: var(--bg-3);
|
|
gap: var(--theme-choice-list-gap);
|
|
grid-template-columns: 1fr;
|
|
}
|
|
.choice {
|
|
box-sizing: var(--choice-box-sizing, content-box);
|
|
display: var(--choice-display, grid);
|
|
flex-direction: column;
|
|
grid-template-columns: minmax(0, 1fr) var(--choice-check-width, 18px);
|
|
gap: var(--choice-gap, 8px);
|
|
padding: 8px;
|
|
border: 1px solid var(--choice-border, var(--line-2));
|
|
border-radius: var(--choice-radius, var(--r-md));
|
|
background: var(--bg-2);
|
|
color: var(--tx-1);
|
|
text-align: left;
|
|
cursor: pointer;
|
|
}
|
|
.choice:hover {
|
|
border-color: var(--choice-hover-border, var(--line-3));
|
|
background: var(--choice-hover-background, var(--bg-3));
|
|
}
|
|
.choice.selected {
|
|
border-color: var(--choice-selected, var(--gold));
|
|
box-shadow: var(--choice-shadow, none);
|
|
background: var(--choice-selected-bg, var(--bg-2));
|
|
}
|
|
.choice:focus-visible {
|
|
outline: 2px solid var(--info);
|
|
outline-offset: 2px;
|
|
}
|
|
.compact .choice {
|
|
font: var(--theme-choice-font);
|
|
grid-template-columns: 76px minmax(0, 1fr) 18px;
|
|
align-items: center;
|
|
}
|
|
.preview {
|
|
box-sizing: var(--choice-box-sizing, content-box);
|
|
grid-column: 1 / -1;
|
|
height: 64px;
|
|
border-radius: var(--choice-preview-radius, var(--r-sm));
|
|
position: relative;
|
|
overflow: hidden;
|
|
display: grid;
|
|
grid-template-columns: 12px 22px 1fr;
|
|
background: var(--bg-0);
|
|
border: 1px solid var(--line-2);
|
|
}
|
|
.compact .preview {
|
|
grid-column: auto;
|
|
height: 48px;
|
|
}
|
|
.rail,
|
|
.list {
|
|
background: var(--bg-1);
|
|
border-right: 1px solid var(--line);
|
|
}
|
|
.rail::before {
|
|
content: "";
|
|
display: block;
|
|
width: 4px;
|
|
height: 4px;
|
|
margin: 6px auto;
|
|
border-radius: 50%;
|
|
background: var(--gold);
|
|
}
|
|
.list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 3px;
|
|
padding: 6px 3px;
|
|
}
|
|
.list i {
|
|
height: 4px;
|
|
border-radius: 2px;
|
|
background: var(--line-3);
|
|
}
|
|
.list i:first-child {
|
|
background: var(--sc-image);
|
|
}
|
|
.stage {
|
|
position: relative;
|
|
padding: 5px 6px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 4px;
|
|
}
|
|
.stage i {
|
|
flex: 1;
|
|
border-radius: 3px;
|
|
background: var(--choice-preview-art, var(--bg-3));
|
|
border: var(--choice-art-border, 1px solid var(--line-2));
|
|
box-shadow: var(--choice-art-shadow, none);
|
|
}
|
|
.stage b {
|
|
box-sizing: var(--choice-box-sizing, content-box);
|
|
border: var(--choice-dock-border, 0);
|
|
height: 9px;
|
|
width: var(--choice-dock-width, 18px);
|
|
align-self: end;
|
|
border-radius: var(--choice-dock-radius, 2px);
|
|
background: var(--choice-dock-background, var(--grad-gold));
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
padding: 1px;
|
|
}
|
|
.stage em {
|
|
width: 14px;
|
|
border-radius: 2px;
|
|
background: var(--grad-gold);
|
|
}
|
|
.preview-text {
|
|
position: absolute;
|
|
left: 40px;
|
|
top: 6px;
|
|
width: 20px;
|
|
height: 3px;
|
|
border-radius: 2px;
|
|
background: var(--tx-1);
|
|
opacity: 0.85;
|
|
}
|
|
.copy {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: var(--choice-copy-gap, 2px) 6px;
|
|
min-width: 0;
|
|
}
|
|
.copy strong {
|
|
font-size: var(--choice-name-size, 13px);
|
|
line-height: var(--choice-name-line, inherit);
|
|
}
|
|
.copy small {
|
|
font: var(--choice-tone-font, 10px var(--mono));
|
|
color: var(--tx-3);
|
|
align-self: var(--choice-tone-align, center);
|
|
}
|
|
.copy > span {
|
|
width: 100%;
|
|
font-size: var(--choice-description-size, 11px);
|
|
line-height: var(--choice-description-line, inherit);
|
|
color: var(--tx-2);
|
|
}
|
|
.check {
|
|
color: var(--gold);
|
|
}
|
|
.notice {
|
|
font-size: 12px;
|
|
color: var(--tx-2);
|
|
margin: 12px 0 0;
|
|
}
|
|
@media (max-width: 1366px) {
|
|
.choices:not(.compact):not(.tiles) {
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
}
|
|
}
|
|
.theme-default {
|
|
box-sizing: border-box;
|
|
height: 16px;
|
|
font-size: 10px;
|
|
}
|
|
</style>
|