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