| 46 | } |
| 47 | |
| 48 | function waitForIdle(fn) { |
| 49 | // Wait for view transition to finish before pre-fetching. |
| 50 | // Otherwise try to wait for idle time so we don't interrupt interactions/animations. |
| 51 | if ('activeViewTransition' in document && document.activeViewTransition) { |
| 52 | (document.activeViewTransition as ViewTransition).finished.then(() => fn()); |
| 53 | } else if (typeof requestIdleCallback === 'function') { |
| 54 | requestIdleCallback(fn); |
| 55 | } else { |
| 56 | setTimeout(fn, 0); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | let observer = |
| 61 | typeof IntersectionObserver !== 'undefined' |