@ind3x/cli-screens 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +230 -0
- package/dist/index.d.ts +312 -0
- package/dist/index.js +2734 -0
- package/package.json +43 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2734 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
39
|
+
|
|
40
|
+
// node:buffer
|
|
41
|
+
var exports_buffer = {};
|
|
42
|
+
__export(exports_buffer, {
|
|
43
|
+
transcode: () => transcode,
|
|
44
|
+
resolveObjectURL: () => resolveObjectURL,
|
|
45
|
+
kStringMaxLength: () => kStringMaxLength,
|
|
46
|
+
kMaxLength: () => kMaxLength,
|
|
47
|
+
isUtf8: () => isUtf8,
|
|
48
|
+
isAscii: () => isAscii,
|
|
49
|
+
default: () => buffer_default,
|
|
50
|
+
constants: () => constants,
|
|
51
|
+
btoa: () => btoa,
|
|
52
|
+
atob: () => atob,
|
|
53
|
+
INSPECT_MAX_BYTES: () => INSPECT_MAX_BYTES,
|
|
54
|
+
File: () => File,
|
|
55
|
+
Buffer: () => Buffer2,
|
|
56
|
+
Blob: () => Blob
|
|
57
|
+
});
|
|
58
|
+
function getLens(b64) {
|
|
59
|
+
var len2 = b64.length;
|
|
60
|
+
if (len2 % 4 > 0)
|
|
61
|
+
throw Error("Invalid string. Length must be a multiple of 4");
|
|
62
|
+
var validLen = b64.indexOf("=");
|
|
63
|
+
if (validLen === -1)
|
|
64
|
+
validLen = len2;
|
|
65
|
+
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
66
|
+
return [validLen, placeHoldersLen];
|
|
67
|
+
}
|
|
68
|
+
function _byteLength(validLen, placeHoldersLen) {
|
|
69
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
70
|
+
}
|
|
71
|
+
function toByteArray(b64) {
|
|
72
|
+
var tmp, lens = getLens(b64), validLen = lens[0], placeHoldersLen = lens[1], arr = new Uint8Array(_byteLength(validLen, placeHoldersLen)), curByte = 0, len2 = placeHoldersLen > 0 ? validLen - 4 : validLen, i2;
|
|
73
|
+
for (i2 = 0;i2 < len2; i2 += 4)
|
|
74
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)], arr[curByte++] = tmp >> 16 & 255, arr[curByte++] = tmp >> 8 & 255, arr[curByte++] = tmp & 255;
|
|
75
|
+
if (placeHoldersLen === 2)
|
|
76
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4, arr[curByte++] = tmp & 255;
|
|
77
|
+
if (placeHoldersLen === 1)
|
|
78
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2, arr[curByte++] = tmp >> 8 & 255, arr[curByte++] = tmp & 255;
|
|
79
|
+
return arr;
|
|
80
|
+
}
|
|
81
|
+
function tripletToBase64(num) {
|
|
82
|
+
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
83
|
+
}
|
|
84
|
+
function encodeChunk(uint8, start, end) {
|
|
85
|
+
var tmp, output = [];
|
|
86
|
+
for (var i2 = start;i2 < end; i2 += 3)
|
|
87
|
+
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255), output.push(tripletToBase64(tmp));
|
|
88
|
+
return output.join("");
|
|
89
|
+
}
|
|
90
|
+
function fromByteArray(uint8) {
|
|
91
|
+
var tmp, len2 = uint8.length, extraBytes = len2 % 3, parts = [], maxChunkLength = 16383;
|
|
92
|
+
for (var i2 = 0, len22 = len2 - extraBytes;i2 < len22; i2 += maxChunkLength)
|
|
93
|
+
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
|
|
94
|
+
if (extraBytes === 1)
|
|
95
|
+
tmp = uint8[len2 - 1], parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
|
|
96
|
+
else if (extraBytes === 2)
|
|
97
|
+
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1], parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "=");
|
|
98
|
+
return parts.join("");
|
|
99
|
+
}
|
|
100
|
+
function read(buffer, offset, isLE, mLen, nBytes) {
|
|
101
|
+
var e, m, eLen = nBytes * 8 - mLen - 1, eMax = (1 << eLen) - 1, eBias = eMax >> 1, nBits = -7, i2 = isLE ? nBytes - 1 : 0, d = isLE ? -1 : 1, s = buffer[offset + i2];
|
|
102
|
+
i2 += d, e = s & (1 << -nBits) - 1, s >>= -nBits, nBits += eLen;
|
|
103
|
+
for (;nBits > 0; e = e * 256 + buffer[offset + i2], i2 += d, nBits -= 8)
|
|
104
|
+
;
|
|
105
|
+
m = e & (1 << -nBits) - 1, e >>= -nBits, nBits += mLen;
|
|
106
|
+
for (;nBits > 0; m = m * 256 + buffer[offset + i2], i2 += d, nBits -= 8)
|
|
107
|
+
;
|
|
108
|
+
if (e === 0)
|
|
109
|
+
e = 1 - eBias;
|
|
110
|
+
else if (e === eMax)
|
|
111
|
+
return m ? NaN : (s ? -1 : 1) * (1 / 0);
|
|
112
|
+
else
|
|
113
|
+
m = m + Math.pow(2, mLen), e = e - eBias;
|
|
114
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
115
|
+
}
|
|
116
|
+
function write(buffer, value, offset, isLE, mLen, nBytes) {
|
|
117
|
+
var e, m, c, eLen = nBytes * 8 - mLen - 1, eMax = (1 << eLen) - 1, eBias = eMax >> 1, rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, i2 = isLE ? 0 : nBytes - 1, d = isLE ? 1 : -1, s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
118
|
+
if (value = Math.abs(value), isNaN(value) || value === 1 / 0)
|
|
119
|
+
m = isNaN(value) ? 1 : 0, e = eMax;
|
|
120
|
+
else {
|
|
121
|
+
if (e = Math.floor(Math.log(value) / Math.LN2), value * (c = Math.pow(2, -e)) < 1)
|
|
122
|
+
e--, c *= 2;
|
|
123
|
+
if (e + eBias >= 1)
|
|
124
|
+
value += rt / c;
|
|
125
|
+
else
|
|
126
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
127
|
+
if (value * c >= 2)
|
|
128
|
+
e++, c /= 2;
|
|
129
|
+
if (e + eBias >= eMax)
|
|
130
|
+
m = 0, e = eMax;
|
|
131
|
+
else if (e + eBias >= 1)
|
|
132
|
+
m = (value * c - 1) * Math.pow(2, mLen), e = e + eBias;
|
|
133
|
+
else
|
|
134
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen), e = 0;
|
|
135
|
+
}
|
|
136
|
+
for (;mLen >= 8; buffer[offset + i2] = m & 255, i2 += d, m /= 256, mLen -= 8)
|
|
137
|
+
;
|
|
138
|
+
e = e << mLen | m, eLen += mLen;
|
|
139
|
+
for (;eLen > 0; buffer[offset + i2] = e & 255, i2 += d, e /= 256, eLen -= 8)
|
|
140
|
+
;
|
|
141
|
+
buffer[offset + i2 - d] |= s * 128;
|
|
142
|
+
}
|
|
143
|
+
function createBuffer(length) {
|
|
144
|
+
if (length > kMaxLength)
|
|
145
|
+
throw RangeError('The value "' + length + '" is invalid for option "size"');
|
|
146
|
+
let buf = new Uint8Array(length);
|
|
147
|
+
return Object.setPrototypeOf(buf, Buffer2.prototype), buf;
|
|
148
|
+
}
|
|
149
|
+
function E(sym, getMessage, Base) {
|
|
150
|
+
return class extends Base {
|
|
151
|
+
constructor() {
|
|
152
|
+
super();
|
|
153
|
+
Object.defineProperty(this, "message", { value: getMessage.apply(this, arguments), writable: true, configurable: true }), this.name = `${this.name} [${sym}]`, this.stack, delete this.name;
|
|
154
|
+
}
|
|
155
|
+
get code() {
|
|
156
|
+
return sym;
|
|
157
|
+
}
|
|
158
|
+
set code(value) {
|
|
159
|
+
Object.defineProperty(this, "code", { configurable: true, enumerable: true, value, writable: true });
|
|
160
|
+
}
|
|
161
|
+
toString() {
|
|
162
|
+
return `${this.name} [${sym}]: ${this.message}`;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function Buffer2(arg, encodingOrOffset, length) {
|
|
167
|
+
if (typeof arg === "number") {
|
|
168
|
+
if (typeof encodingOrOffset === "string")
|
|
169
|
+
throw TypeError('The "string" argument must be of type string. Received type number');
|
|
170
|
+
return allocUnsafe(arg);
|
|
171
|
+
}
|
|
172
|
+
return from(arg, encodingOrOffset, length);
|
|
173
|
+
}
|
|
174
|
+
function from(value, encodingOrOffset, length) {
|
|
175
|
+
if (typeof value === "string")
|
|
176
|
+
return fromString(value, encodingOrOffset);
|
|
177
|
+
if (ArrayBuffer.isView(value))
|
|
178
|
+
return fromArrayView(value);
|
|
179
|
+
if (value == null)
|
|
180
|
+
throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
|
|
181
|
+
if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer))
|
|
182
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
183
|
+
if (typeof SharedArrayBuffer < "u" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer)))
|
|
184
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
185
|
+
if (typeof value === "number")
|
|
186
|
+
throw TypeError('The "value" argument must not be of type number. Received type number');
|
|
187
|
+
let valueOf = value.valueOf && value.valueOf();
|
|
188
|
+
if (valueOf != null && valueOf !== value)
|
|
189
|
+
return Buffer2.from(valueOf, encodingOrOffset, length);
|
|
190
|
+
let b = fromObject(value);
|
|
191
|
+
if (b)
|
|
192
|
+
return b;
|
|
193
|
+
if (typeof Symbol < "u" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function")
|
|
194
|
+
return Buffer2.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length);
|
|
195
|
+
throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
|
|
196
|
+
}
|
|
197
|
+
function assertSize(size) {
|
|
198
|
+
if (typeof size !== "number")
|
|
199
|
+
throw TypeError('"size" argument must be of type number');
|
|
200
|
+
else if (size < 0)
|
|
201
|
+
throw RangeError('The value "' + size + '" is invalid for option "size"');
|
|
202
|
+
}
|
|
203
|
+
function alloc(size, fill, encoding) {
|
|
204
|
+
if (assertSize(size), size <= 0)
|
|
205
|
+
return createBuffer(size);
|
|
206
|
+
if (fill !== undefined)
|
|
207
|
+
return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
|
|
208
|
+
return createBuffer(size);
|
|
209
|
+
}
|
|
210
|
+
function allocUnsafe(size) {
|
|
211
|
+
return assertSize(size), createBuffer(size < 0 ? 0 : checked(size) | 0);
|
|
212
|
+
}
|
|
213
|
+
function fromString(string, encoding) {
|
|
214
|
+
if (typeof encoding !== "string" || encoding === "")
|
|
215
|
+
encoding = "utf8";
|
|
216
|
+
if (!Buffer2.isEncoding(encoding))
|
|
217
|
+
throw TypeError("Unknown encoding: " + encoding);
|
|
218
|
+
let length = byteLength(string, encoding) | 0, buf = createBuffer(length), actual = buf.write(string, encoding);
|
|
219
|
+
if (actual !== length)
|
|
220
|
+
buf = buf.slice(0, actual);
|
|
221
|
+
return buf;
|
|
222
|
+
}
|
|
223
|
+
function fromArrayLike(array) {
|
|
224
|
+
let length = array.length < 0 ? 0 : checked(array.length) | 0, buf = createBuffer(length);
|
|
225
|
+
for (let i2 = 0;i2 < length; i2 += 1)
|
|
226
|
+
buf[i2] = array[i2] & 255;
|
|
227
|
+
return buf;
|
|
228
|
+
}
|
|
229
|
+
function fromArrayView(arrayView) {
|
|
230
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
231
|
+
let copy = new Uint8Array(arrayView);
|
|
232
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
|
|
233
|
+
}
|
|
234
|
+
return fromArrayLike(arrayView);
|
|
235
|
+
}
|
|
236
|
+
function fromArrayBuffer(array, byteOffset, length) {
|
|
237
|
+
if (byteOffset < 0 || array.byteLength < byteOffset)
|
|
238
|
+
throw RangeError('"offset" is outside of buffer bounds');
|
|
239
|
+
if (array.byteLength < byteOffset + (length || 0))
|
|
240
|
+
throw RangeError('"length" is outside of buffer bounds');
|
|
241
|
+
let buf;
|
|
242
|
+
if (byteOffset === undefined && length === undefined)
|
|
243
|
+
buf = new Uint8Array(array);
|
|
244
|
+
else if (length === undefined)
|
|
245
|
+
buf = new Uint8Array(array, byteOffset);
|
|
246
|
+
else
|
|
247
|
+
buf = new Uint8Array(array, byteOffset, length);
|
|
248
|
+
return Object.setPrototypeOf(buf, Buffer2.prototype), buf;
|
|
249
|
+
}
|
|
250
|
+
function fromObject(obj) {
|
|
251
|
+
if (Buffer2.isBuffer(obj)) {
|
|
252
|
+
let len2 = checked(obj.length) | 0, buf = createBuffer(len2);
|
|
253
|
+
if (buf.length === 0)
|
|
254
|
+
return buf;
|
|
255
|
+
return obj.copy(buf, 0, 0, len2), buf;
|
|
256
|
+
}
|
|
257
|
+
if (obj.length !== undefined) {
|
|
258
|
+
if (typeof obj.length !== "number" || Number.isNaN(obj.length))
|
|
259
|
+
return createBuffer(0);
|
|
260
|
+
return fromArrayLike(obj);
|
|
261
|
+
}
|
|
262
|
+
if (obj.type === "Buffer" && Array.isArray(obj.data))
|
|
263
|
+
return fromArrayLike(obj.data);
|
|
264
|
+
}
|
|
265
|
+
function checked(length) {
|
|
266
|
+
if (length >= kMaxLength)
|
|
267
|
+
throw RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + kMaxLength.toString(16) + " bytes");
|
|
268
|
+
return length | 0;
|
|
269
|
+
}
|
|
270
|
+
function byteLength(string, encoding) {
|
|
271
|
+
if (Buffer2.isBuffer(string))
|
|
272
|
+
return string.length;
|
|
273
|
+
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer))
|
|
274
|
+
return string.byteLength;
|
|
275
|
+
if (typeof string !== "string")
|
|
276
|
+
throw TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string);
|
|
277
|
+
let len2 = string.length, mustMatch = arguments.length > 2 && arguments[2] === true;
|
|
278
|
+
if (!mustMatch && len2 === 0)
|
|
279
|
+
return 0;
|
|
280
|
+
let loweredCase = false;
|
|
281
|
+
for (;; )
|
|
282
|
+
switch (encoding) {
|
|
283
|
+
case "ascii":
|
|
284
|
+
case "latin1":
|
|
285
|
+
case "binary":
|
|
286
|
+
return len2;
|
|
287
|
+
case "utf8":
|
|
288
|
+
case "utf-8":
|
|
289
|
+
return utf8ToBytes(string).length;
|
|
290
|
+
case "ucs2":
|
|
291
|
+
case "ucs-2":
|
|
292
|
+
case "utf16le":
|
|
293
|
+
case "utf-16le":
|
|
294
|
+
return len2 * 2;
|
|
295
|
+
case "hex":
|
|
296
|
+
return len2 >>> 1;
|
|
297
|
+
case "base64":
|
|
298
|
+
return base64ToBytes(string).length;
|
|
299
|
+
default:
|
|
300
|
+
if (loweredCase)
|
|
301
|
+
return mustMatch ? -1 : utf8ToBytes(string).length;
|
|
302
|
+
encoding = ("" + encoding).toLowerCase(), loweredCase = true;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function slowToString(encoding, start, end) {
|
|
306
|
+
let loweredCase = false;
|
|
307
|
+
if (start === undefined || start < 0)
|
|
308
|
+
start = 0;
|
|
309
|
+
if (start > this.length)
|
|
310
|
+
return "";
|
|
311
|
+
if (end === undefined || end > this.length)
|
|
312
|
+
end = this.length;
|
|
313
|
+
if (end <= 0)
|
|
314
|
+
return "";
|
|
315
|
+
if (end >>>= 0, start >>>= 0, end <= start)
|
|
316
|
+
return "";
|
|
317
|
+
if (!encoding)
|
|
318
|
+
encoding = "utf8";
|
|
319
|
+
while (true)
|
|
320
|
+
switch (encoding) {
|
|
321
|
+
case "hex":
|
|
322
|
+
return hexSlice(this, start, end);
|
|
323
|
+
case "utf8":
|
|
324
|
+
case "utf-8":
|
|
325
|
+
return utf8Slice(this, start, end);
|
|
326
|
+
case "ascii":
|
|
327
|
+
return asciiSlice(this, start, end);
|
|
328
|
+
case "latin1":
|
|
329
|
+
case "binary":
|
|
330
|
+
return latin1Slice(this, start, end);
|
|
331
|
+
case "base64":
|
|
332
|
+
return base64Slice(this, start, end);
|
|
333
|
+
case "ucs2":
|
|
334
|
+
case "ucs-2":
|
|
335
|
+
case "utf16le":
|
|
336
|
+
case "utf-16le":
|
|
337
|
+
return utf16leSlice(this, start, end);
|
|
338
|
+
default:
|
|
339
|
+
if (loweredCase)
|
|
340
|
+
throw TypeError("Unknown encoding: " + encoding);
|
|
341
|
+
encoding = (encoding + "").toLowerCase(), loweredCase = true;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function swap(b, n, m) {
|
|
345
|
+
let i2 = b[n];
|
|
346
|
+
b[n] = b[m], b[m] = i2;
|
|
347
|
+
}
|
|
348
|
+
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
|
|
349
|
+
if (buffer.length === 0)
|
|
350
|
+
return -1;
|
|
351
|
+
if (typeof byteOffset === "string")
|
|
352
|
+
encoding = byteOffset, byteOffset = 0;
|
|
353
|
+
else if (byteOffset > 2147483647)
|
|
354
|
+
byteOffset = 2147483647;
|
|
355
|
+
else if (byteOffset < -2147483648)
|
|
356
|
+
byteOffset = -2147483648;
|
|
357
|
+
if (byteOffset = +byteOffset, Number.isNaN(byteOffset))
|
|
358
|
+
byteOffset = dir ? 0 : buffer.length - 1;
|
|
359
|
+
if (byteOffset < 0)
|
|
360
|
+
byteOffset = buffer.length + byteOffset;
|
|
361
|
+
if (byteOffset >= buffer.length)
|
|
362
|
+
if (dir)
|
|
363
|
+
return -1;
|
|
364
|
+
else
|
|
365
|
+
byteOffset = buffer.length - 1;
|
|
366
|
+
else if (byteOffset < 0)
|
|
367
|
+
if (dir)
|
|
368
|
+
byteOffset = 0;
|
|
369
|
+
else
|
|
370
|
+
return -1;
|
|
371
|
+
if (typeof val === "string")
|
|
372
|
+
val = Buffer2.from(val, encoding);
|
|
373
|
+
if (Buffer2.isBuffer(val)) {
|
|
374
|
+
if (val.length === 0)
|
|
375
|
+
return -1;
|
|
376
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
|
|
377
|
+
} else if (typeof val === "number") {
|
|
378
|
+
if (val = val & 255, typeof Uint8Array.prototype.indexOf === "function")
|
|
379
|
+
if (dir)
|
|
380
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
|
|
381
|
+
else
|
|
382
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
|
|
383
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
|
|
384
|
+
}
|
|
385
|
+
throw TypeError("val must be string, number or Buffer");
|
|
386
|
+
}
|
|
387
|
+
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
|
388
|
+
let indexSize = 1, arrLength = arr.length, valLength = val.length;
|
|
389
|
+
if (encoding !== undefined) {
|
|
390
|
+
if (encoding = String(encoding).toLowerCase(), encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
|
|
391
|
+
if (arr.length < 2 || val.length < 2)
|
|
392
|
+
return -1;
|
|
393
|
+
indexSize = 2, arrLength /= 2, valLength /= 2, byteOffset /= 2;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function read2(buf, i3) {
|
|
397
|
+
if (indexSize === 1)
|
|
398
|
+
return buf[i3];
|
|
399
|
+
else
|
|
400
|
+
return buf.readUInt16BE(i3 * indexSize);
|
|
401
|
+
}
|
|
402
|
+
let i2;
|
|
403
|
+
if (dir) {
|
|
404
|
+
let foundIndex = -1;
|
|
405
|
+
for (i2 = byteOffset;i2 < arrLength; i2++)
|
|
406
|
+
if (read2(arr, i2) === read2(val, foundIndex === -1 ? 0 : i2 - foundIndex)) {
|
|
407
|
+
if (foundIndex === -1)
|
|
408
|
+
foundIndex = i2;
|
|
409
|
+
if (i2 - foundIndex + 1 === valLength)
|
|
410
|
+
return foundIndex * indexSize;
|
|
411
|
+
} else {
|
|
412
|
+
if (foundIndex !== -1)
|
|
413
|
+
i2 -= i2 - foundIndex;
|
|
414
|
+
foundIndex = -1;
|
|
415
|
+
}
|
|
416
|
+
} else {
|
|
417
|
+
if (byteOffset + valLength > arrLength)
|
|
418
|
+
byteOffset = arrLength - valLength;
|
|
419
|
+
for (i2 = byteOffset;i2 >= 0; i2--) {
|
|
420
|
+
let found = true;
|
|
421
|
+
for (let j = 0;j < valLength; j++)
|
|
422
|
+
if (read2(arr, i2 + j) !== read2(val, j)) {
|
|
423
|
+
found = false;
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
if (found)
|
|
427
|
+
return i2;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return -1;
|
|
431
|
+
}
|
|
432
|
+
function hexWrite(buf, string, offset, length) {
|
|
433
|
+
offset = Number(offset) || 0;
|
|
434
|
+
let remaining = buf.length - offset;
|
|
435
|
+
if (!length)
|
|
436
|
+
length = remaining;
|
|
437
|
+
else if (length = Number(length), length > remaining)
|
|
438
|
+
length = remaining;
|
|
439
|
+
let strLen = string.length;
|
|
440
|
+
if (length > strLen / 2)
|
|
441
|
+
length = strLen / 2;
|
|
442
|
+
let i2;
|
|
443
|
+
for (i2 = 0;i2 < length; ++i2) {
|
|
444
|
+
let parsed = parseInt(string.substr(i2 * 2, 2), 16);
|
|
445
|
+
if (Number.isNaN(parsed))
|
|
446
|
+
return i2;
|
|
447
|
+
buf[offset + i2] = parsed;
|
|
448
|
+
}
|
|
449
|
+
return i2;
|
|
450
|
+
}
|
|
451
|
+
function utf8Write(buf, string, offset, length) {
|
|
452
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
|
|
453
|
+
}
|
|
454
|
+
function asciiWrite(buf, string, offset, length) {
|
|
455
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length);
|
|
456
|
+
}
|
|
457
|
+
function base64Write(buf, string, offset, length) {
|
|
458
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length);
|
|
459
|
+
}
|
|
460
|
+
function ucs2Write(buf, string, offset, length) {
|
|
461
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
|
|
462
|
+
}
|
|
463
|
+
function base64Slice(buf, start, end) {
|
|
464
|
+
if (start === 0 && end === buf.length)
|
|
465
|
+
return fromByteArray(buf);
|
|
466
|
+
else
|
|
467
|
+
return fromByteArray(buf.slice(start, end));
|
|
468
|
+
}
|
|
469
|
+
function utf8Slice(buf, start, end) {
|
|
470
|
+
end = Math.min(buf.length, end);
|
|
471
|
+
let res = [], i2 = start;
|
|
472
|
+
while (i2 < end) {
|
|
473
|
+
let firstByte = buf[i2], codePoint = null, bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
474
|
+
if (i2 + bytesPerSequence <= end) {
|
|
475
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
476
|
+
switch (bytesPerSequence) {
|
|
477
|
+
case 1:
|
|
478
|
+
if (firstByte < 128)
|
|
479
|
+
codePoint = firstByte;
|
|
480
|
+
break;
|
|
481
|
+
case 2:
|
|
482
|
+
if (secondByte = buf[i2 + 1], (secondByte & 192) === 128) {
|
|
483
|
+
if (tempCodePoint = (firstByte & 31) << 6 | secondByte & 63, tempCodePoint > 127)
|
|
484
|
+
codePoint = tempCodePoint;
|
|
485
|
+
}
|
|
486
|
+
break;
|
|
487
|
+
case 3:
|
|
488
|
+
if (secondByte = buf[i2 + 1], thirdByte = buf[i2 + 2], (secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
489
|
+
if (tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63, tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343))
|
|
490
|
+
codePoint = tempCodePoint;
|
|
491
|
+
}
|
|
492
|
+
break;
|
|
493
|
+
case 4:
|
|
494
|
+
if (secondByte = buf[i2 + 1], thirdByte = buf[i2 + 2], fourthByte = buf[i2 + 3], (secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
495
|
+
if (tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63, tempCodePoint > 65535 && tempCodePoint < 1114112)
|
|
496
|
+
codePoint = tempCodePoint;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (codePoint === null)
|
|
501
|
+
codePoint = 65533, bytesPerSequence = 1;
|
|
502
|
+
else if (codePoint > 65535)
|
|
503
|
+
codePoint -= 65536, res.push(codePoint >>> 10 & 1023 | 55296), codePoint = 56320 | codePoint & 1023;
|
|
504
|
+
res.push(codePoint), i2 += bytesPerSequence;
|
|
505
|
+
}
|
|
506
|
+
return decodeCodePointsArray(res);
|
|
507
|
+
}
|
|
508
|
+
function decodeCodePointsArray(codePoints) {
|
|
509
|
+
let len2 = codePoints.length;
|
|
510
|
+
if (len2 <= MAX_ARGUMENTS_LENGTH)
|
|
511
|
+
return String.fromCharCode.apply(String, codePoints);
|
|
512
|
+
let res = "", i2 = 0;
|
|
513
|
+
while (i2 < len2)
|
|
514
|
+
res += String.fromCharCode.apply(String, codePoints.slice(i2, i2 += MAX_ARGUMENTS_LENGTH));
|
|
515
|
+
return res;
|
|
516
|
+
}
|
|
517
|
+
function asciiSlice(buf, start, end) {
|
|
518
|
+
let ret = "";
|
|
519
|
+
end = Math.min(buf.length, end);
|
|
520
|
+
for (let i2 = start;i2 < end; ++i2)
|
|
521
|
+
ret += String.fromCharCode(buf[i2] & 127);
|
|
522
|
+
return ret;
|
|
523
|
+
}
|
|
524
|
+
function latin1Slice(buf, start, end) {
|
|
525
|
+
let ret = "";
|
|
526
|
+
end = Math.min(buf.length, end);
|
|
527
|
+
for (let i2 = start;i2 < end; ++i2)
|
|
528
|
+
ret += String.fromCharCode(buf[i2]);
|
|
529
|
+
return ret;
|
|
530
|
+
}
|
|
531
|
+
function hexSlice(buf, start, end) {
|
|
532
|
+
let len2 = buf.length;
|
|
533
|
+
if (!start || start < 0)
|
|
534
|
+
start = 0;
|
|
535
|
+
if (!end || end < 0 || end > len2)
|
|
536
|
+
end = len2;
|
|
537
|
+
let out = "";
|
|
538
|
+
for (let i2 = start;i2 < end; ++i2)
|
|
539
|
+
out += hexSliceLookupTable[buf[i2]];
|
|
540
|
+
return out;
|
|
541
|
+
}
|
|
542
|
+
function utf16leSlice(buf, start, end) {
|
|
543
|
+
let bytes = buf.slice(start, end), res = "";
|
|
544
|
+
for (let i2 = 0;i2 < bytes.length - 1; i2 += 2)
|
|
545
|
+
res += String.fromCharCode(bytes[i2] + bytes[i2 + 1] * 256);
|
|
546
|
+
return res;
|
|
547
|
+
}
|
|
548
|
+
function checkOffset(offset, ext, length) {
|
|
549
|
+
if (offset % 1 !== 0 || offset < 0)
|
|
550
|
+
throw RangeError("offset is not uint");
|
|
551
|
+
if (offset + ext > length)
|
|
552
|
+
throw RangeError("Trying to access beyond buffer length");
|
|
553
|
+
}
|
|
554
|
+
function checkInt(buf, value, offset, ext, max, min) {
|
|
555
|
+
if (!Buffer2.isBuffer(buf))
|
|
556
|
+
throw TypeError('"buffer" argument must be a Buffer instance');
|
|
557
|
+
if (value > max || value < min)
|
|
558
|
+
throw RangeError('"value" argument is out of bounds');
|
|
559
|
+
if (offset + ext > buf.length)
|
|
560
|
+
throw RangeError("Index out of range");
|
|
561
|
+
}
|
|
562
|
+
function wrtBigUInt64LE(buf, value, offset, min, max) {
|
|
563
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
564
|
+
let lo = Number(value & BigInt(4294967295));
|
|
565
|
+
buf[offset++] = lo, lo = lo >> 8, buf[offset++] = lo, lo = lo >> 8, buf[offset++] = lo, lo = lo >> 8, buf[offset++] = lo;
|
|
566
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
567
|
+
return buf[offset++] = hi, hi = hi >> 8, buf[offset++] = hi, hi = hi >> 8, buf[offset++] = hi, hi = hi >> 8, buf[offset++] = hi, offset;
|
|
568
|
+
}
|
|
569
|
+
function wrtBigUInt64BE(buf, value, offset, min, max) {
|
|
570
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
571
|
+
let lo = Number(value & BigInt(4294967295));
|
|
572
|
+
buf[offset + 7] = lo, lo = lo >> 8, buf[offset + 6] = lo, lo = lo >> 8, buf[offset + 5] = lo, lo = lo >> 8, buf[offset + 4] = lo;
|
|
573
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
574
|
+
return buf[offset + 3] = hi, hi = hi >> 8, buf[offset + 2] = hi, hi = hi >> 8, buf[offset + 1] = hi, hi = hi >> 8, buf[offset] = hi, offset + 8;
|
|
575
|
+
}
|
|
576
|
+
function checkIEEE754(buf, value, offset, ext, max, min) {
|
|
577
|
+
if (offset + ext > buf.length)
|
|
578
|
+
throw RangeError("Index out of range");
|
|
579
|
+
if (offset < 0)
|
|
580
|
+
throw RangeError("Index out of range");
|
|
581
|
+
}
|
|
582
|
+
function writeFloat(buf, value, offset, littleEndian, noAssert) {
|
|
583
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
584
|
+
checkIEEE754(buf, value, offset, 4, 340282346638528860000000000000000000000, -340282346638528860000000000000000000000);
|
|
585
|
+
return write(buf, value, offset, littleEndian, 23, 4), offset + 4;
|
|
586
|
+
}
|
|
587
|
+
function writeDouble(buf, value, offset, littleEndian, noAssert) {
|
|
588
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
589
|
+
checkIEEE754(buf, value, offset, 8, 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, -179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);
|
|
590
|
+
return write(buf, value, offset, littleEndian, 52, 8), offset + 8;
|
|
591
|
+
}
|
|
592
|
+
function addNumericalSeparator(val) {
|
|
593
|
+
let res = "", i2 = val.length, start = val[0] === "-" ? 1 : 0;
|
|
594
|
+
for (;i2 >= start + 4; i2 -= 3)
|
|
595
|
+
res = `_${val.slice(i2 - 3, i2)}${res}`;
|
|
596
|
+
return `${val.slice(0, i2)}${res}`;
|
|
597
|
+
}
|
|
598
|
+
function checkBounds(buf, offset, byteLength2) {
|
|
599
|
+
if (validateNumber(offset, "offset"), buf[offset] === undefined || buf[offset + byteLength2] === undefined)
|
|
600
|
+
boundsError(offset, buf.length - (byteLength2 + 1));
|
|
601
|
+
}
|
|
602
|
+
function checkIntBI(value, min, max, buf, offset, byteLength2) {
|
|
603
|
+
if (value > max || value < min) {
|
|
604
|
+
let n = typeof min === "bigint" ? "n" : "", range;
|
|
605
|
+
if (byteLength2 > 3)
|
|
606
|
+
if (min === 0 || min === BigInt(0))
|
|
607
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`;
|
|
608
|
+
else
|
|
609
|
+
range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength2 + 1) * 8 - 1}${n}`;
|
|
610
|
+
else
|
|
611
|
+
range = `>= ${min}${n} and <= ${max}${n}`;
|
|
612
|
+
throw new ERR_OUT_OF_RANGE("value", range, value);
|
|
613
|
+
}
|
|
614
|
+
checkBounds(buf, offset, byteLength2);
|
|
615
|
+
}
|
|
616
|
+
function validateNumber(value, name) {
|
|
617
|
+
if (typeof value !== "number")
|
|
618
|
+
throw new ERR_INVALID_ARG_TYPE(name, "number", value);
|
|
619
|
+
}
|
|
620
|
+
function boundsError(value, length, type) {
|
|
621
|
+
if (Math.floor(value) !== value)
|
|
622
|
+
throw validateNumber(value, type), new ERR_OUT_OF_RANGE(type || "offset", "an integer", value);
|
|
623
|
+
if (length < 0)
|
|
624
|
+
throw new ERR_BUFFER_OUT_OF_BOUNDS;
|
|
625
|
+
throw new ERR_OUT_OF_RANGE(type || "offset", `>= ${type ? 1 : 0} and <= ${length}`, value);
|
|
626
|
+
}
|
|
627
|
+
function base64clean(str) {
|
|
628
|
+
if (str = str.split("=")[0], str = str.trim().replace(INVALID_BASE64_RE, ""), str.length < 2)
|
|
629
|
+
return "";
|
|
630
|
+
while (str.length % 4 !== 0)
|
|
631
|
+
str = str + "=";
|
|
632
|
+
return str;
|
|
633
|
+
}
|
|
634
|
+
function utf8ToBytes(string, units) {
|
|
635
|
+
units = units || 1 / 0;
|
|
636
|
+
let codePoint, length = string.length, leadSurrogate = null, bytes = [];
|
|
637
|
+
for (let i2 = 0;i2 < length; ++i2) {
|
|
638
|
+
if (codePoint = string.charCodeAt(i2), codePoint > 55295 && codePoint < 57344) {
|
|
639
|
+
if (!leadSurrogate) {
|
|
640
|
+
if (codePoint > 56319) {
|
|
641
|
+
if ((units -= 3) > -1)
|
|
642
|
+
bytes.push(239, 191, 189);
|
|
643
|
+
continue;
|
|
644
|
+
} else if (i2 + 1 === length) {
|
|
645
|
+
if ((units -= 3) > -1)
|
|
646
|
+
bytes.push(239, 191, 189);
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
leadSurrogate = codePoint;
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
if (codePoint < 56320) {
|
|
653
|
+
if ((units -= 3) > -1)
|
|
654
|
+
bytes.push(239, 191, 189);
|
|
655
|
+
leadSurrogate = codePoint;
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
|
|
659
|
+
} else if (leadSurrogate) {
|
|
660
|
+
if ((units -= 3) > -1)
|
|
661
|
+
bytes.push(239, 191, 189);
|
|
662
|
+
}
|
|
663
|
+
if (leadSurrogate = null, codePoint < 128) {
|
|
664
|
+
if ((units -= 1) < 0)
|
|
665
|
+
break;
|
|
666
|
+
bytes.push(codePoint);
|
|
667
|
+
} else if (codePoint < 2048) {
|
|
668
|
+
if ((units -= 2) < 0)
|
|
669
|
+
break;
|
|
670
|
+
bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128);
|
|
671
|
+
} else if (codePoint < 65536) {
|
|
672
|
+
if ((units -= 3) < 0)
|
|
673
|
+
break;
|
|
674
|
+
bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
|
|
675
|
+
} else if (codePoint < 1114112) {
|
|
676
|
+
if ((units -= 4) < 0)
|
|
677
|
+
break;
|
|
678
|
+
bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
|
|
679
|
+
} else
|
|
680
|
+
throw Error("Invalid code point");
|
|
681
|
+
}
|
|
682
|
+
return bytes;
|
|
683
|
+
}
|
|
684
|
+
function asciiToBytes(str) {
|
|
685
|
+
let byteArray = [];
|
|
686
|
+
for (let i2 = 0;i2 < str.length; ++i2)
|
|
687
|
+
byteArray.push(str.charCodeAt(i2) & 255);
|
|
688
|
+
return byteArray;
|
|
689
|
+
}
|
|
690
|
+
function utf16leToBytes(str, units) {
|
|
691
|
+
let c, hi, lo, byteArray = [];
|
|
692
|
+
for (let i2 = 0;i2 < str.length; ++i2) {
|
|
693
|
+
if ((units -= 2) < 0)
|
|
694
|
+
break;
|
|
695
|
+
c = str.charCodeAt(i2), hi = c >> 8, lo = c % 256, byteArray.push(lo), byteArray.push(hi);
|
|
696
|
+
}
|
|
697
|
+
return byteArray;
|
|
698
|
+
}
|
|
699
|
+
function base64ToBytes(str) {
|
|
700
|
+
return toByteArray(base64clean(str));
|
|
701
|
+
}
|
|
702
|
+
function blitBuffer(src, dst, offset, length) {
|
|
703
|
+
let i2;
|
|
704
|
+
for (i2 = 0;i2 < length; ++i2) {
|
|
705
|
+
if (i2 + offset >= dst.length || i2 >= src.length)
|
|
706
|
+
break;
|
|
707
|
+
dst[i2 + offset] = src[i2];
|
|
708
|
+
}
|
|
709
|
+
return i2;
|
|
710
|
+
}
|
|
711
|
+
function isInstance(obj, type) {
|
|
712
|
+
return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
|
|
713
|
+
}
|
|
714
|
+
function defineBigIntMethod(fn) {
|
|
715
|
+
return typeof BigInt > "u" ? BufferBigIntNotDefined : fn;
|
|
716
|
+
}
|
|
717
|
+
function BufferBigIntNotDefined() {
|
|
718
|
+
throw Error("BigInt not supported");
|
|
719
|
+
}
|
|
720
|
+
function notimpl(name) {
|
|
721
|
+
return () => {
|
|
722
|
+
throw Error(name + " is not implemented for node:buffer browser polyfill");
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
var lookup, revLookup, code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", i, len, customInspectSymbol, INSPECT_MAX_BYTES = 50, kMaxLength = 2147483647, kStringMaxLength = 536870888, btoa, atob, File, Blob, constants, ERR_BUFFER_OUT_OF_BOUNDS, ERR_INVALID_ARG_TYPE, ERR_OUT_OF_RANGE, MAX_ARGUMENTS_LENGTH = 4096, INVALID_BASE64_RE, hexSliceLookupTable, resolveObjectURL, isUtf8, isAscii = (str) => {
|
|
726
|
+
for (let char of str)
|
|
727
|
+
if (char.charCodeAt(0) > 127)
|
|
728
|
+
return false;
|
|
729
|
+
return true;
|
|
730
|
+
}, transcode, buffer_default;
|
|
731
|
+
var init_buffer = __esm(() => {
|
|
732
|
+
lookup = [];
|
|
733
|
+
revLookup = [];
|
|
734
|
+
for (i = 0, len = code.length;i < len; ++i)
|
|
735
|
+
lookup[i] = code[i], revLookup[code.charCodeAt(i)] = i;
|
|
736
|
+
revLookup[45] = 62;
|
|
737
|
+
revLookup[95] = 63;
|
|
738
|
+
customInspectSymbol = typeof Symbol === "function" && typeof Symbol.for === "function" ? Symbol.for("nodejs.util.inspect.custom") : null;
|
|
739
|
+
btoa = globalThis.btoa;
|
|
740
|
+
atob = globalThis.atob;
|
|
741
|
+
File = globalThis.File;
|
|
742
|
+
Blob = globalThis.Blob;
|
|
743
|
+
constants = { MAX_LENGTH: kMaxLength, MAX_STRING_LENGTH: kStringMaxLength };
|
|
744
|
+
ERR_BUFFER_OUT_OF_BOUNDS = E("ERR_BUFFER_OUT_OF_BOUNDS", function(name) {
|
|
745
|
+
if (name)
|
|
746
|
+
return `${name} is outside of buffer bounds`;
|
|
747
|
+
return "Attempt to access memory outside buffer bounds";
|
|
748
|
+
}, RangeError);
|
|
749
|
+
ERR_INVALID_ARG_TYPE = E("ERR_INVALID_ARG_TYPE", function(name, actual) {
|
|
750
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`;
|
|
751
|
+
}, TypeError);
|
|
752
|
+
ERR_OUT_OF_RANGE = E("ERR_OUT_OF_RANGE", function(str, range, input) {
|
|
753
|
+
let msg = `The value of "${str}" is out of range.`, received = input;
|
|
754
|
+
if (Number.isInteger(input) && Math.abs(input) > 4294967296)
|
|
755
|
+
received = addNumericalSeparator(String(input));
|
|
756
|
+
else if (typeof input === "bigint") {
|
|
757
|
+
if (received = String(input), input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32)))
|
|
758
|
+
received = addNumericalSeparator(received);
|
|
759
|
+
received += "n";
|
|
760
|
+
}
|
|
761
|
+
return msg += ` It must be ${range}. Received ${received}`, msg;
|
|
762
|
+
}, RangeError);
|
|
763
|
+
Object.defineProperty(Buffer2.prototype, "parent", { enumerable: true, get: function() {
|
|
764
|
+
if (!Buffer2.isBuffer(this))
|
|
765
|
+
return;
|
|
766
|
+
return this.buffer;
|
|
767
|
+
} });
|
|
768
|
+
Object.defineProperty(Buffer2.prototype, "offset", { enumerable: true, get: function() {
|
|
769
|
+
if (!Buffer2.isBuffer(this))
|
|
770
|
+
return;
|
|
771
|
+
return this.byteOffset;
|
|
772
|
+
} });
|
|
773
|
+
Buffer2.poolSize = 8192;
|
|
774
|
+
Buffer2.from = function(value, encodingOrOffset, length) {
|
|
775
|
+
return from(value, encodingOrOffset, length);
|
|
776
|
+
};
|
|
777
|
+
Object.setPrototypeOf(Buffer2.prototype, Uint8Array.prototype);
|
|
778
|
+
Object.setPrototypeOf(Buffer2, Uint8Array);
|
|
779
|
+
Buffer2.alloc = function(size, fill, encoding) {
|
|
780
|
+
return alloc(size, fill, encoding);
|
|
781
|
+
};
|
|
782
|
+
Buffer2.allocUnsafe = function(size) {
|
|
783
|
+
return allocUnsafe(size);
|
|
784
|
+
};
|
|
785
|
+
Buffer2.allocUnsafeSlow = function(size) {
|
|
786
|
+
return allocUnsafe(size);
|
|
787
|
+
};
|
|
788
|
+
Buffer2.isBuffer = function(b) {
|
|
789
|
+
return b != null && b._isBuffer === true && b !== Buffer2.prototype;
|
|
790
|
+
};
|
|
791
|
+
Buffer2.compare = function(a, b) {
|
|
792
|
+
if (isInstance(a, Uint8Array))
|
|
793
|
+
a = Buffer2.from(a, a.offset, a.byteLength);
|
|
794
|
+
if (isInstance(b, Uint8Array))
|
|
795
|
+
b = Buffer2.from(b, b.offset, b.byteLength);
|
|
796
|
+
if (!Buffer2.isBuffer(a) || !Buffer2.isBuffer(b))
|
|
797
|
+
throw TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
|
|
798
|
+
if (a === b)
|
|
799
|
+
return 0;
|
|
800
|
+
let x = a.length, y = b.length;
|
|
801
|
+
for (let i2 = 0, len2 = Math.min(x, y);i2 < len2; ++i2)
|
|
802
|
+
if (a[i2] !== b[i2]) {
|
|
803
|
+
x = a[i2], y = b[i2];
|
|
804
|
+
break;
|
|
805
|
+
}
|
|
806
|
+
if (x < y)
|
|
807
|
+
return -1;
|
|
808
|
+
if (y < x)
|
|
809
|
+
return 1;
|
|
810
|
+
return 0;
|
|
811
|
+
};
|
|
812
|
+
Buffer2.isEncoding = function(encoding) {
|
|
813
|
+
switch (String(encoding).toLowerCase()) {
|
|
814
|
+
case "hex":
|
|
815
|
+
case "utf8":
|
|
816
|
+
case "utf-8":
|
|
817
|
+
case "ascii":
|
|
818
|
+
case "latin1":
|
|
819
|
+
case "binary":
|
|
820
|
+
case "base64":
|
|
821
|
+
case "ucs2":
|
|
822
|
+
case "ucs-2":
|
|
823
|
+
case "utf16le":
|
|
824
|
+
case "utf-16le":
|
|
825
|
+
return true;
|
|
826
|
+
default:
|
|
827
|
+
return false;
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
Buffer2.concat = function(list, length) {
|
|
831
|
+
if (!Array.isArray(list))
|
|
832
|
+
throw TypeError('"list" argument must be an Array of Buffers');
|
|
833
|
+
if (list.length === 0)
|
|
834
|
+
return Buffer2.alloc(0);
|
|
835
|
+
let i2;
|
|
836
|
+
if (length === undefined) {
|
|
837
|
+
length = 0;
|
|
838
|
+
for (i2 = 0;i2 < list.length; ++i2)
|
|
839
|
+
length += list[i2].length;
|
|
840
|
+
}
|
|
841
|
+
let buffer = Buffer2.allocUnsafe(length), pos = 0;
|
|
842
|
+
for (i2 = 0;i2 < list.length; ++i2) {
|
|
843
|
+
let buf = list[i2];
|
|
844
|
+
if (isInstance(buf, Uint8Array))
|
|
845
|
+
if (pos + buf.length > buffer.length) {
|
|
846
|
+
if (!Buffer2.isBuffer(buf))
|
|
847
|
+
buf = Buffer2.from(buf);
|
|
848
|
+
buf.copy(buffer, pos);
|
|
849
|
+
} else
|
|
850
|
+
Uint8Array.prototype.set.call(buffer, buf, pos);
|
|
851
|
+
else if (!Buffer2.isBuffer(buf))
|
|
852
|
+
throw TypeError('"list" argument must be an Array of Buffers');
|
|
853
|
+
else
|
|
854
|
+
buf.copy(buffer, pos);
|
|
855
|
+
pos += buf.length;
|
|
856
|
+
}
|
|
857
|
+
return buffer;
|
|
858
|
+
};
|
|
859
|
+
Buffer2.byteLength = byteLength;
|
|
860
|
+
Buffer2.prototype._isBuffer = true;
|
|
861
|
+
Buffer2.prototype.swap16 = function() {
|
|
862
|
+
let len2 = this.length;
|
|
863
|
+
if (len2 % 2 !== 0)
|
|
864
|
+
throw RangeError("Buffer size must be a multiple of 16-bits");
|
|
865
|
+
for (let i2 = 0;i2 < len2; i2 += 2)
|
|
866
|
+
swap(this, i2, i2 + 1);
|
|
867
|
+
return this;
|
|
868
|
+
};
|
|
869
|
+
Buffer2.prototype.swap32 = function() {
|
|
870
|
+
let len2 = this.length;
|
|
871
|
+
if (len2 % 4 !== 0)
|
|
872
|
+
throw RangeError("Buffer size must be a multiple of 32-bits");
|
|
873
|
+
for (let i2 = 0;i2 < len2; i2 += 4)
|
|
874
|
+
swap(this, i2, i2 + 3), swap(this, i2 + 1, i2 + 2);
|
|
875
|
+
return this;
|
|
876
|
+
};
|
|
877
|
+
Buffer2.prototype.swap64 = function() {
|
|
878
|
+
let len2 = this.length;
|
|
879
|
+
if (len2 % 8 !== 0)
|
|
880
|
+
throw RangeError("Buffer size must be a multiple of 64-bits");
|
|
881
|
+
for (let i2 = 0;i2 < len2; i2 += 8)
|
|
882
|
+
swap(this, i2, i2 + 7), swap(this, i2 + 1, i2 + 6), swap(this, i2 + 2, i2 + 5), swap(this, i2 + 3, i2 + 4);
|
|
883
|
+
return this;
|
|
884
|
+
};
|
|
885
|
+
Buffer2.prototype.toString = function() {
|
|
886
|
+
let length = this.length;
|
|
887
|
+
if (length === 0)
|
|
888
|
+
return "";
|
|
889
|
+
if (arguments.length === 0)
|
|
890
|
+
return utf8Slice(this, 0, length);
|
|
891
|
+
return slowToString.apply(this, arguments);
|
|
892
|
+
};
|
|
893
|
+
Buffer2.prototype.toLocaleString = Buffer2.prototype.toString;
|
|
894
|
+
Buffer2.prototype.equals = function(b) {
|
|
895
|
+
if (!Buffer2.isBuffer(b))
|
|
896
|
+
throw TypeError("Argument must be a Buffer");
|
|
897
|
+
if (this === b)
|
|
898
|
+
return true;
|
|
899
|
+
return Buffer2.compare(this, b) === 0;
|
|
900
|
+
};
|
|
901
|
+
Buffer2.prototype.inspect = function() {
|
|
902
|
+
let str = "", max = INSPECT_MAX_BYTES;
|
|
903
|
+
if (str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim(), this.length > max)
|
|
904
|
+
str += " ... ";
|
|
905
|
+
return "<Buffer " + str + ">";
|
|
906
|
+
};
|
|
907
|
+
if (customInspectSymbol)
|
|
908
|
+
Buffer2.prototype[customInspectSymbol] = Buffer2.prototype.inspect;
|
|
909
|
+
Buffer2.prototype.compare = function(target, start, end, thisStart, thisEnd) {
|
|
910
|
+
if (isInstance(target, Uint8Array))
|
|
911
|
+
target = Buffer2.from(target, target.offset, target.byteLength);
|
|
912
|
+
if (!Buffer2.isBuffer(target))
|
|
913
|
+
throw TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target);
|
|
914
|
+
if (start === undefined)
|
|
915
|
+
start = 0;
|
|
916
|
+
if (end === undefined)
|
|
917
|
+
end = target ? target.length : 0;
|
|
918
|
+
if (thisStart === undefined)
|
|
919
|
+
thisStart = 0;
|
|
920
|
+
if (thisEnd === undefined)
|
|
921
|
+
thisEnd = this.length;
|
|
922
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length)
|
|
923
|
+
throw RangeError("out of range index");
|
|
924
|
+
if (thisStart >= thisEnd && start >= end)
|
|
925
|
+
return 0;
|
|
926
|
+
if (thisStart >= thisEnd)
|
|
927
|
+
return -1;
|
|
928
|
+
if (start >= end)
|
|
929
|
+
return 1;
|
|
930
|
+
if (start >>>= 0, end >>>= 0, thisStart >>>= 0, thisEnd >>>= 0, this === target)
|
|
931
|
+
return 0;
|
|
932
|
+
let x = thisEnd - thisStart, y = end - start, len2 = Math.min(x, y), thisCopy = this.slice(thisStart, thisEnd), targetCopy = target.slice(start, end);
|
|
933
|
+
for (let i2 = 0;i2 < len2; ++i2)
|
|
934
|
+
if (thisCopy[i2] !== targetCopy[i2]) {
|
|
935
|
+
x = thisCopy[i2], y = targetCopy[i2];
|
|
936
|
+
break;
|
|
937
|
+
}
|
|
938
|
+
if (x < y)
|
|
939
|
+
return -1;
|
|
940
|
+
if (y < x)
|
|
941
|
+
return 1;
|
|
942
|
+
return 0;
|
|
943
|
+
};
|
|
944
|
+
Buffer2.prototype.includes = function(val, byteOffset, encoding) {
|
|
945
|
+
return this.indexOf(val, byteOffset, encoding) !== -1;
|
|
946
|
+
};
|
|
947
|
+
Buffer2.prototype.indexOf = function(val, byteOffset, encoding) {
|
|
948
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
|
|
949
|
+
};
|
|
950
|
+
Buffer2.prototype.lastIndexOf = function(val, byteOffset, encoding) {
|
|
951
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
|
|
952
|
+
};
|
|
953
|
+
Buffer2.prototype.write = function(string, offset, length, encoding) {
|
|
954
|
+
if (offset === undefined)
|
|
955
|
+
encoding = "utf8", length = this.length, offset = 0;
|
|
956
|
+
else if (length === undefined && typeof offset === "string")
|
|
957
|
+
encoding = offset, length = this.length, offset = 0;
|
|
958
|
+
else if (isFinite(offset))
|
|
959
|
+
if (offset = offset >>> 0, isFinite(length)) {
|
|
960
|
+
if (length = length >>> 0, encoding === undefined)
|
|
961
|
+
encoding = "utf8";
|
|
962
|
+
} else
|
|
963
|
+
encoding = length, length = undefined;
|
|
964
|
+
else
|
|
965
|
+
throw Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");
|
|
966
|
+
let remaining = this.length - offset;
|
|
967
|
+
if (length === undefined || length > remaining)
|
|
968
|
+
length = remaining;
|
|
969
|
+
if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length)
|
|
970
|
+
throw RangeError("Attempt to write outside buffer bounds");
|
|
971
|
+
if (!encoding)
|
|
972
|
+
encoding = "utf8";
|
|
973
|
+
let loweredCase = false;
|
|
974
|
+
for (;; )
|
|
975
|
+
switch (encoding) {
|
|
976
|
+
case "hex":
|
|
977
|
+
return hexWrite(this, string, offset, length);
|
|
978
|
+
case "utf8":
|
|
979
|
+
case "utf-8":
|
|
980
|
+
return utf8Write(this, string, offset, length);
|
|
981
|
+
case "ascii":
|
|
982
|
+
case "latin1":
|
|
983
|
+
case "binary":
|
|
984
|
+
return asciiWrite(this, string, offset, length);
|
|
985
|
+
case "base64":
|
|
986
|
+
return base64Write(this, string, offset, length);
|
|
987
|
+
case "ucs2":
|
|
988
|
+
case "ucs-2":
|
|
989
|
+
case "utf16le":
|
|
990
|
+
case "utf-16le":
|
|
991
|
+
return ucs2Write(this, string, offset, length);
|
|
992
|
+
default:
|
|
993
|
+
if (loweredCase)
|
|
994
|
+
throw TypeError("Unknown encoding: " + encoding);
|
|
995
|
+
encoding = ("" + encoding).toLowerCase(), loweredCase = true;
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
Buffer2.prototype.toJSON = function() {
|
|
999
|
+
return { type: "Buffer", data: Array.prototype.slice.call(this._arr || this, 0) };
|
|
1000
|
+
};
|
|
1001
|
+
Buffer2.prototype.slice = function(start, end) {
|
|
1002
|
+
let len2 = this.length;
|
|
1003
|
+
if (start = ~~start, end = end === undefined ? len2 : ~~end, start < 0) {
|
|
1004
|
+
if (start += len2, start < 0)
|
|
1005
|
+
start = 0;
|
|
1006
|
+
} else if (start > len2)
|
|
1007
|
+
start = len2;
|
|
1008
|
+
if (end < 0) {
|
|
1009
|
+
if (end += len2, end < 0)
|
|
1010
|
+
end = 0;
|
|
1011
|
+
} else if (end > len2)
|
|
1012
|
+
end = len2;
|
|
1013
|
+
if (end < start)
|
|
1014
|
+
end = start;
|
|
1015
|
+
let newBuf = this.subarray(start, end);
|
|
1016
|
+
return Object.setPrototypeOf(newBuf, Buffer2.prototype), newBuf;
|
|
1017
|
+
};
|
|
1018
|
+
Buffer2.prototype.readUintLE = Buffer2.prototype.readUIntLE = function(offset, byteLength2, noAssert) {
|
|
1019
|
+
if (offset = offset >>> 0, byteLength2 = byteLength2 >>> 0, !noAssert)
|
|
1020
|
+
checkOffset(offset, byteLength2, this.length);
|
|
1021
|
+
let val = this[offset], mul = 1, i2 = 0;
|
|
1022
|
+
while (++i2 < byteLength2 && (mul *= 256))
|
|
1023
|
+
val += this[offset + i2] * mul;
|
|
1024
|
+
return val;
|
|
1025
|
+
};
|
|
1026
|
+
Buffer2.prototype.readUintBE = Buffer2.prototype.readUIntBE = function(offset, byteLength2, noAssert) {
|
|
1027
|
+
if (offset = offset >>> 0, byteLength2 = byteLength2 >>> 0, !noAssert)
|
|
1028
|
+
checkOffset(offset, byteLength2, this.length);
|
|
1029
|
+
let val = this[offset + --byteLength2], mul = 1;
|
|
1030
|
+
while (byteLength2 > 0 && (mul *= 256))
|
|
1031
|
+
val += this[offset + --byteLength2] * mul;
|
|
1032
|
+
return val;
|
|
1033
|
+
};
|
|
1034
|
+
Buffer2.prototype.readUint8 = Buffer2.prototype.readUInt8 = function(offset, noAssert) {
|
|
1035
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1036
|
+
checkOffset(offset, 1, this.length);
|
|
1037
|
+
return this[offset];
|
|
1038
|
+
};
|
|
1039
|
+
Buffer2.prototype.readUint16LE = Buffer2.prototype.readUInt16LE = function(offset, noAssert) {
|
|
1040
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1041
|
+
checkOffset(offset, 2, this.length);
|
|
1042
|
+
return this[offset] | this[offset + 1] << 8;
|
|
1043
|
+
};
|
|
1044
|
+
Buffer2.prototype.readUint16BE = Buffer2.prototype.readUInt16BE = function(offset, noAssert) {
|
|
1045
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1046
|
+
checkOffset(offset, 2, this.length);
|
|
1047
|
+
return this[offset] << 8 | this[offset + 1];
|
|
1048
|
+
};
|
|
1049
|
+
Buffer2.prototype.readUint32LE = Buffer2.prototype.readUInt32LE = function(offset, noAssert) {
|
|
1050
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1051
|
+
checkOffset(offset, 4, this.length);
|
|
1052
|
+
return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
|
|
1053
|
+
};
|
|
1054
|
+
Buffer2.prototype.readUint32BE = Buffer2.prototype.readUInt32BE = function(offset, noAssert) {
|
|
1055
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1056
|
+
checkOffset(offset, 4, this.length);
|
|
1057
|
+
return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
|
|
1058
|
+
};
|
|
1059
|
+
Buffer2.prototype.readBigUInt64LE = defineBigIntMethod(function(offset) {
|
|
1060
|
+
offset = offset >>> 0, validateNumber(offset, "offset");
|
|
1061
|
+
let first = this[offset], last = this[offset + 7];
|
|
1062
|
+
if (first === undefined || last === undefined)
|
|
1063
|
+
boundsError(offset, this.length - 8);
|
|
1064
|
+
let lo = first + this[++offset] * 256 + this[++offset] * 65536 + this[++offset] * 16777216, hi = this[++offset] + this[++offset] * 256 + this[++offset] * 65536 + last * 16777216;
|
|
1065
|
+
return BigInt(lo) + (BigInt(hi) << BigInt(32));
|
|
1066
|
+
});
|
|
1067
|
+
Buffer2.prototype.readBigUInt64BE = defineBigIntMethod(function(offset) {
|
|
1068
|
+
offset = offset >>> 0, validateNumber(offset, "offset");
|
|
1069
|
+
let first = this[offset], last = this[offset + 7];
|
|
1070
|
+
if (first === undefined || last === undefined)
|
|
1071
|
+
boundsError(offset, this.length - 8);
|
|
1072
|
+
let hi = first * 16777216 + this[++offset] * 65536 + this[++offset] * 256 + this[++offset], lo = this[++offset] * 16777216 + this[++offset] * 65536 + this[++offset] * 256 + last;
|
|
1073
|
+
return (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
1074
|
+
});
|
|
1075
|
+
Buffer2.prototype.readIntLE = function(offset, byteLength2, noAssert) {
|
|
1076
|
+
if (offset = offset >>> 0, byteLength2 = byteLength2 >>> 0, !noAssert)
|
|
1077
|
+
checkOffset(offset, byteLength2, this.length);
|
|
1078
|
+
let val = this[offset], mul = 1, i2 = 0;
|
|
1079
|
+
while (++i2 < byteLength2 && (mul *= 256))
|
|
1080
|
+
val += this[offset + i2] * mul;
|
|
1081
|
+
if (mul *= 128, val >= mul)
|
|
1082
|
+
val -= Math.pow(2, 8 * byteLength2);
|
|
1083
|
+
return val;
|
|
1084
|
+
};
|
|
1085
|
+
Buffer2.prototype.readIntBE = function(offset, byteLength2, noAssert) {
|
|
1086
|
+
if (offset = offset >>> 0, byteLength2 = byteLength2 >>> 0, !noAssert)
|
|
1087
|
+
checkOffset(offset, byteLength2, this.length);
|
|
1088
|
+
let i2 = byteLength2, mul = 1, val = this[offset + --i2];
|
|
1089
|
+
while (i2 > 0 && (mul *= 256))
|
|
1090
|
+
val += this[offset + --i2] * mul;
|
|
1091
|
+
if (mul *= 128, val >= mul)
|
|
1092
|
+
val -= Math.pow(2, 8 * byteLength2);
|
|
1093
|
+
return val;
|
|
1094
|
+
};
|
|
1095
|
+
Buffer2.prototype.readInt8 = function(offset, noAssert) {
|
|
1096
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1097
|
+
checkOffset(offset, 1, this.length);
|
|
1098
|
+
if (!(this[offset] & 128))
|
|
1099
|
+
return this[offset];
|
|
1100
|
+
return (255 - this[offset] + 1) * -1;
|
|
1101
|
+
};
|
|
1102
|
+
Buffer2.prototype.readInt16LE = function(offset, noAssert) {
|
|
1103
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1104
|
+
checkOffset(offset, 2, this.length);
|
|
1105
|
+
let val = this[offset] | this[offset + 1] << 8;
|
|
1106
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1107
|
+
};
|
|
1108
|
+
Buffer2.prototype.readInt16BE = function(offset, noAssert) {
|
|
1109
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1110
|
+
checkOffset(offset, 2, this.length);
|
|
1111
|
+
let val = this[offset + 1] | this[offset] << 8;
|
|
1112
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1113
|
+
};
|
|
1114
|
+
Buffer2.prototype.readInt32LE = function(offset, noAssert) {
|
|
1115
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1116
|
+
checkOffset(offset, 4, this.length);
|
|
1117
|
+
return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
|
|
1118
|
+
};
|
|
1119
|
+
Buffer2.prototype.readInt32BE = function(offset, noAssert) {
|
|
1120
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1121
|
+
checkOffset(offset, 4, this.length);
|
|
1122
|
+
return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
|
|
1123
|
+
};
|
|
1124
|
+
Buffer2.prototype.readBigInt64LE = defineBigIntMethod(function(offset) {
|
|
1125
|
+
offset = offset >>> 0, validateNumber(offset, "offset");
|
|
1126
|
+
let first = this[offset], last = this[offset + 7];
|
|
1127
|
+
if (first === undefined || last === undefined)
|
|
1128
|
+
boundsError(offset, this.length - 8);
|
|
1129
|
+
let val = this[offset + 4] + this[offset + 5] * 256 + this[offset + 6] * 65536 + (last << 24);
|
|
1130
|
+
return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 256 + this[++offset] * 65536 + this[++offset] * 16777216);
|
|
1131
|
+
});
|
|
1132
|
+
Buffer2.prototype.readBigInt64BE = defineBigIntMethod(function(offset) {
|
|
1133
|
+
offset = offset >>> 0, validateNumber(offset, "offset");
|
|
1134
|
+
let first = this[offset], last = this[offset + 7];
|
|
1135
|
+
if (first === undefined || last === undefined)
|
|
1136
|
+
boundsError(offset, this.length - 8);
|
|
1137
|
+
let val = (first << 24) + this[++offset] * 65536 + this[++offset] * 256 + this[++offset];
|
|
1138
|
+
return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 16777216 + this[++offset] * 65536 + this[++offset] * 256 + last);
|
|
1139
|
+
});
|
|
1140
|
+
Buffer2.prototype.readFloatLE = function(offset, noAssert) {
|
|
1141
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1142
|
+
checkOffset(offset, 4, this.length);
|
|
1143
|
+
return read(this, offset, true, 23, 4);
|
|
1144
|
+
};
|
|
1145
|
+
Buffer2.prototype.readFloatBE = function(offset, noAssert) {
|
|
1146
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1147
|
+
checkOffset(offset, 4, this.length);
|
|
1148
|
+
return read(this, offset, false, 23, 4);
|
|
1149
|
+
};
|
|
1150
|
+
Buffer2.prototype.readDoubleLE = function(offset, noAssert) {
|
|
1151
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1152
|
+
checkOffset(offset, 8, this.length);
|
|
1153
|
+
return read(this, offset, true, 52, 8);
|
|
1154
|
+
};
|
|
1155
|
+
Buffer2.prototype.readDoubleBE = function(offset, noAssert) {
|
|
1156
|
+
if (offset = offset >>> 0, !noAssert)
|
|
1157
|
+
checkOffset(offset, 8, this.length);
|
|
1158
|
+
return read(this, offset, false, 52, 8);
|
|
1159
|
+
};
|
|
1160
|
+
Buffer2.prototype.writeUintLE = Buffer2.prototype.writeUIntLE = function(value, offset, byteLength2, noAssert) {
|
|
1161
|
+
if (value = +value, offset = offset >>> 0, byteLength2 = byteLength2 >>> 0, !noAssert) {
|
|
1162
|
+
let maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1163
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1164
|
+
}
|
|
1165
|
+
let mul = 1, i2 = 0;
|
|
1166
|
+
this[offset] = value & 255;
|
|
1167
|
+
while (++i2 < byteLength2 && (mul *= 256))
|
|
1168
|
+
this[offset + i2] = value / mul & 255;
|
|
1169
|
+
return offset + byteLength2;
|
|
1170
|
+
};
|
|
1171
|
+
Buffer2.prototype.writeUintBE = Buffer2.prototype.writeUIntBE = function(value, offset, byteLength2, noAssert) {
|
|
1172
|
+
if (value = +value, offset = offset >>> 0, byteLength2 = byteLength2 >>> 0, !noAssert) {
|
|
1173
|
+
let maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1174
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1175
|
+
}
|
|
1176
|
+
let i2 = byteLength2 - 1, mul = 1;
|
|
1177
|
+
this[offset + i2] = value & 255;
|
|
1178
|
+
while (--i2 >= 0 && (mul *= 256))
|
|
1179
|
+
this[offset + i2] = value / mul & 255;
|
|
1180
|
+
return offset + byteLength2;
|
|
1181
|
+
};
|
|
1182
|
+
Buffer2.prototype.writeUint8 = Buffer2.prototype.writeUInt8 = function(value, offset, noAssert) {
|
|
1183
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1184
|
+
checkInt(this, value, offset, 1, 255, 0);
|
|
1185
|
+
return this[offset] = value & 255, offset + 1;
|
|
1186
|
+
};
|
|
1187
|
+
Buffer2.prototype.writeUint16LE = Buffer2.prototype.writeUInt16LE = function(value, offset, noAssert) {
|
|
1188
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1189
|
+
checkInt(this, value, offset, 2, 65535, 0);
|
|
1190
|
+
return this[offset] = value & 255, this[offset + 1] = value >>> 8, offset + 2;
|
|
1191
|
+
};
|
|
1192
|
+
Buffer2.prototype.writeUint16BE = Buffer2.prototype.writeUInt16BE = function(value, offset, noAssert) {
|
|
1193
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1194
|
+
checkInt(this, value, offset, 2, 65535, 0);
|
|
1195
|
+
return this[offset] = value >>> 8, this[offset + 1] = value & 255, offset + 2;
|
|
1196
|
+
};
|
|
1197
|
+
Buffer2.prototype.writeUint32LE = Buffer2.prototype.writeUInt32LE = function(value, offset, noAssert) {
|
|
1198
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1199
|
+
checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1200
|
+
return this[offset + 3] = value >>> 24, this[offset + 2] = value >>> 16, this[offset + 1] = value >>> 8, this[offset] = value & 255, offset + 4;
|
|
1201
|
+
};
|
|
1202
|
+
Buffer2.prototype.writeUint32BE = Buffer2.prototype.writeUInt32BE = function(value, offset, noAssert) {
|
|
1203
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1204
|
+
checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1205
|
+
return this[offset] = value >>> 24, this[offset + 1] = value >>> 16, this[offset + 2] = value >>> 8, this[offset + 3] = value & 255, offset + 4;
|
|
1206
|
+
};
|
|
1207
|
+
Buffer2.prototype.writeBigUInt64LE = defineBigIntMethod(function(value, offset = 0) {
|
|
1208
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1209
|
+
});
|
|
1210
|
+
Buffer2.prototype.writeBigUInt64BE = defineBigIntMethod(function(value, offset = 0) {
|
|
1211
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1212
|
+
});
|
|
1213
|
+
Buffer2.prototype.writeIntLE = function(value, offset, byteLength2, noAssert) {
|
|
1214
|
+
if (value = +value, offset = offset >>> 0, !noAssert) {
|
|
1215
|
+
let limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1216
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1217
|
+
}
|
|
1218
|
+
let i2 = 0, mul = 1, sub = 0;
|
|
1219
|
+
this[offset] = value & 255;
|
|
1220
|
+
while (++i2 < byteLength2 && (mul *= 256)) {
|
|
1221
|
+
if (value < 0 && sub === 0 && this[offset + i2 - 1] !== 0)
|
|
1222
|
+
sub = 1;
|
|
1223
|
+
this[offset + i2] = (value / mul >> 0) - sub & 255;
|
|
1224
|
+
}
|
|
1225
|
+
return offset + byteLength2;
|
|
1226
|
+
};
|
|
1227
|
+
Buffer2.prototype.writeIntBE = function(value, offset, byteLength2, noAssert) {
|
|
1228
|
+
if (value = +value, offset = offset >>> 0, !noAssert) {
|
|
1229
|
+
let limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1230
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1231
|
+
}
|
|
1232
|
+
let i2 = byteLength2 - 1, mul = 1, sub = 0;
|
|
1233
|
+
this[offset + i2] = value & 255;
|
|
1234
|
+
while (--i2 >= 0 && (mul *= 256)) {
|
|
1235
|
+
if (value < 0 && sub === 0 && this[offset + i2 + 1] !== 0)
|
|
1236
|
+
sub = 1;
|
|
1237
|
+
this[offset + i2] = (value / mul >> 0) - sub & 255;
|
|
1238
|
+
}
|
|
1239
|
+
return offset + byteLength2;
|
|
1240
|
+
};
|
|
1241
|
+
Buffer2.prototype.writeInt8 = function(value, offset, noAssert) {
|
|
1242
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1243
|
+
checkInt(this, value, offset, 1, 127, -128);
|
|
1244
|
+
if (value < 0)
|
|
1245
|
+
value = 255 + value + 1;
|
|
1246
|
+
return this[offset] = value & 255, offset + 1;
|
|
1247
|
+
};
|
|
1248
|
+
Buffer2.prototype.writeInt16LE = function(value, offset, noAssert) {
|
|
1249
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1250
|
+
checkInt(this, value, offset, 2, 32767, -32768);
|
|
1251
|
+
return this[offset] = value & 255, this[offset + 1] = value >>> 8, offset + 2;
|
|
1252
|
+
};
|
|
1253
|
+
Buffer2.prototype.writeInt16BE = function(value, offset, noAssert) {
|
|
1254
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1255
|
+
checkInt(this, value, offset, 2, 32767, -32768);
|
|
1256
|
+
return this[offset] = value >>> 8, this[offset + 1] = value & 255, offset + 2;
|
|
1257
|
+
};
|
|
1258
|
+
Buffer2.prototype.writeInt32LE = function(value, offset, noAssert) {
|
|
1259
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1260
|
+
checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1261
|
+
return this[offset] = value & 255, this[offset + 1] = value >>> 8, this[offset + 2] = value >>> 16, this[offset + 3] = value >>> 24, offset + 4;
|
|
1262
|
+
};
|
|
1263
|
+
Buffer2.prototype.writeInt32BE = function(value, offset, noAssert) {
|
|
1264
|
+
if (value = +value, offset = offset >>> 0, !noAssert)
|
|
1265
|
+
checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1266
|
+
if (value < 0)
|
|
1267
|
+
value = 4294967295 + value + 1;
|
|
1268
|
+
return this[offset] = value >>> 24, this[offset + 1] = value >>> 16, this[offset + 2] = value >>> 8, this[offset + 3] = value & 255, offset + 4;
|
|
1269
|
+
};
|
|
1270
|
+
Buffer2.prototype.writeBigInt64LE = defineBigIntMethod(function(value, offset = 0) {
|
|
1271
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1272
|
+
});
|
|
1273
|
+
Buffer2.prototype.writeBigInt64BE = defineBigIntMethod(function(value, offset = 0) {
|
|
1274
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1275
|
+
});
|
|
1276
|
+
Buffer2.prototype.writeFloatLE = function(value, offset, noAssert) {
|
|
1277
|
+
return writeFloat(this, value, offset, true, noAssert);
|
|
1278
|
+
};
|
|
1279
|
+
Buffer2.prototype.writeFloatBE = function(value, offset, noAssert) {
|
|
1280
|
+
return writeFloat(this, value, offset, false, noAssert);
|
|
1281
|
+
};
|
|
1282
|
+
Buffer2.prototype.writeDoubleLE = function(value, offset, noAssert) {
|
|
1283
|
+
return writeDouble(this, value, offset, true, noAssert);
|
|
1284
|
+
};
|
|
1285
|
+
Buffer2.prototype.writeDoubleBE = function(value, offset, noAssert) {
|
|
1286
|
+
return writeDouble(this, value, offset, false, noAssert);
|
|
1287
|
+
};
|
|
1288
|
+
Buffer2.prototype.copy = function(target, targetStart, start, end) {
|
|
1289
|
+
if (!Buffer2.isBuffer(target))
|
|
1290
|
+
throw TypeError("argument should be a Buffer");
|
|
1291
|
+
if (!start)
|
|
1292
|
+
start = 0;
|
|
1293
|
+
if (!end && end !== 0)
|
|
1294
|
+
end = this.length;
|
|
1295
|
+
if (targetStart >= target.length)
|
|
1296
|
+
targetStart = target.length;
|
|
1297
|
+
if (!targetStart)
|
|
1298
|
+
targetStart = 0;
|
|
1299
|
+
if (end > 0 && end < start)
|
|
1300
|
+
end = start;
|
|
1301
|
+
if (end === start)
|
|
1302
|
+
return 0;
|
|
1303
|
+
if (target.length === 0 || this.length === 0)
|
|
1304
|
+
return 0;
|
|
1305
|
+
if (targetStart < 0)
|
|
1306
|
+
throw RangeError("targetStart out of bounds");
|
|
1307
|
+
if (start < 0 || start >= this.length)
|
|
1308
|
+
throw RangeError("Index out of range");
|
|
1309
|
+
if (end < 0)
|
|
1310
|
+
throw RangeError("sourceEnd out of bounds");
|
|
1311
|
+
if (end > this.length)
|
|
1312
|
+
end = this.length;
|
|
1313
|
+
if (target.length - targetStart < end - start)
|
|
1314
|
+
end = target.length - targetStart + start;
|
|
1315
|
+
let len2 = end - start;
|
|
1316
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === "function")
|
|
1317
|
+
this.copyWithin(targetStart, start, end);
|
|
1318
|
+
else
|
|
1319
|
+
Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
|
|
1320
|
+
return len2;
|
|
1321
|
+
};
|
|
1322
|
+
Buffer2.prototype.fill = function(val, start, end, encoding) {
|
|
1323
|
+
if (typeof val === "string") {
|
|
1324
|
+
if (typeof start === "string")
|
|
1325
|
+
encoding = start, start = 0, end = this.length;
|
|
1326
|
+
else if (typeof end === "string")
|
|
1327
|
+
encoding = end, end = this.length;
|
|
1328
|
+
if (encoding !== undefined && typeof encoding !== "string")
|
|
1329
|
+
throw TypeError("encoding must be a string");
|
|
1330
|
+
if (typeof encoding === "string" && !Buffer2.isEncoding(encoding))
|
|
1331
|
+
throw TypeError("Unknown encoding: " + encoding);
|
|
1332
|
+
if (val.length === 1) {
|
|
1333
|
+
let code2 = val.charCodeAt(0);
|
|
1334
|
+
if (encoding === "utf8" && code2 < 128 || encoding === "latin1")
|
|
1335
|
+
val = code2;
|
|
1336
|
+
}
|
|
1337
|
+
} else if (typeof val === "number")
|
|
1338
|
+
val = val & 255;
|
|
1339
|
+
else if (typeof val === "boolean")
|
|
1340
|
+
val = Number(val);
|
|
1341
|
+
if (start < 0 || this.length < start || this.length < end)
|
|
1342
|
+
throw RangeError("Out of range index");
|
|
1343
|
+
if (end <= start)
|
|
1344
|
+
return this;
|
|
1345
|
+
if (start = start >>> 0, end = end === undefined ? this.length : end >>> 0, !val)
|
|
1346
|
+
val = 0;
|
|
1347
|
+
let i2;
|
|
1348
|
+
if (typeof val === "number")
|
|
1349
|
+
for (i2 = start;i2 < end; ++i2)
|
|
1350
|
+
this[i2] = val;
|
|
1351
|
+
else {
|
|
1352
|
+
let bytes = Buffer2.isBuffer(val) ? val : Buffer2.from(val, encoding), len2 = bytes.length;
|
|
1353
|
+
if (len2 === 0)
|
|
1354
|
+
throw TypeError('The value "' + val + '" is invalid for argument "value"');
|
|
1355
|
+
for (i2 = 0;i2 < end - start; ++i2)
|
|
1356
|
+
this[i2 + start] = bytes[i2 % len2];
|
|
1357
|
+
}
|
|
1358
|
+
return this;
|
|
1359
|
+
};
|
|
1360
|
+
INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
1361
|
+
hexSliceLookupTable = function() {
|
|
1362
|
+
let table = Array(256);
|
|
1363
|
+
for (let i2 = 0;i2 < 16; ++i2) {
|
|
1364
|
+
let i16 = i2 * 16;
|
|
1365
|
+
for (let j = 0;j < 16; ++j)
|
|
1366
|
+
table[i16 + j] = "0123456789abcdef"[i2] + "0123456789abcdef"[j];
|
|
1367
|
+
}
|
|
1368
|
+
return table;
|
|
1369
|
+
}();
|
|
1370
|
+
resolveObjectURL = notimpl("resolveObjectURL");
|
|
1371
|
+
isUtf8 = notimpl("isUtf8");
|
|
1372
|
+
transcode = notimpl("transcode");
|
|
1373
|
+
buffer_default = Buffer2;
|
|
1374
|
+
});
|
|
1375
|
+
|
|
1376
|
+
// src/type/text.ts
|
|
1377
|
+
var colors = {
|
|
1378
|
+
black: "\x1B[30m",
|
|
1379
|
+
red: "\x1B[31m",
|
|
1380
|
+
green: "\x1B[32m",
|
|
1381
|
+
yellow: "\x1B[33m",
|
|
1382
|
+
blue: "\x1B[34m",
|
|
1383
|
+
magenta: "\x1B[35m",
|
|
1384
|
+
cyan: "\x1B[36m",
|
|
1385
|
+
white: "\x1B[37m",
|
|
1386
|
+
brightBlack: "\x1B[90m",
|
|
1387
|
+
brightRed: "\x1B[91m",
|
|
1388
|
+
brightGreen: "\x1B[92m",
|
|
1389
|
+
brightYellow: "\x1B[93m",
|
|
1390
|
+
brightBlue: "\x1B[94m",
|
|
1391
|
+
brightMagenta: "\x1B[95m",
|
|
1392
|
+
brightCyan: "\x1B[96m",
|
|
1393
|
+
brightWhite: "\x1B[97m",
|
|
1394
|
+
accent: "\x1B[34m",
|
|
1395
|
+
muted: "\x1B[2m",
|
|
1396
|
+
default: "\x1B[0m"
|
|
1397
|
+
};
|
|
1398
|
+
var AnsiCode = {
|
|
1399
|
+
reset: "\x1B[0m",
|
|
1400
|
+
clear: "\x1B[H\x1B[2J",
|
|
1401
|
+
hideCursor: "\x1B[?25l",
|
|
1402
|
+
showCursor: "\x1B[?25h"
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
// src/renderer/text-layout.ts
|
|
1406
|
+
var ansiPattern = /\x1b\[[0-?]*[ -/]*[@-~]/g;
|
|
1407
|
+
function characterWidth(character) {
|
|
1408
|
+
const code = character.codePointAt(0) ?? 0;
|
|
1409
|
+
if (code === 0 || code < 32 || code >= 127 && code < 160 || /\p{Mark}/u.test(character) || code === 8205 || code >= 65024 && code <= 65039) {
|
|
1410
|
+
return 0;
|
|
1411
|
+
}
|
|
1412
|
+
return isWide(code) ? 2 : 1;
|
|
1413
|
+
}
|
|
1414
|
+
function textWidth(value) {
|
|
1415
|
+
return Array.from(value.replace(ansiPattern, "")).reduce((width, character) => width + characterWidth(character), 0);
|
|
1416
|
+
}
|
|
1417
|
+
function truncate(value, width) {
|
|
1418
|
+
if (width <= 0) {
|
|
1419
|
+
return "";
|
|
1420
|
+
}
|
|
1421
|
+
let output = "";
|
|
1422
|
+
let currentWidth = 0;
|
|
1423
|
+
let offset = 0;
|
|
1424
|
+
while (offset < value.length) {
|
|
1425
|
+
const ansi = value.slice(offset).match(/^\x1b\[[0-?]*[ -/]*[@-~]/)?.[0];
|
|
1426
|
+
if (ansi) {
|
|
1427
|
+
output += ansi;
|
|
1428
|
+
offset += ansi.length;
|
|
1429
|
+
continue;
|
|
1430
|
+
}
|
|
1431
|
+
const character = Array.from(value.slice(offset))[0] ?? "";
|
|
1432
|
+
const nextWidth = characterWidth(character);
|
|
1433
|
+
if (currentWidth + nextWidth > width) {
|
|
1434
|
+
break;
|
|
1435
|
+
}
|
|
1436
|
+
output += character;
|
|
1437
|
+
currentWidth += nextWidth;
|
|
1438
|
+
offset += character.length;
|
|
1439
|
+
}
|
|
1440
|
+
return output;
|
|
1441
|
+
}
|
|
1442
|
+
function wrap(value, width) {
|
|
1443
|
+
if (width <= 0) {
|
|
1444
|
+
return [""];
|
|
1445
|
+
}
|
|
1446
|
+
if (textWidth(value) <= width) {
|
|
1447
|
+
return [value];
|
|
1448
|
+
}
|
|
1449
|
+
const lines = [];
|
|
1450
|
+
let remaining = value;
|
|
1451
|
+
while (remaining.length > 0) {
|
|
1452
|
+
const line = truncate(remaining, width);
|
|
1453
|
+
if (!line) {
|
|
1454
|
+
break;
|
|
1455
|
+
}
|
|
1456
|
+
lines.push(line);
|
|
1457
|
+
remaining = remaining.slice(line.length);
|
|
1458
|
+
}
|
|
1459
|
+
return lines.length > 0 ? lines : [""];
|
|
1460
|
+
}
|
|
1461
|
+
function isWide(code) {
|
|
1462
|
+
return code >= 4352 && (code <= 4447 || code === 9001 || code === 9002 || code >= 11904 && code <= 42191 && code !== 12351 || code >= 44032 && code <= 55203 || code >= 63744 && code <= 64255 || code >= 65040 && code <= 65049 || code >= 65072 && code <= 65135 || code >= 65280 && code <= 65376 || code >= 65504 && code <= 65510 || code >= 127744 && code <= 129791 || code >= 131072 && code <= 262141);
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
// src/renderer/ui.ts
|
|
1466
|
+
class Ui {
|
|
1467
|
+
width;
|
|
1468
|
+
height;
|
|
1469
|
+
lines = [];
|
|
1470
|
+
constructor(width, height = 24) {
|
|
1471
|
+
this.width = width;
|
|
1472
|
+
this.height = height;
|
|
1473
|
+
}
|
|
1474
|
+
style(value, { tone = "default" } = {}) {
|
|
1475
|
+
return `${colors[tone]}${value}${AnsiCode.reset}`;
|
|
1476
|
+
}
|
|
1477
|
+
text(value, { tone = "default" } = {}) {
|
|
1478
|
+
const sourceLines = value.split(`
|
|
1479
|
+
`);
|
|
1480
|
+
for (const sourceLine of sourceLines) {
|
|
1481
|
+
for (const line of wrap(sourceLine, this.width)) {
|
|
1482
|
+
this.lines.push(`${colors[tone]}${line}${AnsiCode.reset}`);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
blank() {
|
|
1487
|
+
this.lines.push("");
|
|
1488
|
+
}
|
|
1489
|
+
columns(left, right, { tone = "default" } = {}) {
|
|
1490
|
+
const rightText = truncate(right, Math.max(0, this.width - 1));
|
|
1491
|
+
const leftWidth = Math.max(0, this.width - textWidth(rightText) - 1);
|
|
1492
|
+
const leftText = truncate(left, leftWidth);
|
|
1493
|
+
const gap = Math.max(0, this.width - textWidth(leftText) - textWidth(rightText));
|
|
1494
|
+
const line = `${leftText}${" ".repeat(gap)}${rightText}`;
|
|
1495
|
+
this.lines.push(`${colors[tone]}${line}${AnsiCode.reset}`);
|
|
1496
|
+
}
|
|
1497
|
+
divider({ character = "-", tone = "default" } = {}) {
|
|
1498
|
+
const token = Array.from(character)[0] ?? "-";
|
|
1499
|
+
this.lines.push(`${colors[tone]}${token.repeat(this.width)}${AnsiCode.reset}`);
|
|
1500
|
+
}
|
|
1501
|
+
header(lines) {
|
|
1502
|
+
const border = "#".repeat(this.width);
|
|
1503
|
+
this.lines.push(border);
|
|
1504
|
+
for (const line of lines) {
|
|
1505
|
+
const innerWidth = Math.max(0, this.width - 2);
|
|
1506
|
+
const truncated = truncate(line, innerWidth);
|
|
1507
|
+
const content = truncated + " ".repeat(Math.max(0, innerWidth - textWidth(truncated)));
|
|
1508
|
+
this.lines.push(`#${content}#`);
|
|
1509
|
+
}
|
|
1510
|
+
this.lines.push(border);
|
|
1511
|
+
}
|
|
1512
|
+
static renderFrame(ui) {
|
|
1513
|
+
return `${ui.lines.join(`
|
|
1514
|
+
`)}
|
|
1515
|
+
`;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
// node:string_decoder
|
|
1520
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
1521
|
+
var require_safe_buffer = __commonJS((exports, module) => {
|
|
1522
|
+
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
1523
|
+
var buffer = (init_buffer(), __toCommonJS(exports_buffer)), Buffer3 = buffer.Buffer;
|
|
1524
|
+
function copyProps(src, dst) {
|
|
1525
|
+
for (var key in src)
|
|
1526
|
+
dst[key] = src[key];
|
|
1527
|
+
}
|
|
1528
|
+
if (Buffer3.from && Buffer3.alloc && Buffer3.allocUnsafe && Buffer3.allocUnsafeSlow)
|
|
1529
|
+
module.exports = buffer;
|
|
1530
|
+
else
|
|
1531
|
+
copyProps(buffer, exports), exports.Buffer = SafeBuffer;
|
|
1532
|
+
function SafeBuffer(arg, encodingOrOffset, length) {
|
|
1533
|
+
return Buffer3(arg, encodingOrOffset, length);
|
|
1534
|
+
}
|
|
1535
|
+
SafeBuffer.prototype = Object.create(Buffer3.prototype);
|
|
1536
|
+
copyProps(Buffer3, SafeBuffer);
|
|
1537
|
+
SafeBuffer.from = function(arg, encodingOrOffset, length) {
|
|
1538
|
+
if (typeof arg === "number")
|
|
1539
|
+
throw TypeError("Argument must not be a number");
|
|
1540
|
+
return Buffer3(arg, encodingOrOffset, length);
|
|
1541
|
+
};
|
|
1542
|
+
SafeBuffer.alloc = function(size, fill, encoding) {
|
|
1543
|
+
if (typeof size !== "number")
|
|
1544
|
+
throw TypeError("Argument must be a number");
|
|
1545
|
+
var buf = Buffer3(size);
|
|
1546
|
+
if (fill !== undefined)
|
|
1547
|
+
if (typeof encoding === "string")
|
|
1548
|
+
buf.fill(fill, encoding);
|
|
1549
|
+
else
|
|
1550
|
+
buf.fill(fill);
|
|
1551
|
+
else
|
|
1552
|
+
buf.fill(0);
|
|
1553
|
+
return buf;
|
|
1554
|
+
};
|
|
1555
|
+
SafeBuffer.allocUnsafe = function(size) {
|
|
1556
|
+
if (typeof size !== "number")
|
|
1557
|
+
throw TypeError("Argument must be a number");
|
|
1558
|
+
return Buffer3(size);
|
|
1559
|
+
};
|
|
1560
|
+
SafeBuffer.allocUnsafeSlow = function(size) {
|
|
1561
|
+
if (typeof size !== "number")
|
|
1562
|
+
throw TypeError("Argument must be a number");
|
|
1563
|
+
return buffer.SlowBuffer(size);
|
|
1564
|
+
};
|
|
1565
|
+
});
|
|
1566
|
+
var Buffer3 = require_safe_buffer().Buffer;
|
|
1567
|
+
var isEncoding = Buffer3.isEncoding || function(encoding) {
|
|
1568
|
+
switch (encoding = "" + encoding, encoding && encoding.toLowerCase()) {
|
|
1569
|
+
case "hex":
|
|
1570
|
+
case "utf8":
|
|
1571
|
+
case "utf-8":
|
|
1572
|
+
case "ascii":
|
|
1573
|
+
case "binary":
|
|
1574
|
+
case "base64":
|
|
1575
|
+
case "ucs2":
|
|
1576
|
+
case "ucs-2":
|
|
1577
|
+
case "utf16le":
|
|
1578
|
+
case "utf-16le":
|
|
1579
|
+
case "raw":
|
|
1580
|
+
return true;
|
|
1581
|
+
default:
|
|
1582
|
+
return false;
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
function _normalizeEncoding(enc) {
|
|
1586
|
+
if (!enc)
|
|
1587
|
+
return "utf8";
|
|
1588
|
+
var retried;
|
|
1589
|
+
while (true)
|
|
1590
|
+
switch (enc) {
|
|
1591
|
+
case "utf8":
|
|
1592
|
+
case "utf-8":
|
|
1593
|
+
return "utf8";
|
|
1594
|
+
case "ucs2":
|
|
1595
|
+
case "ucs-2":
|
|
1596
|
+
case "utf16le":
|
|
1597
|
+
case "utf-16le":
|
|
1598
|
+
return "utf16le";
|
|
1599
|
+
case "latin1":
|
|
1600
|
+
case "binary":
|
|
1601
|
+
return "latin1";
|
|
1602
|
+
case "base64":
|
|
1603
|
+
case "ascii":
|
|
1604
|
+
case "hex":
|
|
1605
|
+
return enc;
|
|
1606
|
+
default:
|
|
1607
|
+
if (retried)
|
|
1608
|
+
return;
|
|
1609
|
+
enc = ("" + enc).toLowerCase(), retried = true;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
function normalizeEncoding(enc) {
|
|
1613
|
+
var nenc = _normalizeEncoding(enc);
|
|
1614
|
+
if (typeof nenc !== "string" && (Buffer3.isEncoding === isEncoding || !isEncoding(enc)))
|
|
1615
|
+
throw Error("Unknown encoding: " + enc);
|
|
1616
|
+
return nenc || enc;
|
|
1617
|
+
}
|
|
1618
|
+
var $StringDecoder = StringDecoder;
|
|
1619
|
+
function StringDecoder(encoding) {
|
|
1620
|
+
this.encoding = normalizeEncoding(encoding);
|
|
1621
|
+
var nb;
|
|
1622
|
+
switch (this.encoding) {
|
|
1623
|
+
case "utf16le":
|
|
1624
|
+
this.text = utf16Text, this.end = utf16End, nb = 4;
|
|
1625
|
+
break;
|
|
1626
|
+
case "utf8":
|
|
1627
|
+
this.fillLast = utf8FillLast, nb = 4;
|
|
1628
|
+
break;
|
|
1629
|
+
case "base64":
|
|
1630
|
+
this.text = base64Text, this.end = base64End, nb = 3;
|
|
1631
|
+
break;
|
|
1632
|
+
default:
|
|
1633
|
+
this.write = simpleWrite, this.end = simpleEnd;
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
this.lastNeed = 0, this.lastTotal = 0, this.lastChar = Buffer3.allocUnsafe(nb);
|
|
1637
|
+
}
|
|
1638
|
+
StringDecoder.prototype.write = function(buf) {
|
|
1639
|
+
if (buf.length === 0)
|
|
1640
|
+
return "";
|
|
1641
|
+
var r, i2;
|
|
1642
|
+
if (this.lastNeed) {
|
|
1643
|
+
if (r = this.fillLast(buf), r === undefined)
|
|
1644
|
+
return "";
|
|
1645
|
+
i2 = this.lastNeed, this.lastNeed = 0;
|
|
1646
|
+
} else
|
|
1647
|
+
i2 = 0;
|
|
1648
|
+
if (i2 < buf.length)
|
|
1649
|
+
return r ? r + this.text(buf, i2) : this.text(buf, i2);
|
|
1650
|
+
return r || "";
|
|
1651
|
+
};
|
|
1652
|
+
StringDecoder.prototype.end = utf8End;
|
|
1653
|
+
StringDecoder.prototype.text = utf8Text;
|
|
1654
|
+
StringDecoder.prototype.fillLast = function(buf) {
|
|
1655
|
+
if (this.lastNeed <= buf.length)
|
|
1656
|
+
return buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed), this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
|
1657
|
+
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length), this.lastNeed -= buf.length;
|
|
1658
|
+
};
|
|
1659
|
+
function utf8CheckByte(byte) {
|
|
1660
|
+
if (byte <= 127)
|
|
1661
|
+
return 0;
|
|
1662
|
+
else if (byte >> 5 === 6)
|
|
1663
|
+
return 2;
|
|
1664
|
+
else if (byte >> 4 === 14)
|
|
1665
|
+
return 3;
|
|
1666
|
+
else if (byte >> 3 === 30)
|
|
1667
|
+
return 4;
|
|
1668
|
+
return byte >> 6 === 2 ? -1 : -2;
|
|
1669
|
+
}
|
|
1670
|
+
function utf8CheckIncomplete(self, buf, i2) {
|
|
1671
|
+
var j = buf.length - 1;
|
|
1672
|
+
if (j < i2)
|
|
1673
|
+
return 0;
|
|
1674
|
+
var nb = utf8CheckByte(buf[j]);
|
|
1675
|
+
if (nb >= 0) {
|
|
1676
|
+
if (nb > 0)
|
|
1677
|
+
self.lastNeed = nb - 1;
|
|
1678
|
+
return nb;
|
|
1679
|
+
}
|
|
1680
|
+
if (--j < i2 || nb === -2)
|
|
1681
|
+
return 0;
|
|
1682
|
+
if (nb = utf8CheckByte(buf[j]), nb >= 0) {
|
|
1683
|
+
if (nb > 0)
|
|
1684
|
+
self.lastNeed = nb - 2;
|
|
1685
|
+
return nb;
|
|
1686
|
+
}
|
|
1687
|
+
if (--j < i2 || nb === -2)
|
|
1688
|
+
return 0;
|
|
1689
|
+
if (nb = utf8CheckByte(buf[j]), nb >= 0) {
|
|
1690
|
+
if (nb > 0)
|
|
1691
|
+
if (nb === 2)
|
|
1692
|
+
nb = 0;
|
|
1693
|
+
else
|
|
1694
|
+
self.lastNeed = nb - 3;
|
|
1695
|
+
return nb;
|
|
1696
|
+
}
|
|
1697
|
+
return 0;
|
|
1698
|
+
}
|
|
1699
|
+
function utf8CheckExtraBytes(self, buf, p) {
|
|
1700
|
+
if ((buf[0] & 192) !== 128)
|
|
1701
|
+
return self.lastNeed = 0, "�";
|
|
1702
|
+
if (self.lastNeed > 1 && buf.length > 1) {
|
|
1703
|
+
if ((buf[1] & 192) !== 128)
|
|
1704
|
+
return self.lastNeed = 1, "�";
|
|
1705
|
+
if (self.lastNeed > 2 && buf.length > 2) {
|
|
1706
|
+
if ((buf[2] & 192) !== 128)
|
|
1707
|
+
return self.lastNeed = 2, "�";
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
function utf8FillLast(buf) {
|
|
1712
|
+
var p = this.lastTotal - this.lastNeed, r = utf8CheckExtraBytes(this, buf, p);
|
|
1713
|
+
if (r !== undefined)
|
|
1714
|
+
return r;
|
|
1715
|
+
if (this.lastNeed <= buf.length)
|
|
1716
|
+
return buf.copy(this.lastChar, p, 0, this.lastNeed), this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
|
1717
|
+
buf.copy(this.lastChar, p, 0, buf.length), this.lastNeed -= buf.length;
|
|
1718
|
+
}
|
|
1719
|
+
function utf8Text(buf, i2) {
|
|
1720
|
+
var total = utf8CheckIncomplete(this, buf, i2);
|
|
1721
|
+
if (!this.lastNeed)
|
|
1722
|
+
return buf.toString("utf8", i2);
|
|
1723
|
+
this.lastTotal = total;
|
|
1724
|
+
var end = buf.length - (total - this.lastNeed);
|
|
1725
|
+
return buf.copy(this.lastChar, 0, end), buf.toString("utf8", i2, end);
|
|
1726
|
+
}
|
|
1727
|
+
function utf8End(buf) {
|
|
1728
|
+
var r = buf && buf.length ? this.write(buf) : "";
|
|
1729
|
+
if (this.lastNeed)
|
|
1730
|
+
return r + "�";
|
|
1731
|
+
return r;
|
|
1732
|
+
}
|
|
1733
|
+
function utf16Text(buf, i2) {
|
|
1734
|
+
if ((buf.length - i2) % 2 === 0) {
|
|
1735
|
+
var r = buf.toString("utf16le", i2);
|
|
1736
|
+
if (r) {
|
|
1737
|
+
var c = r.charCodeAt(r.length - 1);
|
|
1738
|
+
if (c >= 55296 && c <= 56319)
|
|
1739
|
+
return this.lastNeed = 2, this.lastTotal = 4, this.lastChar[0] = buf[buf.length - 2], this.lastChar[1] = buf[buf.length - 1], r.slice(0, -1);
|
|
1740
|
+
}
|
|
1741
|
+
return r;
|
|
1742
|
+
}
|
|
1743
|
+
return this.lastNeed = 1, this.lastTotal = 2, this.lastChar[0] = buf[buf.length - 1], buf.toString("utf16le", i2, buf.length - 1);
|
|
1744
|
+
}
|
|
1745
|
+
function utf16End(buf) {
|
|
1746
|
+
var r = buf && buf.length ? this.write(buf) : "";
|
|
1747
|
+
if (this.lastNeed) {
|
|
1748
|
+
var end = this.lastTotal - this.lastNeed;
|
|
1749
|
+
return r + this.lastChar.toString("utf16le", 0, end);
|
|
1750
|
+
}
|
|
1751
|
+
return r;
|
|
1752
|
+
}
|
|
1753
|
+
function base64Text(buf, i2) {
|
|
1754
|
+
var n = (buf.length - i2) % 3;
|
|
1755
|
+
if (n === 0)
|
|
1756
|
+
return buf.toString("base64", i2);
|
|
1757
|
+
if (this.lastNeed = 3 - n, this.lastTotal = 3, n === 1)
|
|
1758
|
+
this.lastChar[0] = buf[buf.length - 1];
|
|
1759
|
+
else
|
|
1760
|
+
this.lastChar[0] = buf[buf.length - 2], this.lastChar[1] = buf[buf.length - 1];
|
|
1761
|
+
return buf.toString("base64", i2, buf.length - n);
|
|
1762
|
+
}
|
|
1763
|
+
function base64End(buf) {
|
|
1764
|
+
var r = buf && buf.length ? this.write(buf) : "";
|
|
1765
|
+
if (this.lastNeed)
|
|
1766
|
+
return r + this.lastChar.toString("base64", 0, 3 - this.lastNeed);
|
|
1767
|
+
return r;
|
|
1768
|
+
}
|
|
1769
|
+
function simpleWrite(buf) {
|
|
1770
|
+
return buf.toString(this.encoding);
|
|
1771
|
+
}
|
|
1772
|
+
function simpleEnd(buf) {
|
|
1773
|
+
return buf && buf.length ? this.write(buf) : "";
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
// src/input/terminal-events.ts
|
|
1777
|
+
var noModifiers = {
|
|
1778
|
+
ctrl: false,
|
|
1779
|
+
shift: false,
|
|
1780
|
+
alt: false
|
|
1781
|
+
};
|
|
1782
|
+
function createNamedEvent(key, sequence, modifiers = {}) {
|
|
1783
|
+
return { key, ...noModifiers, ...modifiers, sequence };
|
|
1784
|
+
}
|
|
1785
|
+
function createTextEvent(text, sequence, modifiers = {}) {
|
|
1786
|
+
return { key: "text", text, ...noModifiers, ...modifiers, sequence };
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
// src/input/terminal-parsers.ts
|
|
1790
|
+
var controlKeys = {
|
|
1791
|
+
"\r": "enter",
|
|
1792
|
+
"\n": "enter",
|
|
1793
|
+
"\t": "tab",
|
|
1794
|
+
"": "backspace",
|
|
1795
|
+
"\b": "backspace"
|
|
1796
|
+
};
|
|
1797
|
+
var arrowKeys = {
|
|
1798
|
+
A: "up",
|
|
1799
|
+
B: "down",
|
|
1800
|
+
C: "right",
|
|
1801
|
+
D: "left"
|
|
1802
|
+
};
|
|
1803
|
+
function parseInput(value) {
|
|
1804
|
+
const character = Array.from(value)[0];
|
|
1805
|
+
if (!character) {
|
|
1806
|
+
return;
|
|
1807
|
+
}
|
|
1808
|
+
const controlKey = controlKeys[character];
|
|
1809
|
+
if (controlKey) {
|
|
1810
|
+
return parsed(createNamedEvent(controlKey, character));
|
|
1811
|
+
}
|
|
1812
|
+
if (character === "\x1B") {
|
|
1813
|
+
return parseEscapeSequence(value);
|
|
1814
|
+
}
|
|
1815
|
+
const code2 = character.charCodeAt(0);
|
|
1816
|
+
if (code2 >= 1 && code2 <= 26) {
|
|
1817
|
+
return parsed(createTextEvent(String.fromCharCode(code2 + 96), character, { ctrl: true }));
|
|
1818
|
+
}
|
|
1819
|
+
return charIsPrintable(character) ? parsed(createTextEvent(character, character)) : parsed(createNamedEvent("unknown", character));
|
|
1820
|
+
}
|
|
1821
|
+
function parseEscapeSequence(value) {
|
|
1822
|
+
if (value.length === 1) {
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
const prefix = value.charAt(1);
|
|
1826
|
+
if (prefix !== "[" && prefix !== "O") {
|
|
1827
|
+
const character = Array.from(value.slice(1))[0];
|
|
1828
|
+
if (!character) {
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1831
|
+
if (character === "\x1B") {
|
|
1832
|
+
return parsed(createNamedEvent("escape", "\x1B"));
|
|
1833
|
+
}
|
|
1834
|
+
const sequence2 = value.slice(0, 1 + character.length);
|
|
1835
|
+
return charIsPrintable(character) ? parsed(createTextEvent(character, sequence2, { alt: true })) : parsed(createNamedEvent("unknown", sequence2, { alt: true }));
|
|
1836
|
+
}
|
|
1837
|
+
const match = /^\x1b(?:O(.)|\[([0-9;]*)([A-Za-z~]))/.exec(value);
|
|
1838
|
+
if (!match) {
|
|
1839
|
+
return;
|
|
1840
|
+
}
|
|
1841
|
+
const sequence = match[0];
|
|
1842
|
+
const final = match[1] ?? match[3] ?? "";
|
|
1843
|
+
const key = arrowKeys[final] ?? "unknown";
|
|
1844
|
+
const modifiers = prefix === "[" ? parseCsiModifiers(match[2] ?? "") : {};
|
|
1845
|
+
return parsed(createNamedEvent(key, sequence, modifiers));
|
|
1846
|
+
}
|
|
1847
|
+
function parseCsiModifiers(params) {
|
|
1848
|
+
const modifier = Number(params.split(";").filter(Boolean).at(-1));
|
|
1849
|
+
const mask = modifier >= 2 && modifier <= 8 ? modifier - 1 : 0;
|
|
1850
|
+
return {
|
|
1851
|
+
shift: (mask & 1) !== 0,
|
|
1852
|
+
alt: (mask & 2) !== 0,
|
|
1853
|
+
ctrl: (mask & 4) !== 0
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
function parsed(event) {
|
|
1857
|
+
return { event, consumed: event.sequence.length };
|
|
1858
|
+
}
|
|
1859
|
+
function charIsPrintable(character) {
|
|
1860
|
+
const code2 = character.charCodeAt(0);
|
|
1861
|
+
return code2 >= 32 && code2 !== 127;
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
// src/input/terminal-input.ts
|
|
1865
|
+
var ESCAPE_DELAY_MS = 25;
|
|
1866
|
+
|
|
1867
|
+
class TerminalInput {
|
|
1868
|
+
input;
|
|
1869
|
+
onKey;
|
|
1870
|
+
pending = "";
|
|
1871
|
+
pendingEscapeTimeout;
|
|
1872
|
+
wasRaw = false;
|
|
1873
|
+
wasFlowing = false;
|
|
1874
|
+
decoder = new $StringDecoder("utf8");
|
|
1875
|
+
constructor(input = process.stdin) {
|
|
1876
|
+
this.input = input;
|
|
1877
|
+
}
|
|
1878
|
+
start(onKey) {
|
|
1879
|
+
if (this.onKey) {
|
|
1880
|
+
return;
|
|
1881
|
+
}
|
|
1882
|
+
this.onKey = onKey;
|
|
1883
|
+
this.decoder = new $StringDecoder("utf8");
|
|
1884
|
+
this.wasFlowing = this.input.readableFlowing === true;
|
|
1885
|
+
if (this.input.isTTY) {
|
|
1886
|
+
this.wasRaw = !!this.input.isRaw;
|
|
1887
|
+
this.input.setRawMode(true);
|
|
1888
|
+
}
|
|
1889
|
+
this.input.resume();
|
|
1890
|
+
this.input.on("data", this.handleData);
|
|
1891
|
+
}
|
|
1892
|
+
stop() {
|
|
1893
|
+
if (!this.onKey) {
|
|
1894
|
+
return;
|
|
1895
|
+
}
|
|
1896
|
+
this.input.off("data", this.handleData);
|
|
1897
|
+
if (this.input.isTTY) {
|
|
1898
|
+
this.input.setRawMode(this.wasRaw);
|
|
1899
|
+
}
|
|
1900
|
+
if (this.wasFlowing) {
|
|
1901
|
+
this.input.resume();
|
|
1902
|
+
} else {
|
|
1903
|
+
this.input.pause();
|
|
1904
|
+
}
|
|
1905
|
+
this.onKey = undefined;
|
|
1906
|
+
this.pending = "";
|
|
1907
|
+
this.clearEscapeTimeout();
|
|
1908
|
+
}
|
|
1909
|
+
handleData = (chunk) => {
|
|
1910
|
+
this.pending += this.decoder.write(Buffer.from(chunk));
|
|
1911
|
+
this.clearEscapeTimeout();
|
|
1912
|
+
while (this.pending) {
|
|
1913
|
+
const parsed2 = parseInput(this.pending);
|
|
1914
|
+
if (!parsed2) {
|
|
1915
|
+
if (this.pending === "\x1B") {
|
|
1916
|
+
this.waitForStandaloneEscape();
|
|
1917
|
+
}
|
|
1918
|
+
return;
|
|
1919
|
+
}
|
|
1920
|
+
this.pending = this.pending.slice(parsed2.consumed);
|
|
1921
|
+
this.onKey?.(parsed2.event);
|
|
1922
|
+
}
|
|
1923
|
+
};
|
|
1924
|
+
waitForStandaloneEscape() {
|
|
1925
|
+
this.pendingEscapeTimeout = setTimeout(() => {
|
|
1926
|
+
this.pendingEscapeTimeout = undefined;
|
|
1927
|
+
if (this.pending !== "\x1B") {
|
|
1928
|
+
return;
|
|
1929
|
+
}
|
|
1930
|
+
this.pending = "";
|
|
1931
|
+
if (this.onKey) {
|
|
1932
|
+
const namedEvent = createNamedEvent("escape", "\x1B");
|
|
1933
|
+
this.onKey(namedEvent);
|
|
1934
|
+
}
|
|
1935
|
+
}, ESCAPE_DELAY_MS);
|
|
1936
|
+
}
|
|
1937
|
+
clearEscapeTimeout() {
|
|
1938
|
+
if (this.pendingEscapeTimeout === undefined) {
|
|
1939
|
+
return;
|
|
1940
|
+
}
|
|
1941
|
+
clearTimeout(this.pendingEscapeTimeout);
|
|
1942
|
+
this.pendingEscapeTimeout = undefined;
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
// src/core/terminal-session.ts
|
|
1947
|
+
class TerminalSession {
|
|
1948
|
+
input;
|
|
1949
|
+
output;
|
|
1950
|
+
handlers;
|
|
1951
|
+
constructor(input, output = process.stdout) {
|
|
1952
|
+
this.input = new TerminalInput(input);
|
|
1953
|
+
this.output = output;
|
|
1954
|
+
}
|
|
1955
|
+
get width() {
|
|
1956
|
+
return Math.max(1, process.stdout.columns ?? 80);
|
|
1957
|
+
}
|
|
1958
|
+
get height() {
|
|
1959
|
+
return Math.max(1, process.stdout.rows ?? 24);
|
|
1960
|
+
}
|
|
1961
|
+
start(handlers) {
|
|
1962
|
+
this.handlers = handlers;
|
|
1963
|
+
this.output.write(AnsiCode.hideCursor);
|
|
1964
|
+
this.input.start(handlers.key);
|
|
1965
|
+
process.on("SIGINT", handlers.sigint);
|
|
1966
|
+
process.stdout.on("resize", handlers.resize);
|
|
1967
|
+
}
|
|
1968
|
+
writeFrame(frame) {
|
|
1969
|
+
this.output.write(`${AnsiCode.clear}${AnsiCode.reset}${frame}`);
|
|
1970
|
+
}
|
|
1971
|
+
stop() {
|
|
1972
|
+
this.input.stop();
|
|
1973
|
+
if (this.handlers) {
|
|
1974
|
+
process.off("SIGINT", this.handlers.sigint);
|
|
1975
|
+
process.stdout.off("resize", this.handlers.resize);
|
|
1976
|
+
this.handlers = undefined;
|
|
1977
|
+
}
|
|
1978
|
+
this.output.write(`${AnsiCode.clear}${AnsiCode.reset}`);
|
|
1979
|
+
this.output.write(AnsiCode.showCursor);
|
|
1980
|
+
this.output.write(AnsiCode.reset);
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
// src/core/screen-stack-app.ts
|
|
1985
|
+
class ScreenStackApp {
|
|
1986
|
+
options;
|
|
1987
|
+
frameStack = [];
|
|
1988
|
+
terminal;
|
|
1989
|
+
runCompletion;
|
|
1990
|
+
isRendering = false;
|
|
1991
|
+
hasRenderRequest = false;
|
|
1992
|
+
renderBatchDepth = 0;
|
|
1993
|
+
constructor(userOptions) {
|
|
1994
|
+
this.options = userOptions;
|
|
1995
|
+
this.terminal = new TerminalSession(userOptions.input, userOptions.output);
|
|
1996
|
+
}
|
|
1997
|
+
get isRunning() {
|
|
1998
|
+
return this.runCompletion !== undefined;
|
|
1999
|
+
}
|
|
2000
|
+
async run(root) {
|
|
2001
|
+
if (this.runCompletion) {
|
|
2002
|
+
throw new Error("This CLI app is already running.");
|
|
2003
|
+
}
|
|
2004
|
+
const completion = new Promise((resolve, reject) => {
|
|
2005
|
+
this.runCompletion = {
|
|
2006
|
+
resolve,
|
|
2007
|
+
reject
|
|
2008
|
+
};
|
|
2009
|
+
});
|
|
2010
|
+
try {
|
|
2011
|
+
this.terminal.start({
|
|
2012
|
+
key: this.handleKey,
|
|
2013
|
+
resize: this.handleResize,
|
|
2014
|
+
sigint: this.handleSigint
|
|
2015
|
+
});
|
|
2016
|
+
this.batchRender(() => this.mount(root));
|
|
2017
|
+
} catch (error) {
|
|
2018
|
+
this.stop({ error });
|
|
2019
|
+
}
|
|
2020
|
+
return completion;
|
|
2021
|
+
}
|
|
2022
|
+
dispose() {
|
|
2023
|
+
this.stop({ result: undefined });
|
|
2024
|
+
}
|
|
2025
|
+
currentFrame() {
|
|
2026
|
+
return this.frameStack.at(-1);
|
|
2027
|
+
}
|
|
2028
|
+
createFrame(screen, resolve) {
|
|
2029
|
+
const controller = new AbortController;
|
|
2030
|
+
let frame;
|
|
2031
|
+
const navigation = {
|
|
2032
|
+
push: (screen2) => this.pushFrame(frame, screen2),
|
|
2033
|
+
back: (result) => this.back(frame, result),
|
|
2034
|
+
replace: (screen2) => this.replace(frame, screen2),
|
|
2035
|
+
reset: (screen2) => this.reset(frame, screen2),
|
|
2036
|
+
exit: (result) => this.exit(frame, result)
|
|
2037
|
+
};
|
|
2038
|
+
frame = {
|
|
2039
|
+
screen,
|
|
2040
|
+
controller,
|
|
2041
|
+
environment: {
|
|
2042
|
+
context: this.options.context,
|
|
2043
|
+
navigation,
|
|
2044
|
+
signal: controller.signal,
|
|
2045
|
+
requestRender: () => this.requestRender(frame)
|
|
2046
|
+
},
|
|
2047
|
+
resolve
|
|
2048
|
+
};
|
|
2049
|
+
return frame;
|
|
2050
|
+
}
|
|
2051
|
+
mount(screen, resolve) {
|
|
2052
|
+
const frame = this.createFrame(screen, resolve);
|
|
2053
|
+
this.frameStack.push(frame);
|
|
2054
|
+
this.runLifecycleHook(frame, frame.screen.mount);
|
|
2055
|
+
return frame;
|
|
2056
|
+
}
|
|
2057
|
+
requestRender(frame) {
|
|
2058
|
+
if (!frame.controller.signal.aborted && frame === this.currentFrame()) {
|
|
2059
|
+
this.render();
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
pushFrame(expected, screen) {
|
|
2063
|
+
const parent = this.currentFrame();
|
|
2064
|
+
if (!this.isRunning || !parent || expected !== parent) {
|
|
2065
|
+
return Promise.resolve(undefined);
|
|
2066
|
+
}
|
|
2067
|
+
return this.batchRender(() => {
|
|
2068
|
+
this.runLifecycleHook(parent, parent.screen.suspend);
|
|
2069
|
+
return new Promise((resolve) => {
|
|
2070
|
+
this.mount(screen, resolve);
|
|
2071
|
+
});
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
back(expected, result) {
|
|
2075
|
+
if (!this.runCompletion || expected !== this.currentFrame()) {
|
|
2076
|
+
return;
|
|
2077
|
+
}
|
|
2078
|
+
if (this.frameStack.length === 1) {
|
|
2079
|
+
this.stop({ result });
|
|
2080
|
+
return;
|
|
2081
|
+
}
|
|
2082
|
+
this.batchRender(() => {
|
|
2083
|
+
const closed = this.frameStack.pop();
|
|
2084
|
+
this.unmount(closed);
|
|
2085
|
+
closed.resolve?.(result);
|
|
2086
|
+
const parent = this.currentFrame();
|
|
2087
|
+
if (parent) {
|
|
2088
|
+
this.runLifecycleHook(parent, parent.screen.resume);
|
|
2089
|
+
}
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
replace(expected, screen) {
|
|
2093
|
+
const current = this.currentFrame();
|
|
2094
|
+
if (!this.runCompletion || expected !== current) {
|
|
2095
|
+
return;
|
|
2096
|
+
}
|
|
2097
|
+
this.batchRender(() => {
|
|
2098
|
+
const closed = this.frameStack.pop();
|
|
2099
|
+
this.unmount(closed);
|
|
2100
|
+
this.mount(screen, closed.resolve);
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
reset(expected, screen) {
|
|
2104
|
+
const current = this.currentFrame();
|
|
2105
|
+
if (!this.runCompletion || expected !== current) {
|
|
2106
|
+
return;
|
|
2107
|
+
}
|
|
2108
|
+
this.batchRender(() => {
|
|
2109
|
+
const oldFrames = this.frameStack.splice(0);
|
|
2110
|
+
for (const frame of oldFrames.reverse()) {
|
|
2111
|
+
this.unmount(frame);
|
|
2112
|
+
frame.resolve?.(undefined);
|
|
2113
|
+
}
|
|
2114
|
+
this.mount(screen);
|
|
2115
|
+
});
|
|
2116
|
+
}
|
|
2117
|
+
exit(expected, result) {
|
|
2118
|
+
const current = this.currentFrame();
|
|
2119
|
+
if (!this.runCompletion || expected !== current) {
|
|
2120
|
+
return;
|
|
2121
|
+
}
|
|
2122
|
+
this.stop({ result });
|
|
2123
|
+
}
|
|
2124
|
+
render() {
|
|
2125
|
+
const frame = this.currentFrame();
|
|
2126
|
+
if (!this.runCompletion || !frame) {
|
|
2127
|
+
return;
|
|
2128
|
+
}
|
|
2129
|
+
if (this.isRendering || this.renderBatchDepth > 0) {
|
|
2130
|
+
this.hasRenderRequest = true;
|
|
2131
|
+
return;
|
|
2132
|
+
}
|
|
2133
|
+
this.isRendering = true;
|
|
2134
|
+
try {
|
|
2135
|
+
const ui = new Ui(this.terminal.width, this.terminal.height);
|
|
2136
|
+
const environment = {
|
|
2137
|
+
...frame.environment,
|
|
2138
|
+
ui
|
|
2139
|
+
};
|
|
2140
|
+
frame.screen.render(environment);
|
|
2141
|
+
this.terminal.writeFrame(Ui.renderFrame(ui));
|
|
2142
|
+
} catch (error) {
|
|
2143
|
+
this.reportError(error);
|
|
2144
|
+
} finally {
|
|
2145
|
+
this.isRendering = false;
|
|
2146
|
+
if (this.hasRenderRequest) {
|
|
2147
|
+
this.hasRenderRequest = false;
|
|
2148
|
+
queueMicrotask(() => this.render());
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
batchRender(callback) {
|
|
2153
|
+
this.renderBatchDepth += 1;
|
|
2154
|
+
try {
|
|
2155
|
+
return callback();
|
|
2156
|
+
} finally {
|
|
2157
|
+
this.renderBatchDepth -= 1;
|
|
2158
|
+
if (this.renderBatchDepth === 0 && this.runCompletion) {
|
|
2159
|
+
this.hasRenderRequest = false;
|
|
2160
|
+
this.render();
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
handleKey = (event) => {
|
|
2165
|
+
if (!this.runCompletion)
|
|
2166
|
+
return;
|
|
2167
|
+
if (event.key === "text" && event.ctrl && event.text === "c") {
|
|
2168
|
+
this.stop({ result: undefined });
|
|
2169
|
+
return;
|
|
2170
|
+
}
|
|
2171
|
+
const frame = this.currentFrame();
|
|
2172
|
+
if (!frame?.screen.key)
|
|
2173
|
+
return;
|
|
2174
|
+
try {
|
|
2175
|
+
frame.screen.key(event, frame.environment);
|
|
2176
|
+
} catch (error) {
|
|
2177
|
+
this.reportError(error);
|
|
2178
|
+
}
|
|
2179
|
+
};
|
|
2180
|
+
handleSigint = () => {
|
|
2181
|
+
this.stop({ result: undefined });
|
|
2182
|
+
};
|
|
2183
|
+
handleResize = () => {
|
|
2184
|
+
this.render();
|
|
2185
|
+
};
|
|
2186
|
+
runLifecycleHook(frame, hook) {
|
|
2187
|
+
if (!hook) {
|
|
2188
|
+
return;
|
|
2189
|
+
}
|
|
2190
|
+
try {
|
|
2191
|
+
const pending = hook.call(frame.screen, frame.environment);
|
|
2192
|
+
if (pending) {
|
|
2193
|
+
Promise.resolve(pending).catch((error) => this.reportError(error));
|
|
2194
|
+
}
|
|
2195
|
+
} catch (error) {
|
|
2196
|
+
this.reportError(error);
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
unmount(frame, duringCleanup = false) {
|
|
2200
|
+
if (frame.controller.signal.aborted) {
|
|
2201
|
+
return;
|
|
2202
|
+
}
|
|
2203
|
+
frame.controller.abort();
|
|
2204
|
+
try {
|
|
2205
|
+
frame.screen.unmount?.call(frame.screen, frame.environment);
|
|
2206
|
+
} catch (error) {
|
|
2207
|
+
if (!duringCleanup) {
|
|
2208
|
+
this.reportError(error);
|
|
2209
|
+
return;
|
|
2210
|
+
}
|
|
2211
|
+
return this.reportCleanupError(error);
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
reportError(error) {
|
|
2215
|
+
if (this.options.onError) {
|
|
2216
|
+
try {
|
|
2217
|
+
this.options.onError(error);
|
|
2218
|
+
} catch (handlerError) {
|
|
2219
|
+
this.stop({ error: handlerError });
|
|
2220
|
+
}
|
|
2221
|
+
return;
|
|
2222
|
+
}
|
|
2223
|
+
this.stop({ error });
|
|
2224
|
+
}
|
|
2225
|
+
reportCleanupError(error) {
|
|
2226
|
+
if (!this.options.onError)
|
|
2227
|
+
return error;
|
|
2228
|
+
try {
|
|
2229
|
+
this.options.onError(error);
|
|
2230
|
+
} catch (handlerError) {
|
|
2231
|
+
return handlerError;
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
stop(outcome) {
|
|
2235
|
+
const activeRun = this.runCompletion;
|
|
2236
|
+
if (!activeRun) {
|
|
2237
|
+
return;
|
|
2238
|
+
}
|
|
2239
|
+
this.runCompletion = undefined;
|
|
2240
|
+
const cleanupError = this.cleanupFrames();
|
|
2241
|
+
let terminalError;
|
|
2242
|
+
try {
|
|
2243
|
+
this.terminal.stop();
|
|
2244
|
+
} catch (error) {
|
|
2245
|
+
terminalError = error;
|
|
2246
|
+
}
|
|
2247
|
+
if ("error" in outcome) {
|
|
2248
|
+
activeRun.reject(outcome.error);
|
|
2249
|
+
} else if (cleanupError !== undefined) {
|
|
2250
|
+
activeRun.reject(cleanupError);
|
|
2251
|
+
} else if (terminalError !== undefined) {
|
|
2252
|
+
activeRun.reject(terminalError);
|
|
2253
|
+
} else {
|
|
2254
|
+
activeRun.resolve(outcome.result);
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
cleanupFrames() {
|
|
2258
|
+
let firstError;
|
|
2259
|
+
const oldFrames = this.frameStack.splice(0);
|
|
2260
|
+
for (const frame of oldFrames.reverse()) {
|
|
2261
|
+
const error = this.unmount(frame, true);
|
|
2262
|
+
firstError ??= error;
|
|
2263
|
+
frame.resolve?.(undefined);
|
|
2264
|
+
}
|
|
2265
|
+
return firstError;
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
// src/cli-app.ts
|
|
2270
|
+
function createCli(options) {
|
|
2271
|
+
const resolvedOptions = options ?? { context: undefined };
|
|
2272
|
+
return new ScreenStackApp(resolvedOptions);
|
|
2273
|
+
}
|
|
2274
|
+
// src/screen/screen.ts
|
|
2275
|
+
function defineScreen(screen) {
|
|
2276
|
+
return screen;
|
|
2277
|
+
}
|
|
2278
|
+
// src/renderer/text-content.ts
|
|
2279
|
+
function normalizeText(content, defaults = {}) {
|
|
2280
|
+
return typeof content === "string" ? { align: "left", tone: "default", ...defaults, value: content } : { align: "left", tone: "default", ...defaults, ...content };
|
|
2281
|
+
}
|
|
2282
|
+
function renderText(ui, content, defaults) {
|
|
2283
|
+
const { value, tone, align } = normalizeText(content, defaults);
|
|
2284
|
+
const aligned = alignText(value, align, ui.width);
|
|
2285
|
+
ui.text(aligned, { tone });
|
|
2286
|
+
}
|
|
2287
|
+
function alignText(value, alignment, width) {
|
|
2288
|
+
return value.split(`
|
|
2289
|
+
`).map((line) => `${alignmentPadding(line, alignment, width)}${line}`).join(`
|
|
2290
|
+
`);
|
|
2291
|
+
}
|
|
2292
|
+
function alignmentPadding(completeLine, alignment, width) {
|
|
2293
|
+
const available = Math.max(0, width - textWidth(completeLine));
|
|
2294
|
+
const padding = alignment === "center" ? Math.floor(available / 2) : alignment === "right" ? available : 0;
|
|
2295
|
+
return " ".repeat(padding);
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
// src/screen/select.ts
|
|
2299
|
+
function select(options) {
|
|
2300
|
+
let selectedIndex = findEnabled(options.choices, options.initialIndex ?? 0, 1);
|
|
2301
|
+
let windowStart = 0;
|
|
2302
|
+
return defineScreen({
|
|
2303
|
+
render({ ui }) {
|
|
2304
|
+
if (options.title) {
|
|
2305
|
+
renderText(ui, options.title, { tone: "accent" });
|
|
2306
|
+
ui.blank();
|
|
2307
|
+
}
|
|
2308
|
+
const subtitleText = options.subtitle ?? "Use ↑/↓ to move, Enter to select.";
|
|
2309
|
+
renderText(ui, subtitleText, { tone: "muted" });
|
|
2310
|
+
ui.blank();
|
|
2311
|
+
const titleRows = options.title ? normalizeText(options.title).value.split(`
|
|
2312
|
+
`).length + 1 : 0;
|
|
2313
|
+
const subtitleRows = normalizeText(subtitleText).value.split(`
|
|
2314
|
+
`).length + 1;
|
|
2315
|
+
const viewport = getViewport(options.choices, selectedIndex, windowStart, Math.max(1, ui.height - titleRows - subtitleRows), options.maxVisible);
|
|
2316
|
+
windowStart = viewport.start;
|
|
2317
|
+
if (viewport.start > 0) {
|
|
2318
|
+
ui.text(` ↑ ${viewport.start} more`, { tone: "muted" });
|
|
2319
|
+
}
|
|
2320
|
+
for (let index = viewport.start;index < viewport.end; index++) {
|
|
2321
|
+
const choice = options.choices[index];
|
|
2322
|
+
const marker = index === selectedIndex ? "> " : " ";
|
|
2323
|
+
const suffix = choice.disabled ? " (unavailable)" : "";
|
|
2324
|
+
const label = normalizeText(choice.label);
|
|
2325
|
+
renderText(ui, {
|
|
2326
|
+
value: `${marker}${label.value}${suffix}`,
|
|
2327
|
+
align: label.align,
|
|
2328
|
+
tone: index === selectedIndex ? "accent" : choice.disabled ? "muted" : label.tone
|
|
2329
|
+
});
|
|
2330
|
+
if (choice.description) {
|
|
2331
|
+
const description = normalizeText(choice.description, { tone: "muted" });
|
|
2332
|
+
renderText(ui, {
|
|
2333
|
+
...description,
|
|
2334
|
+
value: ` ${description.value}`
|
|
2335
|
+
});
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
const remaining = options.choices.length - viewport.end;
|
|
2339
|
+
if (remaining > 0) {
|
|
2340
|
+
ui.text(` ↓ ${remaining} more`, { tone: "muted" });
|
|
2341
|
+
}
|
|
2342
|
+
},
|
|
2343
|
+
key(event, { navigation, requestRender }) {
|
|
2344
|
+
const cancelKeys = options.cancelKeys ?? ["escape", "backspace"];
|
|
2345
|
+
if (cancelKeys.includes(event.key)) {
|
|
2346
|
+
navigation.back();
|
|
2347
|
+
return;
|
|
2348
|
+
}
|
|
2349
|
+
if (event.key === "enter") {
|
|
2350
|
+
const selected = options.choices[selectedIndex];
|
|
2351
|
+
if (selected && !selected.disabled) {
|
|
2352
|
+
navigation.back(selected.value);
|
|
2353
|
+
}
|
|
2354
|
+
return;
|
|
2355
|
+
}
|
|
2356
|
+
const direction = event.key === "up" ? -1 : event.key === "down" ? 1 : 0;
|
|
2357
|
+
if (direction === 0 || options.choices.length === 0) {
|
|
2358
|
+
return;
|
|
2359
|
+
}
|
|
2360
|
+
const next = move(options.choices, selectedIndex, direction, options.loop ?? true);
|
|
2361
|
+
if (next !== selectedIndex) {
|
|
2362
|
+
selectedIndex = next;
|
|
2363
|
+
requestRender();
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
});
|
|
2367
|
+
}
|
|
2368
|
+
function getViewport(choices, selectedIndex, requestedStart, availableRows, maxVisible = Number.POSITIVE_INFINITY) {
|
|
2369
|
+
if (choices.length === 0)
|
|
2370
|
+
return { start: 0, end: 0 };
|
|
2371
|
+
let start = Math.max(0, Math.min(requestedStart, choices.length - 1));
|
|
2372
|
+
if (selectedIndex >= 0 && selectedIndex < start) {
|
|
2373
|
+
start = selectedIndex;
|
|
2374
|
+
}
|
|
2375
|
+
let end = viewportEnd(choices, start, availableRows, maxVisible);
|
|
2376
|
+
while (selectedIndex >= end && start < selectedIndex) {
|
|
2377
|
+
start += 1;
|
|
2378
|
+
end = viewportEnd(choices, start, availableRows, maxVisible);
|
|
2379
|
+
}
|
|
2380
|
+
return { start, end };
|
|
2381
|
+
}
|
|
2382
|
+
function viewportEnd(choices, start, availableRows, maxVisible) {
|
|
2383
|
+
let rowsUsed = start > 0 ? 1 : 0;
|
|
2384
|
+
let end = start;
|
|
2385
|
+
let visibleCount = 0;
|
|
2386
|
+
const choiceLimit = Math.max(1, maxVisible);
|
|
2387
|
+
while (end < choices.length && visibleCount < choiceLimit) {
|
|
2388
|
+
const choiceRows = choices[end]?.description ? 2 : 1;
|
|
2389
|
+
const bottomIndicatorRows = end + 1 < choices.length ? 1 : 0;
|
|
2390
|
+
if (end > start && rowsUsed + choiceRows + bottomIndicatorRows > availableRows) {
|
|
2391
|
+
break;
|
|
2392
|
+
}
|
|
2393
|
+
rowsUsed += choiceRows;
|
|
2394
|
+
end += 1;
|
|
2395
|
+
visibleCount += 1;
|
|
2396
|
+
}
|
|
2397
|
+
return Math.max(start + 1, end);
|
|
2398
|
+
}
|
|
2399
|
+
function findEnabled(choices, requestedIndex, direction) {
|
|
2400
|
+
if (choices.length === 0) {
|
|
2401
|
+
return -1;
|
|
2402
|
+
}
|
|
2403
|
+
const start = Math.min(Math.max(0, requestedIndex), choices.length - 1);
|
|
2404
|
+
for (let offset = 0;offset < choices.length; offset++) {
|
|
2405
|
+
const index = (start + offset * direction + choices.length) % choices.length;
|
|
2406
|
+
if (!choices[index]?.disabled) {
|
|
2407
|
+
return index;
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
return -1;
|
|
2411
|
+
}
|
|
2412
|
+
function move(choices, current, direction, loop) {
|
|
2413
|
+
if (current < 0) {
|
|
2414
|
+
return findEnabled(choices, 0, 1);
|
|
2415
|
+
}
|
|
2416
|
+
let index = current;
|
|
2417
|
+
for (let count = 0;count < choices.length; count++) {
|
|
2418
|
+
const candidate = index + direction;
|
|
2419
|
+
if (!loop && (candidate < 0 || candidate >= choices.length)) {
|
|
2420
|
+
return current;
|
|
2421
|
+
}
|
|
2422
|
+
index = (candidate + choices.length) % choices.length;
|
|
2423
|
+
if (!choices[index]?.disabled) {
|
|
2424
|
+
return index;
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
return current;
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
// src/screen/menu.ts
|
|
2431
|
+
var backAction = Symbol("back");
|
|
2432
|
+
function menu(options) {
|
|
2433
|
+
const choices = options.backLabel === false ? options.choices : [
|
|
2434
|
+
...options.choices,
|
|
2435
|
+
{ label: options.backLabel ?? "Back", value: backAction }
|
|
2436
|
+
];
|
|
2437
|
+
const selection = select({
|
|
2438
|
+
...options,
|
|
2439
|
+
choices
|
|
2440
|
+
});
|
|
2441
|
+
return defineScreen({
|
|
2442
|
+
render(environment) {
|
|
2443
|
+
selection.render(environment);
|
|
2444
|
+
},
|
|
2445
|
+
key(event, environment) {
|
|
2446
|
+
let selected;
|
|
2447
|
+
const proxy = {
|
|
2448
|
+
...environment,
|
|
2449
|
+
navigation: {
|
|
2450
|
+
...environment.navigation,
|
|
2451
|
+
back(value) {
|
|
2452
|
+
if (value !== undefined) {
|
|
2453
|
+
selected = value;
|
|
2454
|
+
} else {
|
|
2455
|
+
environment.navigation.back();
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
};
|
|
2460
|
+
selection.key?.(event, proxy);
|
|
2461
|
+
if (selected === backAction) {
|
|
2462
|
+
environment.navigation.back();
|
|
2463
|
+
} else if (selected !== undefined) {
|
|
2464
|
+
options.onSelect(selected, environment);
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
});
|
|
2468
|
+
}
|
|
2469
|
+
// src/screen/message.ts
|
|
2470
|
+
function message(options) {
|
|
2471
|
+
const settings = typeof options === "string" || "value" in options ? { text: options } : options;
|
|
2472
|
+
const dismissKeys = settings.dismissKeys ?? ["enter", "escape", "backspace"];
|
|
2473
|
+
return defineScreen({
|
|
2474
|
+
render({ ui }) {
|
|
2475
|
+
if (settings.title) {
|
|
2476
|
+
renderText(ui, settings.title, { tone: "accent" });
|
|
2477
|
+
ui.blank();
|
|
2478
|
+
}
|
|
2479
|
+
renderText(ui, settings.text);
|
|
2480
|
+
ui.blank();
|
|
2481
|
+
renderText(ui, settings.hint ?? "Press Enter to return.", { tone: "muted" });
|
|
2482
|
+
},
|
|
2483
|
+
key(event, { navigation }) {
|
|
2484
|
+
if (dismissKeys.includes("any") || dismissKeys.includes(event.key)) {
|
|
2485
|
+
navigation.back();
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
// src/screen/sequence.ts
|
|
2491
|
+
function sequence(sources) {
|
|
2492
|
+
return defineScreen({
|
|
2493
|
+
async mount({ navigation, signal }) {
|
|
2494
|
+
for (const source of sources) {
|
|
2495
|
+
if (signal.aborted) {
|
|
2496
|
+
return;
|
|
2497
|
+
}
|
|
2498
|
+
const screen = typeof source === "function" ? source() : source;
|
|
2499
|
+
await navigation.push(screen);
|
|
2500
|
+
}
|
|
2501
|
+
if (!signal.aborted) {
|
|
2502
|
+
navigation.back();
|
|
2503
|
+
}
|
|
2504
|
+
},
|
|
2505
|
+
render() {}
|
|
2506
|
+
});
|
|
2507
|
+
}
|
|
2508
|
+
// src/screen/text-input.ts
|
|
2509
|
+
function textInput(options = {}) {
|
|
2510
|
+
let value = options.initialValue ?? "";
|
|
2511
|
+
let cursor = Array.from(value).length;
|
|
2512
|
+
let error;
|
|
2513
|
+
return defineScreen({
|
|
2514
|
+
render({ ui }) {
|
|
2515
|
+
renderText(ui, options.message ?? "Enter a value, then press Enter.");
|
|
2516
|
+
ui.blank();
|
|
2517
|
+
const mask = typeof options.mask === "string" ? options.mask : "*";
|
|
2518
|
+
const characters = Array.from(value);
|
|
2519
|
+
const visibleCharacters = options.mask ? characters.map(() => mask) : characters;
|
|
2520
|
+
let input;
|
|
2521
|
+
if (visibleCharacters.length === 0) {
|
|
2522
|
+
input = normalizeText(options.placeholder ?? "│", { tone: "muted" });
|
|
2523
|
+
} else {
|
|
2524
|
+
const beforeCursor = visibleCharacters.slice(0, cursor).join("");
|
|
2525
|
+
const afterCursor = visibleCharacters.slice(cursor).join("");
|
|
2526
|
+
input = {
|
|
2527
|
+
value: `${beforeCursor}│${afterCursor}`,
|
|
2528
|
+
align: "left",
|
|
2529
|
+
tone: "accent"
|
|
2530
|
+
};
|
|
2531
|
+
}
|
|
2532
|
+
renderText(ui, {
|
|
2533
|
+
...input,
|
|
2534
|
+
value: `> ${input.value}`
|
|
2535
|
+
});
|
|
2536
|
+
if (error) {
|
|
2537
|
+
ui.blank();
|
|
2538
|
+
renderText(ui, error, { tone: "accent" });
|
|
2539
|
+
}
|
|
2540
|
+
},
|
|
2541
|
+
key(event, { navigation, requestRender }) {
|
|
2542
|
+
if (event.key === "escape" && (options.cancelKeys ?? ["escape"]).includes("escape")) {
|
|
2543
|
+
navigation.back();
|
|
2544
|
+
return;
|
|
2545
|
+
}
|
|
2546
|
+
if (event.key === "enter") {
|
|
2547
|
+
error = !options.allowEmpty && value.length === 0 ? "A value is required." : options.validate?.(value);
|
|
2548
|
+
if (error) {
|
|
2549
|
+
requestRender();
|
|
2550
|
+
} else {
|
|
2551
|
+
navigation.back(value);
|
|
2552
|
+
}
|
|
2553
|
+
return;
|
|
2554
|
+
}
|
|
2555
|
+
if (event.key === "backspace") {
|
|
2556
|
+
const characters = Array.from(value);
|
|
2557
|
+
if (cursor > 0) {
|
|
2558
|
+
characters.splice(cursor - 1, 1);
|
|
2559
|
+
cursor -= 1;
|
|
2560
|
+
value = characters.join("");
|
|
2561
|
+
}
|
|
2562
|
+
error = undefined;
|
|
2563
|
+
requestRender();
|
|
2564
|
+
return;
|
|
2565
|
+
}
|
|
2566
|
+
if (event.key === "left" || event.key === "right") {
|
|
2567
|
+
const change = event.key === "left" ? -1 : 1;
|
|
2568
|
+
cursor = Math.max(0, Math.min(Array.from(value).length, cursor + change));
|
|
2569
|
+
requestRender();
|
|
2570
|
+
return;
|
|
2571
|
+
}
|
|
2572
|
+
if (event.key === "text" && !event.ctrl && !event.alt) {
|
|
2573
|
+
const characters = Array.from(value);
|
|
2574
|
+
const inserted = Array.from(event.text);
|
|
2575
|
+
characters.splice(cursor, 0, ...inserted);
|
|
2576
|
+
cursor += inserted.length;
|
|
2577
|
+
value = characters.join("");
|
|
2578
|
+
error = undefined;
|
|
2579
|
+
requestRender();
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
});
|
|
2583
|
+
}
|
|
2584
|
+
// src/screen/typewriter.ts
|
|
2585
|
+
function typewriter(options) {
|
|
2586
|
+
const title = options.title === undefined ? undefined : normalizeText(options.title);
|
|
2587
|
+
const body = normalizeText(options.text);
|
|
2588
|
+
const characters = Array.from(body.value);
|
|
2589
|
+
const speed = Math.max(1, options.charactersPerSecond ?? 30);
|
|
2590
|
+
let visibleCount = 0;
|
|
2591
|
+
let timer;
|
|
2592
|
+
return defineScreen({
|
|
2593
|
+
mount({ requestRender, navigation, signal }) {
|
|
2594
|
+
if (characters.length === 0) {
|
|
2595
|
+
if (options.autoDismiss) {
|
|
2596
|
+
navigation.back();
|
|
2597
|
+
}
|
|
2598
|
+
return;
|
|
2599
|
+
}
|
|
2600
|
+
const delay = Math.max(1, Math.round(1000 / speed));
|
|
2601
|
+
timer = setInterval(() => {
|
|
2602
|
+
visibleCount = Math.min(characters.length, visibleCount + 1);
|
|
2603
|
+
requestRender();
|
|
2604
|
+
if (visibleCount === characters.length && timer) {
|
|
2605
|
+
clearInterval(timer);
|
|
2606
|
+
timer = undefined;
|
|
2607
|
+
if (options.autoDismiss) {
|
|
2608
|
+
navigation.back();
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
}, delay);
|
|
2612
|
+
signal.addEventListener("abort", () => {
|
|
2613
|
+
if (timer) {
|
|
2614
|
+
clearInterval(timer);
|
|
2615
|
+
}
|
|
2616
|
+
timer = undefined;
|
|
2617
|
+
}, { once: true });
|
|
2618
|
+
},
|
|
2619
|
+
render({ ui }) {
|
|
2620
|
+
if (title) {
|
|
2621
|
+
const titleContent = alignText(title.value, title.align, ui.width);
|
|
2622
|
+
ui.text(titleContent, { tone: title.tone });
|
|
2623
|
+
ui.blank();
|
|
2624
|
+
}
|
|
2625
|
+
const bodyContent = alignAnimatedText(body.value, visibleCount, body.align, ui.width);
|
|
2626
|
+
ui.text(bodyContent, { tone: body.tone });
|
|
2627
|
+
if (visibleCount === characters.length && !options.autoDismiss) {
|
|
2628
|
+
ui.blank();
|
|
2629
|
+
const dismissText = alignText("Press Enter to return.", body.align, ui.width);
|
|
2630
|
+
ui.text(dismissText);
|
|
2631
|
+
}
|
|
2632
|
+
},
|
|
2633
|
+
key(event, { navigation, requestRender }) {
|
|
2634
|
+
if (options.autoDismiss) {
|
|
2635
|
+
return;
|
|
2636
|
+
}
|
|
2637
|
+
if (visibleCount < characters.length) {
|
|
2638
|
+
visibleCount = characters.length;
|
|
2639
|
+
if (timer) {
|
|
2640
|
+
clearInterval(timer);
|
|
2641
|
+
}
|
|
2642
|
+
timer = undefined;
|
|
2643
|
+
requestRender();
|
|
2644
|
+
return;
|
|
2645
|
+
}
|
|
2646
|
+
if (visibleCount === characters.length && (event.key === "enter" || event.key === "escape" || event.key === "backspace")) {
|
|
2647
|
+
navigation.back();
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
});
|
|
2651
|
+
}
|
|
2652
|
+
function alignAnimatedText(completeText, visibleCount, alignment, width) {
|
|
2653
|
+
const completeLines = completeText.split(`
|
|
2654
|
+
`);
|
|
2655
|
+
const visibleLines = Array.from(completeText).slice(0, visibleCount).join("").split(`
|
|
2656
|
+
`);
|
|
2657
|
+
return visibleLines.map((line, index) => {
|
|
2658
|
+
const completeLine = completeLines[index] ?? "";
|
|
2659
|
+
return `${alignmentPadding(completeLine, alignment, width)}${line}`;
|
|
2660
|
+
}).join(`
|
|
2661
|
+
`);
|
|
2662
|
+
}
|
|
2663
|
+
// src/screen/with-task.ts
|
|
2664
|
+
function withTask(screen, task) {
|
|
2665
|
+
let screenEnvironment;
|
|
2666
|
+
return defineScreen({
|
|
2667
|
+
async mount(environment) {
|
|
2668
|
+
screenEnvironment = decorateEnvironment(environment);
|
|
2669
|
+
const visualMount = Promise.resolve(screen.mount?.(screenEnvironment));
|
|
2670
|
+
const taskResult = Promise.resolve().then(() => task({
|
|
2671
|
+
context: environment.context,
|
|
2672
|
+
signal: environment.signal
|
|
2673
|
+
}));
|
|
2674
|
+
const visualMountFailure = visualMount.then(() => new Promise(() => {}), (error) => Promise.reject(error));
|
|
2675
|
+
const result = await Promise.race([taskResult, visualMountFailure]);
|
|
2676
|
+
if (!environment.signal.aborted) {
|
|
2677
|
+
environment.navigation.back(result);
|
|
2678
|
+
}
|
|
2679
|
+
},
|
|
2680
|
+
render(environment) {
|
|
2681
|
+
const decorated = screenEnvironment ?? decorateEnvironment(environment);
|
|
2682
|
+
const renderEnvironment = {
|
|
2683
|
+
...decorated,
|
|
2684
|
+
ui: environment.ui
|
|
2685
|
+
};
|
|
2686
|
+
screen.render(renderEnvironment);
|
|
2687
|
+
},
|
|
2688
|
+
key(event) {
|
|
2689
|
+
if (screenEnvironment) {
|
|
2690
|
+
screen.key?.(event, screenEnvironment);
|
|
2691
|
+
}
|
|
2692
|
+
},
|
|
2693
|
+
suspend() {
|
|
2694
|
+
if (screenEnvironment) {
|
|
2695
|
+
screen.suspend?.(screenEnvironment);
|
|
2696
|
+
}
|
|
2697
|
+
},
|
|
2698
|
+
resume() {
|
|
2699
|
+
if (screenEnvironment) {
|
|
2700
|
+
screen.resume?.(screenEnvironment);
|
|
2701
|
+
}
|
|
2702
|
+
},
|
|
2703
|
+
unmount() {
|
|
2704
|
+
if (screenEnvironment) {
|
|
2705
|
+
screen.unmount?.(screenEnvironment);
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
});
|
|
2709
|
+
}
|
|
2710
|
+
function decorateEnvironment(environment) {
|
|
2711
|
+
const navigation = {
|
|
2712
|
+
...environment.navigation,
|
|
2713
|
+
back() {},
|
|
2714
|
+
replace() {},
|
|
2715
|
+
reset() {},
|
|
2716
|
+
exit() {}
|
|
2717
|
+
};
|
|
2718
|
+
return {
|
|
2719
|
+
...environment,
|
|
2720
|
+
navigation
|
|
2721
|
+
};
|
|
2722
|
+
}
|
|
2723
|
+
export {
|
|
2724
|
+
withTask,
|
|
2725
|
+
typewriter,
|
|
2726
|
+
textInput,
|
|
2727
|
+
sequence,
|
|
2728
|
+
select,
|
|
2729
|
+
message,
|
|
2730
|
+
menu,
|
|
2731
|
+
defineScreen,
|
|
2732
|
+
createCli,
|
|
2733
|
+
Ui
|
|
2734
|
+
};
|