@leafer-in/editor 1.9.7 → 1.9.8
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 +154 -137
- package/dist/editor.esm.js +156 -139
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +152 -135
- package/dist/editor.min.cjs +1 -1
- package/dist/editor.min.cjs.map +1 -1
- package/dist/editor.min.js +1 -1
- package/dist/editor.min.js.map +1 -1
- package/package.json +6 -6
- package/src/decorator/data.ts +6 -6
- package/src/display/EditBox.ts +52 -43
- package/src/display/EditSelect.ts +5 -5
- package/src/helper/EditDataHelper.ts +76 -69
- package/src/tool/TransformTool.ts +35 -30
- package/types/index.d.ts +7 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/editor",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.8",
|
|
4
4
|
"description": "@leafer-in/editor",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"leaferjs"
|
|
35
35
|
],
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@leafer-ui/draw": "^1.9.
|
|
38
|
-
"@leafer-ui/core": "^1.9.
|
|
39
|
-
"@leafer-in/resize": "^1.9.
|
|
40
|
-
"@leafer-ui/interface": "^1.9.
|
|
41
|
-
"@leafer-in/interface": "^1.9.
|
|
37
|
+
"@leafer-ui/draw": "^1.9.8",
|
|
38
|
+
"@leafer-ui/core": "^1.9.8",
|
|
39
|
+
"@leafer-in/resize": "^1.9.8",
|
|
40
|
+
"@leafer-ui/interface": "^1.9.8",
|
|
41
|
+
"@leafer-in/interface": "^1.9.8"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/decorator/data.ts
CHANGED
|
@@ -21,18 +21,18 @@ export function targetAttr(fn: IFunction) {
|
|
|
21
21
|
|
|
22
22
|
const isSelect = key === 'target'
|
|
23
23
|
if (isSelect) {
|
|
24
|
-
t.setDimOthers(false)
|
|
25
|
-
t.setBright(false)
|
|
26
|
-
|
|
27
|
-
if (isArray(value) && value.length > 1 && value[0].locked) value.splice(0, 1) // fix: 单个锁定 + shift多选
|
|
28
|
-
if (t.single) t.element.syncEventer = null // 重置 EditBox.load() 设置
|
|
29
|
-
|
|
30
24
|
const { beforeSelect } = t.config
|
|
31
25
|
if (beforeSelect) {
|
|
32
26
|
const check = beforeSelect({ target: value })
|
|
33
27
|
if (isObject(check)) value = check
|
|
34
28
|
else if (check === false) return
|
|
35
29
|
}
|
|
30
|
+
|
|
31
|
+
t.setDimOthers(false)
|
|
32
|
+
t.setBright(false)
|
|
33
|
+
|
|
34
|
+
if (isArray(value) && value.length > 1 && value[0].locked) value.splice(0, 1) // fix: 单个锁定 + shift多选
|
|
35
|
+
if (t.single) t.element.syncEventer = null // 重置 EditBox.load() 设置
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
const type = isSelect ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER
|
package/src/display/EditBox.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IRect, IEventListenerId, IBoundsData, IPointData, IKeyEvent, IGroup, IBox, IBoxInputData, IAlign, IUI, IEditorConfig, IEditorDragStartData, ITransformTool, IUIEvent, IEditPointInputData } from '@leafer-ui/interface'
|
|
2
|
-
import { Group, Text, AroundHelper, Direction9, ResizeEvent, BoundsHelper, isArray, isString, isNumber } from '@leafer-ui/draw'
|
|
2
|
+
import { Group, Text, AroundHelper, Direction9, ResizeEvent, BoundsHelper, isArray, isString, isNumber, getPointData } from '@leafer-ui/draw'
|
|
3
3
|
import { DragEvent, PointerEvent, KeyEvent, RotateEvent, ZoomEvent, MoveEvent } from '@leafer-ui/core'
|
|
4
4
|
|
|
5
5
|
import { IEditBox, IEditor, IEditPoint, IEditPointType } from '@leafer-in/interface'
|
|
@@ -68,6 +68,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
68
68
|
const { moveable, resizeable, rotateable } = this.mergeConfig
|
|
69
69
|
return isString(moveable) || isString(resizeable) || isString(rotateable)
|
|
70
70
|
}
|
|
71
|
+
public get canDragLimitAnimate(): boolean { return (this.moving && this.mergeConfig.dragLimitAnimate && this.target.dragBounds) as any as boolean }
|
|
71
72
|
|
|
72
73
|
protected __eventIds: IEventListenerId[] = []
|
|
73
74
|
|
|
@@ -285,15 +286,14 @@ export class EditBox extends Group implements IEditBox {
|
|
|
285
286
|
|
|
286
287
|
// drag
|
|
287
288
|
|
|
288
|
-
|
|
289
|
+
public onDragStart(e: DragEvent): void {
|
|
289
290
|
this.dragging = true
|
|
290
291
|
const point = this.dragPoint = e.current as IEditPoint, { pointType } = point
|
|
291
|
-
const {
|
|
292
|
+
const { moveable, resizeable, rotateable, skewable } = this.mergeConfig
|
|
292
293
|
|
|
293
294
|
// 确定模式
|
|
294
295
|
if (pointType === 'move') {
|
|
295
296
|
moveable && (this.moving = true)
|
|
296
|
-
editor.opacity = hideOnMove ? 0 : 1 // move
|
|
297
297
|
} else {
|
|
298
298
|
if (pointType.includes('rotate') || this.isHoldRotateKey(e) || !resizeable) {
|
|
299
299
|
rotateable && (this.rotating = true)
|
|
@@ -303,25 +303,10 @@ export class EditBox extends Group implements IEditBox {
|
|
|
303
303
|
if (pointType === 'skew') skewable && (this.skewing = true)
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
-
|
|
307
|
-
dragStartData.y = e.y
|
|
308
|
-
dragStartData.point = { x: target.x, y: target.y } // 用于移动
|
|
309
|
-
dragStartData.bounds = { ...target.getLayoutBounds('box', 'local') } // 用于resize
|
|
310
|
-
dragStartData.rotation = target.rotation // 用于旋转
|
|
311
|
-
if (pointType && pointType.includes('resize')) ResizeEvent.resizingKeys = editor.leafList.keys // 记录正在resize中的元素列表
|
|
306
|
+
this.onTransformStart(e)
|
|
312
307
|
}
|
|
313
308
|
|
|
314
|
-
|
|
315
|
-
if (this.moving && this.mergeConfig.dragLimitAnimate && this.target.dragBounds) this.transformTool.onMove(e)
|
|
316
|
-
|
|
317
|
-
this.dragPoint = null
|
|
318
|
-
this.resetDoing()
|
|
319
|
-
const { pointType } = e.current as IEditPoint
|
|
320
|
-
if (pointType === 'move') this.editor.opacity = 1 // move
|
|
321
|
-
if (pointType && pointType.includes('resize')) ResizeEvent.resizingKeys = null
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
protected onDrag(e: DragEvent): void {
|
|
309
|
+
public onDrag(e: DragEvent): void {
|
|
325
310
|
const { transformTool, moving, resizing, rotating, skewing } = this
|
|
326
311
|
if (moving) {
|
|
327
312
|
transformTool.onMove(e)
|
|
@@ -335,8 +320,37 @@ export class EditBox extends Group implements IEditBox {
|
|
|
335
320
|
updatePointCursor(this, e)
|
|
336
321
|
}
|
|
337
322
|
|
|
338
|
-
|
|
339
|
-
|
|
323
|
+
public onDragEnd(e: DragEvent): void {
|
|
324
|
+
this.onTransformEnd(e)
|
|
325
|
+
this.dragPoint = null
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// 操作事件共用
|
|
329
|
+
|
|
330
|
+
public onTransformStart(e: IUIEvent): void {
|
|
331
|
+
if (this.canUse) {
|
|
332
|
+
if (this.moving) this.editor.opacity = this.mergedConfig.hideOnMove ? 0 : 1 // move
|
|
333
|
+
if (this.resizing) ResizeEvent.resizingKeys = this.editor.leafList.keys // 记录正在resize中的元素列表
|
|
334
|
+
|
|
335
|
+
const { dragStartData, target } = this
|
|
336
|
+
dragStartData.x = e.x
|
|
337
|
+
dragStartData.y = e.y
|
|
338
|
+
dragStartData.totalOffset = getPointData() // 缩放、旋转造成的总偏移量,一般用于手势操作的move纠正
|
|
339
|
+
dragStartData.point = { x: target.x, y: target.y } // 用于移动
|
|
340
|
+
dragStartData.bounds = { ...target.getLayoutBounds('box', 'local') } // 用于resize
|
|
341
|
+
dragStartData.rotation = target.rotation // 用于旋转
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
public onTransformEnd(e: IUIEvent): void {
|
|
346
|
+
if (this.canUse) {
|
|
347
|
+
if (this.canDragLimitAnimate && (e instanceof DragEvent || e instanceof MoveEvent)) this.transformTool.onMove(e)
|
|
348
|
+
if (this.resizing) ResizeEvent.resizingKeys = null
|
|
349
|
+
|
|
350
|
+
this.dragging = this.gesturing = this.moving = this.resizing = this.rotating = this.skewing = false
|
|
351
|
+
this.editor.opacity = 1
|
|
352
|
+
this.update() // 移动端手势操作hideOnMove移动需强制更新一次
|
|
353
|
+
}
|
|
340
354
|
}
|
|
341
355
|
|
|
342
356
|
// 手势控制元素
|
|
@@ -344,24 +358,19 @@ export class EditBox extends Group implements IEditBox {
|
|
|
344
358
|
public onMove(e: MoveEvent): void {
|
|
345
359
|
if (this.canGesture && e.moveType !== 'drag') {
|
|
346
360
|
e.stop()
|
|
347
|
-
if (isString(this.
|
|
361
|
+
if (isString(this.mergedConfig.moveable)) {
|
|
348
362
|
this.gesturing = this.moving = true
|
|
349
|
-
this.transformTool.onMove(e)
|
|
363
|
+
e.type === MoveEvent.START ? this.onTransformStart(e) : this.transformTool.onMove(e)
|
|
350
364
|
}
|
|
351
365
|
}
|
|
352
366
|
}
|
|
353
367
|
|
|
354
|
-
public onMoveEnd(e: MoveEvent): void {
|
|
355
|
-
if (this.moving) this.transformTool.onMove(e)
|
|
356
|
-
this.resetDoing()
|
|
357
|
-
}
|
|
358
|
-
|
|
359
368
|
public onScale(e: ZoomEvent): void {
|
|
360
369
|
if (this.canGesture) {
|
|
361
370
|
e.stop()
|
|
362
|
-
if (isString(this.
|
|
371
|
+
if (isString(this.mergedConfig.resizeable)) {
|
|
363
372
|
this.gesturing = this.resizing = true
|
|
364
|
-
this.transformTool.onScale(e)
|
|
373
|
+
e.type === ZoomEvent.START ? this.onTransformStart(e) : this.transformTool.onScale(e)
|
|
365
374
|
}
|
|
366
375
|
}
|
|
367
376
|
}
|
|
@@ -369,14 +378,15 @@ export class EditBox extends Group implements IEditBox {
|
|
|
369
378
|
public onRotate(e: RotateEvent): void {
|
|
370
379
|
if (this.canGesture) {
|
|
371
380
|
e.stop()
|
|
372
|
-
if (isString(this.
|
|
381
|
+
if (isString(this.mergedConfig.rotateable)) {
|
|
373
382
|
this.gesturing = this.rotating = true
|
|
374
|
-
this.transformTool.onRotate(e)
|
|
383
|
+
e.type === RotateEvent.START ? this.onTransformStart(e) : this.transformTool.onRotate(e)
|
|
375
384
|
}
|
|
376
385
|
}
|
|
377
386
|
}
|
|
378
387
|
|
|
379
388
|
// 键盘
|
|
389
|
+
|
|
380
390
|
public isHoldRotateKey(e: IUIEvent): boolean { // 按住ctrl在控制点上变旋转功能
|
|
381
391
|
const { rotateKey } = this.mergedConfig
|
|
382
392
|
if (rotateKey) return e.isHoldKeys(rotateKey)
|
|
@@ -388,8 +398,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
388
398
|
}
|
|
389
399
|
|
|
390
400
|
public onArrow(e: IKeyEvent): void {
|
|
391
|
-
|
|
392
|
-
if (this.canUse && editor.editing && this.mergeConfig.keyEvent) {
|
|
401
|
+
if (this.canUse && this.mergeConfig.keyEvent) {
|
|
393
402
|
let x = 0, y = 0
|
|
394
403
|
const distance = e.shiftKey ? 10 : 1
|
|
395
404
|
switch (e.code) {
|
|
@@ -405,7 +414,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
405
414
|
case 'ArrowRight':
|
|
406
415
|
x = distance
|
|
407
416
|
}
|
|
408
|
-
if (x || y) transformTool.move(x, y)
|
|
417
|
+
if (x || y) this.transformTool.move(x, y)
|
|
409
418
|
}
|
|
410
419
|
}
|
|
411
420
|
|
|
@@ -471,12 +480,12 @@ export class EditBox extends Group implements IEditBox {
|
|
|
471
480
|
editor.app.on_([
|
|
472
481
|
[[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
|
|
473
482
|
[KeyEvent.DOWN, this.onArrow, this],
|
|
474
|
-
|
|
475
|
-
[
|
|
476
|
-
[
|
|
477
|
-
[
|
|
478
|
-
|
|
479
|
-
[RotateEvent.END, this.
|
|
483
|
+
|
|
484
|
+
[[MoveEvent.START, MoveEvent.BEFORE_MOVE], this.onMove, this, true],
|
|
485
|
+
[[ZoomEvent.START, ZoomEvent.BEFORE_ZOOM], this.onScale, this, true],
|
|
486
|
+
[[RotateEvent.START, RotateEvent.BEFORE_ROTATE], this.onRotate, this, true],
|
|
487
|
+
|
|
488
|
+
[[MoveEvent.END, ZoomEvent.END, RotateEvent.END], this.onTransformEnd, this],
|
|
480
489
|
])
|
|
481
490
|
)
|
|
482
491
|
})
|
|
@@ -17,8 +17,8 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
17
17
|
public editor: IEditor
|
|
18
18
|
|
|
19
19
|
public get dragging(): boolean { return !!this.originList }
|
|
20
|
-
public get running(): boolean { const { editor } = this; return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector &&
|
|
21
|
-
public get isMoveMode(): boolean { return
|
|
20
|
+
public get running(): boolean { const { editor, app } = this; return this.hittable && editor.visible && editor.hittable && editor.mergeConfig.selector && (app && app.mode === 'normal') }
|
|
21
|
+
public get isMoveMode(): boolean { const { app } = this; return app && app.interaction.moveMode }
|
|
22
22
|
|
|
23
23
|
public hoverStroker: IStroker = new Stroker()
|
|
24
24
|
public targetStroker: IStroker = new Stroker()
|
|
@@ -95,7 +95,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
95
95
|
if (e.multiTouch) return
|
|
96
96
|
|
|
97
97
|
const { editor } = this
|
|
98
|
-
const { select } = editor.mergeConfig
|
|
98
|
+
const { select, selectKeep } = editor.mergeConfig
|
|
99
99
|
|
|
100
100
|
if (select === 'tap') this.checkAndSelect(e)
|
|
101
101
|
else if (this.waitSelect) this.waitSelect()
|
|
@@ -103,7 +103,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
103
103
|
if (this.needRemoveItem) {
|
|
104
104
|
editor.removeItem(this.needRemoveItem)
|
|
105
105
|
} else if (this.isMoveMode) {
|
|
106
|
-
editor.target = null // move.dragEmpty
|
|
106
|
+
if (!selectKeep) editor.target = null // move.dragEmpty
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
}
|
|
@@ -125,7 +125,7 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
125
125
|
|
|
126
126
|
} else if (this.allow(e.target)) {
|
|
127
127
|
|
|
128
|
-
if (!this.isHoldMultipleSelectKey(e)) editor.target = null
|
|
128
|
+
if (!this.isHoldMultipleSelectKey(e) && !this.editor.mergedConfig.selectKeep) editor.target = null
|
|
129
129
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IBoundsData, IPointData, IAround, IAlign, IUI, ILayoutBoundsData } from '@leafer-ui/interface'
|
|
2
|
-
import { AroundHelper, MathHelper, PointHelper, Direction9, DragBoundsHelper } from '@leafer-ui/draw'
|
|
2
|
+
import { AroundHelper, MathHelper, PointHelper, Direction9, DragBoundsHelper, isNumber } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
4
|
import { IEditorScaleEvent, IEditorSkewEvent, IEditorRotateEvent } from '@leafer-in/interface'
|
|
5
5
|
|
|
@@ -10,18 +10,12 @@ const { within, sign } = MathHelper
|
|
|
10
10
|
|
|
11
11
|
export const EditDataHelper = {
|
|
12
12
|
|
|
13
|
-
getScaleData(target: IUI, startBounds: ILayoutBoundsData, direction: Direction9,
|
|
13
|
+
getScaleData(target: IUI, startBounds: ILayoutBoundsData, direction: Direction9, totalMoveOrScale: IPointData | number, lockRatio: boolean | 'corner', around: IAround, flipable: boolean, scaleMode: boolean): IEditorScaleEvent {
|
|
14
14
|
let align: IAlign, origin = {} as IPointData, scaleX: number = 1, scaleY: number = 1
|
|
15
15
|
|
|
16
16
|
const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = target
|
|
17
17
|
const { width, height } = startBounds
|
|
18
18
|
|
|
19
|
-
if (around) {
|
|
20
|
-
totalMove.x *= 2
|
|
21
|
-
totalMove.y *= 2
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
19
|
// 获取已经改变的比例
|
|
26
20
|
const originChangedScaleX = target.scaleX / startBounds.scaleX
|
|
27
21
|
const originChangedScaleY = target.scaleY / startBounds.scaleY
|
|
@@ -31,72 +25,85 @@ export const EditDataHelper = {
|
|
|
31
25
|
const changedScaleX = scaleMode ? originChangedScaleX : signX * boxBounds.width / width
|
|
32
26
|
const changedScaleY = scaleMode ? originChangedScaleY : signY * boxBounds.height / height
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
totalMove.y *= scaleMode ? originChangedScaleY : signY
|
|
28
|
+
if (isNumber(totalMoveOrScale)) {
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
const rightScale = (totalMove.x + width) / width
|
|
39
|
-
const bottomScale = (totalMove.y + height) / height
|
|
40
|
-
const leftScale = (-totalMove.x + width) / width
|
|
30
|
+
scaleX = scaleY = Math.sqrt(totalMoveOrScale)
|
|
41
31
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
scaleX = leftScale
|
|
57
|
-
align = 'right'
|
|
58
|
-
break
|
|
59
|
-
case topLeft:
|
|
60
|
-
scaleY = topScale
|
|
61
|
-
scaleX = leftScale
|
|
62
|
-
align = 'bottom-right'
|
|
63
|
-
break
|
|
64
|
-
case topRight:
|
|
65
|
-
scaleY = topScale
|
|
66
|
-
scaleX = rightScale
|
|
67
|
-
align = 'bottom-left'
|
|
68
|
-
break
|
|
69
|
-
case bottomRight:
|
|
70
|
-
scaleY = bottomScale
|
|
71
|
-
scaleX = rightScale
|
|
72
|
-
align = 'top-left'
|
|
73
|
-
break
|
|
74
|
-
case bottomLeft:
|
|
75
|
-
scaleY = bottomScale
|
|
76
|
-
scaleX = leftScale
|
|
77
|
-
align = 'top-right'
|
|
78
|
-
}
|
|
32
|
+
} else {
|
|
33
|
+
|
|
34
|
+
if (around) {
|
|
35
|
+
totalMoveOrScale.x *= 2
|
|
36
|
+
totalMoveOrScale.y *= 2
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
totalMoveOrScale.x *= scaleMode ? originChangedScaleX : signX
|
|
40
|
+
totalMoveOrScale.y *= scaleMode ? originChangedScaleY : signY
|
|
41
|
+
|
|
42
|
+
const topScale = (-totalMoveOrScale.y + height) / height
|
|
43
|
+
const rightScale = (totalMoveOrScale.x + width) / width
|
|
44
|
+
const bottomScale = (totalMoveOrScale.y + height) / height
|
|
45
|
+
const leftScale = (-totalMoveOrScale.x + width) / width
|
|
79
46
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
47
|
+
switch (direction) {
|
|
48
|
+
case top:
|
|
49
|
+
scaleY = topScale
|
|
50
|
+
align = 'bottom'
|
|
51
|
+
break
|
|
52
|
+
case right:
|
|
53
|
+
scaleX = rightScale
|
|
54
|
+
align = 'left'
|
|
55
|
+
break
|
|
56
|
+
case bottom:
|
|
57
|
+
scaleY = bottomScale
|
|
58
|
+
align = 'top'
|
|
59
|
+
break
|
|
60
|
+
case left:
|
|
61
|
+
scaleX = leftScale
|
|
62
|
+
align = 'right'
|
|
63
|
+
break
|
|
64
|
+
case topLeft:
|
|
65
|
+
scaleY = topScale
|
|
66
|
+
scaleX = leftScale
|
|
67
|
+
align = 'bottom-right'
|
|
68
|
+
break
|
|
69
|
+
case topRight:
|
|
70
|
+
scaleY = topScale
|
|
71
|
+
scaleX = rightScale
|
|
72
|
+
align = 'bottom-left'
|
|
73
|
+
break
|
|
74
|
+
case bottomRight:
|
|
75
|
+
scaleY = bottomScale
|
|
76
|
+
scaleX = rightScale
|
|
77
|
+
align = 'top-left'
|
|
78
|
+
break
|
|
79
|
+
case bottomLeft:
|
|
80
|
+
scaleY = bottomScale
|
|
81
|
+
scaleX = leftScale
|
|
82
|
+
align = 'top-right'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (lockRatio) {
|
|
86
|
+
if (lockRatio === 'corner' && direction % 2) {
|
|
87
|
+
lockRatio = false
|
|
88
|
+
} else {
|
|
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
|
+
scaleX = scaleX < 0 ? -scale : scale
|
|
103
|
+
scaleY = scaleY < 0 ? -scale : scale
|
|
96
104
|
}
|
|
97
|
-
scaleX = scaleX < 0 ? -scale : scale
|
|
98
|
-
scaleY = scaleY < 0 ? -scale : scale
|
|
99
105
|
}
|
|
106
|
+
|
|
100
107
|
}
|
|
101
108
|
|
|
102
109
|
const useScaleX = scaleX !== 1, useScaleY = scaleY !== 1
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IEvent, IPointData, IAlign, IAxis, IFunction, IMatrix, IUI } from '@leafer-ui/interface'
|
|
2
|
-
import { MathHelper, Matrix, LeafHelper, AroundHelper, isObject, isString, isNumber } from '@leafer-ui/draw'
|
|
2
|
+
import { MathHelper, PointHelper, Matrix, LeafHelper, AroundHelper, isObject, isString, isNumber } from '@leafer-ui/draw'
|
|
3
3
|
import { DragEvent, RotateEvent, ZoomEvent, MoveEvent } from '@leafer-ui/core'
|
|
4
4
|
|
|
5
5
|
import { IEditBox, IEditPoint, IEditTool, IEditorScaleEvent, ISimulateElement, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent } from '@leafer-in/interface'
|
|
@@ -12,6 +12,7 @@ import { EditorSkewEvent } from '../event/EditorSkewEvent'
|
|
|
12
12
|
import { EditDataHelper } from '../helper/EditDataHelper'
|
|
13
13
|
import { ITransformTool } from '@leafer-ui/interface'
|
|
14
14
|
|
|
15
|
+
|
|
15
16
|
export class TransformTool implements ITransformTool { // Editor use
|
|
16
17
|
|
|
17
18
|
public editBox: IEditBox
|
|
@@ -31,24 +32,19 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
31
32
|
const axisDrag = isString(target.draggable)
|
|
32
33
|
const checkLimitMove = !dragLimitAnimate || isMoveEnd || axisDrag
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
move = e.getLocalMove(target)
|
|
37
|
-
if (checkLimitMove) DragEvent.limitMove(target, move)
|
|
38
|
-
|
|
39
|
-
} else {
|
|
40
|
-
|
|
41
|
-
const total = { x: e.totalX, y: e.totalY }
|
|
42
|
-
|
|
43
|
-
if (e.shiftKey) {
|
|
44
|
-
if (Math.abs(total.x) > Math.abs(total.y)) total.y = 0
|
|
45
|
-
else total.x = 0
|
|
46
|
-
}
|
|
35
|
+
const total = { x: e.totalX, y: e.totalY }
|
|
47
36
|
|
|
48
|
-
|
|
37
|
+
if (e instanceof MoveEvent) {
|
|
38
|
+
PointHelper.move(total, target.getWorldPointByLocal(dragStartData.totalOffset, null, true))
|
|
39
|
+
}
|
|
49
40
|
|
|
41
|
+
if (e.shiftKey) {
|
|
42
|
+
if (Math.abs(total.x) > Math.abs(total.y)) total.y = 0
|
|
43
|
+
else total.x = 0
|
|
50
44
|
}
|
|
51
45
|
|
|
46
|
+
move = DragEvent.getValidMove(target, dragStartData.point, total, checkLimitMove)
|
|
47
|
+
|
|
52
48
|
if (move.x || move.y) {
|
|
53
49
|
if (dragLimitAnimate && !axisDrag && isMoveEnd) LeafHelper.animateMove(this as unknown as IUI, move, isNumber(dragLimitAnimate) ? dragLimitAnimate : 0.3) // 是否进行动画
|
|
54
50
|
else this.move(move)
|
|
@@ -58,33 +54,36 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
58
54
|
public onScale(e: DragEvent | ZoomEvent): void {
|
|
59
55
|
|
|
60
56
|
const { target, mergeConfig, single, dragStartData } = this.editBox
|
|
61
|
-
let { around, lockRatio, flipable, editSize } = mergeConfig
|
|
57
|
+
let { around, lockRatio, flipable, editSize } = mergeConfig, totalMove: IPointData | number
|
|
62
58
|
|
|
63
59
|
if (e instanceof ZoomEvent) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
around = target.getBoxPoint(e)
|
|
61
|
+
totalMove = e.totalScale
|
|
67
62
|
} else {
|
|
63
|
+
totalMove = e.getInnerTotal(target)
|
|
64
|
+
}
|
|
68
65
|
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
const { direction } = e.current as IEditPoint
|
|
67
|
+
if (e.shiftKey || target.lockRatio) lockRatio = true
|
|
71
68
|
|
|
72
|
-
|
|
69
|
+
const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, totalMove, lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, !single || editSize === 'scale')
|
|
73
70
|
|
|
74
|
-
|
|
75
|
-
data.drag = e
|
|
76
|
-
this.scaleWithDrag(data)
|
|
77
|
-
} else {
|
|
78
|
-
this.scaleOf(data.origin, data.scaleX, data.scaleY)
|
|
79
|
-
}
|
|
71
|
+
const targetX = target.x, targetY = target.y
|
|
80
72
|
|
|
73
|
+
if (e instanceof DragEvent && this.editTool && this.editTool.onScaleWithDrag) {
|
|
74
|
+
data.drag = e
|
|
75
|
+
this.scaleWithDrag(data)
|
|
76
|
+
} else {
|
|
77
|
+
this.scaleOf(data.origin, data.scaleX, data.scaleY)
|
|
81
78
|
}
|
|
79
|
+
|
|
80
|
+
PointHelper.move(dragStartData.totalOffset, target.x - targetX, target.y - targetY)
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
public onRotate(e: DragEvent | RotateEvent): void {
|
|
85
84
|
|
|
86
85
|
const { target, mergeConfig, dragStartData } = this.editBox
|
|
87
|
-
const { around, rotateAround, rotateGap } = mergeConfig
|
|
86
|
+
const { around, rotateAround, rotateGap, diagonalRotateKey } = mergeConfig
|
|
88
87
|
const { direction } = e.current as IEditPoint
|
|
89
88
|
|
|
90
89
|
let origin: IPointData, rotation: number
|
|
@@ -96,7 +95,9 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
96
95
|
|
|
97
96
|
} else {
|
|
98
97
|
|
|
99
|
-
const
|
|
98
|
+
const isDiagonalRotate = diagonalRotateKey ? e.isHoldKeys(diagonalRotateKey) : e.shiftKey // 对角旋转
|
|
99
|
+
|
|
100
|
+
const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, isDiagonalRotate ? null : (rotateAround || target.around || target.origin || around || 'center'))
|
|
100
101
|
rotation = dragStartData.rotation + data.rotation - target.rotation
|
|
101
102
|
origin = data.origin
|
|
102
103
|
|
|
@@ -105,7 +106,11 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
105
106
|
rotation = MathHelper.float(MathHelper.getGapRotation(rotation, rotateGap, target.rotation), 2)
|
|
106
107
|
if (!rotation) return
|
|
107
108
|
|
|
109
|
+
const targetX = target.x, targetY = target.y
|
|
110
|
+
|
|
108
111
|
this.rotateOf(origin, rotation)
|
|
112
|
+
|
|
113
|
+
PointHelper.move(dragStartData.totalOffset, target.x - targetX, target.y - targetY)
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
public onSkew(e: DragEvent): void {
|
package/types/index.d.ts
CHANGED
|
@@ -168,6 +168,7 @@ declare class EditBox extends Group implements IEditBox {
|
|
|
168
168
|
get flippedOne(): boolean;
|
|
169
169
|
get canUse(): boolean;
|
|
170
170
|
get canGesture(): boolean;
|
|
171
|
+
get canDragLimitAnimate(): boolean;
|
|
171
172
|
protected __eventIds: IEventListenerId[];
|
|
172
173
|
constructor(editor: IEditor);
|
|
173
174
|
create(): void;
|
|
@@ -181,12 +182,12 @@ declare class EditBox extends Group implements IEditBox {
|
|
|
181
182
|
getPointStyle(userStyle?: IBoxInputData): IBoxInputData;
|
|
182
183
|
getPointsStyle(): IBoxInputData[];
|
|
183
184
|
getMiddlePointsStyle(): IBoxInputData[];
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
onDragStart(e: DragEvent): void;
|
|
186
|
+
onDrag(e: DragEvent): void;
|
|
187
|
+
onDragEnd(e: DragEvent): void;
|
|
188
|
+
onTransformStart(e: IUIEvent): void;
|
|
189
|
+
onTransformEnd(e: IUIEvent): void;
|
|
188
190
|
onMove(e: MoveEvent): void;
|
|
189
|
-
onMoveEnd(e: MoveEvent): void;
|
|
190
191
|
onScale(e: ZoomEvent): void;
|
|
191
192
|
onRotate(e: RotateEvent): void;
|
|
192
193
|
isHoldRotateKey(e: IUIEvent): boolean;
|
|
@@ -387,7 +388,7 @@ declare const EditorHelper: {
|
|
|
387
388
|
};
|
|
388
389
|
|
|
389
390
|
declare const EditDataHelper: {
|
|
390
|
-
getScaleData(target: IUI, startBounds: ILayoutBoundsData, direction: Direction9,
|
|
391
|
+
getScaleData(target: IUI, startBounds: ILayoutBoundsData, direction: Direction9, totalMoveOrScale: IPointData | number, lockRatio: boolean | "corner", around: IAround, flipable: boolean, scaleMode: boolean): IEditorScaleEvent;
|
|
391
392
|
getRotateData(target: IUI, direction: Direction9, current: IPointData, last: IPointData, around: IAround): IEditorRotateEvent;
|
|
392
393
|
getSkewData(bounds: IBoundsData, direction: Direction9, move: IPointData, around: IAround): IEditorSkewEvent;
|
|
393
394
|
getAround(around: IAround, altKey: boolean): IAround;
|