@leafer/layouter 1.0.0-beta.9 → 1.0.0-rc.10

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,32 +1,30 @@
1
1
  {
2
2
  "name": "@leafer/layouter",
3
- "version": "1.0.0-beta.9",
4
- "description": "@leafer/canvas",
3
+ "version": "1.0.0-rc.10",
4
+ "description": "@leafer/layouter",
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
+ "src",
11
+ "types",
12
+ "dist"
10
13
  ],
11
14
  "repository": {
12
15
  "type": "git",
13
16
  "url": "https://github.com/leaferjs/leafer.git"
14
17
  },
15
- "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/canvas/canvas",
18
+ "homepage": "https://github.com/leaferjs/leafer/tree/main/packages/partner/layouter",
16
19
  "bugs": "https://github.com/leaferjs/leafer/issues",
17
20
  "keywords": [
18
21
  "leafer",
19
22
  "leaferjs"
20
23
  ],
21
24
  "dependencies": {
22
- "@leafer/event": "1.0.0-beta.9",
23
- "@leafer/math": "1.0.0-beta.9",
24
- "@leafer/list": "1.0.0-beta.9",
25
- "@leafer/data": "1.0.0-beta.9",
26
- "@leafer/helper": "1.0.0-beta.9",
27
- "@leafer/debug": "1.0.0-beta.9"
25
+ "@leafer/core": "1.0.0-rc.10"
28
26
  },
29
27
  "devDependencies": {
30
- "@leafer/interface": "1.0.0-beta.9"
28
+ "@leafer/interface": "1.0.0-rc.10"
31
29
  }
32
30
  }
@@ -1,11 +1,9 @@
1
1
  import { IBounds, ILayoutBlockData, ILeafList, ILeaf } from '@leafer/interface'
2
- import { Bounds, BoundsHelper } from '@leafer/math'
3
- import { LeafBoundsHelper } from '@leafer/helper'
4
- import { LeafList } from '@leafer/list'
2
+ import { Bounds, LeafBoundsHelper, LeafList } from '@leafer/core'
5
3
 
6
4
 
7
5
  const { worldBounds } = LeafBoundsHelper
8
- const { setByListWithHandle } = BoundsHelper
6
+ const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 }
9
7
 
10
8
  export class LayoutBlockData implements ILayoutBlockData {
11
9
 
@@ -21,16 +19,22 @@ export class LayoutBlockData implements ILayoutBlockData {
21
19
  }
22
20
 
23
21
  public setBefore(): void {
24
- setByListWithHandle(this.beforeBounds, this.updatedList.list, worldBounds)
22
+ this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds)
25
23
  }
26
24
 
27
25
  public setAfter(): void {
28
- setByListWithHandle(this.afterBounds, this.updatedList.list, worldBounds)
29
- 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])
30
34
  }
31
35
 
32
36
  public merge(data: ILayoutBlockData): void {
33
- this.updatedList.pushList(data.updatedList.list)
37
+ this.updatedList.addList(data.updatedList.list)
34
38
  this.beforeBounds.add(data.beforeBounds)
35
39
  this.afterBounds.add(data.afterBounds)
36
40
  this.updatedBounds.add(data.updatedBounds)
package/src/Layouter.ts CHANGED
@@ -1,16 +1,11 @@
1
1
  import { ILayouter, ILeaf, ILayoutBlockData, IEventListenerId, ILayouterConfig, ILeafList } from '@leafer/interface'
2
- import { LayoutEvent, WatchEvent } from '@leafer/event'
3
- import { LeafLevelList, LeafList } from '@leafer/list'
4
- import { BranchHelper, LeafHelper } from '@leafer/helper'
5
- import { DataHelper } from '@leafer/data'
6
- import { Run, Debug } from '@leafer/debug'
2
+ import { LayoutEvent, WatchEvent, LeafLevelList, LeafList, BranchHelper, LeafHelper, DataHelper, Run, Debug } from '@leafer/core'
7
3
 
8
- import { updateBounds, updateMatrix, updateChange } from './LayouterHelper'
4
+ import { updateMatrix, updateBounds, updateChange } from './LayouterHelper'
9
5
  import { LayoutBlockData } from './LayoutBlockData'
10
6
 
11
7
 
12
- const { updateAllWorldMatrix, updateAllChange } = LeafHelper
13
- const { pushAllBranchStack, updateWorldBoundsByBranchStack } = BranchHelper
8
+ const { updateAllMatrix, updateAllChange } = LeafHelper
14
9
 
15
10
  const debug = Debug.get('Layouter')
16
11
 
@@ -18,6 +13,7 @@ export class Layouter implements ILayouter {
18
13
 
19
14
  public target: ILeaf
20
15
  public layoutedBlocks: ILayoutBlockData[]
16
+ public extraBlock: ILayoutBlockData // around / autoLayout
21
17
 
22
18
  public totalTimes: number = 0
23
19
  public times: number
@@ -80,7 +76,6 @@ export class Layouter implements ILayouter {
80
76
  }
81
77
 
82
78
  public layoutOnce(): void {
83
-
84
79
  if (this.layouting) return debug.warn('layouting')
85
80
  if (this.times > 3) return debug.warn('layout max times')
86
81
 
@@ -103,7 +98,6 @@ export class Layouter implements ILayouter {
103
98
  this.waitAgain = false
104
99
  this.layoutOnce()
105
100
  }
106
-
107
101
  }
108
102
 
109
103
  public partLayout(): void {
@@ -114,14 +108,16 @@ export class Layouter implements ILayouter {
114
108
  const { BEFORE, LAYOUT, AFTER } = LayoutEvent
115
109
 
116
110
  const blocks = this.getBlocks(updateList)
117
- blocks.forEach(item => { item.setBefore() })
111
+ blocks.forEach(item => item.setBefore())
118
112
  target.emitEvent(new LayoutEvent(BEFORE, blocks, this.times))
119
113
 
114
+ this.extraBlock = null
120
115
  updateList.sort()
121
116
  updateMatrix(updateList, this.__levelList)
122
117
  updateBounds(this.__levelList)
123
118
  updateChange(updateList)
124
119
 
120
+ if (this.extraBlock) blocks.push(this.extraBlock)
125
121
  blocks.forEach(item => item.setAfter())
126
122
 
127
123
  target.emitEvent(new LayoutEvent(LAYOUT, blocks, this.times))
@@ -132,7 +128,6 @@ export class Layouter implements ILayouter {
132
128
  this.__levelList.reset()
133
129
  this.__updatedList = null
134
130
  Run.end(t)
135
-
136
131
  }
137
132
 
138
133
  public fullLayout(): void {
@@ -153,23 +148,25 @@ export class Layouter implements ILayouter {
153
148
  this.addBlocks(blocks)
154
149
 
155
150
  Run.end(t)
156
-
157
151
  }
158
152
 
159
153
  static fullLayout(target: ILeaf): void {
160
- updateAllWorldMatrix(target)
154
+ updateAllMatrix(target, true)
161
155
 
162
156
  if (target.isBranch) {
163
- const branchStack: ILeaf[] = [target]
164
- pushAllBranchStack(target, branchStack)
165
- updateWorldBoundsByBranchStack(branchStack)
157
+ BranchHelper.updateBounds(target)
166
158
  } else {
167
- target.__updateWorldBounds()
159
+ LeafHelper.updateBounds(target)
168
160
  }
169
161
 
170
162
  updateAllChange(target)
171
163
  }
172
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
+ }
173
170
 
174
171
  public createBlock(data: ILeafList | ILeaf[]): ILayoutBlockData {
175
172
  return new LayoutBlockData(data)
@@ -204,8 +201,7 @@ export class Layouter implements ILayouter {
204
201
  if (this.target) {
205
202
  this.stop()
206
203
  this.__removeListenEvents()
207
- this.target = null
208
- this.config = null
204
+ this.target = this.config = null
209
205
  }
210
206
  }
211
207
 
@@ -1,8 +1,8 @@
1
- import { ILeaf, ILeafLayout, ILeafLevelList, ILeafList } from '@leafer/interface'
2
- import { BranchHelper, LeafHelper } from '@leafer/helper'
1
+ import { ILeafLayout, ILeafLevelList, ILeafList, ILeaf } from '@leafer/interface'
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
 
@@ -11,19 +11,19 @@ export function updateMatrix(updateList: ILeafList, levelList: ILeafLevelList):
11
11
  let layout: ILeafLayout
12
12
  updateList.list.forEach(leaf => { // 更新矩阵, 所有子元素,和父元素都需要更新bounds
13
13
  layout = leaf.__layout
14
- if (levelList.without(leaf) && !layout.useZoomProxy) { // 防止重复, 子元素可能已经被父元素更新过
14
+ if (levelList.without(leaf) && !layout.proxyZoom) { // 防止重复, 子元素可能已经被父元素更新过
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
 
@@ -0,0 +1,38 @@
1
+ import { ILayouter, ILeaf, ILayoutBlockData, ILayouterConfig, ILeafList, IEventListenerId } from '@leafer/interface';
2
+ import { LeafLevelList, WatchEvent } from '@leafer/core';
3
+
4
+ declare class Layouter implements ILayouter {
5
+ target: ILeaf;
6
+ layoutedBlocks: ILayoutBlockData[];
7
+ extraBlock: ILayoutBlockData;
8
+ totalTimes: number;
9
+ times: number;
10
+ disabled: boolean;
11
+ running: boolean;
12
+ layouting: boolean;
13
+ waitAgain: boolean;
14
+ config: ILayouterConfig;
15
+ protected __updatedList: ILeafList;
16
+ protected __levelList: LeafLevelList;
17
+ protected __eventIds: IEventListenerId[];
18
+ constructor(target: ILeaf, userConfig?: ILayouterConfig);
19
+ start(): void;
20
+ stop(): void;
21
+ disable(): void;
22
+ layout(): void;
23
+ layoutAgain(): void;
24
+ layoutOnce(): void;
25
+ partLayout(): void;
26
+ fullLayout(): void;
27
+ static fullLayout(target: ILeaf): void;
28
+ addExtra(leaf: ILeaf): void;
29
+ createBlock(data: ILeafList | ILeaf[]): ILayoutBlockData;
30
+ getBlocks(list: ILeafList): ILayoutBlockData[];
31
+ addBlocks(current: ILayoutBlockData[]): void;
32
+ protected __onReceiveWatchData(event: WatchEvent): void;
33
+ protected __listenEvents(): void;
34
+ protected __removeListenEvents(): void;
35
+ destroy(): void;
36
+ }
37
+
38
+ export { Layouter };