@meng-xi/vite-plugin 0.1.4 → 0.1.6
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 +34 -20
- package/README.md +33 -19
- package/dist/common/format/index.cjs +1 -1
- package/dist/common/format/index.d.cts +19 -114
- package/dist/common/format/index.d.mts +19 -114
- package/dist/common/format/index.d.ts +19 -114
- package/dist/common/format/index.mjs +1 -1
- package/dist/common/fs/index.cjs +1 -1
- package/dist/common/fs/index.d.cts +36 -89
- package/dist/common/fs/index.d.mts +36 -89
- package/dist/common/fs/index.d.ts +36 -89
- package/dist/common/fs/index.mjs +1 -1
- package/dist/common/html/index.cjs +2 -2
- package/dist/common/html/index.d.cts +12 -307
- package/dist/common/html/index.d.mts +12 -307
- package/dist/common/html/index.d.ts +12 -307
- package/dist/common/html/index.mjs +2 -2
- package/dist/common/index.cjs +1 -1
- package/dist/common/index.d.cts +7 -11
- package/dist/common/index.d.mts +7 -11
- package/dist/common/index.d.ts +7 -11
- package/dist/common/index.mjs +1 -1
- package/dist/common/script/index.cjs +1 -1
- package/dist/common/script/index.d.cts +1 -44
- package/dist/common/script/index.d.mts +1 -44
- package/dist/common/script/index.d.ts +1 -44
- package/dist/common/script/index.mjs +1 -1
- package/dist/common/ui/index.cjs +1 -1
- package/dist/common/ui/index.d.cts +1 -111
- package/dist/common/ui/index.d.mts +1 -111
- package/dist/common/ui/index.d.ts +1 -111
- package/dist/common/ui/index.mjs +1 -1
- package/dist/common/validation/index.cjs +1 -1
- package/dist/common/validation/index.d.cts +2 -80
- package/dist/common/validation/index.d.mts +2 -80
- package/dist/common/validation/index.d.ts +2 -80
- package/dist/common/validation/index.mjs +1 -1
- 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 +10 -12
- package/dist/index.d.mts +10 -12
- package/dist/index.d.ts +10 -12
- package/dist/index.mjs +1 -1
- package/dist/logger/index.d.cts +92 -1
- package/dist/logger/index.d.mts +92 -1
- package/dist/logger/index.d.ts +92 -1
- package/dist/plugins/autoImport/index.cjs +19 -0
- package/dist/plugins/autoImport/index.d.cts +291 -0
- package/dist/plugins/autoImport/index.d.mts +291 -0
- package/dist/plugins/autoImport/index.d.ts +291 -0
- package/dist/plugins/autoImport/index.mjs +19 -0
- package/dist/plugins/buildProgress/index.cjs +1 -1
- package/dist/plugins/buildProgress/index.d.cts +1 -1
- package/dist/plugins/buildProgress/index.d.mts +1 -1
- package/dist/plugins/buildProgress/index.d.ts +1 -1
- package/dist/plugins/buildProgress/index.mjs +2 -2
- package/dist/plugins/bundleAnalyzer/index.cjs +21 -21
- package/dist/plugins/bundleAnalyzer/index.d.cts +1 -1
- package/dist/plugins/bundleAnalyzer/index.d.mts +1 -1
- package/dist/plugins/bundleAnalyzer/index.d.ts +1 -1
- package/dist/plugins/bundleAnalyzer/index.mjs +18 -18
- package/dist/plugins/compressAssets/index.cjs +1 -1
- package/dist/plugins/compressAssets/index.d.cts +1 -1
- package/dist/plugins/compressAssets/index.d.mts +1 -1
- package/dist/plugins/compressAssets/index.d.ts +1 -1
- package/dist/plugins/compressAssets/index.mjs +1 -1
- package/dist/plugins/copyFile/index.cjs +1 -1
- package/dist/plugins/copyFile/index.d.cts +1 -1
- package/dist/plugins/copyFile/index.d.mts +1 -1
- package/dist/plugins/copyFile/index.d.ts +1 -1
- package/dist/plugins/copyFile/index.mjs +1 -1
- package/dist/plugins/envGuard/index.cjs +11 -11
- package/dist/plugins/envGuard/index.d.cts +101 -2
- package/dist/plugins/envGuard/index.d.mts +101 -2
- package/dist/plugins/envGuard/index.d.ts +101 -2
- package/dist/plugins/envGuard/index.mjs +9 -9
- package/dist/plugins/faviconManager/index.cjs +1 -1
- package/dist/plugins/faviconManager/index.d.cts +1 -1
- package/dist/plugins/faviconManager/index.d.mts +1 -1
- package/dist/plugins/faviconManager/index.d.ts +1 -1
- package/dist/plugins/faviconManager/index.mjs +1 -1
- package/dist/plugins/generateRouter/index.cjs +5 -4
- package/dist/plugins/generateRouter/index.d.cts +34 -1
- package/dist/plugins/generateRouter/index.d.mts +34 -1
- package/dist/plugins/generateRouter/index.d.ts +34 -1
- package/dist/plugins/generateRouter/index.mjs +5 -4
- package/dist/plugins/generateVersion/index.cjs +1 -1
- package/dist/plugins/generateVersion/index.d.cts +1 -1
- package/dist/plugins/generateVersion/index.d.mts +1 -1
- package/dist/plugins/generateVersion/index.d.ts +1 -1
- package/dist/plugins/generateVersion/index.mjs +1 -1
- package/dist/plugins/htmlInject/index.cjs +7 -1
- package/dist/plugins/htmlInject/index.d.cts +2 -2
- package/dist/plugins/htmlInject/index.d.mts +2 -2
- package/dist/plugins/htmlInject/index.d.ts +2 -2
- package/dist/plugins/htmlInject/index.mjs +7 -1
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +3 -3
- package/dist/plugins/index.d.mts +3 -3
- package/dist/plugins/index.d.ts +3 -3
- package/dist/plugins/index.mjs +1 -1
- package/dist/plugins/loadingManager/index.cjs +26 -26
- package/dist/plugins/loadingManager/index.d.cts +1 -1
- package/dist/plugins/loadingManager/index.d.mts +1 -1
- package/dist/plugins/loadingManager/index.d.ts +1 -1
- package/dist/plugins/loadingManager/index.mjs +10 -10
- package/dist/plugins/versionUpdateChecker/index.cjs +5 -5
- package/dist/plugins/versionUpdateChecker/index.d.cts +1 -1
- package/dist/plugins/versionUpdateChecker/index.d.mts +1 -1
- package/dist/plugins/versionUpdateChecker/index.d.ts +1 -1
- package/dist/plugins/versionUpdateChecker/index.mjs +6 -6
- package/dist/shared/vite-plugin.B8FuZce1.d.cts +45 -0
- package/dist/shared/vite-plugin.B8FuZce1.d.mts +45 -0
- package/dist/shared/vite-plugin.B8FuZce1.d.ts +45 -0
- package/dist/shared/{vite-plugin.FfJ-Wwfu.d.cts → vite-plugin.BI9taN75.d.cts} +1 -22
- package/dist/shared/{vite-plugin.FfJ-Wwfu.d.mts → vite-plugin.BI9taN75.d.mts} +1 -22
- package/dist/shared/{vite-plugin.FfJ-Wwfu.d.ts → vite-plugin.BI9taN75.d.ts} +1 -22
- package/dist/shared/vite-plugin.CcvHfrL8.cjs +1 -0
- package/dist/shared/vite-plugin.CuXEJAWX.mjs +1 -0
- package/package.json +7 -17
- package/dist/common/compress/index.cjs +0 -1
- package/dist/common/compress/index.d.cts +0 -23
- package/dist/common/compress/index.d.mts +0 -23
- package/dist/common/compress/index.d.ts +0 -23
- package/dist/common/compress/index.mjs +0 -1
- package/dist/common/object/index.cjs +0 -1
- package/dist/common/object/index.d.cts +0 -30
- package/dist/common/object/index.d.mts +0 -30
- package/dist/common/object/index.d.ts +0 -30
- package/dist/common/object/index.mjs +0 -1
- package/dist/common/path/index.cjs +0 -1
- package/dist/common/path/index.d.cts +0 -22
- package/dist/common/path/index.d.mts +0 -22
- package/dist/common/path/index.d.ts +0 -22
- package/dist/common/path/index.mjs +0 -1
- package/dist/shared/vite-plugin.BCuhU1au.mjs +0 -7
- package/dist/shared/vite-plugin.BrI73DHA.cjs +0 -7
- package/dist/shared/vite-plugin.CLr0ttuO.d.cts +0 -135
- package/dist/shared/vite-plugin.CLr0ttuO.d.mts +0 -135
- package/dist/shared/vite-plugin.CLr0ttuO.d.ts +0 -135
- package/dist/shared/vite-plugin.CmtcnItg.d.cts +0 -261
- package/dist/shared/vite-plugin.CmtcnItg.d.mts +0 -261
- package/dist/shared/vite-plugin.CmtcnItg.d.ts +0 -261
- package/dist/shared/vite-plugin.DnFDPjNf.mjs +0 -1
- package/dist/shared/vite-plugin.Dumot0up.mjs +0 -1
- package/dist/shared/vite-plugin.soT9a-KD.cjs +0 -1
- package/dist/shared/vite-plugin.vwox4bU0.cjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createPluginFactory as V,BasePlugin as j}from"../../factory/index.mjs";import{
|
|
1
|
+
import{createPluginFactory as V,BasePlugin as j}from"../../factory/index.mjs";import{e as G}from"../../shared/vite-plugin.CuXEJAWX.mjs";import{makeCallback as g}from"../../common/script/index.mjs";import{validateCallbackFields as J,validateNoScriptInTemplate as z,validateGlobalName as Y}from"../../common/validation/index.mjs";import{injectHeadAndBody as K}from"../../common/html/index.mjs";import"../../logger/index.mjs";import"../../shared/vite-plugin.DcExl6jd.mjs";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__",C="__loading-root__",D="data-loading-text",L="__loading-spin__",M="__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);`:"",w=Z(t,l,d),T=n?.enabled!==!1,h=n?.duration??200,y=n?.easing??"ease-out",E=T?`transition: opacity ${h}ms ${y}, visibility ${h}ms ${y};`:"";return`
|
|
2
2
|
.${o} {
|
|
3
3
|
position: fixed;
|
|
4
4
|
top: 0;
|
|
@@ -26,7 +26,7 @@ import{createPluginFactory as V,BasePlugin as j}from"../../factory/index.mjs";im
|
|
|
26
26
|
justify-content: flex-end;
|
|
27
27
|
padding-bottom: 60px;
|
|
28
28
|
}
|
|
29
|
-
${
|
|
29
|
+
${w}
|
|
30
30
|
.${B} {
|
|
31
31
|
margin-top: 12px;
|
|
32
32
|
color: ${a};
|
|
@@ -64,11 +64,11 @@ ${T}
|
|
|
64
64
|
height: calc(${n} / 4);
|
|
65
65
|
border-radius: 50%;
|
|
66
66
|
background: ${t};
|
|
67
|
-
animation: ${
|
|
67
|
+
animation: ${M} 1.2s ease-in-out infinite;
|
|
68
68
|
}
|
|
69
69
|
.${r} .${s}:nth-child(2) { animation-delay: 0.15s; }
|
|
70
70
|
.${r} .${s}:nth-child(3) { animation-delay: 0.3s; }
|
|
71
|
-
@keyframes ${
|
|
71
|
+
@keyframes ${M} {
|
|
72
72
|
0%, 80%, 100% { transform: scale(0.4); opacity: 0.4; }
|
|
73
73
|
40% { transform: scale(1); opacity: 1; }
|
|
74
74
|
}`;case"pulse":return`
|
|
@@ -113,11 +113,11 @@ ${T}
|
|
|
113
113
|
border: 3px solid rgba(0, 0, 0, 0.1);
|
|
114
114
|
border-top-color: ${t};
|
|
115
115
|
border-radius: 50%;
|
|
116
|
-
animation: ${
|
|
116
|
+
animation: ${L} 0.8s linear infinite;
|
|
117
117
|
}
|
|
118
|
-
@keyframes ${
|
|
118
|
+
@keyframes ${L} {
|
|
119
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="${
|
|
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="${C}"${a}>${e.customTemplate}</div>`;const p=te(i);return`<div class="${o} ${l} ${u}${d}" id="${C}"${a}>
|
|
121
121
|
${p}
|
|
122
122
|
<div class="${B}" ${D}>${n}</div>
|
|
123
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;
|
|
@@ -156,7 +156,7 @@ ${T}
|
|
|
156
156
|
var _originalXHROpen = null;
|
|
157
157
|
var _originalXHRSend = null;`}function ie(e){return` function _findEl() {
|
|
158
158
|
if (!_loadingEl) {
|
|
159
|
-
_loadingEl = document.getElementById('${
|
|
159
|
+
_loadingEl = document.getElementById('${C}');
|
|
160
160
|
}
|
|
161
161
|
if (!_textEl && _loadingEl) {
|
|
162
162
|
_textEl = _loadingEl.querySelector('[${D}]');
|
|
@@ -430,7 +430,7 @@ ${T}
|
|
|
430
430
|
}
|
|
431
431
|
`),i+=`
|
|
432
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||[],
|
|
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||[],w=u.excludeUrlPrefixes||[],T=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:w,cbBeforeShow:T,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
434
|
'use strict';
|
|
435
435
|
|
|
436
436
|
// SSR \u73AF\u5883\u68C0\u6D4B
|
|
@@ -449,7 +449,7 @@ ${P}
|
|
|
449
449
|
${X}
|
|
450
450
|
|
|
451
451
|
${q}
|
|
452
|
-
})();`}function de(e){if(!e)return;const{zIndex:t,pointerEvents:n,backdropBlurAmount:i}=e;if(
|
|
452
|
+
})();`}function x(e,t){if(e!==void 0&&(typeof e!="number"||e<0))throw new Error(`${t} \u5FC5\u987B\u662F\u975E\u8D1F\u6570`)}function de(e){if(!e)return;const{zIndex:t,pointerEvents:n,backdropBlurAmount:i}=e;if(x(t,"style.zIndex"),n!==void 0&&typeof n!="boolean")throw new Error("style.pointerEvents \u5FC5\u987B\u662F\u5E03\u5C14\u503C");x(i,"style.backdropBlurAmount")}function se(e){if(!e)return;const{duration:t,easing:n}=e;if(x(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}function S(e,t){if(e?.duration!==void 0&&(typeof e.duration!="number"||e.duration<0))throw new Error(t)}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),S(this.options.minDisplayTime,"minDisplayTime.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),S(this.options.delayShow,"delayShow.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),S(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
453
|
<style data-loading-style data-loading-id="${this.options.globalName||"__LOADING_MANAGER__"}">${t}</style>
|
|
454
454
|
${n}
|
|
455
455
|
<!-- loading-manager: head end -->`}generateBodyInjectCode(t){const n=this.generateLoadingManager(this.options);if(t)return`<!-- loading-manager: body start -->
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const factory_index=require("../../factory/index.cjs"),common_script_index=require("../../common/script/index.cjs"),
|
|
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("../../shared/vite-plugin.Bcg6RW2N.cjs"),require("../../shared/vite-plugin.CcvHfrL8.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
2
|
.__vuc-modal-title__{font-size:18px;font-weight:600;color:#1a1a2e;margin:0 0 12px 0;}
|
|
3
3
|
.__vuc-modal-body__{font-size:14px;color:#555;line-height:1.6;margin:0 0 8px 0;}
|
|
4
4
|
.__vuc-modal-version__{font-size:12px;color:#999;margin:0 0 24px 0;}
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
if (_currentVersion === _latestVersion) return;
|
|
90
90
|
|
|
91
91
|
// \u7248\u672C\u4E0D\u4E00\u81F4\uFF0C\u53D1\u73B0\u66F4\u65B0
|
|
92
|
-
var shouldShow = ${a}(_currentVersion, _latestVersion);
|
|
92
|
+
var shouldShow = (${a})(_currentVersion, _latestVersion);
|
|
93
93
|
if (shouldShow !== false) {
|
|
94
94
|
_showPrompt();
|
|
95
95
|
}
|
|
@@ -126,13 +126,13 @@
|
|
|
126
126
|
|
|
127
127
|
// \u5237\u65B0\u9875\u9762
|
|
128
128
|
window.__VUC_REFRESH__ = function() {
|
|
129
|
-
${_}(_currentVersion, _latestVersion);
|
|
129
|
+
(${_})(_currentVersion, _latestVersion);
|
|
130
130
|
window.location.reload();
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
// \u5FFD\u7565\u66F4\u65B0
|
|
134
134
|
window.__VUC_DISMISS__ = function() {
|
|
135
|
-
${c}(_currentVersion, _latestVersion);
|
|
135
|
+
(${c})(_currentVersion, _latestVersion);
|
|
136
136
|
_dismissed = true;
|
|
137
137
|
_hidePrompt();
|
|
138
138
|
};
|
|
@@ -182,4 +182,4 @@
|
|
|
182
182
|
}
|
|
183
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
184
|
<div id="__vuc-root__" style="display:none">${u}</div>
|
|
185
|
-
<script>${t}<\/script>`}function validateCallbacks(e){
|
|
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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createPluginFactory as d,BasePlugin as p}from"../../factory/index.mjs";import{makeCallback as
|
|
1
|
+
import{createPluginFactory as d,BasePlugin as p}from"../../factory/index.mjs";import{makeCallback as i}from"../../common/script/index.mjs";import{validateNoScriptInTemplate as v,validateGlobalName as f,validateCallbackFields as m}from"../../common/validation/index.mjs";import{injectHeadAndBody as b}from"../../common/html/index.mjs";import"../../logger/index.mjs";import"../../shared/vite-plugin.DcExl6jd.mjs";import"../../shared/vite-plugin.CuXEJAWX.mjs";function F(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
2
|
.__vuc-modal-title__{font-size:18px;font-weight:600;color:#1a1a2e;margin:0 0 12px 0;}
|
|
3
3
|
.__vuc-modal-body__{font-size:14px;color:#555;line-height:1.6;margin:0 0 8px 0;}
|
|
4
4
|
.__vuc-modal-version__{font-size:12px;color:#999;margin:0 0 24px 0;}
|
|
@@ -42,7 +42,7 @@ import{createPluginFactory as d,BasePlugin as p}from"../../factory/index.mjs";im
|
|
|
42
42
|
<div class="__vuc-modal-actions__">
|
|
43
43
|
<button class="__vuc-btn__ __vuc-btn-dismiss__" onclick="window.__VUC_DISMISS__()">${r}</button>
|
|
44
44
|
<button class="__vuc-btn__ __vuc-btn-refresh__" onclick="window.__VUC_REFRESH__()">${t}</button>
|
|
45
|
-
</div></div></div>`}}function h(e){const n=e.versionSource||"auto",u=e.defineName||"__APP_VERSION__",t=e.checkUrl||"/version.json",r=e.checkInterval||3e5,o=e.checkOnVisibilityChange!==!1,
|
|
45
|
+
</div></div></div>`}}function h(e){const n=e.versionSource||"auto",u=e.defineName||"__APP_VERSION__",t=e.checkUrl||"/version.json",r=e.checkInterval||3e5,o=e.checkOnVisibilityChange!==!1,a=e.enableInDev||!1,_=i(e.onUpdateAvailable,"versionUpdateChecker","currentVersion, newVersion"),c=i(e.onRefresh,"versionUpdateChecker","currentVersion, newVersion"),l=i(e.onDismiss,"versionUpdateChecker","currentVersion, newVersion");let s="";return(n==="define"||n==="auto")&&(s=`
|
|
46
46
|
// \u4F18\u5148\u4ECE define \u5168\u5C40\u53D8\u91CF\u8BFB\u53D6
|
|
47
47
|
if (typeof ${u} !== 'undefined') return ${u};`),(n==="file"||n==="auto")&&(s+=`
|
|
48
48
|
// \u4ECE\u9875\u9762 meta \u6807\u7B7E\u8BFB\u53D6
|
|
@@ -56,7 +56,7 @@ import{createPluginFactory as d,BasePlugin as p}from"../../factory/index.mjs";im
|
|
|
56
56
|
|
|
57
57
|
// \u5F00\u53D1\u6A21\u5F0F\u68C0\u6D4B
|
|
58
58
|
var _isDev = typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'development';
|
|
59
|
-
if (_isDev && !${JSON.stringify(
|
|
59
|
+
if (_isDev && !${JSON.stringify(a)}) return;
|
|
60
60
|
|
|
61
61
|
// \u72B6\u6001
|
|
62
62
|
var _currentVersion = null;
|
|
@@ -89,7 +89,7 @@ import{createPluginFactory as d,BasePlugin as p}from"../../factory/index.mjs";im
|
|
|
89
89
|
if (_currentVersion === _latestVersion) return;
|
|
90
90
|
|
|
91
91
|
// \u7248\u672C\u4E0D\u4E00\u81F4\uFF0C\u53D1\u73B0\u66F4\u65B0
|
|
92
|
-
var shouldShow = ${_}(_currentVersion, _latestVersion);
|
|
92
|
+
var shouldShow = (${_})(_currentVersion, _latestVersion);
|
|
93
93
|
if (shouldShow !== false) {
|
|
94
94
|
_showPrompt();
|
|
95
95
|
}
|
|
@@ -126,13 +126,13 @@ import{createPluginFactory as d,BasePlugin as p}from"../../factory/index.mjs";im
|
|
|
126
126
|
|
|
127
127
|
// \u5237\u65B0\u9875\u9762
|
|
128
128
|
window.__VUC_REFRESH__ = function() {
|
|
129
|
-
${c}(_currentVersion, _latestVersion);
|
|
129
|
+
(${c})(_currentVersion, _latestVersion);
|
|
130
130
|
window.location.reload();
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
// \u5FFD\u7565\u66F4\u65B0
|
|
134
134
|
window.__VUC_DISMISS__ = function() {
|
|
135
|
-
${l}(_currentVersion, _latestVersion);
|
|
135
|
+
(${l})(_currentVersion, _latestVersion);
|
|
136
136
|
_dismissed = true;
|
|
137
137
|
_hidePrompt();
|
|
138
138
|
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 构造函数参数接口
|
|
3
|
+
*/
|
|
4
|
+
interface LoggerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 插件名称
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* 是否启用日志
|
|
11
|
+
*/
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 插件日志代理接口
|
|
16
|
+
* @description 为每个插件提供独立的日志接口
|
|
17
|
+
*/
|
|
18
|
+
interface PluginLogger {
|
|
19
|
+
/**
|
|
20
|
+
* 输出成功日志
|
|
21
|
+
* @param message 日志消息
|
|
22
|
+
* @param data 附加数据
|
|
23
|
+
*/
|
|
24
|
+
success(message: string, data?: any): void;
|
|
25
|
+
/**
|
|
26
|
+
* 输出信息日志
|
|
27
|
+
* @param message 日志消息
|
|
28
|
+
* @param data 附加数据
|
|
29
|
+
*/
|
|
30
|
+
info(message: string, data?: any): void;
|
|
31
|
+
/**
|
|
32
|
+
* 输出警告日志
|
|
33
|
+
* @param message 日志消息
|
|
34
|
+
* @param data 附加数据
|
|
35
|
+
*/
|
|
36
|
+
warn(message: string, data?: any): void;
|
|
37
|
+
/**
|
|
38
|
+
* 输出错误日志
|
|
39
|
+
* @param message 日志消息
|
|
40
|
+
* @param data 附加数据
|
|
41
|
+
*/
|
|
42
|
+
error(message: string, data?: any): void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type { LoggerOptions as L, PluginLogger as P };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 构造函数参数接口
|
|
3
|
+
*/
|
|
4
|
+
interface LoggerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 插件名称
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* 是否启用日志
|
|
11
|
+
*/
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 插件日志代理接口
|
|
16
|
+
* @description 为每个插件提供独立的日志接口
|
|
17
|
+
*/
|
|
18
|
+
interface PluginLogger {
|
|
19
|
+
/**
|
|
20
|
+
* 输出成功日志
|
|
21
|
+
* @param message 日志消息
|
|
22
|
+
* @param data 附加数据
|
|
23
|
+
*/
|
|
24
|
+
success(message: string, data?: any): void;
|
|
25
|
+
/**
|
|
26
|
+
* 输出信息日志
|
|
27
|
+
* @param message 日志消息
|
|
28
|
+
* @param data 附加数据
|
|
29
|
+
*/
|
|
30
|
+
info(message: string, data?: any): void;
|
|
31
|
+
/**
|
|
32
|
+
* 输出警告日志
|
|
33
|
+
* @param message 日志消息
|
|
34
|
+
* @param data 附加数据
|
|
35
|
+
*/
|
|
36
|
+
warn(message: string, data?: any): void;
|
|
37
|
+
/**
|
|
38
|
+
* 输出错误日志
|
|
39
|
+
* @param message 日志消息
|
|
40
|
+
* @param data 附加数据
|
|
41
|
+
*/
|
|
42
|
+
error(message: string, data?: any): void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type { LoggerOptions as L, PluginLogger as P };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 构造函数参数接口
|
|
3
|
+
*/
|
|
4
|
+
interface LoggerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 插件名称
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* 是否启用日志
|
|
11
|
+
*/
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 插件日志代理接口
|
|
16
|
+
* @description 为每个插件提供独立的日志接口
|
|
17
|
+
*/
|
|
18
|
+
interface PluginLogger {
|
|
19
|
+
/**
|
|
20
|
+
* 输出成功日志
|
|
21
|
+
* @param message 日志消息
|
|
22
|
+
* @param data 附加数据
|
|
23
|
+
*/
|
|
24
|
+
success(message: string, data?: any): void;
|
|
25
|
+
/**
|
|
26
|
+
* 输出信息日志
|
|
27
|
+
* @param message 日志消息
|
|
28
|
+
* @param data 附加数据
|
|
29
|
+
*/
|
|
30
|
+
info(message: string, data?: any): void;
|
|
31
|
+
/**
|
|
32
|
+
* 输出警告日志
|
|
33
|
+
* @param message 日志消息
|
|
34
|
+
* @param data 附加数据
|
|
35
|
+
*/
|
|
36
|
+
warn(message: string, data?: any): void;
|
|
37
|
+
/**
|
|
38
|
+
* 输出错误日志
|
|
39
|
+
* @param message 日志消息
|
|
40
|
+
* @param data 附加数据
|
|
41
|
+
*/
|
|
42
|
+
error(message: string, data?: any): void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type { LoggerOptions as L, PluginLogger as P };
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTML 注入与安全相关类型定义
|
|
3
|
-
*
|
|
4
|
-
* @module common/html/type
|
|
5
|
-
* @description 定义 HTML 注入位置、选择器匹配模式、条件判断、安全配置等核心类型,
|
|
6
|
-
* 为 HTML 注入和安全过滤功能提供统一的类型约束。
|
|
7
|
-
*/
|
|
8
1
|
/**
|
|
9
2
|
* HTML 单点注入结果
|
|
10
3
|
*
|
|
@@ -95,20 +88,6 @@ interface InjectCondition {
|
|
|
95
88
|
/** 是否取反条件结果,默认为 `false` */
|
|
96
89
|
negate?: boolean;
|
|
97
90
|
}
|
|
98
|
-
/**
|
|
99
|
-
* 按位置注入结果
|
|
100
|
-
*
|
|
101
|
-
* @description 表示按指定位置注入内容后的详细结果,
|
|
102
|
-
* 包含注入后的 HTML、是否成功标志和失败原因。
|
|
103
|
-
*/
|
|
104
|
-
interface PositionInjectResult {
|
|
105
|
-
/** 注入后的 HTML 内容 */
|
|
106
|
-
html: string;
|
|
107
|
-
/** 是否成功注入 */
|
|
108
|
-
injected: boolean;
|
|
109
|
-
/** 注入失败时的原因说明(仅在 `injected` 为 `false` 时存在) */
|
|
110
|
-
reason?: string;
|
|
111
|
-
}
|
|
112
91
|
/**
|
|
113
92
|
* HTML 安全配置
|
|
114
93
|
*
|
|
@@ -140,4 +119,4 @@ interface SecurityConfig {
|
|
|
140
119
|
blockedAttributes?: string[];
|
|
141
120
|
}
|
|
142
121
|
|
|
143
|
-
export type { ConditionType as C, DualInjectResult as D, HtmlInjectResult as H, InjectCondition as I,
|
|
122
|
+
export type { ConditionType as C, DualInjectResult as D, HtmlInjectResult as H, InjectCondition as I, SecurityConfig as S, InjectPosition as a, SelectorMatch as b };
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTML 注入与安全相关类型定义
|
|
3
|
-
*
|
|
4
|
-
* @module common/html/type
|
|
5
|
-
* @description 定义 HTML 注入位置、选择器匹配模式、条件判断、安全配置等核心类型,
|
|
6
|
-
* 为 HTML 注入和安全过滤功能提供统一的类型约束。
|
|
7
|
-
*/
|
|
8
1
|
/**
|
|
9
2
|
* HTML 单点注入结果
|
|
10
3
|
*
|
|
@@ -95,20 +88,6 @@ interface InjectCondition {
|
|
|
95
88
|
/** 是否取反条件结果,默认为 `false` */
|
|
96
89
|
negate?: boolean;
|
|
97
90
|
}
|
|
98
|
-
/**
|
|
99
|
-
* 按位置注入结果
|
|
100
|
-
*
|
|
101
|
-
* @description 表示按指定位置注入内容后的详细结果,
|
|
102
|
-
* 包含注入后的 HTML、是否成功标志和失败原因。
|
|
103
|
-
*/
|
|
104
|
-
interface PositionInjectResult {
|
|
105
|
-
/** 注入后的 HTML 内容 */
|
|
106
|
-
html: string;
|
|
107
|
-
/** 是否成功注入 */
|
|
108
|
-
injected: boolean;
|
|
109
|
-
/** 注入失败时的原因说明(仅在 `injected` 为 `false` 时存在) */
|
|
110
|
-
reason?: string;
|
|
111
|
-
}
|
|
112
91
|
/**
|
|
113
92
|
* HTML 安全配置
|
|
114
93
|
*
|
|
@@ -140,4 +119,4 @@ interface SecurityConfig {
|
|
|
140
119
|
blockedAttributes?: string[];
|
|
141
120
|
}
|
|
142
121
|
|
|
143
|
-
export type { ConditionType as C, DualInjectResult as D, HtmlInjectResult as H, InjectCondition as I,
|
|
122
|
+
export type { ConditionType as C, DualInjectResult as D, HtmlInjectResult as H, InjectCondition as I, SecurityConfig as S, InjectPosition as a, SelectorMatch as b };
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTML 注入与安全相关类型定义
|
|
3
|
-
*
|
|
4
|
-
* @module common/html/type
|
|
5
|
-
* @description 定义 HTML 注入位置、选择器匹配模式、条件判断、安全配置等核心类型,
|
|
6
|
-
* 为 HTML 注入和安全过滤功能提供统一的类型约束。
|
|
7
|
-
*/
|
|
8
1
|
/**
|
|
9
2
|
* HTML 单点注入结果
|
|
10
3
|
*
|
|
@@ -95,20 +88,6 @@ interface InjectCondition {
|
|
|
95
88
|
/** 是否取反条件结果,默认为 `false` */
|
|
96
89
|
negate?: boolean;
|
|
97
90
|
}
|
|
98
|
-
/**
|
|
99
|
-
* 按位置注入结果
|
|
100
|
-
*
|
|
101
|
-
* @description 表示按指定位置注入内容后的详细结果,
|
|
102
|
-
* 包含注入后的 HTML、是否成功标志和失败原因。
|
|
103
|
-
*/
|
|
104
|
-
interface PositionInjectResult {
|
|
105
|
-
/** 注入后的 HTML 内容 */
|
|
106
|
-
html: string;
|
|
107
|
-
/** 是否成功注入 */
|
|
108
|
-
injected: boolean;
|
|
109
|
-
/** 注入失败时的原因说明(仅在 `injected` 为 `false` 时存在) */
|
|
110
|
-
reason?: string;
|
|
111
|
-
}
|
|
112
91
|
/**
|
|
113
92
|
* HTML 安全配置
|
|
114
93
|
*
|
|
@@ -140,4 +119,4 @@ interface SecurityConfig {
|
|
|
140
119
|
blockedAttributes?: string[];
|
|
141
120
|
}
|
|
142
121
|
|
|
143
|
-
export type { ConditionType as C, DualInjectResult as D, HtmlInjectResult as H, InjectCondition as I,
|
|
122
|
+
export type { ConditionType as C, DualInjectResult as D, HtmlInjectResult as H, InjectCondition as I, SecurityConfig as S, InjectPosition as a, SelectorMatch as b };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function escapeHtmlAttr(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">")}function w(t){return/<script\b/i.test(t)}const f=["script","iframe","object","embed","applet","form","input","textarea","select","button"],b=["onclick","ondblclick","onmouseover","onmouseout","onmousemove","onmousedown","onmouseup","onkeydown","onkeyup","onkeypress","onload","onerror","onfocus","onblur","onsubmit","onchange","oninput","oncontextmenu","ondrag","ondrop","onanimationend","ontransitionend"];function sanitizeContent(t,n,o,i){const a=o?.blockDangerousTags!==!1,F=o?.blockDangerousAttributes!==!1,c=o?.blockedTags||f,B=o?.allowedTags,E=o?.blockedAttributes||b;let e=t;if(a){const r=B?c.filter(u=>!B.includes(u)):c;if(w(t))if(n.allowScriptInjection)i?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${n.id||"unnamed"}" \u5DF2\u542F\u7528\u811A\u672C\u6CE8\u5165(allowScriptInjection=true)\uFF0C\u8BF7\u786E\u4FDD\u6CE8\u5165\u5185\u5BB9\u6765\u6E90\u53EF\u4FE1\u3002\u6CE8\u5165\u811A\u672C\u53EF\u80FD\u5E26\u6765 XSS \u653B\u51FB\u98CE\u9669\u3002`);else throw new Error(`\u89C4\u5219 "${n.id||"unnamed"}" \u7684\u5185\u5BB9\u5305\u542B <script> \u6807\u7B7E\uFF0C\u9ED8\u8BA4\u88AB\u963B\u6B62\u3002\u5982\u9700\u6CE8\u5165\u811A\u672C\uFF0C\u8BF7\u8BBE\u7F6E allowScriptInjection: true`);for(const u of r){if(u==="script")continue;const s=new RegExp(`<${u}\\b[^>]*>[\\s\\S]*?<\\/${u}>`,"gi"),l=new RegExp(`<${u}\\b[^>]*/?>`,"gi");if(s.test(e)||l.test(e))if(n.allowScriptInjection){i?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${n.id||"unnamed"}" \u5305\u542B\u88AB\u963B\u6B62\u7684\u6807\u7B7E <${u}>\uFF0C\u5DF2\u901A\u8FC7 allowScriptInjection \u8DF3\u8FC7\u5B89\u5168\u68C0\u67E5\uFF0C\u8BF7\u786E\u4FDD\u5185\u5BB9\u53EF\u4FE1\u3002`);continue}else throw new Error(`\u89C4\u5219 "${n.id||"unnamed"}" \u7684\u5185\u5BB9\u5305\u542B\u88AB\u963B\u6B62\u7684\u6807\u7B7E <${u}>\u3002\u5982\u9700\u6CE8\u5165\u6B64\u6807\u7B7E\uFF0C\u8BF7\u8BBE\u7F6E allowScriptInjection: true \u6216\u5728 security.allowedTags \u4E2D\u6DFB\u52A0 "${u}"`);e=e.replace(s,""),e=e.replace(l,"")}}if(F)for(const r of E){const u=new RegExp(`\\s${r}\\s*=\\s*["'][^"']*["']`,"gi");if(u.test(e))if(n.allowScriptInjection){i?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${n.id||"unnamed"}" \u5305\u542B\u5371\u9669\u5C5E\u6027 ${r}\uFF0C\u5DF2\u901A\u8FC7 allowScriptInjection \u8DF3\u8FC7\u5B89\u5168\u68C0\u67E5\uFF0C\u8BF7\u786E\u4FDD\u5185\u5BB9\u53EF\u4FE1\u3002`);continue}else throw new Error(`\u89C4\u5219 "${n.id||"unnamed"}" \u7684\u5185\u5BB9\u5305\u542B\u5371\u9669\u5C5E\u6027 ${r}\u3002\u5982\u9700\u6CE8\u5165\u6B64\u5C5E\u6027\uFF0C\u8BF7\u8BBE\u7F6E allowScriptInjection: true`);e=e.replace(u,"")}return e}exports.escapeHtmlAttr=escapeHtmlAttr,exports.sanitizeContent=sanitizeContent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function p(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">")}function C(t){return/<script\b/i.test(t)}const d=["script","iframe","object","embed","applet","form","input","textarea","select","button"],w=["onclick","ondblclick","onmouseover","onmouseout","onmousemove","onmousedown","onmouseup","onkeydown","onkeyup","onkeypress","onload","onerror","onfocus","onblur","onsubmit","onchange","oninput","oncontextmenu","ondrag","ondrop","onanimationend","ontransitionend"];function f(t,n,o,i){const s=o?.blockDangerousTags!==!1,F=o?.blockDangerousAttributes!==!1,c=o?.blockedTags||d,B=o?.allowedTags,E=o?.blockedAttributes||w;let e=t;if(s){const r=B?c.filter(u=>!B.includes(u)):c;if(C(t))if(n.allowScriptInjection)i?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${n.id||"unnamed"}" \u5DF2\u542F\u7528\u811A\u672C\u6CE8\u5165(allowScriptInjection=true)\uFF0C\u8BF7\u786E\u4FDD\u6CE8\u5165\u5185\u5BB9\u6765\u6E90\u53EF\u4FE1\u3002\u6CE8\u5165\u811A\u672C\u53EF\u80FD\u5E26\u6765 XSS \u653B\u51FB\u98CE\u9669\u3002`);else throw new Error(`\u89C4\u5219 "${n.id||"unnamed"}" \u7684\u5185\u5BB9\u5305\u542B <script> \u6807\u7B7E\uFF0C\u9ED8\u8BA4\u88AB\u963B\u6B62\u3002\u5982\u9700\u6CE8\u5165\u811A\u672C\uFF0C\u8BF7\u8BBE\u7F6E allowScriptInjection: true`);for(const u of r){if(u==="script")continue;const a=new RegExp(`<${u}\\b[^>]*>[\\s\\S]*?<\\/${u}>`,"gi"),l=new RegExp(`<${u}\\b[^>]*/?>`,"gi");if(a.test(e)||l.test(e))if(n.allowScriptInjection){i?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${n.id||"unnamed"}" \u5305\u542B\u88AB\u963B\u6B62\u7684\u6807\u7B7E <${u}>\uFF0C\u5DF2\u901A\u8FC7 allowScriptInjection \u8DF3\u8FC7\u5B89\u5168\u68C0\u67E5\uFF0C\u8BF7\u786E\u4FDD\u5185\u5BB9\u53EF\u4FE1\u3002`);continue}else throw new Error(`\u89C4\u5219 "${n.id||"unnamed"}" \u7684\u5185\u5BB9\u5305\u542B\u88AB\u963B\u6B62\u7684\u6807\u7B7E <${u}>\u3002\u5982\u9700\u6CE8\u5165\u6B64\u6807\u7B7E\uFF0C\u8BF7\u8BBE\u7F6E allowScriptInjection: true \u6216\u5728 security.allowedTags \u4E2D\u6DFB\u52A0 "${u}"`);e=e.replace(a,""),e=e.replace(l,"")}}if(F)for(const r of E){const u=new RegExp(`\\s${r}\\s*=\\s*["'][^"']*["']`,"gi");if(u.test(e))if(n.allowScriptInjection){i?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${n.id||"unnamed"}" \u5305\u542B\u5371\u9669\u5C5E\u6027 ${r}\uFF0C\u5DF2\u901A\u8FC7 allowScriptInjection \u8DF3\u8FC7\u5B89\u5168\u68C0\u67E5\uFF0C\u8BF7\u786E\u4FDD\u5185\u5BB9\u53EF\u4FE1\u3002`);continue}else throw new Error(`\u89C4\u5219 "${n.id||"unnamed"}" \u7684\u5185\u5BB9\u5305\u542B\u5371\u9669\u5C5E\u6027 ${r}\u3002\u5982\u9700\u6CE8\u5165\u6B64\u5C5E\u6027\uFF0C\u8BF7\u8BBE\u7F6E allowScriptInjection: true`);e=e.replace(u,"")}return e}export{p as e,f as s};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meng-xi/vite-plugin",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.6",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "一个为 Vite 提供实用插件的工具包,同时也是一个完整的插件开发框架",
|
|
7
7
|
"keywords": [
|
|
@@ -25,11 +25,6 @@
|
|
|
25
25
|
"import": "./dist/common/index.mjs",
|
|
26
26
|
"types": "./dist/common/index.d.ts"
|
|
27
27
|
},
|
|
28
|
-
"./common/compress": {
|
|
29
|
-
"require": "./dist/common/compress/index.cjs",
|
|
30
|
-
"import": "./dist/common/compress/index.mjs",
|
|
31
|
-
"types": "./dist/common/compress/index.d.ts"
|
|
32
|
-
},
|
|
33
28
|
"./common/format": {
|
|
34
29
|
"require": "./dist/common/format/index.cjs",
|
|
35
30
|
"import": "./dist/common/format/index.mjs",
|
|
@@ -45,16 +40,6 @@
|
|
|
45
40
|
"import": "./dist/common/html/index.mjs",
|
|
46
41
|
"types": "./dist/common/html/index.d.ts"
|
|
47
42
|
},
|
|
48
|
-
"./common/object": {
|
|
49
|
-
"require": "./dist/common/object/index.cjs",
|
|
50
|
-
"import": "./dist/common/object/index.mjs",
|
|
51
|
-
"types": "./dist/common/object/index.d.ts"
|
|
52
|
-
},
|
|
53
|
-
"./common/path": {
|
|
54
|
-
"require": "./dist/common/path/index.cjs",
|
|
55
|
-
"import": "./dist/common/path/index.mjs",
|
|
56
|
-
"types": "./dist/common/path/index.d.ts"
|
|
57
|
-
},
|
|
58
43
|
"./common/script": {
|
|
59
44
|
"require": "./dist/common/script/index.cjs",
|
|
60
45
|
"import": "./dist/common/script/index.mjs",
|
|
@@ -85,6 +70,11 @@
|
|
|
85
70
|
"import": "./dist/plugins/index.mjs",
|
|
86
71
|
"types": "./dist/plugins/index.d.ts"
|
|
87
72
|
},
|
|
73
|
+
"./plugins/auto-import": {
|
|
74
|
+
"require": "./dist/plugins/autoImport/index.cjs",
|
|
75
|
+
"import": "./dist/plugins/autoImport/index.mjs",
|
|
76
|
+
"types": "./dist/plugins/autoImport/index.d.ts"
|
|
77
|
+
},
|
|
88
78
|
"./plugins/build-progress": {
|
|
89
79
|
"require": "./dist/plugins/buildProgress/index.cjs",
|
|
90
80
|
"import": "./dist/plugins/buildProgress/index.mjs",
|
|
@@ -152,7 +142,7 @@
|
|
|
152
142
|
"generate-exports": "tsx scripts/generate-exports.ts"
|
|
153
143
|
},
|
|
154
144
|
"peerDependencies": {
|
|
155
|
-
"vite": "
|
|
145
|
+
"vite": ">=5.0.0 <8.0.0"
|
|
156
146
|
},
|
|
157
147
|
"devDependencies": {
|
|
158
148
|
"@types/node": "^22.0.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const node_zlib=require("node:zlib"),promises=require("node:stream/promises"),node_stream=require("node:stream");async function calculateGzipSize(e){const t=typeof e=="string"?Buffer.from(e,"utf-8"):e,r=[],n=node_zlib.createGzip({level:9}),o=new node_stream.Transform({transform(s,a,i){r.push(s),i()}});return await promises.pipeline(node_stream.Readable.from(t),n,o),Buffer.concat(r).length}exports.calculateGzipSize=calculateGzipSize;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 计算给定数据的 gzip 压缩后大小
|
|
3
|
-
*
|
|
4
|
-
* @async
|
|
5
|
-
* @param {Buffer | string} data - 待计算的数据
|
|
6
|
-
* @returns {Promise<number>} gzip 压缩后的字节大小
|
|
7
|
-
*
|
|
8
|
-
* @description 将数据通过 gzip 流压缩后计算压缩体积,
|
|
9
|
-
* 用于估算网络传输时的实际体积。
|
|
10
|
-
* 使用最高压缩级别(level: 9)以获得最小的压缩体积。
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const gzipSize = await calculateGzipSize(Buffer.from('hello world'))
|
|
15
|
-
* console.log(`gzip 大小: ${gzipSize} 字节`)
|
|
16
|
-
*
|
|
17
|
-
* const stringData = 'some long string content...'
|
|
18
|
-
* const size = await calculateGzipSize(stringData)
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
declare function calculateGzipSize(data: Buffer | string): Promise<number>;
|
|
22
|
-
|
|
23
|
-
export { calculateGzipSize };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 计算给定数据的 gzip 压缩后大小
|
|
3
|
-
*
|
|
4
|
-
* @async
|
|
5
|
-
* @param {Buffer | string} data - 待计算的数据
|
|
6
|
-
* @returns {Promise<number>} gzip 压缩后的字节大小
|
|
7
|
-
*
|
|
8
|
-
* @description 将数据通过 gzip 流压缩后计算压缩体积,
|
|
9
|
-
* 用于估算网络传输时的实际体积。
|
|
10
|
-
* 使用最高压缩级别(level: 9)以获得最小的压缩体积。
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const gzipSize = await calculateGzipSize(Buffer.from('hello world'))
|
|
15
|
-
* console.log(`gzip 大小: ${gzipSize} 字节`)
|
|
16
|
-
*
|
|
17
|
-
* const stringData = 'some long string content...'
|
|
18
|
-
* const size = await calculateGzipSize(stringData)
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
declare function calculateGzipSize(data: Buffer | string): Promise<number>;
|
|
22
|
-
|
|
23
|
-
export { calculateGzipSize };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 计算给定数据的 gzip 压缩后大小
|
|
3
|
-
*
|
|
4
|
-
* @async
|
|
5
|
-
* @param {Buffer | string} data - 待计算的数据
|
|
6
|
-
* @returns {Promise<number>} gzip 压缩后的字节大小
|
|
7
|
-
*
|
|
8
|
-
* @description 将数据通过 gzip 流压缩后计算压缩体积,
|
|
9
|
-
* 用于估算网络传输时的实际体积。
|
|
10
|
-
* 使用最高压缩级别(level: 9)以获得最小的压缩体积。
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const gzipSize = await calculateGzipSize(Buffer.from('hello world'))
|
|
15
|
-
* console.log(`gzip 大小: ${gzipSize} 字节`)
|
|
16
|
-
*
|
|
17
|
-
* const stringData = 'some long string content...'
|
|
18
|
-
* const size = await calculateGzipSize(stringData)
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
declare function calculateGzipSize(data: Buffer | string): Promise<number>;
|
|
22
|
-
|
|
23
|
-
export { calculateGzipSize };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createGzip as i}from"node:zlib";import{pipeline as p}from"node:stream/promises";import{Transform as m,Readable as c}from"node:stream";async function l(e){const o=typeof e=="string"?Buffer.from(e,"utf-8"):e,r=[],t=i({level:9}),f=new m({transform(n,u,a){r.push(n),a()}});return await p(c.from(o),t,f),Buffer.concat(r).length}export{l as calculateGzipSize};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";function i(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.prototype.toString.call(e)==="[object Object]"}function deepMerge(...e){const t={};for(const r of e)if(r)for(const o in r){if(!Object.prototype.hasOwnProperty.call(r,o))continue;const n=r[o],c=t[o];n!==void 0&&(i(n)&&i(c)?t[o]=deepMerge(c,n):t[o]=n)}return t}exports.deepMerge=deepMerge;
|