@leafer/helper 1.0.0-rc.8 → 1.0.0

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-rc.8",
3
+ "version": "1.0.0",
4
4
  "description": "@leafer/helper",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -15,16 +15,16 @@
15
15
  "type": "git",
16
16
  "url": "https://github.com/leaferjs/leafer.git"
17
17
  },
18
- "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/helper",
18
+ "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/display-module/helper",
19
19
  "bugs": "https://github.com/leaferjs/leafer/issues",
20
20
  "keywords": [
21
21
  "leafer",
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/math": "1.0.0-rc.8"
25
+ "@leafer/math": "1.0.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.8"
28
+ "@leafer/interface": "1.0.0"
29
29
  }
30
30
  }
@@ -1,4 +1,4 @@
1
- import { ILeaf, IBoundsData } from '@leafer/interface'
1
+ import { ILeaf, IBoundsData, IRenderOptions } from '@leafer/interface'
2
2
 
3
3
 
4
4
  export const LeafBoundsHelper = {
@@ -8,27 +8,33 @@ export const LeafBoundsHelper = {
8
8
  },
9
9
 
10
10
  localBoxBounds(target: ILeaf): IBoundsData {
11
- return target.__.isEraser ? null : (target.__local || target.__ as IBoundsData)
11
+ return target.__.eraser || target.__.visible === 0 ? null : (target.__local || target.__layout)
12
12
  },
13
13
 
14
14
  localStrokeBounds(target: ILeaf): IBoundsData {
15
- return target.__.isEraser ? null : target.__layout.localStrokeBounds
15
+ return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localStrokeBounds
16
16
  },
17
17
 
18
18
  localRenderBounds(target: ILeaf): IBoundsData {
19
- return target.__.isEraser ? null : target.__layout.localRenderBounds
19
+ return target.__.eraser || target.__.visible === 0 ? null : target.__layout.localRenderBounds
20
20
  },
21
21
 
22
22
  maskLocalBoxBounds(target: ILeaf): IBoundsData {
23
- return target.__.isMask ? target.__localBounds : null
23
+ return target.__.mask ? target.__localBoxBounds : null
24
24
  },
25
25
 
26
26
  maskLocalStrokeBounds(target: ILeaf): IBoundsData {
27
- return target.__.isMask ? target.__layout.localStrokeBounds : null
27
+ return target.__.mask ? 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.__.mask ? target.__layout.localRenderBounds : null
32
+ },
33
+
34
+ excludeRenderBounds(child: ILeaf, options: IRenderOptions): boolean {
35
+ if (options.bounds && !options.bounds.hit(child.__world, options.matrix)) return true
36
+ if (options.hideBounds && options.hideBounds.includes(child.__world, options.matrix)) return true
37
+ return false
32
38
  }
33
39
 
34
40
  }
package/src/LeafHelper.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ILeaf, IMatrixData, IPointData } from '@leafer/interface'
2
- import { MathHelper, MatrixHelper, PointHelper } from '@leafer/math'
1
+ import { IAlign, ILeaf, IMatrixData, IPointData } from '@leafer/interface'
2
+ import { MathHelper, MatrixHelper, PointHelper, AroundHelper } from '@leafer/math'
3
3
 
4
4
 
5
5
  const { copy, toInnerPoint, scaleOfOuter, rotateOfOuter, skewOfOuter, multiplyParent, divideParent, getLayout } = MatrixHelper
@@ -76,19 +76,24 @@ export const LeafHelper = {
76
76
 
77
77
  // transform
78
78
 
79
- moveWorld(t: ILeaf, x: number, y: number): void {
80
- const local = { x, y }
79
+ moveWorld(t: ILeaf, x: number | IPointData, y = 0): void {
80
+ const local = typeof x === 'object' ? { ...x } : { x, y }
81
81
  if (t.parent) toInnerPoint(t.parent.worldTransform, local, local, true)
82
82
  L.moveLocal(t, local.x, local.y)
83
83
  },
84
84
 
85
- moveLocal(t: ILeaf, x: number, y: number = 0): void {
86
- t.x += x
87
- t.y += y
85
+ moveLocal(t: ILeaf, x: number | IPointData, y = 0): void {
86
+ if (typeof x === 'object') {
87
+ t.x += x.x
88
+ t.y += x.y
89
+ } else {
90
+ t.x += x
91
+ t.y += y
92
+ }
88
93
  },
89
94
 
90
95
  zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void {
91
- this.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize)
96
+ L.zoomOfLocal(t, getTempLocal(t, origin), scaleX, scaleY, resize)
92
97
  },
93
98
 
94
99
  zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number = scaleX, resize?: boolean): void {
@@ -99,7 +104,7 @@ export const LeafHelper = {
99
104
  },
100
105
 
101
106
  rotateOfWorld(t: ILeaf, origin: IPointData, angle: number): void {
102
- this.rotateOfLocal(t, getTempLocal(t, origin), angle)
107
+ L.rotateOfLocal(t, getTempLocal(t, origin), angle)
103
108
  },
104
109
 
105
110
  rotateOfLocal(t: ILeaf, origin: IPointData, angle: number): void {
@@ -110,7 +115,7 @@ export const LeafHelper = {
110
115
  },
111
116
 
112
117
  skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
113
- this.skewOfLocal(t, getTempLocal(t, origin), skewX, skewY, resize)
118
+ L.skewOfLocal(t, getTempLocal(t, origin), skewX, skewY, resize)
114
119
  },
115
120
 
116
121
  skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY: number = 0, resize?: boolean): void {
@@ -119,6 +124,13 @@ export const LeafHelper = {
119
124
  L.setTransform(t, matrix, resize)
120
125
  },
121
126
 
127
+ transformWorld(t: ILeaf, transform: IMatrixData, resize?: boolean): void {
128
+ copy(matrix, t.worldTransform)
129
+ multiplyParent(matrix, transform)
130
+ if (t.parent) divideParent(matrix, t.parent.worldTransform)
131
+ L.setTransform(t, matrix, resize)
132
+ },
133
+
122
134
  transform(t: ILeaf, transform: IMatrixData, resize?: boolean): void {
123
135
  copy(matrix, t.localTransform)
124
136
  multiplyParent(matrix, transform)
@@ -128,18 +140,34 @@ export const LeafHelper = {
128
140
  setTransform(t: ILeaf, transform: IMatrixData, resize?: boolean): void {
129
141
  const layout = getLayout(transform)
130
142
  if (resize) {
131
- t.scaleResize(layout.scaleX / t.scaleX, layout.scaleY / t.scaleY, resize !== true)
143
+ const scaleX = layout.scaleX / t.scaleX
144
+ const scaleY = layout.scaleY / t.scaleY
132
145
  delete layout.scaleX
133
146
  delete layout.scaleY
147
+ t.set(layout)
148
+ t.scaleResize(scaleX, scaleY, resize !== true)
149
+ } else {
150
+ t.set(layout)
134
151
  }
135
- t.set(layout)
136
152
  },
137
153
 
154
+ getLocalOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData {
155
+ return PointHelper.tempToOuterOf(L.getInnerOrigin(t, origin), t.localTransform)
156
+ },
138
157
 
139
- drop(t: ILeaf, parent: ILeaf, index?: number, resize?: boolean): void {
158
+ getInnerOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData {
159
+ if (typeof origin === 'string') AroundHelper.toPoint(origin, t.boxBounds, origin = {} as IPointData)
160
+ return origin
161
+ },
162
+
163
+ getRelativeWorld(t: ILeaf, relative: ILeaf, temp?: boolean): IMatrixData {
140
164
  copy(matrix, t.worldTransform)
141
- divideParent(matrix, parent.worldTransform)
142
- t.setTransform(matrix, resize)
165
+ divideParent(matrix, relative.worldTransform)
166
+ return temp ? matrix : { ...matrix }
167
+ },
168
+
169
+ drop(t: ILeaf, parent: ILeaf, index?: number, resize?: boolean): void {
170
+ t.setTransform(L.getRelativeWorld(t, parent, true), resize)
143
171
  parent.add(t, index)
144
172
  },
145
173
 
@@ -149,13 +177,6 @@ export const LeafHelper = {
149
177
  if (parent === p) return true
150
178
  p = p.parent
151
179
  }
152
- },
153
-
154
- hasParentAutoLayout(p: ILeaf): boolean | void {
155
- while (p.parent) {
156
- p = p.parent
157
- if (p.__hasAutoLayout) return true
158
- }
159
180
  }
160
181
 
161
182
  }
package/src/WaitHelper.ts CHANGED
@@ -2,7 +2,10 @@ import { IFunction } from '@leafer/interface'
2
2
 
3
3
  export const WaitHelper = {
4
4
  run(wait: IFunction[]): void {
5
- for (let i = 0, len = wait.length; i < len; i++) { wait[i]() }
6
- wait.length = 0
5
+ if (wait && wait.length) {
6
+ const len = wait.length
7
+ for (let i = 0; i < len; i++) { wait[i]() }
8
+ wait.length === len ? wait.length = 0 : wait.splice(0, len)
9
+ }
7
10
  }
8
11
  }
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaf, IPointData, IMatrixData, IBoundsData, ILeafList, ILeafLevelList, IFunction } from '@leafer/interface';
1
+ import { ILeaf, IPointData, IMatrixData, 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,19 +7,22 @@ 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, y: number): void;
11
- moveLocal(t: ILeaf, x: number, y?: number): void;
10
+ moveWorld(t: ILeaf, x: number | IPointData, y?: number): void;
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;
14
14
  rotateOfWorld(t: ILeaf, origin: IPointData, angle: number): void;
15
15
  rotateOfLocal(t: ILeaf, origin: IPointData, angle: number): void;
16
16
  skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
17
17
  skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
18
+ transformWorld(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
18
19
  transform(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
19
20
  setTransform(t: ILeaf, transform: IMatrixData, resize?: boolean): void;
21
+ getLocalOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData;
22
+ getInnerOrigin(t: ILeaf, origin: IPointData | IAlign): IPointData;
23
+ getRelativeWorld(t: ILeaf, relative: ILeaf, temp?: boolean): IMatrixData;
20
24
  drop(t: ILeaf, parent: ILeaf, index?: number, resize?: boolean): void;
21
25
  hasParent(p: ILeaf, parent: ILeaf): boolean | void;
22
- hasParentAutoLayout(p: ILeaf): boolean | void;
23
26
  };
24
27
 
25
28
  declare const LeafBoundsHelper: {
@@ -30,6 +33,7 @@ declare const LeafBoundsHelper: {
30
33
  maskLocalBoxBounds(target: ILeaf): IBoundsData;
31
34
  maskLocalStrokeBounds(target: ILeaf): IBoundsData;
32
35
  maskLocalRenderBounds(target: ILeaf): IBoundsData;
36
+ excludeRenderBounds(child: ILeaf, options: IRenderOptions): boolean;
33
37
  };
34
38
 
35
39
  declare const BranchHelper: {