@leafer/helper 1.0.0-beta.2 → 1.0.0-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/helper",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.5",
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.2"
22
+ "@leafer/math": "1.0.0-beta.5"
23
23
  },
24
24
  "devDependencies": {
25
- "@leafer/interface": "1.0.0-beta.2"
25
+ "@leafer/interface": "1.0.0-beta.5"
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
@@ -40,45 +40,54 @@ export const LeafHelper = {
40
40
  }
41
41
  },
42
42
 
43
+ worldHittable(t: ILeaf): boolean {
44
+ if (!t.__.hittable) return false
45
+ let { parent } = t
46
+ while (parent) {
47
+ if (!parent.__.hittable || !parent.__.hitChildren) return false
48
+ parent = parent.parent
49
+ }
50
+ return true
51
+ },
43
52
 
44
53
  // transform
45
54
 
46
- move(t: ILeaf, x: number, y: number): void {
55
+ moveWorld(t: ILeaf, x: number, y: number): void {
47
56
  const local = { x, y }
48
57
  if (t.parent) MatrixHelper.toInnerPoint(t.parent.__world, local, local, true)
49
58
  L.moveLocal(t, local.x, local.y)
50
59
  },
51
60
 
52
- moveLocal(t: ILeaf, x: number, y: number): void {
61
+ moveLocal(t: ILeaf, x: number, y: number = 0): void {
53
62
  t.x = t.__.x + x
54
63
  t.y = t.__.y + y
55
64
  },
56
65
 
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
66
+ zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void {
67
+ const local = t.parent ? PointHelper.tempToInnerOf(origin, t.parent.__world) : origin
59
68
  this.zoomOfLocal(t, local, scaleX, scaleY, moveLayer)
60
69
  },
61
70
 
62
- zoomOfLocal(t: ILeaf, center: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void {
71
+ zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void {
63
72
  if (!scaleY) scaleY = scaleX
64
73
  if (!moveLayer) moveLayer = t
65
74
  const { x, y } = moveLayer.__
66
- const matrix = new Matrix().translate(x, y).scaleOf(center, scaleX, scaleY)
75
+ const matrix = new Matrix().translate(x, y).scaleOfOuter(origin, scaleX, scaleY)
67
76
  moveLayer.x = matrix.e
68
77
  moveLayer.y = matrix.f
69
78
  t.scaleX = t.__.scaleX * scaleX
70
79
  t.scaleY = t.__.scaleY * scaleY
71
80
  },
72
81
 
73
- rotateOf(t: ILeaf, center: IPointData, angle: number, moveLayer?: ILeaf): void {
74
- const local = t.parent ? PointHelper.tempToInnerOf(center, t.parent.__world) : center
82
+ rotateOfWorld(t: ILeaf, origin: IPointData, angle: number, moveLayer?: ILeaf): void {
83
+ const local = t.parent ? PointHelper.tempToInnerOf(origin, t.parent.__world) : origin
75
84
  this.rotateOfLocal(t, local, angle, moveLayer)
76
85
  },
77
86
 
78
- rotateOfLocal(t: ILeaf, center: IPointData, angle: number, moveLayer?: ILeaf): void {
87
+ rotateOfLocal(t: ILeaf, origin: IPointData, angle: number, moveLayer?: ILeaf): void {
79
88
  if (!moveLayer) moveLayer = t
80
89
  const { x, y } = moveLayer.__
81
- const matrix = new Matrix().translate(x, y).rotateOf(center, angle)
90
+ const matrix = new Matrix().translate(x, y).rotateOfOuter(origin, angle)
82
91
  moveLayer.x = matrix.e
83
92
  moveLayer.y = matrix.f
84
93
  t.rotation = t.__.rotation + angle