1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 | var raf = function raf(callback) {
|
8 | return +setTimeout(callback, 16);
|
9 | };
|
10 | var caf = function caf(num) {
|
11 | return clearTimeout(num);
|
12 | };
|
13 | if (typeof window !== 'undefined' && 'requestAnimationFrame' in window) {
|
14 | raf = function raf(callback) {
|
15 | return window.requestAnimationFrame(callback);
|
16 | };
|
17 | caf = function caf(handle) {
|
18 | return window.cancelAnimationFrame(handle);
|
19 | };
|
20 | }
|
21 | var rafUUID = 0;
|
22 | var rafIds = new Map();
|
23 | function cleanup(id) {
|
24 | rafIds.delete(id);
|
25 | }
|
26 | var wrapperRaf = function wrapperRaf(callback) {
|
27 | var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
28 | rafUUID += 1;
|
29 | var id = rafUUID;
|
30 | function callRef(leftTimes) {
|
31 | if (leftTimes === 0) {
|
32 |
|
33 | cleanup(id);
|
34 |
|
35 |
|
36 | callback();
|
37 | } else {
|
38 |
|
39 | var realId = raf(function () {
|
40 | callRef(leftTimes - 1);
|
41 | });
|
42 |
|
43 |
|
44 | rafIds.set(id, realId);
|
45 | }
|
46 | }
|
47 | callRef(times);
|
48 | return id;
|
49 | };
|
50 | wrapperRaf.cancel = function (id) {
|
51 | var realId = rafIds.get(id);
|
52 | cleanup(id);
|
53 | return caf(realId);
|
54 | };
|
55 | if (process.env.NODE_ENV !== 'production') {
|
56 | wrapperRaf.ids = function () {
|
57 | return rafIds;
|
58 | };
|
59 | }
|
60 | var _default = exports.default = wrapperRaf; |
\ | No newline at end of file |