RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,172 @@
|
||||
<script lang="ts">
|
||||
import type { IconName } from "./IconButton.svelte";
|
||||
import { actionIcons } from "./actionIcons";
|
||||
let { icon }: { icon: IconName } = $props();
|
||||
</script>
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
{#if icon === "settings"}
|
||||
<path d="M9.5 6 10 3 14 3 14.5 6 15.95 6.83 18.79 5.77 20.79 9.23 18.45 11.17 18.45 12.83 20.79 14.77 18.79 18.23 15.95 17.17 14.5 18 14 21 10 21 9.5 18 8.05 17.17 5.21 18.23 3.21 14.77 5.55 12.83 5.55 11.17 3.21 9.23 5.21 5.77 8.05 6.83Z" /><circle cx="12" cy="12" r="3" />
|
||||
{:else if icon === "sun"}
|
||||
<circle cx="12" cy="12" r="4" /><path d="M12 2v2m0 16v2M2 12h2m16 0h2M5 5l1.5 1.5m11 11L19 19M5 19l1.5-1.5m11-11L19 5" />
|
||||
{:else if icon === "git"}
|
||||
{@html actionIcons.git}
|
||||
{:else if icon === "globe"}
|
||||
<circle cx="12" cy="12" r="9" /><ellipse cx="12" cy="12" rx="4" ry="9" /><path d="M3 12h18" />
|
||||
{:else if icon === "arrow-left"}
|
||||
<path d="M20 12H4m6-6-6 6 6 6" />
|
||||
{:else if icon === "arrow-right"}
|
||||
<path d="M4 12h16m-6-6 6 6-6 6" />
|
||||
{:else if icon === "copy"}
|
||||
<rect x="8" y="8" width="12" height="12" rx="2" /><path d="M16 8V4H4v12h4" />
|
||||
{:else if icon === "duplicate"}
|
||||
<rect x="8" y="8" width="12" height="12" rx="2" /><path d="M16 8V4H4v12h4M14 11v6M11 14h6" />
|
||||
{:else if icon === "stop"}
|
||||
<rect x="5" y="5" width="14" height="14" rx="2" />
|
||||
{:else if icon === "help"}
|
||||
<circle cx="12" cy="12" r="9" /><path d="M9.5 9a2.5 2.5 0 1 1 4 2c-1 .6-1.5 1-1.5 3M12 17h.01" />
|
||||
{:else if icon === "puzzle"}
|
||||
<path d="M9 3H4v6a3 3 0 1 1 0 6v5h6a3 3 0 1 1 6 0h4v-6a3 3 0 1 0 0-6V3h-5a3 3 0 1 1-6 0Z" />
|
||||
{:else if icon === "up" || icon === "down" || icon === "kanban" || icon === "link" || icon === "zoom-in" || icon === "zoom-out"}
|
||||
{@html actionIcons[icon]}
|
||||
{:else if icon === "more"}
|
||||
<circle cx="5" cy="12" r="1" /><circle cx="12" cy="12" r="1" /><circle cx="19" cy="12" r="1" />
|
||||
{:else if icon === "chevron-down"}
|
||||
<path d="m6 9 6 6 6-6" />
|
||||
{:else if icon === "chevrons-up-down"}
|
||||
<path d="m7 15 5 5 5-5M7 9l5-5 5 5" />
|
||||
{:else if icon === "scroll"}
|
||||
<path d="M12 3v5m-3-2 3-3 3 3M12 21v-5m-3 2 3 3 3-3M3 12h5m-2-3-3 3 3 3M21 12h-5m2-3 3 3-3 3" /><circle cx="12" cy="12" r="1" />
|
||||
{:else if icon === "maximize"}
|
||||
<path d="M8 3H3v5M16 3h5v5M21 16v5h-5M8 21H3v-5" />
|
||||
{:else if icon === "minimize"}
|
||||
<path d="M5 12h14" />
|
||||
{:else if icon === "window-maximize"}
|
||||
<rect x="5" y="5" width="14" height="14" />
|
||||
{:else if icon === "window-restore"}
|
||||
<path d="M9 8V4h11v11h-4" /><rect x="4" y="9" width="11" height="11" />
|
||||
{:else if icon === "check"}
|
||||
<path d="M5 12.5 9.5 17 19 7" />
|
||||
{:else if icon === "alert"}
|
||||
<path d="M12 3 2.5 20h19Z" /><path d="M12 10v4M12 17h.01" />
|
||||
{:else if icon === "palette"}
|
||||
<path d="M12 3a9 9 0 0 0 0 18c1.1 0 1.6-.8 1.6-1.6 0-.5-.2-.8-.5-1.2-.3-.4-.5-.7-.5-1.2 0-.9.7-1.6 1.6-1.6H16a5 5 0 0 0 5-5c0-4.1-4-7.4-9-7.4Z" /><circle cx="7.5" cy="11" r="1" /><circle cx="10.5" cy="7.5" r="1" /><circle cx="15" cy="8" r="1" />
|
||||
{:else if icon === "undo"}
|
||||
<path d="M9 14 4 9l5-5" /><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11" />
|
||||
{:else if icon === "restore"}
|
||||
<path d="M3 8h5V3M21 8h-5V3M16 21v-5h5M3 16h5v5" />
|
||||
{:else if icon === "split"}
|
||||
<rect x="3" y="4" width="18" height="16" rx="2" />
|
||||
<path d="M12 4v16M6 8h3M6 12h3M15 8h3M15 12h3M15 16h3" />
|
||||
{:else if icon === "text"}
|
||||
<path d="M4 6h16M4 10h16M4 14h10M4 18h13" />
|
||||
{:else if icon === "refresh"}
|
||||
<path d="M20 7v5h-5M4 17v-5h5M6 7a7 7 0 0 1 12-1l2 3M4 15l2 3a7 7 0 0 0 12-1" />
|
||||
{:else if icon === "folder-open"}
|
||||
<path d="M6 14l1.5-2.9A2 2 0 0 1 9.2 10H20a2 2 0 0 1 1.8 2.8l-1.5 3.2A2 2 0 0 1 18.5 17H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h3.7a2 2 0 0 1 1.4.6L10 6h8a2 2 0 0 1 2 2" />
|
||||
{:else if icon === "file-plus"}
|
||||
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
|
||||
<path d="M14 2v6h6" />
|
||||
<path d="M12 18v-6" />
|
||||
<path d="M9 15h6" />
|
||||
{:else if icon === "folder-plus"}
|
||||
<path d="M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.7-.9L9.2 3.9A2 2 0 0 0 7.5 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2z" />
|
||||
<path d="M12 10v6" />
|
||||
<path d="M9 13h6" />
|
||||
{:else if icon === "save"}
|
||||
<path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z" />
|
||||
<path d="M17 21v-8H7v8" />
|
||||
<path d="M7 3v5h8" />
|
||||
{:else if icon === "pen"}
|
||||
<path d="M12 20h9" />
|
||||
<path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" />
|
||||
{:else if icon === "code"}
|
||||
<path d="m16 18 6-6-6-6" />
|
||||
<path d="m8 6-6 6 6 6" />
|
||||
{:else if icon === "terminal"}
|
||||
<path d="M4 5h16v14H4z" />
|
||||
<path d="m8 9 3 3-3 3" />
|
||||
<path d="M13 15h4" />
|
||||
{:else if icon === "eye"}
|
||||
<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7-10-7-10-7Z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
{:else if icon === "panel-left"}
|
||||
<path d="M4 5h16v14H4z" />
|
||||
<path d="M9 5v14" />
|
||||
{:else if icon === "panel-right"}
|
||||
<path d="M4 5h16v14H4z" />
|
||||
<path d="M15 5v14" />
|
||||
{:else if icon === "spark"}
|
||||
<path d="M12 3v4" />
|
||||
<path d="M12 17v4" />
|
||||
<path d="M5 12H3" />
|
||||
<path d="M21 12h-2" />
|
||||
<path d="m7 7 2 2" />
|
||||
<path d="m15 15 2 2" />
|
||||
<path d="m17 7-2 2" />
|
||||
<path d="m9 15-2 2" />
|
||||
{:else if icon === "list"}
|
||||
<path d="M8 6h13" />
|
||||
<path d="M8 12h13" />
|
||||
<path d="M8 18h13" />
|
||||
<path d="M3 6h.01" />
|
||||
<path d="M3 12h.01" />
|
||||
<path d="M3 18h.01" />
|
||||
{:else if icon === "search"}
|
||||
<circle cx="11" cy="11" r="7" />
|
||||
<path d="m20 20-3-3" />
|
||||
{:else if icon === "bookmark"}
|
||||
<path d="M6 4h12v16l-6-3-6 3z" />
|
||||
{:else if icon === "files"}
|
||||
<path d="M4 6h9v14H4z" />
|
||||
<path d="M8 6V4h9v14h-2" />
|
||||
{:else if icon === "sort"}
|
||||
<path d="m3 8 4-4 4 4" />
|
||||
<path d="M7 4v16" />
|
||||
<path d="m21 16-4 4-4-4" />
|
||||
<path d="M17 20V4" />
|
||||
{:else if icon === "fold"}
|
||||
<path d="m7 11 5-5 5 5" />
|
||||
<path d="m7 20 5-5 5 5" />
|
||||
{:else if icon === "unfold"}
|
||||
<path d="m7 4 5 5 5-5" />
|
||||
<path d="m7 13 5 5 5-5" />
|
||||
{:else if icon === "book-open"}
|
||||
<path d="M12 7v13" />
|
||||
<path d="M4 19a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h6a3 3 0 0 1 3 3" />
|
||||
<path d="M12 7a3 3 0 0 1 3-3h6a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3" />
|
||||
{:else if icon === "close"}
|
||||
<path d="M6 6l12 12" />
|
||||
<path d="M18 6l-12 12" />
|
||||
{:else if icon === "trash"}
|
||||
<path d="M4 7h16" />
|
||||
<path d="M9 7V5h6v2" />
|
||||
<path d="M6 7l1 13h10l1-13" />
|
||||
{:else if icon === "plus"}
|
||||
<path d="M12 5v14" />
|
||||
<path d="M5 12h14" />
|
||||
{:else if icon === "download"}
|
||||
<path d="M12 4v11" /><path d="M7 10l5 5 5-5" /><path d="M5 20h14" />
|
||||
{:else if icon === "upload"}
|
||||
<path d="M12 20V9" /><path d="M7 14l5-5 5 5" /><path d="M5 4h14" />
|
||||
{:else if icon === "minus"}
|
||||
<path d="M5 12h14" />
|
||||
{:else if icon === "toggle"}
|
||||
<rect x="3" y="7" width="18" height="10" rx="5" /><circle cx="16" cy="12" r="2.5" />
|
||||
{:else if icon === "fit-width"}
|
||||
<path d="M3 4v16M21 4v16M7 12h10M10 9l-3 3 3 3M14 9l3 3-3 3" />
|
||||
{:else if icon === "rotate"}
|
||||
<path d="M20 7v5h-5" /><path d="M20 12a8 8 0 1 0-2 6" />
|
||||
{/if}
|
||||
</svg>
|
||||
<style>
|
||||
svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
flex: 0 0 16px;
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-width: 1.6;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,178 @@
|
||||
<script lang="ts">
|
||||
import { onDestroy } from "svelte";
|
||||
import Icon from "./Icon.svelte";
|
||||
export type IconName =
|
||||
| "globe"
|
||||
| "check"
|
||||
| "alert"
|
||||
| "palette"
|
||||
| "undo"
|
||||
| "git"
|
||||
| "arrow-left"
|
||||
| "arrow-right"
|
||||
| "copy"
|
||||
| "duplicate"
|
||||
| "stop"
|
||||
| "settings"
|
||||
| "sun"
|
||||
| "help"
|
||||
| "puzzle"
|
||||
| "link"
|
||||
| "kanban"
|
||||
| "split"
|
||||
| "more"
|
||||
| "chevron-down"
|
||||
| "chevrons-up-down"
|
||||
| "scroll"
|
||||
| "up"
|
||||
| "down"
|
||||
| "maximize"
|
||||
| "minimize"
|
||||
| "window-maximize"
|
||||
| "window-restore"
|
||||
| "restore"
|
||||
| "refresh"
|
||||
| "text"
|
||||
| "folder-open"
|
||||
| "file-plus"
|
||||
| "folder-plus"
|
||||
| "save"
|
||||
| "pen"
|
||||
| "code"
|
||||
| "terminal"
|
||||
| "eye"
|
||||
| "panel-left"
|
||||
| "panel-right"
|
||||
| "spark"
|
||||
| "list"
|
||||
| "search"
|
||||
| "bookmark"
|
||||
| "files"
|
||||
| "sort"
|
||||
| "fold"
|
||||
| "unfold"
|
||||
| "book-open"
|
||||
| "close"
|
||||
| "trash"
|
||||
| "plus"
|
||||
| "download"
|
||||
| "upload"
|
||||
| "minus"
|
||||
| "toggle"
|
||||
| "zoom-in"
|
||||
| "zoom-out"
|
||||
| "fit-width"
|
||||
| "rotate";
|
||||
|
||||
type Props = {
|
||||
icon: IconName;
|
||||
label: string;
|
||||
active?: boolean;
|
||||
disabled?: boolean;
|
||||
onclick?: () => void;
|
||||
side?: "bottom" | "right";
|
||||
type?: "button" | "submit";
|
||||
};
|
||||
|
||||
let { icon, label, active, disabled = false, onclick, side = "bottom", type = "button" }: Props = $props();
|
||||
const tooltipId = $props.id();
|
||||
let button: HTMLButtonElement;
|
||||
let tooltip: HTMLSpanElement;
|
||||
let showTip = $state(false);
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
function onLeave() {
|
||||
clearTimeout(timer);
|
||||
showTip = false;
|
||||
if (tooltip?.matches(":popover-open")) tooltip.hidePopover();
|
||||
}
|
||||
|
||||
function onEnter() {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
if (!button?.isConnected || disabled) return;
|
||||
const bounds = button.getBoundingClientRect();
|
||||
tooltip.showPopover();
|
||||
const tip = tooltip.getBoundingClientRect();
|
||||
let left = side === "right" ? bounds.right + 8 : bounds.left + (bounds.width - tip.width) / 2;
|
||||
let top = side === "right" ? bounds.top + (bounds.height - tip.height) / 2 : bounds.bottom + 8;
|
||||
if (top + tip.height > innerHeight - 8) top = bounds.top - tip.height - 8;
|
||||
left = Math.max(8, Math.min(left, innerWidth - tip.width - 8));
|
||||
tooltip.style.left = `${left}px`;
|
||||
tooltip.style.top = `${Math.max(8, top)}px`;
|
||||
showTip = true;
|
||||
}, 300);
|
||||
}
|
||||
onDestroy(() => clearTimeout(timer));
|
||||
</script>
|
||||
|
||||
<svelte:window onresize={onLeave} onkeydown={(event) => { if (event.key === "Escape") onLeave(); }} />
|
||||
|
||||
<button
|
||||
bind:this={button}
|
||||
class="icon-btn"
|
||||
class:active
|
||||
{type}
|
||||
{disabled}
|
||||
aria-label={label}
|
||||
aria-pressed={active}
|
||||
aria-describedby={showTip ? tooltipId : undefined}
|
||||
onclick={() => { onLeave(); onclick?.(); }}
|
||||
onmouseenter={onEnter}
|
||||
onmouseleave={onLeave}
|
||||
onfocus={onEnter}
|
||||
onblur={onLeave}
|
||||
>
|
||||
<Icon {icon} />
|
||||
|
||||
</button>
|
||||
<span bind:this={tooltip} id={tooltipId} class="tip" popover="manual" role="tooltip">{label}</span>
|
||||
|
||||
<style>
|
||||
.icon-btn {
|
||||
position: relative;
|
||||
width: 28px;
|
||||
flex: 0 0 28px;
|
||||
border-radius: var(--rs-control-radius);
|
||||
height: 28px;
|
||||
padding: 0;
|
||||
border: 1px solid transparent;
|
||||
background: transparent;
|
||||
color: var(--rs-text);
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* Hover gets a neutral fill. An active toggle also gets the accent color and an accent bar. A disabled button is dim. */
|
||||
.icon-btn:not(:disabled):hover {
|
||||
background: var(--rs-hover-bg);
|
||||
border-color: var(--rs-border);
|
||||
color: var(--rs-text-strong);
|
||||
}
|
||||
|
||||
.icon-btn.active {
|
||||
background: var(--rs-item-selection-bg);
|
||||
color: var(--rs-accent);
|
||||
box-shadow: inset 0 -2px 0 var(--rs-accent);
|
||||
}
|
||||
|
||||
.icon-btn:disabled { color: var(--rs-text-dim); }
|
||||
|
||||
.tip {
|
||||
position: fixed;
|
||||
inset: auto;
|
||||
margin: 0;
|
||||
max-width: min(280px, calc(100vw - 16px));
|
||||
white-space: pre-line;
|
||||
text-align: left;
|
||||
background: var(--rs-tooltip-bg);
|
||||
border: 1px solid var(--rs-border);
|
||||
border-radius: var(--rs-control-radius);
|
||||
box-shadow: var(--rs-tooltip-shadow);
|
||||
color: var(--rs-tooltip-text);
|
||||
padding: var(--rs-tooltip-padding);
|
||||
font: var(--rs-tooltip-font-size)/1.5 var(--rs-font-ui);
|
||||
pointer-events: none;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,16 @@
|
||||
<script lang="ts">
|
||||
import Icon from "./Icon.svelte";
|
||||
import type { IconName } from "./IconButton.svelte";
|
||||
let { image, icon }: { image?: string | null; icon?: IconName } = $props();
|
||||
let failed = $state<string | null>(null);
|
||||
</script>
|
||||
|
||||
{#if image && image !== failed}
|
||||
<img class="tab-icon" src={image} alt="" width="16" height="16" draggable="false" onerror={() => { failed = image ?? null; }} />
|
||||
{:else if icon}
|
||||
<Icon {icon} />
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.tab-icon { width: 16px; height: 16px; flex-shrink: 0; object-fit: contain; }
|
||||
</style>
|
||||
@@ -0,0 +1,83 @@
|
||||
<script lang="ts">
|
||||
// The caption buttons of a window title bar. Windows and Linux get square, full-height buttons.
|
||||
// macOS shows its own traffic lights at the left, so this control is empty there.
|
||||
import { t } from "$lib/i18n";
|
||||
import { onMount } from "svelte";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import IconButton from "./IconButton.svelte";
|
||||
import { isMac } from "./shortcuts";
|
||||
|
||||
let { onError }: { onError: (message: string) => void } = $props();
|
||||
let maximized = $state(false);
|
||||
const appWindow = getCurrentWindow();
|
||||
const mac = isMac();
|
||||
const windows = typeof navigator !== "undefined" && /Windows/.test(navigator.userAgent);
|
||||
let snapTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
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)); }
|
||||
}
|
||||
|
||||
// Windows 11 shows Snap Layouts when the pointer rests on the maximize button. The host opens them for this window.
|
||||
function startSnap() {
|
||||
if (!windows) return;
|
||||
clearTimeout(snapTimer);
|
||||
snapTimer = setTimeout(() => { void invoke("window_snap_layouts").catch(() => { /* Snap Layouts are optional. */ }); }, 500);
|
||||
}
|
||||
function stopSnap() { clearTimeout(snapTimer); }
|
||||
|
||||
onMount(() => {
|
||||
if (mac) return;
|
||||
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?.(); stopSnap(); };
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if !mac}
|
||||
<div class="window-controls" role="group" aria-label={$t("Window controls")}>
|
||||
<IconButton icon="minimize" label={$t("Minimize window")} onclick={() => void run("minimize")} />
|
||||
<div class="window-maximize" role="presentation" onpointerenter={startSnap} onpointerleave={stopSnap} onpointerdown={stopSnap}>
|
||||
<IconButton icon={maximized ? "window-restore" : "window-maximize"}
|
||||
label={maximized ? $t("Restore window") : $t("Maximize window")} onclick={() => void run("toggleMaximize")} />
|
||||
</div>
|
||||
<div class="window-close">
|
||||
<IconButton icon="close" label={$t("Close window")} onclick={() => void run("close")} />
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.window-controls {
|
||||
display: flex;
|
||||
align-self: stretch;
|
||||
flex-shrink: 0;
|
||||
margin-left: 8px;
|
||||
}
|
||||
.window-maximize, .window-close { display: flex; }
|
||||
/* Caption buttons are square, 46 pixels wide, and fill the title bar height. */
|
||||
.window-controls :global(.icon-btn) {
|
||||
width: 46px;
|
||||
flex-basis: 46px;
|
||||
height: 100%;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
.window-controls :global(.icon-btn:hover) { color: var(--rs-text-strong); }
|
||||
.window-close :global(.icon-btn:hover) { background: var(--rs-caption-close-bg); color: white; }
|
||||
</style>
|
||||
@@ -0,0 +1,4 @@
|
||||
/* Icons and labels of action rows, from actionIcons.ts. */
|
||||
.action-icon { width: 17px; height: 17px; flex: 0 0 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.action-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.action-chevron { width: 13px; height: 13px; flex-basis: 13px; color: var(--rs-text-dim); }
|
||||
@@ -0,0 +1,2 @@
|
||||
// The action icons are part of the public plugin SDK, so plugins use the same artwork as the host.
|
||||
export { actionIcon, actionIcons, type ActionIcon } from "../../../packages/plugin-sdk/src/icons.ts";
|
||||
@@ -0,0 +1,100 @@
|
||||
import { actionIcon, type ActionIcon } from "./actionIcons.ts";
|
||||
|
||||
/** The check mark of the current radio row. It sits in the icon column and replaces the icon of the row. */
|
||||
function checkMark() {
|
||||
const svg = actionIcon("task");
|
||||
svg.innerHTML = '<path d="M5 12.5 9.5 17 19 7"/>';
|
||||
return svg;
|
||||
}
|
||||
|
||||
export type ActionMenuItem = { label: string; icon?: ActionIcon; shortcut?: string; run?: () => void; children?: ActionMenuItem[]; disabled?: boolean; checked?: boolean; radio?: boolean; title?: string; danger?: boolean } | { separator: true };
|
||||
|
||||
export function actionMenu(x: number, y: number, items: ActionMenuItem[], onClose: () => void, label = "Table actions", parent: HTMLElement = document.body) {
|
||||
const root = document.createElement("div"); root.className = "rs-menu table-cell-menu"; root.setAttribute("role", "menu"); root.setAttribute("aria-label", label);
|
||||
const opened: { button: HTMLButtonElement; panel: HTMLElement }[] = [];
|
||||
if (label.startsWith("Terminal")) root.style.width = "min(430px, calc(100vw - 16px))";
|
||||
const submenus = new Map<HTMLButtonElement, HTMLElement>();
|
||||
function focusRow(button?: HTMLButtonElement) {
|
||||
if (!button) return;
|
||||
button.focus({ preventScroll: true });
|
||||
const panel = button.parentElement!;
|
||||
const row = button.getBoundingClientRect(), bounds = panel.getBoundingClientRect();
|
||||
if (row.top < bounds.top) panel.scrollTop -= bounds.top - row.top;
|
||||
else if (row.bottom > bounds.bottom) panel.scrollTop += row.bottom - bounds.bottom;
|
||||
}
|
||||
function hideSubmenu(parent: HTMLElement = root) {
|
||||
const keep = parent === root ? 0 : opened.findIndex(entry => entry.panel === parent) + 1;
|
||||
for (const { button, panel } of opened.splice(keep)) { if (panel.matches(":popover-open")) panel.hidePopover(); button.setAttribute("aria-expanded", "false"); }
|
||||
}
|
||||
function positionSubmenu(button: HTMLButtonElement, panel: HTMLElement) {
|
||||
const rect = button.getBoundingClientRect(), size = panel.getBoundingClientRect(), main = button.parentElement!.getBoundingClientRect();
|
||||
panel.style.left = `${Math.max(8, main.right + size.width < innerWidth - 8 ? main.right - 2 : main.left - size.width + 2)}px`;
|
||||
panel.style.top = `${Math.max(8, Math.min(rect.top - 5, innerHeight - size.height - 8))}px`;
|
||||
}
|
||||
function reveal(button: HTMLButtonElement, panel: HTMLElement, focus = false) {
|
||||
if (!opened.some(entry => entry.panel === panel)) { hideSubmenu(button.parentElement!); opened.push({ button, panel }); }
|
||||
if (!panel.matches(":popover-open")) panel.showPopover();
|
||||
button.setAttribute("aria-expanded", "true");
|
||||
positionSubmenu(button, panel);
|
||||
if (focus) focusRow(panel.querySelector<HTMLButtonElement>("button:not(:disabled)") ?? undefined);
|
||||
}
|
||||
function populate(panel: HTMLElement, entries: ActionMenuItem[]) {
|
||||
const hasIcons = entries.some(item => !("separator" in item) && (!!item.icon || item.checked !== undefined));
|
||||
panel.classList.toggle("rs-menu-text", !hasIcons);
|
||||
for (const item of entries) {
|
||||
if ("separator" in item) { const hr = document.createElement("hr"); hr.setAttribute("role", "separator"); panel.append(hr); continue; }
|
||||
const button = document.createElement("button"); button.type = "button"; button.setAttribute("role", "menuitem"); button.disabled = !!item.disabled;
|
||||
if (item.checked !== undefined) { button.setAttribute("role", item.radio ? "menuitemradio" : "menuitemcheckbox"); button.setAttribute("aria-checked", String(item.checked)); }
|
||||
if (item.title) button.title = item.title;
|
||||
if (item.danger) button.classList.add("danger");
|
||||
const label = document.createElement("span"); label.className = "action-label"; label.textContent = item.label;
|
||||
const icon = item.radio ? (item.checked ? checkMark() : document.createElement("span"))
|
||||
: item.checked ? actionIcon("task") : item.icon ? actionIcon(item.icon) : document.createElement("span");
|
||||
icon.classList.add("action-icon"); icon.setAttribute("aria-hidden", "true");
|
||||
button.append(icon, label); panel.append(button);
|
||||
if (item.shortcut) { const shortcut = document.createElement("span"); shortcut.textContent = item.shortcut; shortcut.style.cssText = "margin-left:auto;color:var(--rs-text-dim);font-size:12px;white-space:nowrap"; button.append(shortcut); }
|
||||
if (item.children) {
|
||||
button.setAttribute("aria-haspopup", "menu"); button.setAttribute("aria-expanded", "false");
|
||||
const arrow = actionIcon("chevron"); arrow.classList.add("action-chevron"); button.append(arrow);
|
||||
const submenu = document.createElement("div"); submenu.className = "rs-menu table-cell-submenu"; submenu.setAttribute("role", "menu"); submenu.setAttribute("aria-label", item.label);
|
||||
// A popover shows in the top layer, so the blur of the parent menu cannot clip or move it.
|
||||
submenu.popover = "manual";
|
||||
populate(submenu, item.children); root.append(submenu); submenus.set(button, submenu);
|
||||
button.addEventListener("mousemove", () => { if (!button.disabled) reveal(button, submenu); });
|
||||
button.addEventListener("click", event => {
|
||||
event.stopPropagation();
|
||||
if (item.run && !(event.target instanceof Node && arrow.contains(event.target))) item.run();
|
||||
else reveal(button, submenu, true);
|
||||
});
|
||||
} else {
|
||||
button.addEventListener("mousemove", () => hideSubmenu(panel));
|
||||
button.addEventListener("click", event => { event.stopPropagation(); item.run?.(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
populate(root, items);
|
||||
root.addEventListener("mousedown", event => { event.preventDefault(); event.stopPropagation(); });
|
||||
root.addEventListener("focusin", event => {
|
||||
const button = event.target as HTMLElement;
|
||||
if (!opened.some(entry => entry.button === button) && button.parentElement) hideSubmenu(button.parentElement);
|
||||
});
|
||||
root.addEventListener("keydown", event => {
|
||||
event.stopPropagation();
|
||||
if (event.key === "Escape" || event.key === "Tab") { event.preventDefault(); onClose(); return; }
|
||||
const focused = document.activeElement as HTMLButtonElement, panel = focused.parentElement || root;
|
||||
const buttons = [...panel.querySelectorAll<HTMLButtonElement>(":scope > button:not(:disabled)")], index = buttons.indexOf(focused);
|
||||
if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) {
|
||||
event.preventDefault(); focusRow(buttons[event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (index + (event.key === "ArrowDown" ? 1 : -1) + buttons.length) % buttons.length]);
|
||||
}
|
||||
if (event.key === "ArrowRight" && submenus.has(focused)) { event.preventDefault(); reveal(focused, submenus.get(focused)!, true); }
|
||||
const entry = opened.find(entry => entry.panel === panel);
|
||||
if (event.key === "ArrowLeft" && entry) { event.preventDefault(); hideSubmenu(entry.button.parentElement!); focusRow(entry.button); }
|
||||
});
|
||||
root.addEventListener("scroll", () => { for (const { button, panel } of opened) positionSubmenu(button, panel); }, true);
|
||||
parent.append(root);
|
||||
root.style.left = `${Math.max(8, Math.min(x, innerWidth - root.offsetWidth - 8))}px`;
|
||||
root.style.top = `${Math.max(8, Math.min(y, innerHeight - root.offsetHeight - 8))}px`;
|
||||
(root.querySelector<HTMLButtonElement>(':scope > button[role="menuitemradio"][aria-checked="true"]:not(:disabled)')
|
||||
?? root.querySelector<HTMLButtonElement>(":scope > button:not(:disabled)"))?.focus({ preventScroll: true });
|
||||
return root;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
.rs-find-bar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 8px 10px;
|
||||
background: var(--rs-bg-elevated);
|
||||
color: var(--rs-text);
|
||||
font: 13px/1.4 var(--rs-font-ui);
|
||||
}
|
||||
|
||||
.rs-find-row, .rs-find-actions, .rs-find-field, .rs-find-options {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.rs-find-row, .rs-find-options { flex-wrap: wrap; }
|
||||
.rs-find-actions { flex: 0 0 auto; }
|
||||
.rs-find-field {
|
||||
flex: 1 1 180px;
|
||||
min-height: 30px;
|
||||
padding: 0 8px;
|
||||
border: 1px solid var(--rs-border);
|
||||
border-radius: var(--rs-control-radius);
|
||||
background: var(--rs-bg);
|
||||
color: var(--rs-text-dim);
|
||||
}
|
||||
.rs-find-field:focus-within { border-color: var(--rs-accent); }
|
||||
.rs-find-field:has([aria-invalid="true"]) { border-color: var(--rs-error); }
|
||||
.rs-find-field input {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 5px 0;
|
||||
border: 0;
|
||||
outline: none;
|
||||
background: transparent;
|
||||
color: var(--rs-text);
|
||||
font: inherit;
|
||||
}
|
||||
.rs-find-field input::placeholder { color: var(--rs-text-dim); }
|
||||
.rs-find-button {
|
||||
min-height: 28px;
|
||||
padding: 3px 9px;
|
||||
border: 1px solid var(--rs-border);
|
||||
border-radius: var(--rs-control-radius);
|
||||
background: transparent;
|
||||
color: var(--rs-text);
|
||||
font: inherit;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.rs-find-button:hover:not(:disabled) { background: var(--rs-hover-bg); color: var(--rs-accent); }
|
||||
.rs-find-options { gap: 4px 14px; color: var(--rs-text-dim); font-size: 12px; }
|
||||
.rs-find-options label { display: inline-flex; align-items: center; gap: 5px; min-height: 24px; cursor: pointer; }
|
||||
.rs-find-options input { margin: 0; accent-color: var(--rs-accent); }
|
||||
.rs-find-error { color: var(--rs-error); }
|
||||
:is(.live-writer, .source-editor) .cm-panels.cm-panels-top { border-bottom: 1px solid var(--rs-border); }
|
||||
:is(.live-writer, .source-editor) .cm-searchMatch { background: var(--rs-item-selection-bg); }
|
||||
:is(.live-writer, .source-editor) .cm-searchMatch-selected { background: var(--rs-selection); outline: 1px solid var(--rs-accent); }
|
||||
@@ -0,0 +1,54 @@
|
||||
import { actionMenu, type ActionMenuItem } from "./actionMenu.ts";
|
||||
|
||||
export type MenuOptions = { x: number; y: number; items: ActionMenuItem[]; label?: string; parent?: HTMLElement };
|
||||
export type MenuHandle = { close(restore?: boolean): void; readonly element: HTMLElement; readonly open: boolean };
|
||||
|
||||
/**
|
||||
* Show the shared action menu. It closes on a press outside it, a scroll outside it, a window resize, and window blur.
|
||||
* A choice and Escape return focus to the element that had focus. A host surface can give `restore` to return focus itself.
|
||||
*/
|
||||
export function showActionMenu(options: MenuOptions, signal?: AbortSignal, restore?: () => void): MenuHandle {
|
||||
const origin = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
// Focus can scroll a trigger before its queued scroll event reaches this menu.
|
||||
const scrollPositions = new Map<EventTarget, [number, number]>();
|
||||
for (let node: HTMLElement | null = origin; node; node = node.parentElement) {
|
||||
scrollPositions.set(node, [node.scrollLeft, node.scrollTop]);
|
||||
}
|
||||
scrollPositions.set(document, [window.scrollX, window.scrollY]);
|
||||
let open = true;
|
||||
const close = (back = false) => {
|
||||
if (!open) return;
|
||||
open = false;
|
||||
root.remove();
|
||||
window.removeEventListener("pointerdown", outside, true);
|
||||
window.removeEventListener("resize", dismiss);
|
||||
window.removeEventListener("blur", dismiss);
|
||||
document.removeEventListener("scroll", scroll, true);
|
||||
signal?.removeEventListener("abort", dismiss);
|
||||
if (!back) return;
|
||||
if (restore) restore();
|
||||
else if (origin?.isConnected) origin.focus({ preventScroll: true });
|
||||
};
|
||||
const dismiss = () => close();
|
||||
const outside = (event: PointerEvent) => { if (!root.contains(event.target as Node)) close(); };
|
||||
const scroll = (event: Event) => {
|
||||
if (root.contains(event.target as Node)) return;
|
||||
const before = event.target && scrollPositions.get(event.target);
|
||||
const current = event.target === document ? [window.scrollX, window.scrollY]
|
||||
: event.target instanceof HTMLElement ? [event.target.scrollLeft, event.target.scrollTop] : undefined;
|
||||
if (!before || !current || before[0] !== current[0] || before[1] !== current[1]) close();
|
||||
};
|
||||
const wrap = (items: ActionMenuItem[]): ActionMenuItem[] => items.map(item => "separator" in item ? item : {
|
||||
...item,
|
||||
...(item.children ? { children: wrap(item.children) } : {}),
|
||||
...(!item.children || item.run ? { run: () => { close(true); if (!signal?.aborted) item.run?.(); } } : {}),
|
||||
});
|
||||
const root = actionMenu(options.x, options.y, wrap(options.items), () => close(true), options.label ?? "Actions", options.parent);
|
||||
window.addEventListener("pointerdown", outside, true);
|
||||
window.addEventListener("resize", dismiss);
|
||||
window.addEventListener("blur", dismiss);
|
||||
document.addEventListener("scroll", scroll, true);
|
||||
signal?.addEventListener("abort", dismiss, { once: true });
|
||||
if (signal?.aborted) close();
|
||||
return { close, element: root, get open() { return open; } };
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
.rs-menu, .rs-picker {
|
||||
z-index: 1000;
|
||||
width: var(--rs-menu-width);
|
||||
max-width: calc(100vw - 16px);
|
||||
max-height: calc(100vh - 16px);
|
||||
overflow-y: auto;
|
||||
padding: var(--rs-menu-padding);
|
||||
border: 1px solid var(--rs-menu-border);
|
||||
border-radius: var(--rs-control-radius);
|
||||
background: var(--rs-menu-bg);
|
||||
backdrop-filter: var(--rs-menu-backdrop);
|
||||
color: var(--rs-text);
|
||||
box-shadow: var(--rs-menu-shadow);
|
||||
font: var(--rs-menu-font-size)/1.4 var(--rs-font-ui);
|
||||
}
|
||||
|
||||
.rs-menu { position: fixed; }
|
||||
.rs-picker { box-sizing: border-box; }
|
||||
|
||||
.rs-menu.table-cell-submenu { z-index: 1001; inset: auto; margin: 0; }
|
||||
|
||||
.rs-menu > button, .rs-picker .rs-picker-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--rs-menu-icon-gap);
|
||||
width: 100%;
|
||||
min-height: var(--rs-menu-row-height);
|
||||
padding: var(--rs-menu-row-padding);
|
||||
border: 0;
|
||||
border-radius: var(--rs-control-radius);
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Disabled rows stay readable: dim text at full opacity. */
|
||||
.rs-menu > button:disabled, .rs-picker .rs-picker-row:disabled { color: var(--rs-text-dim); cursor: default; }
|
||||
.rs-menu.rs-menu-text > button > .action-icon { display: none; }
|
||||
/* An action that removes data, such as Delete, uses the error color. */
|
||||
.rs-menu > button.danger:not(:disabled) { color: var(--rs-error); }
|
||||
/* Hover gets only the quiet fill. The current radio row shows a check mark, not a fill. */
|
||||
.rs-menu > button:not(:disabled):is(:hover, :focus-visible, [aria-expanded="true"]),
|
||||
.rs-picker .rs-picker-row:not(:disabled):is(:hover, :focus-visible, :focus-within, [aria-selected="true"], [aria-current="true"]) {
|
||||
background: var(--rs-menu-active-bg);
|
||||
outline: none;
|
||||
}
|
||||
/* Keyboard focus also gets a 2-pixel ring, so it differs from hover. */
|
||||
.rs-menu > button:not(:disabled):focus-visible, .rs-picker .rs-picker-row:not(:disabled):focus-visible {
|
||||
outline: 2px solid var(--rs-focus);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
.rs-menu > hr { margin: 4px 0; border: 0; border-top: 1px solid var(--rs-border); }
|
||||
.rs-menu > button > .action-icon, .rs-picker-icon { width: var(--rs-menu-icon-size); height: var(--rs-menu-icon-size); flex: 0 0 var(--rs-menu-icon-size); }
|
||||
.rs-picker-hint { display: block; color: var(--rs-text-dim); font-size: var(--rs-settings-description-size); }
|
||||
.rs-picker-icon > svg { width: 100%; height: 100%; }
|
||||
.rs-menu > button > .action-label { flex: 1; min-width: 0; overflow: visible; text-overflow: clip; white-space: normal; overflow-wrap: anywhere; }
|
||||
.rs-menu > button > .action-chevron { width: 13px; height: 13px; flex: 0 0 13px; }
|
||||
@@ -0,0 +1,48 @@
|
||||
import { message, tr } from "../i18n/index.ts";
|
||||
import { isMac, keys } from "./shortcuts.ts";
|
||||
import type { ActionMenuItem } from "./actionMenu.ts";
|
||||
|
||||
// The common text actions of the editor and reading menus. Each menu supplies only its commands.
|
||||
|
||||
/** The one label of the action that shows a file in the file manager of the platform. Translate it with `$t` or `tr`. */
|
||||
export function revealLabel(): string {
|
||||
if (isMac()) return message("Show in Finder");
|
||||
return typeof navigator !== "undefined" && /Windows/.test(navigator.userAgent) ? message("Show in Explorer") : message("Show in file manager");
|
||||
}
|
||||
|
||||
/** Undo and Redo, then a separator. */
|
||||
export function historyItems(history: { canUndo: boolean; canRedo: boolean; undo(): void; redo(): void }): ActionMenuItem[] {
|
||||
return [
|
||||
{ label: tr("Undo"), icon: "undo", shortcut: keys("Mod+Z"), disabled: !history.canUndo, run: history.undo },
|
||||
{ label: tr("Redo"), icon: "redo", shortcut: keys("Mod+Shift+Z"), disabled: !history.canRedo, run: history.redo },
|
||||
{ separator: true },
|
||||
];
|
||||
}
|
||||
|
||||
/** Search the workspace for the selected text. The label quotes at most 32 characters. */
|
||||
export function searchItem(text: string, search?: (text: string) => void): ActionMenuItem {
|
||||
return {
|
||||
label: text ? tr("Search for “{text}”", { text: text.length > 32 ? text.slice(0, 32) + "…" : text }) : tr("Search selection"),
|
||||
icon: "search", disabled: !text || !search, run: () => search?.(text),
|
||||
};
|
||||
}
|
||||
|
||||
export type ClipboardActions = {
|
||||
selected: boolean;
|
||||
copy(): void;
|
||||
cut?(): void;
|
||||
paste?(): void;
|
||||
pastePlain?(): void;
|
||||
selectAll?(): void;
|
||||
};
|
||||
|
||||
/** The clipboard actions in their shared order. A menu leaves out an action that it does not supply. */
|
||||
export function clipboardItems(actions: ClipboardActions): ActionMenuItem[] {
|
||||
const items: ActionMenuItem[] = [];
|
||||
if (actions.cut) items.push({ label: tr("Cut"), icon: "cut", shortcut: keys("Mod+X"), disabled: !actions.selected, run: actions.cut });
|
||||
items.push({ label: tr("Copy"), icon: "copy", shortcut: keys("Mod+C"), disabled: !actions.selected, run: actions.copy });
|
||||
if (actions.paste) items.push({ label: tr("Paste"), icon: "paste", shortcut: keys("Mod+V"), run: actions.paste });
|
||||
if (actions.pastePlain) items.push({ label: tr("Paste as plain text"), icon: "paste-text", run: actions.pastePlain });
|
||||
if (actions.selectAll) items.push({ label: tr("Select all"), icon: "select", shortcut: keys("Mod+A"), run: actions.selectAll });
|
||||
return items;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Shortcut labels for the platform: "Ctrl+Shift+P" on Windows and Linux, "⇧⌘P" on macOS.
|
||||
|
||||
/** One key combination. `mod` is Ctrl, or Cmd on macOS. `ctrl` is the Ctrl key on every platform. */
|
||||
export type Shortcut = { key: string; mod?: boolean; ctrl?: boolean; shift?: boolean; alt?: boolean };
|
||||
|
||||
export function isMac(): boolean {
|
||||
if (typeof navigator === 'undefined') return false;
|
||||
const platform = (navigator as Navigator & { userAgentData?: { platform?: string } }).userAgentData?.platform || navigator.platform || '';
|
||||
return /mac|iphone|ipad/i.test(platform);
|
||||
}
|
||||
|
||||
/** Key names as [Windows and Linux, macOS]. */
|
||||
const NAMES: Record<string, [string, string]> = {
|
||||
Escape: ['Esc', '⎋'], Enter: ['Enter', '↩'], Tab: ['Tab', '⇥'], Backspace: ['Backspace', '⌫'], Delete: ['Delete', '⌦'],
|
||||
ArrowUp: ['Up', '↑'], ArrowDown: ['Down', '↓'], ArrowLeft: ['Left', '←'], ArrowRight: ['Right', '→'], ' ': ['Space', 'Space'],
|
||||
};
|
||||
|
||||
export function shortcutLabel(shortcut: Shortcut, mac = isMac()): string {
|
||||
const name = NAMES[shortcut.key]?.[mac ? 1 : 0] ?? (shortcut.key.length === 1 ? shortcut.key.toUpperCase() : shortcut.key);
|
||||
// macOS orders the symbols Control, Option, Shift, Command. Windows orders Ctrl, Alt, Shift.
|
||||
if (mac) return `${shortcut.ctrl ? '⌃' : ''}${shortcut.alt ? '⌥' : ''}${shortcut.shift ? '⇧' : ''}${shortcut.mod ? '⌘' : ''}${name}`;
|
||||
return [shortcut.mod || shortcut.ctrl ? 'Ctrl' : '', shortcut.alt ? 'Alt' : '', shortcut.shift ? 'Shift' : '', name].filter(Boolean).join('+');
|
||||
}
|
||||
|
||||
/** The label of a written combination, such as "Mod+Shift+Z". */
|
||||
export function keys(text: string, mac = isMac()): string {
|
||||
const parts = text.split('+');
|
||||
const key = parts.pop() || '+';
|
||||
const modifiers = new Set(parts.map(part => part.toLowerCase()));
|
||||
return shortcutLabel({ key, mod: modifiers.has('mod'), ctrl: modifiers.has('ctrl'), shift: modifiers.has('shift'), alt: modifiers.has('alt') }, mac);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/* The one switch design for boolean settings: <input type="checkbox" role="switch" class="rs-switch">. */
|
||||
.rs-switch {
|
||||
appearance: none;
|
||||
position: relative;
|
||||
flex: 0 0 40px;
|
||||
width: 40px;
|
||||
height: 24px;
|
||||
margin: 0;
|
||||
border: 1px solid var(--rs-text-dim);
|
||||
border-radius: 12px;
|
||||
background: var(--rs-bg-active);
|
||||
cursor: pointer;
|
||||
transition: background .12s, border-color .12s;
|
||||
}
|
||||
|
||||
.rs-switch::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
left: 3px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 50%;
|
||||
background: var(--rs-text);
|
||||
transition: transform .12s;
|
||||
}
|
||||
|
||||
.rs-switch:checked { background: var(--rs-accent); border-color: var(--rs-accent); }
|
||||
.rs-switch:checked::before { transform: translateX(16px); background: var(--rs-on-accent); }
|
||||
/* A disabled switch keeps full opacity. Its border and knob are dim. */
|
||||
.rs-switch:disabled { cursor: default; border-color: var(--rs-border); }
|
||||
.rs-switch:disabled::before { background: var(--rs-text-dim); }
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.rs-switch, .rs-switch::before { transition: none; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/* Tooltips from tooltip.ts. */
|
||||
.rs-tooltip {
|
||||
position: fixed;
|
||||
inset: auto;
|
||||
margin: 0;
|
||||
max-width: min(280px, calc(100vw - 16px));
|
||||
padding: var(--rs-tooltip-padding);
|
||||
border: 1px solid var(--rs-border);
|
||||
border-radius: var(--rs-control-radius);
|
||||
background: var(--rs-tooltip-bg);
|
||||
color: var(--rs-tooltip-text);
|
||||
box-shadow: var(--rs-tooltip-shadow);
|
||||
font: var(--rs-tooltip-font-size)/1.5 var(--rs-font-ui);
|
||||
white-space: pre-line;
|
||||
pointer-events: none;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// The tooltip helper is part of the public plugin SDK (packages/plugin-sdk/src/tooltip.ts).
|
||||
export { attachTooltip } from "../../../packages/plugin-sdk/src/tooltip.ts";
|
||||
Reference in New Issue
Block a user