@meng-xi/vite-plugin 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/README-en.md +264 -533
  2. package/README.md +253 -522
  3. package/dist/common/format/index.cjs +1 -0
  4. package/dist/common/format/index.d.cts +156 -0
  5. package/dist/common/format/index.d.mts +156 -0
  6. package/dist/common/format/index.d.ts +156 -0
  7. package/dist/common/format/index.mjs +1 -0
  8. package/dist/common/fs/index.cjs +1 -0
  9. package/dist/common/fs/index.d.cts +150 -0
  10. package/dist/common/fs/index.d.mts +150 -0
  11. package/dist/common/fs/index.d.ts +150 -0
  12. package/dist/common/fs/index.mjs +1 -0
  13. package/dist/common/html/index.cjs +2 -0
  14. package/dist/common/html/index.d.cts +109 -0
  15. package/dist/common/html/index.d.mts +109 -0
  16. package/dist/common/html/index.d.ts +109 -0
  17. package/dist/common/html/index.mjs +2 -0
  18. package/dist/common/index.cjs +1 -1
  19. package/dist/common/index.d.cts +7 -417
  20. package/dist/common/index.d.mts +7 -417
  21. package/dist/common/index.d.ts +7 -417
  22. package/dist/common/index.mjs +1 -1
  23. package/dist/common/object/index.cjs +1 -0
  24. package/dist/common/object/index.d.cts +30 -0
  25. package/dist/common/object/index.d.mts +30 -0
  26. package/dist/common/object/index.d.ts +30 -0
  27. package/dist/common/object/index.mjs +1 -0
  28. package/dist/common/script/index.cjs +1 -0
  29. package/dist/common/script/index.d.cts +54 -0
  30. package/dist/common/script/index.d.mts +54 -0
  31. package/dist/common/script/index.d.ts +54 -0
  32. package/dist/common/script/index.mjs +1 -0
  33. package/dist/common/validation/index.cjs +1 -0
  34. package/dist/common/validation/index.d.cts +93 -0
  35. package/dist/common/validation/index.d.mts +93 -0
  36. package/dist/common/validation/index.d.ts +93 -0
  37. package/dist/common/validation/index.mjs +1 -0
  38. package/dist/factory/index.cjs +1 -1
  39. package/dist/factory/index.d.cts +1 -1
  40. package/dist/factory/index.d.mts +1 -1
  41. package/dist/factory/index.d.ts +1 -1
  42. package/dist/factory/index.mjs +1 -1
  43. package/dist/index.cjs +1 -1
  44. package/dist/index.d.cts +16 -3
  45. package/dist/index.d.mts +16 -3
  46. package/dist/index.d.ts +16 -3
  47. package/dist/index.mjs +1 -1
  48. package/dist/plugins/buildProgress/index.cjs +2 -0
  49. package/dist/plugins/buildProgress/index.d.cts +187 -0
  50. package/dist/plugins/buildProgress/index.d.mts +187 -0
  51. package/dist/plugins/buildProgress/index.d.ts +187 -0
  52. package/dist/plugins/buildProgress/index.mjs +2 -0
  53. package/dist/plugins/compressAssets/index.cjs +1 -0
  54. package/dist/plugins/compressAssets/index.d.cts +132 -0
  55. package/dist/plugins/compressAssets/index.d.mts +132 -0
  56. package/dist/plugins/compressAssets/index.d.ts +132 -0
  57. package/dist/plugins/compressAssets/index.mjs +1 -0
  58. package/dist/plugins/copyFile/index.cjs +1 -0
  59. package/dist/plugins/copyFile/index.d.cts +78 -0
  60. package/dist/plugins/copyFile/index.d.mts +78 -0
  61. package/dist/plugins/copyFile/index.d.ts +78 -0
  62. package/dist/plugins/copyFile/index.mjs +1 -0
  63. package/dist/plugins/faviconManager/index.cjs +1 -0
  64. package/dist/plugins/faviconManager/index.d.cts +143 -0
  65. package/dist/plugins/faviconManager/index.d.mts +143 -0
  66. package/dist/plugins/faviconManager/index.d.ts +143 -0
  67. package/dist/plugins/faviconManager/index.mjs +1 -0
  68. package/dist/plugins/generateRouter/index.cjs +35 -0
  69. package/dist/plugins/generateRouter/index.d.cts +215 -0
  70. package/dist/plugins/generateRouter/index.d.mts +215 -0
  71. package/dist/plugins/generateRouter/index.d.ts +215 -0
  72. package/dist/plugins/generateRouter/index.mjs +35 -0
  73. package/dist/plugins/generateVersion/index.cjs +1 -0
  74. package/dist/plugins/generateVersion/index.d.cts +184 -0
  75. package/dist/plugins/generateVersion/index.d.mts +184 -0
  76. package/dist/plugins/generateVersion/index.d.ts +184 -0
  77. package/dist/plugins/generateVersion/index.mjs +1 -0
  78. package/dist/plugins/htmlInject/index.cjs +7 -0
  79. package/dist/plugins/htmlInject/index.d.cts +278 -0
  80. package/dist/plugins/htmlInject/index.d.mts +278 -0
  81. package/dist/plugins/htmlInject/index.d.ts +278 -0
  82. package/dist/plugins/htmlInject/index.mjs +7 -0
  83. package/dist/plugins/index.cjs +1 -1
  84. package/dist/plugins/index.d.cts +11 -1714
  85. package/dist/plugins/index.d.mts +11 -1714
  86. package/dist/plugins/index.d.ts +11 -1714
  87. package/dist/plugins/index.mjs +1 -1
  88. package/dist/plugins/loadingManager/index.cjs +487 -0
  89. package/dist/plugins/loadingManager/index.d.cts +769 -0
  90. package/dist/plugins/loadingManager/index.d.mts +769 -0
  91. package/dist/plugins/loadingManager/index.d.ts +769 -0
  92. package/dist/plugins/loadingManager/index.mjs +487 -0
  93. package/dist/plugins/versionUpdateChecker/index.cjs +185 -0
  94. package/dist/plugins/versionUpdateChecker/index.d.cts +200 -0
  95. package/dist/plugins/versionUpdateChecker/index.d.mts +200 -0
  96. package/dist/plugins/versionUpdateChecker/index.d.ts +200 -0
  97. package/dist/plugins/versionUpdateChecker/index.mjs +185 -0
  98. package/dist/shared/vite-plugin.Bcg6RW2N.cjs +3 -0
  99. package/dist/shared/{vite-plugin.CiHfwMiN.d.ts → vite-plugin.DRRlWY8P.d.cts} +50 -0
  100. package/dist/shared/{vite-plugin.CiHfwMiN.d.cts → vite-plugin.DRRlWY8P.d.mts} +50 -0
  101. package/dist/shared/{vite-plugin.CiHfwMiN.d.mts → vite-plugin.DRRlWY8P.d.ts} +50 -0
  102. package/dist/shared/{vite-plugin.B88RyRN8.mjs → vite-plugin.DcExl6jd.mjs} +2 -2
  103. package/package.json +80 -3
  104. package/dist/shared/vite-plugin.CawoITTT.cjs +0 -1
  105. package/dist/shared/vite-plugin.D6Law9Ke.mjs +0 -706
  106. package/dist/shared/vite-plugin.D8L9KzuW.cjs +0 -706
  107. package/dist/shared/vite-plugin.DFjf9wFM.mjs +0 -2
  108. package/dist/shared/vite-plugin.DSb6XzBn.mjs +0 -1
  109. package/dist/shared/vite-plugin.IGZeStMa.cjs +0 -3
  110. package/dist/shared/vite-plugin.Tab4qcIM.cjs +0 -2
@@ -1 +1 @@
1
- export{b as buildProgress,c as copyFile,f as faviconManager,g as generateRouter,a as generateVersion,l as loadingManager,v as versionUpdateChecker}from"../shared/vite-plugin.D6Law9Ke.mjs";import"../shared/vite-plugin.DSb6XzBn.mjs";import"../logger/index.mjs";import"fs";import"path";import"crypto";import"../shared/vite-plugin.B88RyRN8.mjs";import"../shared/vite-plugin.DFjf9wFM.mjs";
1
+ export{buildProgress}from"./buildProgress/index.mjs";export{compressAssets}from"./compressAssets/index.mjs";export{copyFile}from"./copyFile/index.mjs";export{faviconManager}from"./faviconManager/index.mjs";export{generateRouter}from"./generateRouter/index.mjs";export{generateVersion}from"./generateVersion/index.mjs";export{htmlInject}from"./htmlInject/index.mjs";export{loadingManager}from"./loadingManager/index.mjs";export{versionUpdateChecker}from"./versionUpdateChecker/index.mjs";import"../factory/index.mjs";import"../logger/index.mjs";import"../common/object/index.mjs";import"../shared/vite-plugin.DcExl6jd.mjs";import"node:zlib";import"node:fs";import"node:stream/promises";import"node:path";import"../common/fs/index.mjs";import"fs";import"path";import"../common/html/index.mjs";import"../common/format/index.mjs";import"crypto";import"../common/script/index.mjs";import"../common/validation/index.mjs";
@@ -0,0 +1,487 @@
1
+ "use strict";const factory_index=require("../../factory/index.cjs"),common_format_index=require("../../common/format/index.cjs"),common_script_index=require("../../common/script/index.cjs"),common_validation_index=require("../../common/validation/index.cjs"),common_html_index=require("../../common/html/index.cjs");require("../../logger/index.cjs"),require("../../common/object/index.cjs"),require("../../shared/vite-plugin.Bcg6RW2N.cjs"),require("crypto");const CLS_OVERLAY="__loading-overlay__",CLS_HIDDEN="__loading-hidden__",CLS_VISIBLE="__loading-visible__",CLS_TOP="__loading-top__",CLS_CENTER="__loading-center__",CLS_BOTTOM="__loading-bottom__",CLS_SPINNER="__loading-spinner__",CLS_TEXT="__loading-text__",CLS_DOT="__loading-dot__",ID_ROOT="__loading-root__",ATTR_TEXT="data-loading-text",ANIM_SPIN="__loading-spin__",ANIM_DOTS="__loading-dots__",ANIM_PULSE="__loading-pulse__",ANIM_BAR="__loading-bar__",POSITION_CLASS_MAP={center:CLS_CENTER,top:CLS_TOP,bottom:CLS_BOTTOM};function generateCSS(e,t="spinner",n){const{overlayColor:i="rgba(255, 255, 255, 0.7)",spinnerColor:r="#4361ee",spinnerSize:l="40px",textColor:o="#333",textSize:a="14px",zIndex:d=9999,pointerEvents:g=!0,backdropBlur:u=!1,backdropBlurAmount:s=4}=e,p=g?"":"pointer-events: none;",m=u?`backdrop-filter: blur(${s}px);-webkit-backdrop-filter: blur(${s}px);`:"",h=getSpinnerCSS(t,r,l),y=n?.enabled!==!1,c=n?.duration??200,_=n?.easing??"ease-out",f=y?`transition: opacity ${c}ms ${_}, visibility ${c}ms ${_};`:"";return`
2
+ .${CLS_OVERLAY} {
3
+ position: fixed;
4
+ top: 0;
5
+ left: 0;
6
+ right: 0;
7
+ bottom: 0;
8
+ background: ${i};
9
+ display: flex;
10
+ flex-direction: column;
11
+ align-items: center;
12
+ z-index: ${d};
13
+ ${p}
14
+ ${m}
15
+ contain: content;
16
+ will-change: opacity;
17
+ }
18
+ .${CLS_OVERLAY}.${CLS_TOP} {
19
+ justify-content: flex-start;
20
+ padding-top: 60px;
21
+ }
22
+ .${CLS_OVERLAY}.${CLS_CENTER} {
23
+ justify-content: center;
24
+ }
25
+ .${CLS_OVERLAY}.${CLS_BOTTOM} {
26
+ justify-content: flex-end;
27
+ padding-bottom: 60px;
28
+ }
29
+ ${h}
30
+ .${CLS_TEXT} {
31
+ margin-top: 12px;
32
+ color: ${o};
33
+ font-size: ${a};
34
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
35
+ user-select: none;
36
+ }
37
+ .${CLS_OVERLAY}.${CLS_HIDDEN} {
38
+ opacity: 0;
39
+ visibility: hidden;
40
+ ${f}
41
+ }
42
+ .${CLS_OVERLAY}.${CLS_HIDDEN} .${CLS_SPINNER},
43
+ .${CLS_OVERLAY}.${CLS_HIDDEN} .${CLS_DOT},
44
+ .${CLS_OVERLAY}.${CLS_HIDDEN} .${CLS_SPINNER}::after {
45
+ animation-play-state: paused;
46
+ }
47
+ .${CLS_OVERLAY}.${CLS_VISIBLE} {
48
+ opacity: 1;
49
+ visibility: visible;
50
+ ${f}
51
+ }
52
+ .${CLS_OVERLAY}.${CLS_VISIBLE} .${CLS_SPINNER},
53
+ .${CLS_OVERLAY}.${CLS_VISIBLE} .${CLS_DOT},
54
+ .${CLS_OVERLAY}.${CLS_VISIBLE} .${CLS_SPINNER}::after {
55
+ animation-play-state: running;
56
+ }`}function getSpinnerCSS(e,t,n){switch(e){case"dots":return`
57
+ .${CLS_SPINNER} {
58
+ display: flex;
59
+ gap: 6px;
60
+ align-items: center;
61
+ }
62
+ .${CLS_SPINNER} .${CLS_DOT} {
63
+ width: calc(${n} / 4);
64
+ height: calc(${n} / 4);
65
+ border-radius: 50%;
66
+ background: ${t};
67
+ animation: ${ANIM_DOTS} 1.2s ease-in-out infinite;
68
+ }
69
+ .${CLS_SPINNER} .${CLS_DOT}:nth-child(2) { animation-delay: 0.15s; }
70
+ .${CLS_SPINNER} .${CLS_DOT}:nth-child(3) { animation-delay: 0.3s; }
71
+ @keyframes ${ANIM_DOTS} {
72
+ 0%, 80%, 100% { transform: scale(0.4); opacity: 0.4; }
73
+ 40% { transform: scale(1); opacity: 1; }
74
+ }`;case"pulse":return`
75
+ .${CLS_SPINNER} {
76
+ width: ${n};
77
+ height: ${n};
78
+ background: ${t};
79
+ border-radius: 50%;
80
+ animation: ${ANIM_PULSE} 1.2s ease-in-out infinite;
81
+ }
82
+ @keyframes ${ANIM_PULSE} {
83
+ 0% { transform: scale(0.3); opacity: 0.3; }
84
+ 50% { transform: scale(1); opacity: 1; }
85
+ 100% { transform: scale(0.3); opacity: 0.3; }
86
+ }`;case"bar":return`
87
+ .${CLS_SPINNER} {
88
+ width: calc(${n} * 2.5);
89
+ height: calc(${n} / 5);
90
+ background: rgba(0, 0, 0, 0.08);
91
+ border-radius: calc(${n} / 10);
92
+ overflow: hidden;
93
+ position: relative;
94
+ }
95
+ .${CLS_SPINNER}::after {
96
+ content: '';
97
+ position: absolute;
98
+ top: 0;
99
+ left: 0;
100
+ height: 100%;
101
+ width: 40%;
102
+ background: ${t};
103
+ border-radius: calc(${n} / 10);
104
+ animation: ${ANIM_BAR} 1.2s ease-in-out infinite;
105
+ }
106
+ @keyframes ${ANIM_BAR} {
107
+ 0% { left: -40%; }
108
+ 100% { left: 100%; }
109
+ }`;default:return`
110
+ .${CLS_SPINNER} {
111
+ width: ${n};
112
+ height: ${n};
113
+ border: 3px solid rgba(0, 0, 0, 0.1);
114
+ border-top-color: ${t};
115
+ border-radius: 50%;
116
+ animation: ${ANIM_SPIN} 0.8s linear infinite;
117
+ }
118
+ @keyframes ${ANIM_SPIN} {
119
+ to { transform: rotate(360deg); }
120
+ }`}}function generateHTMLTemplate(e){const t=e.position||"center",n=e.defaultText||"\u52A0\u8F7D\u4E2D...",i=e.spinnerType||"spinner",r=POSITION_CLASS_MAP[t],l=e.style?.customClass?` ${e.style.customClass}`:"",o=e.style?.customStyle?` style="${common_format_index.escapeHtmlAttr(e.style.customStyle)}"`:"",a=e.defaultVisible?CLS_VISIBLE:CLS_HIDDEN;if(e.customTemplate)return`<div class="${CLS_OVERLAY} ${r} ${a}${l}" id="${ID_ROOT}"${o}>${e.customTemplate}</div>`;const d=getSpinnerHTML(i);return`<div class="${CLS_OVERLAY} ${r} ${a}${l}" id="${ID_ROOT}"${o}>
121
+ ${d}
122
+ <div class="${CLS_TEXT}" ${ATTR_TEXT}>${n}</div>
123
+ </div>`}function getSpinnerHTML(e){switch(e){case"dots":return`<div class="${CLS_SPINNER}"><div class="${CLS_DOT}"></div><div class="${CLS_DOT}"></div><div class="${CLS_DOT}"></div></div>`;default:return`<div class="${CLS_SPINNER}"></div>`}}function generateVarsCode(e){return` var _loadingEl = null;
124
+ var _textEl = null;
125
+ var _styleEl = null;
126
+ var _visible = false;
127
+ var _destroyed = false;
128
+ var _showTimer = null;
129
+ var _hideTimer = null;
130
+ var _debounceTimer = null;
131
+ var _retryTimer = null;
132
+ var _showTime = 0;
133
+ var _pendingCount = 0;
134
+ var _showRetryCount = 0;
135
+ var _maxShowRetries = 20;
136
+
137
+ // \u914D\u7F6E
138
+ var _minDisplayTime = ${JSON.stringify(e.minDisplayTime)};
139
+ var _delayShow = ${JSON.stringify(e.delayShow)};
140
+ var _debounceHide = ${JSON.stringify(e.debounceHide)};
141
+ var _transition = ${JSON.stringify(e.transition)};
142
+ var _excludeUrls = ${JSON.stringify(e.excludeUrls.map(t=>({source:t.source,flags:t.flags})))}.map(function(s) { return new RegExp(s.source, s.flags); });
143
+ var _includeUrls = ${JSON.stringify(e.includeUrls.map(t=>({source:t.source,flags:t.flags})))}.map(function(s) { return new RegExp(s.source, s.flags); });
144
+ var _excludeMethods = ${JSON.stringify(e.excludeMethods)};
145
+ var _excludeUrlPrefixes = ${JSON.stringify(e.excludeUrlPrefixes)};
146
+
147
+ // \u56DE\u8C03
148
+ var _onBeforeShow = ${e.cbBeforeShow};
149
+ var _onShow = ${e.cbShow};
150
+ var _onBeforeHide = ${e.cbBeforeHide};
151
+ var _onHide = ${e.cbHide};
152
+ var _onDestroy = ${e.cbDestroy};
153
+
154
+ // \u4FDD\u5B58\u539F\u59CB\u65B9\u6CD5\u5F15\u7528\uFF0C\u7528\u4E8E destroy \u65F6\u6062\u590D
155
+ var _originalFetch = null;
156
+ var _originalXHROpen = null;
157
+ var _originalXHRSend = null;`}function generateHelpersCode(e){return` function _findEl() {
158
+ if (!_loadingEl) {
159
+ _loadingEl = document.getElementById('${ID_ROOT}');
160
+ }
161
+ if (!_textEl && _loadingEl) {
162
+ _textEl = _loadingEl.querySelector('[${ATTR_TEXT}]');
163
+ }
164
+ if (!_styleEl) {
165
+ _styleEl = document.querySelector('style[data-loading-id="${e}"]');
166
+ }
167
+ }
168
+
169
+ function _shouldFilter(url, method) {
170
+ if (!url) return false;
171
+ var upperMethod = (method || 'GET').toUpperCase();
172
+ for (var i = 0; i < _excludeMethods.length; i++) {
173
+ if (upperMethod === _excludeMethods[i].toUpperCase()) return true;
174
+ }
175
+ for (var i = 0; i < _excludeUrlPrefixes.length; i++) {
176
+ if (url.indexOf(_excludeUrlPrefixes[i]) === 0) return true;
177
+ }
178
+ if (_includeUrls.length > 0) {
179
+ var included = false;
180
+ for (var i = 0; i < _includeUrls.length; i++) {
181
+ _includeUrls[i].lastIndex = 0;
182
+ if (_includeUrls[i].test(url)) { included = true; break; }
183
+ }
184
+ if (!included) return true;
185
+ }
186
+ for (var i = 0; i < _excludeUrls.length; i++) {
187
+ _excludeUrls[i].lastIndex = 0;
188
+ if (_excludeUrls[i].test(url)) return true;
189
+ }
190
+ return false;
191
+ }
192
+
193
+ function _clearTimers() {
194
+ if (_showTimer) { clearTimeout(_showTimer); _showTimer = null; }
195
+ if (_hideTimer) { clearTimeout(_hideTimer); _hideTimer = null; }
196
+ if (_debounceTimer) { clearTimeout(_debounceTimer); _debounceTimer = null; }
197
+ if (_retryTimer) { clearTimeout(_retryTimer); _retryTimer = null; }
198
+ }
199
+
200
+ function _applyTransition(show) {
201
+ if (!_transition.enabled || !_loadingEl) return;
202
+ var d = _transition.duration || 200;
203
+ var e = _transition.easing || 'ease-out';
204
+ _loadingEl.style.transition = 'opacity ' + d + 'ms ' + e + ', visibility ' + d + 'ms ' + e;
205
+ }`}function generateCoreLogicCode(){return` function _applyHide() {
206
+ if (!_loadingEl) return;
207
+ _loadingEl.classList.remove('${CLS_VISIBLE}');
208
+ _loadingEl.classList.add('${CLS_HIDDEN}');
209
+ _applyTransition(false);
210
+ _visible = false;
211
+ _showTime = 0;
212
+ _onHide();
213
+ }
214
+
215
+ function _doShow(text) {
216
+ if (_destroyed) return;
217
+ _findEl();
218
+ if (!_loadingEl) {
219
+ if (++_showRetryCount > _maxShowRetries) return;
220
+ _retryTimer = setTimeout(function() { _retryTimer = null; _doShow(text); }, 50);
221
+ return;
222
+ }
223
+ _showRetryCount = 0;
224
+
225
+ var result = _onBeforeShow();
226
+ if (result === false) return;
227
+
228
+ if (_textEl && text) _textEl.textContent = text;
229
+ _loadingEl.classList.remove('${CLS_HIDDEN}');
230
+ _loadingEl.classList.add('${CLS_VISIBLE}');
231
+ _applyTransition(true);
232
+ _visible = true;
233
+ _showTime = Date.now();
234
+ _onShow();
235
+ }
236
+
237
+ function _doHide(force) {
238
+ if (_destroyed) return;
239
+ if (!_visible && !force) return;
240
+ _findEl();
241
+ if (!_loadingEl) return;
242
+
243
+ if (!force) {
244
+ var result = _onBeforeHide();
245
+ if (result === false) return;
246
+ }
247
+
248
+ if (!force && _minDisplayTime.enabled && _showTime > 0) {
249
+ var elapsed = Date.now() - _showTime;
250
+ var remaining = _minDisplayTime.duration - elapsed;
251
+ if (remaining > 0) {
252
+ if (_hideTimer) clearTimeout(_hideTimer);
253
+ _hideTimer = setTimeout(function() { _hideTimer = null; _doHide(true); }, remaining);
254
+ return;
255
+ }
256
+ }
257
+
258
+ if (_debounceHide.enabled && !force) {
259
+ if (_debounceTimer) clearTimeout(_debounceTimer);
260
+ _debounceTimer = setTimeout(function() { _debounceTimer = null; _applyHide(); }, _debounceHide.duration);
261
+ return;
262
+ }
263
+
264
+ _applyHide();
265
+ }
266
+
267
+ function _restoreInterceptors() {
268
+ if (_originalFetch && typeof window !== 'undefined' && window.fetch) {
269
+ window.fetch = _originalFetch;
270
+ _originalFetch = null;
271
+ }
272
+ if (_originalXHROpen && typeof window !== 'undefined' && window.XMLHttpRequest) {
273
+ XMLHttpRequest.prototype.open = _originalXHROpen;
274
+ XMLHttpRequest.prototype.send = _originalXHRSend;
275
+ _originalXHROpen = null;
276
+ _originalXHRSend = null;
277
+ }
278
+ }`}function generateManagerObjectCode(){return` show: function(text) {
279
+ if (_destroyed) return;
280
+ _clearTimers();
281
+ _showTime = 0;
282
+ _showRetryCount = 0;
283
+ if (_delayShow.enabled && _delayShow.duration > 0) {
284
+ _showTimer = setTimeout(function() { _showTimer = null; _doShow(text); }, _delayShow.duration);
285
+ } else {
286
+ _doShow(text);
287
+ }
288
+ },
289
+ hide: function() {
290
+ if (_destroyed) return;
291
+ if (_showTimer) { clearTimeout(_showTimer); _showTimer = null; }
292
+ _doHide(false);
293
+ },
294
+ forceHide: function() {
295
+ if (_destroyed) return;
296
+ _clearTimers();
297
+ _doHide(true);
298
+ },
299
+ toggle: function(text) {
300
+ if (_destroyed) return;
301
+ if (_visible) {
302
+ this.hide();
303
+ } else {
304
+ this.show(text);
305
+ }
306
+ },
307
+ enablePointerEvents: function() {
308
+ if (_destroyed) return;
309
+ _findEl();
310
+ if (_loadingEl) _loadingEl.style.pointerEvents = 'auto';
311
+ },
312
+ disablePointerEvents: function() {
313
+ if (_destroyed) return;
314
+ _findEl();
315
+ if (_loadingEl) _loadingEl.style.pointerEvents = 'none';
316
+ },
317
+ togglePointerEvents: function() {
318
+ if (_destroyed) return;
319
+ _findEl();
320
+ if (!_loadingEl) return;
321
+ if (_loadingEl.style.pointerEvents === 'none') {
322
+ this.enablePointerEvents();
323
+ } else {
324
+ this.disablePointerEvents();
325
+ }
326
+ },
327
+ updateText: function(text) {
328
+ if (_destroyed) return;
329
+ _findEl();
330
+ if (_textEl) _textEl.textContent = text;
331
+ },
332
+ isVisible: function() {
333
+ return _visible && !_destroyed;
334
+ },
335
+ isPointerEventsEnabled: function() {
336
+ if (_destroyed) return false;
337
+ _findEl();
338
+ if (!_loadingEl) return false;
339
+ return _loadingEl.style.pointerEvents !== 'none';
340
+ },
341
+ getPendingCount: function() {
342
+ return _pendingCount;
343
+ },
344
+ destroy: function() {
345
+ if (_destroyed) return;
346
+ _destroyed = true;
347
+ _clearTimers();
348
+ _findEl();
349
+ if (_loadingEl && _loadingEl.parentNode) {
350
+ _loadingEl.parentNode.removeChild(_loadingEl);
351
+ }
352
+ if (_styleEl && _styleEl.parentNode) {
353
+ _styleEl.parentNode.removeChild(_styleEl);
354
+ }
355
+ _loadingEl = null;
356
+ _textEl = null;
357
+ _styleEl = null;
358
+ _visible = false;
359
+ _showTime = 0;
360
+ _pendingCount = 0;
361
+ _restoreInterceptors();
362
+ _onDestroy();
363
+ },
364
+ _requestStart: function(url, method) {
365
+ if (_destroyed) return;
366
+ if (_shouldFilter(url, method)) return;
367
+ _pendingCount++;
368
+ if (_pendingCount === 1) this.show();
369
+ },
370
+ _requestEnd: function(url, method) {
371
+ if (_destroyed) return;
372
+ if (_shouldFilter(url, method)) return;
373
+ _pendingCount = Math.max(0, _pendingCount - 1);
374
+ if (_pendingCount === 0) this.hide();
375
+ }`}function generateInterceptorsCode(e){let t="";return(e==="fetch"||e==="all")&&(t+=` // \u81EA\u52A8\u62E6\u622A fetch
376
+ if (typeof window !== 'undefined' && window.fetch) {
377
+ _originalFetch = window.fetch;
378
+ window.fetch = function(input, init) {
379
+ var url = typeof input === 'string' ? input : (input instanceof URL ? input.href : (input && input.url ? input.url : ''));
380
+ var method = (init && init.method) || (input && input.method) || 'GET';
381
+ manager._requestStart(url, method);
382
+ return _originalFetch.apply(this, arguments).then(
383
+ function(response) { manager._requestEnd(url, method); return response; },
384
+ function(error) { manager._requestEnd(url, method); throw error; }
385
+ );
386
+ };
387
+ }
388
+ `),(e==="xhr"||e==="all")&&(t+=` // \u81EA\u52A8\u62E6\u622A XMLHttpRequest
389
+ if (typeof window !== 'undefined' && window.XMLHttpRequest) {
390
+ _originalXHROpen = XMLHttpRequest.prototype.open;
391
+ _originalXHRSend = XMLHttpRequest.prototype.send;
392
+ XMLHttpRequest.prototype.open = function(method, url) {
393
+ this.__loadingUrl = url || '';
394
+ this.__loadingMethod = method || 'GET';
395
+ return _originalXHROpen.apply(this, arguments);
396
+ };
397
+ XMLHttpRequest.prototype.send = function() {
398
+ var self = this;
399
+ manager._requestStart(self.__loadingUrl, self.__loadingMethod);
400
+ self.addEventListener('loadend', function() {
401
+ manager._requestEnd(self.__loadingUrl, self.__loadingMethod);
402
+ });
403
+ return _originalXHRSend.apply(this, arguments);
404
+ };
405
+ }
406
+ `),t.trimEnd()}function generateInitCode(e,t,n){let i="";return i+=` // defaultVisible: \u540C\u6B65\u521D\u59CB\u53EF\u89C1\u72B6\u6001
407
+ var _defaultVisible = ${JSON.stringify(e)};
408
+ if (_defaultVisible) {
409
+ _visible = true;
410
+ _showTime = Date.now();
411
+ }
412
+ `,e&&t!=="manual"&&(i+=`
413
+ // autoHideOn: \u81EA\u52A8\u9690\u85CF\u65F6\u673A
414
+ var _autoHideOn = '${t}';
415
+ function _autoHideHandler() {
416
+ manager.hide();
417
+ }
418
+ if (_autoHideOn === 'load') {
419
+ if (document.readyState === 'complete') {
420
+ _autoHideHandler();
421
+ } else {
422
+ window.addEventListener('load', _autoHideHandler);
423
+ }
424
+ } else {
425
+ if (document.readyState !== 'loading') {
426
+ _autoHideHandler();
427
+ } else {
428
+ document.addEventListener('DOMContentLoaded', _autoHideHandler);
429
+ }
430
+ }
431
+ `),i+=`
432
+ // \u66B4\u9732\u5230\u5168\u5C40
433
+ window['${n}'] = manager;`,i}function generateLoadingManagerCode(e){const t=e.globalName||"__LOADING_MANAGER__",n=e.minDisplayTime||{enabled:!0,duration:300},i=e.delayShow||{enabled:!0,duration:200},r=e.debounceHide||{enabled:!1,duration:100},l=e.transition||{enabled:!0,duration:200,easing:"ease-out"},o=e.autoBind||"none",a=e.requestFilter||{},d=e.defaultVisible||!1,g=e.autoHideOn||"DOMContentLoaded",u=e.callbacks||{},s=a.excludeUrls||[],p=a.includeUrls||[],m=a.excludeMethods||[],h=a.excludeUrlPrefixes||[],y=common_script_index.makeCallback(u.onBeforeShow,"loadingManager"),c=common_script_index.makeCallback(u.onShow,"loadingManager"),_=common_script_index.makeCallback(u.onBeforeHide,"loadingManager"),f=common_script_index.makeCallback(u.onHide,"loadingManager"),b=common_script_index.makeCallback(u.onDestroy,"loadingManager"),E=generateVarsCode({minDisplayTime:n,delayShow:i,debounceHide:r,transition:l,excludeUrls:s,includeUrls:p,excludeMethods:m,excludeUrlPrefixes:h,cbBeforeShow:y,cbShow:c,cbBeforeHide:_,cbHide:f,cbDestroy:b}),$=generateHelpersCode(t),v=generateCoreLogicCode(),T=generateManagerObjectCode(),w=generateInterceptorsCode(o),x=generateInitCode(d,g,t);return`(function() {
434
+ 'use strict';
435
+
436
+ // SSR \u73AF\u5883\u68C0\u6D4B
437
+ if (typeof window === 'undefined' || typeof document === 'undefined') return;
438
+
439
+ ${E}
440
+
441
+ ${$}
442
+
443
+ ${v}
444
+
445
+ var manager = {
446
+ ${T}
447
+ };
448
+
449
+ ${w}
450
+
451
+ ${x}
452
+ })();`}function validateStyle(e){if(!e)return;const{zIndex:t,pointerEvents:n,backdropBlurAmount:i}=e;if(common_validation_index.validateNonNegativeNumber(t,"style.zIndex"),n!==void 0&&typeof n!="boolean")throw new Error("style.pointerEvents \u5FC5\u987B\u662F\u5E03\u5C14\u503C");common_validation_index.validateNonNegativeNumber(i,"style.backdropBlurAmount")}function validateTransition(e){if(!e)return;const{duration:t,easing:n}=e;if(common_validation_index.validateNonNegativeNumber(t,"transition.duration"),n!==void 0&&typeof n!="string")throw new Error("transition.easing \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u7C7B\u578B")}function validateCallbacks(e){e&&common_validation_index.validateCallbackFields(e,["onBeforeShow","onShow","onBeforeHide","onHide","onDestroy"],"callbacks")}function validateDefaultText(e){return e===""?"defaultText \u4E3A\u7A7A\u5B57\u7B26\u4E32\uFF0Cloading \u5C06\u4E0D\u663E\u793A\u6587\u672C\u5185\u5BB9":null}function validateAutoHideOn(e,t){return!e&&t?"autoHideOn \u4EC5\u5728 defaultVisible \u4E3A true \u65F6\u751F\u6548\uFF0C\u5F53\u524D defaultVisible \u4E3A false\uFF0CautoHideOn \u914D\u7F6E\u5C06\u88AB\u5FFD\u7565":null}class C extends factory_index.BasePlugin{getDefaultOptions(){return{position:"center",defaultText:"\u52A0\u8F7D\u4E2D...",spinnerType:"spinner",autoBind:"none",globalName:"__LOADING_MANAGER__",defaultVisible:!1,autoHideOn:"DOMContentLoaded",style:{overlayColor:"rgba(255, 255, 255, 0.7)",spinnerColor:"#4361ee",spinnerSize:"40px",textColor:"#333",textSize:"14px",zIndex:9999,pointerEvents:!0,backdropBlur:!1,backdropBlurAmount:4},transition:{enabled:!0,duration:200,easing:"ease-out"},minDisplayTime:{enabled:!0,duration:300},delayShow:{enabled:!0,duration:200},debounceHide:{enabled:!1,duration:100}}}validateOptions(){this.validator.field("position").enum(["center","top","bottom"]).field("defaultText").string().field("spinnerType").enum(["spinner","dots","pulse","bar"]).field("autoBind").enum(["fetch","xhr","all","none"]).field("globalName").string().field("customTemplate").string().field("defaultVisible").boolean().field("autoHideOn").enum(["DOMContentLoaded","load","manual"]).validate(),common_validation_index.validateNoScriptInTemplate(this.options.customTemplate,"customTemplate");const t=validateDefaultText(this.options.defaultText);t&&this.logger.warn(t),common_validation_index.validateGlobalName(this.options.globalName,"globalName"),validateStyle(this.options.style),common_validation_index.validateNestedDuration(this.options.minDisplayTime,"minDisplayTime.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),common_validation_index.validateNestedDuration(this.options.delayShow,"delayShow.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),common_validation_index.validateNestedDuration(this.options.debounceHide,"debounceHide.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),validateTransition(this.options.transition),validateCallbacks(this.options.callbacks);const n=validateAutoHideOn(this.options.defaultVisible,this.options.autoHideOn);n&&this.logger.warn(n)}getPluginName(){return"loading-manager"}generateLoadingManager(t){return generateLoadingManagerCode(t)}generateHeadInjectCode(){const{css:t,html:n}=this.getCachedAssets();return`<!-- loading-manager: head start -->
453
+ <style data-loading-style data-loading-id="${this.options.globalName||"__LOADING_MANAGER__"}">${t}</style>
454
+ ${n}
455
+ <!-- loading-manager: head end -->`}generateBodyInjectCode(t){const n=this.generateLoadingManager(this.options);if(t)return`<!-- loading-manager: body start -->
456
+ <script>${n}<\/script>
457
+ <!-- loading-manager: body end -->`;const{css:i,html:r}=this.getCachedAssets();return`<!-- loading-manager: start -->
458
+ <script>
459
+ (function() {
460
+ // SSR \u73AF\u5883\u68C0\u6D4B
461
+ if (typeof window === 'undefined' || typeof document === 'undefined') return;
462
+
463
+ // \u6CE8\u5165 CSS
464
+ var style = document.createElement('style');
465
+ style.setAttribute('data-loading-style', '');
466
+ style.setAttribute('data-loading-id', '${this.options.globalName||"__LOADING_MANAGER__"}');
467
+ style.textContent = ${JSON.stringify(i)};
468
+ document.head.appendChild(style);
469
+
470
+ // \u6CE8\u5165 HTML\uFF08\u7B49\u5F85 body \u53EF\u7528\u65F6\u6267\u884C\uFF09
471
+ function injectHTML() {
472
+ var div = document.createElement('div');
473
+ div.innerHTML = ${JSON.stringify(r)};
474
+ while (div.firstChild) {
475
+ document.body.appendChild(div.firstChild);
476
+ }
477
+ }
478
+
479
+ if (document.body) {
480
+ injectHTML();
481
+ } else {
482
+ document.addEventListener('DOMContentLoaded', injectHTML);
483
+ }
484
+ })();
485
+ ${n}
486
+ <\/script>
487
+ <!-- loading-manager: end -->`}_cachedAssets=null;getCachedAssets(){if(!this._cachedAssets){const t=this.options.style||{},n=this.options.spinnerType||"spinner",i=this.options.transition;this._cachedAssets={css:generateCSS(t,n,i),html:generateHTMLTemplate(this.options)}}return this._cachedAssets}addPluginHooks(t){const n=this.options.defaultVisible||!1,i=n?this.generateHeadInjectCode():void 0,r=this.generateBodyInjectCode(n);t.transformIndexHtml={order:"post",handler:l=>{const o=common_html_index.injectHeadAndBody(l,i,r);return i&&!o.headInjected&&this.logger.warn("\u672A\u627E\u5230 </head> \u6807\u7B7E\uFF0CdefaultVisible \u7684\u767D\u5C4F loading \u5C06\u65E0\u6CD5\u751F\u6548"),o.usedFallback&&this.logger.warn("\u672A\u627E\u5230 </body> \u6216 </html> \u6807\u7B7E\uFF0CLoading \u4EE3\u7801\u8FFD\u52A0\u5230\u6587\u4EF6\u672B\u5C3E"),o.bodyInjected&&this.logger.success("\u6210\u529F\u6CE8\u5165\u5168\u5C40 Loading \u72B6\u6001\u7BA1\u7406\u4EE3\u7801\u5230 HTML \u6587\u4EF6"),o.html}}}}const loadingManager=factory_index.createPluginFactory(C);exports.loadingManager=loadingManager;