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