svelte-intersection-observer 0.8.0 → 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 +40 -0
- package/README.md +62 -25
- package/lib/index.js +18 -15
- package/lib/index.mjs +18 -15
- package/package.json +6 -6
- package/src/IntersectionObserver.svelte +26 -22
- package/types/IntersectionObserver.svelte.d.ts +39 -13
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,46 @@ 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
|
+
|
|
22
|
+
## [0.9.2](https://github.com/metonym/svelte-intersection-observer/releases/tag/v0.9.2) - 2021-11-26
|
|
23
|
+
|
|
24
|
+
**Documentation**
|
|
25
|
+
|
|
26
|
+
- add `let:` directive example
|
|
27
|
+
- update component prop descriptions
|
|
28
|
+
- use Svelte syntax highlighting for `on:observe`, `on:intersect` examples
|
|
29
|
+
|
|
30
|
+
## [0.9.1](https://github.com/metonym/svelte-intersection-observer/releases/tag/v0.9.1) - 2021-10-25
|
|
31
|
+
|
|
32
|
+
**Documentation**
|
|
33
|
+
|
|
34
|
+
- update the "Once" example to include the `"svelte-intersection-observer"` import
|
|
35
|
+
- rename example `svite` to `vite`
|
|
36
|
+
|
|
37
|
+
**Refactoring**
|
|
38
|
+
|
|
39
|
+
- inline `entry` prop typedef
|
|
40
|
+
- remove `@event`, `@slot` artifacts used by sveld to generate initial TypeScript definitions
|
|
41
|
+
|
|
42
|
+
## [0.9.0](https://github.com/metonym/svelte-intersection-observer/releases/tag/v0.9.0) - 2021-10-05
|
|
43
|
+
|
|
44
|
+
- improve TypeScript definitions for dispatched events
|
|
45
|
+
- `on:observe`: `event.detail.isIntersecting` is a `boolean`
|
|
46
|
+
- `on:intersect`: `event.detail.isIntersecting` can only be `true`
|
|
47
|
+
|
|
8
48
|
## [0.8.0](https://github.com/metonym/svelte-intersection-observer/releases/tag/v0.8.0) - 2021-09-02
|
|
9
49
|
|
|
10
50
|
- use `.svelte.d.ts` extension for component TypeScript definition
|
package/README.md
CHANGED
|
@@ -24,6 +24,12 @@ yarn add -D svelte-intersection-observer
|
|
|
24
24
|
npm i -D svelte-intersection-observer
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
**pnpm**
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm i -D svelte-intersection-observer
|
|
31
|
+
```
|
|
32
|
+
|
|
27
33
|
## Usage
|
|
28
34
|
|
|
29
35
|
### Basic
|
|
@@ -55,7 +61,9 @@ Set `once` to `true` for the intersection event to occur only once. The `element
|
|
|
55
61
|
|
|
56
62
|
```svelte
|
|
57
63
|
<script>
|
|
58
|
-
|
|
64
|
+
import IntersectionObserver from "svelte-intersection-observer";
|
|
65
|
+
|
|
66
|
+
let elementOnce;
|
|
59
67
|
let intersectOnce;
|
|
60
68
|
</script>
|
|
61
69
|
|
|
@@ -63,42 +71,71 @@ Set `once` to `true` for the intersection event to occur only once. The `element
|
|
|
63
71
|
{intersectOnce ? "Element is in view" : "Element is not in view"}
|
|
64
72
|
</header>
|
|
65
73
|
|
|
66
|
-
<IntersectionObserver
|
|
67
|
-
|
|
74
|
+
<IntersectionObserver
|
|
75
|
+
once
|
|
76
|
+
element={elementOnce}
|
|
77
|
+
bind:intersecting={intersectOnce}
|
|
78
|
+
>
|
|
79
|
+
<div bind:this={elementOnce}>Hello world</div>
|
|
68
80
|
</IntersectionObserver>
|
|
69
81
|
```
|
|
70
82
|
|
|
71
|
-
###
|
|
83
|
+
### `let:intersecting`
|
|
84
|
+
|
|
85
|
+
An alternative to binding to the `intersecting` prop is to use the `let:` directive.
|
|
86
|
+
|
|
87
|
+
In the following example, the "Hello world" element will fade in when its containing element intersects the viewport.
|
|
88
|
+
|
|
89
|
+
```svelte
|
|
90
|
+
<script>
|
|
91
|
+
import IntersectionObserver from "svelte-intersection-observer";
|
|
92
|
+
import { fade } from "svelte/transition";
|
|
93
|
+
|
|
94
|
+
let node;
|
|
95
|
+
</script>
|
|
96
|
+
|
|
97
|
+
<header />
|
|
98
|
+
|
|
99
|
+
<IntersectionObserver element={node} let:intersecting>
|
|
100
|
+
<div bind:this={node}>
|
|
101
|
+
{#if intersecting}
|
|
102
|
+
<div transition:fade={{ delay: 200 }}>Hello world</div>
|
|
103
|
+
{/if}
|
|
104
|
+
</div>
|
|
105
|
+
</IntersectionObserver>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### `on:observe` event
|
|
72
109
|
|
|
73
110
|
The `observe` event is dispatched when the element is first observed and also whenever an intersection event occurs.
|
|
74
111
|
|
|
75
|
-
```
|
|
112
|
+
```svelte no-eval
|
|
76
113
|
<IntersectionObserver
|
|
77
114
|
{element}
|
|
78
|
-
on:observe=
|
|
115
|
+
on:observe={(e) => {
|
|
79
116
|
console.log(e.detail); // IntersectionObserverEntry
|
|
80
117
|
console.log(e.detail.isIntersecting); // true | false
|
|
81
|
-
}}
|
|
118
|
+
}}
|
|
82
119
|
>
|
|
83
|
-
<div bind:this=
|
|
120
|
+
<div bind:this={element}>Hello world</div>
|
|
84
121
|
</IntersectionObserver>
|
|
85
122
|
```
|
|
86
123
|
|
|
87
|
-
### on:intersect event
|
|
124
|
+
### `on:intersect` event
|
|
88
125
|
|
|
89
126
|
As an alternative to binding the `intersecting` prop, you can listen to the `intersect` event that is dispatched if the observed element is intersecting the viewport.
|
|
90
127
|
|
|
91
128
|
**Note**: Compared to `on:observe`, `on:intersect` is dispatched only when the element is _intersecting the viewport_. In other words, `e.detail.isIntersecting` will only be `true`.
|
|
92
129
|
|
|
93
|
-
```
|
|
130
|
+
```svelte no-eval
|
|
94
131
|
<IntersectionObserver
|
|
95
132
|
{element}
|
|
96
|
-
on:intersect=
|
|
133
|
+
on:intersect={(e) => {
|
|
97
134
|
console.log(e.detail); // IntersectionObserverEntry
|
|
98
135
|
console.log(e.detail.isIntersecting); // true
|
|
99
|
-
}}
|
|
136
|
+
}}
|
|
100
137
|
>
|
|
101
|
-
<div bind:this=
|
|
138
|
+
<div bind:this={element}>Hello world</div>
|
|
102
139
|
</IntersectionObserver>
|
|
103
140
|
```
|
|
104
141
|
|
|
@@ -106,16 +143,16 @@ As an alternative to binding the `intersecting` prop, you can listen to the `int
|
|
|
106
143
|
|
|
107
144
|
### Props
|
|
108
145
|
|
|
109
|
-
| Name | Description
|
|
110
|
-
| :----------- |
|
|
111
|
-
| element |
|
|
112
|
-
| once |
|
|
113
|
-
| intersecting | `true` if the observed element is intersecting the viewport
|
|
114
|
-
| root | Containing element
|
|
115
|
-
| rootMargin | Margin offset of the containing element
|
|
116
|
-
| threshold | Percentage of element
|
|
117
|
-
| entry | Observed element metadata
|
|
118
|
-
| observer | IntersectionObserver instance
|
|
146
|
+
| Name | Description | Type | Default value |
|
|
147
|
+
| :----------- | :---------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------- | :------------ |
|
|
148
|
+
| element | Observed element | `HTMLElement` | `null` |
|
|
149
|
+
| once | Unobserve the element after the first intersection event | `boolean` | `false` |
|
|
150
|
+
| intersecting | `true` if the observed element is intersecting the viewport | `boolean` | `false` |
|
|
151
|
+
| root | Containing element | `null` or `HTMLElement` | `null` |
|
|
152
|
+
| rootMargin | Margin offset of the containing element | `string` | `"0px"` |
|
|
153
|
+
| threshold | Percentage of element visibile to trigger an event | `number` between 0 and 1 | `0` |
|
|
154
|
+
| entry | Observed element metadata | [`IntersectionObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry) | `null` |
|
|
155
|
+
| observer | `IntersectionObserver` instance | [`IntersectionObserver`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver) | `null` |
|
|
119
156
|
|
|
120
157
|
### Dispatched events
|
|
121
158
|
|
|
@@ -124,7 +161,7 @@ As an alternative to binding the `intersecting` prop, you can listen to the `int
|
|
|
124
161
|
|
|
125
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.
|
|
126
163
|
|
|
127
|
-
Note that all properties in `IntersectionObserverEntry` are read
|
|
164
|
+
Note that all properties in `IntersectionObserverEntry` are read-only.
|
|
128
165
|
|
|
129
166
|
<details>
|
|
130
167
|
<summary><code>IntersectionObserverEntry</code></summary>
|
|
@@ -176,7 +213,7 @@ interface IntersectionObserverEntry {
|
|
|
176
213
|
The [examples folder](examples/) contains sample set-ups.
|
|
177
214
|
|
|
178
215
|
- [examples/sveltekit](examples/sveltekit)
|
|
179
|
-
- [examples/
|
|
216
|
+
- [examples/vite](examples/vite)
|
|
180
217
|
- [examples/sapper](examples/sapper)
|
|
181
218
|
- [examples/snowpack](examples/snowpack)
|
|
182
219
|
- [examples/rollup](examples/rollup)
|
package/lib/index.js
CHANGED
|
@@ -264,7 +264,7 @@
|
|
|
264
264
|
on_disconnect: [],
|
|
265
265
|
before_update: [],
|
|
266
266
|
after_update: [],
|
|
267
|
-
context: new Map(parent_component ? parent_component.$$.context :
|
|
267
|
+
context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
|
|
268
268
|
// everything else
|
|
269
269
|
callbacks: blank_object(),
|
|
270
270
|
dirty,
|
|
@@ -334,17 +334,17 @@
|
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
/* src/IntersectionObserver.svelte generated by Svelte v3.
|
|
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
|
@@ -258,7 +258,7 @@ function init(component, options, instance, create_fragment, not_equal, props, a
|
|
|
258
258
|
on_disconnect: [],
|
|
259
259
|
before_update: [],
|
|
260
260
|
after_update: [],
|
|
261
|
-
context: new Map(parent_component ? parent_component.$$.context :
|
|
261
|
+
context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
|
|
262
262
|
// everything else
|
|
263
263
|
callbacks: blank_object(),
|
|
264
264
|
dirty,
|
|
@@ -328,17 +328,17 @@ class SvelteComponent {
|
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
330
|
|
|
331
|
-
/* src/IntersectionObserver.svelte generated by Svelte v3.
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-intersection-observer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
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)",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"format": "prettier --write '.'"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"prettier": "^2.
|
|
21
|
-
"prettier-plugin-svelte": "^2.
|
|
22
|
-
"svelte": "^3.
|
|
23
|
-
"svelte-check": "^2.2.
|
|
24
|
-
"svelte-readme": "^3.
|
|
20
|
+
"prettier": "^2.5.0",
|
|
21
|
+
"prettier-plugin-svelte": "^2.5.0",
|
|
22
|
+
"svelte": "^3.44.2",
|
|
23
|
+
"svelte-check": "^2.2.10",
|
|
24
|
+
"svelte-readme": "^3.6.1"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
|
@@ -1,48 +1,49 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @event {Entry} intersect
|
|
6
|
-
* @slot {{ intersecting: boolean; entry: Entry; observer: IntersectionObserver }}
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The HTML Element to observe
|
|
11
|
-
* @type {null | HTMLElement}
|
|
3
|
+
* The HTML Element to observe.
|
|
4
|
+
* @type {HTMLElement}
|
|
12
5
|
*/
|
|
13
6
|
export let element = null;
|
|
14
7
|
|
|
15
8
|
/**
|
|
16
|
-
* Set to `true` to unobserve the element
|
|
9
|
+
* Set to `true` to unobserve the element
|
|
10
|
+
* after it intersects the viewport.
|
|
17
11
|
* @type {boolean}
|
|
18
12
|
*/
|
|
19
13
|
export let once = false;
|
|
20
14
|
|
|
21
15
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
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}
|
|
25
25
|
*/
|
|
26
26
|
export let root = null;
|
|
27
27
|
|
|
28
|
-
/** Margin offset of the containing element */
|
|
28
|
+
/** Margin offset of the containing element. */
|
|
29
29
|
export let rootMargin = "0px";
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* Percentage of element visibility to trigger an event
|
|
33
|
-
* Value must be between 0 and 1
|
|
32
|
+
* Percentage of element visibility to trigger an event.
|
|
33
|
+
* Value must be between 0 and 1.
|
|
34
34
|
*/
|
|
35
35
|
export let threshold = 0;
|
|
36
36
|
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Observed element metadata.
|
|
39
|
+
* @type {null | IntersectionObserverEntry}
|
|
40
|
+
*/
|
|
38
41
|
export let entry = null;
|
|
39
42
|
|
|
40
43
|
/**
|
|
41
|
-
* `
|
|
44
|
+
* `IntersectionObserver` instance.
|
|
45
|
+
* @type {null | IntersectionObserver}
|
|
42
46
|
*/
|
|
43
|
-
export let intersecting = false;
|
|
44
|
-
|
|
45
|
-
/** @type {null | IntersectionObserver} */
|
|
46
47
|
export let observer = null;
|
|
47
48
|
|
|
48
49
|
import { tick, createEventDispatcher, afterUpdate, onMount } from "svelte";
|
|
@@ -68,7 +69,10 @@
|
|
|
68
69
|
initialize();
|
|
69
70
|
|
|
70
71
|
return () => {
|
|
71
|
-
if (observer)
|
|
72
|
+
if (observer) {
|
|
73
|
+
observer.disconnect();
|
|
74
|
+
observer = null;
|
|
75
|
+
}
|
|
72
76
|
};
|
|
73
77
|
});
|
|
74
78
|
|
|
@@ -5,49 +5,75 @@ 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<
|
|
49
61
|
IntersectionObserverProps,
|
|
50
|
-
{
|
|
62
|
+
{
|
|
63
|
+
/**
|
|
64
|
+
* Dispatched when the element is first observed
|
|
65
|
+
* and also whenever an intersection event occurs.
|
|
66
|
+
*/
|
|
67
|
+
observe: CustomEvent<IntersectionObserverEntry>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Dispatched only when the element is intersecting the viewport.
|
|
71
|
+
* `event.detail.isIntersecting` will only be `true`
|
|
72
|
+
*/
|
|
73
|
+
intersect: CustomEvent<
|
|
74
|
+
IntersectionObserverEntry & { isIntersecting: true }
|
|
75
|
+
>;
|
|
76
|
+
},
|
|
51
77
|
{
|
|
52
78
|
default: {
|
|
53
79
|
intersecting: boolean;
|