reasonix 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dashboard/dist/app.js +618 -491
- package/dashboard/dist/app.js.map +1 -1
- package/dist/cli/index.js +9279 -6831
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{prompt-VZQ2CPID.js → prompt-YUL7CYKY.js} +1 -2
- package/dist/index.d.ts +1 -16
- package/dist/index.js +2 -30
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/cli/banner-demo-QKOPDSTL.js +0 -77
- package/dist/cli/banner-demo-QKOPDSTL.js.map +0 -1
- package/dist/cli/card-demo-5TVXJISK.js +0 -944
- package/dist/cli/card-demo-5TVXJISK.js.map +0 -1
- package/dist/cli/chunk-2H7UOFLK.js +0 -11
- package/dist/cli/chunk-BGTXZKNY.js +0 -197
- package/dist/cli/chunk-BGTXZKNY.js.map +0 -1
- package/dist/cli/chunk-JHXQDL7B.js +0 -2056
- package/dist/cli/chunk-JHXQDL7B.js.map +0 -1
- package/dist/cli/flicker-demo-MOB6GAW4.js +0 -165
- package/dist/cli/flicker-demo-MOB6GAW4.js.map +0 -1
- package/dist/cli/preview-4FOEEE5G.js +0 -224
- package/dist/cli/preview-4FOEEE5G.js.map +0 -1
- package/dist/cli/prompt-VZQ2CPID.js.map +0 -1
- package/dist/cli/renderer-demo-2BIGEV2T.js +0 -95
- package/dist/cli/renderer-demo-2BIGEV2T.js.map +0 -1
- package/dist/cli/select-demo-OA5N34BJ.js +0 -107
- package/dist/cli/select-demo-OA5N34BJ.js.map +0 -1
- package/dist/cli/stress-demo-I7XRPQMM.js +0 -211
- package/dist/cli/stress-demo-I7XRPQMM.js.map +0 -1
- /package/dist/cli/{chunk-2H7UOFLK.js.map → prompt-YUL7CYKY.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/renderer/react/components.ts","../../src/renderer/input/use-keystroke.ts","../../src/renderer/input/keystroke.ts","../../src/renderer/input/reader.ts","../../src/renderer/pools/char-pool.ts","../../src/renderer/pools/hyperlink-pool.ts","../../src/renderer/pools/style-pool.ts","../../src/renderer/reconciler/mount.ts","../../src/renderer/screen/cell.ts","../../src/renderer/screen/diff.ts","../../src/renderer/diff/diff-frames.ts","../../src/renderer/screen/screen.ts","../../src/renderer/diff/frame.ts","../../src/renderer/diff/serialize.ts","../../src/renderer/ink-compat/renderer-bridge.ts","../../src/renderer/ink-compat/use-app.ts","../../src/renderer/ink-compat/viewport.ts","../../src/renderer/layout/layout.ts","../../src/renderer/layout/yoga-layout.ts","../../src/renderer/layout/borders.ts","../../src/renderer/runtime/render-to-bytes.ts","../../src/renderer/reconciler/host-config.ts","../../src/renderer/reconciler/host-node.ts","../../src/renderer/reconciler/cursor.ts","../../src/renderer/ink-compat/index.ts","../../src/renderer/ink-compat/Box.tsx","../../src/renderer/ink-compat/colors.ts","../../src/renderer/ink-compat/Text.tsx","../../src/renderer/ink-compat/Spacer.tsx","../../src/renderer/ink-compat/Static.tsx","../../src/renderer/ink-compat/use-input.ts","../../src/renderer/ink-compat/render.tsx","../../src/renderer/react/render.ts"],"sourcesContent":["import React, { type ReactElement, type ReactNode } from \"react\";\nimport type { BorderStyle, BorderStyleName } from \"../layout/borders.js\";\nimport type { AlignItems, FlexWrap, JustifyContent } from \"../layout/node.js\";\nimport type { AnsiCode } from \"../pools/style-pool.js\";\n\nexport const HOST_BOX = \"rsx-box\" as const;\nexport const HOST_TEXT = \"rsx-text\" as const;\n\nexport interface BoxProps {\n readonly children?: ReactNode;\n readonly flexDirection?: \"column\" | \"row\" | \"column-reverse\" | \"row-reverse\";\n readonly flexGrow?: number;\n readonly flexShrink?: number;\n readonly flexBasis?: number | `${number}%` | \"auto\";\n readonly flexWrap?: FlexWrap;\n readonly justifyContent?: JustifyContent;\n readonly alignItems?: AlignItems;\n readonly alignSelf?: AlignItems;\n readonly alignContent?: AlignItems | \"space-between\" | \"space-around\";\n readonly width?: number | `${number}%`;\n readonly height?: number | `${number}%`;\n readonly minWidth?: number | `${number}%`;\n readonly minHeight?: number | `${number}%`;\n readonly maxWidth?: number | `${number}%`;\n readonly maxHeight?: number | `${number}%`;\n readonly gap?: number;\n readonly columnGap?: number;\n readonly rowGap?: number;\n readonly display?: \"flex\" | \"none\";\n readonly paddingTop?: number;\n readonly paddingBottom?: number;\n readonly paddingLeft?: number;\n readonly paddingRight?: number;\n readonly paddingX?: number;\n readonly paddingY?: number;\n readonly padding?: number;\n readonly marginTop?: number;\n readonly marginBottom?: number;\n readonly marginLeft?: number;\n readonly marginRight?: number;\n readonly marginX?: number;\n readonly marginY?: number;\n readonly margin?: number;\n readonly borderStyle?: BorderStyle | BorderStyleName;\n readonly borderTop?: boolean;\n readonly borderBottom?: boolean;\n readonly borderLeft?: boolean;\n readonly borderRight?: boolean;\n readonly borderColor?: ReadonlyArray<AnsiCode>;\n readonly borderTopColor?: ReadonlyArray<AnsiCode>;\n readonly borderBottomColor?: ReadonlyArray<AnsiCode>;\n readonly borderLeftColor?: ReadonlyArray<AnsiCode>;\n readonly borderRightColor?: ReadonlyArray<AnsiCode>;\n}\n\nexport interface TextProps {\n readonly children?: ReactNode;\n readonly style?: ReadonlyArray<AnsiCode>;\n readonly hyperlink?: string;\n}\n\nexport function Box(props: BoxProps): ReactElement {\n return React.createElement(HOST_BOX, props);\n}\n\nexport function Text(props: TextProps): ReactElement {\n return React.createElement(HOST_TEXT, props);\n}\n","import { createContext, useContext, useEffect } from \"react\";\nimport type { Keystroke } from \"./keystroke.js\";\nimport type { KeystrokeListener, KeystrokeReader } from \"./reader.js\";\n\nexport const KeystrokeContext = createContext<KeystrokeReader | null>(null);\n\nexport function useKeystroke(handler: (key: Keystroke) => void, enabled = true): void {\n const reader = useContext(KeystrokeContext);\n useEffect(() => {\n if (!enabled || !reader) return;\n const wrapped: KeystrokeListener = (key) => handler(key);\n return reader.subscribe(wrapped);\n }, [reader, handler, enabled]);\n}\n","export interface Keystroke {\n readonly input: string;\n readonly raw: string;\n readonly ctrl: boolean;\n readonly meta: boolean;\n readonly shift: boolean;\n readonly upArrow: boolean;\n readonly downArrow: boolean;\n readonly leftArrow: boolean;\n readonly rightArrow: boolean;\n readonly home: boolean;\n readonly end: boolean;\n readonly pageUp: boolean;\n readonly pageDown: boolean;\n readonly delete: boolean;\n readonly backspace: boolean;\n readonly return: boolean;\n readonly escape: boolean;\n readonly tab: boolean;\n readonly wheelUp: boolean;\n readonly wheelDown: boolean;\n}\n\nexport function emptyKeystroke(): Keystroke {\n return {\n input: \"\",\n raw: \"\",\n ctrl: false,\n meta: false,\n shift: false,\n upArrow: false,\n downArrow: false,\n leftArrow: false,\n rightArrow: false,\n home: false,\n end: false,\n pageUp: false,\n pageDown: false,\n delete: false,\n backspace: false,\n return: false,\n escape: false,\n tab: false,\n wheelUp: false,\n wheelDown: false,\n };\n}\n\nconst CSI_FINAL: Record<string, Partial<Keystroke>> = {\n A: { upArrow: true },\n B: { downArrow: true },\n C: { rightArrow: true },\n D: { leftArrow: true },\n H: { home: true },\n F: { end: true },\n};\n\nconst CSI_TILDE: Record<string, Partial<Keystroke>> = {\n \"1\": { home: true },\n \"3\": { delete: true },\n \"4\": { end: true },\n \"5\": { pageUp: true },\n \"6\": { pageDown: true },\n \"7\": { home: true },\n \"8\": { end: true },\n};\n\nexport function parseKeystrokes(chunk: string): Keystroke[] {\n const out: Keystroke[] = [];\n let i = 0;\n while (i < chunk.length) {\n const consumed = parseOne(chunk, i);\n if (consumed.length === 0) {\n i++;\n continue;\n }\n out.push(consumed.key);\n i += consumed.length;\n }\n return out;\n}\n\ninterface Consumed {\n key: Keystroke;\n length: number;\n}\n\nconst PASTE_START = \"\\x1b[200~\";\nconst PASTE_END = \"\\x1b[201~\";\n\nfunction parseOne(s: string, start: number): Consumed {\n const ch = s[start]!;\n\n // Bracketed-paste: terminal wraps pasted content in ESC[200~ ... ESC[201~.\n // Surface the entire payload as ONE keystroke so multi-line reducers can\n // recognise it as a paste burst and allocate a single sentinel.\n if (ch === \"\\x1b\" && s.startsWith(PASTE_START, start)) {\n const bodyStart = start + PASTE_START.length;\n const endIdx = s.indexOf(PASTE_END, bodyStart);\n if (endIdx >= 0) {\n const content = s.slice(bodyStart, endIdx);\n return {\n key: {\n ...emptyKeystroke(),\n raw: s.slice(start, endIdx + PASTE_END.length),\n input: content,\n },\n length: endIdx + PASTE_END.length - start,\n };\n }\n // Unterminated paste in this chunk — fall through to generic escape\n // parsing. Real terminals send the wrapper atomically; if it splits we\n // lose the marker but recover the content as normal keystrokes.\n }\n\n if (ch === \"\\x1b\") {\n return parseEscape(s, start);\n }\n\n if (ch === \"\\r\" || ch === \"\\n\") {\n return { key: { ...emptyKeystroke(), raw: ch, return: true }, length: 1 };\n }\n if (ch === \"\\t\") {\n return { key: { ...emptyKeystroke(), raw: ch, tab: true }, length: 1 };\n }\n if (ch === \"\\x7f\" || ch === \"\\x08\") {\n return { key: { ...emptyKeystroke(), raw: ch, backspace: true }, length: 1 };\n }\n\n const code = ch.charCodeAt(0);\n if (code >= 1 && code <= 26 && ch !== \"\\t\" && ch !== \"\\r\" && ch !== \"\\n\") {\n const letter = String.fromCharCode(code + 96);\n return {\n key: { ...emptyKeystroke(), raw: ch, ctrl: true, input: letter },\n length: 1,\n };\n }\n\n return { key: { ...emptyKeystroke(), raw: ch, input: ch }, length: 1 };\n}\n\nfunction parseEscape(s: string, start: number): Consumed {\n if (start + 1 >= s.length) {\n return { key: { ...emptyKeystroke(), raw: \"\\x1b\", escape: true }, length: 1 };\n }\n\n const next = s[start + 1]!;\n\n if (next === \"[\" || next === \"O\") {\n return parseCsi(s, start);\n }\n\n // Alt+Enter — terminals send \\x1b\\r (or \\x1b\\n on some). Surface as\n // meta+return so multi-line reducers can distinguish it from a bare Enter.\n if (next === \"\\r\" || next === \"\\n\") {\n return {\n key: { ...emptyKeystroke(), raw: `\\x1b${next}`, meta: true, return: true },\n length: 2,\n };\n }\n\n if (isPrintable(next)) {\n return {\n key: { ...emptyKeystroke(), raw: `\\x1b${next}`, meta: true, input: next },\n length: 2,\n };\n }\n\n return { key: { ...emptyKeystroke(), raw: \"\\x1b\", escape: true }, length: 1 };\n}\n\nfunction parseCsi(s: string, start: number): Consumed {\n let i = start + 2;\n let params = \"\";\n while (i < s.length) {\n const c = s[i]!;\n if (isCsiFinal(c)) {\n const raw = s.slice(start, i + 1);\n const key = decodeCsi(params, c, raw);\n return { key, length: i - start + 1 };\n }\n params += c;\n i++;\n }\n return {\n key: { ...emptyKeystroke(), raw: s.slice(start), escape: true },\n length: s.length - start,\n };\n}\n\nfunction decodeCsi(params: string, final: string, raw: string): Keystroke {\n const base = { ...emptyKeystroke(), raw };\n\n if (params.startsWith(\"<\") && (final === \"M\" || final === \"m\")) {\n const mouse = params.slice(1).split(\";\");\n const button = Number.parseInt(mouse[0] ?? \"\", 10);\n if (button === 64) return { ...base, wheelUp: true };\n if (button === 65) return { ...base, wheelDown: true };\n return base;\n }\n\n const segments = params.split(\";\");\n const modCode = segments[1] ? Number.parseInt(segments[1], 10) : 1;\n const mods = decodeModifiers(modCode);\n\n if (final === \"~\" && segments[0]) {\n const part = CSI_TILDE[segments[0]];\n if (part) return { ...base, ...part, ...mods };\n }\n\n const part = CSI_FINAL[final];\n if (part) return { ...base, ...part, ...mods };\n\n return { ...base, escape: true };\n}\n\nfunction decodeModifiers(code: number): Pick<Keystroke, \"shift\" | \"meta\" | \"ctrl\"> {\n const m = code - 1;\n return {\n shift: (m & 1) !== 0,\n meta: (m & 2) !== 0,\n ctrl: (m & 4) !== 0,\n };\n}\n\nfunction isCsiFinal(ch: string): boolean {\n const code = ch.charCodeAt(0);\n return code >= 0x40 && code <= 0x7e && ch !== \"[\";\n}\n\nfunction isPrintable(ch: string): boolean {\n const code = ch.charCodeAt(0);\n return code >= 0x20 && code <= 0x7e;\n}\n","import type { Keystroke } from \"./keystroke.js\";\nimport { parseKeystrokes } from \"./keystroke.js\";\n\nexport type KeystrokeListener = (key: Keystroke) => void;\n\nexport interface KeystrokeSource {\n on(event: \"data\", cb: (chunk: Buffer | string) => void): void;\n off(event: \"data\", cb: (chunk: Buffer | string) => void): void;\n setRawMode?(raw: boolean): void;\n resume?(): void;\n pause?(): void;\n}\n\nexport interface KeystrokeReaderOptions {\n source: KeystrokeSource;\n rawMode?: boolean;\n}\n\nexport class KeystrokeReader {\n private listeners: KeystrokeListener[] = [];\n private readonly onData: (chunk: Buffer | string) => void;\n private destroyed = false;\n\n constructor(private readonly opts: KeystrokeReaderOptions) {\n this.onData = (chunk) => this.handle(chunk);\n if (opts.rawMode !== false) {\n opts.source.setRawMode?.(true);\n }\n opts.source.resume?.();\n opts.source.on(\"data\", this.onData);\n }\n\n subscribe(listener: KeystrokeListener): () => void {\n this.listeners.push(listener);\n return () => {\n const i = this.listeners.indexOf(listener);\n if (i >= 0) this.listeners.splice(i, 1);\n };\n }\n\n destroy(): void {\n if (this.destroyed) return;\n this.destroyed = true;\n this.opts.source.off(\"data\", this.onData);\n if (this.opts.rawMode !== false) {\n this.opts.source.setRawMode?.(false);\n }\n this.listeners.length = 0;\n }\n\n private handle(chunk: Buffer | string): void {\n if (this.destroyed) return;\n const text = typeof chunk === \"string\" ? chunk : chunk.toString(\"utf8\");\n const keys = parseKeystrokes(text);\n for (const key of keys) {\n for (const cb of this.listeners) cb(key);\n }\n }\n}\n","const ASCII_TABLE_SIZE = 128;\nconst SPACE_ID = 0;\nconst EMPTY_ID = 1;\n\nexport class CharPool {\n private readonly strings: string[];\n private readonly map: Map<string, number>;\n private readonly ascii: Int32Array;\n\n constructor() {\n this.strings = [\" \", \"\"];\n this.map = new Map([\n [\" \", SPACE_ID],\n [\"\", EMPTY_ID],\n ]);\n this.ascii = new Int32Array(ASCII_TABLE_SIZE).fill(-1);\n this.ascii[\" \".charCodeAt(0)] = SPACE_ID;\n }\n\n intern(s: string): number {\n if (s.length === 1) {\n const code = s.charCodeAt(0);\n if (code < ASCII_TABLE_SIZE) {\n const cached = this.ascii[code]!;\n if (cached !== -1) return cached;\n const id = this.strings.length;\n this.strings.push(s);\n this.ascii[code] = id;\n this.map.set(s, id);\n return id;\n }\n }\n const existing = this.map.get(s);\n if (existing !== undefined) return existing;\n const id = this.strings.length;\n this.strings.push(s);\n this.map.set(s, id);\n return id;\n }\n\n get(id: number): string {\n return this.strings[id] ?? \" \";\n }\n\n get size(): number {\n return this.strings.length;\n }\n}\n","const NO_HYPERLINK = 0;\n\nexport class HyperlinkPool {\n private readonly strings: string[] = [\"\"];\n private readonly map = new Map<string, number>();\n\n intern(uri: string | undefined): number {\n if (!uri) return NO_HYPERLINK;\n const existing = this.map.get(uri);\n if (existing !== undefined) return existing;\n const id = this.strings.length;\n this.strings.push(uri);\n this.map.set(uri, id);\n return id;\n }\n\n get(id: number): string | undefined {\n if (id === NO_HYPERLINK) return undefined;\n return this.strings[id];\n }\n\n get size(): number {\n return this.strings.length;\n }\n}\n","export interface AnsiCode {\n readonly apply: string;\n readonly revert: string;\n}\n\nconst EMPTY_KEY = \"\";\n\nexport class StylePool {\n private readonly stacks: ReadonlyArray<AnsiCode>[] = [[]];\n private readonly idsByKey = new Map<string, number>([[EMPTY_KEY, 0]]);\n private readonly transitionCache = new Map<number, string>();\n readonly none = 0;\n\n intern(codes: ReadonlyArray<AnsiCode>): number {\n const key = stackKey(codes);\n const existing = this.idsByKey.get(key);\n if (existing !== undefined) return existing;\n const id = this.stacks.length;\n this.stacks.push(codes);\n this.idsByKey.set(key, id);\n return id;\n }\n\n transition(fromId: number, toId: number): string {\n if (fromId === toId) return \"\";\n const cacheKey = (fromId << 16) | toId;\n const cached = this.transitionCache.get(cacheKey);\n if (cached !== undefined) return cached;\n\n const from = this.stacks[fromId] ?? [];\n const to = this.stacks[toId] ?? [];\n const fromApplies = new Set(from.map((c) => c.apply));\n const toApplies = new Set(to.map((c) => c.apply));\n\n let out = \"\";\n for (const c of from) {\n if (!toApplies.has(c.apply)) out += c.revert;\n }\n for (const c of to) {\n if (!fromApplies.has(c.apply)) out += c.apply;\n }\n\n this.transitionCache.set(cacheKey, out);\n return out;\n }\n\n get size(): number {\n return this.stacks.length;\n }\n}\n\nfunction stackKey(codes: ReadonlyArray<AnsiCode>): string {\n if (codes.length === 0) return EMPTY_KEY;\n // Sort so {RED, BOLD} and {BOLD, RED} hash to the same id — style identity is the SET of codes.\n const applies = codes.map((c) => c.apply);\n applies.sort();\n return applies.join(\"\\x00\");\n}\n","import { type ReactNode, createElement } from \"react\";\nimport { type DiffPools, diffFrames } from \"../diff/diff-frames.js\";\nimport { type Cursor, type Frame, emptyFrame } from \"../diff/frame.js\";\nimport { serializePatches } from \"../diff/serialize.js\";\nimport { RendererBridgeContext } from \"../ink-compat/renderer-bridge.js\";\nimport { AppContext } from \"../ink-compat/use-app.js\";\nimport { StdoutContext, ViewportContext } from \"../ink-compat/viewport.js\";\nimport { KeystrokeContext, KeystrokeReader, type KeystrokeSource } from \"../input/index.js\";\nimport { renderViewport, renderVirtual } from \"../layout/layout.js\";\nimport type { LayoutNode } from \"../layout/node.js\";\nimport { renderToBytes } from \"../runtime/render-to-bytes.js\";\nimport { CursorContext, type CursorTarget } from \"./cursor.js\";\nimport { type HostRoot, hostToLayoutNode, reconciler } from \"./host-config.js\";\n\nexport type ScrollMode = \"scrollback\" | \"virtual\";\n\nexport interface MountOptions {\n readonly viewportWidth: number;\n readonly viewportHeight: number;\n readonly pools: DiffPools;\n readonly write: (bytes: string) => void;\n readonly cursor?: () => Cursor;\n readonly stdin?: KeystrokeSource;\n readonly onExit?: (error?: Error) => void;\n /** \"scrollback\" (default): rows that overflow viewport go to scrollback, frozen.\n * \"virtual\": full layout stays live in memory; PgUp/PgDown/Home/End scroll within. */\n readonly scroll?: ScrollMode;\n /** Real stdout stream — exposed to consumers via `inkCompat.useStdout()` so\n * components that need `.on(\"resize\", …)` / `.isTTY` etc. get the actual\n * WriteStream rather than a `{columns,rows}` fake. Defaults to process.stdout. */\n readonly stdout?: NodeJS.WriteStream;\n}\n\nexport interface Handle {\n update(element: ReactNode): void;\n resize(width: number, height: number): void;\n emitStatic(element: ReactNode): void;\n destroy(): void;\n}\n\nconst RESET_SGR = \"\\x1b[0m\";\nconst CLOSE_HYPERLINK = \"\\x1b]8;;\\x1b\\\\\";\n// alt-screen + button-event mouse + SGR coords. Shift+drag bypasses for native selection.\nconst ENTER_VIRTUAL = \"\\x1b[?1049h\\x1b[2J\\x1b[H\\x1b[?1002h\\x1b[?1006h\";\nconst LEAVE_VIRTUAL = \"\\x1b[?1006l\\x1b[?1002l\\x1b[?1000l\\x1b[?1049l\";\n\nexport function mount(element: ReactNode, opts: MountOptions): Handle {\n const scrollMode: ScrollMode = opts.scroll ?? \"scrollback\";\n let viewportWidth = opts.viewportWidth;\n let viewportHeight = opts.viewportHeight;\n let frame: Frame = emptyFrame(viewportWidth, viewportHeight);\n let reservedRows = 0;\n let promotedRows = 0;\n let scrollOffset = 0;\n let stickyBottom = true;\n let lastTotalRows = 0;\n let destroyed = false;\n let lastElement: ReactNode = element;\n\n const reader = opts.stdin ? new KeystrokeReader({ source: opts.stdin }) : null;\n\n let cursorTarget: CursorTarget | null = null;\n const setCursorTarget = (next: CursorTarget | null): void => {\n cursorTarget = next;\n if (!destroyed && root.children.length > 0) root.onCommit();\n };\n\n const computeCursor = (screenHeight: number): Cursor => {\n if (cursorTarget) {\n const rowFromBottom = Math.max(0, cursorTarget.rowFromBottom ?? 0);\n const y = Math.max(0, screenHeight - 1 - rowFromBottom);\n return {\n x: Math.max(0, cursorTarget.col),\n y,\n visible: cursorTarget.visible !== false,\n };\n }\n if (opts.cursor) return opts.cursor();\n return { x: 0, y: screenHeight, visible: true };\n };\n\n const scrollBy = (delta: number): void => {\n if (scrollMode !== \"virtual\") return;\n const window = Math.max(1, viewportHeight - 1);\n const maxOffset = Math.max(0, lastTotalRows - window);\n const next = Math.max(0, Math.min(maxOffset, scrollOffset + delta));\n if (next === scrollOffset) return;\n scrollOffset = next;\n stickyBottom = next === maxOffset;\n if (root.children.length > 0) {\n root.onCommit();\n }\n };\n\n let exitCleanup: (() => void) | null = null;\n let signalCleanup: (() => void) | null = null;\n if (scrollMode === \"virtual\") {\n opts.write(ENTER_VIRTUAL);\n if (reader) {\n reader.subscribe((k) => {\n const window = Math.max(1, viewportHeight - 1);\n if (k.pageUp) scrollBy(-window);\n else if (k.pageDown) scrollBy(window);\n else if (k.home) scrollBy(-Number.MAX_SAFE_INTEGER);\n else if (k.end) scrollBy(Number.MAX_SAFE_INTEGER);\n else if (k.wheelUp) scrollBy(-3);\n else if (k.wheelDown) scrollBy(3);\n });\n }\n if (typeof process !== \"undefined\" && process.on) {\n exitCleanup = () => {\n try {\n opts.write(LEAVE_VIRTUAL);\n } catch {\n /* stdout already closed */\n }\n };\n signalCleanup = () => process.exit(130);\n process.on(\"exit\", exitCleanup);\n process.on(\"SIGINT\", signalCleanup);\n process.on(\"SIGTERM\", signalCleanup);\n }\n }\n\n const commitScrollback = (layout: LayoutNode): void => {\n const maxHeight = Math.max(1, viewportHeight - 1);\n const split = renderViewport(layout, viewportWidth, opts.pools, maxHeight);\n const newPromote = Math.max(0, split.skipped - promotedRows);\n // Buffer every byte for this frame into ONE string so the terminal can't\n // flush between sub-steps. Multiple writes was visible flicker (modal\n // mount + streaming chunks each hitting reserve-grow + patches separately).\n let out = \"\";\n if (newPromote > 0) {\n if (frame.screen.height > 0) {\n out += `\\r\\x1b[${frame.screen.height}A\\x1b[J`;\n } else if (reservedRows === 0) {\n out += \"\\r\\x1b[J\";\n }\n out += split.serializePromoted(promotedRows, split.skipped);\n promotedRows = split.skipped;\n frame = emptyFrame(viewportWidth, viewportHeight);\n reservedRows = 0;\n }\n const screen = split.screen;\n const targetReserve = Math.min(screen.height, Math.max(0, viewportHeight - 1));\n if (targetReserve > reservedRows) {\n const delta = targetReserve - reservedRows;\n if (reservedRows === 0) out += \"\\r\";\n out += `${\"\\n\".repeat(delta)}\\x1b[${delta}A`;\n reservedRows = targetReserve;\n }\n const next: Frame = {\n screen,\n viewportWidth,\n viewportHeight,\n cursor: computeCursor(screen.height),\n };\n const patches = diffFrames(frame, next, opts.pools);\n if (patches.length > 0) out += serializePatches(patches);\n if (out.length > 0) opts.write(out);\n frame = next;\n };\n\n const commitVirtual = (layout: LayoutNode): void => {\n const window = Math.max(1, viewportHeight - 1);\n const virt = renderVirtual(layout, viewportWidth, opts.pools);\n const maxOffset = Math.max(0, virt.totalRows - window);\n if (stickyBottom || virt.totalRows < lastTotalRows) {\n scrollOffset = maxOffset;\n } else {\n scrollOffset = Math.min(scrollOffset, maxOffset);\n }\n lastTotalRows = virt.totalRows;\n const screen = virt.windowAt(scrollOffset, window);\n const targetReserve = Math.min(window, Math.max(0, viewportHeight - 1));\n let out = \"\";\n if (targetReserve > reservedRows) {\n const delta = targetReserve - reservedRows;\n if (reservedRows === 0) out += \"\\r\";\n out += `${\"\\n\".repeat(delta)}\\x1b[${delta}A`;\n reservedRows = targetReserve;\n }\n const next: Frame = {\n screen,\n viewportWidth,\n viewportHeight,\n cursor: computeCursor(screen.height),\n };\n const patches = diffFrames(frame, next, opts.pools);\n if (patches.length > 0) out += serializePatches(patches);\n if (out.length > 0) opts.write(out);\n frame = next;\n };\n\n const root: HostRoot = {\n children: [],\n onCommit: () => {\n if (destroyed) return;\n const layout = collectRootLayout(root.children);\n if (scrollMode === \"virtual\") {\n commitVirtual(layout);\n } else {\n commitScrollback(layout);\n }\n },\n };\n\n const container = reconciler.createContainer(\n root,\n 0,\n null,\n false,\n null,\n \"rsx\",\n () => {\n /* recoverable error */\n },\n null,\n );\n\n // Fires from Static's useEffect (mid-commit). queueMicrotask defers the\n // re-entrant updateContainer until the live commit fully drains —\n // otherwise root.children stays empty when renderToBytes reads it.\n const emitStatic = (node: ReactNode): void => {\n if (destroyed) return;\n queueMicrotask(() => {\n if (destroyed) return;\n const bytes = renderToBytes(node, viewportWidth, opts.pools);\n if (bytes.length === 0) return;\n let out = \"\";\n if (frame.screen.height > 0) {\n out += `\\r\\x1b[${frame.screen.height}A\\x1b[J`;\n } else {\n out += \"\\r\\x1b[J\";\n }\n out += bytes;\n opts.write(out);\n // Static bytes consumed the previously-reserved live rows — drop the\n // reservation so the next commit re-grows it from the cursor's new\n // position, otherwise live paints onto rows now in scrollback.\n frame = emptyFrame(viewportWidth, viewportHeight);\n reservedRows = 0;\n root.onCommit();\n });\n };\n\n const bridge = { emitStatic };\n\n const appApi = {\n exit: (error?: Error): void => {\n if (destroyed) return;\n queueMicrotask(() => opts.onExit?.(error));\n },\n };\n\n const wrap = (node: ReactNode): ReactNode => {\n const withApp: ReactNode = createElement(AppContext.Provider, { value: appApi }, node);\n const withBridge: ReactNode = createElement(\n RendererBridgeContext.Provider,\n { value: bridge },\n withApp,\n );\n const withViewport: ReactNode = createElement(\n ViewportContext.Provider,\n { value: { columns: viewportWidth, rows: viewportHeight } },\n withBridge,\n );\n const stdoutForCtx =\n opts.stdout ??\n (typeof process !== \"undefined\" ? (process.stdout as NodeJS.WriteStream) : undefined);\n const withStdout: ReactNode = stdoutForCtx\n ? createElement(StdoutContext.Provider, { value: stdoutForCtx }, withViewport)\n : withViewport;\n const withCursor: ReactNode = createElement(\n CursorContext.Provider,\n { value: setCursorTarget },\n withStdout,\n );\n return reader\n ? createElement(KeystrokeContext.Provider, { value: reader }, withCursor)\n : withCursor;\n };\n\n reconciler.updateContainer(wrap(element), container, null, () => {\n /* committed */\n });\n\n return {\n update(nextElement: ReactNode): void {\n if (destroyed) return;\n lastElement = nextElement;\n reconciler.updateContainer(wrap(nextElement), container, null, () => {\n /* committed */\n });\n },\n resize(width: number, height: number): void {\n if (destroyed) return;\n viewportWidth = width;\n viewportHeight = height;\n frame = emptyFrame(width, height);\n reservedRows = 0;\n promotedRows = 0;\n scrollOffset = 0;\n stickyBottom = true;\n lastTotalRows = 0;\n opts.write(\"\\x1b[2J\\x1b[H\");\n reconciler.updateContainer(wrap(lastElement), container, null, () => {\n /* committed */\n });\n },\n emitStatic,\n destroy(): void {\n if (destroyed) return;\n destroyed = true;\n reader?.destroy();\n reconciler.updateContainer(null, container, null, () => {\n /* committed */\n });\n const teardown = scrollMode === \"virtual\" ? LEAVE_VIRTUAL : \"\";\n opts.write(`${teardown}${RESET_SGR}${CLOSE_HYPERLINK}`);\n if (exitCleanup && typeof process !== \"undefined\" && process.off) {\n process.off(\"exit\", exitCleanup);\n exitCleanup = null;\n }\n if (signalCleanup && typeof process !== \"undefined\" && process.off) {\n process.off(\"SIGINT\", signalCleanup);\n process.off(\"SIGTERM\", signalCleanup);\n signalCleanup = null;\n }\n },\n };\n}\n\nfunction collectRootLayout(children: ReadonlyArray<unknown>): LayoutNode {\n const layoutChildren: LayoutNode[] = [];\n for (const c of children) {\n const child = hostToLayoutNode(c as Parameters<typeof hostToLayoutNode>[0]);\n if (child) layoutChildren.push(child);\n }\n if (layoutChildren.length === 1) return layoutChildren[0]!;\n return { kind: \"box\", children: layoutChildren };\n}\n","export const CellWidth = {\n Single: 1,\n Wide: 2,\n /** Occupies the column following a Wide glyph; renderer must skip it. */\n SpacerTail: 3,\n} as const;\n\nexport type CellWidth = (typeof CellWidth)[keyof typeof CellWidth];\n\nexport interface Cell {\n charId: number;\n styleId: number;\n hyperlinkId: number;\n width: CellWidth;\n}\n\nexport const EMPTY_CELL: Cell = Object.freeze({\n charId: 0,\n styleId: 0,\n hyperlinkId: 0,\n width: CellWidth.Single,\n});\n\nexport function cellsEqual(a: Cell, b: Cell): boolean {\n return (\n a.charId === b.charId &&\n a.styleId === b.styleId &&\n a.hyperlinkId === b.hyperlinkId &&\n a.width === b.width\n );\n}\n","import { type Cell, cellsEqual } from \"./cell.js\";\nimport type { Screen } from \"./screen.js\";\n\nexport type DiffCallback = (\n x: number,\n y: number,\n prev: Cell | undefined,\n next: Cell | undefined,\n) => boolean | undefined;\n\nexport function diffEach(prev: Screen, next: Screen, cb: DiffCallback): boolean {\n const w = Math.max(prev.width, next.width);\n const h = Math.max(prev.height, next.height);\n for (let y = 0; y < h; y++) {\n for (let x = 0; x < w; x++) {\n const a = prev.cellAt(x, y);\n const b = next.cellAt(x, y);\n if (a === b) continue;\n if (a !== undefined && b !== undefined && cellsEqual(a, b)) continue;\n if (cb(x, y, a, b) === true) return true;\n }\n }\n return false;\n}\n","import type { CharPool } from \"../pools/char-pool.js\";\nimport type { HyperlinkPool } from \"../pools/hyperlink-pool.js\";\nimport type { StylePool } from \"../pools/style-pool.js\";\nimport { type Cell, CellWidth } from \"../screen/cell.js\";\nimport { diffEach } from \"../screen/diff.js\";\nimport type { Frame } from \"./frame.js\";\nimport type { Patch } from \"./patch.js\";\n\nexport interface DiffPools {\n readonly char: CharPool;\n readonly style: StylePool;\n readonly hyperlink: HyperlinkPool;\n}\n\ninterface CursorState {\n x: number;\n y: number;\n styleId: number;\n hyperlinkId: number;\n}\n\nexport function diffFrames(prev: Frame, next: Frame, pools: DiffPools): Patch[] {\n if (prev.viewportWidth !== next.viewportWidth || prev.viewportHeight !== next.viewportHeight) {\n return fullReset(next, pools);\n }\n\n const out: Patch[] = [];\n const cursor: CursorState = {\n x: prev.cursor.x,\n y: prev.cursor.y,\n styleId: pools.style.none,\n hyperlinkId: 0,\n };\n\n diffEach(prev.screen, next.screen, (x, y, _prevCell, nextCell) => {\n moveTo(out, cursor, x, y, next.viewportWidth);\n writeCell(out, cursor, nextCell, pools);\n return undefined;\n });\n\n if (next.cursor.x !== cursor.x || next.cursor.y !== cursor.y) {\n moveTo(out, cursor, next.cursor.x, next.cursor.y, next.viewportWidth);\n }\n\n if (prev.cursor.visible !== next.cursor.visible) {\n out.push({ type: \"cursorVisible\", visible: next.cursor.visible });\n }\n\n resetTrailingState(out, cursor, pools);\n return out;\n}\n\nfunction fullReset(next: Frame, pools: DiffPools): Patch[] {\n const out: Patch[] = [{ type: \"clearTerminal\" }];\n const cursor: CursorState = { x: 0, y: 0, styleId: pools.style.none, hyperlinkId: 0 };\n for (let y = 0; y < next.screen.height; y++) {\n for (let x = 0; x < next.screen.width; x++) {\n const cell = next.screen.cellAt(x, y);\n if (!cell) continue;\n if (cell.width === CellWidth.SpacerTail) continue;\n moveTo(out, cursor, x, y, next.viewportWidth);\n writeCell(out, cursor, cell, pools);\n }\n }\n resetTrailingState(out, cursor, pools);\n return out;\n}\n\nfunction moveTo(\n out: Patch[],\n cursor: CursorState,\n targetX: number,\n targetY: number,\n viewportWidth: number,\n): void {\n if (cursor.x === targetX && cursor.y === targetY) return;\n\n if (cursor.x >= viewportWidth) {\n out.push({ type: \"carriageReturn\" });\n cursor.x = 0;\n }\n\n if (cursor.y !== targetY) {\n const dy = targetY - cursor.y;\n out.push({ type: \"carriageReturn\" });\n out.push({ type: \"cursorMove\", dx: 0, dy });\n cursor.x = 0;\n cursor.y = targetY;\n }\n\n if (cursor.x !== targetX) {\n out.push({ type: \"cursorMove\", dx: targetX - cursor.x, dy: 0 });\n cursor.x = targetX;\n }\n}\n\nfunction writeCell(\n out: Patch[],\n cursor: CursorState,\n cell: Cell | undefined,\n pools: DiffPools,\n): void {\n if (!cell) {\n transitionStyle(out, cursor, pools.style.none, pools);\n transitionHyperlink(out, cursor, 0, pools);\n out.push({ type: \"stdout\", content: \" \" });\n cursor.x++;\n return;\n }\n if (cell.width === CellWidth.SpacerTail) return;\n\n transitionStyle(out, cursor, cell.styleId, pools);\n transitionHyperlink(out, cursor, cell.hyperlinkId, pools);\n const isWide = cell.width === CellWidth.Wide;\n const charStr = pools.char.get(cell.charId);\n if (isWide) {\n // Compensation for terminal-vs-layout width disagreement on East Asian\n // Ambiguous chars: pre-write a space at col+1 (so it's blank on Western\n // terms where the glyph renders only 1 wide), then jump back, write the\n // char, then force the cursor to col+2 regardless of how many cells the\n // terminal actually advanced. Borrowed from Claude Code's logUpdate.\n out.push({ type: \"cursorTo\", col: cursor.x + 1 });\n out.push({ type: \"stdout\", content: \" \" });\n out.push({ type: \"cursorTo\", col: cursor.x });\n out.push({ type: \"stdout\", content: charStr });\n cursor.x += 2;\n out.push({ type: \"cursorTo\", col: cursor.x });\n } else {\n out.push({ type: \"stdout\", content: charStr });\n cursor.x += 1;\n }\n}\n\nfunction transitionStyle(\n out: Patch[],\n cursor: CursorState,\n targetStyleId: number,\n pools: DiffPools,\n): void {\n if (cursor.styleId === targetStyleId) return;\n const str = pools.style.transition(cursor.styleId, targetStyleId);\n if (str.length > 0) out.push({ type: \"styleStr\", str });\n cursor.styleId = targetStyleId;\n}\n\nfunction transitionHyperlink(\n out: Patch[],\n cursor: CursorState,\n targetId: number,\n pools: DiffPools,\n): void {\n if (cursor.hyperlinkId === targetId) return;\n out.push({ type: \"hyperlink\", uri: pools.hyperlink.get(targetId) ?? \"\" });\n cursor.hyperlinkId = targetId;\n}\n\nfunction resetTrailingState(out: Patch[], cursor: CursorState, pools: DiffPools): void {\n transitionStyle(out, cursor, pools.style.none, pools);\n transitionHyperlink(out, cursor, 0, pools);\n}\n","import { type Cell, EMPTY_CELL } from \"./cell.js\";\n\nexport interface Rectangle {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport class Screen {\n readonly width: number;\n readonly height: number;\n readonly cells: Cell[];\n private _damage: Rectangle | undefined;\n\n constructor(width: number, height: number) {\n this.width = Math.max(0, width | 0);\n this.height = Math.max(0, height | 0);\n this.cells = new Array<Cell>(this.width * this.height);\n for (let i = 0; i < this.cells.length; i++) this.cells[i] = EMPTY_CELL;\n this._damage = undefined;\n }\n\n get damage(): Rectangle | undefined {\n return this._damage;\n }\n\n resetDamage(): void {\n this._damage = undefined;\n }\n\n cellAt(x: number, y: number): Cell | undefined {\n if (x < 0 || x >= this.width || y < 0 || y >= this.height) return undefined;\n return this.cells[y * this.width + x];\n }\n\n writeCell(x: number, y: number, cell: Cell): void {\n if (x < 0 || x >= this.width || y < 0 || y >= this.height) return;\n this.cells[y * this.width + x] = cell;\n this.markDamage(x, y, 1, 1);\n }\n\n markDamage(x: number, y: number, w: number, h: number): void {\n if (w <= 0 || h <= 0) return;\n if (this._damage === undefined) {\n this._damage = { x, y, width: w, height: h };\n return;\n }\n const d = this._damage;\n const x1 = Math.min(d.x, x);\n const y1 = Math.min(d.y, y);\n const x2 = Math.max(d.x + d.width, x + w);\n const y2 = Math.max(d.y + d.height, y + h);\n d.x = x1;\n d.y = y1;\n d.width = x2 - x1;\n d.height = y2 - y1;\n }\n}\n","import { Screen } from \"../screen/screen.js\";\n\nexport interface Cursor {\n readonly x: number;\n readonly y: number;\n readonly visible: boolean;\n}\n\nexport interface Frame {\n readonly screen: Screen;\n readonly viewportWidth: number;\n readonly viewportHeight: number;\n readonly cursor: Cursor;\n}\n\nexport function emptyFrame(viewportWidth: number, viewportHeight: number): Frame {\n return {\n screen: new Screen(0, 0),\n viewportWidth,\n viewportHeight,\n cursor: { x: 0, y: 0, visible: true },\n };\n}\n","import type { Diff, Patch } from \"./patch.js\";\n\nconst ESC = \"\\x1b\";\nconst CSI = `${ESC}[`;\nconst ST = `${ESC}\\\\`;\n\nexport function serializePatches(patches: Diff): string {\n let out = \"\";\n for (const patch of patches) {\n out += serializeOne(patch);\n }\n return out;\n}\n\nfunction serializeOne(patch: Patch): string {\n switch (patch.type) {\n case \"stdout\":\n return patch.content;\n case \"cursorMove\":\n return cursorMove(patch.dx, patch.dy);\n case \"cursorTo\":\n return `${CSI}${patch.col + 1}G`;\n case \"cursorVisible\":\n return patch.visible ? `${CSI}?25h` : `${CSI}?25l`;\n case \"carriageReturn\":\n return \"\\r\";\n case \"styleStr\":\n return patch.str;\n case \"hyperlink\":\n return `${ESC}]8;;${patch.uri}${ST}`;\n case \"clear\":\n return clearLines(patch.count);\n case \"clearTerminal\":\n return `${CSI}2J${CSI}H`;\n }\n}\n\nfunction cursorMove(dx: number, dy: number): string {\n let out = \"\";\n if (dy > 0) out += `${CSI}${dy}B`;\n else if (dy < 0) out += `${CSI}${-dy}A`;\n if (dx > 0) out += `${CSI}${dx}C`;\n else if (dx < 0) out += `${CSI}${-dx}D`;\n return out;\n}\n\nfunction clearLines(count: number): string {\n if (count <= 0) return `\\r${CSI}J`;\n return `\\r${CSI}${count}A${CSI}J`;\n}\n","import { type ReactNode, createContext } from \"react\";\n\nexport interface RendererBridge {\n readonly emitStatic: (element: ReactNode) => void;\n}\n\nexport const RendererBridgeContext = createContext<RendererBridge | null>(null);\n","import { createContext, useContext } from \"react\";\n\nexport interface AppApi {\n readonly exit: (error?: Error) => void;\n}\n\nexport const AppContext = createContext<AppApi>({ exit: () => {} });\n\nexport function useApp(): AppApi {\n return useContext(AppContext);\n}\n","/** Mirrors Ink's useStdout — wires viewport sizes + real-stdout methods. */\n\nimport { type ReactNode, createContext, createElement, useContext, useMemo } from \"react\";\n\nexport interface ViewportSize {\n readonly columns: number;\n readonly rows: number;\n}\n\nexport const ViewportContext = createContext<ViewportSize>({ columns: 80, rows: 24 });\n\nexport const StdoutContext = createContext<NodeJS.WriteStream>(\n (typeof process !== \"undefined\" ? (process.stdout ?? null) : null) as NodeJS.WriteStream,\n);\n\nexport function StdoutProvider({\n stdout,\n children,\n}: {\n stdout: NodeJS.WriteStream;\n children: ReactNode;\n}): ReturnType<typeof createElement> {\n return createElement(StdoutContext.Provider, { value: stdout }, children);\n}\n\n/** Quacks like Ink's `useStdout().stdout`: viewport-driven `columns`/`rows`\n * + real `.on/.off/.write/.isTTY` proxied to the WriteStream. */\nexport interface InkStdout {\n readonly columns: number;\n readonly rows: number;\n readonly isTTY: boolean | undefined;\n write(data: string): boolean;\n on(event: string, listener: (...args: unknown[]) => void): unknown;\n off(event: string, listener: (...args: unknown[]) => void): unknown;\n}\n\nexport function useStdout(): { stdout: InkStdout; write: (data: string) => boolean } {\n const viewport = useContext(ViewportContext);\n const real = useContext(StdoutContext);\n // Stable identity: viewport-budget's `useEffect([stdout])` would otherwise\n // re-fire every render (the original cause of the modal-mount flicker).\n return useMemo(() => {\n const stdout: InkStdout = {\n columns: viewport.columns,\n rows: viewport.rows,\n isTTY: real ? real.isTTY : undefined,\n write: real ? (data: string) => real.write(data) : () => true,\n on: real\n ? (event: string, listener: (...args: unknown[]) => void) =>\n real.on(event as never, listener as never)\n : () => undefined,\n off: real\n ? (event: string, listener: (...args: unknown[]) => void) =>\n real.off(event as never, listener as never)\n : () => undefined,\n };\n return { stdout, write: stdout.write };\n }, [viewport.columns, viewport.rows, real]);\n}\n","import stringWidthRaw from \"string-width\";\n\n// Box drawing (U+2500..U+257F) and Block Elements (U+2580..U+259F) render as\n// width 1 on every modern terminal — pin both explicitly so the CJK-aware\n// `ambiguousIsNarrow:false` mode doesn't double-count borders or block art.\nfunction stringWidth(s: string): number {\n if (s.length === 0) return 0;\n if (s.length === 1) {\n const code = s.charCodeAt(0);\n if (code >= 0x2500 && code <= 0x259f) return 1;\n }\n return stringWidthRaw(s, { ambiguousIsNarrow: false });\n}\nimport type { Node as YogaNode } from \"yoga-layout\";\nimport type { CharPool } from \"../pools/char-pool.js\";\nimport type { HyperlinkPool } from \"../pools/hyperlink-pool.js\";\nimport type { AnsiCode, StylePool } from \"../pools/style-pool.js\";\nimport { type Cell, CellWidth } from \"../screen/cell.js\";\nimport { Screen } from \"../screen/screen.js\";\nimport type { BorderStyle } from \"./borders.js\";\nimport type { BoxNode, LayoutNode, TextNode } from \"./node.js\";\nimport {\n type BuiltTree,\n Direction,\n MeasureMode,\n type NodeMeta,\n buildYogaTree,\n} from \"./yoga-layout.js\";\n\nexport interface RenderPools {\n readonly char: CharPool;\n readonly style: StylePool;\n readonly hyperlink: HyperlinkPool;\n}\n\ninterface RowFragment {\n readonly graphemes: ReadonlyArray<{ glyph: string; width: number }>;\n readonly styleId: number;\n readonly hyperlinkId: number;\n readonly leftPad: number;\n}\n\ntype LayoutRows = RowFragment[][];\n\ninterface Laid {\n rows: LayoutRows;\n width: number;\n}\n\nexport function renderToScreen(\n node: LayoutNode,\n width: number,\n pools: RenderPools,\n maxHeight?: number,\n): Screen {\n const w = Math.max(0, width | 0);\n if (w === 0) return new Screen(0, 0);\n const laid = layout(node, w, pools);\n const cap = maxHeight !== undefined ? Math.max(0, Math.floor(maxHeight)) : laid.rows.length;\n const skip = Math.max(0, laid.rows.length - cap);\n return blitRowSlice(laid.rows, skip, laid.rows.length, w, pools);\n}\n\nexport interface ViewportSplit {\n readonly screen: Screen;\n readonly skipped: number;\n readonly totalRows: number;\n serializePromoted(fromRow: number, toRow: number): string;\n}\n\nexport function renderViewport(\n node: LayoutNode,\n width: number,\n pools: RenderPools,\n maxHeight: number,\n): ViewportSplit {\n const w = Math.max(0, width | 0);\n if (w === 0) {\n return {\n screen: new Screen(0, 0),\n skipped: 0,\n totalRows: 0,\n serializePromoted: () => \"\",\n };\n }\n const laid = layout(node, w, pools);\n const cap = Math.max(0, Math.floor(maxHeight));\n const skipped = Math.max(0, laid.rows.length - cap);\n const screen = blitRowSlice(laid.rows, skipped, laid.rows.length, w, pools);\n return {\n screen,\n skipped,\n totalRows: laid.rows.length,\n serializePromoted: (fromRow, toRow) =>\n serializeRowSlice(\n laid.rows,\n Math.max(0, fromRow),\n Math.min(toRow, laid.rows.length),\n w,\n pools,\n ),\n };\n}\n\nfunction blitRowSlice(\n rows: LayoutRows,\n fromRow: number,\n toRow: number,\n width: number,\n pools: RenderPools,\n): Screen {\n const h = Math.max(0, toRow - fromRow);\n const screen = new Screen(width, h);\n for (let y = 0; y < h; y++) {\n for (const frag of rows[y + fromRow]!) blitFragment(screen, frag, y, pools);\n }\n screen.resetDamage();\n return screen;\n}\n\nexport interface VirtualLayout {\n readonly totalRows: number;\n windowAt(scrollOffset: number, windowHeight: number): Screen;\n}\n\nexport function renderVirtual(node: LayoutNode, width: number, pools: RenderPools): VirtualLayout {\n const w = Math.max(0, width | 0);\n if (w === 0) {\n return {\n totalRows: 0,\n windowAt: () => new Screen(0, 0),\n };\n }\n const laid = layout(node, w, pools);\n return {\n totalRows: laid.rows.length,\n windowAt(scrollOffset, windowHeight) {\n const start = Math.max(0, Math.min(laid.rows.length, Math.floor(scrollOffset)));\n const end = Math.max(start, Math.min(laid.rows.length, start + Math.floor(windowHeight)));\n return blitRowSlice(laid.rows, start, end, w, pools);\n },\n };\n}\n\nfunction serializeRowSlice(\n rows: LayoutRows,\n fromRow: number,\n toRow: number,\n width: number,\n pools: RenderPools,\n): string {\n if (toRow <= fromRow) return \"\";\n const screen = blitRowSlice(rows, fromRow, toRow, width, pools);\n let out = \"\";\n let curStyle = pools.style.none;\n let curLink = 0;\n for (let y = 0; y < screen.height; y++) {\n if (y > 0) {\n out += pools.style.transition(curStyle, pools.style.none);\n curStyle = pools.style.none;\n if (curLink !== 0) {\n out += \"\\x1b]8;;\\x1b\\\\\";\n curLink = 0;\n }\n out += \"\\r\\n\";\n }\n for (let x = 0; x < screen.width; x++) {\n const cell = screen.cellAt(x, y);\n if (!cell) continue;\n if (cell.width === CellWidth.SpacerTail) continue;\n if (cell.styleId !== curStyle) {\n out += pools.style.transition(curStyle, cell.styleId);\n curStyle = cell.styleId;\n }\n if (cell.hyperlinkId !== curLink) {\n const uri = pools.hyperlink.get(cell.hyperlinkId) ?? \"\";\n out += `\\x1b]8;;${uri}\\x1b\\\\`;\n curLink = cell.hyperlinkId;\n }\n out += pools.char.get(cell.charId);\n }\n }\n out += pools.style.transition(curStyle, pools.style.none);\n if (curLink !== 0) out += \"\\x1b]8;;\\x1b\\\\\";\n out += \"\\r\\n\";\n return out;\n}\n\nfunction layout(node: LayoutNode, availableWidth: number, pools: RenderPools): Laid {\n if (availableWidth <= 0) return { rows: [], width: 0 };\n\n const built = buildYogaTree(node, pools, measureText);\n built.root.calculateLayout(availableWidth, \"auto\", Direction.LTR);\n\n // Yoga places the root at (marginLeft, marginTop) via getComputedLeft/Top,\n // and getComputedHeight/Width excludes margins. Total render bounds =\n // top-margin + content + bottom-margin (right-margin similarly for width).\n const rootTop = Math.max(0, Math.round(built.root.getComputedTop()));\n const rootLeft = Math.max(0, Math.round(built.root.getComputedLeft()));\n const innerHeight = Math.max(0, Math.ceil(built.root.getComputedHeight()));\n const innerWidth = Math.max(0, Math.ceil(built.root.getComputedWidth()));\n const bottomMargin = node.kind === \"box\" ? Math.max(0, node.marginBottom ?? 0) : 0;\n const rightMargin = node.kind === \"box\" ? Math.max(0, node.marginRight ?? 0) : 0;\n const totalHeight = rootTop + innerHeight + bottomMargin;\n const totalWidth = rootLeft + innerWidth + rightMargin;\n\n const rows: LayoutRows = [];\n for (let i = 0; i < totalHeight; i++) rows.push([]);\n\n rasterize(built.root, built, 0, 0, rows, pools);\n built.root.freeRecursive();\n\n return { rows, width: totalWidth };\n}\n\nfunction rasterize(\n yoga: YogaNode,\n built: BuiltTree,\n parentX: number,\n parentY: number,\n rows: LayoutRows,\n pools: RenderPools,\n): void {\n const meta = built.meta.get(yoga);\n if (!meta) return;\n\n const left = parentX + Math.round(yoga.getComputedLeft());\n const top = parentY + Math.round(yoga.getComputedTop());\n const width = Math.max(0, Math.round(yoga.getComputedWidth()));\n const height = Math.max(0, Math.round(yoga.getComputedHeight()));\n\n if (meta.node.kind === \"text\") {\n rasterizeText(meta.node, left, top, width, height, meta.styleId, meta.hyperlinkId, rows);\n return;\n }\n\n const box = meta.node;\n if (meta.border) {\n paintBorder(meta, box, left, top, width, height, rows, pools);\n }\n\n const childList = built.children.get(yoga) ?? [];\n for (const child of childList) {\n rasterize(child, built, left, top, rows, pools);\n }\n}\n\nfunction rasterizeText(\n text: TextNode,\n x: number,\n y: number,\n width: number,\n height: number,\n styleId: number,\n hyperlinkId: number,\n rows: LayoutRows,\n): void {\n if (width <= 0 || height <= 0 || y < 0) return;\n const segmenter = getSegmenter();\n let lineIdx = 0;\n for (const rawLine of text.content.split(\"\\n\")) {\n if (lineIdx >= height) break;\n const wrapped = wrapLine(rawLine, width, segmenter);\n if (wrapped.length === 0) {\n pushFragment(rows, y + lineIdx, { graphemes: [], styleId, hyperlinkId, leftPad: x });\n lineIdx++;\n continue;\n }\n for (const row of wrapped) {\n if (lineIdx >= height) break;\n pushFragment(rows, y + lineIdx, { graphemes: row, styleId, hyperlinkId, leftPad: x });\n lineIdx++;\n }\n }\n}\n\nfunction paintBorder(\n meta: NodeMeta,\n box: BoxNode,\n left: number,\n top: number,\n width: number,\n height: number,\n rows: LayoutRows,\n pools: RenderPools,\n): void {\n if (!meta.border || width <= 0 || height <= 0) return;\n const border = meta.border;\n const topColor = pickStyleId(box.borderTopColor ?? box.borderColor, pools);\n const bottomColor = pickStyleId(box.borderBottomColor ?? box.borderColor, pools);\n const leftColor = pickStyleId(box.borderLeftColor ?? box.borderColor, pools);\n const rightColor = pickStyleId(box.borderRightColor ?? box.borderColor, pools);\n\n if (meta.useTop) {\n paintHorizontalEdge(\n rows,\n top,\n left,\n width,\n border,\n \"top\",\n meta.useLeft,\n meta.useRight,\n topColor,\n );\n }\n if (meta.useBottom && height > 1) {\n paintHorizontalEdge(\n rows,\n top + height - 1,\n left,\n width,\n border,\n \"bottom\",\n meta.useLeft,\n meta.useRight,\n bottomColor,\n );\n }\n const innerTop = top + (meta.useTop ? 1 : 0);\n const innerBottom = top + height - (meta.useBottom ? 2 : 1);\n for (let r = innerTop; r <= innerBottom; r++) {\n if (meta.useLeft) {\n pushFragment(rows, r, {\n graphemes: [{ glyph: border.left, width: Math.max(1, stringWidth(border.left)) }],\n styleId: leftColor,\n hyperlinkId: 0,\n leftPad: left,\n });\n }\n if (meta.useRight && width > 1) {\n pushFragment(rows, r, {\n graphemes: [{ glyph: border.right, width: Math.max(1, stringWidth(border.right)) }],\n styleId: rightColor,\n hyperlinkId: 0,\n leftPad: left + width - 1,\n });\n }\n }\n}\n\nfunction paintHorizontalEdge(\n rows: LayoutRows,\n y: number,\n x: number,\n width: number,\n style: BorderStyle,\n side: \"top\" | \"bottom\",\n useLeft: boolean,\n useRight: boolean,\n styleId: number,\n): void {\n if (width <= 0 || y < 0) return;\n const corners =\n side === \"top\" ? [style.topLeft, style.topRight] : [style.bottomLeft, style.bottomRight];\n const edge = side === \"top\" ? style.top : style.bottom;\n const graphemes: Array<{ glyph: string; width: number }> = [];\n for (let i = 0; i < width; i++) {\n let glyph: string;\n if (i === 0 && useLeft) glyph = corners[0]!;\n else if (i === width - 1 && useRight) glyph = corners[1]!;\n else glyph = edge;\n graphemes.push({ glyph, width: Math.max(1, stringWidth(glyph)) });\n }\n pushFragment(rows, y, { graphemes, styleId, hyperlinkId: 0, leftPad: x });\n}\n\nfunction pushFragment(rows: LayoutRows, y: number, frag: RowFragment): void {\n if (y < 0) return;\n while (rows.length <= y) rows.push([]);\n rows[y]!.push(frag);\n}\n\nfunction pickStyleId(color: ReadonlyArray<AnsiCode> | undefined, pools: RenderPools): number {\n return color ? pools.style.intern(color) : pools.style.none;\n}\n\n// Yoga measure function for text leaves — must match wrapLine() at rasterization time.\nfunction measureText(\n content: string,\n width: number,\n widthMode: MeasureMode,\n): { width: number; height: number } {\n const segmenter = getSegmenter();\n if (widthMode === MeasureMode.Undefined || width < 0) {\n let maxW = 0;\n let lines = 0;\n for (const line of content.split(\"\\n\")) {\n lines += 1;\n const w = stringWidth(line);\n if (w > maxW) maxW = w;\n }\n return { width: maxW, height: Math.max(1, lines) };\n }\n let maxW = 0;\n let totalLines = 0;\n for (const rawLine of content.split(\"\\n\")) {\n const wrapped = wrapLine(rawLine, Math.floor(width), segmenter);\n if (wrapped.length === 0) {\n totalLines += 1;\n continue;\n }\n totalLines += wrapped.length;\n for (const row of wrapped) {\n let w = 0;\n for (const g of row) w += g.width;\n if (w > maxW) maxW = w;\n }\n }\n return { width: maxW, height: Math.max(1, totalLines) };\n}\n\nfunction wrapLine(\n line: string,\n width: number,\n segmenter: Intl.Segmenter,\n): Array<Array<{ glyph: string; width: number }>> {\n if (width <= 0) return [];\n const rows: Array<Array<{ glyph: string; width: number }>> = [];\n let current: Array<{ glyph: string; width: number }> = [];\n let used = 0;\n for (const seg of segmenter.segment(line)) {\n const glyph = seg.segment;\n const gw = Math.max(0, stringWidth(glyph));\n if (gw === 0) continue;\n if (used + gw > width) {\n if (current.length > 0) rows.push(current);\n current = [];\n used = 0;\n if (gw > width) continue;\n }\n current.push({ glyph, width: gw });\n used += gw;\n }\n if (current.length > 0) rows.push(current);\n return rows;\n}\n\nfunction blitFragment(screen: Screen, frag: RowFragment, y: number, pools: RenderPools): void {\n let x = frag.leftPad;\n for (const { glyph, width } of frag.graphemes) {\n if (x >= screen.width) break;\n const charId = pools.char.intern(glyph);\n const cell: Cell = {\n charId,\n styleId: frag.styleId,\n hyperlinkId: frag.hyperlinkId,\n width: width === 2 ? CellWidth.Wide : CellWidth.Single,\n };\n screen.writeCell(x, y, cell);\n if (width === 2 && x + 1 < screen.width) {\n screen.writeCell(x + 1, y, {\n charId: 1,\n styleId: frag.styleId,\n hyperlinkId: frag.hyperlinkId,\n width: CellWidth.SpacerTail,\n });\n }\n x += width;\n }\n}\n\nlet _segmenter: Intl.Segmenter | undefined;\nfunction getSegmenter(): Intl.Segmenter {\n if (_segmenter) return _segmenter;\n _segmenter = new Intl.Segmenter(undefined, { granularity: \"grapheme\" });\n return _segmenter;\n}\n","import Yoga, {\n Align,\n BoxSizing,\n Direction,\n Display,\n Edge,\n FlexDirection,\n Gutter,\n Justify,\n MeasureMode,\n type MeasureFunction,\n type Node as YogaNode,\n Wrap,\n} from \"yoga-layout\";\nimport type { CharPool } from \"../pools/char-pool.js\";\nimport type { HyperlinkPool } from \"../pools/hyperlink-pool.js\";\nimport type { StylePool } from \"../pools/style-pool.js\";\nimport { type BorderStyle, resolveBorderStyle } from \"./borders.js\";\nimport type { AlignItems, BoxNode, JustifyContent, LayoutNode, TextNode } from \"./node.js\";\n\nexport interface YogaPools {\n readonly char: CharPool;\n readonly style: StylePool;\n readonly hyperlink: HyperlinkPool;\n}\n\nexport interface NodeMeta {\n readonly node: LayoutNode;\n readonly border?: BorderStyle;\n readonly useTop: boolean;\n readonly useBottom: boolean;\n readonly useLeft: boolean;\n readonly useRight: boolean;\n /** Text style/hyperlink interned at build time, applied during rasterization. */\n readonly styleId: number;\n readonly hyperlinkId: number;\n}\n\nexport interface BuiltTree {\n readonly root: YogaNode;\n readonly meta: WeakMap<YogaNode, NodeMeta>;\n /** Children in tree order so the rasterizer can walk without yoga's own tree walk. */\n readonly children: ReadonlyMap<YogaNode, ReadonlyArray<YogaNode>>;\n}\n\nconst ALIGN_MAP: Record<AlignItems, Align> = {\n \"flex-start\": Align.FlexStart,\n \"flex-end\": Align.FlexEnd,\n center: Align.Center,\n stretch: Align.Stretch,\n baseline: Align.Baseline,\n};\n\nconst JUSTIFY_MAP: Record<JustifyContent, Justify> = {\n \"flex-start\": Justify.FlexStart,\n \"flex-end\": Justify.FlexEnd,\n center: Justify.Center,\n \"space-between\": Justify.SpaceBetween,\n \"space-around\": Justify.SpaceAround,\n \"space-evenly\": Justify.SpaceEvenly,\n};\n\n/** Build a yoga tree from a LayoutNode. Caller owns the root and must call freeRecursive(). */\nexport function buildYogaTree(\n node: LayoutNode,\n pools: YogaPools,\n measureText: (\n content: string,\n width: number,\n widthMode: MeasureMode,\n ) => { width: number; height: number },\n): BuiltTree {\n const meta = new WeakMap<YogaNode, NodeMeta>();\n const children = new Map<YogaNode, YogaNode[]>();\n\n const root = build(node, pools, measureText, meta, children);\n return { root, meta, children };\n}\n\nfunction build(\n node: LayoutNode,\n pools: YogaPools,\n measureText: (\n content: string,\n width: number,\n widthMode: MeasureMode,\n ) => { width: number; height: number },\n meta: WeakMap<YogaNode, NodeMeta>,\n children: Map<YogaNode, YogaNode[]>,\n): YogaNode {\n if (node.kind === \"text\") {\n return buildText(node, pools, measureText, meta);\n }\n return buildBox(node, pools, measureText, meta, children);\n}\n\nfunction buildText(\n node: TextNode,\n pools: YogaPools,\n measureText: (\n content: string,\n width: number,\n widthMode: MeasureMode,\n ) => { width: number; height: number },\n meta: WeakMap<YogaNode, NodeMeta>,\n): YogaNode {\n const yoga = Yoga.Node.create();\n yoga.setBoxSizing(BoxSizing.BorderBox);\n // Yoga's default flex-shrink is 0; CSS (and Ink) default is 1. Match CSS so\n // long text wraps to fit narrower containers instead of overflowing.\n yoga.setFlexShrink(1);\n const measure: MeasureFunction = (width, widthMode) =>\n measureText(node.content, width, widthMode);\n yoga.setMeasureFunc(measure);\n\n const styleId = node.style ? pools.style.intern(node.style) : pools.style.none;\n const hyperlinkId = pools.hyperlink.intern(node.hyperlink);\n meta.set(yoga, {\n node,\n useTop: false,\n useBottom: false,\n useLeft: false,\n useRight: false,\n styleId,\n hyperlinkId,\n });\n return yoga;\n}\n\nfunction buildBox(\n node: BoxNode,\n pools: YogaPools,\n measureText: (\n content: string,\n width: number,\n widthMode: MeasureMode,\n ) => { width: number; height: number },\n meta: WeakMap<YogaNode, NodeMeta>,\n children: Map<YogaNode, YogaNode[]>,\n): YogaNode {\n const yoga = Yoga.Node.create();\n yoga.setBoxSizing(BoxSizing.BorderBox);\n // Default shrink=1 to match CSS / Ink ergonomics — applyBoxStyle overrides if explicit.\n yoga.setFlexShrink(1);\n applyBoxStyle(yoga, node);\n\n const border = resolveBorderStyle(node.borderStyle);\n const useTop = border !== undefined && node.borderTop !== false;\n const useBottom = border !== undefined && node.borderBottom !== false;\n const useLeft = border !== undefined && node.borderLeft !== false;\n const useRight = border !== undefined && node.borderRight !== false;\n if (useTop) yoga.setBorder(Edge.Top, 1);\n if (useBottom) yoga.setBorder(Edge.Bottom, 1);\n if (useLeft) yoga.setBorder(Edge.Left, 1);\n if (useRight) yoga.setBorder(Edge.Right, 1);\n\n meta.set(yoga, {\n node,\n border,\n useTop,\n useBottom,\n useLeft,\n useRight,\n styleId: 0,\n hyperlinkId: 0,\n });\n\n const childList: YogaNode[] = [];\n for (let i = 0; i < node.children.length; i++) {\n const childYoga = build(node.children[i]!, pools, measureText, meta, children);\n yoga.insertChild(childYoga, i);\n childList.push(childYoga);\n }\n children.set(yoga, childList);\n return yoga;\n}\n\nfunction applyBoxStyle(yoga: YogaNode, node: BoxNode): void {\n if (node.flexDirection === \"row\") yoga.setFlexDirection(FlexDirection.Row);\n else if (node.flexDirection === \"row-reverse\") yoga.setFlexDirection(FlexDirection.RowReverse);\n else if (node.flexDirection === \"column-reverse\")\n yoga.setFlexDirection(FlexDirection.ColumnReverse);\n else yoga.setFlexDirection(FlexDirection.Column);\n\n if (node.flexGrow !== undefined) yoga.setFlexGrow(node.flexGrow);\n if (node.flexShrink !== undefined) yoga.setFlexShrink(node.flexShrink);\n if (node.flexBasis !== undefined) yoga.setFlexBasis(node.flexBasis);\n if (node.flexWrap === \"wrap\") yoga.setFlexWrap(Wrap.Wrap);\n else if (node.flexWrap === \"wrap-reverse\") yoga.setFlexWrap(Wrap.WrapReverse);\n\n if (node.justifyContent) yoga.setJustifyContent(JUSTIFY_MAP[node.justifyContent]);\n if (node.alignItems) yoga.setAlignItems(ALIGN_MAP[node.alignItems]);\n if (node.alignSelf) yoga.setAlignSelf(ALIGN_MAP[node.alignSelf]);\n if (node.alignContent) {\n if (node.alignContent === \"space-between\") yoga.setAlignContent(Align.SpaceBetween);\n else if (node.alignContent === \"space-around\") yoga.setAlignContent(Align.SpaceAround);\n else yoga.setAlignContent(ALIGN_MAP[node.alignContent]);\n }\n\n if (node.width !== undefined) yoga.setWidth(node.width);\n if (node.height !== undefined) yoga.setHeight(node.height);\n if (node.minWidth !== undefined) yoga.setMinWidth(node.minWidth);\n if (node.minHeight !== undefined) yoga.setMinHeight(node.minHeight);\n if (node.maxWidth !== undefined) yoga.setMaxWidth(node.maxWidth);\n if (node.maxHeight !== undefined) yoga.setMaxHeight(node.maxHeight);\n\n // gap → both row + column gutters; specific overrides win.\n if (node.gap !== undefined) yoga.setGap(Gutter.All, node.gap);\n if (node.rowGap !== undefined) yoga.setGap(Gutter.Row, node.rowGap);\n if (node.columnGap !== undefined) yoga.setGap(Gutter.Column, node.columnGap);\n\n if (node.paddingTop !== undefined) yoga.setPadding(Edge.Top, node.paddingTop);\n if (node.paddingBottom !== undefined) yoga.setPadding(Edge.Bottom, node.paddingBottom);\n if (node.paddingLeft !== undefined) yoga.setPadding(Edge.Left, node.paddingLeft);\n if (node.paddingRight !== undefined) yoga.setPadding(Edge.Right, node.paddingRight);\n\n if (node.marginTop !== undefined) yoga.setMargin(Edge.Top, node.marginTop);\n if (node.marginBottom !== undefined) yoga.setMargin(Edge.Bottom, node.marginBottom);\n if (node.marginLeft !== undefined) yoga.setMargin(Edge.Left, node.marginLeft);\n if (node.marginRight !== undefined) yoga.setMargin(Edge.Right, node.marginRight);\n\n if (node.display === \"none\") yoga.setDisplay(Display.None);\n}\n\nexport { Direction, MeasureMode };\n","export interface BorderStyle {\n readonly topLeft: string;\n readonly top: string;\n readonly topRight: string;\n readonly left: string;\n readonly right: string;\n readonly bottomLeft: string;\n readonly bottom: string;\n readonly bottomRight: string;\n}\n\nexport type BorderStyleName = \"single\" | \"double\" | \"round\" | \"bold\" | \"ascii\";\n\nconst BORDER_PRESETS: Record<BorderStyleName, BorderStyle> = {\n single: {\n topLeft: \"┌\",\n top: \"─\",\n topRight: \"┐\",\n left: \"│\",\n right: \"│\",\n bottomLeft: \"└\",\n bottom: \"─\",\n bottomRight: \"┘\",\n },\n double: {\n topLeft: \"╔\",\n top: \"═\",\n topRight: \"╗\",\n left: \"║\",\n right: \"║\",\n bottomLeft: \"╚\",\n bottom: \"═\",\n bottomRight: \"╝\",\n },\n round: {\n topLeft: \"╭\",\n top: \"─\",\n topRight: \"╮\",\n left: \"│\",\n right: \"│\",\n bottomLeft: \"╰\",\n bottom: \"─\",\n bottomRight: \"╯\",\n },\n bold: {\n topLeft: \"┏\",\n top: \"━\",\n topRight: \"┓\",\n left: \"┃\",\n right: \"┃\",\n bottomLeft: \"┗\",\n bottom: \"━\",\n bottomRight: \"┛\",\n },\n ascii: {\n topLeft: \"+\",\n top: \"-\",\n topRight: \"+\",\n left: \"|\",\n right: \"|\",\n bottomLeft: \"+\",\n bottom: \"-\",\n bottomRight: \"+\",\n },\n};\n\nexport function resolveBorderStyle(\n style: BorderStyle | BorderStyleName | undefined,\n): BorderStyle | undefined {\n if (style === undefined) return undefined;\n if (typeof style === \"string\") return BORDER_PRESETS[style];\n return style;\n}\n","/** One-shot offline render of a React tree to ANSI bytes. */\n\nimport { type ReactNode, createElement } from \"react\";\nimport type { DiffPools } from \"../diff/diff-frames.js\";\nimport { ViewportContext } from \"../ink-compat/viewport.js\";\nimport { renderToScreen } from \"../layout/layout.js\";\nimport type { LayoutNode } from \"../layout/node.js\";\nimport { type HostRoot, hostToLayoutNode, reconciler } from \"../reconciler/host-config.js\";\nimport { CellWidth } from \"../screen/cell.js\";\n\nconst ESC = \"\\x1b\";\nconst ST = `${ESC}\\\\`;\n\nexport function renderToBytes(element: ReactNode, width: number, pools: DiffPools): string {\n const layout = renderTreeToLayout(element, width);\n const screen = renderToScreen(layout, width, pools);\n if (screen.height === 0) return \"\";\n\n let out = \"\";\n let curStyle = pools.style.none;\n let curLink = 0;\n\n for (let y = 0; y < screen.height; y++) {\n if (y > 0) {\n out += pools.style.transition(curStyle, pools.style.none);\n curStyle = pools.style.none;\n if (curLink !== 0) {\n out += `${ESC}]8;;${ST}`;\n curLink = 0;\n }\n out += \"\\r\\n\";\n }\n for (let x = 0; x < screen.width; x++) {\n const cell = screen.cellAt(x, y);\n if (!cell) continue;\n if (cell.width === CellWidth.SpacerTail) continue;\n if (cell.styleId !== curStyle) {\n out += pools.style.transition(curStyle, cell.styleId);\n curStyle = cell.styleId;\n }\n if (cell.hyperlinkId !== curLink) {\n const uri = pools.hyperlink.get(cell.hyperlinkId) ?? \"\";\n out += `${ESC}]8;;${uri}${ST}`;\n curLink = cell.hyperlinkId;\n }\n out += pools.char.get(cell.charId);\n }\n }\n\n out += pools.style.transition(curStyle, pools.style.none);\n if (curLink !== 0) out += `${ESC}]8;;${ST}`;\n out += \"\\r\\n\";\n return out;\n}\n\n/** Render the element through a fresh reconciler container, walk the resulting\n * host tree to a layout node, then unmount. Synchronous: react-reconciler\n * with isPrimaryRenderer=false + LegacyMode commits eagerly. */\nfunction renderTreeToLayout(element: ReactNode, width: number): LayoutNode {\n const root: HostRoot = {\n children: [],\n onCommit: () => {\n /* one-shot — caller reads root.children directly */\n },\n };\n const container = reconciler.createContainer(\n root,\n 0, // LegacyMode — sync\n null,\n false,\n null,\n \"rsx-static\",\n () => {\n /* recoverable error */\n },\n null,\n );\n const wrapped = createElement(\n ViewportContext.Provider,\n { value: { columns: width, rows: 24 } },\n element,\n );\n reconciler.updateContainer(wrapped, container, null, () => {});\n\n const layoutChildren: LayoutNode[] = [];\n for (const c of root.children) {\n const child = hostToLayoutNode(c);\n if (child) layoutChildren.push(child);\n }\n const layout: LayoutNode =\n layoutChildren.length === 1 ? layoutChildren[0]! : { kind: \"box\", children: layoutChildren };\n\n reconciler.updateContainer(null, container, null, () => {});\n\n return layout;\n}\n","import ReactReconciler from \"react-reconciler\";\nimport { type BoxProps, HOST_BOX, HOST_TEXT, type TextProps } from \"../react/components.js\";\nimport {\n type HostBox,\n type HostNode,\n type HostText,\n hostToLayoutNode,\n makeHostBox,\n makeHostRawText,\n makeHostText,\n} from \"./host-node.js\";\n\nexport interface HostRoot {\n readonly children: HostNode[];\n onCommit: () => void;\n}\n\ntype Container = HostRoot;\ntype Type = typeof HOST_BOX | typeof HOST_TEXT | string;\ntype Props = BoxProps | TextProps;\ntype Instance = HostBox | HostText;\ntype TextInstance = ReturnType<typeof makeHostRawText>;\ntype PublicInstance = Instance;\ntype HostContext = Record<string, never>;\ntype UpdatePayload = Props;\ntype ChildSet = never;\ntype TimeoutHandle = ReturnType<typeof setTimeout>;\ntype NoTimeout = -1;\n\nconst hostConfig: ReactReconciler.HostConfig<\n Type,\n Props,\n Container,\n Instance,\n TextInstance,\n never,\n never,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n> = {\n supportsMutation: true,\n supportsPersistence: false,\n supportsHydration: false,\n // We're the only React renderer in this process. `false` would put us on\n // React's shared non-primary context-stack — re-entrant updateContainer\n // (the Static / emitStatic path) crashed against that. `true` gives us our\n // own context state, no shared-stack collisions.\n isPrimaryRenderer: true,\n noTimeout: -1,\n\n createInstance(type, props) {\n if (type === HOST_BOX) return makeHostBox(props as BoxProps);\n if (type === HOST_TEXT) return makeHostText(props as TextProps);\n throw new Error(`Reasonix renderer: unsupported element type: ${String(type)}`);\n },\n\n createTextInstance(text) {\n return makeHostRawText(text);\n },\n\n appendInitialChild(parent, child) {\n parent.children.push(child as HostNode);\n (child as HostNode).parent = parent;\n },\n\n appendChild(parent, child) {\n parent.children.push(child as HostNode);\n (child as HostNode).parent = parent;\n },\n\n appendChildToContainer(container, child) {\n container.children.push(child as HostNode);\n (child as HostNode).parent = null;\n },\n\n insertBefore(parent, child, beforeChild) {\n const idx = parent.children.indexOf(beforeChild as HostNode);\n if (idx < 0) parent.children.push(child as HostNode);\n else parent.children.splice(idx, 0, child as HostNode);\n (child as HostNode).parent = parent;\n },\n\n insertInContainerBefore(container, child, beforeChild) {\n const idx = container.children.indexOf(beforeChild as HostNode);\n if (idx < 0) container.children.push(child as HostNode);\n else container.children.splice(idx, 0, child as HostNode);\n (child as HostNode).parent = null;\n },\n\n removeChild(parent, child) {\n const idx = parent.children.indexOf(child as HostNode);\n if (idx >= 0) parent.children.splice(idx, 1);\n (child as HostNode).parent = null;\n },\n\n removeChildFromContainer(container, child) {\n const idx = container.children.indexOf(child as HostNode);\n if (idx >= 0) container.children.splice(idx, 1);\n },\n\n finalizeInitialChildren() {\n return false;\n },\n\n prepareUpdate(_instance, _type, _oldProps, newProps) {\n return newProps;\n },\n\n commitUpdate(instance, payload) {\n instance.props = payload;\n },\n\n commitTextUpdate(textInstance, _oldText, newText) {\n textInstance.text = newText;\n },\n\n resetTextContent() {\n /* no-op */\n },\n\n shouldSetTextContent() {\n return false;\n },\n\n getRootHostContext() {\n return {};\n },\n\n getChildHostContext() {\n return {};\n },\n\n getPublicInstance(instance) {\n return instance as Instance;\n },\n\n prepareForCommit() {\n return null;\n },\n\n resetAfterCommit(container) {\n container.onCommit();\n },\n\n preparePortalMount() {\n /* no-op */\n },\n\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n\n getCurrentEventPriority() {\n return DefaultEventPriority;\n },\n\n getInstanceFromNode() {\n return null;\n },\n\n beforeActiveInstanceBlur() {\n /* no-op */\n },\n\n afterActiveInstanceBlur() {\n /* no-op */\n },\n\n prepareScopeUpdate() {\n /* no-op */\n },\n\n getInstanceFromScope() {\n return null;\n },\n\n detachDeletedInstance() {\n /* no-op */\n },\n\n clearContainer(container) {\n container.children.length = 0;\n },\n};\n\nconst DefaultEventPriority = 16;\n\nexport const reconciler = ReactReconciler(hostConfig);\n\nexport { hostToLayoutNode };\n","import type { BoxNode, LayoutNode, TextNode } from \"../layout/node.js\";\nimport type { BoxProps, TextProps } from \"../react/components.js\";\n\nexport type HostType = \"box\" | \"text\" | \"raw-text\";\n\nexport interface HostBox {\n readonly type: \"box\";\n props: BoxProps;\n children: HostNode[];\n parent: HostBox | null;\n}\n\nexport interface HostText {\n readonly type: \"text\";\n props: TextProps;\n children: HostNode[];\n parent: HostBox | null;\n}\n\nexport interface HostRawText {\n readonly type: \"raw-text\";\n text: string;\n parent: HostBox | HostText | null;\n}\n\nexport type HostNode = HostBox | HostText | HostRawText;\n\nexport function makeHostBox(props: BoxProps): HostBox {\n return { type: \"box\", props, children: [], parent: null };\n}\n\nexport function makeHostText(props: TextProps): HostText {\n return { type: \"text\", props, children: [], parent: null };\n}\n\nexport function makeHostRawText(text: string): HostRawText {\n return { type: \"raw-text\", text, parent: null };\n}\n\nexport function hostToLayoutNode(node: HostNode): LayoutNode | null {\n if (node.type === \"raw-text\") {\n return { kind: \"text\", content: node.text };\n }\n if (node.type === \"text\") {\n return {\n kind: \"text\",\n content: collectText(node.children),\n ...(node.props.style ? { style: node.props.style } : {}),\n ...(node.props.hyperlink ? { hyperlink: node.props.hyperlink } : {}),\n } satisfies TextNode;\n }\n const layoutChildren: LayoutNode[] = [];\n for (const c of node.children) {\n const child = hostToLayoutNode(c);\n if (child) layoutChildren.push(child);\n }\n const p = node.props;\n const out: BoxNode = { kind: \"box\", children: layoutChildren };\n return assignBoxProps(out, p);\n}\n\nfunction collectText(children: HostNode[]): string {\n let out = \"\";\n for (const child of children) {\n if (child.type === \"raw-text\") out += child.text;\n else if (child.type === \"text\") out += collectText(child.children);\n }\n return out;\n}\n\nfunction assignBoxProps(node: BoxNode, props: BoxProps): BoxNode {\n const result: { -readonly [K in keyof BoxNode]: BoxNode[K] } = { ...node };\n\n // padding shorthand: padding > paddingX/Y > side-specific\n const padAll = props.padding;\n const padX = props.paddingX ?? padAll;\n const padY = props.paddingY ?? padAll;\n const padTop = props.paddingTop ?? padY;\n const padBottom = props.paddingBottom ?? padY;\n const padLeft = props.paddingLeft ?? padX;\n const padRight = props.paddingRight ?? padX;\n if (padTop !== undefined) result.paddingTop = padTop;\n if (padBottom !== undefined) result.paddingBottom = padBottom;\n if (padLeft !== undefined) result.paddingLeft = padLeft;\n if (padRight !== undefined) result.paddingRight = padRight;\n\n // margin shorthand: margin > marginX/Y > side-specific\n const marginAll = props.margin;\n const marginX = props.marginX ?? marginAll;\n const marginY = props.marginY ?? marginAll;\n const marginTop = props.marginTop ?? marginY;\n const marginBottom = props.marginBottom ?? marginY;\n const marginLeft = props.marginLeft ?? marginX;\n const marginRight = props.marginRight ?? marginX;\n if (marginTop !== undefined) result.marginTop = marginTop;\n if (marginBottom !== undefined) result.marginBottom = marginBottom;\n if (marginLeft !== undefined) result.marginLeft = marginLeft;\n if (marginRight !== undefined) result.marginRight = marginRight;\n\n if (props.flexDirection !== undefined) result.flexDirection = props.flexDirection;\n if (props.flexGrow !== undefined) result.flexGrow = props.flexGrow;\n if (props.flexShrink !== undefined) result.flexShrink = props.flexShrink;\n if (props.flexBasis !== undefined) result.flexBasis = props.flexBasis;\n if (props.flexWrap !== undefined) result.flexWrap = props.flexWrap;\n if (props.justifyContent !== undefined) result.justifyContent = props.justifyContent;\n if (props.alignItems !== undefined) result.alignItems = props.alignItems;\n if (props.alignSelf !== undefined) result.alignSelf = props.alignSelf;\n if (props.alignContent !== undefined) result.alignContent = props.alignContent;\n if (props.width !== undefined) result.width = props.width;\n if (props.height !== undefined) result.height = props.height;\n if (props.minWidth !== undefined) result.minWidth = props.minWidth;\n if (props.minHeight !== undefined) result.minHeight = props.minHeight;\n if (props.maxWidth !== undefined) result.maxWidth = props.maxWidth;\n if (props.maxHeight !== undefined) result.maxHeight = props.maxHeight;\n if (props.gap !== undefined) result.gap = props.gap;\n if (props.columnGap !== undefined) result.columnGap = props.columnGap;\n if (props.rowGap !== undefined) result.rowGap = props.rowGap;\n if (props.display !== undefined) result.display = props.display;\n\n if (props.borderStyle !== undefined) result.borderStyle = props.borderStyle;\n if (props.borderTop !== undefined) result.borderTop = props.borderTop;\n if (props.borderBottom !== undefined) result.borderBottom = props.borderBottom;\n if (props.borderLeft !== undefined) result.borderLeft = props.borderLeft;\n if (props.borderRight !== undefined) result.borderRight = props.borderRight;\n if (props.borderColor !== undefined) result.borderColor = props.borderColor;\n if (props.borderTopColor !== undefined) result.borderTopColor = props.borderTopColor;\n if (props.borderBottomColor !== undefined) result.borderBottomColor = props.borderBottomColor;\n if (props.borderLeftColor !== undefined) result.borderLeftColor = props.borderLeftColor;\n if (props.borderRightColor !== undefined) result.borderRightColor = props.borderRightColor;\n return result;\n}\n","/** Cursor request from React → renderer. mount() polls this on every frame commit. */\n\nimport { createContext, useContext, useEffect } from \"react\";\n\nexport interface CursorTarget {\n /** Column from the left edge of the viewport (0-based). Wide chars count as 2. */\n readonly col: number;\n /** Row from the BOTTOM of the rendered screen (0 = last row). Default 0. */\n readonly rowFromBottom?: number;\n /** Hide the terminal cursor when false. Default true. */\n readonly visible?: boolean;\n}\n\nexport type CursorSetter = (target: CursorTarget | null) => void;\n\nexport const CursorContext = createContext<CursorSetter | null>(null);\n\n/** Register / replace / clear the cursor target. Pass `null` to release. */\nexport function useCursor(target: CursorTarget | null): void {\n const setter = useContext(CursorContext);\n // Snapshot to primitive scalars so re-renders with structurally equal\n // targets don't re-fire the effect (callers usually pass fresh object literals).\n const isSet = target !== null;\n const col = target?.col ?? 0;\n const rowFromBottom = target?.rowFromBottom ?? 0;\n const visible = target?.visible !== false;\n useEffect(() => {\n if (!setter) return;\n if (!isSet) {\n setter(null);\n return;\n }\n setter({ col, rowFromBottom, visible });\n return () => setter(null);\n }, [setter, isSet, col, rowFromBottom, visible]);\n}\n","export { Box, type InkBoxProps } from \"./Box.js\";\nexport { Text, type InkTextProps } from \"./Text.js\";\nexport { Spacer } from \"./Spacer.js\";\nexport { Static, type StaticProps } from \"./Static.js\";\nexport { type RendererBridge, RendererBridgeContext } from \"./renderer-bridge.js\";\nexport { type ColorName, bgCode, fgCode } from \"./colors.js\";\nexport {\n type ViewportSize,\n StdoutContext,\n StdoutProvider,\n ViewportContext,\n useStdout,\n} from \"./viewport.js\";\nexport { type AppApi, AppContext, useApp } from \"./use-app.js\";\nexport { type InkInputHandler, type InkKey, type UseInputOptions, useInput } from \"./use-input.js\";\nexport { type InkLikeInstance, type InkLikeRenderOptions, render } from \"./render.js\";\n","// biome-ignore lint/style/useImportType: tsconfig jsx=react needs React in value scope for JSX compilation\nimport React, { type ReactNode } from \"react\";\nimport type { BorderStyleName } from \"../layout/borders.js\";\nimport type { AlignItems, FlexWrap, JustifyContent } from \"../layout/node.js\";\nimport { Box as RsxBox } from \"../react/components.js\";\nimport { fgCode } from \"./colors.js\";\n\nexport interface InkBoxProps {\n readonly children?: ReactNode;\n readonly flexDirection?: \"column\" | \"row\" | \"column-reverse\" | \"row-reverse\";\n readonly flexGrow?: number;\n readonly flexShrink?: number;\n readonly flexBasis?: number | `${number}%` | \"auto\";\n readonly flexWrap?: FlexWrap;\n readonly padding?: number;\n readonly paddingX?: number;\n readonly paddingY?: number;\n readonly paddingTop?: number;\n readonly paddingBottom?: number;\n readonly paddingLeft?: number;\n readonly paddingRight?: number;\n readonly margin?: number;\n readonly marginX?: number;\n readonly marginY?: number;\n readonly marginTop?: number;\n readonly marginBottom?: number;\n readonly marginLeft?: number;\n readonly marginRight?: number;\n readonly borderStyle?: BorderStyleName;\n readonly borderColor?: string;\n readonly borderTopColor?: string;\n readonly borderBottomColor?: string;\n readonly borderLeftColor?: string;\n readonly borderRightColor?: string;\n readonly borderTop?: boolean;\n readonly borderBottom?: boolean;\n readonly borderLeft?: boolean;\n readonly borderRight?: boolean;\n readonly width?: number | `${number}%`;\n readonly height?: number | `${number}%`;\n readonly minWidth?: number | `${number}%`;\n readonly minHeight?: number | `${number}%`;\n readonly maxWidth?: number | `${number}%`;\n readonly maxHeight?: number | `${number}%`;\n readonly justifyContent?: JustifyContent;\n readonly alignItems?: AlignItems;\n readonly alignSelf?: AlignItems;\n readonly alignContent?: AlignItems | \"space-between\" | \"space-around\";\n readonly gap?: number;\n readonly columnGap?: number;\n readonly rowGap?: number;\n readonly display?: \"flex\" | \"none\";\n}\n\nexport function Box(props: InkBoxProps): React.ReactElement {\n const borderColor = fgCode(props.borderColor);\n const borderTopColor = fgCode(props.borderTopColor);\n const borderBottomColor = fgCode(props.borderBottomColor);\n const borderLeftColor = fgCode(props.borderLeftColor);\n const borderRightColor = fgCode(props.borderRightColor);\n return (\n <RsxBox\n flexDirection={props.flexDirection ?? \"row\"}\n flexGrow={props.flexGrow}\n flexShrink={props.flexShrink}\n flexBasis={props.flexBasis}\n flexWrap={props.flexWrap}\n justifyContent={props.justifyContent}\n alignItems={props.alignItems}\n alignSelf={props.alignSelf}\n alignContent={props.alignContent}\n width={props.width}\n height={props.height}\n minWidth={props.minWidth}\n minHeight={props.minHeight}\n maxWidth={props.maxWidth}\n maxHeight={props.maxHeight}\n gap={props.gap}\n columnGap={props.columnGap}\n rowGap={props.rowGap}\n display={props.display}\n padding={props.padding}\n paddingX={props.paddingX}\n paddingY={props.paddingY}\n paddingTop={props.paddingTop}\n paddingBottom={props.paddingBottom}\n paddingLeft={props.paddingLeft}\n paddingRight={props.paddingRight}\n margin={props.margin}\n marginX={props.marginX}\n marginY={props.marginY}\n marginTop={props.marginTop}\n marginBottom={props.marginBottom}\n marginLeft={props.marginLeft}\n marginRight={props.marginRight}\n borderStyle={props.borderStyle}\n borderColor={borderColor ? [borderColor] : undefined}\n borderTopColor={borderTopColor ? [borderTopColor] : undefined}\n borderBottomColor={borderBottomColor ? [borderBottomColor] : undefined}\n borderLeftColor={borderLeftColor ? [borderLeftColor] : undefined}\n borderRightColor={borderRightColor ? [borderRightColor] : undefined}\n borderTop={props.borderTop}\n borderBottom={props.borderBottom}\n borderLeft={props.borderLeft}\n borderRight={props.borderRight}\n >\n {props.children}\n </RsxBox>\n );\n}\n","import type { AnsiCode } from \"../pools/style-pool.js\";\n\nexport type ColorName =\n | \"black\"\n | \"red\"\n | \"green\"\n | \"yellow\"\n | \"blue\"\n | \"magenta\"\n | \"cyan\"\n | \"white\"\n | \"gray\"\n | \"grey\"\n | \"blackBright\"\n | \"redBright\"\n | \"greenBright\"\n | \"yellowBright\"\n | \"blueBright\"\n | \"magentaBright\"\n | \"cyanBright\"\n | \"whiteBright\";\n\nconst FG_BASE: Record<ColorName, number> = {\n black: 30,\n red: 31,\n green: 32,\n yellow: 33,\n blue: 34,\n magenta: 35,\n cyan: 36,\n white: 37,\n gray: 90,\n grey: 90,\n blackBright: 90,\n redBright: 91,\n greenBright: 92,\n yellowBright: 93,\n blueBright: 94,\n magentaBright: 95,\n cyanBright: 96,\n whiteBright: 97,\n};\n\nconst FG_RESET = 39;\nconst BG_RESET = 49;\n\nexport function fgCode(color: string | undefined): AnsiCode | null {\n if (!color) return null;\n if (color.startsWith(\"#\")) {\n const rgb = parseHex(color);\n if (!rgb) return null;\n return { apply: `\\x1b[38;2;${rgb[0]};${rgb[1]};${rgb[2]}m`, revert: `\\x1b[${FG_RESET}m` };\n }\n const code = FG_BASE[color as ColorName];\n if (code === undefined) return null;\n return { apply: `\\x1b[${code}m`, revert: `\\x1b[${FG_RESET}m` };\n}\n\nexport function bgCode(color: string | undefined): AnsiCode | null {\n if (!color) return null;\n if (color.startsWith(\"#\")) {\n const rgb = parseHex(color);\n if (!rgb) return null;\n return { apply: `\\x1b[48;2;${rgb[0]};${rgb[1]};${rgb[2]}m`, revert: `\\x1b[${BG_RESET}m` };\n }\n const base = FG_BASE[color as ColorName];\n if (base === undefined) return null;\n const bg = base < 90 ? base + 10 : base + 10;\n return { apply: `\\x1b[${bg}m`, revert: `\\x1b[${BG_RESET}m` };\n}\n\nfunction parseHex(hex: string): [number, number, number] | null {\n const s = hex.slice(1);\n if (s.length === 3) {\n const r = Number.parseInt(s[0]! + s[0]!, 16);\n const g = Number.parseInt(s[1]! + s[1]!, 16);\n const b = Number.parseInt(s[2]! + s[2]!, 16);\n return Number.isNaN(r) ? null : [r, g, b];\n }\n if (s.length === 6) {\n const r = Number.parseInt(s.slice(0, 2), 16);\n const g = Number.parseInt(s.slice(2, 4), 16);\n const b = Number.parseInt(s.slice(4, 6), 16);\n return Number.isNaN(r) ? null : [r, g, b];\n }\n return null;\n}\n","// biome-ignore lint/style/useImportType: tsconfig jsx=react needs React in value scope for JSX compilation\nimport React, { type ReactNode } from \"react\";\nimport type { AnsiCode } from \"../pools/style-pool.js\";\nimport { Text as RsxText } from \"../react/components.js\";\nimport { bgCode, fgCode } from \"./colors.js\";\n\nexport interface InkTextProps {\n readonly children?: ReactNode;\n readonly color?: string;\n readonly backgroundColor?: string;\n readonly bold?: boolean;\n readonly dimColor?: boolean;\n readonly italic?: boolean;\n readonly underline?: boolean;\n readonly strikethrough?: boolean;\n readonly inverse?: boolean;\n readonly wrap?: \"wrap\" | \"truncate\" | \"truncate-start\" | \"truncate-middle\" | \"truncate-end\";\n}\n\nconst SGR = {\n bold: { apply: \"\\x1b[1m\", revert: \"\\x1b[22m\" },\n dim: { apply: \"\\x1b[2m\", revert: \"\\x1b[22m\" },\n italic: { apply: \"\\x1b[3m\", revert: \"\\x1b[23m\" },\n underline: { apply: \"\\x1b[4m\", revert: \"\\x1b[24m\" },\n inverse: { apply: \"\\x1b[7m\", revert: \"\\x1b[27m\" },\n strikethrough: { apply: \"\\x1b[9m\", revert: \"\\x1b[29m\" },\n} as const;\n\nexport function Text(props: InkTextProps): React.ReactElement {\n const codes: AnsiCode[] = [];\n const fg = fgCode(props.color);\n if (fg) codes.push(fg);\n const bg = bgCode(props.backgroundColor);\n if (bg) codes.push(bg);\n if (props.bold) codes.push(SGR.bold);\n if (props.dimColor) codes.push(SGR.dim);\n if (props.italic) codes.push(SGR.italic);\n if (props.underline) codes.push(SGR.underline);\n if (props.inverse) codes.push(SGR.inverse);\n if (props.strikethrough) codes.push(SGR.strikethrough);\n return <RsxText style={codes.length > 0 ? codes : undefined}>{props.children}</RsxText>;\n}\n","// biome-ignore lint/style/useImportType: tsconfig jsx=react needs React in value scope for JSX compilation\nimport React from \"react\";\nimport { Box } from \"../react/components.js\";\n\nexport function Spacer(): React.ReactElement {\n return <Box flexGrow={1} />;\n}\n","// biome-ignore lint/style/useImportType: tsconfig jsx=react needs React in value scope for JSX compilation\nimport React, { type ReactNode, useContext, useEffect, useRef } from \"react\";\nimport { Box } from \"../react/components.js\";\nimport { RendererBridgeContext } from \"./renderer-bridge.js\";\n\nexport interface StaticProps<T> {\n readonly items: ReadonlyArray<T>;\n readonly children: (item: T, index: number) => ReactNode;\n}\n\nexport function Static<T>(props: StaticProps<T>): React.ReactElement | null {\n const bridge = useContext(RendererBridgeContext);\n const lastIndex = useRef(0);\n\n useEffect(() => {\n if (!bridge) return;\n if (props.items.length < lastIndex.current) {\n lastIndex.current = props.items.length;\n return;\n }\n if (props.items.length === lastIndex.current) return;\n const fresh = props.items.slice(lastIndex.current);\n const startIndex = lastIndex.current;\n lastIndex.current = props.items.length;\n bridge.emitStatic(\n <Box flexDirection=\"column\">\n {fresh.map((item, i) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: Static items are positional and append-only\n <React.Fragment key={`s-${startIndex + i}`}>\n {props.children(item, startIndex + i)}\n </React.Fragment>\n ))}\n </Box>,\n );\n }, [bridge, props.items, props.children]);\n\n if (bridge) return null;\n return (\n <Box flexDirection=\"column\">\n {props.items.map((item, i) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: fallback path with no bridge — positional keys are fine\n <React.Fragment key={`s-${i}`}>{props.children(item, i)}</React.Fragment>\n ))}\n </Box>\n );\n}\n","import { type Keystroke, useKeystroke } from \"../input/index.js\";\n\nexport interface InkKey {\n readonly upArrow: boolean;\n readonly downArrow: boolean;\n readonly leftArrow: boolean;\n readonly rightArrow: boolean;\n readonly pageDown: boolean;\n readonly pageUp: boolean;\n readonly return: boolean;\n readonly escape: boolean;\n readonly ctrl: boolean;\n readonly shift: boolean;\n readonly tab: boolean;\n readonly backspace: boolean;\n readonly delete: boolean;\n readonly meta: boolean;\n}\n\nexport type InkInputHandler = (input: string, key: InkKey) => void;\n\nexport interface UseInputOptions {\n readonly isActive?: boolean;\n}\n\nexport function useInput(handler: InkInputHandler, options: UseInputOptions = {}): void {\n const active = options.isActive !== false;\n useKeystroke((k: Keystroke) => {\n if (!active) return;\n handler(k.input ?? \"\", toInkKey(k));\n });\n}\n\nfunction toInkKey(k: Keystroke): InkKey {\n return {\n upArrow: k.upArrow,\n downArrow: k.downArrow,\n leftArrow: k.leftArrow,\n rightArrow: k.rightArrow,\n pageDown: k.pageDown,\n pageUp: k.pageUp,\n return: k.return,\n escape: k.escape,\n ctrl: k.ctrl,\n shift: k.shift,\n tab: k.tab,\n backspace: k.backspace,\n delete: k.delete,\n meta: k.meta,\n };\n}\n","/** Ink-shaped render() that mounts a React tree on the cell-diff renderer. */\n\nimport type { ReactNode } from \"react\";\nimport { CharPool } from \"../pools/char-pool.js\";\nimport { HyperlinkPool } from \"../pools/hyperlink-pool.js\";\nimport { StylePool } from \"../pools/style-pool.js\";\nimport { type Handle, mount } from \"../reconciler/mount.js\";\n\nexport interface InkLikeRenderOptions {\n readonly stdout?: NodeJS.WriteStream;\n readonly stdin?: NodeJS.ReadStream;\n readonly stderr?: NodeJS.WriteStream;\n /** Default true. Listens for Ctrl+C on stdin and unmounts. */\n readonly exitOnCtrlC?: boolean;\n /** Ink had this; we don't patch console, so this option is accepted but ignored. */\n readonly patchConsole?: boolean;\n}\n\nexport interface InkLikeInstance {\n rerender(element: ReactNode): void;\n unmount(): void;\n waitUntilExit(): Promise<void>;\n cleanup(): void;\n clear(): void;\n}\n\nexport function render(element: ReactNode, opts: InkLikeRenderOptions = {}): InkLikeInstance {\n const stdout = opts.stdout ?? process.stdout;\n const stdin = opts.stdin ?? process.stdin;\n const exitOnCtrlC = opts.exitOnCtrlC !== false;\n\n const pools = {\n char: new CharPool(),\n style: new StylePool(),\n hyperlink: new HyperlinkPool(),\n };\n\n let resolveExit: () => void = () => {};\n let exitError: Error | undefined;\n const exitPromise = new Promise<void>((resolve, reject) => {\n resolveExit = () => {\n if (exitError) reject(exitError);\n else resolve();\n };\n });\n\n let destroyed = false;\n let handle: Handle | null = null;\n\n const onResize = (): void => {\n if (destroyed || !handle) return;\n handle.resize(stdout.columns ?? 80, stdout.rows ?? 24);\n };\n\n const onCtrlCData = (chunk: Buffer | string): void => {\n if (destroyed || !exitOnCtrlC) return;\n const text = typeof chunk === \"string\" ? chunk : chunk.toString(\"utf8\");\n // Ctrl+C in raw mode is a literal \\x03; outside raw mode the terminal turns\n // it into SIGINT and we never see it here. Either path lands in unmount.\n if (text.includes(\"\\x03\")) instance.unmount();\n };\n\n handle = mount(element, {\n viewportWidth: stdout.columns ?? 80,\n viewportHeight: stdout.rows ?? 24,\n pools,\n write: (bytes) => stdout.write(bytes),\n stdin,\n stdout,\n onExit: (err) => {\n if (destroyed) return;\n if (err) exitError = err;\n // Tear down on app-driven exit (useApp().exit()).\n instance.unmount();\n },\n });\n\n stdout.on(\"resize\", onResize);\n stdin.on(\"data\", onCtrlCData);\n\n const sigintListener = (): void => {\n if (!destroyed) instance.unmount();\n };\n if (exitOnCtrlC) process.on(\"SIGINT\", sigintListener);\n\n const instance: InkLikeInstance = {\n rerender(next) {\n if (destroyed || !handle) return;\n handle.update(next);\n },\n unmount() {\n if (destroyed) return;\n destroyed = true;\n stdout.off(\"resize\", onResize);\n stdin.off(\"data\", onCtrlCData);\n if (exitOnCtrlC) process.off(\"SIGINT\", sigintListener);\n handle?.destroy();\n handle = null;\n resolveExit();\n },\n waitUntilExit() {\n return exitPromise;\n },\n cleanup() {\n // Ink uses cleanup() to clear listeners without unmounting; for our renderer\n // the listeners are bound to the handle's lifetime, so this is a no-op\n // unless explicitly unmounting.\n },\n clear() {\n if (destroyed) return;\n stdout.write(\"\\x1b[2J\\x1b[H\");\n },\n };\n\n return instance;\n}\n","import { Fragment, type ReactElement, type ReactNode, isValidElement } from \"react\";\nimport { type RenderPools, renderToScreen } from \"../layout/layout.js\";\nimport type { BoxNode, LayoutNode, TextNode } from \"../layout/node.js\";\nimport type { Screen } from \"../screen/screen.js\";\nimport { type BoxProps, HOST_BOX, HOST_TEXT, type TextProps } from \"./components.js\";\n\nexport interface RenderOptions {\n readonly width: number;\n readonly pools: RenderPools;\n}\n\nexport function render(element: ReactNode, opts: RenderOptions): Screen {\n const node = treeToLayoutNode(element) ?? emptyBox();\n return renderToScreen(node, opts.width, opts.pools);\n}\n\nfunction treeToLayoutNode(element: ReactNode): LayoutNode | null {\n if (element === null || element === undefined || typeof element === \"boolean\") return null;\n if (typeof element === \"string\" || typeof element === \"number\") {\n return { kind: \"text\", content: String(element) };\n }\n if (Array.isArray(element)) {\n const children = element.map(treeToLayoutNode).filter(notNull);\n return children.length > 0 ? { kind: \"box\", children } : null;\n }\n if (isValidElement(element)) {\n return elementToLayoutNode(element);\n }\n return null;\n}\n\nfunction elementToLayoutNode(element: ReactElement): LayoutNode | null {\n const type = element.type;\n const props = element.props as { children?: ReactNode };\n\n if (type === HOST_BOX) {\n const boxProps = element.props as BoxProps;\n const children = childrenToLayoutNodes(props.children);\n return assignAllBoxProps({ kind: \"box\", children }, boxProps);\n }\n\n if (type === HOST_TEXT) {\n const textProps = element.props as TextProps;\n return {\n kind: \"text\",\n content: collectText(textProps.children),\n ...(textProps.style ? { style: textProps.style } : {}),\n ...(textProps.hyperlink ? { hyperlink: textProps.hyperlink } : {}),\n } satisfies TextNode;\n }\n\n if (type === Fragment) {\n const children = childrenToLayoutNodes(props.children);\n return children.length === 1 ? children[0]! : { kind: \"box\", children };\n }\n\n if (typeof type === \"function\") {\n const Component = type as (props: unknown) => ReactNode;\n return treeToLayoutNode(Component(props));\n }\n\n return null;\n}\n\nfunction childrenToLayoutNodes(children: ReactNode): LayoutNode[] {\n if (children === null || children === undefined || typeof children === \"boolean\") return [];\n if (Array.isArray(children)) {\n return children.map(treeToLayoutNode).filter(notNull);\n }\n const node = treeToLayoutNode(children);\n return node ? [node] : [];\n}\n\nfunction collectText(children: ReactNode): string {\n if (children === null || children === undefined || typeof children === \"boolean\") return \"\";\n if (typeof children === \"string\") return children;\n if (typeof children === \"number\") return String(children);\n if (Array.isArray(children)) {\n return children.map(collectText).join(\"\");\n }\n if (isValidElement(children)) {\n const inner = (children.props as { children?: ReactNode }).children;\n return collectText(inner);\n }\n return \"\";\n}\n\nfunction emptyBox(): BoxNode {\n return { kind: \"box\", children: [] };\n}\n\nfunction assignAllBoxProps(node: BoxNode, props: BoxProps): BoxNode {\n const r: { -readonly [K in keyof BoxNode]: BoxNode[K] } = { ...node };\n const padAll = props.padding;\n const padX = props.paddingX ?? padAll;\n const padY = props.paddingY ?? padAll;\n if ((props.paddingTop ?? padY) !== undefined) r.paddingTop = props.paddingTop ?? padY;\n if ((props.paddingBottom ?? padY) !== undefined) r.paddingBottom = props.paddingBottom ?? padY;\n if ((props.paddingLeft ?? padX) !== undefined) r.paddingLeft = props.paddingLeft ?? padX;\n if ((props.paddingRight ?? padX) !== undefined) r.paddingRight = props.paddingRight ?? padX;\n const marginAll = props.margin;\n const marginX = props.marginX ?? marginAll;\n const marginY = props.marginY ?? marginAll;\n if ((props.marginTop ?? marginY) !== undefined) r.marginTop = props.marginTop ?? marginY;\n if ((props.marginBottom ?? marginY) !== undefined) r.marginBottom = props.marginBottom ?? marginY;\n if ((props.marginLeft ?? marginX) !== undefined) r.marginLeft = props.marginLeft ?? marginX;\n if ((props.marginRight ?? marginX) !== undefined) r.marginRight = props.marginRight ?? marginX;\n if (props.flexDirection !== undefined) r.flexDirection = props.flexDirection;\n if (props.flexGrow !== undefined) r.flexGrow = props.flexGrow;\n if (props.flexShrink !== undefined) r.flexShrink = props.flexShrink;\n if (props.flexBasis !== undefined) r.flexBasis = props.flexBasis;\n if (props.flexWrap !== undefined) r.flexWrap = props.flexWrap;\n if (props.justifyContent !== undefined) r.justifyContent = props.justifyContent;\n if (props.alignItems !== undefined) r.alignItems = props.alignItems;\n if (props.alignSelf !== undefined) r.alignSelf = props.alignSelf;\n if (props.alignContent !== undefined) r.alignContent = props.alignContent;\n if (props.width !== undefined) r.width = props.width;\n if (props.height !== undefined) r.height = props.height;\n if (props.minWidth !== undefined) r.minWidth = props.minWidth;\n if (props.minHeight !== undefined) r.minHeight = props.minHeight;\n if (props.maxWidth !== undefined) r.maxWidth = props.maxWidth;\n if (props.maxHeight !== undefined) r.maxHeight = props.maxHeight;\n if (props.gap !== undefined) r.gap = props.gap;\n if (props.columnGap !== undefined) r.columnGap = props.columnGap;\n if (props.rowGap !== undefined) r.rowGap = props.rowGap;\n if (props.display !== undefined) r.display = props.display;\n if (props.borderStyle !== undefined) r.borderStyle = props.borderStyle;\n if (props.borderTop !== undefined) r.borderTop = props.borderTop;\n if (props.borderBottom !== undefined) r.borderBottom = props.borderBottom;\n if (props.borderLeft !== undefined) r.borderLeft = props.borderLeft;\n if (props.borderRight !== undefined) r.borderRight = props.borderRight;\n if (props.borderColor !== undefined) r.borderColor = props.borderColor;\n if (props.borderTopColor !== undefined) r.borderTopColor = props.borderTopColor;\n if (props.borderBottomColor !== undefined) r.borderBottomColor = props.borderBottomColor;\n if (props.borderLeftColor !== undefined) r.borderLeftColor = props.borderLeftColor;\n if (props.borderRightColor !== undefined) r.borderRightColor = props.borderRightColor;\n return r;\n}\n\nfunction notNull<T>(v: T | null): v is T {\n return v !== null;\n}\n"],"mappings":";;;;;;AAAA,OAAO,WAAkD;AAKlD,IAAM,WAAW;AACjB,IAAM,YAAY;AAuDlB,SAAS,IAAI,OAA+B;AACjD,SAAO,MAAM,cAAc,UAAU,KAAK;AAC5C;AAEO,SAAS,KAAK,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,UAAU,OAAO,MAAM,KAAK;AAAA,IACpC;AAAA,IACA;AAAA,IACA,QAAQ,CAAC,QAAQ;AACf,UAAI,UAAW;AACf,UAAI,IAAK,aAAY;AAErB,eAAS,QAAQ;AAAA,IACnB;AAAA,EACF,CAAC;AAED,SAAO,GAAG,UAAU,QAAQ;AAC5B,QAAM,GAAG,QAAQ,WAAW;AAE5B,QAAM,iBAAiB,MAAY;AACjC,QAAI,CAAC,UAAW,UAAS,QAAQ;AAAA,EACnC;AACA,MAAI,YAAa,SAAQ,GAAG,UAAU,cAAc;AAEpD,QAAM,WAA4B;AAAA,IAChC,SAAS,MAAM;AACb,UAAI,aAAa,CAAC,OAAQ;AAC1B,aAAO,OAAO,IAAI;AAAA,IACpB;AAAA,IACA,UAAU;AACR,UAAI,UAAW;AACf,kBAAY;AACZ,aAAO,IAAI,UAAU,QAAQ;AAC7B,YAAM,IAAI,QAAQ,WAAW;AAC7B,UAAI,YAAa,SAAQ,IAAI,UAAU,cAAc;AACrD,cAAQ,QAAQ;AAChB,eAAS;AACT,kBAAY;AAAA,IACd;AAAA,IACA,gBAAgB;AACd,aAAO;AAAA,IACT;AAAA,IACA,UAAU;AAAA,IAIV;AAAA,IACA,QAAQ;AACN,UAAI,UAAW;AACf,aAAO,MAAM,eAAe;AAAA,IAC9B;AAAA,EACF;AAEA,SAAO;AACT;;;ACnHA,SAAS,UAA6C,sBAAsB;","names":["part","id","createElement","createContext","createContext","useContext","createContext","useContext","measureText","maxW","createElement","ESC","ST","layout","createElement","createContext","useContext","useEffect","layout","createElement","Box","Text","React","Box","React","React","Text","React","React","React","React","useContext","useEffect","useContext","useEffect","React"]}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
ApprovalCard,
|
|
4
|
-
ViewportBudgetProvider,
|
|
5
|
-
useReserveRows
|
|
6
|
-
} from "./chunk-BGTXZKNY.js";
|
|
7
|
-
import {
|
|
8
|
-
CharPool,
|
|
9
|
-
HyperlinkPool,
|
|
10
|
-
StylePool,
|
|
11
|
-
ink_compat_exports,
|
|
12
|
-
mount,
|
|
13
|
-
useKeystroke
|
|
14
|
-
} from "./chunk-JHXQDL7B.js";
|
|
15
|
-
import "./chunk-2H7UOFLK.js";
|
|
16
|
-
|
|
17
|
-
// src/cli/commands/flicker-demo.tsx
|
|
18
|
-
import React, { useEffect, useState } from "react";
|
|
19
|
-
var BRAND = "#79c0ff";
|
|
20
|
-
var FAINT = "#6e7681";
|
|
21
|
-
var ACCENT = "#d2a8ff";
|
|
22
|
-
var OK = "#7ee787";
|
|
23
|
-
var META = "#8b949e";
|
|
24
|
-
var SPINNER = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
25
|
-
function Header({ phase }) {
|
|
26
|
-
return /* @__PURE__ */ React.createElement(ink_compat_exports.Box, { flexDirection: "row", gap: 1 }, /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: BRAND, bold: true }, "\u25C8 Reasonix"), /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: FAINT }, "flicker-demo \xB7 phase:"), /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: ACCENT, bold: true }, phase), /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: FAINT }, "\xB7 Esc to exit"));
|
|
27
|
-
}
|
|
28
|
-
function StreamingCard({
|
|
29
|
-
text,
|
|
30
|
-
done,
|
|
31
|
-
frame
|
|
32
|
-
}) {
|
|
33
|
-
const lines = text.length > 0 ? text.split("\n") : [""];
|
|
34
|
-
const visible = lines.slice(-4);
|
|
35
|
-
const glyph = done ? "\u2039" : "\u25B8";
|
|
36
|
-
const head = done ? "reply" : "writing\u2026";
|
|
37
|
-
const tone = done ? OK : BRAND;
|
|
38
|
-
return /* @__PURE__ */ React.createElement(ink_compat_exports.Box, { flexDirection: "column", marginTop: 1 }, /* @__PURE__ */ React.createElement(ink_compat_exports.Box, { flexDirection: "row", gap: 1 }, /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: tone }, glyph), /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: tone, bold: true }, head), !done ? /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: tone }, SPINNER[frame % SPINNER.length] ?? "\xB7") : null), visible.map((line, i) => /* @__PURE__ */ React.createElement(ink_compat_exports.Box, { key: `s-${i}-${line.length}`, paddingLeft: 2 }, /* @__PURE__ */ React.createElement(ink_compat_exports.Text, null, line || " "))));
|
|
39
|
-
}
|
|
40
|
-
var OPTIONS = [
|
|
41
|
-
"1 \xB7 keep current approach",
|
|
42
|
-
"2 \xB7 rewrite with the alternative",
|
|
43
|
-
"3 \xB7 ask me a clarifying question first",
|
|
44
|
-
"Let me type my own answer",
|
|
45
|
-
"Cancel \u2014 drop the question"
|
|
46
|
-
];
|
|
47
|
-
function ChoiceModalInline() {
|
|
48
|
-
return /* @__PURE__ */ React.createElement(ink_compat_exports.Box, { flexDirection: "column", marginTop: 1 }, /* @__PURE__ */ React.createElement(ink_compat_exports.Box, { flexDirection: "row", gap: 1 }, /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: ACCENT, bold: true }, "?"), /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: ACCENT, bold: true }, "which path should I take?"), /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: FAINT }, "\xB7 awaiting")), /* @__PURE__ */ React.createElement(ink_compat_exports.Box, { flexDirection: "column", paddingLeft: 2 }, OPTIONS.map((opt, i) => (
|
|
49
|
-
// biome-ignore lint/suspicious/noArrayIndexKey: static option list, never reordered
|
|
50
|
-
/* @__PURE__ */ React.createElement(ink_compat_exports.Box, { key: `o-${i}`, flexDirection: "row", gap: 1 }, /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: i === 0 ? BRAND : META }, i === 0 ? "\u25B8" : " "), /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: i === 0 ? BRAND : META, bold: i === 0 }, opt))
|
|
51
|
-
)), /* @__PURE__ */ React.createElement(ink_compat_exports.Box, { marginTop: 1 }, /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: FAINT }, "\u2500".repeat(40))), /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: FAINT }, "\u2191\u2193 pick \xB7 \u23CE confirm \xB7 esc cancel")));
|
|
52
|
-
}
|
|
53
|
-
function ChoiceModalReal() {
|
|
54
|
-
useReserveRows("modal", { min: 6, max: 12 });
|
|
55
|
-
return /* @__PURE__ */ React.createElement(ApprovalCard, { tone: "info", title: "which path should I take?", metaRight: "awaiting" }, OPTIONS.map((opt, i) => (
|
|
56
|
-
// biome-ignore lint/suspicious/noArrayIndexKey: static option list, never reordered
|
|
57
|
-
/* @__PURE__ */ React.createElement(ink_compat_exports.Box, { key: `r-${i}`, flexDirection: "row", gap: 1 }, /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: i === 0 ? BRAND : META }, i === 0 ? "\u25B8" : " "), /* @__PURE__ */ React.createElement(ink_compat_exports.Text, { color: i === 0 ? BRAND : META, bold: i === 0 }, opt))
|
|
58
|
-
)));
|
|
59
|
-
}
|
|
60
|
-
var STREAM_TEXT = `analyzing the failing test on src/loop.test.ts
|
|
61
|
-
the assertion on line 42 expects the parser to drop the trailing tool-call marker
|
|
62
|
-
but the new tokenizer keeps it; two paths forward \u2014 patch the tokenizer's strip
|
|
63
|
-
step, or update the expectation. The trade-off is whether downstream consumers
|
|
64
|
-
rely on the marker to detect partial tool-call output.`;
|
|
65
|
-
function FlickerShell({ onExit, realModal }) {
|
|
66
|
-
const [streamText, setStreamText] = useState("");
|
|
67
|
-
const [streamDone, setStreamDone] = useState(false);
|
|
68
|
-
const [showModal, setShowModal] = useState(false);
|
|
69
|
-
const [frame, setFrame] = useState(0);
|
|
70
|
-
const [phase, setPhase] = useState("idle");
|
|
71
|
-
useKeystroke((k) => {
|
|
72
|
-
if (k.escape) onExit();
|
|
73
|
-
});
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
if (streamDone) return;
|
|
76
|
-
const id = setInterval(() => setFrame((f) => f + 1), 80);
|
|
77
|
-
return () => clearInterval(id);
|
|
78
|
-
}, [streamDone]);
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
let cancelled = false;
|
|
81
|
-
const sleep = (ms) => new Promise((resolve) => {
|
|
82
|
-
setTimeout(() => resolve(), ms);
|
|
83
|
-
});
|
|
84
|
-
const cycle = async () => {
|
|
85
|
-
while (!cancelled) {
|
|
86
|
-
setStreamText("");
|
|
87
|
-
setStreamDone(false);
|
|
88
|
-
setShowModal(false);
|
|
89
|
-
setPhase("streaming");
|
|
90
|
-
await sleep(400);
|
|
91
|
-
if (cancelled) return;
|
|
92
|
-
const chunks = STREAM_TEXT.split(" ");
|
|
93
|
-
let revealed = "";
|
|
94
|
-
for (let i = 0; i < chunks.length / 2; i++) {
|
|
95
|
-
if (cancelled) return;
|
|
96
|
-
revealed += `${chunks[i]} `;
|
|
97
|
-
setStreamText(revealed);
|
|
98
|
-
await sleep(80);
|
|
99
|
-
}
|
|
100
|
-
setPhase("streaming + modal");
|
|
101
|
-
setShowModal(true);
|
|
102
|
-
for (let i = Math.floor(chunks.length / 2); i < chunks.length; i++) {
|
|
103
|
-
if (cancelled) return;
|
|
104
|
-
revealed += `${chunks[i]} `;
|
|
105
|
-
setStreamText(revealed);
|
|
106
|
-
await sleep(80);
|
|
107
|
-
}
|
|
108
|
-
setStreamDone(true);
|
|
109
|
-
setPhase("done + modal");
|
|
110
|
-
await sleep(2500);
|
|
111
|
-
if (cancelled) return;
|
|
112
|
-
setShowModal(false);
|
|
113
|
-
setPhase("idle");
|
|
114
|
-
await sleep(800);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
void cycle();
|
|
118
|
-
return () => {
|
|
119
|
-
cancelled = true;
|
|
120
|
-
};
|
|
121
|
-
}, []);
|
|
122
|
-
return /* @__PURE__ */ React.createElement(ink_compat_exports.Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Header, { phase: `${phase}${realModal ? " (real)" : ""}` }), streamText.length > 0 ? /* @__PURE__ */ React.createElement(StreamingCard, { text: streamText.trim(), done: streamDone, frame }) : null, showModal ? realModal ? /* @__PURE__ */ React.createElement(ChoiceModalReal, null) : /* @__PURE__ */ React.createElement(ChoiceModalInline, null) : null);
|
|
123
|
-
}
|
|
124
|
-
async function runFlickerDemo(opts = {}) {
|
|
125
|
-
const stdout = opts.stdout ?? process.stdout;
|
|
126
|
-
const stdin = opts.stdin ?? process.stdin;
|
|
127
|
-
if (!stdin.isTTY || !stdout.isTTY) {
|
|
128
|
-
process.stderr.write("flicker-demo requires an interactive TTY.\n");
|
|
129
|
-
process.exit(1);
|
|
130
|
-
}
|
|
131
|
-
const pools = {
|
|
132
|
-
char: new CharPool(),
|
|
133
|
-
style: new StylePool(),
|
|
134
|
-
hyperlink: new HyperlinkPool()
|
|
135
|
-
};
|
|
136
|
-
let resolveExit = () => {
|
|
137
|
-
};
|
|
138
|
-
const exited = new Promise((resolve) => {
|
|
139
|
-
resolveExit = resolve;
|
|
140
|
-
});
|
|
141
|
-
const realModal = !!opts.realModal;
|
|
142
|
-
const tree = realModal ? /* @__PURE__ */ React.createElement(ViewportBudgetProvider, null, /* @__PURE__ */ React.createElement(FlickerShell, { onExit: () => resolveExit(), realModal: true })) : /* @__PURE__ */ React.createElement(FlickerShell, { onExit: () => resolveExit(), realModal: false });
|
|
143
|
-
const handle = mount(tree, {
|
|
144
|
-
viewportWidth: stdout.columns ?? 80,
|
|
145
|
-
viewportHeight: stdout.rows ?? 24,
|
|
146
|
-
pools,
|
|
147
|
-
write: (bytes) => stdout.write(bytes),
|
|
148
|
-
stdin,
|
|
149
|
-
stdout,
|
|
150
|
-
onExit: () => resolveExit()
|
|
151
|
-
});
|
|
152
|
-
const onResize = () => handle.resize(stdout.columns ?? 80, stdout.rows ?? 24);
|
|
153
|
-
stdout.on("resize", onResize);
|
|
154
|
-
try {
|
|
155
|
-
await exited;
|
|
156
|
-
} finally {
|
|
157
|
-
stdout.off("resize", onResize);
|
|
158
|
-
handle.destroy();
|
|
159
|
-
stdin.pause();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
export {
|
|
163
|
-
runFlickerDemo
|
|
164
|
-
};
|
|
165
|
-
//# sourceMappingURL=flicker-demo-MOB6GAW4.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli/commands/flicker-demo.tsx"],"sourcesContent":["/** Reproduces the streaming-card + ChoiceConfirm-style modal scenario the user\n * reports flickers on. Loops continuously: streaming card grows for ~1.2s,\n * modal pops up below, streaming continues for ~1.5s, modal stays for ~3s,\n * everything tears down, sleep, repeat. Watch the live region — any visible\n * blank rows / repaint flashes during the modal-mount transition is the bug.\n *\n * Use --real-modal to mirror the actual chat flow more closely:\n * - wrap the modal in ViewportBudgetProvider + useReserveRows\n * - use the real ApprovalCard (with dynamic-width horizontal rule)\n * Without the flag, the modal is hand-rolled — equivalent layout, no budget. */\n\n// biome-ignore lint/style/useImportType: tsconfig jsx=react needs React in value scope for JSX compilation\nimport React, { useEffect, useState } from \"react\";\nimport {\n CharPool,\n type Handle,\n HyperlinkPool,\n StylePool,\n inkCompat,\n mount,\n useKeystroke,\n} from \"../../renderer/index.js\";\nimport { ApprovalCard } from \"../ui/cards/ApprovalCard.js\";\nimport { ViewportBudgetProvider, useReserveRows } from \"../ui/layout/viewport-budget.js\";\n\nconst BRAND = \"#79c0ff\";\nconst FAINT = \"#6e7681\";\nconst ACCENT = \"#d2a8ff\";\nconst OK = \"#7ee787\";\nconst META = \"#8b949e\";\n\nconst SPINNER = [\"⠋\", \"⠙\", \"⠹\", \"⠸\", \"⠼\", \"⠴\", \"⠦\", \"⠧\", \"⠇\", \"⠏\"] as const;\n\ninterface FlickerShellProps {\n readonly onExit: () => void;\n readonly realModal: boolean;\n}\n\nfunction Header({ phase }: { phase: string }): React.ReactElement {\n return (\n <inkCompat.Box flexDirection=\"row\" gap={1}>\n <inkCompat.Text color={BRAND} bold>\n ◈ Reasonix\n </inkCompat.Text>\n <inkCompat.Text color={FAINT}>flicker-demo · phase:</inkCompat.Text>\n <inkCompat.Text color={ACCENT} bold>\n {phase}\n </inkCompat.Text>\n <inkCompat.Text color={FAINT}>· Esc to exit</inkCompat.Text>\n </inkCompat.Box>\n );\n}\n\nfunction StreamingCard({\n text,\n done,\n frame,\n}: {\n text: string;\n done: boolean;\n frame: number;\n}): React.ReactElement {\n const lines = text.length > 0 ? text.split(\"\\n\") : [\"\"];\n const visible = lines.slice(-4);\n const glyph = done ? \"‹\" : \"▸\";\n const head = done ? \"reply\" : \"writing…\";\n const tone = done ? OK : BRAND;\n return (\n <inkCompat.Box flexDirection=\"column\" marginTop={1}>\n <inkCompat.Box flexDirection=\"row\" gap={1}>\n <inkCompat.Text color={tone}>{glyph}</inkCompat.Text>\n <inkCompat.Text color={tone} bold>\n {head}\n </inkCompat.Text>\n {!done ? (\n <inkCompat.Text color={tone}>{SPINNER[frame % SPINNER.length] ?? \"·\"}</inkCompat.Text>\n ) : null}\n </inkCompat.Box>\n {visible.map((line, i) => (\n <inkCompat.Box key={`s-${i}-${line.length}`} paddingLeft={2}>\n <inkCompat.Text>{line || \" \"}</inkCompat.Text>\n </inkCompat.Box>\n ))}\n </inkCompat.Box>\n );\n}\n\nconst OPTIONS = [\n \"1 · keep current approach\",\n \"2 · rewrite with the alternative\",\n \"3 · ask me a clarifying question first\",\n \"Let me type my own answer\",\n \"Cancel — drop the question\",\n] as const;\n\nfunction ChoiceModalInline(): React.ReactElement {\n return (\n <inkCompat.Box flexDirection=\"column\" marginTop={1}>\n <inkCompat.Box flexDirection=\"row\" gap={1}>\n <inkCompat.Text color={ACCENT} bold>\n ?\n </inkCompat.Text>\n <inkCompat.Text color={ACCENT} bold>\n which path should I take?\n </inkCompat.Text>\n <inkCompat.Text color={FAINT}>· awaiting</inkCompat.Text>\n </inkCompat.Box>\n <inkCompat.Box flexDirection=\"column\" paddingLeft={2}>\n {OPTIONS.map((opt, i) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: static option list, never reordered\n <inkCompat.Box key={`o-${i}`} flexDirection=\"row\" gap={1}>\n <inkCompat.Text color={i === 0 ? BRAND : META}>{i === 0 ? \"▸\" : \" \"}</inkCompat.Text>\n <inkCompat.Text color={i === 0 ? BRAND : META} bold={i === 0}>\n {opt}\n </inkCompat.Text>\n </inkCompat.Box>\n ))}\n <inkCompat.Box marginTop={1}>\n <inkCompat.Text color={FAINT}>{\"─\".repeat(40)}</inkCompat.Text>\n </inkCompat.Box>\n <inkCompat.Text color={FAINT}>↑↓ pick · ⏎ confirm · esc cancel</inkCompat.Text>\n </inkCompat.Box>\n </inkCompat.Box>\n );\n}\n\n/** Mirrors the real chat flow: wraps in ApprovalCard (dynamic rule width) +\n * claims budget via useReserveRows. Lets us see whether the budget\n * bookkeeping or the dynamic rule width is responsible for the flicker. */\nfunction ChoiceModalReal(): React.ReactElement {\n useReserveRows(\"modal\", { min: 6, max: 12 });\n return (\n <ApprovalCard tone=\"info\" title=\"which path should I take?\" metaRight=\"awaiting\">\n {OPTIONS.map((opt, i) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: static option list, never reordered\n <inkCompat.Box key={`r-${i}`} flexDirection=\"row\" gap={1}>\n <inkCompat.Text color={i === 0 ? BRAND : META}>{i === 0 ? \"▸\" : \" \"}</inkCompat.Text>\n <inkCompat.Text color={i === 0 ? BRAND : META} bold={i === 0}>\n {opt}\n </inkCompat.Text>\n </inkCompat.Box>\n ))}\n </ApprovalCard>\n );\n}\n\nconst STREAM_TEXT = `analyzing the failing test on src/loop.test.ts\n the assertion on line 42 expects the parser to drop the trailing tool-call marker\n but the new tokenizer keeps it; two paths forward — patch the tokenizer's strip\n step, or update the expectation. The trade-off is whether downstream consumers\n rely on the marker to detect partial tool-call output.`;\n\nfunction FlickerShell({ onExit, realModal }: FlickerShellProps): React.ReactElement {\n const [streamText, setStreamText] = useState(\"\");\n const [streamDone, setStreamDone] = useState(false);\n const [showModal, setShowModal] = useState(false);\n const [frame, setFrame] = useState(0);\n const [phase, setPhase] = useState(\"idle\");\n\n useKeystroke((k) => {\n if (k.escape) onExit();\n });\n\n // Spinner ticker — runs while streaming.\n useEffect(() => {\n if (streamDone) return;\n const id = setInterval(() => setFrame((f) => f + 1), 80);\n return () => clearInterval(id);\n }, [streamDone]);\n\n // Main loop — endlessly cycles through the test scenario.\n useEffect(() => {\n let cancelled = false;\n const sleep = (ms: number) =>\n new Promise<void>((resolve) => {\n setTimeout(() => resolve(), ms);\n });\n\n const cycle = async (): Promise<void> => {\n while (!cancelled) {\n // Reset\n setStreamText(\"\");\n setStreamDone(false);\n setShowModal(false);\n setPhase(\"streaming\");\n await sleep(400);\n if (cancelled) return;\n\n // Stream chunks for ~1.2s before the modal appears\n const chunks = STREAM_TEXT.split(\" \");\n let revealed = \"\";\n for (let i = 0; i < chunks.length / 2; i++) {\n if (cancelled) return;\n revealed += `${chunks[i]} `;\n setStreamText(revealed);\n await sleep(80);\n }\n\n // Modal appears WHILE streaming continues — this is the flicker scenario.\n setPhase(\"streaming + modal\");\n setShowModal(true);\n for (let i = Math.floor(chunks.length / 2); i < chunks.length; i++) {\n if (cancelled) return;\n revealed += `${chunks[i]} `;\n setStreamText(revealed);\n await sleep(80);\n }\n\n // Streaming finishes, modal stays\n setStreamDone(true);\n setPhase(\"done + modal\");\n await sleep(2500);\n if (cancelled) return;\n\n // Tear down\n setShowModal(false);\n setPhase(\"idle\");\n await sleep(800);\n }\n };\n\n void cycle();\n return () => {\n cancelled = true;\n };\n }, []);\n\n return (\n <inkCompat.Box flexDirection=\"column\">\n <Header phase={`${phase}${realModal ? \" (real)\" : \"\"}`} />\n {streamText.length > 0 ? (\n <StreamingCard text={streamText.trim()} done={streamDone} frame={frame} />\n ) : null}\n {showModal ? realModal ? <ChoiceModalReal /> : <ChoiceModalInline /> : null}\n </inkCompat.Box>\n );\n}\n\nexport interface FlickerDemoOptions {\n readonly stdout?: NodeJS.WriteStream;\n readonly stdin?: NodeJS.ReadStream;\n /** When true, wraps the modal in the real ApprovalCard + useReserveRows\n * budget claim — same primitives the live chat ChoiceConfirm uses. */\n readonly realModal?: boolean;\n}\n\nexport async function runFlickerDemo(opts: FlickerDemoOptions = {}): Promise<void> {\n const stdout = opts.stdout ?? process.stdout;\n const stdin = opts.stdin ?? process.stdin;\n\n if (!stdin.isTTY || !stdout.isTTY) {\n process.stderr.write(\"flicker-demo requires an interactive TTY.\\n\");\n process.exit(1);\n }\n\n const pools = {\n char: new CharPool(),\n style: new StylePool(),\n hyperlink: new HyperlinkPool(),\n };\n\n let resolveExit: () => void = () => {};\n const exited = new Promise<void>((resolve) => {\n resolveExit = resolve;\n });\n\n const realModal = !!opts.realModal;\n const tree = realModal ? (\n <ViewportBudgetProvider>\n <FlickerShell onExit={() => resolveExit()} realModal={true} />\n </ViewportBudgetProvider>\n ) : (\n <FlickerShell onExit={() => resolveExit()} realModal={false} />\n );\n\n const handle: Handle = mount(tree, {\n viewportWidth: stdout.columns ?? 80,\n viewportHeight: stdout.rows ?? 24,\n pools,\n write: (bytes) => stdout.write(bytes),\n stdin,\n stdout,\n onExit: () => resolveExit(),\n });\n\n const onResize = () => handle.resize(stdout.columns ?? 80, stdout.rows ?? 24);\n stdout.on(\"resize\", onResize);\n\n try {\n await exited;\n } finally {\n stdout.off(\"resize\", onResize);\n handle.destroy();\n stdin.pause();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAYA,OAAO,SAAS,WAAW,gBAAgB;AAa3C,IAAM,QAAQ;AACd,IAAM,QAAQ;AACd,IAAM,SAAS;AACf,IAAM,KAAK;AACX,IAAM,OAAO;AAEb,IAAM,UAAU,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAOjE,SAAS,OAAO,EAAE,MAAM,GAA0C;AAChE,SACE,oCAAC,mBAAU,KAAV,EAAc,eAAc,OAAM,KAAK,KAC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