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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110// Load the actual tile modules under Node, without pulling in the browser board.import assert from 'node:assert/strict';import { readFile } from 'node:fs/promises';import { stripTypeScriptTypes } from 'node:module';
const moduleURL = (code) => `data:text/javascript;base64,${Buffer.from(code).toString('base64')}`;const boards = moduleURL(` export const tileElement = () => null, slotOf = () => null; export const CHIP = { width: 240, height: 180 }, GRAB = { x: 24, y: 16 };`);
async function tileURL(name, imports = {}) { const file = new URL(`../src/lib/tiles/${name}.ts`, import.meta.url); const ts = await readFile(file, 'utf8'); let js = stripTypeScriptTypes(ts, { mode: 'transform' }); if (name.endsWith('.svelte')) { const { compileModule } = await import('svelte/compiler'); js = compileModule(js, { filename: `${name}.js`, generate: 'client' }).js .code; } return moduleURL( js.replace(/from (['"])(.*?)\1/g, (_, _quote, specifier) => { const href = imports[specifier] ?? (specifier.startsWith('.') ? new URL(`${specifier}.ts`, file).href : import.meta.resolve(specifier)); return `from ${JSON.stringify(href)}`; }), );}
const treeURL = await tileURL('tree', { '../api': await tileURL('../api') });export const tree = await import(treeURL);export const resize = await import( await tileURL('resize', { './tree': treeURL }));
export async function loadMoves() { const imports = { './tree': treeURL, '../board.svelte': boards }; return import( await tileURL('moves', { ...imports, './focus': await tileURL('focus', imports), }) );}
export async function loadDock() { return import( await tileURL('dock.svelte', { './tree': treeURL, '../board.svelte': boards, './title': moduleURL(` export const tileTitle = () => 'tile', windowName = (id) => id, windowTitle = () => 'window'; `), }) );}
export const leaf = (window, id = `leaf-${window}`) => ({ id, kind: 'leaf', window,});export const column = (id) => ({ id: `column-${id}`, kind: 'split', axis: 'column', children: [leaf(`top-${id}`), leaf(`bottom-${id}`)], sizes: [0.5, 0.5],});export const close = (actual, expected) => assert.ok(Math.abs(actual - expected) < 1e-8, `${actual} != ${expected}`);const key = (tile) => (tile.kind === 'leaf' ? tile.window : tile.id);
// This is the browser geometry contract, not extendBeside's arithmetic: flex// distributes the split's length after fixed-size gutters are taken out.export const widths = (row, viewport) => { const content = (row.span ?? 1) * viewport; const available = content - tree.GUTTER * (row.children.length - 1); return new Map( row.children.map((child, at) => [key(child), row.sizes[at] * available]), );};
export const makeRow = (weights, span, makeChild) => { const total = weights.reduce((sum, value) => sum + value, 0); return { id: 'root', kind: 'split', axis: 'row', children: weights.map((_, at) => makeChild(at)), sizes: weights.map((value) => value / total), ...(span ? { span } : {}), };};
export function stack(id, children, heights) { const total = heights.reduce((sum, height) => sum + height, 0); return { id, kind: 'split', axis: 'column', children, sizes: heights.map((height) => height / total), };}