@visactor/vrender-core 1.0.0-alpha.20 → 1.0.0-alpha.22
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/cjs/common/performance-raf.d.ts +1 -1
- package/cjs/common/performance-raf.js +8 -7
- package/cjs/common/performance-raf.js.map +1 -1
- package/dist/index.es.js +9 -12
- package/es/common/performance-raf.d.ts +1 -1
- package/es/common/performance-raf.js +8 -7
- package/es/common/performance-raf.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare class PerformanceRAF {
|
|
2
|
-
nextAnimationFrameCbs: FrameRequestCallback
|
|
2
|
+
nextAnimationFrameCbs: Map<number, FrameRequestCallback>;
|
|
3
3
|
private _rafHandle;
|
|
4
4
|
addAnimationFrameCb(callback: FrameRequestCallback): number;
|
|
5
5
|
removeAnimationFrameCb(index: number): boolean;
|
|
@@ -6,23 +6,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
|
|
7
7
|
const application_1 = require("../application");
|
|
8
8
|
|
|
9
|
+
let idx = 0;
|
|
10
|
+
|
|
9
11
|
class PerformanceRAF {
|
|
10
12
|
constructor() {
|
|
11
|
-
this.nextAnimationFrameCbs =
|
|
13
|
+
this.nextAnimationFrameCbs = new Map, this._rafHandle = null, this.runAnimationFrame = time => {
|
|
12
14
|
this._rafHandle = null;
|
|
13
15
|
const cbs = this.nextAnimationFrameCbs;
|
|
14
|
-
this.nextAnimationFrameCbs =
|
|
15
|
-
for (let i = 0; i < cbs.length; i++) cbs[i] && cbs[i](time);
|
|
16
|
+
this.nextAnimationFrameCbs = new Map, cbs.forEach((cb => cb(time)));
|
|
16
17
|
}, this.tryRunAnimationFrameNextFrame = () => {
|
|
17
|
-
null === this._rafHandle && 0 !== this.nextAnimationFrameCbs.
|
|
18
|
+
null === this._rafHandle && 0 !== this.nextAnimationFrameCbs.size && (this._rafHandle = application_1.application.global.getRequestAnimationFrame()(this.runAnimationFrame));
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
21
|
addAnimationFrameCb(callback) {
|
|
21
|
-
return this.nextAnimationFrameCbs.
|
|
22
|
-
|
|
22
|
+
return this.nextAnimationFrameCbs.set(++idx, callback), this.tryRunAnimationFrameNextFrame(),
|
|
23
|
+
idx;
|
|
23
24
|
}
|
|
24
25
|
removeAnimationFrameCb(index) {
|
|
25
|
-
return
|
|
26
|
+
return !!this.nextAnimationFrameCbs.has(index) && (this.nextAnimationFrameCbs.delete(index),
|
|
26
27
|
!0);
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/common/performance-raf.ts"],"names":[],"mappings":";;;AAAA,gDAA6C;
|
|
1
|
+
{"version":3,"sources":["../src/common/performance-raf.ts"],"names":[],"mappings":";;;AAAA,gDAA6C;AAE7C,IAAI,GAAG,GAAG,CAAC,CAAC;AAKZ,MAAa,cAAc;IAA3B;QACE,0BAAqB,GAAsC,IAAI,GAAG,EAAE,CAAC;QAC7D,eAAU,GAAkB,IAAI,CAAC;QAsB/B,sBAAiB,GAAG,CAAC,IAAY,EAAE,EAAE;YAC7C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,MAAM,GAAG,GAAG,IAAI,CAAC,qBAAqB,CAAC;YACvC,IAAI,CAAC,qBAAqB,GAAG,IAAI,GAAG,EAAE,CAAC;YACvC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9B,CAAC,CAAC;QAEQ,kCAA6B,GAAG,GAAG,EAAE;YAC7C,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,IAAI,IAAI,CAAC,qBAAqB,CAAC,IAAI,KAAK,CAAC,EAAE;gBACrE,OAAO;aACR;YACD,IAAI,CAAC,UAAU,GAAG,yBAAW,CAAC,MAAM,CAAC,wBAAwB,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC1F,CAAC,CAAC;IACJ,CAAC;IAjCC,mBAAmB,CAAC,QAA8B;QAChD,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;QAEhD,IAAI,CAAC,6BAA6B,EAAE,CAAC;QACrC,OAAO,GAAG,CAAC;IACb,CAAC;IAOD,sBAAsB,CAAC,KAAa;QAClC,IAAI,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YACzC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CAeF;AArCD,wCAqCC","file":"performance-raf.js","sourcesContent":["import { application } from '../application';\n\nlet idx = 0;\n\n/**\n * 性能优化,将requestAnimationFrame的回调函数存储起来,在下一帧执行\n */\nexport class PerformanceRAF {\n nextAnimationFrameCbs: Map<number, FrameRequestCallback> = new Map();\n private _rafHandle: number | null = null;\n\n addAnimationFrameCb(callback: FrameRequestCallback) {\n this.nextAnimationFrameCbs.set(++idx, callback);\n // 下一帧执行nextAnimationFrameCbs\n this.tryRunAnimationFrameNextFrame();\n return idx;\n }\n\n /**\n * 移除指定索引的回调函数\n * @param index raf索引,从1开始,相当于内部nextAnimationFrameCbs的idx + 1\n * @returns 是否移除成功\n */\n removeAnimationFrameCb(index: number): boolean {\n if (this.nextAnimationFrameCbs.has(index)) {\n this.nextAnimationFrameCbs.delete(index);\n return true;\n }\n return false;\n }\n\n protected runAnimationFrame = (time: number) => {\n this._rafHandle = null;\n const cbs = this.nextAnimationFrameCbs;\n this.nextAnimationFrameCbs = new Map();\n cbs.forEach(cb => cb(time));\n };\n\n protected tryRunAnimationFrameNextFrame = () => {\n if (this._rafHandle !== null || this.nextAnimationFrameCbs.size === 0) {\n return;\n }\n this._rafHandle = application.global.getRequestAnimationFrame()(this.runAnimationFrame);\n };\n}\n"]}
|
package/dist/index.es.js
CHANGED
|
@@ -880,35 +880,32 @@ class Application {
|
|
|
880
880
|
}
|
|
881
881
|
const application = new Application();
|
|
882
882
|
|
|
883
|
+
let idx = 0;
|
|
883
884
|
class PerformanceRAF {
|
|
884
885
|
constructor() {
|
|
885
|
-
this.nextAnimationFrameCbs =
|
|
886
|
+
this.nextAnimationFrameCbs = new Map();
|
|
886
887
|
this._rafHandle = null;
|
|
887
888
|
this.runAnimationFrame = (time) => {
|
|
888
889
|
this._rafHandle = null;
|
|
889
890
|
const cbs = this.nextAnimationFrameCbs;
|
|
890
|
-
this.nextAnimationFrameCbs =
|
|
891
|
-
|
|
892
|
-
if (cbs[i]) {
|
|
893
|
-
cbs[i](time);
|
|
894
|
-
}
|
|
895
|
-
}
|
|
891
|
+
this.nextAnimationFrameCbs = new Map();
|
|
892
|
+
cbs.forEach(cb => cb(time));
|
|
896
893
|
};
|
|
897
894
|
this.tryRunAnimationFrameNextFrame = () => {
|
|
898
|
-
if (this._rafHandle !== null || this.nextAnimationFrameCbs.
|
|
895
|
+
if (this._rafHandle !== null || this.nextAnimationFrameCbs.size === 0) {
|
|
899
896
|
return;
|
|
900
897
|
}
|
|
901
898
|
this._rafHandle = application.global.getRequestAnimationFrame()(this.runAnimationFrame);
|
|
902
899
|
};
|
|
903
900
|
}
|
|
904
901
|
addAnimationFrameCb(callback) {
|
|
905
|
-
this.nextAnimationFrameCbs.
|
|
902
|
+
this.nextAnimationFrameCbs.set(++idx, callback);
|
|
906
903
|
this.tryRunAnimationFrameNextFrame();
|
|
907
|
-
return
|
|
904
|
+
return idx;
|
|
908
905
|
}
|
|
909
906
|
removeAnimationFrameCb(index) {
|
|
910
|
-
if (
|
|
911
|
-
this.nextAnimationFrameCbs
|
|
907
|
+
if (this.nextAnimationFrameCbs.has(index)) {
|
|
908
|
+
this.nextAnimationFrameCbs.delete(index);
|
|
912
909
|
return true;
|
|
913
910
|
}
|
|
914
911
|
return false;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare class PerformanceRAF {
|
|
2
|
-
nextAnimationFrameCbs: FrameRequestCallback
|
|
2
|
+
nextAnimationFrameCbs: Map<number, FrameRequestCallback>;
|
|
3
3
|
private _rafHandle;
|
|
4
4
|
addAnimationFrameCb(callback: FrameRequestCallback): number;
|
|
5
5
|
removeAnimationFrameCb(index: number): boolean;
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { application } from "../application";
|
|
2
2
|
|
|
3
|
+
let idx = 0;
|
|
4
|
+
|
|
3
5
|
export class PerformanceRAF {
|
|
4
6
|
constructor() {
|
|
5
|
-
this.nextAnimationFrameCbs =
|
|
7
|
+
this.nextAnimationFrameCbs = new Map, this._rafHandle = null, this.runAnimationFrame = time => {
|
|
6
8
|
this._rafHandle = null;
|
|
7
9
|
const cbs = this.nextAnimationFrameCbs;
|
|
8
|
-
this.nextAnimationFrameCbs =
|
|
9
|
-
for (let i = 0; i < cbs.length; i++) cbs[i] && cbs[i](time);
|
|
10
|
+
this.nextAnimationFrameCbs = new Map, cbs.forEach((cb => cb(time)));
|
|
10
11
|
}, this.tryRunAnimationFrameNextFrame = () => {
|
|
11
|
-
null === this._rafHandle && 0 !== this.nextAnimationFrameCbs.
|
|
12
|
+
null === this._rafHandle && 0 !== this.nextAnimationFrameCbs.size && (this._rafHandle = application.global.getRequestAnimationFrame()(this.runAnimationFrame));
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
15
|
addAnimationFrameCb(callback) {
|
|
15
|
-
return this.nextAnimationFrameCbs.
|
|
16
|
-
|
|
16
|
+
return this.nextAnimationFrameCbs.set(++idx, callback), this.tryRunAnimationFrameNextFrame(),
|
|
17
|
+
idx;
|
|
17
18
|
}
|
|
18
19
|
removeAnimationFrameCb(index) {
|
|
19
|
-
return
|
|
20
|
+
return !!this.nextAnimationFrameCbs.has(index) && (this.nextAnimationFrameCbs.delete(index),
|
|
20
21
|
!0);
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -1 +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K,CAAC,EAAE;YACzC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CAeF","file":"performance-raf.js","sourcesContent":["import { application } from '../application';\n\nlet idx = 0;\n\n/**\n * 性能优化,将requestAnimationFrame的回调函数存储起来,在下一帧执行\n */\nexport class PerformanceRAF {\n nextAnimationFrameCbs: Map<number, FrameRequestCallback> = new Map();\n private _rafHandle: number | null = null;\n\n addAnimationFrameCb(callback: FrameRequestCallback) {\n this.nextAnimationFrameCbs.set(++idx, callback);\n // 下一帧执行nextAnimationFrameCbs\n this.tryRunAnimationFrameNextFrame();\n return idx;\n }\n\n /**\n * 移除指定索引的回调函数\n * @param index raf索引,从1开始,相当于内部nextAnimationFrameCbs的idx + 1\n * @returns 是否移除成功\n */\n removeAnimationFrameCb(index: number): boolean {\n if (this.nextAnimationFrameCbs.has(index)) {\n this.nextAnimationFrameCbs.delete(index);\n return true;\n }\n return false;\n }\n\n protected runAnimationFrame = (time: number) => {\n this._rafHandle = null;\n const cbs = this.nextAnimationFrameCbs;\n this.nextAnimationFrameCbs = new Map();\n cbs.forEach(cb => cb(time));\n };\n\n protected tryRunAnimationFrameNextFrame = () => {\n if (this._rafHandle !== null || this.nextAnimationFrameCbs.size === 0) {\n return;\n }\n this._rafHandle = application.global.getRequestAnimationFrame()(this.runAnimationFrame);\n };\n}\n"]}
|