@leafer-in/editor 1.0.0-rc.21 → 1.0.0-rc.23
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 +1718 -0
- package/dist/editor.esm.js +497 -328
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.js +498 -327
- package/dist/editor.min.cjs +1 -0
- package/dist/editor.min.js +1 -1
- package/package.json +12 -6
- package/src/Editor.ts +114 -30
- package/src/config.ts +2 -1
- package/src/display/EditBox.ts +126 -71
- package/src/display/EditPoint.ts +3 -3
- package/src/display/EditSelect.ts +40 -35
- package/src/display/Stroker.ts +16 -19
- package/src/editor/cursor.ts +3 -3
- package/src/editor/target.ts +3 -1
- package/src/event/EditorScaleEvent.ts +3 -2
- package/src/helper/EditDataHelper.ts +34 -33
- package/src/index.ts +29 -6
- package/src/tool/EditTool.ts +36 -12
- package/src/tool/EditToolCreator.ts +32 -0
- package/src/tool/InnerEditor.ts +64 -0
- package/src/tool/LineEditTool.ts +8 -8
- package/types/index.d.ts +96 -43
- package/src/tool/index.ts +0 -21
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { IBoundsData, IPointData, IAround } from '@leafer-ui/interface'
|
|
2
|
-
import { AroundHelper, PointHelper } from '@leafer-ui/draw'
|
|
1
|
+
import { IBoundsData, IPointData, IAround, IAlign } from '@leafer-ui/interface'
|
|
2
|
+
import { AroundHelper, PointHelper, Direction9 } from '@leafer-ui/draw'
|
|
3
3
|
|
|
4
|
-
import { IEditorScaleEvent,
|
|
4
|
+
import { IEditorScaleEvent, IEditorSkewEvent, IEditorRotateEvent } from '@leafer-in/interface'
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
const { topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left } =
|
|
7
|
+
const { topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left } = Direction9
|
|
8
8
|
const { toPoint } = AroundHelper
|
|
9
9
|
|
|
10
10
|
export const EditDataHelper = {
|
|
11
11
|
|
|
12
|
-
getScaleData(bounds: IBoundsData, direction:
|
|
13
|
-
let
|
|
12
|
+
getScaleData(bounds: IBoundsData, direction: Direction9, pointMove: IPointData, lockRatio: boolean | 'corner', around: IAround): IEditorScaleEvent {
|
|
13
|
+
let align: IAlign, origin = {} as IPointData, scaleX: number = 1, scaleY: number = 1
|
|
14
14
|
const { width, height } = bounds
|
|
15
15
|
|
|
16
16
|
if (around) {
|
|
@@ -30,102 +30,103 @@ export const EditDataHelper = {
|
|
|
30
30
|
switch (direction) {
|
|
31
31
|
case top:
|
|
32
32
|
scaleY = topScale
|
|
33
|
-
|
|
33
|
+
align = 'bottom'
|
|
34
34
|
break
|
|
35
35
|
case right:
|
|
36
36
|
scaleX = rightScale
|
|
37
|
-
|
|
37
|
+
align = 'left'
|
|
38
38
|
break
|
|
39
39
|
case bottom:
|
|
40
40
|
scaleY = bottomScale
|
|
41
|
-
|
|
41
|
+
align = 'top'
|
|
42
42
|
break
|
|
43
43
|
case left:
|
|
44
44
|
scaleX = leftScale
|
|
45
|
-
|
|
45
|
+
align = 'right'
|
|
46
46
|
break
|
|
47
47
|
case topLeft:
|
|
48
48
|
scaleY = topScale
|
|
49
49
|
scaleX = leftScale
|
|
50
|
-
|
|
50
|
+
align = 'bottom-right'
|
|
51
51
|
break
|
|
52
52
|
case topRight:
|
|
53
53
|
scaleY = topScale
|
|
54
54
|
scaleX = rightScale
|
|
55
|
-
|
|
55
|
+
align = 'bottom-left'
|
|
56
56
|
break
|
|
57
57
|
case bottomRight:
|
|
58
58
|
scaleY = bottomScale
|
|
59
59
|
scaleX = rightScale
|
|
60
|
-
|
|
60
|
+
align = 'top-left'
|
|
61
61
|
break
|
|
62
62
|
case bottomLeft:
|
|
63
63
|
scaleY = bottomScale
|
|
64
64
|
scaleX = leftScale
|
|
65
|
-
|
|
65
|
+
align = 'top-right'
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
if (lockRatio) {
|
|
69
69
|
const unlockSide = lockRatio === 'corner' && direction % 2
|
|
70
70
|
if (!unlockSide) {
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
const scale = Math.sqrt(Math.abs(scaleX * scaleY))
|
|
72
|
+
scaleX = scaleX < 0 ? -scale : scale
|
|
73
|
+
scaleY = scaleY < 0 ? -scale : scale
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
toPoint(around ||
|
|
77
|
+
toPoint(around || align, bounds, origin)
|
|
77
78
|
|
|
78
79
|
return { origin, scaleX, scaleY, direction, lockRatio, around }
|
|
79
80
|
},
|
|
80
81
|
|
|
81
|
-
getRotateData(bounds: IBoundsData, direction:
|
|
82
|
-
let
|
|
82
|
+
getRotateData(bounds: IBoundsData, direction: Direction9, current: IPointData, last: IPointData, around: IAround): IEditorRotateEvent {
|
|
83
|
+
let align: IAlign, origin = {} as IPointData
|
|
83
84
|
|
|
84
85
|
switch (direction) {
|
|
85
86
|
case topLeft:
|
|
86
|
-
|
|
87
|
+
align = 'bottom-right'
|
|
87
88
|
break
|
|
88
89
|
case topRight:
|
|
89
|
-
|
|
90
|
+
align = 'bottom-left'
|
|
90
91
|
break
|
|
91
92
|
case bottomRight:
|
|
92
|
-
|
|
93
|
+
align = 'top-left'
|
|
93
94
|
break
|
|
94
95
|
case bottomLeft:
|
|
95
|
-
|
|
96
|
+
align = 'top-right'
|
|
96
97
|
break
|
|
97
98
|
default:
|
|
98
|
-
|
|
99
|
+
align = 'center'
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
toPoint(around ||
|
|
102
|
+
toPoint(around || align, bounds, origin)
|
|
102
103
|
|
|
103
104
|
return { origin, rotation: PointHelper.getRotation(last, origin, current) }
|
|
104
105
|
},
|
|
105
106
|
|
|
106
|
-
getSkewData(bounds: IBoundsData, direction:
|
|
107
|
-
let
|
|
107
|
+
getSkewData(bounds: IBoundsData, direction: Direction9, move: IPointData, around: IAround): IEditorSkewEvent {
|
|
108
|
+
let align: IAlign, origin = {} as IPointData, skewX = 0, skewY = 0
|
|
108
109
|
let last: IPointData
|
|
109
110
|
|
|
110
111
|
switch (direction) {
|
|
111
112
|
case top:
|
|
112
113
|
last = { x: 0.5, y: 0 }
|
|
113
|
-
|
|
114
|
+
align = 'bottom'
|
|
114
115
|
skewX = 1
|
|
115
116
|
break
|
|
116
117
|
case bottom:
|
|
117
118
|
last = { x: 0.5, y: 1 }
|
|
118
|
-
|
|
119
|
+
align = 'top'
|
|
119
120
|
skewX = 1
|
|
120
121
|
break
|
|
121
122
|
case left:
|
|
122
123
|
last = { x: 0, y: 0.5 }
|
|
123
|
-
|
|
124
|
+
align = 'right'
|
|
124
125
|
skewY = 1
|
|
125
126
|
break
|
|
126
127
|
case right:
|
|
127
128
|
last = { x: 1, y: 0.5 }
|
|
128
|
-
|
|
129
|
+
align = 'left'
|
|
129
130
|
skewY = 1
|
|
130
131
|
}
|
|
131
132
|
|
|
@@ -134,7 +135,7 @@ export const EditDataHelper = {
|
|
|
134
135
|
last.x = x + last.x * width
|
|
135
136
|
last.y = y + last.y * height
|
|
136
137
|
|
|
137
|
-
toPoint(around ||
|
|
138
|
+
toPoint(around || align, bounds, origin)
|
|
138
139
|
|
|
139
140
|
const rotation = PointHelper.getRotation(last, origin, { x: last.x + (skewX ? move.x : 0), y: last.y + (skewY ? move.y : 0) })
|
|
140
141
|
skewX ? skewX = -rotation : skewY = rotation
|
|
@@ -153,7 +154,7 @@ export const EditDataHelper = {
|
|
|
153
154
|
return direction
|
|
154
155
|
},
|
|
155
156
|
|
|
156
|
-
getFlipDirection(direction:
|
|
157
|
+
getFlipDirection(direction: Direction9, flipedX: boolean, flipedY: boolean): Direction9 {
|
|
157
158
|
if (flipedX) {
|
|
158
159
|
switch (direction) {
|
|
159
160
|
case left: direction = right; break
|
package/src/index.ts
CHANGED
|
@@ -14,17 +14,40 @@ export { EditorScaleEvent } from './event/EditorScaleEvent'
|
|
|
14
14
|
export { EditorRotateEvent } from './event/EditorRotateEvent'
|
|
15
15
|
export { EditorSkewEvent } from './event/EditorSkewEvent'
|
|
16
16
|
|
|
17
|
-
export {
|
|
17
|
+
export { EditToolCreator, registerEditTool, registerInnerEditor } from './tool/EditToolCreator'
|
|
18
|
+
export { InnerEditor } from './tool/InnerEditor'
|
|
18
19
|
export { EditTool } from './tool/EditTool'
|
|
20
|
+
export { LineEditTool } from './tool/LineEditTool'
|
|
19
21
|
|
|
20
22
|
export { EditorHelper } from './helper/EditorHelper'
|
|
21
23
|
export { EditDataHelper } from './helper/EditDataHelper'
|
|
22
24
|
export { EditSelectHelper } from './helper/EditSelectHelper'
|
|
23
25
|
|
|
24
|
-
import { IEditor, IEditorConfig } from '@leafer-in/interface'
|
|
25
|
-
import { Creator } from '@leafer-ui/
|
|
26
|
+
import { IEditor, IEditorConfig, IEditToolFunction, IEditorConfigFunction } from '@leafer-in/interface'
|
|
27
|
+
import { Creator, UI, Line, defineKey } from '@leafer-ui/draw'
|
|
28
|
+
|
|
26
29
|
import { Editor } from './Editor'
|
|
27
30
|
|
|
28
|
-
Creator.editor = function (options?: IEditorConfig): IEditor {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
Creator.editor = function (options?: IEditorConfig): IEditor { return new Editor(options) }
|
|
32
|
+
|
|
33
|
+
UI.setEditConfig = function (config: IEditorConfig | IEditorConfigFunction): void {
|
|
34
|
+
defineKey(this.prototype, 'editConfig', {
|
|
35
|
+
get(): IEditorConfig { return typeof config === 'function' ? config(this) : config }
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
UI.setEditOuter = function (toolName: string | IEditToolFunction): void {
|
|
40
|
+
defineKey(this.prototype, 'editOuter', {
|
|
41
|
+
get(): string { return typeof toolName === 'string' ? toolName : toolName(this) }
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
UI.setEditInner = function (editorName: string | IEditToolFunction): void {
|
|
46
|
+
defineKey(this.prototype, 'editInner', {
|
|
47
|
+
get(): string { return typeof editorName === 'string' ? editorName : editorName(this) }
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
Line.setEditOuter(function (line: Line): string {
|
|
52
|
+
return (line.points || line.pathInputed) ? 'EditTool' : 'LineEditTool'
|
|
53
|
+
})
|
package/src/tool/EditTool.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IEditorScaleEvent, IEditorRotateEvent, IEditTool, IEditorSkewEvent, IEditorMoveEvent } from '@leafer-in/interface'
|
|
2
2
|
|
|
3
|
+
import { registerEditTool, EditToolCreator } from './EditToolCreator'
|
|
4
|
+
import { InnerEditor } from './InnerEditor'
|
|
3
5
|
|
|
4
|
-
export class EditTool implements IEditTool {
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
@registerEditTool()
|
|
8
|
+
export class EditTool extends InnerEditor implements IEditTool {
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
static registerEditTool() {
|
|
11
|
+
EditToolCreator.register(this)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
public get tag() { return 'EditTool' }
|
|
9
16
|
|
|
10
|
-
|
|
17
|
+
|
|
18
|
+
// 操作
|
|
19
|
+
|
|
20
|
+
public onMove(e: IEditorMoveEvent): void {
|
|
11
21
|
const { moveX, moveY, editor } = e
|
|
12
22
|
const { app, list } = editor
|
|
13
23
|
app.lockLayout()
|
|
@@ -17,7 +27,7 @@ export class EditTool implements IEditTool {
|
|
|
17
27
|
app.unlockLayout()
|
|
18
28
|
}
|
|
19
29
|
|
|
20
|
-
onScale(e: IEditorScaleEvent): void {
|
|
30
|
+
public onScale(e: IEditorScaleEvent): void {
|
|
21
31
|
const { scaleX, scaleY, transform, worldOrigin, editor } = e
|
|
22
32
|
const { app, list } = editor
|
|
23
33
|
app.lockLayout()
|
|
@@ -32,7 +42,7 @@ export class EditTool implements IEditTool {
|
|
|
32
42
|
app.unlockLayout()
|
|
33
43
|
}
|
|
34
44
|
|
|
35
|
-
onRotate(e: IEditorRotateEvent): void {
|
|
45
|
+
public onRotate(e: IEditorRotateEvent): void {
|
|
36
46
|
const { rotation, transform, worldOrigin, editor } = e
|
|
37
47
|
const { app, list } = editor
|
|
38
48
|
app.lockLayout()
|
|
@@ -47,7 +57,7 @@ export class EditTool implements IEditTool {
|
|
|
47
57
|
app.unlockLayout()
|
|
48
58
|
}
|
|
49
59
|
|
|
50
|
-
onSkew(e: IEditorSkewEvent): void {
|
|
60
|
+
public onSkew(e: IEditorSkewEvent): void {
|
|
51
61
|
const { skewX, skewY, transform, worldOrigin, editor } = e
|
|
52
62
|
const { app, list } = editor
|
|
53
63
|
app.lockLayout()
|
|
@@ -62,14 +72,28 @@ export class EditTool implements IEditTool {
|
|
|
62
72
|
app.unlockLayout()
|
|
63
73
|
}
|
|
64
74
|
|
|
65
|
-
|
|
66
|
-
const { simulateTarget, element } = editor
|
|
75
|
+
// 状态
|
|
67
76
|
|
|
77
|
+
public load(): void {
|
|
78
|
+
this.editBox.view.visible = true
|
|
79
|
+
this.onLoad()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public update(): void {
|
|
83
|
+
const { editor, editBox } = this
|
|
84
|
+
|
|
85
|
+
const { simulateTarget, element } = editor
|
|
68
86
|
if (editor.multiple) simulateTarget.parent.updateLayout()
|
|
69
87
|
|
|
70
88
|
const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = element.getLayoutBounds('box', editor, true)
|
|
71
|
-
|
|
72
|
-
|
|
89
|
+
editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY })
|
|
90
|
+
editBox.update({ x: 0, y: 0, width, height })
|
|
91
|
+
this.onUpdate()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public unload(): void {
|
|
95
|
+
this.editBox.view.visible = false
|
|
96
|
+
this.onUnload()
|
|
73
97
|
}
|
|
74
98
|
|
|
75
99
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IObject } from '@leafer-ui/interface'
|
|
2
|
+
import { Debug } from '@leafer-ui/draw'
|
|
3
|
+
|
|
4
|
+
import { IEditTool, IEditor } from '@leafer-in/interface'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const debug = Debug.get('EditToolCreator')
|
|
8
|
+
|
|
9
|
+
export function registerEditTool() {
|
|
10
|
+
return (target: IObject) => {
|
|
11
|
+
EditToolCreator.register(target)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const registerInnerEditor = registerEditTool
|
|
16
|
+
|
|
17
|
+
export const EditToolCreator = {
|
|
18
|
+
|
|
19
|
+
list: {} as IObject,
|
|
20
|
+
|
|
21
|
+
register(EditTool: IObject): void {
|
|
22
|
+
const { tag } = EditTool.prototype as IEditTool
|
|
23
|
+
list[tag] ? debug.repeat(tag) : (list[tag] = EditTool)
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
get(tag: string, editor: IEditor): IEditTool {
|
|
27
|
+
return new list[tag](editor)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const { list } = EditToolCreator
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { IGroup, IEventListenerId } from '@leafer-ui/interface'
|
|
2
|
+
import { IInnerEditor, IEditor, IEditBox } from '@leafer-in/interface'
|
|
3
|
+
|
|
4
|
+
import { Group } from '@leafer-ui/draw'
|
|
5
|
+
import { EditToolCreator } from './EditToolCreator'
|
|
6
|
+
|
|
7
|
+
export class InnerEditor implements IInnerEditor {
|
|
8
|
+
|
|
9
|
+
static registerInnerEditor() {
|
|
10
|
+
EditToolCreator.register(this)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
public get tag() { return 'InnerEditor' }
|
|
15
|
+
|
|
16
|
+
public editor: IEditor
|
|
17
|
+
public get editBox(): IEditBox { return this.editor.editBox }
|
|
18
|
+
|
|
19
|
+
public view: IGroup
|
|
20
|
+
|
|
21
|
+
public eventIds: IEventListenerId[]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
constructor(editor: IEditor) {
|
|
25
|
+
this.editor = editor
|
|
26
|
+
this.create()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
public onCreate(): void { }
|
|
31
|
+
public create(): void {
|
|
32
|
+
this.view = new Group()
|
|
33
|
+
this.onCreate()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// 状态
|
|
38
|
+
|
|
39
|
+
public onLoad(): void { }
|
|
40
|
+
public load(): void {
|
|
41
|
+
this.editor.selector.hittable = this.editor.app.tree.hitChildren = false
|
|
42
|
+
this.onLoad()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public onUpdate(): void { }
|
|
46
|
+
public update(): void { this.onUpdate() }
|
|
47
|
+
|
|
48
|
+
public onUnload(): void { }
|
|
49
|
+
public unload(): void {
|
|
50
|
+
this.editor.selector.hittable = this.editor.app.tree.hitChildren = true
|
|
51
|
+
this.onUnload()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public onDestroy(): void { }
|
|
55
|
+
public destroy(): void {
|
|
56
|
+
this.onDestroy()
|
|
57
|
+
if (this.editor) {
|
|
58
|
+
if (this.view) this.view.destroy()
|
|
59
|
+
if (this.eventIds) this.editor.off_(this.eventIds)
|
|
60
|
+
this.editor = this.view = this.eventIds = null
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
package/src/tool/LineEditTool.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IEditorScaleEvent, ILine, IEditorSkewEvent } from '@leafer-in/interface'
|
|
2
2
|
|
|
3
|
-
import { getPointData } from '@leafer-ui/draw'
|
|
3
|
+
import { getPointData, Direction9 } from '@leafer-ui/draw'
|
|
4
4
|
|
|
5
5
|
import { EditTool } from './EditTool'
|
|
6
|
+
import { registerEditTool } from './EditToolCreator'
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
const { left, right } =
|
|
10
|
+
const { left, right } = Direction9
|
|
10
11
|
|
|
12
|
+
@registerEditTool()
|
|
11
13
|
export class LineEditTool extends EditTool {
|
|
12
14
|
|
|
13
|
-
public tag
|
|
15
|
+
public get tag() { return 'LineEditTool' }
|
|
14
16
|
|
|
15
17
|
public scaleOfEvent = true
|
|
16
18
|
|
|
@@ -69,10 +71,8 @@ export class LineEditTool extends EditTool {
|
|
|
69
71
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
const { rotatePoints, resizeLines, resizePoints } = editor.editBox
|
|
74
|
-
super.update(editor)
|
|
75
|
-
|
|
74
|
+
onUpdate() {
|
|
75
|
+
const { rotatePoints, resizeLines, resizePoints } = this.editor.editBox
|
|
76
76
|
for (let i = 0; i < 8; i++) {
|
|
77
77
|
if (i < 4) resizeLines[i].visible = false
|
|
78
78
|
resizePoints[i].visible = rotatePoints[i].visible = (i === left || i === right)
|