]> cat aescling's git repositories - mastodon.git/blob - app/javascript/flavours/glitch/util/load_polyfills.js
Merge branch 'master' into glitch-soc/merge-upstream
[mastodon.git] / app / javascript / flavours / glitch / util / load_polyfills.js
1 // Convenience function to load polyfills and return a promise when it's done.
2 // If there are no polyfills, then this is just Promise.resolve() which means
3 // it will execute in the same tick of the event loop (i.e. near-instant).
4
5 function importBasePolyfills() {
6 return import(/* webpackChunkName: "base_polyfills" */ './base_polyfills');
7 }
8
9 function importExtraPolyfills() {
10 return import(/* webpackChunkName: "extra_polyfills" */ './extra_polyfills');
11 }
12
13 function loadPolyfills() {
14 const needsBasePolyfills = !(
15 Array.prototype.includes &&
16 HTMLCanvasElement.prototype.toBlob &&
17 window.Intl &&
18 Number.isNaN &&
19 Object.assign &&
20 Object.values &&
21 window.Symbol
22 );
23
24 // Latest version of Firefox and Safari do not have IntersectionObserver.
25 // Edge does not have requestIdleCallback and object-fit CSS property.
26 // This avoids shipping them all the polyfills.
27 const needsExtraPolyfills = !(
28 window.IntersectionObserver &&
29 window.IntersectionObserverEntry &&
30 'isIntersecting' in IntersectionObserverEntry.prototype &&
31 window.requestIdleCallback &&
32 'object-fit' in (new Image()).style
33 );
34
35 return Promise.all([
36 needsBasePolyfills && importBasePolyfills(),
37 needsExtraPolyfills && importExtraPolyfills(),
38 ]);
39 }
40
41 export default loadPolyfills;
This page took 0.071689 seconds and 4 git commands to generate.