1 /* This is free and unencumbered software released into the public
2 domain. To the extent possible under law, the author of this file
3 waives all copyright and related or neighboring rights to it.
9 /** Polyfills and cross-browser fixes */
12 Math
.sign = function (a
) { return a
&& (a
> 0) - (a
< 0); };
14 if (!String
.prototype.repeat
)
15 Object
.defineProperty(String
.prototype, "repeat", {
16 value: function (count
) {
17 var string
= this.toString();
31 if (!String
.prototype.startsWith
)
32 Object
.defineProperty(String
.prototype, "startsWith", {
33 value: function (sub
) {
34 return this.lastIndexOf(sub
, 0) !== -1;
38 if (!String
.prototype.endsWith
)
39 Object
.defineProperty(String
.prototype, "endsWith", {
40 value: function (sub
) {
41 return this.indexOf(sub
, this.length
- sub
.length
) !== -1;
45 function toObject (o
) {
46 if (o
=== null || o
=== undefined)
47 throw new TypeError("invalid ToObject cast");
52 Object
.defineProperty(Object
, "assign", {
53 value: function (target
) {
54 target
= toObject(target
);
55 for (var i
= 1; i
< arguments
.length
; ++i
) {
56 var source
= toObject(arguments
[i
]);
57 var keys
= Object
.keys(source
);
58 for (var j
= 0; j
< keys
.length
; ++j
)
59 target
[keys
[j
]] = source
[keys
[j
]];
64 if (!Array
.prototype.fill
)
65 Object
.defineProperty(Array
.prototype, "fill", {
66 value: function (value
) {
67 var beg
= arguments
.length
> 1 ? +arguments
[1] : 0;
68 var end
= arguments
.length
> 2 ? +arguments
[2] : this.length
;
69 if (beg
< 0) beg
+= this.length
;
70 if (end
< 0) end
+= this.length
;
71 for (var i
= beg
; i
< end
; ++i
)
77 if (typeof window
!== "undefined") {
78 window
.requestAnimationFrame
= (
79 window
.requestAnimationFrame
80 || window
.mozRequestAnimationFrame
81 || window
.webkitRequestAnimationFrame
);
82 window
.cancelAnimationFrame
= (
83 window
.cancelAnimationFrame
84 || window
.mozCancelAnimationFrame
85 || window
.webkitCancelAnimationFrame
);
87 if (!window
.AudioContext
)
88 window
.AudioContext
= (
89 window
.webkitAudioContext
90 || window
.mozAudioContext
);
92 if (window
.AudioContext
&& !window
.AudioContext
.prototype.createGain
)
93 window
.AudioContext
.prototype.createGain
=
94 window
.AudioContext
.prototype.createGainNode
;
96 /** Canonicalize fullscreen function names if available.
98 Based on https://fullscreen.spec.whatwg.org/, June 7th 2013.
101 if (!Element
.prototype.requestFullscreen
)
102 Element
.prototype.requestFullscreen
= (
103 Element
.prototype.requestFullScreen
104 || Element
.prototype.webkitRequestFullscreen
105 || Element
.prototype.webkitRequestFullScreen
106 || Element
.prototype.mozRequestFullScreen
108 if (!document
.exitFullscreen
)
109 document
.exitFullscreen
= (
110 document
.webkitExitFullscreen
111 || document
.webkitCancelFullScreen
112 || document
.mozCancelFullScreen
114 if (!document
.hasOwnProperty("fullscreenEnabled"))
115 Object
.defineProperty(document
, "fullscreenEnabled", {
118 return (this.webkitFullscreenEnabled
119 || this.mozFullScreenEnabled
123 if (!document
.hasOwnProperty("fullscreenElement"))
124 Object
.defineProperty(document
, "fullscreenElement", {
127 return (this.webkitFullscreenElement
128 || this.webkitCurrentFullScreenElement
129 || this.mozFullScreenEleement