1 | export var raf =
|
2 | (
|
3 | typeof window !== 'undefined' &&
|
4 | (
|
5 | window.requestAnimationFrame ||
|
6 | window.mozRequestAnimationFrame ||
|
7 | window.webkitRequestAnimationFrame
|
8 | )
|
9 | ) ||
|
10 | function(cb) {
|
11 | return setTimeout(cb, 50 / 3);
|
12 | };
|
13 |
|
14 | export var caf =
|
15 | (
|
16 | typeof window !== 'undefined' &&
|
17 | (
|
18 | window.cancelAnimationFrame ||
|
19 | window.mozCancelAnimationFrame ||
|
20 | window.webkitCancelAnimationFrame
|
21 | )
|
22 | ) ||
|
23 | clearTimeout;
|
24 |
|
25 | export function binsearch(arr, prop, key) {
|
26 | var mid = 0;
|
27 | var left = 0;
|
28 | var right = arr.length;
|
29 | while (left < right - 1) {
|
30 | mid = (left + right) >> 1;
|
31 | if (key >= arr[mid][prop]) {
|
32 | left = mid;
|
33 | } else {
|
34 | right = mid;
|
35 | }
|
36 | }
|
37 | if (arr[left] && key < arr[left][prop]) {
|
38 | return left;
|
39 | }
|
40 | return right;
|
41 | }
|
42 |
|
43 |
|
44 | export function formatMode(mode) {
|
45 | if (!/^(ltr|top|bottom)$/i.test(mode)) {
|
46 | return 'rtl';
|
47 | }
|
48 | return mode.toLowerCase();
|
49 | }
|
50 |
|
51 | function collidableRange() {
|
52 | var max = 9007199254740991;
|
53 | return [
|
54 | { range: 0, time: -max, width: max, height: 0 },
|
55 | { range: max, time: max, width: 0, height: 0 }
|
56 | ];
|
57 | }
|
58 |
|
59 | export function resetSpace(space) {
|
60 | space.ltr = collidableRange();
|
61 | space.rtl = collidableRange();
|
62 | space.top = collidableRange();
|
63 | space.bottom = collidableRange();
|
64 | }
|