闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB

  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. function importBasePolyfills() {
  5. return import(/* webpackChunkName: "base_polyfills" */ './base_polyfills');
  6. }
  7. function importExtraPolyfills() {
  8. return import(/* webpackChunkName: "extra_polyfills" */ './extra_polyfills');
  9. }
  10. function loadPolyfills() {
  11. const needsBasePolyfills = !(
  12. Array.prototype.includes &&
  13. HTMLCanvasElement.prototype.toBlob &&
  14. window.Intl &&
  15. Number.isNaN &&
  16. Object.assign &&
  17. Object.values &&
  18. window.Symbol
  19. );
  20. // Latest version of Firefox and Safari do not have IntersectionObserver.
  21. // Edge does not have requestIdleCallback and object-fit CSS property.
  22. // This avoids shipping them all the polyfills.
  23. const needsExtraPolyfills = !(
  24. window.IntersectionObserver &&
  25. window.IntersectionObserverEntry &&
  26. 'isIntersecting' in IntersectionObserverEntry.prototype &&
  27. window.requestIdleCallback &&
  28. 'object-fit' in (new Image()).style
  29. );
  30. return Promise.all([
  31. needsBasePolyfills && importBasePolyfills(),
  32. needsExtraPolyfills && importExtraPolyfills(),
  33. ]);
  34. }
  35. export default loadPolyfills;