@gedit/editor-2d 0.2.61 → 0.2.63

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 (47) hide show
  1. package/lib/browser/model/editor2d-model.d.ts +0 -2
  2. package/lib/browser/model/editor2d-model.d.ts.map +1 -1
  3. package/lib/browser/model/editor2d-model.js +0 -5
  4. package/lib/browser/model/editor2d-model.js.map +1 -1
  5. package/lib/browser/model/editor2d.d.ts +4 -4
  6. package/lib/browser/model/editor2d.d.ts.map +1 -1
  7. package/lib/browser/playground/canvas-draw.d.ts +5 -4
  8. package/lib/browser/playground/canvas-draw.d.ts.map +1 -1
  9. package/lib/browser/playground/canvas-draw.js +75 -41
  10. package/lib/browser/playground/canvas-draw.js.map +1 -1
  11. package/lib/browser/playground/path-edit/path-edit-layer-move-point.d.ts.map +1 -1
  12. package/lib/browser/playground/path-edit/path-edit-layer-move-point.js +4 -0
  13. package/lib/browser/playground/path-edit/path-edit-layer-move-point.js.map +1 -1
  14. package/lib/browser/playground/path-edit/path-edit-layer-svg-path.d.ts +4 -3
  15. package/lib/browser/playground/path-edit/path-edit-layer-svg-path.d.ts.map +1 -1
  16. package/lib/browser/playground/path-edit/path-edit-layer-svg-path.js +22 -10
  17. package/lib/browser/playground/path-edit/path-edit-layer-svg-path.js.map +1 -1
  18. package/lib/browser/playground/path-edit/utils.d.ts +18 -2
  19. package/lib/browser/playground/path-edit/utils.d.ts.map +1 -1
  20. package/lib/browser/playground/path-edit/utils.js +60 -10
  21. package/lib/browser/playground/path-edit/utils.js.map +1 -1
  22. package/lib/browser/playground/path-edit-layer.d.ts +6 -3
  23. package/lib/browser/playground/path-edit-layer.d.ts.map +1 -1
  24. package/lib/browser/playground/path-edit-layer.js +126 -36
  25. package/lib/browser/playground/path-edit-layer.js.map +1 -1
  26. package/lib/browser/playground/playground-context.d.ts +2 -3
  27. package/lib/browser/playground/playground-context.d.ts.map +1 -1
  28. package/lib/browser/playground/playground-context.js +4 -6
  29. package/lib/browser/playground/playground-context.js.map +1 -1
  30. package/lib/browser/playground/playground-contribution.d.ts +1 -2
  31. package/lib/browser/playground/playground-contribution.d.ts.map +1 -1
  32. package/lib/browser/playground/playground-contribution.js +0 -4
  33. package/lib/browser/playground/playground-contribution.js.map +1 -1
  34. package/lib/browser/playground/selection-entity-manager.d.ts +1 -1
  35. package/lib/browser/playground/selection-entity-manager.d.ts.map +1 -1
  36. package/lib/browser/playground/selection-entity-manager.js.map +1 -1
  37. package/package.json +8 -8
  38. package/src/browser/model/editor2d-model.ts +0 -2
  39. package/src/browser/model/editor2d.ts +4 -4
  40. package/src/browser/playground/canvas-draw.ts +75 -41
  41. package/src/browser/playground/path-edit/path-edit-layer-move-point.tsx +6 -0
  42. package/src/browser/playground/path-edit/path-edit-layer-svg-path.tsx +34 -17
  43. package/src/browser/playground/path-edit/utils.tsx +92 -11
  44. package/src/browser/playground/path-edit-layer.tsx +189 -55
  45. package/src/browser/playground/playground-context.ts +3 -3
  46. package/src/browser/playground/playground-contribution.ts +0 -2
  47. package/src/browser/playground/selection-entity-manager.tsx +1 -1
@@ -11,11 +11,32 @@ import {
11
11
  cubicToQuadratic,
12
12
  getPathBounds,
13
13
  PathSchema,
14
+ getPathSizeBounds,
14
15
  } from '@gedit/canvas-draw';
15
16
  import { Bezier } from 'bezier-js';
16
- import { generateUuid, PositionSchema } from '@gedit/utils';
17
+ import {
18
+ generateUuid,
19
+ PositionSchema,
20
+ ScaleSchema,
21
+ SizeSchema,
22
+ } from '@gedit/utils';
17
23
  import { PointSchema } from './path-edit-layer-move-point';
18
24
  import { Editor2dPathNode } from '../../model';
25
+ import { cloneDeep } from 'lodash';
26
+
27
+ export const transformRotation = (p1: Point, p2: Point, rotation: number) => {
28
+ if (!rotation) {
29
+ return p1;
30
+ }
31
+ const { x: x1, y: y1 } = p1;
32
+ const { x: x2, y: y2 } = p2;
33
+ const rotationX = x1 - x2;
34
+ const rotationY = y1 - y2;
35
+ return {
36
+ x: rotationX * Math.cos(rotation) - rotationY * Math.sin(rotation) + x2,
37
+ y: rotationY * Math.cos(rotation) + rotationX * Math.sin(rotation) + y2,
38
+ };
39
+ };
19
40
 
20
41
  export const pathFuncIcon = [
21
42
  {
@@ -102,7 +123,10 @@ export const getBezierHullByPos = (
102
123
  * @param s
103
124
  * @returns
104
125
  */
105
- export const getExtendPositionByPoint = (c: Point, s: Point): Point => ({ x: c.x * 2 - s.x, y: c.y * 2 - s.y });
126
+ export const getExtendPositionByPoint = (c: Point, s: Point): Point => ({
127
+ x: c.x * 2 - s.x,
128
+ y: c.y * 2 - s.y,
129
+ });
106
130
 
107
131
  export const getExtendPositionByRadius = (
108
132
  c: PathChild,
@@ -244,17 +268,62 @@ export const setBezierMovePoint = (
244
268
  return path;
245
269
  };
246
270
 
247
- export const updatePathNodeData = (node: Editor2dPathNode): { path: PathSchema, position: PositionSchema } => {
248
- const { position, origin, path } = node;
271
+ export const transformToData = (
272
+ point: PointSchema,
273
+ transform: { scale?: ScaleSchema; rotation?: number }
274
+ ) => {
275
+ const { scale = { x: 1, y: 1}, rotation = 0 } = transform;
276
+ let { x, y } = point;
277
+ x *= scale.x;
278
+ y *= scale.y;
279
+ const rx = transformRotation({ x, y }, { x: 0, y: 0 }, rotation);
280
+ x = rx.x;
281
+ y = rx.y;
282
+ return {
283
+ x,
284
+ y,
285
+ };
286
+ };
287
+
288
+ export const inverseTransformToData = (
289
+ point: PointSchema,
290
+ transform: { scale: ScaleSchema; rotation: number }
291
+ ) => {
292
+ const { scale, rotation } = transform;
293
+ let { x, y } = point;
294
+ const r = transformRotation({ x, y }, { x: 0, y: 0 }, -rotation);
295
+ x = r.x;
296
+ y = r.y;
297
+ x /= scale.x;
298
+ y /= scale.y;
299
+ return { x, y };
300
+ };
301
+
302
+ export const updatePathNodeData = (
303
+ node: Editor2dPathNode
304
+ ): { path: PathSchema; position?: PositionSchema; size: SizeSchema } => {
305
+ const {
306
+ position = { x: 0, y: 0 },
307
+ origin = { x: 0.5, y: 0.5 },
308
+ path,
309
+ style,
310
+ size,
311
+ rotation = 0,
312
+ scale = { x: 1, y: 1 },
313
+ } = node;
249
314
  const { paths: p = [], closed } = path;
250
- const paths = [...p];
315
+ const paths = cloneDeep(p);
251
316
  if (closed) {
252
- paths.push(paths[0]);
317
+ paths.push(cloneDeep(paths[0]));
253
318
  }
254
319
  const bounds = getPathBounds(paths);
320
+ const { contentWidth, contentHeight } = getPathSizeBounds(
321
+ style!.line,
322
+ bounds
323
+ );
324
+ let x = bounds.minX + bounds.width * origin!.x;
325
+ let y = bounds.minY + bounds.height * origin!.y;
255
326
 
256
- const x = bounds.minX + bounds.width * (origin?.x || 0.5);
257
- const y = bounds.minY + bounds.height * (origin?.y || 0.5);
258
327
  const newPath = p.map(c => {
259
328
  const item = {
260
329
  ...c,
@@ -275,11 +344,23 @@ export const updatePathNodeData = (node: Editor2dPathNode): { path: PathSchema,
275
344
  }
276
345
  return item;
277
346
  });
347
+ const t = transformToData({ x, y }, { scale, rotation });
348
+ x = t.x;
349
+ y = t.y;
350
+
351
+ x += position.x;
352
+ y += position.y;
353
+
278
354
  return {
279
- path: { ...path, paths: newPath },
355
+ path: { ...path, paths: newPath, origin },
356
+ size: {
357
+ ...size,
358
+ width: contentWidth,
359
+ height: contentHeight,
360
+ },
280
361
  position: {
281
- x: x + (position?.x || 0),
282
- y: y + (position?.y || 0),
362
+ x,
363
+ y,
283
364
  },
284
365
  };
285
366
  };
@@ -5,28 +5,25 @@ import {
5
5
  entity,
6
6
  Layer,
7
7
  PathPointSelection,
8
+ PathPointSelectionEntity,
8
9
  PathSelectMode,
10
+ PlaygroundLayer,
9
11
  SelectorBoxConfigEntity,
10
12
  } from '@gedit/playground';
11
13
  import { DocumentEntity } from './entities/document-entity';
12
14
  import { domUtils } from '@gedit/utils/lib/browser';
13
15
  import { GameObjectBaseType } from '@gedit/render-engine';
14
- import { Editor2dDocument, Editor2dPathNode } from '../model';
16
+ import type { Editor2dDocument, Editor2dPathNode } from '../model';
15
17
  import { PlaygroundContext2d } from './playground-context';
16
18
  import { SelectableTreeNode, TreeSelection } from '@gedit/tree';
17
19
  import {
18
20
  PathChild,
21
+ PathSchema,
19
22
  PATH_FUNC_TYPE,
20
23
  toFixedValue,
21
- PathSchema,
22
24
  } from '@gedit/canvas-draw';
23
25
 
24
- import {
25
- deepClone,
26
- Disposable,
27
- generateUuid,
28
- PositionSchema,
29
- } from '@gedit/utils';
26
+ import { deepClone, Disposable, generateUuid } from '@gedit/utils';
30
27
  import {
31
28
  PointSchema,
32
29
  SvgPath,
@@ -34,6 +31,8 @@ import {
34
31
  setBezierMovePoint,
35
32
  PointSelection,
36
33
  updatePathNodeData,
34
+ inverseTransformToData,
35
+ transformToData,
37
36
  } from './path-edit';
38
37
 
39
38
  export interface PathEditLayerEventContextProps {
@@ -60,11 +59,14 @@ export const PathEditLayerEventContext = React.createContext<PathEditLayerEventC
60
59
  */
61
60
  export class PathEditLayer extends Layer<PlaygroundContext2d> {
62
61
  node = domUtils.createDivWithClass('gedit-path-edit-layer');
62
+ id = 'pathEditLayer';
63
63
  @entity(EditorStateConfigEntity)
64
64
  protected editorState: EditorStateConfigEntity;
65
65
  @entity(SelectorBoxConfigEntity)
66
66
  protected selectorConfig!: SelectorBoxConfigEntity;
67
67
  @entity(DocumentEntity) documentEntity: DocumentEntity;
68
+ @entity(PathPointSelectionEntity)
69
+ pathPointSelection: PathPointSelectionEntity;
68
70
 
69
71
  currentPathNode?: Editor2dPathNode;
70
72
  startPos?: PathChild;
@@ -103,6 +105,35 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
103
105
  const nodeData = updatePathNodeData(this.currentPathNode!);
104
106
  this.document?.updateNode(this.currentPathNode!, nodeData, true);
105
107
  }
108
+ updateNodePathData(): void {
109
+ if (!this.currentPathNode) {
110
+ return;
111
+ }
112
+ const { origin = { x: 0.5, y: 0.5 }, size, path } = this.currentPathNode;
113
+ const { origin: oldOrigin = { x: 0.5, y: 0.5 }, paths } = path;
114
+ const diff = {
115
+ x: toFixedValue((oldOrigin.x - origin.x) * (size?.width || 0), 4),
116
+ y: toFixedValue((oldOrigin.y - origin.y) * (size?.height || 0), 4),
117
+ };
118
+ paths.forEach(item => {
119
+ item.x += diff.x;
120
+ item.y += diff.y;
121
+ if (typeof item.x1 === 'number') {
122
+ item.x1 += diff.x;
123
+ }
124
+ if (typeof item.x2 === 'number') {
125
+ item.x2 += diff.x;
126
+ }
127
+ if (typeof item.y1 === 'number') {
128
+ item.y1 += diff.y;
129
+ }
130
+ if (typeof item.y2 === 'number') {
131
+ item.y2 += diff.y;
132
+ }
133
+ });
134
+ path.origin = origin;
135
+ this.document?.updateNode(this.currentPathNode, { path }, true);
136
+ }
106
137
 
107
138
  // 选中的是第一个点
108
139
  protected isOnePoint(point?: PathChild): boolean {
@@ -143,14 +174,14 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
143
174
  }
144
175
 
145
176
  onReady(): void {
146
- this.toDispose.pushAll([
177
+ this.addDispose([
147
178
  this.context.historyService.onHistoryBack(e => {
148
179
  this.reNodeData();
149
180
  this.pathPointSelection!.selectMode = PathSelectMode.ADD_PATH;
150
181
  this.pathPointSelection!.clearSelection();
151
182
  this.editorState.toDefaultState();
152
183
  }),
153
- this.editorState.onStateChange(() => {
184
+ this.editorState.onStateChange(e => {
154
185
  /**
155
186
  * 1. 不是路径编辑状态时,清空数据
156
187
  * 2. 是路径编辑状态时
@@ -182,6 +213,8 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
182
213
  this.currentPathNode.path.closed
183
214
  ? this.pathPointSelection.enterSelectBezierMode(selectionNode)
184
215
  : this.pathPointSelection.enterPathMode(selectionNode);
216
+ // 如果中心点不同,更新数据;
217
+ this.updateNodePathData();
185
218
  } else if (!selectNodes.length) {
186
219
  // 未选中时,清空数据
187
220
  this.pathPointSelection.selectMode = PathSelectMode.ADD_PATH;
@@ -199,10 +232,18 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
199
232
  );
200
233
  const { paths = [], closed } = this.currentPathNode?.path || {};
201
234
  const pathSelects: PathPointSelection[] = [];
235
+ const {
236
+ position = { x: 0, y: 1 },
237
+ scale = { x: 1, y: 1 },
238
+ rotation = 0,
239
+ } = this.currentPathNode!;
202
240
  paths.forEach(p => {
203
241
  const { x: $x, y: $y } = p;
204
- const x = $x + this.currentPathNode!.position!.x;
205
- const y = $y + this.currentPathNode!.position!.y;
242
+ let x = $x;
243
+ let y = $y;
244
+ const r = transformToData({ x, y }, { scale, rotation });
245
+ x = r.x + position.x;
246
+ y = r.y + position.y;
206
247
  const wh = (4 / this.config.finalScale) * 2;
207
248
  if (
208
249
  x >= selectBound.x && // 左
@@ -265,20 +306,26 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
265
306
  ) {
266
307
  return;
267
308
  }
268
- const { position = { x: 0, y: 0 } } = this.currentPathNode || {};
309
+ const {
310
+ position = { x: 0, y: 0 },
311
+ scale = { x: 1, y: 1 },
312
+ rotation = 0,
313
+ } = this.currentPathNode || {};
314
+ let x = e.endPos.x / (this.config?.finalScale || 1) - position.x;
315
+ let y = e.endPos.y / (this.config?.finalScale || 1) - position.y;
316
+ const { x: rx, y: ry } = inverseTransformToData(
317
+ { x, y },
318
+ { scale, rotation }
319
+ );
320
+ x = rx;
321
+ y = ry;
269
322
  this.startPos = {
270
- x: toFixedValue(
271
- e.endPos.x / (this.config?.finalScale || 1) - position.x,
272
- 4
273
- ),
274
- y: toFixedValue(
275
- e.endPos.y / (this.config?.finalScale || 1) - position.y,
276
- 4
277
- ),
278
- }; // this.getPosFromMouseEvent(e);
323
+ x,
324
+ y,
325
+ };
279
326
  this.startPos.id = generateUuid();
280
327
  this.startPos.type = PATH_FUNC_TYPE.STRAIGHT;
281
- this.initPath(this.startPos);
328
+ this.addPath(this.startPos);
282
329
  this.pathPointSelection!.enterPathMode([
283
330
  {
284
331
  pointId: this.startPos.id,
@@ -291,10 +338,21 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
291
338
  return;
292
339
  }
293
340
  // const pos = this.getPosFromMouseEvent(e);
294
- const { position = { x: 0, y: 0 }, path } =
295
- this.currentPathNode || {};
296
- const x = e.endPos.x / (this.config?.finalScale || 1) - position.x;
297
- const y = e.endPos.y / (this.config?.finalScale || 1) - position.y;
341
+ const {
342
+ path,
343
+ position = { x: 0, y: 0 },
344
+ scale = { x: 1, y: 1 },
345
+ rotation = 0,
346
+ } = this.currentPathNode || {};
347
+ let x = e.endPos.x / (this.config?.finalScale || 1) - position.x;
348
+ let y = e.endPos.y / (this.config?.finalScale || 1) - position.y;
349
+ const { x: rx, y: ry } = inverseTransformToData(
350
+ { x, y },
351
+ { scale, rotation }
352
+ );
353
+ x = rx;
354
+ y = ry;
355
+
298
356
  const pathNode = path?.paths.find(
299
357
  c => c.id === this.startPos?.id
300
358
  );
@@ -323,8 +381,24 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
323
381
  },
324
382
  });
325
383
  }),
384
+ this.listenPlaygroundEvent('dblclick', (e: MouseEvent) => {
385
+ // 双击画布时,关闭路径
386
+ // 1. 在路径编辑状态时,不处理;
387
+ // 2. 选中的是 path 路径时,不处理,新增点;
388
+ // 3. 选中点时,不处理;
389
+ // 4. 右键时,不处理;
390
+ // 5. 不是路径编辑状态时,不处理;
391
+ const isExit =
392
+ this.editorState.is(EditorState.EDIT_PATH_STATE.id) &&
393
+ this.pathPointSelection.selectMode === PathSelectMode.SELECT_BEZIER;
394
+ if (isExit) {
395
+ const playgroundLayer = this.pipelineLayers.find(c => c.id === 'playgroundLayer') as PlaygroundLayer;
396
+ playgroundLayer?.keydownEvent?.({ key: 'Escape' } as KeyboardEvent);
397
+ }
398
+ }),
326
399
  // 图层发生变化时退出模式
327
400
  this.selectionService?.onSelectionChanged(e => {
401
+ // todo: pahtSelection 跟随 playground
328
402
  const { isEnabled, pathPointSelection } = this;
329
403
  if (isEnabled) {
330
404
  if (!pathPointSelection) {
@@ -354,6 +428,7 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
354
428
  this.currentPathNode.path.closed
355
429
  ? pathPointSelection.enterSelectBezierMode(selectionNode)
356
430
  : pathPointSelection.enterPathMode(selectionNode);
431
+ this.updateNodePathData();
357
432
  }
358
433
  return;
359
434
  }
@@ -380,7 +455,7 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
380
455
  * 创建路径
381
456
  * @param pos - 当前鼠标点击的位置
382
457
  */
383
- initPath(pos: PointSchema): void {
458
+ addPath(pos: PointSchema): void {
384
459
  if (!this.document) {
385
460
  return;
386
461
  }
@@ -448,14 +523,35 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
448
523
  this.startDrag(e.clientX, e.clientY, {
449
524
  onDrag: e => {
450
525
  if (this.bezierStartPos) {
451
- const { position = { x: 0, y: 0 } } = this.currentPathNode || {};
452
- const x = e.endPos.x / (this.config?.finalScale || 1) - position.x;
453
- const y = e.endPos.y / (this.config?.finalScale || 1) - position.y;
526
+ const {
527
+ position = { x: 0, y: 0 },
528
+ scale = { x: 1, y: 1 },
529
+ rotation = 0,
530
+ } = this.currentPathNode || {};
531
+ let x = e.endPos.x / (this.config?.finalScale || 1) - position.x;
532
+ let y = e.endPos.y / (this.config?.finalScale || 1) - position.y;
533
+ const { x: currentX, y: currentY } = inverseTransformToData(
534
+ { x, y },
535
+ { scale, rotation }
536
+ );
537
+ x = currentX;
538
+ y = currentY;
454
539
  this.onBezierPointMove({ x, y });
455
540
  }
456
541
  },
457
542
  onDragEnd: () => {
458
543
  this.bezierStartPos = undefined;
544
+ const { closed } = this.currentPathNode?.path || {};
545
+ if (!closed) {
546
+ const isStartOrEnd = this.getPointIsStartOrEnd(p);
547
+ if (isStartOrEnd) {
548
+ this.pathPointSelection!.enterPathMode([
549
+ {
550
+ pointId: p.id,
551
+ },
552
+ ]);
553
+ }
554
+ }
459
555
  },
460
556
  });
461
557
  this.draw();
@@ -532,13 +628,14 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
532
628
  // 拖动
533
629
  onDrag: dragEvent => {
534
630
  selection = pathPointSelection?.selection || [];
535
- const { position = { x: 0, y: 0 } } = node;
536
631
  const selectionNodes = selection
537
632
  .map(s => node.path.paths.find(p => p.id === s.pointId))
538
633
  .filter(c => c) as PathChild[];
539
634
  const delta = selectionNodes.map(c => {
540
635
  const point = node.path.paths.find(p => p.id === c.id)!;
541
- const current = node.path.paths.find(p => p.id === currentPoint.id)!;
636
+ const current = node.path.paths.find(
637
+ p => p.id === currentPoint.id
638
+ )!;
542
639
  if (point.id === currentPoint.id) {
543
640
  return { x: 0, y: 0 };
544
641
  }
@@ -550,10 +647,21 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
550
647
  const startNode = selectionNodes.map((s: PathChild) =>
551
648
  startNodeClone.find((c: PathChild) => c.id === s.id)
552
649
  );
553
- const x =
650
+ const {
651
+ position = { x: 0, y: 0 },
652
+ scale = { x: 1, y: 1 },
653
+ rotation = 0,
654
+ } = this.currentPathNode || {};
655
+ let x =
554
656
  dragEvent.endPos.x / (this.config?.finalScale || 1) - position.x;
555
- const y =
657
+ let y =
556
658
  dragEvent.endPos.y / (this.config?.finalScale || 1) - position.y;
659
+ const { x: currentX, y: currentY } = inverseTransformToData(
660
+ { x, y },
661
+ { scale, rotation }
662
+ );
663
+ x = currentX;
664
+ y = currentY;
557
665
  selectionNodes.forEach((p: PathChild, i) => {
558
666
  const start = startNode[i];
559
667
  const d = delta[i];
@@ -574,22 +682,35 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
574
682
  p.x = toFixedValue(x + d.x, 4);
575
683
  p.y = toFixedValue(y + d.y, 4);
576
684
  });
685
+
577
686
  this.updateNodeData();
578
687
  },
579
688
  });
580
-
581
689
  this.draw();
582
690
  }
583
691
  protected onPathAddPoint(i: number, e: React.MouseEvent): void {
584
692
  if (!this.currentPathNode || !this.document) {
585
693
  return;
586
694
  }
587
- const { path, position } = this.currentPathNode;
695
+ const {
696
+ path,
697
+ position = { x: 0, y: 0 },
698
+ scale = { x: 1, y: 1 },
699
+ rotation = 0,
700
+ } = this.currentPathNode || {};
588
701
  const { paths = [] } = path;
589
702
  const p = this.getPosFromMouseEvent(e);
703
+ let x = p.x - position.x;
704
+ let y = p.y - position.y;
705
+ const { x: currentX, y: currentY } = inverseTransformToData(
706
+ { x, y },
707
+ { scale, rotation }
708
+ );
709
+ x = currentX;
710
+ y = currentY;
590
711
  const pos = {
591
- x: p.x - position!.x,
592
- y: p.y - position!.y,
712
+ x,
713
+ y,
593
714
  };
594
715
  const point = paths[i];
595
716
  const nextPoint = paths[i + 1] ? paths[i + 1] : paths[0];
@@ -625,31 +746,44 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
625
746
  // this.editorState.toDefaultState();
626
747
  return <></>;
627
748
  }
749
+
628
750
  const {
629
751
  path = {} as PathSchema,
630
- position = { x: 0, y: 0 } as PositionSchema,
752
+ position = { x: 0, y: 0 },
753
+ scale = { x: 1, y: 1 },
754
+ rotation = 0,
631
755
  } = this.currentPathNode || ({} as Editor2dPathNode);
632
- const { paths: p = [], closed = false } = path;
756
+ const { paths: p = [] } = path;
633
757
  const paths = [...p].map(c => {
634
758
  const item = {
635
759
  ...c,
636
- x: c.x + position.x,
637
- y: c.y + position.y,
760
+ x: c.x,
761
+ y: c.y,
638
762
  };
639
- if (typeof c.x1 === 'number') {
640
- item.x1 = c.x1 + position.x;
641
- }
642
- if (typeof c.x2 === 'number') {
643
- item.x2 = c.x2 + position.x;
644
- }
645
- if (typeof c.y1 === 'number') {
646
- item.y1 = c.y1 + position.y;
763
+
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;
767
+
768
+ if (typeof c.x1 === 'number' || typeof c.y1 === 'number') {
769
+ const { x: x1, y: y1 } = transformToData(
770
+ { x: c.x1 || c.x, y: c.y1 || c.y },
771
+ { scale, rotation }
772
+ );
773
+ item.x1 = x1 + position.x;
774
+ item.y1 = y1 + position.y;
647
775
  }
648
- if (typeof c.y2 === 'number') {
649
- item.y2 = c.y2 + position.y;
776
+ if (typeof c.x2 === 'number' || typeof c.y2 === 'number') {
777
+ const { x: x2, y: y2 } = transformToData(
778
+ { x: c.x2 || c.x, y: c.y2 || c.y },
779
+ { scale, rotation }
780
+ );
781
+ item.x2 = x2 + position.x;
782
+ item.y2 = y2 + position.y;
650
783
  }
651
784
  return item;
652
785
  });
786
+
653
787
  return (
654
788
  <PathEditLayerEventContext.Provider
655
789
  value={{
@@ -661,11 +795,11 @@ export class PathEditLayer extends Layer<PlaygroundContext2d> {
661
795
  }}
662
796
  >
663
797
  <SvgPath
664
- getPosFromMouseEvent={this.getPosFromMouseEvent.bind(this)}
665
798
  width={this.config.config.pageBounds?.width || 300}
666
799
  height={this.config.config.pageBounds?.height || 300}
800
+ getPosFromMouseEvent={this.getPosFromMouseEvent.bind(this)}
801
+ node={this.currentPathNode}
667
802
  paths={paths}
668
- closed={closed}
669
803
  selection={this.pathPointSelection?.selection as PointSelection[]}
670
804
  selectMode={this.pathPointSelection?.selectMode}
671
805
  getPointIsStartOrEnd={this.getPointIsStartOrEnd.bind(this)}
@@ -5,7 +5,7 @@ import { AppConfigService } from '@gedit/app-config';
5
5
  import { debounce, Emitter, URI } from '@gedit/utils';
6
6
  import { Editor2dEntity } from './entities/editor2d-entity';
7
7
  import type { SelectionEntityManager } from './selection-entity-manager';
8
- import { PathPointSelectionService, PathSelectMode, Playground } from '@gedit/playground';
8
+ import { PathPointSelectionEntity, PathSelectMode, Playground } from '@gedit/playground';
9
9
  import { Editor2dDocument } from '../model/editor2d-document';
10
10
  import { Editor2dSelection } from '../model/editor2d-selection';
11
11
  import { Editor2dModelOptions, Editor2dNode } from '../model/editor2d';
@@ -42,7 +42,6 @@ export class PlaygroundContext2d {
42
42
  @inject(OpenerService) readonly openerService: OpenerService,
43
43
  @inject(WorkspaceService)
44
44
  protected readonly workspaceService: WorkspaceService,
45
- @inject(PathPointSelectionService) readonly pathPointSelection: PathPointSelectionService,
46
45
  @inject(HistoryService) readonly historyService: HistoryService
47
46
  ) {
48
47
  this.rootURI = new URI(this.workspaceService.currentRoot!.uri);
@@ -55,7 +54,8 @@ export class PlaygroundContext2d {
55
54
  * 刷新 tree selection
56
55
  */
57
56
  syncToSelectionTree = debounce((entities: SelectionEntityManager) => {
58
- if (this.pathPointSelection.selectMode !== PathSelectMode.ADD_PATH) {
57
+ const pathPointSelection = entities.entityManager.getEntity<PathPointSelectionEntity>(PathPointSelectionEntity);
58
+ if (pathPointSelection?.selectMode !== PathSelectMode.ADD_PATH) {
59
59
  return;
60
60
  }
61
61
  const selectedEntities: Editor2dEntity[] = entities.getSelectedEntities();
@@ -1,7 +1,6 @@
1
1
  import { inject, injectable, optional } from 'inversify';
2
2
  import {
3
3
  EditorStateConfigEntity,
4
- PathPointSelectionService,
5
4
  Playground,
6
5
  PlaygroundConfig,
7
6
  PlaygroundContribution,
@@ -31,7 +30,6 @@ export class PlaygroundContribution2d implements PlaygroundContribution {
31
30
  @inject(CommandService) readonly commandService: CommandService;
32
31
  @inject(ContextMenuRenderer) @optional() readonly menuRender: ContextMenuRenderer;
33
32
  @inject(Editor2dSelection) readonly editor2dSelection: Editor2dSelection;
34
- @inject(PathPointSelectionService) readonly pathPointSelectionService: PathPointSelectionService;
35
33
  @inject(FrontendApplicationStateService) readonly stateService: FrontendApplicationStateService;
36
34
  registerPlayground(registry: PlaygroundRegistry): void {
37
35
  registry.registerLayer(CanvasLayer);
@@ -38,7 +38,7 @@ const numberToFixed4 = (data: {[key: string]: any}) => {
38
38
  export class SelectionEntityManager {
39
39
  nodeEntitiesCache: Map<string, Editor2dEntity> = new Map();
40
40
  constructor(
41
- protected entityManager: EntityManager,
41
+ public entityManager: EntityManager,
42
42
  protected context: PlaygroundContext2d,
43
43
  protected loading: () => boolean,
44
44
  protected getDocument: () => Editor2dDocument | undefined,