index3.js 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. function J(e) {
  2. return typeof e == "object" && e != null && e.nodeType === 1;
  3. }
  4. function R(e, t) {
  5. return (!t || e !== "hidden") && e !== "visible" && e !== "clip";
  6. }
  7. function _(e, t) {
  8. if (e.clientHeight < e.scrollHeight || e.clientWidth < e.scrollWidth) {
  9. var o = getComputedStyle(e, null);
  10. return R(o.overflowY, t) || R(o.overflowX, t) || function(l) {
  11. var r = function(n) {
  12. if (!n.ownerDocument || !n.ownerDocument.defaultView) return null;
  13. try {
  14. return n.ownerDocument.defaultView.frameElement;
  15. } catch (f) {
  16. return null;
  17. }
  18. }(l);
  19. return !!r && (r.clientHeight < l.scrollHeight || r.clientWidth < l.scrollWidth);
  20. }(e);
  21. }
  22. return !1;
  23. }
  24. function D(e, t, o, l, r, n, f, d) {
  25. return n < e && f > t || n > e && f < t ? 0 : n <= e && d <= o || f >= t && d >= o ? n - e - l : f > t && d < o || n < e && d > o ? f - t + r : 0;
  26. }
  27. var B = function(e, t) {
  28. var o = window, l = t.scrollMode, r = t.block, n = t.inline, f = t.boundary, d = t.skipOverflowHiddenElements, te = typeof f == "function" ? f : function(ne) {
  29. return ne !== f;
  30. };
  31. if (!J(e)) throw new TypeError("Invalid target");
  32. for (var q, z, F = document.scrollingElement || document.documentElement, H = [], c = e; J(c) && te(c); ) {
  33. if ((c = (z = (q = c).parentElement) == null ? q.getRootNode().host || null : z) === F) {
  34. H.push(c);
  35. break;
  36. }
  37. c != null && c === document.body && _(c) && !_(document.documentElement) || c != null && _(c, d) && H.push(c);
  38. }
  39. for (var m = o.visualViewport ? o.visualViewport.width : innerWidth, v = o.visualViewport ? o.visualViewport.height : innerHeight, w = window.scrollX || pageXOffset, b = window.scrollY || pageYOffset, g = e.getBoundingClientRect(), W = g.height, y = g.width, O = g.top, Q = g.right, U = g.bottom, E = g.left, u = r === "start" || r === "nearest" ? O : r === "end" ? U : O + W / 2, s = n === "center" ? E + y / 2 : n === "end" ? Q : E, Z = [], $ = 0; $ < H.length; $++) {
  40. var i = H[$], p = i.getBoundingClientRect(), V = p.height, k = p.width, M = p.top, A = p.right, N = p.bottom, T = p.left;
  41. if (l === "if-needed" && O >= 0 && E >= 0 && U <= v && Q <= m && O >= M && U <= N && E >= T && Q <= A) return Z;
  42. var x = getComputedStyle(i), I = parseInt(x.borderLeftWidth, 10), S = parseInt(x.borderTopWidth, 10), j = parseInt(x.borderRightWidth, 10), L = parseInt(x.borderBottomWidth, 10), h = 0, a = 0, X = "offsetWidth" in i ? i.offsetWidth - i.clientWidth - I - j : 0, Y = "offsetHeight" in i ? i.offsetHeight - i.clientHeight - S - L : 0, K = "offsetWidth" in i ? i.offsetWidth === 0 ? 0 : k / i.offsetWidth : 0, P = "offsetHeight" in i ? i.offsetHeight === 0 ? 0 : V / i.offsetHeight : 0;
  43. if (F === i) h = r === "start" ? u : r === "end" ? u - v : r === "nearest" ? D(b, b + v, v, S, L, b + u, b + u + W, W) : u - v / 2, a = n === "start" ? s : n === "center" ? s - m / 2 : n === "end" ? s - m : D(w, w + m, m, I, j, w + s, w + s + y, y), h = Math.max(0, h + b), a = Math.max(0, a + w);
  44. else {
  45. h = r === "start" ? u - M - S : r === "end" ? u - N + L + Y : r === "nearest" ? D(M, N, V, S, L + Y, u, u + W, W) : u - (M + V / 2) + Y / 2, a = n === "start" ? s - T - I : n === "center" ? s - (T + k / 2) + X / 2 : n === "end" ? s - A + j + X : D(T, A, k, I, j + X, s, s + y, y);
  46. var C = i.scrollLeft, G = i.scrollTop;
  47. u += G - (h = Math.max(0, Math.min(G + h / P, i.scrollHeight - V / P + Y))), s += C - (a = Math.max(0, Math.min(C + a / K, i.scrollWidth - k / K + X)));
  48. }
  49. Z.push({ el: i, top: h, left: a });
  50. }
  51. return Z;
  52. };
  53. function ee(e) {
  54. return e === Object(e) && Object.keys(e).length !== 0;
  55. }
  56. function re(e, t) {
  57. t === void 0 && (t = "auto");
  58. var o = "scrollBehavior" in document.body.style;
  59. e.forEach(function(l) {
  60. var r = l.el, n = l.top, f = l.left;
  61. r.scroll && o ? r.scroll({
  62. top: n,
  63. left: f,
  64. behavior: t
  65. }) : (r.scrollTop = n, r.scrollLeft = f);
  66. });
  67. }
  68. function ie(e) {
  69. return e === !1 ? {
  70. block: "end",
  71. inline: "nearest"
  72. } : ee(e) ? e : {
  73. block: "start",
  74. inline: "nearest"
  75. };
  76. }
  77. function oe(e, t) {
  78. var o = e.isConnected || e.ownerDocument.documentElement.contains(e);
  79. if (ee(t) && typeof t.behavior == "function")
  80. return t.behavior(o ? B(e, t) : []);
  81. if (o) {
  82. var l = ie(t);
  83. return re(B(e, l), l.behavior);
  84. }
  85. }
  86. export {
  87. oe as s
  88. };