@leafer/layouter 1.0.0-alpha.1 → 1.0.0-alpha.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,11 +1,13 @@
1
1
  {
2
2
  "name": "@leafer/layouter",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.10",
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.10",
23
+ "@leafer/math": "1.0.0-alpha.10",
24
+ "@leafer/list": "1.0.0-alpha.10",
25
+ "@leafer/data": "1.0.0-alpha.10",
26
+ "@leafer/helper": "1.0.0-alpha.10",
27
+ "@leafer/debug": "1.0.0-alpha.10"
26
28
  },
27
29
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-alpha.1"
30
+ "@leafer/interface": "1.0.0-alpha.10"
29
31
  }
30
32
  }
@@ -46,7 +46,7 @@ export class LayoutBlockData implements ILayoutBlockData {
46
46
  }
47
47
 
48
48
  public destroy(): void {
49
- this.updatedList = undefined
49
+ this.updatedList = null
50
50
  }
51
51
 
52
52
  }
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,8 +89,8 @@ 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
96
  blocks.forEach(item => { item.setAfter() })
@@ -116,15 +99,15 @@ export class Layouter implements ILayouter {
116
99
 
117
100
  this.setBlocks(blocks)
118
101
 
119
- this.levelList.reset()
120
- this.updateList = undefined
102
+ this.__levelList.reset()
103
+ this.__updateList = null
121
104
  Run.end(t)
122
105
 
123
106
  this.__checkAgain()
124
107
  }
125
108
 
126
109
  public fullLayout(): void {
127
- const t = Run.start('full layout')
110
+ const t = Run.start('FullLayout')
128
111
 
129
112
  const { target } = this
130
113
  const { BEFORE_ONCE, ONCE, AFTER_ONCE } = LayoutEvent
@@ -145,8 +128,18 @@ export class Layouter implements ILayouter {
145
128
  this.__checkAgain()
146
129
  }
147
130
 
148
- protected __checkAgain(): void {
149
- if (this.changed && this.times <= this.config.partLayout.maxTimes) this.target.emit(LayoutEvent.AGAIN) // 防止更新布局过程中产生了属性修改
131
+ static fullLayout(target: ILeaf): void {
132
+ updateAllWorldMatrix(target)
133
+
134
+ if (target.__isBranch) {
135
+ const branchStack: ILeaf[] = [target]
136
+ pushAllBranchStack(target, branchStack)
137
+ updateWorldBoundsByBranchStack(branchStack)
138
+ } else {
139
+ target.__updateWorldBounds()
140
+ }
141
+
142
+ updateAllChange(target)
150
143
  }
151
144
 
152
145
 
@@ -162,25 +155,32 @@ export class Layouter implements ILayouter {
162
155
  this.layoutedBlocks ? this.layoutedBlocks.push(...current) : this.layoutedBlocks = current
163
156
  }
164
157
 
158
+ protected __checkAgain(): void {
159
+ if (this.changed && this.times <= this.config.partLayout.maxTimes) this.target.emit(LayoutEvent.AGAIN) // 防止更新布局过程中产生了属性修改
160
+ }
165
161
 
166
- static fullLayout(target: ILeaf): void {
167
- updateAllWorldMatrix(target)
162
+ protected __onReceiveWatchData(event: WatchEvent): void {
163
+ this.__updateList = event.data.updatedList
164
+ }
168
165
 
169
- if (target.__isBranch) {
170
- const branchStack: ILeaf[] = [target]
171
- pushAllBranchStack(target, branchStack)
172
- updateWorldBoundsByBranchStack(branchStack)
173
- } else {
174
- target.__updateWorldBounds()
175
- }
166
+ protected __listenEvents(): void {
167
+ const { target } = this
168
+ this.__eventIds = [
169
+ target.on__(LayoutEvent.REQUEST, this.layout, this),
170
+ target.on__(LayoutEvent.AGAIN, this.layoutOnce, this),
171
+ target.on__(WatchEvent.DATA, this.__onReceiveWatchData, this),
172
+ target.on__(RenderEvent.REQUEST, this.update, this),
173
+ ]
174
+ }
176
175
 
177
- updateAllChange(target)
176
+ protected __removeListenEvents(): void {
177
+ this.target.off__(this.__eventIds)
178
178
  }
179
179
 
180
- destroy(): void {
180
+ public destroy(): void {
181
181
  if (this.target) {
182
- this.removeListenEvents()
183
- this.target = undefined
182
+ this.__removeListenEvents()
183
+ this.target = null
184
184
  }
185
185
  }
186
186