@djvlc/runtime-host-vue 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,287 @@
1
+ import * as vue from 'vue';
2
+ import { Ref, ShallowRef, PropType, InjectionKey, Plugin } from 'vue';
3
+ import * as _djvlc_runtime_core from '@djvlc/runtime-core';
4
+ import { RuntimeOptions, DjvlcRuntime, RuntimePhase, PageResolveResult, RuntimeError, HostAPI, RuntimeState } from '@djvlc/runtime-core';
5
+ export { HostAPI, PageResolveResult, RuntimeError, RuntimeOptions, RuntimePhase, RuntimeState } from '@djvlc/runtime-core';
6
+ import * as _djvlc_contracts_types from '@djvlc/contracts-types';
7
+
8
+ /**
9
+ * Vue 运行时封装
10
+ * 将核心运行时封装为 Vue 友好的 API
11
+ */
12
+
13
+ /**
14
+ * Vue 运行时选项
15
+ */
16
+ interface VueRuntimeOptions extends Omit<RuntimeOptions, 'container'> {
17
+ /** 容器元素引用 */
18
+ containerRef?: Ref<HTMLElement | null>;
19
+ }
20
+ /**
21
+ * Vue 运行时返回值
22
+ */
23
+ interface VueRuntimeReturn {
24
+ /** 运行时实例 */
25
+ runtime: ShallowRef<DjvlcRuntime | null>;
26
+ /** 加载状态 */
27
+ loading: Ref<boolean>;
28
+ /** 当前阶段 */
29
+ phase: Ref<RuntimePhase>;
30
+ /** 页面数据 */
31
+ page: ShallowRef<PageResolveResult | null>;
32
+ /** 错误信息 */
33
+ error: ShallowRef<RuntimeError | null>;
34
+ /** Host API */
35
+ hostApi: ShallowRef<HostAPI | null>;
36
+ /** 初始化 */
37
+ init: () => Promise<void>;
38
+ /** 加载页面 */
39
+ load: () => Promise<PageResolveResult>;
40
+ /** 渲染页面 */
41
+ render: () => Promise<void>;
42
+ /** 销毁 */
43
+ destroy: () => void;
44
+ /** 设置变量 */
45
+ setVariable: (key: string, value: unknown) => void;
46
+ /** 刷新数据 */
47
+ refreshData: (queryId: string) => Promise<void>;
48
+ }
49
+ /**
50
+ * 创建 Vue 运行时
51
+ */
52
+ declare function createVueRuntime(options: VueRuntimeOptions): VueRuntimeReturn;
53
+
54
+ /**
55
+ * DJV 渲染器 Props
56
+ */
57
+ interface DJVRendererProps {
58
+ /** 页面 UID */
59
+ pageUid: string;
60
+ /** API 基础 URL */
61
+ apiBaseUrl: string;
62
+ /** CDN 基础 URL */
63
+ cdnBaseUrl: string;
64
+ /** 渠道 */
65
+ channel?: 'preview' | 'prod' | 'gray';
66
+ /** 用户 ID */
67
+ userId?: string;
68
+ /** 设备 ID */
69
+ deviceId?: string;
70
+ /** 认证 Token */
71
+ authToken?: string;
72
+ /** 预览 Token */
73
+ previewToken?: string;
74
+ /** 调试模式 */
75
+ debug?: boolean;
76
+ /** 是否启用 SRI */
77
+ enableSRI?: boolean;
78
+ }
79
+ /**
80
+ * DJV 渲染器组件
81
+ */
82
+ declare const DJVRenderer: vue.DefineComponent<vue.ExtractPropTypes<{
83
+ pageUid: {
84
+ type: StringConstructor;
85
+ required: true;
86
+ };
87
+ apiBaseUrl: {
88
+ type: StringConstructor;
89
+ required: true;
90
+ };
91
+ cdnBaseUrl: {
92
+ type: StringConstructor;
93
+ required: true;
94
+ };
95
+ channel: {
96
+ type: PropType<"preview" | "prod" | "gray">;
97
+ default: string;
98
+ };
99
+ userId: StringConstructor;
100
+ deviceId: StringConstructor;
101
+ authToken: StringConstructor;
102
+ previewToken: StringConstructor;
103
+ debug: {
104
+ type: BooleanConstructor;
105
+ default: boolean;
106
+ };
107
+ enableSRI: {
108
+ type: BooleanConstructor;
109
+ default: boolean;
110
+ };
111
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
112
+ [key: string]: any;
113
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("ready" | "error" | "load")[], "ready" | "error" | "load", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
114
+ pageUid: {
115
+ type: StringConstructor;
116
+ required: true;
117
+ };
118
+ apiBaseUrl: {
119
+ type: StringConstructor;
120
+ required: true;
121
+ };
122
+ cdnBaseUrl: {
123
+ type: StringConstructor;
124
+ required: true;
125
+ };
126
+ channel: {
127
+ type: PropType<"preview" | "prod" | "gray">;
128
+ default: string;
129
+ };
130
+ userId: StringConstructor;
131
+ deviceId: StringConstructor;
132
+ authToken: StringConstructor;
133
+ previewToken: StringConstructor;
134
+ debug: {
135
+ type: BooleanConstructor;
136
+ default: boolean;
137
+ };
138
+ enableSRI: {
139
+ type: BooleanConstructor;
140
+ default: boolean;
141
+ };
142
+ }>> & Readonly<{
143
+ onError?: ((...args: any[]) => any) | undefined;
144
+ onReady?: ((...args: any[]) => any) | undefined;
145
+ onLoad?: ((...args: any[]) => any) | undefined;
146
+ }>, {
147
+ channel: "preview" | "prod" | "gray";
148
+ debug: boolean;
149
+ enableSRI: boolean;
150
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
151
+
152
+ /**
153
+ * DJV Provider Props
154
+ */
155
+ interface DJVProviderProps {
156
+ /** 运行时实例 */
157
+ runtime: DjvlcRuntime | null;
158
+ /** Host API */
159
+ hostApi: HostAPI | null;
160
+ }
161
+ /**
162
+ * DJV Provider 组件
163
+ * 用于手动控制运行时时使用
164
+ */
165
+ declare const DJVProvider: vue.DefineComponent<vue.ExtractPropTypes<{
166
+ runtime: {
167
+ type: PropType<DjvlcRuntime | null>;
168
+ default: null;
169
+ };
170
+ hostApi: {
171
+ type: PropType<HostAPI | null>;
172
+ default: null;
173
+ };
174
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
175
+ [key: string]: any;
176
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
177
+ runtime: {
178
+ type: PropType<DjvlcRuntime | null>;
179
+ default: null;
180
+ };
181
+ hostApi: {
182
+ type: PropType<HostAPI | null>;
183
+ default: null;
184
+ };
185
+ }>> & Readonly<{}>, {
186
+ runtime: DjvlcRuntime | null;
187
+ hostApi: HostAPI | null;
188
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
189
+
190
+ /**
191
+ * 运行时上下文
192
+ */
193
+ interface RuntimeContextValue {
194
+ runtime: DjvlcRuntime | null;
195
+ state: RuntimeState;
196
+ hostApi: HostAPI | null;
197
+ }
198
+ /**
199
+ * 运行时注入 Key
200
+ */
201
+ declare const RuntimeContextKey: InjectionKey<Ref<RuntimeContextValue>>;
202
+ /**
203
+ * 提供运行时上下文
204
+ */
205
+ declare function provideRuntime(value: Ref<RuntimeContextValue>): void;
206
+ /**
207
+ * 注入运行时上下文
208
+ */
209
+ declare function injectRuntime(): Ref<RuntimeContextValue>;
210
+ /**
211
+ * 使用运行时
212
+ */
213
+ declare function useDJVRuntime(): {
214
+ runtime: vue.ComputedRef<DjvlcRuntime | null>;
215
+ state: vue.ComputedRef<RuntimeState>;
216
+ loading: vue.ComputedRef<boolean>;
217
+ phase: vue.ComputedRef<_djvlc_runtime_core.RuntimePhase>;
218
+ error: vue.ComputedRef<_djvlc_contracts_types.RuntimeError | null>;
219
+ page: vue.ComputedRef<_djvlc_contracts_types.PageResolveResult | null>;
220
+ };
221
+ /**
222
+ * 使用 Host API
223
+ */
224
+ declare function useHostApi(): HostAPI;
225
+ /**
226
+ * 使用运行时状态
227
+ */
228
+ declare function useRuntimeState<T = unknown>(key: string): Ref<T | undefined>;
229
+ /**
230
+ * 使用可写状态
231
+ */
232
+ declare function useRuntimeStateWritable<T = unknown>(key: string, defaultValue?: T): [Ref<T>, (value: T) => void];
233
+ /**
234
+ * 使用查询结果
235
+ */
236
+ declare function useQuery<T = unknown>(queryId: string): {
237
+ data: Ref<T | undefined>;
238
+ loading: Ref<boolean>;
239
+ error: Ref<Error | null>;
240
+ refetch: () => Promise<void>;
241
+ };
242
+ /**
243
+ * 使用动作
244
+ */
245
+ declare function useAction<T = unknown, P = Record<string, unknown>>(actionType: string): {
246
+ execute: (params?: P) => Promise<T | undefined>;
247
+ loading: Ref<boolean>;
248
+ result: Ref<T | undefined>;
249
+ error: Ref<Error | null>;
250
+ };
251
+ /**
252
+ * 使用数据请求
253
+ */
254
+ declare function useData<T = unknown, P = Record<string, unknown>>(queryId: string, params?: P, options?: {
255
+ immediate?: boolean;
256
+ }): {
257
+ data: Ref<T | undefined>;
258
+ loading: Ref<boolean>;
259
+ error: Ref<Error | null>;
260
+ refetch: (newParams?: P) => Promise<void>;
261
+ };
262
+ /**
263
+ * 使用事件监听
264
+ */
265
+ declare function useRuntimeEvent<T = unknown>(eventType: string, handler: (data: T) => void): void;
266
+
267
+ /**
268
+ * Vue 插件
269
+ * 全局注册 DJVLC 组件
270
+ */
271
+
272
+ /**
273
+ * 插件选项
274
+ */
275
+ interface DJVPluginOptions {
276
+ /** 全局配置 */
277
+ defaultApiBaseUrl?: string;
278
+ defaultCdnBaseUrl?: string;
279
+ /** 是否注册全局组件 */
280
+ registerComponents?: boolean;
281
+ }
282
+ /**
283
+ * DJVLC Vue 插件
284
+ */
285
+ declare const DJVPlugin: Plugin;
286
+
287
+ export { DJVPlugin, type DJVPluginOptions, DJVProvider, type DJVProviderProps, DJVRenderer, type DJVRendererProps, RuntimeContextKey, type RuntimeContextValue, type VueRuntimeOptions, type VueRuntimeReturn, createVueRuntime, injectRuntime, provideRuntime, useAction, useDJVRuntime, useData, useHostApi, useQuery, useRuntimeEvent, useRuntimeState, useRuntimeStateWritable };
@@ -0,0 +1,287 @@
1
+ import * as vue from 'vue';
2
+ import { Ref, ShallowRef, PropType, InjectionKey, Plugin } from 'vue';
3
+ import * as _djvlc_runtime_core from '@djvlc/runtime-core';
4
+ import { RuntimeOptions, DjvlcRuntime, RuntimePhase, PageResolveResult, RuntimeError, HostAPI, RuntimeState } from '@djvlc/runtime-core';
5
+ export { HostAPI, PageResolveResult, RuntimeError, RuntimeOptions, RuntimePhase, RuntimeState } from '@djvlc/runtime-core';
6
+ import * as _djvlc_contracts_types from '@djvlc/contracts-types';
7
+
8
+ /**
9
+ * Vue 运行时封装
10
+ * 将核心运行时封装为 Vue 友好的 API
11
+ */
12
+
13
+ /**
14
+ * Vue 运行时选项
15
+ */
16
+ interface VueRuntimeOptions extends Omit<RuntimeOptions, 'container'> {
17
+ /** 容器元素引用 */
18
+ containerRef?: Ref<HTMLElement | null>;
19
+ }
20
+ /**
21
+ * Vue 运行时返回值
22
+ */
23
+ interface VueRuntimeReturn {
24
+ /** 运行时实例 */
25
+ runtime: ShallowRef<DjvlcRuntime | null>;
26
+ /** 加载状态 */
27
+ loading: Ref<boolean>;
28
+ /** 当前阶段 */
29
+ phase: Ref<RuntimePhase>;
30
+ /** 页面数据 */
31
+ page: ShallowRef<PageResolveResult | null>;
32
+ /** 错误信息 */
33
+ error: ShallowRef<RuntimeError | null>;
34
+ /** Host API */
35
+ hostApi: ShallowRef<HostAPI | null>;
36
+ /** 初始化 */
37
+ init: () => Promise<void>;
38
+ /** 加载页面 */
39
+ load: () => Promise<PageResolveResult>;
40
+ /** 渲染页面 */
41
+ render: () => Promise<void>;
42
+ /** 销毁 */
43
+ destroy: () => void;
44
+ /** 设置变量 */
45
+ setVariable: (key: string, value: unknown) => void;
46
+ /** 刷新数据 */
47
+ refreshData: (queryId: string) => Promise<void>;
48
+ }
49
+ /**
50
+ * 创建 Vue 运行时
51
+ */
52
+ declare function createVueRuntime(options: VueRuntimeOptions): VueRuntimeReturn;
53
+
54
+ /**
55
+ * DJV 渲染器 Props
56
+ */
57
+ interface DJVRendererProps {
58
+ /** 页面 UID */
59
+ pageUid: string;
60
+ /** API 基础 URL */
61
+ apiBaseUrl: string;
62
+ /** CDN 基础 URL */
63
+ cdnBaseUrl: string;
64
+ /** 渠道 */
65
+ channel?: 'preview' | 'prod' | 'gray';
66
+ /** 用户 ID */
67
+ userId?: string;
68
+ /** 设备 ID */
69
+ deviceId?: string;
70
+ /** 认证 Token */
71
+ authToken?: string;
72
+ /** 预览 Token */
73
+ previewToken?: string;
74
+ /** 调试模式 */
75
+ debug?: boolean;
76
+ /** 是否启用 SRI */
77
+ enableSRI?: boolean;
78
+ }
79
+ /**
80
+ * DJV 渲染器组件
81
+ */
82
+ declare const DJVRenderer: vue.DefineComponent<vue.ExtractPropTypes<{
83
+ pageUid: {
84
+ type: StringConstructor;
85
+ required: true;
86
+ };
87
+ apiBaseUrl: {
88
+ type: StringConstructor;
89
+ required: true;
90
+ };
91
+ cdnBaseUrl: {
92
+ type: StringConstructor;
93
+ required: true;
94
+ };
95
+ channel: {
96
+ type: PropType<"preview" | "prod" | "gray">;
97
+ default: string;
98
+ };
99
+ userId: StringConstructor;
100
+ deviceId: StringConstructor;
101
+ authToken: StringConstructor;
102
+ previewToken: StringConstructor;
103
+ debug: {
104
+ type: BooleanConstructor;
105
+ default: boolean;
106
+ };
107
+ enableSRI: {
108
+ type: BooleanConstructor;
109
+ default: boolean;
110
+ };
111
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
112
+ [key: string]: any;
113
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("ready" | "error" | "load")[], "ready" | "error" | "load", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
114
+ pageUid: {
115
+ type: StringConstructor;
116
+ required: true;
117
+ };
118
+ apiBaseUrl: {
119
+ type: StringConstructor;
120
+ required: true;
121
+ };
122
+ cdnBaseUrl: {
123
+ type: StringConstructor;
124
+ required: true;
125
+ };
126
+ channel: {
127
+ type: PropType<"preview" | "prod" | "gray">;
128
+ default: string;
129
+ };
130
+ userId: StringConstructor;
131
+ deviceId: StringConstructor;
132
+ authToken: StringConstructor;
133
+ previewToken: StringConstructor;
134
+ debug: {
135
+ type: BooleanConstructor;
136
+ default: boolean;
137
+ };
138
+ enableSRI: {
139
+ type: BooleanConstructor;
140
+ default: boolean;
141
+ };
142
+ }>> & Readonly<{
143
+ onError?: ((...args: any[]) => any) | undefined;
144
+ onReady?: ((...args: any[]) => any) | undefined;
145
+ onLoad?: ((...args: any[]) => any) | undefined;
146
+ }>, {
147
+ channel: "preview" | "prod" | "gray";
148
+ debug: boolean;
149
+ enableSRI: boolean;
150
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
151
+
152
+ /**
153
+ * DJV Provider Props
154
+ */
155
+ interface DJVProviderProps {
156
+ /** 运行时实例 */
157
+ runtime: DjvlcRuntime | null;
158
+ /** Host API */
159
+ hostApi: HostAPI | null;
160
+ }
161
+ /**
162
+ * DJV Provider 组件
163
+ * 用于手动控制运行时时使用
164
+ */
165
+ declare const DJVProvider: vue.DefineComponent<vue.ExtractPropTypes<{
166
+ runtime: {
167
+ type: PropType<DjvlcRuntime | null>;
168
+ default: null;
169
+ };
170
+ hostApi: {
171
+ type: PropType<HostAPI | null>;
172
+ default: null;
173
+ };
174
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
175
+ [key: string]: any;
176
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
177
+ runtime: {
178
+ type: PropType<DjvlcRuntime | null>;
179
+ default: null;
180
+ };
181
+ hostApi: {
182
+ type: PropType<HostAPI | null>;
183
+ default: null;
184
+ };
185
+ }>> & Readonly<{}>, {
186
+ runtime: DjvlcRuntime | null;
187
+ hostApi: HostAPI | null;
188
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
189
+
190
+ /**
191
+ * 运行时上下文
192
+ */
193
+ interface RuntimeContextValue {
194
+ runtime: DjvlcRuntime | null;
195
+ state: RuntimeState;
196
+ hostApi: HostAPI | null;
197
+ }
198
+ /**
199
+ * 运行时注入 Key
200
+ */
201
+ declare const RuntimeContextKey: InjectionKey<Ref<RuntimeContextValue>>;
202
+ /**
203
+ * 提供运行时上下文
204
+ */
205
+ declare function provideRuntime(value: Ref<RuntimeContextValue>): void;
206
+ /**
207
+ * 注入运行时上下文
208
+ */
209
+ declare function injectRuntime(): Ref<RuntimeContextValue>;
210
+ /**
211
+ * 使用运行时
212
+ */
213
+ declare function useDJVRuntime(): {
214
+ runtime: vue.ComputedRef<DjvlcRuntime | null>;
215
+ state: vue.ComputedRef<RuntimeState>;
216
+ loading: vue.ComputedRef<boolean>;
217
+ phase: vue.ComputedRef<_djvlc_runtime_core.RuntimePhase>;
218
+ error: vue.ComputedRef<_djvlc_contracts_types.RuntimeError | null>;
219
+ page: vue.ComputedRef<_djvlc_contracts_types.PageResolveResult | null>;
220
+ };
221
+ /**
222
+ * 使用 Host API
223
+ */
224
+ declare function useHostApi(): HostAPI;
225
+ /**
226
+ * 使用运行时状态
227
+ */
228
+ declare function useRuntimeState<T = unknown>(key: string): Ref<T | undefined>;
229
+ /**
230
+ * 使用可写状态
231
+ */
232
+ declare function useRuntimeStateWritable<T = unknown>(key: string, defaultValue?: T): [Ref<T>, (value: T) => void];
233
+ /**
234
+ * 使用查询结果
235
+ */
236
+ declare function useQuery<T = unknown>(queryId: string): {
237
+ data: Ref<T | undefined>;
238
+ loading: Ref<boolean>;
239
+ error: Ref<Error | null>;
240
+ refetch: () => Promise<void>;
241
+ };
242
+ /**
243
+ * 使用动作
244
+ */
245
+ declare function useAction<T = unknown, P = Record<string, unknown>>(actionType: string): {
246
+ execute: (params?: P) => Promise<T | undefined>;
247
+ loading: Ref<boolean>;
248
+ result: Ref<T | undefined>;
249
+ error: Ref<Error | null>;
250
+ };
251
+ /**
252
+ * 使用数据请求
253
+ */
254
+ declare function useData<T = unknown, P = Record<string, unknown>>(queryId: string, params?: P, options?: {
255
+ immediate?: boolean;
256
+ }): {
257
+ data: Ref<T | undefined>;
258
+ loading: Ref<boolean>;
259
+ error: Ref<Error | null>;
260
+ refetch: (newParams?: P) => Promise<void>;
261
+ };
262
+ /**
263
+ * 使用事件监听
264
+ */
265
+ declare function useRuntimeEvent<T = unknown>(eventType: string, handler: (data: T) => void): void;
266
+
267
+ /**
268
+ * Vue 插件
269
+ * 全局注册 DJVLC 组件
270
+ */
271
+
272
+ /**
273
+ * 插件选项
274
+ */
275
+ interface DJVPluginOptions {
276
+ /** 全局配置 */
277
+ defaultApiBaseUrl?: string;
278
+ defaultCdnBaseUrl?: string;
279
+ /** 是否注册全局组件 */
280
+ registerComponents?: boolean;
281
+ }
282
+ /**
283
+ * DJVLC Vue 插件
284
+ */
285
+ declare const DJVPlugin: Plugin;
286
+
287
+ export { DJVPlugin, type DJVPluginOptions, DJVProvider, type DJVProviderProps, DJVRenderer, type DJVRendererProps, RuntimeContextKey, type RuntimeContextValue, type VueRuntimeOptions, type VueRuntimeReturn, createVueRuntime, injectRuntime, provideRuntime, useAction, useDJVRuntime, useData, useHostApi, useQuery, useRuntimeEvent, useRuntimeState, useRuntimeStateWritable };