@meng-xi/vite-plugin 0.1.3 → 0.1.5

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 (142) hide show
  1. package/README-en.md +49 -775
  2. package/README.md +46 -770
  3. package/dist/common/format/index.cjs +1 -1
  4. package/dist/common/format/index.d.cts +1 -130
  5. package/dist/common/format/index.d.mts +1 -130
  6. package/dist/common/format/index.d.ts +1 -130
  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 +1 -89
  10. package/dist/common/fs/index.d.mts +1 -89
  11. package/dist/common/fs/index.d.ts +1 -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 +19 -81
  15. package/dist/common/html/index.d.mts +19 -81
  16. package/dist/common/html/index.d.ts +19 -81
  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 -8
  20. package/dist/common/index.d.mts +7 -8
  21. package/dist/common/index.d.ts +7 -8
  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 -0
  29. package/dist/common/ui/index.d.cts +22 -0
  30. package/dist/common/ui/index.d.mts +22 -0
  31. package/dist/common/ui/index.d.ts +22 -0
  32. package/dist/common/ui/index.mjs +1 -0
  33. package/dist/common/validation/index.cjs +1 -1
  34. package/dist/common/validation/index.d.cts +2 -79
  35. package/dist/common/validation/index.d.mts +2 -79
  36. package/dist/common/validation/index.d.ts +2 -79
  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 +12 -10
  45. package/dist/index.d.mts +12 -10
  46. package/dist/index.d.ts +12 -10
  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 +17 -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 +17 -0
  56. package/dist/plugins/buildProgress/index.cjs +2 -2
  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 +11 -11
  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 +21 -3
  73. package/dist/plugins/copyFile/index.d.mts +21 -3
  74. package/dist/plugins/copyFile/index.d.ts +21 -3
  75. package/dist/plugins/copyFile/index.mjs +1 -1
  76. package/dist/plugins/envGuard/index.cjs +67 -0
  77. package/dist/plugins/envGuard/index.d.cts +255 -0
  78. package/dist/plugins/envGuard/index.d.mts +255 -0
  79. package/dist/plugins/envGuard/index.d.ts +255 -0
  80. package/dist/plugins/envGuard/index.mjs +67 -0
  81. package/dist/plugins/faviconManager/index.cjs +1 -1
  82. package/dist/plugins/faviconManager/index.d.cts +44 -6
  83. package/dist/plugins/faviconManager/index.d.mts +44 -6
  84. package/dist/plugins/faviconManager/index.d.ts +44 -6
  85. package/dist/plugins/faviconManager/index.mjs +1 -1
  86. package/dist/plugins/generateRouter/index.cjs +4 -4
  87. package/dist/plugins/generateRouter/index.d.cts +62 -15
  88. package/dist/plugins/generateRouter/index.d.mts +62 -15
  89. package/dist/plugins/generateRouter/index.d.ts +62 -15
  90. package/dist/plugins/generateRouter/index.mjs +4 -4
  91. package/dist/plugins/generateVersion/index.cjs +1 -1
  92. package/dist/plugins/generateVersion/index.d.cts +13 -1
  93. package/dist/plugins/generateVersion/index.d.mts +13 -1
  94. package/dist/plugins/generateVersion/index.d.ts +13 -1
  95. package/dist/plugins/generateVersion/index.mjs +1 -1
  96. package/dist/plugins/htmlInject/index.cjs +7 -7
  97. package/dist/plugins/htmlInject/index.d.cts +50 -195
  98. package/dist/plugins/htmlInject/index.d.mts +50 -195
  99. package/dist/plugins/htmlInject/index.d.ts +50 -195
  100. package/dist/plugins/htmlInject/index.mjs +7 -7
  101. package/dist/plugins/index.cjs +1 -1
  102. package/dist/plugins/index.d.cts +5 -2
  103. package/dist/plugins/index.d.mts +5 -2
  104. package/dist/plugins/index.d.ts +5 -2
  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 +11 -11
  111. package/dist/plugins/versionUpdateChecker/index.cjs +1 -1
  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 +1 -1
  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.BI9taN75.d.cts +122 -0
  120. package/dist/shared/vite-plugin.BI9taN75.d.mts +122 -0
  121. package/dist/shared/vite-plugin.BI9taN75.d.ts +122 -0
  122. package/dist/shared/vite-plugin.BPFqtmWa.mjs +1 -0
  123. package/dist/shared/vite-plugin.CnOy46d3.cjs +1 -0
  124. package/package.json +16 -16
  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.CLr0ttuO.d.cts +0 -135
  141. package/dist/shared/vite-plugin.CLr0ttuO.d.mts +0 -135
  142. package/dist/shared/vite-plugin.CLr0ttuO.d.ts +0 -135
@@ -45,75 +45,12 @@ interface CopyResult {
45
45
  executionTime: number;
46
46
  }
47
47
 
48
- /**
49
- * 文件/目录条目信息
50
- */
51
- interface FileEntry {
52
- /** 完整路径 */
53
- path: string;
54
- /** 是否为文件 */
55
- isFile: boolean;
56
- /** 是否为目录 */
57
- isDirectory: boolean;
58
- }
59
48
  /**
60
49
  * 检查源文件是否存在
61
50
  * @param sourcePath 源文件路径
62
51
  * @throws 当源文件不存在或无法访问时抛出异常
63
52
  */
64
53
  declare function checkSourceExists(sourcePath: string): Promise<void>;
65
- /**
66
- * 创建目标目录
67
- * @param targetPath 目标目录路径
68
- * @throws 当无法创建目标目录时抛出异常
69
- */
70
- declare function ensureTargetDir(targetPath: string): Promise<void>;
71
- /**
72
- * 读取目录内容(优化版:一次性获取文件类型信息)
73
- * @param dirPath 目录路径
74
- * @param recursive 是否递归读取
75
- * @returns 文件和目录条目列表
76
- */
77
- declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<FileEntry[]>;
78
- /**
79
- * 检查文件是否需要更新
80
- * @param sourceFile 源文件路径
81
- * @param targetFile 目标文件路径
82
- * @returns 是否需要更新
83
- */
84
- declare function shouldUpdateFile(sourceFile: string, targetFile: string): Promise<boolean>;
85
- /**
86
- * 检查文件是否存在
87
- * @param filePath 文件路径
88
- * @returns 是否存在
89
- *
90
- * @example
91
- * ```typescript
92
- * if (await fileExists('/path/to/file')) {
93
- * console.log('文件存在')
94
- * }
95
- * ```
96
- */
97
- declare function fileExists(filePath: string): Promise<boolean>;
98
- /**
99
- * 带并发限制的批量执行
100
- *
101
- * @param items 待处理项
102
- * @param handler 处理函数
103
- * @param concurrency 并发数
104
- * @returns 处理结果数组,顺序与输入项对应
105
- *
106
- * @example
107
- * ```typescript
108
- * const urls = ['url1', 'url2', 'url3', 'url4', 'url5']
109
- * const results = await runWithConcurrency(
110
- * urls,
111
- * async (url) => fetch(url),
112
- * 3 // 最多同时处理3个请求
113
- * )
114
- * ```
115
- */
116
- declare function runWithConcurrency<T, R>(items: T[], handler: (item: T) => Promise<R>, concurrency: number): Promise<R[]>;
117
54
  /**
118
55
  * 执行文件复制操作(优化版:并行IO)
119
56
  * @param sourcePath 源文件或目录路径
@@ -130,21 +67,6 @@ declare function copySourceToTarget(sourcePath: string, targetPath: string, opti
130
67
  * @throws 当写入过程中出现错误时抛出异常
131
68
  */
132
69
  declare function writeFileContent(filePath: string, content: string): Promise<void>;
133
- /**
134
- * 读取文件内容
135
- * @param filePath 文件路径
136
- * @returns 文件内容字符串
137
- * @throws 当读取过程中出现错误时抛出异常
138
- */
139
- declare function readFileContent(filePath: string): Promise<string>;
140
- /**
141
- * 同步读取文件内容
142
- * @param filePath 文件路径
143
- * @returns 文件内容字符串
144
- * @throws 当读取过程中出现错误时抛出异常
145
- * @deprecated 请使用异步版本 readFileContent
146
- */
147
- declare function readFileSync(filePath: string): string;
148
70
  /**
149
71
  * 扫描目录中的文件信息
150
72
  */
@@ -177,20 +99,11 @@ interface ScanDirectoryOptions {
177
99
  *
178
100
  * @description 递归遍历指定目录下的所有文件,收集每个文件的大小和扩展名信息,
179
101
  * 支持按扩展名、路径模式和自定义过滤函数进行过滤。
180
- * 这是通用的目录扫描函数,可被不同插件复用。
181
102
  *
182
103
  * @example
183
104
  * ```typescript
184
- * // 扫描所有 .js 文件
185
105
  * const jsFiles = await scanDirectory('dist', { includeExtensions: ['.js'] })
186
- *
187
- * // 排除 node_modules
188
106
  * const files = await scanDirectory('dist', { excludePatterns: ['node_modules'] })
189
- *
190
- * // 使用自定义过滤
191
- * const largeFiles = await scanDirectory('dist', {
192
- * filter: (filePath, ext, size) => size > 1024
193
- * })
194
107
  * ```
195
108
  */
196
109
  declare function scanDirectory(dirPath: string, options?: ScanDirectoryOptions): Promise<ScannedFile[]>;
@@ -209,10 +122,9 @@ declare function scanDirectory(dirPath: string, options?: ScanDirectoryOptions):
209
122
  * @example
210
123
  * ```typescript
211
124
  * await writeJsonReport('dist/report.json', { timestamp: Date.now(), stats: [] })
212
- * await writeJsonReport('dist/report.json', data, 4)
213
125
  * ```
214
126
  */
215
127
  declare function writeJsonReport(filePath: string, data: object, indent?: number): Promise<void>;
216
128
 
217
- export { checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, scanDirectory, shouldUpdateFile, writeFileContent, writeJsonReport };
129
+ export { checkSourceExists, copySourceToTarget, scanDirectory, writeFileContent, writeJsonReport };
218
130
  export type { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile };
@@ -45,75 +45,12 @@ interface CopyResult {
45
45
  executionTime: number;
46
46
  }
47
47
 
48
- /**
49
- * 文件/目录条目信息
50
- */
51
- interface FileEntry {
52
- /** 完整路径 */
53
- path: string;
54
- /** 是否为文件 */
55
- isFile: boolean;
56
- /** 是否为目录 */
57
- isDirectory: boolean;
58
- }
59
48
  /**
60
49
  * 检查源文件是否存在
61
50
  * @param sourcePath 源文件路径
62
51
  * @throws 当源文件不存在或无法访问时抛出异常
63
52
  */
64
53
  declare function checkSourceExists(sourcePath: string): Promise<void>;
65
- /**
66
- * 创建目标目录
67
- * @param targetPath 目标目录路径
68
- * @throws 当无法创建目标目录时抛出异常
69
- */
70
- declare function ensureTargetDir(targetPath: string): Promise<void>;
71
- /**
72
- * 读取目录内容(优化版:一次性获取文件类型信息)
73
- * @param dirPath 目录路径
74
- * @param recursive 是否递归读取
75
- * @returns 文件和目录条目列表
76
- */
77
- declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<FileEntry[]>;
78
- /**
79
- * 检查文件是否需要更新
80
- * @param sourceFile 源文件路径
81
- * @param targetFile 目标文件路径
82
- * @returns 是否需要更新
83
- */
84
- declare function shouldUpdateFile(sourceFile: string, targetFile: string): Promise<boolean>;
85
- /**
86
- * 检查文件是否存在
87
- * @param filePath 文件路径
88
- * @returns 是否存在
89
- *
90
- * @example
91
- * ```typescript
92
- * if (await fileExists('/path/to/file')) {
93
- * console.log('文件存在')
94
- * }
95
- * ```
96
- */
97
- declare function fileExists(filePath: string): Promise<boolean>;
98
- /**
99
- * 带并发限制的批量执行
100
- *
101
- * @param items 待处理项
102
- * @param handler 处理函数
103
- * @param concurrency 并发数
104
- * @returns 处理结果数组,顺序与输入项对应
105
- *
106
- * @example
107
- * ```typescript
108
- * const urls = ['url1', 'url2', 'url3', 'url4', 'url5']
109
- * const results = await runWithConcurrency(
110
- * urls,
111
- * async (url) => fetch(url),
112
- * 3 // 最多同时处理3个请求
113
- * )
114
- * ```
115
- */
116
- declare function runWithConcurrency<T, R>(items: T[], handler: (item: T) => Promise<R>, concurrency: number): Promise<R[]>;
117
54
  /**
118
55
  * 执行文件复制操作(优化版:并行IO)
119
56
  * @param sourcePath 源文件或目录路径
@@ -130,21 +67,6 @@ declare function copySourceToTarget(sourcePath: string, targetPath: string, opti
130
67
  * @throws 当写入过程中出现错误时抛出异常
131
68
  */
132
69
  declare function writeFileContent(filePath: string, content: string): Promise<void>;
133
- /**
134
- * 读取文件内容
135
- * @param filePath 文件路径
136
- * @returns 文件内容字符串
137
- * @throws 当读取过程中出现错误时抛出异常
138
- */
139
- declare function readFileContent(filePath: string): Promise<string>;
140
- /**
141
- * 同步读取文件内容
142
- * @param filePath 文件路径
143
- * @returns 文件内容字符串
144
- * @throws 当读取过程中出现错误时抛出异常
145
- * @deprecated 请使用异步版本 readFileContent
146
- */
147
- declare function readFileSync(filePath: string): string;
148
70
  /**
149
71
  * 扫描目录中的文件信息
150
72
  */
@@ -177,20 +99,11 @@ interface ScanDirectoryOptions {
177
99
  *
178
100
  * @description 递归遍历指定目录下的所有文件,收集每个文件的大小和扩展名信息,
179
101
  * 支持按扩展名、路径模式和自定义过滤函数进行过滤。
180
- * 这是通用的目录扫描函数,可被不同插件复用。
181
102
  *
182
103
  * @example
183
104
  * ```typescript
184
- * // 扫描所有 .js 文件
185
105
  * const jsFiles = await scanDirectory('dist', { includeExtensions: ['.js'] })
186
- *
187
- * // 排除 node_modules
188
106
  * const files = await scanDirectory('dist', { excludePatterns: ['node_modules'] })
189
- *
190
- * // 使用自定义过滤
191
- * const largeFiles = await scanDirectory('dist', {
192
- * filter: (filePath, ext, size) => size > 1024
193
- * })
194
107
  * ```
195
108
  */
196
109
  declare function scanDirectory(dirPath: string, options?: ScanDirectoryOptions): Promise<ScannedFile[]>;
@@ -209,10 +122,9 @@ declare function scanDirectory(dirPath: string, options?: ScanDirectoryOptions):
209
122
  * @example
210
123
  * ```typescript
211
124
  * await writeJsonReport('dist/report.json', { timestamp: Date.now(), stats: [] })
212
- * await writeJsonReport('dist/report.json', data, 4)
213
125
  * ```
214
126
  */
215
127
  declare function writeJsonReport(filePath: string, data: object, indent?: number): Promise<void>;
216
128
 
217
- export { checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, scanDirectory, shouldUpdateFile, writeFileContent, writeJsonReport };
129
+ export { checkSourceExists, copySourceToTarget, scanDirectory, writeFileContent, writeJsonReport };
218
130
  export type { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile };
@@ -1 +1 @@
1
- import r from"fs";import w from"path";const T=10;async function k(u){try{await r.promises.access(u,r.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 D(u){try{await r.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 r.promises.readdir(u,{withFileTypes:!0}),i=[];for(const n of e){const a=w.join(u,n.name),F=n.isFile(),c=n.isDirectory();if(i.push({path:a,isFile:F,isDirectory:c}),c&&t){const E=await h(a,t);i.push(...E)}}return i}async function B(u,t){try{const[e,i]=await Promise.all([r.promises.stat(u),r.promises.stat(t)]);return e.mtimeMs>i.mtimeMs||e.size!==i.size}catch{return!0}}async function C(u){try{return await r.promises.access(u,r.constants.F_OK),!0}catch{return!1}}async function g(u,t,e){const i=[];let n=0;async function a(){for(;n<u.length;){const c=n++,E=await t(u[c]);i[c]=E}}const F=Array(Math.min(e,u.length)).fill(null).map(()=>a());return await Promise.all(F),i}async function v(u,t,e){const i=Date.now(),{recursive:n,overwrite:a,incremental:F=!1,parallelLimit:c=T}=e;let E=0,p=0,l=0;if((await r.promises.stat(u)).isDirectory()){await D(t);const o=await h(u,n),f=o.filter(s=>s.isFile);l=o.filter(s=>s.isDirectory).length;const $=new Set;for(const s of f){const A=w.relative(u,s.path),y=w.dirname(w.join(t,A));$.add(y)}await Promise.all([...$].map(s=>D(s)));const x=await g(f,async s=>{const A=w.relative(u,s.path),y=w.join(t,A);let d=a;return d||(d=!await C(y)),F&&d&&(d=await B(s.path,y)),d?(await r.promises.copyFile(s.path,y),{copied:!0,skipped:!1}):{copied:!1,skipped:!0}},c);for(const s of x)s.copied&&E++,s.skipped&&p++}else{await D(w.dirname(t));let o=a;o||(o=!await C(t)),F&&o&&(o=await B(u,t)),o?(await r.promises.copyFile(u,t),E++):p++}const m=Date.now()-i;return{copiedFiles:E,skippedFiles:p,copiedDirs:l,executionTime:m}}async function S(u,t){try{await r.promises.writeFile(u,t,"utf-8")}catch(e){const i=e;throw i.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${i.message}`)}}async function z(u){try{return await r.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 r.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}`)}}async function j(u,t={}){const{includeExtensions:e=[],excludePatterns:i=[],filter:n}=t,a=[];async function F(c){const E=await r.promises.readdir(c,{withFileTypes:!0});for(const p of E){const l=w.join(c,p.name);if(p.isDirectory()){await F(l);continue}if(!p.isFile()||i.some(f=>f.startsWith("*")?l.endsWith(f.slice(1)):l.includes(f)))continue;const m=w.extname(p.name).toLowerCase();if(e.length>0&&!e.includes(m))continue;const o=await r.promises.stat(l);n&&!n(l,m,o.size)||a.push({filePath:l,size:o.size,extension:m})}}return await F(u),a}async function O(u,t,e=2){await S(u,JSON.stringify(t,null,e))}export{k as checkSourceExists,v as copySourceToTarget,D as ensureTargetDir,C as fileExists,h as readDirRecursive,z as readFileContent,P as readFileSync,g as runWithConcurrency,j as scanDirectory,B as shouldUpdateFile,S as writeFileContent,O as writeJsonReport};
1
+ import n from"fs";import p from"path";const S=10;async function T(t){try{await n.promises.access(t,n.constants.F_OK)}catch(u){const e=u;throw e.code==="ENOENT"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${t}`):e.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6E90\u6587\u4EF6 - ${t}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u68C0\u67E5\u6E90\u6587\u4EF6\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function D(t){try{await n.promises.mkdir(t,{recursive:!0})}catch(u){const e=u;throw e.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u521B\u5EFA\u76EE\u6807\u76EE\u5F55 - ${t}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u521B\u5EFA\u76EE\u6807\u76EE\u5F55\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function C(t,u){const e=await n.promises.readdir(t,{withFileTypes:!0}),i=[];for(const o of e){const r=p.join(t,o.name),F=o.isFile(),c=o.isDirectory();if(i.push({path:r,isFile:F,isDirectory:c}),c&&u){const l=await C(r,u);i.push(...l)}}return i}async function g(t,u){try{const[e,i]=await Promise.all([n.promises.stat(t),n.promises.stat(u)]);return e.mtimeMs>i.mtimeMs||e.size!==i.size}catch{return!0}}async function $(t){try{return await n.promises.access(t,n.constants.F_OK),!0}catch{return!1}}async function k(t,u,e){const i=[];let o=0;async function r(){for(;o<t.length;){const c=o++,l=await u(t[c]);i[c]=l}}const F=Array(Math.min(e,t.length)).fill(null).map(()=>r());return await Promise.all(F),i}async function v(t,u,e){const i=Date.now(),{recursive:o,overwrite:r,incremental:F=!1,parallelLimit:c=S}=e;let l=0,w=0,E=0;if((await n.promises.stat(t)).isDirectory()){await D(u);const a=await C(t,o),f=a.filter(s=>s.isFile);E=a.filter(s=>s.isDirectory).length;const A=new Set;for(const s of f){const h=p.relative(t,s.path),y=p.dirname(p.join(u,h));A.add(y)}await Promise.all([...A].map(s=>D(s)));const B=await k(f,async s=>{const h=p.relative(t,s.path),y=p.join(u,h);let d=r;return d||(d=!await $(y)),F&&d&&(d=await g(s.path,y)),d?(await n.promises.copyFile(s.path,y),{copied:!0,skipped:!1}):{copied:!1,skipped:!0}},c);for(const s of B)s.copied&&l++,s.skipped&&w++}else{await D(p.dirname(u));let a=r;a||(a=!await $(u)),F&&a&&(a=await g(t,u)),a?(await n.promises.copyFile(t,u),l++):w++}const m=Date.now()-i;return{copiedFiles:l,skippedFiles:w,copiedDirs:E,executionTime:m}}async function x(t,u){try{await n.promises.writeFile(t,u,"utf-8")}catch(e){const i=e;throw i.code==="EACCES"?new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u5199\u5165\u6587\u4EF6 - ${t}`):new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u5199\u5165\u6587\u4EF6\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${i.message}`)}}async function z(t,u={}){const{includeExtensions:e=[],excludePatterns:i=[],filter:o}=u,r=[];async function F(c){const l=await n.promises.readdir(c,{withFileTypes:!0});for(const w of l){const E=p.join(c,w.name);if(w.isDirectory()){await F(E);continue}if(!w.isFile()||i.some(f=>f.startsWith("*")?E.endsWith(f.slice(1)):E.includes(f)))continue;const m=p.extname(w.name).toLowerCase();if(e.length>0&&!e.includes(m))continue;const a=await n.promises.stat(E);o&&!o(E,m,a.size)||r.push({filePath:E,size:a.size,extension:m})}}return await F(t),r}async function P(t,u,e=2){await x(t,JSON.stringify(u,null,e))}export{T as checkSourceExists,v as copySourceToTarget,z as scanDirectory,x as writeFileContent,P as writeJsonReport};
@@ -1,2 +1,2 @@
1
- "use strict";function injectBeforeTag(e,t,l){const n=new RegExp(t,"i");return n.test(e)?{html:e.replace(n,`${l}
2
- ${t}`),injected:!0}:{html:e,injected:!1}}function injectHtmlByPriority(e,t,l=["</head>","</body>","</html>"]){for(const n of l){const c=injectBeforeTag(e,n,t);if(c.injected)return c}return{html:e+t,injected:!0}}function injectBeforeTagWithFallback(e,t,l){const n=injectBeforeTag(e,"</body>",t);if(n.injected)return{...n,usedFallback:!1};const c=injectBeforeTag(e,"</html>",t);return c.injected?{...c,usedFallback:!1}:{html:e+t,injected:!0,usedFallback:!0}}function injectHeadAndBody(e,t,l){let n=e,c=!1;if(t){const i=injectBeforeTag(n,"</head>",t);i.injected&&(n=i.html,c=!0)}const r=injectBeforeTagWithFallback(n,l);return{html:r.html,headInjected:c,bodyInjected:r.injected,usedFallback:r.usedFallback}}exports.injectBeforeTag=injectBeforeTag,exports.injectBeforeTagWithFallback=injectBeforeTagWithFallback,exports.injectHeadAndBody=injectHeadAndBody,exports.injectHtmlByPriority=injectHtmlByPriority;
1
+ "use strict";const security=require("../../shared/vite-plugin.CnOy46d3.cjs");function injectBeforeTag(e,t,s){const n=new RegExp(t,"i");return n.test(e)?{html:e.replace(n,`${s}
2
+ ${t}`),injected:!0}:{html:e,injected:!1}}function c(e,t,s){const n=injectBeforeTag(e,"</body>",t);if(n.injected)return{...n,usedFallback:!1};const i=injectBeforeTag(e,"</html>",t);return i.injected?{...i,usedFallback:!1}:{html:e+t,injected:!0,usedFallback:!0}}function injectHeadAndBody(e,t,s){let n=e,i=!1;if(t){const d=injectBeforeTag(n,"</head>",t);d.injected&&(n=d.html,i=!0)}const l=c(n,s);return{html:l.html,headInjected:i,bodyInjected:l.injected,usedFallback:l.usedFallback}}exports.sanitizeContent=security.sanitizeContent,exports.injectBeforeTag=injectBeforeTag,exports.injectHeadAndBody=injectHeadAndBody;
@@ -1,25 +1,25 @@
1
+ import { S as SecurityConfig, H as HtmlInjectResult, D as DualInjectResult } from '../../shared/vite-plugin.BI9taN75.cjs';
2
+ export { C as ConditionType, I as InjectCondition, a as InjectPosition, b as SelectorMatch } from '../../shared/vite-plugin.BI9taN75.cjs';
3
+
1
4
  /**
2
- * HTML 注入结果
5
+ * 内容消毒规则选项
3
6
  */
4
- interface HtmlInjectResult {
5
- /** 注入后的 HTML 内容 */
6
- html: string;
7
- /** 是否成功注入 */
8
- injected: boolean;
7
+ interface SanitizeRuleOptions {
8
+ id?: string;
9
+ allowScriptInjection?: boolean;
9
10
  }
10
11
  /**
11
- * 双区域 HTML 注入结果
12
+ * 对注入内容进行安全过滤
13
+ *
14
+ * @param content - 待过滤的 HTML 内容字符串
15
+ * @param rule - 当前注入规则的消毒选项
16
+ * @param security - 全局安全配置
17
+ * @param logger - 日志记录器
18
+ * @returns 过滤后的安全 HTML 内容字符串
12
19
  */
13
- interface DualInjectResult {
14
- /** 注入后的 HTML 内容 */
15
- html: string;
16
- /** head 区域是否成功注入 */
17
- headInjected: boolean;
18
- /** body 区域是否成功注入 */
19
- bodyInjected: boolean;
20
- /** body 注入是否使用了回退策略(追加到末尾) */
21
- usedFallback: boolean;
22
- }
20
+ declare function sanitizeContent(content: string, rule: SanitizeRuleOptions, security?: SecurityConfig, logger?: {
21
+ warn: (msg: string) => void;
22
+ }): string;
23
23
 
24
24
  /**
25
25
  * 在 HTML 中指定闭合标签前注入代码
@@ -28,59 +28,8 @@ interface DualInjectResult {
28
28
  * @param tag - 目标闭合标签(如 `</head>`、`</body>`、`</html>`)
29
29
  * @param code - 要注入的代码
30
30
  * @returns 注入结果对象
31
- *
32
- * @example
33
- * ```typescript
34
- * // 在 </head> 前注入 CSS
35
- * const result = injectBeforeTag(html, '</head>', '<style>...</style>')
36
- *
37
- * // 在 </body> 前注入 JS
38
- * const result = injectBeforeTag(html, '</body>', '<script>...</script>')
39
- * ```
40
31
  */
41
32
  declare function injectBeforeTag(html: string, tag: string, code: string): HtmlInjectResult;
42
- /**
43
- * 按优先级向 HTML 中注入代码
44
- *
45
- * @description 依次尝试在 `</head>`、`</body>`、`</html>` 前注入代码,
46
- * 优先注入到靠前的标签位置。适用于需要注入到页面中但无特定位置要求的场景
47
- *
48
- * @param html - 原始 HTML 内容
49
- * @param code - 要注入的代码
50
- * @param targets - 目标标签优先级列表,默认为 `['</head>', '</body>', '</html>']`
51
- * @returns 注入结果对象
52
- *
53
- * @example
54
- * ```typescript
55
- * // 优先注入到 </body> 前
56
- * const result = injectHtmlByPriority(html, scriptCode, ['</body>', '</html>'])
57
- * ```
58
- */
59
- declare function injectHtmlByPriority(html: string, code: string, targets?: string[]): HtmlInjectResult;
60
- /**
61
- * 带回退策略的 HTML 注入
62
- *
63
- * @description 依次尝试在 `</body>`、`</html>` 前注入代码,
64
- * 如果均未找到目标标签,则将代码追加到 HTML 末尾。
65
- * 适用于需要注入到页面底部但不确定 HTML 结构是否完整的场景。
66
- *
67
- * @param html - 原始 HTML 内容
68
- * @param code - 要注入的代码
69
- * @param fallbackMessage - 回退到末尾时的警告信息,为空则不输出警告
70
- * @returns 注入结果对象,包含注入后的 HTML、是否成功标志和是否使用了回退策略
71
- *
72
- * @example
73
- * ```typescript
74
- * // 注入 JS 脚本到页面底部
75
- * const result = injectBeforeTagWithFallback(html, '<script>...</script>')
76
- *
77
- * // 带自定义警告信息
78
- * const result = injectBeforeTagWithFallback(html, scriptCode, '未找到 </body> 标签,代码追加到文件末尾')
79
- * ```
80
- */
81
- declare function injectBeforeTagWithFallback(html: string, code: string, _fallbackMessage?: string): HtmlInjectResult & {
82
- usedFallback: boolean;
83
- };
84
33
  /**
85
34
  * 双区域 HTML 注入(head + body)
86
35
  *
@@ -91,19 +40,8 @@ declare function injectBeforeTagWithFallback(html: string, code: string, _fallba
91
40
  * @param headCode - 注入到 `</head>` 前的代码(如 CSS、meta 标签),不提供则跳过 head 注入
92
41
  * @param bodyCode - 注入到 `</body>` 前的代码(如 JS 脚本),回退到 `</html>` 前或末尾
93
42
  * @returns 双区域注入结果对象
94
- *
95
- * @example
96
- * ```typescript
97
- * // CSS 注入到 head,JS 注入到 body
98
- * const result = injectHeadAndBody(html, '<style>...</style>', '<script>...</script>')
99
- * if (!result.headInjected) logger.warn('未找到 </head> 标签')
100
- * if (result.usedFallback) logger.warn('代码追加到文件末尾')
101
- *
102
- * // 仅注入到 body
103
- * const result = injectHeadAndBody(html, undefined, '<script>...</script>')
104
- * ```
105
43
  */
106
44
  declare function injectHeadAndBody(html: string, headCode: string | undefined, bodyCode: string): DualInjectResult;
107
45
 
108
- export { injectBeforeTag, injectBeforeTagWithFallback, injectHeadAndBody, injectHtmlByPriority };
109
- export type { DualInjectResult, HtmlInjectResult };
46
+ export { DualInjectResult, HtmlInjectResult, SecurityConfig, injectBeforeTag, injectHeadAndBody, sanitizeContent };
47
+ export type { SanitizeRuleOptions };
@@ -1,25 +1,25 @@
1
+ import { S as SecurityConfig, H as HtmlInjectResult, D as DualInjectResult } from '../../shared/vite-plugin.BI9taN75.mjs';
2
+ export { C as ConditionType, I as InjectCondition, a as InjectPosition, b as SelectorMatch } from '../../shared/vite-plugin.BI9taN75.mjs';
3
+
1
4
  /**
2
- * HTML 注入结果
5
+ * 内容消毒规则选项
3
6
  */
4
- interface HtmlInjectResult {
5
- /** 注入后的 HTML 内容 */
6
- html: string;
7
- /** 是否成功注入 */
8
- injected: boolean;
7
+ interface SanitizeRuleOptions {
8
+ id?: string;
9
+ allowScriptInjection?: boolean;
9
10
  }
10
11
  /**
11
- * 双区域 HTML 注入结果
12
+ * 对注入内容进行安全过滤
13
+ *
14
+ * @param content - 待过滤的 HTML 内容字符串
15
+ * @param rule - 当前注入规则的消毒选项
16
+ * @param security - 全局安全配置
17
+ * @param logger - 日志记录器
18
+ * @returns 过滤后的安全 HTML 内容字符串
12
19
  */
13
- interface DualInjectResult {
14
- /** 注入后的 HTML 内容 */
15
- html: string;
16
- /** head 区域是否成功注入 */
17
- headInjected: boolean;
18
- /** body 区域是否成功注入 */
19
- bodyInjected: boolean;
20
- /** body 注入是否使用了回退策略(追加到末尾) */
21
- usedFallback: boolean;
22
- }
20
+ declare function sanitizeContent(content: string, rule: SanitizeRuleOptions, security?: SecurityConfig, logger?: {
21
+ warn: (msg: string) => void;
22
+ }): string;
23
23
 
24
24
  /**
25
25
  * 在 HTML 中指定闭合标签前注入代码
@@ -28,59 +28,8 @@ interface DualInjectResult {
28
28
  * @param tag - 目标闭合标签(如 `</head>`、`</body>`、`</html>`)
29
29
  * @param code - 要注入的代码
30
30
  * @returns 注入结果对象
31
- *
32
- * @example
33
- * ```typescript
34
- * // 在 </head> 前注入 CSS
35
- * const result = injectBeforeTag(html, '</head>', '<style>...</style>')
36
- *
37
- * // 在 </body> 前注入 JS
38
- * const result = injectBeforeTag(html, '</body>', '<script>...</script>')
39
- * ```
40
31
  */
41
32
  declare function injectBeforeTag(html: string, tag: string, code: string): HtmlInjectResult;
42
- /**
43
- * 按优先级向 HTML 中注入代码
44
- *
45
- * @description 依次尝试在 `</head>`、`</body>`、`</html>` 前注入代码,
46
- * 优先注入到靠前的标签位置。适用于需要注入到页面中但无特定位置要求的场景
47
- *
48
- * @param html - 原始 HTML 内容
49
- * @param code - 要注入的代码
50
- * @param targets - 目标标签优先级列表,默认为 `['</head>', '</body>', '</html>']`
51
- * @returns 注入结果对象
52
- *
53
- * @example
54
- * ```typescript
55
- * // 优先注入到 </body> 前
56
- * const result = injectHtmlByPriority(html, scriptCode, ['</body>', '</html>'])
57
- * ```
58
- */
59
- declare function injectHtmlByPriority(html: string, code: string, targets?: string[]): HtmlInjectResult;
60
- /**
61
- * 带回退策略的 HTML 注入
62
- *
63
- * @description 依次尝试在 `</body>`、`</html>` 前注入代码,
64
- * 如果均未找到目标标签,则将代码追加到 HTML 末尾。
65
- * 适用于需要注入到页面底部但不确定 HTML 结构是否完整的场景。
66
- *
67
- * @param html - 原始 HTML 内容
68
- * @param code - 要注入的代码
69
- * @param fallbackMessage - 回退到末尾时的警告信息,为空则不输出警告
70
- * @returns 注入结果对象,包含注入后的 HTML、是否成功标志和是否使用了回退策略
71
- *
72
- * @example
73
- * ```typescript
74
- * // 注入 JS 脚本到页面底部
75
- * const result = injectBeforeTagWithFallback(html, '<script>...</script>')
76
- *
77
- * // 带自定义警告信息
78
- * const result = injectBeforeTagWithFallback(html, scriptCode, '未找到 </body> 标签,代码追加到文件末尾')
79
- * ```
80
- */
81
- declare function injectBeforeTagWithFallback(html: string, code: string, _fallbackMessage?: string): HtmlInjectResult & {
82
- usedFallback: boolean;
83
- };
84
33
  /**
85
34
  * 双区域 HTML 注入(head + body)
86
35
  *
@@ -91,19 +40,8 @@ declare function injectBeforeTagWithFallback(html: string, code: string, _fallba
91
40
  * @param headCode - 注入到 `</head>` 前的代码(如 CSS、meta 标签),不提供则跳过 head 注入
92
41
  * @param bodyCode - 注入到 `</body>` 前的代码(如 JS 脚本),回退到 `</html>` 前或末尾
93
42
  * @returns 双区域注入结果对象
94
- *
95
- * @example
96
- * ```typescript
97
- * // CSS 注入到 head,JS 注入到 body
98
- * const result = injectHeadAndBody(html, '<style>...</style>', '<script>...</script>')
99
- * if (!result.headInjected) logger.warn('未找到 </head> 标签')
100
- * if (result.usedFallback) logger.warn('代码追加到文件末尾')
101
- *
102
- * // 仅注入到 body
103
- * const result = injectHeadAndBody(html, undefined, '<script>...</script>')
104
- * ```
105
43
  */
106
44
  declare function injectHeadAndBody(html: string, headCode: string | undefined, bodyCode: string): DualInjectResult;
107
45
 
108
- export { injectBeforeTag, injectBeforeTagWithFallback, injectHeadAndBody, injectHtmlByPriority };
109
- export type { DualInjectResult, HtmlInjectResult };
46
+ export { DualInjectResult, HtmlInjectResult, SecurityConfig, injectBeforeTag, injectHeadAndBody, sanitizeContent };
47
+ export type { SanitizeRuleOptions };
@@ -1,25 +1,25 @@
1
+ import { S as SecurityConfig, H as HtmlInjectResult, D as DualInjectResult } from '../../shared/vite-plugin.BI9taN75.js';
2
+ export { C as ConditionType, I as InjectCondition, a as InjectPosition, b as SelectorMatch } from '../../shared/vite-plugin.BI9taN75.js';
3
+
1
4
  /**
2
- * HTML 注入结果
5
+ * 内容消毒规则选项
3
6
  */
4
- interface HtmlInjectResult {
5
- /** 注入后的 HTML 内容 */
6
- html: string;
7
- /** 是否成功注入 */
8
- injected: boolean;
7
+ interface SanitizeRuleOptions {
8
+ id?: string;
9
+ allowScriptInjection?: boolean;
9
10
  }
10
11
  /**
11
- * 双区域 HTML 注入结果
12
+ * 对注入内容进行安全过滤
13
+ *
14
+ * @param content - 待过滤的 HTML 内容字符串
15
+ * @param rule - 当前注入规则的消毒选项
16
+ * @param security - 全局安全配置
17
+ * @param logger - 日志记录器
18
+ * @returns 过滤后的安全 HTML 内容字符串
12
19
  */
13
- interface DualInjectResult {
14
- /** 注入后的 HTML 内容 */
15
- html: string;
16
- /** head 区域是否成功注入 */
17
- headInjected: boolean;
18
- /** body 区域是否成功注入 */
19
- bodyInjected: boolean;
20
- /** body 注入是否使用了回退策略(追加到末尾) */
21
- usedFallback: boolean;
22
- }
20
+ declare function sanitizeContent(content: string, rule: SanitizeRuleOptions, security?: SecurityConfig, logger?: {
21
+ warn: (msg: string) => void;
22
+ }): string;
23
23
 
24
24
  /**
25
25
  * 在 HTML 中指定闭合标签前注入代码
@@ -28,59 +28,8 @@ interface DualInjectResult {
28
28
  * @param tag - 目标闭合标签(如 `</head>`、`</body>`、`</html>`)
29
29
  * @param code - 要注入的代码
30
30
  * @returns 注入结果对象
31
- *
32
- * @example
33
- * ```typescript
34
- * // 在 </head> 前注入 CSS
35
- * const result = injectBeforeTag(html, '</head>', '<style>...</style>')
36
- *
37
- * // 在 </body> 前注入 JS
38
- * const result = injectBeforeTag(html, '</body>', '<script>...</script>')
39
- * ```
40
31
  */
41
32
  declare function injectBeforeTag(html: string, tag: string, code: string): HtmlInjectResult;
42
- /**
43
- * 按优先级向 HTML 中注入代码
44
- *
45
- * @description 依次尝试在 `</head>`、`</body>`、`</html>` 前注入代码,
46
- * 优先注入到靠前的标签位置。适用于需要注入到页面中但无特定位置要求的场景
47
- *
48
- * @param html - 原始 HTML 内容
49
- * @param code - 要注入的代码
50
- * @param targets - 目标标签优先级列表,默认为 `['</head>', '</body>', '</html>']`
51
- * @returns 注入结果对象
52
- *
53
- * @example
54
- * ```typescript
55
- * // 优先注入到 </body> 前
56
- * const result = injectHtmlByPriority(html, scriptCode, ['</body>', '</html>'])
57
- * ```
58
- */
59
- declare function injectHtmlByPriority(html: string, code: string, targets?: string[]): HtmlInjectResult;
60
- /**
61
- * 带回退策略的 HTML 注入
62
- *
63
- * @description 依次尝试在 `</body>`、`</html>` 前注入代码,
64
- * 如果均未找到目标标签,则将代码追加到 HTML 末尾。
65
- * 适用于需要注入到页面底部但不确定 HTML 结构是否完整的场景。
66
- *
67
- * @param html - 原始 HTML 内容
68
- * @param code - 要注入的代码
69
- * @param fallbackMessage - 回退到末尾时的警告信息,为空则不输出警告
70
- * @returns 注入结果对象,包含注入后的 HTML、是否成功标志和是否使用了回退策略
71
- *
72
- * @example
73
- * ```typescript
74
- * // 注入 JS 脚本到页面底部
75
- * const result = injectBeforeTagWithFallback(html, '<script>...</script>')
76
- *
77
- * // 带自定义警告信息
78
- * const result = injectBeforeTagWithFallback(html, scriptCode, '未找到 </body> 标签,代码追加到文件末尾')
79
- * ```
80
- */
81
- declare function injectBeforeTagWithFallback(html: string, code: string, _fallbackMessage?: string): HtmlInjectResult & {
82
- usedFallback: boolean;
83
- };
84
33
  /**
85
34
  * 双区域 HTML 注入(head + body)
86
35
  *
@@ -91,19 +40,8 @@ declare function injectBeforeTagWithFallback(html: string, code: string, _fallba
91
40
  * @param headCode - 注入到 `</head>` 前的代码(如 CSS、meta 标签),不提供则跳过 head 注入
92
41
  * @param bodyCode - 注入到 `</body>` 前的代码(如 JS 脚本),回退到 `</html>` 前或末尾
93
42
  * @returns 双区域注入结果对象
94
- *
95
- * @example
96
- * ```typescript
97
- * // CSS 注入到 head,JS 注入到 body
98
- * const result = injectHeadAndBody(html, '<style>...</style>', '<script>...</script>')
99
- * if (!result.headInjected) logger.warn('未找到 </head> 标签')
100
- * if (result.usedFallback) logger.warn('代码追加到文件末尾')
101
- *
102
- * // 仅注入到 body
103
- * const result = injectHeadAndBody(html, undefined, '<script>...</script>')
104
- * ```
105
43
  */
106
44
  declare function injectHeadAndBody(html: string, headCode: string | undefined, bodyCode: string): DualInjectResult;
107
45
 
108
- export { injectBeforeTag, injectBeforeTagWithFallback, injectHeadAndBody, injectHtmlByPriority };
109
- export type { DualInjectResult, HtmlInjectResult };
46
+ export { DualInjectResult, HtmlInjectResult, SecurityConfig, injectBeforeTag, injectHeadAndBody, sanitizeContent };
47
+ export type { SanitizeRuleOptions };