/** * Slot geometry (API §10) — the physical iframe-slot layer over a stage container * (measure + project). Slots live in the stage (imperative DOM), insulated from * React reconciliation of the hosts; only a slot's box is repositioned, so a * healthy iframe never reloads on reorder/re-key/re-parent. */ /** Viewport-space box a host projects onto its stage slot. */ export interface SlotRect { readonly top: number readonly left: number readonly width: number readonly height: number } /** * One persistent slot inside the stage. Its `element` is the mount host handed * to `shell.mount`; the element NEVER moves in the DOM while the owning host * reorders/re-keys/re-parents — only its box is repositioned via `place`. */ export interface StageSlot { readonly element: HTMLElement place(rect: SlotRect): void release(): void } export interface StageController { acquire(): StageSlot dispose(): void } /** Build the slot layer over a stage container element (imperative, no React). */ export function createStageController(container: HTMLElement): StageController { const slots = new Set() let disposed = false return { acquire() { const element = container.ownerDocument.createElement('div') element.dataset.astraleViewSlot = '' element.style.position = 'absolute' element.style.top = '0' element.style.left = '0' element.style.pointerEvents = 'auto' container.appendChild(element) slots.add(element) let released = false return { element, place(rect) { // translate + explicit box, so a reflow of the container never drifts // the slot off its anchor. element.style.transform = `translate(${rect.left}px, ${rect.top}px)` element.style.width = `${rect.width}px` element.style.height = `${rect.height}px` }, release() { if (released) return released = true slots.delete(element) element.remove() }, } }, dispose() { if (disposed) return disposed = true for (const el of slots) el.remove() slots.clear() }, } } /** Measure an anchor element's viewport box. */ export function rectOf(el: HTMLElement): SlotRect { const r = el.getBoundingClientRect() return { top: r.top, left: r.left, width: r.width, height: r.height } } export function sameRect(a: SlotRect, b: SlotRect): boolean { return a.top === b.top && a.left === b.left && a.width === b.width && a.height === b.height }