@meng-xi/vite-plugin 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/README-en.md +34 -20
  2. package/README.md +33 -19
  3. package/dist/common/format/index.cjs +1 -1
  4. package/dist/common/format/index.d.cts +19 -114
  5. package/dist/common/format/index.d.mts +19 -114
  6. package/dist/common/format/index.d.ts +19 -114
  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 -89
  10. package/dist/common/fs/index.d.mts +36 -89
  11. package/dist/common/fs/index.d.ts +36 -89
  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 +12 -307
  15. package/dist/common/html/index.d.mts +12 -307
  16. package/dist/common/html/index.d.ts +12 -307
  17. package/dist/common/html/index.mjs +2 -2
  18. package/dist/common/index.cjs +1 -1
  19. package/dist/common/index.d.cts +7 -11
  20. package/dist/common/index.d.mts +7 -11
  21. package/dist/common/index.d.ts +7 -11
  22. package/dist/common/index.mjs +1 -1
  23. package/dist/common/script/index.cjs +1 -1
  24. package/dist/common/script/index.d.cts +1 -44
  25. package/dist/common/script/index.d.mts +1 -44
  26. package/dist/common/script/index.d.ts +1 -44
  27. package/dist/common/script/index.mjs +1 -1
  28. package/dist/common/ui/index.cjs +1 -1
  29. package/dist/common/ui/index.d.cts +1 -111
  30. package/dist/common/ui/index.d.mts +1 -111
  31. package/dist/common/ui/index.d.ts +1 -111
  32. package/dist/common/ui/index.mjs +1 -1
  33. package/dist/common/validation/index.cjs +1 -1
  34. package/dist/common/validation/index.d.cts +2 -80
  35. package/dist/common/validation/index.d.mts +2 -80
  36. package/dist/common/validation/index.d.ts +2 -80
  37. package/dist/common/validation/index.mjs +1 -1
  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 +10 -12
  45. package/dist/index.d.mts +10 -12
  46. package/dist/index.d.ts +10 -12
  47. package/dist/index.mjs +1 -1
  48. package/dist/logger/index.d.cts +92 -1
  49. package/dist/logger/index.d.mts +92 -1
  50. package/dist/logger/index.d.ts +92 -1
  51. package/dist/plugins/autoImport/index.cjs +19 -0
  52. package/dist/plugins/autoImport/index.d.cts +291 -0
  53. package/dist/plugins/autoImport/index.d.mts +291 -0
  54. package/dist/plugins/autoImport/index.d.ts +291 -0
  55. package/dist/plugins/autoImport/index.mjs +19 -0
  56. package/dist/plugins/buildProgress/index.cjs +1 -1
  57. package/dist/plugins/buildProgress/index.d.cts +1 -1
  58. package/dist/plugins/buildProgress/index.d.mts +1 -1
  59. package/dist/plugins/buildProgress/index.d.ts +1 -1
  60. package/dist/plugins/buildProgress/index.mjs +2 -2
  61. package/dist/plugins/bundleAnalyzer/index.cjs +21 -21
  62. package/dist/plugins/bundleAnalyzer/index.d.cts +1 -1
  63. package/dist/plugins/bundleAnalyzer/index.d.mts +1 -1
  64. package/dist/plugins/bundleAnalyzer/index.d.ts +1 -1
  65. package/dist/plugins/bundleAnalyzer/index.mjs +18 -18
  66. package/dist/plugins/compressAssets/index.cjs +1 -1
  67. package/dist/plugins/compressAssets/index.d.cts +1 -1
  68. package/dist/plugins/compressAssets/index.d.mts +1 -1
  69. package/dist/plugins/compressAssets/index.d.ts +1 -1
  70. package/dist/plugins/compressAssets/index.mjs +1 -1
  71. package/dist/plugins/copyFile/index.cjs +1 -1
  72. package/dist/plugins/copyFile/index.d.cts +1 -1
  73. package/dist/plugins/copyFile/index.d.mts +1 -1
  74. package/dist/plugins/copyFile/index.d.ts +1 -1
  75. package/dist/plugins/copyFile/index.mjs +1 -1
  76. package/dist/plugins/envGuard/index.cjs +11 -11
  77. package/dist/plugins/envGuard/index.d.cts +101 -2
  78. package/dist/plugins/envGuard/index.d.mts +101 -2
  79. package/dist/plugins/envGuard/index.d.ts +101 -2
  80. package/dist/plugins/envGuard/index.mjs +9 -9
  81. package/dist/plugins/faviconManager/index.cjs +1 -1
  82. package/dist/plugins/faviconManager/index.d.cts +1 -1
  83. package/dist/plugins/faviconManager/index.d.mts +1 -1
  84. package/dist/plugins/faviconManager/index.d.ts +1 -1
  85. package/dist/plugins/faviconManager/index.mjs +1 -1
  86. package/dist/plugins/generateRouter/index.cjs +5 -4
  87. package/dist/plugins/generateRouter/index.d.cts +34 -1
  88. package/dist/plugins/generateRouter/index.d.mts +34 -1
  89. package/dist/plugins/generateRouter/index.d.ts +34 -1
  90. package/dist/plugins/generateRouter/index.mjs +5 -4
  91. package/dist/plugins/generateVersion/index.cjs +1 -1
  92. package/dist/plugins/generateVersion/index.d.cts +1 -1
  93. package/dist/plugins/generateVersion/index.d.mts +1 -1
  94. package/dist/plugins/generateVersion/index.d.ts +1 -1
  95. package/dist/plugins/generateVersion/index.mjs +1 -1
  96. package/dist/plugins/htmlInject/index.cjs +7 -1
  97. package/dist/plugins/htmlInject/index.d.cts +2 -2
  98. package/dist/plugins/htmlInject/index.d.mts +2 -2
  99. package/dist/plugins/htmlInject/index.d.ts +2 -2
  100. package/dist/plugins/htmlInject/index.mjs +7 -1
  101. package/dist/plugins/index.cjs +1 -1
  102. package/dist/plugins/index.d.cts +3 -3
  103. package/dist/plugins/index.d.mts +3 -3
  104. package/dist/plugins/index.d.ts +3 -3
  105. package/dist/plugins/index.mjs +1 -1
  106. package/dist/plugins/loadingManager/index.cjs +26 -26
  107. package/dist/plugins/loadingManager/index.d.cts +1 -1
  108. package/dist/plugins/loadingManager/index.d.mts +1 -1
  109. package/dist/plugins/loadingManager/index.d.ts +1 -1
  110. package/dist/plugins/loadingManager/index.mjs +10 -10
  111. package/dist/plugins/versionUpdateChecker/index.cjs +5 -5
  112. package/dist/plugins/versionUpdateChecker/index.d.cts +1 -1
  113. package/dist/plugins/versionUpdateChecker/index.d.mts +1 -1
  114. package/dist/plugins/versionUpdateChecker/index.d.ts +1 -1
  115. package/dist/plugins/versionUpdateChecker/index.mjs +6 -6
  116. package/dist/shared/vite-plugin.B8FuZce1.d.cts +45 -0
  117. package/dist/shared/vite-plugin.B8FuZce1.d.mts +45 -0
  118. package/dist/shared/vite-plugin.B8FuZce1.d.ts +45 -0
  119. package/dist/shared/{vite-plugin.FfJ-Wwfu.d.cts → vite-plugin.BI9taN75.d.cts} +1 -22
  120. package/dist/shared/{vite-plugin.FfJ-Wwfu.d.mts → vite-plugin.BI9taN75.d.mts} +1 -22
  121. package/dist/shared/{vite-plugin.FfJ-Wwfu.d.ts → vite-plugin.BI9taN75.d.ts} +1 -22
  122. package/dist/shared/vite-plugin.CcvHfrL8.cjs +1 -0
  123. package/dist/shared/vite-plugin.CuXEJAWX.mjs +1 -0
  124. package/package.json +7 -17
  125. package/dist/common/compress/index.cjs +0 -1
  126. package/dist/common/compress/index.d.cts +0 -23
  127. package/dist/common/compress/index.d.mts +0 -23
  128. package/dist/common/compress/index.d.ts +0 -23
  129. package/dist/common/compress/index.mjs +0 -1
  130. package/dist/common/object/index.cjs +0 -1
  131. package/dist/common/object/index.d.cts +0 -30
  132. package/dist/common/object/index.d.mts +0 -30
  133. package/dist/common/object/index.d.ts +0 -30
  134. package/dist/common/object/index.mjs +0 -1
  135. package/dist/common/path/index.cjs +0 -1
  136. package/dist/common/path/index.d.cts +0 -22
  137. package/dist/common/path/index.d.mts +0 -22
  138. package/dist/common/path/index.d.ts +0 -22
  139. package/dist/common/path/index.mjs +0 -1
  140. package/dist/shared/vite-plugin.BCuhU1au.mjs +0 -7
  141. package/dist/shared/vite-plugin.BrI73DHA.cjs +0 -7
  142. package/dist/shared/vite-plugin.CLr0ttuO.d.cts +0 -135
  143. package/dist/shared/vite-plugin.CLr0ttuO.d.mts +0 -135
  144. package/dist/shared/vite-plugin.CLr0ttuO.d.ts +0 -135
  145. package/dist/shared/vite-plugin.CmtcnItg.d.cts +0 -261
  146. package/dist/shared/vite-plugin.CmtcnItg.d.mts +0 -261
  147. package/dist/shared/vite-plugin.CmtcnItg.d.ts +0 -261
  148. package/dist/shared/vite-plugin.DnFDPjNf.mjs +0 -1
  149. package/dist/shared/vite-plugin.Dumot0up.mjs +0 -1
  150. package/dist/shared/vite-plugin.soT9a-KD.cjs +0 -1
  151. package/dist/shared/vite-plugin.vwox4bU0.cjs +0 -1
@@ -1,30 +0,0 @@
1
- /**
2
- * 深度合并对象
3
- *
4
- * @description 将多个源对象深度合并到一个新对象中。
5
- * - undefined 值会被跳过,不会覆盖已有值
6
- * - 嵌套对象会递归合并
7
- * - 数组会直接覆盖,不会合并
8
- * - null 值会覆盖已有值
9
- *
10
- * @param sources 源对象列表
11
- * @returns 合并后的对象
12
- *
13
- * @example
14
- * ```typescript
15
- * // 基本合并
16
- * deepMerge({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }
17
- *
18
- * // undefined 不覆盖
19
- * deepMerge({ a: 1 }, { a: undefined }) // { a: 1 }
20
- *
21
- * // 嵌套对象合并
22
- * deepMerge({ a: { b: 1 } }, { a: { c: 2 } }) // { a: { b: 1, c: 2 } }
23
- *
24
- * // 数组覆盖
25
- * deepMerge({ a: [1, 2] }, { a: [3, 4] }) // { a: [3, 4] }
26
- * ```
27
- */
28
- declare function deepMerge<T extends Record<string, any>>(...sources: Partial<T>[]): T;
29
-
30
- export { deepMerge };
@@ -1,30 +0,0 @@
1
- /**
2
- * 深度合并对象
3
- *
4
- * @description 将多个源对象深度合并到一个新对象中。
5
- * - undefined 值会被跳过,不会覆盖已有值
6
- * - 嵌套对象会递归合并
7
- * - 数组会直接覆盖,不会合并
8
- * - null 值会覆盖已有值
9
- *
10
- * @param sources 源对象列表
11
- * @returns 合并后的对象
12
- *
13
- * @example
14
- * ```typescript
15
- * // 基本合并
16
- * deepMerge({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }
17
- *
18
- * // undefined 不覆盖
19
- * deepMerge({ a: 1 }, { a: undefined }) // { a: 1 }
20
- *
21
- * // 嵌套对象合并
22
- * deepMerge({ a: { b: 1 } }, { a: { c: 2 } }) // { a: { b: 1, c: 2 } }
23
- *
24
- * // 数组覆盖
25
- * deepMerge({ a: [1, 2] }, { a: [3, 4] }) // { a: [3, 4] }
26
- * ```
27
- */
28
- declare function deepMerge<T extends Record<string, any>>(...sources: Partial<T>[]): T;
29
-
30
- export { deepMerge };
@@ -1,30 +0,0 @@
1
- /**
2
- * 深度合并对象
3
- *
4
- * @description 将多个源对象深度合并到一个新对象中。
5
- * - undefined 值会被跳过,不会覆盖已有值
6
- * - 嵌套对象会递归合并
7
- * - 数组会直接覆盖,不会合并
8
- * - null 值会覆盖已有值
9
- *
10
- * @param sources 源对象列表
11
- * @returns 合并后的对象
12
- *
13
- * @example
14
- * ```typescript
15
- * // 基本合并
16
- * deepMerge({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }
17
- *
18
- * // undefined 不覆盖
19
- * deepMerge({ a: 1 }, { a: undefined }) // { a: 1 }
20
- *
21
- * // 嵌套对象合并
22
- * deepMerge({ a: { b: 1 } }, { a: { c: 2 } }) // { a: { b: 1, c: 2 } }
23
- *
24
- * // 数组覆盖
25
- * deepMerge({ a: [1, 2] }, { a: [3, 4] }) // { a: [3, 4] }
26
- * ```
27
- */
28
- declare function deepMerge<T extends Record<string, any>>(...sources: Partial<T>[]): T;
29
-
30
- export { deepMerge };
@@ -1 +0,0 @@
1
- function i(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)&&Object.prototype.toString.call(o)==="[object Object]"}function f(...o){const e={};for(const r of o)if(r)for(const t in r){if(!Object.prototype.hasOwnProperty.call(r,t))continue;const n=r[t],c=e[t];n!==void 0&&(i(n)&&i(c)?e[t]=f(c,n):e[t]=n)}return e}export{f as deepMerge};
@@ -1 +0,0 @@
1
- "use strict";function isNodeModule(s){return s.includes("node_modules")||s.startsWith("\0")||s.startsWith("virtual:")}exports.isNodeModule=isNodeModule;
@@ -1,22 +0,0 @@
1
- /**
2
- * 判断模块 ID 是否来自 node_modules
3
- *
4
- * @param {string} moduleId - 模块标识符
5
- * @returns {boolean} 是否来自 node_modules
6
- *
7
- * @description 检测规则:
8
- * - 路径中包含 `node_modules` 的模块
9
- * - 以 `\0` 开头的虚拟模块(Rollup 内部模块)
10
- * - 以 `virtual:` 开头的虚拟模块
11
- *
12
- * @example
13
- * ```typescript
14
- * isNodeModule('node_modules/lodash/index.js') // true
15
- * isNodeModule('src/utils/helper.ts') // false
16
- * isNodeModule('\0some-virtual-module') // true
17
- * isNodeModule('virtual:import-meta-env') // true
18
- * ```
19
- */
20
- declare function isNodeModule(moduleId: string): boolean;
21
-
22
- export { isNodeModule };
@@ -1,22 +0,0 @@
1
- /**
2
- * 判断模块 ID 是否来自 node_modules
3
- *
4
- * @param {string} moduleId - 模块标识符
5
- * @returns {boolean} 是否来自 node_modules
6
- *
7
- * @description 检测规则:
8
- * - 路径中包含 `node_modules` 的模块
9
- * - 以 `\0` 开头的虚拟模块(Rollup 内部模块)
10
- * - 以 `virtual:` 开头的虚拟模块
11
- *
12
- * @example
13
- * ```typescript
14
- * isNodeModule('node_modules/lodash/index.js') // true
15
- * isNodeModule('src/utils/helper.ts') // false
16
- * isNodeModule('\0some-virtual-module') // true
17
- * isNodeModule('virtual:import-meta-env') // true
18
- * ```
19
- */
20
- declare function isNodeModule(moduleId: string): boolean;
21
-
22
- export { isNodeModule };
@@ -1,22 +0,0 @@
1
- /**
2
- * 判断模块 ID 是否来自 node_modules
3
- *
4
- * @param {string} moduleId - 模块标识符
5
- * @returns {boolean} 是否来自 node_modules
6
- *
7
- * @description 检测规则:
8
- * - 路径中包含 `node_modules` 的模块
9
- * - 以 `\0` 开头的虚拟模块(Rollup 内部模块)
10
- * - 以 `virtual:` 开头的虚拟模块
11
- *
12
- * @example
13
- * ```typescript
14
- * isNodeModule('node_modules/lodash/index.js') // true
15
- * isNodeModule('src/utils/helper.ts') // false
16
- * isNodeModule('\0some-virtual-module') // true
17
- * isNodeModule('virtual:import-meta-env') // true
18
- * ```
19
- */
20
- declare function isNodeModule(moduleId: string): boolean;
21
-
22
- export { isNodeModule };
@@ -1 +0,0 @@
1
- function e(t){return t.includes("node_modules")||t.startsWith("\0")||t.startsWith("virtual:")}export{e as isNodeModule};
@@ -1,7 +0,0 @@
1
- import{containsScriptTag as C}from"../common/script/index.mjs";function d(u,t,r){if(r==="regex"){try{const c=new RegExp(t),e=u.match(c);if(e&&e.index!==void 0)return{index:e.index,length:e[0].length}}catch{return null}return null}const n=u.indexOf(t);return n===-1?null:{index:n,length:t.length}}function m(u,t,r){let n=u;const c={...r,...t};for(const[e,o]of Object.entries(c)){const a=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),E=o.replace(/\$/g,"$$$$");n=n.replace(new RegExp(`\\{\\{${a}\\}\\}`,"g"),E)}return n}function p(u,t){let r=!1;switch(u.type){case"env":{const n=u.value,c=process.env[n];r=!!c&&c!=="false"&&c!=="0";break}case"file-contains":{const n=u.value;r=t.includes(n);break}case"custom":{const n=u.value;try{r=!!n()}catch{r=!1}break}}return u.negate?!r:r}function w(u){return[...u].sort((t,r)=>(t.priority??100)-(r.priority??100))}function b(u,t,r,n,c){switch(r){case"head-start":{const e=u.match(/<head\b[^>]*>/i);if(!e)return{html:u,injected:!1,reason:"\u672A\u627E\u5230 <head> \u6807\u7B7E"};const o=(e.index??0)+e[0].length;return{html:u.slice(0,o)+`
2
- `+t+u.slice(o),injected:!0}}case"head-end":{const e=u.match(/<\/head\s*>/i);if(!e)return{html:u,injected:!1,reason:"\u672A\u627E\u5230 </head> \u6807\u7B7E"};const o=e.index;return{html:u.slice(0,o)+t+`
3
- `+u.slice(o),injected:!0}}case"body-start":{const e=u.match(/<body\b[^>]*>/i);if(!e)return{html:u,injected:!1,reason:"\u672A\u627E\u5230 <body> \u6807\u7B7E"};const o=(e.index??0)+e[0].length;return{html:u.slice(0,o)+`
4
- `+t+u.slice(o),injected:!0}}case"body-end":{const e=u.match(/<\/body\s*>/i);if(!e)return{html:u,injected:!1,reason:"\u672A\u627E\u5230 </body> \u6807\u7B7E"};const o=e.index;return{html:u.slice(0,o)+t+`
5
- `+u.slice(o),injected:!0}}case"before-selector":{if(!n)return{html:u,injected:!1,reason:"before-selector \u9700\u8981 selector \u53C2\u6570"};const e=d(u,n,c);return e?{html:u.slice(0,e.index)+t+`
6
- `+u.slice(e.index),injected:!0}:{html:u,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${n}"`}}case"after-selector":{if(!n)return{html:u,injected:!1,reason:"after-selector \u9700\u8981 selector \u53C2\u6570"};const e=d(u,n,c);if(!e)return{html:u,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${n}"`};const o=e.index+e.length;return{html:u.slice(0,o)+`
7
- `+t+u.slice(o),injected:!0}}case"replace-selector":{if(!n)return{html:u,injected:!1,reason:"replace-selector \u9700\u8981 selector \u53C2\u6570"};const e=d(u,n,c);if(!e)return{html:u,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${n}"`};const o=e.index+e.length;return{html:u.slice(0,e.index)+t+u.slice(o),injected:!0}}default:return{html:u,injected:!1,reason:`\u4E0D\u652F\u6301\u7684\u6CE8\u5165\u4F4D\u7F6E: ${r}`}}}const F=["script","iframe","object","embed","applet","form","input","textarea","select","button"],h=["onclick","ondblclick","onmouseover","onmouseout","onmousemove","onmousedown","onmouseup","onkeydown","onkeyup","onkeypress","onload","onerror","onfocus","onblur","onsubmit","onchange","oninput","oncontextmenu","ondrag","ondrop","onanimationend","ontransitionend"];function g(u){if(u){if(u.blockedTags&&!Array.isArray(u.blockedTags))throw new Error("security.blockedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(u.allowedTags&&!Array.isArray(u.allowedTags))throw new Error("security.allowedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(u.blockedAttributes&&!Array.isArray(u.blockedAttributes))throw new Error("security.blockedAttributes \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4")}}function A(u,t,r,n){const c=r?.blockDangerousTags!==!1,e=r?.blockDangerousAttributes!==!1,o=r?.blockedTags||F,a=r?.allowedTags,E=r?.blockedAttributes||h;let s=u;if(c){const l=a?o.filter(i=>!a.includes(i)):o;if(C(u))if(t.allowScriptInjection)n?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${t.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 "${t.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 i of l){if(i==="script")continue;const B=new RegExp(`<${i}\\b[^>]*>[\\s\\S]*?<\\/${i}>`,"gi"),f=new RegExp(`<${i}\\b[^>]*/?>`,"gi");if(B.test(s)||f.test(s))if(t.allowScriptInjection){n?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${t.id||"unnamed"}" \u5305\u542B\u88AB\u963B\u6B62\u7684\u6807\u7B7E <${i}>\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 "${t.id||"unnamed"}" \u7684\u5185\u5BB9\u5305\u542B\u88AB\u963B\u6B62\u7684\u6807\u7B7E <${i}>\u3002\u5982\u9700\u6CE8\u5165\u6B64\u6807\u7B7E\uFF0C\u8BF7\u8BBE\u7F6E allowScriptInjection: true \u6216\u5728 security.allowedTags \u4E2D\u6DFB\u52A0 "${i}"`);s=s.replace(B,""),s=s.replace(f,"")}}if(e)for(const l of E){const i=new RegExp(`\\s${l}\\s*=\\s*["'][^"']*["']`,"gi");if(i.test(s))if(t.allowScriptInjection){n?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${t.id||"unnamed"}" \u5305\u542B\u5371\u9669\u5C5E\u6027 ${l}\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 "${t.id||"unnamed"}" \u7684\u5185\u5BB9\u5305\u542B\u5371\u9669\u5C5E\u6027 ${l}\u3002\u5982\u9700\u6CE8\u5165\u6B64\u5C5E\u6027\uFF0C\u8BF7\u8BBE\u7F6E allowScriptInjection: true`);s=s.replace(i,"")}return s}export{h as D,F as a,m as b,w as c,p as e,d as f,b as i,A as s,g as v};
@@ -1,7 +0,0 @@
1
- "use strict";const common_script_index=require("../common/script/index.cjs");function findSelectorMatch(u,t,r){if(r==="regex"){try{const i=new RegExp(t),e=u.match(i);if(e&&e.index!==void 0)return{index:e.index,length:e[0].length}}catch{return null}return null}const n=u.indexOf(t);return n===-1?null:{index:n,length:t.length}}function applyTemplateVars(u,t,r){let n=u;const i={...r,...t};for(const[e,o]of Object.entries(i)){const a=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),d=o.replace(/\$/g,"$$$$");n=n.replace(new RegExp(`\\{\\{${a}\\}\\}`,"g"),d)}return n}function evaluateCondition(u,t){let r=!1;switch(u.type){case"env":{const n=u.value,i=process.env[n];r=!!i&&i!=="false"&&i!=="0";break}case"file-contains":{const n=u.value;r=t.includes(n);break}case"custom":{const n=u.value;try{r=!!n()}catch{r=!1}break}}return u.negate?!r:r}function sortRulesByPriority(u){return[...u].sort((t,r)=>(t.priority??100)-(r.priority??100))}function injectAtPosition(u,t,r,n,i){switch(r){case"head-start":{const e=u.match(/<head\b[^>]*>/i);if(!e)return{html:u,injected:!1,reason:"\u672A\u627E\u5230 <head> \u6807\u7B7E"};const o=(e.index??0)+e[0].length;return{html:u.slice(0,o)+`
2
- `+t+u.slice(o),injected:!0}}case"head-end":{const e=u.match(/<\/head\s*>/i);if(!e)return{html:u,injected:!1,reason:"\u672A\u627E\u5230 </head> \u6807\u7B7E"};const o=e.index;return{html:u.slice(0,o)+t+`
3
- `+u.slice(o),injected:!0}}case"body-start":{const e=u.match(/<body\b[^>]*>/i);if(!e)return{html:u,injected:!1,reason:"\u672A\u627E\u5230 <body> \u6807\u7B7E"};const o=(e.index??0)+e[0].length;return{html:u.slice(0,o)+`
4
- `+t+u.slice(o),injected:!0}}case"body-end":{const e=u.match(/<\/body\s*>/i);if(!e)return{html:u,injected:!1,reason:"\u672A\u627E\u5230 </body> \u6807\u7B7E"};const o=e.index;return{html:u.slice(0,o)+t+`
5
- `+u.slice(o),injected:!0}}case"before-selector":{if(!n)return{html:u,injected:!1,reason:"before-selector \u9700\u8981 selector \u53C2\u6570"};const e=findSelectorMatch(u,n,i);return e?{html:u.slice(0,e.index)+t+`
6
- `+u.slice(e.index),injected:!0}:{html:u,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${n}"`}}case"after-selector":{if(!n)return{html:u,injected:!1,reason:"after-selector \u9700\u8981 selector \u53C2\u6570"};const e=findSelectorMatch(u,n,i);if(!e)return{html:u,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${n}"`};const o=e.index+e.length;return{html:u.slice(0,o)+`
7
- `+t+u.slice(o),injected:!0}}case"replace-selector":{if(!n)return{html:u,injected:!1,reason:"replace-selector \u9700\u8981 selector \u53C2\u6570"};const e=findSelectorMatch(u,n,i);if(!e)return{html:u,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${n}"`};const o=e.index+e.length;return{html:u.slice(0,e.index)+t+u.slice(o),injected:!0}}default:return{html:u,injected:!1,reason:`\u4E0D\u652F\u6301\u7684\u6CE8\u5165\u4F4D\u7F6E: ${r}`}}}const DEFAULT_BLOCKED_TAGS=["script","iframe","object","embed","applet","form","input","textarea","select","button"],DEFAULT_BLOCKED_ATTRIBUTES=["onclick","ondblclick","onmouseover","onmouseout","onmousemove","onmousedown","onmouseup","onkeydown","onkeyup","onkeypress","onload","onerror","onfocus","onblur","onsubmit","onchange","oninput","oncontextmenu","ondrag","ondrop","onanimationend","ontransitionend"];function validateSecurityConfig(u){if(u){if(u.blockedTags&&!Array.isArray(u.blockedTags))throw new Error("security.blockedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(u.allowedTags&&!Array.isArray(u.allowedTags))throw new Error("security.allowedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(u.blockedAttributes&&!Array.isArray(u.blockedAttributes))throw new Error("security.blockedAttributes \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4")}}function sanitizeContent(u,t,r,n){const i=r?.blockDangerousTags!==!1,e=r?.blockDangerousAttributes!==!1,o=r?.blockedTags||DEFAULT_BLOCKED_TAGS,a=r?.allowedTags,d=r?.blockedAttributes||DEFAULT_BLOCKED_ATTRIBUTES;let s=u;if(i){const l=a?o.filter(c=>!a.includes(c)):o;if(common_script_index.containsScriptTag(u))if(t.allowScriptInjection)n?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${t.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 "${t.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 c of l){if(c==="script")continue;const E=new RegExp(`<${c}\\b[^>]*>[\\s\\S]*?<\\/${c}>`,"gi"),B=new RegExp(`<${c}\\b[^>]*/?>`,"gi");if(E.test(s)||B.test(s))if(t.allowScriptInjection){n?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${t.id||"unnamed"}" \u5305\u542B\u88AB\u963B\u6B62\u7684\u6807\u7B7E <${c}>\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 "${t.id||"unnamed"}" \u7684\u5185\u5BB9\u5305\u542B\u88AB\u963B\u6B62\u7684\u6807\u7B7E <${c}>\u3002\u5982\u9700\u6CE8\u5165\u6B64\u6807\u7B7E\uFF0C\u8BF7\u8BBE\u7F6E allowScriptInjection: true \u6216\u5728 security.allowedTags \u4E2D\u6DFB\u52A0 "${c}"`);s=s.replace(E,""),s=s.replace(B,"")}}if(e)for(const l of d){const c=new RegExp(`\\s${l}\\s*=\\s*["'][^"']*["']`,"gi");if(c.test(s))if(t.allowScriptInjection){n?.warn(`[\u5B89\u5168\u8B66\u544A] \u89C4\u5219 "${t.id||"unnamed"}" \u5305\u542B\u5371\u9669\u5C5E\u6027 ${l}\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 "${t.id||"unnamed"}" \u7684\u5185\u5BB9\u5305\u542B\u5371\u9669\u5C5E\u6027 ${l}\u3002\u5982\u9700\u6CE8\u5165\u6B64\u5C5E\u6027\uFF0C\u8BF7\u8BBE\u7F6E allowScriptInjection: true`);s=s.replace(c,"")}return s}exports.DEFAULT_BLOCKED_ATTRIBUTES=DEFAULT_BLOCKED_ATTRIBUTES,exports.DEFAULT_BLOCKED_TAGS=DEFAULT_BLOCKED_TAGS,exports.applyTemplateVars=applyTemplateVars,exports.evaluateCondition=evaluateCondition,exports.findSelectorMatch=findSelectorMatch,exports.injectAtPosition=injectAtPosition,exports.sanitizeContent=sanitizeContent,exports.sortRulesByPriority=sortRulesByPriority,exports.validateSecurityConfig=validateSecurityConfig;
@@ -1,135 +0,0 @@
1
- /**
2
- * 构造函数参数接口
3
- */
4
- interface LoggerOptions {
5
- /**
6
- * 插件名称
7
- */
8
- name: string;
9
- /**
10
- * 是否启用日志
11
- */
12
- enabled?: boolean;
13
- }
14
-
15
- /**
16
- * 日志工具类(单例模式)
17
- * @description 全局单例日志管理器,统一管理所有插件的日志输出
18
- */
19
- declare class Logger {
20
- /**
21
- * 单例实例
22
- */
23
- private static instance;
24
- /**
25
- * 库名称
26
- */
27
- private readonly libName;
28
- /**
29
- * 插件日志配置映射表
30
- * @description 存储每个插件的日志开关状态
31
- */
32
- private pluginConfigs;
33
- /**
34
- * 日志类型映射
35
- */
36
- private readonly logTypes;
37
- /**
38
- * 私有构造函数,防止外部实例化
39
- */
40
- private constructor();
41
- /**
42
- * 获取单例实例
43
- * @returns Logger 单例实例
44
- */
45
- private static getInstance;
46
- /**
47
- * 创建日志记录器(工厂方法)
48
- * @param options 配置选项
49
- * @returns Logger 单例实例
50
- * @description 为插件创建日志记录器,实际返回单例实例并注册插件配置
51
- */
52
- static create(options: LoggerOptions): Logger;
53
- /**
54
- * 注册插件日志配置
55
- * @param pluginName 插件名称
56
- * @param enabled 是否启用日志
57
- */
58
- private registerPlugin;
59
- /**
60
- * 注销插件日志配置
61
- * @param pluginName 插件名称
62
- */
63
- private unregisterPlugin;
64
- /**
65
- * 注销指定插件的日志配置
66
- * @param pluginName 插件名称
67
- * @description 从单例中移除指定插件的日志配置,通常在插件销毁时调用
68
- */
69
- static unregister(pluginName: string): void;
70
- /**
71
- * 销毁单例实例,释放所有资源
72
- * @description 清除所有已注册的插件配置,重置单例实例。主要用于测试场景
73
- */
74
- static destroy(): void;
75
- /**
76
- * 生成日志前缀
77
- * @param pluginName 插件名称
78
- * @returns 格式化的日志前缀
79
- */
80
- private formatPrefix;
81
- /**
82
- * 检查插件日志是否启用
83
- * @param pluginName 插件名称
84
- * @returns 是否启用
85
- */
86
- private isPluginEnabled;
87
- /**
88
- * 统一日志输出方法
89
- * @param pluginName 插件名称
90
- * @param type 日志类型
91
- * @param message 日志消息
92
- * @param data 附加数据
93
- */
94
- private log;
95
- /**
96
- * 创建插件日志代理对象
97
- * @param pluginName 插件名称
98
- * @returns 插件日志代理对象
99
- * @internal 供 BasePlugin 内部使用
100
- */
101
- createPluginLogger(pluginName: string): PluginLogger;
102
- }
103
- /**
104
- * 插件日志代理接口
105
- * @description 为每个插件提供独立的日志接口
106
- */
107
- interface PluginLogger {
108
- /**
109
- * 输出成功日志
110
- * @param message 日志消息
111
- * @param data 附加数据
112
- */
113
- success(message: string, data?: any): void;
114
- /**
115
- * 输出信息日志
116
- * @param message 日志消息
117
- * @param data 附加数据
118
- */
119
- info(message: string, data?: any): void;
120
- /**
121
- * 输出警告日志
122
- * @param message 日志消息
123
- * @param data 附加数据
124
- */
125
- warn(message: string, data?: any): void;
126
- /**
127
- * 输出错误日志
128
- * @param message 日志消息
129
- * @param data 附加数据
130
- */
131
- error(message: string, data?: any): void;
132
- }
133
-
134
- export { Logger as L };
135
- export type { PluginLogger as P, LoggerOptions as a };
@@ -1,135 +0,0 @@
1
- /**
2
- * 构造函数参数接口
3
- */
4
- interface LoggerOptions {
5
- /**
6
- * 插件名称
7
- */
8
- name: string;
9
- /**
10
- * 是否启用日志
11
- */
12
- enabled?: boolean;
13
- }
14
-
15
- /**
16
- * 日志工具类(单例模式)
17
- * @description 全局单例日志管理器,统一管理所有插件的日志输出
18
- */
19
- declare class Logger {
20
- /**
21
- * 单例实例
22
- */
23
- private static instance;
24
- /**
25
- * 库名称
26
- */
27
- private readonly libName;
28
- /**
29
- * 插件日志配置映射表
30
- * @description 存储每个插件的日志开关状态
31
- */
32
- private pluginConfigs;
33
- /**
34
- * 日志类型映射
35
- */
36
- private readonly logTypes;
37
- /**
38
- * 私有构造函数,防止外部实例化
39
- */
40
- private constructor();
41
- /**
42
- * 获取单例实例
43
- * @returns Logger 单例实例
44
- */
45
- private static getInstance;
46
- /**
47
- * 创建日志记录器(工厂方法)
48
- * @param options 配置选项
49
- * @returns Logger 单例实例
50
- * @description 为插件创建日志记录器,实际返回单例实例并注册插件配置
51
- */
52
- static create(options: LoggerOptions): Logger;
53
- /**
54
- * 注册插件日志配置
55
- * @param pluginName 插件名称
56
- * @param enabled 是否启用日志
57
- */
58
- private registerPlugin;
59
- /**
60
- * 注销插件日志配置
61
- * @param pluginName 插件名称
62
- */
63
- private unregisterPlugin;
64
- /**
65
- * 注销指定插件的日志配置
66
- * @param pluginName 插件名称
67
- * @description 从单例中移除指定插件的日志配置,通常在插件销毁时调用
68
- */
69
- static unregister(pluginName: string): void;
70
- /**
71
- * 销毁单例实例,释放所有资源
72
- * @description 清除所有已注册的插件配置,重置单例实例。主要用于测试场景
73
- */
74
- static destroy(): void;
75
- /**
76
- * 生成日志前缀
77
- * @param pluginName 插件名称
78
- * @returns 格式化的日志前缀
79
- */
80
- private formatPrefix;
81
- /**
82
- * 检查插件日志是否启用
83
- * @param pluginName 插件名称
84
- * @returns 是否启用
85
- */
86
- private isPluginEnabled;
87
- /**
88
- * 统一日志输出方法
89
- * @param pluginName 插件名称
90
- * @param type 日志类型
91
- * @param message 日志消息
92
- * @param data 附加数据
93
- */
94
- private log;
95
- /**
96
- * 创建插件日志代理对象
97
- * @param pluginName 插件名称
98
- * @returns 插件日志代理对象
99
- * @internal 供 BasePlugin 内部使用
100
- */
101
- createPluginLogger(pluginName: string): PluginLogger;
102
- }
103
- /**
104
- * 插件日志代理接口
105
- * @description 为每个插件提供独立的日志接口
106
- */
107
- interface PluginLogger {
108
- /**
109
- * 输出成功日志
110
- * @param message 日志消息
111
- * @param data 附加数据
112
- */
113
- success(message: string, data?: any): void;
114
- /**
115
- * 输出信息日志
116
- * @param message 日志消息
117
- * @param data 附加数据
118
- */
119
- info(message: string, data?: any): void;
120
- /**
121
- * 输出警告日志
122
- * @param message 日志消息
123
- * @param data 附加数据
124
- */
125
- warn(message: string, data?: any): void;
126
- /**
127
- * 输出错误日志
128
- * @param message 日志消息
129
- * @param data 附加数据
130
- */
131
- error(message: string, data?: any): void;
132
- }
133
-
134
- export { Logger as L };
135
- export type { PluginLogger as P, LoggerOptions as a };
@@ -1,135 +0,0 @@
1
- /**
2
- * 构造函数参数接口
3
- */
4
- interface LoggerOptions {
5
- /**
6
- * 插件名称
7
- */
8
- name: string;
9
- /**
10
- * 是否启用日志
11
- */
12
- enabled?: boolean;
13
- }
14
-
15
- /**
16
- * 日志工具类(单例模式)
17
- * @description 全局单例日志管理器,统一管理所有插件的日志输出
18
- */
19
- declare class Logger {
20
- /**
21
- * 单例实例
22
- */
23
- private static instance;
24
- /**
25
- * 库名称
26
- */
27
- private readonly libName;
28
- /**
29
- * 插件日志配置映射表
30
- * @description 存储每个插件的日志开关状态
31
- */
32
- private pluginConfigs;
33
- /**
34
- * 日志类型映射
35
- */
36
- private readonly logTypes;
37
- /**
38
- * 私有构造函数,防止外部实例化
39
- */
40
- private constructor();
41
- /**
42
- * 获取单例实例
43
- * @returns Logger 单例实例
44
- */
45
- private static getInstance;
46
- /**
47
- * 创建日志记录器(工厂方法)
48
- * @param options 配置选项
49
- * @returns Logger 单例实例
50
- * @description 为插件创建日志记录器,实际返回单例实例并注册插件配置
51
- */
52
- static create(options: LoggerOptions): Logger;
53
- /**
54
- * 注册插件日志配置
55
- * @param pluginName 插件名称
56
- * @param enabled 是否启用日志
57
- */
58
- private registerPlugin;
59
- /**
60
- * 注销插件日志配置
61
- * @param pluginName 插件名称
62
- */
63
- private unregisterPlugin;
64
- /**
65
- * 注销指定插件的日志配置
66
- * @param pluginName 插件名称
67
- * @description 从单例中移除指定插件的日志配置,通常在插件销毁时调用
68
- */
69
- static unregister(pluginName: string): void;
70
- /**
71
- * 销毁单例实例,释放所有资源
72
- * @description 清除所有已注册的插件配置,重置单例实例。主要用于测试场景
73
- */
74
- static destroy(): void;
75
- /**
76
- * 生成日志前缀
77
- * @param pluginName 插件名称
78
- * @returns 格式化的日志前缀
79
- */
80
- private formatPrefix;
81
- /**
82
- * 检查插件日志是否启用
83
- * @param pluginName 插件名称
84
- * @returns 是否启用
85
- */
86
- private isPluginEnabled;
87
- /**
88
- * 统一日志输出方法
89
- * @param pluginName 插件名称
90
- * @param type 日志类型
91
- * @param message 日志消息
92
- * @param data 附加数据
93
- */
94
- private log;
95
- /**
96
- * 创建插件日志代理对象
97
- * @param pluginName 插件名称
98
- * @returns 插件日志代理对象
99
- * @internal 供 BasePlugin 内部使用
100
- */
101
- createPluginLogger(pluginName: string): PluginLogger;
102
- }
103
- /**
104
- * 插件日志代理接口
105
- * @description 为每个插件提供独立的日志接口
106
- */
107
- interface PluginLogger {
108
- /**
109
- * 输出成功日志
110
- * @param message 日志消息
111
- * @param data 附加数据
112
- */
113
- success(message: string, data?: any): void;
114
- /**
115
- * 输出信息日志
116
- * @param message 日志消息
117
- * @param data 附加数据
118
- */
119
- info(message: string, data?: any): void;
120
- /**
121
- * 输出警告日志
122
- * @param message 日志消息
123
- * @param data 附加数据
124
- */
125
- warn(message: string, data?: any): void;
126
- /**
127
- * 输出错误日志
128
- * @param message 日志消息
129
- * @param data 附加数据
130
- */
131
- error(message: string, data?: any): void;
132
- }
133
-
134
- export { Logger as L };
135
- export type { PluginLogger as P, LoggerOptions as a };