@leafer/layout 1.0.0-alpha.21 → 1.0.0-alpha.23
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 +3 -3
- package/src/LeafLayout.ts +68 -60
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/layout",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.23",
|
|
4
4
|
"description": "@leafer/layout",
|
|
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.
|
|
22
|
+
"@leafer/math": "1.0.0-alpha.23"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@leafer/interface": "1.0.0-alpha.
|
|
25
|
+
"@leafer/interface": "1.0.0-alpha.23"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/LeafLayout.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ILeaf, ILeafLayout, ILayoutLocationType, ILayoutBoundsType, IBoundsData, IMatrixData, } from '@leafer/interface'
|
|
2
|
-
import { BoundsHelper } from '@leafer/math'
|
|
1
|
+
import { ILeaf, ILeafLayout, ILayoutLocationType, ILayoutBoundsType, IBoundsData, IMatrixData, IMatrixDecompositionData } from '@leafer/interface'
|
|
2
|
+
import { BoundsHelper, MatrixHelper } from '@leafer/math'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
const { toOuterOf } = BoundsHelper
|
|
6
6
|
|
|
7
7
|
export class LeafLayout implements ILeafLayout {
|
|
8
8
|
|
|
@@ -12,38 +12,36 @@ export class LeafLayout implements ILeafLayout {
|
|
|
12
12
|
|
|
13
13
|
// local
|
|
14
14
|
|
|
15
|
-
public boxBounds: IBoundsData
|
|
16
|
-
public
|
|
17
|
-
public renderBounds: IBoundsData
|
|
15
|
+
public boxBounds: IBoundsData
|
|
16
|
+
public strokeBounds: IBoundsData
|
|
17
|
+
public renderBounds: IBoundsData
|
|
18
18
|
|
|
19
19
|
// auto layout
|
|
20
|
-
public marginBounds: IBoundsData
|
|
21
|
-
public contentBounds: IBoundsData
|
|
20
|
+
public marginBounds: IBoundsData
|
|
21
|
+
public contentBounds: IBoundsData
|
|
22
22
|
|
|
23
|
-
//
|
|
23
|
+
// local
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
public
|
|
27
|
-
public relativeRenderBounds: IBoundsData
|
|
25
|
+
public localStrokeBounds: IBoundsData
|
|
26
|
+
public localRenderBounds: IBoundsData
|
|
28
27
|
|
|
29
28
|
// world temp
|
|
30
29
|
protected _worldBoxBounds: IBoundsData
|
|
31
|
-
protected
|
|
32
|
-
// worldRenderBounds: IBoundsData = leaf.__world
|
|
30
|
+
protected _worldStrokeBounds: IBoundsData
|
|
33
31
|
|
|
34
32
|
// state
|
|
35
33
|
|
|
36
34
|
// matrix changed
|
|
37
|
-
public matrixChanged: boolean
|
|
38
|
-
public positionChanged: boolean
|
|
39
|
-
public scaleChanged: boolean
|
|
40
|
-
public rotationChanged: boolean
|
|
35
|
+
public matrixChanged: boolean
|
|
36
|
+
public positionChanged: boolean
|
|
37
|
+
public scaleChanged: boolean
|
|
38
|
+
public rotationChanged: boolean
|
|
41
39
|
|
|
42
40
|
// bounds
|
|
43
41
|
public boundsChanged: boolean
|
|
44
42
|
|
|
45
43
|
public boxBoundsChanged: boolean
|
|
46
|
-
public
|
|
44
|
+
public strokeBoundsChanged: boolean
|
|
47
45
|
public renderBoundsChanged: boolean
|
|
48
46
|
|
|
49
47
|
public localBoxBoundsChanged: boolean
|
|
@@ -59,109 +57,119 @@ export class LeafLayout implements ILeafLayout {
|
|
|
59
57
|
// keep state
|
|
60
58
|
public affectScaleOrRotation: boolean
|
|
61
59
|
public affectRotation: boolean
|
|
62
|
-
public
|
|
60
|
+
public strokeBoundsSpreadWidth: number
|
|
63
61
|
public renderBoundsSpreadWidth: number
|
|
64
62
|
public renderShapeBoundsSpreadWidth: number
|
|
65
63
|
|
|
66
64
|
|
|
67
65
|
constructor(leaf: ILeaf) {
|
|
68
66
|
this.leaf = leaf
|
|
69
|
-
this.renderBounds = this.
|
|
70
|
-
this.
|
|
67
|
+
this.renderBounds = this.strokeBounds = this.boxBounds = { x: 0, y: 0, width: 0, height: 0 }
|
|
68
|
+
this.localRenderBounds = this.localStrokeBounds = leaf.__local
|
|
71
69
|
this.boxBoundsChange()
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
|
|
75
73
|
public update(): void {
|
|
76
74
|
const { leafer } = this.leaf
|
|
77
|
-
if (leafer
|
|
78
|
-
if (
|
|
79
|
-
|
|
75
|
+
if (leafer) {
|
|
76
|
+
if (leafer.ready) {
|
|
77
|
+
if (leafer.watcher.changed) leafer.layouter.layout()
|
|
78
|
+
} else {
|
|
79
|
+
leafer.start()
|
|
80
|
+
leafer.layouter.layout()
|
|
81
|
+
}
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
public getTransform(
|
|
85
|
+
public getTransform(locationType: ILayoutLocationType): IMatrixData {
|
|
86
|
+
this.update()
|
|
87
|
+
return locationType === 'world' ? this.leaf.__world : this.leaf.__local
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public getMatrixDecompositionData(locationType: ILayoutLocationType): IMatrixDecompositionData {
|
|
84
91
|
this.update()
|
|
85
|
-
return
|
|
92
|
+
return MatrixHelper.decompose(locationType === 'world' ? this.leaf.__world : this.leaf.__local)
|
|
86
93
|
}
|
|
87
94
|
|
|
88
|
-
public getBounds(type:
|
|
95
|
+
public getBounds(type: ILayoutBoundsType, locationType: ILayoutLocationType): IBoundsData {
|
|
89
96
|
|
|
90
97
|
this.update()
|
|
91
98
|
|
|
92
|
-
if (
|
|
99
|
+
if (locationType === 'world') {
|
|
93
100
|
|
|
94
|
-
switch (
|
|
101
|
+
switch (type) {
|
|
95
102
|
case 'render':
|
|
96
103
|
return this.leaf.__world
|
|
97
104
|
case 'box':
|
|
98
105
|
return this.getWorldBoxBounds()
|
|
99
|
-
case '
|
|
100
|
-
return this.
|
|
106
|
+
case 'stroke':
|
|
107
|
+
return this.getWorldStrokeBounds()
|
|
101
108
|
}
|
|
102
109
|
|
|
103
|
-
} else if (
|
|
110
|
+
} else if (locationType === 'inner') {
|
|
104
111
|
|
|
105
|
-
switch (
|
|
112
|
+
switch (type) {
|
|
106
113
|
case 'render':
|
|
107
114
|
return this.renderBounds
|
|
108
115
|
case 'box':
|
|
109
116
|
return this.boxBounds
|
|
110
|
-
case '
|
|
111
|
-
return this.
|
|
117
|
+
case 'stroke':
|
|
118
|
+
return this.strokeBounds
|
|
112
119
|
}
|
|
113
120
|
|
|
114
121
|
} else {
|
|
115
122
|
|
|
116
|
-
switch (
|
|
123
|
+
switch (type) {
|
|
117
124
|
case 'render':
|
|
118
|
-
return this.
|
|
125
|
+
return this.localRenderBounds
|
|
119
126
|
case 'box':
|
|
120
|
-
return this.leaf.
|
|
121
|
-
case '
|
|
122
|
-
return this.
|
|
127
|
+
return this.leaf.__local
|
|
128
|
+
case 'stroke':
|
|
129
|
+
return this.localStrokeBounds
|
|
123
130
|
}
|
|
124
131
|
|
|
125
132
|
}
|
|
133
|
+
|
|
126
134
|
return this.leaf.__world
|
|
127
135
|
}
|
|
128
136
|
|
|
129
137
|
|
|
130
138
|
protected getWorldBoxBounds(): IBoundsData {
|
|
131
139
|
this._worldBoxBounds || (this._worldBoxBounds = {} as IBoundsData)
|
|
132
|
-
|
|
140
|
+
toOuterOf(this.boxBounds, this.leaf.__world, this._worldBoxBounds)
|
|
133
141
|
return this._worldBoxBounds
|
|
134
142
|
}
|
|
135
143
|
|
|
136
|
-
protected
|
|
137
|
-
this.
|
|
138
|
-
|
|
139
|
-
return this.
|
|
144
|
+
protected getWorldStrokeBounds(): IBoundsData {
|
|
145
|
+
this._worldStrokeBounds || (this._worldStrokeBounds = {} as IBoundsData)
|
|
146
|
+
toOuterOf(this.strokeBounds, this.leaf.__world, this._worldStrokeBounds)
|
|
147
|
+
return this._worldStrokeBounds
|
|
140
148
|
}
|
|
141
149
|
|
|
142
150
|
// 独立 / 引用 boxBounds
|
|
143
151
|
|
|
144
|
-
public
|
|
145
|
-
const same = this.renderBounds === this.
|
|
146
|
-
this.
|
|
147
|
-
this.
|
|
152
|
+
public strokeBoundsSpreadCancel(): void {
|
|
153
|
+
const same = this.renderBounds === this.strokeBounds
|
|
154
|
+
this.strokeBounds = this.boxBounds
|
|
155
|
+
this.localStrokeBounds = this.leaf.__local
|
|
148
156
|
if (same) this.renderBoundsSpreadCancel()
|
|
149
157
|
}
|
|
150
158
|
public renderBoundsSpreadCancel(): void {
|
|
151
|
-
this.renderBounds = this.
|
|
152
|
-
this.
|
|
159
|
+
this.renderBounds = this.strokeBounds
|
|
160
|
+
this.localRenderBounds = this.localStrokeBounds
|
|
153
161
|
}
|
|
154
162
|
|
|
155
|
-
public
|
|
156
|
-
const { x, y, width, height } = this.
|
|
157
|
-
this.
|
|
158
|
-
this.
|
|
163
|
+
public strokeBoundsSpread(): void {
|
|
164
|
+
const { x, y, width, height } = this.strokeBounds
|
|
165
|
+
this.strokeBounds = { x, y, width, height }
|
|
166
|
+
this.localStrokeBounds = { x, y, width, height }
|
|
159
167
|
if (!this.renderBoundsSpreadWidth) this.renderBoundsSpreadCancel()
|
|
160
168
|
}
|
|
161
169
|
public renderBoundsSpread(): void {
|
|
162
170
|
const { x, y, width, height } = this.renderBounds
|
|
163
171
|
this.renderBounds = { x, y, width, height }
|
|
164
|
-
this.
|
|
172
|
+
this.localRenderBounds = { x, y, width, height }
|
|
165
173
|
}
|
|
166
174
|
|
|
167
175
|
|
|
@@ -178,9 +186,9 @@ export class LeafLayout implements ILeafLayout {
|
|
|
178
186
|
this.boundsChanged = true
|
|
179
187
|
}
|
|
180
188
|
|
|
181
|
-
public
|
|
182
|
-
this.
|
|
183
|
-
this.
|
|
189
|
+
public strokeBoundsChange(): void {
|
|
190
|
+
this.strokeBoundsChanged = true
|
|
191
|
+
this.strokeBoundsSpreadWidth || (this.strokeBoundsSpreadWidth = 1)
|
|
184
192
|
this.boundsChanged = true
|
|
185
193
|
}
|
|
186
194
|
|