@vvfx/sdk 0.2.2-beta.11 → 0.2.2-beta.13

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/sdk.d.ts CHANGED
@@ -527,6 +527,30 @@ export declare class SDK {
527
527
  * @returns 是否成功触发刷新
528
528
  */
529
529
  refreshCardHTML(id: string): boolean;
530
+ /**
531
+ * @description 获取指定 HTML 卡片当前 iframe 的 window。
532
+ * @description 仅 inline/document 或自行渲染 iframe 的 DOM 内容会返回 window。
533
+ * @param id 卡片元素 ID
534
+ * @returns HTML iframe window
535
+ */
536
+ getHtmlCardWindow(id: string): Window | null | undefined;
537
+ /**
538
+ * @description 向指定 HTML 卡片发送增量 patch。
539
+ * @description 当卡片内容配置了 CardHTMLPatchHandler 时,可用于局部更新 HTML,而不必整卡 refresh。
540
+ * @param id 卡片元素 ID
541
+ * @param patch patch 负载,由卡片内容自己的 patch handler 解释
542
+ * @returns 是否被 patch handler 处理
543
+ */
544
+ patchCardHTML(id: string, patch: unknown): boolean;
545
+ /**
546
+ * @description 向指定 HTML 卡片 iframe 派发事件。
547
+ * @description 通过 postMessage 投递事件,跨源/同源行为一致,消息 source 为 vvfx-card-html-event。
548
+ * @param id 卡片元素 ID
549
+ * @param type 事件名称
550
+ * @param detail 事件 detail
551
+ * @returns 是否成功派发或投递
552
+ */
553
+ dispatchHtmlCardEvent(id: string, type: string, detail?: unknown): boolean;
530
554
  /**
531
555
  * @description 创建卡片元素
532
556
  * @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,10 @@ export type CardHTMLInlineContent = {
94
130
  * @description HTML 字符串内容
95
131
  */
96
132
  html: string;
133
+ /**
134
+ * @description 增量 patch 处理器。可用于将运行时事件派发给 iframe,或直接更新外部状态后触发刷新;返回 false 表示未处理,返回 true 或无返回值表示已接收。
135
+ */
136
+ patch?: CardHTMLPatchHandler;
97
137
  /**
98
138
  * @description 内容卸载时调用的清理函数;SDK 会传入当前内容挂载容器。
99
139
  */
@@ -115,6 +155,10 @@ export type CardHTMLDOMRendererContent = {
115
155
  * @description DOM 渲染函数
116
156
  */
117
157
  render: CardHTMLDOMRenderer;
158
+ /**
159
+ * @description 增量 patch 处理器。适合 React/Vue/原生 DOM 内容接收局部更新;返回 false 表示未处理,返回 true 或无返回值表示已接收。
160
+ */
161
+ patch?: CardHTMLPatchHandler;
118
162
  /**
119
163
  * @description 内容卸载时调用的清理函数;SDK 会传入 render 接收到的同一个容器。
120
164
  */
@@ -169,6 +213,10 @@ export type CardHTMLDocumentContent = {
169
213
  * @description iframe 消息回调。仅接收来自当前 iframe 且 source 为 vvfx-card-html 的消息。
170
214
  */
171
215
  onMessage?: (message: CardHTMLDocumentMessage) => void;
216
+ /**
217
+ * @description 增量 patch 处理器。可结合 contentWindow.postMessage 投递给文档运行时;返回 false 表示未处理,返回 true 或无返回值表示已接收。
218
+ */
219
+ patch?: CardHTMLPatchHandler;
172
220
  /**
173
221
  * @description 内容卸载时调用的清理函数;SDK 会传入当前内容挂载容器。
174
222
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vvfx/sdk",
3
3
  "description": "TODO",
4
- "version": "0.2.2-beta.11",
4
+ "version": "0.2.2-beta.13",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",