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