@leafer-in/editor 1.9.6 → 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.
@@ -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
- if (e instanceof MoveEvent) {
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
- move = DragEvent.getValidMove(target, dragStartData.point, total, checkLimitMove)
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
- this.scaleOf(target.getBoxPoint(e), e.scale, e.scale)
66
-
60
+ around = target.getBoxPoint(e)
61
+ totalMove = e.totalScale
67
62
  } else {
63
+ totalMove = e.getInnerTotal(target)
64
+ }
68
65
 
69
- const { direction } = e.current as IEditPoint
70
- if (e.shiftKey || target.lockRatio) lockRatio = true
66
+ const { direction } = e.current as IEditPoint
67
+ if (e.shiftKey || target.lockRatio) lockRatio = true
71
68
 
72
- const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, e.getInnerTotal(target), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, !single || editSize === 'scale')
69
+ const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, totalMove, lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, !single || editSize === 'scale')
73
70
 
74
- if (this.editTool && this.editTool.onScaleWithDrag) {
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 data = EditDataHelper.getRotateData(target, direction, e, dragStartData, e.shiftKey ? null : (rotateAround || target.around || target.origin || around || 'center'))
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
@@ -1,5 +1,5 @@
1
1
  import * as _leafer_ui_interface from '@leafer-ui/interface';
2
- import { IBounds, ILeafList, IUI, IFunction, IEventListenerId, ILeaf, IPointerEvent, ILeaferCanvas, IRenderOptions, IGroup, IObject, IGroupInputData, IEditSize, IPointData, IAlign, IAxis, IMatrix, IApp, IBox, IEditorDragStartData, IEditorConfig as IEditorConfig$1, ITransformTool, IBoundsData, IBoxInputData, IUIEvent, IKeyEvent, IRect, IRectInputData, IMatrixData, IDragEvent, IAround, IEvent, ILayoutBoundsData } from '@leafer-ui/interface';
2
+ import { IBounds, ILeafList, IUI, IFunction, IEventListenerId, ILeaf, IPointerEvent, ILeaferCanvas, IRenderOptions, IGroup, IObject, IGroupInputData, IEditSize, IPointData, IAlign, IAxis, IMatrix, IApp, IEditorDragStartData, IEditorConfig as IEditorConfig$1, ITransformTool, IBoundsData, IBoxInputData, IUIEvent, IKeyEvent, IRect, IRectInputData, IMatrixData, IDragEvent, IAround, IEvent, ILayoutBoundsData } from '@leafer-ui/interface';
3
3
  import { Group, UI, Direction9, Box, Event } from '@leafer-ui/draw';
4
4
  import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent, KeyEvent } from '@leafer-ui/core';
5
5
  import { IEditSelect, IEditor, IStroker, ISelectArea, IEditorConfig, IEditPoint, ISimulateElement, IEditBox, IEditTool, IInnerEditor, IEditorScaleEvent, IEditPointType, IEditPointInputData, IEditorEvent, IEditorMoveEvent, IEditorRotateEvent, IEditorSkewEvent, IEditorGroupEvent, IInnerEditorEvent, IInnerEditorMode, IUI as IUI$1, IDragEvent as IDragEvent$1, IPointData as IPointData$1, IPathCommandData, IFromToData, IAround as IAround$1 } from '@leafer-in/interface';
@@ -53,8 +53,9 @@ declare class Editor extends Group implements IEditor {
53
53
  config: IEditorConfig;
54
54
  readonly mergeConfig: IEditorConfig;
55
55
  readonly mergedConfig: IEditorConfig;
56
- hoverTarget?: IUI;
57
56
  target?: IUI | IUI[];
57
+ hoverTarget?: IUI;
58
+ dimTarget?: IGroup | IGroup[];
58
59
  leafList: ILeafList;
59
60
  get list(): IUI[];
60
61
  get dragHoverExclude(): IUI[];
@@ -91,6 +92,8 @@ declare class Editor extends Group implements IEditor {
91
92
  addItem(item: IUI): void;
92
93
  removeItem(item: IUI): void;
93
94
  shiftItem(item: IUI): void;
95
+ setDimOthers(value: boolean | number, attrName?: 'bright' | 'dim', list?: IUI[]): void;
96
+ setBright(value: boolean): void;
94
97
  update(): void;
95
98
  updateEditBox(): void;
96
99
  updateEditTool(): void;
@@ -140,7 +143,7 @@ declare class EditBox extends Group implements IEditBox {
140
143
  rotating: boolean;
141
144
  skewing: boolean;
142
145
  view: IGroup;
143
- rect: IBox;
146
+ rect: IEditPoint;
144
147
  circle: IEditPoint;
145
148
  buttons: IGroup;
146
149
  resizePoints: IEditPoint[];
@@ -165,6 +168,7 @@ declare class EditBox extends Group implements IEditBox {
165
168
  get flippedOne(): boolean;
166
169
  get canUse(): boolean;
167
170
  get canGesture(): boolean;
171
+ get canDragLimitAnimate(): boolean;
168
172
  protected __eventIds: IEventListenerId[];
169
173
  constructor(editor: IEditor);
170
174
  create(): void;
@@ -178,12 +182,12 @@ declare class EditBox extends Group implements IEditBox {
178
182
  getPointStyle(userStyle?: IBoxInputData): IBoxInputData;
179
183
  getPointsStyle(): IBoxInputData[];
180
184
  getMiddlePointsStyle(): IBoxInputData[];
181
- protected onDragStart(e: DragEvent): void;
182
- protected onDragEnd(e: DragEvent): void;
183
- protected onDrag(e: DragEvent): void;
184
- protected resetDoing(): void;
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;
185
190
  onMove(e: MoveEvent): void;
186
- onMoveEnd(e: MoveEvent): void;
187
191
  onScale(e: ZoomEvent): void;
188
192
  onRotate(e: RotateEvent): void;
189
193
  isHoldRotateKey(e: IUIEvent): boolean;
@@ -384,7 +388,7 @@ declare const EditorHelper: {
384
388
  };
385
389
 
386
390
  declare const EditDataHelper: {
387
- getScaleData(target: IUI, startBounds: ILayoutBoundsData, direction: Direction9, totalMove: IPointData, lockRatio: boolean | "corner", around: IAround, flipable: boolean, scaleMode: boolean): IEditorScaleEvent;
391
+ getScaleData(target: IUI, startBounds: ILayoutBoundsData, direction: Direction9, totalMoveOrScale: IPointData | number, lockRatio: boolean | "corner", around: IAround, flipable: boolean, scaleMode: boolean): IEditorScaleEvent;
388
392
  getRotateData(target: IUI, direction: Direction9, current: IPointData, last: IPointData, around: IAround): IEditorRotateEvent;
389
393
  getSkewData(bounds: IBoundsData, direction: Direction9, move: IPointData, around: IAround): IEditorSkewEvent;
390
394
  getAround(around: IAround, altKey: boolean): IAround;