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>
49 lines
2.1 KiB
TypeScript
49 lines
2.1 KiB
TypeScript
/**
|
|
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
|
* @license MIT
|
|
*/
|
|
|
|
import jsdom = require('jsdom');
|
|
import { assert } from 'chai';
|
|
import { getCoords } from './Mouse';
|
|
|
|
const CHAR_WIDTH = 10;
|
|
const CHAR_HEIGHT = 20;
|
|
|
|
describe('Mouse getCoords', () => {
|
|
let windowOverride: Pick<Window, 'getComputedStyle'>;
|
|
let document: Document;
|
|
|
|
beforeEach(() => {
|
|
windowOverride = {
|
|
getComputedStyle(): any {
|
|
return {
|
|
getPropertyValue: () => '0px'
|
|
} as Pick<CSSStyleDeclaration, 'getPropertyValue'>;
|
|
}
|
|
};
|
|
document = new jsdom.JSDOM('').window.document;
|
|
});
|
|
|
|
it('should return the cell that was clicked', () => {
|
|
let coords: [number, number] | undefined;
|
|
coords = getCoords(windowOverride, { clientX: CHAR_WIDTH / 2, clientY: CHAR_HEIGHT / 2 }, document.createElement('div'), 10, 10, true, CHAR_WIDTH, CHAR_HEIGHT);
|
|
assert.deepEqual(coords, [1, 1]);
|
|
coords = getCoords(windowOverride, { clientX: CHAR_WIDTH, clientY: CHAR_HEIGHT }, document.createElement('div'), 10, 10, true, CHAR_WIDTH, CHAR_HEIGHT);
|
|
assert.deepEqual(coords, [1, 1]);
|
|
coords = getCoords(windowOverride, { clientX: CHAR_WIDTH, clientY: CHAR_HEIGHT + 1 }, document.createElement('div'), 10, 10, true, CHAR_WIDTH, CHAR_HEIGHT);
|
|
assert.deepEqual(coords, [1, 2]);
|
|
coords = getCoords(windowOverride, { clientX: CHAR_WIDTH + 1, clientY: CHAR_HEIGHT }, document.createElement('div'), 10, 10, true, CHAR_WIDTH, CHAR_HEIGHT);
|
|
assert.deepEqual(coords, [2, 1]);
|
|
});
|
|
|
|
it('should ensure the coordinates are returned within the terminal bounds', () => {
|
|
let coords: [number, number] | undefined;
|
|
coords = getCoords(windowOverride, { clientX: -1, clientY: -1 }, document.createElement('div'), 10, 10, true, CHAR_WIDTH, CHAR_HEIGHT);
|
|
assert.deepEqual(coords, [1, 1]);
|
|
// Event are double the cols/rows
|
|
coords = getCoords(windowOverride, { clientX: CHAR_WIDTH * 20, clientY: CHAR_HEIGHT * 20 }, document.createElement('div'), 10, 10, true, CHAR_WIDTH, CHAR_HEIGHT);
|
|
assert.deepEqual(coords, [10, 10], 'coordinates should never come back as larger than the terminal');
|
|
});
|
|
});
|