@vesk/runtime 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +23 -0
  2. package/dist/action.d.ts +43 -0
  3. package/dist/action.d.ts.map +1 -0
  4. package/dist/action.js +84 -0
  5. package/dist/bindings.d.ts +4 -0
  6. package/dist/bindings.d.ts.map +1 -0
  7. package/dist/bindings.js +137 -0
  8. package/dist/context.d.ts +15 -0
  9. package/dist/context.d.ts.map +1 -0
  10. package/dist/context.js +34 -0
  11. package/dist/experiment.d.ts +17 -0
  12. package/dist/experiment.d.ts.map +1 -0
  13. package/dist/experiment.js +71 -0
  14. package/dist/form.d.ts +36 -0
  15. package/dist/form.d.ts.map +1 -0
  16. package/dist/form.js +278 -0
  17. package/dist/hmr-client.d.ts +1 -0
  18. package/dist/hmr-client.d.ts.map +1 -0
  19. package/dist/hmr-client.js +273 -0
  20. package/dist/hydrate.d.ts +34 -0
  21. package/dist/hydrate.d.ts.map +1 -0
  22. package/dist/hydrate.js +248 -0
  23. package/dist/image.d.ts +19 -0
  24. package/dist/image.d.ts.map +1 -0
  25. package/dist/image.js +51 -0
  26. package/dist/index-client.d.ts +16 -0
  27. package/dist/index-client.d.ts.map +1 -0
  28. package/dist/index-client.js +15 -0
  29. package/dist/index-server.d.ts +15 -0
  30. package/dist/index-server.d.ts.map +1 -0
  31. package/dist/index-server.js +14 -0
  32. package/dist/isr.d.ts +27 -0
  33. package/dist/isr.d.ts.map +1 -0
  34. package/dist/isr.js +143 -0
  35. package/dist/md.d.ts +17 -0
  36. package/dist/md.d.ts.map +1 -0
  37. package/dist/md.js +507 -0
  38. package/dist/package.json +23 -0
  39. package/dist/portal.d.ts +8 -0
  40. package/dist/portal.d.ts.map +1 -0
  41. package/dist/portal.js +20 -0
  42. package/dist/reconcile.d.ts +3 -0
  43. package/dist/reconcile.d.ts.map +1 -0
  44. package/dist/reconcile.js +66 -0
  45. package/dist/request.d.ts +188 -0
  46. package/dist/request.d.ts.map +1 -0
  47. package/dist/request.js +624 -0
  48. package/dist/resource.d.ts +47 -0
  49. package/dist/resource.d.ts.map +1 -0
  50. package/dist/resource.js +502 -0
  51. package/dist/ripple-blocks.d.ts +18 -0
  52. package/dist/ripple-blocks.d.ts.map +1 -0
  53. package/dist/ripple-blocks.js +184 -0
  54. package/dist/ripple-constants.d.ts +42 -0
  55. package/dist/ripple-constants.d.ts.map +1 -0
  56. package/dist/ripple-constants.js +41 -0
  57. package/dist/ripple-runtime.d.ts +125 -0
  58. package/dist/ripple-runtime.d.ts.map +1 -0
  59. package/dist/ripple-runtime.js +891 -0
  60. package/dist/ripple-utils.d.ts +12 -0
  61. package/dist/ripple-utils.d.ts.map +1 -0
  62. package/dist/ripple-utils.js +10 -0
  63. package/dist/router-components.d.ts +83 -0
  64. package/dist/router-components.d.ts.map +1 -0
  65. package/dist/router-components.js +320 -0
  66. package/dist/router-match.d.ts +40 -0
  67. package/dist/router-match.d.ts.map +1 -0
  68. package/dist/router-match.js +158 -0
  69. package/dist/router.d.ts +56 -0
  70. package/dist/router.d.ts.map +1 -0
  71. package/dist/router.js +1330 -0
  72. package/dist/seo.d.ts +94 -0
  73. package/dist/seo.d.ts.map +1 -0
  74. package/dist/seo.js +138 -0
  75. package/dist/suspense.d.ts +1 -0
  76. package/dist/suspense.d.ts.map +1 -0
  77. package/dist/suspense.js +14 -0
  78. package/dist/track.d.ts +20 -0
  79. package/dist/track.d.ts.map +1 -0
  80. package/dist/track.js +124 -0
  81. package/package.json +55 -0
@@ -0,0 +1,891 @@
1
+ import { destroy_block as _destroy_block, destroy_non_branch_children, effect as _effect, } from '@vesk/runtime/src/ripple-blocks';
2
+ export { destroy_non_branch_children };
3
+ import { ASYNC_DERIVED_READ_THROWN, BLOCK_HAS_RUN, BRANCH_BLOCK, DERIVED, COMPUTED_PROPERTY, CONTAINS_TEARDOWN, CONTAINS_UPDATE, DESTROYED, EFFECT_BLOCK, PAUSED, PRE_EFFECT_BLOCK, ROOT_BLOCK, TRACKED, UNINITIALIZED, TRACKED_OBJECT, DEFAULT_NAMESPACE, SUSPENSE_PENDING, SUSPENSE_REJECTED, UPDATE_SOURCE, } from '@vesk/runtime/src/ripple-constants';
4
+ import { is_ripple_object, define_property, get_descriptor, is_array, object_keys, get_own_property_symbols } from '@vesk/runtime/src/ripple-utils';
5
+ const FLUSH_MICROTASK = 0;
6
+ const FLUSH_SYNC = 1;
7
+ export let active_block = null;
8
+ export let active_reaction = null;
9
+ export let active_scope = null;
10
+ export let active_component = null;
11
+ export let active_namespace = DEFAULT_NAMESPACE;
12
+ export let is_mutating_allowed = true;
13
+ const old_values = new Map();
14
+ let scheduler_mode = FLUSH_MICROTASK;
15
+ let is_micro_task_queued = false;
16
+ let clock = 0;
17
+ let queued_root_blocks = [];
18
+ export let disable_scoped_flush = false;
19
+ let queued_microtasks = [];
20
+ let flush_count = 0;
21
+ const queued_post_block_flush = [];
22
+ let active_dependency = null;
23
+ export let tracking = false;
24
+ export let teardown = false;
25
+ function increment_clock() {
26
+ return ++clock;
27
+ }
28
+ export function set_active_block(block) {
29
+ active_block = block;
30
+ }
31
+ export function set_active_reaction(reaction) {
32
+ active_reaction = reaction;
33
+ }
34
+ export function set_active_component(component) {
35
+ active_component = component;
36
+ }
37
+ export function set_tracking(value) {
38
+ tracking = value;
39
+ }
40
+ export function run_teardown(block) {
41
+ const fn = block.t;
42
+ const callbacks = block.tc;
43
+ if (fn !== null || callbacks !== null) {
44
+ const previous_block = active_block;
45
+ const previous_reaction = active_reaction;
46
+ const previous_tracking = tracking;
47
+ const previous_teardown = teardown;
48
+ try {
49
+ active_block = null;
50
+ active_reaction = null;
51
+ tracking = false;
52
+ teardown = true;
53
+ if (fn !== null)
54
+ fn.call(null);
55
+ if (callbacks !== null) {
56
+ for (let i = 0; i < callbacks.length; i++) {
57
+ callbacks[i]();
58
+ }
59
+ }
60
+ }
61
+ finally {
62
+ active_block = previous_block;
63
+ active_reaction = previous_reaction;
64
+ tracking = previous_tracking;
65
+ teardown = previous_teardown;
66
+ }
67
+ }
68
+ }
69
+ export function on_destroy(fn) {
70
+ const block = scope();
71
+ if (block === null)
72
+ return;
73
+ if (block.tc === null)
74
+ block.tc = [];
75
+ block.tc.push(fn);
76
+ }
77
+ export function with_block(block, fn) {
78
+ const prev_block = active_block;
79
+ const previous_component = active_component;
80
+ active_block = block;
81
+ active_component = block.co;
82
+ try {
83
+ return fn();
84
+ }
85
+ finally {
86
+ active_component = previous_component;
87
+ active_block = prev_block;
88
+ }
89
+ }
90
+ function update_derived(computed) {
91
+ let value = computed.__v;
92
+ if (value === UNINITIALIZED || is_tracking_dirty(computed.d)) {
93
+ value = run_derived(computed);
94
+ if (value !== computed.__v) {
95
+ computed.__v = value;
96
+ computed.c = increment_clock();
97
+ }
98
+ }
99
+ }
100
+ function update_tracked_value_clock(tracked, value) {
101
+ tracked.__v = value;
102
+ tracked.c = increment_clock();
103
+ }
104
+ function destroy_computed_children(computed) {
105
+ const blocks = computed.blocks;
106
+ if (blocks !== null) {
107
+ computed.blocks = null;
108
+ for (let i = 0; i < blocks.length; i++) {
109
+ _destroy_block(blocks[i]);
110
+ }
111
+ }
112
+ }
113
+ function run_derived(computed) {
114
+ const previous_block = active_block;
115
+ const previous_reaction = active_reaction;
116
+ const previous_tracking = tracking;
117
+ const previous_dependency = active_dependency;
118
+ const previous_component = active_component;
119
+ const previous_is_mutating_allowed = is_mutating_allowed;
120
+ try {
121
+ active_block = computed.b;
122
+ active_reaction = computed;
123
+ tracking = true;
124
+ active_dependency = null;
125
+ active_component = computed.co;
126
+ is_mutating_allowed = false;
127
+ destroy_computed_children(computed);
128
+ const value = computed.fn();
129
+ computed.d = active_dependency;
130
+ return value;
131
+ }
132
+ catch (error) {
133
+ computed.d = active_dependency;
134
+ if (error === ASYNC_DERIVED_READ_THROWN) {
135
+ let dep = active_dependency;
136
+ while (dep !== null) {
137
+ if (dep.t.__v === SUSPENSE_REJECTED) {
138
+ return SUSPENSE_REJECTED;
139
+ }
140
+ dep = dep.n;
141
+ }
142
+ return SUSPENSE_PENDING;
143
+ }
144
+ throw error;
145
+ }
146
+ finally {
147
+ active_block = previous_block;
148
+ active_reaction = previous_reaction;
149
+ tracking = previous_tracking;
150
+ active_dependency = previous_dependency;
151
+ active_component = previous_component;
152
+ is_mutating_allowed = previous_is_mutating_allowed;
153
+ }
154
+ }
155
+ export function handle_error(error, _block) {
156
+ throw error;
157
+ }
158
+ export function run_block(block) {
159
+ const previous_block = active_block;
160
+ const previous_reaction = active_reaction;
161
+ const previous_tracking = tracking;
162
+ const previous_dependency = active_dependency;
163
+ const previous_component = active_component;
164
+ try {
165
+ active_block = block;
166
+ active_reaction = block;
167
+ active_component = block.co;
168
+ destroy_non_branch_children(block);
169
+ run_teardown(block);
170
+ tracking = (block.f & (ROOT_BLOCK | BRANCH_BLOCK)) === 0;
171
+ active_dependency = null;
172
+ const res = block.fn(block.s);
173
+ if (typeof res === 'function') {
174
+ block.t = res;
175
+ let current = block;
176
+ while (current !== null && (current.f & CONTAINS_TEARDOWN) === 0) {
177
+ current.f ^= CONTAINS_TEARDOWN;
178
+ current = current.p;
179
+ }
180
+ }
181
+ block.d = active_dependency;
182
+ }
183
+ catch (error) {
184
+ block.d = active_dependency;
185
+ if (error !== ASYNC_DERIVED_READ_THROWN) {
186
+ handle_error(error, block);
187
+ }
188
+ }
189
+ finally {
190
+ active_block = previous_block;
191
+ active_reaction = previous_reaction;
192
+ tracking = previous_tracking;
193
+ active_dependency = previous_dependency;
194
+ active_component = previous_component;
195
+ }
196
+ }
197
+ const empty_get_set = { get: undefined, set: undefined };
198
+ class TrackedValue {
199
+ a;
200
+ b;
201
+ c;
202
+ d;
203
+ f;
204
+ __v;
205
+ constructor(v, block, a) {
206
+ this.a = a;
207
+ this.b = block;
208
+ this.c = 0;
209
+ this.d = null;
210
+ this.f = TRACKED;
211
+ this.__v = v;
212
+ }
213
+ get [0]() {
214
+ return get_tracked(this);
215
+ }
216
+ set [0](v) {
217
+ set(this, v);
218
+ }
219
+ get [1]() {
220
+ return this;
221
+ }
222
+ get value() {
223
+ return get_tracked(this);
224
+ }
225
+ set value(v) {
226
+ set(this, v);
227
+ }
228
+ get length() {
229
+ return 2;
230
+ }
231
+ *[Symbol.iterator]() {
232
+ yield get_tracked(this);
233
+ yield this;
234
+ }
235
+ }
236
+ class DerivedValue {
237
+ a;
238
+ b;
239
+ blocks;
240
+ c;
241
+ co;
242
+ d;
243
+ f;
244
+ fn;
245
+ __v;
246
+ constructor(fn, block, a) {
247
+ this.a = a;
248
+ this.b = block;
249
+ this.blocks = null;
250
+ this.c = 0;
251
+ this.co = active_component;
252
+ this.d = null;
253
+ this.f = DERIVED;
254
+ this.fn = fn;
255
+ this.__v = UNINITIALIZED;
256
+ }
257
+ get [0]() {
258
+ return get_derived(this);
259
+ }
260
+ set [0](v) {
261
+ set(this, v);
262
+ }
263
+ get [1]() {
264
+ return this;
265
+ }
266
+ get value() {
267
+ return get_derived(this);
268
+ }
269
+ set value(v) {
270
+ set(this, v);
271
+ }
272
+ get length() {
273
+ return 2;
274
+ }
275
+ *[Symbol.iterator]() {
276
+ yield get_derived(this);
277
+ yield this;
278
+ }
279
+ }
280
+ export function tracked(v, block, get, set) {
281
+ return new TrackedValue(v, block || active_block, get || set ? { get, set } : empty_get_set);
282
+ }
283
+ export function derived(fn, block, get, set) {
284
+ return new DerivedValue(fn, block || active_block, get || set ? { get, set } : empty_get_set);
285
+ }
286
+ export function track(v, b, get, set) {
287
+ if (is_ripple_object(v)) {
288
+ return v;
289
+ }
290
+ let hookGet;
291
+ let hookSet;
292
+ if (typeof b === 'function') {
293
+ hookSet = (set === undefined ? get : set);
294
+ hookGet = b;
295
+ b = undefined;
296
+ }
297
+ else {
298
+ hookGet = get;
299
+ hookSet = set;
300
+ }
301
+ if (typeof v === 'function') {
302
+ return derived(v, b, hookGet, hookSet);
303
+ }
304
+ return tracked(v, b, hookGet, hookSet);
305
+ }
306
+ function create_dependency(tracked) {
307
+ const reaction = active_reaction;
308
+ const existing = reaction.d;
309
+ if (existing !== null) {
310
+ reaction.d = existing.n;
311
+ existing.c = tracked.c;
312
+ existing.t = tracked;
313
+ existing.n = null;
314
+ return existing;
315
+ }
316
+ return {
317
+ c: tracked.c,
318
+ t: tracked,
319
+ n: null,
320
+ };
321
+ }
322
+ function is_tracking_dirty(tracking) {
323
+ if (tracking === null) {
324
+ return false;
325
+ }
326
+ while (tracking !== null) {
327
+ const t = tracking.t;
328
+ if ((t.f & DERIVED) !== 0) {
329
+ try {
330
+ update_derived(t);
331
+ }
332
+ catch (e) {
333
+ if (e === ASYNC_DERIVED_READ_THROWN) {
334
+ return true;
335
+ }
336
+ throw e;
337
+ }
338
+ }
339
+ if (t.c > tracking.c) {
340
+ return true;
341
+ }
342
+ tracking = tracking.n;
343
+ }
344
+ return false;
345
+ }
346
+ export function is_block_dirty(block) {
347
+ const flags = block.f;
348
+ if ((flags & (ROOT_BLOCK | BRANCH_BLOCK)) !== 0) {
349
+ return false;
350
+ }
351
+ if ((flags & BLOCK_HAS_RUN) === 0) {
352
+ block.f ^= BLOCK_HAS_RUN;
353
+ return true;
354
+ }
355
+ return is_tracking_dirty(block.d);
356
+ }
357
+ function flush_updates(root_block) {
358
+ let current = root_block;
359
+ const pre_effects = [];
360
+ const other_blocks = [];
361
+ const effects = [];
362
+ let scope_root = disable_scoped_flush ? root_block : null;
363
+ while (current !== null) {
364
+ const flags = current.f;
365
+ const on_path = (flags & CONTAINS_UPDATE) !== 0;
366
+ if (on_path) {
367
+ current.f ^= CONTAINS_UPDATE;
368
+ }
369
+ if ((flags & UPDATE_SOURCE) !== 0) {
370
+ current.f ^= UPDATE_SOURCE;
371
+ if (scope_root === null) {
372
+ scope_root = current;
373
+ }
374
+ }
375
+ if ((flags & PAUSED) === 0 && (on_path || scope_root !== null)) {
376
+ if ((flags & PRE_EFFECT_BLOCK) !== 0) {
377
+ pre_effects.push(current);
378
+ }
379
+ else if ((flags & EFFECT_BLOCK) !== 0) {
380
+ effects.push(current);
381
+ }
382
+ else {
383
+ other_blocks.push(current);
384
+ }
385
+ const child = current.first;
386
+ if (child !== null) {
387
+ current = child;
388
+ continue;
389
+ }
390
+ }
391
+ let parent = current.p;
392
+ current = current.next;
393
+ while (current === null && parent !== null) {
394
+ if (parent === scope_root) {
395
+ scope_root = null;
396
+ }
397
+ current = parent.next;
398
+ parent = parent.p;
399
+ }
400
+ }
401
+ let arr_length = 0;
402
+ arr_length = pre_effects.length;
403
+ for (let i = 0; i < arr_length; i++) {
404
+ const block = pre_effects[i];
405
+ try {
406
+ if ((block.f & (PAUSED | DESTROYED)) === 0 && is_block_dirty(block)) {
407
+ run_block(block);
408
+ }
409
+ }
410
+ catch (error) {
411
+ handle_error(error, block);
412
+ }
413
+ }
414
+ arr_length = other_blocks.length;
415
+ for (let i = 0; i < arr_length; i++) {
416
+ const block = other_blocks[i];
417
+ try {
418
+ if ((block.f & (PAUSED | DESTROYED)) === 0 && is_block_dirty(block)) {
419
+ run_block(block);
420
+ }
421
+ }
422
+ catch (error) {
423
+ handle_error(error, block);
424
+ }
425
+ }
426
+ arr_length = effects.length;
427
+ for (let i = 0; i < arr_length; i++) {
428
+ const block = effects[i];
429
+ try {
430
+ if ((block.f & (PAUSED | DESTROYED)) === 0 && is_block_dirty(block)) {
431
+ run_block(block);
432
+ }
433
+ }
434
+ catch (error) {
435
+ handle_error(error, block);
436
+ }
437
+ }
438
+ }
439
+ function flush_queued_root_blocks(root_blocks) {
440
+ for (let i = 0; i < root_blocks.length; i++) {
441
+ flush_updates(root_blocks[i]);
442
+ }
443
+ if (queued_post_block_flush.length > 0) {
444
+ const callbacks = queued_post_block_flush;
445
+ queued_post_block_flush.length = 0;
446
+ for (let j = 0; j < callbacks.length; j++) {
447
+ callbacks[j]();
448
+ }
449
+ }
450
+ }
451
+ export async function tick() {
452
+ return new Promise((f) => requestAnimationFrame(() => f()));
453
+ }
454
+ function flush_microtasks() {
455
+ is_micro_task_queued = false;
456
+ if (queued_microtasks.length > 0) {
457
+ const microtasks = queued_microtasks;
458
+ queued_microtasks = [];
459
+ for (let i = 0; i < microtasks.length; i++) {
460
+ microtasks[i]();
461
+ }
462
+ }
463
+ flush_count++;
464
+ if (flush_count > 1001) {
465
+ throw new Error('Maximum update depth exceeded. This typically indicates that an effect reads and writes the same piece of state.');
466
+ }
467
+ const previous_queued_root_blocks = queued_root_blocks;
468
+ queued_root_blocks = [];
469
+ flush_queued_root_blocks(previous_queued_root_blocks);
470
+ if (!is_micro_task_queued) {
471
+ flush_count = 0;
472
+ }
473
+ old_values.clear();
474
+ }
475
+ export function queue_microtask(fn) {
476
+ if (!is_micro_task_queued) {
477
+ is_micro_task_queued = true;
478
+ queueMicrotask(flush_microtasks);
479
+ }
480
+ if (fn !== undefined) {
481
+ queued_microtasks.push(fn);
482
+ }
483
+ }
484
+ export function queue_post_block_flush_callback(fn) {
485
+ queued_post_block_flush.push(fn);
486
+ }
487
+ export function schedule_update(block) {
488
+ if (block === null)
489
+ return;
490
+ if (scheduler_mode === FLUSH_MICROTASK) {
491
+ queue_microtask();
492
+ }
493
+ block.f |= UPDATE_SOURCE;
494
+ let current = block;
495
+ while (current !== null) {
496
+ const flags = current.f;
497
+ if ((flags & CONTAINS_UPDATE) !== 0)
498
+ return;
499
+ current.f ^= CONTAINS_UPDATE;
500
+ if ((flags & ROOT_BLOCK) !== 0) {
501
+ break;
502
+ }
503
+ current = current.p;
504
+ }
505
+ queued_root_blocks.push(current);
506
+ }
507
+ function register_dependency(tracked) {
508
+ if (!disable_scoped_flush && active_block !== null && active_block !== tracked.b) {
509
+ let already_seen = false;
510
+ let prev_dep = active_reaction === null ? null : active_reaction.d;
511
+ while (prev_dep !== null) {
512
+ if (prev_dep.t === tracked) {
513
+ already_seen = true;
514
+ break;
515
+ }
516
+ prev_dep = prev_dep.n;
517
+ }
518
+ if (!already_seen) {
519
+ const owner = tracked.b;
520
+ let node = active_block;
521
+ while (node !== null && node !== owner) {
522
+ node = node.p;
523
+ }
524
+ if (node === null) {
525
+ disable_scoped_flush = true;
526
+ }
527
+ }
528
+ }
529
+ let dependency = active_dependency;
530
+ if (dependency === null) {
531
+ dependency = create_dependency(tracked);
532
+ active_dependency = dependency;
533
+ }
534
+ else {
535
+ let current = dependency;
536
+ while (current !== null) {
537
+ if (current.t === tracked) {
538
+ current.c = tracked.c;
539
+ return;
540
+ }
541
+ const next = current.n;
542
+ if (next === null) {
543
+ break;
544
+ }
545
+ current = next;
546
+ }
547
+ dependency = create_dependency(tracked);
548
+ current.n = dependency;
549
+ }
550
+ }
551
+ export function get_derived(computed) {
552
+ update_derived(computed);
553
+ if (tracking) {
554
+ register_dependency(computed);
555
+ }
556
+ let value = computed.__v;
557
+ const get = computed.a.get;
558
+ if (get !== undefined) {
559
+ value = trigger_track_get(get, value);
560
+ computed.__v = value;
561
+ }
562
+ if (value === SUSPENSE_PENDING || value === SUSPENSE_REJECTED) {
563
+ throw ASYNC_DERIVED_READ_THROWN;
564
+ }
565
+ return value;
566
+ }
567
+ export function get(t) {
568
+ if (!is_ripple_object(t)) {
569
+ return t;
570
+ }
571
+ return t.f & DERIVED
572
+ ? get_derived(t)
573
+ : get_tracked(t);
574
+ }
575
+ export function get_tracked(tracked) {
576
+ let value = tracked.__v;
577
+ if (tracking) {
578
+ register_dependency(tracked);
579
+ }
580
+ if (value === SUSPENSE_PENDING || value === SUSPENSE_REJECTED) {
581
+ throw ASYNC_DERIVED_READ_THROWN;
582
+ }
583
+ if (teardown && old_values.has(tracked)) {
584
+ value = old_values.get(tracked);
585
+ }
586
+ const get = tracked.a.get;
587
+ if (get !== undefined) {
588
+ value = trigger_track_get(get, value);
589
+ }
590
+ return value;
591
+ }
592
+ export function is_tracked_pending(t) {
593
+ try {
594
+ if (typeof t === 'function') {
595
+ t();
596
+ }
597
+ else {
598
+ get(t);
599
+ }
600
+ return false;
601
+ }
602
+ catch (error) {
603
+ if (error === ASYNC_DERIVED_READ_THROWN) {
604
+ return true;
605
+ }
606
+ throw error;
607
+ }
608
+ }
609
+ export function peek_tracked(tracked) {
610
+ if (!is_ripple_object(tracked)) {
611
+ return tracked;
612
+ }
613
+ return tracked.__v;
614
+ }
615
+ export function set(tracked, value) {
616
+ if (!is_mutating_allowed) {
617
+ throw new Error('Assignments or updates to tracked values are not allowed during computed "track(() => ...)" evaluation');
618
+ }
619
+ const old_value = tracked.__v;
620
+ if (value !== old_value) {
621
+ const tracked_block = tracked.b;
622
+ if (tracked_block !== null && (tracked_block.f & CONTAINS_TEARDOWN) !== 0) {
623
+ if (teardown) {
624
+ old_values.set(tracked, value);
625
+ }
626
+ else {
627
+ old_values.set(tracked, old_value);
628
+ }
629
+ }
630
+ const setFn = tracked.a.set;
631
+ if (setFn !== undefined) {
632
+ value = untrack(() => setFn(value, old_value));
633
+ }
634
+ tracked.__v = value;
635
+ tracked.c = increment_clock();
636
+ schedule_update(tracked_block);
637
+ }
638
+ }
639
+ export function untrack(fn) {
640
+ const previous_tracking = tracking;
641
+ const previous_dependency = active_dependency;
642
+ tracking = false;
643
+ active_dependency = null;
644
+ try {
645
+ return fn();
646
+ }
647
+ finally {
648
+ tracking = previous_tracking;
649
+ active_dependency = previous_dependency;
650
+ }
651
+ }
652
+ export function flush_sync(fn) {
653
+ const previous_scheduler_mode = scheduler_mode;
654
+ const previous_queued_root_blocks = queued_root_blocks;
655
+ try {
656
+ const root_blocks = [];
657
+ scheduler_mode = FLUSH_SYNC;
658
+ queued_root_blocks = root_blocks;
659
+ is_micro_task_queued = false;
660
+ flush_queued_root_blocks(previous_queued_root_blocks);
661
+ const result = fn?.();
662
+ if (queued_root_blocks.length > 0 || root_blocks.length > 0) {
663
+ flush_sync();
664
+ }
665
+ flush_count = 0;
666
+ return result;
667
+ }
668
+ finally {
669
+ scheduler_mode = previous_scheduler_mode;
670
+ queued_root_blocks = previous_queued_root_blocks;
671
+ }
672
+ }
673
+ function trigger_track_get(fn, v) {
674
+ let previous_is_mutating_allowed = is_mutating_allowed;
675
+ try {
676
+ is_mutating_allowed = false;
677
+ return untrack(() => fn(v));
678
+ }
679
+ finally {
680
+ is_mutating_allowed = previous_is_mutating_allowed;
681
+ }
682
+ }
683
+ export function spread_props(fn) {
684
+ return proxy_props(fn);
685
+ }
686
+ export function proxy_props(fn) {
687
+ const memo = derived(fn, active_block);
688
+ return new Proxy({}, {
689
+ get(_, property) {
690
+ const obj = get_derived(memo);
691
+ if (is_array(obj)) {
692
+ let item;
693
+ for (let i = obj.length - 1; i >= 0; i--) {
694
+ item = obj[i];
695
+ if (property in item) {
696
+ return item[property];
697
+ }
698
+ }
699
+ return undefined;
700
+ }
701
+ return obj[property];
702
+ },
703
+ has(_, property) {
704
+ if (property === TRACKED_OBJECT) {
705
+ return true;
706
+ }
707
+ const obj = get_derived(memo);
708
+ if (is_array(obj)) {
709
+ for (let i = obj.length - 1; i >= 0; i--) {
710
+ if (property in obj[i]) {
711
+ return true;
712
+ }
713
+ }
714
+ return false;
715
+ }
716
+ return property in obj;
717
+ },
718
+ getOwnPropertyDescriptor(_, key) {
719
+ const obj = get_derived(memo);
720
+ if (is_array(obj)) {
721
+ let item;
722
+ for (let i = obj.length - 1; i >= 0; i--) {
723
+ item = obj[i];
724
+ if (key in item) {
725
+ return get_descriptor(item, key);
726
+ }
727
+ }
728
+ return undefined;
729
+ }
730
+ if (key in obj) {
731
+ return get_descriptor(obj, key);
732
+ }
733
+ return undefined;
734
+ },
735
+ ownKeys() {
736
+ const obj = get_derived(memo);
737
+ const done = {};
738
+ const keys = [];
739
+ if (is_array(obj)) {
740
+ let item;
741
+ for (let i = 0; i < obj.length; i++) {
742
+ item = obj[i];
743
+ for (const key of Reflect.ownKeys(item)) {
744
+ if (done[key]) {
745
+ continue;
746
+ }
747
+ done[key] = 1;
748
+ keys.push(key);
749
+ }
750
+ }
751
+ return keys;
752
+ }
753
+ return Reflect.ownKeys(obj);
754
+ },
755
+ });
756
+ }
757
+ export function computed_property(fn) {
758
+ define_property(fn, COMPUTED_PROPERTY, {
759
+ value: true,
760
+ enumerable: false,
761
+ });
762
+ return fn;
763
+ }
764
+ export function call_property(obj, property, chain_obj, chain_prop, ...args) {
765
+ if (!chain_obj && !chain_prop) {
766
+ return obj[property].call(obj, ...args);
767
+ }
768
+ else if (chain_obj && chain_prop) {
769
+ return obj[property]?.call(obj, ...args);
770
+ }
771
+ else if (chain_obj) {
772
+ return obj[property]?.call(obj, ...args);
773
+ }
774
+ else {
775
+ return obj[property]?.call(obj, ...args);
776
+ }
777
+ }
778
+ export function get_property(obj, property, chain = false) {
779
+ if (chain && obj == null) {
780
+ return undefined;
781
+ }
782
+ const trackedVal = obj[property];
783
+ if (trackedVal == null) {
784
+ return trackedVal;
785
+ }
786
+ return get(trackedVal);
787
+ }
788
+ export function set_property(obj, property, value) {
789
+ const trackedVal = obj[property];
790
+ set(trackedVal, value);
791
+ }
792
+ export function update(tracked, d = 1) {
793
+ let value = get(tracked);
794
+ const result = d === 1 ? value++ : value--;
795
+ set(tracked, value);
796
+ return result;
797
+ }
798
+ export function increment(tracked) {
799
+ set(tracked, tracked.__v + 1);
800
+ }
801
+ export function decrement(tracked) {
802
+ set(tracked, tracked.__v - 1);
803
+ }
804
+ export function update_pre(tracked, d = 1) {
805
+ let value = get(tracked);
806
+ const new_value = d === 1 ? ++value : --value;
807
+ set(tracked, new_value);
808
+ return new_value;
809
+ }
810
+ export function update_property(obj, property, d = 1) {
811
+ const trackedVal = obj[property];
812
+ let value = get(trackedVal);
813
+ const new_value = d === 1 ? value++ : value--;
814
+ set(trackedVal, value);
815
+ return new_value;
816
+ }
817
+ export function update_pre_property(obj, property, d = 1) {
818
+ const trackedVal = obj[property];
819
+ let value = get(trackedVal);
820
+ const new_value = d === 1 ? ++value : --value;
821
+ set(trackedVal, new_value);
822
+ return new_value;
823
+ }
824
+ export function with_scope(block, fn) {
825
+ const previous_scope = active_scope;
826
+ try {
827
+ active_scope = block;
828
+ return fn();
829
+ }
830
+ finally {
831
+ active_scope = previous_scope;
832
+ }
833
+ }
834
+ export function scope() {
835
+ return active_scope || active_block;
836
+ }
837
+ export function safe_scope(err = 'Cannot access outside of a component context') {
838
+ if (active_scope === null) {
839
+ throw new Error(err);
840
+ }
841
+ return active_scope;
842
+ }
843
+ export function create_component_ctx() {
844
+ return {
845
+ b: active_block,
846
+ c: null,
847
+ e: null,
848
+ m: false,
849
+ p: active_component,
850
+ };
851
+ }
852
+ export function push_component() {
853
+ const component = create_component_ctx();
854
+ active_component = component;
855
+ }
856
+ export function pop_component() {
857
+ const component = active_component;
858
+ component.m = true;
859
+ const effects = component.e;
860
+ if (effects !== null) {
861
+ const length = effects.length;
862
+ for (let i = 0; i < length; i++) {
863
+ const { b: block, fn, r: reaction } = effects[i];
864
+ const previous_block = active_block;
865
+ const previous_reaction = active_reaction;
866
+ try {
867
+ active_block = block;
868
+ active_reaction = reaction;
869
+ _effect(fn);
870
+ }
871
+ finally {
872
+ active_block = previous_block;
873
+ active_reaction = previous_reaction;
874
+ }
875
+ }
876
+ }
877
+ active_component = component.p;
878
+ }
879
+ export function exclude_from_object(obj, exclude_keys) {
880
+ const keys = object_keys(obj);
881
+ const new_obj = {};
882
+ for (const key of keys) {
883
+ if (!exclude_keys.includes(key)) {
884
+ new_obj[key] = obj[key];
885
+ }
886
+ }
887
+ for (const symbol of get_own_property_symbols(obj)) {
888
+ new_obj[symbol] = obj[symbol];
889
+ }
890
+ return new_obj;
891
+ }