@autumnsgrove/gossamer 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/dist/animation.js +165 -0
  3. package/dist/animation.test.js +204 -0
  4. package/dist/characters.js +176 -0
  5. package/dist/characters.test.js +115 -0
  6. package/dist/colors.js +199 -0
  7. package/dist/index.js +79 -1850
  8. package/dist/index.test.js +92 -0
  9. package/dist/patterns.js +539 -0
  10. package/dist/patterns.test.js +223 -0
  11. package/dist/renderer.js +362 -0
  12. package/dist/svelte/GossamerBorder.svelte.d.ts +56 -1
  13. package/dist/svelte/GossamerBorder.svelte.d.ts.map +1 -0
  14. package/dist/svelte/GossamerClouds.svelte.d.ts +31 -1
  15. package/dist/svelte/GossamerClouds.svelte.d.ts.map +1 -0
  16. package/dist/svelte/GossamerImage.svelte.d.ts +28 -1
  17. package/dist/svelte/GossamerImage.svelte.d.ts.map +1 -0
  18. package/dist/svelte/GossamerOverlay.svelte.d.ts +32 -1
  19. package/dist/svelte/GossamerOverlay.svelte.d.ts.map +1 -0
  20. package/dist/svelte/GossamerText.svelte.d.ts +29 -1
  21. package/dist/svelte/GossamerText.svelte.d.ts.map +1 -0
  22. package/dist/svelte/index.js +31 -3646
  23. package/dist/svelte/presets.d.ts +4 -2
  24. package/dist/svelte/presets.js +161 -0
  25. package/dist/utils/canvas.js +139 -0
  26. package/dist/utils/image.js +195 -0
  27. package/dist/utils/performance.js +205 -0
  28. package/package.json +18 -22
  29. package/dist/index.js.map +0 -1
  30. package/dist/style.css +0 -124
  31. package/dist/svelte/index.js.map +0 -1
  32. package/src/animation.test.ts +0 -254
  33. package/src/animation.ts +0 -243
  34. package/src/characters.test.ts +0 -148
  35. package/src/characters.ts +0 -219
  36. package/src/colors.ts +0 -234
  37. package/src/index.test.ts +0 -115
  38. package/src/index.ts +0 -234
  39. package/src/patterns.test.ts +0 -273
  40. package/src/patterns.ts +0 -760
  41. package/src/renderer.ts +0 -470
  42. package/src/svelte/index.ts +0 -75
  43. package/src/svelte/presets.ts +0 -174
  44. package/src/utils/canvas.ts +0 -210
  45. package/src/utils/image.ts +0 -275
  46. package/src/utils/performance.ts +0 -282
  47. /package/{src → dist}/svelte/GossamerBorder.svelte +0 -0
  48. /package/{src → dist}/svelte/GossamerClouds.svelte +0 -0
  49. /package/{src → dist}/svelte/GossamerImage.svelte +0 -0
  50. /package/{src → dist}/svelte/GossamerOverlay.svelte +0 -0
  51. /package/{src → dist}/svelte/GossamerText.svelte +0 -0
@@ -1,3648 +1,33 @@
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
- var _a, _commit_callbacks, _discard_callbacks, _pending, _blocking_pending, _deferred, _dirty_effects, _maybe_dirty_effects, _Batch_instances, traverse_effect_tree_fn, defer_effects_fn, resolve_fn, commit_fn, _batches, _onscreen, _offscreen, _outroing, _transition, _commit, _discard;
13
- import { onMount } from "svelte";
14
- import { onReducedMotionChange, createVisibilityObserver, createResizeObserver, CHARACTER_SETS, GossamerRenderer, generateBrightnessGrid, loadImage, imageToPixelData, sampleImageCells, brightnessToChar, invertCharacters, perlinNoise2D } from "../index.js";
15
- import { DEFAULT_CHARACTERS, DEFAULT_CONFIG, VERSION, calculateBrightness, getCharacterSet, getCharacterSetNames, getCharacters, prefersReducedMotion } from "../index.js";
16
- const PUBLIC_VERSION = "5";
17
- if (typeof window !== "undefined") {
18
- ((_a = window.__svelte ?? (window.__svelte = {})).v ?? (_a.v = /* @__PURE__ */ new Set())).add(PUBLIC_VERSION);
19
- }
20
- const PROPS_IS_IMMUTABLE = 1;
21
- const PROPS_IS_UPDATED = 1 << 2;
22
- const PROPS_IS_BINDABLE = 1 << 3;
23
- const PROPS_IS_LAZY_INITIAL = 1 << 4;
24
- const TEMPLATE_FRAGMENT = 1;
25
- const TEMPLATE_USE_IMPORT_NODE = 1 << 1;
26
- const UNINITIALIZED = Symbol();
27
- const NAMESPACE_HTML = "http://www.w3.org/1999/xhtml";
28
- const DEV = false;
29
- var is_array = Array.isArray;
30
- var index_of = Array.prototype.indexOf;
31
- var define_property = Object.defineProperty;
32
- var get_descriptor = Object.getOwnPropertyDescriptor;
33
- var get_descriptors = Object.getOwnPropertyDescriptors;
34
- var object_prototype = Object.prototype;
35
- var array_prototype = Array.prototype;
36
- var get_prototype_of = Object.getPrototypeOf;
37
- function run_all(arr) {
38
- for (var i = 0; i < arr.length; i++) {
39
- arr[i]();
40
- }
41
- }
42
- function deferred() {
43
- var resolve;
44
- var reject;
45
- var promise = new Promise((res, rej) => {
46
- resolve = res;
47
- reject = rej;
48
- });
49
- return { promise, resolve, reject };
50
- }
51
- const DERIVED = 1 << 1;
52
- const EFFECT = 1 << 2;
53
- const RENDER_EFFECT = 1 << 3;
54
- const MANAGED_EFFECT = 1 << 24;
55
- const BLOCK_EFFECT = 1 << 4;
56
- const BRANCH_EFFECT = 1 << 5;
57
- const ROOT_EFFECT = 1 << 6;
58
- const BOUNDARY_EFFECT = 1 << 7;
59
- const CONNECTED = 1 << 9;
60
- const CLEAN = 1 << 10;
61
- const DIRTY = 1 << 11;
62
- const MAYBE_DIRTY = 1 << 12;
63
- const INERT = 1 << 13;
64
- const DESTROYED = 1 << 14;
65
- const EFFECT_RAN = 1 << 15;
66
- const EFFECT_TRANSPARENT = 1 << 16;
67
- const EAGER_EFFECT = 1 << 17;
68
- const HEAD_EFFECT = 1 << 18;
69
- const EFFECT_PRESERVED = 1 << 19;
70
- const USER_EFFECT = 1 << 20;
71
- const WAS_MARKED = 1 << 15;
72
- const REACTION_IS_UPDATING = 1 << 21;
73
- const ASYNC = 1 << 22;
74
- const ERROR_VALUE = 1 << 23;
75
- const STATE_SYMBOL = Symbol("$state");
76
- const LEGACY_PROPS = Symbol("legacy props");
77
- const LOADING_ATTR_SYMBOL = Symbol("");
78
- const STALE_REACTION = new class StaleReactionError extends Error {
79
- constructor() {
80
- super(...arguments);
81
- __publicField(this, "name", "StaleReactionError");
82
- __publicField(this, "message", "The reaction that called `getAbortSignal()` was re-run or destroyed");
83
- }
84
- }();
85
- function async_derived_orphan() {
86
- {
87
- throw new Error(`https://svelte.dev/e/async_derived_orphan`);
88
- }
89
- }
90
- function effect_in_teardown(rune) {
91
- {
92
- throw new Error(`https://svelte.dev/e/effect_in_teardown`);
93
- }
94
- }
95
- function effect_in_unowned_derived() {
96
- {
97
- throw new Error(`https://svelte.dev/e/effect_in_unowned_derived`);
98
- }
99
- }
100
- function effect_orphan(rune) {
101
- {
102
- throw new Error(`https://svelte.dev/e/effect_orphan`);
103
- }
104
- }
105
- function effect_update_depth_exceeded() {
106
- {
107
- throw new Error(`https://svelte.dev/e/effect_update_depth_exceeded`);
108
- }
109
- }
110
- function props_invalid_value(key) {
111
- {
112
- throw new Error(`https://svelte.dev/e/props_invalid_value`);
113
- }
114
- }
115
- function state_descriptors_fixed() {
116
- {
117
- throw new Error(`https://svelte.dev/e/state_descriptors_fixed`);
118
- }
119
- }
120
- function state_prototype_fixed() {
121
- {
122
- throw new Error(`https://svelte.dev/e/state_prototype_fixed`);
123
- }
124
- }
125
- function state_unsafe_mutation() {
126
- {
127
- throw new Error(`https://svelte.dev/e/state_unsafe_mutation`);
128
- }
129
- }
130
- function equals(value) {
131
- return value === this.v;
132
- }
133
- function safe_not_equal(a, b) {
134
- return a != a ? b == b : a !== b || a !== null && typeof a === "object" || typeof a === "function";
135
- }
136
- function safe_equals(value) {
137
- return !safe_not_equal(value, this.v);
138
- }
139
- let tracing_mode_flag = false;
140
- let component_context = null;
141
- function set_component_context(context) {
142
- component_context = context;
143
- }
144
- function push(props, runes = false, fn) {
145
- component_context = {
146
- p: component_context,
147
- i: false,
148
- c: null,
149
- e: null,
150
- s: props,
151
- x: null,
152
- l: null
153
- };
154
- }
155
- function pop(component) {
156
- var context = (
157
- /** @type {ComponentContext} */
158
- component_context
159
- );
160
- var effects = context.e;
161
- if (effects !== null) {
162
- context.e = null;
163
- for (var fn of effects) {
164
- create_user_effect(fn);
165
- }
166
- }
167
- context.i = true;
168
- component_context = context.p;
169
- return (
170
- /** @type {T} */
171
- {}
172
- );
173
- }
174
- function is_runes() {
175
- return true;
176
- }
177
- let micro_tasks = [];
178
- function run_micro_tasks() {
179
- var tasks = micro_tasks;
180
- micro_tasks = [];
181
- run_all(tasks);
182
- }
183
- function queue_micro_task(fn) {
184
- if (micro_tasks.length === 0 && true) {
185
- var tasks = micro_tasks;
186
- queueMicrotask(() => {
187
- if (tasks === micro_tasks) run_micro_tasks();
188
- });
189
- }
190
- micro_tasks.push(fn);
191
- }
192
- function handle_error(error) {
193
- var effect2 = active_effect;
194
- if (effect2 === null) {
195
- active_reaction.f |= ERROR_VALUE;
196
- return error;
197
- }
198
- if ((effect2.f & EFFECT_RAN) === 0) {
199
- if ((effect2.f & BOUNDARY_EFFECT) === 0) {
200
- throw error;
201
- }
202
- effect2.b.error(error);
203
- } else {
204
- invoke_error_boundary(error, effect2);
205
- }
206
- }
207
- function invoke_error_boundary(error, effect2) {
208
- while (effect2 !== null) {
209
- if ((effect2.f & BOUNDARY_EFFECT) !== 0) {
210
- try {
211
- effect2.b.error(error);
212
- return;
213
- } catch (e) {
214
- error = e;
215
- }
216
- }
217
- effect2 = effect2.parent;
218
- }
219
- throw error;
220
- }
221
- const STATUS_MASK = -7169;
222
- function set_signal_status(signal, status) {
223
- signal.f = signal.f & STATUS_MASK | status;
224
- }
225
- function update_derived_status(derived2) {
226
- if ((derived2.f & CONNECTED) !== 0 || derived2.deps === null) {
227
- set_signal_status(derived2, CLEAN);
228
- } else {
229
- set_signal_status(derived2, MAYBE_DIRTY);
230
- }
231
- }
232
- function clear_marked(deps) {
233
- if (deps === null) return;
234
- for (const dep of deps) {
235
- if ((dep.f & DERIVED) === 0 || (dep.f & WAS_MARKED) === 0) {
236
- continue;
237
- }
238
- dep.f ^= WAS_MARKED;
239
- clear_marked(
240
- /** @type {Derived} */
241
- dep.deps
242
- );
243
- }
244
- }
245
- function defer_effect(effect2, dirty_effects, maybe_dirty_effects) {
246
- if ((effect2.f & DIRTY) !== 0) {
247
- dirty_effects.add(effect2);
248
- } else if ((effect2.f & MAYBE_DIRTY) !== 0) {
249
- maybe_dirty_effects.add(effect2);
250
- }
251
- clear_marked(effect2.deps);
252
- set_signal_status(effect2, CLEAN);
253
- }
254
- const batches = /* @__PURE__ */ new Set();
255
- let current_batch = null;
256
- let batch_values = null;
257
- let queued_root_effects = [];
258
- let last_scheduled_effect = null;
259
- let is_flushing = false;
260
- const _Batch = class _Batch {
261
- constructor() {
262
- __privateAdd(this, _Batch_instances);
263
- __publicField(this, "committed", false);
264
- /**
265
- * The current values of any sources that are updated in this batch
266
- * They keys of this map are identical to `this.#previous`
267
- * @type {Map<Source, any>}
268
- */
269
- __publicField(this, "current", /* @__PURE__ */ new Map());
270
- /**
271
- * The values of any sources that are updated in this batch _before_ those updates took place.
272
- * They keys of this map are identical to `this.#current`
273
- * @type {Map<Source, any>}
274
- */
275
- __publicField(this, "previous", /* @__PURE__ */ new Map());
276
- /**
277
- * When the batch is committed (and the DOM is updated), we need to remove old branches
278
- * and append new ones by calling the functions added inside (if/each/key/etc) blocks
279
- * @type {Set<() => void>}
280
- */
281
- __privateAdd(this, _commit_callbacks, /* @__PURE__ */ new Set());
282
- /**
283
- * If a fork is discarded, we need to destroy any effects that are no longer needed
284
- * @type {Set<(batch: Batch) => void>}
285
- */
286
- __privateAdd(this, _discard_callbacks, /* @__PURE__ */ new Set());
287
- /**
288
- * The number of async effects that are currently in flight
289
- */
290
- __privateAdd(this, _pending, 0);
291
- /**
292
- * The number of async effects that are currently in flight, _not_ inside a pending boundary
293
- */
294
- __privateAdd(this, _blocking_pending, 0);
295
- /**
296
- * A deferred that resolves when the batch is committed, used with `settled()`
297
- * TODO replace with Promise.withResolvers once supported widely enough
298
- * @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null}
299
- */
300
- __privateAdd(this, _deferred, null);
301
- /**
302
- * Deferred effects (which run after async work has completed) that are DIRTY
303
- * @type {Set<Effect>}
304
- */
305
- __privateAdd(this, _dirty_effects, /* @__PURE__ */ new Set());
306
- /**
307
- * Deferred effects that are MAYBE_DIRTY
308
- * @type {Set<Effect>}
309
- */
310
- __privateAdd(this, _maybe_dirty_effects, /* @__PURE__ */ new Set());
311
- /**
312
- * A set of branches that still exist, but will be destroyed when this batch
313
- * is committed — we skip over these during `process`
314
- * @type {Set<Effect>}
315
- */
316
- __publicField(this, "skipped_effects", /* @__PURE__ */ new Set());
317
- __publicField(this, "is_fork", false);
318
- }
319
- is_deferred() {
320
- return this.is_fork || __privateGet(this, _blocking_pending) > 0;
321
- }
322
- /**
323
- *
324
- * @param {Effect[]} root_effects
325
- */
326
- process(root_effects) {
327
- var _a2;
328
- queued_root_effects = [];
329
- this.apply();
330
- var effects = [];
331
- var render_effects = [];
332
- for (const root2 of root_effects) {
333
- __privateMethod(this, _Batch_instances, traverse_effect_tree_fn).call(this, root2, effects, render_effects);
334
- }
335
- if (!this.is_fork) {
336
- __privateMethod(this, _Batch_instances, resolve_fn).call(this);
337
- }
338
- if (this.is_deferred()) {
339
- __privateMethod(this, _Batch_instances, defer_effects_fn).call(this, render_effects);
340
- __privateMethod(this, _Batch_instances, defer_effects_fn).call(this, effects);
341
- } else {
342
- current_batch = null;
343
- flush_queued_effects(render_effects);
344
- flush_queued_effects(effects);
345
- (_a2 = __privateGet(this, _deferred)) == null ? void 0 : _a2.resolve();
346
- }
347
- batch_values = null;
348
- }
349
- /**
350
- * Associate a change to a given source with the current
351
- * batch, noting its previous and current values
352
- * @param {Source} source
353
- * @param {any} value
354
- */
355
- capture(source2, value) {
356
- if (value !== UNINITIALIZED && !this.previous.has(source2)) {
357
- this.previous.set(source2, value);
358
- }
359
- if ((source2.f & ERROR_VALUE) === 0) {
360
- this.current.set(source2, source2.v);
361
- batch_values == null ? void 0 : batch_values.set(source2, source2.v);
362
- }
363
- }
364
- activate() {
365
- current_batch = this;
366
- this.apply();
367
- }
368
- deactivate() {
369
- if (current_batch !== this) return;
370
- current_batch = null;
371
- batch_values = null;
372
- }
373
- flush() {
374
- this.activate();
375
- if (queued_root_effects.length > 0) {
376
- flush_effects();
377
- if (current_batch !== null && current_batch !== this) {
378
- return;
379
- }
380
- } else if (__privateGet(this, _pending) === 0) {
381
- this.process([]);
382
- }
383
- this.deactivate();
384
- }
385
- discard() {
386
- for (const fn of __privateGet(this, _discard_callbacks)) fn(this);
387
- __privateGet(this, _discard_callbacks).clear();
388
- }
389
- /**
390
- *
391
- * @param {boolean} blocking
392
- */
393
- increment(blocking) {
394
- __privateSet(this, _pending, __privateGet(this, _pending) + 1);
395
- if (blocking) __privateSet(this, _blocking_pending, __privateGet(this, _blocking_pending) + 1);
396
- }
397
- /**
398
- *
399
- * @param {boolean} blocking
400
- */
401
- decrement(blocking) {
402
- __privateSet(this, _pending, __privateGet(this, _pending) - 1);
403
- if (blocking) __privateSet(this, _blocking_pending, __privateGet(this, _blocking_pending) - 1);
404
- this.revive();
405
- }
406
- revive() {
407
- for (const e of __privateGet(this, _dirty_effects)) {
408
- __privateGet(this, _maybe_dirty_effects).delete(e);
409
- set_signal_status(e, DIRTY);
410
- schedule_effect(e);
411
- }
412
- for (const e of __privateGet(this, _maybe_dirty_effects)) {
413
- set_signal_status(e, MAYBE_DIRTY);
414
- schedule_effect(e);
415
- }
416
- this.flush();
417
- }
418
- /** @param {() => void} fn */
419
- oncommit(fn) {
420
- __privateGet(this, _commit_callbacks).add(fn);
421
- }
422
- /** @param {(batch: Batch) => void} fn */
423
- ondiscard(fn) {
424
- __privateGet(this, _discard_callbacks).add(fn);
425
- }
426
- settled() {
427
- return (__privateGet(this, _deferred) ?? __privateSet(this, _deferred, deferred())).promise;
428
- }
429
- static ensure() {
430
- if (current_batch === null) {
431
- const batch = current_batch = new _Batch();
432
- batches.add(current_batch);
433
- {
434
- _Batch.enqueue(() => {
435
- if (current_batch !== batch) {
436
- return;
437
- }
438
- batch.flush();
439
- });
440
- }
441
- }
442
- return current_batch;
443
- }
444
- /** @param {() => void} task */
445
- static enqueue(task) {
446
- queue_micro_task(task);
447
- }
448
- apply() {
449
- return;
450
- }
451
- };
452
- _commit_callbacks = new WeakMap();
453
- _discard_callbacks = new WeakMap();
454
- _pending = new WeakMap();
455
- _blocking_pending = new WeakMap();
456
- _deferred = new WeakMap();
457
- _dirty_effects = new WeakMap();
458
- _maybe_dirty_effects = new WeakMap();
459
- _Batch_instances = new WeakSet();
460
1
  /**
461
- * Traverse the effect tree, executing effects or stashing
462
- * them for later execution as appropriate
463
- * @param {Effect} root
464
- * @param {Effect[]} effects
465
- * @param {Effect[]} render_effects
2
+ * Gossamer - Svelte 5 Components
3
+ *
4
+ * ASCII visual effects components for Svelte applications.
5
+ *
6
+ * @packageDocumentation
466
7
  */
467
- traverse_effect_tree_fn = function(root2, effects, render_effects) {
468
- root2.f ^= CLEAN;
469
- var effect2 = root2.first;
470
- var pending_boundary = null;
471
- while (effect2 !== null) {
472
- var flags = effect2.f;
473
- var is_branch = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) !== 0;
474
- var is_skippable_branch = is_branch && (flags & CLEAN) !== 0;
475
- var skip = is_skippable_branch || (flags & INERT) !== 0 || this.skipped_effects.has(effect2);
476
- if (!skip && effect2.fn !== null) {
477
- if (is_branch) {
478
- effect2.f ^= CLEAN;
479
- } else if (pending_boundary !== null && (flags & (EFFECT | RENDER_EFFECT | MANAGED_EFFECT)) !== 0) {
480
- pending_boundary.b.defer_effect(effect2);
481
- } else if ((flags & EFFECT) !== 0) {
482
- effects.push(effect2);
483
- } else if (is_dirty(effect2)) {
484
- if ((flags & BLOCK_EFFECT) !== 0) __privateGet(this, _dirty_effects).add(effect2);
485
- update_effect(effect2);
486
- }
487
- var child2 = effect2.first;
488
- if (child2 !== null) {
489
- effect2 = child2;
490
- continue;
491
- }
492
- }
493
- var parent = effect2.parent;
494
- effect2 = effect2.next;
495
- while (effect2 === null && parent !== null) {
496
- if (parent === pending_boundary) {
497
- pending_boundary = null;
498
- }
499
- effect2 = parent.next;
500
- parent = parent.parent;
501
- }
502
- }
503
- };
504
- /**
505
- * @param {Effect[]} effects
506
- */
507
- defer_effects_fn = function(effects) {
508
- for (var i = 0; i < effects.length; i += 1) {
509
- defer_effect(effects[i], __privateGet(this, _dirty_effects), __privateGet(this, _maybe_dirty_effects));
510
- }
511
- };
512
- resolve_fn = function() {
513
- if (__privateGet(this, _blocking_pending) === 0) {
514
- for (const fn of __privateGet(this, _commit_callbacks)) fn();
515
- __privateGet(this, _commit_callbacks).clear();
516
- }
517
- if (__privateGet(this, _pending) === 0) {
518
- __privateMethod(this, _Batch_instances, commit_fn).call(this);
519
- }
520
- };
521
- commit_fn = function() {
522
- var _a2;
523
- if (batches.size > 1) {
524
- this.previous.clear();
525
- var previous_batch_values = batch_values;
526
- var is_earlier = true;
527
- for (const batch of batches) {
528
- if (batch === this) {
529
- is_earlier = false;
530
- continue;
531
- }
532
- const sources = [];
533
- for (const [source2, value] of this.current) {
534
- if (batch.current.has(source2)) {
535
- if (is_earlier && value !== batch.current.get(source2)) {
536
- batch.current.set(source2, value);
537
- } else {
538
- continue;
539
- }
540
- }
541
- sources.push(source2);
542
- }
543
- if (sources.length === 0) {
544
- continue;
545
- }
546
- const others = [...batch.current.keys()].filter((s) => !this.current.has(s));
547
- if (others.length > 0) {
548
- var prev_queued_root_effects = queued_root_effects;
549
- queued_root_effects = [];
550
- const marked = /* @__PURE__ */ new Set();
551
- const checked = /* @__PURE__ */ new Map();
552
- for (const source2 of sources) {
553
- mark_effects(source2, others, marked, checked);
554
- }
555
- if (queued_root_effects.length > 0) {
556
- current_batch = batch;
557
- batch.apply();
558
- for (const root2 of queued_root_effects) {
559
- __privateMethod(_a2 = batch, _Batch_instances, traverse_effect_tree_fn).call(_a2, root2, [], []);
560
- }
561
- batch.deactivate();
562
- }
563
- queued_root_effects = prev_queued_root_effects;
564
- }
565
- }
566
- current_batch = null;
567
- batch_values = previous_batch_values;
568
- }
569
- this.committed = true;
570
- batches.delete(this);
571
- };
572
- let Batch = _Batch;
573
- function flush_effects() {
574
- var was_updating_effect = is_updating_effect;
575
- is_flushing = true;
576
- var source_stacks = null;
577
- try {
578
- var flush_count = 0;
579
- set_is_updating_effect(true);
580
- while (queued_root_effects.length > 0) {
581
- var batch = Batch.ensure();
582
- if (flush_count++ > 1e3) {
583
- var updates, entry;
584
- if (DEV) ;
585
- infinite_loop_guard();
586
- }
587
- batch.process(queued_root_effects);
588
- old_values.clear();
589
- if (DEV) ;
590
- }
591
- } finally {
592
- is_flushing = false;
593
- set_is_updating_effect(was_updating_effect);
594
- last_scheduled_effect = null;
595
- }
596
- }
597
- function infinite_loop_guard() {
598
- try {
599
- effect_update_depth_exceeded();
600
- } catch (error) {
601
- invoke_error_boundary(error, last_scheduled_effect);
602
- }
603
- }
604
- let eager_block_effects = null;
605
- function flush_queued_effects(effects) {
606
- var length = effects.length;
607
- if (length === 0) return;
608
- var i = 0;
609
- while (i < length) {
610
- var effect2 = effects[i++];
611
- if ((effect2.f & (DESTROYED | INERT)) === 0 && is_dirty(effect2)) {
612
- eager_block_effects = /* @__PURE__ */ new Set();
613
- update_effect(effect2);
614
- if (effect2.deps === null && effect2.first === null && effect2.nodes === null) {
615
- if (effect2.teardown === null && effect2.ac === null) {
616
- unlink_effect(effect2);
617
- } else {
618
- effect2.fn = null;
619
- }
620
- }
621
- if ((eager_block_effects == null ? void 0 : eager_block_effects.size) > 0) {
622
- old_values.clear();
623
- for (const e of eager_block_effects) {
624
- if ((e.f & (DESTROYED | INERT)) !== 0) continue;
625
- const ordered_effects = [e];
626
- let ancestor = e.parent;
627
- while (ancestor !== null) {
628
- if (eager_block_effects.has(ancestor)) {
629
- eager_block_effects.delete(ancestor);
630
- ordered_effects.push(ancestor);
631
- }
632
- ancestor = ancestor.parent;
633
- }
634
- for (let j = ordered_effects.length - 1; j >= 0; j--) {
635
- const e2 = ordered_effects[j];
636
- if ((e2.f & (DESTROYED | INERT)) !== 0) continue;
637
- update_effect(e2);
638
- }
639
- }
640
- eager_block_effects.clear();
641
- }
642
- }
643
- }
644
- eager_block_effects = null;
645
- }
646
- function mark_effects(value, sources, marked, checked) {
647
- if (marked.has(value)) return;
648
- marked.add(value);
649
- if (value.reactions !== null) {
650
- for (const reaction of value.reactions) {
651
- const flags = reaction.f;
652
- if ((flags & DERIVED) !== 0) {
653
- mark_effects(
654
- /** @type {Derived} */
655
- reaction,
656
- sources,
657
- marked,
658
- checked
659
- );
660
- } else if ((flags & (ASYNC | BLOCK_EFFECT)) !== 0 && (flags & DIRTY) === 0 && depends_on(reaction, sources, checked)) {
661
- set_signal_status(reaction, DIRTY);
662
- schedule_effect(
663
- /** @type {Effect} */
664
- reaction
665
- );
666
- }
667
- }
668
- }
669
- }
670
- function depends_on(reaction, sources, checked) {
671
- const depends = checked.get(reaction);
672
- if (depends !== void 0) return depends;
673
- if (reaction.deps !== null) {
674
- for (const dep of reaction.deps) {
675
- if (sources.includes(dep)) {
676
- return true;
677
- }
678
- if ((dep.f & DERIVED) !== 0 && depends_on(
679
- /** @type {Derived} */
680
- dep,
681
- sources,
682
- checked
683
- )) {
684
- checked.set(
685
- /** @type {Derived} */
686
- dep,
687
- true
688
- );
689
- return true;
690
- }
691
- }
692
- }
693
- checked.set(reaction, false);
694
- return false;
695
- }
696
- function schedule_effect(signal) {
697
- var effect2 = last_scheduled_effect = signal;
698
- while (effect2.parent !== null) {
699
- effect2 = effect2.parent;
700
- var flags = effect2.f;
701
- if (is_flushing && effect2 === active_effect && (flags & BLOCK_EFFECT) !== 0 && (flags & HEAD_EFFECT) === 0) {
702
- return;
703
- }
704
- if ((flags & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
705
- if ((flags & CLEAN) === 0) return;
706
- effect2.f ^= CLEAN;
707
- }
708
- }
709
- queued_root_effects.push(effect2);
710
- }
711
- function flatten(blockers, sync, async, fn) {
712
- const d = derived;
713
- if (async.length === 0 && blockers.length === 0) {
714
- fn(sync.map(d));
715
- return;
716
- }
717
- var batch = current_batch;
718
- var parent = (
719
- /** @type {Effect} */
720
- active_effect
721
- );
722
- var restore = capture();
723
- function run() {
724
- Promise.all(async.map((expression) => /* @__PURE__ */ async_derived(expression))).then((result) => {
725
- restore();
726
- try {
727
- fn([...sync.map(d), ...result]);
728
- } catch (error) {
729
- if ((parent.f & DESTROYED) === 0) {
730
- invoke_error_boundary(error, parent);
731
- }
732
- }
733
- batch == null ? void 0 : batch.deactivate();
734
- unset_context();
735
- }).catch((error) => {
736
- invoke_error_boundary(error, parent);
737
- });
738
- }
739
- if (blockers.length > 0) {
740
- Promise.all(blockers).then(() => {
741
- restore();
742
- try {
743
- return run();
744
- } finally {
745
- batch == null ? void 0 : batch.deactivate();
746
- unset_context();
747
- }
748
- });
749
- } else {
750
- run();
751
- }
752
- }
753
- function capture() {
754
- var previous_effect = active_effect;
755
- var previous_reaction = active_reaction;
756
- var previous_component_context = component_context;
757
- var previous_batch = current_batch;
758
- return function restore(activate_batch = true) {
759
- set_active_effect(previous_effect);
760
- set_active_reaction(previous_reaction);
761
- set_component_context(previous_component_context);
762
- if (activate_batch) previous_batch == null ? void 0 : previous_batch.activate();
763
- };
764
- }
765
- function unset_context() {
766
- set_active_effect(null);
767
- set_active_reaction(null);
768
- set_component_context(null);
769
- }
770
- // @__NO_SIDE_EFFECTS__
771
- function derived(fn) {
772
- var flags = DERIVED | DIRTY;
773
- var parent_derived = active_reaction !== null && (active_reaction.f & DERIVED) !== 0 ? (
774
- /** @type {Derived} */
775
- active_reaction
776
- ) : null;
777
- if (active_effect !== null) {
778
- active_effect.f |= EFFECT_PRESERVED;
779
- }
780
- const signal = {
781
- ctx: component_context,
782
- deps: null,
783
- effects: null,
784
- equals,
785
- f: flags,
786
- fn,
787
- reactions: null,
788
- rv: 0,
789
- v: (
790
- /** @type {V} */
791
- UNINITIALIZED
792
- ),
793
- wv: 0,
794
- parent: parent_derived ?? active_effect,
795
- ac: null
796
- };
797
- return signal;
798
- }
799
- // @__NO_SIDE_EFFECTS__
800
- function async_derived(fn, label, location) {
801
- let parent = (
802
- /** @type {Effect | null} */
803
- active_effect
804
- );
805
- if (parent === null) {
806
- async_derived_orphan();
807
- }
808
- var boundary = (
809
- /** @type {Boundary} */
810
- parent.b
811
- );
812
- var promise = (
813
- /** @type {Promise<V>} */
814
- /** @type {unknown} */
815
- void 0
816
- );
817
- var signal = source(
818
- /** @type {V} */
819
- UNINITIALIZED
820
- );
821
- var should_suspend = !active_reaction;
822
- var deferreds = /* @__PURE__ */ new Map();
823
- async_effect(() => {
824
- var _a2;
825
- var d = deferred();
826
- promise = d.promise;
827
- try {
828
- Promise.resolve(fn()).then(d.resolve, d.reject).then(() => {
829
- if (batch === current_batch && batch.committed) {
830
- batch.deactivate();
831
- }
832
- unset_context();
833
- });
834
- } catch (error) {
835
- d.reject(error);
836
- unset_context();
837
- }
838
- var batch = (
839
- /** @type {Batch} */
840
- current_batch
841
- );
842
- if (should_suspend) {
843
- var blocking = boundary.is_rendered();
844
- boundary.update_pending_count(1);
845
- batch.increment(blocking);
846
- (_a2 = deferreds.get(batch)) == null ? void 0 : _a2.reject(STALE_REACTION);
847
- deferreds.delete(batch);
848
- deferreds.set(batch, d);
849
- }
850
- const handler = (value, error = void 0) => {
851
- batch.activate();
852
- if (error) {
853
- if (error !== STALE_REACTION) {
854
- signal.f |= ERROR_VALUE;
855
- internal_set(signal, error);
856
- }
857
- } else {
858
- if ((signal.f & ERROR_VALUE) !== 0) {
859
- signal.f ^= ERROR_VALUE;
860
- }
861
- internal_set(signal, value);
862
- for (const [b, d2] of deferreds) {
863
- deferreds.delete(b);
864
- if (b === batch) break;
865
- d2.reject(STALE_REACTION);
866
- }
867
- }
868
- if (should_suspend) {
869
- boundary.update_pending_count(-1);
870
- batch.decrement(blocking);
871
- }
872
- };
873
- d.promise.then(handler, (e) => handler(null, e || "unknown"));
874
- });
875
- teardown(() => {
876
- for (const d of deferreds.values()) {
877
- d.reject(STALE_REACTION);
878
- }
879
- });
880
- return new Promise((fulfil) => {
881
- function next(p) {
882
- function go() {
883
- if (p === promise) {
884
- fulfil(signal);
885
- } else {
886
- next(promise);
887
- }
888
- }
889
- p.then(go, go);
890
- }
891
- next(promise);
892
- });
893
- }
894
- // @__NO_SIDE_EFFECTS__
895
- function user_derived(fn) {
896
- const d = /* @__PURE__ */ derived(fn);
897
- push_reaction_value(d);
898
- return d;
899
- }
900
- // @__NO_SIDE_EFFECTS__
901
- function derived_safe_equal(fn) {
902
- const signal = /* @__PURE__ */ derived(fn);
903
- signal.equals = safe_equals;
904
- return signal;
905
- }
906
- function destroy_derived_effects(derived2) {
907
- var effects = derived2.effects;
908
- if (effects !== null) {
909
- derived2.effects = null;
910
- for (var i = 0; i < effects.length; i += 1) {
911
- destroy_effect(
912
- /** @type {Effect} */
913
- effects[i]
914
- );
915
- }
916
- }
917
- }
918
- function get_derived_parent_effect(derived2) {
919
- var parent = derived2.parent;
920
- while (parent !== null) {
921
- if ((parent.f & DERIVED) === 0) {
922
- return (parent.f & DESTROYED) === 0 ? (
923
- /** @type {Effect} */
924
- parent
925
- ) : null;
926
- }
927
- parent = parent.parent;
928
- }
929
- return null;
930
- }
931
- function execute_derived(derived2) {
932
- var value;
933
- var prev_active_effect = active_effect;
934
- set_active_effect(get_derived_parent_effect(derived2));
935
- {
936
- try {
937
- derived2.f &= ~WAS_MARKED;
938
- destroy_derived_effects(derived2);
939
- value = update_reaction(derived2);
940
- } finally {
941
- set_active_effect(prev_active_effect);
942
- }
943
- }
944
- return value;
945
- }
946
- function update_derived(derived2) {
947
- var value = execute_derived(derived2);
948
- if (!derived2.equals(value)) {
949
- derived2.wv = increment_write_version();
950
- if (!(current_batch == null ? void 0 : current_batch.is_fork) || derived2.deps === null) {
951
- derived2.v = value;
952
- if (derived2.deps === null) {
953
- set_signal_status(derived2, CLEAN);
954
- return;
955
- }
956
- }
957
- }
958
- if (is_destroying_effect) {
959
- return;
960
- }
961
- if (batch_values !== null) {
962
- if (effect_tracking() || (current_batch == null ? void 0 : current_batch.is_fork)) {
963
- batch_values.set(derived2, value);
964
- }
965
- } else {
966
- update_derived_status(derived2);
967
- }
968
- }
969
- let eager_effects = /* @__PURE__ */ new Set();
970
- const old_values = /* @__PURE__ */ new Map();
971
- let eager_effects_deferred = false;
972
- function source(v, stack) {
973
- var signal = {
974
- f: 0,
975
- // TODO ideally we could skip this altogether, but it causes type errors
976
- v,
977
- reactions: null,
978
- equals,
979
- rv: 0,
980
- wv: 0
981
- };
982
- return signal;
983
- }
984
- // @__NO_SIDE_EFFECTS__
985
- function state(v, stack) {
986
- const s = source(v);
987
- push_reaction_value(s);
988
- return s;
989
- }
990
- function set(source2, value, should_proxy = false) {
991
- if (active_reaction !== null && // since we are untracking the function inside `$inspect.with` we need to add this check
992
- // to ensure we error if state is set inside an inspect effect
993
- (!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))) {
994
- state_unsafe_mutation();
995
- }
996
- let new_value = should_proxy ? proxy(value) : value;
997
- return internal_set(source2, new_value);
998
- }
999
- function internal_set(source2, value) {
1000
- if (!source2.equals(value)) {
1001
- var old_value = source2.v;
1002
- if (is_destroying_effect) {
1003
- old_values.set(source2, value);
1004
- } else {
1005
- old_values.set(source2, old_value);
1006
- }
1007
- source2.v = value;
1008
- var batch = Batch.ensure();
1009
- batch.capture(source2, old_value);
1010
- if ((source2.f & DERIVED) !== 0) {
1011
- const derived2 = (
1012
- /** @type {Derived} */
1013
- source2
1014
- );
1015
- if ((source2.f & DIRTY) !== 0) {
1016
- execute_derived(derived2);
1017
- }
1018
- update_derived_status(derived2);
1019
- }
1020
- source2.wv = increment_write_version();
1021
- mark_reactions(source2, DIRTY);
1022
- if (active_effect !== null && (active_effect.f & CLEAN) !== 0 && (active_effect.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0) {
1023
- if (untracked_writes === null) {
1024
- set_untracked_writes([source2]);
1025
- } else {
1026
- untracked_writes.push(source2);
1027
- }
1028
- }
1029
- if (!batch.is_fork && eager_effects.size > 0 && !eager_effects_deferred) {
1030
- flush_eager_effects();
1031
- }
1032
- }
1033
- return value;
1034
- }
1035
- function flush_eager_effects() {
1036
- eager_effects_deferred = false;
1037
- var prev_is_updating_effect = is_updating_effect;
1038
- set_is_updating_effect(true);
1039
- const inspects = Array.from(eager_effects);
1040
- try {
1041
- for (const effect2 of inspects) {
1042
- if ((effect2.f & CLEAN) !== 0) {
1043
- set_signal_status(effect2, MAYBE_DIRTY);
1044
- }
1045
- if (is_dirty(effect2)) {
1046
- update_effect(effect2);
1047
- }
1048
- }
1049
- } finally {
1050
- set_is_updating_effect(prev_is_updating_effect);
1051
- }
1052
- eager_effects.clear();
1053
- }
1054
- function increment(source2) {
1055
- set(source2, source2.v + 1);
1056
- }
1057
- function mark_reactions(signal, status) {
1058
- var reactions = signal.reactions;
1059
- if (reactions === null) return;
1060
- var length = reactions.length;
1061
- for (var i = 0; i < length; i++) {
1062
- var reaction = reactions[i];
1063
- var flags = reaction.f;
1064
- var not_dirty = (flags & DIRTY) === 0;
1065
- if (not_dirty) {
1066
- set_signal_status(reaction, status);
1067
- }
1068
- if ((flags & DERIVED) !== 0) {
1069
- var derived2 = (
1070
- /** @type {Derived} */
1071
- reaction
1072
- );
1073
- batch_values == null ? void 0 : batch_values.delete(derived2);
1074
- if ((flags & WAS_MARKED) === 0) {
1075
- if (flags & CONNECTED) {
1076
- reaction.f |= WAS_MARKED;
1077
- }
1078
- mark_reactions(derived2, MAYBE_DIRTY);
1079
- }
1080
- } else if (not_dirty) {
1081
- if ((flags & BLOCK_EFFECT) !== 0 && eager_block_effects !== null) {
1082
- eager_block_effects.add(
1083
- /** @type {Effect} */
1084
- reaction
1085
- );
1086
- }
1087
- schedule_effect(
1088
- /** @type {Effect} */
1089
- reaction
1090
- );
1091
- }
1092
- }
1093
- }
1094
- function proxy(value) {
1095
- if (typeof value !== "object" || value === null || STATE_SYMBOL in value) {
1096
- return value;
1097
- }
1098
- const prototype = get_prototype_of(value);
1099
- if (prototype !== object_prototype && prototype !== array_prototype) {
1100
- return value;
1101
- }
1102
- var sources = /* @__PURE__ */ new Map();
1103
- var is_proxied_array = is_array(value);
1104
- var version = /* @__PURE__ */ state(0);
1105
- var parent_version = update_version;
1106
- var with_parent = (fn) => {
1107
- if (update_version === parent_version) {
1108
- return fn();
1109
- }
1110
- var reaction = active_reaction;
1111
- var version2 = update_version;
1112
- set_active_reaction(null);
1113
- set_update_version(parent_version);
1114
- var result = fn();
1115
- set_active_reaction(reaction);
1116
- set_update_version(version2);
1117
- return result;
1118
- };
1119
- if (is_proxied_array) {
1120
- sources.set("length", /* @__PURE__ */ state(
1121
- /** @type {any[]} */
1122
- value.length
1123
- ));
1124
- }
1125
- return new Proxy(
1126
- /** @type {any} */
1127
- value,
1128
- {
1129
- defineProperty(_, prop2, descriptor) {
1130
- if (!("value" in descriptor) || descriptor.configurable === false || descriptor.enumerable === false || descriptor.writable === false) {
1131
- state_descriptors_fixed();
1132
- }
1133
- var s = sources.get(prop2);
1134
- if (s === void 0) {
1135
- s = with_parent(() => {
1136
- var s2 = /* @__PURE__ */ state(descriptor.value);
1137
- sources.set(prop2, s2);
1138
- return s2;
1139
- });
1140
- } else {
1141
- set(s, descriptor.value, true);
1142
- }
1143
- return true;
1144
- },
1145
- deleteProperty(target, prop2) {
1146
- var s = sources.get(prop2);
1147
- if (s === void 0) {
1148
- if (prop2 in target) {
1149
- const s2 = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
1150
- sources.set(prop2, s2);
1151
- increment(version);
1152
- }
1153
- } else {
1154
- set(s, UNINITIALIZED);
1155
- increment(version);
1156
- }
1157
- return true;
1158
- },
1159
- get(target, prop2, receiver) {
1160
- var _a2;
1161
- if (prop2 === STATE_SYMBOL) {
1162
- return value;
1163
- }
1164
- var s = sources.get(prop2);
1165
- var exists = prop2 in target;
1166
- if (s === void 0 && (!exists || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable))) {
1167
- s = with_parent(() => {
1168
- var p = proxy(exists ? target[prop2] : UNINITIALIZED);
1169
- var s2 = /* @__PURE__ */ state(p);
1170
- return s2;
1171
- });
1172
- sources.set(prop2, s);
1173
- }
1174
- if (s !== void 0) {
1175
- var v = get(s);
1176
- return v === UNINITIALIZED ? void 0 : v;
1177
- }
1178
- return Reflect.get(target, prop2, receiver);
1179
- },
1180
- getOwnPropertyDescriptor(target, prop2) {
1181
- var descriptor = Reflect.getOwnPropertyDescriptor(target, prop2);
1182
- if (descriptor && "value" in descriptor) {
1183
- var s = sources.get(prop2);
1184
- if (s) descriptor.value = get(s);
1185
- } else if (descriptor === void 0) {
1186
- var source2 = sources.get(prop2);
1187
- var value2 = source2 == null ? void 0 : source2.v;
1188
- if (source2 !== void 0 && value2 !== UNINITIALIZED) {
1189
- return {
1190
- enumerable: true,
1191
- configurable: true,
1192
- value: value2,
1193
- writable: true
1194
- };
1195
- }
1196
- }
1197
- return descriptor;
1198
- },
1199
- has(target, prop2) {
1200
- var _a2;
1201
- if (prop2 === STATE_SYMBOL) {
1202
- return true;
1203
- }
1204
- var s = sources.get(prop2);
1205
- var has = s !== void 0 && s.v !== UNINITIALIZED || Reflect.has(target, prop2);
1206
- if (s !== void 0 || active_effect !== null && (!has || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable))) {
1207
- if (s === void 0) {
1208
- s = with_parent(() => {
1209
- var p = has ? proxy(target[prop2]) : UNINITIALIZED;
1210
- var s2 = /* @__PURE__ */ state(p);
1211
- return s2;
1212
- });
1213
- sources.set(prop2, s);
1214
- }
1215
- var value2 = get(s);
1216
- if (value2 === UNINITIALIZED) {
1217
- return false;
1218
- }
1219
- }
1220
- return has;
1221
- },
1222
- set(target, prop2, value2, receiver) {
1223
- var _a2;
1224
- var s = sources.get(prop2);
1225
- var has = prop2 in target;
1226
- if (is_proxied_array && prop2 === "length") {
1227
- for (var i = value2; i < /** @type {Source<number>} */
1228
- s.v; i += 1) {
1229
- var other_s = sources.get(i + "");
1230
- if (other_s !== void 0) {
1231
- set(other_s, UNINITIALIZED);
1232
- } else if (i in target) {
1233
- other_s = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
1234
- sources.set(i + "", other_s);
1235
- }
1236
- }
1237
- }
1238
- if (s === void 0) {
1239
- if (!has || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable)) {
1240
- s = with_parent(() => /* @__PURE__ */ state(void 0));
1241
- set(s, proxy(value2));
1242
- sources.set(prop2, s);
1243
- }
1244
- } else {
1245
- has = s.v !== UNINITIALIZED;
1246
- var p = with_parent(() => proxy(value2));
1247
- set(s, p);
1248
- }
1249
- var descriptor = Reflect.getOwnPropertyDescriptor(target, prop2);
1250
- if (descriptor == null ? void 0 : descriptor.set) {
1251
- descriptor.set.call(receiver, value2);
1252
- }
1253
- if (!has) {
1254
- if (is_proxied_array && typeof prop2 === "string") {
1255
- var ls = (
1256
- /** @type {Source<number>} */
1257
- sources.get("length")
1258
- );
1259
- var n = Number(prop2);
1260
- if (Number.isInteger(n) && n >= ls.v) {
1261
- set(ls, n + 1);
1262
- }
1263
- }
1264
- increment(version);
1265
- }
1266
- return true;
1267
- },
1268
- ownKeys(target) {
1269
- get(version);
1270
- var own_keys = Reflect.ownKeys(target).filter((key2) => {
1271
- var source3 = sources.get(key2);
1272
- return source3 === void 0 || source3.v !== UNINITIALIZED;
1273
- });
1274
- for (var [key, source2] of sources) {
1275
- if (source2.v !== UNINITIALIZED && !(key in target)) {
1276
- own_keys.push(key);
1277
- }
1278
- }
1279
- return own_keys;
1280
- },
1281
- setPrototypeOf() {
1282
- state_prototype_fixed();
1283
- }
1284
- }
1285
- );
1286
- }
1287
- var is_firefox;
1288
- var first_child_getter;
1289
- var next_sibling_getter;
1290
- function create_text(value = "") {
1291
- return document.createTextNode(value);
1292
- }
1293
- // @__NO_SIDE_EFFECTS__
1294
- function get_first_child(node) {
1295
- return (
1296
- /** @type {TemplateNode | null} */
1297
- first_child_getter.call(node)
1298
- );
1299
- }
1300
- // @__NO_SIDE_EFFECTS__
1301
- function get_next_sibling(node) {
1302
- return (
1303
- /** @type {TemplateNode | null} */
1304
- next_sibling_getter.call(node)
1305
- );
1306
- }
1307
- function child(node, is_text) {
1308
- {
1309
- return /* @__PURE__ */ get_first_child(node);
1310
- }
1311
- }
1312
- function first_child(node, is_text = false) {
1313
- {
1314
- var first = /* @__PURE__ */ get_first_child(node);
1315
- if (first instanceof Comment && first.data === "") return /* @__PURE__ */ get_next_sibling(first);
1316
- return first;
1317
- }
1318
- }
1319
- function sibling(node, count = 1, is_text = false) {
1320
- let next_sibling = node;
1321
- while (count--) {
1322
- next_sibling = /** @type {TemplateNode} */
1323
- /* @__PURE__ */ get_next_sibling(next_sibling);
1324
- }
1325
- {
1326
- return next_sibling;
1327
- }
1328
- }
1329
- function should_defer_append() {
1330
- return false;
1331
- }
1332
- function without_reactive_context(fn) {
1333
- var previous_reaction = active_reaction;
1334
- var previous_effect = active_effect;
1335
- set_active_reaction(null);
1336
- set_active_effect(null);
1337
- try {
1338
- return fn();
1339
- } finally {
1340
- set_active_reaction(previous_reaction);
1341
- set_active_effect(previous_effect);
1342
- }
1343
- }
1344
- function validate_effect(rune) {
1345
- if (active_effect === null) {
1346
- if (active_reaction === null) {
1347
- effect_orphan();
1348
- }
1349
- effect_in_unowned_derived();
1350
- }
1351
- if (is_destroying_effect) {
1352
- effect_in_teardown();
1353
- }
1354
- }
1355
- function push_effect(effect2, parent_effect) {
1356
- var parent_last = parent_effect.last;
1357
- if (parent_last === null) {
1358
- parent_effect.last = parent_effect.first = effect2;
1359
- } else {
1360
- parent_last.next = effect2;
1361
- effect2.prev = parent_last;
1362
- parent_effect.last = effect2;
1363
- }
1364
- }
1365
- function create_effect(type, fn, sync) {
1366
- var parent = active_effect;
1367
- if (parent !== null && (parent.f & INERT) !== 0) {
1368
- type |= INERT;
1369
- }
1370
- var effect2 = {
1371
- ctx: component_context,
1372
- deps: null,
1373
- nodes: null,
1374
- f: type | DIRTY | CONNECTED,
1375
- first: null,
1376
- fn,
1377
- last: null,
1378
- next: null,
1379
- parent,
1380
- b: parent && parent.b,
1381
- prev: null,
1382
- teardown: null,
1383
- wv: 0,
1384
- ac: null
1385
- };
1386
- if (sync) {
1387
- try {
1388
- update_effect(effect2);
1389
- effect2.f |= EFFECT_RAN;
1390
- } catch (e2) {
1391
- destroy_effect(effect2);
1392
- throw e2;
1393
- }
1394
- } else if (fn !== null) {
1395
- schedule_effect(effect2);
1396
- }
1397
- var e = effect2;
1398
- if (sync && e.deps === null && e.teardown === null && e.nodes === null && e.first === e.last && // either `null`, or a singular child
1399
- (e.f & EFFECT_PRESERVED) === 0) {
1400
- e = e.first;
1401
- if ((type & BLOCK_EFFECT) !== 0 && (type & EFFECT_TRANSPARENT) !== 0 && e !== null) {
1402
- e.f |= EFFECT_TRANSPARENT;
1403
- }
1404
- }
1405
- if (e !== null) {
1406
- e.parent = parent;
1407
- if (parent !== null) {
1408
- push_effect(e, parent);
1409
- }
1410
- if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0 && (type & ROOT_EFFECT) === 0) {
1411
- var derived2 = (
1412
- /** @type {Derived} */
1413
- active_reaction
1414
- );
1415
- (derived2.effects ?? (derived2.effects = [])).push(e);
1416
- }
1417
- }
1418
- return effect2;
1419
- }
1420
- function effect_tracking() {
1421
- return active_reaction !== null && !untracking;
1422
- }
1423
- function teardown(fn) {
1424
- const effect2 = create_effect(RENDER_EFFECT, null, false);
1425
- set_signal_status(effect2, CLEAN);
1426
- effect2.teardown = fn;
1427
- return effect2;
1428
- }
1429
- function user_effect(fn) {
1430
- validate_effect();
1431
- var flags = (
1432
- /** @type {Effect} */
1433
- active_effect.f
1434
- );
1435
- var defer = !active_reaction && (flags & BRANCH_EFFECT) !== 0 && (flags & EFFECT_RAN) === 0;
1436
- if (defer) {
1437
- var context = (
1438
- /** @type {ComponentContext} */
1439
- component_context
1440
- );
1441
- (context.e ?? (context.e = [])).push(fn);
1442
- } else {
1443
- return create_user_effect(fn);
1444
- }
1445
- }
1446
- function create_user_effect(fn) {
1447
- return create_effect(EFFECT | USER_EFFECT, fn, false);
1448
- }
1449
- function effect(fn) {
1450
- return create_effect(EFFECT, fn, false);
1451
- }
1452
- function async_effect(fn) {
1453
- return create_effect(ASYNC | EFFECT_PRESERVED, fn, true);
1454
- }
1455
- function render_effect(fn, flags = 0) {
1456
- return create_effect(RENDER_EFFECT | flags, fn, true);
1457
- }
1458
- function template_effect(fn, sync = [], async = [], blockers = []) {
1459
- flatten(blockers, sync, async, (values) => {
1460
- create_effect(RENDER_EFFECT, () => fn(...values.map(get)), true);
1461
- });
1462
- }
1463
- function block(fn, flags = 0) {
1464
- var effect2 = create_effect(BLOCK_EFFECT | flags, fn, true);
1465
- return effect2;
1466
- }
1467
- function branch(fn) {
1468
- return create_effect(BRANCH_EFFECT | EFFECT_PRESERVED, fn, true);
1469
- }
1470
- function execute_effect_teardown(effect2) {
1471
- var teardown2 = effect2.teardown;
1472
- if (teardown2 !== null) {
1473
- const previously_destroying_effect = is_destroying_effect;
1474
- const previous_reaction = active_reaction;
1475
- set_is_destroying_effect(true);
1476
- set_active_reaction(null);
1477
- try {
1478
- teardown2.call(null);
1479
- } finally {
1480
- set_is_destroying_effect(previously_destroying_effect);
1481
- set_active_reaction(previous_reaction);
1482
- }
1483
- }
1484
- }
1485
- function destroy_effect_children(signal, remove_dom = false) {
1486
- var effect2 = signal.first;
1487
- signal.first = signal.last = null;
1488
- while (effect2 !== null) {
1489
- const controller = effect2.ac;
1490
- if (controller !== null) {
1491
- without_reactive_context(() => {
1492
- controller.abort(STALE_REACTION);
1493
- });
1494
- }
1495
- var next = effect2.next;
1496
- if ((effect2.f & ROOT_EFFECT) !== 0) {
1497
- effect2.parent = null;
1498
- } else {
1499
- destroy_effect(effect2, remove_dom);
1500
- }
1501
- effect2 = next;
1502
- }
1503
- }
1504
- function destroy_block_effect_children(signal) {
1505
- var effect2 = signal.first;
1506
- while (effect2 !== null) {
1507
- var next = effect2.next;
1508
- if ((effect2.f & BRANCH_EFFECT) === 0) {
1509
- destroy_effect(effect2);
1510
- }
1511
- effect2 = next;
1512
- }
1513
- }
1514
- function destroy_effect(effect2, remove_dom = true) {
1515
- var removed = false;
1516
- if ((remove_dom || (effect2.f & HEAD_EFFECT) !== 0) && effect2.nodes !== null && effect2.nodes.end !== null) {
1517
- remove_effect_dom(
1518
- effect2.nodes.start,
1519
- /** @type {TemplateNode} */
1520
- effect2.nodes.end
1521
- );
1522
- removed = true;
1523
- }
1524
- destroy_effect_children(effect2, remove_dom && !removed);
1525
- remove_reactions(effect2, 0);
1526
- set_signal_status(effect2, DESTROYED);
1527
- var transitions = effect2.nodes && effect2.nodes.t;
1528
- if (transitions !== null) {
1529
- for (const transition of transitions) {
1530
- transition.stop();
1531
- }
1532
- }
1533
- execute_effect_teardown(effect2);
1534
- var parent = effect2.parent;
1535
- if (parent !== null && parent.first !== null) {
1536
- unlink_effect(effect2);
1537
- }
1538
- effect2.next = effect2.prev = effect2.teardown = effect2.ctx = effect2.deps = effect2.fn = effect2.nodes = effect2.ac = null;
1539
- }
1540
- function remove_effect_dom(node, end) {
1541
- while (node !== null) {
1542
- var next = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
1543
- node.remove();
1544
- node = next;
1545
- }
1546
- }
1547
- function unlink_effect(effect2) {
1548
- var parent = effect2.parent;
1549
- var prev = effect2.prev;
1550
- var next = effect2.next;
1551
- if (prev !== null) prev.next = next;
1552
- if (next !== null) next.prev = prev;
1553
- if (parent !== null) {
1554
- if (parent.first === effect2) parent.first = next;
1555
- if (parent.last === effect2) parent.last = prev;
1556
- }
1557
- }
1558
- function pause_effect(effect2, callback, destroy = true) {
1559
- var transitions = [];
1560
- pause_children(effect2, transitions, true);
1561
- var fn = () => {
1562
- if (destroy) destroy_effect(effect2);
1563
- if (callback) callback();
1564
- };
1565
- var remaining = transitions.length;
1566
- if (remaining > 0) {
1567
- var check = () => --remaining || fn();
1568
- for (var transition of transitions) {
1569
- transition.out(check);
1570
- }
1571
- } else {
1572
- fn();
1573
- }
1574
- }
1575
- function pause_children(effect2, transitions, local) {
1576
- if ((effect2.f & INERT) !== 0) return;
1577
- effect2.f ^= INERT;
1578
- var t = effect2.nodes && effect2.nodes.t;
1579
- if (t !== null) {
1580
- for (const transition of t) {
1581
- if (transition.is_global || local) {
1582
- transitions.push(transition);
1583
- }
1584
- }
1585
- }
1586
- var child2 = effect2.first;
1587
- while (child2 !== null) {
1588
- var sibling2 = child2.next;
1589
- var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || // If this is a branch effect without a block effect parent,
1590
- // it means the parent block effect was pruned. In that case,
1591
- // transparency information was transferred to the branch effect.
1592
- (child2.f & BRANCH_EFFECT) !== 0 && (effect2.f & BLOCK_EFFECT) !== 0;
1593
- pause_children(child2, transitions, transparent ? local : false);
1594
- child2 = sibling2;
1595
- }
1596
- }
1597
- function resume_effect(effect2) {
1598
- resume_children(effect2, true);
1599
- }
1600
- function resume_children(effect2, local) {
1601
- if ((effect2.f & INERT) === 0) return;
1602
- effect2.f ^= INERT;
1603
- if ((effect2.f & CLEAN) === 0) {
1604
- set_signal_status(effect2, DIRTY);
1605
- schedule_effect(effect2);
1606
- }
1607
- var child2 = effect2.first;
1608
- while (child2 !== null) {
1609
- var sibling2 = child2.next;
1610
- var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || (child2.f & BRANCH_EFFECT) !== 0;
1611
- resume_children(child2, transparent ? local : false);
1612
- child2 = sibling2;
1613
- }
1614
- var t = effect2.nodes && effect2.nodes.t;
1615
- if (t !== null) {
1616
- for (const transition of t) {
1617
- if (transition.is_global || local) {
1618
- transition.in();
1619
- }
1620
- }
1621
- }
1622
- }
1623
- function move_effect(effect2, fragment) {
1624
- if (!effect2.nodes) return;
1625
- var node = effect2.nodes.start;
1626
- var end = effect2.nodes.end;
1627
- while (node !== null) {
1628
- var next = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
1629
- fragment.append(node);
1630
- node = next;
1631
- }
1632
- }
1633
- let is_updating_effect = false;
1634
- function set_is_updating_effect(value) {
1635
- is_updating_effect = value;
1636
- }
1637
- let is_destroying_effect = false;
1638
- function set_is_destroying_effect(value) {
1639
- is_destroying_effect = value;
1640
- }
1641
- let active_reaction = null;
1642
- let untracking = false;
1643
- function set_active_reaction(reaction) {
1644
- active_reaction = reaction;
1645
- }
1646
- let active_effect = null;
1647
- function set_active_effect(effect2) {
1648
- active_effect = effect2;
1649
- }
1650
- let current_sources = null;
1651
- function push_reaction_value(value) {
1652
- if (active_reaction !== null && true) {
1653
- if (current_sources === null) {
1654
- current_sources = [value];
1655
- } else {
1656
- current_sources.push(value);
1657
- }
1658
- }
1659
- }
1660
- let new_deps = null;
1661
- let skipped_deps = 0;
1662
- let untracked_writes = null;
1663
- function set_untracked_writes(value) {
1664
- untracked_writes = value;
1665
- }
1666
- let write_version = 1;
1667
- let read_version = 0;
1668
- let update_version = read_version;
1669
- function set_update_version(value) {
1670
- update_version = value;
1671
- }
1672
- function increment_write_version() {
1673
- return ++write_version;
1674
- }
1675
- function is_dirty(reaction) {
1676
- var flags = reaction.f;
1677
- if ((flags & DIRTY) !== 0) {
1678
- return true;
1679
- }
1680
- if (flags & DERIVED) {
1681
- reaction.f &= ~WAS_MARKED;
1682
- }
1683
- if ((flags & MAYBE_DIRTY) !== 0) {
1684
- var dependencies = (
1685
- /** @type {Value[]} */
1686
- reaction.deps
1687
- );
1688
- var length = dependencies.length;
1689
- for (var i = 0; i < length; i++) {
1690
- var dependency = dependencies[i];
1691
- if (is_dirty(
1692
- /** @type {Derived} */
1693
- dependency
1694
- )) {
1695
- update_derived(
1696
- /** @type {Derived} */
1697
- dependency
1698
- );
1699
- }
1700
- if (dependency.wv > reaction.wv) {
1701
- return true;
1702
- }
1703
- }
1704
- if ((flags & CONNECTED) !== 0 && // During time traveling we don't want to reset the status so that
1705
- // traversal of the graph in the other batches still happens
1706
- batch_values === null) {
1707
- set_signal_status(reaction, CLEAN);
1708
- }
1709
- }
1710
- return false;
1711
- }
1712
- function schedule_possible_effect_self_invalidation(signal, effect2, root2 = true) {
1713
- var reactions = signal.reactions;
1714
- if (reactions === null) return;
1715
- if (current_sources == null ? void 0 : current_sources.includes(signal)) {
1716
- return;
1717
- }
1718
- for (var i = 0; i < reactions.length; i++) {
1719
- var reaction = reactions[i];
1720
- if ((reaction.f & DERIVED) !== 0) {
1721
- schedule_possible_effect_self_invalidation(
1722
- /** @type {Derived} */
1723
- reaction,
1724
- effect2,
1725
- false
1726
- );
1727
- } else if (effect2 === reaction) {
1728
- if (root2) {
1729
- set_signal_status(reaction, DIRTY);
1730
- } else if ((reaction.f & CLEAN) !== 0) {
1731
- set_signal_status(reaction, MAYBE_DIRTY);
1732
- }
1733
- schedule_effect(
1734
- /** @type {Effect} */
1735
- reaction
1736
- );
1737
- }
1738
- }
1739
- }
1740
- function update_reaction(reaction) {
1741
- var _a2;
1742
- var previous_deps = new_deps;
1743
- var previous_skipped_deps = skipped_deps;
1744
- var previous_untracked_writes = untracked_writes;
1745
- var previous_reaction = active_reaction;
1746
- var previous_sources = current_sources;
1747
- var previous_component_context = component_context;
1748
- var previous_untracking = untracking;
1749
- var previous_update_version = update_version;
1750
- var flags = reaction.f;
1751
- new_deps = /** @type {null | Value[]} */
1752
- null;
1753
- skipped_deps = 0;
1754
- untracked_writes = null;
1755
- active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
1756
- current_sources = null;
1757
- set_component_context(reaction.ctx);
1758
- untracking = false;
1759
- update_version = ++read_version;
1760
- if (reaction.ac !== null) {
1761
- without_reactive_context(() => {
1762
- reaction.ac.abort(STALE_REACTION);
1763
- });
1764
- reaction.ac = null;
1765
- }
1766
- try {
1767
- reaction.f |= REACTION_IS_UPDATING;
1768
- var fn = (
1769
- /** @type {Function} */
1770
- reaction.fn
1771
- );
1772
- var result = fn();
1773
- var deps = reaction.deps;
1774
- if (new_deps !== null) {
1775
- var i;
1776
- remove_reactions(reaction, skipped_deps);
1777
- if (deps !== null && skipped_deps > 0) {
1778
- deps.length = skipped_deps + new_deps.length;
1779
- for (i = 0; i < new_deps.length; i++) {
1780
- deps[skipped_deps + i] = new_deps[i];
1781
- }
1782
- } else {
1783
- reaction.deps = deps = new_deps;
1784
- }
1785
- if (effect_tracking() && (reaction.f & CONNECTED) !== 0) {
1786
- for (i = skipped_deps; i < deps.length; i++) {
1787
- ((_a2 = deps[i]).reactions ?? (_a2.reactions = [])).push(reaction);
1788
- }
1789
- }
1790
- } else if (deps !== null && skipped_deps < deps.length) {
1791
- remove_reactions(reaction, skipped_deps);
1792
- deps.length = skipped_deps;
1793
- }
1794
- if (is_runes() && untracked_writes !== null && !untracking && deps !== null && (reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0) {
1795
- for (i = 0; i < /** @type {Source[]} */
1796
- untracked_writes.length; i++) {
1797
- schedule_possible_effect_self_invalidation(
1798
- untracked_writes[i],
1799
- /** @type {Effect} */
1800
- reaction
1801
- );
1802
- }
1803
- }
1804
- if (previous_reaction !== null && previous_reaction !== reaction) {
1805
- read_version++;
1806
- if (untracked_writes !== null) {
1807
- if (previous_untracked_writes === null) {
1808
- previous_untracked_writes = untracked_writes;
1809
- } else {
1810
- previous_untracked_writes.push(.../** @type {Source[]} */
1811
- untracked_writes);
1812
- }
1813
- }
1814
- }
1815
- if ((reaction.f & ERROR_VALUE) !== 0) {
1816
- reaction.f ^= ERROR_VALUE;
1817
- }
1818
- return result;
1819
- } catch (error) {
1820
- return handle_error(error);
1821
- } finally {
1822
- reaction.f ^= REACTION_IS_UPDATING;
1823
- new_deps = previous_deps;
1824
- skipped_deps = previous_skipped_deps;
1825
- untracked_writes = previous_untracked_writes;
1826
- active_reaction = previous_reaction;
1827
- current_sources = previous_sources;
1828
- set_component_context(previous_component_context);
1829
- untracking = previous_untracking;
1830
- update_version = previous_update_version;
1831
- }
1832
- }
1833
- function remove_reaction(signal, dependency) {
1834
- let reactions = dependency.reactions;
1835
- if (reactions !== null) {
1836
- var index = index_of.call(reactions, signal);
1837
- if (index !== -1) {
1838
- var new_length = reactions.length - 1;
1839
- if (new_length === 0) {
1840
- reactions = dependency.reactions = null;
1841
- } else {
1842
- reactions[index] = reactions[new_length];
1843
- reactions.pop();
1844
- }
1845
- }
1846
- }
1847
- if (reactions === null && (dependency.f & DERIVED) !== 0 && // Destroying a child effect while updating a parent effect can cause a dependency to appear
1848
- // to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps`
1849
- // allows us to skip the expensive work of disconnecting and immediately reconnecting it
1850
- (new_deps === null || !new_deps.includes(dependency))) {
1851
- var derived2 = (
1852
- /** @type {Derived} */
1853
- dependency
1854
- );
1855
- if ((derived2.f & CONNECTED) !== 0) {
1856
- derived2.f ^= CONNECTED;
1857
- derived2.f &= ~WAS_MARKED;
1858
- }
1859
- update_derived_status(derived2);
1860
- destroy_derived_effects(derived2);
1861
- remove_reactions(derived2, 0);
1862
- }
1863
- }
1864
- function remove_reactions(signal, start_index) {
1865
- var dependencies = signal.deps;
1866
- if (dependencies === null) return;
1867
- for (var i = start_index; i < dependencies.length; i++) {
1868
- remove_reaction(signal, dependencies[i]);
1869
- }
1870
- }
1871
- function update_effect(effect2) {
1872
- var flags = effect2.f;
1873
- if ((flags & DESTROYED) !== 0) {
1874
- return;
1875
- }
1876
- set_signal_status(effect2, CLEAN);
1877
- var previous_effect = active_effect;
1878
- var was_updating_effect = is_updating_effect;
1879
- active_effect = effect2;
1880
- is_updating_effect = true;
1881
- try {
1882
- if ((flags & (BLOCK_EFFECT | MANAGED_EFFECT)) !== 0) {
1883
- destroy_block_effect_children(effect2);
1884
- } else {
1885
- destroy_effect_children(effect2);
1886
- }
1887
- execute_effect_teardown(effect2);
1888
- var teardown2 = update_reaction(effect2);
1889
- effect2.teardown = typeof teardown2 === "function" ? teardown2 : null;
1890
- effect2.wv = write_version;
1891
- var dep;
1892
- if (DEV && tracing_mode_flag && (effect2.f & DIRTY) !== 0 && effect2.deps !== null) ;
1893
- } finally {
1894
- is_updating_effect = was_updating_effect;
1895
- active_effect = previous_effect;
1896
- }
1897
- }
1898
- function get(signal) {
1899
- var flags = signal.f;
1900
- var is_derived = (flags & DERIVED) !== 0;
1901
- if (active_reaction !== null && !untracking) {
1902
- var destroyed = active_effect !== null && (active_effect.f & DESTROYED) !== 0;
1903
- if (!destroyed && !(current_sources == null ? void 0 : current_sources.includes(signal))) {
1904
- var deps = active_reaction.deps;
1905
- if ((active_reaction.f & REACTION_IS_UPDATING) !== 0) {
1906
- if (signal.rv < read_version) {
1907
- signal.rv = read_version;
1908
- if (new_deps === null && deps !== null && deps[skipped_deps] === signal) {
1909
- skipped_deps++;
1910
- } else if (new_deps === null) {
1911
- new_deps = [signal];
1912
- } else if (!new_deps.includes(signal)) {
1913
- new_deps.push(signal);
1914
- }
1915
- }
1916
- } else {
1917
- (active_reaction.deps ?? (active_reaction.deps = [])).push(signal);
1918
- var reactions = signal.reactions;
1919
- if (reactions === null) {
1920
- signal.reactions = [active_reaction];
1921
- } else if (!reactions.includes(active_reaction)) {
1922
- reactions.push(active_reaction);
1923
- }
1924
- }
1925
- }
1926
- }
1927
- if (is_destroying_effect && old_values.has(signal)) {
1928
- return old_values.get(signal);
1929
- }
1930
- if (is_derived) {
1931
- var derived2 = (
1932
- /** @type {Derived} */
1933
- signal
1934
- );
1935
- if (is_destroying_effect) {
1936
- var value = derived2.v;
1937
- if ((derived2.f & CLEAN) === 0 && derived2.reactions !== null || depends_on_old_values(derived2)) {
1938
- value = execute_derived(derived2);
1939
- }
1940
- old_values.set(derived2, value);
1941
- return value;
1942
- }
1943
- var should_connect = (derived2.f & CONNECTED) === 0 && !untracking && active_reaction !== null && (is_updating_effect || (active_reaction.f & CONNECTED) !== 0);
1944
- var is_new = derived2.deps === null;
1945
- if (is_dirty(derived2)) {
1946
- if (should_connect) {
1947
- derived2.f |= CONNECTED;
1948
- }
1949
- update_derived(derived2);
1950
- }
1951
- if (should_connect && !is_new) {
1952
- reconnect(derived2);
1953
- }
1954
- }
1955
- if (batch_values == null ? void 0 : batch_values.has(signal)) {
1956
- return batch_values.get(signal);
1957
- }
1958
- if ((signal.f & ERROR_VALUE) !== 0) {
1959
- throw signal.v;
1960
- }
1961
- return signal.v;
1962
- }
1963
- function reconnect(derived2) {
1964
- if (derived2.deps === null) return;
1965
- derived2.f |= CONNECTED;
1966
- for (const dep of derived2.deps) {
1967
- (dep.reactions ?? (dep.reactions = [])).push(derived2);
1968
- if ((dep.f & DERIVED) !== 0 && (dep.f & CONNECTED) === 0) {
1969
- reconnect(
1970
- /** @type {Derived} */
1971
- dep
1972
- );
1973
- }
1974
- }
1975
- }
1976
- function depends_on_old_values(derived2) {
1977
- if (derived2.v === UNINITIALIZED) return true;
1978
- if (derived2.deps === null) return false;
1979
- for (const dep of derived2.deps) {
1980
- if (old_values.has(dep)) {
1981
- return true;
1982
- }
1983
- if ((dep.f & DERIVED) !== 0 && depends_on_old_values(
1984
- /** @type {Derived} */
1985
- dep
1986
- )) {
1987
- return true;
1988
- }
1989
- }
1990
- return false;
1991
- }
1992
- function untrack(fn) {
1993
- var previous_untracking = untracking;
1994
- try {
1995
- untracking = true;
1996
- return fn();
1997
- } finally {
1998
- untracking = previous_untracking;
1999
- }
2000
- }
2001
- function create_event(event_name, dom, handler, options = {}) {
2002
- function target_handler(event2) {
2003
- if (!options.capture) {
2004
- handle_event_propagation.call(dom, event2);
2005
- }
2006
- if (!event2.cancelBubble) {
2007
- return without_reactive_context(() => {
2008
- return handler == null ? void 0 : handler.call(this, event2);
2009
- });
2010
- }
2011
- }
2012
- if (event_name.startsWith("pointer") || event_name.startsWith("touch") || event_name === "wheel") {
2013
- queue_micro_task(() => {
2014
- dom.addEventListener(event_name, target_handler, options);
2015
- });
2016
- } else {
2017
- dom.addEventListener(event_name, target_handler, options);
2018
- }
2019
- return target_handler;
2020
- }
2021
- function event(event_name, dom, handler, capture2, passive) {
2022
- var options = { capture: capture2, passive };
2023
- var target_handler = create_event(event_name, dom, handler, options);
2024
- if (dom === document.body || // @ts-ignore
2025
- dom === window || // @ts-ignore
2026
- dom === document || // Firefox has quirky behavior, it can happen that we still get "canplay" events when the element is already removed
2027
- dom instanceof HTMLMediaElement) {
2028
- teardown(() => {
2029
- dom.removeEventListener(event_name, target_handler, options);
2030
- });
2031
- }
2032
- }
2033
- let last_propagated_event = null;
2034
- function handle_event_propagation(event2) {
2035
- var _a2;
2036
- var handler_element = this;
2037
- var owner_document = (
2038
- /** @type {Node} */
2039
- handler_element.ownerDocument
2040
- );
2041
- var event_name = event2.type;
2042
- var path = ((_a2 = event2.composedPath) == null ? void 0 : _a2.call(event2)) || [];
2043
- var current_target = (
2044
- /** @type {null | Element} */
2045
- path[0] || event2.target
2046
- );
2047
- last_propagated_event = event2;
2048
- var path_idx = 0;
2049
- var handled_at = last_propagated_event === event2 && event2.__root;
2050
- if (handled_at) {
2051
- var at_idx = path.indexOf(handled_at);
2052
- if (at_idx !== -1 && (handler_element === document || handler_element === /** @type {any} */
2053
- window)) {
2054
- event2.__root = handler_element;
2055
- return;
2056
- }
2057
- var handler_idx = path.indexOf(handler_element);
2058
- if (handler_idx === -1) {
2059
- return;
2060
- }
2061
- if (at_idx <= handler_idx) {
2062
- path_idx = at_idx;
2063
- }
2064
- }
2065
- current_target = /** @type {Element} */
2066
- path[path_idx] || event2.target;
2067
- if (current_target === handler_element) return;
2068
- define_property(event2, "currentTarget", {
2069
- configurable: true,
2070
- get() {
2071
- return current_target || owner_document;
2072
- }
2073
- });
2074
- var previous_reaction = active_reaction;
2075
- var previous_effect = active_effect;
2076
- set_active_reaction(null);
2077
- set_active_effect(null);
2078
- try {
2079
- var throw_error;
2080
- var other_errors = [];
2081
- while (current_target !== null) {
2082
- var parent_element = current_target.assignedSlot || current_target.parentNode || /** @type {any} */
2083
- current_target.host || null;
2084
- try {
2085
- var delegated = current_target["__" + event_name];
2086
- if (delegated != null && (!/** @type {any} */
2087
- current_target.disabled || // DOM could've been updated already by the time this is reached, so we check this as well
2088
- // -> the target could not have been disabled because it emits the event in the first place
2089
- event2.target === current_target)) {
2090
- delegated.call(current_target, event2);
2091
- }
2092
- } catch (error) {
2093
- if (throw_error) {
2094
- other_errors.push(error);
2095
- } else {
2096
- throw_error = error;
2097
- }
2098
- }
2099
- if (event2.cancelBubble || parent_element === handler_element || parent_element === null) {
2100
- break;
2101
- }
2102
- current_target = parent_element;
2103
- }
2104
- if (throw_error) {
2105
- for (let error of other_errors) {
2106
- queueMicrotask(() => {
2107
- throw error;
2108
- });
2109
- }
2110
- throw throw_error;
2111
- }
2112
- } finally {
2113
- event2.__root = handler_element;
2114
- delete event2.currentTarget;
2115
- set_active_reaction(previous_reaction);
2116
- set_active_effect(previous_effect);
2117
- }
2118
- }
2119
- function create_fragment_from_html(html) {
2120
- var elem = document.createElement("template");
2121
- elem.innerHTML = html.replaceAll("<!>", "<!---->");
2122
- return elem.content;
2123
- }
2124
- function assign_nodes(start, end) {
2125
- var effect2 = (
2126
- /** @type {Effect} */
2127
- active_effect
2128
- );
2129
- if (effect2.nodes === null) {
2130
- effect2.nodes = { start, end, a: null, t: null };
2131
- }
2132
- }
2133
- // @__NO_SIDE_EFFECTS__
2134
- function from_html(content, flags) {
2135
- var is_fragment = (flags & TEMPLATE_FRAGMENT) !== 0;
2136
- var use_import_node = (flags & TEMPLATE_USE_IMPORT_NODE) !== 0;
2137
- var node;
2138
- var has_start = !content.startsWith("<!>");
2139
- return () => {
2140
- if (node === void 0) {
2141
- node = create_fragment_from_html(has_start ? content : "<!>" + content);
2142
- if (!is_fragment) node = /** @type {TemplateNode} */
2143
- /* @__PURE__ */ get_first_child(node);
2144
- }
2145
- var clone = (
2146
- /** @type {TemplateNode} */
2147
- use_import_node || is_firefox ? document.importNode(node, true) : node.cloneNode(true)
2148
- );
2149
- if (is_fragment) {
2150
- var start = (
2151
- /** @type {TemplateNode} */
2152
- /* @__PURE__ */ get_first_child(clone)
2153
- );
2154
- var end = (
2155
- /** @type {TemplateNode} */
2156
- clone.lastChild
2157
- );
2158
- assign_nodes(start, end);
2159
- } else {
2160
- assign_nodes(clone, clone);
2161
- }
2162
- return clone;
2163
- };
2164
- }
2165
- function comment() {
2166
- var frag = document.createDocumentFragment();
2167
- var start = document.createComment("");
2168
- var anchor = create_text();
2169
- frag.append(start, anchor);
2170
- assign_nodes(start, anchor);
2171
- return frag;
2172
- }
2173
- function append(anchor, dom) {
2174
- if (anchor === null) {
2175
- return;
2176
- }
2177
- anchor.before(
2178
- /** @type {Node} */
2179
- dom
2180
- );
2181
- }
2182
- function set_text(text, value) {
2183
- var str = value == null ? "" : typeof value === "object" ? value + "" : value;
2184
- if (str !== (text.__t ?? (text.__t = text.nodeValue))) {
2185
- text.__t = str;
2186
- text.nodeValue = str + "";
2187
- }
2188
- }
2189
- class BranchManager {
2190
- /**
2191
- * @param {TemplateNode} anchor
2192
- * @param {boolean} transition
2193
- */
2194
- constructor(anchor, transition = true) {
2195
- /** @type {TemplateNode} */
2196
- __publicField(this, "anchor");
2197
- /** @type {Map<Batch, Key>} */
2198
- __privateAdd(this, _batches, /* @__PURE__ */ new Map());
2199
- /**
2200
- * Map of keys to effects that are currently rendered in the DOM.
2201
- * These effects are visible and actively part of the document tree.
2202
- * Example:
2203
- * ```
2204
- * {#if condition}
2205
- * foo
2206
- * {:else}
2207
- * bar
2208
- * {/if}
2209
- * ```
2210
- * Can result in the entries `true->Effect` and `false->Effect`
2211
- * @type {Map<Key, Effect>}
2212
- */
2213
- __privateAdd(this, _onscreen, /* @__PURE__ */ new Map());
2214
- /**
2215
- * Similar to #onscreen with respect to the keys, but contains branches that are not yet
2216
- * in the DOM, because their insertion is deferred.
2217
- * @type {Map<Key, Branch>}
2218
- */
2219
- __privateAdd(this, _offscreen, /* @__PURE__ */ new Map());
2220
- /**
2221
- * Keys of effects that are currently outroing
2222
- * @type {Set<Key>}
2223
- */
2224
- __privateAdd(this, _outroing, /* @__PURE__ */ new Set());
2225
- /**
2226
- * Whether to pause (i.e. outro) on change, or destroy immediately.
2227
- * This is necessary for `<svelte:element>`
2228
- */
2229
- __privateAdd(this, _transition, true);
2230
- __privateAdd(this, _commit, () => {
2231
- var batch = (
2232
- /** @type {Batch} */
2233
- current_batch
2234
- );
2235
- if (!__privateGet(this, _batches).has(batch)) return;
2236
- var key = (
2237
- /** @type {Key} */
2238
- __privateGet(this, _batches).get(batch)
2239
- );
2240
- var onscreen = __privateGet(this, _onscreen).get(key);
2241
- if (onscreen) {
2242
- resume_effect(onscreen);
2243
- __privateGet(this, _outroing).delete(key);
2244
- } else {
2245
- var offscreen = __privateGet(this, _offscreen).get(key);
2246
- if (offscreen) {
2247
- __privateGet(this, _onscreen).set(key, offscreen.effect);
2248
- __privateGet(this, _offscreen).delete(key);
2249
- offscreen.fragment.lastChild.remove();
2250
- this.anchor.before(offscreen.fragment);
2251
- onscreen = offscreen.effect;
2252
- }
2253
- }
2254
- for (const [b, k] of __privateGet(this, _batches)) {
2255
- __privateGet(this, _batches).delete(b);
2256
- if (b === batch) {
2257
- break;
2258
- }
2259
- const offscreen2 = __privateGet(this, _offscreen).get(k);
2260
- if (offscreen2) {
2261
- destroy_effect(offscreen2.effect);
2262
- __privateGet(this, _offscreen).delete(k);
2263
- }
2264
- }
2265
- for (const [k, effect2] of __privateGet(this, _onscreen)) {
2266
- if (k === key || __privateGet(this, _outroing).has(k)) continue;
2267
- const on_destroy = () => {
2268
- const keys = Array.from(__privateGet(this, _batches).values());
2269
- if (keys.includes(k)) {
2270
- var fragment = document.createDocumentFragment();
2271
- move_effect(effect2, fragment);
2272
- fragment.append(create_text());
2273
- __privateGet(this, _offscreen).set(k, { effect: effect2, fragment });
2274
- } else {
2275
- destroy_effect(effect2);
2276
- }
2277
- __privateGet(this, _outroing).delete(k);
2278
- __privateGet(this, _onscreen).delete(k);
2279
- };
2280
- if (__privateGet(this, _transition) || !onscreen) {
2281
- __privateGet(this, _outroing).add(k);
2282
- pause_effect(effect2, on_destroy, false);
2283
- } else {
2284
- on_destroy();
2285
- }
2286
- }
2287
- });
2288
- /**
2289
- * @param {Batch} batch
2290
- */
2291
- __privateAdd(this, _discard, (batch) => {
2292
- __privateGet(this, _batches).delete(batch);
2293
- const keys = Array.from(__privateGet(this, _batches).values());
2294
- for (const [k, branch2] of __privateGet(this, _offscreen)) {
2295
- if (!keys.includes(k)) {
2296
- destroy_effect(branch2.effect);
2297
- __privateGet(this, _offscreen).delete(k);
2298
- }
2299
- }
2300
- });
2301
- this.anchor = anchor;
2302
- __privateSet(this, _transition, transition);
2303
- }
2304
- /**
2305
- *
2306
- * @param {any} key
2307
- * @param {null | ((target: TemplateNode) => void)} fn
2308
- */
2309
- ensure(key, fn) {
2310
- var batch = (
2311
- /** @type {Batch} */
2312
- current_batch
2313
- );
2314
- var defer = should_defer_append();
2315
- if (fn && !__privateGet(this, _onscreen).has(key) && !__privateGet(this, _offscreen).has(key)) {
2316
- if (defer) {
2317
- var fragment = document.createDocumentFragment();
2318
- var target = create_text();
2319
- fragment.append(target);
2320
- __privateGet(this, _offscreen).set(key, {
2321
- effect: branch(() => fn(target)),
2322
- fragment
2323
- });
2324
- } else {
2325
- __privateGet(this, _onscreen).set(
2326
- key,
2327
- branch(() => fn(this.anchor))
2328
- );
2329
- }
2330
- }
2331
- __privateGet(this, _batches).set(batch, key);
2332
- if (defer) {
2333
- for (const [k, effect2] of __privateGet(this, _onscreen)) {
2334
- if (k === key) {
2335
- batch.skipped_effects.delete(effect2);
2336
- } else {
2337
- batch.skipped_effects.add(effect2);
2338
- }
2339
- }
2340
- for (const [k, branch2] of __privateGet(this, _offscreen)) {
2341
- if (k === key) {
2342
- batch.skipped_effects.delete(branch2.effect);
2343
- } else {
2344
- batch.skipped_effects.add(branch2.effect);
2345
- }
2346
- }
2347
- batch.oncommit(__privateGet(this, _commit));
2348
- batch.ondiscard(__privateGet(this, _discard));
2349
- } else {
2350
- __privateGet(this, _commit).call(this);
2351
- }
2352
- }
2353
- }
2354
- _batches = new WeakMap();
2355
- _onscreen = new WeakMap();
2356
- _offscreen = new WeakMap();
2357
- _outroing = new WeakMap();
2358
- _transition = new WeakMap();
2359
- _commit = new WeakMap();
2360
- _discard = new WeakMap();
2361
- function if_block(node, fn, elseif = false) {
2362
- var branches = new BranchManager(node);
2363
- var flags = elseif ? EFFECT_TRANSPARENT : 0;
2364
- function update_branch(condition, fn2) {
2365
- branches.ensure(condition, fn2);
2366
- }
2367
- block(() => {
2368
- var has_branch = false;
2369
- fn((fn2, flag = true) => {
2370
- has_branch = true;
2371
- update_branch(flag, fn2);
2372
- });
2373
- if (!has_branch) {
2374
- update_branch(false, null);
2375
- }
2376
- }, flags);
2377
- }
2378
- function slot(anchor, $$props, name, slot_props, fallback_fn) {
2379
- var _a2;
2380
- var slot_fn = (_a2 = $$props.$$slots) == null ? void 0 : _a2[name];
2381
- var is_interop = false;
2382
- if (slot_fn === true) {
2383
- slot_fn = $$props["children"];
2384
- is_interop = true;
2385
- }
2386
- if (slot_fn === void 0) ;
2387
- else {
2388
- slot_fn(anchor, is_interop ? () => slot_props : slot_props);
2389
- }
2390
- }
2391
- const whitespace = [..." \n\r\f \v\uFEFF"];
2392
- function to_class(value, hash, directives) {
2393
- var classname = value == null ? "" : "" + value;
2394
- if (hash) {
2395
- classname = classname ? classname + " " + hash : hash;
2396
- }
2397
- if (directives) {
2398
- for (var key in directives) {
2399
- if (directives[key]) {
2400
- classname = classname ? classname + " " + key : key;
2401
- } else if (classname.length) {
2402
- var len = key.length;
2403
- var a = 0;
2404
- while ((a = classname.indexOf(key, a)) >= 0) {
2405
- var b = a + len;
2406
- if ((a === 0 || whitespace.includes(classname[a - 1])) && (b === classname.length || whitespace.includes(classname[b]))) {
2407
- classname = (a === 0 ? "" : classname.substring(0, a)) + classname.substring(b + 1);
2408
- } else {
2409
- a = b;
2410
- }
2411
- }
2412
- }
2413
- }
2414
- }
2415
- return classname === "" ? null : classname;
2416
- }
2417
- function append_styles(styles, important = false) {
2418
- var separator = important ? " !important;" : ";";
2419
- var css = "";
2420
- for (var key in styles) {
2421
- var value = styles[key];
2422
- if (value != null && value !== "") {
2423
- css += " " + key + ": " + value + separator;
2424
- }
2425
- }
2426
- return css;
2427
- }
2428
- function to_style(value, styles) {
2429
- if (styles) {
2430
- var new_style = "";
2431
- var normal_styles;
2432
- var important_styles;
2433
- if (Array.isArray(styles)) {
2434
- normal_styles = styles[0];
2435
- important_styles = styles[1];
2436
- } else {
2437
- normal_styles = styles;
2438
- }
2439
- if (normal_styles) {
2440
- new_style += append_styles(normal_styles);
2441
- }
2442
- if (important_styles) {
2443
- new_style += append_styles(important_styles, true);
2444
- }
2445
- new_style = new_style.trim();
2446
- return new_style === "" ? null : new_style;
2447
- }
2448
- return String(value);
2449
- }
2450
- function set_class(dom, is_html, value, hash, prev_classes, next_classes) {
2451
- var prev = dom.__className;
2452
- if (prev !== value || prev === void 0) {
2453
- var next_class_name = to_class(value, hash, next_classes);
2454
- {
2455
- if (next_class_name == null) {
2456
- dom.removeAttribute("class");
2457
- } else {
2458
- dom.className = next_class_name;
2459
- }
2460
- }
2461
- dom.__className = value;
2462
- } else if (next_classes && prev_classes !== next_classes) {
2463
- for (var key in next_classes) {
2464
- var is_present = !!next_classes[key];
2465
- if (prev_classes == null || is_present !== !!prev_classes[key]) {
2466
- dom.classList.toggle(key, is_present);
2467
- }
2468
- }
2469
- }
2470
- return next_classes;
2471
- }
2472
- function update_styles(dom, prev = {}, next, priority) {
2473
- for (var key in next) {
2474
- var value = next[key];
2475
- if (prev[key] !== value) {
2476
- if (next[key] == null) {
2477
- dom.style.removeProperty(key);
2478
- } else {
2479
- dom.style.setProperty(key, value, priority);
2480
- }
2481
- }
2482
- }
2483
- }
2484
- function set_style(dom, value, prev_styles, next_styles) {
2485
- var prev = dom.__style;
2486
- if (prev !== value) {
2487
- var next_style_attr = to_style(value, next_styles);
2488
- {
2489
- if (next_style_attr == null) {
2490
- dom.removeAttribute("style");
2491
- } else {
2492
- dom.style.cssText = next_style_attr;
2493
- }
2494
- }
2495
- dom.__style = value;
2496
- } else if (next_styles) {
2497
- if (Array.isArray(next_styles)) {
2498
- update_styles(dom, prev_styles == null ? void 0 : prev_styles[0], next_styles[0]);
2499
- update_styles(dom, prev_styles == null ? void 0 : prev_styles[1], next_styles[1], "important");
2500
- } else {
2501
- update_styles(dom, prev_styles, next_styles);
2502
- }
2503
- }
2504
- return next_styles;
2505
- }
2506
- const IS_CUSTOM_ELEMENT = Symbol("is custom element");
2507
- const IS_HTML = Symbol("is html");
2508
- function set_attribute(element, attribute, value, skip_warning) {
2509
- var attributes = get_attributes(element);
2510
- if (attributes[attribute] === (attributes[attribute] = value)) return;
2511
- if (attribute === "loading") {
2512
- element[LOADING_ATTR_SYMBOL] = value;
2513
- }
2514
- if (value == null) {
2515
- element.removeAttribute(attribute);
2516
- } else if (typeof value !== "string" && get_setters(element).includes(attribute)) {
2517
- element[attribute] = value;
2518
- } else {
2519
- element.setAttribute(attribute, value);
2520
- }
2521
- }
2522
- function get_attributes(element) {
2523
- return (
2524
- /** @type {Record<string | symbol, unknown>} **/
2525
- // @ts-expect-error
2526
- element.__attributes ?? (element.__attributes = {
2527
- [IS_CUSTOM_ELEMENT]: element.nodeName.includes("-"),
2528
- [IS_HTML]: element.namespaceURI === NAMESPACE_HTML
2529
- })
2530
- );
2531
- }
2532
- var setters_cache = /* @__PURE__ */ new Map();
2533
- function get_setters(element) {
2534
- var cache_key = element.getAttribute("is") || element.nodeName;
2535
- var setters = setters_cache.get(cache_key);
2536
- if (setters) return setters;
2537
- setters_cache.set(cache_key, setters = []);
2538
- var descriptors;
2539
- var proto = element;
2540
- var element_proto = Element.prototype;
2541
- while (element_proto !== proto) {
2542
- descriptors = get_descriptors(proto);
2543
- for (var key in descriptors) {
2544
- if (descriptors[key].set) {
2545
- setters.push(key);
2546
- }
2547
- }
2548
- proto = get_prototype_of(proto);
2549
- }
2550
- return setters;
2551
- }
2552
- function is_bound_this(bound_value, element_or_component) {
2553
- return bound_value === element_or_component || (bound_value == null ? void 0 : bound_value[STATE_SYMBOL]) === element_or_component;
2554
- }
2555
- function bind_this(element_or_component = {}, update, get_value, get_parts) {
2556
- effect(() => {
2557
- var old_parts;
2558
- var parts;
2559
- render_effect(() => {
2560
- old_parts = parts;
2561
- parts = [];
2562
- untrack(() => {
2563
- if (element_or_component !== get_value(...parts)) {
2564
- update(element_or_component, ...parts);
2565
- if (old_parts && is_bound_this(get_value(...old_parts), element_or_component)) {
2566
- update(null, ...old_parts);
2567
- }
2568
- }
2569
- });
2570
- });
2571
- return () => {
2572
- queue_micro_task(() => {
2573
- if (parts && is_bound_this(get_value(...parts), element_or_component)) {
2574
- update(null, ...parts);
2575
- }
2576
- });
2577
- };
2578
- });
2579
- return element_or_component;
2580
- }
2581
- let is_store_binding = false;
2582
- function capture_store_binding(fn) {
2583
- var previous_is_store_binding = is_store_binding;
2584
- try {
2585
- is_store_binding = false;
2586
- return [fn(), is_store_binding];
2587
- } finally {
2588
- is_store_binding = previous_is_store_binding;
2589
- }
2590
- }
2591
- function prop(props, key, flags, fallback) {
2592
- var _a2;
2593
- var bindable = (flags & PROPS_IS_BINDABLE) !== 0;
2594
- var lazy = (flags & PROPS_IS_LAZY_INITIAL) !== 0;
2595
- var fallback_value = (
2596
- /** @type {V} */
2597
- fallback
2598
- );
2599
- var fallback_dirty = true;
2600
- var get_fallback = () => {
2601
- if (fallback_dirty) {
2602
- fallback_dirty = false;
2603
- fallback_value = lazy ? untrack(
2604
- /** @type {() => V} */
2605
- fallback
2606
- ) : (
2607
- /** @type {V} */
2608
- fallback
2609
- );
2610
- }
2611
- return fallback_value;
2612
- };
2613
- var setter;
2614
- if (bindable) {
2615
- var is_entry_props = STATE_SYMBOL in props || LEGACY_PROPS in props;
2616
- setter = ((_a2 = get_descriptor(props, key)) == null ? void 0 : _a2.set) ?? (is_entry_props && key in props ? (v) => props[key] = v : void 0);
2617
- }
2618
- var initial_value;
2619
- var is_store_sub = false;
2620
- if (bindable) {
2621
- [initial_value, is_store_sub] = capture_store_binding(() => (
2622
- /** @type {V} */
2623
- props[key]
2624
- ));
2625
- } else {
2626
- initial_value = /** @type {V} */
2627
- props[key];
2628
- }
2629
- if (initial_value === void 0 && fallback !== void 0) {
2630
- initial_value = get_fallback();
2631
- if (setter) {
2632
- props_invalid_value();
2633
- setter(initial_value);
2634
- }
2635
- }
2636
- var getter;
2637
- {
2638
- getter = () => {
2639
- var value = (
2640
- /** @type {V} */
2641
- props[key]
2642
- );
2643
- if (value === void 0) return get_fallback();
2644
- fallback_dirty = true;
2645
- return value;
2646
- };
2647
- }
2648
- if ((flags & PROPS_IS_UPDATED) === 0) {
2649
- return getter;
2650
- }
2651
- if (setter) {
2652
- var legacy_parent = props.$$legacy;
2653
- return (
2654
- /** @type {() => V} */
2655
- function(value, mutation) {
2656
- if (arguments.length > 0) {
2657
- if (!mutation || legacy_parent || is_store_sub) {
2658
- setter(mutation ? getter() : value);
2659
- }
2660
- return value;
2661
- }
2662
- return getter();
2663
- }
2664
- );
2665
- }
2666
- var overridden = false;
2667
- var d = ((flags & PROPS_IS_IMMUTABLE) !== 0 ? derived : derived_safe_equal)(() => {
2668
- overridden = false;
2669
- return getter();
2670
- });
2671
- if (bindable) get(d);
2672
- var parent_effect = (
2673
- /** @type {Effect} */
2674
- active_effect
2675
- );
2676
- return (
2677
- /** @type {() => V} */
2678
- function(value, mutation) {
2679
- if (arguments.length > 0) {
2680
- const new_value = mutation ? get(d) : bindable ? proxy(value) : value;
2681
- set(d, new_value);
2682
- overridden = true;
2683
- if (fallback_value !== void 0) {
2684
- fallback_value = new_value;
2685
- }
2686
- return value;
2687
- }
2688
- if (is_destroying_effect && overridden || (parent_effect.f & DESTROYED) !== 0) {
2689
- return d.v;
2690
- }
2691
- return get(d);
2692
- }
2693
- );
2694
- }
2695
- const grovePresets = {
2696
- "grove-mist": {
2697
- name: "Grove Mist",
2698
- description: "Soft fog effect drifting through the trees",
2699
- characters: " ·∙•◦",
2700
- pattern: "perlin",
2701
- frequency: 0.03,
2702
- amplitude: 0.8,
2703
- speed: 0.3,
2704
- opacity: 0.2
2705
- },
2706
- "grove-fireflies": {
2707
- name: "Grove Fireflies",
2708
- description: "Twinkling points of light in the darkness",
2709
- characters: " ·*✦✧",
2710
- pattern: "static",
2711
- frequency: 0.01,
2712
- amplitude: 1.2,
2713
- speed: 0.8,
2714
- opacity: 0.3
2715
- },
2716
- "grove-rain": {
2717
- name: "Grove Rain",
2718
- description: "Gentle rain falling through the canopy",
2719
- characters: " │\\|/",
2720
- pattern: "waves",
2721
- frequency: 0.05,
2722
- amplitude: 1,
2723
- speed: 1.5,
2724
- opacity: 0.15
2725
- },
2726
- "grove-dew": {
2727
- name: "Grove Dew",
2728
- description: "Morning dew glistening on spider silk",
2729
- characters: " ·∘∙●",
2730
- pattern: "fbm",
2731
- frequency: 0.04,
2732
- amplitude: 0.7,
2733
- speed: 0.1,
2734
- opacity: 0.15
2735
- }
2736
- };
2737
- const seasonalPresets = {
2738
- "winter-snow": {
2739
- name: "Winter Snow",
2740
- description: "Gentle snowfall on a quiet night",
2741
- characters: " ·∙*❄",
2742
- pattern: "perlin",
2743
- frequency: 0.04,
2744
- amplitude: 0.9,
2745
- speed: 0.5,
2746
- opacity: 0.25
2747
- },
2748
- "autumn-leaves": {
2749
- name: "Autumn Leaves",
2750
- description: "Scattered leaves drifting on the wind",
2751
- characters: " 🍂·∙",
2752
- pattern: "perlin",
2753
- frequency: 0.06,
2754
- amplitude: 1.1,
2755
- speed: 0.4,
2756
- opacity: 0.2
2757
- },
2758
- "spring-petals": {
2759
- name: "Spring Petals",
2760
- description: "Cherry blossom petals floating on the breeze",
2761
- characters: " ·✿❀",
2762
- pattern: "waves",
2763
- frequency: 0.05,
2764
- amplitude: 0.8,
2765
- speed: 0.6,
2766
- opacity: 0.2
2767
- },
2768
- "summer-heat": {
2769
- name: "Summer Heat",
2770
- description: "Heat shimmer rising from sun-warmed ground",
2771
- characters: " ~≈∿",
2772
- pattern: "waves",
2773
- frequency: 0.08,
2774
- amplitude: 1.3,
2775
- speed: 1,
2776
- opacity: 0.1
2777
- }
2778
- };
2779
- const ambientPresets = {
2780
- "ambient-static": {
2781
- name: "Ambient Static",
2782
- description: "Gentle static noise texture",
2783
- characters: " .:",
2784
- pattern: "static",
2785
- frequency: 0.1,
2786
- amplitude: 0.5,
2787
- speed: 0.2,
2788
- opacity: 0.08
2789
- },
2790
- "ambient-waves": {
2791
- name: "Ambient Waves",
2792
- description: "Soft flowing wave pattern",
2793
- characters: " ·~",
2794
- pattern: "waves",
2795
- frequency: 0.02,
2796
- amplitude: 0.6,
2797
- speed: 0.3,
2798
- opacity: 0.1
2799
- },
2800
- "ambient-clouds": {
2801
- name: "Ambient Clouds",
2802
- description: "Drifting cloud-like patterns",
2803
- characters: " .:-",
2804
- pattern: "fbm",
2805
- frequency: 0.02,
2806
- amplitude: 0.7,
2807
- speed: 0.15,
2808
- opacity: 0.12
2809
- }
2810
- };
2811
- const PRESETS = {
2812
- ...grovePresets,
2813
- ...seasonalPresets,
2814
- ...ambientPresets
2815
- };
2816
- function getPreset(name) {
2817
- return PRESETS[name];
2818
- }
2819
- function getPresetNames() {
2820
- return Object.keys(PRESETS);
2821
- }
2822
- function getPresetsByCategory() {
2823
- return {
2824
- grove: Object.keys(grovePresets),
2825
- seasonal: Object.keys(seasonalPresets),
2826
- ambient: Object.keys(ambientPresets)
2827
- };
2828
- }
2829
- var root$4 = /* @__PURE__ */ from_html(`<div><canvas aria-hidden="true" class="gossamer-canvas svelte-sqd1fq"></canvas></div>`);
2830
- function GossamerClouds($$anchor, $$props) {
2831
- push($$props, true);
2832
- let pattern = prop($$props, "pattern", 3, "perlin"), characters = prop($$props, "characters", 19, () => CHARACTER_SETS.grove.characters), color = prop($$props, "color", 3, "currentColor"), opacity = prop($$props, "opacity", 3, 0.3), animated = prop($$props, "animated", 3, true), speed = prop($$props, "speed", 3, 0.5), frequency = prop($$props, "frequency", 3, 0.05), amplitude = prop($$props, "amplitude", 3, 1), cellSize = prop($$props, "cellSize", 3, 12);
2833
- prop($$props, "fps", 3, 30);
2834
- let className = prop($$props, "class", 3, "");
2835
- let canvas;
2836
- let container;
2837
- let renderer = null;
2838
- let isVisible = true;
2839
- let reducedMotion = false;
2840
- let animationId = null;
2841
- const config = /* @__PURE__ */ user_derived(() => {
2842
- if ($$props.preset && PRESETS[$$props.preset]) {
2843
- const p = PRESETS[$$props.preset];
2844
- return {
2845
- pattern: p.pattern,
2846
- characters: p.characters,
2847
- frequency: p.frequency,
2848
- amplitude: p.amplitude,
2849
- speed: p.speed,
2850
- opacity: p.opacity
2851
- };
2852
- }
2853
- return {
2854
- pattern: pattern(),
2855
- characters: characters(),
2856
- frequency: frequency(),
2857
- amplitude: amplitude(),
2858
- speed: speed(),
2859
- opacity: opacity()
2860
- };
2861
- });
2862
- const shouldAnimate = /* @__PURE__ */ user_derived(() => animated() && isVisible && !reducedMotion);
2863
- let startTime = 0;
2864
- function animate(currentTime) {
2865
- if (!renderer || !get(shouldAnimate)) return;
2866
- const elapsed = (currentTime - startTime) / 1e3;
2867
- const { cols, rows } = renderer.getCellCount();
2868
- const cfg = get(config);
2869
- const grid = generateBrightnessGrid(cols, rows, cfg.pattern, elapsed, {
2870
- frequency: cfg.frequency,
2871
- amplitude: cfg.amplitude,
2872
- speed: cfg.speed
2873
- });
2874
- renderer.renderFromBrightnessGrid(grid);
2875
- animationId = requestAnimationFrame(animate);
2876
- }
2877
- function startAnimation() {
2878
- if (animationId !== null) return;
2879
- startTime = performance.now();
2880
- animationId = requestAnimationFrame(animate);
2881
- }
2882
- function stopAnimation() {
2883
- if (animationId !== null) {
2884
- cancelAnimationFrame(animationId);
2885
- animationId = null;
2886
- }
2887
- }
2888
- function renderStatic() {
2889
- if (!renderer) return;
2890
- const { cols, rows } = renderer.getCellCount();
2891
- const cfg = get(config);
2892
- const grid = generateBrightnessGrid(cols, rows, cfg.pattern, 0, { frequency: cfg.frequency, amplitude: cfg.amplitude, speed: 0 });
2893
- renderer.renderFromBrightnessGrid(grid);
2894
- }
2895
- function setupRenderer(width, height) {
2896
- if (!canvas) return;
2897
- const cfg = get(config);
2898
- if (renderer) {
2899
- renderer.destroy();
2900
- }
2901
- canvas.width = width;
2902
- canvas.height = height;
2903
- renderer = new GossamerRenderer(canvas, {
2904
- characters: cfg.characters,
2905
- cellWidth: cellSize(),
2906
- cellHeight: cellSize(),
2907
- color: color()
2908
- });
2909
- if (get(shouldAnimate)) {
2910
- startAnimation();
2911
- } else {
2912
- renderStatic();
2913
- }
2914
- }
2915
- onMount(() => {
2916
- const cleanupMotion = onReducedMotionChange((prefers) => {
2917
- reducedMotion = prefers;
2918
- });
2919
- const cleanupVisibility = createVisibilityObserver(
2920
- container,
2921
- (visible) => {
2922
- isVisible = visible;
2923
- if (visible && get(shouldAnimate)) {
2924
- startAnimation();
2925
- } else {
2926
- stopAnimation();
2927
- }
2928
- },
2929
- 0.1
2930
- );
2931
- const cleanupResize = createResizeObserver(
2932
- container,
2933
- (width, height) => {
2934
- setupRenderer(width, height);
2935
- },
2936
- 100
2937
- );
2938
- const rect = container.getBoundingClientRect();
2939
- if (rect.width > 0 && rect.height > 0) {
2940
- setupRenderer(rect.width, rect.height);
2941
- }
2942
- return () => {
2943
- cleanupMotion();
2944
- cleanupVisibility();
2945
- cleanupResize();
2946
- stopAnimation();
2947
- renderer == null ? void 0 : renderer.destroy();
2948
- };
2949
- });
2950
- user_effect(() => {
2951
- if (renderer) {
2952
- const cfg = get(config);
2953
- renderer.updateConfig({
2954
- characters: cfg.characters,
2955
- color: color(),
2956
- cellWidth: cellSize(),
2957
- cellHeight: cellSize()
2958
- });
2959
- if (get(shouldAnimate)) {
2960
- startAnimation();
2961
- } else {
2962
- stopAnimation();
2963
- renderStatic();
2964
- }
2965
- }
2966
- });
2967
- var div = root$4();
2968
- let styles;
2969
- var canvas_1 = child(div);
2970
- bind_this(canvas_1, ($$value) => canvas = $$value, () => canvas);
2971
- bind_this(div, ($$value) => container = $$value, () => container);
2972
- template_effect(() => {
2973
- set_class(div, 1, `gossamer-clouds ${className() ?? ""}`, "svelte-sqd1fq");
2974
- styles = set_style(div, "", styles, { opacity: get(config).opacity });
2975
- });
2976
- append($$anchor, div);
2977
- pop();
2978
- }
2979
- var root_1 = /* @__PURE__ */ from_html(`<div class="gossamer-image-loading svelte-1v5c3d1"><span>Loading...</span></div>`);
2980
- var root_3 = /* @__PURE__ */ from_html(`<div class="gossamer-image-error svelte-1v5c3d1"><span>Failed to load image</span></div>`);
2981
- var root_5 = /* @__PURE__ */ from_html(`<img/>`);
2982
- var root_4 = /* @__PURE__ */ from_html(`<canvas aria-hidden="true"></canvas> <!>`, 1);
2983
- var root$3 = /* @__PURE__ */ from_html(`<div role="img"><!></div>`);
2984
- function GossamerImage($$anchor, $$props) {
2985
- push($$props, true);
2986
- let characters = prop($$props, "characters", 19, () => CHARACTER_SETS.standard.characters), cellSize = prop($$props, "cellSize", 3, 8), color = prop($$props, "color", 3, "#ffffff"), invert = prop($$props, "invert", 3, false), showOriginalOnHover = prop($$props, "showOriginalOnHover", 3, false), transitionDuration = prop($$props, "transitionDuration", 3, 300), className = prop($$props, "class", 3, "");
2987
- let canvas;
2988
- let container;
2989
- let isLoading = true;
2990
- let hasError = false;
2991
- let isHovered = false;
2992
- let loadedImage = null;
2993
- let imageWidth = 0;
2994
- let imageHeight = 0;
2995
- const effectiveCharacters = /* @__PURE__ */ user_derived(() => invert() ? invertCharacters(characters()) : characters());
2996
- async function loadAndRender() {
2997
- isLoading = true;
2998
- hasError = false;
2999
- try {
3000
- const img = await loadImage($$props.src, { crossOrigin: "anonymous" });
3001
- loadedImage = img;
3002
- const naturalWidth = img.naturalWidth;
3003
- const naturalHeight = img.naturalHeight;
3004
- const aspectRatio = naturalWidth / naturalHeight;
3005
- if ($$props.width && $$props.height) {
3006
- imageWidth = $$props.width;
3007
- imageHeight = $$props.height;
3008
- } else if ($$props.width) {
3009
- imageWidth = $$props.width;
3010
- imageHeight = Math.round($$props.width / aspectRatio);
3011
- } else if ($$props.height) {
3012
- imageHeight = $$props.height;
3013
- imageWidth = Math.round($$props.height * aspectRatio);
3014
- } else {
3015
- imageWidth = naturalWidth;
3016
- imageHeight = naturalHeight;
3017
- }
3018
- renderASCII();
3019
- isLoading = false;
3020
- } catch {
3021
- hasError = true;
3022
- isLoading = false;
3023
- }
3024
- }
3025
- function renderASCII() {
3026
- if (!canvas || !loadedImage) return;
3027
- canvas.width = imageWidth;
3028
- canvas.height = imageHeight;
3029
- const ctx = canvas.getContext("2d");
3030
- if (!ctx) return;
3031
- const pixelData = imageToPixelData(loadedImage, imageWidth, imageHeight);
3032
- const cells = sampleImageCells(pixelData, cellSize(), cellSize());
3033
- ctx.clearRect(0, 0, imageWidth, imageHeight);
3034
- ctx.font = `${cellSize()}px monospace`;
3035
- ctx.textBaseline = "top";
3036
- ctx.textAlign = "left";
3037
- for (let row = 0; row < cells.length; row++) {
3038
- for (let col = 0; col < cells[row].length; col++) {
3039
- const cell = cells[row][col];
3040
- const char = brightnessToChar(cell.brightness, get(effectiveCharacters));
3041
- if (char !== " ") {
3042
- ctx.fillStyle = color() === "preserve" ? cell.color : color();
3043
- ctx.fillText(char, col * cellSize(), row * cellSize());
3044
- }
3045
- }
3046
- }
3047
- }
3048
- onMount(() => {
3049
- loadAndRender();
3050
- });
3051
- user_effect(() => {
3052
- if ($$props.src) {
3053
- loadAndRender();
3054
- }
3055
- });
3056
- user_effect(() => {
3057
- [
3058
- characters(),
3059
- cellSize(),
3060
- color(),
3061
- invert(),
3062
- $$props.width,
3063
- $$props.height
3064
- ];
3065
- if (loadedImage) {
3066
- renderASCII();
3067
- }
3068
- });
3069
- function handleMouseEnter() {
3070
- if (showOriginalOnHover()) {
3071
- isHovered = true;
3072
- }
3073
- }
3074
- function handleMouseLeave() {
3075
- isHovered = false;
3076
- }
3077
- var div = root$3();
3078
- let classes;
3079
- let styles;
3080
- var node = child(div);
3081
- {
3082
- var consequent = ($$anchor2) => {
3083
- var div_1 = root_1();
3084
- append($$anchor2, div_1);
3085
- };
3086
- var alternate_1 = ($$anchor2) => {
3087
- var fragment = comment();
3088
- var node_1 = first_child(fragment);
3089
- {
3090
- var consequent_1 = ($$anchor3) => {
3091
- var div_2 = root_3();
3092
- append($$anchor3, div_2);
3093
- };
3094
- var alternate = ($$anchor3) => {
3095
- var fragment_1 = root_4();
3096
- var canvas_1 = first_child(fragment_1);
3097
- let classes_1;
3098
- let styles_1;
3099
- bind_this(canvas_1, ($$value) => canvas = $$value, () => canvas);
3100
- var node_2 = sibling(canvas_1, 2);
3101
- {
3102
- var consequent_2 = ($$anchor4) => {
3103
- var img_1 = root_5();
3104
- let classes_2;
3105
- let styles_2;
3106
- template_effect(() => {
3107
- set_attribute(img_1, "src", $$props.src);
3108
- set_attribute(img_1, "alt", $$props.alt);
3109
- classes_2 = set_class(img_1, 1, "gossamer-original svelte-1v5c3d1", null, classes_2, { visible: isHovered });
3110
- set_attribute(img_1, "width", imageWidth);
3111
- set_attribute(img_1, "height", imageHeight);
3112
- styles_2 = set_style(img_1, "", styles_2, { "transition-duration": `${transitionDuration() ?? ""}ms` });
3113
- });
3114
- append($$anchor4, img_1);
3115
- };
3116
- if_block(node_2, ($$render) => {
3117
- if (showOriginalOnHover() && loadedImage) $$render(consequent_2);
3118
- });
3119
- }
3120
- template_effect(() => {
3121
- classes_1 = set_class(canvas_1, 1, "gossamer-canvas svelte-1v5c3d1", null, classes_1, { hidden: showOriginalOnHover() && isHovered });
3122
- styles_1 = set_style(canvas_1, "", styles_1, { "transition-duration": `${transitionDuration() ?? ""}ms` });
3123
- });
3124
- append($$anchor3, fragment_1);
3125
- };
3126
- if_block(
3127
- node_1,
3128
- ($$render) => {
3129
- if (hasError) $$render(consequent_1);
3130
- else $$render(alternate, false);
3131
- },
3132
- true
3133
- );
3134
- }
3135
- append($$anchor2, fragment);
3136
- };
3137
- if_block(node, ($$render) => {
3138
- if (isLoading) $$render(consequent);
3139
- else $$render(alternate_1, false);
3140
- });
3141
- }
3142
- bind_this(div, ($$value) => container = $$value, () => container);
3143
- template_effect(() => {
3144
- classes = set_class(div, 1, `gossamer-image ${className() ?? ""}`, "svelte-1v5c3d1", classes, {
3145
- loading: isLoading,
3146
- error: hasError,
3147
- hoverable: showOriginalOnHover()
3148
- });
3149
- set_attribute(div, "aria-label", $$props.alt);
3150
- styles = set_style(div, "", styles, {
3151
- width: imageWidth ? `${imageWidth}px` : void 0,
3152
- height: imageHeight ? `${imageHeight}px` : void 0
3153
- });
3154
- });
3155
- event("mouseenter", div, handleMouseEnter);
3156
- event("mouseleave", div, handleMouseLeave);
3157
- append($$anchor, div);
3158
- pop();
3159
- }
3160
- var root$2 = /* @__PURE__ */ from_html(`<div><canvas aria-hidden="true" class="gossamer-canvas svelte-fd3qw5"></canvas> <span class="gossamer-text-sr svelte-fd3qw5"> </span></div>`);
3161
- function GossamerText($$anchor, $$props) {
3162
- push($$props, true);
3163
- prop($$props, "characters", 19, () => CHARACTER_SETS.minimal.characters);
3164
- let color = prop($$props, "color", 3, "currentColor"), fontSize = prop($$props, "fontSize", 3, 48), fontFamily = prop($$props, "fontFamily", 3, "monospace"), animated = prop($$props, "animated", 3, false);
3165
- prop($$props, "pattern", 3, "perlin");
3166
- let speed = prop($$props, "speed", 3, 0.5), intensity = prop($$props, "intensity", 3, 0.3);
3167
- prop($$props, "fps", 3, 30);
3168
- let className = prop($$props, "class", 3, "");
3169
- let canvas;
3170
- let container;
3171
- let isVisible = true;
3172
- let reducedMotion = false;
3173
- let animationId = null;
3174
- let textMetrics = { width: 0, height: 0 };
3175
- const shouldAnimate = /* @__PURE__ */ user_derived(() => animated() && isVisible && !reducedMotion);
3176
- function measureText() {
3177
- if (!canvas) return;
3178
- const ctx = canvas.getContext("2d");
3179
- if (!ctx) return;
3180
- ctx.font = `${fontSize()}px ${fontFamily()}`;
3181
- const metrics = ctx.measureText($$props.text);
3182
- textMetrics = {
3183
- width: Math.ceil(metrics.width) + 20,
3184
- height: fontSize() + 20
3185
- };
3186
- canvas.width = textMetrics.width;
3187
- canvas.height = textMetrics.height;
3188
- }
3189
- function renderText(time = 0) {
3190
- if (!canvas) return;
3191
- const ctx = canvas.getContext("2d");
3192
- if (!ctx) return;
3193
- ctx.clearRect(0, 0, canvas.width, canvas.height);
3194
- ctx.font = `${fontSize()}px ${fontFamily()}`;
3195
- ctx.textBaseline = "top";
3196
- ctx.fillStyle = color();
3197
- let x = 10;
3198
- const y = 10;
3199
- for (let i = 0; i < $$props.text.length; i++) {
3200
- const char = $$props.text[i];
3201
- const charWidth = ctx.measureText(char).width;
3202
- if (animated() && time > 0) {
3203
- const noise = perlinNoise2D(i * 0.5 + time * speed() * 1e-3, time * speed() * 5e-4);
3204
- const offsetY = noise * intensity() * 5;
3205
- ctx.globalAlpha = 0.7 + (noise + 1) * 0.15;
3206
- ctx.fillText(char, x, y + offsetY);
3207
- ctx.globalAlpha = 1;
3208
- } else {
3209
- ctx.fillText(char, x, y);
3210
- }
3211
- x += charWidth;
3212
- }
3213
- }
3214
- let startTime = 0;
3215
- function animate(currentTime) {
3216
- if (!get(shouldAnimate)) return;
3217
- const elapsed = currentTime - startTime;
3218
- renderText(elapsed);
3219
- animationId = requestAnimationFrame(animate);
3220
- }
3221
- function startAnimation() {
3222
- if (animationId !== null) return;
3223
- startTime = performance.now();
3224
- animationId = requestAnimationFrame(animate);
3225
- }
3226
- function stopAnimation() {
3227
- if (animationId !== null) {
3228
- cancelAnimationFrame(animationId);
3229
- animationId = null;
3230
- }
3231
- }
3232
- onMount(() => {
3233
- measureText();
3234
- renderText();
3235
- const cleanupMotion = onReducedMotionChange((prefers) => {
3236
- reducedMotion = prefers;
3237
- });
3238
- const cleanupVisibility = createVisibilityObserver(
3239
- container,
3240
- (visible) => {
3241
- isVisible = visible;
3242
- if (visible && get(shouldAnimate)) {
3243
- startAnimation();
3244
- } else {
3245
- stopAnimation();
3246
- renderText();
3247
- }
3248
- },
3249
- 0.1
3250
- );
3251
- if (get(shouldAnimate)) {
3252
- startAnimation();
3253
- }
3254
- return () => {
3255
- cleanupMotion();
3256
- cleanupVisibility();
3257
- stopAnimation();
3258
- };
3259
- });
3260
- user_effect(() => {
3261
- if ($$props.text) {
3262
- measureText();
3263
- if (get(shouldAnimate)) ;
3264
- else {
3265
- renderText();
3266
- }
3267
- }
3268
- });
3269
- user_effect(() => {
3270
- if (get(shouldAnimate)) {
3271
- startAnimation();
3272
- } else {
3273
- stopAnimation();
3274
- renderText();
3275
- }
3276
- });
3277
- var div = root$2();
3278
- let styles;
3279
- var canvas_1 = child(div);
3280
- bind_this(canvas_1, ($$value) => canvas = $$value, () => canvas);
3281
- var span = sibling(canvas_1, 2);
3282
- var text_1 = child(span);
3283
- bind_this(div, ($$value) => container = $$value, () => container);
3284
- template_effect(() => {
3285
- set_class(div, 1, `gossamer-text ${className() ?? ""}`, "svelte-fd3qw5");
3286
- styles = set_style(div, "", styles, {
3287
- width: textMetrics.width ? `${textMetrics.width}px` : "auto",
3288
- height: textMetrics.height ? `${textMetrics.height}px` : "auto"
3289
- });
3290
- set_text(text_1, $$props.text);
3291
- });
3292
- append($$anchor, div);
3293
- pop();
3294
- }
3295
- var root$1 = /* @__PURE__ */ from_html(`<div><canvas aria-hidden="true" class="gossamer-canvas svelte-1oexqwo"></canvas></div>`);
3296
- function GossamerOverlay($$anchor, $$props) {
3297
- push($$props, true);
3298
- let pattern = prop($$props, "pattern", 3, "perlin"), characters = prop($$props, "characters", 19, () => CHARACTER_SETS.minimal.characters), color = prop($$props, "color", 3, "currentColor"), opacity = prop($$props, "opacity", 3, 0.15), blendMode = prop($$props, "blendMode", 3, "overlay"), animated = prop($$props, "animated", 3, true), speed = prop($$props, "speed", 3, 0.3), frequency = prop($$props, "frequency", 3, 0.03), amplitude = prop($$props, "amplitude", 3, 0.6), cellSize = prop($$props, "cellSize", 3, 16);
3299
- prop($$props, "fps", 3, 30);
3300
- let className = prop($$props, "class", 3, "");
3301
- let canvas;
3302
- let container;
3303
- let renderer = null;
3304
- let isVisible = true;
3305
- let reducedMotion = false;
3306
- let animationId = null;
3307
- const shouldAnimate = /* @__PURE__ */ user_derived(() => animated() && isVisible && !reducedMotion);
3308
- let startTime = 0;
3309
- function animate(currentTime) {
3310
- if (!renderer || !get(shouldAnimate)) return;
3311
- const elapsed = (currentTime - startTime) / 1e3;
3312
- const { cols, rows } = renderer.getCellCount();
3313
- const grid = generateBrightnessGrid(cols, rows, pattern(), elapsed, {
3314
- frequency: frequency(),
3315
- amplitude: amplitude(),
3316
- speed: speed()
3317
- });
3318
- renderer.renderFromBrightnessGrid(grid);
3319
- animationId = requestAnimationFrame(animate);
3320
- }
3321
- function startAnimation() {
3322
- if (animationId !== null) return;
3323
- startTime = performance.now();
3324
- animationId = requestAnimationFrame(animate);
3325
- }
3326
- function stopAnimation() {
3327
- if (animationId !== null) {
3328
- cancelAnimationFrame(animationId);
3329
- animationId = null;
3330
- }
3331
- }
3332
- function renderStatic() {
3333
- if (!renderer) return;
3334
- const { cols, rows } = renderer.getCellCount();
3335
- const grid = generateBrightnessGrid(cols, rows, pattern(), 0, { frequency: frequency(), amplitude: amplitude(), speed: 0 });
3336
- renderer.renderFromBrightnessGrid(grid);
3337
- }
3338
- function setupRenderer(width, height) {
3339
- if (!canvas) return;
3340
- if (renderer) {
3341
- renderer.destroy();
3342
- }
3343
- canvas.width = width;
3344
- canvas.height = height;
3345
- renderer = new GossamerRenderer(canvas, {
3346
- characters: characters(),
3347
- cellWidth: cellSize(),
3348
- cellHeight: cellSize(),
3349
- color: color()
3350
- });
3351
- if (get(shouldAnimate)) {
3352
- startAnimation();
3353
- } else {
3354
- renderStatic();
3355
- }
3356
- }
3357
- onMount(() => {
3358
- const cleanupMotion = onReducedMotionChange((prefers) => {
3359
- reducedMotion = prefers;
3360
- });
3361
- const cleanupVisibility = createVisibilityObserver(
3362
- container,
3363
- (visible) => {
3364
- isVisible = visible;
3365
- if (visible && get(shouldAnimate)) {
3366
- startAnimation();
3367
- } else {
3368
- stopAnimation();
3369
- }
3370
- },
3371
- 0.1
3372
- );
3373
- const cleanupResize = createResizeObserver(
3374
- container,
3375
- (width, height) => {
3376
- setupRenderer(width, height);
3377
- },
3378
- 100
3379
- );
3380
- const rect = container.getBoundingClientRect();
3381
- if (rect.width > 0 && rect.height > 0) {
3382
- setupRenderer(rect.width, rect.height);
3383
- }
3384
- return () => {
3385
- cleanupMotion();
3386
- cleanupVisibility();
3387
- cleanupResize();
3388
- stopAnimation();
3389
- renderer == null ? void 0 : renderer.destroy();
3390
- };
3391
- });
3392
- user_effect(() => {
3393
- if (renderer) {
3394
- renderer.updateConfig({
3395
- characters: characters(),
3396
- color: color(),
3397
- cellWidth: cellSize(),
3398
- cellHeight: cellSize()
3399
- });
3400
- if (get(shouldAnimate)) {
3401
- startAnimation();
3402
- } else {
3403
- stopAnimation();
3404
- renderStatic();
3405
- }
3406
- }
3407
- });
3408
- var div = root$1();
3409
- let styles;
3410
- var canvas_1 = child(div);
3411
- bind_this(canvas_1, ($$value) => canvas = $$value, () => canvas);
3412
- bind_this(div, ($$value) => container = $$value, () => container);
3413
- template_effect(() => {
3414
- set_class(div, 1, `gossamer-overlay ${className() ?? ""}`, "svelte-1oexqwo");
3415
- styles = set_style(div, "", styles, { opacity: opacity(), "mix-blend-mode": blendMode() });
3416
- });
3417
- append($$anchor, div);
3418
- pop();
3419
- }
3420
- var root = /* @__PURE__ */ from_html(`<div><canvas aria-hidden="true" class="gossamer-border-canvas svelte-qe7ze6"></canvas> <div class="gossamer-border-content svelte-qe7ze6"><!></div></div>`);
3421
- function GossamerBorder($$anchor, $$props) {
3422
- push($$props, true);
3423
- let style = prop($$props, "style", 3, "simple"), color = prop($$props, "color", 3, "currentColor"), thickness = prop($$props, "thickness", 3, 1), charSize = prop($$props, "charSize", 3, 12), animated = prop($$props, "animated", 3, false), speed = prop($$props, "speed", 3, 0.5), padding = prop($$props, "padding", 3, 0), className = prop($$props, "class", 3, "");
3424
- const BORDER_STYLES = {
3425
- simple: {
3426
- horizontal: "─",
3427
- vertical: "│",
3428
- topLeft: "┌",
3429
- topRight: "┐",
3430
- bottomLeft: "└",
3431
- bottomRight: "┘"
3432
- },
3433
- double: {
3434
- horizontal: "═",
3435
- vertical: "║",
3436
- topLeft: "╔",
3437
- topRight: "╗",
3438
- bottomLeft: "╚",
3439
- bottomRight: "╝"
3440
- },
3441
- dots: {
3442
- horizontal: "·",
3443
- vertical: "·",
3444
- topLeft: "·",
3445
- topRight: "·",
3446
- bottomLeft: "·",
3447
- bottomRight: "·"
3448
- },
3449
- dashes: {
3450
- horizontal: "─",
3451
- vertical: "¦",
3452
- topLeft: "┌",
3453
- topRight: "┐",
3454
- bottomLeft: "└",
3455
- bottomRight: "┘"
3456
- },
3457
- stars: {
3458
- horizontal: "*",
3459
- vertical: "*",
3460
- topLeft: "*",
3461
- topRight: "*",
3462
- bottomLeft: "*",
3463
- bottomRight: "*"
3464
- },
3465
- corners: {
3466
- horizontal: " ",
3467
- vertical: " ",
3468
- topLeft: "╭",
3469
- topRight: "╮",
3470
- bottomLeft: "╰",
3471
- bottomRight: "╯"
3472
- }
3473
- };
3474
- let canvas;
3475
- let container;
3476
- let isVisible = true;
3477
- let reducedMotion = false;
3478
- let animationId = null;
3479
- let borderWidth = 0;
3480
- let borderHeight = 0;
3481
- const borderChars = /* @__PURE__ */ user_derived(() => ({ ...BORDER_STYLES[style()], ...$$props.characters }));
3482
- const shouldAnimate = /* @__PURE__ */ user_derived(() => animated() && isVisible && !reducedMotion);
3483
- function renderBorder(time = 0) {
3484
- if (!canvas) return;
3485
- const ctx = canvas.getContext("2d");
3486
- if (!ctx) return;
3487
- ctx.clearRect(0, 0, canvas.width, canvas.height);
3488
- ctx.font = `${charSize()}px monospace`;
3489
- ctx.textBaseline = "top";
3490
- ctx.fillStyle = color();
3491
- const cols = Math.floor(borderWidth / charSize());
3492
- const rows = Math.floor(borderHeight / charSize());
3493
- if (cols < 3 || rows < 3) return;
3494
- const offset = animated() ? Math.floor(time * speed() * 0.01) : 0;
3495
- ctx.fillText(get(borderChars).topLeft, 0, 0);
3496
- ctx.fillText(get(borderChars).topRight, (cols - 1) * charSize(), 0);
3497
- ctx.fillText(get(borderChars).bottomLeft, 0, (rows - 1) * charSize());
3498
- ctx.fillText(get(borderChars).bottomRight, (cols - 1) * charSize(), (rows - 1) * charSize());
3499
- for (let col = 1; col < cols - 1; col++) {
3500
- const animIndex = (col + offset) % 2;
3501
- const topChar = animated() && animIndex === 0 ? " " : get(borderChars).horizontal;
3502
- const bottomChar = animated() && animIndex === 1 ? " " : get(borderChars).horizontal;
3503
- if (topChar !== " ") {
3504
- ctx.fillText(topChar, col * charSize(), 0);
3505
- }
3506
- if (bottomChar !== " ") {
3507
- ctx.fillText(bottomChar, col * charSize(), (rows - 1) * charSize());
3508
- }
3509
- }
3510
- for (let row = 1; row < rows - 1; row++) {
3511
- const animIndex = (row + offset) % 2;
3512
- const leftChar = animated() && animIndex === 0 ? " " : get(borderChars).vertical;
3513
- const rightChar = animated() && animIndex === 1 ? " " : get(borderChars).vertical;
3514
- if (leftChar !== " ") {
3515
- ctx.fillText(leftChar, 0, row * charSize());
3516
- }
3517
- if (rightChar !== " ") {
3518
- ctx.fillText(rightChar, (cols - 1) * charSize(), row * charSize());
3519
- }
3520
- }
3521
- for (let t = 1; t < thickness(); t++) {
3522
- const innerCol = t;
3523
- const outerCol = cols - 1 - t;
3524
- const innerRow = t;
3525
- const outerRow = rows - 1 - t;
3526
- for (let col = innerCol; col <= outerCol; col++) {
3527
- ctx.fillText(get(borderChars).horizontal, col * charSize(), innerRow * charSize());
3528
- ctx.fillText(get(borderChars).horizontal, col * charSize(), outerRow * charSize());
3529
- }
3530
- for (let row = innerRow; row <= outerRow; row++) {
3531
- ctx.fillText(get(borderChars).vertical, innerCol * charSize(), row * charSize());
3532
- ctx.fillText(get(borderChars).vertical, outerCol * charSize(), row * charSize());
3533
- }
3534
- }
3535
- }
3536
- let startTime = 0;
3537
- function animate(currentTime) {
3538
- if (!get(shouldAnimate)) return;
3539
- const elapsed = currentTime - startTime;
3540
- renderBorder(elapsed);
3541
- animationId = requestAnimationFrame(animate);
3542
- }
3543
- function startAnimation() {
3544
- if (animationId !== null) return;
3545
- startTime = performance.now();
3546
- animationId = requestAnimationFrame(animate);
3547
- }
3548
- function stopAnimation() {
3549
- if (animationId !== null) {
3550
- cancelAnimationFrame(animationId);
3551
- animationId = null;
3552
- }
3553
- }
3554
- function setupCanvas(width, height) {
3555
- if (!canvas) return;
3556
- borderWidth = width;
3557
- borderHeight = height;
3558
- canvas.width = width;
3559
- canvas.height = height;
3560
- if (get(shouldAnimate)) {
3561
- startAnimation();
3562
- } else {
3563
- renderBorder();
3564
- }
3565
- }
3566
- onMount(() => {
3567
- const cleanupMotion = onReducedMotionChange((prefers) => {
3568
- reducedMotion = prefers;
3569
- });
3570
- const cleanupVisibility = createVisibilityObserver(
3571
- container,
3572
- (visible) => {
3573
- isVisible = visible;
3574
- if (visible && get(shouldAnimate)) {
3575
- startAnimation();
3576
- } else {
3577
- stopAnimation();
3578
- }
3579
- },
3580
- 0.1
3581
- );
3582
- const cleanupResize = createResizeObserver(
3583
- container,
3584
- (width, height) => {
3585
- setupCanvas(width, height);
3586
- },
3587
- 100
3588
- );
3589
- const rect = container.getBoundingClientRect();
3590
- if (rect.width > 0 && rect.height > 0) {
3591
- setupCanvas(rect.width, rect.height);
3592
- }
3593
- return () => {
3594
- cleanupMotion();
3595
- cleanupVisibility();
3596
- cleanupResize();
3597
- stopAnimation();
3598
- };
3599
- });
3600
- user_effect(() => {
3601
- if (get(shouldAnimate)) {
3602
- startAnimation();
3603
- } else {
3604
- stopAnimation();
3605
- renderBorder();
3606
- }
3607
- });
3608
- var div = root();
3609
- let styles;
3610
- var canvas_1 = child(div);
3611
- bind_this(canvas_1, ($$value) => canvas = $$value, () => canvas);
3612
- var div_1 = sibling(canvas_1, 2);
3613
- var node = child(div_1);
3614
- slot(node, $$props, "default", {});
3615
- bind_this(div, ($$value) => container = $$value, () => container);
3616
- template_effect(() => {
3617
- set_class(div, 1, `gossamer-border ${className() ?? ""}`, "svelte-qe7ze6");
3618
- styles = set_style(div, "", styles, { padding: `${padding() ?? ""}px` });
3619
- });
3620
- append($$anchor, div);
3621
- pop();
3622
- }
3623
- export {
3624
- CHARACTER_SETS,
3625
- DEFAULT_CHARACTERS,
3626
- DEFAULT_CONFIG,
3627
- GossamerBorder,
3628
- GossamerClouds,
3629
- GossamerImage,
3630
- GossamerOverlay,
3631
- GossamerText,
3632
- PRESETS,
3633
- VERSION,
3634
- ambientPresets,
3635
- brightnessToChar,
3636
- calculateBrightness,
3637
- getCharacterSet,
3638
- getCharacterSetNames,
3639
- getCharacters,
3640
- getPreset,
3641
- getPresetNames,
3642
- getPresetsByCategory,
3643
- grovePresets,
3644
- invertCharacters,
3645
- prefersReducedMotion,
3646
- seasonalPresets
3647
- };
3648
- //# sourceMappingURL=index.js.map
8
+ // =============================================================================
9
+ // Components
10
+ // =============================================================================
11
+ export { default as GossamerClouds } from './GossamerClouds.svelte';
12
+ export { default as GossamerImage } from './GossamerImage.svelte';
13
+ export { default as GossamerText } from './GossamerText.svelte';
14
+ export { default as GossamerOverlay } from './GossamerOverlay.svelte';
15
+ export { default as GossamerBorder } from './GossamerBorder.svelte';
16
+ // =============================================================================
17
+ // Presets
18
+ // =============================================================================
19
+ export { PRESETS, grovePresets, seasonalPresets, ambientPresets, getPreset, getPresetNames, getPresetsByCategory, } from './presets';
20
+ // =============================================================================
21
+ // Re-exports from Core
22
+ // =============================================================================
23
+ export {
24
+ // Constants
25
+ DEFAULT_CHARACTERS, DEFAULT_CONFIG, CHARACTER_SETS,
26
+ // Core functions
27
+ calculateBrightness, brightnessToChar,
28
+ // Character utilities
29
+ getCharacterSet, getCharacters, getCharacterSetNames, invertCharacters,
30
+ // Performance utilities
31
+ prefersReducedMotion,
32
+ // Version
33
+ VERSION, } from '../index';