@leafer/layout 1.0.0-rc.5 → 1.0.0-rc.7
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 -4
- package/src/LeafLayout.ts +145 -53
- package/types/index.d.ts +19 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/layout",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.7",
|
|
4
4
|
"description": "@leafer/layout",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/math": "1.0.0-rc.
|
|
26
|
-
"@leafer/platform": "1.0.0-rc.
|
|
25
|
+
"@leafer/math": "1.0.0-rc.7",
|
|
26
|
+
"@leafer/platform": "1.0.0-rc.7"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.0.0-rc.
|
|
29
|
+
"@leafer/interface": "1.0.0-rc.7"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/LeafLayout.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ILeaf, ILeafLayout,
|
|
2
|
-
import { BoundsHelper } from '@leafer/math'
|
|
1
|
+
import { ILeaf, ILeafLayout, ILocationType, IBoundsType, IBoundsData, IMatrixData, ILayoutBoundsData, ILayoutData, IPointData } from '@leafer/interface'
|
|
2
|
+
import { Bounds, BoundsHelper, Matrix, MatrixHelper } from '@leafer/math'
|
|
3
3
|
import { Platform } from '@leafer/platform'
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
const { toOuterOf } = BoundsHelper
|
|
6
|
+
const { toOuterOf, getPoints } = BoundsHelper
|
|
7
7
|
|
|
8
8
|
export class LeafLayout implements ILeafLayout {
|
|
9
9
|
|
|
@@ -23,8 +23,8 @@ export class LeafLayout implements ILeafLayout {
|
|
|
23
23
|
|
|
24
24
|
// local
|
|
25
25
|
|
|
26
|
-
public localStrokeBounds
|
|
27
|
-
public localRenderBounds
|
|
26
|
+
public localStrokeBounds?: IBoundsData
|
|
27
|
+
public localRenderBounds?: IBoundsData
|
|
28
28
|
|
|
29
29
|
// world temp
|
|
30
30
|
protected _worldContentBounds: IBoundsData
|
|
@@ -33,6 +33,9 @@ export class LeafLayout implements ILeafLayout {
|
|
|
33
33
|
|
|
34
34
|
// state
|
|
35
35
|
|
|
36
|
+
public resized: boolean
|
|
37
|
+
public waitAutoLayout: boolean
|
|
38
|
+
|
|
36
39
|
// matrix changed
|
|
37
40
|
public matrixChanged: boolean
|
|
38
41
|
public scaleChanged: boolean
|
|
@@ -65,84 +68,173 @@ export class LeafLayout implements ILeafLayout {
|
|
|
65
68
|
public strokeBoxSpread: number
|
|
66
69
|
public renderShapeSpread: number
|
|
67
70
|
|
|
71
|
+
// temp local
|
|
72
|
+
public get a() { return 1 }
|
|
73
|
+
public get b() { return 0 }
|
|
74
|
+
public get c() { return 0 }
|
|
75
|
+
public get d() { return 1 }
|
|
76
|
+
public get e() { return this.leaf.__.x }
|
|
77
|
+
public get f() { return this.leaf.__.y }
|
|
78
|
+
|
|
68
79
|
|
|
69
80
|
constructor(leaf: ILeaf) {
|
|
70
81
|
this.leaf = leaf
|
|
71
82
|
this.renderBounds = this.strokeBounds = this.boxBounds = { x: 0, y: 0, width: 0, height: 0 }
|
|
72
|
-
this.localRenderBounds = this.localStrokeBounds = leaf.__local
|
|
83
|
+
if (leaf.__local) this.localRenderBounds = this.localStrokeBounds = leaf.__local
|
|
73
84
|
this.boxChange()
|
|
74
85
|
this.matrixChange()
|
|
75
86
|
}
|
|
76
87
|
|
|
77
|
-
|
|
78
|
-
public checkUpdate(force?: boolean): void {
|
|
88
|
+
public update(): void {
|
|
79
89
|
const { leafer } = this.leaf
|
|
80
90
|
if (leafer) {
|
|
81
91
|
if (leafer.ready) {
|
|
82
|
-
if (
|
|
92
|
+
if (leafer.watcher.changed) leafer.layouter.layout()
|
|
83
93
|
} else {
|
|
84
94
|
leafer.start()
|
|
85
95
|
}
|
|
86
96
|
} else {
|
|
87
97
|
let root = this.leaf
|
|
88
|
-
while (root.parent) { root = root.parent }
|
|
98
|
+
while (root.parent && !root.parent.leafer) { root = root.parent }
|
|
89
99
|
Platform.layout(root)
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
102
|
|
|
93
|
-
public getTransform(
|
|
94
|
-
this.
|
|
95
|
-
|
|
103
|
+
public getTransform(relative: ILocationType | ILeaf = 'world'): IMatrixData {
|
|
104
|
+
this.update()
|
|
105
|
+
switch (relative) {
|
|
106
|
+
case 'world':
|
|
107
|
+
return this.leaf.__world
|
|
108
|
+
case 'local':
|
|
109
|
+
return this.leaf.__localMatrix
|
|
110
|
+
case 'inner':
|
|
111
|
+
return MatrixHelper.defaultMatrix
|
|
112
|
+
default:
|
|
113
|
+
return new Matrix(this.leaf.__world).divideParent(relative.__world)
|
|
114
|
+
}
|
|
96
115
|
}
|
|
97
116
|
|
|
98
|
-
public getBounds(type
|
|
117
|
+
public getBounds(type?: IBoundsType, relative: ILocationType | ILeaf = 'world'): IBoundsData {
|
|
118
|
+
this.update()
|
|
119
|
+
switch (relative) {
|
|
120
|
+
case 'world':
|
|
121
|
+
return this.getWorldBounds(type)
|
|
122
|
+
case 'local':
|
|
123
|
+
return this.getLocalBounds(type)
|
|
124
|
+
case 'inner':
|
|
125
|
+
return this.getInnerBounds(type)
|
|
126
|
+
default:
|
|
127
|
+
return new Bounds(this.getInnerBounds(type)).toOuterOf(this.getTransform(relative))
|
|
128
|
+
}
|
|
129
|
+
}
|
|
99
130
|
|
|
100
|
-
|
|
131
|
+
public getInnerBounds(type: IBoundsType = 'box'): IBoundsData {
|
|
132
|
+
switch (type) {
|
|
133
|
+
case 'render':
|
|
134
|
+
return this.renderBounds
|
|
135
|
+
case 'content':
|
|
136
|
+
if (this.contentBounds) return this.contentBounds
|
|
137
|
+
case 'margin':
|
|
138
|
+
case 'box':
|
|
139
|
+
return this.boxBounds
|
|
140
|
+
case 'stroke':
|
|
141
|
+
return this.strokeBounds
|
|
142
|
+
}
|
|
143
|
+
}
|
|
101
144
|
|
|
102
|
-
|
|
145
|
+
public getLocalBounds(type: IBoundsType = 'box'): IBoundsData {
|
|
146
|
+
switch (type) {
|
|
147
|
+
case 'render':
|
|
148
|
+
if (this.localRenderBounds) return this.localRenderBounds
|
|
149
|
+
case 'stroke':
|
|
150
|
+
if (this.localStrokeBounds) return this.localStrokeBounds
|
|
151
|
+
case 'margin':
|
|
152
|
+
case 'content':
|
|
153
|
+
case 'box':
|
|
154
|
+
return this.leaf.__localBounds
|
|
155
|
+
}
|
|
156
|
+
}
|
|
103
157
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
158
|
+
public getWorldBounds(type: IBoundsType = 'box'): IBoundsData {
|
|
159
|
+
switch (type) {
|
|
160
|
+
case 'render':
|
|
161
|
+
return this.leaf.__world
|
|
162
|
+
case 'content':
|
|
163
|
+
if (this.contentBounds) return this.getWorldContentBounds()
|
|
164
|
+
case 'margin':
|
|
165
|
+
case 'box':
|
|
166
|
+
return this.getWorldBoxBounds()
|
|
167
|
+
case 'margin':
|
|
168
|
+
case 'stroke':
|
|
169
|
+
return this.getWorldStrokeBounds()
|
|
170
|
+
}
|
|
171
|
+
}
|
|
116
172
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
173
|
+
public getLayoutBounds(type?: IBoundsType, relative: ILocationType | ILeaf = 'world', unscale?: boolean): ILayoutBoundsData {
|
|
174
|
+
const { leaf } = this
|
|
175
|
+
let point: IPointData, layout: ILayoutData
|
|
176
|
+
let bounds: IBoundsData = this.getInnerBounds(type)
|
|
177
|
+
|
|
178
|
+
switch (relative) {
|
|
179
|
+
case 'world':
|
|
180
|
+
point = leaf.getWorldPoint(bounds)
|
|
181
|
+
layout = leaf.__world
|
|
182
|
+
break
|
|
183
|
+
case 'local':
|
|
184
|
+
point = leaf.getLocalPointByInner(bounds)
|
|
185
|
+
layout = leaf.__ as ILayoutData
|
|
186
|
+
break
|
|
187
|
+
case 'inner':
|
|
188
|
+
point = bounds
|
|
189
|
+
layout = MatrixHelper.defaultWorld
|
|
190
|
+
break
|
|
191
|
+
default:
|
|
192
|
+
point = leaf.getWorldPoint(bounds, relative)
|
|
193
|
+
layout = leaf.__world
|
|
194
|
+
}
|
|
130
195
|
|
|
131
|
-
}
|
|
196
|
+
let { scaleX, scaleY, rotation, skewX, skewY } = layout
|
|
197
|
+
let { width, height } = bounds
|
|
132
198
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return this.localStrokeBounds
|
|
142
|
-
}
|
|
199
|
+
if (typeof relative === 'object') {
|
|
200
|
+
const r = relative.__world
|
|
201
|
+
scaleX /= r.scaleX
|
|
202
|
+
scaleY /= r.scaleY
|
|
203
|
+
rotation -= r.rotation
|
|
204
|
+
skewX -= r.skewX
|
|
205
|
+
skewY -= r.skewY
|
|
206
|
+
}
|
|
143
207
|
|
|
208
|
+
if (unscale) {
|
|
209
|
+
const uScaleX = scaleX < 0 ? -scaleX : scaleX
|
|
210
|
+
const uScaleY = scaleY < 0 ? -scaleY : scaleY
|
|
211
|
+
scaleX /= uScaleX
|
|
212
|
+
scaleY /= uScaleY
|
|
213
|
+
width *= uScaleX
|
|
214
|
+
height *= uScaleY
|
|
144
215
|
}
|
|
145
216
|
|
|
217
|
+
return { x: point.x, y: point.y, scaleX, scaleY, rotation, skewX, skewY, width, height }
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public getLayoutPoints(type?: IBoundsType, relative: ILocationType | ILeaf = 'world'): IPointData[] {
|
|
221
|
+
const { leaf } = this
|
|
222
|
+
const points = getPoints(this.getInnerBounds(type))
|
|
223
|
+
let relativeLeaf: ILeaf
|
|
224
|
+
switch (relative) {
|
|
225
|
+
case 'world':
|
|
226
|
+
relativeLeaf = null
|
|
227
|
+
break
|
|
228
|
+
case 'local':
|
|
229
|
+
relativeLeaf = leaf.parent
|
|
230
|
+
break
|
|
231
|
+
case 'inner':
|
|
232
|
+
break
|
|
233
|
+
default:
|
|
234
|
+
relativeLeaf = relative
|
|
235
|
+
}
|
|
236
|
+
if (relativeLeaf !== undefined) points.forEach(point => leaf.innerToWorld(point, null, false, relativeLeaf))
|
|
237
|
+
return points
|
|
146
238
|
}
|
|
147
239
|
|
|
148
240
|
protected getWorldContentBounds(): IBoundsData {
|
|
@@ -168,7 +260,7 @@ export class LeafLayout implements ILeafLayout {
|
|
|
168
260
|
public spreadStrokeCancel(): void {
|
|
169
261
|
const same = this.renderBounds === this.strokeBounds
|
|
170
262
|
this.strokeBounds = this.boxBounds
|
|
171
|
-
this.localStrokeBounds = this.leaf.
|
|
263
|
+
this.localStrokeBounds = this.leaf.__localBounds
|
|
172
264
|
if (same) this.spreadRenderCancel()
|
|
173
265
|
}
|
|
174
266
|
public spreadRenderCancel(): void {
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeafLayout, ILeaf, IBoundsData,
|
|
1
|
+
import { ILeafLayout, ILeaf, IBoundsData, ILocationType, IMatrixData, IBoundsType, ILayoutBoundsData, IPointData } from '@leafer/interface';
|
|
2
2
|
|
|
3
3
|
declare class LeafLayout implements ILeafLayout {
|
|
4
4
|
leaf: ILeaf;
|
|
@@ -8,11 +8,13 @@ declare class LeafLayout implements ILeafLayout {
|
|
|
8
8
|
renderBounds: IBoundsData;
|
|
9
9
|
marginBounds: IBoundsData;
|
|
10
10
|
contentBounds: IBoundsData;
|
|
11
|
-
localStrokeBounds
|
|
12
|
-
localRenderBounds
|
|
11
|
+
localStrokeBounds?: IBoundsData;
|
|
12
|
+
localRenderBounds?: IBoundsData;
|
|
13
13
|
protected _worldContentBounds: IBoundsData;
|
|
14
14
|
protected _worldBoxBounds: IBoundsData;
|
|
15
15
|
protected _worldStrokeBounds: IBoundsData;
|
|
16
|
+
resized: boolean;
|
|
17
|
+
waitAutoLayout: boolean;
|
|
16
18
|
matrixChanged: boolean;
|
|
17
19
|
scaleChanged: boolean;
|
|
18
20
|
rotationChanged: boolean;
|
|
@@ -32,10 +34,21 @@ declare class LeafLayout implements ILeafLayout {
|
|
|
32
34
|
renderSpread: number;
|
|
33
35
|
strokeBoxSpread: number;
|
|
34
36
|
renderShapeSpread: number;
|
|
37
|
+
get a(): number;
|
|
38
|
+
get b(): number;
|
|
39
|
+
get c(): number;
|
|
40
|
+
get d(): number;
|
|
41
|
+
get e(): number;
|
|
42
|
+
get f(): number;
|
|
35
43
|
constructor(leaf: ILeaf);
|
|
36
|
-
|
|
37
|
-
getTransform(
|
|
38
|
-
getBounds(type
|
|
44
|
+
update(): void;
|
|
45
|
+
getTransform(relative?: ILocationType | ILeaf): IMatrixData;
|
|
46
|
+
getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData;
|
|
47
|
+
getInnerBounds(type?: IBoundsType): IBoundsData;
|
|
48
|
+
getLocalBounds(type?: IBoundsType): IBoundsData;
|
|
49
|
+
getWorldBounds(type?: IBoundsType): IBoundsData;
|
|
50
|
+
getLayoutBounds(type?: IBoundsType, relative?: ILocationType | ILeaf, unscale?: boolean): ILayoutBoundsData;
|
|
51
|
+
getLayoutPoints(type?: IBoundsType, relative?: ILocationType | ILeaf): IPointData[];
|
|
39
52
|
protected getWorldContentBounds(): IBoundsData;
|
|
40
53
|
protected getWorldBoxBounds(): IBoundsData;
|
|
41
54
|
protected getWorldStrokeBounds(): IBoundsData;
|