@adecore/terminal 0.31.12 → 0.33.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.
@@ -1,4 +1,3 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
1
  import { useEffect, useImperativeHandle, useRef } from 'react';
3
2
  import clsx from 'clsx';
4
3
  import { FitAddon } from '@xterm/addon-fit';
@@ -7,192 +6,242 @@ import { readTerminalFont, readTerminalTheme } from './theme.js';
7
6
  import { bindTerminalLinks } from './links.js';
8
7
  import { webglBudget } from './webgl-budget.js';
9
8
  import { fitToHost, followAncestorScale } from './xterm-internals.js';
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
10
  const RESIZE_DEBOUNCE_MS = 50;
11
11
  /* What the theme and the font are read from: the theme attribute and the tokens an app sets inline on `<html>`. */
12
12
  const ROOT_ATTRIBUTES = ['data-theme', 'style', 'class'];
13
13
  let terminals = 0;
14
14
  /* A terminal on xterm.js that fits its container and follows the theme. The app feeds it through the handle. */
15
- export function TerminalView({ ref, onData, onResize, onOpenLink, onLinkHover, fontSize = 13, lineHeight = 1, readOnly = false, convertEol = false, webgl = false, scaledByAncestor = false, label, className }) {
16
- const hostRef = useRef(null);
17
- const live = useRef(null);
18
- // Filled with the first props, so the mount reads them before the effect below brings them up to date.
19
- const latest = useRef({ onData, onResize, onOpenLink, onLinkHover, fontSize, lineHeight, scaledByAncestor });
20
- useEffect(() => {
21
- latest.current = { onData, onResize, onOpenLink, onLinkHover, fontSize, lineHeight, scaledByAncestor };
15
+ export function TerminalView({
16
+ ref,
17
+ onData,
18
+ onResize,
19
+ onOpenLink,
20
+ onLinkHover,
21
+ fontSize = 13,
22
+ lineHeight = 1,
23
+ readOnly = false,
24
+ convertEol = false,
25
+ webgl = false,
26
+ scaledByAncestor = false,
27
+ label,
28
+ className
29
+ }) {
30
+ const hostRef = useRef(null);
31
+ const live = useRef(null);
32
+ // Filled with the first props, so the mount reads them before the effect below brings them up to date.
33
+ const latest = useRef({
34
+ onData,
35
+ onResize,
36
+ onOpenLink,
37
+ onLinkHover,
38
+ fontSize,
39
+ lineHeight,
40
+ scaledByAncestor
41
+ });
42
+ useEffect(() => {
43
+ latest.current = {
44
+ onData,
45
+ onResize,
46
+ onOpenLink,
47
+ onLinkHover,
48
+ fontSize,
49
+ lineHeight,
50
+ scaledByAncestor
51
+ };
52
+ });
53
+ useImperativeHandle(ref, () => ({
54
+ get terminal() {
55
+ return live.current?.term ?? null;
56
+ },
57
+ write: (data, done) => {
58
+ const current = live.current;
59
+ if (!current) {
60
+ return;
61
+ }
62
+ current.term.write(data, done);
63
+ if (current.webgl) {
64
+ // A terminal that is being written to outranks an idle one when contexts are scarce.
65
+ webglBudget.touch(current.id);
66
+ }
67
+ },
68
+ // Through the parser (RIS), since `Terminal.reset()` runs at once and output still queued would land on the fresh screen.
69
+ reset: () => live.current?.term.write('\x1bc'),
70
+ focus: () => {
71
+ live.current?.term.focus();
72
+ if (live.current?.webgl) {
73
+ webglBudget.focus(live.current.id);
74
+ }
75
+ },
76
+ blur: () => {
77
+ live.current?.term.blur();
78
+ if (live.current?.webgl) {
79
+ webglBudget.blur(live.current.id);
80
+ }
81
+ },
82
+ paste: text => live.current?.term.paste(text),
83
+ selectAll: () => live.current?.term.selectAll(),
84
+ selection: () => live.current?.term.getSelection() ?? '',
85
+ size: () => ({
86
+ cols: live.current?.term.cols ?? 80,
87
+ rows: live.current?.term.rows ?? 24
88
+ }),
89
+ visibleText: () => {
90
+ const term = live.current?.term;
91
+ if (!term) {
92
+ return '';
93
+ }
94
+ const buffer = term.buffer.active;
95
+ const lines = [];
96
+ for (let row = 0; row < term.rows; row++) {
97
+ lines.push(buffer.getLine(buffer.viewportY + row)?.translateToString(true) ?? '');
98
+ }
99
+ return lines.join('\n').replace(/\s+$/, '');
100
+ },
101
+ followGrid: size => live.current?.followGrid(size)
102
+ }), []);
103
+ useEffect(() => {
104
+ const host = hostRef.current;
105
+ if (!host) {
106
+ return;
107
+ }
108
+ const initial = latest.current;
109
+ const term_0 = new Terminal({
110
+ theme: readTerminalTheme(),
111
+ fontFamily: readTerminalFont(),
112
+ fontSize: initial.fontSize,
113
+ lineHeight: initial.lineHeight,
114
+ cursorBlink: true,
115
+ scrollback: 5000,
116
+ macOptionIsMeta: true
22
117
  });
23
- useImperativeHandle(ref, () => ({
24
- get terminal() {
25
- return live.current?.term ?? null;
26
- },
27
- write: (data, done) => {
28
- const current = live.current;
29
- if (!current) {
30
- return;
31
- }
32
- current.term.write(data, done);
33
- if (current.webgl) {
34
- // A terminal that is being written to outranks an idle one when contexts are scarce.
35
- webglBudget.touch(current.id);
36
- }
37
- },
38
- // Through the parser (RIS), since `Terminal.reset()` runs at once and output still queued would land on the fresh screen.
39
- reset: () => live.current?.term.write('\x1bc'),
40
- focus: () => {
41
- live.current?.term.focus();
42
- if (live.current?.webgl) {
43
- webglBudget.focus(live.current.id);
44
- }
45
- },
46
- blur: () => {
47
- live.current?.term.blur();
48
- if (live.current?.webgl) {
49
- webglBudget.blur(live.current.id);
50
- }
51
- },
52
- paste: (text) => live.current?.term.paste(text),
53
- selectAll: () => live.current?.term.selectAll(),
54
- selection: () => live.current?.term.getSelection() ?? '',
55
- size: () => ({ cols: live.current?.term.cols ?? 80, rows: live.current?.term.rows ?? 24 }),
56
- visibleText: () => {
57
- const term = live.current?.term;
58
- if (!term) {
59
- return '';
60
- }
61
- const buffer = term.buffer.active;
62
- const lines = [];
63
- for (let row = 0; row < term.rows; row++) {
64
- lines.push(buffer.getLine(buffer.viewportY + row)?.translateToString(true) ?? '');
65
- }
66
- return lines.join('\n').replace(/\s+$/, '');
67
- },
68
- followGrid: (size) => live.current?.followGrid(size)
69
- }), []);
70
- useEffect(() => {
71
- const host = hostRef.current;
72
- if (!host) {
73
- return;
74
- }
75
- const initial = latest.current;
76
- const term = new Terminal({
77
- theme: readTerminalTheme(),
78
- fontFamily: readTerminalFont(),
79
- fontSize: initial.fontSize,
80
- lineHeight: initial.lineHeight,
81
- cursorBlink: true,
82
- scrollback: 5000,
83
- macOptionIsMeta: true
84
- });
85
- const fit = new FitAddon();
86
- term.loadAddon(fit);
87
- term.open(host);
88
- const disposeLinks = bindTerminalLinks(term, () => latest.current);
89
- if (initial.scaledByAncestor) {
90
- followAncestorScale(term);
91
- }
92
- /*
93
- * The grid this terminal fits and tells the program, and the grid the program has. They part while
94
- * another client sizes the same program; this one then draws that grid, clipped or with room to
95
- * spare, until a fit here changes the grid and claims it back. Null until a fit had room.
96
- */
97
- let claimed = fitToHost(term, fit) ? { cols: term.cols, rows: term.rows } : null;
98
- let shared = claimed;
99
- const drawShared = () => {
100
- if (shared !== null && (term.cols !== shared.cols || term.rows !== shared.rows)) {
101
- term.resize(shared.cols, shared.rows);
102
- }
103
- };
104
- // A resize, a font change and a renderer swap all land here: WebGL and the DOM measure a glyph
105
- // differently, so a swap can change how many cells fit.
106
- const refit = () => {
107
- if (!fitToHost(term, fit)) {
108
- return;
109
- }
110
- if (claimed === null || term.cols !== claimed.cols || term.rows !== claimed.rows) {
111
- claimed = { cols: term.cols, rows: term.rows };
112
- shared = claimed;
113
- latest.current.onResize?.(claimed.cols, claimed.rows);
114
- }
115
- drawShared();
116
- };
117
- let theme = JSON.stringify(term.options.theme);
118
- const restyle = (size, height) => {
119
- const next = readTerminalTheme();
120
- // A fresh theme object repaints every cell, so only a different one is handed over.
121
- if (JSON.stringify(next) !== theme) {
122
- theme = JSON.stringify(next);
123
- term.options.theme = next;
124
- }
125
- term.options.fontFamily = readTerminalFont();
126
- term.options.fontSize = size;
127
- term.options.lineHeight = height;
128
- // A new glyph size changes how many cells fit; the resize observer only hears the host.
129
- refit();
118
+ const fit = new FitAddon();
119
+ term_0.loadAddon(fit);
120
+ term_0.open(host);
121
+ const disposeLinks = bindTerminalLinks(term_0, () => latest.current);
122
+ if (initial.scaledByAncestor) {
123
+ followAncestorScale(term_0);
124
+ }
125
+ /*
126
+ * The grid this terminal fits and tells the program, and the grid the program has. They part while
127
+ * another client sizes the same program; this one then draws that grid, clipped or with room to
128
+ * spare, until a fit here changes the grid and claims it back. Null until a fit had room.
129
+ */
130
+ let claimed = fitToHost(term_0, fit) ? {
131
+ cols: term_0.cols,
132
+ rows: term_0.rows
133
+ } : null;
134
+ let shared = claimed;
135
+ const drawShared = () => {
136
+ if (shared !== null && (term_0.cols !== shared.cols || term_0.rows !== shared.rows)) {
137
+ term_0.resize(shared.cols, shared.rows);
138
+ }
139
+ };
140
+ // A resize, a font change and a renderer swap all land here: WebGL and the DOM measure a glyph
141
+ // differently, so a swap can change how many cells fit.
142
+ const refit = () => {
143
+ if (!fitToHost(term_0, fit)) {
144
+ return;
145
+ }
146
+ if (claimed === null || term_0.cols !== claimed.cols || term_0.rows !== claimed.rows) {
147
+ claimed = {
148
+ cols: term_0.cols,
149
+ rows: term_0.rows
130
150
  };
131
- const id = `terminal-${++terminals}`;
132
- let releaseWebgl = null;
133
- const current = {
134
- term,
135
- refit,
136
- restyle,
137
- followGrid: (size) => {
138
- shared = size;
139
- drawShared();
140
- },
141
- setInput: (readOnly, convertEol) => {
142
- term.options.disableStdin = readOnly;
143
- term.options.cursorBlink = !readOnly;
144
- term.options.convertEol = convertEol;
145
- },
146
- setWebgl: (on) => {
147
- current.webgl = on;
148
- if (on && releaseWebgl === null) {
149
- releaseWebgl = webglBudget.register(id, term, refit);
150
- }
151
- else if (!on && releaseWebgl !== null) {
152
- releaseWebgl();
153
- releaseWebgl = null;
154
- }
155
- },
156
- webgl: false,
157
- id
158
- };
159
- live.current = current;
160
- const data = term.onData((input) => latest.current.onData?.(input));
161
- let timer = null;
162
- const resizes = new ResizeObserver(() => {
163
- if (timer !== null) {
164
- window.clearTimeout(timer);
165
- }
166
- timer = window.setTimeout(() => {
167
- timer = null;
168
- refit();
169
- }, RESIZE_DEBOUNCE_MS);
170
- });
171
- resizes.observe(host);
172
- const themes = new MutationObserver(() => restyle(latest.current.fontSize, latest.current.lineHeight));
173
- themes.observe(document.documentElement, { attributes: true, attributeFilter: ROOT_ATTRIBUTES });
174
- return () => {
175
- if (timer !== null) {
176
- window.clearTimeout(timer);
177
- }
178
- resizes.disconnect();
179
- themes.disconnect();
180
- data.dispose();
181
- // The context goes back before the terminal is gone, so the next one can take it.
182
- current.setWebgl(false);
183
- disposeLinks();
184
- term.dispose();
185
- live.current = null;
186
- };
187
- }, []);
188
- useEffect(() => {
189
- live.current?.restyle(fontSize, lineHeight);
190
- }, [fontSize, lineHeight]);
191
- useEffect(() => {
192
- live.current?.setInput(readOnly, convertEol);
193
- }, [readOnly, convertEol]);
194
- useEffect(() => {
195
- live.current?.setWebgl(webgl);
196
- }, [webgl]);
197
- return (_jsx("div", { className: clsx('terminal-view', className), role: label === undefined ? undefined : 'region', "aria-label": label, children: _jsx("div", { ref: hostRef, className: "terminal-view-host" }) }));
198
- }
151
+ shared = claimed;
152
+ latest.current.onResize?.(claimed.cols, claimed.rows);
153
+ }
154
+ drawShared();
155
+ };
156
+ let theme = JSON.stringify(term_0.options.theme);
157
+ const restyle = (size_0, height) => {
158
+ const next = readTerminalTheme();
159
+ // A fresh theme object repaints every cell, so only a different one is handed over.
160
+ if (JSON.stringify(next) !== theme) {
161
+ theme = JSON.stringify(next);
162
+ term_0.options.theme = next;
163
+ }
164
+ term_0.options.fontFamily = readTerminalFont();
165
+ term_0.options.fontSize = size_0;
166
+ term_0.options.lineHeight = height;
167
+ // A new glyph size changes how many cells fit; the resize observer only hears the host.
168
+ refit();
169
+ };
170
+ const id = `terminal-${++terminals}`;
171
+ let releaseWebgl = null;
172
+ const current_0 = {
173
+ term: term_0,
174
+ refit,
175
+ restyle,
176
+ followGrid: size_1 => {
177
+ shared = size_1;
178
+ drawShared();
179
+ },
180
+ setInput: (readOnly_0, convertEol_0) => {
181
+ term_0.options.disableStdin = readOnly_0;
182
+ term_0.options.cursorBlink = !readOnly_0;
183
+ term_0.options.convertEol = convertEol_0;
184
+ },
185
+ setWebgl: on => {
186
+ current_0.webgl = on;
187
+ if (on && releaseWebgl === null) {
188
+ releaseWebgl = webglBudget.register(id, term_0, refit);
189
+ } else if (!on && releaseWebgl !== null) {
190
+ releaseWebgl();
191
+ releaseWebgl = null;
192
+ }
193
+ },
194
+ webgl: false,
195
+ id
196
+ };
197
+ live.current = current_0;
198
+ const data_0 = term_0.onData(input => latest.current.onData?.(input));
199
+ let timer = null;
200
+ const resizes = new ResizeObserver(() => {
201
+ if (timer !== null) {
202
+ window.clearTimeout(timer);
203
+ }
204
+ timer = window.setTimeout(() => {
205
+ timer = null;
206
+ refit();
207
+ }, RESIZE_DEBOUNCE_MS);
208
+ });
209
+ resizes.observe(host);
210
+ const themes = new MutationObserver(() => restyle(latest.current.fontSize, latest.current.lineHeight));
211
+ themes.observe(document.documentElement, {
212
+ attributes: true,
213
+ attributeFilter: ROOT_ATTRIBUTES
214
+ });
215
+ return () => {
216
+ if (timer !== null) {
217
+ window.clearTimeout(timer);
218
+ }
219
+ resizes.disconnect();
220
+ themes.disconnect();
221
+ data_0.dispose();
222
+ // The context goes back before the terminal is gone, so the next one can take it.
223
+ current_0.setWebgl(false);
224
+ disposeLinks();
225
+ term_0.dispose();
226
+ live.current = null;
227
+ };
228
+ }, []);
229
+ useEffect(() => {
230
+ live.current?.restyle(fontSize, lineHeight);
231
+ }, [fontSize, lineHeight]);
232
+ useEffect(() => {
233
+ live.current?.setInput(readOnly, convertEol);
234
+ }, [readOnly, convertEol]);
235
+ useEffect(() => {
236
+ live.current?.setWebgl(webgl);
237
+ }, [webgl]);
238
+ return /*#__PURE__*/_jsx("div", {
239
+ className: clsx('terminal-view', className),
240
+ role: label === undefined ? undefined : 'region',
241
+ "aria-label": label,
242
+ children: /*#__PURE__*/_jsx("div", {
243
+ ref: hostRef,
244
+ className: "terminal-view-host"
245
+ })
246
+ });
247
+ }
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { TerminalView } from './TerminalView.js';
1
+ export { TerminalView } from "./TerminalView.js";
2
2
  export { webglTerminals } from './webgl-budget.js';
3
- export { linkLineBounds } from './links.js';
3
+ export { linkLineBounds } from './links.js';
package/dist/links.js CHANGED
@@ -1,70 +1,82 @@
1
1
  import { WebLinksAddon } from '@xterm/addon-web-links';
2
2
  export function linkLineBounds(range, grid, screen, pointerY) {
3
- if (screen.width <= 0 || screen.height <= 0) {
4
- return null;
5
- }
6
- const cellWidth = screen.width / grid.cols;
7
- const cellHeight = screen.height / grid.rows;
8
- const row = Math.max(range.start.y, Math.min(range.end.y, grid.viewportY + Math.floor((pointerY - screen.top) / cellHeight) + 1));
9
- const start = row === range.start.y ? range.start.x : 1;
10
- const end = row === range.end.y ? range.end.x : grid.cols;
11
- return {
12
- x: screen.left + (start - 1) * cellWidth,
13
- y: screen.top + (row - grid.viewportY - 1) * cellHeight,
14
- width: (end - start + 1) * cellWidth,
15
- height: cellHeight
16
- };
3
+ if (screen.width <= 0 || screen.height <= 0) {
4
+ return null;
5
+ }
6
+ const cellWidth = screen.width / grid.cols;
7
+ const cellHeight = screen.height / grid.rows;
8
+ const row = Math.max(range.start.y, Math.min(range.end.y, grid.viewportY + Math.floor((pointerY - screen.top) / cellHeight) + 1));
9
+ const start = row === range.start.y ? range.start.x : 1;
10
+ const end = row === range.end.y ? range.end.x : grid.cols;
11
+ return {
12
+ x: screen.left + (start - 1) * cellWidth,
13
+ y: screen.top + (row - grid.viewportY - 1) * cellHeight,
14
+ width: (end - start + 1) * cellWidth,
15
+ height: cellHeight
16
+ };
17
17
  }
18
18
  export function bindTerminalLinks(term, callbacks) {
19
- const element = term.element;
20
- let press = null;
21
- const rememberPress = (event) => {
22
- press = event.button === 0 ? { x: event.clientX, y: event.clientY } : null;
23
- };
24
- const cancelPress = () => {
25
- press = null;
26
- };
27
- const activate = (event, uri) => {
28
- const start = press;
29
- press = null;
30
- // xterm 6 activates on mouseup, including selection drags and non-primary buttons.
31
- if (!start || event.button !== 0 || event.defaultPrevented || term.hasSelection() || Math.hypot(event.clientX - start.x, event.clientY - start.y) > 3) {
32
- return;
33
- }
34
- // OSC 8 targets and detected URLs share the same web-only boundary.
35
- if (!/^https?:\/\//i.test(uri) || !URL.canParse(uri)) {
36
- return;
37
- }
38
- const open = callbacks().onOpenLink;
39
- if (open) {
40
- open(uri, event);
41
- }
42
- else {
43
- // Shells that deny new windows need the target in the initial request.
44
- window.open(uri, '_blank', 'noopener,noreferrer');
45
- }
46
- };
47
- const hover = (event, uri, range) => {
48
- const screen = element.querySelector('.xterm-screen')?.getBoundingClientRect();
49
- // Screen bounds include canvas zoom; xterm ranges are one-based buffer coordinates, including scrollback.
50
- const bounds = screen
51
- ? linkLineBounds(range, { cols: term.cols, rows: term.rows, viewportY: term.buffer.active.viewportY }, screen, event.clientY)
52
- : null;
53
- callbacks().onLinkHover?.(bounds ? uri : null, bounds);
54
- };
55
- const leave = () => callbacks().onLinkHover?.(null, null);
56
- const previous = term.options.linkHandler;
57
- term.options.linkHandler = { activate, hover, leave, allowNonHttpProtocols: false };
58
- const addon = new WebLinksAddon(activate, { hover, leave });
59
- term.loadAddon(addon);
60
- element.addEventListener('mousedown', rememberPress, true);
61
- element.addEventListener('pointercancel', cancelPress);
62
- element.addEventListener('mouseleave', cancelPress);
63
- return () => {
64
- element.removeEventListener('mousedown', rememberPress, true);
65
- element.removeEventListener('pointercancel', cancelPress);
66
- element.removeEventListener('mouseleave', cancelPress);
67
- term.options.linkHandler = previous;
68
- addon.dispose();
69
- };
70
- }
19
+ const element = term.element;
20
+ let press = null;
21
+ const rememberPress = event => {
22
+ press = event.button === 0 ? {
23
+ x: event.clientX,
24
+ y: event.clientY
25
+ } : null;
26
+ };
27
+ const cancelPress = () => {
28
+ press = null;
29
+ };
30
+ const activate = (event, uri) => {
31
+ const start = press;
32
+ press = null;
33
+ // xterm 6 activates on mouseup, including selection drags and non-primary buttons.
34
+ if (!start || event.button !== 0 || event.defaultPrevented || term.hasSelection() || Math.hypot(event.clientX - start.x, event.clientY - start.y) > 3) {
35
+ return;
36
+ }
37
+ // OSC 8 targets and detected URLs share the same web-only boundary.
38
+ if (!/^https?:\/\//i.test(uri) || !URL.canParse(uri)) {
39
+ return;
40
+ }
41
+ const open = callbacks().onOpenLink;
42
+ if (open) {
43
+ open(uri, event);
44
+ } else {
45
+ // Shells that deny new windows need the target in the initial request.
46
+ window.open(uri, '_blank', 'noopener,noreferrer');
47
+ }
48
+ };
49
+ const hover = (event, uri, range) => {
50
+ const screen = element.querySelector('.xterm-screen')?.getBoundingClientRect();
51
+ // Screen bounds include canvas zoom; xterm ranges are one-based buffer coordinates, including scrollback.
52
+ const bounds = screen ? linkLineBounds(range, {
53
+ cols: term.cols,
54
+ rows: term.rows,
55
+ viewportY: term.buffer.active.viewportY
56
+ }, screen, event.clientY) : null;
57
+ callbacks().onLinkHover?.(bounds ? uri : null, bounds);
58
+ };
59
+ const leave = () => callbacks().onLinkHover?.(null, null);
60
+ const previous = term.options.linkHandler;
61
+ term.options.linkHandler = {
62
+ activate,
63
+ hover,
64
+ leave,
65
+ allowNonHttpProtocols: false
66
+ };
67
+ const addon = new WebLinksAddon(activate, {
68
+ hover,
69
+ leave
70
+ });
71
+ term.loadAddon(addon);
72
+ element.addEventListener('mousedown', rememberPress, true);
73
+ element.addEventListener('pointercancel', cancelPress);
74
+ element.addEventListener('mouseleave', cancelPress);
75
+ return () => {
76
+ element.removeEventListener('mousedown', rememberPress, true);
77
+ element.removeEventListener('pointercancel', cancelPress);
78
+ element.removeEventListener('mouseleave', cancelPress);
79
+ term.options.linkHandler = previous;
80
+ addon.dispose();
81
+ };
82
+ }
package/dist/theme.js CHANGED
@@ -1,20 +1,20 @@
1
1
  const ANSI = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'];
2
2
  const token = (style, name) => style.getPropertyValue(name).trim();
3
- const brightKey = (name) => `bright${name[0].toUpperCase()}${name.slice(1)}`;
3
+ const brightKey = name => `bright${name[0].toUpperCase()}${name.slice(1)}`;
4
4
  /* xterm takes literal colors, so the tokens are resolved from the root on every theme change. */
5
5
  export const readTerminalTheme = () => {
6
- const style = getComputedStyle(document.documentElement);
7
- const theme = {
8
- background: token(style, '--term-bg'),
9
- foreground: token(style, '--term-fg'),
10
- cursor: token(style, '--term-cursor'),
11
- cursorAccent: token(style, '--term-bg'),
12
- selectionBackground: token(style, '--selection')
13
- };
14
- for (const name of ANSI) {
15
- theme[name] = token(style, `--term-ansi-${name}`);
16
- theme[brightKey(name)] = token(style, `--term-ansi-bright-${name}`);
17
- }
18
- return theme;
6
+ const style = getComputedStyle(document.documentElement);
7
+ const theme = {
8
+ background: token(style, '--term-bg'),
9
+ foreground: token(style, '--term-fg'),
10
+ cursor: token(style, '--term-cursor'),
11
+ cursorAccent: token(style, '--term-bg'),
12
+ selectionBackground: token(style, '--selection')
13
+ };
14
+ for (const name of ANSI) {
15
+ theme[name] = token(style, `--term-ansi-${name}`);
16
+ theme[brightKey(name)] = token(style, `--term-ansi-bright-${name}`);
17
+ }
18
+ return theme;
19
19
  };
20
- export const readTerminalFont = () => token(getComputedStyle(document.documentElement), '--font-mono');
20
+ export const readTerminalFont = () => token(getComputedStyle(document.documentElement), '--font-mono');
@@ -6,18 +6,18 @@ let Addon = null;
6
6
  let addonLoad = null;
7
7
  /* Probed once for the page; the probe context is released so it does not count against the browser's cap. */
8
8
  const hasWebgl2 = () => {
9
- if (webgl2Available === null) {
10
- const context = document.createElement('canvas').getContext('webgl2');
11
- webgl2Available = context !== null;
12
- context?.getExtension('WEBGL_lose_context')?.loseContext();
13
- }
14
- return webgl2Available;
9
+ if (webgl2Available === null) {
10
+ const context = document.createElement('canvas').getContext('webgl2');
11
+ webgl2Available = context !== null;
12
+ context?.getExtension('WEBGL_lose_context')?.loseContext();
13
+ }
14
+ return webgl2Available;
15
15
  };
16
16
  /* The canvas the addon just added. xterm names the canvas of every render layer it owns
17
17
  (`xterm-link-layer`); the WebGL one is the nameless one. */
18
- const rendererCanvas = (term) => {
19
- const canvases = term.element?.querySelectorAll('.xterm-screen canvas') ?? [];
20
- return [...canvases].filter((canvas) => canvas.classList.length === 0).at(-1) ?? null;
18
+ const rendererCanvas = term => {
19
+ const canvases = term.element?.querySelectorAll('.xterm-screen canvas') ?? [];
20
+ return [...canvases].filter(canvas => canvas.classList.length === 0).at(-1) ?? null;
21
21
  };
22
22
  /**
23
23
  * Keeps the number of live WebGL renderers under the cap, however many terminals a page shows.
@@ -26,118 +26,123 @@ const rendererCanvas = (term) => {
26
26
  * `WebglSlots` decides who holds one, this class loads and disposes the addons.
27
27
  */
28
28
  class WebglBudget {
29
- slots = new WebglSlots(DEFAULT_WEBGL_CONTEXTS);
30
- entries = new Map();
31
- /* A terminal that mounted visibly asks for a context. The returned function gives it back. */
32
- register(id, term, refit) {
33
- const entry = { term, refit, addon: null, canvas: null, frame: null };
34
- this.entries.set(id, entry);
35
- if (hasWebgl2()) {
36
- this.apply(this.slots.request(id));
37
- }
38
- return () => {
39
- if (this.entries.get(id) !== entry) {
40
- return;
41
- }
42
- this.entries.delete(id);
43
- // The context goes back before the next terminal asks for one, never after.
44
- this.drop(entry);
45
- this.apply(this.slots.release(id));
46
- };
47
- }
48
- focus(id) {
49
- this.apply(this.slots.focus(id));
29
+ slots = new WebglSlots(DEFAULT_WEBGL_CONTEXTS);
30
+ entries = new Map();
31
+ /* A terminal that mounted visibly asks for a context. The returned function gives it back. */
32
+ register(id, term, refit) {
33
+ const entry = {
34
+ term,
35
+ refit,
36
+ addon: null,
37
+ canvas: null,
38
+ frame: null
39
+ };
40
+ this.entries.set(id, entry);
41
+ if (hasWebgl2()) {
42
+ this.apply(this.slots.request(id));
50
43
  }
51
- blur(id) {
52
- this.apply(this.slots.blur(id));
44
+ return () => {
45
+ if (this.entries.get(id) !== entry) {
46
+ return;
47
+ }
48
+ this.entries.delete(id);
49
+ // The context goes back before the next terminal asks for one, never after.
50
+ this.drop(entry);
51
+ this.apply(this.slots.release(id));
52
+ };
53
+ }
54
+ focus(id) {
55
+ this.apply(this.slots.focus(id));
56
+ }
57
+ blur(id) {
58
+ this.apply(this.slots.blur(id));
59
+ }
60
+ /* Output arrived; a busy terminal outranks an idle one. */
61
+ touch(id) {
62
+ this.apply(this.slots.touch(id));
63
+ }
64
+ /* The terminals holding a WebGL renderer, highest ranked first. */
65
+ holders() {
66
+ return this.slots.holders().flatMap(id => {
67
+ const entry = this.entries.get(id);
68
+ return entry ? [entry.term] : [];
69
+ });
70
+ }
71
+ apply(change) {
72
+ // Free first, the browser has to be back under its own limit before the next context exists.
73
+ for (const id of change.revoked) {
74
+ this.unload(id);
53
75
  }
54
- /* Output arrived; a busy terminal outranks an idle one. */
55
- touch(id) {
56
- this.apply(this.slots.touch(id));
76
+ for (const id of change.granted) {
77
+ this.load(id);
57
78
  }
58
- /* The terminals holding a WebGL renderer, highest ranked first. */
59
- holders() {
60
- return this.slots.holders().flatMap((id) => {
61
- const entry = this.entries.get(id);
62
- return entry ? [entry.term] : [];
63
- });
64
- }
65
- apply(change) {
66
- // Free first, the browser has to be back under its own limit before the next context exists.
67
- for (const id of change.revoked) {
68
- this.unload(id);
69
- }
70
- for (const id of change.granted) {
71
- this.load(id);
72
- }
79
+ }
80
+ load(id) {
81
+ const entry = this.entries.get(id);
82
+ if (!entry || entry.addon) {
83
+ return;
73
84
  }
74
- load(id) {
75
- const entry = this.entries.get(id);
76
- if (!entry || entry.addon) {
77
- return;
78
- }
79
- if (Addon === null) {
80
- addonLoad ??= import('@xterm/addon-webgl').then((module) => {
81
- Addon = module.WebglAddon;
82
- });
83
- void addonLoad.then(() => {
84
- if (this.slots.holds(id)) {
85
- this.load(id);
86
- }
87
- }, () => this.apply(this.slots.lost(id)));
88
- return;
89
- }
90
- try {
91
- const addon = new Addon();
92
- addon.onContextLoss(() => this.handleLoss(id));
93
- entry.term.loadAddon(addon);
94
- entry.addon = addon;
95
- entry.canvas = rendererCanvas(entry.term);
96
- this.scheduleRefit(entry);
97
- }
98
- catch {
99
- // WebGL refused this terminal; the DOM renderer keeps drawing and the slot goes to the next one.
100
- this.apply(this.slots.lost(id));
85
+ if (Addon === null) {
86
+ addonLoad ??= import('@xterm/addon-webgl').then(module => {
87
+ Addon = module.WebglAddon;
88
+ });
89
+ void addonLoad.then(() => {
90
+ if (this.slots.holds(id)) {
91
+ this.load(id);
101
92
  }
93
+ }, () => this.apply(this.slots.lost(id)));
94
+ return;
102
95
  }
103
- unload(id) {
104
- const entry = this.entries.get(id);
105
- if (!entry?.addon) {
106
- return;
107
- }
108
- this.drop(entry);
109
- // Disposing the addon puts the DOM renderer back and queues a full repaint; the fit runs
110
- // after that frame, on the cell size that renderer measured.
111
- this.scheduleRefit(entry);
96
+ try {
97
+ const addon = new Addon();
98
+ addon.onContextLoss(() => this.handleLoss(id));
99
+ entry.term.loadAddon(addon);
100
+ entry.addon = addon;
101
+ entry.canvas = rendererCanvas(entry.term);
102
+ this.scheduleRefit(entry);
103
+ } catch {
104
+ // WebGL refused this terminal; the DOM renderer keeps drawing and the slot goes to the next one.
105
+ this.apply(this.slots.lost(id));
112
106
  }
113
- handleLoss(id) {
114
- this.unload(id);
115
- // Not gone for good, the terminal waits in line and takes a context again when it is focused.
116
- this.apply(this.slots.lost(id));
107
+ }
108
+ unload(id) {
109
+ const entry = this.entries.get(id);
110
+ if (!entry?.addon) {
111
+ return;
117
112
  }
118
- drop(entry) {
119
- if (entry.frame !== null) {
120
- window.cancelAnimationFrame(entry.frame);
121
- entry.frame = null;
122
- }
123
- entry.addon?.dispose();
124
- entry.addon = null;
125
- // The addon leaves its canvas to the garbage collector, and until that runs the browser
126
- // still counts the context. Losing it by hand is what makes a released slot a free one.
127
- entry.canvas?.getContext('webgl2')?.getExtension('WEBGL_lose_context')?.loseContext();
128
- entry.canvas = null;
113
+ this.drop(entry);
114
+ // Disposing the addon puts the DOM renderer back and queues a full repaint; the fit runs
115
+ // after that frame, on the cell size that renderer measured.
116
+ this.scheduleRefit(entry);
117
+ }
118
+ handleLoss(id) {
119
+ this.unload(id);
120
+ // Not gone for good, the terminal waits in line and takes a context again when it is focused.
121
+ this.apply(this.slots.lost(id));
122
+ }
123
+ drop(entry) {
124
+ if (entry.frame !== null) {
125
+ window.cancelAnimationFrame(entry.frame);
126
+ entry.frame = null;
129
127
  }
130
- scheduleRefit(entry) {
131
- if (entry.frame !== null) {
132
- return;
133
- }
134
- entry.frame = window.requestAnimationFrame(() => {
135
- entry.frame = null;
136
- entry.refit();
137
- });
128
+ entry.addon?.dispose();
129
+ entry.addon = null;
130
+ // The addon leaves its canvas to the garbage collector, and until that runs the browser
131
+ // still counts the context. Losing it by hand is what makes a released slot a free one.
132
+ entry.canvas?.getContext('webgl2')?.getExtension('WEBGL_lose_context')?.loseContext();
133
+ entry.canvas = null;
134
+ }
135
+ scheduleRefit(entry) {
136
+ if (entry.frame !== null) {
137
+ return;
138
138
  }
139
+ entry.frame = window.requestAnimationFrame(() => {
140
+ entry.frame = null;
141
+ entry.refit();
142
+ });
143
+ }
139
144
  }
140
145
  /* One budget for the page, since the browser's cap is per page. */
141
- export const webglBudget = /* @__PURE__ */ new WebglBudget();
146
+ export const webglBudget = /* @__PURE__ */new WebglBudget();
142
147
  /* The terminals drawing with WebGL right now, highest ranked first: the focused one, then the ones written to last. */
143
- export const webglTerminals = () => webglBudget.holders();
148
+ export const webglTerminals = () => webglBudget.holders();
@@ -6,142 +6,151 @@ export const DEFAULT_WEBGL_CONTEXTS = 10;
6
6
  for as long. Without it, more writing terminals than slots trade contexts on every chunk, and
7
7
  each switch rebuilds an atlas and can resize the pty, which makes the program write again. */
8
8
  export const OUTPUT_SWITCH_INTERVAL_MS = 1000;
9
- const nothing = () => ({ granted: [], revoked: [] });
9
+ const nothing = () => ({
10
+ granted: [],
11
+ revoked: []
12
+ });
10
13
  /**
11
14
  * Hands a fixed number of WebGL contexts to the terminals that deserve them most, the focused one
12
15
  * first, then the ones most recently focused or written to. Knows nothing about xterm or the DOM;
13
16
  * the budget turns a `SlotChange` into addons that are loaded and disposed.
14
17
  */
15
18
  export class WebglSlots {
16
- members = new Map();
17
- cap;
18
- focusedId = null;
19
- stamp = 0;
20
- outputSwitchedAt = Number.NEGATIVE_INFINITY;
21
- now;
22
- /* `now` is a clock in milliseconds. */
23
- constructor(cap = DEFAULT_WEBGL_CONTEXTS, now = () => performance.now()) {
24
- this.cap = Math.max(1, cap);
25
- this.now = now;
19
+ members = new Map();
20
+ cap;
21
+ focusedId = null;
22
+ stamp = 0;
23
+ outputSwitchedAt = Number.NEGATIVE_INFINITY;
24
+ now;
25
+ /* `now` is a clock in milliseconds. */
26
+ constructor(cap = DEFAULT_WEBGL_CONTEXTS, now = () => performance.now()) {
27
+ this.cap = Math.max(1, cap);
28
+ this.now = now;
29
+ }
30
+ /* The terminals holding a context, highest ranked first. */
31
+ holders() {
32
+ return this.ranked().filter(id => this.holds(id));
33
+ }
34
+ holds(id) {
35
+ return this.members.get(id)?.holding === true;
36
+ }
37
+ /* The terminals that want a context and do not have one, highest ranked first. */
38
+ waiting() {
39
+ return this.ranked().filter(id => !this.holds(id));
40
+ }
41
+ /* A terminal that just became visible asks for a context. */
42
+ request(id) {
43
+ const member = this.members.get(id);
44
+ if (member) {
45
+ member.seq = ++this.stamp;
46
+ member.activeAt = this.now();
47
+ } else {
48
+ this.members.set(id, {
49
+ seq: ++this.stamp,
50
+ activeAt: this.now(),
51
+ holding: false,
52
+ blocked: false
53
+ });
26
54
  }
27
- /* The terminals holding a context, highest ranked first. */
28
- holders() {
29
- return this.ranked().filter((id) => this.holds(id));
55
+ return this.reconcile();
56
+ }
57
+ /* A terminal that unmounts or stops drawing with WebGL leaves the running for good. */
58
+ release(id) {
59
+ if (!this.members.delete(id)) {
60
+ return nothing();
30
61
  }
31
- holds(id) {
32
- return this.members.get(id)?.holding === true;
62
+ if (this.focusedId === id) {
63
+ this.focusedId = null;
33
64
  }
34
- /* The terminals that want a context and do not have one, highest ranked first. */
35
- waiting() {
36
- return this.ranked().filter((id) => !this.holds(id));
65
+ return this.reconcile();
66
+ }
67
+ focus(id) {
68
+ this.focusedId = id;
69
+ const member = this.members.get(id);
70
+ if (!member) {
71
+ return nothing();
37
72
  }
38
- /* A terminal that just became visible asks for a context. */
39
- request(id) {
40
- const member = this.members.get(id);
41
- if (member) {
42
- member.seq = ++this.stamp;
43
- member.activeAt = this.now();
44
- }
45
- else {
46
- this.members.set(id, { seq: ++this.stamp, activeAt: this.now(), holding: false, blocked: false });
47
- }
48
- return this.reconcile();
73
+ member.seq = ++this.stamp;
74
+ member.activeAt = this.now();
75
+ // Focusing is how a terminal that lost its context asks for a new one.
76
+ member.blocked = false;
77
+ return this.reconcile();
78
+ }
79
+ blur(id) {
80
+ if (this.focusedId !== id) {
81
+ return nothing();
49
82
  }
50
- /* A terminal that unmounts or stops drawing with WebGL leaves the running for good. */
51
- release(id) {
52
- if (!this.members.delete(id)) {
53
- return nothing();
54
- }
55
- if (this.focusedId === id) {
56
- this.focusedId = null;
57
- }
58
- return this.reconcile();
83
+ this.focusedId = null;
84
+ return this.reconcile();
85
+ }
86
+ /* Output arrived, so this terminal is worth more than an idle one. */
87
+ touch(id) {
88
+ const member = this.members.get(id);
89
+ if (!member) {
90
+ return nothing();
59
91
  }
60
- focus(id) {
61
- this.focusedId = id;
62
- const member = this.members.get(id);
63
- if (!member) {
64
- return nothing();
65
- }
66
- member.seq = ++this.stamp;
67
- member.activeAt = this.now();
68
- // Focusing is how a terminal that lost its context asks for a new one.
69
- member.blocked = false;
70
- return this.reconcile();
92
+ const now = this.now();
93
+ member.seq = ++this.stamp;
94
+ member.activeAt = now;
95
+ // A holder that climbs stays a holder; only a waiter can change who holds what.
96
+ if (member.holding || now - this.outputSwitchedAt < OUTPUT_SWITCH_INTERVAL_MS) {
97
+ return nothing();
71
98
  }
72
- blur(id) {
73
- if (this.focusedId !== id) {
74
- return nothing();
75
- }
76
- this.focusedId = null;
77
- return this.reconcile();
99
+ const target = this.target();
100
+ const evictsBusyHolder = [...this.members].some(([other, entry]) => entry.holding && !target.has(other) && now - entry.activeAt < OUTPUT_SWITCH_INTERVAL_MS);
101
+ // The waiter keeps its new rank; its next write tries again, and so does any request, focus or release.
102
+ if (evictsBusyHolder) {
103
+ return nothing();
78
104
  }
79
- /* Output arrived, so this terminal is worth more than an idle one. */
80
- touch(id) {
81
- const member = this.members.get(id);
82
- if (!member) {
83
- return nothing();
84
- }
85
- const now = this.now();
86
- member.seq = ++this.stamp;
87
- member.activeAt = now;
88
- // A holder that climbs stays a holder; only a waiter can change who holds what.
89
- if (member.holding || now - this.outputSwitchedAt < OUTPUT_SWITCH_INTERVAL_MS) {
90
- return nothing();
91
- }
92
- const target = this.target();
93
- const evictsBusyHolder = [...this.members].some(([other, entry]) => entry.holding && !target.has(other) && now - entry.activeAt < OUTPUT_SWITCH_INTERVAL_MS);
94
- // The waiter keeps its new rank; its next write tries again, and so does any request, focus or release.
95
- if (evictsBusyHolder) {
96
- return nothing();
97
- }
98
- const change = this.reconcile(target);
99
- if (change.granted.length > 0 || change.revoked.length > 0) {
100
- this.outputSwitchedAt = now;
101
- }
102
- return change;
105
+ const change = this.reconcile(target);
106
+ if (change.granted.length > 0 || change.revoked.length > 0) {
107
+ this.outputSwitchedAt = now;
103
108
  }
104
- /* The browser reported a context loss, free the slot and wait for a focus before asking again. */
105
- lost(id) {
106
- const member = this.members.get(id);
107
- if (!member) {
108
- return nothing();
109
- }
110
- member.holding = false;
111
- member.blocked = true;
112
- return this.reconcile();
113
- }
114
- setCap(cap) {
115
- this.cap = Math.max(1, cap);
116
- return this.reconcile();
117
- }
118
- ranked() {
119
- return [...this.members.keys()].sort((a, b) => this.rankOf(b) - this.rankOf(a));
109
+ return change;
110
+ }
111
+ /* The browser reported a context loss, free the slot and wait for a focus before asking again. */
112
+ lost(id) {
113
+ const member = this.members.get(id);
114
+ if (!member) {
115
+ return nothing();
120
116
  }
121
- rankOf(id) {
122
- // The focused terminal is the one the person is looking at, whatever its last write says.
123
- if (id === this.focusedId) {
124
- return Number.MAX_SAFE_INTEGER;
125
- }
126
- return this.members.get(id)?.seq ?? -1;
117
+ member.holding = false;
118
+ member.blocked = true;
119
+ return this.reconcile();
120
+ }
121
+ setCap(cap) {
122
+ this.cap = Math.max(1, cap);
123
+ return this.reconcile();
124
+ }
125
+ ranked() {
126
+ return [...this.members.keys()].sort((a, b) => this.rankOf(b) - this.rankOf(a));
127
+ }
128
+ rankOf(id) {
129
+ // The focused terminal is the one the person is looking at, whatever its last write says.
130
+ if (id === this.focusedId) {
131
+ return Number.MAX_SAFE_INTEGER;
127
132
  }
128
- target() {
129
- const eligible = this.ranked().filter((id) => this.members.get(id)?.blocked !== true);
130
- return new Set(eligible.slice(0, this.cap));
131
- }
132
- reconcile(target = this.target()) {
133
- const granted = [];
134
- const revoked = [];
135
- for (const [id, member] of this.members) {
136
- if (target.has(id) && !member.holding) {
137
- member.holding = true;
138
- granted.push(id);
139
- }
140
- else if (!target.has(id) && member.holding) {
141
- member.holding = false;
142
- revoked.push(id);
143
- }
144
- }
145
- return { granted, revoked };
133
+ return this.members.get(id)?.seq ?? -1;
134
+ }
135
+ target() {
136
+ const eligible = this.ranked().filter(id => this.members.get(id)?.blocked !== true);
137
+ return new Set(eligible.slice(0, this.cap));
138
+ }
139
+ reconcile(target = this.target()) {
140
+ const granted = [];
141
+ const revoked = [];
142
+ for (const [id, member] of this.members) {
143
+ if (target.has(id) && !member.holding) {
144
+ member.holding = true;
145
+ granted.push(id);
146
+ } else if (!target.has(id) && member.holding) {
147
+ member.holding = false;
148
+ revoked.push(id);
149
+ }
146
150
  }
147
- }
151
+ return {
152
+ granted,
153
+ revoked
154
+ };
155
+ }
156
+ }
@@ -10,28 +10,27 @@
10
10
  * of it, a grid nobody sees that a shell still redraws its prompt for.
11
11
  */
12
12
  export const fitToHost = (term, fit) => {
13
- const host = term.element?.parentElement;
14
- if (!host || host.clientWidth === 0 || host.clientHeight === 0) {
15
- return false;
16
- }
17
- fit.fit();
18
- // The same private dimensions FitAddon itself divides by.
19
- const cellHeight = term._core._renderService
20
- .dimensions.css.cell.height;
21
- if (cellHeight !== 0) {
22
- const slack = host.clientHeight - term.rows * cellHeight;
23
- host.style.setProperty('--term-offset', `${Math.max(0, Math.floor(slack / 2))}px`);
24
- }
25
- return true;
13
+ const host = term.element?.parentElement;
14
+ if (!host || host.clientWidth === 0 || host.clientHeight === 0) {
15
+ return false;
16
+ }
17
+ fit.fit();
18
+ // The same private dimensions FitAddon itself divides by.
19
+ const cellHeight = term._core._renderService.dimensions.css.cell.height;
20
+ if (cellHeight !== 0) {
21
+ const slack = host.clientHeight - term.rows * cellHeight;
22
+ host.style.setProperty('--term-offset', `${Math.max(0, Math.floor(slack / 2))}px`);
23
+ }
24
+ return true;
26
25
  };
27
26
  /** Where a pointer would stand on an element whose ancestors scale it from its layout size to `rect`. */
28
27
  export const unscaledPointer = (pointer, rect, layout) => {
29
- const scaleX = layout.width > 0 && rect.width > 0 ? rect.width / layout.width : 1;
30
- const scaleY = layout.height > 0 && rect.height > 0 ? rect.height / layout.height : 1;
31
- return {
32
- clientX: rect.left + (pointer.clientX - rect.left) / scaleX,
33
- clientY: rect.top + (pointer.clientY - rect.top) / scaleY
34
- };
28
+ const scaleX = layout.width > 0 && rect.width > 0 ? rect.width / layout.width : 1;
29
+ const scaleY = layout.height > 0 && rect.height > 0 ? rect.height / layout.height : 1;
30
+ return {
31
+ clientX: rect.left + (pointer.clientX - rect.left) / scaleX,
32
+ clientY: rect.top + (pointer.clientY - rect.top) / scaleY
33
+ };
35
34
  };
36
35
  /*
37
36
  * xterm measures a pointer against the screen's scaled bounding box but divides by unscaled cells, so
@@ -39,14 +38,17 @@ export const unscaledPointer = (pointer, rect, layout) => {
39
38
  * service (private, shared by selection, links and mouse reporting) gets the pointer as it would stand
40
39
  * without the transform. Call after `open`, which creates that service.
41
40
  */
42
- export const followAncestorScale = (term) => {
43
- const mouse = term._core._mouseService;
44
- if (!mouse) {
45
- return;
46
- }
47
- const unscaled = (pointer, element) => unscaledPointer(pointer, element.getBoundingClientRect(), { width: element.offsetWidth, height: element.offsetHeight });
48
- const getCoords = mouse.getCoords.bind(mouse);
49
- const getMouseReportCoords = mouse.getMouseReportCoords.bind(mouse);
50
- mouse.getCoords = (event, element, ...rest) => getCoords(unscaled(event, element), element, ...rest);
51
- mouse.getMouseReportCoords = (event, element) => getMouseReportCoords(unscaled(event, element), element);
52
- };
41
+ export const followAncestorScale = term => {
42
+ const mouse = term._core._mouseService;
43
+ if (!mouse) {
44
+ return;
45
+ }
46
+ const unscaled = (pointer, element) => unscaledPointer(pointer, element.getBoundingClientRect(), {
47
+ width: element.offsetWidth,
48
+ height: element.offsetHeight
49
+ });
50
+ const getCoords = mouse.getCoords.bind(mouse);
51
+ const getMouseReportCoords = mouse.getMouseReportCoords.bind(mouse);
52
+ mouse.getCoords = (event, element, ...rest) => getCoords(unscaled(event, element), element, ...rest);
53
+ mouse.getMouseReportCoords = (event, element) => getMouseReportCoords(unscaled(event, element), element);
54
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/terminal",
3
- "version": "0.31.12",
3
+ "version": "0.33.0",
4
4
  "description": "A themed terminal pane on xterm.js that fits its container and is fed by the app.",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "author": "Bas Milius",