|
3 | 3 |
|
4 | 4 | /** |
5 | 5 | * @typedef {Object} Props |
6 | | - * @property {(HTMLElement | null)[]} [elements] Array of HTML Elements to observe. Use this for better performance when observing multiple elements. |
| 6 | + * @property {ReadonlyArray<Element | null | undefined>} [elements] Array of Elements to observe. Use this for better performance when observing multiple elements. |
7 | 7 | * @property {boolean} [once] Set to `true` to unobserve the element after it intersects the viewport. |
8 | | - * @property {null | HTMLElement} [root] Specify the containing element. Defaults to the browser viewport. |
| 8 | + * @property {Element | Document | null | undefined} [root] Specify the containing element. Defaults to the browser viewport. |
9 | 9 | * @property {string} [rootMargin] Margin offset of the containing element. |
10 | 10 | * @property {number | number[]} [threshold] Percentage of element visibility to trigger an event. Value must be between 0 and 1. |
11 | | - * @property {Map<HTMLElement | null, boolean>} [elementIntersections] Map of element to its intersection state. |
12 | | - * @property {Map<HTMLElement | null, IntersectionObserverEntry>} [elementEntries] Map of element to its latest entry. |
| 11 | + * @property {Map<Element | null | undefined, boolean>} [elementIntersections] Map of element to its intersection state. |
| 12 | + * @property {Map<Element | null | undefined, IntersectionObserverEntry>} [elementEntries] Map of element to its latest entry. |
13 | 13 | * @property {null | IntersectionObserver} [observer] `IntersectionObserver` instance. |
14 | 14 | * @property {boolean} [skip] Set to `true` to pause observing all elements without disconnecting the observer or losing `elementIntersections`/`elementEntries` state. Set back to `false` to resume. |
15 | | - * @property {(detail: { entry: IntersectionObserverEntry, target: HTMLElement }) => void} [onobserve] Called when an element is first observed and also whenever an intersection event occurs. |
16 | | - * @property {(detail: { entry: IntersectionObserverEntry & { isIntersecting: true }, target: HTMLElement }) => void} [onintersect] Called only when an element is intersecting the viewport. |
17 | | - * @property {import("svelte").Snippet<[{ observer: null | IntersectionObserver, elementIntersections: Map<HTMLElement | null, boolean>, elementEntries: Map<HTMLElement | null, IntersectionObserverEntry> }]>} [children] |
| 15 | + * @property {(detail: { entry: IntersectionObserverEntry, target: Element }) => void} [onobserve] Called when an element is first observed and also whenever an intersection event occurs. |
| 16 | + * @property {(detail: { entry: IntersectionObserverEntry & { isIntersecting: true }, target: Element }) => void} [onintersect] Called only when an element is intersecting the viewport. |
| 17 | + * @property {import("svelte").Snippet<[{ observer: null | IntersectionObserver, elementIntersections: Map<Element | null | undefined, boolean>, elementEntries: Map<Element | null | undefined, IntersectionObserverEntry> }]>} [children] |
18 | 18 | */ |
19 | 19 |
|
20 | 20 | /** @type {Props} */ |
|
33 | 33 | children, |
34 | 34 | } = $props(); |
35 | 35 |
|
36 | | - /** @type {Set<HTMLElement | null>} */ |
| 36 | + /** @type {Set<Element | null | undefined>} */ |
37 | 37 | let prevElements = new Set(); |
38 | 38 |
|
39 | 39 | let prevSkip = untrack(() => skip); |
|
49 | 49 | observer = new IntersectionObserver( |
50 | 50 | (entries) => { |
51 | 51 | for (const _entry of entries) { |
52 | | - const target = /** @type {HTMLElement} */ (_entry.target); |
| 52 | + const target = /** @type {Element} */ (_entry.target); |
53 | 53 |
|
54 | 54 | elementIntersections.set(target, _entry.isIntersecting); |
55 | 55 | elementEntries.set(target, _entry); |
|
0 commit comments