@trismegisto/terminal 3.3.13 → 3.4.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 (150) hide show
  1. package/README.md +12 -0
  2. package/dist/addons/attach.d.ts +16 -0
  3. package/dist/addons/attach.js +58 -0
  4. package/dist/addons/attach.js.map +1 -0
  5. package/dist/addons/clipboard.d.ts +31 -0
  6. package/dist/addons/clipboard.js +77 -0
  7. package/dist/addons/clipboard.js.map +1 -0
  8. package/dist/addons/fit.d.ts +19 -0
  9. package/dist/addons/fit.js +69 -0
  10. package/dist/addons/fit.js.map +1 -0
  11. package/dist/addons/image/iip.d.ts +38 -0
  12. package/dist/addons/image/iip.js +158 -0
  13. package/dist/addons/image/iip.js.map +1 -0
  14. package/dist/addons/image/index.d.ts +91 -0
  15. package/dist/addons/image/index.js +783 -0
  16. package/dist/addons/image/index.js.map +1 -0
  17. package/dist/addons/image/kitty.d.ts +57 -0
  18. package/dist/addons/image/kitty.js +92 -0
  19. package/dist/addons/image/kitty.js.map +1 -0
  20. package/dist/addons/image/qoi.d.ts +5 -0
  21. package/dist/addons/image/qoi.js +70 -0
  22. package/dist/addons/image/qoi.js.map +1 -0
  23. package/dist/addons/image/sixel.d.ts +30 -0
  24. package/dist/addons/image/sixel.js +251 -0
  25. package/dist/addons/image/sixel.js.map +1 -0
  26. package/dist/addons/image/storage.d.ts +68 -0
  27. package/dist/addons/image/storage.js +87 -0
  28. package/dist/addons/image/storage.js.map +1 -0
  29. package/dist/addons/ligatures.d.ts +17 -0
  30. package/dist/addons/ligatures.js +66 -0
  31. package/dist/addons/ligatures.js.map +1 -0
  32. package/dist/addons/program-status.d.ts +32 -0
  33. package/dist/addons/program-status.js +196 -0
  34. package/dist/addons/program-status.js.map +1 -0
  35. package/dist/addons/progress.d.ts +21 -0
  36. package/dist/addons/progress.js +56 -0
  37. package/dist/addons/progress.js.map +1 -0
  38. package/dist/addons/search.d.ts +46 -0
  39. package/dist/addons/search.js +188 -0
  40. package/dist/addons/search.js.map +1 -0
  41. package/dist/addons/serialize.d.ts +35 -0
  42. package/dist/addons/serialize.js +313 -0
  43. package/dist/addons/serialize.js.map +1 -0
  44. package/dist/addons/unicode.d.ts +19 -0
  45. package/dist/addons/unicode.js +44 -0
  46. package/dist/addons/unicode.js.map +1 -0
  47. package/dist/addons/web-fonts.d.ts +22 -0
  48. package/dist/addons/web-fonts.js +88 -0
  49. package/dist/addons/web-fonts.js.map +1 -0
  50. package/dist/addons/web-links.d.ts +22 -0
  51. package/dist/addons/web-links.js +89 -0
  52. package/dist/addons/web-links.js.map +1 -0
  53. package/dist/addons/webgl/atlas.d.ts +57 -0
  54. package/dist/addons/webgl/atlas.js +90 -0
  55. package/dist/addons/webgl/atlas.js.map +1 -0
  56. package/dist/addons/webgl/box.d.ts +12 -0
  57. package/dist/addons/webgl/box.js +105 -0
  58. package/dist/addons/webgl/box.js.map +1 -0
  59. package/dist/addons/webgl/frame-model.d.ts +28 -0
  60. package/dist/addons/webgl/frame-model.js +105 -0
  61. package/dist/addons/webgl/frame-model.js.map +1 -0
  62. package/dist/addons/webgl/gl-renderer.d.ts +24 -0
  63. package/dist/addons/webgl/gl-renderer.js +211 -0
  64. package/dist/addons/webgl/gl-renderer.js.map +1 -0
  65. package/dist/addons/webgl/webgl-addon.d.ts +42 -0
  66. package/dist/addons/webgl/webgl-addon.js +185 -0
  67. package/dist/addons/webgl/webgl-addon.js.map +1 -0
  68. package/dist/core/attributes.d.ts +53 -0
  69. package/dist/core/attributes.js +75 -0
  70. package/dist/core/attributes.js.map +1 -0
  71. package/dist/core/buffer-line.d.ts +55 -0
  72. package/dist/core/buffer-line.js +242 -0
  73. package/dist/core/buffer-line.js.map +1 -0
  74. package/dist/core/buffer.d.ts +74 -0
  75. package/dist/core/buffer.js +277 -0
  76. package/dist/core/buffer.js.map +1 -0
  77. package/dist/core/charsets.d.ts +8 -0
  78. package/dist/core/charsets.js +79 -0
  79. package/dist/core/charsets.js.map +1 -0
  80. package/dist/core/circular-list.d.ts +22 -0
  81. package/dist/core/circular-list.js +84 -0
  82. package/dist/core/circular-list.js.map +1 -0
  83. package/dist/core/colors.d.ts +25 -0
  84. package/dist/core/colors.js +111 -0
  85. package/dist/core/colors.js.map +1 -0
  86. package/dist/core/event.d.ts +19 -0
  87. package/dist/core/event.js +39 -0
  88. package/dist/core/event.js.map +1 -0
  89. package/dist/core/index.d.ts +11 -0
  90. package/dist/core/index.js +13 -0
  91. package/dist/core/index.js.map +1 -0
  92. package/dist/core/keyboard.d.ts +76 -0
  93. package/dist/core/keyboard.js +249 -0
  94. package/dist/core/keyboard.js.map +1 -0
  95. package/dist/core/parser.d.ts +73 -0
  96. package/dist/core/parser.js +483 -0
  97. package/dist/core/parser.js.map +1 -0
  98. package/dist/core/terminal-core.d.ts +314 -0
  99. package/dist/core/terminal-core.js +1514 -0
  100. package/dist/core/terminal-core.js.map +1 -0
  101. package/dist/core/unicode.d.ts +36 -0
  102. package/dist/core/unicode.js +185 -0
  103. package/dist/core/unicode.js.map +1 -0
  104. package/dist/index.d.ts +25 -0
  105. package/dist/index.js +30 -0
  106. package/dist/index.js.map +1 -0
  107. package/dist/terminal/buffer-api.d.ts +59 -0
  108. package/dist/terminal/buffer-api.js +174 -0
  109. package/dist/terminal/buffer-api.js.map +1 -0
  110. package/dist/terminal/glyphs.d.ts +7 -0
  111. package/dist/terminal/glyphs.js +135 -0
  112. package/dist/terminal/glyphs.js.map +1 -0
  113. package/dist/terminal/i18n/terminal-catalogs.d.ts +15 -0
  114. package/dist/terminal/i18n/terminal-catalogs.js +22 -0
  115. package/dist/terminal/i18n/terminal-catalogs.js.map +1 -0
  116. package/dist/terminal/i18n/terminal-messages.d.ts +32 -0
  117. package/dist/terminal/i18n/terminal-messages.en.d.ts +2 -0
  118. package/dist/terminal/i18n/terminal-messages.en.js +23 -0
  119. package/dist/terminal/i18n/terminal-messages.en.js.map +1 -0
  120. package/dist/terminal/i18n/terminal-messages.es.d.ts +2 -0
  121. package/dist/terminal/i18n/terminal-messages.es.js +23 -0
  122. package/dist/terminal/i18n/terminal-messages.es.js.map +1 -0
  123. package/dist/terminal/i18n/terminal-messages.js +23 -0
  124. package/dist/terminal/i18n/terminal-messages.js.map +1 -0
  125. package/dist/terminal/renderer.d.ts +120 -0
  126. package/dist/terminal/renderer.js +585 -0
  127. package/dist/terminal/renderer.js.map +1 -0
  128. package/dist/terminal/styles.d.ts +2 -0
  129. package/dist/terminal/styles.js +117 -0
  130. package/dist/terminal/styles.js.map +1 -0
  131. package/dist/terminal/terminal-messages.d.ts +2 -0
  132. package/dist/terminal/terminal-messages.js +5 -0
  133. package/dist/terminal/terminal-messages.js.map +1 -0
  134. package/dist/terminal/terminal-view.d.ts +118 -0
  135. package/dist/terminal/terminal-view.js +388 -0
  136. package/dist/terminal/terminal-view.js.map +1 -0
  137. package/dist/terminal/terminal.d.ts +198 -0
  138. package/dist/terminal/terminal.js +1468 -0
  139. package/dist/terminal/terminal.js.map +1 -0
  140. package/dist/terminal/token-theme.d.ts +12 -0
  141. package/dist/terminal/token-theme.js +66 -0
  142. package/dist/terminal/token-theme.js.map +1 -0
  143. package/dist/terminal/types.d.ts +364 -0
  144. package/dist/terminal/types.js +2 -0
  145. package/dist/terminal/types.js.map +1 -0
  146. package/package.json +31 -23
  147. package/fesm2022/trismegisto-terminal.mjs +0 -9717
  148. package/fesm2022/trismegisto-terminal.mjs.map +0 -1
  149. package/types/trismegisto-terminal.d.ts +0 -1952
  150. package/types/trismegisto-terminal.d.ts.map +0 -1
@@ -0,0 +1,1468 @@
1
+ // A classe pública: a API no formato do xterm.js sobre o núcleo deste pacote, com renderização DOM, teclado,
2
+ // mouse, seleção, links, decorações, leitor de tela e complementos.
3
+ import { CircularList } from '../core/circular-list';
4
+ import { ANSI_DEFAULTS, defaultPalette, parseCssColor } from '../core/colors';
5
+ import { DisposableStore, Emitter, toDisposable } from '../core/event';
6
+ import { encodeKey, encodeKittyKey, encodeMouse, encodePaste, encodeWin32Key } from '../core/keyboard';
7
+ import { TerminalCore } from '../core/terminal-core';
8
+ import { BufferApi } from './buffer-api';
9
+ import { DomRenderer } from './renderer';
10
+ import { ensureStyles } from './styles';
11
+ import { DEFAULT_TERMINAL_STRINGS } from './terminal-messages';
12
+ const DEFAULT_OPTIONS = {
13
+ cols: 80,
14
+ rows: 24,
15
+ allowProposedApi: false,
16
+ allowTransparency: false,
17
+ altClickMovesCursor: true,
18
+ convertEol: false,
19
+ cursorBlink: false,
20
+ cursorStyle: 'block',
21
+ cursorWidth: 1,
22
+ cursorInactiveStyle: 'outline',
23
+ customGlyphs: true,
24
+ disableStdin: false,
25
+ drawBoldTextInBrightColors: true,
26
+ fastScrollModifier: 'alt',
27
+ fastScrollSensitivity: 5,
28
+ fontSize: 15,
29
+ fontFamily: 'courier-new, courier, monospace',
30
+ fontWeight: 'normal',
31
+ fontWeightBold: 'bold',
32
+ ignoreBracketedPasteMode: false,
33
+ letterSpacing: 0,
34
+ lineHeight: 1,
35
+ linkHandler: null,
36
+ logLevel: 'info',
37
+ macOptionIsMeta: false,
38
+ macOptionClickForcesSelection: false,
39
+ minimumContrastRatio: 1,
40
+ rightClickSelectsWord: false,
41
+ screenReaderMode: false,
42
+ scrollback: 1000,
43
+ scrollOnEraseInDisplay: false,
44
+ scrollOnUserInput: true,
45
+ scrollSensitivity: 1,
46
+ smoothScrollDuration: 0,
47
+ tabStopWidth: 8,
48
+ theme: {},
49
+ windowsPty: {},
50
+ wordSeparator: ' ()[]{}\',"`',
51
+ blinkIntervalDuration: 0,
52
+ documentOverride: null,
53
+ logger: null,
54
+ mouseEventsRequireAlt: false,
55
+ quirks: {},
56
+ reflowCursorLine: false,
57
+ rescaleOverlappingGlyphs: false,
58
+ scrollbar: {},
59
+ vtExtensions: {},
60
+ windowOptions: {},
61
+ };
62
+ /** Inatividade depois da qual o cursor para de piscar (como no xterm.js). */
63
+ const BLINK_IDLE_MS = 5 * 60 * 1000;
64
+ const THEME_ANSI = [
65
+ 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white',
66
+ 'brightBlack', 'brightRed', 'brightGreen', 'brightYellow', 'brightBlue', 'brightMagenta', 'brightCyan', 'brightWhite',
67
+ ];
68
+ const isMac = () => typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
69
+ class Decoration {
70
+ config;
71
+ element;
72
+ isDisposed = false;
73
+ renderEmitter = new Emitter();
74
+ disposeEmitter = new Emitter();
75
+ onRender = this.renderEmitter.event;
76
+ onDispose = this.disposeEmitter.event;
77
+ options;
78
+ constructor(config) {
79
+ this.config = config;
80
+ this.options = { overviewRulerOptions: config.overviewRulerOptions };
81
+ }
82
+ get marker() {
83
+ return this.config.marker;
84
+ }
85
+ fireRender(el) {
86
+ this.renderEmitter.fire(el);
87
+ }
88
+ dispose() {
89
+ if (this.isDisposed)
90
+ return;
91
+ this.isDisposed = true;
92
+ this.element?.remove();
93
+ this.element = undefined;
94
+ this.disposeEmitter.fire();
95
+ this.renderEmitter.dispose();
96
+ this.disposeEmitter.dispose();
97
+ }
98
+ }
99
+ export class Terminal {
100
+ /** O elemento do terminal, depois do `open`. */
101
+ element;
102
+ /** A área de texto escondida que recebe o foco e o teclado (IME incluído). */
103
+ textarea;
104
+ core;
105
+ store = new DisposableStore();
106
+ resolved;
107
+ options;
108
+ renderer;
109
+ viewport;
110
+ scrollArea;
111
+ a11yTree;
112
+ liveRegion;
113
+ liveText = '';
114
+ liveTimer;
115
+ customKeyHandler;
116
+ customWheelHandler;
117
+ linkProviders = [];
118
+ decorations = [];
119
+ addons = [];
120
+ hoveredLink;
121
+ linkRequest = 0;
122
+ selecting;
123
+ mouseButton = -1;
124
+ lastMouseCell = '';
125
+ composing = false;
126
+ keyHandled = false;
127
+ disposed = false;
128
+ keyEmitter = new Emitter();
129
+ renderEmitter = new Emitter();
130
+ scrollEmitter = new Emitter();
131
+ selectionEmitter = new Emitter();
132
+ bufferEmitter = new Emitter();
133
+ dimensionsEmitter = new Emitter();
134
+ /** As medidas da tela mudaram (fonte, entrelinha, tamanho). */
135
+ onDimensionsChange = this.dimensionsEmitter.event;
136
+ /** Textos que o terminal mesmo usa; troque para traduzir (vale para os terminais abertos depois). */
137
+ static strings = { ...DEFAULT_TERMINAL_STRINGS };
138
+ nextJoinerId = 1;
139
+ blinkTimer;
140
+ smoothTarget = null;
141
+ smoothFrame = 0;
142
+ overviewRuler;
143
+ announcedLines = 0;
144
+ announceWindow = 0;
145
+ onKey = this.keyEmitter.event;
146
+ onRender = this.renderEmitter.event;
147
+ onScroll = this.scrollEmitter.event;
148
+ onSelectionChange = this.selectionEmitter.event;
149
+ buffer;
150
+ parser;
151
+ unicode;
152
+ constructor(options = {}) {
153
+ this.resolved = { ...DEFAULT_OPTIONS, ...stripUndefined(options), theme: { ...(options.theme ?? {}) } };
154
+ this.core = new TerminalCore({
155
+ cols: this.resolved.cols,
156
+ rows: this.resolved.rows,
157
+ scrollback: this.resolved.scrollback,
158
+ tabStopWidth: this.resolved.tabStopWidth,
159
+ convertEol: this.resolved.convertEol,
160
+ scrollOnEraseInDisplay: this.resolved.scrollOnEraseInDisplay,
161
+ cursorStyle: this.resolved.cursorStyle,
162
+ cursorBlink: this.resolved.cursorBlink,
163
+ disableStdin: this.resolved.disableStdin,
164
+ allowSetCursorBlink: !!this.resolved.quirks?.allowSetCursorBlink,
165
+ reflowCursorLine: this.resolved.reflowCursorLine,
166
+ windowsPty: { ...(this.resolved.windowsPty ?? {}) },
167
+ vtExtensions: { ...this.resolved.vtExtensions },
168
+ windowOptions: { ...this.resolved.windowOptions },
169
+ logLevel: this.resolved.logLevel,
170
+ logger: this.resolved.logger,
171
+ });
172
+ this.applyTheme();
173
+ // `terminal.options.fontSize = 16` aplica na hora, como no xterm.
174
+ this.options = new Proxy(this.resolved, {
175
+ set: (target, key, value) => {
176
+ target[key] = value;
177
+ this.applyOption(String(key));
178
+ return true;
179
+ },
180
+ });
181
+ const core = this.core;
182
+ const normal = new BufferApi(() => core.normal);
183
+ const alternate = new BufferApi(() => core.alt);
184
+ this.buffer = {
185
+ get active() {
186
+ return core.buffer === core.normal ? normal : alternate;
187
+ },
188
+ normal,
189
+ alternate,
190
+ onBufferChange: this.bufferEmitter.event,
191
+ };
192
+ this.parser = {
193
+ registerCsiHandler: (id, cb) => core.parser.registerCsiHandler(id, cb),
194
+ registerDcsHandler: (id, cb) => core.parser.registerDcsHandler(id, cb),
195
+ registerEscHandler: (id, cb) => core.parser.registerEscHandler(id, cb),
196
+ registerOscHandler: (ident, cb) => core.parser.registerOscHandler(ident, cb),
197
+ registerApcHandler: (id, cb) => core.parser.registerApcHandler(id, cb),
198
+ };
199
+ const unicode = core.unicode;
200
+ this.unicode = {
201
+ register: (provider) => unicode.register(provider),
202
+ get versions() {
203
+ return unicode.versions;
204
+ },
205
+ get activeVersion() {
206
+ return unicode.activeVersion;
207
+ },
208
+ set activeVersion(version) {
209
+ unicode.activeVersion = version;
210
+ },
211
+ };
212
+ this.store.add(core.onDirty(({ start, end }) => this.renderer?.refreshRows(start, end)));
213
+ this.store.add(core.onScroll((ydisp) => {
214
+ this.syncScrollArea();
215
+ this.scrollEmitter.fire(ydisp);
216
+ }));
217
+ this.store.add(core.onCursorMove(() => {
218
+ this.renderer?.refreshRows(this.core.buffer.y, this.core.buffer.y);
219
+ this.wakeBlink();
220
+ }));
221
+ this.store.add(core.onSelectionChange(() => {
222
+ this.renderer?.refreshRows(0, -1);
223
+ this.selectionEmitter.fire();
224
+ }));
225
+ this.store.add(core.onBufferChange(() => {
226
+ this.syncScrollArea();
227
+ this.bufferEmitter.fire(this.buffer.active);
228
+ }));
229
+ this.store.add(core.onResize(() => {
230
+ this.renderer?.layout();
231
+ this.syncScrollArea();
232
+ }));
233
+ this.store.add(core.onCursorStyleChange(() => this.renderer?.refreshAll()));
234
+ this.store.add(core.onColorsChange(() => {
235
+ this.applyBackground();
236
+ this.renderer?.refreshAll();
237
+ this.renderOverviewRuler();
238
+ }));
239
+ this.store.add(core.onWriteParsed(() => this.announce()));
240
+ }
241
+ // ---------------------------------------------------------------- propriedades
242
+ get cols() {
243
+ return this.core.cols;
244
+ }
245
+ get rows() {
246
+ return this.core.rows;
247
+ }
248
+ get modes() {
249
+ const m = this.core.modes;
250
+ return {
251
+ applicationCursorKeysMode: m.applicationCursorKeysMode,
252
+ applicationKeypadMode: m.applicationKeypadMode,
253
+ bracketedPasteMode: m.bracketedPasteMode,
254
+ insertMode: m.insertMode,
255
+ mouseTrackingMode: m.mouseTrackingMode,
256
+ originMode: m.originMode,
257
+ reverseWraparoundMode: m.reverseWraparoundMode,
258
+ sendFocusMode: m.sendFocusMode,
259
+ showCursor: m.showCursor,
260
+ synchronizedOutputMode: m.synchronizedOutputMode,
261
+ wraparoundMode: m.wraparoundMode,
262
+ };
263
+ }
264
+ /** O elemento das camadas de desenho (linhas, cursor, seleção, decorações), sem o viewport nem a barra. */
265
+ get screenElement() {
266
+ return this.renderer?.screen;
267
+ }
268
+ /** Medidas da tela e da célula; `undefined` antes do `open`. */
269
+ get dimensions() {
270
+ const r = this.renderer;
271
+ if (!r || !r.cellWidth)
272
+ return undefined;
273
+ const dpr = this.element?.ownerDocument.defaultView?.devicePixelRatio || 1;
274
+ const cell = { width: r.cellWidth, height: r.cellHeight };
275
+ const canvas = { width: r.cellWidth * this.cols, height: r.cellHeight * this.rows };
276
+ const charHeight = Math.round((r.cellHeight / this.resolved.lineHeight) * dpr);
277
+ return {
278
+ css: { canvas, cell },
279
+ device: {
280
+ canvas: { width: Math.round(canvas.width * dpr), height: Math.round(canvas.height * dpr) },
281
+ cell: { width: Math.round(cell.width * dpr), height: Math.round(cell.height * dpr) },
282
+ char: {
283
+ width: Math.round((cell.width - this.resolved.letterSpacing) * dpr),
284
+ height: charHeight,
285
+ left: Math.round((this.resolved.letterSpacing * dpr) / 2),
286
+ top: Math.round((cell.height * dpr - charHeight) / 2),
287
+ },
288
+ },
289
+ };
290
+ }
291
+ /**
292
+ * Juntor de caracteres: recebe o texto de cada linha desenhada e devolve faixas `[início, fim)` que viram uma unidade
293
+ * (ligaduras, grafemas). Devolve o id para `deregisterCharacterJoiner`.
294
+ */
295
+ registerCharacterJoiner(handler) {
296
+ const id = this.nextJoinerId++;
297
+ this.pendingJoiners.set(id, handler);
298
+ this.renderer?.joiners.set(id, handler);
299
+ this.renderer?.refreshAll();
300
+ return id;
301
+ }
302
+ deregisterCharacterJoiner(joinerId) {
303
+ this.pendingJoiners.delete(joinerId);
304
+ if (this.renderer?.joiners.delete(joinerId))
305
+ this.renderer.refreshAll();
306
+ }
307
+ pendingJoiners = new Map();
308
+ get markers() {
309
+ return this.core.markers;
310
+ }
311
+ get cellSize() {
312
+ return { width: this.renderer?.cellWidth ?? 0, height: this.renderer?.cellHeight ?? 0 };
313
+ }
314
+ get onData() {
315
+ return this.core.onData;
316
+ }
317
+ get onBinary() {
318
+ return this.core.onBinary;
319
+ }
320
+ get onBell() {
321
+ return this.core.onBell;
322
+ }
323
+ get onTitleChange() {
324
+ return this.core.onTitleChange;
325
+ }
326
+ get onLineFeed() {
327
+ return this.core.onLineFeed;
328
+ }
329
+ get onCursorMove() {
330
+ return this.core.onCursorMove;
331
+ }
332
+ get onResize() {
333
+ return this.core.onResize;
334
+ }
335
+ get onWriteParsed() {
336
+ return this.core.onWriteParsed;
337
+ }
338
+ // ---------------------------------------------------------------- opções e tema
339
+ applyOption(key) {
340
+ const o = this.resolved;
341
+ const core = this.core;
342
+ switch (key) {
343
+ case 'scrollback':
344
+ core.setScrollback(o.scrollback);
345
+ this.syncScrollArea();
346
+ break;
347
+ case 'tabStopWidth':
348
+ case 'convertEol':
349
+ case 'scrollOnEraseInDisplay':
350
+ case 'disableStdin':
351
+ core.options[key] = o[key];
352
+ break;
353
+ case 'cursorStyle':
354
+ case 'cursorBlink':
355
+ core.options[key] = o[key];
356
+ core.modes.cursorBlinkOverride = null;
357
+ this.renderer?.refreshAll();
358
+ break;
359
+ case 'theme':
360
+ this.applyTheme();
361
+ break;
362
+ case 'screenReaderMode':
363
+ this.setupA11y();
364
+ break;
365
+ case 'cols':
366
+ case 'rows':
367
+ this.resize(o.cols, o.rows);
368
+ break;
369
+ case 'quirks':
370
+ core.options.allowSetCursorBlink = !!o.quirks?.allowSetCursorBlink;
371
+ if (!core.options.allowSetCursorBlink)
372
+ core.modes.cursorBlinkOverride = null;
373
+ break;
374
+ case 'reflowCursorLine':
375
+ case 'logLevel':
376
+ case 'logger':
377
+ core.options[key] = o[key];
378
+ break;
379
+ case 'windowsPty':
380
+ core.options.windowsPty = { ...(o.windowsPty ?? {}) };
381
+ break;
382
+ case 'vtExtensions':
383
+ core.options.vtExtensions = { ...o.vtExtensions };
384
+ break;
385
+ case 'windowOptions':
386
+ core.options.windowOptions = { ...o.windowOptions };
387
+ break;
388
+ case 'scrollbar':
389
+ this.applyScrollbar();
390
+ break;
391
+ }
392
+ this.renderer?.setOptions(this.renderOptions());
393
+ this.syncScrollArea();
394
+ }
395
+ applyTheme() {
396
+ const theme = this.resolved.theme ?? {};
397
+ const ansi = THEME_ANSI.map((name, i) => cssOr(theme[name], ANSI_DEFAULTS[i]));
398
+ const palette = defaultPalette(ansi);
399
+ theme.extendedAnsi?.forEach((css, i) => {
400
+ if (16 + i < 256)
401
+ palette[16 + i] = cssOr(css, palette[16 + i]);
402
+ });
403
+ const foreground = cssOr(theme.foreground, 0xffffff);
404
+ const background = cssOr(theme.background, 0x000000);
405
+ this.core.colors.setBase(palette, foreground, background, cssOr(theme.cursor, foreground));
406
+ this.core.notifyColorScheme();
407
+ this.applyBackground();
408
+ this.renderer?.setOptions(this.renderOptions());
409
+ }
410
+ applyBackground() {
411
+ if (!this.element)
412
+ return;
413
+ const { foreground, background } = this.core.colors;
414
+ const hex = (v) => `#${v.toString(16).padStart(6, '0')}`;
415
+ this.element.style.setProperty('--hmt-foreground', hex(foreground));
416
+ this.element.style.setProperty('--hmt-background', this.resolved.allowTransparency && this.resolved.theme.background === 'transparent' ? 'transparent' : hex(background));
417
+ const t = this.resolved.theme;
418
+ if (t.scrollbarSliderBackground)
419
+ this.element.style.setProperty('--hmt-scrollbar', t.scrollbarSliderBackground);
420
+ }
421
+ renderOptions() {
422
+ const o = this.resolved;
423
+ const t = o.theme;
424
+ return {
425
+ fontFamily: o.fontFamily,
426
+ fontSize: o.fontSize,
427
+ fontWeight: o.fontWeight,
428
+ fontWeightBold: o.fontWeightBold,
429
+ lineHeight: o.lineHeight,
430
+ letterSpacing: o.letterSpacing,
431
+ cursorStyle: o.cursorStyle,
432
+ cursorInactiveStyle: o.cursorInactiveStyle,
433
+ cursorWidth: o.cursorWidth,
434
+ cursorBlink: o.cursorBlink,
435
+ drawBoldTextInBrightColors: o.drawBoldTextInBrightColors,
436
+ customGlyphs: o.customGlyphs,
437
+ blinkIntervalDuration: o.blinkIntervalDuration,
438
+ minimumContrastRatio: o.minimumContrastRatio,
439
+ rescaleOverlappingGlyphs: o.rescaleOverlappingGlyphs,
440
+ selectionBackground: t.selectionBackground ?? 'rgba(255, 255, 255, 0.3)',
441
+ selectionForeground: t.selectionForeground,
442
+ selectionInactiveBackground: t.selectionInactiveBackground ?? t.selectionBackground ?? 'rgba(255, 255, 255, 0.2)',
443
+ cursorAccent: t.cursorAccent,
444
+ };
445
+ }
446
+ // ---------------------------------------------------------------- montar na página
447
+ open(parent) {
448
+ if (this.element)
449
+ throw new Error('[hermes-terminal] O terminal já está aberto.');
450
+ const doc = this.resolved.documentOverride ?? parent.ownerDocument;
451
+ ensureStyles(doc);
452
+ const el = doc.createElement('div');
453
+ el.className = 'hmt';
454
+ el.dir = 'ltr';
455
+ this.element = el;
456
+ const viewport = doc.createElement('div');
457
+ viewport.className = 'hmt-viewport';
458
+ const scrollArea = doc.createElement('div');
459
+ scrollArea.className = 'hmt-scroll-area';
460
+ viewport.appendChild(scrollArea);
461
+ el.appendChild(viewport);
462
+ this.viewport = viewport;
463
+ this.scrollArea = scrollArea;
464
+ this.renderer = new DomRenderer(this.core, el, this.renderOptions());
465
+ this.renderer.onOverlays = () => {
466
+ this.renderDecorations();
467
+ this.renderOverviewRuler();
468
+ };
469
+ this.renderer.onMeasured = () => {
470
+ const r = this.renderer;
471
+ this.core.pixelMetrics = { cellWidth: r.cellWidth, cellHeight: r.cellHeight };
472
+ const dims = this.dimensions;
473
+ if (dims)
474
+ this.dimensionsEmitter.fire(dims);
475
+ };
476
+ for (const [id, joiner] of this.pendingJoiners)
477
+ this.renderer.joiners.set(id, joiner);
478
+ this.renderer.onRendered = (start, end) => {
479
+ this.updateA11yRows(start, end);
480
+ this.renderEmitter.fire({ start, end });
481
+ };
482
+ const textarea = doc.createElement('textarea');
483
+ textarea.className = 'hmt-helper-textarea';
484
+ textarea.setAttribute('autocorrect', 'off');
485
+ textarea.setAttribute('autocapitalize', 'off');
486
+ textarea.setAttribute('spellcheck', 'false');
487
+ textarea.setAttribute('tabindex', '0');
488
+ // Nome acessível de `Terminal.strings` (o `hm-terminal` troca pelo do idioma ativo).
489
+ textarea.setAttribute('aria-label', Terminal.strings.promptLabel);
490
+ textarea.setAttribute('aria-multiline', 'false');
491
+ el.appendChild(textarea);
492
+ this.textarea = textarea;
493
+ parent.appendChild(el);
494
+ this.applyBackground();
495
+ this.renderer.measureCell();
496
+ this.setupA11y();
497
+ this.applyScrollbar();
498
+ this.bindEvents();
499
+ this.wakeBlink();
500
+ this.syncScrollArea();
501
+ this.renderer.refreshAll();
502
+ }
503
+ bindEvents() {
504
+ const el = this.element;
505
+ const ta = this.textarea;
506
+ const screen = this.renderer.screen;
507
+ const on = (target, type, fn, opts) => {
508
+ target.addEventListener(type, fn, opts);
509
+ this.store.add(toDisposable(() => target.removeEventListener(type, fn, opts)));
510
+ };
511
+ on(ta, 'keydown', (e) => this.handleKeyDown(e));
512
+ on(ta, 'keyup', (e) => this.handleKeyUp(e));
513
+ on(el, 'mousedown', () => this.wakeBlink());
514
+ on(ta, 'input', (e) => this.handleInput(e));
515
+ on(ta, 'compositionstart', () => (this.composing = true));
516
+ on(ta, 'compositionend', (e) => {
517
+ this.composing = false;
518
+ const data = e.data;
519
+ if (data)
520
+ this.sendUserInput(data);
521
+ ta.value = '';
522
+ });
523
+ on(ta, 'paste', (e) => {
524
+ const text = e.clipboardData?.getData('text/plain');
525
+ e.preventDefault();
526
+ if (text)
527
+ this.paste(text);
528
+ });
529
+ on(ta, 'copy', (e) => this.handleCopy(e));
530
+ on(el, 'copy', (e) => this.handleCopy(e));
531
+ on(ta, 'focus', () => this.setFocused(true));
532
+ on(ta, 'blur', () => this.setFocused(false));
533
+ on(screen, 'mousedown', (e) => this.handleMouseDown(e));
534
+ on(screen, 'mousemove', (e) => this.handleHover(e));
535
+ on(screen, 'mouseleave', (e) => this.clearHoveredLink(e));
536
+ on(screen, 'contextmenu', (e) => {
537
+ if (this.resolved.rightClickSelectsWord)
538
+ this.selectWordAt(e);
539
+ this.textarea?.focus();
540
+ });
541
+ on(el, 'wheel', (e) => this.handleWheel(e), { passive: false });
542
+ on(this.viewport, 'scroll', () => {
543
+ if (!this.renderer?.cellHeight)
544
+ return;
545
+ const b = this.core.buffer;
546
+ const vp = this.viewport;
547
+ // No fim da rolagem, a vista cola no fundo (acompanha a saída nova), seja qual for o arredondamento.
548
+ const atEnd = vp.scrollTop + vp.clientHeight >= vp.scrollHeight - 1;
549
+ const target = atEnd ? b.ybase : Math.max(0, Math.min(b.ybase, Math.round(vp.scrollTop / this.renderer.cellHeight)));
550
+ if (target !== b.ydisp) {
551
+ b.ydisp = target;
552
+ this.renderer.refreshAll();
553
+ this.scrollEmitter.fire(target);
554
+ }
555
+ });
556
+ }
557
+ setFocused(focused) {
558
+ if (!this.renderer)
559
+ return;
560
+ this.renderer.focused = focused;
561
+ this.element?.classList.toggle('hmt-focus', focused);
562
+ if (this.core.modes.sendFocusMode)
563
+ this.core.triggerData(focused ? '\x1b[I' : '\x1b[O', false);
564
+ this.renderer.refreshAll();
565
+ }
566
+ focus() {
567
+ this.textarea?.focus();
568
+ }
569
+ blur() {
570
+ this.textarea?.blur();
571
+ }
572
+ // ---------------------------------------------------------------- teclado
573
+ attachCustomKeyEventHandler(handler) {
574
+ this.customKeyHandler = handler;
575
+ }
576
+ attachCustomWheelEventHandler(handler) {
577
+ this.customWheelHandler = handler;
578
+ }
579
+ handleKeyDown(e) {
580
+ this.keyHandled = false;
581
+ if (this.customKeyHandler && this.customKeyHandler(e) === false)
582
+ return;
583
+ if (this.composing || e.isComposing || e.key === 'Process' || e.keyCode === 229)
584
+ return;
585
+ this.wakeBlink();
586
+ // Protocolos estendidos pedidos pelo processo: win32-input-mode e o teclado do kitty.
587
+ const extended = this.extendedKey(e, 'keydown');
588
+ if (extended !== null) {
589
+ e.preventDefault();
590
+ this.keyHandled = true;
591
+ if (extended) {
592
+ this.keyEmitter.fire({ key: extended, domEvent: e });
593
+ this.sendUserInput(extended);
594
+ }
595
+ return;
596
+ }
597
+ const result = encodeKey(e, {
598
+ applicationCursorKeys: this.core.modes.applicationCursorKeysMode,
599
+ applicationKeypad: this.core.modes.applicationKeypadMode,
600
+ macOptionIsMeta: this.resolved.macOptionIsMeta,
601
+ isMac: isMac(),
602
+ });
603
+ // Shift+PageUp/PageDown/Home/End rolam a vista (atalhos do xterm), não vão para o processo.
604
+ if (e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey && this.core.buffer === this.core.normal) {
605
+ const page = this.rows - 1;
606
+ const scroll = { PageUp: -page, PageDown: page }[e.key];
607
+ if (scroll) {
608
+ this.scrollLines(scroll);
609
+ e.preventDefault();
610
+ return;
611
+ }
612
+ }
613
+ if (!result.data)
614
+ return;
615
+ this.keyHandled = true;
616
+ if (result.cancel || result.data.length === 1)
617
+ e.preventDefault();
618
+ this.keyEmitter.fire({ key: result.data, domEvent: e });
619
+ this.sendUserInput(result.data);
620
+ }
621
+ handleKeyUp(e) {
622
+ if (this.customKeyHandler && this.customKeyHandler(e) === false)
623
+ return;
624
+ const extended = this.extendedKey(e, 'keyup');
625
+ if (extended) {
626
+ e.preventDefault();
627
+ this.sendUserInput(extended, false);
628
+ }
629
+ }
630
+ /** Codificação nos protocolos estendidos; `null` = segue o teclado legado, `''` = engole a tecla. */
631
+ extendedKey(e, type) {
632
+ const input = {
633
+ key: e.key,
634
+ ctrlKey: e.ctrlKey,
635
+ altKey: e.altKey,
636
+ shiftKey: e.shiftKey,
637
+ metaKey: e.metaKey,
638
+ type,
639
+ repeat: e.repeat,
640
+ code: e.code,
641
+ keyCode: e.keyCode,
642
+ location: e.location,
643
+ capsLock: e.getModifierState?.('CapsLock') ?? false,
644
+ numLock: e.getModifierState?.('NumLock') ?? false,
645
+ };
646
+ if (this.core.modes.win32InputMode)
647
+ return encodeWin32Key(input);
648
+ const flags = this.core.kittyKeyboardFlags;
649
+ if (flags)
650
+ return encodeKittyKey(input, flags);
651
+ return null;
652
+ }
653
+ /** Texto que chega sem `keydown` útil (teclado virtual, ditado): vai como digitado. */
654
+ handleInput(e) {
655
+ const ta = this.textarea;
656
+ if (this.composing || e.isComposing)
657
+ return;
658
+ if (!this.keyHandled && e.inputType === 'insertText' && e.data)
659
+ this.sendUserInput(e.data);
660
+ this.keyHandled = false;
661
+ ta.value = '';
662
+ }
663
+ sendUserInput(data, clearSelection = true) {
664
+ if (this.resolved.disableStdin)
665
+ return;
666
+ if (this.resolved.scrollOnUserInput)
667
+ this.scrollToBottom();
668
+ if (clearSelection)
669
+ this.core.clearSelection();
670
+ this.core.triggerData(data, true);
671
+ }
672
+ handleCopy(e) {
673
+ if (!this.hasSelection())
674
+ return;
675
+ e.clipboardData?.setData('text/plain', this.getSelection());
676
+ e.preventDefault();
677
+ }
678
+ /** Manda dados como se o usuário tivesse digitado (`wasUserInput` false: não rola nem limpa a seleção). */
679
+ input(data, wasUserInput = true) {
680
+ if (wasUserInput)
681
+ this.sendUserInput(data);
682
+ else
683
+ this.core.triggerData(data, false);
684
+ }
685
+ paste(data) {
686
+ const bracketed = this.core.modes.bracketedPasteMode && !this.resolved.ignoreBracketedPasteMode;
687
+ this.sendUserInput(encodePaste(data, bracketed));
688
+ }
689
+ // ---------------------------------------------------------------- mouse
690
+ mouseReportingActive(e, wheel = false) {
691
+ if (this.core.modes.mouseTrackingMode === 'none')
692
+ return false;
693
+ // `mouseEventsRequireAlt`: cliques e movimento só vão para o processo com Alt (a roda não muda).
694
+ if (this.resolved.mouseEventsRequireAlt && !wheel)
695
+ return e.altKey;
696
+ // Shift (ou Option no macOS, se ligado) força a seleção mesmo com o processo pedindo o mouse.
697
+ if (e.shiftKey)
698
+ return false;
699
+ if (isMac() && e.altKey && this.resolved.macOptionClickForcesSelection)
700
+ return false;
701
+ return true;
702
+ }
703
+ reportMouse(e, button, action) {
704
+ const { col, row } = this.renderer.cellAt(e.clientX, e.clientY);
705
+ const mode = this.core.modes.mouseTrackingMode;
706
+ if (mode === 'x10' && action !== 'press')
707
+ return;
708
+ if (action === 'move') {
709
+ if (mode !== 'drag' && mode !== 'any')
710
+ return;
711
+ if (mode === 'drag' && this.mouseButton < 0)
712
+ return;
713
+ const key = `${col},${row}`;
714
+ if (key === this.lastMouseCell)
715
+ return;
716
+ this.lastMouseCell = key;
717
+ }
718
+ const rect = this.renderer.screen.getBoundingClientRect();
719
+ const encoding = this.core.modes.mouseEncoding;
720
+ const data = encodeMouse({
721
+ button: action === 'move' && button < 0 ? 3 : button,
722
+ action,
723
+ col: col + 1,
724
+ row: row + 1,
725
+ shift: e.shiftKey,
726
+ // Com `mouseEventsRequireAlt`, o Alt é o gesto de liberar o mouse, não um modificador do relatório.
727
+ alt: e.altKey && !this.resolved.mouseEventsRequireAlt,
728
+ ctrl: e.ctrlKey,
729
+ px: Math.max(1, Math.round(e.clientX - rect.left) + 1),
730
+ py: Math.max(1, Math.round(e.clientY - rect.top) + 1),
731
+ }, encoding);
732
+ // No formato clássico, coordenadas acima de 223 viram bytes que não são UTF-8: vão como binário.
733
+ if (encoding === 'default' && (col + 1 > 223 || row + 1 > 223))
734
+ this.core.triggerBinary(data);
735
+ else
736
+ this.core.triggerData(data, true);
737
+ }
738
+ handleMouseDown(e) {
739
+ const doc = this.element.ownerDocument;
740
+ this.textarea?.focus({ preventScroll: true });
741
+ if (this.mouseReportingActive(e)) {
742
+ const button = e.button === 1 ? 1 : e.button === 2 ? 2 : 0;
743
+ this.mouseButton = button;
744
+ this.reportMouse(e, button, 'press');
745
+ e.preventDefault();
746
+ const move = (ev) => this.reportMouse(ev, this.mouseButton, 'move');
747
+ const up = (ev) => {
748
+ this.reportMouse(ev, this.mouseButton, 'release');
749
+ this.mouseButton = -1;
750
+ doc.removeEventListener('mousemove', move);
751
+ doc.removeEventListener('mouseup', up);
752
+ };
753
+ doc.addEventListener('mousemove', move);
754
+ doc.addEventListener('mouseup', up);
755
+ return;
756
+ }
757
+ if (e.button !== 0)
758
+ return;
759
+ e.preventDefault();
760
+ const point = this.bufferPoint(e, true);
761
+ const mode = e.detail >= 3 ? 'line' : e.detail === 2 ? 'word' : 'char';
762
+ if (mode === 'char' && e.shiftKey && this.core.selection) {
763
+ this.selecting = { anchor: { ...this.core.selection.start }, mode, moved: true };
764
+ this.extendSelection(point);
765
+ }
766
+ else {
767
+ this.selecting = { anchor: point, mode, moved: false };
768
+ if (mode === 'char')
769
+ this.core.clearSelection();
770
+ else
771
+ this.extendSelection(point);
772
+ }
773
+ const move = (ev) => {
774
+ if (!this.selecting)
775
+ return;
776
+ this.selecting.moved = true;
777
+ const { row } = this.renderer.edgeAt(ev.clientX, ev.clientY);
778
+ if (row < 0)
779
+ this.scrollLines(-1);
780
+ else if (row >= this.rows)
781
+ this.scrollLines(1);
782
+ this.extendSelection(this.bufferPoint(ev, true));
783
+ };
784
+ const up = (ev) => {
785
+ const state = this.selecting;
786
+ this.selecting = undefined;
787
+ doc.removeEventListener('mousemove', move);
788
+ doc.removeEventListener('mouseup', up);
789
+ if (state && state.mode === 'char' && !state.moved) {
790
+ this.activateLinkAt(ev);
791
+ if (ev.altKey && this.resolved.altClickMovesCursor)
792
+ this.moveCursorTo(ev);
793
+ }
794
+ };
795
+ doc.addEventListener('mousemove', move);
796
+ doc.addEventListener('mouseup', up);
797
+ }
798
+ /** Ponto do buffer (coluna/linha absoluta) sob o mouse. */
799
+ bufferPoint(e, edge) {
800
+ const r = this.renderer;
801
+ const { col, row } = edge ? r.edgeAt(e.clientX, e.clientY) : r.cellAt(e.clientX, e.clientY);
802
+ const b = this.core.buffer;
803
+ const y = Math.max(0, Math.min(b.lines.length - 1, b.ydisp + Math.max(0, Math.min(this.rows - 1, row))));
804
+ return { x: col, y };
805
+ }
806
+ extendSelection(point) {
807
+ const state = this.selecting;
808
+ const a = state.anchor;
809
+ if (state.mode === 'char') {
810
+ this.core.setSelection(a, point);
811
+ return;
812
+ }
813
+ const [first, last] = a.y < point.y || (a.y === point.y && a.x <= point.x) ? [a, point] : [point, a];
814
+ if (state.mode === 'line') {
815
+ this.core.setSelection({ x: 0, y: this.logicalStart(first.y) }, { x: this.cols, y: this.logicalEnd(last.y) });
816
+ return;
817
+ }
818
+ const start = this.wordBounds(first.x, first.y)[0];
819
+ const end = this.wordBounds(Math.max(0, last.x - (last === point && last !== a ? 1 : 0)), last.y)[1];
820
+ this.core.setSelection(start, end);
821
+ }
822
+ logicalStart(y) {
823
+ const lines = this.core.buffer.lines;
824
+ while (y > 0 && lines.get(y)?.isWrapped)
825
+ y--;
826
+ return y;
827
+ }
828
+ logicalEnd(y) {
829
+ const lines = this.core.buffer.lines;
830
+ while (y + 1 < lines.length && lines.get(y + 1)?.isWrapped)
831
+ y++;
832
+ return y;
833
+ }
834
+ /** Limites da palavra em `(x, y)`: de separador a separador, atravessando quebras automáticas. */
835
+ wordBounds(x, y) {
836
+ const lines = this.core.buffer.lines;
837
+ const cols = this.cols;
838
+ const sep = this.resolved.wordSeparator;
839
+ const charAt = (cx, cy) => {
840
+ const line = lines.get(cy);
841
+ if (!line)
842
+ return ' ';
843
+ const chars = line.getChars(cx);
844
+ return line.getWidth(cx) === 0 ? 'wide' : chars || ' ';
845
+ };
846
+ const isWord = (cx, cy) => {
847
+ const c = charAt(cx, cy);
848
+ return c === 'wide' || !sep.includes(c);
849
+ };
850
+ if (!isWord(x, y))
851
+ return [{ x, y }, { x: x + 1, y }];
852
+ let sx = x;
853
+ let sy = y;
854
+ while (true) {
855
+ if (sx > 0 && isWord(sx - 1, sy))
856
+ sx--;
857
+ else if (sx === 0 && sy > 0 && lines.get(sy)?.isWrapped && isWord(cols - 1, sy - 1)) {
858
+ sy--;
859
+ sx = cols - 1;
860
+ }
861
+ else
862
+ break;
863
+ }
864
+ let ex = x;
865
+ let ey = y;
866
+ while (true) {
867
+ if (ex < cols - 1 && isWord(ex + 1, ey))
868
+ ex++;
869
+ else if (ex === cols - 1 && lines.get(ey + 1)?.isWrapped && isWord(0, ey + 1)) {
870
+ ey++;
871
+ ex = 0;
872
+ }
873
+ else
874
+ break;
875
+ }
876
+ if (lines.get(ey)?.getWidth(ex) === 2)
877
+ ex++;
878
+ return [{ x: sx, y: sy }, { x: ex + 1, y: ey }];
879
+ }
880
+ selectWordAt(e) {
881
+ const point = this.bufferPoint(e, false);
882
+ const [start, end] = this.wordBounds(point.x, point.y);
883
+ this.core.setSelection(start, end);
884
+ }
885
+ /** Alt+clique: move o cursor do prompt até o ponto com setas (como o xterm faz). */
886
+ moveCursorTo(e) {
887
+ if (this.core.buffer !== this.core.normal)
888
+ return;
889
+ const target = this.bufferPoint(e, false);
890
+ const b = this.core.buffer;
891
+ const from = (b.ybase + b.y) * this.cols + b.x;
892
+ const to = target.y * this.cols + target.x;
893
+ const delta = to - from;
894
+ if (!delta)
895
+ return;
896
+ const app = this.core.modes.applicationCursorKeysMode;
897
+ const arrow = `\x1b${app ? 'O' : '['}${delta > 0 ? 'C' : 'D'}`;
898
+ this.sendUserInput(arrow.repeat(Math.abs(delta)));
899
+ }
900
+ handleWheel(e) {
901
+ if (this.customWheelHandler && this.customWheelHandler(e) === false)
902
+ return;
903
+ const cellHeight = this.renderer?.cellHeight || 16;
904
+ const unit = e.deltaMode === 1 ? 1 : e.deltaMode === 2 ? this.rows : 1 / cellHeight;
905
+ const fast = (this.resolved.fastScrollModifier === 'alt' && e.altKey) ||
906
+ (this.resolved.fastScrollModifier === 'ctrl' && e.ctrlKey) ||
907
+ (this.resolved.fastScrollModifier === 'shift' && e.shiftKey);
908
+ const sensitivity = fast ? this.resolved.fastScrollSensitivity : this.resolved.scrollSensitivity;
909
+ const raw = e.deltaY * unit * sensitivity;
910
+ const lines = raw > 0 ? Math.max(1, Math.round(raw)) : raw < 0 ? Math.min(-1, Math.round(raw)) : 0;
911
+ if (!lines)
912
+ return;
913
+ if (this.mouseReportingActive(e, true) && this.core.modes.mouseTrackingMode !== 'x10') {
914
+ for (let i = 0; i < Math.abs(lines); i++)
915
+ this.reportMouse(e, lines < 0 ? 64 : 65, 'press');
916
+ e.preventDefault();
917
+ return;
918
+ }
919
+ // Tela alternativa sem mouse: a roda vira setas (o less e o vim rolam assim).
920
+ if (this.core.buffer === this.core.alt) {
921
+ const app = this.core.modes.applicationCursorKeysMode;
922
+ this.core.triggerData(`\x1b${app ? 'O' : '['}${lines < 0 ? 'A' : 'B'}`.repeat(Math.abs(lines)), true);
923
+ e.preventDefault();
924
+ return;
925
+ }
926
+ const b = this.core.buffer;
927
+ if ((lines < 0 && b.ydisp > 0) || (lines > 0 && b.ydisp < b.ybase))
928
+ e.preventDefault();
929
+ if (this.resolved.smoothScrollDuration > 0)
930
+ this.smoothScrollBy(lines);
931
+ else
932
+ this.scrollLines(lines);
933
+ }
934
+ /** Rolagem suave: anda até o alvo ao longo de `smoothScrollDuration`, linha a linha (a grade é por linhas). */
935
+ smoothScrollBy(lines) {
936
+ const b = this.core.buffer;
937
+ const start = b.ydisp;
938
+ this.smoothTarget = Math.max(0, Math.min(b.ybase, (this.smoothTarget ?? start) + lines));
939
+ const target = this.smoothTarget;
940
+ const win = this.element?.ownerDocument.defaultView;
941
+ if (!win?.requestAnimationFrame) {
942
+ this.smoothTarget = null;
943
+ this.scrollLines(target - start);
944
+ return;
945
+ }
946
+ win.cancelAnimationFrame(this.smoothFrame);
947
+ const duration = this.resolved.smoothScrollDuration;
948
+ const began = win.performance.now();
949
+ const step = (now) => {
950
+ const t = Math.min(1, (now - began) / duration);
951
+ const eased = 1 - (1 - t) ** 3;
952
+ const next = Math.round(start + (target - start) * eased);
953
+ this.scrollLines(next - this.core.buffer.ydisp);
954
+ if (t < 1)
955
+ this.smoothFrame = win.requestAnimationFrame(step);
956
+ else
957
+ this.smoothTarget = null;
958
+ };
959
+ this.smoothFrame = win.requestAnimationFrame(step);
960
+ }
961
+ // ---------------------------------------------------------------- barra de rolagem e régua
962
+ applyScrollbar() {
963
+ const el = this.element;
964
+ if (!el)
965
+ return;
966
+ const sb = this.resolved.scrollbar ?? {};
967
+ const show = sb.showScrollbar !== false;
968
+ el.classList.toggle('hmt-no-scrollbar', !show);
969
+ el.classList.toggle('hmt-scrollbar-sized', show && sb.width !== undefined);
970
+ el.classList.toggle('hmt-scrollbar-arrows', show && !!sb.showArrows);
971
+ if (sb.width !== undefined)
972
+ el.style.setProperty('--hmt-scrollbar-width', `${sb.width}px`);
973
+ else
974
+ el.style.removeProperty('--hmt-scrollbar-width');
975
+ // A régua de visão geral liga com `width` (como no xterm.js) e mostra as decorações que pedem uma marca.
976
+ const ruler = show && sb.width !== undefined;
977
+ if (ruler && !this.overviewRuler) {
978
+ this.overviewRuler = el.ownerDocument.createElement('div');
979
+ this.overviewRuler.className = 'hmt-overview-ruler';
980
+ this.overviewRuler.setAttribute('aria-hidden', 'true');
981
+ el.appendChild(this.overviewRuler);
982
+ }
983
+ else if (!ruler && this.overviewRuler) {
984
+ this.overviewRuler.remove();
985
+ this.overviewRuler = undefined;
986
+ }
987
+ if (this.overviewRuler) {
988
+ this.overviewRuler.classList.toggle('hmt-ruler-top', !!sb.overviewRuler?.showTopBorder);
989
+ this.overviewRuler.classList.toggle('hmt-ruler-bottom', !!sb.overviewRuler?.showBottomBorder);
990
+ const border = this.resolved.theme.overviewRulerBorder;
991
+ if (border)
992
+ this.overviewRuler.style.setProperty('--hmt-ruler-border', border);
993
+ }
994
+ this.renderOverviewRuler();
995
+ this.syncScrollArea();
996
+ }
997
+ renderOverviewRuler() {
998
+ const ruler = this.overviewRuler;
999
+ if (!ruler)
1000
+ return;
1001
+ ruler.textContent = '';
1002
+ const b = this.core.buffer;
1003
+ if (b !== this.core.normal)
1004
+ return;
1005
+ const total = Math.max(1, b.lines.length);
1006
+ const doc = ruler.ownerDocument;
1007
+ for (const decoration of this.decorations) {
1008
+ const o = decoration.options.overviewRulerOptions;
1009
+ if (!o || decoration.marker.isDisposed)
1010
+ continue;
1011
+ const mark = doc.createElement('div');
1012
+ mark.className = 'hmt-ruler-mark';
1013
+ const lines = decoration.config.height ?? 1;
1014
+ mark.style.top = `${(decoration.marker.line / total) * 100}%`;
1015
+ mark.style.height = `${Math.max((lines / total) * 100, 0.4)}%`;
1016
+ const position = o.position ?? 'full';
1017
+ mark.style.left = position === 'right' ? '66%' : position === 'center' ? '33%' : '0';
1018
+ mark.style.width = position === 'full' ? '100%' : '34%';
1019
+ mark.style.background = o.color;
1020
+ ruler.appendChild(mark);
1021
+ }
1022
+ }
1023
+ /** Volta a piscar e agenda a parada por inatividade (5 minutos). */
1024
+ wakeBlink() {
1025
+ const r = this.renderer;
1026
+ if (!r)
1027
+ return;
1028
+ if (r.blinkIdle) {
1029
+ r.blinkIdle = false;
1030
+ r.refreshRows(0, -1);
1031
+ }
1032
+ clearTimeout(this.blinkTimer);
1033
+ this.blinkTimer = setTimeout(() => {
1034
+ r.blinkIdle = true;
1035
+ r.refreshRows(0, -1);
1036
+ }, BLINK_IDLE_MS);
1037
+ }
1038
+ // ---------------------------------------------------------------- links
1039
+ registerLinkProvider(provider) {
1040
+ this.linkProviders.push(provider);
1041
+ return toDisposable(() => {
1042
+ const index = this.linkProviders.indexOf(provider);
1043
+ if (index >= 0)
1044
+ this.linkProviders.splice(index, 1);
1045
+ });
1046
+ }
1047
+ handleHover(e) {
1048
+ if (this.selecting || !this.renderer || this.mouseButton >= 0)
1049
+ return;
1050
+ const point = this.bufferPoint(e, false);
1051
+ const hovered = this.hoveredLink;
1052
+ if (hovered && hovered.ranges.some((r) => r.y === point.y && point.x >= r.start && point.x < r.end))
1053
+ return;
1054
+ this.clearHoveredLink(e);
1055
+ const request = ++this.linkRequest;
1056
+ this.findLink(point, (link) => {
1057
+ if (request !== this.linkRequest || !link)
1058
+ return;
1059
+ const ranges = rangesOf(link.range, this.cols);
1060
+ this.hoveredLink = { link, ranges };
1061
+ const decorations = link.decorations ?? { pointerCursor: true, underline: true };
1062
+ if (decorations.underline)
1063
+ this.renderer.linkRanges = ranges;
1064
+ this.element?.classList.toggle('hmt-link-hover', decorations.pointerCursor);
1065
+ this.renderer.refreshRows(0, -1);
1066
+ link.hover?.(e, link.text);
1067
+ });
1068
+ }
1069
+ clearHoveredLink(e) {
1070
+ const hovered = this.hoveredLink;
1071
+ if (!hovered)
1072
+ return;
1073
+ this.hoveredLink = undefined;
1074
+ this.element?.classList.remove('hmt-link-hover');
1075
+ if (this.renderer) {
1076
+ this.renderer.linkRanges = [];
1077
+ this.renderer.refreshRows(0, -1);
1078
+ }
1079
+ hovered.link.leave?.(e, hovered.link.text);
1080
+ }
1081
+ activateLinkAt(e) {
1082
+ const point = this.bufferPoint(e, false);
1083
+ const hovered = this.hoveredLink;
1084
+ if (hovered && hovered.ranges.some((r) => r.y === point.y && point.x >= r.start && point.x < r.end)) {
1085
+ hovered.link.activate(e, hovered.link.text);
1086
+ return;
1087
+ }
1088
+ this.findLink(point, (link) => link?.activate(e, link.text));
1089
+ }
1090
+ /** Procura o link sob `point`: primeiro os hiperlinks OSC 8, depois os provedores, na ordem de registro. */
1091
+ findLink(point, done) {
1092
+ const osc = this.hyperlinkAt(point);
1093
+ if (osc)
1094
+ return done(osc);
1095
+ const providers = [...this.linkProviders];
1096
+ const next = (i) => {
1097
+ if (i >= providers.length)
1098
+ return done(undefined);
1099
+ providers[i].provideLinks(point.y + 1, (links) => {
1100
+ const hit = links?.find((link) => contains(link.range, point.x + 1, point.y + 1));
1101
+ if (hit)
1102
+ done(hit);
1103
+ else
1104
+ next(i + 1);
1105
+ });
1106
+ };
1107
+ next(0);
1108
+ }
1109
+ hyperlinkAt(point) {
1110
+ const line = this.core.buffer.lines.get(point.y);
1111
+ if (!line)
1112
+ return undefined;
1113
+ const id = line.getExtended(point.x).linkId;
1114
+ if (!id)
1115
+ return undefined;
1116
+ const link = this.core.linkFor(line.getExtended(point.x));
1117
+ if (!link)
1118
+ return undefined;
1119
+ let start = point.x;
1120
+ let end = point.x;
1121
+ while (start > 0 && line.getExtended(start - 1).linkId === id)
1122
+ start--;
1123
+ while (end < line.length - 1 && line.getExtended(end + 1).linkId === id)
1124
+ end++;
1125
+ const uri = link.uri;
1126
+ return {
1127
+ range: { start: { x: start + 1, y: point.y + 1 }, end: { x: end + 1, y: point.y + 1 } },
1128
+ text: uri,
1129
+ activate: (event) => this.openLink(event, uri, { start: { x: start + 1, y: point.y + 1 }, end: { x: end + 1, y: point.y + 1 } }),
1130
+ };
1131
+ }
1132
+ openLink(event, uri, range) {
1133
+ const handler = this.resolved.linkHandler;
1134
+ if (handler) {
1135
+ const http = /^https?:/i.test(uri);
1136
+ if (http || handler.allowNonHttpProtocols)
1137
+ handler.activate(event, uri, range);
1138
+ return;
1139
+ }
1140
+ if (!/^https?:/i.test(uri))
1141
+ return;
1142
+ const win = this.element?.ownerDocument.defaultView;
1143
+ win?.open(uri, '_blank', 'noopener,noreferrer');
1144
+ }
1145
+ // ---------------------------------------------------------------- marcadores e decorações
1146
+ registerMarker(cursorYOffset = 0) {
1147
+ return this.core.registerMarker(cursorYOffset);
1148
+ }
1149
+ registerDecoration(options) {
1150
+ if (options.marker.isDisposed)
1151
+ return undefined;
1152
+ const decoration = new Decoration(options);
1153
+ this.decorations.push(decoration);
1154
+ const sub = options.marker.onDispose(() => decoration.dispose());
1155
+ decoration.onDispose(() => {
1156
+ sub.dispose();
1157
+ const index = this.decorations.indexOf(decoration);
1158
+ if (index >= 0)
1159
+ this.decorations.splice(index, 1);
1160
+ });
1161
+ this.renderer?.refreshRows(0, -1);
1162
+ this.renderOverviewRuler();
1163
+ return decoration;
1164
+ }
1165
+ renderDecorations() {
1166
+ const r = this.renderer;
1167
+ if (!r)
1168
+ return;
1169
+ const b = this.core.buffer;
1170
+ for (const decoration of this.decorations) {
1171
+ const o = decoration.config;
1172
+ const y = o.marker.line - b.ydisp;
1173
+ const visible = b === this.core.normal && y >= 0 && y < this.rows;
1174
+ if (!visible) {
1175
+ if (decoration.element)
1176
+ decoration.element.style.display = 'none';
1177
+ continue;
1178
+ }
1179
+ let el = decoration.element;
1180
+ if (!el) {
1181
+ el = this.element.ownerDocument.createElement('div');
1182
+ el.className = 'hmt-decoration';
1183
+ decoration.element = el;
1184
+ (o.layer === 'top' ? r.decorationsTop : r.decorationsBottom).appendChild(el);
1185
+ }
1186
+ el.style.display = '';
1187
+ el.style.top = `${y * r.cellHeight}px`;
1188
+ el.style.height = `${(o.height ?? 1) * r.cellHeight}px`;
1189
+ el.style.width = `${(o.width ?? 1) * r.cellWidth}px`;
1190
+ const x = (o.x ?? 0) * r.cellWidth;
1191
+ if (o.anchor === 'right') {
1192
+ el.style.right = `${x}px`;
1193
+ el.style.left = '';
1194
+ }
1195
+ else {
1196
+ el.style.left = `${x}px`;
1197
+ el.style.right = '';
1198
+ }
1199
+ if (o.backgroundColor)
1200
+ el.style.backgroundColor = o.backgroundColor;
1201
+ if (o.foregroundColor)
1202
+ el.style.color = o.foregroundColor;
1203
+ decoration.fireRender(el);
1204
+ }
1205
+ }
1206
+ // ---------------------------------------------------------------- leitor de tela
1207
+ setupA11y() {
1208
+ const el = this.element;
1209
+ if (!el)
1210
+ return;
1211
+ if (!this.resolved.screenReaderMode) {
1212
+ this.a11yTree?.remove();
1213
+ this.liveRegion?.remove();
1214
+ this.a11yTree = this.liveRegion = undefined;
1215
+ return;
1216
+ }
1217
+ if (this.a11yTree)
1218
+ return;
1219
+ const doc = el.ownerDocument;
1220
+ this.a11yTree = doc.createElement('div');
1221
+ this.a11yTree.className = 'hmt-a11y-tree';
1222
+ this.a11yTree.setAttribute('role', 'list');
1223
+ this.liveRegion = doc.createElement('div');
1224
+ this.liveRegion.className = 'hmt-a11y-live';
1225
+ this.liveRegion.setAttribute('aria-live', 'polite');
1226
+ this.liveRegion.setAttribute('aria-atomic', 'false');
1227
+ el.appendChild(this.a11yTree);
1228
+ el.appendChild(this.liveRegion);
1229
+ this.updateA11yRows(0, this.rows - 1);
1230
+ }
1231
+ updateA11yRows(start, end) {
1232
+ const tree = this.a11yTree;
1233
+ if (!tree)
1234
+ return;
1235
+ const doc = tree.ownerDocument;
1236
+ while (tree.children.length < this.rows) {
1237
+ const row = doc.createElement('div');
1238
+ row.setAttribute('role', 'listitem');
1239
+ tree.appendChild(row);
1240
+ }
1241
+ while (tree.children.length > this.rows)
1242
+ tree.lastElementChild.remove();
1243
+ const b = this.core.buffer;
1244
+ for (let y = start; y <= end && y < this.rows; y++) {
1245
+ const line = b.lines.get(b.ydisp + y);
1246
+ const text = line ? line.translateToString(true) : '';
1247
+ const row = tree.children[y];
1248
+ row.textContent = text || ' ';
1249
+ row.setAttribute('aria-posinset', String(b.ydisp + y + 1));
1250
+ row.setAttribute('aria-setsize', String(b.lines.length));
1251
+ }
1252
+ }
1253
+ /** Anuncia o que foi escrito (o leitor de tela lê a região viva), em lotes. */
1254
+ announce() {
1255
+ if (!this.liveRegion)
1256
+ return;
1257
+ const b = this.core.buffer;
1258
+ const line = b.lines.get(b.ybase + b.y);
1259
+ const text = line?.translateToString(true) ?? '';
1260
+ if (!text || text === this.liveText)
1261
+ return;
1262
+ // Muitas linhas num instante: o leitor de tela não acompanha; avisa uma vez (`Terminal.strings.tooMuchOutput`).
1263
+ const now = Date.now();
1264
+ if (now - this.announceWindow > 1000) {
1265
+ this.announceWindow = now;
1266
+ this.announcedLines = 0;
1267
+ }
1268
+ if (++this.announcedLines > 20) {
1269
+ if (this.announcedLines === 21) {
1270
+ this.liveText = Terminal.strings.tooMuchOutput;
1271
+ clearTimeout(this.liveTimer);
1272
+ this.liveTimer = setTimeout(() => {
1273
+ if (this.liveRegion)
1274
+ this.liveRegion.textContent = this.liveText;
1275
+ }, 50);
1276
+ }
1277
+ return;
1278
+ }
1279
+ this.liveText = text;
1280
+ clearTimeout(this.liveTimer);
1281
+ this.liveTimer = setTimeout(() => {
1282
+ if (this.liveRegion)
1283
+ this.liveRegion.textContent = this.liveText;
1284
+ }, 50);
1285
+ }
1286
+ // ---------------------------------------------------------------- escrita e tamanho
1287
+ write(data, callback) {
1288
+ this.core.write(data, callback);
1289
+ }
1290
+ writeln(data, callback) {
1291
+ this.core.write(data);
1292
+ this.core.write('\r\n', callback);
1293
+ }
1294
+ resize(columns, rows) {
1295
+ if (!Number.isFinite(columns) || !Number.isFinite(rows))
1296
+ return;
1297
+ this.core.resize(columns, rows);
1298
+ this.resolved.cols = this.core.cols;
1299
+ this.resolved.rows = this.core.rows;
1300
+ }
1301
+ refresh(start, end) {
1302
+ this.renderer?.refreshRows(start, end);
1303
+ }
1304
+ /** Para a renderização por textura do xterm; aqui a renderização é DOM e não há o que limpar. */
1305
+ clearTextureAtlas() { }
1306
+ reset() {
1307
+ this.core.reset();
1308
+ this.syncScrollArea();
1309
+ this.renderer?.refreshAll();
1310
+ }
1311
+ /** Apaga tudo, deixando a linha do cursor (o prompt) como a primeira. */
1312
+ clear() {
1313
+ const core = this.core;
1314
+ const b = core.buffer;
1315
+ if (b !== core.normal)
1316
+ return;
1317
+ const keep = b.lines.get(b.ybase + b.y);
1318
+ const keptLine = b.ybase + b.y;
1319
+ b.lines = new CircularList(b.lines.maxLength);
1320
+ b.lines.push(keep);
1321
+ b.ybase = 0;
1322
+ b.ydisp = 0;
1323
+ b.y = 0;
1324
+ b.fillViewport();
1325
+ for (const marker of [...core.markers]) {
1326
+ if (marker.line === keptLine)
1327
+ marker.line = 0;
1328
+ else
1329
+ marker.dispose();
1330
+ }
1331
+ core.clearSelection();
1332
+ this.syncScrollArea();
1333
+ this.renderer?.refreshAll();
1334
+ this.scrollEmitter.fire(0);
1335
+ }
1336
+ // ---------------------------------------------------------------- rolagem
1337
+ scrollLines(amount) {
1338
+ const b = this.core.buffer;
1339
+ const target = Math.max(0, Math.min(b.ybase, b.ydisp + Math.trunc(amount)));
1340
+ if (target === b.ydisp)
1341
+ return;
1342
+ b.ydisp = target;
1343
+ this.syncScrollArea();
1344
+ this.renderer?.refreshAll();
1345
+ this.scrollEmitter.fire(target);
1346
+ }
1347
+ scrollPages(pageCount) {
1348
+ this.scrollLines(pageCount * (this.rows - 1));
1349
+ }
1350
+ scrollToTop() {
1351
+ this.scrollLines(-this.core.buffer.ydisp);
1352
+ }
1353
+ scrollToBottom() {
1354
+ const b = this.core.buffer;
1355
+ this.scrollLines(b.ybase - b.ydisp);
1356
+ }
1357
+ scrollToLine(line) {
1358
+ this.scrollLines(line - this.core.buffer.ydisp);
1359
+ }
1360
+ syncScrollArea() {
1361
+ const r = this.renderer;
1362
+ if (!r || !this.viewport || !this.scrollArea)
1363
+ return;
1364
+ const b = this.core.buffer;
1365
+ // O viewport pode ser mais alto que as linhas (sobra de pixels do ajuste): a área tem a altura dele mais o
1366
+ // histórico, para o `scrollTop` máximo cair exatamente no fim. Com `linhas × célula`, o navegador limita o
1367
+ // `scrollTop` abaixo do fim, o arredondamento descola a vista do fundo e a saída nova some embaixo.
1368
+ const viewportHeight = this.viewport.clientHeight || this.rows * r.cellHeight;
1369
+ this.scrollArea.style.height = `${(b.lines.length - this.rows) * r.cellHeight + viewportHeight}px`;
1370
+ const top = b.ydisp * r.cellHeight;
1371
+ if (Math.abs(this.viewport.scrollTop - top) >= 1)
1372
+ this.viewport.scrollTop = top;
1373
+ }
1374
+ // ---------------------------------------------------------------- seleção
1375
+ hasSelection() {
1376
+ return this.core.hasSelection();
1377
+ }
1378
+ getSelection() {
1379
+ return this.core.getSelection();
1380
+ }
1381
+ /** Posição da seleção, a partir de 1; `end` é exclusivo. */
1382
+ getSelectionPosition() {
1383
+ const s = this.core.selection;
1384
+ if (!s)
1385
+ return undefined;
1386
+ return { start: { x: s.start.x + 1, y: s.start.y + 1 }, end: { x: s.end.x + 1, y: s.end.y + 1 } };
1387
+ }
1388
+ clearSelection() {
1389
+ this.core.clearSelection();
1390
+ }
1391
+ select(column, row, length) {
1392
+ this.core.select(column, row, length);
1393
+ }
1394
+ selectAll() {
1395
+ this.core.selectAll();
1396
+ }
1397
+ selectLines(start, end) {
1398
+ this.core.selectLines(start, end);
1399
+ }
1400
+ // ---------------------------------------------------------------- complementos e descarte
1401
+ loadAddon(addon) {
1402
+ this.addons.push(addon);
1403
+ addon.activate(this);
1404
+ }
1405
+ dispose() {
1406
+ if (this.disposed)
1407
+ return;
1408
+ this.disposed = true;
1409
+ for (const addon of this.addons.splice(0))
1410
+ addon.dispose();
1411
+ for (const decoration of [...this.decorations])
1412
+ decoration.dispose();
1413
+ clearTimeout(this.liveTimer);
1414
+ clearTimeout(this.blinkTimer);
1415
+ this.element?.ownerDocument.defaultView?.cancelAnimationFrame?.(this.smoothFrame);
1416
+ this.dimensionsEmitter.dispose();
1417
+ this.store.dispose();
1418
+ this.renderer?.dispose();
1419
+ this.element?.remove();
1420
+ this.core.dispose();
1421
+ for (const emitter of [this.keyEmitter, this.renderEmitter, this.scrollEmitter, this.selectionEmitter, this.bufferEmitter])
1422
+ emitter.dispose();
1423
+ }
1424
+ /** Só para os testes e para o componente Angular: desenha já o que está pendente. */
1425
+ renderNow() {
1426
+ this.renderer?.renderNow();
1427
+ }
1428
+ /**
1429
+ * Partes internas para os complementos deste pacote (imagens, renderizador WebGL…). Não é API pública estável:
1430
+ * fora do pacote, use a API no formato do xterm.js.
1431
+ */
1432
+ get _internals() {
1433
+ return {
1434
+ core: this.core,
1435
+ renderer: this.renderer,
1436
+ element: this.element,
1437
+ onFrame: (listener) => {
1438
+ this.renderer?.frameListeners.add(listener);
1439
+ return toDisposable(() => this.renderer?.frameListeners.delete(listener));
1440
+ },
1441
+ refreshAll: () => this.renderer?.refreshAll(),
1442
+ };
1443
+ }
1444
+ }
1445
+ function cssOr(css, fallback) {
1446
+ if (!css)
1447
+ return fallback;
1448
+ return parseCssColor(css) ?? fallback;
1449
+ }
1450
+ function stripUndefined(value) {
1451
+ return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
1452
+ }
1453
+ function contains(range, x, y) {
1454
+ const after = y > range.start.y || (y === range.start.y && x >= range.start.x);
1455
+ const before = y < range.end.y || (y === range.end.y && x <= range.end.x);
1456
+ return after && before;
1457
+ }
1458
+ /** Faixa 1-based e inclusiva → faixas por linha, 0-based, `end` exclusivo. */
1459
+ function rangesOf(range, cols) {
1460
+ const out = [];
1461
+ for (let y = range.start.y; y <= range.end.y; y++) {
1462
+ const start = y === range.start.y ? range.start.x - 1 : 0;
1463
+ const end = y === range.end.y ? range.end.x : cols;
1464
+ out.push({ y: y - 1, start, end });
1465
+ }
1466
+ return out;
1467
+ }
1468
+ //# sourceMappingURL=terminal.js.map