@leafer/layout 1.0.0-rc.22 → 1.0.0-rc.24

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/layout",
3
- "version": "1.0.0-rc.22",
3
+ "version": "1.0.0-rc.24",
4
4
  "description": "@leafer/layout",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/math": "1.0.0-rc.22",
26
- "@leafer/helper": "1.0.0-rc.22",
27
- "@leafer/platform": "1.0.0-rc.22"
25
+ "@leafer/math": "1.0.0-rc.24",
26
+ "@leafer/helper": "1.0.0-rc.24",
27
+ "@leafer/platform": "1.0.0-rc.24"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "1.0.0-rc.22"
30
+ "@leafer/interface": "1.0.0-rc.24"
31
31
  }
32
32
  }
package/src/LeafLayout.ts CHANGED
@@ -6,6 +6,8 @@ import { Platform } from '@leafer/platform'
6
6
 
7
7
  const { getRelativeWorld } = LeafHelper
8
8
  const { toOuterOf, getPoints, copy } = BoundsHelper
9
+ const localContent = '_localContentBounds'
10
+ const worldContent = '_worldContentBounds', worldBox = '_worldBoxBounds', worldStroke = '_worldStrokeBounds'
9
11
 
10
12
  export class LeafLayout implements ILeafLayout {
11
13
 
@@ -15,26 +17,34 @@ export class LeafLayout implements ILeafLayout {
15
17
 
16
18
  // inner
17
19
 
20
+ public get contentBounds(): IBoundsData { return this._contentBounds || this.boxBounds }
21
+ public set contentBounds(bounds: IBoundsData) { this._contentBounds = bounds }
18
22
  public boxBounds: IBoundsData
19
23
  public get strokeBounds(): IBoundsData { return this._strokeBounds || this.boxBounds }
20
24
  public get renderBounds(): IBoundsData { return this._renderBounds || this.boxBounds }
21
25
 
26
+ public _contentBounds: IBoundsData
22
27
  public _strokeBounds: IBoundsData
23
28
  public _renderBounds: IBoundsData
24
29
 
25
- // auto layout
26
- public marginBounds: IBoundsData
27
- public contentBounds: IBoundsData
28
-
29
30
  // local
30
31
 
32
+ public get localContentBounds(): IBoundsData { toOuterOf(this.contentBounds, this.leaf.__localMatrix, this[localContent] || (this[localContent] = {} as IBoundsData)); return this[localContent] }
33
+ // localBoxBounds: IBoundsData // use leaf.__localBoxBounds
31
34
  public get localStrokeBounds(): IBoundsData { return this._localStrokeBounds || this }
32
35
  public get localRenderBounds(): IBoundsData { return this._localRenderBounds || this }
33
36
 
37
+ protected _localContentBounds?: IBoundsData
34
38
  protected _localStrokeBounds?: IBoundsData
35
39
  protected _localRenderBounds?: IBoundsData
36
40
 
37
- // world temp
41
+ // world
42
+
43
+ public get worldContentBounds(): IBoundsData { toOuterOf(this.contentBounds, this.leaf.__world, this[worldContent] || (this[worldContent] = {} as IBoundsData)); return this[worldContent] }
44
+ public get worldBoxBounds(): IBoundsData { toOuterOf(this.boxBounds, this.leaf.__world, this[worldBox] || (this[worldBox] = {} as IBoundsData)); return this[worldBox] }
45
+ public get worldStrokeBounds(): IBoundsData { toOuterOf(this.strokeBounds, this.leaf.__world, this[worldStroke] || (this[worldStroke] = {} as IBoundsData)); return this[worldStroke] }
46
+ // worldRenderBounds: IBoundsData // use leaf.__world
47
+
38
48
  protected _worldContentBounds: IBoundsData
39
49
  protected _worldBoxBounds: IBoundsData
40
50
  protected _worldStrokeBounds: IBoundsData
@@ -72,8 +82,8 @@ export class LeafLayout implements ILeafLayout {
72
82
  public affectChildrenSort?: boolean
73
83
 
74
84
  public strokeSpread: number
75
- public renderSpread: number
76
85
  public strokeBoxSpread: number
86
+ public renderSpread: number
77
87
  public renderShapeSpread: number
78
88
 
79
89
  // temp local
@@ -157,7 +167,6 @@ export class LeafLayout implements ILeafLayout {
157
167
  return this.renderBounds
158
168
  case 'content':
159
169
  if (this.contentBounds) return this.contentBounds
160
- case 'margin':
161
170
  case 'box':
162
171
  return this.boxBounds
163
172
  case 'stroke':
@@ -171,8 +180,8 @@ export class LeafLayout implements ILeafLayout {
171
180
  return this.localRenderBounds
172
181
  case 'stroke':
173
182
  return this.localStrokeBounds
174
- case 'margin':
175
183
  case 'content':
184
+ if (this.contentBounds) return this.localContentBounds
176
185
  case 'box':
177
186
  return this.leaf.__localBoxBounds
178
187
  }
@@ -182,14 +191,12 @@ export class LeafLayout implements ILeafLayout {
182
191
  switch (type) {
183
192
  case 'render':
184
193
  return this.leaf.__world
194
+ case 'stroke':
195
+ return this.worldStrokeBounds
185
196
  case 'content':
186
- if (this.contentBounds) return this.getWorldContentBounds()
187
- case 'margin':
197
+ if (this.contentBounds) return this.worldContentBounds
188
198
  case 'box':
189
- return this.getWorldBoxBounds()
190
- case 'margin':
191
- case 'stroke':
192
- return this.getWorldStrokeBounds()
199
+ return this.worldBoxBounds
193
200
  }
194
201
  }
195
202
 
@@ -258,25 +265,28 @@ export class LeafLayout implements ILeafLayout {
258
265
  return points
259
266
  }
260
267
 
261
- protected getWorldContentBounds(): IBoundsData {
262
- this._worldContentBounds || (this._worldContentBounds = {} as IBoundsData)
263
- toOuterOf(this.contentBounds, this.leaf.__world, this._worldContentBounds)
264
- return this._worldContentBounds
265
- }
268
+ // 独立 / 引用 boxBounds
266
269
 
267
- protected getWorldBoxBounds(): IBoundsData {
268
- this._worldBoxBounds || (this._worldBoxBounds = {} as IBoundsData)
269
- toOuterOf(this.boxBounds, this.leaf.__world, this._worldBoxBounds)
270
- return this._worldBoxBounds
270
+ public shrinkContent(): void {
271
+ const { x, y, width, height } = this.boxBounds
272
+ this._contentBounds = { x, y, width, height }
271
273
  }
272
274
 
273
- protected getWorldStrokeBounds(): IBoundsData {
274
- this._worldStrokeBounds || (this._worldStrokeBounds = {} as IBoundsData)
275
- toOuterOf(this.strokeBounds, this.leaf.__world, this._worldStrokeBounds)
276
- return this._worldStrokeBounds
275
+ public spreadStroke(): void {
276
+ const { x, y, width, height } = this.strokeBounds
277
+ this._strokeBounds = { x, y, width, height }
278
+ this._localStrokeBounds = { x, y, width, height }
279
+ if (!this.renderSpread) this.spreadRenderCancel()
280
+ }
281
+ public spreadRender(): void {
282
+ const { x, y, width, height } = this.renderBounds
283
+ this._renderBounds = { x, y, width, height }
284
+ this._localRenderBounds = { x, y, width, height }
277
285
  }
278
286
 
279
- // 独立 / 引用 boxBounds
287
+ public shrinkContentCancel(): void {
288
+ this._contentBounds = undefined
289
+ }
280
290
 
281
291
  public spreadStrokeCancel(): void {
282
292
  const same = this.renderBounds === this.strokeBounds
@@ -289,18 +299,6 @@ export class LeafLayout implements ILeafLayout {
289
299
  this._localRenderBounds = this._localStrokeBounds
290
300
  }
291
301
 
292
- public spreadStroke(): void {
293
- const { x, y, width, height } = this.strokeBounds
294
- this._strokeBounds = { x, y, width, height }
295
- this._localStrokeBounds = { x, y, width, height }
296
- if (!this.renderSpread) this.spreadRenderCancel()
297
- }
298
- public spreadRender(): void {
299
- const { x, y, width, height } = this.renderBounds
300
- this._renderBounds = { x, y, width, height }
301
- this._localRenderBounds = { x, y, width, height }
302
- }
303
-
304
302
 
305
303
  // bounds
306
304
 
package/types/index.d.ts CHANGED
@@ -3,17 +3,23 @@ import { ILeafLayout, ILeaf, IBoundsData, ILocationType, IMatrixData, IBoundsTyp
3
3
  declare class LeafLayout implements ILeafLayout {
4
4
  leaf: ILeaf;
5
5
  proxyZoom: boolean;
6
+ get contentBounds(): IBoundsData;
7
+ set contentBounds(bounds: IBoundsData);
6
8
  boxBounds: IBoundsData;
7
9
  get strokeBounds(): IBoundsData;
8
10
  get renderBounds(): IBoundsData;
11
+ _contentBounds: IBoundsData;
9
12
  _strokeBounds: IBoundsData;
10
13
  _renderBounds: IBoundsData;
11
- marginBounds: IBoundsData;
12
- contentBounds: IBoundsData;
14
+ get localContentBounds(): IBoundsData;
13
15
  get localStrokeBounds(): IBoundsData;
14
16
  get localRenderBounds(): IBoundsData;
17
+ protected _localContentBounds?: IBoundsData;
15
18
  protected _localStrokeBounds?: IBoundsData;
16
19
  protected _localRenderBounds?: IBoundsData;
20
+ get worldContentBounds(): IBoundsData;
21
+ get worldBoxBounds(): IBoundsData;
22
+ get worldStrokeBounds(): IBoundsData;
17
23
  protected _worldContentBounds: IBoundsData;
18
24
  protected _worldBoxBounds: IBoundsData;
19
25
  protected _worldStrokeBounds: IBoundsData;
@@ -35,8 +41,8 @@ declare class LeafLayout implements ILeafLayout {
35
41
  affectRotation: boolean;
36
42
  affectChildrenSort?: boolean;
37
43
  strokeSpread: number;
38
- renderSpread: number;
39
44
  strokeBoxSpread: number;
45
+ renderSpread: number;
40
46
  renderShapeSpread: number;
41
47
  get a(): number;
42
48
  get b(): number;
@@ -58,13 +64,12 @@ declare class LeafLayout implements ILeafLayout {
58
64
  getWorldBounds(type?: IBoundsType): IBoundsData;
59
65
  getLayoutBounds(type?: IBoundsType, relative?: ILocationType | ILeaf, unscale?: boolean): ILayoutBoundsData;
60
66
  getLayoutPoints(type?: IBoundsType, relative?: ILocationType | ILeaf): IPointData[];
61
- protected getWorldContentBounds(): IBoundsData;
62
- protected getWorldBoxBounds(): IBoundsData;
63
- protected getWorldStrokeBounds(): IBoundsData;
64
- spreadStrokeCancel(): void;
65
- spreadRenderCancel(): void;
67
+ shrinkContent(): void;
66
68
  spreadStroke(): void;
67
69
  spreadRender(): void;
70
+ shrinkContentCancel(): void;
71
+ spreadStrokeCancel(): void;
72
+ spreadRenderCancel(): void;
68
73
  boxChange(): void;
69
74
  localBoxChange(): void;
70
75
  strokeChange(): void;