@nick-skriabin/glyph 0.1.68 → 0.1.70
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 +15 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import ae,{createContext,forwardRef,useContext,useRef,useState,useEffect,useLayoutEffect,useMemo,useCallback}from'react';import $r from'react-reconciler';import Pe from'string-width';import Xn,{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 Sn(){return `glyph-focus-${Vr++}`}function In(e,t){let n=t.style??{};return {type:e,props:t,style:n,children:[],rawTextChildren:[],allChildren:[],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?Sn():null,hidden:false}}function Mt(e,t){t.parent=e,e.children.push(t),e.allChildren.push(t);}function Lt(e,t){t.parent=e,e.rawTextChildren.push(t),e.allChildren.push(t),e.text=e.rawTextChildren.map(n=>n.text).join("");}function wn(e,t){let n=e.children.indexOf(t);n!==-1&&(e.children.splice(n,1),t.parent=null);let r=e.allChildren.indexOf(t);r!==-1&&e.allChildren.splice(r,1);}function Rn(e,t){t.parent=null;let n=e.rawTextChildren.indexOf(t);n!==-1&&e.rawTextChildren.splice(n,1);let r=e.allChildren.indexOf(t);r!==-1&&e.allChildren.splice(r,1),e.text=e.rawTextChildren.map(o=>o.text).join("")||null;}function vn(e,t,n){t.parent=e;let r=e.children.indexOf(n);r!==-1?e.children.splice(r,0,t):e.children.push(t);let o=e.allChildren.indexOf(n);o!==-1?e.allChildren.splice(o,0,t):e.allChildren.push(t);}function Tn(e,t,n){t.parent=e,e.rawTextChildren.push(t);let r=e.allChildren.indexOf(n);r!==-1?e.allChildren.splice(r,0,t):e.allChildren.push(t),e.text=e.rawTextChildren.map(o=>o.text).join("");}function dt(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 At(e,t={}){let n=[],r={color:e.style.color??t.color,bg:e.style.bg??t.bg,bold:e.style.bold??t.bold,dim:e.style.dim??t.dim,italic:e.style.italic??t.italic,underline:e.style.underline??t.underline};if(e.allChildren.length===0&&e.text!=null)return n.push({text:e.text,style:r}),n;for(let o of e.allChildren)o.type==="raw-text"?n.push({text:o.text,style:r}):n.push(...At(o,r));return n}var Ht=32,kn={supportsMutation:true,supportsPersistence:false,supportsHydration:false,isPrimaryRenderer:true,scheduleTimeout:setTimeout,cancelTimeout:clearTimeout,noTimeout:-1,supportsMicrotasks:true,scheduleMicrotask:queueMicrotask,getCurrentUpdatePriority:()=>Ht,setCurrentUpdatePriority:e=>{},resolveUpdatePriority:()=>Ht,getCurrentEventPriority:()=>Ht,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 In(e,t)},createTextInstance(e,t,n,r){return {type:"raw-text",text:e,parent:null}},appendInitialChild(e,t){t.type==="raw-text"?Lt(e,t):Mt(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){t.type==="raw-text"?Lt(e,t):Mt(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){if(t.type==="raw-text")Tn(e,t,n);else if(n.type==="raw-text"){let r=t;r.parent=e,e.children.push(r);let o=e.allChildren.indexOf(n);o!==-1?e.allChildren.splice(o,0,r):e.allChildren.push(r);}else vn(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){t.type==="raw-text"?Rn(e,t):wn(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 ze=$r(kn);ze.injectIntoDevTools({bundleType:process.env.NODE_ENV==="production"?0:1,version:"0.1.0",rendererPackageName:"glyph"});var mt=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 Pn(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 Or(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 ht(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 En(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=Kr(e,n);if(s){t.push(s.key),n=s.end;continue}}if(e[n+1]==="O"){let s=Dr(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 Dr(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 Kr(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),f=parseInt(c[2]??"0",10);i={name:Pn(f),sequence:s},ht(i,l);break}if(i={name:Or(r),sequence:s},r.includes(";")){let c=r.split(";"),l=parseInt(c[1]??"1",10);ht(i,l);}break}case "u":{let c=r.split(";"),l=parseInt(c[0]??"0",10),f=parseInt(c[1]??"1",10);i={name:Pn(l),sequence:s},ht(i,f);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&&ht(i,l);}return {key:i,end:n}}var Wr={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"},_r={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 jt(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 Nn(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=jt(e);return `\x1B[38;2;${o};${s};${i}m`}return Wr[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}=jt(e);return `\x1B[48;2;${o};${s};${i}m`}return _r[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 Bn={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]},Fn=["black","red","green","yellow","blue","magenta","cyan","white","blackBright","redBright","greenBright","yellowBright","blueBright","magentaBright","cyanBright","whiteBright"],Xe=null;function Mn(e){e.size>0&&(Xe=e);}function qr(e){if(Xe){let t=Fn.indexOf(e);if(t!==-1){let n=Xe.get(t);if(n)return n}}return Bn[e]??null}function zr(e){if(typeof e=="string"){if(e.startsWith("#")){let t=jt(e);return [t.r,t.g,t.b]}return qr(e)}if(typeof e=="number"){if(e<16){if(Xe){let s=Xe.get(e);if(s)return s}return Bn[Fn[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 gt(e){let t=zr(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 Ln(e){return e&>(e)?"black":"white"}var Ue=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,f){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:f});}fillRect(t,n,r,o,s,i,c){for(let l=n;l<n+o;l++)for(let f=t;f<t+r;f++)this.setChar(f,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 Xr={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 An(e){return e==="none"?null:Xr[e]}function Hn(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 f of o){let p=Pe(f);p>l&&(l=p);}return {width:l,height:o.length}}let s=Math.max(1,Math.floor(t)),i=ve(o,s,r),c=0;for(let l of i){let f=Pe(l);f>c&&(c=f);}return {width:c,height:i.length}}function ve(e,t,n){let r=[];for(let o of e){if(Pe(o)<=t){r.push(o);continue}if(n==="truncate"){r.push(
|
|
3
|
-
`)
|
|
4
|
-
`),j=ve(M,l,N),I=0,x=0;if(V){let S=o.position,A=0,X=S,$=0;for(let W=0;W<M.length;W++){let B=M[W].length;if(S<=$+B){A=W,X=S-$;break}$+=B+1;}let _=0;for(let W=0;W<A;W++)_+=ve([M[W]],l,N).length;let G=ve([M[A]],l,N),J=0,D=0;for(let W=0;W<G.length;W++){let B=G[W];if(X<=J+B.length){D=W;break}J+=B.length;}I=_+D,x=Pe(M[A].slice(J,J+(X-J)));}let w=Math.max(0,I-f+1);for(let S=0;S<f;S++){let A=w+S;if(A>=j.length)break;let X=j[A],$=0;for(let _ of X){if($>=l)break;let G=Pe(_);G>0&&Se(t,n,i+$,c+S,_,T,h.bg,h.bold,F,h.italic,h.underline),$+=G;}}if(V){let S=I-w;if(S>=0&&S<f){let A=Math.min(x,l-1),X=i+A,$=c+S;if(yt(X,$,n)&&X<i+l)if(s)k={cursorPosition:{x:X,y:$,bg:h.bg}};else {let _=t.get(X,$),G=_?.ch&&_.ch!==" "?_.ch:"\u258C",J=h.bg??"black",D=h.color??"white";t.setChar(X,$,G,J,D,_?.bold,_?.dim,_?.italic,false);}}}}else {let N=0;for(let M of y){if(N>=l)break;let j=Pe(M);j>0&&Se(t,n,i+N,c,M,T,h.bg,h.bold,F,h.italic,h.underline),N+=j;}if(V){let M=Math.min(o.position,l-1),j=i+M;if(yt(j,c,n)&&j<i+l)if(s)k={cursorPosition:{x:j,y:c,bg:h.bg}};else {let I=t.get(j,c),x=I?.ch&&I.ch!==" "?I.ch:"\u258C",w=h.bg??"black",S=h.color??"white";t.setChar(j,c,x,w,S,I?.bold,I?.dim,I?.italic,false);}}}return k}var oo="\x1B",Fe=`${oo}[`;function so(e,t){return `${Fe}${t+1};${e+1}H`}function io(e){let t=`${Fe}0m`;return e.bold&&(t+=`${Fe}1m`),e.dim&&(t+=`${Fe}2m`),e.italic&&(t+=`${Fe}3m`),e.underline&&(t+=`${Fe}4m`),e.fg!=null&&(t+=Nn(e.fg)),e.bg!=null&&(t+=Gn(e.bg)),t}function Wn(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 f=t.get(l,c);if(!n){let m=e.get(l,c);if(m&&t.cellsEqual(f,m))continue}(s!==c||o!==l)&&(r+=so(l,c));let p=io(f);p!==i&&(r+=p,i=p),r+=f.ch,o=l+1,s=c;}return r.length>0&&(r+=`${Fe}0m`),r}var uo={row:FlexDirection.Row,column:FlexDirection.Column},fo={"flex-start":Justify.FlexStart,center:Justify.Center,"flex-end":Justify.FlexEnd,"space-between":Justify.SpaceBetween,"space-around":Justify.SpaceAround},po={"flex-start":Align.FlexStart,center:Align.Center,"flex-end":Align.FlexEnd,stretch:Align.Stretch};function zn(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%"),t(n));}function Ee(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%")?e.setPositionPercent(t,parseFloat(n)):e.setPosition(t,n));}function mo(e,t,n){zn(e,o=>e.setWidth(o),t.width),zn(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(uo[t.flexDirection]??FlexDirection.Column),t.flexWrap&&e.setFlexWrap(t.flexWrap==="wrap"?Wrap.Wrap:Wrap.NoWrap),t.justifyContent&&e.setJustifyContent(fo[t.justifyContent]??Justify.FlexStart),t.alignItems&&e.setAlignItems(po[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&&(Ee(e,Edge.Top,t.inset),Ee(e,Edge.Right,t.inset),Ee(e,Edge.Bottom,t.inset),Ee(e,Edge.Left,t.inset)),Ee(e,Edge.Top,t.top),Ee(e,Edge.Right,t.right),Ee(e,Edge.Bottom,t.bottom),Ee(e,Edge.Left,t.left),t.clip&&e.setOverflow(Overflow.Hidden);}function Un(e){let t=Xn.Node.create();if(e.yogaNode=t,mo(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=Jn(e),Hn(i,n,r,e.style.wrap??"wrap")});else for(let n=0;n<e.children.length;n++){let r=e.children[n];r.hidden||(Un(r),t.insertChild(r.yogaNode,t.getChildCount()));}}function Jn(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=Jn(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 Yn(e,t,n){let r=e.yogaNode,o=r.getComputedLayout(),s=t+o.left,i=n+o.top,c=o.width,l=o.height,f=e.style.border&&e.style.border!=="none"?1:0,p=r.getComputedPadding(Edge.Top),m=r.getComputedPadding(Edge.Right),y=r.getComputedPadding(Edge.Bottom),C=r.getComputedPadding(Edge.Left),P=s+f+C,h=i+f+p,d=Math.max(0,c-f*2-C-m),g=Math.max(0,l-f*2-p-y),b=e.layout;(!b||b.x!==s||b.y!==i||b.width!==c||b.height!==l||b.innerX!==P||b.innerY!==h||b.innerWidth!==d||b.innerHeight!==g)&&(e.layout={x:s,y:i,width:c,height:l,innerX:P,innerY:h,innerWidth:d,innerHeight:g});for(let T of e.children)T.hidden||!T.yogaNode||Yn(T,s,i);}function Qn(e,t,n){let r=Xn.Node.create();r.setWidth(t),r.setHeight(n),r.setFlexDirection(FlexDirection.Column);for(let o of e)o.hidden||(Un(o),r.insertChild(o.yogaNode,r.getChildCount()));r.calculateLayout(t,n,Direction.LTR);for(let o of e)o.hidden||!o.yogaNode||Yn(o,0,0);r.freeRecursive(),Zn(e);}function Zn(e){for(let t of e)t.yogaNode=null,Zn(t.children);}var Q=createContext(null),z=createContext(null),de=createContext(null),$e=createContext(null),Oe=createContext(null),bt=createContext(null);var ie=null;function Qe(e=false){if(ie)return ie;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"?(ie={name:"kitty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},ie):o||t.includes("ghostty")?(ie={name:"ghostty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},ie):s||n==="WezTerm"?(ie={name:"wezterm",supportsKittyGraphics:true,supportsIterm2Images:true,supportsSixel:true},ie):n==="iTerm.app"||i==="iTerm2"?(ie={name:"iterm2",supportsKittyGraphics:false,supportsIterm2Images:true,supportsSixel:false},ie):c?(ie={name:"konsole",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:true},ie):n==="vscode"?(ie={name:"vscode",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},ie):(ie={name:"unknown",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},ie)}function Ot(){let e=Qe();return e.supportsKittyGraphics||e.supportsIterm2Images||e.supportsSixel}var ce="\x1B";function Ct(){return !!process.env.TMUX}function Dt(e){if(!Ct())return e;let t=e.replace(/\x1b/g,"\x1B\x1B");return `${ce}Ptmux;${t}${ce}\\`}function er(e){let t=Qe();return t.supportsKittyGraphics?ho(e):t.supportsIterm2Images?go(e):null}function Kt(e){if(Qe().supportsKittyGraphics){let n;return e!==void 0?n=`${ce}_Ga=d,d=i,i=${e}${ce}\\`:n=`${ce}_Ga=d,d=a${ce}\\`,Dt(n)}return null}function ho(e){let{data:t,width:n,height:r,x:o,y:s,id:i}=e,c=t.toString("base64"),l=`${ce}[${s+1};${o+1}H`,f=Wt(t),p="a=T,f=100";i!==void 0&&(p+=`,i=${i}`),f&&(p+=`,s=${f.width},v=${f.height}`),p+=`,c=${n},r=${r}`;let m=4096,y=[l];Ct()&&y.unshift(`${ce}[?25l`);for(let C=0;C<c.length;C+=m){let P=c.slice(C,C+m),d=C+m>=c.length?"m=0":"m=1",g;C===0?g=`${ce}_G${p},${d},q=2;${P}${ce}\\`:g=`${ce}_G${d};${P}${ce}\\`,y.push(Dt(g));}return Ct()&&y.push(`${ce}[?25h`),y.join("")}function go(e){let{data:t,width:n,height:r,x:o,y:s}=e,i=t.toString("base64"),c=`${ce}[${s+1};${o+1}H`,l=[`width=${n}`,`height=${r}`,"preserveAspectRatio=1","inline=1"].join(";"),f=`${ce}]1337;File=${l}:${i}\x07`;return c+(Ct()?Dt(f):f)}function Wt(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 yo(e,t={}){let n=t.stdout??process.stdout,r=t.stdin??process.stdin,o=t.debug??false,s=t.useNativeCursor??true,i=new mt(n,r);i.setup();let c=false;i.queryPalette().then(a=>{Mn(a),p=true,G();});let l=new Ue(i.columns,i.rows),f=new Ue(i.columns,i.rows),p=true,m=new Set,y=new Set,C=new Map,P={subscribe(a){return m.add(a),()=>m.delete(a)},subscribePriority(a){return y.add(a),()=>y.delete(a)},registerInputHandler(a,R){return C.set(a,R),()=>C.delete(a)}},h=new Map,d=new Map,g={registerImage(a){let R=h.get(a.id);(!R||R.x!==a.x||R.y!==a.y||R.width!==a.width||R.height!==a.height)&&(d.set(a.id,a),G());},unregisterImage(a){h.delete(a),d.delete(a);let R=Kt(a);R&&i.write(R),G();}};function b(){for(let a of d.values()){let R=er({data:a.data,width:a.width,height:a.height,x:a.x,y:a.y,id:a.id});R&&(i.write(R),h.set(a.id,{x:a.x,y:a.y,width:a.width,height:a.height}));}d.clear();}let T=null,F=new Map,V=[],k=new Set,N=new Set,M=[],j=new Set;function I(a){if(T!==a){T=a,G();for(let R of j)R(T);}}function x(){let a=[...V];if(M.length>0){let R=M[M.length-1];a=a.filter(v=>R.has(v));}return a=a.filter(R=>!k.has(R)),a.sort((R,v)=>{let u=F.get(R),H=F.get(v);if(!u||!H)return 0;let q=u.layout,K=H.layout;return q.y!==K.y?q.y-K.y:q.x-K.x}),a}let w={get focusedId(){return T},register(a,R,v=true){if(F.set(a,R),V.includes(a)||V.push(a),v||N.add(a),M.length>0&&M[M.length-1].add(a),T===null&&v){let u=x().filter(H=>!N.has(H));u.length>0&&I(u[0]);}return ()=>{F.delete(a),N.delete(a);let u=V.indexOf(a);if(u!==-1&&V.splice(u,1),T===a){let H=x().filter(q=>!N.has(q));I(H[0]??null);}}},requestFocus(a){I(a);},blur(){I(null);},focusNext(){let a=x();if(a.length===0)return;let v=((T?a.indexOf(T):-1)+1)%a.length;I(a[v]);},focusPrev(){let a=x();if(a.length===0)return;let v=((T?a.indexOf(T):0)-1+a.length)%a.length;I(a[v]);},setSkippable(a,R){if(R){if(k.add(a),T===a){let v=x();v.length>0&&I(v[0]);}}else k.delete(a);},trapIds:null,pushTrap(a){return M.push(a),()=>{let R=M.indexOf(a);R!==-1&&M.splice(R,1);}},onFocusChange(a){return j.add(a),()=>{j.delete(a);}},getRegisteredElements(){let a=[];for(let R of V){if(k.has(R))continue;let v=F.get(R);v&&a.push({id:R,node:v});}return a},getActiveElements(){let a=x(),R=[];for(let v of a){if(k.has(v))continue;let u=F.get(v);u&&R.push({id:v,node:u});}return R}},S=new Map,A={getLayout(a){return a.layout},subscribe(a,R){return S.has(a)||S.set(a,new Set),S.get(a).add(R),()=>{let v=S.get(a);v&&(v.delete(R),v.size===0&&S.delete(a));}}},X={registerNode(){},unregisterNode(){},scheduleRender:G,exit(a){L.exit(a);},get columns(){return i.columns},get rows(){return i.rows}},$={type:"root",children:[],onCommit(){G();}},_=false;function G(){_||(_=true,queueMicrotask(()=>{_=false,J();}));}function J(){let a=i.columns,R=i.rows;(f.width!==a||f.height!==R)&&(f.resize(a,R),l.resize(a,R),p=true),Qn($.children,a,R),D($.children);let v;if(T){let q=F.get(T);q?.type==="input"&&(v={nodeId:T,position:q.props.cursorPosition??q.props.value?.length??0});}let u=On($.children,f,{cursorInfo:v,useNativeCursor:s}),H=Wn(l,f,p);if(H.length>0&&i.write(H),d.size>0&&c&&(i.hideCursor(),c=false),b(),s)if(u.cursorPosition){let q=Ln(u.cursorPosition.bg);i.setCursorColor(q),i.moveCursor(u.cursorPosition.x,u.cursorPosition.y),c||(i.showCursor(),c=true);}else i.hideCursor(),c=false;for(let q=0;q<f.cells.length;q++)l.cells[q]={...f.cells[q]};p=false;}function D(a){for(let R of a){let v=S.get(R);if(v)for(let u of v)u(R.layout);D(R.children);}}let W=i.onData(a=>{let R=En(a);for(let v of R){if(v.ctrl&&v.name==="c"){L.exit();return}if(v.ctrl&&v.name==="z"){i.suspend(),process.kill(0,"SIGSTOP");return}let u=false;for(let H of y)if(H(v)){u=true;break}if(!u&&T){let H=C.get(T);H&&(u=H(v));}if(!u&&v.name==="tab"&&!v.ctrl&&!v.alt){v.shift?w.focusPrev():w.focusNext();continue}if(!u)for(let H of m)H(v);}}),B=i.onResize(()=>{p=true,G();}),ue=()=>{i.resume(),p=true,G();};process.on("SIGCONT",ue);let re=ae.createElement($e.Provider,{value:X},ae.createElement(Q.Provider,{value:P},ae.createElement(z.Provider,{value:w},ae.createElement(de.Provider,{value:A},ae.createElement(bt.Provider,{value:g},e))))),oe=a=>{o&&console.error("Uncaught error:",a);},ee=a=>{o&&console.error("Error caught by boundary:",a);},te=a=>{o&&console.error("Recoverable error:",a);},E=ze.createContainer($,0,null,false,null,"",oe,ee,te,null);ze.updateContainer(re,E,null,null);let L={unmount(){ze.updateContainer(null,E,null,null),W(),B(),process.off("SIGCONT",ue);let a=Kt();a&&i.write(a),i.cleanup();},exit(a){L.unmount(),process.exit(a??0);}};return L}var Co=forwardRef(function({children:t,style:n,focusable:r},o){return ae.createElement("box",{style:n,focusable:r,ref:o},t)});var ko=forwardRef(function({children:t,style:n,wrap:r,focusable:o,focusedStyle:s},i){let c=useContext(z),l=useRef(null),[f,p]=useState(false);useEffect(()=>{if(!c||!o||!l.current?.focusId)return;let C=l.current.focusId;return p(c.focusedId===C),c.onFocusChange(P=>{p(P===C);})},[c,o]);let m=r?{...n,wrap:r}:n;f&&s&&(m={...m,...s});let y=C=>{l.current=C,typeof i=="function"?i(C):i&&(i.current=C);};return ae.createElement("text",{style:m,focusable:o,ref:y},t)});function tr(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 f=ve([l],n,"wrap"),p=0;for(let m of f)o.push({text:m,logicalOffset:s+p}),p+=m.length;s+=l.length+1;}let i=0;for(let l=0;l<o.length;l++){let f=o[l],p=f.text.length,m=l+1<o.length&&o[l+1].logicalOffset!==f.logicalOffset+p,
|
|
6
|
-
`),s=[],i=0;for(let p of o){let m=ve([p],r,"wrap"),
|
|
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 nt(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 Eo(e){let{value:t,defaultValue:n="",onChange:r,onKeyPress:o,onBeforeChange:s,placeholder:i,style:c,focusedStyle:l,multiline:f,autoFocus:p,type:m="text"}=e,[
|
|
8
|
-
`+
|
|
9
|
-
`);)u--;let H=
|
|
10
|
-
`;)u--;return
|
|
11
|
-
`;)u++;for(;u<
|
|
12
|
-
`;)u--;let H=
|
|
13
|
-
`;)u++;for(;u<
|
|
14
|
-
`)))))}function en({count:e,renderItem:t,selectedIndex:n,onSelectionChange:r,onSelect:o,defaultSelectedIndex:s=0,disabledIndices:i,style:c,focusable:l=true}){let f=n!==void 0,[p,m]=useState(s),y=f?n:p,C=useContext(z),P=useContext(Q),h=useRef(null),d=useRef(null),g=useRef(o);g.current=o;let[b,T]=useState(false),[F,V]=useState(false),k=useRef(null),N=useCallback(x=>{let w=Math.max(0,Math.min(x,e-1));f?r?.(w):m(w);},[f,r,e]),M=useCallback((x,w)=>{if(!i||i.size===0)return Math.max(0,Math.min(x+w,e-1));let S=x+w;for(;S>=0&&S<e&&i.has(S);)S+=w;return S<0||S>=e?x:S},[i,e]);useEffect(()=>{if(!(!C||!d.current||!h.current||!l))return C.register(d.current,h.current)},[C,l,b]),useEffect(()=>{if(!C||!d.current)return;let x=d.current;return V(C.focusedId===x),C.onFocusChange(w=>{V(w===x);})},[C,b]);let j=useCallback(x=>{let w=x?e-1:0,S=x?-1:1,A=w;for(;A>=0&&A<e&&i?.has(A);)A+=S;return A>=0&&A<e?A:x?e-1:0},[i,e]);useEffect(()=>{if(!P||!d.current||!l)return;let x=d.current,w=S=>C?.focusedId!==x?false:S.name==="g"&&!S.ctrl&&!S.alt?k.current==="g"?(N(j(false)),k.current=null,true):(k.current="g",true):S.name==="G"||S.name==="g"&&S.shift?(k.current=null,N(j(true)),true):(k.current=null,S.name==="up"||S.name==="k"?(N(M(y,-1)),true):S.name==="down"||S.name==="j"?(N(M(y,1)),true):S.name==="return"?(i?.has(y)||g.current?.(y),true):false);return P.registerInputHandler(x,w)},[P,C,l,y,N,M,j,i,b]);let I=[];for(let x=0;x<e;x++)I.push(ae.createElement(ae.Fragment,{key:x},t({index:x,selected:x===y,focused:F})));return ae.createElement("box",{style:{flexDirection:"column",...c},focusable:l,ref:x=>{x?(h.current=x,d.current=x.focusId,T(true)):(h.current=null,d.current=null,T(false));}},...I)}function Xo({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 p=0;p<e.length;p++)e[p].disabled&&l.add(p);let f=p=>{let m=e[p];m&&!m.disabled&&r?.(m.value,p);};return ae.createElement(en,{count:e.length,selectedIndex:t,onSelectionChange:n,onSelect:f,defaultSelectedIndex:o,disabledIndices:l.size>0?l:void 0,style:s,focusable:c,renderItem:({index:p,selected:m,focused:y})=>{let C=e[p],P=C.disabled,h=m&&y,d=m?">":" ";return ae.createElement("box",{style:{flexDirection:"row",...h?{bg:i}:{}}},ae.createElement("text",{style:h?{bold:true,color:"black"}:P?{dim:true}:{}},`${d} ${C.label}`))}})}function Qo({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),p=Ge(l).innerWidth,[m,y]=useState(0);useEffect(()=>{if(!t)return;let g=setInterval(()=>{y(b=>(b+1)%Math.max(1,p+6));},100);return ()=>clearInterval(g)},[t,p]);let C=Math.max(0,Math.min(1,e??0)),P=o?` ${Math.round(C*100)}%`:"",h="";if(p>0)if(t&&e===void 0){let g=Math.max(1,Math.min(3,Math.floor(p/4))),b=[];for(let T=0;T<p;T++)T>=m-g&&T<m?b.push(i):b.push(c);h=b.join("");}else {let g=Math.round(C*p);h=i.repeat(g)+c.repeat(p-g);}let d=[];return r&&d.push(ae.createElement("text",{key:"label",style:{bold:true}},r+" ")),d.push(ae.createElement("box",{key:"track",style:{flexGrow:1,flexShrink:1},ref:g=>{l.current=g??null;}},ae.createElement("text",{key:"bar",style:{}},h))),o&&d.push(ae.createElement("text",{key:"pct",style:{bold:true}},P)),ae.createElement("box",{style:{flexDirection:"row",width:n,...s}},...d)}var ts=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function ns({frames:e=ts,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=[ae.createElement("text",{key:"frame",style:r},e[o])];return n&&i.push(ae.createElement("text",{key:"label",style:{}}," "+n)),ae.createElement("box",{style:{flexDirection:"row"}},...i)}var hr=createContext(null),cs=0;function as(){let e=useContext(hr);if(!e)throw new Error("useToast must be used within a <ToastHost>");return e.push}var us={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 fs({position:e="bottom-right",maxVisible:t=5,children:n}){let[r,o]=useState([]),s=useRef(new Map),i=useCallback(C=>{let P=`toast-${cs++}`,h={id:P,durationMs:3e3,variant:"info",...C};if(o(d=>[...d,h]),h.durationMs&&h.durationMs>0){let d=setTimeout(()=>{s.current.delete(P),o(g=>g.filter(b=>b.id!==P));},h.durationMs);s.current.set(P,d);}},[]);useEffect(()=>()=>{for(let C of s.current.values())clearTimeout(C);s.current.clear();},[]);let c=useRef({push:i});c.current.push=i;let l=e.startsWith("top"),f=e.endsWith("right"),p={position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:900,flexDirection:"column",justifyContent:l?"flex-start":"flex-end",alignItems:f?"flex-end":"flex-start",padding:1},y=r.slice(-t).map(C=>{let P=C.variant??"info",h=us[P],d=[];return C.title&&d.push(ae.createElement("text",{key:"title",style:{bold:true,color:h.title}},C.title)),d.push(ae.createElement("text",{key:"msg",style:{color:h.text}},C.message)),ae.createElement("box",{key:C.id,style:{bg:h.bg,paddingX:1,flexDirection:"column",minWidth:20,maxWidth:50}},...d)});return ae.createElement(hr.Provider,{value:c.current},n,y.length>0?ae.createElement("box",{style:p},...y):null)}function ds({items:e,value:t,onChange:n,placeholder:r="Select...",style:o,focusedStyle:s,dropdownStyle:i,highlightColor:c="cyan",maxVisible:l=8,searchable:f=true,disabled:p}){let m=useContext(z),y=useContext(Q),C=useContext($e),P=useContext(Oe),h=useRef(null),d=useRef(null),g=useRef(n);g.current=n;let[b,T]=useState(false),[F,V]=useState(false),[k,N]=useState(false),[M,j]=useState(0),[I,x]=useState(""),[w,S]=useState(0),A=Ge(h),X=C?.rows??24,$=P?.getBounds(),G=e.find(a=>a.value===t)?.label??"",J=useMemo(()=>{if(!I)return e;let a=I.toLowerCase();return e.filter(R=>R.label.toLowerCase().includes(a))},[e,I]),D=Math.min(l,J.length),W=J.slice(w,w+D);useEffect(()=>{j(0),S(0);},[I]),useEffect(()=>{!F&&k&&(N(false),x(""));},[F,k]),useEffect(()=>{if(!(!m||!d.current||!h.current))return m.register(d.current,h.current)},[m,b]),useEffect(()=>{!m||!d.current||m.setSkippable(d.current,!!p);},[m,p,b]),useEffect(()=>{if(!m||!d.current)return;let a=d.current;return V(m.focusedId===a),m.onFocusChange(R=>{V(R===a);})},[m,b]);let B=useCallback((a,R)=>{let v=a+R;for(;v>=0&&v<J.length;){if(!J[v].disabled)return v;v+=R;}return a},[J]),ue=useCallback(a=>{a<w?S(a):a>=w+D&&S(a-D+1);},[w,D]);useEffect(()=>{if(!y||!d.current||p)return;let a=d.current,R=v=>{if(m?.focusedId!==a)return false;if(!k){if(v.name==="return"||v.name===" "||v.sequence===" "||v.name==="down"){N(true),x("");let u=J.findIndex(q=>q.value===t),H=u>=0?u:0;return j(H),S(Math.max(0,H-Math.floor(l/2))),true}return false}if(v.name==="tab")return N(false),x(""),false;if(v.name==="escape")return N(false),x(""),true;if(v.name==="return"){let u=J[M];return u&&!u.disabled&&(g.current?.(u.value),N(false),x("")),true}if(v.name==="up"){let u=B(M,-1);return j(u),ue(u),true}if(v.name==="down"){let u=B(M,1);return j(u),ue(u),true}if(v.name==="backspace")return f&&I.length>0&&x(u=>u.slice(0,-1)),true;if(v.name==="home"){let u=B(-1,1);return j(u),ue(u),true}if(v.name==="end"){let u=B(J.length,-1);return j(u),ue(u),true}if(f&&v.sequence&&v.sequence.length===1&&!v.ctrl&&!v.alt){let u=v.sequence;if(u>=" "&&u<="~")return x(H=>H+u),true}return true};return y.registerInputHandler(a,R)},[y,m,p,k,M,J,t,l,f,I,B,ue,b]);let oe={flexDirection:"row",width:"100%",...!o?.bg&&o?.border===void 0?{border:"single"}:{},...o,...F&&s?s:{}},ee=G?o?.color??void 0:"blackBright",te=[ae.createElement("text",{key:"label",style:{flexGrow:1,flexShrink:1,color:ee,wrap:"ellipsis",...G?{}:{dim:true}}},G||r),ae.createElement("text",{key:"arrow",style:{flexShrink:0,color:F?c:"blackBright"}},k?" \u25B2":" \u25BC")],E=null;if(k){let a=[];f&&I&&a.push(ae.createElement("box",{key:"search",style:{paddingX:1}},ae.createElement("text",{style:{color:"blackBright",dim:true}},`/${I}`))),J.length===0&&a.push(ae.createElement("box",{key:"empty",style:{paddingX:1}},ae.createElement("text",{style:{dim:true,color:"blackBright"}},"No matches"))),w>0&&a.push(ae.createElement("box",{key:"scroll-up",style:{justifyContent:"center",alignItems:"center"}},ae.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25B2"))),W.forEach((Te,He)=>{let ke=w+He===M,we=Te.disabled,Ce={paddingX:1,...ke&&!we?{bg:c}:{}},xe={...ke&&!we?{color:"black",bold:true}:{},...we?{dim:true,color:"blackBright"}:{}};a.push(ae.createElement("box",{key:`item-${Te.value}`,style:Ce},ae.createElement("text",{style:xe},Te.label)));}),w+D<J.length&&a.push(ae.createElement("box",{key:"scroll-down",style:{justifyContent:"center",alignItems:"center"}},ae.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25BC")));let R=w>0,v=w+D<J.length,u=f&&I,H=J.length===0,q=!i?.bg&&i?.border===void 0,Y=D+(q?2:0);R&&(Y+=1),v&&(Y+=1),u&&(Y+=1),H&&(Y+=1);let le=A.y+A.height,be,fe;$?(be=$.visibleBottom-le,fe=A.y-$.visibleTop):(be=X-le,fe=A.y);let ye=be<Y&&fe>=Y?-Y:A.height||1;E=ae.createElement("box",{style:{position:"absolute",top:ye,left:0,right:0,zIndex:9999,...q?{border:"single"}:{},bg:"black",flexDirection:"column",...i}},...a);}let L={flexDirection:"column",width:oe.width??"100%",minWidth:oe.minWidth,maxWidth:oe.maxWidth,flexGrow:oe.flexGrow,flexShrink:oe.flexShrink??1};return ae.createElement("box",{style:L},ae.createElement("box",{style:oe,focusable:true,ref:a=>{a?(h.current=a,d.current=a.focusId,T(true)):(h.current=null,d.current=null,T(false));}},...te),E)}function ms({checked:e,onChange:t,label:n,style:r,focusedStyle:o,disabled:s,checkedChar:i="\u2713",uncheckedChar:c=" "}){let l=useContext(z),f=useContext(Q),p=useRef(null),m=useRef(null),y=useRef(t);y.current=t;let C=useRef(e);C.current=e;let[P,h]=useState(false),[d,g]=useState(false);useEffect(()=>{if(!(!l||!m.current||!p.current||s))return l.register(m.current,p.current)},[l,s,P]),useEffect(()=>{if(!l||!m.current)return;let k=m.current;return g(l.focusedId===k),l.onFocusChange(N=>{g(N===k);})},[l,P]),useEffect(()=>{if(!f||!m.current||s)return;let k=m.current,N=M=>l?.focusedId!==k?false:M.name==="return"||M.name===" "||M.sequence===" "?(y.current(!C.current),true):false;return f.registerInputHandler(k,N)},[f,l,s,P]);let b={flexDirection:"row",gap:1,...r,...d&&o?o:{}},T=e?i:c,F={color:s?"blackBright":d?"white":r?.color},V={color:s?"blackBright":r?.color};return ae.createElement("box",{style:b,focusable:!s,ref:k=>{k?(p.current=k,m.current=k.focusId,h(true)):(p.current=null,m.current=null,h(false));}},ae.createElement("text",{key:"box",style:F},`[${T}]`),n?ae.createElement("text",{key:"label",style:V},n):null)}function gs({items:e,value:t,onChange:n,style:r,itemStyle:o,focusedItemStyle:s,selectedItemStyle:i,disabled:c,direction:l="column",gap:f=0,selectedChar:p="\u25CF",unselectedChar:m="\u25CB"}){let y=useContext(z),C=useContext(Q),P=useRef(null),h=useRef(null),d=useRef(n);d.current=n;let[g,b]=useState(false),[T,F]=useState(false),[V,k]=useState(()=>{let I=e.findIndex(x=>x.value===t);return I>=0?I:e.findIndex(x=>!x.disabled)}),N=useCallback((I,x)=>{let w=I;for(let S=0;S<e.length;S++)if(w=(w+x+e.length)%e.length,!e[w]?.disabled)return w;return I},[e]);useEffect(()=>{if(!(!y||!h.current||!P.current||c))return y.register(h.current,P.current)},[y,c,g]),useEffect(()=>{if(!y||!h.current)return;let I=h.current;return F(y.focusedId===I),y.onFocusChange(x=>{F(x===I);})},[y,g]),useEffect(()=>{if(!C||!h.current||c)return;let I=h.current,x=w=>{if(y?.focusedId!==I)return false;if(w.name==="up"||w.name==="left"||w.name==="k"||w.name==="tab"&&w.shift)return k(S=>N(S,-1)),true;if(w.name==="down"||w.name==="right"||w.name==="j"||w.name==="tab"&&!w.shift)return k(S=>N(S,1)),true;if(w.name==="return"||w.name===" "||w.sequence===" "){let S=e[V];return S&&!S.disabled&&d.current(S.value),true}return false};return C.registerInputHandler(I,x)},[C,y,c,e,V,N,g]),useEffect(()=>{let I=e.findIndex(x=>x.value===t);I>=0&&k(I);},[t,e]);let M={flexDirection:l,gap:f,...r},j=e.map((I,x)=>{let w=I.value===t,S=x===V,A=c||I.disabled,X=w?p:m,$={flexDirection:"row",gap:1,...o};w&&i&&($={...$,...i}),T&&S&&s&&($={...$,...s});let _=A?"blackBright":T&&S?s?.color??"white":w?i?.color??o?.color:o?.color;return ae.createElement("box",{key:x,style:$},ae.createElement("text",{key:"radio",style:{color:_}},`(${X})`),ae.createElement("text",{key:"label",style:{color:_}},I.label))});return ae.createElement("box",{style:M,focusable:!c,ref:I=>{I?(P.current=I,h.current=I.focusId,b(true)):(P.current=null,h.current=null,b(false));}},...j)}var Ir=createContext(null);function xs(){let e=useContext(Ir);if(!e)throw new Error("useDialog must be used within a DialogHost");return e}function bs({children:e}){let[t,n]=useState([]),r=useRef(0),o=useCallback((f,p)=>new Promise(m=>{let y=++r.current;n(C=>[...C,{id:y,type:"alert",content:f,okText:p?.okText??"OK",cancelText:"",style:p?.style,buttonStyle:p?.buttonStyle,okButtonStyle:p?.okButtonStyle,focusedButtonStyle:p?.focusedButtonStyle,backdropStyle:p?.backdropStyle,resolve:()=>m()}]);}),[]),s=useCallback((f,p)=>new Promise(m=>{let y=++r.current;n(C=>[...C,{id:y,type:"confirm",content:f,okText:p?.okText??"OK",cancelText:p?.cancelText??"Cancel",style:p?.style,buttonStyle:p?.buttonStyle,okButtonStyle:p?.okButtonStyle,cancelButtonStyle:p?.cancelButtonStyle,focusedButtonStyle:p?.focusedButtonStyle,backdropStyle:p?.backdropStyle,resolve:m}]);}),[]),i=useCallback((f,p)=>{n(m=>{let y=m.find(C=>C.id===f);return y&&y.resolve(p),m.filter(C=>C.id!==f)});},[]),c={alert:o,confirm:s},l=t[t.length-1];return ae.createElement(Ir.Provider,{value:c},e,l&&ae.createElement(Cs,{key:l.id,dialog:l,onDismiss:i}))}function Cs({dialog:e,onDismiss:t}){let n=useContext(z),r=useRef(null),o=useRef(null),s=useRef(null),i=useRef(null),[c,l]=useState("ok"),[f,p]=useState(0);useEffect(()=>{if(!n||f===0)return;let g=[];return r.current&&s.current&&g.push(n.register(s.current,r.current)),o.current&&i.current&&g.push(n.register(i.current,o.current)),s.current&&n.requestFocus(s.current),()=>g.forEach(b=>b())},[n,f]),useEffect(()=>{if(n)return n.onFocusChange(g=>{g===s.current?l("ok"):g===i.current&&l("cancel");})},[n]),rt(g=>{if(g.name==="return"||g.name==="space"){e.type==="alert"?t(e.id,true):t(e.id,c==="ok");return}if(g.name==="escape"){t(e.id,false);return}e.type==="confirm"&&n&&(g.name==="left"||g.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",y=m?e.content.length:0,P={minWidth:Math.max(20,m?Math.min(y+6,50):30),maxWidth:50,bg:"black",border:"round",borderColor:"white",padding:1,flexDirection:"column",gap:1,...e.style},h=(g,b)=>{let T={paddingX:2,bg:"blackBright",color:"white"},F={bg:"white",color:"black",bold:true},V=g==="ok"?e.okButtonStyle:e.cancelButtonStyle;return {...T,...e.buttonStyle,...V,...b?{...F,...e.focusedButtonStyle}:{}}},d={position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:999,...e.backdropStyle};return ae.createElement(qt,{trap:true},ae.createElement("box",{style:d}),ae.createElement("box",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,justifyContent:"center",alignItems:"center",zIndex:1e3}},ae.createElement("box",{style:P},ae.createElement("box",{style:{flexDirection:"column"}},typeof e.content=="string"?ae.createElement("text",null,e.content):e.content),ae.createElement("box",{style:{flexDirection:"row",justifyContent:"flex-end",gap:1}},e.type==="confirm"&&ae.createElement("box",{style:h("cancel",c==="cancel"),focusable:true,ref:g=>{g&&g.focusId&&!i.current&&(o.current=g,i.current=g.focusId,p(b=>b+1));}},ae.createElement("text",null,e.cancelText)),ae.createElement("box",{style:h("ok",c==="ok"),focusable:true,ref:g=>{g&&g.focusId&&!s.current&&(r.current=g,s.current=g.focusId,p(b=>b+1));}},ae.createElement("text",null,e.okText))))))}function ws(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?(...I)=>console.error("[JumpNav]",...I):()=>{},[f,p]=useState(false),[m,y]=useState(""),[C,P]=useState([]),h=useContext(Q),d=useContext(z),g=useContext(de);useEffect(()=>{l("Mounted, inputCtx:",!!h,"focusCtx:",!!d,"enabled:",i);},[]);let T=useCallback(I=>{let x=I.toLowerCase().split("+");return {ctrl:x.includes("ctrl"),alt:x.includes("alt"),shift:x.includes("shift"),meta:x.includes("meta"),name:x[x.length-1]??""}},[])(t),F=useCallback(()=>{if(!d?.getActiveElements){l("refreshElements: no getActiveElements");return}let I=d.getActiveElements();l("getActiveElements returned",I.length,"elements");let x=I.map(({id:w,node:S})=>({id:w,node:S,layout:g?.getLayout(S)??S.layout}));x.sort((w,S)=>w.layout.y!==S.layout.y?w.layout.y-S.layout.y:w.layout.x-S.layout.x),P(x);},[d,g,l]),V=useRef(false);useEffect(()=>{f&&!V.current&&(l("Activated! Refreshing elements..."),F()),V.current=f;},[f,F,l]);let k=C.filter(I=>I.layout.width>0&&I.layout.height>0),N=ws(k.length,s),M=useMemo(()=>{let I=new Map;return k.forEach((x,w)=>{N[w]&&I.set(N[w],x.id);}),I},[k,N]);useEffect(()=>{if(!h||!i){l("Not subscribing - inputCtx:",!!h,"enabled:",i);return}l("Subscribing to priority input, activation key:",t);let I=x=>{let w=x.name===T.name,S=!!x.ctrl===T.ctrl,A=!!x.alt===T.alt,X=!!x.shift===T.shift,$=!!x.meta===T.meta;if(!f&&w&&S&&A&&X&&$)return l("Activation key matched! Activating..."),p(true),y(""),true;if(f){if(x.name==="escape")return l("Escape pressed, deactivating"),p(false),y(""),true;if(x.name==="backspace")return y(""),true;if(x.sequence&&x.sequence.length===1&&/[a-z]/i.test(x.sequence)){let _=m+x.sequence.toLowerCase();l("Buffer:",_);let G=M.get(_);return G?(l("Jumping to",G),d?.requestFocus(G),p(false),y(""),true):[...M.keys()].some(D=>D.startsWith(_))?(y(_),true):(y(""),true)}return true}return false};return h.subscribePriority(I)},[h,i,f,T,m,M,d,t,l]);let j=f?ae.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:99998}},...k.map((I,x)=>{let w=N[x];if(!w)return null;let{x:S,y:A}=I.layout,X=w.startsWith(m)&&m.length>0;return ae.createElement("box",{key:I.id,style:{position:"absolute",top:A,left:Math.max(0,S-w.length-2),bg:X?"cyan":r,color:o,paddingX:1,zIndex:99999,...n}},ae.createElement("text",{style:{bold:true,color:o}},w))}),ae.createElement("box",{style:{position:"absolute",bottom:0,left:0,right:0,bg:"blackBright",paddingX:1,zIndex:99999}},ae.createElement("text",{style:{color:"white"}},m?`Jump: ${m}_`:"Press a key to jump \u2022 ESC to cancel"))):null;return ae.createElement(ae.Fragment,null,e,j)}var We=join(tmpdir(),"glyph-image-cache");function Et(e){return e.startsWith("http://")||e.startsWith("https://")}function Ps(e,t){let n=createHash("md5").update(e).digest("hex"),r=t?Ns(t):Es(e)||".png";return join(We,`${n}${r}`)}function Es(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 Ns(e){switch(e){case "png":return ".png";case "jpeg":return ".jpeg";case "gif":return ".gif";case "webp":return ".webp";default:return ".png"}}function yn(e){if(Et(e))try{let t=new URL(e),n=t.pathname;return basename(n)||t.hostname}catch{return "remote-image"}return basename(e)}function Tr(){existsSync(We)||mkdirSync(We,{recursive:true});}async function kr(e){let t=yn(e);return Et(e)?Bs(e,t):Gs(e,t)}async function Gs(e,t){if(!existsSync(e))throw new Error(`Image not found: ${e}`);return {data:readFileSync(e),name:t,localPath:e,isRemote:false}}async function Bs(e,t){Tr();let n=createHash("md5").update(e).digest("hex"),r=[".png",".jpeg",".gif",".webp"];for(let f of r){let p=join(We,`${n}${f}`);if(existsSync(p))return {data:readFileSync(p),name:t,localPath:p,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(!Fs(i))throw new Error(`Invalid image data from: ${e}`);let c=Nt(i),l=Ps(e,c);return writeFileSync(l,i),{data:i,name:t,localPath:l,isRemote:true}}function Fs(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 Nt(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 Pr(e,t){let n=Nt(e);if(n==="png")return e;Tr();let r=createHash("md5").update(e).digest("hex"),o=join(We,`${r}.${n}`),s=join(We,`${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 Ls(){let e=platform();return e==="darwin"?"quicklook":e==="linux"||e==="win32"?"open":"none"}async function xn(e){switch(Ls()){case "quicklook":return As(e);case "open":return js(e);case "none":throw new Error("No preview method available on this platform")}}function As(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(()=>{Hs();},50),r.on("close",o=>{t();});})}function Hs(){exec(`osascript -e '
|
|
1
|
+
import ue,{createContext,forwardRef,useContext,useRef,useState,useEffect,useLayoutEffect,useMemo,useCallback}from'react';import $r from'react-reconciler';import Pe from'string-width';import Xn,{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 jr=0;function Sn(){return `glyph-focus-${jr++}`}function wn(e,t){let n=t.style??{};return {type:e,props:t,style:n,children:[],rawTextChildren:[],allChildren:[],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?Sn():null,hidden:false}}function Lt(e,t){t.parent=e,e.children.push(t),e.allChildren.push(t);}function At(e,t){t.parent=e,e.rawTextChildren.push(t),e.allChildren.push(t),e.text=e.rawTextChildren.map(n=>n.text).join("");}function In(e,t){let n=e.children.indexOf(t);n!==-1&&(e.children.splice(n,1),t.parent=null);let r=e.allChildren.indexOf(t);r!==-1&&e.allChildren.splice(r,1);}function Rn(e,t){t.parent=null;let n=e.rawTextChildren.indexOf(t);n!==-1&&e.rawTextChildren.splice(n,1);let r=e.allChildren.indexOf(t);r!==-1&&e.allChildren.splice(r,1),e.text=e.rawTextChildren.map(o=>o.text).join("")||null;}function vn(e,t,n){t.parent=e;let r=e.children.indexOf(n);r!==-1?e.children.splice(r,0,t):e.children.push(t);let o=e.allChildren.indexOf(n);o!==-1?e.allChildren.splice(o,0,t):e.allChildren.push(t);}function Tn(e,t,n){t.parent=e,e.rawTextChildren.push(t);let r=e.allChildren.indexOf(n);r!==-1?e.allChildren.splice(r,0,t):e.allChildren.push(t),e.text=e.rawTextChildren.map(o=>o.text).join("");}function dt(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 Ht(e,t={}){let n=[],r={color:e.style.color??t.color,bg:e.style.bg??t.bg,bold:e.style.bold??t.bold,dim:e.style.dim??t.dim,italic:e.style.italic??t.italic,underline:e.style.underline??t.underline};if(e.allChildren.length===0&&e.text!=null)return n.push({text:e.text,style:r}),n;for(let o of e.allChildren)o.type==="raw-text"?n.push({text:o.text,style:r}):n.push(...Ht(o,r));return n}var Vt=32,kn={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 wn(e,t)},createTextInstance(e,t,n,r){return {type:"raw-text",text:e,parent:null}},appendInitialChild(e,t){t.type==="raw-text"?At(e,t):Lt(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){t.type==="raw-text"?At(e,t):Lt(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){if(t.type==="raw-text")Tn(e,t,n);else if(n.type==="raw-text"){let r=t;r.parent=e,e.children.push(r);let o=e.allChildren.indexOf(n);o!==-1?e.allChildren.splice(o,0,r):e.allChildren.push(r);}else vn(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){t.type==="raw-text"?Rn(e,t):In(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 ze=$r(kn);ze.injectIntoDevTools({bundleType:process.env.NODE_ENV==="production"?0:1,version:"0.1.0",rendererPackageName:"glyph"});var mt=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 Pn(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 Or(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 ht(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 En(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=Kr(e,n);if(s){t.push(s.key),n=s.end;continue}}if(e[n+1]==="O"){let s=Dr(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 Dr(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 Kr(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),f=parseInt(c[2]??"0",10);i={name:Pn(f),sequence:s},ht(i,l);break}if(i={name:Or(r),sequence:s},r.includes(";")){let c=r.split(";"),l=parseInt(c[1]??"1",10);ht(i,l);}break}case "u":{let c=r.split(";"),l=parseInt(c[0]??"0",10),f=parseInt(c[1]??"1",10);i={name:Pn(l),sequence:s},ht(i,f);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&&ht(i,l);}return {key:i,end:n}}var Wr={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"},_r={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 jt(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 Nn(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=jt(e);return `\x1B[38;2;${o};${s};${i}m`}return Wr[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}=jt(e);return `\x1B[48;2;${o};${s};${i}m`}return _r[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 Bn={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]},Fn=["black","red","green","yellow","blue","magenta","cyan","white","blackBright","redBright","greenBright","yellowBright","blueBright","magentaBright","cyanBright","whiteBright"],Xe=null;function Mn(e){e.size>0&&(Xe=e);}function qr(e){if(Xe){let t=Fn.indexOf(e);if(t!==-1){let n=Xe.get(t);if(n)return n}}return Bn[e]??null}function zr(e){if(typeof e=="string"){if(e.startsWith("#")){let t=jt(e);return [t.r,t.g,t.b]}return qr(e)}if(typeof e=="number"){if(e<16){if(Xe){let s=Xe.get(e);if(s)return s}return Bn[Fn[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 gt(e){let t=zr(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 $t(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 Ln(e){return e&>(e)?"black":"white"}var Ue=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,f){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:f});}fillRect(t,n,r,o,s,i,c){for(let l=n;l<n+o;l++)for(let f=t;f<t+r;f++)this.setChar(f,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&&$t(t.fg,n.fg)&&$t(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 Xr={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 An(e){return e==="none"?null:Xr[e]}function Hn(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 f of o){let p=Pe(f);p>l&&(l=p);}return {width:l,height:o.length}}let s=Math.max(1,Math.floor(t)),i=ve(o,s,r),c=0;for(let l of i){let f=Pe(l);f>c&&(c=f);}return {width:c,height:i.length}}function ve(e,t,n){let r=[];for(let o of e){if(Pe(o)<=t){r.push(o);continue}if(n==="truncate"){r.push(Vn(o,t));continue}if(n==="ellipsis"){r.push(Jr(o,t));continue}let i=Yr(o,t);r.push(...i);}return r}function Vn(e,t){let n="",r=0;for(let o of e){let s=Pe(o);if(r+s>t)break;n+=o,r+=s;}return n}function Jr(e,t){if(t<=1)return t===1?"\u2026":"";let n=Vn(e,t-1);return Pe(n)<Pe(e)?n+"\u2026":e}function Yr(e,t){let n=[],r="",o=0,s="",i=0;for(let c=0;c<=e.length;c++){let l=e[c],f=c===e.length,p=l===" ";if(f||p){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 b=Pe(m);o+b>t&&r.length>0&&(n.push(r),r="",o=0),r+=m,o+=b;}s="",i=0;}p&&(o+1<=t?(r+=" ",o+=1):(r.length>0&&n.push(r),r=" ",o=1));}else l&&(s+=l,i+=Pe(l));}return r.length>0&&n.push(r),n.length>0?n:[""]}var jn={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"},$n={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 Qr(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:jn[r]?t.fg=jn[r]:$n[r]&&(t.bg=$n[r]);break}n++;}}function Ot(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 p=(i[1]||"0").split(";").map(m=>parseInt(m,10)||0);Qr(p,n),s=o.lastIndex;}let c=e.slice(s);return c&&(r+=c),r&&t.push({text:r,style:{...n}}),t}function Zr(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function On(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||Dn(i,s,i.style.zIndex??0,o);o.sort((i,c)=>i.zIndex-c.zIndex);for(let i of o){let c=to(i.node,t,i.clip,n);c?.cursorPosition&&(r.cursorPosition=c.cursorPosition);}return r}function Dn(e,t,n,r){if(e.hidden)return;let o=e.style.zIndex??n,s=e.style.clip?eo(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)Dn(i,s,o,r);}function eo(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 yt(e,t,n){return e>=n.x&&e<n.x+n.width&&t>=n.y&&t<n.y+n.height}function to(e,t,n,r={}){let{x:o,y:s,width:i,height:c,innerX:l,innerY:f,innerWidth:p,innerHeight:m}=e.layout,b=e.style;if(i<=0||c<=0)return;let P=dt(e).bg;if(b.bg)for(let d=s;d<s+c;d++)for(let g=o;g<o+i;g++)yt(g,d,n)&&t.setChar(g,d," ",void 0,b.bg);let h=b.border?An(b.border):null;if(h&&i>=2&&c>=2){let d=b.borderColor,g=P;Se(t,n,o,s,h.topLeft,d,g);for(let x=o+1;x<o+i-1;x++)Se(t,n,x,s,h.horizontal,d,g);Se(t,n,o+i-1,s,h.topRight,d,g),Se(t,n,o,s+c-1,h.bottomLeft,d,g);for(let x=o+1;x<o+i-1;x++)Se(t,n,x,s+c-1,h.horizontal,d,g);Se(t,n,o+i-1,s+c-1,h.bottomRight,d,g);for(let x=s+1;x<s+c-1;x++)Se(t,n,o,x,h.vertical,d,g),Se(t,n,o+i-1,x,h.vertical,d,g);}if(e.type==="text")no(e,t,n);else if(e.type==="input")return ro(e,t,n,r)}function Se(e,t,n,r,o,s,i,c,l,f,p){yt(n,r,t)&&e.setChar(n,r,o,s,i,c,l,f,p);}function Kn(e,t){if(e!==void 0)return e;if(t!==void 0)return gt(t)?"black":"white"}function no(e,t,n){let{innerX:r,innerY:o,innerWidth:s,innerHeight:i}=e.layout,c=dt(e),l=Ht(e,c);if(l.length===0)return;let f=e.style.wrap??"wrap",p=e.style.textAlign??"left",m=[],b=[];for(let d of l){let g=Ot(d.text);for(let x of g)for(let E of x.text)if(E===`
|
|
3
|
+
`)b.push(m.length);else {let M={color:x.style.fg??d.style.color,bg:x.style.bg??d.style.bg,bold:x.style.bold??d.style.bold,dim:x.style.dim??d.style.dim,italic:x.style.italic??d.style.italic,underline:x.style.underline??d.style.underline};m.push({char:E,style:M});}}let C=[],P=0;for(let d of b)C.push(m.slice(P,d)),P=d;C.push(m.slice(P));let h=[];for(let d of C){if(d.length===0){h.push([]);continue}let g=d.map(M=>M.char).join(""),x=ve([g],s,f),E=0;for(let M of x){let D=[];for(let k of M)E<d.length&&(D.push(d[E]),E++);h.push(D);}}for(let d=0;d<h.length&&d<i;d++){let g=h[d],x=g.reduce((D,k)=>D+Pe(k.char),0),E=0;p==="center"?E=Math.max(0,Math.floor((s-x)/2)):p==="right"&&(E=Math.max(0,s-x));let M=0;for(let{char:D,style:k}of g){let B=Pe(D);if(B>0){let A=Kn(k.color,k.bg);Se(t,n,r+E+M,o+d,D,A,k.bg,k.bold,k.dim,k.italic,k.underline);}M+=B;}}}function ro(e,t,n,r={}){let{cursorInfo:o,useNativeCursor:s}=r,{innerX:i,innerY:c,innerWidth:l,innerHeight:f}=e.layout;if(l<=0||f<=0)return;let p=e.props.value??e.props.defaultValue??"",m=e.props.placeholder??"",b=p||m,C=!p&&!!m,P=e.props.multiline??false,h=dt(e),d=Kn(h.color,h.bg),g=h.bg?gt(h.bg)?"blackBright":"whiteBright":"blackBright",x=C?g:d??h.color??e.style.color,E=C?g:x,M=C?true:h.dim,D=o&&o.nodeId===e.focusId,k;if(P&&!C){let B=e.style.wrap??"wrap",A=b.split(`
|
|
4
|
+
`),$=ve(A,l,B),R=0,v=0;if(D){let y=o.position,I=0,q=y,V=0;for(let K=0;K<A.length;K++){let F=A[K].length;if(y<=V+F){I=K,q=y-V;break}V+=F+1;}let z=0;for(let K=0;K<I;K++)z+=ve([A[K]],l,B).length;let N=ve([A[I]],l,B),O=0,j=0;for(let K=0;K<N.length;K++){let F=N[K];if(q<=O+F.length){j=K;break}O+=F.length;}R=z+j,v=Pe(A[I].slice(O,O+(q-O)));}let T=Math.max(0,R-f+1);for(let y=0;y<f;y++){let I=T+y;if(I>=$.length)break;let q=$[I],V=0;for(let z of q){if(V>=l)break;let N=Pe(z);N>0&&Se(t,n,i+V,c+y,z,E,h.bg,h.bold,M,h.italic,h.underline),V+=N;}}if(D){let y=R-T;if(y>=0&&y<f){let I=Math.min(v,l-1),q=i+I,V=c+y;if(yt(q,V,n)&&q<i+l)if(s)k={cursorPosition:{x:q,y:V,bg:h.bg}};else {let z=t.get(q,V),N=z?.ch&&z.ch!==" "?z.ch:"\u258C",O=h.bg??"black",j=h.color??"white";t.setChar(q,V,N,O,j,z?.bold,z?.dim,z?.italic,false);}}}}else {let B=0;for(let A of b){if(B>=l)break;let $=Pe(A);$>0&&Se(t,n,i+B,c,A,E,h.bg,h.bold,M,h.italic,h.underline),B+=$;}if(D){let A=Math.min(o.position,l-1),$=i+A;if(yt($,c,n)&&$<i+l)if(s)k={cursorPosition:{x:$,y:c,bg:h.bg}};else {let R=t.get($,c),v=R?.ch&&R.ch!==" "?R.ch:"\u258C",T=h.bg??"black",y=h.color??"white";t.setChar($,c,v,T,y,R?.bold,R?.dim,R?.italic,false);}}}return k}var oo="\x1B",Me=`${oo}[`;function so(e,t){return `${Me}${t+1};${e+1}H`}function io(e){let t=`${Me}0m`;return e.bold&&(t+=`${Me}1m`),e.dim&&(t+=`${Me}2m`),e.italic&&(t+=`${Me}3m`),e.underline&&(t+=`${Me}4m`),e.fg!=null&&(t+=Nn(e.fg)),e.bg!=null&&(t+=Gn(e.bg)),t}function Wn(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 f=t.get(l,c);if(!n){let m=e.get(l,c);if(m&&t.cellsEqual(f,m))continue}(s!==c||o!==l)&&(r+=so(l,c));let p=io(f);p!==i&&(r+=p,i=p),r+=f.ch,o=l+1,s=c;}return r.length>0&&(r+=`${Me}0m`),r}var uo={row:FlexDirection.Row,column:FlexDirection.Column},fo={"flex-start":Justify.FlexStart,center:Justify.Center,"flex-end":Justify.FlexEnd,"space-between":Justify.SpaceBetween,"space-around":Justify.SpaceAround},po={"flex-start":Align.FlexStart,center:Align.Center,"flex-end":Align.FlexEnd,stretch:Align.Stretch};function zn(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%"),t(n));}function Ee(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%")?e.setPositionPercent(t,parseFloat(n)):e.setPosition(t,n));}function mo(e,t,n){zn(e,o=>e.setWidth(o),t.width),zn(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(uo[t.flexDirection]??FlexDirection.Column),t.flexWrap&&e.setFlexWrap(t.flexWrap==="wrap"?Wrap.Wrap:Wrap.NoWrap),t.justifyContent&&e.setJustifyContent(fo[t.justifyContent]??Justify.FlexStart),t.alignItems&&e.setAlignItems(po[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&&(Ee(e,Edge.Top,t.inset),Ee(e,Edge.Right,t.inset),Ee(e,Edge.Bottom,t.inset),Ee(e,Edge.Left,t.inset)),Ee(e,Edge.Top,t.top),Ee(e,Edge.Right,t.right),Ee(e,Edge.Bottom,t.bottom),Ee(e,Edge.Left,t.left),t.clip&&e.setOverflow(Overflow.Hidden);}function Un(e){let t=Xn.Node.create();if(e.yogaNode=t,mo(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=Jn(e),Hn(i,n,r,e.style.wrap??"wrap")});else for(let n=0;n<e.children.length;n++){let r=e.children[n];r.hidden||(Un(r),t.insertChild(r.yogaNode,t.getChildCount()));}}function Jn(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=Jn(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 Yn(e,t,n){let r=e.yogaNode,o=r.getComputedLayout(),s=t+o.left,i=n+o.top,c=o.width,l=o.height,f=e.style.border&&e.style.border!=="none"?1:0,p=r.getComputedPadding(Edge.Top),m=r.getComputedPadding(Edge.Right),b=r.getComputedPadding(Edge.Bottom),C=r.getComputedPadding(Edge.Left),P=s+f+C,h=i+f+p,d=Math.max(0,c-f*2-C-m),g=Math.max(0,l-f*2-p-b),x=e.layout;(!x||x.x!==s||x.y!==i||x.width!==c||x.height!==l||x.innerX!==P||x.innerY!==h||x.innerWidth!==d||x.innerHeight!==g)&&(e.layout={x:s,y:i,width:c,height:l,innerX:P,innerY:h,innerWidth:d,innerHeight:g});for(let E of e.children)E.hidden||!E.yogaNode||Yn(E,s,i);}function Qn(e,t,n){let r=Xn.Node.create();r.setWidth(t),r.setHeight(n),r.setFlexDirection(FlexDirection.Column);for(let o of e)o.hidden||(Un(o),r.insertChild(o.yogaNode,r.getChildCount()));r.calculateLayout(t,n,Direction.LTR);for(let o of e)o.hidden||!o.yogaNode||Yn(o,0,0);r.freeRecursive(),Zn(e);}function Zn(e){for(let t of e)t.yogaNode=null,Zn(t.children);}var Z=createContext(null),U=createContext(null),de=createContext(null),Ne=createContext(null),Oe=createContext(null),bt=createContext(null);var le=null;function Qe(e=false){if(le)return le;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"?(le={name:"kitty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},le):o||t.includes("ghostty")?(le={name:"ghostty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},le):s||n==="WezTerm"?(le={name:"wezterm",supportsKittyGraphics:true,supportsIterm2Images:true,supportsSixel:true},le):n==="iTerm.app"||i==="iTerm2"?(le={name:"iterm2",supportsKittyGraphics:false,supportsIterm2Images:true,supportsSixel:false},le):c?(le={name:"konsole",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:true},le):n==="vscode"?(le={name:"vscode",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},le):(le={name:"unknown",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},le)}function Dt(){let e=Qe();return e.supportsKittyGraphics||e.supportsIterm2Images||e.supportsSixel}var ae="\x1B";function Ct(){return !!process.env.TMUX}function Kt(e){if(!Ct())return e;let t=e.replace(/\x1b/g,"\x1B\x1B");return `${ae}Ptmux;${t}${ae}\\`}function er(e){let t=Qe();return t.supportsKittyGraphics?ho(e):t.supportsIterm2Images?go(e):null}function Wt(e){if(Qe().supportsKittyGraphics){let n;return e!==void 0?n=`${ae}_Ga=d,d=i,i=${e}${ae}\\`:n=`${ae}_Ga=d,d=a${ae}\\`,Kt(n)}return null}function ho(e){let{data:t,width:n,height:r,x:o,y:s,id:i}=e,c=t.toString("base64"),l=`${ae}[${s+1};${o+1}H`,f=_t(t),p="a=T,f=100";i!==void 0&&(p+=`,i=${i}`),f&&(p+=`,s=${f.width},v=${f.height}`),p+=`,c=${n},r=${r}`;let m=4096,b=[l];Ct()&&b.unshift(`${ae}[?25l`);for(let C=0;C<c.length;C+=m){let P=c.slice(C,C+m),d=C+m>=c.length?"m=0":"m=1",g;C===0?g=`${ae}_G${p},${d},q=2;${P}${ae}\\`:g=`${ae}_G${d};${P}${ae}\\`,b.push(Kt(g));}return Ct()&&b.push(`${ae}[?25h`),b.join("")}function go(e){let{data:t,width:n,height:r,x:o,y:s}=e,i=t.toString("base64"),c=`${ae}[${s+1};${o+1}H`,l=[`width=${n}`,`height=${r}`,"preserveAspectRatio=1","inline=1"].join(";"),f=`${ae}]1337;File=${l}:${i}\x07`;return c+(Ct()?Kt(f):f)}function _t(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 yo(e,t={}){let n=t.stdout??process.stdout,r=t.stdin??process.stdin,o=t.debug??false,s=t.useNativeCursor??true,i=new mt(n,r);i.setup();let c=false;i.queryPalette().then(a=>{Mn(a),p=true,N();});let l=new Ue(i.columns,i.rows),f=new Ue(i.columns,i.rows),p=true,m=new Set,b=new Set,C=new Map,P={subscribe(a){return m.add(a),()=>m.delete(a)},subscribePriority(a){return b.add(a),()=>b.delete(a)},registerInputHandler(a,S){return C.set(a,S),()=>C.delete(a)}},h=new Map,d=new Map,g={registerImage(a){let S=h.get(a.id);(!S||S.x!==a.x||S.y!==a.y||S.width!==a.width||S.height!==a.height)&&(d.set(a.id,a),N());},unregisterImage(a){h.delete(a),d.delete(a);let S=Wt(a);S&&i.write(S),N();}};function x(){for(let a of d.values()){let S=er({data:a.data,width:a.width,height:a.height,x:a.x,y:a.y,id:a.id});S&&(i.write(S),h.set(a.id,{x:a.x,y:a.y,width:a.width,height:a.height}));}d.clear();}let E=null,M=new Map,D=[],k=new Set,B=new Set,A=[],$=new Set;function R(a){if(E!==a){E=a,N();for(let S of $)S(E);}}function v(){let a=[...D];if(A.length>0){let S=A[A.length-1];a=a.filter(w=>S.has(w));}return a=a.filter(S=>!k.has(S)),a.sort((S,w)=>{let u=M.get(S),H=M.get(w);if(!u||!H)return 0;let X=u.layout,_=H.layout;return X.y!==_.y?X.y-_.y:X.x-_.x}),a}let T={get focusedId(){return E},register(a,S,w=true){if(M.set(a,S),D.includes(a)||D.push(a),w||B.add(a),A.length>0&&A[A.length-1].add(a),E===null&&w){let u=v().filter(H=>!B.has(H));u.length>0&&R(u[0]);}return ()=>{M.delete(a),B.delete(a);let u=D.indexOf(a);if(u!==-1&&D.splice(u,1),E===a){let H=v().filter(X=>!B.has(X));R(H[0]??null);}}},requestFocus(a){R(a);},blur(){R(null);},focusNext(){let a=v();if(a.length===0)return;let w=((E?a.indexOf(E):-1)+1)%a.length;R(a[w]);},focusPrev(){let a=v();if(a.length===0)return;let w=((E?a.indexOf(E):0)-1+a.length)%a.length;R(a[w]);},setSkippable(a,S){if(S){if(k.add(a),E===a){let w=v();w.length>0&&R(w[0]);}}else k.delete(a);},trapIds:null,pushTrap(a){return A.push(a),()=>{let S=A.indexOf(a);S!==-1&&A.splice(S,1);}},onFocusChange(a){return $.add(a),()=>{$.delete(a);}},getRegisteredElements(){let a=[];for(let S of D){if(k.has(S))continue;let w=M.get(S);w&&a.push({id:S,node:w});}return a},getActiveElements(){let a=v(),S=[];for(let w of a){if(k.has(w))continue;let u=M.get(w);u&&S.push({id:w,node:u});}return S}},y=new Map,I={getLayout(a){return a.layout},subscribe(a,S){return y.has(a)||y.set(a,new Set),y.get(a).add(S),()=>{let w=y.get(a);w&&(w.delete(S),w.size===0&&y.delete(a));}}},q={registerNode(){},unregisterNode(){},scheduleRender:N,exit(a){L.exit(a);},get columns(){return i.columns},get rows(){return i.rows}},V={type:"root",children:[],onCommit(){N();}},z=false;function N(){z||(z=true,queueMicrotask(()=>{z=false,O();}));}function O(){let a=i.columns,S=i.rows;(f.width!==a||f.height!==S)&&(f.resize(a,S),l.resize(a,S),p=true),Qn(V.children,a,S),j(V.children);let w;if(E){let X=M.get(E);X?.type==="input"&&(w={nodeId:E,position:X.props.cursorPosition??X.props.value?.length??0});}let u=On(V.children,f,{cursorInfo:w,useNativeCursor:s}),H=Wn(l,f,p);if(H.length>0&&i.write(H),d.size>0&&c&&(i.hideCursor(),c=false),x(),s)if(u.cursorPosition){let X=Ln(u.cursorPosition.bg);i.setCursorColor(X),i.moveCursor(u.cursorPosition.x,u.cursorPosition.y),c||(i.showCursor(),c=true);}else i.hideCursor(),c=false;for(let X=0;X<f.cells.length;X++)l.cells[X]={...f.cells[X]};p=false;}function j(a){for(let S of a){let w=y.get(S);if(w)for(let u of w)u(S.layout);j(S.children);}}let K=i.onData(a=>{let S=En(a);for(let w of S){if(w.ctrl&&w.name==="c"){L.exit();return}if(w.ctrl&&w.name==="z"){i.suspend(),process.kill(0,"SIGSTOP");return}let u=false;for(let H of b)if(H(w)){u=true;break}if(!u&&E){let H=C.get(E);H&&(u=H(w));}if(!u&&w.name==="tab"&&!w.ctrl&&!w.alt){w.shift?T.focusPrev():T.focusNext();continue}if(!u)for(let H of m)H(w);}}),F=i.onResize(()=>{p=true,N();}),te=()=>{i.resume(),p=true,N();};process.on("SIGCONT",te);let Y=ue.createElement(Ne.Provider,{value:q},ue.createElement(Z.Provider,{value:P},ue.createElement(U.Provider,{value:T},ue.createElement(de.Provider,{value:I},ue.createElement(bt.Provider,{value:g},e))))),se=a=>{o&&console.error("Uncaught error:",a);},ne=a=>{o&&console.error("Error caught by boundary:",a);},re=a=>{o&&console.error("Recoverable error:",a);},G=ze.createContainer(V,0,null,false,null,"",se,ne,re,null);ze.updateContainer(Y,G,null,null);let L={unmount(){ze.updateContainer(null,G,null,null),K(),F(),process.off("SIGCONT",te);let a=Wt();a&&i.write(a),i.cleanup();},exit(a){L.unmount(),process.exit(a??0);}};return L}var Co=forwardRef(function({children:t,style:n,focusable:r},o){return ue.createElement("box",{style:n,focusable:r,ref:o},t)});var ko=forwardRef(function({children:t,style:n,wrap:r,focusable:o,focusedStyle:s},i){let c=useContext(U),l=useRef(null),[f,p]=useState(false);useEffect(()=>{if(!c||!o||!l.current?.focusId)return;let C=l.current.focusId;return p(c.focusedId===C),c.onFocusChange(P=>{p(P===C);})},[c,o]);let m=r?{...n,wrap:r}:n;f&&s&&(m={...m,...s});let b=C=>{l.current=C,typeof i=="function"?i(C):i&&(i.current=C);};return ue.createElement("text",{style:m,focusable:o,ref:b},t)});function tr(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 f=ve([l],n,"wrap"),p=0;for(let m of f)o.push({text:m,logicalOffset:s+p}),p+=m.length;s+=l.length+1;}let i=0;for(let l=0;l<o.length;l++){let f=o[l],p=f.text.length,m=l+1<o.length&&o[l+1].logicalOffset!==f.logicalOffset+p,b=p+(m?1:0);if(t<i+p||l===o.length-1)return {visualLine:l,visualCol:Math.min(t-i,p),totalVisualLines:o.length,lineStartOffset:i,lineLength:p};i+=b;}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 nr(e,t,n,r){if(r<=0)return Math.min(n,e.length);let o=e.split(`
|
|
6
|
+
`),s=[],i=0;for(let p of o){let m=ve([p],r,"wrap"),b=0;for(let C of m)s.push({text:C,startOffset:i+b}),b+=C.length;i+=p.length+1;}let c=Math.max(0,Math.min(t,s.length-1)),l=s[c],f=Math.min(n,l.text.length);return l.startOffset+f}function tt(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 nt(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 Eo(e){let{value:t,defaultValue:n="",onChange:r,onKeyPress:o,onBeforeChange:s,placeholder:i,style:c,focusedStyle:l,multiline:f,autoFocus:p,type:m="text"}=e,[b,C]=useState(n),[P,h]=useState(n.length),[d,g]=useState(0),[x,E]=useState(false),[M,D]=useState(false),k=useContext(Z),B=useContext(U),A=useContext(de),$=useRef(null),R=useRef(null),v=t!==void 0,T=v?t:b;useEffect(()=>{if(!A||!$.current)return;let j=A.getLayout($.current);return g(j.innerWidth),A.subscribe($.current,K=>{g(K.innerWidth);})},[A]);let y=useRef(T),I=useRef(P),q=useRef(T),V=useRef(P);useEffect(()=>{T!==q.current&&(y.current=T,q.current=T,I.current=T.length,V.current=T.length,h(T.length));},[T]),useEffect(()=>{P!==V.current&&(I.current=P,V.current=P);},[P]);let z=useRef({isControlled:v,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:f??false,innerWidth:d,type:m});z.current={isControlled:v,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:f??false,innerWidth:d,type:m},useEffect(()=>{if(!(!B||!R.current||!$.current))return B.register(R.current,$.current)},[B,M]);let N=useRef(false);useEffect(()=>{if(!M){N.current=false;return}if(p&&!N.current&&B&&R.current){N.current=true;let j=R.current,K=setTimeout(()=>{B.requestFocus(j);},0);return ()=>clearTimeout(K)}},[p,B,M]),useEffect(()=>{if(!B||!R.current)return;let j=R.current;return E(B.focusedId===j),B.onFocusChange(K=>{E(K===j);})},[B,M]),useEffect(()=>{if(!k||!R.current)return;let j=R.current,K=F=>{let{isControlled:te,onChange:Y,onKeyPress:se,onBeforeChange:ne,multiline:re}=z.current;if(se?.(F)===true)return true;let G=y.current,L=I.current;if(F.name==="escape")return false;let a=(u,H)=>{let X=u,_=H;if(ne){let Q=ne(u,G);if(Q===false)return;typeof Q=="string"&&(X=Q,_=Q.length);}y.current=X,I.current=_,q.current=X,V.current=_,te||C(X),Y?.(X),h(_);},S=u=>{I.current=u,V.current=u,h(u);};if(F.name==="return"){if(re){let u=G.slice(0,L)+`
|
|
8
|
+
`+G.slice(L);return a(u,L+1),true}return false}if(F.ctrl){if(F.name==="w"){if(L>0){let u=L;for(;u>0&&G[u-1]===" ";)u--;for(;u>0&&G[u-1]!==" "&&(!re||G[u-1]!==`
|
|
9
|
+
`);)u--;let H=G.slice(0,u)+G.slice(L);a(H,u);}return true}if(F.name==="a"){if(re){let{line:u,lines:H}=tt(G,L);S(nt(H,u,0));}else S(0);return true}if(F.name==="e"){if(re){let{line:u,lines:H}=tt(G,L);S(nt(H,u,H[u].length));}else S(G.length);return true}if(F.name==="k"){if(re){let{line:u,lines:H}=tt(G,L),X=nt(H,u,H[u].length);if(L<X){let _=G.slice(0,L)+G.slice(X);a(_,L);}}else if(L<G.length){let u=G.slice(0,L);a(u,L);}return true}return false}if(F.alt){if(F.name==="left"||F.name==="b"){let u=L;for(;u>0&&G[u-1]===" ";)u--;for(;u>0&&G[u-1]!==" "&&G[u-1]!==`
|
|
10
|
+
`;)u--;return S(u),true}if(F.name==="right"||F.name==="f"){let u=L;for(;u<G.length&&G[u]!==" "&&G[u]!==`
|
|
11
|
+
`;)u++;for(;u<G.length&&G[u]===" ";)u++;return S(u),true}if(F.name==="backspace"||F.name==="d")if(F.name==="backspace"){if(L>0){let u=L;for(;u>0&&G[u-1]===" ";)u--;for(;u>0&&G[u-1]!==" "&&G[u-1]!==`
|
|
12
|
+
`;)u--;let H=G.slice(0,u)+G.slice(L);a(H,u);}return true}else {if(L<G.length){let u=L;for(;u<G.length&&G[u]!==" "&&G[u]!==`
|
|
13
|
+
`;)u++;for(;u<G.length&&G[u]===" ";)u++;let H=G.slice(0,L)+G.slice(u);a(H,L);}return true}return false}if(F.name==="left")return S(Math.max(0,L-1)),true;if(F.name==="right")return S(Math.min(G.length,L+1)),true;if(F.name==="up"){let{innerWidth:u}=z.current,H=tr(G,L,u);return H.visualLine>0&&S(nr(G,H.visualLine-1,H.visualCol,u)),true}if(F.name==="down"){let{innerWidth:u}=z.current,H=tr(G,L,u);return H.visualLine<H.totalVisualLines-1&&S(nr(G,H.visualLine+1,H.visualCol,u)),true}if(F.name==="home"){if(re){let{line:u,lines:H}=tt(G,L);S(nt(H,u,0));}else S(0);return true}if(F.name==="end"){if(re){let{line:u,lines:H}=tt(G,L);S(nt(H,u,H[u].length));}else S(G.length);return true}if(F.name==="backspace"){if(L>0){let u=G.slice(0,L-1)+G.slice(L);a(u,L-1);}return true}if(F.name==="delete"){if(L<G.length){let u=G.slice(0,L)+G.slice(L+1);a(u,L);}return true}if(F.name.length>1)return false;let w=F.sequence;if(w.length===1&&w.charCodeAt(0)>=32){let{type:u}=z.current;if(u==="number"){let X=/[0-9]/.test(w),_=w==="."&&!G.includes("."),Q=w==="-"&&L===0&&!G.includes("-");if(!X&&!_&&!Q)return true}let H=G.slice(0,L)+w+G.slice(L);return a(H,L+1),true}return false};return k.registerInputHandler(j,K)},[k,M]);let O={...c,...x&&l?l:{}};return ue.createElement("input",{style:O,value:T,defaultValue:n,placeholder:i,onChange:r,cursorPosition:I.current,multiline:f??false,focused:x,ref:j=>{j?($.current=j,R.current=j.focusId,D(true)):($.current=null,R.current=null,D(false));}})}function zt({trap:e=false,children:t}){let n=useContext(U),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]),ue.createElement(ue.Fragment,null,t)}function Mo({size:e}){return ue.createElement("box",{style:{flexGrow:e??1}})}function lr(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 cr(e,t){return !(t.name!==e.name||e.ctrl!==!!t.ctrl||e.alt!==!!t.alt||e.shift!==!!t.shift||e.meta!==!!t.meta)}function Ao({keypress:e,onPress:t,whenFocused:n,priority:r,disabled:o}){let s=useContext(Z),i=useContext(U),c=useRef(t);c.current=t;let l=useRef(lr(e));return l.current=lr(e),useEffect(()=>{if(!(!s||o))if(r){let f=p=>!cr(l.current,p)||n&&i?.focusedId!==n?false:(c.current(),true);return s.subscribePriority(f)}else {let f=p=>{cr(l.current,p)&&(n&&i?.focusedId!==n||c.current());};return s.subscribe(f)}},[s,i,n,r,o]),null}function Vo({children:e,zIndex:t=1e3}){return ue.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:t}},e)}function $o({onPress:e,style:t,focusedStyle:n,children:r,disabled:o}){let s=useContext(U),i=useContext(Z),c=useRef(null),l=useRef(null),f=useRef(e);f.current=e;let[p,m]=useState(false),[b,C]=useState(false);useEffect(()=>{if(!(!s||!l.current||!c.current||o))return s.register(l.current,c.current)},[s,o,p]),useEffect(()=>{if(!s||!l.current)return;let h=l.current;return C(s.focusedId===h),s.onFocusChange(d=>{C(d===h);})},[s,p]),useEffect(()=>{if(!i||!l.current||o)return;let h=l.current,d=g=>s?.focusedId!==h?false:g.name==="return"||g.name===" "||g.sequence===" "?(f.current?.(),true):false;return i.registerInputHandler(h,d)},[i,s,o,p]);let P={...t,...b&&n?n:{}};return ue.createElement("box",{style:P,focusable:!o,ref:h=>{h?(c.current=h,l.current=h.focusId,m(true)):(c.current=null,l.current=null,m(false));}},r)}var Wo={x:0,y:0,width:0,height:0,innerX:0,innerY:0,innerWidth:0,innerHeight:0};function Be(e){let t=useContext(de),[n,r]=useState(Wo);return useEffect(()=>{if(!(!t||!e?.current))return r(t.getLayout(e.current)),t.subscribe(e.current,r)},[t,e]),n}function rt(e,t=[]){let n=useContext(Z);useEffect(()=>{if(n)return n.subscribe(e)},[n,...t]);}function zo({children:e,style:t,scrollOffset:n,onScroll:r,defaultScrollOffset:o=0,scrollStep:s=1,disableKeyboard:i,scrollToFocus:c=true,showScrollbar:l=true,focusable:f=true,focusedStyle:p,totalLines:m,overscan:b=2,virtualize:C=false,estimatedItemHeight:P=1}){let h=n!==void 0,[d,g]=useState(o),x=h?n:d,E=typeof e=="function",M=useMemo(()=>E?[]:ue.Children.toArray(e),[e,E]),D=m!==void 0&&E,k=C&&!E&&M.length>0,B=useRef(null),A=useRef(null),$=Be(B),R=Be(A),v=useRef(new Map),T=useRef(new Map),y=useContext(U),I=useContext(de),q=useRef(null);f&&!q.current&&(q.current=`scrollview-${Math.random().toString(36).slice(2,9)}`);let V=f?q.current:null;useEffect(()=>{if(!(!f||!V||!y||!B.current))return y.register(V,B.current)},[f,V,y]);let z=f&&V&&y?.focusedId===V,N=$.innerHeight,O=useCallback(()=>{if(!k)return 0;let W=0;for(let J=0;J<M.length;J++)W+=v.current.get(J)??P;return W},[k,M.length,P]),j=D?m:k?O():R.height,K=Math.max(0,j-N),F=Math.max(0,Math.min(x,K)),te=useMemo(()=>({getBounds:()=>{let W=$.y;return {visibleTop:W,visibleBottom:W+N,viewportHeight:N,scrollOffset:F}}}),[$.y,N,F]),Y=useCallback(W=>{let J=Math.max(0,Math.min(W,K));h?r?.(J):g(J);},[h,r,K]);useEffect(()=>{x>K&&K>=0&&Y(K);},[x,K,Y]),useEffect(()=>!c||!y||!I||!A.current?void 0:y.onFocusChange(J=>{if(!J||!A.current)return;let ee=Mt=>{if(Mt.focusId===J)return Mt;for(let Vr of Mt.children){let Cn=ee(Vr);if(Cn)return Cn}return null},pe=ee(A.current);if(!pe)return;let ie=I.getLayout(pe),Fe=A.current.layout?.y??0,Ft=ie.y-Fe,bn=Ft+ie.height,Ar=x,Hr=x+N;Ft<Ar?Y(Ft):bn>Hr&&Y(bn-N);}),[c,y,I,x,N,Y]);let se=useCallback(()=>{if(!y)return false;let W=y.focusedId;if(!W)return false;if(f&&V&&W===V)return true;if(!A.current)return false;let J=ee=>{if(ee.focusId===W)return true;for(let pe of ee.children)if(J(pe))return true;return false};return J(A.current)},[y,f,V]);rt(W=>{if(i||!se())return;let J=Math.max(1,Math.floor(N/2)),ee=Math.max(1,N);switch(W.name){case "pageup":Y(x-ee);break;case "pagedown":Y(x+ee);break;default:W.ctrl&&(W.name==="d"?Y(x+J):W.name==="u"?Y(x-J):W.name==="f"?Y(x+ee):W.name==="b"&&Y(x-ee));break}},[x,s,N,K,i,Y,se]);let{padding:ne,paddingX:re,paddingY:G,paddingTop:L,paddingRight:a,paddingBottom:S,paddingLeft:w,...u}=t??{},X=u.border!=null&&u.border!=="none"?2:0,_=j>0?j+X:void 0,Q={...u,...z?p:{},clip:true,...u.height===void 0&&_!==void 0?{height:_,flexShrink:u.flexShrink??1,minHeight:u.minHeight??0}:{}},ce=useMemo(()=>{let W=Math.max(0,F-b),J=Math.min(m??j,F+N+b);return {start:W,end:J,scrollOffset:F,viewportHeight:N}},[F,N,b,m,j]),fe=useCallback(()=>{if(!k)return {startIndex:0,endIndex:0,startOffset:0};let W=0,J=0,ee=0;for(let ie=0;ie<M.length;ie++){let Fe=v.current.get(ie)??P;if(W+Fe>F-b){J=ie,ee=W;break}W+=Fe,J=ie+1,ee=W;}let pe=J;for(let ie=J;ie<M.length;ie++){let Fe=v.current.get(ie)??P;if(pe=ie+1,W+=Fe,W>=F+N+b)break}return {startIndex:J,endIndex:pe,startOffset:ee}},[k,M.length,F,N,b,P])(),he={position:"absolute",top:D?ce.start-F:k?fe.startOffset-F:-F,left:0,right:0,flexDirection:"column",...ne!==void 0&&{padding:ne},...re!==void 0&&{paddingX:re},...G!==void 0&&{paddingY:G},...L!==void 0&&{paddingTop:L},...a!==void 0&&{paddingRight:a},...S!==void 0&&{paddingBottom:S},...w!==void 0&&{paddingLeft:w}},ye=D?e(ce):k?M.slice(fe.startIndex,fe.endIndex).map((W,J)=>{let ee=fe.startIndex+J;return ue.createElement("box",{key:ee,ref:pe=>{pe?T.current.set(ee,pe):T.current.delete(ee);}},W)}):e,[,Te]=useState(0);useEffect(()=>{if(!k||!I)return;let W=false;for(let[J,ee]of T.current){let ie=I.getLayout(ee).height||P;v.current.get(J)!==ie&&(v.current.set(J,ie),W=true);}W&&Te(J=>J+1);});let Ve=j>N&&N>0,we=l&&Ve,ke=Math.max(1,Math.floor(N/j*N)),Ie=j-N,Ce=Ie>0?Math.floor(F/Ie*(N-ke)):0,xe=[];if(we)for(let W=0;W<N;W++)W>=Ce&&W<Ce+ke?xe.push("\u2588"):xe.push("\u2591");let pt={position:"absolute",top:0,right:0,width:1,height:N,flexDirection:"column"};return ue.createElement(Oe.Provider,{value:te},ue.createElement("box",{style:Q,ref:W=>{B.current=W??null;},...f?{focusable:true,focusId:V}:{}},ue.createElement("box",{style:{...he,paddingRight:we?(he.paddingRight??0)+1:he.paddingRight},ref:W=>{A.current=W??null;}},ye),we&&ue.createElement("box",{style:pt},ue.createElement("text",{style:{color:"blackBright"}},xe.join(`
|
|
14
|
+
`)))))}function tn({count:e,renderItem:t,selectedIndex:n,onSelectionChange:r,onSelect:o,defaultSelectedIndex:s=0,disabledIndices:i,style:c,focusable:l=true}){let f=n!==void 0,[p,m]=useState(s),b=f?n:p,C=useContext(U),P=useContext(Z),h=useRef(null),d=useRef(null),g=useRef(o);g.current=o;let[x,E]=useState(false),[M,D]=useState(false),k=useRef(null),B=useCallback(v=>{let T=Math.max(0,Math.min(v,e-1));f?r?.(T):m(T);},[f,r,e]),A=useCallback((v,T)=>{if(!i||i.size===0)return Math.max(0,Math.min(v+T,e-1));let y=v+T;for(;y>=0&&y<e&&i.has(y);)y+=T;return y<0||y>=e?v:y},[i,e]);useEffect(()=>{if(!(!C||!d.current||!h.current||!l))return C.register(d.current,h.current)},[C,l,x]),useEffect(()=>{if(!C||!d.current)return;let v=d.current;return D(C.focusedId===v),C.onFocusChange(T=>{D(T===v);})},[C,x]);let $=useCallback(v=>{let T=v?e-1:0,y=v?-1:1,I=T;for(;I>=0&&I<e&&i?.has(I);)I+=y;return I>=0&&I<e?I:v?e-1:0},[i,e]);useEffect(()=>{if(!P||!d.current||!l)return;let v=d.current,T=y=>C?.focusedId!==v?false:y.name==="g"&&!y.ctrl&&!y.alt?k.current==="g"?(B($(false)),k.current=null,true):(k.current="g",true):y.name==="G"||y.name==="g"&&y.shift?(k.current=null,B($(true)),true):(k.current=null,y.name==="up"||y.name==="k"?(B(A(b,-1)),true):y.name==="down"||y.name==="j"?(B(A(b,1)),true):y.name==="return"?(i?.has(b)||g.current?.(b),true):false);return P.registerInputHandler(v,T)},[P,C,l,b,B,A,$,i,x]);let R=[];for(let v=0;v<e;v++)R.push(ue.createElement(ue.Fragment,{key:v},t({index:v,selected:v===b,focused:M})));return ue.createElement("box",{style:{flexDirection:"column",...c},focusable:l,ref:v=>{v?(h.current=v,d.current=v.focusId,E(true)):(h.current=null,d.current=null,E(false));}},...R)}function Xo({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 p=0;p<e.length;p++)e[p].disabled&&l.add(p);let f=p=>{let m=e[p];m&&!m.disabled&&r?.(m.value,p);};return ue.createElement(tn,{count:e.length,selectedIndex:t,onSelectionChange:n,onSelect:f,defaultSelectedIndex:o,disabledIndices:l.size>0?l:void 0,style:s,focusable:c,renderItem:({index:p,selected:m,focused:b})=>{let C=e[p],P=C.disabled,h=m&&b,d=m?">":" ";return ue.createElement("box",{style:{flexDirection:"row",...h?{bg:i}:{}}},ue.createElement("text",{style:h?{bold:true,color:"black"}:P?{dim:true}:{}},`${d} ${C.label}`))}})}function Qo({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),p=Be(l).innerWidth,[m,b]=useState(0);useEffect(()=>{if(!t)return;let g=setInterval(()=>{b(x=>(x+1)%Math.max(1,p+6));},100);return ()=>clearInterval(g)},[t,p]);let C=Math.max(0,Math.min(1,e??0)),P=o?` ${Math.round(C*100)}%`:"",h="";if(p>0)if(t&&e===void 0){let g=Math.max(1,Math.min(3,Math.floor(p/4))),x=[];for(let E=0;E<p;E++)E>=m-g&&E<m?x.push(i):x.push(c);h=x.join("");}else {let g=Math.round(C*p);h=i.repeat(g)+c.repeat(p-g);}let d=[];return r&&d.push(ue.createElement("text",{key:"label",style:{bold:true}},r+" ")),d.push(ue.createElement("box",{key:"track",style:{flexGrow:1,flexShrink:1},ref:g=>{l.current=g??null;}},ue.createElement("text",{key:"bar",style:{}},h))),o&&d.push(ue.createElement("text",{key:"pct",style:{bold:true}},P)),ue.createElement("box",{style:{flexDirection:"row",width:n,...s}},...d)}var ts=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function ns({frames:e=ts,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=[ue.createElement("text",{key:"frame",style:r},e[o])];return n&&i.push(ue.createElement("text",{key:"label",style:{}}," "+n)),ue.createElement("box",{style:{flexDirection:"row"}},...i)}var hr=createContext(null),cs=0;function as(){let e=useContext(hr);if(!e)throw new Error("useToast must be used within a <ToastHost>");return e.push}var us={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 fs({position:e="bottom-right",maxVisible:t=5,children:n}){let[r,o]=useState([]),s=useRef(new Map),i=useCallback(C=>{let P=`toast-${cs++}`,h={id:P,durationMs:3e3,variant:"info",...C};if(o(d=>[...d,h]),h.durationMs&&h.durationMs>0){let d=setTimeout(()=>{s.current.delete(P),o(g=>g.filter(x=>x.id!==P));},h.durationMs);s.current.set(P,d);}},[]);useEffect(()=>()=>{for(let C of s.current.values())clearTimeout(C);s.current.clear();},[]);let c=useRef({push:i});c.current.push=i;let l=e.startsWith("top"),f=e.endsWith("right"),p={position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:900,flexDirection:"column",justifyContent:l?"flex-start":"flex-end",alignItems:f?"flex-end":"flex-start",padding:1},b=r.slice(-t).map(C=>{let P=C.variant??"info",h=us[P],d=[];return C.title&&d.push(ue.createElement("text",{key:"title",style:{bold:true,color:h.title}},C.title)),d.push(ue.createElement("text",{key:"msg",style:{color:h.text}},C.message)),ue.createElement("box",{key:C.id,style:{bg:h.bg,paddingX:1,flexDirection:"column",minWidth:20,maxWidth:50}},...d)});return ue.createElement(hr.Provider,{value:c.current},n,b.length>0?ue.createElement("box",{style:p},...b):null)}function ds({items:e,value:t,onChange:n,placeholder:r="Select...",style:o,focusedStyle:s,dropdownStyle:i,highlightColor:c="cyan",maxVisible:l=8,searchable:f=true,disabled:p}){let m=useContext(U),b=useContext(Z),C=useContext(Ne),P=useContext(Oe),h=useRef(null),d=useRef(null),g=useRef(n);g.current=n;let[x,E]=useState(false),[M,D]=useState(false),[k,B]=useState(false),[A,$]=useState(0),[R,v]=useState(""),[T,y]=useState(0),I=Be(h),q=C?.rows??24,V=P?.getBounds(),N=e.find(a=>a.value===t)?.label??"",O=useMemo(()=>{if(!R)return e;let a=R.toLowerCase();return e.filter(S=>S.label.toLowerCase().includes(a))},[e,R]),j=Math.min(l,O.length),K=O.slice(T,T+j);useEffect(()=>{$(0),y(0);},[R]),useEffect(()=>{!M&&k&&(B(false),v(""));},[M,k]),useEffect(()=>{if(!(!m||!d.current||!h.current))return m.register(d.current,h.current)},[m,x]),useEffect(()=>{!m||!d.current||m.setSkippable(d.current,!!p);},[m,p,x]),useEffect(()=>{if(!m||!d.current)return;let a=d.current;return D(m.focusedId===a),m.onFocusChange(S=>{D(S===a);})},[m,x]);let F=useCallback((a,S)=>{let w=a+S;for(;w>=0&&w<O.length;){if(!O[w].disabled)return w;w+=S;}return a},[O]),te=useCallback(a=>{a<T?y(a):a>=T+j&&y(a-j+1);},[T,j]);useEffect(()=>{if(!b||!d.current||p)return;let a=d.current,S=w=>{if(m?.focusedId!==a)return false;if(!k){if(w.name==="return"||w.name===" "||w.sequence===" "||w.name==="down"){B(true),v("");let u=O.findIndex(X=>X.value===t),H=u>=0?u:0;return $(H),y(Math.max(0,H-Math.floor(l/2))),true}return false}if(w.name==="tab")return B(false),v(""),false;if(w.name==="escape")return B(false),v(""),true;if(w.name==="return"){let u=O[A];return u&&!u.disabled&&(g.current?.(u.value),B(false),v("")),true}if(w.name==="up"){let u=F(A,-1);return $(u),te(u),true}if(w.name==="down"){let u=F(A,1);return $(u),te(u),true}if(w.name==="backspace")return f&&R.length>0&&v(u=>u.slice(0,-1)),true;if(w.name==="home"){let u=F(-1,1);return $(u),te(u),true}if(w.name==="end"){let u=F(O.length,-1);return $(u),te(u),true}if(f&&w.sequence&&w.sequence.length===1&&!w.ctrl&&!w.alt){let u=w.sequence;if(u>=" "&&u<="~")return v(H=>H+u),true}return true};return b.registerInputHandler(a,S)},[b,m,p,k,A,O,t,l,f,R,F,te,x]);let se={flexDirection:"row",width:"100%",...!o?.bg&&o?.border===void 0?{border:"single"}:{},...o,...M&&s?s:{}},ne=N?o?.color??void 0:"blackBright",re=[ue.createElement("text",{key:"label",style:{flexGrow:1,flexShrink:1,color:ne,wrap:"ellipsis",...N?{}:{dim:true}}},N||r),ue.createElement("text",{key:"arrow",style:{flexShrink:0,color:M?c:"blackBright"}},k?" \u25B2":" \u25BC")],G=null;if(k){let a=[];f&&R&&a.push(ue.createElement("box",{key:"search",style:{paddingX:1}},ue.createElement("text",{style:{color:"blackBright",dim:true}},`/${R}`))),O.length===0&&a.push(ue.createElement("box",{key:"empty",style:{paddingX:1}},ue.createElement("text",{style:{dim:true,color:"blackBright"}},"No matches"))),T>0&&a.push(ue.createElement("box",{key:"scroll-up",style:{justifyContent:"center",alignItems:"center"}},ue.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25B2"))),K.forEach((Te,Ve)=>{let ke=T+Ve===A,Ie=Te.disabled,Ce={paddingX:1,...ke&&!Ie?{bg:c}:{}},xe={...ke&&!Ie?{color:"black",bold:true}:{},...Ie?{dim:true,color:"blackBright"}:{}};a.push(ue.createElement("box",{key:`item-${Te.value}`,style:Ce},ue.createElement("text",{style:xe},Te.label)));}),T+j<O.length&&a.push(ue.createElement("box",{key:"scroll-down",style:{justifyContent:"center",alignItems:"center"}},ue.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25BC")));let S=T>0,w=T+j<O.length,u=f&&R,H=O.length===0,X=!i?.bg&&i?.border===void 0,Q=j+(X?2:0);S&&(Q+=1),w&&(Q+=1),u&&(Q+=1),H&&(Q+=1);let ce=I.y+I.height,be,fe;V?(be=V.visibleBottom-ce,fe=I.y-V.visibleTop):(be=q-ce,fe=I.y);let ye=be<Q&&fe>=Q?-Q:I.height||1;G=ue.createElement("box",{style:{position:"absolute",top:ye,left:0,right:0,zIndex:9999,...X?{border:"single"}:{},bg:"black",flexDirection:"column",...i}},...a);}let L={flexDirection:"column",width:se.width??"100%",minWidth:se.minWidth,maxWidth:se.maxWidth,flexGrow:se.flexGrow,flexShrink:se.flexShrink??1};return ue.createElement("box",{style:L},ue.createElement("box",{style:se,focusable:true,ref:a=>{a?(h.current=a,d.current=a.focusId,E(true)):(h.current=null,d.current=null,E(false));}},...re),G)}function ms({checked:e,onChange:t,label:n,style:r,focusedStyle:o,disabled:s,checkedChar:i="\u2713",uncheckedChar:c=" "}){let l=useContext(U),f=useContext(Z),p=useRef(null),m=useRef(null),b=useRef(t);b.current=t;let C=useRef(e);C.current=e;let[P,h]=useState(false),[d,g]=useState(false);useEffect(()=>{if(!(!l||!m.current||!p.current||s))return l.register(m.current,p.current)},[l,s,P]),useEffect(()=>{if(!l||!m.current)return;let k=m.current;return g(l.focusedId===k),l.onFocusChange(B=>{g(B===k);})},[l,P]),useEffect(()=>{if(!f||!m.current||s)return;let k=m.current,B=A=>l?.focusedId!==k?false:A.name==="return"||A.name===" "||A.sequence===" "?(b.current(!C.current),true):false;return f.registerInputHandler(k,B)},[f,l,s,P]);let x={flexDirection:"row",gap:1,...r,...d&&o?o:{}},E=e?i:c,M={color:s?"blackBright":d?"white":r?.color},D={color:s?"blackBright":r?.color};return ue.createElement("box",{style:x,focusable:!s,ref:k=>{k?(p.current=k,m.current=k.focusId,h(true)):(p.current=null,m.current=null,h(false));}},ue.createElement("text",{key:"box",style:M},`[${E}]`),n?ue.createElement("text",{key:"label",style:D},n):null)}function gs({items:e,value:t,onChange:n,style:r,itemStyle:o,focusedItemStyle:s,selectedItemStyle:i,disabled:c,direction:l="column",gap:f=0,selectedChar:p="\u25CF",unselectedChar:m="\u25CB"}){let b=useContext(U),C=useContext(Z),P=useRef(null),h=useRef(null),d=useRef(n);d.current=n;let[g,x]=useState(false),[E,M]=useState(false),[D,k]=useState(()=>{let R=e.findIndex(v=>v.value===t);return R>=0?R:e.findIndex(v=>!v.disabled)}),B=useCallback((R,v)=>{let T=R;for(let y=0;y<e.length;y++)if(T=(T+v+e.length)%e.length,!e[T]?.disabled)return T;return R},[e]);useEffect(()=>{if(!(!b||!h.current||!P.current||c))return b.register(h.current,P.current)},[b,c,g]),useEffect(()=>{if(!b||!h.current)return;let R=h.current;return M(b.focusedId===R),b.onFocusChange(v=>{M(v===R);})},[b,g]),useEffect(()=>{if(!C||!h.current||c)return;let R=h.current,v=T=>{if(b?.focusedId!==R)return false;if(T.name==="up"||T.name==="left"||T.name==="k"||T.name==="tab"&&T.shift)return k(y=>B(y,-1)),true;if(T.name==="down"||T.name==="right"||T.name==="j"||T.name==="tab"&&!T.shift)return k(y=>B(y,1)),true;if(T.name==="return"||T.name===" "||T.sequence===" "){let y=e[D];return y&&!y.disabled&&d.current(y.value),true}return false};return C.registerInputHandler(R,v)},[C,b,c,e,D,B,g]),useEffect(()=>{let R=e.findIndex(v=>v.value===t);R>=0&&k(R);},[t,e]);let A={flexDirection:l,gap:f,...r},$=e.map((R,v)=>{let T=R.value===t,y=v===D,I=c||R.disabled,q=T?p:m,V={flexDirection:"row",gap:1,...o};T&&i&&(V={...V,...i}),E&&y&&s&&(V={...V,...s});let z=I?"blackBright":E&&y?s?.color??"white":T?i?.color??o?.color:o?.color;return ue.createElement("box",{key:v,style:V},ue.createElement("text",{key:"radio",style:{color:z}},`(${q})`),ue.createElement("text",{key:"label",style:{color:z}},R.label))});return ue.createElement("box",{style:A,focusable:!c,ref:R=>{R?(P.current=R,h.current=R.focusId,x(true)):(P.current=null,h.current=null,x(false));}},...$)}var wr=createContext(null);function xs(){let e=useContext(wr);if(!e)throw new Error("useDialog must be used within a DialogHost");return e}function bs({children:e}){let[t,n]=useState([]),r=useRef(0),o=useCallback((f,p)=>new Promise(m=>{let b=++r.current;n(C=>[...C,{id:b,type:"alert",content:f,okText:p?.okText??"OK",cancelText:"",style:p?.style,buttonStyle:p?.buttonStyle,okButtonStyle:p?.okButtonStyle,focusedButtonStyle:p?.focusedButtonStyle,backdropStyle:p?.backdropStyle,resolve:()=>m()}]);}),[]),s=useCallback((f,p)=>new Promise(m=>{let b=++r.current;n(C=>[...C,{id:b,type:"confirm",content:f,okText:p?.okText??"OK",cancelText:p?.cancelText??"Cancel",style:p?.style,buttonStyle:p?.buttonStyle,okButtonStyle:p?.okButtonStyle,cancelButtonStyle:p?.cancelButtonStyle,focusedButtonStyle:p?.focusedButtonStyle,backdropStyle:p?.backdropStyle,resolve:m}]);}),[]),i=useCallback((f,p)=>{n(m=>{let b=m.find(C=>C.id===f);return b&&b.resolve(p),m.filter(C=>C.id!==f)});},[]),c={alert:o,confirm:s},l=t[t.length-1];return ue.createElement(wr.Provider,{value:c},e,l&&ue.createElement(Cs,{key:l.id,dialog:l,onDismiss:i}))}function Cs({dialog:e,onDismiss:t}){let n=useContext(U),r=useRef(null),o=useRef(null),s=useRef(null),i=useRef(null),[c,l]=useState("ok"),[f,p]=useState(0);useEffect(()=>{if(!n||f===0)return;let g=[];return r.current&&s.current&&g.push(n.register(s.current,r.current)),o.current&&i.current&&g.push(n.register(i.current,o.current)),s.current&&n.requestFocus(s.current),()=>g.forEach(x=>x())},[n,f]),useEffect(()=>{if(n)return n.onFocusChange(g=>{g===s.current?l("ok"):g===i.current&&l("cancel");})},[n]),rt(g=>{if(g.name==="return"||g.name==="space"){e.type==="alert"?t(e.id,true):t(e.id,c==="ok");return}if(g.name==="escape"){t(e.id,false);return}e.type==="confirm"&&n&&(g.name==="left"||g.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",b=m?e.content.length:0,P={minWidth:Math.max(20,m?Math.min(b+6,50):30),maxWidth:50,bg:"black",border:"round",borderColor:"white",padding:1,flexDirection:"column",gap:1,...e.style},h=(g,x)=>{let E={paddingX:2,bg:"blackBright",color:"white"},M={bg:"white",color:"black",bold:true},D=g==="ok"?e.okButtonStyle:e.cancelButtonStyle;return {...E,...e.buttonStyle,...D,...x?{...M,...e.focusedButtonStyle}:{}}},d={position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:999,...e.backdropStyle};return ue.createElement(zt,{trap:true},ue.createElement("box",{style:d}),ue.createElement("box",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,justifyContent:"center",alignItems:"center",zIndex:1e3}},ue.createElement("box",{style:P},ue.createElement("box",{style:{flexDirection:"column"}},typeof e.content=="string"?ue.createElement("text",null,e.content):e.content),ue.createElement("box",{style:{flexDirection:"row",justifyContent:"flex-end",gap:1}},e.type==="confirm"&&ue.createElement("box",{style:h("cancel",c==="cancel"),focusable:true,ref:g=>{g&&g.focusId&&!i.current&&(o.current=g,i.current=g.focusId,p(x=>x+1));}},ue.createElement("text",null,e.cancelText)),ue.createElement("box",{style:h("ok",c==="ok"),focusable:true,ref:g=>{g&&g.focusId&&!s.current&&(r.current=g,s.current=g.focusId,p(x=>x+1));}},ue.createElement("text",null,e.okText))))))}function Is(e,t){let n=[],r=e.parent;for(;r;)r.style.clip&&n.push({x:r.layout.innerX,y:r.layout.innerY,width:r.layout.innerWidth,height:r.layout.innerHeight}),r=r.parent;let o=t;for(let s of n)o=Rs(o,s);return o}function Rs(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 vs(e,t){if(t.width<=0||t.height<=0)return false;let n=e.x+e.width,r=e.y+e.height;return e.x<t.x+t.width&&n>t.x&&e.y<t.y+t.height&&r>t.y}function Ts(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 ks({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?(...y)=>console.error("[JumpNav]",...y):()=>{},[f,p]=useState(false),[m,b]=useState(""),[C,P]=useState([]),h=useContext(Z),d=useContext(U),g=useContext(de),x=useContext(Ne);useEffect(()=>{l("Mounted, inputCtx:",!!h,"focusCtx:",!!d,"enabled:",i);},[]);let M=useCallback(y=>{let I=y.toLowerCase().split("+");return {ctrl:I.includes("ctrl"),alt:I.includes("alt"),shift:I.includes("shift"),meta:I.includes("meta"),name:I[I.length-1]??""}},[])(t),D=useCallback(()=>{if(!d?.getActiveElements){l("refreshElements: no getActiveElements");return}let y=d.getActiveElements();l("getActiveElements returned",y.length,"elements");let I=x?.columns??80,q=x?.rows??24,V={x:0,y:0,width:I,height:q},z=y.map(({id:N,node:O})=>({id:N,node:O,layout:g?.getLayout(O)??O.layout,clipRegion:Is(O,V)}));z.sort((N,O)=>N.layout.y!==O.layout.y?N.layout.y-O.layout.y:N.layout.x-O.layout.x),P(z);},[d,g,x,l]),k=useRef(false);useEffect(()=>{f&&!k.current&&(l("Activated! Refreshing elements..."),D()),k.current=f;},[f,D,l]);let B=x?.columns??80,A=x?.rows??24,$=C.filter(y=>y.layout.width>0&&y.layout.height>0&&vs(y.layout,y.clipRegion)),R=Ts($.length,s),v=useMemo(()=>{let y=new Map;return $.forEach((I,q)=>{R[q]&&y.set(R[q],I.id);}),y},[$,R]);useEffect(()=>{if(!h||!i){l("Not subscribing - inputCtx:",!!h,"enabled:",i);return}l("Subscribing to priority input, activation key:",t);let y=I=>{let q=I.name===M.name,V=!!I.ctrl===M.ctrl,z=!!I.alt===M.alt,N=!!I.shift===M.shift,O=!!I.meta===M.meta;if(!f&&q&&V&&z&&N&&O)return l("Activation key matched! Activating..."),p(true),b(""),true;if(f){if(I.name==="escape")return l("Escape pressed, deactivating"),p(false),b(""),true;if(I.name==="backspace")return b(""),true;if(I.sequence&&I.sequence.length===1&&/[a-z]/i.test(I.sequence)){let j=m+I.sequence.toLowerCase();l("Buffer:",j);let K=v.get(j);return K?(l("Jumping to",K),d?.requestFocus(K),p(false),b(""),true):[...v.keys()].some(te=>te.startsWith(j))?(b(j),true):(b(""),true)}return true}return false};return h.subscribePriority(y)},[h,i,f,M,m,v,d,t,l]);let T=f?ue.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:99998}},...$.map((y,I)=>{let q=R[I];if(!q)return null;let{x:V,y:z,width:N}=y.layout,O=y.clipRegion,j=q.length+2,K=Math.max(O.y,Math.min(z,O.y+O.height-1,A-1)),F=V-j,te=V+N,Y;F>=O.x&&F>=0?Y=F:te+j<=O.x+O.width&&te+j<=B?Y=te:Y=Math.max(O.x,Math.min(V,B-j)),Y=Math.max(0,Math.min(Y,B-j));let se=q.startsWith(m)&&m.length>0;return ue.createElement("box",{key:y.id,style:{position:"absolute",top:K,left:Y,bg:se?"cyan":r,color:o,paddingX:1,zIndex:99999,...n}},ue.createElement("text",{style:{bold:true,color:o}},q))}),ue.createElement("box",{style:{position:"absolute",bottom:0,left:0,right:0,bg:"blackBright",paddingX:1,zIndex:99999}},ue.createElement("text",{style:{color:"white"}},m?`Jump: ${m}_`:"Press a key to jump \u2022 ESC to cancel"))):null;return ue.createElement(ue.Fragment,null,e,T)}var We=join(tmpdir(),"glyph-image-cache");function Nt(e){return e.startsWith("http://")||e.startsWith("https://")}function Gs(e,t){let n=createHash("md5").update(e).digest("hex"),r=t?Fs(t):Bs(e)||".png";return join(We,`${n}${r}`)}function Bs(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 Fs(e){switch(e){case "png":return ".png";case "jpeg":return ".jpeg";case "gif":return ".gif";case "webp":return ".webp";default:return ".png"}}function yn(e){if(Nt(e))try{let t=new URL(e),n=t.pathname;return basename(n)||t.hostname}catch{return "remote-image"}return basename(e)}function Tr(){existsSync(We)||mkdirSync(We,{recursive:true});}async function kr(e){let t=yn(e);return Nt(e)?Ls(e,t):Ms(e,t)}async function Ms(e,t){if(!existsSync(e))throw new Error(`Image not found: ${e}`);return {data:readFileSync(e),name:t,localPath:e,isRemote:false}}async function Ls(e,t){Tr();let n=createHash("md5").update(e).digest("hex"),r=[".png",".jpeg",".gif",".webp"];for(let f of r){let p=join(We,`${n}${f}`);if(existsSync(p))return {data:readFileSync(p),name:t,localPath:p,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(!As(i))throw new Error(`Invalid image data from: ${e}`);let c=Gt(i),l=Gs(e,c);return writeFileSync(l,i),{data:i,name:t,localPath:l,isRemote:true}}function As(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 Pr(e,t){let n=Gt(e);if(n==="png")return e;Tr();let r=createHash("md5").update(e).digest("hex"),o=join(We,`${r}.${n}`),s=join(We,`${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 Vs(){let e=platform();return e==="darwin"?"quicklook":e==="linux"||e==="win32"?"open":"none"}async function xn(e){switch(Vs()){case "quicklook":return js(e);case "open":return Os(e);case "none":throw new Error("No preview method available on this platform")}}function js(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(()=>{$s();},50),r.on("close",o=>{t();});})}function $s(){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
|
|
18
|
+
'`,()=>{});}function Os(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 Ds({src:e,width:t,height:n,unloadTrigger:r,style:o,focusedStyle:s,placeholderStyle:i,focusable:c=true,disabled:l=false,inline:f=true,placeholder:p,onStateChange:m,onError:b,autoLoad:C=false,autoSize:P=false,maxWidth:h,maxHeight:d}){let g=useContext(U),x=useContext(Z),E=useContext(de),M=useContext(bt),D=useContext(Oe),k=useRef(null),B=useRef(null),A=useRef(Math.floor(Math.random()*1e6)),$=useRef(null),[R,v]=useState(false),[T,y]=useState(false),[I,q]=useState("placeholder"),[V,z]=useState(null),[N,O]=useState(null),[j,K]=useState(null),F=useRef(null),te=p||yn(e),Y=Nt(e),se=useRef(r);useEffect(()=>{r!==void 0&&r!==se.current&&I==="loaded"&&(F.current=null,K(null),q("placeholder")),se.current=r;},[r,I]);let ne=useCallback(_=>{q(_),m?.(_);},[m]);useEffect(()=>{if(!(!g||!B.current||!k.current||!c))return g.register(B.current,k.current,false)},[g,c,R]),useEffect(()=>{!g||!B.current||(g.setSkippable(B.current,!!l),l&&g.focusedId===B.current&&g.blur());},[g,l]),useEffect(()=>{if(!g||!B.current)return;let _=B.current;return y(g.focusedId===_),g.onFocusChange(Q=>{y(Q===_);})},[g,R]),useEffect(()=>{if(!(!E||!k.current))return O(E.getLayout(k.current)),E.subscribe(k.current,O)},[E,R]);let re=D?.getBounds().scrollOffset??0;useEffect(()=>{if(D){if($.current===null){$.current=re;return}if(I!=="loaded"){$.current=re;return}re!==$.current&&($.current=re,F.current=null,K(null),q("placeholder"));}},[D,re,I]),useEffect(()=>{if(!M||I!=="loaded"||!F.current||!N)return;let{data:_,cellWidth:Q,cellHeight:ce}=F.current,be=A.current,fe=setTimeout(()=>{M.registerImage({id:be,data:_,x:N.innerX,y:N.innerY,width:Q,height:ce});},0);return ()=>{clearTimeout(fe),M.unregisterImage(be);}},[M,I,N,D]);let G=useCallback(async()=>{if(I!=="loading"){ne("loading"),z(null);try{let _=await kr(e);if(f&&Dt()&&N){let ce=Gt(_.data),be=_.data;if(ce!=="png"){let we=Pr(_.data);if(!we){ne("preview"),await xn(_.localPath),ne("placeholder");return}be=we;}let fe=_t(be),he,ye;if(P&&fe){let Ce=Math.ceil(fe.width/8),xe=Math.ceil(fe.height/16),pt=h??80,W=d??24;if(Ce>pt||xe>W){let J=pt/Ce,ee=W/xe,pe=Math.min(J,ee);Ce=Math.max(1,Math.round(Ce*pe)),xe=Math.max(1,Math.round(xe*pe));}he=Ce,ye=xe,K({width:Ce,height:xe});}else he=t??N.innerWidth,ye=n??N.innerHeight;if(he<=0||ye<=0)throw new Error("Image area too small");let Te=30,Ve=6;if(he>Te||ye>Ve){let we=Te/he,ke=Ve/ye,Ie=Math.min(we,ke);he=Math.max(1,Math.round(he*Ie)),ye=Math.max(1,Math.round(ye*Ie));}F.current={data:be,localPath:_.localPath,cellWidth:he,cellHeight:ye},ne("loaded");}else ne("preview"),await xn(_.localPath),ne("placeholder");}catch(_){let Q=_ instanceof Error?_:new Error(String(_));z(Q.message),ne("error"),b?.(Q);}}},[e,I,f,N,t,n,P,h,d,ne,b]);useEffect(()=>{if(!x||!B.current||!c||l)return;let _=B.current,Q=ce=>g?.focusedId!==_?false:ce.name==="space"||ce.name==="return"||ce.name==="r"&&F.current?(G(),true):ce.name==="escape"&&I==="loaded"?(F.current=null,K(null),ne("placeholder"),true):ce.name==="escape"&&I==="placeholder"?(g?.blur(),true):false;return x.registerInputHandler(_,Q)},[x,g,c,l,R,G,I,ne]),useEffect(()=>{C&&I==="placeholder"&&N&&N.innerWidth>0&&G();},[C,I,N,G]),useEffect(()=>{let _=A.current;return ()=>{M?.unregisterImage(_);}},[M]);let L,a;switch(I){case "placeholder":a=Y?"\u{1F310}":"\u{1F5BC}\uFE0F",L=`${a} ${te}`;break;case "loading":a="\u23F3",L=`${a} Loading...`;break;case "loaded":L=null;break;case "preview":a="\u{1F441}\uFE0F",L=`${a} Previewing...`;break;case "error":a="\u274C",L=`${a} ${V||"Error"}`;break}let S=P&&j?j.width:t,w=P&&j?j.height:n,H={...{border:"round",borderColor:"blackBright",justifyContent:"center",alignItems:"center",...o,...S!==void 0?{width:S}:{},...w!==void 0?{height:w}:{}},...T?{borderColor:"cyan"}:{},...T&&s?s:{}},X={color:"blackBright",...i,...T?{color:"cyan"}:{}};return ue.createElement("box",{style:H,focusable:c,ref:_=>{_?(k.current=_,B.current=_.focusId,v(true)):(k.current=null,B.current=null,v(false));}},L!==null?ue.createElement("text",{style:X},L):null)}function zs(e){let t=useContext(U),[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 Us(e={}){let{disabled:t,onFocus:n,onBlur:r,onKeyPress:o}=e,s=useContext(U),i=useContext(Z),c=useRef(null),l=useRef(null),[f,p]=useState(false),m=useRef(n),b=useRef(r),C=useRef(o);m.current=n,b.current=r,C.current=o;let P=useCallback(d=>{c.current=d,d?l.current=d.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),t&&s.focusedId===l.current&&s.blur());},[s,t]),useEffect(()=>{if(!s||!l.current)return;let d=l.current,g=s.focusedId===d;return p(g),s.onFocusChange(x=>{let E=x===d;p(M=>(E&&!M?m.current?.():!E&&M&&b.current?.(),E));})},[s]),useEffect(()=>{if(!i||!l.current||t)return;let d=l.current,g=x=>s?.focusedId!==d?false:C.current?.(x)===true;return i.registerInputHandler(d,g)},[i,s,t]);let h=useCallback(()=>{s&&l.current&&s.requestFocus(l.current);},[s]);return {ref:P,isFocused:f,focus:h,focusId:l.current}}function Ys(){let e=useContext(Ne);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 ni(){let e=useContext(U),t=useContext(de),[n,r]=useState([]),o=useRef(()=>{}),s=useCallback(()=>{if(!e)return;let c=(e.getActiveElements?.()??e.getRegisteredElements?.()??[]).map(({id:l,node:f})=>({id:l,node:f,layout:t?.getLayout(f)??f.layout,type:f.type}));c.sort((l,f)=>l.layout.y!==f.layout.y?l.layout.y-f.layout.y:l.layout.x-f.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 ri(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 oi(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 me(e){let t=typeof e=="string"?{mask:e}:e,{mask:n,placeholder:r="_",showPlaceholder:o=false}=t,s=ri(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 f="",p=0;for(let m of s)if(m.type==="literal")(p<l.length||o)&&(f+=m.char);else if(p<l.length){let b=l[p];if(oi(b,m.type))f+=b,p++;else {p++;continue}}else o&&(f+=r);return f}}var si={usPhone:me("(999) 999-9999"),intlPhone:me("+9 999 999 9999"),dateUS:me("99/99/9999"),dateEU:me("99/99/9999"),dateISO:me("9999-99-99"),time:me("99:99"),timeFull:me("99:99:99"),creditCard:me("9999 9999 9999 9999"),ssn:me("999-99-9999"),zip:me("99999"),zipPlus4:me("99999-9999"),ipv4:me("999.999.999.999"),mac:me("**:**:**:**:**:**")};export{Co as Box,$o as Button,ms as Checkbox,bs as DialogHost,zt as FocusScope,Ds as Image,Eo as Input,ks as JumpNav,Ao as Keybind,tn as List,Xo as Menu,Vo as Portal,Qo as Progress,gs as Radio,zo as ScrollView,ds as Select,Mo as Spacer,ns as Spinner,ko as Text,fs as ToastHost,me as createMask,Qe as detectTerminalCapabilities,si as masks,Ot as parseAnsi,yo as render,Zr as stripAnsi,Dt as supportsInlineImages,Ys as useApp,xs as useDialog,zs as useFocus,ni as useFocusRegistry,Us as useFocusable,rt as useInput,Be as useLayout,as as useToast};//# sourceMappingURL=index.js.map
|
|
19
19
|
//# sourceMappingURL=index.js.map
|