@leafer/helper 1.0.0-alpha.21 → 1.0.0-alpha.30

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-alpha.21",
3
+ "version": "1.0.0-alpha.30",
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-alpha.21"
22
+ "@leafer/math": "1.0.0-alpha.30"
23
23
  },
24
24
  "devDependencies": {
25
- "@leafer/interface": "1.0.0-alpha.21"
25
+ "@leafer/interface": "1.0.0-alpha.30"
26
26
  }
27
27
  }
@@ -17,11 +17,11 @@ export const BranchHelper = {
17
17
  pushAllChildBranch(branch: ILeaf, pushList: ILeafPushList): void {
18
18
  branch.__tempNumber = 1 // 标识需要更新子Leaf元素的WorldBounds分支 Layouter需使用
19
19
 
20
- if (branch.__childBranchNumber) {
20
+ if (branch.__.__childBranchNumber) {
21
21
  const { children } = branch
22
22
  for (let i = 0, len = children.length; i < len; i++) {
23
23
  branch = children[i]
24
- if (branch.__isBranch) {
24
+ if (branch.isBranch) {
25
25
  branch.__tempNumber = 1
26
26
  pushList.push(branch)
27
27
  pushAllChildBranch(branch, pushList)
@@ -53,7 +53,7 @@ export const BranchHelper = {
53
53
  let start = pushList.length
54
54
  const { children } = branch
55
55
  for (let i = 0, len = children.length; i < len; i++) {
56
- if (children[i].__isBranch) {
56
+ if (children[i].isBranch) {
57
57
  pushList.push(children[i])
58
58
  }
59
59
  }
@@ -7,16 +7,28 @@ export const LeafBoundsHelper = {
7
7
  return target.__world
8
8
  },
9
9
 
10
- relativeBoxBounds(target: ILeaf): IBoundsData {
11
- return target.__relative
10
+ localBoxBounds(target: ILeaf): IBoundsData {
11
+ return target.__local
12
12
  },
13
13
 
14
- relativeEventBounds(target: ILeaf): IBoundsData {
15
- return target.__layout.relativeEventBounds
14
+ localEventBounds(target: ILeaf): IBoundsData {
15
+ return target.__layout.localStrokeBounds
16
16
  },
17
17
 
18
- relativeRenderBounds(target: ILeaf): IBoundsData {
19
- return target.__layout.relativeRenderBounds
18
+ localRenderBounds(target: ILeaf): IBoundsData {
19
+ return target.__layout.localRenderBounds
20
+ },
21
+
22
+ maskLocalBoxBounds(target: ILeaf): IBoundsData {
23
+ return target.isMask ? target.__local : null
24
+ },
25
+
26
+ maskLocalEventBounds(target: ILeaf): IBoundsData {
27
+ return target.isMask ? target.__layout.localStrokeBounds : null
28
+ },
29
+
30
+ maskLocalRenderBounds(target: ILeaf): IBoundsData {
31
+ return target.isMask ? target.__layout.localRenderBounds : null
20
32
  }
21
33
 
22
34
  }
package/src/LeafHelper.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaf, IPointData } from '@leafer/interface'
1
+ import { IBranch, ILeaf, IPointData } from '@leafer/interface'
2
2
  import { Matrix, MatrixHelper, PointHelper } from '@leafer/math'
3
3
 
4
4
 
@@ -7,7 +7,7 @@ export const LeafHelper = {
7
7
  updateAllWorldMatrix(leaf: ILeaf): void {
8
8
  leaf.__updateWorldMatrix()
9
9
 
10
- if (leaf.__isBranch) {
10
+ if (leaf.isBranch) {
11
11
  const { children } = leaf
12
12
  for (let i = 0, len = children.length; i < len; i++) {
13
13
  updateAllWorldMatrix(children[i])
@@ -18,7 +18,7 @@ export const LeafHelper = {
18
18
  updateAllWorldOpacity(leaf: ILeaf): void {
19
19
  leaf.__updateWorldOpacity()
20
20
 
21
- if (leaf.__isBranch) {
21
+ if (leaf.isBranch) {
22
22
  const { children } = leaf
23
23
  for (let i = 0, len = children.length; i < len; i++) {
24
24
  updateAllWorldOpacity(children[i])
@@ -32,7 +32,7 @@ export const LeafHelper = {
32
32
 
33
33
  leaf.__updateChange()
34
34
 
35
- if (leaf.__isBranch) {
35
+ if (leaf.isBranch) {
36
36
  const { children } = leaf
37
37
  for (let i = 0, len = children.length; i < len; i++) {
38
38
  updateAllChange(children[i])
@@ -43,50 +43,53 @@ export const LeafHelper = {
43
43
 
44
44
  // transform
45
45
 
46
- moveOfWorld(t: ILeaf, worldX: number, worldY: number): void {
47
- const local = { x: worldX, y: worldY }
48
- if (t.parent) MatrixHelper.toLocalPoint(t.parent.__world, local, local, true)
49
- L.move(t, local.x, local.y)
46
+ move(t: ILeaf, x: number, y: number): void {
47
+ const local = { x, y }
48
+ if (t.parent) MatrixHelper.toInnerPoint(t.parent.__world, local, local, true)
49
+ L.moveLocal(t, local.x, local.y)
50
50
  },
51
51
 
52
- move(t: ILeaf, x: number, y: number): void {
52
+ moveLocal(t: ILeaf, x: number, y: number): void {
53
53
  t.x = t.__.x + x
54
54
  t.y = t.__.y + y
55
55
  },
56
56
 
57
- zoomOfWorld(t: ILeaf, scale: number, worldCenter: IPointData, moveLayer?: ILeaf): void {
58
- const local = t.parent ? PointHelper.tempToLocal(worldCenter, t.parent.__world) : worldCenter
59
- this.zoom(t, scale, local, moveLayer)
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
59
+ this.zoomOfLocal(t, local, scaleX, scaleY, moveLayer)
60
60
  },
61
61
 
62
- zoom(t: ILeaf, scale: number, localCenter: IPointData, moveLayer?: ILeaf): void {
62
+ zoomOfLocal(t: ILeaf, center: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void {
63
+ if (!scaleY) scaleY = scaleX
63
64
  if (!moveLayer) moveLayer = t
64
65
  const { x, y } = moveLayer.__
65
- const { scaleX, scaleY } = t.__
66
- const centerX = localCenter.x - x
67
- const centerY = localCenter.y - y
68
- const matrix = new Matrix().translate(centerX, centerY).scale(scale).translate(-centerX, -centerY)
69
- moveLayer.x = x - matrix.e
70
- moveLayer.y = y - matrix.f
71
- t.scaleX = scaleX * scale
72
- t.scaleY = scaleY * scale
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
73
71
  },
74
72
 
75
- rotateOfWorld(t: ILeaf, angle: number, worldCenter: IPointData, moveLayer?: ILeaf): void {
76
- const local = t.parent ? PointHelper.tempToLocal(worldCenter, t.parent.__world) : worldCenter
77
- this.rotate(t, angle, local, moveLayer)
73
+ rotateOf(t: ILeaf, center: IPointData, angle: number, moveLayer?: ILeaf): void {
74
+ const local = t.parent ? PointHelper.tempToInnerOf(center, t.parent.__world) : center
75
+ this.rotateOfLocal(t, local, angle, moveLayer)
78
76
  },
79
77
 
80
- rotate(t: ILeaf, angle: number, localCenter: IPointData, moveLayer?: ILeaf): void {
78
+ rotateOfLocal(t: ILeaf, center: IPointData, angle: number, moveLayer?: ILeaf): void {
81
79
  if (!moveLayer) moveLayer = t
82
80
  const { x, y } = moveLayer.__
83
- const { rotation } = t.__
84
- const centerX = localCenter.x - x
85
- const centerY = localCenter.y - y
86
- const matrix = new Matrix().translate(centerX, centerY).rotate(angle).translate(-centerX, -centerY)
87
- moveLayer.x = x - matrix.e
88
- moveLayer.y = y - matrix.f
89
- t.rotation = rotation + angle
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
85
+ },
86
+
87
+ drop(t: ILeaf, parent: IBranch): void {
88
+ const position = { x: t.x, y: t.y }
89
+ t.localToWorld(position)
90
+ parent.worldToInner(position)
91
+ t.set(position)
92
+ parent.add(t)
90
93
  }
91
94
 
92
95
  }
@@ -0,0 +1,8 @@
1
+ import { IFunction } from '@leafer/interface'
2
+
3
+ export const WaitHelper = {
4
+ run(wait: IFunction[]): void {
5
+ for (let i = 0, len = wait.length; i < len; i++) { wait[i]() }
6
+ wait.length = 0
7
+ }
8
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { LeafHelper } from './LeafHelper'
2
2
  export { LeafBoundsHelper } from './LeafBoundsHelper'
3
3
  export { BranchHelper } from './BranchHelper'
4
+ export { WaitHelper } from './WaitHelper'