Korbs/Contour
Archived
Template
1
Fork 0
This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
Contour/public/@shoelace-style/shoelace/cdn/chunks/chunk.ESELY2US.js
2024-01-30 10:59:28 -05: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
};