/** * Polyfill adding function */ export function polyfill() { /* istanbul ignore next */ if (typeof window === 'undefined') { window = { audioContext: function () { return; } }; } /* istanbul ignore next */ if (typeof window !== 'undefined' && !window.requestAnimationFrame) { (window).requestAnimationFrame = (window).webkitRequestAnimationFrame || (window).mozRequestAnimationFrame || function (callback: Function) { window.setInterval(callback, 1000 / 60); }; } /* istanbul ignore next */ if (typeof window !== 'undefined' && !window.cancelAnimationFrame) { (window).cancelAnimationFrame = (window).webkitCancelAnimationFrame || (window).mozCancelAnimationFrame || function () { return; }; } /* istanbul ignore next */ if (typeof window !== 'undefined' && !(window).AudioContext) { if ((window).webkitAudioContext) { const ctx = (window).webkitAudioContext; const replaceMe = ctx.prototype.decodeAudioData; (window).webkitAudioContext.prototype.decodeAudioData = function (arrayBuffer: ArrayBuffer) { return new Promise((resolve, reject) => { replaceMe.call(this, arrayBuffer, resolve, reject); }); }; } (window).AudioContext = (window).AudioContext || (window).webkitAudioContext || (window).mozAudioContext || (window).msAudioContext || (window).oAudioContext; } /* istanbul ignore next */ if (typeof window !== 'undefined' && !(window).devicePixelRatio) { (window).devicePixelRatio = window.devicePixelRatio || 1; } /* istanbul ignore next */ if (typeof window !== 'undefined' && !(window as any).requestIdleCallback) { // Adapted from https://developer.chrome.com/blog/using-requestidlecallback#checking_for_requestidlecallback (window as any).requestIdleCallback = window.requestIdleCallback || function (cb: (args: any) => any) { const start = Date.now(); return setTimeout(function () { cb({ didTimeout: false, timeRemaining: function () { return Math.max(0, 50 - (Date.now() - start)); } }); }, 1); }; (window as any).cancelIdleCallback = window.cancelIdleCallback || function (id: any) { clearTimeout(id); }; } }