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

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 +68 -60
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/layout",
3
- "version": "1.0.0-alpha.21",
3
+ "version": "1.0.0-alpha.23",
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.21"
22
+ "@leafer/math": "1.0.0-alpha.23"
23
23
  },
24
24
  "devDependencies": {
25
- "@leafer/interface": "1.0.0-alpha.21"
25
+ "@leafer/interface": "1.0.0-alpha.23"
26
26
  }
27
27
  }
package/src/LeafLayout.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { ILeaf, ILeafLayout, ILayoutLocationType, ILayoutBoundsType, IBoundsData, IMatrixData, } from '@leafer/interface'
2
- import { BoundsHelper } from '@leafer/math'
1
+ import { ILeaf, ILeafLayout, ILayoutLocationType, ILayoutBoundsType, IBoundsData, IMatrixData, IMatrixDecompositionData } from '@leafer/interface'
2
+ import { BoundsHelper, MatrixHelper } from '@leafer/math'
3
3
 
4
4
 
5
- const { toWorld } = BoundsHelper
5
+ const { toOuterOf } = BoundsHelper
6
6
 
7
7
  export class LeafLayout implements ILeafLayout {
8
8
 
@@ -12,38 +12,36 @@ export class LeafLayout implements ILeafLayout {
12
12
 
13
13
  // local
14
14
 
15
- public boxBounds: IBoundsData // | content + padding |
16
- public eventBounds: IBoundsData // | boxBounds + border |
17
- public renderBounds: IBoundsData // | eventBounds + shadow |
15
+ public boxBounds: IBoundsData
16
+ public strokeBounds: IBoundsData
17
+ public renderBounds: IBoundsData
18
18
 
19
19
  // auto layout
20
- public marginBounds: IBoundsData // | eventBounds + margin |
21
- public contentBounds: IBoundsData // | content |
20
+ public marginBounds: IBoundsData
21
+ public contentBounds: IBoundsData
22
22
 
23
- // relative
23
+ // local
24
24
 
25
- //relativeBoxBounds: IBoundsData = leaf.__relative
26
- public relativeEventBounds: IBoundsData
27
- public relativeRenderBounds: IBoundsData
25
+ public localStrokeBounds: IBoundsData
26
+ public localRenderBounds: IBoundsData
28
27
 
29
28
  // world temp
30
29
  protected _worldBoxBounds: IBoundsData
31
- protected _worldEventBounds: IBoundsData
32
- // worldRenderBounds: IBoundsData = leaf.__world
30
+ protected _worldStrokeBounds: IBoundsData
33
31
 
34
32
  // state
35
33
 
36
34
  // matrix changed
37
- public matrixChanged: boolean // include positionChanged scaleChanged skewChanged
38
- public positionChanged: boolean // x, y
39
- public scaleChanged: boolean // scaleX scaleY
40
- public rotationChanged: boolean // rotaiton, skewX scaleY
35
+ public matrixChanged: boolean
36
+ public positionChanged: boolean
37
+ public scaleChanged: boolean
38
+ public rotationChanged: boolean
41
39
 
42
40
  // bounds
43
41
  public boundsChanged: boolean
44
42
 
45
43
  public boxBoundsChanged: boolean
46
- public eventBoundsChanged: boolean
44
+ public strokeBoundsChanged: boolean
47
45
  public renderBoundsChanged: boolean
48
46
 
49
47
  public localBoxBoundsChanged: boolean
@@ -59,109 +57,119 @@ export class LeafLayout implements ILeafLayout {
59
57
  // keep state
60
58
  public affectScaleOrRotation: boolean
61
59
  public affectRotation: boolean
62
- public eventBoundsSpreadWidth: number
60
+ public strokeBoundsSpreadWidth: number
63
61
  public renderBoundsSpreadWidth: number
64
62
  public renderShapeBoundsSpreadWidth: number
65
63
 
66
64
 
67
65
  constructor(leaf: ILeaf) {
68
66
  this.leaf = leaf
69
- this.renderBounds = this.eventBounds = this.boxBounds = { x: 0, y: 0, width: 0, height: 0 }
70
- this.relativeRenderBounds = this.relativeEventBounds = leaf.__relative
67
+ this.renderBounds = this.strokeBounds = this.boxBounds = { x: 0, y: 0, width: 0, height: 0 }
68
+ this.localRenderBounds = this.localStrokeBounds = leaf.__local
71
69
  this.boxBoundsChange()
72
70
  }
73
71
 
74
72
 
75
73
  public update(): void {
76
74
  const { leafer } = this.leaf
77
- if (leafer && leafer.watcher.changed) {
78
- if (!leafer.running) leafer.start()
79
- leafer.layouter.layout()
75
+ if (leafer) {
76
+ if (leafer.ready) {
77
+ if (leafer.watcher.changed) leafer.layouter.layout()
78
+ } else {
79
+ leafer.start()
80
+ leafer.layouter.layout()
81
+ }
80
82
  }
81
83
  }
82
84
 
83
- public getTransform(type: ILayoutLocationType): IMatrixData {
85
+ public getTransform(locationType: ILayoutLocationType): IMatrixData {
86
+ this.update()
87
+ return locationType === 'world' ? this.leaf.__world : this.leaf.__local
88
+ }
89
+
90
+ public getMatrixDecompositionData(locationType: ILayoutLocationType): IMatrixDecompositionData {
84
91
  this.update()
85
- return type === 'world' ? this.leaf.__world : this.leaf.__relative
92
+ return MatrixHelper.decompose(locationType === 'world' ? this.leaf.__world : this.leaf.__local)
86
93
  }
87
94
 
88
- public getBounds(type: ILayoutLocationType, boundsType: ILayoutBoundsType): IBoundsData {
95
+ public getBounds(type: ILayoutBoundsType, locationType: ILayoutLocationType): IBoundsData {
89
96
 
90
97
  this.update()
91
98
 
92
- if (type === 'world') {
99
+ if (locationType === 'world') {
93
100
 
94
- switch (boundsType) {
101
+ switch (type) {
95
102
  case 'render':
96
103
  return this.leaf.__world
97
104
  case 'box':
98
105
  return this.getWorldBoxBounds()
99
- case 'event':
100
- return this.getWorldEventBounds()
106
+ case 'stroke':
107
+ return this.getWorldStrokeBounds()
101
108
  }
102
109
 
103
- } else if (type === 'local') {
110
+ } else if (locationType === 'inner') {
104
111
 
105
- switch (boundsType) {
112
+ switch (type) {
106
113
  case 'render':
107
114
  return this.renderBounds
108
115
  case 'box':
109
116
  return this.boxBounds
110
- case 'event':
111
- return this.eventBounds
117
+ case 'stroke':
118
+ return this.strokeBounds
112
119
  }
113
120
 
114
121
  } else {
115
122
 
116
- switch (boundsType) {
123
+ switch (type) {
117
124
  case 'render':
118
- return this.relativeRenderBounds
125
+ return this.localRenderBounds
119
126
  case 'box':
120
- return this.leaf.__relative
121
- case 'event':
122
- return this.relativeEventBounds
127
+ return this.leaf.__local
128
+ case 'stroke':
129
+ return this.localStrokeBounds
123
130
  }
124
131
 
125
132
  }
133
+
126
134
  return this.leaf.__world
127
135
  }
128
136
 
129
137
 
130
138
  protected getWorldBoxBounds(): IBoundsData {
131
139
  this._worldBoxBounds || (this._worldBoxBounds = {} as IBoundsData)
132
- toWorld(this.boxBounds, this.leaf.__world, this._worldBoxBounds)
140
+ toOuterOf(this.boxBounds, this.leaf.__world, this._worldBoxBounds)
133
141
  return this._worldBoxBounds
134
142
  }
135
143
 
136
- protected getWorldEventBounds(): IBoundsData {
137
- this._worldEventBounds || (this._worldEventBounds = {} as IBoundsData)
138
- toWorld(this.eventBounds, this.leaf.__world, this._worldEventBounds)
139
- return this._worldEventBounds
144
+ protected getWorldStrokeBounds(): IBoundsData {
145
+ this._worldStrokeBounds || (this._worldStrokeBounds = {} as IBoundsData)
146
+ toOuterOf(this.strokeBounds, this.leaf.__world, this._worldStrokeBounds)
147
+ return this._worldStrokeBounds
140
148
  }
141
149
 
142
150
  // 独立 / 引用 boxBounds
143
151
 
144
- public eventBoundsSpreadCancel(): void {
145
- const same = this.renderBounds === this.eventBounds
146
- this.eventBounds = this.boxBounds
147
- this.relativeEventBounds = this.leaf.__relative
152
+ public strokeBoundsSpreadCancel(): void {
153
+ const same = this.renderBounds === this.strokeBounds
154
+ this.strokeBounds = this.boxBounds
155
+ this.localStrokeBounds = this.leaf.__local
148
156
  if (same) this.renderBoundsSpreadCancel()
149
157
  }
150
158
  public renderBoundsSpreadCancel(): void {
151
- this.renderBounds = this.eventBounds
152
- this.relativeRenderBounds = this.relativeEventBounds
159
+ this.renderBounds = this.strokeBounds
160
+ this.localRenderBounds = this.localStrokeBounds
153
161
  }
154
162
 
155
- public eventBoundsSpread(): void {
156
- const { x, y, width, height } = this.eventBounds
157
- this.eventBounds = { x, y, width, height }
158
- this.relativeEventBounds = { x, y, width, height }
163
+ public strokeBoundsSpread(): void {
164
+ const { x, y, width, height } = this.strokeBounds
165
+ this.strokeBounds = { x, y, width, height }
166
+ this.localStrokeBounds = { x, y, width, height }
159
167
  if (!this.renderBoundsSpreadWidth) this.renderBoundsSpreadCancel()
160
168
  }
161
169
  public renderBoundsSpread(): void {
162
170
  const { x, y, width, height } = this.renderBounds
163
171
  this.renderBounds = { x, y, width, height }
164
- this.relativeRenderBounds = { x, y, width, height }
172
+ this.localRenderBounds = { x, y, width, height }
165
173
  }
166
174
 
167
175
 
@@ -178,9 +186,9 @@ export class LeafLayout implements ILeafLayout {
178
186
  this.boundsChanged = true
179
187
  }
180
188
 
181
- public eventBoundsChange(): void {
182
- this.eventBoundsChanged = true
183
- this.eventBoundsSpreadWidth || (this.eventBoundsSpreadWidth = 1)
189
+ public strokeBoundsChange(): void {
190
+ this.strokeBoundsChanged = true
191
+ this.strokeBoundsSpreadWidth || (this.strokeBoundsSpreadWidth = 1)
184
192
  this.boundsChanged = true
185
193
  }
186
194