{"version":3,"names":["render","Attr","color","diffFrames","FrameBuffer","NO_COLOR","serializeChanges","wrapSynchronized","applySelectionOverlay","createSelection","Align","Direction","Display","Edge","FlexDirection","Gutter","Justify","MeasureMode","Overflow","PositionType","Wrap","Node","YogaNode","FLEX_DIR_MAP","row","Row","column","Column","RowReverse","ColumnReverse","ALIGN_MAP","auto","Auto","FlexStart","center","Center","FlexEnd","stretch","Stretch","baseline","Baseline","JUSTIFY_MAP","SpaceBetween","SpaceAround","SpaceEvenly","WRAP_MAP","nowrap","NoWrap","wrap","WrapReverse","applyProps","node","yoga","yogaNode","p","props","flexDirection","undefined","setFlexDirection","flexGrow","setFlexGrow","flexShrink","setFlexShrink","flexBasis","setFlexBasis","flexWrap","setFlexWrap","alignItems","setAlignItems","alignSelf","setAlignSelf","justifyContent","setJustifyContent","width","setWidth","height","setHeight","minWidth","setMinWidth","minHeight","setMinHeight","maxWidth","setMaxWidth","maxHeight","setMaxHeight","padding","setPadding","All","paddingTop","Top","paddingBottom","Bottom","paddingLeft","Left","paddingRight","Right","margin","setMargin","marginTop","marginBottom","marginLeft","marginRight","gap","setGap","borderStyle","setBorder","overflow","overflowMap","visible","Visible","hidden","Hidden","scroll","Scroll","setOverflow","display","setDisplay","None","Flex","position","posMap","relative","Relative","absolute","Absolute","setPositionType","top","setPosition","bottom","left","right","propColor","key","v","collectText","_cachedText","result","child","children","type","content","setupMeasureFunctions","dirty","measureFunc","setMeasureFunc","widthMode","_height","_heightMode","Undefined","Number","POSITIVE_INFINITY","sourceLines","split","mw","Math","floor","maxLineWidth","line","lw","Bun","stringWidth","max","wrapAnsi","length","min","value","placeholder","ceil","layout","root","applyAllProps","calculateLayout","LTR","truncateLine","mode","lineWidth","sliceAnsi","rightCols","startOffset","half","rightStart","BORDER_CHARS","single","tl","tr","bl","br","h","double","round","bold","cursorToRowCol","cursorPos","colWidth","col","i","w","rowColToCursor","targetRow","targetCol","paintInput","buf","x","y","clip","focused","rawCursor","_cursorPos","fg","bg","placeholderFg","startCol","startRow","maxRow","rows","wrapped","lines","writeString","cur","curRow","curCol","charAtCursor","cols","get","char","Inverse","phFg","truncated","Dim","first","resolveAttrs","attrs","Bold","dim","italic","Italic","underline","Underline","inverse","strikethrough","Strikethrough","applyColorField","field","x0","y0","x1","y1","cell","dirtyRows","add","paint","offsetX","offsetY","getComputedLeft","getComputedTop","getComputedWidth","getComputedHeight","screenRect","bw","bh","bgColor","fillRect","hasBorder","isHorizontal","chars","borderFg","hBar","repeat","r","border","innerClip","scrollY","scrollTop","colorField","wrapMode","srcLine","wLine","href","getScrollHeight","maxBottom","scrollTo","viewportHeight","borderTop","getComputedBorder","borderBottom","contentHeight","maxScroll","scrollBy","delta","scrollToBottom","Infinity","hitTest","rect","hit","findHandler","prop","current","handler","parent","createRenderState","syncSupported","linksEnabled","activeHeight","buffer","prevBuffer","selection","clearDirty","renderFrame","state","clearDirtyRows","anchor","focus","Set","changes","ansi","tmp","renderContentDriven","terminalRows","prevHeight","heightDelta","growing","shrinking","cursorAtBottom","prevHadScrollback","viewportY","out","linesToClear","remaining","renderToAnsi","code","yogaRoot","dispose","contentRows","empty","free"],"sources":["pipeline.ts"],"sourcesContent":["/**\n * Render pipeline: TermNode tree → Yoga layout → FrameBuffer → ANSI output.\n *\n * Connects the Solid reactive tree to terminal output:\n * 1. applyProps() maps JSX props to yoga layout properties\n * 2. setupTextMeasure() wires Bun.stringWidth into yoga measure functions\n * 3. layout() runs yoga calculateLayout on the tree\n * 4. paint() renders positioned nodes into a FrameBuffer\n * 5. renderFrame() diffs + serializes to an ANSI string\n */\n\nimport { render, type TermNode } from \"../renderer/term-node.ts\";\nimport {\n\tAttr,\n\ttype ClipRect,\n\tcolor,\n\tdiffFrames,\n\tFrameBuffer,\n\tNO_COLOR,\n\tserializeChanges,\n\twrapSynchronized,\n} from \"./frame-buffer.ts\";\nimport {\n\tapplySelectionOverlay,\n\tcreateSelection,\n\ttype SelectionState,\n} from \"./selection.ts\";\nimport {\n\tAlign,\n\tDirection,\n\tDisplay,\n\tEdge,\n\tFlexDirection,\n\tGutter,\n\tJustify,\n\tMeasureMode,\n\tOverflow,\n\tPositionType,\n\tWrap,\n\tNode as YogaNode,\n} from \"./yoga.ts\";\n\n// --- Prop → Yoga mapping ---\n\nconst FLEX_DIR_MAP: Record<string, FlexDirection> = {\n\trow: FlexDirection.Row,\n\tcolumn: FlexDirection.Column,\n\t\"row-reverse\": FlexDirection.RowReverse,\n\t\"column-reverse\": FlexDirection.ColumnReverse,\n};\n\nconst ALIGN_MAP: Record<string, Align> = {\n\tauto: Align.Auto,\n\t\"flex-start\": Align.FlexStart,\n\tcenter: Align.Center,\n\t\"flex-end\": Align.FlexEnd,\n\tstretch: Align.Stretch,\n\tbaseline: Align.Baseline,\n};\n\nconst JUSTIFY_MAP: Record<string, Justify> = {\n\t\"flex-start\": Justify.FlexStart,\n\tcenter: Justify.Center,\n\t\"flex-end\": Justify.FlexEnd,\n\t\"space-between\": Justify.SpaceBetween,\n\t\"space-around\": Justify.SpaceAround,\n\t\"space-evenly\": Justify.SpaceEvenly,\n};\n\nconst WRAP_MAP: Record<string, (typeof Wrap)[keyof typeof Wrap]> = {\n\tnowrap: Wrap.NoWrap,\n\twrap: Wrap.Wrap,\n\t\"wrap-reverse\": Wrap.WrapReverse,\n};\n\n/** Apply a TermNode's props to its yoga node. */\nexport function applyProps(node: TermNode): void {\n\tconst yoga = node.yogaNode;\n\tif (!yoga) return;\n\tconst p = node.props;\n\n\t// Flex container\n\tif (p.flexDirection !== undefined)\n\t\tyoga.setFlexDirection(\n\t\t\tFLEX_DIR_MAP[p.flexDirection as string] ?? FlexDirection.Column,\n\t\t);\n\tif (p.flexGrow !== undefined) yoga.setFlexGrow(p.flexGrow as number);\n\tif (p.flexShrink !== undefined) yoga.setFlexShrink(p.flexShrink as number);\n\tif (p.flexBasis !== undefined) yoga.setFlexBasis(p.flexBasis as number);\n\tif (p.flexWrap !== undefined)\n\t\tyoga.setFlexWrap(WRAP_MAP[p.flexWrap as string] ?? Wrap.NoWrap);\n\tif (p.alignItems !== undefined)\n\t\tyoga.setAlignItems(ALIGN_MAP[p.alignItems as string] ?? Align.Stretch);\n\tif (p.alignSelf !== undefined)\n\t\tyoga.setAlignSelf(ALIGN_MAP[p.alignSelf as string] ?? Align.Auto);\n\tif (p.justifyContent !== undefined)\n\t\tyoga.setJustifyContent(\n\t\t\tJUSTIFY_MAP[p.justifyContent as string] ?? Justify.FlexStart,\n\t\t);\n\n\t// Dimensions\n\tif (p.width !== undefined) yoga.setWidth(p.width as number);\n\tif (p.height !== undefined) yoga.setHeight(p.height as number);\n\tif (p.minWidth !== undefined) yoga.setMinWidth(p.minWidth as number);\n\tif (p.minHeight !== undefined) yoga.setMinHeight(p.minHeight as number);\n\tif (p.maxWidth !== undefined) yoga.setMaxWidth(p.maxWidth as number);\n\tif (p.maxHeight !== undefined) yoga.setMaxHeight(p.maxHeight as number);\n\n\t// Padding\n\tif (p.padding !== undefined) yoga.setPadding(Edge.All, p.padding as number);\n\tif (p.paddingTop !== undefined)\n\t\tyoga.setPadding(Edge.Top, p.paddingTop as number);\n\tif (p.paddingBottom !== undefined)\n\t\tyoga.setPadding(Edge.Bottom, p.paddingBottom as number);\n\tif (p.paddingLeft !== undefined)\n\t\tyoga.setPadding(Edge.Left, p.paddingLeft as number);\n\tif (p.paddingRight !== undefined)\n\t\tyoga.setPadding(Edge.Right, p.paddingRight as number);\n\n\t// Margin\n\tif (p.margin !== undefined) yoga.setMargin(Edge.All, p.margin as number);\n\tif (p.marginTop !== undefined)\n\t\tyoga.setMargin(Edge.Top, p.marginTop as number);\n\tif (p.marginBottom !== undefined)\n\t\tyoga.setMargin(Edge.Bottom, p.marginBottom as number);\n\tif (p.marginLeft !== undefined)\n\t\tyoga.setMargin(Edge.Left, p.marginLeft as number);\n\tif (p.marginRight !== undefined)\n\t\tyoga.setMargin(Edge.Right, p.marginRight as number);\n\n\t// Gap\n\tif (p.gap !== undefined) yoga.setGap(Gutter.All, p.gap as number);\n\n\t// Borders — reserve cells for border characters\n\tif (p.borderStyle !== undefined && p.borderStyle !== \"none\") {\n\t\tif (p.borderStyle === \"horizontal\") {\n\t\t\tyoga.setBorder(Edge.Top, 1);\n\t\t\tyoga.setBorder(Edge.Bottom, 1);\n\t\t} else {\n\t\t\tyoga.setBorder(Edge.All, 1);\n\t\t}\n\t}\n\n\t// Overflow\n\tif (p.overflow !== undefined) {\n\t\tconst overflowMap: Record<string, Overflow> = {\n\t\t\tvisible: Overflow.Visible,\n\t\t\thidden: Overflow.Hidden,\n\t\t\tscroll: Overflow.Scroll,\n\t\t};\n\t\tyoga.setOverflow(overflowMap[p.overflow as string] ?? Overflow.Visible);\n\t}\n\n\t// Display\n\tif (p.display !== undefined)\n\t\tyoga.setDisplay(p.display === \"none\" ? Display.None : Display.Flex);\n\n\t// Position\n\tif (p.position !== undefined) {\n\t\tconst posMap: Record<string, PositionType> = {\n\t\t\trelative: PositionType.Relative,\n\t\t\tabsolute: PositionType.Absolute,\n\t\t};\n\t\tyoga.setPositionType(posMap[p.position as string] ?? PositionType.Relative);\n\t}\n\tif (p.top !== undefined) yoga.setPosition(Edge.Top, p.top as number | string);\n\tif (p.bottom !== undefined)\n\t\tyoga.setPosition(Edge.Bottom, p.bottom as number | string);\n\tif (p.left !== undefined)\n\t\tyoga.setPosition(Edge.Left, p.left as number | string);\n\tif (p.right !== undefined)\n\t\tyoga.setPosition(Edge.Right, p.right as number | string);\n}\n\n// --- Prop helpers ---\n\n/** Extract a color prop value, returning NO_COLOR if unset. */\nfunction propColor(props: Record<string, unknown>, key: string): number {\n\tconst v = props[key];\n\tif (v == null) return NO_COLOR;\n\treturn color(v as Bun.ColorInput);\n}\n\n// --- Text measurement ---\n\n/** Collect text content from a text node's children. Cached on the node. */\nexport function collectText(node: TermNode): string {\n\tif (node._cachedText !== null) return node._cachedText;\n\tlet result = \"\";\n\tfor (const child of node.children) {\n\t\tif (child.type === \"_text\") {\n\t\t\tresult += (child.props.content as string) ?? \"\";\n\t\t} else if (child.type !== \"_slot\") {\n\t\t\tresult += collectText(child);\n\t\t}\n\t}\n\tnode._cachedText = result;\n\treturn result;\n}\n\n/**\n * Set up yoga measure functions for text nodes in the tree.\n * Must be called after the tree is built but before layout.\n */\nexport function setupMeasureFunctions(node: TermNode): void {\n\tif (!node.dirty) return; // clean subtree — no new text/input nodes\n\tif ((node.type === \"text\" || node.type === \"hyperlink\") && node.yogaNode) {\n\t\tif (node.yogaNode.measureFunc) {\n\t\t\t// Already installed — closure reads from node dynamically, no need to replace\n\t\t\tfor (const child of node.children) setupMeasureFunctions(child);\n\t\t\treturn;\n\t\t}\n\t\tnode.yogaNode.setMeasureFunc(\n\t\t\t(\n\t\t\t\twidth: number,\n\t\t\t\twidthMode: MeasureMode,\n\t\t\t\t_height: number,\n\t\t\t\t_heightMode: MeasureMode,\n\t\t\t) => {\n\t\t\t\tconst content = collectText(node);\n\t\t\t\tif (!content) return { width: 0, height: 0 };\n\n\t\t\t\tconst maxWidth =\n\t\t\t\t\twidthMode === MeasureMode.Undefined\n\t\t\t\t\t\t? Number.POSITIVE_INFINITY\n\t\t\t\t\t\t: width;\n\n\t\t\t\tconst sourceLines = content.split(\"\\n\");\n\t\t\t\tconst mw = Math.floor(maxWidth);\n\t\t\t\tlet maxLineWidth = 0;\n\t\t\t\tlet height = 0;\n\t\t\t\tfor (const line of sourceLines) {\n\t\t\t\t\tconst lw = Bun.stringWidth(line);\n\t\t\t\t\tmaxLineWidth = Math.max(maxLineWidth, lw);\n\t\t\t\t\tif (mw > 0 && mw < Number.POSITIVE_INFINITY && lw > mw) {\n\t\t\t\t\t\t// Use Bun.wrapAnsi to count lines — matches paint's word-wrap\n\t\t\t\t\t\theight += Bun.wrapAnsi(line, mw).split(\"\\n\").length;\n\t\t\t\t\t} else {\n\t\t\t\t\t\theight += 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn { width: Math.min(maxLineWidth, mw), height };\n\t\t\t},\n\t\t);\n\t} else if (node.type === \"input\" && node.yogaNode) {\n\t\tif (node.yogaNode.measureFunc) {\n\t\t\tfor (const child of node.children) setupMeasureFunctions(child);\n\t\t\treturn;\n\t\t}\n\t\tnode.yogaNode.setMeasureFunc(\n\t\t\t(\n\t\t\t\twidth: number,\n\t\t\t\twidthMode: MeasureMode,\n\t\t\t\t_height: number,\n\t\t\t\t_heightMode: MeasureMode,\n\t\t\t) => {\n\t\t\t\tconst value = (node.props.value as string) ?? \"\";\n\t\t\t\tconst placeholder = (node.props.placeholder as string) ?? \"\";\n\t\t\t\tconst display = value || placeholder;\n\t\t\t\tif (!display) return { width: 1, height: 1 }; // cursor only\n\n\t\t\t\tconst maxWidth =\n\t\t\t\t\twidthMode === MeasureMode.Undefined\n\t\t\t\t\t\t? Number.POSITIVE_INFINITY\n\t\t\t\t\t\t: width;\n\n\t\t\t\t// Measure per-line (not Bun.wrapAnsi which strips trailing spaces)\n\t\t\t\tconst sourceLines = display.split(\"\\n\");\n\t\t\t\tconst mw = Math.floor(maxWidth);\n\t\t\t\tlet maxLineWidth = 0;\n\t\t\t\tlet height = 0;\n\t\t\t\tfor (const line of sourceLines) {\n\t\t\t\t\tconst lw = Bun.stringWidth(line);\n\t\t\t\t\tmaxLineWidth = Math.max(maxLineWidth, lw);\n\t\t\t\t\theight += mw > 0 ? Math.max(1, Math.ceil(lw / mw)) : 1;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\twidth: Math.min(maxLineWidth, mw) + 1, // +1 for cursor\n\t\t\t\t\theight,\n\t\t\t\t};\n\t\t\t},\n\t\t);\n\t}\n\n\tfor (const child of node.children) {\n\t\tsetupMeasureFunctions(child);\n\t}\n}\n\n// --- Layout ---\n\n/** Apply props and calculate layout for the entire tree. */\nexport function layout(root: TermNode, width: number, height?: number): void {\n\tapplyAllProps(root);\n\tsetupMeasureFunctions(root);\n\troot.yogaNode?.calculateLayout(width, height, Direction.LTR);\n}\n\nfunction applyAllProps(node: TermNode): void {\n\tif (!node.dirty) return; // clean subtree — no props changed\n\tapplyProps(node);\n\tfor (const child of node.children) {\n\t\tapplyAllProps(child);\n\t}\n}\n\n// --- Text truncation ---\n\n/** Truncate a single line to fit within `maxWidth` columns. */\nfunction truncateLine(line: string, maxWidth: number, mode: string): string {\n\tconst lineWidth = Bun.stringWidth(line);\n\tif (lineWidth <= maxWidth) return line;\n\tif (maxWidth <= 0) return \"\";\n\n\tswitch (mode) {\n\t\tcase \"truncate\":\n\t\tcase \"truncate-end\":\n\t\t\treturn `${Bun.sliceAnsi(line, 0, maxWidth - 1)}…`;\n\t\tcase \"truncate-start\": {\n\t\t\t// Show the tail of the line with ellipsis at start\n\t\t\tconst rightCols = maxWidth - 1;\n\t\t\tconst startOffset = Bun.stringWidth(line) - rightCols;\n\t\t\treturn `…${Bun.sliceAnsi(line, Math.max(0, startOffset))}`;\n\t\t}\n\t\tcase \"truncate-middle\": {\n\t\t\tconst half = Math.floor((maxWidth - 1) / 2);\n\t\t\tconst left = Bun.sliceAnsi(line, 0, half);\n\t\t\tconst rightCols = maxWidth - 1 - half;\n\t\t\tconst rightStart = Bun.stringWidth(line) - rightCols;\n\t\t\treturn `${left}…${Bun.sliceAnsi(line, Math.max(0, rightStart))}`;\n\t\t}\n\t\tdefault:\n\t\t\treturn Bun.sliceAnsi(line, 0, maxWidth);\n\t}\n}\n\n// --- Border characters ---\n\nconst BORDER_CHARS = {\n\tsingle: { tl: \"┌\", tr: \"┐\", bl: \"└\", br: \"┘\", h: \"─\", v: \"│\" },\n\tdouble: { tl: \"╔\", tr: \"╗\", bl: \"╚\", br: \"╝\", h: \"═\", v: \"║\" },\n\tround: { tl: \"╭\", tr: \"╮\", bl: \"╰\", br: \"╯\", h: \"─\", v: \"│\" },\n\tbold: { tl: \"┏\", tr: \"┓\", bl: \"┗\", br: \"┛\", h: \"━\", v: \"┃\" },\n} as const;\n\n// --- Paint: layout tree → frame buffer ---\n\n/**\n * Compute cursor row and column within a multi-line wrapped string.\n * cursorPos is the character offset in the original (unwrapped) value.\n *\n * Walks the original value character-by-character instead of relying on\n * Bun.wrapAnsi, which strips trailing spaces and would cause the cursor\n * to not advance when the user types a space.\n */\nfunction cursorToRowCol(\n\tvalue: string,\n\tcursorPos: number,\n\tcolWidth: number,\n): { row: number; col: number } {\n\tif (colWidth <= 0) return { row: 0, col: cursorPos };\n\n\tlet row = 0;\n\tlet col = 0;\n\n\tfor (let i = 0; i < cursorPos && i < value.length; i++) {\n\t\tif (value[i] === \"\\n\") {\n\t\t\trow++;\n\t\t\tcol = 0;\n\t\t} else {\n\t\t\tconst w = Bun.stringWidth(value[i] ?? \"\");\n\t\t\tif (col + w > colWidth) {\n\t\t\t\trow++;\n\t\t\t\tcol = w;\n\t\t\t} else {\n\t\t\t\tcol += w;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { row, col };\n}\n\n/**\n * Inverse of cursorToRowCol — convert a (row, col) screen position\n * to a character offset in the value string. Clamps to value.length\n * if the click is past the end of the text.\n */\nexport function rowColToCursor(\n\tvalue: string,\n\ttargetRow: number,\n\ttargetCol: number,\n\tcolWidth: number,\n): number {\n\tif (colWidth <= 0) return Math.min(targetCol, value.length);\n\n\tlet row = 0;\n\tlet col = 0;\n\n\tfor (let i = 0; i < value.length; i++) {\n\t\t// If we've reached the target row and are at or past the target column\n\t\tif (row === targetRow && col >= targetCol) return i;\n\t\t// If we've passed the target row, return start of this position\n\t\tif (row > targetRow) return i;\n\n\t\tif (value[i] === \"\\n\") {\n\t\t\tif (row === targetRow) return i; // clicked past end of this line\n\t\t\trow++;\n\t\t\tcol = 0;\n\t\t} else {\n\t\t\tconst w = Bun.stringWidth(value[i] ?? \"\");\n\t\t\tif (col + w > colWidth) {\n\t\t\t\tif (row === targetRow) return i; // clicked past end of wrapped line\n\t\t\t\trow++;\n\t\t\t\tcol = w;\n\t\t\t} else {\n\t\t\t\tcol += w;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Clicked past end of text\n\treturn value.length;\n}\n\n/** Paint an <input> element — supports multi-line text with cursor. */\nfunction paintInput(\n\tnode: TermNode,\n\tbuf: FrameBuffer,\n\tx: number,\n\ty: number,\n\tw: number,\n\th: number,\n\tclip?: ClipRect,\n): void {\n\tconst value = (node.props.value as string) ?? \"\";\n\tconst placeholder = (node.props.placeholder as string) ?? \"\";\n\tconst focused = (node.props.focused as boolean) ?? true;\n\tconst rawCursor = (node.props._cursorPos as number) ?? value.length;\n\tconst cursorPos = Math.max(0, Math.min(rawCursor, value.length));\n\n\tconst fg = propColor(node.props, \"color\");\n\tconst bg = propColor(node.props, \"bg\");\n\tconst placeholderFg = propColor(node.props, \"placeholderColor\");\n\n\tconst startCol = Math.floor(x);\n\tconst startRow = Math.floor(y);\n\tconst colWidth = Math.floor(w);\n\tconst maxRow = Math.min(startRow + Math.floor(h), buf.rows);\n\n\tif (startRow >= buf.rows) return;\n\n\tif (value) {\n\t\t// Wrap and render all lines\n\t\tconst wrapped = colWidth > 0 ? Bun.wrapAnsi(value, colWidth) : value;\n\t\tconst lines = wrapped.split(\"\\n\");\n\n\t\tfor (let i = 0; i < lines.length && startRow + i < maxRow; i++) {\n\t\t\tbuf.writeString(\n\t\t\t\tstartCol,\n\t\t\t\tstartRow + i,\n\t\t\t\tlines[i] ?? \"\",\n\t\t\t\tfg,\n\t\t\t\tbg,\n\t\t\t\tAttr.None,\n\t\t\t\tclip,\n\t\t\t);\n\t\t}\n\n\t\t// Overlay cursor\n\t\tif (focused) {\n\t\t\tconst cur = cursorToRowCol(value, cursorPos, colWidth);\n\t\t\tconst curRow = startRow + cur.row;\n\t\t\tif (curRow < maxRow) {\n\t\t\t\tconst curCol = startCol + cur.col;\n\t\t\t\tconst charAtCursor =\n\t\t\t\t\tcurCol < buf.cols ? buf.get(curCol, curRow).char : \" \";\n\t\t\t\tconst display =\n\t\t\t\t\tcharAtCursor === \" \" || charAtCursor === \"\" ? \" \" : charAtCursor;\n\t\t\t\tbuf.writeString(curCol, curRow, display, fg, bg, Attr.Inverse, clip);\n\t\t\t}\n\t\t}\n\t} else if (placeholder) {\n\t\t// Render placeholder with dim\n\t\tconst phFg = placeholderFg !== NO_COLOR ? placeholderFg : fg;\n\t\tconst truncated = Bun.sliceAnsi(placeholder, 0, colWidth);\n\t\tbuf.writeString(startCol, startRow, truncated, phFg, bg, Attr.Dim, clip);\n\t\tif (focused) {\n\t\t\tconst first = placeholder[0] ?? \" \";\n\t\t\tbuf.writeString(startCol, startRow, first, phFg, bg, Attr.Inverse, clip);\n\t\t}\n\t} else if (focused) {\n\t\t// Empty + focused: just cursor\n\t\tbuf.writeString(startCol, startRow, \" \", fg, bg, Attr.Inverse, clip);\n\t}\n}\n\n/** Resolve a TermNode's text style props to Cell attributes. */\nfunction resolveAttrs(props: Record<string, unknown>): Attr {\n\tlet attrs = Attr.None;\n\tif (props.bold) attrs |= Attr.Bold;\n\tif (props.dim) attrs |= Attr.Dim;\n\tif (props.italic) attrs |= Attr.Italic;\n\tif (props.underline) attrs |= Attr.Underline;\n\tif (props.inverse) attrs |= Attr.Inverse;\n\tif (props.strikethrough) attrs |= Attr.Strikethrough;\n\treturn attrs;\n}\n\n/** Paint the positioned TermNode tree into a frame buffer. */\n/**\n * A paint-time color filter: maps a glyph cell's local position within a\n * width×height box to a packed 24-bit fg, or `undefined` to leave it untouched.\n */\nexport type ColorField = (\n\tx: number,\n\ty: number,\n\twidth: number,\n\theight: number,\n) => number | undefined;\n\n/**\n * Recolor the glyph cells inside a box's painted region using `field`, after\n * its subtree has painted. Spaces and wide-char continuation cells are skipped,\n * and the box's clip rect is respected. This is how grouped animations\n * (shimmer/wave/pulse) sweep across heterogeneous children — text, spinners,\n * nested boxes — purely by screen position, with no per-node awareness.\n */\nfunction applyColorField(\n\tbuf: FrameBuffer,\n\tcol: number,\n\trow: number,\n\tw: number,\n\th: number,\n\tfield: ColorField,\n\tclip?: ClipRect,\n): void {\n\tconst x0 = Math.max(col, clip?.left ?? 0, 0);\n\tconst y0 = Math.max(row, clip?.top ?? 0, 0);\n\tconst x1 = Math.min(col + w, clip?.right ?? buf.cols, buf.cols);\n\tconst y1 = Math.min(row + h, clip?.bottom ?? buf.rows, buf.rows);\n\tfor (let y = y0; y < y1; y++) {\n\t\tfor (let x = x0; x < x1; x++) {\n\t\t\tconst cell = buf.get(x, y);\n\t\t\tif (cell.width === 0 || cell.char === \" \") continue;\n\t\t\tconst fg = field(x - col, y - row, w, h);\n\t\t\tif (fg !== undefined) {\n\t\t\t\tcell.fg = fg;\n\t\t\t\tbuf.dirtyRows.add(y);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function paint(\n\tnode: TermNode,\n\tbuf: FrameBuffer,\n\toffsetX = 0,\n\toffsetY = 0,\n\tclip?: ClipRect,\n): void {\n\tconst yoga = node.yogaNode;\n\tif (!yoga) return;\n\n\tconst x = offsetX + yoga.getComputedLeft();\n\tconst y = offsetY + yoga.getComputedTop();\n\tconst w = yoga.getComputedWidth();\n\tconst h = yoga.getComputedHeight();\n\n\t// Cache screen-space rect for hit-testing. Mutate the existing rect in place\n\t// when present so a repaint doesn't allocate a new object per node per frame.\n\tconst left = Math.floor(x);\n\tconst top = Math.floor(y);\n\tconst right = Math.floor(x + w);\n\tconst bottom = Math.floor(y + h);\n\tif (node.screenRect) {\n\t\tnode.screenRect.left = left;\n\t\tnode.screenRect.top = top;\n\t\tnode.screenRect.right = right;\n\t\tnode.screenRect.bottom = bottom;\n\t} else {\n\t\tnode.screenRect = { left, top, right, bottom };\n\t}\n\n\tif (node.type === \"box\") {\n\t\tconst col = Math.floor(x);\n\t\tconst row = Math.floor(y);\n\t\tconst bw = Math.floor(w);\n\t\tconst bh = Math.floor(h);\n\n\t\t// Paint background if set\n\t\tconst bgColor = propColor(node.props, \"bg\");\n\t\tif (bgColor !== NO_COLOR) {\n\t\t\tbuf.fillRect(col, row, bw, bh, \" \", NO_COLOR, bgColor, Attr.None, clip);\n\t\t}\n\n\t\t// Paint border if set\n\t\tconst borderStyle = node.props.borderStyle as string | undefined;\n\t\tconst hasBorder = borderStyle != null && borderStyle !== \"none\";\n\t\tif (hasBorder) {\n\t\t\tconst isHorizontal = borderStyle === \"horizontal\";\n\t\t\tconst chars =\n\t\t\t\tBORDER_CHARS[borderStyle as keyof typeof BORDER_CHARS] ??\n\t\t\t\tBORDER_CHARS.single;\n\t\t\tconst borderFg = propColor(node.props, \"color\");\n\n\t\t\tif (isHorizontal) {\n\t\t\t\t// Horizontal-only: full-width lines, no corners or vertical edges\n\t\t\t\tconst hBar = chars.h.repeat(Math.max(0, bw));\n\t\t\t\tbuf.writeString(col, row, hBar, borderFg, bgColor, Attr.None, clip);\n\t\t\t\tbuf.writeString(\n\t\t\t\t\tcol,\n\t\t\t\t\trow + bh - 1,\n\t\t\t\t\thBar,\n\t\t\t\t\tborderFg,\n\t\t\t\t\tbgColor,\n\t\t\t\t\tAttr.None,\n\t\t\t\t\tclip,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// Corners\n\t\t\t\tbuf.writeString(col, row, chars.tl, borderFg, bgColor, Attr.None, clip);\n\t\t\t\tbuf.writeString(\n\t\t\t\t\tcol + bw - 1,\n\t\t\t\t\trow,\n\t\t\t\t\tchars.tr,\n\t\t\t\t\tborderFg,\n\t\t\t\t\tbgColor,\n\t\t\t\t\tAttr.None,\n\t\t\t\t\tclip,\n\t\t\t\t);\n\t\t\t\tbuf.writeString(\n\t\t\t\t\tcol,\n\t\t\t\t\trow + bh - 1,\n\t\t\t\t\tchars.bl,\n\t\t\t\t\tborderFg,\n\t\t\t\t\tbgColor,\n\t\t\t\t\tAttr.None,\n\t\t\t\t\tclip,\n\t\t\t\t);\n\t\t\t\tbuf.writeString(\n\t\t\t\t\tcol + bw - 1,\n\t\t\t\t\trow + bh - 1,\n\t\t\t\t\tchars.br,\n\t\t\t\t\tborderFg,\n\t\t\t\t\tbgColor,\n\t\t\t\t\tAttr.None,\n\t\t\t\t\tclip,\n\t\t\t\t);\n\n\t\t\t\t// Horizontal edges\n\t\t\t\tconst hBar = chars.h.repeat(Math.max(0, bw - 2));\n\t\t\t\tbuf.writeString(col + 1, row, hBar, borderFg, bgColor, Attr.None, clip);\n\t\t\t\tbuf.writeString(\n\t\t\t\t\tcol + 1,\n\t\t\t\t\trow + bh - 1,\n\t\t\t\t\thBar,\n\t\t\t\t\tborderFg,\n\t\t\t\t\tbgColor,\n\t\t\t\t\tAttr.None,\n\t\t\t\t\tclip,\n\t\t\t\t);\n\n\t\t\t\t// Vertical edges\n\t\t\t\tfor (let r = row + 1; r < row + bh - 1 && r < buf.rows; r++) {\n\t\t\t\t\tbuf.writeString(col, r, chars.v, borderFg, bgColor, Attr.None, clip);\n\t\t\t\t\tbuf.writeString(\n\t\t\t\t\t\tcol + bw - 1,\n\t\t\t\t\t\tr,\n\t\t\t\t\t\tchars.v,\n\t\t\t\t\t\tborderFg,\n\t\t\t\t\t\tbgColor,\n\t\t\t\t\t\tAttr.None,\n\t\t\t\t\t\tclip,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Determine child clipping and scroll offset\n\t\tconst overflow = node.props.overflow as string | undefined;\n\t\tif (overflow === \"hidden\" || overflow === \"scroll\") {\n\t\t\tconst border = hasBorder ? 1 : 0;\n\t\t\tconst innerClip: ClipRect = {\n\t\t\t\tleft: Math.max(clip?.left ?? 0, col + border),\n\t\t\t\ttop: Math.max(clip?.top ?? 0, row + border),\n\t\t\t\tright: Math.min(clip?.right ?? buf.cols, col + bw - border),\n\t\t\t\tbottom: Math.min(clip?.bottom ?? buf.rows, row + bh - border),\n\t\t\t};\n\t\t\tconst scrollY = overflow === \"scroll\" ? node.scrollTop : 0;\n\t\t\tfor (const child of node.children) {\n\t\t\t\tpaint(child, buf, x, y - scrollY, innerClip);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (const child of node.children) {\n\t\t\t\tpaint(child, buf, x, y, clip);\n\t\t\t}\n\t\t}\n\n\t\t// Paint-time color filter: recolor glyph cells in this box's region\n\t\t// (set by <Animated> for shimmer/wave/pulse effects across children).\n\t\tconst colorField = node.props.colorField as ColorField | undefined;\n\t\tif (colorField) {\n\t\t\tapplyColorField(buf, col, row, bw, bh, colorField, clip);\n\t\t}\n\t} else if (node.type === \"text\") {\n\t\tconst content = collectText(node);\n\t\tif (!content) return;\n\n\t\tconst fg = propColor(node.props, \"color\");\n\t\tconst bg = propColor(node.props, \"bg\");\n\t\tconst attrs = resolveAttrs(node.props);\n\t\tconst wrapMode = (node.props.wrap as string) ?? \"word\";\n\n\t\tconst colWidth = Math.floor(w);\n\t\tconst startCol = Math.floor(x);\n\t\tconst startRow = Math.floor(y);\n\t\tconst maxRow = Math.min(startRow + Math.floor(h), buf.rows);\n\n\t\tif (wrapMode === \"word\") {\n\t\t\t// Paint from raw content lines to preserve spaces\n\t\t\t// (Bun.wrapAnsi strips trailing whitespace)\n\t\t\tconst sourceLines = content.split(\"\\n\");\n\t\t\tlet row = 0;\n\t\t\tfor (const srcLine of sourceLines) {\n\t\t\t\tif (startRow + row >= maxRow) break;\n\t\t\t\tif (colWidth > 0 && Bun.stringWidth(srcLine) > colWidth) {\n\t\t\t\t\t// Line needs wrapping — use wrapAnsi for word boundaries\n\t\t\t\t\tconst wrapped = Bun.wrapAnsi(srcLine, colWidth);\n\t\t\t\t\tfor (const wLine of wrapped.split(\"\\n\")) {\n\t\t\t\t\t\tif (startRow + row >= maxRow) break;\n\t\t\t\t\t\tbuf.writeString(\n\t\t\t\t\t\t\tstartCol,\n\t\t\t\t\t\t\tstartRow + row,\n\t\t\t\t\t\t\twLine,\n\t\t\t\t\t\t\tfg,\n\t\t\t\t\t\t\tbg,\n\t\t\t\t\t\t\tattrs,\n\t\t\t\t\t\t\tclip,\n\t\t\t\t\t\t);\n\t\t\t\t\t\trow++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbuf.writeString(\n\t\t\t\t\t\tstartCol,\n\t\t\t\t\t\tstartRow + row,\n\t\t\t\t\t\tsrcLine,\n\t\t\t\t\t\tfg,\n\t\t\t\t\t\tbg,\n\t\t\t\t\t\tattrs,\n\t\t\t\t\t\tclip,\n\t\t\t\t\t);\n\t\t\t\t\trow++;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Truncation modes — each source line becomes exactly one output line\n\t\t\tconst sourceLines = content.split(\"\\n\");\n\t\t\tfor (let i = 0; i < sourceLines.length && startRow + i < maxRow; i++) {\n\t\t\t\tconst line = sourceLines[i] ?? \"\";\n\t\t\t\tconst truncated = truncateLine(line, colWidth, wrapMode);\n\t\t\t\tbuf.writeString(startCol, startRow + i, truncated, fg, bg, attrs, clip);\n\t\t\t}\n\t\t}\n\t} else if (node.type === \"hyperlink\") {\n\t\tconst content = collectText(node);\n\t\tif (!content) return;\n\n\t\tconst href = (node.props.href as string) ?? \"\";\n\t\tconst fg = propColor(node.props, \"color\");\n\t\tconst bg = propColor(node.props, \"bg\");\n\t\tconst attrs = resolveAttrs(node.props);\n\n\t\tconst colWidth = Math.floor(w);\n\t\tconst startCol = Math.floor(x);\n\t\tconst startRow = Math.floor(y);\n\t\tconst maxRow = Math.min(startRow + Math.floor(h), buf.rows);\n\n\t\tconst sourceLines = content.split(\"\\n\");\n\t\tlet row = 0;\n\t\tfor (const srcLine of sourceLines) {\n\t\t\tif (startRow + row >= maxRow) break;\n\t\t\tif (colWidth > 0 && Bun.stringWidth(srcLine) > colWidth) {\n\t\t\t\tconst wrapped = Bun.wrapAnsi(srcLine, colWidth);\n\t\t\t\tfor (const wLine of wrapped.split(\"\\n\")) {\n\t\t\t\t\tif (startRow + row >= maxRow) break;\n\t\t\t\t\tbuf.writeString(\n\t\t\t\t\t\tstartCol,\n\t\t\t\t\t\tstartRow + row,\n\t\t\t\t\t\twLine,\n\t\t\t\t\t\tfg,\n\t\t\t\t\t\tbg,\n\t\t\t\t\t\tattrs,\n\t\t\t\t\t\tclip,\n\t\t\t\t\t\thref,\n\t\t\t\t\t);\n\t\t\t\t\trow++;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tbuf.writeString(\n\t\t\t\t\tstartCol,\n\t\t\t\t\tstartRow + row,\n\t\t\t\t\tsrcLine,\n\t\t\t\t\tfg,\n\t\t\t\t\tbg,\n\t\t\t\t\tattrs,\n\t\t\t\t\tclip,\n\t\t\t\t\thref,\n\t\t\t\t);\n\t\t\t\trow++;\n\t\t\t}\n\t\t}\n\t} else if (node.type === \"input\") {\n\t\tpaintInput(node, buf, x, y, w, h, clip);\n\t}\n\t// _text and _slot nodes are handled by their parent text node via collectText\n}\n\n// --- Scroll utilities ---\n\n/** Get the total content height of a node's children (after layout). */\nexport function getScrollHeight(node: TermNode): number {\n\tlet maxBottom = 0;\n\tfor (const child of node.children) {\n\t\tif (child.yogaNode) {\n\t\t\tconst bottom =\n\t\t\t\tchild.yogaNode.getComputedTop() + child.yogaNode.getComputedHeight();\n\t\t\tif (bottom > maxBottom) maxBottom = bottom;\n\t\t}\n\t}\n\treturn maxBottom;\n}\n\n/** Scroll a node to an absolute offset, clamped to valid range. */\nexport function scrollTo(node: TermNode, top: number): void {\n\tconst viewportHeight = node.yogaNode?.getComputedHeight() ?? 0;\n\t// Account for border inset (1 cell top + 1 cell bottom)\n\tconst borderTop = node.yogaNode?.getComputedBorder(Edge.Top) ?? 0;\n\tconst borderBottom = node.yogaNode?.getComputedBorder(Edge.Bottom) ?? 0;\n\tconst border = borderTop + borderBottom;\n\tconst contentHeight = getScrollHeight(node);\n\tconst maxScroll = Math.max(0, contentHeight - (viewportHeight - border));\n\tnode.scrollTop = Math.max(0, Math.min(top, maxScroll));\n}\n\n/** Scroll a node by a relative delta. */\nexport function scrollBy(node: TermNode, delta: number): void {\n\tscrollTo(node, node.scrollTop + delta);\n}\n\n/** Scroll a node to the bottom of its content. */\nexport function scrollToBottom(node: TermNode): void {\n\tscrollTo(node, Infinity);\n}\n\n// --- Hit-testing ---\n\n/**\n * Find the deepest TermNode at screen coordinates (col, row).\n * Walks children in reverse order so later (visually on-top) nodes win.\n * Returns null if no node contains the point.\n */\nexport function hitTest(\n\tnode: TermNode,\n\tcol: number,\n\trow: number,\n): TermNode | null {\n\tconst rect = node.screenRect;\n\tif (!rect) return null;\n\tif (\n\t\tcol < rect.left ||\n\t\tcol >= rect.right ||\n\t\trow < rect.top ||\n\t\trow >= rect.bottom\n\t) {\n\t\treturn null;\n\t}\n\n\t// Check children in reverse z-order (last child is on top)\n\tfor (let i = node.children.length - 1; i >= 0; i--) {\n\t\tconst child = node.children[i];\n\t\tif (!child) continue;\n\t\t// Skip internal nodes (_text, _slot)\n\t\tif (child.type === \"_text\" || child.type === \"_slot\") continue;\n\t\tconst hit = hitTest(child, col, row);\n\t\tif (hit) return hit;\n\t}\n\n\t// No child matched — this node is the target\n\treturn node;\n}\n\n/**\n * Walk from a hit node up to root, looking for the first ancestor\n * (including itself) that has a specific handler prop.\n */\nexport function findHandler(\n\tnode: TermNode | null,\n\tprop: string,\n): { node: TermNode; handler: (e: unknown) => void } | null {\n\tlet current = node;\n\twhile (current) {\n\t\tconst handler = current.props[prop];\n\t\tif (typeof handler === \"function\") {\n\t\t\treturn { node: current, handler: handler as (e: unknown) => void };\n\t\t}\n\t\tcurrent = current.parent;\n\t}\n\treturn null;\n}\n\n// --- Frame render ---\n\nexport interface RenderState {\n\t/** Number of rows actually used by content (updated each frame) */\n\tactiveHeight: number;\n\tbuffer: FrameBuffer;\n\tcols: number;\n\t/** Whether the terminal supports OSC 8 hyperlinks */\n\tlinksEnabled: boolean;\n\tprevBuffer: FrameBuffer;\n\trows: number;\n\t/** Text selection state */\n\tselection: SelectionState;\n\tsyncSupported: boolean;\n}\n\nexport function createRenderState(\n\tcols: number,\n\trows: number,\n\tsyncSupported = false,\n\tlinksEnabled = false,\n): RenderState {\n\treturn {\n\t\tactiveHeight: 0,\n\t\tcols,\n\t\trows,\n\t\tbuffer: new FrameBuffer(cols, rows),\n\t\tprevBuffer: new FrameBuffer(cols, rows),\n\t\tselection: createSelection(),\n\t\tsyncSupported,\n\t\tlinksEnabled,\n\t};\n}\n\n/** Clear dirty flags after layout so unchanged frames skip layout next time. */\nexport function clearDirty(node: TermNode): void {\n\tnode.dirty = false;\n\tfor (const child of node.children) {\n\t\tclearDirty(child);\n\t}\n}\n\n/**\n * Run the full render pipeline: layout → paint → diff → serialize.\n * Returns the ANSI string to write to stdout.\n */\nexport function renderFrame(root: TermNode, state: RenderState): string {\n\t// 1. Layout — skip if no props/children/text changed since last frame\n\tif (root.dirty) {\n\t\tlayout(root, state.cols, state.rows);\n\t\tclearDirty(root);\n\t}\n\n\t// 2. Clear only previously-painted rows, then paint\n\tstate.buffer.clearDirtyRows();\n\tpaint(root, state.buffer);\n\n\t// 2b. Track actual content height\n\tstate.activeHeight = state.buffer.contentHeight();\n\n\t// 2c. Apply selection overlay (if active)\n\tif (state.selection.anchor && state.selection.focus) {\n\t\tapplySelectionOverlay(state.buffer, state.selection);\n\t}\n\n\t// 3. Diff only rows that were painted this frame or last frame\n\tconst dirtyRows = new Set(state.buffer.dirtyRows);\n\tfor (const row of state.prevBuffer.dirtyRows) dirtyRows.add(row);\n\tconst changes = diffFrames(state.prevBuffer, state.buffer, dirtyRows);\n\n\t// 4. Serialize to ANSI\n\tconst ansi = serializeChanges(changes, undefined, state.linksEnabled);\n\n\t// 5. Swap buffers\n\tconst tmp = state.prevBuffer;\n\tstate.prevBuffer = state.buffer;\n\tstate.buffer = tmp;\n\n\t// 6. Wrap in sync output if supported\n\tif (!ansi) return \"\";\n\treturn state.syncSupported ? wrapSynchronized(ansi) : ansi;\n}\n\n/**\n * Content-driven render: active region height = content height.\n * Ports CC's Ink primary-screen rendering model (renderer.ts + log-update.ts):\n *\n * - Yoga root height is unconstrained → content determines height\n * - screen.height = yogaHeight (content height, may exceed terminal rows)\n * - cursor.y = screen.height (parked after last content row)\n * - When content < viewport: only renders content rows, input near top\n * - When content >= viewport: log-update's cursor-restore LF naturally\n *   scrolls old content into terminal scrollback\n * - Diff is only computed for rows within the terminal viewport\n *\n * @param terminalRows - the terminal's visible row count (for viewport calc)\n */\nexport function renderContentDriven(\n\troot: TermNode,\n\tstate: RenderState,\n\tterminalRows: number,\n): string {\n\t// 1. Layout with unconstrained height — content determines size\n\tif (root.dirty) {\n\t\tlayout(root, state.cols);\n\t\tclearDirty(root);\n\t}\n\n\t// 2. Compute content height from yoga layout (CC: renderer.ts line 85)\n\tlet contentHeight = 0;\n\tfor (const child of root.children) {\n\t\tif (child.yogaNode) {\n\t\t\tconst bottom =\n\t\t\t\tchild.yogaNode.getComputedTop() + child.yogaNode.getComputedHeight();\n\t\t\tif (bottom > contentHeight) contentHeight = Math.ceil(bottom);\n\t\t}\n\t}\n\tcontentHeight = Math.max(1, contentHeight);\n\n\t// Ensure buffers are large enough for content\n\tif (contentHeight > state.buffer.rows) {\n\t\tstate.buffer = new FrameBuffer(state.cols, contentHeight);\n\t\tstate.prevBuffer = new FrameBuffer(state.cols, contentHeight);\n\t\tstate.rows = contentHeight;\n\t}\n\n\t// 3. Paint full content into buffer\n\tstate.buffer.clearDirtyRows();\n\tpaint(root, state.buffer);\n\n\tconst prevHeight = state.activeHeight;\n\tstate.activeHeight = contentHeight;\n\tconst heightDelta = Math.max(contentHeight, 1) - Math.max(prevHeight, 1);\n\tconst growing = heightDelta > 0;\n\tconst shrinking = heightDelta < 0;\n\n\t// CC pattern (log-update.ts): cursor is at (0, prevHeight) from the\n\t// previous frame's cursor-restore. Rows 0..viewportY-1 are in scrollback\n\t// (unreachable). We can only diff rows viewportY..contentHeight-1.\n\tconst cursorAtBottom = prevHeight >= terminalRows;\n\tconst prevHadScrollback = cursorAtBottom;\n\tconst viewportY = growing\n\t\t? Math.max(0, prevHeight - terminalRows + (prevHadScrollback ? 1 : 0))\n\t\t: Math.max(\n\t\t\t\tMath.max(prevHeight, contentHeight) -\n\t\t\t\t\tterminalRows +\n\t\t\t\t\t(prevHadScrollback ? 1 : 0),\n\t\t\t\t0,\n\t\t\t);\n\n\t// 4. Diff only rows within the viewport (skip scrollback)\n\tconst dirtyRows = new Set<number>();\n\tfor (const row of state.buffer.dirtyRows) {\n\t\tif (row >= viewportY) dirtyRows.add(row);\n\t}\n\tfor (const row of state.prevBuffer.dirtyRows) {\n\t\tif (row >= viewportY && row < contentHeight) dirtyRows.add(row);\n\t}\n\tconst changes = diffFrames(state.prevBuffer, state.buffer, dirtyRows);\n\n\t// 5. Swap buffers\n\tconst tmp = state.prevBuffer;\n\tstate.prevBuffer = state.buffer;\n\tstate.buffer = tmp;\n\n\t// Skip output if nothing changed and height is stable\n\tif (changes.length === 0 && heightDelta === 0) return \"\";\n\n\tlet out = \"\";\n\n\t// Handle shrinking: clear removed rows from bottom\n\tif (shrinking) {\n\t\tconst linesToClear = -heightDelta;\n\t\t// Move up from cursor position and clear\n\t\tout += `\\x1b[${linesToClear}A\\x1b[0J`;\n\t\t// Now cursor is at contentHeight, move up to row 0 relative\n\t\tconst remaining = contentHeight - (prevHeight - linesToClear);\n\t\tif (remaining > 0) {\n\t\t\t// noop — we're at the right position\n\t\t}\n\t}\n\n\t// Serialize changed rows. serializeChanges uses absolute row positions\n\t// in cursor moves, so this works correctly.\n\tconst ansi = serializeChanges(changes, undefined, state.linksEnabled);\n\tif (ansi) {\n\t\t// Move cursor to top of active region before writing diffs\n\t\tif (prevHeight > 0) {\n\t\t\tout += `\\x1b[${prevHeight}A\\r`;\n\t\t}\n\t\tout += ansi;\n\t}\n\n\t// Handle growth: new rows are rendered by the diff above.\n\t// Move cursor to after content for cursor-restore LF effect.\n\t// CC: cursor.y = screen.height (log-update handles the LF at frame end)\n\tif (growing && !ansi) {\n\t\t// Content grew but diff was empty (shouldn't happen, but be safe)\n\t\tif (prevHeight > 0) {\n\t\t\tout += `\\x1b[${prevHeight}A\\r`;\n\t\t}\n\t}\n\n\t// Park cursor at (0, contentHeight) — CC's cursor-restore position.\n\t// Using CR + LFs to reach the target row, which scrolls the terminal\n\t// when contentHeight >= terminalRows (exactly how CC scrolls).\n\tout += `\\r`;\n\tconst targetRow = contentHeight;\n\t// We need to get to row=contentHeight from wherever the cursor ended up.\n\t// After writing ansi, cursor is somewhere in the content. Use absolute.\n\tout += `\\x1b[${targetRow + 1};1H`;\n\n\t// If content exceeds terminal and cursor is past viewport bottom,\n\t// emit a newline to scroll (CC: log-update lines 426-438)\n\tif (contentHeight >= terminalRows) {\n\t\tout += `\\n`;\n\t}\n\n\tif (!out) return \"\";\n\treturn state.syncSupported ? wrapSynchronized(out) : out;\n}\n\n/**\n * Render a component to an ANSI string (one-shot).\n * Creates a temporary Solid tree, runs layout + paint, serializes, disposes.\n * Returns { ansi, height } — the ANSI output and the content height in rows.\n */\nexport function renderToAnsi(\n\tcode: () => unknown,\n\tcols: number,\n\tlinksEnabled = false,\n): { ansi: string; height: number } {\n\t// Temporary root — unconstrained height so content determines size\n\tconst yogaRoot = new YogaNode();\n\tyogaRoot.setWidth(cols);\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// Mount Solid tree\n\tconst dispose = render(code, root);\n\n\t// Layout with unconstrained height\n\tlayout(root, cols);\n\n\t// Measure actual content height\n\tlet contentRows = 0;\n\tfor (const child of root.children) {\n\t\tif (child.yogaNode) {\n\t\t\tconst bottom =\n\t\t\t\tchild.yogaNode.getComputedTop() + child.yogaNode.getComputedHeight();\n\t\t\tif (bottom > contentRows) contentRows = Math.ceil(bottom);\n\t\t}\n\t}\n\tcontentRows = Math.max(1, contentRows);\n\n\t// Paint into a buffer sized to content\n\tconst buf = new FrameBuffer(cols, contentRows);\n\tpaint(root, buf);\n\n\t// Serialize (diff against empty buffer = full output)\n\tconst empty = new FrameBuffer(cols, contentRows);\n\tconst changes = diffFrames(empty, buf);\n\tconst ansi = serializeChanges(changes, undefined, linksEnabled);\n\n\t// Cleanup\n\tdispose();\n\tyogaRoot.free();\n\n\treturn { ansi, height: contentRows };\n}\n"],"mappings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