UNPKG

@opensig/opendesign

Version:

33 lines (32 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const vue = require("vue"); const core = require("@vueuse/core"); function useWheel(opts) { const { wrapperRef, isHorizontal, axis } = opts; const onWheel = (e) => { const el = wrapperRef.value; if (!el) { return; } const scrollPos = axis.getScroll(el); const maxScroll = axis.getScrollSize(el) - axis.getClientSize(el); const atStartEdge = scrollPos <= 0; const atEndEdge = scrollPos >= maxScroll; const delta = isHorizontal.value ? e.deltaX || (e.shiftKey ? e.deltaY : 0) : e.deltaY; if (atStartEdge && delta < 0 || atEndEdge && delta > 0) { e.preventDefault(); } }; vue.onMounted(() => { core.until(wrapperRef).toBeTruthy().then(() => { var _a; (_a = wrapperRef.value) == null ? void 0 : _a.addEventListener("wheel", onWheel, { passive: false }); }); }); vue.onBeforeUnmount(() => { var _a; (_a = wrapperRef.value) == null ? void 0 : _a.removeEventListener("wheel", onWheel); }); } exports.useWheel = useWheel;