@leafer/helper 1.0.0-beta → 1.0.0-beta.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/helper",
3
- "version": "1.0.0-beta",
3
+ "version": "1.0.0-beta.10",
4
4
  "description": "@leafer/helper",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -19,9 +19,9 @@
19
19
  "leaferjs"
20
20
  ],
21
21
  "dependencies": {
22
- "@leafer/math": "1.0.0-beta"
22
+ "@leafer/math": "1.0.0-beta.10"
23
23
  },
24
24
  "devDependencies": {
25
- "@leafer/interface": "1.0.0-beta"
25
+ "@leafer/interface": "1.0.0-beta.10"
26
26
  }
27
27
  }
@@ -8,27 +8,27 @@ export const LeafBoundsHelper = {
8
8
  },
9
9
 
10
10
  localBoxBounds(target: ILeaf): IBoundsData {
11
- return target.__local
11
+ return target.__.isEraser ? null : target.__local
12
12
  },
13
13
 
14
14
  localEventBounds(target: ILeaf): IBoundsData {
15
- return target.__layout.localStrokeBounds
15
+ return target.__.isEraser ? null : target.__layout.localStrokeBounds
16
16
  },
17
17
 
18
18
  localRenderBounds(target: ILeaf): IBoundsData {
19
- return target.__layout.localRenderBounds
19
+ return target.__.isEraser ? null : target.__layout.localRenderBounds
20
20
  },
21
21
 
22
22
  maskLocalBoxBounds(target: ILeaf): IBoundsData {
23
- return target.isMask ? target.__local : null
23
+ return target.__.isMask ? target.__local : null
24
24
  },
25
25
 
26
26
  maskLocalEventBounds(target: ILeaf): IBoundsData {
27
- return target.isMask ? target.__layout.localStrokeBounds : null
27
+ return target.__.isMask ? target.__layout.localStrokeBounds : null
28
28
  },
29
29
 
30
30
  maskLocalRenderBounds(target: ILeaf): IBoundsData {
31
- return target.isMask ? target.__layout.localRenderBounds : null
31
+ return target.__.isMask ? target.__layout.localRenderBounds : null
32
32
  }
33
33
 
34
34
  }
package/src/LeafHelper.ts CHANGED
@@ -1,7 +1,10 @@
1
- import { IBranch, ILeaf, IPointData } from '@leafer/interface'
2
- import { Matrix, MatrixHelper, PointHelper } from '@leafer/math'
1
+ import { IBranch, ILeaf, IMatrixData, IPointData } from '@leafer/interface'
2
+ import { MatrixHelper, PointHelper } from '@leafer/math'
3
3
 
4
4
 
5
+ const { copy, translate, toInnerPoint, scaleOfOuter, rotateOfOuter } = MatrixHelper
6
+ const matrix = {} as IMatrixData
7
+
5
8
  export const LeafHelper = {
6
9
 
7
10
  updateAllWorldMatrix(leaf: ILeaf): void {
@@ -40,48 +43,61 @@ export const LeafHelper = {
40
43
  }
41
44
  },
42
45
 
46
+ worldHittable(t: ILeaf): boolean {
47
+ if (!t.__.hittable) return false
48
+ let { parent } = t
49
+ while (parent) {
50
+ if (!parent.__.hittable || !parent.__.hitChildren) return false
51
+ parent = parent.parent
52
+ }
53
+ return true
54
+ },
43
55
 
44
56
  // transform
45
57
 
46
- move(t: ILeaf, x: number, y: number): void {
58
+ moveWorld(t: ILeaf, x: number, y: number): void {
59
+ t.__layout.checkUpdate()
47
60
  const local = { x, y }
48
- if (t.parent) MatrixHelper.toInnerPoint(t.parent.__world, local, local, true)
61
+ if (t.parent) toInnerPoint(t.parent.__world, local, local, true)
49
62
  L.moveLocal(t, local.x, local.y)
50
63
  },
51
64
 
52
- moveLocal(t: ILeaf, x: number, y: number): void {
53
- t.x = t.__.x + x
54
- t.y = t.__.y + y
65
+ moveLocal(t: ILeaf, x: number, y: number = 0): void {
66
+ t.x += x
67
+ t.y += y
55
68
  },
56
69
 
57
- zoomOf(t: ILeaf, center: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void {
58
- const local = t.parent ? PointHelper.tempToInnerOf(center, t.parent.__world) : center
70
+ zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void {
71
+ t.__layout.checkUpdate()
72
+ const local = t.parent ? PointHelper.tempToInnerOf(origin, t.parent.__world) : origin
59
73
  this.zoomOfLocal(t, local, scaleX, scaleY, moveLayer)
60
74
  },
61
75
 
62
- zoomOfLocal(t: ILeaf, center: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void {
63
- if (!scaleY) scaleY = scaleX
76
+ zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number = scaleX, moveLayer?: ILeaf): void {
77
+ copy(matrix, t.__local)
78
+ if (moveLayer) translate(matrix, moveLayer.x, moveLayer.y)
79
+ scaleOfOuter(matrix, origin, scaleX, scaleY)
64
80
  if (!moveLayer) moveLayer = t
65
- const { x, y } = moveLayer.__
66
- const matrix = new Matrix().translate(x, y).scaleOf(center, scaleX, scaleY)
67
- moveLayer.x = matrix.e
68
- moveLayer.y = matrix.f
69
- t.scaleX = t.__.scaleX * scaleX
70
- t.scaleY = t.__.scaleY * scaleY
81
+ moveLayer.x += matrix.e - t.__local.e
82
+ moveLayer.y += matrix.f - t.__local.f
83
+ t.scaleX *= scaleX
84
+ t.scaleY *= scaleY
71
85
  },
72
86
 
73
- rotateOf(t: ILeaf, center: IPointData, angle: number, moveLayer?: ILeaf): void {
74
- const local = t.parent ? PointHelper.tempToInnerOf(center, t.parent.__world) : center
87
+ rotateOfWorld(t: ILeaf, origin: IPointData, angle: number, moveLayer?: ILeaf): void {
88
+ t.__layout.checkUpdate()
89
+ const local = t.parent ? PointHelper.tempToInnerOf(origin, t.parent.__world) : origin
75
90
  this.rotateOfLocal(t, local, angle, moveLayer)
76
91
  },
77
92
 
78
- rotateOfLocal(t: ILeaf, center: IPointData, angle: number, moveLayer?: ILeaf): void {
93
+ rotateOfLocal(t: ILeaf, origin: IPointData, angle: number, moveLayer?: ILeaf): void {
94
+ copy(matrix, t.__local)
95
+ if (moveLayer) translate(matrix, moveLayer.x, moveLayer.y)
96
+ rotateOfOuter(matrix, origin, angle)
79
97
  if (!moveLayer) moveLayer = t
80
- const { x, y } = moveLayer.__
81
- const matrix = new Matrix().translate(x, y).rotateOf(center, angle)
82
- moveLayer.x = matrix.e
83
- moveLayer.y = matrix.f
84
- t.rotation = t.__.rotation + angle
98
+ moveLayer.x += matrix.e - t.__local.e
99
+ moveLayer.y += matrix.f - t.__local.f
100
+ t.rotation += angle
85
101
  },
86
102
 
87
103
  drop(t: ILeaf, parent: IBranch): void {