@pz4l/tinyimg-cli 0.0.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.
- package/README.md +227 -0
- package/README.zh-CN.md +227 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1093 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +62 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1093 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import process$1, { stdin, stdout } from "node:process";
|
|
3
|
+
import cac from "cac";
|
|
4
|
+
import kleur from "kleur";
|
|
5
|
+
import fs from "node:fs/promises";
|
|
6
|
+
import { AllCompressionFailedError, AllKeysExhaustedError, KeyPool, NoValidKeysError, compressImages, maskKey, queryQuota, readConfig, validateKey, writeConfig } from "tinyimg-core";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import fastGlob from "fast-glob";
|
|
9
|
+
import { stripVTControlCharacters, styleText } from "node:util";
|
|
10
|
+
import "node:readline";
|
|
11
|
+
import ot from "node:readline";
|
|
12
|
+
import "node:tty";
|
|
13
|
+
import "node:fs";
|
|
14
|
+
//#region \0rolldown/runtime.js
|
|
15
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/utils/files.ts
|
|
18
|
+
const IMAGE_EXTENSIONS = [
|
|
19
|
+
".png",
|
|
20
|
+
".jpg",
|
|
21
|
+
".jpeg"
|
|
22
|
+
];
|
|
23
|
+
const BACKSLASH_REGEX = /\\/g;
|
|
24
|
+
/**
|
|
25
|
+
* Expand input paths (files, directories, globs) to absolute file paths
|
|
26
|
+
* Filters for supported image formats only
|
|
27
|
+
*/
|
|
28
|
+
async function expandInputs(inputs) {
|
|
29
|
+
const results = [];
|
|
30
|
+
for (const input of inputs) try {
|
|
31
|
+
const stat = await fs.stat(input);
|
|
32
|
+
if (stat.isFile()) {
|
|
33
|
+
if (isImageFile(input)) results.push(path.resolve(input));
|
|
34
|
+
} else if (stat.isDirectory()) {
|
|
35
|
+
const pattern = path.join(input, "**", "*").replace(BACKSLASH_REGEX, "/");
|
|
36
|
+
const files = await fastGlob.glob(pattern, {
|
|
37
|
+
absolute: true,
|
|
38
|
+
onlyFiles: true
|
|
39
|
+
});
|
|
40
|
+
results.push(...files.filter(isImageFile));
|
|
41
|
+
}
|
|
42
|
+
} catch {
|
|
43
|
+
try {
|
|
44
|
+
const files = await fastGlob.glob(input, {
|
|
45
|
+
absolute: true,
|
|
46
|
+
onlyFiles: true
|
|
47
|
+
});
|
|
48
|
+
results.push(...files.filter(isImageFile));
|
|
49
|
+
} catch {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return Array.from(new Set(results));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Resolve output path for compressed image
|
|
57
|
+
* If outputDir provided, join with basename of input
|
|
58
|
+
* Otherwise, return input path (overwrite in place)
|
|
59
|
+
*/
|
|
60
|
+
async function resolveOutputPath(inputPath, outputDir) {
|
|
61
|
+
if (outputDir) {
|
|
62
|
+
const outputPath = path.join(outputDir, path.basename(inputPath));
|
|
63
|
+
const absOutputPath = path.resolve(outputPath);
|
|
64
|
+
await fs.mkdir(path.dirname(absOutputPath), { recursive: true });
|
|
65
|
+
return absOutputPath;
|
|
66
|
+
}
|
|
67
|
+
return path.resolve(inputPath);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Check if file is a supported image format
|
|
71
|
+
*/
|
|
72
|
+
function isImageFile(filePath) {
|
|
73
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
74
|
+
return IMAGE_EXTENSIONS.includes(ext);
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/utils/format.ts
|
|
78
|
+
/**
|
|
79
|
+
* Format progress counter for batch compression
|
|
80
|
+
*/
|
|
81
|
+
function formatProgress(current, total) {
|
|
82
|
+
return kleur.cyan(`Compressing ${current}/${total}...`);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Format compression result with size comparison
|
|
86
|
+
*/
|
|
87
|
+
function formatResult(inputPath, _outputPath, originalSize, compressedSize) {
|
|
88
|
+
const basename = path.basename(inputPath);
|
|
89
|
+
const savedPercent = ((originalSize - compressedSize) / originalSize * 100).toFixed(1);
|
|
90
|
+
const originalStr = formatBytes(originalSize);
|
|
91
|
+
const compressedStr = formatBytes(compressedSize);
|
|
92
|
+
return `${kleur.green("✓")} ${kleur.yellow(`${basename}: ${originalStr} → ${compressedStr} (${savedPercent}% saved)`)}`;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Convert bytes to human readable format
|
|
96
|
+
*/
|
|
97
|
+
function formatBytes(bytes) {
|
|
98
|
+
if (bytes < 1024) return `${bytes}B`;
|
|
99
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)}KB`;
|
|
100
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)}MB`;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/commands/compress.ts
|
|
104
|
+
/**
|
|
105
|
+
* Main compression command handler
|
|
106
|
+
*/
|
|
107
|
+
async function compressCommand(inputs, options) {
|
|
108
|
+
if (inputs.length === 0) {
|
|
109
|
+
console.error(kleur.red("Error: No input files specified"));
|
|
110
|
+
console.log("Usage: tinyimg [options] <input...>");
|
|
111
|
+
process$1.exit(1);
|
|
112
|
+
}
|
|
113
|
+
const files = await expandInputs(inputs);
|
|
114
|
+
if (files.length === 0) {
|
|
115
|
+
console.error(kleur.red("Error: No valid image files found"));
|
|
116
|
+
console.log("Supported formats: PNG, JPG, JPEG");
|
|
117
|
+
process$1.exit(1);
|
|
118
|
+
}
|
|
119
|
+
console.log(kleur.cyan("\nConfiguration:"));
|
|
120
|
+
console.log(` Mode: ${options.mode || "random"}`);
|
|
121
|
+
console.log(` Parallel: ${options.parallel || "8"}`);
|
|
122
|
+
console.log(` Cache: ${options.cache !== false ? "enabled" : "disabled"}`);
|
|
123
|
+
console.log(` Files: ${files.length}\n`);
|
|
124
|
+
const buffers = [];
|
|
125
|
+
for (const file of files) try {
|
|
126
|
+
const buffer = await fs.readFile(file);
|
|
127
|
+
buffers.push(buffer);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.error(kleur.red(`Error reading ${file}: ${error.message}`));
|
|
130
|
+
process$1.exit(1);
|
|
131
|
+
}
|
|
132
|
+
const compressOptions = {
|
|
133
|
+
cache: options.cache !== false,
|
|
134
|
+
concurrency: options.parallel ? Number.parseInt(options.parallel, 10) : 8
|
|
135
|
+
};
|
|
136
|
+
if (options.mode) compressOptions.mode = options.mode;
|
|
137
|
+
if (options.mode) try {
|
|
138
|
+
compressOptions.keyPool = new KeyPool(options.mode);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error(kleur.red(`Error: ${error.message}`));
|
|
141
|
+
process$1.exit(1);
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const results = await compressImages(buffers, compressOptions);
|
|
145
|
+
for (let i = 0; i < files.length; i++) {
|
|
146
|
+
const inputFile = files[i];
|
|
147
|
+
const originalBuffer = buffers[i];
|
|
148
|
+
const compressedBuffer = results[i];
|
|
149
|
+
const outputPath = await resolveOutputPath(inputFile, options.output);
|
|
150
|
+
console.log(formatProgress(i + 1, files.length));
|
|
151
|
+
await fs.writeFile(outputPath, compressedBuffer);
|
|
152
|
+
console.log(formatResult(inputFile, outputPath, originalBuffer.length, compressedBuffer.length));
|
|
153
|
+
}
|
|
154
|
+
console.log(kleur.green("\n✓ Compression complete"));
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (error instanceof AllKeysExhaustedError) {
|
|
157
|
+
console.error(kleur.red("Error: All API keys have exhausted quota"));
|
|
158
|
+
console.log("Please add more keys or wait for quota to reset");
|
|
159
|
+
} else if (error instanceof NoValidKeysError) {
|
|
160
|
+
console.error(kleur.red("Error: No valid API keys configured"));
|
|
161
|
+
console.log("Please add API keys using: tinyimg key add <key>");
|
|
162
|
+
} else if (error instanceof AllCompressionFailedError) {
|
|
163
|
+
console.error(kleur.red("Error: All compression methods failed"));
|
|
164
|
+
console.log("Please check your network connection and API status");
|
|
165
|
+
} else console.error(kleur.red(`Error: ${error.message}`));
|
|
166
|
+
process$1.exit(1);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region ../../node_modules/.pnpm/@clack+core@1.1.0/node_modules/@clack/core/dist/index.mjs
|
|
171
|
+
var import_src = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
172
|
+
const ESC = "\x1B";
|
|
173
|
+
const CSI = `${ESC}[`;
|
|
174
|
+
const beep = "\x07";
|
|
175
|
+
const cursor = {
|
|
176
|
+
to(x, y) {
|
|
177
|
+
if (!y) return `${CSI}${x + 1}G`;
|
|
178
|
+
return `${CSI}${y + 1};${x + 1}H`;
|
|
179
|
+
},
|
|
180
|
+
move(x, y) {
|
|
181
|
+
let ret = "";
|
|
182
|
+
if (x < 0) ret += `${CSI}${-x}D`;
|
|
183
|
+
else if (x > 0) ret += `${CSI}${x}C`;
|
|
184
|
+
if (y < 0) ret += `${CSI}${-y}A`;
|
|
185
|
+
else if (y > 0) ret += `${CSI}${y}B`;
|
|
186
|
+
return ret;
|
|
187
|
+
},
|
|
188
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
189
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
190
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
191
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
192
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
193
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
194
|
+
left: `${CSI}G`,
|
|
195
|
+
hide: `${CSI}?25l`,
|
|
196
|
+
show: `${CSI}?25h`,
|
|
197
|
+
save: `${ESC}7`,
|
|
198
|
+
restore: `${ESC}8`
|
|
199
|
+
};
|
|
200
|
+
module.exports = {
|
|
201
|
+
cursor,
|
|
202
|
+
scroll: {
|
|
203
|
+
up: (count = 1) => `${CSI}S`.repeat(count),
|
|
204
|
+
down: (count = 1) => `${CSI}T`.repeat(count)
|
|
205
|
+
},
|
|
206
|
+
erase: {
|
|
207
|
+
screen: `${CSI}2J`,
|
|
208
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
209
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
210
|
+
line: `${CSI}2K`,
|
|
211
|
+
lineEnd: `${CSI}K`,
|
|
212
|
+
lineStart: `${CSI}1K`,
|
|
213
|
+
lines(count) {
|
|
214
|
+
let clear = "";
|
|
215
|
+
for (let i = 0; i < count; i++) clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
216
|
+
if (count) clear += cursor.left;
|
|
217
|
+
return clear;
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
beep
|
|
221
|
+
};
|
|
222
|
+
})))();
|
|
223
|
+
function x$1(t, e, s) {
|
|
224
|
+
if (!s.some((u) => !u.disabled)) return t;
|
|
225
|
+
const i = t + e, r = Math.max(s.length - 1, 0), n = i < 0 ? r : i > r ? 0 : i;
|
|
226
|
+
return s[n].disabled ? x$1(n, e < 0 ? -1 : 1, s) : n;
|
|
227
|
+
}
|
|
228
|
+
const at = (t) => t === 161 || t === 164 || t === 167 || t === 168 || t === 170 || t === 173 || t === 174 || t >= 176 && t <= 180 || t >= 182 && t <= 186 || t >= 188 && t <= 191 || t === 198 || t === 208 || t === 215 || t === 216 || t >= 222 && t <= 225 || t === 230 || t >= 232 && t <= 234 || t === 236 || t === 237 || t === 240 || t === 242 || t === 243 || t >= 247 && t <= 250 || t === 252 || t === 254 || t === 257 || t === 273 || t === 275 || t === 283 || t === 294 || t === 295 || t === 299 || t >= 305 && t <= 307 || t === 312 || t >= 319 && t <= 322 || t === 324 || t >= 328 && t <= 331 || t === 333 || t === 338 || t === 339 || t === 358 || t === 359 || t === 363 || t === 462 || t === 464 || t === 466 || t === 468 || t === 470 || t === 472 || t === 474 || t === 476 || t === 593 || t === 609 || t === 708 || t === 711 || t >= 713 && t <= 715 || t === 717 || t === 720 || t >= 728 && t <= 731 || t === 733 || t === 735 || t >= 768 && t <= 879 || t >= 913 && t <= 929 || t >= 931 && t <= 937 || t >= 945 && t <= 961 || t >= 963 && t <= 969 || t === 1025 || t >= 1040 && t <= 1103 || t === 1105 || t === 8208 || t >= 8211 && t <= 8214 || t === 8216 || t === 8217 || t === 8220 || t === 8221 || t >= 8224 && t <= 8226 || t >= 8228 && t <= 8231 || t === 8240 || t === 8242 || t === 8243 || t === 8245 || t === 8251 || t === 8254 || t === 8308 || t === 8319 || t >= 8321 && t <= 8324 || t === 8364 || t === 8451 || t === 8453 || t === 8457 || t === 8467 || t === 8470 || t === 8481 || t === 8482 || t === 8486 || t === 8491 || t === 8531 || t === 8532 || t >= 8539 && t <= 8542 || t >= 8544 && t <= 8555 || t >= 8560 && t <= 8569 || t === 8585 || t >= 8592 && t <= 8601 || t === 8632 || t === 8633 || t === 8658 || t === 8660 || t === 8679 || t === 8704 || t === 8706 || t === 8707 || t === 8711 || t === 8712 || t === 8715 || t === 8719 || t === 8721 || t === 8725 || t === 8730 || t >= 8733 && t <= 8736 || t === 8739 || t === 8741 || t >= 8743 && t <= 8748 || t === 8750 || t >= 8756 && t <= 8759 || t === 8764 || t === 8765 || t === 8776 || t === 8780 || t === 8786 || t === 8800 || t === 8801 || t >= 8804 && t <= 8807 || t === 8810 || t === 8811 || t === 8814 || t === 8815 || t === 8834 || t === 8835 || t === 8838 || t === 8839 || t === 8853 || t === 8857 || t === 8869 || t === 8895 || t === 8978 || t >= 9312 && t <= 9449 || t >= 9451 && t <= 9547 || t >= 9552 && t <= 9587 || t >= 9600 && t <= 9615 || t >= 9618 && t <= 9621 || t === 9632 || t === 9633 || t >= 9635 && t <= 9641 || t === 9650 || t === 9651 || t === 9654 || t === 9655 || t === 9660 || t === 9661 || t === 9664 || t === 9665 || t >= 9670 && t <= 9672 || t === 9675 || t >= 9678 && t <= 9681 || t >= 9698 && t <= 9701 || t === 9711 || t === 9733 || t === 9734 || t === 9737 || t === 9742 || t === 9743 || t === 9756 || t === 9758 || t === 9792 || t === 9794 || t === 9824 || t === 9825 || t >= 9827 && t <= 9829 || t >= 9831 && t <= 9834 || t === 9836 || t === 9837 || t === 9839 || t === 9886 || t === 9887 || t === 9919 || t >= 9926 && t <= 9933 || t >= 9935 && t <= 9939 || t >= 9941 && t <= 9953 || t === 9955 || t === 9960 || t === 9961 || t >= 9963 && t <= 9969 || t === 9972 || t >= 9974 && t <= 9977 || t === 9979 || t === 9980 || t === 9982 || t === 9983 || t === 10045 || t >= 10102 && t <= 10111 || t >= 11094 && t <= 11097 || t >= 12872 && t <= 12879 || t >= 57344 && t <= 63743 || t >= 65024 && t <= 65039 || t === 65533 || t >= 127232 && t <= 127242 || t >= 127248 && t <= 127277 || t >= 127280 && t <= 127337 || t >= 127344 && t <= 127373 || t === 127375 || t === 127376 || t >= 127387 && t <= 127404 || t >= 917760 && t <= 917999 || t >= 983040 && t <= 1048573 || t >= 1048576 && t <= 1114109, lt = (t) => t === 12288 || t >= 65281 && t <= 65376 || t >= 65504 && t <= 65510, ht = (t) => t >= 4352 && t <= 4447 || t === 8986 || t === 8987 || t === 9001 || t === 9002 || t >= 9193 && t <= 9196 || t === 9200 || t === 9203 || t === 9725 || t === 9726 || t === 9748 || t === 9749 || t >= 9800 && t <= 9811 || t === 9855 || t === 9875 || t === 9889 || t === 9898 || t === 9899 || t === 9917 || t === 9918 || t === 9924 || t === 9925 || t === 9934 || t === 9940 || t === 9962 || t === 9970 || t === 9971 || t === 9973 || t === 9978 || t === 9981 || t === 9989 || t === 9994 || t === 9995 || t === 10024 || t === 10060 || t === 10062 || t >= 10067 && t <= 10069 || t === 10071 || t >= 10133 && t <= 10135 || t === 10160 || t === 10175 || t === 11035 || t === 11036 || t === 11088 || t === 11093 || t >= 11904 && t <= 11929 || t >= 11931 && t <= 12019 || t >= 12032 && t <= 12245 || t >= 12272 && t <= 12287 || t >= 12289 && t <= 12350 || t >= 12353 && t <= 12438 || t >= 12441 && t <= 12543 || t >= 12549 && t <= 12591 || t >= 12593 && t <= 12686 || t >= 12688 && t <= 12771 || t >= 12783 && t <= 12830 || t >= 12832 && t <= 12871 || t >= 12880 && t <= 19903 || t >= 19968 && t <= 42124 || t >= 42128 && t <= 42182 || t >= 43360 && t <= 43388 || t >= 44032 && t <= 55203 || t >= 63744 && t <= 64255 || t >= 65040 && t <= 65049 || t >= 65072 && t <= 65106 || t >= 65108 && t <= 65126 || t >= 65128 && t <= 65131 || t >= 94176 && t <= 94180 || t === 94192 || t === 94193 || t >= 94208 && t <= 100343 || t >= 100352 && t <= 101589 || t >= 101632 && t <= 101640 || t >= 110576 && t <= 110579 || t >= 110581 && t <= 110587 || t === 110589 || t === 110590 || t >= 110592 && t <= 110882 || t === 110898 || t >= 110928 && t <= 110930 || t === 110933 || t >= 110948 && t <= 110951 || t >= 110960 && t <= 111355 || t === 126980 || t === 127183 || t === 127374 || t >= 127377 && t <= 127386 || t >= 127488 && t <= 127490 || t >= 127504 && t <= 127547 || t >= 127552 && t <= 127560 || t === 127568 || t === 127569 || t >= 127584 && t <= 127589 || t >= 127744 && t <= 127776 || t >= 127789 && t <= 127797 || t >= 127799 && t <= 127868 || t >= 127870 && t <= 127891 || t >= 127904 && t <= 127946 || t >= 127951 && t <= 127955 || t >= 127968 && t <= 127984 || t === 127988 || t >= 127992 && t <= 128062 || t === 128064 || t >= 128066 && t <= 128252 || t >= 128255 && t <= 128317 || t >= 128331 && t <= 128334 || t >= 128336 && t <= 128359 || t === 128378 || t === 128405 || t === 128406 || t === 128420 || t >= 128507 && t <= 128591 || t >= 128640 && t <= 128709 || t === 128716 || t >= 128720 && t <= 128722 || t >= 128725 && t <= 128727 || t >= 128732 && t <= 128735 || t === 128747 || t === 128748 || t >= 128756 && t <= 128764 || t >= 128992 && t <= 129003 || t === 129008 || t >= 129292 && t <= 129338 || t >= 129340 && t <= 129349 || t >= 129351 && t <= 129535 || t >= 129648 && t <= 129660 || t >= 129664 && t <= 129672 || t >= 129680 && t <= 129725 || t >= 129727 && t <= 129733 || t >= 129742 && t <= 129755 || t >= 129760 && t <= 129768 || t >= 129776 && t <= 129784 || t >= 131072 && t <= 196605 || t >= 196608 && t <= 262141, O = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y, y = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y, L = /\t{1,1000}/y, P = /[\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, M = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y, ct = /\p{M}+/gu, ft$1 = {
|
|
229
|
+
limit: Infinity,
|
|
230
|
+
ellipsis: ""
|
|
231
|
+
}, X$1 = (t, e = {}, s = {}) => {
|
|
232
|
+
const i = e.limit ?? Infinity, r = e.ellipsis ?? "", n = e?.ellipsisWidth ?? (r ? X$1(r, ft$1, s).width : 0), u = s.ansiWidth ?? 0, a = s.controlWidth ?? 0, l = s.tabWidth ?? 8, E = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, m = s.fullWidthWidth ?? 2, A = s.regularWidth ?? 1, V = s.wideWidth ?? 2;
|
|
233
|
+
let h = 0, o = 0, p = t.length, v = 0, F = !1, d = p, b = Math.max(0, i - n), C = 0, w = 0, c = 0, f = 0;
|
|
234
|
+
t: for (;;) {
|
|
235
|
+
if (w > C || o >= p && o > h) {
|
|
236
|
+
const ut = t.slice(C, w) || t.slice(h, o);
|
|
237
|
+
v = 0;
|
|
238
|
+
for (const Y of ut.replaceAll(ct, "")) {
|
|
239
|
+
const $ = Y.codePointAt(0) || 0;
|
|
240
|
+
if (lt($) ? f = m : ht($) ? f = V : E !== A && at($) ? f = E : f = A, c + f > b && (d = Math.min(d, Math.max(C, h) + v)), c + f > i) {
|
|
241
|
+
F = !0;
|
|
242
|
+
break t;
|
|
243
|
+
}
|
|
244
|
+
v += Y.length, c += f;
|
|
245
|
+
}
|
|
246
|
+
C = w = 0;
|
|
247
|
+
}
|
|
248
|
+
if (o >= p) break;
|
|
249
|
+
if (M.lastIndex = o, M.test(t)) {
|
|
250
|
+
if (v = M.lastIndex - o, f = v * A, c + f > b && (d = Math.min(d, o + Math.floor((b - c) / A))), c + f > i) {
|
|
251
|
+
F = !0;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
c += f, C = h, w = o, o = h = M.lastIndex;
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (O.lastIndex = o, O.test(t)) {
|
|
258
|
+
if (c + u > b && (d = Math.min(d, o)), c + u > i) {
|
|
259
|
+
F = !0;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
c += u, C = h, w = o, o = h = O.lastIndex;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (y.lastIndex = o, y.test(t)) {
|
|
266
|
+
if (v = y.lastIndex - o, f = v * a, c + f > b && (d = Math.min(d, o + Math.floor((b - c) / a))), c + f > i) {
|
|
267
|
+
F = !0;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
c += f, C = h, w = o, o = h = y.lastIndex;
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
if (L.lastIndex = o, L.test(t)) {
|
|
274
|
+
if (v = L.lastIndex - o, f = v * l, c + f > b && (d = Math.min(d, o + Math.floor((b - c) / l))), c + f > i) {
|
|
275
|
+
F = !0;
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
c += f, C = h, w = o, o = h = L.lastIndex;
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (P.lastIndex = o, P.test(t)) {
|
|
282
|
+
if (c + g > b && (d = Math.min(d, o)), c + g > i) {
|
|
283
|
+
F = !0;
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
c += g, C = h, w = o, o = h = P.lastIndex;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
o += 1;
|
|
290
|
+
}
|
|
291
|
+
return {
|
|
292
|
+
width: F ? b : c,
|
|
293
|
+
index: F ? d : p,
|
|
294
|
+
truncated: F,
|
|
295
|
+
ellipsed: F && i >= n
|
|
296
|
+
};
|
|
297
|
+
}, pt$1 = {
|
|
298
|
+
limit: Infinity,
|
|
299
|
+
ellipsis: "",
|
|
300
|
+
ellipsisWidth: 0
|
|
301
|
+
}, S = (t, e = {}) => X$1(t, pt$1, e).width, T = "\x1B", Z = "", Ft$1 = 39, j = "\x07", Q$1 = "[", dt = "]", tt = "m", U$1 = `${dt}8;;`, et = new RegExp(`(?:\\${Q$1}(?<code>\\d+)m|\\${U$1}(?<uri>.*)${j})`, "y"), mt$1 = (t) => {
|
|
302
|
+
if (t >= 30 && t <= 37 || t >= 90 && t <= 97) return 39;
|
|
303
|
+
if (t >= 40 && t <= 47 || t >= 100 && t <= 107) return 49;
|
|
304
|
+
if (t === 1 || t === 2) return 22;
|
|
305
|
+
if (t === 3) return 23;
|
|
306
|
+
if (t === 4) return 24;
|
|
307
|
+
if (t === 7) return 27;
|
|
308
|
+
if (t === 8) return 28;
|
|
309
|
+
if (t === 9) return 29;
|
|
310
|
+
if (t === 0) return 0;
|
|
311
|
+
}, st = (t) => `${T}${Q$1}${t}${tt}`, it = (t) => `${T}${U$1}${t}${j}`, gt$1 = (t) => t.map((e) => S(e)), G = (t, e, s) => {
|
|
312
|
+
const i = e[Symbol.iterator]();
|
|
313
|
+
let r = !1, n = !1, u = t.at(-1), a = u === void 0 ? 0 : S(u), l = i.next(), E = i.next(), g = 0;
|
|
314
|
+
for (; !l.done;) {
|
|
315
|
+
const m = l.value, A = S(m);
|
|
316
|
+
a + A <= s ? t[t.length - 1] += m : (t.push(m), a = 0), (m === T || m === Z) && (r = !0, n = e.startsWith(U$1, g + 1)), r ? n ? m === j && (r = !1, n = !1) : m === tt && (r = !1) : (a += A, a === s && !E.done && (t.push(""), a = 0)), l = E, E = i.next(), g += m.length;
|
|
317
|
+
}
|
|
318
|
+
u = t.at(-1), !a && u !== void 0 && u.length > 0 && t.length > 1 && (t[t.length - 2] += t.pop());
|
|
319
|
+
}, vt$1 = (t) => {
|
|
320
|
+
const e = t.split(" ");
|
|
321
|
+
let s = e.length;
|
|
322
|
+
for (; s > 0 && !(S(e[s - 1]) > 0);) s--;
|
|
323
|
+
return s === e.length ? t : e.slice(0, s).join(" ") + e.slice(s).join("");
|
|
324
|
+
}, Et$1 = (t, e, s = {}) => {
|
|
325
|
+
if (s.trim !== !1 && t.trim() === "") return "";
|
|
326
|
+
let i = "", r, n;
|
|
327
|
+
const u = t.split(" "), a = gt$1(u);
|
|
328
|
+
let l = [""];
|
|
329
|
+
for (const [h, o] of u.entries()) {
|
|
330
|
+
s.trim !== !1 && (l[l.length - 1] = (l.at(-1) ?? "").trimStart());
|
|
331
|
+
let p = S(l.at(-1) ?? "");
|
|
332
|
+
if (h !== 0 && (p >= e && (s.wordWrap === !1 || s.trim === !1) && (l.push(""), p = 0), (p > 0 || s.trim === !1) && (l[l.length - 1] += " ", p++)), s.hard && a[h] > e) {
|
|
333
|
+
const v = e - p, F = 1 + Math.floor((a[h] - v - 1) / e);
|
|
334
|
+
Math.floor((a[h] - 1) / e) < F && l.push(""), G(l, o, e);
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if (p + a[h] > e && p > 0 && a[h] > 0) {
|
|
338
|
+
if (s.wordWrap === !1 && p < e) {
|
|
339
|
+
G(l, o, e);
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
l.push("");
|
|
343
|
+
}
|
|
344
|
+
if (p + a[h] > e && s.wordWrap === !1) {
|
|
345
|
+
G(l, o, e);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
l[l.length - 1] += o;
|
|
349
|
+
}
|
|
350
|
+
s.trim !== !1 && (l = l.map((h) => vt$1(h)));
|
|
351
|
+
const E = l.join(`
|
|
352
|
+
`), g = E[Symbol.iterator]();
|
|
353
|
+
let m = g.next(), A = g.next(), V = 0;
|
|
354
|
+
for (; !m.done;) {
|
|
355
|
+
const h = m.value, o = A.value;
|
|
356
|
+
if (i += h, h === T || h === Z) {
|
|
357
|
+
et.lastIndex = V + 1;
|
|
358
|
+
const F = et.exec(E)?.groups;
|
|
359
|
+
if (F?.code !== void 0) {
|
|
360
|
+
const d = Number.parseFloat(F.code);
|
|
361
|
+
r = d === Ft$1 ? void 0 : d;
|
|
362
|
+
} else F?.uri !== void 0 && (n = F.uri.length === 0 ? void 0 : F.uri);
|
|
363
|
+
}
|
|
364
|
+
const p = r ? mt$1(r) : void 0;
|
|
365
|
+
o === `
|
|
366
|
+
` ? (n && (i += it("")), r && p && (i += st(p))) : h === `
|
|
367
|
+
` && (r && p && (i += st(r)), n && (i += it(n))), V += h.length, m = A, A = g.next();
|
|
368
|
+
}
|
|
369
|
+
return i;
|
|
370
|
+
};
|
|
371
|
+
function K$1(t, e, s) {
|
|
372
|
+
return String(t).normalize().replaceAll(`\r
|
|
373
|
+
`, `
|
|
374
|
+
`).split(`
|
|
375
|
+
`).map((i) => Et$1(i, e, s)).join(`
|
|
376
|
+
`);
|
|
377
|
+
}
|
|
378
|
+
const _ = {
|
|
379
|
+
actions: new Set([
|
|
380
|
+
"up",
|
|
381
|
+
"down",
|
|
382
|
+
"left",
|
|
383
|
+
"right",
|
|
384
|
+
"space",
|
|
385
|
+
"enter",
|
|
386
|
+
"cancel"
|
|
387
|
+
]),
|
|
388
|
+
aliases: new Map([
|
|
389
|
+
["k", "up"],
|
|
390
|
+
["j", "down"],
|
|
391
|
+
["h", "left"],
|
|
392
|
+
["l", "right"],
|
|
393
|
+
["", "cancel"],
|
|
394
|
+
["escape", "cancel"]
|
|
395
|
+
]),
|
|
396
|
+
messages: {
|
|
397
|
+
cancel: "Canceled",
|
|
398
|
+
error: "Something went wrong"
|
|
399
|
+
},
|
|
400
|
+
withGuide: !0
|
|
401
|
+
};
|
|
402
|
+
function H$1(t, e) {
|
|
403
|
+
if (typeof t == "string") return _.aliases.get(t) === e;
|
|
404
|
+
for (const s of t) if (s !== void 0 && H$1(s, e)) return !0;
|
|
405
|
+
return !1;
|
|
406
|
+
}
|
|
407
|
+
function _t$1(t, e) {
|
|
408
|
+
if (t === e) return;
|
|
409
|
+
const s = t.split(`
|
|
410
|
+
`), i = e.split(`
|
|
411
|
+
`), r = Math.max(s.length, i.length), n = [];
|
|
412
|
+
for (let u = 0; u < r; u++) s[u] !== i[u] && n.push(u);
|
|
413
|
+
return {
|
|
414
|
+
lines: n,
|
|
415
|
+
numLinesBefore: s.length,
|
|
416
|
+
numLinesAfter: i.length,
|
|
417
|
+
numLines: r
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
globalThis.process.platform.startsWith("win");
|
|
421
|
+
const z$1 = Symbol("clack:cancel");
|
|
422
|
+
function W$1(t, e) {
|
|
423
|
+
const s = t;
|
|
424
|
+
s.isTTY && s.setRawMode(e);
|
|
425
|
+
}
|
|
426
|
+
const rt = (t) => "columns" in t && typeof t.columns == "number" ? t.columns : 80, nt = (t) => "rows" in t && typeof t.rows == "number" ? t.rows : 20;
|
|
427
|
+
function Bt$1(t, e, s, i = s) {
|
|
428
|
+
return K$1(e, rt(t ?? stdout) - s.length, {
|
|
429
|
+
hard: !0,
|
|
430
|
+
trim: !1
|
|
431
|
+
}).split(`
|
|
432
|
+
`).map((n, u) => `${u === 0 ? i : s}${n}`).join(`
|
|
433
|
+
`);
|
|
434
|
+
}
|
|
435
|
+
var B = class {
|
|
436
|
+
input;
|
|
437
|
+
output;
|
|
438
|
+
_abortSignal;
|
|
439
|
+
rl;
|
|
440
|
+
opts;
|
|
441
|
+
_render;
|
|
442
|
+
_track = !1;
|
|
443
|
+
_prevFrame = "";
|
|
444
|
+
_subscribers = /* @__PURE__ */ new Map();
|
|
445
|
+
_cursor = 0;
|
|
446
|
+
state = "initial";
|
|
447
|
+
error = "";
|
|
448
|
+
value;
|
|
449
|
+
userInput = "";
|
|
450
|
+
constructor(e, s = !0) {
|
|
451
|
+
const { input: i = stdin, output: r = stdout, render: n, signal: u, ...a } = e;
|
|
452
|
+
this.opts = a, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = n.bind(this), this._track = s, this._abortSignal = u, this.input = i, this.output = r;
|
|
453
|
+
}
|
|
454
|
+
unsubscribe() {
|
|
455
|
+
this._subscribers.clear();
|
|
456
|
+
}
|
|
457
|
+
setSubscriber(e, s) {
|
|
458
|
+
const i = this._subscribers.get(e) ?? [];
|
|
459
|
+
i.push(s), this._subscribers.set(e, i);
|
|
460
|
+
}
|
|
461
|
+
on(e, s) {
|
|
462
|
+
this.setSubscriber(e, { cb: s });
|
|
463
|
+
}
|
|
464
|
+
once(e, s) {
|
|
465
|
+
this.setSubscriber(e, {
|
|
466
|
+
cb: s,
|
|
467
|
+
once: !0
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
emit(e, ...s) {
|
|
471
|
+
const i = this._subscribers.get(e) ?? [], r = [];
|
|
472
|
+
for (const n of i) n.cb(...s), n.once && r.push(() => i.splice(i.indexOf(n), 1));
|
|
473
|
+
for (const n of r) n();
|
|
474
|
+
}
|
|
475
|
+
prompt() {
|
|
476
|
+
return new Promise((e) => {
|
|
477
|
+
if (this._abortSignal) {
|
|
478
|
+
if (this._abortSignal.aborted) return this.state = "cancel", this.close(), e(z$1);
|
|
479
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
480
|
+
this.state = "cancel", this.close();
|
|
481
|
+
}, { once: !0 });
|
|
482
|
+
}
|
|
483
|
+
this.rl = ot.createInterface({
|
|
484
|
+
input: this.input,
|
|
485
|
+
tabSize: 2,
|
|
486
|
+
prompt: "",
|
|
487
|
+
escapeCodeTimeout: 50,
|
|
488
|
+
terminal: !0
|
|
489
|
+
}), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, !0), this.input.on("keypress", this.onKeypress), W$1(this.input, !0), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
490
|
+
this.output.write(import_src.cursor.show), this.output.off("resize", this.render), W$1(this.input, !1), e(this.value);
|
|
491
|
+
}), this.once("cancel", () => {
|
|
492
|
+
this.output.write(import_src.cursor.show), this.output.off("resize", this.render), W$1(this.input, !1), e(z$1);
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
_isActionKey(e, s) {
|
|
497
|
+
return e === " ";
|
|
498
|
+
}
|
|
499
|
+
_setValue(e) {
|
|
500
|
+
this.value = e, this.emit("value", this.value);
|
|
501
|
+
}
|
|
502
|
+
_setUserInput(e, s) {
|
|
503
|
+
this.userInput = e ?? "", this.emit("userInput", this.userInput), s && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
504
|
+
}
|
|
505
|
+
_clearUserInput() {
|
|
506
|
+
this.rl?.write(null, {
|
|
507
|
+
ctrl: !0,
|
|
508
|
+
name: "u"
|
|
509
|
+
}), this._setUserInput("");
|
|
510
|
+
}
|
|
511
|
+
onKeypress(e, s) {
|
|
512
|
+
if (this._track && s.name !== "return" && (s.name && this._isActionKey(e, s) && this.rl?.write(null, {
|
|
513
|
+
ctrl: !0,
|
|
514
|
+
name: "h"
|
|
515
|
+
}), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), s?.name && (!this._track && _.aliases.has(s.name) && this.emit("cursor", _.aliases.get(s.name)), _.actions.has(s.name) && this.emit("cursor", s.name)), e && (e.toLowerCase() === "y" || e.toLowerCase() === "n") && this.emit("confirm", e.toLowerCase() === "y"), this.emit("key", e?.toLowerCase(), s), s?.name === "return") {
|
|
516
|
+
if (this.opts.validate) {
|
|
517
|
+
const i = this.opts.validate(this.value);
|
|
518
|
+
i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
|
|
519
|
+
}
|
|
520
|
+
this.state !== "error" && (this.state = "submit");
|
|
521
|
+
}
|
|
522
|
+
H$1([
|
|
523
|
+
e,
|
|
524
|
+
s?.name,
|
|
525
|
+
s?.sequence
|
|
526
|
+
], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
527
|
+
}
|
|
528
|
+
close() {
|
|
529
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
530
|
+
`), W$1(this.input, !1), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
531
|
+
}
|
|
532
|
+
restoreCursor() {
|
|
533
|
+
const e = K$1(this._prevFrame, process.stdout.columns, {
|
|
534
|
+
hard: !0,
|
|
535
|
+
trim: !1
|
|
536
|
+
}).split(`
|
|
537
|
+
`).length - 1;
|
|
538
|
+
this.output.write(import_src.cursor.move(-999, e * -1));
|
|
539
|
+
}
|
|
540
|
+
render() {
|
|
541
|
+
const e = K$1(this._render(this) ?? "", process.stdout.columns, {
|
|
542
|
+
hard: !0,
|
|
543
|
+
trim: !1
|
|
544
|
+
});
|
|
545
|
+
if (e !== this._prevFrame) {
|
|
546
|
+
if (this.state === "initial") this.output.write(import_src.cursor.hide);
|
|
547
|
+
else {
|
|
548
|
+
const s = _t$1(this._prevFrame, e), i = nt(this.output);
|
|
549
|
+
if (this.restoreCursor(), s) {
|
|
550
|
+
const r = Math.max(0, s.numLinesAfter - i), n = Math.max(0, s.numLinesBefore - i);
|
|
551
|
+
let u = s.lines.find((a) => a >= r);
|
|
552
|
+
if (u === void 0) {
|
|
553
|
+
this._prevFrame = e;
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
if (s.lines.length === 1) {
|
|
557
|
+
this.output.write(import_src.cursor.move(0, u - n)), this.output.write(import_src.erase.lines(1));
|
|
558
|
+
const a = e.split(`
|
|
559
|
+
`);
|
|
560
|
+
this.output.write(a[u]), this._prevFrame = e, this.output.write(import_src.cursor.move(0, a.length - u - 1));
|
|
561
|
+
return;
|
|
562
|
+
} else if (s.lines.length > 1) {
|
|
563
|
+
if (r < n) u = r;
|
|
564
|
+
else {
|
|
565
|
+
const l = u - n;
|
|
566
|
+
l > 0 && this.output.write(import_src.cursor.move(0, l));
|
|
567
|
+
}
|
|
568
|
+
this.output.write(import_src.erase.down());
|
|
569
|
+
const a = e.split(`
|
|
570
|
+
`).slice(u);
|
|
571
|
+
this.output.write(a.join(`
|
|
572
|
+
`)), this._prevFrame = e;
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
this.output.write(import_src.erase.down());
|
|
577
|
+
}
|
|
578
|
+
this.output.write(e), this.state === "initial" && (this.state = "active"), this._prevFrame = e;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
var Tt$1 = class extends B {
|
|
583
|
+
options;
|
|
584
|
+
cursor = 0;
|
|
585
|
+
get _selectedValue() {
|
|
586
|
+
return this.options[this.cursor];
|
|
587
|
+
}
|
|
588
|
+
changeValue() {
|
|
589
|
+
this.value = this._selectedValue.value;
|
|
590
|
+
}
|
|
591
|
+
constructor(e) {
|
|
592
|
+
super(e, !1), this.options = e.options;
|
|
593
|
+
const s = this.options.findIndex(({ value: r }) => r === e.initialValue), i = s === -1 ? 0 : s;
|
|
594
|
+
this.cursor = this.options[i].disabled ? x$1(i, 1, this.options) : i, this.changeValue(), this.on("cursor", (r) => {
|
|
595
|
+
switch (r) {
|
|
596
|
+
case "left":
|
|
597
|
+
case "up":
|
|
598
|
+
this.cursor = x$1(this.cursor, -1, this.options);
|
|
599
|
+
break;
|
|
600
|
+
case "down":
|
|
601
|
+
case "right":
|
|
602
|
+
this.cursor = x$1(this.cursor, 1, this.options);
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
this.changeValue();
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
//#endregion
|
|
610
|
+
//#region ../../node_modules/.pnpm/@clack+prompts@1.1.0/node_modules/@clack/prompts/dist/index.mjs
|
|
611
|
+
function pt() {
|
|
612
|
+
return process$1.platform !== "win32" ? process$1.env.TERM !== "linux" : !!process$1.env.CI || !!process$1.env.WT_SESSION || !!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";
|
|
613
|
+
}
|
|
614
|
+
const ee = pt(), I = (e, r) => ee ? e : r, Re = I("◆", "*"), $e = I("■", "x"), de = I("▲", "x"), V = I("◇", "o");
|
|
615
|
+
I("┌", "T");
|
|
616
|
+
const h = I("│", "|"), x = I("└", "—");
|
|
617
|
+
I("┐", "T");
|
|
618
|
+
I("┘", "—");
|
|
619
|
+
const z = I("●", ">"), H = I("○", " ");
|
|
620
|
+
I("◻", "[•]");
|
|
621
|
+
I("◼", "[+]");
|
|
622
|
+
I("◻", "[ ]");
|
|
623
|
+
I("▪", "•");
|
|
624
|
+
I("─", "-");
|
|
625
|
+
I("╮", "+");
|
|
626
|
+
I("├", "+");
|
|
627
|
+
I("╯", "+");
|
|
628
|
+
I("╰", "+");
|
|
629
|
+
I("╭", "+");
|
|
630
|
+
const fe = I("●", "•"), Fe = I("◆", "*"), ye = I("▲", "!"), Ee = I("■", "x"), W = (e) => {
|
|
631
|
+
switch (e) {
|
|
632
|
+
case "initial":
|
|
633
|
+
case "active": return styleText("cyan", Re);
|
|
634
|
+
case "cancel": return styleText("red", $e);
|
|
635
|
+
case "error": return styleText("yellow", de);
|
|
636
|
+
case "submit": return styleText("green", V);
|
|
637
|
+
}
|
|
638
|
+
}, ve = (e) => {
|
|
639
|
+
switch (e) {
|
|
640
|
+
case "initial":
|
|
641
|
+
case "active": return styleText("cyan", h);
|
|
642
|
+
case "cancel": return styleText("red", h);
|
|
643
|
+
case "error": return styleText("yellow", h);
|
|
644
|
+
case "submit": return styleText("green", h);
|
|
645
|
+
}
|
|
646
|
+
}, mt = (e) => e === 161 || e === 164 || e === 167 || e === 168 || e === 170 || e === 173 || e === 174 || e >= 176 && e <= 180 || e >= 182 && e <= 186 || e >= 188 && e <= 191 || e === 198 || e === 208 || e === 215 || e === 216 || e >= 222 && e <= 225 || e === 230 || e >= 232 && e <= 234 || e === 236 || e === 237 || e === 240 || e === 242 || e === 243 || e >= 247 && e <= 250 || e === 252 || e === 254 || e === 257 || e === 273 || e === 275 || e === 283 || e === 294 || e === 295 || e === 299 || e >= 305 && e <= 307 || e === 312 || e >= 319 && e <= 322 || e === 324 || e >= 328 && e <= 331 || e === 333 || e === 338 || e === 339 || e === 358 || e === 359 || e === 363 || e === 462 || e === 464 || e === 466 || e === 468 || e === 470 || e === 472 || e === 474 || e === 476 || e === 593 || e === 609 || e === 708 || e === 711 || e >= 713 && e <= 715 || e === 717 || e === 720 || e >= 728 && e <= 731 || e === 733 || e === 735 || e >= 768 && e <= 879 || e >= 913 && e <= 929 || e >= 931 && e <= 937 || e >= 945 && e <= 961 || e >= 963 && e <= 969 || e === 1025 || e >= 1040 && e <= 1103 || e === 1105 || e === 8208 || e >= 8211 && e <= 8214 || e === 8216 || e === 8217 || e === 8220 || e === 8221 || e >= 8224 && e <= 8226 || e >= 8228 && e <= 8231 || e === 8240 || e === 8242 || e === 8243 || e === 8245 || e === 8251 || e === 8254 || e === 8308 || e === 8319 || e >= 8321 && e <= 8324 || e === 8364 || e === 8451 || e === 8453 || e === 8457 || e === 8467 || e === 8470 || e === 8481 || e === 8482 || e === 8486 || e === 8491 || e === 8531 || e === 8532 || e >= 8539 && e <= 8542 || e >= 8544 && e <= 8555 || e >= 8560 && e <= 8569 || e === 8585 || e >= 8592 && e <= 8601 || e === 8632 || e === 8633 || e === 8658 || e === 8660 || e === 8679 || e === 8704 || e === 8706 || e === 8707 || e === 8711 || e === 8712 || e === 8715 || e === 8719 || e === 8721 || e === 8725 || e === 8730 || e >= 8733 && e <= 8736 || e === 8739 || e === 8741 || e >= 8743 && e <= 8748 || e === 8750 || e >= 8756 && e <= 8759 || e === 8764 || e === 8765 || e === 8776 || e === 8780 || e === 8786 || e === 8800 || e === 8801 || e >= 8804 && e <= 8807 || e === 8810 || e === 8811 || e === 8814 || e === 8815 || e === 8834 || e === 8835 || e === 8838 || e === 8839 || e === 8853 || e === 8857 || e === 8869 || e === 8895 || e === 8978 || e >= 9312 && e <= 9449 || e >= 9451 && e <= 9547 || e >= 9552 && e <= 9587 || e >= 9600 && e <= 9615 || e >= 9618 && e <= 9621 || e === 9632 || e === 9633 || e >= 9635 && e <= 9641 || e === 9650 || e === 9651 || e === 9654 || e === 9655 || e === 9660 || e === 9661 || e === 9664 || e === 9665 || e >= 9670 && e <= 9672 || e === 9675 || e >= 9678 && e <= 9681 || e >= 9698 && e <= 9701 || e === 9711 || e === 9733 || e === 9734 || e === 9737 || e === 9742 || e === 9743 || e === 9756 || e === 9758 || e === 9792 || e === 9794 || e === 9824 || e === 9825 || e >= 9827 && e <= 9829 || e >= 9831 && e <= 9834 || e === 9836 || e === 9837 || e === 9839 || e === 9886 || e === 9887 || e === 9919 || e >= 9926 && e <= 9933 || e >= 9935 && e <= 9939 || e >= 9941 && e <= 9953 || e === 9955 || e === 9960 || e === 9961 || e >= 9963 && e <= 9969 || e === 9972 || e >= 9974 && e <= 9977 || e === 9979 || e === 9980 || e === 9982 || e === 9983 || e === 10045 || e >= 10102 && e <= 10111 || e >= 11094 && e <= 11097 || e >= 12872 && e <= 12879 || e >= 57344 && e <= 63743 || e >= 65024 && e <= 65039 || e === 65533 || e >= 127232 && e <= 127242 || e >= 127248 && e <= 127277 || e >= 127280 && e <= 127337 || e >= 127344 && e <= 127373 || e === 127375 || e === 127376 || e >= 127387 && e <= 127404 || e >= 917760 && e <= 917999 || e >= 983040 && e <= 1048573 || e >= 1048576 && e <= 1114109, gt = (e) => e === 12288 || e >= 65281 && e <= 65376 || e >= 65504 && e <= 65510, ft = (e) => e >= 4352 && e <= 4447 || e === 8986 || e === 8987 || e === 9001 || e === 9002 || e >= 9193 && e <= 9196 || e === 9200 || e === 9203 || e === 9725 || e === 9726 || e === 9748 || e === 9749 || e >= 9800 && e <= 9811 || e === 9855 || e === 9875 || e === 9889 || e === 9898 || e === 9899 || e === 9917 || e === 9918 || e === 9924 || e === 9925 || e === 9934 || e === 9940 || e === 9962 || e === 9970 || e === 9971 || e === 9973 || e === 9978 || e === 9981 || e === 9989 || e === 9994 || e === 9995 || e === 10024 || e === 10060 || e === 10062 || e >= 10067 && e <= 10069 || e === 10071 || e >= 10133 && e <= 10135 || e === 10160 || e === 10175 || e === 11035 || e === 11036 || e === 11088 || e === 11093 || e >= 11904 && e <= 11929 || e >= 11931 && e <= 12019 || e >= 12032 && e <= 12245 || e >= 12272 && e <= 12287 || e >= 12289 && e <= 12350 || e >= 12353 && e <= 12438 || e >= 12441 && e <= 12543 || e >= 12549 && e <= 12591 || e >= 12593 && e <= 12686 || e >= 12688 && e <= 12771 || e >= 12783 && e <= 12830 || e >= 12832 && e <= 12871 || e >= 12880 && e <= 19903 || e >= 19968 && e <= 42124 || e >= 42128 && e <= 42182 || e >= 43360 && e <= 43388 || e >= 44032 && e <= 55203 || e >= 63744 && e <= 64255 || e >= 65040 && e <= 65049 || e >= 65072 && e <= 65106 || e >= 65108 && e <= 65126 || e >= 65128 && e <= 65131 || e >= 94176 && e <= 94180 || e === 94192 || e === 94193 || e >= 94208 && e <= 100343 || e >= 100352 && e <= 101589 || e >= 101632 && e <= 101640 || e >= 110576 && e <= 110579 || e >= 110581 && e <= 110587 || e === 110589 || e === 110590 || e >= 110592 && e <= 110882 || e === 110898 || e >= 110928 && e <= 110930 || e === 110933 || e >= 110948 && e <= 110951 || e >= 110960 && e <= 111355 || e === 126980 || e === 127183 || e === 127374 || e >= 127377 && e <= 127386 || e >= 127488 && e <= 127490 || e >= 127504 && e <= 127547 || e >= 127552 && e <= 127560 || e === 127568 || e === 127569 || e >= 127584 && e <= 127589 || e >= 127744 && e <= 127776 || e >= 127789 && e <= 127797 || e >= 127799 && e <= 127868 || e >= 127870 && e <= 127891 || e >= 127904 && e <= 127946 || e >= 127951 && e <= 127955 || e >= 127968 && e <= 127984 || e === 127988 || e >= 127992 && e <= 128062 || e === 128064 || e >= 128066 && e <= 128252 || e >= 128255 && e <= 128317 || e >= 128331 && e <= 128334 || e >= 128336 && e <= 128359 || e === 128378 || e === 128405 || e === 128406 || e === 128420 || e >= 128507 && e <= 128591 || e >= 128640 && e <= 128709 || e === 128716 || e >= 128720 && e <= 128722 || e >= 128725 && e <= 128727 || e >= 128732 && e <= 128735 || e === 128747 || e === 128748 || e >= 128756 && e <= 128764 || e >= 128992 && e <= 129003 || e === 129008 || e >= 129292 && e <= 129338 || e >= 129340 && e <= 129349 || e >= 129351 && e <= 129535 || e >= 129648 && e <= 129660 || e >= 129664 && e <= 129672 || e >= 129680 && e <= 129725 || e >= 129727 && e <= 129733 || e >= 129742 && e <= 129755 || e >= 129760 && e <= 129768 || e >= 129776 && e <= 129784 || e >= 131072 && e <= 196605 || e >= 196608 && e <= 262141, we = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y, re = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y, ie = /\t{1,1000}/y, Ae = /[\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, ne = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y, Ft = /\p{M}+/gu, yt = {
|
|
647
|
+
limit: Infinity,
|
|
648
|
+
ellipsis: ""
|
|
649
|
+
}, Le = (e, r = {}, s = {}) => {
|
|
650
|
+
const i = r.limit ?? Infinity, a = r.ellipsis ?? "", o = r?.ellipsisWidth ?? (a ? Le(a, yt, s).width : 0), u = s.ansiWidth ?? 0, l = s.controlWidth ?? 0, n = s.tabWidth ?? 8, c = s.ambiguousWidth ?? 1, p = s.emojiWidth ?? 2, f = s.fullWidthWidth ?? 2, g = s.regularWidth ?? 1, E = s.wideWidth ?? 2;
|
|
651
|
+
let $ = 0, m = 0, d = e.length, F = 0, y = !1, v = d, C = Math.max(0, i - o), A = 0, b = 0, w = 0, S = 0;
|
|
652
|
+
e: for (;;) {
|
|
653
|
+
if (b > A || m >= d && m > $) {
|
|
654
|
+
const T = e.slice(A, b) || e.slice($, m);
|
|
655
|
+
F = 0;
|
|
656
|
+
for (const M of T.replaceAll(Ft, "")) {
|
|
657
|
+
const O = M.codePointAt(0) || 0;
|
|
658
|
+
if (gt(O) ? S = f : ft(O) ? S = E : c !== g && mt(O) ? S = c : S = g, w + S > C && (v = Math.min(v, Math.max(A, $) + F)), w + S > i) {
|
|
659
|
+
y = !0;
|
|
660
|
+
break e;
|
|
661
|
+
}
|
|
662
|
+
F += M.length, w += S;
|
|
663
|
+
}
|
|
664
|
+
A = b = 0;
|
|
665
|
+
}
|
|
666
|
+
if (m >= d) break;
|
|
667
|
+
if (ne.lastIndex = m, ne.test(e)) {
|
|
668
|
+
if (F = ne.lastIndex - m, S = F * g, w + S > C && (v = Math.min(v, m + Math.floor((C - w) / g))), w + S > i) {
|
|
669
|
+
y = !0;
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
w += S, A = $, b = m, m = $ = ne.lastIndex;
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
if (we.lastIndex = m, we.test(e)) {
|
|
676
|
+
if (w + u > C && (v = Math.min(v, m)), w + u > i) {
|
|
677
|
+
y = !0;
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
w += u, A = $, b = m, m = $ = we.lastIndex;
|
|
681
|
+
continue;
|
|
682
|
+
}
|
|
683
|
+
if (re.lastIndex = m, re.test(e)) {
|
|
684
|
+
if (F = re.lastIndex - m, S = F * l, w + S > C && (v = Math.min(v, m + Math.floor((C - w) / l))), w + S > i) {
|
|
685
|
+
y = !0;
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
w += S, A = $, b = m, m = $ = re.lastIndex;
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
if (ie.lastIndex = m, ie.test(e)) {
|
|
692
|
+
if (F = ie.lastIndex - m, S = F * n, w + S > C && (v = Math.min(v, m + Math.floor((C - w) / n))), w + S > i) {
|
|
693
|
+
y = !0;
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
w += S, A = $, b = m, m = $ = ie.lastIndex;
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
if (Ae.lastIndex = m, Ae.test(e)) {
|
|
700
|
+
if (w + p > C && (v = Math.min(v, m)), w + p > i) {
|
|
701
|
+
y = !0;
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
w += p, A = $, b = m, m = $ = Ae.lastIndex;
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
m += 1;
|
|
708
|
+
}
|
|
709
|
+
return {
|
|
710
|
+
width: y ? C : w,
|
|
711
|
+
index: y ? v : d,
|
|
712
|
+
truncated: y,
|
|
713
|
+
ellipsed: y && i >= o
|
|
714
|
+
};
|
|
715
|
+
}, Et = {
|
|
716
|
+
limit: Infinity,
|
|
717
|
+
ellipsis: "",
|
|
718
|
+
ellipsisWidth: 0
|
|
719
|
+
}, D = (e, r = {}) => Le(e, Et, r).width, ae = "\x1B", je = "", vt = 39, Ce = "\x07", ke = "[", wt = "]", Ve = "m", Se = `${wt}8;;`, He = new RegExp(`(?:\\${ke}(?<code>\\d+)m|\\${Se}(?<uri>.*)${Ce})`, "y"), At = (e) => {
|
|
720
|
+
if (e >= 30 && e <= 37 || e >= 90 && e <= 97) return 39;
|
|
721
|
+
if (e >= 40 && e <= 47 || e >= 100 && e <= 107) return 49;
|
|
722
|
+
if (e === 1 || e === 2) return 22;
|
|
723
|
+
if (e === 3) return 23;
|
|
724
|
+
if (e === 4) return 24;
|
|
725
|
+
if (e === 7) return 27;
|
|
726
|
+
if (e === 8) return 28;
|
|
727
|
+
if (e === 9) return 29;
|
|
728
|
+
if (e === 0) return 0;
|
|
729
|
+
}, Ue = (e) => `${ae}${ke}${e}${Ve}`, Ke = (e) => `${ae}${Se}${e}${Ce}`, Ct = (e) => e.map((r) => D(r)), Ie = (e, r, s) => {
|
|
730
|
+
const i = r[Symbol.iterator]();
|
|
731
|
+
let a = !1, o = !1, u = e.at(-1), l = u === void 0 ? 0 : D(u), n = i.next(), c = i.next(), p = 0;
|
|
732
|
+
for (; !n.done;) {
|
|
733
|
+
const f = n.value, g = D(f);
|
|
734
|
+
l + g <= s ? e[e.length - 1] += f : (e.push(f), l = 0), (f === ae || f === je) && (a = !0, o = r.startsWith(Se, p + 1)), a ? o ? f === Ce && (a = !1, o = !1) : f === Ve && (a = !1) : (l += g, l === s && !c.done && (e.push(""), l = 0)), n = c, c = i.next(), p += f.length;
|
|
735
|
+
}
|
|
736
|
+
u = e.at(-1), !l && u !== void 0 && u.length > 0 && e.length > 1 && (e[e.length - 2] += e.pop());
|
|
737
|
+
}, St = (e) => {
|
|
738
|
+
const r = e.split(" ");
|
|
739
|
+
let s = r.length;
|
|
740
|
+
for (; s > 0 && !(D(r[s - 1]) > 0);) s--;
|
|
741
|
+
return s === r.length ? e : r.slice(0, s).join(" ") + r.slice(s).join("");
|
|
742
|
+
}, It = (e, r, s = {}) => {
|
|
743
|
+
if (s.trim !== !1 && e.trim() === "") return "";
|
|
744
|
+
let i = "", a, o;
|
|
745
|
+
const u = e.split(" "), l = Ct(u);
|
|
746
|
+
let n = [""];
|
|
747
|
+
for (const [$, m] of u.entries()) {
|
|
748
|
+
s.trim !== !1 && (n[n.length - 1] = (n.at(-1) ?? "").trimStart());
|
|
749
|
+
let d = D(n.at(-1) ?? "");
|
|
750
|
+
if ($ !== 0 && (d >= r && (s.wordWrap === !1 || s.trim === !1) && (n.push(""), d = 0), (d > 0 || s.trim === !1) && (n[n.length - 1] += " ", d++)), s.hard && l[$] > r) {
|
|
751
|
+
const F = r - d, y = 1 + Math.floor((l[$] - F - 1) / r);
|
|
752
|
+
Math.floor((l[$] - 1) / r) < y && n.push(""), Ie(n, m, r);
|
|
753
|
+
continue;
|
|
754
|
+
}
|
|
755
|
+
if (d + l[$] > r && d > 0 && l[$] > 0) {
|
|
756
|
+
if (s.wordWrap === !1 && d < r) {
|
|
757
|
+
Ie(n, m, r);
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
n.push("");
|
|
761
|
+
}
|
|
762
|
+
if (d + l[$] > r && s.wordWrap === !1) {
|
|
763
|
+
Ie(n, m, r);
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
n[n.length - 1] += m;
|
|
767
|
+
}
|
|
768
|
+
s.trim !== !1 && (n = n.map(($) => St($)));
|
|
769
|
+
const c = n.join(`
|
|
770
|
+
`), p = c[Symbol.iterator]();
|
|
771
|
+
let f = p.next(), g = p.next(), E = 0;
|
|
772
|
+
for (; !f.done;) {
|
|
773
|
+
const $ = f.value, m = g.value;
|
|
774
|
+
if (i += $, $ === ae || $ === je) {
|
|
775
|
+
He.lastIndex = E + 1;
|
|
776
|
+
const y = He.exec(c)?.groups;
|
|
777
|
+
if (y?.code !== void 0) {
|
|
778
|
+
const v = Number.parseFloat(y.code);
|
|
779
|
+
a = v === vt ? void 0 : v;
|
|
780
|
+
} else y?.uri !== void 0 && (o = y.uri.length === 0 ? void 0 : y.uri);
|
|
781
|
+
}
|
|
782
|
+
const d = a ? At(a) : void 0;
|
|
783
|
+
m === `
|
|
784
|
+
` ? (o && (i += Ke("")), a && d && (i += Ue(d))) : $ === `
|
|
785
|
+
` && (a && d && (i += Ue(a)), o && (i += Ke(o))), E += $.length, f = g, g = p.next();
|
|
786
|
+
}
|
|
787
|
+
return i;
|
|
788
|
+
};
|
|
789
|
+
function J(e, r, s) {
|
|
790
|
+
return String(e).normalize().replaceAll(`\r
|
|
791
|
+
`, `
|
|
792
|
+
`).split(`
|
|
793
|
+
`).map((i) => It(i, r, s)).join(`
|
|
794
|
+
`);
|
|
795
|
+
}
|
|
796
|
+
const bt = (e, r, s, i, a) => {
|
|
797
|
+
let o = r, u = 0;
|
|
798
|
+
for (let l = s; l < i; l++) {
|
|
799
|
+
const n = e[l];
|
|
800
|
+
if (o = o - n.length, u++, o <= a) break;
|
|
801
|
+
}
|
|
802
|
+
return {
|
|
803
|
+
lineCount: o,
|
|
804
|
+
removals: u
|
|
805
|
+
};
|
|
806
|
+
}, X = ({ cursor: e, options: r, style: s, output: i = process.stdout, maxItems: a = Number.POSITIVE_INFINITY, columnPadding: o = 0, rowPadding: u = 4 }) => {
|
|
807
|
+
const l = rt(i) - o, n = nt(i), c = styleText("dim", "..."), p = Math.max(n - u, 0), f = Math.max(Math.min(a, p), 5);
|
|
808
|
+
let g = 0;
|
|
809
|
+
e >= f - 3 && (g = Math.max(Math.min(e - f + 3, r.length - f), 0));
|
|
810
|
+
let E = f < r.length && g > 0, $ = f < r.length && g + f < r.length;
|
|
811
|
+
const m = Math.min(g + f, r.length), d = [];
|
|
812
|
+
let F = 0;
|
|
813
|
+
E && F++, $ && F++;
|
|
814
|
+
const y = g + (E ? 1 : 0), v = m - ($ ? 1 : 0);
|
|
815
|
+
for (let A = y; A < v; A++) {
|
|
816
|
+
const b = J(s(r[A], A === e), l, {
|
|
817
|
+
hard: !0,
|
|
818
|
+
trim: !1
|
|
819
|
+
}).split(`
|
|
820
|
+
`);
|
|
821
|
+
d.push(b), F += b.length;
|
|
822
|
+
}
|
|
823
|
+
if (F > p) {
|
|
824
|
+
let A = 0, b = 0, w = F;
|
|
825
|
+
const S = e - y, T = (M, O) => bt(d, w, M, O, p);
|
|
826
|
+
E ? ({lineCount: w, removals: A} = T(0, S), w > p && ({lineCount: w, removals: b} = T(S + 1, d.length))) : ({lineCount: w, removals: b} = T(S + 1, d.length), w > p && ({lineCount: w, removals: A} = T(0, S))), A > 0 && (E = !0, d.splice(0, A)), b > 0 && ($ = !0, d.splice(d.length - b, b));
|
|
827
|
+
}
|
|
828
|
+
const C = [];
|
|
829
|
+
E && C.push(c);
|
|
830
|
+
for (const A of d) for (const b of A) C.push(b);
|
|
831
|
+
return $ && C.push(c), C;
|
|
832
|
+
}, R = {
|
|
833
|
+
message: (e = [], { symbol: r = styleText("gray", h), secondarySymbol: s = styleText("gray", h), output: i = process.stdout, spacing: a = 1, withGuide: o } = {}) => {
|
|
834
|
+
const u = [], l = o ?? _.withGuide, n = l ? s : "", c = l ? `${r} ` : "", p = l ? `${s} ` : "";
|
|
835
|
+
for (let g = 0; g < a; g++) u.push(n);
|
|
836
|
+
const f = Array.isArray(e) ? e : e.split(`
|
|
837
|
+
`);
|
|
838
|
+
if (f.length > 0) {
|
|
839
|
+
const [g, ...E] = f;
|
|
840
|
+
g.length > 0 ? u.push(`${c}${g}`) : u.push(l ? r : "");
|
|
841
|
+
for (const $ of E) $.length > 0 ? u.push(`${p}${$}`) : u.push(l ? s : "");
|
|
842
|
+
}
|
|
843
|
+
i.write(`${u.join(`
|
|
844
|
+
`)}
|
|
845
|
+
`);
|
|
846
|
+
},
|
|
847
|
+
info: (e, r) => {
|
|
848
|
+
R.message(e, {
|
|
849
|
+
...r,
|
|
850
|
+
symbol: styleText("blue", fe)
|
|
851
|
+
});
|
|
852
|
+
},
|
|
853
|
+
success: (e, r) => {
|
|
854
|
+
R.message(e, {
|
|
855
|
+
...r,
|
|
856
|
+
symbol: styleText("green", Fe)
|
|
857
|
+
});
|
|
858
|
+
},
|
|
859
|
+
step: (e, r) => {
|
|
860
|
+
R.message(e, {
|
|
861
|
+
...r,
|
|
862
|
+
symbol: styleText("green", V)
|
|
863
|
+
});
|
|
864
|
+
},
|
|
865
|
+
warn: (e, r) => {
|
|
866
|
+
R.message(e, {
|
|
867
|
+
...r,
|
|
868
|
+
symbol: styleText("yellow", ye)
|
|
869
|
+
});
|
|
870
|
+
},
|
|
871
|
+
warning: (e, r) => {
|
|
872
|
+
R.warn(e, r);
|
|
873
|
+
},
|
|
874
|
+
error: (e, r) => {
|
|
875
|
+
R.message(e, {
|
|
876
|
+
...r,
|
|
877
|
+
symbol: styleText("red", Ee)
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
I("─", "-"), I("━", "="), I("█", "#");
|
|
882
|
+
const oe = (e, r) => e.includes(`
|
|
883
|
+
`) ? e.split(`
|
|
884
|
+
`).map((s) => r(s)).join(`
|
|
885
|
+
`) : r(e), Jt = (e) => {
|
|
886
|
+
const r = (s, i) => {
|
|
887
|
+
const a = s.label ?? String(s.value);
|
|
888
|
+
switch (i) {
|
|
889
|
+
case "disabled": return `${styleText("gray", H)} ${oe(a, (o) => styleText("gray", o))}${s.hint ? ` ${styleText("dim", `(${s.hint ?? "disabled"})`)}` : ""}`;
|
|
890
|
+
case "selected": return `${oe(a, (o) => styleText("dim", o))}`;
|
|
891
|
+
case "active": return `${styleText("green", z)} ${a}${s.hint ? ` ${styleText("dim", `(${s.hint})`)}` : ""}`;
|
|
892
|
+
case "cancelled": return `${oe(a, (o) => styleText(["strikethrough", "dim"], o))}`;
|
|
893
|
+
default: return `${styleText("dim", H)} ${oe(a, (o) => styleText("dim", o))}`;
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
return new Tt$1({
|
|
897
|
+
options: e.options,
|
|
898
|
+
signal: e.signal,
|
|
899
|
+
input: e.input,
|
|
900
|
+
output: e.output,
|
|
901
|
+
initialValue: e.initialValue,
|
|
902
|
+
render() {
|
|
903
|
+
const s = e.withGuide ?? _.withGuide, i = `${W(this.state)} `, a = `${ve(this.state)} `, o = Bt$1(e.output, e.message, a, i), u = `${s ? `${styleText("gray", h)}
|
|
904
|
+
` : ""}${o}
|
|
905
|
+
`;
|
|
906
|
+
switch (this.state) {
|
|
907
|
+
case "submit": {
|
|
908
|
+
const l = s ? `${styleText("gray", h)} ` : "";
|
|
909
|
+
return `${u}${Bt$1(e.output, r(this.options[this.cursor], "selected"), l)}`;
|
|
910
|
+
}
|
|
911
|
+
case "cancel": {
|
|
912
|
+
const l = s ? `${styleText("gray", h)} ` : "";
|
|
913
|
+
return `${u}${Bt$1(e.output, r(this.options[this.cursor], "cancelled"), l)}${s ? `
|
|
914
|
+
${styleText("gray", h)}` : ""}`;
|
|
915
|
+
}
|
|
916
|
+
default: {
|
|
917
|
+
const l = s ? `${styleText("cyan", h)} ` : "", n = s ? styleText("cyan", x) : "", c = u.split(`
|
|
918
|
+
`).length, p = s ? 2 : 1;
|
|
919
|
+
return `${u}${l}${X({
|
|
920
|
+
output: e.output,
|
|
921
|
+
cursor: this.cursor,
|
|
922
|
+
options: this.options,
|
|
923
|
+
maxItems: e.maxItems,
|
|
924
|
+
columnPadding: l.length,
|
|
925
|
+
rowPadding: c + p,
|
|
926
|
+
style: (f, g) => r(f, f.disabled ? "disabled" : g ? "active" : "inactive")
|
|
927
|
+
}).join(`
|
|
928
|
+
${l}`)}
|
|
929
|
+
${n}
|
|
930
|
+
`;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
}).prompt();
|
|
935
|
+
}, Qe = `${styleText("gray", h)} `, K = {
|
|
936
|
+
message: async (e, { symbol: r = styleText("gray", h) } = {}) => {
|
|
937
|
+
process.stdout.write(`${styleText("gray", h)}
|
|
938
|
+
${r} `);
|
|
939
|
+
let s = 3;
|
|
940
|
+
for await (let i of e) {
|
|
941
|
+
i = i.replace(/\n/g, `
|
|
942
|
+
${Qe}`), i.includes(`
|
|
943
|
+
`) && (s = 3 + stripVTControlCharacters(i.slice(i.lastIndexOf(`
|
|
944
|
+
`))).length);
|
|
945
|
+
const a = stripVTControlCharacters(i).length;
|
|
946
|
+
s + a < process.stdout.columns ? (s += a, process.stdout.write(i)) : (process.stdout.write(`
|
|
947
|
+
${Qe}${i.trimStart()}`), s = 3 + stripVTControlCharacters(i.trimStart()).length);
|
|
948
|
+
}
|
|
949
|
+
process.stdout.write(`
|
|
950
|
+
`);
|
|
951
|
+
},
|
|
952
|
+
info: (e) => K.message(e, { symbol: styleText("blue", fe) }),
|
|
953
|
+
success: (e) => K.message(e, { symbol: styleText("green", Fe) }),
|
|
954
|
+
step: (e) => K.message(e, { symbol: styleText("green", V) }),
|
|
955
|
+
warn: (e) => K.message(e, { symbol: styleText("yellow", ye) }),
|
|
956
|
+
warning: (e) => K.warn(e),
|
|
957
|
+
error: (e) => K.message(e, { symbol: styleText("red", Ee) })
|
|
958
|
+
};
|
|
959
|
+
//#endregion
|
|
960
|
+
//#region src/commands/key.ts
|
|
961
|
+
async function keyAdd(key) {
|
|
962
|
+
try {
|
|
963
|
+
if (!await validateKey(key)) {
|
|
964
|
+
console.error(kleur.red("✗ Invalid API key. Please check your key and try again."));
|
|
965
|
+
process$1.exit(1);
|
|
966
|
+
}
|
|
967
|
+
const config = readConfig();
|
|
968
|
+
if (config.keys.find((k) => k.key === key)) {
|
|
969
|
+
console.warn(kleur.yellow(`⚠ API key ${maskKey(key)} already exists in config.`));
|
|
970
|
+
process$1.exit(0);
|
|
971
|
+
}
|
|
972
|
+
config.keys.push({
|
|
973
|
+
key,
|
|
974
|
+
valid: true,
|
|
975
|
+
lastCheck: (/* @__PURE__ */ new Date()).toISOString()
|
|
976
|
+
});
|
|
977
|
+
writeConfig(config);
|
|
978
|
+
console.log(kleur.green(`✓ API key ${maskKey(key)} added successfully.`));
|
|
979
|
+
} catch (error) {
|
|
980
|
+
if (error.message?.includes("credentials") || error.message?.includes("Unauthorized")) {
|
|
981
|
+
console.error(kleur.red("✗ Invalid API key. Please check your key and try again."));
|
|
982
|
+
process$1.exit(1);
|
|
983
|
+
}
|
|
984
|
+
console.error(kleur.red(`✗ Error validating key: ${error.message}`));
|
|
985
|
+
process$1.exit(1);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
async function keyRemove(key) {
|
|
989
|
+
try {
|
|
990
|
+
const config = readConfig();
|
|
991
|
+
if (config.keys.length === 0) {
|
|
992
|
+
console.warn(kleur.yellow("⚠ No API keys configured. Use \"tinyimg key add <key>\" to add one."));
|
|
993
|
+
process$1.exit(0);
|
|
994
|
+
}
|
|
995
|
+
let keyToRemove;
|
|
996
|
+
if (!key) {
|
|
997
|
+
const selected = await Jt({
|
|
998
|
+
message: "Select API key to remove:",
|
|
999
|
+
options: config.keys.map((k) => ({
|
|
1000
|
+
value: k.key,
|
|
1001
|
+
label: `${maskKey(k.key)} ${k.valid ? "(valid)" : "(invalid)"}`
|
|
1002
|
+
}))
|
|
1003
|
+
});
|
|
1004
|
+
if (typeof selected !== "string") {
|
|
1005
|
+
console.log(kleur.yellow("Operation cancelled."));
|
|
1006
|
+
process$1.exit(0);
|
|
1007
|
+
}
|
|
1008
|
+
keyToRemove = selected;
|
|
1009
|
+
} else keyToRemove = key;
|
|
1010
|
+
const keyIndex = config.keys.findIndex((k) => k.key === keyToRemove);
|
|
1011
|
+
if (keyIndex === -1) {
|
|
1012
|
+
console.error(kleur.red(`✗ API key ${maskKey(keyToRemove)} not found.`));
|
|
1013
|
+
process$1.exit(1);
|
|
1014
|
+
}
|
|
1015
|
+
const removedKey = config.keys.splice(keyIndex, 1)[0];
|
|
1016
|
+
writeConfig(config);
|
|
1017
|
+
console.log(kleur.green(`✓ API key ${maskKey(removedKey.key)} removed successfully.`));
|
|
1018
|
+
} catch (error) {
|
|
1019
|
+
console.error(kleur.red(`✗ Error removing key: ${error.message}`));
|
|
1020
|
+
process$1.exit(1);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
async function keyList() {
|
|
1024
|
+
try {
|
|
1025
|
+
const config = readConfig();
|
|
1026
|
+
if (config.keys.length === 0) {
|
|
1027
|
+
console.log(kleur.yellow("⚠ No API keys configured."));
|
|
1028
|
+
console.log(kleur.gray("Use \"tinyimg key add <key>\" to add one."));
|
|
1029
|
+
process$1.exit(0);
|
|
1030
|
+
}
|
|
1031
|
+
console.log(kleur.bold("\nAPI Keys:\n"));
|
|
1032
|
+
for (const keyMeta of config.keys) {
|
|
1033
|
+
const masked = maskKey(keyMeta.key);
|
|
1034
|
+
const status = keyMeta.valid ? kleur.green("✓ Valid") : kleur.red("✗ Invalid");
|
|
1035
|
+
const lastCheck = new Date(keyMeta.lastCheck).toLocaleString();
|
|
1036
|
+
console.log(` ${masked} - ${status}`);
|
|
1037
|
+
try {
|
|
1038
|
+
const remaining = await queryQuota(keyMeta.key);
|
|
1039
|
+
const quotaInfo = kleur.gray(` Quota: ${remaining}/500 remaining | Last check: ${lastCheck}`);
|
|
1040
|
+
console.log(quotaInfo);
|
|
1041
|
+
} catch {
|
|
1042
|
+
const quotaInfo = kleur.yellow(` Quota: Unable to query | Last check: ${lastCheck}`);
|
|
1043
|
+
console.log(quotaInfo);
|
|
1044
|
+
}
|
|
1045
|
+
console.log();
|
|
1046
|
+
}
|
|
1047
|
+
} catch (error) {
|
|
1048
|
+
console.error(kleur.red(`✗ Error listing keys: ${error.message}`));
|
|
1049
|
+
process$1.exit(1);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
//#endregion
|
|
1053
|
+
//#region src/cli.ts
|
|
1054
|
+
const cli = cac("tinyimg");
|
|
1055
|
+
cli.command("[...inputs]", "Compress images (PNG, JPG, JPEG)").option("-o, --output <dir>", "Output directory (default: overwrite in place)").option("-k, --key <key>", "API key (overrides environment and config)").option("-m, --mode <mode>", "Key selection strategy (random|round-robin|priority)", { default: "random" }).option("-p, --parallel <number>", "Concurrency limit (default: 8)", { default: "8" }).option("-c, --cache", "Enable caching (default: true)", { default: true }).option("--no-cache", "Disable caching").action(async (inputs, options) => {
|
|
1056
|
+
try {
|
|
1057
|
+
await compressCommand(inputs, options);
|
|
1058
|
+
} catch (error) {
|
|
1059
|
+
console.error(kleur.red(`Error: ${error.message}`));
|
|
1060
|
+
process$1.exit(1);
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
cli.command("key add <key>", "Add API key").action(async (key) => {
|
|
1064
|
+
try {
|
|
1065
|
+
await keyAdd(key);
|
|
1066
|
+
} catch (error) {
|
|
1067
|
+
console.error(kleur.red(`Error: ${error.message}`));
|
|
1068
|
+
process$1.exit(1);
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
cli.command("key remove [key]", "Remove API key (interactive if not specified)").action(async (key) => {
|
|
1072
|
+
try {
|
|
1073
|
+
await keyRemove(key);
|
|
1074
|
+
} catch (error) {
|
|
1075
|
+
console.error(kleur.red(`Error: ${error.message}`));
|
|
1076
|
+
process$1.exit(1);
|
|
1077
|
+
}
|
|
1078
|
+
});
|
|
1079
|
+
cli.command("key", "List all API keys with quota info").action(async () => {
|
|
1080
|
+
try {
|
|
1081
|
+
await keyList();
|
|
1082
|
+
} catch (error) {
|
|
1083
|
+
console.error(kleur.red(`Error: ${error.message}`));
|
|
1084
|
+
process$1.exit(1);
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
cli.help();
|
|
1088
|
+
cli.parse();
|
|
1089
|
+
async function main() {}
|
|
1090
|
+
//#endregion
|
|
1091
|
+
export { main };
|
|
1092
|
+
|
|
1093
|
+
//# sourceMappingURL=index.mjs.map
|