@nick-skriabin/glyph 0.1.41 → 0.1.43

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 CHANGED
@@ -40,8 +40,8 @@ Build real terminal applications with React. Glyph provides a full component mod
40
40
  | | |
41
41
  |---|---|
42
42
  | **Flexbox Layout** | Full CSS-like flexbox via Yoga — rows, columns, wrapping, alignment, gaps, padding |
43
- | **Rich Components** | Box, Text, Input, Button, Checkbox, Radio, Select, ScrollView, List, Menu, Progress, Spinner, Toasts, Dialogs, Portal |
44
- | **Focus System** | Tab navigation, focus scopes, focus trapping for modals |
43
+ | **Rich Components** | Box, Text, Input, Button, Checkbox, Radio, Select, ScrollView, List, Menu, Progress, Spinner, Toasts, Dialogs, Portal, JumpNav |
44
+ | **Focus System** | Tab navigation, focus scopes, focus trapping for modals, JumpNav quick-jump hints |
45
45
  | **Keyboard Input** | `useInput` hook, declarative `<Keybind>` component, vim-style bindings |
46
46
  | **Smart Rendering** | Double-buffered framebuffer with character-level diffing &mdash; only changed cells are written |
47
47
  | **True Colors** | Named colors, hex, RGB, 256-palette. Auto-contrast text on colored backgrounds |
@@ -337,6 +337,44 @@ Renders children in a fullscreen absolute overlay. Useful for modals and dialogs
337
337
  </Portal>
338
338
  ```
339
339
 
340
+ ### `<JumpNav>`
341
+
342
+ Quick keyboard navigation to any focusable element. Press an activation key to show hint labels on all focusable elements, then type the hint to jump directly to that element. Similar to Vim's EasyMotion or browser extensions like Vimium.
343
+
344
+ ```tsx
345
+ function App() {
346
+ return (
347
+ <JumpNav activationKey="ctrl+o">
348
+ <Box style={{ flexDirection: "column", gap: 1 }}>
349
+ <Input placeholder="Name" />
350
+ <Input placeholder="Email" />
351
+ <Select items={countries} />
352
+ <Button onPress={submit}>Submit</Button>
353
+ </Box>
354
+ </JumpNav>
355
+ );
356
+ }
357
+ ```
358
+
359
+ **How it works:**
360
+ 1. Press `Ctrl+O` (or custom `activationKey`) to activate
361
+ 2. Hint labels (a, s, d, f...) appear next to each focusable element
362
+ 3. Type a hint to instantly focus that element
363
+ 4. Press `Escape` to cancel
364
+
365
+ **Props:**
366
+
367
+ | Prop | Type | Default | Description |
368
+ |------|------|---------|-------------|
369
+ | `activationKey` | `string` | `"ctrl+o"` | Key to activate jump mode |
370
+ | `hintChars` | `string` | `"asdfghjkl..."` | Characters used for hints |
371
+ | `hintBg` | `Color` | `"yellow"` | Hint label background |
372
+ | `hintFg` | `Color` | `"black"` | Hint label text color |
373
+ | `hintStyle` | `Style` | `{}` | Additional hint label styling |
374
+ | `enabled` | `boolean` | `true` | Enable/disable JumpNav |
375
+
376
+ **Focus scope aware:** JumpNav automatically respects `<FocusScope trap>`. When a modal with a focus trap is open, only elements inside that trap will show hints.
377
+
340
378
  ### `<Keybind>`
341
379
 
342
380
  Declarative keyboard shortcut. Renders nothing.
package/dist/index.d.ts CHANGED
@@ -421,10 +421,20 @@ interface AlertOptions {
421
421
  okText?: string;
422
422
  /** Style for the dialog box */
423
423
  style?: Style;
424
+ /** Base style for buttons */
425
+ buttonStyle?: Style;
426
+ /** Style for the OK button (merged with buttonStyle) */
427
+ okButtonStyle?: Style;
428
+ /** Style for focused button state (merged with button styles) */
429
+ focusedButtonStyle?: Style;
430
+ /** Style for the backdrop overlay */
431
+ backdropStyle?: Style;
424
432
  }
425
433
  interface ConfirmOptions extends AlertOptions {
426
434
  /** Text for the Cancel button (default: "Cancel") */
427
435
  cancelText?: string;
436
+ /** Style for the Cancel button (merged with buttonStyle) */
437
+ cancelButtonStyle?: Style;
428
438
  }
429
439
  interface DialogContextValue {
430
440
  /** Show an alert dialog. Returns a promise that resolves when dismissed. */
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
- import ee,{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 Lt(){return `glyph-focus-${Hn++}`}function Bt(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?Lt():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 Bt(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),a=parseInt(c[2]??"0",10);i={name:At(a),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),a=parseInt(c[1]??"1",10);i={name:At(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 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 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 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 a of o){let p=ue(a);p>l&&(l=p);}return {width:l,height:o.length}}let s=Math.max(1,Math.floor(t)),i=ce(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 ce(e,t,n){let r=[];for(let o of e){if(ue(o)<=t){r.push(o);continue}if(n==="truncate"){r.push(Xt(o,t));continue}if(n==="ellipsis"){r.push(Xn(o,t));continue}let i=Jn(o,t);r.push(...i);}return r}function Xt(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 Xn(e,t){if(t<=1)return t===1?"\u2026":"";let n=Xt(e,t-1);return ue(n)<ue(e)?n+"\u2026":e}function Jn(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,p=l===" ";if(a||p){if(s.length>0){if(o+i<=t)r+=s,o+=i;else if(i<=t)r.length>0&&n.push(r),r=s,o=i;else for(let d of s){let S=ue(d);o+S>t&&r.length>0&&(n.push(r),r="",o=0),r+=d,o+=S;}s="",i=0;}p&&(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:[""]}function Jt(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||Yt(i,s,i.style.zIndex??0,o);o.sort((i,c)=>i.zIndex-c.zIndex);for(let i of o){let c=Un(i.node,t,i.clip,n);c?.cursorPosition&&(r.cursorPosition=c.cursorPosition);}return r}function Yt(e,t,n,r){if(e.hidden)return;let o=e.style.zIndex??n,s=e.style.clip?Yn(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)Yt(i,s,o,r);}function Yn(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 Un(e,t,n,r={}){let{x:o,y:s,width:i,height:c,innerX:l,innerY:a,innerWidth:p,innerHeight:d}=e.layout,S=e.style;if(i<=0||c<=0)return;let I=_e(e).bg;if(S.bg)for(let u=s;u<s+c;u++)for(let R=o;R<o+i;R++)Xe(R,u,n)&&t.setChar(R,u," ",void 0,S.bg);let f=S.border?qt(S.border):null;if(f&&i>=2&&c>=2){let u=S.borderColor,R=I;ie(t,n,o,s,f.topLeft,u,R);for(let P=o+1;P<o+i-1;P++)ie(t,n,P,s,f.horizontal,u,R);ie(t,n,o+i-1,s,f.topRight,u,R),ie(t,n,o,s+c-1,f.bottomLeft,u,R);for(let P=o+1;P<o+i-1;P++)ie(t,n,P,s+c-1,f.horizontal,u,R);ie(t,n,o+i-1,s+c-1,f.bottomRight,u,R);for(let P=s+1;P<s+c-1;P++)ie(t,n,o,P,f.vertical,u,R),ie(t,n,o+i-1,P,f.vertical,u,R);}if(e.type==="text")Zn(e,t,n);else if(e.type==="input")return Qn(e,t,n,r)}function ie(e,t,n,r,o,s,i,c,l,a,p){Xe(n,r,t)&&e.setChar(n,r,o,s,i,c,l,a,p);}function Ut(e,t){if(e!==void 0)return e;if(t!==void 0)return ze(t)?"black":"white"}function Zn(e,t,n){let{innerX:r,innerY:o,innerWidth:s,innerHeight:i}=e.layout,c=_e(e),l=it(e);if(!l)return;let a=Ut(c.color,c.bg),p=e.style.wrap??"wrap",d=e.style.textAlign??"left",S=l.split(`
3
- `),v=ce(S,s,p);for(let I=0;I<v.length&&I<i;I++){let f=v[I],u=ue(f),R=0;d==="center"?R=Math.max(0,Math.floor((s-u)/2)):d==="right"&&(R=Math.max(0,s-u));let P=0;for(let E of f){let H=ue(E);H>0&&ie(t,n,r+R+P,o+I,E,a,c.bg,c.bold,c.dim,c.italic,c.underline),P+=H;}}}function Qn(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 p=e.props.value??e.props.defaultValue??"",d=e.props.placeholder??"",S=p||d,v=!p&&!!d,I=e.props.multiline??false,f=_e(e),u=Ut(f.color,f.bg),R=f.bg?ze(f.bg)?"blackBright":"whiteBright":"blackBright",P=v?R:u??f.color??e.style.color,E=v?R:P,H=v?true:f.dim,_=o&&o.nodeId===e.focusId,k;if(I&&!v){let G=e.style.wrap??"wrap",T=S.split(`
4
- `),B=ce(T,l,G),C=0,x=0;if(_){let b=o.position,M=0,$=b,K=0;for(let X=0;X<T.length;X++){let J=T[X].length;if(b<=K+J){M=X,$=b-K;break}K+=J+1;}let z=0;for(let X=0;X<M;X++)z+=ce([T[X]],l,G).length;let O=ce([T[M]],l,G),j=0,L=0;for(let X=0;X<O.length;X++){let J=O[X];if($<=j+J.length){L=X;break}j+=J.length;}C=z+L,x=ue(T[M].slice(j,j+($-j)));}let w=Math.max(0,C-a+1);for(let b=0;b<a;b++){let M=w+b;if(M>=B.length)break;let $=B[M],K=0;for(let z of $){if(K>=l)break;let O=ue(z);O>0&&ie(t,n,i+K,c+b,z,E,f.bg,f.bold,H,f.italic,f.underline),K+=O;}}if(_){let b=C-w;if(b>=0&&b<a){let M=Math.min(x,l-1),$=i+M,K=c+b;if(Xe($,K,n)&&$<i+l)if(s)k={cursorPosition:{x:$,y:K,bg:f.bg}};else {let z=t.get($,K),O=z?.ch&&z.ch!==" "?z.ch:"\u258C",j=f.bg??"black",L=f.color??"white";t.setChar($,K,O,j,L,z?.bold,z?.dim,z?.italic,false);}}}}else {let G=0;for(let T of S){if(G>=l)break;let B=ue(T);B>0&&ie(t,n,i+G,c,T,E,f.bg,f.bold,H,f.italic,f.underline),G+=B;}if(_){let T=Math.min(o.position,l-1),B=i+T;if(Xe(B,c,n)&&B<i+l)if(s)k={cursorPosition:{x:B,y:c,bg:f.bg}};else {let C=t.get(B,c),x=C?.ch&&C.ch!==" "?C.ch:"\u258C",w=f.bg??"black",b=f.color??"white";t.setChar(B,c,x,w,b,C?.bold,C?.dim,C?.italic,false);}}}return k}var er="\x1B",de=`${er}[`;function tr(e,t){return `${de}${t+1};${e+1}H`}function nr(e){let t=`${de}0m`;return e.bold&&(t+=`${de}1m`),e.dim&&(t+=`${de}2m`),e.italic&&(t+=`${de}3m`),e.underline&&(t+=`${de}4m`),e.fg!=null&&(t+=Ot(e.fg)),e.bg!=null&&(t+=Dt(e.bg)),t}function Zt(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 d=e.get(l,c);if(d&&t.cellsEqual(a,d))continue}(s!==c||o!==l)&&(r+=tr(l,c));let p=nr(a);p!==i&&(r+=p,i=p),r+=a.ch,o=l+1,s=c;}return r.length>0&&(r+=`${de}0m`),r}var ir={row:FlexDirection.Row,column:FlexDirection.Column},lr={"flex-start":Justify.FlexStart,center:Justify.Center,"flex-end":Justify.FlexEnd,"space-between":Justify.SpaceBetween,"space-around":Justify.SpaceAround},cr={"flex-start":Align.FlexStart,center:Align.Center,"flex-end":Align.FlexEnd,stretch:Align.Stretch};function tn(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 ur(e,t,n){tn(e,o=>e.setWidth(o),t.width),tn(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(ir[t.flexDirection]??FlexDirection.Column),t.flexWrap&&e.setFlexWrap(t.flexWrap==="wrap"?Wrap.Wrap:Wrap.NoWrap),t.justifyContent&&e.setJustifyContent(lr[t.justifyContent]??Justify.FlexStart),t.alignItems&&e.setAlignItems(cr[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 rn(e){let t=nn.Node.create();if(e.yogaNode=t,ur(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=on(e),zt(i,n,r,e.style.wrap??"wrap")});else for(let n=0;n<e.children.length;n++){let r=e.children[n];r.hidden||(rn(r),t.insertChild(r.yogaNode,t.getChildCount()));}}function on(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=on(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 sn(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,p=r.getComputedPadding(Edge.Top),d=r.getComputedPadding(Edge.Right),S=r.getComputedPadding(Edge.Bottom),v=r.getComputedPadding(Edge.Left),I=s+a+v,f=i+a+p,u=Math.max(0,c-a*2-v-d),R=Math.max(0,l-a*2-p-S);e.layout={x:s,y:i,width:c,height:l,innerX:I,innerY:f,innerWidth:u,innerHeight:R};for(let P of e.children)P.hidden||!P.yogaNode||sn(P,s,i);}function ln(e,t,n){let r=nn.Node.create();r.setWidth(t),r.setHeight(n),r.setFlexDirection(FlexDirection.Column);for(let o of e)o.hidden||(rn(o),r.insertChild(o.yogaNode,r.getChildCount()));r.calculateLayout(t,n,Direction.LTR);for(let o of e)o.hidden||!o.yogaNode||sn(o,0,0);r.freeRecursive(),cn(e);}function cn(e){for(let t of e)t.yogaNode=null,cn(t.children);}var Y=createContext(null),q=createContext(null),oe=createContext(null),be=createContext(null),Ye=createContext(null);function ar(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(m=>{_t(m),p=true,b();});let l=new Ne(i.columns,i.rows),a=new Ne(i.columns,i.rows),p=true,d=new Set,S=new Set,v=new Map,I={subscribe(m){return d.add(m),()=>d.delete(m)},subscribePriority(m){return S.add(m),()=>S.delete(m)},registerInputHandler(m,g){return v.set(m,g),()=>v.delete(m)}},f=null,u=new Map,R=[],P=new Set,E=[],H=new Set;function _(m){if(f!==m){f=m,b();for(let g of H)g(f);}}function k(){let m=[...R];if(E.length>0){let g=E[E.length-1];m=m.filter(y=>g.has(y));}return m=m.filter(g=>!P.has(g)),m.sort((g,y)=>{let D=u.get(g),W=u.get(y);if(!D||!W)return 0;let F=D.layout,h=W.layout;return F.y!==h.y?F.y-h.y:F.x-h.x}),m}let G={get focusedId(){return f},register(m,g){if(u.set(m,g),R.includes(m)||R.push(m),E.length>0&&E[E.length-1].add(m),f===null){let y=k();y.length>0&&_(y[0]);}return ()=>{u.delete(m);let y=R.indexOf(m);if(y!==-1&&R.splice(y,1),f===m){let D=k();_(D[0]??null);}}},requestFocus(m){_(m);},focusNext(){let m=k();if(m.length===0)return;let y=((f?m.indexOf(f):-1)+1)%m.length;_(m[y]);},focusPrev(){let m=k();if(m.length===0)return;let y=((f?m.indexOf(f):0)-1+m.length)%m.length;_(m[y]);},setSkippable(m,g){if(g){if(P.add(m),f===m){let y=k();y.length>0&&_(y[0]);}}else P.delete(m);},trapIds:null,pushTrap(m){return E.push(m),()=>{let g=E.indexOf(m);g!==-1&&E.splice(g,1);}},onFocusChange(m){return H.add(m),()=>{H.delete(m);}},getRegisteredElements(){let m=[];for(let g of R){if(P.has(g))continue;let y=u.get(g);y&&m.push({id:g,node:y});}return m},getActiveElements(){let m=k(),g=[];for(let y of m){if(P.has(y))continue;let D=u.get(y);D&&g.push({id:y,node:D});}return g}},T=new Map,B={getLayout(m){return m.layout},subscribe(m,g){return T.has(m)||T.set(m,new Set),T.get(m).add(g),()=>{let y=T.get(m);y&&(y.delete(g),y.size===0&&T.delete(m));}}},C={registerNode(){},unregisterNode(){},scheduleRender:b,exit(m){le.exit(m);},get columns(){return i.columns},get rows(){return i.rows}},x={type:"root",children:[],onCommit(){b();}},w=false;function b(){w||(w=true,queueMicrotask(()=>{w=false,M();}));}function M(){let m=i.columns,g=i.rows;(a.width!==m||a.height!==g)&&(a.resize(m,g),l.resize(m,g),p=true),ln(x.children,m,g),$(x.children);let y;if(f){let F=u.get(f);F?.type==="input"&&(y={nodeId:f,position:F.props.cursorPosition??F.props.value?.length??0});}let D=Jt(x.children,a,{cursorInfo:y,useNativeCursor:s}),W=Zt(l,a,p);if(W.length>0&&i.write(W),s)if(D.cursorPosition){let F=$t(D.cursorPosition.bg);i.setCursorColor(F),i.moveCursor(D.cursorPosition.x,D.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]};p=false;}function $(m){for(let g of m){let y=T.get(g);if(y)for(let D of y)D(g.layout);$(g.children);}}let K=i.onData(m=>{let g=jt(m);for(let y of g){if(y.ctrl&&y.name==="c"){le.exit();return}if(y.ctrl&&y.name==="z"){i.suspend(),process.kill(0,"SIGSTOP");return}if(y.name==="tab"&&!y.ctrl&&!y.alt){y.shift?G.focusPrev():G.focusNext();continue}let D=false;for(let W of S)if(W(y)){D=true;break}if(!D&&f){let W=v.get(f);W&&(D=W(y));}if(!D)for(let W of d)W(y);}}),z=i.onResize(()=>{p=true,b();}),O=()=>{i.resume(),p=true,b();};process.on("SIGCONT",O);let j=ee.createElement(be.Provider,{value:C},ee.createElement(Y.Provider,{value:I},ee.createElement(q.Provider,{value:G},ee.createElement(oe.Provider,{value:B},e)))),L=m=>{o&&console.error("Uncaught error:",m);},X=m=>{o&&console.error("Error caught by boundary:",m);},J=m=>{o&&console.error("Recoverable error:",m);},se=Ie.createContainer(x,0,null,false,null,"",L,X,J,null);Ie.updateContainer(j,se,null,null);let le={unmount(){Ie.updateContainer(null,se,null,null),K(),z(),process.off("SIGCONT",O),i.cleanup();},exit(m){le.unmount(),process.exit(m??0);}};return le}var dr=forwardRef(function({children:t,style:n,focusable:r},o){return ee.createElement("box",{style:n,focusable:r,ref:o},t)});var gr=forwardRef(function({children:t,style:n,wrap:r},o){let s=r?{...n,wrap:r}:n;return ee.createElement("text",{style:s,ref:o},t)});function un(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=ce([l],n,"wrap"),p=0;for(let d of a)o.push({text:d,logicalOffset:s+p}),p+=d.length;s+=l.length+1;}let i=0;for(let l=0;l<o.length;l++){let a=o[l],p=a.text.length,d=l+1<o.length&&o[l+1].logicalOffset!==a.logicalOffset+p,S=p+(d?1:0);if(t<i+p||l===o.length-1)return {visualLine:l,visualCol:Math.min(t-i,p),totalVisualLines:o.length,lineStartOffset:i,lineLength:p};i+=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 an(e,t,n,r){if(r<=0)return Math.min(n,e.length);let o=e.split(`
6
- `),s=[],i=0;for(let p of o){let d=ce([p],r,"wrap"),S=0;for(let v of d)s.push({text:v,startOffset:i+S}),S+=v.length;i+=p.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 Ge(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 Le(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 xr(e){let{value:t,defaultValue:n="",onChange:r,onKeyPress:o,onBeforeChange:s,placeholder:i,style:c,focusedStyle:l,multiline:a,autoFocus:p,type:d="text"}=e,[S,v]=useState(n),[I,f]=useState(n.length),[u,R]=useState(0),[P,E]=useState(false),[H,_]=useState(false),k=useContext(Y),G=useContext(q),T=useContext(oe),B=useRef(null),C=useRef(null),x=t!==void 0,w=x?t:S;useEffect(()=>{if(!T||!B.current)return;let O=T.getLayout(B.current);return R(O.innerWidth),T.subscribe(B.current,j=>{R(j.innerWidth);})},[T]);let b=useRef(w),M=useRef(I);useEffect(()=>{b.current=w,M.current>w.length&&(M.current=w.length,f(w.length));},[w]),useEffect(()=>{M.current=I;},[I]);let $=useRef({isControlled:x,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:a??false,innerWidth:u,type:d});$.current={isControlled:x,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:a??false,innerWidth:u,type:d},useEffect(()=>{if(!(!G||!C.current||!B.current))return G.register(C.current,B.current)},[G,H]);let K=useRef(false);useEffect(()=>{if(!H){K.current=false;return}if(p&&!K.current&&G&&C.current){K.current=true;let O=C.current,j=setTimeout(()=>{G.requestFocus(O);},0);return ()=>clearTimeout(j)}},[p,G,H]),useEffect(()=>{if(!G||!C.current)return;let O=C.current;return E(G.focusedId===O),G.onFocusChange(j=>{E(j===O);})},[G,H]),useEffect(()=>{if(!k||!C.current)return;let O=C.current,j=L=>{let{isControlled:X,onChange:J,onKeyPress:se,onBeforeChange:le,multiline:m}=$.current;if(se?.(L)===true)return true;let g=b.current,y=M.current;if(L.name==="escape")return false;let D=(h,N)=>{let V=h,Q=N;if(le){let A=le(h,g);if(A===false)return;typeof A=="string"&&(V=A,Q=A.length);}b.current=V,M.current=Q,X||v(V),J?.(V),f(Q);},W=h=>{M.current=h,f(h);};if(L.name==="return"){if(m){let h=g.slice(0,y)+`
8
- `+g.slice(y);return D(h,y+1),true}return false}if(L.ctrl){if(L.name==="w"){if(y>0){let h=y;for(;h>0&&g[h-1]===" ";)h--;for(;h>0&&g[h-1]!==" "&&(!m||g[h-1]!==`
9
- `);)h--;let N=g.slice(0,h)+g.slice(y);D(N,h);}return true}if(L.name==="a"){if(m){let{line:h,lines:N}=Ge(g,y);W(Le(N,h,0));}else W(0);return true}if(L.name==="e"){if(m){let{line:h,lines:N}=Ge(g,y);W(Le(N,h,N[h].length));}else W(g.length);return true}if(L.name==="k"){if(m){let{line:h,lines:N}=Ge(g,y),V=Le(N,h,N[h].length);if(y<V){let Q=g.slice(0,y)+g.slice(V);D(Q,y);}}else if(y<g.length){let h=g.slice(0,y);D(h,y);}return true}return false}if(L.alt){if(L.name==="left"||L.name==="b"){let h=y;for(;h>0&&g[h-1]===" ";)h--;for(;h>0&&g[h-1]!==" "&&g[h-1]!==`
10
- `;)h--;return W(h),true}if(L.name==="right"||L.name==="f"){let h=y;for(;h<g.length&&g[h]!==" "&&g[h]!==`
11
- `;)h++;for(;h<g.length&&g[h]===" ";)h++;return W(h),true}if(L.name==="backspace"||L.name==="d")if(L.name==="backspace"){if(y>0){let h=y;for(;h>0&&g[h-1]===" ";)h--;for(;h>0&&g[h-1]!==" "&&g[h-1]!==`
12
- `;)h--;let N=g.slice(0,h)+g.slice(y);D(N,h);}return true}else {if(y<g.length){let h=y;for(;h<g.length&&g[h]!==" "&&g[h]!==`
13
- `;)h++;for(;h<g.length&&g[h]===" ";)h++;let N=g.slice(0,y)+g.slice(h);D(N,y);}return true}return false}if(L.name==="left")return W(Math.max(0,y-1)),true;if(L.name==="right")return W(Math.min(g.length,y+1)),true;if(L.name==="up"){let{innerWidth:h}=$.current,N=un(g,y,h);return N.visualLine>0&&W(an(g,N.visualLine-1,N.visualCol,h)),true}if(L.name==="down"){let{innerWidth:h}=$.current,N=un(g,y,h);return N.visualLine<N.totalVisualLines-1&&W(an(g,N.visualLine+1,N.visualCol,h)),true}if(L.name==="home"){if(m){let{line:h,lines:N}=Ge(g,y);W(Le(N,h,0));}else W(0);return true}if(L.name==="end"){if(m){let{line:h,lines:N}=Ge(g,y);W(Le(N,h,N[h].length));}else W(g.length);return true}if(L.name==="backspace"){if(y>0){let h=g.slice(0,y-1)+g.slice(y);D(h,y-1);}return true}if(L.name==="delete"){if(y<g.length){let h=g.slice(0,y)+g.slice(y+1);D(h,y);}return true}if(L.name.length>1)return false;let F=L.sequence;if(F.length===1&&F.charCodeAt(0)>=32){let{type:h}=$.current;if(h==="number"){let V=/[0-9]/.test(F),Q=F==="."&&!g.includes("."),A=F==="-"&&y===0&&!g.includes("-");if(!V&&!Q&&!A)return true}let N=g.slice(0,y)+F+g.slice(y);return D(N,y+1),true}return false};return k.registerInputHandler(O,j)},[k,H]);let z={...c,...P&&l?l:{}};return ee.createElement("input",{style:z,value:w,defaultValue:n,placeholder:i,onChange:r,cursorPosition:I,multiline:a??false,focused:P,ref:O=>{O?(B.current=O,C.current=O.focusId,_(true)):(B.current=null,C.current=null,_(false));}})}function ft({trap:e=false,children:t}){let n=useContext(q),r=useRef(null),o=useRef(new Set);return useLayoutEffect(()=>{if(!e||!n)return;r.current=n.focusedId;let s=n.pushTrap(o.current);return ()=>{s(),r.current&&n.requestFocus(r.current);}},[e,n]),useEffect(()=>{if(!(!e||!n)&&o.current.size>0){let s=o.current.values().next().value;s&&n.requestFocus(s);}},[e,n]),ee.createElement(ee.Fragment,null,t)}function Rr({size:e}){return ee.createElement("box",{style:{flexGrow:e??1}})}function hn(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 gn(e,t){return !(t.name!==e.name||e.ctrl!==!!t.ctrl||e.alt!==!!t.alt||e.shift!==!!t.shift||e.meta!==!!t.meta)}function Ir({keypress:e,onPress:t,whenFocused:n,priority:r,disabled:o}){let s=useContext(Y),i=useContext(q),c=useRef(t);c.current=t;let l=useRef(hn(e));return l.current=hn(e),useEffect(()=>{if(!(!s||o))if(r){let a=p=>!gn(l.current,p)||n&&i?.focusedId!==n?false:(c.current(),true);return s.subscribePriority(a)}else {let a=p=>{gn(l.current,p)&&(n&&i?.focusedId!==n||c.current());};return s.subscribe(a)}},[s,i,n,r,o]),null}function Nr({children:e,zIndex:t=1e3}){return ee.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:t}},e)}function Er({onPress:e,style:t,focusedStyle:n,children:r,disabled:o}){let s=useContext(q),i=useContext(Y),c=useRef(null),l=useRef(null),a=useRef(e);a.current=e;let[p,d]=useState(false),[S,v]=useState(false);useEffect(()=>{if(!(!s||!l.current||!c.current||o))return s.register(l.current,c.current)},[s,o,p]),useEffect(()=>{if(!s||!l.current)return;let f=l.current;return v(s.focusedId===f),s.onFocusChange(u=>{v(u===f);})},[s,p]),useEffect(()=>{if(!i||!l.current||o)return;let f=l.current,u=R=>s?.focusedId!==f?false:R.name==="return"||R.name===" "||R.sequence===" "?(a.current?.(),true):false;return i.registerInputHandler(f,u)},[i,s,o,p]);let I={...t,...S&&n?n:{}};return ee.createElement("box",{style:I,focusable:!o,ref:f=>{f?(c.current=f,l.current=f.focusId,d(true)):(c.current=null,l.current=null,d(false));}},r)}var Lr={x:0,y:0,width:0,height:0,innerX:0,innerY:0,innerWidth:0,innerHeight:0};function fe(e){let t=useContext(oe),[n,r]=useState(Lr);return useEffect(()=>{if(!(!t||!e?.current))return r(t.getLayout(e.current)),t.subscribe(e.current,r)},[t,e]),n}function Be(e,t=[]){let n=useContext(Y);useEffect(()=>{if(n)return n.subscribe(e)},[n,...t]);}function Ar({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:p}){let d=n!==void 0,[S,v]=useState(o),I=d?n:S,f=useRef(null),u=useRef(null),R=fe(f),P=fe(u),E=useContext(q),H=useContext(oe),_=useRef(null);a&&!_.current&&(_.current=`scrollview-${Math.random().toString(36).slice(2,9)}`);let k=a?_.current:null;useEffect(()=>{if(!(!a||!k||!E||!f.current))return E.register(k,f.current)},[a,k,E]);let G=a&&k&&E?.focusedId===k,T=R.innerHeight,B=P.height,C=Math.max(0,B-T),x=Math.max(0,Math.min(I,C)),w=useMemo(()=>({getBounds:()=>{let A=R.y;return {visibleTop:A,visibleBottom:A+T,viewportHeight:T,scrollOffset:x}}}),[R.y,T,x]),b=useCallback(A=>{let re=Math.max(0,Math.min(A,C));d?r?.(re):v(re);},[d,r,C]);useEffect(()=>{I>C&&C>=0&&b(C);},[I,C,b]),useEffect(()=>!c||!E||!H||!u.current?void 0:E.onFocusChange(re=>{if(!re||!u.current)return;let Z=Ke=>{if(Ke.focusId===re)return Ke;for(let We of Ke.children){let ye=Z(We);if(ye)return ye}return null},pe=Z(u.current);if(!pe)return;let ge=H.getLayout(pe),Re=u.current.layout?.y??0,Oe=ge.y-Re,De=Oe+ge.height,ve=I,ot=I+T;Oe<ve?b(Oe):De>ot&&b(De-T);}),[c,E,H,I,T,b]);let M=useCallback(()=>{if(!E)return false;let A=E.focusedId;if(!A)return false;if(a&&k&&A===k)return true;if(!u.current)return false;let re=Z=>{if(Z.focusId===A)return true;for(let pe of Z.children)if(re(pe))return true;return false};return re(u.current)},[E,a,k]);Be(A=>{if(i||!M())return;let re=Math.max(1,Math.floor(T/2)),Z=Math.max(1,T);switch(A.name){case "pageup":b(I-Z);break;case "pagedown":b(I+Z);break;default:A.ctrl&&(A.name==="d"?b(I+re):A.name==="u"?b(I-re):A.name==="f"?b(I+Z):A.name==="b"&&b(I-Z));break}},[I,s,T,C,i,b,M]);let{padding:$,paddingX:K,paddingY:z,paddingTop:O,paddingRight:j,paddingBottom:L,paddingLeft:X,...J}=t??{},le=J.border!=null&&J.border!=="none"?2:0,m=B>0?B+le:void 0,g={...J,...G?p:{},clip:true,...J.height===void 0&&m!==void 0?{height:m,flexShrink:J.flexShrink??1,minHeight:J.minHeight??0}:{}},y={position:"absolute",top:-x,left:0,right:0,flexDirection:"column",...$!==void 0&&{padding:$},...K!==void 0&&{paddingX:K},...z!==void 0&&{paddingY:z},...O!==void 0&&{paddingTop:O},...j!==void 0&&{paddingRight:j},...L!==void 0&&{paddingBottom:L},...X!==void 0&&{paddingLeft:X}},D=B>T&&T>0,W=l&&D,F=Math.max(1,Math.floor(T/B*T)),h=B-T,N=h>0?Math.floor(x/h*(T-F)):0,V=[];if(W)for(let A=0;A<T;A++)A>=N&&A<N+F?V.push("\u2588"):V.push("\u2591");let Q={position:"absolute",top:0,right:0,width:1,height:T,flexDirection:"column"};return ee.createElement(Ye.Provider,{value:w},ee.createElement("box",{style:g,ref:A=>{f.current=A??null;},...a?{focusable:true,focusId:k}:{}},ee.createElement("box",{style:{...y,paddingRight:W?(y.paddingRight??0)+1:y.paddingRight},ref:A=>{u.current=A??null;}},e),W&&ee.createElement("box",{style:Q},ee.createElement("text",{style:{color:"blackBright"}},V.join(`
14
- `)))))}function Ct({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,[p,d]=useState(s),S=a?n:p,v=useContext(q),I=useContext(Y),f=useRef(null),u=useRef(null),R=useRef(o);R.current=o;let[P,E]=useState(false),[H,_]=useState(false),k=useRef(null),G=useCallback(x=>{let w=Math.max(0,Math.min(x,e-1));a?r?.(w):d(w);},[a,r,e]),T=useCallback((x,w)=>{if(!i||i.size===0)return Math.max(0,Math.min(x+w,e-1));let b=x+w;for(;b>=0&&b<e&&i.has(b);)b+=w;return b<0||b>=e?x:b},[i,e]);useEffect(()=>{if(!(!v||!u.current||!f.current||!l))return v.register(u.current,f.current)},[v,l,P]),useEffect(()=>{if(!v||!u.current)return;let x=u.current;return _(v.focusedId===x),v.onFocusChange(w=>{_(w===x);})},[v,P]);let B=useCallback(x=>{let w=x?e-1:0,b=x?-1:1,M=w;for(;M>=0&&M<e&&i?.has(M);)M+=b;return M>=0&&M<e?M:x?e-1:0},[i,e]);useEffect(()=>{if(!I||!u.current||!l)return;let x=u.current,w=b=>v?.focusedId!==x?false:b.name==="g"&&!b.ctrl&&!b.alt?k.current==="g"?(G(B(false)),k.current=null,true):(k.current="g",true):b.name==="G"||b.name==="g"&&b.shift?(k.current=null,G(B(true)),true):(k.current=null,b.name==="up"||b.name==="k"?(G(T(S,-1)),true):b.name==="down"||b.name==="j"?(G(T(S,1)),true):b.name==="return"?(i?.has(S)||R.current?.(S),true):false);return I.registerInputHandler(x,w)},[I,v,l,S,G,T,B,i,P]);let C=[];for(let x=0;x<e;x++)C.push(ee.createElement(ee.Fragment,{key:x},t({index:x,selected:x===S,focused:H})));return ee.createElement("box",{style:{flexDirection:"column",...c},focusable:l,ref:x=>{x?(f.current=x,u.current=x.focusId,E(true)):(f.current=null,u.current=null,E(false));}},...C)}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 p=0;p<e.length;p++)e[p].disabled&&l.add(p);let a=p=>{let d=e[p];d&&!d.disabled&&r?.(d.value,p);};return ee.createElement(Ct,{count:e.length,selectedIndex:t,onSelectionChange:n,onSelect:a,defaultSelectedIndex:o,disabledIndices:l.size>0?l:void 0,style:s,focusable:c,renderItem:({index:p,selected:d,focused:S})=>{let v=e[p],I=v.disabled,f=d&&S,u=d?">":" ";return ee.createElement("box",{style:{flexDirection:"row",...f?{bg:i}:{}}},ee.createElement("text",{style:f?{bold:true,color:"black"}:I?{dim:true}:{}},`${u} ${v.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),p=fe(l).innerWidth,[d,S]=useState(0);useEffect(()=>{if(!t)return;let R=setInterval(()=>{S(P=>(P+1)%Math.max(1,p+6));},100);return ()=>clearInterval(R)},[t,p]);let v=Math.max(0,Math.min(1,e??0)),I=o?` ${Math.round(v*100)}%`:"",f="";if(p>0)if(t&&e===void 0){let R=Math.max(1,Math.min(3,Math.floor(p/4))),P=[];for(let E=0;E<p;E++)E>=d-R&&E<d?P.push(i):P.push(c);f=P.join("");}else {let R=Math.round(v*p);f=i.repeat(R)+c.repeat(p-R);}let u=[];return r&&u.push(ee.createElement("text",{key:"label",style:{bold:true}},r+" ")),u.push(ee.createElement("box",{key:"track",style:{flexGrow:1,flexShrink:1},ref:R=>{l.current=R??null;}},ee.createElement("text",{key:"bar",style:{}},f))),o&&u.push(ee.createElement("text",{key:"pct",style:{bold:true}},I)),ee.createElement("box",{style:{flexDirection:"row",width:n,...s}},...u)}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=[ee.createElement("text",{key:"frame",style:r},e[o])];return n&&i.push(ee.createElement("text",{key:"label",style:{}}," "+n)),ee.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(v=>{let I=`toast-${Qr++}`,f={id:I,durationMs:3e3,variant:"info",...v};if(o(u=>[...u,f]),f.durationMs&&f.durationMs>0){let u=setTimeout(()=>{s.current.delete(I),o(R=>R.filter(P=>P.id!==I));},f.durationMs);s.current.set(I,u);}},[]);useEffect(()=>()=>{for(let v of s.current.values())clearTimeout(v);s.current.clear();},[]);let c=useRef({push:i});c.current.push=i;let l=e.startsWith("top"),a=e.endsWith("right"),p={position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:900,flexDirection:"column",justifyContent:l?"flex-start":"flex-end",alignItems:a?"flex-end":"flex-start",padding:1},S=r.slice(-t).map(v=>{let I=v.variant??"info",f=to[I],u=[];return v.title&&u.push(ee.createElement("text",{key:"title",style:{bold:true,color:f.title}},v.title)),u.push(ee.createElement("text",{key:"msg",style:{color:f.text}},v.message)),ee.createElement("box",{key:v.id,style:{bg:f.bg,paddingX:1,flexDirection:"column",minWidth:20,maxWidth:50}},...u)});return ee.createElement(Rn.Provider,{value:c.current},n,S.length>0?ee.createElement("box",{style:p},...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:a=true,disabled:p}){let d=useContext(q),S=useContext(Y),v=useContext(be),I=useContext(Ye),f=useRef(null),u=useRef(null),R=useRef(n);R.current=n;let[P,E]=useState(false),[H,_]=useState(false),[k,G]=useState(false),[T,B]=useState(0),[C,x]=useState(""),[w,b]=useState(0),M=fe(f),$=v?.rows??24,K=I?.getBounds(),O=e.find(F=>F.value===t)?.label??"",j=useMemo(()=>{if(!C)return e;let F=C.toLowerCase();return e.filter(h=>h.label.toLowerCase().includes(F))},[e,C]),L=Math.min(l,j.length),X=j.slice(w,w+L);useEffect(()=>{B(0),b(0);},[C]),useEffect(()=>{!H&&k&&(G(false),x(""));},[H,k]),useEffect(()=>{if(!(!d||!u.current||!f.current))return d.register(u.current,f.current)},[d,P]),useEffect(()=>{!d||!u.current||d.setSkippable(u.current,!!p);},[d,p,P]),useEffect(()=>{if(!d||!u.current)return;let F=u.current;return _(d.focusedId===F),d.onFocusChange(h=>{_(h===F);})},[d,P]);let J=useCallback((F,h)=>{let N=F+h;for(;N>=0&&N<j.length;){if(!j[N].disabled)return N;N+=h;}return F},[j]),se=useCallback(F=>{F<w?b(F):F>=w+L&&b(F-L+1);},[w,L]);useEffect(()=>{if(!S||!u.current||p)return;let F=u.current,h=N=>{if(d?.focusedId!==F)return false;if(!k){if(N.name==="return"||N.name===" "||N.sequence===" "||N.name==="down"){G(true),x("");let V=j.findIndex(A=>A.value===t),Q=V>=0?V:0;return B(Q),b(Math.max(0,Q-Math.floor(l/2))),true}return false}if(N.name==="tab")return G(false),x(""),false;if(N.name==="escape")return G(false),x(""),true;if(N.name==="return"){let V=j[T];return V&&!V.disabled&&(R.current?.(V.value),G(false),x("")),true}if(N.name==="up"){let V=J(T,-1);return B(V),se(V),true}if(N.name==="down"){let V=J(T,1);return B(V),se(V),true}if(N.name==="backspace")return a&&C.length>0&&x(V=>V.slice(0,-1)),true;if(N.name==="home"){let V=J(-1,1);return B(V),se(V),true}if(N.name==="end"){let V=J(j.length,-1);return B(V),se(V),true}if(a&&N.sequence&&N.sequence.length===1&&!N.ctrl&&!N.alt){let V=N.sequence;if(V>=" "&&V<="~")return x(Q=>Q+V),true}return true};return S.registerInputHandler(F,h)},[S,d,p,k,T,j,t,l,a,C,J,se,P]);let m={flexDirection:"row",width:"100%",...!o?.bg&&o?.border===void 0?{border:"single"}:{},...o,...H&&s?s:{}},g=O?o?.color??void 0:"blackBright",y=[ee.createElement("text",{key:"label",style:{flexGrow:1,flexShrink:1,color:g,wrap:"ellipsis",...O?{}:{dim:true}}},O||r),ee.createElement("text",{key:"arrow",style:{flexShrink:0,color:H?c:"blackBright"}},k?" \u25B2":" \u25BC")],D=null;if(k){let F=[];a&&C&&F.push(ee.createElement("box",{key:"search",style:{paddingX:1}},ee.createElement("text",{style:{color:"blackBright",dim:true}},`/${C}`))),j.length===0&&F.push(ee.createElement("box",{key:"empty",style:{paddingX:1}},ee.createElement("text",{style:{dim:true,color:"blackBright"}},"No matches"))),w>0&&F.push(ee.createElement("box",{key:"scroll-up",style:{justifyContent:"center",alignItems:"center"}},ee.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25B2"))),X.forEach((ve,ot)=>{let We=w+ot===T,ye=ve.disabled,Mn={paddingX:1,...We&&!ye?{bg:c}:{}},Vn={...We&&!ye?{color:"black",bold:true}:{},...ye?{dim:true,color:"blackBright"}:{}};F.push(ee.createElement("box",{key:`item-${ve.value}`,style:Mn},ee.createElement("text",{style:Vn},ve.label)));}),w+L<j.length&&F.push(ee.createElement("box",{key:"scroll-down",style:{justifyContent:"center",alignItems:"center"}},ee.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25BC")));let h=w>0,N=w+L<j.length,V=a&&C,Q=j.length===0,A=!i?.bg&&i?.border===void 0,Z=L+(A?2:0);h&&(Z+=1),N&&(Z+=1),V&&(Z+=1),Q&&(Z+=1);let pe=M.y+M.height,ge,Re;K?(ge=K.visibleBottom-pe,Re=M.y-K.visibleTop):(ge=$-pe,Re=M.y);let De=ge<Z&&Re>=Z?-Z:M.height||1;D=ee.createElement("box",{style:{position:"absolute",top:De,left:0,right:0,zIndex:9999,...A?{border:"single"}:{},bg:"black",flexDirection:"column",...i}},...F);}let W={flexDirection:"column",width:m.width??"100%",minWidth:m.minWidth,maxWidth:m.maxWidth,flexGrow:m.flexGrow,flexShrink:m.flexShrink??1};return ee.createElement("box",{style:W},ee.createElement("box",{style:m,focusable:true,ref:F=>{F?(f.current=F,u.current=F.focusId,E(true)):(f.current=null,u.current=null,E(false));}},...y),D)}function so({checked:e,onChange:t,label:n,style:r,focusedStyle:o,disabled:s,checkedChar:i="\u2713",uncheckedChar:c=" "}){let l=useContext(q),a=useContext(Y),p=useRef(null),d=useRef(null),S=useRef(t);S.current=t;let v=useRef(e);v.current=e;let[I,f]=useState(false),[u,R]=useState(false);useEffect(()=>{if(!(!l||!d.current||!p.current||s))return l.register(d.current,p.current)},[l,s,I]),useEffect(()=>{if(!l||!d.current)return;let k=d.current;return R(l.focusedId===k),l.onFocusChange(G=>{R(G===k);})},[l,I]),useEffect(()=>{if(!a||!d.current||s)return;let k=d.current,G=T=>l?.focusedId!==k?false:T.name==="return"||T.name===" "||T.sequence===" "?(S.current(!v.current),true):false;return a.registerInputHandler(k,G)},[a,l,s,I]);let P={flexDirection:"row",gap:1,...r,...u&&o?o:{}},E=e?i:c,H={color:s?"blackBright":u?"white":r?.color},_={color:s?"blackBright":r?.color};return ee.createElement("box",{style:P,focusable:!s,ref:k=>{k?(p.current=k,d.current=k.focusId,f(true)):(p.current=null,d.current=null,f(false));}},ee.createElement("text",{key:"box",style:H},`[${E}]`),n?ee.createElement("text",{key:"label",style:_},n):null)}function lo({items:e,value:t,onChange:n,style:r,itemStyle:o,focusedItemStyle:s,selectedItemStyle:i,disabled:c,direction:l="column",gap:a=0,selectedChar:p="\u25CF",unselectedChar:d="\u25CB"}){let S=useContext(q),v=useContext(Y),I=useRef(null),f=useRef(null),u=useRef(n);u.current=n;let[R,P]=useState(false),[E,H]=useState(false),[_,k]=useState(()=>{let C=e.findIndex(x=>x.value===t);return C>=0?C:e.findIndex(x=>!x.disabled)}),G=useCallback((C,x)=>{let w=C;for(let b=0;b<e.length;b++)if(w=(w+x+e.length)%e.length,!e[w]?.disabled)return w;return C},[e]);useEffect(()=>{if(!(!S||!f.current||!I.current||c))return S.register(f.current,I.current)},[S,c,R]),useEffect(()=>{if(!S||!f.current)return;let C=f.current;return H(S.focusedId===C),S.onFocusChange(x=>{H(x===C);})},[S,R]),useEffect(()=>{if(!v||!f.current||c)return;let C=f.current,x=w=>{if(S?.focusedId!==C)return false;if(w.name==="up"||w.name==="left"||w.name==="k"||w.name==="tab"&&w.shift)return k(b=>G(b,-1)),true;if(w.name==="down"||w.name==="right"||w.name==="j"||w.name==="tab"&&!w.shift)return k(b=>G(b,1)),true;if(w.name==="return"||w.name===" "||w.sequence===" "){let b=e[_];return b&&!b.disabled&&u.current(b.value),true}return false};return v.registerInputHandler(C,x)},[v,S,c,e,_,G,R]),useEffect(()=>{let C=e.findIndex(x=>x.value===t);C>=0&&k(C);},[t,e]);let T={flexDirection:l,gap:a,...r},B=e.map((C,x)=>{let w=C.value===t,b=x===_,M=c||C.disabled,$=w?p:d,K={flexDirection:"row",gap:1,...o};w&&i&&(K={...K,...i}),E&&b&&s&&(K={...K,...s});let z=M?"blackBright":E&&b?s?.color??"white":w?i?.color??o?.color:o?.color;return ee.createElement("box",{key:x,style:K},ee.createElement("text",{key:"radio",style:{color:z}},`(${$})`),ee.createElement("text",{key:"label",style:{color:z}},C.label))});return ee.createElement("box",{style:T,focusable:!c,ref:C=>{C?(I.current=C,f.current=C.focusId,P(true)):(I.current=null,f.current=null,P(false));}},...B)}var kn=createContext(null);function uo(){let e=useContext(kn);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((a,p)=>new Promise(d=>{let S=++r.current;n(v=>[...v,{id:S,type:"alert",content:a,okText:p?.okText??"OK",cancelText:"",style:p?.style,resolve:()=>d()}]);}),[]),s=useCallback((a,p)=>new Promise(d=>{let S=++r.current;n(v=>[...v,{id:S,type:"confirm",content:a,okText:p?.okText??"OK",cancelText:p?.cancelText??"Cancel",style:p?.style,resolve:d}]);}),[]),i=useCallback((a,p)=>{n(d=>{let S=d.find(v=>v.id===a);return S&&S.resolve(p),d.filter(v=>v.id!==a)});},[]),c={alert:o,confirm:s},l=t[t.length-1];return ee.createElement(kn.Provider,{value:c},e,l&&ee.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"),[a,p]=useState(0);useEffect(()=>{if(!n||a===0)return;let u=[];return r.current&&s.current&&u.push(n.register(s.current,r.current)),o.current&&i.current&&u.push(n.register(i.current,o.current)),s.current&&n.requestFocus(s.current),()=>u.forEach(R=>R())},[n,a]),useEffect(()=>{if(n)return n.onFocusChange(u=>{u===s.current?l("ok"):u===i.current&&l("cancel");})},[n]),Be(u=>{if(u.name==="return"||u.name==="space"){e.type==="alert"?t(e.id,true):t(e.id,c==="ok");return}if(u.name==="escape"){t(e.id,false);return}e.type==="confirm"&&n&&(u.name==="left"||u.name==="right")&&(c==="ok"&&i.current?n.requestFocus(i.current):s.current&&n.requestFocus(s.current));},[e,c,n,t]);let d=typeof e.content=="string",S=d?e.content.length:0,I={minWidth:Math.max(20,d?Math.min(S+6,50):30),maxWidth:50,bg:"black",border:"round",borderColor:"white",padding:1,flexDirection:"column",gap:1,...e.style},f=u=>({paddingX:2,bg:u?"white":"blackBright",color:u?"black":"white",bold:u});return ee.createElement(ft,{trap:true},ee.createElement("box",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:999}}),ee.createElement("box",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,justifyContent:"center",alignItems:"center",zIndex:1e3}},ee.createElement("box",{style:I},ee.createElement("box",{style:{flexDirection:"column"}},typeof e.content=="string"?ee.createElement("text",null,e.content):e.content),ee.createElement("box",{style:{flexDirection:"row",justifyContent:"flex-end",gap:1}},e.type==="confirm"&&ee.createElement("box",{style:f(c==="cancel"),focusable:true,ref:u=>{u&&u.focusId&&!i.current&&(o.current=u,i.current=u.focusId,p(R=>R+1));}},ee.createElement("text",null,e.cancelText)),ee.createElement("box",{style:f(c==="ok"),focusable:true,ref:u=>{u&&u.focusId&&!s.current&&(r.current=u,s.current=u.focusId,p(R=>R+1));}},ee.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?(...C)=>console.error("[JumpNav]",...C):()=>{},[a,p]=useState(false),[d,S]=useState(""),[v,I]=useState([]),f=useContext(Y),u=useContext(q),R=useContext(oe);useEffect(()=>{l("Mounted, inputCtx:",!!f,"focusCtx:",!!u,"enabled:",i);},[]);let E=useCallback(C=>{let x=C.toLowerCase().split("+");return {ctrl:x.includes("ctrl"),alt:x.includes("alt"),shift:x.includes("shift"),meta:x.includes("meta"),name:x[x.length-1]??""}},[])(t),H=useCallback(()=>{if(!u?.getActiveElements){l("refreshElements: no getActiveElements");return}let C=u.getActiveElements();l("getActiveElements returned",C.length,"elements");let x=C.map(({id:w,node:b})=>({id:w,node:b,layout:R?.getLayout(b)??b.layout}));x.sort((w,b)=>w.layout.y!==b.layout.y?w.layout.y-b.layout.y:w.layout.x-b.layout.x),I(x);},[u,R,l]),_=useRef(false);useEffect(()=>{a&&!_.current&&(l("Activated! Refreshing elements..."),H()),_.current=a;},[a,H,l]);let k=v.filter(C=>C.layout.width>0&&C.layout.height>0),G=ho(k.length,s),T=useMemo(()=>{let C=new Map;return k.forEach((x,w)=>{G[w]&&C.set(G[w],x.id);}),C},[k,G]);useEffect(()=>{if(!f||!i){l("Not subscribing - inputCtx:",!!f,"enabled:",i);return}l("Subscribing to priority input, activation key:",t);let C=x=>{let w=x.name===E.name,b=!!x.ctrl===E.ctrl,M=!!x.alt===E.alt,$=!!x.shift===E.shift,K=!!x.meta===E.meta;if(!a&&w&&b&&M&&$&&K)return l("Activation key matched! Activating..."),p(true),S(""),true;if(a){if(x.name==="escape")return l("Escape pressed, deactivating"),p(false),S(""),true;if(x.name==="backspace")return S(""),true;if(x.sequence&&x.sequence.length===1&&/[a-z]/i.test(x.sequence)){let z=d+x.sequence.toLowerCase();l("Buffer:",z);let O=T.get(z);return O?(l("Jumping to",O),u?.requestFocus(O),p(false),S(""),true):[...T.keys()].some(L=>L.startsWith(z))?(S(z),true):(S(""),true)}return true}return false};return f.subscribePriority(C)},[f,i,a,E,d,T,u,t,l]);let B=a?ee.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:99998}},...k.map((C,x)=>{let w=G[x];if(!w)return null;let{x:b,y:M}=C.layout,$=w.startsWith(d)&&d.length>0;return ee.createElement("box",{key:C.id,style:{position:"absolute",top:M,left:Math.max(0,b-w.length-2),bg:$?"cyan":r,color:o,paddingX:1,zIndex:99999,...n}},ee.createElement("text",{style:{bold:true,color:o}},w))}),ee.createElement("box",{style:{position:"absolute",bottom:0,left:0,right:0,bg:"blackBright",paddingX:1,zIndex:99999}},ee.createElement("text",{style:{color:"white"}},d?`Jump: ${d}_`:"Press a key to jump \u2022 ESC to cancel"))):null;return ee.createElement(ee.Fragment,null,e,B)}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(Y),c=useRef(null),l=useRef(null),[a,p]=useState(false),d=useRef(n),S=useRef(r),v=useRef(o);d.current=n,S.current=r,v.current=o;let I=useCallback(u=>{c.current=u,u?l.current=u.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 u=l.current,R=s.focusedId===u;return p(R),s.onFocusChange(P=>{let E=P===u;p(H=>(E&&!H?d.current?.():!E&&H&&S.current?.(),E));})},[s]),useEffect(()=>{if(!i||!l.current||t)return;let u=l.current,R=P=>s?.focusedId!==u?false:v.current?.(P)===true;return i.registerInputHandler(u,R)},[i,s,t]);let f=useCallback(()=>{s&&l.current&&s.requestFocus(l.current);},[s]);return {ref:I,isFocused:a,focus:f,focusId:l.current}}function Io(){let e=useContext(be);if(!e)throw new Error("useApp must be used within a Glyph render tree");return {exit:e.exit,get columns(){return e.columns},get rows(){return e.rows}}}function ko(){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: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 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 te(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 d of i)(d!==r&&!/[\s\-\(\)\/\.\:]/.test(d)||/[a-zA-Z0-9]/.test(d))&&/[a-zA-Z0-9]/.test(d)&&l.push(d);let a="",p=0;for(let d of s)if(d.type==="literal")(p<l.length||o)&&(a+=d.char);else if(p<l.length){let S=l[p];if(Go(S,d.type))a+=S,p++;else {p++;continue}}else o&&(a+=r);return a}}var Lo={usPhone:te("(999) 999-9999"),intlPhone:te("+9 999 999 9999"),dateUS:te("99/99/9999"),dateEU:te("99/99/9999"),dateISO:te("9999-99-99"),time:te("99:99"),timeFull:te("99:99:99"),creditCard:te("9999 9999 9999 9999"),ssn:te("999-99-9999"),zip:te("99999"),zipPlus4:te("99999-9999"),ipv4:te("999.999.999.999"),mac:te("**:**:**:**:**:**")};export{dr as Box,Er 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,Nr 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,te as createMask,Lo as masks,ar as render,Io as useApp,uo as useDialog,So as useFocus,ko as useFocusRegistry,Ro as useFocusable,Be as useInput,fe as useLayout,eo as useToast};//# sourceMappingURL=index.js.map
1
+ import ee,{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 u of o){let f=ue(u);f>l&&(l=f);}return {width:l,height:o.length}}let s=Math.max(1,Math.floor(t)),i=ce(o,s,r),c=0;for(let l of i){let u=ue(l);u>c&&(c=u);}return {width:c,height:i.length}}function ce(e,t,n){let r=[];for(let o of e){if(ue(o)<=t){r.push(o);continue}if(n==="truncate"){r.push(Xt(o,t));continue}if(n==="ellipsis"){r.push(Xn(o,t));continue}let i=Jn(o,t);r.push(...i);}return r}function Xt(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 Xn(e,t){if(t<=1)return t===1?"\u2026":"";let n=Xt(e,t-1);return ue(n)<ue(e)?n+"\u2026":e}function Jn(e,t){let n=[],r="",o=0,s="",i=0;for(let c=0;c<=e.length;c++){let l=e[c],u=c===e.length,f=l===" ";if(u||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 p of s){let w=ue(p);o+w>t&&r.length>0&&(n.push(r),r="",o=0),r+=p,o+=w;}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:[""]}function Jt(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||Yt(i,s,i.style.zIndex??0,o);o.sort((i,c)=>i.zIndex-c.zIndex);for(let i of o){let c=Un(i.node,t,i.clip,n);c?.cursorPosition&&(r.cursorPosition=c.cursorPosition);}return r}function Yt(e,t,n,r){if(e.hidden)return;let o=e.style.zIndex??n,s=e.style.clip?Yn(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)Yt(i,s,o,r);}function Yn(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 Un(e,t,n,r={}){let{x:o,y:s,width:i,height:c,innerX:l,innerY:u,innerWidth:f,innerHeight:p}=e.layout,w=e.style;if(i<=0||c<=0)return;let T=_e(e).bg;if(w.bg)for(let d=s;d<s+c;d++)for(let y=o;y<o+i;y++)Xe(y,d,n)&&t.setChar(y,d," ",void 0,w.bg);let a=w.border?qt(w.border):null;if(a&&i>=2&&c>=2){let d=w.borderColor,y=T;ie(t,n,o,s,a.topLeft,d,y);for(let I=o+1;I<o+i-1;I++)ie(t,n,I,s,a.horizontal,d,y);ie(t,n,o+i-1,s,a.topRight,d,y),ie(t,n,o,s+c-1,a.bottomLeft,d,y);for(let I=o+1;I<o+i-1;I++)ie(t,n,I,s+c-1,a.horizontal,d,y);ie(t,n,o+i-1,s+c-1,a.bottomRight,d,y);for(let I=s+1;I<s+c-1;I++)ie(t,n,o,I,a.vertical,d,y),ie(t,n,o+i-1,I,a.vertical,d,y);}if(e.type==="text")Zn(e,t,n);else if(e.type==="input")return Qn(e,t,n,r)}function ie(e,t,n,r,o,s,i,c,l,u,f){Xe(n,r,t)&&e.setChar(n,r,o,s,i,c,l,u,f);}function Ut(e,t){if(e!==void 0)return e;if(t!==void 0)return ze(t)?"black":"white"}function Zn(e,t,n){let{innerX:r,innerY:o,innerWidth:s,innerHeight:i}=e.layout,c=_e(e),l=it(e);if(!l)return;let u=Ut(c.color,c.bg),f=e.style.wrap??"wrap",p=e.style.textAlign??"left",w=l.split(`
3
+ `),v=ce(w,s,f);for(let T=0;T<v.length&&T<i;T++){let a=v[T],d=ue(a),y=0;p==="center"?y=Math.max(0,Math.floor((s-d)/2)):p==="right"&&(y=Math.max(0,s-d));let I=0;for(let P of a){let H=ue(P);H>0&&ie(t,n,r+y+I,o+T,P,u,c.bg,c.bold,c.dim,c.italic,c.underline),I+=H;}}}function Qn(e,t,n,r={}){let{cursorInfo:o,useNativeCursor:s}=r,{innerX:i,innerY:c,innerWidth:l,innerHeight:u}=e.layout;if(l<=0||u<=0)return;let f=e.props.value??e.props.defaultValue??"",p=e.props.placeholder??"",w=f||p,v=!f&&!!p,T=e.props.multiline??false,a=_e(e),d=Ut(a.color,a.bg),y=a.bg?ze(a.bg)?"blackBright":"whiteBright":"blackBright",I=v?y:d??a.color??e.style.color,P=v?y:I,H=v?true:a.dim,O=o&&o.nodeId===e.focusId,E;if(T&&!v){let G=e.style.wrap??"wrap",k=w.split(`
4
+ `),L=ce(k,l,G),S=0,b=0;if(O){let C=o.position,M=0,$=C,W=0;for(let X=0;X<k.length;X++){let J=k[X].length;if(C<=W+J){M=X,$=C-W;break}W+=J+1;}let z=0;for(let X=0;X<M;X++)z+=ce([k[X]],l,G).length;let D=ce([k[M]],l,G),j=0,B=0;for(let X=0;X<D.length;X++){let J=D[X];if($<=j+J.length){B=X;break}j+=J.length;}S=z+B,b=ue(k[M].slice(j,j+($-j)));}let R=Math.max(0,S-u+1);for(let C=0;C<u;C++){let M=R+C;if(M>=L.length)break;let $=L[M],W=0;for(let z of $){if(W>=l)break;let D=ue(z);D>0&&ie(t,n,i+W,c+C,z,P,a.bg,a.bold,H,a.italic,a.underline),W+=D;}}if(O){let C=S-R;if(C>=0&&C<u){let M=Math.min(b,l-1),$=i+M,W=c+C;if(Xe($,W,n)&&$<i+l)if(s)E={cursorPosition:{x:$,y:W,bg:a.bg}};else {let z=t.get($,W),D=z?.ch&&z.ch!==" "?z.ch:"\u258C",j=a.bg??"black",B=a.color??"white";t.setChar($,W,D,j,B,z?.bold,z?.dim,z?.italic,false);}}}}else {let G=0;for(let k of w){if(G>=l)break;let L=ue(k);L>0&&ie(t,n,i+G,c,k,P,a.bg,a.bold,H,a.italic,a.underline),G+=L;}if(O){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:a.bg}};else {let S=t.get(L,c),b=S?.ch&&S.ch!==" "?S.ch:"\u258C",R=a.bg??"black",C=a.color??"white";t.setChar(L,c,b,R,C,S?.bold,S?.dim,S?.italic,false);}}}return E}var er="\x1B",pe=`${er}[`;function tr(e,t){return `${pe}${t+1};${e+1}H`}function nr(e){let t=`${pe}0m`;return e.bold&&(t+=`${pe}1m`),e.dim&&(t+=`${pe}2m`),e.italic&&(t+=`${pe}3m`),e.underline&&(t+=`${pe}4m`),e.fg!=null&&(t+=Ot(e.fg)),e.bg!=null&&(t+=Dt(e.bg)),t}function Zt(e,t,n){let r="",o=-1,s=-1,i="";for(let c=0;c<t.height;c++)for(let l=0;l<t.width;l++){let u=t.get(l,c);if(!n){let p=e.get(l,c);if(p&&t.cellsEqual(u,p))continue}(s!==c||o!==l)&&(r+=tr(l,c));let f=nr(u);f!==i&&(r+=f,i=f),r+=u.ch,o=l+1,s=c;}return r.length>0&&(r+=`${pe}0m`),r}var ir={row:FlexDirection.Row,column:FlexDirection.Column},lr={"flex-start":Justify.FlexStart,center:Justify.Center,"flex-end":Justify.FlexEnd,"space-between":Justify.SpaceBetween,"space-around":Justify.SpaceAround},cr={"flex-start":Align.FlexStart,center:Align.Center,"flex-end":Align.FlexEnd,stretch:Align.Stretch};function tn(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 ur(e,t,n){tn(e,o=>e.setWidth(o),t.width),tn(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(ir[t.flexDirection]??FlexDirection.Column),t.flexWrap&&e.setFlexWrap(t.flexWrap==="wrap"?Wrap.Wrap:Wrap.NoWrap),t.justifyContent&&e.setJustifyContent(lr[t.justifyContent]??Justify.FlexStart),t.alignItems&&e.setAlignItems(cr[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 rn(e){let t=nn.Node.create();if(e.yogaNode=t,ur(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=on(e),zt(i,n,r,e.style.wrap??"wrap")});else for(let n=0;n<e.children.length;n++){let r=e.children[n];r.hidden||(rn(r),t.insertChild(r.yogaNode,t.getChildCount()));}}function on(e){if(e.text!=null)return e.text;let t="";for(let n of e.children)t+=on(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 sn(e,t,n){let r=e.yogaNode,o=r.getComputedLayout(),s=t+o.left,i=n+o.top,c=o.width,l=o.height,u=e.style.border&&e.style.border!=="none"?1:0,f=r.getComputedPadding(Edge.Top),p=r.getComputedPadding(Edge.Right),w=r.getComputedPadding(Edge.Bottom),v=r.getComputedPadding(Edge.Left),T=s+u+v,a=i+u+f,d=Math.max(0,c-u*2-v-p),y=Math.max(0,l-u*2-f-w);e.layout={x:s,y:i,width:c,height:l,innerX:T,innerY:a,innerWidth:d,innerHeight:y};for(let I of e.children)I.hidden||!I.yogaNode||sn(I,s,i);}function ln(e,t,n){let r=nn.Node.create();r.setWidth(t),r.setHeight(n),r.setFlexDirection(FlexDirection.Column);for(let o of e)o.hidden||(rn(o),r.insertChild(o.yogaNode,r.getChildCount()));r.calculateLayout(t,n,Direction.LTR);for(let o of e)o.hidden||!o.yogaNode||sn(o,0,0);r.freeRecursive(),cn(e);}function cn(e){for(let t of e)t.yogaNode=null,cn(t.children);}var Y=createContext(null),q=createContext(null),oe=createContext(null),be=createContext(null),Ye=createContext(null);function ar(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(m=>{_t(m),f=true,C();});let l=new ke(i.columns,i.rows),u=new ke(i.columns,i.rows),f=true,p=new Set,w=new Set,v=new Map,T={subscribe(m){return p.add(m),()=>p.delete(m)},subscribePriority(m){return w.add(m),()=>w.delete(m)},registerInputHandler(m,g){return v.set(m,g),()=>v.delete(m)}},a=null,d=new Map,y=[],I=new Set,P=[],H=new Set;function O(m){if(a!==m){a=m,C();for(let g of H)g(a);}}function E(){let m=[...y];if(P.length>0){let g=P[P.length-1];m=m.filter(x=>g.has(x));}return m=m.filter(g=>!I.has(g)),m.sort((g,x)=>{let K=d.get(g),_=d.get(x);if(!K||!_)return 0;let F=K.layout,h=_.layout;return F.y!==h.y?F.y-h.y:F.x-h.x}),m}let G={get focusedId(){return a},register(m,g){if(d.set(m,g),y.includes(m)||y.push(m),P.length>0&&P[P.length-1].add(m),a===null){let x=E();x.length>0&&O(x[0]);}return ()=>{d.delete(m);let x=y.indexOf(m);if(x!==-1&&y.splice(x,1),a===m){let K=E();O(K[0]??null);}}},requestFocus(m){O(m);},focusNext(){let m=E();if(m.length===0)return;let x=((a?m.indexOf(a):-1)+1)%m.length;O(m[x]);},focusPrev(){let m=E();if(m.length===0)return;let x=((a?m.indexOf(a):0)-1+m.length)%m.length;O(m[x]);},setSkippable(m,g){if(g){if(I.add(m),a===m){let x=E();x.length>0&&O(x[0]);}}else I.delete(m);},trapIds:null,pushTrap(m){return P.push(m),()=>{let g=P.indexOf(m);g!==-1&&P.splice(g,1);}},onFocusChange(m){return H.add(m),()=>{H.delete(m);}},getRegisteredElements(){let m=[];for(let g of y){if(I.has(g))continue;let x=d.get(g);x&&m.push({id:g,node:x});}return m},getActiveElements(){let m=E(),g=[];for(let x of m){if(I.has(x))continue;let K=d.get(x);K&&g.push({id:x,node:K});}return g}},k=new Map,L={getLayout(m){return m.layout},subscribe(m,g){return k.has(m)||k.set(m,new Set),k.get(m).add(g),()=>{let x=k.get(m);x&&(x.delete(g),x.size===0&&k.delete(m));}}},S={registerNode(){},unregisterNode(){},scheduleRender:C,exit(m){le.exit(m);},get columns(){return i.columns},get rows(){return i.rows}},b={type:"root",children:[],onCommit(){C();}},R=false;function C(){R||(R=true,queueMicrotask(()=>{R=false,M();}));}function M(){let m=i.columns,g=i.rows;(u.width!==m||u.height!==g)&&(u.resize(m,g),l.resize(m,g),f=true),ln(b.children,m,g),$(b.children);let x;if(a){let F=d.get(a);F?.type==="input"&&(x={nodeId:a,position:F.props.cursorPosition??F.props.value?.length??0});}let K=Jt(b.children,u,{cursorInfo:x,useNativeCursor:s}),_=Zt(l,u,f);if(_.length>0&&i.write(_),s)if(K.cursorPosition){let F=$t(K.cursorPosition.bg);i.setCursorColor(F),i.moveCursor(K.cursorPosition.x,K.cursorPosition.y),c||(i.showCursor(),c=true);}else c&&(i.hideCursor(),c=false);for(let F=0;F<u.cells.length;F++)l.cells[F]={...u.cells[F]};f=false;}function $(m){for(let g of m){let x=k.get(g);if(x)for(let K of x)K(g.layout);$(g.children);}}let W=i.onData(m=>{let g=jt(m);for(let x of g){if(x.ctrl&&x.name==="c"){le.exit();return}if(x.ctrl&&x.name==="z"){i.suspend(),process.kill(0,"SIGSTOP");return}if(x.name==="tab"&&!x.ctrl&&!x.alt){x.shift?G.focusPrev():G.focusNext();continue}let K=false;for(let _ of w)if(_(x)){K=true;break}if(!K&&a){let _=v.get(a);_&&(K=_(x));}if(!K)for(let _ of p)_(x);}}),z=i.onResize(()=>{f=true,C();}),D=()=>{i.resume(),f=true,C();};process.on("SIGCONT",D);let j=ee.createElement(be.Provider,{value:S},ee.createElement(Y.Provider,{value:T},ee.createElement(q.Provider,{value:G},ee.createElement(oe.Provider,{value:L},e)))),B=m=>{o&&console.error("Uncaught error:",m);},X=m=>{o&&console.error("Error caught by boundary:",m);},J=m=>{o&&console.error("Recoverable error:",m);},se=Ie.createContainer(b,0,null,false,null,"",B,X,J,null);Ie.updateContainer(j,se,null,null);let le={unmount(){Ie.updateContainer(null,se,null,null),W(),z(),process.off("SIGCONT",D),i.cleanup();},exit(m){le.unmount(),process.exit(m??0);}};return le}var pr=forwardRef(function({children:t,style:n,focusable:r},o){return ee.createElement("box",{style:n,focusable:r,ref:o},t)});var gr=forwardRef(function({children:t,style:n,wrap:r},o){let s=r?{...n,wrap:r}:n;return ee.createElement("text",{style:s,ref:o},t)});function un(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 u=ce([l],n,"wrap"),f=0;for(let p of u)o.push({text:p,logicalOffset:s+f}),f+=p.length;s+=l.length+1;}let i=0;for(let l=0;l<o.length;l++){let u=o[l],f=u.text.length,p=l+1<o.length&&o[l+1].logicalOffset!==u.logicalOffset+f,w=f+(p?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+=w;}let c=o.length-1;return {visualLine:c,visualCol:o[c].text.length,totalVisualLines:o.length,lineStartOffset:i-o[c].text.length,lineLength:o[c].text.length}}function an(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 p=ce([f],r,"wrap"),w=0;for(let v of p)s.push({text:v,startOffset:i+w}),w+=v.length;i+=f.length+1;}let c=Math.max(0,Math.min(t,s.length-1)),l=s[c],u=Math.min(n,l.text.length);return l.startOffset+u}function Ge(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 Be(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 xr(e){let{value:t,defaultValue:n="",onChange:r,onKeyPress:o,onBeforeChange:s,placeholder:i,style:c,focusedStyle:l,multiline:u,autoFocus:f,type:p="text"}=e,[w,v]=useState(n),[T,a]=useState(n.length),[d,y]=useState(0),[I,P]=useState(false),[H,O]=useState(false),E=useContext(Y),G=useContext(q),k=useContext(oe),L=useRef(null),S=useRef(null),b=t!==void 0,R=b?t:w;useEffect(()=>{if(!k||!L.current)return;let D=k.getLayout(L.current);return y(D.innerWidth),k.subscribe(L.current,j=>{y(j.innerWidth);})},[k]);let C=useRef(R),M=useRef(T);useEffect(()=>{C.current=R,M.current>R.length&&(M.current=R.length,a(R.length));},[R]),useEffect(()=>{M.current=T;},[T]);let $=useRef({isControlled:b,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:u??false,innerWidth:d,type:p});$.current={isControlled:b,onChange:r,onKeyPress:o,onBeforeChange:s,multiline:u??false,innerWidth:d,type:p},useEffect(()=>{if(!(!G||!S.current||!L.current))return G.register(S.current,L.current)},[G,H]);let W=useRef(false);useEffect(()=>{if(!H){W.current=false;return}if(f&&!W.current&&G&&S.current){W.current=true;let D=S.current,j=setTimeout(()=>{G.requestFocus(D);},0);return ()=>clearTimeout(j)}},[f,G,H]),useEffect(()=>{if(!G||!S.current)return;let D=S.current;return P(G.focusedId===D),G.onFocusChange(j=>{P(j===D);})},[G,H]),useEffect(()=>{if(!E||!S.current)return;let D=S.current,j=B=>{let{isControlled:X,onChange:J,onKeyPress:se,onBeforeChange:le,multiline:m}=$.current;if(se?.(B)===true)return true;let g=C.current,x=M.current;if(B.name==="escape")return false;let K=(h,N)=>{let V=h,Q=N;if(le){let A=le(h,g);if(A===false)return;typeof A=="string"&&(V=A,Q=A.length);}C.current=V,M.current=Q,X||v(V),J?.(V),a(Q);},_=h=>{M.current=h,a(h);};if(B.name==="return"){if(m){let h=g.slice(0,x)+`
8
+ `+g.slice(x);return K(h,x+1),true}return false}if(B.ctrl){if(B.name==="w"){if(x>0){let h=x;for(;h>0&&g[h-1]===" ";)h--;for(;h>0&&g[h-1]!==" "&&(!m||g[h-1]!==`
9
+ `);)h--;let N=g.slice(0,h)+g.slice(x);K(N,h);}return true}if(B.name==="a"){if(m){let{line:h,lines:N}=Ge(g,x);_(Be(N,h,0));}else _(0);return true}if(B.name==="e"){if(m){let{line:h,lines:N}=Ge(g,x);_(Be(N,h,N[h].length));}else _(g.length);return true}if(B.name==="k"){if(m){let{line:h,lines:N}=Ge(g,x),V=Be(N,h,N[h].length);if(x<V){let Q=g.slice(0,x)+g.slice(V);K(Q,x);}}else if(x<g.length){let h=g.slice(0,x);K(h,x);}return true}return false}if(B.alt){if(B.name==="left"||B.name==="b"){let h=x;for(;h>0&&g[h-1]===" ";)h--;for(;h>0&&g[h-1]!==" "&&g[h-1]!==`
10
+ `;)h--;return _(h),true}if(B.name==="right"||B.name==="f"){let h=x;for(;h<g.length&&g[h]!==" "&&g[h]!==`
11
+ `;)h++;for(;h<g.length&&g[h]===" ";)h++;return _(h),true}if(B.name==="backspace"||B.name==="d")if(B.name==="backspace"){if(x>0){let h=x;for(;h>0&&g[h-1]===" ";)h--;for(;h>0&&g[h-1]!==" "&&g[h-1]!==`
12
+ `;)h--;let N=g.slice(0,h)+g.slice(x);K(N,h);}return true}else {if(x<g.length){let h=x;for(;h<g.length&&g[h]!==" "&&g[h]!==`
13
+ `;)h++;for(;h<g.length&&g[h]===" ";)h++;let N=g.slice(0,x)+g.slice(h);K(N,x);}return true}return false}if(B.name==="left")return _(Math.max(0,x-1)),true;if(B.name==="right")return _(Math.min(g.length,x+1)),true;if(B.name==="up"){let{innerWidth:h}=$.current,N=un(g,x,h);return N.visualLine>0&&_(an(g,N.visualLine-1,N.visualCol,h)),true}if(B.name==="down"){let{innerWidth:h}=$.current,N=un(g,x,h);return N.visualLine<N.totalVisualLines-1&&_(an(g,N.visualLine+1,N.visualCol,h)),true}if(B.name==="home"){if(m){let{line:h,lines:N}=Ge(g,x);_(Be(N,h,0));}else _(0);return true}if(B.name==="end"){if(m){let{line:h,lines:N}=Ge(g,x);_(Be(N,h,N[h].length));}else _(g.length);return true}if(B.name==="backspace"){if(x>0){let h=g.slice(0,x-1)+g.slice(x);K(h,x-1);}return true}if(B.name==="delete"){if(x<g.length){let h=g.slice(0,x)+g.slice(x+1);K(h,x);}return true}if(B.name.length>1)return false;let F=B.sequence;if(F.length===1&&F.charCodeAt(0)>=32){let{type:h}=$.current;if(h==="number"){let V=/[0-9]/.test(F),Q=F==="."&&!g.includes("."),A=F==="-"&&x===0&&!g.includes("-");if(!V&&!Q&&!A)return true}let N=g.slice(0,x)+F+g.slice(x);return K(N,x+1),true}return false};return E.registerInputHandler(D,j)},[E,H]);let z={...c,...I&&l?l:{}};return ee.createElement("input",{style:z,value:R,defaultValue:n,placeholder:i,onChange:r,cursorPosition:T,multiline:u??false,focused:I,ref:D=>{D?(L.current=D,S.current=D.focusId,O(true)):(L.current=null,S.current=null,O(false));}})}function ft({trap:e=false,children:t}){let n=useContext(q),r=useRef(null),o=useRef(new Set);return useLayoutEffect(()=>{if(!e||!n)return;r.current=n.focusedId;let s=n.pushTrap(o.current);return ()=>{s(),r.current&&n.requestFocus(r.current);}},[e,n]),useEffect(()=>{if(!(!e||!n)&&o.current.size>0){let s=o.current.values().next().value;s&&n.requestFocus(s);}},[e,n]),ee.createElement(ee.Fragment,null,t)}function Rr({size:e}){return ee.createElement("box",{style:{flexGrow:e??1}})}function hn(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 gn(e,t){return !(t.name!==e.name||e.ctrl!==!!t.ctrl||e.alt!==!!t.alt||e.shift!==!!t.shift||e.meta!==!!t.meta)}function Ir({keypress:e,onPress:t,whenFocused:n,priority:r,disabled:o}){let s=useContext(Y),i=useContext(q),c=useRef(t);c.current=t;let l=useRef(hn(e));return l.current=hn(e),useEffect(()=>{if(!(!s||o))if(r){let u=f=>!gn(l.current,f)||n&&i?.focusedId!==n?false:(c.current(),true);return s.subscribePriority(u)}else {let u=f=>{gn(l.current,f)&&(n&&i?.focusedId!==n||c.current());};return s.subscribe(u)}},[s,i,n,r,o]),null}function kr({children:e,zIndex:t=1e3}){return ee.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:t}},e)}function Pr({onPress:e,style:t,focusedStyle:n,children:r,disabled:o}){let s=useContext(q),i=useContext(Y),c=useRef(null),l=useRef(null),u=useRef(e);u.current=e;let[f,p]=useState(false),[w,v]=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 a=l.current;return v(s.focusedId===a),s.onFocusChange(d=>{v(d===a);})},[s,f]),useEffect(()=>{if(!i||!l.current||o)return;let a=l.current,d=y=>s?.focusedId!==a?false:y.name==="return"||y.name===" "||y.sequence===" "?(u.current?.(),true):false;return i.registerInputHandler(a,d)},[i,s,o,f]);let T={...t,...w&&n?n:{}};return ee.createElement("box",{style:T,focusable:!o,ref:a=>{a?(c.current=a,l.current=a.focusId,p(true)):(c.current=null,l.current=null,p(false));}},r)}var Br={x:0,y:0,width:0,height:0,innerX:0,innerY:0,innerWidth:0,innerHeight:0};function fe(e){let t=useContext(oe),[n,r]=useState(Br);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(Y);useEffect(()=>{if(n)return n.subscribe(e)},[n,...t]);}function Ar({children:e,style:t,scrollOffset:n,onScroll:r,defaultScrollOffset:o=0,scrollStep:s=1,disableKeyboard:i,scrollToFocus:c=true,showScrollbar:l=true,focusable:u=true,focusedStyle:f}){let p=n!==void 0,[w,v]=useState(o),T=p?n:w,a=useRef(null),d=useRef(null),y=fe(a),I=fe(d),P=useContext(q),H=useContext(oe),O=useRef(null);u&&!O.current&&(O.current=`scrollview-${Math.random().toString(36).slice(2,9)}`);let E=u?O.current:null;useEffect(()=>{if(!(!u||!E||!P||!a.current))return P.register(E,a.current)},[u,E,P]);let G=u&&E&&P?.focusedId===E,k=y.innerHeight,L=I.height,S=Math.max(0,L-k),b=Math.max(0,Math.min(T,S)),R=useMemo(()=>({getBounds:()=>{let A=y.y;return {visibleTop:A,visibleBottom:A+k,viewportHeight:k,scrollOffset:b}}}),[y.y,k,b]),C=useCallback(A=>{let re=Math.max(0,Math.min(A,S));p?r?.(re):v(re);},[p,r,S]);useEffect(()=>{T>S&&S>=0&&C(S);},[T,S,C]),useEffect(()=>!c||!P||!H||!d.current?void 0:P.onFocusChange(re=>{if(!re||!d.current)return;let Z=Ke=>{if(Ke.focusId===re)return Ke;for(let We of Ke.children){let ye=Z(We);if(ye)return ye}return null},de=Z(d.current);if(!de)return;let ge=H.getLayout(de),Re=d.current.layout?.y??0,Oe=ge.y-Re,De=Oe+ge.height,ve=T,ot=T+k;Oe<ve?C(Oe):De>ot&&C(De-k);}),[c,P,H,T,k,C]);let M=useCallback(()=>{if(!P)return false;let A=P.focusedId;if(!A)return false;if(u&&E&&A===E)return true;if(!d.current)return false;let re=Z=>{if(Z.focusId===A)return true;for(let de of Z.children)if(re(de))return true;return false};return re(d.current)},[P,u,E]);Le(A=>{if(i||!M())return;let re=Math.max(1,Math.floor(k/2)),Z=Math.max(1,k);switch(A.name){case "pageup":C(T-Z);break;case "pagedown":C(T+Z);break;default:A.ctrl&&(A.name==="d"?C(T+re):A.name==="u"?C(T-re):A.name==="f"?C(T+Z):A.name==="b"&&C(T-Z));break}},[T,s,k,S,i,C,M]);let{padding:$,paddingX:W,paddingY:z,paddingTop:D,paddingRight:j,paddingBottom:B,paddingLeft:X,...J}=t??{},le=J.border!=null&&J.border!=="none"?2:0,m=L>0?L+le:void 0,g={...J,...G?f:{},clip:true,...J.height===void 0&&m!==void 0?{height:m,flexShrink:J.flexShrink??1,minHeight:J.minHeight??0}:{}},x={position:"absolute",top:-b,left:0,right:0,flexDirection:"column",...$!==void 0&&{padding:$},...W!==void 0&&{paddingX:W},...z!==void 0&&{paddingY:z},...D!==void 0&&{paddingTop:D},...j!==void 0&&{paddingRight:j},...B!==void 0&&{paddingBottom:B},...X!==void 0&&{paddingLeft:X}},K=L>k&&k>0,_=l&&K,F=Math.max(1,Math.floor(k/L*k)),h=L-k,N=h>0?Math.floor(b/h*(k-F)):0,V=[];if(_)for(let A=0;A<k;A++)A>=N&&A<N+F?V.push("\u2588"):V.push("\u2591");let Q={position:"absolute",top:0,right:0,width:1,height:k,flexDirection:"column"};return ee.createElement(Ye.Provider,{value:R},ee.createElement("box",{style:g,ref:A=>{a.current=A??null;},...u?{focusable:true,focusId:E}:{}},ee.createElement("box",{style:{...x,paddingRight:_?(x.paddingRight??0)+1:x.paddingRight},ref:A=>{d.current=A??null;}},e),_&&ee.createElement("box",{style:Q},ee.createElement("text",{style:{color:"blackBright"}},V.join(`
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,p]=useState(s),w=u?n:f,v=useContext(q),T=useContext(Y),a=useRef(null),d=useRef(null),y=useRef(o);y.current=o;let[I,P]=useState(false),[H,O]=useState(false),E=useRef(null),G=useCallback(b=>{let R=Math.max(0,Math.min(b,e-1));u?r?.(R):p(R);},[u,r,e]),k=useCallback((b,R)=>{if(!i||i.size===0)return Math.max(0,Math.min(b+R,e-1));let C=b+R;for(;C>=0&&C<e&&i.has(C);)C+=R;return C<0||C>=e?b:C},[i,e]);useEffect(()=>{if(!(!v||!d.current||!a.current||!l))return v.register(d.current,a.current)},[v,l,I]),useEffect(()=>{if(!v||!d.current)return;let b=d.current;return O(v.focusedId===b),v.onFocusChange(R=>{O(R===b);})},[v,I]);let L=useCallback(b=>{let R=b?e-1:0,C=b?-1:1,M=R;for(;M>=0&&M<e&&i?.has(M);)M+=C;return M>=0&&M<e?M:b?e-1:0},[i,e]);useEffect(()=>{if(!T||!d.current||!l)return;let b=d.current,R=C=>v?.focusedId!==b?false:C.name==="g"&&!C.ctrl&&!C.alt?E.current==="g"?(G(L(false)),E.current=null,true):(E.current="g",true):C.name==="G"||C.name==="g"&&C.shift?(E.current=null,G(L(true)),true):(E.current=null,C.name==="up"||C.name==="k"?(G(k(w,-1)),true):C.name==="down"||C.name==="j"?(G(k(w,1)),true):C.name==="return"?(i?.has(w)||y.current?.(w),true):false);return T.registerInputHandler(b,R)},[T,v,l,w,G,k,L,i,I]);let S=[];for(let b=0;b<e;b++)S.push(ee.createElement(ee.Fragment,{key:b},t({index:b,selected:b===w,focused:H})));return ee.createElement("box",{style:{flexDirection:"column",...c},focusable:l,ref:b=>{b?(a.current=b,d.current=b.focusId,P(true)):(a.current=null,d.current=null,P(false));}},...S)}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 p=e[f];p&&!p.disabled&&r?.(p.value,f);};return ee.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:p,focused:w})=>{let v=e[f],T=v.disabled,a=p&&w,d=p?">":" ";return ee.createElement("box",{style:{flexDirection:"row",...a?{bg:i}:{}}},ee.createElement("text",{style:a?{bold:true,color:"black"}:T?{dim:true}:{}},`${d} ${v.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=fe(l).innerWidth,[p,w]=useState(0);useEffect(()=>{if(!t)return;let y=setInterval(()=>{w(I=>(I+1)%Math.max(1,f+6));},100);return ()=>clearInterval(y)},[t,f]);let v=Math.max(0,Math.min(1,e??0)),T=o?` ${Math.round(v*100)}%`:"",a="";if(f>0)if(t&&e===void 0){let y=Math.max(1,Math.min(3,Math.floor(f/4))),I=[];for(let P=0;P<f;P++)P>=p-y&&P<p?I.push(i):I.push(c);a=I.join("");}else {let y=Math.round(v*f);a=i.repeat(y)+c.repeat(f-y);}let d=[];return r&&d.push(ee.createElement("text",{key:"label",style:{bold:true}},r+" ")),d.push(ee.createElement("box",{key:"track",style:{flexGrow:1,flexShrink:1},ref:y=>{l.current=y??null;}},ee.createElement("text",{key:"bar",style:{}},a))),o&&d.push(ee.createElement("text",{key:"pct",style:{bold:true}},T)),ee.createElement("box",{style:{flexDirection:"row",width:n,...s}},...d)}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=[ee.createElement("text",{key:"frame",style:r},e[o])];return n&&i.push(ee.createElement("text",{key:"label",style:{}}," "+n)),ee.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(v=>{let T=`toast-${Qr++}`,a={id:T,durationMs:3e3,variant:"info",...v};if(o(d=>[...d,a]),a.durationMs&&a.durationMs>0){let d=setTimeout(()=>{s.current.delete(T),o(y=>y.filter(I=>I.id!==T));},a.durationMs);s.current.set(T,d);}},[]);useEffect(()=>()=>{for(let v of s.current.values())clearTimeout(v);s.current.clear();},[]);let c=useRef({push:i});c.current.push=i;let l=e.startsWith("top"),u=e.endsWith("right"),f={position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:900,flexDirection:"column",justifyContent:l?"flex-start":"flex-end",alignItems:u?"flex-end":"flex-start",padding:1},w=r.slice(-t).map(v=>{let T=v.variant??"info",a=to[T],d=[];return v.title&&d.push(ee.createElement("text",{key:"title",style:{bold:true,color:a.title}},v.title)),d.push(ee.createElement("text",{key:"msg",style:{color:a.text}},v.message)),ee.createElement("box",{key:v.id,style:{bg:a.bg,paddingX:1,flexDirection:"column",minWidth:20,maxWidth:50}},...d)});return ee.createElement(Rn.Provider,{value:c.current},n,w.length>0?ee.createElement("box",{style:f},...w):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 p=useContext(q),w=useContext(Y),v=useContext(be),T=useContext(Ye),a=useRef(null),d=useRef(null),y=useRef(n);y.current=n;let[I,P]=useState(false),[H,O]=useState(false),[E,G]=useState(false),[k,L]=useState(0),[S,b]=useState(""),[R,C]=useState(0),M=fe(a),$=v?.rows??24,W=T?.getBounds(),D=e.find(F=>F.value===t)?.label??"",j=useMemo(()=>{if(!S)return e;let F=S.toLowerCase();return e.filter(h=>h.label.toLowerCase().includes(F))},[e,S]),B=Math.min(l,j.length),X=j.slice(R,R+B);useEffect(()=>{L(0),C(0);},[S]),useEffect(()=>{!H&&E&&(G(false),b(""));},[H,E]),useEffect(()=>{if(!(!p||!d.current||!a.current))return p.register(d.current,a.current)},[p,I]),useEffect(()=>{!p||!d.current||p.setSkippable(d.current,!!f);},[p,f,I]),useEffect(()=>{if(!p||!d.current)return;let F=d.current;return O(p.focusedId===F),p.onFocusChange(h=>{O(h===F);})},[p,I]);let J=useCallback((F,h)=>{let N=F+h;for(;N>=0&&N<j.length;){if(!j[N].disabled)return N;N+=h;}return F},[j]),se=useCallback(F=>{F<R?C(F):F>=R+B&&C(F-B+1);},[R,B]);useEffect(()=>{if(!w||!d.current||f)return;let F=d.current,h=N=>{if(p?.focusedId!==F)return false;if(!E){if(N.name==="return"||N.name===" "||N.sequence===" "||N.name==="down"){G(true),b("");let V=j.findIndex(A=>A.value===t),Q=V>=0?V:0;return L(Q),C(Math.max(0,Q-Math.floor(l/2))),true}return false}if(N.name==="tab")return G(false),b(""),false;if(N.name==="escape")return G(false),b(""),true;if(N.name==="return"){let V=j[k];return V&&!V.disabled&&(y.current?.(V.value),G(false),b("")),true}if(N.name==="up"){let V=J(k,-1);return L(V),se(V),true}if(N.name==="down"){let V=J(k,1);return L(V),se(V),true}if(N.name==="backspace")return u&&S.length>0&&b(V=>V.slice(0,-1)),true;if(N.name==="home"){let V=J(-1,1);return L(V),se(V),true}if(N.name==="end"){let V=J(j.length,-1);return L(V),se(V),true}if(u&&N.sequence&&N.sequence.length===1&&!N.ctrl&&!N.alt){let V=N.sequence;if(V>=" "&&V<="~")return b(Q=>Q+V),true}return true};return w.registerInputHandler(F,h)},[w,p,f,E,k,j,t,l,u,S,J,se,I]);let m={flexDirection:"row",width:"100%",...!o?.bg&&o?.border===void 0?{border:"single"}:{},...o,...H&&s?s:{}},g=D?o?.color??void 0:"blackBright",x=[ee.createElement("text",{key:"label",style:{flexGrow:1,flexShrink:1,color:g,wrap:"ellipsis",...D?{}:{dim:true}}},D||r),ee.createElement("text",{key:"arrow",style:{flexShrink:0,color:H?c:"blackBright"}},E?" \u25B2":" \u25BC")],K=null;if(E){let F=[];u&&S&&F.push(ee.createElement("box",{key:"search",style:{paddingX:1}},ee.createElement("text",{style:{color:"blackBright",dim:true}},`/${S}`))),j.length===0&&F.push(ee.createElement("box",{key:"empty",style:{paddingX:1}},ee.createElement("text",{style:{dim:true,color:"blackBright"}},"No matches"))),R>0&&F.push(ee.createElement("box",{key:"scroll-up",style:{justifyContent:"center",alignItems:"center"}},ee.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25B2"))),X.forEach((ve,ot)=>{let We=R+ot===k,ye=ve.disabled,Mn={paddingX:1,...We&&!ye?{bg:c}:{}},Vn={...We&&!ye?{color:"black",bold:true}:{},...ye?{dim:true,color:"blackBright"}:{}};F.push(ee.createElement("box",{key:`item-${ve.value}`,style:Mn},ee.createElement("text",{style:Vn},ve.label)));}),R+B<j.length&&F.push(ee.createElement("box",{key:"scroll-down",style:{justifyContent:"center",alignItems:"center"}},ee.createElement("text",{style:{dim:true,color:"blackBright"}},"\u25BC")));let h=R>0,N=R+B<j.length,V=u&&S,Q=j.length===0,A=!i?.bg&&i?.border===void 0,Z=B+(A?2:0);h&&(Z+=1),N&&(Z+=1),V&&(Z+=1),Q&&(Z+=1);let de=M.y+M.height,ge,Re;W?(ge=W.visibleBottom-de,Re=M.y-W.visibleTop):(ge=$-de,Re=M.y);let De=ge<Z&&Re>=Z?-Z:M.height||1;K=ee.createElement("box",{style:{position:"absolute",top:De,left:0,right:0,zIndex:9999,...A?{border:"single"}:{},bg:"black",flexDirection:"column",...i}},...F);}let _={flexDirection:"column",width:m.width??"100%",minWidth:m.minWidth,maxWidth:m.maxWidth,flexGrow:m.flexGrow,flexShrink:m.flexShrink??1};return ee.createElement("box",{style:_},ee.createElement("box",{style:m,focusable:true,ref:F=>{F?(a.current=F,d.current=F.focusId,P(true)):(a.current=null,d.current=null,P(false));}},...x),K)}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(Y),f=useRef(null),p=useRef(null),w=useRef(t);w.current=t;let v=useRef(e);v.current=e;let[T,a]=useState(false),[d,y]=useState(false);useEffect(()=>{if(!(!l||!p.current||!f.current||s))return l.register(p.current,f.current)},[l,s,T]),useEffect(()=>{if(!l||!p.current)return;let E=p.current;return y(l.focusedId===E),l.onFocusChange(G=>{y(G===E);})},[l,T]),useEffect(()=>{if(!u||!p.current||s)return;let E=p.current,G=k=>l?.focusedId!==E?false:k.name==="return"||k.name===" "||k.sequence===" "?(w.current(!v.current),true):false;return u.registerInputHandler(E,G)},[u,l,s,T]);let I={flexDirection:"row",gap:1,...r,...d&&o?o:{}},P=e?i:c,H={color:s?"blackBright":d?"white":r?.color},O={color:s?"blackBright":r?.color};return ee.createElement("box",{style:I,focusable:!s,ref:E=>{E?(f.current=E,p.current=E.focusId,a(true)):(f.current=null,p.current=null,a(false));}},ee.createElement("text",{key:"box",style:H},`[${P}]`),n?ee.createElement("text",{key:"label",style:O},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:p="\u25CB"}){let w=useContext(q),v=useContext(Y),T=useRef(null),a=useRef(null),d=useRef(n);d.current=n;let[y,I]=useState(false),[P,H]=useState(false),[O,E]=useState(()=>{let S=e.findIndex(b=>b.value===t);return S>=0?S:e.findIndex(b=>!b.disabled)}),G=useCallback((S,b)=>{let R=S;for(let C=0;C<e.length;C++)if(R=(R+b+e.length)%e.length,!e[R]?.disabled)return R;return S},[e]);useEffect(()=>{if(!(!w||!a.current||!T.current||c))return w.register(a.current,T.current)},[w,c,y]),useEffect(()=>{if(!w||!a.current)return;let S=a.current;return H(w.focusedId===S),w.onFocusChange(b=>{H(b===S);})},[w,y]),useEffect(()=>{if(!v||!a.current||c)return;let S=a.current,b=R=>{if(w?.focusedId!==S)return false;if(R.name==="up"||R.name==="left"||R.name==="k"||R.name==="tab"&&R.shift)return E(C=>G(C,-1)),true;if(R.name==="down"||R.name==="right"||R.name==="j"||R.name==="tab"&&!R.shift)return E(C=>G(C,1)),true;if(R.name==="return"||R.name===" "||R.sequence===" "){let C=e[O];return C&&!C.disabled&&d.current(C.value),true}return false};return v.registerInputHandler(S,b)},[v,w,c,e,O,G,y]),useEffect(()=>{let S=e.findIndex(b=>b.value===t);S>=0&&E(S);},[t,e]);let k={flexDirection:l,gap:u,...r},L=e.map((S,b)=>{let R=S.value===t,C=b===O,M=c||S.disabled,$=R?f:p,W={flexDirection:"row",gap:1,...o};R&&i&&(W={...W,...i}),P&&C&&s&&(W={...W,...s});let z=M?"blackBright":P&&C?s?.color??"white":R?i?.color??o?.color:o?.color;return ee.createElement("box",{key:b,style:W},ee.createElement("text",{key:"radio",style:{color:z}},`(${$})`),ee.createElement("text",{key:"label",style:{color:z}},S.label))});return ee.createElement("box",{style:k,focusable:!c,ref:S=>{S?(T.current=S,a.current=S.focusId,I(true)):(T.current=null,a.current=null,I(false));}},...L)}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(p=>{let w=++r.current;n(v=>[...v,{id:w,type:"alert",content:u,okText:f?.okText??"OK",cancelText:"",style:f?.style,buttonStyle:f?.buttonStyle,okButtonStyle:f?.okButtonStyle,focusedButtonStyle:f?.focusedButtonStyle,backdropStyle:f?.backdropStyle,resolve:()=>p()}]);}),[]),s=useCallback((u,f)=>new Promise(p=>{let w=++r.current;n(v=>[...v,{id:w,type:"confirm",content:u,okText:f?.okText??"OK",cancelText:f?.cancelText??"Cancel",style:f?.style,buttonStyle:f?.buttonStyle,okButtonStyle:f?.okButtonStyle,cancelButtonStyle:f?.cancelButtonStyle,focusedButtonStyle:f?.focusedButtonStyle,backdropStyle:f?.backdropStyle,resolve:p}]);}),[]),i=useCallback((u,f)=>{n(p=>{let w=p.find(v=>v.id===u);return w&&w.resolve(f),p.filter(v=>v.id!==u)});},[]),c={alert:o,confirm:s},l=t[t.length-1];return ee.createElement(En.Provider,{value:c},e,l&&ee.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 y=[];return r.current&&s.current&&y.push(n.register(s.current,r.current)),o.current&&i.current&&y.push(n.register(i.current,o.current)),s.current&&n.requestFocus(s.current),()=>y.forEach(I=>I())},[n,u]),useEffect(()=>{if(n)return n.onFocusChange(y=>{y===s.current?l("ok"):y===i.current&&l("cancel");})},[n]),Le(y=>{if(y.name==="return"||y.name==="space"){e.type==="alert"?t(e.id,true):t(e.id,c==="ok");return}if(y.name==="escape"){t(e.id,false);return}e.type==="confirm"&&n&&(y.name==="left"||y.name==="right")&&(c==="ok"&&i.current?n.requestFocus(i.current):s.current&&n.requestFocus(s.current));},[e,c,n,t]);let p=typeof e.content=="string",w=p?e.content.length:0,T={minWidth:Math.max(20,p?Math.min(w+6,50):30),maxWidth:50,bg:"black",border:"round",borderColor:"white",padding:1,flexDirection:"column",gap:1,...e.style},a=(y,I)=>{let P={paddingX:2,bg:"blackBright",color:"white"},H={bg:"white",color:"black",bold:true},O=y==="ok"?e.okButtonStyle:e.cancelButtonStyle;return {...P,...e.buttonStyle,...O,...I?{...H,...e.focusedButtonStyle}:{}}},d={position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:999,...e.backdropStyle};return ee.createElement(ft,{trap:true},ee.createElement("box",{style:d}),ee.createElement("box",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,justifyContent:"center",alignItems:"center",zIndex:1e3}},ee.createElement("box",{style:T},ee.createElement("box",{style:{flexDirection:"column"}},typeof e.content=="string"?ee.createElement("text",null,e.content):e.content),ee.createElement("box",{style:{flexDirection:"row",justifyContent:"flex-end",gap:1}},e.type==="confirm"&&ee.createElement("box",{style:a("cancel",c==="cancel"),focusable:true,ref:y=>{y&&y.focusId&&!i.current&&(o.current=y,i.current=y.focusId,f(I=>I+1));}},ee.createElement("text",null,e.cancelText)),ee.createElement("box",{style:a("ok",c==="ok"),focusable:true,ref:y=>{y&&y.focusId&&!s.current&&(r.current=y,s.current=y.focusId,f(I=>I+1));}},ee.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?(...S)=>console.error("[JumpNav]",...S):()=>{},[u,f]=useState(false),[p,w]=useState(""),[v,T]=useState([]),a=useContext(Y),d=useContext(q),y=useContext(oe);useEffect(()=>{l("Mounted, inputCtx:",!!a,"focusCtx:",!!d,"enabled:",i);},[]);let P=useCallback(S=>{let b=S.toLowerCase().split("+");return {ctrl:b.includes("ctrl"),alt:b.includes("alt"),shift:b.includes("shift"),meta:b.includes("meta"),name:b[b.length-1]??""}},[])(t),H=useCallback(()=>{if(!d?.getActiveElements){l("refreshElements: no getActiveElements");return}let S=d.getActiveElements();l("getActiveElements returned",S.length,"elements");let b=S.map(({id:R,node:C})=>({id:R,node:C,layout:y?.getLayout(C)??C.layout}));b.sort((R,C)=>R.layout.y!==C.layout.y?R.layout.y-C.layout.y:R.layout.x-C.layout.x),T(b);},[d,y,l]),O=useRef(false);useEffect(()=>{u&&!O.current&&(l("Activated! Refreshing elements..."),H()),O.current=u;},[u,H,l]);let E=v.filter(S=>S.layout.width>0&&S.layout.height>0),G=ho(E.length,s),k=useMemo(()=>{let S=new Map;return E.forEach((b,R)=>{G[R]&&S.set(G[R],b.id);}),S},[E,G]);useEffect(()=>{if(!a||!i){l("Not subscribing - inputCtx:",!!a,"enabled:",i);return}l("Subscribing to priority input, activation key:",t);let S=b=>{let R=b.name===P.name,C=!!b.ctrl===P.ctrl,M=!!b.alt===P.alt,$=!!b.shift===P.shift,W=!!b.meta===P.meta;if(!u&&R&&C&&M&&$&&W)return l("Activation key matched! Activating..."),f(true),w(""),true;if(u){if(b.name==="escape")return l("Escape pressed, deactivating"),f(false),w(""),true;if(b.name==="backspace")return w(""),true;if(b.sequence&&b.sequence.length===1&&/[a-z]/i.test(b.sequence)){let z=p+b.sequence.toLowerCase();l("Buffer:",z);let D=k.get(z);return D?(l("Jumping to",D),d?.requestFocus(D),f(false),w(""),true):[...k.keys()].some(B=>B.startsWith(z))?(w(z),true):(w(""),true)}return true}return false};return a.subscribePriority(S)},[a,i,u,P,p,k,d,t,l]);let L=u?ee.createElement("box",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:99998}},...E.map((S,b)=>{let R=G[b];if(!R)return null;let{x:C,y:M}=S.layout,$=R.startsWith(p)&&p.length>0;return ee.createElement("box",{key:S.id,style:{position:"absolute",top:M,left:Math.max(0,C-R.length-2),bg:$?"cyan":r,color:o,paddingX:1,zIndex:99999,...n}},ee.createElement("text",{style:{bold:true,color:o}},R))}),ee.createElement("box",{style:{position:"absolute",bottom:0,left:0,right:0,bg:"blackBright",paddingX:1,zIndex:99999}},ee.createElement("text",{style:{color:"white"}},p?`Jump: ${p}_`:"Press a key to jump \u2022 ESC to cancel"))):null;return ee.createElement(ee.Fragment,null,e,L)}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(Y),c=useRef(null),l=useRef(null),[u,f]=useState(false),p=useRef(n),w=useRef(r),v=useRef(o);p.current=n,w.current=r,v.current=o;let T=useCallback(d=>{c.current=d,d?l.current=d.focusId??null:l.current=null;},[]);useEffect(()=>{if(!(!s||!l.current||!c.current))return s.register(l.current,c.current)},[s]),useEffect(()=>{!s||!l.current||s.setSkippable(l.current,!!t);},[s,t]),useEffect(()=>{if(!s||!l.current)return;let d=l.current,y=s.focusedId===d;return f(y),s.onFocusChange(I=>{let P=I===d;f(H=>(P&&!H?p.current?.():!P&&H&&w.current?.(),P));})},[s]),useEffect(()=>{if(!i||!l.current||t)return;let d=l.current,y=I=>s?.focusedId!==d?false:v.current?.(I)===true;return i.registerInputHandler(d,y)},[i,s,t]);let a=useCallback(()=>{s&&l.current&&s.requestFocus(l.current);},[s]);return {ref:T,isFocused:u,focus:a,focusId:l.current}}function Io(){let e=useContext(be);if(!e)throw new Error("useApp must be used within a Glyph render tree");return {exit:e.exit,get columns(){return e.columns},get rows(){return e.rows}}}function 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 te(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 p of i)(p!==r&&!/[\s\-\(\)\/\.\:]/.test(p)||/[a-zA-Z0-9]/.test(p))&&/[a-zA-Z0-9]/.test(p)&&l.push(p);let u="",f=0;for(let p of s)if(p.type==="literal")(f<l.length||o)&&(u+=p.char);else if(f<l.length){let w=l[f];if(Go(w,p.type))u+=w,f++;else {f++;continue}}else o&&(u+=r);return u}}var Bo={usPhone:te("(999) 999-9999"),intlPhone:te("+9 999 999 9999"),dateUS:te("99/99/9999"),dateEU:te("99/99/9999"),dateISO:te("9999-99-99"),time:te("99:99"),timeFull:te("99:99:99"),creditCard:te("9999 9999 9999 9999"),ssn:te("999-99-9999"),zip:te("99999"),zipPlus4:te("99999-9999"),ipv4:te("999.999.999.999"),mac:te("**:**:**:**:**:**")};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,te 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,fe as useLayout,eo as useToast};//# sourceMappingURL=index.js.map
15
15
  //# sourceMappingURL=index.js.map