@vobs/router 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,1700 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+
6
+ // packages/reactivity/src/debug.ts
7
+ var activeDebugHooks = null;
8
+ var signalNames = /* @__PURE__ */ new WeakMap();
9
+ function hasDebugHooks() {
10
+ return activeDebugHooks !== null;
11
+ }
12
+ __name(hasDebugHooks, "hasDebugHooks");
13
+ function setSignalDebugName(signal, name) {
14
+ signalNames.set(signal, name);
15
+ invokeDebug("signalNamed", signal, name);
16
+ }
17
+ __name(setSignalDebugName, "setSignalDebugName");
18
+ function invokeDebug(name, ...args) {
19
+ return;
20
+ }
21
+ __name(invokeDebug, "invokeDebug");
22
+
23
+ // packages/reactivity/src/owner.ts
24
+ var currentOwner = null;
25
+ var nextOwnerId = 1;
26
+ var ownerNames = /* @__PURE__ */ new WeakMap();
27
+ function createOwner() {
28
+ const parent = currentOwner;
29
+ let disposed = parent?.disposed ?? false;
30
+ const children = [];
31
+ const cleanups = [];
32
+ const errorHandlers = /* @__PURE__ */ new Set();
33
+ const owner = {
34
+ id: `owner-${nextOwnerId++}`,
35
+ parent,
36
+ children,
37
+ depth: (parent?.depth ?? -1) + 1,
38
+ get disposed() {
39
+ return disposed;
40
+ },
41
+ run(fn) {
42
+ if (disposed) throw new Error("Vobs: \u5DF2\u9500\u6BC1\u7684 Owner \u4E0D\u80FD\u7EE7\u7EED\u8FD0\u884C");
43
+ const previous = currentOwner;
44
+ currentOwner = owner;
45
+ try {
46
+ return fn();
47
+ } finally {
48
+ currentOwner = previous;
49
+ }
50
+ },
51
+ addCleanup(cleanup) {
52
+ if (disposed) {
53
+ cleanup();
54
+ return;
55
+ }
56
+ cleanups.push(cleanup);
57
+ },
58
+ onDispose(cleanup) {
59
+ owner.addCleanup(cleanup);
60
+ },
61
+ onError(handler) {
62
+ errorHandlers.add(handler);
63
+ const remove = /* @__PURE__ */ __name(() => errorHandlers.delete(handler), "remove");
64
+ owner.addCleanup(remove);
65
+ return remove;
66
+ },
67
+ handleError(error) {
68
+ for (const handler of [...errorHandlers].reverse()) {
69
+ try {
70
+ handler(error);
71
+ return true;
72
+ } catch (handlerError) {
73
+ return parent?.handleError(handlerError) ?? false;
74
+ }
75
+ }
76
+ return parent?.handleError(error) ?? false;
77
+ },
78
+ dispose() {
79
+ if (disposed) return;
80
+ disposed = true;
81
+ for (const child of [...children]) child.dispose();
82
+ children.length = 0;
83
+ let firstError;
84
+ for (let index = cleanups.length - 1; index >= 0; index--) {
85
+ try {
86
+ cleanups[index]();
87
+ } catch (error) {
88
+ firstError ?? (firstError = error);
89
+ }
90
+ }
91
+ cleanups.length = 0;
92
+ if (parent) {
93
+ const index = parent.children.indexOf(owner);
94
+ if (index >= 0) parent.children.splice(index, 1);
95
+ }
96
+ if (firstError) throw firstError;
97
+ }
98
+ };
99
+ if (parent && !parent.disposed) parent.children.push(owner);
100
+ return owner;
101
+ }
102
+ __name(createOwner, "createOwner");
103
+ function setOwnerDebugName(owner, name) {
104
+ ownerNames.set(owner, name);
105
+ }
106
+ __name(setOwnerDebugName, "setOwnerDebugName");
107
+ function getCurrentOwner() {
108
+ return currentOwner;
109
+ }
110
+ __name(getCurrentOwner, "getCurrentOwner");
111
+
112
+ // packages/reactivity/src/signal.ts
113
+ var currentSubscriber = null;
114
+ function getCurrentSubscriber() {
115
+ return currentSubscriber;
116
+ }
117
+ __name(getCurrentSubscriber, "getCurrentSubscriber");
118
+ function setCurrentSubscriber(subscriber) {
119
+ currentSubscriber = subscriber;
120
+ }
121
+ __name(setCurrentSubscriber, "setCurrentSubscriber");
122
+ function trackDependency(dependency) {
123
+ if (!currentSubscriber || currentSubscriber.disposed) return;
124
+ !currentSubscriber.dependencies.has(dependency);
125
+ currentSubscriber.dependencies.add(dependency);
126
+ }
127
+ __name(trackDependency, "trackDependency");
128
+ function state(initialValue, debugName) {
129
+ let value = initialValue;
130
+ let disposed = false;
131
+ const subscribers = /* @__PURE__ */ new Set();
132
+ const signalInstance = {
133
+ get value() {
134
+ const subscriber = getCurrentSubscriber();
135
+ if (subscriber && !subscriber.disposed) {
136
+ subscribers.add(subscriber);
137
+ trackDependency(signalInstance);
138
+ }
139
+ return value;
140
+ },
141
+ set value(nextValue) {
142
+ if (disposed || Object.is(value, nextValue)) return;
143
+ value = nextValue;
144
+ for (const subscriber of [...subscribers]) subscriber.notify();
145
+ },
146
+ unsubscribe(subscriber) {
147
+ subscribers.delete(subscriber);
148
+ },
149
+ // 与 `.value =` 赋值同一条路径:判等短路、debug hook、notify 全部一致。
150
+ // 以闭包实现,可安全地作为回调直接传递(无 this 绑定问题)。
151
+ set(next) {
152
+ signalInstance.value = next;
153
+ },
154
+ dispose() {
155
+ if (disposed) return;
156
+ disposed = true;
157
+ subscribers.clear();
158
+ }
159
+ };
160
+ const owner = getCurrentOwner();
161
+ owner?.addCleanup(signalInstance.dispose);
162
+ if (debugName?.trim()) setSignalDebugName(signalInstance, debugName.trim());
163
+ return signalInstance;
164
+ }
165
+ __name(state, "state");
166
+
167
+ // packages/reactivity/src/scheduler.ts
168
+ var _Scheduler = class _Scheduler {
169
+ constructor() {
170
+ this.dirtyEffects = /* @__PURE__ */ new Set();
171
+ this.lowPriorityEffects = /* @__PURE__ */ new Set();
172
+ // flush 不可重入(flushing 标志保证),缓冲数组可在轮次间安全复用,避免每轮分配。
173
+ this.normalBuffer = [];
174
+ this.lowBuffer = [];
175
+ this.flushing = false;
176
+ this.scheduled = false;
177
+ this.batchDepth = 0;
178
+ }
179
+ schedule(effect2) {
180
+ if (effect2.disposed) return;
181
+ this.dirtyEffects.add(effect2);
182
+ this.lowPriorityEffects.delete(effect2);
183
+ this.ensureScheduled();
184
+ }
185
+ /** Queue an effect behind normal updates while preserving deterministic order. */
186
+ scheduleLow(effect2) {
187
+ if (effect2.disposed) return;
188
+ if (!this.dirtyEffects.has(effect2)) this.lowPriorityEffects.add(effect2);
189
+ this.ensureScheduled();
190
+ }
191
+ ensureScheduled() {
192
+ if (this.batchDepth === 0 && !this.flushing && !this.scheduled) {
193
+ this.scheduled = true;
194
+ queueMicrotask(() => {
195
+ this.scheduled = false;
196
+ this.flush();
197
+ });
198
+ }
199
+ }
200
+ remove(effect2) {
201
+ this.dirtyEffects.delete(effect2);
202
+ this.lowPriorityEffects.delete(effect2);
203
+ }
204
+ batch(fn) {
205
+ this.batchDepth++;
206
+ try {
207
+ return fn();
208
+ } finally {
209
+ this.batchDepth--;
210
+ if (this.batchDepth === 0) this.flush();
211
+ }
212
+ }
213
+ flush() {
214
+ if (this.flushing || this.batchDepth > 0) return;
215
+ this.flushing = true;
216
+ let rounds = 0;
217
+ let firstError;
218
+ let hasError = false;
219
+ try {
220
+ while (this.dirtyEffects.size > 0 || this.lowPriorityEffects.size > 0) {
221
+ if (++rounds > 100) {
222
+ this.dirtyEffects.clear();
223
+ this.lowPriorityEffects.clear();
224
+ throw new Error("Vobs: \u54CD\u5E94\u5F0F\u66F4\u65B0\u8D85\u8FC7 100 \u8F6E\uFF0C\u53EF\u80FD\u5B58\u5728\u5FAA\u73AF\u4F9D\u8D56");
225
+ }
226
+ this.collectRunnable(this.dirtyEffects, this.normalBuffer);
227
+ this.collectRunnable(this.lowPriorityEffects, this.lowBuffer);
228
+ sortEffects(this.normalBuffer);
229
+ sortEffects(this.lowBuffer);
230
+ for (const effect2 of this.normalBuffer) {
231
+ try {
232
+ effect2.run();
233
+ } catch (error) {
234
+ if (!hasError) {
235
+ firstError = error;
236
+ hasError = true;
237
+ }
238
+ }
239
+ }
240
+ for (const effect2 of this.lowBuffer) {
241
+ try {
242
+ effect2.run();
243
+ } catch (error) {
244
+ if (!hasError) {
245
+ firstError = error;
246
+ hasError = true;
247
+ }
248
+ }
249
+ }
250
+ this.normalBuffer.length = 0;
251
+ this.lowBuffer.length = 0;
252
+ }
253
+ } finally {
254
+ this.normalBuffer.length = 0;
255
+ this.lowBuffer.length = 0;
256
+ this.flushing = false;
257
+ }
258
+ if (hasError) throw firstError;
259
+ }
260
+ /** 收集未 disposed 的 effect 并清空源集合;run() 期间新调度的 effect 留给下一轮。 */
261
+ collectRunnable(source, target) {
262
+ for (const effect2 of source) {
263
+ if (!effect2.disposed) target.push(effect2);
264
+ }
265
+ source.clear();
266
+ }
267
+ };
268
+ __name(_Scheduler, "Scheduler");
269
+ var Scheduler = _Scheduler;
270
+ function sortEffects(effects) {
271
+ if (effects.length > 1) {
272
+ effects.sort((a, b) => b.depth - a.depth || a.order - b.order);
273
+ }
274
+ }
275
+ __name(sortEffects, "sortEffects");
276
+ var scheduler = new Scheduler();
277
+
278
+ // packages/reactivity/src/effect.ts
279
+ var nextEffectOrder = 1;
280
+ function cleanupDependencies(subscriber) {
281
+ for (const dependency of subscriber.dependencies) {
282
+ dependency.unsubscribe(subscriber);
283
+ }
284
+ subscriber.dependencies.clear();
285
+ }
286
+ __name(cleanupDependencies, "cleanupDependencies");
287
+ function effect(callback) {
288
+ const owner = getCurrentOwner();
289
+ let cleanup;
290
+ let dirty = true;
291
+ let disposed = false;
292
+ const eff = {
293
+ order: nextEffectOrder++,
294
+ depth: owner?.depth ?? 0,
295
+ dependencies: /* @__PURE__ */ new Set(),
296
+ get disposed() {
297
+ return disposed;
298
+ },
299
+ notify() {
300
+ if (disposed || dirty) return;
301
+ dirty = true;
302
+ scheduler.schedule(eff);
303
+ },
304
+ run() {
305
+ if (disposed || !dirty) return;
306
+ dirty = false;
307
+ const previousCleanup = cleanup;
308
+ cleanup = void 0;
309
+ let cleanupError;
310
+ if (previousCleanup) {
311
+ try {
312
+ previousCleanup();
313
+ } catch (error) {
314
+ const handled2 = owner?.handleError(error) ?? false;
315
+ if (!handled2) cleanupError = error;
316
+ }
317
+ }
318
+ cleanupDependencies(eff);
319
+ const previous = getCurrentSubscriber();
320
+ setCurrentSubscriber(eff);
321
+ let thrown;
322
+ let handled = false;
323
+ try {
324
+ const result = owner ? owner.run(callback) : callback();
325
+ cleanup = typeof result === "function" ? result : void 0;
326
+ } catch (error) {
327
+ thrown = error;
328
+ handled = owner?.handleError(error) ?? false;
329
+ if (!handled) throw error;
330
+ } finally {
331
+ setCurrentSubscriber(previous);
332
+ }
333
+ if (cleanupError && !thrown) throw cleanupError;
334
+ },
335
+ scheduleLow() {
336
+ if (disposed || dirty) return;
337
+ dirty = true;
338
+ scheduler.scheduleLow(eff);
339
+ },
340
+ dispose() {
341
+ if (disposed) return;
342
+ disposed = true;
343
+ dirty = false;
344
+ scheduler.remove(eff);
345
+ const previousCleanup = cleanup;
346
+ cleanup = void 0;
347
+ let cleanupError;
348
+ if (previousCleanup) {
349
+ try {
350
+ previousCleanup();
351
+ } catch (error) {
352
+ const handled = owner?.handleError(error) ?? false;
353
+ if (!handled) cleanupError = error;
354
+ }
355
+ }
356
+ cleanupDependencies(eff);
357
+ if (cleanupError) throw cleanupError;
358
+ }
359
+ };
360
+ owner?.addCleanup(eff.dispose);
361
+ eff.run();
362
+ return eff;
363
+ }
364
+ __name(effect, "effect");
365
+
366
+ // packages/runtime/src/debug.ts
367
+ var activeRuntimeDebugHooks = null;
368
+ var activeRuntimeDebugContext = null;
369
+ function getRuntimeDebugHooks() {
370
+ return activeRuntimeDebugHooks;
371
+ }
372
+ __name(getRuntimeDebugHooks, "getRuntimeDebugHooks");
373
+ function getRuntimeDebugContext() {
374
+ return activeRuntimeDebugContext;
375
+ }
376
+ __name(getRuntimeDebugContext, "getRuntimeDebugContext");
377
+ function runWithRuntimeDebugContext(context, task) {
378
+ const previous = activeRuntimeDebugContext;
379
+ const next = { ...previous, ...context };
380
+ activeRuntimeDebugContext = next;
381
+ let result;
382
+ try {
383
+ result = task();
384
+ } catch (error) {
385
+ activeRuntimeDebugContext = previous;
386
+ throw error;
387
+ }
388
+ if (isPromiseLike(result)) {
389
+ return Promise.resolve(result).finally(() => {
390
+ if (activeRuntimeDebugContext === next) activeRuntimeDebugContext = previous;
391
+ });
392
+ }
393
+ activeRuntimeDebugContext = previous;
394
+ return result;
395
+ }
396
+ __name(runWithRuntimeDebugContext, "runWithRuntimeDebugContext");
397
+ function invokeRuntimeDebug(name, ...args) {
398
+ return;
399
+ }
400
+ __name(invokeRuntimeDebug, "invokeRuntimeDebug");
401
+ function isPromiseLike(value) {
402
+ return Boolean(value) && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
403
+ }
404
+ __name(isPromiseLike, "isPromiseLike");
405
+ function describeDebugNode(node) {
406
+ if (!node || typeof node !== "object") return "node";
407
+ const value = node;
408
+ const name = typeof value.tagName === "string" ? value.tagName.toLowerCase() : typeof value.nodeName === "string" ? value.nodeName.toLowerCase() : "node";
409
+ const id = typeof value.id === "string" && value.id ? `#${value.id}` : "";
410
+ const className = typeof value.className === "string" && value.className ? `.${value.className.trim().split(/\s+/).filter(Boolean).join(".")}` : "";
411
+ return `${name}${id}${className}`;
412
+ }
413
+ __name(describeDebugNode, "describeDebugNode");
414
+
415
+ // packages/runtime/src/hmr.ts
416
+ var globalTarget = globalThis;
417
+ var hmrGlobal = globalTarget.__VOBS_HMR__ ?? { modules: /* @__PURE__ */ new Map() };
418
+ globalTarget.__VOBS_HMR__ = hmrGlobal;
419
+ function registerHmrInstance(moduleId, instance) {
420
+ const instances = getModule(moduleId).instances;
421
+ instances.add(instance);
422
+ return () => instances.delete(instance);
423
+ }
424
+ __name(registerHmrInstance, "registerHmrInstance");
425
+ function markHmrInstanceMounted(node, parent) {
426
+ const instance = hmrInstances.get(node);
427
+ if (instance) instance.parent = parent;
428
+ }
429
+ __name(markHmrInstanceMounted, "markHmrInstanceMounted");
430
+ function getModule(moduleId) {
431
+ let module = hmrGlobal.modules.get(moduleId);
432
+ if (!module) {
433
+ module = { components: /* @__PURE__ */ new Map(), state: /* @__PURE__ */ new Map(), instances: /* @__PURE__ */ new Set() };
434
+ hmrGlobal.modules.set(moduleId, module);
435
+ }
436
+ return module;
437
+ }
438
+ __name(getModule, "getModule");
439
+ var hmrInstances = /* @__PURE__ */ new WeakMap();
440
+ function associateHmrInstance(node, instance) {
441
+ hmrInstances.set(node, instance);
442
+ }
443
+ __name(associateHmrInstance, "associateHmrInstance");
444
+ var nodeOwners = /* @__PURE__ */ new WeakMap();
445
+ function getRenderer() {
446
+ {
447
+ throw new Error("\u6E32\u67D3\u5668\u672A\u521D\u59CB\u5316");
448
+ }
449
+ }
450
+ __name(getRenderer, "getRenderer");
451
+ function createComment(content) {
452
+ return getRenderer().createComment(content);
453
+ }
454
+ __name(createComment, "createComment");
455
+ function insertBefore(parent, child, anchor) {
456
+ if (isVobsFragment(child)) {
457
+ child.mount(parent, isVobsFragment(anchor) ? anchor.start : anchor);
458
+ return;
459
+ }
460
+ getRenderer().insertBefore(parent, child, isVobsFragment(anchor) ? anchor.start : anchor);
461
+ markHmrInstanceMounted(child, parent);
462
+ }
463
+ __name(insertBefore, "insertBefore");
464
+ function removeChild(parent, child) {
465
+ disposeNodeOwner(child);
466
+ if (isVobsFragment(child)) {
467
+ child.unmount(parent);
468
+ return;
469
+ }
470
+ getRenderer().removeChild(parent, child);
471
+ }
472
+ __name(removeChild, "removeChild");
473
+ function createComponent(component, props, source) {
474
+ const owner = createOwner();
475
+ const componentName = component.displayName || component.name || "anonymous";
476
+ setOwnerDebugName(owner, source ? `${componentName} (${source.file}:${source.line}:${source.column})` : componentName);
477
+ owner.onError((reason) => {
478
+ attachSourceLocation(reason, source);
479
+ attachComponentContext(reason, componentName, owner.id);
480
+ throw reason;
481
+ });
482
+ let node;
483
+ try {
484
+ node = owner.run(() => component(props));
485
+ } catch (error) {
486
+ owner.dispose();
487
+ attachSourceLocation(error, source);
488
+ attachComponentContext(error, componentName, owner.id);
489
+ throw error;
490
+ }
491
+ associateNodeOwner(node, owner);
492
+ const hmrKey = component.hmrKey;
493
+ if (hmrKey) {
494
+ const instance = {
495
+ node,
496
+ parent: null,
497
+ refresh() {
498
+ const previous = instance.node;
499
+ const next = owner.run(() => component(props));
500
+ if (instance.parent && !isVobsFragment(previous) && !isVobsFragment(next)) {
501
+ getRenderer().insertBefore(instance.parent, next, previous);
502
+ getRenderer().removeChild(instance.parent, previous);
503
+ }
504
+ nodeOwners.delete(previous);
505
+ nodeOwners.set(next, owner);
506
+ associateHmrInstance(next, instance);
507
+ instance.node = next;
508
+ }
509
+ };
510
+ associateHmrInstance(node, instance);
511
+ const separator = hmrKey.lastIndexOf(":");
512
+ const moduleId = separator < 0 ? hmrKey : hmrKey.slice(0, separator);
513
+ const cleanup = registerHmrInstance(moduleId, instance);
514
+ owner.onDispose(cleanup);
515
+ }
516
+ return node;
517
+ }
518
+ __name(createComponent, "createComponent");
519
+ function attachSourceLocation(reason, source) {
520
+ if (!source || (!reason || typeof reason !== "object" && typeof reason !== "function")) return;
521
+ const error = reason;
522
+ if (error.vobsSource) return;
523
+ try {
524
+ Object.defineProperty(error, "vobsSource", {
525
+ configurable: true,
526
+ enumerable: false,
527
+ value: source,
528
+ writable: false
529
+ });
530
+ } catch {
531
+ }
532
+ }
533
+ __name(attachSourceLocation, "attachSourceLocation");
534
+ function attachComponentContext(reason, component, ownerId) {
535
+ if (!reason || typeof reason !== "object" && typeof reason !== "function") return;
536
+ const error = reason;
537
+ try {
538
+ if (!error.vobsComponent) Object.defineProperty(error, "vobsComponent", { configurable: true, enumerable: false, value: component, writable: false });
539
+ if (!error.vobsOwnerId) Object.defineProperty(error, "vobsOwnerId", { configurable: true, enumerable: false, value: ownerId, writable: false });
540
+ } catch {
541
+ }
542
+ }
543
+ __name(attachComponentContext, "attachComponentContext");
544
+ function createBlock(factory) {
545
+ const owner = createOwner();
546
+ setOwnerDebugName(owner, "dynamic");
547
+ let node;
548
+ try {
549
+ node = owner.run(factory);
550
+ } catch (error) {
551
+ owner.dispose();
552
+ throw error;
553
+ }
554
+ if (!node) {
555
+ owner.dispose();
556
+ return null;
557
+ }
558
+ associateNodeOwner(node, owner);
559
+ return node;
560
+ }
561
+ __name(createBlock, "createBlock");
562
+ function associateNodeOwner(node, owner) {
563
+ nodeOwners.set(node, owner);
564
+ }
565
+ __name(associateNodeOwner, "associateNodeOwner");
566
+ function disposeNodeOwner(node) {
567
+ const owner = nodeOwners.get(node);
568
+ if (!owner) return;
569
+ nodeOwners.delete(node);
570
+ owner.dispose();
571
+ }
572
+ __name(disposeNodeOwner, "disposeNodeOwner");
573
+
574
+ // packages/runtime/src/fragment.ts
575
+ function createFragment(factory) {
576
+ const start = createComment("vobs:fragment:start");
577
+ const end = createComment("vobs:fragment:end");
578
+ let parent = null;
579
+ let initialized = false;
580
+ const owner = getCurrentOwner();
581
+ const fragment = {
582
+ kind: "vobs-fragment",
583
+ start,
584
+ end,
585
+ mount(nextParent, anchor) {
586
+ if (parent && parent !== nextParent) {
587
+ throw new Error("Vobs Fragment: \u4E0D\u80FD\u8DE8\u7236\u8282\u70B9\u79FB\u52A8 Fragment");
588
+ }
589
+ if (initialized) {
590
+ moveRange(nextParent, start, end, anchor);
591
+ return;
592
+ }
593
+ const renderer = getRenderer();
594
+ renderer.insertBefore(nextParent, start, anchor);
595
+ renderer.insertBefore(nextParent, end, anchor);
596
+ parent = nextParent;
597
+ initialized = true;
598
+ if (owner) owner.run(() => factory(nextParent, end));
599
+ else factory(nextParent, end);
600
+ },
601
+ unmount(nextParent) {
602
+ if (!initialized || parent !== nextParent) {
603
+ throw new Error("Vobs Fragment: Fragment \u4E0D\u5C5E\u4E8E\u6307\u5B9A\u7236\u8282\u70B9");
604
+ }
605
+ const renderer = getRenderer();
606
+ let current = renderer.nextSibling(start);
607
+ while (current && current !== end) {
608
+ const next = renderer.nextSibling(current);
609
+ renderer.removeChild(nextParent, current);
610
+ current = next;
611
+ }
612
+ renderer.removeChild(nextParent, start);
613
+ renderer.removeChild(nextParent, end);
614
+ parent = null;
615
+ initialized = false;
616
+ }
617
+ };
618
+ return fragment;
619
+ }
620
+ __name(createFragment, "createFragment");
621
+ function isVobsFragment(value) {
622
+ return Boolean(value) && typeof value === "object" && value.kind === "vobs-fragment";
623
+ }
624
+ __name(isVobsFragment, "isVobsFragment");
625
+ function moveRange(parent, start, end, anchor) {
626
+ const renderer = getRenderer();
627
+ const nodes = [start];
628
+ let current = renderer.nextSibling(start);
629
+ while (current) {
630
+ nodes.push(current);
631
+ if (current === end) break;
632
+ current = renderer.nextSibling(current);
633
+ }
634
+ if (nodes[nodes.length - 1] !== end) {
635
+ throw new Error("Vobs Fragment: \u627E\u4E0D\u5230\u7ED3\u675F\u951A\u70B9");
636
+ }
637
+ for (const node of nodes) renderer.insertBefore(parent, node, anchor);
638
+ }
639
+ __name(moveRange, "moveRange");
640
+
641
+ // packages/runtime/src/dynamic.ts
642
+ function insertDynamic(parent, anchor, factory) {
643
+ const marker = createComment("vobs:dynamic");
644
+ insertBefore(parent, marker, anchor);
645
+ let current = null;
646
+ effect(() => {
647
+ const next = createBlock(factory);
648
+ if (next === current) return;
649
+ if (current) removeChild(parent, current);
650
+ current = next;
651
+ if (current) insertBefore(parent, current, marker);
652
+ });
653
+ }
654
+ __name(insertDynamic, "insertDynamic");
655
+
656
+ // packages/runtime/src/error.ts
657
+ var _VobsError = class _VobsError extends Error {
658
+ constructor(options) {
659
+ super(options.message);
660
+ this.name = "VobsError";
661
+ this.code = options.code;
662
+ this.severity = options.severity ?? "error";
663
+ this.layer = options.layer ?? "runtime";
664
+ this.cause = options.cause;
665
+ this.fix = options.fix;
666
+ this.location = options.location;
667
+ this.trace = options.trace;
668
+ this.example = options.example;
669
+ this.docs = options.docs;
670
+ this.codeFrame = options.codeFrame;
671
+ }
672
+ };
673
+ __name(_VobsError, "VobsError");
674
+ var VobsError = _VobsError;
675
+ function isVobsError(value) {
676
+ return value instanceof VobsError || Boolean(value && typeof value === "object" && typeof value.code === "string" && typeof value.message === "string" && typeof value.layer === "string");
677
+ }
678
+ __name(isVobsError, "isVobsError");
679
+ function normalizeVobsError(value, defaults = {}) {
680
+ if (value instanceof VobsError) return value;
681
+ if (value instanceof Error) {
682
+ const metadata = value;
683
+ const code = defaults.code ?? (typeof metadata.vobsCode === "string" ? metadata.vobsCode : void 0);
684
+ if (code) defineErrorMetadata(value, "code", code);
685
+ defineErrorMetadata(value, "severity", defaults.severity ?? "error");
686
+ defineErrorMetadata(value, "layer", defaults.layer ?? "runtime");
687
+ const fix = defaults.fix ?? (typeof metadata.vobsHint === "string" ? metadata.vobsHint : void 0);
688
+ if (fix) defineErrorMetadata(value, "fix", fix);
689
+ const source = metadata.vobsSource;
690
+ if (source && typeof source === "object" && typeof source.file === "string" && typeof source.line === "number" && typeof source.column === "number") {
691
+ defineErrorMetadata(value, "location", source);
692
+ }
693
+ return value;
694
+ }
695
+ if (isVobsError(value)) {
696
+ const candidate = value;
697
+ return new VobsError({
698
+ code: candidate.code,
699
+ message: candidate.message,
700
+ severity: candidate.severity ?? defaults.severity,
701
+ layer: candidate.layer ?? defaults.layer,
702
+ cause: candidate.cause,
703
+ fix: candidate.fix ?? defaults.fix,
704
+ location: candidate.location,
705
+ trace: candidate.trace,
706
+ example: candidate.example,
707
+ docs: candidate.docs,
708
+ codeFrame: candidate.codeFrame
709
+ });
710
+ }
711
+ const message = String(value);
712
+ return new VobsError({
713
+ code: defaults.code ?? "VOBS_UNKNOWN",
714
+ message,
715
+ severity: defaults.severity ?? "error",
716
+ layer: defaults.layer ?? "runtime",
717
+ cause: void 0,
718
+ fix: defaults.fix
719
+ });
720
+ }
721
+ __name(normalizeVobsError, "normalizeVobsError");
722
+ function defineErrorMetadata(target, key, value) {
723
+ if (key in target) return;
724
+ try {
725
+ Object.defineProperty(target, key, { configurable: true, enumerable: false, value, writable: true });
726
+ } catch {
727
+ }
728
+ }
729
+ __name(defineErrorMetadata, "defineErrorMetadata");
730
+
731
+ // packages/runtime/src/boundary.ts
732
+ function insertBoundary(parent, anchor, options) {
733
+ const boundary = createOwner();
734
+ boundary.run(() => {
735
+ const error = state(null);
736
+ let fallbackActive = false;
737
+ let lastError = null;
738
+ let initialized = false;
739
+ let previousKey;
740
+ boundary.onError((reason) => {
741
+ if (fallbackActive) throw reason;
742
+ const normalized = normalizeVobsError(reason, {
743
+ code: "VOBS_R001",
744
+ layer: "runtime",
745
+ fix: "\u68C0\u67E5\u7EC4\u4EF6\u6E32\u67D3\u903B\u8F91\uFF0C\u6216\u5728\u8FB9\u754C fallback \u4E2D\u63D0\u4F9B\u6062\u590D\u64CD\u4F5C\u3002"
746
+ });
747
+ lastError = normalized;
748
+ invokeRuntimeDebug("error", {
749
+ error: normalized,
750
+ owner: boundary,
751
+ phase: "boundary",
752
+ handled: true,
753
+ recovery: "fallback"
754
+ });
755
+ error.value = normalized;
756
+ });
757
+ const retry = /* @__PURE__ */ __name(() => {
758
+ if (error.value) {
759
+ invokeRuntimeDebug("error", {
760
+ error: error.value,
761
+ owner: boundary,
762
+ phase: "boundary",
763
+ handled: true,
764
+ recovery: "retrying"
765
+ });
766
+ }
767
+ error.value = null;
768
+ return options.onRetry?.();
769
+ }, "retry");
770
+ insertDynamic(parent, anchor, () => {
771
+ const nextKey = options.resetKey?.();
772
+ if (!initialized || !Object.is(previousKey, nextKey)) {
773
+ initialized = true;
774
+ previousKey = nextKey;
775
+ if (error.value) error.value = null;
776
+ }
777
+ const currentError = error.value;
778
+ if (!currentError) {
779
+ if (fallbackActive && lastError) {
780
+ invokeRuntimeDebug("error", {
781
+ error: lastError,
782
+ owner: boundary,
783
+ phase: "boundary",
784
+ handled: true,
785
+ recovery: "recovered"
786
+ });
787
+ lastError = null;
788
+ }
789
+ fallbackActive = false;
790
+ return options.children();
791
+ }
792
+ fallbackActive = true;
793
+ return options.fallback(currentError, retry);
794
+ });
795
+ });
796
+ }
797
+ __name(insertBoundary, "insertBoundary");
798
+
799
+ // packages/vobs/src/context.ts
800
+ var ownerProviders = /* @__PURE__ */ new WeakMap();
801
+ function inject(key, fallback) {
802
+ const owner = getCurrentOwner();
803
+ const value = owner ? injectFromOwner(owner, key) : void 0;
804
+ return value === void 0 ? fallback : value;
805
+ }
806
+ __name(inject, "inject");
807
+ function injectFromOwner(owner, key) {
808
+ let current = owner;
809
+ while (current) {
810
+ const providers = ownerProviders.get(current);
811
+ if (providers?.has(key)) return providers.get(key);
812
+ current = current.parent;
813
+ }
814
+ return void 0;
815
+ }
816
+ __name(injectFromOwner, "injectFromOwner");
817
+
818
+ // packages/vobs/src/app.ts
819
+ function createInjectionKey(description) {
820
+ return Symbol(description);
821
+ }
822
+ __name(createInjectionKey, "createInjectionKey");
823
+
824
+ // packages/router/src/debug.ts
825
+ var listeners = /* @__PURE__ */ new Set();
826
+ var nextRouterId = 1;
827
+ function createRouterDebugId() {
828
+ return `router-${nextRouterId++}`;
829
+ }
830
+ __name(createRouterDebugId, "createRouterDebugId");
831
+ function subscribeRouterDebug(listener) {
832
+ listeners.add(listener);
833
+ return () => listeners.delete(listener);
834
+ }
835
+ __name(subscribeRouterDebug, "subscribeRouterDebug");
836
+ function emitRouterDebug(routerId, type, payload, context) {
837
+ const event = { routerId, type, payload, context };
838
+ for (const listener of [...listeners]) {
839
+ try {
840
+ listener(event);
841
+ } catch {
842
+ }
843
+ }
844
+ }
845
+ __name(emitRouterDebug, "emitRouterDebug");
846
+
847
+ // packages/router/src/index.ts
848
+ var _NavigationCancelledError = class _NavigationCancelledError extends Error {
849
+ constructor() {
850
+ super("Vobs Router: \u5BFC\u822A\u5DF2\u88AB\u66F4\u65B0\u7684\u5BFC\u822A\u53D6\u6D88");
851
+ this.code = "NAVIGATION_CANCELLED";
852
+ this.name = "NavigationCancelledError";
853
+ }
854
+ };
855
+ __name(_NavigationCancelledError, "NavigationCancelledError");
856
+ var NavigationCancelledError = _NavigationCancelledError;
857
+ var _NavigationRedirectError = class _NavigationRedirectError extends Error {
858
+ constructor() {
859
+ super("Vobs Router: \u5BFC\u822A\u91CD\u5B9A\u5411\u8D85\u8FC7\u6700\u5927\u6B21\u6570");
860
+ this.code = "NAVIGATION_REDIRECT_LIMIT";
861
+ this.name = "NavigationRedirectError";
862
+ }
863
+ };
864
+ __name(_NavigationRedirectError, "NavigationRedirectError");
865
+ var NavigationRedirectError = _NavigationRedirectError;
866
+ var ROUTER_KEY = createInjectionKey("vobs.router");
867
+ function lazy(loader) {
868
+ return {
869
+ kind: "vobs-lazy-route",
870
+ load: loader
871
+ };
872
+ }
873
+ __name(lazy, "lazy");
874
+ function createMemoryHistory(initial = "/") {
875
+ let entries = [{ path: normalizeHistoryPath(initial), state: void 0 }];
876
+ let index = 0;
877
+ const listeners2 = /* @__PURE__ */ new Set();
878
+ return {
879
+ get location() {
880
+ return entries[index].path;
881
+ },
882
+ get state() {
883
+ return entries[index].state;
884
+ },
885
+ push(path, state2) {
886
+ const next = normalizeHistoryPath(path);
887
+ entries = entries.slice(0, index + 1);
888
+ entries.push({ path: next, state: state2 });
889
+ index++;
890
+ },
891
+ replace(path, state2) {
892
+ entries[index] = { path: normalizeHistoryPath(path), state: state2 };
893
+ },
894
+ back() {
895
+ if (index === 0) return;
896
+ index--;
897
+ notifyListeners(listeners2, entries[index].path, entries[index].state);
898
+ },
899
+ listen(listener) {
900
+ listeners2.add(listener);
901
+ return () => listeners2.delete(listener);
902
+ }
903
+ };
904
+ }
905
+ __name(createMemoryHistory, "createMemoryHistory");
906
+ function createBrowserHistory(base = "") {
907
+ if (typeof window === "undefined") {
908
+ throw new Error("Vobs Router: createBrowserHistory \u9700\u8981\u6D4F\u89C8\u5668\u73AF\u5883");
909
+ }
910
+ const normalizedBase = normalizeBase(base);
911
+ const listeners2 = /* @__PURE__ */ new Set();
912
+ const onPopState = /* @__PURE__ */ __name((event) => {
913
+ notifyListeners(listeners2, readBrowserLocation(normalizedBase), event.state);
914
+ }, "onPopState");
915
+ return {
916
+ get location() {
917
+ return readBrowserLocation(normalizedBase);
918
+ },
919
+ get state() {
920
+ return window.history.state;
921
+ },
922
+ push(path, state2) {
923
+ window.history.pushState(state2 ?? null, "", withBase(normalizeHistoryPath(path), normalizedBase));
924
+ },
925
+ replace(path, state2) {
926
+ window.history.replaceState(state2 ?? null, "", withBase(normalizeHistoryPath(path), normalizedBase));
927
+ },
928
+ back() {
929
+ window.history.back();
930
+ },
931
+ listen(listener) {
932
+ if (listeners2.size === 0) window.addEventListener("popstate", onPopState);
933
+ listeners2.add(listener);
934
+ return () => {
935
+ listeners2.delete(listener);
936
+ if (listeners2.size === 0) window.removeEventListener("popstate", onPopState);
937
+ };
938
+ }
939
+ };
940
+ }
941
+ __name(createBrowserHistory, "createBrowserHistory");
942
+ function createRouter(options) {
943
+ const matchers = normalizeRoutes(options.routes);
944
+ const history = options.history ?? defaultHistory();
945
+ const routerDebugId = createRouterDebugId();
946
+ matchers.sort(compareMatchers);
947
+ const currentRoute = state(resolvePath(history.location));
948
+ const lazyStates = /* @__PURE__ */ new Map();
949
+ const guards = [];
950
+ const navigationHistory = [];
951
+ const dataRequests = [];
952
+ const errors = [];
953
+ const dataLoaders = /* @__PURE__ */ new Map();
954
+ const dataRequestContexts = /* @__PURE__ */ new Map();
955
+ const routerListeners = /* @__PURE__ */ new Map();
956
+ let navigationState = { status: "idle", from: currentRoute.value.fullPath, to: currentRoute.value.fullPath };
957
+ let navigationCount = 0;
958
+ let totalNavigationDuration = 0;
959
+ let slowNavigationCount = 0;
960
+ let nextDataRequestId = 1;
961
+ let nextErrorId = 1;
962
+ let navigationId = 0;
963
+ let destroyed = false;
964
+ const viewRevision = state(0);
965
+ function resolve(to) {
966
+ ensureActive();
967
+ const target = typeof to === "string" ? parseTargetString(to) : normalizeTarget(to, matchers);
968
+ return resolvePath(buildTargetPath(target.path, target.query, target.hash), target.state);
969
+ }
970
+ __name(resolve, "resolve");
971
+ function resolvePath(rawPath, state2) {
972
+ const parsed = parseTargetString(rawPath);
973
+ const matched = matchers.find((matcher) => matcher.regex.exec(parsed.path));
974
+ const params = matched ? extractParams(matched, parsed.path) : {};
975
+ const record = matched?.record ?? null;
976
+ const query = parsed.query;
977
+ const hash = parsed.hash;
978
+ return {
979
+ path: parsed.path,
980
+ fullPath: buildTargetPath(parsed.path, query, hash),
981
+ params,
982
+ query,
983
+ hash,
984
+ name: record?.name,
985
+ meta: matched?.meta ?? {},
986
+ record,
987
+ matched: matched?.chain ?? EMPTY_MATCHED,
988
+ state: state2
989
+ };
990
+ }
991
+ __name(resolvePath, "resolvePath");
992
+ async function navigate(to, replaceHistory, fromHistory, historyState) {
993
+ ensureActive();
994
+ const id = ++navigationId;
995
+ const from = currentRoute.value;
996
+ let target = resolve(to);
997
+ if (fromHistory && historyState !== void 0) target = { ...target, state: historyState };
998
+ const source = fromHistory ? "history" : replaceHistory ? "replace" : "push";
999
+ const startedAt = now();
1000
+ const initialTarget = target.fullPath;
1001
+ let terminalRecorded = false;
1002
+ navigationState = { status: "loading", from: from.fullPath, to: target.fullPath, traceId: id };
1003
+ emitRouter("navigation:start", navigationState);
1004
+ if (target.fullPath === from.fullPath && !fromHistory) {
1005
+ navigationState = { status: "idle", from: from.fullPath, to: target.fullPath };
1006
+ return from;
1007
+ }
1008
+ try {
1009
+ for (let redirectCount = 0; ; redirectCount++) {
1010
+ ensureNavigationIsCurrent(id);
1011
+ let redirect;
1012
+ for (const guard of [...guards]) {
1013
+ let result;
1014
+ try {
1015
+ result = await guard(target, from);
1016
+ } catch (reason) {
1017
+ if (reason instanceof NavigationCancelledError) throw reason;
1018
+ const error = toError(reason);
1019
+ reportError("navigation", error, target.fullPath);
1020
+ recordNavigation({ id, from: from.fullPath, to: target.fullPath, status: "error", source, startedAt, endedAt: now(), duration: now() - startedAt, error: error.message });
1021
+ terminalRecorded = true;
1022
+ throw reason;
1023
+ }
1024
+ ensureNavigationIsCurrent(id);
1025
+ if (result === false) {
1026
+ recordNavigation({ id, from: from.fullPath, to: target.fullPath, status: "cancelled", source, startedAt, endedAt: now(), duration: now() - startedAt });
1027
+ terminalRecorded = true;
1028
+ return false;
1029
+ }
1030
+ if (typeof result === "string" || isRouteLocationRaw(result)) {
1031
+ redirect = result;
1032
+ break;
1033
+ }
1034
+ }
1035
+ for (const record of target.matched) {
1036
+ if (!record.loader) continue;
1037
+ ensureNavigationIsCurrent(id);
1038
+ await trackDataRequest(
1039
+ "loader",
1040
+ `${target.fullPath}#${record.path ?? record.name ?? "route"}`,
1041
+ (context) => record.loader({ route: target, navigationId: id, dataRequestId: context.dataRequestId }),
1042
+ { route: target.fullPath, navigationId: id, trigger: "navigation" }
1043
+ );
1044
+ }
1045
+ ensureNavigationIsCurrent(id);
1046
+ if (redirect !== void 0) {
1047
+ if (redirectCount >= 10) {
1048
+ const error = new NavigationRedirectError();
1049
+ recordNavigation({ id, from: from.fullPath, to: target.fullPath, status: "error", source, startedAt, endedAt: now(), duration: now() - startedAt, error: error.message });
1050
+ terminalRecorded = true;
1051
+ throw error;
1052
+ }
1053
+ const redirected = resolve(redirect);
1054
+ if (redirected.fullPath === target.fullPath) return false;
1055
+ recordNavigation({ id, from: from.fullPath, to: target.fullPath, status: "redirected", source, startedAt, endedAt: now(), duration: now() - startedAt, redirect: redirected.fullPath });
1056
+ target = redirected;
1057
+ continue;
1058
+ }
1059
+ if (target.fullPath === from.fullPath) return from;
1060
+ if (!fromHistory) {
1061
+ if (replaceHistory) history.replace(target.fullPath, target.state);
1062
+ else history.push(target.fullPath, target.state);
1063
+ }
1064
+ currentRoute.value = target;
1065
+ recordNavigation({ id, from: from.fullPath, to: target.fullPath, status: "success", source, startedAt, endedAt: now(), duration: now() - startedAt, redirect: target.fullPath !== initialTarget ? target.fullPath : void 0 });
1066
+ terminalRecorded = true;
1067
+ return target;
1068
+ }
1069
+ } catch (reason) {
1070
+ if (reason instanceof NavigationCancelledError) {
1071
+ recordNavigation({ id, from: from.fullPath, to: target.fullPath, status: "cancelled", source, startedAt, endedAt: now(), duration: now() - startedAt });
1072
+ terminalRecorded = true;
1073
+ } else if (!terminalRecorded) {
1074
+ const error = toError(reason);
1075
+ reportError("navigation", error, target.fullPath);
1076
+ recordNavigation({ id, from: from.fullPath, to: target.fullPath, status: "error", source, startedAt, endedAt: now(), duration: now() - startedAt, error: error.message });
1077
+ terminalRecorded = true;
1078
+ }
1079
+ throw reason;
1080
+ }
1081
+ }
1082
+ __name(navigate, "navigate");
1083
+ function now() {
1084
+ return typeof performance === "undefined" ? Date.now() : performance.now();
1085
+ }
1086
+ __name(now, "now");
1087
+ function emitRouter(event, payload) {
1088
+ for (const callback of routerListeners.get(event) ?? []) {
1089
+ try {
1090
+ callback(payload);
1091
+ } catch {
1092
+ }
1093
+ }
1094
+ emitRouterDebug(routerDebugId, event, payload, getRuntimeDebugContext() ?? void 0);
1095
+ }
1096
+ __name(emitRouter, "emitRouter");
1097
+ function recordNavigation(trace) {
1098
+ navigationHistory.push(Object.freeze(trace));
1099
+ if (navigationHistory.length > 100) navigationHistory.shift();
1100
+ navigationCount++;
1101
+ totalNavigationDuration += trace.duration;
1102
+ if (trace.duration >= 16) slowNavigationCount++;
1103
+ if (trace.id === navigationId) {
1104
+ navigationState = trace.status === "error" ? { status: "error", from: trace.from, to: trace.to, traceId: trace.id, error: trace.error } : { status: "idle", from: trace.from, to: trace.to, traceId: trace.id };
1105
+ }
1106
+ emitRouter("navigation:end", trace);
1107
+ emitRouter("route:update", currentRoute.value);
1108
+ }
1109
+ __name(recordNavigation, "recordNavigation");
1110
+ async function trackDataRequest(kind, key, task, optionsOrRoute = {}) {
1111
+ ensureActive();
1112
+ const options2 = typeof optionsOrRoute === "string" ? { route: optionsOrRoute } : optionsOrRoute;
1113
+ const id = nextDataRequestId++;
1114
+ const startedAt = now();
1115
+ const context = getRuntimeDebugContext();
1116
+ const route = options2.route ?? currentRoute.value.fullPath;
1117
+ const requestContext = {
1118
+ ...context,
1119
+ environment: options2.environment ?? context?.environment,
1120
+ route,
1121
+ navigationId: options2.navigationId ?? context?.navigationId,
1122
+ dataRequestId: id,
1123
+ source: kind
1124
+ };
1125
+ const loading = {
1126
+ id,
1127
+ kind,
1128
+ key,
1129
+ route,
1130
+ status: "loading",
1131
+ startedAt,
1132
+ navigationId: requestContext.navigationId,
1133
+ trigger: options2.trigger,
1134
+ environment: requestContext.environment
1135
+ };
1136
+ dataRequests.push(loading);
1137
+ if (dataRequests.length > 100) dataRequests.shift();
1138
+ dataRequestContexts.set(id, requestContext);
1139
+ emitRouter("route:update", currentRoute.value);
1140
+ emitRouter("data-request", loading);
1141
+ emitRouterDebug(routerDebugId, "data-request", { phase: "start", trace: loading }, requestContext);
1142
+ dataLoaders.set(key, { kind, route, task });
1143
+ try {
1144
+ const result = await runWithRuntimeDebugContext(requestContext, () => task({ dataRequestId: id }));
1145
+ const endedAt = now();
1146
+ replaceDataRequest(id, { ...loading, status: "success", endedAt, duration: endedAt - startedAt, result });
1147
+ return result;
1148
+ } catch (reason) {
1149
+ const endedAt = now();
1150
+ const error = toError(reason);
1151
+ const status = isAbortError(reason) ? "cancelled" : "error";
1152
+ if (status === "error") reportError(kind, error, route, { requestId: id, navigationId: requestContext.navigationId });
1153
+ replaceDataRequest(id, { ...loading, status, endedAt, duration: endedAt - startedAt, error: status === "error" ? error.message : void 0 });
1154
+ throw reason;
1155
+ }
1156
+ }
1157
+ __name(trackDataRequest, "trackDataRequest");
1158
+ function replaceDataRequest(id, trace) {
1159
+ const index = dataRequests.findIndex((item) => item.id === id);
1160
+ if (index >= 0) dataRequests[index] = Object.freeze(trace);
1161
+ emitRouter("route:update", currentRoute.value);
1162
+ emitRouter("data-request", trace);
1163
+ emitRouterDebug(routerDebugId, "data-request", { phase: "end", trace }, dataRequestContexts.get(id));
1164
+ dataRequestContexts.delete(id);
1165
+ }
1166
+ __name(replaceDataRequest, "replaceDataRequest");
1167
+ function reportError(phase, reason, route = currentRoute.value.fullPath, context = {}) {
1168
+ const error = toError(reason);
1169
+ errors.push(Object.freeze({
1170
+ id: nextErrorId++,
1171
+ phase,
1172
+ route,
1173
+ message: error.message,
1174
+ stack: error.stack,
1175
+ timestamp: now(),
1176
+ requestId: context.requestId,
1177
+ navigationId: context.navigationId
1178
+ }));
1179
+ if (errors.length > 100) errors.shift();
1180
+ emitRouter("error", errors[errors.length - 1]);
1181
+ emitRouter("route:update", currentRoute.value);
1182
+ }
1183
+ __name(reportError, "reportError");
1184
+ function routeTree() {
1185
+ const statuses = /* @__PURE__ */ new Map();
1186
+ for (const matcher of matchers) {
1187
+ for (const record of matcher.chain) {
1188
+ if (record.component && isLazyRouteComponent(record.component)) {
1189
+ const debugId = routeDebugIds.get(record);
1190
+ if (debugId) statuses.set(debugId, lazyStates.get(record)?.status ?? "loading");
1191
+ }
1192
+ }
1193
+ }
1194
+ return buildRouteDebugTree(options.routes, statuses);
1195
+ }
1196
+ __name(routeTree, "routeTree");
1197
+ function handleHistoryNavigation(path, state2) {
1198
+ void navigate(path, false, true, state2).then((result) => {
1199
+ if (destroyed) return;
1200
+ if (result === false) {
1201
+ history.replace(currentRoute.value.fullPath, currentRoute.value.state);
1202
+ } else if (result.fullPath !== normalizeHistoryPath(path)) {
1203
+ history.replace(result.fullPath, result.state);
1204
+ }
1205
+ }).catch((error) => {
1206
+ if (!(error instanceof NavigationCancelledError) && !destroyed) {
1207
+ const current = currentRoute.value.fullPath;
1208
+ const failed = toError(error);
1209
+ reportError("navigation", failed, normalizeHistoryPath(path));
1210
+ navigationState = { status: "error", from: current, to: normalizeHistoryPath(path), error: failed.message };
1211
+ emitRouter("navigation:end", { status: "error", from: current, to: normalizeHistoryPath(path), error: failed.message });
1212
+ history.replace(currentRoute.value.fullPath, currentRoute.value.state);
1213
+ }
1214
+ });
1215
+ }
1216
+ __name(handleHistoryNavigation, "handleHistoryNavigation");
1217
+ const stopHistory = history.listen(handleHistoryNavigation);
1218
+ const router = {
1219
+ currentRoute,
1220
+ history,
1221
+ resolve,
1222
+ push(to) {
1223
+ return navigate(to, false, false);
1224
+ },
1225
+ replace(to) {
1226
+ return navigate(to, true, false);
1227
+ },
1228
+ back() {
1229
+ ensureActive();
1230
+ history.back();
1231
+ },
1232
+ beforeEach(guard) {
1233
+ ensureActive();
1234
+ guards.push(guard);
1235
+ return () => {
1236
+ const index = guards.indexOf(guard);
1237
+ if (index >= 0) guards.splice(index, 1);
1238
+ };
1239
+ },
1240
+ getViewState(route) {
1241
+ viewRevision.value;
1242
+ const records = route.matched.length > 0 ? route.matched : route.record ? [route.record] : [];
1243
+ const entries = records.map((record) => ({ record, definition: record.component })).filter((entry) => isRouteComponentDefinition(entry.definition));
1244
+ if (!route.record || entries.length === 0) return { status: "not-found", retry: /* @__PURE__ */ __name(() => void 0, "retry") };
1245
+ const loaded = [];
1246
+ const lazyRecords = [];
1247
+ for (const entry of entries) {
1248
+ const { record, definition } = entry;
1249
+ if (!isLazyRouteComponent(definition)) {
1250
+ loaded.push(definition);
1251
+ continue;
1252
+ }
1253
+ lazyRecords.push(record);
1254
+ const lazyState = ensureLazyState(record, definition);
1255
+ if (lazyState.status === "loading") return { status: "loading", retry: /* @__PURE__ */ __name(() => retryLazyRoutes(lazyRecords), "retry") };
1256
+ if (lazyState.status === "error") {
1257
+ return { status: "error", error: lazyState.error, retry: /* @__PURE__ */ __name(() => retryLazyRoutes(lazyRecords), "retry") };
1258
+ }
1259
+ if (lazyState.component) loaded.push(lazyState.component);
1260
+ }
1261
+ const component = loaded[loaded.length - 1];
1262
+ if (!component) return { status: "not-found", retry: /* @__PURE__ */ __name(() => void 0, "retry") };
1263
+ return {
1264
+ status: "ready",
1265
+ component,
1266
+ layouts: loaded.slice(0, -1),
1267
+ retry: /* @__PURE__ */ __name(() => retryLazyRoutes(lazyRecords), "retry")
1268
+ };
1269
+ },
1270
+ devtools: {
1271
+ getRouteTree: routeTree,
1272
+ getCurrentRoute: /* @__PURE__ */ __name(() => currentRoute.value, "getCurrentRoute"),
1273
+ getNavigationState: /* @__PURE__ */ __name(() => navigationState, "getNavigationState"),
1274
+ getNavigationHistory: /* @__PURE__ */ __name(() => [...navigationHistory], "getNavigationHistory"),
1275
+ getPerformanceMetrics: /* @__PURE__ */ __name(() => ({
1276
+ navigationCount,
1277
+ averageNavigationDuration: navigationCount === 0 ? 0 : totalNavigationDuration / navigationCount,
1278
+ slowNavigationCount
1279
+ }), "getPerformanceMetrics"),
1280
+ getDataRequests: /* @__PURE__ */ __name(() => [...dataRequests], "getDataRequests"),
1281
+ getErrors: /* @__PURE__ */ __name(() => [...errors], "getErrors"),
1282
+ trackDataRequest,
1283
+ runAction: /* @__PURE__ */ __name((key, task) => trackDataRequest("action", key, task, { trigger: "manual" }), "runAction"),
1284
+ runFetcher: /* @__PURE__ */ __name((key, task) => trackDataRequest("fetcher", key, task, { trigger: "manual" }), "runFetcher"),
1285
+ reportError,
1286
+ revalidate: /* @__PURE__ */ __name(async (route) => {
1287
+ await Promise.all([...dataLoaders.entries()].filter(([, loader]) => loader.kind === "loader" && (route === void 0 || loader.route === route)).map(([key, loader]) => trackDataRequest(loader.kind, key, loader.task, { route: loader.route, trigger: "revalidate" })));
1288
+ }, "revalidate"),
1289
+ subscribe(event, callback) {
1290
+ let listeners2 = routerListeners.get(event);
1291
+ if (!listeners2) {
1292
+ listeners2 = /* @__PURE__ */ new Set();
1293
+ routerListeners.set(event, listeners2);
1294
+ }
1295
+ listeners2.add(callback);
1296
+ return () => listeners2?.delete(callback);
1297
+ }
1298
+ },
1299
+ destroy() {
1300
+ if (destroyed) return;
1301
+ destroyed = true;
1302
+ navigationId++;
1303
+ stopHistory();
1304
+ guards.length = 0;
1305
+ routerListeners.clear();
1306
+ lazyStates.clear();
1307
+ errors.length = 0;
1308
+ dataRequestContexts.clear();
1309
+ currentRoute.dispose();
1310
+ viewRevision.dispose();
1311
+ }
1312
+ };
1313
+ function ensureLazyState(record, definition) {
1314
+ let lazyState = lazyStates.get(record);
1315
+ if (!lazyState) {
1316
+ lazyState = { status: "loading" };
1317
+ lazyStates.set(record, lazyState);
1318
+ void loadRouteComponent(definition).then((component) => {
1319
+ if (destroyed) return;
1320
+ lazyState.status = "ready";
1321
+ lazyState.component = component;
1322
+ viewRevision.value++;
1323
+ emitRouter("route:update", currentRoute.value);
1324
+ }).catch((reason) => {
1325
+ if (destroyed) return;
1326
+ lazyState.status = "error";
1327
+ lazyState.error = toError(reason);
1328
+ reportError("lazy", reason, currentRoute.value.fullPath);
1329
+ viewRevision.value++;
1330
+ emitRouter("route:update", currentRoute.value);
1331
+ });
1332
+ }
1333
+ return lazyState;
1334
+ }
1335
+ __name(ensureLazyState, "ensureLazyState");
1336
+ function retryLazyRoutes(records) {
1337
+ for (const record of records) lazyStates.delete(record);
1338
+ viewRevision.value++;
1339
+ }
1340
+ __name(retryLazyRoutes, "retryLazyRoutes");
1341
+ function ensureActive() {
1342
+ if (destroyed) throw new Error("Vobs Router: \u5DF2\u9500\u6BC1\u7684 Router \u4E0D\u80FD\u7EE7\u7EED\u4F7F\u7528");
1343
+ }
1344
+ __name(ensureActive, "ensureActive");
1345
+ function ensureNavigationIsCurrent(id) {
1346
+ if (id !== navigationId) throw new NavigationCancelledError();
1347
+ }
1348
+ __name(ensureNavigationIsCurrent, "ensureNavigationIsCurrent");
1349
+ return router;
1350
+ }
1351
+ __name(createRouter, "createRouter");
1352
+ function RouterView(props = {}) {
1353
+ const router = props.router ?? inject(ROUTER_KEY);
1354
+ if (!router) throw new Error("Vobs Router: RouterView \u627E\u4E0D\u5230 Router\uFF0C\u8BF7\u5B89\u88C5 routerPlugin");
1355
+ return createFragment((parent, anchor) => {
1356
+ let routeRetry = /* @__PURE__ */ __name(() => void 0, "routeRetry");
1357
+ insertBoundary(parent, anchor, {
1358
+ resetKey: /* @__PURE__ */ __name(() => router.currentRoute.value.fullPath, "resetKey"),
1359
+ onRetry: /* @__PURE__ */ __name(() => routeRetry(), "onRetry"),
1360
+ fallback: /* @__PURE__ */ __name((error, retry) => {
1361
+ router.devtools.reportError("render", error, router.currentRoute.value.fullPath);
1362
+ return props.error?.(error, () => {
1363
+ void retry();
1364
+ }) ?? null;
1365
+ }, "fallback"),
1366
+ children: /* @__PURE__ */ __name(() => {
1367
+ const route = router.currentRoute.value;
1368
+ const view = router.getViewState(route);
1369
+ routeRetry = view.retry;
1370
+ if (view.status === "loading") return props.loading?.() ?? null;
1371
+ if (view.status === "not-found") return props.notFound?.(route) ?? null;
1372
+ if (view.status === "error") {
1373
+ throw view.error ?? new Error("\u8DEF\u7531\u7EC4\u4EF6\u52A0\u8F7D\u5931\u8D25");
1374
+ }
1375
+ if (!view.component) return null;
1376
+ let node = createComponent(view.component, {
1377
+ route,
1378
+ params: route.params,
1379
+ query: route.query
1380
+ });
1381
+ for (let index = (view.layouts?.length ?? 0) - 1; index >= 0; index--) {
1382
+ node = createComponent(view.layouts[index], {
1383
+ route,
1384
+ params: route.params,
1385
+ query: route.query,
1386
+ children: node
1387
+ });
1388
+ }
1389
+ return node;
1390
+ }, "children")
1391
+ });
1392
+ });
1393
+ }
1394
+ __name(RouterView, "RouterView");
1395
+ function useRouter() {
1396
+ const router = inject(ROUTER_KEY);
1397
+ if (!router) throw new Error("Vobs Router: useRouter \u627E\u4E0D\u5230 Router\uFF0C\u8BF7\u5B89\u88C5 routerPlugin");
1398
+ return router;
1399
+ }
1400
+ __name(useRouter, "useRouter");
1401
+ function useRoute() {
1402
+ return useRouter().currentRoute;
1403
+ }
1404
+ __name(useRoute, "useRoute");
1405
+ function routerPlugin(options = {}) {
1406
+ return {
1407
+ name: "@vobs/router",
1408
+ version: "0.1.0",
1409
+ install(context) {
1410
+ const ownedRouter = options.router ? void 0 : createRouter({
1411
+ routes: options.routes ?? [],
1412
+ history: options.history
1413
+ });
1414
+ const router = options.router ?? ownedRouter;
1415
+ context.provide(ROUTER_KEY, router);
1416
+ return () => ownedRouter?.destroy();
1417
+ }
1418
+ };
1419
+ }
1420
+ __name(routerPlugin, "routerPlugin");
1421
+ function defaultHistory() {
1422
+ return typeof window === "undefined" ? createMemoryHistory("/") : createBrowserHistory();
1423
+ }
1424
+ __name(defaultHistory, "defaultHistory");
1425
+ var EMPTY_MATCHED = Object.freeze([]);
1426
+ var routeDebugIds = /* @__PURE__ */ new WeakMap();
1427
+ function buildRouteDebugTree(routes, lazyStatuses = /* @__PURE__ */ new Map()) {
1428
+ const visit = /* @__PURE__ */ __name((records, parentPath, parentId) => records.map((record, index) => {
1429
+ const path = record.path === void 0 ? parentPath || "/" : resolveChildPath(parentPath, record.path);
1430
+ const id = `${parentId}.${index}`;
1431
+ const definition = record.component;
1432
+ const lazyDefinition = definition !== void 0 && isLazyRouteComponent(definition);
1433
+ const componentName = definition === void 0 ? "Route" : lazyDefinition ? "lazy(...)" : typeof definition === "function" ? definition.name || "Anonymous" : "Route";
1434
+ return {
1435
+ id,
1436
+ path,
1437
+ name: record.name,
1438
+ component: componentName,
1439
+ source: record.source,
1440
+ lazy: lazyDefinition,
1441
+ loader: record.loader !== void 0,
1442
+ action: record.action !== void 0,
1443
+ status: lazyDefinition ? lazyStatuses.get(id) ?? "loading" : "ready",
1444
+ meta: Object.freeze({ ...record.meta ?? {} }),
1445
+ children: visit(record.children ?? [], path, id)
1446
+ };
1447
+ }), "visit");
1448
+ return Object.freeze(visit(routes, "", "route"));
1449
+ }
1450
+ __name(buildRouteDebugTree, "buildRouteDebugTree");
1451
+ function normalizeRoutes(routes) {
1452
+ const matchers = [];
1453
+ let order = 0;
1454
+ function visit(records, parentPath, parentChain, parentMeta, parentId = "route") {
1455
+ records.forEach((record, index) => {
1456
+ const debugId = `${parentId}.${index}`;
1457
+ const children = record.children ?? [];
1458
+ const path = record.path === void 0 ? parentPath : resolveChildPath(parentPath, record.path);
1459
+ const normalized = {
1460
+ ...record,
1461
+ path: record.path === void 0 ? children.length > 0 ? void 0 : path || "/" : path,
1462
+ meta: record.meta ? { ...record.meta } : {}
1463
+ };
1464
+ routeDebugIds.set(normalized, debugId);
1465
+ const chain = [...parentChain, normalized];
1466
+ const meta = Object.freeze({ ...parentMeta, ...normalized.meta ?? {} });
1467
+ if (children.length > 0) {
1468
+ visit(children, path, chain, meta, debugId);
1469
+ } else if (normalized.component) {
1470
+ matchers.push(createMatcher(normalized, chain, meta, order++, debugId));
1471
+ } else if (normalized.path === void 0) {
1472
+ throw new Error(`Vobs Router: \u7B2C ${index + 1} \u4E2A\u8DEF\u7531\u7F3A\u5C11 path \u6216 children`);
1473
+ }
1474
+ });
1475
+ }
1476
+ __name(visit, "visit");
1477
+ visit(routes, "", [], {});
1478
+ return matchers;
1479
+ }
1480
+ __name(normalizeRoutes, "normalizeRoutes");
1481
+ function resolveChildPath(parentPath, childPath) {
1482
+ const normalizedChild = normalizePath(childPath);
1483
+ if (!parentPath || normalizedChild === "/") return normalizedChild === "/" ? parentPath || "/" : normalizedChild;
1484
+ if (childPath.startsWith("/")) return normalizedChild;
1485
+ return normalizePath(`${parentPath}/${childPath}`);
1486
+ }
1487
+ __name(resolveChildPath, "resolveChildPath");
1488
+ function createMatcher(record, chain, meta, order, debugId) {
1489
+ const path = record.path ?? "/";
1490
+ const segments = path === "/" ? [] : path.slice(1).split("/");
1491
+ const keys = [];
1492
+ let score = 0;
1493
+ const pattern = segments.map((segment) => {
1494
+ if (segment === "*") {
1495
+ keys.push("pathMatch");
1496
+ return "(.*)";
1497
+ }
1498
+ if (segment.startsWith(":")) {
1499
+ const key = segment.slice(1);
1500
+ if (!key) throw new Error(`Vobs Router: \u8DEF\u7531 ${path} \u7684\u53C2\u6570\u540D\u4E0D\u80FD\u4E3A\u7A7A`);
1501
+ if (keys.includes(key)) throw new Error(`Vobs Router: \u8DEF\u7531 ${path} \u5B58\u5728\u91CD\u590D\u53C2\u6570 ${key}`);
1502
+ keys.push(key);
1503
+ score += 1;
1504
+ return "([^/]+)";
1505
+ }
1506
+ score += 3;
1507
+ return escapeRegExp(segment);
1508
+ }).join("/");
1509
+ return {
1510
+ record,
1511
+ debugId,
1512
+ chain: Object.freeze([...chain]),
1513
+ meta,
1514
+ regex: new RegExp(segments.length === 0 ? "^/?$" : `^/${pattern}/?$`),
1515
+ keys,
1516
+ score,
1517
+ order
1518
+ };
1519
+ }
1520
+ __name(createMatcher, "createMatcher");
1521
+ function compareMatchers(left, right) {
1522
+ return right.score - left.score || left.order - right.order;
1523
+ }
1524
+ __name(compareMatchers, "compareMatchers");
1525
+ function extractParams(matcher, path) {
1526
+ const match = matcher.regex.exec(path);
1527
+ if (!match) return {};
1528
+ const params = {};
1529
+ matcher.keys.forEach((key, index) => {
1530
+ params[key] = decodeRoutePart(match[index + 1] ?? "");
1531
+ });
1532
+ return Object.freeze(params);
1533
+ }
1534
+ __name(extractParams, "extractParams");
1535
+ function parseTargetString(raw) {
1536
+ const hashIndex = raw.indexOf("#");
1537
+ const hash = hashIndex >= 0 ? normalizeHash(raw.slice(hashIndex + 1)) : "";
1538
+ const withoutHash = hashIndex >= 0 ? raw.slice(0, hashIndex) : raw;
1539
+ const queryIndex = withoutHash.indexOf("?");
1540
+ const path = normalizePath(queryIndex >= 0 ? withoutHash.slice(0, queryIndex) : withoutHash);
1541
+ const query = queryIndex >= 0 ? parseQuery(withoutHash.slice(queryIndex + 1)) : {};
1542
+ return { path, query, hash };
1543
+ }
1544
+ __name(parseTargetString, "parseTargetString");
1545
+ function normalizeTarget(target, matchers) {
1546
+ let path = target.path;
1547
+ if (!path && target.name) {
1548
+ const matcher = matchers.find((candidate) => candidate.record.name === target.name);
1549
+ if (!matcher) throw new Error(`Vobs Router: \u627E\u4E0D\u5230\u540D\u4E3A ${target.name} \u7684\u8DEF\u7531`);
1550
+ path = fillRouteParams(matcher.record.path ?? "/", target.params ?? {});
1551
+ }
1552
+ if (!path) throw new Error("Vobs Router: \u5BFC\u822A\u76EE\u6807\u5FC5\u987B\u63D0\u4F9B path \u6216 name");
1553
+ const parsed = parseTargetString(path);
1554
+ const filledPath = fillRouteParams(parsed.path, target.params ?? {});
1555
+ const query = target.query === void 0 ? parsed.query : normalizeQuery(target.query);
1556
+ const hash = target.hash === void 0 ? parsed.hash : normalizeHash(target.hash);
1557
+ return { path: filledPath, query, hash, state: target.state };
1558
+ }
1559
+ __name(normalizeTarget, "normalizeTarget");
1560
+ function fillRouteParams(path, params) {
1561
+ return path.replace(/:([A-Za-z0-9_]+)|\*/g, (token, key) => {
1562
+ const value = key ? params[key] : params.pathMatch;
1563
+ if (value === void 0 || value === null) return token;
1564
+ return encodeURIComponent(String(value));
1565
+ });
1566
+ }
1567
+ __name(fillRouteParams, "fillRouteParams");
1568
+ function buildTargetPath(path, query, hash) {
1569
+ const params = new URLSearchParams();
1570
+ for (const key of Object.keys(query).sort()) {
1571
+ const value = query[key];
1572
+ if (typeof value === "string") {
1573
+ params.set(key, value);
1574
+ } else {
1575
+ for (const item of value) params.append(key, item);
1576
+ }
1577
+ }
1578
+ const serialized = params.toString();
1579
+ return `${path}${serialized ? `?${serialized}` : ""}${hash}`;
1580
+ }
1581
+ __name(buildTargetPath, "buildTargetPath");
1582
+ function parseQuery(raw) {
1583
+ const params = new URLSearchParams(raw);
1584
+ const result = {};
1585
+ params.forEach((value, key) => {
1586
+ const previous = result[key];
1587
+ if (previous === void 0) result[key] = value;
1588
+ else if (typeof previous === "string") result[key] = [previous, value];
1589
+ else result[key] = [...previous, value];
1590
+ });
1591
+ for (const key of Object.keys(result)) {
1592
+ if (Array.isArray(result[key])) result[key] = Object.freeze(result[key]);
1593
+ }
1594
+ return Object.freeze(result);
1595
+ }
1596
+ __name(parseQuery, "parseQuery");
1597
+ function normalizeQuery(input) {
1598
+ if (input instanceof URLSearchParams) return parseQuery(input.toString());
1599
+ const result = {};
1600
+ for (const [key, value] of Object.entries(input)) {
1601
+ if (value === void 0 || value === null) continue;
1602
+ if (Array.isArray(value)) result[key] = Object.freeze(value.map((item) => String(item)));
1603
+ else result[key] = String(value);
1604
+ }
1605
+ return Object.freeze(result);
1606
+ }
1607
+ __name(normalizeQuery, "normalizeQuery");
1608
+ function normalizePath(path) {
1609
+ if (!path) return "/";
1610
+ const withoutQuery = path.split(/[?#]/, 1)[0] || "/";
1611
+ const withLeadingSlash = withoutQuery.startsWith("/") ? withoutQuery : `/${withoutQuery}`;
1612
+ if (withLeadingSlash === "/*" || withLeadingSlash === "/") return withLeadingSlash;
1613
+ return withLeadingSlash.replace(/\/+/g, "/").replace(/\/$/, "") || "/";
1614
+ }
1615
+ __name(normalizePath, "normalizePath");
1616
+ function normalizeHistoryPath(path) {
1617
+ const parsed = parseTargetString(path);
1618
+ return buildTargetPath(parsed.path, parsed.query, parsed.hash);
1619
+ }
1620
+ __name(normalizeHistoryPath, "normalizeHistoryPath");
1621
+ function normalizeHash(hash) {
1622
+ if (!hash) return "";
1623
+ return hash.startsWith("#") ? hash : `#${hash}`;
1624
+ }
1625
+ __name(normalizeHash, "normalizeHash");
1626
+ function normalizeBase(base) {
1627
+ if (!base || base === "/") return "";
1628
+ return `/${base.replace(/^\/+|\/+$/g, "")}`;
1629
+ }
1630
+ __name(normalizeBase, "normalizeBase");
1631
+ function readBrowserLocation(base) {
1632
+ const pathname = window.location.pathname;
1633
+ const path = base && (pathname === base || pathname.startsWith(`${base}/`)) ? pathname.slice(base.length) || "/" : pathname;
1634
+ return normalizeHistoryPath(`${path}${window.location.search}${window.location.hash}`);
1635
+ }
1636
+ __name(readBrowserLocation, "readBrowserLocation");
1637
+ function withBase(path, base) {
1638
+ return `${base}${path === "/" ? "/" : path}` || "/";
1639
+ }
1640
+ __name(withBase, "withBase");
1641
+ function notifyListeners(listeners2, path, state2) {
1642
+ for (const listener of [...listeners2]) listener(path, state2);
1643
+ }
1644
+ __name(notifyListeners, "notifyListeners");
1645
+ function escapeRegExp(value) {
1646
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1647
+ }
1648
+ __name(escapeRegExp, "escapeRegExp");
1649
+ function decodeRoutePart(value) {
1650
+ try {
1651
+ return decodeURIComponent(value);
1652
+ } catch {
1653
+ return value;
1654
+ }
1655
+ }
1656
+ __name(decodeRoutePart, "decodeRoutePart");
1657
+ function isLazyRouteComponent(value) {
1658
+ return typeof value === "object" && value !== null && value.kind === "vobs-lazy-route";
1659
+ }
1660
+ __name(isLazyRouteComponent, "isLazyRouteComponent");
1661
+ function isRouteComponentDefinition(value) {
1662
+ return typeof value === "function" || isLazyRouteComponent(value);
1663
+ }
1664
+ __name(isRouteComponentDefinition, "isRouteComponentDefinition");
1665
+ async function loadRouteComponent(loader) {
1666
+ const module = await loader.load();
1667
+ const component = typeof module === "function" ? module : module.default;
1668
+ if (typeof component !== "function") throw new Error("Vobs Router: \u61D2\u52A0\u8F7D\u6A21\u5757\u6CA1\u6709\u9ED8\u8BA4\u7EC4\u4EF6\u5BFC\u51FA");
1669
+ return component;
1670
+ }
1671
+ __name(loadRouteComponent, "loadRouteComponent");
1672
+ function isRouteLocationRaw(value) {
1673
+ return Boolean(value) && typeof value === "object";
1674
+ }
1675
+ __name(isRouteLocationRaw, "isRouteLocationRaw");
1676
+ function toError(reason) {
1677
+ return reason instanceof Error ? reason : new Error(String(reason));
1678
+ }
1679
+ __name(toError, "toError");
1680
+ function isAbortError(reason) {
1681
+ return Boolean(reason) && typeof reason === "object" && (reason.name === "AbortError" || reason.code === "ERR_CANCELED");
1682
+ }
1683
+ __name(isAbortError, "isAbortError");
1684
+
1685
+ exports.NavigationCancelledError = NavigationCancelledError;
1686
+ exports.NavigationRedirectError = NavigationRedirectError;
1687
+ exports.ROUTER_KEY = ROUTER_KEY;
1688
+ exports.RouterView = RouterView;
1689
+ exports.createBrowserHistory = createBrowserHistory;
1690
+ exports.createMemoryHistory = createMemoryHistory;
1691
+ exports.createRouter = createRouter;
1692
+ exports.createRouterDebugId = createRouterDebugId;
1693
+ exports.emitRouterDebug = emitRouterDebug;
1694
+ exports.lazy = lazy;
1695
+ exports.routerPlugin = routerPlugin;
1696
+ exports.subscribeRouterDebug = subscribeRouterDebug;
1697
+ exports.useRoute = useRoute;
1698
+ exports.useRouter = useRouter;
1699
+ //# sourceMappingURL=index.cjs.map
1700
+ //# sourceMappingURL=index.cjs.map