@leafer/helper 1.0.0-beta.12 → 1.0.0-beta.15

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,12 +1,14 @@
1
1
  {
2
2
  "name": "@leafer/helper",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.15",
4
4
  "description": "@leafer/helper",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
7
  "main": "src/index.ts",
8
+ "types": "types/index.d.ts",
8
9
  "files": [
9
- "src"
10
+ "types",
11
+ "dist"
10
12
  ],
11
13
  "repository": {
12
14
  "type": "git",
@@ -19,9 +21,9 @@
19
21
  "leaferjs"
20
22
  ],
21
23
  "dependencies": {
22
- "@leafer/math": "1.0.0-beta.12"
24
+ "@leafer/math": "1.0.0-beta.15"
23
25
  },
24
26
  "devDependencies": {
25
- "@leafer/interface": "1.0.0-beta.12"
27
+ "@leafer/interface": "1.0.0-beta.15"
26
28
  }
27
29
  }
@@ -0,0 +1,44 @@
1
+ import { ILeaf, IPointData, IBranch, IBoundsData, IFunction } from '@leafer/interface';
2
+
3
+ declare const LeafHelper: {
4
+ updateAllWorldMatrix(leaf: ILeaf): void;
5
+ updateAllWorldOpacity(leaf: ILeaf): void;
6
+ updateAllChange(leaf: ILeaf): void;
7
+ worldHittable(t: ILeaf): boolean;
8
+ moveWorld(t: ILeaf, x: number, y: number): void;
9
+ moveLocal(t: ILeaf, x: number, y?: number): void;
10
+ zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void;
11
+ zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void;
12
+ rotateOfWorld(t: ILeaf, origin: IPointData, angle: number, moveLayer?: ILeaf): void;
13
+ rotateOfLocal(t: ILeaf, origin: IPointData, angle: number, moveLayer?: ILeaf): void;
14
+ skewOfWorld(t: ILeaf, origin: IPointData, skewX: number, skewY?: number, moveLayer?: ILeaf): void;
15
+ skewOfLocal(t: ILeaf, origin: IPointData, skewX: number, skewY: number, moveLayer?: ILeaf): void;
16
+ drop(t: ILeaf, parent: IBranch): void;
17
+ };
18
+
19
+ declare const LeafBoundsHelper: {
20
+ worldBounds(target: ILeaf): IBoundsData;
21
+ localBoxBounds(target: ILeaf): IBoundsData;
22
+ localEventBounds(target: ILeaf): IBoundsData;
23
+ localRenderBounds(target: ILeaf): IBoundsData;
24
+ maskLocalBoxBounds(target: ILeaf): IBoundsData;
25
+ maskLocalEventBounds(target: ILeaf): IBoundsData;
26
+ maskLocalRenderBounds(target: ILeaf): IBoundsData;
27
+ };
28
+
29
+ interface ILeafPushList {
30
+ push(item: ILeaf): void;
31
+ }
32
+ declare const BranchHelper: {
33
+ sort(a: ILeaf, b: ILeaf): number;
34
+ pushAllChildBranch(branch: ILeaf, pushList: ILeafPushList): void;
35
+ pushAllParent(leaf: ILeaf, pushList: ILeafPushList): void;
36
+ pushAllBranchStack(branch: ILeaf, pushList: ILeaf[]): void;
37
+ updateWorldBoundsByBranchStack(branchStack: ILeaf[]): void;
38
+ };
39
+
40
+ declare const WaitHelper: {
41
+ run(wait: IFunction[]): void;
42
+ };
43
+
44
+ export { BranchHelper, LeafBoundsHelper, LeafHelper, WaitHelper };
@@ -1,79 +0,0 @@
1
- import { ILeaf, ILeafList } from '@leafer/interface'
2
-
3
-
4
- interface ILeafPushList {
5
- push(item: ILeaf): void
6
- }
7
-
8
-
9
- export const BranchHelper = {
10
-
11
- sort(a: ILeaf, b: ILeaf): number {
12
- return (a.__.zIndex === b.__.zIndex) ? (a.__tempNumber - b.__tempNumber) : (a.__.zIndex - b.__.zIndex)
13
- },
14
-
15
- // push
16
-
17
- pushAllChildBranch(branch: ILeaf, pushList: ILeafPushList): void {
18
- branch.__tempNumber = 1 // 标识需要更新子Leaf元素的WorldBounds分支 Layouter需使用
19
-
20
- if (branch.__.__childBranchNumber) {
21
- const { children } = branch
22
- for (let i = 0, len = children.length; i < len; i++) {
23
- branch = children[i]
24
- if (branch.isBranch) {
25
- branch.__tempNumber = 1
26
- pushList.push(branch)
27
- pushAllChildBranch(branch, pushList)
28
- }
29
- }
30
- }
31
- },
32
-
33
- pushAllParent(leaf: ILeaf, pushList: ILeafPushList): void {
34
- const { keys } = (pushList as ILeafList)
35
- if (keys) {
36
- while (leaf.parent) {
37
- if (keys[leaf.parent.innerId] === undefined) {
38
- pushList.push(leaf.parent)
39
- leaf = leaf.parent
40
- } else {
41
- break
42
- }
43
- }
44
- } else {
45
- while (leaf.parent) {
46
- pushList.push(leaf.parent)
47
- leaf = leaf.parent
48
- }
49
- }
50
- },
51
-
52
- pushAllBranchStack(branch: ILeaf, pushList: ILeaf[]): void {
53
- let start = pushList.length
54
- const { children } = branch
55
- for (let i = 0, len = children.length; i < len; i++) {
56
- if (children[i].isBranch) {
57
- pushList.push(children[i])
58
- }
59
- }
60
-
61
- // 找子级
62
- for (let i = start, len = pushList.length; i < len; i++) {
63
- pushAllBranchStack(pushList[i], pushList)
64
- }
65
- },
66
-
67
- updateWorldBoundsByBranchStack(branchStack: ILeaf[]): void {
68
- let branch: ILeaf
69
- for (let i = branchStack.length - 1; i > -1; i--) {
70
- branch = branchStack[i]
71
- for (let j = 0, len = branch.children.length; j < len; j++) {
72
- branch.children[j].__updateWorldBounds()
73
- }
74
- }
75
- branch.__updateWorldBounds()
76
- }
77
- }
78
-
79
- const { pushAllChildBranch, pushAllBranchStack } = BranchHelper
@@ -1,34 +0,0 @@
1
- import { ILeaf, IBoundsData } from '@leafer/interface'
2
-
3
-
4
- export const LeafBoundsHelper = {
5
-
6
- worldBounds(target: ILeaf): IBoundsData {
7
- return target.__world
8
- },
9
-
10
- localBoxBounds(target: ILeaf): IBoundsData {
11
- return target.__.isEraser ? null : target.__local
12
- },
13
-
14
- localEventBounds(target: ILeaf): IBoundsData {
15
- return target.__.isEraser ? null : target.__layout.localStrokeBounds
16
- },
17
-
18
- localRenderBounds(target: ILeaf): IBoundsData {
19
- return target.__.isEraser ? null : 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
32
- }
33
-
34
- }
package/src/LeafHelper.ts DELETED
@@ -1,113 +0,0 @@
1
- import { IBranch, ILeaf, IMatrixData, IPointData } from '@leafer/interface'
2
- import { MatrixHelper, PointHelper } from '@leafer/math'
3
-
4
-
5
- const { copy, translate, toInnerPoint, scaleOfOuter, rotateOfOuter } = MatrixHelper
6
- const matrix = {} as IMatrixData
7
-
8
- export const LeafHelper = {
9
-
10
- updateAllWorldMatrix(leaf: ILeaf): void {
11
- leaf.__updateWorldMatrix()
12
-
13
- if (leaf.isBranch) {
14
- const { children } = leaf
15
- for (let i = 0, len = children.length; i < len; i++) {
16
- updateAllWorldMatrix(children[i])
17
- }
18
- }
19
- },
20
-
21
- updateAllWorldOpacity(leaf: ILeaf): void {
22
- leaf.__updateWorldOpacity()
23
-
24
- if (leaf.isBranch) {
25
- const { children } = leaf
26
- for (let i = 0, len = children.length; i < len; i++) {
27
- updateAllWorldOpacity(children[i])
28
- }
29
- }
30
- },
31
-
32
- updateAllChange(leaf: ILeaf): void {
33
-
34
- updateAllWorldOpacity(leaf)
35
-
36
- leaf.__updateChange()
37
-
38
- if (leaf.isBranch) {
39
- const { children } = leaf
40
- for (let i = 0, len = children.length; i < len; i++) {
41
- updateAllChange(children[i])
42
- }
43
- }
44
- },
45
-
46
- worldHittable(t: ILeaf): boolean {
47
- if (!t.__.hittable) return false
48
- let { parent } = t
49
- while (parent) {
50
- if (!parent.__.hittable || !parent.__.hitChildren) return false
51
- parent = parent.parent
52
- }
53
- return true
54
- },
55
-
56
- // transform
57
-
58
- moveWorld(t: ILeaf, x: number, y: number): void {
59
- t.__layout.checkUpdate()
60
- const local = { x, y }
61
- if (t.parent) toInnerPoint(t.parent.__world, local, local, true)
62
- L.moveLocal(t, local.x, local.y)
63
- },
64
-
65
- moveLocal(t: ILeaf, x: number, y: number = 0): void {
66
- t.x += x
67
- t.y += y
68
- },
69
-
70
- zoomOfWorld(t: ILeaf, origin: IPointData, scaleX: number, scaleY?: number, moveLayer?: ILeaf): void {
71
- t.__layout.checkUpdate()
72
- const local = t.parent ? PointHelper.tempToInnerOf(origin, t.parent.__world) : origin
73
- this.zoomOfLocal(t, local, scaleX, scaleY, moveLayer)
74
- },
75
-
76
- zoomOfLocal(t: ILeaf, origin: IPointData, scaleX: number, scaleY: number = scaleX, moveLayer?: ILeaf): void {
77
- copy(matrix, t.__local)
78
- if (moveLayer) translate(matrix, moveLayer.x, moveLayer.y)
79
- scaleOfOuter(matrix, origin, scaleX, scaleY)
80
- if (!moveLayer) moveLayer = t
81
- moveLayer.x += matrix.e - t.__local.e
82
- moveLayer.y += matrix.f - t.__local.f
83
- t.scaleX *= scaleX
84
- t.scaleY *= scaleY
85
- },
86
-
87
- rotateOfWorld(t: ILeaf, origin: IPointData, angle: number, moveLayer?: ILeaf): void {
88
- t.__layout.checkUpdate()
89
- const local = t.parent ? PointHelper.tempToInnerOf(origin, t.parent.__world) : origin
90
- this.rotateOfLocal(t, local, angle, moveLayer)
91
- },
92
-
93
- rotateOfLocal(t: ILeaf, origin: IPointData, angle: number, moveLayer?: ILeaf): void {
94
- copy(matrix, t.__local)
95
- if (moveLayer) translate(matrix, moveLayer.x, moveLayer.y)
96
- rotateOfOuter(matrix, origin, angle)
97
- if (!moveLayer) moveLayer = t
98
- moveLayer.x += matrix.e - t.__local.e
99
- moveLayer.y += matrix.f - t.__local.f
100
- t.rotation += angle
101
- },
102
-
103
- drop(t: ILeaf, parent: IBranch): void {
104
- const position = { x: t.x, y: t.y }
105
- t.localToWorld(position)
106
- parent.worldToInner(position)
107
- t.set(position)
108
- parent.add(t)
109
- }
110
-
111
- }
112
- const L = LeafHelper
113
- const { updateAllWorldMatrix, updateAllWorldOpacity, updateAllChange } = L
package/src/WaitHelper.ts DELETED
@@ -1,8 +0,0 @@
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
- }