@leafer-in/editor 1.0.1 → 1.0.3
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 +59 -24
- package/dist/editor.esm.js +60 -25
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.js +59 -24
- package/dist/editor.min.cjs +1 -1
- package/dist/editor.min.js +1 -1
- package/package.json +5 -5
- package/src/Editor.ts +6 -5
- package/src/display/EditBox.ts +2 -0
- package/src/display/EditSelect.ts +1 -1
- package/src/editor/target.ts +1 -0
- package/src/helper/EditDataHelper.ts +22 -7
- package/types/index.d.ts +4 -3
package/src/Editor.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IGroupInputData, IUI, IEventListenerId, IPointData, ILeafList, IEditSize, IGroup, IObject, IAlign, IAxis, IFunction, ILayoutBoundsData } from '@leafer-ui/interface'
|
|
2
|
-
import { Group, Rect, DataHelper, MathHelper, LeafList, Matrix, RenderEvent, LeafHelper } from '@leafer-ui/draw'
|
|
2
|
+
import { Group, Rect, DataHelper, MathHelper, LeafList, Matrix, RenderEvent, LeafHelper, Direction9 } from '@leafer-ui/draw'
|
|
3
3
|
import { DragEvent, RotateEvent, KeyEvent, ZoomEvent, MoveEvent } from '@leafer-ui/core'
|
|
4
4
|
|
|
5
5
|
import { IEditBox, IEditPoint, IEditor, IEditorConfig, IEditTool, IEditorScaleEvent, IInnerEditor } from '@leafer-in/interface'
|
|
@@ -28,7 +28,7 @@ import { EditorGroupEvent } from './event/EditorGroupEvent'
|
|
|
28
28
|
|
|
29
29
|
export class Editor extends Group implements IEditor {
|
|
30
30
|
|
|
31
|
-
public config = config
|
|
31
|
+
public config = DataHelper.clone(config)
|
|
32
32
|
|
|
33
33
|
public get mergeConfig(): IEditorConfig {
|
|
34
34
|
const { element, config } = this
|
|
@@ -52,6 +52,7 @@ export class Editor extends Group implements IEditor {
|
|
|
52
52
|
public get editing(): boolean { return !!this.list.length }
|
|
53
53
|
public innerEditing: boolean
|
|
54
54
|
public get groupOpening(): boolean { return !!this.openedGroupList.length }
|
|
55
|
+
public resizeDirection?: Direction9
|
|
55
56
|
|
|
56
57
|
public get multiple(): boolean { return this.list.length > 1 }
|
|
57
58
|
public get single(): boolean { return this.list.length === 1 }
|
|
@@ -186,7 +187,7 @@ export class Editor extends Group implements IEditor {
|
|
|
186
187
|
|
|
187
188
|
if (e instanceof ZoomEvent) {
|
|
188
189
|
|
|
189
|
-
if (resizeable === 'zoom') e.stop(), this.scaleOf(element.
|
|
190
|
+
if (resizeable === 'zoom') e.stop(), this.scaleOf(element.getBoxPoint(e), e.scale, e.scale)
|
|
190
191
|
|
|
191
192
|
} else {
|
|
192
193
|
|
|
@@ -217,13 +218,13 @@ export class Editor extends Group implements IEditor {
|
|
|
217
218
|
|
|
218
219
|
if (e instanceof RotateEvent) {
|
|
219
220
|
|
|
220
|
-
if (rotateable === 'rotate') e.stop(), rotation = e.rotation, origin = element.
|
|
221
|
+
if (rotateable === 'rotate') e.stop(), rotation = e.rotation, origin = element.getBoxPoint(e)
|
|
221
222
|
else return
|
|
222
223
|
|
|
223
224
|
} else {
|
|
224
225
|
|
|
225
226
|
const last = { x: e.x - e.moveX, y: e.y - e.moveY }
|
|
226
|
-
const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.
|
|
227
|
+
const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(last), e.shiftKey ? null : (element.around || element.origin || around || 'center'))
|
|
227
228
|
rotation = data.rotation
|
|
228
229
|
origin = data.origin
|
|
229
230
|
|
package/src/display/EditBox.ts
CHANGED
|
@@ -242,6 +242,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
242
242
|
editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1 // move
|
|
243
243
|
} else if ((e.current as IEditPoint).pointType === 'resize') {
|
|
244
244
|
editor.dragStartBounds = { ...editor.element.getLayoutBounds('box', 'local') }
|
|
245
|
+
editor.resizeDirection = (e.current as IEditPoint).direction
|
|
245
246
|
}
|
|
246
247
|
}
|
|
247
248
|
|
|
@@ -249,6 +250,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
249
250
|
this.dragging = false
|
|
250
251
|
this.moving = false
|
|
251
252
|
if (e.current.name === 'rect') this.editor.opacity = 1 // move
|
|
253
|
+
this.editor.resizeDirection = undefined
|
|
252
254
|
|
|
253
255
|
}
|
|
254
256
|
|
|
@@ -139,7 +139,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
139
139
|
if (this.allowDrag(e)) {
|
|
140
140
|
const { editor } = this
|
|
141
141
|
const { stroke, area } = editor.mergeConfig
|
|
142
|
-
const { x, y } = e.
|
|
142
|
+
const { x, y } = e.getInnerPoint(this)
|
|
143
143
|
|
|
144
144
|
this.bounds.set(x, y)
|
|
145
145
|
|
package/src/editor/target.ts
CHANGED
|
@@ -13,6 +13,7 @@ export function onTarget(editor: IEditor, oldValue: IUI | IUI[]): void {
|
|
|
13
13
|
editor.leafList = target instanceof LeafList ? target : new LeafList(target instanceof Array ? target : target as IUI)
|
|
14
14
|
} else {
|
|
15
15
|
editor.leafList.reset()
|
|
16
|
+
editor.closeInnerEditor()
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
editor.emitEvent(new EditorEvent(EditorEvent.SELECT, { editor, value: target, oldValue }))
|
|
@@ -86,7 +86,20 @@ export const EditDataHelper = {
|
|
|
86
86
|
if (lockRatio) {
|
|
87
87
|
const unlockSide = lockRatio === 'corner' && direction % 2
|
|
88
88
|
if (!unlockSide) {
|
|
89
|
-
|
|
89
|
+
let scale: number
|
|
90
|
+
switch (direction) {
|
|
91
|
+
case top:
|
|
92
|
+
case bottom:
|
|
93
|
+
scale = scaleY
|
|
94
|
+
break
|
|
95
|
+
case left:
|
|
96
|
+
case right:
|
|
97
|
+
scale = scaleX
|
|
98
|
+
break
|
|
99
|
+
default:
|
|
100
|
+
scale = Math.sqrt(Math.abs(scaleX * scaleY))
|
|
101
|
+
|
|
102
|
+
}
|
|
90
103
|
scaleX = scaleX < 0 ? -scale : scale
|
|
91
104
|
scaleY = scaleY < 0 ? -scale : scale
|
|
92
105
|
}
|
|
@@ -115,7 +128,9 @@ export const EditDataHelper = {
|
|
|
115
128
|
}
|
|
116
129
|
|
|
117
130
|
|
|
118
|
-
toPoint(around || align, boxBounds, origin)
|
|
131
|
+
toPoint(around || align, boxBounds, origin, true)
|
|
132
|
+
|
|
133
|
+
console.log({ origin, scaleX, scaleY, direction, lockRatio, around })
|
|
119
134
|
|
|
120
135
|
return { origin, scaleX, scaleY, direction, lockRatio, around }
|
|
121
136
|
},
|
|
@@ -140,7 +155,7 @@ export const EditDataHelper = {
|
|
|
140
155
|
align = 'center'
|
|
141
156
|
}
|
|
142
157
|
|
|
143
|
-
toPoint(around || align, bounds, origin)
|
|
158
|
+
toPoint(around || align, bounds, origin, true)
|
|
144
159
|
|
|
145
160
|
return { origin, rotation: PointHelper.getRotation(last, origin, current) }
|
|
146
161
|
},
|
|
@@ -171,12 +186,12 @@ export const EditDataHelper = {
|
|
|
171
186
|
skewY = 1
|
|
172
187
|
}
|
|
173
188
|
|
|
174
|
-
const {
|
|
189
|
+
const { width, height } = bounds
|
|
175
190
|
|
|
176
|
-
last.x =
|
|
177
|
-
last.y =
|
|
191
|
+
last.x = last.x * width
|
|
192
|
+
last.y = last.y * height
|
|
178
193
|
|
|
179
|
-
toPoint(around || align, bounds, origin)
|
|
194
|
+
toPoint(around || align, bounds, origin, true)
|
|
180
195
|
|
|
181
196
|
const rotation = PointHelper.getRotation(last, origin, { x: last.x + (skewX ? move.x : 0), y: last.y + (skewY ? move.y : 0) })
|
|
182
197
|
skewX ? skewX = -rotation : skewY = rotation
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from '@leafer-in/resize';
|
|
2
|
-
import { IBounds, ILeafList, IUI, IFunction, IEventListenerId, ILeaf, IPointerEvent, ILeaferCanvas, IRenderOptions,
|
|
3
|
-
import { Group, UI, Matrix, Event,
|
|
2
|
+
import { IBounds, ILeafList, IUI, IFunction, IEventListenerId, ILeaf, IPointerEvent, ILeaferCanvas, IRenderOptions, IObject, IGroup, IPointData, ILayoutBoundsData, IGroupInputData, IEditSize, IAlign, IAxis, IBox, IBoundsData, IEditorConfig as IEditorConfig$1, IBoxInputData, IKeyEvent, IRect, IRectInputData, IMatrixData, IDragEvent, IAround } from '@leafer-ui/interface';
|
|
3
|
+
import { Group, UI, Direction9, Matrix, Event, Box, Answer } from '@leafer-ui/draw';
|
|
4
4
|
import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent } from '@leafer-ui/core';
|
|
5
5
|
import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditorEvent, IEditPoint, IEditPointType, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent, IEditorGroupEvent, IInnerEditorEvent, IUI as IUI$1, IDragEvent as IDragEvent$1, IPointData as IPointData$1, IPathCommandData, IFromToData, IAround as IAround$1 } from '@leafer-in/interface';
|
|
6
6
|
|
|
@@ -48,7 +48,7 @@ declare class EditMask extends UI {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
declare class Editor extends Group implements IEditor {
|
|
51
|
-
config:
|
|
51
|
+
config: IObject;
|
|
52
52
|
get mergeConfig(): IEditorConfig;
|
|
53
53
|
hoverTarget?: IUI;
|
|
54
54
|
target?: IUI | IUI[];
|
|
@@ -58,6 +58,7 @@ declare class Editor extends Group implements IEditor {
|
|
|
58
58
|
get editing(): boolean;
|
|
59
59
|
innerEditing: boolean;
|
|
60
60
|
get groupOpening(): boolean;
|
|
61
|
+
resizeDirection?: Direction9;
|
|
61
62
|
get multiple(): boolean;
|
|
62
63
|
get single(): boolean;
|
|
63
64
|
get dragging(): boolean;
|