Fixes https://github.com/xtermjs/xterm.js/issues/5896 TypeScript path mappings for common/*, browser/*, and headless/* were not rewritten in emitted JavaScript, which forced webpack resolve aliases and NODE_PATH workarounds so runtime could resolve modules. That added build complexity and broke tooling such as ESLint import/no-cycle. Changes: - Convert ~750 imports across src/, addons/, and test/ to relative paths - Remove common/browser/headless paths and src catch-all mappings from tsconfigs (keep @xterm/addon-* demo and addon typings paths) - Remove webpack resolve.alias for common, browser, headless, and vs - Drop NODE_PATH from unit tests, benchmarks, and VS Code launch config - Fix addon-image IIPImageStorage to import ./Types after removing catch-all * Verified: npm run build, esbuild, package, package-headless Co-authored-by: Cursor <cursoragent@cursor.com>
85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
/**
|
|
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
|
* @license MIT
|
|
*/
|
|
|
|
import { IRenderDebouncerWithCallback } from './Types';
|
|
import { ICoreBrowserService } from './services/Services';
|
|
|
|
/**
|
|
* Debounces calls to render terminal rows using animation frames.
|
|
*/
|
|
export class RenderDebouncer implements IRenderDebouncerWithCallback {
|
|
private _rowStart: number | undefined;
|
|
private _rowEnd: number | undefined;
|
|
private _rowCount: number | undefined;
|
|
private _animationFrame: number | undefined;
|
|
private _refreshCallbacks: FrameRequestCallback[] = [];
|
|
|
|
constructor(
|
|
private _renderCallback: (start: number, end: number) => void,
|
|
private readonly _coreBrowserService: ICoreBrowserService
|
|
) {
|
|
}
|
|
|
|
public dispose(): void {
|
|
if (this._animationFrame) {
|
|
this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame);
|
|
this._animationFrame = undefined;
|
|
}
|
|
}
|
|
|
|
public addRefreshCallback(callback: FrameRequestCallback): number {
|
|
this._refreshCallbacks.push(callback);
|
|
if (!this._animationFrame) {
|
|
this._animationFrame = this._coreBrowserService.window.requestAnimationFrame(() => this._innerRefresh());
|
|
}
|
|
return this._animationFrame;
|
|
}
|
|
|
|
public refresh(rowStart: number | undefined, rowEnd: number | undefined, rowCount: number): void {
|
|
this._rowCount = rowCount;
|
|
// Get the min/max row start/end for the arg values
|
|
rowStart = rowStart ?? 0;
|
|
rowEnd = rowEnd ?? this._rowCount - 1;
|
|
// Set the properties to the updated values
|
|
this._rowStart = this._rowStart !== undefined ? Math.min(this._rowStart, rowStart) : rowStart;
|
|
this._rowEnd = this._rowEnd !== undefined ? Math.max(this._rowEnd, rowEnd) : rowEnd;
|
|
|
|
if (this._animationFrame) {
|
|
return;
|
|
}
|
|
|
|
this._animationFrame = this._coreBrowserService.window.requestAnimationFrame(() => this._innerRefresh());
|
|
}
|
|
|
|
private _innerRefresh(): void {
|
|
this._animationFrame = undefined;
|
|
|
|
// Make sure values are set
|
|
if (this._rowStart === undefined || this._rowEnd === undefined || this._rowCount === undefined) {
|
|
this._runRefreshCallbacks();
|
|
return;
|
|
}
|
|
|
|
// Clamp values
|
|
const start = Math.max(this._rowStart, 0);
|
|
const end = Math.min(this._rowEnd, this._rowCount - 1);
|
|
|
|
// Reset debouncer (this happens before render callback as the render could trigger it again)
|
|
this._rowStart = undefined;
|
|
this._rowEnd = undefined;
|
|
|
|
// Run render callback
|
|
this._renderCallback(start, end);
|
|
this._runRefreshCallbacks();
|
|
}
|
|
|
|
private _runRefreshCallbacks(): void {
|
|
for (const callback of this._refreshCallbacks) {
|
|
callback(0);
|
|
}
|
|
this._refreshCallbacks = [];
|
|
}
|
|
}
|