@nomai/nomai 0.1.0

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.
@@ -0,0 +1,2462 @@
1
+ import { t as __commonJSMin } from "./rolldown-runtime-C7HZzL1F.mjs";
2
+ import { existsSync, lstatSync, readdirSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
+ import process$1, { stdin, stdout } from "node:process";
5
+ import { stripVTControlCharacters, styleText } from "node:util";
6
+ import * as l from "node:readline";
7
+ import l__default from "node:readline";
8
+ import { ReadStream } from "node:tty";
9
+ //#region node_modules/fast-string-truncated-width/dist/utils.js
10
+ const getCodePointsLength = (() => {
11
+ const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
12
+ return (input) => {
13
+ let surrogatePairsNr = 0;
14
+ SURROGATE_PAIR_RE.lastIndex = 0;
15
+ while (SURROGATE_PAIR_RE.test(input)) surrogatePairsNr += 1;
16
+ return input.length - surrogatePairsNr;
17
+ };
18
+ })();
19
+ const isFullWidth = (x) => {
20
+ return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
21
+ };
22
+ const isWideNotCJKTNotEmoji = (x) => {
23
+ return x === 8987 || x === 9001 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
24
+ };
25
+ //#endregion
26
+ //#region node_modules/fast-string-truncated-width/dist/index.js
27
+ const ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
28
+ const CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
29
+ const CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy;
30
+ const TAB_RE = /\t{1,1000}/y;
31
+ const EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy;
32
+ const LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
33
+ const MODIFIER_RE = /\p{M}+/gu;
34
+ const NO_TRUNCATION$1 = {
35
+ limit: Infinity,
36
+ ellipsis: ""
37
+ };
38
+ const getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
39
+ const LIMIT = truncationOptions.limit ?? Infinity;
40
+ const ELLIPSIS = truncationOptions.ellipsis ?? "";
41
+ const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION$1, widthOptions).width : 0);
42
+ const ANSI_WIDTH = 0;
43
+ const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
44
+ const TAB_WIDTH = widthOptions.tabWidth ?? 8;
45
+ const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
46
+ const FULL_WIDTH_WIDTH = 2;
47
+ const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
48
+ const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
49
+ const PARSE_BLOCKS = [
50
+ [LATIN_RE, REGULAR_WIDTH],
51
+ [ANSI_RE, ANSI_WIDTH],
52
+ [CONTROL_RE, CONTROL_WIDTH],
53
+ [TAB_RE, TAB_WIDTH],
54
+ [EMOJI_RE, EMOJI_WIDTH],
55
+ [CJKT_WIDE_RE, WIDE_WIDTH]
56
+ ];
57
+ let indexPrev = 0;
58
+ let index = 0;
59
+ let length = input.length;
60
+ let lengthExtra = 0;
61
+ let truncationEnabled = false;
62
+ let truncationIndex = length;
63
+ let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
64
+ let unmatchedStart = 0;
65
+ let unmatchedEnd = 0;
66
+ let width = 0;
67
+ let widthExtra = 0;
68
+ outer: while (true) {
69
+ if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
70
+ const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
71
+ lengthExtra = 0;
72
+ for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
73
+ const codePoint = char.codePointAt(0) || 0;
74
+ if (isFullWidth(codePoint)) widthExtra = FULL_WIDTH_WIDTH;
75
+ else if (isWideNotCJKTNotEmoji(codePoint)) widthExtra = WIDE_WIDTH;
76
+ else widthExtra = REGULAR_WIDTH;
77
+ if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
78
+ if (width + widthExtra > LIMIT) {
79
+ truncationEnabled = true;
80
+ break outer;
81
+ }
82
+ lengthExtra += char.length;
83
+ width += widthExtra;
84
+ }
85
+ unmatchedStart = unmatchedEnd = 0;
86
+ }
87
+ if (index >= length) break outer;
88
+ for (let i = 0, l = PARSE_BLOCKS.length; i < l; i++) {
89
+ const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
90
+ BLOCK_RE.lastIndex = index;
91
+ if (BLOCK_RE.test(input)) {
92
+ lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
93
+ widthExtra = lengthExtra * BLOCK_WIDTH;
94
+ if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
95
+ if (width + widthExtra > LIMIT) {
96
+ truncationEnabled = true;
97
+ break outer;
98
+ }
99
+ width += widthExtra;
100
+ unmatchedStart = indexPrev;
101
+ unmatchedEnd = index;
102
+ index = indexPrev = BLOCK_RE.lastIndex;
103
+ continue outer;
104
+ }
105
+ }
106
+ index += 1;
107
+ }
108
+ return {
109
+ width: truncationEnabled ? truncationLimit : width,
110
+ index: truncationEnabled ? truncationIndex : length,
111
+ truncated: truncationEnabled,
112
+ ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
113
+ };
114
+ };
115
+ //#endregion
116
+ //#region node_modules/fast-string-width/dist/index.js
117
+ const NO_TRUNCATION = {
118
+ limit: Infinity,
119
+ ellipsis: "",
120
+ ellipsisWidth: 0
121
+ };
122
+ const fastStringWidth = (input, options = {}) => {
123
+ return getStringTruncatedWidth(input, NO_TRUNCATION, options).width;
124
+ };
125
+ //#endregion
126
+ //#region node_modules/fast-wrap-ansi/lib/main.js
127
+ const ESC = "\x1B";
128
+ const CSI = "›";
129
+ const END_CODE = 39;
130
+ const ANSI_ESCAPE_BELL = "\x07";
131
+ const ANSI_CSI = "[";
132
+ const ANSI_OSC = "]";
133
+ const ANSI_SGR_TERMINATOR = "m";
134
+ const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
135
+ const GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
136
+ const getClosingCode = (openingCode) => {
137
+ if (openingCode >= 30 && openingCode <= 37) return 39;
138
+ if (openingCode >= 90 && openingCode <= 97) return 39;
139
+ if (openingCode >= 40 && openingCode <= 47) return 49;
140
+ if (openingCode >= 100 && openingCode <= 107) return 49;
141
+ if (openingCode === 1 || openingCode === 2) return 22;
142
+ if (openingCode === 3) return 23;
143
+ if (openingCode === 4) return 24;
144
+ if (openingCode === 7) return 27;
145
+ if (openingCode === 8) return 28;
146
+ if (openingCode === 9) return 29;
147
+ if (openingCode === 0) return 0;
148
+ };
149
+ const wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
150
+ const wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
151
+ const wrapWord = (rows, word, columns) => {
152
+ const characters = word[Symbol.iterator]();
153
+ let isInsideEscape = false;
154
+ let isInsideLinkEscape = false;
155
+ let lastRow = rows.at(-1);
156
+ let visible = lastRow === void 0 ? 0 : fastStringWidth(lastRow);
157
+ let currentCharacter = characters.next();
158
+ let nextCharacter = characters.next();
159
+ let rawCharacterIndex = 0;
160
+ while (!currentCharacter.done) {
161
+ const character = currentCharacter.value;
162
+ const characterLength = fastStringWidth(character);
163
+ if (visible + characterLength <= columns) rows[rows.length - 1] += character;
164
+ else {
165
+ rows.push(character);
166
+ visible = 0;
167
+ }
168
+ if (character === ESC || character === CSI) {
169
+ isInsideEscape = true;
170
+ isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
171
+ }
172
+ if (isInsideEscape) {
173
+ if (isInsideLinkEscape) {
174
+ if (character === ANSI_ESCAPE_BELL) {
175
+ isInsideEscape = false;
176
+ isInsideLinkEscape = false;
177
+ }
178
+ } else if (character === ANSI_SGR_TERMINATOR) isInsideEscape = false;
179
+ } else {
180
+ visible += characterLength;
181
+ if (visible === columns && !nextCharacter.done) {
182
+ rows.push("");
183
+ visible = 0;
184
+ }
185
+ }
186
+ currentCharacter = nextCharacter;
187
+ nextCharacter = characters.next();
188
+ rawCharacterIndex += character.length;
189
+ }
190
+ lastRow = rows.at(-1);
191
+ if (!visible && lastRow !== void 0 && lastRow.length && rows.length > 1) rows[rows.length - 2] += rows.pop();
192
+ };
193
+ const stringVisibleTrimSpacesRight = (string) => {
194
+ const words = string.split(" ");
195
+ let last = words.length;
196
+ while (last) {
197
+ if (fastStringWidth(words[last - 1])) break;
198
+ last--;
199
+ }
200
+ if (last === words.length) return string;
201
+ return words.slice(0, last).join(" ") + words.slice(last).join("");
202
+ };
203
+ const exec = (string, columns, options = {}) => {
204
+ if (options.trim !== false && string.trim() === "") return "";
205
+ let returnValue = "";
206
+ let escapeCode;
207
+ let escapeUrl;
208
+ const words = string.split(" ");
209
+ let rows = [""];
210
+ let rowLength = 0;
211
+ for (let index = 0; index < words.length; index++) {
212
+ const word = words[index];
213
+ if (options.trim !== false) {
214
+ const row = rows.at(-1) ?? "";
215
+ const trimmed = row.trimStart();
216
+ if (row.length !== trimmed.length) {
217
+ rows[rows.length - 1] = trimmed;
218
+ rowLength = fastStringWidth(trimmed);
219
+ }
220
+ }
221
+ if (index !== 0) {
222
+ if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
223
+ rows.push("");
224
+ rowLength = 0;
225
+ }
226
+ if (rowLength || options.trim === false) {
227
+ rows[rows.length - 1] += " ";
228
+ rowLength++;
229
+ }
230
+ }
231
+ const wordLength = fastStringWidth(word);
232
+ if (options.hard && wordLength > columns) {
233
+ const remainingColumns = columns - rowLength;
234
+ const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
235
+ if (Math.floor((wordLength - 1) / columns) < breaksStartingThisLine) rows.push("");
236
+ wrapWord(rows, word, columns);
237
+ rowLength = fastStringWidth(rows.at(-1) ?? "");
238
+ continue;
239
+ }
240
+ if (rowLength + wordLength > columns && rowLength && wordLength) {
241
+ if (options.wordWrap === false && rowLength < columns) {
242
+ wrapWord(rows, word, columns);
243
+ rowLength = fastStringWidth(rows.at(-1) ?? "");
244
+ continue;
245
+ }
246
+ rows.push("");
247
+ rowLength = 0;
248
+ }
249
+ if (rowLength + wordLength > columns && options.wordWrap === false) {
250
+ wrapWord(rows, word, columns);
251
+ rowLength = fastStringWidth(rows.at(-1) ?? "");
252
+ continue;
253
+ }
254
+ rows[rows.length - 1] += word;
255
+ rowLength += wordLength;
256
+ }
257
+ if (options.trim !== false) rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
258
+ const preString = rows.join("\n");
259
+ let inSurrogate = false;
260
+ for (let i = 0; i < preString.length; i++) {
261
+ const character = preString[i];
262
+ returnValue += character;
263
+ if (!inSurrogate) {
264
+ inSurrogate = character >= "\ud800" && character <= "\udbff";
265
+ if (inSurrogate) continue;
266
+ } else inSurrogate = false;
267
+ if (character === ESC || character === CSI) {
268
+ GROUP_REGEX.lastIndex = i + 1;
269
+ const groups = GROUP_REGEX.exec(preString)?.groups;
270
+ if (groups?.code !== void 0) {
271
+ const code = Number.parseFloat(groups.code);
272
+ escapeCode = code === END_CODE ? void 0 : code;
273
+ } else if (groups?.uri !== void 0) escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
274
+ }
275
+ if (preString[i + 1] === "\n") {
276
+ if (escapeUrl) returnValue += wrapAnsiHyperlink("");
277
+ const closingCode = escapeCode ? getClosingCode(escapeCode) : void 0;
278
+ if (escapeCode && closingCode) returnValue += wrapAnsiCode(closingCode);
279
+ } else if (character === "\n") {
280
+ if (escapeCode && getClosingCode(escapeCode)) returnValue += wrapAnsiCode(escapeCode);
281
+ if (escapeUrl) returnValue += wrapAnsiHyperlink(escapeUrl);
282
+ }
283
+ }
284
+ return returnValue;
285
+ };
286
+ const CRLF_OR_LF = /\r?\n/;
287
+ function wrapAnsi(string, columns, options) {
288
+ return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join("\n");
289
+ }
290
+ //#endregion
291
+ //#region node_modules/@clack/core/dist/index.mjs
292
+ var import_src = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
293
+ const ESC = "\x1B";
294
+ const CSI = `${ESC}[`;
295
+ const beep = "\x07";
296
+ const cursor = {
297
+ to(x, y) {
298
+ if (!y) return `${CSI}${x + 1}G`;
299
+ return `${CSI}${y + 1};${x + 1}H`;
300
+ },
301
+ move(x, y) {
302
+ let ret = "";
303
+ if (x < 0) ret += `${CSI}${-x}D`;
304
+ else if (x > 0) ret += `${CSI}${x}C`;
305
+ if (y < 0) ret += `${CSI}${-y}A`;
306
+ else if (y > 0) ret += `${CSI}${y}B`;
307
+ return ret;
308
+ },
309
+ up: (count = 1) => `${CSI}${count}A`,
310
+ down: (count = 1) => `${CSI}${count}B`,
311
+ forward: (count = 1) => `${CSI}${count}C`,
312
+ backward: (count = 1) => `${CSI}${count}D`,
313
+ nextLine: (count = 1) => `${CSI}E`.repeat(count),
314
+ prevLine: (count = 1) => `${CSI}F`.repeat(count),
315
+ left: `${CSI}G`,
316
+ hide: `${CSI}?25l`,
317
+ show: `${CSI}?25h`,
318
+ save: `${ESC}7`,
319
+ restore: `${ESC}8`
320
+ };
321
+ module.exports = {
322
+ cursor,
323
+ scroll: {
324
+ up: (count = 1) => `${CSI}S`.repeat(count),
325
+ down: (count = 1) => `${CSI}T`.repeat(count)
326
+ },
327
+ erase: {
328
+ screen: `${CSI}2J`,
329
+ up: (count = 1) => `${CSI}1J`.repeat(count),
330
+ down: (count = 1) => `${CSI}J`.repeat(count),
331
+ line: `${CSI}2K`,
332
+ lineEnd: `${CSI}K`,
333
+ lineStart: `${CSI}1K`,
334
+ lines(count) {
335
+ let clear = "";
336
+ for (let i = 0; i < count; i++) clear += this.line + (i < count - 1 ? cursor.up() : "");
337
+ if (count) clear += cursor.left;
338
+ return clear;
339
+ }
340
+ },
341
+ beep
342
+ };
343
+ })))();
344
+ function findCursor(s, o, l) {
345
+ if (!l.some((r) => !r.disabled)) return s;
346
+ const t = s + o, n = Math.max(l.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
347
+ return l[e]?.disabled ? findCursor(e, o < 0 ? -1 : 1, l) : e;
348
+ }
349
+ function findTextCursor(s, o, l, i) {
350
+ const t = i.split(`
351
+ `);
352
+ let n = 0, e = s;
353
+ for (const r of t) {
354
+ if (e <= r.length) break;
355
+ e -= r.length + 1, n++;
356
+ }
357
+ for (n = Math.max(0, Math.min(t.length - 1, n + l)), e = Math.min(e, t[n].length) + o; e < 0 && n > 0;) n--, e += t[n].length + 1;
358
+ for (; e > t[n].length && n < t.length - 1;) e -= t[n].length + 1, n++;
359
+ e = Math.max(0, Math.min(t[n].length, e));
360
+ let h = 0;
361
+ for (let r = 0; r < n; r++) h += t[r].length + 1;
362
+ return h + e;
363
+ }
364
+ const settings = {
365
+ actions: /* @__PURE__ */ new Set([
366
+ "up",
367
+ "down",
368
+ "left",
369
+ "right",
370
+ "space",
371
+ "enter",
372
+ "cancel"
373
+ ]),
374
+ aliases: /* @__PURE__ */ new Map([
375
+ ["k", "up"],
376
+ ["j", "down"],
377
+ ["h", "left"],
378
+ ["l", "right"],
379
+ ["", "cancel"],
380
+ ["escape", "cancel"]
381
+ ]),
382
+ messages: {
383
+ cancel: "Canceled",
384
+ error: "Something went wrong"
385
+ },
386
+ withGuide: true,
387
+ date: {
388
+ monthNames: [...[
389
+ "January",
390
+ "February",
391
+ "March",
392
+ "April",
393
+ "May",
394
+ "June",
395
+ "July",
396
+ "August",
397
+ "September",
398
+ "October",
399
+ "November",
400
+ "December"
401
+ ]],
402
+ messages: {
403
+ required: "Please enter a valid date",
404
+ invalidMonth: "There are only 12 months in a year",
405
+ invalidDay: (n, e) => `There are only ${n} days in ${e}`,
406
+ afterMin: (n) => `Date must be on or after ${n.toISOString().slice(0, 10)}`,
407
+ beforeMax: (n) => `Date must be on or before ${n.toISOString().slice(0, 10)}`
408
+ }
409
+ }
410
+ };
411
+ function updateSettings(n) {
412
+ if (n.aliases !== void 0) {
413
+ const e = n.aliases;
414
+ for (const s in e) {
415
+ if (!Object.hasOwn(e, s)) continue;
416
+ const i = e[s];
417
+ i === void 0 || !settings.actions.has(i) || settings.aliases.has(s) || settings.aliases.set(s, i);
418
+ }
419
+ }
420
+ if (n.messages !== void 0) {
421
+ const e = n.messages;
422
+ e.cancel !== void 0 && (settings.messages.cancel = e.cancel), e.error !== void 0 && (settings.messages.error = e.error);
423
+ }
424
+ if (n.withGuide !== void 0 && (settings.withGuide = n.withGuide !== false), n.date !== void 0) {
425
+ const e = n.date;
426
+ 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));
427
+ }
428
+ }
429
+ function isActionKey(n, e) {
430
+ if (typeof n == "string") return settings.aliases.get(n) === e;
431
+ for (const s of n) if (s !== void 0 && isActionKey(s, e)) return true;
432
+ return false;
433
+ }
434
+ function diffLines(i, s) {
435
+ if (i === s) return;
436
+ const e = i.split(`
437
+ `), t = s.split(`
438
+ `), r = Math.max(e.length, t.length), f = [];
439
+ for (let n = 0; n < r; n++) e[n] !== t[n] && f.push(n);
440
+ return {
441
+ lines: f,
442
+ numLinesBefore: e.length,
443
+ numLinesAfter: t.length,
444
+ numLines: r
445
+ };
446
+ }
447
+ const R = globalThis.process.platform.startsWith("win");
448
+ const CANCEL_SYMBOL = Symbol("clack:cancel");
449
+ function isCancel(e) {
450
+ return e === CANCEL_SYMBOL;
451
+ }
452
+ function setRawMode(e, r) {
453
+ const o = e;
454
+ o.isTTY && o.setRawMode(r);
455
+ }
456
+ function block({ input: e = stdin, output: r = stdout, overwrite: o = true, hideCursor: t = true } = {}) {
457
+ const s = l.createInterface({
458
+ input: e,
459
+ output: r,
460
+ prompt: "",
461
+ tabSize: 1
462
+ });
463
+ l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
464
+ const n = (f, { name: a, sequence: p }) => {
465
+ if (isActionKey([
466
+ String(f),
467
+ a,
468
+ p
469
+ ], "cancel")) {
470
+ t && r.write(import_src.cursor.show), process.exit(0);
471
+ return;
472
+ }
473
+ if (!o) return;
474
+ const i = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
475
+ l.moveCursor(r, i, m, () => {
476
+ l.clearLine(r, 1, () => {
477
+ e.once("keypress", n);
478
+ });
479
+ });
480
+ };
481
+ return t && r.write(import_src.cursor.hide), e.once("keypress", n), () => {
482
+ e.off("keypress", n), t && r.write(import_src.cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
483
+ };
484
+ }
485
+ const getColumns = (e) => "columns" in e && typeof e.columns == "number" ? e.columns : 80;
486
+ const getRows = (e) => "rows" in e && typeof e.rows == "number" ? e.rows : 20;
487
+ function wrapTextWithPrefix(e, r, o, t = o, s = o, n) {
488
+ return wrapAnsi(r, getColumns(e ?? stdout) - o.length, {
489
+ hard: true,
490
+ trim: false
491
+ }).split(`
492
+ `).map((c, i, m) => {
493
+ const d = n ? n(c, i) : c;
494
+ return i === 0 ? `${t}${d}` : i === m.length - 1 ? `${s}${d}` : `${o}${d}`;
495
+ }).join(`
496
+ `);
497
+ }
498
+ function runValidation(e, n) {
499
+ if ("~standard" in e) {
500
+ const a = e["~standard"].validate(n);
501
+ if (a instanceof Promise) throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");
502
+ return a.issues?.at(0)?.message;
503
+ }
504
+ return e(n);
505
+ }
506
+ var V = class {
507
+ input;
508
+ output;
509
+ _abortSignal;
510
+ rl;
511
+ opts;
512
+ _render;
513
+ _track = false;
514
+ _prevFrame = "";
515
+ _subscribers = /* @__PURE__ */ new Map();
516
+ _cursor = 0;
517
+ state = "initial";
518
+ error = "";
519
+ value;
520
+ userInput = "";
521
+ constructor(t, e = true) {
522
+ const { input: i = stdin, output: n = stdout, render: s, signal: r, ...o } = t;
523
+ 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;
524
+ }
525
+ /**
526
+ * Unsubscribe all listeners
527
+ */
528
+ unsubscribe() {
529
+ this._subscribers.clear();
530
+ }
531
+ /**
532
+ * Set a subscriber with opts
533
+ * @param event - The event name
534
+ */
535
+ setSubscriber(t, e) {
536
+ const i = this._subscribers.get(t) ?? [];
537
+ i.push(e), this._subscribers.set(t, i);
538
+ }
539
+ /**
540
+ * Subscribe to an event
541
+ * @param event - The event name
542
+ * @param cb - The callback
543
+ */
544
+ on(t, e) {
545
+ this.setSubscriber(t, { cb: e });
546
+ }
547
+ /**
548
+ * Subscribe to an event once
549
+ * @param event - The event name
550
+ * @param cb - The callback
551
+ */
552
+ once(t, e) {
553
+ this.setSubscriber(t, {
554
+ cb: e,
555
+ once: true
556
+ });
557
+ }
558
+ /**
559
+ * Emit an event with data
560
+ * @param event - The event name
561
+ * @param data - The data to pass to the callback
562
+ */
563
+ emit(t, ...e) {
564
+ const i = this._subscribers.get(t) ?? [], n = [];
565
+ for (const s of i) s.cb(...e), s.once && n.push(() => i.splice(i.indexOf(s), 1));
566
+ for (const s of n) s();
567
+ }
568
+ prompt() {
569
+ return new Promise((t) => {
570
+ if (this._abortSignal) {
571
+ if (this._abortSignal.aborted) return this.state = "cancel", this.close(), t(CANCEL_SYMBOL);
572
+ this._abortSignal.addEventListener("abort", () => {
573
+ this.state = "cancel", this.close();
574
+ }, { once: true });
575
+ }
576
+ this.rl = l__default.createInterface({
577
+ input: this.input,
578
+ tabSize: 2,
579
+ prompt: "",
580
+ escapeCodeTimeout: 50,
581
+ terminal: true
582
+ }), 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", () => {
583
+ this.output.write(import_src.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(this.value);
584
+ }), this.once("cancel", () => {
585
+ this.output.write(import_src.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(CANCEL_SYMBOL);
586
+ });
587
+ });
588
+ }
589
+ _isActionKey(t, e) {
590
+ return t === " ";
591
+ }
592
+ _shouldSubmit(t, e) {
593
+ return true;
594
+ }
595
+ _setValue(t) {
596
+ this.value = t, this.emit("value", this.value);
597
+ }
598
+ _setUserInput(t, e) {
599
+ this.userInput = t ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
600
+ }
601
+ _clearUserInput() {
602
+ this.rl?.write(null, {
603
+ ctrl: true,
604
+ name: "u"
605
+ }), this._setUserInput("");
606
+ }
607
+ onKeypress(t, e) {
608
+ if (this._track && e.name !== "return" && (e.name && this._isActionKey(t, e) && this.rl?.write(null, {
609
+ ctrl: true,
610
+ name: "h"
611
+ }), 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)) {
612
+ if (this.opts.validate) {
613
+ const i = runValidation(this.opts.validate, this.value);
614
+ i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
615
+ }
616
+ this.state !== "error" && (this.state = "submit");
617
+ }
618
+ isActionKey([
619
+ t,
620
+ e?.name,
621
+ e?.sequence
622
+ ], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
623
+ }
624
+ close() {
625
+ this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
626
+ `), setRawMode(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
627
+ }
628
+ restoreCursor() {
629
+ const t = wrapAnsi(this._prevFrame, process.stdout.columns, {
630
+ hard: true,
631
+ trim: false
632
+ }).split(`
633
+ `).length - 1;
634
+ this.output.write(import_src.cursor.move(-999, t * -1));
635
+ }
636
+ render() {
637
+ const t = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
638
+ hard: true,
639
+ trim: false
640
+ });
641
+ if (t !== this._prevFrame) {
642
+ if (this.state === "initial") this.output.write(import_src.cursor.hide);
643
+ else {
644
+ const e = diffLines(this._prevFrame, t), i = getRows(this.output);
645
+ if (this.restoreCursor(), e) {
646
+ const n = Math.max(0, e.numLinesAfter - i), s = Math.max(0, e.numLinesBefore - i);
647
+ let r = e.lines.find((o) => o >= n);
648
+ if (r === void 0) {
649
+ this._prevFrame = t;
650
+ return;
651
+ }
652
+ if (e.lines.length === 1) {
653
+ this.output.write(import_src.cursor.move(0, r - s)), this.output.write(import_src.erase.lines(1));
654
+ const o = t.split(`
655
+ `);
656
+ this.output.write(o[r]), this._prevFrame = t, this.output.write(import_src.cursor.move(0, o.length - r - 1));
657
+ return;
658
+ } else if (e.lines.length > 1) {
659
+ if (n < s) r = n;
660
+ else {
661
+ const h = r - s;
662
+ h > 0 && this.output.write(import_src.cursor.move(0, h));
663
+ }
664
+ this.output.write(import_src.erase.down());
665
+ const f = t.split(`
666
+ `).slice(r);
667
+ this.output.write(f.join(`
668
+ `)), this._prevFrame = t;
669
+ return;
670
+ }
671
+ }
672
+ this.output.write(import_src.erase.down());
673
+ }
674
+ this.output.write(t), this.state === "initial" && (this.state = "active"), this._prevFrame = t;
675
+ }
676
+ }
677
+ };
678
+ function p$1(l, e) {
679
+ if (l === void 0 || e.length === 0) return 0;
680
+ const i = e.findIndex((s) => s.value === l);
681
+ return i !== -1 ? i : 0;
682
+ }
683
+ function g(l, e) {
684
+ return (e.label ?? String(e.value)).toLowerCase().includes(l.toLowerCase());
685
+ }
686
+ function m$1(l, e) {
687
+ if (e) return l ? e : e[0];
688
+ }
689
+ let T$1 = class T extends V {
690
+ filteredOptions;
691
+ multiple;
692
+ isNavigating = false;
693
+ selectedValues = [];
694
+ focusedValue;
695
+ #e = 0;
696
+ #s = "";
697
+ #t;
698
+ #i;
699
+ #n;
700
+ get cursor() {
701
+ return this.#e;
702
+ }
703
+ get userInputWithCursor() {
704
+ if (!this.userInput) return styleText(["inverse", "hidden"], "_");
705
+ if (this._cursor >= this.userInput.length) return `${this.userInput}\u2588`;
706
+ const e = this.userInput.slice(0, this.cursor), t = this.userInput.slice(this.cursor, this.cursor + 1), i = this.userInput.slice(this.cursor + 1);
707
+ return `${e}${styleText("inverse", t)}${i}`;
708
+ }
709
+ get options() {
710
+ return typeof this.#i == "function" ? this.#i() : this.#i;
711
+ }
712
+ constructor(e) {
713
+ super(e), this.#i = e.options, this.#n = e.placeholder;
714
+ const t = this.options;
715
+ this.filteredOptions = [...t], this.multiple = e.multiple === true, this.#t = typeof e.options == "function" ? e.filter : e.filter ?? g;
716
+ let i;
717
+ 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) for (const s of i) {
718
+ const n = t.findIndex((o) => o.value === s);
719
+ n !== -1 && (this.toggleSelected(s), this.#e = n);
720
+ }
721
+ this.focusedValue = this.options[this.#e]?.value, this.on("key", (s, n) => this.#l(s, n)), this.on("userInput", (s) => this.#u(s));
722
+ }
723
+ _isActionKey(e, t) {
724
+ return e === " " || this.multiple && this.isNavigating && t.name === "space" && e !== void 0 && e !== "";
725
+ }
726
+ #l(e, t) {
727
+ const i = t.name === "up", s = t.name === "down", n = t.name === "return", o = this.userInput === "" || this.userInput === " ", u = this.#n, a = this.options, f = u !== void 0 && u !== "" && a.some((r) => !r.disabled && (this.#t ? this.#t(u, r) : true));
728
+ if (t.name === "tab" && o && f) {
729
+ this.userInput === " " && this._clearUserInput(), this._setUserInput(u, true), this.isNavigating = false;
730
+ return;
731
+ }
732
+ 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$1(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);
733
+ }
734
+ deselectAll() {
735
+ this.selectedValues = [];
736
+ }
737
+ toggleSelected(e) {
738
+ 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]);
739
+ }
740
+ #u(e) {
741
+ if (e !== this.#s) {
742
+ this.#s = e;
743
+ const t = this.options;
744
+ e && this.#t ? this.filteredOptions = t.filter((n) => this.#t?.(e, n)) : this.filteredOptions = [...t];
745
+ const i = p$1(this.focusedValue, this.filteredOptions);
746
+ this.#e = findCursor(i, 0, this.filteredOptions);
747
+ const s = this.filteredOptions[this.#e];
748
+ s && !s.disabled ? this.focusedValue = s.value : this.focusedValue = void 0, this.multiple || (this.focusedValue !== void 0 ? this.toggleSelected(this.focusedValue) : this.deselectAll());
749
+ }
750
+ }
751
+ };
752
+ var r = class extends V {
753
+ get cursor() {
754
+ return this.value ? 0 : 1;
755
+ }
756
+ get _value() {
757
+ return this.cursor === 0;
758
+ }
759
+ constructor(t) {
760
+ super(t, false), this.value = !!t.initialValue, this.on("userInput", () => {
761
+ this.value = this._value;
762
+ }), this.on("confirm", (i) => {
763
+ this.output.write(import_src.cursor.move(0, -1)), this.value = i, this.state = "submit", this.close();
764
+ }), this.on("cursor", () => {
765
+ this.value = !this.value;
766
+ });
767
+ }
768
+ };
769
+ const _ = {
770
+ Y: {
771
+ type: "year",
772
+ len: 4
773
+ },
774
+ M: {
775
+ type: "month",
776
+ len: 2
777
+ },
778
+ D: {
779
+ type: "day",
780
+ len: 2
781
+ }
782
+ };
783
+ function M(r) {
784
+ return [...r].map((t) => _[t]);
785
+ }
786
+ function P$1(r) {
787
+ const i = new Intl.DateTimeFormat(r, {
788
+ year: "numeric",
789
+ month: "2-digit",
790
+ day: "2-digit"
791
+ }).formatToParts(new Date(2e3, 0, 15)), s = [];
792
+ let n = "/";
793
+ for (const e of i) e.type === "literal" ? n = e.value.trim() || e.value : (e.type === "year" || e.type === "month" || e.type === "day") && s.push({
794
+ type: e.type,
795
+ len: e.type === "year" ? 4 : 2
796
+ });
797
+ return {
798
+ segments: s,
799
+ separator: n
800
+ };
801
+ }
802
+ function p$2(r) {
803
+ return Number.parseInt((r || "0").replace(/_/g, "0"), 10) || 0;
804
+ }
805
+ function f(r) {
806
+ return {
807
+ year: p$2(r.year),
808
+ month: p$2(r.month),
809
+ day: p$2(r.day)
810
+ };
811
+ }
812
+ function c$1(r, t) {
813
+ return new Date(r || 2001, t || 1, 0).getDate();
814
+ }
815
+ function b$1(r) {
816
+ const { year: t, month: i, day: s } = f(r);
817
+ if (!t || t < 0 || t > 9999 || !i || i < 1 || i > 12 || !s || s < 1) return;
818
+ const n = new Date(Date.UTC(t, i - 1, s));
819
+ if (!(n.getUTCFullYear() !== t || n.getUTCMonth() !== i - 1 || n.getUTCDate() !== s)) return {
820
+ year: t,
821
+ month: i,
822
+ day: s
823
+ };
824
+ }
825
+ function C$1(r) {
826
+ const t = b$1(r);
827
+ return t ? new Date(Date.UTC(t.year, t.month - 1, t.day)) : void 0;
828
+ }
829
+ function T(r, t, i, s) {
830
+ const n = i ? {
831
+ year: i.getUTCFullYear(),
832
+ month: i.getUTCMonth() + 1,
833
+ day: i.getUTCDate()
834
+ } : null, e = s ? {
835
+ year: s.getUTCFullYear(),
836
+ month: s.getUTCMonth() + 1,
837
+ day: s.getUTCDate()
838
+ } : null;
839
+ return r === "year" ? {
840
+ min: n?.year ?? 1,
841
+ max: e?.year ?? 9999
842
+ } : r === "month" ? {
843
+ min: n && t.year === n.year ? n.month : 1,
844
+ max: e && t.year === e.year ? e.month : 12
845
+ } : {
846
+ min: n && t.year === n.year && t.month === n.month ? n.day : 1,
847
+ max: e && t.year === e.year && t.month === e.month ? e.day : c$1(t.year, t.month)
848
+ };
849
+ }
850
+ var U = class extends V {
851
+ #i;
852
+ #o;
853
+ #t;
854
+ #h;
855
+ #u;
856
+ #e = {
857
+ segmentIndex: 0,
858
+ positionInSegment: 0
859
+ };
860
+ #n = true;
861
+ #s = null;
862
+ inlineError = "";
863
+ get segmentCursor() {
864
+ return { ...this.#e };
865
+ }
866
+ get segmentValues() {
867
+ return { ...this.#t };
868
+ }
869
+ get segments() {
870
+ return this.#i;
871
+ }
872
+ get separator() {
873
+ return this.#o;
874
+ }
875
+ get formattedValue() {
876
+ return this.#l(this.#t);
877
+ }
878
+ #l(t) {
879
+ return this.#i.map((i) => t[i.type]).join(this.#o);
880
+ }
881
+ #r() {
882
+ this._setUserInput(this.#l(this.#t)), this._setValue(C$1(this.#t) ?? void 0);
883
+ }
884
+ constructor(t) {
885
+ const i = t.format ? {
886
+ segments: M(t.format),
887
+ separator: t.separator ?? "/"
888
+ } : P$1(t.locale), s = t.separator ?? i.separator, n = t.format ? M(t.format) : i.segments, e = t.initialValue ?? t.defaultValue, m = e ? {
889
+ year: String(e.getUTCFullYear()).padStart(4, "0"),
890
+ month: String(e.getUTCMonth() + 1).padStart(2, "0"),
891
+ day: String(e.getUTCDate()).padStart(2, "0")
892
+ } : {
893
+ year: "____",
894
+ month: "__",
895
+ day: "__"
896
+ }, o = n.map((a) => m[a.type]).join(s);
897
+ super({
898
+ ...t,
899
+ initialUserInput: o
900
+ }, 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));
901
+ }
902
+ #a() {
903
+ const t = Math.max(0, Math.min(this.#e.segmentIndex, this.#i.length - 1)), i = this.#i[t];
904
+ if (i) return this.#e.positionInSegment = Math.max(0, Math.min(this.#e.positionInSegment, i.len - 1)), {
905
+ segment: i,
906
+ index: t
907
+ };
908
+ }
909
+ #m(t) {
910
+ this.inlineError = "", this.#s = null;
911
+ const i = this.#a();
912
+ i && (this.#e.segmentIndex = Math.max(0, Math.min(this.#i.length - 1, i.index + t)), this.#e.positionInSegment = 0, this.#n = true);
913
+ }
914
+ #d(t) {
915
+ const i = this.#a();
916
+ if (!i) return;
917
+ 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(s.type, f(this.#t), this.#h, this.#u);
918
+ let a;
919
+ e ? a = t === 1 ? o.min : o.max : a = Math.max(Math.min(o.max, m + t), o.min), this.#t = {
920
+ ...this.#t,
921
+ [s.type]: a.toString().padStart(s.len, "0")
922
+ }, this.#n = true, this.#s = null, this.#r();
923
+ }
924
+ #f(t) {
925
+ if (t) switch (t) {
926
+ case "right": return this.#m(1);
927
+ case "left": return this.#m(-1);
928
+ case "up": return this.#d(1);
929
+ case "down": return this.#d(-1);
930
+ }
931
+ }
932
+ #y(t, i) {
933
+ if (i?.name === "backspace" || i?.sequence === "" || i?.sequence === "\b" || t === "" || t === "\b") {
934
+ this.inlineError = "";
935
+ const n = this.#a();
936
+ if (!n) return;
937
+ if (!this.#t[n.segment.type].replace(/_/g, "")) {
938
+ this.#m(-1);
939
+ return;
940
+ }
941
+ this.#t[n.segment.type] = "_".repeat(n.segment.len), this.#n = true, this.#e.positionInSegment = 0, this.#r();
942
+ return;
943
+ }
944
+ if (i?.name === "tab") {
945
+ this.inlineError = "";
946
+ const n = this.#a();
947
+ if (!n) return;
948
+ const e = i.shift ? -1 : 1, m = n.index + e;
949
+ m >= 0 && m < this.#i.length && (this.#e.segmentIndex = m, this.#e.positionInSegment = 0, this.#n = true);
950
+ return;
951
+ }
952
+ if (t && /^[0-9]$/.test(t)) {
953
+ const n = this.#a();
954
+ if (!n) return;
955
+ const { segment: e } = n, m = !this.#t[e.type].replace(/_/g, "");
956
+ if (this.#n && this.#s !== null && !m) {
957
+ const h = this.#s + t, d = {
958
+ ...this.#t,
959
+ [e.type]: h
960
+ }, g = this.#g(d, e);
961
+ if (g) {
962
+ this.inlineError = g, this.#s = null, this.#n = false;
963
+ return;
964
+ }
965
+ 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);
966
+ return;
967
+ }
968
+ this.#n && !m && (this.#t[e.type] = "_".repeat(e.len), this.#e.positionInSegment = 0), this.#n = false, this.#s = null;
969
+ const o = this.#t[e.type], a = o.indexOf("_"), u = a >= 0 ? a : Math.min(this.#e.positionInSegment, e.len - 1);
970
+ if (u < 0 || u >= e.len) return;
971
+ let l = o.slice(0, u) + t + o.slice(u + 1), D = false;
972
+ if (u === 0 && o === "__" && (e.type === "month" || e.type === "day")) {
973
+ const h = Number.parseInt(t, 10);
974
+ l = `0${t}`, D = h <= (e.type === "month" ? 1 : 2);
975
+ }
976
+ if (e.type === "year" && (l = (o.replace(/_/g, "") + t).padStart(e.len, "_")), !l.includes("_")) {
977
+ const h = {
978
+ ...this.#t,
979
+ [e.type]: l
980
+ }, d = this.#g(h, e);
981
+ if (d) {
982
+ this.inlineError = d;
983
+ return;
984
+ }
985
+ }
986
+ this.inlineError = "", this.#t[e.type] = l;
987
+ const y = l.includes("_") ? void 0 : b$1(this.#t);
988
+ if (y) {
989
+ const { year: h, month: d } = y, g = c$1(h, d);
990
+ this.#t = {
991
+ year: String(Math.max(0, Math.min(9999, h))).padStart(4, "0"),
992
+ month: String(Math.max(1, Math.min(12, d))).padStart(2, "0"),
993
+ day: String(Math.max(1, Math.min(g, y.day))).padStart(2, "0")
994
+ };
995
+ }
996
+ this.#r();
997
+ const S = l.indexOf("_");
998
+ 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);
999
+ }
1000
+ }
1001
+ #g(t, i) {
1002
+ const { month: s, day: n } = f(t);
1003
+ if (i.type === "month" && (s < 0 || s > 12)) return settings.date.messages.invalidMonth;
1004
+ if (i.type === "day" && (n < 0 || n > 31)) return settings.date.messages.invalidDay(31, "any month");
1005
+ }
1006
+ #p(t) {
1007
+ const { year: i, month: s, day: n } = f(this.#t);
1008
+ if (i && s && n) {
1009
+ const e = c$1(i, s);
1010
+ this.#t = {
1011
+ ...this.#t,
1012
+ day: String(Math.min(n, e)).padStart(2, "0")
1013
+ };
1014
+ }
1015
+ this.value = C$1(this.#t) ?? t.defaultValue ?? void 0;
1016
+ }
1017
+ };
1018
+ let u$2 = class u extends V {
1019
+ options;
1020
+ cursor = 0;
1021
+ #t;
1022
+ getGroupItems(t) {
1023
+ return this.options.filter((r) => r.group === t);
1024
+ }
1025
+ isGroupSelected(t) {
1026
+ const r = this.getGroupItems(t), e = this.value;
1027
+ return e === void 0 ? false : r.every((s) => e.includes(s.value));
1028
+ }
1029
+ toggleValue() {
1030
+ const t = this.options[this.cursor];
1031
+ if (t !== void 0) if (this.value === void 0 && (this.value = []), t.group === true) {
1032
+ const r = t.value, e = this.getGroupItems(r);
1033
+ this.isGroupSelected(r) ? this.value = this.value.filter((s) => e.findIndex((i) => i.value === s) === -1) : this.value = [...this.value, ...e.map((s) => s.value)], this.value = Array.from(new Set(this.value));
1034
+ } else {
1035
+ const r = this.value.includes(t.value);
1036
+ this.value = r ? this.value.filter((e) => e !== t.value) : [...this.value, t.value];
1037
+ }
1038
+ }
1039
+ constructor(t) {
1040
+ super(t, false);
1041
+ const { options: r } = t;
1042
+ this.#t = t.selectableGroups !== false, this.options = Object.entries(r).flatMap(([e, s]) => [{
1043
+ value: e,
1044
+ group: true,
1045
+ label: e
1046
+ }, ...s.map((i) => ({
1047
+ ...i,
1048
+ group: e
1049
+ }))]), this.value = [...t.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: e }) => e === t.cursorAt), this.#t ? 0 : 1), this.on("cursor", (e) => {
1050
+ switch (e) {
1051
+ case "left":
1052
+ case "up": {
1053
+ this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
1054
+ const s = this.options[this.cursor]?.group === true;
1055
+ !this.#t && s && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
1056
+ break;
1057
+ }
1058
+ case "down":
1059
+ case "right": {
1060
+ this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
1061
+ const s = this.options[this.cursor]?.group === true;
1062
+ !this.#t && s && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
1063
+ break;
1064
+ }
1065
+ case "space":
1066
+ this.toggleValue();
1067
+ break;
1068
+ }
1069
+ });
1070
+ }
1071
+ };
1072
+ const o = /* @__PURE__ */ new Set([
1073
+ "up",
1074
+ "down",
1075
+ "left",
1076
+ "right"
1077
+ ]);
1078
+ var h = class extends V {
1079
+ #t = false;
1080
+ #s;
1081
+ focused = "editor";
1082
+ get userInputWithCursor() {
1083
+ if (this.state === "submit") return this.userInput;
1084
+ const t = this.userInput;
1085
+ if (this.cursor >= t.length) return `${t}\u2588`;
1086
+ const s = t.slice(0, this.cursor), r = t.slice(this.cursor, this.cursor + 1), i = t.slice(this.cursor + 1);
1087
+ return r === `
1088
+ ` ? `${s}\u2588
1089
+ ${i}` : `${s}${styleText("inverse", r)}${i}`;
1090
+ }
1091
+ get cursor() {
1092
+ return this._cursor;
1093
+ }
1094
+ #r(t) {
1095
+ if (this.userInput.length === 0) {
1096
+ this._setUserInput(t);
1097
+ return;
1098
+ }
1099
+ this._setUserInput(this.userInput.slice(0, this.cursor) + t + this.userInput.slice(this.cursor));
1100
+ }
1101
+ #i(t) {
1102
+ const s = this.value ?? "";
1103
+ switch (t) {
1104
+ case "up":
1105
+ this._cursor = findTextCursor(this._cursor, 0, -1, s);
1106
+ return;
1107
+ case "down":
1108
+ this._cursor = findTextCursor(this._cursor, 0, 1, s);
1109
+ return;
1110
+ case "left":
1111
+ this._cursor = findTextCursor(this._cursor, -1, 0, s);
1112
+ return;
1113
+ case "right":
1114
+ this._cursor = findTextCursor(this._cursor, 1, 0, s);
1115
+ return;
1116
+ }
1117
+ }
1118
+ _shouldSubmit(t, s) {
1119
+ if (this.#s) return this.focused === "submit" ? true : (this.#r(`
1120
+ `), this._cursor++, false);
1121
+ const r = this.#t;
1122
+ return this.#t = true, r && this.cursor === this.userInput.length ? (this.userInput[this.cursor - 1] === `
1123
+ ` && (this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--), true) : (this.#r(`
1124
+ `), this._cursor++, false);
1125
+ }
1126
+ constructor(t) {
1127
+ const s = t.initialUserInput ?? t.initialValue;
1128
+ super({
1129
+ ...t,
1130
+ initialUserInput: s
1131
+ }, false), s !== void 0 && (this._cursor = s.length), this.#s = t.showSubmit ?? false, this.on("key", (r, i) => {
1132
+ if (i?.name && o.has(i.name)) {
1133
+ this.#t = false, this.#i(i.name);
1134
+ return;
1135
+ }
1136
+ if (r === " " && this.#s) {
1137
+ this.focused = this.focused === "editor" ? "submit" : "editor";
1138
+ return;
1139
+ }
1140
+ if (i?.name !== "return") {
1141
+ if (this.#t = false, i?.name === "backspace" && this.cursor > 0) {
1142
+ this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--;
1143
+ return;
1144
+ }
1145
+ if (i?.name === "delete" && this.cursor < this.userInput.length) {
1146
+ this._setUserInput(this.userInput.slice(0, this.cursor) + this.userInput.slice(this.cursor + 1));
1147
+ return;
1148
+ }
1149
+ r && (this.#s && this.focused === "submit" && (this.focused = "editor"), this.#r(r ?? ""), this._cursor++);
1150
+ }
1151
+ }), this.on("userInput", (r) => {
1152
+ this._setValue(r);
1153
+ }), this.on("finalize", () => {
1154
+ this.value || (this.value = t.defaultValue), this.value === void 0 && (this.value = "");
1155
+ });
1156
+ }
1157
+ };
1158
+ var a = class extends V {
1159
+ options;
1160
+ cursor = 0;
1161
+ get _value() {
1162
+ return this.options[this.cursor]?.value;
1163
+ }
1164
+ get _enabledOptions() {
1165
+ return this.options.filter((e) => e.disabled !== true);
1166
+ }
1167
+ toggleAll() {
1168
+ const e = this._enabledOptions, i = this.value !== void 0 && this.value.length === e.length;
1169
+ this.value = i ? [] : e.map((t) => t.value);
1170
+ }
1171
+ toggleInvert() {
1172
+ const e = this.value;
1173
+ if (!e) return;
1174
+ const i = this._enabledOptions.filter((t) => !e.includes(t.value));
1175
+ this.value = i.map((t) => t.value);
1176
+ }
1177
+ toggleValue() {
1178
+ this.value === void 0 && (this.value = []);
1179
+ const e = this.value.includes(this._value);
1180
+ this.value = e ? this.value.filter((i) => i !== this._value) : [...this.value, this._value];
1181
+ }
1182
+ constructor(e) {
1183
+ super(e, false), this.options = e.options, this.value = [...e.initialValues ?? []];
1184
+ const i = Math.max(this.options.findIndex(({ value: t }) => t === e.cursorAt), 0);
1185
+ this.cursor = this.options[i]?.disabled ? findCursor(i, 1, this.options) : i, this.on("key", (t, l) => {
1186
+ l.name === "a" && this.toggleAll(), l.name === "i" && this.toggleInvert();
1187
+ }), this.on("cursor", (t) => {
1188
+ switch (t) {
1189
+ case "left":
1190
+ case "up":
1191
+ this.cursor = findCursor(this.cursor, -1, this.options);
1192
+ break;
1193
+ case "down":
1194
+ case "right":
1195
+ this.cursor = findCursor(this.cursor, 1, this.options);
1196
+ break;
1197
+ case "space":
1198
+ this.toggleValue();
1199
+ break;
1200
+ }
1201
+ });
1202
+ }
1203
+ };
1204
+ let u$1 = class u extends V {
1205
+ _mask = "•";
1206
+ get cursor() {
1207
+ return this._cursor;
1208
+ }
1209
+ get masked() {
1210
+ return this.userInput.replaceAll(/./g, this._mask);
1211
+ }
1212
+ get userInputWithCursor() {
1213
+ if (this.state === "submit" || this.state === "cancel") return this.masked;
1214
+ const t = this.userInput;
1215
+ if (this.cursor >= t.length) return `${this.masked}${styleText(["inverse", "hidden"], "_")}`;
1216
+ const s = this.masked, r = s.slice(0, this.cursor), i = s.slice(this.cursor, this.cursor + 1), o = s.slice(this.cursor + 1);
1217
+ return `${r}${styleText("inverse", i)}${o}`;
1218
+ }
1219
+ clear() {
1220
+ this._clearUserInput();
1221
+ }
1222
+ constructor({ mask: t, ...s }) {
1223
+ super(s), this._mask = t ?? "•", this.on("userInput", (r) => {
1224
+ this._setValue(r);
1225
+ }), this.on("finalize", () => {
1226
+ this.value === void 0 && (this.value = "");
1227
+ });
1228
+ }
1229
+ };
1230
+ let n$1 = class n extends V {
1231
+ options;
1232
+ cursor = 0;
1233
+ get _selectedValue() {
1234
+ return this.options[this.cursor];
1235
+ }
1236
+ changeValue() {
1237
+ const e = this._selectedValue;
1238
+ this.value = e === void 0 ? void 0 : e.value;
1239
+ }
1240
+ constructor(e) {
1241
+ super(e, false), this.options = e.options;
1242
+ const o = this.options.findIndex(({ value: s }) => s === e.initialValue), t = o === -1 ? 0 : o;
1243
+ this.cursor = this.options[t]?.disabled ? findCursor(t, 1, this.options) : t, this.changeValue(), this.on("cursor", (s) => {
1244
+ switch (s) {
1245
+ case "left":
1246
+ case "up":
1247
+ this.cursor = findCursor(this.cursor, -1, this.options);
1248
+ break;
1249
+ case "down":
1250
+ case "right":
1251
+ this.cursor = findCursor(this.cursor, 1, this.options);
1252
+ break;
1253
+ }
1254
+ this.changeValue();
1255
+ });
1256
+ }
1257
+ };
1258
+ var u$3 = class extends V {
1259
+ options;
1260
+ cursor = 0;
1261
+ constructor(t) {
1262
+ super(t, false), this.options = t.options;
1263
+ const s = t.caseSensitive === true, i = this.options.map(({ value: [e] }) => s ? e : e?.toLowerCase());
1264
+ this.cursor = Math.max(i.indexOf(t.initialValue), 0), this.on("key", (e) => {
1265
+ if (!e) return;
1266
+ const o = s ? e : e.toLowerCase();
1267
+ if (!i.includes(o)) return;
1268
+ const n = this.options.find(({ value: [r] }) => s ? r === o : r?.toLowerCase() === o);
1269
+ n && (this.value = n.value, this.state = "submit", this.emit("submit"));
1270
+ });
1271
+ }
1272
+ };
1273
+ var n = class extends V {
1274
+ get userInputWithCursor() {
1275
+ if (this.state === "submit") return this.userInput;
1276
+ const t = this.userInput;
1277
+ if (this.cursor >= t.length) return `${this.userInput}\u2588`;
1278
+ const r = t.slice(0, this.cursor), s = t.slice(this.cursor, this.cursor + 1), e = t.slice(this.cursor + 1);
1279
+ return `${r}${styleText("inverse", s)}${e}`;
1280
+ }
1281
+ get cursor() {
1282
+ return this._cursor;
1283
+ }
1284
+ constructor(t) {
1285
+ super({
1286
+ ...t,
1287
+ initialUserInput: t.initialUserInput ?? t.initialValue
1288
+ }), this.on("userInput", (r) => {
1289
+ this._setValue(r);
1290
+ }), this.on("finalize", () => {
1291
+ this.value || (this.value = t.defaultValue), this.value === void 0 && (this.value = "");
1292
+ });
1293
+ }
1294
+ };
1295
+ //#endregion
1296
+ //#region node_modules/@clack/prompts/dist/index.mjs
1297
+ function isUnicodeSupported() {
1298
+ if (process$1.platform !== "win32") return process$1.env.TERM !== "linux";
1299
+ return Boolean(process$1.env.CI) || Boolean(process$1.env.WT_SESSION) || Boolean(process$1.env.TERMINUS_SUBLIME) || process$1.env.ConEmuTask === "{cmd::Cmder}" || process$1.env.TERM_PROGRAM === "Terminus-Sublime" || process$1.env.TERM_PROGRAM === "vscode" || process$1.env.TERM === "xterm-256color" || process$1.env.TERM === "alacritty" || process$1.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
1300
+ }
1301
+ const unicode = isUnicodeSupported();
1302
+ const isCI = () => process.env.CI === "true";
1303
+ const isTTY = (o) => o.isTTY === true;
1304
+ const unicodeOr = (o, e) => unicode ? o : e;
1305
+ const S_STEP_ACTIVE = unicodeOr("◆", "*");
1306
+ const S_STEP_CANCEL = unicodeOr("■", "x");
1307
+ const S_STEP_ERROR = unicodeOr("▲", "x");
1308
+ const S_STEP_SUBMIT = unicodeOr("◇", "o");
1309
+ const S_BAR_START = unicodeOr("┌", "T");
1310
+ const S_BAR = unicodeOr("│", "|");
1311
+ const S_BAR_END = unicodeOr("└", "—");
1312
+ const S_BAR_START_RIGHT = unicodeOr("┐", "T");
1313
+ const S_BAR_END_RIGHT = unicodeOr("┘", "—");
1314
+ const S_RADIO_ACTIVE = unicodeOr("●", ">");
1315
+ const S_RADIO_INACTIVE = unicodeOr("○", " ");
1316
+ const S_CHECKBOX_ACTIVE = unicodeOr("◻", "[•]");
1317
+ const S_CHECKBOX_SELECTED = unicodeOr("◼", "[+]");
1318
+ const S_CHECKBOX_INACTIVE = unicodeOr("◻", "[ ]");
1319
+ const S_PASSWORD_MASK = unicodeOr("▪", "•");
1320
+ const S_BAR_H = unicodeOr("─", "-");
1321
+ const S_CORNER_TOP_RIGHT = unicodeOr("╮", "+");
1322
+ const S_CONNECT_LEFT = unicodeOr("├", "+");
1323
+ const S_CORNER_BOTTOM_RIGHT = unicodeOr("╯", "+");
1324
+ const S_CORNER_BOTTOM_LEFT = unicodeOr("╰", "+");
1325
+ const S_CORNER_TOP_LEFT = unicodeOr("╭", "+");
1326
+ const S_INFO = unicodeOr("●", "•");
1327
+ const S_SUCCESS = unicodeOr("◆", "*");
1328
+ const S_WARN = unicodeOr("▲", "!");
1329
+ const S_ERROR = unicodeOr("■", "x");
1330
+ const symbol = (o) => {
1331
+ switch (o) {
1332
+ case "initial":
1333
+ case "active": return styleText("cyan", S_STEP_ACTIVE);
1334
+ case "cancel": return styleText("red", S_STEP_CANCEL);
1335
+ case "error": return styleText("yellow", S_STEP_ERROR);
1336
+ case "submit": return styleText("green", S_STEP_SUBMIT);
1337
+ }
1338
+ };
1339
+ const symbolBar = (o) => {
1340
+ switch (o) {
1341
+ case "initial":
1342
+ case "active": return styleText("cyan", S_BAR);
1343
+ case "cancel": return styleText("red", S_BAR);
1344
+ case "error": return styleText("yellow", S_BAR);
1345
+ case "submit": return styleText("green", S_BAR);
1346
+ }
1347
+ };
1348
+ function formatInstructionFooter(o, e) {
1349
+ const r = [`${e ? `${styleText("cyan", S_BAR)} ` : ""}${o.join(" • ")}`];
1350
+ return e && r.push(styleText("cyan", S_BAR_END)), r;
1351
+ }
1352
+ const I = (l, e, w, p, b, C = false) => {
1353
+ let r = e, O = 0;
1354
+ if (C) for (let i = p - 1; i >= w; i--) {
1355
+ const m = l[i];
1356
+ if (m && (r -= m.length), O++, r <= b) break;
1357
+ }
1358
+ else for (let i = w; i < p; i++) {
1359
+ const m = l[i];
1360
+ if (m && (r -= m.length), O++, r <= b) break;
1361
+ }
1362
+ return {
1363
+ lineCount: r,
1364
+ removals: O
1365
+ };
1366
+ };
1367
+ const limitOptions = ({ cursor: l, options: e, style: w, output: p = process.stdout, maxItems: b = Number.POSITIVE_INFINITY, columnPadding: C = 0, rowPadding: r = 4 }) => {
1368
+ const i = getColumns(p) - C, m = getRows(p), M = styleText("dim", "..."), v = Math.max(m - r, 0), a = Math.max(Math.min(b, v), 5);
1369
+ let f = 0;
1370
+ l >= a - 3 && (f = Math.max(Math.min(l - a + 3, e.length - a), 0));
1371
+ let d = a < e.length && f > 0, c = a < e.length && f + a < e.length;
1372
+ const W = Math.min(f + a, e.length), s = [];
1373
+ let g = 0;
1374
+ d && g++, c && g++;
1375
+ const T = f + (d ? 1 : 0), y = W - (c ? 1 : 0);
1376
+ for (let t = T; t < y; t++) {
1377
+ const n = e[t], h = wrapAnsi(n ? w(n, t === l) : "", i, {
1378
+ hard: true,
1379
+ trim: false
1380
+ }).split(`
1381
+ `);
1382
+ s.push(h), g += h.length;
1383
+ }
1384
+ if (g > v) {
1385
+ let t = 0, n = 0, o = g;
1386
+ const h = l - T;
1387
+ let u = v;
1388
+ const L = () => I(s, o, 0, h, u), E = () => I(s, o, h + 1, s.length, u, true);
1389
+ d ? ({lineCount: o, removals: t} = L(), o > u && (c || (u -= 1), {lineCount: o, removals: n} = E())) : (c || (u -= 1), {lineCount: o, removals: n} = E(), o > u && (u -= 1, {lineCount: o, removals: t} = L())), t > 0 && (d = true, s.splice(0, t)), n > 0 && (c = true, s.splice(s.length - n, n));
1390
+ }
1391
+ const x = [];
1392
+ d && x.push(M);
1393
+ for (const t of s) for (const n of t) x.push(n);
1394
+ return c && x.push(M), x;
1395
+ };
1396
+ function P(t) {
1397
+ return t.label ?? String(t.value ?? "");
1398
+ }
1399
+ function E(t, c) {
1400
+ if (!t) return true;
1401
+ const n = (c.label ?? String(c.value ?? "")).toLowerCase(), i = (c.hint ?? "").toLowerCase(), l = String(c.value).toLowerCase(), o = t.toLowerCase();
1402
+ return n.includes(o) || i.includes(o) || l.includes(o);
1403
+ }
1404
+ function N(t, c) {
1405
+ const n = [];
1406
+ for (const i of c) t.includes(i.value) && n.push(i);
1407
+ return n;
1408
+ }
1409
+ const autocomplete = (t) => new T$1({
1410
+ options: t.options,
1411
+ initialValue: t.initialValue ? [t.initialValue] : void 0,
1412
+ initialUserInput: t.initialUserInput,
1413
+ placeholder: t.placeholder,
1414
+ filter: t.filter ?? ((n, i) => E(n, i)),
1415
+ signal: t.signal,
1416
+ input: t.input,
1417
+ output: t.output,
1418
+ validate: t.validate,
1419
+ render() {
1420
+ const n = t.withGuide ?? settings.withGuide, i = n ? [`${styleText("gray", S_BAR)}`, `${symbol(this.state)} ${t.message}`] : [`${symbol(this.state)} ${t.message}`], l = this.userInput, o = this.options, m = t.placeholder, p = l === "" && m !== void 0, $ = (r, s) => {
1421
+ const a = P(r), u = r.hint && r.value === this.focusedValue ? styleText("dim", ` (${r.hint})`) : "";
1422
+ switch (s) {
1423
+ case "active": return `${styleText("green", S_RADIO_ACTIVE)} ${a}${u}`;
1424
+ case "inactive": return `${styleText("dim", S_RADIO_INACTIVE)} ${styleText("dim", a)}`;
1425
+ case "disabled": return `${styleText("gray", S_RADIO_INACTIVE)} ${styleText(["strikethrough", "gray"], a)}`;
1426
+ }
1427
+ };
1428
+ switch (this.state) {
1429
+ case "submit": {
1430
+ const r = N(this.selectedValues, o), s = r.length > 0 ? ` ${styleText("dim", r.map(P).join(", "))}` : "", a = n ? styleText("gray", S_BAR) : "";
1431
+ return `${i.join(`
1432
+ `)}
1433
+ ${a}${s}`;
1434
+ }
1435
+ case "cancel": {
1436
+ const r = l ? ` ${styleText(["strikethrough", "dim"], l)}` : "", s = n ? styleText("gray", S_BAR) : "";
1437
+ return `${i.join(`
1438
+ `)}
1439
+ ${s}${r}`;
1440
+ }
1441
+ default: {
1442
+ const r = this.state === "error" ? "yellow" : "cyan", s = n ? `${styleText(r, S_BAR)} ` : "", a = n ? styleText(r, S_BAR_END) : "";
1443
+ let u = "";
1444
+ if (this.isNavigating || p) {
1445
+ const d = p ? m : l;
1446
+ u = d !== "" ? ` ${styleText("dim", d)}` : "";
1447
+ } else u = ` ${this.userInputWithCursor}`;
1448
+ const V = this.filteredOptions.length !== o.length ? styleText("dim", ` (${this.filteredOptions.length} match${this.filteredOptions.length === 1 ? "" : "es"})`) : "", y = this.filteredOptions.length === 0 && l ? [`${s}${styleText("yellow", "No matches found")}`] : [], b = this.state === "error" ? [`${s}${styleText("yellow", this.error)}`] : [];
1449
+ n && i.push(`${s.trimEnd()}`), i.push(`${s}${styleText("dim", "Search:")}${u}${V}`, ...y, ...b);
1450
+ const g = [`${s}${[
1451
+ `${styleText("dim", "↑/↓")} to select`,
1452
+ `${styleText("dim", "Enter:")} confirm`,
1453
+ `${styleText("dim", "Type:")} to search`
1454
+ ].join(" • ")}`, a], O = this.filteredOptions.length === 0 ? [] : limitOptions({
1455
+ cursor: this.cursor,
1456
+ options: this.filteredOptions,
1457
+ columnPadding: n ? 3 : 0,
1458
+ rowPadding: i.length + g.length,
1459
+ style: (d, f) => $(d, d.disabled ? "disabled" : f ? "active" : "inactive"),
1460
+ maxItems: t.maxItems,
1461
+ output: t.output
1462
+ });
1463
+ return [
1464
+ ...i,
1465
+ ...O.map((d) => `${s}${d}`),
1466
+ ...g
1467
+ ].join(`
1468
+ `);
1469
+ }
1470
+ }
1471
+ }
1472
+ }).prompt();
1473
+ const autocompleteMultiselect = (t) => {
1474
+ const c = (i, l, o, m) => {
1475
+ const p = o.includes(i.value), $ = i.label ?? String(i.value ?? ""), r = i.hint && m !== void 0 && i.value === m ? styleText("dim", ` (${i.hint})`) : "", s = p ? styleText("green", S_CHECKBOX_SELECTED) : styleText("dim", S_CHECKBOX_INACTIVE);
1476
+ return i.disabled ? `${styleText("gray", S_CHECKBOX_INACTIVE)} ${styleText(["strikethrough", "gray"], $)}` : l ? `${s} ${$}${r}` : `${s} ${styleText("dim", $)}`;
1477
+ }, n = new T$1({
1478
+ options: t.options,
1479
+ multiple: true,
1480
+ placeholder: t.placeholder,
1481
+ filter: t.filter ?? ((i, l) => E(i, l)),
1482
+ validate: () => {
1483
+ if (t.required && n.selectedValues.length === 0) return "Please select at least one item";
1484
+ },
1485
+ initialValue: t.initialValues,
1486
+ signal: t.signal,
1487
+ input: t.input,
1488
+ output: t.output,
1489
+ render() {
1490
+ const i = t.withGuide ?? settings.withGuide, l = `${i ? `${styleText("gray", S_BAR)}
1491
+ ` : ""}${symbol(this.state)} ${t.message}
1492
+ `, o = this.userInput, m = t.placeholder, p = o === "" && m !== void 0, $ = this.isNavigating || p ? styleText("dim", p ? m : o) : this.userInputWithCursor, r = this.options, s = this.filteredOptions.length !== r.length ? styleText("dim", ` (${this.filteredOptions.length} match${this.filteredOptions.length === 1 ? "" : "es"})`) : "";
1493
+ switch (this.state) {
1494
+ case "submit": return `${l}${i ? `${styleText("gray", S_BAR)} ` : ""}${styleText("dim", `${this.selectedValues.length} items selected`)}`;
1495
+ case "cancel": return `${l}${i ? `${styleText("gray", S_BAR)} ` : ""}${styleText(["strikethrough", "dim"], o)}`;
1496
+ default: {
1497
+ const a = this.state === "error" ? "yellow" : "cyan", u = i ? `${styleText(a, S_BAR)} ` : "", V = i ? styleText(a, S_BAR_END) : "", y = [
1498
+ `${styleText("dim", "↑/↓")} to navigate`,
1499
+ `${styleText("dim", this.isNavigating ? "Space/Tab:" : "Tab:")} select`,
1500
+ `${styleText("dim", "Enter:")} confirm`,
1501
+ `${styleText("dim", "Type:")} to search`
1502
+ ], b = this.filteredOptions.length === 0 && o ? [`${u}${styleText("yellow", "No matches found")}`] : [], v = this.state === "error" ? [`${u}${styleText("yellow", this.error)}`] : [], g = [
1503
+ ...`${l}${i ? styleText(a, S_BAR) : ""}`.split(`
1504
+ `),
1505
+ `${u}${styleText("dim", "Search:")} ${$}${s}`,
1506
+ ...b,
1507
+ ...v
1508
+ ], O = [`${u}${y.join(" • ")}`, V], d = limitOptions({
1509
+ cursor: this.cursor,
1510
+ options: this.filteredOptions,
1511
+ style: (f, _) => c(f, _, this.selectedValues, this.focusedValue),
1512
+ maxItems: t.maxItems,
1513
+ output: t.output,
1514
+ rowPadding: g.length + O.length
1515
+ });
1516
+ return [
1517
+ ...g,
1518
+ ...d.map((f) => `${u}${f}`),
1519
+ ...O
1520
+ ].join(`
1521
+ `);
1522
+ }
1523
+ }
1524
+ }
1525
+ });
1526
+ return n.prompt();
1527
+ };
1528
+ const J = [
1529
+ S_CORNER_TOP_LEFT,
1530
+ S_CORNER_TOP_RIGHT,
1531
+ S_CORNER_BOTTOM_LEFT,
1532
+ S_CORNER_BOTTOM_RIGHT
1533
+ ];
1534
+ const K = [
1535
+ S_BAR_START,
1536
+ S_BAR_START_RIGHT,
1537
+ S_BAR_END,
1538
+ S_BAR_END_RIGHT
1539
+ ];
1540
+ function A$1(n, e, t, o) {
1541
+ let i = t, f = t;
1542
+ return o === "center" ? i = Math.floor((e - n) / 2) : o === "right" && (i = e - n - t), f = e - i - n, [i, f];
1543
+ }
1544
+ const Q = (n) => n;
1545
+ const box = (n = "", e = "", t) => {
1546
+ const o = t?.output ?? process.stdout, i = getColumns(o), R = 2, u = t?.titlePadding ?? 1, h = t?.contentPadding ?? 2, w = t?.width === void 0 || t.width === "auto" ? 1 : Math.min(1, t.width), m = t?.withGuide ?? settings.withGuide ? `${S_BAR} ` : "", b = t?.formatBorder ?? Q, a = (t?.rounded ? J : K).map(b), _ = b(S_BAR_H), B = b(S_BAR), p = fastStringWidth(m), x = fastStringWidth(e), O = i - p;
1547
+ let r = Math.floor(i * w) - p;
1548
+ if (t?.width === "auto") {
1549
+ const c = n.split(`
1550
+ `);
1551
+ let s = x + u * 2;
1552
+ for (const G of c) {
1553
+ const P = fastStringWidth(G) + h * 2;
1554
+ P > s && (s = P);
1555
+ }
1556
+ const g = s + R;
1557
+ g < r && (r = g);
1558
+ }
1559
+ r % 2 !== 0 && (r < O ? r++ : r--);
1560
+ const d = r - R, S = d - u * 2, T = x > S ? `${e.slice(0, S - 3)}...` : e, [y, W] = A$1(fastStringWidth(T), d, u, t?.titleAlign), L = wrapAnsi(n, d - h * 2, {
1561
+ hard: true,
1562
+ trim: false
1563
+ });
1564
+ o.write(`${m}${a[0]}${_.repeat(y)}${T}${_.repeat(W)}${a[1]}
1565
+ `);
1566
+ const E = L.split(`
1567
+ `);
1568
+ for (const c of E) {
1569
+ const [s, g] = A$1(fastStringWidth(c), d, h, t?.contentAlign);
1570
+ o.write(`${m}${B}${" ".repeat(s)}${c}${" ".repeat(g)}${B}
1571
+ `);
1572
+ }
1573
+ o.write(`${m}${a[2]}${_.repeat(d)}${a[3]}
1574
+ `);
1575
+ };
1576
+ const confirm = (i) => {
1577
+ const a = i.active ?? "Yes", s = i.inactive ?? "No";
1578
+ return new r({
1579
+ active: a,
1580
+ inactive: s,
1581
+ signal: i.signal,
1582
+ input: i.input,
1583
+ output: i.output,
1584
+ initialValue: i.initialValue ?? true,
1585
+ render() {
1586
+ const e = i.withGuide ?? settings.withGuide, u = `${symbol(this.state)} `, l = e ? `${styleText("gray", S_BAR)} ` : "", f = wrapTextWithPrefix(i.output, i.message, l, u), o = `${e ? `${styleText("gray", S_BAR)}
1587
+ ` : ""}${f}
1588
+ `, c = this.value ? a : s;
1589
+ switch (this.state) {
1590
+ case "submit": return `${o}${e ? `${styleText("gray", S_BAR)} ` : ""}${styleText("dim", c)}`;
1591
+ case "cancel": return `${o}${e ? `${styleText("gray", S_BAR)} ` : ""}${styleText(["strikethrough", "dim"], c)}${e ? `
1592
+ ${styleText("gray", S_BAR)}` : ""}`;
1593
+ default: {
1594
+ const r = e ? `${styleText("cyan", S_BAR)} ` : "", g = e ? styleText("cyan", S_BAR_END) : "";
1595
+ return `${o}${r}${this.value ? `${styleText("green", S_RADIO_ACTIVE)} ${a}` : `${styleText("dim", S_RADIO_INACTIVE)} ${styleText("dim", a)}`}${i.vertical ? e ? `
1596
+ ${styleText("cyan", S_BAR)} ` : `
1597
+ ` : ` ${styleText("dim", "/")} `}${this.value ? `${styleText("dim", S_RADIO_INACTIVE)} ${styleText("dim", s)}` : `${styleText("green", S_RADIO_ACTIVE)} ${s}`}
1598
+ ${g}
1599
+ `;
1600
+ }
1601
+ }
1602
+ }
1603
+ }).prompt();
1604
+ };
1605
+ const date = (e) => {
1606
+ const r = e.validate;
1607
+ return new U({
1608
+ ...e,
1609
+ validate(t) {
1610
+ if (t === void 0) return e.defaultValue !== void 0 ? void 0 : r ? runValidation(r, t) : settings.date.messages.required;
1611
+ const o = (i) => i.toISOString().slice(0, 10);
1612
+ if (e.minDate && o(t) < o(e.minDate)) return settings.date.messages.afterMin(e.minDate);
1613
+ if (e.maxDate && o(t) > o(e.maxDate)) return settings.date.messages.beforeMax(e.maxDate);
1614
+ if (r) return runValidation(r, t);
1615
+ },
1616
+ render() {
1617
+ const t = (e?.withGuide ?? settings.withGuide) !== false, i = `${`${t ? `${styleText("gray", S_BAR)}
1618
+ ` : ""}${symbol(this.state)} `}${e.message}
1619
+ `, l = this.state !== "initial" ? this.state : "active", d = b(this, l), c = this.value instanceof Date ? this.formattedValue : "";
1620
+ switch (this.state) {
1621
+ case "error": {
1622
+ const a = this.error ? ` ${styleText("yellow", this.error)}` : "", s = t ? `${styleText("yellow", S_BAR)} ` : "", f = t ? styleText("yellow", S_BAR_END) : "";
1623
+ return `${i.trim()}
1624
+ ${s}${d}
1625
+ ${f}${a}
1626
+ `;
1627
+ }
1628
+ case "submit": {
1629
+ const a = c ? ` ${styleText("dim", c)}` : "";
1630
+ return `${i}${t ? styleText("gray", S_BAR) : ""}${a}`;
1631
+ }
1632
+ case "cancel": {
1633
+ const a = c ? ` ${styleText(["strikethrough", "dim"], c)}` : "", s = t ? styleText("gray", S_BAR) : "";
1634
+ return `${i}${s}${a}${c.trim() ? `
1635
+ ${s}` : ""}`;
1636
+ }
1637
+ default: {
1638
+ const a = t ? `${styleText("cyan", S_BAR)} ` : "", s = t ? styleText("cyan", S_BAR_END) : "", f = t ? `${styleText("cyan", S_BAR)} ` : "";
1639
+ return `${i}${a}${d}${this.inlineError ? `
1640
+ ${f}${styleText("yellow", this.inlineError)}` : ""}
1641
+ ${s}
1642
+ `;
1643
+ }
1644
+ }
1645
+ }
1646
+ }).prompt();
1647
+ };
1648
+ function b(e, r) {
1649
+ const t = e.segmentValues, o = e.segmentCursor;
1650
+ if (r === "submit" || r === "cancel") return e.formattedValue;
1651
+ const i = styleText("gray", e.separator);
1652
+ return e.segments.map((l, d) => {
1653
+ const c = d === o.segmentIndex && !["submit", "cancel"].includes(r), a = p[l.type];
1654
+ return x(t[l.type], {
1655
+ isActive: c,
1656
+ label: a
1657
+ });
1658
+ }).join(i);
1659
+ }
1660
+ function x(e, r) {
1661
+ const t = !e || e.replace(/_/g, "") === "";
1662
+ return r.isActive ? styleText("inverse", t ? r.label : e.replace(/_/g, " ")) : t ? styleText("dim", r.label) : e.replace(/_/g, styleText("dim", " "));
1663
+ }
1664
+ const p = {
1665
+ year: "yyyy",
1666
+ month: "mm",
1667
+ day: "dd"
1668
+ };
1669
+ const group = async (o, r) => {
1670
+ const t = {}, p = Object.keys(o);
1671
+ for (const e of p) {
1672
+ const i = o[e], n = await i({ results: t })?.catch((a) => {
1673
+ throw a;
1674
+ });
1675
+ if (typeof r?.onCancel == "function" && isCancel(n)) {
1676
+ t[e] = "canceled", r.onCancel({ results: t });
1677
+ continue;
1678
+ }
1679
+ t[e] = n;
1680
+ }
1681
+ return t;
1682
+ };
1683
+ const MULTISELECT_INSTRUCTIONS = [
1684
+ `${styleText("dim", "↑/↓")} to navigate`,
1685
+ `${styleText("dim", "Space:")} select`,
1686
+ `${styleText("dim", "Enter:")} confirm`
1687
+ ];
1688
+ const m = (i, u) => i.split(`
1689
+ `).map((d) => u(d)).join(`
1690
+ `);
1691
+ const multiselect = (i) => {
1692
+ const u = (t, a) => {
1693
+ const r = t.label ?? String(t.value);
1694
+ return a === "disabled" ? `${styleText("gray", S_CHECKBOX_INACTIVE)} ${m(r, (o) => styleText(["strikethrough", "gray"], o))}${t.hint ? ` ${styleText("dim", `(${t.hint ?? "disabled"})`)}` : ""}` : a === "active" ? `${styleText("cyan", S_CHECKBOX_ACTIVE)} ${r}${t.hint ? ` ${styleText("dim", `(${t.hint})`)}` : ""}` : a === "selected" ? `${styleText("green", S_CHECKBOX_SELECTED)} ${m(r, (o) => styleText("dim", o))}${t.hint ? ` ${styleText("dim", `(${t.hint})`)}` : ""}` : a === "cancelled" ? `${m(r, (o) => styleText(["strikethrough", "dim"], o))}` : a === "active-selected" ? `${styleText("green", S_CHECKBOX_SELECTED)} ${r}${t.hint ? ` ${styleText("dim", `(${t.hint})`)}` : ""}` : a === "submitted" ? `${m(r, (o) => styleText("dim", o))}` : `${styleText("dim", S_CHECKBOX_INACTIVE)} ${m(r, (o) => styleText("dim", o))}`;
1695
+ }, d = i.required ?? true, v = i.showInstructions ?? true;
1696
+ return new a({
1697
+ options: i.options,
1698
+ signal: i.signal,
1699
+ input: i.input,
1700
+ output: i.output,
1701
+ initialValues: i.initialValues,
1702
+ required: d,
1703
+ cursorAt: i.cursorAt,
1704
+ validate(t) {
1705
+ if (d && (t === void 0 || t.length === 0)) return `Please select at least one option.
1706
+ ${styleText("reset", styleText("dim", `Press ${styleText([
1707
+ "gray",
1708
+ "bgWhite",
1709
+ "inverse"
1710
+ ], " space ")} to select, ${styleText("gray", styleText("bgWhite", styleText("inverse", " enter ")))} to submit`))}`;
1711
+ },
1712
+ render() {
1713
+ const t = i.withGuide ?? settings.withGuide, a = wrapTextWithPrefix(i.output, i.message, t ? `${symbolBar(this.state)} ` : "", `${symbol(this.state)} `), r = `${t ? `${styleText("gray", S_BAR)}
1714
+ ` : ""}${a}
1715
+ `, o = this.value ?? [], p = (n, l) => {
1716
+ if (n.disabled) return u(n, "disabled");
1717
+ const s = o.includes(n.value);
1718
+ return l && s ? u(n, "active-selected") : s ? u(n, "selected") : u(n, l ? "active" : "inactive");
1719
+ };
1720
+ switch (this.state) {
1721
+ case "submit": {
1722
+ const n = this.options.filter(({ value: s }) => o.includes(s)).map((s) => u(s, "submitted")).join(styleText("dim", ", ")) || styleText("dim", "none");
1723
+ return `${r}${wrapTextWithPrefix(i.output, n, t ? `${styleText("gray", S_BAR)} ` : "")}`;
1724
+ }
1725
+ case "cancel": {
1726
+ const n = this.options.filter(({ value: s }) => o.includes(s)).map((s) => u(s, "cancelled")).join(styleText("dim", ", "));
1727
+ if (n.trim() === "") return `${r}${styleText("gray", S_BAR)}`;
1728
+ return `${r}${wrapTextWithPrefix(i.output, n, t ? `${styleText("gray", S_BAR)} ` : "")}${t ? `
1729
+ ${styleText("gray", S_BAR)}` : ""}`;
1730
+ }
1731
+ case "error": {
1732
+ const n = t ? `${styleText("yellow", S_BAR)} ` : "", l = this.error.split(`
1733
+ `).map(($, C) => C === 0 ? `${t ? `${styleText("yellow", S_BAR_END)} ` : ""}${styleText("yellow", $)}` : ` ${$}`).join(`
1734
+ `), s = r.split(`
1735
+ `).length, h = l.split(`
1736
+ `).length + 1;
1737
+ return `${r}${n}${limitOptions({
1738
+ output: i.output,
1739
+ options: this.options,
1740
+ cursor: this.cursor,
1741
+ maxItems: i.maxItems,
1742
+ columnPadding: n.length,
1743
+ rowPadding: s + h,
1744
+ style: p
1745
+ }).join(`
1746
+ ${n}`)}
1747
+ ${l}
1748
+ `;
1749
+ }
1750
+ default: {
1751
+ const n = t ? `${styleText("cyan", S_BAR)} ` : "", l = r.split(`
1752
+ `).length, s = v ? formatInstructionFooter(MULTISELECT_INSTRUCTIONS, t) : t ? [styleText("cyan", S_BAR_END)] : [], h = s.join(`
1753
+ `), $ = s.length + 1;
1754
+ return `${r}${n}${limitOptions({
1755
+ output: i.output,
1756
+ options: this.options,
1757
+ cursor: this.cursor,
1758
+ maxItems: i.maxItems,
1759
+ columnPadding: n.length,
1760
+ rowPadding: l + $,
1761
+ style: p
1762
+ }).join(`
1763
+ ${n}`)}
1764
+ ${h}
1765
+ `;
1766
+ }
1767
+ }
1768
+ }
1769
+ }).prompt();
1770
+ };
1771
+ const groupMultiselect = (o) => {
1772
+ const { selectableGroups: h = true, groupSpacing: x = 0 } = o, m = (n, l, g = []) => {
1773
+ const a = n.label ?? String(n.value), t = typeof n.group == "string", s = t && (g[g.indexOf(n) + 1] ?? { group: true }), u = t && s && s.group === true;
1774
+ let r = "", c = "";
1775
+ t && (h ? (r = u ? `${S_BAR_END} ` : `${S_BAR} `, c = u ? " " : `${S_BAR} `) : r = " ");
1776
+ let i = "";
1777
+ if (x > 0 && !t && (i = `
1778
+ `.repeat(x)), l === "active") return wrapTextWithPrefix(o.output, `${a}${n.hint ? ` ${styleText("dim", `(${n.hint})`)}` : ""}`, `${i}${styleText("dim", r)} `, `${i}${styleText("dim", r)}${styleText("cyan", S_CHECKBOX_ACTIVE)} `, `${i}${styleText("dim", c)} `);
1779
+ if (l === "group-active") return wrapTextWithPrefix(o.output, a, `${i}${r} `, `${i}${r}${styleText("cyan", S_CHECKBOX_ACTIVE)} `, `${i}${c} `, (d) => styleText("dim", d));
1780
+ if (l === "group-active-selected") return wrapTextWithPrefix(o.output, a, `${i}${r} `, `${i}${r}${styleText("green", S_CHECKBOX_SELECTED)} `, `${i}${c} `, (d) => styleText("dim", d));
1781
+ if (l === "selected") {
1782
+ const d = t || h ? styleText("green", S_CHECKBOX_SELECTED) : "";
1783
+ return wrapTextWithPrefix(o.output, `${a}${n.hint ? ` (${n.hint})` : ""}`, `${i}${styleText("dim", r)} `, `${i}${styleText("dim", r)}${d} `, `${i}${styleText("dim", c)} `, (S) => styleText("dim", S));
1784
+ }
1785
+ if (l === "cancelled") return `${styleText(["strikethrough", "dim"], a)}`;
1786
+ if (l === "active-selected") return wrapTextWithPrefix(o.output, `${a}${n.hint ? ` ${styleText("dim", `(${n.hint})`)}` : ""}`, `${i}${styleText("dim", r)} `, `${i}${styleText("dim", r)}${styleText("green", S_CHECKBOX_SELECTED)} `, `${i}${styleText("dim", c)} `);
1787
+ if (l === "submitted") return `${styleText("dim", a)}`;
1788
+ const f = t || h ? styleText("dim", S_CHECKBOX_INACTIVE) : "";
1789
+ return wrapTextWithPrefix(o.output, a, `${i}${styleText("dim", r)} `, `${i}${styleText("dim", r)}${f} `, `${i}${styleText("dim", c)} `, (d) => styleText("dim", d));
1790
+ }, y = o.required ?? true, I = o.showInstructions ?? true;
1791
+ return new u$2({
1792
+ options: o.options,
1793
+ signal: o.signal,
1794
+ input: o.input,
1795
+ output: o.output,
1796
+ initialValues: o.initialValues,
1797
+ required: y,
1798
+ cursorAt: o.cursorAt,
1799
+ selectableGroups: h,
1800
+ validate(n) {
1801
+ if (y && (n === void 0 || n.length === 0)) return `Please select at least one option.
1802
+ ${styleText("reset", styleText("dim", `Press ${styleText([
1803
+ "gray",
1804
+ "bgWhite",
1805
+ "inverse"
1806
+ ], " space ")} to select, ${styleText("gray", styleText(["bgWhite", "inverse"], " enter "))} to submit`))}`;
1807
+ },
1808
+ render() {
1809
+ const n = o.withGuide ?? settings.withGuide, l = `${n ? `${styleText("gray", S_BAR)}
1810
+ ` : ""}${symbol(this.state)} ${o.message}
1811
+ `, g = this.value ?? [], a = (t, s) => {
1812
+ const u = this.options, r = g.includes(t.value) || t.group === true && this.isGroupSelected(`${t.value}`);
1813
+ return !s && typeof t.group == "string" && this.options[this.cursor]?.value === t.group ? m(t, r ? "group-active-selected" : "group-active", u) : s && r ? m(t, "active-selected", u) : r ? m(t, "selected", u) : m(t, s ? "active" : "inactive", u);
1814
+ };
1815
+ switch (this.state) {
1816
+ case "submit": {
1817
+ const t = this.options.filter(({ value: u }) => g.includes(u)).map((u) => m(u, "submitted")), s = t.length === 0 ? "" : ` ${t.join(styleText("dim", ", "))}`;
1818
+ return `${l}${n ? styleText("gray", S_BAR) : ""}${s}`;
1819
+ }
1820
+ case "cancel": {
1821
+ const t = this.options.filter(({ value: s }) => g.includes(s)).map((s) => m(s, "cancelled")).join(styleText("dim", ", "));
1822
+ return `${l}${n ? `${styleText("gray", S_BAR)} ` : ""}${t.trim() ? `${t}${n ? `
1823
+ ${styleText("gray", S_BAR)}` : ""}` : ""}`;
1824
+ }
1825
+ case "error": {
1826
+ const t = n ? `${styleText("yellow", S_BAR)} ` : "", s = this.error.split(`
1827
+ `).map((i, f) => f === 0 ? `${n ? `${styleText("yellow", S_BAR_END)} ` : ""}${styleText("yellow", i)}` : ` ${i}`).join(`
1828
+ `), u = l.split(`
1829
+ `).length, r = s.split(`
1830
+ `).length + 1;
1831
+ return `${l}${t}${limitOptions({
1832
+ output: o.output,
1833
+ options: this.options,
1834
+ cursor: this.cursor,
1835
+ maxItems: o.maxItems,
1836
+ columnPadding: t.length,
1837
+ rowPadding: u + r,
1838
+ style: a
1839
+ }).join(`
1840
+ ${t}`)}
1841
+ ${s}
1842
+ `;
1843
+ }
1844
+ default: {
1845
+ const t = n ? `${styleText("cyan", S_BAR)} ` : "", s = l.split(`
1846
+ `).length, u = I ? formatInstructionFooter(MULTISELECT_INSTRUCTIONS, n) : n ? [styleText("cyan", S_BAR_END)] : [], r = u.join(`
1847
+ `), c = u.length + 1;
1848
+ return `${l}${t}${limitOptions({
1849
+ output: o.output,
1850
+ options: this.options,
1851
+ cursor: this.cursor,
1852
+ maxItems: o.maxItems,
1853
+ columnPadding: t.length,
1854
+ rowPadding: s + c,
1855
+ style: a
1856
+ }).join(`
1857
+ ${t}`)}
1858
+ ${r}
1859
+ `;
1860
+ }
1861
+ }
1862
+ }
1863
+ }).prompt();
1864
+ };
1865
+ const log = {
1866
+ message: (s = [], { symbol: e = styleText("gray", S_BAR), secondarySymbol: r = styleText("gray", S_BAR), output: m = process.stdout, spacing: l = 1, withGuide: c } = {}) => {
1867
+ const t = [], o = c ?? settings.withGuide, f = o ? r : "", O = o ? `${e} ` : "", u = o ? `${r} ` : "";
1868
+ for (let i = 0; i < l; i++) t.push(f);
1869
+ const g = Array.isArray(s) ? s : s.split(`
1870
+ `);
1871
+ if (g.length > 0) {
1872
+ const [i, ...y] = g;
1873
+ i.length > 0 ? t.push(`${O}${i}`) : t.push(o ? e : "");
1874
+ for (const p of y) p.length > 0 ? t.push(`${u}${p}`) : t.push(o ? r : "");
1875
+ }
1876
+ m.write(`${t.join(`
1877
+ `)}
1878
+ `);
1879
+ },
1880
+ info: (s, e) => {
1881
+ log.message(s, {
1882
+ ...e,
1883
+ symbol: styleText("blue", S_INFO)
1884
+ });
1885
+ },
1886
+ success: (s, e) => {
1887
+ log.message(s, {
1888
+ ...e,
1889
+ symbol: styleText("green", S_SUCCESS)
1890
+ });
1891
+ },
1892
+ step: (s, e) => {
1893
+ log.message(s, {
1894
+ ...e,
1895
+ symbol: styleText("green", S_STEP_SUBMIT)
1896
+ });
1897
+ },
1898
+ warn: (s, e) => {
1899
+ log.message(s, {
1900
+ ...e,
1901
+ symbol: styleText("yellow", S_WARN)
1902
+ });
1903
+ },
1904
+ /** alias for `log.warn()`. */
1905
+ warning: (s, e) => {
1906
+ log.warn(s, e);
1907
+ },
1908
+ error: (s, e) => {
1909
+ log.message(s, {
1910
+ ...e,
1911
+ symbol: styleText("red", S_ERROR)
1912
+ });
1913
+ }
1914
+ };
1915
+ const cancel = (o = "", t) => {
1916
+ const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText("gray", S_BAR_END)} ` : "";
1917
+ i.write(`${e}${styleText("red", o)}
1918
+
1919
+ `);
1920
+ };
1921
+ const intro = (o = "", t) => {
1922
+ const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText("gray", S_BAR_START)} ` : "";
1923
+ i.write(`${e}${o}
1924
+ `);
1925
+ };
1926
+ const outro = (o = "", t) => {
1927
+ const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText("gray", S_BAR)}
1928
+ ${styleText("gray", S_BAR_END)} ` : "";
1929
+ i.write(`${e}${o}
1930
+
1931
+ `);
1932
+ };
1933
+ const multiline = (e) => new h({
1934
+ validate: e.validate,
1935
+ placeholder: e.placeholder,
1936
+ defaultValue: e.defaultValue,
1937
+ initialValue: e.initialValue,
1938
+ showSubmit: e.showSubmit,
1939
+ output: e.output,
1940
+ signal: e.signal,
1941
+ input: e.input,
1942
+ render() {
1943
+ const i = e?.withGuide ?? settings.withGuide, o = `${`${i ? `${styleText("gray", S_BAR)}
1944
+ ` : ""}${symbol(this.state)} `}${e.message}
1945
+ `, m = e.placeholder && e.placeholder.length > 0 ? styleText("inverse", e.placeholder[0]) + styleText("dim", e.placeholder.slice(1)) : styleText(["inverse", "hidden"], "_"), a = this.userInput ? this.userInputWithCursor : m, l = this.value ?? "", c = e.showSubmit ? `
1946
+ ${styleText(this.focused === "submit" ? "cyan" : "dim", "[ submit ]")}` : "";
1947
+ switch (this.state) {
1948
+ case "error": {
1949
+ const n = `${styleText("yellow", S_BAR)} `;
1950
+ return `${o}${i ? wrapTextWithPrefix(e.output, a, n, void 0) : a}
1951
+ ${styleText("yellow", S_BAR_END)} ${styleText("yellow", this.error)}${c}
1952
+ `;
1953
+ }
1954
+ case "submit": {
1955
+ const n = `${styleText("gray", S_BAR)} `;
1956
+ return `${o}${i ? wrapTextWithPrefix(e.output, l, n, void 0, void 0, (u) => styleText("dim", u)) : l ? styleText("dim", l) : ""}`;
1957
+ }
1958
+ case "cancel": {
1959
+ const n = `${styleText("gray", S_BAR)} `;
1960
+ return `${o}${i ? wrapTextWithPrefix(e.output, l, n, void 0, void 0, (u) => styleText(["strikethrough", "dim"], u)) : l ? styleText(["strikethrough", "dim"], l) : ""}`;
1961
+ }
1962
+ default: {
1963
+ const n = i ? `${styleText("cyan", S_BAR)} ` : "", r = i ? styleText("cyan", S_BAR_END) : "";
1964
+ return `${o}${i ? wrapTextWithPrefix(e.output, a, n) : a}
1965
+ ${r}${c}
1966
+ `;
1967
+ }
1968
+ }
1969
+ }
1970
+ }).prompt();
1971
+ const W$1 = (o) => o;
1972
+ const C = (o, e, s) => {
1973
+ const a = {
1974
+ hard: true,
1975
+ trim: false
1976
+ }, i = wrapAnsi(o, e, a).split(`
1977
+ `), c = i.reduce((n, t) => Math.max(fastStringWidth(t), n), 0);
1978
+ return wrapAnsi(o, e - (i.map(s).reduce((n, t) => Math.max(fastStringWidth(t), n), 0) - c), a);
1979
+ };
1980
+ const note = (o = "", e = "", s) => {
1981
+ const a = s?.output ?? process$1.stdout, i = s?.withGuide ?? settings.withGuide, c = s?.format ?? W$1, g = [
1982
+ "",
1983
+ ...C(o, getColumns(a) - 6, c).split(`
1984
+ `).map(c),
1985
+ ""
1986
+ ], n = fastStringWidth(e), t = Math.max(g.reduce((m, F) => {
1987
+ const O = fastStringWidth(F);
1988
+ return O > m ? O : m;
1989
+ }, 0), n) + 2, h = g.map((m) => `${styleText("gray", S_BAR)} ${m}${" ".repeat(t - fastStringWidth(m))}${styleText("gray", S_BAR)}`).join(`
1990
+ `), T = i ? `${styleText("gray", S_BAR)}
1991
+ ` : "", l$1 = i ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT;
1992
+ a.write(`${T}${styleText("green", S_STEP_SUBMIT)} ${styleText("reset", e)} ${styleText("gray", S_BAR_H.repeat(Math.max(t - n - 1, 1)) + S_CORNER_TOP_RIGHT)}
1993
+ ${h}
1994
+ ${styleText("gray", l$1 + S_BAR_H.repeat(t + 2) + S_CORNER_BOTTOM_RIGHT)}
1995
+ `);
1996
+ };
1997
+ const password = (r) => new u$1({
1998
+ validate: r.validate,
1999
+ mask: r.mask ?? S_PASSWORD_MASK,
2000
+ signal: r.signal,
2001
+ input: r.input,
2002
+ output: r.output,
2003
+ render() {
2004
+ const e = r.withGuide ?? settings.withGuide, o = `${e ? `${styleText("gray", S_BAR)}
2005
+ ` : ""}${symbol(this.state)} ${r.message}
2006
+ `, c = this.userInputWithCursor, i = this.masked;
2007
+ switch (this.state) {
2008
+ case "error": {
2009
+ const s = e ? `${styleText("yellow", S_BAR)} ` : "", n = e ? `${styleText("yellow", S_BAR_END)} ` : "", l = i ?? "";
2010
+ return r.clearOnError && this.clear(), `${o.trim()}
2011
+ ${s}${l}
2012
+ ${n}${styleText("yellow", this.error)}
2013
+ `;
2014
+ }
2015
+ case "submit": return `${o}${e ? `${styleText("gray", S_BAR)} ` : ""}${i ? styleText("dim", i) : ""}`;
2016
+ case "cancel": return `${o}${e ? `${styleText("gray", S_BAR)} ` : ""}${i ? styleText(["strikethrough", "dim"], i) : ""}${i && e ? `
2017
+ ${styleText("gray", S_BAR)}` : ""}`;
2018
+ default: return `${o}${e ? `${styleText("cyan", S_BAR)} ` : ""}${c}
2019
+ ${e ? styleText("cyan", S_BAR_END) : ""}
2020
+ `;
2021
+ }
2022
+ }
2023
+ }).prompt();
2024
+ const path = (e) => {
2025
+ const a = e.validate;
2026
+ return autocomplete({
2027
+ ...e,
2028
+ initialUserInput: e.initialValue ?? e.root ?? process.cwd(),
2029
+ maxItems: 5,
2030
+ validate(t) {
2031
+ if (!Array.isArray(t)) {
2032
+ if (!t) return "Please select a path";
2033
+ if (a) return runValidation(a, t);
2034
+ }
2035
+ },
2036
+ options() {
2037
+ const t = this.userInput;
2038
+ if (t === "") return [];
2039
+ try {
2040
+ let i;
2041
+ existsSync(t) ? lstatSync(t).isDirectory() && (!e.directory || t.endsWith("/")) ? i = t : i = dirname(t) : i = dirname(t);
2042
+ const c = t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t;
2043
+ return readdirSync(i).map((r) => {
2044
+ const n = join(i, r);
2045
+ return {
2046
+ name: r,
2047
+ path: n,
2048
+ isDirectory: lstatSync(n).isDirectory()
2049
+ };
2050
+ }).filter(({ path: r, isDirectory: n }) => r.startsWith(c) && (n || !e.directory)).map((r) => ({ value: r.path }));
2051
+ } catch {
2052
+ return [];
2053
+ }
2054
+ }
2055
+ });
2056
+ };
2057
+ const W = (l) => styleText("magenta", l);
2058
+ const spinner = ({ indicator: l = "dots", onCancel: h, output: n = process.stdout, cancelMessage: G, errorMessage: O, frames: E = unicode ? [
2059
+ "◒",
2060
+ "◐",
2061
+ "◓",
2062
+ "◑"
2063
+ ] : [
2064
+ "•",
2065
+ "o",
2066
+ "O",
2067
+ "0"
2068
+ ], delay: F = unicode ? 80 : 120, signal: m, ...I } = {}) => {
2069
+ const u = isCI();
2070
+ let M, T, d = false, S = false, s = "", p, w = performance.now();
2071
+ const x = getColumns(n), k = I?.styleFrame ?? W, g = (e) => {
2072
+ const r = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
2073
+ S = e === 1, d && (a(r, e), S && typeof h == "function" && h());
2074
+ }, f = () => g(2), i = () => g(1), A = () => {
2075
+ process.on("uncaughtExceptionMonitor", f), process.on("unhandledRejection", f), process.on("SIGINT", i), process.on("SIGTERM", i), process.on("exit", g), m && m.addEventListener("abort", i);
2076
+ }, H = () => {
2077
+ process.removeListener("uncaughtExceptionMonitor", f), process.removeListener("unhandledRejection", f), process.removeListener("SIGINT", i), process.removeListener("SIGTERM", i), process.removeListener("exit", g), m && m.removeEventListener("abort", i);
2078
+ }, y = () => {
2079
+ if (p === void 0) return;
2080
+ u && n.write(`
2081
+ `);
2082
+ const r = wrapAnsi(p, x, {
2083
+ hard: true,
2084
+ trim: false
2085
+ }).split(`
2086
+ `);
2087
+ r.length > 1 && n.write(import_src.cursor.up(r.length - 1)), n.write(import_src.cursor.to(0)), n.write(import_src.erase.down());
2088
+ }, C = (e) => e.replace(/\.+$/, ""), _ = (e) => {
2089
+ const r = (performance.now() - e) / 1e3, t = Math.floor(r / 60), o = Math.floor(r % 60);
2090
+ return t > 0 ? `[${t}m ${o}s]` : `[${o}s]`;
2091
+ }, N = I.withGuide ?? settings.withGuide, P = (e = "") => {
2092
+ d = true, M = block({ output: n }), s = C(e), w = performance.now(), N && n.write(`${styleText("gray", S_BAR)}
2093
+ `);
2094
+ let r = 0, t = 0;
2095
+ A(), T = setInterval(() => {
2096
+ if (u && s === p) return;
2097
+ y(), p = s;
2098
+ const o = k(E[r]);
2099
+ let v;
2100
+ if (u) v = `${o} ${s}...`;
2101
+ else if (l === "timer") v = `${o} ${s} ${_(w)}`;
2102
+ else {
2103
+ const B = ".".repeat(Math.floor(t)).slice(0, 3);
2104
+ v = `${o} ${s}${B}`;
2105
+ }
2106
+ const j = wrapAnsi(v, x, {
2107
+ hard: true,
2108
+ trim: false
2109
+ });
2110
+ n.write(j), r = r + 1 < E.length ? r + 1 : 0, t = t < 4 ? t + .125 : 0;
2111
+ }, F);
2112
+ }, a = (e = "", r = 0, t = false) => {
2113
+ if (!d) return;
2114
+ d = false, clearInterval(T), y();
2115
+ const o = r === 0 ? styleText("green", S_STEP_SUBMIT) : r === 1 ? styleText("red", S_STEP_CANCEL) : styleText("red", S_STEP_ERROR);
2116
+ s = e ?? s, t || (l === "timer" ? n.write(`${o} ${s} ${_(w)}
2117
+ `) : n.write(`${o} ${s}
2118
+ `)), H(), M();
2119
+ };
2120
+ return {
2121
+ start: P,
2122
+ stop: (e = "") => a(e, 0),
2123
+ message: (e = "") => {
2124
+ s = C(e ?? s);
2125
+ },
2126
+ cancel: (e = "") => a(e, 1),
2127
+ error: (e = "") => a(e, 2),
2128
+ clear: () => a("", 0, true),
2129
+ get isCancelled() {
2130
+ return S;
2131
+ }
2132
+ };
2133
+ };
2134
+ const u = {
2135
+ light: unicodeOr("─", "-"),
2136
+ heavy: unicodeOr("━", "="),
2137
+ block: unicodeOr("█", "#")
2138
+ };
2139
+ function progress({ style: o = "heavy", max: d = 100, size: v = 40, ...x } = {}) {
2140
+ const r = spinner(x);
2141
+ let a = 0, n = "";
2142
+ const c = Math.max(1, d), l = Math.max(1, v), S = (t) => {
2143
+ switch (t) {
2144
+ case "initial":
2145
+ case "active": return (e) => styleText("magenta", e);
2146
+ case "error":
2147
+ case "cancel": return (e) => styleText("red", e);
2148
+ case "submit": return (e) => styleText("green", e);
2149
+ default: return (e) => styleText("magenta", e);
2150
+ }
2151
+ }, p = (t, e) => {
2152
+ const m = Math.floor(a / c * l);
2153
+ return `${S(t)(u[o].repeat(m))}${styleText("dim", u[o].repeat(l - m))} ${e}`;
2154
+ }, h = (t = "") => {
2155
+ n = t, r.start(p("initial", t));
2156
+ }, g = (t = 1, e) => {
2157
+ a = Math.min(c, t + a), r.message(p("active", e ?? n)), n = e ?? n;
2158
+ };
2159
+ return {
2160
+ start: h,
2161
+ stop: r.stop,
2162
+ cancel: r.cancel,
2163
+ error: r.error,
2164
+ clear: r.clear,
2165
+ advance: g,
2166
+ isCancelled: r.isCancelled,
2167
+ message: (t) => g(0, t)
2168
+ };
2169
+ }
2170
+ const SELECT_INSTRUCTIONS = [`${styleText("dim", "↑/↓")} to navigate`, `${styleText("dim", "Enter:")} confirm`];
2171
+ const c = (t, o) => t.includes(`
2172
+ `) ? t.split(`
2173
+ `).map((d) => o(d)).join(`
2174
+ `) : o(t);
2175
+ const select = (t) => {
2176
+ const o = (n, m) => {
2177
+ if (n === void 0) return "";
2178
+ const s = n.label ?? String(n.value);
2179
+ switch (m) {
2180
+ case "disabled": return `${styleText("gray", S_RADIO_INACTIVE)} ${c(s, (i) => styleText("gray", i))}${n.hint ? ` ${styleText("dim", `(${n.hint ?? "disabled"})`)}` : ""}`;
2181
+ case "selected": return `${c(s, (i) => styleText("dim", i))}`;
2182
+ case "active": return `${styleText("green", S_RADIO_ACTIVE)} ${s}${n.hint ? ` ${styleText("dim", `(${n.hint})`)}` : ""}`;
2183
+ case "cancelled": return `${c(s, (i) => styleText(["strikethrough", "dim"], i))}`;
2184
+ default: return `${styleText("dim", S_RADIO_INACTIVE)} ${c(s, (i) => styleText("dim", i))}`;
2185
+ }
2186
+ }, d = t.showInstructions ?? true;
2187
+ return new n$1({
2188
+ options: t.options,
2189
+ signal: t.signal,
2190
+ input: t.input,
2191
+ output: t.output,
2192
+ initialValue: t.initialValue,
2193
+ render() {
2194
+ const n = t.withGuide ?? settings.withGuide, m = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, i = wrapTextWithPrefix(t.output, t.message, s, m), u = `${n ? `${styleText("gray", S_BAR)}
2195
+ ` : ""}${i}
2196
+ `;
2197
+ switch (this.state) {
2198
+ case "submit": {
2199
+ const r = n ? `${styleText("gray", S_BAR)} ` : "";
2200
+ return `${u}${wrapTextWithPrefix(t.output, o(this.options[this.cursor], "selected"), r)}`;
2201
+ }
2202
+ case "cancel": {
2203
+ const r = n ? `${styleText("gray", S_BAR)} ` : "";
2204
+ return `${u}${wrapTextWithPrefix(t.output, o(this.options[this.cursor], "cancelled"), r)}${n ? `
2205
+ ${styleText("gray", S_BAR)}` : ""}`;
2206
+ }
2207
+ default: {
2208
+ const r = n ? `${styleText("cyan", S_BAR)} ` : "", a = u.split(`
2209
+ `).length, p = d ? formatInstructionFooter(SELECT_INSTRUCTIONS, n) : n ? [styleText("cyan", S_BAR_END)] : [], b = p.join(`
2210
+ `), f = p.length + 1;
2211
+ return `${u}${r}${limitOptions({
2212
+ output: t.output,
2213
+ cursor: this.cursor,
2214
+ options: this.options,
2215
+ maxItems: t.maxItems,
2216
+ columnPadding: r.length,
2217
+ rowPadding: a + f,
2218
+ style: (g, x) => o(g, g.disabled ? "disabled" : x ? "active" : "inactive")
2219
+ }).join(`
2220
+ ${r}`)}
2221
+ ${b}
2222
+ `;
2223
+ }
2224
+ }
2225
+ }
2226
+ }).prompt();
2227
+ };
2228
+ const selectKey = (t) => {
2229
+ const l = (e, a = "inactive") => {
2230
+ if (e === void 0) return "";
2231
+ const n = e.label ?? String(e.value);
2232
+ return a === "selected" ? `${styleText("dim", n)}` : a === "cancelled" ? `${styleText(["strikethrough", "dim"], n)}` : a === "active" ? `${styleText(["bgCyan", "gray"], ` ${e.value} `)} ${n}${e.hint ? ` ${styleText("dim", `(${e.hint})`)}` : ""}` : `${styleText([
2233
+ "gray",
2234
+ "bgWhite",
2235
+ "inverse"
2236
+ ], ` ${e.value} `)} ${n}${e.hint ? ` ${styleText("dim", `(${e.hint})`)}` : ""}`;
2237
+ };
2238
+ return new u$3({
2239
+ options: t.options,
2240
+ signal: t.signal,
2241
+ input: t.input,
2242
+ output: t.output,
2243
+ initialValue: t.initialValue,
2244
+ caseSensitive: t.caseSensitive,
2245
+ render() {
2246
+ const e = t.withGuide ?? settings.withGuide, a = `${e ? `${styleText("gray", S_BAR)}
2247
+ ` : ""}${symbol(this.state)} ${t.message}
2248
+ `;
2249
+ switch (this.state) {
2250
+ case "submit": {
2251
+ const n = e ? `${styleText("gray", S_BAR)} ` : "", s = this.options.find((u) => u.value === this.value) ?? t.options[0];
2252
+ return `${a}${wrapTextWithPrefix(t.output, l(s, "selected"), n)}`;
2253
+ }
2254
+ case "cancel": {
2255
+ const n = e ? `${styleText("gray", S_BAR)} ` : "";
2256
+ return `${a}${wrapTextWithPrefix(t.output, l(this.options[0], "cancelled"), n)}${e ? `
2257
+ ${styleText("gray", S_BAR)}` : ""}`;
2258
+ }
2259
+ default: {
2260
+ const n = e ? `${styleText("cyan", S_BAR)} ` : "", s = e ? styleText("cyan", S_BAR_END) : "";
2261
+ return `${a}${this.options.map((u, d) => wrapTextWithPrefix(t.output, l(u, d === this.cursor ? "active" : "inactive"), n)).join(`
2262
+ `)}
2263
+ ${s}
2264
+ `;
2265
+ }
2266
+ }
2267
+ }
2268
+ }).prompt();
2269
+ };
2270
+ const i = `${styleText("gray", S_BAR)} `;
2271
+ const stream = {
2272
+ message: async (e, { symbol: l = styleText("gray", S_BAR) } = {}) => {
2273
+ process.stdout.write(`${styleText("gray", S_BAR)}
2274
+ ${l} `);
2275
+ let s = 3;
2276
+ for await (let r of e) {
2277
+ r = r.replace(/\n/g, `
2278
+ ${i}`), r.includes(`
2279
+ `) && (s = 3 + stripVTControlCharacters(r.slice(r.lastIndexOf(`
2280
+ `))).length);
2281
+ const o = stripVTControlCharacters(r).length;
2282
+ s + o < process.stdout.columns ? (s += o, process.stdout.write(r)) : (process.stdout.write(`
2283
+ ${i}${r.trimStart()}`), s = 3 + stripVTControlCharacters(r.trimStart()).length);
2284
+ }
2285
+ process.stdout.write(`
2286
+ `);
2287
+ },
2288
+ info: (e) => stream.message(e, { symbol: styleText("blue", S_INFO) }),
2289
+ success: (e) => stream.message(e, { symbol: styleText("green", S_SUCCESS) }),
2290
+ step: (e) => stream.message(e, { symbol: styleText("green", S_STEP_SUBMIT) }),
2291
+ warn: (e) => stream.message(e, { symbol: styleText("yellow", S_WARN) }),
2292
+ /** alias for `log.warn()`. */
2293
+ warning: (e) => stream.warn(e),
2294
+ error: (e) => stream.message(e, { symbol: styleText("red", S_ERROR) })
2295
+ };
2296
+ const tasks = async (o, e) => {
2297
+ for (const t of o) {
2298
+ if (t.enabled === false) continue;
2299
+ const s = spinner(e);
2300
+ s.start(t.title);
2301
+ const n = await t.task(s.message);
2302
+ s.stop(n || t.title);
2303
+ }
2304
+ };
2305
+ const A = (l) => l.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g, "");
2306
+ const taskLog = (l) => {
2307
+ const r = l.output ?? process.stdout, O = getColumns(r), i = styleText("gray", S_BAR), p = l.spacing ?? 1, k = 3, m = l.retainLog === true, d = !isCI() && isTTY(r);
2308
+ r.write(`${i}
2309
+ `), r.write(`${styleText("green", S_STEP_SUBMIT)} ${l.title}
2310
+ `);
2311
+ for (let e = 0; e < p; e++) r.write(`${i}
2312
+ `);
2313
+ const n = [{
2314
+ value: "",
2315
+ full: ""
2316
+ }];
2317
+ let v = false;
2318
+ const f = (e) => {
2319
+ if (n.length === 0) return;
2320
+ let s = 0;
2321
+ e && (s += p + 2);
2322
+ for (const t of n) {
2323
+ const { value: o, result: a } = t;
2324
+ let g = a?.message ?? o;
2325
+ if (g.length === 0) continue;
2326
+ a === void 0 && t.header !== void 0 && t.header !== "" && (g += `
2327
+ ${t.header}`);
2328
+ const E = g.split(`
2329
+ `).reduce((b, w) => w === "" ? b + 1 : b + Math.ceil((w.length + k) / O), 0);
2330
+ s += E;
2331
+ }
2332
+ s > 0 && (s += 1, r.write(import_src.erase.lines(s)));
2333
+ }, h = (e, s, t) => {
2334
+ const o = t ? `${e.full}
2335
+ ${e.value}` : e.value;
2336
+ e.header !== void 0 && e.header !== "" && log.message(e.header.split(`
2337
+ `).map((a) => styleText("bold", a)), {
2338
+ output: r,
2339
+ secondarySymbol: i,
2340
+ symbol: i,
2341
+ spacing: 0
2342
+ }), log.message(o.split(`
2343
+ `).map((a) => styleText("dim", a)), {
2344
+ output: r,
2345
+ secondarySymbol: i,
2346
+ symbol: i,
2347
+ spacing: s ?? p
2348
+ });
2349
+ }, T = () => {
2350
+ for (const e of n) {
2351
+ const { header: s, value: t, full: o } = e;
2352
+ (s === void 0 || s.length === 0) && t.length === 0 || h(e, void 0, m === true && o.length > 0);
2353
+ }
2354
+ }, L = (e, s, t) => {
2355
+ if (f(false), (t?.raw !== true || !v) && e.value !== "" && (e.value += `
2356
+ `), e.value += A(s), v = t?.raw === true, l.limit !== void 0) {
2357
+ const o = e.value.split(`
2358
+ `), a = o.length - l.limit;
2359
+ if (a > 0) {
2360
+ const g = o.splice(0, a);
2361
+ m && (e.full += (e.full === "" ? "" : `
2362
+ `) + g.join(`
2363
+ `));
2364
+ }
2365
+ e.value = o.join(`
2366
+ `);
2367
+ }
2368
+ d && y();
2369
+ }, y = () => {
2370
+ for (const e of n) e.result ? e.result.status === "error" ? log.error(e.result.message, {
2371
+ output: r,
2372
+ secondarySymbol: i,
2373
+ spacing: 0
2374
+ }) : log.success(e.result.message, {
2375
+ output: r,
2376
+ secondarySymbol: i,
2377
+ spacing: 0
2378
+ }) : e.value !== "" && h(e, 0);
2379
+ }, B = (e, s) => {
2380
+ f(false), e.result = s, d && y();
2381
+ };
2382
+ return {
2383
+ message(e, s) {
2384
+ L(n[0], e, s);
2385
+ },
2386
+ group(e) {
2387
+ const s = {
2388
+ header: e,
2389
+ value: "",
2390
+ full: ""
2391
+ };
2392
+ return n.push(s), {
2393
+ message(t, o) {
2394
+ L(s, t, o);
2395
+ },
2396
+ error(t) {
2397
+ B(s, {
2398
+ status: "error",
2399
+ message: t
2400
+ });
2401
+ },
2402
+ success(t) {
2403
+ B(s, {
2404
+ status: "success",
2405
+ message: t
2406
+ });
2407
+ }
2408
+ };
2409
+ },
2410
+ error(e, s) {
2411
+ f(true), log.error(e, {
2412
+ output: r,
2413
+ secondarySymbol: i,
2414
+ spacing: 1
2415
+ }), s?.showLog !== false && T(), n.splice(1, n.length - 1), n[0].value = "", n[0].full = "";
2416
+ },
2417
+ success(e, s) {
2418
+ f(true), log.success(e, {
2419
+ output: r,
2420
+ secondarySymbol: i,
2421
+ spacing: 1
2422
+ }), s?.showLog === true && T(), n.splice(1, n.length - 1), n[0].value = "", n[0].full = "";
2423
+ }
2424
+ };
2425
+ };
2426
+ const text = (e) => new n({
2427
+ validate: e.validate,
2428
+ placeholder: e.placeholder,
2429
+ defaultValue: e.defaultValue,
2430
+ initialValue: e.initialValue,
2431
+ output: e.output,
2432
+ signal: e.signal,
2433
+ input: e.input,
2434
+ render() {
2435
+ const i = e?.withGuide ?? settings.withGuide, s = `${`${i ? `${styleText("gray", S_BAR)}
2436
+ ` : ""}${symbol(this.state)} `}${e.message}
2437
+ `, c = e.placeholder && e.placeholder.length > 0 ? styleText("inverse", e.placeholder[0]) + styleText("dim", e.placeholder.slice(1)) : styleText(["inverse", "hidden"], "_"), o = this.userInput ? this.userInputWithCursor : c, l = this.value ?? "";
2438
+ switch (this.state) {
2439
+ case "error": {
2440
+ const n = this.error ? ` ${styleText("yellow", this.error)}` : "", r = i ? `${styleText("yellow", S_BAR)} ` : "", d = i ? styleText("yellow", S_BAR_END) : "";
2441
+ return `${s.trim()}
2442
+ ${r}${o}
2443
+ ${d}${n}
2444
+ `;
2445
+ }
2446
+ case "submit": {
2447
+ const n = l ? ` ${styleText("dim", l)}` : "";
2448
+ return `${s}${i ? styleText("gray", S_BAR) : ""}${n}`;
2449
+ }
2450
+ case "cancel": {
2451
+ const n = l ? ` ${styleText(["strikethrough", "dim"], l)}` : "", r = i ? styleText("gray", S_BAR) : "";
2452
+ return `${s}${r}${n}${l.trim() ? `
2453
+ ${r}` : ""}`;
2454
+ }
2455
+ default: return `${s}${i ? `${styleText("cyan", S_BAR)} ` : ""}${o}
2456
+ ${i ? styleText("cyan", S_BAR_END) : ""}
2457
+ `;
2458
+ }
2459
+ }
2460
+ }).prompt();
2461
+ //#endregion
2462
+ export { MULTISELECT_INSTRUCTIONS, SELECT_INSTRUCTIONS, S_BAR, S_BAR_END, S_BAR_END_RIGHT, S_BAR_H, S_BAR_START, S_BAR_START_RIGHT, S_CHECKBOX_ACTIVE, S_CHECKBOX_INACTIVE, S_CHECKBOX_SELECTED, S_CONNECT_LEFT, S_CORNER_BOTTOM_LEFT, S_CORNER_BOTTOM_RIGHT, S_CORNER_TOP_LEFT, S_CORNER_TOP_RIGHT, S_ERROR, S_INFO, S_PASSWORD_MASK, S_RADIO_ACTIVE, S_RADIO_INACTIVE, S_STEP_ACTIVE, S_STEP_CANCEL, S_STEP_ERROR, S_STEP_SUBMIT, S_SUCCESS, S_WARN, autocomplete, autocompleteMultiselect, box, cancel, confirm, date, formatInstructionFooter, group, groupMultiselect, intro, isCI, isCancel, isTTY, limitOptions, log, multiline, multiselect, note, outro, password, path, progress, select, selectKey, settings, spinner, stream, symbol, symbolBar, taskLog, tasks, text, unicode, unicodeOr, updateSettings };