@leafer/layouter 1.0.0-alpha.1 → 1.0.0-alpha.21

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,11 +1,13 @@
1
1
  {
2
2
  "name": "@leafer/layouter",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.21",
4
4
  "description": "@leafer/canvas",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
7
  "main": "src/index.ts",
8
- "files": ["src"],
8
+ "files": [
9
+ "src"
10
+ ],
9
11
  "repository": {
10
12
  "type": "git",
11
13
  "url": "https://github.com/leaferjs/leafer.git"
@@ -17,14 +19,14 @@
17
19
  "leaferjs"
18
20
  ],
19
21
  "dependencies": {
20
- "@leafer/event": "1.0.0-alpha.1",
21
- "@leafer/math": "1.0.0-alpha.1",
22
- "@leafer/list": "1.0.0-alpha.1",
23
- "@leafer/data": "1.0.0-alpha.1",
24
- "@leafer/helper": "1.0.0-alpha.1",
25
- "@leafer/debug": "1.0.0-alpha.1"
22
+ "@leafer/event": "1.0.0-alpha.21",
23
+ "@leafer/math": "1.0.0-alpha.21",
24
+ "@leafer/list": "1.0.0-alpha.21",
25
+ "@leafer/data": "1.0.0-alpha.21",
26
+ "@leafer/helper": "1.0.0-alpha.21",
27
+ "@leafer/debug": "1.0.0-alpha.21"
26
28
  },
27
29
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-alpha.1"
30
+ "@leafer/interface": "1.0.0-alpha.21"
29
31
  }
30
32
  }
@@ -26,7 +26,7 @@ export class LayoutBlockData implements ILayoutBlockData {
26
26
 
27
27
  public setAfter(): void {
28
28
  setByListWithHandle(this.afterBounds, this.updatedList.list, worldBounds)
29
- this.__computeChange()
29
+ this.updatedBounds.setByList([this.beforeBounds, this.afterBounds])
30
30
  }
31
31
 
32
32
  public merge(data: ILayoutBlockData): void {
@@ -36,17 +36,8 @@ export class LayoutBlockData implements ILayoutBlockData {
36
36
  this.updatedBounds.add(data.updatedBounds)
37
37
  }
38
38
 
39
- protected __computeChange(): void {
40
- const { updatedBounds: changedBounds } = this
41
- changedBounds.setByList([this.beforeBounds, this.afterBounds])
42
- if (!changedBounds.isEmpty()) {
43
- changedBounds.spread(2)
44
- changedBounds.ceil()
45
- }
46
- }
47
-
48
39
  public destroy(): void {
49
- this.updatedList = undefined
40
+ this.updatedList = null
50
41
  }
51
42
 
52
43
  }
package/src/Layouter.ts CHANGED
@@ -16,9 +16,12 @@ export class Layouter implements ILayouter {
16
16
 
17
17
  public target: ILeaf
18
18
  public layoutedBlocks: ILayoutBlockData[]
19
+
19
20
  public totalTimes: number = 0
20
21
  public times: number
22
+
21
23
  public changed: boolean = true
24
+ public running: boolean
22
25
 
23
26
  public config: ILayouterConfig = {
24
27
  partLayout: {
@@ -26,16 +29,14 @@ export class Layouter implements ILayouter {
26
29
  }
27
30
  }
28
31
 
29
- public running: boolean
30
-
31
- protected updateList: ILeafList
32
- protected levelList: LeafLevelList = new LeafLevelList()
33
- protected eventIds: IEventListenerId[]
32
+ protected __updateList: ILeafList
33
+ protected __levelList: LeafLevelList = new LeafLevelList()
34
+ protected __eventIds: IEventListenerId[]
34
35
 
35
36
  constructor(target: ILeaf, userConfig?: ILayouterConfig) {
36
37
  this.target = target
37
38
  if (userConfig) this.config = DataHelper.default(userConfig, this.config)
38
- this.listenEvents()
39
+ this.__listenEvents()
39
40
  }
40
41
 
41
42
  public start(): void {
@@ -46,39 +47,21 @@ export class Layouter implements ILayouter {
46
47
  this.running = false
47
48
  }
48
49
 
49
- protected listenEvents(): void {
50
- const { target } = this
51
- this.eventIds = [
52
- target.on__(LayoutEvent.REQUEST, this.layout, this),
53
- target.on__(LayoutEvent.AGAIN, this.layoutOnce, this),
54
- target.on__(WatchEvent.DATA, this.onReceiveWatchData, this),
55
- target.on__(RenderEvent.REQUEST, this.onChange, this),
56
- ]
57
- }
58
-
59
- protected removeListenEvents(): void {
60
- this.target.off__(this.eventIds)
61
- }
62
-
63
- protected onReceiveWatchData(event: WatchEvent): void {
64
- this.updateList = event.data.updatedList
65
- }
66
-
67
- protected onChange(): void {
50
+ public update(): void {
68
51
  this.changed = true
69
52
  }
70
53
 
71
54
  public layout(): void {
72
55
  if (!this.running) return
73
56
  const { target } = this
74
- const { START, LAYOUT, END } = LayoutEvent
57
+ const { LAYOUT, END } = LayoutEvent
75
58
  this.times = 0
76
59
  this.changed = false
77
- target.emit(START)
60
+ target.emit(LayoutEvent.START)
78
61
  this.layoutOnce()
79
62
  target.emitEvent(new LayoutEvent(LAYOUT, this.layoutedBlocks))
80
63
  target.emitEvent(new LayoutEvent(END, this.layoutedBlocks))
81
- this.layoutedBlocks = undefined
64
+ this.layoutedBlocks = null
82
65
  }
83
66
 
84
67
  public layoutOnce(): void {
@@ -95,10 +78,10 @@ export class Layouter implements ILayouter {
95
78
  }
96
79
 
97
80
  public partLayout(): void {
98
- if (!this.updateList?.length) return
81
+ if (!this.__updateList?.length) return
99
82
 
100
- const t = Run.start('part layout')
101
- const { target, updateList } = this
83
+ const t = Run.start('PartLayout')
84
+ const { target, __updateList: updateList } = this
102
85
  const { BEFORE_ONCE, ONCE, AFTER_ONCE } = LayoutEvent
103
86
 
104
87
  const blocks = this.getBlocks(updateList)
@@ -106,25 +89,26 @@ export class Layouter implements ILayouter {
106
89
  target.emitEvent(new LayoutEvent(BEFORE_ONCE, blocks))
107
90
 
108
91
  updateList.sort()
109
- updateMatrix(updateList, this.levelList)
110
- updateBounds(this.levelList)
92
+ updateMatrix(updateList, this.__levelList)
93
+ updateBounds(this.__levelList)
111
94
  updateChange(updateList)
112
95
 
113
- blocks.forEach(item => { item.setAfter() })
96
+ blocks.forEach(item => item.setAfter())
97
+
114
98
  target.emitEvent(new LayoutEvent(ONCE, blocks))
115
99
  target.emitEvent(new LayoutEvent(AFTER_ONCE, blocks))
116
100
 
117
101
  this.setBlocks(blocks)
118
102
 
119
- this.levelList.reset()
120
- this.updateList = undefined
103
+ this.__levelList.reset()
104
+ this.__updateList = null
121
105
  Run.end(t)
122
106
 
123
107
  this.__checkAgain()
124
108
  }
125
109
 
126
110
  public fullLayout(): void {
127
- const t = Run.start('full layout')
111
+ const t = Run.start('FullLayout')
128
112
 
129
113
  const { target } = this
130
114
  const { BEFORE_ONCE, ONCE, AFTER_ONCE } = LayoutEvent
@@ -145,8 +129,18 @@ export class Layouter implements ILayouter {
145
129
  this.__checkAgain()
146
130
  }
147
131
 
148
- protected __checkAgain(): void {
149
- if (this.changed && this.times <= this.config.partLayout.maxTimes) this.target.emit(LayoutEvent.AGAIN) // 防止更新布局过程中产生了属性修改
132
+ static fullLayout(target: ILeaf): void {
133
+ updateAllWorldMatrix(target)
134
+
135
+ if (target.__isBranch) {
136
+ const branchStack: ILeaf[] = [target]
137
+ pushAllBranchStack(target, branchStack)
138
+ updateWorldBoundsByBranchStack(branchStack)
139
+ } else {
140
+ target.__updateWorldBounds()
141
+ }
142
+
143
+ updateAllChange(target)
150
144
  }
151
145
 
152
146
 
@@ -162,25 +156,32 @@ export class Layouter implements ILayouter {
162
156
  this.layoutedBlocks ? this.layoutedBlocks.push(...current) : this.layoutedBlocks = current
163
157
  }
164
158
 
159
+ protected __checkAgain(): void {
160
+ if (this.changed && this.times <= this.config.partLayout.maxTimes) this.target.emit(LayoutEvent.AGAIN) // 防止更新布局过程中产生了属性修改
161
+ }
165
162
 
166
- static fullLayout(target: ILeaf): void {
167
- updateAllWorldMatrix(target)
163
+ protected __onReceiveWatchData(event: WatchEvent): void {
164
+ this.__updateList = event.data.updatedList
165
+ }
168
166
 
169
- if (target.__isBranch) {
170
- const branchStack: ILeaf[] = [target]
171
- pushAllBranchStack(target, branchStack)
172
- updateWorldBoundsByBranchStack(branchStack)
173
- } else {
174
- target.__updateWorldBounds()
175
- }
167
+ protected __listenEvents(): void {
168
+ const { target } = this
169
+ this.__eventIds = [
170
+ target.on__(LayoutEvent.REQUEST, this.layout, this),
171
+ target.on__(LayoutEvent.AGAIN, this.layoutOnce, this),
172
+ target.on__(WatchEvent.DATA, this.__onReceiveWatchData, this),
173
+ target.on__(RenderEvent.REQUEST, this.update, this),
174
+ ]
175
+ }
176
176
 
177
- updateAllChange(target)
177
+ protected __removeListenEvents(): void {
178
+ this.target.off__(this.__eventIds)
178
179
  }
179
180
 
180
- destroy(): void {
181
+ public destroy(): void {
181
182
  if (this.target) {
182
- this.removeListenEvents()
183
- this.target = undefined
183
+ this.__removeListenEvents()
184
+ this.target = null
184
185
  }
185
186
  }
186
187