@nick-skriabin/glyph 0.1.55 → 0.1.56

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/dist/index.js CHANGED
@@ -1,19 +1,19 @@
1
- import oe,{createContext,forwardRef,useState,useContext,useRef,useEffect,useLayoutEffect,useMemo,useCallback}from'react';import wr from'react-reconciler';import he from'string-width';import Nn,{FlexDirection,Justify,Align,Direction,Edge,Wrap,Gutter,PositionType,Overflow,MeasureMode}from'yoga-layout';import {writeFileSync,existsSync,readFileSync,unlinkSync,mkdirSync}from'fs';import {createHash}from'crypto';import {join,basename}from'path';import {tmpdir,platform}from'os';import {execSync,spawn,exec}from'child_process';var Sr=0;function on(){return `glyph-focus-${Sr++}`}function sn(e,t){let n=t.style??{};return {type:e,props:t,style:n,children:[],rawTextChildren:[],parent:null,yogaNode:null,text:null,layout:{x:0,y:0,width:0,height:0,innerX:0,innerY:0,innerWidth:0,innerHeight:0},focusId:e==="input"||t.focusable?on():null,hidden:false}}function Ct(e,t){t.parent=e,e.children.push(t);}function ln(e,t){let n=e.children.indexOf(t);n!==-1&&(e.children.splice(n,1),t.parent=null);}function cn(e,t,n){t.parent=e;let r=e.children.indexOf(n);r!==-1?e.children.splice(r,0,t):e.children.push(t);}function et(e){let t={},n=e;for(;n;){let r=n.style;t.color===void 0&&r.color!==void 0&&(t.color=r.color),t.bg===void 0&&r.bg!==void 0&&(t.bg=r.bg),t.bold===void 0&&r.bold!==void 0&&(t.bold=r.bold),t.dim===void 0&&r.dim!==void 0&&(t.dim=r.dim),t.italic===void 0&&r.italic!==void 0&&(t.italic=r.italic),t.underline===void 0&&r.underline!==void 0&&(t.underline=r.underline),n=n.parent;}return t}function St(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=St(n);return t}var wt=32,an={supportsMutation:true,supportsPersistence:false,supportsHydration:false,isPrimaryRenderer:true,scheduleTimeout:setTimeout,cancelTimeout:clearTimeout,noTimeout:-1,supportsMicrotasks:true,scheduleMicrotask:queueMicrotask,getCurrentUpdatePriority:()=>wt,setCurrentUpdatePriority:e=>{},resolveUpdatePriority:()=>wt,getCurrentEventPriority:()=>wt,resolveEventType:()=>null,resolveEventTimeStamp:()=>-1.1,shouldAttemptEagerTransition:()=>false,getInstanceFromNode:()=>null,beforeActiveInstanceBlur:()=>{},afterActiveInstanceBlur:()=>{},prepareScopeUpdate:()=>{},getInstanceFromScope:()=>null,detachDeletedInstance:()=>{},requestPostPaintCallback:e=>{},maySuspendCommit:(e,t)=>false,preloadInstance:(e,t)=>true,startSuspendingCommit:()=>{},suspendInstance:(e,t)=>{},waitForCommitToBeReady:()=>null,NotPendingTransition:null,HostTransitionContext:{$$typeof:Symbol.for("react.context"),_currentValue:null},resetFormInstance:e=>{},bindToConsole:(e,t,n)=>Function.prototype.bind.call(console[e],console,...t),supportsResources:false,isHostHoistableType:(e,t)=>false,supportsSingletons:false,isHostSingletonType:e=>false,supportsTestSelectors:false,createInstance(e,t,n,r,o){return sn(e,t)},createTextInstance(e,t,n,r){return {type:"raw-text",text:e,parent:null}},appendInitialChild(e,t){if(t.type==="raw-text"){let n=t;n.parent=e,e.rawTextChildren.push(n),e.text=e.rawTextChildren.map(r=>r.text).join("");}else Ct(e,t);},finalizeInitialChildren(e,t,n,r,o){return false},shouldSetTextContent(e,t){return false},getRootHostContext(e){return {}},getChildHostContext(e,t,n){return e},getPublicInstance(e){return e},prepareForCommit(e){return null},resetAfterCommit(e){e.onCommit();},preparePortalMount(){},appendChild(e,t){if(t.type==="raw-text"){let n=t;n.parent=e,e.rawTextChildren.push(n),e.text=e.rawTextChildren.map(r=>r.text).join("");}else Ct(e,t);},appendChildToContainer(e,t){if(t.type==="raw-text")return;let n=t;n.parent=null,e.children.push(n);},insertBefore(e,t,n){t.type==="raw-text"||n.type==="raw-text"||cn(e,t,n);},insertInContainerBefore(e,t,n){if(t.type==="raw-text"||n.type==="raw-text")return;let r=t,o=n,s=e.children.indexOf(o);s!==-1?e.children.splice(s,0,r):e.children.push(r);},removeChild(e,t){if(t.type==="raw-text"){let n=t;n.parent=null;let r=e.rawTextChildren.indexOf(n);r!==-1&&e.rawTextChildren.splice(r,1),e.text=e.rawTextChildren.map(o=>o.text).join("")||null;return}ln(e,t);},removeChildFromContainer(e,t){if(t.type==="raw-text")return;let n=t,r=e.children.indexOf(n);r!==-1&&e.children.splice(r,1);},commitTextUpdate(e,t,n){e.text=n,e.parent&&(e.parent.text=e.parent.rawTextChildren.map(r=>r.text).join(""));},commitUpdate(e,t,n,r,o){e.props=r,e.style=r.style??{},r.focusable&&!e.focusId&&(e.focusId=`focus-${Math.random().toString(36).slice(2,9)}`);},hideInstance(e){e.hidden=true;},hideTextInstance(e){e.text="";},unhideInstance(e,t){e.hidden=false;},unhideTextInstance(e,t){e.text=t;},clearContainer(e){e.children.length=0;},resetTextContent(e){e.text=null;}};var Ae=wr(an);Ae.injectIntoDevTools({bundleType:process.env.NODE_ENV==="production"?0:1,version:"0.1.0",rendererPackageName:"glyph"});var tt=class{stdout;stdin;wasRaw=false;cleanedUp=false;dataHandlers=new Set;stdinAttached=false;oscState="normal";oscAccum="";escFlushTimer=null;palette=new Map;paletteResolve=null;constructor(t=process.stdout,n=process.stdin){this.stdout=t,this.stdin=n;}get columns(){return this.stdout.columns||80}get rows(){return this.stdout.rows||24}enterRawMode(){this.stdin.isTTY&&(this.wasRaw=this.stdin.isRaw,this.stdin.setRawMode(true),this.stdin.resume(),this.stdin.setEncoding("utf-8"));}exitRawMode(){this.stdin.isTTY&&!this.wasRaw&&(this.stdin.setRawMode(false),this.stdin.pause());}write(t){this.stdout.write(t);}hideCursor(){this.write("\x1B[?25l");}showCursor(){this.write("\x1B[?25h");}moveCursor(t,n){this.write(`\x1B[${n+1};${t+1}H`);}setCursorColor(t){this.write(`\x1B]12;${t}\x07`);}resetCursorColor(){this.write("\x1B]112\x07");}enterAltScreen(){this.write("\x1B[?1049h");}exitAltScreen(){this.write("\x1B[?1049l");}clearScreen(){this.write("\x1B[2J\x1B[H");}resetStyles(){this.write("\x1B[0m");}enableKittyKeyboard(){this.write("\x1B[>1u");}disableKittyKeyboard(){this.write("\x1B[<u");}setup(){this.enterRawMode(),this.enterAltScreen(),this.enableKittyKeyboard(),this.hideCursor(),this.clearScreen(),this.attachStdinListener(),this.installCleanupHandlers();}cleanup(){this.cleanedUp||(this.cleanedUp=true,this.escFlushTimer!==null&&(clearTimeout(this.escFlushTimer),this.escFlushTimer=null),this.resetStyles(),this.resetCursorColor(),this.disableKittyKeyboard(),this.showCursor(),this.exitAltScreen(),this.exitRawMode());}suspend(){this.escFlushTimer!==null&&(clearTimeout(this.escFlushTimer),this.escFlushTimer=null),this.oscState="normal",this.oscAccum="",this.resetStyles(),this.resetCursorColor(),this.disableKittyKeyboard(),this.showCursor(),this.exitAltScreen(),this.exitRawMode();}resume(){this.enterRawMode(),this.enterAltScreen(),this.enableKittyKeyboard(),this.hideCursor(),this.clearScreen();}attachStdinListener(){this.stdinAttached||(this.stdinAttached=true,this.stdin.on("data",t=>{let n=typeof t=="string"?t:t.toString("utf-8");this.dispatchFiltered(n);}));}onData(t){return this.dataHandlers.add(t),()=>{this.dataHandlers.delete(t);}}dispatchFiltered(t){this.escFlushTimer!==null&&(clearTimeout(this.escFlushTimer),this.escFlushTimer=null);let n=this.filterOsc(t);if(n.length>0)for(let r of this.dataHandlers)r(n);this.oscState==="esc"&&(this.escFlushTimer=setTimeout(()=>{this.escFlushTimer=null,this.oscState="normal";for(let r of this.dataHandlers)r("\x1B");},50));}filterOsc(t){let n="";for(let r=0;r<t.length;r++){let o=t[r],s=t.charCodeAt(r);switch(this.oscState){case "normal":s===27?this.oscState="esc":n+=o;break;case "esc":o==="]"?(this.oscState="osc",this.oscAccum=""):(n+="\x1B"+o,this.oscState="normal");break;case "osc":s===7?(this.handleOscResponse(this.oscAccum),this.oscAccum="",this.oscState="normal"):s===27?this.oscState="osc_esc":this.oscAccum+=o;break;case "osc_esc":o==="\\"?(this.handleOscResponse(this.oscAccum),this.oscAccum="",this.oscState="normal"):(this.oscAccum+="\x1B"+o,this.oscState="osc");break}}return n}handleOscResponse(t){let n=t.match(/^4;(\d+);rgb:([0-9a-fA-F]+)\/([0-9a-fA-F]+)\/([0-9a-fA-F]+)/);if(n){let r=parseInt(n[1],10),o=parseInt(n[2].substring(0,2),16),s=parseInt(n[3].substring(0,2),16),i=parseInt(n[4].substring(0,2),16);this.palette.set(r,[o,s,i]),this.palette.size>=16&&this.paletteResolve&&(this.paletteResolve(),this.paletteResolve=null);}}queryPalette(){return new Promise(t=>{let n=()=>t(this.palette),r=setTimeout(n,200);this.paletteResolve=()=>{clearTimeout(r),n();};let o="";for(let s=0;s<16;s++)o+=`\x1B]4;${s};?\x07`;this.write(o);})}onResize(t){return this.stdout.on("resize",t),()=>{this.stdout.off("resize",t);}}installCleanupHandlers(){let t=()=>this.cleanup();process.on("exit",t);let n=r=>{t(),process.kill(process.pid,r);};process.once("SIGINT",()=>n("SIGINT")),process.once("SIGTERM",()=>n("SIGTERM")),process.on("uncaughtException",r=>{t(),console.error(r),process.exit(1);}),process.on("unhandledRejection",r=>{t(),console.error(r),process.exit(1);});}};function un(e){switch(e){case 9:return "tab";case 13:return "return";case 27:return "escape";case 32:return "space";case 127:return "backspace";case 57358:return "capslock";case 57359:return "scrolllock";case 57360:return "numlock";case 57361:return "printscreen";case 57362:return "pause";case 57363:return "menu";case 57364:return "f13";case 57365:return "f14";case 57366:return "f15";case 57367:return "f16";case 57368:return "f17";case 57369:return "f18";case 57370:return "f19";case 57371:return "f20";case 57372:return "f21";case 57373:return "f22";case 57374:return "f23";case 57375:return "f24";case 57376:return "f25";case 57399:return "kp0";case 57400:return "kp1";case 57401:return "kp2";case 57402:return "kp3";case 57403:return "kp4";case 57404:return "kp5";case 57405:return "kp6";case 57406:return "kp7";case 57407:return "kp8";case 57408:return "kp9";case 57409:return "kpdecimal";case 57410:return "kpdivide";case 57411:return "kpmultiply";case 57412:return "kpminus";case 57413:return "kpplus";case 57414:return "kpenter";case 57415:return "kpequal";case 57416:return "kpleft";case 57417:return "kpright";case 57418:return "kpup";case 57419:return "kpdown";case 57420:return "kppageup";case 57421:return "kppagedown";case 57422:return "kphome";case 57423:return "kpend";case 57424:return "kpinsert";case 57425:return "kpdelete";case 57428:return "mediaplaypause";case 57429:return "mediastop";case 57430:return "mediaprev";case 57431:return "medianext";case 57432:return "mediarewind";case 57433:return "mediafastforward";case 57434:return "mediamute";case 57435:return "volumedown";case 57436:return "volumeup";default:return e>=32&&e<=126?String.fromCharCode(e).toLowerCase():"unknown"}}function Ir(e){switch(e.split(";")[0]){case "1":return "home";case "2":return "insert";case "3":return "delete";case "4":return "end";case "5":return "pageup";case "6":return "pagedown";case "7":return "home";case "8":return "end";case "11":return "f1";case "12":return "f2";case "13":return "f3";case "14":return "f4";case "15":return "f5";case "17":return "f6";case "18":return "f7";case "19":return "f8";case "20":return "f9";case "21":return "f10";case "23":return "f11";case "24":return "f12";case "25":return "f13";case "26":return "f14";case "28":return "f15";case "29":return "f16";case "31":return "f17";case "32":return "f18";case "33":return "f19";case "34":return "f20";default:return "unknown"}}function nt(e,t){let n=t-1;n&1&&(e.shift=true),n&2&&(e.alt=true),n&4&&(e.ctrl=true),n&8&&(e.meta=true);}function fn(e){let t=[],n=0;for(;n<e.length;){let r=e[n],o=e.charCodeAt(n);if(r==="\x1B"){if(e[n+1]==="["){let s=Rr(e,n);if(s){t.push(s.key),n=s.end;continue}}if(e[n+1]==="O"){let s=vr(e,n);if(s){t.push(s.key),n=s.end;continue}}if(n+1<e.length&&e.charCodeAt(n+1)>=32){let s=e[n+1];t.push({name:s===" "?"space":s.toLowerCase(),sequence:e.substring(n,n+2),alt:true}),n+=2;continue}t.push({name:"escape",sequence:"\x1B"}),n++;continue}if(o>=1&&o<=26){let s=String.fromCharCode(o+96);o===13?t.push({name:"return",sequence:"\r"}):o===9?t.push({name:"tab",sequence:" "}):o===8?t.push({name:"backspace",sequence:"\b"}):t.push({name:s,sequence:r,ctrl:true}),n++;continue}if(o===127){t.push({name:"backspace",sequence:r}),n++;continue}t.push({name:r===" "?"space":r,sequence:r}),n++;}return t}function vr(e,t){if(t+2>=e.length)return null;let n=e[t+2],r=e.substring(t,t+3),o;switch(n){case "A":o={name:"up",sequence:r};break;case "B":o={name:"down",sequence:r};break;case "C":o={name:"right",sequence:r};break;case "D":o={name:"left",sequence:r};break;case "H":o={name:"home",sequence:r};break;case "F":o={name:"end",sequence:r};break;case "P":o={name:"f1",sequence:r};break;case "Q":o={name:"f2",sequence:r};break;case "R":o={name:"f3",sequence:r};break;case "S":o={name:"f4",sequence:r};break;case "j":o={name:"kpmultiply",sequence:r};break;case "k":o={name:"kpplus",sequence:r};break;case "l":o={name:"kpcomma",sequence:r};break;case "m":o={name:"kpminus",sequence:r};break;case "n":o={name:"kpdecimal",sequence:r};break;case "o":o={name:"kpdivide",sequence:r};break;case "p":o={name:"kp0",sequence:r};break;case "q":o={name:"kp1",sequence:r};break;case "r":o={name:"kp2",sequence:r};break;case "s":o={name:"kp3",sequence:r};break;case "t":o={name:"kp4",sequence:r};break;case "u":o={name:"kp5",sequence:r};break;case "v":o={name:"kp6",sequence:r};break;case "w":o={name:"kp7",sequence:r};break;case "x":o={name:"kp8",sequence:r};break;case "y":o={name:"kp9",sequence:r};break;case "M":o={name:"kpenter",sequence:r};break;default:return null}return {key:o,end:t+3}}function Rr(e,t){let n=t+2,r="";for(;n<e.length;){let c=e.charCodeAt(n);if(c>=48&&c<=63)r+=e[n],n++;else break}if(n>=e.length)return null;let o=e[n],s=e.substring(t,n+1);n++;let i;switch(o){case "A":i={name:"up",sequence:s};break;case "B":i={name:"down",sequence:s};break;case "C":i={name:"right",sequence:s};break;case "D":i={name:"left",sequence:s};break;case "H":i={name:"home",sequence:s};break;case "F":i={name:"end",sequence:s};break;case "Z":i={name:"tab",sequence:s,shift:true};break;case "P":i={name:"f1",sequence:s};break;case "Q":i={name:"f2",sequence:s};break;case "R":i={name:"f3",sequence:s};break;case "S":i={name:"f4",sequence:s};break;case "~":{if(r.startsWith("27;")){let c=r.split(";"),l=parseInt(c[1]??"1",10),u=parseInt(c[2]??"0",10);i={name:un(u),sequence:s},nt(i,l);break}if(i={name:Ir(r),sequence:s},r.includes(";")){let c=r.split(";"),l=parseInt(c[1]??"1",10);nt(i,l);}break}case "u":{let c=r.split(";"),l=parseInt(c[0]??"0",10),u=parseInt(c[1]??"1",10);i={name:un(l),sequence:s},nt(i,u);break}case "I":i={name:"focus",sequence:s};break;case "O":i={name:"blur",sequence:s};break;default:i={name:"unknown",sequence:s};}if(r.includes(";")&&!["~","u"].includes(o)){let c=r.split(";"),l=parseInt(c[c.length-1]??"1",10);l>=1&&l<=16&&nt(i,l);}return {key:i,end:n}}var kr={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",blackBright:"\x1B[90m",redBright:"\x1B[91m",greenBright:"\x1B[92m",yellowBright:"\x1B[93m",blueBright:"\x1B[94m",magentaBright:"\x1B[95m",cyanBright:"\x1B[96m",whiteBright:"\x1B[97m"},Pr={black:"\x1B[40m",red:"\x1B[41m",green:"\x1B[42m",yellow:"\x1B[43m",blue:"\x1B[44m",magenta:"\x1B[45m",cyan:"\x1B[46m",white:"\x1B[47m",blackBright:"\x1B[100m",redBright:"\x1B[101m",greenBright:"\x1B[102m",yellowBright:"\x1B[103m",blueBright:"\x1B[104m",magentaBright:"\x1B[105m",cyanBright:"\x1B[106m",whiteBright:"\x1B[107m"};function It(e){let t=e.replace("#",""),n=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),o=parseInt(t.substring(4,6),16);return {r:n,g:r,b:o}}function pn(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=It(e);return `\x1B[38;2;${o};${s};${i}m`}return kr[e]??"\x1B[39m"}if(typeof e=="number")return `\x1B[38;5;${e}m`;let{r:t,g:n,b:r}=e;return `\x1B[38;2;${t};${n};${r}m`}function dn(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=It(e);return `\x1B[48;2;${o};${s};${i}m`}return Pr[e]??"\x1B[49m"}if(typeof e=="number")return `\x1B[48;5;${e}m`;let{r:t,g:n,b:r}=e;return `\x1B[48;2;${t};${n};${r}m`}var mn={black:[0,0,0],red:[170,0,0],green:[0,170,0],yellow:[170,170,0],blue:[0,0,170],magenta:[170,0,170],cyan:[0,170,170],white:[170,170,170],blackBright:[85,85,85],redBright:[255,85,85],greenBright:[85,255,85],yellowBright:[255,255,85],blueBright:[85,85,255],magentaBright:[255,85,255],cyanBright:[85,255,255],whiteBright:[255,255,255]},hn=["black","red","green","yellow","blue","magenta","cyan","white","blackBright","redBright","greenBright","yellowBright","blueBright","magentaBright","cyanBright","whiteBright"],$e=null;function gn(e){e.size>0&&($e=e);}function Tr(e){if($e){let t=hn.indexOf(e);if(t!==-1){let n=$e.get(t);if(n)return n}}return mn[e]??null}function Er(e){if(typeof e=="string"){if(e.startsWith("#")){let t=It(e);return [t.r,t.g,t.b]}return Tr(e)}if(typeof e=="number"){if(e<16){if($e){let s=$e.get(e);if(s)return s}return mn[hn[e]]}if(e>=232){let s=(e-232)*10+8;return [s,s,s]}let t=e-16,n=t%6*51,r=Math.floor(t/6)%6*51;return [Math.floor(t/36)*51,r,n]}return [e.r,e.g,e.b]}function rt(e){let t=Er(e);if(!t)return false;let[n,r,o]=t.map(i=>{let c=i/255;return c<=.03928?c/12.92:Math.pow((c+.055)/1.055,2.4)});return .2126*n+.7152*r+.0722*o>.4}function vt(e,t){return e===t?true:e==null||t==null?false:typeof e=="object"&&typeof t=="object"?e.r===t.r&&e.g===t.g&&e.b===t.b:false}function yn(e){return e&&rt(e)?"black":"white"}var He=class e{width;height;cells;constructor(t,n){this.width=t,this.height=n,this.cells=new Array(t*n),this.clear();}clear(){for(let t=0;t<this.cells.length;t++)this.cells[t]={ch:" "};}resize(t,n){this.width=t,this.height=n,this.cells=new Array(t*n),this.clear();}get(t,n){if(!(t<0||t>=this.width||n<0||n>=this.height))return this.cells[n*this.width+t]}set(t,n,r){t<0||t>=this.width||n<0||n>=this.height||(this.cells[n*this.width+t]=r);}setChar(t,n,r,o,s,i,c,l,u){t<0||t>=this.width||n<0||n>=this.height||(this.cells[n*this.width+t]={ch:r,fg:o,bg:s,bold:i,dim:c,italic:l,underline:u});}fillRect(t,n,r,o,s,i,c){for(let l=n;l<n+o;l++)for(let u=t;u<t+r;u++)this.setChar(u,l,s,i,c);}clone(){let t=new e(this.width,this.height);for(let n=0;n<this.cells.length;n++){let r=this.cells[n];t.cells[n]={...r};}return t}cellsEqual(t,n){return t.ch===n.ch&&vt(t.fg,n.fg)&&vt(t.bg,n.bg)&&(t.bold??false)===(n.bold??false)&&(t.dim??false)===(n.dim??false)&&(t.italic??false)===(n.italic??false)&&(t.underline??false)===(n.underline??false)}};var Nr={single:{topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502"},double:{topLeft:"\u2554",topRight:"\u2557",bottomLeft:"\u255A",bottomRight:"\u255D",horizontal:"\u2550",vertical:"\u2551"},round:{topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502"},ascii:{topLeft:"+",topRight:"+",bottomLeft:"+",bottomRight:"+",horizontal:"-",vertical:"|"}};function xn(e){return e==="none"?null:Nr[e]}function bn(e,t,n,r){if(e.length===0)return {width:0,height:0};let o=e.split(`
2
- `);if(n===MeasureMode.Undefined||r==="none"){let l=0;for(let u of o){let f=he(u);f>l&&(l=f);}return {width:l,height:o.length}}let s=Math.max(1,Math.floor(t)),i=fe(o,s,r),c=0;for(let l of i){let u=he(l);u>c&&(c=u);}return {width:c,height:i.length}}function fe(e,t,n){let r=[];for(let o of e){if(he(o)<=t){r.push(o);continue}if(n==="truncate"){r.push(Cn(o,t));continue}if(n==="ellipsis"){r.push(Fr(o,t));continue}let i=Gr(o,t);r.push(...i);}return r}function Cn(e,t){let n="",r=0;for(let o of e){let s=he(o);if(r+s>t)break;n+=o,r+=s;}return n}function Fr(e,t){if(t<=1)return t===1?"\u2026":"";let n=Cn(e,t-1);return he(n)<he(e)?n+"\u2026":e}function Gr(e,t){let n=[],r="",o=0,s="",i=0;for(let c=0;c<=e.length;c++){let l=e[c],u=c===e.length,f=l===" ";if(u||f){if(s.length>0){if(o+i<=t)r+=s,o+=i;else if(i<=t)r.length>0&&n.push(r),r=s,o=i;else for(let h of s){let S=he(h);o+S>t&&r.length>0&&(n.push(r),r="",o=0),r+=h,o+=S;}s="",i=0;}f&&(o+1<=t?(r+=" ",o+=1):(r.length>0&&n.push(r),r=" ",o=1));}else l&&(s+=l,i+=he(l));}return r.length>0&&n.push(r),n.length>0?n:[""]}var Sn={30:"black",31:"red",32:"green",33:"yellow",34:"blue",35:"magenta",36:"cyan",37:"white",90:"blackBright",91:"redBright",92:"greenBright",93:"yellowBright",94:"blueBright",95:"magentaBright",96:"cyanBright",97:"whiteBright"},wn={40:"black",41:"red",42:"green",43:"yellow",44:"blue",45:"magenta",46:"cyan",47:"white",100:"blackBright",101:"redBright",102:"greenBright",103:"yellowBright",104:"blueBright",105:"magentaBright",106:"cyanBright",107:"whiteBright"};function Lr(e,t){let n=0;for(;n<e.length;){let r=e[n];switch(r){case 0:t.fg=void 0,t.bg=void 0,t.bold=false,t.dim=false,t.italic=false,t.underline=false;break;case 1:t.bold=true;break;case 2:t.dim=true;break;case 3:t.italic=true;break;case 4:t.underline=true;break;case 22:t.bold=false,t.dim=false;break;case 23:t.italic=false;break;case 24:t.underline=false;break;case 39:t.fg=void 0;break;case 49:t.bg=void 0;break;case 38:if(e[n+1]===5&&e[n+2]!==void 0)t.fg=e[n+2],n+=2;else if(e[n+1]===2&&e[n+4]!==void 0){let o=e[n+2]??0,s=e[n+3]??0,i=e[n+4]??0;t.fg=`#${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`,n+=4;}break;case 48:if(e[n+1]===5&&e[n+2]!==void 0)t.bg=e[n+2],n+=2;else if(e[n+1]===2&&e[n+4]!==void 0){let o=e[n+2]??0,s=e[n+3]??0,i=e[n+4]??0;t.bg=`#${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`,n+=4;}break;default:Sn[r]?t.fg=Sn[r]:wn[r]&&(t.bg=wn[r]);break}n++;}}function Rt(e){let t=[],n={},r="",o=/\x1b\[([0-9;]*)m/g,s=0,i;for(;(i=o.exec(e))!==null;){let l=e.slice(s,i.index);l&&(r+=l),r&&(t.push({text:r,style:{...n}}),r="");let f=(i[1]||"0").split(";").map(h=>parseInt(h,10)||0);Lr(f,n),s=o.lastIndex;}let c=e.slice(s);return c&&(r+=c),r&&t.push({text:r,style:{...n}}),t}function kt(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function In(e,t,n={}){t.clear();let r={},o=[],s={x:0,y:0,width:t.width,height:t.height};for(let i of e)i.hidden||vn(i,s,i.style.zIndex??0,o);o.sort((i,c)=>i.zIndex-c.zIndex);for(let i of o){let c=jr(i.node,t,i.clip,n);c?.cursorPosition&&(r.cursorPosition=c.cursorPosition);}return r}function vn(e,t,n,r){if(e.hidden)return;let o=e.style.zIndex??n,s=e.style.clip?Mr(t,{x:e.layout.innerX,y:e.layout.innerY,width:e.layout.innerWidth,height:e.layout.innerHeight}):t;if(r.push({node:e,clip:t,zIndex:o}),e.type!=="text"&&e.type!=="input")for(let i of e.children)vn(i,s,o,r);}function Mr(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),o=Math.min(e.x+e.width,t.x+t.width),s=Math.min(e.y+e.height,t.y+t.height);return {x:n,y:r,width:Math.max(0,o-n),height:Math.max(0,s-r)}}function ot(e,t,n){return e>=n.x&&e<n.x+n.width&&t>=n.y&&t<n.y+n.height}function jr(e,t,n,r={}){let{x:o,y:s,width:i,height:c,innerX:l,innerY:u,innerWidth:f,innerHeight:h}=e.layout,S=e.style;if(i<=0||c<=0)return;let P=et(e).bg;if(S.bg)for(let g=s;g<s+c;g++)for(let b=o;b<o+i;b++)ot(b,g,n)&&t.setChar(b,g," ",void 0,S.bg);let d=S.border?xn(S.border):null;if(d&&i>=2&&c>=2){let g=S.borderColor,b=P;pe(t,n,o,s,d.topLeft,g,b);for(let k=o+1;k<o+i-1;k++)pe(t,n,k,s,d.horizontal,g,b);pe(t,n,o+i-1,s,d.topRight,g,b),pe(t,n,o,s+c-1,d.bottomLeft,g,b);for(let k=o+1;k<o+i-1;k++)pe(t,n,k,s+c-1,d.horizontal,g,b);pe(t,n,o+i-1,s+c-1,d.bottomRight,g,b);for(let k=s+1;k<s+c-1;k++)pe(t,n,o,k,d.vertical,g,b),pe(t,n,o+i-1,k,d.vertical,g,b);}if(e.type==="text")Ar(e,t,n);else if(e.type==="input")return $r(e,t,n,r)}function pe(e,t,n,r,o,s,i,c,l,u,f){ot(n,r,t)&&e.setChar(n,r,o,s,i,c,l,u,f);}function Rn(e,t){if(e!==void 0)return e;if(t!==void 0)return rt(t)?"black":"white"}function Ar(e,t,n){let{innerX:r,innerY:o,innerWidth:s,innerHeight:i}=e.layout,c=et(e),l=St(e);if(!l)return;let u=Rn(c.color,c.bg),f=e.style.wrap??"wrap",h=e.style.textAlign??"left",S=l.split(`
3
- `),I=S.map(d=>kt(d)),P=fe(I,s,f);for(let d=0;d<P.length&&d<i;d++){let g=0,b=0;for(let y=0;y<I.length;y++){let G=fe([I[y]],s,f).length;if(d<b+G){g=y;break}b+=G;}let k=P[d],R=he(k),A=0;h==="center"?A=Math.max(0,Math.floor((s-R)/2)):h==="right"&&(A=Math.max(0,s-R));let D=S[g],B=Rt(D),F=d-b,E=fe([I[g]],s,f),M=0;for(let y=0;y<F;y++)M+=E[y].length;let x=M+k.length,C=0,w=0;for(let y of B)for(let G of y.text){if(w>=M&&w<x){if(he(G)>0){let H=y.style.fg??u,V=y.style.bg??c.bg,q=y.style.bold??c.bold,_=y.style.dim??c.dim,K=y.style.italic??c.italic,O=y.style.underline??c.underline;pe(t,n,r+A+C,o+d,G,H,V,q,_,K,O);}C+=he(G);}w++;}}}function $r(e,t,n,r={}){let{cursorInfo:o,useNativeCursor:s}=r,{innerX:i,innerY:c,innerWidth:l,innerHeight:u}=e.layout;if(l<=0||u<=0)return;let f=e.props.value??e.props.defaultValue??"",h=e.props.placeholder??"",S=f||h,I=!f&&!!h,P=e.props.multiline??false,d=et(e),g=Rn(d.color,d.bg),b=d.bg?rt(d.bg)?"blackBright":"whiteBright":"blackBright",k=I?b:g??d.color??e.style.color,R=I?b:k,A=I?true:d.dim,D=o&&o.nodeId===e.focusId,B;if(P&&!I){let F=e.style.wrap??"wrap",E=S.split(`
4
- `),M=fe(E,l,F),x=0,C=0;if(D){let y=o.position,G=0,W=y,H=0;for(let O=0;O<E.length;O++){let j=E[O].length;if(y<=H+j){G=O,W=y-H;break}H+=j+1;}let V=0;for(let O=0;O<G;O++)V+=fe([E[O]],l,F).length;let q=fe([E[G]],l,F),_=0,K=0;for(let O=0;O<q.length;O++){let j=q[O];if(W<=_+j.length){K=O;break}_+=j.length;}x=V+K,C=he(E[G].slice(_,_+(W-_)));}let w=Math.max(0,x-u+1);for(let y=0;y<u;y++){let G=w+y;if(G>=M.length)break;let W=M[G],H=0;for(let V of W){if(H>=l)break;let q=he(V);q>0&&pe(t,n,i+H,c+y,V,R,d.bg,d.bold,A,d.italic,d.underline),H+=q;}}if(D){let y=x-w;if(y>=0&&y<u){let G=Math.min(C,l-1),W=i+G,H=c+y;if(ot(W,H,n)&&W<i+l)if(s)B={cursorPosition:{x:W,y:H,bg:d.bg}};else {let V=t.get(W,H),q=V?.ch&&V.ch!==" "?V.ch:"\u258C",_=d.bg??"black",K=d.color??"white";t.setChar(W,H,q,_,K,V?.bold,V?.dim,V?.italic,false);}}}}else {let F=0;for(let E of S){if(F>=l)break;let M=he(E);M>0&&pe(t,n,i+F,c,E,R,d.bg,d.bold,A,d.italic,d.underline),F+=M;}if(D){let E=Math.min(o.position,l-1),M=i+E;if(ot(M,c,n)&&M<i+l)if(s)B={cursorPosition:{x:M,y:c,bg:d.bg}};else {let x=t.get(M,c),C=x?.ch&&x.ch!==" "?x.ch:"\u258C",w=d.bg??"black",y=d.color??"white";t.setChar(M,c,C,w,y,x?.bold,x?.dim,x?.italic,false);}}}return B}var Hr="\x1B",we=`${Hr}[`;function Vr(e,t){return `${we}${t+1};${e+1}H`}function Or(e){let t=`${we}0m`;return e.bold&&(t+=`${we}1m`),e.dim&&(t+=`${we}2m`),e.italic&&(t+=`${we}3m`),e.underline&&(t+=`${we}4m`),e.fg!=null&&(t+=pn(e.fg)),e.bg!=null&&(t+=dn(e.bg)),t}function kn(e,t,n){let r="",o=-1,s=-1,i="";for(let c=0;c<t.height;c++)for(let l=0;l<t.width;l++){let u=t.get(l,c);if(!n){let h=e.get(l,c);if(h&&t.cellsEqual(u,h))continue}(s!==c||o!==l)&&(r+=Vr(l,c));let f=Or(u);f!==i&&(r+=f,i=f),r+=u.ch,o=l+1,s=c;}return r.length>0&&(r+=`${we}0m`),r}var _r={row:FlexDirection.Row,column:FlexDirection.Column},qr={"flex-start":Justify.FlexStart,center:Justify.Center,"flex-end":Justify.FlexEnd,"space-between":Justify.SpaceBetween,"space-around":Justify.SpaceAround},zr={"flex-start":Align.FlexStart,center:Align.Center,"flex-end":Align.FlexEnd,stretch:Align.Stretch};function En(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%"),t(n));}function ge(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%")?e.setPositionPercent(t,parseFloat(n)):e.setPosition(t,n));}function Xr(e,t,n){En(e,o=>e.setWidth(o),t.width),En(e,o=>e.setHeight(o),t.height),t.minWidth!==void 0&&e.setMinWidth(t.minWidth),t.minHeight!==void 0&&e.setMinHeight(t.minHeight),t.maxWidth!==void 0&&e.setMaxWidth(t.maxWidth),t.maxHeight!==void 0&&e.setMaxHeight(t.maxHeight),t.padding!==void 0&&e.setPadding(Edge.All,t.padding),t.paddingX!==void 0&&e.setPadding(Edge.Horizontal,t.paddingX),t.paddingY!==void 0&&e.setPadding(Edge.Vertical,t.paddingY),t.paddingTop!==void 0&&e.setPadding(Edge.Top,t.paddingTop),t.paddingRight!==void 0&&e.setPadding(Edge.Right,t.paddingRight),t.paddingBottom!==void 0&&e.setPadding(Edge.Bottom,t.paddingBottom),t.paddingLeft!==void 0&&e.setPadding(Edge.Left,t.paddingLeft);let r=t.border!=null&&t.border!=="none";e.setBorder(Edge.All,r?1:0),t.flexDirection&&e.setFlexDirection(_r[t.flexDirection]??FlexDirection.Column),t.flexWrap&&e.setFlexWrap(t.flexWrap==="wrap"?Wrap.Wrap:Wrap.NoWrap),t.justifyContent&&e.setJustifyContent(qr[t.justifyContent]??Justify.FlexStart),t.alignItems&&e.setAlignItems(zr[t.alignItems]??Align.Stretch),t.flexGrow!==void 0&&e.setFlexGrow(t.flexGrow),t.flexShrink!==void 0&&e.setFlexShrink(t.flexShrink),t.gap!==void 0&&e.setGap(Gutter.All,t.gap),t.position==="absolute"?e.setPositionType(PositionType.Absolute):e.setPositionType(PositionType.Relative),t.inset!==void 0&&(ge(e,Edge.Top,t.inset),ge(e,Edge.Right,t.inset),ge(e,Edge.Bottom,t.inset),ge(e,Edge.Left,t.inset)),ge(e,Edge.Top,t.top),ge(e,Edge.Right,t.right),ge(e,Edge.Bottom,t.bottom),ge(e,Edge.Left,t.left),t.clip&&e.setOverflow(Overflow.Hidden);}function Bn(e){let t=Nn.Node.create();if(e.yogaNode=t,Xr(t,e.style,e.type),e.type==="text"||e.type==="input")t.setMeasureFunc((n,r,o,s)=>{let i;return e.type==="input"?(i=e.props.value??e.props.defaultValue??e.props.placeholder??"",i.length===0&&(i=" ")):i=Fn(e),bn(i,n,r,e.style.wrap??"wrap")});else for(let n=0;n<e.children.length;n++){let r=e.children[n];r.hidden||(Bn(r),t.insertChild(r.yogaNode,t.getChildCount()));}}function Fn(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=Fn(n);if(t===""&&e.props.children!=null){if(typeof e.props.children=="string")return e.props.children;if(typeof e.props.children=="number")return String(e.props.children)}return t}function Gn(e,t,n){let r=e.yogaNode,o=r.getComputedLayout(),s=t+o.left,i=n+o.top,c=o.width,l=o.height,u=e.style.border&&e.style.border!=="none"?1:0,f=r.getComputedPadding(Edge.Top),h=r.getComputedPadding(Edge.Right),S=r.getComputedPadding(Edge.Bottom),I=r.getComputedPadding(Edge.Left),P=s+u+I,d=i+u+f,g=Math.max(0,c-u*2-I-h),b=Math.max(0,l-u*2-f-S),k=e.layout;(!k||k.x!==s||k.y!==i||k.width!==c||k.height!==l||k.innerX!==P||k.innerY!==d||k.innerWidth!==g||k.innerHeight!==b)&&(e.layout={x:s,y:i,width:c,height:l,innerX:P,innerY:d,innerWidth:g,innerHeight:b});for(let R of e.children)R.hidden||!R.yogaNode||Gn(R,s,i);}function Ln(e,t,n){let r=Nn.Node.create();r.setWidth(t),r.setHeight(n),r.setFlexDirection(FlexDirection.Column);for(let o of e)o.hidden||(Bn(o),r.insertChild(o.yogaNode,r.getChildCount()));r.calculateLayout(t,n,Direction.LTR);for(let o of e)o.hidden||!o.yogaNode||Gn(o,0,0);r.freeRecursive(),Mn(e);}function Mn(e){for(let t of e)t.yogaNode=null,Mn(t.children);}var J=createContext(null),z=createContext(null),se=createContext(null),Be=createContext(null),it=createContext(null),lt=createContext(null);var te=null;function Oe(e=false){if(te)return te;let t=process.env.TERM||"",n=process.env.TERM_PROGRAM||"",r=process.env.KITTY_WINDOW_ID,o=process.env.GHOSTTY_RESOURCES_DIR,s=process.env.WEZTERM_PANE,i=process.env.LC_TERMINAL||"",c=process.env.KONSOLE_VERSION;return r||t==="xterm-kitty"?(te={name:"kitty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},te):o||t.includes("ghostty")?(te={name:"ghostty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},te):s||n==="WezTerm"?(te={name:"wezterm",supportsKittyGraphics:true,supportsIterm2Images:true,supportsSixel:true},te):n==="iTerm.app"||i==="iTerm2"?(te={name:"iterm2",supportsKittyGraphics:false,supportsIterm2Images:true,supportsSixel:false},te):c?(te={name:"konsole",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:true},te):n==="vscode"?(te={name:"vscode",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},te):(te={name:"unknown",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},te)}function Pt(){let e=Oe();return e.supportsKittyGraphics||e.supportsIterm2Images||e.supportsSixel}var re="\x1B";function ct(){return !!process.env.TMUX}function Tt(e){if(!ct())return e;let t=e.replace(/\x1b/g,"\x1B\x1B");return `${re}Ptmux;${t}${re}\\`}function jn(e){let t=Oe();return t.supportsKittyGraphics?Ur(e):t.supportsIterm2Images?Jr(e):null}function An(e){if(Oe().supportsKittyGraphics){let n;return n=`${re}_Ga=d,d=a${re}\\`,Tt(n)}return null}function Ur(e){let{data:t,width:n,height:r,x:o,y:s}=e,c=t.toString("base64"),l=`${re}[${s+1};${o+1}H`,u=Et(t),f="a=T,f=100";u&&(f+=`,s=${u.width},v=${u.height}`),f+=`,c=${n},r=${r}`;let h=4096,S=[l];ct()&&S.unshift(`${re}[?25l`);for(let I=0;I<c.length;I+=h){let P=c.slice(I,I+h),g=I+h>=c.length?"m=0":"m=1",b;I===0?b=`${re}_G${f},${g},q=2;${P}${re}\\`:b=`${re}_G${g};${P}${re}\\`,S.push(Tt(b));}return ct()&&S.push(`${re}[?25h`),S.join("")}function Jr(e){let{data:t,width:n,height:r,x:o,y:s}=e,i=t.toString("base64"),c=`${re}[${s+1};${o+1}H`,l=[`width=${n}`,`height=${r}`,"preserveAspectRatio=1","inline=1"].join(";"),u=`${re}]1337;File=${l}:${i}\x07`;return c+(ct()?Tt(u):u)}function Et(e){if(e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e.length>=24){let t=e.readUInt32BE(16),n=e.readUInt32BE(20);return {width:t,height:n}}if(e[0]===255&&e[1]===216&&e[2]===255){let t=2;for(;t<e.length-8;){if(e[t]!==255){t++;continue}let n=e[t+1];if(n!==void 0&&(n>=192&&n<=195||n>=197&&n<=199||n>=201&&n<=203||n>=205&&n<=207)){let o=e.readUInt16BE(t+5);return {width:e.readUInt16BE(t+7),height:o}}let r=e.readUInt16BE(t+2);t+=2+r;}}if(e[0]===71&&e[1]===73&&e[2]===70&&e.length>=10){let t=e.readUInt16LE(6),n=e.readUInt16LE(8);return {width:t,height:n}}return null}function Yr(e,t={}){let n=t.stdout??process.stdout,r=t.stdin??process.stdin,o=t.debug??false,s=t.useNativeCursor??true,i=new tt(n,r);i.setup();let c=false;i.queryPalette().then(a=>{gn(a),f=true,V();});let l=new He(i.columns,i.rows),u=new He(i.columns,i.rows),f=true,h=new Set,S=new Set,I=new Map,P={subscribe(a){return h.add(a),()=>h.delete(a)},subscribePriority(a){return S.add(a),()=>S.delete(a)},registerInputHandler(a,m){return I.set(a,m),()=>I.delete(a)}},d=new Map,g=new Map,b={registerImage(a){let m=d.get(a.id);(!m||m.x!==a.x||m.y!==a.y||m.width!==a.width||m.height!==a.height)&&(g.set(a.id,a),V());},unregisterImage(a){d.delete(a),g.delete(a);}};function k(){for(let a of g.values()){let m=jn({data:a.data,width:a.width,height:a.height,x:a.x,y:a.y,id:a.id});m&&(i.write(m),d.set(a.id,{x:a.x,y:a.y,width:a.width,height:a.height}));}g.clear();}let R=null,A=new Map,D=[],B=new Set,F=[],E=new Set;function M(a){if(R!==a){R=a,V();for(let m of E)m(R);}}function x(){let a=[...D];if(F.length>0){let m=F[F.length-1];a=a.filter(v=>m.has(v));}return a=a.filter(m=>!B.has(m)),a.sort((m,v)=>{let N=A.get(m),p=A.get(v);if(!N||!p)return 0;let L=N.layout,$=p.layout;return L.y!==$.y?L.y-$.y:L.x-$.x}),a}let C={get focusedId(){return R},register(a,m){if(A.set(a,m),D.includes(a)||D.push(a),F.length>0&&F[F.length-1].add(a),R===null){let v=x();v.length>0&&M(v[0]);}return ()=>{A.delete(a);let v=D.indexOf(a);if(v!==-1&&D.splice(v,1),R===a){let N=x();M(N[0]??null);}}},requestFocus(a){M(a);},focusNext(){let a=x();if(a.length===0)return;let v=((R?a.indexOf(R):-1)+1)%a.length;M(a[v]);},focusPrev(){let a=x();if(a.length===0)return;let v=((R?a.indexOf(R):0)-1+a.length)%a.length;M(a[v]);},setSkippable(a,m){if(m){if(B.add(a),R===a){let v=x();v.length>0&&M(v[0]);}}else B.delete(a);},trapIds:null,pushTrap(a){return F.push(a),()=>{let m=F.indexOf(a);m!==-1&&F.splice(m,1);}},onFocusChange(a){return E.add(a),()=>{E.delete(a);}},getRegisteredElements(){let a=[];for(let m of D){if(B.has(m))continue;let v=A.get(m);v&&a.push({id:m,node:v});}return a},getActiveElements(){let a=x(),m=[];for(let v of a){if(B.has(v))continue;let N=A.get(v);N&&m.push({id:v,node:N});}return m}},w=new Map,y={getLayout(a){return a.layout},subscribe(a,m){return w.has(a)||w.set(a,new Set),w.get(a).add(m),()=>{let v=w.get(a);v&&(v.delete(m),v.size===0&&w.delete(a));}}},G={registerNode(){},unregisterNode(){},scheduleRender:V,exit(a){T.exit(a);},get columns(){return i.columns},get rows(){return i.rows}},W={type:"root",children:[],onCommit(){V();}},H=false;function V(){H||(H=true,queueMicrotask(()=>{H=false,q();}));}function q(){let a=i.columns,m=i.rows;(u.width!==a||u.height!==m)&&(u.resize(a,m),l.resize(a,m),f=true),Ln(W.children,a,m),_(W.children);let v;if(R){let L=A.get(R);L?.type==="input"&&(v={nodeId:R,position:L.props.cursorPosition??L.props.value?.length??0});}let N=In(W.children,u,{cursorInfo:v,useNativeCursor:s}),p=kn(l,u,f);if(p.length>0&&i.write(p),g.size>0&&c&&(i.hideCursor(),c=false),k(),s)if(N.cursorPosition){let L=yn(N.cursorPosition.bg);i.setCursorColor(L),i.moveCursor(N.cursorPosition.x,N.cursorPosition.y),c||(i.showCursor(),c=true);}else i.hideCursor(),c=false;for(let L=0;L<u.cells.length;L++)l.cells[L]={...u.cells[L]};f=false;}function _(a){for(let m of a){let v=w.get(m);if(v)for(let N of v)N(m.layout);_(m.children);}}let K=i.onData(a=>{let m=fn(a);for(let v of m){if(v.ctrl&&v.name==="c"){T.exit();return}if(v.ctrl&&v.name==="z"){i.suspend(),process.kill(0,"SIGSTOP");return}let N=false;for(let p of S)if(p(v)){N=true;break}if(!N&&R){let p=I.get(R);p&&(N=p(v));}if(!N&&v.name==="tab"&&!v.ctrl&&!v.alt){v.shift?C.focusPrev():C.focusNext();continue}if(!N)for(let p of h)p(v);}}),O=i.onResize(()=>{f=true,V();}),j=()=>{i.resume(),f=true,V();};process.on("SIGCONT",j);let Q=oe.createElement(Be.Provider,{value:G},oe.createElement(J.Provider,{value:P},oe.createElement(z.Provider,{value:C},oe.createElement(se.Provider,{value:y},oe.createElement(lt.Provider,{value:b},e))))),ne=a=>{o&&console.error("Uncaught error:",a);},ee=a=>{o&&console.error("Error caught by boundary:",a);},ae=a=>{o&&console.error("Recoverable error:",a);},Z=Ae.createContainer(W,0,null,false,null,"",ne,ee,ae,null);Ae.updateContainer(Q,Z,null,null);let T={unmount(){Ae.updateContainer(null,Z,null,null),K(),O(),process.off("SIGCONT",j);let a=An();a&&i.write(a),i.cleanup();},exit(a){T.unmount(),process.exit(a??0);}};return T}var eo=forwardRef(function({children:t,style:n,focusable:r},o){return oe.createElement("box",{style:n,focusable:r,ref:o},t)});var ro=forwardRef(function({children:t,style:n,wrap:r},o){let s=r?{...n,wrap:r}:n;return oe.createElement("text",{style:s,ref:o},t)});function $n(e,t,n){if(n<=0)return {visualLine:0,visualCol:t,totalVisualLines:1,lineStartOffset:0,lineLength:e.length};let r=e.split(`
5
- `),o=[],s=0;for(let l of r){let u=fe([l],n,"wrap"),f=0;for(let h of u)o.push({text:h,logicalOffset:s+f}),f+=h.length;s+=l.length+1;}let i=0;for(let l=0;l<o.length;l++){let u=o[l],f=u.text.length,h=l+1<o.length&&o[l+1].logicalOffset!==u.logicalOffset+f,S=f+(h?1:0);if(t<i+f||l===o.length-1)return {visualLine:l,visualCol:Math.min(t-i,f),totalVisualLines:o.length,lineStartOffset:i,lineLength:f};i+=S;}let c=o.length-1;return {visualLine:c,visualCol:o[c].text.length,totalVisualLines:o.length,lineStartOffset:i-o[c].text.length,lineLength:o[c].text.length}}function Hn(e,t,n,r){if(r<=0)return Math.min(n,e.length);let o=e.split(`
6
- `),s=[],i=0;for(let f of o){let h=fe([f],r,"wrap"),S=0;for(let I of h)s.push({text:I,startOffset:i+S}),S+=I.length;i+=f.length+1;}let c=Math.max(0,Math.min(t,s.length-1)),l=s[c],u=Math.min(n,l.text.length);return l.startOffset+u}function We(e,t){let n=e.split(`
7
- `),r=t;for(let s=0;s<n.length;s++){if(r<=n[s].length)return {line:s,col:r,lines:n};r-=n[s].length+1;}let o=n.length-1;return {line:o,col:n[o].length,lines:n}}function _e(e,t,n){let r=0;for(let o=0;o<t&&o<e.length;o++)r+=e[o].length+1;return r+Math.min(n,e[t]?.length??0)}function so(e){let{value:t,defaultValue:n="",onChange:r,onKeyPress:o,onBeforeChange:s,placeholder:i,style:c,focusedStyle:l,multiline:u,autoFocus:f,type:h="text"}=e,[S,I]=useState(n),[P,d]=useState(n.length),[g,b]=useState(0),[k,R]=useState(false),[A,D]=useState(false),B=useContext(J),F=useContext(z),E=useContext(se),M=useRef(null),x=useRef(null),C=t!==void 0,w=C?t:S;useEffect(()=>{if(!E||!M.current)return;let K=E.getLayout(M.current);return b(K.innerWidth),E.subscribe(M.current,O=>{b(O.innerWidth);})},[E]);let y=useRef(w),G=useRef(P),W=useRef(w),H=useRef(P);useEffect(()=>{w!==W.current&&(y.current=w,W.current=w,G.current=w.length,H.current=w.length,d(w.length));},[w]),useEffect(()=>{P!==H.current&&(G.current=P,H.current=P);},[P]);let V=useRef({isControlled:C,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:u??false,innerWidth:g,type:h});V.current={isControlled:C,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:u??false,innerWidth:g,type:h},useEffect(()=>{if(!(!F||!x.current||!M.current))return F.register(x.current,M.current)},[F,A]);let q=useRef(false);useEffect(()=>{if(!A){q.current=false;return}if(f&&!q.current&&F&&x.current){q.current=true;let K=x.current,O=setTimeout(()=>{F.requestFocus(K);},0);return ()=>clearTimeout(O)}},[f,F,A]),useEffect(()=>{if(!F||!x.current)return;let K=x.current;return R(F.focusedId===K),F.onFocusChange(O=>{R(O===K);})},[F,A]),useEffect(()=>{if(!B||!x.current)return;let K=x.current,O=j=>{let{isControlled:Q,onChange:ne,onKeyPress:ee,onBeforeChange:ae,multiline:Z}=V.current;if(ee?.(j)===true)return true;let T=y.current,a=G.current;if(j.name==="escape")return false;let m=(p,L)=>{let $=p,U=L;if(ae){let X=ae(p,T);if(X===false)return;typeof X=="string"&&($=X,U=X.length);}y.current=$,G.current=U,W.current=$,H.current=U,Q||I($),ne?.($),d(U);},v=p=>{G.current=p,H.current=p,d(p);};if(j.name==="return"){if(Z){let p=T.slice(0,a)+`
8
- `+T.slice(a);return m(p,a+1),true}return false}if(j.ctrl){if(j.name==="w"){if(a>0){let p=a;for(;p>0&&T[p-1]===" ";)p--;for(;p>0&&T[p-1]!==" "&&(!Z||T[p-1]!==`
9
- `);)p--;let L=T.slice(0,p)+T.slice(a);m(L,p);}return true}if(j.name==="a"){if(Z){let{line:p,lines:L}=We(T,a);v(_e(L,p,0));}else v(0);return true}if(j.name==="e"){if(Z){let{line:p,lines:L}=We(T,a);v(_e(L,p,L[p].length));}else v(T.length);return true}if(j.name==="k"){if(Z){let{line:p,lines:L}=We(T,a),$=_e(L,p,L[p].length);if(a<$){let U=T.slice(0,a)+T.slice($);m(U,a);}}else if(a<T.length){let p=T.slice(0,a);m(p,a);}return true}return false}if(j.alt){if(j.name==="left"||j.name==="b"){let p=a;for(;p>0&&T[p-1]===" ";)p--;for(;p>0&&T[p-1]!==" "&&T[p-1]!==`
10
- `;)p--;return v(p),true}if(j.name==="right"||j.name==="f"){let p=a;for(;p<T.length&&T[p]!==" "&&T[p]!==`
11
- `;)p++;for(;p<T.length&&T[p]===" ";)p++;return v(p),true}if(j.name==="backspace"||j.name==="d")if(j.name==="backspace"){if(a>0){let p=a;for(;p>0&&T[p-1]===" ";)p--;for(;p>0&&T[p-1]!==" "&&T[p-1]!==`
12
- `;)p--;let L=T.slice(0,p)+T.slice(a);m(L,p);}return true}else {if(a<T.length){let p=a;for(;p<T.length&&T[p]!==" "&&T[p]!==`
13
- `;)p++;for(;p<T.length&&T[p]===" ";)p++;let L=T.slice(0,a)+T.slice(p);m(L,a);}return true}return false}if(j.name==="left")return v(Math.max(0,a-1)),true;if(j.name==="right")return v(Math.min(T.length,a+1)),true;if(j.name==="up"){let{innerWidth:p}=V.current,L=$n(T,a,p);return L.visualLine>0&&v(Hn(T,L.visualLine-1,L.visualCol,p)),true}if(j.name==="down"){let{innerWidth:p}=V.current,L=$n(T,a,p);return L.visualLine<L.totalVisualLines-1&&v(Hn(T,L.visualLine+1,L.visualCol,p)),true}if(j.name==="home"){if(Z){let{line:p,lines:L}=We(T,a);v(_e(L,p,0));}else v(0);return true}if(j.name==="end"){if(Z){let{line:p,lines:L}=We(T,a);v(_e(L,p,L[p].length));}else v(T.length);return true}if(j.name==="backspace"){if(a>0){let p=T.slice(0,a-1)+T.slice(a);m(p,a-1);}return true}if(j.name==="delete"){if(a<T.length){let p=T.slice(0,a)+T.slice(a+1);m(p,a);}return true}if(j.name.length>1)return false;let N=j.sequence;if(N.length===1&&N.charCodeAt(0)>=32){let{type:p}=V.current;if(p==="number"){let $=/[0-9]/.test(N),U=N==="."&&!T.includes("."),X=N==="-"&&a===0&&!T.includes("-");if(!$&&!U&&!X)return true}let L=T.slice(0,a)+N+T.slice(a);return m(L,a+1),true}return false};return B.registerInputHandler(K,O)},[B,A]);let _={...c,...k&&l?l:{}};return oe.createElement("input",{style:_,value:w,defaultValue:n,placeholder:i,onChange:r,cursorPosition:G.current,multiline:u??false,focused:k,ref:K=>{K?(M.current=K,x.current=K.focusId,D(true)):(M.current=null,x.current=null,D(false));}})}function Bt({trap:e=false,children:t}){let n=useContext(z),r=useRef(null),o=useRef(new Set);return useLayoutEffect(()=>{if(!e||!n)return;r.current=n.focusedId;let s=n.pushTrap(o.current);return ()=>{s(),r.current&&n.requestFocus(r.current);}},[e,n]),useEffect(()=>{if(!(!e||!n)&&o.current.size>0){let s=o.current.values().next().value;s&&n.requestFocus(s);}},[e,n]),oe.createElement(oe.Fragment,null,t)}function uo({size:e}){return oe.createElement("box",{style:{flexGrow:e??1}})}function Wn(e){let t=e.toLowerCase().split("+");return {name:t[t.length-1],ctrl:t.includes("ctrl"),alt:t.includes("alt"),shift:t.includes("shift"),meta:t.includes("meta")||t.includes("cmd")||t.includes("super")||t.includes("win")}}function _n(e,t){return !(t.name!==e.name||e.ctrl!==!!t.ctrl||e.alt!==!!t.alt||e.shift!==!!t.shift||e.meta!==!!t.meta)}function po({keypress:e,onPress:t,whenFocused:n,priority:r,disabled:o}){let s=useContext(J),i=useContext(z),c=useRef(t);c.current=t;let l=useRef(Wn(e));return l.current=Wn(e),useEffect(()=>{if(!(!s||o))if(r){let u=f=>!_n(l.current,f)||n&&i?.focusedId!==n?false:(c.current(),true);return s.subscribePriority(u)}else {let u=f=>{_n(l.current,f)&&(n&&i?.focusedId!==n||c.current());};return s.subscribe(u)}},[s,i,n,r,o]),null}function ho({children:e,zIndex:t=1e3}){return oe.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:t}},e)}function yo({onPress:e,style:t,focusedStyle:n,children:r,disabled:o}){let s=useContext(z),i=useContext(J),c=useRef(null),l=useRef(null),u=useRef(e);u.current=e;let[f,h]=useState(false),[S,I]=useState(false);useEffect(()=>{if(!(!s||!l.current||!c.current||o))return s.register(l.current,c.current)},[s,o,f]),useEffect(()=>{if(!s||!l.current)return;let d=l.current;return I(s.focusedId===d),s.onFocusChange(g=>{I(g===d);})},[s,f]),useEffect(()=>{if(!i||!l.current||o)return;let d=l.current,g=b=>s?.focusedId!==d?false:b.name==="return"||b.name===" "||b.sequence===" "?(u.current?.(),true):false;return i.registerInputHandler(d,g)},[i,s,o,f]);let P={...t,...S&&n?n:{}};return oe.createElement("box",{style:P,focusable:!o,ref:d=>{d?(c.current=d,l.current=d.focusId,h(true)):(c.current=null,l.current=null,h(false));}},r)}var So={x:0,y:0,width:0,height:0,innerX:0,innerY:0,innerWidth:0,innerHeight:0};function xe(e){let t=useContext(se),[n,r]=useState(So);return useEffect(()=>{if(!(!t||!e?.current))return r(t.getLayout(e.current)),t.subscribe(e.current,r)},[t,e]),n}function qe(e,t=[]){let n=useContext(J);useEffect(()=>{if(n)return n.subscribe(e)},[n,...t]);}function ko({children:e,style:t,scrollOffset:n,onScroll:r,defaultScrollOffset:o=0,scrollStep:s=1,disableKeyboard:i,scrollToFocus:c=true,showScrollbar:l=true,focusable:u=true,focusedStyle:f}){let h=n!==void 0,[S,I]=useState(o),P=h?n:S,d=useRef(null),g=useRef(null),b=xe(d),k=xe(g),R=useContext(z),A=useContext(se),D=useRef(null);u&&!D.current&&(D.current=`scrollview-${Math.random().toString(36).slice(2,9)}`);let B=u?D.current:null;useEffect(()=>{if(!(!u||!B||!R||!d.current))return R.register(B,d.current)},[u,B,R]);let F=u&&B&&R?.focusedId===B,E=b.innerHeight,M=k.height,x=Math.max(0,M-E),C=Math.max(0,Math.min(P,x)),w=useMemo(()=>({getBounds:()=>{let $=b.y;return {visibleTop:$,visibleBottom:$+E,viewportHeight:E,scrollOffset:C}}}),[b.y,E,C]),y=useCallback($=>{let U=Math.max(0,Math.min($,x));h?r?.(U):I(U);},[h,r,x]);useEffect(()=>{P>x&&x>=0&&y(x);},[P,x,y]),useEffect(()=>!c||!R||!A||!g.current?void 0:R.onFocusChange(U=>{if(!U||!g.current)return;let X=ke=>{if(ke.focusId===U)return ke;for(let Se of ke.children){let Pe=X(Se);if(Pe)return Pe}return null},de=X(g.current);if(!de)return;let be=A.getLayout(de),ce=g.current.layout?.y??0,ue=be.y-ce,Ce=ue+be.height,me=P,je=P+E;ue<me?y(ue):Ce>je&&y(Ce-E);}),[c,R,A,P,E,y]);let G=useCallback(()=>{if(!R)return false;let $=R.focusedId;if(!$)return false;if(u&&B&&$===B)return true;if(!g.current)return false;let U=X=>{if(X.focusId===$)return true;for(let de of X.children)if(U(de))return true;return false};return U(g.current)},[R,u,B]);qe($=>{if(i||!G())return;let U=Math.max(1,Math.floor(E/2)),X=Math.max(1,E);switch($.name){case "pageup":y(P-X);break;case "pagedown":y(P+X);break;default:$.ctrl&&($.name==="d"?y(P+U):$.name==="u"?y(P-U):$.name==="f"?y(P+X):$.name==="b"&&y(P-X));break}},[P,s,E,x,i,y,G]);let{padding:W,paddingX:H,paddingY:V,paddingTop:q,paddingRight:_,paddingBottom:K,paddingLeft:O,...j}=t??{},ne=j.border!=null&&j.border!=="none"?2:0,ee=M>0?M+ne:void 0,ae={...j,...F?f:{},clip:true,...j.height===void 0&&ee!==void 0?{height:ee,flexShrink:j.flexShrink??1,minHeight:j.minHeight??0}:{}},Z={position:"absolute",top:-C,left:0,right:0,flexDirection:"column",...W!==void 0&&{padding:W},...H!==void 0&&{paddingX:H},...V!==void 0&&{paddingY:V},...q!==void 0&&{paddingTop:q},..._!==void 0&&{paddingRight:_},...K!==void 0&&{paddingBottom:K},...O!==void 0&&{paddingLeft:O}},T=M>E&&E>0,a=l&&T,m=Math.max(1,Math.floor(E/M*E)),v=M-E,N=v>0?Math.floor(C/v*(E-m)):0,p=[];if(a)for(let $=0;$<E;$++)$>=N&&$<N+m?p.push("\u2588"):p.push("\u2591");let L={position:"absolute",top:0,right:0,width:1,height:E,flexDirection:"column"};return oe.createElement(it.Provider,{value:w},oe.createElement("box",{style:ae,ref:$=>{d.current=$??null;},...u?{focusable:true,focusId:B}:{}},oe.createElement("box",{style:{...Z,paddingRight:a?(Z.paddingRight??0)+1:Z.paddingRight},ref:$=>{g.current=$??null;}},e),a&&oe.createElement("box",{style:L},oe.createElement("text",{style:{color:"blackBright"}},p.join(`
14
- `)))))}function Vt({count:e,renderItem:t,selectedIndex:n,onSelectionChange:r,onSelect:o,defaultSelectedIndex:s=0,disabledIndices:i,style:c,focusable:l=true}){let u=n!==void 0,[f,h]=useState(s),S=u?n:f,I=useContext(z),P=useContext(J),d=useRef(null),g=useRef(null),b=useRef(o);b.current=o;let[k,R]=useState(false),[A,D]=useState(false),B=useRef(null),F=useCallback(C=>{let w=Math.max(0,Math.min(C,e-1));u?r?.(w):h(w);},[u,r,e]),E=useCallback((C,w)=>{if(!i||i.size===0)return Math.max(0,Math.min(C+w,e-1));let y=C+w;for(;y>=0&&y<e&&i.has(y);)y+=w;return y<0||y>=e?C:y},[i,e]);useEffect(()=>{if(!(!I||!g.current||!d.current||!l))return I.register(g.current,d.current)},[I,l,k]),useEffect(()=>{if(!I||!g.current)return;let C=g.current;return D(I.focusedId===C),I.onFocusChange(w=>{D(w===C);})},[I,k]);let M=useCallback(C=>{let w=C?e-1:0,y=C?-1:1,G=w;for(;G>=0&&G<e&&i?.has(G);)G+=y;return G>=0&&G<e?G:C?e-1:0},[i,e]);useEffect(()=>{if(!P||!g.current||!l)return;let C=g.current,w=y=>I?.focusedId!==C?false:y.name==="g"&&!y.ctrl&&!y.alt?B.current==="g"?(F(M(false)),B.current=null,true):(B.current="g",true):y.name==="G"||y.name==="g"&&y.shift?(B.current=null,F(M(true)),true):(B.current=null,y.name==="up"||y.name==="k"?(F(E(S,-1)),true):y.name==="down"||y.name==="j"?(F(E(S,1)),true):y.name==="return"?(i?.has(S)||b.current?.(S),true):false);return P.registerInputHandler(C,w)},[P,I,l,S,F,E,M,i,k]);let x=[];for(let C=0;C<e;C++)x.push(oe.createElement(oe.Fragment,{key:C},t({index:C,selected:C===S,focused:A})));return oe.createElement("box",{style:{flexDirection:"column",...c},focusable:l,ref:C=>{C?(d.current=C,g.current=C.focusId,R(true)):(d.current=null,g.current=null,R(false));}},...x)}function Po({items:e,selectedIndex:t,onSelectionChange:n,onSelect:r,defaultSelectedIndex:o=0,style:s,highlightColor:i="cyan",focusable:c=true}){let l=new Set;for(let f=0;f<e.length;f++)e[f].disabled&&l.add(f);let u=f=>{let h=e[f];h&&!h.disabled&&r?.(h.value,f);};return oe.createElement(Vt,{count:e.length,selectedIndex:t,onSelectionChange:n,onSelect:u,defaultSelectedIndex:o,disabledIndices:l.size>0?l:void 0,style:s,focusable:c,renderItem:({index:f,selected:h,focused:S})=>{let I=e[f],P=I.disabled,d=h&&S,g=h?">":" ";return oe.createElement("box",{style:{flexDirection:"row",...d?{bg:i}:{}}},oe.createElement("text",{style:d?{bold:true,color:"black"}:P?{dim:true}:{}},`${g} ${I.label}`))}})}function Bo({value:e,indeterminate:t=false,width:n="100%",label:r,showPercent:o=false,style:s,filled:i="\u2588",empty:c="\u2591"}){let l=useRef(null),f=xe(l).innerWidth,[h,S]=useState(0);useEffect(()=>{if(!t)return;let b=setInterval(()=>{S(k=>(k+1)%Math.max(1,f+6));},100);return ()=>clearInterval(b)},[t,f]);let I=Math.max(0,Math.min(1,e??0)),P=o?` ${Math.round(I*100)}%`:"",d="";if(f>0)if(t&&e===void 0){let b=Math.max(1,Math.min(3,Math.floor(f/4))),k=[];for(let R=0;R<f;R++)R>=h-b&&R<h?k.push(i):k.push(c);d=k.join("");}else {let b=Math.round(I*f);d=i.repeat(b)+c.repeat(f-b);}let g=[];return r&&g.push(oe.createElement("text",{key:"label",style:{bold:true}},r+" ")),g.push(oe.createElement("box",{key:"track",style:{flexGrow:1,flexShrink:1},ref:b=>{l.current=b??null;}},oe.createElement("text",{key:"bar",style:{}},d))),o&&g.push(oe.createElement("text",{key:"pct",style:{bold:true}},P)),oe.createElement("box",{style:{flexDirection:"row",width:n,...s}},...g)}var Lo=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function Mo({frames:e=Lo,intervalMs:t=80,label:n,style:r}){let[o,s]=useState(0);useEffect(()=>{let c=setInterval(()=>{s(l=>(l+1)%e.length);},t);return ()=>clearInterval(c)},[e.length,t]);let i=[oe.createElement("text",{key:"frame",style:r},e[o])];return n&&i.push(oe.createElement("text",{key:"label",style:{}}," "+n)),oe.createElement("box",{style:{flexDirection:"row"}},...i)}var Qn=createContext(null),Oo=0;function Do(){let e=useContext(Qn);if(!e)throw new Error("useToast must be used within a <ToastHost>");return e.push}var Ko={info:{bg:"blackBright",title:"cyanBright",text:"white"},success:{bg:"blackBright",title:"greenBright",text:"white"},warning:{bg:"blackBright",title:"yellowBright",text:"white"},error:{bg:"blackBright",title:"redBright",text:"white"}};function Wo({position:e="bottom-right",maxVisible:t=5,children:n}){let[r,o]=useState([]),s=useRef(new Map),i=useCallback(I=>{let P=`toast-${Oo++}`,d={id:P,durationMs:3e3,variant:"info",...I};if(o(g=>[...g,d]),d.durationMs&&d.durationMs>0){let g=setTimeout(()=>{s.current.delete(P),o(b=>b.filter(k=>k.id!==P));},d.durationMs);s.current.set(P,g);}},[]);useEffect(()=>()=>{for(let I of s.current.values())clearTimeout(I);s.current.clear();},[]);let c=useRef({push:i});c.current.push=i;let l=e.startsWith("top"),u=e.endsWith("right"),f={position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:900,flexDirection:"column",justifyContent:l?"flex-start":"flex-end",alignItems:u?"flex-end":"flex-start",padding:1},S=r.slice(-t).map(I=>{let P=I.variant??"info",d=Ko[P],g=[];return I.title&&g.push(oe.createElement("text",{key:"title",style:{bold:true,color:d.title}},I.title)),g.push(oe.createElement("text",{key:"msg",style:{color:d.text}},I.message)),oe.createElement("box",{key:I.id,style:{bg:d.bg,paddingX:1,flexDirection:"column",minWidth:20,maxWidth:50}},...g)});return oe.createElement(Qn.Provider,{value:c.current},n,S.length>0?oe.createElement("box",{style:f},...S):null)}function qo({items:e,value:t,onChange:n,placeholder:r="Select...",style:o,focusedStyle:s,dropdownStyle:i,highlightColor:c="cyan",maxVisible:l=8,searchable:u=true,disabled:f}){let h=useContext(z),S=useContext(J),I=useContext(Be),P=useContext(it),d=useRef(null),g=useRef(null),b=useRef(n);b.current=n;let[k,R]=useState(false),[A,D]=useState(false),[B,F]=useState(false),[E,M]=useState(0),[x,C]=useState(""),[w,y]=useState(0),G=xe(d),W=I?.rows??24,H=P?.getBounds(),q=e.find(m=>m.value===t)?.label??"",_=useMemo(()=>{if(!x)return e;let m=x.toLowerCase();return e.filter(v=>v.label.toLowerCase().includes(m))},[e,x]),K=Math.min(l,_.length),O=_.slice(w,w+K);useEffect(()=>{M(0),y(0);},[x]),useEffect(()=>{!A&&B&&(F(false),C(""));},[A,B]),useEffect(()=>{if(!(!h||!g.current||!d.current))return h.register(g.current,d.current)},[h,k]),useEffect(()=>{!h||!g.current||h.setSkippable(g.current,!!f);},[h,f,k]),useEffect(()=>{if(!h||!g.current)return;let m=g.current;return D(h.focusedId===m),h.onFocusChange(v=>{D(v===m);})},[h,k]);let j=useCallback((m,v)=>{let N=m+v;for(;N>=0&&N<_.length;){if(!_[N].disabled)return N;N+=v;}return m},[_]),Q=useCallback(m=>{m<w?y(m):m>=w+K&&y(m-K+1);},[w,K]);useEffect(()=>{if(!S||!g.current||f)return;let m=g.current,v=N=>{if(h?.focusedId!==m)return false;if(!B){if(N.name==="return"||N.name===" "||N.sequence===" "||N.name==="down"){F(true),C("");let p=_.findIndex($=>$.value===t),L=p>=0?p:0;return M(L),y(Math.max(0,L-Math.floor(l/2))),true}return false}if(N.name==="tab")return F(false),C(""),false;if(N.name==="escape")return F(false),C(""),true;if(N.name==="return"){let p=_[E];return p&&!p.disabled&&(b.current?.(p.value),F(false),C("")),true}if(N.name==="up"){let p=j(E,-1);return M(p),Q(p),true}if(N.name==="down"){let p=j(E,1);return M(p),Q(p),true}if(N.name==="backspace")return u&&x.length>0&&C(p=>p.slice(0,-1)),true;if(N.name==="home"){let p=j(-1,1);return M(p),Q(p),true}if(N.name==="end"){let p=j(_.length,-1);return M(p),Q(p),true}if(u&&N.sequence&&N.sequence.length===1&&!N.ctrl&&!N.alt){let p=N.sequence;if(p>=" "&&p<="~")return C(L=>L+p),true}return true};return S.registerInputHandler(m,v)},[S,h,f,B,E,_,t,l,u,x,j,Q,k]);let ee={flexDirection:"row",width:"100%",...!o?.bg&&o?.border===void 0?{border:"single"}:{},...o,...A&&s?s:{}},ae=q?o?.color??void 0:"blackBright",Z=[oe.createElement("text",{key:"label",style:{flexGrow:1,flexShrink:1,color:ae,wrap:"ellipsis",...q?{}:{dim:true}}},q||r),oe.createElement("text",{key:"arrow",style:{flexShrink:0,color:A?c:"blackBright"}},B?" \u25B2":" \u25BC")],T=null;if(B){let m=[];u&&x&&m.push(oe.createElement("box",{key:"search",style:{paddingX:1}},oe.createElement("text",{style:{color:"blackBright",dim:true}},`/${x}`))),_.length===0&&m.push(oe.createElement("box",{key:"empty",style:{paddingX:1}},oe.createElement("text",{style:{dim:true,color:"blackBright"}},"No matches"))),w>0&&m.push(oe.createElement("box",{key:"scroll-up",style:{justifyContent:"center",alignItems:"center"}},oe.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25B2"))),O.forEach((me,je)=>{let Se=w+je===E,Pe=me.disabled,br={paddingX:1,...Se&&!Pe?{bg:c}:{}},Cr={...Se&&!Pe?{color:"black",bold:true}:{},...Pe?{dim:true,color:"blackBright"}:{}};m.push(oe.createElement("box",{key:`item-${me.value}`,style:br},oe.createElement("text",{style:Cr},me.label)));}),w+K<_.length&&m.push(oe.createElement("box",{key:"scroll-down",style:{justifyContent:"center",alignItems:"center"}},oe.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25BC")));let v=w>0,N=w+K<_.length,p=u&&x,L=_.length===0,$=!i?.bg&&i?.border===void 0,X=K+($?2:0);v&&(X+=1),N&&(X+=1),p&&(X+=1),L&&(X+=1);let de=G.y+G.height,be,ce;H?(be=H.visibleBottom-de,ce=G.y-H.visibleTop):(be=W-de,ce=G.y);let Ce=be<X&&ce>=X?-X:G.height||1;T=oe.createElement("box",{style:{position:"absolute",top:Ce,left:0,right:0,zIndex:9999,...$?{border:"single"}:{},bg:"black",flexDirection:"column",...i}},...m);}let a={flexDirection:"column",width:ee.width??"100%",minWidth:ee.minWidth,maxWidth:ee.maxWidth,flexGrow:ee.flexGrow,flexShrink:ee.flexShrink??1};return oe.createElement("box",{style:a},oe.createElement("box",{style:ee,focusable:true,ref:m=>{m?(d.current=m,g.current=m.focusId,R(true)):(d.current=null,g.current=null,R(false));}},...Z),T)}function zo({checked:e,onChange:t,label:n,style:r,focusedStyle:o,disabled:s,checkedChar:i="\u2713",uncheckedChar:c=" "}){let l=useContext(z),u=useContext(J),f=useRef(null),h=useRef(null),S=useRef(t);S.current=t;let I=useRef(e);I.current=e;let[P,d]=useState(false),[g,b]=useState(false);useEffect(()=>{if(!(!l||!h.current||!f.current||s))return l.register(h.current,f.current)},[l,s,P]),useEffect(()=>{if(!l||!h.current)return;let B=h.current;return b(l.focusedId===B),l.onFocusChange(F=>{b(F===B);})},[l,P]),useEffect(()=>{if(!u||!h.current||s)return;let B=h.current,F=E=>l?.focusedId!==B?false:E.name==="return"||E.name===" "||E.sequence===" "?(S.current(!I.current),true):false;return u.registerInputHandler(B,F)},[u,l,s,P]);let k={flexDirection:"row",gap:1,...r,...g&&o?o:{}},R=e?i:c,A={color:s?"blackBright":g?"white":r?.color},D={color:s?"blackBright":r?.color};return oe.createElement("box",{style:k,focusable:!s,ref:B=>{B?(f.current=B,h.current=B.focusId,d(true)):(f.current=null,h.current=null,d(false));}},oe.createElement("text",{key:"box",style:A},`[${R}]`),n?oe.createElement("text",{key:"label",style:D},n):null)}function Uo({items:e,value:t,onChange:n,style:r,itemStyle:o,focusedItemStyle:s,selectedItemStyle:i,disabled:c,direction:l="column",gap:u=0,selectedChar:f="\u25CF",unselectedChar:h="\u25CB"}){let S=useContext(z),I=useContext(J),P=useRef(null),d=useRef(null),g=useRef(n);g.current=n;let[b,k]=useState(false),[R,A]=useState(false),[D,B]=useState(()=>{let x=e.findIndex(C=>C.value===t);return x>=0?x:e.findIndex(C=>!C.disabled)}),F=useCallback((x,C)=>{let w=x;for(let y=0;y<e.length;y++)if(w=(w+C+e.length)%e.length,!e[w]?.disabled)return w;return x},[e]);useEffect(()=>{if(!(!S||!d.current||!P.current||c))return S.register(d.current,P.current)},[S,c,b]),useEffect(()=>{if(!S||!d.current)return;let x=d.current;return A(S.focusedId===x),S.onFocusChange(C=>{A(C===x);})},[S,b]),useEffect(()=>{if(!I||!d.current||c)return;let x=d.current,C=w=>{if(S?.focusedId!==x)return false;if(w.name==="up"||w.name==="left"||w.name==="k"||w.name==="tab"&&w.shift)return B(y=>F(y,-1)),true;if(w.name==="down"||w.name==="right"||w.name==="j"||w.name==="tab"&&!w.shift)return B(y=>F(y,1)),true;if(w.name==="return"||w.name===" "||w.sequence===" "){let y=e[D];return y&&!y.disabled&&g.current(y.value),true}return false};return I.registerInputHandler(x,C)},[I,S,c,e,D,F,b]),useEffect(()=>{let x=e.findIndex(C=>C.value===t);x>=0&&B(x);},[t,e]);let E={flexDirection:l,gap:u,...r},M=e.map((x,C)=>{let w=x.value===t,y=C===D,G=c||x.disabled,W=w?f:h,H={flexDirection:"row",gap:1,...o};w&&i&&(H={...H,...i}),R&&y&&s&&(H={...H,...s});let V=G?"blackBright":R&&y?s?.color??"white":w?i?.color??o?.color:o?.color;return oe.createElement("box",{key:C,style:H},oe.createElement("text",{key:"radio",style:{color:V}},`(${W})`),oe.createElement("text",{key:"label",style:{color:V}},x.label))});return oe.createElement("box",{style:E,focusable:!c,ref:x=>{x?(P.current=x,d.current=x.focusId,k(true)):(P.current=null,d.current=null,k(false));}},...M)}var sr=createContext(null);function Yo(){let e=useContext(sr);if(!e)throw new Error("useDialog must be used within a DialogHost");return e}function Qo({children:e}){let[t,n]=useState([]),r=useRef(0),o=useCallback((u,f)=>new Promise(h=>{let S=++r.current;n(I=>[...I,{id:S,type:"alert",content:u,okText:f?.okText??"OK",cancelText:"",style:f?.style,buttonStyle:f?.buttonStyle,okButtonStyle:f?.okButtonStyle,focusedButtonStyle:f?.focusedButtonStyle,backdropStyle:f?.backdropStyle,resolve:()=>h()}]);}),[]),s=useCallback((u,f)=>new Promise(h=>{let S=++r.current;n(I=>[...I,{id:S,type:"confirm",content:u,okText:f?.okText??"OK",cancelText:f?.cancelText??"Cancel",style:f?.style,buttonStyle:f?.buttonStyle,okButtonStyle:f?.okButtonStyle,cancelButtonStyle:f?.cancelButtonStyle,focusedButtonStyle:f?.focusedButtonStyle,backdropStyle:f?.backdropStyle,resolve:h}]);}),[]),i=useCallback((u,f)=>{n(h=>{let S=h.find(I=>I.id===u);return S&&S.resolve(f),h.filter(I=>I.id!==u)});},[]),c={alert:o,confirm:s},l=t[t.length-1];return oe.createElement(sr.Provider,{value:c},e,l&&oe.createElement(Zo,{key:l.id,dialog:l,onDismiss:i}))}function Zo({dialog:e,onDismiss:t}){let n=useContext(z),r=useRef(null),o=useRef(null),s=useRef(null),i=useRef(null),[c,l]=useState("ok"),[u,f]=useState(0);useEffect(()=>{if(!n||u===0)return;let b=[];return r.current&&s.current&&b.push(n.register(s.current,r.current)),o.current&&i.current&&b.push(n.register(i.current,o.current)),s.current&&n.requestFocus(s.current),()=>b.forEach(k=>k())},[n,u]),useEffect(()=>{if(n)return n.onFocusChange(b=>{b===s.current?l("ok"):b===i.current&&l("cancel");})},[n]),qe(b=>{if(b.name==="return"||b.name==="space"){e.type==="alert"?t(e.id,true):t(e.id,c==="ok");return}if(b.name==="escape"){t(e.id,false);return}e.type==="confirm"&&n&&(b.name==="left"||b.name==="right")&&(c==="ok"&&i.current?n.requestFocus(i.current):s.current&&n.requestFocus(s.current));},[e,c,n,t]);let h=typeof e.content=="string",S=h?e.content.length:0,P={minWidth:Math.max(20,h?Math.min(S+6,50):30),maxWidth:50,bg:"black",border:"round",borderColor:"white",padding:1,flexDirection:"column",gap:1,...e.style},d=(b,k)=>{let R={paddingX:2,bg:"blackBright",color:"white"},A={bg:"white",color:"black",bold:true},D=b==="ok"?e.okButtonStyle:e.cancelButtonStyle;return {...R,...e.buttonStyle,...D,...k?{...A,...e.focusedButtonStyle}:{}}},g={position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:999,...e.backdropStyle};return oe.createElement(Bt,{trap:true},oe.createElement("box",{style:g}),oe.createElement("box",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,justifyContent:"center",alignItems:"center",zIndex:1e3}},oe.createElement("box",{style:P},oe.createElement("box",{style:{flexDirection:"column"}},typeof e.content=="string"?oe.createElement("text",null,e.content):e.content),oe.createElement("box",{style:{flexDirection:"row",justifyContent:"flex-end",gap:1}},e.type==="confirm"&&oe.createElement("box",{style:d("cancel",c==="cancel"),focusable:true,ref:b=>{b&&b.focusId&&!i.current&&(o.current=b,i.current=b.focusId,f(k=>k+1));}},oe.createElement("text",null,e.cancelText)),oe.createElement("box",{style:d("ok",c==="ok"),focusable:true,ref:b=>{b&&b.focusId&&!s.current&&(r.current=b,s.current=b.focusId,f(k=>k+1));}},oe.createElement("text",null,e.okText))))))}function ns(e,t){let n=[],r=t.split("");if(e<=r.length)for(let o=0;o<e;o++)n.push(r[o]);else for(let o=0;o<r.length&&n.length<e;o++)for(let s=0;s<r.length&&n.length<e;s++)n.push(r[o]+r[s]);return n}function rs({children:e,activationKey:t="ctrl+o",hintStyle:n,hintBg:r="yellow",hintFg:o="black",hintChars:s="asdfghjklqwertyuiopzxcvbnm",enabled:i=true,debug:c=false}){let l=c?(...x)=>console.error("[JumpNav]",...x):()=>{},[u,f]=useState(false),[h,S]=useState(""),[I,P]=useState([]),d=useContext(J),g=useContext(z),b=useContext(se);useEffect(()=>{l("Mounted, inputCtx:",!!d,"focusCtx:",!!g,"enabled:",i);},[]);let R=useCallback(x=>{let C=x.toLowerCase().split("+");return {ctrl:C.includes("ctrl"),alt:C.includes("alt"),shift:C.includes("shift"),meta:C.includes("meta"),name:C[C.length-1]??""}},[])(t),A=useCallback(()=>{if(!g?.getActiveElements){l("refreshElements: no getActiveElements");return}let x=g.getActiveElements();l("getActiveElements returned",x.length,"elements");let C=x.map(({id:w,node:y})=>({id:w,node:y,layout:b?.getLayout(y)??y.layout}));C.sort((w,y)=>w.layout.y!==y.layout.y?w.layout.y-y.layout.y:w.layout.x-y.layout.x),P(C);},[g,b,l]),D=useRef(false);useEffect(()=>{u&&!D.current&&(l("Activated! Refreshing elements..."),A()),D.current=u;},[u,A,l]);let B=I.filter(x=>x.layout.width>0&&x.layout.height>0),F=ns(B.length,s),E=useMemo(()=>{let x=new Map;return B.forEach((C,w)=>{F[w]&&x.set(F[w],C.id);}),x},[B,F]);useEffect(()=>{if(!d||!i){l("Not subscribing - inputCtx:",!!d,"enabled:",i);return}l("Subscribing to priority input, activation key:",t);let x=C=>{let w=C.name===R.name,y=!!C.ctrl===R.ctrl,G=!!C.alt===R.alt,W=!!C.shift===R.shift,H=!!C.meta===R.meta;if(!u&&w&&y&&G&&W&&H)return l("Activation key matched! Activating..."),f(true),S(""),true;if(u){if(C.name==="escape")return l("Escape pressed, deactivating"),f(false),S(""),true;if(C.name==="backspace")return S(""),true;if(C.sequence&&C.sequence.length===1&&/[a-z]/i.test(C.sequence)){let V=h+C.sequence.toLowerCase();l("Buffer:",V);let q=E.get(V);return q?(l("Jumping to",q),g?.requestFocus(q),f(false),S(""),true):[...E.keys()].some(K=>K.startsWith(V))?(S(V),true):(S(""),true)}return true}return false};return d.subscribePriority(x)},[d,i,u,R,h,E,g,t,l]);let M=u?oe.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:99998}},...B.map((x,C)=>{let w=F[C];if(!w)return null;let{x:y,y:G}=x.layout,W=w.startsWith(h)&&h.length>0;return oe.createElement("box",{key:x.id,style:{position:"absolute",top:G,left:Math.max(0,y-w.length-2),bg:W?"cyan":r,color:o,paddingX:1,zIndex:99999,...n}},oe.createElement("text",{style:{bold:true,color:o}},w))}),oe.createElement("box",{style:{position:"absolute",bottom:0,left:0,right:0,bg:"blackBright",paddingX:1,zIndex:99999}},oe.createElement("text",{style:{color:"white"}},h?`Jump: ${h}_`:"Press a key to jump \u2022 ESC to cancel"))):null;return oe.createElement(oe.Fragment,null,e,M)}var Le=join(tmpdir(),"glyph-image-cache");function ht(e){return e.startsWith("http://")||e.startsWith("https://")}function ls(e,t){let n=createHash("md5").update(e).digest("hex"),r=t?as(t):cs(e)||".png";return join(Le,`${n}${r}`)}function cs(e){try{let r=new URL(e).pathname.match(/\.(png|jpg|jpeg|gif|webp|bmp|ico)/i);if(r){let o=r[0].toLowerCase();return o===".jpg"?".jpeg":o}return ""}catch{return ""}}function as(e){switch(e){case "png":return ".png";case "jpeg":return ".jpeg";case "gif":return ".gif";case "webp":return ".webp";default:return ".png"}}function nn(e){if(ht(e))try{let t=new URL(e),n=t.pathname;return basename(n)||t.hostname}catch{return "remote-image"}return basename(e)}function ar(){existsSync(Le)||mkdirSync(Le,{recursive:true});}async function ur(e){let t=nn(e);return ht(e)?fs(e,t):us(e,t)}async function us(e,t){if(!existsSync(e))throw new Error(`Image not found: ${e}`);return {data:readFileSync(e),name:t,localPath:e,isRemote:false}}async function fs(e,t){ar();let n=createHash("md5").update(e).digest("hex"),r=[".png",".jpeg",".gif",".webp"];for(let u of r){let f=join(Le,`${n}${u}`);if(existsSync(f))return {data:readFileSync(f),name:t,localPath:f,isRemote:true}}let o=await fetch(e);if(!o.ok)throw new Error(`Failed to download image: ${o.status} ${o.statusText}`);let s=await o.arrayBuffer(),i=Buffer.from(s);if(!ps(i))throw new Error(`Invalid image data from: ${e}`);let c=gt(i),l=ls(e,c);return writeFileSync(l,i),{data:i,name:t,localPath:l,isRemote:true}}function ps(e){return e.length<4?false:e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71||e[0]===255&&e[1]===216&&e[2]===255||e[0]===71&&e[1]===73&&e[2]===70||e[0]===66&&e[1]===77||e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e.length>=12&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80||e[0]===0&&e[1]===0&&e[2]===1&&e[3]===0}function gt(e){return e.length<4?"unknown":e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"png":e[0]===255&&e[1]===216&&e[2]===255?"jpeg":e[0]===71&&e[1]===73&&e[2]===70?"gif":e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e.length>=12&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80?"webp":"unknown"}function fr(e,t){let n=gt(e);if(n==="png")return e;ar();let r=createHash("md5").update(e).digest("hex"),o=join(Le,`${r}.${n}`),s=join(Le,`${r}.png`);try{writeFileSync(o,e);let i=platform(),c=!1;if(i==="darwin")try{execSync(`sips -s format png "${o}" --out "${s}" 2>/dev/null`,{stdio:"pipe"}),c=!0;}catch{}if(!c)try{execSync(`magick "${o}" "${s}" 2>/dev/null`,{stdio:"pipe"}),c=!0;}catch{}if(!c)try{execSync(`convert "${o}" "${s}" 2>/dev/null`,{stdio:"pipe"}),c=!0;}catch{}if(c&&existsSync(s)){let l=readFileSync(s);try{unlinkSync(o);}catch{}try{unlinkSync(s);}catch{}return l}try{unlinkSync(o);}catch{}return null}catch{try{unlinkSync(o);}catch{}try{unlinkSync(s);}catch{}return null}}function ms(){let e=platform();return e==="darwin"?"quicklook":e==="linux"||e==="win32"?"open":"none"}async function rn(e){switch(ms()){case "quicklook":return hs(e);case "open":return ys(e);case "none":throw new Error("No preview method available on this platform")}}function hs(e){return new Promise((t,n)=>{let r=spawn("qlmanage",["-p",e],{detached:false,stdio:["ignore","ignore","ignore"]});r.on("error",o=>{n(new Error(`Failed to open Quick Look: ${o.message}`));}),setTimeout(()=>{gs();},50),r.on("close",o=>{t();});})}function gs(){exec(`osascript -e '
1
+ import oe,{createContext,forwardRef,useState,useContext,useRef,useEffect,useLayoutEffect,useMemo,useCallback}from'react';import Rr from'react-reconciler';import xe from'string-width';import Fn,{FlexDirection,Justify,Align,Direction,Edge,Wrap,Gutter,PositionType,Overflow,MeasureMode}from'yoga-layout';import {writeFileSync,existsSync,readFileSync,unlinkSync,mkdirSync}from'fs';import {createHash}from'crypto';import {join,basename}from'path';import {tmpdir,platform}from'os';import {execSync,spawn,exec}from'child_process';var vr=0;function cn(){return `glyph-focus-${vr++}`}function an(e,t){let n=t.style??{};return {type:e,props:t,style:n,children:[],rawTextChildren:[],parent:null,yogaNode:null,text:null,layout:{x:0,y:0,width:0,height:0,innerX:0,innerY:0,innerWidth:0,innerHeight:0},focusId:e==="input"||t.focusable?cn():null,hidden:false}}function wt(e,t){t.parent=e,e.children.push(t);}function un(e,t){let n=e.children.indexOf(t);n!==-1&&(e.children.splice(n,1),t.parent=null);}function fn(e,t,n){t.parent=e;let r=e.children.indexOf(n);r!==-1?e.children.splice(r,0,t):e.children.push(t);}function st(e){let t={},n=e;for(;n;){let r=n.style;t.color===void 0&&r.color!==void 0&&(t.color=r.color),t.bg===void 0&&r.bg!==void 0&&(t.bg=r.bg),t.bold===void 0&&r.bold!==void 0&&(t.bold=r.bold),t.dim===void 0&&r.dim!==void 0&&(t.dim=r.dim),t.italic===void 0&&r.italic!==void 0&&(t.italic=r.italic),t.underline===void 0&&r.underline!==void 0&&(t.underline=r.underline),n=n.parent;}return t}function It(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=It(n);return t}var vt=32,pn={supportsMutation:true,supportsPersistence:false,supportsHydration:false,isPrimaryRenderer:true,scheduleTimeout:setTimeout,cancelTimeout:clearTimeout,noTimeout:-1,supportsMicrotasks:true,scheduleMicrotask:queueMicrotask,getCurrentUpdatePriority:()=>vt,setCurrentUpdatePriority:e=>{},resolveUpdatePriority:()=>vt,getCurrentEventPriority:()=>vt,resolveEventType:()=>null,resolveEventTimeStamp:()=>-1.1,shouldAttemptEagerTransition:()=>false,getInstanceFromNode:()=>null,beforeActiveInstanceBlur:()=>{},afterActiveInstanceBlur:()=>{},prepareScopeUpdate:()=>{},getInstanceFromScope:()=>null,detachDeletedInstance:()=>{},requestPostPaintCallback:e=>{},maySuspendCommit:(e,t)=>false,preloadInstance:(e,t)=>true,startSuspendingCommit:()=>{},suspendInstance:(e,t)=>{},waitForCommitToBeReady:()=>null,NotPendingTransition:null,HostTransitionContext:{$$typeof:Symbol.for("react.context"),_currentValue:null},resetFormInstance:e=>{},bindToConsole:(e,t,n)=>Function.prototype.bind.call(console[e],console,...t),supportsResources:false,isHostHoistableType:(e,t)=>false,supportsSingletons:false,isHostSingletonType:e=>false,supportsTestSelectors:false,createInstance(e,t,n,r,o){return an(e,t)},createTextInstance(e,t,n,r){return {type:"raw-text",text:e,parent:null}},appendInitialChild(e,t){if(t.type==="raw-text"){let n=t;n.parent=e,e.rawTextChildren.push(n),e.text=e.rawTextChildren.map(r=>r.text).join("");}else wt(e,t);},finalizeInitialChildren(e,t,n,r,o){return false},shouldSetTextContent(e,t){return false},getRootHostContext(e){return {}},getChildHostContext(e,t,n){return e},getPublicInstance(e){return e},prepareForCommit(e){return null},resetAfterCommit(e){e.onCommit();},preparePortalMount(){},appendChild(e,t){if(t.type==="raw-text"){let n=t;n.parent=e,e.rawTextChildren.push(n),e.text=e.rawTextChildren.map(r=>r.text).join("");}else wt(e,t);},appendChildToContainer(e,t){if(t.type==="raw-text")return;let n=t;n.parent=null,e.children.push(n);},insertBefore(e,t,n){t.type==="raw-text"||n.type==="raw-text"||fn(e,t,n);},insertInContainerBefore(e,t,n){if(t.type==="raw-text"||n.type==="raw-text")return;let r=t,o=n,s=e.children.indexOf(o);s!==-1?e.children.splice(s,0,r):e.children.push(r);},removeChild(e,t){if(t.type==="raw-text"){let n=t;n.parent=null;let r=e.rawTextChildren.indexOf(n);r!==-1&&e.rawTextChildren.splice(r,1),e.text=e.rawTextChildren.map(o=>o.text).join("")||null;return}un(e,t);},removeChildFromContainer(e,t){if(t.type==="raw-text")return;let n=t,r=e.children.indexOf(n);r!==-1&&e.children.splice(r,1);},commitTextUpdate(e,t,n){e.text=n,e.parent&&(e.parent.text=e.parent.rawTextChildren.map(r=>r.text).join(""));},commitUpdate(e,t,n,r,o){e.props=r,e.style=r.style??{},r.focusable&&!e.focusId&&(e.focusId=`focus-${Math.random().toString(36).slice(2,9)}`);},hideInstance(e){e.hidden=true;},hideTextInstance(e){e.text="";},unhideInstance(e,t){e.hidden=false;},unhideTextInstance(e,t){e.text=t;},clearContainer(e){e.children.length=0;},resetTextContent(e){e.text=null;}};var je=Rr(pn);je.injectIntoDevTools({bundleType:process.env.NODE_ENV==="production"?0:1,version:"0.1.0",rendererPackageName:"glyph"});var it=class{stdout;stdin;wasRaw=false;cleanedUp=false;dataHandlers=new Set;stdinAttached=false;oscState="normal";oscAccum="";escFlushTimer=null;palette=new Map;paletteResolve=null;constructor(t=process.stdout,n=process.stdin){this.stdout=t,this.stdin=n;}get columns(){return this.stdout.columns||80}get rows(){return this.stdout.rows||24}enterRawMode(){this.stdin.isTTY&&(this.wasRaw=this.stdin.isRaw,this.stdin.setRawMode(true),this.stdin.resume(),this.stdin.setEncoding("utf-8"));}exitRawMode(){this.stdin.isTTY&&!this.wasRaw&&(this.stdin.setRawMode(false),this.stdin.pause());}write(t){this.stdout.write(t);}hideCursor(){this.write("\x1B[?25l");}showCursor(){this.write("\x1B[?25h");}moveCursor(t,n){this.write(`\x1B[${n+1};${t+1}H`);}setCursorColor(t){this.write(`\x1B]12;${t}\x07`);}resetCursorColor(){this.write("\x1B]112\x07");}enterAltScreen(){this.write("\x1B[?1049h");}exitAltScreen(){this.write("\x1B[?1049l");}clearScreen(){this.write("\x1B[2J\x1B[H");}resetStyles(){this.write("\x1B[0m");}enableKittyKeyboard(){this.write("\x1B[>1u");}disableKittyKeyboard(){this.write("\x1B[<u");}setup(){this.enterRawMode(),this.enterAltScreen(),this.enableKittyKeyboard(),this.hideCursor(),this.clearScreen(),this.attachStdinListener(),this.installCleanupHandlers();}cleanup(){this.cleanedUp||(this.cleanedUp=true,this.escFlushTimer!==null&&(clearTimeout(this.escFlushTimer),this.escFlushTimer=null),this.resetStyles(),this.resetCursorColor(),this.disableKittyKeyboard(),this.showCursor(),this.exitAltScreen(),this.exitRawMode());}suspend(){this.escFlushTimer!==null&&(clearTimeout(this.escFlushTimer),this.escFlushTimer=null),this.oscState="normal",this.oscAccum="",this.resetStyles(),this.resetCursorColor(),this.disableKittyKeyboard(),this.showCursor(),this.exitAltScreen(),this.exitRawMode();}resume(){this.enterRawMode(),this.enterAltScreen(),this.enableKittyKeyboard(),this.hideCursor(),this.clearScreen();}attachStdinListener(){this.stdinAttached||(this.stdinAttached=true,this.stdin.on("data",t=>{let n=typeof t=="string"?t:t.toString("utf-8");this.dispatchFiltered(n);}));}onData(t){return this.dataHandlers.add(t),()=>{this.dataHandlers.delete(t);}}dispatchFiltered(t){this.escFlushTimer!==null&&(clearTimeout(this.escFlushTimer),this.escFlushTimer=null);let n=this.filterOsc(t);if(n.length>0)for(let r of this.dataHandlers)r(n);this.oscState==="esc"&&(this.escFlushTimer=setTimeout(()=>{this.escFlushTimer=null,this.oscState="normal";for(let r of this.dataHandlers)r("\x1B");},50));}filterOsc(t){let n="";for(let r=0;r<t.length;r++){let o=t[r],s=t.charCodeAt(r);switch(this.oscState){case "normal":s===27?this.oscState="esc":n+=o;break;case "esc":o==="]"?(this.oscState="osc",this.oscAccum=""):(n+="\x1B"+o,this.oscState="normal");break;case "osc":s===7?(this.handleOscResponse(this.oscAccum),this.oscAccum="",this.oscState="normal"):s===27?this.oscState="osc_esc":this.oscAccum+=o;break;case "osc_esc":o==="\\"?(this.handleOscResponse(this.oscAccum),this.oscAccum="",this.oscState="normal"):(this.oscAccum+="\x1B"+o,this.oscState="osc");break}}return n}handleOscResponse(t){let n=t.match(/^4;(\d+);rgb:([0-9a-fA-F]+)\/([0-9a-fA-F]+)\/([0-9a-fA-F]+)/);if(n){let r=parseInt(n[1],10),o=parseInt(n[2].substring(0,2),16),s=parseInt(n[3].substring(0,2),16),i=parseInt(n[4].substring(0,2),16);this.palette.set(r,[o,s,i]),this.palette.size>=16&&this.paletteResolve&&(this.paletteResolve(),this.paletteResolve=null);}}queryPalette(){return new Promise(t=>{let n=()=>t(this.palette),r=setTimeout(n,200);this.paletteResolve=()=>{clearTimeout(r),n();};let o="";for(let s=0;s<16;s++)o+=`\x1B]4;${s};?\x07`;this.write(o);})}onResize(t){return this.stdout.on("resize",t),()=>{this.stdout.off("resize",t);}}installCleanupHandlers(){let t=()=>this.cleanup();process.on("exit",t);let n=r=>{t(),process.kill(process.pid,r);};process.once("SIGINT",()=>n("SIGINT")),process.once("SIGTERM",()=>n("SIGTERM")),process.on("uncaughtException",r=>{t(),console.error(r),process.exit(1);}),process.on("unhandledRejection",r=>{t(),console.error(r),process.exit(1);});}};function dn(e){switch(e){case 9:return "tab";case 13:return "return";case 27:return "escape";case 32:return "space";case 127:return "backspace";case 57358:return "capslock";case 57359:return "scrolllock";case 57360:return "numlock";case 57361:return "printscreen";case 57362:return "pause";case 57363:return "menu";case 57364:return "f13";case 57365:return "f14";case 57366:return "f15";case 57367:return "f16";case 57368:return "f17";case 57369:return "f18";case 57370:return "f19";case 57371:return "f20";case 57372:return "f21";case 57373:return "f22";case 57374:return "f23";case 57375:return "f24";case 57376:return "f25";case 57399:return "kp0";case 57400:return "kp1";case 57401:return "kp2";case 57402:return "kp3";case 57403:return "kp4";case 57404:return "kp5";case 57405:return "kp6";case 57406:return "kp7";case 57407:return "kp8";case 57408:return "kp9";case 57409:return "kpdecimal";case 57410:return "kpdivide";case 57411:return "kpmultiply";case 57412:return "kpminus";case 57413:return "kpplus";case 57414:return "kpenter";case 57415:return "kpequal";case 57416:return "kpleft";case 57417:return "kpright";case 57418:return "kpup";case 57419:return "kpdown";case 57420:return "kppageup";case 57421:return "kppagedown";case 57422:return "kphome";case 57423:return "kpend";case 57424:return "kpinsert";case 57425:return "kpdelete";case 57428:return "mediaplaypause";case 57429:return "mediastop";case 57430:return "mediaprev";case 57431:return "medianext";case 57432:return "mediarewind";case 57433:return "mediafastforward";case 57434:return "mediamute";case 57435:return "volumedown";case 57436:return "volumeup";default:return e>=32&&e<=126?String.fromCharCode(e).toLowerCase():"unknown"}}function kr(e){switch(e.split(";")[0]){case "1":return "home";case "2":return "insert";case "3":return "delete";case "4":return "end";case "5":return "pageup";case "6":return "pagedown";case "7":return "home";case "8":return "end";case "11":return "f1";case "12":return "f2";case "13":return "f3";case "14":return "f4";case "15":return "f5";case "17":return "f6";case "18":return "f7";case "19":return "f8";case "20":return "f9";case "21":return "f10";case "23":return "f11";case "24":return "f12";case "25":return "f13";case "26":return "f14";case "28":return "f15";case "29":return "f16";case "31":return "f17";case "32":return "f18";case "33":return "f19";case "34":return "f20";default:return "unknown"}}function lt(e,t){let n=t-1;n&1&&(e.shift=true),n&2&&(e.alt=true),n&4&&(e.ctrl=true),n&8&&(e.meta=true);}function mn(e){let t=[],n=0;for(;n<e.length;){let r=e[n],o=e.charCodeAt(n);if(r==="\x1B"){if(e[n+1]==="["){let s=Tr(e,n);if(s){t.push(s.key),n=s.end;continue}}if(e[n+1]==="O"){let s=Pr(e,n);if(s){t.push(s.key),n=s.end;continue}}if(n+1<e.length&&e.charCodeAt(n+1)>=32){let s=e[n+1];t.push({name:s===" "?"space":s.toLowerCase(),sequence:e.substring(n,n+2),alt:true}),n+=2;continue}t.push({name:"escape",sequence:"\x1B"}),n++;continue}if(o>=1&&o<=26){let s=String.fromCharCode(o+96);o===13?t.push({name:"return",sequence:"\r"}):o===9?t.push({name:"tab",sequence:" "}):o===8?t.push({name:"backspace",sequence:"\b"}):t.push({name:s,sequence:r,ctrl:true}),n++;continue}if(o===127){t.push({name:"backspace",sequence:r}),n++;continue}t.push({name:r===" "?"space":r,sequence:r}),n++;}return t}function Pr(e,t){if(t+2>=e.length)return null;let n=e[t+2],r=e.substring(t,t+3),o;switch(n){case "A":o={name:"up",sequence:r};break;case "B":o={name:"down",sequence:r};break;case "C":o={name:"right",sequence:r};break;case "D":o={name:"left",sequence:r};break;case "H":o={name:"home",sequence:r};break;case "F":o={name:"end",sequence:r};break;case "P":o={name:"f1",sequence:r};break;case "Q":o={name:"f2",sequence:r};break;case "R":o={name:"f3",sequence:r};break;case "S":o={name:"f4",sequence:r};break;case "j":o={name:"kpmultiply",sequence:r};break;case "k":o={name:"kpplus",sequence:r};break;case "l":o={name:"kpcomma",sequence:r};break;case "m":o={name:"kpminus",sequence:r};break;case "n":o={name:"kpdecimal",sequence:r};break;case "o":o={name:"kpdivide",sequence:r};break;case "p":o={name:"kp0",sequence:r};break;case "q":o={name:"kp1",sequence:r};break;case "r":o={name:"kp2",sequence:r};break;case "s":o={name:"kp3",sequence:r};break;case "t":o={name:"kp4",sequence:r};break;case "u":o={name:"kp5",sequence:r};break;case "v":o={name:"kp6",sequence:r};break;case "w":o={name:"kp7",sequence:r};break;case "x":o={name:"kp8",sequence:r};break;case "y":o={name:"kp9",sequence:r};break;case "M":o={name:"kpenter",sequence:r};break;default:return null}return {key:o,end:t+3}}function Tr(e,t){let n=t+2,r="";for(;n<e.length;){let c=e.charCodeAt(n);if(c>=48&&c<=63)r+=e[n],n++;else break}if(n>=e.length)return null;let o=e[n],s=e.substring(t,n+1);n++;let i;switch(o){case "A":i={name:"up",sequence:s};break;case "B":i={name:"down",sequence:s};break;case "C":i={name:"right",sequence:s};break;case "D":i={name:"left",sequence:s};break;case "H":i={name:"home",sequence:s};break;case "F":i={name:"end",sequence:s};break;case "Z":i={name:"tab",sequence:s,shift:true};break;case "P":i={name:"f1",sequence:s};break;case "Q":i={name:"f2",sequence:s};break;case "R":i={name:"f3",sequence:s};break;case "S":i={name:"f4",sequence:s};break;case "~":{if(r.startsWith("27;")){let c=r.split(";"),l=parseInt(c[1]??"1",10),u=parseInt(c[2]??"0",10);i={name:dn(u),sequence:s},lt(i,l);break}if(i={name:kr(r),sequence:s},r.includes(";")){let c=r.split(";"),l=parseInt(c[1]??"1",10);lt(i,l);}break}case "u":{let c=r.split(";"),l=parseInt(c[0]??"0",10),u=parseInt(c[1]??"1",10);i={name:dn(l),sequence:s},lt(i,u);break}case "I":i={name:"focus",sequence:s};break;case "O":i={name:"blur",sequence:s};break;default:i={name:"unknown",sequence:s};}if(r.includes(";")&&!["~","u"].includes(o)){let c=r.split(";"),l=parseInt(c[c.length-1]??"1",10);l>=1&&l<=16&&lt(i,l);}return {key:i,end:n}}var Er={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",blackBright:"\x1B[90m",redBright:"\x1B[91m",greenBright:"\x1B[92m",yellowBright:"\x1B[93m",blueBright:"\x1B[94m",magentaBright:"\x1B[95m",cyanBright:"\x1B[96m",whiteBright:"\x1B[97m"},Nr={black:"\x1B[40m",red:"\x1B[41m",green:"\x1B[42m",yellow:"\x1B[43m",blue:"\x1B[44m",magenta:"\x1B[45m",cyan:"\x1B[46m",white:"\x1B[47m",blackBright:"\x1B[100m",redBright:"\x1B[101m",greenBright:"\x1B[102m",yellowBright:"\x1B[103m",blueBright:"\x1B[104m",magentaBright:"\x1B[105m",cyanBright:"\x1B[106m",whiteBright:"\x1B[107m"};function Rt(e){let t=e.replace("#",""),n=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),o=parseInt(t.substring(4,6),16);return {r:n,g:r,b:o}}function hn(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=Rt(e);return `\x1B[38;2;${o};${s};${i}m`}return Er[e]??"\x1B[39m"}if(typeof e=="number")return `\x1B[38;5;${e}m`;let{r:t,g:n,b:r}=e;return `\x1B[38;2;${t};${n};${r}m`}function gn(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=Rt(e);return `\x1B[48;2;${o};${s};${i}m`}return Nr[e]??"\x1B[49m"}if(typeof e=="number")return `\x1B[48;5;${e}m`;let{r:t,g:n,b:r}=e;return `\x1B[48;2;${t};${n};${r}m`}var yn={black:[0,0,0],red:[170,0,0],green:[0,170,0],yellow:[170,170,0],blue:[0,0,170],magenta:[170,0,170],cyan:[0,170,170],white:[170,170,170],blackBright:[85,85,85],redBright:[255,85,85],greenBright:[85,255,85],yellowBright:[255,255,85],blueBright:[85,85,255],magentaBright:[255,85,255],cyanBright:[85,255,255],whiteBright:[255,255,255]},xn=["black","red","green","yellow","blue","magenta","cyan","white","blackBright","redBright","greenBright","yellowBright","blueBright","magentaBright","cyanBright","whiteBright"],$e=null;function bn(e){e.size>0&&($e=e);}function Br(e){if($e){let t=xn.indexOf(e);if(t!==-1){let n=$e.get(t);if(n)return n}}return yn[e]??null}function Gr(e){if(typeof e=="string"){if(e.startsWith("#")){let t=Rt(e);return [t.r,t.g,t.b]}return Br(e)}if(typeof e=="number"){if(e<16){if($e){let s=$e.get(e);if(s)return s}return yn[xn[e]]}if(e>=232){let s=(e-232)*10+8;return [s,s,s]}let t=e-16,n=t%6*51,r=Math.floor(t/6)%6*51;return [Math.floor(t/36)*51,r,n]}return [e.r,e.g,e.b]}function ct(e){let t=Gr(e);if(!t)return false;let[n,r,o]=t.map(i=>{let c=i/255;return c<=.03928?c/12.92:Math.pow((c+.055)/1.055,2.4)});return .2126*n+.7152*r+.0722*o>.4}function kt(e,t){return e===t?true:e==null||t==null?false:typeof e=="object"&&typeof t=="object"?e.r===t.r&&e.g===t.g&&e.b===t.b:false}function Cn(e){return e&&ct(e)?"black":"white"}var Ve=class e{width;height;cells;constructor(t,n){this.width=t,this.height=n,this.cells=new Array(t*n),this.clear();}clear(){for(let t=0;t<this.cells.length;t++)this.cells[t]={ch:" "};}resize(t,n){this.width=t,this.height=n,this.cells=new Array(t*n),this.clear();}get(t,n){if(!(t<0||t>=this.width||n<0||n>=this.height))return this.cells[n*this.width+t]}set(t,n,r){t<0||t>=this.width||n<0||n>=this.height||(this.cells[n*this.width+t]=r);}setChar(t,n,r,o,s,i,c,l,u){t<0||t>=this.width||n<0||n>=this.height||(this.cells[n*this.width+t]={ch:r,fg:o,bg:s,bold:i,dim:c,italic:l,underline:u});}fillRect(t,n,r,o,s,i,c){for(let l=n;l<n+o;l++)for(let u=t;u<t+r;u++)this.setChar(u,l,s,i,c);}clone(){let t=new e(this.width,this.height);for(let n=0;n<this.cells.length;n++){let r=this.cells[n];t.cells[n]={...r};}return t}cellsEqual(t,n){return t.ch===n.ch&&kt(t.fg,n.fg)&&kt(t.bg,n.bg)&&(t.bold??false)===(n.bold??false)&&(t.dim??false)===(n.dim??false)&&(t.italic??false)===(n.italic??false)&&(t.underline??false)===(n.underline??false)}};var Fr={single:{topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502"},double:{topLeft:"\u2554",topRight:"\u2557",bottomLeft:"\u255A",bottomRight:"\u255D",horizontal:"\u2550",vertical:"\u2551"},round:{topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502"},ascii:{topLeft:"+",topRight:"+",bottomLeft:"+",bottomRight:"+",horizontal:"-",vertical:"|"}};function Sn(e){return e==="none"?null:Fr[e]}function wn(e,t,n,r){if(e.length===0)return {width:0,height:0};let o=e.split(`
2
+ `);if(n===MeasureMode.Undefined||r==="none"){let l=0;for(let u of o){let f=xe(u);f>l&&(l=f);}return {width:l,height:o.length}}let s=Math.max(1,Math.floor(t)),i=me(o,s,r),c=0;for(let l of i){let u=xe(l);u>c&&(c=u);}return {width:c,height:i.length}}function me(e,t,n){let r=[];for(let o of e){if(xe(o)<=t){r.push(o);continue}if(n==="truncate"){r.push(In(o,t));continue}if(n==="ellipsis"){r.push(Mr(o,t));continue}let i=Ar(o,t);r.push(...i);}return r}function In(e,t){let n="",r=0;for(let o of e){let s=xe(o);if(r+s>t)break;n+=o,r+=s;}return n}function Mr(e,t){if(t<=1)return t===1?"\u2026":"";let n=In(e,t-1);return xe(n)<xe(e)?n+"\u2026":e}function Ar(e,t){let n=[],r="",o=0,s="",i=0;for(let c=0;c<=e.length;c++){let l=e[c],u=c===e.length,f=l===" ";if(u||f){if(s.length>0){if(o+i<=t)r+=s,o+=i;else if(i<=t)r.length>0&&n.push(r),r=s,o=i;else for(let m of s){let S=xe(m);o+S>t&&r.length>0&&(n.push(r),r="",o=0),r+=m,o+=S;}s="",i=0;}f&&(o+1<=t?(r+=" ",o+=1):(r.length>0&&n.push(r),r=" ",o=1));}else l&&(s+=l,i+=xe(l));}return r.length>0&&n.push(r),n.length>0?n:[""]}var vn={30:"black",31:"red",32:"green",33:"yellow",34:"blue",35:"magenta",36:"cyan",37:"white",90:"blackBright",91:"redBright",92:"greenBright",93:"yellowBright",94:"blueBright",95:"magentaBright",96:"cyanBright",97:"whiteBright"},Rn={40:"black",41:"red",42:"green",43:"yellow",44:"blue",45:"magenta",46:"cyan",47:"white",100:"blackBright",101:"redBright",102:"greenBright",103:"yellowBright",104:"blueBright",105:"magentaBright",106:"cyanBright",107:"whiteBright"};function Hr(e,t){let n=0;for(;n<e.length;){let r=e[n];switch(r){case 0:t.fg=void 0,t.bg=void 0,t.bold=false,t.dim=false,t.italic=false,t.underline=false;break;case 1:t.bold=true;break;case 2:t.dim=true;break;case 3:t.italic=true;break;case 4:t.underline=true;break;case 22:t.bold=false,t.dim=false;break;case 23:t.italic=false;break;case 24:t.underline=false;break;case 39:t.fg=void 0;break;case 49:t.bg=void 0;break;case 38:if(e[n+1]===5&&e[n+2]!==void 0)t.fg=e[n+2],n+=2;else if(e[n+1]===2&&e[n+4]!==void 0){let o=e[n+2]??0,s=e[n+3]??0,i=e[n+4]??0;t.fg=`#${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`,n+=4;}break;case 48:if(e[n+1]===5&&e[n+2]!==void 0)t.bg=e[n+2],n+=2;else if(e[n+1]===2&&e[n+4]!==void 0){let o=e[n+2]??0,s=e[n+3]??0,i=e[n+4]??0;t.bg=`#${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`,n+=4;}break;default:vn[r]?t.fg=vn[r]:Rn[r]&&(t.bg=Rn[r]);break}n++;}}function Pt(e){let t=[],n={},r="",o=/\x1b\[([0-9;]*)m/g,s=0,i;for(;(i=o.exec(e))!==null;){let l=e.slice(s,i.index);l&&(r+=l),r&&(t.push({text:r,style:{...n}}),r="");let f=(i[1]||"0").split(";").map(m=>parseInt(m,10)||0);Hr(f,n),s=o.lastIndex;}let c=e.slice(s);return c&&(r+=c),r&&t.push({text:r,style:{...n}}),t}function Tt(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function kn(e,t,n={}){t.clear();let r={},o=[],s={x:0,y:0,width:t.width,height:t.height};for(let i of e)i.hidden||Pn(i,s,i.style.zIndex??0,o);o.sort((i,c)=>i.zIndex-c.zIndex);for(let i of o){let c=$r(i.node,t,i.clip,n);c?.cursorPosition&&(r.cursorPosition=c.cursorPosition);}return r}function Pn(e,t,n,r){if(e.hidden)return;let o=e.style.zIndex??n,s=e.style.clip?jr(t,{x:e.layout.innerX,y:e.layout.innerY,width:e.layout.innerWidth,height:e.layout.innerHeight}):t;if(r.push({node:e,clip:t,zIndex:o}),e.type!=="text"&&e.type!=="input")for(let i of e.children)Pn(i,s,o,r);}function jr(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),o=Math.min(e.x+e.width,t.x+t.width),s=Math.min(e.y+e.height,t.y+t.height);return {x:n,y:r,width:Math.max(0,o-n),height:Math.max(0,s-r)}}function at(e,t,n){return e>=n.x&&e<n.x+n.width&&t>=n.y&&t<n.y+n.height}function $r(e,t,n,r={}){let{x:o,y:s,width:i,height:c,innerX:l,innerY:u,innerWidth:f,innerHeight:m}=e.layout,S=e.style;if(i<=0||c<=0)return;let E=st(e).bg;if(S.bg)for(let h=s;h<s+c;h++)for(let y=o;y<o+i;y++)at(y,h,n)&&t.setChar(y,h," ",void 0,S.bg);let d=S.border?Sn(S.border):null;if(d&&i>=2&&c>=2){let h=S.borderColor,y=E;he(t,n,o,s,d.topLeft,h,y);for(let R=o+1;R<o+i-1;R++)he(t,n,R,s,d.horizontal,h,y);he(t,n,o+i-1,s,d.topRight,h,y),he(t,n,o,s+c-1,d.bottomLeft,h,y);for(let R=o+1;R<o+i-1;R++)he(t,n,R,s+c-1,d.horizontal,h,y);he(t,n,o+i-1,s+c-1,d.bottomRight,h,y);for(let R=s+1;R<s+c-1;R++)he(t,n,o,R,d.vertical,h,y),he(t,n,o+i-1,R,d.vertical,h,y);}if(e.type==="text")Vr(e,t,n);else if(e.type==="input")return Or(e,t,n,r)}function he(e,t,n,r,o,s,i,c,l,u,f){at(n,r,t)&&e.setChar(n,r,o,s,i,c,l,u,f);}function Tn(e,t){if(e!==void 0)return e;if(t!==void 0)return ct(t)?"black":"white"}function Vr(e,t,n){let{innerX:r,innerY:o,innerWidth:s,innerHeight:i}=e.layout,c=st(e),l=It(e);if(!l)return;let u=Tn(c.color,c.bg),f=e.style.wrap??"wrap",m=e.style.textAlign??"left",S=l.split(`
3
+ `),I=S.map(d=>Tt(d)),E=me(I,s,f);for(let d=0;d<E.length&&d<i;d++){let h=0,y=0;for(let g=0;g<I.length;g++){let $=me([I[g]],s,f).length;if(d<y+$){h=g;break}y+=$;}let R=E[d],k=xe(R),j=0;m==="center"?j=Math.max(0,Math.floor((s-k)/2)):m==="right"&&(j=Math.max(0,s-k));let V=S[h],B=Pt(V),G=d-y,N=me([I[h]],s,f),M=0;for(let g=0;g<G;g++)M+=N[g].length;let C=M+R.length,b=0,x=0;for(let g of B)for(let $ of g.text){if(x>=M&&x<C){if(xe($)>0){let A=g.style.fg??u,O=g.style.bg??c.bg,U=g.style.bold??c.bold,_=g.style.dim??c.dim,D=g.style.italic??c.italic,q=g.style.underline??c.underline;he(t,n,r+j+b,o+d,$,A,O,U,_,D,q);}b+=xe($);}x++;}}}function Or(e,t,n,r={}){let{cursorInfo:o,useNativeCursor:s}=r,{innerX:i,innerY:c,innerWidth:l,innerHeight:u}=e.layout;if(l<=0||u<=0)return;let f=e.props.value??e.props.defaultValue??"",m=e.props.placeholder??"",S=f||m,I=!f&&!!m,E=e.props.multiline??false,d=st(e),h=Tn(d.color,d.bg),y=d.bg?ct(d.bg)?"blackBright":"whiteBright":"blackBright",R=I?y:h??d.color??e.style.color,k=I?y:R,j=I?true:d.dim,V=o&&o.nodeId===e.focusId,B;if(E&&!I){let G=e.style.wrap??"wrap",N=S.split(`
4
+ `),M=me(N,l,G),C=0,b=0;if(V){let g=o.position,$=0,W=g,A=0;for(let q=0;q<N.length;q++){let H=N[q].length;if(g<=A+H){$=q,W=g-A;break}A+=H+1;}let O=0;for(let q=0;q<$;q++)O+=me([N[q]],l,G).length;let U=me([N[$]],l,G),_=0,D=0;for(let q=0;q<U.length;q++){let H=U[q];if(W<=_+H.length){D=q;break}_+=H.length;}C=O+D,b=xe(N[$].slice(_,_+(W-_)));}let x=Math.max(0,C-u+1);for(let g=0;g<u;g++){let $=x+g;if($>=M.length)break;let W=M[$],A=0;for(let O of W){if(A>=l)break;let U=xe(O);U>0&&he(t,n,i+A,c+g,O,k,d.bg,d.bold,j,d.italic,d.underline),A+=U;}}if(V){let g=C-x;if(g>=0&&g<u){let $=Math.min(b,l-1),W=i+$,A=c+g;if(at(W,A,n)&&W<i+l)if(s)B={cursorPosition:{x:W,y:A,bg:d.bg}};else {let O=t.get(W,A),U=O?.ch&&O.ch!==" "?O.ch:"\u258C",_=d.bg??"black",D=d.color??"white";t.setChar(W,A,U,_,D,O?.bold,O?.dim,O?.italic,false);}}}}else {let G=0;for(let N of S){if(G>=l)break;let M=xe(N);M>0&&he(t,n,i+G,c,N,k,d.bg,d.bold,j,d.italic,d.underline),G+=M;}if(V){let N=Math.min(o.position,l-1),M=i+N;if(at(M,c,n)&&M<i+l)if(s)B={cursorPosition:{x:M,y:c,bg:d.bg}};else {let C=t.get(M,c),b=C?.ch&&C.ch!==" "?C.ch:"\u258C",x=d.bg??"black",g=d.color??"white";t.setChar(M,c,b,x,g,C?.bold,C?.dim,C?.italic,false);}}}return B}var Dr="\x1B",Re=`${Dr}[`;function Kr(e,t){return `${Re}${t+1};${e+1}H`}function Wr(e){let t=`${Re}0m`;return e.bold&&(t+=`${Re}1m`),e.dim&&(t+=`${Re}2m`),e.italic&&(t+=`${Re}3m`),e.underline&&(t+=`${Re}4m`),e.fg!=null&&(t+=hn(e.fg)),e.bg!=null&&(t+=gn(e.bg)),t}function En(e,t,n){let r="",o=-1,s=-1,i="";for(let c=0;c<t.height;c++)for(let l=0;l<t.width;l++){let u=t.get(l,c);if(!n){let m=e.get(l,c);if(m&&t.cellsEqual(u,m))continue}(s!==c||o!==l)&&(r+=Kr(l,c));let f=Wr(u);f!==i&&(r+=f,i=f),r+=u.ch,o=l+1,s=c;}return r.length>0&&(r+=`${Re}0m`),r}var Xr={row:FlexDirection.Row,column:FlexDirection.Column},Ur={"flex-start":Justify.FlexStart,center:Justify.Center,"flex-end":Justify.FlexEnd,"space-between":Justify.SpaceBetween,"space-around":Justify.SpaceAround},Jr={"flex-start":Align.FlexStart,center:Align.Center,"flex-end":Align.FlexEnd,stretch:Align.Stretch};function Gn(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%"),t(n));}function be(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%")?e.setPositionPercent(t,parseFloat(n)):e.setPosition(t,n));}function Yr(e,t,n){Gn(e,o=>e.setWidth(o),t.width),Gn(e,o=>e.setHeight(o),t.height),t.minWidth!==void 0&&e.setMinWidth(t.minWidth),t.minHeight!==void 0&&e.setMinHeight(t.minHeight),t.maxWidth!==void 0&&e.setMaxWidth(t.maxWidth),t.maxHeight!==void 0&&e.setMaxHeight(t.maxHeight),t.padding!==void 0&&e.setPadding(Edge.All,t.padding),t.paddingX!==void 0&&e.setPadding(Edge.Horizontal,t.paddingX),t.paddingY!==void 0&&e.setPadding(Edge.Vertical,t.paddingY),t.paddingTop!==void 0&&e.setPadding(Edge.Top,t.paddingTop),t.paddingRight!==void 0&&e.setPadding(Edge.Right,t.paddingRight),t.paddingBottom!==void 0&&e.setPadding(Edge.Bottom,t.paddingBottom),t.paddingLeft!==void 0&&e.setPadding(Edge.Left,t.paddingLeft);let r=t.border!=null&&t.border!=="none";e.setBorder(Edge.All,r?1:0),t.flexDirection&&e.setFlexDirection(Xr[t.flexDirection]??FlexDirection.Column),t.flexWrap&&e.setFlexWrap(t.flexWrap==="wrap"?Wrap.Wrap:Wrap.NoWrap),t.justifyContent&&e.setJustifyContent(Ur[t.justifyContent]??Justify.FlexStart),t.alignItems&&e.setAlignItems(Jr[t.alignItems]??Align.Stretch),t.flexGrow!==void 0&&e.setFlexGrow(t.flexGrow),t.flexShrink!==void 0&&e.setFlexShrink(t.flexShrink),t.gap!==void 0&&e.setGap(Gutter.All,t.gap),t.position==="absolute"?e.setPositionType(PositionType.Absolute):e.setPositionType(PositionType.Relative),t.inset!==void 0&&(be(e,Edge.Top,t.inset),be(e,Edge.Right,t.inset),be(e,Edge.Bottom,t.inset),be(e,Edge.Left,t.inset)),be(e,Edge.Top,t.top),be(e,Edge.Right,t.right),be(e,Edge.Bottom,t.bottom),be(e,Edge.Left,t.left),t.clip&&e.setOverflow(Overflow.Hidden);}function Ln(e){let t=Fn.Node.create();if(e.yogaNode=t,Yr(t,e.style,e.type),e.type==="text"||e.type==="input")t.setMeasureFunc((n,r,o,s)=>{let i;return e.type==="input"?(i=e.props.value??e.props.defaultValue??e.props.placeholder??"",i.length===0&&(i=" ")):i=Mn(e),wn(i,n,r,e.style.wrap??"wrap")});else for(let n=0;n<e.children.length;n++){let r=e.children[n];r.hidden||(Ln(r),t.insertChild(r.yogaNode,t.getChildCount()));}}function Mn(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=Mn(n);if(t===""&&e.props.children!=null){if(typeof e.props.children=="string")return e.props.children;if(typeof e.props.children=="number")return String(e.props.children)}return t}function An(e,t,n){let r=e.yogaNode,o=r.getComputedLayout(),s=t+o.left,i=n+o.top,c=o.width,l=o.height,u=e.style.border&&e.style.border!=="none"?1:0,f=r.getComputedPadding(Edge.Top),m=r.getComputedPadding(Edge.Right),S=r.getComputedPadding(Edge.Bottom),I=r.getComputedPadding(Edge.Left),E=s+u+I,d=i+u+f,h=Math.max(0,c-u*2-I-m),y=Math.max(0,l-u*2-f-S),R=e.layout;(!R||R.x!==s||R.y!==i||R.width!==c||R.height!==l||R.innerX!==E||R.innerY!==d||R.innerWidth!==h||R.innerHeight!==y)&&(e.layout={x:s,y:i,width:c,height:l,innerX:E,innerY:d,innerWidth:h,innerHeight:y});for(let k of e.children)k.hidden||!k.yogaNode||An(k,s,i);}function Hn(e,t,n){let r=Fn.Node.create();r.setWidth(t),r.setHeight(n),r.setFlexDirection(FlexDirection.Column);for(let o of e)o.hidden||(Ln(o),r.insertChild(o.yogaNode,r.getChildCount()));r.calculateLayout(t,n,Direction.LTR);for(let o of e)o.hidden||!o.yogaNode||An(o,0,0);r.freeRecursive(),jn(e);}function jn(e){for(let t of e)t.yogaNode=null,jn(t.children);}var Q=createContext(null),X=createContext(null),ie=createContext(null),Fe=createContext(null),Le=createContext(null),ft=createContext(null);var ne=null;function De(e=false){if(ne)return ne;let t=process.env.TERM||"",n=process.env.TERM_PROGRAM||"",r=process.env.KITTY_WINDOW_ID,o=process.env.GHOSTTY_RESOURCES_DIR,s=process.env.WEZTERM_PANE,i=process.env.LC_TERMINAL||"",c=process.env.KONSOLE_VERSION;return r||t==="xterm-kitty"?(ne={name:"kitty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},ne):o||t.includes("ghostty")?(ne={name:"ghostty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},ne):s||n==="WezTerm"?(ne={name:"wezterm",supportsKittyGraphics:true,supportsIterm2Images:true,supportsSixel:true},ne):n==="iTerm.app"||i==="iTerm2"?(ne={name:"iterm2",supportsKittyGraphics:false,supportsIterm2Images:true,supportsSixel:false},ne):c?(ne={name:"konsole",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:true},ne):n==="vscode"?(ne={name:"vscode",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},ne):(ne={name:"unknown",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},ne)}function Et(){let e=De();return e.supportsKittyGraphics||e.supportsIterm2Images||e.supportsSixel}var re="\x1B";function pt(){return !!process.env.TMUX}function Nt(e){if(!pt())return e;let t=e.replace(/\x1b/g,"\x1B\x1B");return `${re}Ptmux;${t}${re}\\`}function $n(e){let t=De();return t.supportsKittyGraphics?Qr(e):t.supportsIterm2Images?Zr(e):null}function Vn(e){if(De().supportsKittyGraphics){let n;return n=`${re}_Ga=d,d=a${re}\\`,Nt(n)}return null}function Qr(e){let{data:t,width:n,height:r,x:o,y:s}=e,c=t.toString("base64"),l=`${re}[${s+1};${o+1}H`,u=Bt(t),f="a=T,f=100";u&&(f+=`,s=${u.width},v=${u.height}`),f+=`,c=${n},r=${r}`;let m=4096,S=[l];pt()&&S.unshift(`${re}[?25l`);for(let I=0;I<c.length;I+=m){let E=c.slice(I,I+m),h=I+m>=c.length?"m=0":"m=1",y;I===0?y=`${re}_G${f},${h},q=2;${E}${re}\\`:y=`${re}_G${h};${E}${re}\\`,S.push(Nt(y));}return pt()&&S.push(`${re}[?25h`),S.join("")}function Zr(e){let{data:t,width:n,height:r,x:o,y:s}=e,i=t.toString("base64"),c=`${re}[${s+1};${o+1}H`,l=[`width=${n}`,`height=${r}`,"preserveAspectRatio=1","inline=1"].join(";"),u=`${re}]1337;File=${l}:${i}\x07`;return c+(pt()?Nt(u):u)}function Bt(e){if(e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e.length>=24){let t=e.readUInt32BE(16),n=e.readUInt32BE(20);return {width:t,height:n}}if(e[0]===255&&e[1]===216&&e[2]===255){let t=2;for(;t<e.length-8;){if(e[t]!==255){t++;continue}let n=e[t+1];if(n!==void 0&&(n>=192&&n<=195||n>=197&&n<=199||n>=201&&n<=203||n>=205&&n<=207)){let o=e.readUInt16BE(t+5);return {width:e.readUInt16BE(t+7),height:o}}let r=e.readUInt16BE(t+2);t+=2+r;}}if(e[0]===71&&e[1]===73&&e[2]===70&&e.length>=10){let t=e.readUInt16LE(6),n=e.readUInt16LE(8);return {width:t,height:n}}return null}function eo(e,t={}){let n=t.stdout??process.stdout,r=t.stdin??process.stdin,o=t.debug??false,s=t.useNativeCursor??true,i=new it(n,r);i.setup();let c=false;i.queryPalette().then(a=>{bn(a),f=true,O();});let l=new Ve(i.columns,i.rows),u=new Ve(i.columns,i.rows),f=true,m=new Set,S=new Set,I=new Map,E={subscribe(a){return m.add(a),()=>m.delete(a)},subscribePriority(a){return S.add(a),()=>S.delete(a)},registerInputHandler(a,w){return I.set(a,w),()=>I.delete(a)}},d=new Map,h=new Map,y={registerImage(a){let w=d.get(a.id);(!w||w.x!==a.x||w.y!==a.y||w.width!==a.width||w.height!==a.height)&&(h.set(a.id,a),O());},unregisterImage(a){d.delete(a),h.delete(a);}};function R(){for(let a of h.values()){let w=$n({data:a.data,width:a.width,height:a.height,x:a.x,y:a.y,id:a.id});w&&(i.write(w),d.set(a.id,{x:a.x,y:a.y,width:a.width,height:a.height}));}h.clear();}let k=null,j=new Map,V=[],B=new Set,G=[],N=new Set;function M(a){if(k!==a){k=a,O();for(let w of N)w(k);}}function C(){let a=[...V];if(G.length>0){let w=G[G.length-1];a=a.filter(P=>w.has(P));}return a=a.filter(w=>!B.has(w)),a.sort((w,P)=>{let F=j.get(w),p=j.get(P);if(!F||!p)return 0;let v=F.layout,L=p.layout;return v.y!==L.y?v.y-L.y:v.x-L.x}),a}let b={get focusedId(){return k},register(a,w){if(j.set(a,w),V.includes(a)||V.push(a),G.length>0&&G[G.length-1].add(a),k===null){let P=C();P.length>0&&M(P[0]);}return ()=>{j.delete(a);let P=V.indexOf(a);if(P!==-1&&V.splice(P,1),k===a){let F=C();M(F[0]??null);}}},requestFocus(a){M(a);},focusNext(){let a=C();if(a.length===0)return;let P=((k?a.indexOf(k):-1)+1)%a.length;M(a[P]);},focusPrev(){let a=C();if(a.length===0)return;let P=((k?a.indexOf(k):0)-1+a.length)%a.length;M(a[P]);},setSkippable(a,w){if(w){if(B.add(a),k===a){let P=C();P.length>0&&M(P[0]);}}else B.delete(a);},trapIds:null,pushTrap(a){return G.push(a),()=>{let w=G.indexOf(a);w!==-1&&G.splice(w,1);}},onFocusChange(a){return N.add(a),()=>{N.delete(a);}},getRegisteredElements(){let a=[];for(let w of V){if(B.has(w))continue;let P=j.get(w);P&&a.push({id:w,node:P});}return a},getActiveElements(){let a=C(),w=[];for(let P of a){if(B.has(P))continue;let F=j.get(P);F&&w.push({id:P,node:F});}return w}},x=new Map,g={getLayout(a){return a.layout},subscribe(a,w){return x.has(a)||x.set(a,new Set),x.get(a).add(w),()=>{let P=x.get(a);P&&(P.delete(w),P.size===0&&x.delete(a));}}},$={registerNode(){},unregisterNode(){},scheduleRender:O,exit(a){T.exit(a);},get columns(){return i.columns},get rows(){return i.rows}},W={type:"root",children:[],onCommit(){O();}},A=false;function O(){A||(A=true,queueMicrotask(()=>{A=false,U();}));}function U(){let a=i.columns,w=i.rows;(u.width!==a||u.height!==w)&&(u.resize(a,w),l.resize(a,w),f=true),Hn(W.children,a,w),_(W.children);let P;if(k){let v=j.get(k);v?.type==="input"&&(P={nodeId:k,position:v.props.cursorPosition??v.props.value?.length??0});}let F=kn(W.children,u,{cursorInfo:P,useNativeCursor:s}),p=En(l,u,f);if(p.length>0&&i.write(p),h.size>0&&c&&(i.hideCursor(),c=false),R(),s)if(F.cursorPosition){let v=Cn(F.cursorPosition.bg);i.setCursorColor(v),i.moveCursor(F.cursorPosition.x,F.cursorPosition.y),c||(i.showCursor(),c=true);}else i.hideCursor(),c=false;for(let v=0;v<u.cells.length;v++)l.cells[v]={...u.cells[v]};f=false;}function _(a){for(let w of a){let P=x.get(w);if(P)for(let F of P)F(w.layout);_(w.children);}}let D=i.onData(a=>{let w=mn(a);for(let P of w){if(P.ctrl&&P.name==="c"){T.exit();return}if(P.ctrl&&P.name==="z"){i.suspend(),process.kill(0,"SIGSTOP");return}let F=false;for(let p of S)if(p(P)){F=true;break}if(!F&&k){let p=I.get(k);p&&(F=p(P));}if(!F&&P.name==="tab"&&!P.ctrl&&!P.alt){P.shift?b.focusPrev():b.focusNext();continue}if(!F)for(let p of m)p(P);}}),q=i.onResize(()=>{f=true,O();}),H=()=>{i.resume(),f=true,O();};process.on("SIGCONT",H);let fe=oe.createElement(Fe.Provider,{value:$},oe.createElement(Q.Provider,{value:E},oe.createElement(X.Provider,{value:b},oe.createElement(ie.Provider,{value:g},oe.createElement(ft.Provider,{value:y},e))))),ge=a=>{o&&console.error("Uncaught error:",a);},J=a=>{o&&console.error("Error caught by boundary:",a);},se=a=>{o&&console.error("Recoverable error:",a);},Y=je.createContainer(W,0,null,false,null,"",ge,J,se,null);je.updateContainer(fe,Y,null,null);let T={unmount(){je.updateContainer(null,Y,null,null),D(),q(),process.off("SIGCONT",H);let a=Vn();a&&i.write(a),i.cleanup();},exit(a){T.unmount(),process.exit(a??0);}};return T}var ro=forwardRef(function({children:t,style:n,focusable:r},o){return oe.createElement("box",{style:n,focusable:r,ref:o},t)});var io=forwardRef(function({children:t,style:n,wrap:r},o){let s=r?{...n,wrap:r}:n;return oe.createElement("text",{style:s,ref:o},t)});function On(e,t,n){if(n<=0)return {visualLine:0,visualCol:t,totalVisualLines:1,lineStartOffset:0,lineLength:e.length};let r=e.split(`
5
+ `),o=[],s=0;for(let l of r){let u=me([l],n,"wrap"),f=0;for(let m of u)o.push({text:m,logicalOffset:s+f}),f+=m.length;s+=l.length+1;}let i=0;for(let l=0;l<o.length;l++){let u=o[l],f=u.text.length,m=l+1<o.length&&o[l+1].logicalOffset!==u.logicalOffset+f,S=f+(m?1:0);if(t<i+f||l===o.length-1)return {visualLine:l,visualCol:Math.min(t-i,f),totalVisualLines:o.length,lineStartOffset:i,lineLength:f};i+=S;}let c=o.length-1;return {visualLine:c,visualCol:o[c].text.length,totalVisualLines:o.length,lineStartOffset:i-o[c].text.length,lineLength:o[c].text.length}}function Dn(e,t,n,r){if(r<=0)return Math.min(n,e.length);let o=e.split(`
6
+ `),s=[],i=0;for(let f of o){let m=me([f],r,"wrap"),S=0;for(let I of m)s.push({text:I,startOffset:i+S}),S+=I.length;i+=f.length+1;}let c=Math.max(0,Math.min(t,s.length-1)),l=s[c],u=Math.min(n,l.text.length);return l.startOffset+u}function _e(e,t){let n=e.split(`
7
+ `),r=t;for(let s=0;s<n.length;s++){if(r<=n[s].length)return {line:s,col:r,lines:n};r-=n[s].length+1;}let o=n.length-1;return {line:o,col:n[o].length,lines:n}}function qe(e,t,n){let r=0;for(let o=0;o<t&&o<e.length;o++)r+=e[o].length+1;return r+Math.min(n,e[t]?.length??0)}function co(e){let{value:t,defaultValue:n="",onChange:r,onKeyPress:o,onBeforeChange:s,placeholder:i,style:c,focusedStyle:l,multiline:u,autoFocus:f,type:m="text"}=e,[S,I]=useState(n),[E,d]=useState(n.length),[h,y]=useState(0),[R,k]=useState(false),[j,V]=useState(false),B=useContext(Q),G=useContext(X),N=useContext(ie),M=useRef(null),C=useRef(null),b=t!==void 0,x=b?t:S;useEffect(()=>{if(!N||!M.current)return;let D=N.getLayout(M.current);return y(D.innerWidth),N.subscribe(M.current,q=>{y(q.innerWidth);})},[N]);let g=useRef(x),$=useRef(E),W=useRef(x),A=useRef(E);useEffect(()=>{x!==W.current&&(g.current=x,W.current=x,$.current=x.length,A.current=x.length,d(x.length));},[x]),useEffect(()=>{E!==A.current&&($.current=E,A.current=E);},[E]);let O=useRef({isControlled:b,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:u??false,innerWidth:h,type:m});O.current={isControlled:b,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:u??false,innerWidth:h,type:m},useEffect(()=>{if(!(!G||!C.current||!M.current))return G.register(C.current,M.current)},[G,j]);let U=useRef(false);useEffect(()=>{if(!j){U.current=false;return}if(f&&!U.current&&G&&C.current){U.current=true;let D=C.current,q=setTimeout(()=>{G.requestFocus(D);},0);return ()=>clearTimeout(q)}},[f,G,j]),useEffect(()=>{if(!G||!C.current)return;let D=C.current;return k(G.focusedId===D),G.onFocusChange(q=>{k(q===D);})},[G,j]),useEffect(()=>{if(!B||!C.current)return;let D=C.current,q=H=>{let{isControlled:fe,onChange:ge,onKeyPress:J,onBeforeChange:se,multiline:Y}=O.current;if(J?.(H)===true)return true;let T=g.current,a=$.current;if(H.name==="escape")return false;let w=(p,v)=>{let L=p,z=v;if(se){let K=se(p,T);if(K===false)return;typeof K=="string"&&(L=K,z=K.length);}g.current=L,$.current=z,W.current=L,A.current=z,fe||I(L),ge?.(L),d(z);},P=p=>{$.current=p,A.current=p,d(p);};if(H.name==="return"){if(Y){let p=T.slice(0,a)+`
8
+ `+T.slice(a);return w(p,a+1),true}return false}if(H.ctrl){if(H.name==="w"){if(a>0){let p=a;for(;p>0&&T[p-1]===" ";)p--;for(;p>0&&T[p-1]!==" "&&(!Y||T[p-1]!==`
9
+ `);)p--;let v=T.slice(0,p)+T.slice(a);w(v,p);}return true}if(H.name==="a"){if(Y){let{line:p,lines:v}=_e(T,a);P(qe(v,p,0));}else P(0);return true}if(H.name==="e"){if(Y){let{line:p,lines:v}=_e(T,a);P(qe(v,p,v[p].length));}else P(T.length);return true}if(H.name==="k"){if(Y){let{line:p,lines:v}=_e(T,a),L=qe(v,p,v[p].length);if(a<L){let z=T.slice(0,a)+T.slice(L);w(z,a);}}else if(a<T.length){let p=T.slice(0,a);w(p,a);}return true}return false}if(H.alt){if(H.name==="left"||H.name==="b"){let p=a;for(;p>0&&T[p-1]===" ";)p--;for(;p>0&&T[p-1]!==" "&&T[p-1]!==`
10
+ `;)p--;return P(p),true}if(H.name==="right"||H.name==="f"){let p=a;for(;p<T.length&&T[p]!==" "&&T[p]!==`
11
+ `;)p++;for(;p<T.length&&T[p]===" ";)p++;return P(p),true}if(H.name==="backspace"||H.name==="d")if(H.name==="backspace"){if(a>0){let p=a;for(;p>0&&T[p-1]===" ";)p--;for(;p>0&&T[p-1]!==" "&&T[p-1]!==`
12
+ `;)p--;let v=T.slice(0,p)+T.slice(a);w(v,p);}return true}else {if(a<T.length){let p=a;for(;p<T.length&&T[p]!==" "&&T[p]!==`
13
+ `;)p++;for(;p<T.length&&T[p]===" ";)p++;let v=T.slice(0,a)+T.slice(p);w(v,a);}return true}return false}if(H.name==="left")return P(Math.max(0,a-1)),true;if(H.name==="right")return P(Math.min(T.length,a+1)),true;if(H.name==="up"){let{innerWidth:p}=O.current,v=On(T,a,p);return v.visualLine>0&&P(Dn(T,v.visualLine-1,v.visualCol,p)),true}if(H.name==="down"){let{innerWidth:p}=O.current,v=On(T,a,p);return v.visualLine<v.totalVisualLines-1&&P(Dn(T,v.visualLine+1,v.visualCol,p)),true}if(H.name==="home"){if(Y){let{line:p,lines:v}=_e(T,a);P(qe(v,p,0));}else P(0);return true}if(H.name==="end"){if(Y){let{line:p,lines:v}=_e(T,a);P(qe(v,p,v[p].length));}else P(T.length);return true}if(H.name==="backspace"){if(a>0){let p=T.slice(0,a-1)+T.slice(a);w(p,a-1);}return true}if(H.name==="delete"){if(a<T.length){let p=T.slice(0,a)+T.slice(a+1);w(p,a);}return true}if(H.name.length>1)return false;let F=H.sequence;if(F.length===1&&F.charCodeAt(0)>=32){let{type:p}=O.current;if(p==="number"){let L=/[0-9]/.test(F),z=F==="."&&!T.includes("."),K=F==="-"&&a===0&&!T.includes("-");if(!L&&!z&&!K)return true}let v=T.slice(0,a)+F+T.slice(a);return w(v,a+1),true}return false};return B.registerInputHandler(D,q)},[B,j]);let _={...c,...R&&l?l:{}};return oe.createElement("input",{style:_,value:x,defaultValue:n,placeholder:i,onChange:r,cursorPosition:$.current,multiline:u??false,focused:R,ref:D=>{D?(M.current=D,C.current=D.focusId,V(true)):(M.current=null,C.current=null,V(false));}})}function Ft({trap:e=false,children:t}){let n=useContext(X),r=useRef(null),o=useRef(new Set);return useLayoutEffect(()=>{if(!e||!n)return;r.current=n.focusedId;let s=n.pushTrap(o.current);return ()=>{s(),r.current&&n.requestFocus(r.current);}},[e,n]),useEffect(()=>{if(!(!e||!n)&&o.current.size>0){let s=o.current.values().next().value;s&&n.requestFocus(s);}},[e,n]),oe.createElement(oe.Fragment,null,t)}function mo({size:e}){return oe.createElement("box",{style:{flexGrow:e??1}})}function zn(e){let t=e.toLowerCase().split("+");return {name:t[t.length-1],ctrl:t.includes("ctrl"),alt:t.includes("alt"),shift:t.includes("shift"),meta:t.includes("meta")||t.includes("cmd")||t.includes("super")||t.includes("win")}}function Xn(e,t){return !(t.name!==e.name||e.ctrl!==!!t.ctrl||e.alt!==!!t.alt||e.shift!==!!t.shift||e.meta!==!!t.meta)}function go({keypress:e,onPress:t,whenFocused:n,priority:r,disabled:o}){let s=useContext(Q),i=useContext(X),c=useRef(t);c.current=t;let l=useRef(zn(e));return l.current=zn(e),useEffect(()=>{if(!(!s||o))if(r){let u=f=>!Xn(l.current,f)||n&&i?.focusedId!==n?false:(c.current(),true);return s.subscribePriority(u)}else {let u=f=>{Xn(l.current,f)&&(n&&i?.focusedId!==n||c.current());};return s.subscribe(u)}},[s,i,n,r,o]),null}function xo({children:e,zIndex:t=1e3}){return oe.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:t}},e)}function Co({onPress:e,style:t,focusedStyle:n,children:r,disabled:o}){let s=useContext(X),i=useContext(Q),c=useRef(null),l=useRef(null),u=useRef(e);u.current=e;let[f,m]=useState(false),[S,I]=useState(false);useEffect(()=>{if(!(!s||!l.current||!c.current||o))return s.register(l.current,c.current)},[s,o,f]),useEffect(()=>{if(!s||!l.current)return;let d=l.current;return I(s.focusedId===d),s.onFocusChange(h=>{I(h===d);})},[s,f]),useEffect(()=>{if(!i||!l.current||o)return;let d=l.current,h=y=>s?.focusedId!==d?false:y.name==="return"||y.name===" "||y.sequence===" "?(u.current?.(),true):false;return i.registerInputHandler(d,h)},[i,s,o,f]);let E={...t,...S&&n?n:{}};return oe.createElement("box",{style:E,focusable:!o,ref:d=>{d?(c.current=d,l.current=d.focusId,m(true)):(c.current=null,l.current=null,m(false));}},r)}var vo={x:0,y:0,width:0,height:0,innerX:0,innerY:0,innerWidth:0,innerHeight:0};function Se(e){let t=useContext(ie),[n,r]=useState(vo);return useEffect(()=>{if(!(!t||!e?.current))return r(t.getLayout(e.current)),t.subscribe(e.current,r)},[t,e]),n}function ze(e,t=[]){let n=useContext(Q);useEffect(()=>{if(n)return n.subscribe(e)},[n,...t]);}function Eo({children:e,style:t,scrollOffset:n,onScroll:r,defaultScrollOffset:o=0,scrollStep:s=1,disableKeyboard:i,scrollToFocus:c=true,showScrollbar:l=true,focusable:u=true,focusedStyle:f}){let m=n!==void 0,[S,I]=useState(o),E=m?n:S,d=useRef(null),h=useRef(null),y=Se(d),R=Se(h),k=useContext(X),j=useContext(ie),V=useRef(null);u&&!V.current&&(V.current=`scrollview-${Math.random().toString(36).slice(2,9)}`);let B=u?V.current:null;useEffect(()=>{if(!(!u||!B||!k||!d.current))return k.register(B,d.current)},[u,B,k]);let G=u&&B&&k?.focusedId===B,N=y.innerHeight,M=R.height,C=Math.max(0,M-N),b=Math.max(0,Math.min(E,C)),x=useMemo(()=>({getBounds:()=>{let L=y.y;return {visibleTop:L,visibleBottom:L+N,viewportHeight:N,scrollOffset:b}}}),[y.y,N,b]),g=useCallback(L=>{let z=Math.max(0,Math.min(L,C));m?r?.(z):I(z);},[m,r,C]);useEffect(()=>{E>C&&C>=0&&g(C);},[E,C,g]),useEffect(()=>!c||!k||!j||!h.current?void 0:k.onFocusChange(z=>{if(!z||!h.current)return;let K=ye=>{if(ye.focusId===z)return ye;for(let de of ye.children){let ae=K(de);if(ae)return ae}return null},ce=K(h.current);if(!ce)return;let ee=j.getLayout(ce),te=h.current.layout?.y??0,Ie=ee.y-te,ve=Ie+ee.height,pe=E,Ee=E+N;Ie<pe?g(Ie):ve>Ee&&g(ve-N);}),[c,k,j,E,N,g]);let $=useCallback(()=>{if(!k)return false;let L=k.focusedId;if(!L)return false;if(u&&B&&L===B)return true;if(!h.current)return false;let z=K=>{if(K.focusId===L)return true;for(let ce of K.children)if(z(ce))return true;return false};return z(h.current)},[k,u,B]);ze(L=>{if(i||!$())return;let z=Math.max(1,Math.floor(N/2)),K=Math.max(1,N);switch(L.name){case "pageup":g(E-K);break;case "pagedown":g(E+K);break;default:L.ctrl&&(L.name==="d"?g(E+z):L.name==="u"?g(E-z):L.name==="f"?g(E+K):L.name==="b"&&g(E-K));break}},[E,s,N,C,i,g,$]);let{padding:W,paddingX:A,paddingY:O,paddingTop:U,paddingRight:_,paddingBottom:D,paddingLeft:q,...H}=t??{},ge=H.border!=null&&H.border!=="none"?2:0,J=M>0?M+ge:void 0,se={...H,...G?f:{},clip:true,...H.height===void 0&&J!==void 0?{height:J,flexShrink:H.flexShrink??1,minHeight:H.minHeight??0}:{}},Y={position:"absolute",top:-b,left:0,right:0,flexDirection:"column",...W!==void 0&&{padding:W},...A!==void 0&&{paddingX:A},...O!==void 0&&{paddingY:O},...U!==void 0&&{paddingTop:U},..._!==void 0&&{paddingRight:_},...D!==void 0&&{paddingBottom:D},...q!==void 0&&{paddingLeft:q}},T=M>N&&N>0,a=l&&T,w=Math.max(1,Math.floor(N/M*N)),P=M-N,F=P>0?Math.floor(b/P*(N-w)):0,p=[];if(a)for(let L=0;L<N;L++)L>=F&&L<F+w?p.push("\u2588"):p.push("\u2591");let v={position:"absolute",top:0,right:0,width:1,height:N,flexDirection:"column"};return oe.createElement(Le.Provider,{value:x},oe.createElement("box",{style:se,ref:L=>{d.current=L??null;},...u?{focusable:true,focusId:B}:{}},oe.createElement("box",{style:{...Y,paddingRight:a?(Y.paddingRight??0)+1:Y.paddingRight},ref:L=>{h.current=L??null;}},e),a&&oe.createElement("box",{style:v},oe.createElement("text",{style:{color:"blackBright"}},p.join(`
14
+ `)))))}function Dt({count:e,renderItem:t,selectedIndex:n,onSelectionChange:r,onSelect:o,defaultSelectedIndex:s=0,disabledIndices:i,style:c,focusable:l=true}){let u=n!==void 0,[f,m]=useState(s),S=u?n:f,I=useContext(X),E=useContext(Q),d=useRef(null),h=useRef(null),y=useRef(o);y.current=o;let[R,k]=useState(false),[j,V]=useState(false),B=useRef(null),G=useCallback(b=>{let x=Math.max(0,Math.min(b,e-1));u?r?.(x):m(x);},[u,r,e]),N=useCallback((b,x)=>{if(!i||i.size===0)return Math.max(0,Math.min(b+x,e-1));let g=b+x;for(;g>=0&&g<e&&i.has(g);)g+=x;return g<0||g>=e?b:g},[i,e]);useEffect(()=>{if(!(!I||!h.current||!d.current||!l))return I.register(h.current,d.current)},[I,l,R]),useEffect(()=>{if(!I||!h.current)return;let b=h.current;return V(I.focusedId===b),I.onFocusChange(x=>{V(x===b);})},[I,R]);let M=useCallback(b=>{let x=b?e-1:0,g=b?-1:1,$=x;for(;$>=0&&$<e&&i?.has($);)$+=g;return $>=0&&$<e?$:b?e-1:0},[i,e]);useEffect(()=>{if(!E||!h.current||!l)return;let b=h.current,x=g=>I?.focusedId!==b?false:g.name==="g"&&!g.ctrl&&!g.alt?B.current==="g"?(G(M(false)),B.current=null,true):(B.current="g",true):g.name==="G"||g.name==="g"&&g.shift?(B.current=null,G(M(true)),true):(B.current=null,g.name==="up"||g.name==="k"?(G(N(S,-1)),true):g.name==="down"||g.name==="j"?(G(N(S,1)),true):g.name==="return"?(i?.has(S)||y.current?.(S),true):false);return E.registerInputHandler(b,x)},[E,I,l,S,G,N,M,i,R]);let C=[];for(let b=0;b<e;b++)C.push(oe.createElement(oe.Fragment,{key:b},t({index:b,selected:b===S,focused:j})));return oe.createElement("box",{style:{flexDirection:"column",...c},focusable:l,ref:b=>{b?(d.current=b,h.current=b.focusId,k(true)):(d.current=null,h.current=null,k(false));}},...C)}function No({items:e,selectedIndex:t,onSelectionChange:n,onSelect:r,defaultSelectedIndex:o=0,style:s,highlightColor:i="cyan",focusable:c=true}){let l=new Set;for(let f=0;f<e.length;f++)e[f].disabled&&l.add(f);let u=f=>{let m=e[f];m&&!m.disabled&&r?.(m.value,f);};return oe.createElement(Dt,{count:e.length,selectedIndex:t,onSelectionChange:n,onSelect:u,defaultSelectedIndex:o,disabledIndices:l.size>0?l:void 0,style:s,focusable:c,renderItem:({index:f,selected:m,focused:S})=>{let I=e[f],E=I.disabled,d=m&&S,h=m?">":" ";return oe.createElement("box",{style:{flexDirection:"row",...d?{bg:i}:{}}},oe.createElement("text",{style:d?{bold:true,color:"black"}:E?{dim:true}:{}},`${h} ${I.label}`))}})}function Lo({value:e,indeterminate:t=false,width:n="100%",label:r,showPercent:o=false,style:s,filled:i="\u2588",empty:c="\u2591"}){let l=useRef(null),f=Se(l).innerWidth,[m,S]=useState(0);useEffect(()=>{if(!t)return;let y=setInterval(()=>{S(R=>(R+1)%Math.max(1,f+6));},100);return ()=>clearInterval(y)},[t,f]);let I=Math.max(0,Math.min(1,e??0)),E=o?` ${Math.round(I*100)}%`:"",d="";if(f>0)if(t&&e===void 0){let y=Math.max(1,Math.min(3,Math.floor(f/4))),R=[];for(let k=0;k<f;k++)k>=m-y&&k<m?R.push(i):R.push(c);d=R.join("");}else {let y=Math.round(I*f);d=i.repeat(y)+c.repeat(f-y);}let h=[];return r&&h.push(oe.createElement("text",{key:"label",style:{bold:true}},r+" ")),h.push(oe.createElement("box",{key:"track",style:{flexGrow:1,flexShrink:1},ref:y=>{l.current=y??null;}},oe.createElement("text",{key:"bar",style:{}},d))),o&&h.push(oe.createElement("text",{key:"pct",style:{bold:true}},E)),oe.createElement("box",{style:{flexDirection:"row",width:n,...s}},...h)}var Ho=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function jo({frames:e=Ho,intervalMs:t=80,label:n,style:r}){let[o,s]=useState(0);useEffect(()=>{let c=setInterval(()=>{s(l=>(l+1)%e.length);},t);return ()=>clearInterval(c)},[e.length,t]);let i=[oe.createElement("text",{key:"frame",style:r},e[o])];return n&&i.push(oe.createElement("text",{key:"label",style:{}}," "+n)),oe.createElement("box",{style:{flexDirection:"row"}},...i)}var tr=createContext(null),Wo=0;function _o(){let e=useContext(tr);if(!e)throw new Error("useToast must be used within a <ToastHost>");return e.push}var qo={info:{bg:"blackBright",title:"cyanBright",text:"white"},success:{bg:"blackBright",title:"greenBright",text:"white"},warning:{bg:"blackBright",title:"yellowBright",text:"white"},error:{bg:"blackBright",title:"redBright",text:"white"}};function zo({position:e="bottom-right",maxVisible:t=5,children:n}){let[r,o]=useState([]),s=useRef(new Map),i=useCallback(I=>{let E=`toast-${Wo++}`,d={id:E,durationMs:3e3,variant:"info",...I};if(o(h=>[...h,d]),d.durationMs&&d.durationMs>0){let h=setTimeout(()=>{s.current.delete(E),o(y=>y.filter(R=>R.id!==E));},d.durationMs);s.current.set(E,h);}},[]);useEffect(()=>()=>{for(let I of s.current.values())clearTimeout(I);s.current.clear();},[]);let c=useRef({push:i});c.current.push=i;let l=e.startsWith("top"),u=e.endsWith("right"),f={position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:900,flexDirection:"column",justifyContent:l?"flex-start":"flex-end",alignItems:u?"flex-end":"flex-start",padding:1},S=r.slice(-t).map(I=>{let E=I.variant??"info",d=qo[E],h=[];return I.title&&h.push(oe.createElement("text",{key:"title",style:{bold:true,color:d.title}},I.title)),h.push(oe.createElement("text",{key:"msg",style:{color:d.text}},I.message)),oe.createElement("box",{key:I.id,style:{bg:d.bg,paddingX:1,flexDirection:"column",minWidth:20,maxWidth:50}},...h)});return oe.createElement(tr.Provider,{value:c.current},n,S.length>0?oe.createElement("box",{style:f},...S):null)}function Uo({items:e,value:t,onChange:n,placeholder:r="Select...",style:o,focusedStyle:s,dropdownStyle:i,highlightColor:c="cyan",maxVisible:l=8,searchable:u=true,disabled:f}){let m=useContext(X),S=useContext(Q),I=useContext(Fe),E=useContext(Le),d=useRef(null),h=useRef(null),y=useRef(n);y.current=n;let[R,k]=useState(false),[j,V]=useState(false),[B,G]=useState(false),[N,M]=useState(0),[C,b]=useState(""),[x,g]=useState(0),$=Se(d),W=I?.rows??24,A=E?.getBounds(),U=e.find(w=>w.value===t)?.label??"",_=useMemo(()=>{if(!C)return e;let w=C.toLowerCase();return e.filter(P=>P.label.toLowerCase().includes(w))},[e,C]),D=Math.min(l,_.length),q=_.slice(x,x+D);useEffect(()=>{M(0),g(0);},[C]),useEffect(()=>{!j&&B&&(G(false),b(""));},[j,B]),useEffect(()=>{if(!(!m||!h.current||!d.current))return m.register(h.current,d.current)},[m,R]),useEffect(()=>{!m||!h.current||m.setSkippable(h.current,!!f);},[m,f,R]),useEffect(()=>{if(!m||!h.current)return;let w=h.current;return V(m.focusedId===w),m.onFocusChange(P=>{V(P===w);})},[m,R]);let H=useCallback((w,P)=>{let F=w+P;for(;F>=0&&F<_.length;){if(!_[F].disabled)return F;F+=P;}return w},[_]),fe=useCallback(w=>{w<x?g(w):w>=x+D&&g(w-D+1);},[x,D]);useEffect(()=>{if(!S||!h.current||f)return;let w=h.current,P=F=>{if(m?.focusedId!==w)return false;if(!B){if(F.name==="return"||F.name===" "||F.sequence===" "||F.name==="down"){G(true),b("");let p=_.findIndex(L=>L.value===t),v=p>=0?p:0;return M(v),g(Math.max(0,v-Math.floor(l/2))),true}return false}if(F.name==="tab")return G(false),b(""),false;if(F.name==="escape")return G(false),b(""),true;if(F.name==="return"){let p=_[N];return p&&!p.disabled&&(y.current?.(p.value),G(false),b("")),true}if(F.name==="up"){let p=H(N,-1);return M(p),fe(p),true}if(F.name==="down"){let p=H(N,1);return M(p),fe(p),true}if(F.name==="backspace")return u&&C.length>0&&b(p=>p.slice(0,-1)),true;if(F.name==="home"){let p=H(-1,1);return M(p),fe(p),true}if(F.name==="end"){let p=H(_.length,-1);return M(p),fe(p),true}if(u&&F.sequence&&F.sequence.length===1&&!F.ctrl&&!F.alt){let p=F.sequence;if(p>=" "&&p<="~")return b(v=>v+p),true}return true};return S.registerInputHandler(w,P)},[S,m,f,B,N,_,t,l,u,C,H,fe,R]);let J={flexDirection:"row",width:"100%",...!o?.bg&&o?.border===void 0?{border:"single"}:{},...o,...j&&s?s:{}},se=U?o?.color??void 0:"blackBright",Y=[oe.createElement("text",{key:"label",style:{flexGrow:1,flexShrink:1,color:se,wrap:"ellipsis",...U?{}:{dim:true}}},U||r),oe.createElement("text",{key:"arrow",style:{flexShrink:0,color:j?c:"blackBright"}},B?" \u25B2":" \u25BC")],T=null;if(B){let w=[];u&&C&&w.push(oe.createElement("box",{key:"search",style:{paddingX:1}},oe.createElement("text",{style:{color:"blackBright",dim:true}},`/${C}`))),_.length===0&&w.push(oe.createElement("box",{key:"empty",style:{paddingX:1}},oe.createElement("text",{style:{dim:true,color:"blackBright"}},"No matches"))),x>0&&w.push(oe.createElement("box",{key:"scroll-up",style:{justifyContent:"center",alignItems:"center"}},oe.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25B2"))),q.forEach((pe,Ee)=>{let de=x+Ee===N,ae=pe.disabled,rt={paddingX:1,...de&&!ae?{bg:c}:{}},ot={...de&&!ae?{color:"black",bold:true}:{},...ae?{dim:true,color:"blackBright"}:{}};w.push(oe.createElement("box",{key:`item-${pe.value}`,style:rt},oe.createElement("text",{style:ot},pe.label)));}),x+D<_.length&&w.push(oe.createElement("box",{key:"scroll-down",style:{justifyContent:"center",alignItems:"center"}},oe.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25BC")));let P=x>0,F=x+D<_.length,p=u&&C,v=_.length===0,L=!i?.bg&&i?.border===void 0,K=D+(L?2:0);P&&(K+=1),F&&(K+=1),p&&(K+=1),v&&(K+=1);let ce=$.y+$.height,ee,te;A?(ee=A.visibleBottom-ce,te=$.y-A.visibleTop):(ee=W-ce,te=$.y);let ve=ee<K&&te>=K?-K:$.height||1;T=oe.createElement("box",{style:{position:"absolute",top:ve,left:0,right:0,zIndex:9999,...L?{border:"single"}:{},bg:"black",flexDirection:"column",...i}},...w);}let a={flexDirection:"column",width:J.width??"100%",minWidth:J.minWidth,maxWidth:J.maxWidth,flexGrow:J.flexGrow,flexShrink:J.flexShrink??1};return oe.createElement("box",{style:a},oe.createElement("box",{style:J,focusable:true,ref:w=>{w?(d.current=w,h.current=w.focusId,k(true)):(d.current=null,h.current=null,k(false));}},...Y),T)}function Jo({checked:e,onChange:t,label:n,style:r,focusedStyle:o,disabled:s,checkedChar:i="\u2713",uncheckedChar:c=" "}){let l=useContext(X),u=useContext(Q),f=useRef(null),m=useRef(null),S=useRef(t);S.current=t;let I=useRef(e);I.current=e;let[E,d]=useState(false),[h,y]=useState(false);useEffect(()=>{if(!(!l||!m.current||!f.current||s))return l.register(m.current,f.current)},[l,s,E]),useEffect(()=>{if(!l||!m.current)return;let B=m.current;return y(l.focusedId===B),l.onFocusChange(G=>{y(G===B);})},[l,E]),useEffect(()=>{if(!u||!m.current||s)return;let B=m.current,G=N=>l?.focusedId!==B?false:N.name==="return"||N.name===" "||N.sequence===" "?(S.current(!I.current),true):false;return u.registerInputHandler(B,G)},[u,l,s,E]);let R={flexDirection:"row",gap:1,...r,...h&&o?o:{}},k=e?i:c,j={color:s?"blackBright":h?"white":r?.color},V={color:s?"blackBright":r?.color};return oe.createElement("box",{style:R,focusable:!s,ref:B=>{B?(f.current=B,m.current=B.focusId,d(true)):(f.current=null,m.current=null,d(false));}},oe.createElement("text",{key:"box",style:j},`[${k}]`),n?oe.createElement("text",{key:"label",style:V},n):null)}function Qo({items:e,value:t,onChange:n,style:r,itemStyle:o,focusedItemStyle:s,selectedItemStyle:i,disabled:c,direction:l="column",gap:u=0,selectedChar:f="\u25CF",unselectedChar:m="\u25CB"}){let S=useContext(X),I=useContext(Q),E=useRef(null),d=useRef(null),h=useRef(n);h.current=n;let[y,R]=useState(false),[k,j]=useState(false),[V,B]=useState(()=>{let C=e.findIndex(b=>b.value===t);return C>=0?C:e.findIndex(b=>!b.disabled)}),G=useCallback((C,b)=>{let x=C;for(let g=0;g<e.length;g++)if(x=(x+b+e.length)%e.length,!e[x]?.disabled)return x;return C},[e]);useEffect(()=>{if(!(!S||!d.current||!E.current||c))return S.register(d.current,E.current)},[S,c,y]),useEffect(()=>{if(!S||!d.current)return;let C=d.current;return j(S.focusedId===C),S.onFocusChange(b=>{j(b===C);})},[S,y]),useEffect(()=>{if(!I||!d.current||c)return;let C=d.current,b=x=>{if(S?.focusedId!==C)return false;if(x.name==="up"||x.name==="left"||x.name==="k"||x.name==="tab"&&x.shift)return B(g=>G(g,-1)),true;if(x.name==="down"||x.name==="right"||x.name==="j"||x.name==="tab"&&!x.shift)return B(g=>G(g,1)),true;if(x.name==="return"||x.name===" "||x.sequence===" "){let g=e[V];return g&&!g.disabled&&h.current(g.value),true}return false};return I.registerInputHandler(C,b)},[I,S,c,e,V,G,y]),useEffect(()=>{let C=e.findIndex(b=>b.value===t);C>=0&&B(C);},[t,e]);let N={flexDirection:l,gap:u,...r},M=e.map((C,b)=>{let x=C.value===t,g=b===V,$=c||C.disabled,W=x?f:m,A={flexDirection:"row",gap:1,...o};x&&i&&(A={...A,...i}),k&&g&&s&&(A={...A,...s});let O=$?"blackBright":k&&g?s?.color??"white":x?i?.color??o?.color:o?.color;return oe.createElement("box",{key:b,style:A},oe.createElement("text",{key:"radio",style:{color:O}},`(${W})`),oe.createElement("text",{key:"label",style:{color:O}},C.label))});return oe.createElement("box",{style:N,focusable:!c,ref:C=>{C?(E.current=C,d.current=C.focusId,R(true)):(E.current=null,d.current=null,R(false));}},...M)}var cr=createContext(null);function es(){let e=useContext(cr);if(!e)throw new Error("useDialog must be used within a DialogHost");return e}function ts({children:e}){let[t,n]=useState([]),r=useRef(0),o=useCallback((u,f)=>new Promise(m=>{let S=++r.current;n(I=>[...I,{id:S,type:"alert",content:u,okText:f?.okText??"OK",cancelText:"",style:f?.style,buttonStyle:f?.buttonStyle,okButtonStyle:f?.okButtonStyle,focusedButtonStyle:f?.focusedButtonStyle,backdropStyle:f?.backdropStyle,resolve:()=>m()}]);}),[]),s=useCallback((u,f)=>new Promise(m=>{let S=++r.current;n(I=>[...I,{id:S,type:"confirm",content:u,okText:f?.okText??"OK",cancelText:f?.cancelText??"Cancel",style:f?.style,buttonStyle:f?.buttonStyle,okButtonStyle:f?.okButtonStyle,cancelButtonStyle:f?.cancelButtonStyle,focusedButtonStyle:f?.focusedButtonStyle,backdropStyle:f?.backdropStyle,resolve:m}]);}),[]),i=useCallback((u,f)=>{n(m=>{let S=m.find(I=>I.id===u);return S&&S.resolve(f),m.filter(I=>I.id!==u)});},[]),c={alert:o,confirm:s},l=t[t.length-1];return oe.createElement(cr.Provider,{value:c},e,l&&oe.createElement(ns,{key:l.id,dialog:l,onDismiss:i}))}function ns({dialog:e,onDismiss:t}){let n=useContext(X),r=useRef(null),o=useRef(null),s=useRef(null),i=useRef(null),[c,l]=useState("ok"),[u,f]=useState(0);useEffect(()=>{if(!n||u===0)return;let y=[];return r.current&&s.current&&y.push(n.register(s.current,r.current)),o.current&&i.current&&y.push(n.register(i.current,o.current)),s.current&&n.requestFocus(s.current),()=>y.forEach(R=>R())},[n,u]),useEffect(()=>{if(n)return n.onFocusChange(y=>{y===s.current?l("ok"):y===i.current&&l("cancel");})},[n]),ze(y=>{if(y.name==="return"||y.name==="space"){e.type==="alert"?t(e.id,true):t(e.id,c==="ok");return}if(y.name==="escape"){t(e.id,false);return}e.type==="confirm"&&n&&(y.name==="left"||y.name==="right")&&(c==="ok"&&i.current?n.requestFocus(i.current):s.current&&n.requestFocus(s.current));},[e,c,n,t]);let m=typeof e.content=="string",S=m?e.content.length:0,E={minWidth:Math.max(20,m?Math.min(S+6,50):30),maxWidth:50,bg:"black",border:"round",borderColor:"white",padding:1,flexDirection:"column",gap:1,...e.style},d=(y,R)=>{let k={paddingX:2,bg:"blackBright",color:"white"},j={bg:"white",color:"black",bold:true},V=y==="ok"?e.okButtonStyle:e.cancelButtonStyle;return {...k,...e.buttonStyle,...V,...R?{...j,...e.focusedButtonStyle}:{}}},h={position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:999,...e.backdropStyle};return oe.createElement(Ft,{trap:true},oe.createElement("box",{style:h}),oe.createElement("box",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,justifyContent:"center",alignItems:"center",zIndex:1e3}},oe.createElement("box",{style:E},oe.createElement("box",{style:{flexDirection:"column"}},typeof e.content=="string"?oe.createElement("text",null,e.content):e.content),oe.createElement("box",{style:{flexDirection:"row",justifyContent:"flex-end",gap:1}},e.type==="confirm"&&oe.createElement("box",{style:d("cancel",c==="cancel"),focusable:true,ref:y=>{y&&y.focusId&&!i.current&&(o.current=y,i.current=y.focusId,f(R=>R+1));}},oe.createElement("text",null,e.cancelText)),oe.createElement("box",{style:d("ok",c==="ok"),focusable:true,ref:y=>{y&&y.focusId&&!s.current&&(r.current=y,s.current=y.focusId,f(R=>R+1));}},oe.createElement("text",null,e.okText))))))}function ss(e,t){let n=[],r=t.split("");if(e<=r.length)for(let o=0;o<e;o++)n.push(r[o]);else for(let o=0;o<r.length&&n.length<e;o++)for(let s=0;s<r.length&&n.length<e;s++)n.push(r[o]+r[s]);return n}function is({children:e,activationKey:t="ctrl+o",hintStyle:n,hintBg:r="yellow",hintFg:o="black",hintChars:s="asdfghjklqwertyuiopzxcvbnm",enabled:i=true,debug:c=false}){let l=c?(...C)=>console.error("[JumpNav]",...C):()=>{},[u,f]=useState(false),[m,S]=useState(""),[I,E]=useState([]),d=useContext(Q),h=useContext(X),y=useContext(ie);useEffect(()=>{l("Mounted, inputCtx:",!!d,"focusCtx:",!!h,"enabled:",i);},[]);let k=useCallback(C=>{let b=C.toLowerCase().split("+");return {ctrl:b.includes("ctrl"),alt:b.includes("alt"),shift:b.includes("shift"),meta:b.includes("meta"),name:b[b.length-1]??""}},[])(t),j=useCallback(()=>{if(!h?.getActiveElements){l("refreshElements: no getActiveElements");return}let C=h.getActiveElements();l("getActiveElements returned",C.length,"elements");let b=C.map(({id:x,node:g})=>({id:x,node:g,layout:y?.getLayout(g)??g.layout}));b.sort((x,g)=>x.layout.y!==g.layout.y?x.layout.y-g.layout.y:x.layout.x-g.layout.x),E(b);},[h,y,l]),V=useRef(false);useEffect(()=>{u&&!V.current&&(l("Activated! Refreshing elements..."),j()),V.current=u;},[u,j,l]);let B=I.filter(C=>C.layout.width>0&&C.layout.height>0),G=ss(B.length,s),N=useMemo(()=>{let C=new Map;return B.forEach((b,x)=>{G[x]&&C.set(G[x],b.id);}),C},[B,G]);useEffect(()=>{if(!d||!i){l("Not subscribing - inputCtx:",!!d,"enabled:",i);return}l("Subscribing to priority input, activation key:",t);let C=b=>{let x=b.name===k.name,g=!!b.ctrl===k.ctrl,$=!!b.alt===k.alt,W=!!b.shift===k.shift,A=!!b.meta===k.meta;if(!u&&x&&g&&$&&W&&A)return l("Activation key matched! Activating..."),f(true),S(""),true;if(u){if(b.name==="escape")return l("Escape pressed, deactivating"),f(false),S(""),true;if(b.name==="backspace")return S(""),true;if(b.sequence&&b.sequence.length===1&&/[a-z]/i.test(b.sequence)){let O=m+b.sequence.toLowerCase();l("Buffer:",O);let U=N.get(O);return U?(l("Jumping to",U),h?.requestFocus(U),f(false),S(""),true):[...N.keys()].some(D=>D.startsWith(O))?(S(O),true):(S(""),true)}return true}return false};return d.subscribePriority(C)},[d,i,u,k,m,N,h,t,l]);let M=u?oe.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:99998}},...B.map((C,b)=>{let x=G[b];if(!x)return null;let{x:g,y:$}=C.layout,W=x.startsWith(m)&&m.length>0;return oe.createElement("box",{key:C.id,style:{position:"absolute",top:$,left:Math.max(0,g-x.length-2),bg:W?"cyan":r,color:o,paddingX:1,zIndex:99999,...n}},oe.createElement("text",{style:{bold:true,color:o}},x))}),oe.createElement("box",{style:{position:"absolute",bottom:0,left:0,right:0,bg:"blackBright",paddingX:1,zIndex:99999}},oe.createElement("text",{style:{color:"white"}},m?`Jump: ${m}_`:"Press a key to jump \u2022 ESC to cancel"))):null;return oe.createElement(oe.Fragment,null,e,M)}var He=join(tmpdir(),"glyph-image-cache");function bt(e){return e.startsWith("http://")||e.startsWith("https://")}function us(e,t){let n=createHash("md5").update(e).digest("hex"),r=t?ps(t):fs(e)||".png";return join(He,`${n}${r}`)}function fs(e){try{let r=new URL(e).pathname.match(/\.(png|jpg|jpeg|gif|webp|bmp|ico)/i);if(r){let o=r[0].toLowerCase();return o===".jpg"?".jpeg":o}return ""}catch{return ""}}function ps(e){switch(e){case "png":return ".png";case "jpeg":return ".jpeg";case "gif":return ".gif";case "webp":return ".webp";default:return ".png"}}function on(e){if(bt(e))try{let t=new URL(e),n=t.pathname;return basename(n)||t.hostname}catch{return "remote-image"}return basename(e)}function pr(){existsSync(He)||mkdirSync(He,{recursive:true});}async function dr(e){let t=on(e);return bt(e)?ms(e,t):ds(e,t)}async function ds(e,t){if(!existsSync(e))throw new Error(`Image not found: ${e}`);return {data:readFileSync(e),name:t,localPath:e,isRemote:false}}async function ms(e,t){pr();let n=createHash("md5").update(e).digest("hex"),r=[".png",".jpeg",".gif",".webp"];for(let u of r){let f=join(He,`${n}${u}`);if(existsSync(f))return {data:readFileSync(f),name:t,localPath:f,isRemote:true}}let o=await fetch(e);if(!o.ok)throw new Error(`Failed to download image: ${o.status} ${o.statusText}`);let s=await o.arrayBuffer(),i=Buffer.from(s);if(!hs(i))throw new Error(`Invalid image data from: ${e}`);let c=Ct(i),l=us(e,c);return writeFileSync(l,i),{data:i,name:t,localPath:l,isRemote:true}}function hs(e){return e.length<4?false:e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71||e[0]===255&&e[1]===216&&e[2]===255||e[0]===71&&e[1]===73&&e[2]===70||e[0]===66&&e[1]===77||e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e.length>=12&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80||e[0]===0&&e[1]===0&&e[2]===1&&e[3]===0}function Ct(e){return e.length<4?"unknown":e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"png":e[0]===255&&e[1]===216&&e[2]===255?"jpeg":e[0]===71&&e[1]===73&&e[2]===70?"gif":e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e.length>=12&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80?"webp":"unknown"}function mr(e,t){let n=Ct(e);if(n==="png")return e;pr();let r=createHash("md5").update(e).digest("hex"),o=join(He,`${r}.${n}`),s=join(He,`${r}.png`);try{writeFileSync(o,e);let i=platform(),c=!1;if(i==="darwin")try{execSync(`sips -s format png "${o}" --out "${s}" 2>/dev/null`,{stdio:"pipe"}),c=!0;}catch{}if(!c)try{execSync(`magick "${o}" "${s}" 2>/dev/null`,{stdio:"pipe"}),c=!0;}catch{}if(!c)try{execSync(`convert "${o}" "${s}" 2>/dev/null`,{stdio:"pipe"}),c=!0;}catch{}if(c&&existsSync(s)){let l=readFileSync(s);try{unlinkSync(o);}catch{}try{unlinkSync(s);}catch{}return l}try{unlinkSync(o);}catch{}return null}catch{try{unlinkSync(o);}catch{}try{unlinkSync(s);}catch{}return null}}function ys(){let e=platform();return e==="darwin"?"quicklook":e==="linux"||e==="win32"?"open":"none"}async function sn(e){switch(ys()){case "quicklook":return xs(e);case "open":return Cs(e);case "none":throw new Error("No preview method available on this platform")}}function xs(e){return new Promise((t,n)=>{let r=spawn("qlmanage",["-p",e],{detached:false,stdio:["ignore","ignore","ignore"]});r.on("error",o=>{n(new Error(`Failed to open Quick Look: ${o.message}`));}),setTimeout(()=>{bs();},50),r.on("close",o=>{t();});})}function bs(){exec(`osascript -e '
15
15
  tell application "System Events"
16
16
  set frontmost of (first process whose name is "qlmanage") to true
17
17
  end tell
18
- '`,()=>{});}function ys(e){return new Promise((t,n)=>{let r=platform(),o,s;r==="linux"?(o="xdg-open",s=[e]):r==="win32"?(o="cmd",s=["/c","start",'""',e]):(o="open",s=[e]);let i=spawn(o,s,{detached:true,stdio:["ignore","ignore","ignore"]});i.unref(),i.on("error",c=>{n(new Error(`Failed to open preview: ${c.message}`));}),setTimeout(t,100);})}function xs({src:e,width:t,height:n,style:r,focusedStyle:o,placeholderStyle:s,focusable:i=true,inline:c=true,placeholder:l,onStateChange:u,onError:f,autoLoad:h=false,autoSize:S=false,maxWidth:I,maxHeight:P}){let d=useContext(z),g=useContext(J),b=useContext(se),k=useContext(lt),R=useRef(null),A=useRef(null),D=useRef(Math.floor(Math.random()*1e6)),[B,F]=useState(false),[E,M]=useState(false),[x,C]=useState("placeholder"),[w,y]=useState(null),[G,W]=useState(null),[H,V]=useState(null),q=useRef(null),_=l||nn(e),K=ht(e),O=useCallback(m=>{C(m),u?.(m);},[u]);useEffect(()=>{if(!(!d||!A.current||!R.current||!i))return d.register(A.current,R.current)},[d,i,B]),useEffect(()=>{if(!d||!A.current)return;let m=A.current;return M(d.focusedId===m),d.onFocusChange(v=>{M(v===m);})},[d,B]),useEffect(()=>{if(!(!b||!R.current))return W(b.getLayout(R.current)),b.subscribe(R.current,W)},[b,B]),useEffect(()=>{if(!k||x!=="loaded"||!q.current||!G)return;let{data:m,cellWidth:v,cellHeight:N}=q.current,p=D.current;return k.registerImage({id:p,data:m,x:G.innerX,y:G.innerY,width:v,height:N}),()=>{k.unregisterImage(p);}},[k,x,G]);let j=useCallback(async()=>{if(x!=="loading"){O("loading"),y(null);try{let m=await ur(e);if(c&&Pt()&&G){let N=gt(m.data),p=m.data;if(N!=="png"){let X=fr(m.data);if(!X){O("preview"),await rn(m.localPath),O("placeholder");return}p=X;}let L=Et(p),$,U;if(S&&L){let ce=Math.ceil(L.width/8),ue=Math.ceil(L.height/16),Ce=I??80,me=P??24;if(ce>Ce||ue>me){let je=Ce/ce,ke=me/ue,Se=Math.min(je,ke);ce=Math.max(1,Math.round(ce*Se)),ue=Math.max(1,Math.round(ue*Se));}$=ce,U=ue,V({width:ce,height:ue});}else $=t??G.innerWidth,U=n??G.innerHeight;if($<=0||U<=0)throw new Error("Image area too small");q.current={data:p,localPath:m.localPath,cellWidth:$,cellHeight:U},O("loaded");}else O("preview"),await rn(m.localPath),O("placeholder");}catch(m){let v=m instanceof Error?m:new Error(String(m));y(v.message),O("error"),f?.(v);}}},[e,x,c,G,t,n,S,I,P,O,f]);useEffect(()=>{if(!g||!A.current||!i)return;let m=A.current,v=N=>d?.focusedId!==m?false:N.name==="space"||N.name==="return"||N.name==="r"&&q.current?(j(),true):N.name==="escape"&&x==="loaded"?(q.current=null,O("placeholder"),true):false;return g.registerInputHandler(m,v)},[g,d,i,B,j,x,O]),useEffect(()=>{h&&x==="placeholder"&&G&&G.innerWidth>0&&j();},[h,x,G,j]),useEffect(()=>{let m=D.current;return ()=>{k?.unregisterImage(m);}},[k]);let Q,ne;switch(x){case "placeholder":ne=K?"\u{1F310}":"\u{1F5BC}\uFE0F",Q=`${ne} ${_}`;break;case "loading":ne="\u23F3",Q=`${ne} Loading...`;break;case "loaded":Q=null;break;case "preview":ne="\u{1F441}\uFE0F",Q=`${ne} Previewing...`;break;case "error":ne="\u274C",Q=`${ne} ${w||"Error"}`;break}let ee=S&&H?H.width:t,ae=S&&H?H.height:n,T={...{border:"round",borderColor:"blackBright",justifyContent:"center",alignItems:"center",...r,...ee!==void 0?{width:ee}:{},...ae!==void 0?{height:ae}:{}},...E?{borderColor:"cyan"}:{},...E&&o?o:{}},a={color:"blackBright",...s,...E?{color:"cyan"}:{}};return oe.createElement("box",{style:T,focusable:i,ref:m=>{m?(R.current=m,A.current=m.focusId,F(true)):(R.current=null,A.current=null,F(false));}},Q!==null?oe.createElement("text",{style:a},Q):null)}function Is(e){let t=useContext(z),[n]=useState(()=>`focus-${Math.random().toString(36).slice(2,9)}`),r=t?t.focusedId===n:false;useEffect(()=>{if(!(!t||!e?.current))return e.current.focusId=n,t.register(n,e.current)},[t,n,e]);let o=useMemo(()=>()=>{t?.requestFocus(n);},[t,n]);return {focused:r,focus:o}}function Rs(e={}){let{disabled:t,onFocus:n,onBlur:r,onKeyPress:o}=e,s=useContext(z),i=useContext(J),c=useRef(null),l=useRef(null),[u,f]=useState(false),h=useRef(n),S=useRef(r),I=useRef(o);h.current=n,S.current=r,I.current=o;let P=useCallback(g=>{c.current=g,g?l.current=g.focusId??null:l.current=null;},[]);useEffect(()=>{if(!(!s||!l.current||!c.current))return s.register(l.current,c.current)},[s]),useEffect(()=>{!s||!l.current||s.setSkippable(l.current,!!t);},[s,t]),useEffect(()=>{if(!s||!l.current)return;let g=l.current,b=s.focusedId===g;return f(b),s.onFocusChange(k=>{let R=k===g;f(A=>(R&&!A?h.current?.():!R&&A&&S.current?.(),R));})},[s]),useEffect(()=>{if(!i||!l.current||t)return;let g=l.current,b=k=>s?.focusedId!==g?false:I.current?.(k)===true;return i.registerInputHandler(g,b)},[i,s,t]);let d=useCallback(()=>{s&&l.current&&s.requestFocus(l.current);},[s]);return {ref:P,isFocused:u,focus:d,focusId:l.current}}function Ps(){let e=useContext(Be);if(!e)throw new Error("useApp must be used within a Glyph render tree");return {exit:e.exit,get columns(){return e.columns},get rows(){return e.rows}}}function Fs(){let e=useContext(z),t=useContext(se),[n,r]=useState([]),o=useRef(()=>{}),s=useCallback(()=>{if(!e)return;let c=(e.getActiveElements?.()??e.getRegisteredElements?.()??[]).map(({id:l,node:u})=>({id:l,node:u,layout:t?.getLayout(u)??u.layout,type:u.type}));c.sort((l,u)=>l.layout.y!==u.layout.y?l.layout.y-u.layout.y:l.layout.x-u.layout.x),r(c);},[e,t]);return o.current=s,useEffect(()=>{if(!e)return;s();let i=e.onFocusChange(()=>{s();}),c=setTimeout(s,50);return ()=>{i(),clearTimeout(c);}},[e,t,s]),e?{elements:n,focusedId:e.focusedId,requestFocus:e.requestFocus,focusNext:e.focusNext,focusPrev:e.focusPrev,refresh:()=>o.current()}:null}function Gs(e){let t=[];for(let n of e)switch(n){case "9":t.push({type:"digit",char:n});break;case "a":t.push({type:"letter",char:n});break;case "*":t.push({type:"alphanumeric",char:n});break;default:t.push({type:"literal",char:n});break}return t}function Ls(e,t){switch(t){case "digit":return /\d/.test(e);case "letter":return /[a-zA-Z]/.test(e);case "alphanumeric":return /[a-zA-Z0-9]/.test(e);case "literal":return true}}function ie(e){let t=typeof e=="string"?{mask:e}:e,{mask:n,placeholder:r="_",showPlaceholder:o=false}=t,s=Gs(n);return (i,c)=>{let l=[];for(let h of i)(h!==r&&!/[\s\-\(\)\/\.\:]/.test(h)||/[a-zA-Z0-9]/.test(h))&&/[a-zA-Z0-9]/.test(h)&&l.push(h);let u="",f=0;for(let h of s)if(h.type==="literal")(f<l.length||o)&&(u+=h.char);else if(f<l.length){let S=l[f];if(Ls(S,h.type))u+=S,f++;else {f++;continue}}else o&&(u+=r);return u}}var Ms={usPhone:ie("(999) 999-9999"),intlPhone:ie("+9 999 999 9999"),dateUS:ie("99/99/9999"),dateEU:ie("99/99/9999"),dateISO:ie("9999-99-99"),time:ie("99:99"),timeFull:ie("99:99:99"),creditCard:ie("9999 9999 9999 9999"),ssn:ie("999-99-9999"),zip:ie("99999"),zipPlus4:ie("99999-9999"),ipv4:ie("999.999.999.999"),mac:ie("**:**:**:**:**:**")};export{eo as Box,yo as Button,zo as Checkbox,Qo as DialogHost,Bt as FocusScope,xs as Image,so as Input,rs as JumpNav,po as Keybind,Vt as List,Po as Menu,ho as Portal,Bo as Progress,Uo as Radio,ko as ScrollView,qo as Select,uo as Spacer,Mo as Spinner,ro as Text,Wo as ToastHost,ie as createMask,Oe as detectTerminalCapabilities,Ms as masks,Rt as parseAnsi,Yr as render,kt as stripAnsi,Pt as supportsInlineImages,Ps as useApp,Yo as useDialog,Is as useFocus,Fs as useFocusRegistry,Rs as useFocusable,qe as useInput,xe as useLayout,Do as useToast};//# sourceMappingURL=index.js.map
18
+ '`,()=>{});}function Cs(e){return new Promise((t,n)=>{let r=platform(),o,s;r==="linux"?(o="xdg-open",s=[e]):r==="win32"?(o="cmd",s=["/c","start",'""',e]):(o="open",s=[e]);let i=spawn(o,s,{detached:true,stdio:["ignore","ignore","ignore"]});i.unref(),i.on("error",c=>{n(new Error(`Failed to open preview: ${c.message}`));}),setTimeout(t,100);})}function Ss({src:e,width:t,height:n,style:r,focusedStyle:o,placeholderStyle:s,focusable:i=true,inline:c=true,placeholder:l,onStateChange:u,onError:f,autoLoad:m=false,autoSize:S=false,maxWidth:I,maxHeight:E}){let d=useContext(X),h=useContext(Q),y=useContext(ie),R=useContext(ft),k=useContext(Le),j=useRef(null),V=useRef(null),B=useRef(Math.floor(Math.random()*1e6)),G=useRef(0),[N,M]=useState(false),[C,b]=useState(false),[x,g]=useState("placeholder"),[$,W]=useState(null),[A,O]=useState(null),[U,_]=useState(null),[D,q]=useState(true),H=useRef(null),fe=l||on(e),ge=bt(e),J=useCallback(v=>{g(v),u?.(v);},[u]);useEffect(()=>{if(!(!d||!V.current||!j.current||!i))return d.register(V.current,j.current)},[d,i,N]),useEffect(()=>{if(!d||!V.current)return;let v=V.current;return b(d.focusedId===v),d.onFocusChange(L=>{b(L===v);})},[d,N]),useEffect(()=>{if(!(!y||!j.current))return O(y.getLayout(j.current)),y.subscribe(j.current,O)},[y,N]),useEffect(()=>{if(!k)return;let v=()=>{let K=k.getBounds().scrollOffset;return K!==G.current?(G.current=K,q(false),true):false},L=setInterval(()=>{if(!v()&&!D){let K=k.getBounds();if(A){let ce=A.innerY,te=A.innerY+(H.current?.cellHeight??0)>K.visibleTop&&ce<K.visibleBottom;q(te);}}},50);return ()=>clearInterval(L)},[k,A,D]),useEffect(()=>{if(!R||x!=="loaded"||!H.current||!A||k&&!D)return;let{data:v,cellWidth:L,cellHeight:z}=H.current,K=B.current;return R.registerImage({id:K,data:v,x:A.innerX,y:A.innerY,width:L,height:z}),()=>{R.unregisterImage(K);}},[R,x,A,k,D]);let se=useCallback(async()=>{if(x!=="loading"){J("loading"),W(null);try{let v=await dr(e);if(c&&Et()&&A){let z=Ct(v.data),K=v.data;if(z!=="png"){let pe=mr(v.data);if(!pe){J("preview"),await sn(v.localPath),J("placeholder");return}K=pe;}let ce=Bt(K),ee,te;if(S&&ce){let de=Math.ceil(ce.width/8),ae=Math.ceil(ce.height/16),rt=I??80,ot=E??24;if(de>rt||ae>ot){let wr=rt/de,Ir=ot/ae,ln=Math.min(wr,Ir);de=Math.max(1,Math.round(de*ln)),ae=Math.max(1,Math.round(ae*ln));}ee=de,te=ae,_({width:de,height:ae});}else ee=t??A.innerWidth,te=n??A.innerHeight;if(ee<=0||te<=0)throw new Error("Image area too small");let Ie=30,ve=6;if(ee>Ie||te>ve){let pe=Ie/ee,Ee=ve/te,ye=Math.min(pe,Ee);ee=Math.max(1,Math.round(ee*ye)),te=Math.max(1,Math.round(te*ye));}H.current={data:K,localPath:v.localPath,cellWidth:ee,cellHeight:te},J("loaded");}else J("preview"),await sn(v.localPath),J("placeholder");}catch(v){let L=v instanceof Error?v:new Error(String(v));W(L.message),J("error"),f?.(L);}}},[e,x,c,A,t,n,S,I,E,J,f]);useEffect(()=>{if(!h||!V.current||!i)return;let v=V.current,L=z=>d?.focusedId!==v?false:z.name==="space"||z.name==="return"||z.name==="r"&&H.current?(se(),true):z.name==="escape"&&x==="loaded"?(H.current=null,J("placeholder"),true):false;return h.registerInputHandler(v,L)},[h,d,i,N,se,x,J]),useEffect(()=>{m&&x==="placeholder"&&A&&A.innerWidth>0&&se();},[m,x,A,se]),useEffect(()=>{let v=B.current;return ()=>{R?.unregisterImage(v);}},[R]);let Y,T;switch(x){case "placeholder":T=ge?"\u{1F310}":"\u{1F5BC}\uFE0F",Y=`${T} ${fe}`;break;case "loading":T="\u23F3",Y=`${T} Loading...`;break;case "loaded":Y=null;break;case "preview":T="\u{1F441}\uFE0F",Y=`${T} Previewing...`;break;case "error":T="\u274C",Y=`${T} ${$||"Error"}`;break}let a=S&&U?U.width:t,w=S&&U?U.height:n,F={...{border:"round",borderColor:"blackBright",justifyContent:"center",alignItems:"center",...r,...a!==void 0?{width:a}:{},...w!==void 0?{height:w}:{}},...C?{borderColor:"cyan"}:{},...C&&o?o:{}},p={color:"blackBright",...s,...C?{color:"cyan"}:{}};return oe.createElement("box",{style:F,focusable:i,ref:v=>{v?(j.current=v,V.current=v.focusId,M(true)):(j.current=null,V.current=null,M(false));}},Y!==null?oe.createElement("text",{style:p},Y):null)}function ks(e){let t=useContext(X),[n]=useState(()=>`focus-${Math.random().toString(36).slice(2,9)}`),r=t?t.focusedId===n:false;useEffect(()=>{if(!(!t||!e?.current))return e.current.focusId=n,t.register(n,e.current)},[t,n,e]);let o=useMemo(()=>()=>{t?.requestFocus(n);},[t,n]);return {focused:r,focus:o}}function Ts(e={}){let{disabled:t,onFocus:n,onBlur:r,onKeyPress:o}=e,s=useContext(X),i=useContext(Q),c=useRef(null),l=useRef(null),[u,f]=useState(false),m=useRef(n),S=useRef(r),I=useRef(o);m.current=n,S.current=r,I.current=o;let E=useCallback(h=>{c.current=h,h?l.current=h.focusId??null:l.current=null;},[]);useEffect(()=>{if(!(!s||!l.current||!c.current))return s.register(l.current,c.current)},[s]),useEffect(()=>{!s||!l.current||s.setSkippable(l.current,!!t);},[s,t]),useEffect(()=>{if(!s||!l.current)return;let h=l.current,y=s.focusedId===h;return f(y),s.onFocusChange(R=>{let k=R===h;f(j=>(k&&!j?m.current?.():!k&&j&&S.current?.(),k));})},[s]),useEffect(()=>{if(!i||!l.current||t)return;let h=l.current,y=R=>s?.focusedId!==h?false:I.current?.(R)===true;return i.registerInputHandler(h,y)},[i,s,t]);let d=useCallback(()=>{s&&l.current&&s.requestFocus(l.current);},[s]);return {ref:E,isFocused:u,focus:d,focusId:l.current}}function Ns(){let e=useContext(Fe);if(!e)throw new Error("useApp must be used within a Glyph render tree");return {exit:e.exit,get columns(){return e.columns},get rows(){return e.rows}}}function Ms(){let e=useContext(X),t=useContext(ie),[n,r]=useState([]),o=useRef(()=>{}),s=useCallback(()=>{if(!e)return;let c=(e.getActiveElements?.()??e.getRegisteredElements?.()??[]).map(({id:l,node:u})=>({id:l,node:u,layout:t?.getLayout(u)??u.layout,type:u.type}));c.sort((l,u)=>l.layout.y!==u.layout.y?l.layout.y-u.layout.y:l.layout.x-u.layout.x),r(c);},[e,t]);return o.current=s,useEffect(()=>{if(!e)return;s();let i=e.onFocusChange(()=>{s();}),c=setTimeout(s,50);return ()=>{i(),clearTimeout(c);}},[e,t,s]),e?{elements:n,focusedId:e.focusedId,requestFocus:e.requestFocus,focusNext:e.focusNext,focusPrev:e.focusPrev,refresh:()=>o.current()}:null}function As(e){let t=[];for(let n of e)switch(n){case "9":t.push({type:"digit",char:n});break;case "a":t.push({type:"letter",char:n});break;case "*":t.push({type:"alphanumeric",char:n});break;default:t.push({type:"literal",char:n});break}return t}function Hs(e,t){switch(t){case "digit":return /\d/.test(e);case "letter":return /[a-zA-Z]/.test(e);case "alphanumeric":return /[a-zA-Z0-9]/.test(e);case "literal":return true}}function le(e){let t=typeof e=="string"?{mask:e}:e,{mask:n,placeholder:r="_",showPlaceholder:o=false}=t,s=As(n);return (i,c)=>{let l=[];for(let m of i)(m!==r&&!/[\s\-\(\)\/\.\:]/.test(m)||/[a-zA-Z0-9]/.test(m))&&/[a-zA-Z0-9]/.test(m)&&l.push(m);let u="",f=0;for(let m of s)if(m.type==="literal")(f<l.length||o)&&(u+=m.char);else if(f<l.length){let S=l[f];if(Hs(S,m.type))u+=S,f++;else {f++;continue}}else o&&(u+=r);return u}}var js={usPhone:le("(999) 999-9999"),intlPhone:le("+9 999 999 9999"),dateUS:le("99/99/9999"),dateEU:le("99/99/9999"),dateISO:le("9999-99-99"),time:le("99:99"),timeFull:le("99:99:99"),creditCard:le("9999 9999 9999 9999"),ssn:le("999-99-9999"),zip:le("99999"),zipPlus4:le("99999-9999"),ipv4:le("999.999.999.999"),mac:le("**:**:**:**:**:**")};export{ro as Box,Co as Button,Jo as Checkbox,ts as DialogHost,Ft as FocusScope,Ss as Image,co as Input,is as JumpNav,go as Keybind,Dt as List,No as Menu,xo as Portal,Lo as Progress,Qo as Radio,Eo as ScrollView,Uo as Select,mo as Spacer,jo as Spinner,io as Text,zo as ToastHost,le as createMask,De as detectTerminalCapabilities,js as masks,Pt as parseAnsi,eo as render,Tt as stripAnsi,Et as supportsInlineImages,Ns as useApp,es as useDialog,ks as useFocus,Ms as useFocusRegistry,Ts as useFocusable,ze as useInput,Se as useLayout,_o as useToast};//# sourceMappingURL=index.js.map
19
19
  //# sourceMappingURL=index.js.map