@aplus-frontend/ui
Version:
53 lines (52 loc) • 1.14 kB
JavaScript
import { getScrollable as r } from "../../scroll-bar/utils/index.mjs";
import { ref as a, reactive as f, watch as p, unref as b } from "vue";
const B = () => {
const t = a(), c = f({ x: 0, y: 0 }), n = f({ x: 0, y: 0 }), i = a(), s = a();
p(
() => t.value,
() => {
u();
}
);
function u() {
const e = b(t);
if (!e)
return;
const { visibleSize: o, totalSize: l } = r(
e,
"horizontal"
), { visibleSize: z, totalSize: x } = r(e, "vertical");
c.x = l - o, c.y = x - z;
}
function v() {
if (!t.value)
return;
const { totalSize: e, visibleSize: o } = r(
t.value,
"vertical"
), l = n.y / (e - o || 1) * 100;
s.value?.scroll(l);
}
function S() {
if (!t.value)
return;
const { totalSize: e, visibleSize: o } = r(
t.value,
"horizontal"
), l = n.x / (e - o || 1) * 100;
i.value?.scroll(l);
}
return {
maxScrollDistance: c,
scrollOffset: n,
xBarRef: i,
yBarRef: s,
scrollYBar: v,
scrollXBar: S,
containerRef: t,
updateMaxScrollDistance: u
};
};
export {
B as default
};