Icard/angular-clarity-master(work.../node_modules/angular-gridster2/esm2022/lib/gridsterScroll.service.mjs

134 lines
16 KiB
JavaScript

let scrollSensitivity;
let scrollSpeed;
const intervalDuration = 50;
let gridsterElement;
let resizeEvent;
let resizeEventType;
let intervalE;
let intervalW;
let intervalN;
let intervalS;
export function scroll(gridster, left, top, width, height, event, lastMouse, calculateItemPosition, resize, resizeEventScrollType) {
scrollSensitivity = gridster.$options.scrollSensitivity;
scrollSpeed = gridster.$options.scrollSpeed;
gridsterElement = gridster.el;
resizeEvent = resize;
resizeEventType = resizeEventScrollType;
const offsetWidth = gridsterElement.offsetWidth;
const offsetHeight = gridsterElement.offsetHeight;
const offsetLeft = gridsterElement.scrollLeft;
const offsetTop = gridsterElement.scrollTop;
const elemTopOffset = top - offsetTop;
const elemBottomOffset = offsetHeight + offsetTop - top - height;
const { clientX, clientY } = event;
if (!gridster.$options.disableScrollVertical) {
if (lastMouse.clientY < clientY && elemBottomOffset < scrollSensitivity) {
cancelN();
if ((resizeEvent && resizeEventType && !resizeEventType.south) ||
intervalS) {
return;
}
intervalS = startVertical(1, calculateItemPosition, lastMouse);
}
else if (lastMouse.clientY > clientY &&
offsetTop > 0 &&
elemTopOffset < scrollSensitivity) {
cancelS();
if ((resizeEvent && resizeEventType && !resizeEventType.north) ||
intervalN) {
return;
}
intervalN = startVertical(-1, calculateItemPosition, lastMouse);
}
else if (lastMouse.clientY !== clientY) {
cancelVertical();
}
}
const elemRightOffset = offsetLeft + offsetWidth - left - width;
const elemLeftOffset = left - offsetLeft;
if (!gridster.$options.disableScrollHorizontal) {
if (lastMouse.clientX < clientX && elemRightOffset <= scrollSensitivity) {
cancelW();
if ((resizeEvent && resizeEventType && !resizeEventType.east) ||
intervalE) {
return;
}
intervalE = startHorizontal(1, calculateItemPosition, lastMouse);
}
else if (lastMouse.clientX > clientX &&
offsetLeft > 0 &&
elemLeftOffset < scrollSensitivity) {
cancelE();
if ((resizeEvent && resizeEventType && !resizeEventType.west) ||
intervalW) {
return;
}
intervalW = startHorizontal(-1, calculateItemPosition, lastMouse);
}
else if (lastMouse.clientX !== clientX) {
cancelHorizontal();
}
}
}
function startVertical(sign, calculateItemPosition, lastMouse) {
let clientY = lastMouse.clientY;
return window.setInterval(() => {
if (!gridsterElement ||
(sign === -1 && gridsterElement.scrollTop - scrollSpeed < 0)) {
cancelVertical();
}
gridsterElement.scrollTop += sign * scrollSpeed;
clientY += sign * scrollSpeed;
calculateItemPosition({ clientX: lastMouse.clientX, clientY });
}, intervalDuration);
}
function startHorizontal(sign, calculateItemPosition, lastMouse) {
let clientX = lastMouse.clientX;
return window.setInterval(() => {
if (!gridsterElement ||
(sign === -1 && gridsterElement.scrollLeft - scrollSpeed < 0)) {
cancelHorizontal();
}
gridsterElement.scrollLeft += sign * scrollSpeed;
clientX += sign * scrollSpeed;
calculateItemPosition({ clientX, clientY: lastMouse.clientY });
}, intervalDuration);
}
export function cancelScroll() {
cancelHorizontal();
cancelVertical();
gridsterElement = null;
}
function cancelHorizontal() {
cancelE();
cancelW();
}
function cancelVertical() {
cancelN();
cancelS();
}
function cancelE() {
if (intervalE) {
clearInterval(intervalE);
intervalE = 0;
}
}
function cancelW() {
if (intervalW) {
clearInterval(intervalW);
intervalW = 0;
}
}
function cancelS() {
if (intervalS) {
clearInterval(intervalS);
intervalS = 0;
}
}
function cancelN() {
if (intervalN) {
clearInterval(intervalN);
intervalN = 0;
}
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3JpZHN0ZXJTY3JvbGwuc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL2FuZ3VsYXItZ3JpZHN0ZXIyL3NyYy9saWIvZ3JpZHN0ZXJTY3JvbGwuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFHQSxJQUFJLGlCQUF5QixDQUFDO0FBQzlCLElBQUksV0FBb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