f6638788101f9928da00603598075cebc459a7e56f8e6837234ba9bf84f9ff5025de5fb02f0a978fe95151298651ee98225c4b9399d075edfffd30b11600eb 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { nextTick } from 'vue';
  2. import { createLoadingComponent } from './loading.mjs';
  3. import { isClient } from '@vueuse/core';
  4. import { isString } from '@vue/shared';
  5. import { getStyle, addClass, removeClass } from '../../../utils/dom/style.mjs';
  6. let fullscreenInstance = void 0;
  7. const Loading = function(options = {}) {
  8. if (!isClient)
  9. return void 0;
  10. const resolved = resolveOptions(options);
  11. if (resolved.fullscreen && fullscreenInstance) {
  12. return fullscreenInstance;
  13. }
  14. const instance = createLoadingComponent({
  15. ...resolved,
  16. closed: () => {
  17. var _a;
  18. (_a = resolved.closed) == null ? void 0 : _a.call(resolved);
  19. if (resolved.fullscreen)
  20. fullscreenInstance = void 0;
  21. }
  22. }, Loading._context);
  23. addStyle(resolved, resolved.parent, instance);
  24. addClassList(resolved, resolved.parent, instance);
  25. resolved.parent.vLoadingAddClassList = () => addClassList(resolved, resolved.parent, instance);
  26. let loadingNumber = resolved.parent.getAttribute("loading-number");
  27. if (!loadingNumber) {
  28. loadingNumber = "1";
  29. } else {
  30. loadingNumber = `${Number.parseInt(loadingNumber) + 1}`;
  31. }
  32. resolved.parent.setAttribute("loading-number", loadingNumber);
  33. resolved.parent.appendChild(instance.$el);
  34. nextTick(() => instance.visible.value = resolved.visible);
  35. if (resolved.fullscreen) {
  36. fullscreenInstance = instance;
  37. }
  38. return instance;
  39. };
  40. const resolveOptions = (options) => {
  41. var _a, _b, _c, _d;
  42. let target;
  43. if (isString(options.target)) {
  44. target = (_a = document.querySelector(options.target)) != null ? _a : document.body;
  45. } else {
  46. target = options.target || document.body;
  47. }
  48. return {
  49. parent: target === document.body || options.body ? document.body : target,
  50. background: options.background || "",
  51. svg: options.svg || "",
  52. svgViewBox: options.svgViewBox || "",
  53. spinner: options.spinner || false,
  54. text: options.text || "",
  55. fullscreen: target === document.body && ((_b = options.fullscreen) != null ? _b : true),
  56. lock: (_c = options.lock) != null ? _c : false,
  57. customClass: options.customClass || "",
  58. visible: (_d = options.visible) != null ? _d : true,
  59. beforeClose: options.beforeClose,
  60. closed: options.closed,
  61. target
  62. };
  63. };
  64. const addStyle = async (options, parent, instance) => {
  65. const { nextZIndex } = instance.vm.zIndex || instance.vm._.exposed.zIndex;
  66. const maskStyle = {};
  67. if (options.fullscreen) {
  68. instance.originalPosition.value = getStyle(document.body, "position");
  69. instance.originalOverflow.value = getStyle(document.body, "overflow");
  70. maskStyle.zIndex = nextZIndex();
  71. } else if (options.parent === document.body) {
  72. instance.originalPosition.value = getStyle(document.body, "position");
  73. await nextTick();
  74. for (const property of ["top", "left"]) {
  75. const scroll = property === "top" ? "scrollTop" : "scrollLeft";
  76. maskStyle[property] = `${options.target.getBoundingClientRect()[property] + document.body[scroll] + document.documentElement[scroll] - Number.parseInt(getStyle(document.body, `margin-${property}`), 10)}px`;
  77. }
  78. for (const property of ["height", "width"]) {
  79. maskStyle[property] = `${options.target.getBoundingClientRect()[property]}px`;
  80. }
  81. } else {
  82. instance.originalPosition.value = getStyle(parent, "position");
  83. }
  84. for (const [key, value] of Object.entries(maskStyle)) {
  85. instance.$el.style[key] = value;
  86. }
  87. };
  88. const addClassList = (options, parent, instance) => {
  89. const ns = instance.vm.ns || instance.vm._.exposed.ns;
  90. if (!["absolute", "fixed", "sticky"].includes(instance.originalPosition.value)) {
  91. addClass(parent, ns.bm("parent", "relative"));
  92. } else {
  93. removeClass(parent, ns.bm("parent", "relative"));
  94. }
  95. if (options.fullscreen && options.lock) {
  96. addClass(parent, ns.bm("parent", "hidden"));
  97. } else {
  98. removeClass(parent, ns.bm("parent", "hidden"));
  99. }
  100. };
  101. Loading._context = null;
  102. export { Loading as default };
  103. //# sourceMappingURL=service.mjs.map