Files
RuneStone/src/lib/ui/WindowControls.svelte
T
Knotty Wyvern 5bd616d7fd Give themes named color roles, theme data files, and file format 3
Phase 5a-1 and 5a-2.

- roles.ts names 51 color roles. One derivation rule fills the roles
  that a theme does not give, for all themes. tokens.css keeps only the
  root defaults, without theme blocks.
- Each built-in theme is one data file in src/lib/theme/themes/. No code
  outside the theme data names a theme ID. characterThemes.ts is gone.
- New roles: link, focus, on-accent, highlight, scrim, the syntax roles,
  and 16 terminal (ANSI) roles. Stray colors in components use the roles.
- contrast.ts checks each theme against the readability rules of
  docs/ui-color.md. The tests mark the known palette failures as todo,
  and a second test fails when a known failure starts to pass.
- Theme files use schema 3 with a mode and an optional built-in base.
  A short file gets the missing colors and fonts from the base. Schema 1
  and 2 files still import. Old syntax names convert on import.
- Docs: ui-color.md, plugin-development.md (theme tokens), ui-design.md,
  guides/themes.md, and UI-041 and UI-042 in design-decisions.md.

The applied colors stay the same for every built-in theme, except three
small changes: the conflict line uses the warn color, the Write
highlight uses the highlight role, and two dialog backdrops use the
scrim role.

pnpm check passes. pnpm test: 447 pass, 31 todo, 0 fail. Full smoke
suite: 93 passed, 2 known. appearance/palettes read the old syntax
names and passed 3 of 3 times after the fix. workspace/manageTemplates
failed one time and passed on retry.
2026-10-28 15:50:45 -07:00

63 lines
2.1 KiB
Svelte

<script lang="ts">
import { t } from "$lib/i18n";
import { onMount } from "svelte";
import { getCurrentWindow } from "@tauri-apps/api/window";
import IconButton from "./IconButton.svelte";
let { onError }: { onError: (message: string) => void } = $props();
let maximized = $state(false);
const appWindow = getCurrentWindow();
async function syncMaximized() {
maximized = await appWindow.isMaximized();
}
async function run(action: "minimize" | "toggleMaximize" | "close") {
try {
// close() emits the close request handled by the workbench's unsaved-edits guard.
await appWindow[action]();
if (action === "toggleMaximize") await syncMaximized();
} catch (error) { onError(String(error)); }
}
onMount(() => {
let disposed = false;
let unlisten: (() => void) | undefined;
void syncMaximized().catch(error => onError(String(error)));
void appWindow.onResized(() => {
void syncMaximized().catch(error => onError(String(error)));
}).then(off => {
if (disposed) off(); else unlisten = off;
}).catch(error => onError(String(error)));
return () => { disposed = true; unlisten?.(); };
});
</script>
<div class="window-controls" role="group" aria-label={$t("Window controls")}>
<IconButton icon="minimize" label={$t("Minimize window")} onclick={() => void run("minimize")} />
<IconButton icon={maximized ? "window-restore" : "window-maximize"}
label={maximized ? $t("Restore window") : $t("Maximize window")} onclick={() => void run("toggleMaximize")} />
<div class="window-close">
<IconButton icon="close" label={$t("Close window")} onclick={() => void run("close")} />
</div>
</div>
<style>
.window-controls {
display: flex;
align-self: stretch;
flex-shrink: 0;
margin-left: 8px;
border-left: 1px solid var(--rs-border);
}
.window-close { display: flex; }
.window-controls :global(.icon-btn) {
width: 40px;
flex-basis: 40px;
height: 100%;
border: 0;
border-radius: var(--rs-control-radius);
}
.window-close :global(.icon-btn:hover) { background: var(--rs-caption-close-bg); color: white; }
</style>