@djvlc/runtime-web 1.0.4 → 1.0.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/dist/index.d.ts +1325 -77
- package/dist/runtime.esm.js +1 -1
- package/dist/runtime.iife.js +1 -1
- package/package.json +2 -2
- package/dist/error-reporter.d.ts +0 -76
- package/dist/error-reporter.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/mount.d.ts +0 -114
- package/dist/mount.d.ts.map +0 -1
- package/dist/performance.d.ts +0 -88
- package/dist/performance.d.ts.map +0 -1
- package/dist/storage.d.ts +0 -33
- package/dist/storage.d.ts.map +0 -1
- package/dist/tracking.d.ts +0 -87
- package/dist/tracking.d.ts.map +0 -1
- package/dist/utils.d.ts +0 -66
- package/dist/utils.d.ts.map +0 -1
- package/dist/version.d.ts +0 -5
- package/dist/version.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,77 +1,1325 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
* @djvlc/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
1
|
+
import { ActionResult } from '@djvlc/contracts-types';
|
|
2
|
+
import { ActionSheetOptions } from '@djvlc/contracts-types';
|
|
3
|
+
import { ActionSheetResult } from '@djvlc/contracts-types';
|
|
4
|
+
import { ClipboardApi } from '@djvlc/contracts-types';
|
|
5
|
+
import { ComponentContext } from '@djvlc/contracts-types';
|
|
6
|
+
import { ConfirmOptions } from '@djvlc/contracts-types';
|
|
7
|
+
import { DialogOptions } from '@djvlc/contracts-types';
|
|
8
|
+
import { DialogResult } from '@djvlc/contracts-types';
|
|
9
|
+
import * as _djvlc_contracts_types from '@djvlc/contracts-types';
|
|
10
|
+
import { Expression } from '@djvlc/contracts-types';
|
|
11
|
+
import { ExpressionContext } from '@djvlc/contracts-types';
|
|
12
|
+
import { ExpressionValidationResult } from '@djvlc/contracts-types';
|
|
13
|
+
import { HostApi } from '@djvlc/contracts-types';
|
|
14
|
+
import { NavigateOptions } from '@djvlc/contracts-types';
|
|
15
|
+
import { PreviewImageOptions } from '@djvlc/contracts-types';
|
|
16
|
+
import { ScanCodeResult } from '@djvlc/contracts-types';
|
|
17
|
+
import { ShareOptions } from '@djvlc/contracts-types';
|
|
18
|
+
import { ShareResult } from '@djvlc/contracts-types';
|
|
19
|
+
import { StorageApi } from '@djvlc/contracts-types';
|
|
20
|
+
import { ToastOptions } from '@djvlc/contracts-types';
|
|
21
|
+
import { TrackEvent as TrackEvent_3 } from '@djvlc/contracts-types';
|
|
22
|
+
|
|
23
|
+
declare interface ArrayASTNode extends BaseASTNode {
|
|
24
|
+
type: 'array';
|
|
25
|
+
elements: ASTNode[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare type ASTNode = LiteralASTNode | IdentifierASTNode | MemberASTNode | CallASTNode | BinaryASTNode | UnaryASTNode | ConditionalASTNode | ArrayASTNode;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 表达式解析器
|
|
32
|
+
* 将 Token 列表解析为 AST
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* AST 基础节点接口
|
|
37
|
+
*/
|
|
38
|
+
declare interface BaseASTNode {
|
|
39
|
+
type: string;
|
|
40
|
+
/** 起始位置(可选,用于错误定位) */
|
|
41
|
+
start?: number;
|
|
42
|
+
/** 结束位置(可选,用于错误定位) */
|
|
43
|
+
end?: number;
|
|
44
|
+
/** 原始字符串(可选,用于调试) */
|
|
45
|
+
raw?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 批量挂载
|
|
50
|
+
*/
|
|
51
|
+
export declare function batchMount(mounts: Array<{
|
|
52
|
+
id: string;
|
|
53
|
+
container: string | HTMLElement;
|
|
54
|
+
options: MountOptions;
|
|
55
|
+
}>, options?: {
|
|
56
|
+
concurrency?: number;
|
|
57
|
+
continueOnError?: boolean;
|
|
58
|
+
}): Promise<BatchMountResult>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 批量挂载结果
|
|
62
|
+
*/
|
|
63
|
+
export declare interface BatchMountResult {
|
|
64
|
+
/** 成功的挂载结果 */
|
|
65
|
+
results: Map<string, MountResult>;
|
|
66
|
+
/** 失败的错误 */
|
|
67
|
+
errors: Map<string, Error>;
|
|
68
|
+
/** 总耗时 */
|
|
69
|
+
totalTime: number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare interface BinaryASTNode extends BaseASTNode {
|
|
73
|
+
type: 'binary';
|
|
74
|
+
operator: string;
|
|
75
|
+
left: ASTNode;
|
|
76
|
+
right: ASTNode;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare interface CallASTNode extends BaseASTNode {
|
|
80
|
+
type: 'call';
|
|
81
|
+
callee: string;
|
|
82
|
+
arguments: ASTNode[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 采集 Web Vitals 指标
|
|
87
|
+
*/
|
|
88
|
+
export declare function collectWebVitalsMetrics(metrics: PerformanceMetrics): void;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 组件加载结果
|
|
92
|
+
*/
|
|
93
|
+
declare interface ComponentLoadResult {
|
|
94
|
+
/** 组件名称 */
|
|
95
|
+
name: string;
|
|
96
|
+
/** 组件版本 */
|
|
97
|
+
version: string;
|
|
98
|
+
/** 加载状态 */
|
|
99
|
+
status: ComponentLoadStatus;
|
|
100
|
+
/** 组件构造函数(加载成功时) */
|
|
101
|
+
component?: CustomElementConstructor | unknown;
|
|
102
|
+
/** 加载耗时(毫秒) */
|
|
103
|
+
loadTime?: number;
|
|
104
|
+
/** 错误信息(加载失败时) */
|
|
105
|
+
error?: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 组件加载状态
|
|
110
|
+
*/
|
|
111
|
+
declare type ComponentLoadStatus = 'loading' | 'loaded' | 'failed' | 'blocked';
|
|
112
|
+
|
|
113
|
+
declare interface ConditionalASTNode extends BaseASTNode {
|
|
114
|
+
type: 'conditional';
|
|
115
|
+
test: ASTNode;
|
|
116
|
+
consequent: ASTNode;
|
|
117
|
+
alternate: ASTNode;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 创建错误报告器
|
|
122
|
+
*/
|
|
123
|
+
export declare function createErrorReporter(config?: ErrorReporterConfig): ErrorReporter;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 创建性能监控器
|
|
127
|
+
*/
|
|
128
|
+
export declare function createPerformanceMonitor(enabled?: boolean): PerformanceMonitor;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 创建运行时实例
|
|
132
|
+
*/
|
|
133
|
+
export declare function createRuntime(options: RuntimeOptions): DjvlcRuntime;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 创建存储辅助类
|
|
137
|
+
*/
|
|
138
|
+
export declare function createStorageHelper(namespace?: string, useSession?: boolean): StorageHelper;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 创建埋点管理器
|
|
142
|
+
*/
|
|
143
|
+
export declare function createTrackingManager(config?: TrackingConfig): TrackingManager;
|
|
144
|
+
|
|
145
|
+
declare const _default: {
|
|
146
|
+
RUNTIME_VERSION: string;
|
|
147
|
+
mount: typeof mount;
|
|
148
|
+
lazyMount: typeof lazyMount;
|
|
149
|
+
batchMount: typeof batchMount;
|
|
150
|
+
warmup: typeof warmup;
|
|
151
|
+
createTrackingManager: typeof createTrackingManager;
|
|
152
|
+
createErrorReporter: typeof createErrorReporter;
|
|
153
|
+
createPerformanceMonitor: typeof createPerformanceMonitor;
|
|
154
|
+
getPagePerformance: typeof getPagePerformance;
|
|
155
|
+
getResourcePerformance: typeof getResourcePerformance;
|
|
156
|
+
getRuntimeResourcePerformance: typeof getRuntimeResourcePerformance;
|
|
157
|
+
createStorageHelper: typeof createStorageHelper;
|
|
158
|
+
preconnect: typeof preconnect;
|
|
159
|
+
preloadAssets: typeof preloadAssets;
|
|
160
|
+
getDeviceId: typeof getDeviceId;
|
|
161
|
+
generateTraceId: typeof generateTraceId;
|
|
162
|
+
generateSpanId: typeof generateSpanId;
|
|
163
|
+
generateTraceparent: typeof generateTraceparent;
|
|
164
|
+
urlUtils: {
|
|
165
|
+
getParam(name: string, url?: string): string | null;
|
|
166
|
+
setParam(name: string, value: string): void;
|
|
167
|
+
removeParam(name: string): void;
|
|
168
|
+
build(base: string, params: Record<string, string | number | boolean | undefined>): string;
|
|
169
|
+
};
|
|
170
|
+
onVisibilityChange: typeof onVisibilityChange;
|
|
171
|
+
onNetworkChange: typeof onNetworkChange;
|
|
172
|
+
isMobile: typeof isMobile;
|
|
173
|
+
isWeChat: typeof isWeChat;
|
|
174
|
+
supportsWebP: typeof supportsWebP;
|
|
175
|
+
createRuntime: typeof createRuntime;
|
|
176
|
+
};
|
|
177
|
+
export default _default;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* DJVLC 运行时
|
|
181
|
+
*
|
|
182
|
+
* 核心职责:
|
|
183
|
+
* 1. resolve & load:拿到 pageVersion 与 manifest,按 componentVersion 拉资源
|
|
184
|
+
* 2. render:把 schema 变成 UI(基于 Web Components)
|
|
185
|
+
* 3. boundary:组件只能通过 hostApi 触发 data/action/navigate/track
|
|
186
|
+
*/
|
|
187
|
+
declare class DjvlcRuntime {
|
|
188
|
+
private options;
|
|
189
|
+
private container;
|
|
190
|
+
private pageLoader;
|
|
191
|
+
private componentLoader;
|
|
192
|
+
private assetLoader;
|
|
193
|
+
private stateManager;
|
|
194
|
+
private dataBindingManager;
|
|
195
|
+
private eventBus;
|
|
196
|
+
private actionBridge;
|
|
197
|
+
private expressionEngine;
|
|
198
|
+
private securityManager;
|
|
199
|
+
private telemetryManager;
|
|
200
|
+
private renderer;
|
|
201
|
+
private hostApi;
|
|
202
|
+
private lifecycleManager;
|
|
203
|
+
private logger;
|
|
204
|
+
constructor(options: RuntimeOptions);
|
|
205
|
+
/**
|
|
206
|
+
* 初始化运行时
|
|
207
|
+
*/
|
|
208
|
+
init(): Promise<void>;
|
|
209
|
+
/**
|
|
210
|
+
* 加载页面
|
|
211
|
+
*/
|
|
212
|
+
load(): Promise<PageResolveResult>;
|
|
213
|
+
/**
|
|
214
|
+
* 渲染页面
|
|
215
|
+
*/
|
|
216
|
+
render(): Promise<void>;
|
|
217
|
+
/**
|
|
218
|
+
* 获取 Host API
|
|
219
|
+
*/
|
|
220
|
+
getHostApi(): HostAPIImpl;
|
|
221
|
+
/**
|
|
222
|
+
* 获取当前状态
|
|
223
|
+
*/
|
|
224
|
+
getState(): RuntimeState;
|
|
225
|
+
/**
|
|
226
|
+
* 订阅状态变更
|
|
227
|
+
*/
|
|
228
|
+
onStateChange(listener: (state: RuntimeState) => void): () => void;
|
|
229
|
+
/**
|
|
230
|
+
* 订阅事件
|
|
231
|
+
*/
|
|
232
|
+
on<T>(type: RuntimeEvent<T>['type'], handler: (event: RuntimeEvent<T>) => void): () => void;
|
|
233
|
+
/**
|
|
234
|
+
* 更新组件
|
|
235
|
+
*/
|
|
236
|
+
updateComponent(componentId: string, props: Record<string, unknown>): void;
|
|
237
|
+
/**
|
|
238
|
+
* 设置变量
|
|
239
|
+
*/
|
|
240
|
+
setVariable(key: string, value: unknown): void;
|
|
241
|
+
/**
|
|
242
|
+
* 获取变量
|
|
243
|
+
*/
|
|
244
|
+
getVariable<T = unknown>(key: string): T | undefined;
|
|
245
|
+
/**
|
|
246
|
+
* 刷新数据
|
|
247
|
+
*/
|
|
248
|
+
refreshData(queryId: string): Promise<void>;
|
|
249
|
+
/**
|
|
250
|
+
* 执行动作
|
|
251
|
+
*/
|
|
252
|
+
executeAction(actionType: string, params?: Record<string, unknown>): Promise<unknown>;
|
|
253
|
+
/**
|
|
254
|
+
* 销毁运行时
|
|
255
|
+
*/
|
|
256
|
+
destroy(): Promise<void>;
|
|
257
|
+
/**
|
|
258
|
+
* 验证 Schema 版本
|
|
259
|
+
*/
|
|
260
|
+
private validateSchemaVersion;
|
|
261
|
+
private resolveContainer;
|
|
262
|
+
private initHostApi;
|
|
263
|
+
private initActionBridge;
|
|
264
|
+
private initDataBindingManager;
|
|
265
|
+
private initLifecycleManager;
|
|
266
|
+
private initRenderer;
|
|
267
|
+
/**
|
|
268
|
+
* 处理组件事件
|
|
269
|
+
*/
|
|
270
|
+
private handleComponentEvent;
|
|
271
|
+
private handleError;
|
|
272
|
+
private emitEvent;
|
|
273
|
+
private createLogger;
|
|
274
|
+
private log;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* 错误报告
|
|
279
|
+
*/
|
|
280
|
+
export declare interface ErrorReport {
|
|
281
|
+
/** 错误消息 */
|
|
282
|
+
message: string;
|
|
283
|
+
/** 错误堆栈 */
|
|
284
|
+
stack?: string;
|
|
285
|
+
/** 错误类型 */
|
|
286
|
+
type: 'error' | 'unhandledrejection' | 'resource' | 'runtime';
|
|
287
|
+
/** 发生时间 */
|
|
288
|
+
timestamp: number;
|
|
289
|
+
/** 页面 URL */
|
|
290
|
+
url: string;
|
|
291
|
+
/** 用户代理 */
|
|
292
|
+
userAgent: string;
|
|
293
|
+
/** 额外上下文 */
|
|
294
|
+
context?: Record<string, unknown>;
|
|
295
|
+
/** 追踪 ID */
|
|
296
|
+
traceId?: string;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* 错误报告器
|
|
301
|
+
*/
|
|
302
|
+
export declare class ErrorReporter {
|
|
303
|
+
private config;
|
|
304
|
+
private traceId;
|
|
305
|
+
private boundHandlers;
|
|
306
|
+
constructor(config?: ErrorReporterConfig);
|
|
307
|
+
/**
|
|
308
|
+
* 开始监听全局错误
|
|
309
|
+
*/
|
|
310
|
+
start(): void;
|
|
311
|
+
/**
|
|
312
|
+
* 停止监听
|
|
313
|
+
*/
|
|
314
|
+
stop(): void;
|
|
315
|
+
/**
|
|
316
|
+
* 手动报告错误
|
|
317
|
+
*/
|
|
318
|
+
report(error: Error, context?: Record<string, unknown>): void;
|
|
319
|
+
/**
|
|
320
|
+
* 设置追踪 ID
|
|
321
|
+
*/
|
|
322
|
+
setTraceId(traceId: string): void;
|
|
323
|
+
private handleError;
|
|
324
|
+
private handleUnhandledRejection;
|
|
325
|
+
private shouldIgnore;
|
|
326
|
+
private truncateStack;
|
|
327
|
+
private defaultReporter;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* 错误报告
|
|
332
|
+
*/
|
|
333
|
+
/**
|
|
334
|
+
* 错误报告配置
|
|
335
|
+
*/
|
|
336
|
+
export declare interface ErrorReporterConfig {
|
|
337
|
+
/** 上报端点 */
|
|
338
|
+
endpoint?: string;
|
|
339
|
+
/** 是否启用 */
|
|
340
|
+
enabled?: boolean;
|
|
341
|
+
/** 采样率 */
|
|
342
|
+
sampleRate?: number;
|
|
343
|
+
/** 忽略的错误模式 */
|
|
344
|
+
ignorePatterns?: RegExp[];
|
|
345
|
+
/** 自定义上报函数 */
|
|
346
|
+
reporter?: (error: ErrorReport) => void | Promise<void>;
|
|
347
|
+
/** 最大堆栈深度 */
|
|
348
|
+
maxStackDepth?: number;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* 表达式求值器
|
|
353
|
+
* 安全地执行 AST,无 eval
|
|
354
|
+
*/
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* 求值结果
|
|
358
|
+
*/
|
|
359
|
+
declare interface EvaluationResult {
|
|
360
|
+
value: unknown;
|
|
361
|
+
error?: Error;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* 求值器配置
|
|
366
|
+
*/
|
|
367
|
+
declare interface EvaluatorOptions {
|
|
368
|
+
/** 最大递归深度 */
|
|
369
|
+
maxDepth?: number;
|
|
370
|
+
/** 最大执行时间(毫秒) */
|
|
371
|
+
timeout?: number;
|
|
372
|
+
/** 调试模式 */
|
|
373
|
+
debug?: boolean;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* 事件总线实现
|
|
378
|
+
*/
|
|
379
|
+
declare class EventBus {
|
|
380
|
+
private handlers;
|
|
381
|
+
private options;
|
|
382
|
+
constructor(options?: EventBusOptions);
|
|
383
|
+
/**
|
|
384
|
+
* 发送事件
|
|
385
|
+
*/
|
|
386
|
+
emit<T>(event: RuntimeEvent<T>): void;
|
|
387
|
+
/**
|
|
388
|
+
* 订阅事件
|
|
389
|
+
*/
|
|
390
|
+
on<T>(type: RuntimeEventType, handler: EventHandlerFn<T>): Unsubscribe;
|
|
391
|
+
/**
|
|
392
|
+
* 取消订阅
|
|
393
|
+
*/
|
|
394
|
+
off<T>(type: RuntimeEventType, handler: EventHandlerFn<T>): void;
|
|
395
|
+
/**
|
|
396
|
+
* 一次性订阅
|
|
397
|
+
*/
|
|
398
|
+
once<T>(type: RuntimeEventType, handler: EventHandlerFn<T>): Unsubscribe;
|
|
399
|
+
/**
|
|
400
|
+
* 清除所有监听器
|
|
401
|
+
*/
|
|
402
|
+
clear(type?: RuntimeEventType): void;
|
|
403
|
+
/**
|
|
404
|
+
* 获取监听器数量
|
|
405
|
+
*/
|
|
406
|
+
listenerCount(type: RuntimeEventType): number;
|
|
407
|
+
/**
|
|
408
|
+
* 创建事件
|
|
409
|
+
*/
|
|
410
|
+
static createEvent<T>(type: RuntimeEventType, data: T, traceId?: string): RuntimeEvent<T>;
|
|
411
|
+
private log;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* 事件总线
|
|
416
|
+
* 运行时事件系统
|
|
417
|
+
*/
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* 事件总线配置
|
|
421
|
+
*/
|
|
422
|
+
declare interface EventBusOptions {
|
|
423
|
+
/** 是否开启调试 */
|
|
424
|
+
debug?: boolean;
|
|
425
|
+
/** 日志器 */
|
|
426
|
+
logger?: Logger;
|
|
427
|
+
/** 最大监听器数量 */
|
|
428
|
+
maxListeners?: number;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* 事件处理器函数
|
|
433
|
+
*/
|
|
434
|
+
declare type EventHandlerFn<T = unknown> = (event: RuntimeEvent<T>) => void;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* 表达式引擎
|
|
438
|
+
* 安全的表达式解析和求值,无 eval/new Function
|
|
439
|
+
*/
|
|
440
|
+
declare class ExpressionEngine {
|
|
441
|
+
private options;
|
|
442
|
+
private evaluator;
|
|
443
|
+
private astCache;
|
|
444
|
+
constructor(options?: ExpressionEngineOptions);
|
|
445
|
+
/**
|
|
446
|
+
* 求值表达式
|
|
447
|
+
*/
|
|
448
|
+
evaluate(expression: string, context: ExpressionContext): EvaluationResult;
|
|
449
|
+
/**
|
|
450
|
+
* 求值表达式并返回值
|
|
451
|
+
* 出错时返回 fallback 值
|
|
452
|
+
*
|
|
453
|
+
* @param expression - 表达式字符串或 Expression 对象
|
|
454
|
+
* @param context - 表达式上下文
|
|
455
|
+
* @param fallback - 求值失败时的默认值
|
|
456
|
+
*/
|
|
457
|
+
evaluateWithFallback<T>(expression: string | Expression, context: ExpressionContext, fallback?: T): T;
|
|
458
|
+
/**
|
|
459
|
+
* 求值模板字符串
|
|
460
|
+
* 支持 ${expression} 语法
|
|
461
|
+
*/
|
|
462
|
+
evaluateTemplate(template: string, context: ExpressionContext): string;
|
|
463
|
+
/**
|
|
464
|
+
* 解析表达式为 AST
|
|
465
|
+
*/
|
|
466
|
+
parse(expression: string): ASTNode;
|
|
467
|
+
/**
|
|
468
|
+
* 校验表达式
|
|
469
|
+
*/
|
|
470
|
+
validate(expression: string): ExpressionValidationResult;
|
|
471
|
+
/**
|
|
472
|
+
* 清除 AST 缓存
|
|
473
|
+
*/
|
|
474
|
+
clearCache(): void;
|
|
475
|
+
private collectReferences;
|
|
476
|
+
private buildMemberPath;
|
|
477
|
+
private log;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* 表达式引擎
|
|
482
|
+
* 统一的表达式解析和求值入口
|
|
483
|
+
*/
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* 表达式引擎配置
|
|
487
|
+
*/
|
|
488
|
+
declare interface ExpressionEngineOptions extends EvaluatorOptions {
|
|
489
|
+
/** 是否缓存 AST */
|
|
490
|
+
cacheAST?: boolean;
|
|
491
|
+
/** 最大缓存大小 */
|
|
492
|
+
maxCacheSize?: number;
|
|
493
|
+
/** 日志器 */
|
|
494
|
+
logger?: Logger;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* 生成 Span ID
|
|
499
|
+
*/
|
|
500
|
+
export declare function generateSpanId(): string;
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* 生成追踪 ID
|
|
504
|
+
*/
|
|
505
|
+
export declare function generateTraceId(): string;
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* 生成 traceparent 头
|
|
509
|
+
*/
|
|
510
|
+
export declare function generateTraceparent(): string;
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* 获取设备 ID
|
|
514
|
+
*/
|
|
515
|
+
export declare function getDeviceId(): string;
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* 获取页面性能指标
|
|
519
|
+
*/
|
|
520
|
+
export declare function getPagePerformance(): Record<string, number>;
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* 获取资源加载性能
|
|
524
|
+
*/
|
|
525
|
+
export declare function getResourcePerformance(filter?: (entry: PerformanceResourceTiming) => boolean): Array<{
|
|
526
|
+
name: string;
|
|
527
|
+
type: string;
|
|
528
|
+
duration: number;
|
|
529
|
+
size: number;
|
|
530
|
+
}>;
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* 获取运行时资源性能
|
|
534
|
+
*/
|
|
535
|
+
export declare function getRuntimeResourcePerformance(): Array<{
|
|
536
|
+
name: string;
|
|
537
|
+
type: string;
|
|
538
|
+
duration: number;
|
|
539
|
+
size: number;
|
|
540
|
+
}>;
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Host API 实现
|
|
544
|
+
* 完全实现 @djvlc/contracts-types 中定义的 HostApi 接口
|
|
545
|
+
*/
|
|
546
|
+
declare class HostAPIImpl implements HostApi {
|
|
547
|
+
private options;
|
|
548
|
+
private storageNamespace;
|
|
549
|
+
private loadingCount;
|
|
550
|
+
private loadingElement;
|
|
551
|
+
constructor(options: HostAPIOptions);
|
|
552
|
+
navigate(options: NavigateOptions): Promise<void>;
|
|
553
|
+
track(event: TrackEvent_3): void;
|
|
554
|
+
requestData<T = unknown>(queryId: string, params?: Record<string, unknown>): Promise<T>;
|
|
555
|
+
executeAction<T = unknown>(actionType: string, params?: Record<string, unknown>): Promise<ActionResult<T>>;
|
|
556
|
+
openDialog(options: DialogOptions): Promise<DialogResult>;
|
|
557
|
+
closeDialog(dialogId?: string): void;
|
|
558
|
+
showToast(options: ToastOptions): void;
|
|
559
|
+
showLoading(message?: string): void;
|
|
560
|
+
hideLoading(): void;
|
|
561
|
+
clipboard: ClipboardApi;
|
|
562
|
+
storage: StorageApi;
|
|
563
|
+
share(options: ShareOptions): Promise<ShareResult>;
|
|
564
|
+
confirm(options: ConfirmOptions): Promise<boolean>;
|
|
565
|
+
showActionSheet(options: ActionSheetOptions): Promise<ActionSheetResult>;
|
|
566
|
+
previewImage(options: PreviewImageOptions): void;
|
|
567
|
+
scanCode(): Promise<ScanCodeResult>;
|
|
568
|
+
getState<T = unknown>(path: string): T | undefined;
|
|
569
|
+
setState(path: string, value: unknown): void;
|
|
570
|
+
getContext(): ComponentContext;
|
|
571
|
+
private buildHeaders;
|
|
572
|
+
private generateIdempotencyKey;
|
|
573
|
+
private simpleHash;
|
|
574
|
+
private fallbackCopy;
|
|
575
|
+
private log;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Host API 配置
|
|
580
|
+
*/
|
|
581
|
+
declare interface HostAPIOptions {
|
|
582
|
+
/** API 基础 URL */
|
|
583
|
+
apiBaseUrl: string;
|
|
584
|
+
/** 认证 Token */
|
|
585
|
+
authToken?: string;
|
|
586
|
+
/** 请求头 */
|
|
587
|
+
headers?: Record<string, string>;
|
|
588
|
+
/** 状态管理器 */
|
|
589
|
+
stateManager: StateManager;
|
|
590
|
+
/** 事件总线 */
|
|
591
|
+
eventBus: EventBus;
|
|
592
|
+
/** 表达式引擎 */
|
|
593
|
+
expressionEngine: ExpressionEngine;
|
|
594
|
+
/** 运行时上下文 */
|
|
595
|
+
context: RuntimeContext;
|
|
596
|
+
/** 调试模式 */
|
|
597
|
+
debug?: boolean;
|
|
598
|
+
/** 日志器 */
|
|
599
|
+
logger?: Logger;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
declare interface IdentifierASTNode extends BaseASTNode {
|
|
603
|
+
type: 'identifier';
|
|
604
|
+
name: string;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* 检测是否为移动端
|
|
609
|
+
*/
|
|
610
|
+
export declare function isMobile(): boolean;
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* 检测是否为微信环境
|
|
614
|
+
*/
|
|
615
|
+
export declare function isWeChat(): boolean;
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* 懒加载挂载
|
|
619
|
+
*/
|
|
620
|
+
export declare function lazyMount(container: string | HTMLElement, options: LazyMountOptions): {
|
|
621
|
+
cancel: () => void;
|
|
622
|
+
promise: Promise<MountResult>;
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* 懒加载选项
|
|
627
|
+
*/
|
|
628
|
+
export declare interface LazyMountOptions extends MountOptions {
|
|
629
|
+
/** 根边距 */
|
|
630
|
+
rootMargin?: string;
|
|
631
|
+
/** 可见阈值 */
|
|
632
|
+
threshold?: number;
|
|
633
|
+
/** 占位元素 */
|
|
634
|
+
placeholder?: HTMLElement | string;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* AST 节点类型
|
|
639
|
+
*/
|
|
640
|
+
declare interface LiteralASTNode extends BaseASTNode {
|
|
641
|
+
type: 'literal';
|
|
642
|
+
value: string | number | boolean | null;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* 已加载的组件模块
|
|
647
|
+
*/
|
|
648
|
+
export declare interface LoadedComponent {
|
|
649
|
+
/** 组件名称 */
|
|
650
|
+
name: string;
|
|
651
|
+
/** 组件版本 */
|
|
652
|
+
version: string;
|
|
653
|
+
/** 组件类/构造函数 */
|
|
654
|
+
Component: CustomElementConstructor | unknown;
|
|
655
|
+
/** 加载耗时 */
|
|
656
|
+
loadTime: number;
|
|
657
|
+
/** 元数据 */
|
|
658
|
+
meta?: _djvlc_contracts_types.ComponentMeta;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* 日志器接口
|
|
663
|
+
*/
|
|
664
|
+
export declare interface Logger {
|
|
665
|
+
debug(message: string, ...args: unknown[]): void;
|
|
666
|
+
info(message: string, ...args: unknown[]): void;
|
|
667
|
+
warn(message: string, ...args: unknown[]): void;
|
|
668
|
+
error(message: string, ...args: unknown[]): void;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
declare interface MemberASTNode extends BaseASTNode {
|
|
672
|
+
type: 'member';
|
|
673
|
+
object: ASTNode;
|
|
674
|
+
property: string | ASTNode;
|
|
675
|
+
computed: boolean;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* 性能指标类型
|
|
680
|
+
*/
|
|
681
|
+
declare type MetricType = 'pageResolveTime' | 'pageLoadTime' | 'componentLoadTime' | 'firstRenderTime' | 'actionExecuteTime' | 'queryFetchTime' | 'expressionEvalTime';
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* 挂载运行时到指定容器
|
|
685
|
+
*/
|
|
686
|
+
export declare function mount(container: string | HTMLElement, options: MountOptions): Promise<MountResult>;
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* 挂载选项
|
|
690
|
+
*/
|
|
691
|
+
export declare interface MountOptions {
|
|
692
|
+
/** 页面 UID */
|
|
693
|
+
pageUid: string;
|
|
694
|
+
/** API 基础 URL */
|
|
695
|
+
apiBaseUrl: string;
|
|
696
|
+
/** CDN 基础 URL */
|
|
697
|
+
cdnBaseUrl: string;
|
|
698
|
+
/** 渠道 */
|
|
699
|
+
channel?: 'preview' | 'prod' | 'gray';
|
|
700
|
+
/** 用户 ID */
|
|
701
|
+
userId?: string;
|
|
702
|
+
/** 设备 ID */
|
|
703
|
+
deviceId?: string;
|
|
704
|
+
/** 认证 Token */
|
|
705
|
+
authToken?: string;
|
|
706
|
+
/** 预览 Token */
|
|
707
|
+
previewToken?: string;
|
|
708
|
+
/** 调试模式 */
|
|
709
|
+
debug?: boolean;
|
|
710
|
+
/** 是否启用 SRI 校验 */
|
|
711
|
+
enableSRI?: boolean;
|
|
712
|
+
/** 自定义请求头 */
|
|
713
|
+
headers?: Record<string, string>;
|
|
714
|
+
/** 加载完成回调 */
|
|
715
|
+
onLoad?: (data: unknown) => void;
|
|
716
|
+
/** 错误回调 */
|
|
717
|
+
onError?: (error: Error) => void;
|
|
718
|
+
/** 性能指标回调 */
|
|
719
|
+
onMetric?: (metric: PerformanceMetrics) => void;
|
|
720
|
+
/** 阶段变化回调 */
|
|
721
|
+
onPhaseChange?: (phase: string) => void;
|
|
722
|
+
/** 重试次数 */
|
|
723
|
+
retryCount?: number;
|
|
724
|
+
/** 重试延迟 */
|
|
725
|
+
retryDelay?: number;
|
|
726
|
+
/** 超时时间 */
|
|
727
|
+
timeout?: number;
|
|
728
|
+
/** 是否采集 Web Vitals */
|
|
729
|
+
collectWebVitals?: boolean;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* 挂载结果
|
|
734
|
+
*/
|
|
735
|
+
export declare interface MountResult {
|
|
736
|
+
/** 运行时实例 */
|
|
737
|
+
runtime: ReturnType<typeof createRuntime>;
|
|
738
|
+
/** 销毁函数 */
|
|
739
|
+
destroy: () => void;
|
|
740
|
+
/** 性能指标 */
|
|
741
|
+
metrics: PerformanceMetrics;
|
|
742
|
+
/** 刷新页面 */
|
|
743
|
+
refresh: () => Promise<void>;
|
|
744
|
+
/** 设置变量 */
|
|
745
|
+
setVariable: (key: string, value: unknown) => void;
|
|
746
|
+
/** 刷新数据 */
|
|
747
|
+
refreshData: (queryId: string) => Promise<void>;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* 网络状态监听
|
|
752
|
+
*/
|
|
753
|
+
export declare function onNetworkChange(callback: (online: boolean) => void): () => void;
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* 可见性监听
|
|
757
|
+
*/
|
|
758
|
+
export declare function onVisibilityChange(callback: (visible: boolean) => void): () => void;
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* 页面解析结果(Runtime 使用)
|
|
762
|
+
*/
|
|
763
|
+
declare interface PageResolveResult {
|
|
764
|
+
/** 页面 UID */
|
|
765
|
+
pageUid: string;
|
|
766
|
+
/** 页面版本 ID */
|
|
767
|
+
pageVersionId: string;
|
|
768
|
+
/** 页面 JSON(PageSchema) */
|
|
769
|
+
pageJson: _djvlc_contracts_types.PageSchema;
|
|
770
|
+
/** 组件清单 */
|
|
771
|
+
manifest: _djvlc_contracts_types.PageManifest;
|
|
772
|
+
/** 运行时配置 */
|
|
773
|
+
runtimeConfig?: {
|
|
774
|
+
/** 被阻断的组件列表 */
|
|
775
|
+
blockedComponents?: Array<{
|
|
776
|
+
name: string;
|
|
777
|
+
version: string;
|
|
778
|
+
reason: string;
|
|
779
|
+
}>;
|
|
780
|
+
/** Kill Switch 状态 */
|
|
781
|
+
killSwitches?: Array<{
|
|
782
|
+
type: string;
|
|
783
|
+
enabled: boolean;
|
|
784
|
+
}>;
|
|
785
|
+
/** 功能开关 */
|
|
786
|
+
features?: Record<string, boolean>;
|
|
787
|
+
};
|
|
788
|
+
/** 是否为预览模式 */
|
|
789
|
+
isPreview?: boolean;
|
|
790
|
+
/** 预加载的数据 */
|
|
791
|
+
preloadedData?: Record<string, unknown>;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* 性能指标
|
|
796
|
+
*/
|
|
797
|
+
declare interface PerformanceMetric {
|
|
798
|
+
/** 指标类型 */
|
|
799
|
+
type: MetricType;
|
|
800
|
+
/** 指标值(毫秒) */
|
|
801
|
+
value: number;
|
|
802
|
+
/** 页面版本 ID */
|
|
803
|
+
pageVersionId?: string;
|
|
804
|
+
/** 组件名称 */
|
|
805
|
+
componentName?: string;
|
|
806
|
+
/** 组件版本 */
|
|
807
|
+
componentVersion?: string;
|
|
808
|
+
/** 动作类型 */
|
|
809
|
+
actionType?: string;
|
|
810
|
+
/** 查询 ID */
|
|
811
|
+
queryId?: string;
|
|
812
|
+
/** 时间戳 */
|
|
813
|
+
timestamp: number;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* 性能监控工具
|
|
818
|
+
*/
|
|
819
|
+
/**
|
|
820
|
+
* 性能指标
|
|
821
|
+
*/
|
|
822
|
+
export declare interface PerformanceMetrics {
|
|
823
|
+
/** 初始化耗时 */
|
|
824
|
+
initTime: number;
|
|
825
|
+
/** 加载耗时 */
|
|
826
|
+
loadTime: number;
|
|
827
|
+
/** 渲染耗时 */
|
|
828
|
+
renderTime: number;
|
|
829
|
+
/** 总耗时 */
|
|
830
|
+
totalTime: number;
|
|
831
|
+
/** 首次内容绘制时间 */
|
|
832
|
+
fcp?: number;
|
|
833
|
+
/** 最大内容绘制时间 */
|
|
834
|
+
lcp?: number;
|
|
835
|
+
/** 首次输入延迟 */
|
|
836
|
+
fid?: number;
|
|
837
|
+
/** 累计布局偏移 */
|
|
838
|
+
cls?: number;
|
|
839
|
+
/** 组件加载次数 */
|
|
840
|
+
componentLoadCount: number;
|
|
841
|
+
/** 组件加载失败次数 */
|
|
842
|
+
componentLoadErrors: number;
|
|
843
|
+
/** 数据请求次数 */
|
|
844
|
+
dataRequestCount: number;
|
|
845
|
+
/** 数据请求失败次数 */
|
|
846
|
+
dataRequestErrors: number;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* 性能监控器
|
|
851
|
+
*/
|
|
852
|
+
export declare class PerformanceMonitor {
|
|
853
|
+
private marks;
|
|
854
|
+
private measures;
|
|
855
|
+
private enabled;
|
|
856
|
+
constructor(enabled?: boolean);
|
|
857
|
+
/**
|
|
858
|
+
* 标记开始时间
|
|
859
|
+
*/
|
|
860
|
+
mark(name: string): void;
|
|
861
|
+
/**
|
|
862
|
+
* 测量耗时
|
|
863
|
+
*/
|
|
864
|
+
measure(name: string, startMark: string, endMark?: string): number;
|
|
865
|
+
/**
|
|
866
|
+
* 获取所有测量结果
|
|
867
|
+
*/
|
|
868
|
+
getMeasures(): Record<string, number>;
|
|
869
|
+
/**
|
|
870
|
+
* 清空
|
|
871
|
+
*/
|
|
872
|
+
clear(): void;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* 工具函数
|
|
877
|
+
*/
|
|
878
|
+
/**
|
|
879
|
+
* 预连接 CDN/API 域名
|
|
880
|
+
*/
|
|
881
|
+
export declare function preconnect(hosts: string[]): void;
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* 预加载 runtime 资源
|
|
885
|
+
*/
|
|
886
|
+
export declare function preloadAssets(cdnBaseUrl: string, version?: string): void;
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* 版本信息
|
|
890
|
+
*/
|
|
891
|
+
export declare const RUNTIME_VERSION: string;
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Host API 实现
|
|
895
|
+
* 提供给组件的安全 API,完全对齐 @djvlc/contracts-types 中的 HostApi 定义
|
|
896
|
+
*
|
|
897
|
+
* 组件只能通过 HostAPI 与外界交互,禁止:
|
|
898
|
+
* - 直接调用 window.fetch(绕过 Data Proxy)
|
|
899
|
+
* - 直接操作 location.href(绕过权限/埋点)
|
|
900
|
+
* - 随意访问 localStorage(乱写)
|
|
901
|
+
* - 随意上报(污染数据)
|
|
902
|
+
*/
|
|
903
|
+
|
|
904
|
+
/**
|
|
905
|
+
* 运行时上下文
|
|
906
|
+
*/
|
|
907
|
+
declare interface RuntimeContext {
|
|
908
|
+
pageUid: string;
|
|
909
|
+
pageVersionId: string;
|
|
910
|
+
runtimeVersion: string;
|
|
911
|
+
userId?: string;
|
|
912
|
+
deviceId?: string;
|
|
913
|
+
channel?: string;
|
|
914
|
+
appId: string;
|
|
915
|
+
env: 'development' | 'staging' | 'production';
|
|
916
|
+
isEditMode: boolean;
|
|
917
|
+
isPreviewMode: boolean;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* 运行时错误
|
|
922
|
+
*/
|
|
923
|
+
declare interface RuntimeError {
|
|
924
|
+
/** 错误类型 */
|
|
925
|
+
type: RuntimeErrorType;
|
|
926
|
+
/** 错误消息 */
|
|
927
|
+
message: string;
|
|
928
|
+
/** 错误码 */
|
|
929
|
+
code?: string;
|
|
930
|
+
/** 详细信息 */
|
|
931
|
+
details?: Record<string, unknown>;
|
|
932
|
+
/** 原始错误 */
|
|
933
|
+
cause?: Error;
|
|
934
|
+
/** 追踪 ID */
|
|
935
|
+
traceId?: string;
|
|
936
|
+
/** 时间戳 */
|
|
937
|
+
timestamp: number;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* 运行时错误类型
|
|
942
|
+
*/
|
|
943
|
+
declare type RuntimeErrorType = 'LOAD_ERROR' | 'RENDER_ERROR' | 'ACTION_ERROR' | 'QUERY_ERROR' | 'EXPRESSION_ERROR' | 'COMPONENT_ERROR' | 'SECURITY_ERROR' | 'NETWORK_ERROR' | 'UNKNOWN_ERROR';
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* 运行时事件
|
|
947
|
+
*/
|
|
948
|
+
declare interface RuntimeEvent<T = unknown> {
|
|
949
|
+
/** 事件类型 */
|
|
950
|
+
type: RuntimeEventType;
|
|
951
|
+
/** 事件数据 */
|
|
952
|
+
data: T;
|
|
953
|
+
/** 追踪 ID */
|
|
954
|
+
traceId?: string;
|
|
955
|
+
/** 时间戳 */
|
|
956
|
+
timestamp: number;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* 运行时事件类型
|
|
961
|
+
*/
|
|
962
|
+
declare type RuntimeEventType = 'page:resolving' | 'page:resolved' | 'page:loading' | 'page:loaded' | 'page:rendered' | 'page:error' | 'page:destroyed' | 'component:loading' | 'component:loaded' | 'component:error' | 'action:executing' | 'action:executed' | 'action:error' | 'query:fetching' | 'query:fetched' | 'query:error' | 'state:changed';
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* 运行时初始化选项
|
|
966
|
+
*/
|
|
967
|
+
export declare interface RuntimeOptions {
|
|
968
|
+
/** 容器元素或选择器 */
|
|
969
|
+
container: string | HTMLElement;
|
|
970
|
+
/** 页面 UID(pageId) */
|
|
971
|
+
pageUid: string;
|
|
972
|
+
/** API 基础 URL */
|
|
973
|
+
apiBaseUrl: string;
|
|
974
|
+
/** CDN 基础 URL */
|
|
975
|
+
cdnBaseUrl: string;
|
|
976
|
+
/** 渠道 */
|
|
977
|
+
channel?: 'preview' | 'prod' | 'gray';
|
|
978
|
+
/** 用户 ID */
|
|
979
|
+
userId?: string;
|
|
980
|
+
/** 设备 ID */
|
|
981
|
+
deviceId?: string;
|
|
982
|
+
/** 认证 Token */
|
|
983
|
+
authToken?: string;
|
|
984
|
+
/** 预览 Token */
|
|
985
|
+
previewToken?: string;
|
|
986
|
+
/** 调试模式 */
|
|
987
|
+
debug?: boolean;
|
|
988
|
+
/** 是否启用 SRI 校验 */
|
|
989
|
+
enableSRI?: boolean;
|
|
990
|
+
/** 自定义请求头 */
|
|
991
|
+
headers?: Record<string, string>;
|
|
992
|
+
/** 应用 ID */
|
|
993
|
+
appId?: string;
|
|
994
|
+
/** 环境 */
|
|
995
|
+
env?: 'development' | 'staging' | 'production';
|
|
996
|
+
/** 错误回调 */
|
|
997
|
+
onError?: (error: RuntimeError) => void;
|
|
998
|
+
/** 事件回调 */
|
|
999
|
+
onEvent?: (event: RuntimeEvent) => void;
|
|
1000
|
+
/** 性能指标回调 */
|
|
1001
|
+
onMetric?: (metric: PerformanceMetric) => void;
|
|
1002
|
+
/** 加载完成回调 */
|
|
1003
|
+
onLoad?: (data: PageResolveResult) => void;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* 运行时阶段
|
|
1008
|
+
*/
|
|
1009
|
+
declare type RuntimePhase = 'idle' | 'resolving' | 'loading' | 'rendering' | 'ready' | 'error' | 'destroyed';
|
|
1010
|
+
|
|
1011
|
+
/**
|
|
1012
|
+
* 运行时状态
|
|
1013
|
+
*/
|
|
1014
|
+
export declare interface RuntimeState {
|
|
1015
|
+
/** 当前阶段 */
|
|
1016
|
+
phase: RuntimePhase;
|
|
1017
|
+
/** 页面解析结果 */
|
|
1018
|
+
page: PageResolveResult | null;
|
|
1019
|
+
/** 页面状态变量(可变) */
|
|
1020
|
+
variables: Record<string, unknown>;
|
|
1021
|
+
/** 数据查询结果缓存 */
|
|
1022
|
+
queries: Record<string, unknown>;
|
|
1023
|
+
/** 组件加载状态 */
|
|
1024
|
+
components: Map<string, ComponentLoadResult>;
|
|
1025
|
+
/** 错误信息 */
|
|
1026
|
+
error: RuntimeError | null;
|
|
1027
|
+
/** 是否已销毁 */
|
|
1028
|
+
destroyed: boolean;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* 状态变更回调
|
|
1033
|
+
*/
|
|
1034
|
+
declare type StateChangeCallback = (detail: StateChangeDetail) => void;
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* 状态变更详情
|
|
1038
|
+
*/
|
|
1039
|
+
declare interface StateChangeDetail {
|
|
1040
|
+
/** 变更的键 */
|
|
1041
|
+
key: string;
|
|
1042
|
+
/** 旧值 */
|
|
1043
|
+
oldValue: unknown;
|
|
1044
|
+
/** 新值 */
|
|
1045
|
+
newValue: unknown;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* 状态管理器
|
|
1050
|
+
* 管理页面运行时状态,兼容 PageSchema V2
|
|
1051
|
+
*/
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* 状态变更监听器
|
|
1055
|
+
*/
|
|
1056
|
+
declare type StateListener = (state: RuntimeState) => void;
|
|
1057
|
+
|
|
1058
|
+
/**
|
|
1059
|
+
* 状态管理器
|
|
1060
|
+
*/
|
|
1061
|
+
declare class StateManager {
|
|
1062
|
+
private state;
|
|
1063
|
+
private listeners;
|
|
1064
|
+
private changeCallbacks;
|
|
1065
|
+
constructor();
|
|
1066
|
+
/**
|
|
1067
|
+
* 获取当前状态
|
|
1068
|
+
*/
|
|
1069
|
+
getState(): RuntimeState;
|
|
1070
|
+
/**
|
|
1071
|
+
* 获取当前阶段
|
|
1072
|
+
*/
|
|
1073
|
+
getPhase(): RuntimePhase;
|
|
1074
|
+
/**
|
|
1075
|
+
* 设置阶段
|
|
1076
|
+
*/
|
|
1077
|
+
setPhase(phase: RuntimePhase): void;
|
|
1078
|
+
/**
|
|
1079
|
+
* 设置页面数据(兼容 V2 PageSchema)
|
|
1080
|
+
*/
|
|
1081
|
+
setPage(page: PageResolveResult): void;
|
|
1082
|
+
/**
|
|
1083
|
+
* 初始化页面状态(从 PageSchema V2 的 state 定义)
|
|
1084
|
+
*/
|
|
1085
|
+
private initializePageState;
|
|
1086
|
+
/**
|
|
1087
|
+
* 设置错误
|
|
1088
|
+
*/
|
|
1089
|
+
setError(error: RuntimeError): void;
|
|
1090
|
+
/**
|
|
1091
|
+
* 清除错误
|
|
1092
|
+
*/
|
|
1093
|
+
clearError(): void;
|
|
1094
|
+
/**
|
|
1095
|
+
* 获取变量值
|
|
1096
|
+
*/
|
|
1097
|
+
getVariable<T = unknown>(key: string): T | undefined;
|
|
1098
|
+
/**
|
|
1099
|
+
* 设置变量值
|
|
1100
|
+
*/
|
|
1101
|
+
setVariable(key: string, value: unknown): void;
|
|
1102
|
+
/**
|
|
1103
|
+
* 批量设置变量
|
|
1104
|
+
*/
|
|
1105
|
+
setVariables(variables: Record<string, unknown>): void;
|
|
1106
|
+
/**
|
|
1107
|
+
* 获取查询结果
|
|
1108
|
+
*/
|
|
1109
|
+
getQuery<T = unknown>(queryId: string): T | undefined;
|
|
1110
|
+
/**
|
|
1111
|
+
* 设置查询结果
|
|
1112
|
+
*/
|
|
1113
|
+
setQuery(queryId: string, data: unknown): void;
|
|
1114
|
+
/**
|
|
1115
|
+
* 清除查询结果
|
|
1116
|
+
*/
|
|
1117
|
+
clearQuery(queryId: string): void;
|
|
1118
|
+
/**
|
|
1119
|
+
* 更新组件加载状态
|
|
1120
|
+
*/
|
|
1121
|
+
setComponentStatus(key: string, result: ComponentLoadResult): void;
|
|
1122
|
+
/**
|
|
1123
|
+
* 获取组件加载状态
|
|
1124
|
+
*/
|
|
1125
|
+
getComponentStatus(key: string): ComponentLoadResult | undefined;
|
|
1126
|
+
/**
|
|
1127
|
+
* 标记为已销毁
|
|
1128
|
+
*/
|
|
1129
|
+
setDestroyed(): void;
|
|
1130
|
+
/**
|
|
1131
|
+
* 检查是否已销毁
|
|
1132
|
+
*/
|
|
1133
|
+
isDestroyed(): boolean;
|
|
1134
|
+
/**
|
|
1135
|
+
* 订阅状态变更
|
|
1136
|
+
*/
|
|
1137
|
+
subscribe(listener: StateListener): () => void;
|
|
1138
|
+
/**
|
|
1139
|
+
* 订阅特定状态键的变更
|
|
1140
|
+
*/
|
|
1141
|
+
onStateChange(callback: StateChangeCallback): () => void;
|
|
1142
|
+
/**
|
|
1143
|
+
* 重置状态
|
|
1144
|
+
*/
|
|
1145
|
+
reset(): void;
|
|
1146
|
+
/**
|
|
1147
|
+
* 获取表达式上下文
|
|
1148
|
+
* 对齐 contracts 中的 ExpressionContext 定义:
|
|
1149
|
+
* - state: 页面状态变量
|
|
1150
|
+
* - binding: 数据绑定结果(即查询结果)
|
|
1151
|
+
* - local: 局部变量(循环变量、事件参数等,由渲染器管理)
|
|
1152
|
+
* - context: 运行时上下文(额外信息)
|
|
1153
|
+
*/
|
|
1154
|
+
getExpressionContext(): {
|
|
1155
|
+
state: Record<string, unknown>;
|
|
1156
|
+
binding: Record<string, unknown>;
|
|
1157
|
+
local: Record<string, unknown>;
|
|
1158
|
+
context: Record<string, unknown>;
|
|
1159
|
+
};
|
|
1160
|
+
private setState;
|
|
1161
|
+
private notifyListeners;
|
|
1162
|
+
private notifyChange;
|
|
1163
|
+
private getNestedValue;
|
|
1164
|
+
private setNestedValue;
|
|
1165
|
+
private createInitialState;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
/**
|
|
1169
|
+
* 存储辅助工具
|
|
1170
|
+
*/
|
|
1171
|
+
/**
|
|
1172
|
+
* 存储辅助类(带命名空间和 TTL)
|
|
1173
|
+
*/
|
|
1174
|
+
export declare class StorageHelper {
|
|
1175
|
+
private namespace;
|
|
1176
|
+
private storage;
|
|
1177
|
+
constructor(namespace?: string, useSession?: boolean);
|
|
1178
|
+
private getKey;
|
|
1179
|
+
/**
|
|
1180
|
+
* 获取值
|
|
1181
|
+
*/
|
|
1182
|
+
get<T>(key: string): T | null;
|
|
1183
|
+
/**
|
|
1184
|
+
* 设置值
|
|
1185
|
+
*/
|
|
1186
|
+
set<T>(key: string, value: T, ttl?: number): void;
|
|
1187
|
+
/**
|
|
1188
|
+
* 删除值
|
|
1189
|
+
*/
|
|
1190
|
+
remove(key: string): void;
|
|
1191
|
+
/**
|
|
1192
|
+
* 清空命名空间下所有值
|
|
1193
|
+
*/
|
|
1194
|
+
clear(): void;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* 检测是否支持 WebP
|
|
1199
|
+
*/
|
|
1200
|
+
export declare function supportsWebP(): Promise<boolean>;
|
|
1201
|
+
|
|
1202
|
+
/**
|
|
1203
|
+
* 埋点与追踪
|
|
1204
|
+
*/
|
|
1205
|
+
/**
|
|
1206
|
+
* 埋点事件
|
|
1207
|
+
*/
|
|
1208
|
+
declare interface TrackEvent_2 {
|
|
1209
|
+
/** 事件名称 */
|
|
1210
|
+
event: string;
|
|
1211
|
+
/** 事件数据 */
|
|
1212
|
+
data?: Record<string, unknown>;
|
|
1213
|
+
/** 页面 UID */
|
|
1214
|
+
pageUid?: string;
|
|
1215
|
+
/** 页面版本 ID */
|
|
1216
|
+
pageVersionId?: string;
|
|
1217
|
+
/** 组件 ID */
|
|
1218
|
+
componentId?: string;
|
|
1219
|
+
/** 时间戳 */
|
|
1220
|
+
timestamp: number;
|
|
1221
|
+
/** 追踪 ID */
|
|
1222
|
+
traceId?: string;
|
|
1223
|
+
}
|
|
1224
|
+
export { TrackEvent_2 as TrackEvent }
|
|
1225
|
+
|
|
1226
|
+
/**
|
|
1227
|
+
* 埋点配置
|
|
1228
|
+
*/
|
|
1229
|
+
export declare interface TrackingConfig {
|
|
1230
|
+
/** 上报端点 */
|
|
1231
|
+
endpoint?: string;
|
|
1232
|
+
/** 批量上报阈值 */
|
|
1233
|
+
batchSize?: number;
|
|
1234
|
+
/** 上报间隔 */
|
|
1235
|
+
flushInterval?: number;
|
|
1236
|
+
/** 是否启用 */
|
|
1237
|
+
enabled?: boolean;
|
|
1238
|
+
/** 采样率 */
|
|
1239
|
+
sampleRate?: number;
|
|
1240
|
+
/** 自定义上报函数 */
|
|
1241
|
+
reporter?: (events: TrackEvent_2[]) => void | Promise<void>;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
/**
|
|
1245
|
+
* 埋点管理器
|
|
1246
|
+
*/
|
|
1247
|
+
export declare class TrackingManager {
|
|
1248
|
+
private events;
|
|
1249
|
+
private config;
|
|
1250
|
+
private flushTimer;
|
|
1251
|
+
private traceId;
|
|
1252
|
+
constructor(config?: TrackingConfig);
|
|
1253
|
+
/**
|
|
1254
|
+
* 追踪事件
|
|
1255
|
+
*/
|
|
1256
|
+
track(event: string, data?: Record<string, unknown>, context?: Partial<TrackEvent_2>): void;
|
|
1257
|
+
/**
|
|
1258
|
+
* 追踪页面访问
|
|
1259
|
+
*/
|
|
1260
|
+
trackPageView(pageUid: string, pageVersionId?: string): void;
|
|
1261
|
+
/**
|
|
1262
|
+
* 追踪组件曝光
|
|
1263
|
+
*/
|
|
1264
|
+
trackComponentView(componentId: string, componentType: string, pageUid?: string): void;
|
|
1265
|
+
/**
|
|
1266
|
+
* 追踪组件点击
|
|
1267
|
+
*/
|
|
1268
|
+
trackComponentClick(componentId: string, componentType: string, pageUid?: string): void;
|
|
1269
|
+
/**
|
|
1270
|
+
* 追踪动作执行
|
|
1271
|
+
*/
|
|
1272
|
+
trackAction(actionType: string, success: boolean, duration: number, pageUid?: string): void;
|
|
1273
|
+
/**
|
|
1274
|
+
* 追踪错误
|
|
1275
|
+
*/
|
|
1276
|
+
trackError(error: Error, context?: Record<string, unknown>): void;
|
|
1277
|
+
/**
|
|
1278
|
+
* 立即上报
|
|
1279
|
+
*/
|
|
1280
|
+
flush(): Promise<void>;
|
|
1281
|
+
/**
|
|
1282
|
+
* 销毁
|
|
1283
|
+
*/
|
|
1284
|
+
destroy(): void;
|
|
1285
|
+
private defaultReporter;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
declare interface UnaryASTNode extends BaseASTNode {
|
|
1289
|
+
type: 'unary';
|
|
1290
|
+
operator: string;
|
|
1291
|
+
argument: ASTNode;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* 事件订阅取消函数
|
|
1296
|
+
*/
|
|
1297
|
+
declare type Unsubscribe = () => void;
|
|
1298
|
+
|
|
1299
|
+
export declare const urlUtils: {
|
|
1300
|
+
/**
|
|
1301
|
+
* 获取 URL 参数
|
|
1302
|
+
*/
|
|
1303
|
+
getParam(name: string, url?: string): string | null;
|
|
1304
|
+
/**
|
|
1305
|
+
* 设置 URL 参数
|
|
1306
|
+
*/
|
|
1307
|
+
setParam(name: string, value: string): void;
|
|
1308
|
+
/**
|
|
1309
|
+
* 删除 URL 参数
|
|
1310
|
+
*/
|
|
1311
|
+
removeParam(name: string): void;
|
|
1312
|
+
/**
|
|
1313
|
+
* 构建 URL
|
|
1314
|
+
*/
|
|
1315
|
+
build(base: string, params: Record<string, string | number | boolean | undefined>): string;
|
|
1316
|
+
};
|
|
1317
|
+
|
|
1318
|
+
/**
|
|
1319
|
+
* 预热挂载
|
|
1320
|
+
*/
|
|
1321
|
+
export declare function warmup(options: MountOptions): Promise<{
|
|
1322
|
+
mount: (container: string | HTMLElement) => Promise<MountResult>;
|
|
1323
|
+
}>;
|
|
1324
|
+
|
|
1325
|
+
export { }
|