@leafer/layout 1.0.0-beta.12 → 1.0.0-beta.15

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