@vvfx/sdk 0.2.3 → 0.2.4

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,7 @@
1
+ export type SDKCanvasLayers = {
2
+ container: HTMLElement;
3
+ playerContainer?: HTMLElement;
4
+ htmlOverlayLayer?: HTMLElement;
5
+ gestureCanvas?: HTMLElement;
6
+ };
7
+ export declare function orderSDKCanvasLayers({ container, playerContainer, htmlOverlayLayer, gestureCanvas, }: SDKCanvasLayers): void;
@@ -1,4 +1,4 @@
1
- import type { CardItemProperty, CardCreateInfo, CardHTML } from '../types';
1
+ import type { CardItemProperty, CardCreateInfo } from '../types';
2
2
  import { SDKItemType, type CardItemOptions } from './types';
3
3
  import { BaseItem } from './base-item';
4
4
  /**
@@ -21,16 +21,12 @@ export declare class CardItem extends BaseItem {
21
21
  */
22
22
  get cardType(): string;
23
23
  set cardType(value: string);
24
- /**
25
- * @description HTML 覆盖层配置
26
- */
27
- get html(): CardHTML | undefined;
28
- set html(value: CardHTML | undefined);
29
24
  /**
30
25
  * @description 位置
31
26
  */
32
27
  get position(): [number, number];
33
28
  set position(value: [number, number]);
29
+ get isAutoScale(): boolean;
34
30
  /**
35
31
  * @description 宽度
36
32
  */
package/dist/sdk.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Player, spec } from './shared';
2
- import type { SDKInputParam, PageConfig, PageData, SetItemPropertyParam, ViewProperty, ViewParam, ExportParam, SDKBackgroundType, SpriteCreateInfo, GroupCreateInfo, ItemCreateInfo, TextCreateInfo, ViewportFitShiftParam, SceneCreaetInfo, VideoCreateInfo, GeneratorCreateInfo, GeneratorResource, VideoGeneratorResource, SpriteGeneratorResource, EffectsCreateInfo, FrameCreateInfo, CardCreateInfo, CardItemTransformInfo, PageAutoLayoutParam } from './types';
2
+ import type { SDKInputParam, PageConfig, PageData, SetItemPropertyParam, ViewProperty, ViewParam, ExportParam, SDKBackgroundType, SpriteCreateInfo, GroupCreateInfo, ItemCreateInfo, TextCreateInfo, ViewportFitShiftParam, SceneCreaetInfo, VideoCreateInfo, GeneratorCreateInfo, GeneratorResource, VideoGeneratorResource, SpriteGeneratorResource, EffectsCreateInfo, FrameCreateInfo, CardCreateInfo, CardHTML, CardItemTransformInfo, PageAutoLayoutParam } from './types';
3
3
  import { SDKItemType } from './sdk-item/types';
4
4
  import type { CardTypeConfig } from './config';
5
5
  import { ItemOrderAction } from './types';
@@ -10,7 +10,7 @@ import { Box2, Vector2 } from './math';
10
10
  import { GizmoOperation, Operation, UndoRedo } from './service/UndoRedo';
11
11
  import { GestureHandlerInteractType, GizmoType, ItemCreateType, SpriteTextInitParam } from './gesture-handler/gizmo';
12
12
  import { AlignType, DistributeType } from './utils/types';
13
- import { SDKItem } from './sdk-item';
13
+ import { SDKItem, type CardItem } from './sdk-item';
14
14
  import type { LoadingGizmoItemOptions, LoadingGizmoTip } from './gesture-handler/gizmo/loading-gizmo';
15
15
  import type { MaskUndoRedoData } from './gesture-handler/gizmo/mask-gizmo';
16
16
  import type { PictureCutUndoRedoData } from './gesture-handler/gizmo/picture-cut-gizmo';
@@ -99,6 +99,7 @@ export declare class SDK {
99
99
  on: <E extends "progress" | "loadingItemChange" | "selectedItemChange" | "preSelectedItemChange" | "selectedViewChange" | "pageDataChange" | "zoomChange" | "itemPropertyChange" | "exportProgress" | "exportDone" | "exportComplete" | "sdkConfigChange" | "cutBoxChange" | "expandBoxChange" | "textInput" | "undoRedoChange" | "maskGizmoUndoRedoChange" | "pictureCutGizmoUndoRedoChange" | "viewportTransform" | "itemOnDragStart" | "itemOnDrag" | "itemOnDragEnd" | "spriteTextClick" | "videoPlay" | "itemCreate" | "cardItemTransformChange" | "viewLost" | "viewRebuildFinish">(eventName: E, listener: import("@galacean/effects").EventEmitterListener<SDKEvents[E]>, options?: import("@galacean/effects").EventEmitterOptions) => () => void;
100
100
  initPlayer(mode: SDKMode): void;
101
101
  setSDKMode(mode: SDKMode): void;
102
+ private syncCanvasLayerOrder;
102
103
  private getInitParam;
103
104
  private initExporter;
104
105
  private initSDK;
@@ -180,6 +181,7 @@ export declare class SDK {
180
181
  cancelExport(): void;
181
182
  loadPageData(data: PageData): Promise<void>;
182
183
  runByPageData(data: PageData): Promise<void>;
184
+ runByCreateInfos(createInfos: ItemCreateInfo[]): Promise<void>;
183
185
  reloadPageDataByScene(scene: string | spec.JSONScene): Promise<void>;
184
186
  /**
185
187
  * @description 新增视图数据
@@ -507,6 +509,49 @@ export declare class SDK {
507
509
  * @returns 是否已注册
508
510
  */
509
511
  isCardTypeRegistered(type: string): boolean;
512
+ /**
513
+ * @description 按 cardType 从注册表解析卡片的 HTML 渲染配置。
514
+ * @param item 卡片元素
515
+ * @returns HTML 渲染配置
516
+ */
517
+ resolveCardHTML(item: CardItem): CardHTML | undefined;
518
+ /**
519
+ * @description 按 cardType 从注册表解析卡片类型配置。
520
+ * @param item 卡片元素
521
+ * @returns 卡片类型配置
522
+ */
523
+ resolveCardTypeConfig(item: CardItem): CardTypeConfig | undefined;
524
+ /**
525
+ * @description 重新解析并挂载指定卡片的 HTML 内容。
526
+ * @description 当 inline/document 内容依赖 extension 或外部状态变化时,可调用此方法刷新 DOM。
527
+ * @param id 卡片元素 ID
528
+ * @returns 是否成功触发刷新
529
+ */
530
+ refreshCardHTML(id: string): boolean;
531
+ /**
532
+ * @description 获取指定 HTML 卡片当前 iframe 的 window。
533
+ * @description 仅 inline/document 或自行渲染 iframe 的 DOM 内容会返回 window。
534
+ * @param id 卡片元素 ID
535
+ * @returns HTML iframe window
536
+ */
537
+ getHtmlCardWindow(id: string): Window | null | undefined;
538
+ /**
539
+ * @description 向指定 HTML 卡片发送增量 patch。
540
+ * @description 当卡片内容配置了 CardHTMLPatchHandler 时,可用于局部更新 HTML,而不必整卡 refresh。
541
+ * @param id 卡片元素 ID
542
+ * @param patch patch 负载,由卡片内容自己的 patch handler 解释
543
+ * @returns 是否被 patch handler 处理
544
+ */
545
+ patchCardHTML(id: string, patch: unknown): boolean;
546
+ /**
547
+ * @description 向指定 HTML 卡片 iframe 派发事件。
548
+ * @description 通过 postMessage 投递事件,跨源/同源行为一致,消息 source 为 vvfx-card-html-event。
549
+ * @param id 卡片元素 ID
550
+ * @param type 事件名称
551
+ * @param detail 事件 detail
552
+ * @returns 是否成功派发或投递
553
+ */
554
+ dispatchHtmlCardEvent(id: string, type: string, detail?: unknown): boolean;
510
555
  /**
511
556
  * @description 创建卡片元素
512
557
  * @description 底层以透明 SpriteItem 形式渲染,支持 cardType 属性
package/dist/types.d.ts CHANGED
@@ -82,6 +82,42 @@ export type CardHTMLContentCleanup = (container: HTMLElement) => void;
82
82
  * @description Card HTML 覆盖层 DOM 渲染函数。SDK 会传入 overlay 容器;卸载逻辑请使用 content.cleanup。
83
83
  */
84
84
  export type CardHTMLDOMRenderer = (container: HTMLElement) => void;
85
+ export type CardHTMLPatchContext = {
86
+ /**
87
+ * @description 当前卡片元素 ID。
88
+ */
89
+ id: string;
90
+ /**
91
+ * @description 当前 HTML 覆盖层配置。
92
+ */
93
+ html: CardHTML;
94
+ /**
95
+ * @description 当前 HTML 内容配置。
96
+ */
97
+ content: CardHTMLContent;
98
+ /**
99
+ * @description 当前内容挂载容器;未完成挂载时可能不存在。
100
+ */
101
+ container?: HTMLElement;
102
+ /**
103
+ * @description 当前内容 iframe window;host DOM 内容或尚未完成 iframe 加载时可能不存在。
104
+ */
105
+ contentWindow?: Window | null;
106
+ /**
107
+ * @description 重新解析并挂载当前卡片 HTML。
108
+ */
109
+ refresh: () => void;
110
+ };
111
+ export type CardHTMLPatchHandler = (patch: unknown, context: CardHTMLPatchContext) => boolean | undefined;
112
+ /**
113
+ * @description SDK#dispatchHtmlCardEvent 通过 postMessage 投递给 HTML iframe 的消息结构。
114
+ */
115
+ export type CardHTMLWindowEventMessage = {
116
+ source: 'vvfx-card-html-event';
117
+ type: string;
118
+ detail?: unknown;
119
+ payload?: unknown;
120
+ };
85
121
  /**
86
122
  * @description Card HTML 单文件字符串内容。SDK 会通过 iframe srcdoc 渲染。
87
123
  */
@@ -94,6 +130,18 @@ export type CardHTMLInlineContent = {
94
130
  * @description HTML 字符串内容
95
131
  */
96
132
  html: string;
133
+ /**
134
+ * @description iframe sandbox 配置;true/undefined 使用 SDK 默认沙箱 allow-scripts。
135
+ */
136
+ sandbox?: boolean | string;
137
+ /**
138
+ * @description 是否允许 iframe 内 a[href] 执行默认跳转;默认 false,会阻止 Agent 生成 HTML 中的链接把卡片导航走。
139
+ */
140
+ allowAnchorNavigation?: boolean;
141
+ /**
142
+ * @description 增量 patch 处理器。可用于将运行时事件派发给 iframe,或直接更新外部状态后触发刷新;返回 false 表示未处理,返回 true 或无返回值表示已接收。
143
+ */
144
+ patch?: CardHTMLPatchHandler;
97
145
  /**
98
146
  * @description 内容卸载时调用的清理函数;SDK 会传入当前内容挂载容器。
99
147
  */
@@ -115,6 +163,10 @@ export type CardHTMLDOMRendererContent = {
115
163
  * @description DOM 渲染函数
116
164
  */
117
165
  render: CardHTMLDOMRenderer;
166
+ /**
167
+ * @description 增量 patch 处理器。适合 React/Vue/原生 DOM 内容接收局部更新;返回 false 表示未处理,返回 true 或无返回值表示已接收。
168
+ */
169
+ patch?: CardHTMLPatchHandler;
118
170
  /**
119
171
  * @description 内容卸载时调用的清理函数;SDK 会传入 render 接收到的同一个容器。
120
172
  */
@@ -161,6 +213,10 @@ export type CardHTMLDocumentContent = {
161
213
  * @description iframe sandbox 配置;true/undefined 使用 SDK 默认沙箱 allow-scripts;false 不加 sandbox,风险较高,不建议用于不可信内容。
162
214
  */
163
215
  sandbox?: boolean | string;
216
+ /**
217
+ * @description 是否允许 iframe 内 a[href] 执行默认跳转;默认 false,会阻止 Agent 生成 HTML 中的链接把卡片导航走。
218
+ */
219
+ allowAnchorNavigation?: boolean;
164
220
  /**
165
221
  * @description 是否允许 iframe 通过 postMessage 与宿主通信;默认 false。
166
222
  */
@@ -169,6 +225,10 @@ export type CardHTMLDocumentContent = {
169
225
  * @description iframe 消息回调。仅接收来自当前 iframe 且 source 为 vvfx-card-html 的消息。
170
226
  */
171
227
  onMessage?: (message: CardHTMLDocumentMessage) => void;
228
+ /**
229
+ * @description 增量 patch 处理器。可结合 contentWindow.postMessage 投递给文档运行时;返回 false 表示未处理,返回 true 或无返回值表示已接收。
230
+ */
231
+ patch?: CardHTMLPatchHandler;
172
232
  /**
173
233
  * @description 内容卸载时调用的清理函数;SDK 会传入当前内容挂载容器。
174
234
  */
@@ -204,6 +264,17 @@ export type CardHTMLShellContent = {
204
264
  */
205
265
  render: CardHTMLShellRenderer;
206
266
  };
267
+ export type CardHTMLRootStyle = Record<string, string | number | undefined>;
268
+ export type CardHTMLRootConfig = {
269
+ /**
270
+ * @description 追加到 HTML 内容根节点的 className。
271
+ */
272
+ className?: string;
273
+ /**
274
+ * @description 应用到 HTML 内容根节点的内联样式。
275
+ */
276
+ style?: CardHTMLRootStyle;
277
+ };
207
278
  /**
208
279
  * @description Card HTML 覆盖层配置。
209
280
  */
@@ -216,23 +287,19 @@ export type CardHTML = {
216
287
  * @description HTML 外壳,用于定制承载 content 的容器。
217
288
  */
218
289
  shell?: CardHTMLShellContent;
290
+ /**
291
+ * @description HTML 内容根节点样式配置,用于按内容实例设置 className 或内联 style。
292
+ */
293
+ root?: CardHTMLRootConfig;
219
294
  };
220
295
  /**
221
296
  * @description Card 卡片元素属性
222
297
  */
223
298
  export type CardItemProperty = BaseItemProperty & {
224
299
  /**
225
- * @description 卡片类型(动态配置,需在 SDK.config.itemConfig.cardConfig.cardTypes 中注册)
300
+ * @description 卡片类型(动态配置,需通过 SDK.registerCardType/registerCardTypes 注册)
226
301
  */
227
302
  cardType: string;
228
- /**
229
- * @description 是否根据 HTML 挂载内容的自然高度自动更新卡片高度
230
- */
231
- autoHeight?: boolean;
232
- /**
233
- * @description HTML 覆盖层配置;存在该字段时由 DOM overlay 渲染
234
- */
235
- html?: CardHTML;
236
303
  };
237
304
  /**
238
305
  * @description Frame 画板元素布局模式
@@ -931,7 +998,7 @@ export type CardItemTransformInfo = {
931
998
  size: [number, number];
932
999
  };
933
1000
  /**
934
- * @description 卡片类型(动态配置,需在 SDK.config.itemConfig.cardConfig.cardTypes 中注册)
1001
+ * @description 卡片类型(动态配置,需通过 SDK.registerCardType/registerCardTypes 注册)
935
1002
  */
936
1003
  export type CardType = string;
937
1004
  /**
@@ -974,10 +1041,6 @@ export type CardCreateInfo = {
974
1041
  * @description 卡片元素像素高度
975
1042
  */
976
1043
  height: number;
977
- /**
978
- * @description 是否根据 HTML 挂载内容的自然高度自动更新卡片高度
979
- */
980
- autoHeight?: boolean;
981
1044
  /**
982
1045
  * @description 卡片元素位置
983
1046
  */
@@ -990,10 +1053,6 @@ export type CardCreateInfo = {
990
1053
  * @description 卡片元素缩放
991
1054
  */
992
1055
  scale?: [number, number];
993
- /**
994
- * @description HTML 覆盖层配置;存在该字段时由 DOM overlay 渲染
995
- */
996
- html?: CardHTML;
997
1056
  };
998
1057
  };
999
1058
  /**
@@ -88,6 +88,10 @@ export declare class PageDataUtils {
88
88
  * 2. 单个元素多个属性: { itemId, type, property }
89
89
  */
90
90
  setItemProperty<T extends SDKItemType>(param: SetItemPropertyParam<T>): Promise<void>;
91
+ /**
92
+ * @description 设置元素extension字段
93
+ */
94
+ setItemExtension(itemId: string, extension: Record<string, any>): void;
91
95
  /**
92
96
  * @description 场景 1: 设置单个元素的单个属性
93
97
  */
@@ -342,6 +346,13 @@ export declare class PageDataUtils {
342
346
  * @param targetParentVFXItem 目标父 VFXItem(移入 Frame 时为 compositionItem,移出 Frame 时为 composition.rootItem)
343
347
  */
344
348
  getItemTransformUnderParent(itemId: string, targetParentVFXItem: VFXItem): MoveItemTransformOptions | undefined;
349
+ /**
350
+ * @description 修改画板元素大小
351
+ * @param id 元素id
352
+ * @param size 目标大小 [width, height]
353
+ * @param translation 位置偏移补偿(可选,用于保持拖拽角点固定)
354
+ */
355
+ resizeCardItem(id: string, size: spec.vec2, translation?: Vector3): void;
345
356
  /**
346
357
  * @description 修改画板元素大小
347
358
  * @param id 元素id
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vvfx/sdk",
3
3
  "description": "TODO",
4
- "version": "0.2.3",
4
+ "version": "0.2.4",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -68,7 +68,7 @@
68
68
  "prebuild": "pnpm clean",
69
69
  "build": "pnpm build:declaration && pnpm build:module",
70
70
  "build:module": "rollup -c --bundleConfigAsCjs",
71
- "build:declaration": "tsc -d --emitDeclarationOnly",
71
+ "build:declaration": "tsc -p tsconfig.build.json",
72
72
  "clean": "rimraf dist *.tsbuildinfo",
73
73
  "test": "vitest run"
74
74
  }