@visulima/tui 1.0.0-alpha.24 → 1.0.0-alpha.25

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## @visulima/tui [1.0.0-alpha.25](https://github.com/visulima/visulima/compare/@visulima/tui@1.0.0-alpha.24...@visulima/tui@1.0.0-alpha.25) (2026-06-15)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **tui:** clear terminal on windows fullscreen redraws ([879e83e](https://github.com/visulima/visulima/commit/879e83e45a4b195b3956cfa37f13a8914be3c527))
6
+
1
7
  ## @visulima/tui [1.0.0-alpha.24](https://github.com/visulima/visulima/compare/@visulima/tui@1.0.0-alpha.23...@visulima/tui@1.0.0-alpha.24) (2026-06-13)
2
8
 
3
9
  ### Bug Fixes
@@ -1,2 +1,2 @@
1
- import{createRequire as $}from"node:module";import{useRef as L,useEffectEvent as _,useEffect as g}from"react";import{IMECompositionBuffer as S,isIMEInput as q}from"../../packem_shared/IMECompositionBuffer-VhC9HRCv.js";import{kittyModifiers as p}from"../../packem_shared/kittyFlags-g8ALyoCU.js";import{j as w}from"../../packem_shared/reconciler-DhUGYWCr.js";import{useStdinContext as I}from"./use-stdin.js";const C=$(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,P=e=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[a,n]=m.versions.node.split(".").map(Number);if(a>22||a===22&&n>=3||a===20&&n>=16)return m.getBuiltinModule(e)}return C(e)},{Buffer:E}=P("node:buffer"),j=/^\u001B([a-z0-9])$/i,N=/^\u001B+([ON[]|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/,y={"[1~":"home","[2$":"insert","[2^":"insert","[2~":"insert","[3$":"delete","[3^":"delete","[3~":"delete","[4~":"end","[5$":"pageup","[5^":"pageup","[5~":"pageup","[6$":"pagedown","[6^":"pagedown","[6~":"pagedown","[7$":"home","[7^":"home","[7~":"home","[8$":"end","[8^":"end","[8~":"end","[11~":"f1","[12~":"f2","[13~":"f3","[14~":"f4","[15~":"f5","[17~":"f6","[18~":"f7","[19~":"f8","[20~":"f9","[21~":"f10","[23~":"f11","[24~":"f12","[[5~":"pageup","[[6~":"pagedown","[[A":"f1","[[B":"f2","[[C":"f3","[[D":"f4","[[E":"f5","[A":"up","[a":"up","[B":"down","[b":"down","[C":"right","[c":"right","[D":"left","[d":"left","[E":"clear","[e":"clear","[F":"end","[H":"home","[P":"f1","[Q":"f2","[R":"f3","[S":"f4","[Z":"tab",OA:"up",Oa:"up",OB:"down",Ob:"down",OC:"right",Oc:"right",OD:"left",Od:"left",OE:"clear",Oe:"clear",OF:"end",OH:"home",OP:"f1",OQ:"f2",OR:"f3",OS:"f4"},M=[...Object.values(y),"backspace"],T=e=>["[2$","[3$","[5$","[6$","[7$","[8$","[a","[b","[c","[d","[e","[Z"].includes(e),K=e=>["[2^","[3^","[5^","[6^","[7^","[8^","Oa","Ob","Oc","Od","Oe"].includes(e),B=/^\u001B\[(\d+)(?:;(\d+)(?::(\d+))?(?:;([\d:]+))?)?u$/,R=/^\u001B\[(\d+);(\d+):(\d+)([A-Z~])$/i,Z={A:"up",B:"down",C:"right",D:"left",E:"clear",F:"end",H:"home",P:"f1",Q:"f2",R:"f3",S:"f4"},D={2:"insert",3:"delete",5:"pageup",6:"pagedown",7:"home",8:"end",11:"f1",12:"f2",13:"f3",14:"f4",15:"f5",17:"f6",18:"f7",19:"f8",20:"f9",21:"f10",23:"f11",24:"f12"},v={8:"backspace",9:"tab",27:"escape",127:"backspace",57358:"capslock",57359:"scrolllock",57360:"numlock",57361:"printscreen",57362:"pause",57363:"menu",57376:"f13",57377:"f14",57378:"f15",57379:"f16",57380:"f17",57381:"f18",57382:"f19",57383:"f20",57384:"f21",57385:"f22",57386:"f23",57387:"f24",57388:"f25",57389:"f26",57390:"f27",57391:"f28",57392:"f29",57393:"f30",57394:"f31",57395:"f32",57396:"f33",57397:"f34",57398:"f35",57399:"kp0",57400:"kp1",57401:"kp2",57402:"kp3",57403:"kp4",57404:"kp5",57405:"kp6",57406:"kp7",57407:"kp8",57408:"kp9",57409:"kpdecimal",57410:"kpdivide",57411:"kpmultiply",57412:"kpsubtract",57413:"kpadd",57414:"kpenter",57415:"kpequal",57416:"kpseparator",57417:"kpleft",57418:"kpright",57419:"kpup",57420:"kpdown",57421:"kppageup",57422:"kppagedown",57423:"kphome",57424:"kpend",57425:"kpinsert",57426:"kpdelete",57427:"kpbegin",57428:"mediaplay",57429:"mediapause",57430:"mediaplaypause",57431:"mediareverse",57432:"mediastop",57433:"mediafastforward",57434:"mediarewind",57435:"mediatracknext",57436:"mediatrackprevious",57437:"mediarecord",57438:"lowervolume",57439:"raisevolume",57440:"mutevolume",57441:"leftshift",57442:"leftcontrol",57443:"leftalt",57444:"leftsuper",57445:"lefthyper",57446:"leftmeta",57447:"rightshift",57448:"rightcontrol",57449:"rightalt",57450:"rightsuper",57451:"righthyper",57452:"rightmeta",57453:"isoLevel3Shift",57454:"isoLevel5Shift"},x=e=>e>=0&&e<=1114111&&!(e>=55296&&e<=57343),b=e=>x(e)?String.fromCodePoint(e):"?";function A(e){return e===3?"release":e===2?"repeat":"press"}function O(e){return{capsLock:!!(e&p.capsLock),ctrl:!!(e&p.ctrl),hyper:!!(e&p.hyper),meta:!!(e&p.meta),numLock:!!(e&p.numLock),option:!!(e&p.alt),shift:!!(e&p.shift),super:!!(e&p.super)}}const F=e=>{const a=B.exec(e);if(!a)return null;const n=Number.parseInt(a[1],10),c=a[2]?Math.max(0,Number.parseInt(a[2],10)-1):0,t=a[3]?Number.parseInt(a[3],10):1,l=a[4];if(!x(n))return null;let s;l&&(s=l.split(":").map(d=>b(Number.parseInt(d,10))).join(""));let o,i;return n===32?(o="space",i=!0):n===13?(o="return",i=!0):v[n]?(o=v[n],i=!1):n>=1&&n<=26?(o=String.fromCodePoint(n+96),i=!1):(o=b(n).toLowerCase(),i=!0),i&&!s&&(s=b(n)),{name:o,...O(c),eventType:A(t),isKittyProtocol:!0,isPrintable:i,raw:e,sequence:e,text:s}},U=e=>{const a=R.exec(e);if(!a)return null;const n=Number.parseInt(a[1],10),c=Math.max(0,Number.parseInt(a[2],10)-1),t=Number.parseInt(a[3],10),l=a[4],s=l==="~"?D[n]:Z[l];return s?{name:s,...O(c),eventType:A(t),isKittyProtocol:!0,isPrintable:!1,raw:e,sequence:e}:null},z=(e="")=>{let a;E.isBuffer(e)?e[0]>127&&e[1]===void 0?(e[0]-=128,e=`\x1B${String(e)}`):e=String(e):e!==void 0&&typeof e!="string"?e=String(e):e||(e="");const n=F(e);if(n)return n;const c=U(e);if(c)return c;if(B.test(e))return{ctrl:!1,isKittyProtocol:!0,isPrintable:!1,meta:!1,name:"",option:!1,raw:e,sequence:e,shift:!1};const t={ctrl:!1,meta:!1,name:"",option:!1,raw:e,sequence:e,shift:!1};switch(t.sequence=t.sequence||e||t.name,e){case"\r":case"\x1B\r":{t.raw=void 0,t.name="return",t.option=e.length===2;break}case`
1
+ import{createRequire as $}from"node:module";import{useRef as L,useEffectEvent as _,useEffect as g}from"react";import{IMECompositionBuffer as S,isIMEInput as q}from"../../packem_shared/IMECompositionBuffer-VhC9HRCv.js";import{kittyModifiers as p}from"../../packem_shared/kittyFlags-g8ALyoCU.js";import{j as w}from"../../packem_shared/reconciler-CFyBVf7l.js";import{useStdinContext as I}from"./use-stdin.js";const C=$(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,P=e=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[a,n]=m.versions.node.split(".").map(Number);if(a>22||a===22&&n>=3||a===20&&n>=16)return m.getBuiltinModule(e)}return C(e)},{Buffer:E}=P("node:buffer"),j=/^\u001B([a-z0-9])$/i,N=/^\u001B+([ON[]|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/,y={"[1~":"home","[2$":"insert","[2^":"insert","[2~":"insert","[3$":"delete","[3^":"delete","[3~":"delete","[4~":"end","[5$":"pageup","[5^":"pageup","[5~":"pageup","[6$":"pagedown","[6^":"pagedown","[6~":"pagedown","[7$":"home","[7^":"home","[7~":"home","[8$":"end","[8^":"end","[8~":"end","[11~":"f1","[12~":"f2","[13~":"f3","[14~":"f4","[15~":"f5","[17~":"f6","[18~":"f7","[19~":"f8","[20~":"f9","[21~":"f10","[23~":"f11","[24~":"f12","[[5~":"pageup","[[6~":"pagedown","[[A":"f1","[[B":"f2","[[C":"f3","[[D":"f4","[[E":"f5","[A":"up","[a":"up","[B":"down","[b":"down","[C":"right","[c":"right","[D":"left","[d":"left","[E":"clear","[e":"clear","[F":"end","[H":"home","[P":"f1","[Q":"f2","[R":"f3","[S":"f4","[Z":"tab",OA:"up",Oa:"up",OB:"down",Ob:"down",OC:"right",Oc:"right",OD:"left",Od:"left",OE:"clear",Oe:"clear",OF:"end",OH:"home",OP:"f1",OQ:"f2",OR:"f3",OS:"f4"},M=[...Object.values(y),"backspace"],T=e=>["[2$","[3$","[5$","[6$","[7$","[8$","[a","[b","[c","[d","[e","[Z"].includes(e),K=e=>["[2^","[3^","[5^","[6^","[7^","[8^","Oa","Ob","Oc","Od","Oe"].includes(e),B=/^\u001B\[(\d+)(?:;(\d+)(?::(\d+))?(?:;([\d:]+))?)?u$/,R=/^\u001B\[(\d+);(\d+):(\d+)([A-Z~])$/i,Z={A:"up",B:"down",C:"right",D:"left",E:"clear",F:"end",H:"home",P:"f1",Q:"f2",R:"f3",S:"f4"},D={2:"insert",3:"delete",5:"pageup",6:"pagedown",7:"home",8:"end",11:"f1",12:"f2",13:"f3",14:"f4",15:"f5",17:"f6",18:"f7",19:"f8",20:"f9",21:"f10",23:"f11",24:"f12"},v={8:"backspace",9:"tab",27:"escape",127:"backspace",57358:"capslock",57359:"scrolllock",57360:"numlock",57361:"printscreen",57362:"pause",57363:"menu",57376:"f13",57377:"f14",57378:"f15",57379:"f16",57380:"f17",57381:"f18",57382:"f19",57383:"f20",57384:"f21",57385:"f22",57386:"f23",57387:"f24",57388:"f25",57389:"f26",57390:"f27",57391:"f28",57392:"f29",57393:"f30",57394:"f31",57395:"f32",57396:"f33",57397:"f34",57398:"f35",57399:"kp0",57400:"kp1",57401:"kp2",57402:"kp3",57403:"kp4",57404:"kp5",57405:"kp6",57406:"kp7",57407:"kp8",57408:"kp9",57409:"kpdecimal",57410:"kpdivide",57411:"kpmultiply",57412:"kpsubtract",57413:"kpadd",57414:"kpenter",57415:"kpequal",57416:"kpseparator",57417:"kpleft",57418:"kpright",57419:"kpup",57420:"kpdown",57421:"kppageup",57422:"kppagedown",57423:"kphome",57424:"kpend",57425:"kpinsert",57426:"kpdelete",57427:"kpbegin",57428:"mediaplay",57429:"mediapause",57430:"mediaplaypause",57431:"mediareverse",57432:"mediastop",57433:"mediafastforward",57434:"mediarewind",57435:"mediatracknext",57436:"mediatrackprevious",57437:"mediarecord",57438:"lowervolume",57439:"raisevolume",57440:"mutevolume",57441:"leftshift",57442:"leftcontrol",57443:"leftalt",57444:"leftsuper",57445:"lefthyper",57446:"leftmeta",57447:"rightshift",57448:"rightcontrol",57449:"rightalt",57450:"rightsuper",57451:"righthyper",57452:"rightmeta",57453:"isoLevel3Shift",57454:"isoLevel5Shift"},x=e=>e>=0&&e<=1114111&&!(e>=55296&&e<=57343),b=e=>x(e)?String.fromCodePoint(e):"?";function A(e){return e===3?"release":e===2?"repeat":"press"}function O(e){return{capsLock:!!(e&p.capsLock),ctrl:!!(e&p.ctrl),hyper:!!(e&p.hyper),meta:!!(e&p.meta),numLock:!!(e&p.numLock),option:!!(e&p.alt),shift:!!(e&p.shift),super:!!(e&p.super)}}const F=e=>{const a=B.exec(e);if(!a)return null;const n=Number.parseInt(a[1],10),c=a[2]?Math.max(0,Number.parseInt(a[2],10)-1):0,t=a[3]?Number.parseInt(a[3],10):1,l=a[4];if(!x(n))return null;let s;l&&(s=l.split(":").map(d=>b(Number.parseInt(d,10))).join(""));let o,i;return n===32?(o="space",i=!0):n===13?(o="return",i=!0):v[n]?(o=v[n],i=!1):n>=1&&n<=26?(o=String.fromCodePoint(n+96),i=!1):(o=b(n).toLowerCase(),i=!0),i&&!s&&(s=b(n)),{name:o,...O(c),eventType:A(t),isKittyProtocol:!0,isPrintable:i,raw:e,sequence:e,text:s}},U=e=>{const a=R.exec(e);if(!a)return null;const n=Number.parseInt(a[1],10),c=Math.max(0,Number.parseInt(a[2],10)-1),t=Number.parseInt(a[3],10),l=a[4],s=l==="~"?D[n]:Z[l];return s?{name:s,...O(c),eventType:A(t),isKittyProtocol:!0,isPrintable:!1,raw:e,sequence:e}:null},z=(e="")=>{let a;E.isBuffer(e)?e[0]>127&&e[1]===void 0?(e[0]-=128,e=`\x1B${String(e)}`):e=String(e):e!==void 0&&typeof e!="string"?e=String(e):e||(e="");const n=F(e);if(n)return n;const c=U(e);if(c)return c;if(B.test(e))return{ctrl:!1,isKittyProtocol:!0,isPrintable:!1,meta:!1,name:"",option:!1,raw:e,sequence:e,shift:!1};const t={ctrl:!1,meta:!1,name:"",option:!1,raw:e,sequence:e,shift:!1};switch(t.sequence=t.sequence||e||t.name,e){case"\r":case"\x1B\r":{t.raw=void 0,t.name="return",t.option=e.length===2;break}case`
2
2
  `:{t.name="enter";break}case" ":{t.name="tab";break}case" ":case"\x1B ":{t.name="space",t.meta=e.length===2;break}case"\b":case"\x1B\b":{t.name="backspace",t.meta=e.charAt(0)==="\x1B";break}case"\x1B":case"\x1B\x1B":{t.name="escape",t.meta=e.length===2;break}case"\x1B":case"":{t.name="backspace",t.meta=e.charAt(0)==="\x1B";break}default:if(e.length===1&&e<="")t.name=String.fromCharCode(e.charCodeAt(0)+97-1),t.ctrl=!0;else if(e.length===1&&e>="0"&&e<="9")t.name="number";else if(e.length===1&&e>="a"&&e<="z")t.name=e;else if(e.length===1&&e>="A"&&e<="Z")t.name=e.toLowerCase(),t.shift=!0;else if(a=j.exec(e))t.meta=!0,t.shift=/^[A-Z]$/.test(a[1]);else if(a=N.exec(e)){const l=[...e];l[0]==="\x1B"&&l[1]==="\x1B"&&(t.option=!0);const s=[a[1],a[2],a[4],a[6]].filter(Boolean).join(""),o=(a[3]||a[5]||1)-1;t.ctrl=!!(o&4),t.meta=!!(o&10),t.shift=!!(o&1),t.code=s,t.name=y[s]??"",t.shift=T(s)||t.shift,t.ctrl=K(s)||t.ctrl}}return t},X=(e,a={})=>{const{internal_eventEmitter:n,internal_exitOnCtrlC:c,setRawMode:t,stdin:l}=I(),s=a.imeEnabled??!0,o=a.imeTimeout??50,i=L(void 0),d=_(e);g(()=>{if(s)return i.current=new S({onFlush:h=>{const u={backspace:!1,capsLock:!1,ctrl:!1,delete:!1,downArrow:!1,end:!1,escape:!1,home:!1,hyper:!1,leftArrow:!1,meta:!1,numLock:!1,pageDown:!1,pageUp:!1,return:!1,rightArrow:!1,shift:!1,super:!1,tab:!1,upArrow:!1};w.discreteUpdates(()=>{d(h,u)})},timeout:o}),()=>{i.current?.destroy(),i.current=void 0}},[s,o]),g(()=>{if(a.isActive!==!1)return t(!0),()=>{t(!1)}},[a.isActive,t]),g(()=>{if(a.isActive===!1)return;const h=u=>{if(s&&q(u)){i.current?.add(u);return}i.current?.flush();const r=z(u),k={backspace:r.name==="backspace",capsLock:r.capsLock??!1,ctrl:r.ctrl,delete:r.name==="delete",downArrow:r.name==="down",end:r.name==="end",escape:r.name==="escape",eventType:r.eventType,home:r.name==="home",hyper:r.hyper??!1,leftArrow:r.name==="left",meta:r.meta||r.option,numLock:r.numLock??!1,pageDown:r.name==="pagedown",pageUp:r.name==="pageup",return:r.name==="return",rightArrow:r.name==="right",shift:r.shift,super:r.super??!1,tab:r.name==="tab",upArrow:r.name==="up"};let f;r.isKittyProtocol?r.isPrintable?f=r.text??r.name:r.ctrl&&r.name.length===1?f=r.name:f="":r.ctrl?f=r.name:f=r.sequence,!r.isKittyProtocol&&M.includes(r.name)&&(f=""),f.startsWith("\x1B")&&(f=f.slice(1)),f.length===1&&typeof f[0]=="string"&&/[A-Z]/.test(f[0])&&(k.shift=!0),!(f==="c"&&k.ctrl&&c)&&(!r.name&&f===""||w.discreteUpdates(()=>{d(f,k)}))};return n.on("input",h),()=>{n.removeListener("input",h)}},[a.isActive,l,c,s])};export{X as default,X as useInput};
@@ -1 +1 @@
1
- import{useEffectEvent as c,useEffect as a}from"react";import{j as u}from"../../packem_shared/reconciler-DhUGYWCr.js";import{useStdinContext as m}from"./use-stdin.js";const l=(o,e={})=>{const{internal_eventEmitter:t,setBracketedPasteMode:s,setRawMode:r}=m(),f=c(o);a(()=>{if(e.isActive!==!1)return r(!0),s(!0),()=>{r(!1),s(!1)}},[e.isActive,r,s]),a(()=>{if(e.isActive===!1)return;const i=n=>{u.discreteUpdates(()=>{f(n)})};return t.on("paste",i),()=>{t.removeListener("paste",i)}},[e.isActive,t])};export{l as default,l as usePaste};
1
+ import{useEffectEvent as c,useEffect as a}from"react";import{j as u}from"../../packem_shared/reconciler-CFyBVf7l.js";import{useStdinContext as m}from"./use-stdin.js";const l=(o,e={})=>{const{internal_eventEmitter:t,setBracketedPasteMode:s,setRawMode:r}=m(),f=c(o);a(()=>{if(e.isActive!==!1)return r(!0),s(!0),()=>{r(!1),s(!1)}},[e.isActive,r,s]),a(()=>{if(e.isActive===!1)return;const i=n=>{u.discreteUpdates(()=>{f(n)})};return t.on("paste",i),()=>{t.removeListener("paste",i)}},[e.isActive,t])};export{l as default,l as usePaste};
@@ -1,2 +1,2 @@
1
- import{createRequire as g}from"node:module";import{useRef as m,useState as N,useEffect as b,useCallback as E}from"react";const S=g(import.meta.url),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,l=e=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[r,s]=a.versions.node.split(".").map(Number);if(r>22||r===22&&s>=3||r===20&&s>=16)return a.getBuiltinModule(e)}return S(e)},{mkdirSync:v,writeFileSync:h,renameSync:_,readFileSync:w}=l("node:fs"),{homedir:j}=l("node:os"),f=l("node:path"),p=a,q=()=>{const e=new Map;return{read:r=>e.get(r),write:(r,s)=>{e.set(r,s)}}},O=/[/\\]/,$=e=>{if(e===""||e==="."||e===".."||O.test(e)||e.includes("\0"))throw new Error(`[visulima/tui] usePersistentState: invalid namespace ${JSON.stringify(e)} — must not be empty or contain path separators.`)},k=e=>{$(e);const r=f.join(j(),".cache","visulima-tui",`${e}.json`);let s;const i=(t,n)=>{const o=n instanceof Error?n.message:String(n);p.stderr.write(`[visulima/tui] persistent-state ${t} failed: ${o}
2
- `)},c=()=>{if(s!==void 0)return s;try{const t=w(r,"utf8"),n=JSON.parse(t);s=n&&typeof n=="object"?n:{}}catch(t){const n=t?.code;n!=="ENOENT"&&n!=="EACCES"&&i("read",t),s={}}return s};return{read:t=>c()[t],write:(t,n)=>{const o=f.dirname(r),u=`${r}.tmp.${p.pid}`,d=c();d[t]=n;try{v(o,{recursive:!0}),h(u,JSON.stringify(d,null,2),{encoding:"utf8",flag:"w"}),_(u,r)}catch(y){i("write",y)}}}},J=(e,r,s)=>{const i=e.read(r);if(i===void 0)return s;try{return JSON.parse(i)}catch{return s}},C=(e,r,s)=>{const i=m(void 0);i.current??=s?.storage??k(s?.namespace??"tui");const c=i.current,[t,n]=N(()=>J(c,e,r)),o=m(void 0);o.current??={key:e,value:t},b(()=>{if(!(o.current?.key===e&&Object.is(o.current.value,t)))try{c.write(e,JSON.stringify(t)),o.current={key:e,value:t}}catch{}},[e,t,c]);const u=E(d=>{n(d)},[]);return[t,u]};export{k as createFileStorage,q as createMemoryStorage,C as default,C as usePersistentState};
1
+ import{createRequire as g}from"node:module";import{useRef as m,useState as N,useEffect as b,useCallback as E}from"react";const S=g(import.meta.url),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,l=e=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[r,s]=a.versions.node.split(".").map(Number);if(r>22||r===22&&s>=3||r===20&&s>=16)return a.getBuiltinModule(e)}return S(e)},{mkdirSync:v,writeFileSync:h,renameSync:_,readFileSync:w}=l("node:fs"),{homedir:j}=l("node:os"),f=l("node:path"),p=a,q=()=>{const e=new Map;return{read:r=>e.get(r),write:(r,s)=>{e.set(r,s)}}},O=/[/\\]/,k=e=>{if(e===""||e==="."||e===".."||O.test(e)||e.includes("\0"))throw new Error(`[visulima/tui] usePersistentState: invalid namespace ${JSON.stringify(e)} — must not be empty or contain path separators.`)},J=e=>{k(e);const r=f.join(j(),".cache","visulima-tui",`${e}.json`);let s;const i=(t,n)=>{const o=n instanceof Error?n.message:String(n);p.stderr.write(`[visulima/tui] persistent-state ${t} failed: ${o}
2
+ `)},c=()=>{if(s!==void 0)return s;try{const t=w(r,"utf8"),n=JSON.parse(t);s=n&&typeof n=="object"?n:{}}catch(t){const n=t?.code;n!=="ENOENT"&&n!=="EACCES"&&i("read",t),s={}}return s};return{read:t=>c()[t],write:(t,n)=>{const o=f.dirname(r),u=`${r}.tmp.${p.pid}`,d=c();d[t]=n;try{v(o,{recursive:!0}),h(u,JSON.stringify(d,null,2),{encoding:"utf8",flag:"w"}),_(u,r)}catch(y){i("write",y)}}}},M=(e,r,s)=>{const i=e.read(r);if(i===void 0)return s;try{return JSON.parse(i)}catch{return s}},C=(e,r,s)=>{const i=m(void 0);i.current??=s?.storage??J(s?.namespace??"tui");const c=i.current,[t,n]=N(()=>M(c,e,r)),o=m(void 0);o.current??={key:e,value:t},b(()=>{if(!(o.current?.key===e&&Object.is(o.current.value,t)))try{c.write(e,JSON.stringify(t)),o.current={key:e,value:t}}catch{}},[e,t,c]);const u=E(d=>{n(d)},[]);return[t,u]};export{J as createFileStorage,q as createMemoryStorage,C as default,C as usePersistentState};
package/dist/ink/index.js CHANGED
@@ -1 +1 @@
1
- import{clearOsc52 as o,isOsc52Supported as r,writeOsc52 as a}from"../packem_shared/clearOsc52-BUpnQOav.js";import{COLOR_BLINDNESS_COMPENSATION as l,COLOR_BLINDNESS_SIMULATION as i,IDENTITY_MATRIX as n,applyColorMatrix as u,hexToRgb as f,rgbToHex as p,transformHexColor as c}from"../packem_shared/COLOR_BLINDNESS_COMPENSATION-Ilnoyeqc.js";import{g as m,i as x}from"../packem_shared/dom-rphpG0kf.js";import{IMECompositionBuffer as S,isIMEInput as h}from"../packem_shared/IMECompositionBuffer-VhC9HRCv.js";import{kittyFlags as M,kittyModifiers as O}from"../packem_shared/kittyFlags-g8ALyoCU.js";import{c as I,a as L,b,g as C,d as E,e as R,f as N,h as B,i as P,j as H,k as v,l as W,R as k,p as A}from"../packem_shared/measure-element-Cs7_proT.js";import{c as D,a as F,i as z,s as q,b as w,t as j}from"../packem_shared/measure-text-B7juNq4Y.js";import{default as U}from"../packem_shared/render-v2x7ZRzT.js";import{default as X}from"../packem_shared/renderToString-C2YmVNLG.js";import{default as G,ResizeObserverEntry as J}from"../packem_shared/ResizeObserver-aX8XOr2u.js";import{calculateScroll as Z,getScrollHeight as $,getScrollLeft as ee,getScrollTop as te,getScrollWidth as oe}from"../packem_shared/calculateScroll-D4Y_JR4H.js";import{Range as ae,Selection as se,applySelectionToStyledLine as le,comparePoints as ie}from"../packem_shared/Range-BsVYNWtg.js";import{squashTextNodesWithMap as ue}from"../packem_shared/squashTextNodesWithMap-BmUSBPfc.js";import{isTerminalPaletteQuerySupported as pe,queryTerminalPalette as ce}from"../packem_shared/isTerminalPaletteQuerySupported-BYzmqq9-.js";import{wrapOrTruncateStyledLine as me}from"../packem_shared/wrapOrTruncateStyledLine-46W8bTtv.js";import{default as ge}from"../packem_shared/Fullscreen-BRhuBLBh.js";import{default as he}from"../packem_shared/MouseProvider-DUqQ3Eaa.js";import{default as Me}from"../packem_shared/isIntersecting-Bo2npvMR.js";import{default as ye}from"./mouse/use-mouse-action.js";import{default as Le}from"./mouse/use-mouse.js";import{default as Ce}from"./mouse/use-mouse-position.js";import{default as Re}from"./mouse/use-on-mouse-hover.js";import{default as Be}from"./mouse/use-on-mouse-state.js";import{d as He}from"../packem_shared/ansi-parser-DlgLtOYO.js";import{useElementDimensions as We,useElementPosition as ke}from"./mouse/use-element-position.js";import{useOnMouseClick as _e}from"./mouse/use-on-mouse-click.js";export{l as COLOR_BLINDNESS_COMPENSATION,i as COLOR_BLINDNESS_SIMULATION,ge as Fullscreen,n as IDENTITY_MATRIX,S as IMECompositionBuffer,he as MouseProvider,ae as Range,G as ResizeObserver,J as ResizeObserverEntry,se as Selection,u as applyColorMatrix,le as applySelectionToStyledLine,Z as calculateScroll,I as calculateScrollbarLayout,L as calculateScrollbarThumb,o as clearOsc52,D as clearStringWidthCache,F as clearStyledLineCache,b as collectSortedFragments,ie as comparePoints,C as getAddedScrollHeight,E as getBoundingBox,R as getHorizontalScrollbarBoundingBox,N as getInnerHeight,B as getInnerWidth,m as getPathToRoot,P as getRelativeLeft,H as getRelativeTop,$ as getScrollHeight,ee as getScrollLeft,te as getScrollTop,oe as getScrollWidth,v as getText,W as getVerticalScrollbarBoundingBox,f as hexToRgb,z as inkCharacterWidth,h as isIMEInput,Me as isIntersecting,x as isNodeSelectable,r as isOsc52Supported,pe as isTerminalPaletteQuerySupported,M as kittyFlags,O as kittyModifiers,k as measureElement,He as parseSgrMouse,A as processLayout,ce as queryTerminalPalette,U as render,X as renderToString,p as rgbToHex,q as setEnableStyledLineCache,w as setStringWidthFunction,ue as squashTextNodesWithMap,j as toStyledLine,c as transformHexColor,We as useElementDimensions,ke as useElementPosition,ye as useMouseAction,Le as useMouseContext,Ce as useMousePosition,_e as useOnMouseClick,Re as useOnMouseHover,Be as useOnMouseState,me as wrapOrTruncateStyledLine,a as writeOsc52};
1
+ import{clearOsc52 as o,isOsc52Supported as r,writeOsc52 as a}from"../packem_shared/clearOsc52-BUpnQOav.js";import{COLOR_BLINDNESS_COMPENSATION as l,COLOR_BLINDNESS_SIMULATION as i,IDENTITY_MATRIX as n,applyColorMatrix as u,hexToRgb as f,rgbToHex as p,transformHexColor as c}from"../packem_shared/COLOR_BLINDNESS_COMPENSATION-Ilnoyeqc.js";import{g as m,i as x}from"../packem_shared/dom-rphpG0kf.js";import{IMECompositionBuffer as S,isIMEInput as h}from"../packem_shared/IMECompositionBuffer-VhC9HRCv.js";import{kittyFlags as M,kittyModifiers as O}from"../packem_shared/kittyFlags-g8ALyoCU.js";import{c as I,a as L,b,g as C,d as E,e as R,f as N,h as B,i as P,j as H,k as v,l as W,R as k,p as A}from"../packem_shared/measure-element-Cs7_proT.js";import{c as D,a as F,i as z,s as q,b as w,t as j}from"../packem_shared/measure-text-B7juNq4Y.js";import{default as U}from"../packem_shared/render-DSuj2PjD.js";import{default as X}from"../packem_shared/renderToString-Do8K5Fyk.js";import{default as G,ResizeObserverEntry as J}from"../packem_shared/ResizeObserver-aX8XOr2u.js";import{calculateScroll as Z,getScrollHeight as $,getScrollLeft as ee,getScrollTop as te,getScrollWidth as oe}from"../packem_shared/calculateScroll-D4Y_JR4H.js";import{Range as ae,Selection as se,applySelectionToStyledLine as le,comparePoints as ie}from"../packem_shared/Range-BsVYNWtg.js";import{squashTextNodesWithMap as ue}from"../packem_shared/squashTextNodesWithMap-BmUSBPfc.js";import{isTerminalPaletteQuerySupported as pe,queryTerminalPalette as ce}from"../packem_shared/isTerminalPaletteQuerySupported-BYzmqq9-.js";import{wrapOrTruncateStyledLine as me}from"../packem_shared/wrapOrTruncateStyledLine-46W8bTtv.js";import{default as ge}from"../packem_shared/Fullscreen-BRhuBLBh.js";import{default as he}from"../packem_shared/MouseProvider-DUqQ3Eaa.js";import{default as Me}from"../packem_shared/isIntersecting-Bo2npvMR.js";import{default as ye}from"./mouse/use-mouse-action.js";import{default as Le}from"./mouse/use-mouse.js";import{default as Ce}from"./mouse/use-mouse-position.js";import{default as Re}from"./mouse/use-on-mouse-hover.js";import{default as Be}from"./mouse/use-on-mouse-state.js";import{d as He}from"../packem_shared/ansi-parser-DlgLtOYO.js";import{useElementDimensions as We,useElementPosition as ke}from"./mouse/use-element-position.js";import{useOnMouseClick as _e}from"./mouse/use-on-mouse-click.js";export{l as COLOR_BLINDNESS_COMPENSATION,i as COLOR_BLINDNESS_SIMULATION,ge as Fullscreen,n as IDENTITY_MATRIX,S as IMECompositionBuffer,he as MouseProvider,ae as Range,G as ResizeObserver,J as ResizeObserverEntry,se as Selection,u as applyColorMatrix,le as applySelectionToStyledLine,Z as calculateScroll,I as calculateScrollbarLayout,L as calculateScrollbarThumb,o as clearOsc52,D as clearStringWidthCache,F as clearStyledLineCache,b as collectSortedFragments,ie as comparePoints,C as getAddedScrollHeight,E as getBoundingBox,R as getHorizontalScrollbarBoundingBox,N as getInnerHeight,B as getInnerWidth,m as getPathToRoot,P as getRelativeLeft,H as getRelativeTop,$ as getScrollHeight,ee as getScrollLeft,te as getScrollTop,oe as getScrollWidth,v as getText,W as getVerticalScrollbarBoundingBox,f as hexToRgb,z as inkCharacterWidth,h as isIMEInput,Me as isIntersecting,x as isNodeSelectable,r as isOsc52Supported,pe as isTerminalPaletteQuerySupported,M as kittyFlags,O as kittyModifiers,k as measureElement,He as parseSgrMouse,A as processLayout,ce as queryTerminalPalette,U as render,X as renderToString,p as rgbToHex,q as setEnableStyledLineCache,w as setStringWidthFunction,ue as squashTextNodesWithMap,j as toStyledLine,c as transformHexColor,We as useElementDimensions,ke as useElementPosition,ye as useMouseAction,Le as useMouseContext,Ce as useMousePosition,_e as useOnMouseClick,Re as useOnMouseHover,Be as useOnMouseState,me as wrapOrTruncateStyledLine,a as writeOsc52};
@@ -1 +1 @@
1
- import{createRequire as x}from"node:module";import{version as L,createContext as R}from"react";import b from"react-reconciler";import{NoEventPriority as A,DefaultEventPriority as P}from"react-reconciler/constants.js";import{unstable_shouldYield as D,unstable_scheduleCallback as O,unstable_now as G,unstable_cancelCallback as F}from"scheduler";import n from"yoga-layout";import{b as _,d as f,s as m,m as p,e as v,r as T,f as w,c as W,h,j as I}from"./dom-rphpG0kf.js";const z=x(import.meta.url),S=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,y=S,k=[["top",n.EDGE_TOP],["right",n.EDGE_RIGHT],["bottom",n.EDGE_BOTTOM],["left",n.EDGE_LEFT]],B=(t,e)=>{if("position"in e){let r=n.POSITION_TYPE_RELATIVE;e.position==="absolute"?r=n.POSITION_TYPE_ABSOLUTE:e.position==="static"&&(r=n.POSITION_TYPE_STATIC),t.setPositionType(r)}for(const[r,s]of k){if(!(r in e))continue;const l=e[r];if(typeof l=="string"){t.setPositionPercent(s,Number.parseFloat(l));continue}t.setPosition(s,l)}},H=(t,e)=>{"margin"in e&&t.setMargin(n.EDGE_ALL,e.margin??0),"marginX"in e&&t.setMargin(n.EDGE_HORIZONTAL,e.marginX??0),"marginY"in e&&t.setMargin(n.EDGE_VERTICAL,e.marginY??0),"marginLeft"in e&&t.setMargin(n.EDGE_START,e.marginLeft||0),"marginRight"in e&&t.setMargin(n.EDGE_END,e.marginRight||0),"marginTop"in e&&t.setMargin(n.EDGE_TOP,e.marginTop||0),"marginBottom"in e&&t.setMargin(n.EDGE_BOTTOM,e.marginBottom||0)},M=(t,e)=>{"padding"in e&&t.setPadding(n.EDGE_ALL,e.padding??0),"paddingX"in e&&t.setPadding(n.EDGE_HORIZONTAL,e.paddingX??0),"paddingY"in e&&t.setPadding(n.EDGE_VERTICAL,e.paddingY??0),"paddingLeft"in e&&t.setPadding(n.EDGE_LEFT,e.paddingLeft||0),"paddingRight"in e&&t.setPadding(n.EDGE_RIGHT,e.paddingRight||0),"paddingTop"in e&&t.setPadding(n.EDGE_TOP,e.paddingTop||0),"paddingBottom"in e&&t.setPadding(n.EDGE_BOTTOM,e.paddingBottom||0)},U=(t,e)=>{"flexGrow"in e&&t.setFlexGrow(e.flexGrow??0),"flexShrink"in e&&t.setFlexShrink(typeof e.flexShrink=="number"?e.flexShrink:1),"flexWrap"in e&&(e.flexWrap==="nowrap"&&t.setFlexWrap(n.WRAP_NO_WRAP),e.flexWrap==="wrap"&&t.setFlexWrap(n.WRAP_WRAP),e.flexWrap==="wrap-reverse"&&t.setFlexWrap(n.WRAP_WRAP_REVERSE)),"flexDirection"in e&&(e.flexDirection==="row"&&t.setFlexDirection(n.FLEX_DIRECTION_ROW),e.flexDirection==="row-reverse"&&t.setFlexDirection(n.FLEX_DIRECTION_ROW_REVERSE),e.flexDirection==="column"&&t.setFlexDirection(n.FLEX_DIRECTION_COLUMN),e.flexDirection==="column-reverse"&&t.setFlexDirection(n.FLEX_DIRECTION_COLUMN_REVERSE)),"flexBasis"in e&&(typeof e.flexBasis=="number"?t.setFlexBasis(e.flexBasis):typeof e.flexBasis=="string"?t.setFlexBasisPercent(Number.parseInt(e.flexBasis,10)):t.setFlexBasis(Number.NaN)),"alignItems"in e&&((e.alignItems==="stretch"||!e.alignItems)&&t.setAlignItems(n.ALIGN_STRETCH),e.alignItems==="flex-start"&&t.setAlignItems(n.ALIGN_FLEX_START),e.alignItems==="center"&&t.setAlignItems(n.ALIGN_CENTER),e.alignItems==="flex-end"&&t.setAlignItems(n.ALIGN_FLEX_END),e.alignItems==="baseline"&&t.setAlignItems(n.ALIGN_BASELINE)),"alignSelf"in e&&((e.alignSelf==="auto"||!e.alignSelf)&&t.setAlignSelf(n.ALIGN_AUTO),e.alignSelf==="flex-start"&&t.setAlignSelf(n.ALIGN_FLEX_START),e.alignSelf==="center"&&t.setAlignSelf(n.ALIGN_CENTER),e.alignSelf==="flex-end"&&t.setAlignSelf(n.ALIGN_FLEX_END),e.alignSelf==="stretch"&&t.setAlignSelf(n.ALIGN_STRETCH),e.alignSelf==="baseline"&&t.setAlignSelf(n.ALIGN_BASELINE)),"alignContent"in e&&((e.alignContent==="flex-start"||!e.alignContent)&&t.setAlignContent(n.ALIGN_FLEX_START),e.alignContent==="center"&&t.setAlignContent(n.ALIGN_CENTER),e.alignContent==="flex-end"&&t.setAlignContent(n.ALIGN_FLEX_END),e.alignContent==="space-between"&&t.setAlignContent(n.ALIGN_SPACE_BETWEEN),e.alignContent==="space-around"&&t.setAlignContent(n.ALIGN_SPACE_AROUND),e.alignContent==="space-evenly"&&t.setAlignContent(n.ALIGN_SPACE_EVENLY),e.alignContent==="stretch"&&t.setAlignContent(n.ALIGN_STRETCH)),"justifyContent"in e&&((e.justifyContent==="flex-start"||!e.justifyContent)&&t.setJustifyContent(n.JUSTIFY_FLEX_START),e.justifyContent==="center"&&t.setJustifyContent(n.JUSTIFY_CENTER),e.justifyContent==="flex-end"&&t.setJustifyContent(n.JUSTIFY_FLEX_END),e.justifyContent==="space-between"&&t.setJustifyContent(n.JUSTIFY_SPACE_BETWEEN),e.justifyContent==="space-around"&&t.setJustifyContent(n.JUSTIFY_SPACE_AROUND),e.justifyContent==="space-evenly"&&t.setJustifyContent(n.JUSTIFY_SPACE_EVENLY))},Y=(t,e)=>{"width"in e&&(typeof e.width=="number"?t.setWidth(e.width):typeof e.width=="string"?t.setWidthPercent(Number.parseInt(e.width,10)):t.setWidthAuto()),"height"in e&&(typeof e.height=="number"?t.setHeight(e.height):typeof e.height=="string"?t.setHeightPercent(Number.parseInt(e.height,10)):t.setHeightAuto()),"minWidth"in e&&(typeof e.minWidth=="string"?t.setMinWidthPercent(Number.parseInt(e.minWidth,10)):t.setMinWidth(e.minWidth??0)),"minHeight"in e&&(typeof e.minHeight=="string"?t.setMinHeightPercent(Number.parseInt(e.minHeight,10)):t.setMinHeight(e.minHeight??0)),"maxWidth"in e&&(typeof e.maxWidth=="string"?t.setMaxWidthPercent(Number.parseInt(e.maxWidth,10)):t.setMaxWidth(e.maxWidth)),"maxHeight"in e&&(typeof e.maxHeight=="string"?t.setMaxHeightPercent(Number.parseInt(e.maxHeight,10)):t.setMaxHeight(e.maxHeight)),"aspectRatio"in e&&t.setAspectRatio(e.aspectRatio)},j=(t,e)=>{"display"in e&&t.setDisplay(e.display==="flex"?n.DISPLAY_FLEX:n.DISPLAY_NONE)},X=(t,e,r)=>{if(!("borderStyle"in e||"borderTop"in e||"borderBottom"in e||"borderLeft"in e||"borderRight"in e))return;const s=r.borderStyle?1:0;t.setBorder(n.EDGE_TOP,r.borderTop===!1?0:s),t.setBorder(n.EDGE_BOTTOM,r.borderBottom===!1?0:s),t.setBorder(n.EDGE_LEFT,r.borderLeft===!1?0:s),t.setBorder(n.EDGE_RIGHT,r.borderRight===!1?0:s)},V=(t,e)=>{"gap"in e&&t.setGap(n.GUTTER_ALL,e.gap??0),"columnGap"in e&&t.setGap(n.GUTTER_COLUMN,e.columnGap??0),"rowGap"in e&&t.setGap(n.GUTTER_ROW,e.rowGap??0)},J=(t,e)=>{const r=e.overflow??"visible",s=e.overflowX??r,l=e.overflowY??r;s==="scroll"||l==="scroll"?t.setOverflow(n.OVERFLOW_SCROLL):s==="hidden"||l==="hidden"?t.setOverflow(n.OVERFLOW_HIDDEN):t.setOverflow(n.OVERFLOW_VISIBLE)},C=(t,e={},r=e)=>{B(t,e),H(t,e),M(t,e),U(t,e),Y(t,e),j(t,e),X(t,e,r),V(t,e),J(t,r)};if(y.env.DEV==="true"){let t=!1;try{import.meta.resolve("react-devtools-core"),t=!0}catch{}t&&await import("../packem_chunks/devtools.js")}const N=(t,e)=>{if(t===e)return;if(!t)return e;const r={};let s=!1;for(const l of Object.keys(t))(!e||!Object.hasOwn(e,l))&&(r[l]=void 0,s=!0);if(e)for(const l of Object.keys(e))e[l]!==t[l]&&(r[l]=e[l],s=!0);return s?r:void 0},E=t=>{if(t){if(t.yogaNode?.unsetMeasureFunc(),"resizeObservers"in t&&t.resizeObservers?.clear(),"childNodes"in t&&t.childNodes)for(const e of t.childNodes)E(e);t.yogaNode?.free(),"cachedRender"in t&&(t.cachedRender=void 0),"childNodes"in t&&(t.childNodes=[]),t.parentNode=void 0}};let u=A,g;async function q(){const t=(await import("node:fs")).readFileSync(new URL("../package.json",import.meta.url),"utf8"),e=JSON.parse(t);return{name:e?.name,version:e?.version}}let d={name:"ink",version:L};if(y.env.DEV==="true")try{const t=await q();d={name:t.name||d.name,version:t.version||d.version}}catch(t){console.warn("Failed to load package.json in development mode. Falling back to default renderer metadata.",t)}const rt=b({afterActiveInstanceBlur(){},appendChild:f,appendChildToContainer:f,appendInitialChild:f,beforeActiveInstanceBlur(){},cancelCallback:F,cancelTimeout:clearTimeout,clearContainer:()=>!1,commitTextUpdate(t,e,r){m(t,r)},commitUpdate(t,e,r,s){g&&t.internal_static&&(g.isStaticDirty=!0);const l=N(r,s),a=N(r.style,s.style);if(!l&&!a)return;let i=!!a;if(l){for(const[o,c]of Object.entries(l))if(o!=="children"){if(o==="style"){h(t,c);continue}if(o==="internal_transform"){t.internal_transform=c,i=!0;continue}if(o==="internal_cursor"){t.internal_cursor=c,i=!0;continue}if(o==="internal_static"){t.internal_static=!0,i=!0;continue}if(o==="sticky"){t.internal_sticky=c,i=!0;continue}if(o==="internalStickyAlternate"){t.internal_stickyAlternate=c,i=!0;continue}if(o==="opaque"){t.internal_opaque=c,i=!0;continue}if(o==="scrollbar"){t.internal_scrollbar=c,i=!0;continue}if(o==="internal_terminalCursorFocus"){t.internal_terminalCursorFocus=c,i=!0;continue}if(o==="internal_terminalCursorPosition"){t.internal_terminalCursorPosition=c,i=!0;continue}if(o==="cachedRender"){t.cachedRender=c,i=!0;continue}I(t,o,c),i=!0}}a&&t.yogaNode&&C(t.yogaNode,a,s.style??{}),i&&p(t)},createInstance(t,e,r,s){if(s.isInsideText&&t==="ink-box")throw new Error("<Box> can’t be nested inside <Text> component");if(s.isInsideText&&t==="ink-cursor")throw new Error("<Cursor> can’t be nested inside <Text> component");const l=t==="ink-text"&&s.isInsideText?"ink-virtual-text":t,a=W(l);for(const[i,o]of Object.entries(e))if(i!=="children"){if(i==="style"){h(a,o),a.yogaNode&&C(a.yogaNode,o);continue}if(i==="internal_transform"){a.internal_transform=o;continue}if(i==="internal_cursor"){a.internal_cursor=o;continue}if(i==="internal_static"){g=r,a.internal_static=!0,r.isStaticDirty=!0,r.staticNode=a;continue}if(i==="sticky"){a.internal_sticky=o;continue}if(i==="internalStickyAlternate"){a.internal_stickyAlternate=o;continue}if(i==="opaque"){a.internal_opaque=o;continue}if(i==="scrollbar"){a.internal_scrollbar=o;continue}if(i==="internal_terminalCursorFocus"){a.internal_terminalCursorFocus=o;continue}if(i==="internal_terminalCursorPosition"){a.internal_terminalCursorPosition=o;continue}if(i==="internal_static"){a.internal_static=!0;continue}if(i==="cachedRender"){a.cachedRender=o;continue}I(a,i,o)}return a},createTextInstance(t,e,r){if(!r.isInsideText)throw new Error(`Text string "${t}" must be rendered inside <Text> component`);return w(t)},detachDeletedInstance(){},finalizeInitialChildren(){return!1},getChildHostContext(t,e){const r=t.isInsideText,s=e==="ink-text"||e==="ink-virtual-text";return r===s?t:{isInsideText:s}},getCurrentUpdatePriority:()=>u,getInstanceFromNode:()=>null,getInstanceFromScope:()=>null,getPublicInstance:t=>t,getRootHostContext:()=>({isInsideText:!1}),hideInstance(t){t.internal_hidden=!0,t.yogaNode?.setDisplay(n.DISPLAY_NONE),p(t)},hideTextInstance(t){m(t,"")},HostTransitionContext:R(null),insertBefore:_,insertInContainerBefore:_,isPrimaryRenderer:!0,maySuspendCommit(){return!0},noTimeout:-1,NotPendingTransition:void 0,now:G,preloadInstance(){return!0},prepareForCommit:()=>null,preparePortalMount:()=>null,prepareScopeUpdate(){},removeChild(t,e){T(t,e),E(e)},removeChildFromContainer(t,e){T(t,e),E(e)},rendererPackageName:d.name,rendererVersion:d.version,requestPostPaintCallback(){},resetAfterCommit(t){if(typeof t.onComputeLayout=="function"&&t.onComputeLayout(),v(t),t.staticNode!==t.previousStaticNode&&(t.previousStaticNode=t.staticNode,typeof t.onStaticChange=="function"&&t.onStaticChange()),t.isStaticDirty){t.isStaticDirty=!1,typeof t.onImmediateRender=="function"&&t.onImmediateRender();return}typeof t.onRender=="function"&&t.onRender()},resetFormInstance(){},resetTextContent(){},resolveEventTimeStamp(){return-1.1},resolveEventType(){return null},resolveUpdatePriority(){return u!==A?u:P},scheduleCallback:O,scheduleMicrotask:queueMicrotask,scheduleTimeout:setTimeout,setCurrentUpdatePriority(t){u=t},shouldAttemptEagerTransition(){return!1},shouldSetTextContent:()=>!1,shouldYield:D,startSuspendingCommit(){},supportsHydration:!1,supportsMicrotasks:!0,supportsMutation:!0,supportsPersistence:!1,suspendInstance(){},trackSchedulerEvent(){},unhideInstance(t){t.internal_hidden=!1,t.yogaNode?.setDisplay(n.DISPLAY_FLEX),p(t)},unhideTextInstance(t,e){m(t,e)},waitForCommitToBeReady(){return null}});export{C as c,rt as j};
1
+ import{createRequire as x}from"node:module";import{version as L,createContext as R}from"react";import b from"react-reconciler";import{NoEventPriority as A,DefaultEventPriority as P}from"react-reconciler/constants.js";import{unstable_shouldYield as D,unstable_scheduleCallback as O,unstable_now as G,unstable_cancelCallback as F}from"scheduler";import n from"yoga-layout";import{b as _,d as f,s as m,m as p,e as v,r as T,f as w,c as W,h,j as I}from"./dom-rphpG0kf.js";const $=x(import.meta.url),S=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,y=S,k=[["top",n.EDGE_TOP],["right",n.EDGE_RIGHT],["bottom",n.EDGE_BOTTOM],["left",n.EDGE_LEFT]],B=(t,e)=>{if("position"in e){let r=n.POSITION_TYPE_RELATIVE;e.position==="absolute"?r=n.POSITION_TYPE_ABSOLUTE:e.position==="static"&&(r=n.POSITION_TYPE_STATIC),t.setPositionType(r)}for(const[r,s]of k){if(!(r in e))continue;const l=e[r];if(typeof l=="string"){t.setPositionPercent(s,Number.parseFloat(l));continue}t.setPosition(s,l)}},H=(t,e)=>{"margin"in e&&t.setMargin(n.EDGE_ALL,e.margin??0),"marginX"in e&&t.setMargin(n.EDGE_HORIZONTAL,e.marginX??0),"marginY"in e&&t.setMargin(n.EDGE_VERTICAL,e.marginY??0),"marginLeft"in e&&t.setMargin(n.EDGE_START,e.marginLeft||0),"marginRight"in e&&t.setMargin(n.EDGE_END,e.marginRight||0),"marginTop"in e&&t.setMargin(n.EDGE_TOP,e.marginTop||0),"marginBottom"in e&&t.setMargin(n.EDGE_BOTTOM,e.marginBottom||0)},M=(t,e)=>{"padding"in e&&t.setPadding(n.EDGE_ALL,e.padding??0),"paddingX"in e&&t.setPadding(n.EDGE_HORIZONTAL,e.paddingX??0),"paddingY"in e&&t.setPadding(n.EDGE_VERTICAL,e.paddingY??0),"paddingLeft"in e&&t.setPadding(n.EDGE_LEFT,e.paddingLeft||0),"paddingRight"in e&&t.setPadding(n.EDGE_RIGHT,e.paddingRight||0),"paddingTop"in e&&t.setPadding(n.EDGE_TOP,e.paddingTop||0),"paddingBottom"in e&&t.setPadding(n.EDGE_BOTTOM,e.paddingBottom||0)},U=(t,e)=>{"flexGrow"in e&&t.setFlexGrow(e.flexGrow??0),"flexShrink"in e&&t.setFlexShrink(typeof e.flexShrink=="number"?e.flexShrink:1),"flexWrap"in e&&(e.flexWrap==="nowrap"&&t.setFlexWrap(n.WRAP_NO_WRAP),e.flexWrap==="wrap"&&t.setFlexWrap(n.WRAP_WRAP),e.flexWrap==="wrap-reverse"&&t.setFlexWrap(n.WRAP_WRAP_REVERSE)),"flexDirection"in e&&(e.flexDirection==="row"&&t.setFlexDirection(n.FLEX_DIRECTION_ROW),e.flexDirection==="row-reverse"&&t.setFlexDirection(n.FLEX_DIRECTION_ROW_REVERSE),e.flexDirection==="column"&&t.setFlexDirection(n.FLEX_DIRECTION_COLUMN),e.flexDirection==="column-reverse"&&t.setFlexDirection(n.FLEX_DIRECTION_COLUMN_REVERSE)),"flexBasis"in e&&(typeof e.flexBasis=="number"?t.setFlexBasis(e.flexBasis):typeof e.flexBasis=="string"?t.setFlexBasisPercent(Number.parseInt(e.flexBasis,10)):t.setFlexBasis(Number.NaN)),"alignItems"in e&&((e.alignItems==="stretch"||!e.alignItems)&&t.setAlignItems(n.ALIGN_STRETCH),e.alignItems==="flex-start"&&t.setAlignItems(n.ALIGN_FLEX_START),e.alignItems==="center"&&t.setAlignItems(n.ALIGN_CENTER),e.alignItems==="flex-end"&&t.setAlignItems(n.ALIGN_FLEX_END),e.alignItems==="baseline"&&t.setAlignItems(n.ALIGN_BASELINE)),"alignSelf"in e&&((e.alignSelf==="auto"||!e.alignSelf)&&t.setAlignSelf(n.ALIGN_AUTO),e.alignSelf==="flex-start"&&t.setAlignSelf(n.ALIGN_FLEX_START),e.alignSelf==="center"&&t.setAlignSelf(n.ALIGN_CENTER),e.alignSelf==="flex-end"&&t.setAlignSelf(n.ALIGN_FLEX_END),e.alignSelf==="stretch"&&t.setAlignSelf(n.ALIGN_STRETCH),e.alignSelf==="baseline"&&t.setAlignSelf(n.ALIGN_BASELINE)),"alignContent"in e&&((e.alignContent==="flex-start"||!e.alignContent)&&t.setAlignContent(n.ALIGN_FLEX_START),e.alignContent==="center"&&t.setAlignContent(n.ALIGN_CENTER),e.alignContent==="flex-end"&&t.setAlignContent(n.ALIGN_FLEX_END),e.alignContent==="space-between"&&t.setAlignContent(n.ALIGN_SPACE_BETWEEN),e.alignContent==="space-around"&&t.setAlignContent(n.ALIGN_SPACE_AROUND),e.alignContent==="space-evenly"&&t.setAlignContent(n.ALIGN_SPACE_EVENLY),e.alignContent==="stretch"&&t.setAlignContent(n.ALIGN_STRETCH)),"justifyContent"in e&&((e.justifyContent==="flex-start"||!e.justifyContent)&&t.setJustifyContent(n.JUSTIFY_FLEX_START),e.justifyContent==="center"&&t.setJustifyContent(n.JUSTIFY_CENTER),e.justifyContent==="flex-end"&&t.setJustifyContent(n.JUSTIFY_FLEX_END),e.justifyContent==="space-between"&&t.setJustifyContent(n.JUSTIFY_SPACE_BETWEEN),e.justifyContent==="space-around"&&t.setJustifyContent(n.JUSTIFY_SPACE_AROUND),e.justifyContent==="space-evenly"&&t.setJustifyContent(n.JUSTIFY_SPACE_EVENLY))},Y=(t,e)=>{"width"in e&&(typeof e.width=="number"?t.setWidth(e.width):typeof e.width=="string"?t.setWidthPercent(Number.parseInt(e.width,10)):t.setWidthAuto()),"height"in e&&(typeof e.height=="number"?t.setHeight(e.height):typeof e.height=="string"?t.setHeightPercent(Number.parseInt(e.height,10)):t.setHeightAuto()),"minWidth"in e&&(typeof e.minWidth=="string"?t.setMinWidthPercent(Number.parseInt(e.minWidth,10)):t.setMinWidth(e.minWidth??0)),"minHeight"in e&&(typeof e.minHeight=="string"?t.setMinHeightPercent(Number.parseInt(e.minHeight,10)):t.setMinHeight(e.minHeight??0)),"maxWidth"in e&&(typeof e.maxWidth=="string"?t.setMaxWidthPercent(Number.parseInt(e.maxWidth,10)):t.setMaxWidth(e.maxWidth)),"maxHeight"in e&&(typeof e.maxHeight=="string"?t.setMaxHeightPercent(Number.parseInt(e.maxHeight,10)):t.setMaxHeight(e.maxHeight)),"aspectRatio"in e&&t.setAspectRatio(e.aspectRatio)},j=(t,e)=>{"display"in e&&t.setDisplay(e.display==="flex"?n.DISPLAY_FLEX:n.DISPLAY_NONE)},X=(t,e,r)=>{if(!("borderStyle"in e||"borderTop"in e||"borderBottom"in e||"borderLeft"in e||"borderRight"in e))return;const s=r.borderStyle?1:0;t.setBorder(n.EDGE_TOP,r.borderTop===!1?0:s),t.setBorder(n.EDGE_BOTTOM,r.borderBottom===!1?0:s),t.setBorder(n.EDGE_LEFT,r.borderLeft===!1?0:s),t.setBorder(n.EDGE_RIGHT,r.borderRight===!1?0:s)},V=(t,e)=>{"gap"in e&&t.setGap(n.GUTTER_ALL,e.gap??0),"columnGap"in e&&t.setGap(n.GUTTER_COLUMN,e.columnGap??0),"rowGap"in e&&t.setGap(n.GUTTER_ROW,e.rowGap??0)},J=(t,e)=>{const r=e.overflow??"visible",s=e.overflowX??r,l=e.overflowY??r;s==="scroll"||l==="scroll"?t.setOverflow(n.OVERFLOW_SCROLL):s==="hidden"||l==="hidden"?t.setOverflow(n.OVERFLOW_HIDDEN):t.setOverflow(n.OVERFLOW_VISIBLE)},C=(t,e={},r=e)=>{B(t,e),H(t,e),M(t,e),U(t,e),Y(t,e),j(t,e),X(t,e,r),V(t,e),J(t,r)};if(y.env.DEV==="true"){let t=!1;try{import.meta.resolve("react-devtools-core"),t=!0}catch{}t&&await import("../packem_chunks/devtools.js")}const N=(t,e)=>{if(t===e)return;if(!t)return e;const r={};let s=!1;for(const l of Object.keys(t))(!e||!Object.hasOwn(e,l))&&(r[l]=void 0,s=!0);if(e)for(const l of Object.keys(e))e[l]!==t[l]&&(r[l]=e[l],s=!0);return s?r:void 0},E=t=>{if(t){if(t.yogaNode?.unsetMeasureFunc(),"resizeObservers"in t&&t.resizeObservers?.clear(),"childNodes"in t&&t.childNodes)for(const e of t.childNodes)E(e);t.yogaNode?.free(),"cachedRender"in t&&(t.cachedRender=void 0),"childNodes"in t&&(t.childNodes=[]),t.parentNode=void 0}};let u=A,g;async function q(){const t=(await import("node:fs")).readFileSync(new URL("../package.json",import.meta.url),"utf8"),e=JSON.parse(t);return{name:e?.name,version:e?.version}}let d={name:"ink",version:L};if(y.env.DEV==="true")try{const t=await q();d={name:t.name||d.name,version:t.version||d.version}}catch(t){console.warn("Failed to load package.json in development mode. Falling back to default renderer metadata.",t)}const rt=b({afterActiveInstanceBlur(){},appendChild:f,appendChildToContainer:f,appendInitialChild:f,beforeActiveInstanceBlur(){},cancelCallback:F,cancelTimeout:clearTimeout,clearContainer:()=>!1,commitTextUpdate(t,e,r){m(t,r)},commitUpdate(t,e,r,s){g&&t.internal_static&&(g.isStaticDirty=!0);const l=N(r,s),a=N(r.style,s.style);if(!l&&!a)return;let i=!!a;if(l){for(const[o,c]of Object.entries(l))if(o!=="children"){if(o==="style"){h(t,c);continue}if(o==="internal_transform"){t.internal_transform=c,i=!0;continue}if(o==="internal_cursor"){t.internal_cursor=c,i=!0;continue}if(o==="internal_static"){t.internal_static=!0,i=!0;continue}if(o==="sticky"){t.internal_sticky=c,i=!0;continue}if(o==="internalStickyAlternate"){t.internal_stickyAlternate=c,i=!0;continue}if(o==="opaque"){t.internal_opaque=c,i=!0;continue}if(o==="scrollbar"){t.internal_scrollbar=c,i=!0;continue}if(o==="internal_terminalCursorFocus"){t.internal_terminalCursorFocus=c,i=!0;continue}if(o==="internal_terminalCursorPosition"){t.internal_terminalCursorPosition=c,i=!0;continue}if(o==="cachedRender"){t.cachedRender=c,i=!0;continue}I(t,o,c),i=!0}}a&&t.yogaNode&&C(t.yogaNode,a,s.style??{}),i&&p(t)},createInstance(t,e,r,s){if(s.isInsideText&&t==="ink-box")throw new Error("<Box> can’t be nested inside <Text> component");if(s.isInsideText&&t==="ink-cursor")throw new Error("<Cursor> can’t be nested inside <Text> component");const l=t==="ink-text"&&s.isInsideText?"ink-virtual-text":t,a=W(l);for(const[i,o]of Object.entries(e))if(i!=="children"){if(i==="style"){h(a,o),a.yogaNode&&C(a.yogaNode,o);continue}if(i==="internal_transform"){a.internal_transform=o;continue}if(i==="internal_cursor"){a.internal_cursor=o;continue}if(i==="internal_static"){g=r,a.internal_static=!0,r.isStaticDirty=!0,r.staticNode=a;continue}if(i==="sticky"){a.internal_sticky=o;continue}if(i==="internalStickyAlternate"){a.internal_stickyAlternate=o;continue}if(i==="opaque"){a.internal_opaque=o;continue}if(i==="scrollbar"){a.internal_scrollbar=o;continue}if(i==="internal_terminalCursorFocus"){a.internal_terminalCursorFocus=o;continue}if(i==="internal_terminalCursorPosition"){a.internal_terminalCursorPosition=o;continue}if(i==="internal_static"){a.internal_static=!0;continue}if(i==="cachedRender"){a.cachedRender=o;continue}I(a,i,o)}return a},createTextInstance(t,e,r){if(!r.isInsideText)throw new Error(`Text string "${t}" must be rendered inside <Text> component`);return w(t)},detachDeletedInstance(){},finalizeInitialChildren(){return!1},getChildHostContext(t,e){const r=t.isInsideText,s=e==="ink-text"||e==="ink-virtual-text";return r===s?t:{isInsideText:s}},getCurrentUpdatePriority:()=>u,getInstanceFromNode:()=>null,getInstanceFromScope:()=>null,getPublicInstance:t=>t,getRootHostContext:()=>({isInsideText:!1}),hideInstance(t){t.internal_hidden=!0,t.yogaNode?.setDisplay(n.DISPLAY_NONE),p(t)},hideTextInstance(t){m(t,"")},HostTransitionContext:R(null),insertBefore:_,insertInContainerBefore:_,isPrimaryRenderer:!0,maySuspendCommit(){return!0},noTimeout:-1,NotPendingTransition:void 0,now:G,preloadInstance(){return!0},prepareForCommit:()=>null,preparePortalMount:()=>null,prepareScopeUpdate(){},removeChild(t,e){T(t,e),E(e)},removeChildFromContainer(t,e){T(t,e),E(e)},rendererPackageName:d.name,rendererVersion:d.version,requestPostPaintCallback(){},resetAfterCommit(t){if(typeof t.onComputeLayout=="function"&&t.onComputeLayout(),v(t),t.staticNode!==t.previousStaticNode&&(t.previousStaticNode=t.staticNode,typeof t.onStaticChange=="function"&&t.onStaticChange()),t.isStaticDirty){t.isStaticDirty=!1,typeof t.onImmediateRender=="function"&&t.onImmediateRender();return}typeof t.onRender=="function"&&t.onRender()},resetFormInstance(){},resetTextContent(){},resolveEventTimeStamp(){return-1.1},resolveEventType(){return null},resolveUpdatePriority(){return u!==A?u:P},scheduleCallback:O,scheduleMicrotask:queueMicrotask,scheduleTimeout:setTimeout,setCurrentUpdatePriority(t){u=t},shouldAttemptEagerTransition(){return!1},shouldSetTextContent:()=>!1,shouldYield:D,startSuspendingCommit(){},supportsHydration:!1,supportsMicrotasks:!0,supportsMutation:!0,supportsPersistence:!1,suspendInstance(){},trackSchedulerEvent(){},unhideInstance(t){t.internal_hidden=!1,t.yogaNode?.setDisplay(n.DISPLAY_FLEX),p(t)},unhideTextInstance(t,e){m(t,e)},waitForCommitToBeReady(){return null}});export{C as c,rt as j};
@@ -0,0 +1,24 @@
1
+ import{createRequire as we}from"node:module";import{jsxs as W,jsx as x}from"react/jsx-runtime";import{cursorShow as nt,setMode as Vt,BracketedPasteMode as Xt,resetMode as Zt,cursorUp as yt,cursorTo as Ct,cursorHide as q,cursorDown as Te,setCursorStyle as Re,eraseLines as j,cursorNextLine as Se,eraseLineEnd as Ee,createDecMode as Oe,ALT_SCREEN_ON as Pe,clearScreenAndHomeCursor as Ne,ALT_SCREEN_OFF as ke}from"@visulima/ansi";import{wordWrap as De}from"@visulima/string";import Jt from"is-in-ci";import Le from"patch-console";import{ConcurrentRoot as Ie,LegacyRoot as We}from"react-reconciler/constants.js";import{onExit as $e}from"signal-exit";import A from"yoga-layout";import{a as Me}from"./accessibility-context-DDyHTwmA.js";import{PureComponent as Ae,useState as ct,useRef as $,useCallback as y,useEffect as vt,useMemo as F}from"react";import{e as Be}from"./animation-context-DW3p-vpk.js";import{t as He}from"./app-context-BVpKlG1z.js";import{o as Ue}from"./cursor-context-CFviBqPX.js";import{parseStacktrace as Ye}from"@visulima/error/stacktrace";import je from"code-excerpt";import{Box as _}from"../components/box.js";import{Text as M}from"../components/text.js";import{o as qe}from"./focus-context-CsT69klR.js";import{t as ze}from"./stderr-context-Bvnik0hL.js";import{e as Ge}from"./stdin-context-88AhuztD.js";import{t as Ve}from"./stdout-context-BnblEPez.js";import{I as Xe,v as Ze,r as Je,H as Qe}from"./renderer-COXHo5Xk.js";import{c as ti,e as ei}from"./dom-rphpG0kf.js";import{resolveFlags as ii}from"./kittyFlags-g8ALyoCU.js";import{p as ri}from"./load-native-root-binding-DDikxNox.js";import{a as si}from"./measure-text-B7juNq4Y.js";import{j as L,c as oi}from"./reconciler-CFyBVf7l.js";import{measureAndExtractObservers as ni}from"./ResizeObserver-aX8XOr2u.js";import{calculateScroll as ui}from"./calculateScroll-D4Y_JR4H.js";import{g as X}from"./utils-Bup8lyK8.js";const be=we(import.meta.url),Q=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,ot=e=>{if(typeof Q<"u"&&Q.versions&&Q.versions.node){const[t,i]=Q.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return Q.getBuiltinModule(e)}return be(e)},k=Q,{cwd:ye}=k,{Stream:xe}=ot("node:stream"),{Buffer:Ht}=ot("node:buffer"),{Console:Ce}=ot("node:console"),{EventEmitter:_e}=ot("node:events"),{existsSync:Ke,readFileSync:Fe}=ot("node:fs"),Qt="\x1B[200~",Ut="\x1B[201~",ai=e=>e>=48&&e<=63,li=e=>e>=32&&e<=47,te=e=>e>=64&&e<=126,di=(e,t,i)=>{const r=t+i+1;let o=r;for(;o<e.length;o++){const u=e.codePointAt(o);if(u===void 0)return"pending";if(!(ai(u)||li(u))&&!(u===91&&o===r))return te(u)?{nextIndex:o+1,sequence:e.slice(t,o+1)}:void 0}return"pending"},ci=(e,t,i)=>{const r=t+i+2;if(r>e.length)return"pending";const o=e.codePointAt(r-1);if(!(o===void 0||!te(o)))return{nextIndex:r,sequence:e.slice(t,r)}},Kt=(e,t,i)=>{const r=e[t+i];if(r===void 0)return"pending";if(r==="[")return di(e,t,i);if(r==="O")return ci(e,t,i)},hi=(e,t)=>{const i=e.codePointAt(t+1),r=i!==void 0&&i>65535?2:1,o=t+1+r;return{nextIndex:o,sequence:e.slice(t,o)}},fi=(e,t)=>{if(t===e.length-1)return"pending";if(e[t+1]==="\x1B"){if(t+2>=e.length)return"pending";const r=Kt(e,t,2);return r==="pending"?"pending":r||{nextIndex:t+2,sequence:e.slice(t,t+2)}}const i=Kt(e,t,1);return i==="pending"?"pending":i||hi(e,t)},Ft=(e,t)=>{let i=0;for(let r=0;r<e.length;r++){const o=e[r];(o===""||o==="\b")&&(r>i&&t.push(e.slice(i,r)),t.push(o),i=r+1)}i<e.length&&t.push(e.slice(i))},pi=e=>{const t=[];let i=0;const r=o=>({events:t,pending:e.slice(o)});for(;i<e.length;){const o=e.indexOf("\x1B",i);if(o===-1)return Ft(e.slice(i),t),{events:t,pending:""};o>i&&Ft(e.slice(i,o),t);const u=fi(e,o);if(u==="pending")return r(o);if(u.sequence===Qt){const l=u.nextIndex,n=e.indexOf(Ut,l);if(n===-1)return r(o);t.push({paste:e.slice(l,n)}),i=n+Ut.length;continue}t.push(u.sequence),i=u.nextIndex}return{events:t,pending:""}},mi=()=>{let e="";return{flushPendingEscape(){if(!e.startsWith("\x1B"))return;const t=e;return e="",t},hasPendingEscape(){return e.startsWith("\x1B")&&!e.startsWith(Qt)&&e!=="\x1B[200"},push(t){const i=pi(e+t);return e=i.pending,i.events},reset(){e=""}}},wt=e=>{if(!e)return e;const t=ye();return e.replace(`file://${t}/`,"").replace(`${t}/`,"")};function gi({error:e}){const t=Ye(e),i=new Map,r=t.map(s=>{const a=!s.methodName&&!s.file?`raw:${s.raw}`:`${wt(s.file)??""}:${s.line}:${s.column}:${s.methodName??""}`,p=i.get(a)??0;return i.set(a,p+1),{key:`${a}#${p}`,trace:s}}),o=t[0],u=wt(o?.file);let l,n=0;if(u&&o?.line&&Ke(u)){const s=Fe(u,"utf8");if(l=je(s,o.line),l)for(const{line:a}of l)n=Math.max(n,String(a).length)}return W(_,{flexDirection:"column",padding:1,children:[W(_,{children:[W(M,{backgroundColor:"red",color:"white",children:[" ","ERROR"," "]}),W(M,{children:[" ",e.message]})]}),o&&u?x(_,{marginTop:1,children:W(M,{dimColor:!0,children:[u,":",o.line,":",o.column]})}):null,o&&l?x(_,{flexDirection:"column",marginTop:1,children:l.map(({line:s,value:a})=>W(_,{children:[x(_,{width:n+1,children:W(M,{"aria-label":s===o.line?`Line ${s}, error`:`Line ${s}`,backgroundColor:s===o.line?"red":void 0,color:s===o.line?"white":void 0,dimColor:s!==o.line,children:[String(s).padStart(n," "),":"]})}),x(M,{backgroundColor:s===o.line?"red":void 0,color:s===o.line?"white":void 0,children:` ${a}`})]},`excerpt-${s}`))}):null,t.length>0?x(_,{flexDirection:"column",marginTop:1,children:r.map(({key:s,trace:a})=>{const p=wt(a.file)??"";return!a.methodName&&!a.file?W(_,{children:[x(M,{dimColor:!0,children:"- "}),x(M,{bold:!0,dimColor:!0,children:a.raw})]},s):W(_,{children:[x(M,{dimColor:!0,children:"- "}),x(M,{bold:!0,dimColor:!0,children:a.methodName??"<anonymous>"}),W(M,{"aria-label":`at ${p} line ${a.line} column ${a.column}`,color:"gray",dimColor:!0,children:[" ","(",p,":",a.line,":",a.column,")"]})]},s)})}):null]})}class vi extends Ae{static displayName="InternalErrorBoundary";static getDerivedStateFromError(t){return{error:t}}state={error:void 0};componentDidCatch(t){this.props.onError(t)}render(){return this.state.error?x(gi,{error:this.state.error}):this.props.children}}const wi=" ",bi="\x1B[Z",yi="\x1B",xi=Vt(Xt),Yt=Zt(Xt),ee=({children:e,exitOnCtrlC:t,interactive:i,onExit:r,onWaitUntilRenderFlush:o,renderThrottleMs:u,setCursorPosition:l,stderr:n,stdin:s,stdout:a,writeToStderr:p,writeToStdout:w})=>{const[g,d]=ct(!0),[h,v]=ct(void 0),[,b]=ct([]),P=$(0),T=$(new Map),D=$(void 0),N=$(0),I=$(!1),E=$(0),[S]=ct(()=>{const c=new _e;return c.setMaxListeners(1/0),c}),K=$(void 0),R=$(void 0);R.current??=mi();const B=$(void 0),Tt=$(!1),ae=20,z=y(()=>{B.current&&(clearTimeout(B.current),B.current=void 0)},[]),G=y(()=>{D.current&&(clearTimeout(D.current),D.current=void 0)},[]),ut=y(()=>{if(G(),T.current.size===0)return;let c=Number.POSITIVE_INFINITY;for(const f of T.current.values())c=Math.min(c,f.nextDueTime);const m=Math.max(0,c-performance.now());D.current=setTimeout(()=>{D.current=void 0;const f=performance.now(),C=[...T.current.values()];for(const O of C){if(f<O.nextDueTime)continue;O.callback(f);const ge=f-O.startTime,ve=Math.floor(ge/O.interval)+1;O.nextDueTime=O.startTime+ve*O.interval}ut()},m)},[G]),Rt=y((c,m)=>{const f=performance.now();return T.current.set(c,{callback:c,interval:m,nextDueTime:f+m,startTime:f}),ut(),{startTime:f,unsubscribe(){if(T.current.delete(c),T.current.size===0){G();return}ut()}}},[G,ut]);vt(()=>()=>{G()},[G]);const H=s.isTTY,St=y(()=>{K.current&&(s.removeListener("readable",K.current),K.current=void 0)},[s]),at=y(()=>{R.current?.reset(),z(),St()},[z,St]),V=y(()=>{I.current=!1,s.setRawMode(!1),s.unref(),N.current=0,at()},[s,at]),et=y(c=>{H&&(N.current>0||I.current)&&V(),r(c)},[H,V,r]),Et=y(c=>{if(c.includes("")&&t){et();return}c===yi&&g&&v(m=>{if(!m)return m})},[t,et,g]),it=y(c=>{Et(c),S.emit("input",c)},[Et,S]),Ot=y(()=>{z(),B.current=setTimeout(()=>{B.current=void 0;const c=R.current.flushPendingEscape();c&&it(c)},ae)},[z,it]),gt=y(()=>{z();let c;for(;(c=s.read())!==null;){const m=R.current.push(c);for(const f of m)if(typeof f=="string")it(f);else{if(S.listenerCount("paste")===0){Tt.current||(Tt.current=!0,p(`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
+ `)),it(f.paste);continue}S.emit("paste",f.paste)}}R.current.hasPendingEscape()&&Ot()},[s,it,z,Ot,p,S]),Pt=y(()=>{K.current||(K.current=gt,s.addListener("readable",gt))},[s,gt]),Nt=y(c=>{if(!H)throw s===k.stdin?new Error(`Raw mode is not supported on the current process.stdin, which Ink uses as input stream by default.
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(s.setEncoding("utf8"),c){if(N.current===0){const m=I.current;I.current=!1,m||(s.ref(),s.setRawMode(!0)),Pt()}N.current++;return}N.current!==0&&--N.current===0&&(at(),I.current=!0,queueMicrotask(()=>{I.current&&V()}))},[H,s,Pt,at,V]),kt=y(c=>{if(a.isTTY){if(c){E.current===0&&a.write(xi),E.current++;return}E.current!==0&&--E.current===0&&a.write(Yt)}},[a]),Dt=y((c,m)=>{const f=c.findIndex(C=>C.id===m);for(let C=f+1;C<c.length;C++){const O=c[C];if(O?.isActive)return O.id}},[]),Lt=y((c,m)=>{const f=c.findIndex(C=>C.id===m);for(let C=f-1;C>=0;C--){const O=c[C];if(O?.isActive)return O.id}},[]),lt=y(()=>{b(c=>(v(m=>{const f=c.find(C=>C.isActive)?.id;return Dt(c,m)??f}),c))},[Dt]),dt=y(()=>{b(c=>(v(m=>{const f=c.findLast(C=>C.isActive)?.id;return Lt(c,m)??f}),c))},[Lt]);vt(()=>{const c=f=>{!g||P.current===0||(f===wi&&lt(),f===bi&&dt())};S.on("input",c);const m=S;return()=>{m.off("input",c)}},[g,lt,dt,S]);const It=y(()=>{d(!0)},[]),Wt=y(()=>{d(!1)},[]),$t=y(c=>{b(m=>(m.some(f=>f?.id===c)&&v(c),m))},[]),Mt=y((c,{autoFocus:m})=>{b(f=>(P.current=f.length+1,[...f,{id:c,isActive:!0}])),m&&v(f=>f||c)},[]),_t=y(c=>{v(m=>{if(m!==c)return m}),b(m=>{const f=m.filter(C=>C.id!==c);return P.current=f.length,f})},[]),At=y(c=>{b(m=>m.map(f=>f.id!==c?f:{id:c,isActive:!0}))},[]),Bt=y(c=>{v(m=>{if(m!==c)return m}),b(m=>m.map(f=>f.id!==c?f:{id:c,isActive:!1}))},[]);vt(()=>()=>{const c=!a.destroyed&&!a.writableEnded;i&&c&&a.write(nt),H&&(N.current>0||I.current)&&V(),E.current>0&&(a.isTTY&&c&&a.write(Yt),E.current=0)},[a,H,V,i]);const le=F(()=>({exit:et,waitUntilRenderFlush:o}),[et,o]),de=F(()=>({internal_eventEmitter:S,internal_exitOnCtrlC:t,isRawModeSupported:H,setBracketedPasteMode:kt,setRawMode:Nt,stdin:s}),[s,Nt,kt,H,t,S]),ce=F(()=>({stdout:a,write:w}),[a,w]),he=F(()=>({stderr:n,write:p}),[n,p]),fe=F(()=>({setCursorPosition:l}),[l]),pe=F(()=>({activate:At,activeId:h,add:Mt,deactivate:Bt,disableFocus:Wt,enableFocus:It,focus:$t,focusNext:lt,focusPrevious:dt,remove:_t}),[h,Mt,_t,At,Bt,It,Wt,lt,dt,$t]),me=F(()=>({renderThrottleMs:u,subscribe:Rt}),[Rt,u]);return x(He.Provider,{value:le,children:x(Ge.Provider,{value:de,children:x(Ve.Provider,{value:ce,children:x(ze.Provider,{value:he,children:x(qe.Provider,{value:pe,children:x(Be.Provider,{value:me,children:x(Ue.Provider,{value:fe,children:x(vi,{onError:et,children:e})})})})})})})})};ee.displayName="InternalApp";const Ci=(e,t,i)=>{if(i<=0||!e.yogaNode)return"";const{yogaNode:r}=e,o=r.getComputedBorder(A.EDGE_LEFT),u=r.getComputedBorder(A.EDGE_RIGHT),l=r.getComputedBorder(A.EDGE_TOP),n=r.getComputedPadding(A.EDGE_LEFT),s=r.getComputedPadding(A.EDGE_RIGHT),a=r.getComputedPadding(A.EDGE_TOP),p=Math.round(r.getComputedWidth()-o-u-n-s);if(p<=0)return"";const w=new Xe({height:i,width:p}),g=-(e.internal_scrollState?.scrollLeft??0)-o-n,d=-t-l-a;for(const h of e.childNodes)Ze(h,w,{absoluteOffsetX:g,absoluteOffsetY:d,offsetX:g,offsetY:d,skipStaticElements:!1});return w.get().output},xt=new WeakMap,Ti={bar:6,"blinking-bar":5,"blinking-block":1,"blinking-underline":3,block:2,default:0,underline:4},jt=e=>Re(Ti[e]),ft=(e,t)=>e?.x!==t?.x||e?.y!==t?.y,tt=(e,t)=>{if(!t)return"";const i=e-t.y;return(i>0?yt(i):"")+Ct(t.x)+nt},ie=(e,t)=>{if(!t)return"";const i=e-1-t.y;return(i>0?Te(i):"")+Ct(0)},re=e=>{const t=e.cursorWasShown?q:"",i=ie(e.previousLineCount,e.previousCursorPosition),r=tt(e.visibleLineCount,e.cursorPosition);return t+i+r},pt=(e,t,i)=>e?q+ie(t,i):"",Z=e=>e??"default",se=()=>{let e,t;return{consumeDelta:()=>{if(Z(t)===Z(e))return"";const i=Z(t);return e=t,jt(i)},consumeRestoreOnDone:()=>{const i=Z(e)!=="default";return e=void 0,t=void 0,i?jt("default"):""},isDirty:()=>Z(t)!==Z(e),setPending:i=>{t=i}}},st=(e,t)=>t.endsWith(`
5
+ `)?e.length-1:e.length,oe=e=>e.rows||1/0,mt=(e,t)=>Math.min(e,oe(t)),Ri=(e,{showCursor:t=!1}={})=>{let i=0,r="",o=!1,u,l=!1,n,s=!1;const a=se(),p=()=>l?u:void 0,w=(d,h)=>{const v=ft(h,n);return d!==r||v||a.isDirty()},g=d=>{!t&&!o&&(e.write(q),o=!0);const h=p();l=!1;const v=ft(h,n);if(!w(d,h))return!1;const b=a.consumeDelta(),P=d.split(`
6
+ `),T=st(P,d),D=tt(T,h);if(d===r&&v)e.write(b+re({cursorPosition:h,cursorWasShown:s,previousCursorPosition:n,previousLineCount:i,visibleLineCount:T}));else if(d===r&&b!=="")e.write(b);else{r=d;const N=pt(s,i,n);e.write(b+N+j(mt(i,e))+d+D),i=P.length}return n=h?{...h}:void 0,s=h!==void 0,!0};return g.clear=()=>{const d=pt(s,i,n);e.write(d+j(mt(i,e))),r="",i=0,n=void 0,s=!1},g.done=()=>{r="",i=0,n=void 0,s=!1;const d=a.consumeRestoreOnDone();d!==""&&e.write(d),t||(e.write(nt),o=!1)},g.reset=()=>{r="",i=0,n=void 0,s=!1},g.sync=d=>{const h=l?u:void 0;l=!1;const v=d.split(`
7
+ `);r=d,i=v.length;const b=a.consumeDelta();b!==""&&e.write(b),!h&&s&&e.write(q),h&&e.write(tt(st(v,d),h)),n=h?{...h}:void 0,s=h!==void 0},g.setCursorPosition=d=>{u=d,l=!0},g.setCursorShape=a.setPending,g.isCursorDirty=()=>l||a.isDirty(),g.willRender=d=>w(d,p()),g},Si=(e,{showCursor:t=!1}={})=>{let i=[],r="",o=!1,u,l=!1,n,s=!1;const a=se(),p=()=>l?u:void 0,w=(d,h)=>{const v=ft(h,n);return d!==r||v||a.isDirty()},g=d=>{!t&&!o&&(e.write(q),o=!0);const h=p();l=!1;const v=ft(h,n);if(!w(d,h))return!1;const b=a.consumeDelta(),P=d.split(`
8
+ `),T=st(P,d),D=st(i,r);if(d===r&&v)return e.write(b+re({cursorPosition:h,cursorWasShown:s,previousCursorPosition:n,previousLineCount:i.length,visibleLineCount:T})),n=h?{...h}:void 0,s=h!==void 0,!0;if(d===r&&b!=="")return e.write(b),!0;const N=pt(s,i.length,n);if(d===`
9
+ `||r.length===0){const R=tt(T,h);return e.write(b+N+j(mt(i.length,e))+d+R),s=h!==void 0,n=h?{...h}:void 0,r=d,i=P,!0}const I=d.endsWith(`
10
+ `),E=[b,N],S=oe(e);if(T<D){const R=r.endsWith(`
11
+ `)?1:0;E.push(j(Math.min(D-T+R,S)),yt(Math.min(T,S-1)))}else E.push(yt(Math.min(D-1,S-1)));for(let R=0;R<T;R++){const B=R===T-1;if(P[R]===i[R]){(!B||I)&&E.push(Se());continue}E.push(Ct(0)+P[R]+Ee+(B&&!I?"":`
12
+ `))}const K=tt(T,h);return E.push(K),e.write(E.join("")),s=h!==void 0,n=h?{...h}:void 0,r=d,i=P,!0};return g.clear=()=>{const d=pt(s,i.length,n);e.write(d+j(mt(i.length,e))),r="",i=[],n=void 0,s=!1},g.done=()=>{r="",i=[],n=void 0,s=!1;const d=a.consumeRestoreOnDone();d!==""&&e.write(d),t||(e.write(nt),o=!1)},g.reset=()=>{r="",i=[],n=void 0,s=!1},g.sync=d=>{const h=l?u:void 0;l=!1;const v=d.split(`
13
+ `);r=d,i=v;const b=a.consumeDelta();b!==""&&e.write(b),!h&&s&&e.write(q),h&&e.write(tt(st(v,d),h)),n=h?{...h}:void 0,s=h!==void 0},g.setCursorPosition=d=>{u=d,l=!0},g.setCursorShape=a.setPending,g.isCursorDirty=()=>l||a.isDirty(),g.willRender=d=>w(d,p()),g},Ei=(e,{incremental:t=!1,showCursor:i=!1}={})=>t?Si(e,{showCursor:i}):Ri(e,{showCursor:i}),Oi={create:Ei},ne=Oe(2026),Y=Vt(ne),U=Zt(ne);function Pi(e,t){return"isTTY"in e&&e.isTTY&&(t??!Jt)}let J;const Ni=()=>{if(J!==!1){if(J!==void 0)return J;try{return J=ri(import.meta.url).Renderer,J}catch{J=!1;return}}},ki=e=>{const t=Ni();if(!t)return;let i,r=0,o=0;const u=(l,n)=>{(!i||r!==l||o!==n)&&(i?i.resize(l,n):i=new t(l,n),r=l,o=n)};return{clear(){if(i){const l=new Uint32Array(r*o*2),n=65535;for(let s=0;s<l.length;s+=2)l[s]=32,l[s+1]=n;i.render(l)}},destroy(){i=void 0},render(l,n,s){if(u(n,s),!!i){e.isTTY&&i.writeRaw(Y);try{i.render(l)}finally{e.isTTY&&i.writeRaw(U)}}},resize(l,n){u(l,n)}}};function qt(e,t=0,i={}){const r=i.leading??!0,o=i.trailing??!0;let u,l,n,s;const a=()=>{if(l===void 0)return;const h=l;l=void 0,s=e(...h)},p=()=>{u!==void 0&&(clearTimeout(u),u=void 0)},w=()=>{u=void 0,o&&a(),l=void 0,n=void 0},g=()=>{p(),u=setTimeout(w,t)},d=function(...h){const v=Date.now();if(n??=v,v-n>=t)return l=h,a(),n=v,g(),s;l=h;const b=u===void 0;return g(),r&&b&&a(),s};return d.cancel=()=>{p(),l=void 0,n=void 0},d.flush=()=>(p(),a(),n=void 0,s),d}console.Console||(console.Console=Ce);const rt=()=>{},zt=async()=>new Promise(e=>{setImmediate(e)}),Di=27,Li=91,Ii=63,Wi=117,$i=48,Mi=57,_i=e=>e>=$i&&e<=Mi,ue=(e,t)=>{if(e[t]!==Di||e[t+1]!==Li||e[t+2]!==Ii)return;let i=t+3;const r=i;for(;i<e.length&&_i(e[i]);)i++;if(i!==r){if(i===e.length)return{state:"partial"};if(e[i]===Wi)return{endIndex:i,state:"complete"}}},Ai=e=>{for(let t=0;t<e.length;t++)if(ue(e,t)?.state==="complete")return!0;return!1},Bi=e=>{const t=[];let i=0;for(;i<e.length;){const r=ue(e,i);if(r?.state==="complete"){i=r.endIndex+1;continue}if(r?.state==="partial")break;t.push(e[i]),i++}return t},Hi=({isTty:e,isUnmounting:t,isWindows:i,nextOutputHeight:r,previousOutputHeight:o,viewportRows:u})=>{if(!e)return!1;const l=o>0,n=o>=u,s=r>=u,a=o>u,p=r>u,w=n&&r<u;return a||p&&l||w||t&&n||i&&(s||n)},bt=e=>e instanceof Error||Object.prototype.toString.call(e)==="[object Error]",Gt=e=>{const t=!e.destroyed&&!e.writableEnded&&(e.writable??!0),i=e._writableState!==void 0||e.writableLength!==void 0;return{canWriteToStdout:t,hasWritableState:i}},ht=(e,t)=>{if(!e||typeof e.flush!="function")return;const i=e;t?i.flush():typeof i.cancel=="function"&&i.cancel()};class Ui{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;cancelKittyDetection;nextRenderCommit;deferredInitDone=!1;constructor(t){this.options=t,this.rootNode=ti("ink-root"),this.rootNode.onComputeLayout=this.calculateLayout,this.isScreenReaderEnabled=t.isScreenReaderEnabled??k.env.INK_SCREEN_READER==="true",this.interactive=this.resolveInteractiveOption(t.interactive),this.alternateScreen=!1;const i=t.debug||this.isScreenReaderEnabled,r=t.maxFps??30,o=r>0?Math.max(1,Math.ceil(1e3/r)):0;this.renderThrottleMs=i?0:o;const u=i?this.onRender:(()=>{const n=qt(this.onRender,o,{leading:!0,trailing:!0});return this.throttledOnRender=n,()=>{this.hasPendingThrottledRender=!0,n()}})();if(i&&(this.throttledOnRender=void 0),t.standardReactLayoutTiming){let n=!1;const s=()=>{n||(n=!0,queueMicrotask(()=>{n=!1,this.onRender()}))};this.rootNode.onRender=s,this.rootNode.onImmediateRender=s}else this.rootNode.onRender=u,this.rootNode.onImmediateRender=this.onRender;this.rootNode.onStaticChange=this.handleStaticChange,this.log=Oi.create(t.stdout,{incremental:t.incrementalRendering}),this.useNativeRenderer=t.useNativeRenderer??!1,this.useNativeRenderer&&(this.nativeLog=ki(t.stdout),this.nativeLog||(this.useNativeRenderer=!1)),this.manualCursorPosition=void 0,this.renderedCursorPosition=void 0,this.renderedCursorRequested=!1,this.throttledLog=i?this.log:qt(n=>{const s=this.log.willRender(n),a=this.shouldSync();a&&s&&this.options.stdout.write(Y),this.log(n),a&&s&&this.options.stdout.write(U)},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=X(this.options.stdout).columns,this.fullStaticOutput="";const l=t.concurrent?Ie:We;this.container=L.createContainer(this.rootNode,l,null,!1,null,"id",()=>{},()=>{},()=>{},()=>{}),this.unsubscribeExit=$e(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(),k.env.DEV==="true"&&L.injectIntoDevTools(),this.exitPromise=new Promise((n,s)=>{this.resolveExitPromise=n,this.rejectExitPromise=s}),this.exitPromise.catch(rt)}runDeferredInit(){this.deferredInitDone||(this.deferredInitDone=!0,this.initDeferredKittyKeyboard())}resized=()=>{const t=X(this.options.stdout).columns;t<this.lastTerminalWidth&&(this.log.clear(),this.lastOutput="",this.lastOutputToRender=""),si(),this.calculateLayout(),ei(this.rootNode),this.onRender(),this.lastTerminalWidth=t};resolveExitPromise=()=>{};rejectExitPromise=()=>{};unsubscribeExit=()=>{};handleAppExit=t=>{if(!(this.isUnmounted||this.isUnmounting)){if(bt(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=r=>{const o=new Map;this.calculateScrollAndTriggerObservers(r,o);for(const[u,l]of o)u.internalTrigger(l)};this.backbufferNode=void 0,this.prepareYogaTree(this.rootNode,t);const i=X(this.options.stdout).columns;this.rootNode.yogaNode.setWidth(i),this.rootNode.yogaNode.calculateLayout(void 0,void 0,A.DIRECTION_LTR),t(this.rootNode)};calculateScrollAndTriggerObservers(t,i){if(t.nodeName==="ink-box"){const{style:r}=t,o=r.overflow??"visible",u=r.overflowX??o,l=r.overflowY??o;u==="scroll"||l==="scroll"?(ui(t),r.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(ni(t,i),!t.internal_static)for(const r of t.childNodes)r.nodeName!=="#text"&&this.calculateScrollAndTriggerObservers(r,i)}recalculateLayout(){this.markAllTextNodesDirty(this.rootNode),this.calculateLayout(),this.onRender()}prepareYogaTree(t,i){if(t.isYogaTreeDetached&&!t.cachedRender&&t.yogaNode){for(t.yogaNode.setWidthAuto(),t.yogaNode.setHeightAuto(),oi(t.yogaNode,t.style);t.yogaNode.getChildCount()>0;)t.yogaNode.getChild(0).remove();let r=0;for(const o of t.childNodes){const u=o;o.nodeName!=="#text"&&u.yogaNode&&(t.yogaNode.insertChild(u.yogaNode,r),r++)}t.isYogaTreeDetached=!1,this.markAllTextNodesDirty(t)}for(const r of t.childNodes)r.nodeName!=="#text"&&this.prepareYogaTree(r,i);if(t.nodeName==="ink-static-render"&&!t.cachedRender){const r=X(this.options.stdout).columns,{width:o}=t.style;t.yogaNode&&(t.yogaNode.setWidth(typeof o=="number"?o:r),t.yogaNode.calculateLayout(void 0,void 0,A.DIRECTION_LTR)),i(t),Je(t,{skipStaticElements:!1}),t.internal_onRendered?.()}}markAllTextNodesDirty(t){if(!t.cachedRender){t.nodeName==="ink-text"&&t.yogaNode&&t.yogaNode.markDirty();for(const i of t.childNodes)i.nodeName!=="#text"&&this.markAllTextNodesDirty(i)}}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 i=Math.round(t.internal_scrollState.scrollTop),r=t.yogaNode?.getComputedPadding(A.EDGE_TOP)??0,o=Math.max(0,i-Math.round(r)),u=t.internal_maxPushedScrollTop??0,{maxScrollbackLength:l}=t.style,n=l===void 0?u:Math.max(u,o-Math.max(0,l)),s=o-n;if(s<=0)return"";const a=Ci(t,n,s);return a===""?"":(t.internal_maxPushedScrollTop=o,`${a}\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=Qe(this.rootNode,this.isScreenReaderEnabled,{useNativeRenderer:this.useNativeRenderer}),{cursorPosition:i,cursorRequested:r,cursorShape:o,output:u,outputBuffer:l,outputHeight:n,outputWidth:s,staticOutput:a}=t;this.renderedCursorRequested=r,this.renderedCursorPosition=i,this.log.setCursorShape(r?o:void 0);const p=this.computeBackbufferOutput();if(this.useNativeRenderer&&this.nativeLog&&l&&s){a&&a!==`
16
+ `&&this.options.stdout.write(a),p&&this.options.stdout.write(p),this.nativeLog.render(l,s,n),this.lastOutputHeight=n;return}r&&this.log.setCursorPosition(this.getActiveCursorPosition());const w=a&&a!==`
17
+ `;if(this.options.debug){w&&(this.fullStaticOutput+=a),this.lastOutput=u,this.lastOutputToRender=u,this.lastOutputHeight=n,this.options.stdout.write(this.fullStaticOutput+u);return}if(!this.interactive){w&&this.options.stdout.write(a),this.lastOutput=u,this.lastOutputToRender=`${u}
18
+ `,this.lastOutputHeight=n;return}if(this.isScreenReaderEnabled){const g=this.shouldSync();if(g&&this.options.stdout.write(Y),w){const v=this.lastOutputHeight>0?j(this.lastOutputHeight):"";this.options.stdout.write(v+a),this.lastOutputHeight=0}if(u===this.lastOutput&&!w){g&&this.options.stdout.write(U);return}const d=X(this.options.stdout).columns,h=De(u,{trim:!1,width:d,wrapMode:"BREAK_WORDS"}).replace(/\n$/,"");if(w)this.options.stdout.write(h);else{const v=this.lastOutputHeight>0?j(this.lastOutputHeight):"";this.options.stdout.write(v+h)}this.lastOutput=u,this.lastOutputToRender=h,this.lastOutputHeight=h===""?0:h.split(`
19
+ `).length,g&&this.options.stdout.write(U);return}w&&(this.fullStaticOutput+=a),this.renderInteractiveFrame(u,n,w?a:"",p)};accessibilityContextValue;render(t){this.accessibilityContextValue??={isScreenReaderEnabled:this.isScreenReaderEnabled};const i=x(Me.Provider,{value:this.accessibilityContextValue,children:x(ee,{exitOnCtrlC:this.options.exitOnCtrlC,interactive:this.interactive,onExit:this.handleAppExit,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?L.updateContainer(i,this.container,null,rt):(L.updateContainerSync(i,this.container,null,rt),L.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 i=this.shouldSync();i&&this.options.stdout.write(Y),this.log.clear(),this.options.stdout.write(t),this.restoreLastOutput(),i&&this.options.stdout.write(U)};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 i=this.shouldSync();i&&this.options.stdout.write(Y),this.log.clear(),this.options.stderr.write(t),this.restoreLastOutput(),i&&this.options.stdout.write(U)};unmount=t=>{if(this.isUnmounted||this.isUnmounting)return;this.isUnmounting=!0,this.beforeExitHandler&&(k.off("beforeExit",this.beforeExitHandler),this.beforeExitHandler=void 0);const i=this.options.stdout,{canWriteToStdout:r,hasWritableState:o}=Gt(i);ht(this.throttledOnRender,r),r&&!this.alternateScreen&&(!this.throttledOnRender||!this.hasPendingThrottledRender&&this.fullStaticOutput==="")&&(this.calculateLayout(),this.onRender()),this.isUnmounted=!0,this.unsubscribeExit(),ht(this.throttledLog,r),typeof this.restoreConsole=="function"&&this.restoreConsole();const u=()=>{typeof this.unsubscribeResize=="function"&&this.unsubscribeResize(),this.cancelKittyDetection&&this.cancelKittyDetection(),r&&(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,ke),this.writeBestEffort(this.options.stdout,nt),this.alternateScreen=!1):this.interactive?this.options.debug||this.log.done():this.options.stdout.write(this.options.debug?`
20
+ `:`${this.lastOutput}
21
+ `)),this.kittyProtocolEnabled=!1,xt.delete(this.options.stdout);const{exitResult:n}=this,s=()=>{bt(t)?this.rejectExitPromise(t):this.resolveExitPromise(n)};t!==void 0&&!bt(t)?s():r&&o?this.options.stdout.write("",s):setImmediate(s)},l=L;this.options.concurrent?(L.updateContainerSync(null,this.container,null,rt),L.flushSyncWork(),l.flushPassiveEffects?.(),u()):(L.updateContainerSync(null,this.container,null,rt),L.flushSyncWork(),u())};async waitUntilExit(){return this.beforeExitHandler||(this.beforeExitHandler=()=>{this.unmount()},k.on("beforeExit",this.beforeExitHandler)),this.exitPromise}async waitUntilRenderFlush(){if(this.isUnmounted||this.isUnmounting){await this.awaitExit();return}if(await zt(),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}L.flushSyncWork();const t=this.options.stdout,{canWriteToStdout:i,hasWritableState:r}=Gt(t);if(ht(this.throttledOnRender,i),ht(this.throttledLog,i),i&&r){await new Promise(o=>{this.options.stdout.write("",()=>{o()})});return}await zt()}clear(){this.interactive&&!this.options.debug&&(this.log.clear(),this.log.sync(this.lastOutputToRender||`${this.lastOutput}
22
+ `))}patchConsole(){this.options.debug||(this.restoreConsole=Le((t,i)=>{t==="stdout"&&this.writeToStdout(i),t==="stderr"&&(i.startsWith("The above error occurred")||this.writeToStderr(i))}))}setAlternateScreen(t){this.alternateScreen=this.resolveAlternateScreenOption(t,this.interactive),this.alternateScreen&&(this.writeBestEffort(this.options.stdout,Pe),this.writeBestEffort(this.options.stdout,q))}resolveInteractiveOption(t){return t??(!Jt&&!!this.options.stdout.isTTY)}resolveAlternateScreenOption(t,i){return!!t&&i&&!!this.options.stdout.isTTY}shouldSync(){return Pi(this.options.stdout,this.interactive)}writeBestEffort(t,i){try{t.write(i)}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 i=new Promise(r=>{t=r});this.nextRenderCommit={promise:i,resolve:t}}return this.nextRenderCommit.promise}renderInteractiveFrame(t,i,r,o=""){const u=r+o,l=u!=="",n=this.options.stdout.isTTY,s=n?X(this.options.stdout).rows:24,a=n&&i>=s,p=a?t:`${t}
23
+ `,w=k.platform==="win32",g=n&&w&&(a||this.lastOutputHeight>=s);if(Hi({isTty:n,isUnmounting:this.isUnmounting,isWindows:w,nextOutputHeight:i,previousOutputHeight:this.lastOutputHeight,viewportRows:s})){if(this.options.incrementalRendering&&!g){l&&(this.log.clear(),this.options.stdout.write(u)),(t!==this.lastOutput||this.log.isCursorDirty()||l)&&this.throttledLog(p),this.lastOutput=t,this.lastOutputToRender=p,this.lastOutputHeight=i;return}const d=this.shouldSync();d&&this.options.stdout.write(Y),this.options.stdout.write(Ne+this.fullStaticOutput+o+t),this.lastOutput=t,this.lastOutputToRender=p,this.lastOutputHeight=i,this.log.sync(p),d&&this.options.stdout.write(U);return}if(l){const d=this.shouldSync();d&&this.options.stdout.write(Y),this.log.clear(),this.options.stdout.write(u),this.log(p),d&&this.options.stdout.write(U)}else(t!==this.lastOutput||this.log.isCursorDirty())&&this.throttledLog(p);this.lastOutput=t,this.lastOutputToRender=p,this.lastOutputHeight=i}initImmediateKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="enabled")return;const i=t.flags??["disambiguateEscapeCodes"];this.options.stdin.isTTY&&this.options.stdout.isTTY&&this.enableKittyProtocol(i)}initDeferredKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="auto")return;const i=t.flags??["disambiguateEscapeCodes"];!this.interactive||!this.options.stdin.isTTY||!this.options.stdout.isTTY||this.confirmKittySupport(i)}confirmKittySupport(t){const{stdin:i,stdout:r}=this.options;let o=[];const u=()=>{this.cancelKittyDetection=void 0,clearTimeout(n),i.removeListener("data",l);const s=Bi(o);o=[],s.length>0&&i.unshift(Ht.from(s))},l=s=>{const a=typeof s=="string"?Ht.from(s):s;for(const p of a)o.push(p);Ai(o)&&(u(),this.isUnmounted||this.enableKittyProtocol(t))};i.on("data",l);const n=setTimeout(u,200);this.cancelKittyDetection=u,r.write("\x1B[?u")}enableKittyProtocol(t){this.options.stdout.write(`\x1B[>${ii(t)}u`),this.kittyProtocolEnabled=!0}}const xr=(e,t)=>{const i={alternateScreen:!1,concurrent:!1,debug:!1,exitOnCtrlC:!0,incrementalRendering:!1,maxFps:30,patchConsole:!0,stderr:k.stderr,stdin:k.stdin,stdout:k.stdout,...Ki(t)},r=Fi(i.stdout,()=>new Ui(i));return r.render(e),{cleanup(){r.unmount()},clear(){r.clear()},rerender(o){r.render(o)},rootNode:r.rootNode,unmount(){r.unmount()},waitUntilExit(){return r.waitUntilExit()},waitUntilRenderFlush(){return r.waitUntilRenderFlush()}}},Ki=(e={})=>e instanceof xe?{stdin:k.stdin,stdout:e}:e,Fi=(e,t)=>{const i=xt.get(e);if(i===void 0){const r=t();return xt.set(e,r),r}return k.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
+ `),i};export{xr as default};
@@ -1,4 +1,4 @@
1
- import{LegacyRoot as p}from"react-reconciler/constants.js";import N from"yoga-layout";import{c as g}from"./dom-rphpG0kf.js";import{j as l}from"./reconciler-DhUGYWCr.js";import{H as i}from"./renderer-COXHo5Xk.js";import{calculateScroll as v}from"./calculateScroll-D4Y_JR4H.js";const L=(f,u)=>{const d=u?.columns??80,e=g("ink-root");let a="";e.onComputeLayout=()=>{e.yogaNode.setWidth(d),e.yogaNode.calculateLayout(void 0,void 0,N.DIRECTION_LTR);const o=t=>{if(t.nodeName==="ink-box"){const n=t.style.overflow??"visible",m=t.style.overflowX??n,y=t.style.overflowY??n;(m==="scroll"||y==="scroll")&&v(t)}for(const n of t.childNodes)n.nodeName!=="#text"&&o(n)};o(e)},e.onImmediateRender=()=>{const{staticOutput:o}=i(e,!1);o&&o!==`
1
+ import{LegacyRoot as p}from"react-reconciler/constants.js";import N from"yoga-layout";import{c as g}from"./dom-rphpG0kf.js";import{j as l}from"./reconciler-CFyBVf7l.js";import{H as i}from"./renderer-COXHo5Xk.js";import{calculateScroll as v}from"./calculateScroll-D4Y_JR4H.js";const L=(f,u)=>{const d=u?.columns??80,e=g("ink-root");let a="";e.onComputeLayout=()=>{e.yogaNode.setWidth(d),e.yogaNode.calculateLayout(void 0,void 0,N.DIRECTION_LTR);const o=t=>{if(t.nodeName==="ink-box"){const n=t.style.overflow??"visible",m=t.style.overflowX??n,y=t.style.overflowY??n;(m==="scroll"||y==="scroll")&&v(t)}for(const n of t.childNodes)n.nodeName!=="#text"&&o(n)};o(e)},e.onImmediateRender=()=>{const{staticOutput:o}=i(e,!1);o&&o!==`
2
2
  `&&(a+=o)};let r;const c=l.createContainer(e,p,null,!1,null,"render-to-string",o=>{r??=o},()=>{},()=>{},()=>{});let s=!1;try{l.updateContainerSync(f,c,null,()=>{}),l.flushSyncWork();const{output:o}=i(e,!1);if(l.updateContainerSync(null,c,null,()=>{}),l.flushSyncWork(),s=!0,e.yogaNode.free(),r!==void 0)throw r instanceof Error?r:new Error(String(r));const t=a.endsWith(`
3
3
  `)?a.slice(0,-1):a;return t&&o?`${t}
4
4
  ${o}`:t||o}finally{if(!s&&e.yogaNode)try{e.yogaNode.freeRecursive()}catch{}}};export{L as default};
@@ -1 +1 @@
1
- import{createRequire as _}from"node:module";import F from"../packem_shared/render-v2x7ZRzT.js";import{createKeySender as x}from"../packem_shared/KEY-C--kOw41.js";import{KEY as K}from"../packem_shared/KEY-C--kOw41.js";import{createScreen as y}from"../packem_shared/createScreen-DoYpyL0V.js";import{waitFor as T}from"../packem_shared/waitFor-CTAki32d.js";const g=_(import.meta.url),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,w=t=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[e,n]=a.versions.node.split(".").map(Number);if(e>22||e===22&&n>=3||e===20&&n>=16)return a.getBuiltinModule(t)}return g(t)},m=w("node:events");class b extends m{columns;_lastFrame;_frames=[];constructor(e=100){super(),this.columns=e}get frames(){return this._frames}lastFrame(){return this._lastFrame}write=e=>(this._frames.push(e),this._lastFrame=e,!0)}class v extends m{columns;_lastFrame;_frames=[];constructor(e=100){super(),this.columns=e}get frames(){return this._frames}lastFrame(){return this._lastFrame}write=e=>(this._frames.push(e),this._lastFrame=e,!0)}class j extends m{isTTY=!0;pendingData;write=e=>(this.pendingData=e,this.emit("readable"),this.emit("data",e),!0);read(){const{pendingData:e}=this;return this.pendingData=void 0,e}setEncoding(){return this}setRawMode(){return this}resume(){return this}pause(){return this}ref(){return this}unref(){return this}}const u=[],P=(t,e={})=>{const{columns:n,options:d}=e,s=new b(n),c=new v(n),o=new j,i=F(t,{debug:!0,exitOnCtrlC:!1,patchConsole:!1,stderr:c,stdin:o,stdout:s,...d});u.push(i);const l=y(()=>s.lastFrame(),s.frames),p=x(r=>o.write(r)),f=async()=>{await new Promise(r=>{setTimeout(r,0)}),await new Promise(r=>{setTimeout(r,0)})};return{cleanup:i.cleanup,flush:f,get frames(){return s.frames},keys:p,lastFrame:()=>s.lastFrame(),rerender:i.rerender,screen:l,stderr:c,stdin:o,stdout:s,unmount:i.unmount,async waitFor(r,h){await T(r,()=>l.text(),h)}}},S=()=>{for(const t of u)t.cleanup();u.length=0};export{K as KEY,S as cleanup,x as createKeySender,y as createScreen,P as render,T as waitFor};
1
+ import{createRequire as _}from"node:module";import F from"../packem_shared/render-DSuj2PjD.js";import{createKeySender as x}from"../packem_shared/KEY-C--kOw41.js";import{KEY as K}from"../packem_shared/KEY-C--kOw41.js";import{createScreen as y}from"../packem_shared/createScreen-DoYpyL0V.js";import{waitFor as T}from"../packem_shared/waitFor-CTAki32d.js";const g=_(import.meta.url),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,w=t=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[e,n]=a.versions.node.split(".").map(Number);if(e>22||e===22&&n>=3||e===20&&n>=16)return a.getBuiltinModule(t)}return g(t)},m=w("node:events");class b extends m{columns;_lastFrame;_frames=[];constructor(e=100){super(),this.columns=e}get frames(){return this._frames}lastFrame(){return this._lastFrame}write=e=>(this._frames.push(e),this._lastFrame=e,!0)}class v extends m{columns;_lastFrame;_frames=[];constructor(e=100){super(),this.columns=e}get frames(){return this._frames}lastFrame(){return this._lastFrame}write=e=>(this._frames.push(e),this._lastFrame=e,!0)}class j extends m{isTTY=!0;pendingData;write=e=>(this.pendingData=e,this.emit("readable"),this.emit("data",e),!0);read(){const{pendingData:e}=this;return this.pendingData=void 0,e}setEncoding(){return this}setRawMode(){return this}resume(){return this}pause(){return this}ref(){return this}unref(){return this}}const u=[],P=(t,e={})=>{const{columns:n,options:d}=e,s=new b(n),c=new v(n),o=new j,i=F(t,{debug:!0,exitOnCtrlC:!1,patchConsole:!1,stderr:c,stdin:o,stdout:s,...d});u.push(i);const l=y(()=>s.lastFrame(),s.frames),p=x(r=>o.write(r)),f=async()=>{await new Promise(r=>{setTimeout(r,0)}),await new Promise(r=>{setTimeout(r,0)})};return{cleanup:i.cleanup,flush:f,get frames(){return s.frames},keys:p,lastFrame:()=>s.lastFrame(),rerender:i.rerender,screen:l,stderr:c,stdin:o,stdout:s,unmount:i.unmount,async waitFor(r,h){await T(r,()=>l.text(),h)}}},S=()=>{for(const t of u)t.cleanup();u.length=0};export{K as KEY,S as cleanup,x as createKeySender,y as createScreen,P as render,T as waitFor};
package/index.js CHANGED
@@ -87,7 +87,7 @@ function requireNative() {
87
87
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
88
88
  ) {
89
89
  throw new Error(
90
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
90
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
91
91
  );
92
92
  }
93
93
  return binding;
@@ -109,7 +109,7 @@ function requireNative() {
109
109
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
110
110
  ) {
111
111
  throw new Error(
112
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
112
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
113
113
  );
114
114
  }
115
115
  return binding;
@@ -136,7 +136,7 @@ function requireNative() {
136
136
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
137
137
  ) {
138
138
  throw new Error(
139
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
139
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
140
140
  );
141
141
  }
142
142
  return binding;
@@ -158,7 +158,7 @@ function requireNative() {
158
158
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
159
159
  ) {
160
160
  throw new Error(
161
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
161
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
162
162
  );
163
163
  }
164
164
  return binding;
@@ -181,7 +181,7 @@ function requireNative() {
181
181
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
182
182
  ) {
183
183
  throw new Error(
184
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
184
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
185
185
  );
186
186
  }
187
187
  return binding;
@@ -203,7 +203,7 @@ function requireNative() {
203
203
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
204
204
  ) {
205
205
  throw new Error(
206
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
206
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
207
207
  );
208
208
  }
209
209
  return binding;
@@ -224,7 +224,7 @@ function requireNative() {
224
224
  const bindingPackageVersion = require("@visulima/tui-binding-darwin-universal/package.json").version;
225
225
  if (bindingPackageVersion !== "1.0.0-alpha.21" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
226
226
  throw new Error(
227
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
227
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
228
228
  );
229
229
  }
230
230
  return binding;
@@ -246,7 +246,7 @@ function requireNative() {
246
246
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
247
247
  ) {
248
248
  throw new Error(
249
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
249
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
250
250
  );
251
251
  }
252
252
  return binding;
@@ -268,7 +268,7 @@ function requireNative() {
268
268
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
269
269
  ) {
270
270
  throw new Error(
271
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
271
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
272
272
  );
273
273
  }
274
274
  return binding;
@@ -294,7 +294,7 @@ function requireNative() {
294
294
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
295
295
  ) {
296
296
  throw new Error(
297
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
297
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
298
298
  );
299
299
  }
300
300
  return binding;
@@ -316,7 +316,7 @@ function requireNative() {
316
316
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
317
317
  ) {
318
318
  throw new Error(
319
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
319
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
320
320
  );
321
321
  }
322
322
  return binding;
@@ -343,7 +343,7 @@ function requireNative() {
343
343
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
344
344
  ) {
345
345
  throw new Error(
346
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
346
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
347
347
  );
348
348
  }
349
349
  return binding;
@@ -365,7 +365,7 @@ function requireNative() {
365
365
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
366
366
  ) {
367
367
  throw new Error(
368
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
368
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
369
369
  );
370
370
  }
371
371
  return binding;
@@ -389,7 +389,7 @@ function requireNative() {
389
389
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
390
390
  ) {
391
391
  throw new Error(
392
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
392
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
393
393
  );
394
394
  }
395
395
  return binding;
@@ -411,7 +411,7 @@ function requireNative() {
411
411
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
412
412
  ) {
413
413
  throw new Error(
414
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
414
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
415
415
  );
416
416
  }
417
417
  return binding;
@@ -435,7 +435,7 @@ function requireNative() {
435
435
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
436
436
  ) {
437
437
  throw new Error(
438
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
438
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
439
439
  );
440
440
  }
441
441
  return binding;
@@ -457,7 +457,7 @@ function requireNative() {
457
457
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
458
458
  ) {
459
459
  throw new Error(
460
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
460
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
461
461
  );
462
462
  }
463
463
  return binding;
@@ -481,7 +481,7 @@ function requireNative() {
481
481
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
482
482
  ) {
483
483
  throw new Error(
484
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
484
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
485
485
  );
486
486
  }
487
487
  return binding;
@@ -503,7 +503,7 @@ function requireNative() {
503
503
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
504
504
  ) {
505
505
  throw new Error(
506
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
506
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
507
507
  );
508
508
  }
509
509
  return binding;
@@ -527,7 +527,7 @@ function requireNative() {
527
527
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
528
528
  ) {
529
529
  throw new Error(
530
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
530
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
531
531
  );
532
532
  }
533
533
  return binding;
@@ -549,7 +549,7 @@ function requireNative() {
549
549
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
550
550
  ) {
551
551
  throw new Error(
552
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
552
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
553
553
  );
554
554
  }
555
555
  return binding;
@@ -572,7 +572,7 @@ function requireNative() {
572
572
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
573
573
  ) {
574
574
  throw new Error(
575
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
575
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
576
576
  );
577
577
  }
578
578
  return binding;
@@ -594,7 +594,7 @@ function requireNative() {
594
594
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
595
595
  ) {
596
596
  throw new Error(
597
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
597
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
598
598
  );
599
599
  }
600
600
  return binding;
@@ -620,7 +620,7 @@ function requireNative() {
620
620
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
621
621
  ) {
622
622
  throw new Error(
623
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
623
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
624
624
  );
625
625
  }
626
626
  return binding;
@@ -642,7 +642,7 @@ function requireNative() {
642
642
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
643
643
  ) {
644
644
  throw new Error(
645
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
645
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
646
646
  );
647
647
  }
648
648
  return binding;
@@ -664,7 +664,7 @@ function requireNative() {
664
664
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
665
665
  ) {
666
666
  throw new Error(
667
- `Native binding package version mismatch, expected 1.0.0-alpha.24 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
667
+ `Native binding package version mismatch, expected 1.0.0-alpha.25 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
668
668
  );
669
669
  }
670
670
  return binding;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/tui",
3
- "version": "1.0.0-alpha.24",
3
+ "version": "1.0.0-alpha.25",
4
4
  "description": "React-based TUI library powered by a native Rust diff engine, drop-in Ink-compatible API",
5
5
  "keywords": [
6
6
  "cli",
@@ -651,14 +651,14 @@
651
651
  }
652
652
  },
653
653
  "optionalDependencies": {
654
- "@visulima/tui-binding-darwin-arm64": "1.0.0-alpha.24",
655
- "@visulima/tui-binding-linux-arm64-gnu": "1.0.0-alpha.24",
656
- "@visulima/tui-binding-darwin-x64": "1.0.0-alpha.24",
657
- "@visulima/tui-binding-linux-arm64-musl": "1.0.0-alpha.24",
658
- "@visulima/tui-binding-linux-x64-gnu": "1.0.0-alpha.24",
659
- "@visulima/tui-binding-linux-x64-musl": "1.0.0-alpha.24",
660
- "@visulima/tui-binding-win32-arm64-msvc": "1.0.0-alpha.24",
661
- "@visulima/tui-binding-win32-x64-msvc": "1.0.0-alpha.24"
654
+ "@visulima/tui-binding-darwin-arm64": "1.0.0-alpha.25",
655
+ "@visulima/tui-binding-linux-arm64-gnu": "1.0.0-alpha.25",
656
+ "@visulima/tui-binding-linux-x64-gnu": "1.0.0-alpha.25",
657
+ "@visulima/tui-binding-darwin-x64": "1.0.0-alpha.25",
658
+ "@visulima/tui-binding-linux-arm64-musl": "1.0.0-alpha.25",
659
+ "@visulima/tui-binding-linux-x64-musl": "1.0.0-alpha.25",
660
+ "@visulima/tui-binding-win32-arm64-msvc": "1.0.0-alpha.25",
661
+ "@visulima/tui-binding-win32-x64-msvc": "1.0.0-alpha.25"
662
662
  },
663
663
  "engines": {
664
664
  "node": "^22.14.0 || >=24.10.0"
@@ -1,24 +0,0 @@
1
- import{createRequire as we}from"node:module";import{jsxs as $,jsx as x}from"react/jsx-runtime";import{cursorShow as nt,setMode as Vt,BracketedPasteMode as Xt,resetMode as Zt,cursorUp as yt,cursorTo as Ct,cursorHide as q,cursorDown as Te,setCursorStyle as Re,eraseLines as j,cursorNextLine as Se,eraseLineEnd as Ee,createDecMode as Oe,ALT_SCREEN_ON as Pe,clearScreenAndHomeCursor as Ne,ALT_SCREEN_OFF as ke}from"@visulima/ansi";import{wordWrap as De}from"@visulima/string";import Jt from"is-in-ci";import Le from"patch-console";import{ConcurrentRoot as Ie,LegacyRoot as $e}from"react-reconciler/constants.js";import{onExit as We}from"signal-exit";import A from"yoga-layout";import{a as Me}from"./accessibility-context-DDyHTwmA.js";import{PureComponent as Ae,useState as ct,useRef as W,useCallback as b,useEffect as vt,useMemo as F}from"react";import{e as Be}from"./animation-context-DW3p-vpk.js";import{t as He}from"./app-context-BVpKlG1z.js";import{o as Ue}from"./cursor-context-CFviBqPX.js";import{parseStacktrace as Ye}from"@visulima/error/stacktrace";import je from"code-excerpt";import{Box as _}from"../components/box.js";import{Text as M}from"../components/text.js";import{o as qe}from"./focus-context-CsT69klR.js";import{t as ze}from"./stderr-context-Bvnik0hL.js";import{e as Ge}from"./stdin-context-88AhuztD.js";import{t as Ve}from"./stdout-context-BnblEPez.js";import{I as Xe,v as Ze,r as Je,H as Qe}from"./renderer-COXHo5Xk.js";import{c as ti,e as ei}from"./dom-rphpG0kf.js";import{resolveFlags as ii}from"./kittyFlags-g8ALyoCU.js";import{p as ri}from"./load-native-root-binding-DDikxNox.js";import{a as oi}from"./measure-text-B7juNq4Y.js";import{j as D,c as si}from"./reconciler-DhUGYWCr.js";import{measureAndExtractObservers as ni}from"./ResizeObserver-aX8XOr2u.js";import{calculateScroll as ui}from"./calculateScroll-D4Y_JR4H.js";import{g as X}from"./utils-Bup8lyK8.js";const be=we(import.meta.url),Q=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,st=e=>{if(typeof Q<"u"&&Q.versions&&Q.versions.node){const[t,i]=Q.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return Q.getBuiltinModule(e)}return be(e)},L=Q,{cwd:ye}=L,{Stream:xe}=st("node:stream"),{Buffer:Ht}=st("node:buffer"),{Console:Ce}=st("node:console"),{EventEmitter:_e}=st("node:events"),{existsSync:Ke,readFileSync:Fe}=st("node:fs"),Qt="\x1B[200~",Ut="\x1B[201~",ai=e=>e>=48&&e<=63,li=e=>e>=32&&e<=47,te=e=>e>=64&&e<=126,di=(e,t,i)=>{const r=t+i+1;let s=r;for(;s<e.length;s++){const a=e.codePointAt(s);if(a===void 0)return"pending";if(!(ai(a)||li(a))&&!(a===91&&s===r))return te(a)?{nextIndex:s+1,sequence:e.slice(t,s+1)}:void 0}return"pending"},ci=(e,t,i)=>{const r=t+i+2;if(r>e.length)return"pending";const s=e.codePointAt(r-1);if(!(s===void 0||!te(s)))return{nextIndex:r,sequence:e.slice(t,r)}},Kt=(e,t,i)=>{const r=e[t+i];if(r===void 0)return"pending";if(r==="[")return di(e,t,i);if(r==="O")return ci(e,t,i)},hi=(e,t)=>{const i=e.codePointAt(t+1),r=i!==void 0&&i>65535?2:1,s=t+1+r;return{nextIndex:s,sequence:e.slice(t,s)}},fi=(e,t)=>{if(t===e.length-1)return"pending";if(e[t+1]==="\x1B"){if(t+2>=e.length)return"pending";const r=Kt(e,t,2);return r==="pending"?"pending":r||{nextIndex:t+2,sequence:e.slice(t,t+2)}}const i=Kt(e,t,1);return i==="pending"?"pending":i||hi(e,t)},Ft=(e,t)=>{let i=0;for(let r=0;r<e.length;r++){const s=e[r];(s===""||s==="\b")&&(r>i&&t.push(e.slice(i,r)),t.push(s),i=r+1)}i<e.length&&t.push(e.slice(i))},pi=e=>{const t=[];let i=0;const r=s=>({events:t,pending:e.slice(s)});for(;i<e.length;){const s=e.indexOf("\x1B",i);if(s===-1)return Ft(e.slice(i),t),{events:t,pending:""};s>i&&Ft(e.slice(i,s),t);const a=fi(e,s);if(a==="pending")return r(s);if(a.sequence===Qt){const l=a.nextIndex,n=e.indexOf(Ut,l);if(n===-1)return r(s);t.push({paste:e.slice(l,n)}),i=n+Ut.length;continue}t.push(a.sequence),i=a.nextIndex}return{events:t,pending:""}},mi=()=>{let e="";return{flushPendingEscape(){if(!e.startsWith("\x1B"))return;const t=e;return e="",t},hasPendingEscape(){return e.startsWith("\x1B")&&!e.startsWith(Qt)&&e!=="\x1B[200"},push(t){const i=pi(e+t);return e=i.pending,i.events},reset(){e=""}}},wt=e=>{if(!e)return e;const t=ye();return e.replace(`file://${t}/`,"").replace(`${t}/`,"")};function gi({error:e}){const t=Ye(e),i=new Map,r=t.map(o=>{const u=!o.methodName&&!o.file?`raw:${o.raw}`:`${wt(o.file)??""}:${o.line}:${o.column}:${o.methodName??""}`,m=i.get(u)??0;return i.set(u,m+1),{key:`${u}#${m}`,trace:o}}),s=t[0],a=wt(s?.file);let l,n=0;if(a&&s?.line&&Ke(a)){const o=Fe(a,"utf8");if(l=je(o,s.line),l)for(const{line:u}of l)n=Math.max(n,String(u).length)}return $(_,{flexDirection:"column",padding:1,children:[$(_,{children:[$(M,{backgroundColor:"red",color:"white",children:[" ","ERROR"," "]}),$(M,{children:[" ",e.message]})]}),s&&a?x(_,{marginTop:1,children:$(M,{dimColor:!0,children:[a,":",s.line,":",s.column]})}):null,s&&l?x(_,{flexDirection:"column",marginTop:1,children:l.map(({line:o,value:u})=>$(_,{children:[x(_,{width:n+1,children:$(M,{"aria-label":o===s.line?`Line ${o}, error`:`Line ${o}`,backgroundColor:o===s.line?"red":void 0,color:o===s.line?"white":void 0,dimColor:o!==s.line,children:[String(o).padStart(n," "),":"]})}),x(M,{backgroundColor:o===s.line?"red":void 0,color:o===s.line?"white":void 0,children:` ${u}`})]},`excerpt-${o}`))}):null,t.length>0?x(_,{flexDirection:"column",marginTop:1,children:r.map(({key:o,trace:u})=>{const m=wt(u.file)??"";return!u.methodName&&!u.file?$(_,{children:[x(M,{dimColor:!0,children:"- "}),x(M,{bold:!0,dimColor:!0,children:u.raw})]},o):$(_,{children:[x(M,{dimColor:!0,children:"- "}),x(M,{bold:!0,dimColor:!0,children:u.methodName??"<anonymous>"}),$(M,{"aria-label":`at ${m} line ${u.line} column ${u.column}`,color:"gray",dimColor:!0,children:[" ","(",m,":",u.line,":",u.column,")"]})]},o)})}):null]})}class vi extends Ae{static displayName="InternalErrorBoundary";static getDerivedStateFromError(t){return{error:t}}state={error:void 0};componentDidCatch(t){this.props.onError(t)}render(){return this.state.error?x(gi,{error:this.state.error}):this.props.children}}const wi=" ",bi="\x1B[Z",yi="\x1B",xi=Vt(Xt),Yt=Zt(Xt),ee=({children:e,exitOnCtrlC:t,interactive:i,onExit:r,onWaitUntilRenderFlush:s,renderThrottleMs:a,setCursorPosition:l,stderr:n,stdin:o,stdout:u,writeToStderr:m,writeToStdout:y})=>{const[g,c]=ct(!0),[h,v]=ct(void 0),[,w]=ct([]),P=W(0),T=W(new Map),k=W(void 0),N=W(0),I=W(!1),E=W(0),[S]=ct(()=>{const d=new _e;return d.setMaxListeners(1/0),d}),K=W(void 0),R=W(void 0);R.current??=mi();const B=W(void 0),Tt=W(!1),ae=20,z=b(()=>{B.current&&(clearTimeout(B.current),B.current=void 0)},[]),G=b(()=>{k.current&&(clearTimeout(k.current),k.current=void 0)},[]),ut=b(()=>{if(G(),T.current.size===0)return;let d=Number.POSITIVE_INFINITY;for(const f of T.current.values())d=Math.min(d,f.nextDueTime);const p=Math.max(0,d-performance.now());k.current=setTimeout(()=>{k.current=void 0;const f=performance.now(),C=[...T.current.values()];for(const O of C){if(f<O.nextDueTime)continue;O.callback(f);const ge=f-O.startTime,ve=Math.floor(ge/O.interval)+1;O.nextDueTime=O.startTime+ve*O.interval}ut()},p)},[G]),Rt=b((d,p)=>{const f=performance.now();return T.current.set(d,{callback:d,interval:p,nextDueTime:f+p,startTime:f}),ut(),{startTime:f,unsubscribe(){if(T.current.delete(d),T.current.size===0){G();return}ut()}}},[G,ut]);vt(()=>()=>{G()},[G]);const H=o.isTTY,St=b(()=>{K.current&&(o.removeListener("readable",K.current),K.current=void 0)},[o]),at=b(()=>{R.current?.reset(),z(),St()},[z,St]),V=b(()=>{I.current=!1,o.setRawMode(!1),o.unref(),N.current=0,at()},[o,at]),et=b(d=>{H&&(N.current>0||I.current)&&V(),r(d)},[H,V,r]),Et=b(d=>{if(d.includes("")&&t){et();return}d===yi&&g&&v(p=>{if(!p)return p})},[t,et,g]),it=b(d=>{Et(d),S.emit("input",d)},[Et,S]),Ot=b(()=>{z(),B.current=setTimeout(()=>{B.current=void 0;const d=R.current.flushPendingEscape();d&&it(d)},ae)},[z,it]),gt=b(()=>{z();let d;for(;(d=o.read())!==null;){const p=R.current.push(d);for(const f of p)if(typeof f=="string")it(f);else{if(S.listenerCount("paste")===0){Tt.current||(Tt.current=!0,m(`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
- `)),it(f.paste);continue}S.emit("paste",f.paste)}}R.current.hasPendingEscape()&&Ot()},[o,it,z,Ot,m,S]),Pt=b(()=>{K.current||(K.current=gt,o.addListener("readable",gt))},[o,gt]),Nt=b(d=>{if(!H)throw o===L.stdin?new Error(`Raw mode is not supported on the current process.stdin, which Ink uses as input stream by default.
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(o.setEncoding("utf8"),d){if(N.current===0){const p=I.current;I.current=!1,p||(o.ref(),o.setRawMode(!0)),Pt()}N.current++;return}N.current!==0&&--N.current===0&&(at(),I.current=!0,queueMicrotask(()=>{I.current&&V()}))},[H,o,Pt,at,V]),kt=b(d=>{if(u.isTTY){if(d){E.current===0&&u.write(xi),E.current++;return}E.current!==0&&--E.current===0&&u.write(Yt)}},[u]),Dt=b((d,p)=>{const f=d.findIndex(C=>C.id===p);for(let C=f+1;C<d.length;C++){const O=d[C];if(O?.isActive)return O.id}},[]),Lt=b((d,p)=>{const f=d.findIndex(C=>C.id===p);for(let C=f-1;C>=0;C--){const O=d[C];if(O?.isActive)return O.id}},[]),lt=b(()=>{w(d=>(v(p=>{const f=d.find(C=>C.isActive)?.id;return Dt(d,p)??f}),d))},[Dt]),dt=b(()=>{w(d=>(v(p=>{const f=d.findLast(C=>C.isActive)?.id;return Lt(d,p)??f}),d))},[Lt]);vt(()=>{const d=f=>{!g||P.current===0||(f===wi&&lt(),f===bi&&dt())};S.on("input",d);const p=S;return()=>{p.off("input",d)}},[g,lt,dt,S]);const It=b(()=>{c(!0)},[]),$t=b(()=>{c(!1)},[]),Wt=b(d=>{w(p=>(p.some(f=>f?.id===d)&&v(d),p))},[]),Mt=b((d,{autoFocus:p})=>{w(f=>(P.current=f.length+1,[...f,{id:d,isActive:!0}])),p&&v(f=>f||d)},[]),_t=b(d=>{v(p=>{if(p!==d)return p}),w(p=>{const f=p.filter(C=>C.id!==d);return P.current=f.length,f})},[]),At=b(d=>{w(p=>p.map(f=>f.id!==d?f:{id:d,isActive:!0}))},[]),Bt=b(d=>{v(p=>{if(p!==d)return p}),w(p=>p.map(f=>f.id!==d?f:{id:d,isActive:!1}))},[]);vt(()=>()=>{const d=!u.destroyed&&!u.writableEnded;i&&d&&u.write(nt),H&&(N.current>0||I.current)&&V(),E.current>0&&(u.isTTY&&d&&u.write(Yt),E.current=0)},[u,H,V,i]);const le=F(()=>({exit:et,waitUntilRenderFlush:s}),[et,s]),de=F(()=>({internal_eventEmitter:S,internal_exitOnCtrlC:t,isRawModeSupported:H,setBracketedPasteMode:kt,setRawMode:Nt,stdin:o}),[o,Nt,kt,H,t,S]),ce=F(()=>({stdout:u,write:y}),[u,y]),he=F(()=>({stderr:n,write:m}),[n,m]),fe=F(()=>({setCursorPosition:l}),[l]),pe=F(()=>({activate:At,activeId:h,add:Mt,deactivate:Bt,disableFocus:$t,enableFocus:It,focus:Wt,focusNext:lt,focusPrevious:dt,remove:_t}),[h,Mt,_t,At,Bt,It,$t,lt,dt,Wt]),me=F(()=>({renderThrottleMs:a,subscribe:Rt}),[Rt,a]);return x(He.Provider,{value:le,children:x(Ge.Provider,{value:de,children:x(Ve.Provider,{value:ce,children:x(ze.Provider,{value:he,children:x(qe.Provider,{value:pe,children:x(Be.Provider,{value:me,children:x(Ue.Provider,{value:fe,children:x(vi,{onError:et,children:e})})})})})})})})};ee.displayName="InternalApp";const Ci=(e,t,i)=>{if(i<=0||!e.yogaNode)return"";const{yogaNode:r}=e,s=r.getComputedBorder(A.EDGE_LEFT),a=r.getComputedBorder(A.EDGE_RIGHT),l=r.getComputedBorder(A.EDGE_TOP),n=r.getComputedPadding(A.EDGE_LEFT),o=r.getComputedPadding(A.EDGE_RIGHT),u=r.getComputedPadding(A.EDGE_TOP),m=Math.round(r.getComputedWidth()-s-a-n-o);if(m<=0)return"";const y=new Xe({height:i,width:m}),g=-(e.internal_scrollState?.scrollLeft??0)-s-n,c=-t-l-u;for(const h of e.childNodes)Ze(h,y,{absoluteOffsetX:g,absoluteOffsetY:c,offsetX:g,offsetY:c,skipStaticElements:!1});return y.get().output},xt=new WeakMap,Ti={bar:6,"blinking-bar":5,"blinking-block":1,"blinking-underline":3,block:2,default:0,underline:4},jt=e=>Re(Ti[e]),ft=(e,t)=>e?.x!==t?.x||e?.y!==t?.y,tt=(e,t)=>{if(!t)return"";const i=e-t.y;return(i>0?yt(i):"")+Ct(t.x)+nt},ie=(e,t)=>{if(!t)return"";const i=e-1-t.y;return(i>0?Te(i):"")+Ct(0)},re=e=>{const t=e.cursorWasShown?q:"",i=ie(e.previousLineCount,e.previousCursorPosition),r=tt(e.visibleLineCount,e.cursorPosition);return t+i+r},pt=(e,t,i)=>e?q+ie(t,i):"",Z=e=>e??"default",oe=()=>{let e,t;return{consumeDelta:()=>{if(Z(t)===Z(e))return"";const i=Z(t);return e=t,jt(i)},consumeRestoreOnDone:()=>{const i=Z(e)!=="default";return e=void 0,t=void 0,i?jt("default"):""},isDirty:()=>Z(t)!==Z(e),setPending:i=>{t=i}}},ot=(e,t)=>t.endsWith(`
5
- `)?e.length-1:e.length,se=e=>e.rows||1/0,mt=(e,t)=>Math.min(e,se(t)),Ri=(e,{showCursor:t=!1}={})=>{let i=0,r="",s=!1,a,l=!1,n,o=!1;const u=oe(),m=()=>l?a:void 0,y=(c,h)=>{const v=ft(h,n);return c!==r||v||u.isDirty()},g=c=>{!t&&!s&&(e.write(q),s=!0);const h=m();l=!1;const v=ft(h,n);if(!y(c,h))return!1;const w=u.consumeDelta(),P=c.split(`
6
- `),T=ot(P,c),k=tt(T,h);if(c===r&&v)e.write(w+re({cursorPosition:h,cursorWasShown:o,previousCursorPosition:n,previousLineCount:i,visibleLineCount:T}));else if(c===r&&w!=="")e.write(w);else{r=c;const N=pt(o,i,n);e.write(w+N+j(mt(i,e))+c+k),i=P.length}return n=h?{...h}:void 0,o=h!==void 0,!0};return g.clear=()=>{const c=pt(o,i,n);e.write(c+j(mt(i,e))),r="",i=0,n=void 0,o=!1},g.done=()=>{r="",i=0,n=void 0,o=!1;const c=u.consumeRestoreOnDone();c!==""&&e.write(c),t||(e.write(nt),s=!1)},g.reset=()=>{r="",i=0,n=void 0,o=!1},g.sync=c=>{const h=l?a:void 0;l=!1;const v=c.split(`
7
- `);r=c,i=v.length;const w=u.consumeDelta();w!==""&&e.write(w),!h&&o&&e.write(q),h&&e.write(tt(ot(v,c),h)),n=h?{...h}:void 0,o=h!==void 0},g.setCursorPosition=c=>{a=c,l=!0},g.setCursorShape=u.setPending,g.isCursorDirty=()=>l||u.isDirty(),g.willRender=c=>y(c,m()),g},Si=(e,{showCursor:t=!1}={})=>{let i=[],r="",s=!1,a,l=!1,n,o=!1;const u=oe(),m=()=>l?a:void 0,y=(c,h)=>{const v=ft(h,n);return c!==r||v||u.isDirty()},g=c=>{!t&&!s&&(e.write(q),s=!0);const h=m();l=!1;const v=ft(h,n);if(!y(c,h))return!1;const w=u.consumeDelta(),P=c.split(`
8
- `),T=ot(P,c),k=ot(i,r);if(c===r&&v)return e.write(w+re({cursorPosition:h,cursorWasShown:o,previousCursorPosition:n,previousLineCount:i.length,visibleLineCount:T})),n=h?{...h}:void 0,o=h!==void 0,!0;if(c===r&&w!=="")return e.write(w),!0;const N=pt(o,i.length,n);if(c===`
9
- `||r.length===0){const R=tt(T,h);return e.write(w+N+j(mt(i.length,e))+c+R),o=h!==void 0,n=h?{...h}:void 0,r=c,i=P,!0}const I=c.endsWith(`
10
- `),E=[w,N],S=se(e);if(T<k){const R=r.endsWith(`
11
- `)?1:0;E.push(j(Math.min(k-T+R,S)),yt(Math.min(T,S-1)))}else E.push(yt(Math.min(k-1,S-1)));for(let R=0;R<T;R++){const B=R===T-1;if(P[R]===i[R]){(!B||I)&&E.push(Se());continue}E.push(Ct(0)+P[R]+Ee+(B&&!I?"":`
12
- `))}const K=tt(T,h);return E.push(K),e.write(E.join("")),o=h!==void 0,n=h?{...h}:void 0,r=c,i=P,!0};return g.clear=()=>{const c=pt(o,i.length,n);e.write(c+j(mt(i.length,e))),r="",i=[],n=void 0,o=!1},g.done=()=>{r="",i=[],n=void 0,o=!1;const c=u.consumeRestoreOnDone();c!==""&&e.write(c),t||(e.write(nt),s=!1)},g.reset=()=>{r="",i=[],n=void 0,o=!1},g.sync=c=>{const h=l?a:void 0;l=!1;const v=c.split(`
13
- `);r=c,i=v;const w=u.consumeDelta();w!==""&&e.write(w),!h&&o&&e.write(q),h&&e.write(tt(ot(v,c),h)),n=h?{...h}:void 0,o=h!==void 0},g.setCursorPosition=c=>{a=c,l=!0},g.setCursorShape=u.setPending,g.isCursorDirty=()=>l||u.isDirty(),g.willRender=c=>y(c,m()),g},Ei=(e,{incremental:t=!1,showCursor:i=!1}={})=>t?Si(e,{showCursor:i}):Ri(e,{showCursor:i}),Oi={create:Ei},ne=Oe(2026),Y=Vt(ne),U=Zt(ne);function Pi(e,t){return"isTTY"in e&&e.isTTY&&(t??!Jt)}let J;const Ni=()=>{if(J!==!1){if(J!==void 0)return J;try{return J=ri(import.meta.url).Renderer,J}catch{J=!1;return}}},ki=e=>{const t=Ni();if(!t)return;let i,r=0,s=0;const a=(l,n)=>{(!i||r!==l||s!==n)&&(i?i.resize(l,n):i=new t(l,n),r=l,s=n)};return{clear(){if(i){const l=new Uint32Array(r*s*2),n=65535;for(let o=0;o<l.length;o+=2)l[o]=32,l[o+1]=n;i.render(l)}},destroy(){i=void 0},render(l,n,o){if(a(n,o),!!i){e.isTTY&&i.writeRaw(Y);try{i.render(l)}finally{e.isTTY&&i.writeRaw(U)}}},resize(l,n){a(l,n)}}};function qt(e,t=0,i={}){const r=i.leading??!0,s=i.trailing??!0;let a,l,n,o;const u=()=>{if(l===void 0)return;const h=l;l=void 0,o=e(...h)},m=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},y=()=>{a=void 0,s&&u(),l=void 0,n=void 0},g=()=>{m(),a=setTimeout(y,t)},c=function(...h){const v=Date.now();if(n??=v,v-n>=t)return l=h,u(),n=v,g(),o;l=h;const w=a===void 0;return g(),r&&w&&u(),o};return c.cancel=()=>{m(),l=void 0,n=void 0},c.flush=()=>(m(),u(),n=void 0,o),c}console.Console||(console.Console=Ce);const rt=()=>{},zt=async()=>new Promise(e=>{setImmediate(e)}),Di=27,Li=91,Ii=63,$i=117,Wi=48,Mi=57,_i=e=>e>=Wi&&e<=Mi,ue=(e,t)=>{if(e[t]!==Di||e[t+1]!==Li||e[t+2]!==Ii)return;let i=t+3;const r=i;for(;i<e.length&&_i(e[i]);)i++;if(i!==r){if(i===e.length)return{state:"partial"};if(e[i]===$i)return{endIndex:i,state:"complete"}}},Ai=e=>{for(let t=0;t<e.length;t++)if(ue(e,t)?.state==="complete")return!0;return!1},Bi=e=>{const t=[];let i=0;for(;i<e.length;){const r=ue(e,i);if(r?.state==="complete"){i=r.endIndex+1;continue}if(r?.state==="partial")break;t.push(e[i]),i++}return t},Hi=({isTty:e,isUnmounting:t,nextOutputHeight:i,previousOutputHeight:r,viewportRows:s})=>{if(!e)return!1;const a=r>0,l=r>=s,n=r>s,o=i>s,u=l&&i<s;return n||o&&a||u||t&&l},bt=e=>e instanceof Error||Object.prototype.toString.call(e)==="[object Error]",Gt=e=>{const t=!e.destroyed&&!e.writableEnded&&(e.writable??!0),i=e._writableState!==void 0||e.writableLength!==void 0;return{canWriteToStdout:t,hasWritableState:i}},ht=(e,t)=>{if(!e||typeof e.flush!="function")return;const i=e;t?i.flush():typeof i.cancel=="function"&&i.cancel()};class Ui{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;cancelKittyDetection;nextRenderCommit;deferredInitDone=!1;constructor(t){this.options=t,this.rootNode=ti("ink-root"),this.rootNode.onComputeLayout=this.calculateLayout,this.isScreenReaderEnabled=t.isScreenReaderEnabled??L.env.INK_SCREEN_READER==="true",this.interactive=this.resolveInteractiveOption(t.interactive),this.alternateScreen=!1;const i=t.debug||this.isScreenReaderEnabled,r=t.maxFps??30,s=r>0?Math.max(1,Math.ceil(1e3/r)):0;this.renderThrottleMs=i?0:s;const a=i?this.onRender:(()=>{const n=qt(this.onRender,s,{leading:!0,trailing:!0});return this.throttledOnRender=n,()=>{this.hasPendingThrottledRender=!0,n()}})();if(i&&(this.throttledOnRender=void 0),t.standardReactLayoutTiming){let n=!1;const o=()=>{n||(n=!0,queueMicrotask(()=>{n=!1,this.onRender()}))};this.rootNode.onRender=o,this.rootNode.onImmediateRender=o}else this.rootNode.onRender=a,this.rootNode.onImmediateRender=this.onRender;this.rootNode.onStaticChange=this.handleStaticChange,this.log=Oi.create(t.stdout,{incremental:t.incrementalRendering}),this.useNativeRenderer=t.useNativeRenderer??!1,this.useNativeRenderer&&(this.nativeLog=ki(t.stdout),this.nativeLog||(this.useNativeRenderer=!1)),this.manualCursorPosition=void 0,this.renderedCursorPosition=void 0,this.renderedCursorRequested=!1,this.throttledLog=i?this.log:qt(n=>{const o=this.log.willRender(n),u=this.shouldSync();u&&o&&this.options.stdout.write(Y),this.log(n),u&&o&&this.options.stdout.write(U)},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=X(this.options.stdout).columns,this.fullStaticOutput="";const l=t.concurrent?Ie:$e;this.container=D.createContainer(this.rootNode,l,null,!1,null,"id",()=>{},()=>{},()=>{},()=>{}),this.unsubscribeExit=We(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(),L.env.DEV==="true"&&D.injectIntoDevTools(),this.exitPromise=new Promise((n,o)=>{this.resolveExitPromise=n,this.rejectExitPromise=o}),this.exitPromise.catch(rt)}runDeferredInit(){this.deferredInitDone||(this.deferredInitDone=!0,this.initDeferredKittyKeyboard())}resized=()=>{const t=X(this.options.stdout).columns;t<this.lastTerminalWidth&&(this.log.clear(),this.lastOutput="",this.lastOutputToRender=""),oi(),this.calculateLayout(),ei(this.rootNode),this.onRender(),this.lastTerminalWidth=t};resolveExitPromise=()=>{};rejectExitPromise=()=>{};unsubscribeExit=()=>{};handleAppExit=t=>{if(!(this.isUnmounted||this.isUnmounting)){if(bt(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=r=>{const s=new Map;this.calculateScrollAndTriggerObservers(r,s);for(const[a,l]of s)a.internalTrigger(l)};this.backbufferNode=void 0,this.prepareYogaTree(this.rootNode,t);const i=X(this.options.stdout).columns;this.rootNode.yogaNode.setWidth(i),this.rootNode.yogaNode.calculateLayout(void 0,void 0,A.DIRECTION_LTR),t(this.rootNode)};calculateScrollAndTriggerObservers(t,i){if(t.nodeName==="ink-box"){const{style:r}=t,s=r.overflow??"visible",a=r.overflowX??s,l=r.overflowY??s;a==="scroll"||l==="scroll"?(ui(t),r.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(ni(t,i),!t.internal_static)for(const r of t.childNodes)r.nodeName!=="#text"&&this.calculateScrollAndTriggerObservers(r,i)}recalculateLayout(){this.markAllTextNodesDirty(this.rootNode),this.calculateLayout(),this.onRender()}prepareYogaTree(t,i){if(t.isYogaTreeDetached&&!t.cachedRender&&t.yogaNode){for(t.yogaNode.setWidthAuto(),t.yogaNode.setHeightAuto(),si(t.yogaNode,t.style);t.yogaNode.getChildCount()>0;)t.yogaNode.getChild(0).remove();let r=0;for(const s of t.childNodes){const a=s;s.nodeName!=="#text"&&a.yogaNode&&(t.yogaNode.insertChild(a.yogaNode,r),r++)}t.isYogaTreeDetached=!1,this.markAllTextNodesDirty(t)}for(const r of t.childNodes)r.nodeName!=="#text"&&this.prepareYogaTree(r,i);if(t.nodeName==="ink-static-render"&&!t.cachedRender){const r=X(this.options.stdout).columns,{width:s}=t.style;t.yogaNode&&(t.yogaNode.setWidth(typeof s=="number"?s:r),t.yogaNode.calculateLayout(void 0,void 0,A.DIRECTION_LTR)),i(t),Je(t,{skipStaticElements:!1}),t.internal_onRendered?.()}}markAllTextNodesDirty(t){if(!t.cachedRender){t.nodeName==="ink-text"&&t.yogaNode&&t.yogaNode.markDirty();for(const i of t.childNodes)i.nodeName!=="#text"&&this.markAllTextNodesDirty(i)}}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 i=Math.round(t.internal_scrollState.scrollTop),r=t.yogaNode?.getComputedPadding(A.EDGE_TOP)??0,s=Math.max(0,i-Math.round(r)),a=t.internal_maxPushedScrollTop??0,{maxScrollbackLength:l}=t.style,n=l===void 0?a:Math.max(a,s-Math.max(0,l)),o=s-n;if(o<=0)return"";const u=Ci(t,n,o);return u===""?"":(t.internal_maxPushedScrollTop=s,`${u}\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=Qe(this.rootNode,this.isScreenReaderEnabled,{useNativeRenderer:this.useNativeRenderer}),{cursorPosition:i,cursorRequested:r,cursorShape:s,output:a,outputBuffer:l,outputHeight:n,outputWidth:o,staticOutput:u}=t;this.renderedCursorRequested=r,this.renderedCursorPosition=i,this.log.setCursorShape(r?s:void 0);const m=this.computeBackbufferOutput();if(this.useNativeRenderer&&this.nativeLog&&l&&o){u&&u!==`
16
- `&&this.options.stdout.write(u),m&&this.options.stdout.write(m),this.nativeLog.render(l,o,n),this.lastOutputHeight=n;return}r&&this.log.setCursorPosition(this.getActiveCursorPosition());const y=u&&u!==`
17
- `;if(this.options.debug){y&&(this.fullStaticOutput+=u),this.lastOutput=a,this.lastOutputToRender=a,this.lastOutputHeight=n,this.options.stdout.write(this.fullStaticOutput+a);return}if(!this.interactive){y&&this.options.stdout.write(u),this.lastOutput=a,this.lastOutputToRender=`${a}
18
- `,this.lastOutputHeight=n;return}if(this.isScreenReaderEnabled){const g=this.shouldSync();if(g&&this.options.stdout.write(Y),y){const v=this.lastOutputHeight>0?j(this.lastOutputHeight):"";this.options.stdout.write(v+u),this.lastOutputHeight=0}if(a===this.lastOutput&&!y){g&&this.options.stdout.write(U);return}const c=X(this.options.stdout).columns,h=De(a,{trim:!1,width:c,wrapMode:"BREAK_WORDS"}).replace(/\n$/,"");if(y)this.options.stdout.write(h);else{const v=this.lastOutputHeight>0?j(this.lastOutputHeight):"";this.options.stdout.write(v+h)}this.lastOutput=a,this.lastOutputToRender=h,this.lastOutputHeight=h===""?0:h.split(`
19
- `).length,g&&this.options.stdout.write(U);return}y&&(this.fullStaticOutput+=u),this.renderInteractiveFrame(a,n,y?u:"",m)};accessibilityContextValue;render(t){this.accessibilityContextValue??={isScreenReaderEnabled:this.isScreenReaderEnabled};const i=x(Me.Provider,{value:this.accessibilityContextValue,children:x(ee,{exitOnCtrlC:this.options.exitOnCtrlC,interactive:this.interactive,onExit:this.handleAppExit,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?D.updateContainer(i,this.container,null,rt):(D.updateContainerSync(i,this.container,null,rt),D.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 i=this.shouldSync();i&&this.options.stdout.write(Y),this.log.clear(),this.options.stdout.write(t),this.restoreLastOutput(),i&&this.options.stdout.write(U)};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 i=this.shouldSync();i&&this.options.stdout.write(Y),this.log.clear(),this.options.stderr.write(t),this.restoreLastOutput(),i&&this.options.stdout.write(U)};unmount=t=>{if(this.isUnmounted||this.isUnmounting)return;this.isUnmounting=!0,this.beforeExitHandler&&(L.off("beforeExit",this.beforeExitHandler),this.beforeExitHandler=void 0);const i=this.options.stdout,{canWriteToStdout:r,hasWritableState:s}=Gt(i);ht(this.throttledOnRender,r),r&&!this.alternateScreen&&(!this.throttledOnRender||!this.hasPendingThrottledRender&&this.fullStaticOutput==="")&&(this.calculateLayout(),this.onRender()),this.isUnmounted=!0,this.unsubscribeExit(),ht(this.throttledLog,r),typeof this.restoreConsole=="function"&&this.restoreConsole();const a=()=>{typeof this.unsubscribeResize=="function"&&this.unsubscribeResize(),this.cancelKittyDetection&&this.cancelKittyDetection(),r&&(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,ke),this.writeBestEffort(this.options.stdout,nt),this.alternateScreen=!1):this.interactive?this.options.debug||this.log.done():this.options.stdout.write(this.options.debug?`
20
- `:`${this.lastOutput}
21
- `)),this.kittyProtocolEnabled=!1,xt.delete(this.options.stdout);const{exitResult:n}=this,o=()=>{bt(t)?this.rejectExitPromise(t):this.resolveExitPromise(n)};t!==void 0&&!bt(t)?o():r&&s?this.options.stdout.write("",o):setImmediate(o)},l=D;this.options.concurrent?(D.updateContainerSync(null,this.container,null,rt),D.flushSyncWork(),l.flushPassiveEffects?.(),a()):(D.updateContainerSync(null,this.container,null,rt),D.flushSyncWork(),a())};async waitUntilExit(){return this.beforeExitHandler||(this.beforeExitHandler=()=>{this.unmount()},L.on("beforeExit",this.beforeExitHandler)),this.exitPromise}async waitUntilRenderFlush(){if(this.isUnmounted||this.isUnmounting){await this.awaitExit();return}if(await zt(),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}D.flushSyncWork();const t=this.options.stdout,{canWriteToStdout:i,hasWritableState:r}=Gt(t);if(ht(this.throttledOnRender,i),ht(this.throttledLog,i),i&&r){await new Promise(s=>{this.options.stdout.write("",()=>{s()})});return}await zt()}clear(){this.interactive&&!this.options.debug&&(this.log.clear(),this.log.sync(this.lastOutputToRender||`${this.lastOutput}
22
- `))}patchConsole(){this.options.debug||(this.restoreConsole=Le((t,i)=>{t==="stdout"&&this.writeToStdout(i),t==="stderr"&&(i.startsWith("The above error occurred")||this.writeToStderr(i))}))}setAlternateScreen(t){this.alternateScreen=this.resolveAlternateScreenOption(t,this.interactive),this.alternateScreen&&(this.writeBestEffort(this.options.stdout,Pe),this.writeBestEffort(this.options.stdout,q))}resolveInteractiveOption(t){return t??(!Jt&&!!this.options.stdout.isTTY)}resolveAlternateScreenOption(t,i){return!!t&&i&&!!this.options.stdout.isTTY}shouldSync(){return Pi(this.options.stdout,this.interactive)}writeBestEffort(t,i){try{t.write(i)}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 i=new Promise(r=>{t=r});this.nextRenderCommit={promise:i,resolve:t}}return this.nextRenderCommit.promise}renderInteractiveFrame(t,i,r,s=""){const a=r+s,l=a!=="",n=this.options.stdout.isTTY,o=n?X(this.options.stdout).rows:24,u=n&&i>=o?t:`${t}
23
- `;if(Hi({isTty:n,isUnmounting:this.isUnmounting,nextOutputHeight:i,previousOutputHeight:this.lastOutputHeight,viewportRows:o})){if(this.options.incrementalRendering){l&&(this.log.clear(),this.options.stdout.write(a)),(t!==this.lastOutput||this.log.isCursorDirty()||l)&&this.throttledLog(u),this.lastOutput=t,this.lastOutputToRender=u,this.lastOutputHeight=i;return}const m=this.shouldSync();m&&this.options.stdout.write(Y),this.options.stdout.write(Ne+this.fullStaticOutput+s+t),this.lastOutput=t,this.lastOutputToRender=u,this.lastOutputHeight=i,this.log.sync(u),m&&this.options.stdout.write(U);return}if(l){const m=this.shouldSync();m&&this.options.stdout.write(Y),this.log.clear(),this.options.stdout.write(a),this.log(u),m&&this.options.stdout.write(U)}else(t!==this.lastOutput||this.log.isCursorDirty())&&this.throttledLog(u);this.lastOutput=t,this.lastOutputToRender=u,this.lastOutputHeight=i}initImmediateKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="enabled")return;const i=t.flags??["disambiguateEscapeCodes"];this.options.stdin.isTTY&&this.options.stdout.isTTY&&this.enableKittyProtocol(i)}initDeferredKittyKeyboard(){if(!this.options.kittyKeyboard)return;const t=this.options.kittyKeyboard;if((t.mode??"auto")!=="auto")return;const i=t.flags??["disambiguateEscapeCodes"];!this.interactive||!this.options.stdin.isTTY||!this.options.stdout.isTTY||this.confirmKittySupport(i)}confirmKittySupport(t){const{stdin:i,stdout:r}=this.options;let s=[];const a=()=>{this.cancelKittyDetection=void 0,clearTimeout(n),i.removeListener("data",l);const o=Bi(s);s=[],o.length>0&&i.unshift(Ht.from(o))},l=o=>{const u=typeof o=="string"?Ht.from(o):o;for(const m of u)s.push(m);Ai(s)&&(a(),this.isUnmounted||this.enableKittyProtocol(t))};i.on("data",l);const n=setTimeout(a,200);this.cancelKittyDetection=a,r.write("\x1B[?u")}enableKittyProtocol(t){this.options.stdout.write(`\x1B[>${ii(t)}u`),this.kittyProtocolEnabled=!0}}const xr=(e,t)=>{const i={alternateScreen:!1,concurrent:!1,debug:!1,exitOnCtrlC:!0,incrementalRendering:!1,maxFps:30,patchConsole:!0,stderr:L.stderr,stdin:L.stdin,stdout:L.stdout,...Ki(t)},r=Fi(i.stdout,()=>new Ui(i));return r.render(e),{cleanup(){r.unmount()},clear(){r.clear()},rerender(s){r.render(s)},rootNode:r.rootNode,unmount(){r.unmount()},waitUntilExit(){return r.waitUntilExit()},waitUntilRenderFlush(){return r.waitUntilRenderFlush()}}},Ki=(e={})=>e instanceof xe?{stdin:L.stdin,stdout:e}:e,Fi=(e,t)=>{const i=xt.get(e);if(i===void 0){const r=t();return xt.set(e,r),r}return L.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
- `),i};export{xr as default};