@wendongfly/myhi 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/lib/xterm/LICENSE +21 -0
- package/dist/lib/xterm/README.md +225 -0
- package/dist/lib/xterm/css/xterm.css +190 -0
- package/dist/lib/xterm/lib/xterm.js +2 -0
- package/dist/lib/xterm/lib/xterm.js.map +1 -0
- package/dist/lib/xterm/package.json +90 -0
- package/dist/lib/xterm/src/browser/AccessibilityManager.ts +301 -0
- package/dist/lib/xterm/src/browser/Clipboard.ts +99 -0
- package/dist/lib/xterm/src/browser/ColorContrastCache.ts +39 -0
- package/dist/lib/xterm/src/browser/ColorManager.ts +268 -0
- package/dist/lib/xterm/src/browser/Dom.ts +10 -0
- package/dist/lib/xterm/src/browser/Lifecycle.ts +30 -0
- package/dist/lib/xterm/src/browser/Linkifier.ts +356 -0
- package/dist/lib/xterm/src/browser/Linkifier2.ts +397 -0
- package/dist/lib/xterm/src/browser/LocalizableStrings.ts +10 -0
- package/dist/lib/xterm/src/browser/MouseZoneManager.ts +236 -0
- package/dist/lib/xterm/src/browser/RenderDebouncer.ts +82 -0
- package/dist/lib/xterm/src/browser/ScreenDprMonitor.ts +69 -0
- package/dist/lib/xterm/src/browser/Terminal.ts +1447 -0
- package/dist/lib/xterm/src/browser/TimeBasedDebouncer.ts +86 -0
- package/dist/lib/xterm/src/browser/Types.d.ts +317 -0
- package/dist/lib/xterm/src/browser/Viewport.ts +276 -0
- package/dist/lib/xterm/src/browser/decorations/BufferDecorationRenderer.ts +131 -0
- package/dist/lib/xterm/src/browser/decorations/ColorZoneStore.ts +117 -0
- package/dist/lib/xterm/src/browser/decorations/OverviewRulerRenderer.ts +228 -0
- package/dist/lib/xterm/src/browser/input/CompositionHelper.ts +237 -0
- package/dist/lib/xterm/src/browser/input/Mouse.ts +64 -0
- package/dist/lib/xterm/src/browser/input/MoveToCell.ts +249 -0
- package/dist/lib/xterm/src/browser/public/Terminal.ts +298 -0
- package/dist/lib/xterm/src/browser/renderer/BaseRenderLayer.ts +582 -0
- package/dist/lib/xterm/src/browser/renderer/CursorRenderLayer.ts +378 -0
- package/dist/lib/xterm/src/browser/renderer/CustomGlyphs.ts +632 -0
- package/dist/lib/xterm/src/browser/renderer/GridCache.ts +33 -0
- package/dist/lib/xterm/src/browser/renderer/LinkRenderLayer.ts +84 -0
- package/dist/lib/xterm/src/browser/renderer/Renderer.ts +219 -0
- package/dist/lib/xterm/src/browser/renderer/RendererUtils.ts +26 -0
- package/dist/lib/xterm/src/browser/renderer/SelectionRenderLayer.ts +131 -0
- package/dist/lib/xterm/src/browser/renderer/TextRenderLayer.ts +344 -0
- package/dist/lib/xterm/src/browser/renderer/Types.d.ts +109 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/BaseCharAtlas.ts +58 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/CharAtlasCache.ts +95 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/CharAtlasUtils.ts +54 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/Constants.ts +15 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/DynamicCharAtlas.ts +404 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/LRUMap.ts +136 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/Types.d.ts +29 -0
- package/dist/lib/xterm/src/browser/renderer/dom/DomRenderer.ts +403 -0
- package/dist/lib/xterm/src/browser/renderer/dom/DomRendererRowFactory.ts +344 -0
- package/dist/lib/xterm/src/browser/selection/SelectionModel.ts +144 -0
- package/dist/lib/xterm/src/browser/selection/Types.d.ts +15 -0
- package/dist/lib/xterm/src/browser/services/CharSizeService.ts +87 -0
- package/dist/lib/xterm/src/browser/services/CharacterJoinerService.ts +339 -0
- package/dist/lib/xterm/src/browser/services/CoreBrowserService.ts +20 -0
- package/dist/lib/xterm/src/browser/services/MouseService.ts +36 -0
- package/dist/lib/xterm/src/browser/services/RenderService.ts +237 -0
- package/dist/lib/xterm/src/browser/services/SelectionService.ts +1027 -0
- package/dist/lib/xterm/src/browser/services/Services.ts +123 -0
- package/dist/lib/xterm/src/browser/services/SoundService.ts +63 -0
- package/dist/lib/xterm/src/common/CircularList.ts +239 -0
- package/dist/lib/xterm/src/common/Clone.ts +23 -0
- package/dist/lib/xterm/src/common/Color.ts +285 -0
- package/dist/lib/xterm/src/common/CoreTerminal.ts +300 -0
- package/dist/lib/xterm/src/common/EventEmitter.ts +69 -0
- package/dist/lib/xterm/src/common/InputHandler.ts +3230 -0
- package/dist/lib/xterm/src/common/Lifecycle.ts +68 -0
- package/dist/lib/xterm/src/common/Platform.ts +31 -0
- package/dist/lib/xterm/src/common/SortedList.ts +88 -0
- package/dist/lib/xterm/src/common/TypedArrayUtils.ts +50 -0
- package/dist/lib/xterm/src/common/Types.d.ts +489 -0
- package/dist/lib/xterm/src/common/WindowsMode.ts +27 -0
- package/dist/lib/xterm/src/common/buffer/AttributeData.ts +148 -0
- package/dist/lib/xterm/src/common/buffer/Buffer.ts +711 -0
- package/dist/lib/xterm/src/common/buffer/BufferLine.ts +441 -0
- package/dist/lib/xterm/src/common/buffer/BufferRange.ts +13 -0
- package/dist/lib/xterm/src/common/buffer/BufferReflow.ts +220 -0
- package/dist/lib/xterm/src/common/buffer/BufferSet.ts +131 -0
- package/dist/lib/xterm/src/common/buffer/CellData.ts +94 -0
- package/dist/lib/xterm/src/common/buffer/Constants.ts +139 -0
- package/dist/lib/xterm/src/common/buffer/Marker.ts +37 -0
- package/dist/lib/xterm/src/common/buffer/Types.d.ts +64 -0
- package/dist/lib/xterm/src/common/data/Charsets.ts +256 -0
- package/dist/lib/xterm/src/common/data/EscapeSequences.ts +153 -0
- package/dist/lib/xterm/src/common/input/Keyboard.ts +398 -0
- package/dist/lib/xterm/src/common/input/TextDecoder.ts +346 -0
- package/dist/lib/xterm/src/common/input/UnicodeV6.ts +133 -0
- package/dist/lib/xterm/src/common/input/WriteBuffer.ts +229 -0
- package/dist/lib/xterm/src/common/input/XParseColor.ts +80 -0
- package/dist/lib/xterm/src/common/parser/Constants.ts +58 -0
- package/dist/lib/xterm/src/common/parser/DcsParser.ts +192 -0
- package/dist/lib/xterm/src/common/parser/EscapeSequenceParser.ts +796 -0
- package/dist/lib/xterm/src/common/parser/OscParser.ts +238 -0
- package/dist/lib/xterm/src/common/parser/Params.ts +229 -0
- package/dist/lib/xterm/src/common/parser/Types.d.ts +274 -0
- package/dist/lib/xterm/src/common/public/AddonManager.ts +56 -0
- package/dist/lib/xterm/src/common/public/BufferApiView.ts +35 -0
- package/dist/lib/xterm/src/common/public/BufferLineApiView.ts +29 -0
- package/dist/lib/xterm/src/common/public/BufferNamespaceApi.ts +33 -0
- package/dist/lib/xterm/src/common/public/ParserApi.ts +37 -0
- package/dist/lib/xterm/src/common/public/UnicodeApi.ts +27 -0
- package/dist/lib/xterm/src/common/services/BufferService.ts +185 -0
- package/dist/lib/xterm/src/common/services/CharsetService.ts +34 -0
- package/dist/lib/xterm/src/common/services/CoreMouseService.ts +309 -0
- package/dist/lib/xterm/src/common/services/CoreService.ts +92 -0
- package/dist/lib/xterm/src/common/services/DecorationService.ts +139 -0
- package/dist/lib/xterm/src/common/services/DirtyRowService.ts +53 -0
- package/dist/lib/xterm/src/common/services/InstantiationService.ts +83 -0
- package/dist/lib/xterm/src/common/services/LogService.ts +88 -0
- package/dist/lib/xterm/src/common/services/OptionsService.ts +178 -0
- package/dist/lib/xterm/src/common/services/ServiceRegistry.ts +49 -0
- package/dist/lib/xterm/src/common/services/Services.ts +323 -0
- package/dist/lib/xterm/src/common/services/UnicodeService.ts +82 -0
- package/dist/lib/xterm/src/headless/Terminal.ts +170 -0
- package/dist/lib/xterm/src/headless/Types.d.ts +31 -0
- package/dist/lib/xterm/src/headless/public/Terminal.ts +216 -0
- package/dist/lib/xterm/typings/xterm.d.ts +1872 -0
- package/dist/lib/xterm-fit/LICENSE +19 -0
- package/dist/lib/xterm-fit/README.md +24 -0
- package/dist/lib/xterm-fit/lib/xterm-addon-fit.js +2 -0
- package/dist/lib/xterm-fit/lib/xterm-addon-fit.js.map +1 -0
- package/dist/lib/xterm-fit/out/FitAddon.js +58 -0
- package/dist/lib/xterm-fit/out/FitAddon.js.map +1 -0
- package/dist/lib/xterm-fit/out-test/FitAddon.api.js.map +1 -0
- package/dist/lib/xterm-fit/package.json +21 -0
- package/dist/lib/xterm-fit/src/FitAddon.ts +86 -0
- package/dist/lib/xterm-fit/typings/xterm-addon-fit.d.ts +55 -0
- package/dist/lib/xterm-links/LICENSE +19 -0
- package/dist/lib/xterm-links/README.md +21 -0
- package/dist/lib/xterm-links/lib/xterm-addon-web-links.js +2 -0
- package/dist/lib/xterm-links/lib/xterm-addon-web-links.js.map +1 -0
- package/dist/lib/xterm-links/package.json +26 -0
- package/dist/lib/xterm-links/src/WebLinkProvider.ts +145 -0
- package/dist/lib/xterm-links/src/WebLinksAddon.ts +77 -0
- package/dist/lib/xterm-links/typings/xterm-addon-web-links.d.ts +58 -0
- package/package.json +1 -1
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { IRenderDimensions, IRequestRedrawEvent } from 'browser/renderer/Types';
|
|
7
|
+
import { BaseRenderLayer } from 'browser/renderer/BaseRenderLayer';
|
|
8
|
+
import { ICellData } from 'common/Types';
|
|
9
|
+
import { CellData } from 'common/buffer/CellData';
|
|
10
|
+
import { IColorSet } from 'browser/Types';
|
|
11
|
+
import { IBufferService, IOptionsService, ICoreService, IDecorationService } from 'common/services/Services';
|
|
12
|
+
import { IEventEmitter } from 'common/EventEmitter';
|
|
13
|
+
import { ICoreBrowserService } from 'browser/services/Services';
|
|
14
|
+
|
|
15
|
+
interface ICursorState {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
isFocused: boolean;
|
|
19
|
+
style: string;
|
|
20
|
+
width: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The time between cursor blinks.
|
|
25
|
+
*/
|
|
26
|
+
const BLINK_INTERVAL = 600;
|
|
27
|
+
|
|
28
|
+
export class CursorRenderLayer extends BaseRenderLayer {
|
|
29
|
+
private _state: ICursorState;
|
|
30
|
+
private _cursorRenderers: {[key: string]: (x: number, y: number, cell: ICellData) => void};
|
|
31
|
+
private _cursorBlinkStateManager: CursorBlinkStateManager | undefined;
|
|
32
|
+
private _cell: ICellData = new CellData();
|
|
33
|
+
|
|
34
|
+
constructor(
|
|
35
|
+
container: HTMLElement,
|
|
36
|
+
zIndex: number,
|
|
37
|
+
colors: IColorSet,
|
|
38
|
+
rendererId: number,
|
|
39
|
+
private _onRequestRedraw: IEventEmitter<IRequestRedrawEvent>,
|
|
40
|
+
@IBufferService bufferService: IBufferService,
|
|
41
|
+
@IOptionsService optionsService: IOptionsService,
|
|
42
|
+
@ICoreService private readonly _coreService: ICoreService,
|
|
43
|
+
@ICoreBrowserService private readonly _coreBrowserService: ICoreBrowserService,
|
|
44
|
+
@IDecorationService decorationService: IDecorationService
|
|
45
|
+
) {
|
|
46
|
+
super(container, 'cursor', zIndex, true, colors, rendererId, bufferService, optionsService, decorationService);
|
|
47
|
+
this._state = {
|
|
48
|
+
x: 0,
|
|
49
|
+
y: 0,
|
|
50
|
+
isFocused: false,
|
|
51
|
+
style: '',
|
|
52
|
+
width: 0
|
|
53
|
+
};
|
|
54
|
+
this._cursorRenderers = {
|
|
55
|
+
'bar': this._renderBarCursor.bind(this),
|
|
56
|
+
'block': this._renderBlockCursor.bind(this),
|
|
57
|
+
'underline': this._renderUnderlineCursor.bind(this)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public dispose(): void {
|
|
62
|
+
if (this._cursorBlinkStateManager) {
|
|
63
|
+
this._cursorBlinkStateManager.dispose();
|
|
64
|
+
this._cursorBlinkStateManager = undefined;
|
|
65
|
+
}
|
|
66
|
+
super.dispose();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public resize(dim: IRenderDimensions): void {
|
|
70
|
+
super.resize(dim);
|
|
71
|
+
// Resizing the canvas discards the contents of the canvas so clear state
|
|
72
|
+
this._state = {
|
|
73
|
+
x: 0,
|
|
74
|
+
y: 0,
|
|
75
|
+
isFocused: false,
|
|
76
|
+
style: '',
|
|
77
|
+
width: 0
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public reset(): void {
|
|
82
|
+
this._clearCursor();
|
|
83
|
+
this._cursorBlinkStateManager?.restartBlinkAnimation();
|
|
84
|
+
this.onOptionsChanged();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public onBlur(): void {
|
|
88
|
+
this._cursorBlinkStateManager?.pause();
|
|
89
|
+
this._onRequestRedraw.fire({ start: this._bufferService.buffer.y, end: this._bufferService.buffer.y });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public onFocus(): void {
|
|
93
|
+
this._cursorBlinkStateManager?.resume();
|
|
94
|
+
this._onRequestRedraw.fire({ start: this._bufferService.buffer.y, end: this._bufferService.buffer.y });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public onOptionsChanged(): void {
|
|
98
|
+
if (this._optionsService.rawOptions.cursorBlink) {
|
|
99
|
+
if (!this._cursorBlinkStateManager) {
|
|
100
|
+
this._cursorBlinkStateManager = new CursorBlinkStateManager(this._coreBrowserService.isFocused, () => {
|
|
101
|
+
this._render(true);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
this._cursorBlinkStateManager?.dispose();
|
|
106
|
+
this._cursorBlinkStateManager = undefined;
|
|
107
|
+
}
|
|
108
|
+
// Request a refresh from the terminal as management of rendering is being
|
|
109
|
+
// moved back to the terminal
|
|
110
|
+
this._onRequestRedraw.fire({ start: this._bufferService.buffer.y, end: this._bufferService.buffer.y });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public onCursorMove(): void {
|
|
114
|
+
this._cursorBlinkStateManager?.restartBlinkAnimation();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public onGridChanged(startRow: number, endRow: number): void {
|
|
118
|
+
if (!this._cursorBlinkStateManager || this._cursorBlinkStateManager.isPaused) {
|
|
119
|
+
this._render(false);
|
|
120
|
+
} else {
|
|
121
|
+
this._cursorBlinkStateManager.restartBlinkAnimation();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private _render(triggeredByAnimationFrame: boolean): void {
|
|
126
|
+
// Don't draw the cursor if it's hidden
|
|
127
|
+
if (!this._coreService.isCursorInitialized || this._coreService.isCursorHidden) {
|
|
128
|
+
this._clearCursor();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const cursorY = this._bufferService.buffer.ybase + this._bufferService.buffer.y;
|
|
133
|
+
const viewportRelativeCursorY = cursorY - this._bufferService.buffer.ydisp;
|
|
134
|
+
|
|
135
|
+
// Don't draw the cursor if it's off-screen
|
|
136
|
+
if (viewportRelativeCursorY < 0 || viewportRelativeCursorY >= this._bufferService.rows) {
|
|
137
|
+
this._clearCursor();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// in case cursor.x == cols adjust visual cursor to cols - 1
|
|
142
|
+
const cursorX = Math.min(this._bufferService.buffer.x, this._bufferService.cols - 1);
|
|
143
|
+
this._bufferService.buffer.lines.get(cursorY)!.loadCell(cursorX, this._cell);
|
|
144
|
+
if (this._cell.content === undefined) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (!this._coreBrowserService.isFocused) {
|
|
149
|
+
this._clearCursor();
|
|
150
|
+
this._ctx.save();
|
|
151
|
+
this._ctx.fillStyle = this._colors.cursor.css;
|
|
152
|
+
const cursorStyle = this._optionsService.rawOptions.cursorStyle;
|
|
153
|
+
if (cursorStyle && cursorStyle !== 'block') {
|
|
154
|
+
this._cursorRenderers[cursorStyle](cursorX, viewportRelativeCursorY, this._cell);
|
|
155
|
+
} else {
|
|
156
|
+
this._renderBlurCursor(cursorX, viewportRelativeCursorY, this._cell);
|
|
157
|
+
}
|
|
158
|
+
this._ctx.restore();
|
|
159
|
+
this._state.x = cursorX;
|
|
160
|
+
this._state.y = viewportRelativeCursorY;
|
|
161
|
+
this._state.isFocused = false;
|
|
162
|
+
this._state.style = cursorStyle;
|
|
163
|
+
this._state.width = this._cell.getWidth();
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Don't draw the cursor if it's blinking
|
|
168
|
+
if (this._cursorBlinkStateManager && !this._cursorBlinkStateManager.isCursorVisible) {
|
|
169
|
+
this._clearCursor();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (this._state) {
|
|
174
|
+
// The cursor is already in the correct spot, don't redraw
|
|
175
|
+
if (this._state.x === cursorX &&
|
|
176
|
+
this._state.y === viewportRelativeCursorY &&
|
|
177
|
+
this._state.isFocused === this._coreBrowserService.isFocused &&
|
|
178
|
+
this._state.style === this._optionsService.rawOptions.cursorStyle &&
|
|
179
|
+
this._state.width === this._cell.getWidth()) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this._clearCursor();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
this._ctx.save();
|
|
186
|
+
this._cursorRenderers[this._optionsService.rawOptions.cursorStyle || 'block'](cursorX, viewportRelativeCursorY, this._cell);
|
|
187
|
+
this._ctx.restore();
|
|
188
|
+
|
|
189
|
+
this._state.x = cursorX;
|
|
190
|
+
this._state.y = viewportRelativeCursorY;
|
|
191
|
+
this._state.isFocused = false;
|
|
192
|
+
this._state.style = this._optionsService.rawOptions.cursorStyle;
|
|
193
|
+
this._state.width = this._cell.getWidth();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private _clearCursor(): void {
|
|
197
|
+
if (this._state) {
|
|
198
|
+
// Avoid potential rounding errors when device pixel ratio is less than 1
|
|
199
|
+
if (window.devicePixelRatio < 1) {
|
|
200
|
+
this._clearAll();
|
|
201
|
+
} else {
|
|
202
|
+
this._clearCells(this._state.x, this._state.y, this._state.width, 1);
|
|
203
|
+
}
|
|
204
|
+
this._state = {
|
|
205
|
+
x: 0,
|
|
206
|
+
y: 0,
|
|
207
|
+
isFocused: false,
|
|
208
|
+
style: '',
|
|
209
|
+
width: 0
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private _renderBarCursor(x: number, y: number, cell: ICellData): void {
|
|
215
|
+
this._ctx.save();
|
|
216
|
+
this._ctx.fillStyle = this._colors.cursor.css;
|
|
217
|
+
this._fillLeftLineAtCell(x, y, this._optionsService.rawOptions.cursorWidth);
|
|
218
|
+
this._ctx.restore();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private _renderBlockCursor(x: number, y: number, cell: ICellData): void {
|
|
222
|
+
this._ctx.save();
|
|
223
|
+
this._ctx.fillStyle = this._colors.cursor.css;
|
|
224
|
+
this._fillCells(x, y, cell.getWidth(), 1);
|
|
225
|
+
this._ctx.fillStyle = this._colors.cursorAccent.css;
|
|
226
|
+
this._fillCharTrueColor(cell, x, y);
|
|
227
|
+
this._ctx.restore();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private _renderUnderlineCursor(x: number, y: number, cell: ICellData): void {
|
|
231
|
+
this._ctx.save();
|
|
232
|
+
this._ctx.fillStyle = this._colors.cursor.css;
|
|
233
|
+
this._fillBottomLineAtCells(x, y);
|
|
234
|
+
this._ctx.restore();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private _renderBlurCursor(x: number, y: number, cell: ICellData): void {
|
|
238
|
+
this._ctx.save();
|
|
239
|
+
this._ctx.strokeStyle = this._colors.cursor.css;
|
|
240
|
+
this._strokeRectAtCell(x, y, cell.getWidth(), 1);
|
|
241
|
+
this._ctx.restore();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
class CursorBlinkStateManager {
|
|
246
|
+
public isCursorVisible: boolean;
|
|
247
|
+
|
|
248
|
+
private _animationFrame: number | undefined;
|
|
249
|
+
private _blinkStartTimeout: number | undefined;
|
|
250
|
+
private _blinkInterval: number | undefined;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* The time at which the animation frame was restarted, this is used on the
|
|
254
|
+
* next render to restart the timers so they don't need to restart the timers
|
|
255
|
+
* multiple times over a short period.
|
|
256
|
+
*/
|
|
257
|
+
private _animationTimeRestarted: number | undefined;
|
|
258
|
+
|
|
259
|
+
constructor(
|
|
260
|
+
isFocused: boolean,
|
|
261
|
+
private _renderCallback: () => void
|
|
262
|
+
) {
|
|
263
|
+
this.isCursorVisible = true;
|
|
264
|
+
if (isFocused) {
|
|
265
|
+
this._restartInterval();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
public get isPaused(): boolean { return !(this._blinkStartTimeout || this._blinkInterval); }
|
|
270
|
+
|
|
271
|
+
public dispose(): void {
|
|
272
|
+
if (this._blinkInterval) {
|
|
273
|
+
window.clearInterval(this._blinkInterval);
|
|
274
|
+
this._blinkInterval = undefined;
|
|
275
|
+
}
|
|
276
|
+
if (this._blinkStartTimeout) {
|
|
277
|
+
window.clearTimeout(this._blinkStartTimeout);
|
|
278
|
+
this._blinkStartTimeout = undefined;
|
|
279
|
+
}
|
|
280
|
+
if (this._animationFrame) {
|
|
281
|
+
window.cancelAnimationFrame(this._animationFrame);
|
|
282
|
+
this._animationFrame = undefined;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
public restartBlinkAnimation(): void {
|
|
287
|
+
if (this.isPaused) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
// Save a timestamp so that the restart can be done on the next interval
|
|
291
|
+
this._animationTimeRestarted = Date.now();
|
|
292
|
+
// Force a cursor render to ensure it's visible and in the correct position
|
|
293
|
+
this.isCursorVisible = true;
|
|
294
|
+
if (!this._animationFrame) {
|
|
295
|
+
this._animationFrame = window.requestAnimationFrame(() => {
|
|
296
|
+
this._renderCallback();
|
|
297
|
+
this._animationFrame = undefined;
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
private _restartInterval(timeToStart: number = BLINK_INTERVAL): void {
|
|
303
|
+
// Clear any existing interval
|
|
304
|
+
if (this._blinkInterval) {
|
|
305
|
+
window.clearInterval(this._blinkInterval);
|
|
306
|
+
this._blinkInterval = undefined;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Setup the initial timeout which will hide the cursor, this is done before
|
|
310
|
+
// the regular interval is setup in order to support restarting the blink
|
|
311
|
+
// animation in a lightweight way (without thrashing clearInterval and
|
|
312
|
+
// setInterval).
|
|
313
|
+
this._blinkStartTimeout = window.setTimeout(() => {
|
|
314
|
+
// Check if another animation restart was requested while this was being
|
|
315
|
+
// started
|
|
316
|
+
if (this._animationTimeRestarted) {
|
|
317
|
+
const time = BLINK_INTERVAL - (Date.now() - this._animationTimeRestarted);
|
|
318
|
+
this._animationTimeRestarted = undefined;
|
|
319
|
+
if (time > 0) {
|
|
320
|
+
this._restartInterval(time);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Hide the cursor
|
|
326
|
+
this.isCursorVisible = false;
|
|
327
|
+
this._animationFrame = window.requestAnimationFrame(() => {
|
|
328
|
+
this._renderCallback();
|
|
329
|
+
this._animationFrame = undefined;
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// Setup the blink interval
|
|
333
|
+
this._blinkInterval = window.setInterval(() => {
|
|
334
|
+
// Adjust the animation time if it was restarted
|
|
335
|
+
if (this._animationTimeRestarted) {
|
|
336
|
+
// calc time diff
|
|
337
|
+
// Make restart interval do a setTimeout initially?
|
|
338
|
+
const time = BLINK_INTERVAL - (Date.now() - this._animationTimeRestarted);
|
|
339
|
+
this._animationTimeRestarted = undefined;
|
|
340
|
+
this._restartInterval(time);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Invert visibility and render
|
|
345
|
+
this.isCursorVisible = !this.isCursorVisible;
|
|
346
|
+
this._animationFrame = window.requestAnimationFrame(() => {
|
|
347
|
+
this._renderCallback();
|
|
348
|
+
this._animationFrame = undefined;
|
|
349
|
+
});
|
|
350
|
+
}, BLINK_INTERVAL);
|
|
351
|
+
}, timeToStart);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
public pause(): void {
|
|
355
|
+
this.isCursorVisible = true;
|
|
356
|
+
if (this._blinkInterval) {
|
|
357
|
+
window.clearInterval(this._blinkInterval);
|
|
358
|
+
this._blinkInterval = undefined;
|
|
359
|
+
}
|
|
360
|
+
if (this._blinkStartTimeout) {
|
|
361
|
+
window.clearTimeout(this._blinkStartTimeout);
|
|
362
|
+
this._blinkStartTimeout = undefined;
|
|
363
|
+
}
|
|
364
|
+
if (this._animationFrame) {
|
|
365
|
+
window.cancelAnimationFrame(this._animationFrame);
|
|
366
|
+
this._animationFrame = undefined;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
public resume(): void {
|
|
371
|
+
// Clear out any existing timers just in case
|
|
372
|
+
this.pause();
|
|
373
|
+
|
|
374
|
+
this._animationTimeRestarted = undefined;
|
|
375
|
+
this._restartInterval();
|
|
376
|
+
this.restartBlinkAnimation();
|
|
377
|
+
}
|
|
378
|
+
}
|