@visulima/tui 2.0.0 → 2.0.1

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.
Files changed (110) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/dist/components/box.d.ts +25 -25
  3. package/dist/components/canvas.d.ts +26 -31
  4. package/dist/components/cursor.d.ts +39 -44
  5. package/dist/components/error-overview.d.ts +1 -3
  6. package/dist/components/error-overview.js +1 -1
  7. package/dist/components/newline.d.ts +6 -8
  8. package/dist/components/spacer.d.ts +4 -4
  9. package/dist/components/static-render.d.ts +9 -40
  10. package/dist/components/static.d.ts +13 -13
  11. package/dist/components/text.d.ts +34 -47
  12. package/dist/components/transform.d.ts +7 -11
  13. package/dist/core/index.d.ts +11 -11
  14. package/dist/core/index.js +1 -1
  15. package/dist/ink/canvas/index.d.ts +10 -10
  16. package/dist/ink/hooks/use-animation.d.ts +22 -22
  17. package/dist/ink/hooks/use-app.d.ts +3 -3
  18. package/dist/ink/hooks/use-box-metrics.d.ts +16 -16
  19. package/dist/ink/hooks/use-clipboard.d.ts +16 -16
  20. package/dist/ink/hooks/use-color-blindness.d.ts +16 -16
  21. package/dist/ink/hooks/use-console-capture.d.ts +19 -19
  22. package/dist/ink/hooks/use-cursor.d.ts +6 -6
  23. package/dist/ink/hooks/use-focus-manager.d.ts +25 -25
  24. package/dist/ink/hooks/use-focus.d.ts +14 -18
  25. package/dist/ink/hooks/use-form.d.ts +32 -32
  26. package/dist/ink/hooks/use-hotkey.d.ts +17 -17
  27. package/dist/ink/hooks/use-input.d.ts +92 -92
  28. package/dist/ink/hooks/use-input.js +2 -2
  29. package/dist/ink/hooks/use-interval.d.ts +14 -14
  30. package/dist/ink/hooks/use-is-screen-reader-enabled.d.ts +3 -3
  31. package/dist/ink/hooks/use-key-bindings.d.ts +32 -32
  32. package/dist/ink/hooks/use-key-chord.d.ts +15 -15
  33. package/dist/ink/hooks/use-paste.d.ts +38 -38
  34. package/dist/ink/hooks/use-paste.js +1 -1
  35. package/dist/ink/hooks/use-persistent-state.d.ts +46 -46
  36. package/dist/ink/hooks/use-persistent-state.js +2 -2
  37. package/dist/ink/hooks/use-scroll-acceleration.d.ts +24 -24
  38. package/dist/ink/hooks/use-scroll-input.d.ts +15 -15
  39. package/dist/ink/hooks/use-stderr.d.ts +6 -6
  40. package/dist/ink/hooks/use-stderr.js +1 -1
  41. package/dist/ink/hooks/use-stdin.d.ts +10 -10
  42. package/dist/ink/hooks/use-stdin.js +1 -1
  43. package/dist/ink/hooks/use-stdout.d.ts +6 -6
  44. package/dist/ink/hooks/use-stdout.js +1 -1
  45. package/dist/ink/hooks/use-stopwatch.d.ts +12 -12
  46. package/dist/ink/hooks/use-terminal-palette.d.ts +11 -11
  47. package/dist/ink/hooks/use-text-buffer.d.ts +2 -2
  48. package/dist/ink/hooks/use-text-selection.d.ts +18 -18
  49. package/dist/ink/hooks/use-timeout.d.ts +11 -11
  50. package/dist/ink/hooks/use-timer.d.ts +19 -19
  51. package/dist/ink/hooks/use-window-size.d.ts +8 -8
  52. package/dist/ink/hooks/use-window-size.js +1 -1
  53. package/dist/ink/index.d.ts +109 -122
  54. package/dist/ink/index.js +1 -1
  55. package/dist/ink/mouse/use-element-position.d.ts +6 -6
  56. package/dist/ink/mouse/use-mouse-action.d.ts +1 -1
  57. package/dist/ink/mouse/use-mouse-position.d.ts +1 -1
  58. package/dist/ink/mouse/use-mouse.d.ts +1 -1
  59. package/dist/ink/mouse/use-on-mouse-click.d.ts +3 -3
  60. package/dist/ink/mouse/use-on-mouse-hover.d.ts +2 -2
  61. package/dist/ink/mouse/use-on-mouse-state.d.ts +2 -2
  62. package/dist/ink/public/cursor.d.ts +21 -21
  63. package/dist/ink/public/dom.d.ts +2 -2
  64. package/dist/ink/public/highlighter.d.ts +16 -26
  65. package/dist/ink/public/input.d.ts +6 -6
  66. package/dist/ink/public/styles.d.ts +1 -1
  67. package/dist/ink/public/utils.d.ts +2 -2
  68. package/dist/packem_shared/{DevTools-D9tfChBc.js → DevTools-BxD3PYAN.js} +1 -1
  69. package/dist/packem_shared/MouseProvider-DOcWCRVq.js +1 -0
  70. package/dist/packem_shared/{Renderer-DsskdkUd.js → Renderer-BeS49FNq.js} +1 -1
  71. package/dist/packem_shared/{TuiApp-DjIgv5Sk.js → TuiApp-CCVaiKbf.js} +1 -1
  72. package/dist/packem_shared/app-context.d-DMLw5Nxy.d.ts +56 -0
  73. package/dist/packem_shared/{buffer.d-j_dP5JyC.d.ts → buffer.d-CttIC480.d.ts} +26 -26
  74. package/dist/packem_shared/clipboard.d-nDPQkZ2H.d.ts +23 -0
  75. package/dist/packem_shared/color-matrix.d-sTqnJ23h.d.ts +50 -0
  76. package/dist/packem_shared/{createInlineLoop-BT40Wpmx.js → createInlineLoop-DnEvE2eM.js} +1 -1
  77. package/dist/packem_shared/{dom.d-g-nsYquD.d.ts → dom.d-CLGlidfI.d.ts} +138 -151
  78. package/dist/packem_shared/{input.d-D-Yxqha8.d.ts → input.d-Bb8pWHvp.d.ts} +24 -24
  79. package/dist/packem_shared/load-native-root-binding-CxJnHcac.js +1 -0
  80. package/dist/packem_shared/{mouse-context.d-BfL9xGk_.d.ts → mouse-context.d-W-nszUps.d.ts} +8 -8
  81. package/dist/packem_shared/reconciler-DkwOtC5B.js +1 -0
  82. package/dist/packem_shared/{render-D7aV_hO1.js → render-CuCo-R-l.js} +17 -17
  83. package/dist/packem_shared/{render-DMcWfI6-.js → render-DtQd8qQq.js} +1 -1
  84. package/dist/packem_shared/render.d-DjQhFsiN.d.ts +435 -0
  85. package/dist/packem_shared/{renderToString-DqLFFPvO.js → renderToString-B1LgWcJe.js} +1 -1
  86. package/dist/packem_shared/{selection.d-KWphH--_.d.ts → selection.d-BSAWa4ey.d.ts} +16 -16
  87. package/dist/packem_shared/stderr-context-CR2LLec6.js +1 -0
  88. package/dist/packem_shared/stdin-context-BjMA9Sbi.js +1 -0
  89. package/dist/packem_shared/stdout-context-DAAlQct2.js +1 -0
  90. package/dist/packem_shared/styles.d-CKGQFfm4.d.ts +485 -0
  91. package/dist/packem_shared/{terminal-palette.d-D2SQjfn-.d.ts → terminal-palette.d-JbWHISW-.d.ts} +7 -7
  92. package/dist/packem_shared/utils-CVgM8kTn.js +1 -0
  93. package/dist/react/index.d.ts +160 -178
  94. package/dist/react/index.js +1 -1
  95. package/dist/testing/index.d.ts +151 -151
  96. package/dist/testing/index.js +1 -1
  97. package/index.js +52 -52
  98. package/package.json +9 -9
  99. package/dist/packem_shared/MouseProvider-DUqQ3Eaa.js +0 -1
  100. package/dist/packem_shared/app-context.d-CG88lgkg.d.ts +0 -56
  101. package/dist/packem_shared/clipboard.d-D6lZTQ21.d.ts +0 -23
  102. package/dist/packem_shared/color-matrix.d-DSXLsB64.d.ts +0 -50
  103. package/dist/packem_shared/load-native-root-binding-DDikxNox.js +0 -1
  104. package/dist/packem_shared/reconciler-DhUGYWCr.js +0 -1
  105. package/dist/packem_shared/render.d-BvfwvSCx.d.ts +0 -435
  106. package/dist/packem_shared/stderr-context-Bvnik0hL.js +0 -1
  107. package/dist/packem_shared/stdin-context-88AhuztD.js +0 -1
  108. package/dist/packem_shared/stdout-context-BnblEPez.js +0 -1
  109. package/dist/packem_shared/styles.d-D7iZuNC-.d.ts +0 -492
  110. package/dist/packem_shared/utils-C8l_3Dzw.js +0 -1
@@ -1,24 +1,24 @@
1
- import{createRequire as Le}from"node:module";import{jsx as D}from"react/jsx-runtime";import{cursorShow as ot,setMode as le,BracketedPasteMode as de,resetMode as ce,eraseLines as G,cursorHide as nt,cursorUp as Vt,cursorNextLine as Ue,cursorTo as We,eraseLineEnd as $e,createDecMode as Ae,ALT_SCREEN_ON as Xt,clearScreenAndHomeCursor as Be,ALT_SCREEN_OFF as Jt}from"@visulima/ansi";import{wordWrap as He}from"@visulima/string";import{ConcurrentRoot as Ge,LegacyRoot as Ke}from"react-reconciler/constants.js";import U from"yoga-layout";import{a as Ye}from"./accessibility-context-DDyHTwmA.js";import{useState as ct,useRef as I,useCallback as v,useEffect as ht,useMemo as B}from"react";import{e as je}from"./animation-context-DW3p-vpk.js";import{e as qe}from"./app-context-DTm1_XBA.js";import{o as ze}from"./cursor-context-CFviBqPX.js";import Ve from"../components/error-boundary.js";import{o as Xe}from"./focus-context-CsT69klR.js";import{t as Je}from"./stderr-context-Bvnik0hL.js";import{e as Qe}from"./stdin-context-88AhuztD.js";import{t as Ze}from"./stdout-context-BnblEPez.js";import{I as ti,_ as ei,r as ii,H as si}from"./renderer-Cs0KEr1o.js";import{c as ri,e as oi}from"./dom-rphpG0kf.js";import{resolveFlags as Qt}from"./kittyFlags-g8ALyoCU.js";import{buildReturnToBottomPrefix as mt,buildCursorSuffix as st,buildCursorOnlySequence as he,cursorPositionChanged as gt,buildCursorShapeSequence as Zt}from"./buildCursorOnlySequence-CerkmjWt.js";import{p as ni}from"./load-native-root-binding-DDikxNox.js";import{a as ui}from"./measure-text-B7juNq4Y.js";import{j as k,c as ai}from"./reconciler-DhUGYWCr.js";import{measureAndExtractObservers as li}from"./ResizeObserver-BI9bDy-j.js";import{calculateScroll as di}from"./calculateScroll-D4Y_JR4H.js";import{g as q}from"./utils-C8l_3Dzw.js";const De=Le(import.meta.url),X=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,vt=i=>{if(typeof X<"u"&&X.versions&&X.versions.node){const[t,e]=X.versions.node.split(".").map(Number);if(t>22||t===22&&e>=3||t===20&&e>=16)return X.getBuiltinModule(i)}return De(i)},P=X,{env:yt}=P,{PassThrough:qt,Stream:_e}=vt("node:stream"),{Buffer:zt}=vt("node:buffer"),{Console:Me}=vt("node:console"),{EventEmitter:Fe}=vt("node:events"),te=i=>i in yt&&yt[i]!=="0"&&yt[i]!=="false",fe=te("CI")||te("CONTINUOUS_INTEGRATION"),ee=["assert","count","countReset","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","table","time","timeEnd","timeLog","trace","warn"];let xt={};const ci=i=>{const t=new qt,e=new qt;t.write=r=>{i("stdout",r)},e.write=r=>{i("stderr",r)};const s=new console.Console(t,e);for(const r of ee)xt[r]=console[r],console[r]=s[r];return()=>{for(const r of ee)console[r]=xt[r];xt={}}},J=[];J.push("SIGHUP","SIGINT","SIGTERM");process.platform!=="win32"&&J.push("SIGALRM","SIGABRT","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&J.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT");const pt=i=>!!i&&!0&&typeof i.removeListener=="function"&&typeof i.emit=="function"&&typeof i.reallyExit=="function"&&typeof i.listeners=="function"&&typeof i.kill=="function"&&typeof i.pid=="number"&&typeof i.on=="function",Tt=Symbol.for("signal-exit emitter"),St=globalThis,hi=Object.defineProperty.bind(Object);let fi=class{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(St[Tt])return St[Tt];hi(St,Tt,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(t,e){this.listeners[t].push(e)}removeListener(t,e){const s=this.listeners[t],r=s.indexOf(e);r!==-1&&(r===0&&s.length===1?s.length=0:s.splice(r,1))}emit(t,e,s){if(this.emitted[t])return!1;this.emitted[t]=!0;let r=!1;for(const n of this.listeners[t])r=n(e,s)===!0||r;return t==="exit"&&(r=this.emit("afterExit",e,s)||r),r}},pe=class{};const pi=i=>({onExit(t,e){return i.onExit(t,e)},load(){return i.load()},unload(){return i.unload()}});class mi extends pe{onExit(){return()=>{}}load(){}unload(){}}let gi=class extends pe{#n=Et.platform==="win32"?"SIGINT":"SIGHUP";#e=new fi;#t;#r;#o;#s={};#i=!1;constructor(t){super(),this.#t=t,this.#s={};for(const e of J)this.#s[e]=()=>{const s=this.#t.listeners(e);let{count:r}=this.#e;const n=t;if(typeof n.__signal_exit_emitter__=="object"&&typeof n.__signal_exit_emitter__.count=="number"&&(r+=n.__signal_exit_emitter__.count),s.length===r){this.unload();const l=this.#e.emit("exit",null,e),o=e==="SIGHUP"?this.#n:e;l||t.kill(t.pid,o)}};this.#o=t.reallyExit,this.#r=t.emit}onExit(t,e){if(!pt(this.#t))return()=>{};this.#i===!1&&this.load();const s=e?.alwaysLast?"afterExit":"exit";return this.#e.on(s,t),()=>{this.#e.removeListener(s,t),this.#e.listeners.exit.length===0&&this.#e.listeners.afterExit.length===0&&this.unload()}}load(){if(!this.#i){this.#i=!0,this.#e.count+=1;for(const t of J)try{const e=this.#s[t];e&&this.#t.on(t,e)}catch{}this.#t.emit=(t,...e)=>this.#a(t,...e),this.#t.reallyExit=t=>this.#u(t)}}unload(){this.#i&&(this.#i=!1,J.forEach(t=>{const e=this.#s[t];if(!e)throw new Error("Listener not defined for signal: "+t);try{this.#t.removeListener(t,e)}catch{}}),this.#t.emit=this.#r,this.#t.reallyExit=this.#o,this.#e.count-=1)}#u(t){return pt(this.#t)?(this.#t.exitCode=t||0,this.#e.emit("exit",this.#t.exitCode,null),this.#o.call(this.#t,this.#t.exitCode)):0}#a(t,...e){const s=this.#r;if(t==="exit"&&pt(this.#t)){typeof e[0]=="number"&&(this.#t.exitCode=e[0]);const r=s.call(this.#t,t,...e);return this.#e.emit("exit",this.#t.exitCode,null),r}else return s.call(this.#t,t,...e)}};const Et=globalThis.process,{onExit:wi}=pi(pt(Et)?new gi(Et):new mi),me="\x1B[200~",ie="\x1B[201~",vi=i=>i>=48&&i<=63,bi=i=>i>=32&&i<=47,ge=i=>i>=64&&i<=126,yi=(i,t,e)=>{const s=t+e+1;let r=s;for(;r<i.length;r++){const n=i.codePointAt(r);if(n===void 0)return"pending";if(!(vi(n)||bi(n))&&!(n===91&&r===s))return ge(n)?{nextIndex:r+1,sequence:i.slice(t,r+1)}:void 0}return"pending"},xi=(i,t,e)=>{const s=t+e+2;if(s>i.length)return"pending";const r=i.codePointAt(s-1);if(!(r===void 0||!ge(r)))return{nextIndex:s,sequence:i.slice(t,s)}},se=(i,t,e)=>{const s=i[t+e];if(s===void 0)return"pending";if(s==="[")return yi(i,t,e);if(s==="O")return xi(i,t,e)},Ti=(i,t)=>{const e=i.codePointAt(t+1),s=e!==void 0&&e>65535?2:1,r=t+1+s;return{nextIndex:r,sequence:i.slice(t,r)}},Si=(i,t)=>{if(t===i.length-1)return"pending";if(i[t+1]==="\x1B"){if(t+2>=i.length)return"pending";const s=se(i,t,2);return s==="pending"?"pending":s||{nextIndex:t+2,sequence:i.slice(t,t+2)}}const e=se(i,t,1);return e==="pending"?"pending":e||Ti(i,t)},re=(i,t)=>{let e=0;for(let s=0;s<i.length;s++){const r=i[s];(r===""||r==="\b")&&(s>e&&t.push(i.slice(e,s)),t.push(r),e=s+1)}e<i.length&&t.push(i.slice(e))},Ri=i=>{const t=[];let e=0;const s=r=>({events:t,pending:i.slice(r)});for(;e<i.length;){const r=i.indexOf("\x1B",e);if(r===-1)return re(i.slice(e),t),{events:t,pending:""};r>e&&re(i.slice(e,r),t);const n=Si(i,r);if(n==="pending")return s(r);if(n.sequence===me){const l=n.nextIndex,o=i.indexOf(ie,l);if(o===-1)return s(r);t.push({paste:i.slice(l,o)}),e=o+ie.length;continue}t.push(n.sequence),e=n.nextIndex}return{events:t,pending:""}},Ci=()=>{let i="";return{flushPendingEscape(){if(!i.startsWith("\x1B"))return;const t=i;return i="",t},hasPendingEscape(){return i.startsWith("\x1B")&&!i.startsWith(me)&&i!=="\x1B[200"},push(t){const e=Ri(i+t);return i=e.pending,e.events},reset(){i=""}}},Ei=" ",Oi="\x1B[Z",Pi="\x1B",oe=le(de),Rt=ce(de),we=({children:i,exitOnCtrlC:t,interactive:e,onExit:s,onRegisterInputControl:r,onSuspendTerminal:n,onWaitUntilRenderFlush:l,renderThrottleMs:o,setCursorPosition:a,stderr:f,stdin:h,stdout:m,writeToStderr:w,writeToStdout:d})=>{const[c,b]=ct(!0),[y,R]=ct(void 0),[,T]=ct([]),_=I(0),N=I(new Map),W=I(void 0),C=I(0),E=I(!1),M=I(0),[x]=ct(()=>{const u=new Fe;return u.setMaxListeners(1/0),u}),$=I(void 0),Q=I(void 0);Q.current??=Ci();const Z=I(void 0),Pt=I(!1),Te=20,K=v(()=>{Z.current&&(clearTimeout(Z.current),Z.current=void 0)},[]),Y=v(()=>{W.current&&(clearTimeout(W.current),W.current=void 0)},[]),ut=v(()=>{if(Y(),N.current.size===0)return;let u=Number.POSITIVE_INFINITY;for(const g of N.current.values())u=Math.min(u,g.nextDueTime);const p=Math.max(0,u-performance.now());W.current=setTimeout(()=>{W.current=void 0;const g=performance.now(),S=[...N.current.values()];for(const O of S){if(g<O.nextDueTime)continue;O.callback(g);const Ie=g-O.startTime,ke=Math.floor(Ie/O.interval)+1;O.nextDueTime=O.startTime+ke*O.interval}ut()},p)},[Y]),Nt=v((u,p)=>{const g=performance.now();return N.current.set(u,{callback:u,interval:p,nextDueTime:g+p,startTime:g}),ut(),{startTime:g,unsubscribe(){if(N.current.delete(u),N.current.size===0){Y();return}ut()}}},[Y,ut]);ht(()=>()=>{Y()},[Y]);const L=h.isTTY,It=v(()=>{$.current&&(h.removeListener("readable",$.current),$.current=void 0)},[h]),F=v(()=>{Q.current?.reset(),K(),It()},[K,It]),j=v(()=>{E.current=!1,h.setRawMode(!1),h.unref(),C.current=0,F()},[h,F]),tt=v(u=>{L&&(C.current>0||E.current)&&j(),s(u)},[L,j,s]),kt=v(u=>{if(u.includes("")&&t){tt();return}u===Pi&&c&&R(p=>{if(!p)return p})},[t,tt,c]),et=v(u=>{kt(u),x.emit("input",u)},[kt,x]),Lt=v(()=>{K(),Z.current=setTimeout(()=>{Z.current=void 0;const u=Q.current.flushPendingEscape();u&&et(u)},Te)},[K,et]),bt=v(()=>{K();let u;for(;(u=h.read())!==null;){const p=Q.current.push(u);for(const g of p)if(typeof g=="string")et(g);else{if(x.listenerCount("paste")===0){Pt.current||(Pt.current=!0,w(`Warning: useInput() received bracketed paste because no usePaste() handler is active. This fallback is deprecated and will be removed in the next major version. Migrate paste handling to usePaste().
2
- `)),et(g.paste);continue}x.emit("paste",g.paste)}}Q.current.hasPendingEscape()&&Lt()},[h,et,K,Lt,w,x]),at=v(()=>{$.current||($.current=bt,h.addListener("readable",bt))},[h,bt]),Dt=v(u=>{if(!L)throw h===P.stdin?new Error(`Raw mode is not supported on the current process.stdin, which Ink uses as input stream by default.
1
+ import{createRequire as Le}from"node:module";import{jsx as _}from"react/jsx-runtime";import{cursorShow as ot,setMode as le,BracketedPasteMode as de,resetMode as ce,eraseLines as G,cursorHide as nt,cursorUp as Vt,cursorNextLine as We,cursorTo as $e,eraseLineEnd as Ae,createDecMode as Be,ALT_SCREEN_ON as Xt,clearScreenAndHomeCursor as He,ALT_SCREEN_OFF as Jt}from"@visulima/ansi";import{wordWrap as Ge}from"@visulima/string";import{ConcurrentRoot as Ke,LegacyRoot as Ye}from"react-reconciler/constants.js";import U from"yoga-layout";import{a as Fe}from"./accessibility-context-DDyHTwmA.js";import{useState as ct,useRef as I,useCallback as v,useEffect as ht,useMemo as B}from"react";import{e as qe}from"./animation-context-DW3p-vpk.js";import{e as ze}from"./app-context-DTm1_XBA.js";import{o as Ve}from"./cursor-context-CFviBqPX.js";import Xe from"../components/error-boundary.js";import{o as Je}from"./focus-context-CsT69klR.js";import{t as Qe}from"./stderr-context-CR2LLec6.js";import{e as Ze}from"./stdin-context-BjMA9Sbi.js";import{t as ti}from"./stdout-context-DAAlQct2.js";import{I as ei,_ as ii,r as si,H as ri}from"./renderer-Cs0KEr1o.js";import{c as oi,e as ni}from"./dom-rphpG0kf.js";import{resolveFlags as Qt}from"./kittyFlags-g8ALyoCU.js";import{buildReturnToBottomPrefix as mt,buildCursorSuffix as st,buildCursorOnlySequence as he,cursorPositionChanged as gt,buildCursorShapeSequence as Zt}from"./buildCursorOnlySequence-CerkmjWt.js";import{p as ui}from"./load-native-root-binding-CxJnHcac.js";import{a as ai}from"./measure-text-B7juNq4Y.js";import{j as k,c as li}from"./reconciler-DkwOtC5B.js";import{measureAndExtractObservers as di}from"./ResizeObserver-BI9bDy-j.js";import{calculateScroll as ci}from"./calculateScroll-D4Y_JR4H.js";import{g as q}from"./utils-CVgM8kTn.js";let _e;const De=i=>(_e??=Le(import.meta.url))(i),X=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,vt=i=>{if(typeof X<"u"&&X.versions&&X.versions.node){const[t,e]=X.versions.node.split(".").map(Number);if(t>22||t===22&&e>=3||t===20&&e>=16)return X.getBuiltinModule(i)}return De(i)},P=X,{env:yt}=P,{PassThrough:qt,Stream:Me}=vt("node:stream"),{Buffer:zt}=vt("node:buffer"),{Console:Ue}=vt("node:console"),{EventEmitter:je}=vt("node:events"),te=i=>i in yt&&yt[i]!=="0"&&yt[i]!=="false",fe=te("CI")||te("CONTINUOUS_INTEGRATION"),ee=["assert","count","countReset","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","table","time","timeEnd","timeLog","trace","warn"];let xt={};const hi=i=>{const t=new qt,e=new qt;t.write=r=>{i("stdout",r)},e.write=r=>{i("stderr",r)};const s=new console.Console(t,e);for(const r of ee)xt[r]=console[r],console[r]=s[r];return()=>{for(const r of ee)console[r]=xt[r];xt={}}},J=[];J.push("SIGHUP","SIGINT","SIGTERM");process.platform!=="win32"&&J.push("SIGALRM","SIGABRT","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&J.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT");const pt=i=>!!i&&!0&&typeof i.removeListener=="function"&&typeof i.emit=="function"&&typeof i.reallyExit=="function"&&typeof i.listeners=="function"&&typeof i.kill=="function"&&typeof i.pid=="number"&&typeof i.on=="function",Tt=Symbol.for("signal-exit emitter"),St=globalThis,fi=Object.defineProperty.bind(Object);let pi=class{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(St[Tt])return St[Tt];fi(St,Tt,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(t,e){this.listeners[t].push(e)}removeListener(t,e){const s=this.listeners[t],r=s.indexOf(e);r!==-1&&(r===0&&s.length===1?s.length=0:s.splice(r,1))}emit(t,e,s){if(this.emitted[t])return!1;this.emitted[t]=!0;let r=!1;for(const n of this.listeners[t])r=n(e,s)===!0||r;return t==="exit"&&(r=this.emit("afterExit",e,s)||r),r}},pe=class{};const mi=i=>({onExit(t,e){return i.onExit(t,e)},load(){return i.load()},unload(){return i.unload()}});class gi extends pe{onExit(){return()=>{}}load(){}unload(){}}let wi=class extends pe{#n=Et.platform==="win32"?"SIGINT":"SIGHUP";#e=new pi;#t;#r;#o;#s={};#i=!1;constructor(t){super(),this.#t=t,this.#s={};for(const e of J)this.#s[e]=()=>{const s=this.#t.listeners(e);let{count:r}=this.#e;const n=t;if(typeof n.__signal_exit_emitter__=="object"&&typeof n.__signal_exit_emitter__.count=="number"&&(r+=n.__signal_exit_emitter__.count),s.length===r){this.unload();const l=this.#e.emit("exit",null,e),o=e==="SIGHUP"?this.#n:e;l||t.kill(t.pid,o)}};this.#o=t.reallyExit,this.#r=t.emit}onExit(t,e){if(!pt(this.#t))return()=>{};this.#i===!1&&this.load();const s=e?.alwaysLast?"afterExit":"exit";return this.#e.on(s,t),()=>{this.#e.removeListener(s,t),this.#e.listeners.exit.length===0&&this.#e.listeners.afterExit.length===0&&this.unload()}}load(){if(!this.#i){this.#i=!0,this.#e.count+=1;for(const t of J)try{const e=this.#s[t];e&&this.#t.on(t,e)}catch{}this.#t.emit=(t,...e)=>this.#a(t,...e),this.#t.reallyExit=t=>this.#u(t)}}unload(){this.#i&&(this.#i=!1,J.forEach(t=>{const e=this.#s[t];if(!e)throw new Error("Listener not defined for signal: "+t);try{this.#t.removeListener(t,e)}catch{}}),this.#t.emit=this.#r,this.#t.reallyExit=this.#o,this.#e.count-=1)}#u(t){return pt(this.#t)?(this.#t.exitCode=t||0,this.#e.emit("exit",this.#t.exitCode,null),this.#o.call(this.#t,this.#t.exitCode)):0}#a(t,...e){const s=this.#r;if(t==="exit"&&pt(this.#t)){typeof e[0]=="number"&&(this.#t.exitCode=e[0]);const r=s.call(this.#t,t,...e);return this.#e.emit("exit",this.#t.exitCode,null),r}else return s.call(this.#t,t,...e)}};const Et=globalThis.process,{onExit:vi}=mi(pt(Et)?new wi(Et):new gi),me="\x1B[200~",ie="\x1B[201~",bi=i=>i>=48&&i<=63,yi=i=>i>=32&&i<=47,ge=i=>i>=64&&i<=126,xi=(i,t,e)=>{const s=t+e+1;let r=s;for(;r<i.length;r++){const n=i.codePointAt(r);if(n===void 0)return"pending";if(!(bi(n)||yi(n))&&!(n===91&&r===s))return ge(n)?{nextIndex:r+1,sequence:i.slice(t,r+1)}:void 0}return"pending"},Ti=(i,t,e)=>{const s=t+e+2;if(s>i.length)return"pending";const r=i.codePointAt(s-1);if(!(r===void 0||!ge(r)))return{nextIndex:s,sequence:i.slice(t,s)}},se=(i,t,e)=>{const s=i[t+e];if(s===void 0)return"pending";if(s==="[")return xi(i,t,e);if(s==="O")return Ti(i,t,e)},Si=(i,t)=>{const e=i.codePointAt(t+1),s=e!==void 0&&e>65535?2:1,r=t+1+s;return{nextIndex:r,sequence:i.slice(t,r)}},Ri=(i,t)=>{if(t===i.length-1)return"pending";if(i[t+1]==="\x1B"){if(t+2>=i.length)return"pending";const s=se(i,t,2);return s==="pending"?"pending":s||{nextIndex:t+2,sequence:i.slice(t,t+2)}}const e=se(i,t,1);return e==="pending"?"pending":e||Si(i,t)},re=(i,t)=>{let e=0;for(let s=0;s<i.length;s++){const r=i[s];(r===""||r==="\b")&&(s>e&&t.push(i.slice(e,s)),t.push(r),e=s+1)}e<i.length&&t.push(i.slice(e))},Ci=i=>{const t=[];let e=0;const s=r=>({events:t,pending:i.slice(r)});for(;e<i.length;){const r=i.indexOf("\x1B",e);if(r===-1)return re(i.slice(e),t),{events:t,pending:""};r>e&&re(i.slice(e,r),t);const n=Ri(i,r);if(n==="pending")return s(r);if(n.sequence===me){const l=n.nextIndex,o=i.indexOf(ie,l);if(o===-1)return s(r);t.push({paste:i.slice(l,o)}),e=o+ie.length;continue}t.push(n.sequence),e=n.nextIndex}return{events:t,pending:""}},Ei=()=>{let i="";return{flushPendingEscape(){if(!i.startsWith("\x1B"))return;const t=i;return i="",t},hasPendingEscape(){return i.startsWith("\x1B")&&!i.startsWith(me)&&i!=="\x1B[200"},push(t){const e=Ci(i+t);return i=e.pending,e.events},reset(){i=""}}},Oi=" ",Pi="\x1B[Z",Ni="\x1B",oe=le(de),Rt=ce(de),we=({children:i,exitOnCtrlC:t,interactive:e,onExit:s,onRegisterInputControl:r,onSuspendTerminal:n,onWaitUntilRenderFlush:l,renderThrottleMs:o,setCursorPosition:a,stderr:f,stdin:h,stdout:m,writeToStderr:w,writeToStdout:d})=>{const[c,b]=ct(!0),[y,R]=ct(void 0),[,T]=ct([]),D=I(0),N=I(new Map),W=I(void 0),C=I(0),E=I(!1),M=I(0),[x]=ct(()=>{const u=new je;return u.setMaxListeners(1/0),u}),$=I(void 0),Q=I(void 0);Q.current??=Ei();const Z=I(void 0),Pt=I(!1),Te=20,K=v(()=>{Z.current&&(clearTimeout(Z.current),Z.current=void 0)},[]),Y=v(()=>{W.current&&(clearTimeout(W.current),W.current=void 0)},[]),ut=v(()=>{if(Y(),N.current.size===0)return;let u=Number.POSITIVE_INFINITY;for(const g of N.current.values())u=Math.min(u,g.nextDueTime);const p=Math.max(0,u-performance.now());W.current=setTimeout(()=>{W.current=void 0;const g=performance.now(),S=[...N.current.values()];for(const O of S){if(g<O.nextDueTime)continue;O.callback(g);const Ie=g-O.startTime,ke=Math.floor(Ie/O.interval)+1;O.nextDueTime=O.startTime+ke*O.interval}ut()},p)},[Y]),Nt=v((u,p)=>{const g=performance.now();return N.current.set(u,{callback:u,interval:p,nextDueTime:g+p,startTime:g}),ut(),{startTime:g,unsubscribe(){if(N.current.delete(u),N.current.size===0){Y();return}ut()}}},[Y,ut]);ht(()=>()=>{Y()},[Y]);const L=h.isTTY,It=v(()=>{$.current&&(h.removeListener("readable",$.current),$.current=void 0)},[h]),F=v(()=>{Q.current?.reset(),K(),It()},[K,It]),j=v(()=>{E.current=!1,h.setRawMode(!1),h.unref(),C.current=0,F()},[h,F]),tt=v(u=>{L&&(C.current>0||E.current)&&j(),s(u)},[L,j,s]),kt=v(u=>{if(u.includes("")&&t){tt();return}u===Ni&&c&&R(p=>{if(!p)return p})},[t,tt,c]),et=v(u=>{kt(u),x.emit("input",u)},[kt,x]),Lt=v(()=>{K(),Z.current=setTimeout(()=>{Z.current=void 0;const u=Q.current.flushPendingEscape();u&&et(u)},Te)},[K,et]),bt=v(()=>{K();let u;for(;(u=h.read())!==null;){const p=Q.current.push(u);for(const g of p)if(typeof g=="string")et(g);else{if(x.listenerCount("paste")===0){Pt.current||(Pt.current=!0,w(`Warning: useInput() received bracketed paste because no usePaste() handler is active. This fallback is deprecated and will be removed in the next major version. Migrate paste handling to usePaste().
2
+ `)),et(g.paste);continue}x.emit("paste",g.paste)}}Q.current.hasPendingEscape()&&Lt()},[h,et,K,Lt,w,x]),at=v(()=>{$.current||($.current=bt,h.addListener("readable",bt))},[h,bt]),_t=v(u=>{if(!L)throw h===P.stdin?new Error(`Raw mode is not supported on the current process.stdin, which Ink uses as input stream by default.
3
3
  Read about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported`):new Error(`Raw mode is not supported on the stdin provided to Ink.
4
- Read about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported`);if(h.setEncoding("utf8"),u){if(C.current===0){const p=E.current;E.current=!1,p||(h.ref(),h.setRawMode(!0)),at()}C.current++;return}C.current!==0&&--C.current===0&&(F(),E.current=!0,queueMicrotask(()=>{E.current&&j()}))},[L,h,at,F,j]),_t=v(u=>{if(m.isTTY){if(u){M.current===0&&m.write(oe),M.current++;return}M.current!==0&&--M.current===0&&m.write(Rt)}},[m]),Mt=I({bracketedPaste:!1,rawMode:!1}),Ut=v(()=>{const u=L&&(C.current>0||E.current),p=M.current>0;Mt.current={bracketedPaste:p,rawMode:u},p&&m.isTTY&&m.write(Rt),u&&(E.current=!1,F(),h.setRawMode(!1),h.unref())},[L,m,h,F]),Wt=v(()=>{const{bracketedPaste:u,rawMode:p}=Mt.current;p&&(h.ref(),h.setRawMode(!0),h.setEncoding("utf8"),at()),u&&m.isTTY&&m.write(oe)},[h,m,at]);ht(()=>{r(Ut,Wt)},[r,Ut,Wt]);const $t=v((u,p)=>{const g=u.findIndex(S=>S.id===p);for(let S=g+1;S<u.length;S++){const O=u[S];if(O?.isActive)return O.id}},[]),At=v((u,p)=>{const g=u.findIndex(S=>S.id===p);for(let S=g-1;S>=0;S--){const O=u[S];if(O?.isActive)return O.id}},[]),lt=v(()=>{T(u=>(R(p=>{const g=u.find(S=>S.isActive)?.id;return $t(u,p)??g}),u))},[$t]),dt=v(()=>{T(u=>(R(p=>{const g=u.findLast(S=>S.isActive)?.id;return At(u,p)??g}),u))},[At]);ht(()=>{const u=g=>{!c||_.current===0||(g===Ei&&lt(),g===Oi&&dt())};x.on("input",u);const p=x;return()=>{p.off("input",u)}},[c,lt,dt,x]);const Bt=v(()=>{b(!0)},[]),Ht=v(()=>{b(!1)},[]),Gt=v(u=>{T(p=>(p.some(g=>g?.id===u)&&R(u),p))},[]),Kt=v((u,{autoFocus:p})=>{T(g=>(_.current=g.length+1,[...g,{id:u,isActive:!0}])),p&&R(g=>g||u)},[]),Yt=v(u=>{R(p=>{if(p!==u)return p}),T(p=>{const g=p.filter(S=>S.id!==u);return _.current=g.length,g})},[]),Ft=v(u=>{T(p=>p.map(g=>g.id!==u?g:{id:u,isActive:!0}))},[]),jt=v(u=>{R(p=>{if(p!==u)return p}),T(p=>p.map(g=>g.id!==u?g:{id:u,isActive:!1}))},[]);ht(()=>()=>{const u=!m.destroyed&&!m.writableEnded;e&&u&&m.write(ot),L&&(C.current>0||E.current)&&j(),M.current>0&&(m.isTTY&&u&&m.write(Rt),M.current=0)},[m,L,j,e]);const Se=B(()=>({exit:tt,suspendTerminal:n,waitUntilRenderFlush:l}),[tt,n,l]),Re=B(()=>({internal_eventEmitter:x,internal_exitOnCtrlC:t,isRawModeSupported:L,setBracketedPasteMode:_t,setRawMode:Dt,stdin:h}),[h,Dt,_t,L,t,x]),Ce=B(()=>({stdout:m,write:d}),[m,d]),Ee=B(()=>({stderr:f,write:w}),[f,w]),Oe=B(()=>({setCursorPosition:a}),[a]),Pe=B(()=>({activate:Ft,activeId:y,add:Kt,deactivate:jt,disableFocus:Ht,enableFocus:Bt,focus:Gt,focusNext:lt,focusPrevious:dt,remove:Yt}),[y,Kt,Yt,Ft,jt,Bt,Ht,lt,dt,Gt]),Ne=B(()=>({renderThrottleMs:o,subscribe:Nt}),[Nt,o]);return D(qe.Provider,{value:Se,children:D(Qe.Provider,{value:Re,children:D(Ze.Provider,{value:Ce,children:D(Je.Provider,{value:Ee,children:D(Xe.Provider,{value:Pe,children:D(je.Provider,{value:Ne,children:D(ze.Provider,{value:Oe,children:D(Ve,{onError:tt,children:i})})})})})})})})};we.displayName="InternalApp";const Ni=(i,t,e)=>{if(e<=0||!i.yogaNode)return"";const{yogaNode:s}=i,r=s.getComputedBorder(U.EDGE_LEFT),n=s.getComputedBorder(U.EDGE_RIGHT),l=s.getComputedBorder(U.EDGE_TOP),o=s.getComputedPadding(U.EDGE_LEFT),a=s.getComputedPadding(U.EDGE_RIGHT),f=s.getComputedPadding(U.EDGE_TOP),h=Math.round(s.getComputedWidth()-r-n-o-a);if(h<=0)return"";const m=new ti({height:e,width:h}),w=-(i.internal_scrollState?.scrollLeft??0)-r-o,d=-t-l-f;for(const c of i.childNodes)ei(c,m,{absoluteOffsetX:w,absoluteOffsetY:d,offsetX:w,offsetY:d,skipStaticElements:!1});return m.get().output},Ot=new WeakMap,z=i=>i??"default",ve=()=>{let i,t;return{consumeDelta:()=>{if(z(t)===z(i))return"";const e=z(t);return i=t,Zt(e)},consumeRestoreOnDone:()=>{const e=z(i)!=="default";return i=void 0,t=void 0,e?Zt("default"):""},isDirty:()=>z(t)!==z(i),setPending:e=>{t=e}}},rt=(i,t)=>t.endsWith(`
5
- `)?i.length-1:i.length,be=i=>i.rows||1/0,wt=(i,t)=>Math.min(i,be(t)),Ii=(i,{showCursor:t=!1}={})=>{let e=0,s="",r=!1,n,l=!1,o,a=!1;const f=ve(),h=()=>l?n:void 0,m=(d,c)=>{const b=gt(c,o);return d!==s||b||f.isDirty()},w=d=>{!t&&!r&&(i.write(nt),r=!0);const c=h();l=!1;const b=gt(c,o);if(!m(d,c))return!1;const y=f.consumeDelta(),R=d.split(`
6
- `),T=rt(R,d),_=st(T,c);if(d===s&&b)i.write(y+he({cursorPosition:c,cursorWasShown:a,previousCursorPosition:o,previousLineCount:e,visibleLineCount:T}));else if(d===s&&y!=="")i.write(y);else{s=d;const N=mt(a,e,o);i.write(y+N+G(wt(e,i))+d+_),e=R.length}return o=c?{...c}:void 0,a=c!==void 0,!0};return w.clear=()=>{const d=mt(a,e,o);i.write(d+G(wt(e,i))),s="",e=0,o=void 0,a=!1},w.done=()=>{s="",e=0,o=void 0,a=!1;const d=f.consumeRestoreOnDone();d!==""&&i.write(d),t||(i.write(ot),r=!1)},w.reset=()=>{s="",e=0,o=void 0,a=!1},w.sync=d=>{const c=l?n:void 0;l=!1;const b=d.split(`
7
- `);s=d,e=b.length;const y=f.consumeDelta();y!==""&&i.write(y),!c&&a&&i.write(nt),c&&i.write(st(rt(b,d),c)),o=c?{...c}:void 0,a=c!==void 0},w.setCursorPosition=d=>{n=d,l=!0},w.setCursorShape=f.setPending,w.isCursorDirty=()=>l||f.isDirty(),w.willRender=d=>m(d,h()),w},ki=(i,{showCursor:t=!1}={})=>{let e=[],s="",r=!1,n,l=!1,o,a=!1;const f=ve(),h=()=>l?n:void 0,m=(d,c)=>{const b=gt(c,o);return d!==s||b||f.isDirty()},w=d=>{!t&&!r&&(i.write(nt),r=!0);const c=h();l=!1;const b=gt(c,o);if(!m(d,c))return!1;const y=f.consumeDelta(),R=d.split(`
8
- `),T=rt(R,d),_=rt(e,s);if(d===s&&b)return i.write(y+he({cursorPosition:c,cursorWasShown:a,previousCursorPosition:o,previousLineCount:e.length,visibleLineCount:T})),o=c?{...c}:void 0,a=c!==void 0,!0;if(d===s&&y!=="")return i.write(y),!0;const N=mt(a,e.length,o);if(d===`
4
+ Read about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported`);if(h.setEncoding("utf8"),u){if(C.current===0){const p=E.current;E.current=!1,p||(h.ref(),h.setRawMode(!0)),at()}C.current++;return}C.current!==0&&--C.current===0&&(F(),E.current=!0,queueMicrotask(()=>{E.current&&j()}))},[L,h,at,F,j]),Dt=v(u=>{if(m.isTTY){if(u){M.current===0&&m.write(oe),M.current++;return}M.current!==0&&--M.current===0&&m.write(Rt)}},[m]),Mt=I({bracketedPaste:!1,rawMode:!1}),Ut=v(()=>{const u=L&&(C.current>0||E.current),p=M.current>0;Mt.current={bracketedPaste:p,rawMode:u},p&&m.isTTY&&m.write(Rt),u&&(E.current=!1,F(),h.setRawMode(!1),h.unref())},[L,m,h,F]),Wt=v(()=>{const{bracketedPaste:u,rawMode:p}=Mt.current;p&&(h.ref(),h.setRawMode(!0),h.setEncoding("utf8"),at()),u&&m.isTTY&&m.write(oe)},[h,m,at]);ht(()=>{r(Ut,Wt)},[r,Ut,Wt]);const $t=v((u,p)=>{const g=u.findIndex(S=>S.id===p);for(let S=g+1;S<u.length;S++){const O=u[S];if(O?.isActive)return O.id}},[]),At=v((u,p)=>{const g=u.findIndex(S=>S.id===p);for(let S=g-1;S>=0;S--){const O=u[S];if(O?.isActive)return O.id}},[]),lt=v(()=>{T(u=>(R(p=>{const g=u.find(S=>S.isActive)?.id;return $t(u,p)??g}),u))},[$t]),dt=v(()=>{T(u=>(R(p=>{const g=u.findLast(S=>S.isActive)?.id;return At(u,p)??g}),u))},[At]);ht(()=>{const u=g=>{!c||D.current===0||(g===Oi&&lt(),g===Pi&&dt())};x.on("input",u);const p=x;return()=>{p.off("input",u)}},[c,lt,dt,x]);const Bt=v(()=>{b(!0)},[]),Ht=v(()=>{b(!1)},[]),Gt=v(u=>{T(p=>(p.some(g=>g?.id===u)&&R(u),p))},[]),Kt=v((u,{autoFocus:p})=>{T(g=>(D.current=g.length+1,[...g,{id:u,isActive:!0}])),p&&R(g=>g||u)},[]),Yt=v(u=>{R(p=>{if(p!==u)return p}),T(p=>{const g=p.filter(S=>S.id!==u);return D.current=g.length,g})},[]),Ft=v(u=>{T(p=>p.map(g=>g.id!==u?g:{id:u,isActive:!0}))},[]),jt=v(u=>{R(p=>{if(p!==u)return p}),T(p=>p.map(g=>g.id!==u?g:{id:u,isActive:!1}))},[]);ht(()=>()=>{const u=!m.destroyed&&!m.writableEnded;e&&u&&m.write(ot),L&&(C.current>0||E.current)&&j(),M.current>0&&(m.isTTY&&u&&m.write(Rt),M.current=0)},[m,L,j,e]);const Se=B(()=>({exit:tt,suspendTerminal:n,waitUntilRenderFlush:l}),[tt,n,l]),Re=B(()=>({internal_eventEmitter:x,internal_exitOnCtrlC:t,isRawModeSupported:L,setBracketedPasteMode:Dt,setRawMode:_t,stdin:h}),[h,_t,Dt,L,t,x]),Ce=B(()=>({stdout:m,write:d}),[m,d]),Ee=B(()=>({stderr:f,write:w}),[f,w]),Oe=B(()=>({setCursorPosition:a}),[a]),Pe=B(()=>({activate:Ft,activeId:y,add:Kt,deactivate:jt,disableFocus:Ht,enableFocus:Bt,focus:Gt,focusNext:lt,focusPrevious:dt,remove:Yt}),[y,Kt,Yt,Ft,jt,Bt,Ht,lt,dt,Gt]),Ne=B(()=>({renderThrottleMs:o,subscribe:Nt}),[Nt,o]);return _(ze.Provider,{value:Se,children:_(Ze.Provider,{value:Re,children:_(ti.Provider,{value:Ce,children:_(Qe.Provider,{value:Ee,children:_(Je.Provider,{value:Pe,children:_(qe.Provider,{value:Ne,children:_(Ve.Provider,{value:Oe,children:_(Xe,{onError:tt,children:i})})})})})})})})};we.displayName="InternalApp";const Ii=(i,t,e)=>{if(e<=0||!i.yogaNode)return"";const{yogaNode:s}=i,r=s.getComputedBorder(U.EDGE_LEFT),n=s.getComputedBorder(U.EDGE_RIGHT),l=s.getComputedBorder(U.EDGE_TOP),o=s.getComputedPadding(U.EDGE_LEFT),a=s.getComputedPadding(U.EDGE_RIGHT),f=s.getComputedPadding(U.EDGE_TOP),h=Math.round(s.getComputedWidth()-r-n-o-a);if(h<=0)return"";const m=new ei({height:e,width:h}),w=-(i.internal_scrollState?.scrollLeft??0)-r-o,d=-t-l-f;for(const c of i.childNodes)ii(c,m,{absoluteOffsetX:w,absoluteOffsetY:d,offsetX:w,offsetY:d,skipStaticElements:!1});return m.get().output},Ot=new WeakMap,z=i=>i??"default",ve=()=>{let i,t;return{consumeDelta:()=>{if(z(t)===z(i))return"";const e=z(t);return i=t,Zt(e)},consumeRestoreOnDone:()=>{const e=z(i)!=="default";return i=void 0,t=void 0,e?Zt("default"):""},isDirty:()=>z(t)!==z(i),setPending:e=>{t=e}}},rt=(i,t)=>t.endsWith(`
5
+ `)?i.length-1:i.length,be=i=>i.rows||1/0,wt=(i,t)=>Math.min(i,be(t)),ki=(i,{showCursor:t=!1}={})=>{let e=0,s="",r=!1,n,l=!1,o,a=!1;const f=ve(),h=()=>l?n:void 0,m=(d,c)=>{const b=gt(c,o);return d!==s||b||f.isDirty()},w=d=>{!t&&!r&&(i.write(nt),r=!0);const c=h();l=!1;const b=gt(c,o);if(!m(d,c))return!1;const y=f.consumeDelta(),R=d.split(`
6
+ `),T=rt(R,d),D=st(T,c);if(d===s&&b)i.write(y+he({cursorPosition:c,cursorWasShown:a,previousCursorPosition:o,previousLineCount:e,visibleLineCount:T}));else if(d===s&&y!=="")i.write(y);else{s=d;const N=mt(a,e,o);i.write(y+N+G(wt(e,i))+d+D),e=R.length}return o=c?{...c}:void 0,a=c!==void 0,!0};return w.clear=()=>{const d=mt(a,e,o);i.write(d+G(wt(e,i))),s="",e=0,o=void 0,a=!1},w.done=()=>{s="",e=0,o=void 0,a=!1;const d=f.consumeRestoreOnDone();d!==""&&i.write(d),t||(i.write(ot),r=!1)},w.reset=()=>{s="",e=0,o=void 0,a=!1},w.sync=d=>{const c=l?n:void 0;l=!1;const b=d.split(`
7
+ `);s=d,e=b.length;const y=f.consumeDelta();y!==""&&i.write(y),!c&&a&&i.write(nt),c&&i.write(st(rt(b,d),c)),o=c?{...c}:void 0,a=c!==void 0},w.setCursorPosition=d=>{n=d,l=!0},w.setCursorShape=f.setPending,w.isCursorDirty=()=>l||f.isDirty(),w.willRender=d=>m(d,h()),w},Li=(i,{showCursor:t=!1}={})=>{let e=[],s="",r=!1,n,l=!1,o,a=!1;const f=ve(),h=()=>l?n:void 0,m=(d,c)=>{const b=gt(c,o);return d!==s||b||f.isDirty()},w=d=>{!t&&!r&&(i.write(nt),r=!0);const c=h();l=!1;const b=gt(c,o);if(!m(d,c))return!1;const y=f.consumeDelta(),R=d.split(`
8
+ `),T=rt(R,d),D=rt(e,s);if(d===s&&b)return i.write(y+he({cursorPosition:c,cursorWasShown:a,previousCursorPosition:o,previousLineCount:e.length,visibleLineCount:T})),o=c?{...c}:void 0,a=c!==void 0,!0;if(d===s&&y!=="")return i.write(y),!0;const N=mt(a,e.length,o);if(d===`
9
9
  `||s.length===0){const x=st(T,c);return i.write(y+N+G(wt(e.length,i))+d+x),a=c!==void 0,o=c?{...c}:void 0,s=d,e=R,!0}const W=d.endsWith(`
10
- `),C=[y,N],E=be(i);if(T<_){const x=s.endsWith(`
11
- `)?1:0;C.push(G(Math.min(_-T+x,E)),Vt(Math.min(T,E-1)))}else C.push(Vt(Math.min(_-1,E-1)));for(let x=0;x<T;x++){const $=x===T-1;if(R[x]===e[x]){(!$||W)&&C.push(Ue());continue}C.push(We(0)+R[x]+$e+($&&!W?"":`
10
+ `),C=[y,N],E=be(i);if(T<D){const x=s.endsWith(`
11
+ `)?1:0;C.push(G(Math.min(D-T+x,E)),Vt(Math.min(T,E-1)))}else C.push(Vt(Math.min(D-1,E-1)));for(let x=0;x<T;x++){const $=x===T-1;if(R[x]===e[x]){(!$||W)&&C.push(We());continue}C.push($e(0)+R[x]+Ae+($&&!W?"":`
12
12
  `))}const M=st(T,c);return C.push(M),i.write(C.join("")),a=c!==void 0,o=c?{...c}:void 0,s=d,e=R,!0};return w.clear=()=>{const d=mt(a,e.length,o);i.write(d+G(wt(e.length,i))),s="",e=[],o=void 0,a=!1},w.done=()=>{s="",e=[],o=void 0,a=!1;const d=f.consumeRestoreOnDone();d!==""&&i.write(d),t||(i.write(ot),r=!1)},w.reset=()=>{s="",e=[],o=void 0,a=!1},w.sync=d=>{const c=l?n:void 0;l=!1;const b=d.split(`
13
- `);s=d,e=b;const y=f.consumeDelta();y!==""&&i.write(y),!c&&a&&i.write(nt),c&&i.write(st(rt(b,d),c)),o=c?{...c}:void 0,a=c!==void 0},w.setCursorPosition=d=>{n=d,l=!0},w.setCursorShape=f.setPending,w.isCursorDirty=()=>l||f.isDirty(),w.willRender=d=>m(d,h()),w},Li=(i,{incremental:t=!1,showCursor:e=!1}={})=>t?ki(i,{showCursor:e}):Ii(i,{showCursor:e}),Di={create:Li},ye=Ae(2026),H=le(ye),A=ce(ye);function _i(i,t){return"isTTY"in i&&i.isTTY&&(t??!fe)}let V;const Mi=()=>{if(V!==!1){if(V!==void 0)return V;try{return V=ni(import.meta.url).Renderer,V}catch{V=!1;return}}},Ui=i=>{const t=Mi();if(!t)return;let e,s=0,r=0;const n=(l,o)=>{(!e||s!==l||r!==o)&&(e?e.resize(l,o):e=new t(l,o),s=l,r=o)};return{clear(){if(e){const l=new Uint32Array(s*r*2),o=65535;for(let a=0;a<l.length;a+=2)l[a]=32,l[a+1]=o;e.render(l)}},destroy(){e=void 0},render(l,o,a){if(n(o,a),!!e){i.isTTY&&e.writeRaw(H);try{e.render(l)}finally{i.isTTY&&e.writeRaw(A)}}},resize(l,o){n(l,o)}}};function ne(i,t=0,e={}){const s=e.leading??!0,r=e.trailing??!0;let n,l,o,a;const f=()=>{if(l===void 0)return;const c=l;l=void 0,a=i(...c)},h=()=>{n!==void 0&&(clearTimeout(n),n=void 0)},m=()=>{n=void 0,r&&f(),l=void 0,o=void 0},w=()=>{h(),n=setTimeout(m,t)},d=function(...c){const b=Date.now();if(o??=b,b-o>=t)return l=c,f(),o=b,w(),a;l=c;const y=n===void 0;return w(),s&&y&&f(),a};return d.cancel=()=>{h(),l=void 0,o=void 0},d.flush=()=>(h(),f(),o=void 0,a),d}console.Console||(console.Console=Me);const it=()=>{},ue=async()=>new Promise(i=>{setImmediate(i)}),Wi=27,$i=91,Ai=63,Bi=117,Hi=48,Gi=57,Ki=i=>i>=Hi&&i<=Gi,xe=(i,t)=>{if(i[t]!==Wi||i[t+1]!==$i||i[t+2]!==Ai)return;let e=t+3;const s=e;for(;e<i.length&&Ki(i[e]);)e++;if(e!==s){if(e===i.length)return{state:"partial"};if(i[e]===Bi)return{endIndex:e,state:"complete"}}},Yi=i=>{for(let t=0;t<i.length;t++)if(xe(i,t)?.state==="complete")return!0;return!1},Fi=i=>{const t=[];let e=0;for(;e<i.length;){const s=xe(i,e);if(s?.state==="complete"){e=s.endIndex+1;continue}if(s?.state==="partial")break;t.push(i[e]),e++}return t},ji=({isTty:i,isUnmounting:t,isWindows:e,nextOutputHeight:s,previousOutputHeight:r,viewportRows:n})=>{if(!i)return!1;const l=r>0,o=r>=n,a=s>=n,f=r>n,h=s>n,m=o&&s<n;return f||h&&l||m||t&&o||e&&(a||o)},Ct=i=>i instanceof Error||Object.prototype.toString.call(i)==="[object Error]",ae=i=>{const t=!i.destroyed&&!i.writableEnded&&(i.writable??!0),e=i._writableState!==void 0||i.writableLength!==void 0;return{canWriteToStdout:t,hasWritableState:e}},ft=(i,t)=>{if(!i||typeof i.flush!="function")return;const e=i;t?e.flush():typeof e.cancel=="function"&&e.cancel()};class qi{isConcurrent;options;log;manualCursorPosition;renderedCursorPosition;renderedCursorRequested;throttledLog;isScreenReaderEnabled;interactive;renderThrottleMs;alternateScreen;isUnmounted;isUnmounting;lastOutput;lastOutputToRender;lastOutputHeight;lastTerminalWidth;nativeLog;useNativeRenderer;container;rootNode;fullStaticOutput;backbufferNode;backbufferMultiWarned=!1;exitPromise;exitResult;beforeExitHandler;restoreConsole;unsubscribeResize;throttledOnRender;hasPendingThrottledRender=!1;kittyProtocolEnabled=!1;kittyFlags;isSuspended=!1;pauseInput;resumeInput;cancelKittyDetection;nextRenderCommit;deferredInitDone=!1;constructor(t){this.options=t,this.rootNode=ri("ink-root"),this.rootNode.onComputeLayout=this.calculateLayout,this.isScreenReaderEnabled=t.isScreenReaderEnabled??P.env.INK_SCREEN_READER==="true",this.interactive=this.resolveInteractiveOption(t.interactive),this.alternateScreen=!1;const e=t.debug||this.isScreenReaderEnabled,s=t.maxFps??30,r=s>0?Math.max(1,Math.ceil(1e3/s)):0;this.renderThrottleMs=e?0:r;const n=e?this.onRender:(()=>{const o=ne(this.onRender,r,{leading:!0,trailing:!0});return this.throttledOnRender=o,()=>{this.hasPendingThrottledRender=!0,o()}})();if(e&&(this.throttledOnRender=void 0),t.standardReactLayoutTiming){let o=!1;const a=()=>{o||(o=!0,queueMicrotask(()=>{o=!1,this.onRender()}))};this.rootNode.onRender=a,this.rootNode.onImmediateRender=a}else this.rootNode.onRender=n,this.rootNode.onImmediateRender=this.onRender;this.rootNode.onStaticChange=this.handleStaticChange,this.log=Di.create(t.stdout,{incremental:t.incrementalRendering}),this.useNativeRenderer=t.useNativeRenderer??!1,this.useNativeRenderer&&(this.nativeLog=Ui(t.stdout),this.nativeLog||(this.useNativeRenderer=!1)),this.manualCursorPosition=void 0,this.renderedCursorPosition=void 0,this.renderedCursorRequested=!1,this.throttledLog=e?this.log:ne(o=>{const a=this.log.willRender(o),f=this.shouldSync();f&&a&&this.options.stdout.write(H),this.log(o),f&&a&&this.options.stdout.write(A)},void 0,{leading:!0,trailing:!0}),this.isUnmounted=!1,this.isUnmounting=!1,this.isConcurrent=t.concurrent??!1,this.lastOutput="",this.lastOutputToRender="",this.lastOutputHeight=0,this.lastTerminalWidth=q(this.options.stdout).columns,this.fullStaticOutput="";const l=t.concurrent?Ge:Ke;this.container=k.createContainer(this.rootNode,l,null,!1,null,"id",()=>{},()=>{},()=>{},()=>{}),this.unsubscribeExit=wi(this.unmount,{alwaysLast:!1}),this.setAlternateScreen(!!t.alternateScreen),t.patchConsole&&this.patchConsole(),this.interactive&&(t.stdout.on("resize",this.resized),this.unsubscribeResize=()=>{t.stdout.off("resize",this.resized)}),this.initImmediateKittyKeyboard(),P.env.DEV==="true"&&k.injectIntoDevTools(),this.exitPromise=new Promise((o,a)=>{this.resolveExitPromise=o,this.rejectExitPromise=a}),this.exitPromise.catch(it)}runDeferredInit(){this.deferredInitDone||(this.deferredInitDone=!0,this.initDeferredKittyKeyboard())}resized=()=>{const t=q(this.options.stdout).columns;t<this.lastTerminalWidth&&(this.log.clear(),this.lastOutput="",this.lastOutputToRender=""),ui(),this.calculateLayout(),oi(this.rootNode),this.onRender(),this.lastTerminalWidth=t};resolveExitPromise=()=>{};rejectExitPromise=()=>{};unsubscribeExit=()=>{};handleAppExit=t=>{if(!(this.isUnmounted||this.isUnmounting)){if(Ct(t)){this.unmount(t);return}this.exitResult=t,this.unmount()}};getActiveCursorPosition=()=>this.renderedCursorRequested?this.renderedCursorPosition:this.manualCursorPosition;setCursorPosition=t=>{this.manualCursorPosition=t,this.log.setCursorPosition(this.getActiveCursorPosition())};restoreLastOutput=()=>{this.interactive&&(this.log.setCursorPosition(this.getActiveCursorPosition()),this.log(this.lastOutputToRender||`${this.lastOutput}
14
- `))};calculateLayout=()=>{const t=s=>{const r=new Map;this.calculateScrollAndTriggerObservers(s,r);for(const[n,l]of r)n.internalTrigger(l)};this.backbufferNode=void 0,this.prepareYogaTree(this.rootNode,t);const e=q(this.options.stdout).columns;this.rootNode.yogaNode.setWidth(e),this.rootNode.yogaNode.calculateLayout(void 0,void 0,U.DIRECTION_LTR),t(this.rootNode)};calculateScrollAndTriggerObservers(t,e){if(t.nodeName==="ink-box"){const{style:s}=t,r=s.overflow??"visible",n=s.overflowX??r,l=s.overflowY??r;n==="scroll"||l==="scroll"?(di(t),s.overflowToBackbuffer&&(this.backbufferNode&&this.backbufferNode!==t&&!this.backbufferMultiWarned&&(this.backbufferMultiWarned=!0,console.warn("[@visulima/tui] Multiple scrollable regions have `overflowToBackbuffer` enabled; only one is supported. The last one in render order wins.")),this.backbufferNode=t)):t.internal_scrollState&&delete t.internal_scrollState}if(li(t,e),!t.internal_static)for(const s of t.childNodes)s.nodeName!=="#text"&&this.calculateScrollAndTriggerObservers(s,e)}recalculateLayout(){this.markAllTextNodesDirty(this.rootNode),this.calculateLayout(),this.onRender()}prepareYogaTree(t,e){if(t.isYogaTreeDetached&&!t.cachedRender&&t.yogaNode){for(t.yogaNode.setWidthAuto(),t.yogaNode.setHeightAuto(),ai(t.yogaNode,t.style);t.yogaNode.getChildCount()>0;)t.yogaNode.getChild(0).remove();let s=0;for(const r of t.childNodes){const n=r;r.nodeName!=="#text"&&n.yogaNode&&(t.yogaNode.insertChild(n.yogaNode,s),s++)}t.isYogaTreeDetached=!1,this.markAllTextNodesDirty(t)}for(const s of t.childNodes)s.nodeName!=="#text"&&this.prepareYogaTree(s,e);if(t.nodeName==="ink-static-render"&&!t.cachedRender){const s=q(this.options.stdout).columns,{width:r}=t.style;t.yogaNode&&(t.yogaNode.setWidth(typeof r=="number"?r:s),t.yogaNode.calculateLayout(void 0,void 0,U.DIRECTION_LTR)),e(t),ii(t,{skipStaticElements:!1}),t.internal_onRendered?.()}}markAllTextNodesDirty(t){if(!t.cachedRender){t.nodeName==="ink-text"&&t.yogaNode&&t.yogaNode.markDirty();for(const e of t.childNodes)e.nodeName!=="#text"&&this.markAllTextNodesDirty(e)}}handleStaticChange=()=>{this.fullStaticOutput=""};computeBackbufferOutput(){const t=this.backbufferNode;if(!t?.internal_scrollState||!this.interactive||!this.options.stdout.isTTY||this.alternateScreen||this.isScreenReaderEnabled||this.options.debug)return"";const e=Math.round(t.internal_scrollState.scrollTop),s=t.yogaNode?.getComputedPadding(U.EDGE_TOP)??0,r=Math.max(0,e-Math.round(s)),n=t.internal_maxPushedScrollTop??0,{maxScrollbackLength:l}=t.style,o=l===void 0?n:Math.max(n,r-Math.max(0,l)),a=r-o;if(a<=0)return"";const f=Ni(t,o,a);return f===""?"":(t.internal_maxPushedScrollTop=r,`${f}\x1B[0m
15
- `)}onRender=()=>{if(this.hasPendingThrottledRender=!1,this.isUnmounted)return;this.deferredInitDone||this.runDeferredInit(),this.nextRenderCommit&&(this.nextRenderCommit.resolve(),this.nextRenderCommit=void 0);const t=si(this.rootNode,this.isScreenReaderEnabled,{useNativeRenderer:this.useNativeRenderer}),{cursorPosition:e,cursorRequested:s,cursorShape:r,output:n,outputBuffer:l,outputHeight:o,outputWidth:a,staticOutput:f}=t;this.renderedCursorRequested=s,this.renderedCursorPosition=e,this.log.setCursorShape(s?r:void 0);const h=this.computeBackbufferOutput();if(this.useNativeRenderer&&this.nativeLog&&l&&a){f&&f!==`
13
+ `);s=d,e=b;const y=f.consumeDelta();y!==""&&i.write(y),!c&&a&&i.write(nt),c&&i.write(st(rt(b,d),c)),o=c?{...c}:void 0,a=c!==void 0},w.setCursorPosition=d=>{n=d,l=!0},w.setCursorShape=f.setPending,w.isCursorDirty=()=>l||f.isDirty(),w.willRender=d=>m(d,h()),w},_i=(i,{incremental:t=!1,showCursor:e=!1}={})=>t?Li(i,{showCursor:e}):ki(i,{showCursor:e}),Di={create:_i},ye=Be(2026),H=le(ye),A=ce(ye);function Mi(i,t){return"isTTY"in i&&i.isTTY&&(t??!fe)}let V;const Ui=()=>{if(V!==!1){if(V!==void 0)return V;try{return V=ui(import.meta.url).Renderer,V}catch{V=!1;return}}},Wi=i=>{const t=Ui();if(!t)return;let e,s=0,r=0;const n=(l,o)=>{(!e||s!==l||r!==o)&&(e?e.resize(l,o):e=new t(l,o),s=l,r=o)};return{clear(){if(e){const l=new Uint32Array(s*r*2),o=65535;for(let a=0;a<l.length;a+=2)l[a]=32,l[a+1]=o;e.render(l)}},destroy(){e=void 0},render(l,o,a){if(n(o,a),!!e){i.isTTY&&e.writeRaw(H);try{e.render(l)}finally{i.isTTY&&e.writeRaw(A)}}},resize(l,o){n(l,o)}}};function ne(i,t=0,e={}){const s=e.leading??!0,r=e.trailing??!0;let n,l,o,a;const f=()=>{if(l===void 0)return;const c=l;l=void 0,a=i(...c)},h=()=>{n!==void 0&&(clearTimeout(n),n=void 0)},m=()=>{n=void 0,r&&f(),l=void 0,o=void 0},w=()=>{h(),n=setTimeout(m,t)},d=function(...c){const b=Date.now();if(o??=b,b-o>=t)return l=c,f(),o=b,w(),a;l=c;const y=n===void 0;return w(),s&&y&&f(),a};return d.cancel=()=>{h(),l=void 0,o=void 0},d.flush=()=>(h(),f(),o=void 0,a),d}console.Console||(console.Console=Ue);const it=()=>{},ue=async()=>new Promise(i=>{setImmediate(i)}),$i=27,Ai=91,Bi=63,Hi=117,Gi=48,Ki=57,Yi=i=>i>=Gi&&i<=Ki,xe=(i,t)=>{if(i[t]!==$i||i[t+1]!==Ai||i[t+2]!==Bi)return;let e=t+3;const s=e;for(;e<i.length&&Yi(i[e]);)e++;if(e!==s){if(e===i.length)return{state:"partial"};if(i[e]===Hi)return{endIndex:e,state:"complete"}}},Fi=i=>{for(let t=0;t<i.length;t++)if(xe(i,t)?.state==="complete")return!0;return!1},ji=i=>{const t=[];let e=0;for(;e<i.length;){const s=xe(i,e);if(s?.state==="complete"){e=s.endIndex+1;continue}if(s?.state==="partial")break;t.push(i[e]),e++}return t},qi=({isTty:i,isUnmounting:t,isWindows:e,nextOutputHeight:s,previousOutputHeight:r,viewportRows:n})=>{if(!i)return!1;const l=r>0,o=r>=n,a=s>=n,f=r>n,h=s>n,m=o&&s<n;return f||h&&l||m||t&&o||e&&(a||o)},Ct=i=>i instanceof Error||Object.prototype.toString.call(i)==="[object Error]",ae=i=>{const t=!i.destroyed&&!i.writableEnded&&(i.writable??!0),e=i._writableState!==void 0||i.writableLength!==void 0;return{canWriteToStdout:t,hasWritableState:e}},ft=(i,t)=>{if(!i||typeof i.flush!="function")return;const e=i;t?e.flush():typeof e.cancel=="function"&&e.cancel()};class zi{isConcurrent;options;log;manualCursorPosition;renderedCursorPosition;renderedCursorRequested;throttledLog;isScreenReaderEnabled;interactive;renderThrottleMs;alternateScreen;isUnmounted;isUnmounting;lastOutput;lastOutputToRender;lastOutputHeight;lastTerminalWidth;nativeLog;useNativeRenderer;container;rootNode;fullStaticOutput;backbufferNode;backbufferMultiWarned=!1;exitPromise;exitResult;beforeExitHandler;restoreConsole;unsubscribeResize;throttledOnRender;hasPendingThrottledRender=!1;kittyProtocolEnabled=!1;kittyFlags;isSuspended=!1;pauseInput;resumeInput;cancelKittyDetection;nextRenderCommit;deferredInitDone=!1;constructor(t){this.options=t,this.rootNode=oi("ink-root"),this.rootNode.onComputeLayout=this.calculateLayout,this.isScreenReaderEnabled=t.isScreenReaderEnabled??P.env.INK_SCREEN_READER==="true",this.interactive=this.resolveInteractiveOption(t.interactive),this.alternateScreen=!1;const e=t.debug||this.isScreenReaderEnabled,s=t.maxFps??30,r=s>0?Math.max(1,Math.ceil(1e3/s)):0;this.renderThrottleMs=e?0:r;const n=e?this.onRender:(()=>{const o=ne(this.onRender,r,{leading:!0,trailing:!0});return this.throttledOnRender=o,()=>{this.hasPendingThrottledRender=!0,o()}})();if(e&&(this.throttledOnRender=void 0),t.standardReactLayoutTiming){let o=!1;const a=()=>{o||(o=!0,queueMicrotask(()=>{o=!1,this.onRender()}))};this.rootNode.onRender=a,this.rootNode.onImmediateRender=a}else this.rootNode.onRender=n,this.rootNode.onImmediateRender=this.onRender;this.rootNode.onStaticChange=this.handleStaticChange,this.log=Di.create(t.stdout,{incremental:t.incrementalRendering}),this.useNativeRenderer=t.useNativeRenderer??!1,this.useNativeRenderer&&(this.nativeLog=Wi(t.stdout),this.nativeLog||(this.useNativeRenderer=!1)),this.manualCursorPosition=void 0,this.renderedCursorPosition=void 0,this.renderedCursorRequested=!1,this.throttledLog=e?this.log:ne(o=>{const a=this.log.willRender(o),f=this.shouldSync();f&&a&&this.options.stdout.write(H),this.log(o),f&&a&&this.options.stdout.write(A)},void 0,{leading:!0,trailing:!0}),this.isUnmounted=!1,this.isUnmounting=!1,this.isConcurrent=t.concurrent??!1,this.lastOutput="",this.lastOutputToRender="",this.lastOutputHeight=0,this.lastTerminalWidth=q(this.options.stdout).columns,this.fullStaticOutput="";const l=t.concurrent?Ke:Ye;this.container=k.createContainer(this.rootNode,l,null,!1,null,"id",()=>{},()=>{},()=>{},()=>{}),this.unsubscribeExit=vi(this.unmount,{alwaysLast:!1}),this.setAlternateScreen(!!t.alternateScreen),t.patchConsole&&this.patchConsole(),this.interactive&&(t.stdout.on("resize",this.resized),this.unsubscribeResize=()=>{t.stdout.off("resize",this.resized)}),this.initImmediateKittyKeyboard(),P.env.DEV==="true"&&k.injectIntoDevTools(),this.exitPromise=new Promise((o,a)=>{this.resolveExitPromise=o,this.rejectExitPromise=a}),this.exitPromise.catch(it)}runDeferredInit(){this.deferredInitDone||(this.deferredInitDone=!0,this.initDeferredKittyKeyboard())}resized=()=>{const t=q(this.options.stdout).columns;t<this.lastTerminalWidth&&(this.log.clear(),this.lastOutput="",this.lastOutputToRender=""),ai(),this.calculateLayout(),ni(this.rootNode),this.onRender(),this.lastTerminalWidth=t};resolveExitPromise=()=>{};rejectExitPromise=()=>{};unsubscribeExit=()=>{};handleAppExit=t=>{if(!(this.isUnmounted||this.isUnmounting)){if(Ct(t)){this.unmount(t);return}this.exitResult=t,this.unmount()}};getActiveCursorPosition=()=>this.renderedCursorRequested?this.renderedCursorPosition:this.manualCursorPosition;setCursorPosition=t=>{this.manualCursorPosition=t,this.log.setCursorPosition(this.getActiveCursorPosition())};restoreLastOutput=()=>{this.interactive&&(this.log.setCursorPosition(this.getActiveCursorPosition()),this.log(this.lastOutputToRender||`${this.lastOutput}
14
+ `))};calculateLayout=()=>{const t=s=>{const r=new Map;this.calculateScrollAndTriggerObservers(s,r);for(const[n,l]of r)n.internalTrigger(l)};this.backbufferNode=void 0,this.prepareYogaTree(this.rootNode,t);const e=q(this.options.stdout).columns;this.rootNode.yogaNode.setWidth(e),this.rootNode.yogaNode.calculateLayout(void 0,void 0,U.DIRECTION_LTR),t(this.rootNode)};calculateScrollAndTriggerObservers(t,e){if(t.nodeName==="ink-box"){const{style:s}=t,r=s.overflow??"visible",n=s.overflowX??r,l=s.overflowY??r;n==="scroll"||l==="scroll"?(ci(t),s.overflowToBackbuffer&&(this.backbufferNode&&this.backbufferNode!==t&&!this.backbufferMultiWarned&&(this.backbufferMultiWarned=!0,console.warn("[@visulima/tui] Multiple scrollable regions have `overflowToBackbuffer` enabled; only one is supported. The last one in render order wins.")),this.backbufferNode=t)):t.internal_scrollState&&delete t.internal_scrollState}if(di(t,e),!t.internal_static)for(const s of t.childNodes)s.nodeName!=="#text"&&this.calculateScrollAndTriggerObservers(s,e)}recalculateLayout(){this.markAllTextNodesDirty(this.rootNode),this.calculateLayout(),this.onRender()}prepareYogaTree(t,e){if(t.isYogaTreeDetached&&!t.cachedRender&&t.yogaNode){for(t.yogaNode.setWidthAuto(),t.yogaNode.setHeightAuto(),li(t.yogaNode,t.style);t.yogaNode.getChildCount()>0;)t.yogaNode.getChild(0).remove();let s=0;for(const r of t.childNodes){const n=r;r.nodeName!=="#text"&&n.yogaNode&&(t.yogaNode.insertChild(n.yogaNode,s),s++)}t.isYogaTreeDetached=!1,this.markAllTextNodesDirty(t)}for(const s of t.childNodes)s.nodeName!=="#text"&&this.prepareYogaTree(s,e);if(t.nodeName==="ink-static-render"&&!t.cachedRender){const s=q(this.options.stdout).columns,{width:r}=t.style;t.yogaNode&&(t.yogaNode.setWidth(typeof r=="number"?r:s),t.yogaNode.calculateLayout(void 0,void 0,U.DIRECTION_LTR)),e(t),si(t,{skipStaticElements:!1}),t.internal_onRendered?.()}}markAllTextNodesDirty(t){if(!t.cachedRender){t.nodeName==="ink-text"&&t.yogaNode&&t.yogaNode.markDirty();for(const e of t.childNodes)e.nodeName!=="#text"&&this.markAllTextNodesDirty(e)}}handleStaticChange=()=>{this.fullStaticOutput=""};computeBackbufferOutput(){const t=this.backbufferNode;if(!t?.internal_scrollState||!this.interactive||!this.options.stdout.isTTY||this.alternateScreen||this.isScreenReaderEnabled||this.options.debug)return"";const e=Math.round(t.internal_scrollState.scrollTop),s=t.yogaNode?.getComputedPadding(U.EDGE_TOP)??0,r=Math.max(0,e-Math.round(s)),n=t.internal_maxPushedScrollTop??0,{maxScrollbackLength:l}=t.style,o=l===void 0?n:Math.max(n,r-Math.max(0,l)),a=r-o;if(a<=0)return"";const f=Ii(t,o,a);return f===""?"":(t.internal_maxPushedScrollTop=r,`${f}\x1B[0m
15
+ `)}onRender=()=>{if(this.hasPendingThrottledRender=!1,this.isUnmounted)return;this.deferredInitDone||this.runDeferredInit(),this.nextRenderCommit&&(this.nextRenderCommit.resolve(),this.nextRenderCommit=void 0);const t=ri(this.rootNode,this.isScreenReaderEnabled,{useNativeRenderer:this.useNativeRenderer}),{cursorPosition:e,cursorRequested:s,cursorShape:r,output:n,outputBuffer:l,outputHeight:o,outputWidth:a,staticOutput:f}=t;this.renderedCursorRequested=s,this.renderedCursorPosition=e,this.log.setCursorShape(s?r:void 0);const h=this.computeBackbufferOutput();if(this.useNativeRenderer&&this.nativeLog&&l&&a){f&&f!==`
16
16
  `&&this.options.stdout.write(f),h&&this.options.stdout.write(h),this.nativeLog.render(l,a,o),this.lastOutputHeight=o;return}s&&this.log.setCursorPosition(this.getActiveCursorPosition());const m=f&&f!==`
17
17
  `;if(this.options.debug){m&&(this.fullStaticOutput+=f),this.lastOutput=n,this.lastOutputToRender=n,this.lastOutputHeight=o,this.options.stdout.write(this.fullStaticOutput+n);return}if(!this.interactive){m&&this.options.stdout.write(f),this.lastOutput=n,this.lastOutputToRender=`${n}
18
- `,this.lastOutputHeight=o;return}if(this.isScreenReaderEnabled){const w=this.shouldSync();if(w&&this.options.stdout.write(H),m){const b=this.lastOutputHeight>0?G(this.lastOutputHeight):"";this.options.stdout.write(b+f),this.lastOutputHeight=0}if(n===this.lastOutput&&!m){w&&this.options.stdout.write(A);return}const d=q(this.options.stdout).columns,c=He(n,{trim:!1,width:d,wrapMode:"BREAK_WORDS"}).replace(/\n$/,"");if(m)this.options.stdout.write(c);else{const b=this.lastOutputHeight>0?G(this.lastOutputHeight):"";this.options.stdout.write(b+c)}this.lastOutput=n,this.lastOutputToRender=c,this.lastOutputHeight=c===""?0:c.split(`
19
- `).length,w&&this.options.stdout.write(A);return}m&&(this.fullStaticOutput+=f),this.renderInteractiveFrame(n,o,m?f:"",h)};accessibilityContextValue;render(t){this.accessibilityContextValue??={isScreenReaderEnabled:this.isScreenReaderEnabled};const e=D(Ye.Provider,{value:this.accessibilityContextValue,children:D(we,{exitOnCtrlC:this.options.exitOnCtrlC,interactive:this.interactive,onExit:this.handleAppExit,onRegisterInputControl:this.registerInputControl,onSuspendTerminal:this.suspendTerminal,onWaitUntilRenderFlush:this.waitUntilRenderFlush,renderThrottleMs:this.renderThrottleMs,setCursorPosition:this.setCursorPosition,stderr:this.options.stderr,stdin:this.options.stdin,stdout:this.options.stdout,writeToStderr:this.writeToStderr,writeToStdout:this.writeToStdout,children:t})});this.options.concurrent?k.updateContainer(e,this.container,null,it):(k.updateContainerSync(e,this.container,null,it),k.flushSyncWork())}writeToStdout=t=>{if(this.isUnmounted)return;if(this.options.debug){this.options.stdout.write(t+this.fullStaticOutput+this.lastOutput);return}if(!this.interactive){this.options.stdout.write(t);return}const e=this.shouldSync();e&&this.options.stdout.write(H),this.log.clear(),this.options.stdout.write(t),this.restoreLastOutput(),e&&this.options.stdout.write(A)};writeToStderr=t=>{if(this.isUnmounted)return;if(this.options.debug){this.options.stderr.write(t),this.options.stdout.write(this.fullStaticOutput+this.lastOutput);return}if(!this.interactive){this.options.stderr.write(t);return}const e=this.shouldSync();e&&this.options.stdout.write(H),this.log.clear(),this.options.stderr.write(t),this.restoreLastOutput(),e&&this.options.stdout.write(A)};unmount=t=>{if(this.isUnmounted||this.isUnmounting)return;this.isUnmounting=!0,this.beforeExitHandler&&(P.off("beforeExit",this.beforeExitHandler),this.beforeExitHandler=void 0);const e=this.options.stdout,{canWriteToStdout:s,hasWritableState:r}=ae(e);ft(this.throttledOnRender,s),s&&!this.alternateScreen&&(!this.throttledOnRender||!this.hasPendingThrottledRender&&this.fullStaticOutput==="")&&(this.calculateLayout(),this.onRender()),this.isUnmounted=!0,this.unsubscribeExit(),ft(this.throttledLog,s),typeof this.restoreConsole=="function"&&this.restoreConsole();const n=()=>{typeof this.unsubscribeResize=="function"&&this.unsubscribeResize(),this.cancelKittyDetection&&this.cancelKittyDetection(),s&&(this.kittyProtocolEnabled&&this.writeBestEffort(this.options.stdout,"\x1B[<u"),this.alternateScreen?(this.log.clear(),this.log.done(),this.lastOutput="",this.lastOutputToRender="",this.lastOutputHeight=0,this.fullStaticOutput="",this.writeBestEffort(this.options.stdout,Jt),this.writeBestEffort(this.options.stdout,ot),this.alternateScreen=!1):this.interactive?this.options.debug||this.log.done():this.options.stdout.write(this.options.debug?`
18
+ `,this.lastOutputHeight=o;return}if(this.isScreenReaderEnabled){const w=this.shouldSync();if(w&&this.options.stdout.write(H),m){const b=this.lastOutputHeight>0?G(this.lastOutputHeight):"";this.options.stdout.write(b+f),this.lastOutputHeight=0}if(n===this.lastOutput&&!m){w&&this.options.stdout.write(A);return}const d=q(this.options.stdout).columns,c=Ge(n,{trim:!1,width:d,wrapMode:"BREAK_WORDS"}).replace(/\n$/,"");if(m)this.options.stdout.write(c);else{const b=this.lastOutputHeight>0?G(this.lastOutputHeight):"";this.options.stdout.write(b+c)}this.lastOutput=n,this.lastOutputToRender=c,this.lastOutputHeight=c===""?0:c.split(`
19
+ `).length,w&&this.options.stdout.write(A);return}m&&(this.fullStaticOutput+=f),this.renderInteractiveFrame(n,o,m?f:"",h)};accessibilityContextValue;render(t){this.accessibilityContextValue??={isScreenReaderEnabled:this.isScreenReaderEnabled};const e=_(Fe.Provider,{value:this.accessibilityContextValue,children:_(we,{exitOnCtrlC:this.options.exitOnCtrlC,interactive:this.interactive,onExit:this.handleAppExit,onRegisterInputControl:this.registerInputControl,onSuspendTerminal:this.suspendTerminal,onWaitUntilRenderFlush:this.waitUntilRenderFlush,renderThrottleMs:this.renderThrottleMs,setCursorPosition:this.setCursorPosition,stderr:this.options.stderr,stdin:this.options.stdin,stdout:this.options.stdout,writeToStderr:this.writeToStderr,writeToStdout:this.writeToStdout,children:t})});this.options.concurrent?k.updateContainer(e,this.container,null,it):(k.updateContainerSync(e,this.container,null,it),k.flushSyncWork())}writeToStdout=t=>{if(this.isUnmounted)return;if(this.options.debug){this.options.stdout.write(t+this.fullStaticOutput+this.lastOutput);return}if(!this.interactive){this.options.stdout.write(t);return}const e=this.shouldSync();e&&this.options.stdout.write(H),this.log.clear(),this.options.stdout.write(t),this.restoreLastOutput(),e&&this.options.stdout.write(A)};writeToStderr=t=>{if(this.isUnmounted)return;if(this.options.debug){this.options.stderr.write(t),this.options.stdout.write(this.fullStaticOutput+this.lastOutput);return}if(!this.interactive){this.options.stderr.write(t);return}const e=this.shouldSync();e&&this.options.stdout.write(H),this.log.clear(),this.options.stderr.write(t),this.restoreLastOutput(),e&&this.options.stdout.write(A)};unmount=t=>{if(this.isUnmounted||this.isUnmounting)return;this.isUnmounting=!0,this.beforeExitHandler&&(P.off("beforeExit",this.beforeExitHandler),this.beforeExitHandler=void 0);const e=this.options.stdout,{canWriteToStdout:s,hasWritableState:r}=ae(e);ft(this.throttledOnRender,s),s&&!this.alternateScreen&&(!this.throttledOnRender||!this.hasPendingThrottledRender&&this.fullStaticOutput==="")&&(this.calculateLayout(),this.onRender()),this.isUnmounted=!0,this.unsubscribeExit(),ft(this.throttledLog,s),typeof this.restoreConsole=="function"&&this.restoreConsole();const n=()=>{typeof this.unsubscribeResize=="function"&&this.unsubscribeResize(),this.cancelKittyDetection&&this.cancelKittyDetection(),s&&(this.kittyProtocolEnabled&&this.writeBestEffort(this.options.stdout,"\x1B[<u"),this.alternateScreen?(this.log.clear(),this.log.done(),this.lastOutput="",this.lastOutputToRender="",this.lastOutputHeight=0,this.fullStaticOutput="",this.writeBestEffort(this.options.stdout,Jt),this.writeBestEffort(this.options.stdout,ot),this.alternateScreen=!1):this.interactive?this.options.debug||this.log.done():this.options.stdout.write(this.options.debug?`
20
20
  `:`${this.lastOutput}
21
21
  `)),this.kittyProtocolEnabled=!1,Ot.delete(this.options.stdout);const{exitResult:o}=this,a=()=>{Ct(t)?this.rejectExitPromise(t):this.resolveExitPromise(o)};t!==void 0&&!Ct(t)?a():s&&r?this.options.stdout.write("",a):setImmediate(a)},l=k;this.options.concurrent?(k.updateContainerSync(null,this.container,null,it),k.flushSyncWork(),l.flushPassiveEffects?.(),n()):(k.updateContainerSync(null,this.container,null,it),k.flushSyncWork(),n())};async waitUntilExit(){return this.beforeExitHandler||(this.beforeExitHandler=()=>{this.unmount()},P.on("beforeExit",this.beforeExitHandler)),this.exitPromise}async waitUntilRenderFlush(){if(this.isUnmounted||this.isUnmounting){await this.awaitExit();return}if(await ue(),this.isUnmounted||this.isUnmounting){await this.awaitExit();return}if(this.isConcurrent&&this.hasPendingConcurrentWork()&&(await Promise.race([this.awaitNextRender(),this.awaitExit()]),this.isUnmounted||this.isUnmounting)){this.nextRenderCommit=void 0,await this.awaitExit();return}k.flushSyncWork();const t=this.options.stdout,{canWriteToStdout:e,hasWritableState:s}=ae(t);if(ft(this.throttledOnRender,e),ft(this.throttledLog,e),e&&s){await new Promise(r=>{this.options.stdout.write("",()=>{r()})});return}await ue()}clear(){this.interactive&&!this.options.debug&&(this.log.clear(),this.log.sync(this.lastOutputToRender||`${this.lastOutput}
22
- `))}patchConsole(){this.options.debug||(this.restoreConsole=ci((t,e)=>{t==="stdout"&&this.writeToStdout(e),t==="stderr"&&(e.startsWith("The above error occurred")||this.writeToStderr(e))}))}setAlternateScreen(t){this.alternateScreen=this.resolveAlternateScreenOption(t,this.interactive),this.alternateScreen&&(this.writeBestEffort(this.options.stdout,Xt),this.writeBestEffort(this.options.stdout,nt))}resolveInteractiveOption(t){return t??(!fe&&!!this.options.stdout.isTTY)}resolveAlternateScreenOption(t,e){return!!t&&e&&!!this.options.stdout.isTTY}shouldSync(){return _i(this.options.stdout,this.interactive)}writeBestEffort(t,e){try{t.write(e)}catch{}}async awaitExit(){try{await this.exitPromise}catch{}}hasPendingConcurrentWork(){const t=this.container;return(t.pendingLanes??0)!==0&&t.callbackNode!==void 0&&t.callbackNode!==null}async awaitNextRender(){if(!this.nextRenderCommit){let t;const e=new Promise(s=>{t=s});this.nextRenderCommit={promise:e,resolve:t}}return this.nextRenderCommit.promise}renderInteractiveFrame(t,e,s,r=""){const n=s+r,l=n!=="",o=this.options.stdout.isTTY,a=o?q(this.options.stdout).rows:24,f=o&&e>=a,h=f?t:`${t}
23
- `,m=P.platform==="win32",w=o&&m&&(f||this.lastOutputHeight>=a);if(ji({isTty:o,isUnmounting:this.isUnmounting,isWindows:m,nextOutputHeight:e,previousOutputHeight:this.lastOutputHeight,viewportRows:a})){if(this.options.incrementalRendering&&!w){l&&(this.log.clear(),this.options.stdout.write(n)),(t!==this.lastOutput||this.log.isCursorDirty()||l)&&this.throttledLog(h),this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e;return}const d=this.shouldSync();d&&this.options.stdout.write(H),this.options.stdout.write(Be+this.fullStaticOutput+r+t),this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e,this.log.sync(h),d&&this.options.stdout.write(A);return}if(l){const d=this.shouldSync();d&&this.options.stdout.write(H),this.log.clear(),this.options.stdout.write(n),this.log(h),d&&this.options.stdout.write(A)}else(t!==this.lastOutput||this.log.isCursorDirty())&&this.throttledLog(h);this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e}initImmediateKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="enabled")return;const e=t.flags??["disambiguateEscapeCodes"];this.options.stdin.isTTY&&this.options.stdout.isTTY&&this.enableKittyProtocol(e)}initDeferredKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="auto")return;const e=t.flags??["disambiguateEscapeCodes"];!this.interactive||!this.options.stdin.isTTY||!this.options.stdout.isTTY||this.confirmKittySupport(e)}confirmKittySupport(t){const{stdin:e,stdout:s}=this.options;let r=[];const n=()=>{this.cancelKittyDetection=void 0,clearTimeout(o),e.removeListener("data",l);const a=Fi(r);r=[],a.length>0&&e.unshift(zt.from(a))},l=a=>{const f=typeof a=="string"?zt.from(a):a;for(const h of f)r.push(h);Yi(r)&&(n(),this.isUnmounted||this.enableKittyProtocol(t))};e.on("data",l);const o=setTimeout(n,200);this.cancelKittyDetection=n,s.write("\x1B[?u")}registerInputControl=(t,e)=>{this.pauseInput=t,this.resumeInput=e};suspendTerminal=(async t=>{if(this.beginSuspend(),t){try{await t()}finally{await this.endSuspend()}return}const e=async()=>{await this.endSuspend()};return{resume:e,[Symbol.asyncDispose]:e}});beginSuspend(){if(this.isSuspended)throw new Error("The terminal is already suspended. Resume the current suspension before suspending again.");if(this.isSuspended=!0,!(!this.interactive||this.isUnmounted||this.isUnmounting))try{this.log.clear(),this.log.done(),this.kittyProtocolEnabled&&this.writeBestEffort(this.options.stdout,"\x1B[<u"),this.alternateScreen&&(this.writeBestEffort(this.options.stdout,Jt),this.writeBestEffort(this.options.stdout,ot)),this.pauseInput?.()}catch(t){this.isSuspended=!1;try{this.resumeInput?.()}catch{}throw t}}async endSuspend(){if(this.isSuspended&&(this.isSuspended=!1,this.resumeInput?.(),!(!this.interactive||this.isUnmounted||this.isUnmounting))){this.alternateScreen&&this.writeBestEffort(this.options.stdout,Xt),this.kittyProtocolEnabled&&this.kittyFlags&&this.writeBestEffort(this.options.stdout,`\x1B[>${Qt(this.kittyFlags)}u`),this.lastOutput="",this.lastOutputToRender="",this.lastOutputHeight=0,this.log.reset();try{this.calculateLayout(),this.onRender(),await this.waitUntilRenderFlush()}catch{}}}enableKittyProtocol(t){this.kittyFlags=t,this.options.stdout.write(`\x1B[>${Qt(t)}u`),this.kittyProtocolEnabled=!0}}const Cs=(i,t)=>{const e={alternateScreen:!1,concurrent:!1,debug:!1,exitOnCtrlC:!0,incrementalRendering:!1,maxFps:30,patchConsole:!0,stderr:P.stderr,stdin:P.stdin,stdout:P.stdout,...zi(t)},s=Vi(e.stdout,()=>new qi(e));return s.render(i),{cleanup(){s.unmount()},clear(){s.clear()},rerender(r){s.render(r)},rootNode:s.rootNode,unmount(){s.unmount()},waitUntilExit(){return s.waitUntilExit()},waitUntilRenderFlush(){return s.waitUntilRenderFlush()}}},zi=(i={})=>i instanceof _e?{stdin:P.stdin,stdout:i}:i,Vi=(i,t)=>{const e=Ot.get(i);if(e===void 0){const s=t();return Ot.set(i,s),s}return P.stderr.write(`Warning: render() was called again for the same stdout before the previous Ink instance was unmounted. Reusing stdout across multiple render() calls is unsupported. Call unmount() first.
24
- `),e};export{Cs as default};
22
+ `))}patchConsole(){this.options.debug||(this.restoreConsole=hi((t,e)=>{t==="stdout"&&this.writeToStdout(e),t==="stderr"&&(e.startsWith("The above error occurred")||this.writeToStderr(e))}))}setAlternateScreen(t){this.alternateScreen=this.resolveAlternateScreenOption(t,this.interactive),this.alternateScreen&&(this.writeBestEffort(this.options.stdout,Xt),this.writeBestEffort(this.options.stdout,nt))}resolveInteractiveOption(t){return t??(!fe&&!!this.options.stdout.isTTY)}resolveAlternateScreenOption(t,e){return!!t&&e&&!!this.options.stdout.isTTY}shouldSync(){return Mi(this.options.stdout,this.interactive)}writeBestEffort(t,e){try{t.write(e)}catch{}}async awaitExit(){try{await this.exitPromise}catch{}}hasPendingConcurrentWork(){const t=this.container;return(t.pendingLanes??0)!==0&&t.callbackNode!==void 0&&t.callbackNode!==null}async awaitNextRender(){if(!this.nextRenderCommit){let t;const e=new Promise(s=>{t=s});this.nextRenderCommit={promise:e,resolve:t}}return this.nextRenderCommit.promise}renderInteractiveFrame(t,e,s,r=""){const n=s+r,l=n!=="",o=this.options.stdout.isTTY,a=o?q(this.options.stdout).rows:24,f=o&&e>=a,h=f?t:`${t}
23
+ `,m=P.platform==="win32",w=o&&m&&(f||this.lastOutputHeight>=a);if(qi({isTty:o,isUnmounting:this.isUnmounting,isWindows:m,nextOutputHeight:e,previousOutputHeight:this.lastOutputHeight,viewportRows:a})){if(this.options.incrementalRendering&&!w){l&&(this.log.clear(),this.options.stdout.write(n)),(t!==this.lastOutput||this.log.isCursorDirty()||l)&&this.throttledLog(h),this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e;return}const d=this.shouldSync();d&&this.options.stdout.write(H),this.options.stdout.write(He+this.fullStaticOutput+r+t),this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e,this.log.sync(h),d&&this.options.stdout.write(A);return}if(l){const d=this.shouldSync();d&&this.options.stdout.write(H),this.log.clear(),this.options.stdout.write(n),this.log(h),d&&this.options.stdout.write(A)}else(t!==this.lastOutput||this.log.isCursorDirty())&&this.throttledLog(h);this.lastOutput=t,this.lastOutputToRender=h,this.lastOutputHeight=e}initImmediateKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="enabled")return;const e=t.flags??["disambiguateEscapeCodes"];this.options.stdin.isTTY&&this.options.stdout.isTTY&&this.enableKittyProtocol(e)}initDeferredKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="auto")return;const e=t.flags??["disambiguateEscapeCodes"];!this.interactive||!this.options.stdin.isTTY||!this.options.stdout.isTTY||this.confirmKittySupport(e)}confirmKittySupport(t){const{stdin:e,stdout:s}=this.options;let r=[];const n=()=>{this.cancelKittyDetection=void 0,clearTimeout(o),e.removeListener("data",l);const a=ji(r);r=[],a.length>0&&e.unshift(zt.from(a))},l=a=>{const f=typeof a=="string"?zt.from(a):a;for(const h of f)r.push(h);Fi(r)&&(n(),this.isUnmounted||this.enableKittyProtocol(t))};e.on("data",l);const o=setTimeout(n,200);this.cancelKittyDetection=n,s.write("\x1B[?u")}registerInputControl=(t,e)=>{this.pauseInput=t,this.resumeInput=e};suspendTerminal=(async t=>{if(this.beginSuspend(),t){try{await t()}finally{await this.endSuspend()}return}const e=async()=>{await this.endSuspend()};return{resume:e,[Symbol.asyncDispose]:e}});beginSuspend(){if(this.isSuspended)throw new Error("The terminal is already suspended. Resume the current suspension before suspending again.");if(this.isSuspended=!0,!(!this.interactive||this.isUnmounted||this.isUnmounting))try{this.log.clear(),this.log.done(),this.kittyProtocolEnabled&&this.writeBestEffort(this.options.stdout,"\x1B[<u"),this.alternateScreen&&(this.writeBestEffort(this.options.stdout,Jt),this.writeBestEffort(this.options.stdout,ot)),this.pauseInput?.()}catch(t){this.isSuspended=!1;try{this.resumeInput?.()}catch{}throw t}}async endSuspend(){if(this.isSuspended&&(this.isSuspended=!1,this.resumeInput?.(),!(!this.interactive||this.isUnmounted||this.isUnmounting))){this.alternateScreen&&this.writeBestEffort(this.options.stdout,Xt),this.kittyProtocolEnabled&&this.kittyFlags&&this.writeBestEffort(this.options.stdout,`\x1B[>${Qt(this.kittyFlags)}u`),this.lastOutput="",this.lastOutputToRender="",this.lastOutputHeight=0,this.log.reset();try{this.calculateLayout(),this.onRender(),await this.waitUntilRenderFlush()}catch{}}}enableKittyProtocol(t){this.kittyFlags=t,this.options.stdout.write(`\x1B[>${Qt(t)}u`),this.kittyProtocolEnabled=!0}}const Es=(i,t)=>{const e={alternateScreen:!1,concurrent:!1,debug:!1,exitOnCtrlC:!0,incrementalRendering:!1,maxFps:30,patchConsole:!0,stderr:P.stderr,stdin:P.stdin,stdout:P.stdout,...Vi(t)},s=Xi(e.stdout,()=>new zi(e));return s.render(i),{cleanup(){s.unmount()},clear(){s.clear()},rerender(r){s.render(r)},rootNode:s.rootNode,unmount(){s.unmount()},waitUntilExit(){return s.waitUntilExit()},waitUntilRenderFlush(){return s.waitUntilRenderFlush()}}},Vi=(i={})=>i instanceof Me?{stdin:P.stdin,stdout:i}:i,Xi=(i,t)=>{const e=Ot.get(i);if(e===void 0){const s=t();return Ot.set(i,s),s}return P.stderr.write(`Warning: render() was called again for the same stdout before the previous Ink instance was unmounted. Reusing stdout across multiple render() calls is unsupported. Call unmount() first.
24
+ `),e};export{Es as default};
@@ -1 +1 @@
1
- import i from"react";import{FocusProvider as y,useFocusManager as W}from"./FocusContext-C2Sosxa4.js";import{TuiContext as I,useInput as z}from"./TuiContext-BNmP0lMY.js";import{LayoutNode as v}from"./LayoutNode-LPYsuzBg.js";import{T as f,s as P}from"./reconciler-ClpU7Y-V.js";import{renderTreeToBuffer as F}from"./renderTreeToBuffer-BpSD0sBJ.js";import{TuiApp as L}from"./TuiApp-DjIgv5Sk.js";import{InputParser as T}from"./InputParser-CiBitCva.js";import{terminalSize as G}from"./Renderer-DsskdkUd.js";import{createInlineLoop as M}from"./createInlineLoop-BT40Wpmx.js";const R=n=>i.createElement("box",n,n.children),K=n=>i.createElement("text",n,n.children),Q=()=>i.createElement(R,{flexGrow:1}),b=({children:n})=>{const{disableFocus:c,enableFocus:e,focusNext:a,focusPrevious:o}=W();return z((w,s)=>{s.tab&&!s.shift&&a(),s.tab&&s.shift&&o(),s.escape&&(c(),e())}),i.createElement(i.Fragment,null,n)};function V(n,c){const e=new L,a=new T(process.stdin),o=new v,{height:w,width:s}=e.getSize();o.yogaNode.setWidth(s),o.yogaNode.setHeight(w);const u=f.createContainer(o,0,null,!1,null,"",t=>console.error(t),null),p=t=>i.createElement(I.Provider,{value:{app:e,input:a,writeStderr:l=>e.writeStderr(l),writeStdout:l=>e.writeStdout(l)}},i.createElement(y,null,i.createElement(b,null,t)));f.updateContainer(p(n),u,null,()=>{});const h=(t,l)=>o.calculateLayout(t,l),x=(t,l,H)=>F(o,t,l,H),g=()=>e.paintNow(h,x);let S=!1;P(()=>{S=!0});const d=Math.round(1e3/(c?.maxFps??60)),E=setInterval(()=>{S&&(S=!1,g())},d);let N;const r=new Promise(t=>{N=t}),m=()=>{clearInterval(E),f.updateContainer(null,u,null,()=>{}),o.destroy(),e.stop(),a.stop(),process.off("SIGWINCH",C),N()};a.on("exit",()=>{m(),process.exit(0)}),e.on("quit",()=>{m(),process.exit(0)}),a.start(),e.start();const C=()=>{const t=process.stdout.columns||80,l=process.stdout.rows||24;e.resize(t,l),o.yogaNode.setWidth(t),o.yogaNode.setHeight(l),e.emit("resize"),g()};return process.on("SIGWINCH",C),g(),{app:e,input:a,rerender(t){f.updateContainer(p(t),u,null,()=>{})},unmount(){m()},waitUntilExit(){return r}}}function X(n,c){const e=G(),a=c?.rows??10,{cols:o}=e,w=Math.min(a,e.rows),s=new T(process.stdin),u=new v;u.yogaNode.setWidth(o),u.yogaNode.setHeight(w);const p=[],h=[],x={quit:()=>d.stop(),writeStderr:r=>h.push(r),writeStdout:r=>p.push(r)},g=f.createContainer(u,0,null,!1,null,"",r=>console.error(r),null),S=r=>i.createElement(I.Provider,{value:{app:x,input:s,writeStderr:x.writeStderr,writeStdout:x.writeStdout}},i.createElement(y,null,i.createElement(b,null,r)));f.updateContainer(S(n),g,null,()=>{}),P(()=>{});const d=M((r,m,C)=>{u.calculateLayout(m,C),F(u,r,m,C)},{...c,fps:c?.maxFps??c?.fps??60,rows:w});s.on("exit",()=>d.stop());let E;const N=new Promise(r=>{E=r});return process.on("exit",()=>{p.length>0&&process.stdout.write(p.join("")),h.length>0&&process.stderr.write(h.join("")),E()}),d.start(),s.start(),{unmount(){d.stop()},waitUntilExit(){return N}}}export{R as _Box,Q as _Spacer,K as _Text,V as render,X as renderInline};
1
+ import i from"react";import{FocusProvider as y,useFocusManager as W}from"./FocusContext-C2Sosxa4.js";import{TuiContext as I,useInput as z}from"./TuiContext-BNmP0lMY.js";import{LayoutNode as v}from"./LayoutNode-LPYsuzBg.js";import{T as f,s as P}from"./reconciler-ClpU7Y-V.js";import{renderTreeToBuffer as F}from"./renderTreeToBuffer-BpSD0sBJ.js";import{TuiApp as L}from"./TuiApp-CCVaiKbf.js";import{InputParser as T}from"./InputParser-CiBitCva.js";import{terminalSize as G}from"./Renderer-BeS49FNq.js";import{createInlineLoop as M}from"./createInlineLoop-DnEvE2eM.js";const R=n=>i.createElement("box",n,n.children),K=n=>i.createElement("text",n,n.children),Q=()=>i.createElement(R,{flexGrow:1}),b=({children:n})=>{const{disableFocus:c,enableFocus:e,focusNext:a,focusPrevious:o}=W();return z((w,s)=>{s.tab&&!s.shift&&a(),s.tab&&s.shift&&o(),s.escape&&(c(),e())}),i.createElement(i.Fragment,null,n)};function V(n,c){const e=new L,a=new T(process.stdin),o=new v,{height:w,width:s}=e.getSize();o.yogaNode.setWidth(s),o.yogaNode.setHeight(w);const u=f.createContainer(o,0,null,!1,null,"",t=>console.error(t),null),p=t=>i.createElement(I.Provider,{value:{app:e,input:a,writeStderr:l=>e.writeStderr(l),writeStdout:l=>e.writeStdout(l)}},i.createElement(y,null,i.createElement(b,null,t)));f.updateContainer(p(n),u,null,()=>{});const h=(t,l)=>o.calculateLayout(t,l),x=(t,l,H)=>F(o,t,l,H),g=()=>e.paintNow(h,x);let S=!1;P(()=>{S=!0});const d=Math.round(1e3/(c?.maxFps??60)),E=setInterval(()=>{S&&(S=!1,g())},d);let N;const r=new Promise(t=>{N=t}),m=()=>{clearInterval(E),f.updateContainer(null,u,null,()=>{}),o.destroy(),e.stop(),a.stop(),process.off("SIGWINCH",C),N()};a.on("exit",()=>{m(),process.exit(0)}),e.on("quit",()=>{m(),process.exit(0)}),a.start(),e.start();const C=()=>{const t=process.stdout.columns||80,l=process.stdout.rows||24;e.resize(t,l),o.yogaNode.setWidth(t),o.yogaNode.setHeight(l),e.emit("resize"),g()};return process.on("SIGWINCH",C),g(),{app:e,input:a,rerender(t){f.updateContainer(p(t),u,null,()=>{})},unmount(){m()},waitUntilExit(){return r}}}function X(n,c){const e=G(),a=c?.rows??10,{cols:o}=e,w=Math.min(a,e.rows),s=new T(process.stdin),u=new v;u.yogaNode.setWidth(o),u.yogaNode.setHeight(w);const p=[],h=[],x={quit:()=>d.stop(),writeStderr:r=>h.push(r),writeStdout:r=>p.push(r)},g=f.createContainer(u,0,null,!1,null,"",r=>console.error(r),null),S=r=>i.createElement(I.Provider,{value:{app:x,input:s,writeStderr:x.writeStderr,writeStdout:x.writeStdout}},i.createElement(y,null,i.createElement(b,null,r)));f.updateContainer(S(n),g,null,()=>{}),P(()=>{});const d=M((r,m,C)=>{u.calculateLayout(m,C),F(u,r,m,C)},{...c,fps:c?.maxFps??c?.fps??60,rows:w});s.on("exit",()=>d.stop());let E;const N=new Promise(r=>{E=r});return process.on("exit",()=>{p.length>0&&process.stdout.write(p.join("")),h.length>0&&process.stderr.write(h.join("")),E()}),d.start(),s.start(),{unmount(){d.stop()},waitUntilExit(){return N}}}export{R as _Box,Q as _Spacer,K as _Text,V as render,X as renderInline};