svelte-intersection-observer 0.9.2 → 0.10.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/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/lib/index.js +16 -13
- package/lib/index.mjs +16 -13
- package/package.json +1 -1
- package/src/IntersectionObserver.svelte +26 -15
- package/types/IntersectionObserver.svelte.d.ts +24 -12
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.10.0](https://github.com/metonym/svelte-intersection-observer/releases/tag/v0.10.0) - 2021-12-29
|
|
9
|
+
|
|
10
|
+
**Features**
|
|
11
|
+
|
|
12
|
+
- mark `observer` for garbage collection after disconnecting
|
|
13
|
+
|
|
14
|
+
**Documentation**
|
|
15
|
+
|
|
16
|
+
- make prop descriptions consistent with docs
|
|
17
|
+
|
|
18
|
+
**Refactoring**
|
|
19
|
+
|
|
20
|
+
- omit redundant `null` from `element` and `root` types as `HTMLElement` is already nullable
|
|
21
|
+
|
|
8
22
|
## [0.9.2](https://github.com/metonym/svelte-intersection-observer/releases/tag/v0.9.2) - 2021-11-26
|
|
9
23
|
|
|
10
24
|
**Documentation**
|
package/README.md
CHANGED
|
@@ -161,7 +161,7 @@ As an alternative to binding the `intersecting` prop, you can listen to the `int
|
|
|
161
161
|
|
|
162
162
|
The `e.detail` dispatched by the `observe` and `intersect` events is an [`IntersectionObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry) interface.
|
|
163
163
|
|
|
164
|
-
Note that all properties in `IntersectionObserverEntry` are read
|
|
164
|
+
Note that all properties in `IntersectionObserverEntry` are read-only.
|
|
165
165
|
|
|
166
166
|
<details>
|
|
167
167
|
<summary><code>IntersectionObserverEntry</code></summary>
|
package/lib/index.js
CHANGED
|
@@ -337,14 +337,14 @@
|
|
|
337
337
|
/* src/IntersectionObserver.svelte generated by Svelte v3.44.2 */
|
|
338
338
|
|
|
339
339
|
const get_default_slot_changes = dirty => ({
|
|
340
|
-
intersecting: dirty & /*intersecting*/
|
|
341
|
-
entry: dirty & /*entry*/
|
|
340
|
+
intersecting: dirty & /*intersecting*/ 1,
|
|
341
|
+
entry: dirty & /*entry*/ 2,
|
|
342
342
|
observer: dirty & /*observer*/ 4
|
|
343
343
|
});
|
|
344
344
|
|
|
345
345
|
const get_default_slot_context = ctx => ({
|
|
346
|
-
intersecting: /*intersecting*/ ctx[
|
|
347
|
-
entry: /*entry*/ ctx[
|
|
346
|
+
intersecting: /*intersecting*/ ctx[0],
|
|
347
|
+
entry: /*entry*/ ctx[1],
|
|
348
348
|
observer: /*observer*/ ctx[2]
|
|
349
349
|
});
|
|
350
350
|
|
|
@@ -399,11 +399,11 @@
|
|
|
399
399
|
let { $$slots: slots = {}, $$scope } = $$props;
|
|
400
400
|
let { element = null } = $$props;
|
|
401
401
|
let { once = false } = $$props;
|
|
402
|
+
let { intersecting = false } = $$props;
|
|
402
403
|
let { root = null } = $$props;
|
|
403
404
|
let { rootMargin = "0px" } = $$props;
|
|
404
405
|
let { threshold = 0 } = $$props;
|
|
405
406
|
let { entry = null } = $$props;
|
|
406
|
-
let { intersecting = false } = $$props;
|
|
407
407
|
let { observer = null } = $$props;
|
|
408
408
|
const dispatch = createEventDispatcher();
|
|
409
409
|
let prevRootMargin = null;
|
|
@@ -412,8 +412,8 @@
|
|
|
412
412
|
const initialize = () => {
|
|
413
413
|
$$invalidate(2, observer = new IntersectionObserver(entries => {
|
|
414
414
|
entries.forEach(_entry => {
|
|
415
|
-
$$invalidate(
|
|
416
|
-
$$invalidate(
|
|
415
|
+
$$invalidate(1, entry = _entry);
|
|
416
|
+
$$invalidate(0, intersecting = _entry.isIntersecting);
|
|
417
417
|
});
|
|
418
418
|
},
|
|
419
419
|
{ root, rootMargin, threshold }));
|
|
@@ -423,7 +423,10 @@
|
|
|
423
423
|
initialize();
|
|
424
424
|
|
|
425
425
|
return () => {
|
|
426
|
-
if (observer)
|
|
426
|
+
if (observer) {
|
|
427
|
+
observer.disconnect();
|
|
428
|
+
$$invalidate(2, observer = null);
|
|
429
|
+
}
|
|
427
430
|
};
|
|
428
431
|
});
|
|
429
432
|
|
|
@@ -457,18 +460,18 @@
|
|
|
457
460
|
$$self.$$set = $$props => {
|
|
458
461
|
if ('element' in $$props) $$invalidate(3, element = $$props.element);
|
|
459
462
|
if ('once' in $$props) $$invalidate(4, once = $$props.once);
|
|
463
|
+
if ('intersecting' in $$props) $$invalidate(0, intersecting = $$props.intersecting);
|
|
460
464
|
if ('root' in $$props) $$invalidate(5, root = $$props.root);
|
|
461
465
|
if ('rootMargin' in $$props) $$invalidate(6, rootMargin = $$props.rootMargin);
|
|
462
466
|
if ('threshold' in $$props) $$invalidate(7, threshold = $$props.threshold);
|
|
463
|
-
if ('entry' in $$props) $$invalidate(
|
|
464
|
-
if ('intersecting' in $$props) $$invalidate(1, intersecting = $$props.intersecting);
|
|
467
|
+
if ('entry' in $$props) $$invalidate(1, entry = $$props.entry);
|
|
465
468
|
if ('observer' in $$props) $$invalidate(2, observer = $$props.observer);
|
|
466
469
|
if ('$$scope' in $$props) $$invalidate(8, $$scope = $$props.$$scope);
|
|
467
470
|
};
|
|
468
471
|
|
|
469
472
|
return [
|
|
470
|
-
entry,
|
|
471
473
|
intersecting,
|
|
474
|
+
entry,
|
|
472
475
|
observer,
|
|
473
476
|
element,
|
|
474
477
|
once,
|
|
@@ -487,11 +490,11 @@
|
|
|
487
490
|
init(this, options, instance, create_fragment, safe_not_equal, {
|
|
488
491
|
element: 3,
|
|
489
492
|
once: 4,
|
|
493
|
+
intersecting: 0,
|
|
490
494
|
root: 5,
|
|
491
495
|
rootMargin: 6,
|
|
492
496
|
threshold: 7,
|
|
493
|
-
entry:
|
|
494
|
-
intersecting: 1,
|
|
497
|
+
entry: 1,
|
|
495
498
|
observer: 2
|
|
496
499
|
});
|
|
497
500
|
}
|
package/lib/index.mjs
CHANGED
|
@@ -331,14 +331,14 @@ class SvelteComponent {
|
|
|
331
331
|
/* src/IntersectionObserver.svelte generated by Svelte v3.44.2 */
|
|
332
332
|
|
|
333
333
|
const get_default_slot_changes = dirty => ({
|
|
334
|
-
intersecting: dirty & /*intersecting*/
|
|
335
|
-
entry: dirty & /*entry*/
|
|
334
|
+
intersecting: dirty & /*intersecting*/ 1,
|
|
335
|
+
entry: dirty & /*entry*/ 2,
|
|
336
336
|
observer: dirty & /*observer*/ 4
|
|
337
337
|
});
|
|
338
338
|
|
|
339
339
|
const get_default_slot_context = ctx => ({
|
|
340
|
-
intersecting: /*intersecting*/ ctx[
|
|
341
|
-
entry: /*entry*/ ctx[
|
|
340
|
+
intersecting: /*intersecting*/ ctx[0],
|
|
341
|
+
entry: /*entry*/ ctx[1],
|
|
342
342
|
observer: /*observer*/ ctx[2]
|
|
343
343
|
});
|
|
344
344
|
|
|
@@ -393,11 +393,11 @@ function instance($$self, $$props, $$invalidate) {
|
|
|
393
393
|
let { $$slots: slots = {}, $$scope } = $$props;
|
|
394
394
|
let { element = null } = $$props;
|
|
395
395
|
let { once = false } = $$props;
|
|
396
|
+
let { intersecting = false } = $$props;
|
|
396
397
|
let { root = null } = $$props;
|
|
397
398
|
let { rootMargin = "0px" } = $$props;
|
|
398
399
|
let { threshold = 0 } = $$props;
|
|
399
400
|
let { entry = null } = $$props;
|
|
400
|
-
let { intersecting = false } = $$props;
|
|
401
401
|
let { observer = null } = $$props;
|
|
402
402
|
const dispatch = createEventDispatcher();
|
|
403
403
|
let prevRootMargin = null;
|
|
@@ -406,8 +406,8 @@ function instance($$self, $$props, $$invalidate) {
|
|
|
406
406
|
const initialize = () => {
|
|
407
407
|
$$invalidate(2, observer = new IntersectionObserver(entries => {
|
|
408
408
|
entries.forEach(_entry => {
|
|
409
|
-
$$invalidate(
|
|
410
|
-
$$invalidate(
|
|
409
|
+
$$invalidate(1, entry = _entry);
|
|
410
|
+
$$invalidate(0, intersecting = _entry.isIntersecting);
|
|
411
411
|
});
|
|
412
412
|
},
|
|
413
413
|
{ root, rootMargin, threshold }));
|
|
@@ -417,7 +417,10 @@ function instance($$self, $$props, $$invalidate) {
|
|
|
417
417
|
initialize();
|
|
418
418
|
|
|
419
419
|
return () => {
|
|
420
|
-
if (observer)
|
|
420
|
+
if (observer) {
|
|
421
|
+
observer.disconnect();
|
|
422
|
+
$$invalidate(2, observer = null);
|
|
423
|
+
}
|
|
421
424
|
};
|
|
422
425
|
});
|
|
423
426
|
|
|
@@ -451,18 +454,18 @@ function instance($$self, $$props, $$invalidate) {
|
|
|
451
454
|
$$self.$$set = $$props => {
|
|
452
455
|
if ('element' in $$props) $$invalidate(3, element = $$props.element);
|
|
453
456
|
if ('once' in $$props) $$invalidate(4, once = $$props.once);
|
|
457
|
+
if ('intersecting' in $$props) $$invalidate(0, intersecting = $$props.intersecting);
|
|
454
458
|
if ('root' in $$props) $$invalidate(5, root = $$props.root);
|
|
455
459
|
if ('rootMargin' in $$props) $$invalidate(6, rootMargin = $$props.rootMargin);
|
|
456
460
|
if ('threshold' in $$props) $$invalidate(7, threshold = $$props.threshold);
|
|
457
|
-
if ('entry' in $$props) $$invalidate(
|
|
458
|
-
if ('intersecting' in $$props) $$invalidate(1, intersecting = $$props.intersecting);
|
|
461
|
+
if ('entry' in $$props) $$invalidate(1, entry = $$props.entry);
|
|
459
462
|
if ('observer' in $$props) $$invalidate(2, observer = $$props.observer);
|
|
460
463
|
if ('$$scope' in $$props) $$invalidate(8, $$scope = $$props.$$scope);
|
|
461
464
|
};
|
|
462
465
|
|
|
463
466
|
return [
|
|
464
|
-
entry,
|
|
465
467
|
intersecting,
|
|
468
|
+
entry,
|
|
466
469
|
observer,
|
|
467
470
|
element,
|
|
468
471
|
once,
|
|
@@ -481,11 +484,11 @@ class IntersectionObserver_1 extends SvelteComponent {
|
|
|
481
484
|
init(this, options, instance, create_fragment, safe_not_equal, {
|
|
482
485
|
element: 3,
|
|
483
486
|
once: 4,
|
|
487
|
+
intersecting: 0,
|
|
484
488
|
root: 5,
|
|
485
489
|
rootMargin: 6,
|
|
486
490
|
threshold: 7,
|
|
487
|
-
entry:
|
|
488
|
-
intersecting: 1,
|
|
491
|
+
entry: 1,
|
|
489
492
|
observer: 2
|
|
490
493
|
});
|
|
491
494
|
}
|
package/package.json
CHANGED
|
@@ -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 between 0 and 1.
|
|
23
43
|
* @default 0
|
|
24
44
|
*/
|
|
25
45
|
threshold?: 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<
|