@maizzle/framework 6.0.0-rc.24 → 6.0.0-rc.25

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.
Files changed (122) hide show
  1. package/dist/build.js.map +1 -1
  2. package/dist/components/Body.vue +12 -0
  3. package/dist/components/Button.vue +16 -29
  4. package/dist/components/CodeBlock.vue +5 -4
  5. package/dist/components/CodeInline.vue +9 -8
  6. package/dist/components/Column.vue +17 -4
  7. package/dist/components/Container.vue +7 -11
  8. package/dist/components/Hr.vue +1 -1
  9. package/dist/components/Img.vue +39 -22
  10. package/dist/components/Layout.vue +1 -1
  11. package/dist/components/Markdown.vue +9 -14
  12. package/dist/components/QrCode.vue +2 -2
  13. package/dist/components/Section.vue +9 -6
  14. package/dist/components/Text.vue +2 -2
  15. package/dist/components/utils.d.ts +25 -1
  16. package/dist/components/utils.d.ts.map +1 -1
  17. package/dist/components/utils.js +29 -1
  18. package/dist/components/utils.js.map +1 -1
  19. package/dist/components/utils.ts +46 -0
  20. package/dist/composables/useConfig.d.ts.map +1 -1
  21. package/dist/composables/useCurrentTemplate.d.ts.map +1 -1
  22. package/dist/composables/useEvent.d.ts.map +1 -1
  23. package/dist/composables/useFont.js.map +1 -1
  24. package/dist/config/index.js.map +1 -1
  25. package/dist/events/index.d.ts.map +1 -1
  26. package/dist/events/index.js.map +1 -1
  27. package/dist/plaintext.js.map +1 -1
  28. package/dist/plugins/postcss/mergeMediaQueries.js.map +1 -1
  29. package/dist/plugins/postcss/pruneVars.js.map +1 -1
  30. package/dist/plugins/postcss/quoteFontFamilies.d.ts.map +1 -1
  31. package/dist/plugins/postcss/quoteFontFamilies.js.map +1 -1
  32. package/dist/plugins/postcss/removeDeclarations.js.map +1 -1
  33. package/dist/plugins/postcss/resolveProps.d.ts.map +1 -1
  34. package/dist/plugins/postcss/resolveProps.js +0 -3
  35. package/dist/plugins/postcss/resolveProps.js.map +1 -1
  36. package/dist/plugins/postcss/tailwindCleanup.js.map +1 -1
  37. package/dist/prepare.js +1 -1
  38. package/dist/prepare.js.map +1 -1
  39. package/dist/render/active.d.ts.map +1 -1
  40. package/dist/render/createRenderer.d.ts.map +1 -1
  41. package/dist/render/createRenderer.js +3 -7
  42. package/dist/render/createRenderer.js.map +1 -1
  43. package/dist/render/index.js.map +1 -1
  44. package/dist/render/injectFonts.js.map +1 -1
  45. package/dist/render/plugins/codeBlockExtract.d.ts.map +1 -1
  46. package/dist/render/plugins/codeBlockExtract.js.map +1 -1
  47. package/dist/render/plugins/markdownExtract.d.ts.map +1 -1
  48. package/dist/render/plugins/markdownExtract.js.map +1 -1
  49. package/dist/render/plugins/rawExtract.d.ts.map +1 -1
  50. package/dist/render/plugins/rawExtract.js.map +1 -1
  51. package/dist/render/plugins/rowSourceLocation.d.ts.map +1 -1
  52. package/dist/render/plugins/rowSourceLocation.js.map +1 -1
  53. package/dist/serve.js.map +1 -1
  54. package/dist/server/compatibility.d.ts.map +1 -1
  55. package/dist/server/compatibility.js.map +1 -1
  56. package/dist/server/linter.js.map +1 -1
  57. package/dist/server/sfc-utils.js.map +1 -1
  58. package/dist/tests/render/_helpers.d.ts.map +1 -1
  59. package/dist/tests/render/_helpers.js.map +1 -1
  60. package/dist/transformers/addAttributes.js +2 -3
  61. package/dist/transformers/addAttributes.js.map +1 -1
  62. package/dist/transformers/base.d.ts +1 -1
  63. package/dist/transformers/base.d.ts.map +1 -1
  64. package/dist/transformers/base.js +5 -10
  65. package/dist/transformers/base.js.map +1 -1
  66. package/dist/transformers/columnWidth.d.ts.map +1 -1
  67. package/dist/transformers/columnWidth.js +2 -7
  68. package/dist/transformers/columnWidth.js.map +1 -1
  69. package/dist/transformers/entities.js.map +1 -1
  70. package/dist/transformers/filters/defaults.js.map +1 -1
  71. package/dist/transformers/filters/index.js.map +1 -1
  72. package/dist/transformers/format.js.map +1 -1
  73. package/dist/transformers/imgWidth.d.ts +20 -0
  74. package/dist/transformers/imgWidth.d.ts.map +1 -0
  75. package/dist/transformers/imgWidth.js +76 -0
  76. package/dist/transformers/imgWidth.js.map +1 -0
  77. package/dist/transformers/index.d.ts.map +1 -1
  78. package/dist/transformers/index.js +2 -0
  79. package/dist/transformers/index.js.map +1 -1
  80. package/dist/transformers/inlineCss.d.ts +3 -2
  81. package/dist/transformers/inlineCss.d.ts.map +1 -1
  82. package/dist/transformers/inlineCss.js.map +1 -1
  83. package/dist/transformers/inlineLink.js +1 -1
  84. package/dist/transformers/inlineLink.js.map +1 -1
  85. package/dist/transformers/minify.js.map +1 -1
  86. package/dist/transformers/minifyCodeInline.js.map +1 -1
  87. package/dist/transformers/msoPlaceholders.d.ts.map +1 -1
  88. package/dist/transformers/msoPlaceholders.js +2 -7
  89. package/dist/transformers/msoPlaceholders.js.map +1 -1
  90. package/dist/transformers/purgeCss.js.map +1 -1
  91. package/dist/transformers/replaceStrings.js.map +1 -1
  92. package/dist/transformers/safeSelectors.js.map +1 -1
  93. package/dist/transformers/shorthandCss.js.map +1 -1
  94. package/dist/transformers/tailwindComponent.js.map +1 -1
  95. package/dist/transformers/tailwindcss.js +1 -1
  96. package/dist/transformers/tailwindcss.js.map +1 -1
  97. package/dist/transformers/urlQuery.js.map +1 -1
  98. package/dist/types/config.d.ts +5 -4
  99. package/dist/types/config.d.ts.map +1 -1
  100. package/dist/utils/ast/serializer.js.map +1 -1
  101. package/dist/utils/compileTailwindCss.js.map +1 -1
  102. package/dist/utils/componentSources.js.map +1 -1
  103. package/dist/utils/cssBox.d.ts.map +1 -1
  104. package/dist/utils/cssBox.js +2 -7
  105. package/dist/utils/cssBox.js.map +1 -1
  106. package/dist/utils/decodeStyleEntities.js.map +1 -1
  107. package/dist/utils/url.js.map +1 -1
  108. package/dist/utils/watchPaths.js.map +1 -1
  109. package/node_modules/@clack/core/CHANGELOG.md +30 -0
  110. package/node_modules/@clack/core/dist/index.d.mts +109 -3
  111. package/node_modules/@clack/core/dist/index.mjs +972 -17
  112. package/node_modules/@clack/core/package.json +2 -1
  113. package/node_modules/@clack/prompts/CHANGELOG.md +42 -0
  114. package/node_modules/@clack/prompts/README.md +30 -9
  115. package/node_modules/@clack/prompts/dist/index.d.mts +458 -27
  116. package/node_modules/@clack/prompts/dist/index.mjs +1378 -141
  117. package/node_modules/@clack/prompts/package.json +2 -2
  118. package/node_modules/tinyexec/package.json +4 -4
  119. package/package.json +8 -7
  120. package/dist/components/Overlap.vue +0 -156
  121. package/node_modules/@clack/core/dist/index.mjs.map +0 -1
  122. package/node_modules/@clack/prompts/dist/index.mjs.map +0 -1
@@ -1,17 +1,972 @@
1
- import{styleText as v}from"node:util";import{stdout as x,stdin as D}from"node:process";import*as b from"node:readline";import E from"node:readline";import{wrapAnsi as M}from"fast-wrap-ansi";import{cursor as p,erase as V}from"sisteransi";import{ReadStream as O}from"node:tty";function f(r,t,s){if(!s.some(o=>!o.disabled))return r;const e=r+t,i=Math.max(s.length-1,0),n=e<0?i:e>i?0:e;return s[n].disabled?f(n,t<0?-1:1,s):n}function I(r,t,s,e){const i=e.split(`
2
- `);let n=0,o=r;for(const a of i){if(o<=a.length)break;o-=a.length+1,n++}for(n=Math.max(0,Math.min(i.length-1,n+s)),o=Math.min(o,i[n].length)+t;o<0&&n>0;)n--,o+=i[n].length+1;for(;o>i[n].length&&n<i.length-1;)o-=i[n].length+1,n++;o=Math.max(0,Math.min(i[n].length,o));let u=0;for(let a=0;a<n;a++)u+=i[a].length+1;return u+o}const G=["up","down","left","right","space","enter","cancel"],K=["January","February","March","April","May","June","July","August","September","October","November","December"],h={actions:new Set(G),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,date:{monthNames:[...K],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(r,t)=>`There are only ${r} days in ${t}`,afterMin:r=>`Date must be on or after ${r.toISOString().slice(0,10)}`,beforeMax:r=>`Date must be on or before ${r.toISOString().slice(0,10)}`}}};function j(r){if(r.aliases!==void 0){const t=r.aliases;for(const s in t){if(!Object.hasOwn(t,s))continue;const e=t[s];h.actions.has(e)&&(h.aliases.has(s)||h.aliases.set(s,e))}}if(r.messages!==void 0){const t=r.messages;t.cancel!==void 0&&(h.messages.cancel=t.cancel),t.error!==void 0&&(h.messages.error=t.error)}if(r.withGuide!==void 0&&(h.withGuide=r.withGuide!==!1),r.date!==void 0){const t=r.date;t.monthNames!==void 0&&(h.date.monthNames=[...t.monthNames]),t.messages!==void 0&&(t.messages.required!==void 0&&(h.date.messages.required=t.messages.required),t.messages.invalidMonth!==void 0&&(h.date.messages.invalidMonth=t.messages.invalidMonth),t.messages.invalidDay!==void 0&&(h.date.messages.invalidDay=t.messages.invalidDay),t.messages.afterMin!==void 0&&(h.date.messages.afterMin=t.messages.afterMin),t.messages.beforeMax!==void 0&&(h.date.messages.beforeMax=t.messages.beforeMax))}}function C(r,t){if(typeof r=="string")return h.aliases.get(r)===t;for(const s of r)if(s!==void 0&&C(s,t))return!0;return!1}function z(r,t){if(r===t)return;const s=r.split(`
3
- `),e=t.split(`
4
- `),i=Math.max(s.length,e.length),n=[];for(let o=0;o<i;o++)s[o]!==e[o]&&n.push(o);return{lines:n,numLinesBefore:s.length,numLinesAfter:e.length,numLines:i}}const Y=globalThis.process.platform.startsWith("win"),k=Symbol("clack:cancel");function q(r){return r===k}function w(r,t){const s=r;s.isTTY&&s.setRawMode(t)}function R({input:r=D,output:t=x,overwrite:s=!0,hideCursor:e=!0}={}){const i=b.createInterface({input:r,output:t,prompt:"",tabSize:1});b.emitKeypressEvents(r,i),r instanceof O&&r.isTTY&&r.setRawMode(!0);const n=(o,{name:u,sequence:a})=>{const l=String(o);if(C([l,u,a],"cancel")){e&&t.write(p.show),process.exit(0);return}if(!s)return;const c=u==="return"?0:-1,y=u==="return"?-1:0;b.moveCursor(t,c,y,()=>{b.clearLine(t,1,()=>{r.once("keypress",n)})})};return e&&t.write(p.hide),r.once("keypress",n),()=>{r.off("keypress",n),e&&t.write(p.show),r instanceof O&&r.isTTY&&!Y&&r.setRawMode(!1),i.terminal=!1,i.close()}}const A=r=>"columns"in r&&typeof r.columns=="number"?r.columns:80,L=r=>"rows"in r&&typeof r.rows=="number"?r.rows:20;function W(r,t,s,e=s,i=s,n){const o=A(r??x);return M(t,o-s.length,{hard:!0,trim:!1}).split(`
5
- `).map((u,a,l)=>{const c=n?n(u,a):u;return a===0?`${e}${c}`:a===l.length-1?`${i}${c}`:`${s}${c}`}).join(`
6
- `)}let m=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(t,s=!0){const{input:e=D,output:i=x,render:n,signal:o,...u}=t;this.opts=u,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=n.bind(this),this._track=s,this._abortSignal=o,this.input=e,this.output=i}unsubscribe(){this._subscribers.clear()}setSubscriber(t,s){const e=this._subscribers.get(t)??[];e.push(s),this._subscribers.set(t,e)}on(t,s){this.setSubscriber(t,{cb:s})}once(t,s){this.setSubscriber(t,{cb:s,once:!0})}emit(t,...s){const e=this._subscribers.get(t)??[],i=[];for(const n of e)n.cb(...s),n.once&&i.push(()=>e.splice(e.indexOf(n),1));for(const n of i)n()}prompt(){return new Promise(t=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),t(k);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=E.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),w(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(p.show),this.output.off("resize",this.render),w(this.input,!1),t(this.value)}),this.once("cancel",()=>{this.output.write(p.show),this.output.off("resize",this.render),w(this.input,!1),t(k)})})}_isActionKey(t,s){return t===" "}_shouldSubmit(t,s){return!0}_setValue(t){this.value=t,this.emit("value",this.value)}_setUserInput(t,s){this.userInput=t??"",this.emit("userInput",this.userInput),s&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}onKeypress(t,s){if(this._track&&s.name!=="return"&&(s.name&&this._isActionKey(t,s)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),s?.name&&(!this._track&&h.aliases.has(s.name)&&this.emit("cursor",h.aliases.get(s.name)),h.actions.has(s.name)&&this.emit("cursor",s.name)),t&&(t.toLowerCase()==="y"||t.toLowerCase()==="n")&&this.emit("confirm",t.toLowerCase()==="y"),this.emit("key",t?.toLowerCase(),s),s?.name==="return"&&this._shouldSubmit(t,s)){if(this.opts.validate){const e=this.opts.validate(this.value);e&&(this.error=e instanceof Error?e.message:e,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}C([t,s?.name,s?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
7
- `),w(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){const t=M(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
8
- `).length-1;this.output.write(p.move(-999,t*-1))}render(){const t=M(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(t!==this._prevFrame){if(this.state==="initial")this.output.write(p.hide);else{const s=z(this._prevFrame,t),e=L(this.output);if(this.restoreCursor(),s){const i=Math.max(0,s.numLinesAfter-e),n=Math.max(0,s.numLinesBefore-e);let o=s.lines.find(u=>u>=i);if(o===void 0){this._prevFrame=t;return}if(s.lines.length===1){this.output.write(p.move(0,o-n)),this.output.write(V.lines(1));const u=t.split(`
9
- `);this.output.write(u[o]),this._prevFrame=t,this.output.write(p.move(0,u.length-o-1));return}else if(s.lines.length>1){if(i<n)o=i;else{const a=o-n;a>0&&this.output.write(p.move(0,a))}this.output.write(V.down());const u=t.split(`
10
- `).slice(o);this.output.write(u.join(`
11
- `)),this._prevFrame=t;return}}this.output.write(V.down())}this.output.write(t),this.state==="initial"&&(this.state="active"),this._prevFrame=t}}};function B(r,t){if(r===void 0||t.length===0)return 0;const s=t.findIndex(e=>e.value===r);return s!==-1?s:0}function J(r,t){return(t.label??String(t.value)).toLowerCase().includes(r.toLowerCase())}function H(r,t){if(t)return r?t:t[0]}let Q=class extends m{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#s=0;#r="";#t;#n;#u;get cursor(){return this.#s}get userInputWithCursor(){if(!this.userInput)return v(["inverse","hidden"],"_");if(this._cursor>=this.userInput.length)return`${this.userInput}\u2588`;const t=this.userInput.slice(0,this._cursor),[s,...e]=this.userInput.slice(this._cursor);return`${t}${v("inverse",s)}${e.join("")}`}get options(){return typeof this.#n=="function"?this.#n():this.#n}constructor(t){super(t),this.#n=t.options,this.#u=t.placeholder;const s=this.options;this.filteredOptions=[...s],this.multiple=t.multiple===!0,this.#t=typeof t.options=="function"?t.filter:t.filter??J;let e;if(t.initialValue&&Array.isArray(t.initialValue)?this.multiple?e=t.initialValue:e=t.initialValue.slice(0,1):!this.multiple&&this.options.length>0&&(e=[this.options[0].value]),e)for(const i of e){const n=s.findIndex(o=>o.value===i);n!==-1&&(this.toggleSelected(i),this.#s=n)}this.focusedValue=this.options[this.#s]?.value,this.on("key",(i,n)=>this.#e(i,n)),this.on("userInput",i=>this.#i(i))}_isActionKey(t,s){return t===" "||this.multiple&&this.isNavigating&&s.name==="space"&&t!==void 0&&t!==""}#e(t,s){const e=s.name==="up",i=s.name==="down",n=s.name==="return",o=this.userInput===""||this.userInput===" ",u=this.#u,a=this.options,l=u!==void 0&&u!==""&&a.some(c=>!c.disabled&&(this.#t?this.#t(u,c):!0));if(s.name==="tab"&&o&&l){this.userInput===" "&&this._clearUserInput(),this._setUserInput(u,!0),this.isNavigating=!1;return}e||i?(this.#s=f(this.#s,e?-1:1,this.filteredOptions),this.focusedValue=this.filteredOptions[this.#s]?.value,this.multiple||(this.selectedValues=[this.focusedValue]),this.isNavigating=!0):n?this.value=H(this.multiple,this.selectedValues):this.multiple?this.focusedValue!==void 0&&(s.name==="tab"||this.isNavigating&&s.name==="space")?this.toggleSelected(this.focusedValue):this.isNavigating=!1:(this.focusedValue&&(this.selectedValues=[this.focusedValue]),this.isNavigating=!1)}deselectAll(){this.selectedValues=[]}toggleSelected(t){this.filteredOptions.length!==0&&(this.multiple?this.selectedValues.includes(t)?this.selectedValues=this.selectedValues.filter(s=>s!==t):this.selectedValues=[...this.selectedValues,t]:this.selectedValues=[t])}#i(t){if(t!==this.#r){this.#r=t;const s=this.options;t&&this.#t?this.filteredOptions=s.filter(n=>this.#t?.(t,n)):this.filteredOptions=[...s];const e=B(this.focusedValue,this.filteredOptions);this.#s=f(e,0,this.filteredOptions);const i=this.filteredOptions[this.#s];i&&!i.disabled?this.focusedValue=i.value:this.focusedValue=void 0,this.multiple||(this.focusedValue!==void 0?this.toggleSelected(this.focusedValue):this.deselectAll())}}};class X extends m{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(t){super(t,!1),this.value=!!t.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",s=>{this.output.write(p.move(0,-1)),this.value=s,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}}const Z={Y:{type:"year",len:4},M:{type:"month",len:2},D:{type:"day",len:2}};function P(r){return[...r].map(t=>Z[t])}function tt(r){const t=new Intl.DateTimeFormat(r,{year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(new Date(2e3,0,15)),s=[];let e="/";for(const i of t)i.type==="literal"?e=i.value.trim()||i.value:(i.type==="year"||i.type==="month"||i.type==="day")&&s.push({type:i.type,len:i.type==="year"?4:2});return{segments:s,separator:e}}function $(r){return Number.parseInt((r||"0").replace(/_/g,"0"),10)||0}function S(r){return{year:$(r.year),month:$(r.month),day:$(r.day)}}function U(r,t){return new Date(r||2001,t||1,0).getDate()}function F(r){const{year:t,month:s,day:e}=S(r);if(!t||t<0||t>9999||!s||s<1||s>12||!e||e<1)return;const i=new Date(Date.UTC(t,s-1,e));if(!(i.getUTCFullYear()!==t||i.getUTCMonth()!==s-1||i.getUTCDate()!==e))return{year:t,month:s,day:e}}function N(r){const t=F(r);return t?new Date(Date.UTC(t.year,t.month-1,t.day)):void 0}function st(r,t,s,e){const i=s?{year:s.getUTCFullYear(),month:s.getUTCMonth()+1,day:s.getUTCDate()}:null,n=e?{year:e.getUTCFullYear(),month:e.getUTCMonth()+1,day:e.getUTCDate()}:null;return r==="year"?{min:i?.year??1,max:n?.year??9999}:r==="month"?{min:i&&t.year===i.year?i.month:1,max:n&&t.year===n.year?n.month:12}:{min:i&&t.year===i.year&&t.month===i.month?i.day:1,max:n&&t.year===n.year&&t.month===n.month?n.day:U(t.year,t.month)}}class et extends m{#s;#r;#t;#n;#u;#e={segmentIndex:0,positionInSegment:0};#i=!0;#o=null;inlineError="";get segmentCursor(){return{...this.#e}}get segmentValues(){return{...this.#t}}get segments(){return this.#s}get separator(){return this.#r}get formattedValue(){return this.#c(this.#t)}#c(t){return this.#s.map(s=>t[s.type]).join(this.#r)}#a(){this._setUserInput(this.#c(this.#t)),this._setValue(N(this.#t)??void 0)}constructor(t){const s=t.format?{segments:P(t.format),separator:t.separator??"/"}:tt(t.locale),e=t.separator??s.separator,i=t.format?P(t.format):s.segments,n=t.initialValue??t.defaultValue,o=n?{year:String(n.getUTCFullYear()).padStart(4,"0"),month:String(n.getUTCMonth()+1).padStart(2,"0"),day:String(n.getUTCDate()).padStart(2,"0")}:{year:"____",month:"__",day:"__"},u=i.map(a=>o[a.type]).join(e);super({...t,initialUserInput:u},!1),this.#s=i,this.#r=e,this.#t=o,this.#n=t.minDate,this.#u=t.maxDate,this.#a(),this.on("cursor",a=>this.#d(a)),this.on("key",(a,l)=>this.#f(a,l)),this.on("finalize",()=>this.#g(t))}#h(){const t=Math.max(0,Math.min(this.#e.segmentIndex,this.#s.length-1)),s=this.#s[t];if(s)return this.#e.positionInSegment=Math.max(0,Math.min(this.#e.positionInSegment,s.len-1)),{segment:s,index:t}}#l(t){this.inlineError="",this.#o=null;const s=this.#h();s&&(this.#e.segmentIndex=Math.max(0,Math.min(this.#s.length-1,s.index+t)),this.#e.positionInSegment=0,this.#i=!0)}#p(t){const s=this.#h();if(!s)return;const{segment:e}=s,i=this.#t[e.type],n=!i||i.replace(/_/g,"")==="",o=Number.parseInt((i||"0").replace(/_/g,"0"),10)||0,u=st(e.type,S(this.#t),this.#n,this.#u);let a;n?a=t===1?u.min:u.max:a=Math.max(Math.min(u.max,o+t),u.min),this.#t={...this.#t,[e.type]:a.toString().padStart(e.len,"0")},this.#i=!0,this.#o=null,this.#a()}#d(t){if(t)switch(t){case"right":return this.#l(1);case"left":return this.#l(-1);case"up":return this.#p(1);case"down":return this.#p(-1)}}#f(t,s){if(s?.name==="backspace"||s?.sequence==="\x7F"||s?.sequence==="\b"||t==="\x7F"||t==="\b"){this.inlineError="";const e=this.#h();if(!e)return;if(!this.#t[e.segment.type].replace(/_/g,"")){this.#l(-1);return}this.#t[e.segment.type]="_".repeat(e.segment.len),this.#i=!0,this.#e.positionInSegment=0,this.#a();return}if(s?.name==="tab"){this.inlineError="";const e=this.#h();if(!e)return;const i=s.shift?-1:1,n=e.index+i;n>=0&&n<this.#s.length&&(this.#e.segmentIndex=n,this.#e.positionInSegment=0,this.#i=!0);return}if(t&&/^[0-9]$/.test(t)){const e=this.#h();if(!e)return;const{segment:i}=e,n=!this.#t[i.type].replace(/_/g,"");if(this.#i&&this.#o!==null&&!n){const d=this.#o+t,g={...this.#t,[i.type]:d},_=this.#m(g,i);if(_){this.inlineError=_,this.#o=null,this.#i=!1;return}this.inlineError="",this.#t[i.type]=d,this.#o=null,this.#i=!1,this.#a(),e.index<this.#s.length-1&&(this.#e.segmentIndex=e.index+1,this.#e.positionInSegment=0,this.#i=!0);return}this.#i&&!n&&(this.#t[i.type]="_".repeat(i.len),this.#e.positionInSegment=0),this.#i=!1,this.#o=null;const o=this.#t[i.type],u=o.indexOf("_"),a=u>=0?u:Math.min(this.#e.positionInSegment,i.len-1);if(a<0||a>=i.len)return;let l=o.slice(0,a)+t+o.slice(a+1),c=!1;if(a===0&&o==="__"&&(i.type==="month"||i.type==="day")){const d=Number.parseInt(t,10);l=`0${t}`,c=d<=(i.type==="month"?1:2)}if(i.type==="year"&&(l=(o.replace(/_/g,"")+t).padStart(i.len,"_")),!l.includes("_")){const d={...this.#t,[i.type]:l},g=this.#m(d,i);if(g){this.inlineError=g;return}}this.inlineError="",this.#t[i.type]=l;const y=l.includes("_")?void 0:F(this.#t);if(y){const{year:d,month:g}=y,_=U(d,g);this.#t={year:String(Math.max(0,Math.min(9999,d))).padStart(4,"0"),month:String(Math.max(1,Math.min(12,g))).padStart(2,"0"),day:String(Math.max(1,Math.min(_,y.day))).padStart(2,"0")}}this.#a();const T=l.indexOf("_");c?(this.#i=!0,this.#o=t):T>=0?this.#e.positionInSegment=T:u>=0&&e.index<this.#s.length-1?(this.#e.segmentIndex=e.index+1,this.#e.positionInSegment=0,this.#i=!0):this.#e.positionInSegment=Math.min(a+1,i.len-1)}}#m(t,s){const{month:e,day:i}=S(t);if(s.type==="month"&&(e<0||e>12))return h.date.messages.invalidMonth;if(s.type==="day"&&(i<0||i>31))return h.date.messages.invalidDay(31,"any month")}#g(t){const{year:s,month:e,day:i}=S(this.#t);if(s&&e&&i){const n=U(s,e);this.#t={...this.#t,day:String(Math.min(i,n)).padStart(2,"0")}}this.value=N(this.#t)??t.defaultValue??void 0}}class it extends m{options;cursor=0;#s;getGroupItems(t){return this.options.filter(s=>s.group===t)}isGroupSelected(t){const s=this.getGroupItems(t),e=this.value;return e===void 0?!1:s.every(i=>e.includes(i.value))}toggleValue(){const t=this.options[this.cursor];if(this.value===void 0&&(this.value=[]),t.group===!0){const s=t.value,e=this.getGroupItems(s);this.isGroupSelected(s)?this.value=this.value.filter(i=>e.findIndex(n=>n.value===i)===-1):this.value=[...this.value,...e.map(i=>i.value)],this.value=Array.from(new Set(this.value))}else{const s=this.value.includes(t.value);this.value=s?this.value.filter(e=>e!==t.value):[...this.value,t.value]}}constructor(t){super(t,!1);const{options:s}=t;this.#s=t.selectableGroups!==!1,this.options=Object.entries(s).flatMap(([e,i])=>[{value:e,group:!0,label:e},...i.map(n=>({...n,group:e}))]),this.value=[...t.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:e})=>e===t.cursorAt),this.#s?0:1),this.on("cursor",e=>{switch(e){case"left":case"up":{this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;const i=this.options[this.cursor]?.group===!0;!this.#s&&i&&(this.cursor=this.cursor===0?this.options.length-1:this.cursor-1);break}case"down":case"right":{this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;const i=this.options[this.cursor]?.group===!0;!this.#s&&i&&(this.cursor=this.cursor===this.options.length-1?0:this.cursor+1);break}case"space":this.toggleValue();break}})}}class rt extends m{#s=!1;#r;focused="editor";get userInputWithCursor(){if(this.state==="submit")return this.userInput;const t=this.userInput;if(this.cursor>=t.length)return`${t}\u2588`;const s=t.slice(0,this.cursor),e=t[this.cursor],i=t.slice(this.cursor+1);return e===`
12
- `?`${s}\u2588
13
- ${i}`:`${s}${v("inverse",e)}${i}`}get cursor(){return this._cursor}#t(t){if(this.userInput.length===0){this._setUserInput(t);return}this._setUserInput(this.userInput.slice(0,this.cursor)+t+this.userInput.slice(this.cursor))}#n(t){const s=this.value??"";switch(t){case"up":this._cursor=I(this._cursor,0,-1,s);return;case"down":this._cursor=I(this._cursor,0,1,s);return;case"left":this._cursor=I(this._cursor,-1,0,s);return;case"right":this._cursor=I(this._cursor,1,0,s);return}}_shouldSubmit(t,s){if(this.#r)return this.focused==="submit"?!0:(this.#t(`
14
- `),this._cursor++,!1);const e=this.#s;return this.#s=!0,e?(this.userInput[this.cursor-1]===`
15
- `&&(this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--),!0):(this.#t(`
16
- `),this._cursor++,!1)}constructor(t){super(t,!1),this.#r=t.showSubmit??!1,this.on("key",(s,e)=>{if(e?.name&&h.actions.has(e.name)){this.#n(e.name);return}if(s===" "&&this.#r){this.focused=this.focused==="editor"?"submit":"editor";return}if(e?.name!=="return"){if(this.#s=!1,e?.name==="backspace"&&this.cursor>0){this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--;return}if(e?.name==="delete"&&this.cursor<this.userInput.length){this._setUserInput(this.userInput.slice(0,this.cursor)+this.userInput.slice(this.cursor+1));return}s&&(this.#r&&this.focused==="submit"&&(this.focused="editor"),this.#t(s??""),this._cursor++)}}),this.on("userInput",s=>{this._setValue(s)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}}let nt=class extends m{options;cursor=0;get _value(){return this.options[this.cursor].value}get _enabledOptions(){return this.options.filter(t=>t.disabled!==!0)}toggleAll(){const t=this._enabledOptions,s=this.value!==void 0&&this.value.length===t.length;this.value=s?[]:t.map(e=>e.value)}toggleInvert(){const t=this.value;if(!t)return;const s=this._enabledOptions.filter(e=>!t.includes(e.value));this.value=s.map(e=>e.value)}toggleValue(){this.value===void 0&&(this.value=[]);const t=this.value.includes(this._value);this.value=t?this.value.filter(s=>s!==this._value):[...this.value,this._value]}constructor(t){super(t,!1),this.options=t.options,this.value=[...t.initialValues??[]];const s=Math.max(this.options.findIndex(({value:e})=>e===t.cursorAt),0);this.cursor=this.options[s].disabled?f(s,1,this.options):s,this.on("key",e=>{e==="a"&&this.toggleAll(),e==="i"&&this.toggleInvert()}),this.on("cursor",e=>{switch(e){case"left":case"up":this.cursor=f(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=f(this.cursor,1,this.options);break;case"space":this.toggleValue();break}})}};class ot extends m{_mask="\u2022";get cursor(){return this._cursor}get masked(){return this.userInput.replaceAll(/./g,this._mask)}get userInputWithCursor(){if(this.state==="submit"||this.state==="cancel")return this.masked;const t=this.userInput;if(this.cursor>=t.length)return`${this.masked}${v(["inverse","hidden"],"_")}`;const s=this.masked,e=s.slice(0,this.cursor),i=s.slice(this.cursor);return`${e}${v("inverse",i[0])}${i.slice(1)}`}clear(){this._clearUserInput()}constructor({mask:t,...s}){super(s),this._mask=t??"\u2022",this.on("userInput",e=>{this._setValue(e)})}}class ut extends m{options;cursor=0;get _selectedValue(){return this.options[this.cursor]}changeValue(){this.value=this._selectedValue.value}constructor(t){super(t,!1),this.options=t.options;const s=this.options.findIndex(({value:i})=>i===t.initialValue),e=s===-1?0:s;this.cursor=this.options[e].disabled?f(e,1,this.options):e,this.changeValue(),this.on("cursor",i=>{switch(i){case"left":case"up":this.cursor=f(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=f(this.cursor,1,this.options);break}this.changeValue()})}}class at extends m{options;cursor=0;constructor(t){super(t,!1),this.options=t.options;const s=t.caseSensitive===!0,e=this.options.map(({value:[i]})=>s?i:i?.toLowerCase());this.cursor=Math.max(e.indexOf(t.initialValue),0),this.on("key",(i,n)=>{if(!i)return;const o=s&&n.shift?i.toUpperCase():i;if(!e.includes(o))return;const u=this.options.find(({value:[a]})=>s?a===o:a?.toLowerCase()===i);u&&(this.value=u.value,this.state="submit",this.emit("submit"))})}}class ht extends m{get userInputWithCursor(){if(this.state==="submit")return this.userInput;const t=this.userInput;if(this.cursor>=t.length)return`${this.userInput}\u2588`;const s=t.slice(0,this.cursor),[e,...i]=t.slice(this.cursor);return`${s}${v("inverse",e)}${i.join("")}`}get cursor(){return this._cursor}constructor(t){super({...t,initialUserInput:t.initialUserInput??t.initialValue}),this.on("userInput",s=>{this._setValue(s)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}}export{Q as AutocompletePrompt,X as ConfirmPrompt,et as DatePrompt,it as GroupMultiSelectPrompt,rt as MultiLinePrompt,nt as MultiSelectPrompt,ot as PasswordPrompt,m as Prompt,at as SelectKeyPrompt,ut as SelectPrompt,ht as TextPrompt,R as block,A as getColumns,L as getRows,q as isCancel,h as settings,j as updateSettings,W as wrapTextWithPrefix};
17
- //# sourceMappingURL=index.mjs.map
1
+ import { styleText } from 'node:util';
2
+ import { stdout, stdin } from 'node:process';
3
+ import * as l from 'node:readline';
4
+ import l__default from 'node:readline';
5
+ import { wrapAnsi } from 'fast-wrap-ansi';
6
+ import { cursor, erase } from 'sisteransi';
7
+ import { ReadStream } from 'node:tty';
8
+
9
+ function findCursor(s, o, l) {
10
+ if (!l.some((r) => !r.disabled))
11
+ return s;
12
+ const t = s + o, n = Math.max(l.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
13
+ return l[e].disabled ? findCursor(e, o < 0 ? -1 : 1, l) : e;
14
+ }
15
+ function findTextCursor(s, o, l, i) {
16
+ const t = i.split(`
17
+ `);
18
+ let n = 0, e = s;
19
+ for (const r of t) {
20
+ if (e <= r.length)
21
+ break;
22
+ e -= r.length + 1, n++;
23
+ }
24
+ for (n = Math.max(0, Math.min(t.length - 1, n + l)), e = Math.min(e, t[n].length) + o; e < 0 && n > 0; )
25
+ n--, e += t[n].length + 1;
26
+ for (; e > t[n].length && n < t.length - 1; )
27
+ e -= t[n].length + 1, n++;
28
+ e = Math.max(0, Math.min(t[n].length, e));
29
+ let h = 0;
30
+ for (let r = 0; r < n; r++)
31
+ h += t[r].length + 1;
32
+ return h + e;
33
+ }
34
+
35
+ const a$2 = ["up", "down", "left", "right", "space", "enter", "cancel"], t = [
36
+ "January",
37
+ "February",
38
+ "March",
39
+ "April",
40
+ "May",
41
+ "June",
42
+ "July",
43
+ "August",
44
+ "September",
45
+ "October",
46
+ "November",
47
+ "December"
48
+ ];
49
+ const settings = {
50
+ actions: new Set(a$2),
51
+ aliases: /* @__PURE__ */ new Map([
52
+ // vim support
53
+ ["k", "up"],
54
+ ["j", "down"],
55
+ ["h", "left"],
56
+ ["l", "right"],
57
+ ["", "cancel"],
58
+ // opinionated defaults!
59
+ ["escape", "cancel"]
60
+ ]),
61
+ messages: {
62
+ cancel: "Canceled",
63
+ error: "Something went wrong"
64
+ },
65
+ withGuide: true,
66
+ date: {
67
+ monthNames: [...t],
68
+ messages: {
69
+ required: "Please enter a valid date",
70
+ invalidMonth: "There are only 12 months in a year",
71
+ invalidDay: (n, e) => `There are only ${n} days in ${e}`,
72
+ afterMin: (n) => `Date must be on or after ${n.toISOString().slice(0, 10)}`,
73
+ beforeMax: (n) => `Date must be on or before ${n.toISOString().slice(0, 10)}`
74
+ }
75
+ }
76
+ };
77
+ function updateSettings(n) {
78
+ if (n.aliases !== void 0) {
79
+ const e = n.aliases;
80
+ for (const s in e) {
81
+ if (!Object.hasOwn(e, s)) continue;
82
+ const i = e[s];
83
+ settings.actions.has(i) && (settings.aliases.has(s) || settings.aliases.set(s, i));
84
+ }
85
+ }
86
+ if (n.messages !== void 0) {
87
+ const e = n.messages;
88
+ e.cancel !== void 0 && (settings.messages.cancel = e.cancel), e.error !== void 0 && (settings.messages.error = e.error);
89
+ }
90
+ if (n.withGuide !== void 0 && (settings.withGuide = n.withGuide !== false), n.date !== void 0) {
91
+ const e = n.date;
92
+ e.monthNames !== void 0 && (settings.date.monthNames = [...e.monthNames]), e.messages !== void 0 && (e.messages.required !== void 0 && (settings.date.messages.required = e.messages.required), e.messages.invalidMonth !== void 0 && (settings.date.messages.invalidMonth = e.messages.invalidMonth), e.messages.invalidDay !== void 0 && (settings.date.messages.invalidDay = e.messages.invalidDay), e.messages.afterMin !== void 0 && (settings.date.messages.afterMin = e.messages.afterMin), e.messages.beforeMax !== void 0 && (settings.date.messages.beforeMax = e.messages.beforeMax));
93
+ }
94
+ }
95
+ function isActionKey(n, e) {
96
+ if (typeof n == "string")
97
+ return settings.aliases.get(n) === e;
98
+ for (const s of n)
99
+ if (s !== void 0 && isActionKey(s, e))
100
+ return true;
101
+ return false;
102
+ }
103
+
104
+ function diffLines(i, s) {
105
+ if (i === s) return;
106
+ const e = i.split(`
107
+ `), t = s.split(`
108
+ `), r = Math.max(e.length, t.length), f = [];
109
+ for (let n = 0; n < r; n++)
110
+ e[n] !== t[n] && f.push(n);
111
+ return {
112
+ lines: f,
113
+ numLinesBefore: e.length,
114
+ numLinesAfter: t.length,
115
+ numLines: r
116
+ };
117
+ }
118
+
119
+ const R = globalThis.process.platform.startsWith("win");
120
+ const CANCEL_SYMBOL = Symbol("clack:cancel");
121
+ function isCancel(e) {
122
+ return e === CANCEL_SYMBOL;
123
+ }
124
+ function setRawMode(e, r) {
125
+ const o = e;
126
+ o.isTTY && o.setRawMode(r);
127
+ }
128
+ function block({
129
+ input: e = stdin,
130
+ output: r = stdout,
131
+ overwrite: o = true,
132
+ hideCursor: t = true
133
+ } = {}) {
134
+ const s = l.createInterface({
135
+ input: e,
136
+ output: r,
137
+ prompt: "",
138
+ tabSize: 1
139
+ });
140
+ l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
141
+ const n = (f, { name: a, sequence: p }) => {
142
+ const c = String(f);
143
+ if (isActionKey([c, a, p], "cancel")) {
144
+ t && r.write(cursor.show), process.exit(0);
145
+ return;
146
+ }
147
+ if (!o) return;
148
+ const i = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
149
+ l.moveCursor(r, i, m, () => {
150
+ l.clearLine(r, 1, () => {
151
+ e.once("keypress", n);
152
+ });
153
+ });
154
+ };
155
+ return t && r.write(cursor.hide), e.once("keypress", n), () => {
156
+ e.off("keypress", n), t && r.write(cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
157
+ };
158
+ }
159
+ const getColumns = (e) => "columns" in e && typeof e.columns == "number" ? e.columns : 80, getRows = (e) => "rows" in e && typeof e.rows == "number" ? e.rows : 20;
160
+ function wrapTextWithPrefix(e, r, o, t = o, s = o, n) {
161
+ const f = getColumns(e ?? stdout);
162
+ return wrapAnsi(r, f - o.length, {
163
+ hard: true,
164
+ trim: false
165
+ }).split(`
166
+ `).map((c, i, m) => {
167
+ const d = n ? n(c, i) : c;
168
+ return i === 0 ? `${t}${d}` : i === m.length - 1 ? `${s}${d}` : `${o}${d}`;
169
+ }).join(`
170
+ `);
171
+ }
172
+
173
+ function runValidation(e, n) {
174
+ if ("~standard" in e) {
175
+ const a = e["~standard"].validate(n);
176
+ if (a instanceof Promise)
177
+ throw new TypeError(
178
+ "Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic."
179
+ );
180
+ return a.issues?.at(0)?.message;
181
+ }
182
+ return e(n);
183
+ }
184
+
185
+ class V {
186
+ input;
187
+ output;
188
+ _abortSignal;
189
+ rl;
190
+ opts;
191
+ _render;
192
+ _track = false;
193
+ _prevFrame = "";
194
+ _subscribers = /* @__PURE__ */ new Map();
195
+ _cursor = 0;
196
+ state = "initial";
197
+ error = "";
198
+ value;
199
+ userInput = "";
200
+ constructor(t, e = true) {
201
+ const { input: i = stdin, output: n = stdout, render: s, signal: r, ...o } = t;
202
+ this.opts = o, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = s.bind(this), this._track = e, this._abortSignal = r, this.input = i, this.output = n;
203
+ }
204
+ /**
205
+ * Unsubscribe all listeners
206
+ */
207
+ unsubscribe() {
208
+ this._subscribers.clear();
209
+ }
210
+ /**
211
+ * Set a subscriber with opts
212
+ * @param event - The event name
213
+ */
214
+ setSubscriber(t, e) {
215
+ const i = this._subscribers.get(t) ?? [];
216
+ i.push(e), this._subscribers.set(t, i);
217
+ }
218
+ /**
219
+ * Subscribe to an event
220
+ * @param event - The event name
221
+ * @param cb - The callback
222
+ */
223
+ on(t, e) {
224
+ this.setSubscriber(t, { cb: e });
225
+ }
226
+ /**
227
+ * Subscribe to an event once
228
+ * @param event - The event name
229
+ * @param cb - The callback
230
+ */
231
+ once(t, e) {
232
+ this.setSubscriber(t, { cb: e, once: true });
233
+ }
234
+ /**
235
+ * Emit an event with data
236
+ * @param event - The event name
237
+ * @param data - The data to pass to the callback
238
+ */
239
+ emit(t, ...e) {
240
+ const i = this._subscribers.get(t) ?? [], n = [];
241
+ for (const s of i)
242
+ s.cb(...e), s.once && n.push(() => i.splice(i.indexOf(s), 1));
243
+ for (const s of n)
244
+ s();
245
+ }
246
+ prompt() {
247
+ return new Promise((t) => {
248
+ if (this._abortSignal) {
249
+ if (this._abortSignal.aborted)
250
+ return this.state = "cancel", this.close(), t(CANCEL_SYMBOL);
251
+ this._abortSignal.addEventListener(
252
+ "abort",
253
+ () => {
254
+ this.state = "cancel", this.close();
255
+ },
256
+ { once: true }
257
+ );
258
+ }
259
+ this.rl = l__default.createInterface({
260
+ input: this.input,
261
+ tabSize: 2,
262
+ prompt: "",
263
+ escapeCodeTimeout: 50,
264
+ terminal: true
265
+ }), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), setRawMode(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
266
+ this.output.write(cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(this.value);
267
+ }), this.once("cancel", () => {
268
+ this.output.write(cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(CANCEL_SYMBOL);
269
+ });
270
+ });
271
+ }
272
+ _isActionKey(t, e) {
273
+ return t === " ";
274
+ }
275
+ _shouldSubmit(t, e) {
276
+ return true;
277
+ }
278
+ _setValue(t) {
279
+ this.value = t, this.emit("value", this.value);
280
+ }
281
+ _setUserInput(t, e) {
282
+ this.userInput = t ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
283
+ }
284
+ _clearUserInput() {
285
+ this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
286
+ }
287
+ onKeypress(t, e) {
288
+ if (this._track && e.name !== "return" && (e.name && this._isActionKey(t, e) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), e?.name && (!this._track && settings.aliases.has(e.name) && this.emit("cursor", settings.aliases.get(e.name)), settings.actions.has(e.name) && this.emit("cursor", e.name)), t && (t.toLowerCase() === "y" || t.toLowerCase() === "n") && this.emit("confirm", t.toLowerCase() === "y"), this.emit("key", t, e), e?.name === "return" && this._shouldSubmit(t, e)) {
289
+ if (this.opts.validate) {
290
+ const i = runValidation(this.opts.validate, this.value);
291
+ i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
292
+ }
293
+ this.state !== "error" && (this.state = "submit");
294
+ }
295
+ isActionKey([t, e?.name, e?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
296
+ }
297
+ close() {
298
+ this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
299
+ `), setRawMode(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
300
+ }
301
+ restoreCursor() {
302
+ const t = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
303
+ `).length - 1;
304
+ this.output.write(cursor.move(-999, t * -1));
305
+ }
306
+ render() {
307
+ const t = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
308
+ hard: true,
309
+ trim: false
310
+ });
311
+ if (t !== this._prevFrame) {
312
+ if (this.state === "initial")
313
+ this.output.write(cursor.hide);
314
+ else {
315
+ const e = diffLines(this._prevFrame, t), i = getRows(this.output);
316
+ if (this.restoreCursor(), e) {
317
+ const n = Math.max(0, e.numLinesAfter - i), s = Math.max(0, e.numLinesBefore - i);
318
+ let r = e.lines.find((o) => o >= n);
319
+ if (r === void 0) {
320
+ this._prevFrame = t;
321
+ return;
322
+ }
323
+ if (e.lines.length === 1) {
324
+ this.output.write(cursor.move(0, r - s)), this.output.write(erase.lines(1));
325
+ const o = t.split(`
326
+ `);
327
+ this.output.write(o[r]), this._prevFrame = t, this.output.write(cursor.move(0, o.length - r - 1));
328
+ return;
329
+ } else if (e.lines.length > 1) {
330
+ if (n < s)
331
+ r = n;
332
+ else {
333
+ const h = r - s;
334
+ h > 0 && this.output.write(cursor.move(0, h));
335
+ }
336
+ this.output.write(erase.down());
337
+ const f = t.split(`
338
+ `).slice(r);
339
+ this.output.write(f.join(`
340
+ `)), this._prevFrame = t;
341
+ return;
342
+ }
343
+ }
344
+ this.output.write(erase.down());
345
+ }
346
+ this.output.write(t), this.state === "initial" && (this.state = "active"), this._prevFrame = t;
347
+ }
348
+ }
349
+ }
350
+
351
+ function p$1(l, e) {
352
+ if (l === void 0 || e.length === 0)
353
+ return 0;
354
+ const i = e.findIndex((s) => s.value === l);
355
+ return i !== -1 ? i : 0;
356
+ }
357
+ function g(l, e) {
358
+ return (e.label ?? String(e.value)).toLowerCase().includes(l.toLowerCase());
359
+ }
360
+ function m(l, e) {
361
+ if (e)
362
+ return l ? e : e[0];
363
+ }
364
+ let T$1 = class T extends V {
365
+ filteredOptions;
366
+ multiple;
367
+ isNavigating = false;
368
+ selectedValues = [];
369
+ focusedValue;
370
+ #e = 0;
371
+ #s = "";
372
+ #t;
373
+ #i;
374
+ #n;
375
+ get cursor() {
376
+ return this.#e;
377
+ }
378
+ get userInputWithCursor() {
379
+ if (!this.userInput)
380
+ return styleText(["inverse", "hidden"], "_");
381
+ if (this._cursor >= this.userInput.length)
382
+ return `${this.userInput}\u2588`;
383
+ const e = this.userInput.slice(0, this._cursor), [t, ...i] = this.userInput.slice(this._cursor);
384
+ return `${e}${styleText("inverse", t)}${i.join("")}`;
385
+ }
386
+ get options() {
387
+ return typeof this.#i == "function" ? this.#i() : this.#i;
388
+ }
389
+ constructor(e) {
390
+ super(e), this.#i = e.options, this.#n = e.placeholder;
391
+ const t = this.options;
392
+ this.filteredOptions = [...t], this.multiple = e.multiple === true, this.#t = typeof e.options == "function" ? e.filter : e.filter ?? g;
393
+ let i;
394
+ if (e.initialValue && Array.isArray(e.initialValue) ? this.multiple ? i = e.initialValue : i = e.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (i = [this.options[0].value]), i)
395
+ for (const s of i) {
396
+ const n = t.findIndex((o) => o.value === s);
397
+ n !== -1 && (this.toggleSelected(s), this.#e = n);
398
+ }
399
+ this.focusedValue = this.options[this.#e]?.value, this.on("key", (s, n) => this.#l(s, n)), this.on("userInput", (s) => this.#u(s));
400
+ }
401
+ _isActionKey(e, t) {
402
+ return e === " " || this.multiple && this.isNavigating && t.name === "space" && e !== void 0 && e !== "";
403
+ }
404
+ #l(e, t) {
405
+ const i = t.name === "up", s = t.name === "down", n = t.name === "return", o = this.userInput === "" || this.userInput === " ", u = this.#n, h = this.options, f = u !== void 0 && u !== "" && h.some(
406
+ (r) => !r.disabled && (this.#t ? this.#t(u, r) : true)
407
+ );
408
+ if (t.name === "tab" && o && f) {
409
+ this.userInput === " " && this._clearUserInput(), this._setUserInput(u, true), this.isNavigating = false;
410
+ return;
411
+ }
412
+ i || s ? (this.#e = findCursor(this.#e, i ? -1 : 1, this.filteredOptions), this.focusedValue = this.filteredOptions[this.#e]?.value, this.multiple || (this.selectedValues = [this.focusedValue]), this.isNavigating = true) : n ? this.value = m(this.multiple, this.selectedValues) : this.multiple ? this.focusedValue !== void 0 && (t.name === "tab" || this.isNavigating && t.name === "space") ? this.toggleSelected(this.focusedValue) : this.isNavigating = false : (this.focusedValue && (this.selectedValues = [this.focusedValue]), this.isNavigating = false);
413
+ }
414
+ deselectAll() {
415
+ this.selectedValues = [];
416
+ }
417
+ toggleSelected(e) {
418
+ this.filteredOptions.length !== 0 && (this.multiple ? this.selectedValues.includes(e) ? this.selectedValues = this.selectedValues.filter((t) => t !== e) : this.selectedValues = [...this.selectedValues, e] : this.selectedValues = [e]);
419
+ }
420
+ #u(e) {
421
+ if (e !== this.#s) {
422
+ this.#s = e;
423
+ const t = this.options;
424
+ e && this.#t ? this.filteredOptions = t.filter((n) => this.#t?.(e, n)) : this.filteredOptions = [...t];
425
+ const i = p$1(this.focusedValue, this.filteredOptions);
426
+ this.#e = findCursor(i, 0, this.filteredOptions);
427
+ const s = this.filteredOptions[this.#e];
428
+ s && !s.disabled ? this.focusedValue = s.value : this.focusedValue = void 0, this.multiple || (this.focusedValue !== void 0 ? this.toggleSelected(this.focusedValue) : this.deselectAll());
429
+ }
430
+ }
431
+ };
432
+
433
+ class r extends V {
434
+ get cursor() {
435
+ return this.value ? 0 : 1;
436
+ }
437
+ get _value() {
438
+ return this.cursor === 0;
439
+ }
440
+ constructor(t) {
441
+ super(t, false), this.value = !!t.initialValue, this.on("userInput", () => {
442
+ this.value = this._value;
443
+ }), this.on("confirm", (i) => {
444
+ this.output.write(cursor.move(0, -1)), this.value = i, this.state = "submit", this.close();
445
+ }), this.on("cursor", () => {
446
+ this.value = !this.value;
447
+ });
448
+ }
449
+ }
450
+
451
+ const _ = {
452
+ Y: { type: "year", len: 4 },
453
+ M: { type: "month", len: 2 },
454
+ D: { type: "day", len: 2 }
455
+ };
456
+ function M(r) {
457
+ return [...r].map((t) => _[t]);
458
+ }
459
+ function P(r) {
460
+ const i = new Intl.DateTimeFormat(r, {
461
+ year: "numeric",
462
+ month: "2-digit",
463
+ day: "2-digit"
464
+ }).formatToParts(new Date(2e3, 0, 15)), s = [];
465
+ let n = "/";
466
+ for (const e of i)
467
+ e.type === "literal" ? n = e.value.trim() || e.value : (e.type === "year" || e.type === "month" || e.type === "day") && s.push({ type: e.type, len: e.type === "year" ? 4 : 2 });
468
+ return { segments: s, separator: n };
469
+ }
470
+ function p(r) {
471
+ return Number.parseInt((r || "0").replace(/_/g, "0"), 10) || 0;
472
+ }
473
+ function f(r) {
474
+ return {
475
+ year: p(r.year),
476
+ month: p(r.month),
477
+ day: p(r.day)
478
+ };
479
+ }
480
+ function c(r, t) {
481
+ return new Date(r || 2001, t || 1, 0).getDate();
482
+ }
483
+ function b(r) {
484
+ const { year: t, month: i, day: s } = f(r);
485
+ if (!t || t < 0 || t > 9999 || !i || i < 1 || i > 12 || !s || s < 1) return;
486
+ const n = new Date(Date.UTC(t, i - 1, s));
487
+ if (!(n.getUTCFullYear() !== t || n.getUTCMonth() !== i - 1 || n.getUTCDate() !== s))
488
+ return { year: t, month: i, day: s };
489
+ }
490
+ function C(r) {
491
+ const t = b(r);
492
+ return t ? new Date(Date.UTC(t.year, t.month - 1, t.day)) : void 0;
493
+ }
494
+ function T(r, t, i, s) {
495
+ const n = i ? {
496
+ year: i.getUTCFullYear(),
497
+ month: i.getUTCMonth() + 1,
498
+ day: i.getUTCDate()
499
+ } : null, e = s ? {
500
+ year: s.getUTCFullYear(),
501
+ month: s.getUTCMonth() + 1,
502
+ day: s.getUTCDate()
503
+ } : null;
504
+ return r === "year" ? { min: n?.year ?? 1, max: e?.year ?? 9999 } : r === "month" ? {
505
+ min: n && t.year === n.year ? n.month : 1,
506
+ max: e && t.year === e.year ? e.month : 12
507
+ } : {
508
+ min: n && t.year === n.year && t.month === n.month ? n.day : 1,
509
+ max: e && t.year === e.year && t.month === e.month ? e.day : c(t.year, t.month)
510
+ };
511
+ }
512
+ class U extends V {
513
+ #i;
514
+ #o;
515
+ #t;
516
+ #h;
517
+ #u;
518
+ #e = { segmentIndex: 0, positionInSegment: 0 };
519
+ #n = true;
520
+ #s = null;
521
+ inlineError = "";
522
+ get segmentCursor() {
523
+ return { ...this.#e };
524
+ }
525
+ get segmentValues() {
526
+ return { ...this.#t };
527
+ }
528
+ get segments() {
529
+ return this.#i;
530
+ }
531
+ get separator() {
532
+ return this.#o;
533
+ }
534
+ get formattedValue() {
535
+ return this.#l(this.#t);
536
+ }
537
+ #l(t) {
538
+ return this.#i.map((i) => t[i.type]).join(this.#o);
539
+ }
540
+ #r() {
541
+ this._setUserInput(this.#l(this.#t)), this._setValue(C(this.#t) ?? void 0);
542
+ }
543
+ constructor(t) {
544
+ const i = t.format ? { segments: M(t.format), separator: t.separator ?? "/" } : P(t.locale), s = t.separator ?? i.separator, n = t.format ? M(t.format) : i.segments, e = t.initialValue ?? t.defaultValue, m = e ? {
545
+ year: String(e.getUTCFullYear()).padStart(4, "0"),
546
+ month: String(e.getUTCMonth() + 1).padStart(2, "0"),
547
+ day: String(e.getUTCDate()).padStart(2, "0")
548
+ } : { year: "____", month: "__", day: "__" }, o = n.map((a) => m[a.type]).join(s);
549
+ super({ ...t, initialUserInput: o }, false), this.#i = n, this.#o = s, this.#t = m, this.#h = t.minDate, this.#u = t.maxDate, this.#r(), this.on("cursor", (a) => this.#f(a)), this.on("key", (a, u) => this.#y(a, u)), this.on("finalize", () => this.#p(t));
550
+ }
551
+ #a() {
552
+ const t = Math.max(0, Math.min(this.#e.segmentIndex, this.#i.length - 1)), i = this.#i[t];
553
+ if (i)
554
+ return this.#e.positionInSegment = Math.max(
555
+ 0,
556
+ Math.min(this.#e.positionInSegment, i.len - 1)
557
+ ), { segment: i, index: t };
558
+ }
559
+ #m(t) {
560
+ this.inlineError = "", this.#s = null;
561
+ const i = this.#a();
562
+ i && (this.#e.segmentIndex = Math.max(
563
+ 0,
564
+ Math.min(this.#i.length - 1, i.index + t)
565
+ ), this.#e.positionInSegment = 0, this.#n = true);
566
+ }
567
+ #d(t) {
568
+ const i = this.#a();
569
+ if (!i) return;
570
+ const { segment: s } = i, n = this.#t[s.type], e = !n || n.replace(/_/g, "") === "", m = Number.parseInt((n || "0").replace(/_/g, "0"), 10) || 0, o = T(
571
+ s.type,
572
+ f(this.#t),
573
+ this.#h,
574
+ this.#u
575
+ );
576
+ let a;
577
+ e ? a = t === 1 ? o.min : o.max : a = Math.max(Math.min(o.max, m + t), o.min), this.#t = {
578
+ ...this.#t,
579
+ [s.type]: a.toString().padStart(s.len, "0")
580
+ }, this.#n = true, this.#s = null, this.#r();
581
+ }
582
+ #f(t) {
583
+ if (t)
584
+ switch (t) {
585
+ case "right":
586
+ return this.#m(1);
587
+ case "left":
588
+ return this.#m(-1);
589
+ case "up":
590
+ return this.#d(1);
591
+ case "down":
592
+ return this.#d(-1);
593
+ }
594
+ }
595
+ #y(t, i) {
596
+ if (i?.name === "backspace" || i?.sequence === "\x7F" || i?.sequence === "\b" || t === "\x7F" || t === "\b") {
597
+ this.inlineError = "";
598
+ const n = this.#a();
599
+ if (!n) return;
600
+ if (!this.#t[n.segment.type].replace(/_/g, "")) {
601
+ this.#m(-1);
602
+ return;
603
+ }
604
+ this.#t[n.segment.type] = "_".repeat(n.segment.len), this.#n = true, this.#e.positionInSegment = 0, this.#r();
605
+ return;
606
+ }
607
+ if (i?.name === "tab") {
608
+ this.inlineError = "";
609
+ const n = this.#a();
610
+ if (!n) return;
611
+ const e = i.shift ? -1 : 1, m = n.index + e;
612
+ m >= 0 && m < this.#i.length && (this.#e.segmentIndex = m, this.#e.positionInSegment = 0, this.#n = true);
613
+ return;
614
+ }
615
+ if (t && /^[0-9]$/.test(t)) {
616
+ const n = this.#a();
617
+ if (!n) return;
618
+ const { segment: e } = n, m = !this.#t[e.type].replace(/_/g, "");
619
+ if (this.#n && this.#s !== null && !m) {
620
+ const h = this.#s + t, d = { ...this.#t, [e.type]: h }, g = this.#g(d, e);
621
+ if (g) {
622
+ this.inlineError = g, this.#s = null, this.#n = false;
623
+ return;
624
+ }
625
+ this.inlineError = "", this.#t[e.type] = h, this.#s = null, this.#n = false, this.#r(), n.index < this.#i.length - 1 && (this.#e.segmentIndex = n.index + 1, this.#e.positionInSegment = 0, this.#n = true);
626
+ return;
627
+ }
628
+ this.#n && !m && (this.#t[e.type] = "_".repeat(e.len), this.#e.positionInSegment = 0), this.#n = false, this.#s = null;
629
+ const o = this.#t[e.type], a = o.indexOf("_"), u = a >= 0 ? a : Math.min(this.#e.positionInSegment, e.len - 1);
630
+ if (u < 0 || u >= e.len) return;
631
+ let l = o.slice(0, u) + t + o.slice(u + 1), D = false;
632
+ if (u === 0 && o === "__" && (e.type === "month" || e.type === "day")) {
633
+ const h = Number.parseInt(t, 10);
634
+ l = `0${t}`, D = h <= (e.type === "month" ? 1 : 2);
635
+ }
636
+ if (e.type === "year" && (l = (o.replace(/_/g, "") + t).padStart(e.len, "_")), !l.includes("_")) {
637
+ const h = { ...this.#t, [e.type]: l }, d = this.#g(h, e);
638
+ if (d) {
639
+ this.inlineError = d;
640
+ return;
641
+ }
642
+ }
643
+ this.inlineError = "", this.#t[e.type] = l;
644
+ const y = l.includes("_") ? void 0 : b(this.#t);
645
+ if (y) {
646
+ const { year: h, month: d } = y, g = c(h, d);
647
+ this.#t = {
648
+ year: String(Math.max(0, Math.min(9999, h))).padStart(4, "0"),
649
+ month: String(Math.max(1, Math.min(12, d))).padStart(2, "0"),
650
+ day: String(Math.max(1, Math.min(g, y.day))).padStart(2, "0")
651
+ };
652
+ }
653
+ this.#r();
654
+ const S = l.indexOf("_");
655
+ D ? (this.#n = true, this.#s = t) : S >= 0 ? this.#e.positionInSegment = S : a >= 0 && n.index < this.#i.length - 1 ? (this.#e.segmentIndex = n.index + 1, this.#e.positionInSegment = 0, this.#n = true) : this.#e.positionInSegment = Math.min(u + 1, e.len - 1);
656
+ }
657
+ }
658
+ #g(t, i) {
659
+ const { month: s, day: n } = f(t);
660
+ if (i.type === "month" && (s < 0 || s > 12))
661
+ return settings.date.messages.invalidMonth;
662
+ if (i.type === "day" && (n < 0 || n > 31))
663
+ return settings.date.messages.invalidDay(31, "any month");
664
+ }
665
+ #p(t) {
666
+ const { year: i, month: s, day: n } = f(this.#t);
667
+ if (i && s && n) {
668
+ const e = c(i, s);
669
+ this.#t = {
670
+ ...this.#t,
671
+ day: String(Math.min(n, e)).padStart(2, "0")
672
+ };
673
+ }
674
+ this.value = C(this.#t) ?? t.defaultValue ?? void 0;
675
+ }
676
+ }
677
+
678
+ let u$1 = class u extends V {
679
+ options;
680
+ cursor = 0;
681
+ #t;
682
+ getGroupItems(t) {
683
+ return this.options.filter((r) => r.group === t);
684
+ }
685
+ isGroupSelected(t) {
686
+ const r = this.getGroupItems(t), e = this.value;
687
+ return e === void 0 ? false : r.every((s) => e.includes(s.value));
688
+ }
689
+ toggleValue() {
690
+ const t = this.options[this.cursor];
691
+ if (this.value === void 0 && (this.value = []), t.group === true) {
692
+ const r = t.value, e = this.getGroupItems(r);
693
+ this.isGroupSelected(r) ? this.value = this.value.filter(
694
+ (s) => e.findIndex((i) => i.value === s) === -1
695
+ ) : this.value = [...this.value, ...e.map((s) => s.value)], this.value = Array.from(new Set(this.value));
696
+ } else {
697
+ const r = this.value.includes(t.value);
698
+ this.value = r ? this.value.filter((e) => e !== t.value) : [...this.value, t.value];
699
+ }
700
+ }
701
+ constructor(t) {
702
+ super(t, false);
703
+ const { options: r } = t;
704
+ this.#t = t.selectableGroups !== false, this.options = Object.entries(r).flatMap(([e, s]) => [
705
+ { value: e, group: true, label: e },
706
+ ...s.map((i) => ({ ...i, group: e }))
707
+ ]), this.value = [...t.initialValues ?? []], this.cursor = Math.max(
708
+ this.options.findIndex(({ value: e }) => e === t.cursorAt),
709
+ this.#t ? 0 : 1
710
+ ), this.on("cursor", (e) => {
711
+ switch (e) {
712
+ case "left":
713
+ case "up": {
714
+ this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
715
+ const s = this.options[this.cursor]?.group === true;
716
+ !this.#t && s && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
717
+ break;
718
+ }
719
+ case "down":
720
+ case "right": {
721
+ this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
722
+ const s = this.options[this.cursor]?.group === true;
723
+ !this.#t && s && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
724
+ break;
725
+ }
726
+ case "space":
727
+ this.toggleValue();
728
+ break;
729
+ }
730
+ });
731
+ }
732
+ };
733
+
734
+ const o$1 = /* @__PURE__ */ new Set(["up", "down", "left", "right"]);
735
+ class h extends V {
736
+ #s = false;
737
+ #t;
738
+ focused = "editor";
739
+ get userInputWithCursor() {
740
+ if (this.state === "submit")
741
+ return this.userInput;
742
+ const t = this.userInput;
743
+ if (this.cursor >= t.length)
744
+ return `${t}\u2588`;
745
+ const s = t.slice(0, this.cursor), r = t[this.cursor], e = t.slice(this.cursor + 1);
746
+ return r === `
747
+ ` ? `${s}\u2588
748
+ ${e}` : `${s}${styleText("inverse", r)}${e}`;
749
+ }
750
+ get cursor() {
751
+ return this._cursor;
752
+ }
753
+ #r(t) {
754
+ if (this.userInput.length === 0) {
755
+ this._setUserInput(t);
756
+ return;
757
+ }
758
+ this._setUserInput(
759
+ this.userInput.slice(0, this.cursor) + t + this.userInput.slice(this.cursor)
760
+ );
761
+ }
762
+ #i(t) {
763
+ const s = this.value ?? "";
764
+ switch (t) {
765
+ case "up":
766
+ this._cursor = findTextCursor(this._cursor, 0, -1, s);
767
+ return;
768
+ case "down":
769
+ this._cursor = findTextCursor(this._cursor, 0, 1, s);
770
+ return;
771
+ case "left":
772
+ this._cursor = findTextCursor(this._cursor, -1, 0, s);
773
+ return;
774
+ case "right":
775
+ this._cursor = findTextCursor(this._cursor, 1, 0, s);
776
+ return;
777
+ }
778
+ }
779
+ _shouldSubmit(t, s) {
780
+ if (this.#t)
781
+ return this.focused === "submit" ? true : (this.#r(`
782
+ `), this._cursor++, false);
783
+ const r = this.#s;
784
+ return this.#s = true, r ? (this.userInput[this.cursor - 1] === `
785
+ ` && (this._setUserInput(
786
+ this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)
787
+ ), this._cursor--), true) : (this.#r(`
788
+ `), this._cursor++, false);
789
+ }
790
+ constructor(t) {
791
+ super(t, false), this.#t = t.showSubmit ?? false, this.on("key", (s, r) => {
792
+ if (r?.name && o$1.has(r.name)) {
793
+ this.#i(r.name);
794
+ return;
795
+ }
796
+ if (s === " " && this.#t) {
797
+ this.focused = this.focused === "editor" ? "submit" : "editor";
798
+ return;
799
+ }
800
+ if (r?.name !== "return") {
801
+ if (this.#s = false, r?.name === "backspace" && this.cursor > 0) {
802
+ this._setUserInput(
803
+ this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)
804
+ ), this._cursor--;
805
+ return;
806
+ }
807
+ if (r?.name === "delete" && this.cursor < this.userInput.length) {
808
+ this._setUserInput(
809
+ this.userInput.slice(0, this.cursor) + this.userInput.slice(this.cursor + 1)
810
+ );
811
+ return;
812
+ }
813
+ s && (this.#t && this.focused === "submit" && (this.focused = "editor"), this.#r(s ?? ""), this._cursor++);
814
+ }
815
+ }), this.on("userInput", (s) => {
816
+ this._setValue(s);
817
+ }), this.on("finalize", () => {
818
+ this.value || (this.value = t.defaultValue), this.value === void 0 && (this.value = "");
819
+ });
820
+ }
821
+ }
822
+
823
+ let a$1 = class a extends V {
824
+ options;
825
+ cursor = 0;
826
+ get _value() {
827
+ return this.options[this.cursor].value;
828
+ }
829
+ get _enabledOptions() {
830
+ return this.options.filter((e) => e.disabled !== true);
831
+ }
832
+ toggleAll() {
833
+ const e = this._enabledOptions, i = this.value !== void 0 && this.value.length === e.length;
834
+ this.value = i ? [] : e.map((t) => t.value);
835
+ }
836
+ toggleInvert() {
837
+ const e = this.value;
838
+ if (!e)
839
+ return;
840
+ const i = this._enabledOptions.filter((t) => !e.includes(t.value));
841
+ this.value = i.map((t) => t.value);
842
+ }
843
+ toggleValue() {
844
+ this.value === void 0 && (this.value = []);
845
+ const e = this.value.includes(this._value);
846
+ this.value = e ? this.value.filter((i) => i !== this._value) : [...this.value, this._value];
847
+ }
848
+ constructor(e) {
849
+ super(e, false), this.options = e.options, this.value = [...e.initialValues ?? []];
850
+ const i = Math.max(
851
+ this.options.findIndex(({ value: t }) => t === e.cursorAt),
852
+ 0
853
+ );
854
+ this.cursor = this.options[i].disabled ? findCursor(i, 1, this.options) : i, this.on("key", (t, l) => {
855
+ l.name === "a" && this.toggleAll(), l.name === "i" && this.toggleInvert();
856
+ }), this.on("cursor", (t) => {
857
+ switch (t) {
858
+ case "left":
859
+ case "up":
860
+ this.cursor = findCursor(this.cursor, -1, this.options);
861
+ break;
862
+ case "down":
863
+ case "right":
864
+ this.cursor = findCursor(this.cursor, 1, this.options);
865
+ break;
866
+ case "space":
867
+ this.toggleValue();
868
+ break;
869
+ }
870
+ });
871
+ }
872
+ };
873
+
874
+ class o extends V {
875
+ _mask = "\u2022";
876
+ get cursor() {
877
+ return this._cursor;
878
+ }
879
+ get masked() {
880
+ return this.userInput.replaceAll(/./g, this._mask);
881
+ }
882
+ get userInputWithCursor() {
883
+ if (this.state === "submit" || this.state === "cancel")
884
+ return this.masked;
885
+ const t = this.userInput;
886
+ if (this.cursor >= t.length)
887
+ return `${this.masked}${styleText(["inverse", "hidden"], "_")}`;
888
+ const s = this.masked, r = s.slice(0, this.cursor), e = s.slice(this.cursor);
889
+ return `${r}${styleText("inverse", e[0])}${e.slice(1)}`;
890
+ }
891
+ clear() {
892
+ this._clearUserInput();
893
+ }
894
+ constructor({ mask: t, ...s }) {
895
+ super(s), this._mask = t ?? "\u2022", this.on("userInput", (r) => {
896
+ this._setValue(r);
897
+ });
898
+ }
899
+ }
900
+
901
+ class a extends V {
902
+ options;
903
+ cursor = 0;
904
+ get _selectedValue() {
905
+ return this.options[this.cursor];
906
+ }
907
+ changeValue() {
908
+ this.value = this._selectedValue.value;
909
+ }
910
+ constructor(t) {
911
+ super(t, false), this.options = t.options;
912
+ const i = this.options.findIndex(({ value: s }) => s === t.initialValue), e = i === -1 ? 0 : i;
913
+ this.cursor = this.options[e].disabled ? findCursor(e, 1, this.options) : e, this.changeValue(), this.on("cursor", (s) => {
914
+ switch (s) {
915
+ case "left":
916
+ case "up":
917
+ this.cursor = findCursor(this.cursor, -1, this.options);
918
+ break;
919
+ case "down":
920
+ case "right":
921
+ this.cursor = findCursor(this.cursor, 1, this.options);
922
+ break;
923
+ }
924
+ this.changeValue();
925
+ });
926
+ }
927
+ }
928
+
929
+ class u extends V {
930
+ options;
931
+ cursor = 0;
932
+ constructor(t) {
933
+ super(t, false), this.options = t.options;
934
+ const s = t.caseSensitive === true, i = this.options.map(({ value: [e] }) => s ? e : e?.toLowerCase());
935
+ this.cursor = Math.max(i.indexOf(t.initialValue), 0), this.on("key", (e) => {
936
+ if (!e)
937
+ return;
938
+ const o = s ? e : e.toLowerCase();
939
+ if (!i.includes(o))
940
+ return;
941
+ const n = this.options.find(({ value: [r] }) => s ? r === o : r?.toLowerCase() === o);
942
+ n && (this.value = n.value, this.state = "submit", this.emit("submit"));
943
+ });
944
+ }
945
+ }
946
+
947
+ class n extends V {
948
+ get userInputWithCursor() {
949
+ if (this.state === "submit")
950
+ return this.userInput;
951
+ const t = this.userInput;
952
+ if (this.cursor >= t.length)
953
+ return `${this.userInput}\u2588`;
954
+ const e = t.slice(0, this.cursor), [s, ...r] = t.slice(this.cursor);
955
+ return `${e}${styleText("inverse", s)}${r.join("")}`;
956
+ }
957
+ get cursor() {
958
+ return this._cursor;
959
+ }
960
+ constructor(t) {
961
+ super({
962
+ ...t,
963
+ initialUserInput: t.initialUserInput ?? t.initialValue
964
+ }), this.on("userInput", (e) => {
965
+ this._setValue(e);
966
+ }), this.on("finalize", () => {
967
+ this.value || (this.value = t.defaultValue), this.value === void 0 && (this.value = "");
968
+ });
969
+ }
970
+ }
971
+
972
+ export { T$1 as AutocompletePrompt, r as ConfirmPrompt, U as DatePrompt, u$1 as GroupMultiSelectPrompt, h as MultiLinePrompt, a$1 as MultiSelectPrompt, o as PasswordPrompt, V as Prompt, u as SelectKeyPrompt, a as SelectPrompt, n as TextPrompt, block, getColumns, getRows, isCancel, runValidation, settings, updateSettings, wrapTextWithPrefix };