@alchemy.run/sigil 0.0.0-alpha.4 → 0.0.0-alpha.6

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 (138) hide show
  1. package/README.md +21 -9
  2. package/THIRD_PARTY_NOTICES.md +39 -1
  3. package/dist/Text-BobFKi74.d.ts +452 -0
  4. package/dist/ansi.d.ts +122 -131
  5. package/dist/ansi.js +86 -6
  6. package/dist/capabilities.d.ts +5 -0
  7. package/dist/capabilities.js +3 -0
  8. package/dist/cell-_ZVhbfl0.js +44 -0
  9. package/dist/color-CkbalRqK.js +2 -0
  10. package/dist/color-policy-BMzMwV7Q.d.ts +22 -0
  11. package/dist/color-policy-SVj1pYTA.js +560 -0
  12. package/dist/color-profile-DHhQHY55.js +36 -0
  13. package/dist/color-profile-u0Nhe9Nv.d.ts +97 -0
  14. package/dist/color.d.ts +21 -0
  15. package/dist/color.js +3 -0
  16. package/dist/cursor-position-D2LAkRG0.d.ts +7 -0
  17. package/dist/detect-Bh4yGP6w.d.ts +186 -0
  18. package/dist/detect-BuTXtY6e.js +373 -0
  19. package/dist/env-YVw64yZS.js +9 -0
  20. package/dist/escapes-CB_6CWOE.d.ts +72 -0
  21. package/dist/geometry-BxXOzJgo.d.ts +11 -0
  22. package/dist/index-DZ88EXJv.d.ts +21 -0
  23. package/dist/index.d.ts +143 -498
  24. package/dist/index.js +1026 -2244
  25. package/dist/osc-CCH7xDoS.js +71 -0
  26. package/dist/osc-Cn0fw77g.d.ts +23 -0
  27. package/dist/paint-C19minOS.d.ts +81 -0
  28. package/dist/query-vaIeGOkH.d.ts +152 -0
  29. package/dist/router.d.ts +392 -0
  30. package/dist/router.js +709 -0
  31. package/dist/sample-Cqw1bjUL.js +445 -0
  32. package/dist/screen-BOSLQ8fF.d.ts +49 -0
  33. package/dist/screen-CiPytswf.js +342 -0
  34. package/dist/screen.d.ts +5 -0
  35. package/dist/screen.js +5 -0
  36. package/dist/semantic-text-style-DIMzC7xt.js +91 -0
  37. package/dist/serialize-BTkAZgw1.js +79 -0
  38. package/dist/session-aZr9O8h3.js +665 -0
  39. package/dist/sgr-BhwaWAJB.js +246 -0
  40. package/dist/store-CgrG9K4y.d.ts +72 -0
  41. package/dist/string-width-CijQwpIk.js +69 -0
  42. package/dist/strip-BvU4toXG.js +6 -0
  43. package/dist/terminal.d.ts +118 -0
  44. package/dist/terminal.js +2 -0
  45. package/dist/tokenize-AjqbvtiT.js +1242 -0
  46. package/dist/tokenize-Dx1y_l5H.d.ts +57 -0
  47. package/dist/truncate-D31fhU6i.js +562 -0
  48. package/dist/use-focus-BzqAJi0n.js +1337 -0
  49. package/package.json +41 -9
  50. package/src/ansi/chalk.ts +5 -3
  51. package/src/ansi/escapes.ts +14 -0
  52. package/src/ansi/graphemes.ts +8 -0
  53. package/src/ansi/hyperlink.ts +44 -0
  54. package/src/ansi/index.ts +3 -1
  55. package/src/ansi/osc.ts +77 -0
  56. package/src/ansi/tokenize.ts +3 -4
  57. package/src/capabilities/color-policy.ts +34 -0
  58. package/src/capabilities/detect.ts +594 -0
  59. package/src/capabilities/index.ts +37 -0
  60. package/src/capabilities/query.ts +657 -0
  61. package/src/capabilities/store.ts +379 -0
  62. package/src/color/index.ts +3 -0
  63. package/src/color/paint.ts +169 -0
  64. package/src/color/palette.ts +48 -0
  65. package/src/color/sample.ts +323 -0
  66. package/src/color.ts +1 -0
  67. package/src/components/AnsiText.tsx +42 -0
  68. package/src/components/App.tsx +98 -10
  69. package/src/components/BackgroundContext.ts +2 -3
  70. package/src/components/Box.tsx +0 -8
  71. package/src/components/CursorContext.ts +1 -1
  72. package/src/components/Hyperlink.tsx +56 -0
  73. package/src/components/TerminalOscContext.ts +25 -0
  74. package/src/components/Text.tsx +22 -45
  75. package/src/components/Transform.tsx +1 -1
  76. package/src/dom.ts +11 -2
  77. package/src/global.d.ts +3 -0
  78. package/src/hooks/use-capabilities.ts +73 -0
  79. package/src/hooks/use-cursor.ts +2 -2
  80. package/src/hooks/use-terminal-osc.ts +59 -0
  81. package/src/index.ts +45 -1
  82. package/src/ink.tsx +213 -153
  83. package/src/{render-node-to-output.ts → paint-tree.ts} +75 -48
  84. package/src/reconciler.ts +24 -3
  85. package/src/render-background.ts +36 -15
  86. package/src/render-border.ts +94 -61
  87. package/src/render-frame.ts +83 -0
  88. package/src/render-to-string.ts +21 -6
  89. package/src/render.ts +15 -6
  90. package/src/router/components.tsx +343 -0
  91. package/src/router/context.ts +41 -0
  92. package/src/router/history.ts +194 -0
  93. package/src/router/hooks.tsx +391 -0
  94. package/src/router/index.ts +34 -0
  95. package/src/router/matcher.ts +571 -0
  96. package/src/screen/ansi.ts +184 -0
  97. package/src/screen/canvas.ts +160 -0
  98. package/src/screen/cell.ts +138 -0
  99. package/src/screen/color-profile.ts +47 -0
  100. package/src/screen/geometry.ts +9 -0
  101. package/src/screen/index.ts +6 -0
  102. package/src/screen/screen.ts +305 -0
  103. package/src/screen/serialize.ts +129 -0
  104. package/src/screen.ts +1 -0
  105. package/src/semantic-text-style.ts +118 -0
  106. package/src/squash-text-nodes.ts +2 -5
  107. package/src/structured-text.ts +325 -0
  108. package/src/styles.ts +19 -14
  109. package/src/terminal/index.ts +2 -0
  110. package/src/terminal/inline-presenter.ts +120 -0
  111. package/src/terminal/input.ts +86 -0
  112. package/src/terminal/render-scheduler.ts +37 -0
  113. package/src/terminal/screen-presenter.ts +188 -0
  114. package/src/terminal/session.ts +407 -0
  115. package/src/terminal.ts +1 -0
  116. package/src/testing/browser.ts +588 -0
  117. package/src/testing/emulators.ts +205 -0
  118. package/src/testing/explorer-app/index.html +12 -0
  119. package/src/testing/explorer-app/main.ts +381 -0
  120. package/src/testing/explorer-app/style.css +194 -0
  121. package/src/testing/explorer-app/tsconfig.json +15 -0
  122. package/src/testing/explorer-app/vite-env.d.ts +1 -0
  123. package/src/testing/index.ts +26 -0
  124. package/src/testing/keys.ts +56 -0
  125. package/src/testing/live.ts +85 -0
  126. package/src/testing/matchers.ts +70 -0
  127. package/src/testing/public.ts +94 -0
  128. package/src/testing/terminal.ts +349 -0
  129. package/src/testing/vitest.ts +157 -0
  130. package/src/transform-adapter.ts +14 -0
  131. package/src/wrap-text.ts +4 -0
  132. package/dist/sgr-CMfEpjSk.d.ts +0 -91
  133. package/dist/truncate-Cr6xVFMa.js +0 -2330
  134. package/src/ansi/supports-color.ts +0 -207
  135. package/src/colorize.ts +0 -60
  136. package/src/log-update.ts +0 -370
  137. package/src/output.ts +0 -308
  138. package/src/renderer.ts +0 -73
package/dist/ansi.d.ts CHANGED
@@ -1,17 +1,96 @@
1
- import { _ as rgbToAnsi256, a as StylePair, c as backgroundColorNames, d as foregroundColorNames, f as hexToAnsi, g as rgbToAnsi, h as modifierNames, i as StyleName, l as codes, m as hexToRgb, n as ForegroundColorName, o as ansi256ToAnsi, p as hexToAnsi256, r as ModifierName, s as background, t as BackgroundColorName, u as foreground, v as styles } from "./sgr-CMfEpjSk.js";
2
- //#region src/ansi/supports-color.d.ts
3
- type ColorSupportLevel = 0 | 1 | 2 | 3;
4
- type ColorSupport = {
5
- readonly level: ColorSupportLevel;
6
- readonly hasBasic: boolean;
7
- readonly has256: boolean;
8
- readonly has16m: boolean;
1
+ import { i as ColorSupportLevel, n as ColorInfo } from "./detect-Bh4yGP6w.js";
2
+ import { A as exitAlternativeScreen, C as enableBracketedPaste, D as eraseLines, E as eraseLine, F as popKittyKeyboard, I as pushKittyKeyboard, L as resetCursorColor, M as link, N as pasteEnd, O as eraseScreen, P as pasteStart, S as disableBracketedPaste, T as eraseEndLine, _ as cursorNextLine, a as CursorShape, b as cursorTo, c as OSC, d as bsu, f as clearTerminal, g as cursorLeft, h as cursorHide, i as CSI, j as kittyQuery, k as esu, l as ST, m as cursorDown, n as C1_CSI, o as DEL, p as cursorColor, r as C1_ST, s as ESC, t as BEL, u as ansiEscapes, v as cursorShape, w as enterAlternativeScreen, x as cursorUp, y as cursorShow } from "./escapes-CB_6CWOE.js";
3
+ import { a as queryClipboard, c as setTerminalProgress, d as tmuxPassthrough, i as notify, l as setWindowTitle, n as TerminalProgressState, o as setClipboard, r as clearClipboard, s as setPointerShape, t as ClipboardSelection, u as setWorkingDirectory } from "./osc-Cn0fw77g.js";
4
+ import { _ as tokenize, a as StyledChar, c as diffAnsiCodes, d as getLinkStartCode, f as isIntensityCode, g as styledCharsToString, h as styledCharsFromTokens, i as ControlToken, l as endCodesSet, m as reduceAnsiCodesIncremental, n as AnsiToken, o as Token, p as reduceAnsiCodes, r as CharToken, s as ansiCodesToString, t as AnsiCode, u as getEndCode, v as undoAnsiCodes } from "./tokenize-Dx1y_l5H.js";
5
+ //#region src/ansi/sgr.d.ts
6
+ type StylePair = {
7
+ readonly open: string;
8
+ readonly close: string;
9
9
  };
10
- type ColorInfo = ColorSupport | false;
11
- declare const supportsColor: {
12
- stdout: ColorInfo;
13
- stderr: ColorInfo;
10
+ declare const modifierCodes: {
11
+ readonly reset: readonly [0, 0];
12
+ readonly bold: readonly [1, 22];
13
+ readonly dim: readonly [2, 22];
14
+ readonly italic: readonly [3, 23];
15
+ readonly underline: readonly [4, 24];
16
+ readonly overline: readonly [53, 55];
17
+ readonly inverse: readonly [7, 27];
18
+ readonly hidden: readonly [8, 28];
19
+ readonly strikethrough: readonly [9, 29];
14
20
  };
21
+ declare const colorCodes: {
22
+ readonly black: readonly [30, 39];
23
+ readonly red: readonly [31, 39];
24
+ readonly green: readonly [32, 39];
25
+ readonly yellow: readonly [33, 39];
26
+ readonly blue: readonly [34, 39];
27
+ readonly magenta: readonly [35, 39];
28
+ readonly cyan: readonly [36, 39];
29
+ readonly white: readonly [37, 39];
30
+ readonly blackBright: readonly [90, 39];
31
+ readonly gray: readonly [90, 39];
32
+ readonly grey: readonly [90, 39];
33
+ readonly redBright: readonly [91, 39];
34
+ readonly greenBright: readonly [92, 39];
35
+ readonly yellowBright: readonly [93, 39];
36
+ readonly blueBright: readonly [94, 39];
37
+ readonly magentaBright: readonly [95, 39];
38
+ readonly cyanBright: readonly [96, 39];
39
+ readonly whiteBright: readonly [97, 39];
40
+ };
41
+ declare const bgColorCodes: {
42
+ readonly bgBlack: readonly [40, 49];
43
+ readonly bgRed: readonly [41, 49];
44
+ readonly bgGreen: readonly [42, 49];
45
+ readonly bgYellow: readonly [43, 49];
46
+ readonly bgBlue: readonly [44, 49];
47
+ readonly bgMagenta: readonly [45, 49];
48
+ readonly bgCyan: readonly [46, 49];
49
+ readonly bgWhite: readonly [47, 49];
50
+ readonly bgBlackBright: readonly [100, 49];
51
+ readonly bgGray: readonly [100, 49];
52
+ readonly bgGrey: readonly [100, 49];
53
+ readonly bgRedBright: readonly [101, 49];
54
+ readonly bgGreenBright: readonly [102, 49];
55
+ readonly bgYellowBright: readonly [103, 49];
56
+ readonly bgBlueBright: readonly [104, 49];
57
+ readonly bgMagentaBright: readonly [105, 49];
58
+ readonly bgCyanBright: readonly [106, 49];
59
+ readonly bgWhiteBright: readonly [107, 49];
60
+ };
61
+ type ModifierName = keyof typeof modifierCodes;
62
+ type ForegroundColorName = keyof typeof colorCodes;
63
+ type BackgroundColorName = keyof typeof bgColorCodes;
64
+ type StyleName = ModifierName | ForegroundColorName | BackgroundColorName;
65
+ declare const modifierNames: ModifierName[];
66
+ declare const foregroundColorNames: ForegroundColorName[];
67
+ declare const backgroundColorNames: BackgroundColorName[];
68
+ /**
69
+ Named SGR styles as `{open, close}` escape sequence pairs.
70
+ */
71
+ declare const styles: Record<StyleName, StylePair>;
72
+ /**
73
+ Raw SGR code numbers: open code → close code.
74
+ */
75
+ declare const codes: ReadonlyMap<number, number>;
76
+ declare const foreground: {
77
+ close: string;
78
+ ansi: (code: number) => string;
79
+ ansi256: (code: number) => string;
80
+ ansi16m: (red: number, green: number, blue: number) => string;
81
+ };
82
+ declare const background: {
83
+ close: string;
84
+ ansi: (code: number) => string;
85
+ ansi256: (code: number) => string;
86
+ ansi16m: (red: number, green: number, blue: number) => string;
87
+ };
88
+ declare const rgbToAnsi256: (red: number, green: number, blue: number) => number;
89
+ declare const hexToRgb: (hex: string) => [number, number, number];
90
+ declare const hexToAnsi256: (hex: string) => number;
91
+ declare const ansi256ToAnsi: (code: number) => number;
92
+ declare const rgbToAnsi: (red: number, green: number, blue: number) => number;
93
+ declare const hexToAnsi: (hex: string) => number;
15
94
  //#endregion
16
95
  //#region src/ansi/chalk.d.ts
17
96
  type StyleFunction = (text: string) => string;
@@ -26,70 +105,38 @@ type Chalk = NamedStyles & {
26
105
  bgAnsi256: (code: number) => StyleFunction;
27
106
  };
28
107
  declare const chalk: Chalk;
108
+ declare const supportsColor: ColorInfo;
29
109
  //#endregion
30
- //#region src/ansi/escapes.d.ts
31
- declare const ESC = "";
32
- declare const BEL = "";
33
- declare const DEL = "";
34
- /** Control Sequence Introducer. */
35
- declare const CSI = "[";
36
- /** Operating System Command. */
37
- declare const OSC = "]";
38
- /** String Terminator. */
39
- declare const ST = "\\";
40
- /** Single-byte C1 forms of CSI and ST. */
41
- declare const C1_CSI = "›";
42
- declare const C1_ST = "œ";
43
- declare const cursorTo: (x: number, y?: number) => string;
44
- declare const cursorUp: (count?: number) => string;
45
- declare const cursorDown: (count?: number) => string;
46
- declare const cursorLeft: string;
47
- declare const cursorNextLine: string;
48
- declare const eraseEndLine: string;
49
- declare const eraseLine: string;
50
- declare const eraseScreen: string;
51
- declare const eraseLines: (count: number) => string;
52
- declare const clearTerminal = "";
53
- declare const enterAlternativeScreen: string;
54
- declare const exitAlternativeScreen: string;
55
- declare const cursorShow: string;
56
- declare const cursorHide: string;
57
- declare const enableBracketedPaste: string;
58
- declare const disableBracketedPaste: string;
59
- declare const pasteStart: string;
60
- declare const pasteEnd: string;
61
- declare const bsu: string;
62
- declare const esu: string;
63
- declare const kittyQuery: string;
64
- declare const pushKittyKeyboard: (flags: number) => string;
65
- declare const popKittyKeyboard: string;
66
- declare const link: (text: string, url: string) => string;
67
- declare const ansiEscapes: {
68
- cursorTo: typeof cursorTo;
69
- cursorUp: typeof cursorUp;
70
- cursorDown: typeof cursorDown;
71
- cursorLeft: string;
72
- cursorNextLine: string;
73
- eraseEndLine: string;
74
- eraseLine: string;
75
- eraseScreen: string;
76
- eraseLines: typeof eraseLines;
77
- clearTerminal: string;
78
- enterAlternativeScreen: string;
79
- exitAlternativeScreen: string;
80
- cursorShow: string;
81
- cursorHide: string;
82
- enableBracketedPaste: string;
83
- disableBracketedPaste: string;
84
- pasteStart: string;
85
- pasteEnd: string;
86
- bsu: string;
87
- esu: string;
88
- kittyQuery: string;
89
- pushKittyKeyboard: typeof pushKittyKeyboard;
90
- popKittyKeyboard: string;
91
- link: typeof link;
110
+ //#region src/ansi/hyperlink.d.ts
111
+ type HyperlinkOptions = {
112
+ /**
113
+ When the terminal does not support OSC 8 hyperlinks, append the URL in
114
+ parentheses after the text so it stays reachable. Set to `false` to
115
+ return the text alone.
116
+
117
+ @default true
118
+ */
119
+ fallback?: boolean;
120
+ /**
121
+ The stream the text will be written to, for support detection.
122
+
123
+ @default process.stdout
124
+ */
125
+ stream?: {
126
+ isTTY?: boolean;
127
+ };
92
128
  };
129
+ /**
130
+ Wraps text in a clickable OSC 8 hyperlink when the terminal supports it,
131
+ falling back to `text (url)`.
132
+
133
+ ```ts
134
+ import { hyperlink } from "@alchemy.run/sigil/ansi";
135
+
136
+ console.log(hyperlink("Documentation", "https://example.com"));
137
+ ```
138
+ */
139
+ declare const hyperlink: (text: string, url: string, { fallback, stream }?: HyperlinkOptions) => string;
93
140
  //#endregion
94
141
  //#region src/ansi/cursor.d.ts
95
142
  type CursorStream = {
@@ -167,60 +214,4 @@ type WrapOptions = {
167
214
  };
168
215
  declare function wrapAnsi(string: string, columns: number, options?: WrapOptions): string;
169
216
  //#endregion
170
- //#region src/ansi/tokenize.d.ts
171
- /**
172
- An ANSI code paired with the code that ends its effect.
173
- */
174
- type AnsiCode = {
175
- readonly code: string;
176
- readonly endCode: string;
177
- };
178
- type AnsiToken = AnsiCode & {
179
- readonly type: "ansi";
180
- };
181
- type ControlToken = {
182
- readonly type: "control";
183
- readonly code: string;
184
- };
185
- type CharToken = {
186
- readonly type: "char";
187
- readonly value: string;
188
- readonly fullWidth: boolean;
189
- };
190
- type Token = AnsiToken | ControlToken | CharToken;
191
- type StyledChar = CharToken & {
192
- readonly styles: AnsiCode[];
193
- };
194
- declare const endCodesSet: Set<string>;
195
- declare function getLinkStartCode(url: string, params?: Record<string, string>): string;
196
- declare function getEndCode(code: string): string;
197
- declare function ansiCodesToString(codes: readonly AnsiCode[]): string;
198
- /**
199
- Check if a code is an intensity code (bold or dim) — these share the end code
200
- `22m` but can coexist.
201
- */
202
- declare function isIntensityCode(code: AnsiCode): boolean;
203
- declare function tokenize(string: string, endChar?: number): Token[];
204
- /**
205
- Reduces the given array of ANSI codes to the minimum necessary to render with
206
- the same style.
207
- */
208
- declare function reduceAnsiCodes(codes: readonly AnsiCode[]): AnsiCode[];
209
- /**
210
- Like {@link reduceAnsiCodes}, but assumes that `codes` is already reduced.
211
- Further reductions are only done for the items in `newCodes`.
212
- */
213
- declare function reduceAnsiCodesIncremental(codes: readonly AnsiCode[], newCodes: readonly AnsiCode[]): AnsiCode[];
214
- /**
215
- Returns the combination of ANSI codes needed to undo the given ANSI codes.
216
- */
217
- declare function undoAnsiCodes(codes: readonly AnsiCode[]): AnsiCode[];
218
- /**
219
- Returns the minimum amount of ANSI codes necessary to get from the compound
220
- style `from` to `to`. Both are expected to be reduced.
221
- */
222
- declare function diffAnsiCodes(from: readonly AnsiCode[], to: readonly AnsiCode[]): AnsiCode[];
223
- declare function styledCharsFromTokens(tokens: readonly Token[]): StyledChar[];
224
- declare function styledCharsToString(chars: readonly StyledChar[]): string;
225
- //#endregion
226
- export { AnsiCode, AnsiToken, BEL, BackgroundColorName, C1_CSI, C1_ST, CSI, CharToken, ControlToken, DEL, ESC, EastAsianWidthType, ForegroundColorName, ModifierName, OSC, ST, StyleName, StylePair, StyledChar, Token, ambiguousMaximumCodePoint, ambiguousMinimalCodePoint, ambiguousRanges, ansi256ToAnsi, ansiCodesToString, ansiEscapes, background, backgroundColorNames, bsu, chalk, clearTerminal, cliCursor, codes, cursorDown, cursorHide, cursorLeft, cursorNextLine, cursorShow, cursorTo, cursorUp, diffAnsiCodes, disableBracketedPaste, eastAsianWidth, eastAsianWidthType, enableBracketedPaste, endCodesSet, enterAlternativeScreen, eraseEndLine, eraseLine, eraseLines, eraseScreen, esu, exitAlternativeScreen, foreground, foregroundColorNames, fullwidthMaximumCodePoint, fullwidthMinimalCodePoint, fullwidthRanges, getCategory, getEndCode, getLinkStartCode, halfwidthMaximumCodePoint, halfwidthMinimalCodePoint, halfwidthRanges, hexToAnsi, hexToAnsi256, hexToRgb, isAmbiguous, isFullWidth, isFullwidthCodePoint, isFullwidthGrapheme, isIntensityCode, isWide, isWideNotCJKTNotEmoji, kittyQuery, link, modifierNames, narrowMaximumCodePoint, narrowMinimalCodePoint, narrowRanges, pasteEnd, pasteStart, popKittyKeyboard, pushKittyKeyboard, reduceAnsiCodes, reduceAnsiCodesIncremental, rgbToAnsi, rgbToAnsi256, sliceAnsi, stringWidth, stripAnsi, styledCharsFromTokens, styledCharsToString, styles, supportsColor, tokenize, cliTruncate as truncateAnsi, undoAnsiCodes, wideMaximumCodePoint, wideMinimalCodePoint, wideRanges, widestLine, wrapAnsi };
217
+ export { AnsiCode, AnsiToken, BEL, BackgroundColorName, C1_CSI, C1_ST, CSI, CharToken, ClipboardSelection, ControlToken, CursorShape, DEL, ESC, EastAsianWidthType, ForegroundColorName, ModifierName, OSC, ST, StyleName, StylePair, StyledChar, TerminalProgressState, Token, ambiguousMaximumCodePoint, ambiguousMinimalCodePoint, ambiguousRanges, ansi256ToAnsi, ansiCodesToString, ansiEscapes, background, backgroundColorNames, bsu, chalk, clearClipboard, clearTerminal, cliCursor, codes, cursorColor, cursorDown, cursorHide, cursorLeft, cursorNextLine, cursorShape, cursorShow, cursorTo, cursorUp, diffAnsiCodes, disableBracketedPaste, eastAsianWidth, eastAsianWidthType, enableBracketedPaste, endCodesSet, enterAlternativeScreen, eraseEndLine, eraseLine, eraseLines, eraseScreen, esu, exitAlternativeScreen, foreground, foregroundColorNames, fullwidthMaximumCodePoint, fullwidthMinimalCodePoint, fullwidthRanges, getCategory, getEndCode, getLinkStartCode, halfwidthMaximumCodePoint, halfwidthMinimalCodePoint, halfwidthRanges, hexToAnsi, hexToAnsi256, hexToRgb, hyperlink, isAmbiguous, isFullWidth, isFullwidthCodePoint, isFullwidthGrapheme, isIntensityCode, isWide, isWideNotCJKTNotEmoji, kittyQuery, link, modifierNames, narrowMaximumCodePoint, narrowMinimalCodePoint, narrowRanges, notify, pasteEnd, pasteStart, popKittyKeyboard, pushKittyKeyboard, queryClipboard, reduceAnsiCodes, reduceAnsiCodesIncremental, resetCursorColor, rgbToAnsi, rgbToAnsi256, setClipboard, setPointerShape, setTerminalProgress, setWindowTitle, setWorkingDirectory, sliceAnsi, stringWidth, stripAnsi, styledCharsFromTokens, styledCharsToString, styles, supportsColor, tmuxPassthrough, tokenize, cliTruncate as truncateAnsi, undoAnsiCodes, wideMaximumCodePoint, wideMinimalCodePoint, wideRanges, widestLine, wrapAnsi };
package/dist/ansi.js CHANGED
@@ -1,7 +1,87 @@
1
- import { $ as wideRanges, A as ambiguousMaximumCodePoint, At as cursorUp, B as halfwidthMinimalCodePoint, Bt as kittyQuery, Ct as clearTerminal, D as wrapAnsi, Dt as cursorNextLine, Et as cursorLeft, F as fullwidthMaximumCodePoint, Ft as eraseLine, G as isFullwidthGrapheme, Gt as pushKittyKeyboard, H as isAmbiguous, Ht as pasteEnd, I as fullwidthMinimalCodePoint, It as eraseLines, J as narrowMaximumCodePoint, K as isWide, L as fullwidthRanges, Lt as eraseScreen, M as ambiguousRanges, Mt as enableBracketedPaste, N as eastAsianWidth, Nt as enterAlternativeScreen, O as stringWidth, Ot as cursorShow, P as eastAsianWidthType, Pt as eraseEndLine, Q as wideMinimalCodePoint, R as getCategory, Rt as esu, St as bsu, Tt as cursorHide, U as isFullWidth, Ut as pasteStart, V as halfwidthRanges, Vt as link, W as isFullwidthCodePoint, Wt as popKittyKeyboard, X as narrowRanges, Y as narrowMinimalCodePoint, Z as wideMaximumCodePoint, _ as chalk, _t as DEL, a as endCodesSet, at as foregroundColorNames, bt as ST, c as isIntensityCode, ct as hexToRgb, d as styledCharsFromTokens, dt as rgbToAnsi256, et as ansi256ToAnsi, f as styledCharsToString, ft as styles, gt as CSI, ht as C1_ST, i as diffAnsiCodes, it as foreground, j as ambiguousMinimalCodePoint, jt as disableBracketedPaste, k as widestLine, kt as cursorTo, l as reduceAnsiCodes, lt as modifierNames, m as undoAnsiCodes, mt as C1_CSI, n as sliceAnsi, nt as backgroundColorNames, o as getEndCode, ot as hexToAnsi, p as tokenize, pt as BEL, q as isWideNotCJKTNotEmoji, r as ansiCodesToString, rt as codes, s as getLinkStartCode, st as hexToAnsi256, t as cliTruncate, tt as background, u as reduceAnsiCodesIncremental, ut as rgbToAnsi, v as supportsColor, vt as ESC, wt as cursorDown, xt as ansiEscapes, y as cliCursor, yt as OSC, z as halfwidthMaximumCodePoint, zt as exitAlternativeScreen } from "./truncate-Cr6xVFMa.js";
2
- import { stripVTControlCharacters } from "node:util";
3
- //#region src/ansi/strip.ts
4
- const colonSgrRegex = /(?:\u001B\[|\u009B)[\d;]*:[\d;:]*m/g;
5
- const stripAnsi = (input) => stripVTControlCharacters(input.replaceAll(colonSgrRegex, ""));
1
+ import { A as cursorShape, B as eraseScreen, C as bsu, D as cursorHide, E as cursorDown, F as enableBracketedPaste, G as pasteEnd, H as exitAlternativeScreen, I as enterAlternativeScreen, J as pushKittyKeyboard, K as pasteStart, L as eraseEndLine, M as cursorTo, N as cursorUp, O as cursorLeft, P as disableBracketedPaste, R as eraseLine, S as ansiEscapes, T as cursorColor, U as kittyQuery, V as esu, W as link, Y as resetCursorColor, _ as CSI, a as foreground, b as OSC, c as hexToAnsi256, d as rgbToAnsi, f as rgbToAnsi256, g as C1_ST, h as C1_CSI, i as codes, j as cursorShow, k as cursorNextLine, l as hexToRgb, m as BEL, n as background, o as foregroundColorNames, p as styles, q as popKittyKeyboard, r as backgroundColorNames, s as hexToAnsi, t as ansi256ToAnsi, u as modifierNames, v as DEL, w as clearTerminal, x as ST, y as ESC, z as eraseLines } from "./sgr-BhwaWAJB.js";
2
+ import { A as isFullwidthCodePoint, C as fullwidthRanges, D as halfwidthRanges, E as halfwidthMinimalCodePoint, F as narrowMinimalCodePoint, I as narrowRanges, L as wideMaximumCodePoint, M as isWide, N as isWideNotCJKTNotEmoji, O as isAmbiguous, P as narrowMaximumCodePoint, R as wideMinimalCodePoint, S as fullwidthMinimalCodePoint, T as halfwidthMaximumCodePoint, _ as ambiguousMinimalCodePoint, a as getLinkStartCode, b as eastAsianWidthType, c as reduceAnsiCodesIncremental, d as tokenize, f as undoAnsiCodes, g as ambiguousMaximumCodePoint, i as getEndCode, j as isFullwidthGrapheme, k as isFullWidth, l as styledCharsFromTokens, n as diffAnsiCodes, o as isIntensityCode, r as endCodesSet, s as reduceAnsiCodes, t as ansiCodesToString, u as styledCharsToString, v as ambiguousRanges, w as getCategory, x as fullwidthMaximumCodePoint, y as eastAsianWidth, z as wideRanges } from "./tokenize-AjqbvtiT.js";
3
+ import { n as widestLine, t as stringWidth } from "./string-width-CijQwpIk.js";
4
+ import { n as sliceAnsi, r as wrapAnsi, t as cliTruncate } from "./truncate-D31fhU6i.js";
5
+ import { i as detectHyperlinkSupport, t as createSupportsColor } from "./detect-BuTXtY6e.js";
6
+ import { a as setPointerShape, c as setWorkingDirectory, i as setClipboard, l as tmuxPassthrough, n as notify, o as setTerminalProgress, r as queryClipboard, s as setWindowTitle, t as clearClipboard, u as cliCursor } from "./osc-CCH7xDoS.js";
7
+ import { t as stripAnsi } from "./strip-BvU4toXG.js";
8
+ import { isatty } from "node:tty";
9
+ //#region src/ansi/chalk.ts
10
+ const stdoutColor = createSupportsColor({ isTTY: isatty(1) });
11
+ const levelMapping = [
12
+ "ansi",
13
+ "ansi",
14
+ "ansi256",
15
+ "ansi16m"
16
+ ];
17
+ const state = { level: stdoutColor ? stdoutColor.level : 0 };
18
+ const applyStyle = (open, close, text) => {
19
+ if (state.level <= 0 || !text) return text;
20
+ let string = text;
21
+ if (string.includes("\x1B")) string = string.replaceAll(close, close + open);
22
+ if (string.includes("\n")) string = string.replaceAll(/\r?\n/g, `${close}$&${open}`);
23
+ return open + string + close;
24
+ };
25
+ const styleFunction = (open, close) => {
26
+ return (text) => applyStyle(open, close, text);
27
+ };
28
+ const foregroundOpen = (model, args) => {
29
+ return colorOpen(model, args, foreground, rgbToAnsi256, rgbToAnsi);
30
+ };
31
+ const backgroundOpen = (model, args) => {
32
+ return colorOpen(model, args, background, rgbToAnsi256, rgbToAnsi);
33
+ };
34
+ const colorOpen = (model, args, space, toAnsi256, toAnsi) => {
35
+ const rgb = typeof args[0] === "string" ? hexToRgb(args[0]) : args;
36
+ if (model === "ansi16m") return space.ansi16m(...rgb);
37
+ if (model === "ansi256") return space.ansi256(toAnsi256(...rgb));
38
+ return space.ansi(toAnsi(...rgb));
39
+ };
40
+ const named = {};
41
+ for (const name of [
42
+ ...modifierNames,
43
+ ...foregroundColorNames,
44
+ ...backgroundColorNames
45
+ ]) named[name] = styleFunction(styles[name].open, styles[name].close);
46
+ const chalk = {
47
+ ...named,
48
+ get level() {
49
+ return state.level;
50
+ },
51
+ set level(level) {
52
+ state.level = level;
53
+ },
54
+ hex: (color) => styleFunction(foregroundOpen(levelMapping[state.level], [color]), foreground.close),
55
+ bgHex: (color) => styleFunction(backgroundOpen(levelMapping[state.level], [color]), background.close),
56
+ rgb: (red, green, blue) => styleFunction(foregroundOpen(levelMapping[state.level], [
57
+ red,
58
+ green,
59
+ blue
60
+ ]), foreground.close),
61
+ bgRgb: (red, green, blue) => styleFunction(backgroundOpen(levelMapping[state.level], [
62
+ red,
63
+ green,
64
+ blue
65
+ ]), background.close),
66
+ ansi256: (code) => styleFunction(foreground.ansi256(code), foreground.close),
67
+ bgAnsi256: (code) => styleFunction(background.ansi256(code), background.close)
68
+ };
69
+ const supportsColor = stdoutColor;
6
70
  //#endregion
7
- export { BEL, C1_CSI, C1_ST, CSI, DEL, ESC, OSC, ST, ambiguousMaximumCodePoint, ambiguousMinimalCodePoint, ambiguousRanges, ansi256ToAnsi, ansiCodesToString, ansiEscapes, background, backgroundColorNames, bsu, chalk, clearTerminal, cliCursor, codes, cursorDown, cursorHide, cursorLeft, cursorNextLine, cursorShow, cursorTo, cursorUp, diffAnsiCodes, disableBracketedPaste, eastAsianWidth, eastAsianWidthType, enableBracketedPaste, endCodesSet, enterAlternativeScreen, eraseEndLine, eraseLine, eraseLines, eraseScreen, esu, exitAlternativeScreen, foreground, foregroundColorNames, fullwidthMaximumCodePoint, fullwidthMinimalCodePoint, fullwidthRanges, getCategory, getEndCode, getLinkStartCode, halfwidthMaximumCodePoint, halfwidthMinimalCodePoint, halfwidthRanges, hexToAnsi, hexToAnsi256, hexToRgb, isAmbiguous, isFullWidth, isFullwidthCodePoint, isFullwidthGrapheme, isIntensityCode, isWide, isWideNotCJKTNotEmoji, kittyQuery, link, modifierNames, narrowMaximumCodePoint, narrowMinimalCodePoint, narrowRanges, pasteEnd, pasteStart, popKittyKeyboard, pushKittyKeyboard, reduceAnsiCodes, reduceAnsiCodesIncremental, rgbToAnsi, rgbToAnsi256, sliceAnsi, stringWidth, stripAnsi, styledCharsFromTokens, styledCharsToString, styles, supportsColor, tokenize, cliTruncate as truncateAnsi, undoAnsiCodes, wideMaximumCodePoint, wideMinimalCodePoint, wideRanges, widestLine, wrapAnsi };
71
+ //#region src/ansi/hyperlink.ts
72
+ /**
73
+ Wraps text in a clickable OSC 8 hyperlink when the terminal supports it,
74
+ falling back to `text (url)`.
75
+
76
+ ```ts
77
+ import { hyperlink } from "@alchemy.run/sigil/ansi";
78
+
79
+ console.log(hyperlink("Documentation", "https://example.com"));
80
+ ```
81
+ */
82
+ const hyperlink = (text, url, { fallback = true, stream = process.stdout } = {}) => {
83
+ if (detectHyperlinkSupport(stream)) return link(text, url);
84
+ return fallback ? `${text} (${url})` : text;
85
+ };
86
+ //#endregion
87
+ export { BEL, C1_CSI, C1_ST, CSI, DEL, ESC, OSC, ST, ambiguousMaximumCodePoint, ambiguousMinimalCodePoint, ambiguousRanges, ansi256ToAnsi, ansiCodesToString, ansiEscapes, background, backgroundColorNames, bsu, chalk, clearClipboard, clearTerminal, cliCursor, codes, cursorColor, cursorDown, cursorHide, cursorLeft, cursorNextLine, cursorShape, cursorShow, cursorTo, cursorUp, diffAnsiCodes, disableBracketedPaste, eastAsianWidth, eastAsianWidthType, enableBracketedPaste, endCodesSet, enterAlternativeScreen, eraseEndLine, eraseLine, eraseLines, eraseScreen, esu, exitAlternativeScreen, foreground, foregroundColorNames, fullwidthMaximumCodePoint, fullwidthMinimalCodePoint, fullwidthRanges, getCategory, getEndCode, getLinkStartCode, halfwidthMaximumCodePoint, halfwidthMinimalCodePoint, halfwidthRanges, hexToAnsi, hexToAnsi256, hexToRgb, hyperlink, isAmbiguous, isFullWidth, isFullwidthCodePoint, isFullwidthGrapheme, isIntensityCode, isWide, isWideNotCJKTNotEmoji, kittyQuery, link, modifierNames, narrowMaximumCodePoint, narrowMinimalCodePoint, narrowRanges, notify, pasteEnd, pasteStart, popKittyKeyboard, pushKittyKeyboard, queryClipboard, reduceAnsiCodes, reduceAnsiCodesIncremental, resetCursorColor, rgbToAnsi, rgbToAnsi256, setClipboard, setPointerShape, setTerminalProgress, setWindowTitle, setWorkingDirectory, sliceAnsi, stringWidth, stripAnsi, styledCharsFromTokens, styledCharsToString, styles, supportsColor, tmuxPassthrough, tokenize, cliTruncate as truncateAnsi, undoAnsiCodes, wideMaximumCodePoint, wideMinimalCodePoint, wideRanges, widestLine, wrapAnsi };
@@ -0,0 +1,5 @@
1
+ import { a as Multiplexer, c as TerminalAppearance, d as detectCapabilities, f as detectColorLevel, h as detectUnicodeSupport, i as ColorSupportLevel, l as TerminalIdentity, m as detectTerminal, n as ColorInfo, o as PixelGeometry, p as detectHyperlinkSupport, r as ColorSupport, s as RgbColor, t as Capabilities, u as createSupportsColor } from "./detect-Bh4yGP6w.js";
2
+ import { a as getTerminalQuery, i as applyTerminalQuery, n as TerminalQueryOptions, o as queryTerminal, r as TerminalQueryResult, s as refreshTerminalQuery, t as PixelSize } from "./query-vaIeGOkH.js";
3
+ import { n as capabilities, r as getCapabilities, t as CapabilitiesStore } from "./store-CgrG9K4y.js";
4
+ import { i as resolveColorProfile, n as ColorState, r as colorState, t as ColorPolicy } from "./color-policy-BMzMwV7Q.js";
5
+ export { type Capabilities, type CapabilitiesStore, type ColorInfo, type ColorPolicy, type ColorState, type ColorSupport, type ColorSupportLevel, type Multiplexer, type PixelGeometry, type PixelSize, type RgbColor, type TerminalAppearance, type TerminalIdentity, type TerminalQueryOptions, type TerminalQueryResult, applyTerminalQuery, capabilities, colorState, createSupportsColor, detectCapabilities, detectColorLevel, detectHyperlinkSupport, detectTerminal, detectUnicodeSupport, getCapabilities, getTerminalQuery, queryTerminal, refreshTerminalQuery, resolveColorProfile };
@@ -0,0 +1,3 @@
1
+ import { a as detectTerminal, i as detectHyperlinkSupport, n as detectCapabilities, o as detectUnicodeSupport, r as detectColorLevel, t as createSupportsColor } from "./detect-BuTXtY6e.js";
2
+ import { d as queryTerminal, f as refreshTerminalQuery, i as getCapabilities, l as getTerminalQuery, n as resolveColorProfile, r as capabilities, s as applyTerminalQuery, t as colorState } from "./color-policy-SVj1pYTA.js";
3
+ export { applyTerminalQuery, capabilities, colorState, createSupportsColor, detectCapabilities, detectColorLevel, detectHyperlinkSupport, detectTerminal, detectUnicodeSupport, getCapabilities, getTerminalQuery, queryTerminal, refreshTerminalQuery, resolveColorProfile };
@@ -0,0 +1,44 @@
1
+ //#region src/screen/cell.ts
2
+ /**
3
+ Bit flags for terminal text attributes. Multiple attributes may be combined.
4
+ */
5
+ const cellAttributes = {
6
+ none: 0,
7
+ bold: 1,
8
+ faint: 2,
9
+ italic: 4,
10
+ blink: 8,
11
+ rapidBlink: 16,
12
+ inverse: 32,
13
+ hidden: 64,
14
+ strikethrough: 128
15
+ };
16
+ const emptyCellStyle = {
17
+ underline: "none",
18
+ attributes: cellAttributes.none
19
+ };
20
+ const emptyCell = {
21
+ grapheme: " ",
22
+ width: 1,
23
+ style: emptyCellStyle
24
+ };
25
+ const createCell = (grapheme, width, style = emptyCellStyle, hyperlink, reset) => {
26
+ if (grapheme.length === 0) throw new Error("A cell must contain one grapheme cluster");
27
+ if (!Number.isInteger(width) || width < 1) throw new Error("A cell width must be a positive integer");
28
+ return {
29
+ grapheme,
30
+ width,
31
+ style,
32
+ ...hyperlink ? { hyperlink } : {},
33
+ ...reset ? { reset } : {}
34
+ };
35
+ };
36
+ const cellsEqual = (left, right) => {
37
+ if (left === right) return true;
38
+ if (!left || !right || left.grapheme !== right.grapheme || left.width !== right.width) return false;
39
+ const leftStyle = left.style;
40
+ const rightStyle = right.style;
41
+ return leftStyle.attributes === rightStyle.attributes && leftStyle.underline === rightStyle.underline && JSON.stringify(leftStyle.foreground) === JSON.stringify(rightStyle.foreground) && JSON.stringify(leftStyle.background) === JSON.stringify(rightStyle.background) && JSON.stringify(leftStyle.underlineColor) === JSON.stringify(rightStyle.underlineColor) && JSON.stringify(left.hyperlink) === JSON.stringify(right.hyperlink);
42
+ };
43
+ //#endregion
44
+ export { emptyCellStyle as a, emptyCell as i, cellsEqual as n, createCell as r, cellAttributes as t };
@@ -0,0 +1,2 @@
1
+ import "./sample-Cqw1bjUL.js";
2
+ export {};
@@ -0,0 +1,22 @@
1
+ import { i as ColorSupportLevel } from "./detect-Bh4yGP6w.js";
2
+ import { t as ColorProfile } from "./color-profile-u0Nhe9Nv.js";
3
+ //#region src/capabilities/color-policy.d.ts
4
+ /** A user-selected output policy. `auto` follows the target stream. */
5
+ type ColorPolicy = "auto" | ColorProfile;
6
+ /** The three distinct inputs and result of terminal color negotiation. */
7
+ type ColorState = {
8
+ /** The stream/terminal fact after environment and query detection. */
9
+ readonly detected: ColorProfile;
10
+ /** The application's policy for this render instance. */
11
+ readonly policy: ColorPolicy;
12
+ /** The profile the serializer must actually emit. */
13
+ readonly effective: ColorProfile;
14
+ };
15
+ declare function resolveColorProfile(detectedLevel: ColorSupportLevel, policy?: ColorPolicy): ColorProfile;
16
+ declare function colorState(capabilities: {
17
+ readonly color: {
18
+ readonly level: ColorSupportLevel;
19
+ };
20
+ }, policy?: ColorPolicy): ColorState;
21
+ //#endregion
22
+ export { resolveColorProfile as i, ColorState as n, colorState as r, ColorPolicy as t };