@boba-cli/machine 0.1.0-alpha.1

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/dist/index.js ADDED
@@ -0,0 +1,364 @@
1
+ // src/bytes.ts
2
+ var encoder = new TextEncoder();
3
+ var decoder = new TextDecoder("utf-8");
4
+ function encodeString(text) {
5
+ return encoder.encode(text);
6
+ }
7
+ function decodeString(bytes) {
8
+ return decoder.decode(bytes);
9
+ }
10
+ function byteLength(text) {
11
+ return encoder.encode(text).length;
12
+ }
13
+ function concatBytes(...arrays) {
14
+ const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
15
+ const result = new Uint8Array(totalLength);
16
+ let offset = 0;
17
+ for (const arr of arrays) {
18
+ result.set(arr, offset);
19
+ offset += arr.length;
20
+ }
21
+ return result;
22
+ }
23
+ function allocBytes(size) {
24
+ return new Uint8Array(size);
25
+ }
26
+ function fromBytes(values) {
27
+ return new Uint8Array(values);
28
+ }
29
+ function bytesEqual(a, b) {
30
+ if (a.length !== b.length) {
31
+ return false;
32
+ }
33
+ for (let i = 0; i < a.length; i++) {
34
+ if (a[i] !== b[i]) {
35
+ return false;
36
+ }
37
+ }
38
+ return true;
39
+ }
40
+ function startsWith(bytes, prefix) {
41
+ if (bytes.length < prefix.length) {
42
+ return false;
43
+ }
44
+ for (let i = 0; i < prefix.length; i++) {
45
+ if (bytes[i] !== prefix[i]) {
46
+ return false;
47
+ }
48
+ }
49
+ return true;
50
+ }
51
+ function startsWithString(bytes, prefix) {
52
+ return startsWith(bytes, encodeString(prefix));
53
+ }
54
+ function indexOfString(bytes, needle, fromIndex = 0) {
55
+ const needleBytes = encodeString(needle);
56
+ const endIndex = bytes.length - needleBytes.length;
57
+ outer: for (let i = fromIndex; i <= endIndex; i++) {
58
+ for (let j = 0; j < needleBytes.length; j++) {
59
+ if (bytes[i + j] !== needleBytes[j]) {
60
+ continue outer;
61
+ }
62
+ }
63
+ return i;
64
+ }
65
+ return -1;
66
+ }
67
+ function decodeFirstRune(bytes, offset = 0) {
68
+ if (offset >= bytes.length) {
69
+ return [null, 0];
70
+ }
71
+ const firstByte = bytes[offset];
72
+ if (firstByte === void 0) {
73
+ return [null, 0];
74
+ }
75
+ let byteLen;
76
+ if ((firstByte & 128) === 0) {
77
+ byteLen = 1;
78
+ } else if ((firstByte & 224) === 192) {
79
+ byteLen = 2;
80
+ } else if ((firstByte & 240) === 224) {
81
+ byteLen = 3;
82
+ } else if ((firstByte & 248) === 240) {
83
+ byteLen = 4;
84
+ } else {
85
+ byteLen = 1;
86
+ }
87
+ if (offset + byteLen > bytes.length) {
88
+ return [null, 0];
89
+ }
90
+ const slice = bytes.subarray(offset, offset + byteLen);
91
+ const decoded = decoder.decode(slice);
92
+ if (decoded.length === 0) {
93
+ return [null, 0];
94
+ }
95
+ const codePoint = decoded.codePointAt(0);
96
+ if (codePoint === void 0) {
97
+ return [null, 0];
98
+ }
99
+ const firstChar = String.fromCodePoint(codePoint);
100
+ return [firstChar, byteLen];
101
+ }
102
+ function sliceBytes(bytes, start, end) {
103
+ return bytes.subarray(start, end);
104
+ }
105
+ function copyBytes(bytes) {
106
+ return new Uint8Array(bytes);
107
+ }
108
+
109
+ // src/sequences.ts
110
+ var ESC = "\x1B";
111
+ var CSI = `${ESC}[`;
112
+ var OSC = `${ESC}]`;
113
+ var ST = `${ESC}\\`;
114
+ var BEL = "\x07";
115
+ var CURSOR_SHOW = `${CSI}?25h`;
116
+ var CURSOR_HIDE = `${CSI}?25l`;
117
+ var CURSOR_HOME = `${CSI}H`;
118
+ function cursorTo(row, col) {
119
+ return `${CSI}${row};${col}H`;
120
+ }
121
+ function cursorUp(n = 1) {
122
+ return `${CSI}${n}A`;
123
+ }
124
+ function cursorDown(n = 1) {
125
+ return `${CSI}${n}B`;
126
+ }
127
+ function cursorForward(n = 1) {
128
+ return `${CSI}${n}C`;
129
+ }
130
+ function cursorBackward(n = 1) {
131
+ return `${CSI}${n}D`;
132
+ }
133
+ var CURSOR_SAVE = `${CSI}s`;
134
+ var CURSOR_RESTORE = `${CSI}u`;
135
+ var CLEAR_SCREEN = `${CSI}2J`;
136
+ var CLEAR_SCREEN_DOWN = `${CSI}0J`;
137
+ var CLEAR_SCREEN_UP = `${CSI}1J`;
138
+ var CLEAR_LINE = `${CSI}2K`;
139
+ var CLEAR_LINE_END = `${CSI}0K`;
140
+ var CLEAR_LINE_START = `${CSI}1K`;
141
+ var ALT_SCREEN_ON = `${CSI}?1049h`;
142
+ var ALT_SCREEN_OFF = `${CSI}?1049l`;
143
+ var MOUSE_CELL_ON = `${CSI}?1002h`;
144
+ var MOUSE_ALL_ON = `${CSI}?1003h`;
145
+ var MOUSE_SGR_ON = `${CSI}?1006h`;
146
+ var MOUSE_CELL_OFF = `${CSI}?1002l`;
147
+ var MOUSE_ALL_OFF = `${CSI}?1003l`;
148
+ var MOUSE_SGR_OFF = `${CSI}?1006l`;
149
+ var BRACKETED_PASTE_ON = `${CSI}?2004h`;
150
+ var BRACKETED_PASTE_OFF = `${CSI}?2004l`;
151
+ var BRACKETED_PASTE_START = `${CSI}200~`;
152
+ var BRACKETED_PASTE_END = `${CSI}201~`;
153
+ var REPORT_FOCUS_ON = `${CSI}?1004h`;
154
+ var REPORT_FOCUS_OFF = `${CSI}?1004l`;
155
+ var FOCUS_IN = `${CSI}I`;
156
+ var FOCUS_OUT = `${CSI}O`;
157
+ function setWindowTitle(title) {
158
+ return `${OSC}0;${title}${BEL}`;
159
+ }
160
+ var RESET = `${CSI}0m`;
161
+ var BOLD = `${CSI}1m`;
162
+ var DIM = `${CSI}2m`;
163
+ var ITALIC = `${CSI}3m`;
164
+ var UNDERLINE = `${CSI}4m`;
165
+ var BLINK = `${CSI}5m`;
166
+ var REVERSE = `${CSI}7m`;
167
+ var HIDDEN = `${CSI}8m`;
168
+ var STRIKETHROUGH = `${CSI}9m`;
169
+ function fg256(colorIndex) {
170
+ return `${CSI}38;5;${colorIndex}m`;
171
+ }
172
+ function bg256(colorIndex) {
173
+ return `${CSI}48;5;${colorIndex}m`;
174
+ }
175
+ function fgRGB(r, g, b) {
176
+ return `${CSI}38;2;${r};${g};${b}m`;
177
+ }
178
+ function bgRGB(r, g, b) {
179
+ return `${CSI}48;2;${r};${g};${b}m`;
180
+ }
181
+ function scrollUp(n = 1) {
182
+ return `${CSI}${n}S`;
183
+ }
184
+ function scrollDown(n = 1) {
185
+ return `${CSI}${n}T`;
186
+ }
187
+ function setScrollRegion(top, bottom) {
188
+ return `${CSI}${top};${bottom}r`;
189
+ }
190
+ var RESET_SCROLL_REGION = `${CSI}r`;
191
+
192
+ // src/style/index.ts
193
+ var ESC2 = "\x1B[";
194
+ var CODES = {
195
+ // Modifiers (open, close)
196
+ bold: ["1", "22"],
197
+ dim: ["2", "22"],
198
+ italic: ["3", "23"],
199
+ underline: ["4", "24"],
200
+ inverse: ["7", "27"],
201
+ hidden: ["8", "28"],
202
+ strikethrough: ["9", "29"],
203
+ // Basic foreground colors (30-37)
204
+ black: ["30", "39"],
205
+ red: ["31", "39"],
206
+ green: ["32", "39"],
207
+ yellow: ["33", "39"],
208
+ blue: ["34", "39"],
209
+ magenta: ["35", "39"],
210
+ cyan: ["36", "39"],
211
+ white: ["37", "39"],
212
+ // Bright foreground colors (90-97)
213
+ blackBright: ["90", "39"],
214
+ redBright: ["91", "39"],
215
+ greenBright: ["92", "39"],
216
+ yellowBright: ["93", "39"],
217
+ blueBright: ["94", "39"],
218
+ magentaBright: ["95", "39"],
219
+ cyanBright: ["96", "39"],
220
+ whiteBright: ["97", "39"],
221
+ // Basic background colors (40-47)
222
+ bgBlack: ["40", "49"],
223
+ bgRed: ["41", "49"],
224
+ bgGreen: ["42", "49"],
225
+ bgYellow: ["43", "49"],
226
+ bgBlue: ["44", "49"],
227
+ bgMagenta: ["45", "49"],
228
+ bgCyan: ["46", "49"],
229
+ bgWhite: ["47", "49"],
230
+ // Bright background colors (100-107)
231
+ bgBlackBright: ["100", "49"],
232
+ bgRedBright: ["101", "49"],
233
+ bgGreenBright: ["102", "49"],
234
+ bgYellowBright: ["103", "49"],
235
+ bgBlueBright: ["104", "49"],
236
+ bgMagentaBright: ["105", "49"],
237
+ bgCyanBright: ["106", "49"],
238
+ bgWhiteBright: ["107", "49"]
239
+ };
240
+ function applyStyle(text, open, close) {
241
+ const openSeq = `${ESC2}${open}m`;
242
+ const closeSeq = `${ESC2}${close}m`;
243
+ const replaced = text.replace(
244
+ new RegExp(closeSeq.replace(/[[\](){}|^$+*?.\\]/g, "\\$&"), "g"),
245
+ closeSeq + openSeq
246
+ );
247
+ return openSeq + replaced + closeSeq;
248
+ }
249
+ function hexToRgb(hex) {
250
+ const clean = hex.replace(/^#/, "");
251
+ const num = parseInt(clean, 16);
252
+ if (clean.length === 3) {
253
+ const r2 = (num >> 8 & 15) * 17;
254
+ const g2 = (num >> 4 & 15) * 17;
255
+ const b2 = (num & 15) * 17;
256
+ return [r2, g2, b2];
257
+ }
258
+ const r = num >> 16 & 255;
259
+ const g = num >> 8 & 255;
260
+ const b = num & 255;
261
+ return [r, g, b];
262
+ }
263
+ function createStyle(colorSupport) {
264
+ const enabled = colorSupport.level > 0;
265
+ function build(stack) {
266
+ const fn = (text) => {
267
+ if (!enabled || stack.length === 0) {
268
+ return text;
269
+ }
270
+ let result = text;
271
+ for (let i = stack.length - 1; i >= 0; i--) {
272
+ const [open, close] = stack[i];
273
+ result = applyStyle(result, open, close);
274
+ }
275
+ return result;
276
+ };
277
+ const codeNames = Object.keys(CODES);
278
+ for (const name of codeNames) {
279
+ const [open, close] = CODES[name];
280
+ Object.defineProperty(fn, name, {
281
+ get() {
282
+ return build([...stack, [open, close]]);
283
+ }
284
+ });
285
+ }
286
+ Object.defineProperty(fn, "gray", {
287
+ get() {
288
+ const [open, close] = CODES.blackBright;
289
+ return build([...stack, [open, close]]);
290
+ }
291
+ });
292
+ Object.defineProperty(fn, "grey", {
293
+ get() {
294
+ const [open, close] = CODES.blackBright;
295
+ return build([...stack, [open, close]]);
296
+ }
297
+ });
298
+ Object.defineProperty(fn, "hex", {
299
+ value: (color) => {
300
+ if (!enabled || !colorSupport.has16m) {
301
+ return build(stack);
302
+ }
303
+ const [r, g, b] = hexToRgb(color);
304
+ return build([...stack, [`38;2;${r};${g};${b}`, "39"]]);
305
+ },
306
+ writable: true
307
+ });
308
+ Object.defineProperty(fn, "rgb", {
309
+ value: (r, g, b) => {
310
+ if (!enabled || !colorSupport.has16m) {
311
+ return build(stack);
312
+ }
313
+ return build([...stack, [`38;2;${r};${g};${b}`, "39"]]);
314
+ },
315
+ writable: true
316
+ });
317
+ Object.defineProperty(fn, "bgHex", {
318
+ value: (color) => {
319
+ if (!enabled || !colorSupport.has16m) {
320
+ return build(stack);
321
+ }
322
+ const [r, g, b] = hexToRgb(color);
323
+ return build([...stack, [`48;2;${r};${g};${b}`, "49"]]);
324
+ },
325
+ writable: true
326
+ });
327
+ Object.defineProperty(fn, "bgRgb", {
328
+ value: (r, g, b) => {
329
+ if (!enabled || !colorSupport.has16m) {
330
+ return build(stack);
331
+ }
332
+ return build([...stack, [`48;2;${r};${g};${b}`, "49"]]);
333
+ },
334
+ writable: true
335
+ });
336
+ Object.defineProperty(fn, "ansi256", {
337
+ value: (code) => {
338
+ if (!enabled || !colorSupport.has256) {
339
+ return build(stack);
340
+ }
341
+ return build([...stack, [`38;5;${code}`, "39"]]);
342
+ },
343
+ writable: true
344
+ });
345
+ Object.defineProperty(fn, "bgAnsi256", {
346
+ value: (code) => {
347
+ if (!enabled || !colorSupport.has256) {
348
+ return build(stack);
349
+ }
350
+ return build([...stack, [`48;5;${code}`, "49"]]);
351
+ },
352
+ writable: true
353
+ });
354
+ return fn;
355
+ }
356
+ return build([]);
357
+ }
358
+ function createAlwaysEnabledStyle() {
359
+ return createStyle({ level: 3, has256: true, has16m: true });
360
+ }
361
+
362
+ export { ALT_SCREEN_OFF, ALT_SCREEN_ON, BEL, BLINK, BOLD, BRACKETED_PASTE_END, BRACKETED_PASTE_OFF, BRACKETED_PASTE_ON, BRACKETED_PASTE_START, CLEAR_LINE, CLEAR_LINE_END, CLEAR_LINE_START, CLEAR_SCREEN, CLEAR_SCREEN_DOWN, CLEAR_SCREEN_UP, CSI, CURSOR_HIDE, CURSOR_HOME, CURSOR_RESTORE, CURSOR_SAVE, CURSOR_SHOW, DIM, ESC, FOCUS_IN, FOCUS_OUT, HIDDEN, ITALIC, MOUSE_ALL_OFF, MOUSE_ALL_ON, MOUSE_CELL_OFF, MOUSE_CELL_ON, MOUSE_SGR_OFF, MOUSE_SGR_ON, OSC, REPORT_FOCUS_OFF, REPORT_FOCUS_ON, RESET, RESET_SCROLL_REGION, REVERSE, ST, STRIKETHROUGH, UNDERLINE, allocBytes, bg256, bgRGB, byteLength, bytesEqual, concatBytes, copyBytes, createAlwaysEnabledStyle, createStyle, cursorBackward, cursorDown, cursorForward, cursorTo, cursorUp, decodeFirstRune, decodeString, encodeString, fg256, fgRGB, fromBytes, indexOfString, scrollDown, scrollUp, setScrollRegion, setWindowTitle, sliceBytes, startsWith, startsWithString };
363
+ //# sourceMappingURL=index.js.map
364
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bytes.ts","../src/sequences.ts","../src/style/index.ts"],"names":["ESC","r","g","b"],"mappings":";AAMA,IAAM,OAAA,GAAU,IAAI,WAAA,EAAY;AAGhC,IAAM,OAAA,GAAU,IAAI,WAAA,CAAY,OAAO,CAAA;AAShC,SAAS,aAAa,IAAA,EAA0B;AACrD,EAAA,OAAO,OAAA,CAAQ,OAAO,IAAI,CAAA;AAC5B;AASO,SAAS,aAAa,KAAA,EAA2B;AACtD,EAAA,OAAO,OAAA,CAAQ,OAAO,KAAK,CAAA;AAC7B;AASO,SAAS,WAAW,IAAA,EAAsB;AAC/C,EAAA,OAAO,OAAA,CAAQ,MAAA,CAAO,IAAI,CAAA,CAAE,MAAA;AAC9B;AASO,SAAS,eAAe,MAAA,EAAkC;AAC/D,EAAA,MAAM,WAAA,GAAc,OA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,CAAA;AAAA,MACA,QAAA,EAAU;AAAA,KACX,CAAA;AAGD,IAAA,MAAA,CAAO,cAAA,CAAe,IAAI,WAAA,EAAa;AAAA,MACrC,KAAA,EAAO,CAAC,IAAA,KAA0B;AAChC,QAAA,IAAI,CAAC,OAAA,IAAW,CAAC,YAAA,CAAa,MAAA,EAAQ;AACpC,UAAA,OAAO,MAAM,KAAK,CAAA;AAAA,QACpB;AACA,QAAA,OAAO,KAAA,CAAM,CAAC,GAAG,KAAA,EAAO,CAAC,QAAQ,IAAI,CAAA,CAAA,EAAI,IAAI,CAAC,CAAC,CAAA;AAAA,MACjD,CAAA;AAAA,MACA,QAAA,EAAU;AAAA,KACX,CAAA;AAED,IAAA,OAAO,EAAA;AAAA,EACT;AAEA,EAAA,OAAO,KAAA,CAAM,EAAE,CAAA;AACjB;AAOO,SAAS,wBAAA,GAAoC;AAClD,EAAA,OAAO,WAAA,CAAY,EAAE,KAAA,EAAO,CAAA,EAAmB,MAAA,EAAQ,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,CAAA;AAC7E","file":"index.js","sourcesContent":["/**\n * Platform-agnostic byte utilities using Uint8Array.\n * These replace Node.js Buffer operations for cross-platform compatibility.\n */\n\n/** Shared TextEncoder instance for string encoding. */\nconst encoder = new TextEncoder()\n\n/** Shared TextDecoder instance for string decoding. */\nconst decoder = new TextDecoder('utf-8')\n\n/**\n * Encode a string to UTF-8 bytes.\n * Equivalent to `Buffer.from(text, 'utf8')`.\n * @param text - String to encode\n * @returns UTF-8 encoded bytes\n * @public\n */\nexport function encodeString(text: string): Uint8Array {\n return encoder.encode(text)\n}\n\n/**\n * Decode UTF-8 bytes to a string.\n * Equivalent to `buffer.toString('utf8')`.\n * @param bytes - Bytes to decode\n * @returns Decoded string\n * @public\n */\nexport function decodeString(bytes: Uint8Array): string {\n return decoder.decode(bytes)\n}\n\n/**\n * Get the byte length of a string when encoded as UTF-8.\n * Equivalent to `Buffer.byteLength(text, 'utf8')`.\n * @param text - String to measure\n * @returns Byte length\n * @public\n */\nexport function byteLength(text: string): number {\n return encoder.encode(text).length\n}\n\n/**\n * Concatenate multiple Uint8Arrays into one.\n * Equivalent to `Buffer.concat(arrays)`.\n * @param arrays - Arrays to concatenate\n * @returns Combined array\n * @public\n */\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0)\n const result = new Uint8Array(totalLength)\n let offset = 0\n for (const arr of arrays) {\n result.set(arr, offset)\n offset += arr.length\n }\n return result\n}\n\n/**\n * Create a new Uint8Array of the specified size, filled with zeros.\n * Equivalent to `Buffer.alloc(size)`.\n * @param size - Size of the array\n * @returns New zero-filled array\n * @public\n */\nexport function allocBytes(size: number): Uint8Array {\n return new Uint8Array(size)\n}\n\n/**\n * Create a Uint8Array from an array of byte values.\n * Equivalent to `Buffer.from([...])`.\n * @param values - Byte values (0-255)\n * @returns New Uint8Array\n * @public\n */\nexport function fromBytes(values: number[]): Uint8Array {\n return new Uint8Array(values)\n}\n\n/**\n * Compare two Uint8Arrays for equality.\n * Equivalent to `buffer1.equals(buffer2)`.\n * @param a - First array\n * @param b - Second array\n * @returns True if arrays are equal\n * @public\n */\nexport function bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) {\n return false\n }\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) {\n return false\n }\n }\n return true\n}\n\n/**\n * Check if a byte array starts with a specific prefix.\n * @param bytes - Array to check\n * @param prefix - Prefix to look for\n * @returns True if bytes starts with prefix\n * @public\n */\nexport function startsWith(bytes: Uint8Array, prefix: Uint8Array): boolean {\n if (bytes.length < prefix.length) {\n return false\n }\n for (let i = 0; i < prefix.length; i++) {\n if (bytes[i] !== prefix[i]) {\n return false\n }\n }\n return true\n}\n\n/**\n * Check if a byte array starts with a specific string (UTF-8 encoded).\n * @param bytes - Array to check\n * @param prefix - String prefix to look for\n * @returns True if bytes starts with the encoded prefix\n * @public\n */\nexport function startsWithString(bytes: Uint8Array, prefix: string): boolean {\n return startsWith(bytes, encodeString(prefix))\n}\n\n/**\n * Find the index of a substring within a byte array.\n * Returns -1 if not found.\n * @param bytes - Array to search\n * @param needle - String to find\n * @param fromIndex - Start index (default 0)\n * @returns Index of first occurrence or -1\n * @public\n */\nexport function indexOfString(\n bytes: Uint8Array,\n needle: string,\n fromIndex: number = 0,\n): number {\n const needleBytes = encodeString(needle)\n const endIndex = bytes.length - needleBytes.length\n\n outer: for (let i = fromIndex; i <= endIndex; i++) {\n for (let j = 0; j < needleBytes.length; j++) {\n if (bytes[i + j] !== needleBytes[j]) {\n continue outer\n }\n }\n return i\n }\n return -1\n}\n\n/**\n * Decode the first complete UTF-8 character from a byte array.\n * Returns the character and its byte length, or null if incomplete.\n * @param bytes - Byte array to decode\n * @param offset - Start offset (default 0)\n * @returns Tuple of [character, byteLength] or [null, 0] if incomplete\n * @public\n */\nexport function decodeFirstRune(\n bytes: Uint8Array,\n offset: number = 0,\n): [string | null, number] {\n if (offset >= bytes.length) {\n return [null, 0]\n }\n\n const firstByte = bytes[offset]\n if (firstByte === undefined) {\n return [null, 0]\n }\n\n // Determine the byte length of this UTF-8 character\n let byteLen: number\n if ((firstByte & 0x80) === 0) {\n // Single byte character (ASCII)\n byteLen = 1\n } else if ((firstByte & 0xe0) === 0xc0) {\n // Two byte character\n byteLen = 2\n } else if ((firstByte & 0xf0) === 0xe0) {\n // Three byte character\n byteLen = 3\n } else if ((firstByte & 0xf8) === 0xf0) {\n // Four byte character\n byteLen = 4\n } else {\n // Invalid UTF-8 start byte, treat as single byte\n byteLen = 1\n }\n\n // Check if we have enough bytes\n if (offset + byteLen > bytes.length) {\n return [null, 0]\n }\n\n // Decode the character\n const slice = bytes.subarray(offset, offset + byteLen)\n const decoded = decoder.decode(slice)\n\n if (decoded.length === 0) {\n return [null, 0]\n }\n\n // Use codePointAt to properly handle surrogate pairs (emoji, etc.)\n // This returns the full Unicode code point, not just the first surrogate\n const codePoint = decoded.codePointAt(0)\n if (codePoint === undefined) {\n return [null, 0]\n }\n\n // Convert the code point back to a string (handles surrogate pairs correctly)\n const firstChar = String.fromCodePoint(codePoint)\n\n return [firstChar, byteLen]\n}\n\n/**\n * Slice a portion of a byte array.\n * Equivalent to `buffer.subarray(start, end)`.\n * @param bytes - Source array\n * @param start - Start index\n * @param end - End index (optional, defaults to length)\n * @returns New Uint8Array view of the slice\n * @public\n */\nexport function sliceBytes(\n bytes: Uint8Array,\n start: number,\n end?: number,\n): Uint8Array {\n return bytes.subarray(start, end)\n}\n\n/**\n * Create a copy of a byte array.\n * @param bytes - Array to copy\n * @returns New Uint8Array with copied data\n * @public\n */\nexport function copyBytes(bytes: Uint8Array): Uint8Array {\n return new Uint8Array(bytes)\n}\n","/**\n * ANSI escape sequences for terminal control.\n * These are platform-agnostic constants that work in any terminal emulator.\n */\n\n/** Escape character. @public */\nexport const ESC = '\\u001b'\n\n/** Control Sequence Introducer. @public */\nexport const CSI = `${ESC}[`\n\n/** Operating System Command. @public */\nexport const OSC = `${ESC}]`\n\n/** String Terminator. @public */\nexport const ST = `${ESC}\\\\`\n\n/** Bell character (alternative string terminator). @public */\nexport const BEL = '\\u0007'\n\n// ============================================================================\n// Cursor Control\n// ============================================================================\n\n/** Show the cursor. @public */\nexport const CURSOR_SHOW = `${CSI}?25h`\n\n/** Hide the cursor. @public */\nexport const CURSOR_HIDE = `${CSI}?25l`\n\n/** Move cursor to home position (1,1). @public */\nexport const CURSOR_HOME = `${CSI}H`\n\n/**\n * Move cursor to specific position.\n * @param row - Row number (1-based)\n * @param col - Column number (1-based)\n * @returns ANSI escape sequence\n * @public\n */\nexport function cursorTo(row: number, col: number): string {\n return `${CSI}${row};${col}H`\n}\n\n/**\n * Move cursor up by n rows.\n * @param n - Number of rows\n * @returns ANSI escape sequence\n * @public\n */\nexport function cursorUp(n: number = 1): string {\n return `${CSI}${n}A`\n}\n\n/**\n * Move cursor down by n rows.\n * @param n - Number of rows\n * @returns ANSI escape sequence\n * @public\n */\nexport function cursorDown(n: number = 1): string {\n return `${CSI}${n}B`\n}\n\n/**\n * Move cursor forward (right) by n columns.\n * @param n - Number of columns\n * @returns ANSI escape sequence\n * @public\n */\nexport function cursorForward(n: number = 1): string {\n return `${CSI}${n}C`\n}\n\n/**\n * Move cursor backward (left) by n columns.\n * @param n - Number of columns\n * @returns ANSI escape sequence\n * @public\n */\nexport function cursorBackward(n: number = 1): string {\n return `${CSI}${n}D`\n}\n\n/**\n * Save cursor position.\n * @public\n */\nexport const CURSOR_SAVE = `${CSI}s`\n\n/**\n * Restore cursor position.\n * @public\n */\nexport const CURSOR_RESTORE = `${CSI}u`\n\n// ============================================================================\n// Screen Control\n// ============================================================================\n\n/** Clear the entire screen. @public */\nexport const CLEAR_SCREEN = `${CSI}2J`\n\n/** Clear from cursor to end of screen. @public */\nexport const CLEAR_SCREEN_DOWN = `${CSI}0J`\n\n/** Clear from cursor to beginning of screen. @public */\nexport const CLEAR_SCREEN_UP = `${CSI}1J`\n\n/** Clear the entire line. @public */\nexport const CLEAR_LINE = `${CSI}2K`\n\n/** Clear from cursor to end of line. @public */\nexport const CLEAR_LINE_END = `${CSI}0K`\n\n/** Clear from cursor to beginning of line. @public */\nexport const CLEAR_LINE_START = `${CSI}1K`\n\n// ============================================================================\n// Alternate Screen Buffer\n// ============================================================================\n\n/** Enter alternate screen buffer. @public */\nexport const ALT_SCREEN_ON = `${CSI}?1049h`\n\n/** Exit alternate screen buffer. @public */\nexport const ALT_SCREEN_OFF = `${CSI}?1049l`\n\n// ============================================================================\n// Mouse Tracking\n// ============================================================================\n\n/** Enable cell-motion mouse tracking (button events + motion while pressed). @public */\nexport const MOUSE_CELL_ON = `${CSI}?1002h`\n\n/** Enable all-motion mouse tracking (button events + all motion). @public */\nexport const MOUSE_ALL_ON = `${CSI}?1003h`\n\n/** Enable SGR extended mouse mode (supports coordinates \\> 223). @public */\nexport const MOUSE_SGR_ON = `${CSI}?1006h`\n\n/** Disable cell-motion mouse tracking. @public */\nexport const MOUSE_CELL_OFF = `${CSI}?1002l`\n\n/** Disable all-motion mouse tracking. @public */\nexport const MOUSE_ALL_OFF = `${CSI}?1003l`\n\n/** Disable SGR extended mouse mode. @public */\nexport const MOUSE_SGR_OFF = `${CSI}?1006l`\n\n// ============================================================================\n// Bracketed Paste\n// ============================================================================\n\n/** Enable bracketed paste mode. @public */\nexport const BRACKETED_PASTE_ON = `${CSI}?2004h`\n\n/** Disable bracketed paste mode. @public */\nexport const BRACKETED_PASTE_OFF = `${CSI}?2004l`\n\n/** Bracketed paste start sequence. @public */\nexport const BRACKETED_PASTE_START = `${CSI}200~`\n\n/** Bracketed paste end sequence. @public */\nexport const BRACKETED_PASTE_END = `${CSI}201~`\n\n// ============================================================================\n// Focus Reporting\n// ============================================================================\n\n/** Enable focus reporting. @public */\nexport const REPORT_FOCUS_ON = `${CSI}?1004h`\n\n/** Disable focus reporting. @public */\nexport const REPORT_FOCUS_OFF = `${CSI}?1004l`\n\n/** Focus gained sequence. @public */\nexport const FOCUS_IN = `${CSI}I`\n\n/** Focus lost sequence. @public */\nexport const FOCUS_OUT = `${CSI}O`\n\n// ============================================================================\n// Window Control\n// ============================================================================\n\n/**\n * Set the terminal window title.\n * @param title - Window title\n * @returns ANSI escape sequence\n * @public\n */\nexport function setWindowTitle(title: string): string {\n return `${OSC}0;${title}${BEL}`\n}\n\n// ============================================================================\n// Text Formatting (SGR - Select Graphic Rendition)\n// ============================================================================\n\n/** Reset all text attributes. @public */\nexport const RESET = `${CSI}0m`\n\n/** Bold text. @public */\nexport const BOLD = `${CSI}1m`\n\n/** Dim/faint text. @public */\nexport const DIM = `${CSI}2m`\n\n/** Italic text. @public */\nexport const ITALIC = `${CSI}3m`\n\n/** Underlined text. @public */\nexport const UNDERLINE = `${CSI}4m`\n\n/** Blinking text. @public */\nexport const BLINK = `${CSI}5m`\n\n/** Reverse video (swap foreground/background). @public */\nexport const REVERSE = `${CSI}7m`\n\n/** Hidden text. @public */\nexport const HIDDEN = `${CSI}8m`\n\n/** Strikethrough text. @public */\nexport const STRIKETHROUGH = `${CSI}9m`\n\n// ============================================================================\n// Color Utilities\n// ============================================================================\n\n/**\n * Set foreground color using 256-color palette.\n * @param colorIndex - Color index (0-255)\n * @returns ANSI escape sequence\n * @public\n */\nexport function fg256(colorIndex: number): string {\n return `${CSI}38;5;${colorIndex}m`\n}\n\n/**\n * Set background color using 256-color palette.\n * @param colorIndex - Color index (0-255)\n * @returns ANSI escape sequence\n * @public\n */\nexport function bg256(colorIndex: number): string {\n return `${CSI}48;5;${colorIndex}m`\n}\n\n/**\n * Set foreground color using RGB true color.\n * @param r - Red component (0-255)\n * @param g - Green component (0-255)\n * @param b - Blue component (0-255)\n * @returns ANSI escape sequence\n * @public\n */\nexport function fgRGB(r: number, g: number, b: number): string {\n return `${CSI}38;2;${r};${g};${b}m`\n}\n\n/**\n * Set background color using RGB true color.\n * @param r - Red component (0-255)\n * @param g - Green component (0-255)\n * @param b - Blue component (0-255)\n * @returns ANSI escape sequence\n * @public\n */\nexport function bgRGB(r: number, g: number, b: number): string {\n return `${CSI}48;2;${r};${g};${b}m`\n}\n\n// ============================================================================\n// Scrolling\n// ============================================================================\n\n/**\n * Scroll up by n lines.\n * @param n - Number of lines\n * @returns ANSI escape sequence\n * @public\n */\nexport function scrollUp(n: number = 1): string {\n return `${CSI}${n}S`\n}\n\n/**\n * Scroll down by n lines.\n * @param n - Number of lines\n * @returns ANSI escape sequence\n * @public\n */\nexport function scrollDown(n: number = 1): string {\n return `${CSI}${n}T`\n}\n\n/**\n * Set scrolling region.\n * @param top - Top row (1-based)\n * @param bottom - Bottom row (1-based)\n * @returns ANSI escape sequence\n * @public\n */\nexport function setScrollRegion(top: number, bottom: number): string {\n return `${CSI}${top};${bottom}r`\n}\n\n/** Reset scrolling region to full screen. @public */\nexport const RESET_SCROLL_REGION = `${CSI}r`\n","/**\n * Pure JavaScript ANSI styling utility for terminal text.\n * Works identically in Node.js and browser/xterm.js contexts.\n */\n\nimport type { ColorSupport, StyleFn } from '../types.js'\n\n// ANSI escape codes\nconst ESC = '\\x1b['\nconst RESET = `${ESC}0m`\n\n// Modifier codes\nconst CODES = {\n // Modifiers (open, close)\n bold: ['1', '22'],\n dim: ['2', '22'],\n italic: ['3', '23'],\n underline: ['4', '24'],\n inverse: ['7', '27'],\n hidden: ['8', '28'],\n strikethrough: ['9', '29'],\n\n // Basic foreground colors (30-37)\n black: ['30', '39'],\n red: ['31', '39'],\n green: ['32', '39'],\n yellow: ['33', '39'],\n blue: ['34', '39'],\n magenta: ['35', '39'],\n cyan: ['36', '39'],\n white: ['37', '39'],\n\n // Bright foreground colors (90-97)\n blackBright: ['90', '39'],\n redBright: ['91', '39'],\n greenBright: ['92', '39'],\n yellowBright: ['93', '39'],\n blueBright: ['94', '39'],\n magentaBright: ['95', '39'],\n cyanBright: ['96', '39'],\n whiteBright: ['97', '39'],\n\n // Basic background colors (40-47)\n bgBlack: ['40', '49'],\n bgRed: ['41', '49'],\n bgGreen: ['42', '49'],\n bgYellow: ['43', '49'],\n bgBlue: ['44', '49'],\n bgMagenta: ['45', '49'],\n bgCyan: ['46', '49'],\n bgWhite: ['47', '49'],\n\n // Bright background colors (100-107)\n bgBlackBright: ['100', '49'],\n bgRedBright: ['101', '49'],\n bgGreenBright: ['102', '49'],\n bgYellowBright: ['103', '49'],\n bgBlueBright: ['104', '49'],\n bgMagentaBright: ['105', '49'],\n bgCyanBright: ['106', '49'],\n bgWhiteBright: ['107', '49'],\n} as const\n\ntype CodeName = keyof typeof CODES\n\n/**\n * Apply ANSI codes to text.\n * @param text - Text to style\n * @param open - Opening ANSI code\n * @param close - Closing ANSI code\n * @returns Styled text\n */\nfunction applyStyle(text: string, open: string, close: string): string {\n const openSeq = `${ESC}${open}m`\n const closeSeq = `${ESC}${close}m`\n\n // Replace any existing close codes with close+open to properly nest styles\n // This handles cases like style.bold(style.bold('text')) where the inner\n // bold close would prematurely end the outer bold\n const replaced = text.replace(\n new RegExp(closeSeq.replace(/[[\\](){}|^$+*?.\\\\]/g, '\\\\$&'), 'g'),\n closeSeq + openSeq,\n )\n\n return openSeq + replaced + closeSeq\n}\n\n/**\n * Convert hex color to RGB.\n * @param hex - Hex color string (with or without #)\n * @returns RGB array [r, g, b]\n */\nfunction hexToRgb(hex: string): [number, number, number] {\n const clean = hex.replace(/^#/, '')\n const num = parseInt(clean, 16)\n\n if (clean.length === 3) {\n // Short form: #RGB -> #RRGGBB\n const r = ((num >> 8) & 0xf) * 17\n const g = ((num >> 4) & 0xf) * 17\n const b = (num & 0xf) * 17\n return [r, g, b]\n }\n\n // Long form: #RRGGBB\n const r = (num >> 16) & 0xff\n const g = (num >> 8) & 0xff\n const b = num & 0xff\n return [r, g, b]\n}\n\n/**\n * Create a chainable style function.\n * @param colorSupport - Color support level information\n * @returns Chainable style function\n * @public\n */\nexport function createStyle(colorSupport: ColorSupport): StyleFn {\n const enabled = colorSupport.level > 0\n\n /**\n * Build a style function that can be chained.\n * @param stack - Array of [open, close] code pairs to apply\n * @returns Style function\n */\n function build(stack: Array<[string, string]>): StyleFn {\n // The function itself - applies all stacked styles\n const fn = (text: string): string => {\n if (!enabled || stack.length === 0) {\n return text\n }\n\n // Apply styles from inside out\n let result = text\n for (let i = stack.length - 1; i >= 0; i--) {\n const [open, close] = stack[i]!\n result = applyStyle(result, open, close)\n }\n return result\n }\n\n // Add all code-based style properties\n const codeNames = Object.keys(CODES) as CodeName[]\n for (const name of codeNames) {\n const [open, close] = CODES[name]\n Object.defineProperty(fn, name, {\n get() {\n return build([...stack, [open, close]])\n },\n })\n }\n\n // Add gray as alias for blackBright\n Object.defineProperty(fn, 'gray', {\n get() {\n const [open, close] = CODES.blackBright\n return build([...stack, [open, close]])\n },\n })\n\n // Add grey as alias for blackBright\n Object.defineProperty(fn, 'grey', {\n get() {\n const [open, close] = CODES.blackBright\n return build([...stack, [open, close]])\n },\n })\n\n // Add extended color methods\n\n // hex(color: string): StyleFn\n Object.defineProperty(fn, 'hex', {\n value: (color: string): StyleFn => {\n if (!enabled || !colorSupport.has16m) {\n return build(stack)\n }\n const [r, g, b] = hexToRgb(color)\n return build([...stack, [`38;2;${r};${g};${b}`, '39']])\n },\n writable: true,\n })\n\n // rgb(r: number, g: number, b: number): StyleFn\n Object.defineProperty(fn, 'rgb', {\n value: (r: number, g: number, b: number): StyleFn => {\n if (!enabled || !colorSupport.has16m) {\n return build(stack)\n }\n return build([...stack, [`38;2;${r};${g};${b}`, '39']])\n },\n writable: true,\n })\n\n // bgHex(color: string): StyleFn\n Object.defineProperty(fn, 'bgHex', {\n value: (color: string): StyleFn => {\n if (!enabled || !colorSupport.has16m) {\n return build(stack)\n }\n const [r, g, b] = hexToRgb(color)\n return build([...stack, [`48;2;${r};${g};${b}`, '49']])\n },\n writable: true,\n })\n\n // bgRgb(r: number, g: number, b: number): StyleFn\n Object.defineProperty(fn, 'bgRgb', {\n value: (r: number, g: number, b: number): StyleFn => {\n if (!enabled || !colorSupport.has16m) {\n return build(stack)\n }\n return build([...stack, [`48;2;${r};${g};${b}`, '49']])\n },\n writable: true,\n })\n\n // ansi256(code: number): StyleFn\n Object.defineProperty(fn, 'ansi256', {\n value: (code: number): StyleFn => {\n if (!enabled || !colorSupport.has256) {\n return build(stack)\n }\n return build([...stack, [`38;5;${code}`, '39']])\n },\n writable: true,\n })\n\n // bgAnsi256(code: number): StyleFn\n Object.defineProperty(fn, 'bgAnsi256', {\n value: (code: number): StyleFn => {\n if (!enabled || !colorSupport.has256) {\n return build(stack)\n }\n return build([...stack, [`48;5;${code}`, '49']])\n },\n writable: true,\n })\n\n return fn as StyleFn\n }\n\n return build([])\n}\n\n/**\n * Create a style function that always applies colors (for xterm.js).\n * @returns Chainable style function with full color support\n * @public\n */\nexport function createAlwaysEnabledStyle(): StyleFn {\n return createStyle({ level: 3, hasBasic: true, has256: true, has16m: true })\n}\n"]}