@learnosity/lib-qti-converter 0.16.0 → 0.16.2
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/package.json +10 -10
- package/packages/cli/dist/{batchProcessors-C7czhqX0.js → batchProcessors-BGdELwug.js} +75 -102
- package/packages/cli/dist/batchProcessors-BGdELwug.js.map +1 -0
- package/packages/cli/dist/batchWorker.js +2 -3
- package/packages/cli/dist/{configOutput-FwkFyQmk.js → configOutput-DYPwNQf7.js} +5 -9
- package/packages/cli/dist/{configOutput-FwkFyQmk.js.map → configOutput-DYPwNQf7.js.map} +1 -1
- package/packages/cli/dist/{create-prompt-dWckcotJ.js → create-prompt-C3XKo-s3.js} +95 -71
- package/packages/cli/dist/create-prompt-C3XKo-s3.js.map +1 -0
- package/packages/cli/dist/{dist-DXDR2peT.js → dist-D7b9-VIt.js} +8 -11
- package/packages/cli/dist/dist-D7b9-VIt.js.map +1 -0
- package/packages/cli/dist/{learnosityToQti-D4ddrXaz.js → learnosityToQti-CN6KKSmF.js} +5 -6
- package/packages/cli/dist/{learnosityToQti-D4ddrXaz.js.map → learnosityToQti-CN6KKSmF.js.map} +1 -1
- package/packages/cli/dist/{learnosityToQtiPackage-Bwzm-uLX.js → learnosityToQtiPackage-CMOQRiCV.js} +29 -21
- package/packages/cli/dist/learnosityToQtiPackage-CMOQRiCV.js.map +1 -0
- package/packages/cli/dist/main.js +22 -29
- package/packages/cli/dist/main.js.map +1 -1
- package/packages/cli/dist/{nodeFileAccess-BhCoGDOi.js → nodeFileAccess-_jRCd340.js} +6 -10
- package/packages/cli/dist/{nodeFileAccess-BhCoGDOi.js.map → nodeFileAccess-_jRCd340.js.map} +1 -1
- package/packages/cli/dist/pathUtils-I2bRHUwu.js +2922 -0
- package/packages/cli/dist/pathUtils-I2bRHUwu.js.map +1 -0
- package/packages/cli/dist/{qtiPackageToLearnosity-CX9htPId.js → qtiPackageToLearnosity-JRb3TTyC.js} +7 -8
- package/packages/cli/dist/{qtiPackageToLearnosity-CX9htPId.js.map → qtiPackageToLearnosity-JRb3TTyC.js.map} +1 -1
- package/packages/cli/dist/{qtiToLearnosity-JQYOkNbM.js → qtiToLearnosity-C-jQYKqR.js} +6 -7
- package/packages/cli/dist/{qtiToLearnosity-JQYOkNbM.js.map → qtiToLearnosity-C-jQYKqR.js.map} +1 -1
- package/packages/cli/dist/{resolveOptions-BuNN2KMA.js → resolveOptions-ikupjaRQ.js} +322 -359
- package/packages/cli/dist/resolveOptions-ikupjaRQ.js.map +1 -0
- package/packages/cli/dist/{rolldown-runtime-DktXgydw.js → rolldown-runtime-BuRBZLzk.js} +13 -12
- package/packages/cli/dist/{table-DsKq-B4-.js → table-6SiZD7aK.js} +9944 -2294
- package/packages/cli/dist/table-6SiZD7aK.js.map +1 -0
- package/packages/core/dist/index.d.ts +8 -58
- package/packages/core/dist/index.js +9923 -2267
- package/packages/core/dist/node.d.ts +10 -80
- package/packages/core/dist/node.js +9951 -2311
- package/packages/cli/dist/batchProcessors-C7czhqX0.js.map +0 -1
- package/packages/cli/dist/create-prompt-dWckcotJ.js.map +0 -1
- package/packages/cli/dist/dist-DXDR2peT.js.map +0 -1
- package/packages/cli/dist/learnosityToQtiPackage-Bwzm-uLX.js.map +0 -1
- package/packages/cli/dist/pathUtils-D_VsVde8.js +0 -2272
- package/packages/cli/dist/pathUtils-D_VsVde8.js.map +0 -1
- package/packages/cli/dist/resolveOptions-BuNN2KMA.js.map +0 -1
- package/packages/cli/dist/table-DsKq-B4-.js.map +0 -1
|
@@ -0,0 +1,2922 @@
|
|
|
1
|
+
import { _ as isEnterKey, b as isTabKey, c as usePrefix, d as useEffect, f as useState, h as isBackspaceKey, l as makeTheme, o as useKeypress, t as createPrompt } from "./create-prompt-C3XKo-s3.js";
|
|
2
|
+
import { D as DiagnosticCode, i as chalk } from "./table-6SiZD7aK.js";
|
|
3
|
+
import process$1 from "node:process";
|
|
4
|
+
import { access, readFile } from "fs/promises";
|
|
5
|
+
import { resolve } from "path";
|
|
6
|
+
import { homedir } from "os";
|
|
7
|
+
// ../../node_modules/.pnpm/@inquirer+input@5.2.1_@types+node@26.6.10/node_modules/@inquirer/input/dist/index.js
|
|
8
|
+
const inputTheme = { validationFailureMode: "keep" };
|
|
9
|
+
var dist_default = createPrompt((config, done) => {
|
|
10
|
+
const { prefill = "tab" } = config;
|
|
11
|
+
const theme = makeTheme(inputTheme, config.theme);
|
|
12
|
+
const [status, setStatus] = useState("idle");
|
|
13
|
+
const [defaultValue, setDefaultValue] = useState(String(config.default ?? ""));
|
|
14
|
+
const [errorMsg, setError] = useState();
|
|
15
|
+
const [value, setValue] = useState("");
|
|
16
|
+
const prefix = usePrefix({
|
|
17
|
+
status,
|
|
18
|
+
theme
|
|
19
|
+
});
|
|
20
|
+
async function validate(value) {
|
|
21
|
+
const { required, pattern, patternError = "Invalid input" } = config;
|
|
22
|
+
if (required && !value) return "You must provide a value";
|
|
23
|
+
if (pattern && value.search(pattern) === -1) return patternError;
|
|
24
|
+
if (typeof config.validate === "function") return await config.validate(value) || "You must provide a valid value";
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
useKeypress(async (key, rl) => {
|
|
28
|
+
if (status !== "idle") return;
|
|
29
|
+
if (isEnterKey(key)) {
|
|
30
|
+
const answer = value || defaultValue;
|
|
31
|
+
setStatus("loading");
|
|
32
|
+
const isValid = await validate(answer);
|
|
33
|
+
if (isValid === true) {
|
|
34
|
+
setError(void 0);
|
|
35
|
+
setValue(answer);
|
|
36
|
+
setStatus("done");
|
|
37
|
+
done(answer);
|
|
38
|
+
} else {
|
|
39
|
+
rl.clearLine(0);
|
|
40
|
+
if (theme.validationFailureMode === "clear") setValue("");
|
|
41
|
+
else rl.write(value);
|
|
42
|
+
setError(isValid);
|
|
43
|
+
setStatus("idle");
|
|
44
|
+
}
|
|
45
|
+
} else if (isBackspaceKey(key) && !value) setDefaultValue("");
|
|
46
|
+
else if (isTabKey(key) && !value) {
|
|
47
|
+
setDefaultValue("");
|
|
48
|
+
rl.clearLine(0);
|
|
49
|
+
rl.write(defaultValue);
|
|
50
|
+
setValue(defaultValue);
|
|
51
|
+
} else {
|
|
52
|
+
setValue(rl.line);
|
|
53
|
+
setError(void 0);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
useEffect((rl) => {
|
|
57
|
+
if (prefill === "editable" && defaultValue) {
|
|
58
|
+
rl.write(defaultValue);
|
|
59
|
+
setValue(defaultValue);
|
|
60
|
+
}
|
|
61
|
+
}, []);
|
|
62
|
+
const message = theme.style.message(config.message, status);
|
|
63
|
+
let formattedValue = value;
|
|
64
|
+
if (typeof config.transformer === "function") formattedValue = config.transformer(value, { isFinal: status === "done" });
|
|
65
|
+
else if (status === "done") formattedValue = theme.style.answer(value);
|
|
66
|
+
let defaultStr;
|
|
67
|
+
if (defaultValue && status !== "done" && !value) defaultStr = theme.style.defaultAnswer(defaultValue);
|
|
68
|
+
let error = "";
|
|
69
|
+
if (errorMsg) error = theme.style.error(errorMsg);
|
|
70
|
+
return [[
|
|
71
|
+
prefix,
|
|
72
|
+
message,
|
|
73
|
+
defaultStr,
|
|
74
|
+
formattedValue
|
|
75
|
+
].filter((v) => v !== void 0).join(" "), error];
|
|
76
|
+
});
|
|
77
|
+
// ../../node_modules/.pnpm/ansi-regex@6.6.0/node_modules/ansi-regex/index.js
|
|
78
|
+
const ST = String.raw`(?:\u001B\u005C|\u009C)`;
|
|
79
|
+
const stringControls = String.raw`\u0018\u001A\u001B\u0080-\u009F`;
|
|
80
|
+
const osc = String.raw`(?:\u001B\]|\u009D)[^\u0007${stringControls}]*(?:\u0007|${ST})`;
|
|
81
|
+
const controlString = String.raw`(?:\u001B[PX^_k]|[\u0090\u0098\u009E\u009F])[^${stringControls}]*${ST}`;
|
|
82
|
+
const pattern = `${String.raw`\u001B\](?:P[\dA-Fa-f]{7}|R)(?:\u0007|${ST})?`}|${osc}|${controlString}|${String.raw`(?:\u001B\[|\u009B)[\u0030-\u003F]*[\u0020-\u002F]*[\u0040-\u007E]`}|${String.raw`\u001B(?:[\u0020-\u002F]+[\u0030-\u007E]|[\dA-PR-TZcf-oq-uy=><~|}])`}`;
|
|
83
|
+
function ansiRegex({ onlyFirst = false } = {}) {
|
|
84
|
+
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
85
|
+
}
|
|
86
|
+
// ../../node_modules/.pnpm/strip-ansi@7.2.0/node_modules/strip-ansi/index.js
|
|
87
|
+
const regex = ansiRegex();
|
|
88
|
+
function stripAnsi(string) {
|
|
89
|
+
if (typeof string !== "string") throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
90
|
+
if (!string.includes("\x1B") && !string.includes("")) return string;
|
|
91
|
+
return string.replace(regex, "");
|
|
92
|
+
}
|
|
93
|
+
const ambiguousRanges = [
|
|
94
|
+
161,
|
|
95
|
+
161,
|
|
96
|
+
164,
|
|
97
|
+
164,
|
|
98
|
+
167,
|
|
99
|
+
168,
|
|
100
|
+
170,
|
|
101
|
+
170,
|
|
102
|
+
173,
|
|
103
|
+
174,
|
|
104
|
+
176,
|
|
105
|
+
180,
|
|
106
|
+
182,
|
|
107
|
+
186,
|
|
108
|
+
188,
|
|
109
|
+
191,
|
|
110
|
+
198,
|
|
111
|
+
198,
|
|
112
|
+
208,
|
|
113
|
+
208,
|
|
114
|
+
215,
|
|
115
|
+
216,
|
|
116
|
+
222,
|
|
117
|
+
225,
|
|
118
|
+
230,
|
|
119
|
+
230,
|
|
120
|
+
232,
|
|
121
|
+
234,
|
|
122
|
+
236,
|
|
123
|
+
237,
|
|
124
|
+
240,
|
|
125
|
+
240,
|
|
126
|
+
242,
|
|
127
|
+
243,
|
|
128
|
+
247,
|
|
129
|
+
250,
|
|
130
|
+
252,
|
|
131
|
+
252,
|
|
132
|
+
254,
|
|
133
|
+
254,
|
|
134
|
+
257,
|
|
135
|
+
257,
|
|
136
|
+
273,
|
|
137
|
+
273,
|
|
138
|
+
275,
|
|
139
|
+
275,
|
|
140
|
+
283,
|
|
141
|
+
283,
|
|
142
|
+
294,
|
|
143
|
+
295,
|
|
144
|
+
299,
|
|
145
|
+
299,
|
|
146
|
+
305,
|
|
147
|
+
307,
|
|
148
|
+
312,
|
|
149
|
+
312,
|
|
150
|
+
319,
|
|
151
|
+
322,
|
|
152
|
+
324,
|
|
153
|
+
324,
|
|
154
|
+
328,
|
|
155
|
+
331,
|
|
156
|
+
333,
|
|
157
|
+
333,
|
|
158
|
+
338,
|
|
159
|
+
339,
|
|
160
|
+
358,
|
|
161
|
+
359,
|
|
162
|
+
363,
|
|
163
|
+
363,
|
|
164
|
+
462,
|
|
165
|
+
462,
|
|
166
|
+
464,
|
|
167
|
+
464,
|
|
168
|
+
466,
|
|
169
|
+
466,
|
|
170
|
+
468,
|
|
171
|
+
468,
|
|
172
|
+
470,
|
|
173
|
+
470,
|
|
174
|
+
472,
|
|
175
|
+
472,
|
|
176
|
+
474,
|
|
177
|
+
474,
|
|
178
|
+
476,
|
|
179
|
+
476,
|
|
180
|
+
593,
|
|
181
|
+
593,
|
|
182
|
+
609,
|
|
183
|
+
609,
|
|
184
|
+
708,
|
|
185
|
+
708,
|
|
186
|
+
711,
|
|
187
|
+
711,
|
|
188
|
+
713,
|
|
189
|
+
715,
|
|
190
|
+
717,
|
|
191
|
+
717,
|
|
192
|
+
720,
|
|
193
|
+
720,
|
|
194
|
+
728,
|
|
195
|
+
731,
|
|
196
|
+
733,
|
|
197
|
+
733,
|
|
198
|
+
735,
|
|
199
|
+
735,
|
|
200
|
+
768,
|
|
201
|
+
879,
|
|
202
|
+
913,
|
|
203
|
+
929,
|
|
204
|
+
931,
|
|
205
|
+
937,
|
|
206
|
+
945,
|
|
207
|
+
961,
|
|
208
|
+
963,
|
|
209
|
+
969,
|
|
210
|
+
1025,
|
|
211
|
+
1025,
|
|
212
|
+
1040,
|
|
213
|
+
1103,
|
|
214
|
+
1105,
|
|
215
|
+
1105,
|
|
216
|
+
8208,
|
|
217
|
+
8208,
|
|
218
|
+
8211,
|
|
219
|
+
8214,
|
|
220
|
+
8216,
|
|
221
|
+
8217,
|
|
222
|
+
8220,
|
|
223
|
+
8221,
|
|
224
|
+
8224,
|
|
225
|
+
8226,
|
|
226
|
+
8228,
|
|
227
|
+
8231,
|
|
228
|
+
8240,
|
|
229
|
+
8240,
|
|
230
|
+
8242,
|
|
231
|
+
8243,
|
|
232
|
+
8245,
|
|
233
|
+
8245,
|
|
234
|
+
8251,
|
|
235
|
+
8251,
|
|
236
|
+
8254,
|
|
237
|
+
8254,
|
|
238
|
+
8308,
|
|
239
|
+
8308,
|
|
240
|
+
8319,
|
|
241
|
+
8319,
|
|
242
|
+
8321,
|
|
243
|
+
8324,
|
|
244
|
+
8364,
|
|
245
|
+
8364,
|
|
246
|
+
8451,
|
|
247
|
+
8451,
|
|
248
|
+
8453,
|
|
249
|
+
8453,
|
|
250
|
+
8457,
|
|
251
|
+
8457,
|
|
252
|
+
8467,
|
|
253
|
+
8467,
|
|
254
|
+
8470,
|
|
255
|
+
8470,
|
|
256
|
+
8481,
|
|
257
|
+
8482,
|
|
258
|
+
8486,
|
|
259
|
+
8486,
|
|
260
|
+
8491,
|
|
261
|
+
8491,
|
|
262
|
+
8531,
|
|
263
|
+
8532,
|
|
264
|
+
8539,
|
|
265
|
+
8542,
|
|
266
|
+
8544,
|
|
267
|
+
8555,
|
|
268
|
+
8560,
|
|
269
|
+
8569,
|
|
270
|
+
8585,
|
|
271
|
+
8585,
|
|
272
|
+
8592,
|
|
273
|
+
8601,
|
|
274
|
+
8632,
|
|
275
|
+
8633,
|
|
276
|
+
8658,
|
|
277
|
+
8658,
|
|
278
|
+
8660,
|
|
279
|
+
8660,
|
|
280
|
+
8679,
|
|
281
|
+
8679,
|
|
282
|
+
8704,
|
|
283
|
+
8704,
|
|
284
|
+
8706,
|
|
285
|
+
8707,
|
|
286
|
+
8711,
|
|
287
|
+
8712,
|
|
288
|
+
8715,
|
|
289
|
+
8715,
|
|
290
|
+
8719,
|
|
291
|
+
8719,
|
|
292
|
+
8721,
|
|
293
|
+
8721,
|
|
294
|
+
8725,
|
|
295
|
+
8725,
|
|
296
|
+
8730,
|
|
297
|
+
8730,
|
|
298
|
+
8733,
|
|
299
|
+
8736,
|
|
300
|
+
8739,
|
|
301
|
+
8739,
|
|
302
|
+
8741,
|
|
303
|
+
8741,
|
|
304
|
+
8743,
|
|
305
|
+
8748,
|
|
306
|
+
8750,
|
|
307
|
+
8750,
|
|
308
|
+
8756,
|
|
309
|
+
8759,
|
|
310
|
+
8764,
|
|
311
|
+
8765,
|
|
312
|
+
8776,
|
|
313
|
+
8776,
|
|
314
|
+
8780,
|
|
315
|
+
8780,
|
|
316
|
+
8786,
|
|
317
|
+
8786,
|
|
318
|
+
8800,
|
|
319
|
+
8801,
|
|
320
|
+
8804,
|
|
321
|
+
8807,
|
|
322
|
+
8810,
|
|
323
|
+
8811,
|
|
324
|
+
8814,
|
|
325
|
+
8815,
|
|
326
|
+
8834,
|
|
327
|
+
8835,
|
|
328
|
+
8838,
|
|
329
|
+
8839,
|
|
330
|
+
8853,
|
|
331
|
+
8853,
|
|
332
|
+
8857,
|
|
333
|
+
8857,
|
|
334
|
+
8869,
|
|
335
|
+
8869,
|
|
336
|
+
8895,
|
|
337
|
+
8895,
|
|
338
|
+
8978,
|
|
339
|
+
8978,
|
|
340
|
+
9312,
|
|
341
|
+
9449,
|
|
342
|
+
9451,
|
|
343
|
+
9547,
|
|
344
|
+
9552,
|
|
345
|
+
9587,
|
|
346
|
+
9600,
|
|
347
|
+
9615,
|
|
348
|
+
9618,
|
|
349
|
+
9621,
|
|
350
|
+
9632,
|
|
351
|
+
9633,
|
|
352
|
+
9635,
|
|
353
|
+
9641,
|
|
354
|
+
9650,
|
|
355
|
+
9651,
|
|
356
|
+
9654,
|
|
357
|
+
9655,
|
|
358
|
+
9660,
|
|
359
|
+
9661,
|
|
360
|
+
9664,
|
|
361
|
+
9665,
|
|
362
|
+
9670,
|
|
363
|
+
9672,
|
|
364
|
+
9675,
|
|
365
|
+
9675,
|
|
366
|
+
9678,
|
|
367
|
+
9681,
|
|
368
|
+
9698,
|
|
369
|
+
9701,
|
|
370
|
+
9711,
|
|
371
|
+
9711,
|
|
372
|
+
9733,
|
|
373
|
+
9734,
|
|
374
|
+
9737,
|
|
375
|
+
9737,
|
|
376
|
+
9742,
|
|
377
|
+
9743,
|
|
378
|
+
9756,
|
|
379
|
+
9756,
|
|
380
|
+
9758,
|
|
381
|
+
9758,
|
|
382
|
+
9792,
|
|
383
|
+
9792,
|
|
384
|
+
9794,
|
|
385
|
+
9794,
|
|
386
|
+
9824,
|
|
387
|
+
9825,
|
|
388
|
+
9827,
|
|
389
|
+
9829,
|
|
390
|
+
9831,
|
|
391
|
+
9834,
|
|
392
|
+
9836,
|
|
393
|
+
9837,
|
|
394
|
+
9839,
|
|
395
|
+
9839,
|
|
396
|
+
9886,
|
|
397
|
+
9887,
|
|
398
|
+
9919,
|
|
399
|
+
9919,
|
|
400
|
+
9926,
|
|
401
|
+
9933,
|
|
402
|
+
9935,
|
|
403
|
+
9939,
|
|
404
|
+
9941,
|
|
405
|
+
9953,
|
|
406
|
+
9955,
|
|
407
|
+
9955,
|
|
408
|
+
9960,
|
|
409
|
+
9961,
|
|
410
|
+
9963,
|
|
411
|
+
9969,
|
|
412
|
+
9972,
|
|
413
|
+
9972,
|
|
414
|
+
9974,
|
|
415
|
+
9977,
|
|
416
|
+
9979,
|
|
417
|
+
9980,
|
|
418
|
+
9982,
|
|
419
|
+
9983,
|
|
420
|
+
10045,
|
|
421
|
+
10045,
|
|
422
|
+
10102,
|
|
423
|
+
10111,
|
|
424
|
+
11094,
|
|
425
|
+
11097,
|
|
426
|
+
12872,
|
|
427
|
+
12879,
|
|
428
|
+
57344,
|
|
429
|
+
63743,
|
|
430
|
+
65024,
|
|
431
|
+
65039,
|
|
432
|
+
65533,
|
|
433
|
+
65533,
|
|
434
|
+
127232,
|
|
435
|
+
127242,
|
|
436
|
+
127248,
|
|
437
|
+
127277,
|
|
438
|
+
127280,
|
|
439
|
+
127337,
|
|
440
|
+
127344,
|
|
441
|
+
127373,
|
|
442
|
+
127375,
|
|
443
|
+
127376,
|
|
444
|
+
127387,
|
|
445
|
+
127404,
|
|
446
|
+
917760,
|
|
447
|
+
917999,
|
|
448
|
+
983040,
|
|
449
|
+
0xffffd,
|
|
450
|
+
1048576,
|
|
451
|
+
1114109
|
|
452
|
+
];
|
|
453
|
+
const fullwidthRanges = [
|
|
454
|
+
12288,
|
|
455
|
+
12288,
|
|
456
|
+
65281,
|
|
457
|
+
65376,
|
|
458
|
+
65504,
|
|
459
|
+
65510
|
|
460
|
+
];
|
|
461
|
+
const wideRanges = [
|
|
462
|
+
4352,
|
|
463
|
+
4447,
|
|
464
|
+
8986,
|
|
465
|
+
8987,
|
|
466
|
+
9001,
|
|
467
|
+
9002,
|
|
468
|
+
9193,
|
|
469
|
+
9196,
|
|
470
|
+
9200,
|
|
471
|
+
9200,
|
|
472
|
+
9203,
|
|
473
|
+
9203,
|
|
474
|
+
9725,
|
|
475
|
+
9726,
|
|
476
|
+
9748,
|
|
477
|
+
9749,
|
|
478
|
+
9776,
|
|
479
|
+
9783,
|
|
480
|
+
9800,
|
|
481
|
+
9811,
|
|
482
|
+
9855,
|
|
483
|
+
9855,
|
|
484
|
+
9866,
|
|
485
|
+
9871,
|
|
486
|
+
9875,
|
|
487
|
+
9875,
|
|
488
|
+
9889,
|
|
489
|
+
9889,
|
|
490
|
+
9898,
|
|
491
|
+
9899,
|
|
492
|
+
9917,
|
|
493
|
+
9918,
|
|
494
|
+
9924,
|
|
495
|
+
9925,
|
|
496
|
+
9934,
|
|
497
|
+
9934,
|
|
498
|
+
9940,
|
|
499
|
+
9940,
|
|
500
|
+
9962,
|
|
501
|
+
9962,
|
|
502
|
+
9970,
|
|
503
|
+
9971,
|
|
504
|
+
9973,
|
|
505
|
+
9973,
|
|
506
|
+
9978,
|
|
507
|
+
9978,
|
|
508
|
+
9981,
|
|
509
|
+
9981,
|
|
510
|
+
9989,
|
|
511
|
+
9989,
|
|
512
|
+
9994,
|
|
513
|
+
9995,
|
|
514
|
+
10024,
|
|
515
|
+
10024,
|
|
516
|
+
10060,
|
|
517
|
+
10060,
|
|
518
|
+
10062,
|
|
519
|
+
10062,
|
|
520
|
+
10067,
|
|
521
|
+
10069,
|
|
522
|
+
10071,
|
|
523
|
+
10071,
|
|
524
|
+
10133,
|
|
525
|
+
10135,
|
|
526
|
+
10160,
|
|
527
|
+
10160,
|
|
528
|
+
10175,
|
|
529
|
+
10175,
|
|
530
|
+
11035,
|
|
531
|
+
11036,
|
|
532
|
+
11088,
|
|
533
|
+
11088,
|
|
534
|
+
11093,
|
|
535
|
+
11093,
|
|
536
|
+
11904,
|
|
537
|
+
11929,
|
|
538
|
+
11931,
|
|
539
|
+
12019,
|
|
540
|
+
12032,
|
|
541
|
+
12245,
|
|
542
|
+
12272,
|
|
543
|
+
12287,
|
|
544
|
+
12289,
|
|
545
|
+
12350,
|
|
546
|
+
12353,
|
|
547
|
+
12438,
|
|
548
|
+
12441,
|
|
549
|
+
12543,
|
|
550
|
+
12549,
|
|
551
|
+
12591,
|
|
552
|
+
12593,
|
|
553
|
+
12686,
|
|
554
|
+
12688,
|
|
555
|
+
12773,
|
|
556
|
+
12783,
|
|
557
|
+
12830,
|
|
558
|
+
12832,
|
|
559
|
+
12871,
|
|
560
|
+
12880,
|
|
561
|
+
42124,
|
|
562
|
+
42128,
|
|
563
|
+
42182,
|
|
564
|
+
43360,
|
|
565
|
+
43388,
|
|
566
|
+
44032,
|
|
567
|
+
55203,
|
|
568
|
+
63744,
|
|
569
|
+
64255,
|
|
570
|
+
65040,
|
|
571
|
+
65049,
|
|
572
|
+
65072,
|
|
573
|
+
65106,
|
|
574
|
+
65108,
|
|
575
|
+
65126,
|
|
576
|
+
65128,
|
|
577
|
+
65131,
|
|
578
|
+
94176,
|
|
579
|
+
94180,
|
|
580
|
+
94192,
|
|
581
|
+
94198,
|
|
582
|
+
94208,
|
|
583
|
+
101594,
|
|
584
|
+
101631,
|
|
585
|
+
101664,
|
|
586
|
+
101760,
|
|
587
|
+
101874,
|
|
588
|
+
101888,
|
|
589
|
+
102801,
|
|
590
|
+
102816,
|
|
591
|
+
102866,
|
|
592
|
+
110576,
|
|
593
|
+
110579,
|
|
594
|
+
110581,
|
|
595
|
+
110587,
|
|
596
|
+
110589,
|
|
597
|
+
110590,
|
|
598
|
+
110592,
|
|
599
|
+
110888,
|
|
600
|
+
110898,
|
|
601
|
+
110898,
|
|
602
|
+
110928,
|
|
603
|
+
110930,
|
|
604
|
+
110933,
|
|
605
|
+
110933,
|
|
606
|
+
110948,
|
|
607
|
+
110952,
|
|
608
|
+
110960,
|
|
609
|
+
111355,
|
|
610
|
+
119552,
|
|
611
|
+
119638,
|
|
612
|
+
119648,
|
|
613
|
+
119670,
|
|
614
|
+
126980,
|
|
615
|
+
126980,
|
|
616
|
+
127183,
|
|
617
|
+
127183,
|
|
618
|
+
127374,
|
|
619
|
+
127374,
|
|
620
|
+
127377,
|
|
621
|
+
127386,
|
|
622
|
+
127406,
|
|
623
|
+
127406,
|
|
624
|
+
127488,
|
|
625
|
+
127490,
|
|
626
|
+
127504,
|
|
627
|
+
127547,
|
|
628
|
+
127552,
|
|
629
|
+
127560,
|
|
630
|
+
127568,
|
|
631
|
+
127569,
|
|
632
|
+
127584,
|
|
633
|
+
127589,
|
|
634
|
+
127744,
|
|
635
|
+
127776,
|
|
636
|
+
127789,
|
|
637
|
+
127797,
|
|
638
|
+
127799,
|
|
639
|
+
127868,
|
|
640
|
+
127870,
|
|
641
|
+
127891,
|
|
642
|
+
127904,
|
|
643
|
+
127946,
|
|
644
|
+
127951,
|
|
645
|
+
127955,
|
|
646
|
+
127968,
|
|
647
|
+
127984,
|
|
648
|
+
127988,
|
|
649
|
+
127988,
|
|
650
|
+
127992,
|
|
651
|
+
128062,
|
|
652
|
+
128064,
|
|
653
|
+
128064,
|
|
654
|
+
128066,
|
|
655
|
+
128252,
|
|
656
|
+
128255,
|
|
657
|
+
128317,
|
|
658
|
+
128331,
|
|
659
|
+
128334,
|
|
660
|
+
128336,
|
|
661
|
+
128359,
|
|
662
|
+
128378,
|
|
663
|
+
128378,
|
|
664
|
+
128405,
|
|
665
|
+
128406,
|
|
666
|
+
128420,
|
|
667
|
+
128420,
|
|
668
|
+
128507,
|
|
669
|
+
128591,
|
|
670
|
+
128640,
|
|
671
|
+
128709,
|
|
672
|
+
128716,
|
|
673
|
+
128716,
|
|
674
|
+
128720,
|
|
675
|
+
128722,
|
|
676
|
+
128725,
|
|
677
|
+
128729,
|
|
678
|
+
128732,
|
|
679
|
+
128735,
|
|
680
|
+
128747,
|
|
681
|
+
128748,
|
|
682
|
+
128756,
|
|
683
|
+
128764,
|
|
684
|
+
128986,
|
|
685
|
+
128986,
|
|
686
|
+
128992,
|
|
687
|
+
129003,
|
|
688
|
+
129008,
|
|
689
|
+
129008,
|
|
690
|
+
129292,
|
|
691
|
+
129338,
|
|
692
|
+
129340,
|
|
693
|
+
129349,
|
|
694
|
+
129351,
|
|
695
|
+
129535,
|
|
696
|
+
129648,
|
|
697
|
+
129660,
|
|
698
|
+
129664,
|
|
699
|
+
129734,
|
|
700
|
+
129736,
|
|
701
|
+
129736,
|
|
702
|
+
129740,
|
|
703
|
+
129757,
|
|
704
|
+
129759,
|
|
705
|
+
129771,
|
|
706
|
+
129775,
|
|
707
|
+
129786,
|
|
708
|
+
131072,
|
|
709
|
+
196605,
|
|
710
|
+
196608,
|
|
711
|
+
262141
|
|
712
|
+
];
|
|
713
|
+
// ../../node_modules/.pnpm/get-east-asian-width@1.7.0/node_modules/get-east-asian-width/utilities.js
|
|
714
|
+
/**
|
|
715
|
+
Binary search on a sorted flat array of [start, end] pairs.
|
|
716
|
+
|
|
717
|
+
@param {number[]} ranges - Flat array of inclusive [start, end] range pairs, e.g. [0, 5, 10, 20].
|
|
718
|
+
@param {number} codePoint - The value to search for.
|
|
719
|
+
@returns {boolean} Whether the value falls within any of the ranges.
|
|
720
|
+
*/
|
|
721
|
+
const isInRange = (ranges, codePoint) => {
|
|
722
|
+
let low = 0;
|
|
723
|
+
let high = Math.floor(ranges.length / 2) - 1;
|
|
724
|
+
while (low <= high) {
|
|
725
|
+
const mid = Math.floor((low + high) / 2);
|
|
726
|
+
const i = mid * 2;
|
|
727
|
+
if (codePoint < ranges[i]) high = mid - 1;
|
|
728
|
+
else if (codePoint > ranges[i + 1]) low = mid + 1;
|
|
729
|
+
else return true;
|
|
730
|
+
}
|
|
731
|
+
return false;
|
|
732
|
+
};
|
|
733
|
+
// ../../node_modules/.pnpm/get-east-asian-width@1.7.0/node_modules/get-east-asian-width/lookup.js
|
|
734
|
+
const commonCjkCodePoint = 19968;
|
|
735
|
+
const [wideFastPathStart, wideFastPathEnd] = /* #__PURE__ */ findWideFastPathRange(wideRanges);
|
|
736
|
+
function findWideFastPathRange(ranges) {
|
|
737
|
+
let fastPathStart = ranges[0];
|
|
738
|
+
let fastPathEnd = ranges[1];
|
|
739
|
+
for (let index = 0; index < ranges.length; index += 2) {
|
|
740
|
+
const start = ranges[index];
|
|
741
|
+
const end = ranges[index + 1];
|
|
742
|
+
if (commonCjkCodePoint >= start && commonCjkCodePoint <= end) return [start, end];
|
|
743
|
+
if (end - start > fastPathEnd - fastPathStart) {
|
|
744
|
+
fastPathStart = start;
|
|
745
|
+
fastPathEnd = end;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
return [fastPathStart, fastPathEnd];
|
|
749
|
+
}
|
|
750
|
+
const isAmbiguous = (codePoint) => {
|
|
751
|
+
if (codePoint < 161 || codePoint > 1114109) return false;
|
|
752
|
+
return isInRange(ambiguousRanges, codePoint);
|
|
753
|
+
};
|
|
754
|
+
const isFullwidth = (codePoint) => {
|
|
755
|
+
if (codePoint < 12288 || codePoint > 65510) return false;
|
|
756
|
+
return isInRange(fullwidthRanges, codePoint);
|
|
757
|
+
};
|
|
758
|
+
const isWide = (codePoint) => {
|
|
759
|
+
if (codePoint >= wideFastPathStart && codePoint <= wideFastPathEnd) return true;
|
|
760
|
+
if (codePoint < 4352 || codePoint > 262141) return false;
|
|
761
|
+
return isInRange(wideRanges, codePoint);
|
|
762
|
+
};
|
|
763
|
+
// ../../node_modules/.pnpm/get-east-asian-width@1.7.0/node_modules/get-east-asian-width/index.js
|
|
764
|
+
function validate(codePoint) {
|
|
765
|
+
if (!Number.isSafeInteger(codePoint)) throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
766
|
+
}
|
|
767
|
+
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
768
|
+
validate(codePoint);
|
|
769
|
+
if (isFullwidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) return 2;
|
|
770
|
+
return 1;
|
|
771
|
+
}
|
|
772
|
+
// ../../node_modules/.pnpm/string-width@8.3.0/node_modules/string-width/index.js
|
|
773
|
+
/**
|
|
774
|
+
Logic:
|
|
775
|
+
- Segment graphemes to match how terminals render clusters.
|
|
776
|
+
- Width rules:
|
|
777
|
+
1. Skip non-printing clusters (Default_Ignorable, Control, pure nonspacing/enclosing Mark, lone Surrogates). Tabs are ignored by design.
|
|
778
|
+
2. RGI emoji clusters (\p{RGI_Emoji}) are double-width.
|
|
779
|
+
3. Minimally-qualified/unqualified emoji clusters (ZWJ sequences with 2+ Extended_Pictographic, or keycap sequences) are double-width.
|
|
780
|
+
4. Hangul jamo collapse each standard modern Hangul L+V or L+V+T syllable piece to width 2.
|
|
781
|
+
Unmatched repeated leading/vowel/trailing jamo stay additive because that matches how the terminals we target render them.
|
|
782
|
+
5. Otherwise use East Asian Width of the cluster's first visible code point, and add widths for trailing spacing marks and Halfwidth/Fullwidth Forms within the same cluster (e.g., dakuten/handakuten/prolonged sound mark).
|
|
783
|
+
*/
|
|
784
|
+
const segmenter$1 = new Intl.Segmenter();
|
|
785
|
+
const visibleCharacterRegex = /[^\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Nonspacing_Mark}\p{Enclosing_Mark}\p{Surrogate}]/v;
|
|
786
|
+
const spacingMarkRegex = /\p{Spacing_Mark}/v;
|
|
787
|
+
const rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
|
|
788
|
+
const unqualifiedKeycapRegex = /^[\d#*]\u20E3$/;
|
|
789
|
+
const extendedPictographicRegex = /\p{Extended_Pictographic}/gu;
|
|
790
|
+
function isDoubleWidthNonRgiEmojiSequence(segment) {
|
|
791
|
+
if (segment.length > 50) return false;
|
|
792
|
+
if (unqualifiedKeycapRegex.test(segment)) return true;
|
|
793
|
+
if (segment.includes("")) {
|
|
794
|
+
const pictographics = segment.match(extendedPictographicRegex);
|
|
795
|
+
return pictographics !== null && pictographics.length >= 2;
|
|
796
|
+
}
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
function baseVisible(segment) {
|
|
800
|
+
const index = segment.search(visibleCharacterRegex);
|
|
801
|
+
return index === -1 ? void 0 : segment.slice(index);
|
|
802
|
+
}
|
|
803
|
+
function isHangulLeadingJamo(codePoint) {
|
|
804
|
+
return codePoint >= 4352 && codePoint <= 4447 || codePoint >= 43360 && codePoint <= 43388;
|
|
805
|
+
}
|
|
806
|
+
function isHangulVowelJamo(codePoint) {
|
|
807
|
+
return codePoint >= 4448 && codePoint <= 4519 || codePoint >= 55216 && codePoint <= 55238;
|
|
808
|
+
}
|
|
809
|
+
function isHangulTrailingJamo(codePoint) {
|
|
810
|
+
return codePoint >= 4520 && codePoint <= 4607 || codePoint >= 55243 && codePoint <= 55291;
|
|
811
|
+
}
|
|
812
|
+
function isHangulJamo(codePoint) {
|
|
813
|
+
return isHangulLeadingJamo(codePoint) || isHangulVowelJamo(codePoint) || isHangulTrailingJamo(codePoint);
|
|
814
|
+
}
|
|
815
|
+
function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
|
|
816
|
+
const codePoints = [];
|
|
817
|
+
for (const character of visibleSegment) {
|
|
818
|
+
if (!visibleCharacterRegex.test(character)) continue;
|
|
819
|
+
codePoints.push(character.codePointAt(0));
|
|
820
|
+
}
|
|
821
|
+
if (codePoints.length === 0) return;
|
|
822
|
+
let width = 0;
|
|
823
|
+
for (let index = 0; index < codePoints.length; index++) {
|
|
824
|
+
const codePoint = codePoints[index];
|
|
825
|
+
if (!isHangulJamo(codePoint)) {
|
|
826
|
+
if (width === 0) return;
|
|
827
|
+
for (let remaining = index; remaining < codePoints.length; remaining++) width += eastAsianWidth(codePoints[remaining], eastAsianWidthOptions);
|
|
828
|
+
return width;
|
|
829
|
+
}
|
|
830
|
+
if (isHangulLeadingJamo(codePoint) && isHangulVowelJamo(codePoints[index + 1])) {
|
|
831
|
+
width += 2;
|
|
832
|
+
index += isHangulTrailingJamo(codePoints[index + 2]) ? 2 : 1;
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
836
|
+
}
|
|
837
|
+
return width;
|
|
838
|
+
}
|
|
839
|
+
function trailingWidth(visibleSegment, eastAsianWidthOptions) {
|
|
840
|
+
let extra = 0;
|
|
841
|
+
let first = true;
|
|
842
|
+
for (const character of visibleSegment) {
|
|
843
|
+
if (first) {
|
|
844
|
+
first = false;
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
847
|
+
if (spacingMarkRegex.test(character) || character >= "" && character <= "") extra += eastAsianWidth(character.codePointAt(0), eastAsianWidthOptions);
|
|
848
|
+
}
|
|
849
|
+
return extra;
|
|
850
|
+
}
|
|
851
|
+
function stringWidth(input, options = {}) {
|
|
852
|
+
if (typeof input !== "string" || input.length === 0) return 0;
|
|
853
|
+
const { ambiguousIsNarrow = true, countAnsiEscapeCodes = false } = options;
|
|
854
|
+
let string = input;
|
|
855
|
+
if (!countAnsiEscapeCodes && (string.includes("\x1B") || string.includes(""))) string = stripAnsi(string);
|
|
856
|
+
if (string.length === 0) return 0;
|
|
857
|
+
if (/^[\u0020-\u007E]*$/.test(string)) return string.length;
|
|
858
|
+
let width = 0;
|
|
859
|
+
const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
|
|
860
|
+
for (const { segment } of segmenter$1.segment(string)) {
|
|
861
|
+
const visibleSegment = baseVisible(segment);
|
|
862
|
+
if (visibleSegment === void 0) continue;
|
|
863
|
+
if (rgiEmojiRegex.test(segment) || isDoubleWidthNonRgiEmojiSequence(segment)) {
|
|
864
|
+
width += 2;
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
const hangulWidth = hangulClusterWidth(visibleSegment, eastAsianWidthOptions);
|
|
868
|
+
if (hangulWidth !== void 0) {
|
|
869
|
+
width += hangulWidth;
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
const codePoint = visibleSegment.codePointAt(0);
|
|
873
|
+
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
874
|
+
width += trailingWidth(visibleSegment, eastAsianWidthOptions);
|
|
875
|
+
}
|
|
876
|
+
return width;
|
|
877
|
+
}
|
|
878
|
+
// ../../node_modules/.pnpm/widest-line@6.0.0/node_modules/widest-line/index.js
|
|
879
|
+
function widestLine(string) {
|
|
880
|
+
let lineWidth = 0;
|
|
881
|
+
for (const line of string.split("\n")) lineWidth = Math.max(lineWidth, stringWidth(line));
|
|
882
|
+
return lineWidth;
|
|
883
|
+
}
|
|
884
|
+
// ../../node_modules/.pnpm/cli-boxes@4.0.1/node_modules/cli-boxes/index.js
|
|
885
|
+
var cli_boxes_default = {
|
|
886
|
+
single: {
|
|
887
|
+
"topLeft": "┌",
|
|
888
|
+
"top": "─",
|
|
889
|
+
"topRight": "┐",
|
|
890
|
+
"right": "│",
|
|
891
|
+
"bottomRight": "┘",
|
|
892
|
+
"bottom": "─",
|
|
893
|
+
"bottomLeft": "└",
|
|
894
|
+
"left": "│"
|
|
895
|
+
},
|
|
896
|
+
double: {
|
|
897
|
+
"topLeft": "╔",
|
|
898
|
+
"top": "═",
|
|
899
|
+
"topRight": "╗",
|
|
900
|
+
"right": "║",
|
|
901
|
+
"bottomRight": "╝",
|
|
902
|
+
"bottom": "═",
|
|
903
|
+
"bottomLeft": "╚",
|
|
904
|
+
"left": "║"
|
|
905
|
+
},
|
|
906
|
+
round: {
|
|
907
|
+
"topLeft": "╭",
|
|
908
|
+
"top": "─",
|
|
909
|
+
"topRight": "╮",
|
|
910
|
+
"right": "│",
|
|
911
|
+
"bottomRight": "╯",
|
|
912
|
+
"bottom": "─",
|
|
913
|
+
"bottomLeft": "╰",
|
|
914
|
+
"left": "│"
|
|
915
|
+
},
|
|
916
|
+
bold: {
|
|
917
|
+
"topLeft": "┏",
|
|
918
|
+
"top": "━",
|
|
919
|
+
"topRight": "┓",
|
|
920
|
+
"right": "┃",
|
|
921
|
+
"bottomRight": "┛",
|
|
922
|
+
"bottom": "━",
|
|
923
|
+
"bottomLeft": "┗",
|
|
924
|
+
"left": "┃"
|
|
925
|
+
},
|
|
926
|
+
singleDouble: {
|
|
927
|
+
"topLeft": "╓",
|
|
928
|
+
"top": "─",
|
|
929
|
+
"topRight": "╖",
|
|
930
|
+
"right": "║",
|
|
931
|
+
"bottomRight": "╜",
|
|
932
|
+
"bottom": "─",
|
|
933
|
+
"bottomLeft": "╙",
|
|
934
|
+
"left": "║"
|
|
935
|
+
},
|
|
936
|
+
doubleSingle: {
|
|
937
|
+
"topLeft": "╒",
|
|
938
|
+
"top": "═",
|
|
939
|
+
"topRight": "╕",
|
|
940
|
+
"right": "│",
|
|
941
|
+
"bottomRight": "╛",
|
|
942
|
+
"bottom": "═",
|
|
943
|
+
"bottomLeft": "╘",
|
|
944
|
+
"left": "│"
|
|
945
|
+
},
|
|
946
|
+
classic: {
|
|
947
|
+
"topLeft": "+",
|
|
948
|
+
"top": "-",
|
|
949
|
+
"topRight": "+",
|
|
950
|
+
"right": "|",
|
|
951
|
+
"bottomRight": "+",
|
|
952
|
+
"bottom": "-",
|
|
953
|
+
"bottomLeft": "+",
|
|
954
|
+
"left": "|"
|
|
955
|
+
},
|
|
956
|
+
arrow: {
|
|
957
|
+
"topLeft": "↘",
|
|
958
|
+
"top": "↓",
|
|
959
|
+
"topRight": "↙",
|
|
960
|
+
"right": "←",
|
|
961
|
+
"bottomRight": "↖",
|
|
962
|
+
"bottom": "↑",
|
|
963
|
+
"bottomLeft": "↗",
|
|
964
|
+
"left": "→"
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
// ../../node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js
|
|
968
|
+
const ANSI_BACKGROUND_OFFSET = 10;
|
|
969
|
+
const wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
|
|
970
|
+
const wrapAnsi256 = (offset = 0) => (code) => `\u001B[${38 + offset};5;${code}m`;
|
|
971
|
+
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
|
|
972
|
+
const styles = {
|
|
973
|
+
modifier: {
|
|
974
|
+
reset: [0, 0],
|
|
975
|
+
bold: [1, 22],
|
|
976
|
+
dim: [2, 22],
|
|
977
|
+
italic: [3, 23],
|
|
978
|
+
underline: [4, 24],
|
|
979
|
+
overline: [53, 55],
|
|
980
|
+
inverse: [7, 27],
|
|
981
|
+
hidden: [8, 28],
|
|
982
|
+
strikethrough: [9, 29]
|
|
983
|
+
},
|
|
984
|
+
color: {
|
|
985
|
+
black: [30, 39],
|
|
986
|
+
red: [31, 39],
|
|
987
|
+
green: [32, 39],
|
|
988
|
+
yellow: [33, 39],
|
|
989
|
+
blue: [34, 39],
|
|
990
|
+
magenta: [35, 39],
|
|
991
|
+
cyan: [36, 39],
|
|
992
|
+
white: [37, 39],
|
|
993
|
+
blackBright: [90, 39],
|
|
994
|
+
gray: [90, 39],
|
|
995
|
+
grey: [90, 39],
|
|
996
|
+
redBright: [91, 39],
|
|
997
|
+
greenBright: [92, 39],
|
|
998
|
+
yellowBright: [93, 39],
|
|
999
|
+
blueBright: [94, 39],
|
|
1000
|
+
magentaBright: [95, 39],
|
|
1001
|
+
cyanBright: [96, 39],
|
|
1002
|
+
whiteBright: [97, 39]
|
|
1003
|
+
},
|
|
1004
|
+
bgColor: {
|
|
1005
|
+
bgBlack: [40, 49],
|
|
1006
|
+
bgRed: [41, 49],
|
|
1007
|
+
bgGreen: [42, 49],
|
|
1008
|
+
bgYellow: [43, 49],
|
|
1009
|
+
bgBlue: [44, 49],
|
|
1010
|
+
bgMagenta: [45, 49],
|
|
1011
|
+
bgCyan: [46, 49],
|
|
1012
|
+
bgWhite: [47, 49],
|
|
1013
|
+
bgBlackBright: [100, 49],
|
|
1014
|
+
bgGray: [100, 49],
|
|
1015
|
+
bgGrey: [100, 49],
|
|
1016
|
+
bgRedBright: [101, 49],
|
|
1017
|
+
bgGreenBright: [102, 49],
|
|
1018
|
+
bgYellowBright: [103, 49],
|
|
1019
|
+
bgBlueBright: [104, 49],
|
|
1020
|
+
bgMagentaBright: [105, 49],
|
|
1021
|
+
bgCyanBright: [106, 49],
|
|
1022
|
+
bgWhiteBright: [107, 49]
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
1025
|
+
Object.keys(styles.modifier);
|
|
1026
|
+
const foregroundColorNames = Object.keys(styles.color);
|
|
1027
|
+
const backgroundColorNames = Object.keys(styles.bgColor);
|
|
1028
|
+
[...foregroundColorNames, ...backgroundColorNames];
|
|
1029
|
+
function assembleStyles() {
|
|
1030
|
+
const codes = /* @__PURE__ */ new Map();
|
|
1031
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
1032
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
1033
|
+
styles[styleName] = {
|
|
1034
|
+
open: `\u001B[${style[0]}m`,
|
|
1035
|
+
close: `\u001B[${style[1]}m`
|
|
1036
|
+
};
|
|
1037
|
+
group[styleName] = styles[styleName];
|
|
1038
|
+
codes.set(style[0], style[1]);
|
|
1039
|
+
}
|
|
1040
|
+
Object.defineProperty(styles, groupName, {
|
|
1041
|
+
value: group,
|
|
1042
|
+
enumerable: false
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
Object.defineProperty(styles, "codes", {
|
|
1046
|
+
value: codes,
|
|
1047
|
+
enumerable: false
|
|
1048
|
+
});
|
|
1049
|
+
styles.color.close = "\x1B[39m";
|
|
1050
|
+
styles.bgColor.close = "\x1B[49m";
|
|
1051
|
+
styles.color.ansi = wrapAnsi16();
|
|
1052
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
1053
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
1054
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
1055
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
1056
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
1057
|
+
Object.defineProperties(styles, {
|
|
1058
|
+
rgbToAnsi256: {
|
|
1059
|
+
value(red, green, blue) {
|
|
1060
|
+
if (red === green && green === blue) {
|
|
1061
|
+
if (red < 8) return 16;
|
|
1062
|
+
if (red > 248) return 231;
|
|
1063
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
|
1064
|
+
}
|
|
1065
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
1066
|
+
},
|
|
1067
|
+
enumerable: false
|
|
1068
|
+
},
|
|
1069
|
+
hexToRgb: {
|
|
1070
|
+
value(hex) {
|
|
1071
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
1072
|
+
if (!matches) return [
|
|
1073
|
+
0,
|
|
1074
|
+
0,
|
|
1075
|
+
0
|
|
1076
|
+
];
|
|
1077
|
+
let [colorString] = matches;
|
|
1078
|
+
if (colorString.length === 3) colorString = [...colorString].map((character) => character + character).join("");
|
|
1079
|
+
const integer = Number.parseInt(colorString, 16);
|
|
1080
|
+
return [
|
|
1081
|
+
integer >> 16 & 255,
|
|
1082
|
+
integer >> 8 & 255,
|
|
1083
|
+
integer & 255
|
|
1084
|
+
];
|
|
1085
|
+
},
|
|
1086
|
+
enumerable: false
|
|
1087
|
+
},
|
|
1088
|
+
hexToAnsi256: {
|
|
1089
|
+
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
1090
|
+
enumerable: false
|
|
1091
|
+
},
|
|
1092
|
+
ansi256ToAnsi: {
|
|
1093
|
+
value(code) {
|
|
1094
|
+
if (code < 8) return 30 + code;
|
|
1095
|
+
if (code < 16) return 90 + (code - 8);
|
|
1096
|
+
let red;
|
|
1097
|
+
let green;
|
|
1098
|
+
let blue;
|
|
1099
|
+
if (code >= 232) {
|
|
1100
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
1101
|
+
green = red;
|
|
1102
|
+
blue = red;
|
|
1103
|
+
} else {
|
|
1104
|
+
code -= 16;
|
|
1105
|
+
const remainder = code % 36;
|
|
1106
|
+
red = Math.floor(code / 36) / 5;
|
|
1107
|
+
green = Math.floor(remainder / 6) / 5;
|
|
1108
|
+
blue = remainder % 6 / 5;
|
|
1109
|
+
}
|
|
1110
|
+
const value = Math.max(red, green, blue) * 2;
|
|
1111
|
+
if (value === 0) return 30;
|
|
1112
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
1113
|
+
if (value === 2) result += 60;
|
|
1114
|
+
return result;
|
|
1115
|
+
},
|
|
1116
|
+
enumerable: false
|
|
1117
|
+
},
|
|
1118
|
+
rgbToAnsi: {
|
|
1119
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
1120
|
+
enumerable: false
|
|
1121
|
+
},
|
|
1122
|
+
hexToAnsi: {
|
|
1123
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
1124
|
+
enumerable: false
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
return styles;
|
|
1128
|
+
}
|
|
1129
|
+
const ansiStyles = assembleStyles();
|
|
1130
|
+
// ../../node_modules/.pnpm/wrap-ansi@10.0.2/node_modules/wrap-ansi/index.js
|
|
1131
|
+
const ANSI_ESCAPE = "\x1B";
|
|
1132
|
+
const ANSI_ESCAPE_BELL = "\x07";
|
|
1133
|
+
const C1_CSI = "";
|
|
1134
|
+
const ANSI_CSI$1 = "[";
|
|
1135
|
+
const ANSI_OSC$1 = "]";
|
|
1136
|
+
const ANSI_SGR_TERMINATOR$1 = "m";
|
|
1137
|
+
const ANSI_SGR_RESET = 0;
|
|
1138
|
+
const ANSI_SGR_RESET_FOREGROUND = 39;
|
|
1139
|
+
const ANSI_SGR_RESET_BACKGROUND = 49;
|
|
1140
|
+
const ANSI_SGR_RESET_UNDERLINE_COLOR = 59;
|
|
1141
|
+
const ANSI_SGR_FOREGROUND_EXTENDED = 38;
|
|
1142
|
+
const ANSI_SGR_BACKGROUND_EXTENDED = 48;
|
|
1143
|
+
const ANSI_SGR_UNDERLINE_COLOR_EXTENDED = 58;
|
|
1144
|
+
const ANSI_SGR_COLOR_MODE_RGB = 2;
|
|
1145
|
+
const ANSI_SGR_COLOR_MODE_256 = 5;
|
|
1146
|
+
const ANSI_ESCAPE_LINK = `${ANSI_OSC$1}8;`;
|
|
1147
|
+
const ESCAPES$1 = /* @__PURE__ */ new Set([ANSI_ESCAPE, C1_CSI]);
|
|
1148
|
+
const ESCAPE_CHARACTERS = [...ESCAPES$1].join("");
|
|
1149
|
+
const CSI_INTRODUCER = `(?:${ANSI_ESCAPE}\\${ANSI_CSI$1}|${C1_CSI})`;
|
|
1150
|
+
const CSI_PARAMETERS = "[0-?]*[ -/]*[@-~]";
|
|
1151
|
+
const SGR_PARAMETERS = `(?<sgr>[0-9;:]*)${ANSI_SGR_TERMINATOR$1}`;
|
|
1152
|
+
const OSC_STRING_TERMINATOR = `(?:${ANSI_ESCAPE_BELL}|${ANSI_ESCAPE}\\\\)`;
|
|
1153
|
+
const OSC_STRING_PAYLOAD = String.raw`[^\u0000-\u001F\u007F-\u009F]*`;
|
|
1154
|
+
const LINK_PARAMETERS = String.raw`8;(?<parameters>[^;\u0000-\u001F\u007F-\u009F]*);(?<uri>${OSC_STRING_PAYLOAD})${OSC_STRING_TERMINATOR}`;
|
|
1155
|
+
const OSC_STRING = `${OSC_STRING_PAYLOAD}${OSC_STRING_TERMINATOR}`;
|
|
1156
|
+
const ANSI_ESCAPE_REGEX = new RegExp(`${CSI_INTRODUCER}(?:${SGR_PARAMETERS}|${CSI_PARAMETERS})|${ANSI_ESCAPE}\\${ANSI_OSC$1}(?:${LINK_PARAMETERS}|${OSC_STRING})`, "y");
|
|
1157
|
+
const ANSI_SGR_MODIFIER_CLOSE_CODES = new Set(ansiStyles.codes.values());
|
|
1158
|
+
ANSI_SGR_MODIFIER_CLOSE_CODES.delete(ANSI_SGR_RESET);
|
|
1159
|
+
const segmenter = new Intl.Segmenter();
|
|
1160
|
+
const getStringWidth = (string) => stringWidth(string, { countAnsiEscapeCodes: true });
|
|
1161
|
+
const TAB_SIZE = 8;
|
|
1162
|
+
const ESCAPE_INTRODUCER_REGEX = new RegExp(`[${ESCAPE_CHARACTERS}]`, "g");
|
|
1163
|
+
const ROW_BOUNDARY_REGEX = new RegExp(`[\\n${ESCAPE_CHARACTERS}]`, "g");
|
|
1164
|
+
const ASCII_PRINTABLE_REGEX = /^[ -~]*$/;
|
|
1165
|
+
const wrapAnsiCode = (code) => `${ANSI_ESCAPE}${ANSI_CSI$1}${code}${ANSI_SGR_TERMINATOR$1}`;
|
|
1166
|
+
const wrapAnsiHyperlink = (url, parameters = "") => `${ANSI_ESCAPE}${ANSI_ESCAPE_LINK}${parameters};${url}${ANSI_ESCAPE_BELL}`;
|
|
1167
|
+
const matchAnsiEscape = (string, index) => {
|
|
1168
|
+
if (!ESCAPES$1.has(string[index])) return;
|
|
1169
|
+
ANSI_ESCAPE_REGEX.lastIndex = index;
|
|
1170
|
+
return ANSI_ESCAPE_REGEX.exec(string) ?? void 0;
|
|
1171
|
+
};
|
|
1172
|
+
const forEachSegment = (string, onPlainText, onEscape = () => {}) => {
|
|
1173
|
+
let plainStart = 0;
|
|
1174
|
+
let index = 0;
|
|
1175
|
+
while (index < string.length) {
|
|
1176
|
+
ESCAPE_INTRODUCER_REGEX.lastIndex = index;
|
|
1177
|
+
const introducer = ESCAPE_INTRODUCER_REGEX.exec(string);
|
|
1178
|
+
if (!introducer) break;
|
|
1179
|
+
const escape = matchAnsiEscape(string, introducer.index);
|
|
1180
|
+
if (!escape) {
|
|
1181
|
+
index = introducer.index + 1;
|
|
1182
|
+
continue;
|
|
1183
|
+
}
|
|
1184
|
+
if (introducer.index > plainStart) onPlainText(string.slice(plainStart, introducer.index));
|
|
1185
|
+
onEscape(escape[0]);
|
|
1186
|
+
index = introducer.index + escape[0].length;
|
|
1187
|
+
plainStart = index;
|
|
1188
|
+
}
|
|
1189
|
+
if (plainStart < string.length) onPlainText(string.slice(plainStart));
|
|
1190
|
+
};
|
|
1191
|
+
const getWidth = (string) => {
|
|
1192
|
+
let plainText = "";
|
|
1193
|
+
forEachSegment(string, (part) => {
|
|
1194
|
+
plainText += part;
|
|
1195
|
+
});
|
|
1196
|
+
return getStringWidth(plainText);
|
|
1197
|
+
};
|
|
1198
|
+
const getTokens = (string) => {
|
|
1199
|
+
const tokens = [];
|
|
1200
|
+
forEachSegment(string, (plainText) => {
|
|
1201
|
+
if (ASCII_PRINTABLE_REGEX.test(plainText)) {
|
|
1202
|
+
for (const character of plainText) tokens.push({
|
|
1203
|
+
value: character,
|
|
1204
|
+
width: 1
|
|
1205
|
+
});
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
for (const { segment } of segmenter.segment(plainText)) tokens.push({
|
|
1209
|
+
value: segment,
|
|
1210
|
+
width: getStringWidth(segment)
|
|
1211
|
+
});
|
|
1212
|
+
}, (escape) => {
|
|
1213
|
+
tokens.push({
|
|
1214
|
+
value: escape,
|
|
1215
|
+
width: 0
|
|
1216
|
+
});
|
|
1217
|
+
});
|
|
1218
|
+
return tokens;
|
|
1219
|
+
};
|
|
1220
|
+
const splitWords = (string) => {
|
|
1221
|
+
let currentWord = {
|
|
1222
|
+
value: "",
|
|
1223
|
+
plainText: ""
|
|
1224
|
+
};
|
|
1225
|
+
const words = [currentWord];
|
|
1226
|
+
forEachSegment(string, (plainText) => {
|
|
1227
|
+
const parts = plainText.split(" ");
|
|
1228
|
+
currentWord.value += parts[0];
|
|
1229
|
+
currentWord.plainText += parts[0];
|
|
1230
|
+
for (let index = 1; index < parts.length; index++) {
|
|
1231
|
+
currentWord = {
|
|
1232
|
+
value: parts[index],
|
|
1233
|
+
plainText: parts[index]
|
|
1234
|
+
};
|
|
1235
|
+
words.push(currentWord);
|
|
1236
|
+
}
|
|
1237
|
+
}, (escape) => {
|
|
1238
|
+
currentWord.value += escape;
|
|
1239
|
+
});
|
|
1240
|
+
for (const word of words) word.width = getStringWidth(word.plainText);
|
|
1241
|
+
return words;
|
|
1242
|
+
};
|
|
1243
|
+
const getColonColorToken = (parameter) => {
|
|
1244
|
+
const parts = parameter.split(":");
|
|
1245
|
+
const code = Number.parseInt(parts[0], 10);
|
|
1246
|
+
const mode = Number.parseInt(parts[1], 10);
|
|
1247
|
+
if (![
|
|
1248
|
+
ANSI_SGR_FOREGROUND_EXTENDED,
|
|
1249
|
+
ANSI_SGR_BACKGROUND_EXTENDED,
|
|
1250
|
+
ANSI_SGR_UNDERLINE_COLOR_EXTENDED
|
|
1251
|
+
].includes(code)) return;
|
|
1252
|
+
if (mode === ANSI_SGR_COLOR_MODE_256 && parts.length === 3 && /^\d+$/.test(parts[2])) return {
|
|
1253
|
+
code,
|
|
1254
|
+
open: parameter,
|
|
1255
|
+
hasArguments: true
|
|
1256
|
+
};
|
|
1257
|
+
if (mode !== ANSI_SGR_COLOR_MODE_RGB) return;
|
|
1258
|
+
const components = parts.length === 6 ? parts.slice(3) : parts.slice(2);
|
|
1259
|
+
const colorSpace = parts.length === 6 ? parts[2] : void 0;
|
|
1260
|
+
if (components.length === 3 && components.every((component) => /^\d+$/.test(component)) && (colorSpace === void 0 || /^\d*$/.test(colorSpace))) return {
|
|
1261
|
+
code,
|
|
1262
|
+
open: parameter,
|
|
1263
|
+
hasArguments: true
|
|
1264
|
+
};
|
|
1265
|
+
};
|
|
1266
|
+
const getSgrTokens = (sgrParameters) => {
|
|
1267
|
+
const parameters = sgrParameters.split(";");
|
|
1268
|
+
const sgrTokens = [];
|
|
1269
|
+
for (let index = 0; index < parameters.length; index++) {
|
|
1270
|
+
const parameter = parameters[index];
|
|
1271
|
+
if (parameter.includes(":")) {
|
|
1272
|
+
const colonColorToken = getColonColorToken(parameter);
|
|
1273
|
+
if (colonColorToken) sgrTokens.push(colonColorToken);
|
|
1274
|
+
continue;
|
|
1275
|
+
}
|
|
1276
|
+
const code = parameter === "" ? ANSI_SGR_RESET : Number.parseInt(parameter, 10);
|
|
1277
|
+
if (!Number.isFinite(code)) continue;
|
|
1278
|
+
if (code === ANSI_SGR_FOREGROUND_EXTENDED || code === ANSI_SGR_BACKGROUND_EXTENDED || code === ANSI_SGR_UNDERLINE_COLOR_EXTENDED) {
|
|
1279
|
+
if (index + 1 >= parameters.length) break;
|
|
1280
|
+
const mode = Number.parseInt(parameters[index + 1], 10);
|
|
1281
|
+
const colorIndex = Number.parseInt(parameters[index + 2], 10);
|
|
1282
|
+
if (mode === ANSI_SGR_COLOR_MODE_256 && Number.isFinite(colorIndex)) {
|
|
1283
|
+
sgrTokens.push({
|
|
1284
|
+
code,
|
|
1285
|
+
open: [
|
|
1286
|
+
code,
|
|
1287
|
+
mode,
|
|
1288
|
+
colorIndex
|
|
1289
|
+
].join(";"),
|
|
1290
|
+
hasArguments: true
|
|
1291
|
+
});
|
|
1292
|
+
index += 2;
|
|
1293
|
+
continue;
|
|
1294
|
+
}
|
|
1295
|
+
const red = Number.parseInt(parameters[index + 2], 10);
|
|
1296
|
+
const green = Number.parseInt(parameters[index + 3], 10);
|
|
1297
|
+
const blue = Number.parseInt(parameters[index + 4], 10);
|
|
1298
|
+
if (mode === ANSI_SGR_COLOR_MODE_RGB && Number.isFinite(red) && Number.isFinite(green) && Number.isFinite(blue)) {
|
|
1299
|
+
sgrTokens.push({
|
|
1300
|
+
code,
|
|
1301
|
+
open: [
|
|
1302
|
+
code,
|
|
1303
|
+
mode,
|
|
1304
|
+
red,
|
|
1305
|
+
green,
|
|
1306
|
+
blue
|
|
1307
|
+
].join(";"),
|
|
1308
|
+
hasArguments: true
|
|
1309
|
+
});
|
|
1310
|
+
index += 4;
|
|
1311
|
+
continue;
|
|
1312
|
+
}
|
|
1313
|
+
break;
|
|
1314
|
+
}
|
|
1315
|
+
sgrTokens.push({
|
|
1316
|
+
code,
|
|
1317
|
+
open: String(code),
|
|
1318
|
+
hasArguments: false
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
return sgrTokens;
|
|
1322
|
+
};
|
|
1323
|
+
const removeActiveStyle = (activeStyles, family) => {
|
|
1324
|
+
const activeStyleIndex = activeStyles.findIndex((activeStyle) => activeStyle.family === family);
|
|
1325
|
+
if (activeStyleIndex !== -1) activeStyles.splice(activeStyleIndex, 1);
|
|
1326
|
+
};
|
|
1327
|
+
const upsertActiveStyle = (activeStyles, nextActiveStyle) => {
|
|
1328
|
+
removeActiveStyle(activeStyles, nextActiveStyle.family);
|
|
1329
|
+
activeStyles.push(nextActiveStyle);
|
|
1330
|
+
};
|
|
1331
|
+
const removeModifierStylesByClose = (activeStyles, closeCode) => {
|
|
1332
|
+
for (let index = activeStyles.length - 1; index >= 0; index--) {
|
|
1333
|
+
const activeStyle = activeStyles[index];
|
|
1334
|
+
if (activeStyle.family.startsWith("modifier-") && activeStyle.close === closeCode) activeStyles.splice(index, 1);
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
const getColorStyle = (sgrToken) => {
|
|
1338
|
+
const { code, open, hasArguments } = sgrToken;
|
|
1339
|
+
if (code >= 30 && code <= 37 || code >= 90 && code <= 97 || code === ANSI_SGR_FOREGROUND_EXTENDED && hasArguments) return {
|
|
1340
|
+
family: "foreground",
|
|
1341
|
+
open,
|
|
1342
|
+
close: ANSI_SGR_RESET_FOREGROUND
|
|
1343
|
+
};
|
|
1344
|
+
if (code >= 40 && code <= 47 || code >= 100 && code <= 107 || code === ANSI_SGR_BACKGROUND_EXTENDED && hasArguments) return {
|
|
1345
|
+
family: "background",
|
|
1346
|
+
open,
|
|
1347
|
+
close: ANSI_SGR_RESET_BACKGROUND
|
|
1348
|
+
};
|
|
1349
|
+
if (code === ANSI_SGR_UNDERLINE_COLOR_EXTENDED && hasArguments) return {
|
|
1350
|
+
family: "underlineColor",
|
|
1351
|
+
open,
|
|
1352
|
+
close: ANSI_SGR_RESET_UNDERLINE_COLOR
|
|
1353
|
+
};
|
|
1354
|
+
};
|
|
1355
|
+
const applySgrResetCode = (code, activeStyles) => {
|
|
1356
|
+
if (code === ANSI_SGR_RESET) {
|
|
1357
|
+
activeStyles.length = 0;
|
|
1358
|
+
return true;
|
|
1359
|
+
}
|
|
1360
|
+
if (code === ANSI_SGR_RESET_FOREGROUND) {
|
|
1361
|
+
removeActiveStyle(activeStyles, "foreground");
|
|
1362
|
+
return true;
|
|
1363
|
+
}
|
|
1364
|
+
if (code === ANSI_SGR_RESET_BACKGROUND) {
|
|
1365
|
+
removeActiveStyle(activeStyles, "background");
|
|
1366
|
+
return true;
|
|
1367
|
+
}
|
|
1368
|
+
if (code === ANSI_SGR_RESET_UNDERLINE_COLOR) {
|
|
1369
|
+
removeActiveStyle(activeStyles, "underlineColor");
|
|
1370
|
+
return true;
|
|
1371
|
+
}
|
|
1372
|
+
if (ANSI_SGR_MODIFIER_CLOSE_CODES.has(code)) {
|
|
1373
|
+
removeModifierStylesByClose(activeStyles, code);
|
|
1374
|
+
return true;
|
|
1375
|
+
}
|
|
1376
|
+
return false;
|
|
1377
|
+
};
|
|
1378
|
+
const applySgrToken$1 = (sgrToken, activeStyles) => {
|
|
1379
|
+
const { code } = sgrToken;
|
|
1380
|
+
if (applySgrResetCode(code, activeStyles)) return;
|
|
1381
|
+
const colorStyle = getColorStyle(sgrToken);
|
|
1382
|
+
if (colorStyle) {
|
|
1383
|
+
upsertActiveStyle(activeStyles, colorStyle);
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
const close = ansiStyles.codes.get(code);
|
|
1387
|
+
if (close !== void 0 && close !== ANSI_SGR_RESET) upsertActiveStyle(activeStyles, {
|
|
1388
|
+
family: `modifier-${code}`,
|
|
1389
|
+
open: sgrToken.open,
|
|
1390
|
+
close
|
|
1391
|
+
});
|
|
1392
|
+
};
|
|
1393
|
+
const applySgrParameters = (sgrParameters, activeStyles) => {
|
|
1394
|
+
for (const sgrToken of getSgrTokens(sgrParameters)) applySgrToken$1(sgrToken, activeStyles);
|
|
1395
|
+
};
|
|
1396
|
+
const applySgrResets = (sgrParameters, activeStyles) => {
|
|
1397
|
+
for (const { code } of getSgrTokens(sgrParameters)) applySgrResetCode(code, activeStyles);
|
|
1398
|
+
};
|
|
1399
|
+
const applyLeadingSgrResets = (string, startIndex, activeStyles) => {
|
|
1400
|
+
let index = startIndex;
|
|
1401
|
+
while (index < string.length) {
|
|
1402
|
+
const match = matchAnsiEscape(string, index);
|
|
1403
|
+
if (!match) break;
|
|
1404
|
+
if (match.groups.sgr !== void 0) applySgrResets(match.groups.sgr, activeStyles);
|
|
1405
|
+
index += match[0].length;
|
|
1406
|
+
}
|
|
1407
|
+
};
|
|
1408
|
+
const getClosingSgrSequence = (activeStyles) => [...activeStyles].reverse().map((activeStyle) => wrapAnsiCode(activeStyle.close)).join("");
|
|
1409
|
+
const getOpeningSgrSequence = (activeStyles) => activeStyles.map((activeStyle) => wrapAnsiCode(activeStyle.open)).join("");
|
|
1410
|
+
const wrapWord = (rows, word, columns, rowWidth) => {
|
|
1411
|
+
const tokens = getTokens(word);
|
|
1412
|
+
let visible = rowWidth;
|
|
1413
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
1414
|
+
const token = tokens[index];
|
|
1415
|
+
if (token.width > 0 && visible > 0 && visible + token.width > columns) {
|
|
1416
|
+
rows.push("");
|
|
1417
|
+
visible = 0;
|
|
1418
|
+
}
|
|
1419
|
+
rows[rows.length - 1] += token.value;
|
|
1420
|
+
visible += token.width;
|
|
1421
|
+
if (visible === columns && index < tokens.length - 1) {
|
|
1422
|
+
rows.push("");
|
|
1423
|
+
visible = 0;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
if (!visible && rows.at(-1).length > 0 && rows.length > 1) rows[rows.length - 2] += rows.pop();
|
|
1427
|
+
return getWidth(rows.at(-1));
|
|
1428
|
+
};
|
|
1429
|
+
const stringVisibleTrimSpacesRight = (string) => {
|
|
1430
|
+
if (!string.includes(" ")) return string;
|
|
1431
|
+
const segments = [];
|
|
1432
|
+
forEachSegment(string, (plainText) => {
|
|
1433
|
+
segments.push({
|
|
1434
|
+
value: plainText,
|
|
1435
|
+
isEscape: false
|
|
1436
|
+
});
|
|
1437
|
+
}, (escape) => {
|
|
1438
|
+
segments.push({
|
|
1439
|
+
value: escape,
|
|
1440
|
+
isEscape: true
|
|
1441
|
+
});
|
|
1442
|
+
});
|
|
1443
|
+
for (let index = segments.length - 1; index >= 0; index--) {
|
|
1444
|
+
const segment = segments[index];
|
|
1445
|
+
if (segment.isEscape) continue;
|
|
1446
|
+
let end = segment.value.length;
|
|
1447
|
+
while (end > 0 && segment.value[end - 1] === " ") end--;
|
|
1448
|
+
segment.value = segment.value.slice(0, end);
|
|
1449
|
+
if (getStringWidth(segment.value) > 0) break;
|
|
1450
|
+
}
|
|
1451
|
+
return segments.map((segment) => segment.value).join("");
|
|
1452
|
+
};
|
|
1453
|
+
const expandTabs = (line) => {
|
|
1454
|
+
if (!line.includes(" ")) return line;
|
|
1455
|
+
let visible = 0;
|
|
1456
|
+
let expandedLine = "";
|
|
1457
|
+
let plainTextSinceTab = "";
|
|
1458
|
+
const expandPlainText = (plainText) => {
|
|
1459
|
+
const segments = plainText.split(" ");
|
|
1460
|
+
for (const [index, segment] of segments.entries()) {
|
|
1461
|
+
expandedLine += segment;
|
|
1462
|
+
plainTextSinceTab += segment;
|
|
1463
|
+
if (index < segments.length - 1) {
|
|
1464
|
+
visible += getStringWidth(plainTextSinceTab);
|
|
1465
|
+
plainTextSinceTab = "";
|
|
1466
|
+
const spaces = TAB_SIZE - visible % TAB_SIZE;
|
|
1467
|
+
expandedLine += " ".repeat(spaces);
|
|
1468
|
+
visible += spaces;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
};
|
|
1472
|
+
forEachSegment(line, expandPlainText, (escape) => {
|
|
1473
|
+
expandedLine += escape;
|
|
1474
|
+
});
|
|
1475
|
+
return expandedLine;
|
|
1476
|
+
};
|
|
1477
|
+
const restoreStylesAcrossRows = (preString) => {
|
|
1478
|
+
let returnValue = "";
|
|
1479
|
+
let activeHyperlink;
|
|
1480
|
+
const activeStyles = [];
|
|
1481
|
+
let index = 0;
|
|
1482
|
+
let copiedIndex = 0;
|
|
1483
|
+
while (index < preString.length) {
|
|
1484
|
+
ROW_BOUNDARY_REGEX.lastIndex = index;
|
|
1485
|
+
const boundary = ROW_BOUNDARY_REGEX.exec(preString);
|
|
1486
|
+
if (!boundary) break;
|
|
1487
|
+
index = boundary.index;
|
|
1488
|
+
if (boundary[0] !== "\n") {
|
|
1489
|
+
const escape = matchAnsiEscape(preString, index);
|
|
1490
|
+
if (!escape) {
|
|
1491
|
+
index++;
|
|
1492
|
+
continue;
|
|
1493
|
+
}
|
|
1494
|
+
const { groups } = escape;
|
|
1495
|
+
if (groups.sgr !== void 0) applySgrParameters(groups.sgr, activeStyles);
|
|
1496
|
+
else if (groups.uri !== void 0) activeHyperlink = groups.uri.length === 0 ? void 0 : {
|
|
1497
|
+
parameters: groups.parameters,
|
|
1498
|
+
uri: groups.uri
|
|
1499
|
+
};
|
|
1500
|
+
index += escape[0].length;
|
|
1501
|
+
continue;
|
|
1502
|
+
}
|
|
1503
|
+
returnValue += preString.slice(copiedIndex, index);
|
|
1504
|
+
if (index > copiedIndex) {
|
|
1505
|
+
if (activeHyperlink) returnValue += wrapAnsiHyperlink("");
|
|
1506
|
+
returnValue += getClosingSgrSequence(activeStyles);
|
|
1507
|
+
}
|
|
1508
|
+
returnValue += "\n";
|
|
1509
|
+
index++;
|
|
1510
|
+
copiedIndex = index;
|
|
1511
|
+
if (index < preString.length && preString[index] !== "\n") {
|
|
1512
|
+
const openingStyles = [...activeStyles];
|
|
1513
|
+
applyLeadingSgrResets(preString, index, openingStyles);
|
|
1514
|
+
returnValue += getOpeningSgrSequence(openingStyles);
|
|
1515
|
+
if (activeHyperlink) returnValue += wrapAnsiHyperlink(activeHyperlink.uri, activeHyperlink.parameters);
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
return returnValue + preString.slice(copiedIndex);
|
|
1519
|
+
};
|
|
1520
|
+
const exec = (string, columns, options = {}) => {
|
|
1521
|
+
if (options.trim !== false && string.trim() === "") return "";
|
|
1522
|
+
const words = splitWords(string);
|
|
1523
|
+
let rows = [""];
|
|
1524
|
+
let rowLength = 0;
|
|
1525
|
+
let trimmedRowIndex = -1;
|
|
1526
|
+
let isFirstWord = true;
|
|
1527
|
+
for (const word of words) {
|
|
1528
|
+
const rowIndex = rows.length - 1;
|
|
1529
|
+
if (options.trim !== false && trimmedRowIndex !== rowIndex) {
|
|
1530
|
+
const row = rows[rowIndex];
|
|
1531
|
+
const trimmedRow = row.trimStart();
|
|
1532
|
+
if (trimmedRow.length !== row.length) {
|
|
1533
|
+
rows[rowIndex] = trimmedRow;
|
|
1534
|
+
rowLength = getWidth(trimmedRow);
|
|
1535
|
+
}
|
|
1536
|
+
if (trimmedRow.length > 0) trimmedRowIndex = rowIndex;
|
|
1537
|
+
}
|
|
1538
|
+
if (isFirstWord) isFirstWord = false;
|
|
1539
|
+
else {
|
|
1540
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
1541
|
+
rows.push("");
|
|
1542
|
+
rowLength = 0;
|
|
1543
|
+
}
|
|
1544
|
+
if (rowLength > 0 || options.trim === false) {
|
|
1545
|
+
rows[rows.length - 1] += " ";
|
|
1546
|
+
rowLength++;
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
if (options.hard && options.wordWrap !== false && word.width > columns) {
|
|
1550
|
+
const remainingColumns = columns - rowLength;
|
|
1551
|
+
const breaksStartingThisLine = 1 + Math.floor((word.width - remainingColumns - 1) / columns);
|
|
1552
|
+
if (Math.floor((word.width - 1) / columns) < breaksStartingThisLine) {
|
|
1553
|
+
rows.push("");
|
|
1554
|
+
rowLength = 0;
|
|
1555
|
+
}
|
|
1556
|
+
rowLength = wrapWord(rows, word.value, columns, rowLength);
|
|
1557
|
+
continue;
|
|
1558
|
+
}
|
|
1559
|
+
if (rowLength + word.width > columns && rowLength > 0 && word.width > 0) {
|
|
1560
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
1561
|
+
rowLength = wrapWord(rows, word.value, columns, rowLength);
|
|
1562
|
+
continue;
|
|
1563
|
+
}
|
|
1564
|
+
rows.push("");
|
|
1565
|
+
rowLength = 0;
|
|
1566
|
+
}
|
|
1567
|
+
if (rowLength + word.width > columns && options.wordWrap === false) {
|
|
1568
|
+
rowLength = wrapWord(rows, word.value, columns, rowLength);
|
|
1569
|
+
continue;
|
|
1570
|
+
}
|
|
1571
|
+
rows[rows.length - 1] += word.value;
|
|
1572
|
+
rowLength += word.width;
|
|
1573
|
+
}
|
|
1574
|
+
if (options.trim !== false) rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
1575
|
+
return restoreStylesAcrossRows(rows.join("\n"));
|
|
1576
|
+
};
|
|
1577
|
+
const normalizeText = (string) => {
|
|
1578
|
+
let normalizedString = "";
|
|
1579
|
+
forEachSegment(string, (plainText) => {
|
|
1580
|
+
normalizedString += plainText.normalize();
|
|
1581
|
+
}, (escape) => {
|
|
1582
|
+
normalizedString += escape;
|
|
1583
|
+
});
|
|
1584
|
+
return normalizedString;
|
|
1585
|
+
};
|
|
1586
|
+
function wrapAnsi(string, columns, options) {
|
|
1587
|
+
return normalizeText(String(string)).replaceAll("\r\n", "\n").split("\n").map((line) => exec(expandTabs(line), columns, options)).join("\n");
|
|
1588
|
+
}
|
|
1589
|
+
// ../../node_modules/.pnpm/is-fullwidth-code-point@5.1.0/node_modules/is-fullwidth-code-point/index.js
|
|
1590
|
+
function isFullwidthCodePoint(codePoint) {
|
|
1591
|
+
if (!Number.isInteger(codePoint)) return false;
|
|
1592
|
+
return isFullwidth(codePoint) || isWide(codePoint);
|
|
1593
|
+
}
|
|
1594
|
+
// ../../node_modules/.pnpm/slice-ansi@9.0.1/node_modules/slice-ansi/tokenize-ansi.js
|
|
1595
|
+
const ESCAPE_CODE_POINT = 27;
|
|
1596
|
+
const C1_DCS_CODE_POINT = 144;
|
|
1597
|
+
const C1_SOS_CODE_POINT = 152;
|
|
1598
|
+
const C1_CSI_CODE_POINT = 155;
|
|
1599
|
+
const C1_ST_CODE_POINT = 156;
|
|
1600
|
+
const C1_OSC_CODE_POINT = 157;
|
|
1601
|
+
const C1_PM_CODE_POINT = 158;
|
|
1602
|
+
const C1_APC_CODE_POINT = 159;
|
|
1603
|
+
const ESCAPES = /* @__PURE__ */ new Set([
|
|
1604
|
+
ESCAPE_CODE_POINT,
|
|
1605
|
+
C1_DCS_CODE_POINT,
|
|
1606
|
+
C1_SOS_CODE_POINT,
|
|
1607
|
+
C1_CSI_CODE_POINT,
|
|
1608
|
+
C1_ST_CODE_POINT,
|
|
1609
|
+
C1_OSC_CODE_POINT,
|
|
1610
|
+
C1_PM_CODE_POINT,
|
|
1611
|
+
C1_APC_CODE_POINT
|
|
1612
|
+
]);
|
|
1613
|
+
const ESCAPE = "\x1B";
|
|
1614
|
+
const ANSI_BELL = "\x07";
|
|
1615
|
+
const ANSI_CSI = "[";
|
|
1616
|
+
const ANSI_OSC = "]";
|
|
1617
|
+
const ANSI_DCS = "P";
|
|
1618
|
+
const ANSI_SOS = "X";
|
|
1619
|
+
const ANSI_PM = "^";
|
|
1620
|
+
const ANSI_APC = "_";
|
|
1621
|
+
const ANSI_SGR_TERMINATOR = "m";
|
|
1622
|
+
const ANSI_OSC_TERMINATOR = "\\";
|
|
1623
|
+
const ANSI_STRING_TERMINATOR = `${ESCAPE}${ANSI_OSC_TERMINATOR}`;
|
|
1624
|
+
const C1_OSC = "";
|
|
1625
|
+
const C1_STRING_TERMINATOR = "";
|
|
1626
|
+
const ANSI_HYPERLINK_ESC_PREFIX = `${ESCAPE}${ANSI_OSC}8;`;
|
|
1627
|
+
const ANSI_HYPERLINK_C1_PREFIX = `${C1_OSC}8;`;
|
|
1628
|
+
const ANSI_HYPERLINK_ESC_CLOSE = `${ANSI_HYPERLINK_ESC_PREFIX};`;
|
|
1629
|
+
const ANSI_HYPERLINK_C1_CLOSE = `${ANSI_HYPERLINK_C1_PREFIX};`;
|
|
1630
|
+
const CODE_POINT_0 = "0".codePointAt(0);
|
|
1631
|
+
const CODE_POINT_9 = "9".codePointAt(0);
|
|
1632
|
+
const CODE_POINT_SEMICOLON = ";".codePointAt(0);
|
|
1633
|
+
const CODE_POINT_COLON = ":".codePointAt(0);
|
|
1634
|
+
const CODE_POINT_CSI_PARAMETER_START = "0".codePointAt(0);
|
|
1635
|
+
const CODE_POINT_CSI_PARAMETER_END = "?".codePointAt(0);
|
|
1636
|
+
const CODE_POINT_CSI_INTERMEDIATE_START = " ".codePointAt(0);
|
|
1637
|
+
const CODE_POINT_CSI_INTERMEDIATE_END = "/".codePointAt(0);
|
|
1638
|
+
const CODE_POINT_CSI_FINAL_START = "@".codePointAt(0);
|
|
1639
|
+
const CODE_POINT_CSI_FINAL_END = "~".codePointAt(0);
|
|
1640
|
+
const REGIONAL_INDICATOR_SYMBOL_LETTER_A = 127462;
|
|
1641
|
+
const REGIONAL_INDICATOR_SYMBOL_LETTER_Z = 127487;
|
|
1642
|
+
const SGR_RESET_CODE = 0;
|
|
1643
|
+
const SGR_EXTENDED_FOREGROUND_CODE = 38;
|
|
1644
|
+
const SGR_DEFAULT_FOREGROUND_CODE = 39;
|
|
1645
|
+
const SGR_EXTENDED_BACKGROUND_CODE = 48;
|
|
1646
|
+
const SGR_DEFAULT_BACKGROUND_CODE = 49;
|
|
1647
|
+
const SGR_COLOR_TYPE_ANSI_256 = 5;
|
|
1648
|
+
const SGR_COLOR_TYPE_TRUECOLOR = 2;
|
|
1649
|
+
const SGR_ANSI_256_FRAGMENT_LENGTH = 3;
|
|
1650
|
+
const SGR_TRUECOLOR_FRAGMENT_LENGTH = 5;
|
|
1651
|
+
const SGR_ANSI_256_LAST_PARAMETER_OFFSET = 2;
|
|
1652
|
+
const SGR_TRUECOLOR_LAST_PARAMETER_OFFSET = 4;
|
|
1653
|
+
const VARIATION_SELECTOR_16_CODE_POINT = 65039;
|
|
1654
|
+
const COMBINING_ENCLOSING_KEYCAP_CODE_POINT = 8419;
|
|
1655
|
+
const EMOJI_PRESENTATION_GRAPHEME_REGEX = /\p{Emoji_Presentation}/v;
|
|
1656
|
+
const GRAPHEME_SEGMENTER = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
1657
|
+
const endCodeNumbers = /* @__PURE__ */ new Set();
|
|
1658
|
+
for (const [, end] of ansiStyles.codes) endCodeNumbers.add(end);
|
|
1659
|
+
function isSgrParameterCharacter(codePoint) {
|
|
1660
|
+
return codePoint >= CODE_POINT_0 && codePoint <= CODE_POINT_9 || codePoint === CODE_POINT_SEMICOLON || codePoint === CODE_POINT_COLON;
|
|
1661
|
+
}
|
|
1662
|
+
function isCsiParameterCharacter(codePoint) {
|
|
1663
|
+
return codePoint >= CODE_POINT_CSI_PARAMETER_START && codePoint <= CODE_POINT_CSI_PARAMETER_END;
|
|
1664
|
+
}
|
|
1665
|
+
function isCsiIntermediateCharacter(codePoint) {
|
|
1666
|
+
return codePoint >= CODE_POINT_CSI_INTERMEDIATE_START && codePoint <= CODE_POINT_CSI_INTERMEDIATE_END;
|
|
1667
|
+
}
|
|
1668
|
+
function isCsiFinalCharacter(codePoint) {
|
|
1669
|
+
return codePoint >= CODE_POINT_CSI_FINAL_START && codePoint <= CODE_POINT_CSI_FINAL_END;
|
|
1670
|
+
}
|
|
1671
|
+
function isRegionalIndicatorCodePoint(codePoint) {
|
|
1672
|
+
return codePoint >= REGIONAL_INDICATOR_SYMBOL_LETTER_A && codePoint <= REGIONAL_INDICATOR_SYMBOL_LETTER_Z;
|
|
1673
|
+
}
|
|
1674
|
+
function createControlParseResult(code, endIndex) {
|
|
1675
|
+
return {
|
|
1676
|
+
token: {
|
|
1677
|
+
type: "control",
|
|
1678
|
+
code
|
|
1679
|
+
},
|
|
1680
|
+
endIndex
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
function isEmojiStyleGrapheme(grapheme) {
|
|
1684
|
+
if (EMOJI_PRESENTATION_GRAPHEME_REGEX.test(grapheme)) return true;
|
|
1685
|
+
for (const character of grapheme) {
|
|
1686
|
+
const codePoint = character.codePointAt(0);
|
|
1687
|
+
if (codePoint === VARIATION_SELECTOR_16_CODE_POINT || codePoint === COMBINING_ENCLOSING_KEYCAP_CODE_POINT) return true;
|
|
1688
|
+
}
|
|
1689
|
+
return false;
|
|
1690
|
+
}
|
|
1691
|
+
function getGraphemeWidth(grapheme) {
|
|
1692
|
+
let regionalIndicatorCount = 0;
|
|
1693
|
+
for (const character of grapheme) {
|
|
1694
|
+
const codePoint = character.codePointAt(0);
|
|
1695
|
+
if (isFullwidthCodePoint(codePoint)) return 2;
|
|
1696
|
+
if (isRegionalIndicatorCodePoint(codePoint)) regionalIndicatorCount++;
|
|
1697
|
+
}
|
|
1698
|
+
if (regionalIndicatorCount >= 1) return 2;
|
|
1699
|
+
if (isEmojiStyleGrapheme(grapheme)) return 2;
|
|
1700
|
+
return 1;
|
|
1701
|
+
}
|
|
1702
|
+
function getSgrPrefix(code) {
|
|
1703
|
+
if (code.startsWith("")) return "";
|
|
1704
|
+
return `${ESCAPE}${ANSI_CSI}`;
|
|
1705
|
+
}
|
|
1706
|
+
function createSgrCode(prefix, values) {
|
|
1707
|
+
return `${prefix}${values.join(";")}${ANSI_SGR_TERMINATOR}`;
|
|
1708
|
+
}
|
|
1709
|
+
function getSgrFragments(code) {
|
|
1710
|
+
const fragments = [];
|
|
1711
|
+
const sgrPrefix = getSgrPrefix(code);
|
|
1712
|
+
let parameterString;
|
|
1713
|
+
if (code.startsWith(`${ESCAPE}${ANSI_CSI}`)) parameterString = code.slice(2, -1);
|
|
1714
|
+
else if (code.startsWith("")) parameterString = code.slice(1, -1);
|
|
1715
|
+
else return fragments;
|
|
1716
|
+
const rawCodes = parameterString.length === 0 ? [String(SGR_RESET_CODE)] : parameterString.split(";");
|
|
1717
|
+
let index = 0;
|
|
1718
|
+
while (index < rawCodes.length) {
|
|
1719
|
+
const codeNumber = Number.parseInt(rawCodes[index], 10);
|
|
1720
|
+
if (Number.isNaN(codeNumber)) {
|
|
1721
|
+
index++;
|
|
1722
|
+
continue;
|
|
1723
|
+
}
|
|
1724
|
+
if (codeNumber === SGR_RESET_CODE) {
|
|
1725
|
+
fragments.push({ type: "reset" });
|
|
1726
|
+
index++;
|
|
1727
|
+
continue;
|
|
1728
|
+
}
|
|
1729
|
+
if (codeNumber === SGR_EXTENDED_FOREGROUND_CODE || codeNumber === SGR_EXTENDED_BACKGROUND_CODE) {
|
|
1730
|
+
const colorType = Number.parseInt(rawCodes[index + 1], 10);
|
|
1731
|
+
if (colorType === SGR_COLOR_TYPE_ANSI_256 && index + SGR_ANSI_256_LAST_PARAMETER_OFFSET < rawCodes.length) {
|
|
1732
|
+
const openCode = createSgrCode(sgrPrefix, rawCodes.slice(index, index + SGR_ANSI_256_FRAGMENT_LENGTH));
|
|
1733
|
+
fragments.push({
|
|
1734
|
+
type: "start",
|
|
1735
|
+
code: openCode,
|
|
1736
|
+
endCode: ansiStyles.color.ansi(codeNumber === SGR_EXTENDED_FOREGROUND_CODE ? SGR_DEFAULT_FOREGROUND_CODE : SGR_DEFAULT_BACKGROUND_CODE)
|
|
1737
|
+
});
|
|
1738
|
+
index += SGR_ANSI_256_FRAGMENT_LENGTH;
|
|
1739
|
+
continue;
|
|
1740
|
+
}
|
|
1741
|
+
if (colorType === SGR_COLOR_TYPE_TRUECOLOR && index + SGR_TRUECOLOR_LAST_PARAMETER_OFFSET < rawCodes.length) {
|
|
1742
|
+
const openCode = createSgrCode(sgrPrefix, rawCodes.slice(index, index + SGR_TRUECOLOR_FRAGMENT_LENGTH));
|
|
1743
|
+
fragments.push({
|
|
1744
|
+
type: "start",
|
|
1745
|
+
code: openCode,
|
|
1746
|
+
endCode: ansiStyles.color.ansi(codeNumber === SGR_EXTENDED_FOREGROUND_CODE ? SGR_DEFAULT_FOREGROUND_CODE : SGR_DEFAULT_BACKGROUND_CODE)
|
|
1747
|
+
});
|
|
1748
|
+
index += SGR_TRUECOLOR_FRAGMENT_LENGTH;
|
|
1749
|
+
continue;
|
|
1750
|
+
}
|
|
1751
|
+
const openCode = createSgrCode(sgrPrefix, [rawCodes[index]]);
|
|
1752
|
+
fragments.push({
|
|
1753
|
+
type: "start",
|
|
1754
|
+
code: openCode,
|
|
1755
|
+
endCode: ansiStyles.color.ansi(codeNumber === SGR_EXTENDED_FOREGROUND_CODE ? SGR_DEFAULT_FOREGROUND_CODE : SGR_DEFAULT_BACKGROUND_CODE)
|
|
1756
|
+
});
|
|
1757
|
+
index++;
|
|
1758
|
+
continue;
|
|
1759
|
+
}
|
|
1760
|
+
if (endCodeNumbers.has(codeNumber)) {
|
|
1761
|
+
fragments.push({
|
|
1762
|
+
type: "end",
|
|
1763
|
+
endCode: ansiStyles.color.ansi(codeNumber)
|
|
1764
|
+
});
|
|
1765
|
+
index++;
|
|
1766
|
+
continue;
|
|
1767
|
+
}
|
|
1768
|
+
const mappedEndCode = ansiStyles.codes.get(codeNumber);
|
|
1769
|
+
if (mappedEndCode !== void 0) {
|
|
1770
|
+
const openCode = createSgrCode(sgrPrefix, [rawCodes[index]]);
|
|
1771
|
+
fragments.push({
|
|
1772
|
+
type: "start",
|
|
1773
|
+
code: openCode,
|
|
1774
|
+
endCode: ansiStyles.color.ansi(mappedEndCode)
|
|
1775
|
+
});
|
|
1776
|
+
index++;
|
|
1777
|
+
continue;
|
|
1778
|
+
}
|
|
1779
|
+
const openCode = createSgrCode(sgrPrefix, [rawCodes[index]]);
|
|
1780
|
+
fragments.push({
|
|
1781
|
+
type: "start",
|
|
1782
|
+
code: openCode,
|
|
1783
|
+
endCode: ansiStyles.reset.open
|
|
1784
|
+
});
|
|
1785
|
+
index++;
|
|
1786
|
+
}
|
|
1787
|
+
if (fragments.length === 0) fragments.push({ type: "reset" });
|
|
1788
|
+
return fragments;
|
|
1789
|
+
}
|
|
1790
|
+
function parseCsiCode(string, index) {
|
|
1791
|
+
const escapeCodePoint = string.codePointAt(index);
|
|
1792
|
+
let sequenceStartIndex;
|
|
1793
|
+
if (escapeCodePoint === ESCAPE_CODE_POINT) {
|
|
1794
|
+
if (string[index + 1] !== ANSI_CSI) return;
|
|
1795
|
+
sequenceStartIndex = index + 2;
|
|
1796
|
+
} else if (escapeCodePoint === C1_CSI_CODE_POINT) sequenceStartIndex = index + 1;
|
|
1797
|
+
else return;
|
|
1798
|
+
let hasCanonicalSgrParameters = true;
|
|
1799
|
+
for (let sequenceIndex = sequenceStartIndex; sequenceIndex < string.length; sequenceIndex++) {
|
|
1800
|
+
const codePoint = string.codePointAt(sequenceIndex);
|
|
1801
|
+
if (isCsiFinalCharacter(codePoint)) {
|
|
1802
|
+
const code = string.slice(index, sequenceIndex + 1);
|
|
1803
|
+
if (string[sequenceIndex] !== ANSI_SGR_TERMINATOR || !hasCanonicalSgrParameters) return createControlParseResult(code, sequenceIndex + 1);
|
|
1804
|
+
return {
|
|
1805
|
+
token: {
|
|
1806
|
+
type: "sgr",
|
|
1807
|
+
code,
|
|
1808
|
+
fragments: getSgrFragments(code)
|
|
1809
|
+
},
|
|
1810
|
+
endIndex: sequenceIndex + 1
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
if (isCsiParameterCharacter(codePoint)) {
|
|
1814
|
+
if (!isSgrParameterCharacter(codePoint)) hasCanonicalSgrParameters = false;
|
|
1815
|
+
continue;
|
|
1816
|
+
}
|
|
1817
|
+
if (isCsiIntermediateCharacter(codePoint)) {
|
|
1818
|
+
hasCanonicalSgrParameters = false;
|
|
1819
|
+
continue;
|
|
1820
|
+
}
|
|
1821
|
+
const endIndex = sequenceIndex;
|
|
1822
|
+
return createControlParseResult(string.slice(index, endIndex), endIndex);
|
|
1823
|
+
}
|
|
1824
|
+
return createControlParseResult(string.slice(index), string.length);
|
|
1825
|
+
}
|
|
1826
|
+
function parseHyperlinkCode(string, index) {
|
|
1827
|
+
let hyperlinkPrefix;
|
|
1828
|
+
let hyperlinkClose;
|
|
1829
|
+
const codePoint = string.codePointAt(index);
|
|
1830
|
+
if (codePoint === ESCAPE_CODE_POINT && string.startsWith(ANSI_HYPERLINK_ESC_PREFIX, index)) {
|
|
1831
|
+
hyperlinkPrefix = ANSI_HYPERLINK_ESC_PREFIX;
|
|
1832
|
+
hyperlinkClose = ANSI_HYPERLINK_ESC_CLOSE;
|
|
1833
|
+
} else if (codePoint === C1_OSC_CODE_POINT && string.startsWith(ANSI_HYPERLINK_C1_PREFIX, index)) {
|
|
1834
|
+
hyperlinkPrefix = ANSI_HYPERLINK_C1_PREFIX;
|
|
1835
|
+
hyperlinkClose = ANSI_HYPERLINK_C1_CLOSE;
|
|
1836
|
+
} else return;
|
|
1837
|
+
const uriStart = string.indexOf(";", index + hyperlinkPrefix.length);
|
|
1838
|
+
if (uriStart === -1) return createControlParseResult(string.slice(index), string.length);
|
|
1839
|
+
for (let sequenceIndex = uriStart + 1; sequenceIndex < string.length; sequenceIndex++) {
|
|
1840
|
+
const character = string[sequenceIndex];
|
|
1841
|
+
if (character === ANSI_BELL) return {
|
|
1842
|
+
token: {
|
|
1843
|
+
type: "hyperlink",
|
|
1844
|
+
code: string.slice(index, sequenceIndex + 1),
|
|
1845
|
+
action: sequenceIndex === uriStart + 1 ? "close" : "open",
|
|
1846
|
+
closePrefix: hyperlinkClose,
|
|
1847
|
+
terminator: ANSI_BELL
|
|
1848
|
+
},
|
|
1849
|
+
endIndex: sequenceIndex + 1
|
|
1850
|
+
};
|
|
1851
|
+
if (character === ESCAPE && string[sequenceIndex + 1] === ANSI_OSC_TERMINATOR) return {
|
|
1852
|
+
token: {
|
|
1853
|
+
type: "hyperlink",
|
|
1854
|
+
code: string.slice(index, sequenceIndex + 2),
|
|
1855
|
+
action: sequenceIndex === uriStart + 1 ? "close" : "open",
|
|
1856
|
+
closePrefix: hyperlinkClose,
|
|
1857
|
+
terminator: ANSI_STRING_TERMINATOR
|
|
1858
|
+
},
|
|
1859
|
+
endIndex: sequenceIndex + 2
|
|
1860
|
+
};
|
|
1861
|
+
if (character === C1_STRING_TERMINATOR) return {
|
|
1862
|
+
token: {
|
|
1863
|
+
type: "hyperlink",
|
|
1864
|
+
code: string.slice(index, sequenceIndex + 1),
|
|
1865
|
+
action: sequenceIndex === uriStart + 1 ? "close" : "open",
|
|
1866
|
+
closePrefix: hyperlinkClose,
|
|
1867
|
+
terminator: C1_STRING_TERMINATOR
|
|
1868
|
+
},
|
|
1869
|
+
endIndex: sequenceIndex + 1
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
return createControlParseResult(string.slice(index), string.length);
|
|
1873
|
+
}
|
|
1874
|
+
function parseControlStringCode(string, index) {
|
|
1875
|
+
const codePoint = string.codePointAt(index);
|
|
1876
|
+
let sequenceStartIndex;
|
|
1877
|
+
let supportsBellTerminator = false;
|
|
1878
|
+
switch (codePoint) {
|
|
1879
|
+
case ESCAPE_CODE_POINT:
|
|
1880
|
+
switch (string[index + 1]) {
|
|
1881
|
+
case ANSI_OSC:
|
|
1882
|
+
sequenceStartIndex = index + 2;
|
|
1883
|
+
supportsBellTerminator = true;
|
|
1884
|
+
break;
|
|
1885
|
+
case ANSI_DCS:
|
|
1886
|
+
case ANSI_SOS:
|
|
1887
|
+
case ANSI_PM:
|
|
1888
|
+
case ANSI_APC:
|
|
1889
|
+
sequenceStartIndex = index + 2;
|
|
1890
|
+
break;
|
|
1891
|
+
case ANSI_OSC_TERMINATOR: return createControlParseResult(ANSI_STRING_TERMINATOR, index + 2);
|
|
1892
|
+
default: return;
|
|
1893
|
+
}
|
|
1894
|
+
break;
|
|
1895
|
+
case C1_OSC_CODE_POINT:
|
|
1896
|
+
sequenceStartIndex = index + 1;
|
|
1897
|
+
supportsBellTerminator = true;
|
|
1898
|
+
break;
|
|
1899
|
+
case C1_DCS_CODE_POINT:
|
|
1900
|
+
case C1_SOS_CODE_POINT:
|
|
1901
|
+
case C1_PM_CODE_POINT:
|
|
1902
|
+
case C1_APC_CODE_POINT:
|
|
1903
|
+
sequenceStartIndex = index + 1;
|
|
1904
|
+
break;
|
|
1905
|
+
case C1_ST_CODE_POINT: return createControlParseResult(C1_STRING_TERMINATOR, index + 1);
|
|
1906
|
+
default: return;
|
|
1907
|
+
}
|
|
1908
|
+
for (let sequenceIndex = sequenceStartIndex; sequenceIndex < string.length; sequenceIndex++) {
|
|
1909
|
+
if (supportsBellTerminator && string[sequenceIndex] === ANSI_BELL) return createControlParseResult(string.slice(index, sequenceIndex + 1), sequenceIndex + 1);
|
|
1910
|
+
if (string[sequenceIndex] === ESCAPE && string[sequenceIndex + 1] === ANSI_OSC_TERMINATOR) return createControlParseResult(string.slice(index, sequenceIndex + 2), sequenceIndex + 2);
|
|
1911
|
+
if (string[sequenceIndex] === C1_STRING_TERMINATOR) return createControlParseResult(string.slice(index, sequenceIndex + 1), sequenceIndex + 1);
|
|
1912
|
+
}
|
|
1913
|
+
return createControlParseResult(string.slice(index), string.length);
|
|
1914
|
+
}
|
|
1915
|
+
function parseAnsiCode(string, index) {
|
|
1916
|
+
const codePoint = string.codePointAt(index);
|
|
1917
|
+
if (codePoint === ESCAPE_CODE_POINT || codePoint === C1_OSC_CODE_POINT) {
|
|
1918
|
+
const hyperlinkCode = parseHyperlinkCode(string, index);
|
|
1919
|
+
if (hyperlinkCode) return hyperlinkCode;
|
|
1920
|
+
}
|
|
1921
|
+
const controlStringCode = parseControlStringCode(string, index);
|
|
1922
|
+
if (controlStringCode) return controlStringCode;
|
|
1923
|
+
return parseCsiCode(string, index);
|
|
1924
|
+
}
|
|
1925
|
+
function appendTrailingAnsiTokens(string, index, tokens) {
|
|
1926
|
+
while (index < string.length) {
|
|
1927
|
+
const nextCodePoint = string.codePointAt(index);
|
|
1928
|
+
if (!ESCAPES.has(nextCodePoint)) break;
|
|
1929
|
+
const escapeCode = parseAnsiCode(string, index);
|
|
1930
|
+
if (!escapeCode) break;
|
|
1931
|
+
tokens.push(escapeCode.token);
|
|
1932
|
+
index = escapeCode.endIndex;
|
|
1933
|
+
}
|
|
1934
|
+
return index;
|
|
1935
|
+
}
|
|
1936
|
+
function parseCharacterTokenWithRawSegmentation(string, index, graphemeSegments) {
|
|
1937
|
+
const segment = graphemeSegments.containing(index);
|
|
1938
|
+
if (!segment || segment.index !== index) return;
|
|
1939
|
+
return {
|
|
1940
|
+
token: {
|
|
1941
|
+
type: "character",
|
|
1942
|
+
value: segment.segment,
|
|
1943
|
+
visibleWidth: getGraphemeWidth(segment.segment),
|
|
1944
|
+
isGraphemeContinuation: false
|
|
1945
|
+
},
|
|
1946
|
+
endIndex: index + segment.segment.length
|
|
1947
|
+
};
|
|
1948
|
+
}
|
|
1949
|
+
function collectVisibleCharacters(string) {
|
|
1950
|
+
const visibleCharacters = [];
|
|
1951
|
+
let index = 0;
|
|
1952
|
+
while (index < string.length) {
|
|
1953
|
+
const codePoint = string.codePointAt(index);
|
|
1954
|
+
if (ESCAPES.has(codePoint)) {
|
|
1955
|
+
const code = parseAnsiCode(string, index);
|
|
1956
|
+
if (code) {
|
|
1957
|
+
index = code.endIndex;
|
|
1958
|
+
continue;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
const value = String.fromCodePoint(codePoint);
|
|
1962
|
+
visibleCharacters.push({
|
|
1963
|
+
value,
|
|
1964
|
+
visibleWidth: 1,
|
|
1965
|
+
isGraphemeContinuation: false
|
|
1966
|
+
});
|
|
1967
|
+
index += value.length;
|
|
1968
|
+
}
|
|
1969
|
+
return visibleCharacters;
|
|
1970
|
+
}
|
|
1971
|
+
function applyGraphemeMetadata(visibleCharacters) {
|
|
1972
|
+
if (visibleCharacters.length === 0) return;
|
|
1973
|
+
const visibleString = visibleCharacters.map(({ value }) => value).join("");
|
|
1974
|
+
const scalarOffsets = [];
|
|
1975
|
+
let scalarOffset = 0;
|
|
1976
|
+
for (const visibleCharacter of visibleCharacters) {
|
|
1977
|
+
scalarOffsets.push(scalarOffset);
|
|
1978
|
+
scalarOffset += visibleCharacter.value.length;
|
|
1979
|
+
}
|
|
1980
|
+
let scalarIndex = 0;
|
|
1981
|
+
for (const segment of GRAPHEME_SEGMENTER.segment(visibleString)) {
|
|
1982
|
+
while (scalarIndex < visibleCharacters.length && scalarOffsets[scalarIndex] < segment.index) scalarIndex++;
|
|
1983
|
+
let graphemeIndex = scalarIndex;
|
|
1984
|
+
let isFirstInGrapheme = true;
|
|
1985
|
+
while (graphemeIndex < visibleCharacters.length && scalarOffsets[graphemeIndex] < segment.index + segment.segment.length) {
|
|
1986
|
+
visibleCharacters[graphemeIndex].visibleWidth = isFirstInGrapheme ? getGraphemeWidth(segment.segment) : 0;
|
|
1987
|
+
visibleCharacters[graphemeIndex].isGraphemeContinuation = !isFirstInGrapheme;
|
|
1988
|
+
isFirstInGrapheme = false;
|
|
1989
|
+
graphemeIndex++;
|
|
1990
|
+
}
|
|
1991
|
+
scalarIndex = graphemeIndex;
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
function tokenizeAnsiWithVisibleSegmentation(string, { endCharacter = Number.POSITIVE_INFINITY } = {}) {
|
|
1995
|
+
const tokens = [];
|
|
1996
|
+
const visibleCharacters = collectVisibleCharacters(string);
|
|
1997
|
+
applyGraphemeMetadata(visibleCharacters);
|
|
1998
|
+
let index = 0;
|
|
1999
|
+
let visibleCharacterIndex = 0;
|
|
2000
|
+
let visibleCount = 0;
|
|
2001
|
+
while (index < string.length) {
|
|
2002
|
+
const codePoint = string.codePointAt(index);
|
|
2003
|
+
if (ESCAPES.has(codePoint)) {
|
|
2004
|
+
const code = parseAnsiCode(string, index);
|
|
2005
|
+
if (code) {
|
|
2006
|
+
tokens.push(code.token);
|
|
2007
|
+
index = code.endIndex;
|
|
2008
|
+
continue;
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
const value = String.fromCodePoint(codePoint);
|
|
2012
|
+
const visibleCharacter = visibleCharacters[visibleCharacterIndex];
|
|
2013
|
+
let visibleWidth = isFullwidthCodePoint(codePoint) ? 2 : value.length;
|
|
2014
|
+
if (visibleCharacter) visibleWidth = visibleCharacter.visibleWidth;
|
|
2015
|
+
const token = {
|
|
2016
|
+
type: "character",
|
|
2017
|
+
value,
|
|
2018
|
+
visibleWidth,
|
|
2019
|
+
isGraphemeContinuation: visibleCharacter ? visibleCharacter.isGraphemeContinuation : false
|
|
2020
|
+
};
|
|
2021
|
+
tokens.push(token);
|
|
2022
|
+
index += value.length;
|
|
2023
|
+
visibleCharacterIndex++;
|
|
2024
|
+
visibleCount += token.visibleWidth;
|
|
2025
|
+
if (visibleCount >= endCharacter) {
|
|
2026
|
+
const nextVisibleCharacter = visibleCharacters[visibleCharacterIndex];
|
|
2027
|
+
if (!nextVisibleCharacter || !nextVisibleCharacter.isGraphemeContinuation) {
|
|
2028
|
+
index = appendTrailingAnsiTokens(string, index, tokens);
|
|
2029
|
+
break;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
return tokens;
|
|
2034
|
+
}
|
|
2035
|
+
function areValuesInSameGrapheme(leftValue, rightValue) {
|
|
2036
|
+
const pair = `${leftValue}${rightValue}`;
|
|
2037
|
+
const splitIndex = leftValue.length;
|
|
2038
|
+
for (const segment of GRAPHEME_SEGMENTER.segment(pair)) {
|
|
2039
|
+
if (segment.index === splitIndex) return false;
|
|
2040
|
+
if (segment.index > splitIndex) return true;
|
|
2041
|
+
}
|
|
2042
|
+
return true;
|
|
2043
|
+
}
|
|
2044
|
+
function hasAnsiSplitContinuationAhead(string, startIndex, previousVisibleValue, graphemeSegments) {
|
|
2045
|
+
if (!previousVisibleValue) return false;
|
|
2046
|
+
let index = startIndex;
|
|
2047
|
+
let hasAnsiCode = false;
|
|
2048
|
+
while (index < string.length) {
|
|
2049
|
+
const codePoint = string.codePointAt(index);
|
|
2050
|
+
if (ESCAPES.has(codePoint)) {
|
|
2051
|
+
const code = parseAnsiCode(string, index);
|
|
2052
|
+
if (code) {
|
|
2053
|
+
hasAnsiCode = true;
|
|
2054
|
+
index = code.endIndex;
|
|
2055
|
+
continue;
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
if (!hasAnsiCode) return false;
|
|
2059
|
+
const characterToken = parseCharacterTokenWithRawSegmentation(string, index, graphemeSegments);
|
|
2060
|
+
if (!characterToken) return true;
|
|
2061
|
+
return areValuesInSameGrapheme(previousVisibleValue, characterToken.token.value);
|
|
2062
|
+
}
|
|
2063
|
+
return false;
|
|
2064
|
+
}
|
|
2065
|
+
function tokenizeAnsi(string, { endCharacter = Number.POSITIVE_INFINITY } = {}) {
|
|
2066
|
+
const tokens = [];
|
|
2067
|
+
const graphemeSegments = GRAPHEME_SEGMENTER.segment(string);
|
|
2068
|
+
let index = 0;
|
|
2069
|
+
let visibleCount = 0;
|
|
2070
|
+
let previousVisibleValue;
|
|
2071
|
+
let hasAnsiSinceLastVisible = false;
|
|
2072
|
+
while (index < string.length) {
|
|
2073
|
+
const codePoint = string.codePointAt(index);
|
|
2074
|
+
if (ESCAPES.has(codePoint)) {
|
|
2075
|
+
const code = parseAnsiCode(string, index);
|
|
2076
|
+
if (code) {
|
|
2077
|
+
tokens.push(code.token);
|
|
2078
|
+
index = code.endIndex;
|
|
2079
|
+
hasAnsiSinceLastVisible = true;
|
|
2080
|
+
continue;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
const characterToken = parseCharacterTokenWithRawSegmentation(string, index, graphemeSegments);
|
|
2084
|
+
if (!characterToken) return tokenizeAnsiWithVisibleSegmentation(string, { endCharacter });
|
|
2085
|
+
if (hasAnsiSinceLastVisible && previousVisibleValue && areValuesInSameGrapheme(previousVisibleValue, characterToken.token.value)) return tokenizeAnsiWithVisibleSegmentation(string, { endCharacter });
|
|
2086
|
+
tokens.push(characterToken.token);
|
|
2087
|
+
index = characterToken.endIndex;
|
|
2088
|
+
visibleCount += characterToken.token.visibleWidth;
|
|
2089
|
+
hasAnsiSinceLastVisible = false;
|
|
2090
|
+
previousVisibleValue = characterToken.token.value;
|
|
2091
|
+
if (visibleCount >= endCharacter) {
|
|
2092
|
+
if (hasAnsiSplitContinuationAhead(string, index, previousVisibleValue, graphemeSegments)) return tokenizeAnsiWithVisibleSegmentation(string, { endCharacter });
|
|
2093
|
+
index = appendTrailingAnsiTokens(string, index, tokens);
|
|
2094
|
+
break;
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
return tokens;
|
|
2098
|
+
}
|
|
2099
|
+
// ../../node_modules/.pnpm/slice-ansi@9.0.1/node_modules/slice-ansi/index.js
|
|
2100
|
+
function applySgrFragments(activeStyles, fragments) {
|
|
2101
|
+
for (const fragment of fragments) switch (fragment.type) {
|
|
2102
|
+
case "reset":
|
|
2103
|
+
activeStyles.clear();
|
|
2104
|
+
break;
|
|
2105
|
+
case "end":
|
|
2106
|
+
activeStyles.delete(fragment.endCode);
|
|
2107
|
+
break;
|
|
2108
|
+
case "start":
|
|
2109
|
+
activeStyles.delete(fragment.endCode);
|
|
2110
|
+
activeStyles.set(fragment.endCode, fragment.code);
|
|
2111
|
+
}
|
|
2112
|
+
return activeStyles;
|
|
2113
|
+
}
|
|
2114
|
+
function undoAnsiCodes(activeStyles) {
|
|
2115
|
+
return [...activeStyles.keys()].toReversed().join("");
|
|
2116
|
+
}
|
|
2117
|
+
function closeHyperlink(hyperlinkToken) {
|
|
2118
|
+
return `${hyperlinkToken.closePrefix}${hyperlinkToken.terminator}`;
|
|
2119
|
+
}
|
|
2120
|
+
function shouldIncludeSgrAfterEnd(token, activeStyles) {
|
|
2121
|
+
let hasStartFragment = false;
|
|
2122
|
+
let hasClosingEffect = false;
|
|
2123
|
+
for (const fragment of token.fragments) {
|
|
2124
|
+
if (fragment.type === "start") {
|
|
2125
|
+
hasStartFragment = true;
|
|
2126
|
+
continue;
|
|
2127
|
+
}
|
|
2128
|
+
if (fragment.type === "reset" && activeStyles.size > 0) {
|
|
2129
|
+
hasClosingEffect = true;
|
|
2130
|
+
continue;
|
|
2131
|
+
}
|
|
2132
|
+
if (fragment.type === "end" && activeStyles.has(fragment.endCode)) hasClosingEffect = true;
|
|
2133
|
+
}
|
|
2134
|
+
return hasClosingEffect && !hasStartFragment;
|
|
2135
|
+
}
|
|
2136
|
+
function hasSgrStartFragment(token) {
|
|
2137
|
+
return token.fragments.some((fragment) => fragment.type === "start");
|
|
2138
|
+
}
|
|
2139
|
+
function discardPendingHyperlink(state) {
|
|
2140
|
+
if (state.activeHyperlink && !state.activeHyperlinkHasVisibleText && state.activeHyperlinkOutputIndex !== void 0) {
|
|
2141
|
+
const openCodeLength = state.activeHyperlink.code.length;
|
|
2142
|
+
state.returnValue = state.returnValue.slice(0, state.activeHyperlinkOutputIndex) + state.returnValue.slice(state.activeHyperlinkOutputIndex + openCodeLength);
|
|
2143
|
+
if (state.pendingSgrOutputIndex !== void 0 && state.pendingSgrOutputIndex > state.activeHyperlinkOutputIndex) state.pendingSgrOutputIndex -= openCodeLength;
|
|
2144
|
+
}
|
|
2145
|
+
state.activeHyperlink = void 0;
|
|
2146
|
+
state.activeHyperlinkHasVisibleText = false;
|
|
2147
|
+
state.activeHyperlinkOutputIndex = void 0;
|
|
2148
|
+
}
|
|
2149
|
+
function settleActiveHyperlink(state) {
|
|
2150
|
+
if (state.activeHyperlinkHasVisibleText) state.returnValue += closeHyperlink(state.activeHyperlink);
|
|
2151
|
+
else discardPendingHyperlink(state);
|
|
2152
|
+
}
|
|
2153
|
+
function applySgrToken(state) {
|
|
2154
|
+
if (state.isPastEnd && !shouldIncludeSgrAfterEnd(state.token, state.activeStyles)) return;
|
|
2155
|
+
if (state.include && hasSgrStartFragment(state.token) && state.pendingSgrOutputIndex === void 0) {
|
|
2156
|
+
state.pendingSgrOutputIndex = state.returnValue.length;
|
|
2157
|
+
state.pendingSgrActiveStyles = new Map(state.activeStyles);
|
|
2158
|
+
}
|
|
2159
|
+
state.activeStyles = applySgrFragments(state.activeStyles, state.token.fragments);
|
|
2160
|
+
if (state.include) state.returnValue += state.token.code;
|
|
2161
|
+
}
|
|
2162
|
+
function applyHyperlinkToken(state) {
|
|
2163
|
+
if (state.isPastEnd && (state.token.action !== "close" || !state.activeHyperlink)) return;
|
|
2164
|
+
if (state.token.action === "open") {
|
|
2165
|
+
if (state.activeHyperlink) settleActiveHyperlink(state);
|
|
2166
|
+
state.activeHyperlink = state.token;
|
|
2167
|
+
state.activeHyperlinkHasVisibleText = false;
|
|
2168
|
+
state.activeHyperlinkOutputIndex = void 0;
|
|
2169
|
+
if (state.include) state.activeHyperlinkOutputIndex = state.returnValue.length;
|
|
2170
|
+
} else if (state.token.action === "close") {
|
|
2171
|
+
if (state.include && state.activeHyperlink && !state.activeHyperlinkHasVisibleText) {
|
|
2172
|
+
discardPendingHyperlink(state);
|
|
2173
|
+
return;
|
|
2174
|
+
}
|
|
2175
|
+
state.activeHyperlink = void 0;
|
|
2176
|
+
state.activeHyperlinkHasVisibleText = false;
|
|
2177
|
+
state.activeHyperlinkOutputIndex = void 0;
|
|
2178
|
+
}
|
|
2179
|
+
if (state.include) state.returnValue += state.token.code;
|
|
2180
|
+
}
|
|
2181
|
+
function applyControlToken(state) {
|
|
2182
|
+
if (!state.isPastEnd && state.include) state.returnValue += state.token.code;
|
|
2183
|
+
}
|
|
2184
|
+
function applyCharacterToken(state) {
|
|
2185
|
+
if (!state.include && state.position >= state.start && !state.token.isGraphemeContinuation) {
|
|
2186
|
+
state.include = true;
|
|
2187
|
+
state.returnValue = [...state.activeStyles.values()].join("");
|
|
2188
|
+
if (state.activeHyperlink) {
|
|
2189
|
+
state.activeHyperlinkOutputIndex = state.returnValue.length;
|
|
2190
|
+
state.returnValue += state.activeHyperlink.code;
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
if (state.include) {
|
|
2194
|
+
state.returnValue += state.token.value;
|
|
2195
|
+
state.pendingSgrOutputIndex = void 0;
|
|
2196
|
+
state.pendingSgrActiveStyles = void 0;
|
|
2197
|
+
if (state.activeHyperlink) state.activeHyperlinkHasVisibleText = true;
|
|
2198
|
+
}
|
|
2199
|
+
state.position += state.token.visibleWidth;
|
|
2200
|
+
}
|
|
2201
|
+
const tokenHandlers = {
|
|
2202
|
+
sgr: applySgrToken,
|
|
2203
|
+
hyperlink: applyHyperlinkToken,
|
|
2204
|
+
control: applyControlToken,
|
|
2205
|
+
character: applyCharacterToken
|
|
2206
|
+
};
|
|
2207
|
+
function applyToken(state) {
|
|
2208
|
+
tokenHandlers[state.token.type]?.(state);
|
|
2209
|
+
}
|
|
2210
|
+
function createHasContinuationAheadMap(tokens) {
|
|
2211
|
+
const hasContinuationAhead = Array.from({ length: tokens.length }, () => false);
|
|
2212
|
+
let nextCharacterIsContinuation = false;
|
|
2213
|
+
for (let tokenIndex = tokens.length - 1; tokenIndex >= 0; tokenIndex--) {
|
|
2214
|
+
const token = tokens[tokenIndex];
|
|
2215
|
+
hasContinuationAhead[tokenIndex] = nextCharacterIsContinuation;
|
|
2216
|
+
if (token.type === "character") nextCharacterIsContinuation = Boolean(token.isGraphemeContinuation);
|
|
2217
|
+
}
|
|
2218
|
+
return hasContinuationAhead;
|
|
2219
|
+
}
|
|
2220
|
+
function isPastEndBoundary(token, position, end) {
|
|
2221
|
+
if (end === void 0) return false;
|
|
2222
|
+
if (position >= end) return true;
|
|
2223
|
+
return token.type === "character" && !token.isGraphemeContinuation && position + token.visibleWidth > end;
|
|
2224
|
+
}
|
|
2225
|
+
function sliceAnsi(string, start, end) {
|
|
2226
|
+
const tokens = tokenizeAnsi(string, { endCharacter: end });
|
|
2227
|
+
const hasContinuationAhead = createHasContinuationAheadMap(tokens);
|
|
2228
|
+
const state = {
|
|
2229
|
+
start,
|
|
2230
|
+
token: void 0,
|
|
2231
|
+
isPastEnd: false,
|
|
2232
|
+
activeStyles: /* @__PURE__ */ new Map(),
|
|
2233
|
+
activeHyperlink: void 0,
|
|
2234
|
+
activeHyperlinkHasVisibleText: false,
|
|
2235
|
+
activeHyperlinkOutputIndex: void 0,
|
|
2236
|
+
pendingSgrOutputIndex: void 0,
|
|
2237
|
+
pendingSgrActiveStyles: void 0,
|
|
2238
|
+
position: 0,
|
|
2239
|
+
returnValue: "",
|
|
2240
|
+
include: false
|
|
2241
|
+
};
|
|
2242
|
+
for (const [tokenIndex, token] of tokens.entries()) {
|
|
2243
|
+
let isPastEnd = isPastEndBoundary(token, state.position, end);
|
|
2244
|
+
if (isPastEnd && token.type !== "character" && hasContinuationAhead[tokenIndex]) isPastEnd = false;
|
|
2245
|
+
if (isPastEnd && token.type === "character" && !token.isGraphemeContinuation) {
|
|
2246
|
+
if (state.activeHyperlink && !state.activeHyperlinkHasVisibleText) discardPendingHyperlink(state);
|
|
2247
|
+
if (state.pendingSgrOutputIndex !== void 0) {
|
|
2248
|
+
state.returnValue = state.returnValue.slice(0, state.pendingSgrOutputIndex);
|
|
2249
|
+
state.activeStyles = state.pendingSgrActiveStyles;
|
|
2250
|
+
state.pendingSgrOutputIndex = void 0;
|
|
2251
|
+
state.pendingSgrActiveStyles = void 0;
|
|
2252
|
+
}
|
|
2253
|
+
break;
|
|
2254
|
+
}
|
|
2255
|
+
state.token = token;
|
|
2256
|
+
state.isPastEnd = isPastEnd;
|
|
2257
|
+
applyToken(state);
|
|
2258
|
+
}
|
|
2259
|
+
if (!state.include) return "";
|
|
2260
|
+
if (state.activeHyperlink) settleActiveHyperlink(state);
|
|
2261
|
+
state.returnValue += undoAnsiCodes(state.activeStyles);
|
|
2262
|
+
return state.returnValue;
|
|
2263
|
+
}
|
|
2264
|
+
// ../../node_modules/.pnpm/boxen@9.0.0/node_modules/boxen/index.js
|
|
2265
|
+
const NEWLINE = "\n";
|
|
2266
|
+
const PAD = " ";
|
|
2267
|
+
const NONE = "none";
|
|
2268
|
+
const LINE_BREAKS = /\r\n|[\n\v\f\r]/gv;
|
|
2269
|
+
const STYLING_ESCAPE = /^(?:\u{1B}\[[0-9:;]*m|\u{1B}\]8;[^\u{0}-\u{1F};\u{7F}]*;[^\u{0}-\u{1F}\u{7F}]*(?:\u{7}|\u{1B}\\))$/v;
|
|
2270
|
+
const CONTROL_ESCAPE = /(\u{1B}\].*?(?:\u{7}|\u{1B}\\|$)|\u{1B}\[[\u{20}-\u{3F}]*[\u{40}-\u{7E}]|\u{1B}[^\u{7}\u{5B}\u{5D}]?)/gsv;
|
|
2271
|
+
const writeControls = (text) => {
|
|
2272
|
+
const parts = text.split(CONTROL_ESCAPE);
|
|
2273
|
+
const characters = [];
|
|
2274
|
+
for (const [index, part] of parts.entries()) {
|
|
2275
|
+
if (index % 2 === 1) {
|
|
2276
|
+
if (STYLING_ESCAPE.test(part)) characters.push(part);
|
|
2277
|
+
continue;
|
|
2278
|
+
}
|
|
2279
|
+
for (const character of part.replaceAll(" ", " ")) if (character === "\b") {
|
|
2280
|
+
const previousIndex = characters.findLastIndex((previousCharacter) => !previousCharacter.startsWith("\x1B"));
|
|
2281
|
+
if (previousIndex !== -1 && characters[previousIndex] !== NEWLINE) characters.splice(previousIndex, 1);
|
|
2282
|
+
} else characters.push(character);
|
|
2283
|
+
}
|
|
2284
|
+
return characters.join("");
|
|
2285
|
+
};
|
|
2286
|
+
const terminalColumns = () => process$1.stdout?.columns || process$1.stderr?.columns || Number(process$1.env.COLUMNS) || 80;
|
|
2287
|
+
const terminalRows = () => process$1.stdout?.rows || process$1.stderr?.rows || Number(process$1.env.LINES);
|
|
2288
|
+
const getObject = (detail) => {
|
|
2289
|
+
const object = typeof detail === "number" ? {
|
|
2290
|
+
top: detail,
|
|
2291
|
+
right: detail * 3,
|
|
2292
|
+
bottom: detail,
|
|
2293
|
+
left: detail * 3
|
|
2294
|
+
} : {
|
|
2295
|
+
top: 0,
|
|
2296
|
+
right: 0,
|
|
2297
|
+
bottom: 0,
|
|
2298
|
+
left: 0,
|
|
2299
|
+
...detail
|
|
2300
|
+
};
|
|
2301
|
+
for (const side of [
|
|
2302
|
+
"top",
|
|
2303
|
+
"right",
|
|
2304
|
+
"bottom",
|
|
2305
|
+
"left"
|
|
2306
|
+
]) {
|
|
2307
|
+
const value = Number(object[side]);
|
|
2308
|
+
object[side] = Number.isFinite(value) ? Math.max(0, Math.floor(value)) : 0;
|
|
2309
|
+
}
|
|
2310
|
+
return object;
|
|
2311
|
+
};
|
|
2312
|
+
const getBorderWidth = (borderStyle) => {
|
|
2313
|
+
if (borderStyle === NONE) return 0;
|
|
2314
|
+
const { left, right } = getBorderChars(borderStyle);
|
|
2315
|
+
return stringWidth(left || PAD) + stringWidth(right || PAD);
|
|
2316
|
+
};
|
|
2317
|
+
const getBorderHeight = (borderStyle) => borderStyle === NONE ? 0 : 2;
|
|
2318
|
+
const getCornerWidths = (borderStyle) => {
|
|
2319
|
+
const { topLeft, topRight, bottomLeft, bottomRight } = getBorderChars(borderStyle);
|
|
2320
|
+
return {
|
|
2321
|
+
top: stringWidth(topLeft) + stringWidth(topRight),
|
|
2322
|
+
bottom: stringWidth(bottomLeft) + stringWidth(bottomRight)
|
|
2323
|
+
};
|
|
2324
|
+
};
|
|
2325
|
+
const sanitizeSize = (size, borderWidth, minimum = 1) => {
|
|
2326
|
+
const value = Number(size);
|
|
2327
|
+
return Number.isFinite(value) && value > 0 ? Math.max(minimum, value - borderWidth) : void 0;
|
|
2328
|
+
};
|
|
2329
|
+
const wrapLine = (line, width) => stringWidth(line) > width ? wrapAnsi(line, width, { hard: true }) : line;
|
|
2330
|
+
const isValidSize = (size) => {
|
|
2331
|
+
const value = Number(size);
|
|
2332
|
+
return Number.isFinite(value) && value > 0;
|
|
2333
|
+
};
|
|
2334
|
+
const alignText = (text, alignment, width) => {
|
|
2335
|
+
if (alignment === "left") return text;
|
|
2336
|
+
return text.split(NEWLINE).map((line) => {
|
|
2337
|
+
const padding = Math.max(0, width - stringWidth(line));
|
|
2338
|
+
return PAD.repeat(alignment === "right" ? padding : Math.floor(padding / 2)) + line;
|
|
2339
|
+
}).join(NEWLINE);
|
|
2340
|
+
};
|
|
2341
|
+
const getBorderChars = (borderStyle) => {
|
|
2342
|
+
const sides = [
|
|
2343
|
+
"topLeft",
|
|
2344
|
+
"topRight",
|
|
2345
|
+
"bottomRight",
|
|
2346
|
+
"bottomLeft",
|
|
2347
|
+
"left",
|
|
2348
|
+
"right",
|
|
2349
|
+
"top",
|
|
2350
|
+
"bottom"
|
|
2351
|
+
];
|
|
2352
|
+
let characters;
|
|
2353
|
+
if (borderStyle === NONE) borderStyle = Object.fromEntries(sides.map((side) => [side, ""]));
|
|
2354
|
+
if (typeof borderStyle === "string") {
|
|
2355
|
+
characters = Object.hasOwn(cli_boxes_default, borderStyle) ? cli_boxes_default[borderStyle] : void 0;
|
|
2356
|
+
if (!characters) throw new TypeError(`Invalid border style: ${borderStyle}`);
|
|
2357
|
+
} else {
|
|
2358
|
+
borderStyle = {
|
|
2359
|
+
...borderStyle,
|
|
2360
|
+
left: borderStyle?.left ?? borderStyle?.vertical,
|
|
2361
|
+
right: borderStyle?.right ?? borderStyle?.vertical,
|
|
2362
|
+
top: borderStyle?.top ?? borderStyle?.horizontal,
|
|
2363
|
+
bottom: borderStyle?.bottom ?? borderStyle?.horizontal
|
|
2364
|
+
};
|
|
2365
|
+
for (const side of sides) if (borderStyle[side] === null || typeof borderStyle[side] !== "string") throw new TypeError(`Invalid border style: ${side}`);
|
|
2366
|
+
characters = borderStyle;
|
|
2367
|
+
}
|
|
2368
|
+
return Object.fromEntries(sides.map((side) => [side, writeControls(characters[side].replaceAll(LINE_BREAKS, " ")).toWellFormed()]));
|
|
2369
|
+
};
|
|
2370
|
+
const makeLabel = (text, horizontal, alignment) => {
|
|
2371
|
+
let label = "";
|
|
2372
|
+
const textWidth = stringWidth(text);
|
|
2373
|
+
switch (alignment) {
|
|
2374
|
+
case "left":
|
|
2375
|
+
label = text + sliceAnsi(horizontal, textWidth);
|
|
2376
|
+
break;
|
|
2377
|
+
case "right":
|
|
2378
|
+
label = sliceAnsi(horizontal, textWidth) + text;
|
|
2379
|
+
break;
|
|
2380
|
+
default: {
|
|
2381
|
+
const width = Math.max(0, stringWidth(horizontal) - textWidth);
|
|
2382
|
+
if (width % 2 === 1) {
|
|
2383
|
+
horizontal = sliceAnsi(horizontal, Math.floor(width / 2) + textWidth);
|
|
2384
|
+
label = sliceAnsi(horizontal, 1) + text + horizontal;
|
|
2385
|
+
} else {
|
|
2386
|
+
horizontal = sliceAnsi(horizontal, width / 2 + textWidth);
|
|
2387
|
+
label = horizontal + text + horizontal;
|
|
2388
|
+
}
|
|
2389
|
+
break;
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
return label;
|
|
2393
|
+
};
|
|
2394
|
+
const makeContentText = (text, { padding, width, textAlignment, height }) => {
|
|
2395
|
+
const max = width - padding.left - padding.right;
|
|
2396
|
+
const wrappedText = text.split(NEWLINE).map((line) => wrapLine(line, max)).join(NEWLINE);
|
|
2397
|
+
const textWidth = Math.min(max, widestLine(wrappedText));
|
|
2398
|
+
const alignedText = alignText(wrappedText, textAlignment, textWidth);
|
|
2399
|
+
let offset = 0;
|
|
2400
|
+
if (textAlignment === "right") offset = max - textWidth;
|
|
2401
|
+
else if (textAlignment === "center") offset = Math.floor((max - textWidth) / 2);
|
|
2402
|
+
let lines = alignedText.split(NEWLINE).map((line) => PAD.repeat(offset) + line);
|
|
2403
|
+
const paddingLeft = PAD.repeat(padding.left);
|
|
2404
|
+
const paddingRight = PAD.repeat(padding.right);
|
|
2405
|
+
lines = lines.map((line) => {
|
|
2406
|
+
const newLine = paddingLeft + line + paddingRight;
|
|
2407
|
+
return newLine + PAD.repeat(Math.max(0, width - stringWidth(newLine)));
|
|
2408
|
+
});
|
|
2409
|
+
if (height !== void 0 && lines.length > Math.max(0, height - padding.top - padding.bottom)) lines = lines.slice(0, height - padding.top - padding.bottom);
|
|
2410
|
+
if (padding.top > 0) lines = [...Array.from({ length: padding.top }, () => PAD.repeat(width)), ...lines];
|
|
2411
|
+
if (padding.bottom > 0) lines = [...lines, ...Array.from({ length: padding.bottom }, () => PAD.repeat(width))];
|
|
2412
|
+
if (height !== void 0 && lines.length < height) lines = [...lines, ...Array.from({ length: height - lines.length }, () => PAD.repeat(width))];
|
|
2413
|
+
return lines.join(NEWLINE);
|
|
2414
|
+
};
|
|
2415
|
+
const fillBar = (character, width) => {
|
|
2416
|
+
const fill = character || PAD;
|
|
2417
|
+
const count = Math.ceil(Math.max(0, width) / Math.max(1, stringWidth(fill)));
|
|
2418
|
+
return sliceAnsi(fill.repeat(count), 0, Math.max(0, width));
|
|
2419
|
+
};
|
|
2420
|
+
const boxContent = (content, contentWidth, options) => {
|
|
2421
|
+
const colorizeBorder = (border) => {
|
|
2422
|
+
const coloredBorder = options.borderColor ? getColorFunction(options.borderColor)(border) : border;
|
|
2423
|
+
let bgColoredBorder = coloredBorder;
|
|
2424
|
+
if (options.borderBackgroundColor !== void 0) {
|
|
2425
|
+
if (options.borderBackgroundColor === "inherit") {
|
|
2426
|
+
if (options.backgroundColor) bgColoredBorder = getBGColorFunction(options.backgroundColor)(coloredBorder);
|
|
2427
|
+
} else bgColoredBorder = getBGColorFunction(options.borderBackgroundColor)(coloredBorder);
|
|
2428
|
+
}
|
|
2429
|
+
return options.dimBorder ? chalk.dim(bgColoredBorder) : bgColoredBorder;
|
|
2430
|
+
};
|
|
2431
|
+
const colorizeContent = (text) => options.backgroundColor ? getBGColorFunction(options.backgroundColor)(text) : text;
|
|
2432
|
+
const colorizeTitle = (title) => options.titleColor ? getColorFunction(options.titleColor)(title) : title;
|
|
2433
|
+
const chars = getBorderChars(options.borderStyle);
|
|
2434
|
+
const columns = terminalColumns();
|
|
2435
|
+
let marginLeft = PAD.repeat(options.margin.left);
|
|
2436
|
+
if (options.float === "center") {
|
|
2437
|
+
const marginWidth = Math.max((columns - contentWidth - getBorderWidth(options.borderStyle)) / 2, 0);
|
|
2438
|
+
marginLeft = PAD.repeat(marginWidth);
|
|
2439
|
+
} else if (options.float === "right") {
|
|
2440
|
+
const marginWidth = Math.max(columns - contentWidth - options.margin.right - getBorderWidth(options.borderStyle), 0);
|
|
2441
|
+
marginLeft = PAD.repeat(marginWidth);
|
|
2442
|
+
}
|
|
2443
|
+
const rows = [];
|
|
2444
|
+
const hasBorder = options.borderStyle !== NONE;
|
|
2445
|
+
const left = hasBorder ? chars.left || PAD : "";
|
|
2446
|
+
const right = hasBorder ? chars.right || PAD : "";
|
|
2447
|
+
const rowWidth = contentWidth + stringWidth(left) + stringWidth(right);
|
|
2448
|
+
const bar = (character, cornerStart, cornerEnd, label, alignment) => {
|
|
2449
|
+
const width = Math.max(0, rowWidth - stringWidth(cornerStart) - stringWidth(cornerEnd));
|
|
2450
|
+
const fill = fillBar(character, width);
|
|
2451
|
+
const filled = label ? makeLabel(label, fill, alignment) : fill;
|
|
2452
|
+
return sliceAnsi(filled + PAD.repeat(Math.max(0, width - stringWidth(filled))), 0, Math.max(0, width));
|
|
2453
|
+
};
|
|
2454
|
+
if (options.borderStyle !== NONE || options.title) {
|
|
2455
|
+
const topBar = bar(chars.top, chars.topLeft, chars.topRight, options.title ? colorizeTitle(options.title) : "", options.titleAlignment);
|
|
2456
|
+
rows.push(marginLeft + colorizeBorder(chars.topLeft + topBar + chars.topRight));
|
|
2457
|
+
}
|
|
2458
|
+
const lines = content === "" ? [] : content.split(NEWLINE);
|
|
2459
|
+
for (const line of lines) {
|
|
2460
|
+
const padded = line + PAD.repeat(Math.max(0, contentWidth - stringWidth(line)));
|
|
2461
|
+
rows.push(marginLeft + colorizeBorder(left) + colorizeContent(padded) + colorizeBorder(right));
|
|
2462
|
+
}
|
|
2463
|
+
if (options.borderStyle !== NONE || options.footer) {
|
|
2464
|
+
const bottomBar = bar(chars.bottom, chars.bottomLeft, chars.bottomRight, options.footer ?? "", options.footerAlignment);
|
|
2465
|
+
rows.push(marginLeft + colorizeBorder(chars.bottomLeft + bottomBar + chars.bottomRight));
|
|
2466
|
+
}
|
|
2467
|
+
return NEWLINE.repeat(options.margin.top) + rows.join(NEWLINE) + NEWLINE.repeat(options.margin.bottom);
|
|
2468
|
+
};
|
|
2469
|
+
const sanitizeOptions = (options) => {
|
|
2470
|
+
if (options.fullscreen && process$1?.stdout) {
|
|
2471
|
+
let newDimensions = [terminalColumns(), terminalRows()];
|
|
2472
|
+
if (typeof options.fullscreen === "function") newDimensions = options.fullscreen(...newDimensions);
|
|
2473
|
+
if (!isValidSize(options.width)) options.width = newDimensions[0];
|
|
2474
|
+
if (!isValidSize(options.height)) options.height = newDimensions[1];
|
|
2475
|
+
}
|
|
2476
|
+
const borderWidth = getBorderWidth(options.borderStyle);
|
|
2477
|
+
options.width = sanitizeSize(options.width, borderWidth);
|
|
2478
|
+
options.maxWidth = sanitizeSize(options.maxWidth, borderWidth);
|
|
2479
|
+
options.height = sanitizeSize(options.height, getBorderHeight(options.borderStyle), 0);
|
|
2480
|
+
return options;
|
|
2481
|
+
};
|
|
2482
|
+
const labelFrame = (borderStyle) => borderStyle === NONE ? 0 : 2;
|
|
2483
|
+
const formatLabel = (label, borderStyle) => borderStyle === NONE ? label : ` ${label} `;
|
|
2484
|
+
const fitLabel = (label, width, borderStyle, cornerWidth) => {
|
|
2485
|
+
if (!label) return label;
|
|
2486
|
+
label = writeControls(label.replaceAll(LINE_BREAKS, " ")).toWellFormed();
|
|
2487
|
+
label = sliceAnsi(label, 0, Math.max(0, width + getBorderWidth(borderStyle) - cornerWidth - labelFrame(borderStyle)));
|
|
2488
|
+
return label && formatLabel(label, borderStyle);
|
|
2489
|
+
};
|
|
2490
|
+
const determineDimensions = (text, options) => {
|
|
2491
|
+
options = sanitizeOptions(options);
|
|
2492
|
+
const isWidthOverride = options.width !== void 0;
|
|
2493
|
+
const columns = terminalColumns();
|
|
2494
|
+
const borderWidth = getBorderWidth(options.borderStyle);
|
|
2495
|
+
const cornerWidths = getCornerWidths(options.borderStyle);
|
|
2496
|
+
const corners = Math.max(cornerWidths.top, cornerWidths.bottom);
|
|
2497
|
+
const terminalWidth = columns - borderWidth;
|
|
2498
|
+
const maxContentWidth = Math.min(terminalWidth, options.maxWidth || terminalWidth);
|
|
2499
|
+
const marginWidth = () => {
|
|
2500
|
+
switch (options.float) {
|
|
2501
|
+
case "center": return 0;
|
|
2502
|
+
case "right": return options.margin.right;
|
|
2503
|
+
default: return options.margin.left + options.margin.right;
|
|
2504
|
+
}
|
|
2505
|
+
};
|
|
2506
|
+
const availableWidth = isWidthOverride ? columns - borderWidth - (options.float === "left" ? options.margin.left : 0) : terminalWidth - marginWidth();
|
|
2507
|
+
const maxTextWidth = Math.max(1, maxContentWidth - options.padding.left - options.padding.right);
|
|
2508
|
+
const widestText = widestLine(text.split(NEWLINE).map((line) => wrapLine(line, maxTextWidth)).join(NEWLINE));
|
|
2509
|
+
let widest = Math.min(widestText + options.padding.left + options.padding.right, maxContentWidth);
|
|
2510
|
+
options.width ||= widest;
|
|
2511
|
+
if ((options.margin.left || options.margin.right) && Math.max(1, options.width) > availableWidth) {
|
|
2512
|
+
const multiplier = (columns - Math.max(1, options.width) - borderWidth) / (options.margin.left + options.margin.right);
|
|
2513
|
+
options.margin.left = Math.max(0, Math.floor(options.margin.left * multiplier));
|
|
2514
|
+
options.margin.right = Math.max(0, Math.floor(options.margin.right * multiplier));
|
|
2515
|
+
}
|
|
2516
|
+
const labelWidth = isWidthOverride ? options.width : Math.min(columns - borderWidth - marginWidth(), maxContentWidth);
|
|
2517
|
+
options.title = fitLabel(options.title, labelWidth, options.borderStyle, cornerWidths.top);
|
|
2518
|
+
options.footer = fitLabel(options.footer, labelWidth, options.borderStyle, cornerWidths.bottom);
|
|
2519
|
+
if (getBorderHeight(options.borderStyle) === 0 && options.height !== void 0) options.height = Math.max(0, options.height - (options.title ? 1 : 0) - (options.footer ? 1 : 0));
|
|
2520
|
+
if (!isWidthOverride) {
|
|
2521
|
+
for (const [label, cornerWidth] of [[options.title, cornerWidths.top], [options.footer, cornerWidths.bottom]]) if (label) widest = Math.max(widest, stringWidth(label) - borderWidth + cornerWidth);
|
|
2522
|
+
options.width = Math.max(1, Math.min(widest, columns - borderWidth - marginWidth()));
|
|
2523
|
+
}
|
|
2524
|
+
options.width = Math.max(options.width, corners - borderWidth, 1);
|
|
2525
|
+
if (options.padding.left + options.padding.right >= options.width) {
|
|
2526
|
+
options.padding.left = 0;
|
|
2527
|
+
options.padding.right = 0;
|
|
2528
|
+
}
|
|
2529
|
+
if (options.height !== void 0 && options.padding.top + options.padding.bottom >= options.height) {
|
|
2530
|
+
options.padding.top = 0;
|
|
2531
|
+
options.padding.bottom = 0;
|
|
2532
|
+
}
|
|
2533
|
+
return options;
|
|
2534
|
+
};
|
|
2535
|
+
const colorNames = /* @__PURE__ */ new Set([
|
|
2536
|
+
"black",
|
|
2537
|
+
"red",
|
|
2538
|
+
"green",
|
|
2539
|
+
"yellow",
|
|
2540
|
+
"blue",
|
|
2541
|
+
"magenta",
|
|
2542
|
+
"cyan",
|
|
2543
|
+
"white",
|
|
2544
|
+
"gray",
|
|
2545
|
+
"grey",
|
|
2546
|
+
"blackBright",
|
|
2547
|
+
"redBright",
|
|
2548
|
+
"greenBright",
|
|
2549
|
+
"yellowBright",
|
|
2550
|
+
"blueBright",
|
|
2551
|
+
"magentaBright",
|
|
2552
|
+
"cyanBright",
|
|
2553
|
+
"whiteBright"
|
|
2554
|
+
]);
|
|
2555
|
+
const isHex = (color) => /^#(?:[\da-f]{3}){1,2}$/iv.test(color);
|
|
2556
|
+
const isColorValid = (color) => typeof color === "string" && (colorNames.has(color) || isHex(color));
|
|
2557
|
+
const getColorFunction = (color) => isHex(color) ? chalk.hex(color) : chalk[color];
|
|
2558
|
+
const getBGColorFunction = (color) => isHex(color) ? chalk.bgHex(color) : chalk[`bg${color[0].toUpperCase()}${color.slice(1)}`];
|
|
2559
|
+
function boxen(text, options) {
|
|
2560
|
+
text = writeControls(text.replaceAll(LINE_BREAKS, "\n")).toWellFormed();
|
|
2561
|
+
options = {
|
|
2562
|
+
padding: 0,
|
|
2563
|
+
dimBorder: false,
|
|
2564
|
+
float: "left",
|
|
2565
|
+
...options
|
|
2566
|
+
};
|
|
2567
|
+
options.borderStyle ??= "single";
|
|
2568
|
+
options.textAlignment ??= options.align ?? "left";
|
|
2569
|
+
options.titleAlignment ??= "left";
|
|
2570
|
+
options.footerAlignment ??= "left";
|
|
2571
|
+
if (options.borderColor && !isColorValid(options.borderColor)) throw new Error(`${options.borderColor} is not a valid borderColor`);
|
|
2572
|
+
if (options.titleColor && !isColorValid(options.titleColor)) throw new Error(`${options.titleColor} is not a valid titleColor`);
|
|
2573
|
+
if (options.backgroundColor && !isColorValid(options.backgroundColor)) throw new Error(`${options.backgroundColor} is not a valid backgroundColor`);
|
|
2574
|
+
if (!("borderBackgroundColor" in options)) options.borderBackgroundColor = "inherit";
|
|
2575
|
+
if (options.borderBackgroundColor !== void 0 && options.borderBackgroundColor !== "inherit" && !isColorValid(options.borderBackgroundColor)) throw new Error(`${options.borderBackgroundColor} is not a valid borderBackgroundColor`);
|
|
2576
|
+
options.padding = getObject(options.padding);
|
|
2577
|
+
options.margin = getObject(options.margin);
|
|
2578
|
+
options = determineDimensions(text, options);
|
|
2579
|
+
text = makeContentText(text, options);
|
|
2580
|
+
return boxContent(text, Math.max(options.width, widestLine(text)), options);
|
|
2581
|
+
}
|
|
2582
|
+
// src/ux/banner.ts
|
|
2583
|
+
/**
|
|
2584
|
+
* Display the tool banner
|
|
2585
|
+
*/
|
|
2586
|
+
function showBanner(command, version, quiet = false) {
|
|
2587
|
+
if (quiet) return;
|
|
2588
|
+
const banner = boxen(`${chalk.bold.cyan("QTI <-> Learnosity Converter")}\n${chalk.dim("Version:")} ${version}\n${chalk.dim("Command:")} ${command}`, {
|
|
2589
|
+
padding: 1,
|
|
2590
|
+
margin: 1,
|
|
2591
|
+
borderStyle: "round",
|
|
2592
|
+
borderColor: "cyan"
|
|
2593
|
+
});
|
|
2594
|
+
console.log(banner);
|
|
2595
|
+
}
|
|
2596
|
+
// src/options/schema.ts
|
|
2597
|
+
const VALID_QTI_VERSIONS = ["2.1", "2.2"];
|
|
2598
|
+
const VALID_OUTPUT_FORMATS = [
|
|
2599
|
+
"dir",
|
|
2600
|
+
"zip",
|
|
2601
|
+
"stdout"
|
|
2602
|
+
];
|
|
2603
|
+
const VALID_DIAGNOSTICS_OUTPUTS = [
|
|
2604
|
+
"stderr",
|
|
2605
|
+
"file",
|
|
2606
|
+
"both",
|
|
2607
|
+
"none"
|
|
2608
|
+
];
|
|
2609
|
+
const VALID_ITEM_REFERENCE_SOURCES = [
|
|
2610
|
+
"itemIdentifier",
|
|
2611
|
+
"qti",
|
|
2612
|
+
"sourceFilename",
|
|
2613
|
+
"uuid"
|
|
2614
|
+
];
|
|
2615
|
+
const VALID_ITEM_FILENAME_SOURCES = [
|
|
2616
|
+
"itemIdentifier",
|
|
2617
|
+
"qti",
|
|
2618
|
+
"sourceFilename"
|
|
2619
|
+
];
|
|
2620
|
+
const KNOWN_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
2621
|
+
"qtiVersion",
|
|
2622
|
+
"outputFormat",
|
|
2623
|
+
"diagnostics",
|
|
2624
|
+
"pretty",
|
|
2625
|
+
"verbose",
|
|
2626
|
+
"output",
|
|
2627
|
+
"organisationId",
|
|
2628
|
+
"mediaVault",
|
|
2629
|
+
"customAssetUrl",
|
|
2630
|
+
"preserveAssetFilenames",
|
|
2631
|
+
"itemReferenceSource",
|
|
2632
|
+
"itemFilenameSource",
|
|
2633
|
+
"truncateTags",
|
|
2634
|
+
"splitCsvTags"
|
|
2635
|
+
]);
|
|
2636
|
+
/**
|
|
2637
|
+
* Validate config object and return diagnostics
|
|
2638
|
+
*/
|
|
2639
|
+
function validateConfig(config) {
|
|
2640
|
+
const diagnostics = [];
|
|
2641
|
+
const valid = {};
|
|
2642
|
+
for (const key of Object.keys(config)) if (!KNOWN_CONFIG_KEYS.has(key)) diagnostics.push({
|
|
2643
|
+
level: "warning",
|
|
2644
|
+
code: DiagnosticCode.CONFIG_UNKNOWN_KEY,
|
|
2645
|
+
message: `Unknown config key: "${key}"`,
|
|
2646
|
+
file: "",
|
|
2647
|
+
context: { key }
|
|
2648
|
+
});
|
|
2649
|
+
if ("qtiVersion" in config) {
|
|
2650
|
+
if (typeof config.qtiVersion === "string" && VALID_QTI_VERSIONS.includes(config.qtiVersion)) valid.qtiVersion = config.qtiVersion;
|
|
2651
|
+
else diagnostics.push({
|
|
2652
|
+
level: "error",
|
|
2653
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2654
|
+
message: `Invalid qtiVersion: "${config.qtiVersion}". Must be "2.1" or "2.2".`,
|
|
2655
|
+
file: "qtiVersion"
|
|
2656
|
+
});
|
|
2657
|
+
}
|
|
2658
|
+
if ("outputFormat" in config) {
|
|
2659
|
+
if (typeof config.outputFormat === "string" && VALID_OUTPUT_FORMATS.includes(config.outputFormat)) valid.outputFormat = config.outputFormat;
|
|
2660
|
+
else diagnostics.push({
|
|
2661
|
+
level: "error",
|
|
2662
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2663
|
+
message: `Invalid outputFormat: "${config.outputFormat}". Must be "dir", "zip", or "stdout".`,
|
|
2664
|
+
file: "outputFormat"
|
|
2665
|
+
});
|
|
2666
|
+
}
|
|
2667
|
+
if ("diagnostics" in config) {
|
|
2668
|
+
if (typeof config.diagnostics === "string" && VALID_DIAGNOSTICS_OUTPUTS.includes(config.diagnostics)) valid.diagnostics = config.diagnostics;
|
|
2669
|
+
else diagnostics.push({
|
|
2670
|
+
level: "error",
|
|
2671
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2672
|
+
message: `Invalid diagnostics: "${config.diagnostics}". Must be "stderr", "file", "both", or "none".`,
|
|
2673
|
+
file: "diagnostics"
|
|
2674
|
+
});
|
|
2675
|
+
}
|
|
2676
|
+
if ("pretty" in config) {
|
|
2677
|
+
if (typeof config.pretty === "boolean") valid.pretty = config.pretty;
|
|
2678
|
+
else diagnostics.push({
|
|
2679
|
+
level: "error",
|
|
2680
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2681
|
+
message: `Invalid pretty: "${config.pretty}". Must be boolean.`,
|
|
2682
|
+
file: "pretty"
|
|
2683
|
+
});
|
|
2684
|
+
}
|
|
2685
|
+
if ("verbose" in config) {
|
|
2686
|
+
if (typeof config.verbose === "boolean") valid.verbose = config.verbose;
|
|
2687
|
+
else diagnostics.push({
|
|
2688
|
+
level: "error",
|
|
2689
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2690
|
+
message: `Invalid verbose: "${config.verbose}". Must be boolean.`,
|
|
2691
|
+
file: "verbose"
|
|
2692
|
+
});
|
|
2693
|
+
}
|
|
2694
|
+
if ("output" in config) {
|
|
2695
|
+
if (typeof config.output === "string") valid.output = config.output;
|
|
2696
|
+
else diagnostics.push({
|
|
2697
|
+
level: "error",
|
|
2698
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2699
|
+
message: `Invalid output: "${config.output}". Must be string.`,
|
|
2700
|
+
file: "output"
|
|
2701
|
+
});
|
|
2702
|
+
}
|
|
2703
|
+
if ("organisationId" in config) {
|
|
2704
|
+
if (typeof config.organisationId === "number" && Number.isInteger(config.organisationId)) valid.organisationId = config.organisationId;
|
|
2705
|
+
else diagnostics.push({
|
|
2706
|
+
level: "error",
|
|
2707
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2708
|
+
message: `Invalid organisationId: "${config.organisationId}". Must be an integer.`,
|
|
2709
|
+
file: "organisationId"
|
|
2710
|
+
});
|
|
2711
|
+
}
|
|
2712
|
+
if ("mediaVault" in config) {
|
|
2713
|
+
if (typeof config.mediaVault === "boolean") valid.mediaVault = config.mediaVault;
|
|
2714
|
+
else diagnostics.push({
|
|
2715
|
+
level: "error",
|
|
2716
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2717
|
+
message: `Invalid mediaVault: "${config.mediaVault}". Must be boolean.`,
|
|
2718
|
+
file: "mediaVault"
|
|
2719
|
+
});
|
|
2720
|
+
}
|
|
2721
|
+
if ("customAssetUrl" in config) {
|
|
2722
|
+
if (typeof config.customAssetUrl === "string") valid.customAssetUrl = config.customAssetUrl;
|
|
2723
|
+
else diagnostics.push({
|
|
2724
|
+
level: "error",
|
|
2725
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2726
|
+
message: `Invalid customAssetUrl: "${config.customAssetUrl}". Must be string.`,
|
|
2727
|
+
file: "customAssetUrl"
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2730
|
+
if ("preserveAssetFilenames" in config) {
|
|
2731
|
+
if (typeof config.preserveAssetFilenames === "boolean") valid.preserveAssetFilenames = config.preserveAssetFilenames;
|
|
2732
|
+
else diagnostics.push({
|
|
2733
|
+
level: "error",
|
|
2734
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2735
|
+
message: `Invalid preserveAssetFilenames: "${String(config.preserveAssetFilenames)}". Must be boolean.`,
|
|
2736
|
+
file: "preserveAssetFilenames"
|
|
2737
|
+
});
|
|
2738
|
+
}
|
|
2739
|
+
if ("itemReferenceSource" in config) {
|
|
2740
|
+
if (typeof config.itemReferenceSource === "string" && VALID_ITEM_REFERENCE_SOURCES.includes(config.itemReferenceSource)) valid.itemReferenceSource = config.itemReferenceSource;
|
|
2741
|
+
else diagnostics.push({
|
|
2742
|
+
level: "error",
|
|
2743
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2744
|
+
message: `Invalid itemReferenceSource: "${String(config.itemReferenceSource)}". Must be "itemIdentifier", "qti", "sourceFilename", or "uuid".`,
|
|
2745
|
+
file: "itemReferenceSource"
|
|
2746
|
+
});
|
|
2747
|
+
}
|
|
2748
|
+
if ("truncateTags" in config) {
|
|
2749
|
+
if (typeof config.truncateTags === "boolean") valid.truncateTags = config.truncateTags;
|
|
2750
|
+
else diagnostics.push({
|
|
2751
|
+
level: "error",
|
|
2752
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2753
|
+
message: `Invalid truncateTags: "${config.truncateTags}". Must be boolean.`,
|
|
2754
|
+
file: "truncateTags"
|
|
2755
|
+
});
|
|
2756
|
+
}
|
|
2757
|
+
if ("splitCsvTags" in config) {
|
|
2758
|
+
if (typeof config.splitCsvTags === "boolean") valid.splitCsvTags = config.splitCsvTags;
|
|
2759
|
+
else diagnostics.push({
|
|
2760
|
+
level: "error",
|
|
2761
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2762
|
+
message: `Invalid splitCsvTags: "${String(config.splitCsvTags)}". Must be boolean.`,
|
|
2763
|
+
file: "splitCsvTags"
|
|
2764
|
+
});
|
|
2765
|
+
}
|
|
2766
|
+
if ("itemFilenameSource" in config) {
|
|
2767
|
+
if (typeof config.itemFilenameSource === "string" && VALID_ITEM_FILENAME_SOURCES.includes(config.itemFilenameSource)) valid.itemFilenameSource = config.itemFilenameSource;
|
|
2768
|
+
else diagnostics.push({
|
|
2769
|
+
level: "error",
|
|
2770
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2771
|
+
message: `Invalid itemFilenameSource: "${String(config.itemFilenameSource)}". Must be "itemIdentifier", "qti", or "sourceFilename".`,
|
|
2772
|
+
file: "itemFilenameSource"
|
|
2773
|
+
});
|
|
2774
|
+
}
|
|
2775
|
+
return {
|
|
2776
|
+
valid,
|
|
2777
|
+
diagnostics
|
|
2778
|
+
};
|
|
2779
|
+
}
|
|
2780
|
+
// src/options/loadConfig.ts
|
|
2781
|
+
/**
|
|
2782
|
+
* Load config from file path
|
|
2783
|
+
*/
|
|
2784
|
+
async function loadConfigFromPath(configPath) {
|
|
2785
|
+
const diagnostics = [];
|
|
2786
|
+
const absolutePath = resolve(configPath);
|
|
2787
|
+
try {
|
|
2788
|
+
await access(absolutePath);
|
|
2789
|
+
} catch {
|
|
2790
|
+
diagnostics.push({
|
|
2791
|
+
level: "error",
|
|
2792
|
+
code: DiagnosticCode.CONFIG_FILE_NOT_FOUND,
|
|
2793
|
+
message: `Config file not found: ${absolutePath}`,
|
|
2794
|
+
file: "",
|
|
2795
|
+
context: { configPath: absolutePath }
|
|
2796
|
+
});
|
|
2797
|
+
return {
|
|
2798
|
+
config: null,
|
|
2799
|
+
diagnostics,
|
|
2800
|
+
configPath: null
|
|
2801
|
+
};
|
|
2802
|
+
}
|
|
2803
|
+
let content;
|
|
2804
|
+
try {
|
|
2805
|
+
content = await readFile(absolutePath, "utf-8");
|
|
2806
|
+
} catch (error) {
|
|
2807
|
+
diagnostics.push({
|
|
2808
|
+
level: "error",
|
|
2809
|
+
code: DiagnosticCode.CONFIG_FILE_NOT_FOUND,
|
|
2810
|
+
message: `Failed to read config file: ${error instanceof Error ? error.message : "unknown error"}`,
|
|
2811
|
+
file: "",
|
|
2812
|
+
context: { configPath: absolutePath }
|
|
2813
|
+
});
|
|
2814
|
+
return {
|
|
2815
|
+
config: null,
|
|
2816
|
+
diagnostics,
|
|
2817
|
+
configPath: null
|
|
2818
|
+
};
|
|
2819
|
+
}
|
|
2820
|
+
let parsed;
|
|
2821
|
+
try {
|
|
2822
|
+
parsed = JSON.parse(content);
|
|
2823
|
+
} catch (error) {
|
|
2824
|
+
diagnostics.push({
|
|
2825
|
+
level: "error",
|
|
2826
|
+
code: DiagnosticCode.CONFIG_FILE_INVALID_JSON,
|
|
2827
|
+
message: `Invalid JSON in config file: ${error instanceof Error ? error.message : "unknown error"}`,
|
|
2828
|
+
file: "",
|
|
2829
|
+
context: { configPath: absolutePath }
|
|
2830
|
+
});
|
|
2831
|
+
return {
|
|
2832
|
+
config: null,
|
|
2833
|
+
diagnostics,
|
|
2834
|
+
configPath: null
|
|
2835
|
+
};
|
|
2836
|
+
}
|
|
2837
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
2838
|
+
diagnostics.push({
|
|
2839
|
+
level: "error",
|
|
2840
|
+
code: DiagnosticCode.CONFIG_SCHEMA_INVALID,
|
|
2841
|
+
message: "Config file must be a JSON object",
|
|
2842
|
+
file: "",
|
|
2843
|
+
context: { configPath: absolutePath }
|
|
2844
|
+
});
|
|
2845
|
+
return {
|
|
2846
|
+
config: null,
|
|
2847
|
+
diagnostics,
|
|
2848
|
+
configPath: null
|
|
2849
|
+
};
|
|
2850
|
+
}
|
|
2851
|
+
const { valid, diagnostics: validationDiagnostics } = validateConfig(parsed);
|
|
2852
|
+
diagnostics.push(...validationDiagnostics);
|
|
2853
|
+
if (diagnostics.some((d) => d.level === "error")) return {
|
|
2854
|
+
config: null,
|
|
2855
|
+
diagnostics,
|
|
2856
|
+
configPath: null
|
|
2857
|
+
};
|
|
2858
|
+
diagnostics.push({
|
|
2859
|
+
level: "info",
|
|
2860
|
+
code: DiagnosticCode.CONFIG_LOADED,
|
|
2861
|
+
message: `Config loaded from ${absolutePath}`,
|
|
2862
|
+
file: "",
|
|
2863
|
+
context: { configPath: absolutePath }
|
|
2864
|
+
});
|
|
2865
|
+
return {
|
|
2866
|
+
config: valid,
|
|
2867
|
+
diagnostics,
|
|
2868
|
+
configPath: absolutePath
|
|
2869
|
+
};
|
|
2870
|
+
}
|
|
2871
|
+
/**
|
|
2872
|
+
* Load config with discovery (default path or explicit)
|
|
2873
|
+
*/
|
|
2874
|
+
async function loadConfig(explicitPath, noConfig) {
|
|
2875
|
+
const diagnostics = [];
|
|
2876
|
+
if (noConfig) {
|
|
2877
|
+
diagnostics.push({
|
|
2878
|
+
level: "info",
|
|
2879
|
+
code: DiagnosticCode.CONFIG_DISABLED,
|
|
2880
|
+
message: "Config loading disabled via --no-config",
|
|
2881
|
+
file: ""
|
|
2882
|
+
});
|
|
2883
|
+
return {
|
|
2884
|
+
config: null,
|
|
2885
|
+
diagnostics,
|
|
2886
|
+
configPath: null
|
|
2887
|
+
};
|
|
2888
|
+
}
|
|
2889
|
+
if (explicitPath) return loadConfigFromPath(explicitPath);
|
|
2890
|
+
const defaultPath = resolve(process.cwd(), "lrn-converter.config.json");
|
|
2891
|
+
try {
|
|
2892
|
+
await access(defaultPath);
|
|
2893
|
+
return loadConfigFromPath(defaultPath);
|
|
2894
|
+
} catch {
|
|
2895
|
+
return {
|
|
2896
|
+
config: null,
|
|
2897
|
+
diagnostics: [],
|
|
2898
|
+
configPath: null
|
|
2899
|
+
};
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
// src/utils/pathUtils.ts
|
|
2903
|
+
/**
|
|
2904
|
+
* Expand tilde (~) to home directory in paths.
|
|
2905
|
+
*
|
|
2906
|
+
* Handles:
|
|
2907
|
+
* - `~/path` → `/home/user/path`
|
|
2908
|
+
* - `~` → `/home/user`
|
|
2909
|
+
*
|
|
2910
|
+
* Does NOT handle `~username/path` syntax (returns unchanged).
|
|
2911
|
+
*
|
|
2912
|
+
* @param filePath - The file path that may contain a tilde
|
|
2913
|
+
* @returns The path with tilde expanded to home directory
|
|
2914
|
+
*/
|
|
2915
|
+
function expandTilde(filePath) {
|
|
2916
|
+
if (filePath.startsWith("~/")) return filePath.replace("~", homedir());
|
|
2917
|
+
if (filePath === "~") return homedir();
|
|
2918
|
+
return filePath;
|
|
2919
|
+
}
|
|
2920
|
+
export { stringWidth as a, boxen as i, loadConfig as n, dist_default as o, showBanner as r, expandTilde as t };
|
|
2921
|
+
|
|
2922
|
+
//# sourceMappingURL=pathUtils-I2bRHUwu.js.map
|