@leafer-in/editor 1.0.0-rc.3 → 1.0.0-rc.30

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.
Files changed (41) hide show
  1. package/dist/editor.cjs +1937 -0
  2. package/dist/editor.esm.js +1822 -422
  3. package/dist/editor.esm.min.js +1 -1
  4. package/dist/editor.js +1848 -428
  5. package/dist/editor.min.cjs +1 -0
  6. package/dist/editor.min.js +1 -1
  7. package/package.json +12 -9
  8. package/src/Editor.ts +396 -145
  9. package/src/config.ts +38 -0
  10. package/src/decorator/data.ts +16 -0
  11. package/src/display/EditBox.ts +342 -0
  12. package/src/display/EditMask.ts +37 -0
  13. package/src/display/EditPoint.ts +9 -0
  14. package/src/display/EditSelect.ts +255 -0
  15. package/src/display/SelectArea.ts +30 -0
  16. package/src/display/Stroker.ts +92 -0
  17. package/src/editor/cursor.ts +45 -0
  18. package/src/editor/simulate.ts +14 -0
  19. package/src/editor/target.ts +39 -0
  20. package/src/event/EditorEvent.ts +33 -0
  21. package/src/event/EditorGroupEvent.ts +23 -0
  22. package/src/event/EditorMoveEvent.ts +17 -0
  23. package/src/event/EditorRotateEvent.ts +4 -10
  24. package/src/event/EditorScaleEvent.ts +28 -0
  25. package/src/event/EditorSkewEvent.ts +18 -0
  26. package/src/event/InnerEditorEvent.ts +23 -0
  27. package/src/helper/EditDataHelper.ts +183 -0
  28. package/src/helper/EditSelectHelper.ts +34 -0
  29. package/src/helper/EditorHelper.ts +73 -0
  30. package/src/index.ts +50 -3
  31. package/src/svg.ts +54 -0
  32. package/src/tool/EditTool.ts +99 -0
  33. package/src/tool/EditToolCreator.ts +32 -0
  34. package/src/tool/InnerEditor.ts +68 -0
  35. package/src/tool/LineEditTool.ts +135 -0
  36. package/types/index.d.ts +293 -45
  37. package/src/cursor.ts +0 -57
  38. package/src/event/EditorResizeEvent.ts +0 -34
  39. package/src/resize.ts +0 -87
  40. package/src/tool/LineTool.ts +0 -88
  41. package/src/tool/RectTool.ts +0 -139
package/types/index.d.ts CHANGED
@@ -1,68 +1,316 @@
1
- import { IUI, IPolygon, IEventListenerId, IGroupInputData, IResizeType, IAround, IDragEvent, IBoundsData, IPointData } from '@leafer-ui/interface';
2
- import { IEditor, IEditorConfig, IEditorTool, IDirection8, IEditorResizeEvent, IEditorRotateEvent } from '@leafer-in/interface';
3
- import { Group, DragEvent, RotateEvent, Event } from '@leafer-ui/core';
1
+ export * from '@leafer-in/resize';
2
+ import { IBounds, ILeafList, IUI, IEventListenerId, ILeaf, IPointerEvent, ILeaferCanvas, IRenderOptions, IGroup, IObject, IPointData, IGroupInputData, IEditSize, IAlign, IBox, IBoundsData, IBoxInputData, IKeyEvent, IRect, IRectInputData, IMatrixData, IDragEvent, IAround } from '@leafer-ui/interface';
3
+ import { Group, UI, Event, Direction9, Box, Answer } from '@leafer-ui/draw';
4
+ import { PointerEvent, DragEvent, MoveEvent, ZoomEvent, RotateEvent } from '@leafer-ui/core';
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';
4
6
 
5
- declare class Editor extends Group implements IEditor {
6
- config: IEditorConfig;
7
- resizePoints: IUI[];
8
- rotatePoints: IUI[];
9
- resizeLines: IUI[];
10
- targetRect: IUI;
11
- rect: IPolygon;
12
- circle: IUI;
13
- tool: IEditorTool;
14
- private _target;
15
- get target(): IUI;
16
- set target(value: IUI);
17
- enterPoint: IUI;
7
+ declare class EditSelect extends Group implements IEditSelect {
8
+ editor: IEditor;
9
+ get dragging(): boolean;
10
+ get running(): boolean;
11
+ get isMoveMode(): boolean;
12
+ hoverStroker: IStroker;
13
+ targetStroker: IStroker;
14
+ bounds: IBounds;
15
+ selectArea: ISelectArea;
16
+ protected originList: ILeafList;
17
+ protected needRemoveItem: IUI;
18
18
  protected __eventIds: IEventListenerId[];
19
- protected __targetEventIds: IEventListenerId[];
20
- constructor(userConfig?: IEditorConfig, data?: IGroupInputData);
21
- protected init(): void;
22
- protected onTarget(): void;
23
- getTool(value: IUI): IEditorTool;
19
+ constructor(editor: IEditor);
20
+ protected onHover(): void;
21
+ protected onSelect(): void;
24
22
  update(): void;
23
+ protected onPointerMove(e: PointerEvent): void;
24
+ protected onBeforeDown(e: PointerEvent): void;
25
+ protected onTap(e: PointerEvent): void;
26
+ protected checkAndSelect(e: PointerEvent): void;
27
+ protected onDragStart(e: DragEvent): void;
25
28
  protected onDrag(e: DragEvent): void;
26
- protected onMove(e: DragEvent): void;
27
- protected onRotate(e: DragEvent | RotateEvent): void;
28
- onResize(e: DragEvent): void;
29
- updateMoveCursor(): void;
29
+ protected onDragEnd(): void;
30
+ protected onAutoMove(e: MoveEvent): void;
31
+ protected allow(target: ILeaf): boolean;
32
+ protected allowDrag(e: DragEvent): boolean;
33
+ protected allowSelect(e: IPointerEvent): boolean;
34
+ findDeepOne(e: PointerEvent): IUI;
35
+ findUI(e: PointerEvent): IUI;
36
+ isMultipleSelect(e: IPointerEvent): boolean;
30
37
  protected __listenEvents(): void;
31
38
  protected __removeListenEvents(): void;
32
- protected __listenPointEvents(point: IUI, type: 'rotate' | 'resize', direction: IDirection8): void;
33
- protected __listenTargetEvents(): void;
34
- protected __removeTargetEvents(): void;
35
39
  destroy(): void;
36
40
  }
37
41
 
38
- declare class EditorResizeEvent extends Event implements IEditorResizeEvent {
39
- static RESIZE: string;
42
+ declare class EditMask extends UI {
43
+ editor: IEditor;
44
+ constructor(editor: IEditor);
45
+ __draw(canvas: ILeaferCanvas, options: IRenderOptions): void;
46
+ destroy(): void;
47
+ }
48
+
49
+ declare class Editor extends Group implements IEditor {
50
+ config: IEditorConfig;
51
+ get mergeConfig(): IEditorConfig;
52
+ hoverTarget?: IUI;
53
+ target?: IUI | IUI[];
54
+ get list(): IUI[];
55
+ leafList: ILeafList;
56
+ openedGroupList: ILeafList;
57
+ get editing(): boolean;
58
+ innerEditing: boolean;
59
+ get groupOpening(): boolean;
60
+ get multiple(): boolean;
61
+ get single(): boolean;
62
+ get dragging(): boolean;
63
+ get element(): IUI;
64
+ simulateTarget: IUI;
65
+ editBox: IEditBox;
66
+ get buttons(): IGroup;
67
+ editTool?: IEditTool;
68
+ innerEditor?: IInnerEditor;
69
+ editToolList: IObject;
70
+ selector: EditSelect;
71
+ editMask: EditMask;
72
+ dragStartPoint: IPointData;
73
+ targetEventIds: IEventListenerId[];
74
+ constructor(userConfig?: IEditorConfig, data?: IGroupInputData);
75
+ select(target: IUI | IUI[]): void;
76
+ cancel(): void;
77
+ hasItem(item: IUI): boolean;
78
+ addItem(item: IUI): void;
79
+ removeItem(item: IUI): void;
80
+ shiftItem(item: IUI): void;
81
+ update(): void;
82
+ updateEditBox(): void;
83
+ updateEditTool(): void;
84
+ getEditSize(_ui: IUI): IEditSize;
85
+ onMove(e: DragEvent): void;
86
+ onScale(e: DragEvent | ZoomEvent): void;
87
+ onRotate(e: DragEvent | RotateEvent): void;
88
+ onSkew(e: DragEvent): void;
89
+ move(x: number | IPointData, y?: number): void;
90
+ scaleWithDrag(data: IEditorScaleEvent): void;
91
+ scaleOf(origin: IPointData | IAlign, scaleX: number, scaleY?: number, _resize?: boolean): void;
92
+ rotateOf(origin: IPointData | IAlign, rotation: number): void;
93
+ skewOf(origin: IPointData | IAlign, skewX: number, skewY?: number, _resize?: boolean): void;
94
+ group(userGroup?: IGroup | IGroupInputData): IGroup;
95
+ ungroup(): IUI[];
96
+ openGroup(group: IGroup): void;
97
+ closeGroup(group: IGroup): void;
98
+ checkOpenedGroups(): void;
99
+ checkDeepSelect(): void;
100
+ emitGroupEvent(type: string, group: IGroup): void;
101
+ openInnerEditor(target?: IUI): void;
102
+ closeInnerEditor(): void;
103
+ emitInnerEvent(type: string): void;
104
+ lock(): void;
105
+ unlock(): void;
106
+ toTop(): void;
107
+ toBottom(): void;
108
+ listenTargetEvents(): void;
109
+ removeTargetEvents(): void;
110
+ destroy(): void;
111
+ }
112
+
113
+ declare class EditorEvent extends Event implements IEditorEvent {
114
+ static SELECT: string;
115
+ static HOVER: string;
40
116
  readonly target: IUI;
41
117
  readonly editor: IEditor;
42
- readonly resizeType: IResizeType;
43
- readonly lockRatio: boolean;
44
- readonly around: IAround;
45
- readonly dragEvent: IDragEvent;
46
- readonly direction: IDirection8;
47
- readonly bounds: IBoundsData;
48
- readonly old: IBoundsData;
118
+ readonly value: IUI | IUI[];
119
+ readonly oldValue: IUI | IUI[];
120
+ get list(): IUI[];
121
+ get oldList(): IUI[];
122
+ readonly worldOrigin: IPointData;
49
123
  readonly origin: IPointData;
124
+ constructor(type: string, data?: IEditorEvent);
125
+ }
126
+
127
+ declare class EditBox extends Group implements IEditBox {
128
+ editor: IEditor;
129
+ dragging: boolean;
130
+ moving: boolean;
131
+ view: IGroup;
132
+ rect: IBox;
133
+ circle: IEditPoint;
134
+ buttons: IGroup;
135
+ resizePoints: IEditPoint[];
136
+ rotatePoints: IEditPoint[];
137
+ resizeLines: IEditPoint[];
138
+ get flipped(): boolean;
139
+ get flippedX(): boolean;
140
+ get flippedY(): boolean;
141
+ get flippedOne(): boolean;
142
+ enterPoint: IEditPoint;
143
+ protected __eventIds: IEventListenerId[];
144
+ constructor(editor: IEditor);
145
+ create(): void;
146
+ load(): void;
147
+ update(bounds: IBoundsData): void;
148
+ protected layoutButtons(): void;
149
+ unload(): void;
150
+ getPointStyle(userStyle?: IBoxInputData): IBoxInputData;
151
+ getPointsStyle(): IBoxInputData[];
152
+ getMiddlePointsStyle(): IBoxInputData[];
153
+ protected onSelect(e: EditorEvent): void;
154
+ protected onDragStart(e: DragEvent): void;
155
+ protected onDragEnd(e: DragEvent): void;
156
+ protected onDrag(e: DragEvent): void;
157
+ onArrow(e: IKeyEvent): void;
158
+ protected onDoubleTap(e: PointerEvent): void;
159
+ protected onLongPress(e: PointerEvent): void;
160
+ protected openInner(e: PointerEvent): void;
161
+ listenPointEvents(point: IEditPoint, type: IEditPointType, direction: Direction9): void;
162
+ protected __listenEvents(): void;
163
+ protected __removeListenEvents(): void;
164
+ destroy(): void;
165
+ }
166
+
167
+ declare class EditPoint extends Box implements IEditPoint {
168
+ direction: Direction9;
169
+ pointType: IEditPointType;
170
+ }
171
+
172
+ declare class SelectArea extends Group implements ISelectArea {
173
+ protected strokeArea: IRect;
174
+ protected fillArea: IRect;
175
+ constructor(data?: IGroupInputData);
176
+ setStyle(style: IRectInputData, userStyle?: IRectInputData): void;
177
+ setBounds(bounds: IBoundsData): void;
178
+ }
179
+
180
+ declare class Stroker extends UI implements IStroker {
181
+ target: IUI | IUI[];
182
+ list: IUI[];
183
+ constructor();
184
+ setTarget(target: IUI | IUI[], style: IRectInputData): void;
185
+ __draw(canvas: ILeaferCanvas, options: IRenderOptions): void;
186
+ destroy(): void;
187
+ }
188
+
189
+ declare class EditorMoveEvent extends EditorEvent implements IEditorMoveEvent {
190
+ static MOVE: string;
191
+ readonly moveX: number;
192
+ readonly moveY: number;
193
+ constructor(type: string, data?: IEditorMoveEvent);
194
+ }
195
+
196
+ declare class EditorScaleEvent extends EditorEvent implements IEditorScaleEvent {
197
+ static SCALE: string;
50
198
  readonly scaleX: number;
51
199
  readonly scaleY: number;
52
- constructor(type: string, data?: IEditorResizeEvent);
200
+ readonly transform?: IMatrixData;
201
+ readonly drag: IDragEvent;
202
+ readonly direction: Direction9;
203
+ readonly lockRatio: boolean;
204
+ readonly around: IAround;
205
+ constructor(type: string, data?: IEditorScaleEvent);
53
206
  }
54
207
 
55
- declare class EditorRotateEvent extends Event implements IEditorRotateEvent {
208
+ declare class EditorRotateEvent extends EditorEvent implements IEditorRotateEvent {
56
209
  static ROTATE: string;
57
- readonly target: IUI;
58
- readonly editor: IEditor;
59
- readonly origin: IPointData;
60
210
  readonly rotation: number;
61
211
  constructor(type: string, data?: IEditorRotateEvent);
62
212
  }
63
213
 
64
- declare const LineTool: IEditorTool;
214
+ declare class EditorSkewEvent extends EditorEvent implements IEditorSkewEvent {
215
+ static SKEW: string;
216
+ readonly skewX: number;
217
+ readonly skewY: number;
218
+ constructor(type: string, data?: IEditorSkewEvent);
219
+ }
220
+
221
+ declare class EditorGroupEvent extends EditorEvent implements IEditorGroupEvent {
222
+ static GROUP: string;
223
+ static BEFORE_UNGROUP: string;
224
+ static UNGROUP: string;
225
+ static OPEN: string;
226
+ static CLOSE: string;
227
+ readonly editTarget: IGroup;
228
+ constructor(type: string, data?: IEditorGroupEvent);
229
+ }
230
+
231
+ declare class InnerEditorEvent extends EditorEvent implements IInnerEditorEvent {
232
+ static BEFORE_OPEN: string;
233
+ static OPEN: string;
234
+ static BEFORE_CLOSE: string;
235
+ static CLOSE: string;
236
+ readonly editTarget: IUI;
237
+ readonly innerEditor: IInnerEditor;
238
+ constructor(type: string, data?: IInnerEditorEvent);
239
+ }
240
+
241
+ declare function registerEditTool(): (target: IObject) => void;
242
+ declare const registerInnerEditor: typeof registerEditTool;
243
+ declare const EditToolCreator: {
244
+ list: IObject;
245
+ register(EditTool: IObject): void;
246
+ get(tag: string, editor: IEditor): IEditTool;
247
+ };
248
+
249
+ declare class InnerEditor implements IInnerEditor {
250
+ static registerInnerEditor(): void;
251
+ get tag(): string;
252
+ editTarget: IUI;
253
+ config: IObject;
254
+ editor: IEditor;
255
+ get editBox(): IEditBox;
256
+ view: IGroup;
257
+ eventIds: IEventListenerId[];
258
+ constructor(editor: IEditor);
259
+ onCreate(): void;
260
+ create(): void;
261
+ onLoad(): void;
262
+ load(): void;
263
+ onUpdate(): void;
264
+ update(): void;
265
+ onUnload(): void;
266
+ unload(): void;
267
+ onDestroy(): void;
268
+ destroy(): void;
269
+ }
270
+
271
+ declare class EditTool extends InnerEditor implements IEditTool {
272
+ static registerEditTool(): void;
273
+ get tag(): string;
274
+ onMove(e: IEditorMoveEvent): void;
275
+ onScale(e: IEditorScaleEvent): void;
276
+ onRotate(e: IEditorRotateEvent): void;
277
+ onSkew(e: IEditorSkewEvent): void;
278
+ load(): void;
279
+ update(): void;
280
+ unload(): void;
281
+ }
282
+
283
+ declare class LineEditTool extends EditTool {
284
+ get tag(): string;
285
+ scaleOfEvent: boolean;
286
+ onScaleWithDrag(e: IEditorScaleEvent): void;
287
+ getInnerMove(ui: IUI$1, event: IDragEvent$1, lockRatio: boolean | 'corner'): IPointData$1;
288
+ getFromToByPath(path: IPathCommandData): IFromToData;
289
+ getFromToByPoints(points: number[]): IFromToData;
290
+ dragPoint(fromPoint: IPointData$1, toPoint: IPointData$1, isDragFrom: boolean, around: IAround$1, movePoint: IPointData$1): void;
291
+ onSkew(_e: IEditorSkewEvent): void;
292
+ onUpdate(): void;
293
+ }
294
+
295
+ declare const EditorHelper: {
296
+ group(list: IUI[], element?: IUI, userGroup?: IGroup | IGroupInputData): IGroup;
297
+ ungroup(list: IUI[]): IUI[];
298
+ toTop(list: IUI[]): void;
299
+ toBottom(list: IUI[]): void;
300
+ };
301
+
302
+ declare const EditDataHelper: {
303
+ getScaleData(bounds: IBoundsData, direction: Direction9, pointMove: IPointData, lockRatio: boolean | "corner", around: IAround): IEditorScaleEvent;
304
+ getRotateData(bounds: IBoundsData, direction: Direction9, current: IPointData, last: IPointData, around: IAround): IEditorRotateEvent;
305
+ getSkewData(bounds: IBoundsData, direction: Direction9, move: IPointData, around: IAround): IEditorSkewEvent;
306
+ getAround(around: IAround, altKey: boolean): IAround;
307
+ getRotateDirection(direction: number, rotation: number, totalDirection?: number): number;
308
+ getFlipDirection(direction: Direction9, flipedX: boolean, flipedY: boolean): Direction9;
309
+ };
65
310
 
66
- declare const RectTool: IEditorTool;
311
+ declare const EditSelectHelper: {
312
+ findOne(path: ILeafList): IUI;
313
+ findBounds(leaf: IUI, bounds: IBounds): Answer;
314
+ };
67
315
 
68
- export { Editor, EditorResizeEvent, EditorRotateEvent, LineTool, RectTool };
316
+ export { EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, InnerEditor, InnerEditorEvent, LineEditTool, SelectArea, Stroker, registerEditTool, registerInnerEditor };
package/src/cursor.ts DELETED
@@ -1,57 +0,0 @@
1
- import { ICursorType, IUIEvent } from '@leafer-ui/interface'
2
- import { IDirection8, IEditor } from '@leafer-in/interface'
3
-
4
-
5
- const { topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left } = IDirection8
6
-
7
- export function updateCursor(editor: IEditor, e: IUIEvent): void {
8
-
9
- const point = editor.enterPoint
10
- if (!point || !editor.target || !editor.visible) return
11
-
12
- let { rotation } = editor
13
- let { resizeCursor, rotateCursor, resizeable } = editor.config
14
- const mirror = editor.tool.getMirrorData(editor)
15
- const { __direction, __isResizePoint } = point.__
16
-
17
- editor.enterPoint = point
18
-
19
- if (__isResizePoint && (e.metaKey || e.ctrlKey || !resizeable)) resizeCursor = rotateCursor
20
-
21
- if (mirror.x || mirror.y) {
22
- mirrorCursors(resizeCursor = [...resizeCursor], mirror.x, mirror.y)
23
- mirrorCursors(rotateCursor = [...rotateCursor], mirror.y, mirror.x)
24
- if (mirror.x + mirror.y === 1) rotation = -rotation
25
- }
26
-
27
- let index = (__direction + Math.round(rotation / 45)) % 8
28
- if (index < 0) index += 8
29
-
30
- point.cursor = __isResizePoint ? resizeCursor[index] : rotateCursor[index]
31
-
32
- }
33
-
34
-
35
- export function mirrorCursors(mirror: ICursorType[], mirrorX: number, mirrorY: number): void {
36
-
37
- if (mirrorX) {
38
- const topCursor = mirror[top], topLeftCursor = mirror[topLeft], topRightCursor = mirror[topRight]
39
- mirror[top] = mirror[bottom]
40
- mirror[topLeft] = mirror[bottomLeft]
41
- mirror[topRight] = mirror[bottomRight]
42
- mirror[bottom] = topCursor
43
- mirror[bottomLeft] = topLeftCursor
44
- mirror[bottomRight] = topRightCursor
45
- }
46
-
47
- if (mirrorY) {
48
- const leftCursor = mirror[left], topLeftCursor = mirror[topLeft], bottomLeftCursor = mirror[bottomLeft]
49
- mirror[left] = mirror[right]
50
- mirror[topLeft] = mirror[topRight]
51
- mirror[bottomLeft] = mirror[bottomRight]
52
- mirror[right] = leftCursor
53
- mirror[topRight] = topLeftCursor
54
- mirror[bottomRight] = bottomLeftCursor
55
- }
56
-
57
- }
@@ -1,34 +0,0 @@
1
- import { IUI, IResizeType, IBoundsData, IPointData, IAround, IDragEvent } from '@leafer-ui/interface'
2
- import { IEditor, IDirection8, IEditorResizeEvent } from '@leafer-in/interface'
3
-
4
- import { Event } from '@leafer-ui/core'
5
-
6
- export class EditorResizeEvent extends Event implements IEditorResizeEvent {
7
-
8
- static RESIZE = 'editor.resize'
9
-
10
- declare readonly target: IUI
11
- readonly editor: IEditor
12
-
13
- readonly resizeType: IResizeType
14
- readonly lockRatio: boolean
15
- readonly around: IAround
16
-
17
- readonly dragEvent: IDragEvent
18
- readonly direction: IDirection8
19
-
20
- // from old to bounds
21
- readonly bounds: IBoundsData
22
- readonly old: IBoundsData
23
-
24
- // scaleOf(origin, scaleX, scaleY)
25
- readonly origin: IPointData
26
- readonly scaleX: number
27
- readonly scaleY: number
28
-
29
- constructor(type: string, data?: IEditorResizeEvent) {
30
- super(type)
31
- if (data) Object.assign(this, data)
32
- }
33
-
34
- }
package/src/resize.ts DELETED
@@ -1,87 +0,0 @@
1
- import { IBoundsData, IPointData, IMatrixData, IAround } from '@leafer-ui/interface'
2
- import { IEditorResizeEvent, IDirection8 } from '@leafer-in/interface'
3
-
4
- import { MatrixHelper } from '@leafer-ui/core'
5
-
6
-
7
- const { scaleOfOuter, reset } = MatrixHelper
8
- const { topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left } = IDirection8
9
- const matrix = {} as IMatrixData
10
-
11
- export function getResizeData(old: IBoundsData, direction: IDirection8, move: IPointData, lockRatio: boolean, around: IAround): IEditorResizeEvent {
12
-
13
- if (around) {
14
- move.x *= 2
15
- move.y *= 2
16
- }
17
-
18
- let origin: IPointData, scaleX: number = 1, scaleY: number = 1
19
- const { x, y, width, height } = old
20
-
21
- const topScale = (-move.y + height) / height
22
- const rightScale = (move.x + width) / width
23
- const bottomScale = (move.y + height) / height
24
- const leftScale = (-move.x + width) / width
25
-
26
- switch (direction) {
27
- case top:
28
- scaleY = topScale
29
- if (lockRatio) scaleX = scaleY
30
- origin = { x: x + width / 2, y: y + height }
31
- break
32
- case right:
33
- scaleX = rightScale
34
- if (lockRatio) scaleY = scaleX
35
- origin = { x, y: y + height / 2 }
36
- break
37
- case bottom:
38
- scaleY = bottomScale
39
- if (lockRatio) scaleX = scaleY
40
- origin = { x: x + width / 2, y }
41
- break
42
- case left:
43
- scaleX = leftScale
44
- if (lockRatio) scaleY = scaleX
45
- origin = { x: x + width, y: y + height / 2 }
46
- break
47
- case topLeft:
48
- scaleY = topScale
49
- scaleX = leftScale
50
- if (lockRatio) scaleX = scaleY
51
- origin = { x: x + width, y: y + height }
52
- break
53
- case topRight:
54
- scaleY = topScale
55
- scaleX = rightScale
56
- if (lockRatio) scaleX = scaleY
57
- origin = { x, y: y + height }
58
- break
59
- case bottomRight:
60
- scaleY = bottomScale
61
- scaleX = rightScale
62
- if (lockRatio) scaleX = scaleY
63
- origin = { x, y }
64
- break
65
- case bottomLeft:
66
- scaleY = bottomScale
67
- scaleX = leftScale
68
- if (lockRatio) scaleX = scaleY
69
- origin = { x: x + width, y }
70
- break
71
- }
72
-
73
- if (around) {
74
- if (typeof around === 'object') {
75
- origin = { x: x + width / around.x, y: y + height / around.y }
76
- } else {
77
- origin = { x: x + width / 2, y: y + height / 2 }
78
- }
79
- }
80
-
81
- reset(matrix)
82
- scaleOfOuter(matrix, origin, scaleX, scaleY)
83
- const bounds = { x: old.x + matrix.e, y: old.y + matrix.f, width: width * scaleX, height: height * scaleY }
84
- return { bounds, old, origin, scaleX, scaleY, direction, lockRatio, around, }
85
-
86
- }
87
-
@@ -1,88 +0,0 @@
1
- import { IDirection8, IEditor, IEditorTool, IEditorResizeEvent, IEditorRotateEvent, ILine, IPointData } from '@leafer-in/interface'
2
-
3
- import { RectTool } from './RectTool'
4
-
5
-
6
- const { left, right } = IDirection8
7
-
8
- export const LineTool: IEditorTool = {
9
-
10
- name: 'LineTool',
11
-
12
- getMirrorData(_editor: IEditor): IPointData {
13
- return {
14
- x: 0,
15
- y: 0
16
- }
17
- },
18
-
19
- resize(e: IEditorResizeEvent): void {
20
- const { direction, dragEvent, lockRatio, around } = e
21
- const target = e.target as ILine
22
-
23
- const fromPoint = { x: 0, y: 0 }
24
- const { toPoint } = target
25
-
26
- target.rotation = 0
27
-
28
- let { x, y } = dragEvent.getInnerMove(target)
29
-
30
- if (lockRatio) {
31
- if (Math.abs(x) > Math.abs(y)) {
32
- y = 0
33
- } else {
34
- x = 0
35
- }
36
- }
37
-
38
- if (direction === left) {
39
-
40
- fromPoint.x += x
41
- fromPoint.y += y
42
-
43
- if (around) {
44
- toPoint.x -= x
45
- toPoint.y -= y
46
- }
47
-
48
- } else {
49
-
50
- if (around) {
51
- fromPoint.x -= x
52
- fromPoint.y -= y
53
- }
54
-
55
- toPoint.x += x
56
- toPoint.y += y
57
-
58
- }
59
-
60
- target.getLocalPointByInner(fromPoint, null, null, true)
61
- target.getLocalPointByInner(toPoint, null, null, true)
62
- target.x = fromPoint.x
63
- target.y = fromPoint.y
64
-
65
- target.getInnerPointByLocal(toPoint, null, null, true)
66
- target.toPoint = toPoint
67
-
68
- },
69
-
70
- rotate(e: IEditorRotateEvent): void {
71
- RectTool.rotate(e)
72
- },
73
-
74
- update(editor: IEditor) {
75
-
76
- const { rotatePoints, circle, resizeLines, resizePoints } = editor
77
- RectTool.update(editor)
78
-
79
- for (let i = 0; i < 8; i++) {
80
- if (i < 4) resizeLines[i].visible = false
81
- resizePoints[i].visible = rotatePoints[i].visible = i === left || i === right
82
- }
83
-
84
- circle.visible = false
85
-
86
- }
87
-
88
- }