版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

79 строки
2.4 KiB

  1. import '../browser.mjs';
  2. import { getStyle } from './style.mjs';
  3. import { isClient } from '@vueuse/core';
  4. const isScroll = (el, isVertical) => {
  5. if (!isClient)
  6. return false;
  7. const key = {
  8. undefined: "overflow",
  9. true: "overflow-y",
  10. false: "overflow-x"
  11. }[String(isVertical)];
  12. const overflow = getStyle(el, key);
  13. return ["scroll", "auto", "overlay"].some((s) => overflow.includes(s));
  14. };
  15. const getScrollContainer = (el, isVertical) => {
  16. if (!isClient)
  17. return;
  18. let parent = el;
  19. while (parent) {
  20. if ([window, document, document.documentElement].includes(parent))
  21. return window;
  22. if (isScroll(parent, isVertical))
  23. return parent;
  24. parent = parent.parentNode;
  25. }
  26. return parent;
  27. };
  28. let scrollBarWidth;
  29. const getScrollBarWidth = (namespace) => {
  30. var _a;
  31. if (!isClient)
  32. return 0;
  33. if (scrollBarWidth !== void 0)
  34. return scrollBarWidth;
  35. const outer = document.createElement("div");
  36. outer.className = `${namespace}-scrollbar__wrap`;
  37. outer.style.visibility = "hidden";
  38. outer.style.width = "100px";
  39. outer.style.position = "absolute";
  40. outer.style.top = "-9999px";
  41. document.body.appendChild(outer);
  42. const widthNoScroll = outer.offsetWidth;
  43. outer.style.overflow = "scroll";
  44. const inner = document.createElement("div");
  45. inner.style.width = "100%";
  46. outer.appendChild(inner);
  47. const widthWithScroll = inner.offsetWidth;
  48. (_a = outer.parentNode) == null ? void 0 : _a.removeChild(outer);
  49. scrollBarWidth = widthNoScroll - widthWithScroll;
  50. return scrollBarWidth;
  51. };
  52. function scrollIntoView(container, selected) {
  53. if (!isClient)
  54. return;
  55. if (!selected) {
  56. container.scrollTop = 0;
  57. return;
  58. }
  59. const offsetParents = [];
  60. let pointer = selected.offsetParent;
  61. while (pointer !== null && container !== pointer && container.contains(pointer)) {
  62. offsetParents.push(pointer);
  63. pointer = pointer.offsetParent;
  64. }
  65. const top = selected.offsetTop + offsetParents.reduce((prev, curr) => prev + curr.offsetTop, 0);
  66. const bottom = top + selected.offsetHeight;
  67. const viewRectTop = container.scrollTop;
  68. const viewRectBottom = viewRectTop + container.clientHeight;
  69. if (top < viewRectTop) {
  70. container.scrollTop = top;
  71. } else if (bottom > viewRectBottom) {
  72. container.scrollTop = bottom - container.clientHeight;
  73. }
  74. }
  75. export { getScrollBarWidth, getScrollContainer, isScroll, scrollIntoView };
  76. //# sourceMappingURL=scroll.mjs.map