dockview-core
Version:
Zero dependency layout manager supporting tabs, groups, grids and splitviews for vanilla TypeScript
45 lines (44 loc) • 2.03 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PointerGhost = void 0;
/**
* Floating clone that follows the pointer; appended to the owning
* document's body with `pointer-events: none` so it doesn't intercept
* hit-testing.
*/
var PointerGhost = /** @class */ (function () {
function PointerGhost(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(".concat(opts.initialX - this.offsetX, "px, ").concat(opts.initialY - this.offsetY, "px, 0)");
var ownerDocument = (_e = (_d = opts.owner) === null || _d === void 0 ? void 0 : _d.ownerDocument) !== null && _e !== void 0 ? _e : document;
ownerDocument.body.appendChild(this.element);
}
PointerGhost.prototype.update = function (clientX, clientY) {
if (this._disposed) {
return;
}
// translate3d composites on the GPU — no layout per pointermove.
this.element.style.transform = "translate3d(".concat(clientX - this.offsetX, "px, ").concat(clientY - this.offsetY, "px, 0)");
};
PointerGhost.prototype.dispose = function () {
if (this._disposed) {
return;
}
this._disposed = true;
this.element.remove();
};
return PointerGhost;
}());
exports.PointerGhost = PointerGhost;