@leafer-in/editor 2.1.3 → 2.1.5
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 +85 -47
- package/dist/editor.esm.js +85 -47
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +85 -47
- 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/config.ts +1 -0
- package/src/decorator/data.ts +2 -1
- package/src/display/EditBox.ts +8 -7
- package/src/display/EditSelect.ts +2 -2
- package/src/display/Stroker.ts +16 -7
- package/src/helper/EditDataHelper.ts +41 -17
- package/src/index.ts +6 -1
- package/src/tool/EditTool.ts +7 -7
- package/src/tool/TransformTool.ts +12 -12
- package/types/index.d.ts +6 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/editor",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
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": "^2.1.
|
|
38
|
-
"@leafer-ui/core": "^2.1.
|
|
39
|
-
"@leafer-in/resize": "^2.1.
|
|
40
|
-
"@leafer-ui/interface": "^2.1.
|
|
41
|
-
"@leafer-in/interface": "^2.1.
|
|
37
|
+
"@leafer-ui/draw": "^2.1.5",
|
|
38
|
+
"@leafer-ui/core": "^2.1.5",
|
|
39
|
+
"@leafer-in/resize": "^2.1.5",
|
|
40
|
+
"@leafer-ui/interface": "^2.1.5",
|
|
41
|
+
"@leafer-in/interface": "^2.1.5"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/config.ts
CHANGED
package/src/decorator/data.ts
CHANGED
|
@@ -60,10 +60,11 @@ export function mergeConfigAttr() {
|
|
|
60
60
|
|
|
61
61
|
if (element && element.editConfig) {
|
|
62
62
|
let { editConfig } = element
|
|
63
|
-
if (editConfig.hover || editConfig.hoverStyle) { // 元素的hover样式,不能覆盖到总配置里
|
|
63
|
+
if (editConfig.hover || editConfig.hoverStyle || editConfig.hoverPathType) { // 元素的hover样式,不能覆盖到总配置里
|
|
64
64
|
editConfig = { ...editConfig }
|
|
65
65
|
delete editConfig.hover
|
|
66
66
|
delete editConfig.hoverStyle
|
|
67
|
+
delete editConfig.hoverPathType
|
|
67
68
|
}
|
|
68
69
|
Object.assign(mergeConfig, editConfig) // 元素上的配置
|
|
69
70
|
}
|
package/src/display/EditBox.ts
CHANGED
|
@@ -151,8 +151,8 @@ export class EditBox extends Group implements IEditBox {
|
|
|
151
151
|
|
|
152
152
|
// 必须来自 editor.update(),需同步更新编辑工具
|
|
153
153
|
public update(): void {
|
|
154
|
-
const { editor } = this
|
|
155
|
-
const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds(
|
|
154
|
+
const { editor, mergeConfig } = this
|
|
155
|
+
const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds(mergeConfig.editBoxType, editor, true)
|
|
156
156
|
this.visible = !this.target.locked
|
|
157
157
|
this.set({ x, y, scaleX, scaleY, rotation, skewX, skewY })
|
|
158
158
|
this.updateBounds({ x: 0, y: 0, width, height })
|
|
@@ -165,9 +165,9 @@ export class EditBox extends Group implements IEditBox {
|
|
|
165
165
|
|
|
166
166
|
|
|
167
167
|
public updateBounds(bounds: IBoundsData): void {
|
|
168
|
-
const { editor,
|
|
168
|
+
const { editor, mergedConfig, single, rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this
|
|
169
169
|
const { editMask } = editor
|
|
170
|
-
const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask, dimOthers, bright, spread, hideRotatePoints, hideResizeLines } =
|
|
170
|
+
const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask, dimOthers, bright, spread, hideRotatePoints, hideResizeLines } = mergedConfig
|
|
171
171
|
|
|
172
172
|
editMask.visible = mask ? true : 0
|
|
173
173
|
|
|
@@ -221,7 +221,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
// rotate
|
|
224
|
-
circle.visible = showPoints && rotateable && !!(
|
|
224
|
+
circle.visible = showPoints && rotateable && !!(mergedConfig.circle || mergedConfig.rotatePoint)
|
|
225
225
|
if (circle.visible) this.layoutCircle()
|
|
226
226
|
|
|
227
227
|
// rect
|
|
@@ -344,7 +344,8 @@ export class EditBox extends Group implements IEditBox {
|
|
|
344
344
|
// 操作事件共用
|
|
345
345
|
|
|
346
346
|
public onTransformStart(e: IUIEvent): void {
|
|
347
|
-
|
|
347
|
+
const { hideOnMove, editBoxType } = this.mergedConfig
|
|
348
|
+
if (this.moving || this.gesturing) this.editor.opacity = hideOnMove ? 0 : 1 // move
|
|
348
349
|
if (this.resizing) ResizeEvent.resizingKeys = this.editor.leafList.keys // 记录正在resize中的元素列表
|
|
349
350
|
|
|
350
351
|
const { dragStartData, target } = this
|
|
@@ -352,7 +353,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
352
353
|
dragStartData.y = e.y
|
|
353
354
|
dragStartData.totalOffset = getPointData() // 缩放、旋转造成的总偏移量,一般用于手势操作的move纠正
|
|
354
355
|
dragStartData.point = { x: target.x, y: target.y } // 用于移动
|
|
355
|
-
dragStartData.bounds = { ...target.getLayoutBounds(
|
|
356
|
+
dragStartData.bounds = { ...target.getLayoutBounds(editBoxType, 'local') } // 用于resize
|
|
356
357
|
dragStartData.rotation = target.rotation // 用于旋转
|
|
357
358
|
}
|
|
358
359
|
|
|
@@ -47,8 +47,8 @@ export class EditSelect extends Group implements IEditSelect {
|
|
|
47
47
|
if (this.running && !this.dragging && !editor.dragging) {
|
|
48
48
|
const { hoverTarget, mergeConfig } = editor, config = { ...mergeConfig }
|
|
49
49
|
if (hoverTarget && hoverTarget.editConfig) Object.assign(config, hoverTarget.editConfig) // hover元素上的配置
|
|
50
|
-
const { stroke, strokeWidth, hover, hoverStyle } = config
|
|
51
|
-
this.hoverStroker.setTarget(hover ? hoverTarget : null, { stroke, strokeWidth, ...(hoverStyle || {}) })
|
|
50
|
+
const { stroke, strokeWidth, hover, hoverStyle, hoverPathType } = config
|
|
51
|
+
this.hoverStroker.setTarget(hover ? hoverTarget : null, { stroke, strokeWidth, strokePathType: hoverPathType, ...(hoverStyle || {}) })
|
|
52
52
|
} else {
|
|
53
53
|
this.hoverStroker.target = null
|
|
54
54
|
}
|
package/src/display/Stroker.ts
CHANGED
|
@@ -21,7 +21,7 @@ export class Stroker extends UI implements IStroker {
|
|
|
21
21
|
public list: IUI[] = []
|
|
22
22
|
|
|
23
23
|
@surfaceType('render-path')
|
|
24
|
-
public strokePathType: 'path' | 'render-path'
|
|
24
|
+
public strokePathType: 'path' | 'render-path' | 'box' | 'stroke'
|
|
25
25
|
|
|
26
26
|
constructor() {
|
|
27
27
|
super()
|
|
@@ -68,12 +68,21 @@ export class Stroker extends UI implements IStroker {
|
|
|
68
68
|
canvas.setWorld(matrix, options.matrix)
|
|
69
69
|
canvas.beginPath()
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
switch (this.strokePathType) {
|
|
72
|
+
case 'box':
|
|
73
|
+
const { boxBounds } = leaf.__layout
|
|
74
|
+
canvas.rect(boxBounds.x, boxBounds.y, boxBounds.width, boxBounds.height)
|
|
75
|
+
break
|
|
76
|
+
case 'stroke':
|
|
77
|
+
const { strokeBounds } = leaf.__layout
|
|
78
|
+
canvas.rect(strokeBounds.x, strokeBounds.y, strokeBounds.width, strokeBounds.height)
|
|
79
|
+
break
|
|
80
|
+
case 'path':
|
|
81
|
+
leaf.__drawPath(canvas)
|
|
82
|
+
break
|
|
83
|
+
default:
|
|
84
|
+
if (leaf.__.__useArrow) leaf.__drawPath(canvas)
|
|
85
|
+
else leaf.__.__pathForRender ? leaf.__drawRenderPath(canvas) : leaf.__drawPathByBox(canvas)
|
|
77
86
|
}
|
|
78
87
|
|
|
79
88
|
data.strokeWidth = strokeWidth / Math.max(aScaleX, aScaleY)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IPointData, IAround, IAlign, IUI, ILayoutBoundsData, IBoundsType } from '@leafer-ui/interface'
|
|
2
2
|
import { AroundHelper, MathHelper, PointHelper, Direction9, isNumber } from '@leafer-ui/draw'
|
|
3
3
|
import { DragBoundsHelper } from '@leafer-ui/core'
|
|
4
4
|
|
|
@@ -10,11 +10,12 @@ const { toPoint } = AroundHelper, { within, sign } = MathHelper, { abs } = Math
|
|
|
10
10
|
|
|
11
11
|
export const EditDataHelper = {
|
|
12
12
|
|
|
13
|
-
getScaleData(target: IUI, startBounds: ILayoutBoundsData, direction: Direction9, totalMoveOrScale: IPointData | number, lockRatio: boolean | 'corner', around: IAround, flipable: boolean, scaleMode: boolean): IEditorScaleEvent {
|
|
13
|
+
getScaleData(target: IUI, startBounds: ILayoutBoundsData, direction: Direction9, totalMoveOrScale: IPointData | number, lockRatio: boolean | 'corner', around: IAround, flipable: boolean, scaleMode: boolean, boundsType: IBoundsType): IEditorScaleEvent {
|
|
14
14
|
let align: IAlign, origin = {} as IPointData, scaleX: number = 1, scaleY: number = 1, lockScale: number
|
|
15
15
|
|
|
16
|
-
const {
|
|
16
|
+
const { widthRange, heightRange, dragBounds, worldTransform, boxBounds } = target
|
|
17
17
|
const { width, height } = startBounds
|
|
18
|
+
const innerBounds = target.getBounds(boundsType, 'inner')
|
|
18
19
|
|
|
19
20
|
// 获取已经改变的比例
|
|
20
21
|
const originChangedScaleX = target.scaleX / startBounds.scaleX
|
|
@@ -22,8 +23,8 @@ export const EditDataHelper = {
|
|
|
22
23
|
const signX = sign(originChangedScaleX)
|
|
23
24
|
const signY = sign(originChangedScaleY)
|
|
24
25
|
|
|
25
|
-
const changedScaleX = scaleMode ? originChangedScaleX : signX *
|
|
26
|
-
const changedScaleY = scaleMode ? originChangedScaleY : signY *
|
|
26
|
+
const changedScaleX = scaleMode ? originChangedScaleX : signX * innerBounds.width / width
|
|
27
|
+
const changedScaleY = scaleMode ? originChangedScaleY : signY * innerBounds.height / height
|
|
27
28
|
|
|
28
29
|
if (isNumber(totalMoveOrScale)) {
|
|
29
30
|
|
|
@@ -112,13 +113,15 @@ export const EditDataHelper = {
|
|
|
112
113
|
|
|
113
114
|
if (!flipable) {
|
|
114
115
|
const { worldTransform } = target
|
|
115
|
-
if (scaleX < 0) scaleX = 1 /
|
|
116
|
-
if (scaleY < 0) scaleY = 1 /
|
|
116
|
+
if (scaleX < 0) scaleX = 1 / innerBounds.width / worldTransform.scaleX
|
|
117
|
+
if (scaleY < 0) scaleY = 1 / innerBounds.height / worldTransform.scaleY
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
// 检查限制
|
|
120
121
|
|
|
121
|
-
toPoint(around || align,
|
|
122
|
+
toPoint(around || align, innerBounds, origin, true)
|
|
123
|
+
|
|
124
|
+
this.checkOrigin(target, origin, boundsType)
|
|
122
125
|
|
|
123
126
|
if (dragBounds) {
|
|
124
127
|
const scaleData = { x: scaleX, y: scaleY }
|
|
@@ -128,18 +131,25 @@ export const EditDataHelper = {
|
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
if (useScaleX && widthRange) {
|
|
131
|
-
const nowWidth =
|
|
134
|
+
const nowWidth = innerBounds.width * target.scaleX
|
|
132
135
|
scaleX = within(nowWidth * scaleX, widthRange) / nowWidth
|
|
133
136
|
}
|
|
134
137
|
|
|
135
138
|
if (useScaleY && heightRange) {
|
|
136
|
-
const nowHeight =
|
|
139
|
+
const nowHeight = innerBounds.height * target.scaleY
|
|
137
140
|
scaleY = within(nowHeight * scaleY, heightRange) / nowHeight
|
|
138
141
|
}
|
|
139
142
|
|
|
140
143
|
// 防止小于1px
|
|
141
|
-
|
|
142
|
-
|
|
144
|
+
let minWidth = 1 * abs(worldTransform.scaleX), minHeight = 1 * abs(worldTransform.scaleY)
|
|
145
|
+
|
|
146
|
+
if (boundsType !== 'box') {
|
|
147
|
+
minWidth += innerBounds.width - boxBounds.width
|
|
148
|
+
minHeight += innerBounds.height - boxBounds.height
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (useScaleX && abs(scaleX * innerBounds.width) < minWidth) scaleX = sign(scaleX) * minWidth / innerBounds.width
|
|
152
|
+
if (useScaleY && abs(scaleY * innerBounds.height) < minHeight) scaleY = sign(scaleY) * minHeight / innerBounds.height
|
|
143
153
|
|
|
144
154
|
if (lockRatio && scaleX !== scaleY) {
|
|
145
155
|
lockScale = Math.min(abs(scaleX), abs(scaleY))
|
|
@@ -153,7 +163,7 @@ export const EditDataHelper = {
|
|
|
153
163
|
return { origin, scaleX, scaleY, direction, lockRatio, around }
|
|
154
164
|
},
|
|
155
165
|
|
|
156
|
-
getRotateData(target: IUI, direction: Direction9, current: IPointData, last: IPointData, around: IAround): IEditorRotateEvent {
|
|
166
|
+
getRotateData(target: IUI, direction: Direction9, current: IPointData, last: IPointData, around: IAround, boundsType: IBoundsType): IEditorRotateEvent {
|
|
157
167
|
let align: IAlign, origin = {} as IPointData
|
|
158
168
|
|
|
159
169
|
switch (direction) {
|
|
@@ -173,12 +183,14 @@ export const EditDataHelper = {
|
|
|
173
183
|
align = 'center'
|
|
174
184
|
}
|
|
175
185
|
|
|
176
|
-
toPoint(around || align, target.
|
|
186
|
+
toPoint(around || align, target.getBounds(boundsType, 'inner'), origin, true)
|
|
187
|
+
|
|
188
|
+
this.checkOrigin(target, origin, boundsType)
|
|
177
189
|
|
|
178
190
|
return { origin, rotation: PointHelper.getRotation(last, target.getWorldPointByBox(origin), current) }
|
|
179
191
|
},
|
|
180
192
|
|
|
181
|
-
getSkewData(
|
|
193
|
+
getSkewData(target: IUI, direction: Direction9, move: IPointData, around: IAround, boundsType: IBoundsType,): IEditorSkewEvent {
|
|
182
194
|
let align: IAlign, origin = {} as IPointData, skewX = 0, skewY = 0
|
|
183
195
|
let last: IPointData
|
|
184
196
|
|
|
@@ -208,12 +220,15 @@ export const EditDataHelper = {
|
|
|
208
220
|
skewY = 1
|
|
209
221
|
}
|
|
210
222
|
|
|
211
|
-
const
|
|
223
|
+
const innerBounds = target.getBounds(boundsType, 'inner')
|
|
224
|
+
const { width, height } = innerBounds
|
|
212
225
|
|
|
213
226
|
last.x = last.x * width
|
|
214
227
|
last.y = last.y * height
|
|
215
228
|
|
|
216
|
-
toPoint(around || align,
|
|
229
|
+
toPoint(around || align, innerBounds, origin, true)
|
|
230
|
+
|
|
231
|
+
this.checkOrigin(target, origin, boundsType)
|
|
217
232
|
|
|
218
233
|
const rotation = PointHelper.getRotation(last, origin, { x: last.x + (skewX ? move.x : 0), y: last.y + (skewY ? move.y : 0) })
|
|
219
234
|
skewX ? skewX = -rotation : skewY = rotation
|
|
@@ -222,6 +237,15 @@ export const EditDataHelper = {
|
|
|
222
237
|
},
|
|
223
238
|
|
|
224
239
|
|
|
240
|
+
checkOrigin(target: IUI, origin: IPointData, boundsType: IBoundsType): void {
|
|
241
|
+
if (boundsType !== 'box') {
|
|
242
|
+
const { boxBounds } = target, innerBounds = target.getBounds(boundsType, 'inner')
|
|
243
|
+
origin.x += innerBounds.x - boxBounds.x
|
|
244
|
+
origin.y += innerBounds.y - boxBounds.y
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
|
|
225
249
|
getAround(around: IAround, altKey: boolean): IAround {
|
|
226
250
|
return (altKey && !around) ? 'center' : around
|
|
227
251
|
},
|
package/src/index.ts
CHANGED
|
@@ -33,6 +33,7 @@ import { Creator, UI, Group, Text, Box, dataType, Plugin } from '@leafer-ui/draw
|
|
|
33
33
|
import '@leafer-in/resize'
|
|
34
34
|
|
|
35
35
|
import { Editor } from './Editor'
|
|
36
|
+
import { EditToolCreator } from './tool/EditToolCreator'
|
|
36
37
|
|
|
37
38
|
|
|
38
39
|
Plugin.add('editor', 'resize')
|
|
@@ -47,7 +48,11 @@ Creator.editor = function (options?: IEditorConfig, app?: IApp): IEditor {
|
|
|
47
48
|
Box.addAttr('textBox', false, dataType)
|
|
48
49
|
|
|
49
50
|
UI.addAttr('editConfig', undefined, dataType)
|
|
50
|
-
UI.addAttr('editOuter', (ui: UI) => {
|
|
51
|
+
UI.addAttr('editOuter', (ui: UI) => {
|
|
52
|
+
ui.updateLayout() // fix: Line 需要更新布局才能精准确定
|
|
53
|
+
const name = (ui.tag === 'Line' ? '' : ui.tag) + 'EditTool'
|
|
54
|
+
return ui.__.__isLinePath ? 'LineEditTool' : (EditToolCreator.list[name] ? name : 'EditTool')
|
|
55
|
+
}, dataType)
|
|
51
56
|
|
|
52
57
|
UI.addAttr('editInner', 'PathEditor', dataType)
|
|
53
58
|
Group.addAttr('editInner', '', dataType) // 必须设为空
|
package/src/tool/EditTool.ts
CHANGED
|
@@ -26,36 +26,36 @@ export class EditTool extends InnerEditor implements IEditTool {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
public onScale(e: IEditorScaleEvent): void {
|
|
29
|
-
const { scaleX, scaleY, transform, worldOrigin, editor } = e
|
|
29
|
+
const { scaleX, scaleY, transform, worldOrigin, editor, editBoxType } = e
|
|
30
30
|
const { app, list } = editor
|
|
31
31
|
app.lockLayout()
|
|
32
32
|
list.forEach(target => {
|
|
33
33
|
const resize = editor.getEditSize(target) !== 'scale'
|
|
34
|
-
if (transform) target.transformWorld(transform, resize)
|
|
35
|
-
else target.scaleOfWorld(worldOrigin, scaleX, scaleY, resize)
|
|
34
|
+
if (transform) target.transformWorld(transform, resize, false, editBoxType)
|
|
35
|
+
else target.scaleOfWorld(worldOrigin, scaleX, scaleY, resize, false, editBoxType)
|
|
36
36
|
})
|
|
37
37
|
app.unlockLayout()
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
public onRotate(e: IEditorRotateEvent): void {
|
|
41
|
-
const { rotation, transform, worldOrigin, editor } = e
|
|
41
|
+
const { rotation, transform, worldOrigin, editor, editBoxType } = e
|
|
42
42
|
const { app, list } = editor
|
|
43
43
|
app.lockLayout()
|
|
44
44
|
list.forEach(target => {
|
|
45
45
|
const resize = editor.getEditSize(target) !== 'scale'
|
|
46
|
-
if (transform) target.transformWorld(transform, resize)
|
|
46
|
+
if (transform) target.transformWorld(transform, resize, false, editBoxType)
|
|
47
47
|
else target.rotateOfWorld(worldOrigin, rotation)
|
|
48
48
|
})
|
|
49
49
|
app.unlockLayout()
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
public onSkew(e: IEditorSkewEvent): void {
|
|
53
|
-
const { skewX, skewY, transform, worldOrigin, editor } = e
|
|
53
|
+
const { skewX, skewY, transform, worldOrigin, editor, editBoxType } = e
|
|
54
54
|
const { app, list } = editor
|
|
55
55
|
app.lockLayout()
|
|
56
56
|
list.forEach(target => {
|
|
57
57
|
const resize = editor.getEditSize(target) !== 'scale'
|
|
58
|
-
if (transform) target.transformWorld(transform, resize)
|
|
58
|
+
if (transform) target.transformWorld(transform, resize, false, editBoxType)
|
|
59
59
|
else target.skewOfWorld(worldOrigin, skewX, skewY, resize)
|
|
60
60
|
})
|
|
61
61
|
app.unlockLayout()
|
|
@@ -54,7 +54,7 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
54
54
|
public onScale(e: DragEvent | ZoomEvent): void {
|
|
55
55
|
|
|
56
56
|
const { target, mergeConfig, single, dragStartData } = this.editBox
|
|
57
|
-
let { around, lockRatio, flipable, editSize } = mergeConfig, totalMove: IPointData | number
|
|
57
|
+
let { around, lockRatio, flipable, editSize, editBoxType } = mergeConfig, totalMove: IPointData | number
|
|
58
58
|
|
|
59
59
|
if (e instanceof ZoomEvent) {
|
|
60
60
|
if (!around) around = target.getBoxPoint(e)
|
|
@@ -66,7 +66,7 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
66
66
|
const { direction } = e.current as IEditPoint
|
|
67
67
|
if (e.shiftKey || target.lockRatio) lockRatio = true
|
|
68
68
|
|
|
69
|
-
const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, totalMove, 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', editBoxType)
|
|
70
70
|
|
|
71
71
|
const targetX = target.x, targetY = target.y
|
|
72
72
|
|
|
@@ -83,7 +83,7 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
83
83
|
public onRotate(e: DragEvent | RotateEvent): void {
|
|
84
84
|
|
|
85
85
|
const { target, mergeConfig, dragStartData } = this.editBox
|
|
86
|
-
const { around, rotateAround, rotateGap, diagonalRotateKey } = mergeConfig
|
|
86
|
+
const { around, rotateAround, rotateGap, diagonalRotateKey, editBoxType } = mergeConfig
|
|
87
87
|
const { direction } = e.current as IEditPoint
|
|
88
88
|
|
|
89
89
|
let origin: IPointData, rotation: number
|
|
@@ -97,7 +97,7 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
97
97
|
|
|
98
98
|
const isDiagonalRotate = diagonalRotateKey ? e.isHoldKeys(diagonalRotateKey) : e.shiftKey // 对角旋转
|
|
99
99
|
|
|
100
|
-
const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, isDiagonalRotate ? null : (rotateAround || target.around || target.origin || around || 'center'))
|
|
100
|
+
const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, isDiagonalRotate ? null : (rotateAround || target.around || target.origin || around || 'center'), editBoxType)
|
|
101
101
|
rotation = dragStartData.rotation + data.rotation - target.rotation
|
|
102
102
|
origin = data.origin
|
|
103
103
|
|
|
@@ -116,9 +116,9 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
116
116
|
public onSkew(e: DragEvent): void {
|
|
117
117
|
|
|
118
118
|
const { target, mergeConfig } = this.editBox
|
|
119
|
-
const { around } = mergeConfig
|
|
119
|
+
const { around, editBoxType } = mergeConfig
|
|
120
120
|
|
|
121
|
-
const { origin, skewX, skewY } = EditDataHelper.getSkewData(target
|
|
121
|
+
const { origin, skewX, skewY } = EditDataHelper.getSkewData(target, (e.current as IEditPoint).direction, e.getInnerMove(target), EditDataHelper.getAround(around, e.altKey), editBoxType)
|
|
122
122
|
if (!skewX && !skewY) return
|
|
123
123
|
|
|
124
124
|
this.skewOf(origin, skewX, skewY)
|
|
@@ -173,7 +173,7 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
173
173
|
|
|
174
174
|
const { target, mergeConfig, single, editor } = this.editBox
|
|
175
175
|
|
|
176
|
-
const { beforeScale } = mergeConfig
|
|
176
|
+
const { beforeScale, editBoxType } = mergeConfig
|
|
177
177
|
if (beforeScale) {
|
|
178
178
|
const check = beforeScale({ target, origin, scaleX, scaleY })
|
|
179
179
|
if (isObject(check)) scaleX = check.scaleX, scaleY = check.scaleY
|
|
@@ -182,7 +182,7 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
182
182
|
|
|
183
183
|
const worldOrigin = this.getWorldOrigin(origin)
|
|
184
184
|
const transform = !single && this.getChangedTransform(() => (target as ISimulateElement).safeChange(() => target.scaleOf(origin, scaleX, scaleY)))
|
|
185
|
-
const data: IEditorScaleEvent = { target, editor, worldOrigin, scaleX, scaleY, transform }
|
|
185
|
+
const data: IEditorScaleEvent = { target, editor, worldOrigin, scaleX, scaleY, transform, editBoxType }
|
|
186
186
|
|
|
187
187
|
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data))
|
|
188
188
|
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data)
|
|
@@ -210,7 +210,7 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
210
210
|
|
|
211
211
|
const { target, mergeConfig, single, editor } = this.editBox
|
|
212
212
|
|
|
213
|
-
const { beforeRotate } = mergeConfig
|
|
213
|
+
const { beforeRotate, editBoxType } = mergeConfig
|
|
214
214
|
if (beforeRotate) {
|
|
215
215
|
const check = beforeRotate({ target, origin, rotation })
|
|
216
216
|
if (isNumber(check)) rotation = check
|
|
@@ -219,7 +219,7 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
219
219
|
|
|
220
220
|
const worldOrigin = this.getWorldOrigin(origin)
|
|
221
221
|
const transform = !single && this.getChangedTransform(() => (target as ISimulateElement).safeChange(() => target.rotateOf(origin, rotation)))
|
|
222
|
-
const data: IEditorRotateEvent = { target, editor, worldOrigin, rotation, transform }
|
|
222
|
+
const data: IEditorRotateEvent = { target, editor, worldOrigin, rotation, transform, editBoxType }
|
|
223
223
|
|
|
224
224
|
this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data))
|
|
225
225
|
const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data)
|
|
@@ -232,7 +232,7 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
232
232
|
|
|
233
233
|
const { target, mergeConfig, single, editor } = this.editBox
|
|
234
234
|
|
|
235
|
-
const { beforeSkew } = mergeConfig
|
|
235
|
+
const { beforeSkew, editBoxType } = mergeConfig
|
|
236
236
|
if (beforeSkew) {
|
|
237
237
|
const check = beforeSkew({ target, origin, skewX, skewY })
|
|
238
238
|
if (isObject(check)) skewX = check.skewX, skewY = check.skewY
|
|
@@ -241,7 +241,7 @@ export class TransformTool implements ITransformTool { // Editor use
|
|
|
241
241
|
|
|
242
242
|
const worldOrigin = this.getWorldOrigin(origin)
|
|
243
243
|
const transform = !single && this.getChangedTransform(() => (target as ISimulateElement).safeChange(() => target.skewOf(origin, skewX, skewY)))
|
|
244
|
-
const data: IEditorSkewEvent = { target, editor, worldOrigin, skewX, skewY, transform }
|
|
244
|
+
const data: IEditorSkewEvent = { target, editor, worldOrigin, skewX, skewY, transform, editBoxType }
|
|
245
245
|
|
|
246
246
|
this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data))
|
|
247
247
|
const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data)
|
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, IEditorDragStartData, IEditorConfig as IEditorConfig$1, ITransformTool, IBoundsData, IBoxInputData, IUIEvent, IKeyEvent, IRect, IRectInputData, IUIInputData, 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, IUIInputData, IMatrixData, IDragEvent, IAround, IEvent, ILayoutBoundsData, IBoundsType } 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';
|
|
@@ -225,7 +225,7 @@ declare class SelectArea extends Group implements ISelectArea {
|
|
|
225
225
|
declare class Stroker extends UI implements IStroker {
|
|
226
226
|
target: IUI | IUI[];
|
|
227
227
|
list: IUI[];
|
|
228
|
-
strokePathType: 'path' | 'render-path';
|
|
228
|
+
strokePathType: 'path' | 'render-path' | 'box' | 'stroke';
|
|
229
229
|
constructor();
|
|
230
230
|
setTarget(target: IUI | IUI[], style?: IUIInputData): void;
|
|
231
231
|
update(style?: IUIInputData): void;
|
|
@@ -398,9 +398,10 @@ declare const EditorHelper: {
|
|
|
398
398
|
};
|
|
399
399
|
|
|
400
400
|
declare const EditDataHelper: {
|
|
401
|
-
getScaleData(target: IUI, startBounds: ILayoutBoundsData, direction: Direction9, totalMoveOrScale: IPointData | number, lockRatio: boolean | "corner", around: IAround, flipable: boolean, scaleMode: boolean): IEditorScaleEvent;
|
|
402
|
-
getRotateData(target: IUI, direction: Direction9, current: IPointData, last: IPointData, around: IAround): IEditorRotateEvent;
|
|
403
|
-
getSkewData(
|
|
401
|
+
getScaleData(target: IUI, startBounds: ILayoutBoundsData, direction: Direction9, totalMoveOrScale: IPointData | number, lockRatio: boolean | "corner", around: IAround, flipable: boolean, scaleMode: boolean, boundsType: IBoundsType): IEditorScaleEvent;
|
|
402
|
+
getRotateData(target: IUI, direction: Direction9, current: IPointData, last: IPointData, around: IAround, boundsType: IBoundsType): IEditorRotateEvent;
|
|
403
|
+
getSkewData(target: IUI, direction: Direction9, move: IPointData, around: IAround, boundsType: IBoundsType): IEditorSkewEvent;
|
|
404
|
+
checkOrigin(target: IUI, origin: IPointData, boundsType: IBoundsType): void;
|
|
404
405
|
getAround(around: IAround, altKey: boolean): IAround;
|
|
405
406
|
getRotateDirection(direction: number, rotation: number, totalDirection?: number): number;
|
|
406
407
|
getFlipDirection(direction: Direction9, flipedX: boolean, flipedY: boolean): Direction9;
|