sudovanilla-website/public/@shoelace-style/shoelace/cdn/chunks/chunk.ESELY2US.js
2024-05-13 23:34:06 -04:00

30 lines
962 B
JavaScript

// src/internal/drag.ts
function drag(container, options) {
function move(pointerEvent) {
const dims = container.getBoundingClientRect();
const defaultView = container.ownerDocument.defaultView;
const offsetX = dims.left + defaultView.scrollX;
const offsetY = dims.top + defaultView.scrollY;
const x = pointerEvent.pageX - offsetX;
const y = pointerEvent.pageY - offsetY;
if (options == null ? void 0 : options.onMove) {
options.onMove(x, y);
}
}
function stop() {
document.removeEventListener("pointermove", move);
document.removeEventListener("pointerup", stop);
if (options == null ? void 0 : options.onStop) {
options.onStop();
}
}
document.addEventListener("pointermove", move, { passive: true });
document.addEventListener("pointerup", stop);
if ((options == null ? void 0 : options.initialEvent) instanceof PointerEvent) {
move(options.initialEvent);
}
}
export {
drag
};