@vvfx/sdk 0.2.2 → 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.
package/dist/config.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import { ExportMediaInitOptions } from './exporter';
2
2
  import { GlobalLayoutMode } from './utils';
3
+ import type { CardHTML } from './types';
4
+ import type { CardItem } from './sdk-item/card-item';
3
5
  export type SDKMode = 'editor' | 'template';
6
+ export type CardTypeHTMLResolver = (item: CardItem) => CardHTML | undefined;
7
+ export type CardAutoHeightAnchor = 'top' | 'center';
4
8
  /**
5
9
  * @description SDK功能配置
6
10
  */
@@ -136,6 +140,30 @@ export type CardTypeConfig = {
136
140
  * @description TransformGizmo 左上角展示的 icon URL
137
141
  */
138
142
  iconUrl: string;
143
+ /**
144
+ * @description 卡片类型对应的运行时 HTML 渲染配置;函数不会进入序列化数据,恢复时由 cardType 动态解析。
145
+ */
146
+ html?: CardTypeHTMLResolver;
147
+ /**
148
+ * @description 是否根据 HTML 挂载内容的自然高度自动更新卡片高度
149
+ */
150
+ autoHeight?: boolean;
151
+ /**
152
+ * @description autoHeight 更新卡片高度时的锚点。top 保持上边缘不动,center 保持中心点不动。未配置时默认 top。
153
+ */
154
+ autoHeightAnchor?: CardAutoHeightAnchor;
155
+ /**
156
+ * @description HTML 内容是否跟随卡片 scale 缩放,关闭后 HTML 按最终显示尺寸重新布局
157
+ */
158
+ autoScale?: boolean;
159
+ /**
160
+ * @description 是否启用编辑态交互。未配置时默认 true;只有显式 false 时,卡片默认直接交互且不进入编辑态。
161
+ */
162
+ editable?: boolean;
163
+ /**
164
+ * @description HTML 内容中可在非编辑态直接响应事件的额外 CSS 选择器;会与 SDK 默认交互选择器合并。
165
+ */
166
+ htmlInteractionSelectors?: string[];
139
167
  };
140
168
  /**
141
169
  * @description 卡片元素参数配置
@@ -146,7 +174,7 @@ export type CardConfig = {
146
174
  */
147
175
  backgroundColor: [number, number, number, number];
148
176
  /**
149
- * @description 注册的卡片类型列表,支持动态配置
177
+ * @description 注册的卡片类型列表,支持通过 registerCardType/registerCardTypes 动态配置
150
178
  * 每个条目包含 type 标识、显示名称和图标 URL
151
179
  */
152
180
  cardTypes: CardTypeConfig[];
@@ -28,7 +28,7 @@ export declare class MaskGizmo extends Gizmo {
28
28
  private _config;
29
29
  private boxGraphics;
30
30
  type: GizmoType;
31
- mode: 'paint' | 'erase';
31
+ mode: 'paint' | 'erase' | 'box-erase' | 'box-paint';
32
32
  /**
33
33
  * 蒙版工具独立的撤销重做实例
34
34
  */
@@ -37,6 +37,10 @@ export declare class MaskGizmo extends Gizmo {
37
37
  * 存储绘画开始前的数据,用于 undoRedo
38
38
  */
39
39
  private _oldLines;
40
+ /**
41
+ * 框选擦除进行中标记(按下到松开之间),用于实时选框描边的显示控制
42
+ */
43
+ private _isBoxErasing;
40
44
  /**
41
45
  * 鼠标状态绘制结果
42
46
  */
@@ -52,9 +56,17 @@ export declare class MaskGizmo extends Gizmo {
52
56
  set config(config: Partial<MaskGizmoConfig>);
53
57
  /**
54
58
  * 设置模式
55
- * @param mode 模式类型:'paint' 表示涂抹,'erase' 表示擦除
59
+ * @param mode 模式类型:'paint' 笔刷涂抹、'erase' 笔刷逐笔擦除、'box-erase' 框选擦除、'box-paint' 框选涂抹
60
+ */
61
+ setMode(mode: 'paint' | 'erase' | 'box-erase' | 'box-paint'): void;
62
+ /**
63
+ * @description 判断点是否在包围盒内
64
+ */
65
+ private _isPointInBox;
66
+ /**
67
+ * @description 将屏幕坐标转换为包围盒内的归一化坐标 [0,1](钳制在范围内)
56
68
  */
57
- setMode(mode: 'paint' | 'erase'): void;
69
+ private _toNormalized;
58
70
  initialize(): void;
59
71
  preparationAction(event: MouseEvent): GizmoType | undefined;
60
72
  preAction(event: MouseEvent): GizmoType | undefined;
@@ -85,6 +85,10 @@ export type MaskResult = {
85
85
  brushSize: number;
86
86
  points: Vector2[];
87
87
  type?: 'paint' | 'erase';
88
+ /**
89
+ * @description 形状类型:'stroke' 折线(默认),'rect' 矩形框选(points=[起点, 终点])
90
+ */
91
+ shape?: 'stroke' | 'rect';
88
92
  }[];
89
93
  };
90
94
  /**
@@ -396,7 +400,7 @@ export type InsertPosition = {
396
400
  siblingId?: string;
397
401
  };
398
402
  export type GizmoType = 'null' | 'selector' | 'transform' | 'control' | 'adsorption' | 'preference' | 'picture-cut' | 'text' | 'mask' | 'loading' | 'picture-expand' | 'sprite-text-edit' | 'icon' | 'item-create';
399
- export type GestureCursorType = 'normal' | 'rotation' | 'scale' | 'text-rotation' | 'circle' | 'hand' | 'active-hand' | 'pointer' | 'text-create' | 'frame-create';
403
+ export type GestureCursorType = 'normal' | 'rotation' | 'scale' | 'text-rotation' | 'circle' | 'hand' | 'active-hand' | 'pointer' | 'text-create' | 'frame-create' | 'box-select';
400
404
  export type TransformType = 'null' | 'translation' | 'rotation' | 'scale';
401
405
  export type GestureHandlerInteractType = 'select' | 'hand';
402
406
  export type ControlGizmoInteractionType = 'mouse' | 'wheel';
@@ -107,7 +107,7 @@ export declare class GestureHandler {
107
107
  closeMaskGizmo(): void;
108
108
  setMaskGizmoConfig(config: Partial<MaskGizmoConfig>): void;
109
109
  getMask(): string | null | undefined;
110
- setMaskGizmoMode(mode: 'paint' | 'erase'): void;
110
+ setMaskGizmoMode(mode: 'paint' | 'erase' | 'box-erase' | 'box-paint'): void;
111
111
  openLoadingGizmo(id: string, options?: {
112
112
  loadingBox?: Box2;
113
113
  clearSelected?: boolean;
@@ -0,0 +1 @@
1
+ export declare function withCardHTMLAnchorNavigationGuard(html: string, allowAnchorNavigation?: boolean): string;
@@ -4,10 +4,15 @@ export type CardHTMLAutoHeightMessage = {
4
4
  id: string;
5
5
  height: number;
6
6
  };
7
+ export type CardHTMLAutoHeightRequest = {
8
+ source: 'vvfx-card-html-auto-height-request';
9
+ id: string;
10
+ };
7
11
  export type CardHTMLAutoHeightOptions = {
8
12
  autoHeightId?: string;
9
13
  onAutoHeight?: (height: number) => void;
10
14
  };
11
15
  export declare function createAutoHeightMessageListener(iframe: HTMLIFrameElement, options?: CardHTMLAutoHeightOptions): CardHTMLRenderCleanup;
12
16
  export declare function isCardHTMLAutoHeightMessage(data: unknown, id: string): data is CardHTMLAutoHeightMessage;
17
+ export declare function requestCardHTMLAutoHeight(iframe: HTMLIFrameElement, id: string): void;
13
18
  export declare function withCardHTMLAutoHeightBridge(html: string, id?: string): string;
@@ -1,14 +1,20 @@
1
1
  import type { Box2 } from '../math';
2
2
  import { type SnapdomOptions } from '@zumer/snapdom';
3
+ import type { CardAutoHeightAnchor, CardTypeConfig } from '../config';
3
4
  import type { EventEmitter } from '../shared';
4
5
  import type { SDKEvents } from '../sdk';
5
6
  import { type SDKItem } from '../sdk-item';
7
+ import type { CardHTML } from '../types';
6
8
  type CardRasterizeOptions = {
7
9
  width: number;
8
10
  height: number;
9
11
  pixelRatio?: number;
10
12
  snapdomOptions?: SnapdomOptions;
11
13
  };
14
+ type SetCardItemHeightOptions = {
15
+ anchor: CardAutoHeightAnchor;
16
+ previousHeight: number;
17
+ };
12
18
  type HTMLOverlayManagerOptions = {
13
19
  container: HTMLElement;
14
20
  emitter: EventEmitter<SDKEvents>;
@@ -23,47 +29,102 @@ type HTMLOverlayManagerOptions = {
23
29
  translation: [number, number];
24
30
  }) => void;
25
31
  viewportFit: (box: Box2) => void;
26
- setCardItemHeight: (id: string, height: number) => void;
32
+ setCardItemHeight: (id: string, height: number, options: SetCardItemHeightOptions) => void;
33
+ getSelectedItemIds: () => string[];
34
+ setSelectedItemIds: (ids: string[]) => void;
35
+ getPreSelectedItemId: () => string | undefined;
36
+ getSelectionEdgeStyle: () => {
37
+ color: number;
38
+ alpha: number;
39
+ width: number;
40
+ };
41
+ getPreSelectionEdgeStyle: () => {
42
+ color: number;
43
+ alpha: number;
44
+ width: number;
45
+ };
46
+ getCanvasEventTarget?: () => HTMLElement | undefined;
47
+ resolveCardHTML: (item: SDKItem) => CardHTML | undefined;
48
+ resolveCardTypeConfig: (item: SDKItem) => CardTypeConfig | undefined;
27
49
  };
28
50
  export declare class HTMLOverlayManager {
29
51
  private options;
30
52
  private eventCleanups;
53
+ private htmlRootConfigCleanups;
54
+ private pendingContentInteractionEvent?;
55
+ private contentInteractionFrame?;
31
56
  private state;
32
57
  constructor(options: HTMLOverlayManagerOptions);
33
58
  attach(): void;
59
+ get layerElement(): HTMLElement | undefined;
34
60
  dispose(): void;
35
61
  scheduleRender(): void;
62
+ invalidateCardHTML(id: string): void;
63
+ getHtmlCardWindow(id: string): Window | null | undefined;
64
+ patchCardHTML(id: string, patch: unknown): boolean;
65
+ dispatchHtmlCardEvent(id: string, type: string, detail?: unknown): boolean;
36
66
  rasterizeCard(id: string, options: CardRasterizeOptions): Promise<string | undefined>;
37
67
  private initEvents;
38
68
  private initDOMEvents;
39
69
  private handleContainerDoubleClick;
40
70
  private handleContainerMouseDown;
71
+ private selectHTMLInteractionCard;
41
72
  private handleContainerMouseMove;
42
73
  private handleContainerMouseLeave;
74
+ private isMouseLeaveWithinContainer;
75
+ private handleContainerContextMenu;
76
+ private isHTMLContextMenuEvent;
43
77
  private handleViewportTransform;
44
78
  private render;
45
79
  private syncOverlayOrder;
80
+ private getOrCreateSelectionLayer;
46
81
  private renderFrameOverlays;
47
82
  private getOrCreateFrameOverlay;
48
83
  private getOrCreateOverlay;
84
+ private getOrCreateSelectionOverlay;
85
+ private syncOverlaySelection;
86
+ private getSelectionBoxShadow;
87
+ private getPreSelectionBoxShadow;
49
88
  private getHTMLCardIdByEvent;
50
89
  private getHoverShellInteractiveIdByEvent;
90
+ private syncActiveContentInteraction;
91
+ private scheduleActiveContentInteractionSync;
92
+ private setActiveContentInteraction;
93
+ private shouldKeepActiveContentInteractionForFocusedElement;
94
+ private resolveHTMLInteractionTarget;
95
+ private getActiveSubtreeInteractionAtEvent;
96
+ private resolveContentInteractionZone;
97
+ private getContentInteractionZones;
98
+ private getContentInteractiveSelector;
99
+ private isContentInteractionDisabled;
100
+ private getContentInteractionZoneMode;
101
+ private invalidateContentInteractionZones;
102
+ private observeContentInteractionZoneResizes;
51
103
  private getLayerPoint;
52
104
  private getOrCreateContentOverlay;
53
105
  private createContentScaleOverlay;
54
106
  private syncContentScale;
107
+ private requestAutoHeightFromIframes;
55
108
  private syncContentInteraction;
109
+ private syncContentInteractionZones;
110
+ private clearContentInteractionState;
56
111
  private syncShellInteraction;
57
112
  private enterEditing;
58
113
  private exitEditing;
114
+ private isEditableCard;
59
115
  private getEditingFitZoom;
60
116
  private isEventInsideOverlay;
61
117
  private renderOverlayHTML;
118
+ private createPatchContext;
119
+ private observeContentInteractionZones;
120
+ private applyHTMLRootConfig;
121
+ private makeSelectionOverlayTransparent;
62
122
  private renderOverlayContent;
63
123
  private chainCleanups;
64
124
  private cleanupOverlayContent;
65
125
  private removeOverlay;
66
126
  private syncAutoHeight;
127
+ private ensureAutoHeightMode;
67
128
  private createAutoHeightObserver;
68
129
  private scheduleAutoHeightMeasure;
69
130
  private measureAutoHeight;
@@ -72,6 +133,10 @@ export declare class HTMLOverlayManager {
72
133
  private getChildrenNaturalHeight;
73
134
  private cleanupAutoHeight;
74
135
  private applyAutoHeight;
136
+ private getAutoHeightAnchor;
137
+ private getAutoHeightItemHeight;
75
138
  private isAutoHeightMessage;
139
+ private isAutoHeightEnabled;
140
+ private isAutoScaleEnabled;
76
141
  }
77
142
  export {};
@@ -4,9 +4,11 @@ export type CardOverlayBoxStyle = {
4
4
  top: string;
5
5
  width: string;
6
6
  height: string;
7
+ contentWidth: number;
8
+ contentHeight: number;
7
9
  transform: string;
8
10
  };
9
- export declare function getCardOverlayBoxStyle(box: Box2, width: number, height: number, offsetX?: number, offsetY?: number): CardOverlayBoxStyle;
11
+ export declare function getCardOverlayBoxStyle(box: Box2, width: number, height: number, offsetX?: number, offsetY?: number, _autoScale?: boolean): CardOverlayBoxStyle;
10
12
  export declare function isPointInCardOverlayBox(box: Box2, point: {
11
13
  x: number;
12
14
  y: number;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type { SDKOptions, SDKInputParam, PageData, PageProperty, ViewProperty, ActiveData, ViewParam, BaseItemProperty, SpriteItemProperty, TextItemProperty, VideoItemProperty, GeneratorItemProperty, FrameItemProperty, FrameLayoutMode, SpriteCreateInfo, TextCreateInfo, GroupCreateInfo, VideoCreateInfo, GeneratorCreateInfo, EffectsCreateInfo, FrameCreateInfo, CardCreateInfo, CardItemProperty, CardItemTransformInfo, ItemCreateInfo, } from './types';
2
- export type { CardTypeConfig, CardConfig } from './config';
1
+ export type { SDKOptions, SDKInputParam, PageData, PageProperty, ViewProperty, ActiveData, ViewParam, BaseItemProperty, SpriteItemProperty, TextItemProperty, VideoItemProperty, GeneratorItemProperty, FrameItemProperty, FrameLayoutMode, SpriteCreateInfo, TextCreateInfo, GroupCreateInfo, VideoCreateInfo, GeneratorCreateInfo, EffectsCreateInfo, FrameCreateInfo, CardCreateInfo, CardItemProperty, CardItemTransformInfo, CardHTML, CardHTMLContent, CardHTMLInlineContent, CardHTMLDOMRendererContent, CardHTMLDocumentContent, CardHTMLDocumentMessage, CardHTMLShellContent, CardHTMLShellRenderer, CardHTMLShellRendererContext, CardHTMLShellRendererResult, CardHTMLDOMRenderer, CardHTMLContentCleanup, CardHTMLRenderCleanup, CardHTMLPatchContext, CardHTMLPatchHandler, CardHTMLWindowEventMessage, CardHTMLRootConfig, CardHTMLRootStyle, ItemCreateInfo, } from './types';
2
+ export type { SDKConfig, SDKMode, CardTypeConfig, CardConfig, CardAutoHeightAnchor, CardTypeHTMLResolver, } from './config';
3
3
  export type { SDKItem } from './sdk-item';
4
4
  export { BaseItem, SpriteItem, TextItem, VideoItem, GroupItem, GeneratorItem, EffectsItem, FrameItem, CardItem, isBaseItem, isSpriteItem, isTextItem, isVideoItem, isGroupItem, isGeneratorItem, isEffectsItem, isFrameItem, isCardItem, SDKItemType, } from './sdk-item';
5
5
  export type { SDKItemOptions, SpriteItemOptions, TextItemOptions, VideoItemOptions, GroupItemOptions, GeneratorItemOptions, EffectsItemOptions, FrameItemOptions, CardItemOptions, } from './sdk-item';