@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.
- package/dist/editor.cjs +1803 -0
- package/dist/editor.esm.js +186 -114
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.js +190 -112
- package/dist/editor.min.cjs +1 -0
- package/dist/editor.min.js +1 -1
- package/package.json +12 -6
- package/src/Editor.ts +4 -8
- package/src/config.ts +1 -1
- package/src/display/EditBox.ts +3 -2
- package/src/display/Stroker.ts +12 -15
- package/src/helper/EditDataHelper.ts +29 -25
- package/src/index.ts +2 -6
- package/src/tool/EditTool.ts +3 -3
- package/src/tool/LineEditTool.ts +88 -36
- package/types/index.d.ts +6 -2
package/src/tool/LineEditTool.ts
CHANGED
|
@@ -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
|
|
21
|
+
const line = e.target as ILine
|
|
22
|
+
const isDragFrom = direction === left
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
const { toPoint } = target
|
|
24
|
+
if (line.pathInputed) {
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
const { path } = line.__
|
|
27
|
+
const { from, to } = this.getFromToByPath(path)
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
this.dragPoint(from, to, isDragFrom, around, this.getInnerMove(line, drag, lockRatio))
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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 (
|
|
35
|
+
} else if (line.points) {
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
const { points } = line
|
|
38
|
+
const { from, to } = this.getFromToByPoints(points)
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
66
|
-
|
|
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 } =
|
|
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
|
-
|
|
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(
|
|
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
|
}
|