@meng-xi/vite-plugin 0.1.5 → 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.
Files changed (57) hide show
  1. package/README-en.md +29 -15
  2. package/README.md +29 -15
  3. package/dist/common/format/index.cjs +1 -1
  4. package/dist/common/format/index.d.cts +35 -1
  5. package/dist/common/format/index.d.mts +35 -1
  6. package/dist/common/format/index.d.ts +35 -1
  7. package/dist/common/format/index.mjs +1 -1
  8. package/dist/common/fs/index.cjs +1 -1
  9. package/dist/common/fs/index.d.cts +36 -1
  10. package/dist/common/fs/index.d.mts +36 -1
  11. package/dist/common/fs/index.d.ts +36 -1
  12. package/dist/common/fs/index.mjs +1 -1
  13. package/dist/common/html/index.cjs +2 -2
  14. package/dist/common/html/index.d.cts +17 -1
  15. package/dist/common/html/index.d.mts +17 -1
  16. package/dist/common/html/index.d.ts +17 -1
  17. package/dist/common/html/index.mjs +2 -2
  18. package/dist/common/index.cjs +1 -1
  19. package/dist/common/index.d.cts +3 -3
  20. package/dist/common/index.d.mts +3 -3
  21. package/dist/common/index.d.ts +3 -3
  22. package/dist/common/index.mjs +1 -1
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.d.cts +3 -3
  25. package/dist/index.d.mts +3 -3
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.mjs +1 -1
  28. package/dist/plugins/autoImport/index.cjs +7 -5
  29. package/dist/plugins/autoImport/index.mjs +9 -7
  30. package/dist/plugins/buildProgress/index.cjs +2 -2
  31. package/dist/plugins/bundleAnalyzer/index.cjs +21 -21
  32. package/dist/plugins/compressAssets/index.cjs +1 -1
  33. package/dist/plugins/compressAssets/index.mjs +1 -1
  34. package/dist/plugins/envGuard/index.cjs +9 -9
  35. package/dist/plugins/envGuard/index.mjs +7 -7
  36. package/dist/plugins/faviconManager/index.cjs +1 -1
  37. package/dist/plugins/faviconManager/index.mjs +1 -1
  38. package/dist/plugins/generateRouter/index.cjs +5 -4
  39. package/dist/plugins/generateRouter/index.d.cts +33 -0
  40. package/dist/plugins/generateRouter/index.d.mts +33 -0
  41. package/dist/plugins/generateRouter/index.d.ts +33 -0
  42. package/dist/plugins/generateRouter/index.mjs +3 -2
  43. package/dist/plugins/generateVersion/index.cjs +1 -1
  44. package/dist/plugins/generateVersion/index.mjs +1 -1
  45. package/dist/plugins/htmlInject/index.cjs +7 -7
  46. package/dist/plugins/htmlInject/index.mjs +2 -2
  47. package/dist/plugins/index.cjs +1 -1
  48. package/dist/plugins/index.mjs +1 -1
  49. package/dist/plugins/loadingManager/index.cjs +5 -5
  50. package/dist/plugins/loadingManager/index.mjs +4 -4
  51. package/dist/plugins/versionUpdateChecker/index.cjs +4 -4
  52. package/dist/plugins/versionUpdateChecker/index.mjs +4 -4
  53. package/dist/shared/vite-plugin.CcvHfrL8.cjs +1 -0
  54. package/dist/shared/vite-plugin.CuXEJAWX.mjs +1 -0
  55. package/package.json +2 -2
  56. package/dist/shared/vite-plugin.BPFqtmWa.mjs +0 -1
  57. package/dist/shared/vite-plugin.CnOy46d3.cjs +0 -1
@@ -1 +1 @@
1
- import{createPluginFactory as r,BasePlugin as a}from"../../factory/index.mjs";import{getDateFormatParams as u}from"../../common/format/index.mjs";import{writeFileContent as m}from"../../common/fs/index.mjs";import{join as h}from"path";import{randomBytes as p}from"crypto";import"../../logger/index.mjs";import"../../shared/vite-plugin.DcExl6jd.mjs";import"fs";function f(o=8){const t=Math.max(1,Math.min(64,o));return p(Math.ceil(t/2)).toString("hex").slice(0,t)}function l(o,t){let e=o;for(const[i,s]of Object.entries(t))e=e.replace(new RegExp(`\\{${i}\\}`,"g"),s);return e}class c extends a{version="";buildTime=new Date;getDefaultOptions(){return{format:"timestamp",semverBase:"1.0.0",outputType:"file",outputFile:"version.json",defineName:"__APP_VERSION__",hashLength:8,prefix:"",suffix:""}}validateOptions(){if(this.validator.field("format").enum(["timestamp","date","datetime","semver","hash","custom"]).field("outputType").enum(["file","define","both"]).field("hashLength").number().minValue(1).maxValue(32).validate(),this.options.format==="custom"&&!this.options.customFormat)throw new Error("\u5F53 format \u4E3A custom \u65F6\uFF0C\u5FC5\u987B\u63D0\u4F9B customFormat")}getPluginName(){return"generate-version"}generateVersion(){const t=u(this.buildTime),e=f(this.options.hashLength);let i;switch(this.options.format){case"timestamp":i=`${t.YYYY}${t.MM}${t.DD}${t.HH}${t.mm}${t.ss}`;break;case"date":i=`${t.YYYY}.${t.MM}.${t.DD}`;break;case"datetime":i=`${t.YYYY}.${t.MM}.${t.DD}.${t.HH}${t.mm}${t.ss}`;break;case"semver":i=this.options.semverBase||"1.0.0";break;case"hash":i=e;break;case"custom":i=this.parseCustomFormat({...t,hash:e});break;default:i=t.timestamp}const s=this.options.prefix||"",n=this.options.suffix||"";return`${s}${i}${n}`}parseCustomFormat(t){const e={...t};if(this.options.semverBase){const[i,s,n]=this.options.semverBase.split(".");e.major=i||"1",e.minor=s||"0",e.patch=n||"0"}return l(this.options.customFormat||"",e)}generateVersionInfo(){return{version:this.version,buildTime:this.buildTime.toISOString(),timestamp:this.buildTime.getTime(),format:this.options.format,...this.options.extra}}async writeVersionFile(t){const e=h(t,this.options.outputFile||"version.json"),i=this.generateVersionInfo();await m(e,JSON.stringify(i,null,2)),this.logger.success(`\u7248\u672C\u6587\u4EF6\u5DF2\u751F\u6210: ${e}`)}addPluginHooks(t){t.configResolved=()=>{this.buildTime=new Date,this.version=this.generateVersion(),this.logger.info(`\u751F\u6210\u7248\u672C\u53F7: ${this.version}`)},(this.options.outputType==="define"||this.options.outputType==="both")&&(t.config=()=>{this.version||(this.buildTime=new Date,this.version=this.generateVersion());const e=this.options.defineName||"__APP_VERSION__";return this.logger.info(`\u6CE8\u5165\u5168\u5C40\u53D8\u91CF: ${e} = "${this.version}"`),{define:{[e]:JSON.stringify(this.version),[`${e}_INFO`]:JSON.stringify(this.generateVersionInfo())}}}),(this.options.outputType==="file"||this.options.outputType==="both")&&(t.writeBundle=async()=>{this.viteConfig&&await this.safeExecute(async()=>{const e=this.viteConfig.build.outDir;await this.writeVersionFile(e)},"\u5199\u5165\u7248\u672C\u6587\u4EF6")})}}const g=r(c);export{g as generateVersion};
1
+ import{createPluginFactory as r,BasePlugin as a}from"../../factory/index.mjs";import{randomBytes as u}from"crypto";import{getDateFormatParams as m}from"../../common/format/index.mjs";import{writeFileContent as h}from"../../common/fs/index.mjs";import{join as p}from"path";import"../../logger/index.mjs";import"../../shared/vite-plugin.DcExl6jd.mjs";import"fs";function f(o=8){const t=Math.max(1,Math.min(64,o));return u(Math.ceil(t/2)).toString("hex").slice(0,t)}function l(o,t){let e=o;for(const[i,s]of Object.entries(t))e=e.replace(new RegExp(`\\{${i}\\}`,"g"),s);return e}class c extends a{version="";buildTime=new Date;getDefaultOptions(){return{format:"timestamp",semverBase:"1.0.0",outputType:"file",outputFile:"version.json",defineName:"__APP_VERSION__",hashLength:8,prefix:"",suffix:""}}validateOptions(){if(this.validator.field("format").enum(["timestamp","date","datetime","semver","hash","custom"]).field("outputType").enum(["file","define","both"]).field("hashLength").number().minValue(1).maxValue(32).validate(),this.options.format==="custom"&&!this.options.customFormat)throw new Error("\u5F53 format \u4E3A custom \u65F6\uFF0C\u5FC5\u987B\u63D0\u4F9B customFormat")}getPluginName(){return"generate-version"}generateVersion(){const t=m(this.buildTime),e=f(this.options.hashLength);let i;switch(this.options.format){case"timestamp":i=`${t.YYYY}${t.MM}${t.DD}${t.HH}${t.mm}${t.ss}`;break;case"date":i=`${t.YYYY}.${t.MM}.${t.DD}`;break;case"datetime":i=`${t.YYYY}.${t.MM}.${t.DD}.${t.HH}${t.mm}${t.ss}`;break;case"semver":i=this.options.semverBase||"1.0.0";break;case"hash":i=e;break;case"custom":i=this.parseCustomFormat({...t,hash:e});break;default:i=t.timestamp}const s=this.options.prefix||"",n=this.options.suffix||"";return`${s}${i}${n}`}parseCustomFormat(t){const e={...t};if(this.options.semverBase){const[i,s,n]=this.options.semverBase.split(".");e.major=i||"1",e.minor=s||"0",e.patch=n||"0"}return l(this.options.customFormat||"",e)}generateVersionInfo(){return{version:this.version,buildTime:this.buildTime.toISOString(),timestamp:this.buildTime.getTime(),format:this.options.format,...this.options.extra}}async writeVersionFile(t){const e=p(t,this.options.outputFile||"version.json"),i=this.generateVersionInfo();await h(e,JSON.stringify(i,null,2)),this.logger.success(`\u7248\u672C\u6587\u4EF6\u5DF2\u751F\u6210: ${e}`)}addPluginHooks(t){t.configResolved=()=>{this.buildTime=new Date,this.version=this.generateVersion(),this.logger.info(`\u751F\u6210\u7248\u672C\u53F7: ${this.version}`)},(this.options.outputType==="define"||this.options.outputType==="both")&&(t.config=()=>{this.version||(this.buildTime=new Date,this.version=this.generateVersion());const e=this.options.defineName||"__APP_VERSION__";return this.logger.info(`\u6CE8\u5165\u5168\u5C40\u53D8\u91CF: ${e} = "${this.version}"`),{define:{[e]:JSON.stringify(this.version),[`${e}_INFO`]:JSON.stringify(this.generateVersionInfo())}}}),(this.options.outputType==="file"||this.options.outputType==="both")&&(t.writeBundle=async()=>{this.viteConfig&&await this.safeExecute(async()=>{const e=this.viteConfig.build.outDir;await this.writeVersionFile(e)},"\u5199\u5165\u7248\u672C\u6587\u4EF6")})}}const g=r(c);export{g as generateVersion};
@@ -1,7 +1,7 @@
1
- "use strict";const factory_index=require("../../factory/index.cjs"),security=require("../../shared/vite-plugin.CnOy46d3.cjs"),i=require("node:path");require("../../logger/index.cjs"),require("../../shared/vite-plugin.Bcg6RW2N.cjs");function _interopDefaultCompat(t){return t&&typeof t=="object"&&"default"in t?t.default:t}const i__default=_interopDefaultCompat(i);function e(t){if(t){if(t.blockedTags&&!Array.isArray(t.blockedTags))throw new Error("security.blockedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(t.allowedTags&&!Array.isArray(t.allowedTags))throw new Error("security.allowedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(t.blockedAttributes&&!Array.isArray(t.blockedAttributes))throw new Error("security.blockedAttributes \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4")}}function validateRules(t){if(!t.rules||!Array.isArray(t.rules))throw new Error("rules \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4");if(t.rules.length===0)throw new Error("rules \u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");for(let n=0;n<t.rules.length;n++)s(t.rules[n],n)}function s(t,n){if(!t.content||typeof t.content!="string")throw new Error(`rules[${n}].content \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`);if(!t.position||typeof t.position!="string")throw new Error(`rules[${n}].position \u5FC5\u987B\u662F\u6709\u6548\u7684\u6CE8\u5165\u4F4D\u7F6E`);const o=["head-start","head-end","body-start","body-end","before-selector","after-selector","replace-selector"];if(!o.includes(t.position))throw new Error(`rules[${n}].position \u5FC5\u987B\u662F ${o.join(", ")} \u4E4B\u4E00`);if(t.position.includes("selector")&&!t.selector)throw new Error(`rules[${n}].position \u4E3A "${t.position}" \u65F6\uFF0Cselector \u4E3A\u5FC5\u586B\u9879`);if(t.priority!==void 0&&(typeof t.priority!="number"||t.priority<0))throw new Error(`rules[${n}].priority \u5FC5\u987B\u662F\u975E\u8D1F\u6570`);t.condition&&l(t.condition,n)}function l(t,n){if(!t)return;const o=["env","file-contains","custom"];if(!o.includes(t.type))throw new Error(`rules[${n}].condition.type \u5FC5\u987B\u662F ${o.join(", ")} \u4E4B\u4E00`);if(t.type==="custom"&&typeof t.value!="function")throw new Error(`rules[${n}].condition.type \u4E3A "custom" \u65F6\uFF0Cvalue \u5FC5\u987B\u662F\u51FD\u6570`);if(t.type!=="custom"&&typeof t.value!="string")throw new Error(`rules[${n}].condition.type \u4E3A "${t.type}" \u65F6\uFF0Cvalue \u5FC5\u987B\u662F\u5B57\u7B26\u4E32`)}function validateAll(t){validateRules(t),e(t.security)}function g(t,n,o){if(o==="regex"){try{const d=new RegExp(n),r=t.match(d);if(r&&r.index!==void 0)return{index:r.index,length:r[0].length}}catch{return null}return null}const c=t.indexOf(n);return c===-1?null:{index:c,length:n.length}}function p(t,n,o){let c=t;const d={...o,...n};for(const[r,a]of Object.entries(d)){const F=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),f=a.replace(/\$/g,"$$$$");c=c.replace(new RegExp(`\\{\\{${F}\\}\\}`,"g"),f)}return c}function y(t,n){let o=!1;switch(t.type){case"env":{const c=t.value,d=process.env[c];o=!!d&&d!=="false"&&d!=="0";break}case"file-contains":{const c=t.value;o=n.includes(c);break}case"custom":{const c=t.value;try{o=!!c()}catch{o=!1}break}}return t.negate?!o:o}function x(t){return[...t].sort((n,o)=>(n.priority??100)-(o.priority??100))}function h(t,n,o,c,d){switch(o){case"head-start":{const r=t.match(/<head\b[^>]*>/i);if(!r)return{html:t,injected:!1,reason:"\u672A\u627E\u5230 <head> \u6807\u7B7E"};const a=(r.index??0)+r[0].length;return{html:t.slice(0,a)+`
2
- `+n+t.slice(a),injected:!0}}case"head-end":{const r=t.match(/<\/head\s*>/i);if(!r)return{html:t,injected:!1,reason:"\u672A\u627E\u5230 </head> \u6807\u7B7E"};const a=r.index;return{html:t.slice(0,a)+n+`
3
- `+t.slice(a),injected:!0}}case"body-start":{const r=t.match(/<body\b[^>]*>/i);if(!r)return{html:t,injected:!1,reason:"\u672A\u627E\u5230 <body> \u6807\u7B7E"};const a=(r.index??0)+r[0].length;return{html:t.slice(0,a)+`
4
- `+n+t.slice(a),injected:!0}}case"body-end":{const r=t.match(/<\/body\s*>/i);if(!r)return{html:t,injected:!1,reason:"\u672A\u627E\u5230 </body> \u6807\u7B7E"};const a=r.index;return{html:t.slice(0,a)+n+`
5
- `+t.slice(a),injected:!0}}case"before-selector":{if(!c)return{html:t,injected:!1,reason:"before-selector \u9700\u8981 selector \u53C2\u6570"};const r=g(t,c,d);return r?{html:t.slice(0,r.index)+n+`
6
- `+t.slice(r.index),injected:!0}:{html:t,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${c}"`}}case"after-selector":{if(!c)return{html:t,injected:!1,reason:"after-selector \u9700\u8981 selector \u53C2\u6570"};const r=g(t,c,d);if(!r)return{html:t,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${c}"`};const a=r.index+r.length;return{html:t.slice(0,a)+`
7
- `+n+t.slice(a),injected:!0}}case"replace-selector":{if(!c)return{html:t,injected:!1,reason:"replace-selector \u9700\u8981 selector \u53C2\u6570"};const r=g(t,c,d);if(!r)return{html:t,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${c}"`};const a=r.index+r.length;return{html:t.slice(0,r.index)+n+t.slice(a),injected:!0}}default:return{html:t,injected:!1,reason:`\u4E0D\u652F\u6301\u7684\u6CE8\u5165\u4F4D\u7F6E: ${o}`}}}function processRules(t,n,o,c,d){let r=t;const a=[],F=x(n);for(const f of F){const E={ruleId:f.id||"unnamed",position:f.position,selector:f.selector,injected:!1,timestamp:Date.now()};if(f.condition&&!y(f.condition,r)){E.injected=!1,E.reason="\u6761\u4EF6\u4E0D\u6EE1\u8DB3\uFF0C\u8DF3\u8FC7\u6CE8\u5165",a.push(E);continue}let m=p(f.content,f.templateVars,o);try{m=security.sanitizeContent(m,f,c,d)}catch(C){E.injected=!1,E.reason=C.message,a.push(E),d?.warn(`\u89C4\u5219 "${f.id||"unnamed"}" \u5B89\u5168\u68C0\u67E5\u5931\u8D25: ${C.message}`);continue}const j=h(r,m,f.position,f.selector,f.selectorMatch);r=j.html,E.injected=j.injected,E.reason=j.reason,a.push(E)}return{html:r,logs:a}}class u extends factory_index.BasePlugin{injectionLogs=[];getDefaultOptions(){return{targetFile:"index.html",logInjection:!0,security:{blockDangerousTags:!0,blockDangerousAttributes:!0}}}validateOptions(){this.validator.field("targetFile").string().field("rules").required().field("logInjection").boolean().validate(),validateAll(this.options)}getPluginName(){return"html-inject"}isTargetFile(n,o){if(o==="index.html")return n.endsWith("index.html")||n.endsWith("index.htm");const c=o.replace(/\\/g,"/"),d=n.replace(/\\/g,"/");return d.endsWith(c)?!0:i__default.basename(d)===i__default.basename(c)}addPluginHooks(n){n.transformIndexHtml={order:"post",handler:(o,c)=>{const d=c.filename||"",r=this.options.targetFile||"index.html";if(!this.isTargetFile(d,r))return o;const a={warn:f=>this.logger.warn(f)},F=processRules(o,this.options.rules,this.options.templateVars,this.options.security,a);return this.injectionLogs=F.logs,this.options.logInjection&&this.logInjectionResults(F.logs),F.html}},n.buildEnd=()=>{this.options.logInjection&&this.injectionLogs.length>0&&this.logger.info(`\u6CE8\u5165\u5B8C\u6210\uFF0C\u5171\u5904\u7406 ${this.injectionLogs.length} \u6761\u89C4\u5219`)}}logInjectionResults(n){for(const o of n)o.injected?this.logger.success(`\u89C4\u5219 "${o.ruleId}" \u6CE8\u5165\u6210\u529F (\u4F4D\u7F6E: ${o.position}${o.selector?`, \u9009\u62E9\u5668: ${o.selector}`:""})`):this.logger.warn(`\u89C4\u5219 "${o.ruleId}" \u6CE8\u5165\u5931\u8D25: ${o.reason||"\u672A\u77E5\u539F\u56E0"}`)}getInjectionLogs(){return[...this.injectionLogs]}}const htmlInject=factory_index.createPluginFactory(u);exports.htmlInject=htmlInject;
1
+ "use strict";const factory_index=require("../../factory/index.cjs"),security=require("../../shared/vite-plugin.CcvHfrL8.cjs"),common_format_index=require("../../common/format/index.cjs"),l$1=require("node:path");require("../../logger/index.cjs"),require("../../shared/vite-plugin.Bcg6RW2N.cjs");function _interopDefaultCompat(t){return t&&typeof t=="object"&&"default"in t?t.default:t}const l__default=_interopDefaultCompat(l$1);function e(t){if(t){if(t.blockedTags&&!Array.isArray(t.blockedTags))throw new Error("security.blockedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(t.allowedTags&&!Array.isArray(t.allowedTags))throw new Error("security.allowedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(t.blockedAttributes&&!Array.isArray(t.blockedAttributes))throw new Error("security.blockedAttributes \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4")}}function validateRules(t){if(!t.rules||!Array.isArray(t.rules))throw new Error("rules \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4");if(t.rules.length===0)throw new Error("rules \u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");for(let n=0;n<t.rules.length;n++)s(t.rules[n],n)}function s(t,n){if(!t.content||typeof t.content!="string")throw new Error(`rules[${n}].content \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`);if(!t.position||typeof t.position!="string")throw new Error(`rules[${n}].position \u5FC5\u987B\u662F\u6709\u6548\u7684\u6CE8\u5165\u4F4D\u7F6E`);const o=["head-start","head-end","body-start","body-end","before-selector","after-selector","replace-selector"];if(!o.includes(t.position))throw new Error(`rules[${n}].position \u5FC5\u987B\u662F ${o.join(", ")} \u4E4B\u4E00`);if(t.position.includes("selector")&&!t.selector)throw new Error(`rules[${n}].position \u4E3A "${t.position}" \u65F6\uFF0Cselector \u4E3A\u5FC5\u586B\u9879`);if(t.priority!==void 0&&(typeof t.priority!="number"||t.priority<0))throw new Error(`rules[${n}].priority \u5FC5\u987B\u662F\u975E\u8D1F\u6570`);t.condition&&l(t.condition,n)}function l(t,n){if(!t)return;const o=["env","file-contains","custom"];if(!o.includes(t.type))throw new Error(`rules[${n}].condition.type \u5FC5\u987B\u662F ${o.join(", ")} \u4E4B\u4E00`);if(t.type==="custom"&&typeof t.value!="function")throw new Error(`rules[${n}].condition.type \u4E3A "custom" \u65F6\uFF0Cvalue \u5FC5\u987B\u662F\u51FD\u6570`);if(t.type!=="custom"&&typeof t.value!="string")throw new Error(`rules[${n}].condition.type \u4E3A "${t.type}" \u65F6\uFF0Cvalue \u5FC5\u987B\u662F\u5B57\u7B26\u4E32`)}function validateAll(t){validateRules(t),e(t.security)}function f(t,n,o){if(o==="regex"){try{const a=new RegExp(n),r=t.match(a);if(r&&r.index!==void 0)return{index:r.index,length:r[0].length}}catch{return null}return null}const i=t.indexOf(n);return i===-1?null:{index:i,length:n.length}}function p(t,n,o){const i={...o,...n};return common_format_index.parseTemplate(t,i)}function x(t,n){let o=!1;switch(t.type){case"env":{const i=t.value,a=process.env[i];o=!!a&&a!=="false"&&a!=="0";break}case"file-contains":{const i=t.value;o=n.includes(i);break}case"custom":{const i=t.value;try{o=!!i()}catch{o=!1}break}}return t.negate?!o:o}function h(t){return[...t].sort((n,o)=>(n.priority??100)-(o.priority??100))}function b(t,n,o,i,a){switch(o){case"head-start":{const r=t.match(/<head\b[^>]*>/i);if(!r)return{html:t,injected:!1,reason:"\u672A\u627E\u5230 <head> \u6807\u7B7E"};const c=(r.index??0)+r[0].length;return{html:t.slice(0,c)+`
2
+ `+n+t.slice(c),injected:!0}}case"head-end":{const r=t.match(/<\/head\s*>/i);if(!r)return{html:t,injected:!1,reason:"\u672A\u627E\u5230 </head> \u6807\u7B7E"};const c=r.index;return{html:t.slice(0,c)+n+`
3
+ `+t.slice(c),injected:!0}}case"body-start":{const r=t.match(/<body\b[^>]*>/i);if(!r)return{html:t,injected:!1,reason:"\u672A\u627E\u5230 <body> \u6807\u7B7E"};const c=(r.index??0)+r[0].length;return{html:t.slice(0,c)+`
4
+ `+n+t.slice(c),injected:!0}}case"body-end":{const r=t.match(/<\/body\s*>/i);if(!r)return{html:t,injected:!1,reason:"\u672A\u627E\u5230 </body> \u6807\u7B7E"};const c=r.index;return{html:t.slice(0,c)+n+`
5
+ `+t.slice(c),injected:!0}}case"before-selector":{if(!i)return{html:t,injected:!1,reason:"before-selector \u9700\u8981 selector \u53C2\u6570"};const r=f(t,i,a);return r?{html:t.slice(0,r.index)+n+`
6
+ `+t.slice(r.index),injected:!0}:{html:t,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${i}"`}}case"after-selector":{if(!i)return{html:t,injected:!1,reason:"after-selector \u9700\u8981 selector \u53C2\u6570"};const r=f(t,i,a);if(!r)return{html:t,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${i}"`};const c=r.index+r.length;return{html:t.slice(0,c)+`
7
+ `+n+t.slice(c),injected:!0}}case"replace-selector":{if(!i)return{html:t,injected:!1,reason:"replace-selector \u9700\u8981 selector \u53C2\u6570"};const r=f(t,i,a);if(!r)return{html:t,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${i}"`};const c=r.index+r.length;return{html:t.slice(0,r.index)+n+t.slice(c),injected:!0}}default:return{html:t,injected:!1,reason:`\u4E0D\u652F\u6301\u7684\u6CE8\u5165\u4F4D\u7F6E: ${o}`}}}function processRules(t,n,o,i,a){let r=t;const c=[],E=h(n);for(const d of E){const g={ruleId:d.id||"unnamed",position:d.position,selector:d.selector,injected:!1,timestamp:Date.now()};if(d.condition&&!x(d.condition,r)){g.injected=!1,g.reason="\u6761\u4EF6\u4E0D\u6EE1\u8DB3\uFF0C\u8DF3\u8FC7\u6CE8\u5165",c.push(g);continue}let m=p(d.content,d.templateVars,o);try{m=security.sanitizeContent(m,d,i,a)}catch(y){g.injected=!1,g.reason=y.message,c.push(g),a?.warn(`\u89C4\u5219 "${d.id||"unnamed"}" \u5B89\u5168\u68C0\u67E5\u5931\u8D25: ${y.message}`);continue}const F=b(r,m,d.position,d.selector,d.selectorMatch);r=F.html,g.injected=F.injected,g.reason=F.reason,c.push(g)}return{html:r,logs:c}}class u extends factory_index.BasePlugin{injectionLogs=[];getDefaultOptions(){return{targetFile:"index.html",logInjection:!0,security:{blockDangerousTags:!0,blockDangerousAttributes:!0}}}validateOptions(){this.validator.field("targetFile").string().field("rules").required().field("logInjection").boolean().validate(),validateAll(this.options)}getPluginName(){return"html-inject"}isTargetFile(n,o){if(o==="index.html")return n.endsWith("index.html")||n.endsWith("index.htm");const i=o.replace(/\\/g,"/"),a=n.replace(/\\/g,"/");return a.endsWith(i)?!0:l__default.basename(a)===l__default.basename(i)}addPluginHooks(n){n.transformIndexHtml={order:"post",handler:(o,i)=>{const a=i.filename||"",r=this.options.targetFile||"index.html";if(!this.isTargetFile(a,r))return o;const c={warn:d=>this.logger.warn(d)},E=processRules(o,this.options.rules,this.options.templateVars,this.options.security,c);return this.injectionLogs=E.logs,this.options.logInjection&&this.logInjectionResults(E.logs),E.html}},n.buildEnd=()=>{this.options.logInjection&&this.injectionLogs.length>0&&this.logger.info(`\u6CE8\u5165\u5B8C\u6210\uFF0C\u5171\u5904\u7406 ${this.injectionLogs.length} \u6761\u89C4\u5219`)}}logInjectionResults(n){for(const o of n)o.injected?this.logger.success(`\u89C4\u5219 "${o.ruleId}" \u6CE8\u5165\u6210\u529F (\u4F4D\u7F6E: ${o.position}${o.selector?`, \u9009\u62E9\u5668: ${o.selector}`:""})`):this.logger.warn(`\u89C4\u5219 "${o.ruleId}" \u6CE8\u5165\u5931\u8D25: ${o.reason||"\u672A\u77E5\u539F\u56E0"}`)}getInjectionLogs(){return[...this.injectionLogs]}}const htmlInject=factory_index.createPluginFactory(u);exports.htmlInject=htmlInject;
@@ -1,7 +1,7 @@
1
- import{createPluginFactory as E,BasePlugin as p}from"../../factory/index.mjs";import{s as m}from"../../shared/vite-plugin.BPFqtmWa.mjs";import g from"node:path";import"../../logger/index.mjs";import"../../shared/vite-plugin.DcExl6jd.mjs";function F(e){if(e){if(e.blockedTags&&!Array.isArray(e.blockedTags))throw new Error("security.blockedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(e.allowedTags&&!Array.isArray(e.allowedTags))throw new Error("security.allowedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(e.blockedAttributes&&!Array.isArray(e.blockedAttributes))throw new Error("security.blockedAttributes \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4")}}function y(e){if(!e.rules||!Array.isArray(e.rules))throw new Error("rules \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4");if(e.rules.length===0)throw new Error("rules \u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");for(let t=0;t<e.rules.length;t++)j(e.rules[t],t)}function j(e,t){if(!e.content||typeof e.content!="string")throw new Error(`rules[${t}].content \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`);if(!e.position||typeof e.position!="string")throw new Error(`rules[${t}].position \u5FC5\u987B\u662F\u6709\u6548\u7684\u6CE8\u5165\u4F4D\u7F6E`);const n=["head-start","head-end","body-start","body-end","before-selector","after-selector","replace-selector"];if(!n.includes(e.position))throw new Error(`rules[${t}].position \u5FC5\u987B\u662F ${n.join(", ")} \u4E4B\u4E00`);if(e.position.includes("selector")&&!e.selector)throw new Error(`rules[${t}].position \u4E3A "${e.position}" \u65F6\uFF0Cselector \u4E3A\u5FC5\u586B\u9879`);if(e.priority!==void 0&&(typeof e.priority!="number"||e.priority<0))throw new Error(`rules[${t}].priority \u5FC5\u987B\u662F\u975E\u8D1F\u6570`);e.condition&&C(e.condition,t)}function C(e,t){if(!e)return;const n=["env","file-contains","custom"];if(!n.includes(e.type))throw new Error(`rules[${t}].condition.type \u5FC5\u987B\u662F ${n.join(", ")} \u4E4B\u4E00`);if(e.type==="custom"&&typeof e.value!="function")throw new Error(`rules[${t}].condition.type \u4E3A "custom" \u65F6\uFF0Cvalue \u5FC5\u987B\u662F\u51FD\u6570`);if(e.type!=="custom"&&typeof e.value!="string")throw new Error(`rules[${t}].condition.type \u4E3A "${e.type}" \u65F6\uFF0Cvalue \u5FC5\u987B\u662F\u5B57\u7B26\u4E32`)}function w(e){y(e),F(e.security)}function h(e,t,n){if(n==="regex"){try{const i=new RegExp(t),u=e.match(i);if(u&&u.index!==void 0)return{index:u.index,length:u[0].length}}catch{return null}return null}const r=e.indexOf(t);return r===-1?null:{index:r,length:t.length}}function b(e,t,n){let r=e;const i={...n,...t};for(const[u,o]of Object.entries(i)){const c=u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=o.replace(/\$/g,"$$$$");r=r.replace(new RegExp(`\\{\\{${c}\\}\\}`,"g"),s)}return r}function $(e,t){let n=!1;switch(e.type){case"env":{const r=e.value,i=process.env[r];n=!!i&&i!=="false"&&i!=="0";break}case"file-contains":{const r=e.value;n=t.includes(r);break}case"custom":{const r=e.value;try{n=!!r()}catch{n=!1}break}}return e.negate?!n:n}function A(e){return[...e].sort((t,n)=>(t.priority??100)-(n.priority??100))}function B(e,t,n,r,i){switch(n){case"head-start":{const u=e.match(/<head\b[^>]*>/i);if(!u)return{html:e,injected:!1,reason:"\u672A\u627E\u5230 <head> \u6807\u7B7E"};const o=(u.index??0)+u[0].length;return{html:e.slice(0,o)+`
1
+ import{createPluginFactory as g,BasePlugin as p}from"../../factory/index.mjs";import{s as m}from"../../shared/vite-plugin.CuXEJAWX.mjs";import{parseTemplate as F}from"../../common/format/index.mjs";import E from"node:path";import"../../logger/index.mjs";import"../../shared/vite-plugin.DcExl6jd.mjs";function y(e){if(e){if(e.blockedTags&&!Array.isArray(e.blockedTags))throw new Error("security.blockedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(e.allowedTags&&!Array.isArray(e.allowedTags))throw new Error("security.allowedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(e.blockedAttributes&&!Array.isArray(e.blockedAttributes))throw new Error("security.blockedAttributes \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4")}}function j(e){if(!e.rules||!Array.isArray(e.rules))throw new Error("rules \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4");if(e.rules.length===0)throw new Error("rules \u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");for(let t=0;t<e.rules.length;t++)C(e.rules[t],t)}function C(e,t){if(!e.content||typeof e.content!="string")throw new Error(`rules[${t}].content \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`);if(!e.position||typeof e.position!="string")throw new Error(`rules[${t}].position \u5FC5\u987B\u662F\u6709\u6548\u7684\u6CE8\u5165\u4F4D\u7F6E`);const n=["head-start","head-end","body-start","body-end","before-selector","after-selector","replace-selector"];if(!n.includes(e.position))throw new Error(`rules[${t}].position \u5FC5\u987B\u662F ${n.join(", ")} \u4E4B\u4E00`);if(e.position.includes("selector")&&!e.selector)throw new Error(`rules[${t}].position \u4E3A "${e.position}" \u65F6\uFF0Cselector \u4E3A\u5FC5\u586B\u9879`);if(e.priority!==void 0&&(typeof e.priority!="number"||e.priority<0))throw new Error(`rules[${t}].priority \u5FC5\u987B\u662F\u975E\u8D1F\u6570`);e.condition&&w(e.condition,t)}function w(e,t){if(!e)return;const n=["env","file-contains","custom"];if(!n.includes(e.type))throw new Error(`rules[${t}].condition.type \u5FC5\u987B\u662F ${n.join(", ")} \u4E4B\u4E00`);if(e.type==="custom"&&typeof e.value!="function")throw new Error(`rules[${t}].condition.type \u4E3A "custom" \u65F6\uFF0Cvalue \u5FC5\u987B\u662F\u51FD\u6570`);if(e.type!=="custom"&&typeof e.value!="string")throw new Error(`rules[${t}].condition.type \u4E3A "${e.type}" \u65F6\uFF0Cvalue \u5FC5\u987B\u662F\u5B57\u7B26\u4E32`)}function b(e){j(e),y(e.security)}function h(e,t,n){if(n==="regex"){try{const i=new RegExp(t),u=e.match(i);if(u&&u.index!==void 0)return{index:u.index,length:u[0].length}}catch{return null}return null}const r=e.indexOf(t);return r===-1?null:{index:r,length:t.length}}function A(e,t,n){const r={...n,...t};return F(e,r)}function B(e,t){let n=!1;switch(e.type){case"env":{const r=e.value,i=process.env[r];n=!!i&&i!=="false"&&i!=="0";break}case"file-contains":{const r=e.value;n=t.includes(r);break}case"custom":{const r=e.value;try{n=!!r()}catch{n=!1}break}}return e.negate?!n:n}function $(e){return[...e].sort((t,n)=>(t.priority??100)-(n.priority??100))}function x(e,t,n,r,i){switch(n){case"head-start":{const u=e.match(/<head\b[^>]*>/i);if(!u)return{html:e,injected:!1,reason:"\u672A\u627E\u5230 <head> \u6807\u7B7E"};const o=(u.index??0)+u[0].length;return{html:e.slice(0,o)+`
2
2
  `+t+e.slice(o),injected:!0}}case"head-end":{const u=e.match(/<\/head\s*>/i);if(!u)return{html:e,injected:!1,reason:"\u672A\u627E\u5230 </head> \u6807\u7B7E"};const o=u.index;return{html:e.slice(0,o)+t+`
3
3
  `+e.slice(o),injected:!0}}case"body-start":{const u=e.match(/<body\b[^>]*>/i);if(!u)return{html:e,injected:!1,reason:"\u672A\u627E\u5230 <body> \u6807\u7B7E"};const o=(u.index??0)+u[0].length;return{html:e.slice(0,o)+`
4
4
  `+t+e.slice(o),injected:!0}}case"body-end":{const u=e.match(/<\/body\s*>/i);if(!u)return{html:e,injected:!1,reason:"\u672A\u627E\u5230 </body> \u6807\u7B7E"};const o=u.index;return{html:e.slice(0,o)+t+`
5
5
  `+e.slice(o),injected:!0}}case"before-selector":{if(!r)return{html:e,injected:!1,reason:"before-selector \u9700\u8981 selector \u53C2\u6570"};const u=h(e,r,i);return u?{html:e.slice(0,u.index)+t+`
6
6
  `+e.slice(u.index),injected:!0}:{html:e,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${r}"`}}case"after-selector":{if(!r)return{html:e,injected:!1,reason:"after-selector \u9700\u8981 selector \u53C2\u6570"};const u=h(e,r,i);if(!u)return{html:e,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${r}"`};const o=u.index+u.length;return{html:e.slice(0,o)+`
7
- `+t+e.slice(o),injected:!0}}case"replace-selector":{if(!r)return{html:e,injected:!1,reason:"replace-selector \u9700\u8981 selector \u53C2\u6570"};const u=h(e,r,i);if(!u)return{html:e,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${r}"`};const o=u.index+u.length;return{html:e.slice(0,u.index)+t+e.slice(o),injected:!0}}default:return{html:e,injected:!1,reason:`\u4E0D\u652F\u6301\u7684\u6CE8\u5165\u4F4D\u7F6E: ${n}`}}}function x(e,t,n,r,i){let u=e;const o=[],c=A(t);for(const s of c){const l={ruleId:s.id||"unnamed",position:s.position,selector:s.selector,injected:!1,timestamp:Date.now()};if(s.condition&&!$(s.condition,u)){l.injected=!1,l.reason="\u6761\u4EF6\u4E0D\u6EE1\u8DB3\uFF0C\u8DF3\u8FC7\u6CE8\u5165",o.push(l);continue}let a=b(s.content,s.templateVars,n);try{a=m(a,s,r,i)}catch(f){l.injected=!1,l.reason=f.message,o.push(l),i?.warn(`\u89C4\u5219 "${s.id||"unnamed"}" \u5B89\u5168\u68C0\u67E5\u5931\u8D25: ${f.message}`);continue}const d=B(u,a,s.position,s.selector,s.selectorMatch);u=d.html,l.injected=d.injected,l.reason=d.reason,o.push(l)}return{html:u,logs:o}}class v extends p{injectionLogs=[];getDefaultOptions(){return{targetFile:"index.html",logInjection:!0,security:{blockDangerousTags:!0,blockDangerousAttributes:!0}}}validateOptions(){this.validator.field("targetFile").string().field("rules").required().field("logInjection").boolean().validate(),w(this.options)}getPluginName(){return"html-inject"}isTargetFile(t,n){if(n==="index.html")return t.endsWith("index.html")||t.endsWith("index.htm");const r=n.replace(/\\/g,"/"),i=t.replace(/\\/g,"/");return i.endsWith(r)?!0:g.basename(i)===g.basename(r)}addPluginHooks(t){t.transformIndexHtml={order:"post",handler:(n,r)=>{const i=r.filename||"",u=this.options.targetFile||"index.html";if(!this.isTargetFile(i,u))return n;const o={warn:s=>this.logger.warn(s)},c=x(n,this.options.rules,this.options.templateVars,this.options.security,o);return this.injectionLogs=c.logs,this.options.logInjection&&this.logInjectionResults(c.logs),c.html}},t.buildEnd=()=>{this.options.logInjection&&this.injectionLogs.length>0&&this.logger.info(`\u6CE8\u5165\u5B8C\u6210\uFF0C\u5171\u5904\u7406 ${this.injectionLogs.length} \u6761\u89C4\u5219`)}}logInjectionResults(t){for(const n of t)n.injected?this.logger.success(`\u89C4\u5219 "${n.ruleId}" \u6CE8\u5165\u6210\u529F (\u4F4D\u7F6E: ${n.position}${n.selector?`, \u9009\u62E9\u5668: ${n.selector}`:""})`):this.logger.warn(`\u89C4\u5219 "${n.ruleId}" \u6CE8\u5165\u5931\u8D25: ${n.reason||"\u672A\u77E5\u539F\u56E0"}`)}getInjectionLogs(){return[...this.injectionLogs]}}const D=E(v);export{D as htmlInject};
7
+ `+t+e.slice(o),injected:!0}}case"replace-selector":{if(!r)return{html:e,injected:!1,reason:"replace-selector \u9700\u8981 selector \u53C2\u6570"};const u=h(e,r,i);if(!u)return{html:e,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${r}"`};const o=u.index+u.length;return{html:e.slice(0,u.index)+t+e.slice(o),injected:!0}}default:return{html:e,injected:!1,reason:`\u4E0D\u652F\u6301\u7684\u6CE8\u5165\u4F4D\u7F6E: ${n}`}}}function v(e,t,n,r,i){let u=e;const o=[],c=$(t);for(const s of c){const l={ruleId:s.id||"unnamed",position:s.position,selector:s.selector,injected:!1,timestamp:Date.now()};if(s.condition&&!B(s.condition,u)){l.injected=!1,l.reason="\u6761\u4EF6\u4E0D\u6EE1\u8DB3\uFF0C\u8DF3\u8FC7\u6CE8\u5165",o.push(l);continue}let a=A(s.content,s.templateVars,n);try{a=m(a,s,r,i)}catch(f){l.injected=!1,l.reason=f.message,o.push(l),i?.warn(`\u89C4\u5219 "${s.id||"unnamed"}" \u5B89\u5168\u68C0\u67E5\u5931\u8D25: ${f.message}`);continue}const d=x(u,a,s.position,s.selector,s.selectorMatch);u=d.html,l.injected=d.injected,l.reason=d.reason,o.push(l)}return{html:u,logs:o}}class D extends p{injectionLogs=[];getDefaultOptions(){return{targetFile:"index.html",logInjection:!0,security:{blockDangerousTags:!0,blockDangerousAttributes:!0}}}validateOptions(){this.validator.field("targetFile").string().field("rules").required().field("logInjection").boolean().validate(),b(this.options)}getPluginName(){return"html-inject"}isTargetFile(t,n){if(n==="index.html")return t.endsWith("index.html")||t.endsWith("index.htm");const r=n.replace(/\\/g,"/"),i=t.replace(/\\/g,"/");return i.endsWith(r)?!0:E.basename(i)===E.basename(r)}addPluginHooks(t){t.transformIndexHtml={order:"post",handler:(n,r)=>{const i=r.filename||"",u=this.options.targetFile||"index.html";if(!this.isTargetFile(i,u))return n;const o={warn:s=>this.logger.warn(s)},c=v(n,this.options.rules,this.options.templateVars,this.options.security,o);return this.injectionLogs=c.logs,this.options.logInjection&&this.logInjectionResults(c.logs),c.html}},t.buildEnd=()=>{this.options.logInjection&&this.injectionLogs.length>0&&this.logger.info(`\u6CE8\u5165\u5B8C\u6210\uFF0C\u5171\u5904\u7406 ${this.injectionLogs.length} \u6761\u89C4\u5219`)}}logInjectionResults(t){for(const n of t)n.injected?this.logger.success(`\u89C4\u5219 "${n.ruleId}" \u6CE8\u5165\u6210\u529F (\u4F4D\u7F6E: ${n.position}${n.selector?`, \u9009\u62E9\u5668: ${n.selector}`:""})`):this.logger.warn(`\u89C4\u5219 "${n.ruleId}" \u6CE8\u5165\u5931\u8D25: ${n.reason||"\u672A\u77E5\u539F\u56E0"}`)}getInjectionLogs(){return[...this.injectionLogs]}}const k=g(D);export{k as htmlInject};
@@ -1 +1 @@
1
- "use strict";const plugins_autoImport_index=require("./autoImport/index.cjs"),plugins_buildProgress_index=require("./buildProgress/index.cjs"),plugins_bundleAnalyzer_index=require("./bundleAnalyzer/index.cjs"),plugins_compressAssets_index=require("./compressAssets/index.cjs"),plugins_copyFile_index=require("./copyFile/index.cjs"),plugins_envGuard_index=require("./envGuard/index.cjs"),plugins_faviconManager_index=require("./faviconManager/index.cjs"),plugins_generateRouter_index=require("./generateRouter/index.cjs"),plugins_generateVersion_index=require("./generateVersion/index.cjs"),plugins_htmlInject_index=require("./htmlInject/index.cjs"),plugins_loadingManager_index=require("./loadingManager/index.cjs"),plugins_versionUpdateChecker_index=require("./versionUpdateChecker/index.cjs");require("../factory/index.cjs"),require("../logger/index.cjs"),require("../shared/vite-plugin.Bcg6RW2N.cjs"),require("node:fs"),require("node:path"),require("../common/ui/index.cjs"),require("node:zlib"),require("node:util"),require("../common/fs/index.cjs"),require("fs"),require("path"),require("../common/format/index.cjs"),require("node:stream/promises"),require("../common/html/index.cjs"),require("../shared/vite-plugin.CnOy46d3.cjs"),require("crypto"),require("../common/script/index.cjs"),require("../common/validation/index.cjs"),exports.autoImport=plugins_autoImport_index.autoImport,exports.buildProgress=plugins_buildProgress_index.buildProgress,exports.bundleAnalyzer=plugins_bundleAnalyzer_index.bundleAnalyzer,exports.compressAssets=plugins_compressAssets_index.compressAssets,exports.copyFile=plugins_copyFile_index.copyFile,exports.envGuard=plugins_envGuard_index.envGuard,exports.faviconManager=plugins_faviconManager_index.faviconManager,exports.generateRouter=plugins_generateRouter_index.generateRouter,exports.generateVersion=plugins_generateVersion_index.generateVersion,exports.htmlInject=plugins_htmlInject_index.htmlInject,exports.loadingManager=plugins_loadingManager_index.loadingManager,exports.versionUpdateChecker=plugins_versionUpdateChecker_index.versionUpdateChecker;
1
+ "use strict";const plugins_autoImport_index=require("./autoImport/index.cjs"),plugins_buildProgress_index=require("./buildProgress/index.cjs"),plugins_bundleAnalyzer_index=require("./bundleAnalyzer/index.cjs"),plugins_compressAssets_index=require("./compressAssets/index.cjs"),plugins_copyFile_index=require("./copyFile/index.cjs"),plugins_envGuard_index=require("./envGuard/index.cjs"),plugins_faviconManager_index=require("./faviconManager/index.cjs"),plugins_generateRouter_index=require("./generateRouter/index.cjs"),plugins_generateVersion_index=require("./generateVersion/index.cjs"),plugins_htmlInject_index=require("./htmlInject/index.cjs"),plugins_loadingManager_index=require("./loadingManager/index.cjs"),plugins_versionUpdateChecker_index=require("./versionUpdateChecker/index.cjs");require("../factory/index.cjs"),require("../logger/index.cjs"),require("../shared/vite-plugin.Bcg6RW2N.cjs"),require("node:fs"),require("node:path"),require("../common/fs/index.cjs"),require("fs"),require("path"),require("../common/ui/index.cjs"),require("node:zlib"),require("node:util"),require("../common/format/index.cjs"),require("node:stream/promises"),require("../common/html/index.cjs"),require("../shared/vite-plugin.CcvHfrL8.cjs"),require("crypto"),require("../common/script/index.cjs"),require("../common/validation/index.cjs"),exports.autoImport=plugins_autoImport_index.autoImport,exports.buildProgress=plugins_buildProgress_index.buildProgress,exports.bundleAnalyzer=plugins_bundleAnalyzer_index.bundleAnalyzer,exports.compressAssets=plugins_compressAssets_index.compressAssets,exports.copyFile=plugins_copyFile_index.copyFile,exports.envGuard=plugins_envGuard_index.envGuard,exports.faviconManager=plugins_faviconManager_index.faviconManager,exports.generateRouter=plugins_generateRouter_index.generateRouter,exports.generateVersion=plugins_generateVersion_index.generateVersion,exports.htmlInject=plugins_htmlInject_index.htmlInject,exports.loadingManager=plugins_loadingManager_index.loadingManager,exports.versionUpdateChecker=plugins_versionUpdateChecker_index.versionUpdateChecker;
@@ -1 +1 @@
1
- export{autoImport}from"./autoImport/index.mjs";export{buildProgress}from"./buildProgress/index.mjs";export{bundleAnalyzer}from"./bundleAnalyzer/index.mjs";export{compressAssets}from"./compressAssets/index.mjs";export{copyFile}from"./copyFile/index.mjs";export{envGuard}from"./envGuard/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"../shared/vite-plugin.DcExl6jd.mjs";import"node:fs";import"node:path";import"../common/ui/index.mjs";import"node:zlib";import"node:util";import"../common/fs/index.mjs";import"fs";import"path";import"../common/format/index.mjs";import"node:stream/promises";import"../common/html/index.mjs";import"../shared/vite-plugin.BPFqtmWa.mjs";import"crypto";import"../common/script/index.mjs";import"../common/validation/index.mjs";
1
+ export{autoImport}from"./autoImport/index.mjs";export{buildProgress}from"./buildProgress/index.mjs";export{bundleAnalyzer}from"./bundleAnalyzer/index.mjs";export{compressAssets}from"./compressAssets/index.mjs";export{copyFile}from"./copyFile/index.mjs";export{envGuard}from"./envGuard/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"../shared/vite-plugin.DcExl6jd.mjs";import"node:fs";import"node:path";import"../common/fs/index.mjs";import"fs";import"path";import"../common/ui/index.mjs";import"node:zlib";import"node:util";import"../common/format/index.mjs";import"node:stream/promises";import"../common/html/index.mjs";import"../shared/vite-plugin.CuXEJAWX.mjs";import"crypto";import"../common/script/index.mjs";import"../common/validation/index.mjs";
@@ -1,4 +1,4 @@
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.CnOy46d3.cjs");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 P(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function generateCSS(e,t="spinner",n){const{overlayColor:o="rgba(255, 255, 255, 0.7)",spinnerColor:a="#4361ee",spinnerSize:u="40px",textColor:r="#333",textSize:l="14px",zIndex:c=9999,pointerEvents:m=!0,backdropBlur:d=!1,backdropBlurAmount:_=4}=e,h=m?"":"pointer-events: none;",y=d?`backdrop-filter: blur(${_}px);-webkit-backdrop-filter: blur(${_}px);`:"",E=getSpinnerCSS(t,a,u),b=n?.enabled!==!1,f=n?.duration??200,g=n?.easing??"ease-out",p=b?`transition: opacity ${f}ms ${g}, visibility ${f}ms ${g};`:"";return`
1
+ "use strict";const factory_index=require("../../factory/index.cjs"),security=require("../../shared/vite-plugin.CcvHfrL8.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");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:o="rgba(255, 255, 255, 0.7)",spinnerColor:a="#4361ee",spinnerSize:u="40px",textColor:r="#333",textSize:l="14px",zIndex:c=9999,pointerEvents:m=!0,backdropBlur:d=!1,backdropBlurAmount:_=4}=e,h=m?"":"pointer-events: none;",y=d?`backdrop-filter: blur(${_}px);-webkit-backdrop-filter: blur(${_}px);`:"",E=getSpinnerCSS(t,a,u),b=n?.enabled!==!1,f=n?.duration??200,p=n?.easing??"ease-out",g=b?`transition: opacity ${f}ms ${p}, visibility ${f}ms ${p};`:"";return`
2
2
  .${CLS_OVERLAY} {
3
3
  position: fixed;
4
4
  top: 0;
@@ -37,7 +37,7 @@ ${E}
37
37
  .${CLS_OVERLAY}.${CLS_HIDDEN} {
38
38
  opacity: 0;
39
39
  visibility: hidden;
40
- ${p}
40
+ ${g}
41
41
  }
42
42
  .${CLS_OVERLAY}.${CLS_HIDDEN} .${CLS_SPINNER},
43
43
  .${CLS_OVERLAY}.${CLS_HIDDEN} .${CLS_DOT},
@@ -47,7 +47,7 @@ ${E}
47
47
  .${CLS_OVERLAY}.${CLS_VISIBLE} {
48
48
  opacity: 1;
49
49
  visibility: visible;
50
- ${p}
50
+ ${g}
51
51
  }
52
52
  .${CLS_OVERLAY}.${CLS_VISIBLE} .${CLS_SPINNER},
53
53
  .${CLS_OVERLAY}.${CLS_VISIBLE} .${CLS_DOT},
@@ -117,7 +117,7 @@ ${E}
117
117
  }
118
118
  @keyframes ${ANIM_SPIN} {
119
119
  to { transform: rotate(360deg); }
120
- }`}}function generateHTMLTemplate(e){const t=e.position||"center",n=e.defaultText||"\u52A0\u8F7D\u4E2D...",o=e.spinnerType||"spinner",a=POSITION_CLASS_MAP[t],u=e.style?.customClass?` ${e.style.customClass}`:"",r=e.style?.customStyle?` style="${P(e.style.customStyle)}"`:"",l=e.defaultVisible?CLS_VISIBLE:CLS_HIDDEN;if(e.customTemplate)return`<div class="${CLS_OVERLAY} ${a} ${l}${u}" id="${ID_ROOT}"${r}>${e.customTemplate}</div>`;const c=getSpinnerHTML(o);return`<div class="${CLS_OVERLAY} ${a} ${l}${u}" id="${ID_ROOT}"${r}>
120
+ }`}}function generateHTMLTemplate(e){const t=e.position||"center",n=e.defaultText||"\u52A0\u8F7D\u4E2D...",o=e.spinnerType||"spinner",a=POSITION_CLASS_MAP[t],u=e.style?.customClass?` ${e.style.customClass}`:"",r=e.style?.customStyle?` style="${security.escapeHtmlAttr(e.style.customStyle)}"`:"",l=e.defaultVisible?CLS_VISIBLE:CLS_HIDDEN;if(e.customTemplate)return`<div class="${CLS_OVERLAY} ${a} ${l}${u}" id="${ID_ROOT}"${r}>${e.customTemplate}</div>`;const c=getSpinnerHTML(o);return`<div class="${CLS_OVERLAY} ${a} ${l}${u}" id="${ID_ROOT}"${r}>
121
121
  ${c}
122
122
  <div class="${CLS_TEXT}" ${ATTR_TEXT}>${n}</div>
123
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;
@@ -430,7 +430,7 @@ ${E}
430
430
  }
431
431
  `),o+=`
432
432
  // \u66B4\u9732\u5230\u5168\u5C40
433
- window['${n}'] = manager;`,o}function generateLoadingManagerCode(e){const t=e.globalName||"__LOADING_MANAGER__",n=e.minDisplayTime||{enabled:!0,duration:300},o=e.delayShow||{enabled:!0,duration:200},a=e.debounceHide||{enabled:!1,duration:100},u=e.transition||{enabled:!0,duration:200,easing:"ease-out"},r=e.autoBind||"none",l=e.requestFilter||{},c=e.defaultVisible||!1,m=e.autoHideOn||"DOMContentLoaded",d=e.callbacks||{},_=l.excludeUrls||[],h=l.includeUrls||[],y=l.excludeMethods||[],E=l.excludeUrlPrefixes||[],b=common_script_index.makeCallback(d.onBeforeShow,"loadingManager"),f=common_script_index.makeCallback(d.onShow,"loadingManager"),g=common_script_index.makeCallback(d.onBeforeHide,"loadingManager"),p=common_script_index.makeCallback(d.onHide,"loadingManager"),$=common_script_index.makeCallback(d.onDestroy,"loadingManager"),v=generateVarsCode({minDisplayTime:n,delayShow:o,debounceHide:a,transition:u,excludeUrls:_,includeUrls:h,excludeMethods:y,excludeUrlPrefixes:E,cbBeforeShow:b,cbShow:f,cbBeforeHide:g,cbHide:p,cbDestroy:$}),w=generateHelpersCode(t),C=generateCoreLogicCode(),T=generateManagerObjectCode(),x=generateInterceptorsCode(r),S=generateInitCode(c,m,t);return`(function() {
433
+ window['${n}'] = manager;`,o}function generateLoadingManagerCode(e){const t=e.globalName||"__LOADING_MANAGER__",n=e.minDisplayTime||{enabled:!0,duration:300},o=e.delayShow||{enabled:!0,duration:200},a=e.debounceHide||{enabled:!1,duration:100},u=e.transition||{enabled:!0,duration:200,easing:"ease-out"},r=e.autoBind||"none",l=e.requestFilter||{},c=e.defaultVisible||!1,m=e.autoHideOn||"DOMContentLoaded",d=e.callbacks||{},_=l.excludeUrls||[],h=l.includeUrls||[],y=l.excludeMethods||[],E=l.excludeUrlPrefixes||[],b=common_script_index.makeCallback(d.onBeforeShow,"loadingManager"),f=common_script_index.makeCallback(d.onShow,"loadingManager"),p=common_script_index.makeCallback(d.onBeforeHide,"loadingManager"),g=common_script_index.makeCallback(d.onHide,"loadingManager"),$=common_script_index.makeCallback(d.onDestroy,"loadingManager"),v=generateVarsCode({minDisplayTime:n,delayShow:o,debounceHide:a,transition:u,excludeUrls:_,includeUrls:h,excludeMethods:y,excludeUrlPrefixes:E,cbBeforeShow:b,cbShow:f,cbBeforeHide:p,cbHide:g,cbDestroy:$}),w=generateHelpersCode(t),C=generateCoreLogicCode(),T=generateManagerObjectCode(),x=generateInterceptorsCode(r),S=generateInitCode(c,m,t);return`(function() {
434
434
  'use strict';
435
435
 
436
436
  // SSR \u73AF\u5883\u68C0\u6D4B
@@ -1,4 +1,4 @@
1
- import{createPluginFactory as V,BasePlugin as j}from"../../factory/index.mjs";import{makeCallback as g}from"../../common/script/index.mjs";import{validateCallbackFields as G,validateNoScriptInTemplate as J,validateGlobalName as z}from"../../common/validation/index.mjs";import{injectHeadAndBody as Y}from"../../common/html/index.mjs";import"../../logger/index.mjs";import"../../shared/vite-plugin.DcExl6jd.mjs";import"../../shared/vite-plugin.BPFqtmWa.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__",K={center:F,top:H,bottom:A};function Q(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}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`
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;
@@ -117,7 +117,7 @@ ${w}
117
117
  }
118
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=K[t],d=e.style?.customClass?` ${e.style.customClass}`:"",a=e.style?.customStyle?` style="${Q(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}>
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;
@@ -449,7 +449,7 @@ ${P}
449
449
  ${X}
450
450
 
451
451
  ${q}
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&&G(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(),J(this.options.customTemplate,"customTemplate");const t=ce(this.options.defaultText);t&&this.logger.warn(t),z(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 -->
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 -->
@@ -484,4 +484,4 @@ ${n}
484
484
  })();
485
485
  ${n}
486
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=Y(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};
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};
@@ -1,4 +1,4 @@
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.CnOy46d3.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;}
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
  };
@@ -1,4 +1,4 @@
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.BPFqtmWa.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;}
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;}
@@ -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 @@
1
+ "use strict";function escapeHtmlAttr(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}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,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}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.5",
4
+ "version": "0.1.6",
5
5
  "private": false,
6
6
  "description": "一个为 Vite 提供实用插件的工具包,同时也是一个完整的插件开发框架",
7
7
  "keywords": [
@@ -142,7 +142,7 @@
142
142
  "generate-exports": "tsx scripts/generate-exports.ts"
143
143
  },
144
144
  "peerDependencies": {
145
- "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
145
+ "vite": ">=5.0.0 <8.0.0"
146
146
  },
147
147
  "devDependencies": {
148
148
  "@types/node": "^22.0.0",
@@ -1 +0,0 @@
1
- function C(i){return/<script\b/i.test(i)}const p=["script","iframe","object","embed","applet","form","input","textarea","select","button"],d=["onclick","ondblclick","onmouseover","onmouseout","onmousemove","onmousedown","onmouseup","onkeydown","onkeyup","onkeypress","onload","onerror","onfocus","onblur","onsubmit","onchange","oninput","oncontextmenu","ondrag","ondrop","onanimationend","ontransitionend"];function w(i,o,e,r){const l=e?.blockDangerousTags!==!1,a=e?.blockDangerousAttributes!==!1,B=e?.blockedTags||p,c=e?.allowedTags,E=e?.blockedAttributes||d;let n=i;if(l){const t=c?B.filter(u=>!c.includes(u)):B;if(C(i))if(o.allowScriptInjection)r?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${o.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 "${o.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 t){if(u==="script")continue;const F=new RegExp(`<${u}\\b[^>]*>[\\s\\S]*?<\\/${u}>`,"gi"),s=new RegExp(`<${u}\\b[^>]*/?>`,"gi");if(F.test(n)||s.test(n))if(o.allowScriptInjection){r?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${o.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 "${o.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}"`);n=n.replace(F,""),n=n.replace(s,"")}}if(a)for(const t of E){const u=new RegExp(`\\s${t}\\s*=\\s*["'][^"']*["']`,"gi");if(u.test(n))if(o.allowScriptInjection){r?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${o.id||"unnamed"}" \u5305\u542B\u5371\u9669\u5C5E\u6027 ${t}\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 "${o.id||"unnamed"}" \u7684\u5185\u5BB9\u5305\u542B\u5371\u9669\u5C5E\u6027 ${t}\u3002\u5982\u9700\u6CE8\u5165\u6B64\u5C5E\u6027\uFF0C\u8BF7\u8BBE\u7F6E allowScriptInjection: true`);n=n.replace(u,"")}return n}export{w as s};
@@ -1 +0,0 @@
1
- "use strict";function w(i){return/<script\b/i.test(i)}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(i,o,e,r){const l=e?.blockDangerousTags!==!1,a=e?.blockDangerousAttributes!==!1,B=e?.blockedTags||f,c=e?.allowedTags,E=e?.blockedAttributes||b;let n=i;if(l){const t=c?B.filter(u=>!c.includes(u)):B;if(w(i))if(o.allowScriptInjection)r?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${o.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 "${o.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 t){if(u==="script")continue;const F=new RegExp(`<${u}\\b[^>]*>[\\s\\S]*?<\\/${u}>`,"gi"),s=new RegExp(`<${u}\\b[^>]*/?>`,"gi");if(F.test(n)||s.test(n))if(o.allowScriptInjection){r?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${o.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 "${o.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}"`);n=n.replace(F,""),n=n.replace(s,"")}}if(a)for(const t of E){const u=new RegExp(`\\s${t}\\s*=\\s*["'][^"']*["']`,"gi");if(u.test(n))if(o.allowScriptInjection){r?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${o.id||"unnamed"}" \u5305\u542B\u5371\u9669\u5C5E\u6027 ${t}\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 "${o.id||"unnamed"}" \u7684\u5185\u5BB9\u5305\u542B\u5371\u9669\u5C5E\u6027 ${t}\u3002\u5982\u9700\u6CE8\u5165\u6B64\u5C5E\u6027\uFF0C\u8BF7\u8BBE\u7F6E allowScriptInjection: true`);n=n.replace(u,"")}return n}exports.sanitizeContent=sanitizeContent;