@leafer/layouter 1.0.0-rc.6 → 1.0.0-rc.8

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/layouter",
3
- "version": "1.0.0-rc.6",
3
+ "version": "1.0.0-rc.8",
4
4
  "description": "@leafer/canvas",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,9 +22,9 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.0.0-rc.6"
25
+ "@leafer/core": "1.0.0-rc.8"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.6"
28
+ "@leafer/interface": "1.0.0-rc.8"
29
29
  }
30
30
  }
@@ -1,9 +1,9 @@
1
1
  import { IBounds, ILayoutBlockData, ILeafList, ILeaf } from '@leafer/interface'
2
- import { Bounds, BoundsHelper, LeafBoundsHelper, LeafList } from '@leafer/core'
2
+ import { Bounds, LeafBoundsHelper, LeafList } from '@leafer/core'
3
3
 
4
4
 
5
5
  const { worldBounds } = LeafBoundsHelper
6
- const { setByListWithHandle } = BoundsHelper
6
+ const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 }
7
7
 
8
8
  export class LayoutBlockData implements ILayoutBlockData {
9
9
 
@@ -19,16 +19,22 @@ export class LayoutBlockData implements ILayoutBlockData {
19
19
  }
20
20
 
21
21
  public setBefore(): void {
22
- setByListWithHandle(this.beforeBounds, this.updatedList.list, worldBounds)
22
+ this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds)
23
23
  }
24
24
 
25
25
  public setAfter(): void {
26
- setByListWithHandle(this.afterBounds, this.updatedList.list, worldBounds)
27
- this.updatedBounds.setByList([this.beforeBounds, this.afterBounds])
26
+ const { list } = this.updatedList
27
+ if (list.some(leaf => leaf.noBounds)) {
28
+ this.afterBounds.set(bigBounds)
29
+ } else {
30
+ this.afterBounds.setListWithFn(list, worldBounds)
31
+ }
32
+
33
+ this.updatedBounds.setList([this.beforeBounds, this.afterBounds])
28
34
  }
29
35
 
30
36
  public merge(data: ILayoutBlockData): void {
31
- this.updatedList.pushList(data.updatedList.list)
37
+ this.updatedList.addList(data.updatedList.list)
32
38
  this.beforeBounds.add(data.beforeBounds)
33
39
  this.afterBounds.add(data.afterBounds)
34
40
  this.updatedBounds.add(data.updatedBounds)
package/src/Layouter.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { ILayouter, ILeaf, ILayoutBlockData, IEventListenerId, ILayouterConfig, ILeafList } from '@leafer/interface'
2
2
  import { LayoutEvent, WatchEvent, LeafLevelList, LeafList, BranchHelper, LeafHelper, DataHelper, Run, Debug } from '@leafer/core'
3
3
 
4
- import { updateBounds, updateMatrix, updateChange } from './LayouterHelper'
4
+ import { updateMatrix, updateBounds, updateChange } from './LayouterHelper'
5
5
  import { LayoutBlockData } from './LayoutBlockData'
6
6
 
7
7
 
8
- const { updateAllWorldMatrix, updateAllChange } = LeafHelper
9
- const { pushAllBranchStack, updateWorldBoundsByBranchStack } = BranchHelper
8
+ const { updateAllMatrix, updateAllChange } = LeafHelper
10
9
 
11
10
  const debug = Debug.get('Layouter')
12
11
 
@@ -14,6 +13,7 @@ export class Layouter implements ILayouter {
14
13
 
15
14
  public target: ILeaf
16
15
  public layoutedBlocks: ILayoutBlockData[]
16
+ public extraBlock: ILayoutBlockData // around / autoLayout
17
17
 
18
18
  public totalTimes: number = 0
19
19
  public times: number
@@ -76,7 +76,6 @@ export class Layouter implements ILayouter {
76
76
  }
77
77
 
78
78
  public layoutOnce(): void {
79
-
80
79
  if (this.layouting) return debug.warn('layouting')
81
80
  if (this.times > 3) return debug.warn('layout max times')
82
81
 
@@ -99,7 +98,6 @@ export class Layouter implements ILayouter {
99
98
  this.waitAgain = false
100
99
  this.layoutOnce()
101
100
  }
102
-
103
101
  }
104
102
 
105
103
  public partLayout(): void {
@@ -110,14 +108,16 @@ export class Layouter implements ILayouter {
110
108
  const { BEFORE, LAYOUT, AFTER } = LayoutEvent
111
109
 
112
110
  const blocks = this.getBlocks(updateList)
113
- blocks.forEach(item => { item.setBefore() })
111
+ blocks.forEach(item => item.setBefore())
114
112
  target.emitEvent(new LayoutEvent(BEFORE, blocks, this.times))
115
113
 
114
+ this.extraBlock = null
116
115
  updateList.sort()
117
116
  updateMatrix(updateList, this.__levelList)
118
117
  updateBounds(this.__levelList)
119
118
  updateChange(updateList)
120
119
 
120
+ if (this.extraBlock) blocks.push(this.extraBlock)
121
121
  blocks.forEach(item => item.setAfter())
122
122
 
123
123
  target.emitEvent(new LayoutEvent(LAYOUT, blocks, this.times))
@@ -128,7 +128,6 @@ export class Layouter implements ILayouter {
128
128
  this.__levelList.reset()
129
129
  this.__updatedList = null
130
130
  Run.end(t)
131
-
132
131
  }
133
132
 
134
133
  public fullLayout(): void {
@@ -149,23 +148,25 @@ export class Layouter implements ILayouter {
149
148
  this.addBlocks(blocks)
150
149
 
151
150
  Run.end(t)
152
-
153
151
  }
154
152
 
155
153
  static fullLayout(target: ILeaf): void {
156
- updateAllWorldMatrix(target)
154
+ updateAllMatrix(target, true)
157
155
 
158
156
  if (target.isBranch) {
159
- const branchStack: ILeaf[] = [target]
160
- pushAllBranchStack(target, branchStack)
161
- updateWorldBoundsByBranchStack(branchStack)
157
+ BranchHelper.updateBounds(target)
162
158
  } else {
163
- target.__updateWorldBounds()
159
+ LeafHelper.updateBounds(target)
164
160
  }
165
161
 
166
162
  updateAllChange(target)
167
163
  }
168
164
 
165
+ public addExtra(leaf: ILeaf): void {
166
+ const block = this.extraBlock || (this.extraBlock = new LayoutBlockData([]))
167
+ block.updatedList.add(leaf)
168
+ block.beforeBounds.add(leaf.__world)
169
+ }
169
170
 
170
171
  public createBlock(data: ILeafList | ILeaf[]): ILayoutBlockData {
171
172
  return new LayoutBlockData(data)
@@ -200,8 +201,7 @@ export class Layouter implements ILayouter {
200
201
  if (this.target) {
201
202
  this.stop()
202
203
  this.__removeListenEvents()
203
- this.target = null
204
- this.config = null
204
+ this.target = this.config = null
205
205
  }
206
206
  }
207
207
 
@@ -1,8 +1,8 @@
1
- import { ILeaf, ILeafLayout, ILeafLevelList, ILeafList } from '@leafer/interface'
1
+ import { ILeafLayout, ILeafLevelList, ILeafList, ILeaf } from '@leafer/interface'
2
2
  import { BranchHelper, LeafHelper } from '@leafer/core'
3
3
 
4
4
 
5
- const { updateAllWorldMatrix, updateAllWorldOpacity } = LeafHelper
5
+ const { updateAllMatrix, updateBounds: updateOneBounds, updateAllWorldOpacity } = LeafHelper
6
6
  const { pushAllChildBranch, pushAllParent } = BranchHelper
7
7
 
8
8
 
@@ -15,15 +15,15 @@ export function updateMatrix(updateList: ILeafList, levelList: ILeafLevelList):
15
15
 
16
16
  if (layout.matrixChanged) {
17
17
 
18
- updateAllWorldMatrix(leaf)
18
+ updateAllMatrix(leaf, true)
19
19
 
20
- levelList.push(leaf)
20
+ levelList.add(leaf)
21
21
  if (leaf.isBranch) pushAllChildBranch(leaf, levelList)
22
22
  pushAllParent(leaf, levelList)
23
23
 
24
24
  } else if (layout.boundsChanged) {
25
25
 
26
- levelList.push(leaf)
26
+ levelList.add(leaf)
27
27
  if (leaf.isBranch) leaf.__tempNumber = 0 // 标识需要更新子Leaf元素的WorldBounds分支, 0表示不需要更新
28
28
  pushAllParent(leaf, levelList)
29
29
  }
@@ -32,30 +32,26 @@ export function updateMatrix(updateList: ILeafList, levelList: ILeafLevelList):
32
32
 
33
33
  }
34
34
 
35
-
36
35
  export function updateBounds(boundsList: ILeafLevelList): void {
37
-
38
- let itemList: ILeaf[], branch: ILeaf
36
+ let list: ILeaf[], branch: ILeaf, children: ILeaf[]
39
37
  boundsList.sort(true)
40
38
  boundsList.levels.forEach(level => {
41
- itemList = boundsList.levelMap[level]
42
- for (let i = 0, len = itemList.length; i < len; i++) {
43
- branch = itemList[i]
39
+ list = boundsList.levelMap[level]
40
+ for (let i = 0, len = list.length; i < len; i++) {
41
+ branch = list[i]
44
42
 
45
43
  // 标识了需要更新子元素
46
44
  if (branch.isBranch && branch.__tempNumber) {
47
- for (let j = 0, jLen = branch.children.length; j < jLen; j++) {
48
- if (!branch.children[j].isBranch) {
49
- branch.children[j].__updateWorldBounds()
45
+ children = branch.children
46
+ for (let j = 0, jLen = children.length; j < jLen; j++) {
47
+ if (!children[j].isBranch) {
48
+ updateOneBounds(children[j])
50
49
  }
51
50
  }
52
51
  }
53
-
54
- branch.__updateWorldBounds()
55
-
52
+ updateOneBounds(branch)
56
53
  }
57
54
  })
58
-
59
55
  }
60
56
 
61
57
 
package/types/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import { LeafLevelList, WatchEvent } from '@leafer/core';
4
4
  declare class Layouter implements ILayouter {
5
5
  target: ILeaf;
6
6
  layoutedBlocks: ILayoutBlockData[];
7
+ extraBlock: ILayoutBlockData;
7
8
  totalTimes: number;
8
9
  times: number;
9
10
  disabled: boolean;
@@ -24,6 +25,7 @@ declare class Layouter implements ILayouter {
24
25
  partLayout(): void;
25
26
  fullLayout(): void;
26
27
  static fullLayout(target: ILeaf): void;
28
+ addExtra(leaf: ILeaf): void;
27
29
  createBlock(data: ILeafList | ILeaf[]): ILayoutBlockData;
28
30
  getBlocks(list: ILeafList): ILayoutBlockData[];
29
31
  addBlocks(current: ILayoutBlockData[]): void;