1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.throttle = exports.throttleReactEventCallback = exports.throttleEvent = exports.elementIsOrContains = void 0;
|
19 | var functionUtils_1 = require("./functionUtils");
|
20 | function elementIsOrContains(element, testElement) {
|
21 | return element === testElement || element.contains(testElement);
|
22 | }
|
23 | exports.elementIsOrContains = elementIsOrContains;
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function throttleEvent(target, eventName, newEventName) {
|
32 | var throttledFunc = throttleImpl(function (event) {
|
33 | target.dispatchEvent(new CustomEvent(newEventName, event));
|
34 | });
|
35 | target.addEventListener(eventName, throttledFunc);
|
36 | return throttledFunc;
|
37 | }
|
38 | exports.throttleEvent = throttleEvent;
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | function throttleReactEventCallback(callback, options) {
|
46 | if (options === void 0) { options = {}; }
|
47 | var throttledFunc = throttleImpl(callback, function (event2) {
|
48 | if (options.preventDefault) {
|
49 | event2.preventDefault();
|
50 | }
|
51 | },
|
52 |
|
53 | function (event2) { return event2.persist(); });
|
54 | return throttledFunc;
|
55 | }
|
56 | exports.throttleReactEventCallback = throttleReactEventCallback;
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | function throttle(method) {
|
63 | return throttleImpl(method);
|
64 | }
|
65 | exports.throttle = throttle;
|
66 |
|
67 | function throttleImpl(onAnimationFrameRequested, onBeforeIsRunningCheck, onAfterIsRunningCheck) {
|
68 | var isRunning = false;
|
69 | var func = function () {
|
70 | var args = [];
|
71 | for (var _i = 0; _i < arguments.length; _i++) {
|
72 | args[_i] = arguments[_i];
|
73 | }
|
74 |
|
75 |
|
76 | if (functionUtils_1.isFunction(onBeforeIsRunningCheck)) {
|
77 | onBeforeIsRunningCheck.apply(void 0, args);
|
78 | }
|
79 | if (isRunning) {
|
80 | return;
|
81 | }
|
82 | isRunning = true;
|
83 | if (functionUtils_1.isFunction(onAfterIsRunningCheck)) {
|
84 | onAfterIsRunningCheck.apply(void 0, args);
|
85 | }
|
86 | requestAnimationFrame(function () {
|
87 | onAnimationFrameRequested.apply(void 0, args);
|
88 | isRunning = false;
|
89 | });
|
90 | };
|
91 | return func;
|
92 | }
|
93 |
|
\ | No newline at end of file |