@leafer/helper 1.12.0 → 1.12.2

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.12.0",
3
+ "version": "1.12.2",
4
4
  "description": "@leafer/helper",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/data": "1.12.0",
26
- "@leafer/math": "1.12.0",
27
- "@leafer/platform": "1.12.0"
25
+ "@leafer/data": "1.12.2",
26
+ "@leafer/math": "1.12.2",
27
+ "@leafer/platform": "1.12.2"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "1.12.0"
30
+ "@leafer/interface": "1.12.2"
31
31
  }
32
32
  }
@@ -1,4 +1,4 @@
1
- import { ILeaf, ILeafLevelList, ILeafList } from '@leafer/interface'
1
+ import { ILeaf, ILeafLevelList, ILeafList, IMatrixWithBoundsData, IMatrixWithBoundsScaleData } from '@leafer/interface'
2
2
  import { isUndefined } from '@leafer/data'
3
3
  import { LeafHelper } from './LeafHelper'
4
4
 
@@ -79,7 +79,62 @@ export const BranchHelper = {
79
79
  if (exclude && exclude === branch) continue
80
80
  updateBounds(branch)
81
81
  }
82
+ },
83
+
84
+ move(branch: ILeaf, x: number, y: number): void {
85
+ let w: IMatrixWithBoundsData
86
+ const { children } = branch
87
+ for (let i = 0, len = children.length; i < len; i++) {
88
+ branch = children[i]
89
+ w = branch.__world
90
+
91
+ w.e += x
92
+ w.f += y
93
+ w.x += x
94
+ w.y += y
95
+
96
+ if (branch.isBranch) move(branch, x, y)
97
+ }
98
+ },
99
+
100
+ scale(branch: ILeaf, x: number, y: number, scaleX: number, scaleY: number, a: number, b: number): void {
101
+ let w: IMatrixWithBoundsScaleData
102
+ const { children } = branch
103
+ const changeScaleX = scaleX - 1
104
+ const changeScaleY = scaleY - 1
105
+
106
+ for (let i = 0, len = children.length; i < len; i++) {
107
+ branch = children[i]
108
+ w = branch.__world
109
+
110
+ w.a *= scaleX
111
+ w.d *= scaleY
112
+
113
+ if (w.b || w.c) {
114
+ w.b *= scaleX
115
+ w.c *= scaleY
116
+ }
117
+
118
+ if (w.e === w.x && w.f === w.y) {
119
+ w.x = w.e += (w.e - a) * changeScaleX + x
120
+ w.y = w.f += (w.f - b) * changeScaleY + y
121
+ } else {
122
+ w.e += (w.e - a) * changeScaleX + x
123
+ w.f += (w.f - b) * changeScaleY + y
124
+
125
+ w.x += (w.x - a) * changeScaleX + x
126
+ w.y += (w.y - b) * changeScaleY + y
127
+ }
128
+
129
+ w.width *= scaleX
130
+ w.height *= scaleY
131
+
132
+ w.scaleX *= scaleX
133
+ w.scaleY *= scaleY
134
+
135
+ if (branch.isBranch) scale(branch, x, y, scaleX, scaleY, a, b)
136
+ }
82
137
  }
83
138
  }
84
139
 
85
- const { pushAllChildBranch, pushAllBranchStack, updateBoundsByBranchStack } = BranchHelper
140
+ const { pushAllChildBranch, pushAllBranchStack, updateBoundsByBranchStack, move, scale } = BranchHelper
package/types/index.d.ts CHANGED
@@ -50,6 +50,8 @@ declare const BranchHelper: {
50
50
  pushAllBranchStack(branch: ILeaf, pushList: ILeaf[]): void;
51
51
  updateBounds(branch: ILeaf, exclude?: ILeaf): void;
52
52
  updateBoundsByBranchStack(branchStack: ILeaf[], exclude?: ILeaf): void;
53
+ move(branch: ILeaf, x: number, y: number): void;
54
+ scale(branch: ILeaf, x: number, y: number, scaleX: number, scaleY: number, a: number, b: number): void;
53
55
  };
54
56
 
55
57
  declare const WaitHelper: {