{"version":3,"names":["flush","createInputBus","InputContext","decodePasteBytes","startInput","handleInputKey","createComponent","insertNode","render","diffFrames","serializeChanges","wrapSynchronized","clearDirty","createRenderState","findHandler","hitTest","layout","paint","renderFrame","renderToAnsi","scrollBy","clearSelection","copyToClipboard","getSelectedText","terminalCaps","Node","YogaNode","getTerminalSize","cols","process","stdout","columns","rows","mount","code","options","termSize","fps","write","data","syncOutput","enableInput","altScreen","contentDriven","contentRows","prevViewportY","yogaRoot","setWidth","setHeight","root","type","props","children","parent","yogaNode","screenRect","scrollTop","dirty","_cachedText","state","hyperlinks","bus","dispose","value","findFocusedInput","node","focused","child","found","handleInputElement","key","inputNode","rawCursor","_cursorPos","length","cursorPos","Math","max","min","inputState","multiline","result","changed","onChange","submit","onSubmit","hoveredNode","handleMouseEvent","event","col","x","row","y","target","button","selection","anchor","focus","text","prevBuffer","leave","handler","enter","click","scrollContainer","overflow","delta","scroll","direction","scrollTarget","inputHandle","onKey","_dispatchKey","scheduleRender","onMouse","_dispatchMouse","onPaste","bytes","_dispatchPaste","mouse","kittyKeyboard","frameTimer","running","renderPending","renderedSinceTick","doRender","undefined","contentHeight","bottom","getComputedTop","getComputedHeight","ceil","viewportY","visibleRows","scrollDelta","heightDelta","totalLFs","repeat","oldPrev","oldRows","copyRows","srcRow","set","get","overlap","buffer","clearDirtyRows","activeHeight","dirtyRows","Set","add","changes","ansi","linksEnabled","tmp","out","syncSupported","queueMicrotask","tick","setInterval","round","onResize","size","screen","resize","on","onSignal","unmount","exit","onExit","mouseActive","input","enabled","setMouse","clearInterval","stop","off","commit","content","refresh","commitTo","tempYoga","tempRoot","idx","indexOf","splice","removeChild","free","newCols","newRows"],"sources":["screen.ts"],"sourcesContent":["/**\n * Screen: the top-level entry point that ties Solid rendering to the terminal.\n *\n * Creates a root TermNode, starts the frame scheduler, manages input,\n * and handles the terminal lifecycle (raw mode, cleanup on exit).\n *\n * Usage:\n *   const screen = mount(() => <App />, { fps: 30 })\n *   // later:\n *   screen.unmount()\n */\n\nimport type { Element as JSXElement } from \"solid-js\";\nimport { flush } from \"solid-js\";\nimport {\n\tcreateInputBus,\n\ttype InputBus,\n\ttype InputBusInternal,\n\tInputContext,\n} from \"../input/hooks.ts\";\nimport {\n\tdecodePasteBytes,\n\ttype InputHandle,\n\tstartInput,\n} from \"../input/index.ts\";\nimport { handleInputKey } from \"../input/input-handler.ts\";\nimport type { ParsedKey } from \"../input/parse-keypress.ts\";\nimport type { RawMouseEvent } from \"../input/parse-mouse.ts\";\nimport {\n\tcreateComponent,\n\tinsertNode,\n\trender,\n\ttype TermNode,\n} from \"../renderer/term-node.ts\";\nimport {\n\tdiffFrames,\n\tserializeChanges,\n\twrapSynchronized,\n} from \"./frame-buffer.ts\";\nimport {\n\tclearDirty,\n\tcreateRenderState,\n\tfindHandler,\n\thitTest,\n\tlayout,\n\tpaint,\n\trenderFrame,\n\trenderToAnsi,\n\tscrollBy,\n} from \"./pipeline.ts\";\nimport {\n\tclearSelection,\n\tcopyToClipboard,\n\tgetSelectedText,\n} from \"./selection.ts\";\nimport { terminalCaps } from \"./terminal-caps.ts\";\nimport { Node as YogaNode } from \"./yoga.ts\";\n\nexport interface ScreenOptions {\n\t/** Use alternate screen buffer (default: false — prefer primary buffer for terminal-native feel) */\n\taltScreen?: boolean;\n\t/** Terminal columns (default: stdout columns or 80) */\n\tcols?: number;\n\t/**\n\t * Content-driven height (default: false). When true, the active region\n\t * height equals the content height instead of the terminal height.\n\t * Content grows downward from the cursor position; when it exceeds the\n\t * viewport, old content scrolls into terminal scrollback via natural LFs.\n\t * This matches Claude Code / Ink's primary-screen rendering model.\n\t */\n\tcontentDriven?: boolean;\n\t/** Enable input handling (default: true) */\n\tenableInput?: boolean;\n\t/** Target frames per second (default: 30) */\n\tfps?: number;\n\t/** Enable kitty keyboard protocol (default: false) */\n\tkittyKeyboard?: boolean;\n\t/** Enable mouse tracking (default: false) */\n\tmouse?: boolean;\n\t/** Terminal rows (default: stdout rows or 24) */\n\trows?: number;\n\t/** Whether synchronized output is supported (default: false) */\n\tsyncOutput?: boolean;\n\t/** Write function (default: process.stdout.write) */\n\twrite?: (data: string) => void;\n}\n\nexport interface Screen {\n\t/**\n\t * Commit a component to scrollback above the active render region.\n\t * Renders the JSX once, writes it permanently, then disposes the tree.\n\t * Use this to \"finalize\" completed output (e.g., finished tool calls, messages).\n\t */\n\tcommit(content: () => JSXElement): void;\n\t/**\n\t * Commit a component inline — renders once, disposes reactivity, and inserts\n\t * the frozen nodes into a target parent within the viewport. Unlike commit(),\n\t * the content stays visible in the active render region and participates in\n\t * layout/paint, but has no reactive subscriptions.\n\t */\n\tcommitTo(\n\t\tcontent: () => JSXElement,\n\t\tparent: TermNode,\n\t\tanchor?: TermNode,\n\t): void;\n\t/** The input bus — for direct event subscription outside components. */\n\tinput: InputBus;\n\t/** Whether mouse tracking is currently enabled. */\n\tmouse: boolean;\n\t/** Force an immediate render (bypasses frame scheduler). */\n\trefresh(): void;\n\t/** Resize the screen. Triggers a full re-render. */\n\tresize(cols: number, rows: number): void;\n\t/** The root TermNode — available for testing/inspection. */\n\troot: TermNode;\n\t/** Enable or disable mouse tracking at runtime. */\n\tsetMouse(enabled: boolean): void;\n\t/** Stop the frame loop, dispose the Solid tree, restore terminal. */\n\tunmount(): void;\n}\n\nfunction getTerminalSize(): { cols: number; rows: number } {\n\tconst cols = process.stdout.columns ?? 80;\n\tconst rows = process.stdout.rows ?? 24;\n\treturn { cols, rows };\n}\n\nexport function mount(\n\tcode: () => JSXElement,\n\toptions: ScreenOptions = {},\n): Screen {\n\tconst termSize = getTerminalSize();\n\tlet cols = options.cols ?? termSize.cols;\n\tlet rows = options.rows ?? termSize.rows;\n\tconst fps = options.fps ?? 30;\n\tconst write = options.write ?? ((data: string) => process.stdout.write(data));\n\tconst syncOutput = options.syncOutput ?? terminalCaps.syncOutput;\n\tconst enableInput = options.enableInput ?? true;\n\tconst altScreen = options.altScreen ?? false;\n\tconst contentDriven = options.contentDriven ?? false;\n\n\t// Track content-driven state\n\tlet contentRows = 0; // visible rows on terminal (min of content, terminal)\n\tlet prevViewportY = 0; // viewport offset from previous frame\n\n\t// Create root node with yoga\n\tconst yogaRoot = new YogaNode();\n\tyogaRoot.setWidth(cols);\n\tif (!contentDriven) {\n\t\tyogaRoot.setHeight(rows);\n\t}\n\t// else: unconstrained height initially — will be set per frame\n\tconst root: TermNode = {\n\t\ttype: \"box\",\n\t\tprops: {},\n\t\tchildren: [],\n\t\tparent: null,\n\t\tyogaNode: yogaRoot,\n\t\tscreenRect: null,\n\t\tscrollTop: 0,\n\t\tdirty: true,\n\t\t_cachedText: null,\n\t};\n\n\t// Render state (double-buffered frame buffers)\n\tlet state = createRenderState(\n\t\tcols,\n\t\trows,\n\t\tsyncOutput,\n\t\tterminalCaps.hyperlinks,\n\t);\n\n\t// Input bus — shared between the input system and Solid components via context\n\tconst bus: InputBusInternal = createInputBus();\n\n\t// Mount the Solid tree with InputContext provider\n\t// In Solid 2.0, createContext() returns the provider component directly\n\tconst dispose = render(\n\t\t() =>\n\t\t\tcreateComponent(InputContext, {\n\t\t\t\tvalue: bus as InputBus,\n\t\t\t\tget children() {\n\t\t\t\t\treturn code();\n\t\t\t\t},\n\t\t\t}) as TermNode,\n\t\troot,\n\t);\n\n\t// Find the first focused <input> node in the tree\n\tfunction findFocusedInput(node: TermNode): TermNode | null {\n\t\tif (node.type === \"input\" && node.props.focused !== false) {\n\t\t\treturn node;\n\t\t}\n\t\tfor (const child of node.children) {\n\t\t\tconst found = findFocusedInput(child);\n\t\t\tif (found) return found;\n\t\t}\n\t\treturn null;\n\t}\n\n\t// Route key events to focused <input> elements\n\tfunction handleInputElement(key: ParsedKey): boolean {\n\t\tconst inputNode = findFocusedInput(root);\n\t\tif (!inputNode) return false;\n\n\t\tconst value = (inputNode.props.value as string) ?? \"\";\n\t\tconst rawCursor = (inputNode.props._cursorPos as number) ?? value.length;\n\t\t// Clamp cursor — value may have been changed externally (e.g. submit clearing)\n\t\tconst cursorPos = Math.max(0, Math.min(rawCursor, value.length));\n\t\tconst inputState = { value, cursorPos };\n\t\tconst multiline = inputNode.props.multiline as boolean | undefined;\n\n\t\tconst result = handleInputKey(key, inputState, { multiline });\n\n\t\t// Update cursor position on the node\n\t\tinputNode.props._cursorPos = result.cursorPos;\n\n\t\tif (result.changed) {\n\t\t\tconst onChange = inputNode.props.onChange as\n\t\t\t\t| ((v: string) => void)\n\t\t\t\t| undefined;\n\t\t\tonChange?.(result.value);\n\t\t}\n\t\tif (result.submit) {\n\t\t\tconst onSubmit = inputNode.props.onSubmit as\n\t\t\t\t| ((v: string) => void)\n\t\t\t\t| undefined;\n\t\t\tonSubmit?.(result.value);\n\t\t}\n\n\t\treturn result.changed || result.submit || result.cursorPos !== cursorPos;\n\t}\n\n\t// Mouse hit-testing state\n\tlet hoveredNode: TermNode | null = null;\n\n\tfunction handleMouseEvent(event: RawMouseEvent): void {\n\t\t// Mouse coords are already 0-indexed from the parser\n\t\tconst col = event.x;\n\t\tconst row = event.y;\n\t\tconst target = hitTest(root, col, row);\n\n\t\t// Text selection handling\n\t\tif (event.type === \"down\" && event.button === 0) {\n\t\t\tstate.selection.anchor = { col, row };\n\t\t\tstate.selection.focus = { col, row };\n\t\t} else if (event.type === \"drag\" && state.selection.anchor) {\n\t\t\tstate.selection.focus = { col, row };\n\t\t} else if (\n\t\t\tevent.type === \"up\" &&\n\t\t\tevent.button === 0 &&\n\t\t\tstate.selection.anchor\n\t\t) {\n\t\t\tstate.selection.focus = { col, row };\n\t\t\tconst { anchor } = state.selection;\n\t\t\tif (anchor.col === col && anchor.row === row) {\n\t\t\t\t// Click with no drag — clear selection\n\t\t\t\tclearSelection(state.selection);\n\t\t\t} else {\n\t\t\t\t// Copy selected text to clipboard via OSC 52\n\t\t\t\t// Use prevBuffer — it has the last rendered frame (buffer gets swapped)\n\t\t\t\tconst text = getSelectedText(state.prevBuffer, state.selection);\n\t\t\t\tif (text) copyToClipboard(text, write);\n\t\t\t}\n\t\t}\n\n\t\t// Enter/leave tracking\n\t\tif (event.type === \"move\" || event.type === \"drag\") {\n\t\t\tif (target !== hoveredNode) {\n\t\t\t\tif (hoveredNode) {\n\t\t\t\t\tconst leave = findHandler(hoveredNode, \"onMouseLeave\");\n\t\t\t\t\tleave?.handler(event);\n\t\t\t\t}\n\t\t\t\thoveredNode = target;\n\t\t\t\tif (target) {\n\t\t\t\t\tconst enter = findHandler(target, \"onMouseEnter\");\n\t\t\t\t\tenter?.handler(event);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Click dispatch\n\t\tif (event.type === \"up\" && target) {\n\t\t\tconst click = findHandler(target, \"onClick\");\n\t\t\tclick?.handler(event);\n\t\t}\n\n\t\t// Scroll dispatch to scroll containers\n\t\tif (event.type === \"scroll\" && target) {\n\t\t\t// Auto-scroll the nearest overflow=\"scroll\" ancestor\n\t\t\tlet scrollContainer: TermNode | null = target;\n\t\t\twhile (scrollContainer) {\n\t\t\t\tif (scrollContainer.props.overflow === \"scroll\") {\n\t\t\t\t\tconst delta = event.scroll?.direction === \"up\" ? -1 : 1;\n\t\t\t\t\tscrollBy(scrollContainer, delta);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tscrollContainer = scrollContainer.parent;\n\t\t\t}\n\t\t\t// Still fire user's onScroll handler if present\n\t\t\tconst scrollTarget = findHandler(target, \"onScroll\");\n\t\t\tif (scrollTarget) {\n\t\t\t\tscrollTarget.handler(event);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Start input handling\n\tlet inputHandle: InputHandle | null = null;\n\tif (enableInput) {\n\t\tinputHandle = startInput(\n\t\t\t{\n\t\t\t\tonKey(key) {\n\t\t\t\t\t// Clear text selection on any keypress\n\t\t\t\t\tif (state.selection.anchor) clearSelection(state.selection);\n\t\t\t\t\t// Route to focused <input> first, then dispatch to bus\n\t\t\t\t\thandleInputElement(key);\n\t\t\t\t\tbus._dispatchKey(key);\n\t\t\t\t\t// Render on next microtask — coalesces rapid keypresses\n\t\t\t\t\tscheduleRender();\n\t\t\t\t},\n\t\t\t\tonMouse(event) {\n\t\t\t\t\thandleMouseEvent(event);\n\t\t\t\t\tbus._dispatchMouse(event);\n\t\t\t\t},\n\t\t\t\tonPaste(bytes) {\n\t\t\t\t\tbus._dispatchPaste(decodePasteBytes(bytes));\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tmouse: options.mouse ?? false,\n\t\t\t\tkittyKeyboard: options.kittyKeyboard ?? terminalCaps.kittyKeyboard,\n\t\t\t},\n\t\t);\n\t}\n\n\t// Frame scheduler\n\tlet frameTimer: Timer | null = null;\n\tlet running = true;\n\tlet renderPending = false;\n\tlet renderedSinceTick = false;\n\n\t/** Flush signals and render a frame. */\n\tfunction doRender() {\n\t\tif (!running) return;\n\t\tflush();\n\n\t\tif (contentDriven) {\n\t\t\tif (!root.dirty) return;\n\n\t\t\t// ── Always unconstrained layout (CC pattern) ──\n\t\t\tyogaRoot.setHeight(undefined as unknown as number);\n\t\t\tlayout(root, cols, undefined);\n\t\t\tclearDirty(root);\n\n\t\t\t// Measure natural content height\n\t\t\tlet contentHeight = 0;\n\t\t\tfor (const child of root.children) {\n\t\t\t\tif (child.yogaNode) {\n\t\t\t\t\tconst bottom =\n\t\t\t\t\t\tchild.yogaNode.getComputedTop() +\n\t\t\t\t\t\tchild.yogaNode.getComputedHeight();\n\t\t\t\t\tif (bottom > contentHeight) contentHeight = Math.ceil(bottom);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontentHeight = Math.max(1, contentHeight);\n\n\t\t\t// Viewport: show the last `rows` rows of content\n\t\t\tconst viewportY = Math.max(0, contentHeight - rows);\n\t\t\tconst visibleRows = Math.min(contentHeight, rows);\n\n\t\t\t// ── Terminal adjustments ──\n\t\t\tconst scrollDelta = viewportY - prevViewportY;\n\t\t\tconst heightDelta = visibleRows - contentRows;\n\n\t\t\t// Growth and scroll can happen simultaneously (e.g., opening\n\t\t\t// command palette pushes content past the terminal bottom).\n\t\t\t// Total LFs = new terminal rows (heightDelta) + scroll amount.\n\t\t\tconst totalLFs = Math.max(0, heightDelta) + Math.max(0, scrollDelta);\n\t\t\tif (totalLFs > 0 && contentRows > 0) {\n\t\t\t\twrite(`\\x1b[${contentRows};1H`);\n\t\t\t\twrite(\"\\n\".repeat(totalLFs));\n\t\t\t\twrite(`\\x1b[${rows}A`);\n\t\t\t} else if (heightDelta < 0 || scrollDelta < 0) {\n\t\t\t\t// Content shrunk or viewport shifted up — clear the entire\n\t\t\t\t// old visible area so stale content (border lines, suggestion\n\t\t\t\t// text) from the previous frame doesn't linger on screen.\n\t\t\t\twrite(`\\x1b[1;1H\\x1b[0J`);\n\t\t\t}\n\n\t\t\t// ── Resize / shift prevBuffer to match terminal state after scroll ──\n\t\t\tif (visibleRows !== contentRows || scrollDelta !== 0) {\n\t\t\t\tconst oldPrev = state.prevBuffer;\n\t\t\t\tconst oldRows = state.rows;\n\t\t\t\tstate = createRenderState(\n\t\t\t\t\tcols,\n\t\t\t\t\tvisibleRows,\n\t\t\t\t\tsyncOutput,\n\t\t\t\t\tterminalCaps.hyperlinks,\n\t\t\t\t);\n\n\t\t\t\tif (scrollDelta > 0 && oldRows > 0) {\n\t\t\t\t\t// Terminal scrolled: shift prevBuffer up by scrollDelta.\n\t\t\t\t\t// After scroll, terminal row 1 has what was in old buffer row scrollDelta.\n\t\t\t\t\tconst copyRows = Math.min(oldRows - scrollDelta, visibleRows);\n\t\t\t\t\tfor (let row = 0; row < copyRows; row++) {\n\t\t\t\t\t\tconst srcRow = row + scrollDelta;\n\t\t\t\t\t\tif (srcRow >= 0 && srcRow < oldRows) {\n\t\t\t\t\t\t\tfor (let col = 0; col < cols; col++) {\n\t\t\t\t\t\t\t\tstate.prevBuffer.set(col, row, oldPrev.get(col, srcRow));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (scrollDelta === 0 && heightDelta >= 0) {\n\t\t\t\t\t// No scroll, just grew: copy overlapping rows\n\t\t\t\t\tconst overlap = Math.min(oldRows, visibleRows);\n\t\t\t\t\tfor (let row = 0; row < overlap; row++) {\n\t\t\t\t\t\tfor (let col = 0; col < cols; col++) {\n\t\t\t\t\t\t\tstate.prevBuffer.set(col, row, oldPrev.get(col, row));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// For shrinking (heightDelta < 0) or unscroll (scrollDelta < 0),\n\t\t\t\t// prevBuffer starts blank → full repaint. Sync output masks flicker.\n\t\t\t}\n\n\t\t\tcontentRows = visibleRows;\n\t\t\tprevViewportY = viewportY;\n\n\t\t\t// ── Paint with viewport offset → only visible content in buffer ──\n\t\t\tstate.buffer.clearDirtyRows();\n\t\t\tpaint(root, state.buffer, 0, -viewportY);\n\t\t\tstate.activeHeight = state.buffer.contentHeight();\n\n\t\t\tconst dirtyRows = new Set(state.buffer.dirtyRows);\n\t\t\tfor (const row of state.prevBuffer.dirtyRows) dirtyRows.add(row);\n\t\t\tconst changes = diffFrames(state.prevBuffer, state.buffer, dirtyRows);\n\t\t\tconst ansi = serializeChanges(changes, undefined, state.linksEnabled);\n\t\t\tconst tmp = state.prevBuffer;\n\t\t\tstate.prevBuffer = state.buffer;\n\t\t\tstate.buffer = tmp;\n\t\t\tif (ansi) {\n\t\t\t\tconst out = state.syncSupported ? wrapSynchronized(ansi) : ansi;\n\t\t\t\twrite(out);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst ansi = renderFrame(root, state);\n\t\tif (ansi) write(ansi);\n\t}\n\n\t/** Schedule a render on the next microtask (coalesces rapid input). */\n\tfunction scheduleRender() {\n\t\tif (renderPending) return;\n\t\trenderPending = true;\n\t\tqueueMicrotask(() => {\n\t\t\trenderPending = false;\n\t\t\tif (!running) return;\n\t\t\trenderedSinceTick = true;\n\t\t\tdoRender();\n\t\t});\n\t}\n\n\tfunction tick() {\n\t\tif (!running) return;\n\t\tif (renderedSinceTick) {\n\t\t\trenderedSinceTick = false;\n\t\t\treturn;\n\t\t}\n\t\tdoRender();\n\t}\n\n\tframeTimer = setInterval(tick, Math.round(1000 / fps));\n\n\tif (altScreen) {\n\t\twrite(\"\\x1b[?1049h\\x1b[?25l\");\n\t} else if (contentDriven) {\n\t\t// Content-driven: scroll viewport to guarantee content starts at row 1.\n\t\t// Same as CC/Ink's primary-screen setup — CUP (absolute positioning)\n\t\t// in serializeChanges relies on content at row 1.\n\t\twrite(`${\"\\n\".repeat(rows)}\\x1b[${rows}A\\x1b[0J\\x1b[?25l`);\n\t} else {\n\t\t// Scroll terminal to make clean space, clear it, hide cursor\n\t\twrite(`${\"\\n\".repeat(rows)}\\x1b[${rows}A\\x1b[0J\\x1b[?25l`);\n\t}\n\n\t// Initial render\n\ttick();\n\n\t// Handle terminal resize\n\tconst onResize = () => {\n\t\tconst size = getTerminalSize();\n\t\tscreen.resize(size.cols, size.rows);\n\t};\n\tprocess.stdout.on(\"resize\", onResize);\n\n\t// Safety net: restore terminal on unexpected exit\n\tconst onSignal = () => {\n\t\tscreen.unmount();\n\t\tprocess.exit();\n\t};\n\tconst onExit = () => {\n\t\tscreen.unmount();\n\t};\n\tprocess.on(\"SIGINT\", onSignal);\n\tprocess.on(\"SIGTERM\", onSignal);\n\tprocess.on(\"exit\", onExit);\n\n\tlet mouseActive = options.mouse ?? false;\n\n\tconst screen: Screen = {\n\t\troot,\n\t\tinput: bus,\n\t\tget mouse() {\n\t\t\treturn mouseActive;\n\t\t},\n\t\tset mouse(enabled: boolean) {\n\t\t\tscreen.setMouse(enabled);\n\t\t},\n\n\t\tsetMouse(enabled: boolean) {\n\t\t\tif (enabled === mouseActive) return;\n\t\t\tmouseActive = enabled;\n\t\t\tif (enabled) {\n\t\t\t\twrite(\"\\x1b[?1006h\\x1b[?1003h\");\n\t\t\t} else {\n\t\t\t\twrite(\"\\x1b[?1003l\\x1b[?1006l\");\n\t\t\t}\n\t\t},\n\n\t\tunmount() {\n\t\t\tif (!running) return;\n\t\t\trunning = false;\n\t\t\tif (frameTimer) {\n\t\t\t\tclearInterval(frameTimer);\n\t\t\t\tframeTimer = null;\n\t\t\t}\n\t\t\tinputHandle?.stop();\n\t\t\tinputHandle = null;\n\t\t\tif (mouseActive) {\n\t\t\t\twrite(\"\\x1b[?1003l\\x1b[?1006l\");\n\t\t\t\tmouseActive = false;\n\t\t\t}\n\t\t\tdispose();\n\t\t\tprocess.stdout.off(\"resize\", onResize);\n\t\t\tprocess.off(\"SIGINT\", onSignal);\n\t\t\tprocess.off(\"SIGTERM\", onSignal);\n\t\t\tprocess.off(\"exit\", onExit);\n\t\t\tif (altScreen) {\n\t\t\t\t// Leave alternate screen buffer + restore cursor\n\t\t\t\twrite(\"\\x1b[?25h\\x1b[?1049l\");\n\t\t\t} else {\n\t\t\t\t// Restore the terminal's native cursor\n\t\t\t\twrite(\"\\x1b[?25h\");\n\t\t\t}\n\t\t},\n\n\t\tcommit(content: () => JSXElement) {\n\t\t\tif (altScreen) return; // alt-screen has no scrollback\n\n\t\t\t// 1. Render the component to ANSI\n\t\t\tconst { ansi } = renderToAnsi(content, cols, terminalCaps.hyperlinks);\n\n\t\t\t// 2. Erase the active region from the viewport\n\t\t\twrite(\"\\x1b[1;1H\\x1b[0J\\x1b[0m\");\n\n\t\t\t// 3. Write rendered content at the viewport top\n\t\t\twrite(ansi);\n\n\t\t\t// 4. Push committed content into scrollback\n\t\t\twrite(\"\\n\".repeat(rows));\n\t\t\twrite(\"\\x1b[H\");\n\n\t\t\t// 5. Reset frame buffers and repaint\n\t\t\troot.dirty = true;\n\t\t\tstate = createRenderState(\n\t\t\t\tcols,\n\t\t\t\trows,\n\t\t\t\tsyncOutput,\n\t\t\t\tterminalCaps.hyperlinks,\n\t\t\t);\n\t\t\tscreen.refresh();\n\t\t},\n\n\t\tcommitTo(content: () => JSXElement, parent: TermNode, anchor?: TermNode) {\n\t\t\t// Render content in an isolated Solid root\n\t\t\tconst tempYoga = new YogaNode();\n\t\t\ttempYoga.setWidth(cols);\n\t\t\tconst tempRoot: TermNode = {\n\t\t\t\ttype: \"box\",\n\t\t\t\tprops: {},\n\t\t\t\tchildren: [],\n\t\t\t\tparent: null,\n\t\t\t\tyogaNode: tempYoga,\n\t\t\t\tscreenRect: null,\n\t\t\t\tscrollTop: 0,\n\t\t\t\tdirty: true,\n\t\t\t\t_cachedText: null,\n\t\t\t};\n\n\t\t\tconst dispose = render(content, tempRoot);\n\n\t\t\t// Dispose reactivity — effects die, nodes remain frozen\n\t\t\tdispose();\n\n\t\t\t// Move children from temp root into target parent\n\t\t\tconst children = [...tempRoot.children];\n\t\t\tfor (const child of children) {\n\t\t\t\t// Detach from temp root\n\t\t\t\tconst idx = tempRoot.children.indexOf(child);\n\t\t\t\ttempRoot.children.splice(idx, 1);\n\t\t\t\tif (tempRoot.yogaNode && child.yogaNode) {\n\t\t\t\t\ttempRoot.yogaNode.removeChild(child.yogaNode);\n\t\t\t\t}\n\t\t\t\tchild.parent = null;\n\n\t\t\t\t// Insert into target parent via renderer (handles yoga reparenting + markDirty)\n\t\t\t\tinsertNode(parent, child, anchor);\n\t\t\t}\n\n\t\t\ttempYoga.free();\n\t\t\tscreen.refresh();\n\t\t},\n\n\t\trefresh() {\n\t\t\tdoRender();\n\t\t},\n\n\t\tresize(newCols: number, newRows: number) {\n\t\t\tif (newCols < 1 || newRows < 1) return;\n\t\t\tclearSelection(state.selection);\n\t\t\tcols = newCols;\n\t\t\trows = newRows;\n\t\t\tyogaRoot.setWidth(cols);\n\t\t\tif (!contentDriven) {\n\t\t\t\tyogaRoot.setHeight(rows);\n\t\t\t} else {\n\t\t\t\t// Content-driven: reset viewport tracking on resize\n\t\t\t\tcontentRows = 0;\n\t\t\t\tprevViewportY = 0;\n\t\t\t}\n\t\t\troot.dirty = true;\n\t\t\tstate = createRenderState(\n\t\t\t\tcols,\n\t\t\t\tcontentDriven ? 1 : rows,\n\t\t\t\tsyncOutput,\n\t\t\t\tterminalCaps.hyperlinks,\n\t\t\t);\n\t\t\t// Clear the entire viewport to avoid ghost artifacts when terminal grows\n\t\t\tif (!altScreen) {\n\t\t\t\twrite(`\\x1b[H\\x1b[0J`);\n\t\t\t}\n\t\t\tscreen.refresh();\n\t\t},\n\t};\n\n\treturn screen;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,KAAK,QAAQ,UAAU;AAChC,SACCC,cAAc,EAGdC,YAAY,QACN,mBAAmB;AAC1B,SACCC,gBAAgB,EAEhBC,UAAU,QACJ,mBAAmB;AAC1B,SAASC,cAAc,QAAQ,2BAA2B;AAG1D,SACCC,eAAe,EACfC,UAAU,EACVC,MAAM,QAEA,0BAA0B;AACjC,SACCC,UAAU,EACVC,gBAAgB,EAChBC,gBAAgB,QACV,mBAAmB;AAC1B,SACCC,UAAU,EACVC,iBAAiB,EACjBC,WAAW,EACXC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,WAAW,EACXC,YAAY,EACZC,QAAQ,QACF,eAAe;AACtB,SACCC,cAAc,EACdC,eAAe,EACfC,eAAe,QACT,gBAAgB;AACvB,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,IAAI,IAAIC,QAAQ,QAAQ,WAAW;AAiE5C,SAASC,eAAeA,CAAA,EAAmC;EAC1D,MAAMC,IAAI,GAAGC,OAAO,CAACC,MAAM,CAACC,OAAO,IAAI,EAAE;EACzC,MAAMC,IAAI,GAAGH,OAAO,CAACC,MAAM,CAACE,IAAI,IAAI,EAAE;EACtC,OAAO;IAAEJ,IAAI;IAAEI;EAAK,CAAC;AACtB;AAEA,OAAO,SAASC,KAAKA,CACpBC,IAAsB,EACtBC,OAAsB,GAAG,CAAC,CAAC,EAClB;EACT,MAAMC,QAAQ,GAAGT,eAAe,CAAC,CAAC;EAClC,IAAIC,IAAI,GAAGO,OAAO,CAACP,IAAI,IAAIQ,QAAQ,CAACR,IAAI;EACxC,IAAII,IAAI,GAAGG,OAAO,CAACH,IAAI,IAAII,QAAQ,CAACJ,IA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