dockview-core
Version:
Zero dependency layout manager supporting tabs, groups, grids and splitviews for vanilla TypeScript
40 lines (39 loc) • 1.71 kB
JavaScript
/**
* Floating clone that follows the pointer; appended to the owning
* document's body with `pointer-events: none` so it doesn't intercept
* hit-testing.
*/
export class PointerGhost {
constructor(opts) {
var _a, _b, _c, _d, _e;
this._disposed = false;
this.element = opts.element;
this.offsetX = (_a = opts.offsetX) !== null && _a !== void 0 ? _a : 0;
this.offsetY = (_b = opts.offsetY) !== null && _b !== void 0 ? _b : 0;
// Animate via transform (see update); position:fixed for scroll-independence.
this.element.style.position = 'fixed';
this.element.style.left = '0px';
this.element.style.top = '0px';
this.element.style.pointerEvents = 'none';
this.element.style.zIndex = '99999';
this.element.style.opacity = String((_c = opts.opacity) !== null && _c !== void 0 ? _c : 0.8);
this.element.style.willChange = 'transform';
this.element.style.transform = `translate3d(${opts.initialX - this.offsetX}px, ${opts.initialY - this.offsetY}px, 0)`;
const ownerDocument = (_e = (_d = opts.owner) === null || _d === void 0 ? void 0 : _d.ownerDocument) !== null && _e !== void 0 ? _e : document;
ownerDocument.body.appendChild(this.element);
}
update(clientX, clientY) {
if (this._disposed) {
return;
}
// translate3d composites on the GPU — no layout per pointermove.
this.element.style.transform = `translate3d(${clientX - this.offsetX}px, ${clientY - this.offsetY}px, 0)`;
}
dispose() {
if (this._disposed) {
return;
}
this._disposed = true;
this.element.remove();
}
}