@leafer-in/editor 2.1.7 → 2.1.9
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 +35 -24
- package/dist/editor.esm.js +35 -24
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +35 -24
- 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/Editor.ts +9 -5
- package/src/display/EditBox.ts +6 -5
- package/src/helper/EditDataHelper.ts +10 -10
- package/src/tool/EditTool.ts +4 -2
- package/src/tool/EditToolCreator.ts +4 -3
- package/types/index.d.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/editor",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.9",
|
|
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.9",
|
|
38
|
+
"@leafer-ui/core": "^2.1.9",
|
|
39
|
+
"@leafer-in/resize": "^2.1.9",
|
|
40
|
+
"@leafer-ui/interface": "^2.1.9",
|
|
41
|
+
"@leafer-in/interface": "^2.1.9"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/Editor.ts
CHANGED
|
@@ -189,18 +189,22 @@ export class Editor extends Group implements IEditor {
|
|
|
189
189
|
if (EditToolCreator.list[name]) {
|
|
190
190
|
const tool = this.editTool = this.getEditTool(name)
|
|
191
191
|
this.editBox.load()
|
|
192
|
+
tool.editTarget = target
|
|
192
193
|
tool.load()
|
|
193
194
|
this.update()
|
|
194
195
|
}
|
|
195
196
|
}
|
|
196
197
|
}
|
|
197
198
|
|
|
198
|
-
public unloadEditTool(): void {
|
|
199
|
+
public unloadEditTool(onlyTool?: boolean): void {
|
|
199
200
|
let tool = this.editTool
|
|
200
201
|
if (tool) {
|
|
201
|
-
|
|
202
|
+
if (!onlyTool) {
|
|
203
|
+
this.editBox.unload()
|
|
204
|
+
this.editTool = null
|
|
205
|
+
}
|
|
202
206
|
tool.unload()
|
|
203
|
-
|
|
207
|
+
tool.editTarget = null
|
|
204
208
|
}
|
|
205
209
|
}
|
|
206
210
|
|
|
@@ -335,7 +339,7 @@ export class Editor extends Group implements IEditor {
|
|
|
335
339
|
}
|
|
336
340
|
|
|
337
341
|
if (EditToolCreator.list[name]) {
|
|
338
|
-
this.
|
|
342
|
+
this.unloadEditTool(true)
|
|
339
343
|
this.innerEditing = true
|
|
340
344
|
this.innerEditor = this.getInnerEditor(name)
|
|
341
345
|
this.innerEditor.editTarget = target
|
|
@@ -356,7 +360,7 @@ export class Editor extends Group implements IEditor {
|
|
|
356
360
|
this.emitInnerEvent(InnerEditorEvent.CLOSE)
|
|
357
361
|
|
|
358
362
|
if (!onlyInnerEditor) this.updateEditTool()
|
|
359
|
-
this.innerEditor = null
|
|
363
|
+
this.innerEditor = this.innerEditor.editTarget = null
|
|
360
364
|
}
|
|
361
365
|
}
|
|
362
366
|
|
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
|
|
155
|
-
const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds(
|
|
154
|
+
const { editor } = this
|
|
155
|
+
const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds('box', 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, mergeConfig, 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, editBoxType, mask, dimOthers, bright, spread, hideRotatePoints, hideResizeLines } = mergeConfig
|
|
171
171
|
|
|
172
172
|
editMask.visible = mask ? true : 0
|
|
173
173
|
|
|
@@ -179,6 +179,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
179
179
|
editor.cancelDimOthers()
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
if (editBoxType === 'stroke') BoundsHelper.spread(bounds, editor.element.__layout.strokeBoxSpread)
|
|
182
183
|
if (spread) BoundsHelper.spread(bounds, spread)
|
|
183
184
|
|
|
184
185
|
if (this.view.worldOpacity) {
|
|
@@ -221,7 +222,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
221
222
|
}
|
|
222
223
|
|
|
223
224
|
// rotate
|
|
224
|
-
circle.visible = showPoints && rotateable && !!(
|
|
225
|
+
circle.visible = showPoints && rotateable && !!(mergeConfig.circle || mergeConfig.rotatePoint)
|
|
225
226
|
if (circle.visible) this.layoutCircle()
|
|
226
227
|
|
|
227
228
|
// rect
|
|
@@ -14,7 +14,7 @@ export const EditDataHelper = {
|
|
|
14
14
|
let align: IAlign, origin = {} as IPointData, scaleX: number = 1, scaleY: number = 1, lockScale: number
|
|
15
15
|
|
|
16
16
|
const { widthRange, heightRange, dragBounds, worldTransform, boxBounds } = target
|
|
17
|
-
const { width, height } = startBounds
|
|
17
|
+
const { width, height } = startBounds, worldScaleX = abs(worldTransform.scaleX), worldScaleY = abs(worldTransform.scaleY)
|
|
18
18
|
const innerBounds = target.getBounds(boundsType, 'inner')
|
|
19
19
|
|
|
20
20
|
// 获取已经改变的比例
|
|
@@ -112,9 +112,8 @@ export const EditDataHelper = {
|
|
|
112
112
|
if (useScaleY) scaleY /= changedScaleY
|
|
113
113
|
|
|
114
114
|
if (!flipable) {
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
if (scaleY < 0) scaleY = 1 / innerBounds.height / worldTransform.scaleY
|
|
115
|
+
if (scaleX < 0) scaleX = 1 / innerBounds.width / worldScaleX
|
|
116
|
+
if (scaleY < 0) scaleY = 1 / innerBounds.height / worldScaleY
|
|
118
117
|
}
|
|
119
118
|
|
|
120
119
|
// 检查限制
|
|
@@ -140,16 +139,17 @@ export const EditDataHelper = {
|
|
|
140
139
|
scaleY = within(nowHeight * scaleY, heightRange) / nowHeight
|
|
141
140
|
}
|
|
142
141
|
|
|
143
|
-
// 防止小于1px
|
|
144
|
-
let minWidth = 1
|
|
142
|
+
// 防止小于1px, 需要考虑 editSize 的各种情况
|
|
143
|
+
let minWidth = 1, minHeight = 1
|
|
145
144
|
|
|
146
145
|
if (boundsType !== 'box') {
|
|
147
|
-
minWidth += innerBounds.width - boxBounds.width
|
|
148
|
-
minHeight += innerBounds.height - boxBounds.height
|
|
146
|
+
minWidth += (innerBounds.width - boxBounds.width) * worldScaleX
|
|
147
|
+
minHeight += (innerBounds.height - boxBounds.height) * worldScaleY
|
|
149
148
|
}
|
|
150
149
|
|
|
151
|
-
|
|
152
|
-
if (
|
|
150
|
+
const worldWidth = worldScaleX * innerBounds.width, worldHeight = worldScaleY * innerBounds.height
|
|
151
|
+
if (useScaleX && abs(scaleX * worldWidth) < minWidth) scaleX = sign(scaleX) * minWidth / worldWidth
|
|
152
|
+
if (useScaleY && abs(scaleY * worldHeight) < minHeight) scaleY = sign(scaleY) * minHeight / worldHeight
|
|
153
153
|
|
|
154
154
|
if (lockRatio && scaleX !== scaleY) {
|
|
155
155
|
lockScale = Math.min(abs(scaleX), abs(scaleY))
|
package/src/tool/EditTool.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IEditorScaleEvent, IEditorRotateEvent, IEditTool, IEditorSkewEvent, IEditorMoveEvent } from '@leafer-in/interface'
|
|
2
|
+
import { defineKey } from '@leafer-ui/draw'
|
|
2
3
|
|
|
3
4
|
import { registerEditTool, EditToolCreator } from './EditToolCreator'
|
|
4
5
|
import { InnerEditor } from './InnerEditor'
|
|
@@ -7,8 +8,9 @@ import { InnerEditor } from './InnerEditor'
|
|
|
7
8
|
@registerEditTool()
|
|
8
9
|
export class EditTool extends InnerEditor implements IEditTool {
|
|
9
10
|
|
|
10
|
-
static registerEditTool() {
|
|
11
|
-
EditToolCreator.register(this)
|
|
11
|
+
static registerEditTool(name?: string, changeTag?: boolean) {
|
|
12
|
+
EditToolCreator.register(this, name)
|
|
13
|
+
if (changeTag) defineKey(this.prototype, 'tag', { get() { return name } })
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
|
|
@@ -18,10 +18,11 @@ export const EditToolCreator = {
|
|
|
18
18
|
|
|
19
19
|
list: {} as IObject,
|
|
20
20
|
|
|
21
|
-
register(EditTool: IObject): void {
|
|
21
|
+
register(EditTool: IObject, name?: string): void {
|
|
22
22
|
const { tag } = EditTool.prototype as IEditTool
|
|
23
|
-
|
|
24
|
-
list[
|
|
23
|
+
name || (name = tag)
|
|
24
|
+
list[name] && debug.repeat(name)
|
|
25
|
+
list[name] = EditTool
|
|
25
26
|
},
|
|
26
27
|
|
|
27
28
|
get(tag: string, editor: IEditor): IEditTool {
|
package/types/index.d.ts
CHANGED
|
@@ -101,7 +101,7 @@ declare class Editor extends Group implements IEditor {
|
|
|
101
101
|
updateEditBox(): void;
|
|
102
102
|
getEditTool(name: string): IEditTool;
|
|
103
103
|
updateEditTool(): void;
|
|
104
|
-
unloadEditTool(): void;
|
|
104
|
+
unloadEditTool(onlyTool?: boolean): void;
|
|
105
105
|
getEditSize(_ui: IUI): IEditSize;
|
|
106
106
|
onMove(_e: DragEvent | MoveEvent): void;
|
|
107
107
|
onScale(_e: DragEvent | ZoomEvent): void;
|
|
@@ -313,7 +313,7 @@ declare function registerEditTool(): (target: IObject) => void;
|
|
|
313
313
|
declare const registerInnerEditor: typeof registerEditTool;
|
|
314
314
|
declare const EditToolCreator: {
|
|
315
315
|
list: IObject;
|
|
316
|
-
register(EditTool: IObject): void;
|
|
316
|
+
register(EditTool: IObject, name?: string): void;
|
|
317
317
|
get(tag: string, editor: IEditor): IEditTool;
|
|
318
318
|
};
|
|
319
319
|
|
|
@@ -344,7 +344,7 @@ declare class InnerEditor implements IInnerEditor {
|
|
|
344
344
|
}
|
|
345
345
|
|
|
346
346
|
declare class EditTool extends InnerEditor implements IEditTool {
|
|
347
|
-
static registerEditTool(): void;
|
|
347
|
+
static registerEditTool(name?: string, changeTag?: boolean): void;
|
|
348
348
|
get tag(): string;
|
|
349
349
|
onMove(e: IEditorMoveEvent): void;
|
|
350
350
|
onScale(e: IEditorScaleEvent): void;
|