@payfit/unity-components
Version:
49 lines (48 loc) • 2.02 kB
JavaScript
var e = {
hasOverflowInline: !1,
hasOverflowBlock: !1,
canScrollInlineStart: !1,
canScrollInlineEnd: !1,
canScrollBlockStart: !1,
canScrollBlockEnd: !1
}, t;
function n() {
if (t) return t;
if (typeof document > "u") return "negative";
let e = document.createElement("div"), n = document.createElement("div");
return e.dir = "rtl", e.style.cssText = "width:4px;height:1px;overflow:scroll;visibility:hidden;position:absolute;top:-9999px;", n.style.width = "8px", e.append(n), document.body.append(e), e.scrollLeft > 0 ? t = "default" : (e.scrollLeft = 1, t = e.scrollLeft === 0 ? "negative" : "reverse"), e.remove(), t;
}
function r(e, t) {
return Math.min(Math.max(e, 0), t);
}
function i(e, t, i = n()) {
let a = Math.max(e.scrollWidth - e.clientWidth, 0);
if (t === "ltr") return r(e.scrollLeft, a);
switch (i) {
case "default": return r(a - e.scrollLeft, a);
case "negative": return r(-e.scrollLeft, a);
case "reverse": return r(e.scrollLeft, a);
}
}
function a(e) {
return e > 1;
}
function o(e, t) {
return t - e > 1;
}
function s(e, t = "both") {
let n = t === "inline" || t === "both", s = t === "block" || t === "both", c = Math.max(e.scrollWidth - e.clientWidth, 0), l = Math.max(e.scrollHeight - e.clientHeight, 0), u = i(e, getComputedStyle(e).direction === "rtl" ? "rtl" : "ltr"), d = r(e.scrollTop, l), f = n && c > 1, p = s && l > 1;
return {
hasOverflowInline: f,
hasOverflowBlock: p,
canScrollInlineStart: f && a(u),
canScrollInlineEnd: f && o(u, c),
canScrollBlockStart: p && a(d),
canScrollBlockEnd: p && o(d, l)
};
}
function c(e, t) {
return e.hasOverflowInline === t.hasOverflowInline && e.hasOverflowBlock === t.hasOverflowBlock && e.canScrollInlineStart === t.canScrollInlineStart && e.canScrollInlineEnd === t.canScrollInlineEnd && e.canScrollBlockStart === t.canScrollBlockStart && e.canScrollBlockEnd === t.canScrollBlockEnd;
}
//#endregion
export { c as areScrollEdgesEqual, e as emptyScrollEdges, i as getLogicalInlineScrollOffset, s as getScrollEdges };