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/lib/index.mjs CHANGED
@@ -1,344 +1,609 @@
1
- function noop() { }
1
+ /** @returns {void} */
2
+ function noop() {}
3
+
4
+ /**
5
+ * @template T
6
+ * @template S
7
+ * @param {T} tar
8
+ * @param {S} src
9
+ * @returns {T & S}
10
+ */
2
11
  function assign(tar, src) {
3
- // @ts-ignore
4
- for (const k in src)
5
- tar[k] = src[k];
6
- return tar;
12
+ // @ts-ignore
13
+ for (const k in src) tar[k] = src[k];
14
+ return /** @type {T & S} */ (tar);
7
15
  }
16
+
8
17
  function run(fn) {
9
- return fn();
18
+ return fn();
10
19
  }
20
+
11
21
  function blank_object() {
12
- return Object.create(null);
22
+ return Object.create(null);
13
23
  }
24
+
25
+ /**
26
+ * @param {Function[]} fns
27
+ * @returns {void}
28
+ */
14
29
  function run_all(fns) {
15
- fns.forEach(run);
30
+ fns.forEach(run);
16
31
  }
32
+
33
+ /**
34
+ * @param {any} thing
35
+ * @returns {thing is Function}
36
+ */
17
37
  function is_function(thing) {
18
- return typeof thing === 'function';
38
+ return typeof thing === 'function';
19
39
  }
40
+
41
+ /** @returns {boolean} */
20
42
  function safe_not_equal(a, b) {
21
- return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
43
+ return a != a ? b == b : a !== b || (a && typeof a === 'object') || typeof a === 'function';
22
44
  }
45
+
46
+ /** @returns {boolean} */
23
47
  function is_empty(obj) {
24
- return Object.keys(obj).length === 0;
48
+ return Object.keys(obj).length === 0;
25
49
  }
50
+
26
51
  function create_slot(definition, ctx, $$scope, fn) {
27
- if (definition) {
28
- const slot_ctx = get_slot_context(definition, ctx, $$scope, fn);
29
- return definition[0](slot_ctx);
30
- }
52
+ if (definition) {
53
+ const slot_ctx = get_slot_context(definition, ctx, $$scope, fn);
54
+ return definition[0](slot_ctx);
55
+ }
31
56
  }
57
+
32
58
  function get_slot_context(definition, ctx, $$scope, fn) {
33
- return definition[1] && fn
34
- ? assign($$scope.ctx.slice(), definition[1](fn(ctx)))
35
- : $$scope.ctx;
59
+ return definition[1] && fn ? assign($$scope.ctx.slice(), definition[1](fn(ctx))) : $$scope.ctx;
36
60
  }
61
+
37
62
  function get_slot_changes(definition, $$scope, dirty, fn) {
38
- if (definition[2] && fn) {
39
- const lets = definition[2](fn(dirty));
40
- if ($$scope.dirty === undefined) {
41
- return lets;
42
- }
43
- if (typeof lets === 'object') {
44
- const merged = [];
45
- const len = Math.max($$scope.dirty.length, lets.length);
46
- for (let i = 0; i < len; i += 1) {
47
- merged[i] = $$scope.dirty[i] | lets[i];
48
- }
49
- return merged;
50
- }
51
- return $$scope.dirty | lets;
52
- }
53
- return $$scope.dirty;
54
- }
55
- function update_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn) {
56
- if (slot_changes) {
57
- const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);
58
- slot.p(slot_context, slot_changes);
59
- }
63
+ if (definition[2] && fn) {
64
+ const lets = definition[2](fn(dirty));
65
+ if ($$scope.dirty === undefined) {
66
+ return lets;
67
+ }
68
+ if (typeof lets === 'object') {
69
+ const merged = [];
70
+ const len = Math.max($$scope.dirty.length, lets.length);
71
+ for (let i = 0; i < len; i += 1) {
72
+ merged[i] = $$scope.dirty[i] | lets[i];
73
+ }
74
+ return merged;
75
+ }
76
+ return $$scope.dirty | lets;
77
+ }
78
+ return $$scope.dirty;
60
79
  }
80
+
81
+ /** @returns {void} */
82
+ function update_slot_base(
83
+ slot,
84
+ slot_definition,
85
+ ctx,
86
+ $$scope,
87
+ slot_changes,
88
+ get_slot_context_fn
89
+ ) {
90
+ if (slot_changes) {
91
+ const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);
92
+ slot.p(slot_context, slot_changes);
93
+ }
94
+ }
95
+
96
+ /** @returns {any[] | -1} */
61
97
  function get_all_dirty_from_scope($$scope) {
62
- if ($$scope.ctx.length > 32) {
63
- const dirty = [];
64
- const length = $$scope.ctx.length / 32;
65
- for (let i = 0; i < length; i++) {
66
- dirty[i] = -1;
67
- }
68
- return dirty;
69
- }
70
- return -1;
98
+ if ($$scope.ctx.length > 32) {
99
+ const dirty = [];
100
+ const length = $$scope.ctx.length / 32;
101
+ for (let i = 0; i < length; i++) {
102
+ dirty[i] = -1;
103
+ }
104
+ return dirty;
105
+ }
106
+ return -1;
71
107
  }
108
+
109
+ /**
110
+ * @param {Node} node
111
+ * @returns {void}
112
+ */
72
113
  function detach(node) {
73
- node.parentNode.removeChild(node);
114
+ if (node.parentNode) {
115
+ node.parentNode.removeChild(node);
116
+ }
74
117
  }
118
+
119
+ /**
120
+ * @param {Element} element
121
+ * @returns {ChildNode[]}
122
+ */
75
123
  function children(element) {
76
- return Array.from(element.childNodes);
124
+ return Array.from(element.childNodes);
77
125
  }
78
- function custom_event(type, detail, bubbles = false) {
79
- const e = document.createEvent('CustomEvent');
80
- e.initCustomEvent(type, bubbles, false, detail);
81
- return e;
126
+
127
+ /**
128
+ * @template T
129
+ * @param {string} type
130
+ * @param {T} [detail]
131
+ * @param {{ bubbles?: boolean, cancelable?: boolean }} [options]
132
+ * @returns {CustomEvent<T>}
133
+ */
134
+ function custom_event(type, detail, { bubbles = false, cancelable = false } = {}) {
135
+ return new CustomEvent(type, { detail, bubbles, cancelable });
82
136
  }
83
137
 
138
+ /**
139
+ * @typedef {Node & {
140
+ * claim_order?: number;
141
+ * hydrate_init?: true;
142
+ * actual_end_child?: NodeEx;
143
+ * childNodes: NodeListOf<NodeEx>;
144
+ * }} NodeEx
145
+ */
146
+
147
+ /** @typedef {ChildNode & NodeEx} ChildNodeEx */
148
+
149
+ /** @typedef {NodeEx & { claim_order: number }} NodeEx2 */
150
+
151
+ /**
152
+ * @typedef {ChildNodeEx[] & {
153
+ * claim_info?: {
154
+ * last_index: number;
155
+ * total_claimed: number;
156
+ * };
157
+ * }} ChildNodeArray
158
+ */
159
+
84
160
  let current_component;
161
+
162
+ /** @returns {void} */
85
163
  function set_current_component(component) {
86
- current_component = component;
164
+ current_component = component;
87
165
  }
166
+
88
167
  function get_current_component() {
89
- if (!current_component)
90
- throw new Error('Function called outside component initialization');
91
- return current_component;
92
- }
93
- function onMount(fn) {
94
- get_current_component().$$.on_mount.push(fn);
95
- }
96
- function afterUpdate(fn) {
97
- get_current_component().$$.after_update.push(fn);
168
+ if (!current_component) throw new Error('Function called outside component initialization');
169
+ return current_component;
98
170
  }
171
+
172
+ /**
173
+ * Creates an event dispatcher that can be used to dispatch [component events](/docs#template-syntax-component-directives-on-eventname).
174
+ * Event dispatchers are functions that can take two arguments: `name` and `detail`.
175
+ *
176
+ * Component events created with `createEventDispatcher` create a
177
+ * [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent).
178
+ * These events do not [bubble](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#Event_bubbling_and_capture).
179
+ * The `detail` argument corresponds to the [CustomEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail)
180
+ * property and can contain any type of data.
181
+ *
182
+ * The event dispatcher can be typed to narrow the allowed event names and the type of the `detail` argument:
183
+ * ```ts
184
+ * const dispatch = createEventDispatcher<{
185
+ * loaded: never; // does not take a detail argument
186
+ * change: string; // takes a detail argument of type string, which is required
187
+ * optional: number | null; // takes an optional detail argument of type number
188
+ * }>();
189
+ * ```
190
+ *
191
+ * https://svelte.dev/docs/svelte#createeventdispatcher
192
+ * @template {Record<string, any>} [EventMap=any]
193
+ * @returns {import('./public.js').EventDispatcher<EventMap>}
194
+ */
99
195
  function createEventDispatcher() {
100
- const component = get_current_component();
101
- return (type, detail) => {
102
- const callbacks = component.$$.callbacks[type];
103
- if (callbacks) {
104
- // TODO are there situations where events could be dispatched
105
- // in a server (non-DOM) environment?
106
- const event = custom_event(type, detail);
107
- callbacks.slice().forEach(fn => {
108
- fn.call(component, event);
109
- });
110
- }
111
- };
196
+ const component = get_current_component();
197
+ return (type, detail, { cancelable = false } = {}) => {
198
+ const callbacks = component.$$.callbacks[type];
199
+ if (callbacks) {
200
+ // TODO are there situations where events could be dispatched
201
+ // in a server (non-DOM) environment?
202
+ const event = custom_event(/** @type {string} */ (type), detail, { cancelable });
203
+ callbacks.slice().forEach((fn) => {
204
+ fn.call(component, event);
205
+ });
206
+ return !event.defaultPrevented;
207
+ }
208
+ return true;
209
+ };
112
210
  }
113
211
 
114
212
  const dirty_components = [];
115
213
  const binding_callbacks = [];
116
- const render_callbacks = [];
214
+
215
+ let render_callbacks = [];
216
+
117
217
  const flush_callbacks = [];
118
- const resolved_promise = Promise.resolve();
218
+
219
+ const resolved_promise = /* @__PURE__ */ Promise.resolve();
220
+
119
221
  let update_scheduled = false;
222
+
223
+ /** @returns {void} */
120
224
  function schedule_update() {
121
- if (!update_scheduled) {
122
- update_scheduled = true;
123
- resolved_promise.then(flush);
124
- }
125
- }
126
- function tick() {
127
- schedule_update();
128
- return resolved_promise;
225
+ if (!update_scheduled) {
226
+ update_scheduled = true;
227
+ resolved_promise.then(flush);
228
+ }
129
229
  }
230
+
231
+ /** @returns {void} */
130
232
  function add_render_callback(fn) {
131
- render_callbacks.push(fn);
233
+ render_callbacks.push(fn);
132
234
  }
133
- let flushing = false;
235
+
236
+ // flush() calls callbacks in this order:
237
+ // 1. All beforeUpdate callbacks, in order: parents before children
238
+ // 2. All bind:this callbacks, in reverse order: children before parents.
239
+ // 3. All afterUpdate callbacks, in order: parents before children. EXCEPT
240
+ // for afterUpdates called during the initial onMount, which are called in
241
+ // reverse order: children before parents.
242
+ // Since callbacks might update component values, which could trigger another
243
+ // call to flush(), the following steps guard against this:
244
+ // 1. During beforeUpdate, any updated components will be added to the
245
+ // dirty_components array and will cause a reentrant call to flush(). Because
246
+ // the flush index is kept outside the function, the reentrant call will pick
247
+ // up where the earlier call left off and go through all dirty components. The
248
+ // current_component value is saved and restored so that the reentrant call will
249
+ // not interfere with the "parent" flush() call.
250
+ // 2. bind:this callbacks cannot trigger new flush() calls.
251
+ // 3. During afterUpdate, any updated components will NOT have their afterUpdate
252
+ // callback called a second time; the seen_callbacks set, outside the flush()
253
+ // function, guarantees this behavior.
134
254
  const seen_callbacks = new Set();
255
+
256
+ let flushidx = 0; // Do *not* move this inside the flush() function
257
+
258
+ /** @returns {void} */
135
259
  function flush() {
136
- if (flushing)
137
- return;
138
- flushing = true;
139
- do {
140
- // first, call beforeUpdate functions
141
- // and update components
142
- for (let i = 0; i < dirty_components.length; i += 1) {
143
- const component = dirty_components[i];
144
- set_current_component(component);
145
- update(component.$$);
146
- }
147
- set_current_component(null);
148
- dirty_components.length = 0;
149
- while (binding_callbacks.length)
150
- binding_callbacks.pop()();
151
- // then, once components are updated, call
152
- // afterUpdate functions. This may cause
153
- // subsequent updates...
154
- for (let i = 0; i < render_callbacks.length; i += 1) {
155
- const callback = render_callbacks[i];
156
- if (!seen_callbacks.has(callback)) {
157
- // ...so guard against infinite loops
158
- seen_callbacks.add(callback);
159
- callback();
160
- }
161
- }
162
- render_callbacks.length = 0;
163
- } while (dirty_components.length);
164
- while (flush_callbacks.length) {
165
- flush_callbacks.pop()();
166
- }
167
- update_scheduled = false;
168
- flushing = false;
169
- seen_callbacks.clear();
260
+ // Do not reenter flush while dirty components are updated, as this can
261
+ // result in an infinite loop. Instead, let the inner flush handle it.
262
+ // Reentrancy is ok afterwards for bindings etc.
263
+ if (flushidx !== 0) {
264
+ return;
265
+ }
266
+ const saved_component = current_component;
267
+ do {
268
+ // first, call beforeUpdate functions
269
+ // and update components
270
+ try {
271
+ while (flushidx < dirty_components.length) {
272
+ const component = dirty_components[flushidx];
273
+ flushidx++;
274
+ set_current_component(component);
275
+ update(component.$$);
276
+ }
277
+ } catch (e) {
278
+ // reset dirty state to not end up in a deadlocked state and then rethrow
279
+ dirty_components.length = 0;
280
+ flushidx = 0;
281
+ throw e;
282
+ }
283
+ set_current_component(null);
284
+ dirty_components.length = 0;
285
+ flushidx = 0;
286
+ while (binding_callbacks.length) binding_callbacks.pop()();
287
+ // then, once components are updated, call
288
+ // afterUpdate functions. This may cause
289
+ // subsequent updates...
290
+ for (let i = 0; i < render_callbacks.length; i += 1) {
291
+ const callback = render_callbacks[i];
292
+ if (!seen_callbacks.has(callback)) {
293
+ // ...so guard against infinite loops
294
+ seen_callbacks.add(callback);
295
+ callback();
296
+ }
297
+ }
298
+ render_callbacks.length = 0;
299
+ } while (dirty_components.length);
300
+ while (flush_callbacks.length) {
301
+ flush_callbacks.pop()();
302
+ }
303
+ update_scheduled = false;
304
+ seen_callbacks.clear();
305
+ set_current_component(saved_component);
170
306
  }
307
+
308
+ /** @returns {void} */
171
309
  function update($$) {
172
- if ($$.fragment !== null) {
173
- $$.update();
174
- run_all($$.before_update);
175
- const dirty = $$.dirty;
176
- $$.dirty = [-1];
177
- $$.fragment && $$.fragment.p($$.ctx, dirty);
178
- $$.after_update.forEach(add_render_callback);
179
- }
310
+ if ($$.fragment !== null) {
311
+ $$.update();
312
+ run_all($$.before_update);
313
+ const dirty = $$.dirty;
314
+ $$.dirty = [-1];
315
+ $$.fragment && $$.fragment.p($$.ctx, dirty);
316
+ $$.after_update.forEach(add_render_callback);
317
+ }
318
+ }
319
+
320
+ /**
321
+ * Useful for example to execute remaining `afterUpdate` callbacks before executing `destroy`.
322
+ * @param {Function[]} fns
323
+ * @returns {void}
324
+ */
325
+ function flush_render_callbacks(fns) {
326
+ const filtered = [];
327
+ const targets = [];
328
+ render_callbacks.forEach((c) => (fns.indexOf(c) === -1 ? filtered.push(c) : targets.push(c)));
329
+ targets.forEach((c) => c());
330
+ render_callbacks = filtered;
180
331
  }
332
+
181
333
  const outroing = new Set();
334
+
335
+ /**
336
+ * @type {Outro}
337
+ */
182
338
  let outros;
339
+
340
+ /**
341
+ * @param {import('./private.js').Fragment} block
342
+ * @param {0 | 1} [local]
343
+ * @returns {void}
344
+ */
183
345
  function transition_in(block, local) {
184
- if (block && block.i) {
185
- outroing.delete(block);
186
- block.i(local);
187
- }
346
+ if (block && block.i) {
347
+ outroing.delete(block);
348
+ block.i(local);
349
+ }
188
350
  }
351
+
352
+ /**
353
+ * @param {import('./private.js').Fragment} block
354
+ * @param {0 | 1} local
355
+ * @param {0 | 1} [detach]
356
+ * @param {() => void} [callback]
357
+ * @returns {void}
358
+ */
189
359
  function transition_out(block, local, detach, callback) {
190
- if (block && block.o) {
191
- if (outroing.has(block))
192
- return;
193
- outroing.add(block);
194
- outros.c.push(() => {
195
- outroing.delete(block);
196
- if (callback) {
197
- if (detach)
198
- block.d(1);
199
- callback();
200
- }
201
- });
202
- block.o(local);
203
- }
204
- }
205
- function mount_component(component, target, anchor, customElement) {
206
- const { fragment, on_mount, on_destroy, after_update } = component.$$;
207
- fragment && fragment.m(target, anchor);
208
- if (!customElement) {
209
- // onMount happens before the initial afterUpdate
210
- add_render_callback(() => {
211
- const new_on_destroy = on_mount.map(run).filter(is_function);
212
- if (on_destroy) {
213
- on_destroy.push(...new_on_destroy);
214
- }
215
- else {
216
- // Edge case - component was destroyed immediately,
217
- // most likely as a result of a binding initialising
218
- run_all(new_on_destroy);
219
- }
220
- component.$$.on_mount = [];
221
- });
222
- }
223
- after_update.forEach(add_render_callback);
360
+ if (block && block.o) {
361
+ if (outroing.has(block)) return;
362
+ outroing.add(block);
363
+ outros.c.push(() => {
364
+ outroing.delete(block);
365
+ if (callback) {
366
+ if (detach) block.d(1);
367
+ callback();
368
+ }
369
+ });
370
+ block.o(local);
371
+ } else if (callback) {
372
+ callback();
373
+ }
224
374
  }
375
+
376
+ /** @typedef {1} INTRO */
377
+ /** @typedef {0} OUTRO */
378
+ /** @typedef {{ direction: 'in' | 'out' | 'both' }} TransitionOptions */
379
+ /** @typedef {(node: Element, params: any, options: TransitionOptions) => import('../transition/public.js').TransitionConfig} TransitionFn */
380
+
381
+ /**
382
+ * @typedef {Object} Outro
383
+ * @property {number} r
384
+ * @property {Function[]} c
385
+ * @property {Object} p
386
+ */
387
+
388
+ /**
389
+ * @typedef {Object} PendingProgram
390
+ * @property {number} start
391
+ * @property {INTRO|OUTRO} b
392
+ * @property {Outro} [group]
393
+ */
394
+
395
+ /**
396
+ * @typedef {Object} Program
397
+ * @property {number} a
398
+ * @property {INTRO|OUTRO} b
399
+ * @property {1|-1} d
400
+ * @property {number} duration
401
+ * @property {number} start
402
+ * @property {number} end
403
+ * @property {Outro} [group]
404
+ */
405
+
406
+ /** @returns {void} */
407
+ function mount_component(component, target, anchor) {
408
+ const { fragment, after_update } = component.$$;
409
+ fragment && fragment.m(target, anchor);
410
+ // onMount happens before the initial afterUpdate
411
+ add_render_callback(() => {
412
+ const new_on_destroy = component.$$.on_mount.map(run).filter(is_function);
413
+ // if the component was destroyed immediately
414
+ // it will update the `$$.on_destroy` reference to `null`.
415
+ // the destructured on_destroy may still reference to the old array
416
+ if (component.$$.on_destroy) {
417
+ component.$$.on_destroy.push(...new_on_destroy);
418
+ } else {
419
+ // Edge case - component was destroyed immediately,
420
+ // most likely as a result of a binding initialising
421
+ run_all(new_on_destroy);
422
+ }
423
+ component.$$.on_mount = [];
424
+ });
425
+ after_update.forEach(add_render_callback);
426
+ }
427
+
428
+ /** @returns {void} */
225
429
  function destroy_component(component, detaching) {
226
- const $$ = component.$$;
227
- if ($$.fragment !== null) {
228
- run_all($$.on_destroy);
229
- $$.fragment && $$.fragment.d(detaching);
230
- // TODO null out other refs, including component.$$ (but need to
231
- // preserve final state?)
232
- $$.on_destroy = $$.fragment = null;
233
- $$.ctx = [];
234
- }
430
+ const $$ = component.$$;
431
+ if ($$.fragment !== null) {
432
+ flush_render_callbacks($$.after_update);
433
+ run_all($$.on_destroy);
434
+ $$.fragment && $$.fragment.d(detaching);
435
+ // TODO null out other refs, including component.$$ (but need to
436
+ // preserve final state?)
437
+ $$.on_destroy = $$.fragment = null;
438
+ $$.ctx = [];
439
+ }
235
440
  }
441
+
442
+ /** @returns {void} */
236
443
  function make_dirty(component, i) {
237
- if (component.$$.dirty[0] === -1) {
238
- dirty_components.push(component);
239
- schedule_update();
240
- component.$$.dirty.fill(0);
241
- }
242
- component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
243
- }
244
- function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) {
245
- const parent_component = current_component;
246
- set_current_component(component);
247
- const $$ = component.$$ = {
248
- fragment: null,
249
- ctx: null,
250
- // state
251
- props,
252
- update: noop,
253
- not_equal,
254
- bound: blank_object(),
255
- // lifecycle
256
- on_mount: [],
257
- on_destroy: [],
258
- on_disconnect: [],
259
- before_update: [],
260
- after_update: [],
261
- context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
262
- // everything else
263
- callbacks: blank_object(),
264
- dirty,
265
- skip_bound: false,
266
- root: options.target || parent_component.$$.root
267
- };
268
- append_styles && append_styles($$.root);
269
- let ready = false;
270
- $$.ctx = instance
271
- ? instance(component, options.props || {}, (i, ret, ...rest) => {
272
- const value = rest.length ? rest[0] : ret;
273
- if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
274
- if (!$$.skip_bound && $$.bound[i])
275
- $$.bound[i](value);
276
- if (ready)
277
- make_dirty(component, i);
278
- }
279
- return ret;
280
- })
281
- : [];
282
- $$.update();
283
- ready = true;
284
- run_all($$.before_update);
285
- // `false` as a special case of no DOM component
286
- $$.fragment = create_fragment ? create_fragment($$.ctx) : false;
287
- if (options.target) {
288
- if (options.hydrate) {
289
- const nodes = children(options.target);
290
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
291
- $$.fragment && $$.fragment.l(nodes);
292
- nodes.forEach(detach);
293
- }
294
- else {
295
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
296
- $$.fragment && $$.fragment.c();
297
- }
298
- if (options.intro)
299
- transition_in(component.$$.fragment);
300
- mount_component(component, options.target, options.anchor, options.customElement);
301
- flush();
302
- }
303
- set_current_component(parent_component);
444
+ if (component.$$.dirty[0] === -1) {
445
+ dirty_components.push(component);
446
+ schedule_update();
447
+ component.$$.dirty.fill(0);
448
+ }
449
+ component.$$.dirty[(i / 31) | 0] |= 1 << i % 31;
304
450
  }
451
+
452
+ /** @returns {void} */
453
+ function init(
454
+ component,
455
+ options,
456
+ instance,
457
+ create_fragment,
458
+ not_equal,
459
+ props,
460
+ append_styles,
461
+ dirty = [-1]
462
+ ) {
463
+ const parent_component = current_component;
464
+ set_current_component(component);
465
+ /** @type {import('./private.js').T$$} */
466
+ const $$ = (component.$$ = {
467
+ fragment: null,
468
+ ctx: [],
469
+ // state
470
+ props,
471
+ update: noop,
472
+ not_equal,
473
+ bound: blank_object(),
474
+ // lifecycle
475
+ on_mount: [],
476
+ on_destroy: [],
477
+ on_disconnect: [],
478
+ before_update: [],
479
+ after_update: [],
480
+ context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
481
+ // everything else
482
+ callbacks: blank_object(),
483
+ dirty,
484
+ skip_bound: false,
485
+ root: options.target || parent_component.$$.root
486
+ });
487
+ append_styles && append_styles($$.root);
488
+ let ready = false;
489
+ $$.ctx = instance
490
+ ? instance(component, options.props || {}, (i, ret, ...rest) => {
491
+ const value = rest.length ? rest[0] : ret;
492
+ if ($$.ctx && not_equal($$.ctx[i], ($$.ctx[i] = value))) {
493
+ if (!$$.skip_bound && $$.bound[i]) $$.bound[i](value);
494
+ if (ready) make_dirty(component, i);
495
+ }
496
+ return ret;
497
+ })
498
+ : [];
499
+ $$.update();
500
+ ready = true;
501
+ run_all($$.before_update);
502
+ // `false` as a special case of no DOM component
503
+ $$.fragment = create_fragment ? create_fragment($$.ctx) : false;
504
+ if (options.target) {
505
+ if (options.hydrate) {
506
+ const nodes = children(options.target);
507
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
508
+ $$.fragment && $$.fragment.l(nodes);
509
+ nodes.forEach(detach);
510
+ } else {
511
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
512
+ $$.fragment && $$.fragment.c();
513
+ }
514
+ if (options.intro) transition_in(component.$$.fragment);
515
+ mount_component(component, options.target, options.anchor);
516
+ flush();
517
+ }
518
+ set_current_component(parent_component);
519
+ }
520
+
305
521
  /**
306
522
  * Base class for Svelte components. Used when dev=false.
523
+ *
524
+ * @template {Record<string, any>} [Props=any]
525
+ * @template {Record<string, any>} [Events=any]
307
526
  */
308
527
  class SvelteComponent {
309
- $destroy() {
310
- destroy_component(this, 1);
311
- this.$destroy = noop;
312
- }
313
- $on(type, callback) {
314
- const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
315
- callbacks.push(callback);
316
- return () => {
317
- const index = callbacks.indexOf(callback);
318
- if (index !== -1)
319
- callbacks.splice(index, 1);
320
- };
321
- }
322
- $set($$props) {
323
- if (this.$$set && !is_empty($$props)) {
324
- this.$$.skip_bound = true;
325
- this.$$set($$props);
326
- this.$$.skip_bound = false;
327
- }
328
- }
329
- }
330
-
331
- /* src/IntersectionObserver.svelte generated by Svelte v3.44.2 */
528
+ /**
529
+ * ### PRIVATE API
530
+ *
531
+ * Do not use, may change at any time
532
+ *
533
+ * @type {any}
534
+ */
535
+ $$ = undefined;
536
+ /**
537
+ * ### PRIVATE API
538
+ *
539
+ * Do not use, may change at any time
540
+ *
541
+ * @type {any}
542
+ */
543
+ $$set = undefined;
544
+
545
+ /** @returns {void} */
546
+ $destroy() {
547
+ destroy_component(this, 1);
548
+ this.$destroy = noop;
549
+ }
550
+
551
+ /**
552
+ * @template {Extract<keyof Events, string>} K
553
+ * @param {K} type
554
+ * @param {((e: Events[K]) => void) | null | undefined} callback
555
+ * @returns {() => void}
556
+ */
557
+ $on(type, callback) {
558
+ if (!is_function(callback)) {
559
+ return noop;
560
+ }
561
+ const callbacks = this.$$.callbacks[type] || (this.$$.callbacks[type] = []);
562
+ callbacks.push(callback);
563
+ return () => {
564
+ const index = callbacks.indexOf(callback);
565
+ if (index !== -1) callbacks.splice(index, 1);
566
+ };
567
+ }
568
+
569
+ /**
570
+ * @param {Partial<Props>} props
571
+ * @returns {void}
572
+ */
573
+ $set(props) {
574
+ if (this.$$set && !is_empty(props)) {
575
+ this.$$.skip_bound = true;
576
+ this.$$set(props);
577
+ this.$$.skip_bound = false;
578
+ }
579
+ }
580
+ }
581
+
582
+ /**
583
+ * @typedef {Object} CustomElementPropDefinition
584
+ * @property {string} [attribute]
585
+ * @property {boolean} [reflect]
586
+ * @property {'String'|'Boolean'|'Number'|'Array'|'Object'} [type]
587
+ */
588
+
589
+ // generated during release, do not modify
590
+ const PUBLIC_VERSION = '4';
591
+
592
+ if (typeof window !== 'undefined')
593
+ // @ts-ignore
594
+ (window.__svelte || (window.__svelte = { v: new Set() })).v.add(PUBLIC_VERSION);
595
+
596
+ /* src/IntersectionObserver.svelte generated by Svelte v4.1.0 */
332
597
 
333
598
  const get_default_slot_changes = dirty => ({
334
- intersecting: dirty & /*intersecting*/ 2,
335
- entry: dirty & /*entry*/ 1,
599
+ intersecting: dirty & /*intersecting*/ 1,
600
+ entry: dirty & /*entry*/ 2,
336
601
  observer: dirty & /*observer*/ 4
337
602
  });
338
603
 
339
604
  const get_default_slot_context = ctx => ({
340
- intersecting: /*intersecting*/ ctx[1],
341
- entry: /*entry*/ ctx[0],
605
+ intersecting: /*intersecting*/ ctx[0],
606
+ entry: /*entry*/ ctx[1],
342
607
  observer: /*observer*/ ctx[2]
343
608
  });
344
609
 
@@ -393,76 +658,29 @@ function instance($$self, $$props, $$invalidate) {
393
658
  let { $$slots: slots = {}, $$scope } = $$props;
394
659
  let { element = null } = $$props;
395
660
  let { once = false } = $$props;
661
+ let { intersecting = false } = $$props;
396
662
  let { root = null } = $$props;
397
663
  let { rootMargin = "0px" } = $$props;
398
664
  let { threshold = 0 } = $$props;
399
665
  let { entry = null } = $$props;
400
- let { intersecting = false } = $$props;
401
666
  let { observer = null } = $$props;
402
- const dispatch = createEventDispatcher();
403
- let prevRootMargin = null;
404
- let prevElement = null;
405
-
406
- const initialize = () => {
407
- $$invalidate(2, observer = new IntersectionObserver(entries => {
408
- entries.forEach(_entry => {
409
- $$invalidate(0, entry = _entry);
410
- $$invalidate(1, intersecting = _entry.isIntersecting);
411
- });
412
- },
413
- { root, rootMargin, threshold }));
414
- };
415
-
416
- onMount(() => {
417
- initialize();
418
-
419
- return () => {
420
- if (observer) observer.disconnect();
421
- };
422
- });
423
-
424
- afterUpdate(async () => {
425
- if (entry !== null) {
426
- dispatch("observe", entry);
427
-
428
- if (entry.isIntersecting) {
429
- dispatch("intersect", entry);
430
- if (once) observer.unobserve(element);
431
- }
432
- }
433
-
434
- await tick();
435
-
436
- if (element !== null && element !== prevElement) {
437
- observer.observe(element);
438
- if (prevElement !== null) observer.unobserve(prevElement);
439
- prevElement = element;
440
- }
441
-
442
- if (prevRootMargin && rootMargin !== prevRootMargin) {
443
- observer.disconnect();
444
- prevElement = null;
445
- initialize();
446
- }
447
-
448
- prevRootMargin = rootMargin;
449
- });
667
+ createEventDispatcher();
450
668
 
451
669
  $$self.$$set = $$props => {
452
670
  if ('element' in $$props) $$invalidate(3, element = $$props.element);
453
671
  if ('once' in $$props) $$invalidate(4, once = $$props.once);
672
+ if ('intersecting' in $$props) $$invalidate(0, intersecting = $$props.intersecting);
454
673
  if ('root' in $$props) $$invalidate(5, root = $$props.root);
455
674
  if ('rootMargin' in $$props) $$invalidate(6, rootMargin = $$props.rootMargin);
456
675
  if ('threshold' in $$props) $$invalidate(7, threshold = $$props.threshold);
457
- if ('entry' in $$props) $$invalidate(0, entry = $$props.entry);
458
- if ('intersecting' in $$props) $$invalidate(1, intersecting = $$props.intersecting);
676
+ if ('entry' in $$props) $$invalidate(1, entry = $$props.entry);
459
677
  if ('observer' in $$props) $$invalidate(2, observer = $$props.observer);
460
678
  if ('$$scope' in $$props) $$invalidate(8, $$scope = $$props.$$scope);
461
679
  };
462
680
 
463
681
  return [
464
- entry,
465
682
  intersecting,
683
+ entry,
466
684
  observer,
467
685
  element,
468
686
  once,
@@ -481,14 +699,14 @@ class IntersectionObserver_1 extends SvelteComponent {
481
699
  init(this, options, instance, create_fragment, safe_not_equal, {
482
700
  element: 3,
483
701
  once: 4,
702
+ intersecting: 0,
484
703
  root: 5,
485
704
  rootMargin: 6,
486
705
  threshold: 7,
487
- entry: 0,
488
- intersecting: 1,
706
+ entry: 1,
489
707
  observer: 2
490
708
  });
491
709
  }
492
710
  }
493
711
 
494
- export default IntersectionObserver_1;
712
+ export { IntersectionObserver_1 as default };