@leafer-in/editor 1.9.9 → 1.9.11

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": "1.9.9",
3
+ "version": "1.9.11",
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": "^1.9.9",
38
- "@leafer-ui/core": "^1.9.9",
39
- "@leafer-in/resize": "^1.9.9",
40
- "@leafer-ui/interface": "^1.9.9",
41
- "@leafer-in/interface": "^1.9.9"
37
+ "@leafer-ui/draw": "^1.9.11",
38
+ "@leafer-ui/core": "^1.9.11",
39
+ "@leafer-in/resize": "^1.9.11",
40
+ "@leafer-ui/interface": "^1.9.11",
41
+ "@leafer-in/interface": "^1.9.11"
42
42
  }
43
43
  }
@@ -32,7 +32,10 @@ export function targetAttr(fn: IFunction) {
32
32
  t.setBright(false)
33
33
 
34
34
  if (isArray(value) && value.length > 1 && value[0].locked) value.splice(0, 1) // fix: 单个锁定 + shift多选
35
- if (t.single) t.element.syncEventer = null // 重置 EditBox.load() 设置
35
+ if (t.single) {
36
+ delete t.element.syncEventer // 重置 EditBox.load() 同步事件设置
37
+ delete t.element.__world.ignorePixelSnap // 重置 EditBox.load() 忽略对齐像素设置
38
+ }
36
39
  }
37
40
 
38
41
  const type = isSelect ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER
@@ -52,7 +55,15 @@ export function mergeConfigAttr() {
52
55
  defineKey(target, key, {
53
56
  get() {
54
57
  const { config, element, dragPoint, editBox, app } = this, mergeConfig = { ...config } // 实时合并,后期可优化
55
- if (element && element.editConfig) Object.assign(mergeConfig, element.editConfig) // 元素上的配置
58
+ if (element && element.editConfig) {
59
+ let { editConfig } = element
60
+ if (editConfig.hover || editConfig.hoverStyle) { // 元素的hover样式,不能覆盖到总配置里
61
+ editConfig = { ...editConfig }
62
+ delete editConfig.hover
63
+ delete editConfig.hoverStyle
64
+ }
65
+ Object.assign(mergeConfig, editConfig) // 元素上的配置
66
+ }
56
67
  if (editBox.config) Object.assign(mergeConfig, editBox.config) // EditBox 上的配置
57
68
  if (dragPoint) {
58
69
  if (dragPoint.editConfig) Object.assign(mergeConfig, dragPoint.editConfig)
@@ -1,5 +1,5 @@
1
1
  import { IRect, IEventListenerId, IBoundsData, IPointData, IKeyEvent, IGroup, IBox, IBoxInputData, IAlign, IUI, IEditorConfig, IEditorDragStartData, ITransformTool, IUIEvent, IEditPointInputData } from '@leafer-ui/interface'
2
- import { Group, Text, AroundHelper, Direction9, ResizeEvent, BoundsHelper, isArray, isString, isNumber, getPointData } from '@leafer-ui/draw'
2
+ import { Group, Text, AroundHelper, Direction9, ResizeEvent, BoundsHelper, DataHelper, isArray, isString, isNumber, isNull, getPointData } from '@leafer-ui/draw'
3
3
  import { DragEvent, PointerEvent, KeyEvent, RotateEvent, ZoomEvent, MoveEvent } from '@leafer-ui/core'
4
4
 
5
5
  import { IEditBox, IEditor, IEditPoint, IEditPointType } from '@leafer-in/interface'
@@ -62,7 +62,7 @@ export class EditBox extends Group implements IEditBox {
62
62
  public get flippedY(): boolean { return this.scaleY < 0 }
63
63
  public get flippedOne(): boolean { return this.scaleX * this.scaleY < 0 }
64
64
 
65
- public get canUse(): boolean { return (this.visible && this.view.visible) as boolean } // 编辑框是否处于激活状态
65
+ public get canUse(): boolean { return this.app && this.editor.editing } // 编辑框是否处于激活状态
66
66
  public get canGesture(): boolean { // 是否支持手势
67
67
  if (!this.canUse) return false
68
68
  const { moveable, resizeable, rotateable } = this.mergeConfig
@@ -111,7 +111,7 @@ export class EditBox extends Group implements IEditBox {
111
111
 
112
112
  public load(): void {
113
113
  const { target, mergeConfig, single, rect, circle, resizePoints, resizeLines } = this
114
- const { stroke, strokeWidth, resizeLine } = mergeConfig
114
+ const { stroke, strokeWidth, resizeLine, ignorePixelSnap } = mergeConfig
115
115
 
116
116
  const pointsStyle = this.getPointsStyle()
117
117
  const middlePointsStyle = this.getMiddlePointsStyle()
@@ -133,20 +133,22 @@ export class EditBox extends Group implements IEditBox {
133
133
  // rect
134
134
  rect.set({ stroke, strokeWidth, editConfig, ...(mergeConfig.rect || {}) })
135
135
 
136
- const syncEventer = single && this.transformTool.editTool
137
-
138
136
  // 编辑框作为底部虚拟元素, 在 unload() 中重置
139
- rect.hittable = !syncEventer
140
- rect.syncEventer = syncEventer && this.editor // 单选下 rect 的事件不会冒泡,需要手动传递给editor
137
+ const rectThrough = isNull(mergeConfig.rectThrough) ? single : mergeConfig.rectThrough
138
+ rect.hittable = !rectThrough
141
139
 
142
- if (syncEventer) {
143
- target.syncEventer = rect // target 属性装饰中重置
140
+ if (rectThrough) {
141
+ target.syncEventer = rect // 同步给 rect 冒泡,在 target 属性装饰器中重置
144
142
  this.app.interaction.bottomList = [{ target: rect, proxy: target }]
145
143
  }
146
144
 
145
+ // 忽略元素像素对齐,在 target 属性装饰器中重置
146
+ if (single) DataHelper.stintSet(target.__world, 'ignorePixelSnap', ignorePixelSnap)
147
+
147
148
  updateMoveCursor(this)
148
149
  }
149
150
 
151
+ // 必须来自 editor.update(),需同步更新编辑工具
150
152
  public update(): void {
151
153
  const { editor } = this
152
154
  const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds('box', editor, true)
@@ -328,29 +330,25 @@ export class EditBox extends Group implements IEditBox {
328
330
  // 操作事件共用
329
331
 
330
332
  public onTransformStart(e: IUIEvent): void {
331
- if (this.canUse) {
332
- if (this.moving) this.editor.opacity = this.mergedConfig.hideOnMove ? 0 : 1 // move
333
- if (this.resizing) ResizeEvent.resizingKeys = this.editor.leafList.keys // 记录正在resize中的元素列表
334
-
335
- const { dragStartData, target } = this
336
- dragStartData.x = e.x
337
- dragStartData.y = e.y
338
- dragStartData.totalOffset = getPointData() // 缩放、旋转造成的总偏移量,一般用于手势操作的move纠正
339
- dragStartData.point = { x: target.x, y: target.y } // 用于移动
340
- dragStartData.bounds = { ...target.getLayoutBounds('box', 'local') } // 用于resize
341
- dragStartData.rotation = target.rotation // 用于旋转
342
- }
333
+ if (this.moving) this.editor.opacity = this.mergedConfig.hideOnMove ? 0 : 1 // move
334
+ if (this.resizing) ResizeEvent.resizingKeys = this.editor.leafList.keys // 记录正在resize中的元素列表
335
+
336
+ const { dragStartData, target } = this
337
+ dragStartData.x = e.x
338
+ dragStartData.y = e.y
339
+ dragStartData.totalOffset = getPointData() // 缩放、旋转造成的总偏移量,一般用于手势操作的move纠正
340
+ dragStartData.point = { x: target.x, y: target.y } // 用于移动
341
+ dragStartData.bounds = { ...target.getLayoutBounds('box', 'local') } // 用于resize
342
+ dragStartData.rotation = target.rotation // 用于旋转
343
343
  }
344
344
 
345
345
  public onTransformEnd(e: IUIEvent): void {
346
- if (this.canUse) {
347
- if (this.canDragLimitAnimate && (e instanceof DragEvent || e instanceof MoveEvent)) this.transformTool.onMove(e)
348
- if (this.resizing) ResizeEvent.resizingKeys = null
346
+ if (this.canDragLimitAnimate && (e instanceof DragEvent || e instanceof MoveEvent)) this.transformTool.onMove(e)
347
+ if (this.resizing) ResizeEvent.resizingKeys = null
349
348
 
350
- this.dragging = this.gesturing = this.moving = this.resizing = this.rotating = this.skewing = false
351
- this.editor.opacity = 1
352
- this.update() // 移动端手势操作hideOnMove移动需强制更新一次
353
- }
349
+ this.dragging = this.gesturing = this.moving = this.resizing = this.rotating = this.skewing = false
350
+ this.editor.opacity = 1
351
+ this.editor.update() // 移动端手势操作hideOnMove移动需强制更新一次
354
352
  }
355
353
 
356
354
  // 手势控制元素
@@ -385,6 +383,14 @@ export class EditBox extends Group implements IEditBox {
385
383
  }
386
384
  }
387
385
 
386
+ public onGestureStart(e: IUIEvent): void {
387
+ if (this.canGesture && (e as MoveEvent).moveType !== 'drag') this.onTransformStart(e)
388
+ }
389
+
390
+ public onGestureEnd(e: IUIEvent): void {
391
+ if (this.canGesture && (e as MoveEvent).moveType !== 'drag') this.onTransformEnd(e)
392
+ }
393
+
388
394
  // 键盘
389
395
 
390
396
  public isHoldRotateKey(e: IUIEvent): boolean { // 按住ctrl在控制点上变旋转功能
@@ -481,11 +487,12 @@ export class EditBox extends Group implements IEditBox {
481
487
  [[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
482
488
  [KeyEvent.DOWN, this.onArrow, this],
483
489
 
484
- [[MoveEvent.START, MoveEvent.BEFORE_MOVE], this.onMove, this, true],
485
- [[ZoomEvent.START, ZoomEvent.BEFORE_ZOOM], this.onScale, this, true],
486
- [[RotateEvent.START, RotateEvent.BEFORE_ROTATE], this.onRotate, this, true],
490
+ [MoveEvent.BEFORE_MOVE, this.onMove, this, true],
491
+ [ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
492
+ [RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
487
493
 
488
- [[MoveEvent.END, ZoomEvent.END, RotateEvent.END], this.onTransformEnd, this],
494
+ [[MoveEvent.START, ZoomEvent.START, RotateEvent.START], this.onGestureStart, this],
495
+ [[MoveEvent.END, ZoomEvent.END, RotateEvent.END], this.onGestureEnd, this],
489
496
  ])
490
497
  )
491
498
  })
@@ -45,8 +45,10 @@ export class EditSelect extends Group implements IEditSelect {
45
45
  protected onHover(): void {
46
46
  const { editor } = this
47
47
  if (this.running && !this.dragging && !editor.dragging) {
48
- const { stroke, strokeWidth, hover, hoverStyle } = editor.mergeConfig
49
- this.hoverStroker.setTarget(hover ? this.editor.hoverTarget : null, { stroke, strokeWidth, ...(hoverStyle || {}) })
48
+ const { hoverTarget, mergeConfig } = editor, config = { ...mergeConfig }
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
52
  } else {
51
53
  this.hoverStroker.target = null
52
54
  }
@@ -1,17 +1,17 @@
1
1
  import { IBoundsData, IPointData, IAround, IAlign, IUI, ILayoutBoundsData } from '@leafer-ui/interface'
2
- import { AroundHelper, MathHelper, PointHelper, Direction9, DragBoundsHelper, isNumber } from '@leafer-ui/draw'
2
+ import { AroundHelper, MathHelper, PointHelper, Direction9, isNumber } from '@leafer-ui/draw'
3
+ import { DragBoundsHelper } from '@leafer-ui/core'
3
4
 
4
5
  import { IEditorScaleEvent, IEditorSkewEvent, IEditorRotateEvent } from '@leafer-in/interface'
5
6
 
6
7
 
7
8
  const { topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left } = Direction9
8
- const { toPoint } = AroundHelper
9
- const { within, sign } = MathHelper
9
+ const { toPoint } = AroundHelper, { within, sign } = MathHelper, { abs } = Math
10
10
 
11
11
  export const EditDataHelper = {
12
12
 
13
13
  getScaleData(target: IUI, startBounds: ILayoutBoundsData, direction: Direction9, totalMoveOrScale: IPointData | number, lockRatio: boolean | 'corner', around: IAround, flipable: boolean, scaleMode: boolean): IEditorScaleEvent {
14
- let align: IAlign, origin = {} as IPointData, scaleX: number = 1, scaleY: number = 1
14
+ let align: IAlign, origin = {} as IPointData, scaleX: number = 1, scaleY: number = 1, lockScale: number
15
15
 
16
16
  const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = target
17
17
  const { width, height } = startBounds
@@ -86,21 +86,20 @@ export const EditDataHelper = {
86
86
  if (lockRatio === 'corner' && direction % 2) {
87
87
  lockRatio = false
88
88
  } else {
89
- let scale: number
90
89
  switch (direction) {
91
90
  case top:
92
91
  case bottom:
93
- scale = scaleY
92
+ scaleX = scaleY
94
93
  break
95
94
  case left:
96
95
  case right:
97
- scale = scaleX
96
+ scaleY = scaleX
98
97
  break
99
98
  default:
100
- scale = Math.sqrt(Math.abs(scaleX * scaleY))
99
+ lockScale = Math.sqrt(abs(scaleX * scaleY))
100
+ scaleX = sign(scaleX) * lockScale
101
+ scaleY = sign(scaleY) * lockScale
101
102
  }
102
- scaleX = scaleX < 0 ? -scale : scale
103
- scaleY = scaleY < 0 ? -scale : scale
104
103
  }
105
104
  }
106
105
 
@@ -123,7 +122,7 @@ export const EditDataHelper = {
123
122
 
124
123
  if (dragBounds) {
125
124
  const scaleData = { x: scaleX, y: scaleY }
126
- DragBoundsHelper.limitScaleOf(target, origin, scaleData)
125
+ DragBoundsHelper.limitScaleOf(target, origin, scaleData, lockRatio as boolean)
127
126
  scaleX = scaleData.x
128
127
  scaleY = scaleData.y
129
128
  }
@@ -139,10 +138,14 @@ export const EditDataHelper = {
139
138
  }
140
139
 
141
140
  // 防止小于1px
142
- if (useScaleX && Math.abs(scaleX * worldBoxBounds.width) < 1) scaleX = sign(scaleX) / worldBoxBounds.width
143
- if (useScaleY && Math.abs(scaleY * worldBoxBounds.height) < 1) scaleY = sign(scaleY) / worldBoxBounds.height
141
+ if (useScaleX && abs(scaleX * worldBoxBounds.width) < 1) scaleX = sign(scaleX) / worldBoxBounds.width
142
+ if (useScaleY && abs(scaleY * worldBoxBounds.height) < 1) scaleY = sign(scaleY) / worldBoxBounds.height
144
143
 
145
- if (lockRatio && scaleX !== scaleY) scaleY = scaleX = Math.min(scaleX, scaleY)
144
+ if (lockRatio && scaleX !== scaleY) {
145
+ lockScale = Math.min(abs(scaleX), abs(scaleY))
146
+ scaleX = sign(scaleX) * lockScale
147
+ scaleY = sign(scaleY) * lockScale
148
+ }
146
149
 
147
150
  return { origin, scaleX, scaleY, direction, lockRatio, around }
148
151
  },
package/types/index.d.ts CHANGED
@@ -190,6 +190,8 @@ declare class EditBox extends Group implements IEditBox {
190
190
  onMove(e: MoveEvent): void;
191
191
  onScale(e: ZoomEvent): void;
192
192
  onRotate(e: RotateEvent): void;
193
+ onGestureStart(e: IUIEvent): void;
194
+ onGestureEnd(e: IUIEvent): void;
193
195
  isHoldRotateKey(e: IUIEvent): boolean;
194
196
  protected onKey(e: KeyEvent): void;
195
197
  onArrow(e: IKeyEvent): void;