svelte-intersection-observer 1.2.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/IntersectionObserver.svelte +53 -100
- package/IntersectionObserver.svelte.d.ts +85 -77
- package/MultipleIntersectionObserver.svelte +61 -108
- package/MultipleIntersectionObserver.svelte.d.ts +88 -80
- package/README.md +212 -133
- package/index.d.ts +2 -2
- package/index.js +1 -1
- package/{intersect.d.ts → intersect.svelte.d.ts} +21 -3
- package/{intersect.js → intersect.svelte.js} +15 -3
- package/package.json +1 -1
|
@@ -1,90 +1,98 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Component, Snippet } from "svelte";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
elements?: (HTMLElement | null)[];
|
|
3
|
+
export interface MultipleIntersectionObserverProps {
|
|
4
|
+
/**
|
|
5
|
+
* Array of HTML Elements to observe.
|
|
6
|
+
* Use this for better performance when observing multiple elements.
|
|
7
|
+
* @default []
|
|
8
|
+
*/
|
|
9
|
+
elements?: (HTMLElement | null)[];
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Set to `true` to unobserve the element
|
|
13
|
+
* after it intersects the viewport.
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
once?: boolean;
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Specify the containing element.
|
|
20
|
+
* Defaults to the browser viewport.
|
|
21
|
+
* @default null
|
|
22
|
+
*/
|
|
23
|
+
root?: null | HTMLElement;
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Margin offset of the containing element.
|
|
27
|
+
* @default "0px"
|
|
28
|
+
*/
|
|
29
|
+
rootMargin?: string;
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Percentage of element visibility to trigger an event.
|
|
33
|
+
* Value must be a number between 0 and 1, or an array of numbers between 0 and 1.
|
|
34
|
+
* @default 0
|
|
35
|
+
*/
|
|
36
|
+
threshold?: number | number[];
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Map of element to its intersection state.
|
|
40
|
+
* @default new Map()
|
|
41
|
+
*/
|
|
42
|
+
elementIntersections?: Map<HTMLElement | null, boolean>;
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Map of element to its latest entry.
|
|
46
|
+
* @default new Map()
|
|
47
|
+
*/
|
|
48
|
+
elementEntries?: Map<HTMLElement | null, IntersectionObserverEntry>;
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
/**
|
|
51
|
+
* `IntersectionObserver` instance.
|
|
52
|
+
* @default null
|
|
53
|
+
*/
|
|
54
|
+
observer?: null | IntersectionObserver;
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
/**
|
|
67
|
-
* Dispatched when an element is first observed
|
|
68
|
-
* and also whenever an intersection event occurs.
|
|
69
|
-
*/
|
|
70
|
-
observe: CustomEvent<{
|
|
71
|
-
entry: IntersectionObserverEntry;
|
|
72
|
-
target: HTMLElement;
|
|
73
|
-
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Set to `true` to pause observing all elements without disconnecting
|
|
58
|
+
* the observer or losing `elementIntersections`/`elementEntries` state.
|
|
59
|
+
* Set back to `false` to resume.
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
62
|
+
skip?: boolean;
|
|
74
63
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Called when an element is first observed
|
|
66
|
+
* and also whenever an intersection event occurs.
|
|
67
|
+
*/
|
|
68
|
+
onobserve?: (detail: {
|
|
69
|
+
entry: IntersectionObserverEntry;
|
|
70
|
+
target: HTMLElement;
|
|
71
|
+
}) => void;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Called only when an element is intersecting the viewport.
|
|
75
|
+
*/
|
|
76
|
+
onintersect?: (detail: {
|
|
77
|
+
entry: IntersectionObserverEntry & { isIntersecting: true };
|
|
78
|
+
target: HTMLElement;
|
|
79
|
+
}) => void;
|
|
80
|
+
|
|
81
|
+
children?: Snippet<
|
|
82
|
+
[
|
|
83
|
+
{
|
|
84
|
+
observer: null | IntersectionObserver;
|
|
85
|
+
elementIntersections: Map<HTMLElement | null, boolean>;
|
|
86
|
+
elementEntries: Map<HTMLElement | null, IntersectionObserverEntry>;
|
|
87
|
+
},
|
|
88
|
+
]
|
|
89
|
+
>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
declare const MultipleIntersectionObserverComponent: Component<
|
|
93
|
+
MultipleIntersectionObserverProps,
|
|
94
|
+
Record<string, never>,
|
|
95
|
+
"elementIntersections" | "elementEntries" | "observer"
|
|
96
|
+
>;
|
|
97
|
+
|
|
98
|
+
export default MultipleIntersectionObserverComponent;
|