@leafer-in/editor 2.1.8 → 2.1.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/editor",
3
- "version": "2.1.8",
3
+ "version": "2.1.10",
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.8",
38
- "@leafer-ui/core": "^2.1.8",
39
- "@leafer-in/resize": "^2.1.8",
40
- "@leafer-ui/interface": "^2.1.8",
41
- "@leafer-in/interface": "^2.1.8"
37
+ "@leafer-ui/draw": "^2.1.10",
38
+ "@leafer-ui/core": "^2.1.10",
39
+ "@leafer-in/resize": "^2.1.10",
40
+ "@leafer-ui/interface": "^2.1.10",
41
+ "@leafer-in/interface": "^2.1.10"
42
42
  }
43
43
  }
package/src/Editor.ts CHANGED
@@ -189,18 +189,20 @@ 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
- this.editBox.unload()
202
+ if (!onlyTool) this.editBox.unload()
202
203
  tool.unload()
203
- this.editTool = null
204
+ if (!onlyTool) this.editTool = null
205
+ tool.editTarget = null
204
206
  }
205
207
  }
206
208
 
@@ -335,7 +337,7 @@ export class Editor extends Group implements IEditor {
335
337
  }
336
338
 
337
339
  if (EditToolCreator.list[name]) {
338
- this.editTool.unload()
340
+ this.unloadEditTool(true)
339
341
  this.innerEditing = true
340
342
  this.innerEditor = this.getInnerEditor(name)
341
343
  this.innerEditor.editTarget = target
@@ -356,7 +358,7 @@ export class Editor extends Group implements IEditor {
356
358
  this.emitInnerEvent(InnerEditorEvent.CLOSE)
357
359
 
358
360
  if (!onlyInnerEditor) this.updateEditTool()
359
- this.innerEditor = null
361
+ this.innerEditor = this.innerEditor.editTarget = null
360
362
  }
361
363
  }
362
364
 
@@ -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, mergeConfig } = this
155
- const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds(mergeConfig.editBoxType, editor, true)
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, mergedConfig, single, rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this
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 } = mergedConfig
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, this.target.__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 && !!(mergedConfig.circle || mergedConfig.rotatePoint)
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
- const { worldTransform } = target
116
- if (scaleX < 0) scaleX = 1 / innerBounds.width / worldTransform.scaleX
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 * abs(worldTransform.scaleX), minHeight = 1 * abs(worldTransform.scaleY)
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
- 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
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))
@@ -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(name?: string) {
11
+ static registerEditTool(name?: string, changeTag?: boolean) {
11
12
  EditToolCreator.register(this, name)
13
+ if (changeTag) defineKey(this.prototype, 'tag', { get() { return name } })
12
14
  }
13
15
 
14
16
 
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;
@@ -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(name?: string): 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;