@semos-labs/glyph 0.1.74 → 0.1.76
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/README.md +49 -23
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
<p align="center">
|
|
21
21
|
<a href="https://www.npmjs.com/package/@semos-labs/glyph"><img src="https://img.shields.io/npm/v/@semos-labs/glyph?color=crimson&logo=npm" alt="npm version"></a>
|
|
22
|
-
<a href="https://github.com/
|
|
22
|
+
<a href="https://github.com/semos-labs/glyph/actions/workflows/test.yml"><img src="https://github.com/semos-labs/glyph/actions/workflows/test.yml/badge.svg" alt="Tests"></a>
|
|
23
23
|
<img src="https://img.shields.io/badge/React-18%2B-61dafb?logo=react&logoColor=white" alt="React 18+">
|
|
24
24
|
<img src="https://img.shields.io/badge/Yoga-Flexbox-mediumpurple?logo=meta&logoColor=white" alt="Yoga Flexbox">
|
|
25
25
|
<img src="https://img.shields.io/badge/TypeScript-First-3178c6?logo=typescript&logoColor=white" alt="TypeScript">
|
|
@@ -50,22 +50,48 @@ Build real terminal applications with React. Glyph provides a full component mod
|
|
|
50
50
|
|
|
51
51
|
---
|
|
52
52
|
|
|
53
|
-
##
|
|
53
|
+
## Quick Start
|
|
54
|
+
|
|
55
|
+
The fastest way to get started — scaffold a new project:
|
|
54
56
|
|
|
55
57
|
```bash
|
|
58
|
+
# bun
|
|
59
|
+
bun create @semos-labs/glyph my-app
|
|
60
|
+
|
|
56
61
|
# npm
|
|
57
|
-
npm
|
|
62
|
+
npm create @semos-labs/glyph my-app
|
|
58
63
|
|
|
59
64
|
# pnpm
|
|
60
|
-
pnpm
|
|
65
|
+
pnpm create @semos-labs/glyph my-app
|
|
61
66
|
|
|
67
|
+
# yarn
|
|
68
|
+
yarn create @semos-labs/glyph my-app
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Then:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
cd my-app
|
|
75
|
+
bun install
|
|
76
|
+
bun dev
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Manual Installation
|
|
80
|
+
|
|
81
|
+
```bash
|
|
62
82
|
# bun
|
|
63
83
|
bun add @semos-labs/glyph react
|
|
84
|
+
|
|
85
|
+
# npm
|
|
86
|
+
npm install @semos-labs/glyph react
|
|
87
|
+
|
|
88
|
+
# pnpm
|
|
89
|
+
pnpm add @semos-labs/glyph react
|
|
64
90
|
```
|
|
65
91
|
|
|
66
92
|
---
|
|
67
93
|
|
|
68
|
-
##
|
|
94
|
+
## Hello World
|
|
69
95
|
|
|
70
96
|
```tsx
|
|
71
97
|
import React from "react";
|
|
@@ -834,27 +860,27 @@ Interactive examples are included in the repo. Each demonstrates different compo
|
|
|
834
860
|
|
|
835
861
|
| Example | Description | Source |
|
|
836
862
|
|---------|-------------|--------|
|
|
837
|
-
| **basic-layout** | Flexbox layout fundamentals | [View →](https://github.com/
|
|
838
|
-
| **modal-input** | Modal dialogs, input focus trapping | [View →](https://github.com/
|
|
839
|
-
| **scrollview-demo** | Scrollable content with keyboard navigation | [View →](https://github.com/
|
|
840
|
-
| **list-demo** | Keyboard-navigable lists | [View →](https://github.com/
|
|
841
|
-
| **menu-demo** | Styled menus with icons | [View →](https://github.com/
|
|
842
|
-
| **select-demo** | Dropdown select with search | [View →](https://github.com/
|
|
843
|
-
| **forms-demo** | Checkbox and Radio inputs | [View →](https://github.com/
|
|
844
|
-
| **masked-input** | Input masks (phone, credit card, SSN) | [View →](https://github.com/
|
|
845
|
-
| **dialog-demo** | Alert and Confirm dialogs | [View →](https://github.com/
|
|
846
|
-
| **jump-nav** | Quick navigation with keyboard hints | [View →](https://github.com/
|
|
847
|
-
| **ansi-text** | ANSI escape codes and colored output | [View →](https://github.com/
|
|
848
|
-
| **image** | Inline images and OS preview | [View →](https://github.com/
|
|
849
|
-
| **virtualized-list** | Virtualized ScrollView with 10k+ items | [View →](https://github.com/
|
|
850
|
-
| **showcase** | Progress bars, Spinners, Toasts | [View →](https://github.com/
|
|
851
|
-
| **dashboard** | Full task manager (all components) | [View →](https://github.com/
|
|
863
|
+
| **basic-layout** | Flexbox layout fundamentals | [View →](https://github.com/semos-labs/glyph/tree/main/examples/basic-layout) |
|
|
864
|
+
| **modal-input** | Modal dialogs, input focus trapping | [View →](https://github.com/semos-labs/glyph/tree/main/examples/modal-input) |
|
|
865
|
+
| **scrollview-demo** | Scrollable content with keyboard navigation | [View →](https://github.com/semos-labs/glyph/tree/main/examples/scrollview-demo) |
|
|
866
|
+
| **list-demo** | Keyboard-navigable lists | [View →](https://github.com/semos-labs/glyph/tree/main/examples/list-demo) |
|
|
867
|
+
| **menu-demo** | Styled menus with icons | [View →](https://github.com/semos-labs/glyph/tree/main/examples/menu-demo) |
|
|
868
|
+
| **select-demo** | Dropdown select with search | [View →](https://github.com/semos-labs/glyph/tree/main/examples/select-demo) |
|
|
869
|
+
| **forms-demo** | Checkbox and Radio inputs | [View →](https://github.com/semos-labs/glyph/tree/main/examples/forms-demo) |
|
|
870
|
+
| **masked-input** | Input masks (phone, credit card, SSN) | [View →](https://github.com/semos-labs/glyph/tree/main/examples/masked-input) |
|
|
871
|
+
| **dialog-demo** | Alert and Confirm dialogs | [View →](https://github.com/semos-labs/glyph/tree/main/examples/dialog-demo) |
|
|
872
|
+
| **jump-nav** | Quick navigation with keyboard hints | [View →](https://github.com/semos-labs/glyph/tree/main/examples/jump-nav) |
|
|
873
|
+
| **ansi-text** | ANSI escape codes and colored output | [View →](https://github.com/semos-labs/glyph/tree/main/examples/ansi-text) |
|
|
874
|
+
| **image** | Inline images and OS preview | [View →](https://github.com/semos-labs/glyph/tree/main/examples/image) |
|
|
875
|
+
| **virtualized-list** | Virtualized ScrollView with 10k+ items | [View →](https://github.com/semos-labs/glyph/tree/main/examples/virtualized-list) |
|
|
876
|
+
| **showcase** | Progress bars, Spinners, Toasts | [View →](https://github.com/semos-labs/glyph/tree/main/examples/showcase) |
|
|
877
|
+
| **dashboard** | Full task manager (all components) | [View →](https://github.com/semos-labs/glyph/tree/main/examples/dashboard) |
|
|
852
878
|
|
|
853
879
|
### Running Examples Locally
|
|
854
880
|
|
|
855
881
|
```bash
|
|
856
882
|
# Clone and install
|
|
857
|
-
git clone https://github.com/
|
|
883
|
+
git clone https://github.com/semos-labs/glyph.git && cd glyph
|
|
858
884
|
bun install && bun run build
|
|
859
885
|
|
|
860
886
|
# Run any example
|
|
@@ -872,7 +898,7 @@ bun run --filter jump-nav dev
|
|
|
872
898
|
<table>
|
|
873
899
|
<tr>
|
|
874
900
|
<td align="center">
|
|
875
|
-
<a href="https://github.com/
|
|
901
|
+
<a href="https://github.com/semos-labs/aion">
|
|
876
902
|
<strong>Aion</strong>
|
|
877
903
|
</a>
|
|
878
904
|
<br>
|
|
@@ -881,7 +907,7 @@ bun run --filter jump-nav dev
|
|
|
881
907
|
</tr>
|
|
882
908
|
</table>
|
|
883
909
|
|
|
884
|
-
<sub>Using Glyph in your project? <a href="https://github.com/
|
|
910
|
+
<sub>Using Glyph in your project? <a href="https://github.com/semos-labs/glyph/issues">Let us know!</a></sub>
|
|
885
911
|
|
|
886
912
|
---
|
|
887
913
|
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import ae,{createContext,forwardRef,useContext,useRef,useState,useImperativeHandle,useEffect,useCallback,useMemo,useLayoutEffect}from'react';import $r from'react-reconciler';import Ne from'string-width';import Un,{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 Or=0;function In(){return `glyph-focus-${Or++}`}function wn(e,t){let n=t.style??{};return {type:e,props:t,style:n,children:[],rawTextChildren:[],allChildren:[],parent:null,yogaNode:null,text:null,layout:{x:0,y:0,width:0,height:0,innerX:0,innerY:0,innerWidth:0,innerHeight:0},focusId:e==="input"||t.focusable?In():null,hidden:false}}function Lt(e,t){t.parent=e,e.children.push(t),e.allChildren.push(t);}function Ht(e,t){t.parent=e,e.rawTextChildren.push(t),e.allChildren.push(t),e.text=e.rawTextChildren.map(n=>n.text).join("");}function Rn(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 vn(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 Tn(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 kn(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 mt(e){let t={},n=e;for(;n;){let r=n.style;t.color===void 0&&r.color!==void 0&&(t.color=r.color),t.bg===void 0&&r.bg!==void 0&&(t.bg=r.bg),t.bold===void 0&&r.bold!==void 0&&(t.bold=r.bold),t.dim===void 0&&r.dim!==void 0&&(t.dim=r.dim),t.italic===void 0&&r.italic!==void 0&&(t.italic=r.italic),t.underline===void 0&&r.underline!==void 0&&(t.underline=r.underline),n=n.parent;}return t}function At(e,t={}){let n=[],r={color:e.style.color??t.color,bg:e.style.bg??t.bg,bold:e.style.bold??t.bold,dim:e.style.dim??t.dim,italic:e.style.italic??t.italic,underline:e.style.underline??t.underline};if(e.allChildren.length===0&&e.text!=null)return n.push({text:e.text,style:r}),n;for(let o of e.allChildren)o.type==="raw-text"?n.push({text:o.text,style:r}):n.push(...At(o,r));return n}var Vt=32,Pn={supportsMutation:true,supportsPersistence:false,supportsHydration:false,isPrimaryRenderer:true,scheduleTimeout:setTimeout,cancelTimeout:clearTimeout,noTimeout:-1,supportsMicrotasks:true,scheduleMicrotask:queueMicrotask,getCurrentUpdatePriority:()=>Vt,setCurrentUpdatePriority:e=>{},resolveUpdatePriority:()=>Vt,getCurrentEventPriority:()=>Vt,resolveEventType:()=>null,resolveEventTimeStamp:()=>-1.1,shouldAttemptEagerTransition:()=>false,getInstanceFromNode:()=>null,beforeActiveInstanceBlur:()=>{},afterActiveInstanceBlur:()=>{},prepareScopeUpdate:()=>{},getInstanceFromScope:()=>null,detachDeletedInstance:()=>{},requestPostPaintCallback:e=>{},maySuspendCommit:(e,t)=>false,preloadInstance:(e,t)=>true,startSuspendingCommit:()=>{},suspendInstance:(e,t)=>{},waitForCommitToBeReady:()=>null,NotPendingTransition:null,HostTransitionContext:{$$typeof:Symbol.for("react.context"),_currentValue:null},resetFormInstance:e=>{},bindToConsole:(e,t,n)=>Function.prototype.bind.call(console[e],console,...t),supportsResources:false,isHostHoistableType:(e,t)=>false,supportsSingletons:false,isHostSingletonType:e=>false,supportsTestSelectors:false,createInstance(e,t,n,r,o){return wn(e,t)},createTextInstance(e,t,n,r){return {type:"raw-text",text:e,parent:null}},appendInitialChild(e,t){t.type==="raw-text"?Ht(e,t):Lt(e,t);},finalizeInitialChildren(e,t,n,r,o){return false},shouldSetTextContent(e,t){return false},getRootHostContext(e){return {}},getChildHostContext(e,t,n){return e},getPublicInstance(e){return e},prepareForCommit(e){return null},resetAfterCommit(e){e.onCommit();},preparePortalMount(){},appendChild(e,t){t.type==="raw-text"?Ht(e,t):Lt(e,t);},appendChildToContainer(e,t){if(t.type==="raw-text")return;let n=t;n.parent=null,e.children.push(n);},insertBefore(e,t,n){if(t.type==="raw-text")kn(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 Tn(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"?vn(e,t):Rn(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 Xe=$r(Pn);Xe.injectIntoDevTools({bundleType:process.env.NODE_ENV==="production"?0:1,version:"0.1.0",rendererPackageName:"glyph"});var ht=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 En(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 Dr(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 gt(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 Nn(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=Wr(e,n);if(s){t.push(s.key),n=s.end;continue}}if(e[n+1]==="O"){let s=Kr(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 Kr(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 Wr(e,t){let n=t+2,r="";for(;n<e.length;){let l=e.charCodeAt(n);if(l>=48&&l<=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 l=r.split(";"),u=parseInt(l[1]??"1",10),f=parseInt(l[2]??"0",10);i={name:En(f),sequence:s},gt(i,u);break}if(i={name:Dr(r),sequence:s},r.includes(";")){let l=r.split(";"),u=parseInt(l[1]??"1",10);gt(i,u);}break}case "u":{let l=r.split(";"),u=parseInt(l[0]??"0",10),f=parseInt(l[1]??"1",10);i={name:En(u),sequence:s},gt(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 l=r.split(";"),u=parseInt(l[l.length-1]??"1",10);u>=1&&u<=16&>(i,u);}return {key:i,end:n}}var qr={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",blackBright:"\x1B[90m",redBright:"\x1B[91m",greenBright:"\x1B[92m",yellowBright:"\x1B[93m",blueBright:"\x1B[94m",magentaBright:"\x1B[95m",cyanBright:"\x1B[96m",whiteBright:"\x1B[97m"},_r={black:"\x1B[40m",red:"\x1B[41m",green:"\x1B[42m",yellow:"\x1B[43m",blue:"\x1B[44m",magenta:"\x1B[45m",cyan:"\x1B[46m",white:"\x1B[47m",blackBright:"\x1B[100m",redBright:"\x1B[101m",greenBright:"\x1B[102m",yellowBright:"\x1B[103m",blueBright:"\x1B[104m",magentaBright:"\x1B[105m",cyanBright:"\x1B[106m",whiteBright:"\x1B[107m"};function jt(e){let t=e.replace("#",""),n=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),o=parseInt(t.substring(4,6),16);return {r:n,g:r,b:o}}function Gn(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=jt(e);return `\x1B[38;2;${o};${s};${i}m`}return qr[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 Fn(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=jt(e);return `\x1B[48;2;${o};${s};${i}m`}return _r[e]??"\x1B[49m"}if(typeof e=="number")return `\x1B[48;5;${e}m`;let{r:t,g:n,b:r}=e;return `\x1B[48;2;${t};${n};${r}m`}var Bn={black:[0,0,0],red:[170,0,0],green:[0,170,0],yellow:[170,170,0],blue:[0,0,170],magenta:[170,0,170],cyan:[0,170,170],white:[170,170,170],blackBright:[85,85,85],redBright:[255,85,85],greenBright:[85,255,85],yellowBright:[255,255,85],blueBright:[85,85,255],magentaBright:[255,85,255],cyanBright:[85,255,255],whiteBright:[255,255,255]},Mn=["black","red","green","yellow","blue","magenta","cyan","white","blackBright","redBright","greenBright","yellowBright","blueBright","magentaBright","cyanBright","whiteBright"],Ue=null;function Ln(e){e.size>0&&(Ue=e);}function zr(e){if(Ue){let t=Mn.indexOf(e);if(t!==-1){let n=Ue.get(t);if(n)return n}}return Bn[e]??null}function Xr(e){if(typeof e=="string"){if(e.startsWith("#")){let t=jt(e);return [t.r,t.g,t.b]}return zr(e)}if(typeof e=="number"){if(e<16){if(Ue){let s=Ue.get(e);if(s)return s}return Bn[Mn[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 xt(e){let t=Xr(e);if(!t)return false;let[n,r,o]=t.map(i=>{let l=i/255;return l<=.03928?l/12.92:Math.pow((l+.055)/1.055,2.4)});return .2126*n+.7152*r+.0722*o>.4}function Ot(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 Hn(e){return e&&xt(e)?"black":"white"}var Ye=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,l,u,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:l,italic:u,underline:f});}fillRect(t,n,r,o,s,i,l){for(let u=n;u<n+o;u++)for(let f=t;f<t+r;f++)this.setChar(f,u,s,i,l);}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&&Ot(t.fg,n.fg)&&Ot(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 Ur={single:{topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502"},double:{topLeft:"\u2554",topRight:"\u2557",bottomLeft:"\u255A",bottomRight:"\u255D",horizontal:"\u2550",vertical:"\u2551"},round:{topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502"},ascii:{topLeft:"+",topRight:"+",bottomLeft:"+",bottomRight:"+",horizontal:"-",vertical:"|"}};function An(e){return e==="none"?null:Ur[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 u=0;for(let f of o){let a=Ne(f);a>u&&(u=a);}return {width:u,height:o.length}}let s=Math.max(1,Math.floor(t)),i=Pe(o,s,r),l=0;for(let u of i){let f=Ne(u);f>l&&(l=f);}return {width:l,height:i.length}}function Pe(e,t,n){let r=[];for(let o of e){if(Ne(o)<=t){r.push(o);continue}if(n==="truncate"){r.push(jn(o,t));continue}if(n==="ellipsis"){r.push(Jr(o,t));continue}let i=Qr(o,t);r.push(...i);}return r}function jn(e,t){let n="",r=0;for(let o of e){let s=Ne(o);if(r+s>t)break;n+=o,r+=s;}return n}function Jr(e,t){if(t<=1)return t===1?"\u2026":"";let n=jn(e,t-1);return Ne(n)<Ne(e)?n+"\u2026":e}function Qr(e,t){let n=[],r="",o=0,s="",i=0;for(let l=0;l<=e.length;l++){let u=e[l],f=l===e.length,a=u===" ";if(f||a){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 b of s){let I=Ne(b);o+I>t&&r.length>0&&(n.push(r),r="",o=0),r+=b,o+=I;}s="",i=0;}a&&(o+1<=t?(r+=" ",o+=1):(r.length>0&&n.push(r),r=" ",o=1));}else u&&(s+=u,i+=Ne(u));}return r.length>0&&n.push(r),n.length>0?n:[""]}var On={30:"black",31:"red",32:"green",33:"yellow",34:"blue",35:"magenta",36:"cyan",37:"white",90:"blackBright",91:"redBright",92:"greenBright",93:"yellowBright",94:"blueBright",95:"magentaBright",96:"cyanBright",97:"whiteBright"},$n={40:"black",41:"red",42:"green",43:"yellow",44:"blue",45:"magenta",46:"cyan",47:"white",100:"blackBright",101:"redBright",102:"greenBright",103:"yellowBright",104:"blueBright",105:"magentaBright",106:"cyanBright",107:"whiteBright"};function Zr(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:On[r]?t.fg=On[r]:$n[r]&&(t.bg=$n[r]);break}n++;}}function $t(e){let t=[],n={},r="",o=/\x1b\[([0-9;]*)m/g,s=0,i;for(;(i=o.exec(e))!==null;){let u=e.slice(s,i.index);u&&(r+=u),r&&(t.push({text:r,style:{...n}}),r="");let a=(i[1]||"0").split(";").map(b=>parseInt(b,10)||0);Zr(a,n),s=o.lastIndex;}let l=e.slice(s);return l&&(r+=l),r&&t.push({text:r,style:{...n}}),t}function eo(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function Dn(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||Kn(i,s,i.style.zIndex??0,o);o.sort((i,l)=>i.zIndex-l.zIndex);for(let i of o){let l=no(i.node,t,i.clip,n);l?.cursorPosition&&(r.cursorPosition=l.cursorPosition);}return r}function Kn(e,t,n,r){if(e.hidden)return;let o=e.style.zIndex??n,s=e.style.clip?to(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)Kn(i,s,o,r);}function to(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),o=Math.min(e.x+e.width,t.x+t.width),s=Math.min(e.y+e.height,t.y+t.height);return {x:n,y:r,width:Math.max(0,o-n),height:Math.max(0,s-r)}}function yt(e,t,n){return e>=n.x&&e<n.x+n.width&&t>=n.y&&t<n.y+n.height}function no(e,t,n,r={}){let{x:o,y:s,width:i,height:l,innerX:u,innerY:f,innerWidth:a,innerHeight:b}=e.layout,I=e.style;if(i<=0||l<=0)return;let R=mt(e).bg;if(I.bg)for(let
|
|
3
|
-
`)I.push(b.length);else {let B={color:h.style.fg??
|
|
4
|
-
`),T=Pe(E,u,D),$=0,N=0;if(j){let p=o.position,w=0,k=p,P=0;for(let z=0;z<E.length;z++){let H=E[z].length;if(p<=P+H){w=z,k=p-P;break}P+=H+1;}let K=0;for(let z=0;z<w;z++)K+=Pe([E[z]],u,D).length;let M=Pe([E[w]],u,D),_=0,W=0;for(let z=0;z<M.length;z++){let H=M[z];if(k<=_+H.length){W=z;break}_+=H.length;}$=K+W,N=Ne(E[w].slice(_,_+(k-_)));}let V=Math.max(0,$-f+1);for(let p=0;p<f;p++){let w=V+p;if(w>=T.length)break;let k=T[w],P=0;for(let K of k){if(P>=u)break;let M=Ne(K);M>0&&Se(t,n,i+P,l+p,K,C,m.bg,m.bold,B,m.italic,m.underline),P+=M;}}if(j){let p=$-V;if(p>=0&&p<f){let w=Math.min(N,u-1),k=i+w,P=l+p;if(yt(k,P,n)&&k<i+u)if(s)L={cursorPosition:{x:k,y:P,bg:m.bg}};else {let K=t.get(k,P),M=K?.ch&&K.ch!==" "?K.ch:"\u258C",_=m.bg??"black",W=m.color??"white";t.setChar(k,P,M,_,W,K?.bold,K?.dim,K?.italic,false);}}}}else {let D=0;for(let E of I){if(D>=u)break;let T=Ne(E);T>0&&Se(t,n,i+D,l,E,C,m.bg,m.bold,B,m.italic,m.underline),D+=T;}if(j){let E=Math.min(o.position,u-1),T=i+E;if(yt(T,l,n)&&T<i+u)if(s)L={cursorPosition:{x:T,y:l,bg:m.bg}};else {let $=t.get(T,l),N=$?.ch&&$.ch!==" "?$.ch:"\u258C",V=m.bg??"black",p=m.color??"white";t.setChar(T,l,N,V,p,$?.bold,$?.dim,$?.italic,false);}}}return L}var so="\x1B",Le=`${so}[`;function io(e,t){return `${Le}${t+1};${e+1}H`}function lo(e){let t=`${Le}0m`;return e.bold&&(t+=`${Le}1m`),e.dim&&(t+=`${Le}2m`),e.italic&&(t+=`${Le}3m`),e.underline&&(t+=`${Le}4m`),e.fg!=null&&(t+=Gn(e.fg)),e.bg!=null&&(t+=Fn(e.bg)),t}function qn(e,t,n){let r="",o=-1,s=-1,i="";for(let l=0;l<t.height;l++)for(let u=0;u<t.width;u++){let f=t.get(u,l);if(!n){let b=e.get(u,l);if(b&&t.cellsEqual(f,b))continue}(s!==l||o!==u)&&(r+=io(u,l));let a=lo(f);a!==i&&(r+=a,i=a),r+=f.ch,o=u+1,s=l;}return r.length>0&&(r+=`${Le}0m`),r}var fo={row:FlexDirection.Row,column:FlexDirection.Column},po={"flex-start":Justify.FlexStart,center:Justify.Center,"flex-end":Justify.FlexEnd,"space-between":Justify.SpaceBetween,"space-around":Justify.SpaceAround},mo={"flex-start":Align.FlexStart,center:Align.Center,"flex-end":Align.FlexEnd,stretch:Align.Stretch};function Xn(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%"),t(n));}function Ge(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%")?e.setPositionPercent(t,parseFloat(n)):e.setPosition(t,n));}function ho(e,t,n){Xn(e,o=>e.setWidth(o),t.width),Xn(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(fo[t.flexDirection]??FlexDirection.Column),t.flexWrap&&e.setFlexWrap(t.flexWrap==="wrap"?Wrap.Wrap:Wrap.NoWrap),t.justifyContent&&e.setJustifyContent(po[t.justifyContent]??Justify.FlexStart),t.alignItems&&e.setAlignItems(mo[t.alignItems]??Align.Stretch),t.flexGrow!==void 0&&e.setFlexGrow(t.flexGrow),t.flexShrink!==void 0&&e.setFlexShrink(t.flexShrink),t.gap!==void 0&&e.setGap(Gutter.All,t.gap),t.position==="absolute"?e.setPositionType(PositionType.Absolute):e.setPositionType(PositionType.Relative),t.inset!==void 0&&(Ge(e,Edge.Top,t.inset),Ge(e,Edge.Right,t.inset),Ge(e,Edge.Bottom,t.inset),Ge(e,Edge.Left,t.inset)),Ge(e,Edge.Top,t.top),Ge(e,Edge.Right,t.right),Ge(e,Edge.Bottom,t.bottom),Ge(e,Edge.Left,t.left),t.clip&&e.setOverflow(Overflow.Hidden);}function Yn(e){let t=Un.Node.create();if(e.yogaNode=t,ho(t,e.style,e.type),e.type==="text"||e.type==="input")t.setMeasureFunc((n,r,o,s)=>{let i;return e.type==="input"?(i=e.props.value??e.props.defaultValue??e.props.placeholder??"",i.length===0&&(i=" ")):i=Jn(e),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||(Yn(r),t.insertChild(r.yogaNode,t.getChildCount()));}}function Jn(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=Jn(n);if(t===""&&e.props.children!=null){if(typeof e.props.children=="string")return e.props.children;if(typeof e.props.children=="number")return String(e.props.children)}return t}function Qn(e,t,n){let r=e.yogaNode,o=r.getComputedLayout(),s=t+o.left,i=n+o.top,l=o.width,u=o.height,f=e.style.border&&e.style.border!=="none"?1:0,a=r.getComputedPadding(Edge.Top),b=r.getComputedPadding(Edge.Right),I=r.getComputedPadding(Edge.Bottom),S=r.getComputedPadding(Edge.Left),R=s+f+S,m=i+f+a,x=Math.max(0,l-f*2-S-b),g=Math.max(0,u-f*2-a-I),h=e.layout;(!h||h.x!==s||h.y!==i||h.width!==l||h.height!==u||h.innerX!==R||h.innerY!==m||h.innerWidth!==x||h.innerHeight!==g)&&(e.layout={x:s,y:i,width:l,height:u,innerX:R,innerY:m,innerWidth:x,innerHeight:g});for(let C of e.children)C.hidden||!C.yogaNode||Qn(C,s,i);}function Zn(e,t,n){let r=Un.Node.create();r.setWidth(t),r.setHeight(n),r.setFlexDirection(FlexDirection.Column);for(let o of e)o.hidden||(Yn(o),r.insertChild(o.yogaNode,r.getChildCount()));r.calculateLayout(t,n,Direction.LTR);for(let o of e)o.hidden||!o.yogaNode||Qn(o,0,0);r.freeRecursive(),er(e);}function er(e){for(let t of e)t.yogaNode=null,er(t.children);}var Z=createContext(null),Y=createContext(null),pe=createContext(null),Fe=createContext(null),De=createContext(null),Ct=createContext(null);var ce=null;function Ze(e=false){if(ce)return ce;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||"",l=process.env.KONSOLE_VERSION;return r||t==="xterm-kitty"?(ce={name:"kitty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},ce):o||t.includes("ghostty")?(ce={name:"ghostty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},ce):s||n==="WezTerm"?(ce={name:"wezterm",supportsKittyGraphics:true,supportsIterm2Images:true,supportsSixel:true},ce):n==="iTerm.app"||i==="iTerm2"?(ce={name:"iterm2",supportsKittyGraphics:false,supportsIterm2Images:true,supportsSixel:false},ce):l?(ce={name:"konsole",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:true},ce):n==="vscode"?(ce={name:"vscode",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},ce):(ce={name:"unknown",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},ce)}function Dt(){let e=Ze();return e.supportsKittyGraphics||e.supportsIterm2Images||e.supportsSixel}var ue="\x1B";function St(){return !!process.env.TMUX}function Kt(e){if(!St())return e;let t=e.replace(/\x1b/g,"\x1B\x1B");return `${ue}Ptmux;${t}${ue}\\`}function tr(e){let t=Ze();return t.supportsKittyGraphics?go(e):t.supportsIterm2Images?xo(e):null}function Wt(e){if(Ze().supportsKittyGraphics){let n;return e!==void 0?n=`${ue}_Ga=d,d=i,i=${e}${ue}\\`:n=`${ue}_Ga=d,d=a${ue}\\`,Kt(n)}return null}function go(e){let{data:t,width:n,height:r,x:o,y:s,id:i}=e,l=t.toString("base64"),u=`${ue}[${s+1};${o+1}H`,f=qt(t),a="a=T,f=100";i!==void 0&&(a+=`,i=${i}`),f&&(a+=`,s=${f.width},v=${f.height}`),a+=`,c=${n},r=${r}`;let b=4096,I=[u];St()&&I.unshift(`${ue}[?25l`);for(let S=0;S<l.length;S+=b){let R=l.slice(S,S+b),x=S+b>=l.length?"m=0":"m=1",g;S===0?g=`${ue}_G${a},${x},q=2;${R}${ue}\\`:g=`${ue}_G${x};${R}${ue}\\`,I.push(Kt(g));}return St()&&I.push(`${ue}[?25h`),I.join("")}function xo(e){let{data:t,width:n,height:r,x:o,y:s}=e,i=t.toString("base64"),l=`${ue}[${s+1};${o+1}H`,u=[`width=${n}`,`height=${r}`,"preserveAspectRatio=1","inline=1"].join(";"),f=`${ue}]1337;File=${u}:${i}\x07`;return l+(St()?Kt(f):f)}function qt(e){if(e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e.length>=24){let t=e.readUInt32BE(16),n=e.readUInt32BE(20);return {width:t,height:n}}if(e[0]===255&&e[1]===216&&e[2]===255){let t=2;for(;t<e.length-8;){if(e[t]!==255){t++;continue}let n=e[t+1];if(n!==void 0&&(n>=192&&n<=195||n>=197&&n<=199||n>=201&&n<=203||n>=205&&n<=207)){let o=e.readUInt16BE(t+5);return {width:e.readUInt16BE(t+7),height:o}}let r=e.readUInt16BE(t+2);t+=2+r;}}if(e[0]===71&&e[1]===73&&e[2]===70&&e.length>=10){let t=e.readUInt16LE(6),n=e.readUInt16LE(8);return {width:t,height:n}}return null}function yo(e,t={}){let n=t.stdout??process.stdout,r=t.stdin??process.stdin,o=t.debug??false,s=t.useNativeCursor??true,i=new ht(n,r);i.setup();let l=false;i.queryPalette().then(c=>{Ln(c),a=true,M();});let u=new Ye(i.columns,i.rows),f=new Ye(i.columns,i.rows),a=true,b=new Set,I=new Set,S=new Map,R={subscribe(c){return b.add(c),()=>b.delete(c)},subscribePriority(c){return I.add(c),()=>I.delete(c)},registerInputHandler(c,y){return S.set(c,y),()=>S.delete(c)}},m=new Map,x=new Map,g={registerImage(c){let y=m.get(c.id);(!y||y.x!==c.x||y.y!==c.y||y.width!==c.width||y.height!==c.height)&&(x.set(c.id,c),M());},unregisterImage(c){m.delete(c),x.delete(c);let y=Wt(c);y&&i.write(y),M();}};function h(){for(let c of x.values()){let y=tr({data:c.data,width:c.width,height:c.height,x:c.x,y:c.y,id:c.id});y&&(i.write(y),m.set(c.id,{x:c.x,y:c.y,width:c.width,height:c.height}));}x.clear();}let C=null,B=new Map,j=[],L=new Set,D=new Set,E=[],T=new Set;function $(c){if(C!==c){C=c,M();for(let y of T)y(C);}}function N(){let c=[...j];if(E.length>0){let y=E[E.length-1];c=c.filter(F=>y.has(F));}return c=c.filter(y=>!L.has(y)),c.sort((y,F)=>{let v=B.get(y),X=B.get(F);if(!v||!X)return 0;let d=v.layout,G=X.layout;return d.y!==G.y?d.y-G.y:d.x-G.x}),c}let V={get focusedId(){return C},register(c,y,F=true){if(B.set(c,y),j.includes(c)||j.push(c),F||D.add(c),E.length>0&&E[E.length-1].add(c),C===null&&F){let v=N().filter(X=>!D.has(X));v.length>0&&$(v[0]);}return ()=>{B.delete(c),D.delete(c);let v=j.indexOf(c);if(v!==-1&&j.splice(v,1),C===c){let X=N().filter(d=>!D.has(d));$(X[0]??null);}}},requestFocus(c){$(c);},blur(){$(null);},focusNext(){let c=N();if(c.length===0)return;let F=((C?c.indexOf(C):-1)+1)%c.length;$(c[F]);},focusPrev(){let c=N();if(c.length===0)return;let F=((C?c.indexOf(C):0)-1+c.length)%c.length;$(c[F]);},setSkippable(c,y){if(y){if(L.add(c),C===c){let F=N();F.length>0&&$(F[0]);}}else L.delete(c);},trapIds:null,pushTrap(c){return E.push(c),()=>{let y=E.indexOf(c);y!==-1&&E.splice(y,1);}},onFocusChange(c){return T.add(c),()=>{T.delete(c);}},getRegisteredElements(){let c=[];for(let y of j){if(L.has(y))continue;let F=B.get(y);F&&c.push({id:y,node:F});}return c},getActiveElements(){let c=N(),y=[];for(let F of c){if(L.has(F))continue;let v=B.get(F);v&&y.push({id:F,node:v});}return y}},p=new Map,w={getLayout(c){return c.layout},subscribe(c,y){return p.has(c)||p.set(c,new Set),p.get(c).add(y),()=>{let F=p.get(c);F&&(F.delete(y),F.size===0&&p.delete(c));}}},k={registerNode(){},unregisterNode(){},scheduleRender:M,exit(c){ee.exit(c);},get columns(){return i.columns},get rows(){return i.rows}},P={type:"root",children:[],onCommit(){M();}},K=false;function M(){K||(K=true,queueMicrotask(()=>{K=false,_();}));}function _(){let c=i.columns,y=i.rows;(f.width!==c||f.height!==y)&&(f.resize(c,y),u.resize(c,y),a=true),Zn(P.children,c,y),W(P.children);let F;if(C){let d=B.get(C);d?.type==="input"&&(F={nodeId:C,position:d.props.cursorPosition??d.props.value?.length??0});}let v=Dn(P.children,f,{cursorInfo:F,useNativeCursor:s}),X=qn(u,f,a);if(X.length>0&&i.write(X),x.size>0&&l&&(i.hideCursor(),l=false),h(),s)if(v.cursorPosition){let d=Hn(v.cursorPosition.bg);i.setCursorColor(d),i.moveCursor(v.cursorPosition.x,v.cursorPosition.y),l||(i.showCursor(),l=true);}else i.hideCursor(),l=false;for(let d=0;d<f.cells.length;d++)u.cells[d]={...f.cells[d]};a=false;}function W(c){for(let y of c){let F=p.get(y);if(F)for(let v of F)v(y.layout);W(y.children);}}let z=i.onData(c=>{let y=Nn(c);for(let F of y){if(F.ctrl&&F.name==="c"){ee.exit();return}if(F.ctrl&&F.name==="z"){i.suspend(),process.kill(0,"SIGSTOP");return}let v=false;for(let X of I)if(X(F)){v=true;break}if(!v&&C){let X=S.get(C);X&&(v=X(F));}if(!v&&F.name==="tab"&&!F.ctrl&&!F.alt){F.shift?V.focusPrev():V.focusNext();continue}if(!v)for(let X of b)X(F);}}),H=i.onResize(()=>{a=true,M();}),J=()=>{i.resume(),a=true,M();};process.on("SIGCONT",J);let A=ae.createElement(Fe.Provider,{value:k},ae.createElement(Z.Provider,{value:R},ae.createElement(Y.Provider,{value:V},ae.createElement(pe.Provider,{value:w},ae.createElement(Ct.Provider,{value:g},e))))),le=c=>{o&&console.error("Uncaught error:",c);},fe=c=>{o&&console.error("Error caught by boundary:",c);},Ie=c=>{o&&console.error("Recoverable error:",c);},Q=Xe.createContainer(P,0,null,false,null,"",le,fe,Ie,null);Xe.updateContainer(A,Q,null,null);let ee={unmount(){Xe.updateContainer(null,Q,null,null),z(),H(),process.off("SIGCONT",J);let c=Wt();c&&i.write(c),i.cleanup();},exit(c){ee.unmount(),process.exit(c??0);}};return ee}var So=forwardRef(function({children:t,style:n,focusable:r},o){return ae.createElement("box",{style:n,focusable:r,ref:o},t)});var Po=forwardRef(function({children:t,style:n,wrap:r,focusable:o,focusedStyle:s},i){let l=useContext(Y),u=useRef(null),f=useRef(null),[a,b]=useState(false);useImperativeHandle(i,()=>({focus(){l&&f.current&&l.requestFocus(f.current);},blur(){l&&l.blur();},get isFocused(){return a}}),[l,a]),useEffect(()=>{if(!l||!o||!f.current)return;let R=f.current;return b(l.focusedId===R),l.onFocusChange(m=>{b(m===R);})},[l,o]);let I=r?{...n,wrap:r}:n;a&&s&&(I={...I,...s});let S=R=>{u.current=R,f.current=R?.focusId??null;};return ae.createElement("text",{style:I,focusable:o,ref:S},t)});function rr(e,t,n){if(n<=0)return {visualLine:0,visualCol:t,totalVisualLines:1,lineStartOffset:0,lineLength:e.length};let r=e.split(`
|
|
2
|
+
`);if(n===MeasureMode.Undefined||r==="none"){let u=0;for(let f of o){let a=Ne(f);a>u&&(u=a);}return {width:u,height:o.length}}let s=Math.max(1,Math.floor(t)),i=Pe(o,s,r),l=0;for(let u of i){let f=Ne(u);f>l&&(l=f);}return {width:l,height:i.length}}function Pe(e,t,n){let r=[];for(let o of e){if(Ne(o)<=t){r.push(o);continue}if(n==="truncate"){r.push(jn(o,t));continue}if(n==="ellipsis"){r.push(Jr(o,t));continue}let i=Qr(o,t);r.push(...i);}return r}function jn(e,t){let n="",r=0;for(let o of e){let s=Ne(o);if(r+s>t)break;n+=o,r+=s;}return n}function Jr(e,t){if(t<=1)return t===1?"\u2026":"";let n=jn(e,t-1);return Ne(n)<Ne(e)?n+"\u2026":e}function Qr(e,t){let n=[],r="",o=0,s="",i=0;for(let l=0;l<=e.length;l++){let u=e[l],f=l===e.length,a=u===" ";if(f||a){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 b of s){let I=Ne(b);o+I>t&&r.length>0&&(n.push(r),r="",o=0),r+=b,o+=I;}s="",i=0;}a&&(o+1<=t?(r+=" ",o+=1):(r.length>0&&n.push(r),r=" ",o=1));}else u&&(s+=u,i+=Ne(u));}return r.length>0&&n.push(r),n.length>0?n:[""]}var On={30:"black",31:"red",32:"green",33:"yellow",34:"blue",35:"magenta",36:"cyan",37:"white",90:"blackBright",91:"redBright",92:"greenBright",93:"yellowBright",94:"blueBright",95:"magentaBright",96:"cyanBright",97:"whiteBright"},$n={40:"black",41:"red",42:"green",43:"yellow",44:"blue",45:"magenta",46:"cyan",47:"white",100:"blackBright",101:"redBright",102:"greenBright",103:"yellowBright",104:"blueBright",105:"magentaBright",106:"cyanBright",107:"whiteBright"};function Zr(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:On[r]?t.fg=On[r]:$n[r]&&(t.bg=$n[r]);break}n++;}}function $t(e){let t=[],n={},r="",o=/\x1b\[([0-9;]*)m/g,s=0,i;for(;(i=o.exec(e))!==null;){let u=e.slice(s,i.index);u&&(r+=u),r&&(t.push({text:r,style:{...n}}),r="");let a=(i[1]||"0").split(";").map(b=>parseInt(b,10)||0);Zr(a,n),s=o.lastIndex;}let l=e.slice(s);return l&&(r+=l),r&&t.push({text:r,style:{...n}}),t}function eo(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function Dn(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||Kn(i,s,i.style.zIndex??0,o);o.sort((i,l)=>i.zIndex-l.zIndex);for(let i of o){let l=no(i.node,t,i.clip,n);l?.cursorPosition&&(r.cursorPosition=l.cursorPosition);}return r}function Kn(e,t,n,r){if(e.hidden)return;let o=e.style.zIndex??n,s=e.style.clip?to(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)Kn(i,s,o,r);}function to(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),o=Math.min(e.x+e.width,t.x+t.width),s=Math.min(e.y+e.height,t.y+t.height);return {x:n,y:r,width:Math.max(0,o-n),height:Math.max(0,s-r)}}function yt(e,t,n){return e>=n.x&&e<n.x+n.width&&t>=n.y&&t<n.y+n.height}function no(e,t,n,r={}){let{x:o,y:s,width:i,height:l,innerX:u,innerY:f,innerWidth:a,innerHeight:b}=e.layout,I=e.style;if(i<=0||l<=0)return;let R=mt(e).bg;if(I.bg)for(let y=s;y<s+l;y++)for(let g=o;g<o+i;g++)yt(g,y,n)&&t.setChar(g,y," ",void 0,I.bg);let m=I.border?An(I.border):null;if(m&&i>=2&&l>=2){let y=I.borderColor,g=R;Se(t,n,o,s,m.topLeft,y,g);for(let h=o+1;h<o+i-1;h++)Se(t,n,h,s,m.horizontal,y,g);Se(t,n,o+i-1,s,m.topRight,y,g),Se(t,n,o,s+l-1,m.bottomLeft,y,g);for(let h=o+1;h<o+i-1;h++)Se(t,n,h,s+l-1,m.horizontal,y,g);Se(t,n,o+i-1,s+l-1,m.bottomRight,y,g);for(let h=s+1;h<s+l-1;h++)Se(t,n,o,h,m.vertical,y,g),Se(t,n,o+i-1,h,m.vertical,y,g);}if(e.type==="text")ro(e,t,n);else if(e.type==="input")return oo(e,t,n,r)}function Se(e,t,n,r,o,s,i,l,u,f,a){yt(n,r,t)&&e.setChar(n,r,o,s,i,l,u,f,a);}function Wn(e,t){if(e!==void 0)return e;if(t!==void 0)return xt(t)?"black":"white"}function ro(e,t,n){let{innerX:r,innerY:o,innerWidth:s,innerHeight:i}=e.layout,l=mt(e),u=At(e,l);if(u.length===0)return;let f=e.style.wrap??"wrap",a=e.style.textAlign??"left",b=[],I=[];for(let y of u){let g=$t(y.text);for(let h of g)for(let C of h.text)if(C===`
|
|
3
|
+
`)I.push(b.length);else {let B={color:h.style.fg??y.style.color,bg:h.style.bg??y.style.bg,bold:h.style.bold??y.style.bold,dim:h.style.dim??y.style.dim,italic:h.style.italic??y.style.italic,underline:h.style.underline??y.style.underline};b.push({char:C,style:B});}}let S=[],R=0;for(let y of I)S.push(b.slice(R,y)),R=y;S.push(b.slice(R));let m=[];for(let y of S){if(y.length===0){m.push([]);continue}let g=y.map(B=>B.char).join(""),h=Pe([g],s,f),C=0;for(let B of h){let j=[];for(let H of B)C<y.length&&(j.push(y[C]),C++);m.push(j);}}for(let y=0;y<m.length&&y<i;y++){let g=m[y],h=g.reduce((j,H)=>j+Ne(H.char),0),C=0;a==="center"?C=Math.max(0,Math.floor((s-h)/2)):a==="right"&&(C=Math.max(0,s-h));let B=0;for(let{char:j,style:H}of g){let D=Ne(j);if(D>0){let E=Wn(H.color,H.bg);Se(t,n,r+C+B,o+y,j,E,H.bg,H.bold,H.dim,H.italic,H.underline);}B+=D;}}}function oo(e,t,n,r={}){let{cursorInfo:o,useNativeCursor:s}=r,{innerX:i,innerY:l,innerWidth:u,innerHeight:f}=e.layout;if(u<=0||f<=0)return;let a=e.props.value??e.props.defaultValue??"",b=e.props.placeholder??"",I=a||b,S=!a&&!!b,R=e.props.multiline??false,m=mt(e),y=Wn(m.color,m.bg),g=m.bg?xt(m.bg)?"blackBright":"whiteBright":"blackBright",h=S?g:y??m.color??e.style.color,C=S?g:h,B=S?true:m.dim,j=o&&o.nodeId===e.focusId,H;if(R&&!S){let D=e.style.wrap??"wrap",E=I.split(`
|
|
4
|
+
`),T=Pe(E,u,D),$=0,N=0;if(j){let p=o.position,w=0,k=p,P=0;for(let z=0;z<E.length;z++){let A=E[z].length;if(p<=P+A){w=z,k=p-P;break}P+=A+1;}let K=0;for(let z=0;z<w;z++)K+=Pe([E[z]],u,D).length;let M=Pe([E[w]],u,D),_=0,W=0;for(let z=0;z<M.length;z++){let A=M[z];if(k<=_+A.length){W=z;break}_+=A.length;}$=K+W,N=Ne(E[w].slice(_,_+(k-_)));}let V=Math.max(0,$-f+1);for(let p=0;p<f;p++){let w=V+p;if(w>=T.length)break;let k=T[w],P=0;for(let K of k){if(P>=u)break;let M=Ne(K);M>0&&Se(t,n,i+P,l+p,K,C,m.bg,m.bold,B,m.italic,m.underline),P+=M;}}if(j){let p=$-V;if(p>=0&&p<f){let w=Math.min(N,u-1),k=i+w,P=l+p;if(yt(k,P,n)&&k<i+u)if(s)H={cursorPosition:{x:k,y:P,bg:m.bg}};else {let K=t.get(k,P),M=K?.ch&&K.ch!==" "?K.ch:"\u258C",_=m.bg??"black",W=m.color??"white";t.setChar(k,P,M,_,W,K?.bold,K?.dim,K?.italic,false);}}}}else {let D=0;for(let E of I){if(D>=u)break;let T=Ne(E);T>0&&Se(t,n,i+D,l,E,C,m.bg,m.bold,B,m.italic,m.underline),D+=T;}if(j){let E=Math.min(o.position,u-1),T=i+E;if(yt(T,l,n)&&T<i+u)if(s)H={cursorPosition:{x:T,y:l,bg:m.bg}};else {let $=t.get(T,l),N=$?.ch&&$.ch!==" "?$.ch:"\u258C",V=m.bg??"black",p=m.color??"white";t.setChar(T,l,N,V,p,$?.bold,$?.dim,$?.italic,false);}}}return H}var so="\x1B",Le=`${so}[`;function io(e,t){return `${Le}${t+1};${e+1}H`}function lo(e){let t=`${Le}0m`;return e.bold&&(t+=`${Le}1m`),e.dim&&(t+=`${Le}2m`),e.italic&&(t+=`${Le}3m`),e.underline&&(t+=`${Le}4m`),e.fg!=null&&(t+=Gn(e.fg)),e.bg!=null&&(t+=Fn(e.bg)),t}function qn(e,t,n){let r="",o=-1,s=-1,i="";for(let l=0;l<t.height;l++)for(let u=0;u<t.width;u++){let f=t.get(u,l);if(!n){let b=e.get(u,l);if(b&&t.cellsEqual(f,b))continue}(s!==l||o!==u)&&(r+=io(u,l));let a=lo(f);a!==i&&(r+=a,i=a),r+=f.ch,o=u+1,s=l;}return r.length>0&&(r+=`${Le}0m`),r}var fo={row:FlexDirection.Row,column:FlexDirection.Column},po={"flex-start":Justify.FlexStart,center:Justify.Center,"flex-end":Justify.FlexEnd,"space-between":Justify.SpaceBetween,"space-around":Justify.SpaceAround},mo={"flex-start":Align.FlexStart,center:Align.Center,"flex-end":Align.FlexEnd,stretch:Align.Stretch};function Xn(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%"),t(n));}function Ge(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%")?e.setPositionPercent(t,parseFloat(n)):e.setPosition(t,n));}function ho(e,t,n){Xn(e,o=>e.setWidth(o),t.width),Xn(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(fo[t.flexDirection]??FlexDirection.Column),t.flexWrap&&e.setFlexWrap(t.flexWrap==="wrap"?Wrap.Wrap:Wrap.NoWrap),t.justifyContent&&e.setJustifyContent(po[t.justifyContent]??Justify.FlexStart),t.alignItems&&e.setAlignItems(mo[t.alignItems]??Align.Stretch),t.flexGrow!==void 0&&e.setFlexGrow(t.flexGrow),t.flexShrink!==void 0&&e.setFlexShrink(t.flexShrink),t.gap!==void 0&&e.setGap(Gutter.All,t.gap),t.position==="absolute"?e.setPositionType(PositionType.Absolute):e.setPositionType(PositionType.Relative),t.inset!==void 0&&(Ge(e,Edge.Top,t.inset),Ge(e,Edge.Right,t.inset),Ge(e,Edge.Bottom,t.inset),Ge(e,Edge.Left,t.inset)),Ge(e,Edge.Top,t.top),Ge(e,Edge.Right,t.right),Ge(e,Edge.Bottom,t.bottom),Ge(e,Edge.Left,t.left),t.clip&&e.setOverflow(Overflow.Hidden);}function Yn(e){let t=Un.Node.create();if(e.yogaNode=t,ho(t,e.style,e.type),e.type==="text"||e.type==="input")t.setMeasureFunc((n,r,o,s)=>{let i;return e.type==="input"?(i=e.props.value??e.props.defaultValue??e.props.placeholder??"",i.length===0&&(i=" ")):i=Jn(e),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||(Yn(r),t.insertChild(r.yogaNode,t.getChildCount()));}}function Jn(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=Jn(n);if(t===""&&e.props.children!=null){if(typeof e.props.children=="string")return e.props.children;if(typeof e.props.children=="number")return String(e.props.children)}return t}function Qn(e,t,n){let r=e.yogaNode,o=r.getComputedLayout(),s=t+o.left,i=n+o.top,l=o.width,u=o.height,f=e.style.border&&e.style.border!=="none"?1:0,a=r.getComputedPadding(Edge.Top),b=r.getComputedPadding(Edge.Right),I=r.getComputedPadding(Edge.Bottom),S=r.getComputedPadding(Edge.Left),R=s+f+S,m=i+f+a,y=Math.max(0,l-f*2-S-b),g=Math.max(0,u-f*2-a-I),h=e.layout;(!h||h.x!==s||h.y!==i||h.width!==l||h.height!==u||h.innerX!==R||h.innerY!==m||h.innerWidth!==y||h.innerHeight!==g)&&(e.layout={x:s,y:i,width:l,height:u,innerX:R,innerY:m,innerWidth:y,innerHeight:g});for(let C of e.children)C.hidden||!C.yogaNode||Qn(C,s,i);}function Zn(e,t,n){let r=Un.Node.create();r.setWidth(t),r.setHeight(n),r.setFlexDirection(FlexDirection.Column);for(let o of e)o.hidden||(Yn(o),r.insertChild(o.yogaNode,r.getChildCount()));r.calculateLayout(t,n,Direction.LTR);for(let o of e)o.hidden||!o.yogaNode||Qn(o,0,0);r.freeRecursive(),er(e);}function er(e){for(let t of e)t.yogaNode=null,er(t.children);}var Z=createContext(null),Y=createContext(null),pe=createContext(null),Fe=createContext(null),De=createContext(null),Ct=createContext(null);var ce=null;function Ze(e=false){if(ce)return ce;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||"",l=process.env.KONSOLE_VERSION;return r||t==="xterm-kitty"?(ce={name:"kitty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},ce):o||t.includes("ghostty")?(ce={name:"ghostty",supportsKittyGraphics:true,supportsIterm2Images:false,supportsSixel:false},ce):s||n==="WezTerm"?(ce={name:"wezterm",supportsKittyGraphics:true,supportsIterm2Images:true,supportsSixel:true},ce):n==="iTerm.app"||i==="iTerm2"?(ce={name:"iterm2",supportsKittyGraphics:false,supportsIterm2Images:true,supportsSixel:false},ce):l?(ce={name:"konsole",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:true},ce):n==="vscode"?(ce={name:"vscode",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},ce):(ce={name:"unknown",supportsKittyGraphics:false,supportsIterm2Images:false,supportsSixel:false},ce)}function Dt(){let e=Ze();return e.supportsKittyGraphics||e.supportsIterm2Images||e.supportsSixel}var ue="\x1B";function St(){return !!process.env.TMUX}function Kt(e){if(!St())return e;let t=e.replace(/\x1b/g,"\x1B\x1B");return `${ue}Ptmux;${t}${ue}\\`}function tr(e){let t=Ze();return t.supportsKittyGraphics?go(e):t.supportsIterm2Images?xo(e):null}function Wt(e){if(Ze().supportsKittyGraphics){let n;return e!==void 0?n=`${ue}_Ga=d,d=i,i=${e}${ue}\\`:n=`${ue}_Ga=d,d=a${ue}\\`,Kt(n)}return null}function go(e){let{data:t,width:n,height:r,x:o,y:s,id:i}=e,l=t.toString("base64"),u=`${ue}[${s+1};${o+1}H`,f=qt(t),a="a=T,f=100";i!==void 0&&(a+=`,i=${i}`),f&&(a+=`,s=${f.width},v=${f.height}`),a+=`,c=${n},r=${r}`;let b=4096,I=[u];St()&&I.unshift(`${ue}[?25l`);for(let S=0;S<l.length;S+=b){let R=l.slice(S,S+b),y=S+b>=l.length?"m=0":"m=1",g;S===0?g=`${ue}_G${a},${y},q=2;${R}${ue}\\`:g=`${ue}_G${y};${R}${ue}\\`,I.push(Kt(g));}return St()&&I.push(`${ue}[?25h`),I.join("")}function xo(e){let{data:t,width:n,height:r,x:o,y:s}=e,i=t.toString("base64"),l=`${ue}[${s+1};${o+1}H`,u=[`width=${n}`,`height=${r}`,"preserveAspectRatio=1","inline=1"].join(";"),f=`${ue}]1337;File=${u}:${i}\x07`;return l+(St()?Kt(f):f)}function qt(e){if(e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e.length>=24){let t=e.readUInt32BE(16),n=e.readUInt32BE(20);return {width:t,height:n}}if(e[0]===255&&e[1]===216&&e[2]===255){let t=2;for(;t<e.length-8;){if(e[t]!==255){t++;continue}let n=e[t+1];if(n!==void 0&&(n>=192&&n<=195||n>=197&&n<=199||n>=201&&n<=203||n>=205&&n<=207)){let o=e.readUInt16BE(t+5);return {width:e.readUInt16BE(t+7),height:o}}let r=e.readUInt16BE(t+2);t+=2+r;}}if(e[0]===71&&e[1]===73&&e[2]===70&&e.length>=10){let t=e.readUInt16LE(6),n=e.readUInt16LE(8);return {width:t,height:n}}return null}function yo(e,t={}){let n=t.stdout??process.stdout,r=t.stdin??process.stdin,o=t.debug??false,s=t.useNativeCursor??true,i=new ht(n,r);i.setup();let l=false;i.queryPalette().then(c=>{Ln(c),a=true,M();});let u=new Ye(i.columns,i.rows),f=new Ye(i.columns,i.rows),a=true,b=new Set,I=new Set,S=new Map,R={subscribe(c){return b.add(c),()=>b.delete(c)},subscribePriority(c){return I.add(c),()=>I.delete(c)},registerInputHandler(c,x){return S.set(c,x),()=>S.delete(c)}},m=new Map,y=new Map,g={registerImage(c){let x=m.get(c.id);(!x||x.x!==c.x||x.y!==c.y||x.width!==c.width||x.height!==c.height)&&(y.set(c.id,c),M());},unregisterImage(c){m.delete(c),y.delete(c);let x=Wt(c);x&&i.write(x),M();}};function h(){for(let c of y.values()){let x=tr({data:c.data,width:c.width,height:c.height,x:c.x,y:c.y,id:c.id});x&&(i.write(x),m.set(c.id,{x:c.x,y:c.y,width:c.width,height:c.height}));}y.clear();}let C=null,B=new Map,j=[],H=new Set,D=new Set,E=[],T=new Set;function $(c){if(C!==c){C=c,M();for(let x of T)x(C);}}function N(){let c=[...j];if(E.length>0){let x=E[E.length-1];c=c.filter(G=>x.has(G));}return c=c.filter(x=>!H.has(x)),c.sort((x,G)=>{let v=B.get(x),X=B.get(G);if(!v||!X)return 0;let d=v.layout,F=X.layout;return d.y!==F.y?d.y-F.y:d.x-F.x}),c}let V={get focusedId(){return C},register(c,x,G=true){if(B.set(c,x),j.includes(c)||j.push(c),G||D.add(c),E.length>0&&E[E.length-1].add(c),C===null&&G){let v=N().filter(X=>!D.has(X));v.length>0&&$(v[0]);}return ()=>{B.delete(c),D.delete(c);let v=j.indexOf(c);if(v!==-1&&j.splice(v,1),C===c){let X=N().filter(d=>!D.has(d));$(X[0]??null);}}},requestFocus(c){$(c);},blur(){$(null);},focusNext(){let c=N();if(c.length===0)return;let G=((C?c.indexOf(C):-1)+1)%c.length;$(c[G]);},focusPrev(){let c=N();if(c.length===0)return;let G=((C?c.indexOf(C):0)-1+c.length)%c.length;$(c[G]);},setSkippable(c,x){if(x){if(H.add(c),C===c){let G=N();G.length>0&&$(G[0]);}}else H.delete(c);},trapIds:null,pushTrap(c){return E.push(c),()=>{let x=E.indexOf(c);x!==-1&&E.splice(x,1);}},onFocusChange(c){return T.add(c),()=>{T.delete(c);}},getRegisteredElements(){let c=[];for(let x of j){if(H.has(x))continue;let G=B.get(x);G&&c.push({id:x,node:G});}return c},getActiveElements(){let c=N(),x=[];for(let G of c){if(H.has(G))continue;let v=B.get(G);v&&x.push({id:G,node:v});}return x}},p=new Map,w={getLayout(c){return c.layout},subscribe(c,x){return p.has(c)||p.set(c,new Set),p.get(c).add(x),()=>{let G=p.get(c);G&&(G.delete(x),G.size===0&&p.delete(c));}}},k={registerNode(){},unregisterNode(){},scheduleRender:M,exit(c){ee.exit(c);},get columns(){return i.columns},get rows(){return i.rows}},P={type:"root",children:[],onCommit(){M();}},K=false;function M(){K||(K=true,queueMicrotask(()=>{K=false,_();}));}function _(){let c=i.columns,x=i.rows;(f.width!==c||f.height!==x)&&(f.resize(c,x),u.resize(c,x),a=true),Zn(P.children,c,x),W(P.children);let G;if(C){let d=B.get(C);d?.type==="input"&&(G={nodeId:C,position:d.props.cursorPosition??d.props.value?.length??0});}let v=Dn(P.children,f,{cursorInfo:G,useNativeCursor:s}),X=qn(u,f,a);if(X.length>0&&i.write(X),y.size>0&&l&&(i.hideCursor(),l=false),h(),s)if(v.cursorPosition){let d=Hn(v.cursorPosition.bg);i.setCursorColor(d),i.moveCursor(v.cursorPosition.x,v.cursorPosition.y),l||(i.showCursor(),l=true);}else i.hideCursor(),l=false;for(let d=0;d<f.cells.length;d++)u.cells[d]={...f.cells[d]};a=false;}function W(c){for(let x of c){let G=p.get(x);if(G)for(let v of G)v(x.layout);W(x.children);}}let z=i.onData(c=>{let x=Nn(c);for(let G of x){if(G.ctrl&&G.name==="c"){ee.exit();return}if(G.ctrl&&G.name==="z"){i.suspend(),process.kill(0,"SIGSTOP");return}let v=false;for(let X of I)if(X(G)){v=true;break}if(!v&&C){let X=S.get(C);X&&(v=X(G));}if(!v&&G.name==="tab"&&!G.ctrl&&!G.alt){G.shift?V.focusPrev():V.focusNext();continue}if(!v)for(let X of b)X(G);}}),A=i.onResize(()=>{a=true,M();}),J=()=>{i.resume(),a=true,M();};process.on("SIGCONT",J);let L=ae.createElement(Fe.Provider,{value:k},ae.createElement(Z.Provider,{value:R},ae.createElement(Y.Provider,{value:V},ae.createElement(pe.Provider,{value:w},ae.createElement(Ct.Provider,{value:g},e))))),le=c=>{o&&console.error("Uncaught error:",c);},fe=c=>{o&&console.error("Error caught by boundary:",c);},Ie=c=>{o&&console.error("Recoverable error:",c);},Q=Xe.createContainer(P,0,null,false,null,"",le,fe,Ie,null);Xe.updateContainer(L,Q,null,null);let ee={unmount(){Xe.updateContainer(null,Q,null,null),z(),A(),process.off("SIGCONT",J);let c=Wt();c&&i.write(c),i.cleanup();},exit(c){ee.unmount(),process.exit(c??0);}};return ee}var So=forwardRef(function({children:t,style:n,focusable:r},o){return ae.createElement("box",{style:n,focusable:r,ref:o},t)});var Po=forwardRef(function({children:t,style:n,wrap:r,focusable:o,focusedStyle:s},i){let l=useContext(Y),u=useRef(null),f=useRef(null),[a,b]=useState(false);useImperativeHandle(i,()=>({focus(){l&&f.current&&l.requestFocus(f.current);},blur(){l&&l.blur();},get isFocused(){return a}}),[l,a]),useEffect(()=>{if(!l||!o||!f.current)return;let R=f.current;return b(l.focusedId===R),l.onFocusChange(m=>{b(m===R);})},[l,o]);let I=r?{...n,wrap:r}:n;a&&s&&(I={...I,...s});let S=R=>{u.current=R,f.current=R?.focusId??null;};return ae.createElement("text",{style:I,focusable:o,ref:S},t)});function rr(e,t,n){if(n<=0)return {visualLine:0,visualCol:t,totalVisualLines:1,lineStartOffset:0,lineLength:e.length};let r=e.split(`
|
|
5
5
|
`),o=[],s=0;for(let u of r){let f=Pe([u],n,"wrap"),a=0;for(let b of f)o.push({text:b,logicalOffset:s+a}),a+=b.length;s+=u.length+1;}let i=0;for(let u=0;u<o.length;u++){let f=o[u],a=f.text.length,b=u+1<o.length&&o[u+1].logicalOffset!==f.logicalOffset+a,I=a+(b?1:0);if(t<i+a||u===o.length-1)return {visualLine:u,visualCol:Math.min(t-i,a),totalVisualLines:o.length,lineStartOffset:i,lineLength:a};i+=I;}let l=o.length-1;return {visualLine:l,visualCol:o[l].text.length,totalVisualLines:o.length,lineStartOffset:i-o[l].text.length,lineLength:o[l].text.length}}function or(e,t,n,r){if(r<=0)return Math.min(n,e.length);let o=e.split(`
|
|
6
6
|
`),s=[],i=0;for(let a of o){let b=Pe([a],r,"wrap"),I=0;for(let S of b)s.push({text:S,startOffset:i+I}),I+=S.length;i+=a.length+1;}let l=Math.max(0,Math.min(t,s.length-1)),u=s[l],f=Math.min(n,u.text.length);return u.startOffset+f}function nt(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 rt(e,t,n){let r=0;for(let o=0;o<t&&o<e.length;o++)r+=e[o].length+1;return r+Math.min(n,e[t]?.length??0)}var Fo=forwardRef(function(t,n){let{value:r,defaultValue:o="",onChange:s,onKeyPress:i,onBeforeChange:l,placeholder:u,style:f,focusedStyle:a,multiline:b,autoFocus:I,type:S="text"}=t,[R,m]=useState(o),[
|
|
8
|
-
`+c.slice(
|
|
9
|
-
`);)d--;let
|
|
10
|
-
`;)d--;return v(d),true}if(
|
|
11
|
-
`;)d++;for(;d<c.length&&c[d]===" ";)d++;return v(d),true}if(
|
|
12
|
-
`;)d--;let
|
|
13
|
-
`;)d++;for(;d<c.length&&c[d]===" ";)d++;let
|
|
14
|
-
`)))))}var tn=forwardRef(function({count:t,renderItem:n,selectedIndex:r,onSelectionChange:o,onSelect:s,defaultSelectedIndex:i=0,disabledIndices:l,style:u,focusable:f=true},a){let b=r!==void 0,[I,S]=useState(i),R=b?r:I,m=useContext(Y),x=useContext(Z),g=useRef(null),h=useRef(null),C=useRef(s);C.current=s;let[B,j]=useState(false),[L,D]=useState(false);useImperativeHandle(a,()=>({focus(){m&&h.current&&m.requestFocus(h.current);},blur(){m&&m.blur();},get isFocused(){return L},get selectedIndex(){return R}}),[m,L,R]);let E=useRef(null),T=useCallback(p=>{let w=Math.max(0,Math.min(p,t-1));b?o?.(w):S(w);},[b,o,t]),$=useCallback((p,w)=>{if(!l||l.size===0)return Math.max(0,Math.min(p+w,t-1));let k=p+w;for(;k>=0&&k<t&&l.has(k);)k+=w;return k<0||k>=t?p:k},[l,t]);useEffect(()=>{if(!(!m||!h.current||!g.current||!f))return m.register(h.current,g.current)},[m,f,B]),useEffect(()=>{if(!m||!h.current)return;let p=h.current;return D(m.focusedId===p),m.onFocusChange(w=>{D(w===p);})},[m,B]);let N=useCallback(p=>{let w=p?t-1:0,k=p?-1:1,P=w;for(;P>=0&&P<t&&l?.has(P);)P+=k;return P>=0&&P<t?P:p?t-1:0},[l,t]);useEffect(()=>{if(!x||!h.current||!f)return;let p=h.current,w=k=>m?.focusedId!==p?false:k.name==="g"&&!k.ctrl&&!k.alt?E.current==="g"?(T(N(false)),E.current=null,true):(E.current="g",true):k.name==="G"||k.name==="g"&&k.shift?(E.current=null,T(N(true)),true):(E.current=null,k.name==="up"||k.name==="k"?(T($(R,-1)),true):k.name==="down"||k.name==="j"?(T($(R,1)),true):k.name==="return"?(l?.has(R)||C.current?.(R),true):false);return x.registerInputHandler(p,w)},[x,m,f,R,T,$,N,l,B]);let V=[];for(let p=0;p<t;p++)V.push(ae.createElement(ae.Fragment,{key:p},n({index:p,selected:p===R,focused:L})));return ae.createElement("box",{style:{flexDirection:"column",...u},focusable:f,ref:p=>{p?(g.current=p,h.current=p.focusId,j(true)):(g.current=null,h.current=null,j(false));}},...V)});function ts({items:e,selectedIndex:t,onSelectionChange:n,onSelect:r,defaultSelectedIndex:o=0,style:s,highlightColor:i="cyan",focusable:l=true}){let u=new Set;for(let a=0;a<e.length;a++)e[a].disabled&&u.add(a);let f=a=>{let b=e[a];b&&!b.disabled&&r?.(b.value,a);};return ae.createElement(tn,{count:e.length,selectedIndex:t,onSelectionChange:n,onSelect:f,defaultSelectedIndex:o,disabledIndices:u.size>0?u:void 0,style:s,focusable:l,renderItem:({index:a,selected:b,focused:I})=>{let S=e[a],R=S.disabled,m=b&&I,x=b?">":" ";return ae.createElement("box",{style:{flexDirection:"row",...m?{bg:i}:{}}},ae.createElement("text",{style:m?{bold:true,color:"black"}:R?{dim:true}:{}},`${x} ${S.label}`))}})}function ss({value:e,indeterminate:t=false,width:n="100%",label:r,showPercent:o=false,style:s,filled:i="\u2588",empty:l="\u2591"}){let u=useRef(null),a=Me(u).innerWidth,[b,I]=useState(0);useEffect(()=>{if(!t)return;let g=setInterval(()=>{I(h=>(h+1)%Math.max(1,a+6));},100);return ()=>clearInterval(g)},[t,a]);let S=Math.max(0,Math.min(1,e??0)),R=o?` ${Math.round(S*100)}%`:"",m="";if(a>0)if(t&&e===void 0){let g=Math.max(1,Math.min(3,Math.floor(a/4))),h=[];for(let C=0;C<a;C++)C>=b-g&&C<b?h.push(i):h.push(l);m=h.join("");}else {let g=Math.round(S*a);m=i.repeat(g)+l.repeat(a-g);}let x=[];return r&&x.push(ae.createElement("text",{key:"label",style:{bold:true}},r+" ")),x.push(ae.createElement("box",{key:"track",style:{flexGrow:1,flexShrink:1},ref:g=>{u.current=g??null;}},ae.createElement("text",{key:"bar",style:{}},m))),o&&x.push(ae.createElement("text",{key:"pct",style:{bold:true}},R)),ae.createElement("box",{style:{flexDirection:"row",width:n,...s}},...x)}var cs=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function us({frames:e=cs,intervalMs:t=80,label:n,style:r}){let[o,s]=useState(0);useEffect(()=>{let l=setInterval(()=>{s(u=>(u+1)%e.length);},t);return ()=>clearInterval(l)},[e.length,t]);let i=[ae.createElement("text",{key:"frame",style:r},e[o])];return n&&i.push(ae.createElement("text",{key:"label",style:{}}," "+n)),ae.createElement("box",{style:{flexDirection:"row"}},...i)}var xr=createContext(null),hs=0;function gs(){let e=useContext(xr);if(!e)throw new Error("useToast must be used within a <ToastHost>");return e.push}var xs={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 ys({position:e="bottom-right",maxVisible:t=5,children:n}){let[r,o]=useState([]),s=useRef(new Map),i=useCallback(S=>{let R=`toast-${hs++}`,m={id:R,durationMs:3e3,variant:"info",...S};if(o(x=>[...x,m]),m.durationMs&&m.durationMs>0){let x=setTimeout(()=>{s.current.delete(R),o(g=>g.filter(h=>h.id!==R));},m.durationMs);s.current.set(R,x);}},[]);useEffect(()=>()=>{for(let S of s.current.values())clearTimeout(S);s.current.clear();},[]);let l=useRef({push:i});l.current.push=i;let u=e.startsWith("top"),f=e.endsWith("right"),a={position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:900,flexDirection:"column",justifyContent:u?"flex-start":"flex-end",alignItems:f?"flex-end":"flex-start",padding:1},I=r.slice(-t).map(S=>{let R=S.variant??"info",m=xs[R],x=[];return S.title&&x.push(ae.createElement("text",{key:"title",style:{bold:true,color:m.title}},S.title)),x.push(ae.createElement("text",{key:"msg",style:{color:m.text}},S.message)),ae.createElement("box",{key:S.id,style:{bg:m.bg,paddingX:1,flexDirection:"column",minWidth:20,maxWidth:50}},...x)});return ae.createElement(xr.Provider,{value:l.current},n,I.length>0?ae.createElement("box",{style:a},...I):null)}var Is=forwardRef(function({items:t,value:n,onChange:r,placeholder:o="Select...",style:s,focusedStyle:i,dropdownStyle:l,highlightColor:u="cyan",maxVisible:f=8,searchable:a=true,openDirection:b="auto",disabled:I},S){let R=useContext(Y),m=useContext(Z),x=useContext(Fe),g=useContext(De),h=useRef(null),C=useRef(null),B=useRef(r);B.current=r;let[j,L]=useState(false),[D,E]=useState(false),[T,$]=useState(false);useImperativeHandle(S,()=>({focus(){R&&C.current&&R.requestFocus(C.current);},blur(){R&&R.blur();},get isFocused(){return D},get value(){return n},get isOpen(){return T}}),[R,D,n,T]);let[N,V]=useState(0),[p,w]=useState(""),[k,P]=useState(0),K=Me(h),M=x?.rows??24,_=g?.getBounds(),z=t.find(v=>v.value===n)?.label??"",H=useMemo(()=>{if(!p)return t;let v=p.toLowerCase();return t.filter(X=>X.label.toLowerCase().includes(v))},[t,p]),J=Math.min(f,H.length),A=H.slice(k,k+J);useEffect(()=>{V(0),P(0);},[p]),useEffect(()=>{!D&&T&&($(false),w(""));},[D,T]),useEffect(()=>{if(!(!R||!C.current||!h.current))return R.register(C.current,h.current)},[R,j]),useEffect(()=>{!R||!C.current||R.setSkippable(C.current,!!I);},[R,I,j]),useEffect(()=>{if(!R||!C.current)return;let v=C.current;return E(R.focusedId===v),R.onFocusChange(X=>{E(X===v);})},[R,j]);let le=useCallback((v,X)=>{let d=v+X;for(;d>=0&&d<H.length;){if(!H[d].disabled)return d;d+=X;}return v},[H]),fe=useCallback(v=>{v<k?P(v):v>=k+J&&P(v-J+1);},[k,J]);useEffect(()=>{if(!m||!C.current||I)return;let v=C.current,X=d=>{if(R?.focusedId!==v)return false;if(!T){if(d.name==="return"||d.name===" "||d.sequence===" "){$(true),w("");let G=H.findIndex(q=>q.value===n),re=G>=0?G:0;return V(re),P(Math.max(0,re-Math.floor(f/2))),true}return false}if(d.name==="tab")return $(false),w(""),false;if(d.name==="escape")return $(false),w(""),true;if(d.name==="return"){let G=H[N];return G&&!G.disabled&&(B.current?.(G.value),$(false),w("")),true}if(d.name==="up"){let G=le(N,-1);return V(G),fe(G),true}if(d.name==="down"){let G=le(N,1);return V(G),fe(G),true}if(d.name==="backspace")return a&&p.length>0&&w(G=>G.slice(0,-1)),true;if(d.name==="home"){let G=le(-1,1);return V(G),fe(G),true}if(d.name==="end"){let G=le(H.length,-1);return V(G),fe(G),true}if(a&&d.sequence&&d.sequence.length===1&&!d.ctrl&&!d.alt){let G=d.sequence;if(G>=" "&&G<="~")return w(re=>re+G),true}return true};return m.registerInputHandler(v,X)},[m,R,I,T,N,H,n,f,a,p,le,fe,j]);let Q={flexDirection:"row",width:"100%",...!s?.bg&&s?.border===void 0?{border:"single"}:{},...s,...D&&i?i:{}},ee=z?s?.color??void 0:"blackBright",c=[ae.createElement("text",{key:"label",style:{flexGrow:1,flexShrink:1,color:ee,wrap:"ellipsis",...z?{}:{dim:true}}},z||o),ae.createElement("text",{key:"arrow",style:{flexShrink:0,color:D?u:"blackBright"}},T?" \u25B2":" \u25BC")],y=null;if(T){let v=[];a&&p&&v.push(ae.createElement("box",{key:"search",style:{paddingX:1}},ae.createElement("text",{style:{color:"blackBright",dim:true}},`/${p}`))),H.length===0&&v.push(ae.createElement("box",{key:"empty",style:{paddingX:1}},ae.createElement("text",{style:{dim:true,color:"blackBright"}},"No matches"))),k>0&&v.push(ae.createElement("box",{key:"scroll-up",style:{justifyContent:"center",alignItems:"center"}},ae.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25B2"))),A.forEach((ke,we)=>{let Re=k+we===N,ye=ke.disabled,O={paddingX:1,...Re&&!ye?{bg:u}:{}},U={...Re&&!ye?{color:"black",bold:true}:{},...ye?{dim:true,color:"blackBright"}:{}};v.push(ae.createElement("box",{key:`item-${ke.value}`,style:O},ae.createElement("text",{style:U},ke.label)));}),k+J<H.length&&v.push(ae.createElement("box",{key:"scroll-down",style:{justifyContent:"center",alignItems:"center"}},ae.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25BC")));let X=k>0,d=k+J<H.length,G=a&&p,re=H.length===0,q=!l?.bg&&l?.border===void 0,ne=J+(q?2:0);X&&(ne+=1),d&&(ne+=1),G&&(ne+=1),re&&(ne+=1);let he=K.y+K.height,be,de;_?(be=_.visibleBottom-he,de=K.y-_.visibleTop):(be=M-he,de=K.y);let Ee=(b==="up"?true:b==="down"?false:be<ne&&de>=ne)?-ne:K.height||1;y=ae.createElement("box",{style:{position:"absolute",top:Ee,left:0,right:0,zIndex:9999,...q?{border:"single"}:{},bg:"black",flexDirection:"column",...l}},...v);}let F={flexDirection:"column",width:Q.width??"100%",minWidth:Q.minWidth,maxWidth:Q.maxWidth,flexGrow:Q.flexGrow,flexShrink:Q.flexShrink??1};return ae.createElement("box",{style:F},ae.createElement("box",{style:Q,focusable:true,ref:v=>{v?(h.current=v,C.current=v.focusId,L(true)):(h.current=null,C.current=null,L(false));}},...c),y)});var vs=forwardRef(function({checked:t,onChange:n,label:r,style:o,focusedStyle:s,disabled:i,checkedChar:l="\u2713",uncheckedChar:u=" "},f){let a=useContext(Y),b=useContext(Z),I=useRef(null),S=useRef(null),R=useRef(n);R.current=n;let m=useRef(t);m.current=t;let[x,g]=useState(false),[h,C]=useState(false);useImperativeHandle(f,()=>({focus(){a&&S.current&&a.requestFocus(S.current);},blur(){a&&a.blur();},get isFocused(){return h},get checked(){return m.current}}),[a,h]),useEffect(()=>{if(!(!a||!S.current||!I.current||i))return a.register(S.current,I.current)},[a,i,x]),useEffect(()=>{if(!a||!S.current)return;let E=S.current;return C(a.focusedId===E),a.onFocusChange(T=>{C(T===E);})},[a,x]),useEffect(()=>{if(!b||!S.current||i)return;let E=S.current,T=$=>a?.focusedId!==E?false:$.name==="return"||$.name===" "||$.sequence===" "?(R.current(!m.current),true):false;return b.registerInputHandler(E,T)},[b,a,i,x]);let B={flexDirection:"row",gap:1,...o,...h&&s?s:{}},j=t?l:u,L={color:i?"blackBright":h?"white":o?.color},D={color:i?"blackBright":o?.color};return ae.createElement("box",{style:B,focusable:!i,ref:E=>{E?(I.current=E,S.current=E.focusId,g(true)):(I.current=null,S.current=null,g(false));}},ae.createElement("text",{key:"box",style:L},`[${j}]`),r?ae.createElement("text",{key:"label",style:D},r):null)});function Es({items:e,value:t,onChange:n,style:r,itemStyle:o,focusedItemStyle:s,selectedItemStyle:i,disabled:l,direction:u="column",gap:f=0,selectedChar:a="\u25CF",unselectedChar:b="\u25CB",forwardedRef:I}){let S=useContext(Y),R=useContext(Z),m=useRef(null),x=useRef(null),g=useRef(n);g.current=n;let[h,C]=useState(false),[B,j]=useState(false);useImperativeHandle(I,()=>({focus(){S&&x.current&&S.requestFocus(x.current);},blur(){S&&S.blur();},get isFocused(){return B},get value(){return t}}),[S,B,t]);let[L,D]=useState(()=>{let N=e.findIndex(V=>V.value===t);return N>=0?N:e.findIndex(V=>!V.disabled)}),E=useCallback((N,V)=>{let p=N;for(let w=0;w<e.length;w++)if(p=(p+V+e.length)%e.length,!e[p]?.disabled)return p;return N},[e]);useEffect(()=>{if(!(!S||!x.current||!m.current||l))return S.register(x.current,m.current)},[S,l,h]),useEffect(()=>{if(!S||!x.current)return;let N=x.current;return j(S.focusedId===N),S.onFocusChange(V=>{j(V===N);})},[S,h]),useEffect(()=>{if(!R||!x.current||l)return;let N=x.current,V=p=>{if(S?.focusedId!==N)return false;if(p.name==="up"||p.name==="left"||p.name==="k"||p.name==="tab"&&p.shift)return D(w=>E(w,-1)),true;if(p.name==="down"||p.name==="right"||p.name==="j"||p.name==="tab"&&!p.shift)return D(w=>E(w,1)),true;if(p.name==="return"||p.name===" "||p.sequence===" "){let w=e[L];return w&&!w.disabled&&g.current(w.value),true}return false};return R.registerInputHandler(N,V)},[R,S,l,e,L,E,h]),useEffect(()=>{let N=e.findIndex(V=>V.value===t);N>=0&&D(N);},[t,e]);let T={flexDirection:u,gap:f,...r},$=e.map((N,V)=>{let p=N.value===t,w=V===L,k=l||N.disabled,P=p?a:b,K={flexDirection:"row",gap:1,...o};p&&i&&(K={...K,...i}),B&&w&&s&&(K={...K,...s});let M=k?"blackBright":B&&w?s?.color??"white":p?i?.color??o?.color:o?.color;return ae.createElement("box",{key:V,style:K},ae.createElement("text",{key:"radio",style:{color:M}},`(${P})`),ae.createElement("text",{key:"label",style:{color:M}},N.label))});return ae.createElement("box",{style:T,focusable:!l,ref:N=>{N?(m.current=N,x.current=N.focusId,C(true)):(m.current=null,x.current=null,C(false));}},...$)}var Ns=forwardRef(function(t,n){return ae.createElement(Es,{...t,forwardedRef:n})});var Rr=createContext(null);function Fs(){let e=useContext(Rr);if(!e)throw new Error("useDialog must be used within a DialogHost");return e}function Bs({children:e}){let[t,n]=useState([]),r=useRef(0),o=useCallback((f,a)=>new Promise(b=>{let I=++r.current;n(S=>[...S,{id:I,type:"alert",content:f,okText:a?.okText??"OK",cancelText:"",style:a?.style,buttonStyle:a?.buttonStyle,okButtonStyle:a?.okButtonStyle,focusedButtonStyle:a?.focusedButtonStyle,backdropStyle:a?.backdropStyle,resolve:()=>b()}]);}),[]),s=useCallback((f,a)=>new Promise(b=>{let I=++r.current;n(S=>[...S,{id:I,type:"confirm",content:f,okText:a?.okText??"OK",cancelText:a?.cancelText??"Cancel",style:a?.style,buttonStyle:a?.buttonStyle,okButtonStyle:a?.okButtonStyle,cancelButtonStyle:a?.cancelButtonStyle,focusedButtonStyle:a?.focusedButtonStyle,backdropStyle:a?.backdropStyle,resolve:b}]);}),[]),i=useCallback((f,a)=>{n(b=>{let I=b.find(S=>S.id===f);return I&&I.resolve(a),b.filter(S=>S.id!==f)});},[]),l={alert:o,confirm:s},u=t[t.length-1];return ae.createElement(Rr.Provider,{value:l},e,u&&ae.createElement(Ms,{key:u.id,dialog:u,onDismiss:i}))}function Ms({dialog:e,onDismiss:t}){let n=useContext(Y),r=useRef(null),o=useRef(null),s=useRef(null),i=useRef(null),[l,u]=useState("ok"),[f,a]=useState(0);useEffect(()=>{if(!n||f===0)return;let g=[];return r.current&&s.current&&g.push(n.register(s.current,r.current)),o.current&&i.current&&g.push(n.register(i.current,o.current)),s.current&&n.requestFocus(s.current),()=>g.forEach(h=>h())},[n,f]),useEffect(()=>{if(n)return n.onFocusChange(g=>{g===s.current?u("ok"):g===i.current&&u("cancel");})},[n]),ot(g=>{if(g.name==="return"||g.name==="space"){e.type==="alert"?t(e.id,true):t(e.id,l==="ok");return}if(g.name==="escape"){t(e.id,false);return}e.type==="confirm"&&n&&(g.name==="left"||g.name==="right")&&(l==="ok"&&i.current?n.requestFocus(i.current):s.current&&n.requestFocus(s.current));},[e,l,n,t]);let b=typeof e.content=="string",I=b?e.content.length:0,R={minWidth:Math.max(20,b?Math.min(I+6,50):30),maxWidth:50,bg:"black",border:"round",borderColor:"white",padding:1,flexDirection:"column",gap:1,...e.style},m=(g,h)=>{let C={paddingX:2,bg:"blackBright",color:"white"},B={bg:"white",color:"black",bold:true},j=g==="ok"?e.okButtonStyle:e.cancelButtonStyle;return {...C,...e.buttonStyle,...j,...h?{...B,...e.focusedButtonStyle}:{}}},x={position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:999,...e.backdropStyle};return ae.createElement(zt,{trap:true},ae.createElement("box",{style:x}),ae.createElement("box",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,justifyContent:"center",alignItems:"center",zIndex:1e3}},ae.createElement("box",{style:R},ae.createElement("box",{style:{flexDirection:"column"}},typeof e.content=="string"?ae.createElement("text",null,e.content):e.content),ae.createElement("box",{style:{flexDirection:"row",justifyContent:"flex-end",gap:1}},e.type==="confirm"&&ae.createElement("box",{style:m("cancel",l==="cancel"),focusable:true,ref:g=>{g&&g.focusId&&!i.current&&(o.current=g,i.current=g.focusId,a(h=>h+1));}},ae.createElement("text",null,e.cancelText)),ae.createElement("box",{style:m("ok",l==="ok"),focusable:true,ref:g=>{g&&g.focusId&&!s.current&&(r.current=g,s.current=g.focusId,a(h=>h+1));}},ae.createElement("text",null,e.okText))))))}function As(e,t){let n=[],r=e.parent;for(;r;)r.style.clip&&n.push({x:r.layout.innerX,y:r.layout.innerY,width:r.layout.innerWidth,height:r.layout.innerHeight}),r=r.parent;let o=t;for(let s of n)o=Vs(o,s);return o}function Vs(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 js(e,t){if(t.width<=0||t.height<=0)return false;let n=e.x+e.width,r=e.y+e.height;return e.x<t.x+t.width&&n>t.x&&e.y<t.y+t.height&&r>t.y}function Os(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 $s({children:e,activationKey:t="ctrl+o",hintStyle:n,hintBg:r="yellow",hintFg:o="black",hintChars:s="asdfghjklqwertyuiopzxcvbnm",enabled:i=true,debug:l=false}){let u=l?(...p)=>console.error("[JumpNav]",...p):()=>{},[f,a]=useState(false),[b,I]=useState(""),[S,R]=useState([]),m=useContext(Z),x=useContext(Y),g=useContext(pe),h=useContext(Fe);useEffect(()=>{u("Mounted, inputCtx:",!!m,"focusCtx:",!!x,"enabled:",i);},[]);let B=useCallback(p=>{let w=p.toLowerCase().split("+");return {ctrl:w.includes("ctrl"),alt:w.includes("alt"),shift:w.includes("shift"),meta:w.includes("meta"),name:w[w.length-1]??""}},[])(t),j=useCallback(()=>{if(!x?.getActiveElements){u("refreshElements: no getActiveElements");return}let p=x.getActiveElements();u("getActiveElements returned",p.length,"elements");let w=h?.columns??80,k=h?.rows??24,P={x:0,y:0,width:w,height:k},K=p.map(({id:M,node:_})=>({id:M,node:_,layout:g?.getLayout(_)??_.layout,clipRegion:As(_,P)}));K.sort((M,_)=>M.layout.y!==_.layout.y?M.layout.y-_.layout.y:M.layout.x-_.layout.x),R(K);},[x,g,h,u]),L=useRef(false);useEffect(()=>{f&&!L.current&&(u("Activated! Refreshing elements..."),j()),L.current=f;},[f,j,u]);let D=h?.columns??80,E=h?.rows??24,T=S.filter(p=>p.layout.width>0&&p.layout.height>0&&js(p.layout,p.clipRegion)),$=Os(T.length,s),N=useMemo(()=>{let p=new Map;return T.forEach((w,k)=>{$[k]&&p.set($[k],w.id);}),p},[T,$]);useEffect(()=>{if(!m||!i){u("Not subscribing - inputCtx:",!!m,"enabled:",i);return}u("Subscribing to priority input, activation key:",t);let p=w=>{let k=w.name===B.name,P=!!w.ctrl===B.ctrl,K=!!w.alt===B.alt,M=!!w.shift===B.shift,_=!!w.meta===B.meta;if(!f&&k&&P&&K&&M&&_)return u("Activation key matched! Activating..."),a(true),I(""),true;if(f){if(w.name==="escape")return u("Escape pressed, deactivating"),a(false),I(""),true;if(w.name==="backspace")return I(""),true;if(w.sequence&&w.sequence.length===1&&/[a-z]/i.test(w.sequence)){let W=b+w.sequence.toLowerCase();u("Buffer:",W);let z=N.get(W);return z?(u("Jumping to",z),x?.requestFocus(z),a(false),I(""),true):[...N.keys()].some(J=>J.startsWith(W))?(I(W),true):(I(""),true)}return true}return false};return m.subscribePriority(p)},[m,i,f,B,b,N,x,t,u]);let V=f?ae.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:99998}},...T.map((p,w)=>{let k=$[w];if(!k)return null;let{x:P,y:K,width:M}=p.layout,_=p.clipRegion,W=k.length+2,z=Math.max(_.y,Math.min(K,_.y+_.height-1,E-1)),H=P-W,J=P+M,A;H>=_.x&&H>=0?A=H:J+W<=_.x+_.width&&J+W<=D?A=J:A=Math.max(_.x,Math.min(P,D-W)),A=Math.max(0,Math.min(A,D-W));let le=k.startsWith(b)&&b.length>0;return ae.createElement("box",{key:p.id,style:{position:"absolute",top:z,left:A,bg:le?"cyan":r,color:o,paddingX:1,zIndex:99999,...n}},ae.createElement("text",{style:{bold:true,color:o}},k))}),ae.createElement("box",{style:{position:"absolute",bottom:0,left:0,right:0,bg:"blackBright",paddingX:1,zIndex:99999}},ae.createElement("text",{style:{color:"white"}},b?`Jump: ${b}_`:"Press a key to jump \u2022 ESC to cancel"))):null;return ae.createElement(ae.Fragment,null,e,V)}var qe=join(tmpdir(),"glyph-image-cache");function Nt(e){return e.startsWith("http://")||e.startsWith("https://")}function qs(e,t){let n=createHash("md5").update(e).digest("hex"),r=t?zs(t):_s(e)||".png";return join(qe,`${n}${r}`)}function _s(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 zs(e){switch(e){case "png":return ".png";case "jpeg":return ".jpeg";case "gif":return ".gif";case "webp":return ".webp";default:return ".png"}}function xn(e){if(Nt(e))try{let t=new URL(e),n=t.pathname;return basename(n)||t.hostname}catch{return "remote-image"}return basename(e)}function Pr(){existsSync(qe)||mkdirSync(qe,{recursive:true});}async function Er(e){let t=xn(e);return Nt(e)?Us(e,t):Xs(e,t)}async function Xs(e,t){if(!existsSync(e))throw new Error(`Image not found: ${e}`);return {data:readFileSync(e),name:t,localPath:e,isRemote:false}}async function Us(e,t){Pr();let n=createHash("md5").update(e).digest("hex"),r=[".png",".jpeg",".gif",".webp"];for(let f of r){let a=join(qe,`${n}${f}`);if(existsSync(a))return {data:readFileSync(a),name:t,localPath:a,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(!Ys(i))throw new Error(`Invalid image data from: ${e}`);let l=Gt(i),u=qs(e,l);return writeFileSync(u,i),{data:i,name:t,localPath:u,isRemote:true}}function Ys(e){return e.length<4?false:e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71||e[0]===255&&e[1]===216&&e[2]===255||e[0]===71&&e[1]===73&&e[2]===70||e[0]===66&&e[1]===77||e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e.length>=12&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80||e[0]===0&&e[1]===0&&e[2]===1&&e[3]===0}function Gt(e){return e.length<4?"unknown":e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"png":e[0]===255&&e[1]===216&&e[2]===255?"jpeg":e[0]===71&&e[1]===73&&e[2]===70?"gif":e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e.length>=12&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80?"webp":"unknown"}function Nr(e,t){let n=Gt(e);if(n==="png")return e;Pr();let r=createHash("md5").update(e).digest("hex"),o=join(qe,`${r}.${n}`),s=join(qe,`${r}.png`);try{writeFileSync(o,e);let i=platform(),l=!1;if(i==="darwin")try{execSync(`sips -s format png "${o}" --out "${s}" 2>/dev/null`,{stdio:"pipe"}),l=!0;}catch{}if(!l)try{execSync(`magick "${o}" "${s}" 2>/dev/null`,{stdio:"pipe"}),l=!0;}catch{}if(!l)try{execSync(`convert "${o}" "${s}" 2>/dev/null`,{stdio:"pipe"}),l=!0;}catch{}if(l&&existsSync(s)){let u=readFileSync(s);try{unlinkSync(o);}catch{}try{unlinkSync(s);}catch{}return u}try{unlinkSync(o);}catch{}return null}catch{try{unlinkSync(o);}catch{}try{unlinkSync(s);}catch{}return null}}function Qs(){let e=platform();return e==="darwin"?"quicklook":e==="linux"||e==="win32"?"open":"none"}async function yn(e){switch(Qs()){case "quicklook":return Zs(e);case "open":return ti(e);case "none":throw new Error("No preview method available on this platform")}}function Zs(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(()=>{ei();},50),r.on("close",o=>{t();});})}function ei(){exec(`osascript -e '
|
|
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 rt(e,t,n){let r=0;for(let o=0;o<t&&o<e.length;o++)r+=e[o].length+1;return r+Math.min(n,e[t]?.length??0)}var Fo=forwardRef(function(t,n){let{value:r,defaultValue:o="",onChange:s,onKeyPress:i,onBeforeChange:l,placeholder:u,style:f,focusedStyle:a,multiline:b,autoFocus:I,type:S="text"}=t,[R,m]=useState(o),[y,g]=useState(o.length),[h,C]=useState(0),[B,j]=useState(false),[H,D]=useState(false),E=useContext(Z),T=useContext(Y),$=useContext(pe),N=useRef(null),V=useRef(null),p=r!==void 0,w=p?r:R;useImperativeHandle(n,()=>({focus(){T&&V.current&&T.requestFocus(V.current);},blur(){T&&T.blur();},get isFocused(){return B},get value(){return k.current}}),[T,B]),useEffect(()=>{if(!$||!N.current)return;let A=$.getLayout(N.current);return C(A.innerWidth),$.subscribe(N.current,J=>{C(J.innerWidth);})},[$]);let k=useRef(w),P=useRef(y),K=useRef(w),M=useRef(y);useEffect(()=>{w!==K.current&&(k.current=w,K.current=w,P.current=w.length,M.current=w.length,g(w.length));},[w]),useEffect(()=>{y!==M.current&&(P.current=y,M.current=y);},[y]);let _=useRef({isControlled:p,onChange:s,onKeyPress:i,onBeforeChange:l,multiline:b??false,innerWidth:h,type:S});_.current={isControlled:p,onChange:s,onKeyPress:i,onBeforeChange:l,multiline:b??false,innerWidth:h,type:S},useEffect(()=>{if(!(!T||!V.current||!N.current))return T.register(V.current,N.current)},[T,H]);let W=useRef(false);useEffect(()=>{if(!H){W.current=false;return}if(I&&!W.current&&T&&V.current){W.current=true;let A=V.current,J=setTimeout(()=>{T.requestFocus(A);},0);return ()=>clearTimeout(J)}},[I,T,H]),useEffect(()=>{if(!T||!V.current)return;let A=V.current;return j(T.focusedId===A),T.onFocusChange(J=>{j(J===A);})},[T,H]),useEffect(()=>{if(!E||!V.current)return;let A=V.current,J=L=>{let{isControlled:le,onChange:fe,onKeyPress:Ie,onBeforeChange:Q,multiline:ee}=_.current;if(Ie?.(L)===true)return true;let c=k.current,x=P.current;if(L.name==="escape")return false;let G=(d,F)=>{let re=d,q=F;if(Q){let se=Q(d,c);if(se===false)return;typeof se=="string"&&(re=se,q=se.length);}k.current=re,P.current=q,K.current=re,M.current=q,le||m(re),fe?.(re),g(q);},v=d=>{P.current=d,M.current=d,g(d);};if(L.name==="return"){if(ee){let d=c.slice(0,x)+`
|
|
8
|
+
`+c.slice(x);return G(d,x+1),true}return false}if(L.ctrl){if(L.name==="w"){if(x>0){let d=x;for(;d>0&&c[d-1]===" ";)d--;for(;d>0&&c[d-1]!==" "&&(!ee||c[d-1]!==`
|
|
9
|
+
`);)d--;let F=c.slice(0,d)+c.slice(x);G(F,d);}return true}if(L.name==="a"){if(ee){let{line:d,lines:F}=nt(c,x);v(rt(F,d,0));}else v(0);return true}if(L.name==="e"){if(ee){let{line:d,lines:F}=nt(c,x);v(rt(F,d,F[d].length));}else v(c.length);return true}if(L.name==="k"){if(ee){let{line:d,lines:F}=nt(c,x),re=rt(F,d,F[d].length);if(x<re){let q=c.slice(0,x)+c.slice(re);G(q,x);}}else if(x<c.length){let d=c.slice(0,x);G(d,x);}return true}return false}if(L.alt){if(L.name==="left"||L.name==="b"){let d=x;for(;d>0&&c[d-1]===" ";)d--;for(;d>0&&c[d-1]!==" "&&c[d-1]!==`
|
|
10
|
+
`;)d--;return v(d),true}if(L.name==="right"||L.name==="f"){let d=x;for(;d<c.length&&c[d]!==" "&&c[d]!==`
|
|
11
|
+
`;)d++;for(;d<c.length&&c[d]===" ";)d++;return v(d),true}if(L.name==="backspace"||L.name==="d")if(L.name==="backspace"){if(x>0){let d=x;for(;d>0&&c[d-1]===" ";)d--;for(;d>0&&c[d-1]!==" "&&c[d-1]!==`
|
|
12
|
+
`;)d--;let F=c.slice(0,d)+c.slice(x);G(F,d);}return true}else {if(x<c.length){let d=x;for(;d<c.length&&c[d]!==" "&&c[d]!==`
|
|
13
|
+
`;)d++;for(;d<c.length&&c[d]===" ";)d++;let F=c.slice(0,x)+c.slice(d);G(F,x);}return true}return false}if(L.name==="left")return v(Math.max(0,x-1)),true;if(L.name==="right")return v(Math.min(c.length,x+1)),true;if(L.name==="up"){let{innerWidth:d}=_.current,F=rr(c,x,d);return F.visualLine>0&&v(or(c,F.visualLine-1,F.visualCol,d)),true}if(L.name==="down"){let{innerWidth:d}=_.current,F=rr(c,x,d);return F.visualLine<F.totalVisualLines-1&&v(or(c,F.visualLine+1,F.visualCol,d)),true}if(L.name==="home"){if(ee){let{line:d,lines:F}=nt(c,x);v(rt(F,d,0));}else v(0);return true}if(L.name==="end"){if(ee){let{line:d,lines:F}=nt(c,x);v(rt(F,d,F[d].length));}else v(c.length);return true}if(L.name==="backspace"){if(x>0){let d=c.slice(0,x-1)+c.slice(x);G(d,x-1);}return true}if(L.name==="delete"){if(x<c.length){let d=c.slice(0,x)+c.slice(x+1);G(d,x);}return true}if(L.name==="space"){let d=c.slice(0,x)+" "+c.slice(x);return G(d,x+1),true}if(L.name.length>1)return false;let X=L.sequence;if(X.length===1&&X.charCodeAt(0)>=32){let{type:d}=_.current;if(d==="number"){let re=/[0-9]/.test(X),q=X==="."&&!c.includes("."),se=X==="-"&&x===0&&!c.includes("-");if(!re&&!q&&!se)return true}let F=c.slice(0,x)+X+c.slice(x);return G(F,x+1),true}return false};return E.registerInputHandler(A,J)},[E,H]);let z={...f,...B&&a?a:{}};return ae.createElement("input",{style:z,value:w,defaultValue:o,placeholder:u,onChange:s,cursorPosition:P.current,multiline:b??false,focused:B,ref:A=>{A?(N.current=A,V.current=A.focusId,D(true)):(N.current=null,V.current=null,D(false));}})});function zt({trap:e=false,children:t}){let n=useContext(Y),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]),ae.createElement(ae.Fragment,null,t)}function Ao({size:e}){return ae.createElement("box",{style:{flexGrow:e??1}})}function ur(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 ar(e,t){return !(t.name!==e.name||e.ctrl!==!!t.ctrl||e.alt!==!!t.alt||e.shift!==!!t.shift||e.meta!==!!t.meta)}function jo({keypress:e,onPress:t,whenFocused:n,priority:r,disabled:o}){let s=useContext(Z),i=useContext(Y),l=useRef(t);l.current=t;let u=useRef(ur(e));return u.current=ur(e),useEffect(()=>{if(!(!s||o))if(r){let f=a=>!ar(u.current,a)||n&&i?.focusedId!==n?false:(l.current(),true);return s.subscribePriority(f)}else {let f=a=>{ar(u.current,a)&&(n&&i?.focusedId!==n||l.current());};return s.subscribe(f)}},[s,i,n,r,o]),null}function $o({children:e,zIndex:t=1e3}){return ae.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:t}},e)}var qo=forwardRef(function({onPress:t,style:n,focusedStyle:r,children:o,disabled:s},i){let l=useContext(Y),u=useContext(Z),f=useRef(null),a=useRef(null),b=useRef(t);b.current=t;let[I,S]=useState(false),[R,m]=useState(false);useImperativeHandle(i,()=>({focus(){l&&a.current&&l.requestFocus(a.current);},blur(){l&&l.blur();},get isFocused(){return R}}),[l,R]),useEffect(()=>{if(!(!l||!a.current||!f.current||s))return l.register(a.current,f.current)},[l,s,I]),useEffect(()=>{if(!l||!a.current)return;let g=a.current;return m(l.focusedId===g),l.onFocusChange(h=>{m(h===g);})},[l,I]),useEffect(()=>{if(!u||!a.current||s)return;let g=a.current,h=C=>l?.focusedId!==g?false:C.name==="return"||C.name===" "||C.sequence===" "?(b.current?.(),true):false;return u.registerInputHandler(g,h)},[u,l,s,I]);let y={...n,...R&&r?r:{}};return ae.createElement("box",{style:y,focusable:!s,ref:g=>{g?(f.current=g,a.current=g.focusId,S(true)):(f.current=null,a.current=null,S(false));}},o)});var Uo={x:0,y:0,width:0,height:0,innerX:0,innerY:0,innerWidth:0,innerHeight:0};function Me(e){let t=useContext(pe),[n,r]=useState(Uo);return useEffect(()=>{if(!(!t||!e?.current))return r(t.getLayout(e.current)),t.subscribe(e.current,r)},[t,e]),n}function ot(e,t=[]){let n=useContext(Z);useEffect(()=>{if(n)return n.subscribe(e)},[n,...t]);}function Qo({children:e,style:t,scrollOffset:n,onScroll:r,defaultScrollOffset:o=0,scrollStep:s=1,disableKeyboard:i,scrollToFocus:l=true,showScrollbar:u=true,focusable:f=true,focusedStyle:a,totalLines:b,overscan:I=2,virtualize:S=false,estimatedItemHeight:R=1}){let m=n!==void 0,[y,g]=useState(o),h=m?n:y,C=typeof e=="function",B=useMemo(()=>C?[]:ae.Children.toArray(e),[e,C]),j=b!==void 0&&C,H=S&&!C&&B.length>0,D=useRef(null),E=useRef(null),T=Me(D),$=Me(E),N=useRef(new Map),V=useRef(new Map),p=useContext(Y),w=useContext(pe),k=useRef(null);f&&!k.current&&(k.current=`scrollview-${Math.random().toString(36).slice(2,9)}`);let P=f?k.current:null;useEffect(()=>{if(!(!f||!P||!p||!D.current))return p.register(P,D.current)},[f,P,p]);let K=f&&P&&p?.focusedId===P,M=T.innerHeight,_=useCallback(()=>{if(!H)return 0;let O=0;for(let U=0;U<B.length;U++)O+=N.current.get(U)??R;return O},[H,B.length,R]),W=j?b:H?_():$.height,z=Math.max(0,W-M),A=Math.max(0,Math.min(h,z)),J=useMemo(()=>({getBounds:()=>{let O=T.y;return {visibleTop:O,visibleBottom:O+M,viewportHeight:M,scrollOffset:A}}}),[T.y,M,A]),L=useCallback(O=>{let U=Math.max(0,Math.min(O,z));m?r?.(U):g(U);},[m,r,z]);useEffect(()=>{h>z&&z>=0&&L(z);},[h,z,L]),useEffect(()=>!l||!p||!w||!E.current?void 0:p.onFocusChange(U=>{if(!U||!E.current)return;let te=Mt=>{if(Mt.focusId===U)return Mt;for(let jr of Mt.children){let Sn=te(jr);if(Sn)return Sn}return null},ge=te(E.current);if(!ge)return;let ie=w.getLayout(ge),ve=E.current.layout?.y??0,Bt=ie.y-ve,Cn=Bt+ie.height,Ar=h,Vr=h+M;Bt<Ar?L(Bt):Cn>Vr&&L(Cn-M);}),[l,p,w,h,M,L]);let le=useCallback(()=>{if(!p)return false;let O=p.focusedId;if(!O)return false;if(f&&P&&O===P)return true;if(!E.current)return false;let U=te=>{if(te.focusId===O)return true;for(let ge of te.children)if(U(ge))return true;return false};return U(E.current)},[p,f,P]);ot(O=>{if(i||!le())return;let U=Math.max(1,Math.floor(M/2)),te=Math.max(1,M);switch(O.name){case "pageup":L(h-te);break;case "pagedown":L(h+te);break;default:O.ctrl&&(O.name==="d"?L(h+U):O.name==="u"?L(h-U):O.name==="f"?L(h+te):O.name==="b"&&L(h-te));break}},[h,s,M,z,i,L,le]);let{padding:fe,paddingX:Ie,paddingY:Q,paddingTop:ee,paddingRight:c,paddingBottom:x,paddingLeft:G,...v}=t??{},d=v.border!=null&&v.border!=="none"?2:0,F=W>0?W+d:void 0,re={...v,...K?a:{},clip:true,...v.height===void 0&&F!==void 0?{height:F,flexShrink:v.flexShrink??1,minHeight:v.minHeight??0}:{}},q=useMemo(()=>{let O=Math.max(0,A-I),U=Math.min(b??W,A+M+I);return {start:O,end:U,scrollOffset:A,viewportHeight:M}},[A,M,I,b,W]),ne=useCallback(()=>{if(!H)return {startIndex:0,endIndex:0,startOffset:0};let O=0,U=0,te=0;for(let ie=0;ie<B.length;ie++){let ve=N.current.get(ie)??R;if(O+ve>A-I){U=ie,te=O;break}O+=ve,U=ie+1,te=O;}let ge=U;for(let ie=U;ie<B.length;ie++){let ve=N.current.get(ie)??R;if(ge=ie+1,O+=ve,O>=A+M+I)break}return {startIndex:U,endIndex:ge,startOffset:te}},[H,B.length,A,M,I,R])(),he={position:"absolute",top:j?q.start-A:H?ne.startOffset-A:-A,left:0,right:0,flexDirection:"column",...fe!==void 0&&{padding:fe},...Ie!==void 0&&{paddingX:Ie},...Q!==void 0&&{paddingY:Q},...ee!==void 0&&{paddingTop:ee},...c!==void 0&&{paddingRight:c},...x!==void 0&&{paddingBottom:x},...G!==void 0&&{paddingLeft:G}},be=j?e(q):H?B.slice(ne.startIndex,ne.endIndex).map((O,U)=>{let te=ne.startIndex+U;return ae.createElement("box",{key:te,ref:ge=>{ge?V.current.set(te,ge):V.current.delete(te);}},O)}):e,[,de]=useState(0);useEffect(()=>{if(!H||!w)return;let O=false;for(let[U,te]of V.current){let ie=w.getLayout(te).height||R;N.current.get(U)!==ie&&(N.current.set(U,ie),O=true);}O&&de(U=>U+1);});let Ce=W>M&&M>0,Ee=u&&Ce,ke=Math.max(1,Math.floor(M/W*M)),we=W-M,je=we>0?Math.floor(A/we*(M-ke)):0,Re=[];if(Ee)for(let O=0;O<M;O++)O>=je&&O<je+ke?Re.push("\u2588"):Re.push("\u2591");let ye={position:"absolute",top:0,right:0,width:1,height:M,flexDirection:"column"};return ae.createElement(De.Provider,{value:J},ae.createElement("box",{style:re,ref:O=>{D.current=O??null;},...f?{focusable:true,focusId:P}:{}},ae.createElement("box",{style:{...he,paddingRight:Ee?(he.paddingRight??0)+1:he.paddingRight},ref:O=>{E.current=O??null;}},be),Ee&&ae.createElement("box",{style:ye},ae.createElement("text",{style:{color:"blackBright"}},Re.join(`
|
|
14
|
+
`)))))}var tn=forwardRef(function({count:t,renderItem:n,selectedIndex:r,onSelectionChange:o,onSelect:s,defaultSelectedIndex:i=0,disabledIndices:l,style:u,focusable:f=true},a){let b=r!==void 0,[I,S]=useState(i),R=b?r:I,m=useContext(Y),y=useContext(Z),g=useRef(null),h=useRef(null),C=useRef(s);C.current=s;let[B,j]=useState(false),[H,D]=useState(false);useImperativeHandle(a,()=>({focus(){m&&h.current&&m.requestFocus(h.current);},blur(){m&&m.blur();},get isFocused(){return H},get selectedIndex(){return R}}),[m,H,R]);let E=useRef(null),T=useCallback(p=>{let w=Math.max(0,Math.min(p,t-1));b?o?.(w):S(w);},[b,o,t]),$=useCallback((p,w)=>{if(!l||l.size===0)return Math.max(0,Math.min(p+w,t-1));let k=p+w;for(;k>=0&&k<t&&l.has(k);)k+=w;return k<0||k>=t?p:k},[l,t]);useEffect(()=>{if(!(!m||!h.current||!g.current||!f))return m.register(h.current,g.current)},[m,f,B]),useEffect(()=>{if(!m||!h.current)return;let p=h.current;return D(m.focusedId===p),m.onFocusChange(w=>{D(w===p);})},[m,B]);let N=useCallback(p=>{let w=p?t-1:0,k=p?-1:1,P=w;for(;P>=0&&P<t&&l?.has(P);)P+=k;return P>=0&&P<t?P:p?t-1:0},[l,t]);useEffect(()=>{if(!y||!h.current||!f)return;let p=h.current,w=k=>m?.focusedId!==p?false:k.name==="g"&&!k.ctrl&&!k.alt?E.current==="g"?(T(N(false)),E.current=null,true):(E.current="g",true):k.name==="G"||k.name==="g"&&k.shift?(E.current=null,T(N(true)),true):(E.current=null,k.name==="up"||k.name==="k"?(T($(R,-1)),true):k.name==="down"||k.name==="j"?(T($(R,1)),true):k.name==="return"?(l?.has(R)||C.current?.(R),true):false);return y.registerInputHandler(p,w)},[y,m,f,R,T,$,N,l,B]);let V=[];for(let p=0;p<t;p++)V.push(ae.createElement(ae.Fragment,{key:p},n({index:p,selected:p===R,focused:H})));return ae.createElement("box",{style:{flexDirection:"column",...u},focusable:f,ref:p=>{p?(g.current=p,h.current=p.focusId,j(true)):(g.current=null,h.current=null,j(false));}},...V)});function ts({items:e,selectedIndex:t,onSelectionChange:n,onSelect:r,defaultSelectedIndex:o=0,style:s,highlightColor:i="cyan",focusable:l=true}){let u=new Set;for(let a=0;a<e.length;a++)e[a].disabled&&u.add(a);let f=a=>{let b=e[a];b&&!b.disabled&&r?.(b.value,a);};return ae.createElement(tn,{count:e.length,selectedIndex:t,onSelectionChange:n,onSelect:f,defaultSelectedIndex:o,disabledIndices:u.size>0?u:void 0,style:s,focusable:l,renderItem:({index:a,selected:b,focused:I})=>{let S=e[a],R=S.disabled,m=b&&I,y=b?">":" ";return ae.createElement("box",{style:{flexDirection:"row",...m?{bg:i}:{}}},ae.createElement("text",{style:m?{bold:true,color:"black"}:R?{dim:true}:{}},`${y} ${S.label}`))}})}function ss({value:e,indeterminate:t=false,width:n="100%",label:r,showPercent:o=false,style:s,filled:i="\u2588",empty:l="\u2591"}){let u=useRef(null),a=Me(u).innerWidth,[b,I]=useState(0);useEffect(()=>{if(!t)return;let g=setInterval(()=>{I(h=>(h+1)%Math.max(1,a+6));},100);return ()=>clearInterval(g)},[t,a]);let S=Math.max(0,Math.min(1,e??0)),R=o?` ${Math.round(S*100)}%`:"",m="";if(a>0)if(t&&e===void 0){let g=Math.max(1,Math.min(3,Math.floor(a/4))),h=[];for(let C=0;C<a;C++)C>=b-g&&C<b?h.push(i):h.push(l);m=h.join("");}else {let g=Math.round(S*a);m=i.repeat(g)+l.repeat(a-g);}let y=[];return r&&y.push(ae.createElement("text",{key:"label",style:{bold:true}},r+" ")),y.push(ae.createElement("box",{key:"track",style:{flexGrow:1,flexShrink:1},ref:g=>{u.current=g??null;}},ae.createElement("text",{key:"bar",style:{}},m))),o&&y.push(ae.createElement("text",{key:"pct",style:{bold:true}},R)),ae.createElement("box",{style:{flexDirection:"row",width:n,...s}},...y)}var cs=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function us({frames:e=cs,intervalMs:t=80,label:n,style:r}){let[o,s]=useState(0);useEffect(()=>{let l=setInterval(()=>{s(u=>(u+1)%e.length);},t);return ()=>clearInterval(l)},[e.length,t]);let i=[ae.createElement("text",{key:"frame",style:r},e[o])];return n&&i.push(ae.createElement("text",{key:"label",style:{}}," "+n)),ae.createElement("box",{style:{flexDirection:"row"}},...i)}var xr=createContext(null),hs=0;function gs(){let e=useContext(xr);if(!e)throw new Error("useToast must be used within a <ToastHost>");return e.push}var xs={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 ys({position:e="bottom-right",maxVisible:t=5,children:n}){let[r,o]=useState([]),s=useRef(new Map),i=useCallback(S=>{let R=`toast-${hs++}`,m={id:R,durationMs:3e3,variant:"info",...S};if(o(y=>[...y,m]),m.durationMs&&m.durationMs>0){let y=setTimeout(()=>{s.current.delete(R),o(g=>g.filter(h=>h.id!==R));},m.durationMs);s.current.set(R,y);}},[]);useEffect(()=>()=>{for(let S of s.current.values())clearTimeout(S);s.current.clear();},[]);let l=useRef({push:i});l.current.push=i;let u=e.startsWith("top"),f=e.endsWith("right"),a={position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:900,flexDirection:"column",justifyContent:u?"flex-start":"flex-end",alignItems:f?"flex-end":"flex-start",padding:1},I=r.slice(-t).map(S=>{let R=S.variant??"info",m=xs[R],y=[];return S.title&&y.push(ae.createElement("text",{key:"title",style:{bold:true,color:m.title}},S.title)),y.push(ae.createElement("text",{key:"msg",style:{color:m.text}},S.message)),ae.createElement("box",{key:S.id,style:{bg:m.bg,paddingX:1,flexDirection:"column",minWidth:20,maxWidth:50}},...y)});return ae.createElement(xr.Provider,{value:l.current},n,I.length>0?ae.createElement("box",{style:a},...I):null)}var Is=forwardRef(function({items:t,value:n,onChange:r,placeholder:o="Select...",style:s,focusedStyle:i,dropdownStyle:l,highlightColor:u="cyan",maxVisible:f=8,searchable:a=true,openDirection:b="auto",disabled:I},S){let R=useContext(Y),m=useContext(Z),y=useContext(Fe),g=useContext(De),h=useRef(null),C=useRef(null),B=useRef(r);B.current=r;let[j,H]=useState(false),[D,E]=useState(false),[T,$]=useState(false);useImperativeHandle(S,()=>({focus(){R&&C.current&&R.requestFocus(C.current);},blur(){R&&R.blur();},get isFocused(){return D},get value(){return n},get isOpen(){return T}}),[R,D,n,T]);let[N,V]=useState(0),[p,w]=useState(""),[k,P]=useState(0),K=Me(h),M=y?.rows??24,_=g?.getBounds(),z=t.find(v=>v.value===n)?.label??"",A=useMemo(()=>{if(!p)return t;let v=p.toLowerCase();return t.filter(X=>X.label.toLowerCase().includes(v))},[t,p]),J=Math.min(f,A.length),L=A.slice(k,k+J);useEffect(()=>{V(0),P(0);},[p]),useEffect(()=>{!D&&T&&($(false),w(""));},[D,T]),useEffect(()=>{if(!(!R||!C.current||!h.current))return R.register(C.current,h.current)},[R,j]),useEffect(()=>{!R||!C.current||R.setSkippable(C.current,!!I);},[R,I,j]),useEffect(()=>{if(!R||!C.current)return;let v=C.current;return E(R.focusedId===v),R.onFocusChange(X=>{E(X===v);})},[R,j]);let le=useCallback((v,X)=>{let d=v+X;for(;d>=0&&d<A.length;){if(!A[d].disabled)return d;d+=X;}return v},[A]),fe=useCallback(v=>{v<k?P(v):v>=k+J&&P(v-J+1);},[k,J]);useEffect(()=>{if(!m||!C.current||I)return;let v=C.current,X=d=>{if(R?.focusedId!==v)return false;if(!T){if(d.name==="return"||d.name===" "||d.sequence===" "){$(true),w("");let F=A.findIndex(q=>q.value===n),re=F>=0?F:0;return V(re),P(Math.max(0,re-Math.floor(f/2))),true}return false}if(d.name==="tab")return $(false),w(""),false;if(d.name==="escape")return $(false),w(""),true;if(d.name==="return"){let F=A[N];return F&&!F.disabled&&(B.current?.(F.value),$(false),w("")),true}if(d.name==="up"){let F=le(N,-1);return V(F),fe(F),true}if(d.name==="down"){let F=le(N,1);return V(F),fe(F),true}if(d.name==="backspace")return a&&p.length>0&&w(F=>F.slice(0,-1)),true;if(d.name==="home"){let F=le(-1,1);return V(F),fe(F),true}if(d.name==="end"){let F=le(A.length,-1);return V(F),fe(F),true}if(a&&d.sequence&&d.sequence.length===1&&!d.ctrl&&!d.alt){let F=d.sequence;if(F>=" "&&F<="~")return w(re=>re+F),true}return true};return m.registerInputHandler(v,X)},[m,R,I,T,N,A,n,f,a,p,le,fe,j]);let Q={flexDirection:"row",width:"100%",...!s?.bg&&s?.border===void 0?{border:"single"}:{},...s,...D&&i?i:{}},ee=z?s?.color??void 0:"blackBright",c=[ae.createElement("text",{key:"label",style:{flexGrow:1,flexShrink:1,color:ee,wrap:"ellipsis",...z?{}:{dim:true}}},z||o),ae.createElement("text",{key:"arrow",style:{flexShrink:0,color:D?u:"blackBright"}},T?" \u25B2":" \u25BC")],x=null;if(T){let v=[];a&&p&&v.push(ae.createElement("box",{key:"search",style:{paddingX:1}},ae.createElement("text",{style:{color:"blackBright",dim:true}},`/${p}`))),A.length===0&&v.push(ae.createElement("box",{key:"empty",style:{paddingX:1}},ae.createElement("text",{style:{dim:true,color:"blackBright"}},"No matches"))),k>0&&v.push(ae.createElement("box",{key:"scroll-up",style:{justifyContent:"center",alignItems:"center"}},ae.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25B2"))),L.forEach((ke,we)=>{let Re=k+we===N,ye=ke.disabled,O={paddingX:1,...Re&&!ye?{bg:u}:{}},U={...Re&&!ye?{color:"black",bold:true}:{},...ye?{dim:true,color:"blackBright"}:{}};v.push(ae.createElement("box",{key:`item-${ke.value}`,style:O},ae.createElement("text",{style:U},ke.label)));}),k+J<A.length&&v.push(ae.createElement("box",{key:"scroll-down",style:{justifyContent:"center",alignItems:"center"}},ae.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25BC")));let X=k>0,d=k+J<A.length,F=a&&p,re=A.length===0,q=!l?.bg&&l?.border===void 0,ne=J+(q?2:0);X&&(ne+=1),d&&(ne+=1),F&&(ne+=1),re&&(ne+=1);let he=K.y+K.height,be,de;_?(be=_.visibleBottom-he,de=K.y-_.visibleTop):(be=M-he,de=K.y);let Ee=(b==="up"?true:b==="down"?false:be<ne&&de>=ne)?-ne:K.height||1;x=ae.createElement("box",{style:{position:"absolute",top:Ee,left:0,right:0,zIndex:9999,...q?{border:"single"}:{},bg:"black",flexDirection:"column",...l}},...v);}let G={flexDirection:"column",width:Q.width??"100%",minWidth:Q.minWidth,maxWidth:Q.maxWidth,flexGrow:Q.flexGrow,flexShrink:Q.flexShrink??1};return ae.createElement("box",{style:G},ae.createElement("box",{style:Q,focusable:true,ref:v=>{v?(h.current=v,C.current=v.focusId,H(true)):(h.current=null,C.current=null,H(false));}},...c),x)});var vs=forwardRef(function({checked:t,onChange:n,label:r,style:o,focusedStyle:s,disabled:i,checkedChar:l="\u2713",uncheckedChar:u=" "},f){let a=useContext(Y),b=useContext(Z),I=useRef(null),S=useRef(null),R=useRef(n);R.current=n;let m=useRef(t);m.current=t;let[y,g]=useState(false),[h,C]=useState(false);useImperativeHandle(f,()=>({focus(){a&&S.current&&a.requestFocus(S.current);},blur(){a&&a.blur();},get isFocused(){return h},get checked(){return m.current}}),[a,h]),useEffect(()=>{if(!(!a||!S.current||!I.current||i))return a.register(S.current,I.current)},[a,i,y]),useEffect(()=>{if(!a||!S.current)return;let E=S.current;return C(a.focusedId===E),a.onFocusChange(T=>{C(T===E);})},[a,y]),useEffect(()=>{if(!b||!S.current||i)return;let E=S.current,T=$=>a?.focusedId!==E?false:$.name==="return"||$.name===" "||$.sequence===" "?(R.current(!m.current),true):false;return b.registerInputHandler(E,T)},[b,a,i,y]);let B={flexDirection:"row",gap:1,...o,...h&&s?s:{}},j=t?l:u,H={color:i?"blackBright":h?"white":o?.color},D={color:i?"blackBright":o?.color};return ae.createElement("box",{style:B,focusable:!i,ref:E=>{E?(I.current=E,S.current=E.focusId,g(true)):(I.current=null,S.current=null,g(false));}},ae.createElement("text",{key:"box",style:H},`[${j}]`),r?ae.createElement("text",{key:"label",style:D},r):null)});function Es({items:e,value:t,onChange:n,style:r,itemStyle:o,focusedItemStyle:s,selectedItemStyle:i,disabled:l,direction:u="column",gap:f=0,selectedChar:a="\u25CF",unselectedChar:b="\u25CB",forwardedRef:I}){let S=useContext(Y),R=useContext(Z),m=useRef(null),y=useRef(null),g=useRef(n);g.current=n;let[h,C]=useState(false),[B,j]=useState(false);useImperativeHandle(I,()=>({focus(){S&&y.current&&S.requestFocus(y.current);},blur(){S&&S.blur();},get isFocused(){return B},get value(){return t}}),[S,B,t]);let[H,D]=useState(()=>{let N=e.findIndex(V=>V.value===t);return N>=0?N:e.findIndex(V=>!V.disabled)}),E=useCallback((N,V)=>{let p=N;for(let w=0;w<e.length;w++)if(p=(p+V+e.length)%e.length,!e[p]?.disabled)return p;return N},[e]);useEffect(()=>{if(!(!S||!y.current||!m.current||l))return S.register(y.current,m.current)},[S,l,h]),useEffect(()=>{if(!S||!y.current)return;let N=y.current;return j(S.focusedId===N),S.onFocusChange(V=>{j(V===N);})},[S,h]),useEffect(()=>{if(!R||!y.current||l)return;let N=y.current,V=p=>{if(S?.focusedId!==N)return false;if(p.name==="up"||p.name==="left"||p.name==="k"||p.name==="tab"&&p.shift)return D(w=>E(w,-1)),true;if(p.name==="down"||p.name==="right"||p.name==="j"||p.name==="tab"&&!p.shift)return D(w=>E(w,1)),true;if(p.name==="return"||p.name===" "||p.sequence===" "){let w=e[H];return w&&!w.disabled&&g.current(w.value),true}return false};return R.registerInputHandler(N,V)},[R,S,l,e,H,E,h]),useEffect(()=>{let N=e.findIndex(V=>V.value===t);N>=0&&D(N);},[t,e]);let T={flexDirection:u,gap:f,...r},$=e.map((N,V)=>{let p=N.value===t,w=V===H,k=l||N.disabled,P=p?a:b,K={flexDirection:"row",gap:1,...o};p&&i&&(K={...K,...i}),B&&w&&s&&(K={...K,...s});let M=k?"blackBright":B&&w?s?.color??"white":p?i?.color??o?.color:o?.color;return ae.createElement("box",{key:V,style:K},ae.createElement("text",{key:"radio",style:{color:M}},`(${P})`),ae.createElement("text",{key:"label",style:{color:M}},N.label))});return ae.createElement("box",{style:T,focusable:!l,ref:N=>{N?(m.current=N,y.current=N.focusId,C(true)):(m.current=null,y.current=null,C(false));}},...$)}var Ns=forwardRef(function(t,n){return ae.createElement(Es,{...t,forwardedRef:n})});var Rr=createContext(null);function Fs(){let e=useContext(Rr);if(!e)throw new Error("useDialog must be used within a DialogHost");return e}function Bs({children:e}){let[t,n]=useState([]),r=useRef(0),o=useCallback((f,a)=>new Promise(b=>{let I=++r.current;n(S=>[...S,{id:I,type:"alert",content:f,okText:a?.okText??"OK",cancelText:"",style:a?.style,buttonStyle:a?.buttonStyle,okButtonStyle:a?.okButtonStyle,focusedButtonStyle:a?.focusedButtonStyle,backdropStyle:a?.backdropStyle,resolve:()=>b()}]);}),[]),s=useCallback((f,a)=>new Promise(b=>{let I=++r.current;n(S=>[...S,{id:I,type:"confirm",content:f,okText:a?.okText??"OK",cancelText:a?.cancelText??"Cancel",style:a?.style,buttonStyle:a?.buttonStyle,okButtonStyle:a?.okButtonStyle,cancelButtonStyle:a?.cancelButtonStyle,focusedButtonStyle:a?.focusedButtonStyle,backdropStyle:a?.backdropStyle,resolve:b}]);}),[]),i=useCallback((f,a)=>{n(b=>{let I=b.find(S=>S.id===f);return I&&I.resolve(a),b.filter(S=>S.id!==f)});},[]),l={alert:o,confirm:s},u=t[t.length-1];return ae.createElement(Rr.Provider,{value:l},e,u&&ae.createElement(Ms,{key:u.id,dialog:u,onDismiss:i}))}function Ms({dialog:e,onDismiss:t}){let n=useContext(Y),r=useRef(null),o=useRef(null),s=useRef(null),i=useRef(null),[l,u]=useState("ok"),[f,a]=useState(0);useEffect(()=>{if(!n||f===0)return;let g=[];return r.current&&s.current&&g.push(n.register(s.current,r.current)),o.current&&i.current&&g.push(n.register(i.current,o.current)),s.current&&n.requestFocus(s.current),()=>g.forEach(h=>h())},[n,f]),useEffect(()=>{if(n)return n.onFocusChange(g=>{g===s.current?u("ok"):g===i.current&&u("cancel");})},[n]),ot(g=>{if(g.name==="return"||g.name==="space"){e.type==="alert"?t(e.id,true):t(e.id,l==="ok");return}if(g.name==="escape"){t(e.id,false);return}e.type==="confirm"&&n&&(g.name==="left"||g.name==="right")&&(l==="ok"&&i.current?n.requestFocus(i.current):s.current&&n.requestFocus(s.current));},[e,l,n,t]);let b=typeof e.content=="string",I=b?e.content.length:0,R={minWidth:Math.max(20,b?Math.min(I+6,50):30),maxWidth:50,bg:"black",border:"round",borderColor:"white",padding:1,flexDirection:"column",gap:1,...e.style},m=(g,h)=>{let C={paddingX:2,bg:"blackBright",color:"white"},B={bg:"white",color:"black",bold:true},j=g==="ok"?e.okButtonStyle:e.cancelButtonStyle;return {...C,...e.buttonStyle,...j,...h?{...B,...e.focusedButtonStyle}:{}}},y={position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:999,...e.backdropStyle};return ae.createElement(zt,{trap:true},ae.createElement("box",{style:y}),ae.createElement("box",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,justifyContent:"center",alignItems:"center",zIndex:1e3}},ae.createElement("box",{style:R},ae.createElement("box",{style:{flexDirection:"column"}},typeof e.content=="string"?ae.createElement("text",null,e.content):e.content),ae.createElement("box",{style:{flexDirection:"row",justifyContent:"flex-end",gap:1}},e.type==="confirm"&&ae.createElement("box",{style:m("cancel",l==="cancel"),focusable:true,ref:g=>{g&&g.focusId&&!i.current&&(o.current=g,i.current=g.focusId,a(h=>h+1));}},ae.createElement("text",null,e.cancelText)),ae.createElement("box",{style:m("ok",l==="ok"),focusable:true,ref:g=>{g&&g.focusId&&!s.current&&(r.current=g,s.current=g.focusId,a(h=>h+1));}},ae.createElement("text",null,e.okText))))))}function As(e,t){let n=[],r=e.parent;for(;r;)r.style.clip&&n.push({x:r.layout.innerX,y:r.layout.innerY,width:r.layout.innerWidth,height:r.layout.innerHeight}),r=r.parent;let o=t;for(let s of n)o=Vs(o,s);return o}function Vs(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 js(e,t){if(t.width<=0||t.height<=0)return false;let n=e.x+e.width,r=e.y+e.height;return e.x<t.x+t.width&&n>t.x&&e.y<t.y+t.height&&r>t.y}function Os(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 $s({children:e,activationKey:t="ctrl+o",hintStyle:n,hintBg:r="yellow",hintFg:o="black",hintChars:s="asdfghjklqwertyuiopzxcvbnm",enabled:i=true,debug:l=false}){let u=l?(...p)=>console.error("[JumpNav]",...p):()=>{},[f,a]=useState(false),[b,I]=useState(""),[S,R]=useState([]),m=useContext(Z),y=useContext(Y),g=useContext(pe),h=useContext(Fe);useEffect(()=>{u("Mounted, inputCtx:",!!m,"focusCtx:",!!y,"enabled:",i);},[]);let B=useCallback(p=>{let w=p.toLowerCase().split("+");return {ctrl:w.includes("ctrl"),alt:w.includes("alt"),shift:w.includes("shift"),meta:w.includes("meta"),name:w[w.length-1]??""}},[])(t),j=useCallback(()=>{if(!y?.getActiveElements){u("refreshElements: no getActiveElements");return}let p=y.getActiveElements();u("getActiveElements returned",p.length,"elements");let w=h?.columns??80,k=h?.rows??24,P={x:0,y:0,width:w,height:k},K=p.map(({id:M,node:_})=>({id:M,node:_,layout:g?.getLayout(_)??_.layout,clipRegion:As(_,P)}));K.sort((M,_)=>M.layout.y!==_.layout.y?M.layout.y-_.layout.y:M.layout.x-_.layout.x),R(K);},[y,g,h,u]),H=useRef(false);useEffect(()=>{f&&!H.current&&(u("Activated! Refreshing elements..."),j()),H.current=f;},[f,j,u]);let D=h?.columns??80,E=h?.rows??24,T=S.filter(p=>p.layout.width>0&&p.layout.height>0&&js(p.layout,p.clipRegion)),$=Os(T.length,s),N=useMemo(()=>{let p=new Map;return T.forEach((w,k)=>{$[k]&&p.set($[k],w.id);}),p},[T,$]);useEffect(()=>{if(!m||!i){u("Not subscribing - inputCtx:",!!m,"enabled:",i);return}u("Subscribing to priority input, activation key:",t);let p=w=>{let k=w.name===B.name,P=!!w.ctrl===B.ctrl,K=!!w.alt===B.alt,M=!!w.shift===B.shift,_=!!w.meta===B.meta;if(!f&&k&&P&&K&&M&&_)return u("Activation key matched! Activating..."),a(true),I(""),true;if(f){if(w.name==="escape")return u("Escape pressed, deactivating"),a(false),I(""),true;if(w.name==="backspace")return I(""),true;if(w.sequence&&w.sequence.length===1&&/[a-z]/i.test(w.sequence)){let W=b+w.sequence.toLowerCase();u("Buffer:",W);let z=N.get(W);return z?(u("Jumping to",z),y?.requestFocus(z),a(false),I(""),true):[...N.keys()].some(J=>J.startsWith(W))?(I(W),true):(I(""),true)}return true}return false};return m.subscribePriority(p)},[m,i,f,B,b,N,y,t,u]);let V=f?ae.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:99998}},...T.map((p,w)=>{let k=$[w];if(!k)return null;let{x:P,y:K,width:M}=p.layout,_=p.clipRegion,W=k.length+2,z=Math.max(_.y,Math.min(K,_.y+_.height-1,E-1)),A=P-W,J=P+M,L;A>=_.x&&A>=0?L=A:J+W<=_.x+_.width&&J+W<=D?L=J:L=Math.max(_.x,Math.min(P,D-W)),L=Math.max(0,Math.min(L,D-W));let le=k.startsWith(b)&&b.length>0;return ae.createElement("box",{key:p.id,style:{position:"absolute",top:z,left:L,bg:le?"cyan":r,color:o,paddingX:1,zIndex:99999,...n}},ae.createElement("text",{style:{bold:true,color:o}},k))}),ae.createElement("box",{style:{position:"absolute",bottom:0,left:0,right:0,bg:"blackBright",paddingX:1,zIndex:99999}},ae.createElement("text",{style:{color:"white"}},b?`Jump: ${b}_`:"Press a key to jump \u2022 ESC to cancel"))):null;return ae.createElement(ae.Fragment,null,e,V)}var qe=join(tmpdir(),"glyph-image-cache");function Nt(e){return e.startsWith("http://")||e.startsWith("https://")}function qs(e,t){let n=createHash("md5").update(e).digest("hex"),r=t?zs(t):_s(e)||".png";return join(qe,`${n}${r}`)}function _s(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 zs(e){switch(e){case "png":return ".png";case "jpeg":return ".jpeg";case "gif":return ".gif";case "webp":return ".webp";default:return ".png"}}function xn(e){if(Nt(e))try{let t=new URL(e),n=t.pathname;return basename(n)||t.hostname}catch{return "remote-image"}return basename(e)}function Pr(){existsSync(qe)||mkdirSync(qe,{recursive:true});}async function Er(e){let t=xn(e);return Nt(e)?Us(e,t):Xs(e,t)}async function Xs(e,t){if(!existsSync(e))throw new Error(`Image not found: ${e}`);return {data:readFileSync(e),name:t,localPath:e,isRemote:false}}async function Us(e,t){Pr();let n=createHash("md5").update(e).digest("hex"),r=[".png",".jpeg",".gif",".webp"];for(let f of r){let a=join(qe,`${n}${f}`);if(existsSync(a))return {data:readFileSync(a),name:t,localPath:a,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(!Ys(i))throw new Error(`Invalid image data from: ${e}`);let l=Gt(i),u=qs(e,l);return writeFileSync(u,i),{data:i,name:t,localPath:u,isRemote:true}}function Ys(e){return e.length<4?false:e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71||e[0]===255&&e[1]===216&&e[2]===255||e[0]===71&&e[1]===73&&e[2]===70||e[0]===66&&e[1]===77||e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e.length>=12&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80||e[0]===0&&e[1]===0&&e[2]===1&&e[3]===0}function Gt(e){return e.length<4?"unknown":e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"png":e[0]===255&&e[1]===216&&e[2]===255?"jpeg":e[0]===71&&e[1]===73&&e[2]===70?"gif":e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e.length>=12&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80?"webp":"unknown"}function Nr(e,t){let n=Gt(e);if(n==="png")return e;Pr();let r=createHash("md5").update(e).digest("hex"),o=join(qe,`${r}.${n}`),s=join(qe,`${r}.png`);try{writeFileSync(o,e);let i=platform(),l=!1;if(i==="darwin")try{execSync(`sips -s format png "${o}" --out "${s}" 2>/dev/null`,{stdio:"pipe"}),l=!0;}catch{}if(!l)try{execSync(`magick "${o}" "${s}" 2>/dev/null`,{stdio:"pipe"}),l=!0;}catch{}if(!l)try{execSync(`convert "${o}" "${s}" 2>/dev/null`,{stdio:"pipe"}),l=!0;}catch{}if(l&&existsSync(s)){let u=readFileSync(s);try{unlinkSync(o);}catch{}try{unlinkSync(s);}catch{}return u}try{unlinkSync(o);}catch{}return null}catch{try{unlinkSync(o);}catch{}try{unlinkSync(s);}catch{}return null}}function Qs(){let e=platform();return e==="darwin"?"quicklook":e==="linux"||e==="win32"?"open":"none"}async function yn(e){switch(Qs()){case "quicklook":return Zs(e);case "open":return ti(e);case "none":throw new Error("No preview method available on this platform")}}function Zs(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(()=>{ei();},50),r.on("close",o=>{t();});})}function ei(){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 ti(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",l=>{n(new Error(`Failed to open preview: ${l.message}`));}),setTimeout(t,100);})}var oi=forwardRef(function({src:t,width:n,height:r,unloadTrigger:o,style:s,focusedStyle:i,placeholderStyle:l,focusable:u=true,disabled:f=false,inline:a=true,placeholder:b,onStateChange:I,onError:S,autoLoad:R=false,autoSize:m=false,maxWidth:
|
|
18
|
+
'`,()=>{});}function ti(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",l=>{n(new Error(`Failed to open preview: ${l.message}`));}),setTimeout(t,100);})}var oi=forwardRef(function({src:t,width:n,height:r,unloadTrigger:o,style:s,focusedStyle:i,placeholderStyle:l,focusable:u=true,disabled:f=false,inline:a=true,placeholder:b,onStateChange:I,onError:S,autoLoad:R=false,autoSize:m=false,maxWidth:y,maxHeight:g},h){let C=useContext(Y),B=useContext(Z),j=useContext(pe),H=useContext(Ct),D=useContext(De),E=useRef(null),T=useRef(null),$=useRef(Math.floor(Math.random()*1e6)),N=useRef(null),[V,p]=useState(false),[w,k]=useState(false),[P,K]=useState("placeholder"),[M,_]=useState(null),[W,z]=useState(null),[A,J]=useState(null),L=useRef(null);useImperativeHandle(h,()=>({focus(){C&&T.current&&C.requestFocus(T.current);},blur(){C&&C.blur();},get isFocused(){return w}}),[C,w]);let le=b||xn(t),fe=Nt(t),Ie=useRef(o);useEffect(()=>{o!==void 0&&o!==Ie.current&&P==="loaded"&&(L.current=null,J(null),K("placeholder")),Ie.current=o;},[o,P]);let Q=useCallback(q=>{K(q),I?.(q);},[I]);useEffect(()=>{if(!(!C||!T.current||!E.current||!u))return C.register(T.current,E.current,false)},[C,u,V]),useEffect(()=>{!C||!T.current||(C.setSkippable(T.current,!!f),f&&C.focusedId===T.current&&C.blur());},[C,f]),useEffect(()=>{if(!C||!T.current)return;let q=T.current;return k(C.focusedId===q),C.onFocusChange(se=>{k(se===q);})},[C,V]),useEffect(()=>{if(!(!j||!E.current))return z(j.getLayout(E.current)),j.subscribe(E.current,z)},[j,V]);let ee=D?.getBounds().scrollOffset??0;useEffect(()=>{if(D){if(N.current===null){N.current=ee;return}if(P!=="loaded"){N.current=ee;return}ee!==N.current&&(N.current=ee,L.current=null,J(null),K("placeholder"));}},[D,ee,P]),useEffect(()=>{if(!H||P!=="loaded"||!L.current||!W)return;let{data:q,cellWidth:se,cellHeight:ne}=L.current,he=$.current,be=setTimeout(()=>{H.registerImage({id:he,data:q,x:W.innerX,y:W.innerY,width:se,height:ne});},0);return ()=>{clearTimeout(be),H.unregisterImage(he);}},[H,P,W,D]);let c=useCallback(async()=>{if(P!=="loading"){Q("loading"),_(null);try{let q=await Er(t);if(a&&Dt()&&W){let ne=Gt(q.data),he=q.data;if(ne!=="png"){let we=Nr(q.data);if(!we){Q("preview"),await yn(q.localPath),Q("placeholder");return}he=we;}let be=qt(he),de,Ce;if(m&&be){let ye=Math.ceil(be.width/8),O=Math.ceil(be.height/16),U=y??80,te=g??24;if(ye>U||O>te){let ge=U/ye,ie=te/O,ve=Math.min(ge,ie);ye=Math.max(1,Math.round(ye*ve)),O=Math.max(1,Math.round(O*ve));}de=ye,Ce=O,J({width:ye,height:O});}else de=n??W.innerWidth,Ce=r??W.innerHeight;if(de<=0||Ce<=0)throw new Error("Image area too small");let Ee=30,ke=6;if(de>Ee||Ce>ke){let we=Ee/de,je=ke/Ce,Re=Math.min(we,je);de=Math.max(1,Math.round(de*Re)),Ce=Math.max(1,Math.round(Ce*Re));}L.current={data:he,localPath:q.localPath,cellWidth:de,cellHeight:Ce},Q("loaded");}else Q("preview"),await yn(q.localPath),Q("placeholder");}catch(q){let se=q instanceof Error?q:new Error(String(q));_(se.message),Q("error"),S?.(se);}}},[t,P,a,W,n,r,m,y,g,Q,S]);useEffect(()=>{if(!B||!T.current||!u||f)return;let q=T.current,se=ne=>C?.focusedId!==q?false:ne.name==="space"||ne.name==="return"||ne.name==="r"&&L.current?(c(),true):ne.name==="escape"&&P==="loaded"?(L.current=null,J(null),Q("placeholder"),true):ne.name==="escape"&&P==="placeholder"?(C?.blur(),true):false;return B.registerInputHandler(q,se)},[B,C,u,f,V,c,P,Q]),useEffect(()=>{R&&P==="placeholder"&&W&&W.innerWidth>0&&c();},[R,P,W,c]),useEffect(()=>{let q=$.current;return ()=>{H?.unregisterImage(q);}},[H]);let x,G;switch(P){case "placeholder":G=fe?"\u{1F310}":"\u{1F5BC}\uFE0F",x=`${G} ${le}`;break;case "loading":G="\u23F3",x=`${G} Loading...`;break;case "loaded":x=null;break;case "preview":G="\u{1F441}\uFE0F",x=`${G} Previewing...`;break;case "error":G="\u274C",x=`${G} ${M||"Error"}`;break}let v=m&&A?A.width:n,X=m&&A?A.height:r,F={...{border:"round",borderColor:"blackBright",justifyContent:"center",alignItems:"center",...s,...v!==void 0?{width:v}:{},...X!==void 0?{height:X}:{}},...w?{borderColor:"cyan"}:{},...w&&i?i:{}},re={color:"blackBright",...l,...w?{color:"cyan"}:{}};return ae.createElement("box",{style:F,focusable:u,ref:q=>{q?(E.current=q,T.current=q.focusId,p(true)):(E.current=null,T.current=null,p(false));}},x!==null?ae.createElement("text",{style:re},x):null)});function ui(e){let t=useContext(Y),[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 fi(e={}){let{disabled:t,onFocus:n,onBlur:r,onKeyPress:o}=e,s=useContext(Y),i=useContext(Z),l=useRef(null),u=useRef(null),[f,a]=useState(false),b=useRef(n),I=useRef(r),S=useRef(o);b.current=n,I.current=r,S.current=o;let R=useCallback(g=>{l.current=g,g?u.current=g.focusId??null:u.current=null;},[]);useEffect(()=>{if(!(!s||!u.current||!l.current))return s.register(u.current,l.current)},[s]),useEffect(()=>{!s||!u.current||(s.setSkippable(u.current,!!t),t&&s.focusedId===u.current&&s.blur());},[s,t]),useEffect(()=>{if(!s||!u.current)return;let g=u.current,h=s.focusedId===g;return a(h),s.onFocusChange(C=>{let B=C===g;a(j=>(B&&!j?b.current?.():!B&&j&&I.current?.(),B));})},[s]),useEffect(()=>{if(!i||!u.current||t)return;let g=u.current,h=C=>s?.focusedId!==g?false:S.current?.(C)===true;return i.registerInputHandler(g,h)},[i,s,t]);let m=useCallback(()=>{s&&u.current&&s.requestFocus(u.current);},[s]),y=useCallback(()=>{s&&s.blur();},[s]);return {ref:R,isFocused:f,focus:m,blur:y,focusId:u.current}}function pi(){let e=useContext(Fe);if(!e)throw new Error("useApp must be used within a Glyph render tree");return {exit:e.exit,get columns(){return e.columns},get rows(){return e.rows}}}function yi(){let e=useContext(Y),t=useContext(pe),[n,r]=useState([]),o=useRef(()=>{}),s=useCallback(()=>{if(!e)return;let l=(e.getActiveElements?.()??e.getRegisteredElements?.()??[]).map(({id:u,node:f})=>({id:u,node:f,layout:t?.getLayout(f)??f.layout,type:f.type}));l.sort((u,f)=>u.layout.y!==f.layout.y?u.layout.y-f.layout.y:u.layout.x-f.layout.x),r(l);},[e,t]);return o.current=s,useEffect(()=>{if(!e)return;s();let i=e.onFocusChange(()=>{s();}),l=setTimeout(s,50);return ()=>{i(),clearTimeout(l);}},[e,t,s]),e?{elements:n,focusedId:e.focusedId,requestFocus:e.requestFocus,focusNext:e.focusNext,focusPrev:e.focusPrev,refresh:()=>o.current()}:null}function bi(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 Ci(e,t){switch(t){case "digit":return /\d/.test(e);case "letter":return /[a-zA-Z]/.test(e);case "alphanumeric":return /[a-zA-Z0-9]/.test(e);case "literal":return true}}function me(e){let t=typeof e=="string"?{mask:e}:e,{mask:n,placeholder:r="_",showPlaceholder:o=false}=t,s=bi(n);return (i,l)=>{let u=[];for(let b of i)(b!==r&&!/[\s\-\(\)\/\.\:]/.test(b)||/[a-zA-Z0-9]/.test(b))&&/[a-zA-Z0-9]/.test(b)&&u.push(b);let f="",a=0;for(let b of s)if(b.type==="literal")(a<u.length||o)&&(f+=b.char);else if(a<u.length){let I=u[a];if(Ci(I,b.type))f+=I,a++;else {a++;continue}}else o&&(f+=r);return f}}var Si={usPhone:me("(999) 999-9999"),intlPhone:me("+9 999 999 9999"),dateUS:me("99/99/9999"),dateEU:me("99/99/9999"),dateISO:me("9999-99-99"),time:me("99:99"),timeFull:me("99:99:99"),creditCard:me("9999 9999 9999 9999"),ssn:me("999-99-9999"),zip:me("99999"),zipPlus4:me("99999-9999"),ipv4:me("999.999.999.999"),mac:me("**:**:**:**:**:**")};export{So as Box,qo as Button,vs as Checkbox,Bs as DialogHost,zt as FocusScope,oi as Image,Fo as Input,$s as JumpNav,jo as Keybind,tn as List,ts as Menu,$o as Portal,ss as Progress,Ns as Radio,Qo as ScrollView,Is as Select,Ao as Spacer,us as Spinner,Po as Text,ys as ToastHost,me as createMask,Ze as detectTerminalCapabilities,Si as masks,$t as parseAnsi,yo as render,eo as stripAnsi,Dt as supportsInlineImages,pi as useApp,Fs as useDialog,ui as useFocus,yi as useFocusRegistry,fi as useFocusable,ot as useInput,Me as useLayout,gs as useToast};//# sourceMappingURL=index.js.map
|
|
19
19
|
//# sourceMappingURL=index.js.map
|