@leafer-in/editor 1.0.0-rc.9 → 1.0.1
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 +2008 -0
- package/dist/editor.esm.js +1197 -458
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.js +1235 -487
- package/dist/editor.min.cjs +1 -0
- package/dist/editor.min.js +1 -1
- package/package.json +12 -7
- package/src/Editor.ts +268 -76
- package/src/config.ts +14 -4
- package/src/decorator/data.ts +1 -1
- package/src/display/EditBox.ts +164 -81
- package/src/display/EditMask.ts +37 -0
- package/src/display/EditPoint.ts +3 -3
- package/src/display/EditSelect.ts +84 -49
- package/src/display/SelectArea.ts +1 -1
- package/src/display/Stroker.ts +24 -21
- package/src/editor/cursor.ts +29 -38
- package/src/editor/simulate.ts +2 -2
- package/src/editor/target.ts +4 -2
- package/src/event/EditorEvent.ts +8 -1
- package/src/event/EditorGroupEvent.ts +23 -0
- package/src/event/EditorScaleEvent.ts +3 -2
- package/src/event/InnerEditorEvent.ts +23 -0
- package/src/helper/EditDataHelper.ts +112 -41
- package/src/helper/EditSelectHelper.ts +5 -4
- package/src/helper/EditorHelper.ts +11 -4
- package/src/index.ts +29 -5
- package/src/svg.ts +54 -0
- package/src/tool/EditTool.ts +51 -22
- package/src/tool/EditToolCreator.ts +32 -0
- package/src/tool/InnerEditor.ts +68 -0
- package/src/tool/LineEditTool.ts +94 -38
- package/types/index.d.ts +157 -52
- package/src/tool/index.ts +0 -21
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { IBounds, ILeaf, ILeafList, IUI, IEventListenerId } from '@leafer-ui/interface'
|
|
2
|
-
import { Bounds,
|
|
1
|
+
import { IBounds, ILeaf, ILeafList, IUI, IEventListenerId, IPointerEvent, IFunction } from '@leafer-ui/interface'
|
|
2
|
+
import { Bounds, LeafList, Group } from '@leafer-ui/draw'
|
|
3
|
+
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent } from '@leafer-ui/core'
|
|
3
4
|
|
|
4
5
|
import { IEditSelect, IEditor, ISelectArea, IStroker } from '@leafer-in/interface'
|
|
5
6
|
|
|
@@ -16,7 +17,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
16
17
|
public editor: IEditor
|
|
17
18
|
|
|
18
19
|
public get dragging(): boolean { return !!this.originList }
|
|
19
|
-
public get running(): boolean { return this.editor.hittable &&
|
|
20
|
+
public get running(): boolean { const { editor } = this; return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector }
|
|
20
21
|
public get isMoveMode(): boolean { return this.app && this.app.interaction.moveMode }
|
|
21
22
|
|
|
22
23
|
public hoverStroker: IStroker = new Stroker()
|
|
@@ -26,10 +27,11 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
26
27
|
public selectArea: ISelectArea = new SelectArea()
|
|
27
28
|
|
|
28
29
|
protected originList: ILeafList
|
|
29
|
-
protected
|
|
30
|
+
protected needRemoveItem: IUI
|
|
30
31
|
|
|
31
|
-
protected
|
|
32
|
+
protected waitSelect: IFunction // 手机端延迟选中,防止多点触屏误选元素
|
|
32
33
|
|
|
34
|
+
protected __eventIds: IEventListenerId[] = []
|
|
33
35
|
|
|
34
36
|
constructor(editor: IEditor) {
|
|
35
37
|
super()
|
|
@@ -43,8 +45,8 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
43
45
|
protected onHover(): void {
|
|
44
46
|
const { editor } = this
|
|
45
47
|
if (this.running && !this.dragging && !editor.dragging) {
|
|
46
|
-
const { stroke, strokeWidth, hover } = editor.
|
|
47
|
-
this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, { stroke, strokeWidth })
|
|
48
|
+
const { stroke, strokeWidth, hover, hoverStyle } = editor.mergeConfig
|
|
49
|
+
this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, { stroke, strokeWidth, ...(hoverStyle || {}) })
|
|
48
50
|
} else {
|
|
49
51
|
this.hoverStroker.target = null
|
|
50
52
|
}
|
|
@@ -52,7 +54,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
52
54
|
|
|
53
55
|
protected onSelect(): void {
|
|
54
56
|
if (this.running) {
|
|
55
|
-
const { config, list } = this.editor
|
|
57
|
+
const { mergeConfig: config, list } = this.editor
|
|
56
58
|
const { stroke, strokeWidth } = config
|
|
57
59
|
this.targetStroker.setTarget(list, { stroke, strokeWidth: Math.max(1, strokeWidth / 2) })
|
|
58
60
|
this.hoverStroker.target = null
|
|
@@ -60,66 +62,88 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
public update(): void {
|
|
63
|
-
if (this.
|
|
65
|
+
if (this.targetStroker.target) this.targetStroker.forceUpdate()
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
// move / down
|
|
67
69
|
|
|
68
70
|
protected onPointerMove(e: PointerEvent): void {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
const { app, editor } = this
|
|
72
|
+
if (this.running && !this.isMoveMode && app.interaction.canHover && !app.interaction.dragging) {
|
|
73
|
+
const find = this.findUI(e)
|
|
74
|
+
editor.hoverTarget = editor.hasItem(find) ? null : find
|
|
72
75
|
} if (this.isMoveMode) {
|
|
73
|
-
|
|
76
|
+
editor.hoverTarget = null // move.dragEmpty
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
protected onBeforeDown(e: PointerEvent): void {
|
|
78
|
-
if (
|
|
79
|
-
const find = this.lastDownLeaf = findOne(e.path)
|
|
81
|
+
if (e.multiTouch) return
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
const { select } = this.editor.mergeConfig
|
|
84
|
+
if (select === 'press') {
|
|
85
|
+
if (this.app.config.mobile) {
|
|
86
|
+
this.waitSelect = () => this.checkAndSelect(e)
|
|
87
|
+
} else {
|
|
88
|
+
this.checkAndSelect(e)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
82
92
|
|
|
83
|
-
|
|
84
|
-
|
|
93
|
+
protected onTap(e: PointerEvent): void {
|
|
94
|
+
if (e.multiTouch) return
|
|
95
|
+
|
|
96
|
+
const { editor } = this
|
|
97
|
+
const { select } = editor.mergeConfig
|
|
98
|
+
|
|
99
|
+
if (select === 'tap') this.checkAndSelect(e)
|
|
100
|
+
else if (this.waitSelect) this.waitSelect()
|
|
101
|
+
|
|
102
|
+
if (this.needRemoveItem) {
|
|
103
|
+
editor.removeItem(this.needRemoveItem)
|
|
104
|
+
} else if (this.isMoveMode) {
|
|
105
|
+
editor.target = null // move.dragEmpty
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
protected checkAndSelect(e: PointerEvent): void { // pointer.down or tap
|
|
111
|
+
this.needRemoveItem = null
|
|
112
|
+
|
|
113
|
+
if (this.allowSelect(e)) {
|
|
114
|
+
const { editor } = this
|
|
115
|
+
const find = this.findUI(e)
|
|
116
|
+
|
|
117
|
+
if (find) {
|
|
118
|
+
if (this.isMultipleSelect(e)) {
|
|
119
|
+
if (editor.hasItem(find)) this.needRemoveItem = find // 等待tap事件再实际移除
|
|
120
|
+
else editor.addItem(find)
|
|
85
121
|
} else {
|
|
86
|
-
|
|
122
|
+
editor.target = find
|
|
87
123
|
}
|
|
88
124
|
|
|
89
|
-
// change down data
|
|
90
|
-
this.editor.updateLayout()
|
|
91
|
-
find.leafer.interaction.updateDownData()
|
|
92
|
-
|
|
93
125
|
} else if (this.allow(e.target)) {
|
|
94
126
|
|
|
95
|
-
if (!e.shiftKey)
|
|
127
|
+
if (!e.shiftKey) editor.target = null
|
|
96
128
|
|
|
97
129
|
}
|
|
98
130
|
}
|
|
99
131
|
}
|
|
100
132
|
|
|
101
|
-
protected onTap(e: PointerEvent): void {
|
|
102
|
-
if (this.running && e.shiftKey && !e.middle && !this.lastDownLeaf) {
|
|
103
|
-
const find = this.findDeepOne(e)
|
|
104
|
-
if (find) this.editor.shiftItem(find)
|
|
105
|
-
} else if (this.isMoveMode) {
|
|
106
|
-
this.editor.target = null // move.dragEmpty
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
this.lastDownLeaf = null
|
|
110
|
-
}
|
|
111
|
-
|
|
112
133
|
// drag
|
|
113
134
|
|
|
114
135
|
protected onDragStart(e: DragEvent): void {
|
|
115
|
-
if (
|
|
136
|
+
if (e.multiTouch) return
|
|
137
|
+
if (this.waitSelect) this.waitSelect()
|
|
138
|
+
|
|
139
|
+
if (this.allowDrag(e)) {
|
|
116
140
|
const { editor } = this
|
|
117
|
-
const { stroke,
|
|
141
|
+
const { stroke, area } = editor.mergeConfig
|
|
118
142
|
const { x, y } = e.getInner(this)
|
|
119
143
|
|
|
120
144
|
this.bounds.set(x, y)
|
|
121
145
|
|
|
122
|
-
this.selectArea.setStyle({ visible: true, stroke,
|
|
146
|
+
this.selectArea.setStyle({ visible: true, stroke, x, y }, area)
|
|
123
147
|
this.selectArea.setBounds(this.bounds.get())
|
|
124
148
|
|
|
125
149
|
this.originList = editor.leafList.clone()
|
|
@@ -127,10 +151,8 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
127
151
|
}
|
|
128
152
|
|
|
129
153
|
protected onDrag(e: DragEvent): void {
|
|
130
|
-
if (
|
|
131
|
-
|
|
132
|
-
return
|
|
133
|
-
}
|
|
154
|
+
if (e.multiTouch) return
|
|
155
|
+
if (this.editor.dragging) return this.onDragEnd(e)
|
|
134
156
|
|
|
135
157
|
if (this.dragging) {
|
|
136
158
|
const { editor } = this
|
|
@@ -158,13 +180,14 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
158
180
|
} else {
|
|
159
181
|
|
|
160
182
|
editor.target = this.originList.list as IUI[]
|
|
161
|
-
if (editor.leafList.length) editor.update()
|
|
162
183
|
|
|
163
184
|
}
|
|
164
185
|
}
|
|
165
186
|
}
|
|
166
187
|
|
|
167
|
-
protected onDragEnd(): void {
|
|
188
|
+
protected onDragEnd(e: DragEvent): void {
|
|
189
|
+
if (e.multiTouch) return
|
|
190
|
+
|
|
168
191
|
if (this.dragging) this.originList = null, this.selectArea.visible = false
|
|
169
192
|
}
|
|
170
193
|
|
|
@@ -183,18 +206,30 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
183
206
|
}
|
|
184
207
|
|
|
185
208
|
protected allowDrag(e: DragEvent) {
|
|
186
|
-
if (this.editor.
|
|
187
|
-
return (!this.editor.
|
|
209
|
+
if (this.running && this.editor.mergeConfig.boxSelect && !e.target.draggable) {
|
|
210
|
+
return (!this.editor.editing && this.allow(e.target)) || (e.shiftKey && !findOne(e.path))
|
|
188
211
|
} else {
|
|
189
212
|
return false
|
|
190
213
|
}
|
|
191
214
|
}
|
|
192
215
|
|
|
193
|
-
protected
|
|
216
|
+
protected allowSelect(e: IPointerEvent): boolean {
|
|
217
|
+
return this.running && !this.isMoveMode && !e.middle
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public findDeepOne(e: PointerEvent): IUI {
|
|
194
221
|
const options = { exclude: new LeafList(this.editor.editBox.rect) }
|
|
195
222
|
return findOne(e.target.leafer.interaction.findPath(e, options)) as IUI
|
|
196
223
|
}
|
|
197
224
|
|
|
225
|
+
public findUI(e: PointerEvent): IUI {
|
|
226
|
+
return this.isMultipleSelect(e) ? this.findDeepOne(e) : findOne(e.path)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
public isMultipleSelect(e: IPointerEvent): boolean {
|
|
230
|
+
return e.shiftKey || this.editor.mergeConfig.continuousSelect
|
|
231
|
+
}
|
|
232
|
+
|
|
198
233
|
protected __listenEvents(): void {
|
|
199
234
|
const { editor } = this
|
|
200
235
|
editor.waitLeafer(() => {
|
|
@@ -210,7 +245,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
210
245
|
app.on_(PointerEvent.BEFORE_DOWN, this.onBeforeDown, this),
|
|
211
246
|
app.on_(PointerEvent.TAP, this.onTap, this),
|
|
212
247
|
|
|
213
|
-
app.on_(DragEvent.START, this.onDragStart, this),
|
|
248
|
+
app.on_(DragEvent.START, this.onDragStart, this, true), // 采用捕获事件,需要比EditBox中的dragStart早触发
|
|
214
249
|
app.on_(DragEvent.DRAG, this.onDrag, this),
|
|
215
250
|
app.on_(DragEvent.END, this.onDragEnd, this),
|
|
216
251
|
|
|
@@ -229,7 +264,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
229
264
|
}
|
|
230
265
|
|
|
231
266
|
public destroy(): void {
|
|
232
|
-
this.editor = this.originList = this.
|
|
267
|
+
this.editor = this.originList = this.needRemoveItem = null
|
|
233
268
|
this.__removeListenEvents()
|
|
234
269
|
super.destroy()
|
|
235
270
|
}
|
package/src/display/Stroker.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IUI, ILeaferCanvas, IRenderOptions, IRectInputData } from '@leafer-ui/interface'
|
|
2
|
-
import { Paint, UI, MatrixHelper } from '@leafer-ui/
|
|
2
|
+
import { Paint, UI, MatrixHelper } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
import { IStroker } from '@leafer-in/interface'
|
|
5
5
|
|
|
@@ -24,8 +24,7 @@ export class Stroker extends UI implements IStroker {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
public setTarget(target: IUI | IUI[], style: IRectInputData): void {
|
|
27
|
-
|
|
28
|
-
this.set({ stroke, strokeWidth })
|
|
27
|
+
this.set(style)
|
|
29
28
|
this.target = target
|
|
30
29
|
}
|
|
31
30
|
|
|
@@ -34,40 +33,44 @@ export class Stroker extends UI implements IStroker {
|
|
|
34
33
|
if (list.length) {
|
|
35
34
|
|
|
36
35
|
let leaf: IUI
|
|
37
|
-
const { stroke, strokeWidth } = this.__
|
|
36
|
+
const { stroke, strokeWidth, fill } = this.__
|
|
38
37
|
const { bounds } = options
|
|
39
38
|
|
|
40
39
|
for (let i = 0; i < list.length; i++) {
|
|
41
40
|
leaf = list[i]
|
|
42
41
|
if (bounds && bounds.hit(leaf.__world, options.matrix)) {
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY)
|
|
45
44
|
|
|
46
|
-
if (
|
|
47
|
-
const aScaleX = abs(leaf.__world.scaleX), aScaleY = abs(leaf.__world.scaleY)
|
|
48
|
-
if (aScaleX !== aScaleY) { // need no scale stroke
|
|
49
|
-
copy(matrix, leaf.__world)
|
|
50
|
-
scale(matrix, 1 / aScaleX, 1 / aScaleY)
|
|
45
|
+
if (aScaleX !== aScaleY) { // need no scale stroke, use rect path
|
|
51
46
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.__.strokeWidth = strokeWidth
|
|
47
|
+
copy(matrix, leaf.__world)
|
|
48
|
+
scale(matrix, 1 / aScaleX, 1 / aScaleY)
|
|
55
49
|
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
canvas.setWorld(matrix, options.matrix)
|
|
51
|
+
canvas.beginPath()
|
|
52
|
+
this.__.strokeWidth = strokeWidth
|
|
58
53
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
const { x, y, width, height } = leaf.__layout.boxBounds
|
|
55
|
+
canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY)
|
|
56
|
+
|
|
57
|
+
} else {
|
|
62
58
|
|
|
63
|
-
if (!drewPath) {
|
|
64
59
|
canvas.setWorld(leaf.__world, options.matrix)
|
|
65
60
|
canvas.beginPath()
|
|
66
|
-
|
|
61
|
+
|
|
62
|
+
if (leaf.__.__useArrow) {
|
|
63
|
+
leaf.__drawPath(canvas)
|
|
64
|
+
} else {
|
|
65
|
+
leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas)
|
|
66
|
+
}
|
|
67
|
+
|
|
67
68
|
this.__.strokeWidth = strokeWidth / abs(leaf.__world.scaleX)
|
|
69
|
+
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
typeof stroke === 'string' ? Paint.stroke(stroke, this, canvas
|
|
72
|
+
if (stroke) typeof stroke === 'string' ? Paint.stroke(stroke, this, canvas) : Paint.strokes(stroke, this, canvas)
|
|
73
|
+
if (fill) typeof fill === 'string' ? Paint.fill(fill, this, canvas) : Paint.fills(fill, this, canvas)
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
|
package/src/editor/cursor.ts
CHANGED
|
@@ -1,58 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { IObject, IUIEvent } from '@leafer-ui/interface'
|
|
2
|
+
|
|
3
|
+
import { IEditor } from '@leafer-in/interface'
|
|
4
|
+
import { MathHelper } from '@leafer-ui/draw'
|
|
3
5
|
|
|
4
6
|
import { EditDataHelper } from '../helper/EditDataHelper'
|
|
5
7
|
|
|
6
8
|
|
|
7
|
-
const
|
|
9
|
+
const cacheCursors: IObject = {}
|
|
8
10
|
|
|
9
11
|
export function updateCursor(editor: IEditor, e: IUIEvent): void {
|
|
10
12
|
const { editBox } = editor, point = editBox.enterPoint
|
|
11
|
-
if (!point || !editor.
|
|
13
|
+
if (!point || !editor.editing || !editBox.visible) return
|
|
14
|
+
if (point.name === 'circle') return // 独立旋转按钮
|
|
15
|
+
if (point.pointType === 'button') { // 普通按钮
|
|
16
|
+
if (!point.cursor) point.cursor = 'pointer'
|
|
17
|
+
return
|
|
18
|
+
}
|
|
12
19
|
|
|
13
20
|
let { rotation } = editBox
|
|
14
|
-
|
|
15
|
-
const {
|
|
21
|
+
const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig
|
|
22
|
+
const { pointType } = point, { flippedX, flippedY } = editBox
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
let showResize = pointType === 'resize'
|
|
25
|
+
if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable)) showResize = false
|
|
26
|
+
const showSkew = skewable && !showResize && point.name === 'resize-line'
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
const cursor = showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor)
|
|
29
|
+
rotation += (EditDataHelper.getFlipDirection(point.direction, flippedX, flippedY) + 1) * 45
|
|
30
|
+
rotation = Math.round(MathHelper.formatRotation(rotation, true) / 2) * 2
|
|
21
31
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
mirrorCursors(resizeCursor = [...resizeCursor], flippedX, flippedY)
|
|
25
|
-
mirrorCursors(rotateCursor = [...rotateCursor], flippedY, flippedX)
|
|
26
|
-
if (editBox.flippedOne) rotation = -rotation
|
|
27
|
-
}
|
|
32
|
+
const { url, x, y } = cursor
|
|
33
|
+
const key = url + rotation
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
if (cacheCursors[key]) {
|
|
36
|
+
point.cursor = cacheCursors[key]
|
|
37
|
+
} else {
|
|
38
|
+
cacheCursors[key] = point.cursor = { url: toDataURL(url, rotation), x, y }
|
|
39
|
+
}
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
export function updateMoveCursor(editor: IEditor): void {
|
|
34
|
-
editor.editBox.rect.cursor = editor.
|
|
43
|
+
editor.editBox.rect.cursor = editor.mergeConfig.moveCursor
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const topCursor = mirror[top], topLeftCursor = mirror[topLeft], topRightCursor = mirror[topRight]
|
|
41
|
-
mirror[top] = mirror[bottom]
|
|
42
|
-
mirror[topLeft] = mirror[bottomLeft]
|
|
43
|
-
mirror[topRight] = mirror[bottomRight]
|
|
44
|
-
mirror[bottom] = topCursor
|
|
45
|
-
mirror[bottomLeft] = topLeftCursor
|
|
46
|
-
mirror[bottomRight] = topRightCursor
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (mirrorY) {
|
|
50
|
-
const leftCursor = mirror[left], topLeftCursor = mirror[topLeft], bottomLeftCursor = mirror[bottomLeft]
|
|
51
|
-
mirror[left] = mirror[right]
|
|
52
|
-
mirror[topLeft] = mirror[topRight]
|
|
53
|
-
mirror[bottomLeft] = mirror[bottomRight]
|
|
54
|
-
mirror[right] = leftCursor
|
|
55
|
-
mirror[topRight] = topLeftCursor
|
|
56
|
-
mirror[bottomRight] = bottomLeftCursor
|
|
57
|
-
}
|
|
47
|
+
function toDataURL(svg: string, rotation: number): string {
|
|
48
|
+
return '"data:image/svg+xml,' + encodeURIComponent(svg.replace('{{rotation}}', rotation.toString())) + '"'
|
|
58
49
|
}
|
package/src/editor/simulate.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IGroup, ILeaf } from '@leafer-ui/interface'
|
|
2
|
-
import { Bounds } from '@leafer-ui/
|
|
2
|
+
import { Bounds } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
import { IEditor } from '@leafer-in/interface'
|
|
5
5
|
|
|
@@ -8,7 +8,7 @@ export function simulate(editor: IEditor) {
|
|
|
8
8
|
const { simulateTarget, leafList: targetList } = editor
|
|
9
9
|
const { x, y, width, height } = new Bounds().setListWithFn(targetList.list, (leaf: ILeaf) => leaf.worldBoxBounds)
|
|
10
10
|
|
|
11
|
-
const parent = simulateTarget.parent = targetList.list[0].leafer.zoomLayer as IGroup
|
|
11
|
+
const parent = simulateTarget.parent = targetList.list[0].leafer.zoomLayer as IGroup // follow zoomLayer zoom / move
|
|
12
12
|
const { scaleX, scaleY, e: worldX, f: worldY } = parent.__world
|
|
13
13
|
simulateTarget.reset({ x: (x - worldX) / scaleX, y: (y - worldY) / scaleY, width: width / scaleX, height: height / scaleY })
|
|
14
14
|
}
|
package/src/editor/target.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LeafList } from '@leafer-ui/
|
|
1
|
+
import { LeafList } from '@leafer-ui/draw'
|
|
2
2
|
|
|
3
3
|
import { IEditor, IUI } from '@leafer-in/interface'
|
|
4
4
|
|
|
@@ -16,8 +16,9 @@ export function onTarget(editor: IEditor, oldValue: IUI | IUI[]): void {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
editor.emitEvent(new EditorEvent(EditorEvent.SELECT, { editor, value: target, oldValue }))
|
|
19
|
+
editor.checkOpenedGroups()
|
|
19
20
|
|
|
20
|
-
if (editor.
|
|
21
|
+
if (editor.editing) {
|
|
21
22
|
editor.waitLeafer(() => {
|
|
22
23
|
if (editor.multiple) simulate(editor)
|
|
23
24
|
updateMoveCursor(editor)
|
|
@@ -26,6 +27,7 @@ export function onTarget(editor: IEditor, oldValue: IUI | IUI[]): void {
|
|
|
26
27
|
editor.listenTargetEvents()
|
|
27
28
|
})
|
|
28
29
|
} else {
|
|
30
|
+
editor.updateEditTool()
|
|
29
31
|
editor.removeTargetEvents()
|
|
30
32
|
}
|
|
31
33
|
}
|
package/src/event/EditorEvent.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { IUI, IPointData } from '@leafer-ui/interface'
|
|
2
|
-
import { Event } from '@leafer-ui/
|
|
2
|
+
import { Event } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
import { IEditor, IEditorEvent } from '@leafer-in/interface'
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
function toList(value: IUI | IUI[]): IUI[] {
|
|
8
|
+
return value ? (value instanceof Array ? value : [value]) : []
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
export class EditorEvent extends Event implements IEditorEvent {
|
|
8
12
|
|
|
9
13
|
static SELECT = 'editor.select'
|
|
@@ -15,6 +19,9 @@ export class EditorEvent extends Event implements IEditorEvent {
|
|
|
15
19
|
readonly value: IUI | IUI[]
|
|
16
20
|
readonly oldValue: IUI | IUI[]
|
|
17
21
|
|
|
22
|
+
get list() { return toList(this.value) }
|
|
23
|
+
get oldList() { return toList(this.oldValue) }
|
|
24
|
+
|
|
18
25
|
readonly worldOrigin: IPointData
|
|
19
26
|
declare readonly origin: IPointData
|
|
20
27
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IEditorGroupEvent } from '@leafer-in/interface'
|
|
2
|
+
|
|
3
|
+
import { EditorEvent } from './EditorEvent'
|
|
4
|
+
import { IGroup } from '@leafer-ui/interface'
|
|
5
|
+
import { } from '../tool/InnerEditor'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class EditorGroupEvent extends EditorEvent implements IEditorGroupEvent {
|
|
9
|
+
|
|
10
|
+
static GROUP = 'editor.group'
|
|
11
|
+
static BEFORE_UNGROUP = 'editor.before_ungroup'
|
|
12
|
+
static UNGROUP = 'editor.ungroup'
|
|
13
|
+
|
|
14
|
+
static OPEN = 'editor.open_group'
|
|
15
|
+
static CLOSE = 'editor.close_group'
|
|
16
|
+
|
|
17
|
+
readonly editTarget: IGroup
|
|
18
|
+
|
|
19
|
+
constructor(type: string, data?: IEditorGroupEvent) {
|
|
20
|
+
super(type, data)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IAround, IDragEvent, IMatrixData } from '@leafer-ui/interface'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { IEditorScaleEvent } from '@leafer-in/interface'
|
|
4
|
+
import { Direction9 } from '@leafer-ui/draw'
|
|
4
5
|
|
|
5
6
|
import { EditorEvent } from './EditorEvent'
|
|
6
7
|
|
|
@@ -16,7 +17,7 @@ export class EditorScaleEvent extends EditorEvent implements IEditorScaleEvent {
|
|
|
16
17
|
|
|
17
18
|
readonly drag: IDragEvent
|
|
18
19
|
|
|
19
|
-
readonly direction:
|
|
20
|
+
readonly direction: Direction9
|
|
20
21
|
readonly lockRatio: boolean
|
|
21
22
|
readonly around: IAround
|
|
22
23
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IInnerEditorEvent, IInnerEditor } from '@leafer-in/interface'
|
|
2
|
+
|
|
3
|
+
import { EditorEvent } from './EditorEvent'
|
|
4
|
+
import { IUI } from '@leafer-ui/interface'
|
|
5
|
+
import { } from '../tool/InnerEditor'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class InnerEditorEvent extends EditorEvent implements IInnerEditorEvent {
|
|
9
|
+
|
|
10
|
+
static BEFORE_OPEN = 'innerEditor.before_open'
|
|
11
|
+
static OPEN = 'innerEditor.open'
|
|
12
|
+
|
|
13
|
+
static BEFORE_CLOSE = 'innerEditor.before_close'
|
|
14
|
+
static CLOSE = 'innerEditor.close'
|
|
15
|
+
|
|
16
|
+
readonly editTarget: IUI
|
|
17
|
+
readonly innerEditor: IInnerEditor
|
|
18
|
+
|
|
19
|
+
constructor(type: string, data?: IInnerEditorEvent) {
|
|
20
|
+
super(type, data)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|