@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.
- package/README-en.md +264 -533
- package/README.md +253 -522
- package/dist/common/format/index.cjs +1 -0
- package/dist/common/format/index.d.cts +156 -0
- package/dist/common/format/index.d.mts +156 -0
- package/dist/common/format/index.d.ts +156 -0
- package/dist/common/format/index.mjs +1 -0
- package/dist/common/fs/index.cjs +1 -0
- package/dist/common/fs/index.d.cts +150 -0
- package/dist/common/fs/index.d.mts +150 -0
- package/dist/common/fs/index.d.ts +150 -0
- package/dist/common/fs/index.mjs +1 -0
- package/dist/common/html/index.cjs +2 -0
- package/dist/common/html/index.d.cts +109 -0
- package/dist/common/html/index.d.mts +109 -0
- package/dist/common/html/index.d.ts +109 -0
- package/dist/common/html/index.mjs +2 -0
- package/dist/common/index.cjs +1 -1
- package/dist/common/index.d.cts +7 -417
- package/dist/common/index.d.mts +7 -417
- package/dist/common/index.d.ts +7 -417
- package/dist/common/index.mjs +1 -1
- package/dist/common/object/index.cjs +1 -0
- package/dist/common/object/index.d.cts +30 -0
- package/dist/common/object/index.d.mts +30 -0
- package/dist/common/object/index.d.ts +30 -0
- package/dist/common/object/index.mjs +1 -0
- package/dist/common/script/index.cjs +1 -0
- package/dist/common/script/index.d.cts +54 -0
- package/dist/common/script/index.d.mts +54 -0
- package/dist/common/script/index.d.ts +54 -0
- package/dist/common/script/index.mjs +1 -0
- package/dist/common/validation/index.cjs +1 -0
- package/dist/common/validation/index.d.cts +93 -0
- package/dist/common/validation/index.d.mts +93 -0
- package/dist/common/validation/index.d.ts +93 -0
- package/dist/common/validation/index.mjs +1 -0
- package/dist/factory/index.cjs +1 -1
- package/dist/factory/index.d.cts +1 -1
- package/dist/factory/index.d.mts +1 -1
- package/dist/factory/index.d.ts +1 -1
- package/dist/factory/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +16 -3
- package/dist/index.d.mts +16 -3
- package/dist/index.d.ts +16 -3
- package/dist/index.mjs +1 -1
- package/dist/plugins/buildProgress/index.cjs +2 -0
- package/dist/plugins/buildProgress/index.d.cts +187 -0
- package/dist/plugins/buildProgress/index.d.mts +187 -0
- package/dist/plugins/buildProgress/index.d.ts +187 -0
- package/dist/plugins/buildProgress/index.mjs +2 -0
- package/dist/plugins/compressAssets/index.cjs +1 -0
- package/dist/plugins/compressAssets/index.d.cts +132 -0
- package/dist/plugins/compressAssets/index.d.mts +132 -0
- package/dist/plugins/compressAssets/index.d.ts +132 -0
- package/dist/plugins/compressAssets/index.mjs +1 -0
- package/dist/plugins/copyFile/index.cjs +1 -0
- package/dist/plugins/copyFile/index.d.cts +78 -0
- package/dist/plugins/copyFile/index.d.mts +78 -0
- package/dist/plugins/copyFile/index.d.ts +78 -0
- package/dist/plugins/copyFile/index.mjs +1 -0
- package/dist/plugins/faviconManager/index.cjs +1 -0
- package/dist/plugins/faviconManager/index.d.cts +143 -0
- package/dist/plugins/faviconManager/index.d.mts +143 -0
- package/dist/plugins/faviconManager/index.d.ts +143 -0
- package/dist/plugins/faviconManager/index.mjs +1 -0
- package/dist/plugins/generateRouter/index.cjs +35 -0
- package/dist/plugins/generateRouter/index.d.cts +215 -0
- package/dist/plugins/generateRouter/index.d.mts +215 -0
- package/dist/plugins/generateRouter/index.d.ts +215 -0
- package/dist/plugins/generateRouter/index.mjs +35 -0
- package/dist/plugins/generateVersion/index.cjs +1 -0
- package/dist/plugins/generateVersion/index.d.cts +184 -0
- package/dist/plugins/generateVersion/index.d.mts +184 -0
- package/dist/plugins/generateVersion/index.d.ts +184 -0
- package/dist/plugins/generateVersion/index.mjs +1 -0
- package/dist/plugins/htmlInject/index.cjs +7 -0
- package/dist/plugins/htmlInject/index.d.cts +278 -0
- package/dist/plugins/htmlInject/index.d.mts +278 -0
- package/dist/plugins/htmlInject/index.d.ts +278 -0
- package/dist/plugins/htmlInject/index.mjs +7 -0
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +11 -1714
- package/dist/plugins/index.d.mts +11 -1714
- package/dist/plugins/index.d.ts +11 -1714
- package/dist/plugins/index.mjs +1 -1
- package/dist/plugins/loadingManager/index.cjs +487 -0
- package/dist/plugins/loadingManager/index.d.cts +769 -0
- package/dist/plugins/loadingManager/index.d.mts +769 -0
- package/dist/plugins/loadingManager/index.d.ts +769 -0
- package/dist/plugins/loadingManager/index.mjs +487 -0
- package/dist/plugins/versionUpdateChecker/index.cjs +185 -0
- package/dist/plugins/versionUpdateChecker/index.d.cts +200 -0
- package/dist/plugins/versionUpdateChecker/index.d.mts +200 -0
- package/dist/plugins/versionUpdateChecker/index.d.ts +200 -0
- package/dist/plugins/versionUpdateChecker/index.mjs +185 -0
- package/dist/shared/vite-plugin.Bcg6RW2N.cjs +3 -0
- package/dist/shared/{vite-plugin.CiHfwMiN.d.ts → vite-plugin.DRRlWY8P.d.cts} +50 -0
- package/dist/shared/{vite-plugin.CiHfwMiN.d.cts → vite-plugin.DRRlWY8P.d.mts} +50 -0
- package/dist/shared/{vite-plugin.CiHfwMiN.d.mts → vite-plugin.DRRlWY8P.d.ts} +50 -0
- package/dist/shared/{vite-plugin.B88RyRN8.mjs → vite-plugin.DcExl6jd.mjs} +2 -2
- package/package.json +80 -3
- package/dist/shared/vite-plugin.CawoITTT.cjs +0 -1
- package/dist/shared/vite-plugin.D6Law9Ke.mjs +0 -706
- package/dist/shared/vite-plugin.D8L9KzuW.cjs +0 -706
- package/dist/shared/vite-plugin.DFjf9wFM.mjs +0 -2
- package/dist/shared/vite-plugin.DSb6XzBn.mjs +0 -1
- package/dist/shared/vite-plugin.IGZeStMa.cjs +0 -3
- package/dist/shared/vite-plugin.Tab4qcIM.cjs +0 -2
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
import{createPluginFactory as V,BasePlugin as j}from"../../factory/index.mjs";import{escapeHtmlAttr as G}from"../../common/format/index.mjs";import{makeCallback as g}from"../../common/script/index.mjs";import{validateNonNegativeNumber as C,validateCallbackFields as J,validateNoScriptInTemplate as z,validateGlobalName as Y,validateNestedDuration as x}from"../../common/validation/index.mjs";import{injectHeadAndBody as K}from"../../common/html/index.mjs";import"../../logger/index.mjs";import"../../common/object/index.mjs";import"../../shared/vite-plugin.DcExl6jd.mjs";import"crypto";const o="__loading-overlay__",c="__loading-hidden__",f="__loading-visible__",H="__loading-top__",F="__loading-center__",A="__loading-bottom__",r="__loading-spinner__",B="__loading-text__",s="__loading-dot__",S="__loading-root__",D="data-loading-text",M="__loading-spin__",L="__loading-dots__",O="__loading-pulse__",N="__loading-bar__",Q={center:F,top:H,bottom:A};function W(e,t="spinner",n){const{overlayColor:i="rgba(255, 255, 255, 0.7)",spinnerColor:l="#4361ee",spinnerSize:d="40px",textColor:a="#333",textSize:u="14px",zIndex:p=9999,pointerEvents:$=!0,backdropBlur:_=!1,backdropBlurAmount:m=4}=e,b=$?"":"pointer-events: none;",v=_?`backdrop-filter: blur(${m}px);-webkit-backdrop-filter: blur(${m}px);`:"",T=Z(t,l,d),w=n?.enabled!==!1,h=n?.duration??200,y=n?.easing??"ease-out",E=w?`transition: opacity ${h}ms ${y}, visibility ${h}ms ${y};`:"";return`
|
|
2
|
+
.${o} {
|
|
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: ${p};
|
|
13
|
+
${b}
|
|
14
|
+
${v}
|
|
15
|
+
contain: content;
|
|
16
|
+
will-change: opacity;
|
|
17
|
+
}
|
|
18
|
+
.${o}.${H} {
|
|
19
|
+
justify-content: flex-start;
|
|
20
|
+
padding-top: 60px;
|
|
21
|
+
}
|
|
22
|
+
.${o}.${F} {
|
|
23
|
+
justify-content: center;
|
|
24
|
+
}
|
|
25
|
+
.${o}.${A} {
|
|
26
|
+
justify-content: flex-end;
|
|
27
|
+
padding-bottom: 60px;
|
|
28
|
+
}
|
|
29
|
+
${T}
|
|
30
|
+
.${B} {
|
|
31
|
+
margin-top: 12px;
|
|
32
|
+
color: ${a};
|
|
33
|
+
font-size: ${u};
|
|
34
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
35
|
+
user-select: none;
|
|
36
|
+
}
|
|
37
|
+
.${o}.${c} {
|
|
38
|
+
opacity: 0;
|
|
39
|
+
visibility: hidden;
|
|
40
|
+
${E}
|
|
41
|
+
}
|
|
42
|
+
.${o}.${c} .${r},
|
|
43
|
+
.${o}.${c} .${s},
|
|
44
|
+
.${o}.${c} .${r}::after {
|
|
45
|
+
animation-play-state: paused;
|
|
46
|
+
}
|
|
47
|
+
.${o}.${f} {
|
|
48
|
+
opacity: 1;
|
|
49
|
+
visibility: visible;
|
|
50
|
+
${E}
|
|
51
|
+
}
|
|
52
|
+
.${o}.${f} .${r},
|
|
53
|
+
.${o}.${f} .${s},
|
|
54
|
+
.${o}.${f} .${r}::after {
|
|
55
|
+
animation-play-state: running;
|
|
56
|
+
}`}function Z(e,t,n){switch(e){case"dots":return`
|
|
57
|
+
.${r} {
|
|
58
|
+
display: flex;
|
|
59
|
+
gap: 6px;
|
|
60
|
+
align-items: center;
|
|
61
|
+
}
|
|
62
|
+
.${r} .${s} {
|
|
63
|
+
width: calc(${n} / 4);
|
|
64
|
+
height: calc(${n} / 4);
|
|
65
|
+
border-radius: 50%;
|
|
66
|
+
background: ${t};
|
|
67
|
+
animation: ${L} 1.2s ease-in-out infinite;
|
|
68
|
+
}
|
|
69
|
+
.${r} .${s}:nth-child(2) { animation-delay: 0.15s; }
|
|
70
|
+
.${r} .${s}:nth-child(3) { animation-delay: 0.3s; }
|
|
71
|
+
@keyframes ${L} {
|
|
72
|
+
0%, 80%, 100% { transform: scale(0.4); opacity: 0.4; }
|
|
73
|
+
40% { transform: scale(1); opacity: 1; }
|
|
74
|
+
}`;case"pulse":return`
|
|
75
|
+
.${r} {
|
|
76
|
+
width: ${n};
|
|
77
|
+
height: ${n};
|
|
78
|
+
background: ${t};
|
|
79
|
+
border-radius: 50%;
|
|
80
|
+
animation: ${O} 1.2s ease-in-out infinite;
|
|
81
|
+
}
|
|
82
|
+
@keyframes ${O} {
|
|
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
|
+
.${r} {
|
|
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
|
+
.${r}::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: ${N} 1.2s ease-in-out infinite;
|
|
105
|
+
}
|
|
106
|
+
@keyframes ${N} {
|
|
107
|
+
0% { left: -40%; }
|
|
108
|
+
100% { left: 100%; }
|
|
109
|
+
}`;default:return`
|
|
110
|
+
.${r} {
|
|
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: ${M} 0.8s linear infinite;
|
|
117
|
+
}
|
|
118
|
+
@keyframes ${M} {
|
|
119
|
+
to { transform: rotate(360deg); }
|
|
120
|
+
}`}}function ee(e){const t=e.position||"center",n=e.defaultText||"\u52A0\u8F7D\u4E2D...",i=e.spinnerType||"spinner",l=Q[t],d=e.style?.customClass?` ${e.style.customClass}`:"",a=e.style?.customStyle?` style="${G(e.style.customStyle)}"`:"",u=e.defaultVisible?f:c;if(e.customTemplate)return`<div class="${o} ${l} ${u}${d}" id="${S}"${a}>${e.customTemplate}</div>`;const p=te(i);return`<div class="${o} ${l} ${u}${d}" id="${S}"${a}>
|
|
121
|
+
${p}
|
|
122
|
+
<div class="${B}" ${D}>${n}</div>
|
|
123
|
+
</div>`}function te(e){switch(e){case"dots":return`<div class="${r}"><div class="${s}"></div><div class="${s}"></div><div class="${s}"></div></div>`;default:return`<div class="${r}"></div>`}}function ne(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 ie(e){return` function _findEl() {
|
|
158
|
+
if (!_loadingEl) {
|
|
159
|
+
_loadingEl = document.getElementById('${S}');
|
|
160
|
+
}
|
|
161
|
+
if (!_textEl && _loadingEl) {
|
|
162
|
+
_textEl = _loadingEl.querySelector('[${D}]');
|
|
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 oe(){return` function _applyHide() {
|
|
206
|
+
if (!_loadingEl) return;
|
|
207
|
+
_loadingEl.classList.remove('${f}');
|
|
208
|
+
_loadingEl.classList.add('${c}');
|
|
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('${c}');
|
|
230
|
+
_loadingEl.classList.add('${f}');
|
|
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 re(){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 ae(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 le(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 ue(e){const t=e.globalName||"__LOADING_MANAGER__",n=e.minDisplayTime||{enabled:!0,duration:300},i=e.delayShow||{enabled:!0,duration:200},l=e.debounceHide||{enabled:!1,duration:100},d=e.transition||{enabled:!0,duration:200,easing:"ease-out"},a=e.autoBind||"none",u=e.requestFilter||{},p=e.defaultVisible||!1,$=e.autoHideOn||"DOMContentLoaded",_=e.callbacks||{},m=u.excludeUrls||[],b=u.includeUrls||[],v=u.excludeMethods||[],T=u.excludeUrlPrefixes||[],w=g(_.onBeforeShow,"loadingManager"),h=g(_.onShow,"loadingManager"),y=g(_.onBeforeHide,"loadingManager"),E=g(_.onHide,"loadingManager"),R=g(_.onDestroy,"loadingManager"),I=ne({minDisplayTime:n,delayShow:i,debounceHide:l,transition:d,excludeUrls:m,includeUrls:b,excludeMethods:v,excludeUrlPrefixes:T,cbBeforeShow:w,cbShow:h,cbBeforeHide:y,cbHide:E,cbDestroy:R}),k=ie(t),U=oe(),P=re(),X=ae(a),q=le(p,$,t);return`(function() {
|
|
434
|
+
'use strict';
|
|
435
|
+
|
|
436
|
+
// SSR \u73AF\u5883\u68C0\u6D4B
|
|
437
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') return;
|
|
438
|
+
|
|
439
|
+
${I}
|
|
440
|
+
|
|
441
|
+
${k}
|
|
442
|
+
|
|
443
|
+
${U}
|
|
444
|
+
|
|
445
|
+
var manager = {
|
|
446
|
+
${P}
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
${X}
|
|
450
|
+
|
|
451
|
+
${q}
|
|
452
|
+
})();`}function de(e){if(!e)return;const{zIndex:t,pointerEvents:n,backdropBlurAmount:i}=e;if(C(t,"style.zIndex"),n!==void 0&&typeof n!="boolean")throw new Error("style.pointerEvents \u5FC5\u987B\u662F\u5E03\u5C14\u503C");C(i,"style.backdropBlurAmount")}function se(e){if(!e)return;const{duration:t,easing:n}=e;if(C(t,"transition.duration"),n!==void 0&&typeof n!="string")throw new Error("transition.easing \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u7C7B\u578B")}function _e(e){e&&J(e,["onBeforeShow","onShow","onBeforeHide","onHide","onDestroy"],"callbacks")}function ce(e){return e===""?"defaultText \u4E3A\u7A7A\u5B57\u7B26\u4E32\uFF0Cloading \u5C06\u4E0D\u663E\u793A\u6587\u672C\u5185\u5BB9":null}function fe(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 pe extends j{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(),z(this.options.customTemplate,"customTemplate");const t=ce(this.options.defaultText);t&&this.logger.warn(t),Y(this.options.globalName,"globalName"),de(this.options.style),x(this.options.minDisplayTime,"minDisplayTime.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),x(this.options.delayShow,"delayShow.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),x(this.options.debounceHide,"debounceHide.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),se(this.options.transition),_e(this.options.callbacks);const n=fe(this.options.defaultVisible,this.options.autoHideOn);n&&this.logger.warn(n)}getPluginName(){return"loading-manager"}generateLoadingManager(t){return ue(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:l}=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(l)};
|
|
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:W(t,n,i),html:ee(this.options)}}return this._cachedAssets}addPluginHooks(t){const n=this.options.defaultVisible||!1,i=n?this.generateHeadInjectCode():void 0,l=this.generateBodyInjectCode(n);t.transformIndexHtml={order:"post",handler:d=>{const a=K(d,i,l);return i&&!a.headInjected&&this.logger.warn("\u672A\u627E\u5230 </head> \u6807\u7B7E\uFF0CdefaultVisible \u7684\u767D\u5C4F loading \u5C06\u65E0\u6CD5\u751F\u6548"),a.usedFallback&&this.logger.warn("\u672A\u627E\u5230 </body> \u6216 </html> \u6807\u7B7E\uFF0CLoading \u4EE3\u7801\u8FFD\u52A0\u5230\u6587\u4EF6\u672B\u5C3E"),a.bodyInjected&&this.logger.success("\u6210\u529F\u6CE8\u5165\u5168\u5C40 Loading \u72B6\u6001\u7BA1\u7406\u4EE3\u7801\u5230 HTML \u6587\u4EF6"),a.html}}}}const ge=V(pe);export{ge as loadingManager};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";const factory_index=require("../../factory/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");function generateCSS(e,n){const u=".__vuc-overlay__{position:fixed;top:0;left:0;right:0;bottom:0;z-index:99999;pointer-events:none;}";let t="";switch(e){case"modal":t=`.__vuc-modal__{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:#fff;border-radius:12px;box-shadow:0 8px 32px rgba(0,0,0,0.15);padding:32px;max-width:420px;width:90%;z-index:100000;pointer-events:auto;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;text-align:center;}
|
|
2
|
+
.__vuc-modal-title__{font-size:18px;font-weight:600;color:#1a1a2e;margin:0 0 12px 0;}
|
|
3
|
+
.__vuc-modal-body__{font-size:14px;color:#555;line-height:1.6;margin:0 0 8px 0;}
|
|
4
|
+
.__vuc-modal-version__{font-size:12px;color:#999;margin:0 0 24px 0;}
|
|
5
|
+
.__vuc-modal-version__ span{font-family:Consolas,'Courier New',monospace;background:#f0f0f0;padding:2px 6px;border-radius:4px;font-size:11px;}
|
|
6
|
+
.__vuc-modal-actions__{display:flex;gap:12px;justify-content:center;}
|
|
7
|
+
.__vuc-btn__{padding:10px 24px;border-radius:8px;font-size:14px;cursor:pointer;border:none;transition:all 0.2s ease;}
|
|
8
|
+
.__vuc-btn-refresh__{background:#4361ee;color:#fff;}
|
|
9
|
+
.__vuc-btn-refresh__:hover{background:#3451d1;}
|
|
10
|
+
.__vuc-btn-dismiss__{background:#f0f0f0;color:#666;}
|
|
11
|
+
.__vuc-btn-dismiss__:hover{background:#e0e0e0;}`;break;case"banner":t=`.__vuc-banner__{position:fixed;top:0;left:0;right:0;background:linear-gradient(135deg,#4361ee,#7c3aed);color:#fff;padding:12px 20px;z-index:100000;pointer-events:auto;display:flex;align-items:center;justify-content:space-between;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;box-shadow:0 2px 12px rgba(67,97,238,0.3);}
|
|
12
|
+
.__vuc-banner-text__{font-size:14px;flex:1;}
|
|
13
|
+
.__vuc-banner-actions__{display:flex;gap:8px;flex-shrink:0;}
|
|
14
|
+
.__vuc-btn-banner-refresh__{background:rgba(255,255,255,0.2);color:#fff;border:1px solid rgba(255,255,255,0.3);padding:6px 16px;border-radius:6px;font-size:13px;cursor:pointer;transition:all 0.2s ease;}
|
|
15
|
+
.__vuc-btn-banner-refresh__:hover{background:rgba(255,255,255,0.3);}
|
|
16
|
+
.__vuc-btn-banner-dismiss__{background:transparent;color:rgba(255,255,255,0.8);border:none;padding:6px 12px;font-size:13px;cursor:pointer;}
|
|
17
|
+
.__vuc-btn-banner-dismiss__:hover{color:#fff;}`;break;case"toast":t=`.__vuc-toast__{position:fixed;bottom:24px;left:50%;transform:translateX(-50%);background:#1a1a2e;color:#fff;padding:14px 24px;border-radius:10px;z-index:100000;pointer-events:auto;display:flex;align-items:center;gap:12px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;box-shadow:0 4px 20px rgba(0,0,0,0.2);max-width:90%;}
|
|
18
|
+
.__vuc-toast-text__{font-size:14px;white-space:nowrap;}
|
|
19
|
+
.__vuc-btn-toast-refresh__{background:#4361ee;color:#fff;border:none;padding:6px 16px;border-radius:6px;font-size:13px;cursor:pointer;white-space:nowrap;transition:all 0.2s ease;}
|
|
20
|
+
.__vuc-btn-toast-refresh__:hover{background:#3451d1;}
|
|
21
|
+
.__vuc-btn-toast-dismiss__{background:transparent;color:rgba(255,255,255,0.6);border:none;padding:6px 12px;font-size:13px;cursor:pointer;white-space:nowrap;transition:all 0.2s ease;}
|
|
22
|
+
.__vuc-btn-toast-dismiss__:hover{color:#fff;}`;break}return`<style data-vuc-style>${u}${t}${n||""}</style>`}function generateHTMLTemplate(e){const n=e.promptStyle||"modal",u=e.promptMessage||"\u53D1\u73B0\u65B0\u7248\u672C\uFF0C\u662F\u5426\u7ACB\u5373\u5237\u65B0\u83B7\u53D6\u6700\u65B0\u5185\u5BB9\uFF1F",t=e.refreshButtonText||"\u7ACB\u5373\u5237\u65B0",r=e.dismissButtonText||"\u7A0D\u540E\u518D\u8BF4";if(e.customPromptTemplate)return e.customPromptTemplate.replace(/\{\{message\}\}/g,u).replace(/\{\{currentVersion\}\}/g,'<span id="__vuc-current__"></span>').replace(/\{\{newVersion\}\}/g,'<span id="__vuc-new__"></span>').replace(/\{\{refreshButton\}\}/g,`<button class="__vuc-btn-refresh__" onclick="window.__VUC_REFRESH__()">${t}</button>`).replace(/\{\{dismissButton\}\}/g,`<button class="__vuc-btn-dismiss__" onclick="window.__VUC_DISMISS__()">${r}</button>`);switch(n){case"modal":return`<div class="__vuc-overlay__"><div class="__vuc-modal__">
|
|
23
|
+
<p class="__vuc-modal-title__">\u7248\u672C\u66F4\u65B0</p>
|
|
24
|
+
<p class="__vuc-modal-body__">${u}</p>
|
|
25
|
+
<p class="__vuc-modal-version__"><span id="__vuc-current__"></span> \u2192 <span id="__vuc-new__"></span></p>
|
|
26
|
+
<div class="__vuc-modal-actions__">
|
|
27
|
+
<button class="__vuc-btn__ __vuc-btn-dismiss__" onclick="window.__VUC_DISMISS__()">${r}</button>
|
|
28
|
+
<button class="__vuc-btn__ __vuc-btn-refresh__" onclick="window.__VUC_REFRESH__()">${t}</button>
|
|
29
|
+
</div></div></div>`;case"banner":return`<div class="__vuc-overlay__"><div class="__vuc-banner__">
|
|
30
|
+
<span class="__vuc-banner-text__">${u}</span>
|
|
31
|
+
<div class="__vuc-banner-actions__">
|
|
32
|
+
<button class="__vuc-btn-banner-dismiss__" onclick="window.__VUC_DISMISS__()">${r}</button>
|
|
33
|
+
<button class="__vuc-btn-banner-refresh__" onclick="window.__VUC_REFRESH__()">${t}</button>
|
|
34
|
+
</div></div></div>`;case"toast":return`<div class="__vuc-overlay__"><div class="__vuc-toast__">
|
|
35
|
+
<span class="__vuc-toast-text__">${u}</span>
|
|
36
|
+
<button class="__vuc-btn-toast-dismiss__" onclick="window.__VUC_DISMISS__()">${r}</button>
|
|
37
|
+
<button class="__vuc-btn-toast-refresh__" onclick="window.__VUC_REFRESH__()">${t}</button>
|
|
38
|
+
</div></div>`;default:return`<div class="__vuc-overlay__"><div class="__vuc-modal__">
|
|
39
|
+
<p class="__vuc-modal-title__">\u7248\u672C\u66F4\u65B0</p>
|
|
40
|
+
<p class="__vuc-modal-body__">${u}</p>
|
|
41
|
+
<p class="__vuc-modal-version__"><span id="__vuc-current__"></span> \u2192 <span id="__vuc-new__"></span></p>
|
|
42
|
+
<div class="__vuc-modal-actions__">
|
|
43
|
+
<button class="__vuc-btn__ __vuc-btn-dismiss__" onclick="window.__VUC_DISMISS__()">${r}</button>
|
|
44
|
+
<button class="__vuc-btn__ __vuc-btn-refresh__" onclick="window.__VUC_REFRESH__()">${t}</button>
|
|
45
|
+
</div></div></div>`}}function generateCheckerCode(e){const n=e.versionSource||"auto",u=e.defineName||"__APP_VERSION__",t=e.checkUrl||"/version.json",r=e.checkInterval||3e5,o=e.checkOnVisibilityChange!==!1,i=e.enableInDev||!1,a=common_script_index.makeCallback(e.onUpdateAvailable,"versionUpdateChecker","currentVersion, newVersion"),_=common_script_index.makeCallback(e.onRefresh,"versionUpdateChecker","currentVersion, newVersion"),c=common_script_index.makeCallback(e.onDismiss,"versionUpdateChecker","currentVersion, newVersion");let s="";return(n==="define"||n==="auto")&&(s=`
|
|
46
|
+
// \u4F18\u5148\u4ECE define \u5168\u5C40\u53D8\u91CF\u8BFB\u53D6
|
|
47
|
+
if (typeof ${u} !== 'undefined') return ${u};`),(n==="file"||n==="auto")&&(s+=`
|
|
48
|
+
// \u4ECE\u9875\u9762 meta \u6807\u7B7E\u8BFB\u53D6
|
|
49
|
+
var metaEl = document.querySelector('meta[name="app-version"]');
|
|
50
|
+
if (metaEl && metaEl.getAttribute('content')) return metaEl.getAttribute('content');`),s+=`
|
|
51
|
+
return null;`,`;(function() {
|
|
52
|
+
'use strict';
|
|
53
|
+
|
|
54
|
+
// SSR \u73AF\u5883\u68C0\u6D4B
|
|
55
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') return;
|
|
56
|
+
|
|
57
|
+
// \u5F00\u53D1\u6A21\u5F0F\u68C0\u6D4B
|
|
58
|
+
var _isDev = typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'development';
|
|
59
|
+
if (_isDev && !${JSON.stringify(i)}) return;
|
|
60
|
+
|
|
61
|
+
// \u72B6\u6001
|
|
62
|
+
var _currentVersion = null;
|
|
63
|
+
var _latestVersion = null;
|
|
64
|
+
var _promptVisible = false;
|
|
65
|
+
var _dismissed = false;
|
|
66
|
+
var _delayTimer = null;
|
|
67
|
+
var _intervalTimer = null;
|
|
68
|
+
var _destroyed = false;
|
|
69
|
+
|
|
70
|
+
// \u83B7\u53D6\u5F53\u524D\u7248\u672C\u53F7
|
|
71
|
+
function _getCurrentVersion() {${s}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// \u68C0\u67E5\u7248\u672C\u66F4\u65B0
|
|
75
|
+
function _checkForUpdate() {
|
|
76
|
+
if (_destroyed || _dismissed || _promptVisible) return;
|
|
77
|
+
|
|
78
|
+
var xhr = new XMLHttpRequest();
|
|
79
|
+
xhr.open('GET', ${JSON.stringify(t)} + '?_t=' + Date.now(), true);
|
|
80
|
+
xhr.timeout = 10000;
|
|
81
|
+
xhr.onreadystatechange = function() {
|
|
82
|
+
if (xhr.readyState !== 4) return;
|
|
83
|
+
if (xhr.status !== 200) return;
|
|
84
|
+
try {
|
|
85
|
+
var data = JSON.parse(xhr.responseText);
|
|
86
|
+
_latestVersion = data.version || data;
|
|
87
|
+
if (!_currentVersion) _currentVersion = _getCurrentVersion();
|
|
88
|
+
if (!_currentVersion || !_latestVersion) return;
|
|
89
|
+
if (_currentVersion === _latestVersion) return;
|
|
90
|
+
|
|
91
|
+
// \u7248\u672C\u4E0D\u4E00\u81F4\uFF0C\u53D1\u73B0\u66F4\u65B0
|
|
92
|
+
var shouldShow = ${a}(_currentVersion, _latestVersion);
|
|
93
|
+
if (shouldShow !== false) {
|
|
94
|
+
_showPrompt();
|
|
95
|
+
}
|
|
96
|
+
} catch(e) {
|
|
97
|
+
// \u89E3\u6790\u5931\u8D25\uFF0C\u9759\u9ED8\u5FFD\u7565
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
xhr.send();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// \u663E\u793A\u66F4\u65B0\u63D0\u793A
|
|
104
|
+
function _showPrompt() {
|
|
105
|
+
if (_promptVisible || _destroyed) return;
|
|
106
|
+
_promptVisible = true;
|
|
107
|
+
|
|
108
|
+
var container = document.getElementById('__vuc-root__');
|
|
109
|
+
if (!container) return;
|
|
110
|
+
|
|
111
|
+
container.style.display = '';
|
|
112
|
+
|
|
113
|
+
// \u586B\u5145\u7248\u672C\u53F7
|
|
114
|
+
var currentEl = document.getElementById('__vuc-current__');
|
|
115
|
+
var newEl = document.getElementById('__vuc-new__');
|
|
116
|
+
if (currentEl) currentEl.textContent = _currentVersion;
|
|
117
|
+
if (newEl) newEl.textContent = _latestVersion;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// \u9690\u85CF\u66F4\u65B0\u63D0\u793A
|
|
121
|
+
function _hidePrompt() {
|
|
122
|
+
_promptVisible = false;
|
|
123
|
+
var container = document.getElementById('__vuc-root__');
|
|
124
|
+
if (container) container.style.display = 'none';
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// \u5237\u65B0\u9875\u9762
|
|
128
|
+
window.__VUC_REFRESH__ = function() {
|
|
129
|
+
${_}(_currentVersion, _latestVersion);
|
|
130
|
+
window.location.reload();
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// \u5FFD\u7565\u66F4\u65B0
|
|
134
|
+
window.__VUC_DISMISS__ = function() {
|
|
135
|
+
${c}(_currentVersion, _latestVersion);
|
|
136
|
+
_dismissed = true;
|
|
137
|
+
_hidePrompt();
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// \u542F\u52A8\u5B9A\u65F6\u68C0\u67E5
|
|
141
|
+
function _startChecking() {
|
|
142
|
+
_currentVersion = _getCurrentVersion();
|
|
143
|
+
if (!_currentVersion) {
|
|
144
|
+
console.warn('[versionUpdateChecker] \u65E0\u6CD5\u83B7\u53D6\u5F53\u524D\u7248\u672C\u53F7\uFF0C\u7248\u672C\u68C0\u67E5\u5DF2\u8DF3\u8FC7\u3002\u8BF7\u786E\u8BA4 generateVersion \u63D2\u4EF6\u5DF2\u6B63\u786E\u914D\u7F6E\u3002');
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// \u9996\u6B21\u5EF6\u8FDF 10 \u79D2\u68C0\u67E5\uFF0C\u907F\u514D\u9875\u9762\u521A\u52A0\u8F7D\u5C31\u5F39\u51FA
|
|
149
|
+
_delayTimer = setTimeout(function() {
|
|
150
|
+
_checkForUpdate();
|
|
151
|
+
// \u4E4B\u540E\u6309\u95F4\u9694\u5B9A\u671F\u68C0\u67E5
|
|
152
|
+
_intervalTimer = setInterval(_checkForUpdate, ${r});
|
|
153
|
+
}, 10000);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// \u9500\u6BC1\u68C0\u67E5\u5668\uFF0C\u6E05\u7406\u5B9A\u65F6\u5668\u548C DOM
|
|
157
|
+
function _destroy() {
|
|
158
|
+
_destroyed = true;
|
|
159
|
+
if (_delayTimer) { clearTimeout(_delayTimer); _delayTimer = null; }
|
|
160
|
+
if (_intervalTimer) { clearInterval(_intervalTimer); _intervalTimer = null; }
|
|
161
|
+
var container = document.getElementById('__vuc-root__');
|
|
162
|
+
if (container) container.parentNode.removeChild(container);
|
|
163
|
+
var styleEl = document.querySelector('style[data-vuc-style]');
|
|
164
|
+
if (styleEl) styleEl.parentNode.removeChild(styleEl);
|
|
165
|
+
delete window.__VUC_REFRESH__;
|
|
166
|
+
delete window.__VUC_DISMISS__;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// \u9875\u9762\u53EF\u89C1\u6027\u53D8\u5316\u65F6\u68C0\u67E5
|
|
170
|
+
${o?`
|
|
171
|
+
document.addEventListener('visibilitychange', function() {
|
|
172
|
+
if (!document.hidden && !_destroyed && !_dismissed && !_promptVisible) {
|
|
173
|
+
_checkForUpdate();
|
|
174
|
+
}
|
|
175
|
+
});`:""}
|
|
176
|
+
|
|
177
|
+
// DOM \u5C31\u7EEA\u540E\u542F\u52A8
|
|
178
|
+
if (document.readyState === 'loading') {
|
|
179
|
+
document.addEventListener('DOMContentLoaded', _startChecking);
|
|
180
|
+
} else {
|
|
181
|
+
_startChecking();
|
|
182
|
+
}
|
|
183
|
+
})();`}function generateMetaTag(e){const n=e.versionSource||"auto";return n!=="file"&&n!=="auto"?"":`<meta name="app-version" content="${e.defineName||"__APP_VERSION__"}">`}function generateFullInjectCode(e){const n=generateCSS(e.promptStyle||"modal",e.customStyle),u=generateHTMLTemplate(e),t=generateCheckerCode(e);return`${n}
|
|
184
|
+
<div id="__vuc-root__" style="display:none">${u}</div>
|
|
185
|
+
<script>${t}<\/script>`}function validateCallbacks(e){common_validation_index.validateCallbackFields(e,["onUpdateAvailable","onRefresh","onDismiss"],"callbacks")}function validateAll(e){common_validation_index.validateNoScriptInTemplate(e.customPromptTemplate,"customPromptTemplate"),validateCallbacks(e),common_validation_index.validateGlobalName(e.defineName,"defineName")}class p extends factory_index.BasePlugin{getDefaultOptions(){return{versionSource:"auto",defineName:"__APP_VERSION__",checkUrl:"/version.json",checkInterval:3e5,checkOnVisibilityChange:!0,enableInDev:!1,promptStyle:"modal",promptMessage:"\u53D1\u73B0\u65B0\u7248\u672C\uFF0C\u662F\u5426\u7ACB\u5373\u5237\u65B0\u83B7\u53D6\u6700\u65B0\u5185\u5BB9\uFF1F",refreshButtonText:"\u7ACB\u5373\u5237\u65B0",dismissButtonText:"\u7A0D\u540E\u518D\u8BF4"}}validateOptions(){this.validator.field("versionSource").enum(["define","file","auto"]).field("promptStyle").enum(["modal","banner","toast"]).field("checkInterval").number().minValue(5e3).validate(),validateAll(this.options)}getPluginName(){return"version-update-checker"}addPluginHooks(n){const u=generateFullInjectCode(this.options),t=generateMetaTag(this.options);n.transformIndexHtml={order:"post",handler:r=>{const o=common_html_index.injectHeadAndBody(r,t,u);return o.usedFallback&&this.logger.warn("\u672A\u627E\u5230 </body> \u6216 </html> \u6807\u7B7E\uFF0C\u7248\u672C\u66F4\u65B0\u68C0\u67E5\u4EE3\u7801\u8FFD\u52A0\u5230\u6587\u4EF6\u672B\u5C3E"),o.bodyInjected&&this.logger.success("\u6210\u529F\u6CE8\u5165\u7248\u672C\u66F4\u65B0\u68C0\u67E5\u4EE3\u7801\u5230 HTML \u6587\u4EF6"),o.html}}}}const versionUpdateChecker=factory_index.createPluginFactory(p);exports.versionUpdateChecker=versionUpdateChecker;
|