@ac-kit/format-ansi 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +43 -0
  3. package/dist/_ansi-16-palette.d.ts +10 -0
  4. package/dist/_ansi-16-palette.d.ts.map +1 -0
  5. package/dist/_ansi-16-palette.js +38 -0
  6. package/dist/_ansi-16-palette.js.map +1 -0
  7. package/dist/_ansi-256-palette.d.ts +13 -0
  8. package/dist/_ansi-256-palette.d.ts.map +1 -0
  9. package/dist/_ansi-256-palette.js +45 -0
  10. package/dist/_ansi-256-palette.js.map +1 -0
  11. package/dist/ansi-decoder.d.ts +27 -0
  12. package/dist/ansi-decoder.d.ts.map +1 -0
  13. package/dist/ansi-decoder.js +151 -0
  14. package/dist/ansi-decoder.js.map +1 -0
  15. package/dist/ansi-encoder.d.ts +13 -0
  16. package/dist/ansi-encoder.d.ts.map +1 -0
  17. package/dist/ansi-encoder.js +24 -0
  18. package/dist/ansi-encoder.js.map +1 -0
  19. package/dist/ansi-stream.d.ts +22 -0
  20. package/dist/ansi-stream.d.ts.map +1 -0
  21. package/dist/ansi-stream.js +22 -0
  22. package/dist/ansi-stream.js.map +1 -0
  23. package/dist/ansi-token.d.ts +26 -0
  24. package/dist/ansi-token.d.ts.map +1 -0
  25. package/dist/ansi-token.js +4 -0
  26. package/dist/ansi-token.js.map +1 -0
  27. package/dist/color.d.ts +29 -0
  28. package/dist/color.d.ts.map +1 -0
  29. package/dist/color.js +51 -0
  30. package/dist/color.js.map +1 -0
  31. package/dist/cursor.d.ts +19 -0
  32. package/dist/cursor.d.ts.map +1 -0
  33. package/dist/cursor.js +24 -0
  34. package/dist/cursor.js.map +1 -0
  35. package/dist/hyperlink.d.ts +3 -0
  36. package/dist/hyperlink.d.ts.map +1 -0
  37. package/dist/hyperlink.js +6 -0
  38. package/dist/hyperlink.js.map +1 -0
  39. package/dist/index.d.ts +9 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +9 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/strip-ansi-escapes.d.ts +10 -0
  44. package/dist/strip-ansi-escapes.d.ts.map +1 -0
  45. package/dist/strip-ansi-escapes.js +24 -0
  46. package/dist/strip-ansi-escapes.js.map +1 -0
  47. package/package.json +66 -0
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024-2026 Anthony Champagne and contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @ac-kit/format-ansi
2
+
3
+ The escape sequences a terminal understands: colour, styling, cursor movement,
4
+ alternate screen, and OSC 8 hyperlinks — plus the decoder that strips them back
5
+ out again.
6
+
7
+ The hard part is not emitting `\x1b[31m`; it is emitting something the target
8
+ terminal can actually show. Ask for a truecolor value on a 16-colour terminal
9
+ and you get either garbage or nothing, so this downsamples: truecolor → 256 → 16
10
+ → monochrome, according to a `colorDepth` you supply.
11
+
12
+ ```typescript
13
+ import { hyperlink, stripAnsiEscapes, styleText } from "@ac-kit/format-ansi";
14
+
15
+ const warning = styleText("disk almost full", {
16
+ styles: ["bold"],
17
+ foreground: { r8: 255, g8: 170, b8: 0 },
18
+ colorDepth: 4, // downsampled to the nearest of the 16 basic colours
19
+ });
20
+
21
+ const link = hyperlink("https://example.com", "docs");
22
+
23
+ stripAnsiEscapes(warning).length; // the visible length, for column maths
24
+ ```
25
+
26
+ ## What it exposes
27
+
28
+ - `styleText` — SGR styles plus foreground/background colour, downsampled to
29
+ `colorDepth`.
30
+ - `nearestAnsi16`, `nearestAnsi256` — the downsampling on its own.
31
+ - `stripAnsiEscapes` — remove every sequence, leaving the visible text.
32
+ - `cursorUp`, `cursorDown`, `ERASE_LINE`, `CLEAR_SCREEN`, `HIDE_CURSOR`,
33
+ `SHOW_CURSOR`, `ENTER_ALT_SCREEN`, `EXIT_ALT_SCREEN`.
34
+ - `hyperlink` — OSC 8 clickable links.
35
+ - `createAnsiEncoder`, the ANSI decoder and `AnsiToken` — for parsing a stream
36
+ of sequences rather than producing one.
37
+
38
+ Portable: no Node.js built-ins. `@ac-kit/app-terminal`'s `styleTextFor` wraps
39
+ `styleText` to read `colorDepth` off a `Terminal` for you.
40
+
41
+ See the
42
+ [generated API docs](https://anthochamp.github.io/node-essentials/api/format-ansi/)
43
+ for the full reference.
@@ -0,0 +1,10 @@
1
+ import type { Rgb8 } from "@ac-kit/math-color";
2
+ /**
3
+ * The nearest basic/bright ANSI color index (0-15) for `color`, by OKLab
4
+ * (perceptual) distance.
5
+ *
6
+ * The palette is converted on first use, so importing this module costs nothing
7
+ * for a caller that never downsamples.
8
+ */
9
+ export declare function nearestAnsi16(color: Rgb8): number;
10
+ //# sourceMappingURL=_ansi-16-palette.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_ansi-16-palette.d.ts","sourceRoot":"","sources":["../src/_ansi-16-palette.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAmCnE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAKjD"}
@@ -0,0 +1,38 @@
1
+ import { createNearestColorFinder, RGB8_BLACK, RGB8_WHITE, rgb8ToOklab, } from "@ac-kit/math-color";
2
+ // The standard xterm default RGB approximations for the 16 basic/bright ANSI
3
+ // colors — indices 0-7 are black/red/green/yellow/blue/magenta/cyan/white,
4
+ // 8-15 are their bright counterparts, in that fixed SGR order. Hand-written,
5
+ // not generated: there is no official/versioned source for these, only
6
+ // long-standing terminal convention (same situation as this repo's
7
+ // `CSS_NAMED_COLORS`).
8
+ const ANSI_16_PALETTE = [
9
+ RGB8_BLACK,
10
+ { r8: 205, g8: 0, b8: 0 },
11
+ { r8: 0, g8: 205, b8: 0 },
12
+ { r8: 205, g8: 205, b8: 0 },
13
+ { r8: 0, g8: 0, b8: 238 },
14
+ { r8: 205, g8: 0, b8: 205 },
15
+ { r8: 0, g8: 205, b8: 205 },
16
+ { r8: 229, g8: 229, b8: 229 },
17
+ { r8: 127, g8: 127, b8: 127 },
18
+ { r8: 255, g8: 0, b8: 0 },
19
+ { r8: 0, g8: 255, b8: 0 },
20
+ { r8: 255, g8: 255, b8: 0 },
21
+ { r8: 92, g8: 92, b8: 255 },
22
+ { r8: 255, g8: 0, b8: 255 },
23
+ { r8: 0, g8: 255, b8: 255 },
24
+ RGB8_WHITE,
25
+ ];
26
+ let finder = null;
27
+ /**
28
+ * The nearest basic/bright ANSI color index (0-15) for `color`, by OKLab
29
+ * (perceptual) distance.
30
+ *
31
+ * The palette is converted on first use, so importing this module costs nothing
32
+ * for a caller that never downsamples.
33
+ */
34
+ export function nearestAnsi16(color) {
35
+ finder ??= createNearestColorFinder(ANSI_16_PALETTE.keys(), (index) => rgb8ToOklab(ANSI_16_PALETTE[index]));
36
+ return finder(rgb8ToOklab(color));
37
+ }
38
+ //# sourceMappingURL=_ansi-16-palette.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_ansi-16-palette.js","sourceRoot":"","sources":["../src/_ansi-16-palette.ts"],"names":[],"mappings":"AACA,OAAO,EACN,wBAAwB,EACxB,UAAU,EACV,UAAU,EACV,WAAW,GACX,MAAM,oBAAoB,CAAC;AAE5B,6EAA6E;AAC7E,2EAA2E;AAC3E,6EAA6E;AAC7E,uEAAuE;AACvE,mEAAmE;AACnE,uBAAuB;AACvB,MAAM,eAAe,GAAoB;IACxC,UAAU;IACV,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE;IACzB,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE;IACzB,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE;IAC3B,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE;IACzB,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE;IAC3B,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE;IAC3B,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE;IAC7B,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE;IAC7B,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE;IACzB,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE;IACzB,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE;IAC3B,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE;IAC3B,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE;IAC3B,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE;IAC3B,UAAU;CACV,CAAC;AAEF,IAAI,MAAM,GAAsC,IAAI,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,KAAW;IACxC,MAAM,KAAK,wBAAwB,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CACrE,WAAW,CAAC,eAAe,CAAC,KAAK,CAAE,CAAC,CACpC,CAAC;IACF,OAAO,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Rgb8 } from "@ac-kit/math-color";
2
+ /**
3
+ * The nearest xterm 256-color palette index (16-255: the 6×6×6 color cube or
4
+ * the 24-step grayscale ramp) for `color`, by OKLab (perceptual) distance.
5
+ *
6
+ * Indices 0-15 (basic/bright) are covered separately by `nearestAnsi16`, for
7
+ * the depth that can only render that smaller palette.
8
+ *
9
+ * The 240-entry palette is built and converted on first use — importing this
10
+ * module costs nothing for a caller that never downsamples.
11
+ */
12
+ export declare function nearestAnsi256(color: Rgb8): number;
13
+ //# sourceMappingURL=_ansi-256-palette.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_ansi-256-palette.d.ts","sourceRoot":"","sources":["../src/_ansi-256-palette.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAwCnE;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAKlD"}
@@ -0,0 +1,45 @@
1
+ import { createNearestColorFinder, rgb8ToOklab } from "@ac-kit/math-color";
2
+ const CUBE_LEVELS_ = [0, 95, 135, 175, 215, 255];
3
+ function buildExtendedPalette() {
4
+ const entries = [];
5
+ // 6x6x6 color cube, indices 16-231.
6
+ for (let r = 0; r < 6; r++) {
7
+ for (let g = 0; g < 6; g++) {
8
+ for (let b = 0; b < 6; b++) {
9
+ entries.push({
10
+ index: 16 + 36 * r + 6 * g + b,
11
+ color: {
12
+ r8: CUBE_LEVELS_[r],
13
+ g8: CUBE_LEVELS_[g],
14
+ b8: CUBE_LEVELS_[b],
15
+ },
16
+ });
17
+ }
18
+ }
19
+ }
20
+ // 24-step grayscale ramp, indices 232-255.
21
+ for (let step = 0; step < 24; step++) {
22
+ const level = 8 + 10 * step;
23
+ entries.push({
24
+ index: 232 + step,
25
+ color: { r8: level, g8: level, b8: level },
26
+ });
27
+ }
28
+ return entries;
29
+ }
30
+ let finder = null;
31
+ /**
32
+ * The nearest xterm 256-color palette index (16-255: the 6×6×6 color cube or
33
+ * the 24-step grayscale ramp) for `color`, by OKLab (perceptual) distance.
34
+ *
35
+ * Indices 0-15 (basic/bright) are covered separately by `nearestAnsi16`, for
36
+ * the depth that can only render that smaller palette.
37
+ *
38
+ * The 240-entry palette is built and converted on first use — importing this
39
+ * module costs nothing for a caller that never downsamples.
40
+ */
41
+ export function nearestAnsi256(color) {
42
+ finder ??= createNearestColorFinder(buildExtendedPalette(), (entry) => rgb8ToOklab(entry.color));
43
+ return finder(rgb8ToOklab(color)).index;
44
+ }
45
+ //# sourceMappingURL=_ansi-256-palette.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_ansi-256-palette.js","sourceRoot":"","sources":["../src/_ansi-256-palette.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE3E,MAAM,YAAY,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAIjD,SAAS,oBAAoB;IAC5B,MAAM,OAAO,GAAoB,EAAE,CAAC;IAEpC,oCAAoC;IACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC;oBACZ,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;oBAC9B,KAAK,EAAE;wBACN,EAAE,EAAE,YAAY,CAAC,CAAC,CAAE;wBACpB,EAAE,EAAE,YAAY,CAAC,CAAC,CAAE;wBACpB,EAAE,EAAE,YAAY,CAAC,CAAC,CAAE;qBACpB;iBACD,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;IACF,CAAC;IAED,2CAA2C;IAC3C,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;QAC5B,OAAO,CAAC,IAAI,CAAC;YACZ,KAAK,EAAE,GAAG,GAAG,IAAI;YACjB,KAAK,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE;SAC1C,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,IAAI,MAAM,GAA6C,IAAI,CAAC;AAE5D;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,KAAW;IACzC,MAAM,KAAK,wBAAwB,CAAC,oBAAoB,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CACrE,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CACxB,CAAC;IACF,OAAO,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AACzC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { DecodeContext, Decoder, DecodeResult } from "@ac-kit/format-core";
2
+ import { AnsiToken } from "./ansi-token.js";
3
+ /**
4
+ * Decodes an ANSI/VT100 character stream into text runs and escape sequences.
5
+ *
6
+ * The single implementation of the ANSI read grammar: `stripAnsiEscapes` and
7
+ * `AnsiParseStream` are both driven by this rather than repeating it.
8
+ *
9
+ * Covers CSI (`ESC [` and the 8-bit `\u009B`) and OSC (`ESC ]`, terminated by
10
+ * BEL or ST) — what this package's own builders emit. An escape sequence still
11
+ * arriving is reported as `incomplete`, so a sequence split across chunks is
12
+ * reassembled rather than mistaken for text; an unterminated one at end of
13
+ * input is emitted as text, which is the only lossless option left.
14
+ *
15
+ * Written against `string` rather than `Uint8Array` because a text run must not
16
+ * be split mid-character; byte-to-text conversion is the buffer's job
17
+ * (`TextDecodeBuffer`).
18
+ */
19
+ export declare class AnsiDecoder implements Decoder<AnsiToken, string> {
20
+ decode(view: string, context: DecodeContext): DecodeResult<AnsiToken>;
21
+ private decodeCsi;
22
+ private decodeOsc;
23
+ /** Index of the next escape introducer at or after `from`, else the end. */
24
+ private nextIntroducer;
25
+ private pendingOrText;
26
+ }
27
+ //# sourceMappingURL=ansi-decoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ansi-decoder.d.ts","sourceRoot":"","sources":["../src/ansi-decoder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEhF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAoB5C;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,WAAY,YAAW,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC;IAC7D,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,YAAY,CAAC,SAAS,CAAC,CA4BpE;IAED,OAAO,CAAC,SAAS;IAsCjB,OAAO,CAAC,SAAS;IA6CjB,4EAA4E;IAC5E,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,aAAa;CAarB"}
@@ -0,0 +1,151 @@
1
+ import { BEL_CHAR, ESC_CHAR } from "@ac-kit/core";
2
+ /** 8-bit CSI introducer, equivalent to the two-character `ESC [`. */
3
+ const CSI_8BIT_ = "\u009B";
4
+ function isParameterByte(char) {
5
+ const code = char.charCodeAt(0);
6
+ return code >= 0x30 && code <= 0x3f;
7
+ }
8
+ function isIntermediateByte(char) {
9
+ const code = char.charCodeAt(0);
10
+ return code >= 0x20 && code <= 0x2f;
11
+ }
12
+ function isFinalByte(char) {
13
+ const code = char.charCodeAt(0);
14
+ return code >= 0x40 && code <= 0x7e;
15
+ }
16
+ /**
17
+ * Decodes an ANSI/VT100 character stream into text runs and escape sequences.
18
+ *
19
+ * The single implementation of the ANSI read grammar: `stripAnsiEscapes` and
20
+ * `AnsiParseStream` are both driven by this rather than repeating it.
21
+ *
22
+ * Covers CSI (`ESC [` and the 8-bit `\u009B`) and OSC (`ESC ]`, terminated by
23
+ * BEL or ST) — what this package's own builders emit. An escape sequence still
24
+ * arriving is reported as `incomplete`, so a sequence split across chunks is
25
+ * reassembled rather than mistaken for text; an unterminated one at end of
26
+ * input is emitted as text, which is the only lossless option left.
27
+ *
28
+ * Written against `string` rather than `Uint8Array` because a text run must not
29
+ * be split mid-character; byte-to-text conversion is the buffer's job
30
+ * (`TextDecodeBuffer`).
31
+ */
32
+ export class AnsiDecoder {
33
+ decode(view, context) {
34
+ const first = view[0];
35
+ if (first === ESC_CHAR || first === CSI_8BIT_) {
36
+ const introducerLength = first === CSI_8BIT_ ? 1 : 2;
37
+ const second = first === CSI_8BIT_ ? "[" : view[1];
38
+ if (second === undefined) {
39
+ return this.pendingOrText(view, context);
40
+ }
41
+ if (second === "[") {
42
+ return this.decodeCsi(view, introducerLength, context);
43
+ }
44
+ if (second === "]") {
45
+ return this.decodeOsc(view, context);
46
+ }
47
+ // Not a sequence this package emits: hand the introducer back as text
48
+ // so the stream stays lossless rather than swallowing it.
49
+ return {
50
+ status: "decoded",
51
+ value: { kind: "text", text: first },
52
+ consumed: 1,
53
+ };
54
+ }
55
+ const next = this.nextIntroducer(view, 1);
56
+ const text = view.slice(0, next);
57
+ return { status: "decoded", value: { kind: "text", text }, consumed: next };
58
+ }
59
+ decodeCsi(view, start, context) {
60
+ let index = start;
61
+ while (index < view.length && isParameterByte(view[index])) {
62
+ index += 1;
63
+ }
64
+ const parameters = view.slice(start, index);
65
+ const intermediateStart = index;
66
+ while (index < view.length && isIntermediateByte(view[index])) {
67
+ index += 1;
68
+ }
69
+ const intermediates = view.slice(intermediateStart, index);
70
+ if (index >= view.length) {
71
+ return this.pendingOrText(view, context);
72
+ }
73
+ const final = view[index];
74
+ if (!isFinalByte(final)) {
75
+ // A byte outside every CSI class: the sequence is malformed, so the
76
+ // introducer becomes text and scanning resumes after it.
77
+ return {
78
+ status: "decoded",
79
+ value: { kind: "text", text: view.slice(0, start) },
80
+ consumed: start,
81
+ };
82
+ }
83
+ return {
84
+ status: "decoded",
85
+ value: { kind: "csi", parameters, intermediates, final },
86
+ consumed: index + 1,
87
+ };
88
+ }
89
+ decodeOsc(view, context) {
90
+ const bodyStart = 2;
91
+ for (let index = bodyStart; index < view.length; index++) {
92
+ const char = view[index];
93
+ if (char === BEL_CHAR) {
94
+ return {
95
+ status: "decoded",
96
+ value: {
97
+ kind: "osc",
98
+ body: view.slice(bodyStart, index),
99
+ terminator: "bel",
100
+ },
101
+ consumed: index + 1,
102
+ };
103
+ }
104
+ if (char === ESC_CHAR) {
105
+ if (index + 1 >= view.length) {
106
+ return this.pendingOrText(view, context);
107
+ }
108
+ if (view[index + 1] === "\\") {
109
+ return {
110
+ status: "decoded",
111
+ value: {
112
+ kind: "osc",
113
+ body: view.slice(bodyStart, index),
114
+ terminator: "st",
115
+ },
116
+ consumed: index + 2,
117
+ };
118
+ }
119
+ // A bare ESC inside the body ends nothing; treat the introducer as
120
+ // text and rescan from there.
121
+ return {
122
+ status: "decoded",
123
+ value: { kind: "text", text: view.slice(0, bodyStart) },
124
+ consumed: bodyStart,
125
+ };
126
+ }
127
+ }
128
+ return this.pendingOrText(view, context);
129
+ }
130
+ /** Index of the next escape introducer at or after `from`, else the end. */
131
+ nextIntroducer(view, from) {
132
+ for (let index = from; index < view.length; index++) {
133
+ const char = view[index];
134
+ if (char === ESC_CHAR || char === CSI_8BIT_) {
135
+ return index;
136
+ }
137
+ }
138
+ return view.length;
139
+ }
140
+ pendingOrText(view, context) {
141
+ if (context.atEof) {
142
+ return {
143
+ status: "decoded",
144
+ value: { kind: "text", text: view },
145
+ consumed: view.length,
146
+ };
147
+ }
148
+ return { status: "incomplete" };
149
+ }
150
+ }
151
+ //# sourceMappingURL=ansi-decoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ansi-decoder.js","sourceRoot":"","sources":["../src/ansi-decoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAKlD,qEAAqE;AACrE,M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,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE;gBACnC,QAAQ,EAAE,IAAI,CAAC,MAAM;aACrB,CAAC;QACH,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IACjC,CAAC;CACD"}
@@ -0,0 +1,13 @@
1
+ import type { Encoder } from "@ac-kit/format-core";
2
+ import { AnsiToken } from "./ansi-token.js";
3
+ /**
4
+ * Renders one token back to its character form.
5
+ *
6
+ * The single implementation of the ANSI write grammar; this package's named
7
+ * builders (`cursorUp`, `hyperlink`, `styleText`, …) are conveniences that
8
+ * produce the same sequences for the cases callers reach for by name.
9
+ */
10
+ export declare function printAnsiToken(token: AnsiToken): string;
11
+ /** Creates the ANSI write half: tokens in, escape-sequence text out. */
12
+ export declare function createAnsiEncoder(): Encoder<AnsiToken, string>;
13
+ //# sourceMappingURL=ansi-encoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ansi-encoder.d.ts","sourceRoot":"","sources":["../src/ansi-encoder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAM,MAAM,iBAAiB,CAAC;AAEhD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAWvD;AAED,wEAAwE;AACxE,wBAAgB,iBAAiB,IAAI,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAE9D"}
@@ -0,0 +1,24 @@
1
+ import { BEL_CHAR, ESC_CHAR } from "@ac-kit/core";
2
+ import { ST } from "./ansi-token.js";
3
+ /**
4
+ * Renders one token back to its character form.
5
+ *
6
+ * The single implementation of the ANSI write grammar; this package's named
7
+ * builders (`cursorUp`, `hyperlink`, `styleText`, …) are conveniences that
8
+ * produce the same sequences for the cases callers reach for by name.
9
+ */
10
+ export function printAnsiToken(token) {
11
+ switch (token.kind) {
12
+ case "text":
13
+ return token.text;
14
+ case "csi":
15
+ return `${ESC_CHAR}[${token.parameters}${token.intermediates}${token.final}`;
16
+ default:
17
+ return `${ESC_CHAR}]${token.body}${token.terminator === "bel" ? BEL_CHAR : ST}`;
18
+ }
19
+ }
20
+ /** Creates the ANSI write half: tokens in, escape-sequence text out. */
21
+ export function createAnsiEncoder() {
22
+ return { encode: printAnsiToken };
23
+ }
24
+ //# sourceMappingURL=ansi-encoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ansi-encoder.js","sourceRoot":"","sources":["../src/ansi-encoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,EAAa,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,KAAgB;IAC9C,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,MAAM;YACV,OAAO,KAAK,CAAC,IAAI,CAAC;QACnB,KAAK,KAAK;YACT,OAAO,GAAG,QAAQ,IAAI,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;QAC9E;YACC,OAAO,GAAG,QAAQ,IAAI,KAAK,CAAC,IAAI,GAC/B,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EACzC,EAAE,CAAC;IACL,CAAC;AACF,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,iBAAiB;IAChC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;AACnC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { DecodeStream, EncodeStream } from "@ac-kit/format-core";
2
+ import type { AnsiToken } from "./ansi-token.js";
3
+ /** Options for {@link AnsiParseStream}. */
4
+ export type AnsiParseStreamOptions = {
5
+ /**
6
+ * Hard ceiling on undecoded retained text, in UTF-16 code units. Defaults to
7
+ * 1 MiB.
8
+ */
9
+ readonly maxBufferSize?: number;
10
+ };
11
+ /**
12
+ * Splits a terminal byte stream into {@link AnsiToken}s, reassembling escape
13
+ * sequences split across chunk boundaries.
14
+ */
15
+ export declare class AnsiParseStream extends DecodeStream<AnsiToken, string, Uint8Array> {
16
+ constructor(options?: AnsiParseStreamOptions);
17
+ }
18
+ /** Renders {@link AnsiToken}s back to escape-sequence text. */
19
+ export declare class AnsiPrintStream extends EncodeStream<AnsiToken, string> {
20
+ constructor();
21
+ }
22
+ //# sourceMappingURL=ansi-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ansi-stream.d.ts","sourceRoot":"","sources":["../src/ansi-stream.ts"],"names":[],"mappings":"AACA,OAAO,EACN,YAAY,EACZ,YAAY,EAEZ,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,2CAA2C;AAC3C,MAAM,MAAM,sBAAsB,GAAG;IACpC;;;OAGG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,YAAY,CAChD,SAAS,EACT,MAAM,EACN,UAAU,CACV;IACA,YAAY,OAAO,GAAE,sBAA2B,EAI/C;CACD;AAED,+DAA+D;AAC/D,qBAAa,eAAgB,SAAQ,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC;IACnE,cAEC;CACD"}
@@ -0,0 +1,22 @@
1
+ import { BYTES_PER_MIB } from "@ac-kit/core";
2
+ import { DecodeStream, EncodeStream, TextDecodeBuffer, } from "@ac-kit/format-core";
3
+ import { AnsiDecoder } from "./ansi-decoder.js";
4
+ import { createAnsiEncoder } from "./ansi-encoder.js";
5
+ /**
6
+ * Splits a terminal byte stream into {@link AnsiToken}s, reassembling escape
7
+ * sequences split across chunk boundaries.
8
+ */
9
+ export class AnsiParseStream extends DecodeStream {
10
+ constructor(options = {}) {
11
+ super(new AnsiDecoder(), {
12
+ buffer: new TextDecodeBuffer(options.maxBufferSize ?? BYTES_PER_MIB),
13
+ });
14
+ }
15
+ }
16
+ /** Renders {@link AnsiToken}s back to escape-sequence text. */
17
+ export class AnsiPrintStream extends EncodeStream {
18
+ constructor() {
19
+ super(createAnsiEncoder());
20
+ }
21
+ }
22
+ //# sourceMappingURL=ansi-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ansi-stream.js","sourceRoot":"","sources":["../src/ansi-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACN,YAAY,EACZ,YAAY,EACZ,gBAAgB,GAChB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAYtD;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,YAIpC;IACA,YAAY,OAAO,GAA2B,EAAE;QAC/C,KAAK,CAAC,IAAI,WAAW,EAAE,EAAE;YACxB,MAAM,EAAE,IAAI,gBAAgB,CAAC,OAAO,CAAC,aAAa,IAAI,aAAa,CAAC;SACpE,CAAC,CAAC;IACJ,CAAC;CACD;AAED,+DAA+D;AAC/D,MAAM,OAAO,eAAgB,SAAQ,YAA+B;IACnE;QACC,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC5B,CAAC;CACD"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * One unit of an ANSI byte stream.
3
+ *
4
+ * `text` carries everything that is not an escape sequence; the sequence kinds
5
+ * keep their parameter and intermediate bytes verbatim, so an encoder can
6
+ * reproduce the original stream exactly.
7
+ */
8
+ export type AnsiToken = {
9
+ readonly kind: "text";
10
+ readonly text: string;
11
+ } | {
12
+ /** `ESC [` … final byte: cursor motion, erase, SGR. */
13
+ readonly kind: "csi";
14
+ readonly parameters: string;
15
+ readonly intermediates: string;
16
+ readonly final: string;
17
+ } | {
18
+ /** `ESC ]` … BEL or ST: window title, OSC 8 hyperlink. */
19
+ readonly kind: "osc";
20
+ readonly body: string;
21
+ /** Which terminator closed it, since both are legal and round-trip. */
22
+ readonly terminator: "bel" | "st";
23
+ };
24
+ /** `ESC \` — the String Terminator, the other legal OSC terminator. */
25
+ export declare const ST: `${string}\\`;
26
+ //# sourceMappingURL=ansi-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ansi-token.d.ts","sourceRoot":"","sources":["../src/ansi-token.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChD;IACA,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACtB,GACD;IACA,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,QAAQ,CAAC,UAAU,EAAE,KAAK,GAAG,IAAI,CAAC;CACjC,CAAC;AAEL,uEAAuE;AACvE,eAAO,MAAM,EAAE,eAA2B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { ESC_CHAR } from "@ac-kit/core";
2
+ /** `ESC \` — the String Terminator, the other legal OSC terminator. */
3
+ export const ST = `${ESC_CHAR}\\`;
4
+ //# sourceMappingURL=ansi-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ansi-token.js","sourceRoot":"","sources":["../src/ansi-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AA0BxC,uEAAuE;AACvE,MAAM,CAAC,MAAM,EAAE,GAAG,GAAG,QAAQ,IAAa,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { Rgb8 } from "@ac-kit/math-color";
2
+ /**
3
+ * Matches `Terminal.colorDepth` (`@ac-kit/app-terminal`) — how many colors can
4
+ * be rendered.
5
+ */
6
+ export type ColorDepth = 1 | 4 | 8 | 24;
7
+ export type SgrStyleName = "bold" | "dim" | "italic" | "underline" | "inverse" | "strikethrough";
8
+ export type StyleTextOptions = {
9
+ /** SGR attributes to apply, e.g. `["bold", "underline"]`. */
10
+ styles?: readonly SgrStyleName[];
11
+ foreground?: Rgb8;
12
+ background?: Rgb8;
13
+ /**
14
+ * Downsamples requested colors to what this depth can render. Default `24`
15
+ * (no downsampling).
16
+ */
17
+ colorDepth?: ColorDepth;
18
+ };
19
+ /**
20
+ * Wraps `text` in SGR escape codes for the requested styles/colors, reset at
21
+ * the end. `foreground`/`background` are always specified as truecolor RGB and
22
+ * downsampled to `colorDepth` here — callers never hand-pick a palette index
23
+ * themselves.
24
+ *
25
+ * `colorDepth: 1` (monochrome) drops `foreground`/`background` entirely; styles
26
+ * (bold, underline, …) still apply, since those aren't color.
27
+ */
28
+ export declare function styleText(text: string, options?: StyleTextOptions): string;
29
+ //# sourceMappingURL=color.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../src/color.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAK/C;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;AAExC,MAAM,MAAM,YAAY,GACrB,MAAM,GACN,KAAK,GACL,QAAQ,GACR,WAAW,GACX,SAAS,GACT,eAAe,CAAC;AAWnB,MAAM,MAAM,gBAAgB,GAAG;IAC9B,6DAA6D;IAC7D,MAAM,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IACjC,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;CACxB,CAAC;AAqBF;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAuB1E"}
package/dist/color.js ADDED
@@ -0,0 +1,51 @@
1
+ import { nearestAnsi16 } from "./_ansi-16-palette.js";
2
+ import { nearestAnsi256 } from "./_ansi-256-palette.js";
3
+ const STYLE_CODES = {
4
+ bold: 1,
5
+ dim: 2,
6
+ italic: 3,
7
+ underline: 4,
8
+ inverse: 7,
9
+ strikethrough: 9,
10
+ };
11
+ function colorCodes(color, depth, isBackground) {
12
+ if (depth === 24) {
13
+ return [isBackground ? 48 : 38, 2, color.r8, color.g8, color.b8];
14
+ }
15
+ if (depth === 8) {
16
+ return [isBackground ? 48 : 38, 5, nearestAnsi256(color)];
17
+ }
18
+ const index = nearestAnsi16(color);
19
+ const bright = index >= 8;
20
+ const base = isBackground ? (bright ? 100 : 40) : bright ? 90 : 30;
21
+ return [base + (bright ? index - 8 : index)];
22
+ }
23
+ /**
24
+ * Wraps `text` in SGR escape codes for the requested styles/colors, reset at
25
+ * the end. `foreground`/`background` are always specified as truecolor RGB and
26
+ * downsampled to `colorDepth` here — callers never hand-pick a palette index
27
+ * themselves.
28
+ *
29
+ * `colorDepth: 1` (monochrome) drops `foreground`/`background` entirely; styles
30
+ * (bold, underline, …) still apply, since those aren't color.
31
+ */
32
+ export function styleText(text, options) {
33
+ const depth = options?.colorDepth ?? 24;
34
+ const codes = [];
35
+ for (const style of options?.styles ?? []) {
36
+ codes.push(STYLE_CODES[style]);
37
+ }
38
+ if (depth !== 1) {
39
+ if (options?.foreground) {
40
+ codes.push(...colorCodes(options.foreground, depth, false));
41
+ }
42
+ if (options?.background) {
43
+ codes.push(...colorCodes(options.background, depth, true));
44
+ }
45
+ }
46
+ if (codes.length === 0) {
47
+ return text;
48
+ }
49
+ return `\u001B[${codes.join(";")}m${text}\u001B[0m`;
50
+ }
51
+ //# sourceMappingURL=color.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.js","sourceRoot":"","sources":["../src/color.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAgBxD,MAAM,WAAW,GAAiC;IACjD,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,MAAM,EAAE,CAAC;IACT,SAAS,EAAE,CAAC;IACZ,OAAO,EAAE,CAAC;IACV,aAAa,EAAE,CAAC;CACP,CAAC;AAcX,SAAS,UAAU,CAClB,KAAW,EACX,KAAiB,EACjB,YAAqB;IAErB,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QAClB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,MAAM,GAAG,KAAK,IAAI,CAAC,CAAC;IAC1B,MAAM,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,OAAO,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,OAA0B;IACjE,MAAM,KAAK,GAAG,OAAO,EAAE,UAAU,IAAI,EAAE,CAAC;IACxC,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,MAAM,IAAI,EAAE,EAAE,CAAC;QAC3C,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QACjB,IAAI,OAAO,EAAE,UAAU,EAAE,CAAC;YACzB,KAAK,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QAC7D,CAAC;QAED,IAAI,OAAO,EAAE,UAAU,EAAE,CAAC;YACzB,KAAK,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QAC5D,CAAC;IACF,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,OAAO,UAAU,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,WAAW,CAAC;AACrD,CAAC"}
@@ -0,0 +1,19 @@
1
+ /** Moves the cursor up `count` rows. A no-op string when `count` is `0`. */
2
+ export declare function cursorUp(count: number): string;
3
+ /** Moves the cursor down `count` rows. A no-op string when `count` is `0`. */
4
+ export declare function cursorDown(count: number): string;
5
+ /** Erases from the cursor to the end of the screen. */
6
+ export declare const ERASE_FROM_CURSOR_TO_END: `${string}[0J`;
7
+ /** Erases the entire current line. */
8
+ export declare const ERASE_LINE: `${string}[2K`;
9
+ /** Erases the whole screen and its scrollback, then moves the cursor home. */
10
+ export declare const CLEAR_SCREEN: `${string}[2J${string}[3J${string}[H`;
11
+ /** Hides the text cursor. */
12
+ export declare const HIDE_CURSOR: `${string}[?25l`;
13
+ /** Shows the text cursor. */
14
+ export declare const SHOW_CURSOR: `${string}[?25h`;
15
+ /** Switches to the terminal's alternate screen buffer. */
16
+ export declare const ENTER_ALT_SCREEN: `${string}[?1049h`;
17
+ /** Switches back to the terminal's primary screen buffer. */
18
+ export declare const EXIT_ALT_SCREEN: `${string}[?1049l`;
19
+ //# sourceMappingURL=cursor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../src/cursor.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,8EAA8E;AAC9E,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,uDAAuD;AACvD,eAAO,MAAM,wBAAwB,gBAA4B,CAAC;AAElE,sCAAsC;AACtC,eAAO,MAAM,UAAU,gBAA4B,CAAC;AAEpD,8EAA8E;AAC9E,eAAO,MAAM,YAAY,uCAC4B,CAAC;AAEtD,6BAA6B;AAC7B,eAAO,MAAM,WAAW,kBAA8B,CAAC;AAEvD,6BAA6B;AAC7B,eAAO,MAAM,WAAW,kBAA8B,CAAC;AAEvD,0DAA0D;AAC1D,eAAO,MAAM,gBAAgB,oBAAgC,CAAC;AAE9D,6DAA6D;AAC7D,eAAO,MAAM,eAAe,oBAAgC,CAAC"}
package/dist/cursor.js ADDED
@@ -0,0 +1,24 @@
1
+ import { ESC_CHAR } from "@ac-kit/core";
2
+ /** Moves the cursor up `count` rows. A no-op string when `count` is `0`. */
3
+ export function cursorUp(count) {
4
+ return count > 0 ? `${ESC_CHAR}[${count}A` : "";
5
+ }
6
+ /** Moves the cursor down `count` rows. A no-op string when `count` is `0`. */
7
+ export function cursorDown(count) {
8
+ return count > 0 ? `${ESC_CHAR}[${count}B` : "";
9
+ }
10
+ /** Erases from the cursor to the end of the screen. */
11
+ export const ERASE_FROM_CURSOR_TO_END = `${ESC_CHAR}[0J`;
12
+ /** Erases the entire current line. */
13
+ export const ERASE_LINE = `${ESC_CHAR}[2K`;
14
+ /** Erases the whole screen and its scrollback, then moves the cursor home. */
15
+ export const CLEAR_SCREEN = `${ESC_CHAR}[2J${ESC_CHAR}[3J${ESC_CHAR}[H`;
16
+ /** Hides the text cursor. */
17
+ export const HIDE_CURSOR = `${ESC_CHAR}[?25l`;
18
+ /** Shows the text cursor. */
19
+ export const SHOW_CURSOR = `${ESC_CHAR}[?25h`;
20
+ /** Switches to the terminal's alternate screen buffer. */
21
+ export const ENTER_ALT_SCREEN = `${ESC_CHAR}[?1049h`;
22
+ /** Switches back to the terminal's primary screen buffer. */
23
+ export const EXIT_ALT_SCREEN = `${ESC_CHAR}[?1049l`;
24
+ //# sourceMappingURL=cursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.js","sourceRoot":"","sources":["../src/cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,4EAA4E;AAC5E,MAAM,UAAU,QAAQ,CAAC,KAAa;IACrC,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AACjD,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,UAAU,CAAC,KAAa;IACvC,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AACjD,CAAC;AAED,uDAAuD;AACvD,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,QAAQ,KAAc,CAAC;AAElE,sCAAsC;AACtC,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,QAAQ,KAAc,CAAC;AAEpD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,YAAY,GACxB,GAAG,QAAQ,MAAM,QAAQ,MAAM,QAAQ,IAAa,CAAC;AAEtD,6BAA6B;AAC7B,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,QAAQ,OAAgB,CAAC;AAEvD,6BAA6B;AAC7B,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,QAAQ,OAAgB,CAAC;AAEvD,0DAA0D;AAC1D,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,QAAQ,SAAkB,CAAC;AAE9D,6DAA6D;AAC7D,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,QAAQ,SAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Wraps `text` in an OSC 8 hyperlink escape sequence pointing at `url`. */
2
+ export declare function hyperlink(url: string, text: string): string;
3
+ //# sourceMappingURL=hyperlink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hyperlink.d.ts","sourceRoot":"","sources":["../src/hyperlink.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3D"}
@@ -0,0 +1,6 @@
1
+ import { BEL_CHAR, ESC_CHAR } from "@ac-kit/core";
2
+ /** Wraps `text` in an OSC 8 hyperlink escape sequence pointing at `url`. */
3
+ export function hyperlink(url, text) {
4
+ return `${ESC_CHAR}]8;;${url}${BEL_CHAR}${text}${ESC_CHAR}]8;;${BEL_CHAR}`;
5
+ }
6
+ //# sourceMappingURL=hyperlink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hyperlink.js","sourceRoot":"","sources":["../src/hyperlink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAElD,4EAA4E;AAC5E,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,IAAY;IAClD,OAAO,GAAG,QAAQ,OAAO,GAAG,GAAG,QAAQ,GAAG,IAAI,GAAG,QAAQ,OAAO,QAAQ,EAAE,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,9 @@
1
+ export * from "./ansi-decoder.js";
2
+ export * from "./ansi-encoder.js";
3
+ export * from "./ansi-stream.js";
4
+ export * from "./ansi-token.js";
5
+ export * from "./color.js";
6
+ export * from "./cursor.js";
7
+ export * from "./hyperlink.js";
8
+ export * from "./strip-ansi-escapes.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export * from "./ansi-decoder.js";
2
+ export * from "./ansi-encoder.js";
3
+ export * from "./ansi-stream.js";
4
+ export * from "./ansi-token.js";
5
+ export * from "./color.js";
6
+ export * from "./cursor.js";
7
+ export * from "./hyperlink.js";
8
+ export * from "./strip-ansi-escapes.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Strips ANSI/VT100 escape sequences (SGR colors, cursor moves, OSC 8 links).
3
+ *
4
+ * A utility over {@link AnsiDecoder}: every token that is not text is dropped.
5
+ * Handles CSI (`ESC [` and the 8-bit introducer) and OSC (`ESC ]`, terminated
6
+ * by BEL or ST). An unterminated sequence at the end of the input is kept, on
7
+ * the grounds that it is indistinguishable from ordinary text at that point.
8
+ */
9
+ export declare function stripAnsiEscapes(text: string): string;
10
+ //# sourceMappingURL=strip-ansi-escapes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strip-ansi-escapes.d.ts","sourceRoot":"","sources":["../src/strip-ansi-escapes.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiBrD"}
@@ -0,0 +1,24 @@
1
+ import { decodeAll, TextBuffer } from "@ac-kit/format-core";
2
+ import { AnsiDecoder } from "./ansi-decoder.js";
3
+ /**
4
+ * Strips ANSI/VT100 escape sequences (SGR colors, cursor moves, OSC 8 links).
5
+ *
6
+ * A utility over {@link AnsiDecoder}: every token that is not text is dropped.
7
+ * Handles CSI (`ESC [` and the 8-bit introducer) and OSC (`ESC ]`, terminated
8
+ * by BEL or ST). An unterminated sequence at the end of the input is kept, on
9
+ * the grounds that it is indistinguishable from ordinary text at that point.
10
+ */
11
+ export function stripAnsiEscapes(text) {
12
+ if (text.length === 0) {
13
+ return text;
14
+ }
15
+ const result = decodeAll(new AnsiDecoder(), text, { buffer: new TextBuffer(text.length) });
16
+ let out = "";
17
+ for (const item of result.items) {
18
+ if (item.value.kind === "text") {
19
+ out += item.value.text;
20
+ }
21
+ }
22
+ return out;
23
+ }
24
+ //# sourceMappingURL=strip-ansi-escapes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strip-ansi-escapes.js","sourceRoot":"","sources":["../src/strip-ansi-escapes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,MAAM,GAAG,SAAS,CACvB,IAAI,WAAW,EAAE,EACjB,IAAI,EACJ,EAAE,MAAM,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CACvC,CAAC;IAEF,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjC,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAChC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;QACxB,CAAC;IACF,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@ac-kit/format-ansi",
3
+ "version": "0.1.0",
4
+ "description": "ANSI/VT100/xterm escape sequences: stripping, cursor movement, OSC 8 hyperlinks, and SGR colour and style with colour-depth-aware downsampling.",
5
+ "keywords": [
6
+ "ansi",
7
+ "color",
8
+ "escape-codes",
9
+ "sgr",
10
+ "terminal"
11
+ ],
12
+ "homepage": "https://anthochamp.github.io/node-essentials/api/format-ansi/",
13
+ "bugs": {
14
+ "url": "https://github.com/anthochamp/node-essentials/issues"
15
+ },
16
+ "license": "BSD-3-Clause",
17
+ "author": "Anthony Champagne <dev@anthonychampagne.fr>",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/anthochamp/node-essentials.git",
21
+ "directory": "packages/format-ansi"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "main": "./dist/index.js",
29
+ "exports": {
30
+ ".": "./dist/index.js"
31
+ },
32
+ "publishConfig": {
33
+ "main": "./dist/index.js",
34
+ "exports": {
35
+ ".": "./dist/index.js"
36
+ },
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "compile": "tsc -p ./tsconfig.build.json -outDir dist",
41
+ "compile:check": "tsc -noEmit -p ./tsconfig.json",
42
+ "clean": "rimraf dist",
43
+ "build": "yarn clean && yarn compile",
44
+ "test": "yarn run -T vitest run",
45
+ "prepack": "yarn build"
46
+ },
47
+ "dependencies": {
48
+ "@ac-kit/algo": "^0.1.0",
49
+ "@ac-kit/core": "^0.1.0",
50
+ "@ac-kit/format-core": "^0.1.0",
51
+ "@ac-kit/math-color": "^0.1.0",
52
+ "@types/web": "^0.0.354"
53
+ },
54
+ "devDependencies": {
55
+ "@ac-kit/tsconfig": "0.1.0",
56
+ "@ac-kit/typedoc-config": "0.1.0",
57
+ "@ac-kit/vitest-config": "0.1.0",
58
+ "@typescript/native": "typescript@7.0.2",
59
+ "rimraf": "6.1.3",
60
+ "typedoc": "0.28.20",
61
+ "typescript": "@typescript/typescript6@6.0.2"
62
+ },
63
+ "engines": {
64
+ "node": ">=24"
65
+ }
66
+ }