svelte-intersection-observer 0.9.2 → 0.10.1
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/CHANGELOG.md +20 -0
- package/README.md +2 -4
- package/lib/index.js +719 -501
- package/lib/index.mjs +545 -327
- package/package.json +9 -9
- package/src/IntersectionObserver.svelte +26 -15
- package/types/IntersectionObserver.svelte.d.ts +25 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-intersection-observer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
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)",
|
|
@@ -8,20 +8,20 @@
|
|
|
8
8
|
"main": "./lib/index.js",
|
|
9
9
|
"module": "./lib/index.mjs",
|
|
10
10
|
"types": "./types/index.d.ts",
|
|
11
|
-
"sideEffects": false,
|
|
12
11
|
"scripts": {
|
|
13
12
|
"dev": "rollup -cw",
|
|
14
13
|
"build": "rollup -c",
|
|
15
14
|
"prepack": "BUNDLE=true rollup -c",
|
|
16
|
-
"test": "svelte-check --workspace test",
|
|
17
|
-
"
|
|
15
|
+
"test:types": "svelte-check --workspace test",
|
|
16
|
+
"test:examples": "node test/examples",
|
|
17
|
+
"format": "prettier --ignore-path .gitignore --write '.'"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"prettier": "^
|
|
21
|
-
"prettier-plugin-svelte": "^
|
|
22
|
-
"svelte": "^
|
|
23
|
-
"svelte-check": "^
|
|
24
|
-
"svelte-readme": "^3.6.
|
|
20
|
+
"prettier": "^3.0.0",
|
|
21
|
+
"prettier-plugin-svelte": "^3.0.0",
|
|
22
|
+
"svelte": "^4.1.0",
|
|
23
|
+
"svelte-check": "^3.4.6",
|
|
24
|
+
"svelte-readme": "^3.6.3"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
|
@@ -1,41 +1,49 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
/**
|
|
3
|
-
* The HTML Element to observe
|
|
4
|
-
* @type {
|
|
3
|
+
* The HTML Element to observe.
|
|
4
|
+
* @type {HTMLElement}
|
|
5
5
|
*/
|
|
6
6
|
export let element = null;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Set to `true` to unobserve the element
|
|
9
|
+
* Set to `true` to unobserve the element
|
|
10
|
+
* after it intersects the viewport.
|
|
10
11
|
* @type {boolean}
|
|
11
12
|
*/
|
|
12
13
|
export let once = false;
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
|
|
16
|
+
* `true` if the observed element
|
|
17
|
+
* is intersecting the viewport.
|
|
18
|
+
*/
|
|
19
|
+
export let intersecting = false;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Specify the containing element.
|
|
23
|
+
* Defaults to the browser viewport.
|
|
24
|
+
* @type {HTMLElement}
|
|
18
25
|
*/
|
|
19
26
|
export let root = null;
|
|
20
27
|
|
|
21
|
-
/** Margin offset of the containing element */
|
|
28
|
+
/** Margin offset of the containing element. */
|
|
22
29
|
export let rootMargin = "0px";
|
|
23
30
|
|
|
24
31
|
/**
|
|
25
|
-
* Percentage of element visibility to trigger an event
|
|
26
|
-
* Value must be between 0 and 1
|
|
32
|
+
* Percentage of element visibility to trigger an event.
|
|
33
|
+
* Value must be between 0 and 1.
|
|
27
34
|
*/
|
|
28
35
|
export let threshold = 0;
|
|
29
36
|
|
|
30
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Observed element metadata.
|
|
39
|
+
* @type {null | IntersectionObserverEntry}
|
|
40
|
+
*/
|
|
31
41
|
export let entry = null;
|
|
32
42
|
|
|
33
43
|
/**
|
|
34
|
-
* `
|
|
44
|
+
* `IntersectionObserver` instance.
|
|
45
|
+
* @type {null | IntersectionObserver}
|
|
35
46
|
*/
|
|
36
|
-
export let intersecting = false;
|
|
37
|
-
|
|
38
|
-
/** @type {null | IntersectionObserver} */
|
|
39
47
|
export let observer = null;
|
|
40
48
|
|
|
41
49
|
import { tick, createEventDispatcher, afterUpdate, onMount } from "svelte";
|
|
@@ -61,7 +69,10 @@
|
|
|
61
69
|
initialize();
|
|
62
70
|
|
|
63
71
|
return () => {
|
|
64
|
-
if (observer)
|
|
72
|
+
if (observer) {
|
|
73
|
+
observer.disconnect();
|
|
74
|
+
observer = null;
|
|
75
|
+
}
|
|
65
76
|
};
|
|
66
77
|
});
|
|
67
78
|
|
|
@@ -5,44 +5,56 @@ export type Entry = null | IntersectionObserverEntry;
|
|
|
5
5
|
|
|
6
6
|
export interface IntersectionObserverProps {
|
|
7
7
|
/**
|
|
8
|
+
* The HTML Element to observe.
|
|
8
9
|
* @default null
|
|
9
10
|
*/
|
|
10
|
-
element?:
|
|
11
|
+
element?: HTMLElement;
|
|
11
12
|
|
|
12
13
|
/**
|
|
14
|
+
* Set to `true` to unobserve the element
|
|
15
|
+
* after it intersects the viewport.
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
once?: boolean;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* `true` if the observed element
|
|
22
|
+
* is intersecting the viewport.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
intersecting?: boolean;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Specify the containing element.
|
|
29
|
+
* Defaults to the browser viewport.
|
|
13
30
|
* @default null
|
|
14
31
|
*/
|
|
15
|
-
root?:
|
|
32
|
+
root?: HTMLElement;
|
|
16
33
|
|
|
17
34
|
/**
|
|
35
|
+
* Margin offset of the containing element.
|
|
18
36
|
* @default "0px"
|
|
19
37
|
*/
|
|
20
38
|
rootMargin?: string;
|
|
21
39
|
|
|
22
40
|
/**
|
|
41
|
+
* Percentage of element visibility to trigger an event.
|
|
42
|
+
* Value must be a number between 0 and 1, or an array of numbers between 0 and 1.
|
|
23
43
|
* @default 0
|
|
24
44
|
*/
|
|
25
|
-
threshold?: number;
|
|
45
|
+
threshold?: number | number[];
|
|
26
46
|
|
|
27
47
|
/**
|
|
48
|
+
* Observed element metadata.
|
|
28
49
|
* @default null
|
|
29
50
|
*/
|
|
30
51
|
entry?: null | Entry;
|
|
31
52
|
|
|
32
53
|
/**
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
intersecting?: boolean;
|
|
36
|
-
|
|
37
|
-
/**
|
|
54
|
+
* `IntersectionObserver` instance.
|
|
38
55
|
* @default null
|
|
39
56
|
*/
|
|
40
57
|
observer?: null | IntersectionObserver;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @default false
|
|
44
|
-
*/
|
|
45
|
-
once?: boolean;
|
|
46
58
|
}
|
|
47
59
|
|
|
48
60
|
export default class SvelteIntersectionObserver extends SvelteComponentTyped<
|