round-core 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js DELETED
@@ -1,2071 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- let reporter = null;
4
- function setErrorReporter(fn) {
5
- reporter = typeof fn === "function" ? fn : null;
6
- }
7
- __name(setErrorReporter, "setErrorReporter");
8
- function reportErrorSafe(error, info) {
9
- if (!reporter) return;
10
- try {
11
- reporter(error, info);
12
- } catch {
13
- }
14
- }
15
- __name(reportErrorSafe, "reportErrorSafe");
16
- const componentStack = [];
17
- function getCurrentComponent() {
18
- return componentStack[componentStack.length - 1];
19
- }
20
- __name(getCurrentComponent, "getCurrentComponent");
21
- function runInLifecycle(componentInstance, fn) {
22
- componentStack.push(componentInstance);
23
- try {
24
- return fn();
25
- } finally {
26
- componentStack.pop();
27
- }
28
- }
29
- __name(runInLifecycle, "runInLifecycle");
30
- function createComponentInstance() {
31
- return {
32
- mountHooks: [],
33
- unmountHooks: [],
34
- updateHooks: [],
35
- nodes: [],
36
- isMounted: false,
37
- mountTimerId: null
38
- };
39
- }
40
- __name(createComponentInstance, "createComponentInstance");
41
- function onMount(fn) {
42
- const component = getCurrentComponent();
43
- if (component) {
44
- component.mountHooks.push(fn);
45
- } else {
46
- try {
47
- fn();
48
- } catch (e) {
49
- reportErrorSafe(e, { phase: "onMount" });
50
- }
51
- }
52
- }
53
- __name(onMount, "onMount");
54
- function onUnmount(fn) {
55
- const component = getCurrentComponent();
56
- if (component) {
57
- component.unmountHooks.push(fn);
58
- }
59
- }
60
- __name(onUnmount, "onUnmount");
61
- const onCleanup = onUnmount;
62
- function onUpdate(fn) {
63
- const component = getCurrentComponent();
64
- if (component) {
65
- component.updateHooks.push(fn);
66
- }
67
- }
68
- __name(onUpdate, "onUpdate");
69
- function mountComponent(component) {
70
- if (component.isMounted) return;
71
- try {
72
- const root = component?.nodes?.[0];
73
- if (root && root instanceof Node && root.isConnected === false) {
74
- return;
75
- }
76
- } catch {
77
- }
78
- component.isMounted = true;
79
- component.mountHooks.forEach((hook) => {
80
- try {
81
- const cleanup2 = hook();
82
- if (typeof cleanup2 === "function") {
83
- component.unmountHooks.push(cleanup2);
84
- }
85
- } catch (e) {
86
- reportErrorSafe(e, { phase: "mount", component: component.name ?? null });
87
- }
88
- });
89
- }
90
- __name(mountComponent, "mountComponent");
91
- function unmountComponent(component) {
92
- if (!component.isMounted) return;
93
- if (component.mountTimerId != null) {
94
- try {
95
- clearTimeout(component.mountTimerId);
96
- } catch {
97
- }
98
- component.mountTimerId = null;
99
- }
100
- component.isMounted = false;
101
- component.unmountHooks.forEach((hook) => {
102
- try {
103
- hook();
104
- } catch (e) {
105
- reportErrorSafe(e, { phase: "unmount", component: component.name ?? null });
106
- }
107
- });
108
- }
109
- __name(unmountComponent, "unmountComponent");
110
- function triggerUpdate(component) {
111
- if (!component.isMounted) return;
112
- component.updateHooks.forEach((hook) => {
113
- try {
114
- hook();
115
- } catch (e) {
116
- reportErrorSafe(e, { phase: "update", component: component.name ?? null });
117
- }
118
- });
119
- }
120
- __name(triggerUpdate, "triggerUpdate");
121
- const observer = typeof MutationObserver !== "undefined" ? new MutationObserver((mutations) => {
122
- mutations.forEach((mutation) => {
123
- if (mutation.removedNodes.length > 0) {
124
- mutation.removedNodes.forEach((node) => {
125
- if (node._componentInstance) {
126
- unmountComponent(node._componentInstance);
127
- }
128
- cleanupNodeRecursively(node);
129
- });
130
- }
131
- });
132
- }) : null;
133
- function cleanupNodeRecursively(node) {
134
- if (node._componentInstance) {
135
- unmountComponent(node._componentInstance);
136
- }
137
- node.childNodes.forEach(cleanupNodeRecursively);
138
- }
139
- __name(cleanupNodeRecursively, "cleanupNodeRecursively");
140
- function initLifecycleRoot(rootNode) {
141
- if (!rootNode) return;
142
- if (!observer) return;
143
- observer.observe(rootNode, { childList: true, subtree: true });
144
- }
145
- __name(initLifecycleRoot, "initLifecycleRoot");
146
- const Lifecycle = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
147
- __proto__: null,
148
- createComponentInstance,
149
- getCurrentComponent,
150
- initLifecycleRoot,
151
- mountComponent,
152
- onCleanup,
153
- onMount,
154
- onUnmount,
155
- onUpdate,
156
- runInLifecycle,
157
- triggerUpdate,
158
- unmountComponent
159
- }, Symbol.toStringTag, { value: "Module" }));
160
- let context = null;
161
- let batchCount = 0;
162
- let pendingEffects = [];
163
- let globalVersion = 0;
164
- function isPromiseLike$2(v) {
165
- return v && (typeof v === "object" || typeof v === "function") && typeof v.then === "function";
166
- }
167
- __name(isPromiseLike$2, "isPromiseLike$2");
168
- function isSignalLike(v) {
169
- return typeof v === "function" && typeof v.peek === "function" && "value" in v;
170
- }
171
- __name(isSignalLike, "isSignalLike");
172
- function untrack(fn) {
173
- const prev = context;
174
- context = null;
175
- try {
176
- return typeof fn === "function" ? fn() : void 0;
177
- } finally {
178
- context = prev;
179
- }
180
- }
181
- __name(untrack, "untrack");
182
- function batch(fn) {
183
- batchCount++;
184
- try {
185
- return fn();
186
- } finally {
187
- if (--batchCount === 0) {
188
- const effects = pendingEffects;
189
- pendingEffects = [];
190
- for (let i = 0; i < effects.length; i++) {
191
- effects[i].queued = false;
192
- effects[i].run();
193
- }
194
- }
195
- }
196
- }
197
- __name(batch, "batch");
198
- function subscribe(sub, dep) {
199
- let link = sub.deps;
200
- while (link) {
201
- if (link.dep === dep) return;
202
- link = link.nextDep;
203
- }
204
- link = {
205
- sub,
206
- dep,
207
- nextSub: dep.subs,
208
- prevSub: null,
209
- nextDep: sub.deps,
210
- prevDep: null
211
- };
212
- if (dep.subs) dep.subs.prevSub = link;
213
- dep.subs = link;
214
- if (sub.deps) sub.deps.prevDep = link;
215
- sub.deps = link;
216
- }
217
- __name(subscribe, "subscribe");
218
- function cleanup(sub) {
219
- let link = sub.deps;
220
- while (link) {
221
- const { dep, prevSub, nextSub } = link;
222
- if (prevSub) prevSub.nextSub = nextSub;
223
- else dep.subs = nextSub;
224
- if (nextSub) nextSub.prevSub = prevSub;
225
- link = link.nextDep;
226
- }
227
- sub.deps = null;
228
- }
229
- __name(cleanup, "cleanup");
230
- function notify(dep) {
231
- let link = dep.subs;
232
- while (link) {
233
- const sub = link.sub;
234
- if (sub.isComputed) {
235
- sub.version = -1;
236
- notify(sub);
237
- } else {
238
- if (batchCount > 0) {
239
- if (!sub.queued) {
240
- sub.queued = true;
241
- pendingEffects.push(sub);
242
- }
243
- } else {
244
- sub.run();
245
- }
246
- }
247
- link = link.nextSub;
248
- }
249
- }
250
- __name(notify, "notify");
251
- function effect(arg1, arg2, arg3) {
252
- let callback, explicitDeps = null, options = { onLoad: true };
253
- let owner = getCurrentComponent();
254
- if (typeof arg1 === "function") {
255
- callback = arg1;
256
- if (arg2 && typeof arg2 === "object") options = { ...options, ...arg2 };
257
- } else {
258
- explicitDeps = arg1;
259
- callback = arg2;
260
- if (arg3 && typeof arg3 === "object") options = { ...options, ...arg3 };
261
- }
262
- const sub = {
263
- deps: null,
264
- queued: false,
265
- run() {
266
- if (this._cleanup) {
267
- try {
268
- this._cleanup();
269
- } catch (e) {
270
- reportErrorSafe(e, { phase: "effect.cleanup", component: owner?.name });
271
- }
272
- this._cleanup = null;
273
- }
274
- cleanup(this);
275
- const prev = context;
276
- context = this;
277
- try {
278
- if (explicitDeps) {
279
- if (Array.isArray(explicitDeps)) {
280
- for (let i = 0; i < explicitDeps.length; i++) {
281
- const d = explicitDeps[i];
282
- if (typeof d === "function") d();
283
- }
284
- } else if (typeof explicitDeps === "function") {
285
- explicitDeps();
286
- }
287
- }
288
- const res = callback();
289
- if (typeof res === "function") this._cleanup = res;
290
- if (owner?.isMounted) triggerUpdate(owner);
291
- } catch (e) {
292
- if (!isPromiseLike$2(e)) reportErrorSafe(e, { phase: "effect", component: owner?.name });
293
- else throw e;
294
- } finally {
295
- context = prev;
296
- }
297
- },
298
- _cleanup: null
299
- };
300
- const dispose = /* @__PURE__ */ __name(() => {
301
- if (sub._cleanup) {
302
- try {
303
- sub._cleanup();
304
- } catch (e) {
305
- }
306
- sub._cleanup = null;
307
- }
308
- cleanup(sub);
309
- }, "dispose");
310
- if (options.onLoad) {
311
- onMount(() => sub.run());
312
- } else {
313
- sub.run();
314
- }
315
- return dispose;
316
- }
317
- __name(effect, "effect");
318
- function defineBindMarkerIfNeeded(source, target) {
319
- if (source && source.bind === true) {
320
- try {
321
- Object.defineProperty(target, "bind", { enumerable: true, value: true, configurable: true });
322
- } catch {
323
- target.bind = true;
324
- }
325
- }
326
- }
327
- __name(defineBindMarkerIfNeeded, "defineBindMarkerIfNeeded");
328
- function attachHelpers(s) {
329
- if (!s || typeof s !== "function") return s;
330
- if (typeof s.transform === "function" && typeof s.validate === "function" && typeof s.$pick === "function") return s;
331
- s.$pick = (p) => pick(s, p);
332
- s.transform = (fromInput, toOutput) => {
333
- const fromFn = typeof fromInput === "function" ? fromInput : (v) => v;
334
- const toFn = typeof toOutput === "function" ? toOutput : (v) => v;
335
- const wrapped = /* @__PURE__ */ __name(function(...args) {
336
- if (args.length > 0) return s(fromFn(args[0]));
337
- return toFn(s());
338
- }, "wrapped");
339
- wrapped.peek = () => toFn(s.peek());
340
- Object.defineProperty(wrapped, "value", {
341
- enumerable: true,
342
- configurable: true,
343
- get() {
344
- return wrapped.peek();
345
- },
346
- set(v) {
347
- wrapped(v);
348
- }
349
- });
350
- defineBindMarkerIfNeeded(s, wrapped);
351
- return attachHelpers(wrapped);
352
- };
353
- s.validate = (validator, options = {}) => {
354
- const validateFn = typeof validator === "function" ? validator : null;
355
- const error = signal(null);
356
- const validateOn = options?.validateOn || "input";
357
- const validateInitial = !!options?.validateInitial;
358
- const wrapped = /* @__PURE__ */ __name(function(...args) {
359
- if (args.length > 0) {
360
- const next = args[0];
361
- if (validateFn) {
362
- let res = true;
363
- try {
364
- res = validateFn(next, s.peek());
365
- } catch {
366
- res = "Invalid value";
367
- }
368
- if (res === true || res === void 0 || res === null) {
369
- error(null);
370
- return s(next);
371
- }
372
- error(typeof res === "string" && res.length ? res : "Invalid value");
373
- return s.peek();
374
- }
375
- error(null);
376
- return s(next);
377
- }
378
- return s();
379
- }, "wrapped");
380
- wrapped.check = () => {
381
- if (!validateFn) {
382
- error(null);
383
- return true;
384
- }
385
- const cur = s.peek();
386
- let res = true;
387
- try {
388
- res = validateFn(cur, cur);
389
- } catch {
390
- res = "Invalid value";
391
- }
392
- if (res === true || res === void 0 || res === null) {
393
- error(null);
394
- return true;
395
- }
396
- error(typeof res === "string" && res.length ? res : "Invalid value");
397
- return false;
398
- };
399
- wrapped.peek = () => s.peek();
400
- Object.defineProperty(wrapped, "value", {
401
- enumerable: true,
402
- configurable: true,
403
- get() {
404
- return wrapped.peek();
405
- },
406
- set(v) {
407
- wrapped(v);
408
- }
409
- });
410
- wrapped.error = error;
411
- wrapped.__round_validateOn = validateOn;
412
- if (validateInitial) {
413
- try {
414
- wrapped.check();
415
- } catch {
416
- }
417
- }
418
- defineBindMarkerIfNeeded(s, wrapped);
419
- return attachHelpers(wrapped);
420
- };
421
- return s;
422
- }
423
- __name(attachHelpers, "attachHelpers");
424
- function signal(initialValue) {
425
- const dep = {
426
- value: initialValue,
427
- version: 0,
428
- subs: null
429
- };
430
- const s = /* @__PURE__ */ __name(function(newValue) {
431
- if (arguments.length > 0) {
432
- if (dep.value !== newValue) {
433
- dep.value = newValue;
434
- dep.version = ++globalVersion;
435
- notify(dep);
436
- }
437
- return dep.value;
438
- }
439
- if (context) subscribe(context, dep);
440
- return dep.value;
441
- }, "s");
442
- s.peek = () => dep.value;
443
- Object.defineProperty(s, "value", {
444
- enumerable: true,
445
- configurable: true,
446
- get() {
447
- return s();
448
- },
449
- set(v) {
450
- s(v);
451
- }
452
- });
453
- return attachHelpers(s);
454
- }
455
- __name(signal, "signal");
456
- function bindable(initialValue) {
457
- const s = signal(initialValue);
458
- try {
459
- Object.defineProperty(s, "bind", { enumerable: true, value: true, configurable: true });
460
- } catch {
461
- s.bind = true;
462
- }
463
- return attachHelpers(s);
464
- }
465
- __name(bindable, "bindable");
466
- function getIn(obj, path) {
467
- let cur = obj;
468
- for (let i = 0; i < path.length; i++) {
469
- if (cur == null) return void 0;
470
- cur = cur[path[i]];
471
- }
472
- return cur;
473
- }
474
- __name(getIn, "getIn");
475
- function setIn(obj, path, value) {
476
- if (!Array.isArray(path) || path.length === 0) return value;
477
- const root = obj && typeof obj === "object" ? obj : {};
478
- const out = Array.isArray(root) ? root.slice() : { ...root };
479
- let curOut = out;
480
- let curIn = root;
481
- for (let i = 0; i < path.length - 1; i++) {
482
- const key = path[i];
483
- const nextIn = curIn && typeof curIn === "object" ? curIn[key] : void 0;
484
- const nextOut = nextIn && typeof nextIn === "object" ? Array.isArray(nextIn) ? nextIn.slice() : { ...nextIn } : {};
485
- curOut[key] = nextOut;
486
- curOut = nextOut;
487
- curIn = nextIn;
488
- }
489
- curOut[path[path.length - 1]] = value;
490
- return out;
491
- }
492
- __name(setIn, "setIn");
493
- function parsePath(path) {
494
- if (Array.isArray(path)) return path.map((p) => String(p));
495
- if (typeof path === "string") return path.split(".").filter(Boolean);
496
- return [String(path)];
497
- }
498
- __name(parsePath, "parsePath");
499
- function pick(root, path) {
500
- if (!isSignalLike(root)) throw new Error("[round] pick() expects a signal.");
501
- const pathArr = parsePath(path);
502
- const view = /* @__PURE__ */ __name(function(...args) {
503
- if (args.length > 0) {
504
- const nextRoot = setIn(root.peek(), pathArr, args[0]);
505
- return root(nextRoot);
506
- }
507
- const v = root();
508
- return getIn(v, pathArr);
509
- }, "view");
510
- view.peek = () => getIn(root.peek(), pathArr);
511
- Object.defineProperty(view, "value", {
512
- enumerable: true,
513
- configurable: true,
514
- get() {
515
- return view.peek();
516
- },
517
- set(v) {
518
- view(v);
519
- }
520
- });
521
- if (root.bind === true) {
522
- try {
523
- Object.defineProperty(view, "bind", { enumerable: true, value: true, configurable: true });
524
- } catch {
525
- view.bind = true;
526
- }
527
- }
528
- return view;
529
- }
530
- __name(pick, "pick");
531
- function createBindableObjectProxy(root, basePath) {
532
- const cache = /* @__PURE__ */ new Map();
533
- const handler = {
534
- get(_target, prop) {
535
- if (prop === Symbol.toStringTag) return "BindableObject";
536
- if (prop === "peek") return () => basePath.length ? pick(root, basePath).peek() : root.peek();
537
- if (prop === "value") return basePath.length ? pick(root, basePath).peek() : root.peek();
538
- if (prop === "bind") return true;
539
- if (prop === "$pick") {
540
- return (p) => createBindableObjectProxy(root, basePath.concat(parsePath(p)));
541
- }
542
- if (prop === "_root") return root;
543
- if (prop === "_path") return basePath.slice();
544
- const key = String(prop);
545
- const nextPath = basePath.concat(key);
546
- const cacheKey = nextPath.join(".");
547
- if (cache.has(cacheKey)) return cache.get(cacheKey);
548
- try {
549
- const stored = getIn(root.peek(), nextPath);
550
- if (isSignalLike(stored)) {
551
- cache.set(cacheKey, stored);
552
- return stored;
553
- }
554
- } catch {
555
- }
556
- const next = createBindableObjectProxy(root, nextPath);
557
- cache.set(cacheKey, next);
558
- return next;
559
- },
560
- set(_target, prop, value) {
561
- const key = String(prop);
562
- const nextPath = basePath.concat(key);
563
- try {
564
- const stored = getIn(root.peek(), nextPath);
565
- if (isSignalLike(stored)) {
566
- stored(value);
567
- return true;
568
- }
569
- } catch {
570
- }
571
- pick(root, nextPath)(value);
572
- return true;
573
- },
574
- has(_target, prop) {
575
- if (prop === "peek" || prop === "value" || prop === "bind" || prop === "$pick") return true;
576
- const v = basePath.length ? pick(root, basePath).peek() : root.peek();
577
- return v != null && Object.prototype.hasOwnProperty.call(v, prop);
578
- }
579
- };
580
- const fn = /* @__PURE__ */ __name(function(...args) {
581
- if (args.length > 0) return basePath.length ? pick(root, basePath)(args[0]) : root(args[0]);
582
- return basePath.length ? pick(root, basePath)() : root();
583
- }, "fn");
584
- fn.peek = () => basePath.length ? pick(root, basePath).peek() : root.peek();
585
- Object.defineProperty(fn, "value", { enumerable: true, configurable: true, get() {
586
- return fn.peek();
587
- }, set(v) {
588
- fn(v);
589
- } });
590
- try {
591
- Object.defineProperty(fn, "bind", { enumerable: true, value: true, configurable: true });
592
- } catch {
593
- fn.bind = true;
594
- }
595
- return new Proxy(fn, handler);
596
- }
597
- __name(createBindableObjectProxy, "createBindableObjectProxy");
598
- bindable.object = function(initialObject = {}) {
599
- const root = bindable(initialObject && typeof initialObject === "object" ? initialObject : {});
600
- return createBindableObjectProxy(root, []);
601
- };
602
- function derive(fn) {
603
- const dep = {
604
- fn,
605
- value: void 0,
606
- version: -1,
607
- depsVersion: -1,
608
- subs: null,
609
- deps: null,
610
- isComputed: true,
611
- run() {
612
- cleanup(this);
613
- const prev = context;
614
- context = this;
615
- try {
616
- this.value = this.fn();
617
- this.depsVersion = globalVersion;
618
- this.version = ++globalVersion;
619
- } finally {
620
- context = prev;
621
- }
622
- }
623
- };
624
- const s = /* @__PURE__ */ __name(function() {
625
- if (dep.version === -1 || dep.depsVersion < globalVersion) dep.run();
626
- if (context) subscribe(context, dep);
627
- return dep.value;
628
- }, "s");
629
- s.peek = () => {
630
- if (dep.version === -1 || dep.depsVersion < globalVersion) dep.run();
631
- return dep.value;
632
- };
633
- Object.defineProperty(s, "value", { enumerable: true, configurable: true, get() {
634
- return s();
635
- } });
636
- return attachHelpers(s);
637
- }
638
- __name(derive, "derive");
639
- const Signals = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
640
- __proto__: null,
641
- batch,
642
- bindable,
643
- derive,
644
- effect,
645
- pick,
646
- signal,
647
- untrack
648
- }, Symbol.toStringTag, { value: "Module" }));
649
- let nextContextId = 1;
650
- const contextStack = [];
651
- function pushContext(values) {
652
- contextStack.push(values);
653
- }
654
- __name(pushContext, "pushContext");
655
- function popContext() {
656
- contextStack.pop();
657
- }
658
- __name(popContext, "popContext");
659
- function readContext(ctx) {
660
- for (let i = contextStack.length - 1; i >= 0; i--) {
661
- const layer = contextStack[i];
662
- if (layer && Object.prototype.hasOwnProperty.call(layer, ctx.id)) {
663
- return layer[ctx.id];
664
- }
665
- }
666
- return ctx.defaultValue;
667
- }
668
- __name(readContext, "readContext");
669
- function createContext(defaultValue) {
670
- const ctx = {
671
- id: nextContextId++,
672
- defaultValue,
673
- Provider: null
674
- };
675
- function Provider(props = {}) {
676
- const children = props.children;
677
- pushContext({ [ctx.id]: props.value });
678
- try {
679
- return createElement("span", { style: { display: "contents" } }, () => {
680
- const val = typeof props.value === "function" && props.value.peek ? props.value() : props.value;
681
- pushContext({ [ctx.id]: val });
682
- try {
683
- return children;
684
- } finally {
685
- popContext();
686
- }
687
- });
688
- } finally {
689
- popContext();
690
- }
691
- }
692
- __name(Provider, "Provider");
693
- ctx.Provider = Provider;
694
- return ctx;
695
- }
696
- __name(createContext, "createContext");
697
- function bindContext(ctx) {
698
- return () => {
699
- const provided = readContext(ctx);
700
- if (typeof provided === "function") {
701
- try {
702
- return provided();
703
- } catch {
704
- return provided;
705
- }
706
- }
707
- return provided;
708
- };
709
- }
710
- __name(bindContext, "bindContext");
711
- function captureContext() {
712
- return contextStack.slice();
713
- }
714
- __name(captureContext, "captureContext");
715
- function runInContext(snapshot, fn) {
716
- const prev = contextStack.slice();
717
- contextStack.length = 0;
718
- contextStack.push(...snapshot);
719
- try {
720
- return fn();
721
- } finally {
722
- contextStack.length = 0;
723
- contextStack.push(...prev);
724
- }
725
- }
726
- __name(runInContext, "runInContext");
727
- const Context = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
728
- __proto__: null,
729
- bindContext,
730
- captureContext,
731
- createContext,
732
- readContext,
733
- runInContext
734
- }, Symbol.toStringTag, { value: "Module" }));
735
- function isPromiseLike$1(v) {
736
- return v && (typeof v === "object" || typeof v === "function") && typeof v.then === "function";
737
- }
738
- __name(isPromiseLike$1, "isPromiseLike$1");
739
- const SuspenseContext = createContext(null);
740
- function lazy(loader) {
741
- if (typeof loader !== "function") {
742
- throw new Error("lazy(loader) expects a function that returns a Promise");
743
- }
744
- let status = "uninitialized";
745
- let promise = null;
746
- let component = null;
747
- let error = null;
748
- function pickComponent(mod) {
749
- if (!mod) return null;
750
- if (typeof mod === "function") return mod;
751
- if (typeof mod.default === "function") return mod.default;
752
- if (typeof mod.Counter === "function") return mod.Counter;
753
- const fns = [];
754
- for (const k of Object.keys(mod)) {
755
- if (typeof mod[k] === "function") fns.push(mod[k]);
756
- }
757
- if (fns.length === 1) return fns[0];
758
- return null;
759
- }
760
- __name(pickComponent, "pickComponent");
761
- return /* @__PURE__ */ __name(function LazyComponent(props = {}) {
762
- if (status === "resolved") {
763
- return createElement(component, props);
764
- }
765
- if (status === "rejected") {
766
- throw error;
767
- }
768
- if (!promise) {
769
- status = "pending";
770
- try {
771
- promise = Promise.resolve(loader()).then((mod) => {
772
- const resolved = pickComponent(mod);
773
- if (typeof resolved !== "function") {
774
- throw new Error("lazy() loaded module does not export a component");
775
- }
776
- component = resolved;
777
- status = "resolved";
778
- }).catch((e) => {
779
- error = e instanceof Error ? e : new Error(String(e));
780
- status = "rejected";
781
- });
782
- } catch (e) {
783
- error = e instanceof Error ? e : new Error(String(e));
784
- status = "rejected";
785
- throw error;
786
- }
787
- }
788
- throw promise;
789
- }, "LazyComponent");
790
- }
791
- __name(lazy, "lazy");
792
- function Suspense(props = {}) {
793
- const tick = signal(0);
794
- const pending = /* @__PURE__ */ new Set();
795
- const waiting = /* @__PURE__ */ new Set();
796
- const child = Array.isArray(props.children) ? props.children[0] : props.children;
797
- const childFn = typeof child === "function" ? child : () => child;
798
- const register = /* @__PURE__ */ __name((promise) => {
799
- if (!waiting.has(promise)) {
800
- waiting.add(promise);
801
- pending.add(promise);
802
- promise.then(
803
- () => {
804
- waiting.delete(promise);
805
- pending.delete(promise);
806
- tick(tick.peek() + 1);
807
- },
808
- () => {
809
- waiting.delete(promise);
810
- pending.delete(promise);
811
- tick(tick.peek() + 1);
812
- }
813
- );
814
- }
815
- }, "register");
816
- return createElement(SuspenseContext.Provider, {
817
- value: { register }
818
- }, () => {
819
- tick();
820
- if (pending.size > 0) {
821
- return props.fallback ?? null;
822
- }
823
- try {
824
- const res = childFn();
825
- if (isPromiseLike$1(res)) {
826
- register(res);
827
- return props.fallback ?? null;
828
- }
829
- return res ?? null;
830
- } catch (e) {
831
- if (isPromiseLike$1(e)) {
832
- register(e);
833
- return props.fallback ?? null;
834
- }
835
- throw e;
836
- }
837
- });
838
- }
839
- __name(Suspense, "Suspense");
840
- const Suspense$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
841
- __proto__: null,
842
- Suspense,
843
- SuspenseContext,
844
- lazy
845
- }, Symbol.toStringTag, { value: "Module" }));
846
- const warnedSignals = /* @__PURE__ */ new Set();
847
- function isPromiseLike(v) {
848
- return v && (typeof v === "object" || typeof v === "function") && typeof v.then === "function";
849
- }
850
- __name(isPromiseLike, "isPromiseLike");
851
- function warnSignalDirectUsage(fn, kind) {
852
- try {
853
- if (typeof fn !== "function") return;
854
- if (typeof fn.peek !== "function") return;
855
- if (!("value" in fn)) return;
856
- if (kind === "child") return;
857
- if (typeof kind === "string" && kind.startsWith("prop:")) return;
858
- const key = `${kind}:${fn.name ?? "signal"}`;
859
- if (warnedSignals.has(key)) return;
860
- warnedSignals.add(key);
861
- console.warn(`[round] Prefer {signal()} (reactive) or {signal.value} (static). Direct {signal} usage is allowed but discouraged.`);
862
- } catch {
863
- }
864
- }
865
- __name(warnSignalDirectUsage, "warnSignalDirectUsage");
866
- function createElement(tag, props = {}, ...children) {
867
- if (typeof tag === "function") {
868
- const componentInstance = createComponentInstance();
869
- const componentName = tag?.name ?? "Anonymous";
870
- componentInstance.name = componentName;
871
- let node = runInLifecycle(componentInstance, () => {
872
- const componentProps = { ...props, children };
873
- try {
874
- const res = untrack(() => tag(componentProps));
875
- if (isPromiseLike(res)) throw res;
876
- return res;
877
- } catch (e) {
878
- if (isPromiseLike(e)) {
879
- const suspense = readContext(SuspenseContext);
880
- if (!suspense) {
881
- throw new Error("cannot instance a lazy component outside a suspense");
882
- }
883
- throw e;
884
- }
885
- reportErrorSafe(e, { phase: "component.render", component: componentName });
886
- return createElement("div", { style: { padding: "16px" } }, `Error in ${componentName}`);
887
- }
888
- });
889
- if (Array.isArray(node)) {
890
- const wrapper = document.createElement("span");
891
- wrapper.style.display = "contents";
892
- node.forEach((n) => appendChild(wrapper, n));
893
- node = wrapper;
894
- }
895
- if (node instanceof Node) {
896
- node._componentInstance = componentInstance;
897
- componentInstance.nodes.push(node);
898
- componentInstance.mountTimerId = setTimeout(() => {
899
- componentInstance.mountTimerId = null;
900
- mountComponent(componentInstance);
901
- }, 0);
902
- }
903
- return node;
904
- }
905
- if (typeof tag === "string") {
906
- const isCustomElement = tag.includes("-");
907
- const isStandard = /^(a|abbr|address|area|article|aside|audio|b|base|bdi|bdo|blockquote|body|br|button|canvas|caption|cite|code|col|colgroup|data|datalist|dd|del|details|dfn|dialog|div|dl|dt|em|embed|fieldset|figcaption|figure|footer|form|h1|h2|h3|h4|h5|h6|head|header|hgroup|hr|html|i|iframe|img|input|ins|kbd|label|legend|li|link|main|map|mark|meta|meter|nav|noscript|object|ol|optgroup|option|output|p|param|picture|pre|progress|q|rp|rt|ruby|s|samp|script|search|section|select|slot|small|source|span|strong|style|sub|summary|sup|svg|table|tbody|td|template|textarea|tfoot|th|thead|time|title|tr|track|u|ul|var|video|wbr|menu|animate|animateMotion|animateTransform|circle|clipPath|defs|desc|ellipse|feBlend|feColorMatrix|feComponentTransfer|feComposite|feConvolveMatrix|feDiffuseLighting|feDisplacementMap|feDistantLight|feDropShadow|feFlood|feFuncA|feFuncB|feFuncG|feFuncR|feGaussianBlur|feImage|feMerge|feMergeNode|feMorphology|feOffset|fePointLight|feSpecularLighting|feSpotLight|feTile|feTurbulence|filter|foreignObject|g|image|line|linearGradient|marker|mask|metadata|mpath|path|pattern|polygon|polyline|radialGradient|rect|set|stop|switch|symbol|text|textPath|tspan|use|view)$/.test(tag);
908
- const isCustomConfigured = typeof __ROUND_CUSTOM_TAGS__ !== "undefined" && __ROUND_CUSTOM_TAGS__.includes(tag);
909
- if (!isCustomElement && !isStandard && !isCustomConfigured && /^[a-z]/.test(tag)) {
910
- throw new Error(`Component names must start with an uppercase letter: <${tag} />`);
911
- }
912
- }
913
- const element = document.createElement(tag);
914
- if (props) {
915
- Object.entries(props).forEach(([key, value]) => {
916
- if (key === "bind:value" || key === "bind:checked") {
917
- const isSignalLike2 = typeof value === "function" && typeof value.peek === "function" && "value" in value;
918
- const isBindable = isSignalLike2 && value.bind === true;
919
- if (!isSignalLike2) {
920
- try {
921
- console.warn("[round] bind:* expects a signal/bindable. Example: const name = bindable(''); <input bind:value={name} />");
922
- } catch {
923
- }
924
- return;
925
- }
926
- if (!isBindable) {
927
- try {
928
- console.warn("[round] bind:* is intended to be used with bindable(). Plain signal() is accepted but discouraged.");
929
- } catch {
930
- }
931
- }
932
- const isValueBinding = key === "bind:value";
933
- const isCheckedBinding = key === "bind:checked";
934
- const el = element;
935
- const tagName = String(el.tagName ?? "").toLowerCase();
936
- const type = String(el.getAttribute?.("type") ?? "").toLowerCase();
937
- const isInput = tagName === "input";
938
- const isTextarea = tagName === "textarea";
939
- const isSelect = tagName === "select";
940
- if (isCheckedBinding && !(isInput && (type === "checkbox" || type === "radio"))) {
941
- try {
942
- console.warn(`[round] bind:checked is only supported on <input type="checkbox|radio">. Got <${tagName}${type ? ` type="${type}"` : ""}>.`);
943
- } catch {
944
- }
945
- return;
946
- }
947
- if (isValueBinding && !(isInput || isTextarea || isSelect)) {
948
- try {
949
- console.warn(`[round] bind:value is only supported on <input>, <textarea>, and <select>. Got <${tagName}>.`);
950
- } catch {
951
- }
952
- return;
953
- }
954
- const coerceFromDom = /* @__PURE__ */ __name(() => {
955
- if (isCheckedBinding) {
956
- if (type === "radio") {
957
- return Boolean(el.checked);
958
- }
959
- return Boolean(el.checked);
960
- }
961
- if (isInput && type === "number") {
962
- const raw = el.value;
963
- if (raw === "") return "";
964
- const n = Number(raw);
965
- return Number.isFinite(n) ? n : raw;
966
- }
967
- if (isSelect && el.multiple) {
968
- try {
969
- return Array.from(el.selectedOptions ?? []).map((o) => o.value);
970
- } catch {
971
- return [];
972
- }
973
- }
974
- return el.value;
975
- }, "coerceFromDom");
976
- const writeToDom = /* @__PURE__ */ __name((v) => {
977
- if (isCheckedBinding) {
978
- const b = Boolean(v);
979
- if (type === "radio") {
980
- el.checked = b;
981
- } else {
982
- el.checked = b;
983
- }
984
- return;
985
- }
986
- if (isSelect && el.multiple) {
987
- const arr = Array.isArray(v) ? v.map((x) => String(x)) : [];
988
- try {
989
- Array.from(el.options ?? []).forEach((opt) => {
990
- opt.selected = arr.includes(opt.value);
991
- });
992
- } catch {
993
- }
994
- return;
995
- }
996
- el.value = v ?? "";
997
- }, "writeToDom");
998
- const warnTypeMismatch = /* @__PURE__ */ __name((next) => {
999
- try {
1000
- if (isCheckedBinding && typeof next !== "boolean") {
1001
- console.warn("[round] bind:checked expects a boolean signal value.");
1002
- }
1003
- if (isValueBinding && isSelect && el.multiple && !Array.isArray(next)) {
1004
- console.warn("[round] bind:value on <select multiple> expects an array signal value.");
1005
- }
1006
- if (isValueBinding && isInput && type === "number" && !(typeof next === "number" || typeof next === "string")) {
1007
- console.warn('[round] bind:value on <input type="number"> expects number|string (empty string allowed).');
1008
- }
1009
- } catch {
1010
- }
1011
- }, "warnTypeMismatch");
1012
- effect(() => {
1013
- const v = value();
1014
- warnTypeMismatch(v);
1015
- writeToDom(v);
1016
- }, { onLoad: false });
1017
- const validateOn = isValueBinding && value && typeof value === "function" ? value.__round_validateOn : null;
1018
- const valueEvent = validateOn === "blur" ? "blur" : isSelect ? "change" : "input";
1019
- const eventName = isCheckedBinding ? "change" : valueEvent;
1020
- el.addEventListener(eventName, (e) => {
1021
- try {
1022
- const target = e.currentTarget;
1023
- if (!target) return;
1024
- const next = coerceFromDom();
1025
- value(next);
1026
- } catch {
1027
- }
1028
- });
1029
- return;
1030
- }
1031
- if (key.startsWith("on") && typeof value === "function") {
1032
- element.addEventListener(key.toLowerCase().substring(2), value);
1033
- return;
1034
- }
1035
- if (key === "dangerouslySetInnerHTML") {
1036
- if (typeof value === "function") {
1037
- effect(() => {
1038
- const v = value();
1039
- if (v && typeof v === "object" && "__html" in v) {
1040
- element.innerHTML = v.__html ?? "";
1041
- }
1042
- }, { onLoad: false });
1043
- } else if (value && typeof value === "object" && "__html" in value) {
1044
- element.innerHTML = value.__html ?? "";
1045
- }
1046
- return;
1047
- }
1048
- if (key === "style") {
1049
- if (typeof value === "function") {
1050
- effect(() => {
1051
- const v = value();
1052
- if (v && typeof v === "object") {
1053
- Object.assign(element.style, v);
1054
- }
1055
- }, { onLoad: false });
1056
- return;
1057
- }
1058
- if (value && typeof value === "object") {
1059
- Object.assign(element.style, value);
1060
- return;
1061
- }
1062
- }
1063
- if (typeof value === "function") {
1064
- warnSignalDirectUsage(value, `prop:${key}`);
1065
- effect(() => {
1066
- const val = value();
1067
- if (key === "className") element.className = val;
1068
- else if (key === "value") element.value = val;
1069
- else if (key === "checked") element.checked = Boolean(val);
1070
- else element.setAttribute(key, val);
1071
- }, { onLoad: false });
1072
- return;
1073
- }
1074
- if (key === "classList") {
1075
- if (value && typeof value === "object") {
1076
- Object.entries(value).forEach(([className, condition]) => {
1077
- if (typeof condition === "function") {
1078
- effect(() => {
1079
- element.classList.toggle(className, !!condition());
1080
- }, { onLoad: false });
1081
- } else {
1082
- element.classList.toggle(className, !!condition);
1083
- }
1084
- });
1085
- }
1086
- return;
1087
- }
1088
- if (key === "className") element.className = value;
1089
- else if (key === "value") element.value = value;
1090
- else if (key === "checked") element.checked = Boolean(value);
1091
- else element.setAttribute(key, value);
1092
- });
1093
- }
1094
- children.forEach((child) => appendChild(element, child));
1095
- return element;
1096
- }
1097
- __name(createElement, "createElement");
1098
- function appendChild(parent, child) {
1099
- if (child === null || child === void 0) return;
1100
- if (Array.isArray(child)) {
1101
- child.forEach((c) => appendChild(parent, c));
1102
- return;
1103
- }
1104
- if (typeof child === "string" || typeof child === "number") {
1105
- parent.appendChild(document.createTextNode(child));
1106
- return;
1107
- }
1108
- if (typeof child === "function") {
1109
- warnSignalDirectUsage(child, "child");
1110
- const placeholder = document.createTextNode("");
1111
- parent.appendChild(placeholder);
1112
- let currentNode = placeholder;
1113
- const ctxSnapshot = captureContext();
1114
- effect(() => {
1115
- runInContext(ctxSnapshot, () => {
1116
- let val;
1117
- try {
1118
- val = child();
1119
- if (isPromiseLike(val)) throw val;
1120
- } catch (e) {
1121
- if (isPromiseLike(e)) {
1122
- const suspense = readContext(SuspenseContext);
1123
- if (suspense && typeof suspense.register === "function") {
1124
- suspense.register(e);
1125
- return;
1126
- }
1127
- throw new Error("cannot instance a lazy component outside a suspense");
1128
- }
1129
- reportErrorSafe(e, { phase: "child.dynamic" });
1130
- val = createElement("div", { style: { padding: "16px" } }, "Error");
1131
- }
1132
- if (Array.isArray(val)) {
1133
- if (!(currentNode instanceof Element) || !currentNode._roundArrayWrapper) {
1134
- const wrapper = document.createElement("span");
1135
- wrapper.style.display = "contents";
1136
- wrapper._roundArrayWrapper = true;
1137
- if (currentNode.parentNode) {
1138
- currentNode.parentNode.replaceChild(wrapper, currentNode);
1139
- currentNode = wrapper;
1140
- }
1141
- }
1142
- while (currentNode.firstChild) currentNode.removeChild(currentNode.firstChild);
1143
- val.forEach((v) => appendChild(currentNode, v));
1144
- return;
1145
- }
1146
- if (val instanceof Node) {
1147
- if (currentNode !== val) {
1148
- if (currentNode.parentNode) {
1149
- currentNode.parentNode.replaceChild(val, currentNode);
1150
- currentNode = val;
1151
- }
1152
- }
1153
- } else {
1154
- const textContent = val === null || val === void 0 ? "" : val;
1155
- if (currentNode instanceof Element) {
1156
- const newText = document.createTextNode(textContent);
1157
- if (currentNode.parentNode) {
1158
- currentNode.parentNode.replaceChild(newText, currentNode);
1159
- currentNode = newText;
1160
- }
1161
- } else {
1162
- currentNode.textContent = textContent;
1163
- }
1164
- }
1165
- });
1166
- }, { onLoad: false });
1167
- return;
1168
- }
1169
- if (child instanceof Node) {
1170
- parent.appendChild(child);
1171
- return;
1172
- }
1173
- }
1174
- __name(appendChild, "appendChild");
1175
- function Fragment(props) {
1176
- return props.children;
1177
- }
1178
- __name(Fragment, "Fragment");
1179
- const DOM = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1180
- __proto__: null,
1181
- Fragment,
1182
- createElement
1183
- }, Symbol.toStringTag, { value: "Module" }));
1184
- const hasWindow$1 = typeof window !== "undefined" && typeof document !== "undefined";
1185
- const ROUTING_TRAILING_SLASH = typeof __ROUND_ROUTING_TRAILING_SLASH__ !== "undefined" ? Boolean(__ROUND_ROUTING_TRAILING_SLASH__) : true;
1186
- const currentPath = signal(hasWindow$1 ? window.location.pathname : "/");
1187
- let listenerInitialized = false;
1188
- let lastPathEvaluated = null;
1189
- const pathHasMatch = signal(false);
1190
- const pathEvalReady = signal(true);
1191
- let defaultNotFoundComponent = null;
1192
- let autoNotFoundMounted = false;
1193
- let userProvidedNotFound = false;
1194
- const RoutingContext = createContext("");
1195
- function ensureListener() {
1196
- if (!hasWindow$1 || listenerInitialized) return;
1197
- listenerInitialized = true;
1198
- mountAutoNotFound();
1199
- window.addEventListener("popstate", () => {
1200
- currentPath(window.location.pathname);
1201
- });
1202
- }
1203
- __name(ensureListener, "ensureListener");
1204
- function getPathname() {
1205
- return normalizePathname(currentPath());
1206
- }
1207
- __name(getPathname, "getPathname");
1208
- function usePathname() {
1209
- return () => normalizePathname(currentPath());
1210
- }
1211
- __name(usePathname, "usePathname");
1212
- function getLocation() {
1213
- if (!hasWindow$1) {
1214
- return { pathname: normalizePathname("/"), search: "", hash: "" };
1215
- }
1216
- return {
1217
- pathname: normalizePathname(window.location.pathname),
1218
- search: window.location.search ?? "",
1219
- hash: window.location.hash ?? ""
1220
- };
1221
- }
1222
- __name(getLocation, "getLocation");
1223
- function useLocation() {
1224
- return () => {
1225
- const pathname = normalizePathname(currentPath());
1226
- if (!hasWindow$1) return { pathname, search: "", hash: "" };
1227
- return { pathname, search: window.location.search ?? "", hash: window.location.hash ?? "" };
1228
- };
1229
- }
1230
- __name(useLocation, "useLocation");
1231
- function getRouteReady() {
1232
- const pathname = normalizePathname(currentPath());
1233
- return Boolean(pathEvalReady()) && lastPathEvaluated === pathname;
1234
- }
1235
- __name(getRouteReady, "getRouteReady");
1236
- function useRouteReady() {
1237
- return () => {
1238
- const pathname = normalizePathname(currentPath());
1239
- return Boolean(pathEvalReady()) && lastPathEvaluated === pathname;
1240
- };
1241
- }
1242
- __name(useRouteReady, "useRouteReady");
1243
- function getIsNotFound() {
1244
- const pathname = normalizePathname(currentPath());
1245
- if (pathname === "/") return false;
1246
- if (!(Boolean(pathEvalReady()) && lastPathEvaluated === pathname)) return false;
1247
- return !Boolean(pathHasMatch());
1248
- }
1249
- __name(getIsNotFound, "getIsNotFound");
1250
- function useIsNotFound() {
1251
- return () => {
1252
- const pathname = normalizePathname(currentPath());
1253
- if (pathname === "/") return false;
1254
- if (!(Boolean(pathEvalReady()) && lastPathEvaluated === pathname)) return false;
1255
- return !Boolean(pathHasMatch());
1256
- };
1257
- }
1258
- __name(useIsNotFound, "useIsNotFound");
1259
- function mountAutoNotFound() {
1260
- if (!hasWindow$1 || autoNotFoundMounted) return;
1261
- autoNotFoundMounted = true;
1262
- const host = document.getElementById("app") ?? document.body;
1263
- const root = document.createElement("div");
1264
- root.setAttribute("data-round-auto-notfound", "1");
1265
- host.appendChild(root);
1266
- const view = createElement("span", { style: { display: "contents" } }, () => {
1267
- if (userProvidedNotFound) return null;
1268
- const pathname = normalizePathname(currentPath());
1269
- const ready = pathEvalReady();
1270
- const hasMatch = pathHasMatch();
1271
- if (!ready) return null;
1272
- if (lastPathEvaluated !== pathname) return null;
1273
- if (hasMatch) return null;
1274
- if (pathname === "/") return null;
1275
- const Comp = defaultNotFoundComponent;
1276
- if (typeof Comp === "function") {
1277
- return createElement(Comp, { pathname });
1278
- }
1279
- return createElement(
1280
- "div",
1281
- { style: { padding: "16px" } },
1282
- createElement("h1", null, "404"),
1283
- createElement("p", null, "Page not found: ", pathname)
1284
- );
1285
- });
1286
- root.appendChild(view);
1287
- }
1288
- __name(mountAutoNotFound, "mountAutoNotFound");
1289
- function navigate(to, options = {}) {
1290
- if (!hasWindow$1) return;
1291
- ensureListener();
1292
- const normalizedTo = normalizeTo(to);
1293
- const replace = Boolean(options.replace);
1294
- if (replace) window.history.replaceState({}, "", normalizedTo);
1295
- else window.history.pushState({}, "", normalizedTo);
1296
- currentPath(window.location.pathname);
1297
- }
1298
- __name(navigate, "navigate");
1299
- function applyHead({ title, meta, links, icon, favicon }) {
1300
- if (!hasWindow$1) return;
1301
- if (typeof title === "string") {
1302
- document.title = title;
1303
- }
1304
- document.querySelectorAll('[data-round-head="1"]').forEach((n) => n.remove());
1305
- const iconHref = icon ?? favicon;
1306
- if (typeof iconHref === "string" && iconHref.length) {
1307
- const el = document.createElement("link");
1308
- el.setAttribute("data-round-head", "1");
1309
- el.setAttribute("rel", "icon");
1310
- el.setAttribute("href", iconHref);
1311
- document.head.appendChild(el);
1312
- }
1313
- if (Array.isArray(links)) {
1314
- links.forEach((l) => {
1315
- if (!l || typeof l !== "object") return;
1316
- const el = document.createElement("link");
1317
- el.setAttribute("data-round-head", "1");
1318
- Object.entries(l).forEach(([k, v]) => {
1319
- if (v === null || v === void 0) return;
1320
- el.setAttribute(k, String(v));
1321
- });
1322
- document.head.appendChild(el);
1323
- });
1324
- }
1325
- if (Array.isArray(meta)) {
1326
- meta.forEach((entry) => {
1327
- if (!entry) return;
1328
- const el = document.createElement("meta");
1329
- el.setAttribute("data-round-head", "1");
1330
- if (Array.isArray(entry) && entry.length >= 2) {
1331
- const [name, content] = entry;
1332
- if (typeof name === "string") el.setAttribute("name", name);
1333
- el.setAttribute("content", String(content ?? ""));
1334
- } else if (typeof entry === "object") {
1335
- Object.entries(entry).forEach(([k, v]) => {
1336
- if (v === null || v === void 0) return;
1337
- el.setAttribute(k, String(v));
1338
- });
1339
- } else {
1340
- return;
1341
- }
1342
- document.head.appendChild(el);
1343
- });
1344
- } else if (meta && typeof meta === "object") {
1345
- Object.entries(meta).forEach(([name, content]) => {
1346
- if (typeof name !== "string") return;
1347
- const el = document.createElement("meta");
1348
- el.setAttribute("data-round-head", "1");
1349
- el.setAttribute("name", name);
1350
- el.setAttribute("content", String(content ?? ""));
1351
- document.head.appendChild(el);
1352
- });
1353
- }
1354
- }
1355
- __name(applyHead, "applyHead");
1356
- function startHead(_head) {
1357
- return _head;
1358
- }
1359
- __name(startHead, "startHead");
1360
- function splitUrl(url) {
1361
- const str = String(url ?? "");
1362
- const hashIdx = str.indexOf("#");
1363
- const queryIdx = str.indexOf("?");
1364
- const cutIdx = hashIdx === -1 ? queryIdx : queryIdx === -1 ? hashIdx : Math.min(hashIdx, queryIdx);
1365
- if (cutIdx === -1) return { path: str, suffix: "" };
1366
- return { path: str.slice(0, cutIdx), suffix: str.slice(cutIdx) };
1367
- }
1368
- __name(splitUrl, "splitUrl");
1369
- function normalizePathname(p) {
1370
- let pathname = String(p ?? "/");
1371
- if (!pathname.startsWith("/")) pathname = "/" + pathname;
1372
- if (pathname.length > 1) {
1373
- if (ROUTING_TRAILING_SLASH) {
1374
- if (!pathname.endsWith("/")) pathname += "/";
1375
- } else {
1376
- if (pathname.endsWith("/")) pathname = pathname.slice(0, -1);
1377
- }
1378
- }
1379
- return pathname;
1380
- }
1381
- __name(normalizePathname, "normalizePathname");
1382
- function normalizeTo(to) {
1383
- const { path, suffix } = splitUrl(to);
1384
- if (!path.startsWith("/")) return String(to ?? "");
1385
- return normalizePathname(path) + suffix;
1386
- }
1387
- __name(normalizeTo, "normalizeTo");
1388
- function matchRoute(route, pathname, exact = true) {
1389
- const r = normalizePathname(route);
1390
- const p = normalizePathname(pathname);
1391
- if (exact) return r === p;
1392
- return p === r || p.startsWith(r.endsWith("/") ? r : r + "/");
1393
- }
1394
- __name(matchRoute, "matchRoute");
1395
- function beginPathEvaluation(pathname) {
1396
- if (pathname !== lastPathEvaluated) {
1397
- lastPathEvaluated = pathname;
1398
- pathHasMatch(false);
1399
- pathEvalReady(false);
1400
- setTimeout(() => {
1401
- if (lastPathEvaluated !== pathname) return;
1402
- pathEvalReady(true);
1403
- }, 0);
1404
- }
1405
- }
1406
- __name(beginPathEvaluation, "beginPathEvaluation");
1407
- function setNotFound(Component) {
1408
- defaultNotFoundComponent = Component;
1409
- }
1410
- __name(setNotFound, "setNotFound");
1411
- function Route(props = {}) {
1412
- ensureListener();
1413
- return createElement("span", { style: { display: "contents" } }, () => {
1414
- const parentPath = readContext(RoutingContext) || "";
1415
- const pathname = normalizePathname(currentPath());
1416
- beginPathEvaluation(pathname);
1417
- const routeProp = props.route ?? "/";
1418
- if (typeof routeProp === "string" && !routeProp.startsWith("/")) {
1419
- throw new Error(`Invalid route: "${routeProp}". All routes must start with a forward slash "/". (Nested under: "${parentPath || "root"}")`);
1420
- }
1421
- let fullRoute = "";
1422
- if (parentPath && parentPath !== "/") {
1423
- const cleanParent = parentPath.endsWith("/") ? parentPath.slice(0, -1) : parentPath;
1424
- const cleanChild = routeProp.startsWith("/") ? routeProp : "/" + routeProp;
1425
- if (cleanChild.startsWith(cleanParent + "/") || cleanChild === cleanParent) {
1426
- fullRoute = normalizePathname(cleanChild);
1427
- } else {
1428
- fullRoute = normalizePathname(cleanParent + cleanChild);
1429
- }
1430
- } else {
1431
- fullRoute = normalizePathname(routeProp);
1432
- }
1433
- const isRoot = fullRoute === "/";
1434
- const exact = props.exact !== void 0 ? Boolean(props.exact) : isRoot;
1435
- if (!matchRoute(fullRoute, pathname, exact)) return null;
1436
- if (matchRoute(fullRoute, pathname, true)) {
1437
- pathHasMatch(true);
1438
- }
1439
- const mergedHead = props.head && typeof props.head === "object" ? props.head : {};
1440
- const meta = props.description ? [{ name: "description", content: String(props.description) }].concat(mergedHead.meta ?? props.meta ?? []) : mergedHead.meta ?? props.meta;
1441
- const links = mergedHead.links ?? props.links;
1442
- const title = mergedHead.title ?? props.title;
1443
- const icon = mergedHead.icon ?? props.icon;
1444
- const favicon = mergedHead.favicon ?? props.favicon;
1445
- applyHead({ title, meta, links, icon, favicon });
1446
- return createElement(RoutingContext.Provider, { value: fullRoute }, props.children);
1447
- });
1448
- }
1449
- __name(Route, "Route");
1450
- function Page(props = {}) {
1451
- ensureListener();
1452
- return createElement("span", { style: { display: "contents" } }, () => {
1453
- const parentPath = readContext(RoutingContext) || "";
1454
- const pathname = normalizePathname(currentPath());
1455
- beginPathEvaluation(pathname);
1456
- const routeProp = props.route ?? "/";
1457
- if (typeof routeProp === "string" && !routeProp.startsWith("/")) {
1458
- throw new Error(`Invalid route: "${routeProp}". All routes must start with a forward slash "/". (Nested under: "${parentPath || "root"}")`);
1459
- }
1460
- let fullRoute = "";
1461
- if (parentPath && parentPath !== "/") {
1462
- const cleanParent = parentPath.endsWith("/") ? parentPath.slice(0, -1) : parentPath;
1463
- const cleanChild = routeProp.startsWith("/") ? routeProp : "/" + routeProp;
1464
- if (cleanChild.startsWith(cleanParent + "/") || cleanChild === cleanParent) {
1465
- fullRoute = normalizePathname(cleanChild);
1466
- } else {
1467
- fullRoute = normalizePathname(cleanParent + cleanChild);
1468
- }
1469
- } else {
1470
- fullRoute = normalizePathname(routeProp);
1471
- }
1472
- const isRoot = fullRoute === "/";
1473
- const exact = props.exact !== void 0 ? Boolean(props.exact) : isRoot;
1474
- if (!matchRoute(fullRoute, pathname, exact)) return null;
1475
- if (matchRoute(fullRoute, pathname, true)) {
1476
- pathHasMatch(true);
1477
- }
1478
- const mergedHead = props.head && typeof props.head === "object" ? props.head : {};
1479
- const meta = props.description ? [{ name: "description", content: String(props.description) }].concat(mergedHead.meta ?? props.meta ?? []) : mergedHead.meta ?? props.meta;
1480
- const links = mergedHead.links ?? props.links;
1481
- const title = mergedHead.title ?? props.title;
1482
- const icon = mergedHead.icon ?? props.icon;
1483
- const favicon = mergedHead.favicon ?? props.favicon;
1484
- applyHead({ title, meta, links, icon, favicon });
1485
- return createElement(RoutingContext.Provider, { value: fullRoute }, props.children);
1486
- });
1487
- }
1488
- __name(Page, "Page");
1489
- function NotFound(props = {}) {
1490
- ensureListener();
1491
- userProvidedNotFound = true;
1492
- return createElement("span", { style: { display: "contents" } }, () => {
1493
- const pathname = normalizePathname(currentPath());
1494
- beginPathEvaluation(pathname);
1495
- const ready = pathEvalReady();
1496
- const hasMatch = pathHasMatch();
1497
- if (!ready) return null;
1498
- if (lastPathEvaluated !== pathname) return null;
1499
- if (hasMatch) return null;
1500
- if (pathname === "/") return null;
1501
- const Comp = props.component ?? defaultNotFoundComponent;
1502
- if (typeof Comp === "function") {
1503
- return createElement(Comp, { pathname });
1504
- }
1505
- if (props.children !== void 0) return props.children;
1506
- return createElement(
1507
- "div",
1508
- { style: { padding: "16px" } },
1509
- createElement("h1", null, "404"),
1510
- createElement("p", null, "Page not found: ", pathname)
1511
- );
1512
- });
1513
- }
1514
- __name(NotFound, "NotFound");
1515
- function Link(props = {}) {
1516
- ensureListener();
1517
- const rawHref = props.href ?? props.to ?? "#";
1518
- const href = spaNormalizeHref(rawHref);
1519
- const spa = props.spa !== void 0 ? Boolean(props.spa) : true;
1520
- const reload = Boolean(props.reload);
1521
- const onClick = /* @__PURE__ */ __name((e) => {
1522
- if (typeof props.onClick === "function") props.onClick(e);
1523
- if (e.defaultPrevented) return;
1524
- if (props.target === "_blank") return;
1525
- const strHref = String(href);
1526
- if (strHref.includes("://") || strHref.startsWith("mailto:") || strHref.startsWith("tel:")) return;
1527
- if (!spa || reload) return;
1528
- if (e.button !== 0) return;
1529
- if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
1530
- e.preventDefault();
1531
- navigate(href);
1532
- }, "onClick");
1533
- const { children, to, ...rest } = props;
1534
- const normalizedChildren = Array.isArray(children) ? children : children === void 0 || children === null ? [] : [children];
1535
- return createElement("a", { ...rest, href, onClick }, ...normalizedChildren);
1536
- }
1537
- __name(Link, "Link");
1538
- function spaNormalizeHref(href) {
1539
- const str = String(href ?? "#");
1540
- if (!str.startsWith("/")) return str;
1541
- return normalizeTo(str);
1542
- }
1543
- __name(spaNormalizeHref, "spaNormalizeHref");
1544
- const Router = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1545
- __proto__: null,
1546
- Link,
1547
- NotFound,
1548
- Page,
1549
- Route,
1550
- getIsNotFound,
1551
- getLocation,
1552
- getPathname,
1553
- getRouteReady,
1554
- navigate,
1555
- setNotFound,
1556
- startHead,
1557
- useIsNotFound,
1558
- useLocation,
1559
- usePathname,
1560
- useRouteReady
1561
- }, Symbol.toStringTag, { value: "Module" }));
1562
- const errors = signal([]);
1563
- let lastSentKey = null;
1564
- let lastSentAt = 0;
1565
- let lastStoredKey = null;
1566
- let lastStoredAt = 0;
1567
- function reportError(error, info = {}) {
1568
- const err = error instanceof Error ? error : new Error(String(error));
1569
- const stack = err.stack ? String(err.stack) : "";
1570
- const message = err.message;
1571
- const phase = info.phase ?? null;
1572
- const component = info.component ?? null;
1573
- const key = `${message}|${component ?? ""}|${phase ?? ""}|${stack}`;
1574
- const now = Date.now();
1575
- if (lastStoredKey === key && now - lastStoredAt < 1500) {
1576
- return;
1577
- }
1578
- lastStoredKey = key;
1579
- lastStoredAt = now;
1580
- const entry = {
1581
- error: err,
1582
- message,
1583
- stack,
1584
- phase,
1585
- component,
1586
- time: now
1587
- };
1588
- const current = typeof errors.peek === "function" ? errors.peek() : errors();
1589
- errors([entry, ...Array.isArray(current) ? current : []]);
1590
- try {
1591
- const where = entry.component ? ` in ${entry.component}` : "";
1592
- const phase2 = entry.phase ? ` (${entry.phase})` : "";
1593
- const label = `[round] Runtime error${where}${phase2}`;
1594
- if (typeof console.groupCollapsed === "function") {
1595
- console.groupCollapsed(label);
1596
- console.error(entry.error);
1597
- if (entry.stack) console.log(entry.stack);
1598
- if (info && Object.keys(info).length) console.log("info:", info);
1599
- console.groupEnd();
1600
- } else {
1601
- console.error(label);
1602
- console.error(entry.error);
1603
- if (entry.stack) console.log(entry.stack);
1604
- if (info && Object.keys(info).length) console.log("info:", info);
1605
- }
1606
- } catch {
1607
- }
1608
- try {
1609
- if (void 0) ;
1610
- } catch {
1611
- }
1612
- }
1613
- __name(reportError, "reportError");
1614
- function clearErrors() {
1615
- errors([]);
1616
- }
1617
- __name(clearErrors, "clearErrors");
1618
- function useErrors() {
1619
- return errors;
1620
- }
1621
- __name(useErrors, "useErrors");
1622
- setErrorReporter(reportError);
1623
- function ErrorProvider(props = {}) {
1624
- return createElement("span", { style: { display: "contents" } }, () => {
1625
- const list = useErrors()();
1626
- if (!Array.isArray(list) || list.length === 0) return props.children ?? null;
1627
- const first = list[0];
1628
- return createElement(
1629
- "div",
1630
- {
1631
- style: {
1632
- position: "fixed",
1633
- inset: "0",
1634
- zIndex: 2147483647,
1635
- display: "flex",
1636
- alignItems: "center",
1637
- justifyContent: "center",
1638
- padding: "24px",
1639
- background: "rgba(17, 24, 39, 0.72)",
1640
- backdropFilter: "blur(10px)",
1641
- WebkitBackdropFilter: "blur(10px)"
1642
- }
1643
- },
1644
- createElement(
1645
- "div",
1646
- {
1647
- style: {
1648
- width: "min(900px, 100%)",
1649
- borderRadius: "14px",
1650
- border: "1px solid rgba(255,255,255,0.12)",
1651
- background: "rgba(0,0,0,0.55)",
1652
- boxShadow: "0 30px 80px rgba(0,0,0,0.55)",
1653
- color: "#fff",
1654
- overflow: "hidden"
1655
- }
1656
- },
1657
- createElement(
1658
- "div",
1659
- {
1660
- style: {
1661
- padding: "14px 16px",
1662
- display: "flex",
1663
- alignItems: "center",
1664
- gap: "10px",
1665
- borderBottom: "1px solid rgba(255,255,255,0.10)",
1666
- background: "linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0))"
1667
- }
1668
- },
1669
- createElement("div", {
1670
- style: {
1671
- width: "10px",
1672
- height: "10px",
1673
- borderRadius: "999px",
1674
- background: "#ef4444",
1675
- boxShadow: "0 0 0 4px rgba(239,68,68,0.18)"
1676
- }
1677
- }),
1678
- createElement("strong", { style: { fontFamily: "ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial" } }, "Round Error"),
1679
- createElement("span", { style: { opacity: 0.75, fontFamily: "ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial", fontSize: "12px" } }, new Date(first.time).toLocaleString()),
1680
- createElement("button", {
1681
- style: {
1682
- marginLeft: "auto",
1683
- border: "1px solid rgba(255,255,255,0.16)",
1684
- background: "rgba(255,255,255,0.08)",
1685
- color: "#fff",
1686
- padding: "8px 10px",
1687
- borderRadius: "10px",
1688
- cursor: "pointer"
1689
- },
1690
- onMouseOver: /* @__PURE__ */ __name((e) => {
1691
- try {
1692
- e.currentTarget.style.background = "rgba(255,255,255,0.12)";
1693
- } catch {
1694
- }
1695
- }, "onMouseOver"),
1696
- onMouseOut: /* @__PURE__ */ __name((e) => {
1697
- try {
1698
- e.currentTarget.style.background = "rgba(255,255,255,0.08)";
1699
- } catch {
1700
- }
1701
- }, "onMouseOut"),
1702
- onClick: /* @__PURE__ */ __name(() => clearErrors(), "onClick")
1703
- }, "Dismiss")
1704
- ),
1705
- createElement(
1706
- "div",
1707
- {
1708
- style: {
1709
- padding: "16px",
1710
- fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace'
1711
- }
1712
- },
1713
- createElement("div", { style: { fontSize: "14px", fontWeight: "700" } }, String(first.message ?? "Error")),
1714
- createElement(
1715
- "div",
1716
- { style: { marginTop: "10px", opacity: 0.85, fontSize: "12px", lineHeight: "18px" } },
1717
- first.component ? createElement("div", null, createElement("span", { style: { opacity: 0.75 } }, "Component: "), String(first.component)) : null,
1718
- first.phase ? createElement("div", null, createElement("span", { style: { opacity: 0.75 } }, "Phase: "), String(first.phase)) : null
1719
- ),
1720
- first.stack ? createElement("pre", {
1721
- style: {
1722
- marginTop: "12px",
1723
- padding: "12px",
1724
- borderRadius: "12px",
1725
- background: "rgba(0,0,0,0.55)",
1726
- border: "1px solid rgba(255,255,255,0.10)",
1727
- whiteSpace: "pre-wrap",
1728
- fontSize: "12px",
1729
- lineHeight: "18px",
1730
- overflow: "auto",
1731
- maxHeight: "55vh"
1732
- }
1733
- }, String(first.stack)) : null
1734
- )
1735
- )
1736
- );
1737
- });
1738
- }
1739
- __name(ErrorProvider, "ErrorProvider");
1740
- function initErrorHandling(container) {
1741
- if (typeof document === "undefined") return;
1742
- if (!container || !(container instanceof Element)) return;
1743
- if (!document.querySelector('[data-round-error-style="1"]')) {
1744
- const style = document.createElement("style");
1745
- style.setAttribute("data-round-error-style", "1");
1746
- style.textContent = `
1747
- [data-round-error-root="1"] pre{scrollbar-width:thin;scrollbar-color:rgba(255,255,255,0.28) rgba(255,255,255,0.06);}
1748
- [data-round-error-root="1"] pre::-webkit-scrollbar{width:10px;height:10px;}
1749
- [data-round-error-root="1"] pre::-webkit-scrollbar-track{background:rgba(255,255,255,0.06);border-radius:999px;}
1750
- [data-round-error-root="1"] pre::-webkit-scrollbar-thumb{background:rgba(255,255,255,0.22);border-radius:999px;border:2px solid rgba(0,0,0,0.35);}
1751
- [data-round-error-root="1"] pre::-webkit-scrollbar-thumb:hover{background:rgba(255,255,255,0.32);}
1752
- `.trim();
1753
- document.head.appendChild(style);
1754
- }
1755
- if (!document.querySelector('[data-round-error-root="1"]')) {
1756
- const root = document.createElement("div");
1757
- root.setAttribute("data-round-error-root", "1");
1758
- container.appendChild(root);
1759
- root.appendChild(createElement(ErrorProvider, null));
1760
- }
1761
- if (!window.__round_error_handlers_installed) {
1762
- window.__round_error_handlers_installed = true;
1763
- window.addEventListener("error", (e) => {
1764
- reportError(e?.error ?? e?.message ?? e, { phase: "window.error" });
1765
- });
1766
- window.addEventListener("unhandledrejection", (e) => {
1767
- reportError(e?.reason ?? e, { phase: "window.unhandledrejection" });
1768
- });
1769
- }
1770
- }
1771
- __name(initErrorHandling, "initErrorHandling");
1772
- const Errors = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1773
- __proto__: null,
1774
- ErrorProvider,
1775
- initErrorHandling,
1776
- reportError
1777
- }, Symbol.toStringTag, { value: "Module" }));
1778
- function ErrorBoundary(props = {}) {
1779
- const error = signal(null);
1780
- const name = props.name ?? "ErrorBoundary";
1781
- const fallback = props.fallback;
1782
- const resetKey = props.resetKey;
1783
- let lastResetKey = resetKey;
1784
- return createElement("span", { style: { display: "contents" } }, () => {
1785
- if (resetKey !== void 0 && resetKey !== lastResetKey) {
1786
- lastResetKey = resetKey;
1787
- if (error()) error(null);
1788
- }
1789
- const err = error();
1790
- if (err) {
1791
- if (typeof fallback === "function") {
1792
- try {
1793
- return fallback({ error: err });
1794
- } catch (e) {
1795
- reportError(e, { phase: "ErrorBoundary.fallback", component: name });
1796
- return createElement("div", { style: { padding: "16px" } }, "ErrorBoundary fallback crashed");
1797
- }
1798
- }
1799
- if (fallback !== void 0) return fallback;
1800
- return createElement("div", { style: { padding: "16px" } }, "Something went wrong.");
1801
- }
1802
- const renderFn = typeof props.render === "function" ? props.render : typeof props.children === "function" ? props.children : null;
1803
- if (typeof renderFn !== "function") return props.children ?? null;
1804
- try {
1805
- return renderFn();
1806
- } catch (e) {
1807
- if (!error() || error() !== e) error(e);
1808
- reportError(e, { phase: "ErrorBoundary.render", component: name });
1809
- return null;
1810
- }
1811
- });
1812
- }
1813
- __name(ErrorBoundary, "ErrorBoundary");
1814
- function hasWindow() {
1815
- return typeof window !== "undefined" && typeof document !== "undefined";
1816
- }
1817
- __name(hasWindow, "hasWindow");
1818
- function createStore(initialState = {}, actions = null) {
1819
- const state = initialState && typeof initialState === "object" ? initialState : {};
1820
- const signals = /* @__PURE__ */ Object.create(null);
1821
- const persistState = {
1822
- enabled: false,
1823
- key: null,
1824
- storage: null,
1825
- persisting: false,
1826
- persistNow: null,
1827
- watchers: /* @__PURE__ */ new Set()
1828
- };
1829
- for (const k of Object.keys(state)) {
1830
- signals[k] = bindable(state[k]);
1831
- }
1832
- function setKey(k, v) {
1833
- const key = String(k);
1834
- if (!Object.prototype.hasOwnProperty.call(signals, key)) {
1835
- signals[key] = bindable(state[key]);
1836
- }
1837
- state[key] = v;
1838
- signals[key](v);
1839
- if (persistState.enabled && typeof persistState.persistNow === "function") {
1840
- persistState.persistNow();
1841
- }
1842
- return v;
1843
- }
1844
- __name(setKey, "setKey");
1845
- function patch(obj) {
1846
- if (!obj || typeof obj !== "object") return;
1847
- for (const [k, v] of Object.entries(obj)) {
1848
- setKey(k, v);
1849
- }
1850
- }
1851
- __name(patch, "patch");
1852
- function getSnapshot(reactive = false) {
1853
- const out = {};
1854
- for (const k of Object.keys(signals)) {
1855
- out[k] = reactive ? signals[k]() : signals[k].peek();
1856
- }
1857
- return out;
1858
- }
1859
- __name(getSnapshot, "getSnapshot");
1860
- const store = {
1861
- use(key) {
1862
- const k = String(key);
1863
- if (!Object.prototype.hasOwnProperty.call(signals, k)) {
1864
- signals[k] = bindable(state[k]);
1865
- if (!Object.prototype.hasOwnProperty.call(state, k)) {
1866
- try {
1867
- reportErrorSafe(new Error(`Store key not found: ${k}`), { phase: "store.use", component: "createStore" });
1868
- } catch {
1869
- }
1870
- }
1871
- }
1872
- if (persistState.enabled) {
1873
- const sig = signals[k];
1874
- if (sig && typeof sig === "function" && !persistState.watchers.has(k)) {
1875
- persistState.watchers.add(k);
1876
- effect(() => {
1877
- sig();
1878
- if (persistState.persisting) return;
1879
- if (typeof persistState.persistNow === "function") persistState.persistNow();
1880
- }, { onLoad: false });
1881
- }
1882
- }
1883
- return signals[k];
1884
- },
1885
- set(key, value) {
1886
- return setKey(key, value);
1887
- },
1888
- patch,
1889
- snapshot(options = {}) {
1890
- const reactive = options && typeof options === "object" && options.reactive === true;
1891
- return getSnapshot(reactive);
1892
- },
1893
- actions: {}
1894
- };
1895
- if (actions && typeof actions === "object") {
1896
- Object.entries(actions).forEach(([name, reducer]) => {
1897
- if (typeof reducer !== "function") return;
1898
- const fn = /* @__PURE__ */ __name((...args) => {
1899
- try {
1900
- const next = reducer(getSnapshot(false), ...args);
1901
- if (next && typeof next === "object") {
1902
- patch(next);
1903
- }
1904
- return next;
1905
- } catch (e) {
1906
- reportErrorSafe(e, { phase: "store.action", component: String(name) });
1907
- }
1908
- }, "fn");
1909
- store.actions[name] = fn;
1910
- store[name] = fn;
1911
- });
1912
- }
1913
- store.persist = (storageKey, optionsOrStorage) => {
1914
- if (typeof storageKey !== "string" || !storageKey.length) return store;
1915
- const isStorageLike = optionsOrStorage && typeof optionsOrStorage.getItem === "function" && typeof optionsOrStorage.setItem === "function";
1916
- const opts = !isStorageLike && optionsOrStorage && typeof optionsOrStorage === "object" ? optionsOrStorage : {};
1917
- const st = isStorageLike ? optionsOrStorage : opts.storage ?? (hasWindow() ? window.localStorage : null);
1918
- if (!st || typeof st.getItem !== "function" || typeof st.setItem !== "function") return store;
1919
- const debounceMs = Number.isFinite(Number(opts.debounce)) ? Number(opts.debounce) : 0;
1920
- const exclude = Array.isArray(opts.exclude) ? opts.exclude.map(String) : [];
1921
- try {
1922
- const raw = st.getItem(storageKey);
1923
- if (raw) {
1924
- const parsed = JSON.parse(raw);
1925
- if (parsed && typeof parsed === "object") {
1926
- const filtered = exclude.length ? Object.fromEntries(Object.entries(parsed).filter(([k]) => !exclude.includes(String(k)))) : parsed;
1927
- patch(filtered);
1928
- }
1929
- }
1930
- } catch {
1931
- }
1932
- const persistNow = /* @__PURE__ */ __name(() => {
1933
- try {
1934
- persistState.persisting = true;
1935
- const snap = getSnapshot(false);
1936
- const out = exclude.length ? Object.fromEntries(Object.entries(snap).filter(([k]) => !exclude.includes(String(k)))) : snap;
1937
- st.setItem(storageKey, JSON.stringify(out));
1938
- } catch {
1939
- } finally {
1940
- persistState.persisting = false;
1941
- }
1942
- }, "persistNow");
1943
- let debounceId = null;
1944
- const schedulePersist = /* @__PURE__ */ __name(() => {
1945
- if (debounceMs <= 0) return persistNow();
1946
- try {
1947
- if (debounceId != null) clearTimeout(debounceId);
1948
- } catch {
1949
- }
1950
- debounceId = setTimeout(() => {
1951
- debounceId = null;
1952
- persistNow();
1953
- }, debounceMs);
1954
- }, "schedulePersist");
1955
- persistState.enabled = true;
1956
- persistState.key = storageKey;
1957
- persistState.storage = st;
1958
- persistState.persistNow = schedulePersist;
1959
- const origSet = store.set;
1960
- store.set = (k, v) => {
1961
- const res = origSet(k, v);
1962
- schedulePersist();
1963
- return res;
1964
- };
1965
- const origPatch = store.patch;
1966
- store.patch = (obj) => {
1967
- origPatch(obj);
1968
- schedulePersist();
1969
- };
1970
- Object.keys(store.actions).forEach((name) => {
1971
- const orig = store.actions[name];
1972
- if (typeof orig !== "function") return;
1973
- store.actions[name] = (...args) => {
1974
- const res = orig(...args);
1975
- schedulePersist();
1976
- return res;
1977
- };
1978
- store[name] = store.actions[name];
1979
- });
1980
- Object.keys(signals).forEach((k) => {
1981
- try {
1982
- store.use(k);
1983
- } catch {
1984
- }
1985
- });
1986
- schedulePersist();
1987
- return store;
1988
- };
1989
- return store;
1990
- }
1991
- __name(createStore, "createStore");
1992
- const Store = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1993
- __proto__: null,
1994
- createStore
1995
- }, Symbol.toStringTag, { value: "Module" }));
1996
- function render(Component, container) {
1997
- initLifecycleRoot(container);
1998
- initErrorHandling(container);
1999
- try {
2000
- const root = createElement(Component);
2001
- container.appendChild(root);
2002
- } catch (e) {
2003
- reportError(e, { phase: "render", component: Component?.name ?? "App" });
2004
- }
2005
- }
2006
- __name(render, "render");
2007
- const index = {
2008
- ...Signals,
2009
- ...DOM,
2010
- ...Lifecycle,
2011
- ...Router,
2012
- ...Errors,
2013
- ...Suspense$1,
2014
- ...Context,
2015
- ...Store,
2016
- render
2017
- };
2018
- export {
2019
- ErrorBoundary,
2020
- ErrorProvider,
2021
- Fragment,
2022
- Link,
2023
- NotFound,
2024
- Page,
2025
- Route,
2026
- Suspense,
2027
- SuspenseContext,
2028
- batch,
2029
- bindContext,
2030
- bindable,
2031
- captureContext,
2032
- clearErrors,
2033
- createComponentInstance,
2034
- createContext,
2035
- createElement,
2036
- createStore,
2037
- index as default,
2038
- derive,
2039
- effect,
2040
- getCurrentComponent,
2041
- getIsNotFound,
2042
- getLocation,
2043
- getPathname,
2044
- getRouteReady,
2045
- initErrorHandling,
2046
- initLifecycleRoot,
2047
- lazy,
2048
- mountComponent,
2049
- navigate,
2050
- onCleanup,
2051
- onMount,
2052
- onUnmount,
2053
- onUpdate,
2054
- pick,
2055
- readContext,
2056
- render,
2057
- reportError,
2058
- runInContext,
2059
- runInLifecycle,
2060
- setNotFound,
2061
- signal,
2062
- startHead,
2063
- triggerUpdate,
2064
- unmountComponent,
2065
- untrack,
2066
- useErrors,
2067
- useIsNotFound,
2068
- useLocation,
2069
- usePathname,
2070
- useRouteReady
2071
- };