mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-23 11:00:35 +03:00
improve code
This commit is contained in:
+190
-150
@@ -387,17 +387,18 @@ const g = window.clearTimeout;
|
|||||||
const h = /[^\x20\t\r\n\f]+/g;
|
const h = /[^\x20\t\r\n\f]+/g;
|
||||||
|
|
||||||
const classListAction = (t, n, o) => {
|
const classListAction = (t, n, o) => {
|
||||||
let s;
|
const s = t && t.classList;
|
||||||
let e = 0;
|
let e;
|
||||||
let c = false;
|
let c = 0;
|
||||||
if (t && n && isString(n)) {
|
let r = false;
|
||||||
const r = n.match(h) || [];
|
if (s && n && isString(n)) {
|
||||||
c = r.length > 0;
|
const t = n.match(h) || [];
|
||||||
while (s = r[e++]) {
|
r = t.length > 0;
|
||||||
c = !!o(t.classList, s) && c;
|
while (e = t[c++]) {
|
||||||
|
r = !!o(s, e) && r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c;
|
return r;
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasClass = (t, n) => classListAction(t, n, ((t, n) => t.contains(n)));
|
const hasClass = (t, n) => classListAction(t, n, ((t, n) => t.contains(n)));
|
||||||
@@ -1108,8 +1109,11 @@ const bt = {
|
|||||||
return [ arrangeViewport, undoViewportArrange ];
|
return [ arrangeViewport, undoViewportArrange ];
|
||||||
},
|
},
|
||||||
j: () => {
|
j: () => {
|
||||||
let t = windowSize();
|
let t = {
|
||||||
let n = getWindowDPR();
|
w: 0,
|
||||||
|
h: 0
|
||||||
|
};
|
||||||
|
let n = 0;
|
||||||
return (o, s, e) => {
|
return (o, s, e) => {
|
||||||
const c = windowSize();
|
const c = windowSize();
|
||||||
const r = {
|
const r = {
|
||||||
@@ -1130,7 +1134,7 @@ const bt = {
|
|||||||
const a = getWindowDPR();
|
const a = getWindowDPR();
|
||||||
const u = i.w > 2 && i.h > 2;
|
const u = i.w > 2 && i.h > 2;
|
||||||
const d = !diffBiggerThanOne(l.w, l.h);
|
const d = !diffBiggerThanOne(l.w, l.h);
|
||||||
const f = a !== n && n > 0;
|
const f = a !== n && a > 0;
|
||||||
const _ = u && d && f;
|
const _ = u && d && f;
|
||||||
if (_) {
|
if (_) {
|
||||||
const [t, n] = s();
|
const [t, n] = s();
|
||||||
@@ -1733,11 +1737,7 @@ const createStructureSetupUpdate = (t, n) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const It = "animationstart";
|
const It = 3333333;
|
||||||
|
|
||||||
const Tt = "scroll";
|
|
||||||
|
|
||||||
const Et = 3333333;
|
|
||||||
|
|
||||||
const getElmDirectionIsRTL = t => "rtl" === style(t, "direction");
|
const getElmDirectionIsRTL = t => "rtl" === style(t, "direction");
|
||||||
|
|
||||||
@@ -1776,8 +1776,8 @@ const createSizeObserver = (t, n, o) => {
|
|||||||
}
|
}
|
||||||
if (s && a) {
|
if (s && a) {
|
||||||
const n = e ? t[0] : getElmDirectionIsRTL(l);
|
const n = e ? t[0] : getElmDirectionIsRTL(l);
|
||||||
scrollLeft(l, n ? r.n ? -Et : r.i ? 0 : Et : Et);
|
scrollLeft(l, n ? r.n ? -It : r.i ? 0 : It : It);
|
||||||
scrollTop(l, Et);
|
scrollTop(l, It);
|
||||||
}
|
}
|
||||||
if (!c) {
|
if (!c) {
|
||||||
n({
|
n({
|
||||||
@@ -1806,7 +1806,7 @@ const createSizeObserver = (t, n, o) => {
|
|||||||
u: !d()
|
u: !d()
|
||||||
}, d);
|
}, d);
|
||||||
const [t] = h;
|
const [t] = h;
|
||||||
push(_, on(l, Tt, (n => {
|
push(_, on(l, "scroll", (n => {
|
||||||
const o = t();
|
const o = t();
|
||||||
const [s, e] = o;
|
const [s, e] = o;
|
||||||
if (e) {
|
if (e) {
|
||||||
@@ -1823,7 +1823,7 @@ const createSizeObserver = (t, n, o) => {
|
|||||||
}
|
}
|
||||||
if (g) {
|
if (g) {
|
||||||
addClass(l, M);
|
addClass(l, M);
|
||||||
push(_, on(l, It, g, {
|
push(_, on(l, "animationstart", g, {
|
||||||
O: !!u
|
O: !!u
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -1837,45 +1837,52 @@ const createSizeObserver = (t, n, o) => {
|
|||||||
const isHeightIntrinsic = t => 0 === t.h || t.isIntersecting || t.intersectionRatio > 0;
|
const isHeightIntrinsic = t => 0 === t.h || t.isIntersecting || t.intersectionRatio > 0;
|
||||||
|
|
||||||
const createTrinsicObserver = (t, n) => {
|
const createTrinsicObserver = (t, n) => {
|
||||||
const o = createDiv(k);
|
let o;
|
||||||
const s = [];
|
const s = createDiv(k);
|
||||||
const [e] = createCache({
|
const e = [];
|
||||||
|
const [c] = createCache({
|
||||||
u: false
|
u: false
|
||||||
});
|
});
|
||||||
const triggerOnTrinsicChangedCallback = t => {
|
const triggerOnTrinsicChangedCallback = (t, o) => {
|
||||||
if (t) {
|
if (t) {
|
||||||
const o = e(isHeightIntrinsic(t));
|
const s = c(isHeightIntrinsic(t));
|
||||||
const [, s] = o;
|
const [, e] = s;
|
||||||
if (s) {
|
if (e) {
|
||||||
n(o);
|
!o && n(s);
|
||||||
|
return [ s ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const intersectionObserverCallback = (t, n) => {
|
||||||
|
if (t && t.length > 0) {
|
||||||
|
return triggerOnTrinsicChangedCallback(t.pop(), n);
|
||||||
|
}
|
||||||
|
};
|
||||||
if (a) {
|
if (a) {
|
||||||
const n = new a((t => {
|
o = new a((t => intersectionObserverCallback(t)), {
|
||||||
if (t && t.length > 0) {
|
|
||||||
triggerOnTrinsicChangedCallback(t.pop());
|
|
||||||
}
|
|
||||||
}), {
|
|
||||||
root: t
|
root: t
|
||||||
});
|
});
|
||||||
n.observe(o);
|
o.observe(s);
|
||||||
push(s, (() => {
|
push(e, (() => {
|
||||||
n.disconnect();
|
o.disconnect();
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
const onSizeChanged = () => {
|
const onSizeChanged = () => {
|
||||||
const t = offsetSize(o);
|
const t = offsetSize(s);
|
||||||
triggerOnTrinsicChangedCallback(t);
|
triggerOnTrinsicChangedCallback(t);
|
||||||
};
|
};
|
||||||
push(s, createSizeObserver(o, onSizeChanged));
|
push(e, createSizeObserver(s, onSizeChanged));
|
||||||
onSizeChanged();
|
onSizeChanged();
|
||||||
}
|
}
|
||||||
prependChildren(t, o);
|
prependChildren(t, s);
|
||||||
return () => {
|
return [ () => {
|
||||||
runEachAndClear(s);
|
runEachAndClear(e);
|
||||||
removeElements(o);
|
removeElements(s);
|
||||||
};
|
}, () => {
|
||||||
|
if (o) {
|
||||||
|
return intersectionObserverCallback(o.takeRecords(), true);
|
||||||
|
}
|
||||||
|
} ];
|
||||||
};
|
};
|
||||||
|
|
||||||
const createEventContentChange = (t, n, o) => {
|
const createEventContentChange = (t, n, o) => {
|
||||||
@@ -1929,65 +1936,69 @@ const createEventContentChange = (t, n, o) => {
|
|||||||
const createDOMObserver = (t, n, o, s) => {
|
const createDOMObserver = (t, n, o, s) => {
|
||||||
let e = false;
|
let e = false;
|
||||||
const {Mt: c, Rt: r, Dt: i, jt: a, Vt: u, kt: d} = s || {};
|
const {Mt: c, Rt: r, Dt: i, jt: a, Vt: u, kt: d} = s || {};
|
||||||
const [f, _] = createEventContentChange(t, debounce((() => {
|
const f = debounce((() => {
|
||||||
if (e) {
|
if (e) {
|
||||||
o(true);
|
o(true);
|
||||||
}
|
}
|
||||||
}), {
|
}), {
|
||||||
v: 33,
|
v: 33,
|
||||||
p: 99
|
p: 99
|
||||||
}), i);
|
});
|
||||||
const g = c || [];
|
const [_, g] = createEventContentChange(t, f, i);
|
||||||
const h = r || [];
|
const h = c || [];
|
||||||
const v = g.concat(h);
|
const v = r || [];
|
||||||
const observerCallback = e => {
|
const w = h.concat(v);
|
||||||
const c = u || noop;
|
const observerCallback = (e, c) => {
|
||||||
const r = d || noop;
|
const r = u || noop;
|
||||||
const i = [];
|
const i = d || noop;
|
||||||
const l = [];
|
const l = [];
|
||||||
let f = false;
|
const f = [];
|
||||||
let g = false;
|
let _ = false;
|
||||||
let v = false;
|
let h = false;
|
||||||
|
let w = false;
|
||||||
each(e, (o => {
|
each(e, (o => {
|
||||||
const {attributeName: e, target: u, type: d, oldValue: _, addedNodes: w} = o;
|
const {attributeName: e, target: c, type: u, oldValue: d, addedNodes: g} = o;
|
||||||
const p = "attributes" === d;
|
const p = "attributes" === u;
|
||||||
const b = "childList" === d;
|
const b = "childList" === u;
|
||||||
const y = t === u;
|
const y = t === c;
|
||||||
const m = p && isString(e) ? attr(u, e) : 0;
|
const m = p && isString(e) ? attr(c, e) : 0;
|
||||||
const S = 0 !== m && _ !== m;
|
const S = 0 !== m && d !== m;
|
||||||
const x = indexOf(h, e) > -1 && S;
|
const x = indexOf(v, e) > -1 && S;
|
||||||
if (n && !y) {
|
if (n && !y) {
|
||||||
const n = !p;
|
const n = !p;
|
||||||
const i = p && x;
|
const l = p && x;
|
||||||
const d = i && a && is(u, a);
|
const u = l && a && is(c, a);
|
||||||
const f = d ? !c(u, e, _, m) : n || i;
|
const _ = u ? !r(c, e, d, m) : n || l;
|
||||||
const h = f && !r(o, !!d, t, s);
|
const v = _ && !i(o, !!u, t, s);
|
||||||
push(l, w);
|
push(f, g);
|
||||||
g = g || h;
|
h = h || v;
|
||||||
v = v || b;
|
w = w || b;
|
||||||
}
|
}
|
||||||
if (!n && y && S && !c(u, e, _, m)) {
|
if (!n && y && S && !r(c, e, d, m)) {
|
||||||
push(i, e);
|
push(l, e);
|
||||||
f = f || x;
|
_ = _ || x;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
if (v && !isEmptyArray(l)) {
|
if (w && !isEmptyArray(f)) {
|
||||||
_((t => l.reduce(((n, o) => {
|
g((t => f.reduce(((n, o) => {
|
||||||
push(n, find(t, o));
|
push(n, find(t, o));
|
||||||
return is(o, t) ? push(n, o) : n;
|
return is(o, t) ? push(n, o) : n;
|
||||||
}), [])));
|
}), [])));
|
||||||
}
|
}
|
||||||
if (n) {
|
if (n) {
|
||||||
g && o(false);
|
!c && h && o(false);
|
||||||
} else if (!isEmptyArray(i) || f) {
|
return [ false ];
|
||||||
o(i, f);
|
}
|
||||||
|
if (!isEmptyArray(l) || _) {
|
||||||
|
!c && o(l, _);
|
||||||
|
return [ l, _ ];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const w = new l(observerCallback);
|
const p = new l((t => observerCallback(t)));
|
||||||
w.observe(t, {
|
p.observe(t, {
|
||||||
attributes: true,
|
attributes: true,
|
||||||
attributeOldValue: true,
|
attributeOldValue: true,
|
||||||
attributeFilter: v,
|
attributeFilter: w,
|
||||||
subtree: n,
|
subtree: n,
|
||||||
childList: n,
|
childList: n,
|
||||||
characterData: n
|
characterData: n
|
||||||
@@ -1995,26 +2006,28 @@ const createDOMObserver = (t, n, o, s) => {
|
|||||||
e = true;
|
e = true;
|
||||||
return [ () => {
|
return [ () => {
|
||||||
if (e) {
|
if (e) {
|
||||||
f();
|
_();
|
||||||
w.disconnect();
|
p.disconnect();
|
||||||
e = false;
|
e = false;
|
||||||
}
|
}
|
||||||
}, () => {
|
}, () => {
|
||||||
if (e) {
|
if (e) {
|
||||||
observerCallback(w.takeRecords());
|
f.S();
|
||||||
|
const t = p.takeRecords();
|
||||||
|
return !isEmptyArray(t) && observerCallback(t, true);
|
||||||
}
|
}
|
||||||
} ];
|
} ];
|
||||||
};
|
};
|
||||||
|
|
||||||
const Pt = `[${x}]`;
|
const Tt = `[${x}]`;
|
||||||
|
|
||||||
const Lt = `.${I}`;
|
const Et = `.${I}`;
|
||||||
|
|
||||||
const Ht = [ "tabindex" ];
|
const Pt = [ "tabindex" ];
|
||||||
|
|
||||||
const Mt = [ "wrap", "cols", "rows" ];
|
const Lt = [ "wrap", "cols", "rows" ];
|
||||||
|
|
||||||
const Rt = [ "id", "class", "style", "open" ];
|
const Ht = [ "id", "class", "style", "open" ];
|
||||||
|
|
||||||
const createStructureSetupObservers = (t, n, o) => {
|
const createStructureSetupObservers = (t, n, o) => {
|
||||||
let s;
|
let s;
|
||||||
@@ -2041,7 +2054,7 @@ const createStructureSetupObservers = (t, n, o) => {
|
|||||||
h: o.h + n.h + s.h
|
h: o.h + n.h + s.h
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
const p = d ? Mt : Rt.concat(Mt);
|
const p = d ? Lt : Ht.concat(Lt);
|
||||||
const b = debounce(o, {
|
const b = debounce(o, {
|
||||||
v: () => s,
|
v: () => s,
|
||||||
p: () => e,
|
p: () => e,
|
||||||
@@ -2055,8 +2068,8 @@ const createStructureSetupObservers = (t, n, o) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const updateViewportAttrsFromHost = t => {
|
const updateViewportAttrsFromHost = t => {
|
||||||
each(t || Ht, (t => {
|
each(t || Pt, (t => {
|
||||||
if (indexOf(Ht, t) > -1) {
|
if (indexOf(Pt, t) > -1) {
|
||||||
const n = attr(i, t);
|
const n = attr(i, t);
|
||||||
if (isString(n)) {
|
if (isString(n)) {
|
||||||
attr(l, t, n);
|
attr(l, t, n);
|
||||||
@@ -2066,14 +2079,16 @@ const createStructureSetupObservers = (t, n, o) => {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
const onTrinsicChanged = t => {
|
const onTrinsicChanged = (t, n) => {
|
||||||
const [n, s] = t;
|
const [s, e] = t;
|
||||||
|
const c = {
|
||||||
|
gt: e
|
||||||
|
};
|
||||||
r({
|
r({
|
||||||
_t: n
|
_t: s
|
||||||
});
|
|
||||||
o({
|
|
||||||
gt: s
|
|
||||||
});
|
});
|
||||||
|
!n && o(c);
|
||||||
|
return c;
|
||||||
};
|
};
|
||||||
const onSizeChanged = ({ht: t, Ht: n, Lt: s}) => {
|
const onSizeChanged = ({ht: t, Ht: n, Lt: s}) => {
|
||||||
const e = !t || s ? o : b;
|
const e = !t || s ? o : b;
|
||||||
@@ -2090,39 +2105,64 @@ const createStructureSetupObservers = (t, n, o) => {
|
|||||||
bt: c
|
bt: c
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const onContentMutation = t => {
|
const onContentMutation = (t, n) => {
|
||||||
const [, n] = w();
|
const [, s] = w();
|
||||||
const s = t ? o : b;
|
const e = {
|
||||||
if (n) {
|
vt: s
|
||||||
s({
|
};
|
||||||
vt: true
|
const c = t ? o : b;
|
||||||
});
|
if (s) {
|
||||||
|
!n && c(e);
|
||||||
}
|
}
|
||||||
|
return e;
|
||||||
};
|
};
|
||||||
const onHostMutation = (t, n) => {
|
const onHostMutation = (t, n, o) => {
|
||||||
|
const s = {
|
||||||
|
$t: n
|
||||||
|
};
|
||||||
if (n) {
|
if (n) {
|
||||||
b({
|
!o && b(s);
|
||||||
$t: true
|
|
||||||
});
|
|
||||||
} else if (!f) {
|
} else if (!f) {
|
||||||
updateViewportAttrsFromHost(t);
|
updateViewportAttrsFromHost(t);
|
||||||
}
|
}
|
||||||
|
return s;
|
||||||
};
|
};
|
||||||
const y = (a || !v) && createTrinsicObserver(i, onTrinsicChanged);
|
const y = (a || !v) && createTrinsicObserver(i, onTrinsicChanged);
|
||||||
const m = !f && createSizeObserver(i, onSizeChanged, {
|
const m = !f && createSizeObserver(i, onSizeChanged, {
|
||||||
Lt: true,
|
Lt: true,
|
||||||
Pt: !h
|
Pt: !h
|
||||||
});
|
});
|
||||||
const [S] = createDOMObserver(i, false, onHostMutation, {
|
const [S, x] = createDOMObserver(i, false, onHostMutation, {
|
||||||
Rt: Rt,
|
Rt: Ht,
|
||||||
Mt: Rt.concat(Ht)
|
Mt: Ht.concat(Pt)
|
||||||
});
|
});
|
||||||
const x = f && new u(onSizeChanged.bind(0, {
|
const C = f && new u(onSizeChanged.bind(0, {
|
||||||
ht: true
|
ht: true
|
||||||
}));
|
}));
|
||||||
x && x.observe(i);
|
C && C.observe(i);
|
||||||
updateViewportAttrsFromHost();
|
updateViewportAttrsFromHost();
|
||||||
return [ t => {
|
return [ () => {
|
||||||
|
c && c[0]();
|
||||||
|
y && y[0]();
|
||||||
|
m && m();
|
||||||
|
C && C.disconnect();
|
||||||
|
S();
|
||||||
|
}, () => {
|
||||||
|
const t = {};
|
||||||
|
const n = x();
|
||||||
|
const o = c && c[1]();
|
||||||
|
const s = y && y[1]();
|
||||||
|
if (n) {
|
||||||
|
assignDeep(t, onHostMutation.apply(0, push(n, true)));
|
||||||
|
}
|
||||||
|
if (o) {
|
||||||
|
assignDeep(t, onContentMutation.apply(0, push(o, true)));
|
||||||
|
}
|
||||||
|
if (s) {
|
||||||
|
assignDeep(t, onTrinsicChanged.apply(0, push(s, true)));
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}, t => {
|
||||||
const [n] = t("updating.ignoreMutation");
|
const [n] = t("updating.ignoreMutation");
|
||||||
const [o, r] = t("updating.attributes");
|
const [o, r] = t("updating.attributes");
|
||||||
const [i, u] = t("updating.elementEvents");
|
const [i, u] = t("updating.elementEvents");
|
||||||
@@ -2138,11 +2178,11 @@ const createStructureSetupObservers = (t, n, o) => {
|
|||||||
Rt: p.concat(o || []),
|
Rt: p.concat(o || []),
|
||||||
Mt: p.concat(o || []),
|
Mt: p.concat(o || []),
|
||||||
Dt: i,
|
Dt: i,
|
||||||
jt: Pt,
|
jt: Tt,
|
||||||
kt: (t, n) => {
|
kt: (t, n) => {
|
||||||
const {target: o, attributeName: s} = t;
|
const {target: o, attributeName: s} = t;
|
||||||
const e = !n && s ? liesBetween(o, Pt, Lt) : false;
|
const e = !n && s ? liesBetween(o, Tt, Et) : false;
|
||||||
return e || !!ignoreMutationFromOptions(t);
|
return e || !!closest(o, `.${B}`) || !!ignoreMutationFromOptions(t);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2161,21 +2201,15 @@ const createStructureSetupObservers = (t, n, o) => {
|
|||||||
e = false;
|
e = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, () => {
|
|
||||||
c && c[0]();
|
|
||||||
y && y();
|
|
||||||
m && m();
|
|
||||||
x && x.disconnect();
|
|
||||||
S();
|
|
||||||
} ];
|
} ];
|
||||||
};
|
};
|
||||||
|
|
||||||
const Dt = {
|
const Mt = {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
const jt = {
|
const Rt = {
|
||||||
k: {
|
k: {
|
||||||
t: 0,
|
t: 0,
|
||||||
r: 0,
|
r: 0,
|
||||||
@@ -2192,8 +2226,8 @@ const jt = {
|
|||||||
paddingBottom: 0,
|
paddingBottom: 0,
|
||||||
paddingLeft: 0
|
paddingLeft: 0
|
||||||
},
|
},
|
||||||
Ot: Dt,
|
Ot: Mt,
|
||||||
zt: Dt,
|
zt: Mt,
|
||||||
Ct: {
|
Ct: {
|
||||||
x: "hidden",
|
x: "hidden",
|
||||||
y: "hidden"
|
y: "hidden"
|
||||||
@@ -2208,34 +2242,40 @@ const jt = {
|
|||||||
|
|
||||||
const createStructureSetup = (t, n) => {
|
const createStructureSetup = (t, n) => {
|
||||||
const o = createOptionCheck(n, {});
|
const o = createOptionCheck(n, {});
|
||||||
const s = createState(jt);
|
const s = createState(Rt);
|
||||||
const [e, c, r] = createEventListenerHub();
|
const [e, c, r] = createEventListenerHub();
|
||||||
const [i] = s;
|
const [i] = s;
|
||||||
const [l, a, u] = createStructureSetupElements(t);
|
const [l, a, u] = createStructureSetupElements(t);
|
||||||
const d = createStructureSetupUpdate(l, s);
|
const d = createStructureSetupUpdate(l, s);
|
||||||
const [f, _] = createStructureSetupObservers(l, s, (t => {
|
const triggerUpdateEvent = (t, n, o) => {
|
||||||
r("u", [ d(o, t), {}, false ]);
|
const s = keys(t).some((n => t[n]));
|
||||||
|
if (s || !isEmptyObject(n) || o) {
|
||||||
|
r("u", [ t, n, o ]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const [f, _, g] = createStructureSetupObservers(l, s, (t => {
|
||||||
|
triggerUpdateEvent(d(o, t), {}, false);
|
||||||
}));
|
}));
|
||||||
const g = i.bind(0);
|
const h = i.bind(0);
|
||||||
g.Bt = t => {
|
h.Bt = t => {
|
||||||
e("u", t);
|
e("u", t);
|
||||||
};
|
};
|
||||||
g.Ft = a;
|
h.Ft = a;
|
||||||
g.Yt = l;
|
h.Yt = l;
|
||||||
return [ (t, o) => {
|
return [ (t, o) => {
|
||||||
const s = createOptionCheck(n, t, o);
|
const s = createOptionCheck(n, t, o);
|
||||||
f(s);
|
g(s);
|
||||||
r("u", [ d(s, {}, o), t, !!o ]);
|
triggerUpdateEvent(d(s, _(), o), t, !!o);
|
||||||
}, g, () => {
|
}, h, () => {
|
||||||
c();
|
c();
|
||||||
_();
|
f();
|
||||||
u();
|
u();
|
||||||
} ];
|
} ];
|
||||||
};
|
};
|
||||||
|
|
||||||
const Vt = "touchstart mouseenter";
|
const Dt = "touchstart mouseenter";
|
||||||
|
|
||||||
const kt = "touchend touchcancel mouseleave";
|
const jt = "touchend touchcancel mouseleave";
|
||||||
|
|
||||||
const stopRootClickPropagation = (t, n) => on(t, "mousedown", on.bind(0, n, "click", stopPropagation, {
|
const stopRootClickPropagation = (t, n) => on(t, "mousedown", on.bind(0, n, "click", stopPropagation, {
|
||||||
O: true,
|
O: true,
|
||||||
@@ -2276,10 +2316,10 @@ const createScrollbarsSetupElements = (t, n) => {
|
|||||||
appendChildren(c, r);
|
appendChildren(c, r);
|
||||||
appendChildren(r, i);
|
appendChildren(r, i);
|
||||||
push(o, l);
|
push(o, l);
|
||||||
push(d, [ removeElements.bind(0, c), on(c, Vt, (() => {
|
push(d, [ removeElements.bind(0, c), on(c, Dt, (() => {
|
||||||
h(X, true);
|
h(X, true);
|
||||||
v(X, true);
|
v(X, true);
|
||||||
})), on(c, kt, (() => {
|
})), on(c, jt, (() => {
|
||||||
h(X);
|
h(X);
|
||||||
v(X);
|
v(X);
|
||||||
})), stopRootClickPropagation(c, e) ]);
|
})), stopRootClickPropagation(c, e) ]);
|
||||||
@@ -2416,21 +2456,21 @@ const createScrollbarsSetup = (t, n, o) => {
|
|||||||
}, T, runEachAndClear.bind(0, I) ];
|
}, T, runEachAndClear.bind(0, I) ];
|
||||||
};
|
};
|
||||||
|
|
||||||
const Bt = new Set;
|
const Vt = new Set;
|
||||||
|
|
||||||
const Ft = new WeakMap;
|
const kt = new WeakMap;
|
||||||
|
|
||||||
const addInstance = (t, n) => {
|
const addInstance = (t, n) => {
|
||||||
Ft.set(t, n);
|
kt.set(t, n);
|
||||||
Bt.add(t);
|
Vt.add(t);
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeInstance = t => {
|
const removeInstance = t => {
|
||||||
Ft.delete(t);
|
kt.delete(t);
|
||||||
Bt.delete(t);
|
Vt.delete(t);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getInstance = t => Ft.get(t);
|
const getInstance = t => kt.get(t);
|
||||||
|
|
||||||
const OverlayScrollbars = (t, n, o) => {
|
const OverlayScrollbars = (t, n, o) => {
|
||||||
let s = false;
|
let s = false;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+354
-306
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -153,8 +153,8 @@ const createEnvironment = (): InternalEnvironment => {
|
|||||||
y: nativeScrollbarsSize.y === 0,
|
y: nativeScrollbarsSize.y === 0,
|
||||||
};
|
};
|
||||||
const initializationStrategy = {
|
const initializationStrategy = {
|
||||||
_padding: !nativeScrollbarsHiding,
|
padding: !nativeScrollbarsHiding,
|
||||||
_content: false,
|
content: false,
|
||||||
};
|
};
|
||||||
const defaultDefaultOptions = assignDeep({}, defaultOptions);
|
const defaultDefaultOptions = assignDeep({}, defaultOptions);
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ export interface Options {
|
|||||||
y: OverflowBehavior;
|
y: OverflowBehavior;
|
||||||
};
|
};
|
||||||
scrollbars: {
|
scrollbars: {
|
||||||
|
theme: string | null;
|
||||||
visibility: ScrollbarVisibilityBehavior;
|
visibility: ScrollbarVisibilityBehavior;
|
||||||
autoHide: ScrollbarAutoHideBehavior;
|
autoHide: ScrollbarAutoHideBehavior;
|
||||||
autoHideDelay: number;
|
autoHideDelay: number;
|
||||||
@@ -111,6 +112,7 @@ export const defaultOptions: Options = {
|
|||||||
initialize: false, // true || false
|
initialize: false, // true || false
|
||||||
},
|
},
|
||||||
scrollbars: {
|
scrollbars: {
|
||||||
|
theme: 'os-theme-dark',
|
||||||
visibility: 'auto', // visible || hidden || auto || v || h || a
|
visibility: 'auto', // visible || hidden || auto || v || h || a
|
||||||
autoHide: 'never', // never || scroll || leave || move || n || s || l || m
|
autoHide: 'never', // never || scroll || leave || move || n || s || l || m
|
||||||
autoHideDelay: 800, // number
|
autoHideDelay: 800, // number
|
||||||
|
|||||||
+1
@@ -37,6 +37,7 @@ const optionsTemplate: OptionsTemplate<Options> = {
|
|||||||
y: overflowAllowedValues, // visible-hidden || visible-scroll || hidden || scrol
|
y: overflowAllowedValues, // visible-hidden || visible-scroll || hidden || scrol
|
||||||
},
|
},
|
||||||
scrollbars: {
|
scrollbars: {
|
||||||
|
theme: [oTypes.string, oTypes.null], // string || null
|
||||||
visibility: scrollbarsVisibilityAllowedValues, // visible || hidden || auto || v ||
|
visibility: scrollbarsVisibilityAllowedValues, // visible || hidden || auto || v ||
|
||||||
autoHide: scrollbarsAutoHideAllowedValues, // never || scroll || leave || move ||
|
autoHide: scrollbarsAutoHideAllowedValues, // never || scroll || leave || move ||
|
||||||
autoHideDelay: numberAllowedValues, // number
|
autoHideDelay: numberAllowedValues, // number
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export interface ScrollbarStructure {
|
|||||||
export interface ScrollbarsSetupElement {
|
export interface ScrollbarsSetupElement {
|
||||||
_scrollbarStructures: ScrollbarStructure[];
|
_scrollbarStructures: ScrollbarStructure[];
|
||||||
_clone: () => ScrollbarStructure;
|
_clone: () => ScrollbarStructure;
|
||||||
_addRemoveClass: (classNames: string, add?: boolean) => void;
|
_addRemoveClass: (classNames: string | false | null | undefined, add?: boolean) => void;
|
||||||
// _removeClass: (classNames: string) => void;
|
// _removeClass: (classNames: string) => void;
|
||||||
/*
|
/*
|
||||||
_addEventListener: () => void;
|
_addEventListener: () => void;
|
||||||
@@ -74,11 +74,12 @@ export const createScrollbarsSetupElements = (
|
|||||||
structureSetupElements: StructureSetupElementsObj
|
structureSetupElements: StructureSetupElementsObj
|
||||||
): ScrollbarsSetupElements => {
|
): ScrollbarsSetupElements => {
|
||||||
const { _getInitializationStrategy } = getEnvironment();
|
const { _getInitializationStrategy } = getEnvironment();
|
||||||
const { _scrollbarsSlot: environmentScrollbarSlot } =
|
const { scrollbarsSlot: environmentScrollbarSlot } =
|
||||||
_getInitializationStrategy() as ScrollbarsInitializationStrategy;
|
_getInitializationStrategy() as ScrollbarsInitializationStrategy;
|
||||||
const { _documentElm, _target, _host, _viewport, _targetIsElm } = structureSetupElements;
|
const { _documentElm, _target, _host, _viewport, _targetIsElm } = structureSetupElements;
|
||||||
const initializationScrollbarSlot =
|
const initializationScrollbarSlot = _targetIsElm
|
||||||
!_targetIsElm && (target as ScrollbarsInitialization).scrollbarsSlot;
|
? null
|
||||||
|
: (target as ScrollbarsInitialization).scrollbarsSlot;
|
||||||
const evaluatedScrollbarSlot =
|
const evaluatedScrollbarSlot =
|
||||||
generalDynamicInitializationElement<ScrollbarsDynamicInitializationElement>(
|
generalDynamicInitializationElement<ScrollbarsDynamicInitializationElement>(
|
||||||
[_target, _host, _viewport],
|
[_target, _host, _viewport],
|
||||||
@@ -88,7 +89,7 @@ export const createScrollbarsSetupElements = (
|
|||||||
);
|
);
|
||||||
const scrollbarsAddRemoveClass = (
|
const scrollbarsAddRemoveClass = (
|
||||||
scrollbarStructures: ScrollbarStructure[],
|
scrollbarStructures: ScrollbarStructure[],
|
||||||
classNames: string,
|
classNames: string | false | null | undefined,
|
||||||
add?: boolean
|
add?: boolean
|
||||||
) => {
|
) => {
|
||||||
const action = add ? addClass : removeClass;
|
const action = add ? addClass : removeClass;
|
||||||
@@ -109,7 +110,7 @@ export const createScrollbarsSetupElements = (
|
|||||||
const arrToPush = horizontal ? horizontalScrollbars : verticalScrollbars;
|
const arrToPush = horizontal ? horizontalScrollbars : verticalScrollbars;
|
||||||
const transitionlessClass = isEmptyArray(arrToPush) ? classNamesScrollbarTransitionless : '';
|
const transitionlessClass = isEmptyArray(arrToPush) ? classNamesScrollbarTransitionless : '';
|
||||||
const scrollbar = createDiv(
|
const scrollbar = createDiv(
|
||||||
`${classNameScrollbar} ${scrollbarClassName} ${transitionlessClass} os-theme-dark`
|
`${classNameScrollbar} ${scrollbarClassName} ${transitionlessClass}`
|
||||||
);
|
);
|
||||||
const track = createDiv(classNameScrollbarTrack);
|
const track = createDiv(classNameScrollbarTrack);
|
||||||
const handle = createDiv(classNameScrollbarHandle);
|
const handle = createDiv(classNameScrollbarHandle);
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ export interface ScrollbarsInitialization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type ScrollbarsInitializationStrategy = {
|
export type ScrollbarsInitializationStrategy = {
|
||||||
[K in keyof ScrollbarsInitialization as `_${K}`]: InitializtationElementStrategy<
|
[K in keyof ScrollbarsInitialization]: InitializtationElementStrategy<
|
||||||
ScrollbarsInitialization[K]
|
ScrollbarsInitialization[K]
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -46,11 +46,13 @@ export const createScrollbarsSetup = (
|
|||||||
options: ReadonlyOSOptions,
|
options: ReadonlyOSOptions,
|
||||||
structureSetupState: (() => StructureSetupState) & StructureSetupStaticState
|
structureSetupState: (() => StructureSetupState) & StructureSetupStaticState
|
||||||
): Setup<ScrollbarsSetupState, ScrollbarsSetupStaticState, [StructureSetupUpdateHints]> => {
|
): Setup<ScrollbarsSetupState, ScrollbarsSetupStaticState, [StructureSetupUpdateHints]> => {
|
||||||
let globalAutoHideDelay = 0;
|
|
||||||
let autoHideIsMove: boolean;
|
let autoHideIsMove: boolean;
|
||||||
let autoHideIsLeave: boolean;
|
let autoHideIsLeave: boolean;
|
||||||
let autoHideNotNever: boolean;
|
let autoHideNotNever: boolean;
|
||||||
let mouseInHost: boolean;
|
let mouseInHost: boolean | undefined;
|
||||||
|
let prevTheme: string | null | undefined;
|
||||||
|
let globalAutoHideDelay = 0;
|
||||||
|
|
||||||
const state = createState({});
|
const state = createState({});
|
||||||
const [getState] = state;
|
const [getState] = state;
|
||||||
const [requestMouseMoveAnimationFrame, cancelMouseMoveAnimationFrame] = createSelfCancelTimeout();
|
const [requestMouseMoveAnimationFrame, cancelMouseMoveAnimationFrame] = createSelfCancelTimeout();
|
||||||
@@ -132,6 +134,7 @@ export const createScrollbarsSetup = (
|
|||||||
structureUpdateHints;
|
structureUpdateHints;
|
||||||
const checkOption = createOptionCheck(options, changedOptions, force);
|
const checkOption = createOptionCheck(options, changedOptions, force);
|
||||||
|
|
||||||
|
const [theme, themeChanged] = checkOption<string | null>('scrollbars.theme');
|
||||||
const [visibility, visibilityChanged] =
|
const [visibility, visibilityChanged] =
|
||||||
checkOption<ScrollbarVisibilityBehavior>('scrollbars.visibility');
|
checkOption<ScrollbarVisibilityBehavior>('scrollbars.visibility');
|
||||||
const [autoHide, autoHideChanged] =
|
const [autoHide, autoHideChanged] =
|
||||||
@@ -167,6 +170,14 @@ export const createScrollbarsSetup = (
|
|||||||
addRemoveClassHorizontal(classNamesScrollbarCornerless, !hasCorner);
|
addRemoveClassHorizontal(classNamesScrollbarCornerless, !hasCorner);
|
||||||
addRemoveClassVertical(classNamesScrollbarCornerless, !hasCorner);
|
addRemoveClassVertical(classNamesScrollbarCornerless, !hasCorner);
|
||||||
}
|
}
|
||||||
|
if (themeChanged) {
|
||||||
|
addRemoveClassHorizontal(prevTheme);
|
||||||
|
addRemoveClassVertical(prevTheme);
|
||||||
|
|
||||||
|
addRemoveClassHorizontal(theme, true);
|
||||||
|
addRemoveClassVertical(theme, true);
|
||||||
|
prevTheme = theme;
|
||||||
|
}
|
||||||
if (autoHideChanged) {
|
if (autoHideChanged) {
|
||||||
autoHideIsMove = autoHide === 'move';
|
autoHideIsMove = autoHide === 'move';
|
||||||
autoHideIsLeave = autoHide === 'leave';
|
autoHideIsLeave = autoHide === 'leave';
|
||||||
|
|||||||
@@ -93,10 +93,10 @@ export const createStructureSetupElements = (
|
|||||||
const createUniqueViewportArrangeElement =
|
const createUniqueViewportArrangeElement =
|
||||||
scrollbarsHidingPlugin && scrollbarsHidingPlugin._createUniqueViewportArrangeElement;
|
scrollbarsHidingPlugin && scrollbarsHidingPlugin._createUniqueViewportArrangeElement;
|
||||||
const {
|
const {
|
||||||
_host: hostInitializationStrategy,
|
host: hostInitializationStrategy,
|
||||||
_viewport: viewportInitializationStrategy,
|
viewport: viewportInitializationStrategy,
|
||||||
_padding: paddingInitializationStrategy,
|
padding: paddingInitializationStrategy,
|
||||||
_content: contentInitializationStrategy,
|
content: contentInitializationStrategy,
|
||||||
} = _getInitializationStrategy();
|
} = _getInitializationStrategy();
|
||||||
const targetIsElm = isHTMLElement(target);
|
const targetIsElm = isHTMLElement(target);
|
||||||
const targetStructureInitialization = target as StructureInitialization;
|
const targetStructureInitialization = target as StructureInitialization;
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ export interface StructureInitialization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type StructureInitializationStrategy = {
|
export type StructureInitializationStrategy = {
|
||||||
[K in keyof Omit<StructureInitialization, 'target'> as `_${K}`]: InitializtationElementStrategy<
|
[K in keyof Omit<StructureInitialization, 'target'>]: InitializtationElementStrategy<
|
||||||
StructureInitialization[K]
|
StructureInitialization[K]
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
opacity: 0;
|
opacity: 0;
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
|
body > .os-scrollbar {
|
||||||
|
position: fixed;
|
||||||
|
}
|
||||||
.os-scrollbar-transitionless {
|
.os-scrollbar-transitionless {
|
||||||
transition: none;
|
transition: none;
|
||||||
}
|
}
|
||||||
|
|||||||
+68
@@ -0,0 +1,68 @@
|
|||||||
|
import './index.scss';
|
||||||
|
import 'index.scss';
|
||||||
|
import { OverlayScrollbars } from 'overlayscrollbars';
|
||||||
|
|
||||||
|
OverlayScrollbars.env().setDefaultOptions({
|
||||||
|
nativeScrollbarsOverlaid: { initialize: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
OverlayScrollbars.env().setInitializationStrategy({ viewport: (target) => target });
|
||||||
|
|
||||||
|
window.os = OverlayScrollbars(document.body, {});
|
||||||
|
|
||||||
|
// test viewport inheritted attrs (tabindex) for multiple and single element init
|
||||||
|
// test appear & resize for multiple and single element init
|
||||||
|
// test children changing attr according to dom observer
|
||||||
|
|
||||||
|
/*
|
||||||
|
import { OverlayScrollbars } from 'overlayscrollbars';
|
||||||
|
|
||||||
|
import should from 'should';
|
||||||
|
import { resize } from '@/testing-browser/Resize';
|
||||||
|
import { timeout } from '@/testing-browser/timeout';
|
||||||
|
import { setTestResult, waitForOrFailTest } from '@/testing-browser/TestResult';
|
||||||
|
import { addClass, each, isArray, removeAttr, style } from 'support';
|
||||||
|
|
||||||
|
OverlayScrollbars.env().setDefaultOptions({
|
||||||
|
nativeScrollbarsOverlaid: { initialize: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
const startBtn: HTMLButtonElement | null = document.querySelector('#start');
|
||||||
|
const target: HTMLElement | null = document.querySelector('#target');
|
||||||
|
const updatesSlot: HTMLElement | null = document.querySelector('#update');
|
||||||
|
|
||||||
|
let updateCount = 0;
|
||||||
|
|
||||||
|
const osInstance = OverlayScrollbars(
|
||||||
|
{ target: target! },
|
||||||
|
{
|
||||||
|
updating: {
|
||||||
|
ignoreMutation(mutation) {
|
||||||
|
console.log(mutation);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
updated() {
|
||||||
|
updateCount++;
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (updatesSlot) {
|
||||||
|
updatesSlot.textContent = `${updateCount}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const start = async () => {
|
||||||
|
setTestResult(null);
|
||||||
|
|
||||||
|
setTestResult(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
startBtn?.addEventListener('click', start);
|
||||||
|
*/
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<div id="content">content</div>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
body {
|
||||||
|
}
|
||||||
|
|
||||||
|
#content {
|
||||||
|
background: rgba(255, 0, 0, 0.4);
|
||||||
|
height: 200vh;
|
||||||
|
width: 200vw;
|
||||||
|
border: 2px solid blue;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// @ts-ignore
|
||||||
|
import { playwrightRollup, expectSuccess } from '@/playwright/rollup';
|
||||||
|
import { test } from '@playwright/test';
|
||||||
|
|
||||||
|
playwrightRollup();
|
||||||
|
|
||||||
|
test.describe('StructureSetup.elements', () => {
|
||||||
|
test('nesting updates', async ({ page }) => {
|
||||||
|
await page.click('#start');
|
||||||
|
await expectSuccess(page);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user