@gedit/editor-2d 0.3.9 → 0.3.11

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 (53) hide show
  1. package/lib/browser/model/editor2d-document.d.ts +3 -1
  2. package/lib/browser/model/editor2d-document.d.ts.map +1 -1
  3. package/lib/browser/model/editor2d-document.js +18 -12
  4. package/lib/browser/model/editor2d-document.js.map +1 -1
  5. package/lib/browser/model/utils/anim.utils.d.ts +1 -0
  6. package/lib/browser/model/utils/anim.utils.d.ts.map +1 -1
  7. package/lib/browser/model/utils/anim.utils.js +22 -0
  8. package/lib/browser/model/utils/anim.utils.js.map +1 -1
  9. package/lib/browser/playground/anim-path-edit-layer.d.ts.map +1 -1
  10. package/lib/browser/playground/anim-path-edit-layer.js +5 -3
  11. package/lib/browser/playground/anim-path-edit-layer.js.map +1 -1
  12. package/lib/browser/playground/canvas-draw.d.ts +1 -0
  13. package/lib/browser/playground/canvas-draw.d.ts.map +1 -1
  14. package/lib/browser/playground/canvas-draw.js +26 -11
  15. package/lib/browser/playground/canvas-draw.js.map +1 -1
  16. package/lib/browser/playground/canvas-layer.d.ts +1 -2
  17. package/lib/browser/playground/canvas-layer.d.ts.map +1 -1
  18. package/lib/browser/playground/canvas-layer.js +53 -44
  19. package/lib/browser/playground/canvas-layer.js.map +1 -1
  20. package/lib/browser/playground/extend-edit/gradient-conic-node.js +4 -4
  21. package/lib/browser/playground/extend-edit/gradient-conic-node.js.map +1 -1
  22. package/lib/browser/playground/extend-edit/gradient-node.d.ts.map +1 -1
  23. package/lib/browser/playground/extend-edit/gradient-node.js +3 -3
  24. package/lib/browser/playground/extend-edit/gradient-node.js.map +1 -1
  25. package/lib/browser/playground/path-edit/utils.d.ts +2 -2
  26. package/lib/browser/playground/path-edit/utils.d.ts.map +1 -1
  27. package/lib/browser/playground/path-edit/utils.js +55 -45
  28. package/lib/browser/playground/path-edit/utils.js.map +1 -1
  29. package/lib/browser/playground/path-edit-layer.d.ts +11 -1
  30. package/lib/browser/playground/path-edit-layer.d.ts.map +1 -1
  31. package/lib/browser/playground/path-edit-layer.js +242 -75
  32. package/lib/browser/playground/path-edit-layer.js.map +1 -1
  33. package/lib/browser/playground/selection-entity-manager.d.ts.map +1 -1
  34. package/lib/browser/playground/selection-entity-manager.js +60 -10
  35. package/lib/browser/playground/selection-entity-manager.js.map +1 -1
  36. package/lib/browser/utils/bounds.js +4 -4
  37. package/lib/browser/utils/snapshot.d.ts.map +1 -1
  38. package/lib/browser/utils/snapshot.js +2 -1
  39. package/lib/browser/utils/snapshot.js.map +1 -1
  40. package/package.json +9 -9
  41. package/src/browser/model/editor2d-document.ts +22 -12
  42. package/src/browser/model/utils/anim.utils.ts +24 -0
  43. package/src/browser/playground/anim-path-edit-layer.tsx +8 -4
  44. package/src/browser/playground/canvas-draw.ts +24 -6
  45. package/src/browser/playground/canvas-layer.ts +25 -14
  46. package/src/browser/playground/extend-edit/gradient-conic-node.tsx +4 -4
  47. package/src/browser/playground/extend-edit/gradient-node.tsx +3 -2
  48. package/src/browser/playground/path-edit/utils.tsx +56 -54
  49. package/src/browser/playground/path-edit-layer.tsx +310 -74
  50. package/src/browser/playground/selection-entity-manager.tsx +127 -30
  51. package/src/browser/utils/bounds.ts +4 -4
  52. package/src/browser/utils/snapshot.ts +1 -0
  53. package/LICENSE +0 -21
@@ -23,7 +23,12 @@ import {
23
23
  toFixedValue,
24
24
  } from '@gedit/canvas-draw';
25
25
 
26
- import { deepClone, Disposable, generateUuid } from '@gedit/utils';
26
+ import {
27
+ deepClone,
28
+ Disposable,
29
+ DisposableCollection,
30
+ generateUuid,
31
+ } from '@gedit/utils';
27
32
  import {
28
33
  PointSchema,
29
34
  SvgPath,
@@ -69,6 +74,9 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
69
74
 
70
75
  currentPathNode?: Editor2dPathNode;
71
76
  startPos?: PathChild;
77
+
78
+ // 访录当前图层在 timeline 里的监听事件
79
+ layerDisposeMap = new Map<string, Disposable>();
72
80
  protected bezierStartPos?: {
73
81
  x: number;
74
82
  y: number;
@@ -76,6 +84,8 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
76
84
  path: PathChild;
77
85
  };
78
86
 
87
+ protected docDispose?: Disposable;
88
+
79
89
  get document(): Editor2dDocument | undefined {
80
90
  return this.documentEntity.config.document;
81
91
  }
@@ -99,40 +109,49 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
99
109
  this.startPos = undefined;
100
110
  this.pathPointSelection!.clearSelection();
101
111
  this.pathPointSelection!.selectMode = PathSelectMode.ADD_PATH;
112
+ this.docDispose?.dispose();
102
113
  }
103
114
  updateNodeData(): void {
104
- const nodeData = updatePathNodeData(this.currentPathNode!);
105
- this.document?.updateNode(this.currentPathNode!, nodeData, true);
106
- }
107
- updateNodePathData(): void {
108
115
  if (!this.currentPathNode) {
109
116
  return;
110
117
  }
111
- const { origin = { x: 0.5, y: 0.5 }, size, path } = this.currentPathNode;
112
- const { origin: oldOrigin = { x: 0.5, y: 0.5 }, paths } = path;
113
- const diff = {
114
- x: toFixedValue((oldOrigin.x - origin.x) * (size?.width || 0), 4),
115
- y: toFixedValue((oldOrigin.y - origin.y) * (size?.height || 0), 4),
116
- };
117
- paths.forEach(item => {
118
- item.x += diff.x;
119
- item.y += diff.y;
120
- if (typeof item.x1 === 'number') {
121
- item.x1 += diff.x;
122
- }
123
- if (typeof item.x2 === 'number') {
124
- item.x2 += diff.x;
125
- }
126
- if (typeof item.y1 === 'number') {
127
- item.y1 += diff.y;
128
- }
129
- if (typeof item.y2 === 'number') {
130
- item.y2 += diff.y;
131
- }
132
- });
133
- path.origin = origin;
134
- this.document?.updateNode(this.currentPathNode, { path }, true);
118
+ const nodeData = updatePathNodeData(this.currentPathNode);
119
+ // console.log('updateNodeData', nodeData);
120
+ // 直接更新数据,,动画 updateAnimationNode 里会把数据删了;
121
+ this.currentPathNode.path = nodeData.path;
122
+ this.document?.updateNode(this.currentPathNode, nodeData, true);
135
123
  }
124
+ // updateNodePathData(): void {
125
+ // if (!this.currentPathNode) {
126
+ // return;
127
+ // }
128
+ // const { origin = { x: 0.5, y: 0.5 }, size, path } = this.currentPathNode;
129
+ // const { origin: oldOrigin = { x: 0.5, y: 0.5 }, paths } = path;
130
+ // const diff = {
131
+ // x: toFixedValue((oldOrigin.x - origin.x) * (size?.width || 0), 4),
132
+ // y: toFixedValue((oldOrigin.y - origin.y) * (size?.height || 0), 4),
133
+ // };
134
+ // paths.forEach(item => {
135
+ // item.x += diff.x;
136
+ // item.y += diff.y;
137
+ // if (typeof item.x1 === 'number') {
138
+ // item.x1 += diff.x;
139
+ // }
140
+ // if (typeof item.x2 === 'number') {
141
+ // item.x2 += diff.x;
142
+ // }
143
+ // if (typeof item.y1 === 'number') {
144
+ // item.y1 += diff.y;
145
+ // }
146
+ // if (typeof item.y2 === 'number') {
147
+ // item.y2 += diff.y;
148
+ // }
149
+ // });
150
+
151
+ // path.origin = origin;
152
+ // console.log(path);
153
+ // this.document?.updateNode(this.currentPathNode, { path }, true);
154
+ // }
136
155
 
137
156
  // 选中的是第一个点
138
157
  protected isOnePoint(point?: PathChild): boolean {
@@ -172,6 +191,52 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
172
191
  );
173
192
  }
174
193
 
194
+ protected updateTimelineCurrentFrameDataToCurrentNode(): void {
195
+ if (!this.currentPathNode) {
196
+ return;
197
+ }
198
+ const timelineData = this.document?.timelineService?.currentTimelineData;
199
+ if (!timelineData) {
200
+ return;
201
+ }
202
+ const { frames = [] } = timelineData;
203
+ const currentFrame = frames.find(c => c.id === this.currentPathNode?.id);
204
+ if (currentFrame) {
205
+ const currentValues = this.document?.timelineService?.getNodeCurrentFrame(
206
+ currentFrame
207
+ );
208
+ if (currentValues && currentValues['path.paths']) {
209
+ this.currentPathNode.path.paths = (deepClone(
210
+ currentValues['path.paths']
211
+ ) as unknown) as PathChild[];
212
+ }
213
+ }
214
+ }
215
+
216
+ // 注册监听时间轴事件
217
+ protected onRegisterTimelineEvent(): void {
218
+ if (!this.currentPathNode || !this.document?.timelineService) {
219
+ return;
220
+ }
221
+ const currentDisposeCache = this.layerDisposeMap.get(
222
+ this.currentPathNode.id
223
+ );
224
+ if (!currentDisposeCache) {
225
+ const currentDispose = new DisposableCollection();
226
+ currentDispose.pushAll([
227
+ this.document.timelineService.onTimelineCurrentTimeChange(() => {
228
+ this.updateTimelineCurrentFrameDataToCurrentNode();
229
+ this.draw();
230
+ }),
231
+ this.document.timelineService.onTimelineChangeData(() => {
232
+ this.updateTimelineCurrentFrameDataToCurrentNode();
233
+ this.draw();
234
+ }),
235
+ ]);
236
+ this.layerDisposeMap.set(this.currentPathNode.id, currentDispose);
237
+ }
238
+ }
239
+
175
240
  onReady(): void {
176
241
  this.addDispose([
177
242
  this.context.historyService.onHistoryBack(e => {
@@ -189,6 +254,7 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
189
254
  * -- 2. 非闭合路径时,切换编辑模式;
190
255
  * - 2. 未选中时节点时, 设置编辑模式;
191
256
  */
257
+ // console.log('path edit state change', e);
192
258
  if (!this.isEnabled) {
193
259
  this.reNodeData();
194
260
  } else {
@@ -196,12 +262,26 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
196
262
  return;
197
263
  }
198
264
  const selectNodes = this.document?.getSelectedNodes() || [];
199
- if (
200
- selectNodes.length &&
201
- selectNodes[0].displayType === GameObjectBaseType.PATH
202
- ) {
265
+
266
+ const pathSelectsNodes = selectNodes.filter(
267
+ c => c.displayType === GameObjectBaseType.PATH
268
+ );
269
+
270
+ if (selectNodes.length && pathSelectsNodes.length) {
203
271
  // 选中一个 path 路径时;
204
- this.currentPathNode = selectNodes[0] as Editor2dPathNode;
272
+ this.currentPathNode = deepClone(
273
+ pathSelectsNodes[0]
274
+ ) as Editor2dPathNode;
275
+ if (
276
+ this.currentPathNode.useAnimationId &&
277
+ this.document?.timelineService?.currentTimelineData &&
278
+ this.document.timelineService.currentTimelineData.id ===
279
+ this.currentPathNode.useAnimationId
280
+ ) {
281
+ this.updateTimelineCurrentFrameDataToCurrentNode();
282
+ this.onRegisterTimelineEvent();
283
+ }
284
+
205
285
  const selectionNode = [
206
286
  {
207
287
  pointId: this.currentPathNode.path.paths[
@@ -213,7 +293,56 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
213
293
  ? this.pathPointSelection.enterSelectBezierMode(selectionNode)
214
294
  : this.pathPointSelection.enterPathMode(selectionNode);
215
295
  // 如果中心点不同,更新数据;
216
- this.updateNodePathData();
296
+ if (
297
+ (this.currentPathNode.origin?.x ||
298
+ this.currentPathNode.origin?.y) &&
299
+ !this.currentPathNode.path.originChangeBeforeSize
300
+ ) {
301
+ // 初始 origin 是照这个宽度算的;计算偏差使用;
302
+ this.currentPathNode.path.originChangeBeforeSize = {
303
+ width: this.currentPathNode.size?.width || 0,
304
+ height: this.currentPathNode.size?.height || 0,
305
+ };
306
+
307
+ this.document?.updateNode(
308
+ this.currentPathNode,
309
+ this.currentPathNode,
310
+ true
311
+ );
312
+ } else if (
313
+ !this.currentPathNode.origin?.x &&
314
+ !this.currentPathNode.origin?.y &&
315
+ this.currentPathNode.path.originChangeBeforeSize
316
+ ) {
317
+ delete this.currentPathNode.path.originChangeBeforeSize;
318
+ this.document?.updateNode(
319
+ this.currentPathNode,
320
+ this.currentPathNode,
321
+ true
322
+ );
323
+ }
324
+ this.docDispose = this.document?.onContentChanged(c => {
325
+ const newNode = c.nodes?.find(
326
+ c => c.id === this.currentPathNode?.id
327
+ ) as Editor2dPathNode;
328
+ if (
329
+ newNode &&
330
+ JSON.stringify(newNode.path.paths) !==
331
+ JSON.stringify(this.currentPathNode?.path.paths)
332
+ ) {
333
+ // 属性栏修改数据时,数据源不是同一个,需要手动更新数据
334
+ this.currentPathNode = newNode;
335
+ if (
336
+ this.currentPathNode.useAnimationId &&
337
+ this.document?.timelineService?.currentTimelineData &&
338
+ this.document.timelineService.currentTimelineData.id ===
339
+ this.currentPathNode.useAnimationId
340
+ ) {
341
+ this.updateTimelineCurrentFrameDataToCurrentNode();
342
+ this.draw();
343
+ }
344
+ }
345
+ });
217
346
  } else if (!selectNodes.length) {
218
347
  // 未选中时,清空数据
219
348
  this.pathPointSelection.selectMode = PathSelectMode.ADD_PATH;
@@ -236,11 +365,16 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
236
365
  scale = { x: 1, y: 1 },
237
366
  rotation = 0,
238
367
  } = this.currentPathNode!;
368
+ const offset = this.getBoundsOffset();
369
+ const center = {
370
+ x: -offset.x,
371
+ y: -offset.y,
372
+ };
239
373
  paths.forEach(p => {
240
374
  const { x: $x, y: $y } = p;
241
375
  let x = $x;
242
376
  let y = $y;
243
- const r = transformToData({ x, y }, { scale, rotation });
377
+ const r = transformToData({ x, y }, { scale, rotation }, center);
244
378
  x = r.x + position.x;
245
379
  y = r.y + position.y;
246
380
  const wh = (4 / this.config.finalScale) * 2;
@@ -310,11 +444,23 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
310
444
  scale = { x: 1, y: 1 },
311
445
  rotation = 0,
312
446
  } = this.currentPathNode || {};
313
- let x = e.endPos.x / (this.config?.finalScale || 1) - position.x;
314
- let y = e.endPos.y / (this.config?.finalScale || 1) - position.y;
447
+ const offset = this.getBoundsOffset();
448
+ let x =
449
+ e.endPos.x / (this.config?.finalScale || 1) -
450
+ position.x -
451
+ offset.x;
452
+ let y =
453
+ e.endPos.y / (this.config?.finalScale || 1) -
454
+ position.y -
455
+ offset.y;
456
+ const center = {
457
+ x: -offset.x,
458
+ y: -offset.y,
459
+ };
315
460
  const { x: rx, y: ry } = inverseTransformToData(
316
461
  { x, y },
317
- { scale, rotation }
462
+ { scale, rotation },
463
+ center
318
464
  );
319
465
  x = rx;
320
466
  y = ry;
@@ -343,11 +489,23 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
343
489
  scale = { x: 1, y: 1 },
344
490
  rotation = 0,
345
491
  } = this.currentPathNode || {};
346
- let x = e.endPos.x / (this.config?.finalScale || 1) - position.x;
347
- let y = e.endPos.y / (this.config?.finalScale || 1) - position.y;
492
+ const offset = this.getBoundsOffset();
493
+ let x =
494
+ e.endPos.x / (this.config?.finalScale || 1) -
495
+ position.x -
496
+ offset.x;
497
+ let y =
498
+ e.endPos.y / (this.config?.finalScale || 1) -
499
+ position.y -
500
+ offset.y;
501
+ const center = {
502
+ x: -offset.x,
503
+ y: -offset.y,
504
+ };
348
505
  const { x: rx, y: ry } = inverseTransformToData(
349
506
  { x, y },
350
- { scale, rotation }
507
+ { scale, rotation },
508
+ center
351
509
  );
352
510
  x = rx;
353
511
  y = ry;
@@ -366,10 +524,10 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
366
524
  const x1 = pathNode.x * 2 - x;
367
525
  const y1 = pathNode.y * 2 - y;
368
526
  const reverse = this.isOnePoint();
369
- pathNode.x2 = toFixedValue(reverse ? x1 : x, 4);
370
- pathNode.y2 = toFixedValue(reverse ? y1 : y, 4);
371
- pathNode.x1 = toFixedValue(reverse ? x : x1, 4);
372
- pathNode.y1 = toFixedValue(reverse ? y : y1, 4);
527
+ pathNode.x2 = toFixedValue(reverse ? x1 : x, 2);
528
+ pathNode.y2 = toFixedValue(reverse ? y1 : y, 2);
529
+ pathNode.x1 = toFixedValue(reverse ? x : x1, 2);
530
+ pathNode.y1 = toFixedValue(reverse ? y : y1, 2);
373
531
  pathNode.type = PATH_FUNC_TYPE.EQUAL;
374
532
  // console.log(this.startPos, path?.paths);
375
533
  this.updateNodeData();
@@ -418,6 +576,15 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
418
576
  ) {
419
577
  // 选中的不是当前的 path 路径, 切换 currentPathNode;
420
578
  this.currentPathNode = selectNodes[0] as Editor2dPathNode;
579
+ if (
580
+ this.currentPathNode.useAnimationId &&
581
+ this.document?.timelineService?.currentTimelineData &&
582
+ this.document.timelineService.currentTimelineData.id ===
583
+ this.currentPathNode.useAnimationId
584
+ ) {
585
+ this.updateTimelineCurrentFrameDataToCurrentNode();
586
+ this.onRegisterTimelineEvent();
587
+ }
421
588
  const selectionNode = [
422
589
  {
423
590
  pointId: this.currentPathNode.path.paths[
@@ -429,7 +596,7 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
429
596
  this.currentPathNode.path.closed
430
597
  ? pathPointSelection.enterSelectBezierMode(selectionNode)
431
598
  : pathPointSelection.enterPathMode(selectionNode);
432
- this.updateNodePathData();
599
+ // this.updateNodePathData();
433
600
  }
434
601
  return;
435
602
  }
@@ -452,6 +619,34 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
452
619
  ]);
453
620
  }
454
621
 
622
+ /**
623
+ * 获取偏差
624
+ */
625
+
626
+ getBoundsOffset(): { x: number; y: number } {
627
+ const { size = { width: 0, height: 0 }, origin = { x: 0, y: 0 }, path } =
628
+ this.currentPathNode || {};
629
+
630
+ const { originChangeBeforeSize } = path || {};
631
+
632
+ const offset = {
633
+ x: 0,
634
+ y: 0,
635
+ };
636
+
637
+ if (originChangeBeforeSize) {
638
+ offset.x = -origin.x * size.width;
639
+ offset.y = -origin.y * size.height;
640
+ if (originChangeBeforeSize.width !== size.width) {
641
+ offset.x += (size.width - originChangeBeforeSize.width) * origin.x;
642
+ }
643
+ if (originChangeBeforeSize.height !== size.height) {
644
+ offset.y += (size.height - originChangeBeforeSize.height) * origin.y;
645
+ }
646
+ }
647
+ return offset;
648
+ }
649
+
455
650
  /**
456
651
  * 创建路径
457
652
  * @param pos - 当前鼠标点击的位置
@@ -483,9 +678,9 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
483
678
  }
484
679
 
485
680
  // 创建时坐标是 0, 需要换线更新坐标;
486
- setTimeout(() => {
487
- this.updateNodeData();
488
- });
681
+ // setTimeout(() => {
682
+ // this.updateNodeData();
683
+ // });
489
684
  }
490
685
 
491
686
  protected onBezierPointMove(pos: PointSchema): void {
@@ -529,11 +724,19 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
529
724
  scale = { x: 1, y: 1 },
530
725
  rotation = 0,
531
726
  } = this.currentPathNode || {};
532
- let x = e.endPos.x / (this.config?.finalScale || 1) - position.x;
533
- let y = e.endPos.y / (this.config?.finalScale || 1) - position.y;
727
+ const offset = this.getBoundsOffset();
728
+ let x =
729
+ e.endPos.x / (this.config?.finalScale || 1) - position.x - offset.x;
730
+ let y =
731
+ e.endPos.y / (this.config?.finalScale || 1) - position.y - offset.y;
732
+ const center = {
733
+ x: -offset.x,
734
+ y: -offset.y,
735
+ };
534
736
  const { x: currentX, y: currentY } = inverseTransformToData(
535
737
  { x, y },
536
- { scale, rotation }
738
+ { scale, rotation },
739
+ center
537
740
  );
538
741
  x = currentX;
539
742
  y = currentY;
@@ -652,13 +855,23 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
652
855
  scale = { x: 1, y: 1 },
653
856
  rotation = 0,
654
857
  } = this.currentPathNode || {};
858
+ const offset = this.getBoundsOffset();
655
859
  let x =
656
- dragEvent.endPos.x / (this.config?.finalScale || 1) - position.x;
860
+ dragEvent.endPos.x / (this.config?.finalScale || 1) -
861
+ position.x -
862
+ offset.x;
657
863
  let y =
658
- dragEvent.endPos.y / (this.config?.finalScale || 1) - position.y;
864
+ dragEvent.endPos.y / (this.config?.finalScale || 1) -
865
+ position.y -
866
+ offset.y;
867
+ const center = {
868
+ x: -offset.x,
869
+ y: -offset.y,
870
+ };
659
871
  const { x: currentX, y: currentY } = inverseTransformToData(
660
872
  { x, y },
661
- { scale, rotation }
873
+ { scale, rotation },
874
+ center
662
875
  );
663
876
  x = currentX;
664
877
  y = currentY;
@@ -668,19 +881,19 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
668
881
  const deltaX = x - start.x + d.x;
669
882
  const deltaY = y - start.y + d.y;
670
883
  if (typeof p.x1 === 'number') {
671
- p.x1 = toFixedValue(start.x1 + deltaX, 4);
884
+ p.x1 = toFixedValue(start.x1 + deltaX, 2);
672
885
  }
673
886
  if (typeof p.x2 === 'number') {
674
- p.x2 = toFixedValue(start.x2 + deltaX, 4);
887
+ p.x2 = toFixedValue(start.x2 + deltaX, 2);
675
888
  }
676
889
  if (typeof p.y1 === 'number') {
677
- p.y1 = toFixedValue(start.y1 + deltaY, 4);
890
+ p.y1 = toFixedValue(start.y1 + deltaY, 2);
678
891
  }
679
892
  if (typeof p.y2 === 'number') {
680
- p.y2 = toFixedValue(start.y2 + deltaY, 4);
893
+ p.y2 = toFixedValue(start.y2 + deltaY, 2);
681
894
  }
682
- p.x = toFixedValue(x + d.x, 4);
683
- p.y = toFixedValue(y + d.y, 4);
895
+ p.x = toFixedValue(x + d.x, 2);
896
+ p.y = toFixedValue(y + d.y, 2);
684
897
  });
685
898
 
686
899
  this.updateNodeData();
@@ -700,11 +913,18 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
700
913
  } = this.currentPathNode || {};
701
914
  const { paths = [] } = path;
702
915
  const p = this.getPosFromMouseEvent(e);
703
- let x = p.x - position.x;
704
- let y = p.y - position.y;
916
+ const offset = this.getBoundsOffset();
917
+ let x = p.x - position.x - offset.x;
918
+ let y = p.y - position.y - offset.y;
919
+
920
+ const center = {
921
+ x: -offset.x,
922
+ y: -offset.y,
923
+ };
705
924
  const { x: currentX, y: currentY } = inverseTransformToData(
706
925
  { x, y },
707
- { scale, rotation }
926
+ { scale, rotation },
927
+ center
708
928
  );
709
929
  x = currentX;
710
930
  y = currentY;
@@ -728,6 +948,9 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
728
948
  return;
729
949
  }
730
950
  this.currentPathNode.path.closed = true;
951
+ this.currentPathNode.path.paths[
952
+ this.currentPathNode.path.paths.length - 1
953
+ ].closed = true;
731
954
  this.pathPointSelection!.enterSelectBezierMode([
732
955
  {
733
956
  pointId: this.currentPathNode.path.paths[0].id,
@@ -754,6 +977,13 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
754
977
  rotation = 0,
755
978
  } = this.currentPathNode || ({} as Editor2dPathNode);
756
979
  const { paths: p = [] } = path;
980
+
981
+ const offset = this.getBoundsOffset();
982
+ const center = {
983
+ x: -offset.x,
984
+ y: -offset.y,
985
+ };
986
+
757
987
  const paths = [...p].map(c => {
758
988
  const item = {
759
989
  ...c,
@@ -761,25 +991,31 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
761
991
  y: c.y,
762
992
  };
763
993
 
764
- const { x, y } = transformToData({ x: c.x, y: c.y }, { scale, rotation });
765
- item.x = x + position.x;
766
- item.y = y + position.y;
994
+ const { x, y } = transformToData(
995
+ { x: c.x, y: c.y },
996
+ { scale, rotation },
997
+ center
998
+ );
999
+ item.x = x + position.x + offset.x;
1000
+ item.y = y + position.y + offset.y;
767
1001
 
768
1002
  if (typeof c.x1 === 'number' || typeof c.y1 === 'number') {
769
1003
  const { x: x1, y: y1 } = transformToData(
770
1004
  { x: c.x1 || c.x, y: c.y1 || c.y },
771
- { scale, rotation }
1005
+ { scale, rotation },
1006
+ center
772
1007
  );
773
- item.x1 = x1 + position.x;
774
- item.y1 = y1 + position.y;
1008
+ item.x1 = x1 + position.x + offset.x;
1009
+ item.y1 = y1 + position.y + offset.y;
775
1010
  }
776
1011
  if (typeof c.x2 === 'number' || typeof c.y2 === 'number') {
777
1012
  const { x: x2, y: y2 } = transformToData(
778
1013
  { x: c.x2 || c.x, y: c.y2 || c.y },
779
- { scale, rotation }
1014
+ { scale, rotation },
1015
+ center
780
1016
  );
781
- item.x2 = x2 + position.x;
782
- item.y2 = y2 + position.y;
1017
+ item.x2 = x2 + position.x + offset.x;
1018
+ item.y2 = y2 + position.y + offset.y;
783
1019
  }
784
1020
  return item;
785
1021
  });