@leafer/layout 1.0.0-alpha.9 → 1.0.0-beta
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 +4 -3
- package/src/LeafLayout.ts +115 -84
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/layout",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta",
|
|
4
4
|
"description": "@leafer/layout",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,9 +19,10 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leafer/math": "1.0.0-
|
|
22
|
+
"@leafer/math": "1.0.0-beta",
|
|
23
|
+
"@leafer/platform": "1.0.0-beta"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@leafer/interface": "1.0.0-
|
|
26
|
+
"@leafer/interface": "1.0.0-beta"
|
|
26
27
|
}
|
|
27
28
|
}
|
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,41 +13,40 @@ 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
|
-
public
|
|
46
|
-
public
|
|
47
|
-
public
|
|
45
|
+
public boxChanged: boolean
|
|
46
|
+
public strokeChanged: boolean
|
|
47
|
+
public renderChanged: boolean
|
|
48
48
|
|
|
49
|
-
public
|
|
49
|
+
public localBoxChanged: boolean
|
|
50
50
|
|
|
51
51
|
// face
|
|
52
52
|
public surfaceChanged: boolean
|
|
@@ -59,133 +59,164 @@ export class LeafLayout implements ILeafLayout {
|
|
|
59
59
|
// keep state
|
|
60
60
|
public affectScaleOrRotation: boolean
|
|
61
61
|
public affectRotation: boolean
|
|
62
|
-
|
|
63
|
-
public
|
|
64
|
-
public
|
|
62
|
+
|
|
63
|
+
public strokeSpread: number
|
|
64
|
+
public renderSpread: number
|
|
65
|
+
public strokeBoxSpread: number
|
|
66
|
+
public renderShapeSpread: number
|
|
65
67
|
|
|
66
68
|
|
|
67
69
|
constructor(leaf: ILeaf) {
|
|
68
70
|
this.leaf = leaf
|
|
69
|
-
this.renderBounds = this.
|
|
70
|
-
this.
|
|
71
|
+
this.renderBounds = this.strokeBounds = this.boxBounds = { x: 0, y: 0, width: 0, height: 0 }
|
|
72
|
+
this.localRenderBounds = this.localStrokeBounds = leaf.__local
|
|
73
|
+
this.boxChange()
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
|
|
74
|
-
public
|
|
77
|
+
public checkUpdate(): void {
|
|
75
78
|
const { leafer } = this.leaf
|
|
76
|
-
if (leafer
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
+
if (leafer) {
|
|
80
|
+
if (leafer.ready) {
|
|
81
|
+
if (leafer.watcher.changed) leafer.layouter.layout()
|
|
82
|
+
} else {
|
|
83
|
+
leafer.start()
|
|
84
|
+
leafer.layouter.layout()
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
let root = this.leaf
|
|
88
|
+
while (root.parent) { root = root.parent }
|
|
89
|
+
Platform.layout(root)
|
|
79
90
|
}
|
|
80
91
|
}
|
|
81
92
|
|
|
82
|
-
public getTransform(
|
|
83
|
-
this.
|
|
84
|
-
return
|
|
93
|
+
public getTransform(locationType: ILayoutLocationType): IMatrixData {
|
|
94
|
+
this.checkUpdate()
|
|
95
|
+
return locationType === 'world' ? this.leaf.__world : this.leaf.__local
|
|
85
96
|
}
|
|
86
97
|
|
|
87
|
-
public
|
|
98
|
+
public decomposeTransform(locationType: ILayoutLocationType): IMatrixDecompositionData {
|
|
99
|
+
this.checkUpdate()
|
|
100
|
+
return MatrixHelper.decompose(locationType === 'world' ? this.leaf.__world : this.leaf.__local)
|
|
101
|
+
}
|
|
88
102
|
|
|
89
|
-
|
|
103
|
+
public getBounds(type: ILayoutBoundsType, locationType: ILayoutLocationType): IBoundsData {
|
|
90
104
|
|
|
91
|
-
|
|
105
|
+
this.checkUpdate()
|
|
92
106
|
|
|
93
|
-
|
|
107
|
+
if (locationType === 'world') {
|
|
108
|
+
|
|
109
|
+
switch (type) {
|
|
94
110
|
case 'render':
|
|
95
111
|
return this.leaf.__world
|
|
112
|
+
case 'content':
|
|
113
|
+
if (this.contentBounds) return this.getWorldContentBounds()
|
|
114
|
+
case 'margin':
|
|
96
115
|
case 'box':
|
|
97
116
|
return this.getWorldBoxBounds()
|
|
98
|
-
case '
|
|
99
|
-
|
|
117
|
+
case 'margin':
|
|
118
|
+
case 'stroke':
|
|
119
|
+
return this.getWorldStrokeBounds()
|
|
100
120
|
}
|
|
101
121
|
|
|
102
|
-
} else if (
|
|
122
|
+
} else if (locationType === 'inner') {
|
|
103
123
|
|
|
104
|
-
switch (
|
|
124
|
+
switch (type) {
|
|
105
125
|
case 'render':
|
|
106
126
|
return this.renderBounds
|
|
127
|
+
case 'content':
|
|
128
|
+
if (this.contentBounds) return this.contentBounds
|
|
129
|
+
case 'margin':
|
|
107
130
|
case 'box':
|
|
108
131
|
return this.boxBounds
|
|
109
|
-
case '
|
|
110
|
-
return this.
|
|
132
|
+
case 'stroke':
|
|
133
|
+
return this.strokeBounds
|
|
111
134
|
}
|
|
112
135
|
|
|
113
136
|
} else {
|
|
114
137
|
|
|
115
|
-
switch (
|
|
138
|
+
switch (type) {
|
|
116
139
|
case 'render':
|
|
117
|
-
return this.
|
|
140
|
+
return this.localRenderBounds
|
|
141
|
+
case 'margin':
|
|
142
|
+
case 'content':
|
|
118
143
|
case 'box':
|
|
119
|
-
return this.leaf.
|
|
120
|
-
case '
|
|
121
|
-
return this.
|
|
144
|
+
return this.leaf.__local
|
|
145
|
+
case 'stroke':
|
|
146
|
+
return this.localStrokeBounds
|
|
122
147
|
}
|
|
123
148
|
|
|
124
149
|
}
|
|
125
|
-
|
|
150
|
+
|
|
126
151
|
}
|
|
127
152
|
|
|
153
|
+
protected getWorldContentBounds(): IBoundsData {
|
|
154
|
+
this._worldContentBounds || (this._worldContentBounds = {} as IBoundsData)
|
|
155
|
+
toOuterOf(this.contentBounds, this.leaf.__world, this._worldContentBounds)
|
|
156
|
+
return this._worldContentBounds
|
|
157
|
+
}
|
|
128
158
|
|
|
129
159
|
protected getWorldBoxBounds(): IBoundsData {
|
|
130
160
|
this._worldBoxBounds || (this._worldBoxBounds = {} as IBoundsData)
|
|
131
|
-
|
|
161
|
+
toOuterOf(this.boxBounds, this.leaf.__world, this._worldBoxBounds)
|
|
132
162
|
return this._worldBoxBounds
|
|
133
163
|
}
|
|
134
164
|
|
|
135
|
-
protected
|
|
136
|
-
this.
|
|
137
|
-
|
|
138
|
-
return this.
|
|
165
|
+
protected getWorldStrokeBounds(): IBoundsData {
|
|
166
|
+
this._worldStrokeBounds || (this._worldStrokeBounds = {} as IBoundsData)
|
|
167
|
+
toOuterOf(this.strokeBounds, this.leaf.__world, this._worldStrokeBounds)
|
|
168
|
+
return this._worldStrokeBounds
|
|
139
169
|
}
|
|
140
170
|
|
|
141
171
|
// 独立 / 引用 boxBounds
|
|
142
172
|
|
|
143
|
-
public
|
|
144
|
-
const same = this.renderBounds === this.
|
|
145
|
-
this.
|
|
146
|
-
this.
|
|
147
|
-
if (same) this.
|
|
173
|
+
public spreadStrokeCancel(): void {
|
|
174
|
+
const same = this.renderBounds === this.strokeBounds
|
|
175
|
+
this.strokeBounds = this.boxBounds
|
|
176
|
+
this.localStrokeBounds = this.leaf.__local
|
|
177
|
+
if (same) this.spreadRenderCancel()
|
|
148
178
|
}
|
|
149
|
-
public
|
|
150
|
-
this.renderBounds = this.
|
|
151
|
-
this.
|
|
179
|
+
public spreadRenderCancel(): void {
|
|
180
|
+
this.renderBounds = this.strokeBounds
|
|
181
|
+
this.localRenderBounds = this.localStrokeBounds
|
|
152
182
|
}
|
|
153
183
|
|
|
154
|
-
public
|
|
155
|
-
const { x, y, width, height } = this.
|
|
156
|
-
this.
|
|
157
|
-
this.
|
|
158
|
-
if (!this.
|
|
184
|
+
public spreadStroke(): void {
|
|
185
|
+
const { x, y, width, height } = this.strokeBounds
|
|
186
|
+
this.strokeBounds = { x, y, width, height }
|
|
187
|
+
this.localStrokeBounds = { x, y, width, height }
|
|
188
|
+
if (!this.renderSpread) this.spreadRenderCancel()
|
|
159
189
|
}
|
|
160
|
-
public
|
|
190
|
+
public spreadRender(): void {
|
|
161
191
|
const { x, y, width, height } = this.renderBounds
|
|
162
192
|
this.renderBounds = { x, y, width, height }
|
|
163
|
-
this.
|
|
193
|
+
this.localRenderBounds = { x, y, width, height }
|
|
164
194
|
}
|
|
165
195
|
|
|
166
196
|
|
|
167
197
|
// bounds
|
|
168
198
|
|
|
169
|
-
public
|
|
170
|
-
this.
|
|
171
|
-
this.
|
|
199
|
+
public boxChange(): void {
|
|
200
|
+
this.boxChanged = true
|
|
201
|
+
this.localBoxChanged || this.localBoxChange()
|
|
172
202
|
this.hitCanvasChanged = true
|
|
173
203
|
}
|
|
174
204
|
|
|
175
|
-
public
|
|
176
|
-
this.
|
|
205
|
+
public localBoxChange(): void {
|
|
206
|
+
this.localBoxChanged = true
|
|
177
207
|
this.boundsChanged = true
|
|
178
208
|
}
|
|
179
209
|
|
|
180
|
-
public
|
|
181
|
-
this.
|
|
182
|
-
this.
|
|
210
|
+
public strokeChange(): void {
|
|
211
|
+
this.strokeChanged = true
|
|
212
|
+
this.strokeSpread || (this.strokeSpread = 1)
|
|
183
213
|
this.boundsChanged = true
|
|
214
|
+
this.hitCanvasChanged = true
|
|
184
215
|
}
|
|
185
216
|
|
|
186
|
-
public
|
|
187
|
-
this.
|
|
188
|
-
this.
|
|
217
|
+
public renderChange(): void {
|
|
218
|
+
this.renderChanged = true
|
|
219
|
+
this.renderSpread || (this.renderSpread = 1)
|
|
189
220
|
this.boundsChanged = true
|
|
190
221
|
}
|
|
191
222
|
|
|
@@ -195,7 +226,7 @@ export class LeafLayout implements ILeafLayout {
|
|
|
195
226
|
public positionChange(): void {
|
|
196
227
|
this.positionChanged = true
|
|
197
228
|
this.matrixChanged = true
|
|
198
|
-
this.
|
|
229
|
+
this.localBoxChanged || this.localBoxChange()
|
|
199
230
|
}
|
|
200
231
|
|
|
201
232
|
public scaleChange(): void {
|
|
@@ -212,7 +243,7 @@ export class LeafLayout implements ILeafLayout {
|
|
|
212
243
|
protected _scaleOrRotationChange() {
|
|
213
244
|
this.affectScaleOrRotation = true
|
|
214
245
|
this.matrixChanged = true
|
|
215
|
-
this.
|
|
246
|
+
this.localBoxChanged || this.localBoxChange()
|
|
216
247
|
}
|
|
217
248
|
|
|
218
249
|
|
|
@@ -228,7 +259,7 @@ export class LeafLayout implements ILeafLayout {
|
|
|
228
259
|
}
|
|
229
260
|
|
|
230
261
|
public destroy(): void {
|
|
231
|
-
this.leaf =
|
|
262
|
+
this.leaf = null
|
|
232
263
|
}
|
|
233
264
|
|
|
234
265
|
}
|