@djvlc/runtime-web 1.0.0

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.
@@ -0,0 +1,115 @@
1
+ import { createRuntime } from '@djvlc/runtime-core';
2
+
3
+ export declare const RUNTIME_VERSION: string;
4
+ /**
5
+ * 挂载选项(简化版,用于浏览器端)
6
+ */
7
+ export interface MountOptions {
8
+ /** 页面 UID */
9
+ pageUid: string;
10
+ /** API 基础 URL */
11
+ apiBaseUrl: string;
12
+ /** CDN 基础 URL */
13
+ cdnBaseUrl: string;
14
+ /** 渠道 */
15
+ channel?: 'preview' | 'prod' | 'gray';
16
+ /** 用户 ID */
17
+ userId?: string;
18
+ /** 设备 ID */
19
+ deviceId?: string;
20
+ /** 认证 Token */
21
+ authToken?: string;
22
+ /** 预览 Token(仅 preview 渠道) */
23
+ previewToken?: string;
24
+ /** 调试模式 */
25
+ debug?: boolean;
26
+ /** 是否启用 SRI 校验 */
27
+ enableSRI?: boolean;
28
+ /** 自定义请求头 */
29
+ headers?: Record<string, string>;
30
+ /** 加载完成回调 */
31
+ onLoad?: (data: unknown) => void;
32
+ /** 错误回调 */
33
+ onError?: (error: Error) => void;
34
+ /** 性能指标回调 */
35
+ onMetric?: (metric: unknown) => void;
36
+ }
37
+ /**
38
+ * 挂载结果
39
+ */
40
+ export interface MountResult {
41
+ /** 运行时实例 */
42
+ runtime: ReturnType<typeof createRuntime>;
43
+ /** 销毁函数 */
44
+ destroy: () => void;
45
+ }
46
+ /**
47
+ * 挂载运行时到指定容器
48
+ *
49
+ * @param container - 容器选择器或元素
50
+ * @param options - 挂载选项
51
+ * @returns 挂载结果
52
+ *
53
+ * @example
54
+ * ```javascript
55
+ * const { runtime, destroy } = await DJVRuntime.mount('#app', {
56
+ * pageUid: 'page_123',
57
+ * apiBaseUrl: 'https://api.example.com',
58
+ * cdnBaseUrl: 'https://cdn.example.com',
59
+ * channel: 'prod',
60
+ * });
61
+ *
62
+ * // 页面卸载时销毁
63
+ * window.addEventListener('beforeunload', destroy);
64
+ * ```
65
+ */
66
+ export declare function mount(container: string | HTMLElement, options: MountOptions): Promise<MountResult>;
67
+ /**
68
+ * 预连接 CDN/API 域名(优化加载速度)
69
+ *
70
+ * @param hosts - 域名列表
71
+ *
72
+ * @example
73
+ * ```javascript
74
+ * DJVRuntime.preconnect(['cdn.example.com', 'api.example.com']);
75
+ * ```
76
+ */
77
+ export declare function preconnect(hosts: string[]): void;
78
+ /**
79
+ * 预加载 runtime 资源
80
+ *
81
+ * @param cdnBaseUrl - CDN 基础 URL
82
+ * @param version - 运行时版本(默认当前版本)
83
+ */
84
+ export declare function preloadAssets(cdnBaseUrl: string, version?: string): void;
85
+ /**
86
+ * 获取设备 ID(自动生成并持久化)
87
+ */
88
+ export declare function getDeviceId(): string;
89
+ /**
90
+ * 生成追踪 ID(W3C Trace Context 格式)
91
+ */
92
+ export declare function generateTraceId(): string;
93
+ /**
94
+ * 生成 Span ID
95
+ */
96
+ export declare function generateSpanId(): string;
97
+ /**
98
+ * 生成 traceparent 头
99
+ */
100
+ export declare function generateTraceparent(): string;
101
+ export { createRuntime } from '@djvlc/runtime-core';
102
+ export type { RuntimeOptions, RuntimeState, LoadedComponent, Logger } from '@djvlc/runtime-core';
103
+ declare const _default: {
104
+ mount: typeof mount;
105
+ preconnect: typeof preconnect;
106
+ preloadAssets: typeof preloadAssets;
107
+ getDeviceId: typeof getDeviceId;
108
+ generateTraceId: typeof generateTraceId;
109
+ generateSpanId: typeof generateSpanId;
110
+ generateTraceparent: typeof generateTraceparent;
111
+ createRuntime: typeof createRuntime;
112
+ RUNTIME_VERSION: string;
113
+ };
114
+ export default _default;
115
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,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