@dialpad/dialtone
Version:
Dialpad's Dialtone design system monorepo
65 lines (64 loc) • 1.71 kB
JavaScript
//#region common/mixins/dom.js
var e = { methods: {
scrollElementIntoViewIfNeeded(e, t, n, r) {
e.scrollIntoViewIfNeeded ? this.scrollIntoViewIfNeeded(e, t, n, r) : this.scrollIntoView(e, "bottom", !1, n, r);
},
scrollElementIntoView(e, t, n, r) {
if (t === "center") {
this.scrollIntoView(e, "center", !1, n, r);
return;
}
t === !1 ? this.scrollIntoView(e, "bottom", !1, n, r) : this.scrollIntoView(e, "top", !1, n, r);
},
scrollIntoViewIfNeeded(e, t, n, r) {
let i = t ? "center" : void 0;
this.scrollIntoView(e, i, !0, n, r);
},
scrollIntoView(e, t, n, r, i) {
if (!e || !e.parentElement) return;
let a = e.offsetTop, o = i || e.parentElement, s = this._getScrollBounds(o), c = s.bottom - s.top, l = this._getElementHeight(e), u = a + l, d = -1;
switch (t) {
case "top":
d = a;
break;
case "center":
d = a + (l - c) / 2;
break;
case "bottom":
d = d = u - c;
break;
default:
d = a - s.top <= c / 2 ? a : u - c;
break;
}
this._setScrollTop(o, d, s, a, u, n, r);
},
_setScrollTop(e, t, n, r, i, a, o) {
n = n || this._getScrollBounds(e);
let s = n.bottom - n.top;
if (a && this._inScrollBounds(r, i, n)) if (r < n.top) t = r;
else if (i > n.bottom) t = i - s;
else return;
o ? e.scrollTo({
top: t,
behavior: o
}) : e.scrollTop = t;
},
_getElementHeight(e) {
return e.getBoundingClientRect().height;
},
_getScrollBounds(e) {
let t = this._getElementHeight(e), n = e.scrollTop;
return {
top: n,
bottom: n + t
};
},
_inScrollBounds(e, t, n) {
let r = t - e;
return t <= n.bottom + 3 * r / 4 && e >= n.top - r / 4;
}
} };
//#endregion
export { e as default };
//# sourceMappingURL=dom.js.map