svelte-intersection-observer 1.1.1 → 1.1.2
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.
|
@@ -50,8 +50,12 @@
|
|
|
50
50
|
|
|
51
51
|
const dispatch = createEventDispatcher();
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
let prevRootMargin = rootMargin;
|
|
54
|
+
|
|
55
|
+
let prevThreshold = threshold;
|
|
56
|
+
|
|
57
|
+
/** @type {null | HTMLElement} */
|
|
58
|
+
let prevRoot = root;
|
|
55
59
|
|
|
56
60
|
/** @type {null | HTMLElement} */
|
|
57
61
|
let prevElement = null;
|
|
@@ -62,6 +66,14 @@
|
|
|
62
66
|
entries.forEach((_entry) => {
|
|
63
67
|
entry = _entry;
|
|
64
68
|
intersecting = _entry.isIntersecting;
|
|
69
|
+
|
|
70
|
+
dispatch("observe", entry);
|
|
71
|
+
|
|
72
|
+
if (_entry.isIntersecting) {
|
|
73
|
+
dispatch("intersect", entry);
|
|
74
|
+
|
|
75
|
+
if (element && once) observer?.unobserve(element);
|
|
76
|
+
}
|
|
65
77
|
});
|
|
66
78
|
},
|
|
67
79
|
{ root, rootMargin, threshold },
|
|
@@ -80,16 +92,6 @@
|
|
|
80
92
|
});
|
|
81
93
|
|
|
82
94
|
afterUpdate(async () => {
|
|
83
|
-
if (entry !== null) {
|
|
84
|
-
dispatch("observe", entry);
|
|
85
|
-
|
|
86
|
-
if (entry.isIntersecting) {
|
|
87
|
-
dispatch("intersect", entry);
|
|
88
|
-
|
|
89
|
-
if (element && once) observer?.unobserve(element);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
95
|
await tick();
|
|
94
96
|
|
|
95
97
|
if (element !== null && element !== prevElement) {
|
|
@@ -99,13 +101,15 @@
|
|
|
99
101
|
prevElement = element;
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
if (prevRootMargin
|
|
104
|
+
if (rootMargin !== prevRootMargin || threshold !== prevThreshold || root !== prevRoot) {
|
|
103
105
|
observer?.disconnect();
|
|
104
106
|
prevElement = null;
|
|
105
107
|
initialize();
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
prevRootMargin = rootMargin;
|
|
111
|
+
prevThreshold = threshold;
|
|
112
|
+
prevRoot = root;
|
|
109
113
|
});
|
|
110
114
|
</script>
|
|
111
115
|
|
|
@@ -51,11 +51,12 @@
|
|
|
51
51
|
|
|
52
52
|
const dispatch = createEventDispatcher();
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
let prevRootMargin = rootMargin;
|
|
55
|
+
|
|
56
|
+
let prevThreshold = threshold;
|
|
56
57
|
|
|
57
58
|
/** @type {null | HTMLElement} */
|
|
58
|
-
let
|
|
59
|
+
let prevRoot = root;
|
|
59
60
|
|
|
60
61
|
/** @type {(HTMLElement | null)[]} */
|
|
61
62
|
let prevElements = [];
|
|
@@ -117,9 +118,8 @@
|
|
|
117
118
|
prevElements = [...elements];
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
if (prevRootMargin
|
|
121
|
+
if (rootMargin !== prevRootMargin || threshold !== prevThreshold || root !== prevRoot) {
|
|
121
122
|
observer?.disconnect();
|
|
122
|
-
prevElement = null;
|
|
123
123
|
prevElements = [];
|
|
124
124
|
initialize();
|
|
125
125
|
|
|
@@ -131,6 +131,8 @@
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
prevRootMargin = rootMargin;
|
|
134
|
+
prevThreshold = threshold;
|
|
135
|
+
prevRoot = root;
|
|
134
136
|
});
|
|
135
137
|
</script>
|
|
136
138
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-intersection-observer",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Detect if an element is in the viewport using the Intersection Observer API",
|
|
6
6
|
"author": "Eric Liu (https://github.com/metonym)",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"svelte": "./
|
|
8
|
+
"svelte": "./index.js",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git+https://github.com/metonym/svelte-intersection-observer.git"
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
27
|
"types": "./index.d.ts",
|
|
28
|
-
"svelte": "./index.js"
|
|
28
|
+
"svelte": "./index.js",
|
|
29
|
+
"import": "./index.js"
|
|
29
30
|
},
|
|
30
31
|
"./*.svelte": {
|
|
31
32
|
"types": "./*.svelte.d.ts",
|