@leafer-in/editor 1.0.0-rc.22 → 1.0.0-rc.24

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.
@@ -1,13 +1,13 @@
1
- import { IEditorScaleEvent, ILine, IEditorSkewEvent } from '@leafer-in/interface'
1
+ import { IEditorScaleEvent, ILine, IEditorSkewEvent, IPointData, IAround, IPathCommandData, IFromToData, IUI, IDragEvent } from '@leafer-in/interface'
2
2
 
3
- import { getPointData, Direction9 } from '@leafer-ui/draw'
3
+ import { getPointData, Direction9, PointHelper } from '@leafer-ui/draw'
4
4
 
5
5
  import { EditTool } from './EditTool'
6
6
  import { registerEditTool } from './EditToolCreator'
7
7
 
8
8
 
9
-
10
9
  const { left, right } = Direction9
10
+ const { move, copy } = PointHelper
11
11
 
12
12
  @registerEditTool()
13
13
  export class LineEditTool extends EditTool {
@@ -18,53 +18,86 @@ export class LineEditTool extends EditTool {
18
18
 
19
19
  onScaleWithDrag(e: IEditorScaleEvent): void {
20
20
  const { drag, direction, lockRatio, around } = e
21
- const target = e.target as ILine
21
+ const line = e.target as ILine
22
+ const isDragFrom = direction === left
22
23
 
23
- const fromPoint = getPointData()
24
- const { toPoint } = target
24
+ if (line.pathInputed) {
25
25
 
26
- target.rotation = 0
26
+ const { path } = line.__
27
+ const { from, to } = this.getFromToByPath(path)
27
28
 
28
- let { x, y } = drag.getInnerMove(target)
29
+ this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio))
29
30
 
30
- if (lockRatio) {
31
- if (Math.abs(x) > Math.abs(y)) {
32
- y = 0
33
- } else {
34
- x = 0
35
- }
36
- }
31
+ path[1] = from.x, path[2] = from.y
32
+ path[4] = to.x, path[5] = to.y
33
+ line.path = path
37
34
 
38
- if (direction === left) {
35
+ } else if (line.points) {
39
36
 
40
- fromPoint.x += x
41
- fromPoint.y += y
37
+ const { points } = line
38
+ const { from, to } = this.getFromToByPoints(points)
42
39
 
43
- if (around) {
44
- toPoint.x -= x
45
- toPoint.y -= y
46
- }
40
+ this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio))
41
+
42
+ points[0] = from.x, points[1] = from.y
43
+ points[2] = to.x, points[3] = to.y
44
+ line.points = points
47
45
 
48
46
  } else {
49
47
 
50
- if (around) {
51
- fromPoint.x -= x
52
- fromPoint.y -= y
53
- }
48
+ const from = getPointData()
49
+ const { toPoint } = line
50
+ line.rotation = 0
51
+
52
+ this.dragPoint(from, toPoint, isDragFrom, around, this.getInnerMove(line, drag, lockRatio))
53
+
54
+ line.getLocalPointByInner(from, null, null, true)
55
+ line.getLocalPointByInner(toPoint, null, null, true)
56
+ line.x = from.x
57
+ line.y = from.y
58
+
59
+ line.getInnerPointByLocal(toPoint, null, null, true)
60
+ line.toPoint = toPoint
61
+
62
+ }
54
63
 
55
- toPoint.x += x
56
- toPoint.y += y
64
+ }
57
65
 
66
+ getInnerMove(ui: IUI, event: IDragEvent, lockRatio: boolean | 'corner'): IPointData {
67
+ const movePoint = event.getInnerMove(ui)
68
+ if (lockRatio) {
69
+ if (Math.abs(movePoint.x) > Math.abs(movePoint.y)) {
70
+ movePoint.y = 0
71
+ } else {
72
+ movePoint.x = 0
73
+ }
58
74
  }
75
+ return movePoint
76
+ }
59
77
 
60
- target.getLocalPointByInner(fromPoint, null, null, true)
61
- target.getLocalPointByInner(toPoint, null, null, true)
62
- target.x = fromPoint.x
63
- target.y = fromPoint.y
78
+ getFromToByPath(path: IPathCommandData): IFromToData {
79
+ return {
80
+ from: { x: path[1], y: path[2] },
81
+ to: { x: path[4], y: path[5] }
82
+ }
83
+ }
64
84
 
65
- target.getInnerPointByLocal(toPoint, null, null, true)
66
- target.toPoint = toPoint
85
+ getFromToByPoints(points: number[]): IFromToData {
86
+ return {
87
+ from: { x: points[0], y: points[1] },
88
+ to: { x: points[2], y: points[3] }
89
+ }
90
+ }
67
91
 
92
+ dragPoint(fromPoint: IPointData, toPoint: IPointData, isDragFrom: boolean, around: IAround, movePoint: IPointData): void {
93
+ const { x, y } = movePoint
94
+ if (isDragFrom) {
95
+ move(fromPoint, x, y)
96
+ if (around) move(toPoint, -x, -y)
97
+ } else {
98
+ if (around) move(fromPoint, -x, -y)
99
+ move(toPoint, x, y)
100
+ }
68
101
  }
69
102
 
70
103
  onSkew(_e: IEditorSkewEvent): void {
@@ -72,10 +105,29 @@ export class LineEditTool extends EditTool {
72
105
  }
73
106
 
74
107
  onUpdate() {
75
- const { rotatePoints, resizeLines, resizePoints } = this.editor.editBox
108
+ const { editBox } = this, { rotatePoints, resizeLines, resizePoints, rect } = editBox
109
+ const line = this.editor.element as ILine
110
+
111
+ let fromTo: IFromToData, leftOrRight: boolean
112
+ if (line.pathInputed) fromTo = this.getFromToByPath(line.__.path)
113
+ else if (line.points) fromTo = this.getFromToByPoints(line.__.points)
114
+
115
+ if (fromTo) {
116
+ const { from, to } = fromTo
117
+ line.innerToWorld(from, from, false, editBox)
118
+ line.innerToWorld(to, to, false, editBox)
119
+ rect.pen.clearPath().moveTo(from.x, from.y).lineTo(to.x, to.y)
120
+ copy(resizePoints[7] as IPointData, from)
121
+ copy(rotatePoints[7] as IPointData, from)
122
+ copy(resizePoints[3] as IPointData, to)
123
+ copy(rotatePoints[3] as IPointData, to)
124
+ }
125
+
76
126
  for (let i = 0; i < 8; i++) {
77
127
  if (i < 4) resizeLines[i].visible = false
78
- resizePoints[i].visible = rotatePoints[i].visible = (i === left || i === right)
128
+ leftOrRight = i === left || i === right
129
+ resizePoints[i].visible = leftOrRight
130
+ rotatePoints[i].visible = fromTo ? false : leftOrRight
79
131
  }
80
132
  }
81
133
 
package/types/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from '@leafer-ui/scale';
2
2
  import { IBounds, ILeafList, IUI, IEventListenerId, ILeaf, IPointerEvent, IGroup, IObject, IPointData, IGroupInputData, IEditSize, IBox, IBoundsData, IBoxInputData, IKeyEvent, IRect, IRectInputData, ILeaferCanvas, IRenderOptions, IMatrixData, IDragEvent, IAround } from '@leafer-ui/interface';
3
3
  import { Group, Event, Direction9, Box, UI, Answer } from '@leafer-ui/draw';
4
4
  import { PointerEvent, DragEvent, MoveEvent, RotateEvent } from '@leafer-ui/core';
5
- import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditorEvent, IEditPoint, IEditPointType, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent } from '@leafer-in/interface';
5
+ import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditorEvent, IEditPoint, IEditPointType, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent, IUI as IUI$1, IDragEvent as IDragEvent$1, IPointData as IPointData$1, IPathCommandData, IFromToData, IAround as IAround$1 } from '@leafer-in/interface';
6
6
 
7
7
  declare class EditSelect extends Group implements IEditSelect {
8
8
  editor: IEditor;
@@ -72,7 +72,7 @@ declare class Editor extends Group implements IEditor {
72
72
  shiftItem(item: IUI): void;
73
73
  update(): void;
74
74
  updateEditTool(): void;
75
- getEditSize(ui: IUI): IEditSize;
75
+ getEditSize(_ui: IUI): IEditSize;
76
76
  onMove(e: DragEvent): void;
77
77
  onScale(e: DragEvent): void;
78
78
  onRotate(e: DragEvent | RotateEvent): void;
@@ -250,6 +250,10 @@ declare class LineEditTool extends EditTool {
250
250
  get tag(): string;
251
251
  scaleOfEvent: boolean;
252
252
  onScaleWithDrag(e: IEditorScaleEvent): void;
253
+ getInnerMove(ui: IUI$1, event: IDragEvent$1, lockRatio: boolean | 'corner'): IPointData$1;
254
+ getFromToByPath(path: IPathCommandData): IFromToData;
255
+ getFromToByPoints(points: number[]): IFromToData;
256
+ dragPoint(fromPoint: IPointData$1, toPoint: IPointData$1, isDragFrom: boolean, around: IAround$1, movePoint: IPointData$1): void;
253
257
  onSkew(_e: IEditorSkewEvent): void;
254
258
  onUpdate(): void;
255
259
  }