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