@vvfx/sdk 0.2.8 → 0.2.10
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.js +231 -0
- package/dist/exporter/config.js +18 -0
- package/dist/exporter/const.js +71 -0
- package/dist/exporter/export-media.js +878 -0
- package/dist/exporter/exporter.js +121 -0
- package/dist/exporter/index.js +1 -0
- package/dist/exporter/types.js +1 -0
- package/dist/exporter/utils.js +190 -0
- package/dist/exporter/wav-audio.js +50 -0
- package/dist/gesture-handler/gizmo/adsorption-gizmo.js +227 -0
- package/dist/gesture-handler/gizmo/control-gizmo.js +149 -0
- package/dist/gesture-handler/gizmo/gizmo.js +17 -0
- package/dist/gesture-handler/gizmo/icon-gizmo.js +189 -0
- package/dist/gesture-handler/gizmo/index.js +6 -0
- package/dist/gesture-handler/gizmo/item-create-gizmo.js +256 -0
- package/dist/gesture-handler/gizmo/loading-gizmo.js +320 -0
- package/dist/gesture-handler/gizmo/mask-gizmo.js +648 -0
- package/dist/gesture-handler/gizmo/picture-cut-gizmo.js +550 -0
- package/dist/gesture-handler/gizmo/picture-expand-gizmo.js +491 -0
- package/dist/gesture-handler/gizmo/preference-gizmo.js +148 -0
- package/dist/gesture-handler/gizmo/selector-gizmo.d.ts +1 -1
- package/dist/gesture-handler/gizmo/selector-gizmo.js +468 -0
- package/dist/gesture-handler/gizmo/sprite-text-edit-gizmo.js +247 -0
- package/dist/gesture-handler/gizmo/text-gizmo.js +1033 -0
- package/dist/gesture-handler/gizmo/transform-gizmo.js +1199 -0
- package/dist/gesture-handler/gizmo/type.js +18 -0
- package/dist/gesture-handler/index.js +3 -0
- package/dist/gesture-handler/src/gesture-handler.js +770 -0
- package/dist/gesture-handler/src/icons.js +24 -0
- package/dist/gesture-handler/utils.js +40 -0
- package/dist/html-overlay/anchor-navigation-runtime.js +27 -0
- package/dist/html-overlay/auto-height-layout.d.ts +6 -0
- package/dist/html-overlay/auto-height-layout.js +7 -0
- package/dist/html-overlay/auto-height-runtime.js +132 -0
- package/dist/html-overlay/document-runtime.js +71 -0
- package/dist/html-overlay/document-transform.js +96 -0
- package/dist/html-overlay/dom-order.js +8 -0
- package/dist/html-overlay/host-message-runtime.js +24 -0
- package/dist/html-overlay/html-capture-runtime.js +282 -0
- package/dist/html-overlay/html-viewport-style.js +10 -0
- package/dist/html-overlay/index.js +1 -0
- package/dist/html-overlay/manager.d.ts +1 -0
- package/dist/html-overlay/manager.js +1677 -0
- package/dist/html-overlay/mime-utils.js +21 -0
- package/dist/html-overlay/overlay-transform.js +57 -0
- package/dist/html-overlay/path-utils.js +35 -0
- package/dist/html-overlay/shell-runtime.js +12 -0
- package/dist/index.cjs +34 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -75311
- package/dist/index.mjs +75337 -0
- package/dist/index.mjs.map +1 -0
- package/dist/layer-order.js +8 -0
- package/dist/math/box2.js +396 -0
- package/dist/math/circle.js +131 -0
- package/dist/math/euler.js +35 -0
- package/dist/math/index.js +13 -0
- package/dist/math/line2.js +153 -0
- package/dist/math/line3.js +36 -0
- package/dist/math/matrix4.js +207 -0
- package/dist/math/plane.js +52 -0
- package/dist/math/quaternion.js +3 -0
- package/dist/math/ray-caster.js +25 -0
- package/dist/math/ray.js +47 -0
- package/dist/math/type.js +1 -0
- package/dist/math/utils.js +77 -0
- package/dist/math/vector2.js +70 -0
- package/dist/math/vector3.js +60 -0
- package/dist/screen-shot/index.js +1 -0
- package/dist/screen-shot/screen-shot.js +113 -0
- package/dist/sdk-item/base-item.js +160 -0
- package/dist/sdk-item/card-item.js +131 -0
- package/dist/sdk-item/effects-item.js +144 -0
- package/dist/sdk-item/frame-item.js +217 -0
- package/dist/sdk-item/generator-item.js +188 -0
- package/dist/sdk-item/group-item.js +116 -0
- package/dist/sdk-item/index.js +39 -0
- package/dist/sdk-item/sprite-item.js +147 -0
- package/dist/sdk-item/text-item.js +223 -0
- package/dist/sdk-item/types.d.ts +1 -1
- package/dist/sdk-item/types.js +15 -0
- package/dist/sdk-item/video-item.js +174 -0
- package/dist/sdk.js +1908 -0
- package/dist/service/UndoRedo.js +79 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +2 -0
- package/dist/shared/player.d.ts +1 -1
- package/dist/shared/player.js +9 -0
- package/dist/shared/spec.d.ts +1 -0
- package/dist/shared/spec.js +1 -0
- package/dist/size-adapte/index.js +1 -0
- package/dist/size-adapte/size-adapt.js +395 -0
- package/dist/types.d.ts +5 -1
- package/dist/types.js +17 -0
- package/dist/utils/background-manager.js +189 -0
- package/dist/utils/common-utils.js +183 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/interaction-utils.js +205 -0
- package/dist/utils/json-data-utils.js +1529 -0
- package/dist/utils/layout-utils.js +1217 -0
- package/dist/utils/page-data-utils.js +5397 -0
- package/dist/utils/player-data-utils.js +48 -0
- package/dist/utils/types.js +8 -0
- package/dist/wireframe/common/box.js +18 -0
- package/dist/wireframe/common/dashed-line.js +21 -0
- package/dist/wireframe/common/line.js +17 -0
- package/dist/wireframe/common/pixi-ext.js +1 -0
- package/dist/wireframe/common/pixi.js +31 -0
- package/dist/wireframe/index.js +4 -0
- package/package.json +10 -3
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { FrameLayoutMode } from '../types';
|
|
2
|
+
import { SDKItemType } from './types';
|
|
3
|
+
import { BaseItem } from './base-item';
|
|
4
|
+
import { deepClone } from '../utils/common-utils';
|
|
5
|
+
import { generateGUID } from '../shared';
|
|
6
|
+
/**
|
|
7
|
+
* @description 画板/框架元素 SDKItem 类
|
|
8
|
+
* @description 支持自动布局和自由布局两种模式
|
|
9
|
+
* @description 底层以 composition 形式渲染
|
|
10
|
+
*/
|
|
11
|
+
export class FrameItem extends BaseItem {
|
|
12
|
+
/**
|
|
13
|
+
* @description 元素类型
|
|
14
|
+
*/
|
|
15
|
+
type = SDKItemType.FRAME;
|
|
16
|
+
/**
|
|
17
|
+
* @description 预合成元素ID
|
|
18
|
+
*/
|
|
19
|
+
subCompositionItemId;
|
|
20
|
+
/**
|
|
21
|
+
* @description 元素属性
|
|
22
|
+
*/
|
|
23
|
+
property;
|
|
24
|
+
constructor(options) {
|
|
25
|
+
super(options);
|
|
26
|
+
this.subCompositionItemId = '';
|
|
27
|
+
// 初始化属性
|
|
28
|
+
this.property = {
|
|
29
|
+
position: options.property?.position ?? [0, 0],
|
|
30
|
+
rotation: options.property?.rotation ?? [0, 0, 0],
|
|
31
|
+
width: options.property?.width ?? 0,
|
|
32
|
+
height: options.property?.height ?? 0,
|
|
33
|
+
scale: options.property?.scale ?? [1, 1],
|
|
34
|
+
layoutMode: options.property?.layoutMode ?? FrameLayoutMode.FREE,
|
|
35
|
+
children: [...options.children ?? []],
|
|
36
|
+
autoLayoutConfig: options.property?.autoLayoutConfig,
|
|
37
|
+
layoutInfos: options.property?.layoutInfos ?? {},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// ==================== 便捷访问器 ====================
|
|
41
|
+
/**
|
|
42
|
+
* @description 子元素ID列表(只读)
|
|
43
|
+
*/
|
|
44
|
+
get children() {
|
|
45
|
+
return this.property.children;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @description 布局模式
|
|
49
|
+
*/
|
|
50
|
+
get layoutMode() {
|
|
51
|
+
return this.property.layoutMode;
|
|
52
|
+
}
|
|
53
|
+
set layoutMode(value) {
|
|
54
|
+
this.property.layoutMode = value;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @description 布局信息
|
|
58
|
+
*/
|
|
59
|
+
get layoutInfos() {
|
|
60
|
+
return this.property.layoutInfos;
|
|
61
|
+
}
|
|
62
|
+
set layoutInfos(info) {
|
|
63
|
+
this.property.layoutInfos = info;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @description 位置
|
|
67
|
+
*/
|
|
68
|
+
get position() {
|
|
69
|
+
return this.property.position;
|
|
70
|
+
}
|
|
71
|
+
set position(value) {
|
|
72
|
+
this.property.position = value;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @description 宽度
|
|
76
|
+
*/
|
|
77
|
+
get width() {
|
|
78
|
+
return this.property.width;
|
|
79
|
+
}
|
|
80
|
+
set width(value) {
|
|
81
|
+
this.property.width = value;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* @description 高度
|
|
85
|
+
*/
|
|
86
|
+
get height() {
|
|
87
|
+
return this.property.height;
|
|
88
|
+
}
|
|
89
|
+
set height(value) {
|
|
90
|
+
this.property.height = value;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @description 缩放
|
|
94
|
+
*/
|
|
95
|
+
get scale() {
|
|
96
|
+
return this.property.scale;
|
|
97
|
+
}
|
|
98
|
+
set scale(value) {
|
|
99
|
+
this.property.scale = value;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @description 旋转(二维旋转角度)
|
|
103
|
+
*/
|
|
104
|
+
get rotation() {
|
|
105
|
+
return this.property.rotation[2];
|
|
106
|
+
}
|
|
107
|
+
set rotation(value) {
|
|
108
|
+
this.property.rotation[2] = value;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* @description 完整旋转(包含 x, y, z)
|
|
112
|
+
*/
|
|
113
|
+
get fullRotation() {
|
|
114
|
+
return this.property.rotation;
|
|
115
|
+
}
|
|
116
|
+
set fullRotation(value) {
|
|
117
|
+
this.property.rotation = value;
|
|
118
|
+
}
|
|
119
|
+
// ==================== 子元素管理接口 ====================
|
|
120
|
+
/**
|
|
121
|
+
* @description 添加子元素
|
|
122
|
+
* @param itemId 子元素ID
|
|
123
|
+
* @returns 是否添加成功
|
|
124
|
+
*/
|
|
125
|
+
addChild(itemId) {
|
|
126
|
+
if (this.property.children.includes(itemId)) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
this.property.children.push(itemId);
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* @description 批量添加子元素
|
|
134
|
+
* @param itemIds 子元素ID列表
|
|
135
|
+
*/
|
|
136
|
+
addChildren(itemIds) {
|
|
137
|
+
itemIds.map(id => this.addChild(id));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @description 移除子元素
|
|
141
|
+
* @param itemId 子元素ID
|
|
142
|
+
* @returns 是否移除成功
|
|
143
|
+
*/
|
|
144
|
+
removeChild(itemId) {
|
|
145
|
+
const index = this.property.children.indexOf(itemId);
|
|
146
|
+
if (index === -1) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
this.property.children.splice(index, 1);
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @description 批量移除子元素
|
|
154
|
+
* @param itemIds 子元素ID列表
|
|
155
|
+
*/
|
|
156
|
+
removeChildren(itemIds) {
|
|
157
|
+
this.property.children = this.property.children.filter(id => !itemIds.includes(id));
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @description 是否包含指定子元素
|
|
161
|
+
* @param itemId 子元素ID
|
|
162
|
+
*/
|
|
163
|
+
hasChild(itemId) {
|
|
164
|
+
return this.property.children.includes(itemId);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* @description 清空所有子元素
|
|
168
|
+
*/
|
|
169
|
+
clearChildren() {
|
|
170
|
+
this.property.children = [];
|
|
171
|
+
}
|
|
172
|
+
// ==================== 实现抽象方法 ====================
|
|
173
|
+
/**
|
|
174
|
+
* @description 转换为 FrameCreateInfo
|
|
175
|
+
* @param withParent 是否包含父节点ID
|
|
176
|
+
*/
|
|
177
|
+
toCreateInfo(withParent) {
|
|
178
|
+
const createInfo = {
|
|
179
|
+
type: SDKItemType.FRAME,
|
|
180
|
+
id: this.id,
|
|
181
|
+
name: this.name,
|
|
182
|
+
property: deepClone(this.property)
|
|
183
|
+
};
|
|
184
|
+
if (withParent && this.parentId) {
|
|
185
|
+
createInfo.parentId = this.parentId;
|
|
186
|
+
}
|
|
187
|
+
// 添加扩展属性
|
|
188
|
+
const extension = this.getAllExtension();
|
|
189
|
+
if (Object.keys(extension).length > 0) {
|
|
190
|
+
createInfo.extension = extension;
|
|
191
|
+
}
|
|
192
|
+
return createInfo;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* @description 克隆 SDKItem
|
|
196
|
+
*/
|
|
197
|
+
clone() {
|
|
198
|
+
return new FrameItem({
|
|
199
|
+
id: generateGUID(),
|
|
200
|
+
name: this.name,
|
|
201
|
+
parentId: this.parentId,
|
|
202
|
+
duration: this.duration,
|
|
203
|
+
delay: this.delay,
|
|
204
|
+
endBehavior: this.endBehavior,
|
|
205
|
+
isLocked: this.isLocked,
|
|
206
|
+
isCoreEditable: this.isCoreEditable,
|
|
207
|
+
property: deepClone(this.property),
|
|
208
|
+
extension: this.getAllExtension()
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* @description 类型守卫:检查是否是 FrameItem
|
|
214
|
+
*/
|
|
215
|
+
export function isFrameItem(obj) {
|
|
216
|
+
return obj instanceof FrameItem;
|
|
217
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { SDKItemType } from './types';
|
|
2
|
+
import { BaseItem } from './base-item';
|
|
3
|
+
import { deepClone } from '../utils/common-utils';
|
|
4
|
+
import { generateGUID } from '../shared';
|
|
5
|
+
/**
|
|
6
|
+
* @description 资源生成器元素 SDKItem 类
|
|
7
|
+
* @description 支持 image 和 video 两种生成器类型
|
|
8
|
+
* @description 在 Player 中以透明 SpriteItem 形式渲染
|
|
9
|
+
* @description 支持属性扩展,可转换为 SpriteItem 或 VideoItem
|
|
10
|
+
*/
|
|
11
|
+
export class GeneratorItem extends BaseItem {
|
|
12
|
+
/**
|
|
13
|
+
* @description 元素类型(独立类型,不属于 spec.ItemType)
|
|
14
|
+
*/
|
|
15
|
+
type = SDKItemType.GENERATOR;
|
|
16
|
+
/**
|
|
17
|
+
* @description 元素属性(包含 generatorType)
|
|
18
|
+
*/
|
|
19
|
+
property;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
super(options);
|
|
22
|
+
// 初始化属性(包含 generatorType)
|
|
23
|
+
this.property = {
|
|
24
|
+
position: options.property?.position ?? [0, 0],
|
|
25
|
+
rotation: options.property?.rotation ?? [0, 0, 0],
|
|
26
|
+
width: options.property?.width ?? 0,
|
|
27
|
+
height: options.property?.height ?? 0,
|
|
28
|
+
scale: options.property?.scale ?? [1, 1],
|
|
29
|
+
generatorType: options.property?.generatorType ?? 'video',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// ==================== generatorType 访问器 ====================
|
|
33
|
+
/**
|
|
34
|
+
* @description 生成器类型
|
|
35
|
+
*/
|
|
36
|
+
get generatorType() {
|
|
37
|
+
return this.property.generatorType;
|
|
38
|
+
}
|
|
39
|
+
set generatorType(value) {
|
|
40
|
+
this.property.generatorType = value;
|
|
41
|
+
}
|
|
42
|
+
// ==================== 便捷访问器 ====================
|
|
43
|
+
/**
|
|
44
|
+
* @description 图片地址(生成器返回空)
|
|
45
|
+
*/
|
|
46
|
+
get image() {
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
set image(_value) {
|
|
50
|
+
// 生成器不设置图片
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @description 位置
|
|
54
|
+
*/
|
|
55
|
+
get position() {
|
|
56
|
+
return this.property.position;
|
|
57
|
+
}
|
|
58
|
+
set position(value) {
|
|
59
|
+
this.property.position = value;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @description 宽度
|
|
63
|
+
*/
|
|
64
|
+
get width() {
|
|
65
|
+
return this.property.width;
|
|
66
|
+
}
|
|
67
|
+
set width(value) {
|
|
68
|
+
this.property.width = value;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @description 高度
|
|
72
|
+
*/
|
|
73
|
+
get height() {
|
|
74
|
+
return this.property.height;
|
|
75
|
+
}
|
|
76
|
+
set height(value) {
|
|
77
|
+
this.property.height = value;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @description 旋转(二维旋转角度)
|
|
81
|
+
*/
|
|
82
|
+
get rotation() {
|
|
83
|
+
return this.property.rotation[2];
|
|
84
|
+
}
|
|
85
|
+
set rotation(value) {
|
|
86
|
+
this.property.rotation[2] = value;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @description 完整旋转(包含 x, y, z)
|
|
90
|
+
*/
|
|
91
|
+
get fullRotation() {
|
|
92
|
+
return this.property.rotation;
|
|
93
|
+
}
|
|
94
|
+
set fullRotation(value) {
|
|
95
|
+
this.property.rotation = value;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @description 是否正在编辑关键属性
|
|
99
|
+
* @deprecated 该属性即将废弃,使用 isCoreEditable 代替
|
|
100
|
+
*/
|
|
101
|
+
get keyPropertyEditing() {
|
|
102
|
+
return this.isCoreEditable;
|
|
103
|
+
}
|
|
104
|
+
set keyPropertyEditing(value) {
|
|
105
|
+
this.isCoreEditable = value;
|
|
106
|
+
}
|
|
107
|
+
// ==================== 实现抽象方法 ====================
|
|
108
|
+
/**
|
|
109
|
+
* @description 转换为 GeneratorCreateInfo
|
|
110
|
+
* @param withParent 是否包含父节点ID
|
|
111
|
+
*/
|
|
112
|
+
toCreateInfo(withParent) {
|
|
113
|
+
const extension = this.getAllExtension();
|
|
114
|
+
return {
|
|
115
|
+
type: SDKItemType.GENERATOR,
|
|
116
|
+
id: this.id,
|
|
117
|
+
name: this.name,
|
|
118
|
+
parentId: withParent ? this.parentId : undefined,
|
|
119
|
+
extension: Object.keys(extension).length > 0 ? extension : undefined,
|
|
120
|
+
property: deepClone(this.property)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @description 转换为 VideoCreateInfo(用于转换为视频元素)
|
|
125
|
+
* @param videoUrl 视频资源地址
|
|
126
|
+
* @param withParent 是否包含父节点ID
|
|
127
|
+
*/
|
|
128
|
+
toVideoCreateInfo(videoUrl, withParent) {
|
|
129
|
+
const extension = this.getAllExtension();
|
|
130
|
+
const property = deepClone(this.property);
|
|
131
|
+
delete property.generatorType; // 转换为视频元素时不需要 generatorType
|
|
132
|
+
return {
|
|
133
|
+
type: SDKItemType.VIDEO,
|
|
134
|
+
id: this.id, // 复用相同 ID
|
|
135
|
+
name: this.name,
|
|
136
|
+
parentId: withParent ? this.parentId : undefined,
|
|
137
|
+
extension: Object.keys(extension).length > 0 ? extension : undefined,
|
|
138
|
+
property: {
|
|
139
|
+
video: videoUrl,
|
|
140
|
+
...property
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* @description 转换为 SpriteCreateInfo(用于转换为图片元素)
|
|
146
|
+
* @param imageUrl 图片资源地址
|
|
147
|
+
* @param withParent 是否包含父节点ID
|
|
148
|
+
*/
|
|
149
|
+
toSpriteCreateInfo(imageUrl, withParent) {
|
|
150
|
+
const extension = this.getAllExtension();
|
|
151
|
+
const property = deepClone(this.property);
|
|
152
|
+
delete property.generatorType; // 转换为视频元素时不需要 generatorType
|
|
153
|
+
return {
|
|
154
|
+
type: SDKItemType.SPRITE,
|
|
155
|
+
id: this.id, // 复用相同 ID
|
|
156
|
+
name: this.name,
|
|
157
|
+
parentId: withParent ? this.parentId : undefined,
|
|
158
|
+
extension: Object.keys(extension).length > 0 ? extension : undefined,
|
|
159
|
+
property: {
|
|
160
|
+
image: imageUrl,
|
|
161
|
+
...property
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* @description 克隆 SDKItem
|
|
167
|
+
*/
|
|
168
|
+
clone() {
|
|
169
|
+
return new GeneratorItem({
|
|
170
|
+
id: generateGUID(),
|
|
171
|
+
name: this.name,
|
|
172
|
+
parentId: this.parentId,
|
|
173
|
+
duration: this.duration,
|
|
174
|
+
delay: this.delay,
|
|
175
|
+
endBehavior: this.endBehavior,
|
|
176
|
+
isLocked: this.isLocked,
|
|
177
|
+
isCoreEditable: this.isCoreEditable,
|
|
178
|
+
property: deepClone(this.property),
|
|
179
|
+
extension: this.getAllExtension()
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* @description 类型守卫:检查是否是 GeneratorItem
|
|
185
|
+
*/
|
|
186
|
+
export function isGeneratorItem(obj) {
|
|
187
|
+
return obj instanceof GeneratorItem;
|
|
188
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { SDKItemType } from './types';
|
|
2
|
+
import { generateGUID } from '../shared';
|
|
3
|
+
import { BaseItem } from './base-item';
|
|
4
|
+
import { deepClone } from '../utils/common-utils';
|
|
5
|
+
/**
|
|
6
|
+
* @description 空节点/组 SDKItem 类
|
|
7
|
+
* @description 支持属性扩展
|
|
8
|
+
*/
|
|
9
|
+
export class GroupItem extends BaseItem {
|
|
10
|
+
/**
|
|
11
|
+
* @description 元素类型
|
|
12
|
+
*/
|
|
13
|
+
type = SDKItemType.GROUP;
|
|
14
|
+
/**
|
|
15
|
+
* @description 元素属性
|
|
16
|
+
*/
|
|
17
|
+
property;
|
|
18
|
+
constructor(options) {
|
|
19
|
+
super(options);
|
|
20
|
+
// 初始化属性
|
|
21
|
+
this.property = {
|
|
22
|
+
position: options.property?.position ?? [0, 0],
|
|
23
|
+
rotation: options.property?.rotation ?? [0, 0, 0],
|
|
24
|
+
width: options.property?.width ?? 0,
|
|
25
|
+
height: options.property?.height ?? 0,
|
|
26
|
+
children: [...options.children ?? []],
|
|
27
|
+
scale: options.property?.scale ?? [1, 1]
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
// ==================== 便捷访问器 ====================
|
|
31
|
+
/**
|
|
32
|
+
* @description 位置
|
|
33
|
+
*/
|
|
34
|
+
get position() {
|
|
35
|
+
return this.property.position;
|
|
36
|
+
}
|
|
37
|
+
set position(value) {
|
|
38
|
+
this.property.position = value;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @description 大小
|
|
42
|
+
*/
|
|
43
|
+
get scale() {
|
|
44
|
+
return this.property.scale;
|
|
45
|
+
}
|
|
46
|
+
set scale(value) {
|
|
47
|
+
this.property.scale = value;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @description 旋转(二维旋转角度)
|
|
51
|
+
*/
|
|
52
|
+
get rotation() {
|
|
53
|
+
return this.property.rotation[2];
|
|
54
|
+
}
|
|
55
|
+
set rotation(value) {
|
|
56
|
+
this.property.rotation[2] = value;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @description 完整旋转(包含 x, y, z)
|
|
60
|
+
*/
|
|
61
|
+
get fullRotation() {
|
|
62
|
+
return this.property.rotation;
|
|
63
|
+
}
|
|
64
|
+
set fullRotation(value) {
|
|
65
|
+
this.property.rotation = value;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @description 是否正在编辑关键属性
|
|
69
|
+
* @deprecated 该属性即将废弃,使用 isCoreEditable 代替
|
|
70
|
+
*/
|
|
71
|
+
get keyPropertyEditing() {
|
|
72
|
+
return this.isCoreEditable;
|
|
73
|
+
}
|
|
74
|
+
set keyPropertyEditing(value) {
|
|
75
|
+
this.isCoreEditable = value;
|
|
76
|
+
}
|
|
77
|
+
// ==================== 实现抽象方法 ====================
|
|
78
|
+
/**
|
|
79
|
+
* @description 转换为 CreateInfo
|
|
80
|
+
* @param withParent 是否包含父节点ID
|
|
81
|
+
*/
|
|
82
|
+
toCreateInfo(withParent) {
|
|
83
|
+
const extension = this.getAllExtension();
|
|
84
|
+
return {
|
|
85
|
+
type: this.type,
|
|
86
|
+
id: this.id,
|
|
87
|
+
name: this.name,
|
|
88
|
+
parentId: withParent ? this.parentId : undefined,
|
|
89
|
+
extension: Object.keys(extension).length > 0 ? extension : undefined,
|
|
90
|
+
property: deepClone(this.property)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @description 克隆 SDKItem
|
|
95
|
+
*/
|
|
96
|
+
clone() {
|
|
97
|
+
return new GroupItem({
|
|
98
|
+
id: generateGUID(),
|
|
99
|
+
name: this.name,
|
|
100
|
+
parentId: this.parentId,
|
|
101
|
+
duration: this.duration,
|
|
102
|
+
delay: this.delay,
|
|
103
|
+
endBehavior: this.endBehavior,
|
|
104
|
+
isLocked: this.isLocked,
|
|
105
|
+
isCoreEditable: this.isCoreEditable,
|
|
106
|
+
property: deepClone(this.property),
|
|
107
|
+
extension: this.getAllExtension()
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @description 类型守卫:检查是否是 GroupItem
|
|
113
|
+
*/
|
|
114
|
+
export function isGroupItem(obj) {
|
|
115
|
+
return obj instanceof GroupItem;
|
|
116
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export { SDKItemType, } from './types';
|
|
2
|
+
// ==================== 类导出 ====================
|
|
3
|
+
export { BaseItem, isBaseItem } from './base-item';
|
|
4
|
+
export { SpriteItem, isSpriteItem } from './sprite-item';
|
|
5
|
+
export { TextItem, isTextItem } from './text-item';
|
|
6
|
+
export { VideoItem, isVideoItem } from './video-item';
|
|
7
|
+
export { GroupItem, isGroupItem } from './group-item';
|
|
8
|
+
export { GeneratorItem, isGeneratorItem } from './generator-item';
|
|
9
|
+
export { EffectsItem, isEffectsItem } from './effects-item';
|
|
10
|
+
export { FrameItem, isFrameItem } from './frame-item';
|
|
11
|
+
export { CardItem, isCardItem } from './card-item';
|
|
12
|
+
// ==================== 工厂函数 ====================
|
|
13
|
+
import { spec } from '../shared';
|
|
14
|
+
import { SpriteItem } from './sprite-item';
|
|
15
|
+
import { GroupItem } from './group-item';
|
|
16
|
+
import { TextItem } from './text-item';
|
|
17
|
+
import { VideoItem } from './video-item';
|
|
18
|
+
/**
|
|
19
|
+
* @description 根据 item type 创建对应的 SDKItem 实例
|
|
20
|
+
* @param type 元素类型
|
|
21
|
+
* @param options SDKItem 选项
|
|
22
|
+
* @returns SDKItem 实例
|
|
23
|
+
*/
|
|
24
|
+
export function createSDKItem(type, options) {
|
|
25
|
+
switch (type) {
|
|
26
|
+
case spec.ItemType.sprite:
|
|
27
|
+
return new SpriteItem(options);
|
|
28
|
+
case spec.ItemType.null:
|
|
29
|
+
return new GroupItem(options);
|
|
30
|
+
case spec.ItemType.text:
|
|
31
|
+
return new TextItem(options);
|
|
32
|
+
case spec.ItemType.video:
|
|
33
|
+
return new VideoItem(options);
|
|
34
|
+
default:
|
|
35
|
+
// 对于未实现类型的回退,创建 GroupItem
|
|
36
|
+
console.warn(`SDKItem type ${type} not implemented, falling back to GroupItem`);
|
|
37
|
+
return new GroupItem(options);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { generateGUID } from '../shared';
|
|
2
|
+
import { SDKItemType } from './types';
|
|
3
|
+
import { BaseItem } from './base-item';
|
|
4
|
+
import { deepClone } from '../utils/common-utils';
|
|
5
|
+
/**
|
|
6
|
+
* @description 图片元素 SDKItem 类
|
|
7
|
+
* @description 支持属性扩展
|
|
8
|
+
*/
|
|
9
|
+
export class SpriteItem extends BaseItem {
|
|
10
|
+
/**
|
|
11
|
+
* @description 元素类型
|
|
12
|
+
*/
|
|
13
|
+
type = SDKItemType.SPRITE;
|
|
14
|
+
/**
|
|
15
|
+
* @description 元素属性
|
|
16
|
+
*/
|
|
17
|
+
property;
|
|
18
|
+
constructor(options) {
|
|
19
|
+
super(options);
|
|
20
|
+
// 初始化属性
|
|
21
|
+
this.property = {
|
|
22
|
+
position: options.property?.position ?? [0, 0],
|
|
23
|
+
rotation: options.property?.rotation ?? [0, 0, 0],
|
|
24
|
+
width: options.property?.width ?? 0,
|
|
25
|
+
height: options.property?.height ?? 0,
|
|
26
|
+
scale: options.property?.scale ?? [1, 1],
|
|
27
|
+
image: options.property?.image ?? ''
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
// ==================== 便捷访问器 ====================
|
|
31
|
+
/**
|
|
32
|
+
* @description 图片地址
|
|
33
|
+
*/
|
|
34
|
+
get image() {
|
|
35
|
+
return this.property.image;
|
|
36
|
+
}
|
|
37
|
+
set image(value) {
|
|
38
|
+
this.property.image = value;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @description 位置
|
|
42
|
+
*/
|
|
43
|
+
get position() {
|
|
44
|
+
return this.property.position;
|
|
45
|
+
}
|
|
46
|
+
set position(value) {
|
|
47
|
+
this.property.position = value;
|
|
48
|
+
}
|
|
49
|
+
get width() {
|
|
50
|
+
return this.property.width;
|
|
51
|
+
}
|
|
52
|
+
set width(value) {
|
|
53
|
+
this.property.width = value;
|
|
54
|
+
}
|
|
55
|
+
get height() {
|
|
56
|
+
return this.property.height;
|
|
57
|
+
}
|
|
58
|
+
set height(value) {
|
|
59
|
+
this.property.height = value;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @description 旋转(二维旋转角度)
|
|
63
|
+
*/
|
|
64
|
+
get rotation() {
|
|
65
|
+
return this.property.rotation[2];
|
|
66
|
+
}
|
|
67
|
+
set rotation(value) {
|
|
68
|
+
this.property.rotation[2] = value;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @description 完整旋转(包含 x, y, z)
|
|
72
|
+
*/
|
|
73
|
+
get fullRotation() {
|
|
74
|
+
return this.property.rotation;
|
|
75
|
+
}
|
|
76
|
+
set fullRotation(value) {
|
|
77
|
+
this.property.rotation = value;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @description 是否正在编辑关键属性
|
|
81
|
+
* @deprecated 该属性即将废弃,使用 isCoreEditable 代替
|
|
82
|
+
*/
|
|
83
|
+
get keyPropertyEditing() {
|
|
84
|
+
return this.isCoreEditable;
|
|
85
|
+
}
|
|
86
|
+
set keyPropertyEditing(value) {
|
|
87
|
+
this.isCoreEditable = value;
|
|
88
|
+
}
|
|
89
|
+
// ==================== 实现抽象方法 ====================
|
|
90
|
+
/**
|
|
91
|
+
* @description 转换为 CreateInfo
|
|
92
|
+
* @param withParent 是否包含父节点ID
|
|
93
|
+
*/
|
|
94
|
+
toCreateInfo(withParent) {
|
|
95
|
+
const extension = this.getAllExtension();
|
|
96
|
+
const property = deepClone(this.property);
|
|
97
|
+
Object.assign(property, {
|
|
98
|
+
width: property.size[0],
|
|
99
|
+
height: property.size[1]
|
|
100
|
+
});
|
|
101
|
+
delete property.size;
|
|
102
|
+
return {
|
|
103
|
+
type: SDKItemType.SPRITE,
|
|
104
|
+
id: this.id,
|
|
105
|
+
name: this.name,
|
|
106
|
+
parentId: withParent ? this.parentId : undefined,
|
|
107
|
+
extension: Object.keys(extension).length > 0 ? extension : undefined,
|
|
108
|
+
property
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @description 克隆 SDKItem
|
|
113
|
+
*/
|
|
114
|
+
clone() {
|
|
115
|
+
return new SpriteItem({
|
|
116
|
+
id: generateGUID(),
|
|
117
|
+
name: this.name,
|
|
118
|
+
parentId: this.parentId,
|
|
119
|
+
duration: this.duration,
|
|
120
|
+
delay: this.delay,
|
|
121
|
+
endBehavior: this.endBehavior,
|
|
122
|
+
isLocked: this.isLocked,
|
|
123
|
+
isCoreEditable: this.isCoreEditable,
|
|
124
|
+
property: deepClone(this.property),
|
|
125
|
+
extension: this.getAllExtension()
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @description 创建包含扩展属性的 CreateInfo
|
|
130
|
+
* @param withParent 是否包含父节点ID
|
|
131
|
+
* @param extraProps 额外的属性
|
|
132
|
+
*/
|
|
133
|
+
toCreateInfoWithExtensions(withParent, extraProps) {
|
|
134
|
+
const createInfo = this.toCreateInfo(withParent);
|
|
135
|
+
// 添加额外属性
|
|
136
|
+
if (extraProps) {
|
|
137
|
+
Object.assign(createInfo, extraProps);
|
|
138
|
+
}
|
|
139
|
+
return createInfo;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* @description 类型守卫:检查是否是 SpriteItem
|
|
144
|
+
*/
|
|
145
|
+
export function isSpriteItem(obj) {
|
|
146
|
+
return obj instanceof SpriteItem;
|
|
147
|
+
}
|