@leafer/layout 1.0.0-alpha.23 → 1.0.0-alpha.31

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/LeafLayout.ts +28 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/layout",
3
- "version": "1.0.0-alpha.23",
3
+ "version": "1.0.0-alpha.31",
4
4
  "description": "@leafer/layout",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -19,9 +19,9 @@
19
19
  "leaferjs"
20
20
  ],
21
21
  "dependencies": {
22
- "@leafer/math": "1.0.0-alpha.23"
22
+ "@leafer/math": "1.0.0-alpha.31"
23
23
  },
24
24
  "devDependencies": {
25
- "@leafer/interface": "1.0.0-alpha.23"
25
+ "@leafer/interface": "1.0.0-alpha.31"
26
26
  }
27
27
  }
package/src/LeafLayout.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ILeaf, ILeafLayout, ILayoutLocationType, ILayoutBoundsType, IBoundsData, IMatrixData, IMatrixDecompositionData } from '@leafer/interface'
2
2
  import { BoundsHelper, MatrixHelper } from '@leafer/math'
3
+ import { Platform } from '@leafer/platform'
3
4
 
4
5
 
5
6
  const { toOuterOf } = BoundsHelper
@@ -26,6 +27,7 @@ export class LeafLayout implements ILeafLayout {
26
27
  public localRenderBounds: IBoundsData
27
28
 
28
29
  // world temp
30
+ protected _worldContentBounds: IBoundsData
29
31
  protected _worldBoxBounds: IBoundsData
30
32
  protected _worldStrokeBounds: IBoundsData
31
33
 
@@ -57,9 +59,11 @@ export class LeafLayout implements ILeafLayout {
57
59
  // keep state
58
60
  public affectScaleOrRotation: boolean
59
61
  public affectRotation: boolean
62
+
60
63
  public strokeBoundsSpreadWidth: number
61
64
  public renderBoundsSpreadWidth: number
62
- public renderShapeBoundsSpreadWidth: number
65
+ public shapeStrokeSpreadWidth: number
66
+ public shapeRenderSpreadWidth: number
63
67
 
64
68
 
65
69
  constructor(leaf: ILeaf) {
@@ -70,7 +74,7 @@ export class LeafLayout implements ILeafLayout {
70
74
  }
71
75
 
72
76
 
73
- public update(): void {
77
+ public checkUpdate(): void {
74
78
  const { leafer } = this.leaf
75
79
  if (leafer) {
76
80
  if (leafer.ready) {
@@ -79,30 +83,38 @@ export class LeafLayout implements ILeafLayout {
79
83
  leafer.start()
80
84
  leafer.layouter.layout()
81
85
  }
86
+ } else {
87
+ let root = this.leaf
88
+ while (root.parent) { root = root.parent }
89
+ Platform.layout(root)
82
90
  }
83
91
  }
84
92
 
85
93
  public getTransform(locationType: ILayoutLocationType): IMatrixData {
86
- this.update()
94
+ this.checkUpdate()
87
95
  return locationType === 'world' ? this.leaf.__world : this.leaf.__local
88
96
  }
89
97
 
90
98
  public getMatrixDecompositionData(locationType: ILayoutLocationType): IMatrixDecompositionData {
91
- this.update()
99
+ this.checkUpdate()
92
100
  return MatrixHelper.decompose(locationType === 'world' ? this.leaf.__world : this.leaf.__local)
93
101
  }
94
102
 
95
103
  public getBounds(type: ILayoutBoundsType, locationType: ILayoutLocationType): IBoundsData {
96
104
 
97
- this.update()
105
+ this.checkUpdate()
98
106
 
99
107
  if (locationType === 'world') {
100
108
 
101
109
  switch (type) {
102
110
  case 'render':
103
111
  return this.leaf.__world
112
+ case 'content':
113
+ if (this.contentBounds) return this.getWorldContentBounds()
114
+ case 'margin':
104
115
  case 'box':
105
116
  return this.getWorldBoxBounds()
117
+ case 'margin':
106
118
  case 'stroke':
107
119
  return this.getWorldStrokeBounds()
108
120
  }
@@ -112,6 +124,9 @@ export class LeafLayout implements ILeafLayout {
112
124
  switch (type) {
113
125
  case 'render':
114
126
  return this.renderBounds
127
+ case 'content':
128
+ if (this.contentBounds) return this.contentBounds
129
+ case 'margin':
115
130
  case 'box':
116
131
  return this.boxBounds
117
132
  case 'stroke':
@@ -123,6 +138,8 @@ export class LeafLayout implements ILeafLayout {
123
138
  switch (type) {
124
139
  case 'render':
125
140
  return this.localRenderBounds
141
+ case 'margin':
142
+ case 'content':
126
143
  case 'box':
127
144
  return this.leaf.__local
128
145
  case 'stroke':
@@ -131,9 +148,13 @@ export class LeafLayout implements ILeafLayout {
131
148
 
132
149
  }
133
150
 
134
- return this.leaf.__world
135
151
  }
136
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
+ }
137
158
 
138
159
  protected getWorldBoxBounds(): IBoundsData {
139
160
  this._worldBoxBounds || (this._worldBoxBounds = {} as IBoundsData)
@@ -190,6 +211,7 @@ export class LeafLayout implements ILeafLayout {
190
211
  this.strokeBoundsChanged = true
191
212
  this.strokeBoundsSpreadWidth || (this.strokeBoundsSpreadWidth = 1)
192
213
  this.boundsChanged = true
214
+ this.hitCanvasChanged = true
193
215
  }
194
216
 
195
217
  public renderBoundsChange(): void {