@nick-skriabin/glyph 0.1.48 → 0.1.49
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 +32 -0
- package/dist/index.d.ts +37 -1
- package/dist/index.js +14 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,6 +120,37 @@ Styled text content. Supports wrapping, alignment, bold, dim, italic, underline.
|
|
|
120
120
|
</Text>
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
+
**ANSI Escape Codes:** Text automatically parses and renders embedded ANSI escape codes, making it easy to display colorized output from CLI tools, libraries like `chalk`/`picocolors`, or your own styled strings:
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
// Using ANSI codes directly
|
|
127
|
+
const coloredText = "\x1b[32mGreen\x1b[0m and \x1b[1;31mBold Red\x1b[0m";
|
|
128
|
+
<Text>{coloredText}</Text>
|
|
129
|
+
|
|
130
|
+
// Works with chalk, picocolors, etc.
|
|
131
|
+
import chalk from "chalk";
|
|
132
|
+
<Text>{chalk.blue("Blue") + " " + chalk.bold.red("Bold Red")}</Text>
|
|
133
|
+
|
|
134
|
+
// Display CLI output with preserved colors
|
|
135
|
+
const gitOutput = execSync("git status --short", { encoding: "utf8" });
|
|
136
|
+
<Text>{gitOutput}</Text>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Supports: basic colors (30-37, 40-47), bright colors (90-97, 100-107), 256-color palette (`\x1b[38;5;Nm`), true color RGB (`\x1b[38;2;R;G;Bm`), and attributes (bold, dim, italic, underline).
|
|
140
|
+
|
|
141
|
+
**Utility functions** for working with ANSI strings:
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
import { parseAnsi, stripAnsi } from "@nick-skriabin/glyph";
|
|
145
|
+
|
|
146
|
+
// Parse ANSI into styled segments
|
|
147
|
+
const segments = parseAnsi("\x1b[31mRed\x1b[0m Normal");
|
|
148
|
+
// [{ text: "Red", style: { fg: "red" } }, { text: " Normal", style: {} }]
|
|
149
|
+
|
|
150
|
+
// Strip all ANSI codes (useful for width calculations)
|
|
151
|
+
stripAnsi("\x1b[32mHello\x1b[0m"); // "Hello"
|
|
152
|
+
```
|
|
153
|
+
|
|
123
154
|
### `<Input>`
|
|
124
155
|
|
|
125
156
|
Text input field with cursor and placeholder support.
|
|
@@ -731,6 +762,7 @@ Interactive examples are included in the repo. Each demonstrates different compo
|
|
|
731
762
|
| **masked-input** | Input masks (phone, credit card, SSN) | [View →](https://github.com/nick-skriabin/glyph/tree/main/examples/masked-input) |
|
|
732
763
|
| **dialog-demo** | Alert and Confirm dialogs | [View →](https://github.com/nick-skriabin/glyph/tree/main/examples/dialog-demo) |
|
|
733
764
|
| **jump-nav** | Quick navigation with keyboard hints | [View →](https://github.com/nick-skriabin/glyph/tree/main/examples/jump-nav) |
|
|
765
|
+
| **ansi-text** | ANSI escape codes and colored output | [View →](https://github.com/nick-skriabin/glyph/tree/main/examples/ansi-text) |
|
|
734
766
|
| **showcase** | Progress bars, Spinners, Toasts | [View →](https://github.com/nick-skriabin/glyph/tree/main/examples/showcase) |
|
|
735
767
|
| **dashboard** | Full task manager (all components) | [View →](https://github.com/nick-skriabin/glyph/tree/main/examples/dashboard) |
|
|
736
768
|
|
package/dist/index.d.ts
CHANGED
|
@@ -689,4 +689,40 @@ declare const masks: {
|
|
|
689
689
|
mac: (newValue: string, oldValue: string) => string | false | void;
|
|
690
690
|
};
|
|
691
691
|
|
|
692
|
-
|
|
692
|
+
/**
|
|
693
|
+
* ANSI escape code parser for text with embedded formatting.
|
|
694
|
+
*
|
|
695
|
+
* Parses strings containing ANSI SGR (Select Graphic Rendition) codes
|
|
696
|
+
* and returns an array of styled segments.
|
|
697
|
+
*/
|
|
698
|
+
|
|
699
|
+
interface AnsiStyle {
|
|
700
|
+
fg?: Color;
|
|
701
|
+
bg?: Color;
|
|
702
|
+
bold?: boolean;
|
|
703
|
+
dim?: boolean;
|
|
704
|
+
italic?: boolean;
|
|
705
|
+
underline?: boolean;
|
|
706
|
+
}
|
|
707
|
+
interface StyledSegment {
|
|
708
|
+
text: string;
|
|
709
|
+
style: AnsiStyle;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Parse a string with ANSI escape codes into styled segments.
|
|
713
|
+
*
|
|
714
|
+
* Handles:
|
|
715
|
+
* - SGR codes: \x1b[<params>m (colors, bold, italic, etc.)
|
|
716
|
+
* - Resets escape sequences to plain text
|
|
717
|
+
*
|
|
718
|
+
* @param input String potentially containing ANSI escape codes
|
|
719
|
+
* @returns Array of segments with text and associated style
|
|
720
|
+
*/
|
|
721
|
+
declare function parseAnsi(input: string): StyledSegment[];
|
|
722
|
+
/**
|
|
723
|
+
* Strip all ANSI escape codes from a string.
|
|
724
|
+
* Useful for measuring visible width.
|
|
725
|
+
*/
|
|
726
|
+
declare function stripAnsi(input: string): string;
|
|
727
|
+
|
|
728
|
+
export { type AlertOptions, type AnsiStyle, type AppHandle, type BorderStyle, Box, type BoxProps, Button, type ButtonProps, Checkbox, type CheckboxProps, type Color, type ConfirmOptions, type DialogContextValue, DialogHost, type DialogHostProps, type DimensionValue, type FocusRegistryValue, FocusScope, type FocusScopeProps, type FocusableElement, type HexColor, Input, type InputProps, type InputType, JumpNav, type JumpNavProps, type Key, Keybind, type KeybindProps, type LayoutRect, List, type ListItemInfo, type ListProps, type MaskOptions, Menu, type MenuItem, type MenuProps, type NamedColor, Portal, type PortalProps, Progress, type ProgressProps, type RGBColor, Radio, type RadioItem, type RadioProps, type RenderOptions, ScrollView, type ScrollViewProps, Select, type SelectItem, type SelectProps, Spacer, type SpacerProps, Spinner, type SpinnerProps, type Style, type StyledSegment, Text, type TextAlign, type TextProps, type Toast, ToastHost, type ToastHostProps, type ToastPosition, type ToastVariant, type UseFocusableOptions, type UseFocusableResult, type WrapMode, createMask, masks, parseAnsi, render, stripAnsi, useApp, useDialog, useFocus, useFocusRegistry, useFocusable, useInput, useLayout, useToast };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import te,{createContext,forwardRef,useState,useContext,useRef,useEffect,useLayoutEffect,useMemo,useCallback}from'react';import An from'react-reconciler';import ue from'string-width';import nn,{FlexDirection,Justify,Align,Direction,Edge,Wrap,Gutter,PositionType,Overflow,MeasureMode}from'yoga-layout';var Hn=0;function Bt(){return `glyph-focus-${Hn++}`}function Lt(e,t){let n=t.style??{};return {type:e,props:t,style:n,children:[],rawTextChildren:[],parent:null,yogaNode:null,text:null,layout:{x:0,y:0,width:0,height:0,innerX:0,innerY:0,innerWidth:0,innerHeight:0},focusId:e==="input"||t.focusable?Bt():null,hidden:false}}function st(e,t){t.parent=e,e.children.push(t);}function Mt(e,t){let n=e.children.indexOf(t);n!==-1&&(e.children.splice(n,1),t.parent=null);}function Vt(e,t,n){t.parent=e;let r=e.children.indexOf(n);r!==-1?e.children.splice(r,0,t):e.children.push(t);}function _e(e){let t={},n=e;for(;n;){let r=n.style;t.color===void 0&&r.color!==void 0&&(t.color=r.color),t.bg===void 0&&r.bg!==void 0&&(t.bg=r.bg),t.bold===void 0&&r.bold!==void 0&&(t.bold=r.bold),t.dim===void 0&&r.dim!==void 0&&(t.dim=r.dim),t.italic===void 0&&r.italic!==void 0&&(t.italic=r.italic),t.underline===void 0&&r.underline!==void 0&&(t.underline=r.underline),n=n.parent;}return t}function it(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=it(n);return t}var lt=32,Ht={supportsMutation:true,supportsPersistence:false,supportsHydration:false,isPrimaryRenderer:true,scheduleTimeout:setTimeout,cancelTimeout:clearTimeout,noTimeout:-1,supportsMicrotasks:true,scheduleMicrotask:queueMicrotask,getCurrentUpdatePriority:()=>lt,setCurrentUpdatePriority:e=>{},resolveUpdatePriority:()=>lt,getCurrentEventPriority:()=>lt,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 Lt(e,t)},createTextInstance(e,t,n,r){return {type:"raw-text",text:e,parent:null}},appendInitialChild(e,t){if(t.type==="raw-text"){let n=t;n.parent=e,e.rawTextChildren.push(n),e.text=e.rawTextChildren.map(r=>r.text).join("");}else st(e,t);},finalizeInitialChildren(e,t,n,r,o){return false},shouldSetTextContent(e,t){return false},getRootHostContext(e){return {}},getChildHostContext(e,t,n){return e},getPublicInstance(e){return e},prepareForCommit(e){return null},resetAfterCommit(e){e.onCommit();},preparePortalMount(){},appendChild(e,t){if(t.type==="raw-text"){let n=t;n.parent=e,e.rawTextChildren.push(n),e.text=e.rawTextChildren.map(r=>r.text).join("");}else st(e,t);},appendChildToContainer(e,t){if(t.type==="raw-text")return;let n=t;n.parent=null,e.children.push(n);},insertBefore(e,t,n){t.type==="raw-text"||n.type==="raw-text"||Vt(e,t,n);},insertInContainerBefore(e,t,n){if(t.type==="raw-text"||n.type==="raw-text")return;let r=t,o=n,s=e.children.indexOf(o);s!==-1?e.children.splice(s,0,r):e.children.push(r);},removeChild(e,t){if(t.type==="raw-text"){let n=t;n.parent=null;let r=e.rawTextChildren.indexOf(n);r!==-1&&e.rawTextChildren.splice(r,1),e.text=e.rawTextChildren.map(o=>o.text).join("")||null;return}Mt(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 Ie=An(Ht);Ie.injectIntoDevTools({bundleType:process.env.NODE_ENV==="production"?0:1,version:"0.1.0",rendererPackageName:"glyph"});var $e=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 At(e){switch(e){case 9:return "tab";case 13:return "return";case 27:return "escape";case 32:return " ";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 jn(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 qe(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 jt(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=Dn(e,n);if(s){t.push(s.key),n=s.end;continue}}if(e[n+1]==="O"){let s=On(e,n);if(s){t.push(s.key),n=s.end;continue}}if(n+1<e.length&&e.charCodeAt(n+1)>=32){t.push({name:e[n+1].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,sequence:r}),n++;}return t}function On(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 Dn(e,t){let n=t+2,r="";for(;n<e.length;){let c=e.charCodeAt(n);if(c>=48&&c<=63)r+=e[n],n++;else break}if(n>=e.length)return null;let o=e[n],s=e.substring(t,n+1);n++;let i;switch(o){case "A":i={name:"up",sequence:s};break;case "B":i={name:"down",sequence:s};break;case "C":i={name:"right",sequence:s};break;case "D":i={name:"left",sequence:s};break;case "H":i={name:"home",sequence:s};break;case "F":i={name:"end",sequence:s};break;case "Z":i={name:"tab",sequence:s,shift:true};break;case "P":i={name:"f1",sequence:s};break;case "Q":i={name:"f2",sequence:s};break;case "R":i={name:"f3",sequence:s};break;case "S":i={name:"f4",sequence:s};break;case "~":{if(r.startsWith("27;")){let c=r.split(";"),l=parseInt(c[1]??"1",10),u=parseInt(c[2]??"0",10);i={name:At(u),sequence:s},qe(i,l);break}if(i={name:jn(r),sequence:s},r.includes(";")){let c=r.split(";"),l=parseInt(c[1]??"1",10);qe(i,l);}break}case "u":{let c=r.split(";"),l=parseInt(c[0]??"0",10),u=parseInt(c[1]??"1",10);i={name:At(l),sequence:s},qe(i,u);break}case "I":i={name:"focus",sequence:s};break;case "O":i={name:"blur",sequence:s};break;default:i={name:"unknown",sequence:s};}if(r.includes(";")&&!["~","u"].includes(o)){let c=r.split(";"),l=parseInt(c[c.length-1]??"1",10);l>=1&&l<=16&&qe(i,l);}return {key:i,end:n}}var Kn={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"},Wn={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 ct(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 Ot(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=ct(e);return `\x1B[38;2;${o};${s};${i}m`}return Kn[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 Dt(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=ct(e);return `\x1B[48;2;${o};${s};${i}m`}return Wn[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 Kt={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]},Wt=["black","red","green","yellow","blue","magenta","cyan","white","blackBright","redBright","greenBright","yellowBright","blueBright","magentaBright","cyanBright","whiteBright"],Te=null;function _t(e){e.size>0&&(Te=e);}function _n(e){if(Te){let t=Wt.indexOf(e);if(t!==-1){let n=Te.get(t);if(n)return n}}return Kt[e]??null}function $n(e){if(typeof e=="string"){if(e.startsWith("#")){let t=ct(e);return [t.r,t.g,t.b]}return _n(e)}if(typeof e=="number"){if(e<16){if(Te){let s=Te.get(e);if(s)return s}return Kt[Wt[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 ze(e){let t=$n(e);if(!t)return false;let[n,r,o]=t.map(i=>{let c=i/255;return c<=.03928?c/12.92:Math.pow((c+.055)/1.055,2.4)});return .2126*n+.7152*r+.0722*o>.4}function ut(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 $t(e){return e&&ze(e)?"black":"white"}var ke=class e{width;height;cells;constructor(t,n){this.width=t,this.height=n,this.cells=new Array(t*n),this.clear();}clear(){for(let t=0;t<this.cells.length;t++)this.cells[t]={ch:" "};}resize(t,n){this.width=t,this.height=n,this.cells=new Array(t*n),this.clear();}get(t,n){if(!(t<0||t>=this.width||n<0||n>=this.height))return this.cells[n*this.width+t]}set(t,n,r){t<0||t>=this.width||n<0||n>=this.height||(this.cells[n*this.width+t]=r);}setChar(t,n,r,o,s,i,c,l,u){t<0||t>=this.width||n<0||n>=this.height||(this.cells[n*this.width+t]={ch:r,fg:o,bg:s,bold:i,dim:c,italic:l,underline:u});}fillRect(t,n,r,o,s,i,c){for(let l=n;l<n+o;l++)for(let u=t;u<t+r;u++)this.setChar(u,l,s,i,c);}clone(){let t=new e(this.width,this.height);for(let n=0;n<this.cells.length;n++){let r=this.cells[n];t.cells[n]={...r};}return t}cellsEqual(t,n){return t.ch===n.ch&&ut(t.fg,n.fg)&&ut(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 qn={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 qt(e){return e==="none"?null:qn[e]}function zt(e,t,n,r){if(e.length===0)return {width:0,height:0};let o=e.split(`
|
|
2
|
-
`);if(n===MeasureMode.Undefined||r==="none"){let l=0;for(let
|
|
3
|
-
`),R=
|
|
4
|
-
`),
|
|
5
|
-
`),o=[],s=0;for(let l of r){let
|
|
6
|
-
`),s=[],i=0;for(let f of o){let
|
|
7
|
-
`),r=t;for(let s=0;s<n.length;s++){if(r<=n[s].length)return {line:s,col:r,lines:n};r-=n[s].length+1;}let o=n.length-1;return {line:o,col:n[o].length,lines:n}}function
|
|
8
|
-
`+w.slice(
|
|
9
|
-
`);)d--;let
|
|
10
|
-
`;)d--;return
|
|
11
|
-
`;)d++;for(;d<w.length&&w[d]===" ";)d++;return
|
|
12
|
-
`;)d--;let
|
|
13
|
-
`;)d++;for(;d<w.length&&w[d]===" ";)d++;let
|
|
14
|
-
`)))))}function Ct({count:e,renderItem:t,selectedIndex:n,onSelectionChange:r,onSelect:o,defaultSelectedIndex:s=0,disabledIndices:i,style:c,focusable:l=true}){let u=n!==void 0,[f,m]=useState(s),S=u?n:f,R=useContext(q),v=useContext(Z),a=useRef(null),p=useRef(null),h=useRef(o);h.current=o;let[I,P]=useState(false),[j,K]=useState(false),E=useRef(null),G=useCallback(y=>{let C=Math.max(0,Math.min(y,e-1));u?r?.(C):m(C);},[u,r,e]),T=useCallback((y,C)=>{if(!i||i.size===0)return Math.max(0,Math.min(y+C,e-1));let x=y+C;for(;x>=0&&x<e&&i.has(x);)x+=C;return x<0||x>=e?y:x},[i,e]);useEffect(()=>{if(!(!R||!p.current||!a.current||!l))return R.register(p.current,a.current)},[R,l,I]),useEffect(()=>{if(!R||!p.current)return;let y=p.current;return K(R.focusedId===y),R.onFocusChange(C=>{K(C===y);})},[R,I]);let M=useCallback(y=>{let C=y?e-1:0,x=y?-1:1,V=C;for(;V>=0&&V<e&&i?.has(V);)V+=x;return V>=0&&V<e?V:y?e-1:0},[i,e]);useEffect(()=>{if(!v||!p.current||!l)return;let y=p.current,C=x=>R?.focusedId!==y?false:x.name==="g"&&!x.ctrl&&!x.alt?E.current==="g"?(G(M(false)),E.current=null,true):(E.current="g",true):x.name==="G"||x.name==="g"&&x.shift?(E.current=null,G(M(true)),true):(E.current=null,x.name==="up"||x.name==="k"?(G(T(S,-1)),true):x.name==="down"||x.name==="j"?(G(T(S,1)),true):x.name==="return"?(i?.has(S)||h.current?.(S),true):false);return v.registerInputHandler(y,C)},[v,R,l,S,G,T,M,i,I]);let b=[];for(let y=0;y<e;y++)b.push(te.createElement(te.Fragment,{key:y},t({index:y,selected:y===S,focused:j})));return te.createElement("box",{style:{flexDirection:"column",...c},focusable:l,ref:y=>{y?(a.current=y,p.current=y.focusId,P(true)):(a.current=null,p.current=null,P(false));}},...b)}function jr({items:e,selectedIndex:t,onSelectionChange:n,onSelect:r,defaultSelectedIndex:o=0,style:s,highlightColor:i="cyan",focusable:c=true}){let l=new Set;for(let f=0;f<e.length;f++)e[f].disabled&&l.add(f);let u=f=>{let m=e[f];m&&!m.disabled&&r?.(m.value,f);};return te.createElement(Ct,{count:e.length,selectedIndex:t,onSelectionChange:n,onSelect:u,defaultSelectedIndex:o,disabledIndices:l.size>0?l:void 0,style:s,focusable:c,renderItem:({index:f,selected:m,focused:S})=>{let R=e[f],v=R.disabled,a=m&&S,p=m?">":" ";return te.createElement("box",{style:{flexDirection:"row",...a?{bg:i}:{}}},te.createElement("text",{style:a?{bold:true,color:"black"}:v?{dim:true}:{}},`${p} ${R.label}`))}})}function Wr({value:e,indeterminate:t=false,width:n="100%",label:r,showPercent:o=false,style:s,filled:i="\u2588",empty:c="\u2591"}){let l=useRef(null),f=de(l).innerWidth,[m,S]=useState(0);useEffect(()=>{if(!t)return;let h=setInterval(()=>{S(I=>(I+1)%Math.max(1,f+6));},100);return ()=>clearInterval(h)},[t,f]);let R=Math.max(0,Math.min(1,e??0)),v=o?` ${Math.round(R*100)}%`:"",a="";if(f>0)if(t&&e===void 0){let h=Math.max(1,Math.min(3,Math.floor(f/4))),I=[];for(let P=0;P<f;P++)P>=m-h&&P<m?I.push(i):I.push(c);a=I.join("");}else {let h=Math.round(R*f);a=i.repeat(h)+c.repeat(f-h);}let p=[];return r&&p.push(te.createElement("text",{key:"label",style:{bold:true}},r+" ")),p.push(te.createElement("box",{key:"track",style:{flexGrow:1,flexShrink:1},ref:h=>{l.current=h??null;}},te.createElement("text",{key:"bar",style:{}},a))),o&&p.push(te.createElement("text",{key:"pct",style:{bold:true}},v)),te.createElement("box",{style:{flexDirection:"row",width:n,...s}},...p)}var qr=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function zr({frames:e=qr,intervalMs:t=80,label:n,style:r}){let[o,s]=useState(0);useEffect(()=>{let c=setInterval(()=>{s(l=>(l+1)%e.length);},t);return ()=>clearInterval(c)},[e.length,t]);let i=[te.createElement("text",{key:"frame",style:r},e[o])];return n&&i.push(te.createElement("text",{key:"label",style:{}}," "+n)),te.createElement("box",{style:{flexDirection:"row"}},...i)}var Rn=createContext(null),Qr=0;function eo(){let e=useContext(Rn);if(!e)throw new Error("useToast must be used within a <ToastHost>");return e.push}var to={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 no({position:e="bottom-right",maxVisible:t=5,children:n}){let[r,o]=useState([]),s=useRef(new Map),i=useCallback(R=>{let v=`toast-${Qr++}`,a={id:v,durationMs:3e3,variant:"info",...R};if(o(p=>[...p,a]),a.durationMs&&a.durationMs>0){let p=setTimeout(()=>{s.current.delete(v),o(h=>h.filter(I=>I.id!==v));},a.durationMs);s.current.set(v,p);}},[]);useEffect(()=>()=>{for(let R of s.current.values())clearTimeout(R);s.current.clear();},[]);let c=useRef({push:i});c.current.push=i;let l=e.startsWith("top"),u=e.endsWith("right"),f={position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:900,flexDirection:"column",justifyContent:l?"flex-start":"flex-end",alignItems:u?"flex-end":"flex-start",padding:1},S=r.slice(-t).map(R=>{let v=R.variant??"info",a=to[v],p=[];return R.title&&p.push(te.createElement("text",{key:"title",style:{bold:true,color:a.title}},R.title)),p.push(te.createElement("text",{key:"msg",style:{color:a.text}},R.message)),te.createElement("box",{key:R.id,style:{bg:a.bg,paddingX:1,flexDirection:"column",minWidth:20,maxWidth:50}},...p)});return te.createElement(Rn.Provider,{value:c.current},n,S.length>0?te.createElement("box",{style:f},...S):null)}function oo({items:e,value:t,onChange:n,placeholder:r="Select...",style:o,focusedStyle:s,dropdownStyle:i,highlightColor:c="cyan",maxVisible:l=8,searchable:u=true,disabled:f}){let m=useContext(q),S=useContext(Z),R=useContext(Ce),v=useContext(Ye),a=useRef(null),p=useRef(null),h=useRef(n);h.current=n;let[I,P]=useState(false),[j,K]=useState(false),[E,G]=useState(false),[T,M]=useState(0),[b,y]=useState(""),[C,x]=useState(0),V=de(a),z=R?.rows??24,O=v?.getBounds(),Y=e.find(F=>F.value===t)?.label??"",X=useMemo(()=>{if(!b)return e;let F=b.toLowerCase();return e.filter($=>$.label.toLowerCase().includes(F))},[e,b]),_=Math.min(l,X.length),J=X.slice(C,C+_);useEffect(()=>{M(0),x(0);},[b]),useEffect(()=>{!j&&E&&(G(false),y(""));},[j,E]),useEffect(()=>{if(!(!m||!p.current||!a.current))return m.register(p.current,a.current)},[m,I]),useEffect(()=>{!m||!p.current||m.setSkippable(p.current,!!f);},[m,f,I]),useEffect(()=>{if(!m||!p.current)return;let F=p.current;return K(m.focusedId===F),m.onFocusChange($=>{K($===F);})},[m,I]);let B=useCallback((F,$)=>{let D=F+$;for(;D>=0&&D<X.length;){if(!X[D].disabled)return D;D+=$;}return F},[X]),se=useCallback(F=>{F<C?x(F):F>=C+_&&x(F-_+1);},[C,_]);useEffect(()=>{if(!S||!p.current||f)return;let F=p.current,$=D=>{if(m?.focusedId!==F)return false;if(!E){if(D.name==="return"||D.name===" "||D.sequence===" "||D.name==="down"){G(true),y("");let d=X.findIndex(H=>H.value===t),A=d>=0?d:0;return M(A),x(Math.max(0,A-Math.floor(l/2))),true}return false}if(D.name==="tab")return G(false),y(""),false;if(D.name==="escape")return G(false),y(""),true;if(D.name==="return"){let d=X[T];return d&&!d.disabled&&(h.current?.(d.value),G(false),y("")),true}if(D.name==="up"){let d=B(T,-1);return M(d),se(d),true}if(D.name==="down"){let d=B(T,1);return M(d),se(d),true}if(D.name==="backspace")return u&&b.length>0&&y(d=>d.slice(0,-1)),true;if(D.name==="home"){let d=B(-1,1);return M(d),se(d),true}if(D.name==="end"){let d=B(X.length,-1);return M(d),se(d),true}if(u&&D.sequence&&D.sequence.length===1&&!D.ctrl&&!D.alt){let d=D.sequence;if(d>=" "&&d<="~")return y(A=>A+d),true}return true};return S.registerInputHandler(F,$)},[S,m,f,E,T,X,t,l,u,b,B,se,I]);let g={flexDirection:"row",width:"100%",...!o?.bg&&o?.border===void 0?{border:"single"}:{},...o,...j&&s?s:{}},L=Y?o?.color??void 0:"blackBright",N=[te.createElement("text",{key:"label",style:{flexGrow:1,flexShrink:1,color:L,wrap:"ellipsis",...Y?{}:{dim:true}}},Y||r),te.createElement("text",{key:"arrow",style:{flexShrink:0,color:j?c:"blackBright"}},E?" \u25B2":" \u25BC")],w=null;if(E){let F=[];u&&b&&F.push(te.createElement("box",{key:"search",style:{paddingX:1}},te.createElement("text",{style:{color:"blackBright",dim:true}},`/${b}`))),X.length===0&&F.push(te.createElement("box",{key:"empty",style:{paddingX:1}},te.createElement("text",{style:{dim:true,color:"blackBright"}},"No matches"))),C>0&&F.push(te.createElement("box",{key:"scroll-up",style:{justifyContent:"center",alignItems:"center"}},te.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25B2"))),J.forEach((ve,ot)=>{let We=C+ot===T,xe=ve.disabled,Mn={paddingX:1,...We&&!xe?{bg:c}:{}},Vn={...We&&!xe?{color:"black",bold:true}:{},...xe?{dim:true,color:"blackBright"}:{}};F.push(te.createElement("box",{key:`item-${ve.value}`,style:Mn},te.createElement("text",{style:Vn},ve.label)));}),C+_<X.length&&F.push(te.createElement("box",{key:"scroll-down",style:{justifyContent:"center",alignItems:"center"}},te.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25BC")));let $=C>0,D=C+_<X.length,d=u&&b,A=X.length===0,H=!i?.bg&&i?.border===void 0,U=_+(H?2:0);$&&(U+=1),D&&(U+=1),d&&(U+=1),A&&(U+=1);let pe=V.y+V.height,ye,Re;O?(ye=O.visibleBottom-pe,Re=V.y-O.visibleTop):(ye=z-pe,Re=V.y);let De=ye<U&&Re>=U?-U:V.height||1;w=te.createElement("box",{style:{position:"absolute",top:De,left:0,right:0,zIndex:9999,...H?{border:"single"}:{},bg:"black",flexDirection:"column",...i}},...F);}let k={flexDirection:"column",width:g.width??"100%",minWidth:g.minWidth,maxWidth:g.maxWidth,flexGrow:g.flexGrow,flexShrink:g.flexShrink??1};return te.createElement("box",{style:k},te.createElement("box",{style:g,focusable:true,ref:F=>{F?(a.current=F,p.current=F.focusId,P(true)):(a.current=null,p.current=null,P(false));}},...N),w)}function so({checked:e,onChange:t,label:n,style:r,focusedStyle:o,disabled:s,checkedChar:i="\u2713",uncheckedChar:c=" "}){let l=useContext(q),u=useContext(Z),f=useRef(null),m=useRef(null),S=useRef(t);S.current=t;let R=useRef(e);R.current=e;let[v,a]=useState(false),[p,h]=useState(false);useEffect(()=>{if(!(!l||!m.current||!f.current||s))return l.register(m.current,f.current)},[l,s,v]),useEffect(()=>{if(!l||!m.current)return;let E=m.current;return h(l.focusedId===E),l.onFocusChange(G=>{h(G===E);})},[l,v]),useEffect(()=>{if(!u||!m.current||s)return;let E=m.current,G=T=>l?.focusedId!==E?false:T.name==="return"||T.name===" "||T.sequence===" "?(S.current(!R.current),true):false;return u.registerInputHandler(E,G)},[u,l,s,v]);let I={flexDirection:"row",gap:1,...r,...p&&o?o:{}},P=e?i:c,j={color:s?"blackBright":p?"white":r?.color},K={color:s?"blackBright":r?.color};return te.createElement("box",{style:I,focusable:!s,ref:E=>{E?(f.current=E,m.current=E.focusId,a(true)):(f.current=null,m.current=null,a(false));}},te.createElement("text",{key:"box",style:j},`[${P}]`),n?te.createElement("text",{key:"label",style:K},n):null)}function lo({items:e,value:t,onChange:n,style:r,itemStyle:o,focusedItemStyle:s,selectedItemStyle:i,disabled:c,direction:l="column",gap:u=0,selectedChar:f="\u25CF",unselectedChar:m="\u25CB"}){let S=useContext(q),R=useContext(Z),v=useRef(null),a=useRef(null),p=useRef(n);p.current=n;let[h,I]=useState(false),[P,j]=useState(false),[K,E]=useState(()=>{let b=e.findIndex(y=>y.value===t);return b>=0?b:e.findIndex(y=>!y.disabled)}),G=useCallback((b,y)=>{let C=b;for(let x=0;x<e.length;x++)if(C=(C+y+e.length)%e.length,!e[C]?.disabled)return C;return b},[e]);useEffect(()=>{if(!(!S||!a.current||!v.current||c))return S.register(a.current,v.current)},[S,c,h]),useEffect(()=>{if(!S||!a.current)return;let b=a.current;return j(S.focusedId===b),S.onFocusChange(y=>{j(y===b);})},[S,h]),useEffect(()=>{if(!R||!a.current||c)return;let b=a.current,y=C=>{if(S?.focusedId!==b)return false;if(C.name==="up"||C.name==="left"||C.name==="k"||C.name==="tab"&&C.shift)return E(x=>G(x,-1)),true;if(C.name==="down"||C.name==="right"||C.name==="j"||C.name==="tab"&&!C.shift)return E(x=>G(x,1)),true;if(C.name==="return"||C.name===" "||C.sequence===" "){let x=e[K];return x&&!x.disabled&&p.current(x.value),true}return false};return R.registerInputHandler(b,y)},[R,S,c,e,K,G,h]),useEffect(()=>{let b=e.findIndex(y=>y.value===t);b>=0&&E(b);},[t,e]);let T={flexDirection:l,gap:u,...r},M=e.map((b,y)=>{let C=b.value===t,x=y===K,V=c||b.disabled,z=C?f:m,O={flexDirection:"row",gap:1,...o};C&&i&&(O={...O,...i}),P&&x&&s&&(O={...O,...s});let W=V?"blackBright":P&&x?s?.color??"white":C?i?.color??o?.color:o?.color;return te.createElement("box",{key:y,style:O},te.createElement("text",{key:"radio",style:{color:W}},`(${z})`),te.createElement("text",{key:"label",style:{color:W}},b.label))});return te.createElement("box",{style:T,focusable:!c,ref:b=>{b?(v.current=b,a.current=b.focusId,I(true)):(v.current=null,a.current=null,I(false));}},...M)}var En=createContext(null);function uo(){let e=useContext(En);if(!e)throw new Error("useDialog must be used within a DialogHost");return e}function ao({children:e}){let[t,n]=useState([]),r=useRef(0),o=useCallback((u,f)=>new Promise(m=>{let S=++r.current;n(R=>[...R,{id:S,type:"alert",content:u,okText:f?.okText??"OK",cancelText:"",style:f?.style,buttonStyle:f?.buttonStyle,okButtonStyle:f?.okButtonStyle,focusedButtonStyle:f?.focusedButtonStyle,backdropStyle:f?.backdropStyle,resolve:()=>m()}]);}),[]),s=useCallback((u,f)=>new Promise(m=>{let S=++r.current;n(R=>[...R,{id:S,type:"confirm",content:u,okText:f?.okText??"OK",cancelText:f?.cancelText??"Cancel",style:f?.style,buttonStyle:f?.buttonStyle,okButtonStyle:f?.okButtonStyle,cancelButtonStyle:f?.cancelButtonStyle,focusedButtonStyle:f?.focusedButtonStyle,backdropStyle:f?.backdropStyle,resolve:m}]);}),[]),i=useCallback((u,f)=>{n(m=>{let S=m.find(R=>R.id===u);return S&&S.resolve(f),m.filter(R=>R.id!==u)});},[]),c={alert:o,confirm:s},l=t[t.length-1];return te.createElement(En.Provider,{value:c},e,l&&te.createElement(fo,{key:l.id,dialog:l,onDismiss:i}))}function fo({dialog:e,onDismiss:t}){let n=useContext(q),r=useRef(null),o=useRef(null),s=useRef(null),i=useRef(null),[c,l]=useState("ok"),[u,f]=useState(0);useEffect(()=>{if(!n||u===0)return;let h=[];return r.current&&s.current&&h.push(n.register(s.current,r.current)),o.current&&i.current&&h.push(n.register(i.current,o.current)),s.current&&n.requestFocus(s.current),()=>h.forEach(I=>I())},[n,u]),useEffect(()=>{if(n)return n.onFocusChange(h=>{h===s.current?l("ok"):h===i.current&&l("cancel");})},[n]),Le(h=>{if(h.name==="return"||h.name==="space"){e.type==="alert"?t(e.id,true):t(e.id,c==="ok");return}if(h.name==="escape"){t(e.id,false);return}e.type==="confirm"&&n&&(h.name==="left"||h.name==="right")&&(c==="ok"&&i.current?n.requestFocus(i.current):s.current&&n.requestFocus(s.current));},[e,c,n,t]);let m=typeof e.content=="string",S=m?e.content.length:0,v={minWidth:Math.max(20,m?Math.min(S+6,50):30),maxWidth:50,bg:"black",border:"round",borderColor:"white",padding:1,flexDirection:"column",gap:1,...e.style},a=(h,I)=>{let P={paddingX:2,bg:"blackBright",color:"white"},j={bg:"white",color:"black",bold:true},K=h==="ok"?e.okButtonStyle:e.cancelButtonStyle;return {...P,...e.buttonStyle,...K,...I?{...j,...e.focusedButtonStyle}:{}}},p={position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:999,...e.backdropStyle};return te.createElement(ft,{trap:true},te.createElement("box",{style:p}),te.createElement("box",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,justifyContent:"center",alignItems:"center",zIndex:1e3}},te.createElement("box",{style:v},te.createElement("box",{style:{flexDirection:"column"}},typeof e.content=="string"?te.createElement("text",null,e.content):e.content),te.createElement("box",{style:{flexDirection:"row",justifyContent:"flex-end",gap:1}},e.type==="confirm"&&te.createElement("box",{style:a("cancel",c==="cancel"),focusable:true,ref:h=>{h&&h.focusId&&!i.current&&(o.current=h,i.current=h.focusId,f(I=>I+1));}},te.createElement("text",null,e.cancelText)),te.createElement("box",{style:a("ok",c==="ok"),focusable:true,ref:h=>{h&&h.focusId&&!s.current&&(r.current=h,s.current=h.focusId,f(I=>I+1));}},te.createElement("text",null,e.okText))))))}function ho(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 go({children:e,activationKey:t="ctrl+o",hintStyle:n,hintBg:r="yellow",hintFg:o="black",hintChars:s="asdfghjklqwertyuiopzxcvbnm",enabled:i=true,debug:c=false}){let l=c?(...b)=>console.error("[JumpNav]",...b):()=>{},[u,f]=useState(false),[m,S]=useState(""),[R,v]=useState([]),a=useContext(Z),p=useContext(q),h=useContext(oe);useEffect(()=>{l("Mounted, inputCtx:",!!a,"focusCtx:",!!p,"enabled:",i);},[]);let P=useCallback(b=>{let y=b.toLowerCase().split("+");return {ctrl:y.includes("ctrl"),alt:y.includes("alt"),shift:y.includes("shift"),meta:y.includes("meta"),name:y[y.length-1]??""}},[])(t),j=useCallback(()=>{if(!p?.getActiveElements){l("refreshElements: no getActiveElements");return}let b=p.getActiveElements();l("getActiveElements returned",b.length,"elements");let y=b.map(({id:C,node:x})=>({id:C,node:x,layout:h?.getLayout(x)??x.layout}));y.sort((C,x)=>C.layout.y!==x.layout.y?C.layout.y-x.layout.y:C.layout.x-x.layout.x),v(y);},[p,h,l]),K=useRef(false);useEffect(()=>{u&&!K.current&&(l("Activated! Refreshing elements..."),j()),K.current=u;},[u,j,l]);let E=R.filter(b=>b.layout.width>0&&b.layout.height>0),G=ho(E.length,s),T=useMemo(()=>{let b=new Map;return E.forEach((y,C)=>{G[C]&&b.set(G[C],y.id);}),b},[E,G]);useEffect(()=>{if(!a||!i){l("Not subscribing - inputCtx:",!!a,"enabled:",i);return}l("Subscribing to priority input, activation key:",t);let b=y=>{let C=y.name===P.name,x=!!y.ctrl===P.ctrl,V=!!y.alt===P.alt,z=!!y.shift===P.shift,O=!!y.meta===P.meta;if(!u&&C&&x&&V&&z&&O)return l("Activation key matched! Activating..."),f(true),S(""),true;if(u){if(y.name==="escape")return l("Escape pressed, deactivating"),f(false),S(""),true;if(y.name==="backspace")return S(""),true;if(y.sequence&&y.sequence.length===1&&/[a-z]/i.test(y.sequence)){let W=m+y.sequence.toLowerCase();l("Buffer:",W);let Y=T.get(W);return Y?(l("Jumping to",Y),p?.requestFocus(Y),f(false),S(""),true):[...T.keys()].some(_=>_.startsWith(W))?(S(W),true):(S(""),true)}return true}return false};return a.subscribePriority(b)},[a,i,u,P,m,T,p,t,l]);let M=u?te.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:99998}},...E.map((b,y)=>{let C=G[y];if(!C)return null;let{x,y:V}=b.layout,z=C.startsWith(m)&&m.length>0;return te.createElement("box",{key:b.id,style:{position:"absolute",top:V,left:Math.max(0,x-C.length-2),bg:z?"cyan":r,color:o,paddingX:1,zIndex:99999,...n}},te.createElement("text",{style:{bold:true,color:o}},C))}),te.createElement("box",{style:{position:"absolute",bottom:0,left:0,right:0,bg:"blackBright",paddingX:1,zIndex:99999}},te.createElement("text",{style:{color:"white"}},m?`Jump: ${m}_`:"Press a key to jump \u2022 ESC to cancel"))):null;return te.createElement(te.Fragment,null,e,M)}function So(e){let t=useContext(q),[n]=useState(()=>`focus-${Math.random().toString(36).slice(2,9)}`),r=t?t.focusedId===n:false;useEffect(()=>{if(!(!t||!e?.current))return e.current.focusId=n,t.register(n,e.current)},[t,n,e]);let o=useMemo(()=>()=>{t?.requestFocus(n);},[t,n]);return {focused:r,focus:o}}function Ro(e={}){let{disabled:t,onFocus:n,onBlur:r,onKeyPress:o}=e,s=useContext(q),i=useContext(Z),c=useRef(null),l=useRef(null),[u,f]=useState(false),m=useRef(n),S=useRef(r),R=useRef(o);m.current=n,S.current=r,R.current=o;let v=useCallback(p=>{c.current=p,p?l.current=p.focusId??null:l.current=null;},[]);useEffect(()=>{if(!(!s||!l.current||!c.current))return s.register(l.current,c.current)},[s]),useEffect(()=>{!s||!l.current||s.setSkippable(l.current,!!t);},[s,t]),useEffect(()=>{if(!s||!l.current)return;let p=l.current,h=s.focusedId===p;return f(h),s.onFocusChange(I=>{let P=I===p;f(j=>(P&&!j?m.current?.():!P&&j&&S.current?.(),P));})},[s]),useEffect(()=>{if(!i||!l.current||t)return;let p=l.current,h=I=>s?.focusedId!==p?false:R.current?.(I)===true;return i.registerInputHandler(p,h)},[i,s,t]);let a=useCallback(()=>{s&&l.current&&s.requestFocus(l.current);},[s]);return {ref:v,isFocused:u,focus:a,focusId:l.current}}function Io(){let e=useContext(Ce);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 Eo(){let e=useContext(q),t=useContext(oe),[n,r]=useState([]),o=useRef(()=>{}),s=useCallback(()=>{if(!e)return;let c=(e.getActiveElements?.()??e.getRegisteredElements?.()??[]).map(({id:l,node:u})=>({id:l,node:u,layout:t?.getLayout(u)??u.layout,type:u.type}));c.sort((l,u)=>l.layout.y!==u.layout.y?l.layout.y-u.layout.y:l.layout.x-u.layout.x),r(c);},[e,t]);return o.current=s,useEffect(()=>{if(!e)return;s();let i=e.onFocusChange(()=>{s();}),c=setTimeout(s,50);return ()=>{i(),clearTimeout(c);}},[e,t,s]),e?{elements:n,focusedId:e.focusedId,requestFocus:e.requestFocus,focusNext:e.focusNext,focusPrev:e.focusPrev,refresh:()=>o.current()}:null}function Fo(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 Go(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 ne(e){let t=typeof e=="string"?{mask:e}:e,{mask:n,placeholder:r="_",showPlaceholder:o=false}=t,s=Fo(n);return (i,c)=>{let l=[];for(let m of i)(m!==r&&!/[\s\-\(\)\/\.\:]/.test(m)||/[a-zA-Z0-9]/.test(m))&&/[a-zA-Z0-9]/.test(m)&&l.push(m);let u="",f=0;for(let m of s)if(m.type==="literal")(f<l.length||o)&&(u+=m.char);else if(f<l.length){let S=l[f];if(Go(S,m.type))u+=S,f++;else {f++;continue}}else o&&(u+=r);return u}}var Bo={usPhone:ne("(999) 999-9999"),intlPhone:ne("+9 999 999 9999"),dateUS:ne("99/99/9999"),dateEU:ne("99/99/9999"),dateISO:ne("9999-99-99"),time:ne("99:99"),timeFull:ne("99:99:99"),creditCard:ne("9999 9999 9999 9999"),ssn:ne("999-99-9999"),zip:ne("99999"),zipPlus4:ne("99999-9999"),ipv4:ne("999.999.999.999"),mac:ne("**:**:**:**:**:**")};export{pr as Box,Pr as Button,so as Checkbox,ao as DialogHost,ft as FocusScope,xr as Input,go as JumpNav,Ir as Keybind,Ct as List,jr as Menu,kr as Portal,Wr as Progress,lo as Radio,Ar as ScrollView,oo as Select,Rr as Spacer,zr as Spinner,gr as Text,no as ToastHost,ne as createMask,Bo as masks,ar as render,Io as useApp,uo as useDialog,So as useFocus,Eo as useFocusRegistry,Ro as useFocusable,Le as useInput,de as useLayout,eo as useToast};//# sourceMappingURL=index.js.map
|
|
1
|
+
import te,{createContext,forwardRef,useState,useContext,useRef,useEffect,useLayoutEffect,useMemo,useCallback}from'react';import Kn from'react-reconciler';import ue from'string-width';import ln,{FlexDirection,Justify,Align,Direction,Edge,Wrap,Gutter,PositionType,Overflow,MeasureMode}from'yoga-layout';var Dn=0;function Mt(){return `glyph-focus-${Dn++}`}function At(e,t){let n=t.style??{};return {type:e,props:t,style:n,children:[],rawTextChildren:[],parent:null,yogaNode:null,text:null,layout:{x:0,y:0,width:0,height:0,innerX:0,innerY:0,innerWidth:0,innerHeight:0},focusId:e==="input"||t.focusable?Mt():null,hidden:false}}function st(e,t){t.parent=e,e.children.push(t);}function Vt(e,t){let n=e.children.indexOf(t);n!==-1&&(e.children.splice(n,1),t.parent=null);}function Ht(e,t,n){t.parent=e;let r=e.children.indexOf(n);r!==-1?e.children.splice(r,0,t):e.children.push(t);}function We(e){let t={},n=e;for(;n;){let r=n.style;t.color===void 0&&r.color!==void 0&&(t.color=r.color),t.bg===void 0&&r.bg!==void 0&&(t.bg=r.bg),t.bold===void 0&&r.bold!==void 0&&(t.bold=r.bold),t.dim===void 0&&r.dim!==void 0&&(t.dim=r.dim),t.italic===void 0&&r.italic!==void 0&&(t.italic=r.italic),t.underline===void 0&&r.underline!==void 0&&(t.underline=r.underline),n=n.parent;}return t}function it(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=it(n);return t}var lt=32,jt={supportsMutation:true,supportsPersistence:false,supportsHydration:false,isPrimaryRenderer:true,scheduleTimeout:setTimeout,cancelTimeout:clearTimeout,noTimeout:-1,supportsMicrotasks:true,scheduleMicrotask:queueMicrotask,getCurrentUpdatePriority:()=>lt,setCurrentUpdatePriority:e=>{},resolveUpdatePriority:()=>lt,getCurrentEventPriority:()=>lt,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 At(e,t)},createTextInstance(e,t,n,r){return {type:"raw-text",text:e,parent:null}},appendInitialChild(e,t){if(t.type==="raw-text"){let n=t;n.parent=e,e.rawTextChildren.push(n),e.text=e.rawTextChildren.map(r=>r.text).join("");}else st(e,t);},finalizeInitialChildren(e,t,n,r,o){return false},shouldSetTextContent(e,t){return false},getRootHostContext(e){return {}},getChildHostContext(e,t,n){return e},getPublicInstance(e){return e},prepareForCommit(e){return null},resetAfterCommit(e){e.onCommit();},preparePortalMount(){},appendChild(e,t){if(t.type==="raw-text"){let n=t;n.parent=e,e.rawTextChildren.push(n),e.text=e.rawTextChildren.map(r=>r.text).join("");}else st(e,t);},appendChildToContainer(e,t){if(t.type==="raw-text")return;let n=t;n.parent=null,e.children.push(n);},insertBefore(e,t,n){t.type==="raw-text"||n.type==="raw-text"||Ht(e,t,n);},insertInContainerBefore(e,t,n){if(t.type==="raw-text"||n.type==="raw-text")return;let r=t,o=n,s=e.children.indexOf(o);s!==-1?e.children.splice(s,0,r):e.children.push(r);},removeChild(e,t){if(t.type==="raw-text"){let n=t;n.parent=null;let r=e.rawTextChildren.indexOf(n);r!==-1&&e.rawTextChildren.splice(r,1),e.text=e.rawTextChildren.map(o=>o.text).join("")||null;return}Vt(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 ke=Kn(jt);ke.injectIntoDevTools({bundleType:process.env.NODE_ENV==="production"?0:1,version:"0.1.0",rendererPackageName:"glyph"});var _e=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 Ot(e){switch(e){case 9:return "tab";case 13:return "return";case 27:return "escape";case 32:return " ";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 $n(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 qe(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 Dt(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=_n(e,n);if(s){t.push(s.key),n=s.end;continue}}if(e[n+1]==="O"){let s=Wn(e,n);if(s){t.push(s.key),n=s.end;continue}}if(n+1<e.length&&e.charCodeAt(n+1)>=32){t.push({name:e[n+1].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,sequence:r}),n++;}return t}function Wn(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 _n(e,t){let n=t+2,r="";for(;n<e.length;){let c=e.charCodeAt(n);if(c>=48&&c<=63)r+=e[n],n++;else break}if(n>=e.length)return null;let o=e[n],s=e.substring(t,n+1);n++;let i;switch(o){case "A":i={name:"up",sequence:s};break;case "B":i={name:"down",sequence:s};break;case "C":i={name:"right",sequence:s};break;case "D":i={name:"left",sequence:s};break;case "H":i={name:"home",sequence:s};break;case "F":i={name:"end",sequence:s};break;case "Z":i={name:"tab",sequence:s,shift:true};break;case "P":i={name:"f1",sequence:s};break;case "Q":i={name:"f2",sequence:s};break;case "R":i={name:"f3",sequence:s};break;case "S":i={name:"f4",sequence:s};break;case "~":{if(r.startsWith("27;")){let c=r.split(";"),l=parseInt(c[1]??"1",10),a=parseInt(c[2]??"0",10);i={name:Ot(a),sequence:s},qe(i,l);break}if(i={name:$n(r),sequence:s},r.includes(";")){let c=r.split(";"),l=parseInt(c[1]??"1",10);qe(i,l);}break}case "u":{let c=r.split(";"),l=parseInt(c[0]??"0",10),a=parseInt(c[1]??"1",10);i={name:Ot(l),sequence:s},qe(i,a);break}case "I":i={name:"focus",sequence:s};break;case "O":i={name:"blur",sequence:s};break;default:i={name:"unknown",sequence:s};}if(r.includes(";")&&!["~","u"].includes(o)){let c=r.split(";"),l=parseInt(c[c.length-1]??"1",10);l>=1&&l<=16&&qe(i,l);}return {key:i,end:n}}var qn={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"},zn={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 ct(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 Kt(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=ct(e);return `\x1B[38;2;${o};${s};${i}m`}return qn[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 $t(e){if(typeof e=="string"){if(e.startsWith("#")){let{r:o,g:s,b:i}=ct(e);return `\x1B[48;2;${o};${s};${i}m`}return zn[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 Wt={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]},_t=["black","red","green","yellow","blue","magenta","cyan","white","blackBright","redBright","greenBright","yellowBright","blueBright","magentaBright","cyanBright","whiteBright"],Te=null;function qt(e){e.size>0&&(Te=e);}function Xn(e){if(Te){let t=_t.indexOf(e);if(t!==-1){let n=Te.get(t);if(n)return n}}return Wt[e]??null}function Jn(e){if(typeof e=="string"){if(e.startsWith("#")){let t=ct(e);return [t.r,t.g,t.b]}return Xn(e)}if(typeof e=="number"){if(e<16){if(Te){let s=Te.get(e);if(s)return s}return Wt[_t[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 ze(e){let t=Jn(e);if(!t)return false;let[n,r,o]=t.map(i=>{let c=i/255;return c<=.03928?c/12.92:Math.pow((c+.055)/1.055,2.4)});return .2126*n+.7152*r+.0722*o>.4}function ut(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 zt(e){return e&&ze(e)?"black":"white"}var Ne=class e{width;height;cells;constructor(t,n){this.width=t,this.height=n,this.cells=new Array(t*n),this.clear();}clear(){for(let t=0;t<this.cells.length;t++)this.cells[t]={ch:" "};}resize(t,n){this.width=t,this.height=n,this.cells=new Array(t*n),this.clear();}get(t,n){if(!(t<0||t>=this.width||n<0||n>=this.height))return this.cells[n*this.width+t]}set(t,n,r){t<0||t>=this.width||n<0||n>=this.height||(this.cells[n*this.width+t]=r);}setChar(t,n,r,o,s,i,c,l,a){t<0||t>=this.width||n<0||n>=this.height||(this.cells[n*this.width+t]={ch:r,fg:o,bg:s,bold:i,dim:c,italic:l,underline:a});}fillRect(t,n,r,o,s,i,c){for(let l=n;l<n+o;l++)for(let a=t;a<t+r;a++)this.setChar(a,l,s,i,c);}clone(){let t=new e(this.width,this.height);for(let n=0;n<this.cells.length;n++){let r=this.cells[n];t.cells[n]={...r};}return t}cellsEqual(t,n){return t.ch===n.ch&&ut(t.fg,n.fg)&&ut(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 Yn={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 Xt(e){return e==="none"?null:Yn[e]}function Jt(e,t,n,r){if(e.length===0)return {width:0,height:0};let o=e.split(`
|
|
2
|
+
`);if(n===MeasureMode.Undefined||r==="none"){let l=0;for(let a of o){let f=ue(a);f>l&&(l=f);}return {width:l,height:o.length}}let s=Math.max(1,Math.floor(t)),i=ie(o,s,r),c=0;for(let l of i){let a=ue(l);a>c&&(c=a);}return {width:c,height:i.length}}function ie(e,t,n){let r=[];for(let o of e){if(ue(o)<=t){r.push(o);continue}if(n==="truncate"){r.push(Yt(o,t));continue}if(n==="ellipsis"){r.push(Zn(o,t));continue}let i=Qn(o,t);r.push(...i);}return r}function Yt(e,t){let n="",r=0;for(let o of e){let s=ue(o);if(r+s>t)break;n+=o,r+=s;}return n}function Zn(e,t){if(t<=1)return t===1?"\u2026":"";let n=Yt(e,t-1);return ue(n)<ue(e)?n+"\u2026":e}function Qn(e,t){let n=[],r="",o=0,s="",i=0;for(let c=0;c<=e.length;c++){let l=e[c],a=c===e.length,f=l===" ";if(a||f){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 h of s){let S=ue(h);o+S>t&&r.length>0&&(n.push(r),r="",o=0),r+=h,o+=S;}s="",i=0;}f&&(o+1<=t?(r+=" ",o+=1):(r.length>0&&n.push(r),r=" ",o=1));}else l&&(s+=l,i+=ue(l));}return r.length>0&&n.push(r),n.length>0?n:[""]}var Ut={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"},Zt={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 er(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:Ut[r]?t.fg=Ut[r]:Zt[r]&&(t.bg=Zt[r]);break}n++;}}function at(e){let t=[],n={},r="",o=/\x1b\[([0-9;]*)m/g,s=0,i;for(;(i=o.exec(e))!==null;){let l=e.slice(s,i.index);l&&(r+=l),r&&(t.push({text:r,style:{...n}}),r="");let f=(i[1]||"0").split(";").map(h=>parseInt(h,10)||0);er(f,n),s=o.lastIndex;}let c=e.slice(s);return c&&(r+=c),r&&t.push({text:r,style:{...n}}),t}function ft(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function Qt(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||en(i,s,i.style.zIndex??0,o);o.sort((i,c)=>i.zIndex-c.zIndex);for(let i of o){let c=nr(i.node,t,i.clip,n);c?.cursorPosition&&(r.cursorPosition=c.cursorPosition);}return r}function en(e,t,n,r){if(e.hidden)return;let o=e.style.zIndex??n,s=e.style.clip?tr(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)en(i,s,o,r);}function tr(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 Xe(e,t,n){return e>=n.x&&e<n.x+n.width&&t>=n.y&&t<n.y+n.height}function nr(e,t,n,r={}){let{x:o,y:s,width:i,height:c,innerX:l,innerY:a,innerWidth:f,innerHeight:h}=e.layout,S=e.style;if(i<=0||c<=0)return;let I=We(e).bg;if(S.bg)for(let m=s;m<s+c;m++)for(let g=o;g<o+i;g++)Xe(g,m,n)&&t.setChar(g,m," ",void 0,S.bg);let u=S.border?Xt(S.border):null;if(u&&i>=2&&c>=2){let m=S.borderColor,g=I;le(t,n,o,s,u.topLeft,m,g);for(let v=o+1;v<o+i-1;v++)le(t,n,v,s,u.horizontal,m,g);le(t,n,o+i-1,s,u.topRight,m,g),le(t,n,o,s+c-1,u.bottomLeft,m,g);for(let v=o+1;v<o+i-1;v++)le(t,n,v,s+c-1,u.horizontal,m,g);le(t,n,o+i-1,s+c-1,u.bottomRight,m,g);for(let v=s+1;v<s+c-1;v++)le(t,n,o,v,u.vertical,m,g),le(t,n,o+i-1,v,u.vertical,m,g);}if(e.type==="text")rr(e,t,n);else if(e.type==="input")return or(e,t,n,r)}function le(e,t,n,r,o,s,i,c,l,a,f){Xe(n,r,t)&&e.setChar(n,r,o,s,i,c,l,a,f);}function tn(e,t){if(e!==void 0)return e;if(t!==void 0)return ze(t)?"black":"white"}function rr(e,t,n){let{innerX:r,innerY:o,innerWidth:s,innerHeight:i}=e.layout,c=We(e),l=it(e);if(!l)return;let a=tn(c.color,c.bg),f=e.style.wrap??"wrap",h=e.style.textAlign??"left",S=l.split(`
|
|
3
|
+
`),R=S.map(u=>ft(u)),I=ie(R,s,f);for(let u=0;u<I.length&&u<i;u++){let m=0,g=0;for(let p=0;p<R.length;p++){let G=ie([R[p]],s,f).length;if(u<g+G){m=p;break}g+=G;}let v=I[u],P=ue(v),H=0;h==="center"?H=Math.max(0,Math.floor((s-P)/2)):h==="right"&&(H=Math.max(0,s-P));let D=S[m],E=at(D),B=u-g,k=ie([R[m]],s,f),L=0;for(let p=0;p<B;p++)L+=k[p].length;let b=L+v.length,y=0,C=0;for(let p of E)for(let G of p.text){if(C>=L&&C<b){if(ue(G)>0){let O=p.style.fg??a,$=p.style.bg??c.bg,Y=p.style.bold??c.bold,q=p.style.dim??c.dim,W=p.style.italic??c.italic,X=p.style.underline??c.underline;le(t,n,r+H+y,o+u,G,O,$,Y,q,W,X);}y+=ue(G);}C++;}}}function or(e,t,n,r={}){let{cursorInfo:o,useNativeCursor:s}=r,{innerX:i,innerY:c,innerWidth:l,innerHeight:a}=e.layout;if(l<=0||a<=0)return;let f=e.props.value??e.props.defaultValue??"",h=e.props.placeholder??"",S=f||h,R=!f&&!!h,I=e.props.multiline??false,u=We(e),m=tn(u.color,u.bg),g=u.bg?ze(u.bg)?"blackBright":"whiteBright":"blackBright",v=R?g:m??u.color??e.style.color,P=R?g:v,H=R?true:u.dim,D=o&&o.nodeId===e.focusId,E;if(I&&!R){let B=e.style.wrap??"wrap",k=S.split(`
|
|
4
|
+
`),L=ie(k,l,B),b=0,y=0;if(D){let p=o.position,G=0,z=p,O=0;for(let X=0;X<k.length;X++){let M=k[X].length;if(p<=O+M){G=X,z=p-O;break}O+=M+1;}let $=0;for(let X=0;X<G;X++)$+=ie([k[X]],l,B).length;let Y=ie([k[G]],l,B),q=0,W=0;for(let X=0;X<Y.length;X++){let M=Y[X];if(z<=q+M.length){W=X;break}q+=M.length;}b=$+W,y=ue(k[G].slice(q,q+(z-q)));}let C=Math.max(0,b-a+1);for(let p=0;p<a;p++){let G=C+p;if(G>=L.length)break;let z=L[G],O=0;for(let $ of z){if(O>=l)break;let Y=ue($);Y>0&&le(t,n,i+O,c+p,$,P,u.bg,u.bold,H,u.italic,u.underline),O+=Y;}}if(D){let p=b-C;if(p>=0&&p<a){let G=Math.min(y,l-1),z=i+G,O=c+p;if(Xe(z,O,n)&&z<i+l)if(s)E={cursorPosition:{x:z,y:O,bg:u.bg}};else {let $=t.get(z,O),Y=$?.ch&&$.ch!==" "?$.ch:"\u258C",q=u.bg??"black",W=u.color??"white";t.setChar(z,O,Y,q,W,$?.bold,$?.dim,$?.italic,false);}}}}else {let B=0;for(let k of S){if(B>=l)break;let L=ue(k);L>0&&le(t,n,i+B,c,k,P,u.bg,u.bold,H,u.italic,u.underline),B+=L;}if(D){let k=Math.min(o.position,l-1),L=i+k;if(Xe(L,c,n)&&L<i+l)if(s)E={cursorPosition:{x:L,y:c,bg:u.bg}};else {let b=t.get(L,c),y=b?.ch&&b.ch!==" "?b.ch:"\u258C",C=u.bg??"black",p=u.color??"white";t.setChar(L,c,y,C,p,b?.bold,b?.dim,b?.italic,false);}}}return E}var sr="\x1B",me=`${sr}[`;function ir(e,t){return `${me}${t+1};${e+1}H`}function lr(e){let t=`${me}0m`;return e.bold&&(t+=`${me}1m`),e.dim&&(t+=`${me}2m`),e.italic&&(t+=`${me}3m`),e.underline&&(t+=`${me}4m`),e.fg!=null&&(t+=Kt(e.fg)),e.bg!=null&&(t+=$t(e.bg)),t}function nn(e,t,n){let r="",o=-1,s=-1,i="";for(let c=0;c<t.height;c++)for(let l=0;l<t.width;l++){let a=t.get(l,c);if(!n){let h=e.get(l,c);if(h&&t.cellsEqual(a,h))continue}(s!==c||o!==l)&&(r+=ir(l,c));let f=lr(a);f!==i&&(r+=f,i=f),r+=a.ch,o=l+1,s=c;}return r.length>0&&(r+=`${me}0m`),r}var fr={row:FlexDirection.Row,column:FlexDirection.Column},dr={"flex-start":Justify.FlexStart,center:Justify.Center,"flex-end":Justify.FlexEnd,"space-between":Justify.SpaceBetween,"space-around":Justify.SpaceAround},pr={"flex-start":Align.FlexStart,center:Align.Center,"flex-end":Align.FlexEnd,stretch:Align.Stretch};function sn(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%"),t(n));}function ae(e,t,n){n!==void 0&&(typeof n=="string"&&n.endsWith("%")?e.setPositionPercent(t,parseFloat(n)):e.setPosition(t,n));}function mr(e,t,n){sn(e,o=>e.setWidth(o),t.width),sn(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(fr[t.flexDirection]??FlexDirection.Column),t.flexWrap&&e.setFlexWrap(t.flexWrap==="wrap"?Wrap.Wrap:Wrap.NoWrap),t.justifyContent&&e.setJustifyContent(dr[t.justifyContent]??Justify.FlexStart),t.alignItems&&e.setAlignItems(pr[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&&(ae(e,Edge.Top,t.inset),ae(e,Edge.Right,t.inset),ae(e,Edge.Bottom,t.inset),ae(e,Edge.Left,t.inset)),ae(e,Edge.Top,t.top),ae(e,Edge.Right,t.right),ae(e,Edge.Bottom,t.bottom),ae(e,Edge.Left,t.left),t.clip&&e.setOverflow(Overflow.Hidden);}function cn(e){let t=ln.Node.create();if(e.yogaNode=t,mr(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=un(e),Jt(i,n,r,e.style.wrap??"wrap")});else for(let n=0;n<e.children.length;n++){let r=e.children[n];r.hidden||(cn(r),t.insertChild(r.yogaNode,t.getChildCount()));}}function un(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=un(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 an(e,t,n){let r=e.yogaNode,o=r.getComputedLayout(),s=t+o.left,i=n+o.top,c=o.width,l=o.height,a=e.style.border&&e.style.border!=="none"?1:0,f=r.getComputedPadding(Edge.Top),h=r.getComputedPadding(Edge.Right),S=r.getComputedPadding(Edge.Bottom),R=r.getComputedPadding(Edge.Left),I=s+a+R,u=i+a+f,m=Math.max(0,c-a*2-R-h),g=Math.max(0,l-a*2-f-S);e.layout={x:s,y:i,width:c,height:l,innerX:I,innerY:u,innerWidth:m,innerHeight:g};for(let v of e.children)v.hidden||!v.yogaNode||an(v,s,i);}function fn(e,t,n){let r=ln.Node.create();r.setWidth(t),r.setHeight(n),r.setFlexDirection(FlexDirection.Column);for(let o of e)o.hidden||(cn(o),r.insertChild(o.yogaNode,r.getChildCount()));r.calculateLayout(t,n,Direction.LTR);for(let o of e)o.hidden||!o.yogaNode||an(o,0,0);r.freeRecursive(),dn(e);}function dn(e){for(let t of e)t.yogaNode=null,dn(t.children);}var Z=createContext(null),J=createContext(null),oe=createContext(null),Se=createContext(null),Ye=createContext(null);function hr(e,t={}){let n=t.stdout??process.stdout,r=t.stdin??process.stdin,o=t.debug??false,s=t.useNativeCursor??true,i=new _e(n,r);i.setup();let c=false;i.queryPalette().then(x=>{qt(x),f=true,p();});let l=new Ne(i.columns,i.rows),a=new Ne(i.columns,i.rows),f=true,h=new Set,S=new Set,R=new Map,I={subscribe(x){return h.add(x),()=>h.delete(x)},subscribePriority(x){return S.add(x),()=>S.delete(x)},registerInputHandler(x,A){return R.set(x,A),()=>R.delete(x)}},u=null,m=new Map,g=[],v=new Set,P=[],H=new Set;function D(x){if(u!==x){u=x,p();for(let A of H)A(u);}}function E(){let x=[...g];if(P.length>0){let A=P[P.length-1];x=x.filter(N=>A.has(N));}return x=x.filter(A=>!v.has(A)),x.sort((A,N)=>{let w=m.get(A),T=m.get(N);if(!w||!T)return 0;let F=w.layout,_=T.layout;return F.y!==_.y?F.y-_.y:F.x-_.x}),x}let B={get focusedId(){return u},register(x,A){if(m.set(x,A),g.includes(x)||g.push(x),P.length>0&&P[P.length-1].add(x),u===null){let N=E();N.length>0&&D(N[0]);}return ()=>{m.delete(x);let N=g.indexOf(x);if(N!==-1&&g.splice(N,1),u===x){let w=E();D(w[0]??null);}}},requestFocus(x){D(x);},focusNext(){let x=E();if(x.length===0)return;let N=((u?x.indexOf(u):-1)+1)%x.length;D(x[N]);},focusPrev(){let x=E();if(x.length===0)return;let N=((u?x.indexOf(u):0)-1+x.length)%x.length;D(x[N]);},setSkippable(x,A){if(A){if(v.add(x),u===x){let N=E();N.length>0&&D(N[0]);}}else v.delete(x);},trapIds:null,pushTrap(x){return P.push(x),()=>{let A=P.indexOf(x);A!==-1&&P.splice(A,1);}},onFocusChange(x){return H.add(x),()=>{H.delete(x);}},getRegisteredElements(){let x=[];for(let A of g){if(v.has(A))continue;let N=m.get(A);N&&x.push({id:A,node:N});}return x},getActiveElements(){let x=E(),A=[];for(let N of x){if(v.has(N))continue;let w=m.get(N);w&&A.push({id:N,node:w});}return A}},k=new Map,L={getLayout(x){return x.layout},subscribe(x,A){return k.has(x)||k.set(x,new Set),k.get(x).add(A),()=>{let N=k.get(x);N&&(N.delete(A),N.size===0&&k.delete(x));}}},b={registerNode(){},unregisterNode(){},scheduleRender:p,exit(x){ce.exit(x);},get columns(){return i.columns},get rows(){return i.rows}},y={type:"root",children:[],onCommit(){p();}},C=false;function p(){C||(C=true,queueMicrotask(()=>{C=false,G();}));}function G(){let x=i.columns,A=i.rows;(a.width!==x||a.height!==A)&&(a.resize(x,A),l.resize(x,A),f=true),fn(y.children,x,A),z(y.children);let N;if(u){let F=m.get(u);F?.type==="input"&&(N={nodeId:u,position:F.props.cursorPosition??F.props.value?.length??0});}let w=Qt(y.children,a,{cursorInfo:N,useNativeCursor:s}),T=nn(l,a,f);if(T.length>0&&i.write(T),s)if(w.cursorPosition){let F=zt(w.cursorPosition.bg);i.setCursorColor(F),i.moveCursor(w.cursorPosition.x,w.cursorPosition.y),c||(i.showCursor(),c=true);}else c&&(i.hideCursor(),c=false);for(let F=0;F<a.cells.length;F++)l.cells[F]={...a.cells[F]};f=false;}function z(x){for(let A of x){let N=k.get(A);if(N)for(let w of N)w(A.layout);z(A.children);}}let O=i.onData(x=>{let A=Dt(x);for(let N of A){if(N.ctrl&&N.name==="c"){ce.exit();return}if(N.ctrl&&N.name==="z"){i.suspend(),process.kill(0,"SIGSTOP");return}let w=false;for(let T of S)if(T(N)){w=true;break}if(!w&&u){let T=R.get(u);T&&(w=T(N));}if(!w&&N.name==="tab"&&!N.ctrl&&!N.alt){N.shift?B.focusPrev():B.focusNext();continue}if(!w)for(let T of h)T(N);}}),$=i.onResize(()=>{f=true,p();}),Y=()=>{i.resume(),f=true,p();};process.on("SIGCONT",Y);let q=te.createElement(Se.Provider,{value:b},te.createElement(Z.Provider,{value:I},te.createElement(J.Provider,{value:B},te.createElement(oe.Provider,{value:L},e)))),W=x=>{o&&console.error("Uncaught error:",x);},X=x=>{o&&console.error("Error caught by boundary:",x);},M=x=>{o&&console.error("Recoverable error:",x);},se=ke.createContainer(y,0,null,false,null,"",W,X,M,null);ke.updateContainer(q,se,null,null);let ce={unmount(){ke.updateContainer(null,se,null,null),O(),$(),process.off("SIGCONT",Y),i.cleanup();},exit(x){ce.unmount(),process.exit(x??0);}};return ce}var xr=forwardRef(function({children:t,style:n,focusable:r},o){return te.createElement("box",{style:n,focusable:r,ref:o},t)});var Sr=forwardRef(function({children:t,style:n,wrap:r},o){let s=r?{...n,wrap:r}:n;return te.createElement("text",{style:s,ref:o},t)});function pn(e,t,n){if(n<=0)return {visualLine:0,visualCol:t,totalVisualLines:1,lineStartOffset:0,lineLength:e.length};let r=e.split(`
|
|
5
|
+
`),o=[],s=0;for(let l of r){let a=ie([l],n,"wrap"),f=0;for(let h of a)o.push({text:h,logicalOffset:s+f}),f+=h.length;s+=l.length+1;}let i=0;for(let l=0;l<o.length;l++){let a=o[l],f=a.text.length,h=l+1<o.length&&o[l+1].logicalOffset!==a.logicalOffset+f,S=f+(h?1:0);if(t<i+f||l===o.length-1)return {visualLine:l,visualCol:Math.min(t-i,f),totalVisualLines:o.length,lineStartOffset:i,lineLength:f};i+=S;}let c=o.length-1;return {visualLine:c,visualCol:o[c].text.length,totalVisualLines:o.length,lineStartOffset:i-o[c].text.length,lineLength:o[c].text.length}}function mn(e,t,n,r){if(r<=0)return Math.min(n,e.length);let o=e.split(`
|
|
6
|
+
`),s=[],i=0;for(let f of o){let h=ie([f],r,"wrap"),S=0;for(let R of h)s.push({text:R,startOffset:i+S}),S+=R.length;i+=f.length+1;}let c=Math.max(0,Math.min(t,s.length-1)),l=s[c],a=Math.min(n,l.text.length);return l.startOffset+a}function Be(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 Ge(e,t,n){let r=0;for(let o=0;o<t&&o<e.length;o++)r+=e[o].length+1;return r+Math.min(n,e[t]?.length??0)}function Rr(e){let{value:t,defaultValue:n="",onChange:r,onKeyPress:o,onBeforeChange:s,placeholder:i,style:c,focusedStyle:l,multiline:a,autoFocus:f,type:h="text"}=e,[S,R]=useState(n),[I,u]=useState(n.length),[m,g]=useState(0),[v,P]=useState(false),[H,D]=useState(false),E=useContext(Z),B=useContext(J),k=useContext(oe),L=useRef(null),b=useRef(null),y=t!==void 0,C=y?t:S;useEffect(()=>{if(!k||!L.current)return;let W=k.getLayout(L.current);return g(W.innerWidth),k.subscribe(L.current,X=>{g(X.innerWidth);})},[k]);let p=useRef(C),G=useRef(I),z=useRef(C),O=useRef(I);useEffect(()=>{C!==z.current&&(p.current=C,z.current=C,G.current=C.length,O.current=C.length,u(C.length));},[C]),useEffect(()=>{I!==O.current&&(G.current=I,O.current=I);},[I]);let $=useRef({isControlled:y,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:a??false,innerWidth:m,type:h});$.current={isControlled:y,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:a??false,innerWidth:m,type:h},useEffect(()=>{if(!(!B||!b.current||!L.current))return B.register(b.current,L.current)},[B,H]);let Y=useRef(false);useEffect(()=>{if(!H){Y.current=false;return}if(f&&!Y.current&&B&&b.current){Y.current=true;let W=b.current,X=setTimeout(()=>{B.requestFocus(W);},0);return ()=>clearTimeout(X)}},[f,B,H]),useEffect(()=>{if(!B||!b.current)return;let W=b.current;return P(B.focusedId===W),B.onFocusChange(X=>{P(X===W);})},[B,H]),useEffect(()=>{if(!E||!b.current)return;let W=b.current,X=M=>{let{isControlled:se,onChange:ce,onKeyPress:x,onBeforeChange:A,multiline:N}=$.current;if(x?.(M)===true)return true;let w=p.current,T=G.current;if(M.name==="escape")return false;let F=(d,j)=>{let V=d,Q=j;if(A){let U=A(d,w);if(U===false)return;typeof U=="string"&&(V=U,Q=U.length);}p.current=V,G.current=Q,z.current=V,O.current=Q,se||R(V),ce?.(V),u(Q);},_=d=>{G.current=d,O.current=d,u(d);};if(M.name==="return"){if(N){let d=w.slice(0,T)+`
|
|
8
|
+
`+w.slice(T);return F(d,T+1),true}return false}if(M.ctrl){if(M.name==="w"){if(T>0){let d=T;for(;d>0&&w[d-1]===" ";)d--;for(;d>0&&w[d-1]!==" "&&(!N||w[d-1]!==`
|
|
9
|
+
`);)d--;let j=w.slice(0,d)+w.slice(T);F(j,d);}return true}if(M.name==="a"){if(N){let{line:d,lines:j}=Be(w,T);_(Ge(j,d,0));}else _(0);return true}if(M.name==="e"){if(N){let{line:d,lines:j}=Be(w,T);_(Ge(j,d,j[d].length));}else _(w.length);return true}if(M.name==="k"){if(N){let{line:d,lines:j}=Be(w,T),V=Ge(j,d,j[d].length);if(T<V){let Q=w.slice(0,T)+w.slice(V);F(Q,T);}}else if(T<w.length){let d=w.slice(0,T);F(d,T);}return true}return false}if(M.alt){if(M.name==="left"||M.name==="b"){let d=T;for(;d>0&&w[d-1]===" ";)d--;for(;d>0&&w[d-1]!==" "&&w[d-1]!==`
|
|
10
|
+
`;)d--;return _(d),true}if(M.name==="right"||M.name==="f"){let d=T;for(;d<w.length&&w[d]!==" "&&w[d]!==`
|
|
11
|
+
`;)d++;for(;d<w.length&&w[d]===" ";)d++;return _(d),true}if(M.name==="backspace"||M.name==="d")if(M.name==="backspace"){if(T>0){let d=T;for(;d>0&&w[d-1]===" ";)d--;for(;d>0&&w[d-1]!==" "&&w[d-1]!==`
|
|
12
|
+
`;)d--;let j=w.slice(0,d)+w.slice(T);F(j,d);}return true}else {if(T<w.length){let d=T;for(;d<w.length&&w[d]!==" "&&w[d]!==`
|
|
13
|
+
`;)d++;for(;d<w.length&&w[d]===" ";)d++;let j=w.slice(0,T)+w.slice(d);F(j,T);}return true}return false}if(M.name==="left")return _(Math.max(0,T-1)),true;if(M.name==="right")return _(Math.min(w.length,T+1)),true;if(M.name==="up"){let{innerWidth:d}=$.current,j=pn(w,T,d);return j.visualLine>0&&_(mn(w,j.visualLine-1,j.visualCol,d)),true}if(M.name==="down"){let{innerWidth:d}=$.current,j=pn(w,T,d);return j.visualLine<j.totalVisualLines-1&&_(mn(w,j.visualLine+1,j.visualCol,d)),true}if(M.name==="home"){if(N){let{line:d,lines:j}=Be(w,T);_(Ge(j,d,0));}else _(0);return true}if(M.name==="end"){if(N){let{line:d,lines:j}=Be(w,T);_(Ge(j,d,j[d].length));}else _(w.length);return true}if(M.name==="backspace"){if(T>0){let d=w.slice(0,T-1)+w.slice(T);F(d,T-1);}return true}if(M.name==="delete"){if(T<w.length){let d=w.slice(0,T)+w.slice(T+1);F(d,T);}return true}if(M.name.length>1)return false;let K=M.sequence;if(K.length===1&&K.charCodeAt(0)>=32){let{type:d}=$.current;if(d==="number"){let V=/[0-9]/.test(K),Q=K==="."&&!w.includes("."),U=K==="-"&&T===0&&!w.includes("-");if(!V&&!Q&&!U)return true}let j=w.slice(0,T)+K+w.slice(T);return F(j,T+1),true}return false};return E.registerInputHandler(W,X)},[E,H]);let q={...c,...v&&l?l:{}};return te.createElement("input",{style:q,value:C,defaultValue:n,placeholder:i,onChange:r,cursorPosition:G.current,multiline:a??false,focused:v,ref:W=>{W?(L.current=W,b.current=W.focusId,D(true)):(L.current=null,b.current=null,D(false));}})}function pt({trap:e=false,children:t}){let n=useContext(J),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]),te.createElement(te.Fragment,null,t)}function Nr({size:e}){return te.createElement("box",{style:{flexGrow:e??1}})}function bn(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 Cn(e,t){return !(t.name!==e.name||e.ctrl!==!!t.ctrl||e.alt!==!!t.alt||e.shift!==!!t.shift||e.meta!==!!t.meta)}function Er({keypress:e,onPress:t,whenFocused:n,priority:r,disabled:o}){let s=useContext(Z),i=useContext(J),c=useRef(t);c.current=t;let l=useRef(bn(e));return l.current=bn(e),useEffect(()=>{if(!(!s||o))if(r){let a=f=>!Cn(l.current,f)||n&&i?.focusedId!==n?false:(c.current(),true);return s.subscribePriority(a)}else {let a=f=>{Cn(l.current,f)&&(n&&i?.focusedId!==n||c.current());};return s.subscribe(a)}},[s,i,n,r,o]),null}function Br({children:e,zIndex:t=1e3}){return te.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:t}},e)}function Lr({onPress:e,style:t,focusedStyle:n,children:r,disabled:o}){let s=useContext(J),i=useContext(Z),c=useRef(null),l=useRef(null),a=useRef(e);a.current=e;let[f,h]=useState(false),[S,R]=useState(false);useEffect(()=>{if(!(!s||!l.current||!c.current||o))return s.register(l.current,c.current)},[s,o,f]),useEffect(()=>{if(!s||!l.current)return;let u=l.current;return R(s.focusedId===u),s.onFocusChange(m=>{R(m===u);})},[s,f]),useEffect(()=>{if(!i||!l.current||o)return;let u=l.current,m=g=>s?.focusedId!==u?false:g.name==="return"||g.name===" "||g.sequence===" "?(a.current?.(),true):false;return i.registerInputHandler(u,m)},[i,s,o,f]);let I={...t,...S&&n?n:{}};return te.createElement("box",{style:I,focusable:!o,ref:u=>{u?(c.current=u,l.current=u.focusId,h(true)):(c.current=null,l.current=null,h(false));}},r)}var Hr={x:0,y:0,width:0,height:0,innerX:0,innerY:0,innerWidth:0,innerHeight:0};function de(e){let t=useContext(oe),[n,r]=useState(Hr);return useEffect(()=>{if(!(!t||!e?.current))return r(t.getLayout(e.current)),t.subscribe(e.current,r)},[t,e]),n}function Le(e,t=[]){let n=useContext(Z);useEffect(()=>{if(n)return n.subscribe(e)},[n,...t]);}function $r({children:e,style:t,scrollOffset:n,onScroll:r,defaultScrollOffset:o=0,scrollStep:s=1,disableKeyboard:i,scrollToFocus:c=true,showScrollbar:l=true,focusable:a=true,focusedStyle:f}){let h=n!==void 0,[S,R]=useState(o),I=h?n:S,u=useRef(null),m=useRef(null),g=de(u),v=de(m),P=useContext(J),H=useContext(oe),D=useRef(null);a&&!D.current&&(D.current=`scrollview-${Math.random().toString(36).slice(2,9)}`);let E=a?D.current:null;useEffect(()=>{if(!(!a||!E||!P||!u.current))return P.register(E,u.current)},[a,E,P]);let B=a&&E&&P?.focusedId===E,k=g.innerHeight,L=v.height,b=Math.max(0,L-k),y=Math.max(0,Math.min(I,b)),C=useMemo(()=>({getBounds:()=>{let V=g.y;return {visibleTop:V,visibleBottom:V+k,viewportHeight:k,scrollOffset:y}}}),[g.y,k,y]),p=useCallback(V=>{let Q=Math.max(0,Math.min(V,b));h?r?.(Q):R(Q);},[h,r,b]);useEffect(()=>{I>b&&b>=0&&p(b);},[I,b,p]),useEffect(()=>!c||!P||!H||!m.current?void 0:P.onFocusChange(Q=>{if(!Q||!m.current)return;let U=Ke=>{if(Ke.focusId===Q)return Ke;for(let $e of Ke.children){let xe=U($e);if(xe)return xe}return null},pe=U(m.current);if(!pe)return;let ye=H.getLayout(pe),ve=m.current.layout?.y??0,Oe=ye.y-ve,De=Oe+ye.height,Ie=I,ot=I+k;Oe<Ie?p(Oe):De>ot&&p(De-k);}),[c,P,H,I,k,p]);let G=useCallback(()=>{if(!P)return false;let V=P.focusedId;if(!V)return false;if(a&&E&&V===E)return true;if(!m.current)return false;let Q=U=>{if(U.focusId===V)return true;for(let pe of U.children)if(Q(pe))return true;return false};return Q(m.current)},[P,a,E]);Le(V=>{if(i||!G())return;let Q=Math.max(1,Math.floor(k/2)),U=Math.max(1,k);switch(V.name){case "pageup":p(I-U);break;case "pagedown":p(I+U);break;default:V.ctrl&&(V.name==="d"?p(I+Q):V.name==="u"?p(I-Q):V.name==="f"?p(I+U):V.name==="b"&&p(I-U));break}},[I,s,k,b,i,p,G]);let{padding:z,paddingX:O,paddingY:$,paddingTop:Y,paddingRight:q,paddingBottom:W,paddingLeft:X,...M}=t??{},ce=M.border!=null&&M.border!=="none"?2:0,x=L>0?L+ce:void 0,A={...M,...B?f:{},clip:true,...M.height===void 0&&x!==void 0?{height:x,flexShrink:M.flexShrink??1,minHeight:M.minHeight??0}:{}},N={position:"absolute",top:-y,left:0,right:0,flexDirection:"column",...z!==void 0&&{padding:z},...O!==void 0&&{paddingX:O},...$!==void 0&&{paddingY:$},...Y!==void 0&&{paddingTop:Y},...q!==void 0&&{paddingRight:q},...W!==void 0&&{paddingBottom:W},...X!==void 0&&{paddingLeft:X}},w=L>k&&k>0,T=l&&w,F=Math.max(1,Math.floor(k/L*k)),_=L-k,K=_>0?Math.floor(y/_*(k-F)):0,d=[];if(T)for(let V=0;V<k;V++)V>=K&&V<K+F?d.push("\u2588"):d.push("\u2591");let j={position:"absolute",top:0,right:0,width:1,height:k,flexDirection:"column"};return te.createElement(Ye.Provider,{value:C},te.createElement("box",{style:A,ref:V=>{u.current=V??null;},...a?{focusable:true,focusId:E}:{}},te.createElement("box",{style:{...N,paddingRight:T?(N.paddingRight??0)+1:N.paddingRight},ref:V=>{m.current=V??null;}},e),T&&te.createElement("box",{style:j},te.createElement("text",{style:{color:"blackBright"}},d.join(`
|
|
14
|
+
`)))))}function wt({count:e,renderItem:t,selectedIndex:n,onSelectionChange:r,onSelect:o,defaultSelectedIndex:s=0,disabledIndices:i,style:c,focusable:l=true}){let a=n!==void 0,[f,h]=useState(s),S=a?n:f,R=useContext(J),I=useContext(Z),u=useRef(null),m=useRef(null),g=useRef(o);g.current=o;let[v,P]=useState(false),[H,D]=useState(false),E=useRef(null),B=useCallback(y=>{let C=Math.max(0,Math.min(y,e-1));a?r?.(C):h(C);},[a,r,e]),k=useCallback((y,C)=>{if(!i||i.size===0)return Math.max(0,Math.min(y+C,e-1));let p=y+C;for(;p>=0&&p<e&&i.has(p);)p+=C;return p<0||p>=e?y:p},[i,e]);useEffect(()=>{if(!(!R||!m.current||!u.current||!l))return R.register(m.current,u.current)},[R,l,v]),useEffect(()=>{if(!R||!m.current)return;let y=m.current;return D(R.focusedId===y),R.onFocusChange(C=>{D(C===y);})},[R,v]);let L=useCallback(y=>{let C=y?e-1:0,p=y?-1:1,G=C;for(;G>=0&&G<e&&i?.has(G);)G+=p;return G>=0&&G<e?G:y?e-1:0},[i,e]);useEffect(()=>{if(!I||!m.current||!l)return;let y=m.current,C=p=>R?.focusedId!==y?false:p.name==="g"&&!p.ctrl&&!p.alt?E.current==="g"?(B(L(false)),E.current=null,true):(E.current="g",true):p.name==="G"||p.name==="g"&&p.shift?(E.current=null,B(L(true)),true):(E.current=null,p.name==="up"||p.name==="k"?(B(k(S,-1)),true):p.name==="down"||p.name==="j"?(B(k(S,1)),true):p.name==="return"?(i?.has(S)||g.current?.(S),true):false);return I.registerInputHandler(y,C)},[I,R,l,S,B,k,L,i,v]);let b=[];for(let y=0;y<e;y++)b.push(te.createElement(te.Fragment,{key:y},t({index:y,selected:y===S,focused:H})));return te.createElement("box",{style:{flexDirection:"column",...c},focusable:l,ref:y=>{y?(u.current=y,m.current=y.focusId,P(true)):(u.current=null,m.current=null,P(false));}},...b)}function Wr({items:e,selectedIndex:t,onSelectionChange:n,onSelect:r,defaultSelectedIndex:o=0,style:s,highlightColor:i="cyan",focusable:c=true}){let l=new Set;for(let f=0;f<e.length;f++)e[f].disabled&&l.add(f);let a=f=>{let h=e[f];h&&!h.disabled&&r?.(h.value,f);};return te.createElement(wt,{count:e.length,selectedIndex:t,onSelectionChange:n,onSelect:a,defaultSelectedIndex:o,disabledIndices:l.size>0?l:void 0,style:s,focusable:c,renderItem:({index:f,selected:h,focused:S})=>{let R=e[f],I=R.disabled,u=h&&S,m=h?">":" ";return te.createElement("box",{style:{flexDirection:"row",...u?{bg:i}:{}}},te.createElement("text",{style:u?{bold:true,color:"black"}:I?{dim:true}:{}},`${m} ${R.label}`))}})}function Xr({value:e,indeterminate:t=false,width:n="100%",label:r,showPercent:o=false,style:s,filled:i="\u2588",empty:c="\u2591"}){let l=useRef(null),f=de(l).innerWidth,[h,S]=useState(0);useEffect(()=>{if(!t)return;let g=setInterval(()=>{S(v=>(v+1)%Math.max(1,f+6));},100);return ()=>clearInterval(g)},[t,f]);let R=Math.max(0,Math.min(1,e??0)),I=o?` ${Math.round(R*100)}%`:"",u="";if(f>0)if(t&&e===void 0){let g=Math.max(1,Math.min(3,Math.floor(f/4))),v=[];for(let P=0;P<f;P++)P>=h-g&&P<h?v.push(i):v.push(c);u=v.join("");}else {let g=Math.round(R*f);u=i.repeat(g)+c.repeat(f-g);}let m=[];return r&&m.push(te.createElement("text",{key:"label",style:{bold:true}},r+" ")),m.push(te.createElement("box",{key:"track",style:{flexGrow:1,flexShrink:1},ref:g=>{l.current=g??null;}},te.createElement("text",{key:"bar",style:{}},u))),o&&m.push(te.createElement("text",{key:"pct",style:{bold:true}},I)),te.createElement("box",{style:{flexDirection:"row",width:n,...s}},...m)}var Ur=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function Zr({frames:e=Ur,intervalMs:t=80,label:n,style:r}){let[o,s]=useState(0);useEffect(()=>{let c=setInterval(()=>{s(l=>(l+1)%e.length);},t);return ()=>clearInterval(c)},[e.length,t]);let i=[te.createElement("text",{key:"frame",style:r},e[o])];return n&&i.push(te.createElement("text",{key:"label",style:{}}," "+n)),te.createElement("box",{style:{flexDirection:"row"}},...i)}var Tn=createContext(null),oo=0;function so(){let e=useContext(Tn);if(!e)throw new Error("useToast must be used within a <ToastHost>");return e.push}var io={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 lo({position:e="bottom-right",maxVisible:t=5,children:n}){let[r,o]=useState([]),s=useRef(new Map),i=useCallback(R=>{let I=`toast-${oo++}`,u={id:I,durationMs:3e3,variant:"info",...R};if(o(m=>[...m,u]),u.durationMs&&u.durationMs>0){let m=setTimeout(()=>{s.current.delete(I),o(g=>g.filter(v=>v.id!==I));},u.durationMs);s.current.set(I,m);}},[]);useEffect(()=>()=>{for(let R of s.current.values())clearTimeout(R);s.current.clear();},[]);let c=useRef({push:i});c.current.push=i;let l=e.startsWith("top"),a=e.endsWith("right"),f={position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:900,flexDirection:"column",justifyContent:l?"flex-start":"flex-end",alignItems:a?"flex-end":"flex-start",padding:1},S=r.slice(-t).map(R=>{let I=R.variant??"info",u=io[I],m=[];return R.title&&m.push(te.createElement("text",{key:"title",style:{bold:true,color:u.title}},R.title)),m.push(te.createElement("text",{key:"msg",style:{color:u.text}},R.message)),te.createElement("box",{key:R.id,style:{bg:u.bg,paddingX:1,flexDirection:"column",minWidth:20,maxWidth:50}},...m)});return te.createElement(Tn.Provider,{value:c.current},n,S.length>0?te.createElement("box",{style:f},...S):null)}function uo({items:e,value:t,onChange:n,placeholder:r="Select...",style:o,focusedStyle:s,dropdownStyle:i,highlightColor:c="cyan",maxVisible:l=8,searchable:a=true,disabled:f}){let h=useContext(J),S=useContext(Z),R=useContext(Se),I=useContext(Ye),u=useRef(null),m=useRef(null),g=useRef(n);g.current=n;let[v,P]=useState(false),[H,D]=useState(false),[E,B]=useState(false),[k,L]=useState(0),[b,y]=useState(""),[C,p]=useState(0),G=de(u),z=R?.rows??24,O=I?.getBounds(),Y=e.find(F=>F.value===t)?.label??"",q=useMemo(()=>{if(!b)return e;let F=b.toLowerCase();return e.filter(_=>_.label.toLowerCase().includes(F))},[e,b]),W=Math.min(l,q.length),X=q.slice(C,C+W);useEffect(()=>{L(0),p(0);},[b]),useEffect(()=>{!H&&E&&(B(false),y(""));},[H,E]),useEffect(()=>{if(!(!h||!m.current||!u.current))return h.register(m.current,u.current)},[h,v]),useEffect(()=>{!h||!m.current||h.setSkippable(m.current,!!f);},[h,f,v]),useEffect(()=>{if(!h||!m.current)return;let F=m.current;return D(h.focusedId===F),h.onFocusChange(_=>{D(_===F);})},[h,v]);let M=useCallback((F,_)=>{let K=F+_;for(;K>=0&&K<q.length;){if(!q[K].disabled)return K;K+=_;}return F},[q]),se=useCallback(F=>{F<C?p(F):F>=C+W&&p(F-W+1);},[C,W]);useEffect(()=>{if(!S||!m.current||f)return;let F=m.current,_=K=>{if(h?.focusedId!==F)return false;if(!E){if(K.name==="return"||K.name===" "||K.sequence===" "||K.name==="down"){B(true),y("");let d=q.findIndex(V=>V.value===t),j=d>=0?d:0;return L(j),p(Math.max(0,j-Math.floor(l/2))),true}return false}if(K.name==="tab")return B(false),y(""),false;if(K.name==="escape")return B(false),y(""),true;if(K.name==="return"){let d=q[k];return d&&!d.disabled&&(g.current?.(d.value),B(false),y("")),true}if(K.name==="up"){let d=M(k,-1);return L(d),se(d),true}if(K.name==="down"){let d=M(k,1);return L(d),se(d),true}if(K.name==="backspace")return a&&b.length>0&&y(d=>d.slice(0,-1)),true;if(K.name==="home"){let d=M(-1,1);return L(d),se(d),true}if(K.name==="end"){let d=M(q.length,-1);return L(d),se(d),true}if(a&&K.sequence&&K.sequence.length===1&&!K.ctrl&&!K.alt){let d=K.sequence;if(d>=" "&&d<="~")return y(j=>j+d),true}return true};return S.registerInputHandler(F,_)},[S,h,f,E,k,q,t,l,a,b,M,se,v]);let x={flexDirection:"row",width:"100%",...!o?.bg&&o?.border===void 0?{border:"single"}:{},...o,...H&&s?s:{}},A=Y?o?.color??void 0:"blackBright",N=[te.createElement("text",{key:"label",style:{flexGrow:1,flexShrink:1,color:A,wrap:"ellipsis",...Y?{}:{dim:true}}},Y||r),te.createElement("text",{key:"arrow",style:{flexShrink:0,color:H?c:"blackBright"}},E?" \u25B2":" \u25BC")],w=null;if(E){let F=[];a&&b&&F.push(te.createElement("box",{key:"search",style:{paddingX:1}},te.createElement("text",{style:{color:"blackBright",dim:true}},`/${b}`))),q.length===0&&F.push(te.createElement("box",{key:"empty",style:{paddingX:1}},te.createElement("text",{style:{dim:true,color:"blackBright"}},"No matches"))),C>0&&F.push(te.createElement("box",{key:"scroll-up",style:{justifyContent:"center",alignItems:"center"}},te.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25B2"))),X.forEach((Ie,ot)=>{let $e=C+ot===k,xe=Ie.disabled,jn={paddingX:1,...$e&&!xe?{bg:c}:{}},On={...$e&&!xe?{color:"black",bold:true}:{},...xe?{dim:true,color:"blackBright"}:{}};F.push(te.createElement("box",{key:`item-${Ie.value}`,style:jn},te.createElement("text",{style:On},Ie.label)));}),C+W<q.length&&F.push(te.createElement("box",{key:"scroll-down",style:{justifyContent:"center",alignItems:"center"}},te.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25BC")));let _=C>0,K=C+W<q.length,d=a&&b,j=q.length===0,V=!i?.bg&&i?.border===void 0,U=W+(V?2:0);_&&(U+=1),K&&(U+=1),d&&(U+=1),j&&(U+=1);let pe=G.y+G.height,ye,ve;O?(ye=O.visibleBottom-pe,ve=G.y-O.visibleTop):(ye=z-pe,ve=G.y);let De=ye<U&&ve>=U?-U:G.height||1;w=te.createElement("box",{style:{position:"absolute",top:De,left:0,right:0,zIndex:9999,...V?{border:"single"}:{},bg:"black",flexDirection:"column",...i}},...F);}let T={flexDirection:"column",width:x.width??"100%",minWidth:x.minWidth,maxWidth:x.maxWidth,flexGrow:x.flexGrow,flexShrink:x.flexShrink??1};return te.createElement("box",{style:T},te.createElement("box",{style:x,focusable:true,ref:F=>{F?(u.current=F,m.current=F.focusId,P(true)):(u.current=null,m.current=null,P(false));}},...N),w)}function ao({checked:e,onChange:t,label:n,style:r,focusedStyle:o,disabled:s,checkedChar:i="\u2713",uncheckedChar:c=" "}){let l=useContext(J),a=useContext(Z),f=useRef(null),h=useRef(null),S=useRef(t);S.current=t;let R=useRef(e);R.current=e;let[I,u]=useState(false),[m,g]=useState(false);useEffect(()=>{if(!(!l||!h.current||!f.current||s))return l.register(h.current,f.current)},[l,s,I]),useEffect(()=>{if(!l||!h.current)return;let E=h.current;return g(l.focusedId===E),l.onFocusChange(B=>{g(B===E);})},[l,I]),useEffect(()=>{if(!a||!h.current||s)return;let E=h.current,B=k=>l?.focusedId!==E?false:k.name==="return"||k.name===" "||k.sequence===" "?(S.current(!R.current),true):false;return a.registerInputHandler(E,B)},[a,l,s,I]);let v={flexDirection:"row",gap:1,...r,...m&&o?o:{}},P=e?i:c,H={color:s?"blackBright":m?"white":r?.color},D={color:s?"blackBright":r?.color};return te.createElement("box",{style:v,focusable:!s,ref:E=>{E?(f.current=E,h.current=E.focusId,u(true)):(f.current=null,h.current=null,u(false));}},te.createElement("text",{key:"box",style:H},`[${P}]`),n?te.createElement("text",{key:"label",style:D},n):null)}function po({items:e,value:t,onChange:n,style:r,itemStyle:o,focusedItemStyle:s,selectedItemStyle:i,disabled:c,direction:l="column",gap:a=0,selectedChar:f="\u25CF",unselectedChar:h="\u25CB"}){let S=useContext(J),R=useContext(Z),I=useRef(null),u=useRef(null),m=useRef(n);m.current=n;let[g,v]=useState(false),[P,H]=useState(false),[D,E]=useState(()=>{let b=e.findIndex(y=>y.value===t);return b>=0?b:e.findIndex(y=>!y.disabled)}),B=useCallback((b,y)=>{let C=b;for(let p=0;p<e.length;p++)if(C=(C+y+e.length)%e.length,!e[C]?.disabled)return C;return b},[e]);useEffect(()=>{if(!(!S||!u.current||!I.current||c))return S.register(u.current,I.current)},[S,c,g]),useEffect(()=>{if(!S||!u.current)return;let b=u.current;return H(S.focusedId===b),S.onFocusChange(y=>{H(y===b);})},[S,g]),useEffect(()=>{if(!R||!u.current||c)return;let b=u.current,y=C=>{if(S?.focusedId!==b)return false;if(C.name==="up"||C.name==="left"||C.name==="k"||C.name==="tab"&&C.shift)return E(p=>B(p,-1)),true;if(C.name==="down"||C.name==="right"||C.name==="j"||C.name==="tab"&&!C.shift)return E(p=>B(p,1)),true;if(C.name==="return"||C.name===" "||C.sequence===" "){let p=e[D];return p&&!p.disabled&&m.current(p.value),true}return false};return R.registerInputHandler(b,y)},[R,S,c,e,D,B,g]),useEffect(()=>{let b=e.findIndex(y=>y.value===t);b>=0&&E(b);},[t,e]);let k={flexDirection:l,gap:a,...r},L=e.map((b,y)=>{let C=b.value===t,p=y===D,G=c||b.disabled,z=C?f:h,O={flexDirection:"row",gap:1,...o};C&&i&&(O={...O,...i}),P&&p&&s&&(O={...O,...s});let $=G?"blackBright":P&&p?s?.color??"white":C?i?.color??o?.color:o?.color;return te.createElement("box",{key:y,style:O},te.createElement("text",{key:"radio",style:{color:$}},`(${z})`),te.createElement("text",{key:"label",style:{color:$}},b.label))});return te.createElement("box",{style:k,focusable:!c,ref:b=>{b?(I.current=b,u.current=b.focusId,v(true)):(I.current=null,u.current=null,v(false));}},...L)}var Ln=createContext(null);function ho(){let e=useContext(Ln);if(!e)throw new Error("useDialog must be used within a DialogHost");return e}function go({children:e}){let[t,n]=useState([]),r=useRef(0),o=useCallback((a,f)=>new Promise(h=>{let S=++r.current;n(R=>[...R,{id:S,type:"alert",content:a,okText:f?.okText??"OK",cancelText:"",style:f?.style,buttonStyle:f?.buttonStyle,okButtonStyle:f?.okButtonStyle,focusedButtonStyle:f?.focusedButtonStyle,backdropStyle:f?.backdropStyle,resolve:()=>h()}]);}),[]),s=useCallback((a,f)=>new Promise(h=>{let S=++r.current;n(R=>[...R,{id:S,type:"confirm",content:a,okText:f?.okText??"OK",cancelText:f?.cancelText??"Cancel",style:f?.style,buttonStyle:f?.buttonStyle,okButtonStyle:f?.okButtonStyle,cancelButtonStyle:f?.cancelButtonStyle,focusedButtonStyle:f?.focusedButtonStyle,backdropStyle:f?.backdropStyle,resolve:h}]);}),[]),i=useCallback((a,f)=>{n(h=>{let S=h.find(R=>R.id===a);return S&&S.resolve(f),h.filter(R=>R.id!==a)});},[]),c={alert:o,confirm:s},l=t[t.length-1];return te.createElement(Ln.Provider,{value:c},e,l&&te.createElement(yo,{key:l.id,dialog:l,onDismiss:i}))}function yo({dialog:e,onDismiss:t}){let n=useContext(J),r=useRef(null),o=useRef(null),s=useRef(null),i=useRef(null),[c,l]=useState("ok"),[a,f]=useState(0);useEffect(()=>{if(!n||a===0)return;let g=[];return r.current&&s.current&&g.push(n.register(s.current,r.current)),o.current&&i.current&&g.push(n.register(i.current,o.current)),s.current&&n.requestFocus(s.current),()=>g.forEach(v=>v())},[n,a]),useEffect(()=>{if(n)return n.onFocusChange(g=>{g===s.current?l("ok"):g===i.current&&l("cancel");})},[n]),Le(g=>{if(g.name==="return"||g.name==="space"){e.type==="alert"?t(e.id,true):t(e.id,c==="ok");return}if(g.name==="escape"){t(e.id,false);return}e.type==="confirm"&&n&&(g.name==="left"||g.name==="right")&&(c==="ok"&&i.current?n.requestFocus(i.current):s.current&&n.requestFocus(s.current));},[e,c,n,t]);let h=typeof e.content=="string",S=h?e.content.length:0,I={minWidth:Math.max(20,h?Math.min(S+6,50):30),maxWidth:50,bg:"black",border:"round",borderColor:"white",padding:1,flexDirection:"column",gap:1,...e.style},u=(g,v)=>{let P={paddingX:2,bg:"blackBright",color:"white"},H={bg:"white",color:"black",bold:true},D=g==="ok"?e.okButtonStyle:e.cancelButtonStyle;return {...P,...e.buttonStyle,...D,...v?{...H,...e.focusedButtonStyle}:{}}},m={position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:999,...e.backdropStyle};return te.createElement(pt,{trap:true},te.createElement("box",{style:m}),te.createElement("box",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,justifyContent:"center",alignItems:"center",zIndex:1e3}},te.createElement("box",{style:I},te.createElement("box",{style:{flexDirection:"column"}},typeof e.content=="string"?te.createElement("text",null,e.content):e.content),te.createElement("box",{style:{flexDirection:"row",justifyContent:"flex-end",gap:1}},e.type==="confirm"&&te.createElement("box",{style:u("cancel",c==="cancel"),focusable:true,ref:g=>{g&&g.focusId&&!i.current&&(o.current=g,i.current=g.focusId,f(v=>v+1));}},te.createElement("text",null,e.cancelText)),te.createElement("box",{style:u("ok",c==="ok"),focusable:true,ref:g=>{g&&g.focusId&&!s.current&&(r.current=g,s.current=g.focusId,f(v=>v+1));}},te.createElement("text",null,e.okText))))))}function Co(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 So({children:e,activationKey:t="ctrl+o",hintStyle:n,hintBg:r="yellow",hintFg:o="black",hintChars:s="asdfghjklqwertyuiopzxcvbnm",enabled:i=true,debug:c=false}){let l=c?(...b)=>console.error("[JumpNav]",...b):()=>{},[a,f]=useState(false),[h,S]=useState(""),[R,I]=useState([]),u=useContext(Z),m=useContext(J),g=useContext(oe);useEffect(()=>{l("Mounted, inputCtx:",!!u,"focusCtx:",!!m,"enabled:",i);},[]);let P=useCallback(b=>{let y=b.toLowerCase().split("+");return {ctrl:y.includes("ctrl"),alt:y.includes("alt"),shift:y.includes("shift"),meta:y.includes("meta"),name:y[y.length-1]??""}},[])(t),H=useCallback(()=>{if(!m?.getActiveElements){l("refreshElements: no getActiveElements");return}let b=m.getActiveElements();l("getActiveElements returned",b.length,"elements");let y=b.map(({id:C,node:p})=>({id:C,node:p,layout:g?.getLayout(p)??p.layout}));y.sort((C,p)=>C.layout.y!==p.layout.y?C.layout.y-p.layout.y:C.layout.x-p.layout.x),I(y);},[m,g,l]),D=useRef(false);useEffect(()=>{a&&!D.current&&(l("Activated! Refreshing elements..."),H()),D.current=a;},[a,H,l]);let E=R.filter(b=>b.layout.width>0&&b.layout.height>0),B=Co(E.length,s),k=useMemo(()=>{let b=new Map;return E.forEach((y,C)=>{B[C]&&b.set(B[C],y.id);}),b},[E,B]);useEffect(()=>{if(!u||!i){l("Not subscribing - inputCtx:",!!u,"enabled:",i);return}l("Subscribing to priority input, activation key:",t);let b=y=>{let C=y.name===P.name,p=!!y.ctrl===P.ctrl,G=!!y.alt===P.alt,z=!!y.shift===P.shift,O=!!y.meta===P.meta;if(!a&&C&&p&&G&&z&&O)return l("Activation key matched! Activating..."),f(true),S(""),true;if(a){if(y.name==="escape")return l("Escape pressed, deactivating"),f(false),S(""),true;if(y.name==="backspace")return S(""),true;if(y.sequence&&y.sequence.length===1&&/[a-z]/i.test(y.sequence)){let $=h+y.sequence.toLowerCase();l("Buffer:",$);let Y=k.get($);return Y?(l("Jumping to",Y),m?.requestFocus(Y),f(false),S(""),true):[...k.keys()].some(W=>W.startsWith($))?(S($),true):(S(""),true)}return true}return false};return u.subscribePriority(b)},[u,i,a,P,h,k,m,t,l]);let L=a?te.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:99998}},...E.map((b,y)=>{let C=B[y];if(!C)return null;let{x:p,y:G}=b.layout,z=C.startsWith(h)&&h.length>0;return te.createElement("box",{key:b.id,style:{position:"absolute",top:G,left:Math.max(0,p-C.length-2),bg:z?"cyan":r,color:o,paddingX:1,zIndex:99999,...n}},te.createElement("text",{style:{bold:true,color:o}},C))}),te.createElement("box",{style:{position:"absolute",bottom:0,left:0,right:0,bg:"blackBright",paddingX:1,zIndex:99999}},te.createElement("text",{style:{color:"white"}},h?`Jump: ${h}_`:"Press a key to jump \u2022 ESC to cancel"))):null;return te.createElement(te.Fragment,null,e,L)}function ko(e){let t=useContext(J),[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 No(e={}){let{disabled:t,onFocus:n,onBlur:r,onKeyPress:o}=e,s=useContext(J),i=useContext(Z),c=useRef(null),l=useRef(null),[a,f]=useState(false),h=useRef(n),S=useRef(r),R=useRef(o);h.current=n,S.current=r,R.current=o;let I=useCallback(m=>{c.current=m,m?l.current=m.focusId??null:l.current=null;},[]);useEffect(()=>{if(!(!s||!l.current||!c.current))return s.register(l.current,c.current)},[s]),useEffect(()=>{!s||!l.current||s.setSkippable(l.current,!!t);},[s,t]),useEffect(()=>{if(!s||!l.current)return;let m=l.current,g=s.focusedId===m;return f(g),s.onFocusChange(v=>{let P=v===m;f(H=>(P&&!H?h.current?.():!P&&H&&S.current?.(),P));})},[s]),useEffect(()=>{if(!i||!l.current||t)return;let m=l.current,g=v=>s?.focusedId!==m?false:R.current?.(v)===true;return i.registerInputHandler(m,g)},[i,s,t]);let u=useCallback(()=>{s&&l.current&&s.requestFocus(l.current);},[s]);return {ref:I,isFocused:a,focus:u,focusId:l.current}}function Eo(){let e=useContext(Se);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 Mo(){let e=useContext(J),t=useContext(oe),[n,r]=useState([]),o=useRef(()=>{}),s=useCallback(()=>{if(!e)return;let c=(e.getActiveElements?.()??e.getRegisteredElements?.()??[]).map(({id:l,node:a})=>({id:l,node:a,layout:t?.getLayout(a)??a.layout,type:a.type}));c.sort((l,a)=>l.layout.y!==a.layout.y?l.layout.y-a.layout.y:l.layout.x-a.layout.x),r(c);},[e,t]);return o.current=s,useEffect(()=>{if(!e)return;s();let i=e.onFocusChange(()=>{s();}),c=setTimeout(s,50);return ()=>{i(),clearTimeout(c);}},[e,t,s]),e?{elements:n,focusedId:e.focusedId,requestFocus:e.requestFocus,focusNext:e.focusNext,focusPrev:e.focusPrev,refresh:()=>o.current()}:null}function Ao(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 Vo(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 ne(e){let t=typeof e=="string"?{mask:e}:e,{mask:n,placeholder:r="_",showPlaceholder:o=false}=t,s=Ao(n);return (i,c)=>{let l=[];for(let h of i)(h!==r&&!/[\s\-\(\)\/\.\:]/.test(h)||/[a-zA-Z0-9]/.test(h))&&/[a-zA-Z0-9]/.test(h)&&l.push(h);let a="",f=0;for(let h of s)if(h.type==="literal")(f<l.length||o)&&(a+=h.char);else if(f<l.length){let S=l[f];if(Vo(S,h.type))a+=S,f++;else {f++;continue}}else o&&(a+=r);return a}}var Ho={usPhone:ne("(999) 999-9999"),intlPhone:ne("+9 999 999 9999"),dateUS:ne("99/99/9999"),dateEU:ne("99/99/9999"),dateISO:ne("9999-99-99"),time:ne("99:99"),timeFull:ne("99:99:99"),creditCard:ne("9999 9999 9999 9999"),ssn:ne("999-99-9999"),zip:ne("99999"),zipPlus4:ne("99999-9999"),ipv4:ne("999.999.999.999"),mac:ne("**:**:**:**:**:**")};export{xr as Box,Lr as Button,ao as Checkbox,go as DialogHost,pt as FocusScope,Rr as Input,So as JumpNav,Er as Keybind,wt as List,Wr as Menu,Br as Portal,Xr as Progress,po as Radio,$r as ScrollView,uo as Select,Nr as Spacer,Zr as Spinner,Sr as Text,lo as ToastHost,ne as createMask,Ho as masks,at as parseAnsi,hr as render,ft as stripAnsi,Eo as useApp,ho as useDialog,ko as useFocus,Mo as useFocusRegistry,No as useFocusable,Le as useInput,de as useLayout,so as useToast};//# sourceMappingURL=index.js.map
|
|
15
15
|
//# sourceMappingURL=index.js.map
|