vue-micro-router 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +617 -0
- package/dist/audio.d.ts +104 -0
- package/dist/audio.mjs +100 -0
- package/dist/index.d.ts +887 -0
- package/dist/index.mjs +1230 -0
- package/dist/styles.css +1 -0
- package/dist/styles.d.ts +1 -0
- package/dist/styles.mjs +1 -0
- package/dist/timer-manager.mjs +20 -0
- package/package.json +94 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1230 @@
|
|
|
1
|
+
import { markRaw as Ge, shallowReactive as K, computed as C, defineAsyncComponent as ge, reactive as fe, nextTick as J, ref as de, inject as z, watch as j, onMounted as H, onBeforeUnmount as Ae, provide as N, toRefs as Ie, toRef as Ne, defineComponent as ee, openBlock as I, createBlock as U, resolveDynamicComponent as ve, mergeProps as me, Teleport as Be, createElementVNode as Q, normalizeStyle as Re, normalizeClass as le, withModifiers as Oe, renderSlot as he, createElementBlock as q, Fragment as Z, createVNode as De, TransitionGroup as we, withCtx as ae, renderList as ie, unref as Y } from "vue";
|
|
2
|
+
import { c as pe, d as se } from "./timer-manager.mjs";
|
|
3
|
+
const Ee = Symbol("micro-router");
|
|
4
|
+
function lt() {
|
|
5
|
+
return Symbol("micro-router-nested");
|
|
6
|
+
}
|
|
7
|
+
const ce = Symbol("micro-router-root"), Se = Symbol("micro-route-path"), Le = Symbol("micro-dialog-path"), Me = Symbol("micro-control-name"), te = Symbol("micro-attrs-read"), ne = Symbol("micro-attrs-write"), We = 550;
|
|
8
|
+
function $(e) {
|
|
9
|
+
return e.startsWith("/") ? e : `/${e}`;
|
|
10
|
+
}
|
|
11
|
+
function T(e) {
|
|
12
|
+
return e.split("/").filter(Boolean);
|
|
13
|
+
}
|
|
14
|
+
function W(e) {
|
|
15
|
+
return `/${e.join("/")}`;
|
|
16
|
+
}
|
|
17
|
+
function V(e) {
|
|
18
|
+
return e.split("/").filter(Boolean).at(-1) ?? "";
|
|
19
|
+
}
|
|
20
|
+
function ye(e) {
|
|
21
|
+
try {
|
|
22
|
+
return Ge(e);
|
|
23
|
+
} catch {
|
|
24
|
+
return e;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function Pe(e) {
|
|
28
|
+
return typeof e == "function" && !("__name" in e) && !("setup" in e) && !("render" in e);
|
|
29
|
+
}
|
|
30
|
+
async function k(e) {
|
|
31
|
+
try {
|
|
32
|
+
await e();
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function $e(e, n) {
|
|
37
|
+
const o = e.defaultControlName, a = e.onboardingControlName, t = 300, c = pe();
|
|
38
|
+
let l = !1;
|
|
39
|
+
const r = K(/* @__PURE__ */ new Map()), u = K(
|
|
40
|
+
/* @__PURE__ */ new Map()
|
|
41
|
+
), i = C(() => {
|
|
42
|
+
const s = [];
|
|
43
|
+
for (const f of r.values())
|
|
44
|
+
f.activated && s.push(f);
|
|
45
|
+
return s;
|
|
46
|
+
}), d = i, E = C(
|
|
47
|
+
() => i.value.some((s) => s.name !== o)
|
|
48
|
+
), M = C(() => {
|
|
49
|
+
const s = i.value.find((f) => f.name !== o);
|
|
50
|
+
return (s == null ? void 0 : s.name) ?? o;
|
|
51
|
+
});
|
|
52
|
+
function A(s, f, y) {
|
|
53
|
+
var D, b, p;
|
|
54
|
+
if (!(f && l)) {
|
|
55
|
+
f && (l = !0);
|
|
56
|
+
try {
|
|
57
|
+
const h = r.get(s);
|
|
58
|
+
if (!h) return;
|
|
59
|
+
const v = r.get(o), w = s === o || s === a;
|
|
60
|
+
if (f)
|
|
61
|
+
(D = n == null ? void 0 : n.trackGuiEnter) == null || D.call(n, s), w ? r.forEach((P) => {
|
|
62
|
+
var L;
|
|
63
|
+
P.name !== o && P.activated && ((L = n == null ? void 0 : n.trackGuiLeave) == null || L.call(n, P.name), r.set(P.name, {
|
|
64
|
+
...P,
|
|
65
|
+
activated: !1,
|
|
66
|
+
attrs: void 0
|
|
67
|
+
}));
|
|
68
|
+
}) : v != null && v.activated && ((b = n == null ? void 0 : n.trackGuiLeave) == null || b.call(n, o), r.set(o, { ...v, activated: !1 })), y && u.set(s, { ...y }), r.set(s, {
|
|
69
|
+
...h,
|
|
70
|
+
activated: !0,
|
|
71
|
+
componentKey: (h.componentKey || 0) + 1,
|
|
72
|
+
attrs: y ? { ...y } : void 0
|
|
73
|
+
});
|
|
74
|
+
else {
|
|
75
|
+
(p = n == null ? void 0 : n.trackGuiLeave) == null || p.call(n, s), u.delete(s), r.set(s, { ...h, activated: !1, attrs: void 0 });
|
|
76
|
+
const P = r.get(o);
|
|
77
|
+
if (!w && P && !P.activated) {
|
|
78
|
+
if (P.name === a) return;
|
|
79
|
+
r.set(o, { ...P, activated: !0 });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} finally {
|
|
83
|
+
f && c.schedule(() => {
|
|
84
|
+
l = !1;
|
|
85
|
+
}, t);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function _(s) {
|
|
90
|
+
r.has(s.name) && console.warn(`[vue-micro-router] Control "${s.name}" already registered. Overwriting.`);
|
|
91
|
+
let { component: f } = s;
|
|
92
|
+
Pe(f) && (f = ge(f)), r.set(s.name, {
|
|
93
|
+
...s,
|
|
94
|
+
component: ye(f)
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function G(s) {
|
|
98
|
+
s.forEach(_);
|
|
99
|
+
}
|
|
100
|
+
function g(s) {
|
|
101
|
+
return u.get(s);
|
|
102
|
+
}
|
|
103
|
+
function m(s, f) {
|
|
104
|
+
const y = u.get(s);
|
|
105
|
+
u.set(s, { ...y, ...f });
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
resolveControls: d,
|
|
109
|
+
activeControl: E,
|
|
110
|
+
currentControl: M,
|
|
111
|
+
toggleControl: A,
|
|
112
|
+
registerControl: _,
|
|
113
|
+
registerControls: G,
|
|
114
|
+
getControlAttrs: g,
|
|
115
|
+
updateControlAttrs: m,
|
|
116
|
+
cleanup: c.cleanup
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const re = "micro-router-inspector", Ke = "micro-router-events";
|
|
120
|
+
async function Ye(e) {
|
|
121
|
+
if (typeof import.meta < "u") return;
|
|
122
|
+
let n;
|
|
123
|
+
try {
|
|
124
|
+
n = (await import(
|
|
125
|
+
/* @vite-ignore */
|
|
126
|
+
"@vue/devtools-api"
|
|
127
|
+
)).setupDevtoolsPlugin;
|
|
128
|
+
} catch {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
n && n(
|
|
132
|
+
{
|
|
133
|
+
id: "vue-micro-router",
|
|
134
|
+
label: "Micro Router",
|
|
135
|
+
packageName: "vue-micro-router",
|
|
136
|
+
homepage: "https://github.com/danh121097/vue-micro-router"
|
|
137
|
+
},
|
|
138
|
+
(o) => {
|
|
139
|
+
o.addInspector({
|
|
140
|
+
id: re,
|
|
141
|
+
label: "Micro Router",
|
|
142
|
+
icon: "route"
|
|
143
|
+
}), o.addTimelineLayer({
|
|
144
|
+
id: Ke,
|
|
145
|
+
label: "Micro Router",
|
|
146
|
+
color: 4372611
|
|
147
|
+
}), o.on.getInspectorTree((a) => {
|
|
148
|
+
a.inspectorId === re && (a.rootNodes = [
|
|
149
|
+
{
|
|
150
|
+
id: "routes",
|
|
151
|
+
label: `Routes (${e.resolveRoutes.value.length} active)`,
|
|
152
|
+
children: e.resolveRoutes.value.map((t) => ({
|
|
153
|
+
id: `route-${t.path}`,
|
|
154
|
+
label: t.path
|
|
155
|
+
}))
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: "dialogs",
|
|
159
|
+
label: `Dialogs (${e.resolveDialogs.value.length} open)`,
|
|
160
|
+
children: e.resolveDialogs.value.map((t) => ({
|
|
161
|
+
id: `dialog-${t.path}`,
|
|
162
|
+
label: t.path
|
|
163
|
+
}))
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
id: "controls",
|
|
167
|
+
label: `Controls (${e.resolveControls.value.length} active)`,
|
|
168
|
+
children: e.resolveControls.value.map((t) => ({
|
|
169
|
+
id: `control-${t.name}`,
|
|
170
|
+
label: t.name
|
|
171
|
+
}))
|
|
172
|
+
}
|
|
173
|
+
]);
|
|
174
|
+
}), o.on.getInspectorState((a) => {
|
|
175
|
+
if (a.inspectorId === re) {
|
|
176
|
+
if (a.nodeId === "routes")
|
|
177
|
+
a.state = {
|
|
178
|
+
Navigation: [
|
|
179
|
+
{ key: "activePath", value: e.activePath.value },
|
|
180
|
+
{ key: "fromPath", value: e.fromPath.value },
|
|
181
|
+
{ key: "toPath", value: e.toPath.value },
|
|
182
|
+
{ key: "activePage", value: e.activePage.value }
|
|
183
|
+
]
|
|
184
|
+
};
|
|
185
|
+
else if (a.nodeId.startsWith("route-")) {
|
|
186
|
+
const t = a.nodeId.replace("route-", "");
|
|
187
|
+
a.state = {
|
|
188
|
+
Route: [
|
|
189
|
+
{ key: "path", value: t },
|
|
190
|
+
{ key: "attrs", value: e.getRouteAttrs(t) ?? {} }
|
|
191
|
+
]
|
|
192
|
+
};
|
|
193
|
+
} else if (a.nodeId.startsWith("dialog-")) {
|
|
194
|
+
const t = a.nodeId.replace("dialog-", "");
|
|
195
|
+
a.state = {
|
|
196
|
+
Dialog: [
|
|
197
|
+
{ key: "path", value: t },
|
|
198
|
+
{ key: "attrs", value: e.getDialogAttrs(t) ?? {} }
|
|
199
|
+
]
|
|
200
|
+
};
|
|
201
|
+
} else if (a.nodeId.startsWith("control-")) {
|
|
202
|
+
const t = a.nodeId.replace("control-", "");
|
|
203
|
+
a.state = {
|
|
204
|
+
Control: [
|
|
205
|
+
{ key: "name", value: t },
|
|
206
|
+
{ key: "attrs", value: e.getControlAttrs(t) ?? {} }
|
|
207
|
+
]
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
function Xe(e) {
|
|
216
|
+
const n = e.activePath.value.split("/").filter(Boolean), o = {};
|
|
217
|
+
for (const r of n) {
|
|
218
|
+
const u = e.getRouteAttrs(r);
|
|
219
|
+
u && (o[r] = { ...u });
|
|
220
|
+
}
|
|
221
|
+
const a = [], t = {};
|
|
222
|
+
for (const r of e.resolveDialogs.value) {
|
|
223
|
+
if (r.closing) continue;
|
|
224
|
+
a.push(r.path);
|
|
225
|
+
const u = e.getDialogAttrs(r.path);
|
|
226
|
+
u && (t[r.path] = { ...u });
|
|
227
|
+
}
|
|
228
|
+
const c = [], l = {};
|
|
229
|
+
for (const r of e.resolveControls.value) {
|
|
230
|
+
c.push(r.name);
|
|
231
|
+
const u = e.getControlAttrs(r.name);
|
|
232
|
+
u && (l[r.name] = { ...u });
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
version: 1,
|
|
236
|
+
navigation: { activePath: e.activePath.value, routeAttrs: o },
|
|
237
|
+
dialogs: { stack: a, attrs: t },
|
|
238
|
+
controls: { active: c, attrs: l }
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
async function Ue(e, n) {
|
|
242
|
+
if (n.version !== 1) {
|
|
243
|
+
console.warn("[vue-micro-router] Unknown serialized state version:", n.version);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const { activePath: o, routeAttrs: a } = n.navigation;
|
|
247
|
+
await e.push(o);
|
|
248
|
+
for (const [t, c] of Object.entries(a))
|
|
249
|
+
e.updateRouteAttrs(t, c);
|
|
250
|
+
for (const t of n.dialogs.stack) {
|
|
251
|
+
const c = n.dialogs.attrs[t];
|
|
252
|
+
e.openDialog(t, c);
|
|
253
|
+
}
|
|
254
|
+
for (const t of n.controls.active) {
|
|
255
|
+
const c = n.controls.attrs[t];
|
|
256
|
+
e.toggleControl(t, !0, c);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function ze(e) {
|
|
260
|
+
const o = pe();
|
|
261
|
+
let a = !1;
|
|
262
|
+
const t = fe({
|
|
263
|
+
activeDialog: "",
|
|
264
|
+
fromDialog: "",
|
|
265
|
+
toDialog: "",
|
|
266
|
+
/** Open order stack — last entry = topmost dialog. Used for z-index and focus management. */
|
|
267
|
+
dialogStack: [],
|
|
268
|
+
/** Dialog definitions. Re-set on open/close to trigger shallowReactive reactivity. */
|
|
269
|
+
dialogs: K(/* @__PURE__ */ new Map()),
|
|
270
|
+
/** Attrs stored separately for useMicroState access inside dialog components */
|
|
271
|
+
dialogAttrs: K(/* @__PURE__ */ new Map())
|
|
272
|
+
}), c = C(() => {
|
|
273
|
+
const g = [];
|
|
274
|
+
for (const m of t.dialogs.values())
|
|
275
|
+
(m.activated || m.closing) && g.push(m);
|
|
276
|
+
return g;
|
|
277
|
+
}), l = o.schedule;
|
|
278
|
+
function r(g, m) {
|
|
279
|
+
return { path: g, attrs: m };
|
|
280
|
+
}
|
|
281
|
+
function u({ path: g, open: m, attrs: s }) {
|
|
282
|
+
const f = t.dialogs.get(g);
|
|
283
|
+
return f && J(() => {
|
|
284
|
+
if (m)
|
|
285
|
+
t.fromDialog = t.activeDialog, t.toDialog = g, t.dialogStack.includes(g) || t.dialogStack.push(g), t.activeDialog = g, s && t.dialogAttrs.set(g, { ...s }), t.dialogs.set(g, {
|
|
286
|
+
...f,
|
|
287
|
+
activated: !0,
|
|
288
|
+
componentKey: (f.componentKey || 0) + 1,
|
|
289
|
+
attrs: {
|
|
290
|
+
path: g,
|
|
291
|
+
...s,
|
|
292
|
+
onClose: () => {
|
|
293
|
+
d(g), s != null && s.onClose && typeof s.onClose == "function" && s.onClose();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
else {
|
|
298
|
+
t.fromDialog = t.activeDialog;
|
|
299
|
+
const y = t.dialogStack.indexOf(g);
|
|
300
|
+
y > -1 && t.dialogStack.splice(y, 1), t.activeDialog = t.dialogStack.at(-1) ?? "", t.toDialog = t.activeDialog;
|
|
301
|
+
const D = f.transitionDuration ?? (f.transition === "slide" ? 500 : 300);
|
|
302
|
+
t.dialogs.set(g, {
|
|
303
|
+
...f,
|
|
304
|
+
activated: !1,
|
|
305
|
+
closing: !0,
|
|
306
|
+
attrs: void 0
|
|
307
|
+
}), l(() => {
|
|
308
|
+
const b = t.dialogs.get(g);
|
|
309
|
+
b && !b.activated && t.dialogs.set(g, { ...b, closing: !1 });
|
|
310
|
+
}, D + 200);
|
|
311
|
+
}
|
|
312
|
+
}), r(g, s);
|
|
313
|
+
}
|
|
314
|
+
function i(g, m) {
|
|
315
|
+
var s;
|
|
316
|
+
if (a) return r(g, m);
|
|
317
|
+
a = !0;
|
|
318
|
+
try {
|
|
319
|
+
const f = t.activeDialog || "";
|
|
320
|
+
(s = e == null ? void 0 : e.trackDialogEnter) == null || s.call(e, g, f, g);
|
|
321
|
+
const y = u({ path: g, open: !0, attrs: m });
|
|
322
|
+
return l(() => {
|
|
323
|
+
a = !1;
|
|
324
|
+
}, 300), y;
|
|
325
|
+
} catch (f) {
|
|
326
|
+
throw a = !1, f;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function d(g) {
|
|
330
|
+
var m;
|
|
331
|
+
(m = e == null ? void 0 : e.trackDialogLeave) == null || m.call(e, g, g, ""), t.dialogAttrs.delete(g), u({ path: g, open: !1 });
|
|
332
|
+
}
|
|
333
|
+
function E() {
|
|
334
|
+
const g = [], m = [];
|
|
335
|
+
t.dialogs.forEach((s, f) => {
|
|
336
|
+
var y, D;
|
|
337
|
+
if (s.activated) {
|
|
338
|
+
(y = e == null ? void 0 : e.trackDialogLeave) == null || y.call(e, f, f, "");
|
|
339
|
+
const b = (D = s.attrs) == null ? void 0 : D.onClose;
|
|
340
|
+
typeof b == "function" && m.push(b), t.dialogs.set(f, {
|
|
341
|
+
...s,
|
|
342
|
+
activated: !1,
|
|
343
|
+
closing: !0,
|
|
344
|
+
attrs: void 0
|
|
345
|
+
}), g.push(f);
|
|
346
|
+
}
|
|
347
|
+
}), m.forEach((s) => s()), t.dialogAttrs.clear(), t.fromDialog = t.activeDialog, t.toDialog = "", t.activeDialog = "", t.dialogStack = [], l(() => {
|
|
348
|
+
g.forEach((s) => {
|
|
349
|
+
const f = t.dialogs.get(s);
|
|
350
|
+
f && !f.activated && t.dialogs.set(s, { ...f, closing: !1 });
|
|
351
|
+
});
|
|
352
|
+
}, 500);
|
|
353
|
+
}
|
|
354
|
+
function M(g) {
|
|
355
|
+
t.dialogs.has(g.path) && console.warn(`[vue-micro-router] Dialog "${g.path}" already registered. Overwriting.`);
|
|
356
|
+
let { component: m } = g;
|
|
357
|
+
Pe(m) && (m = ge(m)), t.dialogs.set(g.path, {
|
|
358
|
+
persistent: !0,
|
|
359
|
+
...g,
|
|
360
|
+
component: ye(m)
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
function A(g) {
|
|
364
|
+
g.forEach(M);
|
|
365
|
+
}
|
|
366
|
+
function _(g) {
|
|
367
|
+
return t.dialogAttrs.get(g);
|
|
368
|
+
}
|
|
369
|
+
function G(g, m) {
|
|
370
|
+
const s = t.dialogAttrs.get(g);
|
|
371
|
+
t.dialogAttrs.set(g, { ...s, ...m });
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
activeDialog: C(() => t.activeDialog),
|
|
375
|
+
fromDialog: C(() => t.fromDialog),
|
|
376
|
+
toDialog: C(() => t.toDialog),
|
|
377
|
+
resolveDialogs: c,
|
|
378
|
+
openDialog: i,
|
|
379
|
+
closeDialog: d,
|
|
380
|
+
closeAllDialogs: E,
|
|
381
|
+
registerDialog: M,
|
|
382
|
+
registerDialogs: A,
|
|
383
|
+
getDialogAttrs: _,
|
|
384
|
+
updateDialogAttrs: G,
|
|
385
|
+
cleanup: o.cleanup
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
const be = 5e3;
|
|
389
|
+
async function ue(e, n, o, a) {
|
|
390
|
+
let t;
|
|
391
|
+
try {
|
|
392
|
+
const c = await Promise.race([
|
|
393
|
+
Promise.resolve(e(n, o)),
|
|
394
|
+
new Promise((l, r) => {
|
|
395
|
+
t = setTimeout(() => r(new Error("Navigation guard timed out")), a);
|
|
396
|
+
})
|
|
397
|
+
]);
|
|
398
|
+
return clearTimeout(t), c !== !1;
|
|
399
|
+
} catch {
|
|
400
|
+
return clearTimeout(t), !1;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
async function Fe(e, n, o, a = be) {
|
|
404
|
+
for (const t of e)
|
|
405
|
+
if (!await ue(t, n, o, a)) return !1;
|
|
406
|
+
return !0;
|
|
407
|
+
}
|
|
408
|
+
async function Ce(e, n, o, a) {
|
|
409
|
+
var r;
|
|
410
|
+
const t = o.guardTimeout ?? be;
|
|
411
|
+
if ((r = o.beforeEach) != null && r.length && !await Fe(o.beforeEach, e, n, t))
|
|
412
|
+
return !1;
|
|
413
|
+
const c = V(e);
|
|
414
|
+
if (c) {
|
|
415
|
+
const u = a.getRoute(c);
|
|
416
|
+
if (u != null && u.beforeEnter && !await ue(u.beforeEnter, e, n, t))
|
|
417
|
+
return !1;
|
|
418
|
+
}
|
|
419
|
+
const l = V(n);
|
|
420
|
+
if (l) {
|
|
421
|
+
const u = a.getRoute(l);
|
|
422
|
+
if (u != null && u.beforeLeave && !await ue(u.beforeLeave, e, n, t))
|
|
423
|
+
return !1;
|
|
424
|
+
}
|
|
425
|
+
return !0;
|
|
426
|
+
}
|
|
427
|
+
function Ve(e, n, o) {
|
|
428
|
+
if (o != null && o.length)
|
|
429
|
+
for (const a of o)
|
|
430
|
+
try {
|
|
431
|
+
a(e, n);
|
|
432
|
+
} catch {
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
function je(e, n) {
|
|
436
|
+
const o = e.maxEntries ?? 50, a = [];
|
|
437
|
+
let t = -1, c = !1;
|
|
438
|
+
const l = de(0);
|
|
439
|
+
function r(g, m) {
|
|
440
|
+
!e.enabled || c || (t < a.length - 1 && a.splice(t + 1), a.push({ path: g, timestamp: Date.now(), props: m ? { ...m } : void 0 }), t = a.length - 1, a.length > o && (a.shift(), t--), l.value++);
|
|
441
|
+
}
|
|
442
|
+
const u = C(() => (l.value, [...a])), i = C(() => (l.value, t > 0)), d = C(() => (l.value, t < a.length - 1));
|
|
443
|
+
async function E(g) {
|
|
444
|
+
if (g < 0 || g >= a.length) return;
|
|
445
|
+
const m = a[g];
|
|
446
|
+
if (m) {
|
|
447
|
+
t = g, c = !0, l.value++;
|
|
448
|
+
try {
|
|
449
|
+
await n(m.path);
|
|
450
|
+
} finally {
|
|
451
|
+
c = !1;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
async function M() {
|
|
456
|
+
i.value && await E(t - 1);
|
|
457
|
+
}
|
|
458
|
+
async function A() {
|
|
459
|
+
d.value && await E(t + 1);
|
|
460
|
+
}
|
|
461
|
+
async function _(g) {
|
|
462
|
+
const m = t + g;
|
|
463
|
+
await E(m);
|
|
464
|
+
}
|
|
465
|
+
function G() {
|
|
466
|
+
a.length = 0, t = -1, l.value++;
|
|
467
|
+
}
|
|
468
|
+
return { entries: u, canGoBack: i, canGoForward: d, back: M, forward: A, go: _, clear: G, record: r };
|
|
469
|
+
}
|
|
470
|
+
function He() {
|
|
471
|
+
const e = K(/* @__PURE__ */ new Map()), n = /* @__PURE__ */ new Map();
|
|
472
|
+
function o(l) {
|
|
473
|
+
e.has(l.path) && console.warn(`[vue-micro-router] Route "${l.path}" already registered. Overwriting.`);
|
|
474
|
+
let { component: r } = l;
|
|
475
|
+
Pe(r) && (n.set(l.path, r), r = ge(r)), e.set(l.path, {
|
|
476
|
+
...l,
|
|
477
|
+
component: ye(r)
|
|
478
|
+
}), l.preload === "eager" && n.has(l.path) && k(n.get(l.path));
|
|
479
|
+
}
|
|
480
|
+
function a(l) {
|
|
481
|
+
l.forEach(o);
|
|
482
|
+
}
|
|
483
|
+
async function t(l) {
|
|
484
|
+
const r = n.get(l);
|
|
485
|
+
r && await k(r);
|
|
486
|
+
}
|
|
487
|
+
function c(l) {
|
|
488
|
+
for (const [r, u] of e.entries())
|
|
489
|
+
if (u.preload === "adjacent" && !l.includes(r)) {
|
|
490
|
+
const i = n.get(r);
|
|
491
|
+
i && k(i);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return { routes: e, asyncLoaders: n, registerRoute: o, registerRoutes: a, preloadRoute: t, preloadAdjacent: c };
|
|
495
|
+
}
|
|
496
|
+
function xe(e) {
|
|
497
|
+
const n = e.stepWiseDelay ?? Math.max(e.stepDelay * 1.2, e.stepDelay + 100);
|
|
498
|
+
async function o(t, c) {
|
|
499
|
+
if (!t || e.isLocked()) return;
|
|
500
|
+
const l = $(t);
|
|
501
|
+
if (e.getActivePath() !== l) {
|
|
502
|
+
e.lock();
|
|
503
|
+
try {
|
|
504
|
+
if (e.runGuards) {
|
|
505
|
+
const i = $(e.getActivePath());
|
|
506
|
+
if (!await e.runGuards(l, i)) {
|
|
507
|
+
e.unlock();
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
const r = T(e.getActivePath()), u = T(l);
|
|
512
|
+
if (t.startsWith("/"))
|
|
513
|
+
for (let i = 0; i < u.length; i++) {
|
|
514
|
+
const d = W(
|
|
515
|
+
u.slice(0, i + 1)
|
|
516
|
+
);
|
|
517
|
+
if (e.getActivePath() === d) continue;
|
|
518
|
+
const E = i === u.length - 1;
|
|
519
|
+
await e.pushCore(d, E ? c : void 0), E || await se(n);
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
const i = u.filter(
|
|
523
|
+
(d) => !r.includes(d)
|
|
524
|
+
);
|
|
525
|
+
if (i.length === 0) {
|
|
526
|
+
await e.pushCore(t, c), e.scheduleUnlock();
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
for (let d = 0; d < i.length; d++) {
|
|
530
|
+
const E = d === i.length - 1;
|
|
531
|
+
await e.pushCore(i[d], E ? c : void 0), E || await se(n);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
e.scheduleUnlock();
|
|
535
|
+
} catch (r) {
|
|
536
|
+
throw e.unlock(), r;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
async function a(t) {
|
|
541
|
+
if (t < 1 || e.isLocked()) return;
|
|
542
|
+
const c = T(e.getActivePath()), l = Math.min(t, c.length - 1);
|
|
543
|
+
if (!(l < 1)) {
|
|
544
|
+
e.lock();
|
|
545
|
+
try {
|
|
546
|
+
if (e.runGuards) {
|
|
547
|
+
const r = c.slice(0, c.length - l), u = W(r), i = $(e.getActivePath());
|
|
548
|
+
if (!await e.runGuards(u, i)) {
|
|
549
|
+
e.unlock();
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
for (let r = 0; r < l; r++)
|
|
554
|
+
await e.pushCore(-1), r < l - 1 && await se(n);
|
|
555
|
+
e.scheduleUnlock();
|
|
556
|
+
} catch (r) {
|
|
557
|
+
throw e.unlock(), r;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return { stepWisePush: o, stepWiseBack: a };
|
|
562
|
+
}
|
|
563
|
+
function qe(e, n) {
|
|
564
|
+
const o = e.defaultPath, a = e.stepDelay ?? We, t = e.guards ?? {}, c = e.history ?? {}, l = pe(), r = He();
|
|
565
|
+
let u = !1;
|
|
566
|
+
const i = fe({
|
|
567
|
+
activePath: o,
|
|
568
|
+
fromPath: o,
|
|
569
|
+
toPath: o,
|
|
570
|
+
/** Attrs stored separately — changes here do NOT invalidate resolveRoutes computed */
|
|
571
|
+
routeAttrs: K(/* @__PURE__ */ new Map()),
|
|
572
|
+
/** Version stamp per segment — incremented on re-navigation to same segment (forces transition) */
|
|
573
|
+
routeKeys: K(/* @__PURE__ */ new Map()),
|
|
574
|
+
/** Component key per segment — incremented to force Vue full remount (resets local state) */
|
|
575
|
+
componentKeys: K(/* @__PURE__ */ new Map())
|
|
576
|
+
}), d = /* @__PURE__ */ new Map(), E = C(() => {
|
|
577
|
+
const p = T(i.activePath), h = [];
|
|
578
|
+
for (const v of p) {
|
|
579
|
+
const w = r.routes.get(v);
|
|
580
|
+
if (!w) continue;
|
|
581
|
+
const P = i.routeKeys.get(v) || 0, L = i.componentKeys.get(v) || 0, S = `${w.path}-${P}`, R = d.get(v);
|
|
582
|
+
if (R && R.key === S && R.componentKey === L)
|
|
583
|
+
h.push(R);
|
|
584
|
+
else {
|
|
585
|
+
const B = { ...w, key: S, componentKey: L };
|
|
586
|
+
d.set(v, B), h.push(B);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
for (const v of d.keys())
|
|
590
|
+
p.includes(v) || d.delete(v);
|
|
591
|
+
return h;
|
|
592
|
+
});
|
|
593
|
+
function M(p, h) {
|
|
594
|
+
var B, O;
|
|
595
|
+
const v = T(i.activePath), w = Math.min(p, v.length - 1);
|
|
596
|
+
if (w <= 0) return;
|
|
597
|
+
const P = v.slice(0, -w), L = W(P);
|
|
598
|
+
v.slice(-w).forEach((F) => {
|
|
599
|
+
i.routeAttrs.delete(F);
|
|
600
|
+
});
|
|
601
|
+
const S = P.at(-1);
|
|
602
|
+
if (S && h) {
|
|
603
|
+
const F = i.routeAttrs.get(S);
|
|
604
|
+
i.routeAttrs.set(S, { ...F, ...h }), i.componentKeys.set(
|
|
605
|
+
S,
|
|
606
|
+
(i.componentKeys.get(S) || 0) + 1
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
const R = i.activePath;
|
|
610
|
+
(B = n == null ? void 0 : n.trackPageLeave) == null || B.call(n, R, R, L), i.fromPath = R, i.toPath = L, i.activePath = L, (O = n == null ? void 0 : n.trackPageEnter) == null || O.call(n, L, R, L);
|
|
611
|
+
}
|
|
612
|
+
async function A(p, h) {
|
|
613
|
+
var L, S;
|
|
614
|
+
const v = $(p), w = T(v);
|
|
615
|
+
await Promise.all(
|
|
616
|
+
w.map((R) => r.asyncLoaders.get(R)).filter((R) => !!R).map((R) => k(R))
|
|
617
|
+
);
|
|
618
|
+
const P = i.activePath;
|
|
619
|
+
P !== v && ((L = n == null ? void 0 : n.trackPageLeave) == null || L.call(n, P, P, v)), i.fromPath = P, i.toPath = v, i.activePath = v, h && _(v, h), (S = n == null ? void 0 : n.trackPageEnter) == null || S.call(n, v, P, v);
|
|
620
|
+
}
|
|
621
|
+
function _(p, h) {
|
|
622
|
+
const v = T(p).at(-1);
|
|
623
|
+
if (!v) return;
|
|
624
|
+
const w = i.routeAttrs.get(v);
|
|
625
|
+
i.routeAttrs.set(v, { ...w, ...h });
|
|
626
|
+
}
|
|
627
|
+
function G(p, h) {
|
|
628
|
+
const v = i.routeAttrs.get(p);
|
|
629
|
+
i.routeAttrs.set(p, { ...v, ...h });
|
|
630
|
+
}
|
|
631
|
+
function g(p) {
|
|
632
|
+
return i.routeAttrs.get(p);
|
|
633
|
+
}
|
|
634
|
+
async function m(p, h) {
|
|
635
|
+
if (!p && p !== 0) return;
|
|
636
|
+
if (typeof p == "number" && p < 0) {
|
|
637
|
+
M(Math.abs(p), h);
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
const v = p.toString();
|
|
641
|
+
if (v.startsWith("/")) {
|
|
642
|
+
const S = T(v), R = T(i.activePath);
|
|
643
|
+
if (S.length < R.length && S.every((F, oe) => R[oe] === F)) {
|
|
644
|
+
if (R.length - S.length === 1)
|
|
645
|
+
M(1, h);
|
|
646
|
+
else {
|
|
647
|
+
const oe = R.slice(0, S.length + 1), _e = W(oe);
|
|
648
|
+
R.slice(S.length + 1).forEach((Te) => {
|
|
649
|
+
i.routeAttrs.delete(Te);
|
|
650
|
+
}), i.activePath = _e, await J(), M(1, h);
|
|
651
|
+
}
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
const O = S.at(-1);
|
|
655
|
+
O && R.at(-1) === O && i.routeKeys.set(
|
|
656
|
+
O,
|
|
657
|
+
(i.routeKeys.get(O) || 0) + 1
|
|
658
|
+
), await A(v, h);
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
const w = T(i.activePath), P = w.indexOf(v);
|
|
662
|
+
if (P !== -1) {
|
|
663
|
+
const S = w.length - (P + 1);
|
|
664
|
+
if (S === 1)
|
|
665
|
+
M(1, h);
|
|
666
|
+
else if (S > 1) {
|
|
667
|
+
const R = w.slice(0, P + 2), B = W(R);
|
|
668
|
+
w.slice(P + 2).forEach((O) => {
|
|
669
|
+
i.routeAttrs.delete(O);
|
|
670
|
+
}), i.activePath = B, await J(), M(1, h);
|
|
671
|
+
} else
|
|
672
|
+
i.routeKeys.set(v, (i.routeKeys.get(v) || 0) + 1), await A(
|
|
673
|
+
W(w.slice(0, P + 1)),
|
|
674
|
+
h
|
|
675
|
+
);
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
const L = W([...w, v]);
|
|
679
|
+
await A(L, h);
|
|
680
|
+
}
|
|
681
|
+
function s(p) {
|
|
682
|
+
if (typeof p == "number" && p < 0) {
|
|
683
|
+
const P = T(i.activePath), L = Math.min(Math.abs(p), P.length - 1);
|
|
684
|
+
return L <= 0 ? i.activePath : W(P.slice(0, -L));
|
|
685
|
+
}
|
|
686
|
+
const h = p.toString();
|
|
687
|
+
if (h.startsWith("/")) return $(h);
|
|
688
|
+
const v = T(i.activePath), w = v.indexOf(h);
|
|
689
|
+
return W(w !== -1 ? v.slice(0, w + 1) : [...v, h]);
|
|
690
|
+
}
|
|
691
|
+
const f = { getRoute: (p) => r.routes.get(p) };
|
|
692
|
+
async function y(p, h) {
|
|
693
|
+
var v;
|
|
694
|
+
if (!u) {
|
|
695
|
+
u = !0;
|
|
696
|
+
try {
|
|
697
|
+
const w = (((v = t.beforeEach) == null ? void 0 : v.length) ?? 0) > 0, P = r.routes.size > 0;
|
|
698
|
+
if ((w || P) && p) {
|
|
699
|
+
const R = s(p), B = $(i.activePath);
|
|
700
|
+
if (!await Ce(R, B, t, f)) {
|
|
701
|
+
u = !1;
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
const L = $(i.activePath);
|
|
706
|
+
await m(p, h);
|
|
707
|
+
const S = $(i.activePath);
|
|
708
|
+
D == null || D.record(S, h), Ve(S, L, t.afterEach), r.preloadAdjacent(T(i.activePath)), l.schedule(() => {
|
|
709
|
+
u = !1;
|
|
710
|
+
}, a);
|
|
711
|
+
} catch (w) {
|
|
712
|
+
throw u = !1, w;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
const D = c.enabled ? je(c, async (p) => {
|
|
717
|
+
const h = T(i.activePath), v = T(p);
|
|
718
|
+
if (v.length < h.length && v.every((P, L) => h[L] === P)) {
|
|
719
|
+
const P = h.length - v.length;
|
|
720
|
+
await y(-P);
|
|
721
|
+
} else
|
|
722
|
+
await y(p);
|
|
723
|
+
}) : void 0;
|
|
724
|
+
D && D.record($(o));
|
|
725
|
+
const b = xe({
|
|
726
|
+
getActivePath: () => i.activePath,
|
|
727
|
+
pushCore: m,
|
|
728
|
+
runGuards: (p, h) => Ce(p, h, t, f),
|
|
729
|
+
scheduleUnlock: () => l.schedule(() => {
|
|
730
|
+
u = !1;
|
|
731
|
+
}, a),
|
|
732
|
+
lock: () => {
|
|
733
|
+
u = !0;
|
|
734
|
+
},
|
|
735
|
+
unlock: () => {
|
|
736
|
+
u = !1;
|
|
737
|
+
},
|
|
738
|
+
isLocked: () => u,
|
|
739
|
+
stepDelay: a
|
|
740
|
+
});
|
|
741
|
+
return {
|
|
742
|
+
activePath: C(() => i.activePath),
|
|
743
|
+
fromPath: C(() => i.fromPath),
|
|
744
|
+
toPath: C(() => i.toPath),
|
|
745
|
+
activePage: C(() => V(i.activePath)),
|
|
746
|
+
fromPage: C(() => V(i.fromPath)),
|
|
747
|
+
toPage: C(() => V(i.toPath)),
|
|
748
|
+
resolveRoutes: E,
|
|
749
|
+
push: y,
|
|
750
|
+
stepWisePush: b.stepWisePush,
|
|
751
|
+
stepWiseBack: b.stepWiseBack,
|
|
752
|
+
registerRoute: r.registerRoute,
|
|
753
|
+
registerRoutes: r.registerRoutes,
|
|
754
|
+
updateRouteAttrs: G,
|
|
755
|
+
getRouteAttrs: g,
|
|
756
|
+
preloadRoute: r.preloadRoute,
|
|
757
|
+
history: D,
|
|
758
|
+
cleanup: l.cleanup
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
const X = () => {
|
|
762
|
+
};
|
|
763
|
+
function Je(e) {
|
|
764
|
+
return {
|
|
765
|
+
trackPageEnter: (e == null ? void 0 : e.trackPageEnter) ?? X,
|
|
766
|
+
trackPageLeave: (e == null ? void 0 : e.trackPageLeave) ?? X,
|
|
767
|
+
trackDialogEnter: (e == null ? void 0 : e.trackDialogEnter) ?? X,
|
|
768
|
+
trackDialogLeave: (e == null ? void 0 : e.trackDialogLeave) ?? X,
|
|
769
|
+
trackGuiEnter: (e == null ? void 0 : e.trackGuiEnter) ?? X,
|
|
770
|
+
trackGuiLeave: (e == null ? void 0 : e.trackGuiLeave) ?? X,
|
|
771
|
+
cleanupAllSessions: (e == null ? void 0 : e.cleanupAllSessions) ?? X
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
function Qe(e) {
|
|
775
|
+
const n = Je(e.tracker), o = qe(
|
|
776
|
+
{
|
|
777
|
+
defaultPath: e.defaultPath,
|
|
778
|
+
stepDelay: e.stepDelay,
|
|
779
|
+
guards: e.guards,
|
|
780
|
+
history: e.history
|
|
781
|
+
},
|
|
782
|
+
n
|
|
783
|
+
), a = ze(n), t = $e(
|
|
784
|
+
{
|
|
785
|
+
defaultControlName: e.defaultControlName,
|
|
786
|
+
onboardingControlName: e.onboardingControlName
|
|
787
|
+
},
|
|
788
|
+
n
|
|
789
|
+
), c = {
|
|
790
|
+
// Navigation
|
|
791
|
+
activePath: o.activePath,
|
|
792
|
+
fromPath: o.fromPath,
|
|
793
|
+
toPath: o.toPath,
|
|
794
|
+
activePage: o.activePage,
|
|
795
|
+
fromPage: o.fromPage,
|
|
796
|
+
toPage: o.toPage,
|
|
797
|
+
resolveRoutes: o.resolveRoutes,
|
|
798
|
+
push: o.push,
|
|
799
|
+
stepWisePush: o.stepWisePush,
|
|
800
|
+
stepWiseBack: o.stepWiseBack,
|
|
801
|
+
registerRoute: o.registerRoute,
|
|
802
|
+
registerRoutes: o.registerRoutes,
|
|
803
|
+
updateRouteAttrs: o.updateRouteAttrs,
|
|
804
|
+
getRouteAttrs: o.getRouteAttrs,
|
|
805
|
+
preloadRoute: o.preloadRoute,
|
|
806
|
+
// History (conditional — only if enabled)
|
|
807
|
+
...o.history ? {
|
|
808
|
+
canGoBack: o.history.canGoBack,
|
|
809
|
+
canGoForward: o.history.canGoForward,
|
|
810
|
+
historyBack: o.history.back,
|
|
811
|
+
historyForward: o.history.forward,
|
|
812
|
+
historyGo: o.history.go
|
|
813
|
+
} : {},
|
|
814
|
+
// Dialogs
|
|
815
|
+
activeDialog: a.activeDialog,
|
|
816
|
+
fromDialog: a.fromDialog,
|
|
817
|
+
toDialog: a.toDialog,
|
|
818
|
+
resolveDialogs: a.resolveDialogs,
|
|
819
|
+
openDialog: a.openDialog,
|
|
820
|
+
closeDialog: a.closeDialog,
|
|
821
|
+
closeAllDialogs: a.closeAllDialogs,
|
|
822
|
+
registerDialog: a.registerDialog,
|
|
823
|
+
registerDialogs: a.registerDialogs,
|
|
824
|
+
getDialogAttrs: a.getDialogAttrs,
|
|
825
|
+
updateDialogAttrs: a.updateDialogAttrs,
|
|
826
|
+
// Controls
|
|
827
|
+
resolveControls: t.resolveControls,
|
|
828
|
+
activeControl: t.activeControl,
|
|
829
|
+
currentControl: t.currentControl,
|
|
830
|
+
toggleControl: t.toggleControl,
|
|
831
|
+
registerControl: t.registerControl,
|
|
832
|
+
registerControls: t.registerControls,
|
|
833
|
+
getControlAttrs: t.getControlAttrs,
|
|
834
|
+
updateControlAttrs: t.updateControlAttrs,
|
|
835
|
+
// Serialization
|
|
836
|
+
serialize: () => Xe(c),
|
|
837
|
+
restore: (u) => Ue(c, u)
|
|
838
|
+
}, l = V(e.defaultPath);
|
|
839
|
+
return j(o.activePage, (u, i) => {
|
|
840
|
+
if (!i) return;
|
|
841
|
+
const d = t.currentControl.value;
|
|
842
|
+
i === l && u !== l && n.trackGuiLeave(d), u === l && i !== l && n.trackGuiEnter(d);
|
|
843
|
+
}), H(async () => {
|
|
844
|
+
await J(), t.toggleControl(e.defaultControlName, !0), n.trackPageEnter(
|
|
845
|
+
o.activePath.value,
|
|
846
|
+
void 0,
|
|
847
|
+
o.activePath.value
|
|
848
|
+
), Ye(c);
|
|
849
|
+
}), Ae(() => {
|
|
850
|
+
n.cleanupAllSessions(), o.cleanup(), a.cleanup(), t.cleanup();
|
|
851
|
+
}), N(Ee, c), z(ce, null) || N(ce, c), c;
|
|
852
|
+
}
|
|
853
|
+
function x(e) {
|
|
854
|
+
const n = e != null && e.root ? ce : Ee, o = z(n);
|
|
855
|
+
if (!o)
|
|
856
|
+
throw new Error(
|
|
857
|
+
e != null && e.root ? "[vue-micro-router] useMicroRouter({ root: true }) failed — no root <MicroRouterView> found." : "[vue-micro-router] useMicroRouter() must be called inside <MicroRouterView>. Did you forget to wrap your app with <MicroRouterView>?"
|
|
858
|
+
);
|
|
859
|
+
return o;
|
|
860
|
+
}
|
|
861
|
+
function ct(e) {
|
|
862
|
+
const n = z(te), o = z(ne);
|
|
863
|
+
!n && !e && console.warn(
|
|
864
|
+
"[vue-micro-router] useMicroState() called without provider and no defaults. Ensure component is inside <RoutePage>, <MicroDialog>, or <MicroControlWrapper>."
|
|
865
|
+
);
|
|
866
|
+
const a = (n == null ? void 0 : n()) ?? {}, t = e ? { ...e } : {};
|
|
867
|
+
for (const r of Object.keys(a))
|
|
868
|
+
t[r] = a[r];
|
|
869
|
+
const c = fe(t);
|
|
870
|
+
o && j(
|
|
871
|
+
c,
|
|
872
|
+
(r) => o({ ...r }),
|
|
873
|
+
{ deep: !0, flush: "post" }
|
|
874
|
+
);
|
|
875
|
+
const l = Ie(c);
|
|
876
|
+
return new Proxy(l, {
|
|
877
|
+
get(r, u, i) {
|
|
878
|
+
return typeof u == "string" && !(u in r) && (r[u] = Ne(c, u)), Reflect.get(r, u, i);
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
function ut(e) {
|
|
883
|
+
const n = z(Se);
|
|
884
|
+
if (!n) {
|
|
885
|
+
console.warn(
|
|
886
|
+
"[vue-micro-router] useRouteLifecycle() must be called inside a route component rendered by <MicroRouterView>."
|
|
887
|
+
);
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
const { activePage: o } = x();
|
|
891
|
+
let a = o.value === n;
|
|
892
|
+
a && H(() => {
|
|
893
|
+
var t;
|
|
894
|
+
return (t = e.onRouteEnter) == null ? void 0 : t.call(e);
|
|
895
|
+
}), j(o, (t) => {
|
|
896
|
+
var l, r;
|
|
897
|
+
const c = t === n;
|
|
898
|
+
c && !a ? (l = e.onRouteEnter) == null || l.call(e) : !c && a && ((r = e.onRouteLeave) == null || r.call(e)), a = c;
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
function gt(e) {
|
|
902
|
+
const n = z(Le);
|
|
903
|
+
if (!n) {
|
|
904
|
+
console.warn(
|
|
905
|
+
"[vue-micro-router] useDialogLifecycle() must be called inside a dialog component rendered by <MicroDialog>."
|
|
906
|
+
);
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
const { activeDialog: o } = x();
|
|
910
|
+
let a = o.value === n;
|
|
911
|
+
a && H(() => {
|
|
912
|
+
var t;
|
|
913
|
+
return (t = e.onDialogEnter) == null ? void 0 : t.call(e);
|
|
914
|
+
}), j(o, (t) => {
|
|
915
|
+
var l, r;
|
|
916
|
+
const c = t === n;
|
|
917
|
+
c && !a ? (l = e.onDialogEnter) == null || l.call(e) : !c && a && ((r = e.onDialogLeave) == null || r.call(e)), a = c;
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
function ft(e) {
|
|
921
|
+
const n = z(Me);
|
|
922
|
+
if (!n) {
|
|
923
|
+
console.warn(
|
|
924
|
+
"[vue-micro-router] useControlLifecycle() must be called inside a control component rendered by <MicroControlWrapper>."
|
|
925
|
+
);
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
const { currentControl: o } = x();
|
|
929
|
+
let a = o.value === n;
|
|
930
|
+
a && H(() => {
|
|
931
|
+
var t;
|
|
932
|
+
return (t = e.onControlEnter) == null ? void 0 : t.call(e);
|
|
933
|
+
}), j(o, (t) => {
|
|
934
|
+
var l, r;
|
|
935
|
+
const c = t === n;
|
|
936
|
+
c && !a ? (l = e.onControlEnter) == null || l.call(e) : !c && a && ((r = e.onControlLeave) == null || r.call(e)), a = c;
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
function Ze(e, n) {
|
|
940
|
+
if (!e.enabled) return;
|
|
941
|
+
const o = e.edgeWidth ?? 20, a = e.threshold ?? 0.3, t = e.velocityThreshold ?? 0.5;
|
|
942
|
+
let c = 0, l = 0, r = 0, u = !1, i = null, d = null;
|
|
943
|
+
function E() {
|
|
944
|
+
const s = n.containerRef.value;
|
|
945
|
+
return s ? "$el" in s ? s.$el : s : null;
|
|
946
|
+
}
|
|
947
|
+
function M() {
|
|
948
|
+
const s = E();
|
|
949
|
+
if (!s) return { current: null, previous: null };
|
|
950
|
+
const f = s.querySelectorAll(".route-page");
|
|
951
|
+
return f.length < 2 ? { current: f[f.length - 1] ?? null, previous: null } : {
|
|
952
|
+
current: f[f.length - 1],
|
|
953
|
+
previous: f[f.length - 2]
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
function A(s) {
|
|
957
|
+
var b;
|
|
958
|
+
if (!n.canGoBack() || s.clientX > o) return;
|
|
959
|
+
const { current: f, previous: y } = M();
|
|
960
|
+
if (!f) return;
|
|
961
|
+
u = !0, c = s.clientX, l = s.clientY, r = Date.now(), i = f, d = y;
|
|
962
|
+
const D = E();
|
|
963
|
+
(b = D == null ? void 0 : D.setPointerCapture) == null || b.call(D, s.pointerId), i.style.willChange = "transform", d && (d.style.willChange = "transform", d.style.transition = "none"), i.style.transition = "none";
|
|
964
|
+
}
|
|
965
|
+
function _(s) {
|
|
966
|
+
if (!u || !i) return;
|
|
967
|
+
const f = Math.max(0, s.clientX - c);
|
|
968
|
+
if (Math.abs(s.clientY - l) > f * 1.5) {
|
|
969
|
+
g();
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
const D = f / window.innerWidth;
|
|
973
|
+
if (i.style.transform = `translateX(${f}px)`, d) {
|
|
974
|
+
const b = -20 + 20 * D;
|
|
975
|
+
d.style.transform = `translateX(${b}%)`;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
function G(s) {
|
|
979
|
+
if (!u || !i) return;
|
|
980
|
+
if (!i.isConnected) {
|
|
981
|
+
m(), u = !1;
|
|
982
|
+
return;
|
|
983
|
+
}
|
|
984
|
+
const f = s.clientX - c, y = Date.now() - r, D = f / y;
|
|
985
|
+
f / window.innerWidth > a || D > t ? (i.style.transition = "transform 0.2s ease-out", i.style.transform = "translateX(100%)", d && (d.style.transition = "transform 0.2s ease-out", d.style.transform = "translateX(0)"), setTimeout(() => {
|
|
986
|
+
m(), n.goBack();
|
|
987
|
+
}, 200)) : (i.style.transition = "transform 0.2s ease-out", i.style.transform = "translateX(0)", d && (d.style.transition = "transform 0.2s ease-out", d.style.transform = "translateX(-20%)"), setTimeout(m, 200)), u = !1;
|
|
988
|
+
}
|
|
989
|
+
function g() {
|
|
990
|
+
u && (i && (i.style.transition = "transform 0.15s ease-out", i.style.transform = "translateX(0)"), d && (d.style.transition = "transform 0.15s ease-out", d.style.transform = "translateX(-20%)"), setTimeout(m, 150), u = !1);
|
|
991
|
+
}
|
|
992
|
+
function m() {
|
|
993
|
+
i && (i.style.willChange = "", i.style.transition = "", i.style.transform = ""), d && (d.style.willChange = "", d.style.transition = "", d.style.transform = ""), i = null, d = null;
|
|
994
|
+
}
|
|
995
|
+
H(() => {
|
|
996
|
+
const s = E();
|
|
997
|
+
s != null && s.addEventListener && (s.addEventListener("pointerdown", A, { passive: !0 }), s.addEventListener("pointermove", _, { passive: !0 }), s.addEventListener("pointerup", G, { passive: !0 }), s.addEventListener("pointercancel", g, { passive: !0 }));
|
|
998
|
+
}), Ae(() => {
|
|
999
|
+
const s = E();
|
|
1000
|
+
s != null && s.removeEventListener && (s.removeEventListener("pointerdown", A), s.removeEventListener("pointermove", _), s.removeEventListener("pointerup", G), s.removeEventListener("pointercancel", g));
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
function dt(e) {
|
|
1004
|
+
return { ...e };
|
|
1005
|
+
}
|
|
1006
|
+
function ke(e, n) {
|
|
1007
|
+
var o, a, t;
|
|
1008
|
+
for (const c of e)
|
|
1009
|
+
(o = c.routes) != null && o.length && n.registerRoutes(c.routes), (a = c.dialogs) != null && a.length && n.registerDialogs(c.dialogs), (t = c.controls) != null && t.length && n.registerControls(c.controls);
|
|
1010
|
+
}
|
|
1011
|
+
const et = /* @__PURE__ */ ee({
|
|
1012
|
+
__name: "MicroControlWrapper",
|
|
1013
|
+
props: {
|
|
1014
|
+
control: {}
|
|
1015
|
+
},
|
|
1016
|
+
setup(e) {
|
|
1017
|
+
const n = e, { getControlAttrs: o, updateControlAttrs: a } = x();
|
|
1018
|
+
return N(Me, n.control.name), N(te, () => o(n.control.name)), N(ne, (t) => {
|
|
1019
|
+
a(n.control.name, t);
|
|
1020
|
+
}), (t, c) => (I(), U(ve(e.control.component), me({
|
|
1021
|
+
key: e.control.componentKey || 0
|
|
1022
|
+
}, e.control.attrs), null, 16));
|
|
1023
|
+
}
|
|
1024
|
+
}), tt = /* @__PURE__ */ ee({
|
|
1025
|
+
__name: "MicroDialog",
|
|
1026
|
+
props: {
|
|
1027
|
+
dialog: {},
|
|
1028
|
+
stackIndex: {}
|
|
1029
|
+
},
|
|
1030
|
+
emits: ["close"],
|
|
1031
|
+
setup(e, { emit: n }) {
|
|
1032
|
+
const o = e, a = n, { getDialogAttrs: t, updateDialogAttrs: c } = x(), l = de(null);
|
|
1033
|
+
N(Le, o.dialog.path), N(te, () => t(o.dialog.path)), N(ne, (A) => {
|
|
1034
|
+
c(o.dialog.path, A);
|
|
1035
|
+
});
|
|
1036
|
+
const r = C(() => o.dialog.transition ?? "scale"), u = C(() => o.dialog.transitionDuration != null ? o.dialog.transitionDuration : r.value === "slide" ? 500 : 300), i = C(() => o.dialog.position ?? "standard"), d = C(() => o.dialog.seamless ?? !0);
|
|
1037
|
+
function E(A) {
|
|
1038
|
+
if (o.dialog.persistent) {
|
|
1039
|
+
A.preventDefault();
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
A.preventDefault(), a("close", o.dialog.path);
|
|
1043
|
+
}
|
|
1044
|
+
function M(A) {
|
|
1045
|
+
o.dialog.persistent || A.target === l.value && a("close", o.dialog.path);
|
|
1046
|
+
}
|
|
1047
|
+
return j(
|
|
1048
|
+
() => o.dialog.activated,
|
|
1049
|
+
(A) => {
|
|
1050
|
+
J(() => {
|
|
1051
|
+
l.value && (A && !l.value.open ? l.value.showModal() : !A && l.value.open && l.value.close());
|
|
1052
|
+
});
|
|
1053
|
+
},
|
|
1054
|
+
{ immediate: !0 }
|
|
1055
|
+
), H(() => {
|
|
1056
|
+
o.dialog.activated && l.value && !l.value.open && l.value.showModal();
|
|
1057
|
+
}), (A, _) => (I(), U(Be, { to: "body" }, [
|
|
1058
|
+
Q("dialog", {
|
|
1059
|
+
ref_key: "dialogRef",
|
|
1060
|
+
ref: l,
|
|
1061
|
+
class: le([
|
|
1062
|
+
"micro-dialog",
|
|
1063
|
+
`micro-dialog--${i.value}`,
|
|
1064
|
+
e.dialog.fullscreen && "micro-dialog--fullscreen",
|
|
1065
|
+
d.value && "micro-dialog--seamless",
|
|
1066
|
+
`dialog-transition-${r.value}`,
|
|
1067
|
+
e.dialog.closing && "micro-dialog--closing"
|
|
1068
|
+
]),
|
|
1069
|
+
style: Re({
|
|
1070
|
+
"--dialog-duration": `${u.value}ms`,
|
|
1071
|
+
zIndex: 100 + e.stackIndex
|
|
1072
|
+
}),
|
|
1073
|
+
onCancel: E,
|
|
1074
|
+
onClick: M
|
|
1075
|
+
}, [
|
|
1076
|
+
Q("div", {
|
|
1077
|
+
class: "micro-dialog__content",
|
|
1078
|
+
onClick: _[0] || (_[0] = Oe(() => {
|
|
1079
|
+
}, ["stop"]))
|
|
1080
|
+
}, [
|
|
1081
|
+
he(A.$slots, "default"),
|
|
1082
|
+
(I(), U(ve(e.dialog.component), me({
|
|
1083
|
+
key: e.dialog.componentKey
|
|
1084
|
+
}, e.dialog.attrs), null, 16))
|
|
1085
|
+
])
|
|
1086
|
+
], 38)
|
|
1087
|
+
]));
|
|
1088
|
+
}
|
|
1089
|
+
}), nt = { class: "route-page" }, ot = { class: "route-page__body" }, at = /* @__PURE__ */ ee({
|
|
1090
|
+
__name: "RoutePage",
|
|
1091
|
+
props: {
|
|
1092
|
+
routePath: {}
|
|
1093
|
+
},
|
|
1094
|
+
setup(e) {
|
|
1095
|
+
const n = e;
|
|
1096
|
+
if (n.routePath) {
|
|
1097
|
+
const o = n.routePath;
|
|
1098
|
+
N(Se, o);
|
|
1099
|
+
const { updateRouteAttrs: a, getRouteAttrs: t } = x();
|
|
1100
|
+
N(te, () => t(o)), N(ne, (c) => {
|
|
1101
|
+
a(o, c);
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
return (o, a) => (I(), q("div", nt, [
|
|
1105
|
+
Q("div", ot, [
|
|
1106
|
+
he(o.$slots, "default")
|
|
1107
|
+
])
|
|
1108
|
+
]));
|
|
1109
|
+
}
|
|
1110
|
+
}), it = { class: "micro-router-content-layer" }, vt = /* @__PURE__ */ ee({
|
|
1111
|
+
__name: "MicroRouterView",
|
|
1112
|
+
props: {
|
|
1113
|
+
config: {},
|
|
1114
|
+
plugins: {},
|
|
1115
|
+
nested: { type: Boolean }
|
|
1116
|
+
},
|
|
1117
|
+
setup(e) {
|
|
1118
|
+
var g, m;
|
|
1119
|
+
const n = e, o = Qe(n.config);
|
|
1120
|
+
(g = n.plugins) != null && g.length && ke(n.plugins, o);
|
|
1121
|
+
const {
|
|
1122
|
+
resolveRoutes: a,
|
|
1123
|
+
resolveDialogs: t,
|
|
1124
|
+
resolveControls: c,
|
|
1125
|
+
fromPath: l,
|
|
1126
|
+
toPath: r,
|
|
1127
|
+
closeDialog: u
|
|
1128
|
+
} = o, i = de(null), d = C(() => {
|
|
1129
|
+
const s = l.value.split("/").filter(Boolean), f = r.value.split("/").filter(Boolean);
|
|
1130
|
+
return s.some((y) => f.includes(y));
|
|
1131
|
+
}), E = C(() => c.value.length > 0), M = C(() => {
|
|
1132
|
+
const s = a.value.at(-1);
|
|
1133
|
+
return (s == null ? void 0 : s.transition) ?? "slide";
|
|
1134
|
+
}), A = C(() => M.value === "none" ? "" : M.value === "fade" ? "page-fade" : "page-slide"), _ = C(() => {
|
|
1135
|
+
const s = a.value.at(-1);
|
|
1136
|
+
return s != null && s.transitionDuration ? s.transitionDuration : M.value === "fade" ? 300 : 500;
|
|
1137
|
+
}), G = C(() => d.value && M.value !== "none");
|
|
1138
|
+
return (m = n.config.gesture) != null && m.enabled && Ze(n.config.gesture, {
|
|
1139
|
+
containerRef: i,
|
|
1140
|
+
goBack: () => o.push(-1),
|
|
1141
|
+
canGoBack: () => a.value.length > 1
|
|
1142
|
+
}), (s, f) => (I(), q(Z, null, [
|
|
1143
|
+
De(we, {
|
|
1144
|
+
ref_key: "pageContainerRef",
|
|
1145
|
+
ref: i,
|
|
1146
|
+
name: A.value,
|
|
1147
|
+
css: G.value
|
|
1148
|
+
}, {
|
|
1149
|
+
default: ae(() => [
|
|
1150
|
+
(I(!0), q(Z, null, ie(Y(a), (y, D) => (I(), U(at, {
|
|
1151
|
+
key: y.key || y.path,
|
|
1152
|
+
"route-path": y.path,
|
|
1153
|
+
class: le({
|
|
1154
|
+
deactive: Y(a).length > 1 && D !== Y(a).length - 1
|
|
1155
|
+
}),
|
|
1156
|
+
style: Re({
|
|
1157
|
+
transition: G.value ? `transform ${_.value}ms cubic-bezier(0.65, 0, 0.35, 1), opacity ${_.value}ms ease` : "none",
|
|
1158
|
+
zIndex: D,
|
|
1159
|
+
"--mr-page-height": e.nested ? "100%" : "100dvh"
|
|
1160
|
+
})
|
|
1161
|
+
}, {
|
|
1162
|
+
default: ae(() => [
|
|
1163
|
+
(I(), U(ve(y.component), me({
|
|
1164
|
+
key: y.componentKey
|
|
1165
|
+
}, { ref_for: !0 }, Y(o).getRouteAttrs(y.path)), null, 16))
|
|
1166
|
+
]),
|
|
1167
|
+
_: 2
|
|
1168
|
+
}, 1032, ["route-path", "class", "style"]))), 128))
|
|
1169
|
+
]),
|
|
1170
|
+
_: 1
|
|
1171
|
+
}, 8, ["name", "css"]),
|
|
1172
|
+
Q("div", it, [
|
|
1173
|
+
he(s.$slots, "default")
|
|
1174
|
+
]),
|
|
1175
|
+
Q("div", {
|
|
1176
|
+
class: le(["micro-router-gui-layer", { "gui-visible": E.value }])
|
|
1177
|
+
}, [
|
|
1178
|
+
De(we, { name: "control-fade" }, {
|
|
1179
|
+
default: ae(() => [
|
|
1180
|
+
(I(!0), q(Z, null, ie(Y(c), (y) => (I(), U(et, {
|
|
1181
|
+
key: y.name + "-" + (y.componentKey || 0),
|
|
1182
|
+
control: y
|
|
1183
|
+
}, null, 8, ["control"]))), 128))
|
|
1184
|
+
]),
|
|
1185
|
+
_: 1
|
|
1186
|
+
})
|
|
1187
|
+
], 2),
|
|
1188
|
+
(I(!0), q(Z, null, ie(Y(t), (y, D) => (I(), U(tt, {
|
|
1189
|
+
key: "dialog-" + y.path,
|
|
1190
|
+
dialog: y,
|
|
1191
|
+
"stack-index": D,
|
|
1192
|
+
onClose: Y(u)
|
|
1193
|
+
}, null, 8, ["dialog", "stack-index", "onClose"]))), 128))
|
|
1194
|
+
], 64));
|
|
1195
|
+
}
|
|
1196
|
+
});
|
|
1197
|
+
export {
|
|
1198
|
+
te as MICRO_ATTRS_READ_KEY,
|
|
1199
|
+
ne as MICRO_ATTRS_WRITE_KEY,
|
|
1200
|
+
Me as MICRO_CONTROL_NAME_KEY,
|
|
1201
|
+
Le as MICRO_DIALOG_PATH_KEY,
|
|
1202
|
+
Ee as MICRO_ROUTER_KEY,
|
|
1203
|
+
ce as MICRO_ROUTER_ROOT_KEY,
|
|
1204
|
+
Se as MICRO_ROUTE_PATH_KEY,
|
|
1205
|
+
et as MicroControlWrapper,
|
|
1206
|
+
tt as MicroDialogComponent,
|
|
1207
|
+
vt as MicroRouterView,
|
|
1208
|
+
at as RoutePage,
|
|
1209
|
+
We as STEP_DELAY,
|
|
1210
|
+
W as buildPathFromSegments,
|
|
1211
|
+
lt as createRouterKey,
|
|
1212
|
+
dt as defineFeaturePlugin,
|
|
1213
|
+
V as getLastSegment,
|
|
1214
|
+
Pe as isAsyncLoader,
|
|
1215
|
+
$ as normalizePath,
|
|
1216
|
+
T as parsePathSegments,
|
|
1217
|
+
ke as registerFeaturePlugins,
|
|
1218
|
+
ye as safeMarkRaw,
|
|
1219
|
+
ft as useControlLifecycle,
|
|
1220
|
+
$e as useControlManager,
|
|
1221
|
+
gt as useDialogLifecycle,
|
|
1222
|
+
ze as useDialogManager,
|
|
1223
|
+
Ze as useGestureNavigation,
|
|
1224
|
+
Qe as useGlobalMicroRouter,
|
|
1225
|
+
x as useMicroRouter,
|
|
1226
|
+
ct as useMicroState,
|
|
1227
|
+
qe as useNavigation,
|
|
1228
|
+
Je as usePageTracker,
|
|
1229
|
+
ut as useRouteLifecycle
|
|
1230
|
+
};
|