-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathbrowser.js
107 lines (87 loc) · 3.22 KB
/
browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict';
var frameName = (function() {
if (window.requestAnimationFrame) return 'requestAnimationFrame';
if (window.mozRequestAnimationFrame) return 'mozRequestAnimationFrame';
if (window.webkitRequestAnimationFrame) return 'webkitRequestAnimationFrame';
if (window.msRequestAnimationFrame) return 'msRequestAnimationFrame';
})();
exports.frame = function(fn) {
return window[frameName](fn);
};
exports.cancelFrame = function(id) {
(window.cancelRequestAnimationFrame ||
window.mozCancelRequestAnimationFrame ||
window.webkitCancelRequestAnimationFrame ||
window.msCancelRequestAnimationFrame)(id);
};
exports.timed = function (fn, dur, ctx) {
if (!dur) { return fn.call(ctx, 1); }
var abort = false,
start = window.performance ? window.performance.now() : Date.now();
function tick(now) {
if (abort) return;
if (!window.performance) now = Date.now();
if (now > start + dur) {
fn.call(ctx, 1);
} else {
fn.call(ctx, (now - start) / dur);
exports.frame(tick);
}
}
exports.frame(tick);
return function() { abort = true; };
};
exports.supported = function() {
var supports = [
function() { return typeof window !== 'undefined'; },
function() { return typeof document !== 'undefined'; },
function () {
return !!(Array.prototype &&
Array.prototype.every &&
Array.prototype.filter &&
Array.prototype.forEach &&
Array.prototype.indexOf &&
Array.prototype.lastIndexOf &&
Array.prototype.map &&
Array.prototype.some &&
Array.prototype.reduce &&
Array.prototype.reduceRight &&
Array.isArray);
},
function() {
return !!(Function.prototype && Function.prototype.bind),
!!(Object.keys &&
Object.create &&
Object.getPrototypeOf &&
Object.getOwnPropertyNames &&
Object.isSealed &&
Object.isFrozen &&
Object.isExtensible &&
Object.getOwnPropertyDescriptor &&
Object.defineProperty &&
Object.defineProperties &&
Object.seal &&
Object.freeze &&
Object.preventExtensions);
},
function() {
return 'JSON' in window && 'parse' in JSON && 'stringify' in JSON;
},
function() {
var canvas = document.createElement('canvas');
if ('supportsContext' in canvas) {
return canvas.supportsContext('webgl') || canvas.supportsContext('experimental-webgl');
}
return !!window.WebGLRenderingContext;
},
function() { return 'Worker' in window; }
];
for (var i = 0; i < supports.length; i++) {
if (!supports[i]()) return false;
}
return true;
};
exports.hardwareConcurrency = navigator.hardwareConcurrency || 8;
Object.defineProperty(exports, 'devicePixelRatio', {
get: function() { return window.devicePixelRatio; }
});