Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193<script lang="ts"> import type { Board } from '../board.svelte'; import TileView from './TileView.svelte'; import { measureGutter, trackResize } from './resize-grab'; import { planGutter } from './resize'; import type { Split } from './tree';
// Tiles side by side (a row) or stacked (a column). The gap between two is // the handle that resizes them, drawn as zen's desk gap is: nothing until // pointed at, then a hairline of the accent. BoardView grabs tiled gutters; // canvas and expanded splits preview their sizes locally. let { board, split }: { board: Board; split: Split } = $props();
const STEP = 0.04; let element = $state<HTMLElement>(); let live = $state.raw<number[] | null>(null); const sizes = $derived(live ?? split.sizes); const row = $derived(split.axis === 'row');
let cancelGrab: (() => void) | null = null; $effect(() => () => cancelGrab?.());
function grab(event: PointerEvent, at: number) { if (event.button !== 0 || event.buttons !== 1 || !element || cancelGrab) return; const gutter = event.currentTarget as HTMLElement; if (gutter.closest('.sizing, [inert], [hidden]')) return; const { length: measured, scale } = measureGutter(split, element, gutter); const length = measured / scale; if (!(length > 0 && Number.isFinite(length))) return; const base = board.root; const expanded = board.expanded; const start = split; const plan = planGutter(start, at, length); const horizontal = start.axis === 'row'; cancelGrab = trackResize( event, gutter, () => gutter.isConnected && board.root === base && board.expanded === expanded, (dx, dy) => (live = plan((horizontal ? dx : dy) / scale).sizes), (apply) => { const next = live; live = null; cancelGrab = null; if (apply && next && next !== start.sizes) board.resize(start.id, next); }, ); if (cancelGrab) { live = start.sizes; gutter.focus({ preventScroll: true }); } }
function nudge(event: KeyboardEvent, at: number) { const keys = row ? ['ArrowLeft', 'ArrowRight'] : ['ArrowUp', 'ArrowDown']; const by = keys.indexOf(event.key); if (by < 0 || !element) return; event.preventDefault(); const gutter = event.currentTarget as HTMLElement; if (cancelGrab || gutter.closest('.sizing')) return; const { length: measured, scale } = measureGutter(split, element, gutter); const length = measured / scale; if (!(length > 0 && Number.isFinite(length))) return; const { sizes } = planGutter( split, at, length, )((by ? STEP : -STEP) * length); if (sizes !== split.sizes) board.resize(split.id, sizes); }
function even() { const share = 1 / split.children.length; if (split.sizes.some((size) => size !== share)) board.resize( split.id, split.children.map(() => share), ); }</script>
<div class="split" class:row class:column={!row} class:resizing={live !== null} data-tile={split.id} bind:this={element}> {#each split.children as child, at (child.id)} {#if at > 0} {@const share = sizes[at - 1] / (sizes[at - 1] + sizes[at])} <!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions (a focusable separator is the ARIA window splitter) --> <div class="gutter" data-index={at - 1} role="separator" aria-orientation={row ? 'vertical' : 'horizontal'} aria-label="resize" aria-valuemin={0} aria-valuemax={100} aria-valuenow={Math.round(share * 100)} tabindex="0" onpointerdown={(event) => grab(event, at - 1)} onkeydown={(event) => nudge(event, at - 1)} ondblclick={even} ></div> {/if} <div class="part" style:flex-grow={sizes[at]}> <TileView {board} tile={child} /> </div> {/each}</div>
<style> .split { display: flex; flex: 1; width: 100%; height: 100%; min-width: 0; min-height: 0; } .column { flex-direction: column; } .resizing { user-select: none; } .resizing.row, .resizing.row :global(*) { cursor: col-resize !important; } .resizing.column, .resizing.column :global(*) { cursor: row-resize !important; } .resizing :global(iframe) { pointer-events: none; } .part { display: flex; flex-basis: 0; flex-shrink: 1; min-width: 0; min-height: 0; } .gutter { position: relative; flex: none; touch-action: none; } .row > .gutter { width: 6px; cursor: col-resize; } .column > .gutter { height: 6px; cursor: row-resize; } .gutter::after { position: absolute; background: var(--accent); border-radius: 1px; opacity: 0; content: ''; transition: opacity 120ms ease; } .row > .gutter::after { top: 30%; bottom: 30%; left: 2px; width: 2px; } .column > .gutter::after { left: 30%; right: 30%; top: 2px; height: 2px; } .gutter:hover::after, .gutter:focus-visible::after, .resizing > .gutter:active::after { opacity: 0.55; } .gutter:focus-visible { outline: none; }</style>