@esmx/core 3.0.0-rc.60 → 3.0.0-rc.63

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.
@@ -1,104 +1,104 @@
1
1
  import serialize from 'serialize-javascript';
2
2
  import type { Esmx } from './core';
3
3
  /**
4
- * RenderContext 的配置选项接口
4
+ * Configuration options interface for RenderContext
5
5
  *
6
6
  * @description
7
- * RenderContextOptions 用于配置 RenderContext 实例的行为,包括基础路径、入口名称、参数和导入映射模式等。
7
+ * RenderContextOptions is used to configure the behavior of RenderContext instances, including base path, entry name, parameters, and import map mode.
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
- * // 1. 基础路径配置示例
12
- * // 支持将静态资源部署到不同的路径下
11
+ * // 1. Base path configuration example
12
+ * // Supports deploying static assets to different paths
13
13
  * const rc = await esmx.render({
14
- * // 设置基础路径为 /esmx,所有静态资源都会基于此路径加载
14
+ * // Set base path to /esmx, all static assets will be loaded based on this path
15
15
  * base: '/esmx',
16
- * // 其他配置...
16
+ * // Other configurations...
17
17
  * });
18
18
  *
19
- * // 2. 多语言站点部署示例
20
- * // 通过不同的基础路径支持多语言站点
19
+ * // 2. Multi-language site deployment example
20
+ * // Support multi-language sites through different base paths
21
21
  * const rc = await esmx.render({
22
- * base: '/cn', // 中文站点
22
+ * base: '/cn', // Chinese site
23
23
  * params: { lang: 'zh-CN' }
24
24
  * });
25
25
  *
26
- * // 3. 导入映射模式配置示例
26
+ * // 3. Import map mode configuration example
27
27
  * const rc = await esmx.render({
28
- * // 使用内联模式,适合小型应用
28
+ * // Use inline mode, suitable for small applications
29
29
  * importmapMode: 'inline',
30
- * // 其他配置...
30
+ * // Other configurations...
31
31
  * });
32
32
  * ```
33
33
  */
34
34
  export interface RenderContextOptions {
35
35
  /**
36
- * 静态资源的基础路径
36
+ * Base path for static assets
37
37
  * @description
38
- * - 默认为空字符串
39
- * - 所有静态资源(JSCSS、图片等)都会基于此路径加载
40
- * - 支持运行时动态配置,无需重新构建
41
- * - 常用于多语言站点、微前端应用等场景
38
+ * - Defaults to empty string
39
+ * - All static assets (JS, CSS, images, etc.) will be loaded based on this path
40
+ * - Supports runtime dynamic configuration without rebuilding
41
+ * - Commonly used for multi-language sites, micro-frontends, and other scenarios
42
42
  */
43
43
  base?: string;
44
44
  /**
45
- * 服务端渲染入口名称
45
+ * Server-side rendering entry name
46
46
  * @description
47
- * - 默认为 'default'
48
- * - 用于指定服务端渲染时使用的入口函数
49
- * - 当一个模块导出多个渲染函数时使用
47
+ * - Defaults to 'default'
48
+ * - Used to specify the entry function used during server-side rendering
49
+ * - Used when a module exports multiple rendering functions
50
50
  */
51
51
  entryName?: string;
52
52
  /**
53
- * 渲染参数
53
+ * Rendering parameters
54
54
  * @description
55
- * - 可以传递任意类型的参数给渲染函数
56
- * - 常用于传递请求信息(URLquery 参数等)
57
- * - 在服务端渲染过程中可以通过 rc.params 访问
55
+ * - Can pass parameters of any type to the rendering function
56
+ * - Commonly used to pass request information (URL, query parameters, etc.)
57
+ * - Can be accessed through rc.params during server-side rendering
58
58
  */
59
59
  params?: Record<string, any>;
60
60
  /**
61
- * 定义 importmap 的生成模式
61
+ * Define the generation mode for importmap
62
62
  *
63
63
  * @description
64
- * ImportmapMode 用于控制 importmap 的生成方式,支持两种模式:
65
- * - `inline`: importmap 内容直接内联到 HTML 中(默认值),适用于以下场景:
66
- * - 需要减少 HTTP 请求数量
67
- * - importmap 内容较小
68
- * - 对首屏加载性能要求较高
69
- * - `js`: importmap 内容生成为独立的 JS 文件,适用于以下场景:
70
- * - importmap 内容较大
71
- * - 需要利用浏览器缓存机制
72
- * - 多个页面共享相同的 importmap
73
- *
74
- * 默认值选择 'inline' 的原因:
75
- * 1. 简单直接
76
- * - 减少额外的 HTTP 请求
77
- * - 无需额外的资源管理
78
- * - 适合大多数应用场景
79
- * 2. 首屏性能
80
- * - 避免额外的网络请求
81
- * - 确保导入映射立即可用
82
- * - 减少页面加载时间
83
- * 3. 易于调试
84
- * - 导入映射直接可见
85
- * - 便于问题诊断
86
- * - 简化开发流程
64
+ * ImportmapMode is used to control the generation method of importmap, supporting two modes:
65
+ * - `inline`: Inline importmap content directly into HTML (default value), suitable for the following scenarios:
66
+ * - Need to reduce the number of HTTP requests
67
+ * - Importmap content is small
68
+ * - High requirements for first-screen loading performance
69
+ * - `js`: Generate importmap content as an independent JS file, suitable for the following scenarios:
70
+ * - Importmap content is large
71
+ * - Need to utilize browser caching mechanisms
72
+ * - Multiple pages share the same importmap
73
+ *
74
+ * Reasons for choosing 'inline' as the default value:
75
+ * 1. Simple and direct
76
+ * - Reduce additional HTTP requests
77
+ * - No additional resource management required
78
+ * - Suitable for most application scenarios
79
+ * 2. First-screen performance
80
+ * - Avoid additional network requests
81
+ * - Ensure import maps are immediately available
82
+ * - Reduce page loading time
83
+ * 3. Easy to debug
84
+ * - Import maps are directly visible
85
+ * - Facilitate problem diagnosis
86
+ * - Simplify development process
87
87
  *
88
88
  * @example
89
89
  * ```ts
90
- * // 使用内联模式(默认)
90
+ * // Use inline mode (default)
91
91
  * const rc = await esmx.render({
92
92
  * params: { url: req.url }
93
93
  * });
94
94
  *
95
- * // 显式指定内联模式
95
+ * // Explicitly specify inline mode
96
96
  * const rc = await esmx.render({
97
97
  * importmapMode: 'inline',
98
98
  * params: { url: req.url }
99
99
  * });
100
100
  *
101
- * // 使用 JS 文件模式
101
+ * // Use JS file mode
102
102
  * const rc = await esmx.render({
103
103
  * importmapMode: 'js',
104
104
  * params: { url: req.url }
@@ -108,47 +108,47 @@ export interface RenderContextOptions {
108
108
  importmapMode?: ImportmapMode;
109
109
  }
110
110
  /**
111
- * 服务端渲染函数
111
+ * Server-side rendering function
112
112
  */
113
113
  export type ServerRenderHandle = (rc: RenderContext) => Promise<void>;
114
114
  /**
115
- * 渲染资源文件列表接口
115
+ * Render resource file list interface
116
116
  * @description
117
- * RenderFiles 接口定义了服务端渲染过程中收集的各类静态资源:
117
+ * The RenderFiles interface defines various static assets collected during the server-side rendering process:
118
118
  *
119
- * 1. **资源类型**
120
- * - css: 样式表文件列表
121
- * - modulepreload: 需要预加载的 ESM 模块列表
122
- * - js: JavaScript 文件列表
123
- * - resources: 其他资源文件列表
119
+ * 1. **Resource Types**
120
+ * - css: List of stylesheet files
121
+ * - modulepreload: List of ESM modules that need to be preloaded
122
+ * - js: List of JavaScript files
123
+ * - resources: List of other resource files
124
124
  *
125
- * 2. **使用场景**
126
- * - commit() 方法中自动收集
127
- * - 通过 preload()css() 等方法注入
128
- * - 支持基础路径配置
125
+ * 2. **Use Cases**
126
+ * - Automatically collected in the commit() method
127
+ * - Injected through methods like preload(), css(), etc.
128
+ * - Supports base path configuration
129
129
  *
130
130
  * @example
131
131
  * ```ts
132
- * // 1. 资源收集
132
+ * // 1. Resource collection
133
133
  * await rc.commit();
134
134
  *
135
- * // 2. 资源注入
135
+ * // 2. Resource injection
136
136
  * rc.html = `
137
137
  * <!DOCTYPE html>
138
138
  * <html>
139
139
  * <head>
140
- * <!-- 预加载资源 -->
140
+ * <!-- Preload resources -->
141
141
  * ${rc.preload()}
142
- * <!-- 注入样式表 -->
142
+ * <!-- Inject stylesheets -->
143
143
  * ${rc.css()}
144
144
  * </head>
145
145
  * <body>
146
146
  * ${html}
147
- * <!-- 注入导入映射 -->
147
+ * <!-- Inject import map -->
148
148
  * ${rc.importmap()}
149
- * <!-- 注入客户端入口 -->
149
+ * <!-- Inject client entry -->
150
150
  * ${rc.moduleEntry()}
151
- * <!-- 预加载模块 -->
151
+ * <!-- Preload modules -->
152
152
  * ${rc.modulePreload()}
153
153
  * </body>
154
154
  * </html>
@@ -157,64 +157,64 @@ export type ServerRenderHandle = (rc: RenderContext) => Promise<void>;
157
157
  */
158
158
  export interface RenderFiles {
159
159
  /**
160
- * JavaScript 文件列表
160
+ * List of JavaScript files
161
161
  */
162
162
  js: string[];
163
163
  /**
164
- * CSS 文件列表
164
+ * List of CSS files
165
165
  */
166
166
  css: string[];
167
167
  /**
168
- * 需要预加载的 ESM 模块列表
168
+ * List of ESM modules that need to be preloaded
169
169
  */
170
170
  modulepreload: string[];
171
171
  /**
172
- * 其他资源文件列表(图片、字体等)
172
+ * List of other resource files (images, fonts, etc.)
173
173
  */
174
174
  resources: string[];
175
175
  }
176
176
  /**
177
- * 定义 importmap 的生成模式
177
+ * Define the generation mode for importmap
178
178
  *
179
179
  * @description
180
- * ImportmapMode 用于控制 importmap 的生成方式,支持两种模式:
181
- * - `inline`: importmap 内容直接内联到 HTML 中(默认值),适用于以下场景:
182
- * - 需要减少 HTTP 请求数量
183
- * - importmap 内容较小
184
- * - 对首屏加载性能要求较高
185
- * - `js`: importmap 内容生成为独立的 JS 文件,适用于以下场景:
186
- * - importmap 内容较大
187
- * - 需要利用浏览器缓存机制
188
- * - 多个页面共享相同的 importmap
180
+ * ImportmapMode is used to control the generation method of importmap, supporting two modes:
181
+ * - `inline`: Inline importmap content directly into HTML (default value), suitable for the following scenarios:
182
+ * - Need to reduce the number of HTTP requests
183
+ * - Importmap content is small
184
+ * - High requirements for first-screen loading performance
185
+ * - `js`: Generate importmap content as an independent JS file, suitable for the following scenarios:
186
+ * - Importmap content is large
187
+ * - Need to utilize browser caching mechanisms
188
+ * - Multiple pages share the same importmap
189
189
  *
190
- * 默认值选择 'inline' 的原因:
191
- * 1. 简单直接
192
- * - 减少额外的 HTTP 请求
193
- * - 无需额外的资源管理
194
- * - 适合大多数应用场景
195
- * 2. 首屏性能
196
- * - 避免额外的网络请求
197
- * - 确保导入映射立即可用
198
- * - 减少页面加载时间
199
- * 3. 易于调试
200
- * - 导入映射直接可见
201
- * - 便于问题诊断
202
- * - 简化开发流程
190
+ * Reasons for choosing 'inline' as the default value:
191
+ * 1. Simple and direct
192
+ * - Reduce additional HTTP requests
193
+ * - No additional resource management required
194
+ * - Suitable for most application scenarios
195
+ * 2. First-screen performance
196
+ * - Avoid additional network requests
197
+ * - Ensure import maps are immediately available
198
+ * - Reduce page loading time
199
+ * 3. Easy to debug
200
+ * - Import maps are directly visible
201
+ * - Facilitate problem diagnosis
202
+ * - Simplify development process
203
203
  *
204
204
  * @example
205
205
  * ```ts
206
- * // 使用内联模式(默认)
206
+ * // Use inline mode (default)
207
207
  * const rc = await esmx.render({
208
208
  * params: { url: req.url }
209
209
  * });
210
210
  *
211
- * // 显式指定内联模式
211
+ * // Explicitly specify inline mode
212
212
  * const rc = await esmx.render({
213
213
  * importmapMode: 'inline',
214
214
  * params: { url: req.url }
215
215
  * });
216
216
  *
217
- * // 使用 JS 文件模式
217
+ * // Use JS file mode
218
218
  * const rc = await esmx.render({
219
219
  * importmapMode: 'js',
220
220
  * params: { url: req.url }
@@ -223,59 +223,59 @@ export interface RenderFiles {
223
223
  */
224
224
  export type ImportmapMode = 'inline' | 'js';
225
225
  /**
226
- * RenderContext Esmx 框架中的核心类,负责服务端渲染(SSR)过程中的资源管理和 HTML 生成
226
+ * RenderContext is the core class in the Esmx framework, responsible for resource management and HTML generation during server-side rendering (SSR)
227
227
  *
228
228
  * @description
229
- * RenderContext 具有以下核心特点:
230
- * 1. **基于 ESM 的模块系统**
231
- * - 采用现代的 ECMAScript Modules 标准
232
- * - 支持原生的模块导入导出
233
- * - 实现了更好的代码分割和按需加载
229
+ * RenderContext has the following core features:
230
+ * 1. **ESM-based module system**
231
+ * - Adopts modern ECMAScript Modules standard
232
+ * - Supports native module imports and exports
233
+ * - Implements better code splitting and on-demand loading
234
234
  *
235
- * 2. **智能依赖收集**
236
- * - 基于实际渲染路径动态收集依赖
237
- * - 避免不必要的资源加载
238
- * - 支持异步组件和动态导入
235
+ * 2. **Intelligent dependency collection**
236
+ * - Dynamically collects dependencies based on actual rendering paths
237
+ * - Avoids unnecessary resource loading
238
+ * - Supports async components and dynamic imports
239
239
  *
240
- * 3. **精确的资源注入**
241
- * - 严格控制资源加载顺序
242
- * - 优化首屏加载性能
243
- * - 确保客户端激活(Hydration)的可靠性
240
+ * 3. **Precise resource injection**
241
+ * - Strictly controls resource loading order
242
+ * - Optimizes first-screen loading performance
243
+ * - Ensures reliability of client-side hydration
244
244
  *
245
- * 4. **灵活的配置机制**
246
- * - 支持动态基础路径配置
247
- * - 提供多种导入映射模式
248
- * - 适应不同的部署场景
245
+ * 4. **Flexible configuration mechanism**
246
+ * - Supports dynamic base path configuration
247
+ * - Provides multiple import map modes
248
+ * - Adapts to different deployment scenarios
249
249
  *
250
250
  * @example
251
251
  * ```ts
252
252
  * export default async (rc: RenderContext) => {
253
- * // 1. 渲染页面内容并收集依赖
253
+ * // 1. Render page content and collect dependencies
254
254
  * const app = createApp();
255
255
  * const html = await renderToString(app, {
256
256
  * importMetaSet: rc.importMetaSet
257
257
  * });
258
258
  *
259
- * // 2. 提交依赖收集
259
+ * // 2. Commit dependency collection
260
260
  * await rc.commit();
261
261
  *
262
- * // 3. 生成完整 HTML
262
+ * // 3. Generate complete HTML
263
263
  * rc.html = `
264
264
  * <!DOCTYPE html>
265
265
  * <html>
266
266
  * <head>
267
- * <!-- 预加载 CSS JS 资源,提前开始加载以优化性能 -->
267
+ * <!-- Preload CSS and JS resources to start loading early for performance optimization -->
268
268
  * ${rc.preload()}
269
- * <!-- 注入首屏样式表,避免页面闪烁 -->
269
+ * <!-- Inject first-screen stylesheets to avoid page flickering -->
270
270
  * ${rc.css()}
271
271
  * </head>
272
272
  * <body>
273
273
  * ${html}
274
- * <!-- 注入模块导入映射,定义 ESM 模块的路径解析规则 -->
274
+ * <!-- Inject module import map to define path resolution rules for ESM modules -->
275
275
  * ${rc.importmap()}
276
- * <!-- 注入客户端入口模块,必须在 importmap 之后执行 -->
276
+ * <!-- Inject client entry module, must be executed after importmap -->
277
277
  * ${rc.moduleEntry()}
278
- * <!-- 预加载模块依赖,基于实际渲染收集的依赖进行优化加载 -->
278
+ * <!-- Preload module dependencies, optimized loading based on dependencies collected during actual rendering -->
279
279
  * ${rc.modulePreload()}
280
280
  * </body>
281
281
  * </html>
@@ -286,35 +286,35 @@ export type ImportmapMode = 'inline' | 'js';
286
286
  export declare class RenderContext {
287
287
  esmx: Esmx;
288
288
  /**
289
- * 重定向地址
289
+ * Redirect address
290
290
  * @description
291
- * - 默认为 null,表示不进行重定向
292
- * - 设置后,服务端可以根据此值进行 HTTP 重定向
293
- * - 常用于登录验证、权限控制等场景
291
+ * - Defaults to null, indicating no redirect
292
+ * - When set, the server can perform HTTP redirection based on this value
293
+ * - Commonly used for scenarios like login verification, permission control, etc.
294
294
  *
295
295
  * @example
296
296
  * ```ts
297
- * // 1. 登录验证示例
297
+ * // 1. Login verification example
298
298
  * export default async (rc: RenderContext) => {
299
299
  * if (!isLoggedIn()) {
300
300
  * rc.redirect = '/login';
301
301
  * rc.status = 302;
302
302
  * return;
303
303
  * }
304
- * // 继续渲染页面...
304
+ * // Continue rendering page...
305
305
  * };
306
306
  *
307
- * // 2. 权限控制示例
307
+ * // 2. Permission control example
308
308
  * export default async (rc: RenderContext) => {
309
309
  * if (!hasPermission()) {
310
310
  * rc.redirect = '/403';
311
311
  * rc.status = 403;
312
312
  * return;
313
313
  * }
314
- * // 继续渲染页面...
314
+ * // Continue rendering page...
315
315
  * };
316
316
  *
317
- * // 3. 服务端处理示例
317
+ * // 3. Server-side processing example
318
318
  * app.use(async (req, res) => {
319
319
  * const rc = await esmx.render({
320
320
  * params: {
@@ -322,7 +322,7 @@ export declare class RenderContext {
322
322
  * }
323
323
  * });
324
324
  *
325
- * // 处理重定向
325
+ * // Handle redirect
326
326
  * if (rc.redirect) {
327
327
  * res.statusCode = rc.status || 302;
328
328
  * res.setHeader('Location', rc.redirect);
@@ -330,49 +330,49 @@ export declare class RenderContext {
330
330
  * return;
331
331
  * }
332
332
  *
333
- * // 设置状态码
333
+ * // Set status code
334
334
  * if (rc.status) {
335
335
  * res.statusCode = rc.status;
336
336
  * }
337
337
  *
338
- * // 响应 HTML 内容
338
+ * // Respond with HTML content
339
339
  * res.end(rc.html);
340
340
  * });
341
341
  * ```
342
342
  */
343
343
  redirect: string | null;
344
344
  /**
345
- * HTTP 响应状态码
345
+ * HTTP response status code
346
346
  * @description
347
- * - 默认为 null,表示使用 200 状态码
348
- * - 可以设置任意有效的 HTTP 状态码
349
- * - 常用于错误处理、重定向等场景
350
- * - 通常与 redirect 属性配合使用
347
+ * - Defaults to null, indicating use of 200 status code
348
+ * - Can set any valid HTTP status code
349
+ * - Commonly used for scenarios like error handling, redirection, etc.
350
+ * - Usually used in conjunction with the redirect property
351
351
  *
352
352
  * @example
353
353
  * ```ts
354
- * // 1. 404 错误处理示例
354
+ * // 1. 404 error handling example
355
355
  * export default async (rc: RenderContext) => {
356
356
  * const page = await findPage(rc.params.url);
357
357
  * if (!page) {
358
358
  * rc.status = 404;
359
- * // 渲染 404 页面...
359
+ * // Render 404 page...
360
360
  * return;
361
361
  * }
362
- * // 继续渲染页面...
362
+ * // Continue rendering page...
363
363
  * };
364
364
  *
365
- * // 2. 临时重定向示例
365
+ * // 2. Temporary redirect example
366
366
  * export default async (rc: RenderContext) => {
367
367
  * if (needMaintenance()) {
368
368
  * rc.redirect = '/maintenance';
369
- * rc.status = 307; // 临时重定向,保持请求方法不变
369
+ * rc.status = 307; // Temporary redirect, keep request method unchanged
370
370
  * return;
371
371
  * }
372
- * // 继续渲染页面...
372
+ * // Continue rendering page...
373
373
  * };
374
374
  *
375
- * // 3. 服务端处理示例
375
+ * // 3. Server-side processing example
376
376
  * app.use(async (req, res) => {
377
377
  * const rc = await esmx.render({
378
378
  * params: {
@@ -380,7 +380,7 @@ export declare class RenderContext {
380
380
  * }
381
381
  * });
382
382
  *
383
- * // 处理重定向
383
+ * // Handle redirect
384
384
  * if (rc.redirect) {
385
385
  * res.statusCode = rc.status || 302;
386
386
  * res.setHeader('Location', rc.redirect);
@@ -388,12 +388,12 @@ export declare class RenderContext {
388
388
  * return;
389
389
  * }
390
390
  *
391
- * // 设置状态码
391
+ * // Set status code
392
392
  * if (rc.status) {
393
393
  * res.statusCode = rc.status;
394
394
  * }
395
395
  *
396
- * // 响应 HTML 内容
396
+ * // Respond with HTML content
397
397
  * res.end(rc.html);
398
398
  * });
399
399
  * ```
@@ -401,80 +401,80 @@ export declare class RenderContext {
401
401
  status: number | null;
402
402
  private _html;
403
403
  /**
404
- * 静态资源的基础路径
404
+ * Base path for static assets
405
405
  * @description
406
- * base 属性用于控制静态资源的加载路径,是 Esmx 框架动态基础路径配置的核心:
406
+ * The base property is used to control the loading path of static assets and is the core of Esmx framework's dynamic base path configuration:
407
407
  *
408
- * 1. **构建时处理**
409
- * - 静态资源路径使用特殊占位符标记:`[[[___GEZ_DYNAMIC_BASE___]]]/your-app-name/`
410
- * - 占位符会被注入到所有静态资源的引用路径中
411
- * - 支持 CSSJavaScript、图片等各类静态资源
408
+ * 1. **Build-time Processing**
409
+ * - Static asset paths are marked with special placeholders: `[[[___ESMX_DYNAMIC_BASE___]]]/your-app-name/`
410
+ * - Placeholders are injected into all static asset reference paths
411
+ * - Supports various static assets like CSS, JavaScript, images, etc.
412
412
  *
413
- * 2. **运行时替换**
414
- * - 通过 `esmx.render()` 的 `base` 参数设置实际基础路径
415
- * - RenderContext 自动将 HTML 中的占位符替换为实际路径
413
+ * 2. **Runtime Replacement**
414
+ * - Set the actual base path through the `base` parameter of `esmx.render()`
415
+ * - RenderContext automatically replaces placeholders in HTML with actual paths
416
416
  *
417
- * 3. **技术优势**
418
- * - 部署灵活:同一套构建产物可部署到任意路径
419
- * - 性能优化:保持静态资源的最佳缓存策略
420
- * - 开发友好:简化多环境配置管理
417
+ * 3. **Technical Advantages**
418
+ * - Deployment flexibility: The same set of build artifacts can be deployed to any path
419
+ * - Performance optimization: Maintain the best caching strategy for static assets
420
+ * - Development-friendly: Simplify multi-environment configuration management
421
421
  *
422
422
  * @example
423
423
  * ```ts
424
- * // 1. 基础用法
424
+ * // 1. Basic usage
425
425
  * const rc = await esmx.render({
426
- * base: '/esmx', // 设置基础路径
426
+ * base: '/esmx', // Set base path
427
427
  * params: { url: req.url }
428
428
  * });
429
429
  *
430
- * // 2. 多语言站点示例
430
+ * // 2. Multi-language site example
431
431
  * const rc = await esmx.render({
432
- * base: '/cn', // 中文站点
432
+ * base: '/cn', // Chinese site
433
433
  * params: { lang: 'zh-CN' }
434
434
  * });
435
435
  *
436
- * // 3. 微前端应用示例
436
+ * // 3. Micro-frontend application example
437
437
  * const rc = await esmx.render({
438
- * base: '/app1', // 子应用1
438
+ * base: '/app1', // Sub-application 1
439
439
  * params: { appId: 1 }
440
440
  * });
441
441
  * ```
442
442
  */
443
443
  readonly base: string;
444
444
  /**
445
- * 服务端渲染入口函数名称
445
+ * Server-side rendering entry function name
446
446
  * @description
447
- * entryName 属性用于指定服务端渲染时使用的入口函数:
447
+ * The entryName property is used to specify the entry function used during server-side rendering:
448
448
  *
449
- * 1. **基本用途**
450
- * - 默认值为 'default'
451
- * - 用于从 entry.server.ts 中选择要使用的渲染函数
452
- * - 支持一个模块导出多个渲染函数的场景
449
+ * 1. **Basic Usage**
450
+ * - Default value is 'default'
451
+ * - Used to select the rendering function to use from entry.server.ts
452
+ * - Supports scenarios where a module exports multiple rendering functions
453
453
  *
454
- * 2. **使用场景**
455
- * - 多模板渲染:不同页面使用不同的渲染模板
456
- * - A/B 测试:同一页面使用不同的渲染逻辑
457
- * - 特殊渲染:某些页面需要自定义的渲染流程
454
+ * 2. **Use Cases**
455
+ * - Multi-template rendering: Different pages use different rendering templates
456
+ * - A/B testing: The same page uses different rendering logic
457
+ * - Special rendering: Some pages need custom rendering processes
458
458
  *
459
459
  * @example
460
460
  * ```ts
461
- * // 1. 默认入口函数
461
+ * // 1. Default entry function
462
462
  * // entry.server.ts
463
463
  * export default async (rc: RenderContext) => {
464
- * // 默认渲染逻辑
464
+ * // Default rendering logic
465
465
  * };
466
466
  *
467
- * // 2. 多个入口函数
467
+ * // 2. Multiple entry functions
468
468
  * // entry.server.ts
469
469
  * export const mobile = async (rc: RenderContext) => {
470
- * // 移动端渲染逻辑
470
+ * // Mobile rendering logic
471
471
  * };
472
472
  *
473
473
  * export const desktop = async (rc: RenderContext) => {
474
- * // 桌面端渲染逻辑
474
+ * // Desktop rendering logic
475
475
  * };
476
476
  *
477
- * // 3. 根据设备类型选择入口函数
477
+ * // 3. Select entry function based on device type
478
478
  * const rc = await esmx.render({
479
479
  * entryName: isMobile ? 'mobile' : 'desktop',
480
480
  * params: { url: req.url }
@@ -483,29 +483,29 @@ export declare class RenderContext {
483
483
  */
484
484
  readonly entryName: string;
485
485
  /**
486
- * 渲染参数
486
+ * Rendering parameters
487
487
  * @description
488
- * params 属性用于在服务端渲染过程中传递和访问参数:
488
+ * The params property is used to pass and access parameters during the server-side rendering process:
489
489
  *
490
- * 1. **参数类型**
491
- * - 支持任意类型的键值对
492
- * - 通过 Record<string, any> 类型定义
493
- * - 在整个渲染生命周期中保持不变
490
+ * 1. **Parameter Types**
491
+ * - Supports key-value pairs of any type
492
+ * - Defined through Record<string, any> type
493
+ * - Remains unchanged throughout the entire rendering lifecycle
494
494
  *
495
- * 2. **常见使用场景**
496
- * - 传递请求信息(URLquery 参数等)
497
- * - 设置页面配置(语言、主题等)
498
- * - 注入环境变量(API 地址、版本号等)
499
- * - 共享服务端状态(用户信息、权限等)
495
+ * 2. **Common Use Cases**
496
+ * - Pass request information (URL, query parameters, etc.)
497
+ * - Set page configuration (language, theme, etc.)
498
+ * - Inject environment variables (API address, version number, etc.)
499
+ * - Share server-side state (user information, permissions, etc.)
500
500
  *
501
- * 3. **访问方式**
502
- * - 在服务端渲染函数中通过 rc.params 访问
503
- * - 可以解构获取特定参数
504
- * - 支持设置默认值
501
+ * 3. **Access Methods**
502
+ * - Accessed through rc.params in server-side rendering functions
503
+ * - Can destructure to get specific parameters
504
+ * - Supports setting default values
505
505
  *
506
506
  * @example
507
507
  * ```ts
508
- * // 1. 基础用法 - 传递 URL 和语言设置
508
+ * // 1. Basic usage - Pass URL and language settings
509
509
  * const rc = await esmx.render({
510
510
  * params: {
511
511
  * url: req.url,
@@ -513,7 +513,7 @@ export declare class RenderContext {
513
513
  * }
514
514
  * });
515
515
  *
516
- * // 2. 页面配置 - 设置主题和布局
516
+ * // 2. Page configuration - Set theme and layout
517
517
  * const rc = await esmx.render({
518
518
  * params: {
519
519
  * theme: 'dark',
@@ -521,7 +521,7 @@ export declare class RenderContext {
521
521
  * }
522
522
  * });
523
523
  *
524
- * // 3. 环境配置 - 注入 API 地址
524
+ * // 3. Environment configuration - Inject API address
525
525
  * const rc = await esmx.render({
526
526
  * params: {
527
527
  * apiBaseUrl: process.env.API_BASE_URL,
@@ -529,17 +529,17 @@ export declare class RenderContext {
529
529
  * }
530
530
  * });
531
531
  *
532
- * // 4. 在渲染函数中使用
532
+ * // 4. Use in rendering function
533
533
  * export default async (rc: RenderContext) => {
534
- * // 解构获取参数
534
+ * // Destructure to get parameters
535
535
  * const { url, lang = 'en' } = rc.params;
536
536
  *
537
- * // 根据参数执行不同逻辑
537
+ * // Execute different logic based on parameters
538
538
  * if (lang === 'zh-CN') {
539
- * // 中文版本处理...
539
+ * // Chinese version processing...
540
540
  * }
541
541
  *
542
- * // 传递参数到组件
542
+ * // Pass parameters to component
543
543
  * const html = await renderToString(createApp({
544
544
  * props: {
545
545
  * currentUrl: url,
@@ -547,7 +547,7 @@ export declare class RenderContext {
547
547
  * }
548
548
  * }));
549
549
  *
550
- * // 设置 HTML
550
+ * // Set HTML
551
551
  * rc.html = `
552
552
  * <!DOCTYPE html>
553
553
  * <html lang="${lang}">
@@ -559,50 +559,50 @@ export declare class RenderContext {
559
559
  */
560
560
  readonly params: Record<string, any>;
561
561
  /**
562
- * 模块依赖收集集合
562
+ * Module dependency collection set
563
563
  * @description
564
- * importMetaSet Esmx 框架智能依赖收集机制的核心,用于在服务端渲染过程中追踪和记录模块依赖:
564
+ * importMetaSet is the core of Esmx framework's intelligent dependency collection mechanism, used to track and record module dependencies during the server-side rendering process:
565
565
  *
566
- * 1. **按需收集**
567
- * - 在组件实际渲染过程中自动追踪和记录模块依赖
568
- * - 只收集当前页面渲染时真正使用到的资源
569
- * - 精确记录每个组件的模块依赖关系
566
+ * 1. **On-demand Collection**
567
+ * - Automatically tracks and records module dependencies during the actual component rendering process
568
+ * - Only collects resources actually used during the current page rendering
569
+ * - Precisely records the module dependency relationships of each component
570
570
  *
571
- * 2. **性能优化**
572
- * - 避免加载未使用的模块,显著减少首屏加载时间
573
- * - 精确控制资源加载顺序,优化页面渲染性能
574
- * - 自动生成最优的导入映射(Import Map)
571
+ * 2. **Performance Optimization**
572
+ * - Avoids loading unused modules, significantly reducing first-screen loading time
573
+ * - Precisely controls resource loading order, optimizing page rendering performance
574
+ * - Automatically generates optimal import maps
575
575
  *
576
- * 3. **使用方式**
577
- * - 在渲染函数中传递给 renderToString
578
- * - 框架自动收集依赖,无需手动处理
579
- * - 支持异步组件和动态导入的依赖收集
576
+ * 3. **Usage**
577
+ * - Passed to renderToString in the rendering function
578
+ * - Framework automatically collects dependencies, no manual handling required
579
+ * - Supports dependency collection for async components and dynamic imports
580
580
  *
581
581
  * @example
582
582
  * ```ts
583
- * // 1. 基础用法
583
+ * // 1. Basic usage
584
584
  * const renderToString = (app: any, context: { importMetaSet: Set<ImportMeta> }) => {
585
- * // 在渲染过程中自动收集模块依赖
586
- * // 框架会在组件渲染时自动调用 context.importMetaSet.add(import.meta)
587
- * // 开发者无需手动处理依赖收集
585
+ * // Automatically collect module dependencies during the rendering process
586
+ * // Framework will automatically call context.importMetaSet.add(import.meta) during component rendering
587
+ * // Developers do not need to manually handle dependency collection
588
588
  * return '<div id="app">Hello World</div>';
589
589
  * };
590
590
  *
591
- * // 使用示例
591
+ * // Usage example
592
592
  * const app = createApp();
593
593
  * const html = await renderToString(app, {
594
594
  * importMetaSet: rc.importMetaSet
595
595
  * });
596
596
  *
597
- * // 2. 提交依赖
597
+ * // 2. Commit dependencies
598
598
  * await rc.commit();
599
599
  *
600
- * // 3. 生成 HTML
600
+ * // 3. Generate HTML
601
601
  * rc.html = `
602
602
  * <!DOCTYPE html>
603
603
  * <html>
604
604
  * <head>
605
- * <!-- 基于收集的依赖自动注入资源 -->
605
+ * <!-- Automatically inject resources based on collected dependencies -->
606
606
  * ${rc.preload()}
607
607
  * ${rc.css()}
608
608
  * </head>
@@ -618,35 +618,35 @@ export declare class RenderContext {
618
618
  */
619
619
  importMetaSet: Set<ImportMeta>;
620
620
  /**
621
- * 资源文件列表
621
+ * Resource file list
622
622
  * @description
623
- * files 属性存储了在服务端渲染过程中收集到的所有静态资源文件路径:
623
+ * The files property stores all static resource file paths collected during the server-side rendering process:
624
624
  *
625
- * 1. **资源类型**
626
- * - js: JavaScript 文件列表,包含所有脚本和模块
627
- * - css: 样式表文件列表
628
- * - modulepreload: 需要预加载的 ESM 模块列表
629
- * - importmap: 导入映射文件列表
630
- * - resources: 其他资源文件列表(图片、字体等)
625
+ * 1. **Resource Types**
626
+ * - js: List of JavaScript files, containing all scripts and modules
627
+ * - css: List of stylesheet files
628
+ * - modulepreload: List of ESM modules that need to be preloaded
629
+ * - importmap: List of import map files
630
+ * - resources: List of other resource files (images, fonts, etc.)
631
631
  *
632
- * 2. **使用场景**
633
- * - commit() 方法中自动收集和分类资源
634
- * - 通过 preload()css() 等方法注入资源到 HTML
635
- * - 支持基础路径配置,实现资源的动态加载
632
+ * 2. **Use Cases**
633
+ * - Automatically collect and categorize resources in the commit() method
634
+ * - Inject resources into HTML through methods like preload(), css(), etc.
635
+ * - Supports base path configuration, implementing dynamic loading of resources
636
636
  *
637
637
  * @example
638
638
  * ```ts
639
- * // 1. 资源收集
639
+ * // 1. Resource collection
640
640
  * await rc.commit();
641
641
  *
642
- * // 2. 资源注入
642
+ * // 2. Resource injection
643
643
  * rc.html = `
644
644
  * <!DOCTYPE html>
645
645
  * <html>
646
646
  * <head>
647
- * <!-- 预加载资源 -->
647
+ * <!-- Preload resources -->
648
648
  * ${rc.preload()}
649
- * <!-- 注入样式表 -->
649
+ * <!-- Inject stylesheets -->
650
650
  * ${rc.css()}
651
651
  * </head>
652
652
  * <body>
@@ -662,47 +662,47 @@ export declare class RenderContext {
662
662
  files: RenderFiles;
663
663
  private _importMap;
664
664
  /**
665
- * 定义 importmap 的生成模式
665
+ * Define the generation mode for importmap
666
666
  *
667
667
  * @description
668
- * ImportmapMode 用于控制 importmap 的生成方式,支持两种模式:
669
- * - `inline`: importmap 内容直接内联到 HTML 中(默认值),适用于以下场景:
670
- * - 需要减少 HTTP 请求数量
671
- * - importmap 内容较小
672
- * - 对首屏加载性能要求较高
673
- * - `js`: importmap 内容生成为独立的 JS 文件,适用于以下场景:
674
- * - importmap 内容较大
675
- * - 需要利用浏览器缓存机制
676
- * - 多个页面共享相同的 importmap
677
- *
678
- * 默认值选择 'inline' 的原因:
679
- * 1. 简单直接
680
- * - 减少额外的 HTTP 请求
681
- * - 无需额外的资源管理
682
- * - 适合大多数应用场景
683
- * 2. 首屏性能
684
- * - 避免额外的网络请求
685
- * - 确保导入映射立即可用
686
- * - 减少页面加载时间
687
- * 3. 易于调试
688
- * - 导入映射直接可见
689
- * - 便于问题诊断
690
- * - 简化开发流程
668
+ * ImportmapMode is used to control the generation method of importmap, supporting two modes:
669
+ * - `inline`: Inline importmap content directly into HTML (default value), suitable for the following scenarios:
670
+ * - Need to reduce the number of HTTP requests
671
+ * - Importmap content is small
672
+ * - High requirements for first-screen loading performance
673
+ * - `js`: Generate importmap content as an independent JS file, suitable for the following scenarios:
674
+ * - Importmap content is large
675
+ * - Need to utilize browser caching mechanisms
676
+ * - Multiple pages share the same importmap
677
+ *
678
+ * Reasons for choosing 'inline' as the default value:
679
+ * 1. Simple and direct
680
+ * - Reduce additional HTTP requests
681
+ * - No additional resource management required
682
+ * - Suitable for most application scenarios
683
+ * 2. First-screen performance
684
+ * - Avoid additional network requests
685
+ * - Ensure import maps are immediately available
686
+ * - Reduce page loading time
687
+ * 3. Easy to debug
688
+ * - Import maps are directly visible
689
+ * - Facilitate problem diagnosis
690
+ * - Simplify development process
691
691
  *
692
692
  * @example
693
693
  * ```ts
694
- * // 使用内联模式(默认)
694
+ * // Use inline mode (default)
695
695
  * const rc = await esmx.render({
696
696
  * params: { url: req.url }
697
697
  * });
698
698
  *
699
- * // 显式指定内联模式
699
+ * // Explicitly specify inline mode
700
700
  * const rc = await esmx.render({
701
701
  * importmapMode: 'inline',
702
702
  * params: { url: req.url }
703
703
  * });
704
704
  *
705
- * // 使用 JS 文件模式
705
+ * // Use JS file mode
706
706
  * const rc = await esmx.render({
707
707
  * importmapMode: 'js',
708
708
  * params: { url: req.url }
@@ -711,25 +711,25 @@ export declare class RenderContext {
711
711
  */
712
712
  importmapMode: ImportmapMode;
713
713
  /**
714
- * HTML 内容
714
+ * HTML content
715
715
  * @description
716
- * html 属性用于设置和获取最终生成的 HTML 内容:
716
+ * The html property is used to set and get the final generated HTML content:
717
717
  *
718
- * 1. **基础路径替换**
719
- * - 在设置 HTML 时自动处理基础路径占位符
720
- * - `[[[___GEZ_DYNAMIC_BASE___]]]/your-app-name/` 替换为实际的 base 路径
721
- * - 确保所有静态资源的引用路径正确
718
+ * 1. **Base Path Replacement**
719
+ * - Automatically handles base path placeholders when setting HTML
720
+ * - Replaces `[[[___ESMX_DYNAMIC_BASE___]]]/your-app-name/` with the actual base path
721
+ * - Ensures all static asset reference paths are correct
722
722
  *
723
- * 2. **使用场景**
724
- * - 设置服务端渲染生成的 HTML 内容
725
- * - 支持动态基础路径配置
726
- * - 自动处理静态资源的引用路径
723
+ * 2. **Use Cases**
724
+ * - Set HTML content generated by server-side rendering
725
+ * - Support dynamic base path configuration
726
+ * - Automatically handle static asset reference paths
727
727
  *
728
728
  * @example
729
729
  * ```ts
730
- * // 1. 基础用法
730
+ * // 1. Basic usage
731
731
  * export default async (rc: RenderContext) => {
732
- * // 设置 HTML 内容
732
+ * // Set HTML content
733
733
  * rc.html = `
734
734
  * <!DOCTYPE html>
735
735
  * <html>
@@ -747,15 +747,15 @@ export declare class RenderContext {
747
747
  * `;
748
748
  * };
749
749
  *
750
- * // 2. 动态基础路径
750
+ * // 2. Dynamic base path
751
751
  * const rc = await esmx.render({
752
- * base: '/app', // 设置基础路径
752
+ * base: '/app', // Set base path
753
753
  * params: { url: req.url }
754
754
  * });
755
755
  *
756
- * // HTML 中的占位符会被自动替换:
757
- * // [[[___GEZ_DYNAMIC_BASE___]]]/your-app-name/css/style.css
758
- * // 替换为:
756
+ * // Placeholders in HTML will be automatically replaced:
757
+ * // [[[___ESMX_DYNAMIC_BASE___]]]/your-app-name/css/style.css
758
+ * // Replaced with:
759
759
  * // /app/your-app-name/css/style.css
760
760
  * ```
761
761
  */
@@ -763,23 +763,23 @@ export declare class RenderContext {
763
763
  set html(html: string);
764
764
  constructor(esmx: Esmx, options?: RenderContextOptions);
765
765
  /**
766
- * JavaScript 对象序列化为字符串
766
+ * Serialize JavaScript object to string
767
767
  * @description
768
- * serialize 方法用于在服务端渲染过程中将状态数据序列化,以便传递到客户端:
768
+ * The serialize method is used to serialize state data during the server-side rendering process for passing to the client:
769
769
  *
770
- * 1. **主要用途**
771
- * - 序列化服务端状态数据
772
- * - 确保数据可以安全地嵌入到 HTML
773
- * - 支持复杂的数据结构(如 DateRegExp 等)
770
+ * 1. **Main Uses**
771
+ * - Serialize server-side state data
772
+ * - Ensure data can be safely embedded in HTML
773
+ * - Support complex data structures (such as Date, RegExp, etc.)
774
774
  *
775
- * 2. **安全处理**
776
- * - 自动转义特殊字符
777
- * - 防止 XSS 攻击
778
- * - 保持数据类型的完整性
775
+ * 2. **Security Handling**
776
+ * - Automatically escape special characters
777
+ * - Prevent XSS attacks
778
+ * - Maintain data type integrity
779
779
  *
780
780
  * @example
781
781
  * ```ts
782
- * // 1. 基础用法 - 序列化状态数据
782
+ * // 1. Basic usage - Serialize state data
783
783
  * export default async (rc: RenderContext) => {
784
784
  * const state = {
785
785
  * user: { id: 1, name: 'Alice' },
@@ -792,7 +792,7 @@ export declare class RenderContext {
792
792
  * <html>
793
793
  * <head>
794
794
  * <script>
795
- * // 将序列化后的状态注入到全局变量
795
+ * // Inject serialized state into global variable
796
796
  * window.__INITIAL_STATE__ = ${rc.serialize(state)};
797
797
  * </script>
798
798
  * </head>
@@ -801,41 +801,41 @@ export declare class RenderContext {
801
801
  * `;
802
802
  * };
803
803
  *
804
- * // 2. 自定义序列化选项
804
+ * // 2. Custom serialization options
805
805
  * const state = { sensitive: 'data' };
806
806
  * const serialized = rc.serialize(state, {
807
- * isJSON: true, // 使用 JSON 兼容模式
808
- * unsafe: false // 禁用不安全的序列化
807
+ * isJSON: true, // Use JSON compatible mode
808
+ * unsafe: false // Disable unsafe serialization
809
809
  * });
810
810
  * ```
811
811
  *
812
- * @param {any} input - 要序列化的输入数据
813
- * @param {serialize.SerializeJSOptions} [options] - 序列化选项
814
- * @returns {string} 序列化后的字符串
812
+ * @param {any} input - Input data to be serialized
813
+ * @param {serialize.SerializeJSOptions} [options] - Serialization options
814
+ * @returns {string} Serialized string
815
815
  */
816
816
  serialize(input: any, options?: serialize.SerializeJSOptions): string;
817
817
  /**
818
- * 将状态数据序列化并注入到 HTML
818
+ * Serialize state data and inject it into HTML
819
819
  * @description
820
- * state 方法用于在服务端渲染时将状态数据序列化并注入到 HTML 中,以便客户端可以在激活时恢复这些状态:
820
+ * The state method is used to serialize state data and inject it into HTML during server-side rendering, so that the client can restore these states when activating:
821
821
  *
822
- * 1. **序列化机制**
823
- * - 使用安全的序列化方法处理数据
824
- * - 支持复杂的数据结构(对象、数组等)
825
- * - 自动处理特殊字符和 XSS 防护
822
+ * 1. **Serialization Mechanism**
823
+ * - Use safe serialization methods to process data
824
+ * - Support complex data structures (objects, arrays, etc.)
825
+ * - Automatically handle special characters and XSS protection
826
826
  *
827
- * 2. **使用场景**
828
- * - 服务端状态同步到客户端
829
- * - 初始化客户端应用状态
830
- * - 实现无缝的服务端渲染到客户端激活
827
+ * 2. **Use Cases**
828
+ * - Synchronize server-side state to client
829
+ * - Initialize client application state
830
+ * - Implement seamless server-side rendering to client activation
831
831
  *
832
- * @param varName 全局变量名,用于在客户端访问注入的数据
833
- * @param data 需要序列化的数据对象
834
- * @returns 包含序列化数据的 script 标签字符串
832
+ * @param varName Global variable name, used to access injected data on the client
833
+ * @param data Data object that needs to be serialized
834
+ * @returns Script tag string containing serialized data
835
835
  *
836
836
  * @example
837
837
  * ```ts
838
- * // 1. 基础用法 - 注入用户信息
838
+ * // 1. Basic usage - Inject user information
839
839
  * export default async (rc: RenderContext) => {
840
840
  * const userInfo = {
841
841
  * id: 1,
@@ -856,12 +856,12 @@ export declare class RenderContext {
856
856
  * `;
857
857
  * };
858
858
  *
859
- * // 2. 客户端使用
860
- * // 在客户端可以直接访问注入的数据
859
+ * // 2. Client-side usage
860
+ * // Can directly access injected data on the client
861
861
  * const userInfo = window.__USER__;
862
- * console.log(userInfo.name); // 输出: 'John'
862
+ * console.log(userInfo.name); // Output: 'John'
863
863
  *
864
- * // 3. 复杂数据结构
864
+ * // 3. Complex data structures
865
865
  * export default async (rc: RenderContext) => {
866
866
  * const appState = {
867
867
  * user: {
@@ -893,42 +893,42 @@ export declare class RenderContext {
893
893
  */
894
894
  state(varName: string, data: Record<string, any>): string;
895
895
  /**
896
- * 提交依赖收集并更新资源列表
896
+ * Commit dependency collection and update resource list
897
897
  * @description
898
- * commit 方法是 RenderContext 依赖收集机制的核心,负责处理所有收集到的模块依赖并更新文件资源列表:
899
- *
900
- * 1. **依赖处理流程**
901
- * - importMetaSet 中收集所有使用到的模块
902
- * - 基于 manifest 文件解析每个模块的具体资源
903
- * - 处理 JSCSS、资源文件等不同类型的依赖
904
- * - 自动处理模块预加载和导入映射
905
- *
906
- * 2. **资源分类**
907
- * - js: JavaScript 文件,包含所有脚本和模块
908
- * - css: 样式表文件
909
- * - modulepreload: 需要预加载的 ESM 模块
910
- * - importmap: 导入映射文件
911
- * - resources: 其他资源文件(图片、字体等)
912
- *
913
- * 3. **路径处理**
914
- * - 自动添加基础路径前缀
915
- * - 确保资源路径的正确性
916
- * - 支持多应用场景的资源隔离
898
+ * The commit method is the core of RenderContext's dependency collection mechanism, responsible for handling all collected module dependencies and updating the file resource list:
899
+ *
900
+ * 1. **Dependency Processing Flow**
901
+ * - Collect all used modules from importMetaSet
902
+ * - Parse specific resources for each module based on manifest files
903
+ * - Handle different types of dependencies such as JS, CSS, resource files, etc.
904
+ * - Automatically handle module preloading and import maps
905
+ *
906
+ * 2. **Resource Classification**
907
+ * - js: JavaScript files, containing all scripts and modules
908
+ * - css: Stylesheet files
909
+ * - modulepreload: ESM modules that need to be preloaded
910
+ * - importmap: Import map files
911
+ * - resources: Other resource files (images, fonts, etc.)
912
+ *
913
+ * 3. **Path Processing**
914
+ * - Automatically add base path prefix
915
+ * - Ensure the correctness of resource paths
916
+ * - Support resource isolation for multi-application scenarios
917
917
  *
918
918
  * @example
919
919
  * ```ts
920
- * // 1. 基础用法
920
+ * // 1. Basic usage
921
921
  * export default async (rc: RenderContext) => {
922
- * // 渲染页面并收集依赖
922
+ * // Render page and collect dependencies
923
923
  * const app = createApp();
924
924
  * const html = await renderToString(app, {
925
925
  * importMetaSet: rc.importMetaSet
926
926
  * });
927
927
  *
928
- * // 提交依赖收集
928
+ * // Commit dependency collection
929
929
  * await rc.commit();
930
930
  *
931
- * // 生成 HTML
931
+ * // Generate HTML
932
932
  * rc.html = `
933
933
  * <!DOCTYPE html>
934
934
  * <html>
@@ -946,53 +946,53 @@ export declare class RenderContext {
946
946
  * `;
947
947
  * };
948
948
  *
949
- * // 2. 多应用场景
949
+ * // 2. Multi-application scenario
950
950
  * const rc = await esmx.render({
951
- * base: '/app1', // 设置基础路径
951
+ * base: '/app1', // Set base path
952
952
  * params: { appId: 1 }
953
953
  * });
954
954
  *
955
- * // 渲染并提交依赖
955
+ * // Render and commit dependencies
956
956
  * const html = await renderApp(rc);
957
957
  * await rc.commit();
958
958
  *
959
- * // 资源路径会自动添加基础路径前缀
960
- * // 例如:/app1/your-app-name/js/main.js
959
+ * // Resource paths will automatically add base path prefix
960
+ * // For example: /app1/your-app-name/js/main.js
961
961
  * ```
962
962
  */
963
963
  commit(): Promise<void>;
964
964
  /**
965
- * 生成资源预加载标签
965
+ * Generate resource preload tags
966
966
  * @description
967
- * preload() 方法用于生成资源预加载标签,通过提前加载关键资源来优化页面性能:
967
+ * The preload() method is used to generate resource preload tags, optimizing page performance by loading critical resources in advance:
968
968
  *
969
- * 1. **资源类型**
970
- * - CSS 文件:使用 `as="style"` 预加载样式表
971
- * - JS 文件:使用 `as="script"` 预加载导入映射脚本
969
+ * 1. **Resource Types**
970
+ * - CSS files: Use `as="style"` to preload stylesheets
971
+ * - JS files: Use `as="script"` to preload import map scripts
972
972
  *
973
- * 2. **性能优化**
974
- * - 提前发现并加载关键资源
975
- * - HTML 解析并行加载
976
- * - 优化资源加载顺序
977
- * - 减少页面渲染阻塞
973
+ * 2. **Performance Optimization**
974
+ * - Discover and load critical resources in advance
975
+ * - Load in parallel with HTML parsing
976
+ * - Optimize resource loading order
977
+ * - Reduce page rendering blocking
978
978
  *
979
- * 3. **最佳实践**
980
- * - head 中尽早使用
981
- * - 只预加载当前页面必需的资源
982
- * - 与其他资源加载方法配合使用
979
+ * 3. **Best Practices**
980
+ * - Use as early as possible in the head
981
+ * - Only preload resources necessary for the current page
982
+ * - Use in conjunction with other resource loading methods
983
983
  *
984
- * @returns 返回包含所有预加载标签的 HTML 字符串
984
+ * @returns Returns HTML string containing all preload tags
985
985
  *
986
986
  * @example
987
987
  * ```ts
988
- * // HTML head 中使用
988
+ * // Use in HTML head
989
989
  * rc.html = `
990
990
  * <!DOCTYPE html>
991
991
  * <html>
992
992
  * <head>
993
- * <!-- 预加载关键资源 -->
993
+ * <!-- Preload critical resources -->
994
994
  * ${rc.preload()}
995
- * <!-- 注入样式表 -->
995
+ * <!-- Inject stylesheets -->
996
996
  * ${rc.css()}
997
997
  * </head>
998
998
  * <body>
@@ -1007,34 +1007,34 @@ export declare class RenderContext {
1007
1007
  */
1008
1008
  preload(): string;
1009
1009
  /**
1010
- * 注入首屏样式表
1010
+ * Inject first-screen stylesheets
1011
1011
  * @description
1012
- * css() 方法用于注入页面所需的样式表资源:
1012
+ * The css() method is used to inject stylesheet resources required by the page:
1013
1013
  *
1014
- * 1. **注入位置**
1015
- * - 必须在 head 标签中注入
1016
- * - 避免页面闪烁(FOUC)和重排
1017
- * - 确保样式在内容渲染时就位
1014
+ * 1. **Injection Position**
1015
+ * - Must be injected in the head tag
1016
+ * - Avoid page flickering (FOUC) and reflow
1017
+ * - Ensure styles are in place when content is rendered
1018
1018
  *
1019
- * 2. **性能优化**
1020
- * - 支持关键 CSS 提取
1021
- * - 自动处理样式依赖关系
1022
- * - 利用浏览器并行加载能力
1019
+ * 2. **Performance Optimization**
1020
+ * - Support critical CSS extraction
1021
+ * - Automatically handle style dependency relationships
1022
+ * - Utilize browser parallel loading capabilities
1023
1023
  *
1024
- * 3. **使用场景**
1025
- * - 注入首屏必需的样式
1026
- * - 处理组件级别的样式
1027
- * - 支持主题切换和动态样式
1024
+ * 3. **Use Cases**
1025
+ * - Inject styles necessary for the first screen
1026
+ * - Handle component-level styles
1027
+ * - Support theme switching and dynamic styles
1028
1028
  *
1029
1029
  * @example
1030
1030
  * ```ts
1031
- * // 1. 基础用法
1031
+ * // 1. Basic usage
1032
1032
  * rc.html = `
1033
1033
  * <!DOCTYPE html>
1034
1034
  * <html>
1035
1035
  * <head>
1036
- * ${rc.preload()} <!-- 预加载资源 -->
1037
- * ${rc.css()} <!-- 注入样式表 -->
1036
+ * ${rc.preload()} <!-- Preload resources -->
1037
+ * ${rc.css()} <!-- Inject stylesheets -->
1038
1038
  * </head>
1039
1039
  * <body>
1040
1040
  * <div id="app">Hello World</div>
@@ -1042,13 +1042,13 @@ export declare class RenderContext {
1042
1042
  * </html>
1043
1043
  * `;
1044
1044
  *
1045
- * // 2. 与其他资源配合使用
1045
+ * // 2. Use in conjunction with other resources
1046
1046
  * rc.html = `
1047
1047
  * <!DOCTYPE html>
1048
1048
  * <html>
1049
1049
  * <head>
1050
- * ${rc.preload()} <!-- 预加载资源 -->
1051
- * ${rc.css()} <!-- 注入样式表 -->
1050
+ * ${rc.preload()} <!-- Preload resources -->
1051
+ * ${rc.css()} <!-- Inject stylesheets -->
1052
1052
  * </head>
1053
1053
  * <body>
1054
1054
  * ${html}
@@ -1062,35 +1062,35 @@ export declare class RenderContext {
1062
1062
  */
1063
1063
  css(): string;
1064
1064
  /**
1065
- * 注入模块导入映射
1065
+ * Inject module import map
1066
1066
  * @description
1067
- * importmap() 方法用于注入 ESM 模块的路径解析规则:
1068
- *
1069
- * 1. **注入位置**
1070
- * - 必须在 body 中注入
1071
- * - 必须在 moduleEntry 之前执行
1072
- * - 避免阻塞页面首次渲染
1073
- *
1074
- * 2. **导入映射模式**
1075
- * - 内联模式(inline):
1076
- * - 将映射内容直接内联到 HTML
1077
- * - 适合映射内容较小的场景
1078
- * - 减少 HTTP 请求数量
1079
- * - JS 文件模式(js):
1080
- * - 生成独立的 JS 文件
1081
- * - 适合映射内容较大的场景
1082
- * - 可以利用浏览器缓存机制
1083
- *
1084
- * 3. **技术原因**
1085
- * - 定义了 ESM 模块的路径解析规则
1086
- * - 客户端入口模块和其依赖都需要使用这些映射
1087
- * - 确保在执行模块代码前已正确设置映射
1067
+ * The importmap() method is used to inject path resolution rules for ESM modules:
1068
+ *
1069
+ * 1. **Injection Position**
1070
+ * - Must be injected in the body
1071
+ * - Must be executed before moduleEntry
1072
+ * - Avoid blocking the first page render
1073
+ *
1074
+ * 2. **Import Map Modes**
1075
+ * - Inline mode (inline):
1076
+ * - Inline map content directly into HTML
1077
+ * - Suitable for scenarios with smaller map content
1078
+ * - Reduce the number of HTTP requests
1079
+ * - JS file mode (js):
1080
+ * - Generate independent JS files
1081
+ * - Suitable for scenarios with larger map content
1082
+ * - Can utilize browser caching mechanisms
1083
+ *
1084
+ * 3. **Technical Reasons**
1085
+ * - Define path resolution rules for ESM modules
1086
+ * - Client entry modules and their dependencies need to use these maps
1087
+ * - Ensure the map is correctly set before executing module code
1088
1088
  *
1089
1089
  * @example
1090
1090
  * ```ts
1091
- * // 1. 基础用法 - 内联模式
1091
+ * // 1. Basic usage - Inline mode
1092
1092
  * const rc = await esmx.render({
1093
- * importmapMode: 'inline' // 默认模式
1093
+ * importmapMode: 'inline' // Default mode
1094
1094
  * });
1095
1095
  *
1096
1096
  * rc.html = `
@@ -1102,42 +1102,42 @@ export declare class RenderContext {
1102
1102
  * </head>
1103
1103
  * <body>
1104
1104
  * ${html}
1105
- * ${rc.importmap()} <!-- 注入导入映射 -->
1106
- * ${rc.moduleEntry()} <!-- 在导入映射之后执行 -->
1105
+ * ${rc.importmap()} <!-- Inject import map -->
1106
+ * ${rc.moduleEntry()} <!-- Execute after import map -->
1107
1107
  * ${rc.modulePreload()}
1108
1108
  * </body>
1109
1109
  * </html>
1110
1110
  * `;
1111
1111
  *
1112
- * // 2. JS 文件模式 - 适合大型应用
1112
+ * // 2. JS file mode - Suitable for large applications
1113
1113
  * const rc = await esmx.render({
1114
- * importmapMode: 'js' // 使用 JS 文件模式
1114
+ * importmapMode: 'js' // Use JS file mode
1115
1115
  * });
1116
1116
  * ```
1117
1117
  */
1118
1118
  importmap(): string;
1119
1119
  /**
1120
- * 注入客户端入口模块
1120
+ * Inject client entry module
1121
1121
  * @description
1122
- * moduleEntry() 方法用于注入客户端的入口模块:
1123
- * 1. **注入位置**
1124
- * - 必须在 importmap 之后执行
1125
- * - 确保在执行模块代码前已正确设置导入映射
1126
- * - 控制客户端激活(Hydration)的开始时机
1127
- *
1128
- * 2. **技术原因**
1129
- * - 作为客户端代码的入口点
1130
- * - 需要等待基础设施(如导入映射)就绪
1131
- * - 确保正确的模块路径解析
1132
- *
1133
- * 3. **使用场景**
1134
- * - 启动客户端应用
1135
- * - 执行客户端激活
1136
- * - 初始化客户端状态
1122
+ * The moduleEntry() method is used to inject the client's entry module:
1123
+ * 1. **Injection Position**
1124
+ * - Must be executed after importmap
1125
+ * - Ensure the import map is correctly set before executing module code
1126
+ * - Control the start timing of client activation (Hydration)
1127
+ *
1128
+ * 2. **Technical Reasons**
1129
+ * - Serve as the entry point for client code
1130
+ * - Need to wait for infrastructure (such as import maps) to be ready
1131
+ * - Ensure correct module path resolution
1132
+ *
1133
+ * 3. **Use Cases**
1134
+ * - Start the client application
1135
+ * - Execute client activation
1136
+ * - Initialize client state
1137
1137
  *
1138
1138
  * @example
1139
1139
  * ```ts
1140
- * // 1. 基础用法
1140
+ * // 1. Basic usage
1141
1141
  * rc.html = `
1142
1142
  * <!DOCTYPE html>
1143
1143
  * <html>
@@ -1147,44 +1147,44 @@ export declare class RenderContext {
1147
1147
  * </head>
1148
1148
  * <body>
1149
1149
  * ${html}
1150
- * ${rc.importmap()} <!-- 先注入导入映射 -->
1151
- * ${rc.moduleEntry()} <!-- 再注入入口模块 -->
1150
+ * ${rc.importmap()} <!-- Inject import map first -->
1151
+ * ${rc.moduleEntry()} <!-- Then inject entry module -->
1152
1152
  * ${rc.modulePreload()}
1153
1153
  * </body>
1154
1154
  * </html>
1155
1155
  * `;
1156
1156
  *
1157
- * // 2. 多入口配置
1157
+ * // 2. Multiple entry configuration
1158
1158
  * const rc = await esmx.render({
1159
- * entryName: 'mobile', // 指定入口名称
1159
+ * entryName: 'mobile', // Specify entry name
1160
1160
  * params: { device: 'mobile' }
1161
1161
  * });
1162
1162
  * ```
1163
1163
  */
1164
1164
  moduleEntry(): string;
1165
1165
  /**
1166
- * 预加载模块依赖
1166
+ * Preload module dependencies
1167
1167
  * @description
1168
- * modulePreload() 方法用于预加载后续可能用到的模块:
1168
+ * The modulePreload() method is used to preload modules that may be needed later:
1169
1169
  *
1170
- * 1. **注入位置**
1171
- * - 必须在 importmap moduleEntry 之后
1172
- * - 确保使用正确的模块路径映射
1173
- * - 避免与首屏渲染竞争资源
1170
+ * 1. **Injection Position**
1171
+ * - Must be after importmap and moduleEntry
1172
+ * - Ensure the correct module path mapping is used
1173
+ * - Avoid competing with first-screen rendering for resources
1174
1174
  *
1175
- * 2. **性能优化**
1176
- * - 预加载后续可能用到的模块
1177
- * - 提升运行时性能
1178
- * - 优化按需加载体验
1175
+ * 2. **Performance Optimization**
1176
+ * - Preload modules that may be needed later
1177
+ * - Improve runtime performance
1178
+ * - Optimize on-demand loading experience
1179
1179
  *
1180
- * 3. **技术原因**
1181
- * - 需要正确的路径解析规则
1182
- * - 避免重复加载
1183
- * - 控制加载优先级
1180
+ * 3. **Technical Reasons**
1181
+ * - Need correct path resolution rules
1182
+ * - Avoid duplicate loading
1183
+ * - Control loading priority
1184
1184
  *
1185
1185
  * @example
1186
1186
  * ```ts
1187
- * // 1. 基础用法
1187
+ * // 1. Basic usage
1188
1188
  * rc.html = `
1189
1189
  * <!DOCTYPE html>
1190
1190
  * <html>
@@ -1196,16 +1196,16 @@ export declare class RenderContext {
1196
1196
  * ${html}
1197
1197
  * ${rc.importmap()}
1198
1198
  * ${rc.moduleEntry()}
1199
- * ${rc.modulePreload()} <!-- 预加载模块依赖 -->
1199
+ * ${rc.modulePreload()} <!-- Preload module dependencies -->
1200
1200
  * </body>
1201
1201
  * </html>
1202
1202
  * `;
1203
1203
  *
1204
- * // 2. 与异步组件配合使用
1204
+ * // 2. Use with async components
1205
1205
  * const AsyncComponent = defineAsyncComponent(() =>
1206
1206
  * import('./components/AsyncComponent.vue')
1207
1207
  * );
1208
- * // modulePreload 会自动收集并预加载异步组件的依赖
1208
+ * // modulePreload will automatically collect and preload dependencies of async components
1209
1209
  * ```
1210
1210
  */
1211
1211
  modulePreload(): string;