@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.
- package/README-en.md +49 -775
- package/README.md +46 -770
- package/dist/common/format/index.cjs +1 -1
- package/dist/common/format/index.d.cts +1 -130
- package/dist/common/format/index.d.mts +1 -130
- package/dist/common/format/index.d.ts +1 -130
- package/dist/common/format/index.mjs +1 -1
- package/dist/common/fs/index.cjs +1 -1
- package/dist/common/fs/index.d.cts +1 -89
- package/dist/common/fs/index.d.mts +1 -89
- package/dist/common/fs/index.d.ts +1 -89
- package/dist/common/fs/index.mjs +1 -1
- package/dist/common/html/index.cjs +2 -2
- package/dist/common/html/index.d.cts +19 -81
- package/dist/common/html/index.d.mts +19 -81
- package/dist/common/html/index.d.ts +19 -81
- package/dist/common/html/index.mjs +2 -2
- package/dist/common/index.cjs +1 -1
- package/dist/common/index.d.cts +7 -8
- package/dist/common/index.d.mts +7 -8
- package/dist/common/index.d.ts +7 -8
- package/dist/common/index.mjs +1 -1
- package/dist/common/script/index.cjs +1 -1
- package/dist/common/script/index.d.cts +1 -44
- package/dist/common/script/index.d.mts +1 -44
- package/dist/common/script/index.d.ts +1 -44
- package/dist/common/script/index.mjs +1 -1
- package/dist/common/ui/index.cjs +1 -0
- package/dist/common/ui/index.d.cts +22 -0
- package/dist/common/ui/index.d.mts +22 -0
- package/dist/common/ui/index.d.ts +22 -0
- package/dist/common/ui/index.mjs +1 -0
- package/dist/common/validation/index.cjs +1 -1
- package/dist/common/validation/index.d.cts +2 -79
- package/dist/common/validation/index.d.mts +2 -79
- package/dist/common/validation/index.d.ts +2 -79
- package/dist/common/validation/index.mjs +1 -1
- package/dist/factory/index.cjs +1 -1
- package/dist/factory/index.d.cts +1 -1
- package/dist/factory/index.d.mts +1 -1
- package/dist/factory/index.d.ts +1 -1
- package/dist/factory/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +12 -10
- package/dist/index.d.mts +12 -10
- package/dist/index.d.ts +12 -10
- package/dist/index.mjs +1 -1
- package/dist/logger/index.d.cts +92 -1
- package/dist/logger/index.d.mts +92 -1
- package/dist/logger/index.d.ts +92 -1
- package/dist/plugins/autoImport/index.cjs +17 -0
- package/dist/plugins/autoImport/index.d.cts +291 -0
- package/dist/plugins/autoImport/index.d.mts +291 -0
- package/dist/plugins/autoImport/index.d.ts +291 -0
- package/dist/plugins/autoImport/index.mjs +17 -0
- package/dist/plugins/buildProgress/index.cjs +2 -2
- package/dist/plugins/buildProgress/index.d.cts +1 -1
- package/dist/plugins/buildProgress/index.d.mts +1 -1
- package/dist/plugins/buildProgress/index.d.ts +1 -1
- package/dist/plugins/buildProgress/index.mjs +2 -2
- package/dist/plugins/bundleAnalyzer/index.cjs +11 -11
- package/dist/plugins/bundleAnalyzer/index.d.cts +1 -1
- package/dist/plugins/bundleAnalyzer/index.d.mts +1 -1
- package/dist/plugins/bundleAnalyzer/index.d.ts +1 -1
- package/dist/plugins/bundleAnalyzer/index.mjs +18 -18
- package/dist/plugins/compressAssets/index.cjs +1 -1
- package/dist/plugins/compressAssets/index.d.cts +1 -1
- package/dist/plugins/compressAssets/index.d.mts +1 -1
- package/dist/plugins/compressAssets/index.d.ts +1 -1
- package/dist/plugins/compressAssets/index.mjs +1 -1
- package/dist/plugins/copyFile/index.cjs +1 -1
- package/dist/plugins/copyFile/index.d.cts +21 -3
- package/dist/plugins/copyFile/index.d.mts +21 -3
- package/dist/plugins/copyFile/index.d.ts +21 -3
- package/dist/plugins/copyFile/index.mjs +1 -1
- package/dist/plugins/envGuard/index.cjs +67 -0
- package/dist/plugins/envGuard/index.d.cts +255 -0
- package/dist/plugins/envGuard/index.d.mts +255 -0
- package/dist/plugins/envGuard/index.d.ts +255 -0
- package/dist/plugins/envGuard/index.mjs +67 -0
- package/dist/plugins/faviconManager/index.cjs +1 -1
- package/dist/plugins/faviconManager/index.d.cts +44 -6
- package/dist/plugins/faviconManager/index.d.mts +44 -6
- package/dist/plugins/faviconManager/index.d.ts +44 -6
- package/dist/plugins/faviconManager/index.mjs +1 -1
- package/dist/plugins/generateRouter/index.cjs +4 -4
- package/dist/plugins/generateRouter/index.d.cts +62 -15
- package/dist/plugins/generateRouter/index.d.mts +62 -15
- package/dist/plugins/generateRouter/index.d.ts +62 -15
- package/dist/plugins/generateRouter/index.mjs +4 -4
- package/dist/plugins/generateVersion/index.cjs +1 -1
- package/dist/plugins/generateVersion/index.d.cts +13 -1
- package/dist/plugins/generateVersion/index.d.mts +13 -1
- package/dist/plugins/generateVersion/index.d.ts +13 -1
- package/dist/plugins/generateVersion/index.mjs +1 -1
- package/dist/plugins/htmlInject/index.cjs +7 -7
- package/dist/plugins/htmlInject/index.d.cts +50 -195
- package/dist/plugins/htmlInject/index.d.mts +50 -195
- package/dist/plugins/htmlInject/index.d.ts +50 -195
- package/dist/plugins/htmlInject/index.mjs +7 -7
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +5 -2
- package/dist/plugins/index.d.mts +5 -2
- package/dist/plugins/index.d.ts +5 -2
- package/dist/plugins/index.mjs +1 -1
- package/dist/plugins/loadingManager/index.cjs +26 -26
- package/dist/plugins/loadingManager/index.d.cts +1 -1
- package/dist/plugins/loadingManager/index.d.mts +1 -1
- package/dist/plugins/loadingManager/index.d.ts +1 -1
- package/dist/plugins/loadingManager/index.mjs +11 -11
- package/dist/plugins/versionUpdateChecker/index.cjs +1 -1
- package/dist/plugins/versionUpdateChecker/index.d.cts +1 -1
- package/dist/plugins/versionUpdateChecker/index.d.mts +1 -1
- package/dist/plugins/versionUpdateChecker/index.d.ts +1 -1
- package/dist/plugins/versionUpdateChecker/index.mjs +1 -1
- package/dist/shared/vite-plugin.B8FuZce1.d.cts +45 -0
- package/dist/shared/vite-plugin.B8FuZce1.d.mts +45 -0
- package/dist/shared/vite-plugin.B8FuZce1.d.ts +45 -0
- package/dist/shared/vite-plugin.BI9taN75.d.cts +122 -0
- package/dist/shared/vite-plugin.BI9taN75.d.mts +122 -0
- package/dist/shared/vite-plugin.BI9taN75.d.ts +122 -0
- package/dist/shared/vite-plugin.BPFqtmWa.mjs +1 -0
- package/dist/shared/vite-plugin.CnOy46d3.cjs +1 -0
- package/package.json +16 -16
- package/dist/common/compress/index.cjs +0 -1
- package/dist/common/compress/index.d.cts +0 -23
- package/dist/common/compress/index.d.mts +0 -23
- package/dist/common/compress/index.d.ts +0 -23
- package/dist/common/compress/index.mjs +0 -1
- package/dist/common/object/index.cjs +0 -1
- package/dist/common/object/index.d.cts +0 -30
- package/dist/common/object/index.d.mts +0 -30
- package/dist/common/object/index.d.ts +0 -30
- package/dist/common/object/index.mjs +0 -1
- package/dist/common/path/index.cjs +0 -1
- package/dist/common/path/index.d.cts +0 -22
- package/dist/common/path/index.d.mts +0 -22
- package/dist/common/path/index.d.ts +0 -22
- package/dist/common/path/index.mjs +0 -1
- package/dist/shared/vite-plugin.CLr0ttuO.d.cts +0 -135
- package/dist/shared/vite-plugin.CLr0ttuO.d.mts +0 -135
- package/dist/shared/vite-plugin.CLr0ttuO.d.ts +0 -135
|
@@ -1,239 +1,94 @@
|
|
|
1
1
|
import { BasePluginOptions, PluginFactory } from '../../factory/index.js';
|
|
2
|
+
import { a as InjectPosition, b as SelectorMatch, I as InjectCondition, S as SecurityConfig } from '../../shared/vite-plugin.BI9taN75.js';
|
|
2
3
|
import 'vite';
|
|
3
|
-
import '../../shared/vite-plugin.
|
|
4
|
+
import '../../shared/vite-plugin.B8FuZce1.js';
|
|
4
5
|
import '../../shared/vite-plugin.DRRlWY8P.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @description
|
|
10
|
-
* - 'string': 使用字符串精确匹配(默认)
|
|
11
|
-
* - 'regex': 使用正则表达式匹配,支持更灵活的模式
|
|
12
|
-
*/
|
|
13
|
-
type SelectorMatch = 'string' | 'regex';
|
|
14
|
-
/**
|
|
15
|
-
* HTML 内容注入位置
|
|
16
|
-
*
|
|
17
|
-
* @description
|
|
18
|
-
* - 'head-start': 注入到 `<head>` 标签开始之后
|
|
19
|
-
* - 'head-end': 注入到 `</head>` 标签之前
|
|
20
|
-
* - 'body-start': 注入到 `<body>` 标签开始之后
|
|
21
|
-
* - 'body-end': 注入到 `</body>` 标签之前
|
|
22
|
-
* - 'before-selector': 注入到指定选择器之前
|
|
23
|
-
* - 'after-selector': 注入到指定选择器之后
|
|
24
|
-
* - 'replace-selector': 替换指定选择器匹配的内容
|
|
25
|
-
*/
|
|
26
|
-
type InjectPosition = 'head-start' | 'head-end' | 'body-start' | 'body-end' | 'before-selector' | 'after-selector' | 'replace-selector';
|
|
27
|
-
/**
|
|
28
|
-
* 条件类型
|
|
29
|
-
*
|
|
30
|
-
* @description
|
|
31
|
-
* - 'env': 基于环境变量判断
|
|
32
|
-
* - 'file-contains': 基于 HTML 文件内容判断
|
|
33
|
-
* - 'custom': 基于自定义函数判断
|
|
34
|
-
*/
|
|
35
|
-
type ConditionType = 'env' | 'file-contains' | 'custom';
|
|
36
|
-
/**
|
|
37
|
-
* 注入条件接口
|
|
38
|
-
*
|
|
39
|
-
* @interface InjectCondition
|
|
40
|
-
* @description 定义内容注入的触发条件,支持环境变量检测、文件内容检测和自定义函数
|
|
41
|
-
*/
|
|
42
|
-
interface InjectCondition {
|
|
43
|
-
/**
|
|
44
|
-
* 条件类型
|
|
45
|
-
*/
|
|
46
|
-
type: ConditionType;
|
|
47
|
-
/**
|
|
48
|
-
* 条件值
|
|
49
|
-
*
|
|
50
|
-
* @description
|
|
51
|
-
* - 当 type 为 'env' 时,为环境变量名(字符串)
|
|
52
|
-
* - 当 type 为 'file-contains' 时,为要搜索的字符串(字符串)
|
|
53
|
-
* - 当 type 为 'custom' 时,为返回布尔值的判断函数
|
|
54
|
-
*/
|
|
55
|
-
value: string | ((...args: any[]) => boolean);
|
|
56
|
-
/**
|
|
57
|
-
* 是否对条件结果取反
|
|
58
|
-
*
|
|
59
|
-
* @default false
|
|
60
|
-
*/
|
|
61
|
-
negate?: boolean;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* 注入规则接口
|
|
8
|
+
* HTML 注入规则接口
|
|
65
9
|
*
|
|
66
10
|
* @interface InjectRule
|
|
67
|
-
* @description 定义单条 HTML
|
|
11
|
+
* @description 定义单条 HTML 内容注入规则,包含注入内容、位置、条件和安全配置。
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* {
|
|
16
|
+
* id: 'meta-viewport',
|
|
17
|
+
* content: '<meta name="viewport" content="width=device-width">',
|
|
18
|
+
* position: 'head-end',
|
|
19
|
+
* priority: 10
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
68
22
|
*/
|
|
69
23
|
interface InjectRule {
|
|
70
|
-
/**
|
|
71
|
-
* 规则唯一标识符,用于日志记录和调试
|
|
72
|
-
*/
|
|
24
|
+
/** 规则唯一标识,用于日志输出和调试追踪 */
|
|
73
25
|
id?: string;
|
|
74
|
-
/**
|
|
75
|
-
* 要注入的 HTML 内容
|
|
76
|
-
*
|
|
77
|
-
* @example '<meta name="description" content="My App">'
|
|
78
|
-
*/
|
|
26
|
+
/** 要注入的 HTML 内容字符串,支持模板变量占位符 `{{varName}}` */
|
|
79
27
|
content: string;
|
|
80
|
-
/**
|
|
81
|
-
* 注入位置
|
|
82
|
-
*/
|
|
28
|
+
/** 注入位置,如 'head-start'、'head-end'、'body-start'、'body-end' 等 */
|
|
83
29
|
position: InjectPosition;
|
|
84
|
-
/**
|
|
85
|
-
* 选择器字符串,当 position 为 selector 相关位置时必填
|
|
86
|
-
*
|
|
87
|
-
* @description 当 selectorMatch 为 'string' 时,使用字符串精确匹配;
|
|
88
|
-
* 当 selectorMatch 为 'regex' 时,使用正则表达式匹配
|
|
89
|
-
*
|
|
90
|
-
* @example '<div id="app">'
|
|
91
|
-
*/
|
|
30
|
+
/** CSS 选择器,仅在 position 为 'before-selector' 或 'after-selector' 时需要 */
|
|
92
31
|
selector?: string;
|
|
93
|
-
/**
|
|
94
|
-
* 选择器匹配模式
|
|
95
|
-
*
|
|
96
|
-
* @default 'string'
|
|
97
|
-
*/
|
|
32
|
+
/** 选择器匹配模式,仅在指定 selector 时有效 */
|
|
98
33
|
selectorMatch?: SelectorMatch;
|
|
99
|
-
/**
|
|
100
|
-
* 规则优先级,数值越小优先级越高,越先执行
|
|
101
|
-
*
|
|
102
|
-
* @default 100
|
|
103
|
-
*/
|
|
34
|
+
/** 规则优先级,数值越大越先执行 */
|
|
104
35
|
priority?: number;
|
|
105
|
-
/**
|
|
106
|
-
* 注入条件,满足条件时才执行注入
|
|
107
|
-
*/
|
|
36
|
+
/** 条件注入配置,满足条件时才执行注入 */
|
|
108
37
|
condition?: InjectCondition;
|
|
109
|
-
/**
|
|
110
|
-
* 规则级模板变量,会覆盖全局模板变量
|
|
111
|
-
*
|
|
112
|
-
* @description 使用 `{{变量名}}` 语法在 content 中引用变量
|
|
113
|
-
*
|
|
114
|
-
* @example { greeting: 'Hello', name: 'World' }
|
|
115
|
-
*/
|
|
38
|
+
/** 规则级别的模板变量,会与全局 templateVars 合并 */
|
|
116
39
|
templateVars?: Record<string, string>;
|
|
117
|
-
/**
|
|
118
|
-
* 是否允许注入脚本等危险内容
|
|
119
|
-
*
|
|
120
|
-
* @default false
|
|
121
|
-
* @remarks 启用此选项将跳过安全检查,请确保注入内容来源可信
|
|
122
|
-
*/
|
|
40
|
+
/** 是否允许注入 `<script>` 标签,默认为 false 以防止 XSS 攻击 */
|
|
123
41
|
allowScriptInjection?: boolean;
|
|
124
42
|
}
|
|
125
|
-
/**
|
|
126
|
-
* 安全配置接口
|
|
127
|
-
*
|
|
128
|
-
* @interface SecurityConfig
|
|
129
|
-
* @description 控制 HTML 注入内容的安全过滤行为,防止 XSS 攻击
|
|
130
|
-
*/
|
|
131
|
-
interface SecurityConfig {
|
|
132
|
-
/**
|
|
133
|
-
* 是否阻止危险标签(script、iframe、object 等)
|
|
134
|
-
*
|
|
135
|
-
* @default true
|
|
136
|
-
*/
|
|
137
|
-
blockDangerousTags?: boolean;
|
|
138
|
-
/**
|
|
139
|
-
* 是否阻止危险属性(onclick、onload 等事件处理器)
|
|
140
|
-
*
|
|
141
|
-
* @default true
|
|
142
|
-
*/
|
|
143
|
-
blockDangerousAttributes?: boolean;
|
|
144
|
-
/**
|
|
145
|
-
* 允许通过的标签白名单,白名单中的标签不会被阻止
|
|
146
|
-
*
|
|
147
|
-
* @example ['iframe', 'object']
|
|
148
|
-
*/
|
|
149
|
-
allowedTags?: string[];
|
|
150
|
-
/**
|
|
151
|
-
* 自定义阻止标签列表,覆盖默认阻止列表
|
|
152
|
-
*
|
|
153
|
-
* @example ['div', 'span']
|
|
154
|
-
*/
|
|
155
|
-
blockedTags?: string[];
|
|
156
|
-
/**
|
|
157
|
-
* 自定义阻止属性列表,覆盖默认阻止列表
|
|
158
|
-
*
|
|
159
|
-
* @example ['data-custom', 'data-track']
|
|
160
|
-
*/
|
|
161
|
-
blockedAttributes?: string[];
|
|
162
|
-
}
|
|
163
43
|
/**
|
|
164
44
|
* 注入日志条目接口
|
|
165
45
|
*
|
|
166
46
|
* @interface InjectionLogEntry
|
|
167
|
-
* @description
|
|
47
|
+
* @description 记录单条注入规则的执行结果,用于调试和统计。
|
|
168
48
|
*/
|
|
169
49
|
interface InjectionLogEntry {
|
|
170
|
-
/**
|
|
171
|
-
* 规则标识符
|
|
172
|
-
*/
|
|
50
|
+
/** 规则标识 */
|
|
173
51
|
ruleId: string;
|
|
174
|
-
/**
|
|
175
|
-
* 注入位置
|
|
176
|
-
*/
|
|
52
|
+
/** 注入位置 */
|
|
177
53
|
position: InjectPosition;
|
|
178
|
-
/**
|
|
179
|
-
* 使用的选择器
|
|
180
|
-
*/
|
|
54
|
+
/** 使用的 CSS 选择器(如果有) */
|
|
181
55
|
selector?: string;
|
|
182
|
-
/**
|
|
183
|
-
* 是否注入成功
|
|
184
|
-
*/
|
|
56
|
+
/** 是否注入成功 */
|
|
185
57
|
injected: boolean;
|
|
186
|
-
/**
|
|
187
|
-
* 注入失败原因
|
|
188
|
-
*/
|
|
58
|
+
/** 注入失败原因(如果失败) */
|
|
189
59
|
reason?: string;
|
|
190
|
-
/**
|
|
191
|
-
* 日志时间戳
|
|
192
|
-
*/
|
|
60
|
+
/** 日志记录时间戳(毫秒) */
|
|
193
61
|
timestamp: number;
|
|
194
62
|
}
|
|
195
63
|
/**
|
|
196
|
-
* HTML
|
|
64
|
+
* HTML 内容注入插件的配置选项接口
|
|
197
65
|
*
|
|
198
66
|
* @interface HtmlInjectOptions
|
|
199
67
|
* @extends {BasePluginOptions}
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* htmlInject({
|
|
72
|
+
* targetFile: 'index.html',
|
|
73
|
+
* rules: [
|
|
74
|
+
* { content: '<meta name="description" content="My App">', position: 'head-end' }
|
|
75
|
+
* ],
|
|
76
|
+
* security: { blockDangerousTags: true },
|
|
77
|
+
* templateVars: { appName: 'My App' },
|
|
78
|
+
* logInjection: true
|
|
79
|
+
* })
|
|
80
|
+
* ```
|
|
200
81
|
*/
|
|
201
82
|
interface HtmlInjectOptions extends BasePluginOptions {
|
|
202
|
-
/**
|
|
203
|
-
* 目标 HTML 文件路径或文件名
|
|
204
|
-
*
|
|
205
|
-
* @default 'index.html'
|
|
206
|
-
* @description 支持相对路径和文件名匹配,默认匹配所有 index.html 文件
|
|
207
|
-
*
|
|
208
|
-
* @example 'index.html'
|
|
209
|
-
* @example 'src/views/home.html'
|
|
210
|
-
*/
|
|
83
|
+
/** 目标 HTML 文件路径或文件名,默认为 'index.html' */
|
|
211
84
|
targetFile?: string;
|
|
212
|
-
/**
|
|
213
|
-
* 注入规则数组
|
|
214
|
-
*
|
|
215
|
-
* @description 定义要注入的 HTML 内容及其注入位置和条件,规则按 priority 升序执行
|
|
216
|
-
*/
|
|
85
|
+
/** 注入规则数组,至少包含一条规则 */
|
|
217
86
|
rules: InjectRule[];
|
|
218
|
-
/**
|
|
219
|
-
* 安全配置
|
|
220
|
-
*
|
|
221
|
-
* @description 控制注入内容的安全过滤行为,防止 XSS 攻击
|
|
222
|
-
*/
|
|
87
|
+
/** 安全过滤配置,控制危险标签和属性的过滤行为 */
|
|
223
88
|
security?: SecurityConfig;
|
|
224
|
-
/**
|
|
225
|
-
* 全局模板变量,可被规则级 templateVars 覆盖
|
|
226
|
-
*
|
|
227
|
-
* @description 使用 `{{变量名}}` 语法在 content 中引用变量
|
|
228
|
-
*
|
|
229
|
-
* @example { appName: 'My App', version: '1.0.0' }
|
|
230
|
-
*/
|
|
89
|
+
/** 全局模板变量映射,用于替换内容中的 `{{varName}}` 占位符 */
|
|
231
90
|
templateVars?: Record<string, string>;
|
|
232
|
-
/**
|
|
233
|
-
* 是否在控制台输出注入日志
|
|
234
|
-
*
|
|
235
|
-
* @default true
|
|
236
|
-
*/
|
|
91
|
+
/** 是否在控制台输出注入结果日志 */
|
|
237
92
|
logInjection?: boolean;
|
|
238
93
|
}
|
|
239
94
|
|
|
@@ -275,4 +130,4 @@ interface HtmlInjectOptions extends BasePluginOptions {
|
|
|
275
130
|
declare const htmlInject: PluginFactory<HtmlInjectOptions, HtmlInjectOptions>;
|
|
276
131
|
|
|
277
132
|
export { htmlInject };
|
|
278
|
-
export type {
|
|
133
|
+
export type { HtmlInjectOptions, InjectRule, InjectionLogEntry };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{createPluginFactory as
|
|
2
|
-
`+e
|
|
3
|
-
`+
|
|
4
|
-
`+e
|
|
5
|
-
`+
|
|
6
|
-
`+
|
|
7
|
-
`+e
|
|
1
|
+
import{createPluginFactory as E,BasePlugin as p}from"../../factory/index.mjs";import{s as m}from"../../shared/vite-plugin.BPFqtmWa.mjs";import g from"node:path";import"../../logger/index.mjs";import"../../shared/vite-plugin.DcExl6jd.mjs";function F(e){if(e){if(e.blockedTags&&!Array.isArray(e.blockedTags))throw new Error("security.blockedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(e.allowedTags&&!Array.isArray(e.allowedTags))throw new Error("security.allowedTags \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");if(e.blockedAttributes&&!Array.isArray(e.blockedAttributes))throw new Error("security.blockedAttributes \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4")}}function y(e){if(!e.rules||!Array.isArray(e.rules))throw new Error("rules \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4");if(e.rules.length===0)throw new Error("rules \u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");for(let t=0;t<e.rules.length;t++)j(e.rules[t],t)}function j(e,t){if(!e.content||typeof e.content!="string")throw new Error(`rules[${t}].content \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`);if(!e.position||typeof e.position!="string")throw new Error(`rules[${t}].position \u5FC5\u987B\u662F\u6709\u6548\u7684\u6CE8\u5165\u4F4D\u7F6E`);const n=["head-start","head-end","body-start","body-end","before-selector","after-selector","replace-selector"];if(!n.includes(e.position))throw new Error(`rules[${t}].position \u5FC5\u987B\u662F ${n.join(", ")} \u4E4B\u4E00`);if(e.position.includes("selector")&&!e.selector)throw new Error(`rules[${t}].position \u4E3A "${e.position}" \u65F6\uFF0Cselector \u4E3A\u5FC5\u586B\u9879`);if(e.priority!==void 0&&(typeof e.priority!="number"||e.priority<0))throw new Error(`rules[${t}].priority \u5FC5\u987B\u662F\u975E\u8D1F\u6570`);e.condition&&C(e.condition,t)}function C(e,t){if(!e)return;const n=["env","file-contains","custom"];if(!n.includes(e.type))throw new Error(`rules[${t}].condition.type \u5FC5\u987B\u662F ${n.join(", ")} \u4E4B\u4E00`);if(e.type==="custom"&&typeof e.value!="function")throw new Error(`rules[${t}].condition.type \u4E3A "custom" \u65F6\uFF0Cvalue \u5FC5\u987B\u662F\u51FD\u6570`);if(e.type!=="custom"&&typeof e.value!="string")throw new Error(`rules[${t}].condition.type \u4E3A "${e.type}" \u65F6\uFF0Cvalue \u5FC5\u987B\u662F\u5B57\u7B26\u4E32`)}function w(e){y(e),F(e.security)}function h(e,t,n){if(n==="regex"){try{const i=new RegExp(t),u=e.match(i);if(u&&u.index!==void 0)return{index:u.index,length:u[0].length}}catch{return null}return null}const r=e.indexOf(t);return r===-1?null:{index:r,length:t.length}}function b(e,t,n){let r=e;const i={...n,...t};for(const[u,o]of Object.entries(i)){const c=u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=o.replace(/\$/g,"$$$$");r=r.replace(new RegExp(`\\{\\{${c}\\}\\}`,"g"),s)}return r}function $(e,t){let n=!1;switch(e.type){case"env":{const r=e.value,i=process.env[r];n=!!i&&i!=="false"&&i!=="0";break}case"file-contains":{const r=e.value;n=t.includes(r);break}case"custom":{const r=e.value;try{n=!!r()}catch{n=!1}break}}return e.negate?!n:n}function A(e){return[...e].sort((t,n)=>(t.priority??100)-(n.priority??100))}function B(e,t,n,r,i){switch(n){case"head-start":{const u=e.match(/<head\b[^>]*>/i);if(!u)return{html:e,injected:!1,reason:"\u672A\u627E\u5230 <head> \u6807\u7B7E"};const o=(u.index??0)+u[0].length;return{html:e.slice(0,o)+`
|
|
2
|
+
`+t+e.slice(o),injected:!0}}case"head-end":{const u=e.match(/<\/head\s*>/i);if(!u)return{html:e,injected:!1,reason:"\u672A\u627E\u5230 </head> \u6807\u7B7E"};const o=u.index;return{html:e.slice(0,o)+t+`
|
|
3
|
+
`+e.slice(o),injected:!0}}case"body-start":{const u=e.match(/<body\b[^>]*>/i);if(!u)return{html:e,injected:!1,reason:"\u672A\u627E\u5230 <body> \u6807\u7B7E"};const o=(u.index??0)+u[0].length;return{html:e.slice(0,o)+`
|
|
4
|
+
`+t+e.slice(o),injected:!0}}case"body-end":{const u=e.match(/<\/body\s*>/i);if(!u)return{html:e,injected:!1,reason:"\u672A\u627E\u5230 </body> \u6807\u7B7E"};const o=u.index;return{html:e.slice(0,o)+t+`
|
|
5
|
+
`+e.slice(o),injected:!0}}case"before-selector":{if(!r)return{html:e,injected:!1,reason:"before-selector \u9700\u8981 selector \u53C2\u6570"};const u=h(e,r,i);return u?{html:e.slice(0,u.index)+t+`
|
|
6
|
+
`+e.slice(u.index),injected:!0}:{html:e,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${r}"`}}case"after-selector":{if(!r)return{html:e,injected:!1,reason:"after-selector \u9700\u8981 selector \u53C2\u6570"};const u=h(e,r,i);if(!u)return{html:e,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${r}"`};const o=u.index+u.length;return{html:e.slice(0,o)+`
|
|
7
|
+
`+t+e.slice(o),injected:!0}}case"replace-selector":{if(!r)return{html:e,injected:!1,reason:"replace-selector \u9700\u8981 selector \u53C2\u6570"};const u=h(e,r,i);if(!u)return{html:e,injected:!1,reason:`\u672A\u627E\u5230\u9009\u62E9\u5668 "${r}"`};const o=u.index+u.length;return{html:e.slice(0,u.index)+t+e.slice(o),injected:!0}}default:return{html:e,injected:!1,reason:`\u4E0D\u652F\u6301\u7684\u6CE8\u5165\u4F4D\u7F6E: ${n}`}}}function x(e,t,n,r,i){let u=e;const o=[],c=A(t);for(const s of c){const l={ruleId:s.id||"unnamed",position:s.position,selector:s.selector,injected:!1,timestamp:Date.now()};if(s.condition&&!$(s.condition,u)){l.injected=!1,l.reason="\u6761\u4EF6\u4E0D\u6EE1\u8DB3\uFF0C\u8DF3\u8FC7\u6CE8\u5165",o.push(l);continue}let a=b(s.content,s.templateVars,n);try{a=m(a,s,r,i)}catch(f){l.injected=!1,l.reason=f.message,o.push(l),i?.warn(`\u89C4\u5219 "${s.id||"unnamed"}" \u5B89\u5168\u68C0\u67E5\u5931\u8D25: ${f.message}`);continue}const d=B(u,a,s.position,s.selector,s.selectorMatch);u=d.html,l.injected=d.injected,l.reason=d.reason,o.push(l)}return{html:u,logs:o}}class v extends p{injectionLogs=[];getDefaultOptions(){return{targetFile:"index.html",logInjection:!0,security:{blockDangerousTags:!0,blockDangerousAttributes:!0}}}validateOptions(){this.validator.field("targetFile").string().field("rules").required().field("logInjection").boolean().validate(),w(this.options)}getPluginName(){return"html-inject"}isTargetFile(t,n){if(n==="index.html")return t.endsWith("index.html")||t.endsWith("index.htm");const r=n.replace(/\\/g,"/"),i=t.replace(/\\/g,"/");return i.endsWith(r)?!0:g.basename(i)===g.basename(r)}addPluginHooks(t){t.transformIndexHtml={order:"post",handler:(n,r)=>{const i=r.filename||"",u=this.options.targetFile||"index.html";if(!this.isTargetFile(i,u))return n;const o={warn:s=>this.logger.warn(s)},c=x(n,this.options.rules,this.options.templateVars,this.options.security,o);return this.injectionLogs=c.logs,this.options.logInjection&&this.logInjectionResults(c.logs),c.html}},t.buildEnd=()=>{this.options.logInjection&&this.injectionLogs.length>0&&this.logger.info(`\u6CE8\u5165\u5B8C\u6210\uFF0C\u5171\u5904\u7406 ${this.injectionLogs.length} \u6761\u89C4\u5219`)}}logInjectionResults(t){for(const n of t)n.injected?this.logger.success(`\u89C4\u5219 "${n.ruleId}" \u6CE8\u5165\u6210\u529F (\u4F4D\u7F6E: ${n.position}${n.selector?`, \u9009\u62E9\u5668: ${n.selector}`:""})`):this.logger.warn(`\u89C4\u5219 "${n.ruleId}" \u6CE8\u5165\u5931\u8D25: ${n.reason||"\u672A\u77E5\u539F\u56E0"}`)}getInjectionLogs(){return[...this.injectionLogs]}}const D=E(v);export{D as htmlInject};
|
package/dist/plugins/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const plugins_buildProgress_index=require("./buildProgress/index.cjs"),plugins_bundleAnalyzer_index=require("./bundleAnalyzer/index.cjs"),plugins_compressAssets_index=require("./compressAssets/index.cjs"),plugins_copyFile_index=require("./copyFile/index.cjs"),plugins_faviconManager_index=require("./faviconManager/index.cjs"),plugins_generateRouter_index=require("./generateRouter/index.cjs"),plugins_generateVersion_index=require("./generateVersion/index.cjs"),plugins_htmlInject_index=require("./htmlInject/index.cjs"),plugins_loadingManager_index=require("./loadingManager/index.cjs"),plugins_versionUpdateChecker_index=require("./versionUpdateChecker/index.cjs");require("../factory/index.cjs"),require("../logger/index.cjs"),require("../
|
|
1
|
+
"use strict";const plugins_autoImport_index=require("./autoImport/index.cjs"),plugins_buildProgress_index=require("./buildProgress/index.cjs"),plugins_bundleAnalyzer_index=require("./bundleAnalyzer/index.cjs"),plugins_compressAssets_index=require("./compressAssets/index.cjs"),plugins_copyFile_index=require("./copyFile/index.cjs"),plugins_envGuard_index=require("./envGuard/index.cjs"),plugins_faviconManager_index=require("./faviconManager/index.cjs"),plugins_generateRouter_index=require("./generateRouter/index.cjs"),plugins_generateVersion_index=require("./generateVersion/index.cjs"),plugins_htmlInject_index=require("./htmlInject/index.cjs"),plugins_loadingManager_index=require("./loadingManager/index.cjs"),plugins_versionUpdateChecker_index=require("./versionUpdateChecker/index.cjs");require("../factory/index.cjs"),require("../logger/index.cjs"),require("../shared/vite-plugin.Bcg6RW2N.cjs"),require("node:fs"),require("node:path"),require("../common/ui/index.cjs"),require("node:zlib"),require("node:util"),require("../common/fs/index.cjs"),require("fs"),require("path"),require("../common/format/index.cjs"),require("node:stream/promises"),require("../common/html/index.cjs"),require("../shared/vite-plugin.CnOy46d3.cjs"),require("crypto"),require("../common/script/index.cjs"),require("../common/validation/index.cjs"),exports.autoImport=plugins_autoImport_index.autoImport,exports.buildProgress=plugins_buildProgress_index.buildProgress,exports.bundleAnalyzer=plugins_bundleAnalyzer_index.bundleAnalyzer,exports.compressAssets=plugins_compressAssets_index.compressAssets,exports.copyFile=plugins_copyFile_index.copyFile,exports.envGuard=plugins_envGuard_index.envGuard,exports.faviconManager=plugins_faviconManager_index.faviconManager,exports.generateRouter=plugins_generateRouter_index.generateRouter,exports.generateVersion=plugins_generateVersion_index.generateVersion,exports.htmlInject=plugins_htmlInject_index.htmlInject,exports.loadingManager=plugins_loadingManager_index.loadingManager,exports.versionUpdateChecker=plugins_versionUpdateChecker_index.versionUpdateChecker;
|
package/dist/plugins/index.d.cts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
export { AutoImportOptions, ImportMapping, ResolvedImport, ScannedModule, TransformResult, autoImport } from './autoImport/index.cjs';
|
|
1
2
|
export { BuildPhase, BuildProgressOptions, ProgressFormat, ProgressTheme, buildProgress } from './buildProgress/index.cjs';
|
|
2
3
|
export { BundleAnalysisResult, BundleAnalyzerOptions, BundleOutputFormat, ChunkStats, ComparisonDiff, FileTypeDistribution, ModuleStats, SizeWarning, bundleAnalyzer } from './bundleAnalyzer/index.cjs';
|
|
3
4
|
export { CompressAlgorithm, CompressAssetsOptions, CompressStats, CompressSummary, compressAssets } from './compressAssets/index.cjs';
|
|
4
5
|
export { CopyFileOptions, copyFile } from './copyFile/index.cjs';
|
|
6
|
+
export { EnvFailAction, EnvGuardOptions, EnvGuardResult, RuntimeGuardMode, envGuard } from './envGuard/index.cjs';
|
|
5
7
|
export { FaviconManagerOptions, Icon, faviconManager } from './faviconManager/index.cjs';
|
|
6
8
|
export { GenerateRouterOptions, NameStrategy, OutputFormat, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, generateRouter } from './generateRouter/index.cjs';
|
|
7
9
|
export { GenerateVersionOptions, OutputType, VersionFormat, VersionInfo, generateVersion } from './generateVersion/index.cjs';
|
|
8
|
-
export {
|
|
10
|
+
export { HtmlInjectOptions, InjectRule, InjectionLogEntry, htmlInject } from './htmlInject/index.cjs';
|
|
9
11
|
export { AutoBindMode, AutoHideOn, DebounceHide, DelayShow, LoadingCallbacks, LoadingManager, LoadingManagerOptions, LoadingPosition, LoadingStyle, MinDisplayTime, RequestFilter, SpinnerType, TransitionConfig, loadingManager } from './loadingManager/index.cjs';
|
|
10
12
|
export { PromptStyle, VersionSource, VersionUpdateCheckerOptions, versionUpdateChecker } from './versionUpdateChecker/index.cjs';
|
|
11
13
|
import '../factory/index.cjs';
|
|
12
14
|
import 'vite';
|
|
13
|
-
import '../shared/vite-plugin.
|
|
15
|
+
import '../shared/vite-plugin.B8FuZce1.cjs';
|
|
14
16
|
import '../shared/vite-plugin.DRRlWY8P.cjs';
|
|
17
|
+
import '../shared/vite-plugin.BI9taN75.cjs';
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
export { AutoImportOptions, ImportMapping, ResolvedImport, ScannedModule, TransformResult, autoImport } from './autoImport/index.mjs';
|
|
1
2
|
export { BuildPhase, BuildProgressOptions, ProgressFormat, ProgressTheme, buildProgress } from './buildProgress/index.mjs';
|
|
2
3
|
export { BundleAnalysisResult, BundleAnalyzerOptions, BundleOutputFormat, ChunkStats, ComparisonDiff, FileTypeDistribution, ModuleStats, SizeWarning, bundleAnalyzer } from './bundleAnalyzer/index.mjs';
|
|
3
4
|
export { CompressAlgorithm, CompressAssetsOptions, CompressStats, CompressSummary, compressAssets } from './compressAssets/index.mjs';
|
|
4
5
|
export { CopyFileOptions, copyFile } from './copyFile/index.mjs';
|
|
6
|
+
export { EnvFailAction, EnvGuardOptions, EnvGuardResult, RuntimeGuardMode, envGuard } from './envGuard/index.mjs';
|
|
5
7
|
export { FaviconManagerOptions, Icon, faviconManager } from './faviconManager/index.mjs';
|
|
6
8
|
export { GenerateRouterOptions, NameStrategy, OutputFormat, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, generateRouter } from './generateRouter/index.mjs';
|
|
7
9
|
export { GenerateVersionOptions, OutputType, VersionFormat, VersionInfo, generateVersion } from './generateVersion/index.mjs';
|
|
8
|
-
export {
|
|
10
|
+
export { HtmlInjectOptions, InjectRule, InjectionLogEntry, htmlInject } from './htmlInject/index.mjs';
|
|
9
11
|
export { AutoBindMode, AutoHideOn, DebounceHide, DelayShow, LoadingCallbacks, LoadingManager, LoadingManagerOptions, LoadingPosition, LoadingStyle, MinDisplayTime, RequestFilter, SpinnerType, TransitionConfig, loadingManager } from './loadingManager/index.mjs';
|
|
10
12
|
export { PromptStyle, VersionSource, VersionUpdateCheckerOptions, versionUpdateChecker } from './versionUpdateChecker/index.mjs';
|
|
11
13
|
import '../factory/index.mjs';
|
|
12
14
|
import 'vite';
|
|
13
|
-
import '../shared/vite-plugin.
|
|
15
|
+
import '../shared/vite-plugin.B8FuZce1.mjs';
|
|
14
16
|
import '../shared/vite-plugin.DRRlWY8P.mjs';
|
|
17
|
+
import '../shared/vite-plugin.BI9taN75.mjs';
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
export { AutoImportOptions, ImportMapping, ResolvedImport, ScannedModule, TransformResult, autoImport } from './autoImport/index.js';
|
|
1
2
|
export { BuildPhase, BuildProgressOptions, ProgressFormat, ProgressTheme, buildProgress } from './buildProgress/index.js';
|
|
2
3
|
export { BundleAnalysisResult, BundleAnalyzerOptions, BundleOutputFormat, ChunkStats, ComparisonDiff, FileTypeDistribution, ModuleStats, SizeWarning, bundleAnalyzer } from './bundleAnalyzer/index.js';
|
|
3
4
|
export { CompressAlgorithm, CompressAssetsOptions, CompressStats, CompressSummary, compressAssets } from './compressAssets/index.js';
|
|
4
5
|
export { CopyFileOptions, copyFile } from './copyFile/index.js';
|
|
6
|
+
export { EnvFailAction, EnvGuardOptions, EnvGuardResult, RuntimeGuardMode, envGuard } from './envGuard/index.js';
|
|
5
7
|
export { FaviconManagerOptions, Icon, faviconManager } from './faviconManager/index.js';
|
|
6
8
|
export { GenerateRouterOptions, NameStrategy, OutputFormat, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, generateRouter } from './generateRouter/index.js';
|
|
7
9
|
export { GenerateVersionOptions, OutputType, VersionFormat, VersionInfo, generateVersion } from './generateVersion/index.js';
|
|
8
|
-
export {
|
|
10
|
+
export { HtmlInjectOptions, InjectRule, InjectionLogEntry, htmlInject } from './htmlInject/index.js';
|
|
9
11
|
export { AutoBindMode, AutoHideOn, DebounceHide, DelayShow, LoadingCallbacks, LoadingManager, LoadingManagerOptions, LoadingPosition, LoadingStyle, MinDisplayTime, RequestFilter, SpinnerType, TransitionConfig, loadingManager } from './loadingManager/index.js';
|
|
10
12
|
export { PromptStyle, VersionSource, VersionUpdateCheckerOptions, versionUpdateChecker } from './versionUpdateChecker/index.js';
|
|
11
13
|
import '../factory/index.js';
|
|
12
14
|
import 'vite';
|
|
13
|
-
import '../shared/vite-plugin.
|
|
15
|
+
import '../shared/vite-plugin.B8FuZce1.js';
|
|
14
16
|
import '../shared/vite-plugin.DRRlWY8P.js';
|
|
17
|
+
import '../shared/vite-plugin.BI9taN75.js';
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{buildProgress}from"./buildProgress/index.mjs";export{bundleAnalyzer}from"./bundleAnalyzer/index.mjs";export{compressAssets}from"./compressAssets/index.mjs";export{copyFile}from"./copyFile/index.mjs";export{faviconManager}from"./faviconManager/index.mjs";export{generateRouter}from"./generateRouter/index.mjs";export{generateVersion}from"./generateVersion/index.mjs";export{htmlInject}from"./htmlInject/index.mjs";export{loadingManager}from"./loadingManager/index.mjs";export{versionUpdateChecker}from"./versionUpdateChecker/index.mjs";import"../factory/index.mjs";import"../logger/index.mjs";import"../
|
|
1
|
+
export{autoImport}from"./autoImport/index.mjs";export{buildProgress}from"./buildProgress/index.mjs";export{bundleAnalyzer}from"./bundleAnalyzer/index.mjs";export{compressAssets}from"./compressAssets/index.mjs";export{copyFile}from"./copyFile/index.mjs";export{envGuard}from"./envGuard/index.mjs";export{faviconManager}from"./faviconManager/index.mjs";export{generateRouter}from"./generateRouter/index.mjs";export{generateVersion}from"./generateVersion/index.mjs";export{htmlInject}from"./htmlInject/index.mjs";export{loadingManager}from"./loadingManager/index.mjs";export{versionUpdateChecker}from"./versionUpdateChecker/index.mjs";import"../factory/index.mjs";import"../logger/index.mjs";import"../shared/vite-plugin.DcExl6jd.mjs";import"node:fs";import"node:path";import"../common/ui/index.mjs";import"node:zlib";import"node:util";import"../common/fs/index.mjs";import"fs";import"path";import"../common/format/index.mjs";import"node:stream/promises";import"../common/html/index.mjs";import"../shared/vite-plugin.BPFqtmWa.mjs";import"crypto";import"../common/script/index.mjs";import"../common/validation/index.mjs";
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
"use strict";const factory_index=require("../../factory/index.cjs"),
|
|
1
|
+
"use strict";const factory_index=require("../../factory/index.cjs"),common_script_index=require("../../common/script/index.cjs"),common_validation_index=require("../../common/validation/index.cjs"),common_html_index=require("../../common/html/index.cjs");require("../../logger/index.cjs"),require("../../shared/vite-plugin.Bcg6RW2N.cjs"),require("../../shared/vite-plugin.CnOy46d3.cjs");const CLS_OVERLAY="__loading-overlay__",CLS_HIDDEN="__loading-hidden__",CLS_VISIBLE="__loading-visible__",CLS_TOP="__loading-top__",CLS_CENTER="__loading-center__",CLS_BOTTOM="__loading-bottom__",CLS_SPINNER="__loading-spinner__",CLS_TEXT="__loading-text__",CLS_DOT="__loading-dot__",ID_ROOT="__loading-root__",ATTR_TEXT="data-loading-text",ANIM_SPIN="__loading-spin__",ANIM_DOTS="__loading-dots__",ANIM_PULSE="__loading-pulse__",ANIM_BAR="__loading-bar__",POSITION_CLASS_MAP={center:CLS_CENTER,top:CLS_TOP,bottom:CLS_BOTTOM};function P(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function generateCSS(e,t="spinner",n){const{overlayColor:o="rgba(255, 255, 255, 0.7)",spinnerColor:a="#4361ee",spinnerSize:u="40px",textColor:r="#333",textSize:l="14px",zIndex:c=9999,pointerEvents:m=!0,backdropBlur:d=!1,backdropBlurAmount:_=4}=e,h=m?"":"pointer-events: none;",y=d?`backdrop-filter: blur(${_}px);-webkit-backdrop-filter: blur(${_}px);`:"",E=getSpinnerCSS(t,a,u),b=n?.enabled!==!1,f=n?.duration??200,g=n?.easing??"ease-out",p=b?`transition: opacity ${f}ms ${g}, visibility ${f}ms ${g};`:"";return`
|
|
2
2
|
.${CLS_OVERLAY} {
|
|
3
3
|
position: fixed;
|
|
4
4
|
top: 0;
|
|
5
5
|
left: 0;
|
|
6
6
|
right: 0;
|
|
7
7
|
bottom: 0;
|
|
8
|
-
background: ${
|
|
8
|
+
background: ${o};
|
|
9
9
|
display: flex;
|
|
10
10
|
flex-direction: column;
|
|
11
11
|
align-items: center;
|
|
12
|
-
z-index: ${
|
|
13
|
-
${
|
|
14
|
-
${
|
|
12
|
+
z-index: ${c};
|
|
13
|
+
${h}
|
|
14
|
+
${y}
|
|
15
15
|
contain: content;
|
|
16
16
|
will-change: opacity;
|
|
17
17
|
}
|
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
justify-content: flex-end;
|
|
27
27
|
padding-bottom: 60px;
|
|
28
28
|
}
|
|
29
|
-
${
|
|
29
|
+
${E}
|
|
30
30
|
.${CLS_TEXT} {
|
|
31
31
|
margin-top: 12px;
|
|
32
|
-
color: ${
|
|
33
|
-
font-size: ${
|
|
32
|
+
color: ${r};
|
|
33
|
+
font-size: ${l};
|
|
34
34
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
35
35
|
user-select: none;
|
|
36
36
|
}
|
|
37
37
|
.${CLS_OVERLAY}.${CLS_HIDDEN} {
|
|
38
38
|
opacity: 0;
|
|
39
39
|
visibility: hidden;
|
|
40
|
-
${
|
|
40
|
+
${p}
|
|
41
41
|
}
|
|
42
42
|
.${CLS_OVERLAY}.${CLS_HIDDEN} .${CLS_SPINNER},
|
|
43
43
|
.${CLS_OVERLAY}.${CLS_HIDDEN} .${CLS_DOT},
|
|
@@ -47,7 +47,7 @@ ${h}
|
|
|
47
47
|
.${CLS_OVERLAY}.${CLS_VISIBLE} {
|
|
48
48
|
opacity: 1;
|
|
49
49
|
visibility: visible;
|
|
50
|
-
${
|
|
50
|
+
${p}
|
|
51
51
|
}
|
|
52
52
|
.${CLS_OVERLAY}.${CLS_VISIBLE} .${CLS_SPINNER},
|
|
53
53
|
.${CLS_OVERLAY}.${CLS_VISIBLE} .${CLS_DOT},
|
|
@@ -117,8 +117,8 @@ ${h}
|
|
|
117
117
|
}
|
|
118
118
|
@keyframes ${ANIM_SPIN} {
|
|
119
119
|
to { transform: rotate(360deg); }
|
|
120
|
-
}`}}function generateHTMLTemplate(e){const t=e.position||"center",n=e.defaultText||"\u52A0\u8F7D\u4E2D...",
|
|
121
|
-
${
|
|
120
|
+
}`}}function generateHTMLTemplate(e){const t=e.position||"center",n=e.defaultText||"\u52A0\u8F7D\u4E2D...",o=e.spinnerType||"spinner",a=POSITION_CLASS_MAP[t],u=e.style?.customClass?` ${e.style.customClass}`:"",r=e.style?.customStyle?` style="${P(e.style.customStyle)}"`:"",l=e.defaultVisible?CLS_VISIBLE:CLS_HIDDEN;if(e.customTemplate)return`<div class="${CLS_OVERLAY} ${a} ${l}${u}" id="${ID_ROOT}"${r}>${e.customTemplate}</div>`;const c=getSpinnerHTML(o);return`<div class="${CLS_OVERLAY} ${a} ${l}${u}" id="${ID_ROOT}"${r}>
|
|
121
|
+
${c}
|
|
122
122
|
<div class="${CLS_TEXT}" ${ATTR_TEXT}>${n}</div>
|
|
123
123
|
</div>`}function getSpinnerHTML(e){switch(e){case"dots":return`<div class="${CLS_SPINNER}"><div class="${CLS_DOT}"></div><div class="${CLS_DOT}"></div><div class="${CLS_DOT}"></div></div>`;default:return`<div class="${CLS_SPINNER}"></div>`}}function generateVarsCode(e){return` var _loadingEl = null;
|
|
124
124
|
var _textEl = null;
|
|
@@ -403,13 +403,13 @@ ${h}
|
|
|
403
403
|
return _originalXHRSend.apply(this, arguments);
|
|
404
404
|
};
|
|
405
405
|
}
|
|
406
|
-
`),t.trimEnd()}function generateInitCode(e,t,n){let
|
|
406
|
+
`),t.trimEnd()}function generateInitCode(e,t,n){let o="";return o+=` // defaultVisible: \u540C\u6B65\u521D\u59CB\u53EF\u89C1\u72B6\u6001
|
|
407
407
|
var _defaultVisible = ${JSON.stringify(e)};
|
|
408
408
|
if (_defaultVisible) {
|
|
409
409
|
_visible = true;
|
|
410
410
|
_showTime = Date.now();
|
|
411
411
|
}
|
|
412
|
-
`,e&&t!=="manual"&&(
|
|
412
|
+
`,e&&t!=="manual"&&(o+=`
|
|
413
413
|
// autoHideOn: \u81EA\u52A8\u9690\u85CF\u65F6\u673A
|
|
414
414
|
var _autoHideOn = '${t}';
|
|
415
415
|
function _autoHideHandler() {
|
|
@@ -428,33 +428,33 @@ ${h}
|
|
|
428
428
|
document.addEventListener('DOMContentLoaded', _autoHideHandler);
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
|
-
`),
|
|
431
|
+
`),o+=`
|
|
432
432
|
// \u66B4\u9732\u5230\u5168\u5C40
|
|
433
|
-
window['${n}'] = manager;`,
|
|
433
|
+
window['${n}'] = manager;`,o}function generateLoadingManagerCode(e){const t=e.globalName||"__LOADING_MANAGER__",n=e.minDisplayTime||{enabled:!0,duration:300},o=e.delayShow||{enabled:!0,duration:200},a=e.debounceHide||{enabled:!1,duration:100},u=e.transition||{enabled:!0,duration:200,easing:"ease-out"},r=e.autoBind||"none",l=e.requestFilter||{},c=e.defaultVisible||!1,m=e.autoHideOn||"DOMContentLoaded",d=e.callbacks||{},_=l.excludeUrls||[],h=l.includeUrls||[],y=l.excludeMethods||[],E=l.excludeUrlPrefixes||[],b=common_script_index.makeCallback(d.onBeforeShow,"loadingManager"),f=common_script_index.makeCallback(d.onShow,"loadingManager"),g=common_script_index.makeCallback(d.onBeforeHide,"loadingManager"),p=common_script_index.makeCallback(d.onHide,"loadingManager"),$=common_script_index.makeCallback(d.onDestroy,"loadingManager"),v=generateVarsCode({minDisplayTime:n,delayShow:o,debounceHide:a,transition:u,excludeUrls:_,includeUrls:h,excludeMethods:y,excludeUrlPrefixes:E,cbBeforeShow:b,cbShow:f,cbBeforeHide:g,cbHide:p,cbDestroy:$}),w=generateHelpersCode(t),C=generateCoreLogicCode(),T=generateManagerObjectCode(),x=generateInterceptorsCode(r),S=generateInitCode(c,m,t);return`(function() {
|
|
434
434
|
'use strict';
|
|
435
435
|
|
|
436
436
|
// SSR \u73AF\u5883\u68C0\u6D4B
|
|
437
437
|
if (typeof window === 'undefined' || typeof document === 'undefined') return;
|
|
438
438
|
|
|
439
|
-
${
|
|
439
|
+
${v}
|
|
440
440
|
|
|
441
|
-
${
|
|
441
|
+
${w}
|
|
442
442
|
|
|
443
|
-
${
|
|
443
|
+
${C}
|
|
444
444
|
|
|
445
445
|
var manager = {
|
|
446
446
|
${T}
|
|
447
447
|
};
|
|
448
448
|
|
|
449
|
-
${w}
|
|
450
|
-
|
|
451
449
|
${x}
|
|
452
|
-
|
|
450
|
+
|
|
451
|
+
${S}
|
|
452
|
+
})();`}function i(e,t){if(e!==void 0&&(typeof e!="number"||e<0))throw new Error(`${t} \u5FC5\u987B\u662F\u975E\u8D1F\u6570`)}function validateStyle(e){if(!e)return;const{zIndex:t,pointerEvents:n,backdropBlurAmount:o}=e;if(i(t,"style.zIndex"),n!==void 0&&typeof n!="boolean")throw new Error("style.pointerEvents \u5FC5\u987B\u662F\u5E03\u5C14\u503C");i(o,"style.backdropBlurAmount")}function validateTransition(e){if(!e)return;const{duration:t,easing:n}=e;if(i(t,"transition.duration"),n!==void 0&&typeof n!="string")throw new Error("transition.easing \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u7C7B\u578B")}function validateCallbacks(e){e&&common_validation_index.validateCallbackFields(e,["onBeforeShow","onShow","onBeforeHide","onHide","onDestroy"],"callbacks")}function validateDefaultText(e){return e===""?"defaultText \u4E3A\u7A7A\u5B57\u7B26\u4E32\uFF0Cloading \u5C06\u4E0D\u663E\u793A\u6587\u672C\u5185\u5BB9":null}function validateAutoHideOn(e,t){return!e&&t?"autoHideOn \u4EC5\u5728 defaultVisible \u4E3A true \u65F6\u751F\u6548\uFF0C\u5F53\u524D defaultVisible \u4E3A false\uFF0CautoHideOn \u914D\u7F6E\u5C06\u88AB\u5FFD\u7565":null}function s(e,t){if(e?.duration!==void 0&&(typeof e.duration!="number"||e.duration<0))throw new Error(t)}class L extends factory_index.BasePlugin{getDefaultOptions(){return{position:"center",defaultText:"\u52A0\u8F7D\u4E2D...",spinnerType:"spinner",autoBind:"none",globalName:"__LOADING_MANAGER__",defaultVisible:!1,autoHideOn:"DOMContentLoaded",style:{overlayColor:"rgba(255, 255, 255, 0.7)",spinnerColor:"#4361ee",spinnerSize:"40px",textColor:"#333",textSize:"14px",zIndex:9999,pointerEvents:!0,backdropBlur:!1,backdropBlurAmount:4},transition:{enabled:!0,duration:200,easing:"ease-out"},minDisplayTime:{enabled:!0,duration:300},delayShow:{enabled:!0,duration:200},debounceHide:{enabled:!1,duration:100}}}validateOptions(){this.validator.field("position").enum(["center","top","bottom"]).field("defaultText").string().field("spinnerType").enum(["spinner","dots","pulse","bar"]).field("autoBind").enum(["fetch","xhr","all","none"]).field("globalName").string().field("customTemplate").string().field("defaultVisible").boolean().field("autoHideOn").enum(["DOMContentLoaded","load","manual"]).validate(),common_validation_index.validateNoScriptInTemplate(this.options.customTemplate,"customTemplate");const t=validateDefaultText(this.options.defaultText);t&&this.logger.warn(t),common_validation_index.validateGlobalName(this.options.globalName,"globalName"),validateStyle(this.options.style),s(this.options.minDisplayTime,"minDisplayTime.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),s(this.options.delayShow,"delayShow.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),s(this.options.debounceHide,"debounceHide.duration \u5FC5\u987B\u662F\u975E\u8D1F\u6570"),validateTransition(this.options.transition),validateCallbacks(this.options.callbacks);const n=validateAutoHideOn(this.options.defaultVisible,this.options.autoHideOn);n&&this.logger.warn(n)}getPluginName(){return"loading-manager"}generateLoadingManager(t){return generateLoadingManagerCode(t)}generateHeadInjectCode(){const{css:t,html:n}=this.getCachedAssets();return`<!-- loading-manager: head start -->
|
|
453
453
|
<style data-loading-style data-loading-id="${this.options.globalName||"__LOADING_MANAGER__"}">${t}</style>
|
|
454
454
|
${n}
|
|
455
455
|
<!-- loading-manager: head end -->`}generateBodyInjectCode(t){const n=this.generateLoadingManager(this.options);if(t)return`<!-- loading-manager: body start -->
|
|
456
456
|
<script>${n}<\/script>
|
|
457
|
-
<!-- loading-manager: body end -->`;const{css:
|
|
457
|
+
<!-- loading-manager: body end -->`;const{css:o,html:a}=this.getCachedAssets();return`<!-- loading-manager: start -->
|
|
458
458
|
<script>
|
|
459
459
|
(function() {
|
|
460
460
|
// SSR \u73AF\u5883\u68C0\u6D4B
|
|
@@ -464,13 +464,13 @@ ${n}
|
|
|
464
464
|
var style = document.createElement('style');
|
|
465
465
|
style.setAttribute('data-loading-style', '');
|
|
466
466
|
style.setAttribute('data-loading-id', '${this.options.globalName||"__LOADING_MANAGER__"}');
|
|
467
|
-
style.textContent = ${JSON.stringify(
|
|
467
|
+
style.textContent = ${JSON.stringify(o)};
|
|
468
468
|
document.head.appendChild(style);
|
|
469
469
|
|
|
470
470
|
// \u6CE8\u5165 HTML\uFF08\u7B49\u5F85 body \u53EF\u7528\u65F6\u6267\u884C\uFF09
|
|
471
471
|
function injectHTML() {
|
|
472
472
|
var div = document.createElement('div');
|
|
473
|
-
div.innerHTML = ${JSON.stringify(
|
|
473
|
+
div.innerHTML = ${JSON.stringify(a)};
|
|
474
474
|
while (div.firstChild) {
|
|
475
475
|
document.body.appendChild(div.firstChild);
|
|
476
476
|
}
|
|
@@ -484,4 +484,4 @@ ${n}
|
|
|
484
484
|
})();
|
|
485
485
|
${n}
|
|
486
486
|
<\/script>
|
|
487
|
-
<!-- loading-manager: end -->`}_cachedAssets=null;getCachedAssets(){if(!this._cachedAssets){const t=this.options.style||{},n=this.options.spinnerType||"spinner",
|
|
487
|
+
<!-- loading-manager: end -->`}_cachedAssets=null;getCachedAssets(){if(!this._cachedAssets){const t=this.options.style||{},n=this.options.spinnerType||"spinner",o=this.options.transition;this._cachedAssets={css:generateCSS(t,n,o),html:generateHTMLTemplate(this.options)}}return this._cachedAssets}addPluginHooks(t){const n=this.options.defaultVisible||!1,o=n?this.generateHeadInjectCode():void 0,a=this.generateBodyInjectCode(n);t.transformIndexHtml={order:"post",handler:u=>{const r=common_html_index.injectHeadAndBody(u,o,a);return o&&!r.headInjected&&this.logger.warn("\u672A\u627E\u5230 </head> \u6807\u7B7E\uFF0CdefaultVisible \u7684\u767D\u5C4F loading \u5C06\u65E0\u6CD5\u751F\u6548"),r.usedFallback&&this.logger.warn("\u672A\u627E\u5230 </body> \u6216 </html> \u6807\u7B7E\uFF0CLoading \u4EE3\u7801\u8FFD\u52A0\u5230\u6587\u4EF6\u672B\u5C3E"),r.bodyInjected&&this.logger.success("\u6210\u529F\u6CE8\u5165\u5168\u5C40 Loading \u72B6\u6001\u7BA1\u7406\u4EE3\u7801\u5230 HTML \u6587\u4EF6"),r.html}}}}const loadingManager=factory_index.createPluginFactory(L);exports.loadingManager=loadingManager;
|