@nick-skriabin/glyph 0.1.65 → 0.1.66
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 ne,{createContext,forwardRef,useContext,useRef,useState,useEffect,useLayoutEffect,useMemo,useCallback}from'react';import Pr from'react-reconciler';import Se from'string-width';import jn,{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 kr=0;function un(){return `glyph-focus-${kr++}`}function fn(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?un():null,hidden:false}}function It(e,t){t.parent=e,e.children.push(t),e.allChildren.push(t);}function wt(e,t){t.parent=e,e.rawTextChildren.push(t),e.allChildren.push(t),e.text=e.rawTextChildren.map(n=>n.text).join("");}function pn(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 dn(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 mn(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 hn(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 st(e){let t={},n=e;for(;n;){let r=n.style;t.color===void 0&&r.color!==void 0&&(t.color=r.color),t.bg===void 0&&r.bg!==void 0&&(t.bg=r.bg),t.bold===void 0&&r.bold!==void 0&&(t.bold=r.bold),t.dim===void 0&&r.dim!==void 0&&(t.dim=r.dim),t.italic===void 0&&r.italic!==void 0&&(t.italic=r.italic),t.underline===void 0&&r.underline!==void 0&&(t.underline=r.underline),n=n.parent;}return t}function vt(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(...vt(o,r));return n}var Rt=32,gn={supportsMutation:true,supportsPersistence:false,supportsHydration:false,isPrimaryRenderer:true,scheduleTimeout:setTimeout,cancelTimeout:clearTimeout,noTimeout:-1,supportsMicrotasks:true,scheduleMicrotask:queueMicrotask,getCurrentUpdatePriority:()=>Rt,setCurrentUpdatePriority:e=>{},resolveUpdatePriority:()=>Rt,getCurrentEventPriority:()=>Rt,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 fn(e,t)},createTextInstance(e,t,n,r){return {type:"raw-text",text:e,parent:null}},appendInitialChild(e,t){t.type==="raw-text"?wt(e,t):It(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"?wt(e,t):It(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")hn(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 mn(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"?dn(e,t):pn(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 $e=Pr(gn);$e.injectIntoDevTools({bundleType:process.env.NODE_ENV==="production"?0:1,version:"0.1.0",rendererPackageName:"glyph"});var it=class{stdout;stdin;wasRaw=false;cleanedUp=false;dataHandlers=new Set;stdinAttached=false;oscState="normal";oscAccum="";escFlushTimer=null;palette=new Map;paletteResolve=null;constructor(t=process.stdout,n=process.stdin){this.stdout=t,this.stdin=n;}get columns(){return this.stdout.columns||80}get rows(){return this.stdout.rows||24}enterRawMode(){this.stdin.isTTY&&(this.wasRaw=this.stdin.isRaw,this.stdin.setRawMode(true),this.stdin.resume(),this.stdin.setEncoding("utf-8"));}exitRawMode(){this.stdin.isTTY&&!this.wasRaw&&(this.stdin.setRawMode(false),this.stdin.pause());}write(t){this.stdout.write(t);}hideCursor(){this.write("\x1B[?25l");}showCursor(){this.write("\x1B[?25h");}moveCursor(t,n){this.write(`\x1B[${n+1};${t+1}H`);}setCursorColor(t){this.write(`\x1B]12;${t}\x07`);}resetCursorColor(){this.write("\x1B]112\x07");}enterAltScreen(){this.write("\x1B[?1049h");}exitAltScreen(){this.write("\x1B[?1049l");}clearScreen(){this.write("\x1B[2J\x1B[H");}resetStyles(){this.write("\x1B[0m");}enableKittyKeyboard(){this.write("\x1B[>1u");}disableKittyKeyboard(){this.write("\x1B[<u");}setup(){this.enterRawMode(),this.enterAltScreen(),this.enableKittyKeyboard(),this.hideCursor(),this.clearScreen(),this.attachStdinListener(),this.installCleanupHandlers();}cleanup(){this.cleanedUp||(this.cleanedUp=true,this.escFlushTimer!==null&&(clearTimeout(this.escFlushTimer),this.escFlushTimer=null),this.resetStyles(),this.resetCursorColor(),this.disableKittyKeyboard(),this.showCursor(),this.exitAltScreen(),this.exitRawMode());}suspend(){this.escFlushTimer!==null&&(clearTimeout(this.escFlushTimer),this.escFlushTimer=null),this.oscState="normal",this.oscAccum="",this.resetStyles(),this.resetCursorColor(),this.disableKittyKeyboard(),this.showCursor(),this.exitAltScreen(),this.exitRawMode();}resume(){this.enterRawMode(),this.enterAltScreen(),this.enableKittyKeyboard(),this.hideCursor(),this.clearScreen();}attachStdinListener(){this.stdinAttached||(this.stdinAttached=true,this.stdin.on("data",t=>{let n=typeof t=="string"?t:t.toString("utf-8");this.dispatchFiltered(n);}));}onData(t){return this.dataHandlers.add(t),()=>{this.dataHandlers.delete(t);}}dispatchFiltered(t){this.escFlushTimer!==null&&(clearTimeout(this.escFlushTimer),this.escFlushTimer=null);let n=this.filterOsc(t);if(n.length>0)for(let r of this.dataHandlers)r(n);this.oscState==="esc"&&(this.escFlushTimer=setTimeout(()=>{this.escFlushTimer=null,this.oscState="normal";for(let r of this.dataHandlers)r("\x1B");},50));}filterOsc(t){let n="";for(let r=0;r<t.length;r++){let o=t[r],s=t.charCodeAt(r);switch(this.oscState){case "normal":s===27?this.oscState="esc":n+=o;break;case "esc":o==="]"?(this.oscState="osc",this.oscAccum=""):(n+="\x1B"+o,this.oscState="normal");break;case "osc":s===7?(this.handleOscResponse(this.oscAccum),this.oscAccum="",this.oscState="normal"):s===27?this.oscState="osc_esc":this.oscAccum+=o;break;case "osc_esc":o==="\\"?(this.handleOscResponse(this.oscAccum),this.oscAccum="",this.oscState="normal"):(this.oscAccum+="\x1B"+o,this.oscState="osc");break}}return n}handleOscResponse(t){let n=t.match(/^4;(\d+);rgb:([0-9a-fA-F]+)\/([0-9a-fA-F]+)\/([0-9a-fA-F]+)/);if(n){let r=parseInt(n[1],10),o=parseInt(n[2].substring(0,2),16),s=parseInt(n[3].substring(0,2),16),i=parseInt(n[4].substring(0,2),16);this.palette.set(r,[o,s,i]),this.palette.size>=16&&this.paletteResolve&&(this.paletteResolve(),this.paletteResolve=null);}}queryPalette(){return new Promise(t=>{let n=()=>t(this.palette),r=setTimeout(n,200);this.paletteResolve=()=>{clearTimeout(r),n();};let o="";for(let s=0;s<16;s++)o+=`\x1B]4;${s};?\x07`;this.write(o);})}onResize(t){return this.stdout.on("resize",t),()=>{this.stdout.off("resize",t);}}installCleanupHandlers(){let t=()=>this.cleanup();process.on("exit",t);let n=r=>{t(),process.kill(process.pid,r);};process.once("SIGINT",()=>n("SIGINT")),process.once("SIGTERM",()=>n("SIGTERM")),process.on("uncaughtException",r=>{t(),console.error(r),process.exit(1);}),process.on("unhandledRejection",r=>{t(),console.error(r),process.exit(1);});}};function yn(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 Er(e){switch(e.split(";")[0]){case "1":return "home";case "2":return "insert";case "3":return "delete";case "4":return "end";case "5":return "pageup";case "6":return "pagedown";case "7":return "home";case "8":return "end";case "11":return "f1";case "12":return "f2";case "13":return "f3";case "14":return "f4";case "15":return "f5";case "17":return "f6";case "18":return "f7";case "19":return "f8";case "20":return "f9";case "21":return "f10";case "23":return "f11";case "24":return "f12";case "25":return "f13";case "26":return "f14";case "28":return "f15";case "29":return "f16";case "31":return "f17";case "32":return "f18";case "33":return "f19";case "34":return "f20";default:return "unknown"}}function lt(e,t){let n=t-1;n&1&&(e.shift=true),n&2&&(e.alt=true),n&4&&(e.ctrl=true),n&8&&(e.meta=true);}function xn(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=Gr(e,n);if(s){t.push(s.key),n=s.end;continue}}if(e[n+1]==="O"){let s=Nr(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 Nr(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 Gr(e,t){let n=t+2,r="";for(;n<e.length;){let c=e.charCodeAt(n);if(c>=48&&c<=63)r+=e[n],n++;else break}if(n>=e.length)return null;let o=e[n],s=e.substring(t,n+1);n++;let i;switch(o){case "A":i={name:"up",sequence:s};break;case "B":i={name:"down",sequence:s};break;case "C":i={name:"right",sequence:s};break;case "D":i={name:"left",sequence:s};break;case "H":i={name:"home",sequence:s};break;case "F":i={name:"end",sequence:s};break;case "Z":i={name:"tab",sequence:s,shift:true};break;case "P":i={name:"f1",sequence:s};break;case "Q":i={name:"f2",sequence:s};break;case "R":i={name:"f3",sequence:s};break;case "S":i={name:"f4",sequence:s};break;case "~":{if(r.startsWith("27;")){let c=r.split(";"),l=parseInt(c[1]??"1",10),u=parseInt(c[2]??"0",10);i={name:yn(u),sequence:s},lt(i,l);break}if(i={name:Er(r),sequence:s},r.includes(";")){let c=r.split(";"),l=parseInt(c[1]??"1",10);lt(i,l);}break}case "u":{let c=r.split(";"),l=parseInt(c[0]??"0",10),u=parseInt(c[1]??"1",10);i={name:yn(l),sequence:s},lt(i,u);break}case "I":i={name:"focus",sequence:s};break;case "O":i={name:"blur",sequence:s};break;default:i={name:"unknown",sequence:s};}if(r.includes(";")&&!["~","u"].includes(o)){let c=r.split(";"),l=parseInt(c[c.length-1]??"1",10);l>=1&&l<=16&<(i,l);}return {key:i,end:n}}var Br={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"},Fr={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 Tt(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 bn(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=Tt(e);return `\x1B[38;2;${o};${s};${i}m`}return Br[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 Cn(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=Tt(e);return `\x1B[48;2;${o};${s};${i}m`}return Fr[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 Sn={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]},In=["black","red","green","yellow","blue","magenta","cyan","white","blackBright","redBright","greenBright","yellowBright","blueBright","magentaBright","cyanBright","whiteBright"],Oe=null;function wn(e){e.size>0&&(Oe=e);}function Lr(e){if(Oe){let t=In.indexOf(e);if(t!==-1){let n=Oe.get(t);if(n)return n}}return Sn[e]??null}function Mr(e){if(typeof e=="string"){if(e.startsWith("#")){let t=Tt(e);return [t.r,t.g,t.b]}return Lr(e)}if(typeof e=="number"){if(e<16){if(Oe){let s=Oe.get(e);if(s)return s}return Sn[In[e]]}if(e>=232){let s=(e-232)*10+8;return [s,s,s]}let t=e-16,n=t%6*51,r=Math.floor(t/6)%6*51;return [Math.floor(t/36)*51,r,n]}return [e.r,e.g,e.b]}function ct(e){let t=Mr(e);if(!t)return false;let[n,r,o]=t.map(i=>{let c=i/255;return c<=.03928?c/12.92:Math.pow((c+.055)/1.055,2.4)});return .2126*n+.7152*r+.0722*o>.4}function kt(e,t){return e===t?true:e==null||t==null?false:typeof e=="object"&&typeof t=="object"?e.r===t.r&&e.g===t.g&&e.b===t.b:false}function vn(e){return e&&ct(e)?"black":"white"}var Ve=class e{width;height;cells;constructor(t,n){this.width=t,this.height=n,this.cells=new Array(t*n),this.clear();}clear(){for(let t=0;t<this.cells.length;t++)this.cells[t]={ch:" "};}resize(t,n){this.width=t,this.height=n,this.cells=new Array(t*n),this.clear();}get(t,n){if(!(t<0||t>=this.width||n<0||n>=this.height))return this.cells[n*this.width+t]}set(t,n,r){t<0||t>=this.width||n<0||n>=this.height||(this.cells[n*this.width+t]=r);}setChar(t,n,r,o,s,i,c,l,u){t<0||t>=this.width||n<0||n>=this.height||(this.cells[n*this.width+t]={ch:r,fg:o,bg:s,bold:i,dim:c,italic:l,underline:u});}fillRect(t,n,r,o,s,i,c){for(let l=n;l<n+o;l++)for(let u=t;u<t+r;u++)this.setChar(u,l,s,i,c);}clone(){let t=new e(this.width,this.height);for(let n=0;n<this.cells.length;n++){let r=this.cells[n];t.cells[n]={...r};}return t}cellsEqual(t,n){return t.ch===n.ch&&kt(t.fg,n.fg)&&kt(t.bg,n.bg)&&(t.bold??false)===(n.bold??false)&&(t.dim??false)===(n.dim??false)&&(t.italic??false)===(n.italic??false)&&(t.underline??false)===(n.underline??false)}};var Ar={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 Rn(e){return e==="none"?null:Ar[e]}function Tn(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
|
|
3
|
-
`)C.push(m.length);else {let M={color:v.style.fg??
|
|
4
|
-
`),A=ge(G,l,B),I=0,x=0;if(H){let y=o.position,O=0,z=y,V=0;for(let K=0;K<G.length;K++){let $=G[K].length;if(y<=V+$){O=K,z=y-V;break}V+=$+1;}let j=0;for(let K=0;K<O;K++)j+=ge([G[K]],l,B).length;let U=ge([G[O]],l,B),W=0,D=0;for(let K=0;K<U.length;K++){let $=U[K];if(z<=W+$.length){D=K;break}W+=$.length;}I=j+D,x=Se(G[O].slice(W,W+(z-W)));}let w=Math.max(0,I-u+1);for(let y=0;y<u;y++){let O=w+y;if(O>=A.length)break;let z=A[O],V=0;for(let j of z){if(V>=l)break;let U=Se(j);U>0&&de(t,n,i+V,c+y,j,R,h.bg,h.bold,M,h.italic,h.underline),V+=U;}}if(H){let y=I-w;if(y>=0&&y<u){let O=Math.min(x,l-1),z=i+O,V=c+y;if(at(z,V,n)&&z<i+l)if(s)P={cursorPosition:{x:z,y:V,bg:h.bg}};else {let j=t.get(z,V),U=j?.ch&&j.ch!==" "?j.ch:"\u258C",W=h.bg??"black",D=h.color??"white";t.setChar(z,V,U,W,D,j?.bold,j?.dim,j?.italic,false);}}}}else {let B=0;for(let G of C){if(B>=l)break;let A=Se(G);A>0&&de(t,n,i+B,c,G,R,h.bg,h.bold,M,h.italic,h.underline),B+=A;}if(H){let G=Math.min(o.position,l-1),A=i+G;if(at(A,c,n)&&A<i+l)if(s)P={cursorPosition:{x:A,y:c,bg:h.bg}};else {let I=t.get(A,c),x=I?.ch&&I.ch!==" "?I.ch:"\u258C",w=h.bg??"black",y=h.color??"white";t.setChar(A,c,x,w,y,I?.bold,I?.dim,I?.italic,false);}}}return P}var qr="\x1B",ke=`${qr}[`;function zr(e,t){return `${ke}${t+1};${e+1}H`}function Xr(e){let t=`${ke}0m`;return e.bold&&(t+=`${ke}1m`),e.dim&&(t+=`${ke}2m`),e.italic&&(t+=`${ke}3m`),e.underline&&(t+=`${ke}4m`),e.fg!=null&&(t+=bn(e.fg)),e.bg!=null&&(t+=Cn(e.bg)),t}function Fn(e,t,n){let r="",o=-1,s=-1,i="";for(let c=0;c<t.height;c++)for(let l=0;l<t.width;l++){let u=t.get(l,c);if(!n){let m=e.get(l,c);if(m&&t.cellsEqual(u,m))continue}(s!==c||o!==l)&&(r+=zr(l,c));let f=Xr(u);f!==i&&(r+=f,i=f),r+=u.ch,o=l+1,s=c;}return r.length>0&&(r+=`${ke}0m`),r}var Qr={row:FlexDirection.Row,column:FlexDirection.Column},Zr={"flex-start":Justify.FlexStart,center:Justify.Center,"flex-end":Justify.FlexEnd,"space-between":Justify.SpaceBetween,"space-around":Justify.SpaceAround},eo={"flex-start":Align.FlexStart,center:Align.Center,"flex-end":Align.FlexEnd,stretch:Align.Stretch};function An(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%"),t(n));}function Ie(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%")?e.setPositionPercent(t,parseFloat(n)):e.setPosition(t,n));}function to(e,t,n){An(e,o=>e.setWidth(o),t.width),An(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(Qr[t.flexDirection]??FlexDirection.Column),t.flexWrap&&e.setFlexWrap(t.flexWrap==="wrap"?Wrap.Wrap:Wrap.NoWrap),t.justifyContent&&e.setJustifyContent(Zr[t.justifyContent]??Justify.FlexStart),t.alignItems&&e.setAlignItems(eo[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&&(Ie(e,Edge.Top,t.inset),Ie(e,Edge.Right,t.inset),Ie(e,Edge.Bottom,t.inset),Ie(e,Edge.Left,t.inset)),Ie(e,Edge.Top,t.top),Ie(e,Edge.Right,t.right),Ie(e,Edge.Bottom,t.bottom),Ie(e,Edge.Left,t.left),t.clip&&e.setOverflow(Overflow.Hidden);}function Hn(e){let t=jn.Node.create();if(e.yogaNode=t,to(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=$n(e),Tn(i,n,r,e.style.wrap??"wrap")});else for(let n=0;n<e.children.length;n++){let r=e.children[n];r.hidden||(Hn(r),t.insertChild(r.yogaNode,t.getChildCount()));}}function $n(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=$n(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 On(e,t,n){let r=e.yogaNode,o=r.getComputedLayout(),s=t+o.left,i=n+o.top,c=o.width,l=o.height,u=e.style.border&&e.style.border!=="none"?1:0,f=r.getComputedPadding(Edge.Top),m=r.getComputedPadding(Edge.Right),C=r.getComputedPadding(Edge.Bottom),S=r.getComputedPadding(Edge.Left),k=s+u+S,h=i+u+f,p=Math.max(0,c-u*2-S-m),g=Math.max(0,l-u*2-f-C),v=e.layout;(!v||v.x!==s||v.y!==i||v.width!==c||v.height!==l||v.innerX!==k||v.innerY!==h||v.innerWidth!==p||v.innerHeight!==g)&&(e.layout={x:s,y:i,width:c,height:l,innerX:k,innerY:h,innerWidth:p,innerHeight:g});for(let R of e.children)R.hidden||!R.yogaNode||On(R,s,i);}function Vn(e,t,n){let r=jn.Node.create();r.setWidth(t),r.setHeight(n),r.setFlexDirection(FlexDirection.Column);for(let o of e)o.hidden||(Hn(o),r.insertChild(o.yogaNode,r.getChildCount()));r.calculateLayout(t,n,Direction.LTR);for(let o of e)o.hidden||!o.yogaNode||On(o,0,0);r.freeRecursive(),Dn(e);}function Dn(e){for(let t of e)t.yogaNode=null,Dn(t.children);}var Y=createContext(null),q=createContext(null),ie=createContext(null),Be=createContext(null),Fe=createContext(null),ft=createContext(null);var ee=null;function We(e=false){if(ee)return ee;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"?(ee={name:"kitty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},ee):o||t.includes("ghostty")?(ee={name:"ghostty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},ee):s||n==="WezTerm"?(ee={name:"wezterm",supportsKittyGraphics:true,supportsIterm2Images:true,supportsSixel:true},ee):n==="iTerm.app"||i==="iTerm2"?(ee={name:"iterm2",supportsKittyGraphics:false,supportsIterm2Images:true,supportsSixel:false},ee):c?(ee={name:"konsole",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:true},ee):n==="vscode"?(ee={name:"vscode",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},ee):(ee={name:"unknown",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},ee)}function Et(){let e=We();return e.supportsKittyGraphics||e.supportsIterm2Images||e.supportsSixel}var te="\x1B";function pt(){return !!process.env.TMUX}function Nt(e){if(!pt())return e;let t=e.replace(/\x1b/g,"\x1B\x1B");return `${te}Ptmux;${t}${te}\\`}function Kn(e){let t=We();return t.supportsKittyGraphics?no(e):t.supportsIterm2Images?ro(e):null}function Gt(e){if(We().supportsKittyGraphics){let n;return e!==void 0?n=`${te}_Ga=d,d=i,i=${e}${te}\\`:n=`${te}_Ga=d,d=a${te}\\`,Nt(n)}return null}function no(e){let{data:t,width:n,height:r,x:o,y:s,id:i}=e,c=t.toString("base64"),l=`${te}[${s+1};${o+1}H`,u=Bt(t),f="a=T,f=100";i!==void 0&&(f+=`,i=${i}`),u&&(f+=`,s=${u.width},v=${u.height}`),f+=`,c=${n},r=${r}`;let m=4096,C=[l];pt()&&C.unshift(`${te}[?25l`);for(let S=0;S<c.length;S+=m){let k=c.slice(S,S+m),p=S+m>=c.length?"m=0":"m=1",g;S===0?g=`${te}_G${f},${p},q=2;${k}${te}\\`:g=`${te}_G${p};${k}${te}\\`,C.push(Nt(g));}return pt()&&C.push(`${te}[?25h`),C.join("")}function ro(e){let{data:t,width:n,height:r,x:o,y:s}=e,i=t.toString("base64"),c=`${te}[${s+1};${o+1}H`,l=[`width=${n}`,`height=${r}`,"preserveAspectRatio=1","inline=1"].join(";"),u=`${te}]1337;File=${l}:${i}\x07`;return c+(pt()?Nt(u):u)}function Bt(e){if(e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e.length>=24){let t=e.readUInt32BE(16),n=e.readUInt32BE(20);return {width:t,height:n}}if(e[0]===255&&e[1]===216&&e[2]===255){let t=2;for(;t<e.length-8;){if(e[t]!==255){t++;continue}let n=e[t+1];if(n!==void 0&&(n>=192&&n<=195||n>=197&&n<=199||n>=201&&n<=203||n>=205&&n<=207)){let o=e.readUInt16BE(t+5);return {width:e.readUInt16BE(t+7),height:o}}let r=e.readUInt16BE(t+2);t+=2+r;}}if(e[0]===71&&e[1]===73&&e[2]===70&&e.length>=10){let t=e.readUInt16LE(6),n=e.readUInt16LE(8);return {width:t,height:n}}return null}function oo(e,t={}){let n=t.stdout??process.stdout,r=t.stdin??process.stdin,o=t.debug??false,s=t.useNativeCursor??true,i=new it(n,r);i.setup();let c=false;i.queryPalette().then(a=>{wn(a),f=true,j();});let l=new Ve(i.columns,i.rows),u=new Ve(i.columns,i.rows),f=true,m=new Set,C=new Set,S=new Map,k={subscribe(a){return m.add(a),()=>m.delete(a)},subscribePriority(a){return C.add(a),()=>C.delete(a)},registerInputHandler(a,b){return S.set(a,b),()=>S.delete(a)}},h=new Map,p=new Map,g={registerImage(a){let b=h.get(a.id);(!b||b.x!==a.x||b.y!==a.y||b.width!==a.width||b.height!==a.height)&&(p.set(a.id,a),j());},unregisterImage(a){h.delete(a),p.delete(a);let b=Gt(a);b&&i.write(b),j();}};function v(){for(let a of p.values()){let b=Kn({data:a.data,width:a.width,height:a.height,x:a.x,y:a.y,id:a.id});b&&(i.write(b),h.set(a.id,{x:a.x,y:a.y,width:a.width,height:a.height}));}p.clear();}let R=null,M=new Map,H=[],P=new Set,B=[],G=new Set;function A(a){if(R!==a){R=a,j();for(let b of G)b(R);}}function I(){let a=[...H];if(B.length>0){let b=B[B.length-1];a=a.filter(T=>b.has(T));}return a=a.filter(b=>!P.has(b)),a.sort((b,T)=>{let F=M.get(b),d=M.get(T);if(!F||!d)return 0;let L=F.layout,E=d.layout;return L.y!==E.y?L.y-E.y:L.x-E.x}),a}let x={get focusedId(){return R},register(a,b){if(M.set(a,b),H.includes(a)||H.push(a),B.length>0&&B[B.length-1].add(a),R===null){let T=I();T.length>0&&A(T[0]);}return ()=>{M.delete(a);let T=H.indexOf(a);if(T!==-1&&H.splice(T,1),R===a){let F=I();A(F[0]??null);}}},requestFocus(a){A(a);},focusNext(){let a=I();if(a.length===0)return;let T=((R?a.indexOf(R):-1)+1)%a.length;A(a[T]);},focusPrev(){let a=I();if(a.length===0)return;let T=((R?a.indexOf(R):0)-1+a.length)%a.length;A(a[T]);},setSkippable(a,b){if(b){if(P.add(a),R===a){let T=I();T.length>0&&A(T[0]);}}else P.delete(a);},trapIds:null,pushTrap(a){return B.push(a),()=>{let b=B.indexOf(a);b!==-1&&B.splice(b,1);}},onFocusChange(a){return G.add(a),()=>{G.delete(a);}},getRegisteredElements(){let a=[];for(let b of H){if(P.has(b))continue;let T=M.get(b);T&&a.push({id:b,node:T});}return a},getActiveElements(){let a=I(),b=[];for(let T of a){if(P.has(T))continue;let F=M.get(T);F&&b.push({id:T,node:F});}return b}},w=new Map,y={getLayout(a){return a.layout},subscribe(a,b){return w.has(a)||w.set(a,new Set),w.get(a).add(b),()=>{let T=w.get(a);T&&(T.delete(b),T.size===0&&w.delete(a));}}},O={registerNode(){},unregisterNode(){},scheduleRender:j,exit(a){N.exit(a);},get columns(){return i.columns},get rows(){return i.rows}},z={type:"root",children:[],onCommit(){j();}},V=false;function j(){V||(V=true,queueMicrotask(()=>{V=false,U();}));}function U(){let a=i.columns,b=i.rows;(u.width!==a||u.height!==b)&&(u.resize(a,b),l.resize(a,b),f=true),Vn(z.children,a,b),W(z.children);let T;if(R){let L=M.get(R);L?.type==="input"&&(T={nodeId:R,position:L.props.cursorPosition??L.props.value?.length??0});}let F=Nn(z.children,u,{cursorInfo:T,useNativeCursor:s}),d=Fn(l,u,f);if(d.length>0&&i.write(d),p.size>0&&c&&(i.hideCursor(),c=false),v(),s)if(F.cursorPosition){let L=vn(F.cursorPosition.bg);i.setCursorColor(L),i.moveCursor(F.cursorPosition.x,F.cursorPosition.y),c||(i.showCursor(),c=true);}else i.hideCursor(),c=false;for(let L=0;L<u.cells.length;L++)l.cells[L]={...u.cells[L]};f=false;}function W(a){for(let b of a){let T=w.get(b);if(T)for(let F of T)F(b.layout);W(b.children);}}let D=i.onData(a=>{let b=xn(a);for(let T of b){if(T.ctrl&&T.name==="c"){N.exit();return}if(T.ctrl&&T.name==="z"){i.suspend(),process.kill(0,"SIGSTOP");return}let F=false;for(let d of C)if(d(T)){F=true;break}if(!F&&R){let d=S.get(R);d&&(F=d(T));}if(!F&&T.name==="tab"&&!T.ctrl&&!T.alt){T.shift?x.focusPrev():x.focusNext();continue}if(!F)for(let d of m)d(T);}}),K=i.onResize(()=>{f=true,j();}),$=()=>{i.resume(),f=true,j();};process.on("SIGCONT",$);let fe=ne.createElement(Be.Provider,{value:O},ne.createElement(Y.Provider,{value:k},ne.createElement(q.Provider,{value:x},ne.createElement(ie.Provider,{value:y},ne.createElement(ft.Provider,{value:g},e))))),me=a=>{o&&console.error("Uncaught error:",a);},J=a=>{o&&console.error("Error caught by boundary:",a);},re=a=>{o&&console.error("Recoverable error:",a);},Q=$e.createContainer(z,0,null,false,null,"",me,J,re,null);$e.updateContainer(fe,Q,null,null);let N={unmount(){$e.updateContainer(null,Q,null,null),D(),K(),process.off("SIGCONT",$);let a=Gt();a&&i.write(a),i.cleanup();},exit(a){N.unmount(),process.exit(a??0);}};return N}var lo=forwardRef(function({children:t,style:n,focusable:r},o){return ne.createElement("box",{style:n,focusable:r,ref:o},t)});var ho=forwardRef(function({children:t,style:n,wrap:r,focusable:o,focusedStyle:s},i){let c=useContext(q),l=useRef(null),[u,f]=useState(false);useEffect(()=>{if(!c||!o||!l.current?.focusId)return;let S=l.current.focusId;return f(c.focusedId===S),c.onFocusChange(k=>{f(k===S);})},[c,o]);let m=r?{...n,wrap:r}:n;u&&s&&(m={...m,...s});let C=S=>{l.current=S,typeof i=="function"?i(S):i&&(i.current=S);};return ne.createElement("text",{style:m,focusable:o,ref:C},t)});function Wn(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
|
|
6
|
-
`),s=[],i=0;for(let
|
|
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 Xe(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 yo(e){let{value:t,defaultValue:n="",onChange:r,onKeyPress:o,onBeforeChange:s,placeholder:i,style:c,focusedStyle:l,multiline:
|
|
8
|
-
`+
|
|
9
|
-
`);)
|
|
10
|
-
`;)
|
|
11
|
-
`;)
|
|
12
|
-
`;)
|
|
13
|
-
`;)
|
|
14
|
-
`)))))}function Kt({count:e,renderItem:t,selectedIndex:n,onSelectionChange:r,onSelect:o,defaultSelectedIndex:s=0,disabledIndices:i,style:c,focusable:l=true}){let u=n!==void 0,[f,m]=useState(s),C=u?n:f,S=useContext(q),k=useContext(Y),h=useRef(null),p=useRef(null),g=useRef(o);g.current=o;let[v,R]=useState(false),[M,H]=useState(false),P=useRef(null),B=useCallback(x=>{let w=Math.max(0,Math.min(x,e-1));u?r?.(w):m(w);},[u,r,e]),G=useCallback((x,w)=>{if(!i||i.size===0)return Math.max(0,Math.min(x+w,e-1));let y=x+w;for(;y>=0&&y<e&&i.has(y);)y+=w;return y<0||y>=e?x:y},[i,e]);useEffect(()=>{if(!(!S||!p.current||!h.current||!l))return S.register(p.current,h.current)},[S,l,v]),useEffect(()=>{if(!S||!p.current)return;let x=p.current;return H(S.focusedId===x),S.onFocusChange(w=>{H(w===x);})},[S,v]);let A=useCallback(x=>{let w=x?e-1:0,y=x?-1:1,O=w;for(;O>=0&&O<e&&i?.has(O);)O+=y;return O>=0&&O<e?O:x?e-1:0},[i,e]);useEffect(()=>{if(!k||!p.current||!l)return;let x=p.current,w=y=>S?.focusedId!==x?false:y.name==="g"&&!y.ctrl&&!y.alt?P.current==="g"?(B(A(false)),P.current=null,true):(P.current="g",true):y.name==="G"||y.name==="g"&&y.shift?(P.current=null,B(A(true)),true):(P.current=null,y.name==="up"||y.name==="k"?(B(G(C,-1)),true):y.name==="down"||y.name==="j"?(B(G(C,1)),true):y.name==="return"?(i?.has(C)||g.current?.(C),true):false);return k.registerInputHandler(x,w)},[k,S,l,C,B,G,A,i,v]);let I=[];for(let x=0;x<e;x++)I.push(ne.createElement(ne.Fragment,{key:x},t({index:x,selected:x===C,focused:M})));return ne.createElement("box",{style:{flexDirection:"column",...c},focusable:l,ref:x=>{x?(h.current=x,p.current=x.focusId,R(true)):(h.current=null,p.current=null,R(false));}},...I)}function Ho({items:e,selectedIndex:t,onSelectionChange:n,onSelect:r,defaultSelectedIndex:o=0,style:s,highlightColor:i="cyan",focusable:c=true}){let l=new Set;for(let f=0;f<e.length;f++)e[f].disabled&&l.add(f);let u=f=>{let m=e[f];m&&!m.disabled&&r?.(m.value,f);};return ne.createElement(Kt,{count:e.length,selectedIndex:t,onSelectionChange:n,onSelect:u,defaultSelectedIndex:o,disabledIndices:l.size>0?l:void 0,style:s,focusable:c,renderItem:({index:f,selected:m,focused:C})=>{let S=e[f],k=S.disabled,h=m&&C,p=m?">":" ";return ne.createElement("box",{style:{flexDirection:"row",...h?{bg:i}:{}}},ne.createElement("text",{style:h?{bold:true,color:"black"}:k?{dim:true}:{}},`${p} ${S.label}`))}})}function Do({value:e,indeterminate:t=false,width:n="100%",label:r,showPercent:o=false,style:s,filled:i="\u2588",empty:c="\u2591"}){let l=useRef(null),f=ve(l).innerWidth,[m,C]=useState(0);useEffect(()=>{if(!t)return;let g=setInterval(()=>{C(v=>(v+1)%Math.max(1,f+6));},100);return ()=>clearInterval(g)},[t,f]);let S=Math.max(0,Math.min(1,e??0)),k=o?` ${Math.round(S*100)}%`:"",h="";if(f>0)if(t&&e===void 0){let g=Math.max(1,Math.min(3,Math.floor(f/4))),v=[];for(let R=0;R<f;R++)R>=m-g&&R<m?v.push(i):v.push(c);h=v.join("");}else {let g=Math.round(S*f);h=i.repeat(g)+c.repeat(f-g);}let p=[];return r&&p.push(ne.createElement("text",{key:"label",style:{bold:true}},r+" ")),p.push(ne.createElement("box",{key:"track",style:{flexGrow:1,flexShrink:1},ref:g=>{l.current=g??null;}},ne.createElement("text",{key:"bar",style:{}},h))),o&&p.push(ne.createElement("text",{key:"pct",style:{bold:true}},k)),ne.createElement("box",{style:{flexDirection:"row",width:n,...s}},...p)}var _o=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function qo({frames:e=_o,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=[ne.createElement("text",{key:"frame",style:r},e[o])];return n&&i.push(ne.createElement("text",{key:"label",style:{}}," "+n)),ne.createElement("box",{style:{flexDirection:"row"}},...i)}var or=createContext(null),Qo=0;function Zo(){let e=useContext(or);if(!e)throw new Error("useToast must be used within a <ToastHost>");return e.push}var es={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 ts({position:e="bottom-right",maxVisible:t=5,children:n}){let[r,o]=useState([]),s=useRef(new Map),i=useCallback(S=>{let k=`toast-${Qo++}`,h={id:k,durationMs:3e3,variant:"info",...S};if(o(p=>[...p,h]),h.durationMs&&h.durationMs>0){let p=setTimeout(()=>{s.current.delete(k),o(g=>g.filter(v=>v.id!==k));},h.durationMs);s.current.set(k,p);}},[]);useEffect(()=>()=>{for(let S of s.current.values())clearTimeout(S);s.current.clear();},[]);let c=useRef({push:i});c.current.push=i;let l=e.startsWith("top"),u=e.endsWith("right"),f={position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:900,flexDirection:"column",justifyContent:l?"flex-start":"flex-end",alignItems:u?"flex-end":"flex-start",padding:1},C=r.slice(-t).map(S=>{let k=S.variant??"info",h=es[k],p=[];return S.title&&p.push(ne.createElement("text",{key:"title",style:{bold:true,color:h.title}},S.title)),p.push(ne.createElement("text",{key:"msg",style:{color:h.text}},S.message)),ne.createElement("box",{key:S.id,style:{bg:h.bg,paddingX:1,flexDirection:"column",minWidth:20,maxWidth:50}},...p)});return ne.createElement(or.Provider,{value:c.current},n,C.length>0?ne.createElement("box",{style:f},...C):null)}function rs({items:e,value:t,onChange:n,placeholder:r="Select...",style:o,focusedStyle:s,dropdownStyle:i,highlightColor:c="cyan",maxVisible:l=8,searchable:u=true,disabled:f}){let m=useContext(q),C=useContext(Y),S=useContext(Be),k=useContext(Fe),h=useRef(null),p=useRef(null),g=useRef(n);g.current=n;let[v,R]=useState(false),[M,H]=useState(false),[P,B]=useState(false),[G,A]=useState(0),[I,x]=useState(""),[w,y]=useState(0),O=ve(h),z=S?.rows??24,V=k?.getBounds(),U=e.find(b=>b.value===t)?.label??"",W=useMemo(()=>{if(!I)return e;let b=I.toLowerCase();return e.filter(T=>T.label.toLowerCase().includes(b))},[e,I]),D=Math.min(l,W.length),K=W.slice(w,w+D);useEffect(()=>{A(0),y(0);},[I]),useEffect(()=>{!M&&P&&(B(false),x(""));},[M,P]),useEffect(()=>{if(!(!m||!p.current||!h.current))return m.register(p.current,h.current)},[m,v]),useEffect(()=>{!m||!p.current||m.setSkippable(p.current,!!f);},[m,f,v]),useEffect(()=>{if(!m||!p.current)return;let b=p.current;return H(m.focusedId===b),m.onFocusChange(T=>{H(T===b);})},[m,v]);let $=useCallback((b,T)=>{let F=b+T;for(;F>=0&&F<W.length;){if(!W[F].disabled)return F;F+=T;}return b},[W]),fe=useCallback(b=>{b<w?y(b):b>=w+D&&y(b-D+1);},[w,D]);useEffect(()=>{if(!C||!p.current||f)return;let b=p.current,T=F=>{if(m?.focusedId!==b)return false;if(!P){if(F.name==="return"||F.name===" "||F.sequence===" "||F.name==="down"){B(true),x("");let d=W.findIndex(E=>E.value===t),L=d>=0?d:0;return A(L),y(Math.max(0,L-Math.floor(l/2))),true}return false}if(F.name==="tab")return B(false),x(""),false;if(F.name==="escape")return B(false),x(""),true;if(F.name==="return"){let d=W[G];return d&&!d.disabled&&(g.current?.(d.value),B(false),x("")),true}if(F.name==="up"){let d=$(G,-1);return A(d),fe(d),true}if(F.name==="down"){let d=$(G,1);return A(d),fe(d),true}if(F.name==="backspace")return u&&I.length>0&&x(d=>d.slice(0,-1)),true;if(F.name==="home"){let d=$(-1,1);return A(d),fe(d),true}if(F.name==="end"){let d=$(W.length,-1);return A(d),fe(d),true}if(u&&F.sequence&&F.sequence.length===1&&!F.ctrl&&!F.alt){let d=F.sequence;if(d>=" "&&d<="~")return x(L=>L+d),true}return true};return C.registerInputHandler(b,T)},[C,m,f,P,G,W,t,l,u,I,$,fe,v]);let J={flexDirection:"row",width:"100%",...!o?.bg&&o?.border===void 0?{border:"single"}:{},...o,...M&&s?s:{}},re=U?o?.color??void 0:"blackBright",Q=[ne.createElement("text",{key:"label",style:{flexGrow:1,flexShrink:1,color:re,wrap:"ellipsis",...U?{}:{dim:true}}},U||r),ne.createElement("text",{key:"arrow",style:{flexShrink:0,color:M?c:"blackBright"}},P?" \u25B2":" \u25BC")],N=null;if(P){let b=[];u&&I&&b.push(ne.createElement("box",{key:"search",style:{paddingX:1}},ne.createElement("text",{style:{color:"blackBright",dim:true}},`/${I}`))),W.length===0&&b.push(ne.createElement("box",{key:"empty",style:{paddingX:1}},ne.createElement("text",{style:{dim:true,color:"blackBright"}},"No matches"))),w>0&&b.push(ne.createElement("box",{key:"scroll-up",style:{justifyContent:"center",alignItems:"center"}},ne.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25B2"))),K.forEach((xe,he)=>{let be=w+he===G,ae=xe.disabled,Ce={paddingX:1,...be&&!ae?{bg:c}:{}},ot={...be&&!ae?{color:"black",bold:true}:{},...ae?{dim:true,color:"blackBright"}:{}};b.push(ne.createElement("box",{key:`item-${xe.value}`,style:Ce},ne.createElement("text",{style:ot},xe.label)));}),w+D<W.length&&b.push(ne.createElement("box",{key:"scroll-down",style:{justifyContent:"center",alignItems:"center"}},ne.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25BC")));let T=w>0,F=w+D<W.length,d=u&&I,L=W.length===0,E=!i?.bg&&i?.border===void 0,_=D+(E?2:0);T&&(_+=1),F&&(_+=1),d&&(_+=1),L&&(_+=1);let oe=O.y+O.height,pe,se;V?(pe=V.visibleBottom-oe,se=O.y-V.visibleTop):(pe=z-oe,se=O.y);let Re=pe<_&&se>=_?-_:O.height||1;N=ne.createElement("box",{style:{position:"absolute",top:Re,left:0,right:0,zIndex:9999,...E?{border:"single"}:{},bg:"black",flexDirection:"column",...i}},...b);}let a={flexDirection:"column",width:J.width??"100%",minWidth:J.minWidth,maxWidth:J.maxWidth,flexGrow:J.flexGrow,flexShrink:J.flexShrink??1};return ne.createElement("box",{style:a},ne.createElement("box",{style:J,focusable:true,ref:b=>{b?(h.current=b,p.current=b.focusId,R(true)):(h.current=null,p.current=null,R(false));}},...Q),N)}function os({checked:e,onChange:t,label:n,style:r,focusedStyle:o,disabled:s,checkedChar:i="\u2713",uncheckedChar:c=" "}){let l=useContext(q),u=useContext(Y),f=useRef(null),m=useRef(null),C=useRef(t);C.current=t;let S=useRef(e);S.current=e;let[k,h]=useState(false),[p,g]=useState(false);useEffect(()=>{if(!(!l||!m.current||!f.current||s))return l.register(m.current,f.current)},[l,s,k]),useEffect(()=>{if(!l||!m.current)return;let P=m.current;return g(l.focusedId===P),l.onFocusChange(B=>{g(B===P);})},[l,k]),useEffect(()=>{if(!u||!m.current||s)return;let P=m.current,B=G=>l?.focusedId!==P?false:G.name==="return"||G.name===" "||G.sequence===" "?(C.current(!S.current),true):false;return u.registerInputHandler(P,B)},[u,l,s,k]);let v={flexDirection:"row",gap:1,...r,...p&&o?o:{}},R=e?i:c,M={color:s?"blackBright":p?"white":r?.color},H={color:s?"blackBright":r?.color};return ne.createElement("box",{style:v,focusable:!s,ref:P=>{P?(f.current=P,m.current=P.focusId,h(true)):(f.current=null,m.current=null,h(false));}},ne.createElement("text",{key:"box",style:M},`[${R}]`),n?ne.createElement("text",{key:"label",style:H},n):null)}function is({items:e,value:t,onChange:n,style:r,itemStyle:o,focusedItemStyle:s,selectedItemStyle:i,disabled:c,direction:l="column",gap:u=0,selectedChar:f="\u25CF",unselectedChar:m="\u25CB"}){let C=useContext(q),S=useContext(Y),k=useRef(null),h=useRef(null),p=useRef(n);p.current=n;let[g,v]=useState(false),[R,M]=useState(false),[H,P]=useState(()=>{let I=e.findIndex(x=>x.value===t);return I>=0?I:e.findIndex(x=>!x.disabled)}),B=useCallback((I,x)=>{let w=I;for(let y=0;y<e.length;y++)if(w=(w+x+e.length)%e.length,!e[w]?.disabled)return w;return I},[e]);useEffect(()=>{if(!(!C||!h.current||!k.current||c))return C.register(h.current,k.current)},[C,c,g]),useEffect(()=>{if(!C||!h.current)return;let I=h.current;return M(C.focusedId===I),C.onFocusChange(x=>{M(x===I);})},[C,g]),useEffect(()=>{if(!S||!h.current||c)return;let I=h.current,x=w=>{if(C?.focusedId!==I)return false;if(w.name==="up"||w.name==="left"||w.name==="k"||w.name==="tab"&&w.shift)return P(y=>B(y,-1)),true;if(w.name==="down"||w.name==="right"||w.name==="j"||w.name==="tab"&&!w.shift)return P(y=>B(y,1)),true;if(w.name==="return"||w.name===" "||w.sequence===" "){let y=e[H];return y&&!y.disabled&&p.current(y.value),true}return false};return S.registerInputHandler(I,x)},[S,C,c,e,H,B,g]),useEffect(()=>{let I=e.findIndex(x=>x.value===t);I>=0&&P(I);},[t,e]);let G={flexDirection:l,gap:u,...r},A=e.map((I,x)=>{let w=I.value===t,y=x===H,O=c||I.disabled,z=w?f:m,V={flexDirection:"row",gap:1,...o};w&&i&&(V={...V,...i}),R&&y&&s&&(V={...V,...s});let j=O?"blackBright":R&&y?s?.color??"white":w?i?.color??o?.color:o?.color;return ne.createElement("box",{key:x,style:V},ne.createElement("text",{key:"radio",style:{color:j}},`(${z})`),ne.createElement("text",{key:"label",style:{color:j}},I.label))});return ne.createElement("box",{style:G,focusable:!c,ref:I=>{I?(k.current=I,h.current=I.focusId,v(true)):(k.current=null,h.current=null,v(false));}},...A)}var fr=createContext(null);function cs(){let e=useContext(fr);if(!e)throw new Error("useDialog must be used within a DialogHost");return e}function as({children:e}){let[t,n]=useState([]),r=useRef(0),o=useCallback((u,f)=>new Promise(m=>{let C=++r.current;n(S=>[...S,{id:C,type:"alert",content:u,okText:f?.okText??"OK",cancelText:"",style:f?.style,buttonStyle:f?.buttonStyle,okButtonStyle:f?.okButtonStyle,focusedButtonStyle:f?.focusedButtonStyle,backdropStyle:f?.backdropStyle,resolve:()=>m()}]);}),[]),s=useCallback((u,f)=>new Promise(m=>{let C=++r.current;n(S=>[...S,{id:C,type:"confirm",content:u,okText:f?.okText??"OK",cancelText:f?.cancelText??"Cancel",style:f?.style,buttonStyle:f?.buttonStyle,okButtonStyle:f?.okButtonStyle,cancelButtonStyle:f?.cancelButtonStyle,focusedButtonStyle:f?.focusedButtonStyle,backdropStyle:f?.backdropStyle,resolve:m}]);}),[]),i=useCallback((u,f)=>{n(m=>{let C=m.find(S=>S.id===u);return C&&C.resolve(f),m.filter(S=>S.id!==u)});},[]),c={alert:o,confirm:s},l=t[t.length-1];return ne.createElement(fr.Provider,{value:c},e,l&&ne.createElement(us,{key:l.id,dialog:l,onDismiss:i}))}function us({dialog:e,onDismiss:t}){let n=useContext(q),r=useRef(null),o=useRef(null),s=useRef(null),i=useRef(null),[c,l]=useState("ok"),[u,f]=useState(0);useEffect(()=>{if(!n||u===0)return;let 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(v=>v())},[n,u]),useEffect(()=>{if(n)return n.onFocusChange(g=>{g===s.current?l("ok"):g===i.current&&l("cancel");})},[n]),Ue(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",C=m?e.content.length:0,k={minWidth:Math.max(20,m?Math.min(C+6,50):30),maxWidth:50,bg:"black",border:"round",borderColor:"white",padding:1,flexDirection:"column",gap:1,...e.style},h=(g,v)=>{let R={paddingX:2,bg:"blackBright",color:"white"},M={bg:"white",color:"black",bold:true},H=g==="ok"?e.okButtonStyle:e.cancelButtonStyle;return {...R,...e.buttonStyle,...H,...v?{...M,...e.focusedButtonStyle}:{}}},p={position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:999,...e.backdropStyle};return ne.createElement(Lt,{trap:true},ne.createElement("box",{style:p}),ne.createElement("box",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,justifyContent:"center",alignItems:"center",zIndex:1e3}},ne.createElement("box",{style:k},ne.createElement("box",{style:{flexDirection:"column"}},typeof e.content=="string"?ne.createElement("text",null,e.content):e.content),ne.createElement("box",{style:{flexDirection:"row",justifyContent:"flex-end",gap:1}},e.type==="confirm"&&ne.createElement("box",{style:h("cancel",c==="cancel"),focusable:true,ref:g=>{g&&g.focusId&&!i.current&&(o.current=g,i.current=g.focusId,f(v=>v+1));}},ne.createElement("text",null,e.cancelText)),ne.createElement("box",{style:h("ok",c==="ok"),focusable:true,ref:g=>{g&&g.focusId&&!s.current&&(r.current=g,s.current=g.focusId,f(v=>v+1));}},ne.createElement("text",null,e.okText))))))}function ds(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 ms({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):()=>{},[u,f]=useState(false),[m,C]=useState(""),[S,k]=useState([]),h=useContext(Y),p=useContext(q),g=useContext(ie);useEffect(()=>{l("Mounted, inputCtx:",!!h,"focusCtx:",!!p,"enabled:",i);},[]);let R=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),M=useCallback(()=>{if(!p?.getActiveElements){l("refreshElements: no getActiveElements");return}let I=p.getActiveElements();l("getActiveElements returned",I.length,"elements");let x=I.map(({id:w,node:y})=>({id:w,node:y,layout:g?.getLayout(y)??y.layout}));x.sort((w,y)=>w.layout.y!==y.layout.y?w.layout.y-y.layout.y:w.layout.x-y.layout.x),k(x);},[p,g,l]),H=useRef(false);useEffect(()=>{u&&!H.current&&(l("Activated! Refreshing elements..."),M()),H.current=u;},[u,M,l]);let P=S.filter(I=>I.layout.width>0&&I.layout.height>0),B=ds(P.length,s),G=useMemo(()=>{let I=new Map;return P.forEach((x,w)=>{B[w]&&I.set(B[w],x.id);}),I},[P,B]);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===R.name,y=!!x.ctrl===R.ctrl,O=!!x.alt===R.alt,z=!!x.shift===R.shift,V=!!x.meta===R.meta;if(!u&&w&&y&&O&&z&&V)return l("Activation key matched! Activating..."),f(true),C(""),true;if(u){if(x.name==="escape")return l("Escape pressed, deactivating"),f(false),C(""),true;if(x.name==="backspace")return C(""),true;if(x.sequence&&x.sequence.length===1&&/[a-z]/i.test(x.sequence)){let j=m+x.sequence.toLowerCase();l("Buffer:",j);let U=G.get(j);return U?(l("Jumping to",U),p?.requestFocus(U),f(false),C(""),true):[...G.keys()].some(D=>D.startsWith(j))?(C(j),true):(C(""),true)}return true}return false};return h.subscribePriority(I)},[h,i,u,R,m,G,p,t,l]);let A=u?ne.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:99998}},...P.map((I,x)=>{let w=B[x];if(!w)return null;let{x:y,y:O}=I.layout,z=w.startsWith(m)&&m.length>0;return ne.createElement("box",{key:I.id,style:{position:"absolute",top:O,left:Math.max(0,y-w.length-2),bg:z?"cyan":r,color:o,paddingX:1,zIndex:99999,...n}},ne.createElement("text",{style:{bold:true,color:o}},w))}),ne.createElement("box",{style:{position:"absolute",bottom:0,left:0,right:0,bg:"blackBright",paddingX:1,zIndex:99999}},ne.createElement("text",{style:{color:"white"}},m?`Jump: ${m}_`:"Press a key to jump \u2022 ESC to cancel"))):null;return ne.createElement(ne.Fragment,null,e,A)}var Ae=join(tmpdir(),"glyph-image-cache");function bt(e){return e.startsWith("http://")||e.startsWith("https://")}function xs(e,t){let n=createHash("md5").update(e).digest("hex"),r=t?Cs(t):bs(e)||".png";return join(Ae,`${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 Cs(e){switch(e){case "png":return ".png";case "jpeg":return ".jpeg";case "gif":return ".gif";case "webp":return ".webp";default:return ".png"}}function sn(e){if(bt(e))try{let t=new URL(e),n=t.pathname;return basename(n)||t.hostname}catch{return "remote-image"}return basename(e)}function hr(){existsSync(Ae)||mkdirSync(Ae,{recursive:true});}async function gr(e){let t=sn(e);return bt(e)?Is(e,t):Ss(e,t)}async function Ss(e,t){if(!existsSync(e))throw new Error(`Image not found: ${e}`);return {data:readFileSync(e),name:t,localPath:e,isRemote:false}}async function Is(e,t){hr();let n=createHash("md5").update(e).digest("hex"),r=[".png",".jpeg",".gif",".webp"];for(let u of r){let f=join(Ae,`${n}${u}`);if(existsSync(f))return {data:readFileSync(f),name:t,localPath:f,isRemote:true}}let o=await fetch(e);if(!o.ok)throw new Error(`Failed to download image: ${o.status} ${o.statusText}`);let s=await o.arrayBuffer(),i=Buffer.from(s);if(!ws(i))throw new Error(`Invalid image data from: ${e}`);let c=Ct(i),l=xs(e,c);return writeFileSync(l,i),{data:i,name:t,localPath:l,isRemote:true}}function ws(e){return e.length<4?false:e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71||e[0]===255&&e[1]===216&&e[2]===255||e[0]===71&&e[1]===73&&e[2]===70||e[0]===66&&e[1]===77||e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e.length>=12&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80||e[0]===0&&e[1]===0&&e[2]===1&&e[3]===0}function Ct(e){return e.length<4?"unknown":e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"png":e[0]===255&&e[1]===216&&e[2]===255?"jpeg":e[0]===71&&e[1]===73&&e[2]===70?"gif":e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e.length>=12&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80?"webp":"unknown"}function yr(e,t){let n=Ct(e);if(n==="png")return e;hr();let r=createHash("md5").update(e).digest("hex"),o=join(Ae,`${r}.${n}`),s=join(Ae,`${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 Rs(){let e=platform();return e==="darwin"?"quicklook":e==="linux"||e==="win32"?"open":"none"}async function ln(e){switch(Rs()){case "quicklook":return Ts(e);case "open":return Ps(e);case "none":throw new Error("No preview method available on this platform")}}function Ts(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(()=>{ks();},50),r.on("close",o=>{t();});})}function ks(){exec(`osascript -e '
|
|
1
|
+
import ne,{createContext,forwardRef,useContext,useRef,useState,useEffect,useLayoutEffect,useMemo,useCallback}from'react';import Pr from'react-reconciler';import Se from'string-width';import jn,{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 kr=0;function un(){return `glyph-focus-${kr++}`}function fn(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?un():null,hidden:false}}function It(e,t){t.parent=e,e.children.push(t),e.allChildren.push(t);}function wt(e,t){t.parent=e,e.rawTextChildren.push(t),e.allChildren.push(t),e.text=e.rawTextChildren.map(n=>n.text).join("");}function pn(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 dn(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 mn(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 hn(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 st(e){let t={},n=e;for(;n;){let r=n.style;t.color===void 0&&r.color!==void 0&&(t.color=r.color),t.bg===void 0&&r.bg!==void 0&&(t.bg=r.bg),t.bold===void 0&&r.bold!==void 0&&(t.bold=r.bold),t.dim===void 0&&r.dim!==void 0&&(t.dim=r.dim),t.italic===void 0&&r.italic!==void 0&&(t.italic=r.italic),t.underline===void 0&&r.underline!==void 0&&(t.underline=r.underline),n=n.parent;}return t}function vt(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(...vt(o,r));return n}var Rt=32,gn={supportsMutation:true,supportsPersistence:false,supportsHydration:false,isPrimaryRenderer:true,scheduleTimeout:setTimeout,cancelTimeout:clearTimeout,noTimeout:-1,supportsMicrotasks:true,scheduleMicrotask:queueMicrotask,getCurrentUpdatePriority:()=>Rt,setCurrentUpdatePriority:e=>{},resolveUpdatePriority:()=>Rt,getCurrentEventPriority:()=>Rt,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 fn(e,t)},createTextInstance(e,t,n,r){return {type:"raw-text",text:e,parent:null}},appendInitialChild(e,t){t.type==="raw-text"?wt(e,t):It(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"?wt(e,t):It(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")hn(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 mn(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"?dn(e,t):pn(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 $e=Pr(gn);$e.injectIntoDevTools({bundleType:process.env.NODE_ENV==="production"?0:1,version:"0.1.0",rendererPackageName:"glyph"});var it=class{stdout;stdin;wasRaw=false;cleanedUp=false;dataHandlers=new Set;stdinAttached=false;oscState="normal";oscAccum="";escFlushTimer=null;palette=new Map;paletteResolve=null;constructor(t=process.stdout,n=process.stdin){this.stdout=t,this.stdin=n;}get columns(){return this.stdout.columns||80}get rows(){return this.stdout.rows||24}enterRawMode(){this.stdin.isTTY&&(this.wasRaw=this.stdin.isRaw,this.stdin.setRawMode(true),this.stdin.resume(),this.stdin.setEncoding("utf-8"));}exitRawMode(){this.stdin.isTTY&&!this.wasRaw&&(this.stdin.setRawMode(false),this.stdin.pause());}write(t){this.stdout.write(t);}hideCursor(){this.write("\x1B[?25l");}showCursor(){this.write("\x1B[?25h");}moveCursor(t,n){this.write(`\x1B[${n+1};${t+1}H`);}setCursorColor(t){this.write(`\x1B]12;${t}\x07`);}resetCursorColor(){this.write("\x1B]112\x07");}enterAltScreen(){this.write("\x1B[?1049h");}exitAltScreen(){this.write("\x1B[?1049l");}clearScreen(){this.write("\x1B[2J\x1B[H");}resetStyles(){this.write("\x1B[0m");}enableKittyKeyboard(){this.write("\x1B[>1u");}disableKittyKeyboard(){this.write("\x1B[<u");}setup(){this.enterRawMode(),this.enterAltScreen(),this.enableKittyKeyboard(),this.hideCursor(),this.clearScreen(),this.attachStdinListener(),this.installCleanupHandlers();}cleanup(){this.cleanedUp||(this.cleanedUp=true,this.escFlushTimer!==null&&(clearTimeout(this.escFlushTimer),this.escFlushTimer=null),this.resetStyles(),this.resetCursorColor(),this.disableKittyKeyboard(),this.showCursor(),this.exitAltScreen(),this.exitRawMode());}suspend(){this.escFlushTimer!==null&&(clearTimeout(this.escFlushTimer),this.escFlushTimer=null),this.oscState="normal",this.oscAccum="",this.resetStyles(),this.resetCursorColor(),this.disableKittyKeyboard(),this.showCursor(),this.exitAltScreen(),this.exitRawMode();}resume(){this.enterRawMode(),this.enterAltScreen(),this.enableKittyKeyboard(),this.hideCursor(),this.clearScreen();}attachStdinListener(){this.stdinAttached||(this.stdinAttached=true,this.stdin.on("data",t=>{let n=typeof t=="string"?t:t.toString("utf-8");this.dispatchFiltered(n);}));}onData(t){return this.dataHandlers.add(t),()=>{this.dataHandlers.delete(t);}}dispatchFiltered(t){this.escFlushTimer!==null&&(clearTimeout(this.escFlushTimer),this.escFlushTimer=null);let n=this.filterOsc(t);if(n.length>0)for(let r of this.dataHandlers)r(n);this.oscState==="esc"&&(this.escFlushTimer=setTimeout(()=>{this.escFlushTimer=null,this.oscState="normal";for(let r of this.dataHandlers)r("\x1B");},50));}filterOsc(t){let n="";for(let r=0;r<t.length;r++){let o=t[r],s=t.charCodeAt(r);switch(this.oscState){case "normal":s===27?this.oscState="esc":n+=o;break;case "esc":o==="]"?(this.oscState="osc",this.oscAccum=""):(n+="\x1B"+o,this.oscState="normal");break;case "osc":s===7?(this.handleOscResponse(this.oscAccum),this.oscAccum="",this.oscState="normal"):s===27?this.oscState="osc_esc":this.oscAccum+=o;break;case "osc_esc":o==="\\"?(this.handleOscResponse(this.oscAccum),this.oscAccum="",this.oscState="normal"):(this.oscAccum+="\x1B"+o,this.oscState="osc");break}}return n}handleOscResponse(t){let n=t.match(/^4;(\d+);rgb:([0-9a-fA-F]+)\/([0-9a-fA-F]+)\/([0-9a-fA-F]+)/);if(n){let r=parseInt(n[1],10),o=parseInt(n[2].substring(0,2),16),s=parseInt(n[3].substring(0,2),16),i=parseInt(n[4].substring(0,2),16);this.palette.set(r,[o,s,i]),this.palette.size>=16&&this.paletteResolve&&(this.paletteResolve(),this.paletteResolve=null);}}queryPalette(){return new Promise(t=>{let n=()=>t(this.palette),r=setTimeout(n,200);this.paletteResolve=()=>{clearTimeout(r),n();};let o="";for(let s=0;s<16;s++)o+=`\x1B]4;${s};?\x07`;this.write(o);})}onResize(t){return this.stdout.on("resize",t),()=>{this.stdout.off("resize",t);}}installCleanupHandlers(){let t=()=>this.cleanup();process.on("exit",t);let n=r=>{t(),process.kill(process.pid,r);};process.once("SIGINT",()=>n("SIGINT")),process.once("SIGTERM",()=>n("SIGTERM")),process.on("uncaughtException",r=>{t(),console.error(r),process.exit(1);}),process.on("unhandledRejection",r=>{t(),console.error(r),process.exit(1);});}};function yn(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 Er(e){switch(e.split(";")[0]){case "1":return "home";case "2":return "insert";case "3":return "delete";case "4":return "end";case "5":return "pageup";case "6":return "pagedown";case "7":return "home";case "8":return "end";case "11":return "f1";case "12":return "f2";case "13":return "f3";case "14":return "f4";case "15":return "f5";case "17":return "f6";case "18":return "f7";case "19":return "f8";case "20":return "f9";case "21":return "f10";case "23":return "f11";case "24":return "f12";case "25":return "f13";case "26":return "f14";case "28":return "f15";case "29":return "f16";case "31":return "f17";case "32":return "f18";case "33":return "f19";case "34":return "f20";default:return "unknown"}}function lt(e,t){let n=t-1;n&1&&(e.shift=true),n&2&&(e.alt=true),n&4&&(e.ctrl=true),n&8&&(e.meta=true);}function xn(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=Gr(e,n);if(s){t.push(s.key),n=s.end;continue}}if(e[n+1]==="O"){let s=Nr(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 Nr(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 Gr(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:yn(f),sequence:s},lt(i,l);break}if(i={name:Er(r),sequence:s},r.includes(";")){let c=r.split(";"),l=parseInt(c[1]??"1",10);lt(i,l);}break}case "u":{let c=r.split(";"),l=parseInt(c[0]??"0",10),f=parseInt(c[1]??"1",10);i={name:yn(l),sequence:s},lt(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&<(i,l);}return {key:i,end:n}}var Br={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"},Fr={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 Tt(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 bn(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=Tt(e);return `\x1B[38;2;${o};${s};${i}m`}return Br[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 Cn(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=Tt(e);return `\x1B[48;2;${o};${s};${i}m`}return Fr[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 Sn={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]},In=["black","red","green","yellow","blue","magenta","cyan","white","blackBright","redBright","greenBright","yellowBright","blueBright","magentaBright","cyanBright","whiteBright"],Oe=null;function wn(e){e.size>0&&(Oe=e);}function Lr(e){if(Oe){let t=In.indexOf(e);if(t!==-1){let n=Oe.get(t);if(n)return n}}return Sn[e]??null}function Mr(e){if(typeof e=="string"){if(e.startsWith("#")){let t=Tt(e);return [t.r,t.g,t.b]}return Lr(e)}if(typeof e=="number"){if(e<16){if(Oe){let s=Oe.get(e);if(s)return s}return Sn[In[e]]}if(e>=232){let s=(e-232)*10+8;return [s,s,s]}let t=e-16,n=t%6*51,r=Math.floor(t/6)%6*51;return [Math.floor(t/36)*51,r,n]}return [e.r,e.g,e.b]}function ct(e){let t=Mr(e);if(!t)return false;let[n,r,o]=t.map(i=>{let c=i/255;return c<=.03928?c/12.92:Math.pow((c+.055)/1.055,2.4)});return .2126*n+.7152*r+.0722*o>.4}function kt(e,t){return e===t?true:e==null||t==null?false:typeof e=="object"&&typeof t=="object"?e.r===t.r&&e.g===t.g&&e.b===t.b:false}function vn(e){return e&&ct(e)?"black":"white"}var Ve=class e{width;height;cells;constructor(t,n){this.width=t,this.height=n,this.cells=new Array(t*n),this.clear();}clear(){for(let t=0;t<this.cells.length;t++)this.cells[t]={ch:" "};}resize(t,n){this.width=t,this.height=n,this.cells=new Array(t*n),this.clear();}get(t,n){if(!(t<0||t>=this.width||n<0||n>=this.height))return this.cells[n*this.width+t]}set(t,n,r){t<0||t>=this.width||n<0||n>=this.height||(this.cells[n*this.width+t]=r);}setChar(t,n,r,o,s,i,c,l,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&&kt(t.fg,n.fg)&&kt(t.bg,n.bg)&&(t.bold??false)===(n.bold??false)&&(t.dim??false)===(n.dim??false)&&(t.italic??false)===(n.italic??false)&&(t.underline??false)===(n.underline??false)}};var Ar={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 Rn(e){return e==="none"?null:Ar[e]}function Tn(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=Se(f);p>l&&(l=p);}return {width:l,height:o.length}}let s=Math.max(1,Math.floor(t)),i=ge(o,s,r),c=0;for(let l of i){let f=Se(l);f>c&&(c=f);}return {width:c,height:i.length}}function ge(e,t,n){let r=[];for(let o of e){if(Se(o)<=t){r.push(o);continue}if(n==="truncate"){r.push(kn(o,t));continue}if(n==="ellipsis"){r.push(Hr(o,t));continue}let i=$r(o,t);r.push(...i);}return r}function kn(e,t){let n="",r=0;for(let o of e){let s=Se(o);if(r+s>t)break;n+=o,r+=s;}return n}function Hr(e,t){if(t<=1)return t===1?"\u2026":"";let n=kn(e,t-1);return Se(n)<Se(e)?n+"\u2026":e}function $r(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 C=Se(m);o+C>t&&r.length>0&&(n.push(r),r="",o=0),r+=m,o+=C;}s="",i=0;}p&&(o+1<=t?(r+=" ",o+=1):(r.length>0&&n.push(r),r=" ",o=1));}else l&&(s+=l,i+=Se(l));}return r.length>0&&n.push(r),n.length>0?n:[""]}var Pn={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"},En={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 Or(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:Pn[r]?t.fg=Pn[r]:En[r]&&(t.bg=En[r]);break}n++;}}function Pt(e){let t=[],n={},r="",o=/\x1b\[([0-9;]*)m/g,s=0,i;for(;(i=o.exec(e))!==null;){let l=e.slice(s,i.index);l&&(r+=l),r&&(t.push({text:r,style:{...n}}),r="");let p=(i[1]||"0").split(";").map(m=>parseInt(m,10)||0);Or(p,n),s=o.lastIndex;}let c=e.slice(s);return c&&(r+=c),r&&t.push({text:r,style:{...n}}),t}function Vr(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function Nn(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||Gn(i,s,i.style.zIndex??0,o);o.sort((i,c)=>i.zIndex-c.zIndex);for(let i of o){let c=Kr(i.node,t,i.clip,n);c?.cursorPosition&&(r.cursorPosition=c.cursorPosition);}return r}function Gn(e,t,n,r){if(e.hidden)return;let o=e.style.zIndex??n,s=e.style.clip?Dr(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)Gn(i,s,o,r);}function Dr(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),o=Math.min(e.x+e.width,t.x+t.width),s=Math.min(e.y+e.height,t.y+t.height);return {x:n,y:r,width:Math.max(0,o-n),height:Math.max(0,s-r)}}function at(e,t,n){return e>=n.x&&e<n.x+n.width&&t>=n.y&&t<n.y+n.height}function Kr(e,t,n,r={}){let{x:o,y:s,width:i,height:c,innerX:l,innerY:f,innerWidth:p,innerHeight:m}=e.layout,C=e.style;if(i<=0||c<=0)return;let P=st(e).bg;if(C.bg)for(let d=s;d<s+c;d++)for(let y=o;y<o+i;y++)at(y,d,n)&&t.setChar(y,d," ",void 0,C.bg);let h=C.border?Rn(C.border):null;if(h&&i>=2&&c>=2){let d=C.borderColor,y=P;de(t,n,o,s,h.topLeft,d,y);for(let v=o+1;v<o+i-1;v++)de(t,n,v,s,h.horizontal,d,y);de(t,n,o+i-1,s,h.topRight,d,y),de(t,n,o,s+c-1,h.bottomLeft,d,y);for(let v=o+1;v<o+i-1;v++)de(t,n,v,s+c-1,h.horizontal,d,y);de(t,n,o+i-1,s+c-1,h.bottomRight,d,y);for(let v=s+1;v<s+c-1;v++)de(t,n,o,v,h.vertical,d,y),de(t,n,o+i-1,v,h.vertical,d,y);}if(e.type==="text")Wr(e,t,n);else if(e.type==="input")return _r(e,t,n,r)}function de(e,t,n,r,o,s,i,c,l,f,p){at(n,r,t)&&e.setChar(n,r,o,s,i,c,l,f,p);}function Bn(e,t){if(e!==void 0)return e;if(t!==void 0)return ct(t)?"black":"white"}function Wr(e,t,n){let{innerX:r,innerY:o,innerWidth:s,innerHeight:i}=e.layout,c=st(e),l=vt(e,c);if(l.length===0)return;let f=e.style.wrap??"wrap",p=e.style.textAlign??"left",m=[],C=[];for(let d of l){let y=Pt(d.text);for(let v of y)for(let R of v.text)if(R===`
|
|
3
|
+
`)C.push(m.length);else {let M={color:v.style.fg??d.style.color,bg:v.style.bg??d.style.bg,bold:v.style.bold??d.style.bold,dim:v.style.dim??d.style.dim,italic:v.style.italic??d.style.italic,underline:v.style.underline??d.style.underline};m.push({char:R,style:M});}}let S=[],P=0;for(let d of C)S.push(m.slice(P,d)),P=d;S.push(m.slice(P));let h=[];for(let d of S){if(d.length===0){h.push([]);continue}let y=d.map(M=>M.char).join(""),v=ge([y],s,f),R=0;for(let M of v){let A=[];for(let E of M)R<d.length&&(A.push(d[R]),R++);h.push(A);}}for(let d=0;d<h.length&&d<i;d++){let y=h[d],v=y.reduce((A,E)=>A+Se(E.char),0),R=0;p==="center"?R=Math.max(0,Math.floor((s-v)/2)):p==="right"&&(R=Math.max(0,s-v));let M=0;for(let{char:A,style:E}of y){let L=Se(A);if(L>0){let N=Bn(E.color,E.bg);de(t,n,r+R+M,o+d,A,N,E.bg,E.bold,E.dim,E.italic,E.underline);}M+=L;}}}function _r(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??"",C=p||m,S=!p&&!!m,P=e.props.multiline??false,h=st(e),d=Bn(h.color,h.bg),y=h.bg?ct(h.bg)?"blackBright":"whiteBright":"blackBright",v=S?y:d??h.color??e.style.color,R=S?y:v,M=S?true:h.dim,A=o&&o.nodeId===e.focusId,E;if(P&&!S){let L=e.style.wrap??"wrap",N=C.split(`
|
|
4
|
+
`),j=ge(N,l,L),b=0,x=0;if(A){let g=o.position,O=0,U=g,V=0;for(let K=0;K<N.length;K++){let H=N[K].length;if(g<=V+H){O=K,U=g-V;break}V+=H+1;}let $=0;for(let K=0;K<O;K++)$+=ge([N[K]],l,L).length;let q=ge([N[O]],l,L),z=0,D=0;for(let K=0;K<q.length;K++){let H=q[K];if(U<=z+H.length){D=K;break}z+=H.length;}b=$+D,x=Se(N[O].slice(z,z+(U-z)));}let I=Math.max(0,b-f+1);for(let g=0;g<f;g++){let O=I+g;if(O>=j.length)break;let U=j[O],V=0;for(let $ of U){if(V>=l)break;let q=Se($);q>0&&de(t,n,i+V,c+g,$,R,h.bg,h.bold,M,h.italic,h.underline),V+=q;}}if(A){let g=b-I;if(g>=0&&g<f){let O=Math.min(x,l-1),U=i+O,V=c+g;if(at(U,V,n)&&U<i+l)if(s)E={cursorPosition:{x:U,y:V,bg:h.bg}};else {let $=t.get(U,V),q=$?.ch&&$.ch!==" "?$.ch:"\u258C",z=h.bg??"black",D=h.color??"white";t.setChar(U,V,q,z,D,$?.bold,$?.dim,$?.italic,false);}}}}else {let L=0;for(let N of C){if(L>=l)break;let j=Se(N);j>0&&de(t,n,i+L,c,N,R,h.bg,h.bold,M,h.italic,h.underline),L+=j;}if(A){let N=Math.min(o.position,l-1),j=i+N;if(at(j,c,n)&&j<i+l)if(s)E={cursorPosition:{x:j,y:c,bg:h.bg}};else {let b=t.get(j,c),x=b?.ch&&b.ch!==" "?b.ch:"\u258C",I=h.bg??"black",g=h.color??"white";t.setChar(j,c,x,I,g,b?.bold,b?.dim,b?.italic,false);}}}return E}var qr="\x1B",ke=`${qr}[`;function zr(e,t){return `${ke}${t+1};${e+1}H`}function Xr(e){let t=`${ke}0m`;return e.bold&&(t+=`${ke}1m`),e.dim&&(t+=`${ke}2m`),e.italic&&(t+=`${ke}3m`),e.underline&&(t+=`${ke}4m`),e.fg!=null&&(t+=bn(e.fg)),e.bg!=null&&(t+=Cn(e.bg)),t}function Fn(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+=zr(l,c));let p=Xr(f);p!==i&&(r+=p,i=p),r+=f.ch,o=l+1,s=c;}return r.length>0&&(r+=`${ke}0m`),r}var Qr={row:FlexDirection.Row,column:FlexDirection.Column},Zr={"flex-start":Justify.FlexStart,center:Justify.Center,"flex-end":Justify.FlexEnd,"space-between":Justify.SpaceBetween,"space-around":Justify.SpaceAround},eo={"flex-start":Align.FlexStart,center:Align.Center,"flex-end":Align.FlexEnd,stretch:Align.Stretch};function An(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%"),t(n));}function Ie(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%")?e.setPositionPercent(t,parseFloat(n)):e.setPosition(t,n));}function to(e,t,n){An(e,o=>e.setWidth(o),t.width),An(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(Qr[t.flexDirection]??FlexDirection.Column),t.flexWrap&&e.setFlexWrap(t.flexWrap==="wrap"?Wrap.Wrap:Wrap.NoWrap),t.justifyContent&&e.setJustifyContent(Zr[t.justifyContent]??Justify.FlexStart),t.alignItems&&e.setAlignItems(eo[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&&(Ie(e,Edge.Top,t.inset),Ie(e,Edge.Right,t.inset),Ie(e,Edge.Bottom,t.inset),Ie(e,Edge.Left,t.inset)),Ie(e,Edge.Top,t.top),Ie(e,Edge.Right,t.right),Ie(e,Edge.Bottom,t.bottom),Ie(e,Edge.Left,t.left),t.clip&&e.setOverflow(Overflow.Hidden);}function Hn(e){let t=jn.Node.create();if(e.yogaNode=t,to(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=$n(e),Tn(i,n,r,e.style.wrap??"wrap")});else for(let n=0;n<e.children.length;n++){let r=e.children[n];r.hidden||(Hn(r),t.insertChild(r.yogaNode,t.getChildCount()));}}function $n(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=$n(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 On(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),C=r.getComputedPadding(Edge.Bottom),S=r.getComputedPadding(Edge.Left),P=s+f+S,h=i+f+p,d=Math.max(0,c-f*2-S-m),y=Math.max(0,l-f*2-p-C),v=e.layout;(!v||v.x!==s||v.y!==i||v.width!==c||v.height!==l||v.innerX!==P||v.innerY!==h||v.innerWidth!==d||v.innerHeight!==y)&&(e.layout={x:s,y:i,width:c,height:l,innerX:P,innerY:h,innerWidth:d,innerHeight:y});for(let R of e.children)R.hidden||!R.yogaNode||On(R,s,i);}function Vn(e,t,n){let r=jn.Node.create();r.setWidth(t),r.setHeight(n),r.setFlexDirection(FlexDirection.Column);for(let o of e)o.hidden||(Hn(o),r.insertChild(o.yogaNode,r.getChildCount()));r.calculateLayout(t,n,Direction.LTR);for(let o of e)o.hidden||!o.yogaNode||On(o,0,0);r.freeRecursive(),Dn(e);}function Dn(e){for(let t of e)t.yogaNode=null,Dn(t.children);}var Y=createContext(null),X=createContext(null),ie=createContext(null),Be=createContext(null),Fe=createContext(null),ft=createContext(null);var ee=null;function We(e=false){if(ee)return ee;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"?(ee={name:"kitty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},ee):o||t.includes("ghostty")?(ee={name:"ghostty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},ee):s||n==="WezTerm"?(ee={name:"wezterm",supportsKittyGraphics:true,supportsIterm2Images:true,supportsSixel:true},ee):n==="iTerm.app"||i==="iTerm2"?(ee={name:"iterm2",supportsKittyGraphics:false,supportsIterm2Images:true,supportsSixel:false},ee):c?(ee={name:"konsole",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:true},ee):n==="vscode"?(ee={name:"vscode",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},ee):(ee={name:"unknown",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},ee)}function Et(){let e=We();return e.supportsKittyGraphics||e.supportsIterm2Images||e.supportsSixel}var te="\x1B";function pt(){return !!process.env.TMUX}function Nt(e){if(!pt())return e;let t=e.replace(/\x1b/g,"\x1B\x1B");return `${te}Ptmux;${t}${te}\\`}function Kn(e){let t=We();return t.supportsKittyGraphics?no(e):t.supportsIterm2Images?ro(e):null}function Gt(e){if(We().supportsKittyGraphics){let n;return e!==void 0?n=`${te}_Ga=d,d=i,i=${e}${te}\\`:n=`${te}_Ga=d,d=a${te}\\`,Nt(n)}return null}function no(e){let{data:t,width:n,height:r,x:o,y:s,id:i}=e,c=t.toString("base64"),l=`${te}[${s+1};${o+1}H`,f=Bt(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,C=[l];pt()&&C.unshift(`${te}[?25l`);for(let S=0;S<c.length;S+=m){let P=c.slice(S,S+m),d=S+m>=c.length?"m=0":"m=1",y;S===0?y=`${te}_G${p},${d},q=2;${P}${te}\\`:y=`${te}_G${d};${P}${te}\\`,C.push(Nt(y));}return pt()&&C.push(`${te}[?25h`),C.join("")}function ro(e){let{data:t,width:n,height:r,x:o,y:s}=e,i=t.toString("base64"),c=`${te}[${s+1};${o+1}H`,l=[`width=${n}`,`height=${r}`,"preserveAspectRatio=1","inline=1"].join(";"),f=`${te}]1337;File=${l}:${i}\x07`;return c+(pt()?Nt(f):f)}function Bt(e){if(e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e.length>=24){let t=e.readUInt32BE(16),n=e.readUInt32BE(20);return {width:t,height:n}}if(e[0]===255&&e[1]===216&&e[2]===255){let t=2;for(;t<e.length-8;){if(e[t]!==255){t++;continue}let n=e[t+1];if(n!==void 0&&(n>=192&&n<=195||n>=197&&n<=199||n>=201&&n<=203||n>=205&&n<=207)){let o=e.readUInt16BE(t+5);return {width:e.readUInt16BE(t+7),height:o}}let r=e.readUInt16BE(t+2);t+=2+r;}}if(e[0]===71&&e[1]===73&&e[2]===70&&e.length>=10){let t=e.readUInt16LE(6),n=e.readUInt16LE(8);return {width:t,height:n}}return null}function oo(e,t={}){let n=t.stdout??process.stdout,r=t.stdin??process.stdin,o=t.debug??false,s=t.useNativeCursor??true,i=new it(n,r);i.setup();let c=false;i.queryPalette().then(a=>{wn(a),p=true,q();});let l=new Ve(i.columns,i.rows),f=new Ve(i.columns,i.rows),p=true,m=new Set,C=new Set,S=new Map,P={subscribe(a){return m.add(a),()=>m.delete(a)},subscribePriority(a){return C.add(a),()=>C.delete(a)},registerInputHandler(a,T){return S.set(a,T),()=>S.delete(a)}},h=new Map,d=new Map,y={registerImage(a){let T=h.get(a.id);(!T||T.x!==a.x||T.y!==a.y||T.width!==a.width||T.height!==a.height)&&(d.set(a.id,a),q());},unregisterImage(a){h.delete(a),d.delete(a);let T=Gt(a);T&&i.write(T),q();}};function v(){for(let a of d.values()){let T=Kn({data:a.data,width:a.width,height:a.height,x:a.x,y:a.y,id:a.id});T&&(i.write(T),h.set(a.id,{x:a.x,y:a.y,width:a.width,height:a.height}));}d.clear();}let R=null,M=new Map,A=[],E=new Set,L=new Set,N=[],j=new Set;function b(a){if(R!==a){R=a,q();for(let T of j)T(R);}}function x(){let a=[...A];if(N.length>0){let T=N[N.length-1];a=a.filter(k=>T.has(k));}return a=a.filter(T=>!E.has(T)),a.sort((T,k)=>{let u=M.get(T),F=M.get(k);if(!u||!F)return 0;let w=u.layout,W=F.layout;return w.y!==W.y?w.y-W.y:w.x-W.x}),a}let I={get focusedId(){return R},register(a,T,k=true){if(M.set(a,T),A.includes(a)||A.push(a),k||L.add(a),N.length>0&&N[N.length-1].add(a),R===null&&k){let u=x().filter(F=>!L.has(F));u.length>0&&b(u[0]);}return ()=>{M.delete(a),L.delete(a);let u=A.indexOf(a);if(u!==-1&&A.splice(u,1),R===a){let F=x().filter(w=>!L.has(w));b(F[0]??null);}}},requestFocus(a){b(a);},blur(){b(null);},focusNext(){let a=x();if(a.length===0)return;let k=((R?a.indexOf(R):-1)+1)%a.length;b(a[k]);},focusPrev(){let a=x();if(a.length===0)return;let k=((R?a.indexOf(R):0)-1+a.length)%a.length;b(a[k]);},setSkippable(a,T){if(T){if(E.add(a),R===a){let k=x();k.length>0&&b(k[0]);}}else E.delete(a);},trapIds:null,pushTrap(a){return N.push(a),()=>{let T=N.indexOf(a);T!==-1&&N.splice(T,1);}},onFocusChange(a){return j.add(a),()=>{j.delete(a);}},getRegisteredElements(){let a=[];for(let T of A){if(E.has(T))continue;let k=M.get(T);k&&a.push({id:T,node:k});}return a},getActiveElements(){let a=x(),T=[];for(let k of a){if(E.has(k))continue;let u=M.get(k);u&&T.push({id:k,node:u});}return T}},g=new Map,O={getLayout(a){return a.layout},subscribe(a,T){return g.has(a)||g.set(a,new Set),g.get(a).add(T),()=>{let k=g.get(a);k&&(k.delete(T),k.size===0&&g.delete(a));}}},U={registerNode(){},unregisterNode(){},scheduleRender:q,exit(a){B.exit(a);},get columns(){return i.columns},get rows(){return i.rows}},V={type:"root",children:[],onCommit(){q();}},$=false;function q(){$||($=true,queueMicrotask(()=>{$=false,z();}));}function z(){let a=i.columns,T=i.rows;(f.width!==a||f.height!==T)&&(f.resize(a,T),l.resize(a,T),p=true),Vn(V.children,a,T),D(V.children);let k;if(R){let w=M.get(R);w?.type==="input"&&(k={nodeId:R,position:w.props.cursorPosition??w.props.value?.length??0});}let u=Nn(V.children,f,{cursorInfo:k,useNativeCursor:s}),F=Fn(l,f,p);if(F.length>0&&i.write(F),d.size>0&&c&&(i.hideCursor(),c=false),v(),s)if(u.cursorPosition){let w=vn(u.cursorPosition.bg);i.setCursorColor(w),i.moveCursor(u.cursorPosition.x,u.cursorPosition.y),c||(i.showCursor(),c=true);}else i.hideCursor(),c=false;for(let w=0;w<f.cells.length;w++)l.cells[w]={...f.cells[w]};p=false;}function D(a){for(let T of a){let k=g.get(T);if(k)for(let u of k)u(T.layout);D(T.children);}}let K=i.onData(a=>{let T=xn(a);for(let k of T){if(k.ctrl&&k.name==="c"){B.exit();return}if(k.ctrl&&k.name==="z"){i.suspend(),process.kill(0,"SIGSTOP");return}let u=false;for(let F of C)if(F(k)){u=true;break}if(!u&&R){let F=S.get(R);F&&(u=F(k));}if(!u&&k.name==="tab"&&!k.ctrl&&!k.alt){k.shift?I.focusPrev():I.focusNext();continue}if(!u)for(let F of m)F(k);}}),H=i.onResize(()=>{p=true,q();}),ce=()=>{i.resume(),p=true,q();};process.on("SIGCONT",ce);let me=ne.createElement(Be.Provider,{value:U},ne.createElement(Y.Provider,{value:P},ne.createElement(X.Provider,{value:I},ne.createElement(ie.Provider,{value:O},ne.createElement(ft.Provider,{value:y},e))))),J=a=>{o&&console.error("Uncaught error:",a);},re=a=>{o&&console.error("Error caught by boundary:",a);},Q=a=>{o&&console.error("Recoverable error:",a);},G=$e.createContainer(V,0,null,false,null,"",J,re,Q,null);$e.updateContainer(me,G,null,null);let B={unmount(){$e.updateContainer(null,G,null,null),K(),H(),process.off("SIGCONT",ce);let a=Gt();a&&i.write(a),i.cleanup();},exit(a){B.unmount(),process.exit(a??0);}};return B}var lo=forwardRef(function({children:t,style:n,focusable:r},o){return ne.createElement("box",{style:n,focusable:r,ref:o},t)});var ho=forwardRef(function({children:t,style:n,wrap:r,focusable:o,focusedStyle:s},i){let c=useContext(X),l=useRef(null),[f,p]=useState(false);useEffect(()=>{if(!c||!o||!l.current?.focusId)return;let S=l.current.focusId;return p(c.focusedId===S),c.onFocusChange(P=>{p(P===S);})},[c,o]);let m=r?{...n,wrap:r}:n;f&&s&&(m={...m,...s});let C=S=>{l.current=S,typeof i=="function"?i(S):i&&(i.current=S);};return ne.createElement("text",{style:m,focusable:o,ref:C},t)});function Wn(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=ge([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,C=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+=C;}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 _n(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=ge([p],r,"wrap"),C=0;for(let S of m)s.push({text:S,startOffset:i+C}),C+=S.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 ze(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 Xe(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 yo(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,[C,S]=useState(n),[P,h]=useState(n.length),[d,y]=useState(0),[v,R]=useState(false),[M,A]=useState(false),E=useContext(Y),L=useContext(X),N=useContext(ie),j=useRef(null),b=useRef(null),x=t!==void 0,I=x?t:C;useEffect(()=>{if(!N||!j.current)return;let D=N.getLayout(j.current);return y(D.innerWidth),N.subscribe(j.current,K=>{y(K.innerWidth);})},[N]);let g=useRef(I),O=useRef(P),U=useRef(I),V=useRef(P);useEffect(()=>{I!==U.current&&(g.current=I,U.current=I,O.current=I.length,V.current=I.length,h(I.length));},[I]),useEffect(()=>{P!==V.current&&(O.current=P,V.current=P);},[P]);let $=useRef({isControlled:x,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:f??false,innerWidth:d,type:m});$.current={isControlled:x,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:f??false,innerWidth:d,type:m},useEffect(()=>{if(!(!L||!b.current||!j.current))return L.register(b.current,j.current)},[L,M]);let q=useRef(false);useEffect(()=>{if(!M){q.current=false;return}if(p&&!q.current&&L&&b.current){q.current=true;let D=b.current,K=setTimeout(()=>{L.requestFocus(D);},0);return ()=>clearTimeout(K)}},[p,L,M]),useEffect(()=>{if(!L||!b.current)return;let D=b.current;return R(L.focusedId===D),L.onFocusChange(K=>{R(K===D);})},[L,M]),useEffect(()=>{if(!E||!b.current)return;let D=b.current,K=H=>{let{isControlled:ce,onChange:me,onKeyPress:J,onBeforeChange:re,multiline:Q}=$.current;if(J?.(H)===true)return true;let G=g.current,B=O.current;if(H.name==="escape")return false;let a=(u,F)=>{let w=u,W=F;if(re){let _=re(u,G);if(_===false)return;typeof _=="string"&&(w=_,W=_.length);}g.current=w,O.current=W,U.current=w,V.current=W,ce||S(w),me?.(w),h(W);},T=u=>{O.current=u,V.current=u,h(u);};if(H.name==="return"){if(Q){let u=G.slice(0,B)+`
|
|
8
|
+
`+G.slice(B);return a(u,B+1),true}return false}if(H.ctrl){if(H.name==="w"){if(B>0){let u=B;for(;u>0&&G[u-1]===" ";)u--;for(;u>0&&G[u-1]!==" "&&(!Q||G[u-1]!==`
|
|
9
|
+
`);)u--;let F=G.slice(0,u)+G.slice(B);a(F,u);}return true}if(H.name==="a"){if(Q){let{line:u,lines:F}=ze(G,B);T(Xe(F,u,0));}else T(0);return true}if(H.name==="e"){if(Q){let{line:u,lines:F}=ze(G,B);T(Xe(F,u,F[u].length));}else T(G.length);return true}if(H.name==="k"){if(Q){let{line:u,lines:F}=ze(G,B),w=Xe(F,u,F[u].length);if(B<w){let W=G.slice(0,B)+G.slice(w);a(W,B);}}else if(B<G.length){let u=G.slice(0,B);a(u,B);}return true}return false}if(H.alt){if(H.name==="left"||H.name==="b"){let u=B;for(;u>0&&G[u-1]===" ";)u--;for(;u>0&&G[u-1]!==" "&&G[u-1]!==`
|
|
10
|
+
`;)u--;return T(u),true}if(H.name==="right"||H.name==="f"){let u=B;for(;u<G.length&&G[u]!==" "&&G[u]!==`
|
|
11
|
+
`;)u++;for(;u<G.length&&G[u]===" ";)u++;return T(u),true}if(H.name==="backspace"||H.name==="d")if(H.name==="backspace"){if(B>0){let u=B;for(;u>0&&G[u-1]===" ";)u--;for(;u>0&&G[u-1]!==" "&&G[u-1]!==`
|
|
12
|
+
`;)u--;let F=G.slice(0,u)+G.slice(B);a(F,u);}return true}else {if(B<G.length){let u=B;for(;u<G.length&&G[u]!==" "&&G[u]!==`
|
|
13
|
+
`;)u++;for(;u<G.length&&G[u]===" ";)u++;let F=G.slice(0,B)+G.slice(u);a(F,B);}return true}return false}if(H.name==="left")return T(Math.max(0,B-1)),true;if(H.name==="right")return T(Math.min(G.length,B+1)),true;if(H.name==="up"){let{innerWidth:u}=$.current,F=Wn(G,B,u);return F.visualLine>0&&T(_n(G,F.visualLine-1,F.visualCol,u)),true}if(H.name==="down"){let{innerWidth:u}=$.current,F=Wn(G,B,u);return F.visualLine<F.totalVisualLines-1&&T(_n(G,F.visualLine+1,F.visualCol,u)),true}if(H.name==="home"){if(Q){let{line:u,lines:F}=ze(G,B);T(Xe(F,u,0));}else T(0);return true}if(H.name==="end"){if(Q){let{line:u,lines:F}=ze(G,B);T(Xe(F,u,F[u].length));}else T(G.length);return true}if(H.name==="backspace"){if(B>0){let u=G.slice(0,B-1)+G.slice(B);a(u,B-1);}return true}if(H.name==="delete"){if(B<G.length){let u=G.slice(0,B)+G.slice(B+1);a(u,B);}return true}if(H.name.length>1)return false;let k=H.sequence;if(k.length===1&&k.charCodeAt(0)>=32){let{type:u}=$.current;if(u==="number"){let w=/[0-9]/.test(k),W=k==="."&&!G.includes("."),_=k==="-"&&B===0&&!G.includes("-");if(!w&&!W&&!_)return true}let F=G.slice(0,B)+k+G.slice(B);return a(F,B+1),true}return false};return E.registerInputHandler(D,K)},[E,M]);let z={...c,...v&&l?l:{}};return ne.createElement("input",{style:z,value:I,defaultValue:n,placeholder:i,onChange:r,cursorPosition:O.current,multiline:f??false,focused:v,ref:D=>{D?(j.current=D,b.current=D.focusId,A(true)):(j.current=null,b.current=null,A(false));}})}function Lt({trap:e=false,children:t}){let n=useContext(X),r=useRef(null),o=useRef(new Set);return useLayoutEffect(()=>{if(!e||!n)return;r.current=n.focusedId;let s=n.pushTrap(o.current);return ()=>{s(),r.current&&n.requestFocus(r.current);}},[e,n]),useEffect(()=>{if(!(!e||!n)&&o.current.size>0){let s=o.current.values().next().value;s&&n.requestFocus(s);}},[e,n]),ne.createElement(ne.Fragment,null,t)}function Io({size:e}){return ne.createElement("box",{style:{flexGrow:e??1}})}function Jn(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 Yn(e,t){return !(t.name!==e.name||e.ctrl!==!!t.ctrl||e.alt!==!!t.alt||e.shift!==!!t.shift||e.meta!==!!t.meta)}function vo({keypress:e,onPress:t,whenFocused:n,priority:r,disabled:o}){let s=useContext(Y),i=useContext(X),c=useRef(t);c.current=t;let l=useRef(Jn(e));return l.current=Jn(e),useEffect(()=>{if(!(!s||o))if(r){let f=p=>!Yn(l.current,p)||n&&i?.focusedId!==n?false:(c.current(),true);return s.subscribePriority(f)}else {let f=p=>{Yn(l.current,p)&&(n&&i?.focusedId!==n||c.current());};return s.subscribe(f)}},[s,i,n,r,o]),null}function To({children:e,zIndex:t=1e3}){return ne.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:t}},e)}function Po({onPress:e,style:t,focusedStyle:n,children:r,disabled:o}){let s=useContext(X),i=useContext(Y),c=useRef(null),l=useRef(null),f=useRef(e);f.current=e;let[p,m]=useState(false),[C,S]=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 S(s.focusedId===h),s.onFocusChange(d=>{S(d===h);})},[s,p]),useEffect(()=>{if(!i||!l.current||o)return;let h=l.current,d=y=>s?.focusedId!==h?false:y.name==="return"||y.name===" "||y.sequence===" "?(f.current?.(),true):false;return i.registerInputHandler(h,d)},[i,s,o,p]);let P={...t,...C&&n?n:{}};return ne.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 Bo={x:0,y:0,width:0,height:0,innerX:0,innerY:0,innerWidth:0,innerHeight:0};function ve(e){let t=useContext(ie),[n,r]=useState(Bo);return useEffect(()=>{if(!(!t||!e?.current))return r(t.getLayout(e.current)),t.subscribe(e.current,r)},[t,e]),n}function Ue(e,t=[]){let n=useContext(Y);useEffect(()=>{if(n)return n.subscribe(e)},[n,...t]);}function jo({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}){let m=n!==void 0,[C,S]=useState(o),P=m?n:C,h=useRef(null),d=useRef(null),y=ve(h),v=ve(d),R=useContext(X),M=useContext(ie),A=useRef(null);f&&!A.current&&(A.current=`scrollview-${Math.random().toString(36).slice(2,9)}`);let E=f?A.current:null;useEffect(()=>{if(!(!f||!E||!R||!h.current))return R.register(E,h.current)},[f,E,R]);let L=f&&E&&R?.focusedId===E,N=y.innerHeight,j=v.height,b=Math.max(0,j-N),x=Math.max(0,Math.min(P,b)),I=useMemo(()=>({getBounds:()=>{let w=y.y;return {visibleTop:w,visibleBottom:w+N,viewportHeight:N,scrollOffset:x}}}),[y.y,N,x]),g=useCallback(w=>{let W=Math.max(0,Math.min(w,b));m?r?.(W):S(W);},[m,r,b]);useEffect(()=>{P>b&&b>=0&&g(b);},[P,b,g]),useEffect(()=>!c||!R||!M||!d.current?void 0:R.onFocusChange(W=>{if(!W||!d.current)return;let _=Te=>{if(Te.focusId===W)return Te;for(let be of Te.children){let ue=_(be);if(ue)return ue}return null},oe=_(d.current);if(!oe)return;let pe=M.getLayout(oe),se=d.current.layout?.y??0,ae=pe.y-se,Re=ae+pe.height,xe=P,he=P+N;ae<xe?g(ae):Re>he&&g(Re-N);}),[c,R,M,P,N,g]);let O=useCallback(()=>{if(!R)return false;let w=R.focusedId;if(!w)return false;if(f&&E&&w===E)return true;if(!d.current)return false;let W=_=>{if(_.focusId===w)return true;for(let oe of _.children)if(W(oe))return true;return false};return W(d.current)},[R,f,E]);Ue(w=>{if(i||!O())return;let W=Math.max(1,Math.floor(N/2)),_=Math.max(1,N);switch(w.name){case "pageup":g(P-_);break;case "pagedown":g(P+_);break;default:w.ctrl&&(w.name==="d"?g(P+W):w.name==="u"?g(P-W):w.name==="f"?g(P+_):w.name==="b"&&g(P-_));break}},[P,s,N,b,i,g,O]);let{padding:U,paddingX:V,paddingY:$,paddingTop:q,paddingRight:z,paddingBottom:D,paddingLeft:K,...H}=t??{},me=H.border!=null&&H.border!=="none"?2:0,J=j>0?j+me:void 0,re={...H,...L?p:{},clip:true,...H.height===void 0&&J!==void 0?{height:J,flexShrink:H.flexShrink??1,minHeight:H.minHeight??0}:{}},Q={position:"absolute",top:-x,left:0,right:0,flexDirection:"column",...U!==void 0&&{padding:U},...V!==void 0&&{paddingX:V},...$!==void 0&&{paddingY:$},...q!==void 0&&{paddingTop:q},...z!==void 0&&{paddingRight:z},...D!==void 0&&{paddingBottom:D},...K!==void 0&&{paddingLeft:K}},G=j>N&&N>0,B=l&&G,a=Math.max(1,Math.floor(N/j*N)),T=j-N,k=T>0?Math.floor(x/T*(N-a)):0,u=[];if(B)for(let w=0;w<N;w++)w>=k&&w<k+a?u.push("\u2588"):u.push("\u2591");let F={position:"absolute",top:0,right:0,width:1,height:N,flexDirection:"column"};return ne.createElement(Fe.Provider,{value:I},ne.createElement("box",{style:re,ref:w=>{h.current=w??null;},...f?{focusable:true,focusId:E}:{}},ne.createElement("box",{style:{...Q,paddingRight:B?(Q.paddingRight??0)+1:Q.paddingRight},ref:w=>{d.current=w??null;}},e),B&&ne.createElement("box",{style:F},ne.createElement("text",{style:{color:"blackBright"}},u.join(`
|
|
14
|
+
`)))))}function Kt({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),C=f?n:p,S=useContext(X),P=useContext(Y),h=useRef(null),d=useRef(null),y=useRef(o);y.current=o;let[v,R]=useState(false),[M,A]=useState(false),E=useRef(null),L=useCallback(x=>{let I=Math.max(0,Math.min(x,e-1));f?r?.(I):m(I);},[f,r,e]),N=useCallback((x,I)=>{if(!i||i.size===0)return Math.max(0,Math.min(x+I,e-1));let g=x+I;for(;g>=0&&g<e&&i.has(g);)g+=I;return g<0||g>=e?x:g},[i,e]);useEffect(()=>{if(!(!S||!d.current||!h.current||!l))return S.register(d.current,h.current)},[S,l,v]),useEffect(()=>{if(!S||!d.current)return;let x=d.current;return A(S.focusedId===x),S.onFocusChange(I=>{A(I===x);})},[S,v]);let j=useCallback(x=>{let I=x?e-1:0,g=x?-1:1,O=I;for(;O>=0&&O<e&&i?.has(O);)O+=g;return O>=0&&O<e?O:x?e-1:0},[i,e]);useEffect(()=>{if(!P||!d.current||!l)return;let x=d.current,I=g=>S?.focusedId!==x?false:g.name==="g"&&!g.ctrl&&!g.alt?E.current==="g"?(L(j(false)),E.current=null,true):(E.current="g",true):g.name==="G"||g.name==="g"&&g.shift?(E.current=null,L(j(true)),true):(E.current=null,g.name==="up"||g.name==="k"?(L(N(C,-1)),true):g.name==="down"||g.name==="j"?(L(N(C,1)),true):g.name==="return"?(i?.has(C)||y.current?.(C),true):false);return P.registerInputHandler(x,I)},[P,S,l,C,L,N,j,i,v]);let b=[];for(let x=0;x<e;x++)b.push(ne.createElement(ne.Fragment,{key:x},t({index:x,selected:x===C,focused:M})));return ne.createElement("box",{style:{flexDirection:"column",...c},focusable:l,ref:x=>{x?(h.current=x,d.current=x.focusId,R(true)):(h.current=null,d.current=null,R(false));}},...b)}function Ho({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 ne.createElement(Kt,{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:C})=>{let S=e[p],P=S.disabled,h=m&&C,d=m?">":" ";return ne.createElement("box",{style:{flexDirection:"row",...h?{bg:i}:{}}},ne.createElement("text",{style:h?{bold:true,color:"black"}:P?{dim:true}:{}},`${d} ${S.label}`))}})}function Do({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=ve(l).innerWidth,[m,C]=useState(0);useEffect(()=>{if(!t)return;let y=setInterval(()=>{C(v=>(v+1)%Math.max(1,p+6));},100);return ()=>clearInterval(y)},[t,p]);let S=Math.max(0,Math.min(1,e??0)),P=o?` ${Math.round(S*100)}%`:"",h="";if(p>0)if(t&&e===void 0){let y=Math.max(1,Math.min(3,Math.floor(p/4))),v=[];for(let R=0;R<p;R++)R>=m-y&&R<m?v.push(i):v.push(c);h=v.join("");}else {let y=Math.round(S*p);h=i.repeat(y)+c.repeat(p-y);}let d=[];return r&&d.push(ne.createElement("text",{key:"label",style:{bold:true}},r+" ")),d.push(ne.createElement("box",{key:"track",style:{flexGrow:1,flexShrink:1},ref:y=>{l.current=y??null;}},ne.createElement("text",{key:"bar",style:{}},h))),o&&d.push(ne.createElement("text",{key:"pct",style:{bold:true}},P)),ne.createElement("box",{style:{flexDirection:"row",width:n,...s}},...d)}var _o=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function qo({frames:e=_o,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=[ne.createElement("text",{key:"frame",style:r},e[o])];return n&&i.push(ne.createElement("text",{key:"label",style:{}}," "+n)),ne.createElement("box",{style:{flexDirection:"row"}},...i)}var or=createContext(null),Qo=0;function Zo(){let e=useContext(or);if(!e)throw new Error("useToast must be used within a <ToastHost>");return e.push}var es={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 ts({position:e="bottom-right",maxVisible:t=5,children:n}){let[r,o]=useState([]),s=useRef(new Map),i=useCallback(S=>{let P=`toast-${Qo++}`,h={id:P,durationMs:3e3,variant:"info",...S};if(o(d=>[...d,h]),h.durationMs&&h.durationMs>0){let d=setTimeout(()=>{s.current.delete(P),o(y=>y.filter(v=>v.id!==P));},h.durationMs);s.current.set(P,d);}},[]);useEffect(()=>()=>{for(let S of s.current.values())clearTimeout(S);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},C=r.slice(-t).map(S=>{let P=S.variant??"info",h=es[P],d=[];return S.title&&d.push(ne.createElement("text",{key:"title",style:{bold:true,color:h.title}},S.title)),d.push(ne.createElement("text",{key:"msg",style:{color:h.text}},S.message)),ne.createElement("box",{key:S.id,style:{bg:h.bg,paddingX:1,flexDirection:"column",minWidth:20,maxWidth:50}},...d)});return ne.createElement(or.Provider,{value:c.current},n,C.length>0?ne.createElement("box",{style:p},...C):null)}function rs({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(X),C=useContext(Y),S=useContext(Be),P=useContext(Fe),h=useRef(null),d=useRef(null),y=useRef(n);y.current=n;let[v,R]=useState(false),[M,A]=useState(false),[E,L]=useState(false),[N,j]=useState(0),[b,x]=useState(""),[I,g]=useState(0),O=ve(h),U=S?.rows??24,V=P?.getBounds(),q=e.find(a=>a.value===t)?.label??"",z=useMemo(()=>{if(!b)return e;let a=b.toLowerCase();return e.filter(T=>T.label.toLowerCase().includes(a))},[e,b]),D=Math.min(l,z.length),K=z.slice(I,I+D);useEffect(()=>{j(0),g(0);},[b]),useEffect(()=>{!M&&E&&(L(false),x(""));},[M,E]),useEffect(()=>{if(!(!m||!d.current||!h.current))return m.register(d.current,h.current)},[m,v]),useEffect(()=>{!m||!d.current||m.setSkippable(d.current,!!p);},[m,p,v]),useEffect(()=>{if(!m||!d.current)return;let a=d.current;return A(m.focusedId===a),m.onFocusChange(T=>{A(T===a);})},[m,v]);let H=useCallback((a,T)=>{let k=a+T;for(;k>=0&&k<z.length;){if(!z[k].disabled)return k;k+=T;}return a},[z]),ce=useCallback(a=>{a<I?g(a):a>=I+D&&g(a-D+1);},[I,D]);useEffect(()=>{if(!C||!d.current||p)return;let a=d.current,T=k=>{if(m?.focusedId!==a)return false;if(!E){if(k.name==="return"||k.name===" "||k.sequence===" "||k.name==="down"){L(true),x("");let u=z.findIndex(w=>w.value===t),F=u>=0?u:0;return j(F),g(Math.max(0,F-Math.floor(l/2))),true}return false}if(k.name==="tab")return L(false),x(""),false;if(k.name==="escape")return L(false),x(""),true;if(k.name==="return"){let u=z[N];return u&&!u.disabled&&(y.current?.(u.value),L(false),x("")),true}if(k.name==="up"){let u=H(N,-1);return j(u),ce(u),true}if(k.name==="down"){let u=H(N,1);return j(u),ce(u),true}if(k.name==="backspace")return f&&b.length>0&&x(u=>u.slice(0,-1)),true;if(k.name==="home"){let u=H(-1,1);return j(u),ce(u),true}if(k.name==="end"){let u=H(z.length,-1);return j(u),ce(u),true}if(f&&k.sequence&&k.sequence.length===1&&!k.ctrl&&!k.alt){let u=k.sequence;if(u>=" "&&u<="~")return x(F=>F+u),true}return true};return C.registerInputHandler(a,T)},[C,m,p,E,N,z,t,l,f,b,H,ce,v]);let J={flexDirection:"row",width:"100%",...!o?.bg&&o?.border===void 0?{border:"single"}:{},...o,...M&&s?s:{}},re=q?o?.color??void 0:"blackBright",Q=[ne.createElement("text",{key:"label",style:{flexGrow:1,flexShrink:1,color:re,wrap:"ellipsis",...q?{}:{dim:true}}},q||r),ne.createElement("text",{key:"arrow",style:{flexShrink:0,color:M?c:"blackBright"}},E?" \u25B2":" \u25BC")],G=null;if(E){let a=[];f&&b&&a.push(ne.createElement("box",{key:"search",style:{paddingX:1}},ne.createElement("text",{style:{color:"blackBright",dim:true}},`/${b}`))),z.length===0&&a.push(ne.createElement("box",{key:"empty",style:{paddingX:1}},ne.createElement("text",{style:{dim:true,color:"blackBright"}},"No matches"))),I>0&&a.push(ne.createElement("box",{key:"scroll-up",style:{justifyContent:"center",alignItems:"center"}},ne.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25B2"))),K.forEach((xe,he)=>{let be=I+he===N,ue=xe.disabled,Ce={paddingX:1,...be&&!ue?{bg:c}:{}},ot={...be&&!ue?{color:"black",bold:true}:{},...ue?{dim:true,color:"blackBright"}:{}};a.push(ne.createElement("box",{key:`item-${xe.value}`,style:Ce},ne.createElement("text",{style:ot},xe.label)));}),I+D<z.length&&a.push(ne.createElement("box",{key:"scroll-down",style:{justifyContent:"center",alignItems:"center"}},ne.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25BC")));let T=I>0,k=I+D<z.length,u=f&&b,F=z.length===0,w=!i?.bg&&i?.border===void 0,_=D+(w?2:0);T&&(_+=1),k&&(_+=1),u&&(_+=1),F&&(_+=1);let oe=O.y+O.height,pe,se;V?(pe=V.visibleBottom-oe,se=O.y-V.visibleTop):(pe=U-oe,se=O.y);let Re=pe<_&&se>=_?-_:O.height||1;G=ne.createElement("box",{style:{position:"absolute",top:Re,left:0,right:0,zIndex:9999,...w?{border:"single"}:{},bg:"black",flexDirection:"column",...i}},...a);}let B={flexDirection:"column",width:J.width??"100%",minWidth:J.minWidth,maxWidth:J.maxWidth,flexGrow:J.flexGrow,flexShrink:J.flexShrink??1};return ne.createElement("box",{style:B},ne.createElement("box",{style:J,focusable:true,ref:a=>{a?(h.current=a,d.current=a.focusId,R(true)):(h.current=null,d.current=null,R(false));}},...Q),G)}function os({checked:e,onChange:t,label:n,style:r,focusedStyle:o,disabled:s,checkedChar:i="\u2713",uncheckedChar:c=" "}){let l=useContext(X),f=useContext(Y),p=useRef(null),m=useRef(null),C=useRef(t);C.current=t;let S=useRef(e);S.current=e;let[P,h]=useState(false),[d,y]=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 E=m.current;return y(l.focusedId===E),l.onFocusChange(L=>{y(L===E);})},[l,P]),useEffect(()=>{if(!f||!m.current||s)return;let E=m.current,L=N=>l?.focusedId!==E?false:N.name==="return"||N.name===" "||N.sequence===" "?(C.current(!S.current),true):false;return f.registerInputHandler(E,L)},[f,l,s,P]);let v={flexDirection:"row",gap:1,...r,...d&&o?o:{}},R=e?i:c,M={color:s?"blackBright":d?"white":r?.color},A={color:s?"blackBright":r?.color};return ne.createElement("box",{style:v,focusable:!s,ref:E=>{E?(p.current=E,m.current=E.focusId,h(true)):(p.current=null,m.current=null,h(false));}},ne.createElement("text",{key:"box",style:M},`[${R}]`),n?ne.createElement("text",{key:"label",style:A},n):null)}function is({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 C=useContext(X),S=useContext(Y),P=useRef(null),h=useRef(null),d=useRef(n);d.current=n;let[y,v]=useState(false),[R,M]=useState(false),[A,E]=useState(()=>{let b=e.findIndex(x=>x.value===t);return b>=0?b:e.findIndex(x=>!x.disabled)}),L=useCallback((b,x)=>{let I=b;for(let g=0;g<e.length;g++)if(I=(I+x+e.length)%e.length,!e[I]?.disabled)return I;return b},[e]);useEffect(()=>{if(!(!C||!h.current||!P.current||c))return C.register(h.current,P.current)},[C,c,y]),useEffect(()=>{if(!C||!h.current)return;let b=h.current;return M(C.focusedId===b),C.onFocusChange(x=>{M(x===b);})},[C,y]),useEffect(()=>{if(!S||!h.current||c)return;let b=h.current,x=I=>{if(C?.focusedId!==b)return false;if(I.name==="up"||I.name==="left"||I.name==="k"||I.name==="tab"&&I.shift)return E(g=>L(g,-1)),true;if(I.name==="down"||I.name==="right"||I.name==="j"||I.name==="tab"&&!I.shift)return E(g=>L(g,1)),true;if(I.name==="return"||I.name===" "||I.sequence===" "){let g=e[A];return g&&!g.disabled&&d.current(g.value),true}return false};return S.registerInputHandler(b,x)},[S,C,c,e,A,L,y]),useEffect(()=>{let b=e.findIndex(x=>x.value===t);b>=0&&E(b);},[t,e]);let N={flexDirection:l,gap:f,...r},j=e.map((b,x)=>{let I=b.value===t,g=x===A,O=c||b.disabled,U=I?p:m,V={flexDirection:"row",gap:1,...o};I&&i&&(V={...V,...i}),R&&g&&s&&(V={...V,...s});let $=O?"blackBright":R&&g?s?.color??"white":I?i?.color??o?.color:o?.color;return ne.createElement("box",{key:x,style:V},ne.createElement("text",{key:"radio",style:{color:$}},`(${U})`),ne.createElement("text",{key:"label",style:{color:$}},b.label))});return ne.createElement("box",{style:N,focusable:!c,ref:b=>{b?(P.current=b,h.current=b.focusId,v(true)):(P.current=null,h.current=null,v(false));}},...j)}var fr=createContext(null);function cs(){let e=useContext(fr);if(!e)throw new Error("useDialog must be used within a DialogHost");return e}function as({children:e}){let[t,n]=useState([]),r=useRef(0),o=useCallback((f,p)=>new Promise(m=>{let C=++r.current;n(S=>[...S,{id:C,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 C=++r.current;n(S=>[...S,{id:C,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 C=m.find(S=>S.id===f);return C&&C.resolve(p),m.filter(S=>S.id!==f)});},[]),c={alert:o,confirm:s},l=t[t.length-1];return ne.createElement(fr.Provider,{value:c},e,l&&ne.createElement(us,{key:l.id,dialog:l,onDismiss:i}))}function us({dialog:e,onDismiss:t}){let n=useContext(X),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 y=[];return r.current&&s.current&&y.push(n.register(s.current,r.current)),o.current&&i.current&&y.push(n.register(i.current,o.current)),s.current&&n.requestFocus(s.current),()=>y.forEach(v=>v())},[n,f]),useEffect(()=>{if(n)return n.onFocusChange(y=>{y===s.current?l("ok"):y===i.current&&l("cancel");})},[n]),Ue(y=>{if(y.name==="return"||y.name==="space"){e.type==="alert"?t(e.id,true):t(e.id,c==="ok");return}if(y.name==="escape"){t(e.id,false);return}e.type==="confirm"&&n&&(y.name==="left"||y.name==="right")&&(c==="ok"&&i.current?n.requestFocus(i.current):s.current&&n.requestFocus(s.current));},[e,c,n,t]);let m=typeof e.content=="string",C=m?e.content.length:0,P={minWidth:Math.max(20,m?Math.min(C+6,50):30),maxWidth:50,bg:"black",border:"round",borderColor:"white",padding:1,flexDirection:"column",gap:1,...e.style},h=(y,v)=>{let R={paddingX:2,bg:"blackBright",color:"white"},M={bg:"white",color:"black",bold:true},A=y==="ok"?e.okButtonStyle:e.cancelButtonStyle;return {...R,...e.buttonStyle,...A,...v?{...M,...e.focusedButtonStyle}:{}}},d={position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:999,...e.backdropStyle};return ne.createElement(Lt,{trap:true},ne.createElement("box",{style:d}),ne.createElement("box",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,justifyContent:"center",alignItems:"center",zIndex:1e3}},ne.createElement("box",{style:P},ne.createElement("box",{style:{flexDirection:"column"}},typeof e.content=="string"?ne.createElement("text",null,e.content):e.content),ne.createElement("box",{style:{flexDirection:"row",justifyContent:"flex-end",gap:1}},e.type==="confirm"&&ne.createElement("box",{style:h("cancel",c==="cancel"),focusable:true,ref:y=>{y&&y.focusId&&!i.current&&(o.current=y,i.current=y.focusId,p(v=>v+1));}},ne.createElement("text",null,e.cancelText)),ne.createElement("box",{style:h("ok",c==="ok"),focusable:true,ref:y=>{y&&y.focusId&&!s.current&&(r.current=y,s.current=y.focusId,p(v=>v+1));}},ne.createElement("text",null,e.okText))))))}function ds(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 ms({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?(...b)=>console.error("[JumpNav]",...b):()=>{},[f,p]=useState(false),[m,C]=useState(""),[S,P]=useState([]),h=useContext(Y),d=useContext(X),y=useContext(ie);useEffect(()=>{l("Mounted, inputCtx:",!!h,"focusCtx:",!!d,"enabled:",i);},[]);let R=useCallback(b=>{let x=b.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),M=useCallback(()=>{if(!d?.getActiveElements){l("refreshElements: no getActiveElements");return}let b=d.getActiveElements();l("getActiveElements returned",b.length,"elements");let x=b.map(({id:I,node:g})=>({id:I,node:g,layout:y?.getLayout(g)??g.layout}));x.sort((I,g)=>I.layout.y!==g.layout.y?I.layout.y-g.layout.y:I.layout.x-g.layout.x),P(x);},[d,y,l]),A=useRef(false);useEffect(()=>{f&&!A.current&&(l("Activated! Refreshing elements..."),M()),A.current=f;},[f,M,l]);let E=S.filter(b=>b.layout.width>0&&b.layout.height>0),L=ds(E.length,s),N=useMemo(()=>{let b=new Map;return E.forEach((x,I)=>{L[I]&&b.set(L[I],x.id);}),b},[E,L]);useEffect(()=>{if(!h||!i){l("Not subscribing - inputCtx:",!!h,"enabled:",i);return}l("Subscribing to priority input, activation key:",t);let b=x=>{let I=x.name===R.name,g=!!x.ctrl===R.ctrl,O=!!x.alt===R.alt,U=!!x.shift===R.shift,V=!!x.meta===R.meta;if(!f&&I&&g&&O&&U&&V)return l("Activation key matched! Activating..."),p(true),C(""),true;if(f){if(x.name==="escape")return l("Escape pressed, deactivating"),p(false),C(""),true;if(x.name==="backspace")return C(""),true;if(x.sequence&&x.sequence.length===1&&/[a-z]/i.test(x.sequence)){let $=m+x.sequence.toLowerCase();l("Buffer:",$);let q=N.get($);return q?(l("Jumping to",q),d?.requestFocus(q),p(false),C(""),true):[...N.keys()].some(D=>D.startsWith($))?(C($),true):(C(""),true)}return true}return false};return h.subscribePriority(b)},[h,i,f,R,m,N,d,t,l]);let j=f?ne.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:99998}},...E.map((b,x)=>{let I=L[x];if(!I)return null;let{x:g,y:O}=b.layout,U=I.startsWith(m)&&m.length>0;return ne.createElement("box",{key:b.id,style:{position:"absolute",top:O,left:Math.max(0,g-I.length-2),bg:U?"cyan":r,color:o,paddingX:1,zIndex:99999,...n}},ne.createElement("text",{style:{bold:true,color:o}},I))}),ne.createElement("box",{style:{position:"absolute",bottom:0,left:0,right:0,bg:"blackBright",paddingX:1,zIndex:99999}},ne.createElement("text",{style:{color:"white"}},m?`Jump: ${m}_`:"Press a key to jump \u2022 ESC to cancel"))):null;return ne.createElement(ne.Fragment,null,e,j)}var Ae=join(tmpdir(),"glyph-image-cache");function bt(e){return e.startsWith("http://")||e.startsWith("https://")}function xs(e,t){let n=createHash("md5").update(e).digest("hex"),r=t?Cs(t):bs(e)||".png";return join(Ae,`${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 Cs(e){switch(e){case "png":return ".png";case "jpeg":return ".jpeg";case "gif":return ".gif";case "webp":return ".webp";default:return ".png"}}function sn(e){if(bt(e))try{let t=new URL(e),n=t.pathname;return basename(n)||t.hostname}catch{return "remote-image"}return basename(e)}function hr(){existsSync(Ae)||mkdirSync(Ae,{recursive:true});}async function gr(e){let t=sn(e);return bt(e)?Is(e,t):Ss(e,t)}async function Ss(e,t){if(!existsSync(e))throw new Error(`Image not found: ${e}`);return {data:readFileSync(e),name:t,localPath:e,isRemote:false}}async function Is(e,t){hr();let n=createHash("md5").update(e).digest("hex"),r=[".png",".jpeg",".gif",".webp"];for(let f of r){let p=join(Ae,`${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(!ws(i))throw new Error(`Invalid image data from: ${e}`);let c=Ct(i),l=xs(e,c);return writeFileSync(l,i),{data:i,name:t,localPath:l,isRemote:true}}function ws(e){return e.length<4?false:e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71||e[0]===255&&e[1]===216&&e[2]===255||e[0]===71&&e[1]===73&&e[2]===70||e[0]===66&&e[1]===77||e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e.length>=12&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80||e[0]===0&&e[1]===0&&e[2]===1&&e[3]===0}function Ct(e){return e.length<4?"unknown":e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"png":e[0]===255&&e[1]===216&&e[2]===255?"jpeg":e[0]===71&&e[1]===73&&e[2]===70?"gif":e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e.length>=12&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80?"webp":"unknown"}function yr(e,t){let n=Ct(e);if(n==="png")return e;hr();let r=createHash("md5").update(e).digest("hex"),o=join(Ae,`${r}.${n}`),s=join(Ae,`${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 Rs(){let e=platform();return e==="darwin"?"quicklook":e==="linux"||e==="win32"?"open":"none"}async function ln(e){switch(Rs()){case "quicklook":return Ts(e);case "open":return Ps(e);case "none":throw new Error("No preview method available on this platform")}}function Ts(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(()=>{ks();},50),r.on("close",o=>{t();});})}function ks(){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 Ps(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 Es({src:e,width:t,height:n,unloadTrigger:r,style:o,focusedStyle:s,placeholderStyle:i,focusable:c=true,inline:l=true,placeholder:
|
|
18
|
+
'`,()=>{});}function Ps(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 Es({src:e,width:t,height:n,unloadTrigger:r,style:o,focusedStyle:s,placeholderStyle:i,focusable:c=true,inline:l=true,placeholder:f,onStateChange:p,onError:m,autoLoad:C=false,autoSize:S=false,maxWidth:P,maxHeight:h}){let d=useContext(X),y=useContext(Y),v=useContext(ie),R=useContext(ft),M=useContext(Fe),A=useRef(null),E=useRef(null),L=useRef(Math.floor(Math.random()*1e6)),N=useRef(null),[j,b]=useState(false),[x,I]=useState(false),[g,O]=useState("placeholder"),[U,V]=useState(null),[$,q]=useState(null),[z,D]=useState(null),K=useRef(null),H=f||sn(e),ce=bt(e),me=useRef(r);useEffect(()=>{r!==void 0&&r!==me.current&&g==="loaded"&&(K.current=null,D(null),O("placeholder")),me.current=r;},[r,g]);let J=useCallback(w=>{O(w),p?.(w);},[p]);useEffect(()=>{if(!(!d||!E.current||!A.current||!c))return d.register(E.current,A.current,false)},[d,c,j]),useEffect(()=>{if(!d||!E.current)return;let w=E.current;return I(d.focusedId===w),d.onFocusChange(W=>{I(W===w);})},[d,j]),useEffect(()=>{if(!(!v||!A.current))return q(v.getLayout(A.current)),v.subscribe(A.current,q)},[v,j]);let re=M?.getBounds().scrollOffset??0;useEffect(()=>{if(M){if(N.current===null){N.current=re;return}if(g!=="loaded"){N.current=re;return}re!==N.current&&(N.current=re,K.current=null,D(null),O("placeholder"));}},[M,re,g]),useEffect(()=>{if(!R||g!=="loaded"||!K.current||!$)return;let{data:w,cellWidth:W,cellHeight:_}=K.current,oe=L.current,pe=setTimeout(()=>{R.registerImage({id:oe,data:w,x:$.innerX,y:$.innerY,width:W,height:_});},0);return ()=>{clearTimeout(pe),R.unregisterImage(oe);}},[R,g,$,M]);let Q=useCallback(async()=>{if(g!=="loading"){J("loading"),V(null);try{let w=await gr(e);if(l&&Et()&&$){let _=Ct(w.data),oe=w.data;if(_!=="png"){let he=yr(w.data);if(!he){J("preview"),await ln(w.localPath),J("placeholder");return}oe=he;}let pe=Bt(oe),se,ae;if(S&&pe){let ue=Math.ceil(pe.width/8),Ce=Math.ceil(pe.height/16),ot=P??80,cn=h??24;if(ue>ot||Ce>cn){let Rr=ot/ue,Tr=cn/Ce,an=Math.min(Rr,Tr);ue=Math.max(1,Math.round(ue*an)),Ce=Math.max(1,Math.round(Ce*an));}se=ue,ae=Ce,D({width:ue,height:Ce});}else se=t??$.innerWidth,ae=n??$.innerHeight;if(se<=0||ae<=0)throw new Error("Image area too small");let Re=30,xe=6;if(se>Re||ae>xe){let he=Re/se,Te=xe/ae,be=Math.min(he,Te);se=Math.max(1,Math.round(se*be)),ae=Math.max(1,Math.round(ae*be));}K.current={data:oe,localPath:w.localPath,cellWidth:se,cellHeight:ae},J("loaded");}else J("preview"),await ln(w.localPath),J("placeholder");}catch(w){let W=w instanceof Error?w:new Error(String(w));V(W.message),J("error"),m?.(W);}}},[e,g,l,$,t,n,S,P,h,J,m]);useEffect(()=>{if(!y||!E.current||!c)return;let w=E.current,W=_=>d?.focusedId!==w?false:_.name==="space"||_.name==="return"||_.name==="r"&&K.current?(Q(),true):_.name==="escape"&&g==="loaded"?(K.current=null,D(null),J("placeholder"),true):_.name==="escape"&&g==="placeholder"?(d?.blur(),true):false;return y.registerInputHandler(w,W)},[y,d,c,j,Q,g,J]),useEffect(()=>{C&&g==="placeholder"&&$&&$.innerWidth>0&&Q();},[C,g,$,Q]),useEffect(()=>{let w=L.current;return ()=>{R?.unregisterImage(w);}},[R]);let G,B;switch(g){case "placeholder":B=ce?"\u{1F310}":"\u{1F5BC}\uFE0F",G=`${B} ${H}`;break;case "loading":B="\u23F3",G=`${B} Loading...`;break;case "loaded":G=null;break;case "preview":B="\u{1F441}\uFE0F",G=`${B} Previewing...`;break;case "error":B="\u274C",G=`${B} ${U||"Error"}`;break}let a=S&&z?z.width:t,T=S&&z?z.height:n,u={...{border:"round",borderColor:"blackBright",justifyContent:"center",alignItems:"center",...o,...a!==void 0?{width:a}:{},...T!==void 0?{height:T}:{}},...x?{borderColor:"cyan"}:{},...x&&s?s:{}},F={color:"blackBright",...i,...x?{color:"cyan"}:{}};return ne.createElement("box",{style:u,focusable:c,ref:w=>{w?(A.current=w,E.current=w.focusId,b(true)):(A.current=null,E.current=null,b(false));}},G!==null?ne.createElement("text",{style:F},G):null)}function Ls(e){let t=useContext(X),[n]=useState(()=>`focus-${Math.random().toString(36).slice(2,9)}`),r=t?t.focusedId===n:false;useEffect(()=>{if(!(!t||!e?.current))return e.current.focusId=n,t.register(n,e.current)},[t,n,e]);let o=useMemo(()=>()=>{t?.requestFocus(n);},[t,n]);return {focused:r,focus:o}}function As(e={}){let{disabled:t,onFocus:n,onBlur:r,onKeyPress:o}=e,s=useContext(X),i=useContext(Y),c=useRef(null),l=useRef(null),[f,p]=useState(false),m=useRef(n),C=useRef(r),S=useRef(o);m.current=n,C.current=r,S.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);},[s,t]),useEffect(()=>{if(!s||!l.current)return;let d=l.current,y=s.focusedId===d;return p(y),s.onFocusChange(v=>{let R=v===d;p(M=>(R&&!M?m.current?.():!R&&M&&C.current?.(),R));})},[s]),useEffect(()=>{if(!i||!l.current||t)return;let d=l.current,y=v=>s?.focusedId!==d?false:S.current?.(v)===true;return i.registerInputHandler(d,y)},[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 Hs(){let e=useContext(Be);if(!e)throw new Error("useApp must be used within a Glyph render tree");return {exit:e.exit,get columns(){return e.columns},get rows(){return e.rows}}}function Ks(){let e=useContext(X),t=useContext(ie),[n,r]=useState([]),o=useRef(()=>{}),s=useCallback(()=>{if(!e)return;let c=(e.getActiveElements?.()??e.getRegisteredElements?.()??[]).map(({id:l,node: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 Ws(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 _s(e,t){switch(t){case "digit":return /\d/.test(e);case "letter":return /[a-zA-Z]/.test(e);case "alphanumeric":return /[a-zA-Z0-9]/.test(e);case "literal":return true}}function le(e){let t=typeof e=="string"?{mask:e}:e,{mask:n,placeholder:r="_",showPlaceholder:o=false}=t,s=Ws(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 C=l[p];if(_s(C,m.type))f+=C,p++;else {p++;continue}}else o&&(f+=r);return f}}var qs={usPhone:le("(999) 999-9999"),intlPhone:le("+9 999 999 9999"),dateUS:le("99/99/9999"),dateEU:le("99/99/9999"),dateISO:le("9999-99-99"),time:le("99:99"),timeFull:le("99:99:99"),creditCard:le("9999 9999 9999 9999"),ssn:le("999-99-9999"),zip:le("99999"),zipPlus4:le("99999-9999"),ipv4:le("999.999.999.999"),mac:le("**:**:**:**:**:**")};export{lo as Box,Po as Button,os as Checkbox,as as DialogHost,Lt as FocusScope,Es as Image,yo as Input,ms as JumpNav,vo as Keybind,Kt as List,Ho as Menu,To as Portal,Do as Progress,is as Radio,jo as ScrollView,rs as Select,Io as Spacer,qo as Spinner,ho as Text,ts as ToastHost,le as createMask,We as detectTerminalCapabilities,qs as masks,Pt as parseAnsi,oo as render,Vr as stripAnsi,Et as supportsInlineImages,Hs as useApp,cs as useDialog,Ls as useFocus,Ks as useFocusRegistry,As as useFocusable,Ue as useInput,ve as useLayout,Zo as useToast};//# sourceMappingURL=index.js.map
|
|
19
19
|
//# sourceMappingURL=index.js.map
|