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