UNPKG

@aplus-frontend/ui

Version:

38 lines (37 loc) 859 B
import { useRafFn as x } from "@vueuse/core"; import "../../scroll-bar/index.mjs"; import { ensureRangeValue as u } from "../../scroll-bar/utils/index.mjs"; const m = { horizontal: "x", vertical: "y" }, p = () => { }, M = (e) => 1 - Math.pow(1 - e, 3), y = ({ scrollOffset: e, maxScrollDistance: d, timer: l = 500, onScroll: n = p, onScrollEnd: f = p }) => { let a, t, i; const { pause: r, resume: g, isActive: h } = x( () => { const o = Date.now(), s = m[t], T = o - a, c = u(T / l, 0, 1), v = M(c); c === 1 ? (e[s] = 0, r(), n(t), f(t)) : (e[s] = u( i * (1 - v), 0, d[s] ), n(t)); }, { immediate: !1 } ); function w(o) { t = o, a = Date.now(), i = e[m[o]], g(); } function D() { r(); } return { start: w, stop: D, isActive: h }; }; export { y as useScrollBack };