You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.9 KiB

1 month ago
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var index = require('../use-namespace/index.js');
  5. var error = require('../../utils/error.js');
  6. var core = require('@vueuse/core');
  7. var style = require('../../utils/dom/style.js');
  8. var scroll = require('../../utils/dom/scroll.js');
  9. const useLockscreen = (trigger, options = {}) => {
  10. if (!vue.isRef(trigger)) {
  11. error.throwError("[useLockscreen]", "You need to pass a ref param to this function");
  12. }
  13. const ns = options.ns || index.useNamespace("popup");
  14. const hiddenCls = vue.computed(() => ns.bm("parent", "hidden"));
  15. if (!core.isClient || style.hasClass(document.body, hiddenCls.value)) {
  16. return;
  17. }
  18. let scrollBarWidth = 0;
  19. let withoutHiddenClass = false;
  20. let bodyWidth = "0";
  21. const cleanup = () => {
  22. setTimeout(() => {
  23. if (typeof document === "undefined")
  24. return;
  25. if (withoutHiddenClass && document) {
  26. document.body.style.width = bodyWidth;
  27. style.removeClass(document.body, hiddenCls.value);
  28. }
  29. }, 200);
  30. };
  31. vue.watch(trigger, (val) => {
  32. if (!val) {
  33. cleanup();
  34. return;
  35. }
  36. withoutHiddenClass = !style.hasClass(document.body, hiddenCls.value);
  37. if (withoutHiddenClass) {
  38. bodyWidth = document.body.style.width;
  39. style.addClass(document.body, hiddenCls.value);
  40. }
  41. scrollBarWidth = scroll.getScrollBarWidth(ns.namespace.value);
  42. const bodyHasOverflow = document.documentElement.clientHeight < document.body.scrollHeight;
  43. const bodyOverflowY = style.getStyle(document.body, "overflowY");
  44. if (scrollBarWidth > 0 && (bodyHasOverflow || bodyOverflowY === "scroll") && withoutHiddenClass) {
  45. document.body.style.width = `calc(100% - ${scrollBarWidth}px)`;
  46. }
  47. });
  48. vue.onScopeDispose(() => cleanup());
  49. };
  50. exports.useLockscreen = useLockscreen;
  51. //# sourceMappingURL=index.js.map