{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/hooks/use-loading/index.ts"],"sourcesContent":["let activeLoadingCount = 0;\nlet hideTimer: ReturnType<typeof setTimeout> | undefined;\n\n/** 全局页面加载效果控制器。 */\nexport const useLoading = {\n\t/** 显示全局页面加载效果。 */\n\tshow: (): void => {\n\t\tactiveLoadingCount++;\n\t\tif (hideTimer !== undefined) {\n\t\t\tclearTimeout(hideTimer);\n\t\t\thideTimer = undefined;\n\t\t}\n\t\t// 判断是否存在加载效果\n\t\tif (!document.querySelector(\".__fa-loading\")) {\n\t\t\tconst bodyEl: Element = document.body;\n\t\t\tconst div = document.createElement(\"div\");\n\t\t\tdiv.className = \"__fa-loading\";\n\t\t\tdiv.innerHTML = `\n<div class=\"__fa-loading__box\">\n\t<div class=\"__fa-loading__box-warp\">\n\t\t\t<div class=\"__fa-loading__box-warp__item\"></div>\n\t</div>\n</div>\n`;\n\t\t\tbodyEl.insertBefore(div, bodyEl.firstChild);\n\t\t}\n\t\twindow.loading = true;\n\t},\n\t/** 隐藏全局页面加载效果。 */\n\thide: (): void => {\n\t\tactiveLoadingCount = Math.max(activeLoadingCount - 1, 0);\n\t\tif (activeLoadingCount > 0 || !window.loading) return;\n\t\tif (hideTimer !== undefined) clearTimeout(hideTimer);\n\t\thideTimer = setTimeout(() => {\n\t\t\tdocument.querySelector(\".__fa-loading\")?.remove();\n\t\t\twindow.loading = false;\n\t\t\thideTimer = undefined;\n\t\t}, 500);\n\t},\n};\n"],"mappings":";AAAA,IAAI,qBAAqB;AACzB,IAAI;;AAGJ,MAAa,aAAa;;CAEzB,YAAkB;EACjB;EACA,IAAI,cAAc,KAAA,GAAW;GAC5B,aAAa,SAAS;GACtB,YAAY,KAAA;EACb;EAEA,IAAI,CAAC,SAAS,cAAc,eAAe,GAAG;GAC7C,MAAM,SAAkB,SAAS;GACjC,MAAM,MAAM,SAAS,cAAc,KAAK;GACxC,IAAI,YAAY;GAChB,IAAI,YAAY;;;;;;;GAOhB,OAAO,aAAa,KAAK,OAAO,UAAU;EAC3C;EACA,OAAO,UAAU;CAClB;;CAEA,YAAkB;EACjB,qBAAqB,KAAK,IAAI,qBAAqB,GAAG,CAAC;EACvD,IAAI,qBAAqB,KAAK,CAAC,OAAO,SAAS;EAC/C,IAAI,cAAc,KAAA,GAAW,aAAa,SAAS;EACnD,YAAY,iBAAiB;GAC5B,SAAS,cAAc,eAAe,CAAC,EAAE,OAAO;GAChD,OAAO,UAAU;GACjB,YAAY,KAAA;EACb,GAAG,GAAG;CACP;AACD"}