@leafer/helper 1.0.0 → 1.0.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.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "@leafer/helper",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,9 +22,9 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/math": "1.0.0"
25
+ "@leafer/math": "1.0.2"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0"
28
+ "@leafer/interface": "1.0.2"
29
29
  }
30
30
  }
package/src/LeafHelper.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { IAlign, ILeaf, IMatrixData, IPointData } from '@leafer/interface'
2
- import { MathHelper, MatrixHelper, PointHelper, AroundHelper } from '@leafer/math'
1
+ import { IAlign, ILeaf, IMatrixData, IPointData, IAxis } from '@leafer/interface'
2
+ import { MathHelper, MatrixHelper, PointHelper, AroundHelper, getMatrixData } from '@leafer/math'
3
3
 
4
4
 
5
- const { copy, toInnerPoint, scaleOfOuter, rotateOfOuter, skewOfOuter, multiplyParent, divideParent, getLayout } = MatrixHelper
5
+ const { copy, toInnerPoint, toOuterPoint, scaleOfOuter, rotateOfOuter, skewOfOuter, multiplyParent, divideParent, getLayout } = MatrixHelper
6
6
  const matrix = {} as IMatrixData
7
7
 
8
8
  export const LeafHelper = {
@@ -76,9 +76,9 @@ export const LeafHelper = {
76
76
 
77
77
  // transform
78
78
 
79
- moveWorld(t: ILeaf, x: number | IPointData, y = 0): void {
79
+ moveWorld(t: ILeaf, x: number | IPointData, y = 0, isInnerPoint?: boolean): void {
80
80
  const local = typeof x === 'object' ? { ...x } : { x, y }
81
- if (t.parent) toInnerPoint(t.parent.worldTransform, local, local, true)
81
+ isInnerPoint ? toOuterPoint(t.localTransform, local, local, true) : (t.parent && toInnerPoint(t.parent.worldTransform, local, local, true))
82
82
  L.moveLocal(t, local.x, local.y)
83
83
  },
84
84
 
@@ -99,8 +99,12 @@ export const LeafHelper = {
99
99
  zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number = scaleX, resize?: boolean): void {
100
100
  copy(matrix, t.__localMatrix)
101
101
  scaleOfOuter(matrix, origin, scaleX, scaleY)
102
- moveByMatrix(t, matrix)
103
- t.scaleResize(scaleX, scaleY, resize !== true)
102
+ if (t.origin || t.around) {
103
+ L.setTransform(t, matrix, resize)
104
+ } else {
105
+ moveByMatrix(t, matrix)
106
+ t.scaleResize(scaleX, scaleY, resize !== true)
107
+ }
104
108
  },
105
109
 
106
110
  rotateOfWorld(t: ILeaf, origin: IPointData, angle: number): void {
@@ -110,8 +114,12 @@ export const LeafHelper = {
110
114
  rotateOfLocal(t: ILeaf, origin: IPointData, angle: number): void {
111
115
  copy(matrix, t.__localMatrix)
112
116
  rotateOfOuter(matrix, origin, angle)
113
- moveByMatrix(t, matrix)
114
- t.rotation = MathHelper.formatRotation(t.rotation + angle)
117
+ if (t.origin || t.around) {
118
+ L.setTransform(t, matrix)
119
+ } else {
120
+ moveByMatrix(t, matrix)
121
+ t.rotation = MathHelper.formatRotation(t.rotation + angle)
122
+ }
115
123
  },
116
124
 
117
125
  skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
@@ -138,7 +146,7 @@ export const LeafHelper = {
138
146
  },
139
147
 
140
148
  setTransform(t: ILeaf, transform: IMatrixData, resize?: boolean): void {
141
- const layout = getLayout(transform)
149
+ const layout = getLayout(transform, t.origin && L.getInnerOrigin(t, t.origin), t.around && L.getInnerOrigin(t, t.around))
142
150
  if (resize) {
143
151
  const scaleX = layout.scaleX / t.scaleX
144
152
  const scaleY = layout.scaleY / t.scaleY
@@ -151,13 +159,21 @@ export const LeafHelper = {
151
159
  }
152
160
  },
153
161
 
162
+ getFlipTransform(t: ILeaf, axis: IAxis): IMatrixData {
163
+ const m = getMatrixData()
164
+ const sign = axis === 'x' ? 1 : -1
165
+ scaleOfOuter(m, L.getLocalOrigin(t, 'center'), -1 * sign, 1 * sign)
166
+ return m
167
+ },
168
+
154
169
  getLocalOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData {
155
170
  return PointHelper.tempToOuterOf(L.getInnerOrigin(t, origin), t.localTransform)
156
171
  },
157
172
 
158
173
  getInnerOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData {
159
- if (typeof origin === 'string') AroundHelper.toPoint(origin, t.boxBounds, origin = {} as IPointData)
160
- return origin
174
+ const innerOrigin = {} as IPointData
175
+ AroundHelper.toPoint(origin, t.boxBounds, innerOrigin)
176
+ return innerOrigin
161
177
  },
162
178
 
163
179
  getRelativeWorld(t: ILeaf, relative: ILeaf, temp?: boolean): IMatrixData {
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaf, IPointData, IMatrixData, IAlign, IBoundsData, IRenderOptions, ILeafList, ILeafLevelList, IFunction } from '@leafer/interface';
1
+ import { ILeaf, IPointData, IMatrixData, IAxis, IAlign, IBoundsData, IRenderOptions, ILeafList, ILeafLevelList, IFunction } from '@leafer/interface';
2
2
 
3
3
  declare const LeafHelper: {
4
4
  updateAllMatrix(leaf: ILeaf, checkAutoLayout?: boolean, waitAutoLayout?: boolean): void;
@@ -7,7 +7,7 @@ declare const LeafHelper: {
7
7
  updateAllWorldOpacity(leaf: ILeaf): void;
8
8
  updateAllChange(leaf: ILeaf): void;
9
9
  worldHittable(t: ILeaf): boolean;
10
- moveWorld(t: ILeaf, x: number | IPointData, y?: number): void;
10
+ moveWorld(t: ILeaf, x: number | IPointData, y?: number, isInnerPoint?: boolean): void;
11
11
  moveLocal(t: ILeaf, x: number | IPointData, y?: number): void;
12
12
  zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
13
13
  zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
@@ -18,6 +18,7 @@ declare const LeafHelper: {
18
18
  transformWorld(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
19
19
  transform(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
20
20
  setTransform(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
21
+ getFlipTransform(t: ILeaf, axis: IAxis): IMatrixData;
21
22
  getLocalOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData;
22
23
  getInnerOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData;
23
24
  getRelativeWorld(t: ILeaf, relative: ILeaf, temp?: boolean): IMatrixData;