{"version":3,"file":"service.mjs","sources":["../../../../../../packages/components/loading/src/service.ts"],"sourcesContent":["// @ts-nocheck\nimport { nextTick } from 'vue'\nimport {\n addClass,\n getStyle,\n isClient,\n isString,\n removeClass,\n} from '@element-plus/utils'\nimport { createLoadingComponent } from './loading'\n\nimport type { UseNamespaceReturn, UseZIndexReturn } from '@element-plus/hooks'\nimport type { LoadingInstance } from './loading'\nimport type { LoadingOptionsResolved } from '..'\nimport type { LoadingOptions } from './types'\nimport type { CSSProperties } from 'vue'\n\nlet fullscreenInstance: LoadingInstance | undefined = undefined\n\nexport const Loading = function (\n options: LoadingOptions = {}\n): LoadingInstance {\n if (!isClient) return undefined as any\n\n const resolved = resolveOptions(options)\n\n if (resolved.fullscreen && fullscreenInstance) {\n return fullscreenInstance\n }\n\n const instance = createLoadingComponent({\n ...resolved,\n closed: () => {\n resolved.closed?.()\n if (resolved.fullscreen) fullscreenInstance = undefined\n },\n })\n\n addStyle(resolved, resolved.parent, instance)\n addClassList(resolved, resolved.parent, instance)\n\n resolved.parent.vLoadingAddClassList = () =>\n addClassList(resolved, resolved.parent, instance)\n\n /**\n * add loading-number to parent.\n * because if a fullscreen loading is triggered when somewhere\n * a v-loading.body was triggered before and it's parent is\n * document.body which with a margin , the fullscreen loading's\n * destroySelf function will remove 'el-loading-parent--relative',\n * and then the position of v-loading.body will be error.\n */\n let loadingNumber: string | null =\n resolved.parent.getAttribute('loading-number')\n if (!loadingNumber) {\n loadingNumber = '1'\n } else {\n loadingNumber = `${Number.parseInt(loadingNumber) + 1}`\n }\n resolved.parent.setAttribute('loading-number', loadingNumber)\n\n resolved.parent.appendChild(instance.$el)\n\n // after instance render, then modify visible to trigger transition\n nextTick(() => (instance.visible.value = resolved.visible))\n\n if (resolved.fullscreen) {\n fullscreenInstance = instance\n }\n return instance\n}\n\nconst resolveOptions = (options: LoadingOptions): LoadingOptionsResolved => {\n let target: HTMLElement\n if (isString(options.target)) {\n target =\n document.querySelector(options.target) ?? document.body\n } else {\n target = options.target || document.body\n }\n return {\n parent: target === document.body || options.body ? document.body : target,\n background: options.background || '',\n svg: options.svg || '',\n svgViewBox: options.svgViewBox || '',\n spinner: options.spinner || false,\n text: options.text || '',\n fullscreen: target === document.body && (options.fullscreen ?? true),\n lock: options.lock ?? false,\n customClass: options.customClass || '',\n visible: options.visible ?? true,\n beforeClose: options.beforeClose,\n closed: options.closed,\n target,\n }\n}\n\nconst addStyle = async (\n options: LoadingOptionsResolved,\n parent: HTMLElement,\n instance: LoadingInstance\n) => {\n // Compatible with the instance data format of vue@3.2.12 and earlier versions #12351\n const { nextZIndex } =\n ((instance.vm as any).zIndex as UseZIndexReturn) ||\n (instance.vm as any)._.exposed.zIndex\n\n const maskStyle: CSSProperties = {}\n if (options.fullscreen) {\n instance.originalPosition.value = getStyle(document.body, 'position')\n instance.originalOverflow.value = getStyle(document.body, 'overflow')\n maskStyle.zIndex = nextZIndex()\n } else if (options.parent === document.body) {\n instance.originalPosition.value = getStyle(document.body, 'position')\n /**\n * await dom render when visible is true in init,\n * because some component's height maybe 0.\n * e.g. el-table.\n */\n await nextTick()\n for (const property of ['top', 'left']) {\n const scroll = property === 'top' ? 'scrollTop' : 'scrollLeft'\n maskStyle[property] = `${\n (options.target as HTMLElement).getBoundingClientRect()[property] +\n document.body[scroll] +\n document.documentElement[scroll] -\n Number.parseInt(getStyle(document.body, `margin-${property}`), 10)\n }px`\n }\n for (const property of ['height', 'width']) {\n maskStyle[property] = `${\n (options.target as HTMLElement).getBoundingClientRect()[property]\n }px`\n }\n } else {\n instance.originalPosition.value = getStyle(parent, 'position')\n }\n for (const [key, value] of Object.entries(maskStyle)) {\n instance.$el.style[key] = value\n }\n}\n\nconst addClassList = (\n options: LoadingOptions,\n parent: HTMLElement,\n instance: LoadingInstance\n) => {\n // Compatible with the instance data format of vue@3.2.12 and earlier versions #12351\n const ns =\n ((instance.vm as any).ns as UseNamespaceReturn) ||\n (instance.vm as any)._.exposed.ns\n\n if (\n !['absolute', 'fixed', 'sticky'].includes(instance.originalPosition.value)\n ) {\n addClass(parent, ns.bm('parent', 'relative'))\n } else {\n removeClass(parent, ns.bm('parent', 'relative'))\n }\n if (options.fullscreen && options.lock) {\n addClass(parent, ns.bm('parent', 'hidden'))\n } else {\n removeClass(parent, ns.bm('parent', 'hidden'))\n }\n}\n"],"names":[],"mappings":";;;;;;;AASA,IAAI,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACpB,MAAC,OAAO,GAAG,SAAS,OAAO,GAAG,EAAE,EAAE;AAC9C,EAAE,IAAI,CAAC,QAAQ;AACf,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,EAAE,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;AAC3C,EAAE,IAAI,QAAQ,CAAC,UAAU,IAAI,kBAAkB,EAAE;AACjD,IAAI,OAAO,kBAAkB,CAAC;AAC9B,GAAG;AACH,EAAE,MAAM,QAAQ,GAAG,sBAAsB,CAAC;AAC1C,IAAI,GAAG,QAAQ;AACf,IAAI,MAAM,EAAE,MAAM;AAClB,MAAM,IAAI,EAAE,CAAC;AACb,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC,MAAM,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAClE,MAAM,IAAI,QAAQ,CAAC,UAAU;AAC7B,QAAQ,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACpC,KAAK;AACL,GAAG,CAAC,CAAC;AACL,EAAE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAChD,EAAE,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACpD,EAAE,QAAQ,CAAC,MAAM,CAAC,oBAAoB,GAAG,MAAM,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACjG,EAAE,IA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