@vvfx/sdk 0.2.8 → 0.2.9

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.
Files changed (107) hide show
  1. package/dist/config.js +231 -0
  2. package/dist/exporter/config.js +18 -0
  3. package/dist/exporter/const.js +71 -0
  4. package/dist/exporter/export-media.js +878 -0
  5. package/dist/exporter/exporter.js +121 -0
  6. package/dist/exporter/index.js +1 -0
  7. package/dist/exporter/types.js +1 -0
  8. package/dist/exporter/utils.js +190 -0
  9. package/dist/exporter/wav-audio.js +50 -0
  10. package/dist/gesture-handler/gizmo/adsorption-gizmo.js +227 -0
  11. package/dist/gesture-handler/gizmo/control-gizmo.js +149 -0
  12. package/dist/gesture-handler/gizmo/gizmo.js +17 -0
  13. package/dist/gesture-handler/gizmo/icon-gizmo.js +189 -0
  14. package/dist/gesture-handler/gizmo/index.js +6 -0
  15. package/dist/gesture-handler/gizmo/item-create-gizmo.js +256 -0
  16. package/dist/gesture-handler/gizmo/loading-gizmo.js +320 -0
  17. package/dist/gesture-handler/gizmo/mask-gizmo.js +648 -0
  18. package/dist/gesture-handler/gizmo/picture-cut-gizmo.js +550 -0
  19. package/dist/gesture-handler/gizmo/picture-expand-gizmo.js +491 -0
  20. package/dist/gesture-handler/gizmo/preference-gizmo.js +148 -0
  21. package/dist/gesture-handler/gizmo/selector-gizmo.d.ts +1 -1
  22. package/dist/gesture-handler/gizmo/selector-gizmo.js +468 -0
  23. package/dist/gesture-handler/gizmo/sprite-text-edit-gizmo.js +247 -0
  24. package/dist/gesture-handler/gizmo/text-gizmo.js +1033 -0
  25. package/dist/gesture-handler/gizmo/transform-gizmo.js +1199 -0
  26. package/dist/gesture-handler/gizmo/type.js +18 -0
  27. package/dist/gesture-handler/index.js +3 -0
  28. package/dist/gesture-handler/src/gesture-handler.js +770 -0
  29. package/dist/gesture-handler/src/icons.js +24 -0
  30. package/dist/gesture-handler/utils.js +40 -0
  31. package/dist/html-overlay/anchor-navigation-runtime.js +27 -0
  32. package/dist/html-overlay/auto-height-runtime.js +132 -0
  33. package/dist/html-overlay/document-runtime.js +71 -0
  34. package/dist/html-overlay/document-transform.js +96 -0
  35. package/dist/html-overlay/dom-order.js +8 -0
  36. package/dist/html-overlay/host-message-runtime.js +24 -0
  37. package/dist/html-overlay/html-capture-runtime.js +282 -0
  38. package/dist/html-overlay/html-viewport-style.js +10 -0
  39. package/dist/html-overlay/index.js +1 -0
  40. package/dist/html-overlay/manager.js +1663 -0
  41. package/dist/html-overlay/mime-utils.js +21 -0
  42. package/dist/html-overlay/overlay-transform.js +57 -0
  43. package/dist/html-overlay/path-utils.js +35 -0
  44. package/dist/html-overlay/shell-runtime.js +12 -0
  45. package/dist/index.cjs +1 -1
  46. package/dist/index.cjs.map +1 -1
  47. package/dist/index.js +13 -75311
  48. package/dist/index.mjs +75311 -0
  49. package/dist/{index.js.map → index.mjs.map} +1 -1
  50. package/dist/layer-order.js +8 -0
  51. package/dist/math/box2.js +396 -0
  52. package/dist/math/circle.js +131 -0
  53. package/dist/math/euler.js +35 -0
  54. package/dist/math/index.js +13 -0
  55. package/dist/math/line2.js +153 -0
  56. package/dist/math/line3.js +36 -0
  57. package/dist/math/matrix4.js +207 -0
  58. package/dist/math/plane.js +52 -0
  59. package/dist/math/quaternion.js +3 -0
  60. package/dist/math/ray-caster.js +25 -0
  61. package/dist/math/ray.js +47 -0
  62. package/dist/math/type.js +1 -0
  63. package/dist/math/utils.js +77 -0
  64. package/dist/math/vector2.js +70 -0
  65. package/dist/math/vector3.js +60 -0
  66. package/dist/screen-shot/index.js +1 -0
  67. package/dist/screen-shot/screen-shot.js +113 -0
  68. package/dist/sdk-item/base-item.js +160 -0
  69. package/dist/sdk-item/card-item.js +131 -0
  70. package/dist/sdk-item/effects-item.js +144 -0
  71. package/dist/sdk-item/frame-item.js +217 -0
  72. package/dist/sdk-item/generator-item.js +188 -0
  73. package/dist/sdk-item/group-item.js +116 -0
  74. package/dist/sdk-item/index.js +39 -0
  75. package/dist/sdk-item/sprite-item.js +147 -0
  76. package/dist/sdk-item/text-item.js +223 -0
  77. package/dist/sdk-item/types.d.ts +1 -1
  78. package/dist/sdk-item/types.js +15 -0
  79. package/dist/sdk-item/video-item.js +174 -0
  80. package/dist/sdk.js +1903 -0
  81. package/dist/service/UndoRedo.js +79 -0
  82. package/dist/shared/index.d.ts +1 -0
  83. package/dist/shared/index.js +2 -0
  84. package/dist/shared/player.d.ts +1 -1
  85. package/dist/shared/player.js +9 -0
  86. package/dist/shared/spec.d.ts +1 -0
  87. package/dist/shared/spec.js +1 -0
  88. package/dist/size-adapte/index.js +1 -0
  89. package/dist/size-adapte/size-adapt.js +395 -0
  90. package/dist/types.d.ts +5 -1
  91. package/dist/types.js +17 -0
  92. package/dist/utils/background-manager.js +189 -0
  93. package/dist/utils/common-utils.js +183 -0
  94. package/dist/utils/index.js +8 -0
  95. package/dist/utils/interaction-utils.js +205 -0
  96. package/dist/utils/json-data-utils.js +1529 -0
  97. package/dist/utils/layout-utils.js +1217 -0
  98. package/dist/utils/page-data-utils.js +5397 -0
  99. package/dist/utils/player-data-utils.js +48 -0
  100. package/dist/utils/types.js +8 -0
  101. package/dist/wireframe/common/box.js +18 -0
  102. package/dist/wireframe/common/dashed-line.js +21 -0
  103. package/dist/wireframe/common/line.js +17 -0
  104. package/dist/wireframe/common/pixi-ext.js +1 -0
  105. package/dist/wireframe/common/pixi.js +31 -0
  106. package/dist/wireframe/index.js +4 -0
  107. package/package.json +10 -3
@@ -0,0 +1,491 @@
1
+ import { Box2, getBoxByNormalizeBox, getNormalizeBoxByBoxes, Line2, RAD2DEG, Vector2 } from '../../math';
2
+ import { SDK } from '../../sdk';
3
+ import { assertExist } from '../../utils';
4
+ import { Graphics } from '../../wireframe';
5
+ import { Gizmo } from './gizmo';
6
+ export class PictureExpandGizmo extends Gizmo {
7
+ result = {
8
+ type: 'invalid'
9
+ };
10
+ interactionParam = { type: 'none' };
11
+ graphics = new Graphics();
12
+ /**
13
+ * @description Shift按键是否按下,用于判断交互
14
+ */
15
+ isShiftDown = false;
16
+ /**
17
+ * @description 是否锁定宽高比缩放
18
+ */
19
+ _isLockScale = false;
20
+ _pageDataUtils;
21
+ _eventEmitter;
22
+ type = 'picture-expand';
23
+ /**
24
+ * 鼠标状态绘制结果
25
+ */
26
+ cursorResult = {
27
+ type: 'normal',
28
+ angle: 0,
29
+ };
30
+ get interactive() {
31
+ return SDK.config.gestureHandlerConfig.pictureExpandGizmoEnabled;
32
+ }
33
+ set interactive(bool) {
34
+ if (bool === SDK.config.gestureHandlerConfig.pictureExpandGizmoEnabled) {
35
+ return;
36
+ }
37
+ if (this._pageDataUtils.getPageData()?.activeData.selectedItems?.length !== 1) {
38
+ console.warn('Selected items` length is not one, Picture expand gizmo can not open.');
39
+ }
40
+ else {
41
+ SDK.config.gestureHandlerConfig.pictureExpandGizmoEnabled = bool;
42
+ }
43
+ }
44
+ get isLockScale() {
45
+ return this._isLockScale;
46
+ }
47
+ set isLockScale(state) {
48
+ if (state === this.isLockScale) {
49
+ return;
50
+ }
51
+ this._isLockScale = state;
52
+ }
53
+ constructor(utils, eventEmitter) {
54
+ super();
55
+ this._pageDataUtils = utils;
56
+ this._eventEmitter = eventEmitter;
57
+ }
58
+ preparationAction(event) {
59
+ if (!this.interactive) {
60
+ return undefined;
61
+ }
62
+ const mouse = new Vector2(event.offsetX, event.offsetY);
63
+ const clinetMouse = new Vector2(event.clientX, event.clientY);
64
+ this.refreshInteractionType(mouse, clinetMouse);
65
+ return this.type;
66
+ }
67
+ preAction(event, isDoubleClick) {
68
+ if (!this.interactive || this.interactionParam.type === 'none') {
69
+ return undefined;
70
+ }
71
+ return this.type;
72
+ }
73
+ action(event) {
74
+ if (!this.interactive
75
+ || this.interactionParam.type === 'none'
76
+ || this.result.type === 'invalid') {
77
+ return;
78
+ }
79
+ const currentClientMouse = new Vector2(event.clientX, event.clientY);
80
+ const { startMouse, box } = this.interactionParam;
81
+ const shift = new Vector2().subtractVectors(currentClientMouse, startMouse);
82
+ const { itemBox } = this.result;
83
+ const { min: itemBoxMin, max: itemBoxMax } = itemBox;
84
+ switch (this.interactionParam.type) {
85
+ case 'move': {
86
+ const { min: originMin, max: originMax } = box;
87
+ const xMinShift = itemBoxMax.x - originMax.x;
88
+ const xMaxShift = itemBoxMin.x - originMin.x;
89
+ const yMinShift = itemBoxMax.y - originMax.y;
90
+ const yMaxShift = itemBoxMin.y - originMin.y;
91
+ shift.x = Math.min(Math.max(shift.x, xMinShift), xMaxShift);
92
+ shift.y = Math.min(Math.max(shift.y, yMinShift), yMaxShift);
93
+ const resultBox = box.clone().translate(shift);
94
+ this.result.normalizeExpandBox = getNormalizeBoxByBoxes(itemBox, resultBox);
95
+ this._eventEmitter.emit('expandBoxChange', this.getExpandBox());
96
+ break;
97
+ }
98
+ case 'scale': {
99
+ const { index } = this.interactionParam;
100
+ const { min, max } = box;
101
+ const startCorner = box.corners[index];
102
+ const anchor = box.corners[(index + 2) % 4];
103
+ const resultCorner = new Vector2(startCorner.x + shift.x, startCorner.y + shift.y);
104
+ // x位置校验
105
+ if (startCorner.x >= max.x) {
106
+ resultCorner.x = Math.max(resultCorner.x, itemBoxMax.x);
107
+ }
108
+ else if (startCorner.x <= min.x) {
109
+ resultCorner.x = Math.min(resultCorner.x, itemBoxMin.x);
110
+ }
111
+ else {
112
+ console.warn('resultCorner has wrong, we have move it to the nearest corner');
113
+ resultCorner.x = Math.abs(resultCorner.x - min.x) > Math.abs(resultCorner.x - max.x) ? max.x : min.x;
114
+ }
115
+ // y位置校验
116
+ if (startCorner.y >= max.y) {
117
+ resultCorner.y = Math.max(resultCorner.y, itemBoxMax.y);
118
+ }
119
+ else if (startCorner.y <= min.y) {
120
+ resultCorner.y = Math.min(resultCorner.y, itemBoxMin.y);
121
+ }
122
+ else {
123
+ console.warn('resultCorner has wrong, we have move it to the nearest corner');
124
+ resultCorner.y = Math.abs(resultCorner.y - min.y) > Math.abs(resultCorner.y - max.y) ? max.y : min.y;
125
+ }
126
+ // Shift键按下时,锁定缩放
127
+ if (this.isShiftDown || this.isLockScale) {
128
+ const expandBox = this.getExpandBox();
129
+ const { x: boxWidth, y: boxHeight } = expandBox.getSize();
130
+ const { x: originWidth, y: originHeight } = box.getSize();
131
+ this.interactionParam.lockedAspect ??= boxWidth / boxHeight;
132
+ if (Math.abs(resultCorner.x - anchor.x) / originWidth > Math.abs(resultCorner.y - anchor.y) / originHeight) {
133
+ const resultHeight = Math.abs(resultCorner.x - anchor.x) / this.interactionParam.lockedAspect;
134
+ resultCorner.y = (startCorner.y - anchor.y) / Math.abs((startCorner.y - anchor.y)) * resultHeight + anchor.y;
135
+ // y位置校验
136
+ if (startCorner.y >= max.y) {
137
+ resultCorner.y = Math.max(resultCorner.y, itemBoxMax.y);
138
+ }
139
+ else if (startCorner.y <= min.y) {
140
+ resultCorner.y = Math.min(resultCorner.y, itemBoxMin.y);
141
+ }
142
+ else {
143
+ console.warn('resultCorner has wrong, we have move it to the nearest corner');
144
+ resultCorner.y = Math.abs(resultCorner.y - min.y) > Math.abs(resultCorner.y - max.y) ? max.y : min.y;
145
+ }
146
+ }
147
+ else {
148
+ const resultWidth = Math.abs(resultCorner.y - anchor.y) * this.interactionParam.lockedAspect;
149
+ resultCorner.x = (startCorner.x - anchor.x) / Math.abs((startCorner.x - anchor.x)) * resultWidth + anchor.x;
150
+ // x位置校验
151
+ if (startCorner.x >= max.x) {
152
+ resultCorner.x = Math.max(resultCorner.x, itemBoxMax.x);
153
+ }
154
+ else if (startCorner.x <= min.x) {
155
+ resultCorner.x = Math.min(resultCorner.x, itemBoxMin.x);
156
+ }
157
+ else {
158
+ console.warn('resultCorner has wrong, we have move it to the nearest corner');
159
+ resultCorner.x = Math.abs(resultCorner.x - min.x) > Math.abs(resultCorner.x - max.x) ? max.x : min.x;
160
+ }
161
+ }
162
+ }
163
+ this.result.normalizeExpandBox = getNormalizeBoxByBoxes(itemBox, new Box2().setFromVec2ArrayWithOutCorners([resultCorner, anchor]));
164
+ this._eventEmitter.emit('expandBoxChange', this.getExpandBox());
165
+ break;
166
+ }
167
+ case 'direction-scale': {
168
+ const { index } = this.interactionParam;
169
+ const startPoint = box.corners[index].clone();
170
+ const expandBox = this.getExpandBox();
171
+ const { x: boxWidth, y: boxHeight } = expandBox.getSize();
172
+ this.interactionParam.lockedAspect ??= boxWidth / boxHeight;
173
+ const nextCorner = box.corners[(index + 1) % 4].clone();
174
+ const shiftDirection = index % 2 === 0 ? 'x' : 'y';
175
+ if (shiftDirection === 'x') {
176
+ if (index === 0) {
177
+ shift.x = Math.max(box.corners[index].x + shift.x, itemBoxMax.x) - startPoint.x;
178
+ if (this.isShiftDown || this.isLockScale) {
179
+ const expandBox = this.getExpandBox();
180
+ const { x: boxWidth, y: boxHeight } = expandBox.getSize();
181
+ this.interactionParam.lockedAspect ??= boxWidth / boxHeight;
182
+ shift.y = shift.x / this.interactionParam.lockedAspect;
183
+ const resuleTargetCornerY = nextCorner.y + shift.y;
184
+ const clampResultCornerY = Math.max(resuleTargetCornerY, itemBoxMax.y);
185
+ shift.y = clampResultCornerY - nextCorner.y;
186
+ shift.x = shift.y * this.interactionParam.lockedAspect;
187
+ }
188
+ else {
189
+ shift.y = 0;
190
+ }
191
+ }
192
+ else if (index === 2) {
193
+ shift.x = Math.min(box.corners[index].x + shift.x, itemBoxMin.x) - startPoint.x;
194
+ if (this.isShiftDown || this.isLockScale) {
195
+ const expandBox = this.getExpandBox();
196
+ const { x: boxWidth, y: boxHeight } = expandBox.getSize();
197
+ this.interactionParam.lockedAspect ??= boxWidth / boxHeight;
198
+ shift.y = shift.x / this.interactionParam.lockedAspect;
199
+ const resuleTargetCornerY = nextCorner.y + shift.y;
200
+ const clampResultCornerY = Math.min(resuleTargetCornerY, itemBoxMin.y);
201
+ shift.y = clampResultCornerY - nextCorner.y;
202
+ shift.x = shift.y * this.interactionParam.lockedAspect;
203
+ }
204
+ else {
205
+ shift.y = 0;
206
+ }
207
+ }
208
+ }
209
+ else {
210
+ if (index === 1) {
211
+ shift.y = Math.max(box.corners[index].y + shift.y, itemBoxMax.y) - startPoint.y;
212
+ if (this.isShiftDown || this.isLockScale) {
213
+ const expandBox = this.getExpandBox();
214
+ const { x: boxWidth, y: boxHeight } = expandBox.getSize();
215
+ this.interactionParam.lockedAspect ??= boxWidth / boxHeight;
216
+ shift.x = -shift.y * this.interactionParam.lockedAspect;
217
+ const resuleTargetCornerX = nextCorner.x + shift.x;
218
+ const clampResultCornerX = Math.min(resuleTargetCornerX, itemBoxMin.x);
219
+ shift.x = clampResultCornerX - nextCorner.x;
220
+ shift.y = -shift.x / this.interactionParam.lockedAspect;
221
+ }
222
+ else {
223
+ shift.x = 0;
224
+ }
225
+ }
226
+ else if (index === 3) {
227
+ shift.y = Math.min(box.corners[index].y + shift.y, itemBoxMin.y) - startPoint.y;
228
+ if (this.isShiftDown || this.isLockScale) {
229
+ const expandBox = this.getExpandBox();
230
+ const { x: boxWidth, y: boxHeight } = expandBox.getSize();
231
+ this.interactionParam.lockedAspect ??= boxWidth / boxHeight;
232
+ shift.x = -shift.y * this.interactionParam.lockedAspect;
233
+ const resuleTargetCornerX = nextCorner.x + shift.x;
234
+ const clampResultCornerX = Math.max(resuleTargetCornerX, itemBoxMax.x);
235
+ shift.x = clampResultCornerX - nextCorner.x;
236
+ shift.y = -shift.x / this.interactionParam.lockedAspect;
237
+ }
238
+ else {
239
+ shift.x = 0;
240
+ }
241
+ }
242
+ }
243
+ const resultCorners = [];
244
+ box.corners.forEach((corner, i) => {
245
+ const resultCorner = new Vector2();
246
+ if (index === i) {
247
+ if (shiftDirection === 'y') {
248
+ resultCorner.copyFrom(corner.clone().add(new Vector2(0, shift.y)));
249
+ }
250
+ else {
251
+ resultCorner.copyFrom(corner.clone().add(new Vector2(shift.x, 0)));
252
+ }
253
+ }
254
+ else if (index === (i + 3) % 4) {
255
+ resultCorner.copyFrom(corner.clone().add(shift));
256
+ }
257
+ else if (index === (i + 2) % 4) {
258
+ if (shiftDirection === 'x') {
259
+ resultCorner.copyFrom(corner.clone().add(new Vector2(0, shift.y)));
260
+ }
261
+ else {
262
+ resultCorner.copyFrom(corner.clone().add(new Vector2(shift.x, 0)));
263
+ }
264
+ }
265
+ else {
266
+ resultCorner.copyFrom(corner.clone());
267
+ }
268
+ resultCorners.push(resultCorner);
269
+ });
270
+ this.result.normalizeExpandBox = getNormalizeBoxByBoxes(itemBox, new Box2().setFromVec2Array(resultCorners));
271
+ this._eventEmitter.emit('expandBoxChange', this.getExpandBox());
272
+ break;
273
+ }
274
+ default:
275
+ break;
276
+ }
277
+ }
278
+ endAction(event) {
279
+ if (!this.interactive || this.interactionParam.type === 'none') {
280
+ return undefined;
281
+ }
282
+ const mouse = new Vector2(event.offsetX, event.offsetY);
283
+ const clinetMouse = new Vector2(event.clientX, event.clientY);
284
+ this.refreshInteractionType(mouse, clinetMouse);
285
+ return this.type;
286
+ }
287
+ interruption() {
288
+ this.interactionParam = { type: 'none' };
289
+ return undefined;
290
+ }
291
+ actionKey(keyCode) {
292
+ this.isShiftDown = keyCode.shiftKey;
293
+ }
294
+ endActionKey(keyCode) {
295
+ this.isShiftDown = keyCode.shiftKey;
296
+ if ('lockedAspect' in this.interactionParam) {
297
+ delete this.interactionParam.lockedAspect;
298
+ }
299
+ }
300
+ cancelPreparation() {
301
+ this.interactionParam = { type: 'none' };
302
+ }
303
+ refreshResults() {
304
+ if (this.interactive) {
305
+ const pageData = this._pageDataUtils.getPageData();
306
+ assertExist(pageData, 'You must call SDK#run() first');
307
+ if (pageData.activeData.selectedItems.length !== 1) {
308
+ console.warn('Picture Expand Gizmo can edit one picture at a time.');
309
+ }
310
+ else {
311
+ if (this.result.type === 'invalid') {
312
+ const itemViewBox = this._pageDataUtils.getViewBoxById(pageData.activeData.selectedItems[0]);
313
+ this.result = {
314
+ type: 'valid',
315
+ itemBox: itemViewBox.clone(),
316
+ normalizeExpandBox: new Box2(new Vector2(), new Vector2(1, 1)),
317
+ };
318
+ }
319
+ else {
320
+ const currentViewBox = this._pageDataUtils.getViewBoxById(pageData.activeData.selectedItems[0]);
321
+ const shift = currentViewBox.getCenter().subtract(this.result.itemBox.getCenter());
322
+ const scaleValue = currentViewBox.getSize().x / this.result.itemBox.getSize().x;
323
+ this.result.itemBox.translate(shift);
324
+ this.result.itemBox.scale(scaleValue);
325
+ }
326
+ }
327
+ }
328
+ else {
329
+ this.result = { type: 'invalid' };
330
+ }
331
+ }
332
+ refreshRenderObjects() {
333
+ this.graphics.clear();
334
+ if (!this.interactive || this.result.type === 'invalid') {
335
+ return [];
336
+ }
337
+ const { maskColor, maskAlpha, expandBoxLineWidth, expandBoxLineColor, expandBoxLineAlpha, expandBoxCornerRadius, expandBoxCornerFillColor, expandBoxCornerLineWidth, expandBoxCornerLineColor, expandBoxCornerLineAlpha, gridLineWidth, gridLineColor, gridLineAlpha, gridCount, } = SDK.config.gestureHandlerConfig.pictureExpandGizmoConfig;
338
+ const { normalizeExpandBox, itemBox } = this.result;
339
+ const expandBox = getBoxByNormalizeBox(itemBox, normalizeExpandBox);
340
+ // 绘制蒙版层
341
+ this.graphics.beginFill(maskColor, maskAlpha);
342
+ this.graphics.fillBox(expandBox);
343
+ this.graphics.endFill();
344
+ // 绘制网格线
345
+ const { min: expandMin, max: expandMax } = expandBox;
346
+ const xShift = expandBox.getSize().x / (gridCount + 1);
347
+ const yShift = expandBox.getSize().y / (gridCount + 1);
348
+ this.graphics.lineStyle(gridLineWidth, gridLineColor, gridLineAlpha);
349
+ for (let i = 1; i <= gridCount; i++) {
350
+ const xGridLine = new Line2(new Vector2(expandMin.x + xShift * i, expandMin.y), new Vector2(expandMin.x + xShift * i, expandMax.y));
351
+ const yGridLine = new Line2(new Vector2(expandMin.x, expandMin.y + yShift * i), new Vector2(expandMax.x, expandMin.y + yShift * i));
352
+ this.graphics.drawLine(xGridLine);
353
+ this.graphics.drawLine(yGridLine);
354
+ }
355
+ // 绘制扩边包围盒
356
+ this.graphics.lineStyle(expandBoxLineWidth, expandBoxLineColor, expandBoxLineAlpha);
357
+ this.graphics.drawBox(expandBox);
358
+ // 绘制角点
359
+ this.graphics.beginFill(expandBoxCornerFillColor);
360
+ this.graphics.lineStyle(expandBoxCornerLineWidth, expandBoxCornerLineColor, expandBoxCornerLineAlpha);
361
+ expandBox.corners.forEach(corner => {
362
+ this.graphics.drawCircle(corner.x, corner.y, expandBoxCornerRadius);
363
+ });
364
+ this.graphics.endFill();
365
+ return [this.graphics];
366
+ }
367
+ /**
368
+ * 刷新指针结果
369
+ * @param activeType 交互类型
370
+ * @param point 指针位置
371
+ * @param dir 指针方向
372
+ */
373
+ refreshCursorResult(activeType, angle = 0) {
374
+ switch (activeType) {
375
+ case 'scale': {
376
+ this.cursorResult = {
377
+ type: 'scale',
378
+ angle,
379
+ };
380
+ break;
381
+ }
382
+ case 'direction-scale': {
383
+ this.cursorResult = {
384
+ type: 'scale',
385
+ angle,
386
+ };
387
+ break;
388
+ }
389
+ case 'move':
390
+ case 'none': {
391
+ this.cursorResult = {
392
+ type: 'normal',
393
+ angle: 0,
394
+ };
395
+ break;
396
+ }
397
+ }
398
+ }
399
+ getRenderObjects() {
400
+ if (!this.interactive) {
401
+ return [];
402
+ }
403
+ else {
404
+ return this.refreshRenderObjects();
405
+ }
406
+ }
407
+ refreshInteractionType(point, clientMouse) {
408
+ this.interactionParam.type = 'none';
409
+ if (!this.interactive || this.result.type === 'invalid') {
410
+ return;
411
+ }
412
+ const { normalizeExpandBox, itemBox } = this.result;
413
+ const expandBox = getBoxByNormalizeBox(itemBox, normalizeExpandBox);
414
+ let hasInteractionType = false;
415
+ let angle = 0;
416
+ // 判定交互状态 - 缩放
417
+ expandBox.corners.forEach((corner, index) => {
418
+ if (hasInteractionType) {
419
+ return;
420
+ }
421
+ if (corner.distanceTo(point) < SDK.config.gestureHandlerConfig.pictureExpandGizmoConfig.scaleInteractionDistance) {
422
+ hasInteractionType = true;
423
+ this.interactionParam = {
424
+ type: 'scale',
425
+ index,
426
+ box: expandBox.clone(),
427
+ startMouse: clientMouse,
428
+ };
429
+ angle = Math.PI / 2 * index;
430
+ }
431
+ });
432
+ // 判定交互状态 - 单向缩放
433
+ expandBox.corners.forEach((corner, index) => {
434
+ if (hasInteractionType) {
435
+ return;
436
+ }
437
+ const edge = new Line2(corner.clone(), expandBox.corners[(index + 1) % 4]);
438
+ const dis = point.distanceToLine(edge);
439
+ const state = dis.d >= 0 && dis.d <= 8 && dis.t >= 0 && dis.t <= 1;
440
+ if (state) {
441
+ hasInteractionType = true;
442
+ this.interactionParam = {
443
+ type: 'direction-scale',
444
+ index,
445
+ box: expandBox.clone(),
446
+ startMouse: clientMouse,
447
+ };
448
+ angle = Math.PI / 2 * index + Math.PI / 4;
449
+ }
450
+ });
451
+ // 判定交互状态 - 移动
452
+ if (expandBox.containsPoint(point) && !hasInteractionType) {
453
+ this.interactionParam = { type: 'move', box: expandBox.clone(), startMouse: clientMouse };
454
+ hasInteractionType = true;
455
+ }
456
+ this.refreshCursorResult(this.interactionParam.type, angle * RAD2DEG);
457
+ }
458
+ getExpandInfo() {
459
+ const [item] = this._pageDataUtils.getSelectedItems();
460
+ if (!this.interactive || this.result.type === 'invalid' || !item) {
461
+ return undefined;
462
+ }
463
+ // 真实包围盒信息
464
+ return {
465
+ expandBox: this.getExpandBox(),
466
+ itemBox: this._pageDataUtils.getItemBoxById(item.id),
467
+ };
468
+ }
469
+ getExpandBox() {
470
+ const [item] = this._pageDataUtils.getSelectedItems();
471
+ if (!this.interactive || this.result.type === 'invalid' || !item) {
472
+ return undefined;
473
+ }
474
+ const originBox = this._pageDataUtils.getItemBoxById(item.id);
475
+ const { normalizeExpandBox } = this.result;
476
+ return getBoxByNormalizeBox(originBox, normalizeExpandBox);
477
+ }
478
+ setExpandBox(min, max) {
479
+ const [item] = this._pageDataUtils.getSelectedItems();
480
+ if (!this.interactive || this.result.type === 'invalid' || !item) {
481
+ return undefined;
482
+ }
483
+ const currentBox = new Box2(min, max);
484
+ const originBox = this._pageDataUtils.getItemBoxById(item.id);
485
+ const { min: expandBoxMin, max: expandBoxMax } = getNormalizeBoxByBoxes(originBox, currentBox);
486
+ this.result.normalizeExpandBox.set(new Vector2(Math.min(expandBoxMin.x, 0), Math.min(expandBoxMin.y, 0)), new Vector2(Math.max(expandBoxMax.x, 1), Math.max(expandBoxMax.y, 1)));
487
+ const expandBox = this.getExpandBox();
488
+ this._eventEmitter.emit('expandBoxChange', expandBox);
489
+ return expandBox;
490
+ }
491
+ }
@@ -0,0 +1,148 @@
1
+ import { SDK } from '../../sdk';
2
+ import { Box2, Vector2 } from '../../math';
3
+ import { assertExist } from '../../shared';
4
+ import { Graphics, Sprite } from '../../wireframe';
5
+ import { Gizmo } from './gizmo';
6
+ export class PreferenceGizmo extends Gizmo {
7
+ safeAreaSprites = new Map();
8
+ preparationAction() {
9
+ return undefined;
10
+ }
11
+ preAction() {
12
+ return undefined;
13
+ }
14
+ action() { }
15
+ endAction() {
16
+ return undefined;
17
+ }
18
+ interruption() {
19
+ return undefined;
20
+ }
21
+ actionKey() { }
22
+ endActionKey() { }
23
+ cancelPreparation() { }
24
+ refreshResults() {
25
+ this.box = new Box2();
26
+ if (!this.interactive) {
27
+ console.warn('Preference gizmo is not opened, use #SDK.setAdsorptionConfig() open this feature.');
28
+ return;
29
+ }
30
+ if (SDK.config.mode === 'editor') {
31
+ return;
32
+ }
33
+ const pageData = this.PageDataUtils.getPageData();
34
+ assertExist(pageData);
35
+ const { container } = this.PageDataUtils;
36
+ if (container) {
37
+ const { zoom } = pageData.property;
38
+ const { offsetWidth, offsetHeight } = container;
39
+ const playerViewSize = new Vector2(offsetWidth, offsetHeight).multiply(zoom);
40
+ const center = this.PageDataUtils.getViewportLeftTopPosition().add(playerViewSize.clone().divide(2));
41
+ this.box = new Box2().setFromCenterAndSize(center, playerViewSize);
42
+ }
43
+ }
44
+ refreshRenderObjects() {
45
+ if (SDK.config.mode === 'editor') {
46
+ return;
47
+ }
48
+ const { boxWidth, boxColor, markColor, markAlpha, safeAreaEnabled, safeAreaBoxColor, safeAreaBoxAlpha, } = SDK.config.gestureHandlerConfig.preferenceGizmoConfig;
49
+ this.graphics = new Graphics();
50
+ const { offsetWidth: width, offsetHeight: height } = this.PageDataUtils.container.parentElement;
51
+ const box1 = new Box2(new Vector2(0, 0), new Vector2(width, this.box.min.y));
52
+ const box2 = new Box2(new Vector2(0, this.box.min.y), new Vector2(this.box.min.x, height));
53
+ const box3 = new Box2(new Vector2(this.box.min.x, this.box.max.y), new Vector2(width, height));
54
+ const box4 = new Box2(new Vector2(this.box.max.x, this.box.min.y), new Vector2(width, this.box.max.y));
55
+ // 绘制渲染外区域
56
+ this.graphics.beginFill(markColor, markAlpha);
57
+ this.graphics.fillBox(box1);
58
+ this.graphics.fillBox(box2);
59
+ this.graphics.fillBox(box3);
60
+ this.graphics.fillBox(box4);
61
+ this.graphics.endFill();
62
+ // 绘制出血区域
63
+ if (safeAreaEnabled) {
64
+ const viewProperty = this.PageDataUtils.getViewProperty();
65
+ if (viewProperty) {
66
+ const { size, safeArea, previewSafeAreas } = viewProperty;
67
+ const [top, bottom, left, right] = safeArea;
68
+ const boxSize = this.box.getSize();
69
+ const topHeight = top / size[1] * boxSize.y;
70
+ const leftWidth = left / size[0] * boxSize.x;
71
+ const rightWidth = right / size[0] * boxSize.x;
72
+ const bottomHeight = bottom / size[1] * boxSize.y;
73
+ const { min, max } = this.box;
74
+ this.graphics.beginFill(safeAreaBoxColor, safeAreaBoxAlpha);
75
+ const topBox = new Box2(min, new Vector2(max.x, min.y + topHeight));
76
+ const leftBox = new Box2(new Vector2(min.x, min.y + topHeight), new Vector2(min.x + leftWidth, max.y));
77
+ const rightBox = new Box2(new Vector2(max.x - rightWidth, min.y + topHeight), new Vector2(max.x, max.y));
78
+ const bottomBox = new Box2(new Vector2(min.x + leftWidth, max.y - bottomHeight), new Vector2(max.x - rightWidth, max.y));
79
+ this.graphics.fillBox(topBox);
80
+ this.graphics.fillBox(leftBox);
81
+ this.graphics.fillBox(rightBox);
82
+ this.graphics.fillBox(bottomBox);
83
+ this.graphics.endFill();
84
+ previewSafeAreas.forEach(previewSafeArea => {
85
+ const { box: [left, top, safeAreaWidth, safeAreaHeight], color, url, visible } = previewSafeArea;
86
+ if (visible === false) {
87
+ return;
88
+ }
89
+ const previewSize = this.box.getSize();
90
+ const safeAreaSize = new Vector2(safeAreaWidth / size[0] * previewSize.x, safeAreaHeight / size[1] * previewSize.y);
91
+ const center = new Vector2(left / size[0] * previewSize.x + safeAreaSize.x / 2, top / size[1] * previewSize.y + safeAreaSize.y / 2).add(min);
92
+ const safeBox = new Box2().setFromCenterAndSize(center, safeAreaSize);
93
+ if (url) {
94
+ let sprite = this.safeAreaSprites.get(url);
95
+ if (!sprite) {
96
+ sprite = Sprite.from(url);
97
+ sprite.anchor.set(0.5, 0.5);
98
+ this.safeAreaSprites.set(url, sprite);
99
+ }
100
+ sprite.x = center.x;
101
+ sprite.y = center.y;
102
+ sprite.width = safeAreaSize.x;
103
+ sprite.height = safeAreaSize.y;
104
+ this.graphics.addChild(sprite);
105
+ }
106
+ else {
107
+ const alpha = color?.[3] ?? 0.3;
108
+ const colorValue = (color?.slice(0, 3) ?? [255, 0, 0]);
109
+ const resultColor = colorValue[0] << 16 | colorValue[1] << 8 | colorValue[2];
110
+ this.graphics.beginFill(resultColor, alpha);
111
+ this.graphics.fillBox(safeBox);
112
+ this.graphics.endFill();
113
+ }
114
+ });
115
+ }
116
+ }
117
+ // 绘制渲染边缘框
118
+ this.graphics.lineStyle(boxWidth, boxColor);
119
+ this.graphics.drawBox(this.box);
120
+ }
121
+ getRenderObjects() {
122
+ if (!SDK.config.gestureHandlerConfig.preferenceGizmoEnabled || SDK.config.mode === 'editor') {
123
+ return [];
124
+ }
125
+ this.refreshRenderObjects();
126
+ return [this.graphics];
127
+ }
128
+ /**
129
+ * 遮挡层绘制结果
130
+ */
131
+ box = new Box2();
132
+ /**
133
+ * 视图框图形
134
+ */
135
+ graphics = new Graphics();
136
+ PageDataUtils;
137
+ type = 'preference';
138
+ constructor(utils) {
139
+ super();
140
+ this.PageDataUtils = utils;
141
+ }
142
+ get interactive() {
143
+ return SDK.config.gestureHandlerConfig.preferenceGizmoEnabled;
144
+ }
145
+ set interactive(bool) {
146
+ SDK.config.gestureHandlerConfig.preferenceGizmoEnabled = bool;
147
+ }
148
+ }
@@ -1,6 +1,6 @@
1
1
  import { Graphics } from '@pixi/graphics';
2
2
  import '../../wireframe/common/pixi-ext';
3
- import { Composition } from '../../shared/player';
3
+ import { Composition } from '../../shared';
4
4
  import { Gizmo } from './gizmo';
5
5
  import type { GizmoType, HitTestResult, SelectorResult } from './type';
6
6
  import type { PageDataUtils } from '../../utils/page-data-utils';