| 30 | // out too, and the copy is placed by a margin, not a transform: the copy |
| 31 | // gets one layer the size of the screen, never one the size of the page. |
| 32 | const makeGhost = (page: HTMLElement): HTMLElement => { |
| 33 | const standing = Array.from( |
| 34 | page.querySelectorAll<HTMLElement>(standingSelector), |
| 35 | ).map((element) => ({ |
| 36 | rect: element.getBoundingClientRect(), |
| 37 | leave: |
| 38 | element.classList.contains('shell-cluster') || |
| 39 | element.classList.contains('shell-scrim'), |
| 40 | })); |
| 41 | const below = Array.from( |
| 42 | page.querySelectorAll<HTMLElement>(itemSelector), |
| 43 | ).map((element) => element.getBoundingClientRect().top > window.innerHeight); |
| 44 | const ghost = document.createElement('div'); |
| 45 | ghost.className = 'shell-ghost'; |
| 46 | ghost.setAttribute('aria-hidden', 'true'); |
| 47 | ghost.setAttribute('inert', ''); |
| 48 | const inner = page.cloneNode(true) as HTMLElement; |
| 49 | inner.removeAttribute('id'); |
| 50 | inner |
| 51 | .querySelectorAll('iframe, video, script') |
| 52 | .forEach((element) => element.remove()); |
| 53 | Array.from(inner.querySelectorAll<HTMLElement>(itemSelector)).forEach( |
| 54 | (element, index) => { |
| 55 | if (below[index]) { |
| 56 | element.remove(); |
| 57 | } |
| 58 | }, |
| 59 | ); |
| 60 | inner.style.marginTop = `${-window.scrollY}px`; |
| 61 | inner.style.transition = 'none'; |
| 62 | Array.from(inner.querySelectorAll<HTMLElement>(standingSelector)).forEach( |
| 63 | (element, index) => { |
| 64 | const place = standing[index]; |
| 65 | if (!place || place.leave) { |
| 66 | element.remove(); |
| 67 | return; |
| 68 | } |
| 69 | Object.assign(element.style, { |
| 70 | position: 'absolute', |
| 71 | top: `${place.rect.top}px`, |
| 72 | left: `${place.rect.left}px`, |
| 73 | width: `${place.rect.width}px`, |
| 74 | height: `${place.rect.height}px`, |
| 75 | bottom: 'auto', |
| 76 | right: 'auto', |
| 77 | transform: 'none', |
| 78 | translate: 'none', |
| 79 | transition: 'none', |
| 80 | }); |
| 81 | ghost.appendChild(element); |
| 82 | }, |
| 83 | ); |
| 84 | ghost.prepend(inner); |
| 85 | return ghost; |
| 86 | }; |
| 87 | |
| 88 | let active: (() => void) | undefined; |
| 89 | |