Initial RuneStone project

This commit is contained in:
Knotty Wyvern
2026-09-26 01:25:42 -07:00
commit bdc15e952d
190 changed files with 25986 additions and 0 deletions
+167
View File
@@ -0,0 +1,167 @@
<script lang="ts">
import type { MenuAction, MenuItem } from "./menuTypes";
type Props = {
x: number;
y: number;
items: MenuItem[];
onClose: () => void;
};
let { x, y, items, onClose }: Props = $props();
let root: HTMLElement | undefined = $state();
let left = $state(0);
let top = $state(0);
$effect(() => {
left = x;
top = y;
void items;
queueMicrotask(() => {
if (!root) {
return;
}
const rect = root.getBoundingClientRect();
left = Math.min(x, window.innerWidth - rect.width - 8);
top = Math.min(y, window.innerHeight - rect.height - 8);
});
});
function onWindowDown(event: MouseEvent) {
if (root && !root.contains(event.target as Node)) {
onClose();
}
}
function onKey(event: KeyboardEvent) {
if (event.key === "Escape") {
onClose();
}
}
function runAction(item: MenuAction) {
if (item.disabled) {
return;
}
item.run();
onClose();
}
</script>
<svelte:window onmousedown={onWindowDown} onkeydown={onKey} />
<div
bind:this={root}
class="menu"
style:left="{left}px"
style:top="{top}px"
role="menu"
>
{#each items as item, i (i)}
{#if item.kind === "sep"}
<div class="sep"></div>
{:else if item.kind === "group"}
<div class="group">
<div class="group-label" role="none">{item.label}</div>
<div class="flyout" role="menu">
{#each item.items as sub, j (`${i}-${j}`)}
{#if sub.kind === "sep"}
<div class="sep"></div>
{:else if sub.kind === "action"}
<button
type="button"
role="menuitem"
disabled={sub.disabled}
onclick={() => runAction(sub)}
>
{sub.label}
</button>
{/if}
{/each}
</div>
</div>
{:else}
<button
type="button"
role="menuitem"
disabled={item.disabled}
onclick={() => runAction(item)}
>
{item.label}
</button>
{/if}
{/each}
</div>
<style>
.menu,
.flyout {
min-width: 200px;
padding: 4px 0;
background: var(--rs-bg-elevated);
border: 1px solid var(--rs-border);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.menu {
position: fixed;
z-index: 40;
}
.group {
position: relative;
}
.group-label {
padding: 6px 12px;
color: var(--rs-text);
cursor: default;
}
.group-label::after {
content: "▸";
float: right;
color: var(--rs-text-dim);
}
.flyout {
display: none;
position: absolute;
left: 100%;
top: 0;
z-index: 41;
}
.group:hover > .flyout,
.group:focus-within > .flyout {
display: block;
}
button {
display: block;
width: 100%;
border: 0;
background: transparent;
color: var(--rs-text-strong);
text-align: left;
padding: 6px 12px;
}
button:hover,
button:focus-visible {
background: var(--rs-bg-active);
outline: none;
}
button:disabled {
color: var(--rs-text-dim);
opacity: 0.55;
}
.sep {
height: 1px;
margin: 4px 0;
background: var(--rs-border);
}
</style>