@meng-xi/vite-plugin 0.0.9 → 0.1.1

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 (105) hide show
  1. package/README-en.md +467 -269
  2. package/README.md +451 -254
  3. package/dist/common/format/index.cjs +1 -0
  4. package/dist/common/format/index.d.cts +156 -0
  5. package/dist/common/format/index.d.mts +156 -0
  6. package/dist/common/format/index.d.ts +156 -0
  7. package/dist/common/format/index.mjs +1 -0
  8. package/dist/common/fs/index.cjs +1 -0
  9. package/dist/common/fs/index.d.cts +150 -0
  10. package/dist/common/fs/index.d.mts +150 -0
  11. package/dist/common/fs/index.d.ts +150 -0
  12. package/dist/common/fs/index.mjs +1 -0
  13. package/dist/common/html/index.cjs +2 -0
  14. package/dist/common/html/index.d.cts +109 -0
  15. package/dist/common/html/index.d.mts +109 -0
  16. package/dist/common/html/index.d.ts +109 -0
  17. package/dist/common/html/index.mjs +2 -0
  18. package/dist/common/index.cjs +1 -1
  19. package/dist/common/index.d.cts +7 -318
  20. package/dist/common/index.d.mts +7 -318
  21. package/dist/common/index.d.ts +7 -318
  22. package/dist/common/index.mjs +1 -1
  23. package/dist/common/object/index.cjs +1 -0
  24. package/dist/common/object/index.d.cts +30 -0
  25. package/dist/common/object/index.d.mts +30 -0
  26. package/dist/common/object/index.d.ts +30 -0
  27. package/dist/common/object/index.mjs +1 -0
  28. package/dist/common/script/index.cjs +1 -0
  29. package/dist/common/script/index.d.cts +54 -0
  30. package/dist/common/script/index.d.mts +54 -0
  31. package/dist/common/script/index.d.ts +54 -0
  32. package/dist/common/script/index.mjs +1 -0
  33. package/dist/common/validation/index.cjs +1 -0
  34. package/dist/common/validation/index.d.cts +93 -0
  35. package/dist/common/validation/index.d.mts +93 -0
  36. package/dist/common/validation/index.d.ts +93 -0
  37. package/dist/common/validation/index.mjs +1 -0
  38. package/dist/factory/index.cjs +1 -1
  39. package/dist/factory/index.d.cts +1 -1
  40. package/dist/factory/index.d.mts +1 -1
  41. package/dist/factory/index.d.ts +1 -1
  42. package/dist/factory/index.mjs +1 -1
  43. package/dist/index.cjs +1 -1
  44. package/dist/index.d.cts +15 -3
  45. package/dist/index.d.mts +15 -3
  46. package/dist/index.d.ts +15 -3
  47. package/dist/index.mjs +1 -1
  48. package/dist/plugins/buildProgress/index.cjs +2 -0
  49. package/dist/plugins/buildProgress/index.d.cts +187 -0
  50. package/dist/plugins/buildProgress/index.d.mts +187 -0
  51. package/dist/plugins/buildProgress/index.d.ts +187 -0
  52. package/dist/plugins/buildProgress/index.mjs +2 -0
  53. package/dist/plugins/copyFile/index.cjs +1 -0
  54. package/dist/plugins/copyFile/index.d.cts +78 -0
  55. package/dist/plugins/copyFile/index.d.mts +78 -0
  56. package/dist/plugins/copyFile/index.d.ts +78 -0
  57. package/dist/plugins/copyFile/index.mjs +1 -0
  58. package/dist/plugins/faviconManager/index.cjs +1 -0
  59. package/dist/plugins/faviconManager/index.d.cts +143 -0
  60. package/dist/plugins/faviconManager/index.d.mts +143 -0
  61. package/dist/plugins/faviconManager/index.d.ts +143 -0
  62. package/dist/plugins/faviconManager/index.mjs +1 -0
  63. package/dist/plugins/generateRouter/index.cjs +35 -0
  64. package/dist/plugins/generateRouter/index.d.cts +215 -0
  65. package/dist/plugins/generateRouter/index.d.mts +215 -0
  66. package/dist/plugins/generateRouter/index.d.ts +215 -0
  67. package/dist/plugins/generateRouter/index.mjs +35 -0
  68. package/dist/plugins/generateVersion/index.cjs +1 -0
  69. package/dist/plugins/generateVersion/index.d.cts +184 -0
  70. package/dist/plugins/generateVersion/index.d.mts +184 -0
  71. package/dist/plugins/generateVersion/index.d.ts +184 -0
  72. package/dist/plugins/generateVersion/index.mjs +1 -0
  73. package/dist/plugins/htmlInject/index.cjs +7 -0
  74. package/dist/plugins/htmlInject/index.d.cts +278 -0
  75. package/dist/plugins/htmlInject/index.d.mts +278 -0
  76. package/dist/plugins/htmlInject/index.d.ts +278 -0
  77. package/dist/plugins/htmlInject/index.mjs +7 -0
  78. package/dist/plugins/index.cjs +1 -1
  79. package/dist/plugins/index.d.cts +10 -1520
  80. package/dist/plugins/index.d.mts +10 -1520
  81. package/dist/plugins/index.d.ts +10 -1520
  82. package/dist/plugins/index.mjs +1 -1
  83. package/dist/plugins/loadingManager/index.cjs +487 -0
  84. package/dist/plugins/loadingManager/index.d.cts +769 -0
  85. package/dist/plugins/loadingManager/index.d.mts +769 -0
  86. package/dist/plugins/loadingManager/index.d.ts +769 -0
  87. package/dist/plugins/loadingManager/index.mjs +487 -0
  88. package/dist/plugins/versionUpdateChecker/index.cjs +185 -0
  89. package/dist/plugins/versionUpdateChecker/index.d.cts +200 -0
  90. package/dist/plugins/versionUpdateChecker/index.d.mts +200 -0
  91. package/dist/plugins/versionUpdateChecker/index.d.ts +200 -0
  92. package/dist/plugins/versionUpdateChecker/index.mjs +185 -0
  93. package/dist/shared/vite-plugin.Bcg6RW2N.cjs +3 -0
  94. package/dist/shared/{vite-plugin.CiHfwMiN.d.cts → vite-plugin.DRRlWY8P.d.cts} +50 -0
  95. package/dist/shared/{vite-plugin.CiHfwMiN.d.mts → vite-plugin.DRRlWY8P.d.mts} +50 -0
  96. package/dist/shared/{vite-plugin.CiHfwMiN.d.ts → vite-plugin.DRRlWY8P.d.ts} +50 -0
  97. package/dist/shared/{vite-plugin.B88RyRN8.mjs → vite-plugin.DcExl6jd.mjs} +2 -2
  98. package/package.json +72 -2
  99. package/dist/shared/vite-plugin.BI4kA-bR.mjs +0 -526
  100. package/dist/shared/vite-plugin.Ba9646wL.cjs +0 -1
  101. package/dist/shared/vite-plugin.C3ejdBNf.mjs +0 -1
  102. package/dist/shared/vite-plugin.CawoITTT.cjs +0 -1
  103. package/dist/shared/vite-plugin.CsdNNQ-4.cjs +0 -526
  104. package/dist/shared/vite-plugin.DSb6XzBn.mjs +0 -1
  105. package/dist/shared/vite-plugin.IGZeStMa.cjs +0 -3
@@ -1,526 +0,0 @@
1
- import{c as _,B as E}from"./vite-plugin.DSb6XzBn.mjs";import{c as M,a as O,t as R,m as ie,i as P,l as ne,w as L,d as ue,g as oe,h as se}from"./vite-plugin.C3ejdBNf.mjs";import"crypto";import{resolve as x,join as re}from"path";import{existsSync as S,watch as ae}from"fs";import{V as le}from"./vite-plugin.B88RyRN8.mjs";const N=process.platform==="win32"?["|","/","-","\\"]:["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],a={reset:"\x1B[0G",clearLine:"\x1B[2K",hideCursor:"\x1B[?25l",showCursor:"\x1B[?25h",green:n=>`\x1B[32m${n}\x1B[39m`,cyan:n=>`\x1B[36m${n}\x1B[39m`,gray:n=>`\x1B[90m${n}\x1B[39m`,bold:n=>`\x1B[1m${n}\x1B[22m`},k={completeColor:a.green,incompleteColor:a.gray,percentageColor:a.bold,phaseColor:a.cyan,moduleColor:a.gray},de={idle:"\u7B49\u5F85\u4E2D",config:"\u8BFB\u53D6\u914D\u7F6E",resolve:"\u89E3\u6790\u6A21\u5757",transform:"\u8F6C\u6362\u6A21\u5757",bundle:"\u6253\u5305\u4E2D",write:"\u5199\u5165\u6587\u4EF6",done:"\u6784\u5EFA\u5B8C\u6210"};class v extends E{totalModules=0;transformedModules=0;currentModule="";phase="idle";spinnerIndex=0;spinnerTimer=null;isDev=!1;theme=k;lastPercentage=0;static ANSI_REGEX=/\x1b\[[0-9;]*m/g;static stripAnsi(e){return e.replace(v.ANSI_REGEX,"")}getDefaultOptions(){return{width:30,format:"bar",completeChar:"\u2588",incompleteChar:"\u2591",clearOnComplete:!0,showModuleName:!0}}validateOptions(){this.validator.field("width").number().custom(e=>!e||e>0,"width \u5FC5\u987B\u5927\u4E8E 0").field("format").custom(e=>!e||["bar","spinner","minimal"].includes(e),"format \u5FC5\u987B\u662F bar, spinner \u6216 minimal").field("completeChar").string().field("incompleteChar").string().field("clearOnComplete").boolean().field("showModuleName").boolean().validate()}getPluginName(){return"build-progress"}onConfigResolved(e){super.onConfigResolved(e),this.theme=this.options.theme||k}getPercentage(){if(this.phase==="done")return this.lastPercentage=100;if(this.phase==="config")return this.lastPercentage=5;if(this.phase==="resolve")return this.lastPercentage=10;if(this.totalModules===0)return this.lastPercentage=15;const e=Math.min(this.transformedModules/this.totalModules*70,70),t=this.phase==="bundle"?10:0,i=this.phase==="write"?5:0,u=Math.min(Math.floor(15+e+t+i),99);return this.lastPercentage=Math.max(u,this.lastPercentage),this.lastPercentage}renderBar(e){const t=this.options.width||30,i=this.options.completeChar||"\u2588",u=this.options.incompleteChar||"\u2591",o=Math.round(e/100*t),s=t-o;return this.theme.completeColor(i.repeat(o))+this.theme.incompleteColor(u.repeat(s))}renderSpinner(){const e=N[this.spinnerIndex%N.length];return this.spinnerIndex++,this.theme.phaseColor(e)}render(e){const t=this.options.format||"bar",i=this.theme.phaseColor(de[this.phase]),u=this.theme.percentageColor(`${e}%`);let o="";if(t==="bar"?o=`${this.renderSpinner()} ${i} ${this.renderBar(e)} ${u}`:t==="spinner"?o=`${this.renderSpinner()} ${i} ${u}`:o=`${i} ${u}`,this.options.showModuleName&&this.currentModule&&this.phase==="transform"){const s=v.stripAnsi(o).length,r=Math.max((process.stdout.columns||80)-s-3,20),c=this.currentModule.length>r?"..."+this.currentModule.slice(-r+3):this.currentModule;o+=` ${this.theme.moduleColor(c)}`}return o}update(){if(!process.stdout.isTTY)return;const e=this.getPercentage(),t=this.render(e);this.safeExecuteSync(()=>{process.stdout.write(a.clearLine+a.reset+t)},"\u66F4\u65B0\u8FDB\u5EA6\u663E\u793A")}startSpinner(){this.spinnerTimer||process.stdout.isTTY&&(this.spinnerTimer=setInterval(()=>this.update(),80))}stopSpinner(){this.spinnerTimer&&(clearInterval(this.spinnerTimer),this.spinnerTimer=null)}complete(){if(this.phase="done",this.stopSpinner(),!process.stdout.isTTY){this.logger.success("\u6784\u5EFA\u5B8C\u6210");return}if(this.options.clearOnComplete)this.safeExecuteSync(()=>{process.stdout.write(a.clearLine+a.reset)},"\u6E05\u9664\u8FDB\u5EA6\u884C");else{const e=this.render(100);this.safeExecuteSync(()=>{process.stdout.write(a.clearLine+a.reset+e+`
2
- `)},"\u8F93\u51FA\u5B8C\u6210\u8FDB\u5EA6")}this.safeExecuteSync(()=>{process.stdout.write(a.showCursor)},"\u6062\u590D\u5149\u6807\u663E\u793A")}addPluginHooks(e){e.config=(t,{command:i})=>(this.isDev=i==="serve",null),e.configResolved=()=>{this.options.enabled&&(this.phase="config",process.stdout.isTTY&&this.safeExecuteSync(()=>{process.stdout.write(a.hideCursor)},"\u9690\u85CF\u5149\u6807"),this.startSpinner())},e.buildStart=()=>{this.options.enabled&&(this.phase="resolve",this.totalModules=0,this.transformedModules=0)},e.resolveId={handler:t=>{this.options.enabled&&(t.includes("node_modules")||t.includes(".virtual")||this.totalModules++)}},e.transform={handler:(t,i)=>{this.options.enabled&&(i.includes("node_modules")||i.includes(".virtual")||(this.phase="transform",this.transformedModules++,this.currentModule=i))}},e.writeBundle=()=>{this.options.enabled&&(this.phase="write",this.update())},e.closeBundle=()=>{this.options.enabled&&this.complete()},e.buildEnd=()=>{this.options.enabled&&(this.isDev||(this.phase="bundle",this.update()))},e.configureServer=()=>{this.options.enabled&&this.isDev&&this.complete()}}destroy(){super.destroy(),this.stopSpinner(),process.stdout.isTTY&&this.safeExecuteSync(()=>{process.stdout.write(a.showCursor)},"\u6062\u590D\u5149\u6807\u663E\u793A")}}const ce=_(v);class he extends E{getDefaultOptions(){return{overwrite:!0,recursive:!0,incremental:!0}}validateOptions(){this.validator.field("sourceDir").required().string().custom(e=>e.trim()!=="","sourceDir \u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32").field("targetDir").required().string().custom(e=>e.trim()!=="","targetDir \u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32").field("overwrite").boolean().field("recursive").boolean().field("incremental").boolean().validate()}getPluginName(){return"copy-file"}getEnforce(){return"post"}async copyFiles(){const{sourceDir:e,targetDir:t,overwrite:i=!0,recursive:u=!0,incremental:o=!0,enabled:s=!0}=this.options;if(!s){this.logger.info(`\u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u6267\u884C\uFF1A\u4ECE ${e} \u590D\u5236\u5230 ${t}`);return}await M(e);const r=await O(e,t,{recursive:u,overwrite:i,incremental:o});this.logger.success(`\u590D\u5236\u6587\u4EF6\u6210\u529F\uFF1A\u4ECE ${e} \u5230 ${t}`,`\u590D\u5236\u4E86 ${r.copiedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8DF3\u8FC7\u4E86 ${r.skippedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8017\u65F6 ${r.executionTime}ms`)}addPluginHooks(e){e.writeBundle=async()=>{await this.safeExecute(()=>this.copyFiles(),"\u590D\u5236\u6587\u4EF6")}}}const pe=_(he);class fe extends E{projectRoot=process.cwd();tabBarPages=new Set;watcher=null;getDefaultOptions(){return{pagesJsonPath:"src/pages.json",outputPath:"src/router.config.ts",outputFormat:"ts",nameStrategy:"camelCase",includeSubPackages:!0,watch:!0,exportTypes:!0,preserveRouteChanges:!0,metaMapping:{navigationBarTitleText:"title",requireAuth:"requireAuth"}}}validateOptions(){if(this.validator.field("pagesJsonPath").string().field("outputPath").string().field("outputFormat").custom(e=>!e||["ts","js"].includes(e),"outputFormat \u5FC5\u987B\u662F ts \u6216 js").field("nameStrategy").custom(e=>!e||["path","camelCase","pascalCase","custom"].includes(e),"nameStrategy \u5FC5\u987B\u662F path, camelCase, pascalCase \u6216 custom").validate(),this.options.nameStrategy==="custom"&&!this.options.customNameGenerator)throw new Error("\u5F53 nameStrategy \u4E3A custom \u65F6\uFF0C\u5FC5\u987B\u63D0\u4F9B customNameGenerator")}getPluginName(){return"generate-router"}generateRouteName(e){switch(this.options.nameStrategy){case"path":return e.replace(/\//g,"_").replace(/^_/,"");case"camelCase":return R(e);case"pascalCase":return ie(e);case"custom":return this.options.customNameGenerator(e);default:return R(e)}}extractMeta(e,t){const i={},u=e.style||{},o=this.options.metaMapping||{};for(const[s,r]of Object.entries(o))u[s]!==void 0&&(i[r]=u[s]);return this.tabBarPages.has(t)&&(i.isTab=!0),i}parsePageToRoute(e,t=""){const i=t?`/${t}/${e.path}`:`/${e.path}`,u=this.generateRouteName(i),o=this.extractMeta(e,i.replace(/^\//,"")),s={path:i,name:u};return Object.keys(o).length>0&&(s.meta=o),s}parsePagesJson(e){const t=[];if(!e.pages||!Array.isArray(e.pages)||e.pages.length===0)return this.logger.warn("pages.json \u4E2D\u6CA1\u6709\u6709\u6548\u7684\u9875\u9762\u914D\u7F6E"),t;if(this.tabBarPages.clear(),e.tabBar?.list)for(const i of e.tabBar.list)this.tabBarPages.add(i.pagePath);for(const i of e.pages)t.push(this.parsePageToRoute(i));if(this.options.includeSubPackages&&e.subPackages){for(const i of e.subPackages)if(i.pages&&Array.isArray(i.pages))for(const u of i.pages)t.push(this.parsePageToRoute(u,i.root))}return t}generateTypeDefinitions(){return!this.options.exportTypes||this.options.outputFormat==="js"?"":`
3
- /**
4
- * \u8DEF\u7531\u5143\u4FE1\u606F
5
- */
6
- export interface RouteMeta {
7
- /** \u9875\u9762\u6807\u9898 */
8
- title?: string
9
- /** \u662F\u5426\u4E3ATabBar\u9875\u9762 */
10
- isTab?: boolean
11
- /** \u662F\u5426\u9700\u8981\u767B\u5F55 */
12
- requireAuth?: boolean
13
- /** \u81EA\u5B9A\u4E49\u6269\u5C55\u5B57\u6BB5 */
14
- [key: string]: unknown
15
- }
16
-
17
- /**
18
- * \u8DEF\u7531\u914D\u7F6E\u9879
19
- */
20
- export interface RouteConfig {
21
- /** \u8DEF\u7531\u8DEF\u5F84 */
22
- path: string
23
- /** \u8DEF\u7531\u540D\u79F0\uFF08\u7528\u4E8E\u547D\u540D\u8DEF\u7531\u5BFC\u822A\uFF09 */
24
- name?: string
25
- /** \u8DEF\u7531\u5143\u4FE1\u606F */
26
- meta?: RouteMeta
27
- }
28
- `}generateFileContent(e){const t=this.generateTypeDefinitions(),i=this.options.outputFormat==="ts",u=JSON.stringify(e,null," ").replace(/"(\w+)":/g,"$1:").replace(/: "([^"]+)"/g,": '$1'");return`${t}
29
- /**
30
- * \u8DEF\u7531\u914D\u7F6E\u5217\u8868
31
- * @description \u7531 pages.json \u81EA\u52A8\u751F\u6210
32
- */
33
- export const routes${i?": RouteConfig[]":""} = ${u}
34
-
35
- export default routes
36
- `}async readPagesJson(){const e=x(this.projectRoot,this.options.pagesJsonPath);if(!S(e))return this.logger.warn(`pages.json \u6587\u4EF6\u4E0D\u5B58\u5728: ${e}`),null;try{const t=await P(e),i=ne(t);return JSON.parse(i)}catch(t){return this.logger.error(`\u89E3\u6790 pages.json \u5931\u8D25: ${t.message}`),null}}extractExistingRoutes(e){const t=new Map,i=e.match(/export const routes[^=]*=\s*(\[[\s\S]*?\](?=\s*\n|\s*$|\s*\/\/))/);if(!i)return t;try{let u=i[1].replace(/(\w+)(?=\s*:)/g,'"$1"').replace(/'([^']*)'/g,'"$1"').replace(/,\s*([\]\}])/g,"$1");const o=JSON.parse(u);for(const s of o)s.path&&t.set(s.path,s)}catch{this.logger.warn("\u89E3\u6790\u73B0\u6709 routes \u914D\u7F6E\u5931\u8D25\uFF0C\u5C06\u5B8C\u5168\u91CD\u65B0\u751F\u6210")}return t}mergeRoutes(e,t){return e.map(i=>{const u=t.get(i.path);if(!u)return i;const o={};return i.meta&&Object.assign(o,i.meta),u.meta&&Object.assign(o,u.meta),{...u,path:i.path,meta:Object.keys(o).length>0?o:void 0}})}async generateRouterConfig(){const e=await this.readPagesJson();if(!e)return;let t=this.parsePagesJson(e);const i=x(this.projectRoot,this.options.outputPath);if(this.options.preserveRouteChanges&&S(i))try{const o=await P(i),s=this.extractExistingRoutes(o);s.size>0&&(t=this.mergeRoutes(t,s),this.logger.info("\u5DF2\u5408\u5E76\u7528\u6237\u5BF9\u8DEF\u7531\u914D\u7F6E\u7684\u4FEE\u6539"))}catch{}const u=this.generateFileContent(t);await L(i,u),this.logger.success(`\u8DEF\u7531\u914D\u7F6E\u6587\u4EF6\u5DF2\u751F\u6210: ${i}`),this.logger.info(`\u5171\u751F\u6210 ${t.length} \u6761\u8DEF\u7531\u914D\u7F6E`)}startWatching(){if(!this.options.watch)return;const e=x(this.projectRoot,this.options.pagesJsonPath);S(e)&&(this.watcher=ae(e,async t=>{t==="change"&&(this.logger.info("\u68C0\u6D4B\u5230 pages.json \u53D8\u5316\uFF0C\u91CD\u65B0\u751F\u6210\u8DEF\u7531\u914D\u7F6E..."),await this.safeExecute(()=>this.generateRouterConfig(),"\u91CD\u65B0\u751F\u6210\u8DEF\u7531\u914D\u7F6E"))}),this.logger.info(`\u6B63\u5728\u76D1\u542C pages.json \u53D8\u5316: ${e}`))}stopWatching(){this.watcher&&(this.watcher.close(),this.watcher=null)}addPluginHooks(e){e.configResolved=async t=>{this.projectRoot=t.root,await this.safeExecute(()=>this.generateRouterConfig(),"\u751F\u6210\u8DEF\u7531\u914D\u7F6E"),t.command==="serve"&&this.startWatching()}}destroy(){super.destroy(),this.stopWatching()}}const ge=_(fe);class me extends E{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").custom(e=>!e||["timestamp","date","datetime","semver","hash","custom"].includes(e),"format \u5FC5\u987B\u662F timestamp, date, datetime, semver, hash \u6216 custom").field("outputType").custom(e=>!e||["file","define","both"].includes(e),"outputType \u5FC5\u987B\u662F file, define \u6216 both").field("hashLength").number().custom(e=>!e||e>0&&e<=32,"hashLength \u5FC5\u987B\u5728 1-32 \u4E4B\u95F4").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 e=ue(this.buildTime),t=oe(this.options.hashLength);let i;switch(this.options.format){case"timestamp":i=`${e.YYYY}${e.MM}${e.DD}${e.HH}${e.mm}${e.ss}`;break;case"date":i=`${e.YYYY}.${e.MM}.${e.DD}`;break;case"datetime":i=`${e.YYYY}.${e.MM}.${e.DD}.${e.HH}${e.mm}${e.ss}`;break;case"semver":i=this.options.semverBase||"1.0.0";break;case"hash":i=t;break;case"custom":i=this.parseCustomFormat({...e,hash:t});break;default:i=e.timestamp}const u=this.options.prefix||"",o=this.options.suffix||"";return`${u}${i}${o}`}parseCustomFormat(e){const t={...e};if(this.options.semverBase){const[i,u,o]=this.options.semverBase.split(".");t.major=i||"1",t.minor=u||"0",t.patch=o||"0"}return se(this.options.customFormat||"",t)}generateVersionInfo(){return{version:this.version,buildTime:this.buildTime.toISOString(),timestamp:this.buildTime.getTime(),format:this.options.format,...this.options.extra}}async writeVersionFile(e){const t=re(e,this.options.outputFile||"version.json"),i=this.generateVersionInfo();await L(t,JSON.stringify(i,null,2)),this.logger.success(`\u7248\u672C\u6587\u4EF6\u5DF2\u751F\u6210: ${t}`)}addPluginHooks(e){e.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")&&(e.config=()=>{this.version||(this.buildTime=new Date,this.version=this.generateVersion());const t=this.options.defineName||"__APP_VERSION__";return this.logger.info(`\u6CE8\u5165\u5168\u5C40\u53D8\u91CF: ${t} = "${this.version}"`),{define:{[t]:JSON.stringify(this.version),[`${t}_INFO`]:JSON.stringify(this.generateVersionInfo())}}}),(this.options.outputType==="file"||this.options.outputType==="both")&&(e.writeBundle=async()=>{this.viteConfig&&await this.safeExecute(async()=>{const t=this.viteConfig.build.outDir;await this.writeVersionFile(t)},"\u5199\u5165\u7248\u672C\u6587\u4EF6")})}}const _e=_(me);function Ee(n){const e=[];if(n.link)return[];if(n.icons&&n.icons.length>0)for(const t of n.icons){const i={rel:t.rel,href:t.href};t.sizes&&(i.sizes=t.sizes),t.type&&(i.type=t.type),e.push({tag:"link",attrs:i,injectTo:"head"})}else if(n.url)e.push({tag:"link",attrs:{rel:"icon",href:n.url},injectTo:"head"});else{const t=n.base||"/",i=t.endsWith("/")?`${t}favicon.ico`:`${t}/favicon.ico`;e.push({tag:"link",attrs:{rel:"icon",href:i},injectTo:"head"})}return e}class Fe extends E{getDefaultOptions(){return{base:"/"}}validateOptions(){this.validator.field("base").string().field("url").string().field("link").string().field("icons").array(),this.options?.copyOptions&&(this.validator.field("copyOptions").object(),new le(this.options.copyOptions).field("sourceDir").required().string().field("targetDir").required().string().field("overwrite").boolean().field("recursive").boolean().validate()),this.validator.validate()}getPluginName(){return"inject-ico"}getIconTagDescriptors(){if(!this.options.enabled)return this.logger.info("\u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u56FE\u6807\u6CE8\u5165"),[];const e=Ee(this.options);return e.length>0&&this.logger.success(`\u6210\u529F\u6CE8\u5165 ${e.length} \u4E2A\u56FE\u6807\u6807\u7B7E\u5230 HTML \u6587\u4EF6`),e}injectCustomLinkTag(e){if(!this.options.enabled||!this.options.link)return e;const t=this.options.link,i=/<\/head>/i,u=e.match(i);if(u&&u.index!==void 0){const o=e.slice(0,u.index)+t+`
37
- `+e.slice(u.index);return this.logger.success("\u6210\u529F\u6CE8\u5165\u81EA\u5B9A\u4E49\u56FE\u6807\u6807\u7B7E\u5230 HTML \u6587\u4EF6"),this.logger.info(` - ${t}`),o}return this.logger.warn("\u672A\u627E\u5230 </head> \u6807\u7B7E\uFF0C\u8DF3\u8FC7\u56FE\u6807\u6CE8\u5165"),e}async copyFiles(){if(!this.options.enabled){this.logger.info("\u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u6587\u4EF6\u590D\u5236");return}const{copyOptions:e}=this.options;if(!e)return;const{sourceDir:t,targetDir:i,overwrite:u=!0,recursive:o=!0}=e;await M(t);const s=await O(t,i,{recursive:o,overwrite:u,incremental:!0});this.logger.success(`\u56FE\u6807\u6587\u4EF6\u590D\u5236\u6210\u529F\uFF1A\u4ECE ${t} \u5230 ${i}`,`\u590D\u5236\u4E86 ${s.copiedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8DF3\u8FC7\u4E86 ${s.skippedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8017\u65F6 ${s.executionTime}ms`)}addPluginHooks(e){e.transformIndexHtml={order:"pre",handler:t=>{if(this.options.link)return this.injectCustomLinkTag(t);const i=this.getIconTagDescriptors();return i.length>0?{html:t,tags:i}:t}},e.writeBundle=async()=>{await this.safeExecute(()=>this.copyFiles(),"\u56FE\u6807\u6587\u4EF6\u590D\u5236")}}}const ye=_(Fe,n=>typeof n=="string"?{base:n}:n||{}),l="__loading-overlay__",f="__loading-hidden__",g="__loading-visible__",I="__loading-top__",j="__loading-center__",U="__loading-bottom__",d="__loading-spinner__",V="__loading-text__",h="__loading-dot__",A="__loading-root__",J="data-loading-text",q="__loading-spin__",X="__loading-dots__",G="__loading-pulse__",Y="__loading-bar__",Ce={center:j,top:I,bottom:U};function be(n){return n.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function $e(n,e="spinner",t){const{overlayColor:i="rgba(255, 255, 255, 0.7)",spinnerColor:u="#4361ee",spinnerSize:o="40px",textColor:s="#333",textSize:r="14px",zIndex:c=9999,pointerEvents:m=!0,backdropBlur:p=!1,backdropBlurAmount:y=4}=n,w=m?"":"pointer-events: none;",D=p?`backdrop-filter: blur(${y}px);-webkit-backdrop-filter: blur(${y}px);`:"",B=ve(e,u,o),T=t?.enabled!==!1,C=t?.duration??200,b=t?.easing??"ease-out",$=T?`transition: opacity ${C}ms ${b}, visibility ${C}ms ${b};`:"";return`
38
- .${l} {
39
- position: fixed;
40
- top: 0;
41
- left: 0;
42
- right: 0;
43
- bottom: 0;
44
- background: ${i};
45
- display: flex;
46
- flex-direction: column;
47
- align-items: center;
48
- z-index: ${c};
49
- ${w}
50
- ${D}
51
- contain: content;
52
- will-change: opacity;
53
- }
54
- .${l}.${I} {
55
- justify-content: flex-start;
56
- padding-top: 60px;
57
- }
58
- .${l}.${j} {
59
- justify-content: center;
60
- }
61
- .${l}.${U} {
62
- justify-content: flex-end;
63
- padding-bottom: 60px;
64
- }
65
- ${B}
66
- .${V} {
67
- margin-top: 12px;
68
- color: ${s};
69
- font-size: ${r};
70
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
71
- user-select: none;
72
- }
73
- .${l}.${f} {
74
- opacity: 0;
75
- visibility: hidden;
76
- ${$}
77
- }
78
- .${l}.${f} .${d},
79
- .${l}.${f} .${h},
80
- .${l}.${f} .${d}::after {
81
- animation-play-state: paused;
82
- }
83
- .${l}.${g} {
84
- opacity: 1;
85
- visibility: visible;
86
- ${$}
87
- }
88
- .${l}.${g} .${d},
89
- .${l}.${g} .${h},
90
- .${l}.${g} .${d}::after {
91
- animation-play-state: running;
92
- }`}function ve(n,e,t){switch(n){case"dots":return`
93
- .${d} {
94
- display: flex;
95
- gap: 6px;
96
- align-items: center;
97
- }
98
- .${d} .${h} {
99
- width: calc(${t} / 4);
100
- height: calc(${t} / 4);
101
- border-radius: 50%;
102
- background: ${e};
103
- animation: ${X} 1.2s ease-in-out infinite;
104
- }
105
- .${d} .${h}:nth-child(2) { animation-delay: 0.15s; }
106
- .${d} .${h}:nth-child(3) { animation-delay: 0.3s; }
107
- @keyframes ${X} {
108
- 0%, 80%, 100% { transform: scale(0.4); opacity: 0.4; }
109
- 40% { transform: scale(1); opacity: 1; }
110
- }`;case"pulse":return`
111
- .${d} {
112
- width: ${t};
113
- height: ${t};
114
- background: ${e};
115
- border-radius: 50%;
116
- animation: ${G} 1.2s ease-in-out infinite;
117
- }
118
- @keyframes ${G} {
119
- 0% { transform: scale(0.3); opacity: 0.3; }
120
- 50% { transform: scale(1); opacity: 1; }
121
- 100% { transform: scale(0.3); opacity: 0.3; }
122
- }`;case"bar":return`
123
- .${d} {
124
- width: calc(${t} * 2.5);
125
- height: calc(${t} / 5);
126
- background: rgba(0, 0, 0, 0.08);
127
- border-radius: calc(${t} / 10);
128
- overflow: hidden;
129
- position: relative;
130
- }
131
- .${d}::after {
132
- content: '';
133
- position: absolute;
134
- top: 0;
135
- left: 0;
136
- height: 100%;
137
- width: 40%;
138
- background: ${e};
139
- border-radius: calc(${t} / 10);
140
- animation: ${Y} 1.2s ease-in-out infinite;
141
- }
142
- @keyframes ${Y} {
143
- 0% { left: -40%; }
144
- 100% { left: 100%; }
145
- }`;default:return`
146
- .${d} {
147
- width: ${t};
148
- height: ${t};
149
- border: 3px solid rgba(0, 0, 0, 0.1);
150
- border-top-color: ${e};
151
- border-radius: 50%;
152
- animation: ${q} 0.8s linear infinite;
153
- }
154
- @keyframes ${q} {
155
- to { transform: rotate(360deg); }
156
- }`}}function we(n){const e=n.position||"center",t=n.defaultText||"\u52A0\u8F7D\u4E2D...",i=n.spinnerType||"spinner",u=Ce[e],o=n.style?.customClass?` ${n.style.customClass}`:"",s=n.style?.customStyle?` style="${be(n.style.customStyle)}"`:"",r=n.defaultVisible?g:f;if(n.customTemplate)return`<div class="${l} ${u} ${r}${o}" id="${A}"${s}>${n.customTemplate}</div>`;const c=De(i);return`<div class="${l} ${u} ${r}${o}" id="${A}"${s}>
157
- ${c}
158
- <div class="${V}" ${J}>${t}</div>
159
- </div>`}function De(n){switch(n){case"dots":return`<div class="${d}"><div class="${h}"></div><div class="${h}"></div><div class="${h}"></div></div>`;default:return`<div class="${d}"></div>`}}function F(n){return n?`function() { try { ${n} } catch(e) { console.error('[injectLoading] callback error:', e); } }`:"function() {}"}function Be(n){return` var _loadingEl = null;
160
- var _textEl = null;
161
- var _styleEl = null;
162
- var _visible = false;
163
- var _destroyed = false;
164
- var _showTimer = null;
165
- var _hideTimer = null;
166
- var _debounceTimer = null;
167
- var _retryTimer = null;
168
- var _showTime = 0;
169
- var _pendingCount = 0;
170
- var _showRetryCount = 0;
171
- var _maxShowRetries = 20;
172
-
173
- // \u914D\u7F6E
174
- var _minDisplayTime = ${JSON.stringify(n.minDisplayTime)};
175
- var _delayShow = ${JSON.stringify(n.delayShow)};
176
- var _debounceHide = ${JSON.stringify(n.debounceHide)};
177
- var _transition = ${JSON.stringify(n.transition)};
178
- var _excludeUrls = ${JSON.stringify(n.excludeUrls.map(e=>({source:e.source,flags:e.flags})))}.map(function(s) { return new RegExp(s.source, s.flags); });
179
- var _includeUrls = ${JSON.stringify(n.includeUrls.map(e=>({source:e.source,flags:e.flags})))}.map(function(s) { return new RegExp(s.source, s.flags); });
180
- var _excludeMethods = ${JSON.stringify(n.excludeMethods)};
181
- var _excludeUrlPrefixes = ${JSON.stringify(n.excludeUrlPrefixes)};
182
-
183
- // \u56DE\u8C03
184
- var _onBeforeShow = ${n.cbBeforeShow};
185
- var _onShow = ${n.cbShow};
186
- var _onBeforeHide = ${n.cbBeforeHide};
187
- var _onHide = ${n.cbHide};
188
- var _onDestroy = ${n.cbDestroy};
189
-
190
- // \u4FDD\u5B58\u539F\u59CB\u65B9\u6CD5\u5F15\u7528\uFF0C\u7528\u4E8E destroy \u65F6\u6062\u590D
191
- var _originalFetch = null;
192
- var _originalXHROpen = null;
193
- var _originalXHRSend = null;`}function Te(n){return` function _findEl() {
194
- if (!_loadingEl) {
195
- _loadingEl = document.getElementById('${A}');
196
- }
197
- if (!_textEl && _loadingEl) {
198
- _textEl = _loadingEl.querySelector('[${J}]');
199
- }
200
- if (!_styleEl) {
201
- _styleEl = document.querySelector('style[data-loading-id="${n}"]');
202
- }
203
- }
204
-
205
- function _shouldFilter(url, method) {
206
- if (!url) return false;
207
- var upperMethod = (method || 'GET').toUpperCase();
208
- for (var i = 0; i < _excludeMethods.length; i++) {
209
- if (upperMethod === _excludeMethods[i].toUpperCase()) return true;
210
- }
211
- for (var i = 0; i < _excludeUrlPrefixes.length; i++) {
212
- if (url.indexOf(_excludeUrlPrefixes[i]) === 0) return true;
213
- }
214
- if (_includeUrls.length > 0) {
215
- var included = false;
216
- for (var i = 0; i < _includeUrls.length; i++) {
217
- _includeUrls[i].lastIndex = 0;
218
- if (_includeUrls[i].test(url)) { included = true; break; }
219
- }
220
- if (!included) return true;
221
- }
222
- for (var i = 0; i < _excludeUrls.length; i++) {
223
- _excludeUrls[i].lastIndex = 0;
224
- if (_excludeUrls[i].test(url)) return true;
225
- }
226
- return false;
227
- }
228
-
229
- function _clearTimers() {
230
- if (_showTimer) { clearTimeout(_showTimer); _showTimer = null; }
231
- if (_hideTimer) { clearTimeout(_hideTimer); _hideTimer = null; }
232
- if (_debounceTimer) { clearTimeout(_debounceTimer); _debounceTimer = null; }
233
- if (_retryTimer) { clearTimeout(_retryTimer); _retryTimer = null; }
234
- }
235
-
236
- function _applyTransition(show) {
237
- if (!_transition.enabled || !_loadingEl) return;
238
- var d = _transition.duration || 200;
239
- var e = _transition.easing || 'ease-out';
240
- _loadingEl.style.transition = 'opacity ' + d + 'ms ' + e + ', visibility ' + d + 'ms ' + e;
241
- }`}function xe(){return` function _applyHide() {
242
- if (!_loadingEl) return;
243
- _loadingEl.classList.remove('${g}');
244
- _loadingEl.classList.add('${f}');
245
- _applyTransition(false);
246
- _visible = false;
247
- _showTime = 0;
248
- _onHide();
249
- }
250
-
251
- function _doShow(text) {
252
- if (_destroyed) return;
253
- _findEl();
254
- if (!_loadingEl) {
255
- if (++_showRetryCount > _maxShowRetries) return;
256
- _retryTimer = setTimeout(function() { _retryTimer = null; _doShow(text); }, 50);
257
- return;
258
- }
259
- _showRetryCount = 0;
260
-
261
- var result = _onBeforeShow();
262
- if (result === false) return;
263
-
264
- if (_textEl && text) _textEl.textContent = text;
265
- _loadingEl.classList.remove('${f}');
266
- _loadingEl.classList.add('${g}');
267
- _applyTransition(true);
268
- _visible = true;
269
- _showTime = Date.now();
270
- _onShow();
271
- }
272
-
273
- function _doHide(force) {
274
- if (_destroyed) return;
275
- if (!_visible && !force) return;
276
- _findEl();
277
- if (!_loadingEl) return;
278
-
279
- if (!force) {
280
- var result = _onBeforeHide();
281
- if (result === false) return;
282
- }
283
-
284
- if (!force && _minDisplayTime.enabled && _showTime > 0) {
285
- var elapsed = Date.now() - _showTime;
286
- var remaining = _minDisplayTime.duration - elapsed;
287
- if (remaining > 0) {
288
- if (_hideTimer) clearTimeout(_hideTimer);
289
- _hideTimer = setTimeout(function() { _hideTimer = null; _doHide(true); }, remaining);
290
- return;
291
- }
292
- }
293
-
294
- if (_debounceHide.enabled && !force) {
295
- if (_debounceTimer) clearTimeout(_debounceTimer);
296
- _debounceTimer = setTimeout(function() { _debounceTimer = null; _applyHide(); }, _debounceHide.duration);
297
- return;
298
- }
299
-
300
- _applyHide();
301
- }
302
-
303
- function _restoreInterceptors() {
304
- if (_originalFetch && typeof window !== 'undefined' && window.fetch) {
305
- window.fetch = _originalFetch;
306
- _originalFetch = null;
307
- }
308
- if (_originalXHROpen && typeof window !== 'undefined' && window.XMLHttpRequest) {
309
- XMLHttpRequest.prototype.open = _originalXHROpen;
310
- XMLHttpRequest.prototype.send = _originalXHRSend;
311
- _originalXHROpen = null;
312
- _originalXHRSend = null;
313
- }
314
- }`}function Se(){return` show: function(text) {
315
- if (_destroyed) return;
316
- _clearTimers();
317
- _showTime = 0;
318
- _showRetryCount = 0;
319
- if (_delayShow.enabled && _delayShow.duration > 0) {
320
- _showTimer = setTimeout(function() { _showTimer = null; _doShow(text); }, _delayShow.duration);
321
- } else {
322
- _doShow(text);
323
- }
324
- },
325
- hide: function() {
326
- if (_destroyed) return;
327
- if (_showTimer) { clearTimeout(_showTimer); _showTimer = null; }
328
- _doHide(false);
329
- },
330
- forceHide: function() {
331
- if (_destroyed) return;
332
- _clearTimers();
333
- _doHide(true);
334
- },
335
- toggle: function(text) {
336
- if (_destroyed) return;
337
- if (_visible) {
338
- this.hide();
339
- } else {
340
- this.show(text);
341
- }
342
- },
343
- enablePointerEvents: function() {
344
- if (_destroyed) return;
345
- _findEl();
346
- if (_loadingEl) _loadingEl.style.pointerEvents = 'auto';
347
- },
348
- disablePointerEvents: function() {
349
- if (_destroyed) return;
350
- _findEl();
351
- if (_loadingEl) _loadingEl.style.pointerEvents = 'none';
352
- },
353
- togglePointerEvents: function() {
354
- if (_destroyed) return;
355
- _findEl();
356
- if (!_loadingEl) return;
357
- if (_loadingEl.style.pointerEvents === 'none') {
358
- this.enablePointerEvents();
359
- } else {
360
- this.disablePointerEvents();
361
- }
362
- },
363
- updateText: function(text) {
364
- if (_destroyed) return;
365
- _findEl();
366
- if (_textEl) _textEl.textContent = text;
367
- },
368
- isVisible: function() {
369
- return _visible && !_destroyed;
370
- },
371
- isPointerEventsEnabled: function() {
372
- if (_destroyed) return false;
373
- _findEl();
374
- if (!_loadingEl) return false;
375
- return _loadingEl.style.pointerEvents !== 'none';
376
- },
377
- getPendingCount: function() {
378
- return _pendingCount;
379
- },
380
- destroy: function() {
381
- if (_destroyed) return;
382
- _destroyed = true;
383
- _clearTimers();
384
- _findEl();
385
- if (_loadingEl && _loadingEl.parentNode) {
386
- _loadingEl.parentNode.removeChild(_loadingEl);
387
- }
388
- if (_styleEl && _styleEl.parentNode) {
389
- _styleEl.parentNode.removeChild(_styleEl);
390
- }
391
- _loadingEl = null;
392
- _textEl = null;
393
- _styleEl = null;
394
- _visible = false;
395
- _showTime = 0;
396
- _pendingCount = 0;
397
- _restoreInterceptors();
398
- _onDestroy();
399
- },
400
- _requestStart: function(url, method) {
401
- if (_destroyed) return;
402
- if (_shouldFilter(url, method)) return;
403
- _pendingCount++;
404
- if (_pendingCount === 1) this.show();
405
- },
406
- _requestEnd: function(url, method) {
407
- if (_destroyed) return;
408
- if (_shouldFilter(url, method)) return;
409
- _pendingCount = Math.max(0, _pendingCount - 1);
410
- if (_pendingCount === 0) this.hide();
411
- }`}function Ae(n){let e="";return(n==="fetch"||n==="all")&&(e+=` // \u81EA\u52A8\u62E6\u622A fetch
412
- if (typeof window !== 'undefined' && window.fetch) {
413
- _originalFetch = window.fetch;
414
- window.fetch = function(input, init) {
415
- var url = typeof input === 'string' ? input : (input instanceof URL ? input.href : (input && input.url ? input.url : ''));
416
- var method = (init && init.method) || (input && input.method) || 'GET';
417
- manager._requestStart(url, method);
418
- return _originalFetch.apply(this, arguments).then(
419
- function(response) { manager._requestEnd(url, method); return response; },
420
- function(error) { manager._requestEnd(url, method); throw error; }
421
- );
422
- };
423
- }
424
- `),(n==="xhr"||n==="all")&&(e+=` // \u81EA\u52A8\u62E6\u622A XMLHttpRequest
425
- if (typeof window !== 'undefined' && window.XMLHttpRequest) {
426
- _originalXHROpen = XMLHttpRequest.prototype.open;
427
- _originalXHRSend = XMLHttpRequest.prototype.send;
428
- XMLHttpRequest.prototype.open = function(method, url) {
429
- this.__loadingUrl = url || '';
430
- this.__loadingMethod = method || 'GET';
431
- return _originalXHROpen.apply(this, arguments);
432
- };
433
- XMLHttpRequest.prototype.send = function() {
434
- var self = this;
435
- manager._requestStart(self.__loadingUrl, self.__loadingMethod);
436
- self.addEventListener('loadend', function() {
437
- manager._requestEnd(self.__loadingUrl, self.__loadingMethod);
438
- });
439
- return _originalXHRSend.apply(this, arguments);
440
- };
441
- }
442
- `),e.trimEnd()}function He(n,e,t){let i="";return i+=` // defaultVisible: \u540C\u6B65\u521D\u59CB\u53EF\u89C1\u72B6\u6001
443
- var _defaultVisible = ${JSON.stringify(n)};
444
- if (_defaultVisible) {
445
- _visible = true;
446
- _showTime = Date.now();
447
- }
448
- `,n&&e!=="manual"&&(i+=`
449
- // autoHideOn: \u81EA\u52A8\u9690\u85CF\u65F6\u673A
450
- var _autoHideOn = '${e}';
451
- function _autoHideHandler() {
452
- manager.hide();
453
- }
454
- if (_autoHideOn === 'load') {
455
- if (document.readyState === 'complete') {
456
- _autoHideHandler();
457
- } else {
458
- window.addEventListener('load', _autoHideHandler);
459
- }
460
- } else {
461
- if (document.readyState !== 'loading') {
462
- _autoHideHandler();
463
- } else {
464
- document.addEventListener('DOMContentLoaded', _autoHideHandler);
465
- }
466
- }
467
- `),i+=`
468
- // \u66B4\u9732\u5230\u5168\u5C40
469
- window['${t}'] = manager;`,i}function Me(n){const e=n.globalName||"__LOADING_MANAGER__",t=n.minDisplayTime||{enabled:!0,duration:300},i=n.delayShow||{enabled:!0,duration:200},u=n.debounceHide||{enabled:!1,duration:100},o=n.transition||{enabled:!0,duration:200,easing:"ease-out"},s=n.autoBind||"none",r=n.requestFilter||{},c=n.defaultVisible||!1,m=n.autoHideOn||"DOMContentLoaded",p=n.callbacks||{},y=r.excludeUrls||[],w=r.includeUrls||[],D=r.excludeMethods||[],B=r.excludeUrlPrefixes||[],T=F(p.onBeforeShow),C=F(p.onShow),b=F(p.onBeforeHide),$=F(p.onHide),z=F(p.onDestroy),W=Be({minDisplayTime:t,delayShow:i,debounceHide:u,transition:o,excludeUrls:y,includeUrls:w,excludeMethods:D,excludeUrlPrefixes:B,cbBeforeShow:T,cbShow:C,cbBeforeHide:b,cbHide:$,cbDestroy:z}),Z=Te(e),K=xe(),Q=Se(),ee=Ae(s),te=He(c,m,e);return`(function() {
470
- 'use strict';
471
-
472
- // SSR \u73AF\u5883\u68C0\u6D4B
473
- if (typeof window === 'undefined' || typeof document === 'undefined') return;
474
-
475
- ${W}
476
-
477
- ${Z}
478
-
479
- ${K}
480
-
481
- var manager = {
482
- ${Q}
483
- };
484
-
485
- ${ee}
486
-
487
- ${te}
488
- })();`}function Oe(n){if(!n)return;const{zIndex:e,pointerEvents:t,backdropBlurAmount:i}=n;if(e!==void 0&&(typeof e!="number"||e<0))throw new Error("style.zIndex \u5FC5\u987B\u662F\u975E\u8D1F\u6570");if(t!==void 0&&typeof t!="boolean")throw new Error("style.pointerEvents \u5FC5\u987B\u662F\u5E03\u5C14\u503C");if(i!==void 0&&(typeof i!="number"||i<0))throw new Error("style.backdropBlurAmount \u5FC5\u987B\u662F\u975E\u8D1F\u6570")}function H(n,e){if(n?.duration!==void 0&&(typeof n.duration!="number"||n.duration<0))throw new Error(e)}function Re(n){if(!n)return;const{duration:e,easing:t}=n;if(e!==void 0&&(typeof e!="number"||e<0))throw new Error("transition.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570");if(t!==void 0&&typeof t!="string")throw new Error("transition.easing \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u7C7B\u578B")}function Pe(n){if(!n)return;const e=["onBeforeShow","onShow","onBeforeHide","onHide","onDestroy"];for(const t of e){if(n[t]!==void 0&&typeof n[t]!="string")throw new Error(`callbacks.${t} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u7C7B\u578B`);if(n[t]&&/<script\b/i.test(n[t]))throw new Error(`callbacks.${t} \u4E0D\u5141\u8BB8\u5305\u542B <script> \u6807\u7B7E`)}}function Le(n){if(n&&/<script\b/i.test(n))throw new Error("customTemplate \u4E0D\u5141\u8BB8\u5305\u542B <script> \u6807\u7B7E\uFF0C\u8BF7\u4F7F\u7528 callbacks \u914D\u7F6E\u56DE\u8C03\u903B\u8F91")}function Ne(n){if(n){if(!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(n))throw new Error(`globalName "${n}" \u4E0D\u662F\u5408\u6CD5\u7684 JavaScript \u6807\u8BC6\u7B26\uFF0C\u5FC5\u987B\u4EE5\u5B57\u6BCD\u3001\u4E0B\u5212\u7EBF\u6216\u7F8E\u5143\u7B26\u5F00\u5934\uFF0C\u4EC5\u5305\u542B\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u4E0B\u5212\u7EBF\u548C\u7F8E\u5143\u7B26`);if(["__proto__","constructor","prototype"].includes(n))throw new Error(`globalName "${n}" \u662F JavaScript \u5185\u7F6E\u5C5E\u6027\uFF0C\u53EF\u80FD\u5BFC\u81F4\u539F\u578B\u6C61\u67D3\uFF0C\u8BF7\u4F7F\u7528\u5176\u4ED6\u540D\u79F0`)}}function ke(n){return n===""?"defaultText \u4E3A\u7A7A\u5B57\u7B26\u4E32\uFF0Cloading \u5C06\u4E0D\u663E\u793A\u6587\u672C\u5185\u5BB9":null}function Ie(n,e){return!n&&e?"autoHideOn \u4EC5\u5728 defaultVisible \u4E3A true \u65F6\u751F\u6548\uFF0C\u5F53\u524D defaultVisible \u4E3A false\uFF0CautoHideOn \u914D\u7F6E\u5C06\u88AB\u5FFD\u7565":null}class je extends E{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").custom(i=>!i||["center","top","bottom"].includes(i),"position \u5FC5\u987B\u662F center, top \u6216 bottom").field("defaultText").string().field("spinnerType").custom(i=>!i||["spinner","dots","pulse","bar"].includes(i),"spinnerType \u5FC5\u987B\u662F spinner, dots, pulse \u6216 bar").field("autoBind").custom(i=>!i||["fetch","xhr","all","none"].includes(i),"autoBind \u5FC5\u987B\u662F fetch, xhr, all \u6216 none").field("globalName").string().field("customTemplate").string().field("defaultVisible").boolean().field("autoHideOn").custom(i=>!i||["DOMContentLoaded","load","manual"].includes(i),"autoHideOn \u5FC5\u987B\u662F DOMContentLoaded, load \u6216 manual").validate(),Le(this.options.customTemplate);const e=ke(this.options.defaultText);e&&this.logger.warn(e),Ne(this.options.globalName),Oe(this.options.style),H(this.options.minDisplayTime,"minDisplayTime.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),H(this.options.delayShow,"delayShow.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),H(this.options.debounceHide,"debounceHide.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),Re(this.options.transition),Pe(this.options.callbacks);const t=Ie(this.options.defaultVisible,this.options.autoHideOn);t&&this.logger.warn(t)}getPluginName(){return"inject-loading"}generateLoadingManager(e){return Me(e)}generateHeadInjectCode(){const{css:e,html:t}=this.getCachedAssets();return`<!-- inject-loading: head start -->
489
- <style data-loading-style data-loading-id="${this.options.globalName||"__LOADING_MANAGER__"}">${e}</style>
490
- ${t}
491
- <!-- inject-loading: head end -->`}generateBodyInjectCode(e){const t=this.generateLoadingManager(this.options);if(e)return`<!-- inject-loading: body start -->
492
- <script>${t}<\/script>
493
- <!-- inject-loading: body end -->`;const{css:i,html:u}=this.getCachedAssets();return`<!-- inject-loading: start -->
494
- <script>
495
- (function() {
496
- // SSR \u73AF\u5883\u68C0\u6D4B
497
- if (typeof window === 'undefined' || typeof document === 'undefined') return;
498
-
499
- // \u6CE8\u5165 CSS
500
- var style = document.createElement('style');
501
- style.setAttribute('data-loading-style', '');
502
- style.setAttribute('data-loading-id', '${this.options.globalName||"__LOADING_MANAGER__"}');
503
- style.textContent = ${JSON.stringify(i)};
504
- document.head.appendChild(style);
505
-
506
- // \u6CE8\u5165 HTML\uFF08\u7B49\u5F85 body \u53EF\u7528\u65F6\u6267\u884C\uFF09
507
- function injectHTML() {
508
- var div = document.createElement('div');
509
- div.innerHTML = ${JSON.stringify(u)};
510
- while (div.firstChild) {
511
- document.body.appendChild(div.firstChild);
512
- }
513
- }
514
-
515
- if (document.body) {
516
- injectHTML();
517
- } else {
518
- document.addEventListener('DOMContentLoaded', injectHTML);
519
- }
520
- })();
521
- ${t}
522
- <\/script>
523
- <!-- inject-loading: end -->`}_cachedAssets=null;getCachedAssets(){if(!this._cachedAssets){const e=this.options.style||{},t=this.options.spinnerType||"spinner",i=this.options.transition;this._cachedAssets={css:$e(e,t,i),html:we(this.options)}}return this._cachedAssets}addPluginHooks(e){const t=this.options.defaultVisible||!1,i=t?this.generateHeadInjectCode():"",u=this.generateBodyInjectCode(t);e.transformIndexHtml={order:"post",handler:o=>{let s=o;if(i){const m=/<\/head>/i;m.test(s)?s=s.replace(m,`${i}
524
- </head>`):this.logger.warn("\u672A\u627E\u5230 </head> \u6807\u7B7E\uFF0CdefaultVisible \u7684\u767D\u5C4F loading \u5C06\u65E0\u6CD5\u751F\u6548")}const r=/<\/body>/i;if(r.test(s))return s=s.replace(r,`${u}
525
- </body>`),this.logger.success("\u6210\u529F\u6CE8\u5165\u5168\u5C40 Loading \u72B6\u6001\u7BA1\u7406\u4EE3\u7801\u5230 HTML \u6587\u4EF6"),s;const c=/<\/html>/i;return c.test(s)?(s=s.replace(c,`${u}
526
- </html>`),this.logger.success("\u6210\u529F\u6CE8\u5165\u5168\u5C40 Loading \u72B6\u6001\u7BA1\u7406\u4EE3\u7801\u5230 HTML \u6587\u4EF6"),s):(this.logger.warn("\u672A\u627E\u5230 </body> \u6216 </html> \u6807\u7B7E\uFF0CLoading \u4EE3\u7801\u8FFD\u52A0\u5230\u6587\u4EF6\u672B\u5C3E"),s+u)}}}}const Ue=_(je);export{_e as a,ce as b,pe as c,Ue as d,ge as g,ye as i};
@@ -1 +0,0 @@
1
- "use strict";const o=require("fs"),u=require("path"),crypto=require("crypto");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const o__default=_interopDefaultCompat(o),u__default=_interopDefaultCompat(u),S=10;async function checkSourceExists(e){try{await o__default.promises.access(e,o__default.constants.F_OK)}catch(t){const r=t;throw r.code==="ENOENT"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${e}`):r.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6E90\u6587\u4EF6 - ${e}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u68C0\u67E5\u6E90\u6587\u4EF6\u65F6\u51FA\u9519 - ${e}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}async function ensureTargetDir(e){try{await o__default.promises.mkdir(e,{recursive:!0})}catch(t){const r=t;throw r.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u521B\u5EFA\u76EE\u6807\u76EE\u5F55 - ${e}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u521B\u5EFA\u76EE\u6807\u76EE\u5F55\u65F6\u51FA\u9519 - ${e}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}async function readDirRecursive(e,t){const r=await o__default.promises.readdir(e,{withFileTypes:!0}),s=[];for(const n of r){const i=u__default.join(e,n.name),l=n.isFile(),F=n.isDirectory();if(s.push({path:i,isFile:l,isDirectory:F}),F&&t){const p=await readDirRecursive(i,t);s.push(...p)}}return s}async function shouldUpdateFile(e,t){try{const[r,s]=await Promise.all([o__default.promises.stat(e),o__default.promises.stat(t)]);return r.mtimeMs>s.mtimeMs||r.size!==s.size}catch{return!0}}async function fileExists(e){try{return await o__default.promises.access(e,o__default.constants.F_OK),!0}catch{return!1}}async function runWithConcurrency(e,t,r){const s=[];let n=0;async function i(){for(;n<e.length;){const F=n++,p=await t(e[F]);s[F]=p}}const l=Array(Math.min(r,e.length)).fill(null).map(()=>i());return await Promise.all(l),s}async function copySourceToTarget(e,t,r){const s=Date.now(),{recursive:n,overwrite:i,incremental:l=!1,parallelLimit:F=S}=r;let p=0,f=0,d=0;if((await o__default.promises.stat(e)).isDirectory()){await ensureTargetDir(t);const c=await readDirRecursive(e,n),D=c.filter(a=>a.isFile);d=c.filter(a=>a.isDirectory).length;const C=new Set;for(const a of D){const w=u__default.relative(e,a.path),E=u__default.dirname(u__default.join(t,w));C.add(E)}await Promise.all([...C].map(a=>ensureTargetDir(a)));const y=await runWithConcurrency(D,async a=>{const w=u__default.relative(e,a.path),E=u__default.join(t,w);let m=i;return m||(m=!await fileExists(E)),l&&m&&(m=await shouldUpdateFile(a.path,E)),m?(await o__default.promises.copyFile(a.path,E),{copied:!0,skipped:!1}):{copied:!1,skipped:!0}},F);for(const a of y)a.copied&&p++,a.skipped&&f++}else{await ensureTargetDir(u__default.dirname(t));let c=i;c||(c=!await fileExists(t)),l&&c&&(c=await shouldUpdateFile(e,t)),c?(await o__default.promises.copyFile(e,t),p++):f++}const h=Date.now()-s;return{copiedFiles:p,skippedFiles:f,copiedDirs:d,executionTime:h}}async function writeFileContent(e,t){try{await o__default.promises.writeFile(e,t,"utf-8")}catch(r){const s=r;throw s.code==="EACCES"?new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u5199\u5165\u6587\u4EF6 - ${e}`):new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u5199\u5165\u6587\u4EF6\u65F6\u51FA\u9519 - ${e}\uFF0C\u9519\u8BEF\uFF1A${s.message}`)}}async function readFileContent(e){try{return await o__default.promises.readFile(e,"utf-8")}catch(t){const r=t;throw r.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${e}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${e}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}function readFileSync(e){try{return o__default.readFileSync(e,"utf-8")}catch(t){const r=t;throw r.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${e}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${e}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}function padNumber(e,t=2){return e.toString().padStart(t,"0")}function generateRandomHash(e=8){const t=Math.max(1,Math.min(64,e));return crypto.randomBytes(Math.ceil(t/2)).toString("hex").slice(0,t)}function getDateFormatParams(e=new Date){return{YYYY:e.getFullYear().toString(),YY:e.getFullYear().toString().slice(-2),MM:padNumber(e.getMonth()+1),DD:padNumber(e.getDate()),HH:padNumber(e.getHours()),mm:padNumber(e.getMinutes()),ss:padNumber(e.getSeconds()),SSS:padNumber(e.getMilliseconds(),3),timestamp:e.getTime().toString()}}function formatDate(e,t){const r=getDateFormatParams(e);let s=t;for(const[n,i]of Object.entries(r))s=s.replace(new RegExp(`\\{${n}\\}`,"g"),i);return s}function parseTemplate(e,t){let r=e;for(const[s,n]of Object.entries(t))r=r.replace(new RegExp(`\\{${s}\\}`,"g"),n);return r}function toCamelCase(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map((r,s)=>s===0?r.toLowerCase():r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function toPascalCase(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function stripJsonComments(e){return e.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}exports.checkSourceExists=checkSourceExists,exports.copySourceToTarget=copySourceToTarget,exports.ensureTargetDir=ensureTargetDir,exports.fileExists=fileExists,exports.formatDate=formatDate,exports.generateRandomHash=generateRandomHash,exports.getDateFormatParams=getDateFormatParams,exports.padNumber=padNumber,exports.parseTemplate=parseTemplate,exports.readDirRecursive=readDirRecursive,exports.readFileContent=readFileContent,exports.readFileSync=readFileSync,exports.runWithConcurrency=runWithConcurrency,exports.shouldUpdateFile=shouldUpdateFile,exports.stripJsonComments=stripJsonComments,exports.toCamelCase=toCamelCase,exports.toPascalCase=toPascalCase,exports.writeFileContent=writeFileContent;
@@ -1 +0,0 @@
1
- import s from"fs";import l from"path";import{randomBytes as j}from"crypto";const T=10;async function Y(u){try{await s.promises.access(u,s.constants.F_OK)}catch(t){const e=t;throw e.code==="ENOENT"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${u}`):e.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6E90\u6587\u4EF6 - ${u}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u68C0\u67E5\u6E90\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function f(u){try{await s.promises.mkdir(u,{recursive:!0})}catch(t){const e=t;throw e.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u521B\u5EFA\u76EE\u6807\u76EE\u5F55 - ${u}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u521B\u5EFA\u76EE\u6807\u76EE\u5F55\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function h(u,t){const e=await s.promises.readdir(u,{withFileTypes:!0}),r=[];for(const n of e){const i=l.join(u,n.name),p=n.isFile(),c=n.isDirectory();if(r.push({path:i,isFile:p,isDirectory:c}),c&&t){const F=await h(i,t);r.push(...F)}}return r}async function A(u,t){try{const[e,r]=await Promise.all([s.promises.stat(u),s.promises.stat(t)]);return e.mtimeMs>r.mtimeMs||e.size!==r.size}catch{return!0}}async function g(u){try{return await s.promises.access(u,s.constants.F_OK),!0}catch{return!1}}async function S(u,t,e){const r=[];let n=0;async function i(){for(;n<u.length;){const c=n++,F=await t(u[c]);r[c]=F}}const p=Array(Math.min(e,u.length)).fill(null).map(()=>i());return await Promise.all(p),r}async function k(u,t,e){const r=Date.now(),{recursive:n,overwrite:i,incremental:p=!1,parallelLimit:c=T}=e;let F=0,D=0,C=0;if((await s.promises.stat(u)).isDirectory()){await f(t);const o=await h(u,n),y=o.filter(a=>a.isFile);C=o.filter(a=>a.isDirectory).length;const B=new Set;for(const a of y){const d=l.relative(u,a.path),m=l.dirname(l.join(t,d));B.add(m)}await Promise.all([...B].map(a=>f(a)));const x=await S(y,async a=>{const d=l.relative(u,a.path),m=l.join(t,d);let w=i;return w||(w=!await g(m)),p&&w&&(w=await A(a.path,m)),w?(await s.promises.copyFile(a.path,m),{copied:!0,skipped:!1}):{copied:!1,skipped:!0}},c);for(const a of x)a.copied&&F++,a.skipped&&D++}else{await f(l.dirname(t));let o=i;o||(o=!await g(t)),p&&o&&(o=await A(u,t)),o?(await s.promises.copyFile(u,t),F++):D++}const M=Date.now()-r;return{copiedFiles:F,skippedFiles:D,copiedDirs:C,executionTime:M}}async function v(u,t){try{await s.promises.writeFile(u,t,"utf-8")}catch(e){const r=e;throw r.code==="EACCES"?new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u5199\u5165\u6587\u4EF6 - ${u}`):new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u5199\u5165\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}async function O(u){try{return await s.promises.readFile(u,"utf-8")}catch(t){const e=t;throw e.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${u}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}function P(u){try{return s.readFileSync(u,"utf-8")}catch(t){const e=t;throw e.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${u}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}function E(u,t=2){return u.toString().padStart(t,"0")}function b(u=8){const t=Math.max(1,Math.min(64,u));return j(Math.ceil(t/2)).toString("hex").slice(0,t)}function $(u=new Date){return{YYYY:u.getFullYear().toString(),YY:u.getFullYear().toString().slice(-2),MM:E(u.getMonth()+1),DD:E(u.getDate()),HH:E(u.getHours()),mm:E(u.getMinutes()),ss:E(u.getSeconds()),SSS:E(u.getMilliseconds(),3),timestamp:u.getTime().toString()}}function H(u,t){const e=$(u);let r=t;for(const[n,i]of Object.entries(e))r=r.replace(new RegExp(`\\{${n}\\}`,"g"),i);return r}function L(u,t){let e=u;for(const[r,n]of Object.entries(t))e=e.replace(new RegExp(`\\{${r}\\}`,"g"),n);return e}function R(u,t=/[/-]/){return u.replace(/^\/+/,"").split(t).filter(Boolean).map((e,r)=>r===0?e.toLowerCase():e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join("")}function N(u,t=/[/-]/){return u.replace(/^\/+/,"").split(t).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join("")}function U(u){return u.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}export{k as a,H as b,Y as c,$ as d,f as e,g as f,b as g,L as h,O as i,P as j,S as k,U as l,N as m,E as p,h as r,A as s,R as t,v as w};
@@ -1 +0,0 @@
1
- "use strict";const logger_index=require("../logger/index.cjs");require("fs"),require("path"),require("crypto");const validation=require("./vite-plugin.IGZeStMa.cjs");class BasePlugin{options;logger;validator;viteConfig=null;constructor(e,r){this.options=this.mergeOptions(e),this.logger=this.initLogger(r),this.validator=new validation.Validator(this.options),this.safeExecuteSync(()=>this.validateOptions(),"\u63D2\u4EF6\u914D\u7F6E\u9A8C\u8BC1")}getDefaultOptions(){return{}}mergeOptions(e){const r={enabled:!0,verbose:!0,errorStrategy:"throw"},t=this.getDefaultOptions();return validation.deepMerge(r,t,e)}initLogger(e){return logger_index.Logger.create({name:this.getPluginName(),enabled:this.options.verbose,...e}).createPluginLogger(this.getPluginName())}validateOptions(){}getEnforce(){}onConfigResolved(e){this.viteConfig=e,this.logger.info("\u914D\u7F6E\u89E3\u6790\u5B8C\u6210\uFF0C\u63D2\u4EF6\u5DF2\u521D\u59CB\u5316")}destroy(){logger_index.Logger.unregister(this.getPluginName())}safeExecuteSync(e,r){try{return e()}catch(t){return this.handleError(t,r)}}async safeExecute(e,r){try{return await e()}catch(t){return this.handleError(t,r)}}handleError(e,r){let t=`${r}: `;switch(e instanceof Error?t+=e.message:typeof e=="string"?t+=e:t+=String(e),this.options.errorStrategy){case"throw":throw this.logger.error(t),e;case"log":case"ignore":this.logger.error(t);return;default:throw this.logger.error(t),e}}toPlugin(){const e={name:this.getPluginName(),enforce:this.getEnforce()};this.addPluginHooks(e);const r=e.configResolved;e.configResolved=o=>{this.options.enabled&&(this.onConfigResolved(o),typeof r=="function"&&r(o))};const t=this,n=e.closeBundle;return e.closeBundle=function(){typeof n=="function"&&n.call(this),t.destroy()},e}}function createPluginFactory(i,e){return r=>{const t=e?e(r):r,n=new i(t),o=n.toPlugin();return o.pluginInstance=n,o}}exports.BasePlugin=BasePlugin,exports.createPluginFactory=createPluginFactory;