heroshot 0.0.2-alpha.1 → 0.0.2-alpha.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.
@@ -0,0 +1,4019 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __typeError = (msg) => {
3
+ throw TypeError(msg);
4
+ };
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
8
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
9
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
12
+ (function(exports) {
13
+ "use strict";
14
+ var _commit_callbacks, _discard_callbacks, _pending, _blocking_pending, _deferred, _dirty_effects, _maybe_dirty_effects, _Batch_instances, traverse_effect_tree_fn, defer_effects_fn, clear_marked_fn, resolve_fn, commit_fn, _pending2, _anchor, _hydrate_open, _props, _children, _effect, _main_effect, _pending_effect, _failed_effect, _offscreen_fragment, _pending_anchor, _local_pending_count, _pending_count, _is_creating_fallback, _effect_pending, _effect_pending_subscriber, _Boundary_instances, hydrate_resolved_content_fn, hydrate_pending_content_fn, get_anchor_fn, run_fn, show_pending_snippet_fn, update_pending_count_fn, _batches, _onscreen, _offscreen, _outroing, _transition, _commit, _discard, _a;
15
+ const DEV = false;
16
+ var is_array = Array.isArray;
17
+ var index_of = Array.prototype.indexOf;
18
+ var array_from = Array.from;
19
+ var define_property = Object.defineProperty;
20
+ var get_descriptor = Object.getOwnPropertyDescriptor;
21
+ var object_prototype = Object.prototype;
22
+ var array_prototype = Array.prototype;
23
+ var get_prototype_of = Object.getPrototypeOf;
24
+ var is_extensible = Object.isExtensible;
25
+ function run_all(arr) {
26
+ for (var i = 0; i < arr.length; i++) {
27
+ arr[i]();
28
+ }
29
+ }
30
+ function deferred() {
31
+ var resolve;
32
+ var reject;
33
+ var promise = new Promise((res, rej) => {
34
+ resolve = res;
35
+ reject = rej;
36
+ });
37
+ return { promise, resolve, reject };
38
+ }
39
+ const DERIVED = 1 << 1;
40
+ const EFFECT = 1 << 2;
41
+ const RENDER_EFFECT = 1 << 3;
42
+ const MANAGED_EFFECT = 1 << 24;
43
+ const BLOCK_EFFECT = 1 << 4;
44
+ const BRANCH_EFFECT = 1 << 5;
45
+ const ROOT_EFFECT = 1 << 6;
46
+ const BOUNDARY_EFFECT = 1 << 7;
47
+ const CONNECTED = 1 << 9;
48
+ const CLEAN = 1 << 10;
49
+ const DIRTY = 1 << 11;
50
+ const MAYBE_DIRTY = 1 << 12;
51
+ const INERT = 1 << 13;
52
+ const DESTROYED = 1 << 14;
53
+ const EFFECT_RAN = 1 << 15;
54
+ const EFFECT_TRANSPARENT = 1 << 16;
55
+ const EAGER_EFFECT = 1 << 17;
56
+ const HEAD_EFFECT = 1 << 18;
57
+ const EFFECT_PRESERVED = 1 << 19;
58
+ const USER_EFFECT = 1 << 20;
59
+ const EFFECT_OFFSCREEN = 1 << 25;
60
+ const WAS_MARKED = 1 << 15;
61
+ const REACTION_IS_UPDATING = 1 << 21;
62
+ const ASYNC = 1 << 22;
63
+ const ERROR_VALUE = 1 << 23;
64
+ const STATE_SYMBOL = Symbol("$state");
65
+ const STALE_REACTION = new class StaleReactionError extends Error {
66
+ constructor() {
67
+ super(...arguments);
68
+ __publicField(this, "name", "StaleReactionError");
69
+ __publicField(this, "message", "The reaction that called `getAbortSignal()` was re-run or destroyed");
70
+ }
71
+ }();
72
+ function async_derived_orphan() {
73
+ {
74
+ throw new Error(`https://svelte.dev/e/async_derived_orphan`);
75
+ }
76
+ }
77
+ function effect_in_teardown(rune) {
78
+ {
79
+ throw new Error(`https://svelte.dev/e/effect_in_teardown`);
80
+ }
81
+ }
82
+ function effect_in_unowned_derived() {
83
+ {
84
+ throw new Error(`https://svelte.dev/e/effect_in_unowned_derived`);
85
+ }
86
+ }
87
+ function effect_orphan(rune) {
88
+ {
89
+ throw new Error(`https://svelte.dev/e/effect_orphan`);
90
+ }
91
+ }
92
+ function effect_update_depth_exceeded() {
93
+ {
94
+ throw new Error(`https://svelte.dev/e/effect_update_depth_exceeded`);
95
+ }
96
+ }
97
+ function state_descriptors_fixed() {
98
+ {
99
+ throw new Error(`https://svelte.dev/e/state_descriptors_fixed`);
100
+ }
101
+ }
102
+ function state_prototype_fixed() {
103
+ {
104
+ throw new Error(`https://svelte.dev/e/state_prototype_fixed`);
105
+ }
106
+ }
107
+ function state_unsafe_mutation() {
108
+ {
109
+ throw new Error(`https://svelte.dev/e/state_unsafe_mutation`);
110
+ }
111
+ }
112
+ function svelte_boundary_reset_onerror() {
113
+ {
114
+ throw new Error(`https://svelte.dev/e/svelte_boundary_reset_onerror`);
115
+ }
116
+ }
117
+ const EACH_ITEM_REACTIVE = 1;
118
+ const EACH_INDEX_REACTIVE = 1 << 1;
119
+ const EACH_ITEM_IMMUTABLE = 1 << 4;
120
+ const TEMPLATE_FRAGMENT = 1;
121
+ const TEMPLATE_USE_IMPORT_NODE = 1 << 1;
122
+ const UNINITIALIZED = Symbol();
123
+ function svelte_boundary_reset_noop() {
124
+ {
125
+ console.warn(`https://svelte.dev/e/svelte_boundary_reset_noop`);
126
+ }
127
+ }
128
+ function equals(value) {
129
+ return value === this.v;
130
+ }
131
+ function safe_not_equal(a, b) {
132
+ return a != a ? b == b : a !== b || a !== null && typeof a === "object" || typeof a === "function";
133
+ }
134
+ function safe_equals(value) {
135
+ return !safe_not_equal(value, this.v);
136
+ }
137
+ let tracing_mode_flag = false;
138
+ let component_context = null;
139
+ function set_component_context(context) {
140
+ component_context = context;
141
+ }
142
+ function push(props, runes = false, fn) {
143
+ component_context = {
144
+ p: component_context,
145
+ i: false,
146
+ c: null,
147
+ e: null,
148
+ s: props,
149
+ x: null,
150
+ l: null
151
+ };
152
+ }
153
+ function pop(component) {
154
+ var context = (
155
+ /** @type {ComponentContext} */
156
+ component_context
157
+ );
158
+ var effects = context.e;
159
+ if (effects !== null) {
160
+ context.e = null;
161
+ for (var fn of effects) {
162
+ create_user_effect(fn);
163
+ }
164
+ }
165
+ context.i = true;
166
+ component_context = context.p;
167
+ return (
168
+ /** @type {T} */
169
+ {}
170
+ );
171
+ }
172
+ function is_runes() {
173
+ return true;
174
+ }
175
+ let micro_tasks = [];
176
+ function run_micro_tasks() {
177
+ var tasks = micro_tasks;
178
+ micro_tasks = [];
179
+ run_all(tasks);
180
+ }
181
+ function queue_micro_task(fn) {
182
+ if (micro_tasks.length === 0 && !is_flushing_sync) {
183
+ var tasks = micro_tasks;
184
+ queueMicrotask(() => {
185
+ if (tasks === micro_tasks) run_micro_tasks();
186
+ });
187
+ }
188
+ micro_tasks.push(fn);
189
+ }
190
+ function flush_tasks() {
191
+ while (micro_tasks.length > 0) {
192
+ run_micro_tasks();
193
+ }
194
+ }
195
+ function handle_error(error) {
196
+ var effect2 = active_effect;
197
+ if (effect2 === null) {
198
+ active_reaction.f |= ERROR_VALUE;
199
+ return error;
200
+ }
201
+ if ((effect2.f & EFFECT_RAN) === 0) {
202
+ if ((effect2.f & BOUNDARY_EFFECT) === 0) {
203
+ throw error;
204
+ }
205
+ effect2.b.error(error);
206
+ } else {
207
+ invoke_error_boundary(error, effect2);
208
+ }
209
+ }
210
+ function invoke_error_boundary(error, effect2) {
211
+ while (effect2 !== null) {
212
+ if ((effect2.f & BOUNDARY_EFFECT) !== 0) {
213
+ try {
214
+ effect2.b.error(error);
215
+ return;
216
+ } catch (e) {
217
+ error = e;
218
+ }
219
+ }
220
+ effect2 = effect2.parent;
221
+ }
222
+ throw error;
223
+ }
224
+ const batches = /* @__PURE__ */ new Set();
225
+ let current_batch = null;
226
+ let previous_batch = null;
227
+ let batch_values = null;
228
+ let queued_root_effects = [];
229
+ let last_scheduled_effect = null;
230
+ let is_flushing = false;
231
+ let is_flushing_sync = false;
232
+ const _Batch = class _Batch {
233
+ constructor() {
234
+ __privateAdd(this, _Batch_instances);
235
+ __publicField(this, "committed", false);
236
+ /**
237
+ * The current values of any sources that are updated in this batch
238
+ * They keys of this map are identical to `this.#previous`
239
+ * @type {Map<Source, any>}
240
+ */
241
+ __publicField(this, "current", /* @__PURE__ */ new Map());
242
+ /**
243
+ * The values of any sources that are updated in this batch _before_ those updates took place.
244
+ * They keys of this map are identical to `this.#current`
245
+ * @type {Map<Source, any>}
246
+ */
247
+ __publicField(this, "previous", /* @__PURE__ */ new Map());
248
+ /**
249
+ * When the batch is committed (and the DOM is updated), we need to remove old branches
250
+ * and append new ones by calling the functions added inside (if/each/key/etc) blocks
251
+ * @type {Set<() => void>}
252
+ */
253
+ __privateAdd(this, _commit_callbacks, /* @__PURE__ */ new Set());
254
+ /**
255
+ * If a fork is discarded, we need to destroy any effects that are no longer needed
256
+ * @type {Set<(batch: Batch) => void>}
257
+ */
258
+ __privateAdd(this, _discard_callbacks, /* @__PURE__ */ new Set());
259
+ /**
260
+ * The number of async effects that are currently in flight
261
+ */
262
+ __privateAdd(this, _pending, 0);
263
+ /**
264
+ * The number of async effects that are currently in flight, _not_ inside a pending boundary
265
+ */
266
+ __privateAdd(this, _blocking_pending, 0);
267
+ /**
268
+ * A deferred that resolves when the batch is committed, used with `settled()`
269
+ * TODO replace with Promise.withResolvers once supported widely enough
270
+ * @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null}
271
+ */
272
+ __privateAdd(this, _deferred, null);
273
+ /**
274
+ * Deferred effects (which run after async work has completed) that are DIRTY
275
+ * @type {Set<Effect>}
276
+ */
277
+ __privateAdd(this, _dirty_effects, /* @__PURE__ */ new Set());
278
+ /**
279
+ * Deferred effects that are MAYBE_DIRTY
280
+ * @type {Set<Effect>}
281
+ */
282
+ __privateAdd(this, _maybe_dirty_effects, /* @__PURE__ */ new Set());
283
+ /**
284
+ * A set of branches that still exist, but will be destroyed when this batch
285
+ * is committed — we skip over these during `process`
286
+ * @type {Set<Effect>}
287
+ */
288
+ __publicField(this, "skipped_effects", /* @__PURE__ */ new Set());
289
+ __publicField(this, "is_fork", false);
290
+ }
291
+ is_deferred() {
292
+ return this.is_fork || __privateGet(this, _blocking_pending) > 0;
293
+ }
294
+ /**
295
+ *
296
+ * @param {Effect[]} root_effects
297
+ */
298
+ process(root_effects) {
299
+ var _a2;
300
+ queued_root_effects = [];
301
+ previous_batch = null;
302
+ this.apply();
303
+ var target = {
304
+ parent: null,
305
+ effect: null,
306
+ effects: [],
307
+ render_effects: []
308
+ };
309
+ for (const root2 of root_effects) {
310
+ __privateMethod(this, _Batch_instances, traverse_effect_tree_fn).call(this, root2, target);
311
+ }
312
+ if (!this.is_fork) {
313
+ __privateMethod(this, _Batch_instances, resolve_fn).call(this);
314
+ }
315
+ if (this.is_deferred()) {
316
+ __privateMethod(this, _Batch_instances, defer_effects_fn).call(this, target.effects);
317
+ __privateMethod(this, _Batch_instances, defer_effects_fn).call(this, target.render_effects);
318
+ } else {
319
+ previous_batch = this;
320
+ current_batch = null;
321
+ flush_queued_effects(target.render_effects);
322
+ flush_queued_effects(target.effects);
323
+ previous_batch = null;
324
+ (_a2 = __privateGet(this, _deferred)) == null ? void 0 : _a2.resolve();
325
+ }
326
+ batch_values = null;
327
+ }
328
+ /**
329
+ * Associate a change to a given source with the current
330
+ * batch, noting its previous and current values
331
+ * @param {Source} source
332
+ * @param {any} value
333
+ */
334
+ capture(source2, value) {
335
+ if (!this.previous.has(source2)) {
336
+ this.previous.set(source2, value);
337
+ }
338
+ if ((source2.f & ERROR_VALUE) === 0) {
339
+ this.current.set(source2, source2.v);
340
+ batch_values == null ? void 0 : batch_values.set(source2, source2.v);
341
+ }
342
+ }
343
+ activate() {
344
+ current_batch = this;
345
+ this.apply();
346
+ }
347
+ deactivate() {
348
+ if (current_batch !== this) return;
349
+ current_batch = null;
350
+ batch_values = null;
351
+ }
352
+ flush() {
353
+ this.activate();
354
+ if (queued_root_effects.length > 0) {
355
+ flush_effects();
356
+ if (current_batch !== null && current_batch !== this) {
357
+ return;
358
+ }
359
+ } else if (__privateGet(this, _pending) === 0) {
360
+ this.process([]);
361
+ }
362
+ this.deactivate();
363
+ }
364
+ discard() {
365
+ for (const fn of __privateGet(this, _discard_callbacks)) fn(this);
366
+ __privateGet(this, _discard_callbacks).clear();
367
+ }
368
+ /**
369
+ *
370
+ * @param {boolean} blocking
371
+ */
372
+ increment(blocking) {
373
+ __privateSet(this, _pending, __privateGet(this, _pending) + 1);
374
+ if (blocking) __privateSet(this, _blocking_pending, __privateGet(this, _blocking_pending) + 1);
375
+ }
376
+ /**
377
+ *
378
+ * @param {boolean} blocking
379
+ */
380
+ decrement(blocking) {
381
+ __privateSet(this, _pending, __privateGet(this, _pending) - 1);
382
+ if (blocking) __privateSet(this, _blocking_pending, __privateGet(this, _blocking_pending) - 1);
383
+ this.revive();
384
+ }
385
+ revive() {
386
+ for (const e of __privateGet(this, _dirty_effects)) {
387
+ __privateGet(this, _maybe_dirty_effects).delete(e);
388
+ set_signal_status(e, DIRTY);
389
+ schedule_effect(e);
390
+ }
391
+ for (const e of __privateGet(this, _maybe_dirty_effects)) {
392
+ set_signal_status(e, MAYBE_DIRTY);
393
+ schedule_effect(e);
394
+ }
395
+ this.flush();
396
+ }
397
+ /** @param {() => void} fn */
398
+ oncommit(fn) {
399
+ __privateGet(this, _commit_callbacks).add(fn);
400
+ }
401
+ /** @param {(batch: Batch) => void} fn */
402
+ ondiscard(fn) {
403
+ __privateGet(this, _discard_callbacks).add(fn);
404
+ }
405
+ settled() {
406
+ return (__privateGet(this, _deferred) ?? __privateSet(this, _deferred, deferred())).promise;
407
+ }
408
+ static ensure() {
409
+ if (current_batch === null) {
410
+ const batch = current_batch = new _Batch();
411
+ batches.add(current_batch);
412
+ if (!is_flushing_sync) {
413
+ _Batch.enqueue(() => {
414
+ if (current_batch !== batch) {
415
+ return;
416
+ }
417
+ batch.flush();
418
+ });
419
+ }
420
+ }
421
+ return current_batch;
422
+ }
423
+ /** @param {() => void} task */
424
+ static enqueue(task) {
425
+ queue_micro_task(task);
426
+ }
427
+ apply() {
428
+ return;
429
+ }
430
+ };
431
+ _commit_callbacks = new WeakMap();
432
+ _discard_callbacks = new WeakMap();
433
+ _pending = new WeakMap();
434
+ _blocking_pending = new WeakMap();
435
+ _deferred = new WeakMap();
436
+ _dirty_effects = new WeakMap();
437
+ _maybe_dirty_effects = new WeakMap();
438
+ _Batch_instances = new WeakSet();
439
+ /**
440
+ * Traverse the effect tree, executing effects or stashing
441
+ * them for later execution as appropriate
442
+ * @param {Effect} root
443
+ * @param {EffectTarget} target
444
+ */
445
+ traverse_effect_tree_fn = function(root2, target) {
446
+ var _a2;
447
+ root2.f ^= CLEAN;
448
+ var effect2 = root2.first;
449
+ while (effect2 !== null) {
450
+ var flags2 = effect2.f;
451
+ var is_branch = (flags2 & (BRANCH_EFFECT | ROOT_EFFECT)) !== 0;
452
+ var is_skippable_branch = is_branch && (flags2 & CLEAN) !== 0;
453
+ var skip = is_skippable_branch || (flags2 & INERT) !== 0 || this.skipped_effects.has(effect2);
454
+ if ((effect2.f & BOUNDARY_EFFECT) !== 0 && ((_a2 = effect2.b) == null ? void 0 : _a2.is_pending())) {
455
+ target = {
456
+ parent: target,
457
+ effect: effect2,
458
+ effects: [],
459
+ render_effects: []
460
+ };
461
+ }
462
+ if (!skip && effect2.fn !== null) {
463
+ if (is_branch) {
464
+ effect2.f ^= CLEAN;
465
+ } else if ((flags2 & EFFECT) !== 0) {
466
+ target.effects.push(effect2);
467
+ } else if (is_dirty(effect2)) {
468
+ if ((effect2.f & BLOCK_EFFECT) !== 0) __privateGet(this, _dirty_effects).add(effect2);
469
+ update_effect(effect2);
470
+ }
471
+ var child2 = effect2.first;
472
+ if (child2 !== null) {
473
+ effect2 = child2;
474
+ continue;
475
+ }
476
+ }
477
+ var parent = effect2.parent;
478
+ effect2 = effect2.next;
479
+ while (effect2 === null && parent !== null) {
480
+ if (parent === target.effect) {
481
+ __privateMethod(this, _Batch_instances, defer_effects_fn).call(this, target.effects);
482
+ __privateMethod(this, _Batch_instances, defer_effects_fn).call(this, target.render_effects);
483
+ target = /** @type {EffectTarget} */
484
+ target.parent;
485
+ }
486
+ effect2 = parent.next;
487
+ parent = parent.parent;
488
+ }
489
+ }
490
+ };
491
+ /**
492
+ * @param {Effect[]} effects
493
+ */
494
+ defer_effects_fn = function(effects) {
495
+ for (const e of effects) {
496
+ if ((e.f & DIRTY) !== 0) {
497
+ __privateGet(this, _dirty_effects).add(e);
498
+ } else if ((e.f & MAYBE_DIRTY) !== 0) {
499
+ __privateGet(this, _maybe_dirty_effects).add(e);
500
+ }
501
+ __privateMethod(this, _Batch_instances, clear_marked_fn).call(this, e.deps);
502
+ set_signal_status(e, CLEAN);
503
+ }
504
+ };
505
+ /**
506
+ * @param {Value[] | null} deps
507
+ */
508
+ clear_marked_fn = function(deps) {
509
+ if (deps === null) return;
510
+ for (const dep of deps) {
511
+ if ((dep.f & DERIVED) === 0 || (dep.f & WAS_MARKED) === 0) {
512
+ continue;
513
+ }
514
+ dep.f ^= WAS_MARKED;
515
+ __privateMethod(this, _Batch_instances, clear_marked_fn).call(
516
+ this,
517
+ /** @type {Derived} */
518
+ dep.deps
519
+ );
520
+ }
521
+ };
522
+ resolve_fn = function() {
523
+ if (__privateGet(this, _blocking_pending) === 0) {
524
+ for (const fn of __privateGet(this, _commit_callbacks)) fn();
525
+ __privateGet(this, _commit_callbacks).clear();
526
+ }
527
+ if (__privateGet(this, _pending) === 0) {
528
+ __privateMethod(this, _Batch_instances, commit_fn).call(this);
529
+ }
530
+ };
531
+ commit_fn = function() {
532
+ var _a2;
533
+ if (batches.size > 1) {
534
+ this.previous.clear();
535
+ var previous_batch_values = batch_values;
536
+ var is_earlier = true;
537
+ var dummy_target = {
538
+ parent: null,
539
+ effect: null,
540
+ effects: [],
541
+ render_effects: []
542
+ };
543
+ for (const batch of batches) {
544
+ if (batch === this) {
545
+ is_earlier = false;
546
+ continue;
547
+ }
548
+ const sources = [];
549
+ for (const [source2, value] of this.current) {
550
+ if (batch.current.has(source2)) {
551
+ if (is_earlier && value !== batch.current.get(source2)) {
552
+ batch.current.set(source2, value);
553
+ } else {
554
+ continue;
555
+ }
556
+ }
557
+ sources.push(source2);
558
+ }
559
+ if (sources.length === 0) {
560
+ continue;
561
+ }
562
+ const others = [...batch.current.keys()].filter((s) => !this.current.has(s));
563
+ if (others.length > 0) {
564
+ var prev_queued_root_effects = queued_root_effects;
565
+ queued_root_effects = [];
566
+ const marked = /* @__PURE__ */ new Set();
567
+ const checked = /* @__PURE__ */ new Map();
568
+ for (const source2 of sources) {
569
+ mark_effects(source2, others, marked, checked);
570
+ }
571
+ if (queued_root_effects.length > 0) {
572
+ current_batch = batch;
573
+ batch.apply();
574
+ for (const root2 of queued_root_effects) {
575
+ __privateMethod(_a2 = batch, _Batch_instances, traverse_effect_tree_fn).call(_a2, root2, dummy_target);
576
+ }
577
+ batch.deactivate();
578
+ }
579
+ queued_root_effects = prev_queued_root_effects;
580
+ }
581
+ }
582
+ current_batch = null;
583
+ batch_values = previous_batch_values;
584
+ }
585
+ this.committed = true;
586
+ batches.delete(this);
587
+ };
588
+ let Batch = _Batch;
589
+ function flushSync(fn) {
590
+ var was_flushing_sync = is_flushing_sync;
591
+ is_flushing_sync = true;
592
+ try {
593
+ var result;
594
+ if (fn) ;
595
+ while (true) {
596
+ flush_tasks();
597
+ if (queued_root_effects.length === 0) {
598
+ current_batch == null ? void 0 : current_batch.flush();
599
+ if (queued_root_effects.length === 0) {
600
+ last_scheduled_effect = null;
601
+ return (
602
+ /** @type {T} */
603
+ result
604
+ );
605
+ }
606
+ }
607
+ flush_effects();
608
+ }
609
+ } finally {
610
+ is_flushing_sync = was_flushing_sync;
611
+ }
612
+ }
613
+ function flush_effects() {
614
+ var was_updating_effect = is_updating_effect;
615
+ is_flushing = true;
616
+ var source_stacks = null;
617
+ try {
618
+ var flush_count = 0;
619
+ set_is_updating_effect(true);
620
+ while (queued_root_effects.length > 0) {
621
+ var batch = Batch.ensure();
622
+ if (flush_count++ > 1e3) {
623
+ var updates, entry;
624
+ if (DEV) ;
625
+ infinite_loop_guard();
626
+ }
627
+ batch.process(queued_root_effects);
628
+ old_values.clear();
629
+ if (DEV) ;
630
+ }
631
+ } finally {
632
+ is_flushing = false;
633
+ set_is_updating_effect(was_updating_effect);
634
+ last_scheduled_effect = null;
635
+ }
636
+ }
637
+ function infinite_loop_guard() {
638
+ try {
639
+ effect_update_depth_exceeded();
640
+ } catch (error) {
641
+ invoke_error_boundary(error, last_scheduled_effect);
642
+ }
643
+ }
644
+ let eager_block_effects = null;
645
+ function flush_queued_effects(effects) {
646
+ var length = effects.length;
647
+ if (length === 0) return;
648
+ var i = 0;
649
+ while (i < length) {
650
+ var effect2 = effects[i++];
651
+ if ((effect2.f & (DESTROYED | INERT)) === 0 && is_dirty(effect2)) {
652
+ eager_block_effects = /* @__PURE__ */ new Set();
653
+ update_effect(effect2);
654
+ if (effect2.deps === null && effect2.first === null && effect2.nodes === null) {
655
+ if (effect2.teardown === null && effect2.ac === null) {
656
+ unlink_effect(effect2);
657
+ } else {
658
+ effect2.fn = null;
659
+ }
660
+ }
661
+ if ((eager_block_effects == null ? void 0 : eager_block_effects.size) > 0) {
662
+ old_values.clear();
663
+ for (const e of eager_block_effects) {
664
+ if ((e.f & (DESTROYED | INERT)) !== 0) continue;
665
+ const ordered_effects = [e];
666
+ let ancestor = e.parent;
667
+ while (ancestor !== null) {
668
+ if (eager_block_effects.has(ancestor)) {
669
+ eager_block_effects.delete(ancestor);
670
+ ordered_effects.push(ancestor);
671
+ }
672
+ ancestor = ancestor.parent;
673
+ }
674
+ for (let j = ordered_effects.length - 1; j >= 0; j--) {
675
+ const e2 = ordered_effects[j];
676
+ if ((e2.f & (DESTROYED | INERT)) !== 0) continue;
677
+ update_effect(e2);
678
+ }
679
+ }
680
+ eager_block_effects.clear();
681
+ }
682
+ }
683
+ }
684
+ eager_block_effects = null;
685
+ }
686
+ function mark_effects(value, sources, marked, checked) {
687
+ if (marked.has(value)) return;
688
+ marked.add(value);
689
+ if (value.reactions !== null) {
690
+ for (const reaction of value.reactions) {
691
+ const flags2 = reaction.f;
692
+ if ((flags2 & DERIVED) !== 0) {
693
+ mark_effects(
694
+ /** @type {Derived} */
695
+ reaction,
696
+ sources,
697
+ marked,
698
+ checked
699
+ );
700
+ } else if ((flags2 & (ASYNC | BLOCK_EFFECT)) !== 0 && (flags2 & DIRTY) === 0 && depends_on(reaction, sources, checked)) {
701
+ set_signal_status(reaction, DIRTY);
702
+ schedule_effect(
703
+ /** @type {Effect} */
704
+ reaction
705
+ );
706
+ }
707
+ }
708
+ }
709
+ }
710
+ function depends_on(reaction, sources, checked) {
711
+ const depends = checked.get(reaction);
712
+ if (depends !== void 0) return depends;
713
+ if (reaction.deps !== null) {
714
+ for (const dep of reaction.deps) {
715
+ if (sources.includes(dep)) {
716
+ return true;
717
+ }
718
+ if ((dep.f & DERIVED) !== 0 && depends_on(
719
+ /** @type {Derived} */
720
+ dep,
721
+ sources,
722
+ checked
723
+ )) {
724
+ checked.set(
725
+ /** @type {Derived} */
726
+ dep,
727
+ true
728
+ );
729
+ return true;
730
+ }
731
+ }
732
+ }
733
+ checked.set(reaction, false);
734
+ return false;
735
+ }
736
+ function schedule_effect(signal) {
737
+ var effect2 = last_scheduled_effect = signal;
738
+ while (effect2.parent !== null) {
739
+ effect2 = effect2.parent;
740
+ var flags2 = effect2.f;
741
+ if (is_flushing && effect2 === active_effect && (flags2 & BLOCK_EFFECT) !== 0 && (flags2 & HEAD_EFFECT) === 0) {
742
+ return;
743
+ }
744
+ if ((flags2 & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
745
+ if ((flags2 & CLEAN) === 0) return;
746
+ effect2.f ^= CLEAN;
747
+ }
748
+ }
749
+ queued_root_effects.push(effect2);
750
+ }
751
+ function createSubscriber(start) {
752
+ let subscribers = 0;
753
+ let version = source(0);
754
+ let stop;
755
+ return () => {
756
+ if (effect_tracking()) {
757
+ get(version);
758
+ render_effect(() => {
759
+ if (subscribers === 0) {
760
+ stop = untrack(() => start(() => increment(version)));
761
+ }
762
+ subscribers += 1;
763
+ return () => {
764
+ queue_micro_task(() => {
765
+ subscribers -= 1;
766
+ if (subscribers === 0) {
767
+ stop == null ? void 0 : stop();
768
+ stop = void 0;
769
+ increment(version);
770
+ }
771
+ });
772
+ };
773
+ });
774
+ }
775
+ };
776
+ }
777
+ var flags = EFFECT_TRANSPARENT | EFFECT_PRESERVED | BOUNDARY_EFFECT;
778
+ function boundary(node, props, children) {
779
+ new Boundary(node, props, children);
780
+ }
781
+ class Boundary {
782
+ /**
783
+ * @param {TemplateNode} node
784
+ * @param {BoundaryProps} props
785
+ * @param {((anchor: Node) => void)} children
786
+ */
787
+ constructor(node, props, children) {
788
+ __privateAdd(this, _Boundary_instances);
789
+ /** @type {Boundary | null} */
790
+ __publicField(this, "parent");
791
+ __privateAdd(this, _pending2, false);
792
+ /** @type {TemplateNode} */
793
+ __privateAdd(this, _anchor);
794
+ /** @type {TemplateNode | null} */
795
+ __privateAdd(this, _hydrate_open, null);
796
+ /** @type {BoundaryProps} */
797
+ __privateAdd(this, _props);
798
+ /** @type {((anchor: Node) => void)} */
799
+ __privateAdd(this, _children);
800
+ /** @type {Effect} */
801
+ __privateAdd(this, _effect);
802
+ /** @type {Effect | null} */
803
+ __privateAdd(this, _main_effect, null);
804
+ /** @type {Effect | null} */
805
+ __privateAdd(this, _pending_effect, null);
806
+ /** @type {Effect | null} */
807
+ __privateAdd(this, _failed_effect, null);
808
+ /** @type {DocumentFragment | null} */
809
+ __privateAdd(this, _offscreen_fragment, null);
810
+ /** @type {TemplateNode | null} */
811
+ __privateAdd(this, _pending_anchor, null);
812
+ __privateAdd(this, _local_pending_count, 0);
813
+ __privateAdd(this, _pending_count, 0);
814
+ __privateAdd(this, _is_creating_fallback, false);
815
+ /**
816
+ * A source containing the number of pending async deriveds/expressions.
817
+ * Only created if `$effect.pending()` is used inside the boundary,
818
+ * otherwise updating the source results in needless `Batch.ensure()`
819
+ * calls followed by no-op flushes
820
+ * @type {Source<number> | null}
821
+ */
822
+ __privateAdd(this, _effect_pending, null);
823
+ __privateAdd(this, _effect_pending_subscriber, createSubscriber(() => {
824
+ __privateSet(this, _effect_pending, source(__privateGet(this, _local_pending_count)));
825
+ return () => {
826
+ __privateSet(this, _effect_pending, null);
827
+ };
828
+ }));
829
+ __privateSet(this, _anchor, node);
830
+ __privateSet(this, _props, props);
831
+ __privateSet(this, _children, children);
832
+ this.parent = /** @type {Effect} */
833
+ active_effect.b;
834
+ __privateSet(this, _pending2, !!__privateGet(this, _props).pending);
835
+ __privateSet(this, _effect, block(() => {
836
+ active_effect.b = this;
837
+ {
838
+ var anchor = __privateMethod(this, _Boundary_instances, get_anchor_fn).call(this);
839
+ try {
840
+ __privateSet(this, _main_effect, branch(() => children(anchor)));
841
+ } catch (error) {
842
+ this.error(error);
843
+ }
844
+ if (__privateGet(this, _pending_count) > 0) {
845
+ __privateMethod(this, _Boundary_instances, show_pending_snippet_fn).call(this);
846
+ } else {
847
+ __privateSet(this, _pending2, false);
848
+ }
849
+ }
850
+ return () => {
851
+ var _a2;
852
+ (_a2 = __privateGet(this, _pending_anchor)) == null ? void 0 : _a2.remove();
853
+ };
854
+ }, flags));
855
+ }
856
+ /**
857
+ * Returns `true` if the effect exists inside a boundary whose pending snippet is shown
858
+ * @returns {boolean}
859
+ */
860
+ is_pending() {
861
+ return __privateGet(this, _pending2) || !!this.parent && this.parent.is_pending();
862
+ }
863
+ has_pending_snippet() {
864
+ return !!__privateGet(this, _props).pending;
865
+ }
866
+ /**
867
+ * Update the source that powers `$effect.pending()` inside this boundary,
868
+ * and controls when the current `pending` snippet (if any) is removed.
869
+ * Do not call from inside the class
870
+ * @param {1 | -1} d
871
+ */
872
+ update_pending_count(d) {
873
+ __privateMethod(this, _Boundary_instances, update_pending_count_fn).call(this, d);
874
+ __privateSet(this, _local_pending_count, __privateGet(this, _local_pending_count) + d);
875
+ if (__privateGet(this, _effect_pending)) {
876
+ internal_set(__privateGet(this, _effect_pending), __privateGet(this, _local_pending_count));
877
+ }
878
+ }
879
+ get_effect_pending() {
880
+ __privateGet(this, _effect_pending_subscriber).call(this);
881
+ return get(
882
+ /** @type {Source<number>} */
883
+ __privateGet(this, _effect_pending)
884
+ );
885
+ }
886
+ /** @param {unknown} error */
887
+ error(error) {
888
+ var onerror = __privateGet(this, _props).onerror;
889
+ let failed = __privateGet(this, _props).failed;
890
+ if (__privateGet(this, _is_creating_fallback) || !onerror && !failed) {
891
+ throw error;
892
+ }
893
+ if (__privateGet(this, _main_effect)) {
894
+ destroy_effect(__privateGet(this, _main_effect));
895
+ __privateSet(this, _main_effect, null);
896
+ }
897
+ if (__privateGet(this, _pending_effect)) {
898
+ destroy_effect(__privateGet(this, _pending_effect));
899
+ __privateSet(this, _pending_effect, null);
900
+ }
901
+ if (__privateGet(this, _failed_effect)) {
902
+ destroy_effect(__privateGet(this, _failed_effect));
903
+ __privateSet(this, _failed_effect, null);
904
+ }
905
+ var did_reset = false;
906
+ var calling_on_error = false;
907
+ const reset = () => {
908
+ if (did_reset) {
909
+ svelte_boundary_reset_noop();
910
+ return;
911
+ }
912
+ did_reset = true;
913
+ if (calling_on_error) {
914
+ svelte_boundary_reset_onerror();
915
+ }
916
+ Batch.ensure();
917
+ __privateSet(this, _local_pending_count, 0);
918
+ if (__privateGet(this, _failed_effect) !== null) {
919
+ pause_effect(__privateGet(this, _failed_effect), () => {
920
+ __privateSet(this, _failed_effect, null);
921
+ });
922
+ }
923
+ __privateSet(this, _pending2, this.has_pending_snippet());
924
+ __privateSet(this, _main_effect, __privateMethod(this, _Boundary_instances, run_fn).call(this, () => {
925
+ __privateSet(this, _is_creating_fallback, false);
926
+ return branch(() => __privateGet(this, _children).call(this, __privateGet(this, _anchor)));
927
+ }));
928
+ if (__privateGet(this, _pending_count) > 0) {
929
+ __privateMethod(this, _Boundary_instances, show_pending_snippet_fn).call(this);
930
+ } else {
931
+ __privateSet(this, _pending2, false);
932
+ }
933
+ };
934
+ var previous_reaction = active_reaction;
935
+ try {
936
+ set_active_reaction(null);
937
+ calling_on_error = true;
938
+ onerror == null ? void 0 : onerror(error, reset);
939
+ calling_on_error = false;
940
+ } catch (error2) {
941
+ invoke_error_boundary(error2, __privateGet(this, _effect) && __privateGet(this, _effect).parent);
942
+ } finally {
943
+ set_active_reaction(previous_reaction);
944
+ }
945
+ if (failed) {
946
+ queue_micro_task(() => {
947
+ __privateSet(this, _failed_effect, __privateMethod(this, _Boundary_instances, run_fn).call(this, () => {
948
+ Batch.ensure();
949
+ __privateSet(this, _is_creating_fallback, true);
950
+ try {
951
+ return branch(() => {
952
+ failed(
953
+ __privateGet(this, _anchor),
954
+ () => error,
955
+ () => reset
956
+ );
957
+ });
958
+ } catch (error2) {
959
+ invoke_error_boundary(
960
+ error2,
961
+ /** @type {Effect} */
962
+ __privateGet(this, _effect).parent
963
+ );
964
+ return null;
965
+ } finally {
966
+ __privateSet(this, _is_creating_fallback, false);
967
+ }
968
+ }));
969
+ });
970
+ }
971
+ }
972
+ }
973
+ _pending2 = new WeakMap();
974
+ _anchor = new WeakMap();
975
+ _hydrate_open = new WeakMap();
976
+ _props = new WeakMap();
977
+ _children = new WeakMap();
978
+ _effect = new WeakMap();
979
+ _main_effect = new WeakMap();
980
+ _pending_effect = new WeakMap();
981
+ _failed_effect = new WeakMap();
982
+ _offscreen_fragment = new WeakMap();
983
+ _pending_anchor = new WeakMap();
984
+ _local_pending_count = new WeakMap();
985
+ _pending_count = new WeakMap();
986
+ _is_creating_fallback = new WeakMap();
987
+ _effect_pending = new WeakMap();
988
+ _effect_pending_subscriber = new WeakMap();
989
+ _Boundary_instances = new WeakSet();
990
+ hydrate_resolved_content_fn = function() {
991
+ try {
992
+ __privateSet(this, _main_effect, branch(() => __privateGet(this, _children).call(this, __privateGet(this, _anchor))));
993
+ } catch (error) {
994
+ this.error(error);
995
+ }
996
+ __privateSet(this, _pending2, false);
997
+ };
998
+ hydrate_pending_content_fn = function() {
999
+ const pending = __privateGet(this, _props).pending;
1000
+ if (!pending) {
1001
+ return;
1002
+ }
1003
+ __privateSet(this, _pending_effect, branch(() => pending(__privateGet(this, _anchor))));
1004
+ Batch.enqueue(() => {
1005
+ var anchor = __privateMethod(this, _Boundary_instances, get_anchor_fn).call(this);
1006
+ __privateSet(this, _main_effect, __privateMethod(this, _Boundary_instances, run_fn).call(this, () => {
1007
+ Batch.ensure();
1008
+ return branch(() => __privateGet(this, _children).call(this, anchor));
1009
+ }));
1010
+ if (__privateGet(this, _pending_count) > 0) {
1011
+ __privateMethod(this, _Boundary_instances, show_pending_snippet_fn).call(this);
1012
+ } else {
1013
+ pause_effect(
1014
+ /** @type {Effect} */
1015
+ __privateGet(this, _pending_effect),
1016
+ () => {
1017
+ __privateSet(this, _pending_effect, null);
1018
+ }
1019
+ );
1020
+ __privateSet(this, _pending2, false);
1021
+ }
1022
+ });
1023
+ };
1024
+ get_anchor_fn = function() {
1025
+ var anchor = __privateGet(this, _anchor);
1026
+ if (__privateGet(this, _pending2)) {
1027
+ __privateSet(this, _pending_anchor, create_text());
1028
+ __privateGet(this, _anchor).before(__privateGet(this, _pending_anchor));
1029
+ anchor = __privateGet(this, _pending_anchor);
1030
+ }
1031
+ return anchor;
1032
+ };
1033
+ /**
1034
+ * @param {() => Effect | null} fn
1035
+ */
1036
+ run_fn = function(fn) {
1037
+ var previous_effect = active_effect;
1038
+ var previous_reaction = active_reaction;
1039
+ var previous_ctx = component_context;
1040
+ set_active_effect(__privateGet(this, _effect));
1041
+ set_active_reaction(__privateGet(this, _effect));
1042
+ set_component_context(__privateGet(this, _effect).ctx);
1043
+ try {
1044
+ return fn();
1045
+ } catch (e) {
1046
+ handle_error(e);
1047
+ return null;
1048
+ } finally {
1049
+ set_active_effect(previous_effect);
1050
+ set_active_reaction(previous_reaction);
1051
+ set_component_context(previous_ctx);
1052
+ }
1053
+ };
1054
+ show_pending_snippet_fn = function() {
1055
+ const pending = (
1056
+ /** @type {(anchor: Node) => void} */
1057
+ __privateGet(this, _props).pending
1058
+ );
1059
+ if (__privateGet(this, _main_effect) !== null) {
1060
+ __privateSet(this, _offscreen_fragment, document.createDocumentFragment());
1061
+ __privateGet(this, _offscreen_fragment).append(
1062
+ /** @type {TemplateNode} */
1063
+ __privateGet(this, _pending_anchor)
1064
+ );
1065
+ move_effect(__privateGet(this, _main_effect), __privateGet(this, _offscreen_fragment));
1066
+ }
1067
+ if (__privateGet(this, _pending_effect) === null) {
1068
+ __privateSet(this, _pending_effect, branch(() => pending(__privateGet(this, _anchor))));
1069
+ }
1070
+ };
1071
+ /**
1072
+ * Updates the pending count associated with the currently visible pending snippet,
1073
+ * if any, such that we can replace the snippet with content once work is done
1074
+ * @param {1 | -1} d
1075
+ */
1076
+ update_pending_count_fn = function(d) {
1077
+ var _a2;
1078
+ if (!this.has_pending_snippet()) {
1079
+ if (this.parent) {
1080
+ __privateMethod(_a2 = this.parent, _Boundary_instances, update_pending_count_fn).call(_a2, d);
1081
+ }
1082
+ return;
1083
+ }
1084
+ __privateSet(this, _pending_count, __privateGet(this, _pending_count) + d);
1085
+ if (__privateGet(this, _pending_count) === 0) {
1086
+ __privateSet(this, _pending2, false);
1087
+ if (__privateGet(this, _pending_effect)) {
1088
+ pause_effect(__privateGet(this, _pending_effect), () => {
1089
+ __privateSet(this, _pending_effect, null);
1090
+ });
1091
+ }
1092
+ if (__privateGet(this, _offscreen_fragment)) {
1093
+ __privateGet(this, _anchor).before(__privateGet(this, _offscreen_fragment));
1094
+ __privateSet(this, _offscreen_fragment, null);
1095
+ }
1096
+ }
1097
+ };
1098
+ function flatten(blockers, sync, async, fn) {
1099
+ const d = derived;
1100
+ if (async.length === 0 && blockers.length === 0) {
1101
+ fn(sync.map(d));
1102
+ return;
1103
+ }
1104
+ var batch = current_batch;
1105
+ var parent = (
1106
+ /** @type {Effect} */
1107
+ active_effect
1108
+ );
1109
+ var restore = capture();
1110
+ function run() {
1111
+ Promise.all(async.map((expression) => /* @__PURE__ */ async_derived(expression))).then((result) => {
1112
+ restore();
1113
+ try {
1114
+ fn([...sync.map(d), ...result]);
1115
+ } catch (error) {
1116
+ if ((parent.f & DESTROYED) === 0) {
1117
+ invoke_error_boundary(error, parent);
1118
+ }
1119
+ }
1120
+ batch == null ? void 0 : batch.deactivate();
1121
+ unset_context();
1122
+ }).catch((error) => {
1123
+ invoke_error_boundary(error, parent);
1124
+ });
1125
+ }
1126
+ if (blockers.length > 0) {
1127
+ Promise.all(blockers).then(() => {
1128
+ restore();
1129
+ try {
1130
+ return run();
1131
+ } finally {
1132
+ batch == null ? void 0 : batch.deactivate();
1133
+ unset_context();
1134
+ }
1135
+ });
1136
+ } else {
1137
+ run();
1138
+ }
1139
+ }
1140
+ function capture() {
1141
+ var previous_effect = active_effect;
1142
+ var previous_reaction = active_reaction;
1143
+ var previous_component_context = component_context;
1144
+ var previous_batch2 = current_batch;
1145
+ return function restore(activate_batch = true) {
1146
+ set_active_effect(previous_effect);
1147
+ set_active_reaction(previous_reaction);
1148
+ set_component_context(previous_component_context);
1149
+ if (activate_batch) previous_batch2 == null ? void 0 : previous_batch2.activate();
1150
+ };
1151
+ }
1152
+ function unset_context() {
1153
+ set_active_effect(null);
1154
+ set_active_reaction(null);
1155
+ set_component_context(null);
1156
+ }
1157
+ // @__NO_SIDE_EFFECTS__
1158
+ function derived(fn) {
1159
+ var flags2 = DERIVED | DIRTY;
1160
+ var parent_derived = active_reaction !== null && (active_reaction.f & DERIVED) !== 0 ? (
1161
+ /** @type {Derived} */
1162
+ active_reaction
1163
+ ) : null;
1164
+ if (active_effect !== null) {
1165
+ active_effect.f |= EFFECT_PRESERVED;
1166
+ }
1167
+ const signal = {
1168
+ ctx: component_context,
1169
+ deps: null,
1170
+ effects: null,
1171
+ equals,
1172
+ f: flags2,
1173
+ fn,
1174
+ reactions: null,
1175
+ rv: 0,
1176
+ v: (
1177
+ /** @type {V} */
1178
+ UNINITIALIZED
1179
+ ),
1180
+ wv: 0,
1181
+ parent: parent_derived ?? active_effect,
1182
+ ac: null
1183
+ };
1184
+ return signal;
1185
+ }
1186
+ // @__NO_SIDE_EFFECTS__
1187
+ function async_derived(fn, location) {
1188
+ let parent = (
1189
+ /** @type {Effect | null} */
1190
+ active_effect
1191
+ );
1192
+ if (parent === null) {
1193
+ async_derived_orphan();
1194
+ }
1195
+ var boundary2 = (
1196
+ /** @type {Boundary} */
1197
+ parent.b
1198
+ );
1199
+ var promise = (
1200
+ /** @type {Promise<V>} */
1201
+ /** @type {unknown} */
1202
+ void 0
1203
+ );
1204
+ var signal = source(
1205
+ /** @type {V} */
1206
+ UNINITIALIZED
1207
+ );
1208
+ var should_suspend = !active_reaction;
1209
+ var deferreds = /* @__PURE__ */ new Map();
1210
+ async_effect(() => {
1211
+ var _a2;
1212
+ var d = deferred();
1213
+ promise = d.promise;
1214
+ try {
1215
+ Promise.resolve(fn()).then(d.resolve, d.reject).then(() => {
1216
+ if (batch === current_batch && batch.committed) {
1217
+ batch.deactivate();
1218
+ }
1219
+ unset_context();
1220
+ });
1221
+ } catch (error) {
1222
+ d.reject(error);
1223
+ unset_context();
1224
+ }
1225
+ var batch = (
1226
+ /** @type {Batch} */
1227
+ current_batch
1228
+ );
1229
+ if (should_suspend) {
1230
+ var blocking = !boundary2.is_pending();
1231
+ boundary2.update_pending_count(1);
1232
+ batch.increment(blocking);
1233
+ (_a2 = deferreds.get(batch)) == null ? void 0 : _a2.reject(STALE_REACTION);
1234
+ deferreds.delete(batch);
1235
+ deferreds.set(batch, d);
1236
+ }
1237
+ const handler = (value, error = void 0) => {
1238
+ batch.activate();
1239
+ if (error) {
1240
+ if (error !== STALE_REACTION) {
1241
+ signal.f |= ERROR_VALUE;
1242
+ internal_set(signal, error);
1243
+ }
1244
+ } else {
1245
+ if ((signal.f & ERROR_VALUE) !== 0) {
1246
+ signal.f ^= ERROR_VALUE;
1247
+ }
1248
+ internal_set(signal, value);
1249
+ for (const [b, d2] of deferreds) {
1250
+ deferreds.delete(b);
1251
+ if (b === batch) break;
1252
+ d2.reject(STALE_REACTION);
1253
+ }
1254
+ }
1255
+ if (should_suspend) {
1256
+ boundary2.update_pending_count(-1);
1257
+ batch.decrement(blocking);
1258
+ }
1259
+ };
1260
+ d.promise.then(handler, (e) => handler(null, e || "unknown"));
1261
+ });
1262
+ teardown(() => {
1263
+ for (const d of deferreds.values()) {
1264
+ d.reject(STALE_REACTION);
1265
+ }
1266
+ });
1267
+ return new Promise((fulfil) => {
1268
+ function next(p) {
1269
+ function go() {
1270
+ if (p === promise) {
1271
+ fulfil(signal);
1272
+ } else {
1273
+ next(promise);
1274
+ }
1275
+ }
1276
+ p.then(go, go);
1277
+ }
1278
+ next(promise);
1279
+ });
1280
+ }
1281
+ // @__NO_SIDE_EFFECTS__
1282
+ function user_derived(fn) {
1283
+ const d = /* @__PURE__ */ derived(fn);
1284
+ push_reaction_value(d);
1285
+ return d;
1286
+ }
1287
+ // @__NO_SIDE_EFFECTS__
1288
+ function derived_safe_equal(fn) {
1289
+ const signal = /* @__PURE__ */ derived(fn);
1290
+ signal.equals = safe_equals;
1291
+ return signal;
1292
+ }
1293
+ function destroy_derived_effects(derived2) {
1294
+ var effects = derived2.effects;
1295
+ if (effects !== null) {
1296
+ derived2.effects = null;
1297
+ for (var i = 0; i < effects.length; i += 1) {
1298
+ destroy_effect(
1299
+ /** @type {Effect} */
1300
+ effects[i]
1301
+ );
1302
+ }
1303
+ }
1304
+ }
1305
+ function get_derived_parent_effect(derived2) {
1306
+ var parent = derived2.parent;
1307
+ while (parent !== null) {
1308
+ if ((parent.f & DERIVED) === 0) {
1309
+ return (parent.f & DESTROYED) === 0 ? (
1310
+ /** @type {Effect} */
1311
+ parent
1312
+ ) : null;
1313
+ }
1314
+ parent = parent.parent;
1315
+ }
1316
+ return null;
1317
+ }
1318
+ function execute_derived(derived2) {
1319
+ var value;
1320
+ var prev_active_effect = active_effect;
1321
+ set_active_effect(get_derived_parent_effect(derived2));
1322
+ {
1323
+ try {
1324
+ derived2.f &= ~WAS_MARKED;
1325
+ destroy_derived_effects(derived2);
1326
+ value = update_reaction(derived2);
1327
+ } finally {
1328
+ set_active_effect(prev_active_effect);
1329
+ }
1330
+ }
1331
+ return value;
1332
+ }
1333
+ function update_derived(derived2) {
1334
+ var value = execute_derived(derived2);
1335
+ if (!derived2.equals(value)) {
1336
+ if (!(current_batch == null ? void 0 : current_batch.is_fork)) {
1337
+ derived2.v = value;
1338
+ }
1339
+ derived2.wv = increment_write_version();
1340
+ }
1341
+ if (is_destroying_effect) {
1342
+ return;
1343
+ }
1344
+ if (batch_values !== null) {
1345
+ if (effect_tracking() || (current_batch == null ? void 0 : current_batch.is_fork)) {
1346
+ batch_values.set(derived2, value);
1347
+ }
1348
+ } else {
1349
+ var status = (derived2.f & CONNECTED) === 0 ? MAYBE_DIRTY : CLEAN;
1350
+ set_signal_status(derived2, status);
1351
+ }
1352
+ }
1353
+ let eager_effects = /* @__PURE__ */ new Set();
1354
+ const old_values = /* @__PURE__ */ new Map();
1355
+ let eager_effects_deferred = false;
1356
+ function source(v, stack) {
1357
+ var signal = {
1358
+ f: 0,
1359
+ // TODO ideally we could skip this altogether, but it causes type errors
1360
+ v,
1361
+ reactions: null,
1362
+ equals,
1363
+ rv: 0,
1364
+ wv: 0
1365
+ };
1366
+ return signal;
1367
+ }
1368
+ // @__NO_SIDE_EFFECTS__
1369
+ function state(v, stack) {
1370
+ const s = source(v);
1371
+ push_reaction_value(s);
1372
+ return s;
1373
+ }
1374
+ // @__NO_SIDE_EFFECTS__
1375
+ function mutable_source(initial_value, immutable = false, trackable = true) {
1376
+ const s = source(initial_value);
1377
+ if (!immutable) {
1378
+ s.equals = safe_equals;
1379
+ }
1380
+ return s;
1381
+ }
1382
+ function set(source2, value, should_proxy = false) {
1383
+ if (active_reaction !== null && // since we are untracking the function inside `$inspect.with` we need to add this check
1384
+ // to ensure we error if state is set inside an inspect effect
1385
+ (!untracking || (active_reaction.f & EAGER_EFFECT) !== 0) && is_runes() && (active_reaction.f & (DERIVED | BLOCK_EFFECT | ASYNC | EAGER_EFFECT)) !== 0 && !(current_sources == null ? void 0 : current_sources.includes(source2))) {
1386
+ state_unsafe_mutation();
1387
+ }
1388
+ let new_value = should_proxy ? proxy(value) : value;
1389
+ return internal_set(source2, new_value);
1390
+ }
1391
+ function internal_set(source2, value) {
1392
+ if (!source2.equals(value)) {
1393
+ var old_value = source2.v;
1394
+ if (is_destroying_effect) {
1395
+ old_values.set(source2, value);
1396
+ } else {
1397
+ old_values.set(source2, old_value);
1398
+ }
1399
+ source2.v = value;
1400
+ var batch = Batch.ensure();
1401
+ batch.capture(source2, old_value);
1402
+ if ((source2.f & DERIVED) !== 0) {
1403
+ if ((source2.f & DIRTY) !== 0) {
1404
+ execute_derived(
1405
+ /** @type {Derived} */
1406
+ source2
1407
+ );
1408
+ }
1409
+ set_signal_status(source2, (source2.f & CONNECTED) !== 0 ? CLEAN : MAYBE_DIRTY);
1410
+ }
1411
+ source2.wv = increment_write_version();
1412
+ mark_reactions(source2, DIRTY);
1413
+ if (active_effect !== null && (active_effect.f & CLEAN) !== 0 && (active_effect.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0) {
1414
+ if (untracked_writes === null) {
1415
+ set_untracked_writes([source2]);
1416
+ } else {
1417
+ untracked_writes.push(source2);
1418
+ }
1419
+ }
1420
+ if (!batch.is_fork && eager_effects.size > 0 && !eager_effects_deferred) {
1421
+ flush_eager_effects();
1422
+ }
1423
+ }
1424
+ return value;
1425
+ }
1426
+ function flush_eager_effects() {
1427
+ eager_effects_deferred = false;
1428
+ var prev_is_updating_effect = is_updating_effect;
1429
+ set_is_updating_effect(true);
1430
+ const inspects = Array.from(eager_effects);
1431
+ try {
1432
+ for (const effect2 of inspects) {
1433
+ if ((effect2.f & CLEAN) !== 0) {
1434
+ set_signal_status(effect2, MAYBE_DIRTY);
1435
+ }
1436
+ if (is_dirty(effect2)) {
1437
+ update_effect(effect2);
1438
+ }
1439
+ }
1440
+ } finally {
1441
+ set_is_updating_effect(prev_is_updating_effect);
1442
+ }
1443
+ eager_effects.clear();
1444
+ }
1445
+ function increment(source2) {
1446
+ set(source2, source2.v + 1);
1447
+ }
1448
+ function mark_reactions(signal, status) {
1449
+ var reactions = signal.reactions;
1450
+ if (reactions === null) return;
1451
+ var length = reactions.length;
1452
+ for (var i = 0; i < length; i++) {
1453
+ var reaction = reactions[i];
1454
+ var flags2 = reaction.f;
1455
+ var not_dirty = (flags2 & DIRTY) === 0;
1456
+ if (not_dirty) {
1457
+ set_signal_status(reaction, status);
1458
+ }
1459
+ if ((flags2 & DERIVED) !== 0) {
1460
+ var derived2 = (
1461
+ /** @type {Derived} */
1462
+ reaction
1463
+ );
1464
+ batch_values == null ? void 0 : batch_values.delete(derived2);
1465
+ if ((flags2 & WAS_MARKED) === 0) {
1466
+ if (flags2 & CONNECTED) {
1467
+ reaction.f |= WAS_MARKED;
1468
+ }
1469
+ mark_reactions(derived2, MAYBE_DIRTY);
1470
+ }
1471
+ } else if (not_dirty) {
1472
+ if ((flags2 & BLOCK_EFFECT) !== 0 && eager_block_effects !== null) {
1473
+ eager_block_effects.add(
1474
+ /** @type {Effect} */
1475
+ reaction
1476
+ );
1477
+ }
1478
+ schedule_effect(
1479
+ /** @type {Effect} */
1480
+ reaction
1481
+ );
1482
+ }
1483
+ }
1484
+ }
1485
+ function proxy(value) {
1486
+ if (typeof value !== "object" || value === null || STATE_SYMBOL in value) {
1487
+ return value;
1488
+ }
1489
+ const prototype = get_prototype_of(value);
1490
+ if (prototype !== object_prototype && prototype !== array_prototype) {
1491
+ return value;
1492
+ }
1493
+ var sources = /* @__PURE__ */ new Map();
1494
+ var is_proxied_array = is_array(value);
1495
+ var version = /* @__PURE__ */ state(0);
1496
+ var parent_version = update_version;
1497
+ var with_parent = (fn) => {
1498
+ if (update_version === parent_version) {
1499
+ return fn();
1500
+ }
1501
+ var reaction = active_reaction;
1502
+ var version2 = update_version;
1503
+ set_active_reaction(null);
1504
+ set_update_version(parent_version);
1505
+ var result = fn();
1506
+ set_active_reaction(reaction);
1507
+ set_update_version(version2);
1508
+ return result;
1509
+ };
1510
+ if (is_proxied_array) {
1511
+ sources.set("length", /* @__PURE__ */ state(
1512
+ /** @type {any[]} */
1513
+ value.length
1514
+ ));
1515
+ }
1516
+ return new Proxy(
1517
+ /** @type {any} */
1518
+ value,
1519
+ {
1520
+ defineProperty(_, prop, descriptor) {
1521
+ if (!("value" in descriptor) || descriptor.configurable === false || descriptor.enumerable === false || descriptor.writable === false) {
1522
+ state_descriptors_fixed();
1523
+ }
1524
+ var s = sources.get(prop);
1525
+ if (s === void 0) {
1526
+ s = with_parent(() => {
1527
+ var s2 = /* @__PURE__ */ state(descriptor.value);
1528
+ sources.set(prop, s2);
1529
+ return s2;
1530
+ });
1531
+ } else {
1532
+ set(s, descriptor.value, true);
1533
+ }
1534
+ return true;
1535
+ },
1536
+ deleteProperty(target, prop) {
1537
+ var s = sources.get(prop);
1538
+ if (s === void 0) {
1539
+ if (prop in target) {
1540
+ const s2 = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
1541
+ sources.set(prop, s2);
1542
+ increment(version);
1543
+ }
1544
+ } else {
1545
+ set(s, UNINITIALIZED);
1546
+ increment(version);
1547
+ }
1548
+ return true;
1549
+ },
1550
+ get(target, prop, receiver) {
1551
+ var _a2;
1552
+ if (prop === STATE_SYMBOL) {
1553
+ return value;
1554
+ }
1555
+ var s = sources.get(prop);
1556
+ var exists = prop in target;
1557
+ if (s === void 0 && (!exists || ((_a2 = get_descriptor(target, prop)) == null ? void 0 : _a2.writable))) {
1558
+ s = with_parent(() => {
1559
+ var p = proxy(exists ? target[prop] : UNINITIALIZED);
1560
+ var s2 = /* @__PURE__ */ state(p);
1561
+ return s2;
1562
+ });
1563
+ sources.set(prop, s);
1564
+ }
1565
+ if (s !== void 0) {
1566
+ var v = get(s);
1567
+ return v === UNINITIALIZED ? void 0 : v;
1568
+ }
1569
+ return Reflect.get(target, prop, receiver);
1570
+ },
1571
+ getOwnPropertyDescriptor(target, prop) {
1572
+ var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
1573
+ if (descriptor && "value" in descriptor) {
1574
+ var s = sources.get(prop);
1575
+ if (s) descriptor.value = get(s);
1576
+ } else if (descriptor === void 0) {
1577
+ var source2 = sources.get(prop);
1578
+ var value2 = source2 == null ? void 0 : source2.v;
1579
+ if (source2 !== void 0 && value2 !== UNINITIALIZED) {
1580
+ return {
1581
+ enumerable: true,
1582
+ configurable: true,
1583
+ value: value2,
1584
+ writable: true
1585
+ };
1586
+ }
1587
+ }
1588
+ return descriptor;
1589
+ },
1590
+ has(target, prop) {
1591
+ var _a2;
1592
+ if (prop === STATE_SYMBOL) {
1593
+ return true;
1594
+ }
1595
+ var s = sources.get(prop);
1596
+ var has = s !== void 0 && s.v !== UNINITIALIZED || Reflect.has(target, prop);
1597
+ if (s !== void 0 || active_effect !== null && (!has || ((_a2 = get_descriptor(target, prop)) == null ? void 0 : _a2.writable))) {
1598
+ if (s === void 0) {
1599
+ s = with_parent(() => {
1600
+ var p = has ? proxy(target[prop]) : UNINITIALIZED;
1601
+ var s2 = /* @__PURE__ */ state(p);
1602
+ return s2;
1603
+ });
1604
+ sources.set(prop, s);
1605
+ }
1606
+ var value2 = get(s);
1607
+ if (value2 === UNINITIALIZED) {
1608
+ return false;
1609
+ }
1610
+ }
1611
+ return has;
1612
+ },
1613
+ set(target, prop, value2, receiver) {
1614
+ var _a2;
1615
+ var s = sources.get(prop);
1616
+ var has = prop in target;
1617
+ if (is_proxied_array && prop === "length") {
1618
+ for (var i = value2; i < /** @type {Source<number>} */
1619
+ s.v; i += 1) {
1620
+ var other_s = sources.get(i + "");
1621
+ if (other_s !== void 0) {
1622
+ set(other_s, UNINITIALIZED);
1623
+ } else if (i in target) {
1624
+ other_s = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
1625
+ sources.set(i + "", other_s);
1626
+ }
1627
+ }
1628
+ }
1629
+ if (s === void 0) {
1630
+ if (!has || ((_a2 = get_descriptor(target, prop)) == null ? void 0 : _a2.writable)) {
1631
+ s = with_parent(() => /* @__PURE__ */ state(void 0));
1632
+ set(s, proxy(value2));
1633
+ sources.set(prop, s);
1634
+ }
1635
+ } else {
1636
+ has = s.v !== UNINITIALIZED;
1637
+ var p = with_parent(() => proxy(value2));
1638
+ set(s, p);
1639
+ }
1640
+ var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
1641
+ if (descriptor == null ? void 0 : descriptor.set) {
1642
+ descriptor.set.call(receiver, value2);
1643
+ }
1644
+ if (!has) {
1645
+ if (is_proxied_array && typeof prop === "string") {
1646
+ var ls = (
1647
+ /** @type {Source<number>} */
1648
+ sources.get("length")
1649
+ );
1650
+ var n = Number(prop);
1651
+ if (Number.isInteger(n) && n >= ls.v) {
1652
+ set(ls, n + 1);
1653
+ }
1654
+ }
1655
+ increment(version);
1656
+ }
1657
+ return true;
1658
+ },
1659
+ ownKeys(target) {
1660
+ get(version);
1661
+ var own_keys = Reflect.ownKeys(target).filter((key2) => {
1662
+ var source3 = sources.get(key2);
1663
+ return source3 === void 0 || source3.v !== UNINITIALIZED;
1664
+ });
1665
+ for (var [key, source2] of sources) {
1666
+ if (source2.v !== UNINITIALIZED && !(key in target)) {
1667
+ own_keys.push(key);
1668
+ }
1669
+ }
1670
+ return own_keys;
1671
+ },
1672
+ setPrototypeOf() {
1673
+ state_prototype_fixed();
1674
+ }
1675
+ }
1676
+ );
1677
+ }
1678
+ var $window;
1679
+ var $document;
1680
+ var is_firefox;
1681
+ var first_child_getter;
1682
+ var next_sibling_getter;
1683
+ function init_operations() {
1684
+ if ($window !== void 0) {
1685
+ return;
1686
+ }
1687
+ $window = window;
1688
+ $document = document;
1689
+ is_firefox = /Firefox/.test(navigator.userAgent);
1690
+ var element_prototype = Element.prototype;
1691
+ var node_prototype = Node.prototype;
1692
+ var text_prototype = Text.prototype;
1693
+ first_child_getter = get_descriptor(node_prototype, "firstChild").get;
1694
+ next_sibling_getter = get_descriptor(node_prototype, "nextSibling").get;
1695
+ if (is_extensible(element_prototype)) {
1696
+ element_prototype.__click = void 0;
1697
+ element_prototype.__className = void 0;
1698
+ element_prototype.__attributes = null;
1699
+ element_prototype.__style = void 0;
1700
+ element_prototype.__e = void 0;
1701
+ }
1702
+ if (is_extensible(text_prototype)) {
1703
+ text_prototype.__t = void 0;
1704
+ }
1705
+ }
1706
+ function create_text(value = "") {
1707
+ return document.createTextNode(value);
1708
+ }
1709
+ // @__NO_SIDE_EFFECTS__
1710
+ function get_first_child(node) {
1711
+ return (
1712
+ /** @type {TemplateNode | null} */
1713
+ first_child_getter.call(node)
1714
+ );
1715
+ }
1716
+ // @__NO_SIDE_EFFECTS__
1717
+ function get_next_sibling(node) {
1718
+ return (
1719
+ /** @type {TemplateNode | null} */
1720
+ next_sibling_getter.call(node)
1721
+ );
1722
+ }
1723
+ function child(node, is_text) {
1724
+ {
1725
+ return /* @__PURE__ */ get_first_child(node);
1726
+ }
1727
+ }
1728
+ function first_child(node, is_text = false) {
1729
+ {
1730
+ var first = /* @__PURE__ */ get_first_child(node);
1731
+ if (first instanceof Comment && first.data === "") return /* @__PURE__ */ get_next_sibling(first);
1732
+ return first;
1733
+ }
1734
+ }
1735
+ function sibling(node, count = 1, is_text = false) {
1736
+ let next_sibling = node;
1737
+ while (count--) {
1738
+ next_sibling = /** @type {TemplateNode} */
1739
+ /* @__PURE__ */ get_next_sibling(next_sibling);
1740
+ }
1741
+ {
1742
+ return next_sibling;
1743
+ }
1744
+ }
1745
+ function clear_text_content(node) {
1746
+ node.textContent = "";
1747
+ }
1748
+ function should_defer_append() {
1749
+ return false;
1750
+ }
1751
+ let listening_to_form_reset = false;
1752
+ function add_form_reset_listener() {
1753
+ if (!listening_to_form_reset) {
1754
+ listening_to_form_reset = true;
1755
+ document.addEventListener(
1756
+ "reset",
1757
+ (evt) => {
1758
+ Promise.resolve().then(() => {
1759
+ var _a2;
1760
+ if (!evt.defaultPrevented) {
1761
+ for (
1762
+ const e of
1763
+ /**@type {HTMLFormElement} */
1764
+ evt.target.elements
1765
+ ) {
1766
+ (_a2 = e.__on_r) == null ? void 0 : _a2.call(e);
1767
+ }
1768
+ }
1769
+ });
1770
+ },
1771
+ // In the capture phase to guarantee we get noticed of it (no possibility of stopPropagation)
1772
+ { capture: true }
1773
+ );
1774
+ }
1775
+ }
1776
+ function without_reactive_context(fn) {
1777
+ var previous_reaction = active_reaction;
1778
+ var previous_effect = active_effect;
1779
+ set_active_reaction(null);
1780
+ set_active_effect(null);
1781
+ try {
1782
+ return fn();
1783
+ } finally {
1784
+ set_active_reaction(previous_reaction);
1785
+ set_active_effect(previous_effect);
1786
+ }
1787
+ }
1788
+ function listen_to_event_and_reset_event(element, event2, handler, on_reset = handler) {
1789
+ element.addEventListener(event2, () => without_reactive_context(handler));
1790
+ const prev = element.__on_r;
1791
+ if (prev) {
1792
+ element.__on_r = () => {
1793
+ prev();
1794
+ on_reset(true);
1795
+ };
1796
+ } else {
1797
+ element.__on_r = () => on_reset(true);
1798
+ }
1799
+ add_form_reset_listener();
1800
+ }
1801
+ function validate_effect(rune) {
1802
+ if (active_effect === null) {
1803
+ if (active_reaction === null) {
1804
+ effect_orphan();
1805
+ }
1806
+ effect_in_unowned_derived();
1807
+ }
1808
+ if (is_destroying_effect) {
1809
+ effect_in_teardown();
1810
+ }
1811
+ }
1812
+ function push_effect(effect2, parent_effect) {
1813
+ var parent_last = parent_effect.last;
1814
+ if (parent_last === null) {
1815
+ parent_effect.last = parent_effect.first = effect2;
1816
+ } else {
1817
+ parent_last.next = effect2;
1818
+ effect2.prev = parent_last;
1819
+ parent_effect.last = effect2;
1820
+ }
1821
+ }
1822
+ function create_effect(type, fn, sync) {
1823
+ var parent = active_effect;
1824
+ if (parent !== null && (parent.f & INERT) !== 0) {
1825
+ type |= INERT;
1826
+ }
1827
+ var effect2 = {
1828
+ ctx: component_context,
1829
+ deps: null,
1830
+ nodes: null,
1831
+ f: type | DIRTY | CONNECTED,
1832
+ first: null,
1833
+ fn,
1834
+ last: null,
1835
+ next: null,
1836
+ parent,
1837
+ b: parent && parent.b,
1838
+ prev: null,
1839
+ teardown: null,
1840
+ wv: 0,
1841
+ ac: null
1842
+ };
1843
+ if (sync) {
1844
+ try {
1845
+ update_effect(effect2);
1846
+ effect2.f |= EFFECT_RAN;
1847
+ } catch (e2) {
1848
+ destroy_effect(effect2);
1849
+ throw e2;
1850
+ }
1851
+ } else if (fn !== null) {
1852
+ schedule_effect(effect2);
1853
+ }
1854
+ var e = effect2;
1855
+ if (sync && e.deps === null && e.teardown === null && e.nodes === null && e.first === e.last && // either `null`, or a singular child
1856
+ (e.f & EFFECT_PRESERVED) === 0) {
1857
+ e = e.first;
1858
+ if ((type & BLOCK_EFFECT) !== 0 && (type & EFFECT_TRANSPARENT) !== 0 && e !== null) {
1859
+ e.f |= EFFECT_TRANSPARENT;
1860
+ }
1861
+ }
1862
+ if (e !== null) {
1863
+ e.parent = parent;
1864
+ if (parent !== null) {
1865
+ push_effect(e, parent);
1866
+ }
1867
+ if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0 && (type & ROOT_EFFECT) === 0) {
1868
+ var derived2 = (
1869
+ /** @type {Derived} */
1870
+ active_reaction
1871
+ );
1872
+ (derived2.effects ?? (derived2.effects = [])).push(e);
1873
+ }
1874
+ }
1875
+ return effect2;
1876
+ }
1877
+ function effect_tracking() {
1878
+ return active_reaction !== null && !untracking;
1879
+ }
1880
+ function teardown(fn) {
1881
+ const effect2 = create_effect(RENDER_EFFECT, null, false);
1882
+ set_signal_status(effect2, CLEAN);
1883
+ effect2.teardown = fn;
1884
+ return effect2;
1885
+ }
1886
+ function user_effect(fn) {
1887
+ validate_effect();
1888
+ var flags2 = (
1889
+ /** @type {Effect} */
1890
+ active_effect.f
1891
+ );
1892
+ var defer = !active_reaction && (flags2 & BRANCH_EFFECT) !== 0 && (flags2 & EFFECT_RAN) === 0;
1893
+ if (defer) {
1894
+ var context = (
1895
+ /** @type {ComponentContext} */
1896
+ component_context
1897
+ );
1898
+ (context.e ?? (context.e = [])).push(fn);
1899
+ } else {
1900
+ return create_user_effect(fn);
1901
+ }
1902
+ }
1903
+ function create_user_effect(fn) {
1904
+ return create_effect(EFFECT | USER_EFFECT, fn, false);
1905
+ }
1906
+ function component_root(fn) {
1907
+ Batch.ensure();
1908
+ const effect2 = create_effect(ROOT_EFFECT | EFFECT_PRESERVED, fn, true);
1909
+ return (options = {}) => {
1910
+ return new Promise((fulfil) => {
1911
+ if (options.outro) {
1912
+ pause_effect(effect2, () => {
1913
+ destroy_effect(effect2);
1914
+ fulfil(void 0);
1915
+ });
1916
+ } else {
1917
+ destroy_effect(effect2);
1918
+ fulfil(void 0);
1919
+ }
1920
+ });
1921
+ };
1922
+ }
1923
+ function effect(fn) {
1924
+ return create_effect(EFFECT, fn, false);
1925
+ }
1926
+ function async_effect(fn) {
1927
+ return create_effect(ASYNC | EFFECT_PRESERVED, fn, true);
1928
+ }
1929
+ function render_effect(fn, flags2 = 0) {
1930
+ return create_effect(RENDER_EFFECT | flags2, fn, true);
1931
+ }
1932
+ function template_effect(fn, sync = [], async = [], blockers = []) {
1933
+ flatten(blockers, sync, async, (values) => {
1934
+ create_effect(RENDER_EFFECT, () => fn(...values.map(get)), true);
1935
+ });
1936
+ }
1937
+ function block(fn, flags2 = 0) {
1938
+ var effect2 = create_effect(BLOCK_EFFECT | flags2, fn, true);
1939
+ return effect2;
1940
+ }
1941
+ function branch(fn) {
1942
+ return create_effect(BRANCH_EFFECT | EFFECT_PRESERVED, fn, true);
1943
+ }
1944
+ function execute_effect_teardown(effect2) {
1945
+ var teardown2 = effect2.teardown;
1946
+ if (teardown2 !== null) {
1947
+ const previously_destroying_effect = is_destroying_effect;
1948
+ const previous_reaction = active_reaction;
1949
+ set_is_destroying_effect(true);
1950
+ set_active_reaction(null);
1951
+ try {
1952
+ teardown2.call(null);
1953
+ } finally {
1954
+ set_is_destroying_effect(previously_destroying_effect);
1955
+ set_active_reaction(previous_reaction);
1956
+ }
1957
+ }
1958
+ }
1959
+ function destroy_effect_children(signal, remove_dom = false) {
1960
+ var effect2 = signal.first;
1961
+ signal.first = signal.last = null;
1962
+ while (effect2 !== null) {
1963
+ const controller = effect2.ac;
1964
+ if (controller !== null) {
1965
+ without_reactive_context(() => {
1966
+ controller.abort(STALE_REACTION);
1967
+ });
1968
+ }
1969
+ var next = effect2.next;
1970
+ if ((effect2.f & ROOT_EFFECT) !== 0) {
1971
+ effect2.parent = null;
1972
+ } else {
1973
+ destroy_effect(effect2, remove_dom);
1974
+ }
1975
+ effect2 = next;
1976
+ }
1977
+ }
1978
+ function destroy_block_effect_children(signal) {
1979
+ var effect2 = signal.first;
1980
+ while (effect2 !== null) {
1981
+ var next = effect2.next;
1982
+ if ((effect2.f & BRANCH_EFFECT) === 0) {
1983
+ destroy_effect(effect2);
1984
+ }
1985
+ effect2 = next;
1986
+ }
1987
+ }
1988
+ function destroy_effect(effect2, remove_dom = true) {
1989
+ var removed = false;
1990
+ if ((remove_dom || (effect2.f & HEAD_EFFECT) !== 0) && effect2.nodes !== null && effect2.nodes.end !== null) {
1991
+ remove_effect_dom(
1992
+ effect2.nodes.start,
1993
+ /** @type {TemplateNode} */
1994
+ effect2.nodes.end
1995
+ );
1996
+ removed = true;
1997
+ }
1998
+ destroy_effect_children(effect2, remove_dom && !removed);
1999
+ remove_reactions(effect2, 0);
2000
+ set_signal_status(effect2, DESTROYED);
2001
+ var transitions = effect2.nodes && effect2.nodes.t;
2002
+ if (transitions !== null) {
2003
+ for (const transition of transitions) {
2004
+ transition.stop();
2005
+ }
2006
+ }
2007
+ execute_effect_teardown(effect2);
2008
+ var parent = effect2.parent;
2009
+ if (parent !== null && parent.first !== null) {
2010
+ unlink_effect(effect2);
2011
+ }
2012
+ effect2.next = effect2.prev = effect2.teardown = effect2.ctx = effect2.deps = effect2.fn = effect2.nodes = effect2.ac = null;
2013
+ }
2014
+ function remove_effect_dom(node, end) {
2015
+ while (node !== null) {
2016
+ var next = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
2017
+ node.remove();
2018
+ node = next;
2019
+ }
2020
+ }
2021
+ function unlink_effect(effect2) {
2022
+ var parent = effect2.parent;
2023
+ var prev = effect2.prev;
2024
+ var next = effect2.next;
2025
+ if (prev !== null) prev.next = next;
2026
+ if (next !== null) next.prev = prev;
2027
+ if (parent !== null) {
2028
+ if (parent.first === effect2) parent.first = next;
2029
+ if (parent.last === effect2) parent.last = prev;
2030
+ }
2031
+ }
2032
+ function pause_effect(effect2, callback, destroy = true) {
2033
+ var transitions = [];
2034
+ pause_children(effect2, transitions, true);
2035
+ var fn = () => {
2036
+ if (destroy) destroy_effect(effect2);
2037
+ if (callback) callback();
2038
+ };
2039
+ var remaining = transitions.length;
2040
+ if (remaining > 0) {
2041
+ var check = () => --remaining || fn();
2042
+ for (var transition of transitions) {
2043
+ transition.out(check);
2044
+ }
2045
+ } else {
2046
+ fn();
2047
+ }
2048
+ }
2049
+ function pause_children(effect2, transitions, local) {
2050
+ if ((effect2.f & INERT) !== 0) return;
2051
+ effect2.f ^= INERT;
2052
+ var t = effect2.nodes && effect2.nodes.t;
2053
+ if (t !== null) {
2054
+ for (const transition of t) {
2055
+ if (transition.is_global || local) {
2056
+ transitions.push(transition);
2057
+ }
2058
+ }
2059
+ }
2060
+ var child2 = effect2.first;
2061
+ while (child2 !== null) {
2062
+ var sibling2 = child2.next;
2063
+ var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || // If this is a branch effect without a block effect parent,
2064
+ // it means the parent block effect was pruned. In that case,
2065
+ // transparency information was transferred to the branch effect.
2066
+ (child2.f & BRANCH_EFFECT) !== 0 && (effect2.f & BLOCK_EFFECT) !== 0;
2067
+ pause_children(child2, transitions, transparent ? local : false);
2068
+ child2 = sibling2;
2069
+ }
2070
+ }
2071
+ function resume_effect(effect2) {
2072
+ resume_children(effect2, true);
2073
+ }
2074
+ function resume_children(effect2, local) {
2075
+ if ((effect2.f & INERT) === 0) return;
2076
+ effect2.f ^= INERT;
2077
+ if ((effect2.f & CLEAN) === 0) {
2078
+ set_signal_status(effect2, DIRTY);
2079
+ schedule_effect(effect2);
2080
+ }
2081
+ var child2 = effect2.first;
2082
+ while (child2 !== null) {
2083
+ var sibling2 = child2.next;
2084
+ var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || (child2.f & BRANCH_EFFECT) !== 0;
2085
+ resume_children(child2, transparent ? local : false);
2086
+ child2 = sibling2;
2087
+ }
2088
+ var t = effect2.nodes && effect2.nodes.t;
2089
+ if (t !== null) {
2090
+ for (const transition of t) {
2091
+ if (transition.is_global || local) {
2092
+ transition.in();
2093
+ }
2094
+ }
2095
+ }
2096
+ }
2097
+ function move_effect(effect2, fragment) {
2098
+ if (!effect2.nodes) return;
2099
+ var node = effect2.nodes.start;
2100
+ var end = effect2.nodes.end;
2101
+ while (node !== null) {
2102
+ var next = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
2103
+ fragment.append(node);
2104
+ node = next;
2105
+ }
2106
+ }
2107
+ let is_updating_effect = false;
2108
+ function set_is_updating_effect(value) {
2109
+ is_updating_effect = value;
2110
+ }
2111
+ let is_destroying_effect = false;
2112
+ function set_is_destroying_effect(value) {
2113
+ is_destroying_effect = value;
2114
+ }
2115
+ let active_reaction = null;
2116
+ let untracking = false;
2117
+ function set_active_reaction(reaction) {
2118
+ active_reaction = reaction;
2119
+ }
2120
+ let active_effect = null;
2121
+ function set_active_effect(effect2) {
2122
+ active_effect = effect2;
2123
+ }
2124
+ let current_sources = null;
2125
+ function push_reaction_value(value) {
2126
+ if (active_reaction !== null && true) {
2127
+ if (current_sources === null) {
2128
+ current_sources = [value];
2129
+ } else {
2130
+ current_sources.push(value);
2131
+ }
2132
+ }
2133
+ }
2134
+ let new_deps = null;
2135
+ let skipped_deps = 0;
2136
+ let untracked_writes = null;
2137
+ function set_untracked_writes(value) {
2138
+ untracked_writes = value;
2139
+ }
2140
+ let write_version = 1;
2141
+ let read_version = 0;
2142
+ let update_version = read_version;
2143
+ function set_update_version(value) {
2144
+ update_version = value;
2145
+ }
2146
+ function increment_write_version() {
2147
+ return ++write_version;
2148
+ }
2149
+ function is_dirty(reaction) {
2150
+ var flags2 = reaction.f;
2151
+ if ((flags2 & DIRTY) !== 0) {
2152
+ return true;
2153
+ }
2154
+ if (flags2 & DERIVED) {
2155
+ reaction.f &= ~WAS_MARKED;
2156
+ }
2157
+ if ((flags2 & MAYBE_DIRTY) !== 0) {
2158
+ var dependencies = reaction.deps;
2159
+ if (dependencies !== null) {
2160
+ var length = dependencies.length;
2161
+ for (var i = 0; i < length; i++) {
2162
+ var dependency = dependencies[i];
2163
+ if (is_dirty(
2164
+ /** @type {Derived} */
2165
+ dependency
2166
+ )) {
2167
+ update_derived(
2168
+ /** @type {Derived} */
2169
+ dependency
2170
+ );
2171
+ }
2172
+ if (dependency.wv > reaction.wv) {
2173
+ return true;
2174
+ }
2175
+ }
2176
+ }
2177
+ if ((flags2 & CONNECTED) !== 0 && // During time traveling we don't want to reset the status so that
2178
+ // traversal of the graph in the other batches still happens
2179
+ batch_values === null) {
2180
+ set_signal_status(reaction, CLEAN);
2181
+ }
2182
+ }
2183
+ return false;
2184
+ }
2185
+ function schedule_possible_effect_self_invalidation(signal, effect2, root2 = true) {
2186
+ var reactions = signal.reactions;
2187
+ if (reactions === null) return;
2188
+ if (current_sources == null ? void 0 : current_sources.includes(signal)) {
2189
+ return;
2190
+ }
2191
+ for (var i = 0; i < reactions.length; i++) {
2192
+ var reaction = reactions[i];
2193
+ if ((reaction.f & DERIVED) !== 0) {
2194
+ schedule_possible_effect_self_invalidation(
2195
+ /** @type {Derived} */
2196
+ reaction,
2197
+ effect2,
2198
+ false
2199
+ );
2200
+ } else if (effect2 === reaction) {
2201
+ if (root2) {
2202
+ set_signal_status(reaction, DIRTY);
2203
+ } else if ((reaction.f & CLEAN) !== 0) {
2204
+ set_signal_status(reaction, MAYBE_DIRTY);
2205
+ }
2206
+ schedule_effect(
2207
+ /** @type {Effect} */
2208
+ reaction
2209
+ );
2210
+ }
2211
+ }
2212
+ }
2213
+ function update_reaction(reaction) {
2214
+ var _a2;
2215
+ var previous_deps = new_deps;
2216
+ var previous_skipped_deps = skipped_deps;
2217
+ var previous_untracked_writes = untracked_writes;
2218
+ var previous_reaction = active_reaction;
2219
+ var previous_sources = current_sources;
2220
+ var previous_component_context = component_context;
2221
+ var previous_untracking = untracking;
2222
+ var previous_update_version = update_version;
2223
+ var flags2 = reaction.f;
2224
+ new_deps = /** @type {null | Value[]} */
2225
+ null;
2226
+ skipped_deps = 0;
2227
+ untracked_writes = null;
2228
+ active_reaction = (flags2 & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
2229
+ current_sources = null;
2230
+ set_component_context(reaction.ctx);
2231
+ untracking = false;
2232
+ update_version = ++read_version;
2233
+ if (reaction.ac !== null) {
2234
+ without_reactive_context(() => {
2235
+ reaction.ac.abort(STALE_REACTION);
2236
+ });
2237
+ reaction.ac = null;
2238
+ }
2239
+ try {
2240
+ reaction.f |= REACTION_IS_UPDATING;
2241
+ var fn = (
2242
+ /** @type {Function} */
2243
+ reaction.fn
2244
+ );
2245
+ var result = fn();
2246
+ var deps = reaction.deps;
2247
+ if (new_deps !== null) {
2248
+ var i;
2249
+ remove_reactions(reaction, skipped_deps);
2250
+ if (deps !== null && skipped_deps > 0) {
2251
+ deps.length = skipped_deps + new_deps.length;
2252
+ for (i = 0; i < new_deps.length; i++) {
2253
+ deps[skipped_deps + i] = new_deps[i];
2254
+ }
2255
+ } else {
2256
+ reaction.deps = deps = new_deps;
2257
+ }
2258
+ if (effect_tracking() && (reaction.f & CONNECTED) !== 0) {
2259
+ for (i = skipped_deps; i < deps.length; i++) {
2260
+ ((_a2 = deps[i]).reactions ?? (_a2.reactions = [])).push(reaction);
2261
+ }
2262
+ }
2263
+ } else if (deps !== null && skipped_deps < deps.length) {
2264
+ remove_reactions(reaction, skipped_deps);
2265
+ deps.length = skipped_deps;
2266
+ }
2267
+ if (is_runes() && untracked_writes !== null && !untracking && deps !== null && (reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0) {
2268
+ for (i = 0; i < /** @type {Source[]} */
2269
+ untracked_writes.length; i++) {
2270
+ schedule_possible_effect_self_invalidation(
2271
+ untracked_writes[i],
2272
+ /** @type {Effect} */
2273
+ reaction
2274
+ );
2275
+ }
2276
+ }
2277
+ if (previous_reaction !== null && previous_reaction !== reaction) {
2278
+ read_version++;
2279
+ if (untracked_writes !== null) {
2280
+ if (previous_untracked_writes === null) {
2281
+ previous_untracked_writes = untracked_writes;
2282
+ } else {
2283
+ previous_untracked_writes.push(.../** @type {Source[]} */
2284
+ untracked_writes);
2285
+ }
2286
+ }
2287
+ }
2288
+ if ((reaction.f & ERROR_VALUE) !== 0) {
2289
+ reaction.f ^= ERROR_VALUE;
2290
+ }
2291
+ return result;
2292
+ } catch (error) {
2293
+ return handle_error(error);
2294
+ } finally {
2295
+ reaction.f ^= REACTION_IS_UPDATING;
2296
+ new_deps = previous_deps;
2297
+ skipped_deps = previous_skipped_deps;
2298
+ untracked_writes = previous_untracked_writes;
2299
+ active_reaction = previous_reaction;
2300
+ current_sources = previous_sources;
2301
+ set_component_context(previous_component_context);
2302
+ untracking = previous_untracking;
2303
+ update_version = previous_update_version;
2304
+ }
2305
+ }
2306
+ function remove_reaction(signal, dependency) {
2307
+ let reactions = dependency.reactions;
2308
+ if (reactions !== null) {
2309
+ var index = index_of.call(reactions, signal);
2310
+ if (index !== -1) {
2311
+ var new_length = reactions.length - 1;
2312
+ if (new_length === 0) {
2313
+ reactions = dependency.reactions = null;
2314
+ } else {
2315
+ reactions[index] = reactions[new_length];
2316
+ reactions.pop();
2317
+ }
2318
+ }
2319
+ }
2320
+ if (reactions === null && (dependency.f & DERIVED) !== 0 && // Destroying a child effect while updating a parent effect can cause a dependency to appear
2321
+ // to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps`
2322
+ // allows us to skip the expensive work of disconnecting and immediately reconnecting it
2323
+ (new_deps === null || !new_deps.includes(dependency))) {
2324
+ set_signal_status(dependency, MAYBE_DIRTY);
2325
+ if ((dependency.f & CONNECTED) !== 0) {
2326
+ dependency.f ^= CONNECTED;
2327
+ dependency.f &= ~WAS_MARKED;
2328
+ }
2329
+ destroy_derived_effects(
2330
+ /** @type {Derived} **/
2331
+ dependency
2332
+ );
2333
+ remove_reactions(
2334
+ /** @type {Derived} **/
2335
+ dependency,
2336
+ 0
2337
+ );
2338
+ }
2339
+ }
2340
+ function remove_reactions(signal, start_index) {
2341
+ var dependencies = signal.deps;
2342
+ if (dependencies === null) return;
2343
+ for (var i = start_index; i < dependencies.length; i++) {
2344
+ remove_reaction(signal, dependencies[i]);
2345
+ }
2346
+ }
2347
+ function update_effect(effect2) {
2348
+ var flags2 = effect2.f;
2349
+ if ((flags2 & DESTROYED) !== 0) {
2350
+ return;
2351
+ }
2352
+ set_signal_status(effect2, CLEAN);
2353
+ var previous_effect = active_effect;
2354
+ var was_updating_effect = is_updating_effect;
2355
+ active_effect = effect2;
2356
+ is_updating_effect = true;
2357
+ try {
2358
+ if ((flags2 & (BLOCK_EFFECT | MANAGED_EFFECT)) !== 0) {
2359
+ destroy_block_effect_children(effect2);
2360
+ } else {
2361
+ destroy_effect_children(effect2);
2362
+ }
2363
+ execute_effect_teardown(effect2);
2364
+ var teardown2 = update_reaction(effect2);
2365
+ effect2.teardown = typeof teardown2 === "function" ? teardown2 : null;
2366
+ effect2.wv = write_version;
2367
+ var dep;
2368
+ if (DEV && tracing_mode_flag && (effect2.f & DIRTY) !== 0 && effect2.deps !== null) ;
2369
+ } finally {
2370
+ is_updating_effect = was_updating_effect;
2371
+ active_effect = previous_effect;
2372
+ }
2373
+ }
2374
+ async function tick() {
2375
+ await Promise.resolve();
2376
+ flushSync();
2377
+ }
2378
+ function get(signal) {
2379
+ var flags2 = signal.f;
2380
+ var is_derived = (flags2 & DERIVED) !== 0;
2381
+ if (active_reaction !== null && !untracking) {
2382
+ var destroyed = active_effect !== null && (active_effect.f & DESTROYED) !== 0;
2383
+ if (!destroyed && !(current_sources == null ? void 0 : current_sources.includes(signal))) {
2384
+ var deps = active_reaction.deps;
2385
+ if ((active_reaction.f & REACTION_IS_UPDATING) !== 0) {
2386
+ if (signal.rv < read_version) {
2387
+ signal.rv = read_version;
2388
+ if (new_deps === null && deps !== null && deps[skipped_deps] === signal) {
2389
+ skipped_deps++;
2390
+ } else if (new_deps === null) {
2391
+ new_deps = [signal];
2392
+ } else if (!new_deps.includes(signal)) {
2393
+ new_deps.push(signal);
2394
+ }
2395
+ }
2396
+ } else {
2397
+ (active_reaction.deps ?? (active_reaction.deps = [])).push(signal);
2398
+ var reactions = signal.reactions;
2399
+ if (reactions === null) {
2400
+ signal.reactions = [active_reaction];
2401
+ } else if (!reactions.includes(active_reaction)) {
2402
+ reactions.push(active_reaction);
2403
+ }
2404
+ }
2405
+ }
2406
+ }
2407
+ if (is_destroying_effect) {
2408
+ if (old_values.has(signal)) {
2409
+ return old_values.get(signal);
2410
+ }
2411
+ if (is_derived) {
2412
+ var derived2 = (
2413
+ /** @type {Derived} */
2414
+ signal
2415
+ );
2416
+ var value = derived2.v;
2417
+ if ((derived2.f & CLEAN) === 0 && derived2.reactions !== null || depends_on_old_values(derived2)) {
2418
+ value = execute_derived(derived2);
2419
+ }
2420
+ old_values.set(derived2, value);
2421
+ return value;
2422
+ }
2423
+ } else if (is_derived && (!(batch_values == null ? void 0 : batch_values.has(signal)) || (current_batch == null ? void 0 : current_batch.is_fork) && !effect_tracking())) {
2424
+ derived2 = /** @type {Derived} */
2425
+ signal;
2426
+ if (is_dirty(derived2)) {
2427
+ update_derived(derived2);
2428
+ }
2429
+ if (is_updating_effect && effect_tracking() && (derived2.f & CONNECTED) === 0) {
2430
+ reconnect(derived2);
2431
+ }
2432
+ }
2433
+ if (batch_values == null ? void 0 : batch_values.has(signal)) {
2434
+ return batch_values.get(signal);
2435
+ }
2436
+ if ((signal.f & ERROR_VALUE) !== 0) {
2437
+ throw signal.v;
2438
+ }
2439
+ return signal.v;
2440
+ }
2441
+ function reconnect(derived2) {
2442
+ if (derived2.deps === null) return;
2443
+ derived2.f ^= CONNECTED;
2444
+ for (const dep of derived2.deps) {
2445
+ (dep.reactions ?? (dep.reactions = [])).push(derived2);
2446
+ if ((dep.f & DERIVED) !== 0 && (dep.f & CONNECTED) === 0) {
2447
+ reconnect(
2448
+ /** @type {Derived} */
2449
+ dep
2450
+ );
2451
+ }
2452
+ }
2453
+ }
2454
+ function depends_on_old_values(derived2) {
2455
+ if (derived2.v === UNINITIALIZED) return true;
2456
+ if (derived2.deps === null) return false;
2457
+ for (const dep of derived2.deps) {
2458
+ if (old_values.has(dep)) {
2459
+ return true;
2460
+ }
2461
+ if ((dep.f & DERIVED) !== 0 && depends_on_old_values(
2462
+ /** @type {Derived} */
2463
+ dep
2464
+ )) {
2465
+ return true;
2466
+ }
2467
+ }
2468
+ return false;
2469
+ }
2470
+ function untrack(fn) {
2471
+ var previous_untracking = untracking;
2472
+ try {
2473
+ untracking = true;
2474
+ return fn();
2475
+ } finally {
2476
+ untracking = previous_untracking;
2477
+ }
2478
+ }
2479
+ const STATUS_MASK = -7169;
2480
+ function set_signal_status(signal, status) {
2481
+ signal.f = signal.f & STATUS_MASK | status;
2482
+ }
2483
+ const PASSIVE_EVENTS = ["touchstart", "touchmove"];
2484
+ function is_passive_event(name) {
2485
+ return PASSIVE_EVENTS.includes(name);
2486
+ }
2487
+ const all_registered_events = /* @__PURE__ */ new Set();
2488
+ const root_event_handles = /* @__PURE__ */ new Set();
2489
+ function create_event(event_name, dom, handler, options = {}) {
2490
+ function target_handler(event2) {
2491
+ if (!options.capture) {
2492
+ handle_event_propagation.call(dom, event2);
2493
+ }
2494
+ if (!event2.cancelBubble) {
2495
+ return without_reactive_context(() => {
2496
+ return handler == null ? void 0 : handler.call(this, event2);
2497
+ });
2498
+ }
2499
+ }
2500
+ if (event_name.startsWith("pointer") || event_name.startsWith("touch") || event_name === "wheel") {
2501
+ queue_micro_task(() => {
2502
+ dom.addEventListener(event_name, target_handler, options);
2503
+ });
2504
+ } else {
2505
+ dom.addEventListener(event_name, target_handler, options);
2506
+ }
2507
+ return target_handler;
2508
+ }
2509
+ function event(event_name, dom, handler, capture2, passive) {
2510
+ var options = { capture: capture2, passive };
2511
+ var target_handler = create_event(event_name, dom, handler, options);
2512
+ if (dom === document.body || // @ts-ignore
2513
+ dom === window || // @ts-ignore
2514
+ dom === document || // Firefox has quirky behavior, it can happen that we still get "canplay" events when the element is already removed
2515
+ dom instanceof HTMLMediaElement) {
2516
+ teardown(() => {
2517
+ dom.removeEventListener(event_name, target_handler, options);
2518
+ });
2519
+ }
2520
+ }
2521
+ function delegate(events) {
2522
+ for (var i = 0; i < events.length; i++) {
2523
+ all_registered_events.add(events[i]);
2524
+ }
2525
+ for (var fn of root_event_handles) {
2526
+ fn(events);
2527
+ }
2528
+ }
2529
+ let last_propagated_event = null;
2530
+ function handle_event_propagation(event2) {
2531
+ var _a2;
2532
+ var handler_element = this;
2533
+ var owner_document = (
2534
+ /** @type {Node} */
2535
+ handler_element.ownerDocument
2536
+ );
2537
+ var event_name = event2.type;
2538
+ var path = ((_a2 = event2.composedPath) == null ? void 0 : _a2.call(event2)) || [];
2539
+ var current_target = (
2540
+ /** @type {null | Element} */
2541
+ path[0] || event2.target
2542
+ );
2543
+ last_propagated_event = event2;
2544
+ var path_idx = 0;
2545
+ var handled_at = last_propagated_event === event2 && event2.__root;
2546
+ if (handled_at) {
2547
+ var at_idx = path.indexOf(handled_at);
2548
+ if (at_idx !== -1 && (handler_element === document || handler_element === /** @type {any} */
2549
+ window)) {
2550
+ event2.__root = handler_element;
2551
+ return;
2552
+ }
2553
+ var handler_idx = path.indexOf(handler_element);
2554
+ if (handler_idx === -1) {
2555
+ return;
2556
+ }
2557
+ if (at_idx <= handler_idx) {
2558
+ path_idx = at_idx;
2559
+ }
2560
+ }
2561
+ current_target = /** @type {Element} */
2562
+ path[path_idx] || event2.target;
2563
+ if (current_target === handler_element) return;
2564
+ define_property(event2, "currentTarget", {
2565
+ configurable: true,
2566
+ get() {
2567
+ return current_target || owner_document;
2568
+ }
2569
+ });
2570
+ var previous_reaction = active_reaction;
2571
+ var previous_effect = active_effect;
2572
+ set_active_reaction(null);
2573
+ set_active_effect(null);
2574
+ try {
2575
+ var throw_error;
2576
+ var other_errors = [];
2577
+ while (current_target !== null) {
2578
+ var parent_element = current_target.assignedSlot || current_target.parentNode || /** @type {any} */
2579
+ current_target.host || null;
2580
+ try {
2581
+ var delegated = current_target["__" + event_name];
2582
+ if (delegated != null && (!/** @type {any} */
2583
+ current_target.disabled || // DOM could've been updated already by the time this is reached, so we check this as well
2584
+ // -> the target could not have been disabled because it emits the event in the first place
2585
+ event2.target === current_target)) {
2586
+ delegated.call(current_target, event2);
2587
+ }
2588
+ } catch (error) {
2589
+ if (throw_error) {
2590
+ other_errors.push(error);
2591
+ } else {
2592
+ throw_error = error;
2593
+ }
2594
+ }
2595
+ if (event2.cancelBubble || parent_element === handler_element || parent_element === null) {
2596
+ break;
2597
+ }
2598
+ current_target = parent_element;
2599
+ }
2600
+ if (throw_error) {
2601
+ for (let error of other_errors) {
2602
+ queueMicrotask(() => {
2603
+ throw error;
2604
+ });
2605
+ }
2606
+ throw throw_error;
2607
+ }
2608
+ } finally {
2609
+ event2.__root = handler_element;
2610
+ delete event2.currentTarget;
2611
+ set_active_reaction(previous_reaction);
2612
+ set_active_effect(previous_effect);
2613
+ }
2614
+ }
2615
+ function create_fragment_from_html(html) {
2616
+ var elem = document.createElement("template");
2617
+ elem.innerHTML = html.replaceAll("<!>", "<!---->");
2618
+ return elem.content;
2619
+ }
2620
+ function assign_nodes(start, end) {
2621
+ var effect2 = (
2622
+ /** @type {Effect} */
2623
+ active_effect
2624
+ );
2625
+ if (effect2.nodes === null) {
2626
+ effect2.nodes = { start, end, a: null, t: null };
2627
+ }
2628
+ }
2629
+ // @__NO_SIDE_EFFECTS__
2630
+ function from_html(content, flags2) {
2631
+ var is_fragment = (flags2 & TEMPLATE_FRAGMENT) !== 0;
2632
+ var use_import_node = (flags2 & TEMPLATE_USE_IMPORT_NODE) !== 0;
2633
+ var node;
2634
+ var has_start = !content.startsWith("<!>");
2635
+ return () => {
2636
+ if (node === void 0) {
2637
+ node = create_fragment_from_html(has_start ? content : "<!>" + content);
2638
+ if (!is_fragment) node = /** @type {TemplateNode} */
2639
+ /* @__PURE__ */ get_first_child(node);
2640
+ }
2641
+ var clone = (
2642
+ /** @type {TemplateNode} */
2643
+ use_import_node || is_firefox ? document.importNode(node, true) : node.cloneNode(true)
2644
+ );
2645
+ if (is_fragment) {
2646
+ var start = (
2647
+ /** @type {TemplateNode} */
2648
+ /* @__PURE__ */ get_first_child(clone)
2649
+ );
2650
+ var end = (
2651
+ /** @type {TemplateNode} */
2652
+ clone.lastChild
2653
+ );
2654
+ assign_nodes(start, end);
2655
+ } else {
2656
+ assign_nodes(clone, clone);
2657
+ }
2658
+ return clone;
2659
+ };
2660
+ }
2661
+ function append(anchor, dom) {
2662
+ if (anchor === null) {
2663
+ return;
2664
+ }
2665
+ anchor.before(
2666
+ /** @type {Node} */
2667
+ dom
2668
+ );
2669
+ }
2670
+ function set_text(text, value) {
2671
+ var str = value == null ? "" : typeof value === "object" ? value + "" : value;
2672
+ if (str !== (text.__t ?? (text.__t = text.nodeValue))) {
2673
+ text.__t = str;
2674
+ text.nodeValue = str + "";
2675
+ }
2676
+ }
2677
+ function mount(component, options) {
2678
+ return _mount(component, options);
2679
+ }
2680
+ const document_listeners = /* @__PURE__ */ new Map();
2681
+ function _mount(Component, { target, anchor, props = {}, events, context, intro = true }) {
2682
+ init_operations();
2683
+ var registered_events = /* @__PURE__ */ new Set();
2684
+ var event_handle = (events2) => {
2685
+ for (var i = 0; i < events2.length; i++) {
2686
+ var event_name = events2[i];
2687
+ if (registered_events.has(event_name)) continue;
2688
+ registered_events.add(event_name);
2689
+ var passive = is_passive_event(event_name);
2690
+ target.addEventListener(event_name, handle_event_propagation, { passive });
2691
+ var n = document_listeners.get(event_name);
2692
+ if (n === void 0) {
2693
+ document.addEventListener(event_name, handle_event_propagation, { passive });
2694
+ document_listeners.set(event_name, 1);
2695
+ } else {
2696
+ document_listeners.set(event_name, n + 1);
2697
+ }
2698
+ }
2699
+ };
2700
+ event_handle(array_from(all_registered_events));
2701
+ root_event_handles.add(event_handle);
2702
+ var component = void 0;
2703
+ var unmount2 = component_root(() => {
2704
+ var anchor_node = anchor ?? target.appendChild(create_text());
2705
+ boundary(
2706
+ /** @type {TemplateNode} */
2707
+ anchor_node,
2708
+ {
2709
+ pending: () => {
2710
+ }
2711
+ },
2712
+ (anchor_node2) => {
2713
+ if (context) {
2714
+ push({});
2715
+ var ctx = (
2716
+ /** @type {ComponentContext} */
2717
+ component_context
2718
+ );
2719
+ ctx.c = context;
2720
+ }
2721
+ if (events) {
2722
+ props.$$events = events;
2723
+ }
2724
+ component = Component(anchor_node2, props) || {};
2725
+ if (context) {
2726
+ pop();
2727
+ }
2728
+ }
2729
+ );
2730
+ return () => {
2731
+ var _a2;
2732
+ for (var event_name of registered_events) {
2733
+ target.removeEventListener(event_name, handle_event_propagation);
2734
+ var n = (
2735
+ /** @type {number} */
2736
+ document_listeners.get(event_name)
2737
+ );
2738
+ if (--n === 0) {
2739
+ document.removeEventListener(event_name, handle_event_propagation);
2740
+ document_listeners.delete(event_name);
2741
+ } else {
2742
+ document_listeners.set(event_name, n);
2743
+ }
2744
+ }
2745
+ root_event_handles.delete(event_handle);
2746
+ if (anchor_node !== anchor) {
2747
+ (_a2 = anchor_node.parentNode) == null ? void 0 : _a2.removeChild(anchor_node);
2748
+ }
2749
+ };
2750
+ });
2751
+ mounted_components.set(component, unmount2);
2752
+ return component;
2753
+ }
2754
+ let mounted_components = /* @__PURE__ */ new WeakMap();
2755
+ function unmount(component, options) {
2756
+ const fn = mounted_components.get(component);
2757
+ if (fn) {
2758
+ mounted_components.delete(component);
2759
+ return fn(options);
2760
+ }
2761
+ return Promise.resolve();
2762
+ }
2763
+ class BranchManager {
2764
+ /**
2765
+ * @param {TemplateNode} anchor
2766
+ * @param {boolean} transition
2767
+ */
2768
+ constructor(anchor, transition = true) {
2769
+ /** @type {TemplateNode} */
2770
+ __publicField(this, "anchor");
2771
+ /** @type {Map<Batch, Key>} */
2772
+ __privateAdd(this, _batches, /* @__PURE__ */ new Map());
2773
+ /**
2774
+ * Map of keys to effects that are currently rendered in the DOM.
2775
+ * These effects are visible and actively part of the document tree.
2776
+ * Example:
2777
+ * ```
2778
+ * {#if condition}
2779
+ * foo
2780
+ * {:else}
2781
+ * bar
2782
+ * {/if}
2783
+ * ```
2784
+ * Can result in the entries `true->Effect` and `false->Effect`
2785
+ * @type {Map<Key, Effect>}
2786
+ */
2787
+ __privateAdd(this, _onscreen, /* @__PURE__ */ new Map());
2788
+ /**
2789
+ * Similar to #onscreen with respect to the keys, but contains branches that are not yet
2790
+ * in the DOM, because their insertion is deferred.
2791
+ * @type {Map<Key, Branch>}
2792
+ */
2793
+ __privateAdd(this, _offscreen, /* @__PURE__ */ new Map());
2794
+ /**
2795
+ * Keys of effects that are currently outroing
2796
+ * @type {Set<Key>}
2797
+ */
2798
+ __privateAdd(this, _outroing, /* @__PURE__ */ new Set());
2799
+ /**
2800
+ * Whether to pause (i.e. outro) on change, or destroy immediately.
2801
+ * This is necessary for `<svelte:element>`
2802
+ */
2803
+ __privateAdd(this, _transition, true);
2804
+ __privateAdd(this, _commit, () => {
2805
+ var batch = (
2806
+ /** @type {Batch} */
2807
+ current_batch
2808
+ );
2809
+ if (!__privateGet(this, _batches).has(batch)) return;
2810
+ var key = (
2811
+ /** @type {Key} */
2812
+ __privateGet(this, _batches).get(batch)
2813
+ );
2814
+ var onscreen = __privateGet(this, _onscreen).get(key);
2815
+ if (onscreen) {
2816
+ resume_effect(onscreen);
2817
+ __privateGet(this, _outroing).delete(key);
2818
+ } else {
2819
+ var offscreen = __privateGet(this, _offscreen).get(key);
2820
+ if (offscreen) {
2821
+ __privateGet(this, _onscreen).set(key, offscreen.effect);
2822
+ __privateGet(this, _offscreen).delete(key);
2823
+ offscreen.fragment.lastChild.remove();
2824
+ this.anchor.before(offscreen.fragment);
2825
+ onscreen = offscreen.effect;
2826
+ }
2827
+ }
2828
+ for (const [b, k] of __privateGet(this, _batches)) {
2829
+ __privateGet(this, _batches).delete(b);
2830
+ if (b === batch) {
2831
+ break;
2832
+ }
2833
+ const offscreen2 = __privateGet(this, _offscreen).get(k);
2834
+ if (offscreen2) {
2835
+ destroy_effect(offscreen2.effect);
2836
+ __privateGet(this, _offscreen).delete(k);
2837
+ }
2838
+ }
2839
+ for (const [k, effect2] of __privateGet(this, _onscreen)) {
2840
+ if (k === key || __privateGet(this, _outroing).has(k)) continue;
2841
+ const on_destroy = () => {
2842
+ const keys = Array.from(__privateGet(this, _batches).values());
2843
+ if (keys.includes(k)) {
2844
+ var fragment = document.createDocumentFragment();
2845
+ move_effect(effect2, fragment);
2846
+ fragment.append(create_text());
2847
+ __privateGet(this, _offscreen).set(k, { effect: effect2, fragment });
2848
+ } else {
2849
+ destroy_effect(effect2);
2850
+ }
2851
+ __privateGet(this, _outroing).delete(k);
2852
+ __privateGet(this, _onscreen).delete(k);
2853
+ };
2854
+ if (__privateGet(this, _transition) || !onscreen) {
2855
+ __privateGet(this, _outroing).add(k);
2856
+ pause_effect(effect2, on_destroy, false);
2857
+ } else {
2858
+ on_destroy();
2859
+ }
2860
+ }
2861
+ });
2862
+ /**
2863
+ * @param {Batch} batch
2864
+ */
2865
+ __privateAdd(this, _discard, (batch) => {
2866
+ __privateGet(this, _batches).delete(batch);
2867
+ const keys = Array.from(__privateGet(this, _batches).values());
2868
+ for (const [k, branch2] of __privateGet(this, _offscreen)) {
2869
+ if (!keys.includes(k)) {
2870
+ destroy_effect(branch2.effect);
2871
+ __privateGet(this, _offscreen).delete(k);
2872
+ }
2873
+ }
2874
+ });
2875
+ this.anchor = anchor;
2876
+ __privateSet(this, _transition, transition);
2877
+ }
2878
+ /**
2879
+ *
2880
+ * @param {any} key
2881
+ * @param {null | ((target: TemplateNode) => void)} fn
2882
+ */
2883
+ ensure(key, fn) {
2884
+ var batch = (
2885
+ /** @type {Batch} */
2886
+ current_batch
2887
+ );
2888
+ var defer = should_defer_append();
2889
+ if (fn && !__privateGet(this, _onscreen).has(key) && !__privateGet(this, _offscreen).has(key)) {
2890
+ if (defer) {
2891
+ var fragment = document.createDocumentFragment();
2892
+ var target = create_text();
2893
+ fragment.append(target);
2894
+ __privateGet(this, _offscreen).set(key, {
2895
+ effect: branch(() => fn(target)),
2896
+ fragment
2897
+ });
2898
+ } else {
2899
+ __privateGet(this, _onscreen).set(
2900
+ key,
2901
+ branch(() => fn(this.anchor))
2902
+ );
2903
+ }
2904
+ }
2905
+ __privateGet(this, _batches).set(batch, key);
2906
+ if (defer) {
2907
+ for (const [k, effect2] of __privateGet(this, _onscreen)) {
2908
+ if (k === key) {
2909
+ batch.skipped_effects.delete(effect2);
2910
+ } else {
2911
+ batch.skipped_effects.add(effect2);
2912
+ }
2913
+ }
2914
+ for (const [k, branch2] of __privateGet(this, _offscreen)) {
2915
+ if (k === key) {
2916
+ batch.skipped_effects.delete(branch2.effect);
2917
+ } else {
2918
+ batch.skipped_effects.add(branch2.effect);
2919
+ }
2920
+ }
2921
+ batch.oncommit(__privateGet(this, _commit));
2922
+ batch.ondiscard(__privateGet(this, _discard));
2923
+ } else {
2924
+ __privateGet(this, _commit).call(this);
2925
+ }
2926
+ }
2927
+ }
2928
+ _batches = new WeakMap();
2929
+ _onscreen = new WeakMap();
2930
+ _offscreen = new WeakMap();
2931
+ _outroing = new WeakMap();
2932
+ _transition = new WeakMap();
2933
+ _commit = new WeakMap();
2934
+ _discard = new WeakMap();
2935
+ function if_block(node, fn, elseif = false) {
2936
+ var branches = new BranchManager(node);
2937
+ var flags2 = elseif ? EFFECT_TRANSPARENT : 0;
2938
+ function update_branch(condition, fn2) {
2939
+ branches.ensure(condition, fn2);
2940
+ }
2941
+ block(() => {
2942
+ var has_branch = false;
2943
+ fn((fn2, flag = true) => {
2944
+ has_branch = true;
2945
+ update_branch(flag, fn2);
2946
+ });
2947
+ if (!has_branch) {
2948
+ update_branch(false, null);
2949
+ }
2950
+ }, flags2);
2951
+ }
2952
+ function pause_effects(state2, to_destroy, controlled_anchor) {
2953
+ var transitions = [];
2954
+ var length = to_destroy.length;
2955
+ var group;
2956
+ var remaining = to_destroy.length;
2957
+ for (var i = 0; i < length; i++) {
2958
+ let effect2 = to_destroy[i];
2959
+ pause_effect(
2960
+ effect2,
2961
+ () => {
2962
+ if (group) {
2963
+ group.pending.delete(effect2);
2964
+ group.done.add(effect2);
2965
+ if (group.pending.size === 0) {
2966
+ var groups = (
2967
+ /** @type {Set<EachOutroGroup>} */
2968
+ state2.outrogroups
2969
+ );
2970
+ destroy_effects(array_from(group.done));
2971
+ groups.delete(group);
2972
+ if (groups.size === 0) {
2973
+ state2.outrogroups = null;
2974
+ }
2975
+ }
2976
+ } else {
2977
+ remaining -= 1;
2978
+ }
2979
+ },
2980
+ false
2981
+ );
2982
+ }
2983
+ if (remaining === 0) {
2984
+ var fast_path = transitions.length === 0 && controlled_anchor !== null;
2985
+ if (fast_path) {
2986
+ var anchor = (
2987
+ /** @type {Element} */
2988
+ controlled_anchor
2989
+ );
2990
+ var parent_node = (
2991
+ /** @type {Element} */
2992
+ anchor.parentNode
2993
+ );
2994
+ clear_text_content(parent_node);
2995
+ parent_node.append(anchor);
2996
+ state2.items.clear();
2997
+ }
2998
+ destroy_effects(to_destroy, !fast_path);
2999
+ } else {
3000
+ group = {
3001
+ pending: new Set(to_destroy),
3002
+ done: /* @__PURE__ */ new Set()
3003
+ };
3004
+ (state2.outrogroups ?? (state2.outrogroups = /* @__PURE__ */ new Set())).add(group);
3005
+ }
3006
+ }
3007
+ function destroy_effects(to_destroy, remove_dom = true) {
3008
+ for (var i = 0; i < to_destroy.length; i++) {
3009
+ destroy_effect(to_destroy[i], remove_dom);
3010
+ }
3011
+ }
3012
+ var offscreen_anchor;
3013
+ function each(node, flags2, get_collection, get_key, render_fn, fallback_fn = null) {
3014
+ var anchor = node;
3015
+ var items = /* @__PURE__ */ new Map();
3016
+ {
3017
+ var parent_node = (
3018
+ /** @type {Element} */
3019
+ node
3020
+ );
3021
+ anchor = parent_node.appendChild(create_text());
3022
+ }
3023
+ var fallback = null;
3024
+ var each_array = /* @__PURE__ */ derived_safe_equal(() => {
3025
+ var collection = get_collection();
3026
+ return is_array(collection) ? collection : collection == null ? [] : array_from(collection);
3027
+ });
3028
+ var array;
3029
+ var first_run = true;
3030
+ function commit() {
3031
+ state2.fallback = fallback;
3032
+ reconcile(state2, array, anchor, flags2, get_key);
3033
+ if (fallback !== null) {
3034
+ if (array.length === 0) {
3035
+ if ((fallback.f & EFFECT_OFFSCREEN) === 0) {
3036
+ resume_effect(fallback);
3037
+ } else {
3038
+ fallback.f ^= EFFECT_OFFSCREEN;
3039
+ move(fallback, null, anchor);
3040
+ }
3041
+ } else {
3042
+ pause_effect(fallback, () => {
3043
+ fallback = null;
3044
+ });
3045
+ }
3046
+ }
3047
+ }
3048
+ var effect2 = block(() => {
3049
+ array = /** @type {V[]} */
3050
+ get(each_array);
3051
+ var length = array.length;
3052
+ var keys = /* @__PURE__ */ new Set();
3053
+ var batch = (
3054
+ /** @type {Batch} */
3055
+ current_batch
3056
+ );
3057
+ var defer = should_defer_append();
3058
+ for (var index = 0; index < length; index += 1) {
3059
+ var value = array[index];
3060
+ var key = get_key(value, index);
3061
+ var item = first_run ? null : items.get(key);
3062
+ if (item) {
3063
+ if (item.v) internal_set(item.v, value);
3064
+ if (item.i) internal_set(item.i, index);
3065
+ if (defer) {
3066
+ batch.skipped_effects.delete(item.e);
3067
+ }
3068
+ } else {
3069
+ item = create_item(
3070
+ items,
3071
+ first_run ? anchor : offscreen_anchor ?? (offscreen_anchor = create_text()),
3072
+ value,
3073
+ key,
3074
+ index,
3075
+ render_fn,
3076
+ flags2,
3077
+ get_collection
3078
+ );
3079
+ if (!first_run) {
3080
+ item.e.f |= EFFECT_OFFSCREEN;
3081
+ }
3082
+ items.set(key, item);
3083
+ }
3084
+ keys.add(key);
3085
+ }
3086
+ if (length === 0 && fallback_fn && !fallback) {
3087
+ if (first_run) {
3088
+ fallback = branch(() => fallback_fn(anchor));
3089
+ } else {
3090
+ fallback = branch(() => fallback_fn(offscreen_anchor ?? (offscreen_anchor = create_text())));
3091
+ fallback.f |= EFFECT_OFFSCREEN;
3092
+ }
3093
+ }
3094
+ if (!first_run) {
3095
+ if (defer) {
3096
+ for (const [key2, item2] of items) {
3097
+ if (!keys.has(key2)) {
3098
+ batch.skipped_effects.add(item2.e);
3099
+ }
3100
+ }
3101
+ batch.oncommit(commit);
3102
+ batch.ondiscard(() => {
3103
+ });
3104
+ } else {
3105
+ commit();
3106
+ }
3107
+ }
3108
+ get(each_array);
3109
+ });
3110
+ var state2 = { effect: effect2, items, outrogroups: null, fallback };
3111
+ first_run = false;
3112
+ }
3113
+ function reconcile(state2, array, anchor, flags2, get_key) {
3114
+ var _a2;
3115
+ var length = array.length;
3116
+ var items = state2.items;
3117
+ var current = state2.effect.first;
3118
+ var seen;
3119
+ var prev = null;
3120
+ var matched = [];
3121
+ var stashed = [];
3122
+ var value;
3123
+ var key;
3124
+ var effect2;
3125
+ var i;
3126
+ for (i = 0; i < length; i += 1) {
3127
+ value = array[i];
3128
+ key = get_key(value, i);
3129
+ effect2 = /** @type {EachItem} */
3130
+ items.get(key).e;
3131
+ if (state2.outrogroups !== null) {
3132
+ for (const group of state2.outrogroups) {
3133
+ group.pending.delete(effect2);
3134
+ group.done.delete(effect2);
3135
+ }
3136
+ }
3137
+ if ((effect2.f & EFFECT_OFFSCREEN) !== 0) {
3138
+ effect2.f ^= EFFECT_OFFSCREEN;
3139
+ if (effect2 === current) {
3140
+ move(effect2, null, anchor);
3141
+ } else {
3142
+ var next = prev ? prev.next : current;
3143
+ if (effect2 === state2.effect.last) {
3144
+ state2.effect.last = effect2.prev;
3145
+ }
3146
+ if (effect2.prev) effect2.prev.next = effect2.next;
3147
+ if (effect2.next) effect2.next.prev = effect2.prev;
3148
+ link(state2, prev, effect2);
3149
+ link(state2, effect2, next);
3150
+ move(effect2, next, anchor);
3151
+ prev = effect2;
3152
+ matched = [];
3153
+ stashed = [];
3154
+ current = prev.next;
3155
+ continue;
3156
+ }
3157
+ }
3158
+ if ((effect2.f & INERT) !== 0) {
3159
+ resume_effect(effect2);
3160
+ }
3161
+ if (effect2 !== current) {
3162
+ if (seen !== void 0 && seen.has(effect2)) {
3163
+ if (matched.length < stashed.length) {
3164
+ var start = stashed[0];
3165
+ var j;
3166
+ prev = start.prev;
3167
+ var a = matched[0];
3168
+ var b = matched[matched.length - 1];
3169
+ for (j = 0; j < matched.length; j += 1) {
3170
+ move(matched[j], start, anchor);
3171
+ }
3172
+ for (j = 0; j < stashed.length; j += 1) {
3173
+ seen.delete(stashed[j]);
3174
+ }
3175
+ link(state2, a.prev, b.next);
3176
+ link(state2, prev, a);
3177
+ link(state2, b, start);
3178
+ current = start;
3179
+ prev = b;
3180
+ i -= 1;
3181
+ matched = [];
3182
+ stashed = [];
3183
+ } else {
3184
+ seen.delete(effect2);
3185
+ move(effect2, current, anchor);
3186
+ link(state2, effect2.prev, effect2.next);
3187
+ link(state2, effect2, prev === null ? state2.effect.first : prev.next);
3188
+ link(state2, prev, effect2);
3189
+ prev = effect2;
3190
+ }
3191
+ continue;
3192
+ }
3193
+ matched = [];
3194
+ stashed = [];
3195
+ while (current !== null && current !== effect2) {
3196
+ (seen ?? (seen = /* @__PURE__ */ new Set())).add(current);
3197
+ stashed.push(current);
3198
+ current = current.next;
3199
+ }
3200
+ if (current === null) {
3201
+ continue;
3202
+ }
3203
+ }
3204
+ if ((effect2.f & EFFECT_OFFSCREEN) === 0) {
3205
+ matched.push(effect2);
3206
+ }
3207
+ prev = effect2;
3208
+ current = effect2.next;
3209
+ }
3210
+ if (state2.outrogroups !== null) {
3211
+ for (const group of state2.outrogroups) {
3212
+ if (group.pending.size === 0) {
3213
+ destroy_effects(array_from(group.done));
3214
+ (_a2 = state2.outrogroups) == null ? void 0 : _a2.delete(group);
3215
+ }
3216
+ }
3217
+ if (state2.outrogroups.size === 0) {
3218
+ state2.outrogroups = null;
3219
+ }
3220
+ }
3221
+ if (current !== null || seen !== void 0) {
3222
+ var to_destroy = [];
3223
+ if (seen !== void 0) {
3224
+ for (effect2 of seen) {
3225
+ if ((effect2.f & INERT) === 0) {
3226
+ to_destroy.push(effect2);
3227
+ }
3228
+ }
3229
+ }
3230
+ while (current !== null) {
3231
+ if ((current.f & INERT) === 0 && current !== state2.fallback) {
3232
+ to_destroy.push(current);
3233
+ }
3234
+ current = current.next;
3235
+ }
3236
+ var destroy_length = to_destroy.length;
3237
+ if (destroy_length > 0) {
3238
+ var controlled_anchor = length === 0 ? anchor : null;
3239
+ pause_effects(state2, to_destroy, controlled_anchor);
3240
+ }
3241
+ }
3242
+ }
3243
+ function create_item(items, anchor, value, key, index, render_fn, flags2, get_collection) {
3244
+ var v = (flags2 & EACH_ITEM_REACTIVE) !== 0 ? (flags2 & EACH_ITEM_IMMUTABLE) === 0 ? /* @__PURE__ */ mutable_source(value, false, false) : source(value) : null;
3245
+ var i = (flags2 & EACH_INDEX_REACTIVE) !== 0 ? source(index) : null;
3246
+ return {
3247
+ v,
3248
+ i,
3249
+ e: branch(() => {
3250
+ render_fn(anchor, v ?? value, i ?? index, get_collection);
3251
+ return () => {
3252
+ items.delete(key);
3253
+ };
3254
+ })
3255
+ };
3256
+ }
3257
+ function move(effect2, next, anchor) {
3258
+ if (!effect2.nodes) return;
3259
+ var node = effect2.nodes.start;
3260
+ var end = effect2.nodes.end;
3261
+ var dest = next && (next.f & EFFECT_OFFSCREEN) === 0 ? (
3262
+ /** @type {EffectNodes} */
3263
+ next.nodes.start
3264
+ ) : anchor;
3265
+ while (node !== null) {
3266
+ var next_node = (
3267
+ /** @type {TemplateNode} */
3268
+ /* @__PURE__ */ get_next_sibling(node)
3269
+ );
3270
+ dest.before(node);
3271
+ if (node === end) {
3272
+ return;
3273
+ }
3274
+ node = next_node;
3275
+ }
3276
+ }
3277
+ function link(state2, prev, next) {
3278
+ if (prev === null) {
3279
+ state2.effect.first = next;
3280
+ } else {
3281
+ prev.next = next;
3282
+ }
3283
+ if (next === null) {
3284
+ state2.effect.last = prev;
3285
+ } else {
3286
+ next.prev = prev;
3287
+ }
3288
+ }
3289
+ function append_styles(anchor, css) {
3290
+ effect(() => {
3291
+ var root2 = anchor.getRootNode();
3292
+ var target = (
3293
+ /** @type {ShadowRoot} */
3294
+ root2.host ? (
3295
+ /** @type {ShadowRoot} */
3296
+ root2
3297
+ ) : (
3298
+ /** @type {Document} */
3299
+ root2.head ?? /** @type {Document} */
3300
+ root2.ownerDocument.head
3301
+ )
3302
+ );
3303
+ if (!target.querySelector("#" + css.hash)) {
3304
+ const style = document.createElement("style");
3305
+ style.id = css.hash;
3306
+ style.textContent = css.code;
3307
+ target.appendChild(style);
3308
+ }
3309
+ });
3310
+ }
3311
+ const whitespace = [..." \n\r\f \v\uFEFF"];
3312
+ function to_class(value, hash, directives) {
3313
+ var classname = value == null ? "" : "" + value;
3314
+ if (directives) {
3315
+ for (var key in directives) {
3316
+ if (directives[key]) {
3317
+ classname = classname ? classname + " " + key : key;
3318
+ } else if (classname.length) {
3319
+ var len = key.length;
3320
+ var a = 0;
3321
+ while ((a = classname.indexOf(key, a)) >= 0) {
3322
+ var b = a + len;
3323
+ if ((a === 0 || whitespace.includes(classname[a - 1])) && (b === classname.length || whitespace.includes(classname[b]))) {
3324
+ classname = (a === 0 ? "" : classname.substring(0, a)) + classname.substring(b + 1);
3325
+ } else {
3326
+ a = b;
3327
+ }
3328
+ }
3329
+ }
3330
+ }
3331
+ }
3332
+ return classname === "" ? null : classname;
3333
+ }
3334
+ function to_style(value, styles) {
3335
+ return value == null ? null : String(value);
3336
+ }
3337
+ function set_class(dom, is_html, value, hash, prev_classes, next_classes) {
3338
+ var prev = dom.__className;
3339
+ if (prev !== value || prev === void 0) {
3340
+ var next_class_name = to_class(value, hash, next_classes);
3341
+ {
3342
+ if (next_class_name == null) {
3343
+ dom.removeAttribute("class");
3344
+ } else {
3345
+ dom.className = next_class_name;
3346
+ }
3347
+ }
3348
+ dom.__className = value;
3349
+ } else if (next_classes && prev_classes !== next_classes) {
3350
+ for (var key in next_classes) {
3351
+ var is_present = !!next_classes[key];
3352
+ if (prev_classes == null || is_present !== !!prev_classes[key]) {
3353
+ dom.classList.toggle(key, is_present);
3354
+ }
3355
+ }
3356
+ }
3357
+ return next_classes;
3358
+ }
3359
+ function set_style(dom, value, prev_styles, next_styles) {
3360
+ var prev = dom.__style;
3361
+ if (prev !== value) {
3362
+ var next_style_attr = to_style(value);
3363
+ {
3364
+ if (next_style_attr == null) {
3365
+ dom.removeAttribute("style");
3366
+ } else {
3367
+ dom.style.cssText = next_style_attr;
3368
+ }
3369
+ }
3370
+ dom.__style = value;
3371
+ }
3372
+ return next_styles;
3373
+ }
3374
+ function bind_value(input, get2, set2 = get2) {
3375
+ var batches2 = /* @__PURE__ */ new WeakSet();
3376
+ listen_to_event_and_reset_event(input, "input", async (is_reset) => {
3377
+ var value = is_reset ? input.defaultValue : input.value;
3378
+ value = is_numberlike_input(input) ? to_number(value) : value;
3379
+ set2(value);
3380
+ if (current_batch !== null) {
3381
+ batches2.add(current_batch);
3382
+ }
3383
+ await tick();
3384
+ if (value !== (value = get2())) {
3385
+ var start = input.selectionStart;
3386
+ var end = input.selectionEnd;
3387
+ var length = input.value.length;
3388
+ input.value = value ?? "";
3389
+ if (end !== null) {
3390
+ var new_length = input.value.length;
3391
+ if (start === end && end === length && new_length > length) {
3392
+ input.selectionStart = new_length;
3393
+ input.selectionEnd = new_length;
3394
+ } else {
3395
+ input.selectionStart = start;
3396
+ input.selectionEnd = Math.min(end, new_length);
3397
+ }
3398
+ }
3399
+ }
3400
+ });
3401
+ if (
3402
+ // If we are hydrating and the value has since changed,
3403
+ // then use the updated value from the input instead.
3404
+ // If defaultValue is set, then value == defaultValue
3405
+ // TODO Svelte 6: remove input.value check and set to empty string?
3406
+ untrack(get2) == null && input.value
3407
+ ) {
3408
+ set2(is_numberlike_input(input) ? to_number(input.value) : input.value);
3409
+ if (current_batch !== null) {
3410
+ batches2.add(current_batch);
3411
+ }
3412
+ }
3413
+ render_effect(() => {
3414
+ var value = get2();
3415
+ if (input === document.activeElement) {
3416
+ var batch = (
3417
+ /** @type {Batch} */
3418
+ previous_batch ?? current_batch
3419
+ );
3420
+ if (batches2.has(batch)) {
3421
+ return;
3422
+ }
3423
+ }
3424
+ if (is_numberlike_input(input) && value === to_number(input.value)) {
3425
+ return;
3426
+ }
3427
+ if (input.type === "date" && !value && !input.value) {
3428
+ return;
3429
+ }
3430
+ if (value !== input.value) {
3431
+ input.value = value ?? "";
3432
+ }
3433
+ });
3434
+ }
3435
+ function is_numberlike_input(input) {
3436
+ var type = input.type;
3437
+ return type === "number" || type === "range";
3438
+ }
3439
+ function to_number(value) {
3440
+ return value === "" ? null : +value;
3441
+ }
3442
+ function is_bound_this(bound_value, element_or_component) {
3443
+ return bound_value === element_or_component || (bound_value == null ? void 0 : bound_value[STATE_SYMBOL]) === element_or_component;
3444
+ }
3445
+ function bind_this(element_or_component = {}, update, get_value, get_parts) {
3446
+ effect(() => {
3447
+ var old_parts;
3448
+ var parts;
3449
+ render_effect(() => {
3450
+ old_parts = parts;
3451
+ parts = [];
3452
+ untrack(() => {
3453
+ if (element_or_component !== get_value(...parts)) {
3454
+ update(element_or_component, ...parts);
3455
+ if (old_parts && is_bound_this(get_value(...old_parts), element_or_component)) {
3456
+ update(null, ...old_parts);
3457
+ }
3458
+ }
3459
+ });
3460
+ });
3461
+ return () => {
3462
+ queue_micro_task(() => {
3463
+ if (parts && is_bound_this(get_value(...parts), element_or_component)) {
3464
+ update(null, ...parts);
3465
+ }
3466
+ });
3467
+ };
3468
+ });
3469
+ return element_or_component;
3470
+ }
3471
+ const PUBLIC_VERSION = "5";
3472
+ if (typeof window !== "undefined") {
3473
+ ((_a = window.__svelte ?? (window.__svelte = {})).v ?? (_a.v = /* @__PURE__ */ new Set())).add(PUBLIC_VERSION);
3474
+ }
3475
+ function deepElementFromPoint(x, y) {
3476
+ let element = document.elementFromPoint(x, y);
3477
+ if (!element) return null;
3478
+ while (element == null ? void 0 : element.shadowRoot) {
3479
+ const inner = element.shadowRoot.elementFromPoint(x, y);
3480
+ if (!inner || inner === element) break;
3481
+ element = inner;
3482
+ }
3483
+ return element;
3484
+ }
3485
+ function getSelector(element) {
3486
+ const elementRoot = element.getRootNode();
3487
+ if (element.id && !element.id.startsWith("heroshot") && !(elementRoot instanceof ShadowRoot)) {
3488
+ return `#${element.id}`;
3489
+ }
3490
+ const path = [];
3491
+ let current = element;
3492
+ for (let depth = 0; (current == null ? void 0 : current.nodeType) === Node.ELEMENT_NODE && depth < 20; depth++) {
3493
+ const root2 = current.getRootNode();
3494
+ const isInShadow = root2 instanceof ShadowRoot;
3495
+ const parent = current.parentElement;
3496
+ let selector = current.tagName.toLowerCase();
3497
+ if (current.id && !current.id.startsWith("heroshot")) {
3498
+ selector = `#${current.id}`;
3499
+ if (!isInShadow) {
3500
+ path.unshift(selector);
3501
+ break;
3502
+ }
3503
+ } else {
3504
+ if (current.className && typeof current.className === "string") {
3505
+ const classes = current.className.trim().split(/\s+/).filter((cls) => cls && !cls.startsWith("heroshot"));
3506
+ if (classes.length > 0) {
3507
+ selector += "." + classes.slice(0, 2).join(".");
3508
+ }
3509
+ }
3510
+ }
3511
+ const siblingContainer = parent ?? (root2 instanceof ShadowRoot ? root2 : null);
3512
+ if (siblingContainer) {
3513
+ const currentTagName = current.tagName;
3514
+ const siblings = [...siblingContainer.children].filter(
3515
+ (child2) => child2.tagName === currentTagName
3516
+ );
3517
+ if (siblings.length > 1) {
3518
+ const index = siblings.indexOf(current) + 1;
3519
+ selector += `:nth-of-type(${index})`;
3520
+ }
3521
+ }
3522
+ path.unshift(selector);
3523
+ if (parent) {
3524
+ current = parent;
3525
+ } else if (root2 instanceof ShadowRoot) {
3526
+ path.unshift(">>>");
3527
+ current = root2.host;
3528
+ } else {
3529
+ current = null;
3530
+ }
3531
+ }
3532
+ return path.join(" > ").replaceAll("> >>> >", " >>> ");
3533
+ }
3534
+ var root_1$1 = /* @__PURE__ */ from_html(`<p class="empty svelte-1tkp9dc">No screenshots added yet. Click the crosshair to pick an element.</p>`);
3535
+ var root_3$1 = /* @__PURE__ */ from_html(`<li class="list-item svelte-1tkp9dc"><button class="item-info svelte-1tkp9dc" title="Navigate to this element"><span class="item-name svelte-1tkp9dc"> </span> <span class="item-selector svelte-1tkp9dc"> </span></button> <button class="remove-btn svelte-1tkp9dc" title="Remove screenshot"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg></button></li>`);
3536
+ var root_2$1 = /* @__PURE__ */ from_html(`<ul class="list svelte-1tkp9dc"></ul>`);
3537
+ var root$1 = /* @__PURE__ */ from_html(`<div class="backdrop svelte-1tkp9dc" role="presentation"><div class="dialog svelte-1tkp9dc" role="dialog" aria-modal="true" aria-labelledby="dialog-title" tabindex="0"><div class="header svelte-1tkp9dc"><h3 id="dialog-title" class="svelte-1tkp9dc"> </h3> <button class="close-btn svelte-1tkp9dc" title="Close"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg></button></div> <div class="content svelte-1tkp9dc"><!></div></div></div>`);
3538
+ const $$css$2 = {
3539
+ hash: "svelte-1tkp9dc",
3540
+ code: ".backdrop.svelte-1tkp9dc {position:fixed;inset:0;background:rgba(0, 0, 0, 0.6);display:flex;align-items:center;justify-content:center;z-index:2147483647;}.dialog.svelte-1tkp9dc {background:#1a1a2e;border-radius:12px;min-width:500px;max-width:90vw;max-height:80vh;box-shadow:0 8px 32px rgba(0, 0, 0, 0.4);font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;color:#fff;display:flex;flex-direction:column;}.header.svelte-1tkp9dc {display:flex;align-items:center;justify-content:space-between;padding:20px 24px;border-bottom:1px solid #2d2d44;}h3.svelte-1tkp9dc {margin:0;font-size:18px;font-weight:600;}.close-btn.svelte-1tkp9dc {width:32px;height:32px;border:none;border-radius:6px;background:transparent;color:#aaa;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all 0.2s;}.close-btn.svelte-1tkp9dc:hover {background:#2d2d44;color:#fff;}.content.svelte-1tkp9dc {padding:16px 24px 24px;overflow-y:auto;flex:1;}.empty.svelte-1tkp9dc {color:#666;text-align:center;padding:32px 0;margin:0;}.list.svelte-1tkp9dc {list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:8px;}.list-item.svelte-1tkp9dc {display:flex;align-items:center;gap:12px;padding:12px 16px;background:#2d2d44;border-radius:8px;transition:background 0.2s;}.list-item.svelte-1tkp9dc:hover {background:#3d3d5c;}.item-info.svelte-1tkp9dc {flex:1;min-width:0;display:flex;flex-direction:column;align-items:flex-start;gap:4px;background:transparent;border:none;padding:0;cursor:pointer;text-align:left;}.item-info.svelte-1tkp9dc:hover .item-name:where(.svelte-1tkp9dc) {color:#3b82f6;}.item-name.svelte-1tkp9dc {font-weight:600;color:#fff;}.item-selector.svelte-1tkp9dc {font-family:monospace;font-size:12px;color:#888;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}.remove-btn.svelte-1tkp9dc {width:32px;height:32px;border:none;border-radius:6px;background:transparent;color:#666;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all 0.2s;flex-shrink:0;}.remove-btn.svelte-1tkp9dc:hover {background:#ef4444;color:#fff;}"
3541
+ };
3542
+ function ListDialog($$anchor, $$props) {
3543
+ push($$props, true);
3544
+ append_styles($$anchor, $$css$2);
3545
+ function stopKeyboardEvent(event2) {
3546
+ event2.stopPropagation();
3547
+ if (event2.key === "Escape") {
3548
+ $$props.onClose();
3549
+ }
3550
+ }
3551
+ var div = root$1();
3552
+ div.__click = function(...$$args) {
3553
+ var _a2;
3554
+ (_a2 = $$props.onClose) == null ? void 0 : _a2.apply(this, $$args);
3555
+ };
3556
+ div.__keydown = stopKeyboardEvent;
3557
+ div.__keyup = (event2) => event2.stopPropagation();
3558
+ var div_1 = child(div);
3559
+ div_1.__click = (event2) => event2.stopPropagation();
3560
+ div_1.__keydown = stopKeyboardEvent;
3561
+ div_1.__keyup = (event2) => event2.stopPropagation();
3562
+ var div_2 = child(div_1);
3563
+ var h3 = child(div_2);
3564
+ var text = child(h3);
3565
+ var button = sibling(h3, 2);
3566
+ button.__click = function(...$$args) {
3567
+ var _a2;
3568
+ (_a2 = $$props.onClose) == null ? void 0 : _a2.apply(this, $$args);
3569
+ };
3570
+ var div_3 = sibling(div_2, 2);
3571
+ var node = child(div_3);
3572
+ {
3573
+ var consequent = ($$anchor2) => {
3574
+ var p = root_1$1();
3575
+ append($$anchor2, p);
3576
+ };
3577
+ var alternate = ($$anchor2) => {
3578
+ var ul = root_2$1();
3579
+ each(ul, 21, () => $$props.screenshots, (screenshot) => screenshot.id, ($$anchor3, screenshot) => {
3580
+ var li = root_3$1();
3581
+ var button_1 = child(li);
3582
+ button_1.__click = () => $$props.onSelect(get(screenshot));
3583
+ var span = child(button_1);
3584
+ var text_1 = child(span);
3585
+ var span_1 = sibling(span, 2);
3586
+ var text_2 = child(span_1);
3587
+ var button_2 = sibling(button_1, 2);
3588
+ button_2.__click = () => $$props.onRemove(get(screenshot).id);
3589
+ template_effect(() => {
3590
+ set_text(text_1, get(screenshot).name);
3591
+ set_text(text_2, get(screenshot).selector);
3592
+ });
3593
+ append($$anchor3, li);
3594
+ });
3595
+ append($$anchor2, ul);
3596
+ };
3597
+ if_block(node, ($$render) => {
3598
+ if ($$props.screenshots.length === 0) $$render(consequent);
3599
+ else $$render(alternate, false);
3600
+ });
3601
+ }
3602
+ template_effect(() => set_text(text, `Screenshots (${$$props.screenshots.length ?? ""})`));
3603
+ event("keypress", div, (event2) => event2.stopPropagation());
3604
+ event("keypress", div_1, (event2) => event2.stopPropagation());
3605
+ append($$anchor, div);
3606
+ pop();
3607
+ }
3608
+ delegate(["click", "keydown", "keyup"]);
3609
+ var root = /* @__PURE__ */ from_html(`<div class="backdrop svelte-1eaujs8" role="presentation"><div class="modal svelte-1eaujs8" role="dialog" aria-modal="true" aria-labelledby="modal-title" tabindex="0"><h3 id="modal-title" class="svelte-1eaujs8">Name this screenshot</h3> <p class="selector-preview svelte-1eaujs8"> </p> <form><input type="text" placeholder="e.g., hero-section, login-button" class="input svelte-1eaujs8"/> <div class="actions svelte-1eaujs8"><button type="button" class="btn-secondary svelte-1eaujs8">Cancel</button> <button type="submit" class="btn-primary svelte-1eaujs8">Save</button></div></form></div></div>`);
3610
+ const $$css$1 = {
3611
+ hash: "svelte-1eaujs8",
3612
+ code: ".backdrop.svelte-1eaujs8 {position:fixed;inset:0;background:rgba(0, 0, 0, 0.6);display:flex;align-items:center;justify-content:center;z-index:2147483647;}.modal.svelte-1eaujs8 {background:#1a1a2e;border-radius:12px;padding:24px;min-width:400px;max-width:90vw;box-shadow:0 8px 32px rgba(0, 0, 0, 0.4);font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;color:#fff;}h3.svelte-1eaujs8 {margin:0 0 12px;font-size:18px;font-weight:600;}.selector-preview.svelte-1eaujs8 {margin:0 0 20px;padding:8px 12px;background:#2d2d44;border-radius:6px;font-family:monospace;font-size:12px;color:#aaa;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}.input.svelte-1eaujs8 {width:100%;padding:12px;border:2px solid #3d3d5c;border-radius:6px;background:#2d2d44;color:#fff;font-size:14px;outline:none;box-sizing:border-box;transition:border-color 0.2s;}.input.svelte-1eaujs8:focus {border-color:#3b82f6;}.input.svelte-1eaujs8::placeholder {color:#666;}.actions.svelte-1eaujs8 {display:flex;gap:12px;justify-content:flex-end;margin-top:20px;}.btn-primary.svelte-1eaujs8,\n .btn-secondary.svelte-1eaujs8 {padding:10px 20px;border:none;border-radius:6px;font-size:14px;font-weight:600;cursor:pointer;transition:all 0.2s;}.btn-primary.svelte-1eaujs8 {background:#22c55e;color:#fff;}.btn-primary.svelte-1eaujs8:hover:not(:disabled) {background:#16a34a;}.btn-primary.svelte-1eaujs8:disabled {background:#3d3d5c;color:#666;cursor:not-allowed;}.btn-secondary.svelte-1eaujs8 {background:#3d3d5c;color:#fff;}.btn-secondary.svelte-1eaujs8:hover {background:#4d4d6c;}"
3613
+ };
3614
+ function NameModal($$anchor, $$props) {
3615
+ push($$props, true);
3616
+ append_styles($$anchor, $$css$1);
3617
+ let name = /* @__PURE__ */ state("");
3618
+ let inputElement = /* @__PURE__ */ state(null);
3619
+ user_effect(() => {
3620
+ if (get(inputElement)) {
3621
+ get(inputElement).focus();
3622
+ }
3623
+ });
3624
+ function handleSubmit(event2) {
3625
+ event2.preventDefault();
3626
+ const trimmedName = get(name).trim();
3627
+ if (trimmedName) {
3628
+ $$props.onSave(trimmedName);
3629
+ }
3630
+ }
3631
+ function stopKeyboardEvent(event2) {
3632
+ event2.stopPropagation();
3633
+ if (event2.key === "Escape") {
3634
+ $$props.onCancel();
3635
+ }
3636
+ }
3637
+ var div = root();
3638
+ div.__click = function(...$$args) {
3639
+ var _a2;
3640
+ (_a2 = $$props.onCancel) == null ? void 0 : _a2.apply(this, $$args);
3641
+ };
3642
+ div.__keydown = stopKeyboardEvent;
3643
+ div.__keyup = (event2) => event2.stopPropagation();
3644
+ var div_1 = child(div);
3645
+ div_1.__click = (event2) => event2.stopPropagation();
3646
+ div_1.__keydown = stopKeyboardEvent;
3647
+ div_1.__keyup = (event2) => event2.stopPropagation();
3648
+ var p = sibling(child(div_1), 2);
3649
+ var text = child(p);
3650
+ var form = sibling(p, 2);
3651
+ var input = child(form);
3652
+ bind_this(input, ($$value) => set(inputElement, $$value), () => get(inputElement));
3653
+ var div_2 = sibling(input, 2);
3654
+ var button = child(div_2);
3655
+ button.__click = function(...$$args) {
3656
+ var _a2;
3657
+ (_a2 = $$props.onCancel) == null ? void 0 : _a2.apply(this, $$args);
3658
+ };
3659
+ var button_1 = sibling(button, 2);
3660
+ template_effect(
3661
+ ($0) => {
3662
+ set_text(text, $$props.selector);
3663
+ button_1.disabled = $0;
3664
+ },
3665
+ [() => !get(name).trim()]
3666
+ );
3667
+ event("keypress", div, (event2) => event2.stopPropagation());
3668
+ event("keypress", div_1, (event2) => event2.stopPropagation());
3669
+ event("submit", form, handleSubmit);
3670
+ bind_value(input, () => get(name), ($$value) => set(name, $$value));
3671
+ append($$anchor, div);
3672
+ pop();
3673
+ }
3674
+ delegate(["click", "keydown", "keyup"]);
3675
+ var root_2 = /* @__PURE__ */ from_html(`<span class="badge svelte-1xm8gof"> </span>`);
3676
+ var root_3 = /* @__PURE__ */ from_html(`<div class="overlay svelte-1xm8gof"><div class="overlay-dark svelte-1xm8gof"></div> <div class="overlay-dark svelte-1xm8gof"></div> <div class="overlay-dark svelte-1xm8gof"></div> <div class="overlay-dark svelte-1xm8gof"></div> <div class="highlight svelte-1xm8gof"></div></div>`);
3677
+ var root_1 = /* @__PURE__ */ from_html(`<div class="toolbar svelte-1xm8gof"><button title="Pick element"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="svelte-1xm8gof"><circle cx="12" cy="12" r="10" class="svelte-1xm8gof"></circle><circle cx="12" cy="12" r="3" class="svelte-1xm8gof"></circle><line x1="12" y1="2" x2="12" y2="6" class="svelte-1xm8gof"></line><line x1="12" y1="18" x2="12" y2="22" class="svelte-1xm8gof"></line><line x1="2" y1="12" x2="6" y2="12" class="svelte-1xm8gof"></line><line x1="18" y1="12" x2="22" y2="12" class="svelte-1xm8gof"></line></svg></button> <span class="status svelte-1xm8gof"> </span> <button title="View screenshots"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="svelte-1xm8gof"><line x1="8" y1="6" x2="21" y2="6" class="svelte-1xm8gof"></line><line x1="8" y1="12" x2="21" y2="12" class="svelte-1xm8gof"></line><line x1="8" y1="18" x2="21" y2="18" class="svelte-1xm8gof"></line><line x1="3" y1="6" x2="3.01" y2="6" class="svelte-1xm8gof"></line><line x1="3" y1="12" x2="3.01" y2="12" class="svelte-1xm8gof"></line><line x1="3" y1="18" x2="3.01" y2="18" class="svelte-1xm8gof"></line></svg> <!></button> <button class="done-btn svelte-1xm8gof" title="Done - save and close">Done</button></div> <!> <!> <!>`, 1);
3678
+ const $$css = {
3679
+ hash: "svelte-1xm8gof",
3680
+ code: "\n /*\n * Styles are encapsulated via Shadow DOM (see main.ts).\n * No !important needed - host page CSS cannot leak in.\n */.toolbar.svelte-1xm8gof {position:fixed;bottom:20px;left:50%;transform:translateX(-50%);z-index:2147483647;background:#1a1a2e;border-radius:8px;padding:8px 16px;display:flex;align-items:center;gap:12px;font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;font-size:13px;color:#fff;box-shadow:0 4px 20px rgba(0, 0, 0, 0.3);user-select:none;}.picker-btn.svelte-1xm8gof,\n .list-btn.svelte-1xm8gof {width:36px;height:36px;border:2px solid transparent;border-radius:6px;background:#2d2d44;color:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all 0.2s;position:relative;}.picker-btn.svelte-1xm8gof:hover,\n .list-btn.svelte-1xm8gof:hover {background:#3d3d5c;}.picker-btn.active.svelte-1xm8gof {background:#22c55e;border-color:#16a34a;color:#fff;\n animation: svelte-1xm8gof-pulse 1s infinite;}\n\n @keyframes svelte-1xm8gof-pulse {\n 0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }\n 50% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }\n }.list-btn.has-items.svelte-1xm8gof {background:#3b82f6;}.badge.svelte-1xm8gof {position:absolute;top:-6px;right:-6px;background:#ef4444;color:#fff;font-size:10px;font-weight:bold;min-width:16px;height:16px;border-radius:8px;display:flex;align-items:center;justify-content:center;padding:0 4px;}.status.svelte-1xm8gof {color:#aaa;max-width:400px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}.done-btn.svelte-1xm8gof {padding:8px 16px;border:none;border-radius:6px;background:#22c55e;color:#fff;font-weight:600;cursor:pointer;transition:all 0.2s;}.done-btn.svelte-1xm8gof:hover {background:#16a34a;}.overlay.svelte-1xm8gof {position:fixed;top:0;left:0;width:100vw;height:100vh;z-index:2147483646;pointer-events:none;}.overlay-dark.svelte-1xm8gof {position:fixed;background:rgba(0, 0, 0, 0.5);pointer-events:none;}.highlight.svelte-1xm8gof {position:fixed;border:3px solid #22c55e;background:rgba(34, 197, 94, 0.1);pointer-events:none;box-sizing:border-box;}"
3681
+ };
3682
+ function Toolbar($$anchor, $$props) {
3683
+ push($$props, true);
3684
+ append_styles($$anchor, $$css);
3685
+ function emit(event2) {
3686
+ var _a2;
3687
+ (_a2 = globalThis.__heroshot) == null ? void 0 : _a2.emit(event2);
3688
+ }
3689
+ let isPickerActive = /* @__PURE__ */ state(false);
3690
+ let isHighlighting = /* @__PURE__ */ state(
3691
+ false
3692
+ // True when showing highlight from job
3693
+ );
3694
+ let currentElement = /* @__PURE__ */ state(null);
3695
+ let statusText = /* @__PURE__ */ state("Click crosshair to pick element");
3696
+ let screenshots = /* @__PURE__ */ state(proxy([...$$props.initialScreenshots ?? []]));
3697
+ let pendingPick = /* @__PURE__ */ state(null);
3698
+ let showNameModal = /* @__PURE__ */ state(false);
3699
+ let showListDialog = /* @__PURE__ */ state(false);
3700
+ let scrollY = /* @__PURE__ */ state(proxy(globalThis.scrollY ?? 0));
3701
+ let scrollX = /* @__PURE__ */ state(proxy(globalThis.scrollX ?? 0));
3702
+ let screenshotCount = /* @__PURE__ */ user_derived(() => get(screenshots).length);
3703
+ let showOverlay = /* @__PURE__ */ user_derived(() => (get(isPickerActive) || get(isHighlighting)) && get(overlayRects) !== null);
3704
+ function togglePicker() {
3705
+ set(isPickerActive, !get(isPickerActive));
3706
+ set(isHighlighting, false);
3707
+ if (get(isPickerActive)) {
3708
+ set(statusText, "Hover over element, click to select");
3709
+ document.body.style.cursor = "crosshair";
3710
+ } else {
3711
+ set(statusText, "Click crosshair to pick element");
3712
+ document.body.style.cursor = "";
3713
+ set(currentElement, null);
3714
+ }
3715
+ }
3716
+ function handleMouseMove(event2) {
3717
+ if (!get(isPickerActive)) return;
3718
+ const element = deepElementFromPoint(event2.clientX, event2.clientY);
3719
+ if (element && !element.closest("#heroshot-root") && !element.closest("#heroshot-overlay")) {
3720
+ set(currentElement, element, true);
3721
+ const selector = getSelector(element);
3722
+ set(statusText, selector, true);
3723
+ }
3724
+ }
3725
+ function handleClick(event2) {
3726
+ if (!get(isPickerActive)) return;
3727
+ const { target } = event2;
3728
+ if (target instanceof Element && target.closest("#heroshot-root")) {
3729
+ return;
3730
+ }
3731
+ event2.preventDefault();
3732
+ event2.stopPropagation();
3733
+ if (get(currentElement)) {
3734
+ const selector = getSelector(get(currentElement));
3735
+ const { href } = globalThis.location;
3736
+ set(pendingPick, { url: href, selector }, true);
3737
+ set(showNameModal, true);
3738
+ set(isPickerActive, false);
3739
+ document.body.style.cursor = "";
3740
+ }
3741
+ }
3742
+ function handleKeyDown(event2) {
3743
+ if (event2.key === "Escape") {
3744
+ if (get(showNameModal)) {
3745
+ set(showNameModal, false);
3746
+ set(pendingPick, null);
3747
+ } else if (get(showListDialog)) {
3748
+ set(showListDialog, false);
3749
+ } else if (get(isPickerActive)) {
3750
+ togglePicker();
3751
+ } else if (get(isHighlighting)) {
3752
+ set(isHighlighting, false);
3753
+ set(currentElement, null);
3754
+ set(statusText, "Click crosshair to pick element");
3755
+ }
3756
+ }
3757
+ }
3758
+ function handleNameSave(name) {
3759
+ if (!get(pendingPick)) return;
3760
+ const screenshotData = {
3761
+ id: generateUid(),
3762
+ name,
3763
+ url: get(pendingPick).url,
3764
+ selector: get(pendingPick).selector
3765
+ };
3766
+ set(screenshots, [...get(screenshots), screenshotData], true);
3767
+ emit({ type: "screenshot-added", data: screenshotData });
3768
+ set(showNameModal, false);
3769
+ set(pendingPick, null);
3770
+ set(currentElement, null);
3771
+ set(statusText, "Click crosshair to pick element");
3772
+ }
3773
+ function handleNameCancel() {
3774
+ set(showNameModal, false);
3775
+ set(pendingPick, null);
3776
+ set(currentElement, null);
3777
+ set(statusText, "Click crosshair to pick element");
3778
+ }
3779
+ function handleRemoveScreenshot(id) {
3780
+ set(screenshots, get(screenshots).filter((s) => s.id !== id), true);
3781
+ emit({ type: "screenshot-removed", id });
3782
+ }
3783
+ function handleSelectScreenshot(screenshot) {
3784
+ set(showListDialog, false);
3785
+ emit({
3786
+ type: "screenshot-selected",
3787
+ id: screenshot.id,
3788
+ url: screenshot.url,
3789
+ selector: screenshot.selector
3790
+ });
3791
+ }
3792
+ function querySelectorPiercing(selector) {
3793
+ const parts = selector.split(">>>").map((s) => s.trim());
3794
+ let current = document;
3795
+ for (const part of parts) {
3796
+ if (!part) continue;
3797
+ const root2 = current instanceof Element ? current.shadowRoot ?? current : current;
3798
+ const found = root2.querySelector(part);
3799
+ if (!found) {
3800
+ return null;
3801
+ }
3802
+ current = found;
3803
+ }
3804
+ return current instanceof Element ? current : null;
3805
+ }
3806
+ function highlightElement(selector, attempt = 1) {
3807
+ const maxAttempts = 5;
3808
+ const element = selector.includes(">>>") ? querySelectorPiercing(selector) : document.querySelector(selector);
3809
+ if (element) {
3810
+ set(currentElement, element, true);
3811
+ set(isHighlighting, true);
3812
+ set(statusText, selector, true);
3813
+ element.scrollIntoView({ behavior: "smooth", block: "center" });
3814
+ emit({ type: "job-complete" });
3815
+ } else if (attempt < maxAttempts) {
3816
+ set(statusText, `Looking for element... (attempt ${attempt}/${maxAttempts})`);
3817
+ globalThis.setTimeout(() => highlightElement(selector, attempt + 1), 1e3);
3818
+ } else {
3819
+ set(statusText, `Element not found: ${selector}`);
3820
+ emit({ type: "job-complete" });
3821
+ }
3822
+ }
3823
+ function executePendingJob(job) {
3824
+ highlightElement(job.selector);
3825
+ }
3826
+ function isToolbarJob(value) {
3827
+ return typeof value === "object" && value !== null && "type" in value && "selector" in value;
3828
+ }
3829
+ function handleNewJob(event2) {
3830
+ if (event2 instanceof CustomEvent && isToolbarJob(event2.detail)) {
3831
+ executePendingJob(event2.detail);
3832
+ }
3833
+ }
3834
+ user_effect(() => {
3835
+ const job = $$props.pendingJob;
3836
+ if (job) {
3837
+ globalThis.setTimeout(() => executePendingJob(job), 100);
3838
+ }
3839
+ });
3840
+ user_effect(() => {
3841
+ globalThis.addEventListener("heroshot-job", handleNewJob);
3842
+ return () => globalThis.removeEventListener("heroshot-job", handleNewJob);
3843
+ });
3844
+ function handleDone() {
3845
+ emit({ type: "done" });
3846
+ }
3847
+ function generateUid() {
3848
+ return Math.random().toString(36).slice(2, 10);
3849
+ }
3850
+ function handleScroll() {
3851
+ set(scrollY, globalThis.scrollY, true);
3852
+ set(scrollX, globalThis.scrollX, true);
3853
+ }
3854
+ function getOverlayRects(element, _scrollX, _scrollY) {
3855
+ if (!element) return null;
3856
+ const rect = element.getBoundingClientRect();
3857
+ const { innerWidth, innerHeight } = globalThis;
3858
+ return {
3859
+ top: { top: 0, left: 0, width: innerWidth, height: rect.top },
3860
+ bottom: {
3861
+ top: rect.bottom,
3862
+ left: 0,
3863
+ width: innerWidth,
3864
+ height: innerHeight - rect.bottom
3865
+ },
3866
+ left: {
3867
+ top: rect.top,
3868
+ left: 0,
3869
+ width: rect.left,
3870
+ height: rect.height
3871
+ },
3872
+ right: {
3873
+ top: rect.top,
3874
+ left: rect.right,
3875
+ width: innerWidth - rect.right,
3876
+ height: rect.height
3877
+ },
3878
+ highlight: {
3879
+ top: rect.top,
3880
+ left: rect.left,
3881
+ width: rect.width,
3882
+ height: rect.height
3883
+ }
3884
+ };
3885
+ }
3886
+ let overlayRects = /* @__PURE__ */ user_derived(() => getOverlayRects(get(currentElement), get(scrollX), get(scrollY)));
3887
+ var fragment = root_1();
3888
+ event("scroll", $window, handleScroll);
3889
+ event("mousemove", $document, handleMouseMove);
3890
+ event("click", $document, handleClick);
3891
+ event("keydown", $document, handleKeyDown);
3892
+ var div = first_child(fragment);
3893
+ var button = child(div);
3894
+ let classes;
3895
+ button.__click = togglePicker;
3896
+ var span = sibling(button, 2);
3897
+ var text = child(span);
3898
+ var button_1 = sibling(span, 2);
3899
+ let classes_1;
3900
+ button_1.__click = () => set(showListDialog, true);
3901
+ var node = sibling(child(button_1), 2);
3902
+ {
3903
+ var consequent = ($$anchor2) => {
3904
+ var span_1 = root_2();
3905
+ var text_1 = child(span_1);
3906
+ template_effect(() => set_text(text_1, get(screenshotCount)));
3907
+ append($$anchor2, span_1);
3908
+ };
3909
+ if_block(node, ($$render) => {
3910
+ if (get(screenshotCount) > 0) $$render(consequent);
3911
+ });
3912
+ }
3913
+ var button_2 = sibling(button_1, 2);
3914
+ button_2.__click = handleDone;
3915
+ var node_1 = sibling(div, 2);
3916
+ {
3917
+ var consequent_1 = ($$anchor2) => {
3918
+ var div_1 = root_3();
3919
+ var div_2 = child(div_1);
3920
+ var div_3 = sibling(div_2, 2);
3921
+ var div_4 = sibling(div_3, 2);
3922
+ var div_5 = sibling(div_4, 2);
3923
+ var div_6 = sibling(div_5, 2);
3924
+ template_effect(() => {
3925
+ set_style(div_2, `top:${get(overlayRects).top.top ?? ""}px;left:${get(overlayRects).top.left ?? ""}px;width:${get(overlayRects).top.width ?? ""}px;height:${get(overlayRects).top.height ?? ""}px;`);
3926
+ set_style(div_3, `top:${get(overlayRects).bottom.top ?? ""}px;left:${get(overlayRects).bottom.left ?? ""}px;width:${get(overlayRects).bottom.width ?? ""}px;height:${get(overlayRects).bottom.height ?? ""}px;`);
3927
+ set_style(div_4, `top:${get(overlayRects).left.top ?? ""}px;left:${get(overlayRects).left.left ?? ""}px;width:${get(overlayRects).left.width ?? ""}px;height:${get(overlayRects).left.height ?? ""}px;`);
3928
+ set_style(div_5, `top:${get(overlayRects).right.top ?? ""}px;left:${get(overlayRects).right.left ?? ""}px;width:${get(overlayRects).right.width ?? ""}px;height:${get(overlayRects).right.height ?? ""}px;`);
3929
+ set_style(div_6, `top:${get(overlayRects).highlight.top ?? ""}px;left:${get(overlayRects).highlight.left ?? ""}px;width:${get(overlayRects).highlight.width ?? ""}px;height:${get(overlayRects).highlight.height ?? ""}px;`);
3930
+ });
3931
+ append($$anchor2, div_1);
3932
+ };
3933
+ if_block(node_1, ($$render) => {
3934
+ if (get(showOverlay) && get(overlayRects)) $$render(consequent_1);
3935
+ });
3936
+ }
3937
+ var node_2 = sibling(node_1, 2);
3938
+ {
3939
+ var consequent_2 = ($$anchor2) => {
3940
+ NameModal($$anchor2, {
3941
+ get selector() {
3942
+ return get(pendingPick).selector;
3943
+ },
3944
+ onSave: handleNameSave,
3945
+ onCancel: handleNameCancel
3946
+ });
3947
+ };
3948
+ if_block(node_2, ($$render) => {
3949
+ if (get(showNameModal) && get(pendingPick)) $$render(consequent_2);
3950
+ });
3951
+ }
3952
+ var node_3 = sibling(node_2, 2);
3953
+ {
3954
+ var consequent_3 = ($$anchor2) => {
3955
+ ListDialog($$anchor2, {
3956
+ get screenshots() {
3957
+ return get(screenshots);
3958
+ },
3959
+ onSelect: handleSelectScreenshot,
3960
+ onRemove: handleRemoveScreenshot,
3961
+ onClose: () => set(showListDialog, false)
3962
+ });
3963
+ };
3964
+ if_block(node_3, ($$render) => {
3965
+ if (get(showListDialog)) $$render(consequent_3);
3966
+ });
3967
+ }
3968
+ template_effect(() => {
3969
+ classes = set_class(button, 1, "picker-btn svelte-1xm8gof", null, classes, { active: get(isPickerActive) });
3970
+ set_text(text, get(statusText));
3971
+ classes_1 = set_class(button_1, 1, "list-btn svelte-1xm8gof", null, classes_1, { "has-items": get(screenshotCount) > 0 });
3972
+ });
3973
+ append($$anchor, fragment);
3974
+ pop();
3975
+ }
3976
+ delegate(["click"]);
3977
+ function initToolbar() {
3978
+ if (!globalThis.__heroshot) {
3979
+ globalThis.__heroshot = {
3980
+ initialized: false,
3981
+ screenshots: [],
3982
+ pendingJob: null,
3983
+ emit: () => {
3984
+ }
3985
+ };
3986
+ }
3987
+ if (globalThis.__heroshot.initialized) {
3988
+ return null;
3989
+ }
3990
+ globalThis.__heroshot.initialized = true;
3991
+ const host = document.createElement("div");
3992
+ host.id = "heroshot-root";
3993
+ document.body.append(host);
3994
+ const shadow = host.attachShadow({ mode: "closed" });
3995
+ let component;
3996
+ try {
3997
+ component = mount(Toolbar, {
3998
+ target: shadow,
3999
+ props: {
4000
+ initialScreenshots: [...globalThis.__heroshot.screenshots],
4001
+ pendingJob: globalThis.__heroshot.pendingJob
4002
+ }
4003
+ });
4004
+ } catch {
4005
+ return null;
4006
+ }
4007
+ function cleanup() {
4008
+ void unmount(component);
4009
+ host.remove();
4010
+ if (globalThis.__heroshot) {
4011
+ globalThis.__heroshot.initialized = false;
4012
+ }
4013
+ }
4014
+ return cleanup;
4015
+ }
4016
+ initToolbar();
4017
+ exports.initToolbar = initToolbar;
4018
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4019
+ })(this.HeroshotToolbar = this.HeroshotToolbar || {});