fouc.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.displayContent = displayContent;
  6. // This wrapper function is used to safely select the best available function
  7. // to schedule removal of the no-FOUC styles workaround. requestAnimationFrame
  8. // is the ideal choice, but when used in iframes, there are no guarantees that
  9. // the callback will actually be called, which could stall the promise returned
  10. // from displayContent.
  11. //
  12. // See: https://www.vector-logic.com/blog/posts/on-request-animation-frame-and-embedded-iframes
  13. const safeCallbackQueue = (callback)=>{
  14. if (window.requestAnimationFrame && window.self === window.top) {
  15. window.requestAnimationFrame(callback);
  16. } else {
  17. window.setTimeout(callback);
  18. }
  19. };
  20. function displayContent() {
  21. return new Promise((resolve)=>{
  22. safeCallbackQueue(function() {
  23. for(var x = document.querySelectorAll('[data-next-hide-fouc]'), i = x.length; i--;){
  24. x[i].parentNode.removeChild(x[i]);
  25. }
  26. resolve();
  27. });
  28. });
  29. }
  30. if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
  31. Object.defineProperty(exports.default, '__esModule', { value: true });
  32. Object.assign(exports.default, exports);
  33. module.exports = exports.default;
  34. }
  35. //# sourceMappingURL=fouc.js.map