@leafer/renderer 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 +8 -9
- package/src/Renderer.ts +20 -17
- package/types/index.d.ts +46 -0
package/package.json
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/renderer",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.10",
|
|
4
4
|
"description": "@leafer/renderer",
|
|
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/renderer",
|
|
18
|
+
"homepage": "https://github.com/leaferjs/leafer/tree/main/packages/partner/renderer",
|
|
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/
|
|
23
|
-
"@leafer/math": "1.0.0-beta.9",
|
|
24
|
-
"@leafer/data": "1.0.0-beta.9",
|
|
25
|
-
"@leafer/platform": "1.0.0-beta.9",
|
|
26
|
-
"@leafer/debug": "1.0.0-beta.9"
|
|
25
|
+
"@leafer/core": "1.0.0-rc.10"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.0.0-
|
|
28
|
+
"@leafer/interface": "1.0.0-rc.10"
|
|
30
29
|
}
|
|
31
30
|
}
|
package/src/Renderer.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { ILeaf, ILeaferCanvas, IRenderer, IRendererConfig, IEventListenerId, IBounds, IFunction, IRenderOptions } from '@leafer/interface'
|
|
2
|
-
import { AnimateEvent, LayoutEvent, RenderEvent, ResizeEvent } from '@leafer/
|
|
3
|
-
import { Bounds } from '@leafer/math'
|
|
4
|
-
import { DataHelper } from '@leafer/data'
|
|
5
|
-
import { Platform } from '@leafer/platform'
|
|
6
|
-
import { Debug, Run } from '@leafer/debug'
|
|
2
|
+
import { AnimateEvent, LayoutEvent, RenderEvent, ResizeEvent, ImageManager, Bounds, DataHelper, Platform, Debug, Run } from '@leafer/core'
|
|
7
3
|
|
|
8
4
|
|
|
9
5
|
const debug = Debug.get('Renderer')
|
|
@@ -77,7 +73,10 @@ export class Renderer implements IRenderer {
|
|
|
77
73
|
this.emitRender(RenderEvent.START)
|
|
78
74
|
this.renderOnce(callback)
|
|
79
75
|
this.emitRender(RenderEvent.END, this.totalBounds)
|
|
76
|
+
|
|
77
|
+
ImageManager.clearRecycled()
|
|
80
78
|
} catch (e) {
|
|
79
|
+
this.rendering = false
|
|
81
80
|
debug.error(e)
|
|
82
81
|
}
|
|
83
82
|
|
|
@@ -135,7 +134,7 @@ export class Renderer implements IRenderer {
|
|
|
135
134
|
const { canvas, updateBlocks: list } = this
|
|
136
135
|
if (!list) return debug.warn('PartRender: need update attr')
|
|
137
136
|
|
|
138
|
-
|
|
137
|
+
this.mergeBlocks()
|
|
139
138
|
list.forEach(block => { if (canvas.bounds.hit(block) && !block.isEmpty()) this.clipRender(block) })
|
|
140
139
|
}
|
|
141
140
|
|
|
@@ -145,7 +144,7 @@ export class Renderer implements IRenderer {
|
|
|
145
144
|
|
|
146
145
|
const bounds = block.getIntersect(canvas.bounds)
|
|
147
146
|
const includes = block.includes(this.target.__world)
|
|
148
|
-
const realBounds = new Bounds(
|
|
147
|
+
const realBounds = new Bounds(bounds)
|
|
149
148
|
|
|
150
149
|
canvas.save()
|
|
151
150
|
|
|
@@ -157,7 +156,7 @@ export class Renderer implements IRenderer {
|
|
|
157
156
|
canvas.clipWorld(bounds, true)
|
|
158
157
|
}
|
|
159
158
|
|
|
160
|
-
this.__render(bounds, realBounds)
|
|
159
|
+
this.__render(bounds, includes, realBounds)
|
|
161
160
|
canvas.restore()
|
|
162
161
|
|
|
163
162
|
Run.end(t)
|
|
@@ -169,14 +168,14 @@ export class Renderer implements IRenderer {
|
|
|
169
168
|
|
|
170
169
|
canvas.save()
|
|
171
170
|
canvas.clear()
|
|
172
|
-
this.__render(canvas.bounds)
|
|
171
|
+
this.__render(canvas.bounds, true)
|
|
173
172
|
canvas.restore()
|
|
174
173
|
|
|
175
174
|
Run.end(t)
|
|
176
175
|
}
|
|
177
176
|
|
|
178
|
-
protected __render(bounds: IBounds, realBounds?: IBounds): void {
|
|
179
|
-
const options: IRenderOptions = bounds
|
|
177
|
+
protected __render(bounds: IBounds, includes?: boolean, realBounds?: IBounds,): void {
|
|
178
|
+
const options: IRenderOptions = bounds.includes(this.target.__world) ? { includes } : { bounds, includes }
|
|
180
179
|
|
|
181
180
|
if (this.needFill) this.canvas.fillWorld(bounds, this.config.fill)
|
|
182
181
|
if (Debug.showRepaint) this.canvas.strokeWorld(bounds, 'red')
|
|
@@ -189,6 +188,7 @@ export class Renderer implements IRenderer {
|
|
|
189
188
|
|
|
190
189
|
if (Debug.showHitView) this.renderHitView(options)
|
|
191
190
|
if (Debug.showBoundsView) this.renderBoundsView(options)
|
|
191
|
+
this.canvas.updateRender()
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
public renderHitView(_options: IRenderOptions): void { }
|
|
@@ -204,7 +204,7 @@ export class Renderer implements IRenderer {
|
|
|
204
204
|
const { updateBlocks: list } = this
|
|
205
205
|
if (list) {
|
|
206
206
|
const bounds = new Bounds()
|
|
207
|
-
bounds.
|
|
207
|
+
bounds.setList(list)
|
|
208
208
|
list.length = 0
|
|
209
209
|
list.push(bounds)
|
|
210
210
|
}
|
|
@@ -214,10 +214,13 @@ export class Renderer implements IRenderer {
|
|
|
214
214
|
const startTime = Date.now()
|
|
215
215
|
Platform.requestRender(() => {
|
|
216
216
|
this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - startTime)))
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
|
|
218
|
+
if (this.running) {
|
|
219
|
+
this.target.emit(AnimateEvent.FRAME)
|
|
220
|
+
if (this.changed && this.canvas.view) this.render()
|
|
221
|
+
this.target.emit(RenderEvent.NEXT)
|
|
219
222
|
}
|
|
220
|
-
|
|
223
|
+
|
|
221
224
|
if (this.target) this.__requestRender()
|
|
222
225
|
})
|
|
223
226
|
}
|
|
@@ -229,7 +232,7 @@ export class Renderer implements IRenderer {
|
|
|
229
232
|
const bounds = new Bounds(0, 0, width, height)
|
|
230
233
|
if (!bounds.includes(this.target.__world) || this.needFill || !e.samePixelRatio) {
|
|
231
234
|
this.addBlock(this.canvas.bounds)
|
|
232
|
-
this.target.forceUpdate('
|
|
235
|
+
this.target.forceUpdate('surface')
|
|
233
236
|
}
|
|
234
237
|
}
|
|
235
238
|
}
|
|
@@ -240,7 +243,7 @@ export class Renderer implements IRenderer {
|
|
|
240
243
|
if (item.updatedList) item.updatedList.list.some(leaf => {
|
|
241
244
|
empty = (!leaf.__world.width || !leaf.__world.height)
|
|
242
245
|
if (empty) {
|
|
243
|
-
debug.
|
|
246
|
+
if (!leaf.isLeafer) debug.tip(leaf.innerName, ': empty')
|
|
244
247
|
empty = (!leaf.isBranch || leaf.isBranchLeaf) // render object
|
|
245
248
|
}
|
|
246
249
|
return empty
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { IRenderer, ILeaf, ILeaferCanvas, IBounds, IRendererConfig, IRenderOptions, IEventListenerId, IFunction } from '@leafer/interface';
|
|
2
|
+
import { ResizeEvent, LayoutEvent } from '@leafer/core';
|
|
3
|
+
|
|
4
|
+
declare class Renderer implements IRenderer {
|
|
5
|
+
target: ILeaf;
|
|
6
|
+
canvas: ILeaferCanvas;
|
|
7
|
+
updateBlocks: IBounds[];
|
|
8
|
+
FPS: number;
|
|
9
|
+
totalTimes: number;
|
|
10
|
+
times: number;
|
|
11
|
+
running: boolean;
|
|
12
|
+
rendering: boolean;
|
|
13
|
+
waitAgain: boolean;
|
|
14
|
+
changed: boolean;
|
|
15
|
+
config: IRendererConfig;
|
|
16
|
+
protected renderBounds: IBounds;
|
|
17
|
+
protected renderOptions: IRenderOptions;
|
|
18
|
+
protected totalBounds: IBounds;
|
|
19
|
+
protected __eventIds: IEventListenerId[];
|
|
20
|
+
protected get needFill(): boolean;
|
|
21
|
+
constructor(target: ILeaf, canvas: ILeaferCanvas, userConfig?: IRendererConfig);
|
|
22
|
+
start(): void;
|
|
23
|
+
stop(): void;
|
|
24
|
+
update(): void;
|
|
25
|
+
requestLayout(): void;
|
|
26
|
+
render(callback?: IFunction): void;
|
|
27
|
+
renderAgain(): void;
|
|
28
|
+
renderOnce(callback?: IFunction): void;
|
|
29
|
+
partRender(): void;
|
|
30
|
+
clipRender(block: IBounds): void;
|
|
31
|
+
fullRender(): void;
|
|
32
|
+
protected __render(bounds: IBounds, includes?: boolean, realBounds?: IBounds): void;
|
|
33
|
+
renderHitView(_options: IRenderOptions): void;
|
|
34
|
+
renderBoundsView(_options: IRenderOptions): void;
|
|
35
|
+
addBlock(block: IBounds): void;
|
|
36
|
+
mergeBlocks(): void;
|
|
37
|
+
protected __requestRender(): void;
|
|
38
|
+
protected __onResize(e: ResizeEvent): void;
|
|
39
|
+
protected __onLayoutEnd(event: LayoutEvent): void;
|
|
40
|
+
protected emitRender(type: string, bounds?: IBounds, options?: IRenderOptions): void;
|
|
41
|
+
protected __listenEvents(): void;
|
|
42
|
+
protected __removeListenEvents(): void;
|
|
43
|
+
destroy(): void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { Renderer };
|