@wsxjs/wsx-router 0.0.16 → 0.0.18
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 +2 -2
- package/README.md +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +1209 -582
- package/package.json +9 -7
- package/src/RouterUtils.ts +34 -4
- package/src/WsxLink.css +1 -1
- package/src/WsxLink.wsx +2 -1
- package/src/WsxRouter.css +6 -3
- package/src/WsxRouter.wsx +335 -44
- package/src/WsxView.wsx +104 -31
- package/src/index.ts +1 -1
- package/src/types/wsx.d.ts +3 -2
package/dist/index.js
CHANGED
|
@@ -1,591 +1,1383 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return
|
|
11
|
-
|
|
1
|
+
import { autoRegister as we, LightComponent as oe, jsx as ae, WebComponent as Re } from "@wsxjs/wsx-core";
|
|
2
|
+
function Ge(t) {
|
|
3
|
+
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
|
|
4
|
+
}
|
|
5
|
+
var ue = { exports: {} };
|
|
6
|
+
function Xe(t) {
|
|
7
|
+
try {
|
|
8
|
+
return JSON.stringify(t);
|
|
9
|
+
} catch {
|
|
10
|
+
return '"[Circular]"';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
var Ye = Ze;
|
|
14
|
+
function Ze(t, e, n) {
|
|
15
|
+
var r = n && n.stringify || Xe, s = 1;
|
|
16
|
+
if (typeof t == "object" && t !== null) {
|
|
17
|
+
var l = e.length + s;
|
|
18
|
+
if (l === 1) return t;
|
|
19
|
+
var m = new Array(l);
|
|
20
|
+
m[0] = r(t);
|
|
21
|
+
for (var g = 1; g < l; g++)
|
|
22
|
+
m[g] = r(e[g]);
|
|
23
|
+
return m.join(" ");
|
|
24
|
+
}
|
|
25
|
+
if (typeof t != "string")
|
|
26
|
+
return t;
|
|
27
|
+
var u = e.length;
|
|
28
|
+
if (u === 0) return t;
|
|
29
|
+
for (var i = "", p = 1 - s, v = -1, z = t && t.length || 0, x = 0; x < z; ) {
|
|
30
|
+
if (t.charCodeAt(x) === 37 && x + 1 < z) {
|
|
31
|
+
switch (v = v > -1 ? v : 0, t.charCodeAt(x + 1)) {
|
|
32
|
+
case 100:
|
|
33
|
+
// 'd'
|
|
34
|
+
case 102:
|
|
35
|
+
if (p >= u || e[p] == null) break;
|
|
36
|
+
v < x && (i += t.slice(v, x)), i += Number(e[p]), v = x + 2, x++;
|
|
37
|
+
break;
|
|
38
|
+
case 105:
|
|
39
|
+
if (p >= u || e[p] == null) break;
|
|
40
|
+
v < x && (i += t.slice(v, x)), i += Math.floor(Number(e[p])), v = x + 2, x++;
|
|
41
|
+
break;
|
|
42
|
+
case 79:
|
|
43
|
+
// 'O'
|
|
44
|
+
case 111:
|
|
45
|
+
// 'o'
|
|
46
|
+
case 106:
|
|
47
|
+
if (p >= u || e[p] === void 0) break;
|
|
48
|
+
v < x && (i += t.slice(v, x));
|
|
49
|
+
var o = typeof e[p];
|
|
50
|
+
if (o === "string") {
|
|
51
|
+
i += "'" + e[p] + "'", v = x + 2, x++;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
if (o === "function") {
|
|
55
|
+
i += e[p].name || "<anonymous>", v = x + 2, x++;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
i += r(e[p]), v = x + 2, x++;
|
|
59
|
+
break;
|
|
60
|
+
case 115:
|
|
61
|
+
if (p >= u)
|
|
62
|
+
break;
|
|
63
|
+
v < x && (i += t.slice(v, x)), i += String(e[p]), v = x + 2, x++;
|
|
64
|
+
break;
|
|
65
|
+
case 37:
|
|
66
|
+
v < x && (i += t.slice(v, x)), i += "%", v = x + 2, x++, p--;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
++p;
|
|
70
|
+
}
|
|
71
|
+
++x;
|
|
72
|
+
}
|
|
73
|
+
return v === -1 ? t : (v < z && (i += t.slice(v)), i);
|
|
74
|
+
}
|
|
75
|
+
const Le = Ye;
|
|
76
|
+
ue.exports = K;
|
|
77
|
+
const re = mt().console || {}, et = {
|
|
78
|
+
mapHttpRequest: ie,
|
|
79
|
+
mapHttpResponse: ie,
|
|
80
|
+
wrapRequestSerializer: fe,
|
|
81
|
+
wrapResponseSerializer: fe,
|
|
82
|
+
wrapErrorSerializer: fe,
|
|
83
|
+
req: ie,
|
|
84
|
+
res: ie,
|
|
85
|
+
err: _e,
|
|
86
|
+
errWithCause: _e
|
|
87
|
+
};
|
|
88
|
+
function Y(t, e) {
|
|
89
|
+
return t === "silent" ? 1 / 0 : e.levels.values[t];
|
|
90
|
+
}
|
|
91
|
+
const xe = Symbol("pino.logFuncs"), be = Symbol("pino.hierarchy"), tt = {
|
|
92
|
+
error: "log",
|
|
93
|
+
fatal: "error",
|
|
94
|
+
warn: "error",
|
|
95
|
+
info: "log",
|
|
96
|
+
debug: "log",
|
|
97
|
+
trace: "log"
|
|
98
|
+
};
|
|
99
|
+
function ke(t, e) {
|
|
100
|
+
const n = {
|
|
101
|
+
logger: e,
|
|
102
|
+
parent: t[be]
|
|
103
|
+
};
|
|
104
|
+
e[be] = n;
|
|
105
|
+
}
|
|
106
|
+
function nt(t, e, n) {
|
|
107
|
+
const r = {};
|
|
108
|
+
e.forEach((s) => {
|
|
109
|
+
r[s] = n[s] ? n[s] : re[s] || re[tt[s] || "log"] || ne;
|
|
110
|
+
}), t[xe] = r;
|
|
111
|
+
}
|
|
112
|
+
function rt(t, e) {
|
|
113
|
+
return Array.isArray(t) ? t.filter(function(r) {
|
|
114
|
+
return r !== "!stdSerializers.err";
|
|
115
|
+
}) : t === !0 ? Object.keys(e) : !1;
|
|
116
|
+
}
|
|
117
|
+
function K(t) {
|
|
118
|
+
t = t || {}, t.browser = t.browser || {};
|
|
119
|
+
const e = t.browser.transmit;
|
|
120
|
+
if (e && typeof e.send != "function")
|
|
121
|
+
throw Error("pino: transmit option must have a send function");
|
|
122
|
+
const n = t.browser.write || re;
|
|
123
|
+
t.browser.write && (t.browser.asObject = !0);
|
|
124
|
+
const r = t.serializers || {}, s = rt(t.browser.serialize, r);
|
|
125
|
+
let l = t.browser.serialize;
|
|
126
|
+
Array.isArray(t.browser.serialize) && t.browser.serialize.indexOf("!stdSerializers.err") > -1 && (l = !1);
|
|
127
|
+
const m = Object.keys(t.customLevels || {}), g = ["error", "fatal", "warn", "info", "debug", "trace"].concat(m);
|
|
128
|
+
typeof n == "function" && g.forEach(function(c) {
|
|
129
|
+
n[c] = n;
|
|
130
|
+
}), (t.enabled === !1 || t.browser.disabled) && (t.level = "silent");
|
|
131
|
+
const u = t.level || "info", i = Object.create(n);
|
|
132
|
+
i.log || (i.log = ne), nt(i, g, n), ke({}, i), Object.defineProperty(i, "levelVal", {
|
|
133
|
+
get: v
|
|
134
|
+
}), Object.defineProperty(i, "level", {
|
|
135
|
+
get: z,
|
|
136
|
+
set: x
|
|
137
|
+
});
|
|
138
|
+
const p = {
|
|
139
|
+
transmit: e,
|
|
140
|
+
serialize: s,
|
|
141
|
+
asObject: t.browser.asObject,
|
|
142
|
+
asObjectBindingsOnly: t.browser.asObjectBindingsOnly,
|
|
143
|
+
formatters: t.browser.formatters,
|
|
144
|
+
levels: g,
|
|
145
|
+
timestamp: ht(t),
|
|
146
|
+
messageKey: t.messageKey || "msg",
|
|
147
|
+
onChild: t.onChild || ne
|
|
148
|
+
};
|
|
149
|
+
i.levels = it(t), i.level = u, i.isLevelEnabled = function(c) {
|
|
150
|
+
return this.levels.values[c] ? this.levels.values[c] >= this.levels.values[this.level] : !1;
|
|
151
|
+
}, i.setMaxListeners = i.getMaxListeners = i.emit = i.addListener = i.on = i.prependListener = i.once = i.prependOnceListener = i.removeListener = i.removeAllListeners = i.listeners = i.listenerCount = i.eventNames = i.write = i.flush = ne, i.serializers = r, i._serialize = s, i._stdErrSerialize = l, i.child = function(...c) {
|
|
152
|
+
return o.call(this, p, ...c);
|
|
153
|
+
}, e && (i._logEvent = ye());
|
|
154
|
+
function v() {
|
|
155
|
+
return Y(this.level, this);
|
|
156
|
+
}
|
|
157
|
+
function z() {
|
|
158
|
+
return this._level;
|
|
159
|
+
}
|
|
160
|
+
function x(c) {
|
|
161
|
+
if (c !== "silent" && !this.levels.values[c])
|
|
162
|
+
throw Error("unknown level " + c);
|
|
163
|
+
this._level = c, Z(this, p, i, "error"), Z(this, p, i, "fatal"), Z(this, p, i, "warn"), Z(this, p, i, "info"), Z(this, p, i, "debug"), Z(this, p, i, "trace"), m.forEach((f) => {
|
|
164
|
+
Z(this, p, i, f);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function o(c, f, h) {
|
|
168
|
+
if (!f)
|
|
169
|
+
throw new Error("missing bindings for child Pino");
|
|
170
|
+
h = h || {}, s && f.serializers && (h.serializers = f.serializers);
|
|
171
|
+
const d = h.serializers;
|
|
172
|
+
if (s && d) {
|
|
173
|
+
var T = Object.assign({}, r, d), V = t.browser.serialize === !0 ? Object.keys(T) : s;
|
|
174
|
+
delete f.serializers, Ee([f], V, T, this._stdErrSerialize);
|
|
175
|
+
}
|
|
176
|
+
function A(_) {
|
|
177
|
+
this._childLevel = (_._childLevel | 0) + 1, this.bindings = f, T && (this.serializers = T, this._serialize = V), e && (this._logEvent = ye(
|
|
178
|
+
[].concat(_._logEvent.bindings, f)
|
|
179
|
+
));
|
|
180
|
+
}
|
|
181
|
+
A.prototype = this;
|
|
182
|
+
const I = new A(this);
|
|
183
|
+
return ke(this, I), I.child = function(..._) {
|
|
184
|
+
return o.call(this, c, ..._);
|
|
185
|
+
}, I.level = h.level || this.level, c.onChild(I), I;
|
|
186
|
+
}
|
|
187
|
+
return i;
|
|
188
|
+
}
|
|
189
|
+
function it(t) {
|
|
190
|
+
const e = t.customLevels || {}, n = Object.assign({}, K.levels.values, e), r = Object.assign({}, K.levels.labels, st(e));
|
|
191
|
+
return {
|
|
192
|
+
values: n,
|
|
193
|
+
labels: r
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function st(t) {
|
|
197
|
+
const e = {};
|
|
198
|
+
return Object.keys(t).forEach(function(n) {
|
|
199
|
+
e[t[n]] = n;
|
|
200
|
+
}), e;
|
|
201
|
+
}
|
|
202
|
+
K.levels = {
|
|
203
|
+
values: {
|
|
204
|
+
fatal: 60,
|
|
205
|
+
error: 50,
|
|
206
|
+
warn: 40,
|
|
207
|
+
info: 30,
|
|
208
|
+
debug: 20,
|
|
209
|
+
trace: 10
|
|
210
|
+
},
|
|
211
|
+
labels: {
|
|
212
|
+
10: "trace",
|
|
213
|
+
20: "debug",
|
|
214
|
+
30: "info",
|
|
215
|
+
40: "warn",
|
|
216
|
+
50: "error",
|
|
217
|
+
60: "fatal"
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
K.stdSerializers = et;
|
|
221
|
+
K.stdTimeFunctions = Object.assign({}, { nullTime: De, epochTime: Me, unixTime: ft, isoTime: dt });
|
|
222
|
+
function ot(t) {
|
|
223
|
+
const e = [];
|
|
224
|
+
t.bindings && e.push(t.bindings);
|
|
225
|
+
let n = t[be];
|
|
226
|
+
for (; n.parent; )
|
|
227
|
+
n = n.parent, n.logger.bindings && e.push(n.logger.bindings);
|
|
228
|
+
return e.reverse();
|
|
229
|
+
}
|
|
230
|
+
function Z(t, e, n, r) {
|
|
231
|
+
if (Object.defineProperty(t, r, {
|
|
232
|
+
value: Y(t.level, n) > Y(r, n) ? ne : n[xe][r],
|
|
233
|
+
writable: !0,
|
|
234
|
+
enumerable: !0,
|
|
235
|
+
configurable: !0
|
|
236
|
+
}), t[r] === ne) {
|
|
237
|
+
if (!e.transmit) return;
|
|
238
|
+
const l = e.transmit.level || t.level, m = Y(l, n);
|
|
239
|
+
if (Y(r, n) < m) return;
|
|
240
|
+
}
|
|
241
|
+
t[r] = ct(t, e, n, r);
|
|
242
|
+
const s = ot(t);
|
|
243
|
+
s.length !== 0 && (t[r] = at(s, t[r]));
|
|
244
|
+
}
|
|
245
|
+
function at(t, e) {
|
|
246
|
+
return function() {
|
|
247
|
+
return e.apply(this, [...t, ...arguments]);
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function ct(t, e, n, r) {
|
|
251
|
+
return /* @__PURE__ */ function(s) {
|
|
252
|
+
return function() {
|
|
253
|
+
const m = e.timestamp(), g = new Array(arguments.length), u = Object.getPrototypeOf && Object.getPrototypeOf(this) === re ? re : this;
|
|
254
|
+
for (var i = 0; i < g.length; i++) g[i] = arguments[i];
|
|
255
|
+
var p = !1;
|
|
256
|
+
if (e.serialize && (Ee(g, this._serialize, this.serializers, this._stdErrSerialize), p = !0), e.asObject || e.formatters ? s.call(u, ...lt(this, r, g, m, e)) : s.apply(u, g), e.transmit) {
|
|
257
|
+
const v = e.transmit.level || t._level, z = Y(v, n), x = Y(r, n);
|
|
258
|
+
if (x < z) return;
|
|
259
|
+
ut(this, {
|
|
260
|
+
ts: m,
|
|
261
|
+
methodLevel: r,
|
|
262
|
+
methodValue: x,
|
|
263
|
+
transmitValue: n.levels.values[e.transmit.level || t._level],
|
|
264
|
+
send: e.transmit.send,
|
|
265
|
+
val: Y(t._level, n)
|
|
266
|
+
}, g, p);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
}(t[xe][r]);
|
|
270
|
+
}
|
|
271
|
+
function lt(t, e, n, r, s) {
|
|
272
|
+
const {
|
|
273
|
+
level: l,
|
|
274
|
+
log: m = (v) => v
|
|
275
|
+
} = s.formatters || {}, g = n.slice();
|
|
276
|
+
let u = g[0];
|
|
277
|
+
const i = {};
|
|
278
|
+
let p = (t._childLevel | 0) + 1;
|
|
279
|
+
if (p < 1 && (p = 1), r && (i.time = r), l) {
|
|
280
|
+
const v = l(e, t.levels.values[e]);
|
|
281
|
+
Object.assign(i, v);
|
|
282
|
+
} else
|
|
283
|
+
i.level = t.levels.values[e];
|
|
284
|
+
if (s.asObjectBindingsOnly) {
|
|
285
|
+
if (u !== null && typeof u == "object")
|
|
286
|
+
for (; p-- && typeof g[0] == "object"; )
|
|
287
|
+
Object.assign(i, g.shift());
|
|
288
|
+
return [m(i), ...g];
|
|
289
|
+
} else {
|
|
290
|
+
if (u !== null && typeof u == "object") {
|
|
291
|
+
for (; p-- && typeof g[0] == "object"; )
|
|
292
|
+
Object.assign(i, g.shift());
|
|
293
|
+
u = g.length ? Le(g.shift(), g) : void 0;
|
|
294
|
+
} else typeof u == "string" && (u = Le(g.shift(), g));
|
|
295
|
+
return u !== void 0 && (i[s.messageKey] = u), [m(i)];
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function Ee(t, e, n, r) {
|
|
299
|
+
for (const s in t)
|
|
300
|
+
if (r && t[s] instanceof Error)
|
|
301
|
+
t[s] = K.stdSerializers.err(t[s]);
|
|
302
|
+
else if (typeof t[s] == "object" && !Array.isArray(t[s]) && e)
|
|
303
|
+
for (const l in t[s])
|
|
304
|
+
e.indexOf(l) > -1 && l in n && (t[s][l] = n[l](t[s][l]));
|
|
305
|
+
}
|
|
306
|
+
function ut(t, e, n, r = !1) {
|
|
307
|
+
const s = e.send, l = e.ts, m = e.methodLevel, g = e.methodValue, u = e.val, i = t._logEvent.bindings;
|
|
308
|
+
r || Ee(
|
|
309
|
+
n,
|
|
310
|
+
t._serialize || Object.keys(t.serializers),
|
|
311
|
+
t.serializers,
|
|
312
|
+
t._stdErrSerialize === void 0 ? !0 : t._stdErrSerialize
|
|
313
|
+
), t._logEvent.ts = l, t._logEvent.messages = n.filter(function(p) {
|
|
314
|
+
return i.indexOf(p) === -1;
|
|
315
|
+
}), t._logEvent.level.label = m, t._logEvent.level.value = g, s(m, t._logEvent, u), t._logEvent = ye(i);
|
|
316
|
+
}
|
|
317
|
+
function ye(t) {
|
|
318
|
+
return {
|
|
319
|
+
ts: 0,
|
|
320
|
+
messages: [],
|
|
321
|
+
bindings: t || [],
|
|
322
|
+
level: { label: "", value: 0 }
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
function _e(t) {
|
|
326
|
+
const e = {
|
|
327
|
+
type: t.constructor.name,
|
|
328
|
+
msg: t.message,
|
|
329
|
+
stack: t.stack
|
|
330
|
+
};
|
|
331
|
+
for (const n in t)
|
|
332
|
+
e[n] === void 0 && (e[n] = t[n]);
|
|
333
|
+
return e;
|
|
334
|
+
}
|
|
335
|
+
function ht(t) {
|
|
336
|
+
return typeof t.timestamp == "function" ? t.timestamp : t.timestamp === !1 ? De : Me;
|
|
337
|
+
}
|
|
338
|
+
function ie() {
|
|
339
|
+
return {};
|
|
340
|
+
}
|
|
341
|
+
function fe(t) {
|
|
342
|
+
return t;
|
|
343
|
+
}
|
|
344
|
+
function ne() {
|
|
345
|
+
}
|
|
346
|
+
function De() {
|
|
347
|
+
return !1;
|
|
348
|
+
}
|
|
349
|
+
function Me() {
|
|
350
|
+
return Date.now();
|
|
351
|
+
}
|
|
352
|
+
function ft() {
|
|
353
|
+
return Math.round(Date.now() / 1e3);
|
|
354
|
+
}
|
|
355
|
+
function dt() {
|
|
356
|
+
return new Date(Date.now()).toISOString();
|
|
357
|
+
}
|
|
358
|
+
function mt() {
|
|
359
|
+
function t(e) {
|
|
360
|
+
return typeof e < "u" && e;
|
|
361
|
+
}
|
|
362
|
+
try {
|
|
363
|
+
return typeof globalThis < "u" || Object.defineProperty(Object.prototype, "globalThis", {
|
|
364
|
+
get: function() {
|
|
365
|
+
return delete Object.prototype.globalThis, this.globalThis = this;
|
|
366
|
+
},
|
|
367
|
+
configurable: !0
|
|
368
|
+
}), globalThis;
|
|
369
|
+
} catch {
|
|
370
|
+
return t(self) || t(window) || t(this) || {};
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
ue.exports.default = K;
|
|
374
|
+
ue.exports.pino = K;
|
|
375
|
+
var gt = ue.exports;
|
|
376
|
+
const se = /* @__PURE__ */ Ge(gt);
|
|
377
|
+
function ce() {
|
|
378
|
+
return typeof process < "u" && process.env.NODE_ENV === "production";
|
|
379
|
+
}
|
|
380
|
+
function pt() {
|
|
381
|
+
var t;
|
|
382
|
+
return typeof process < "u" && ((t = process.versions) == null ? void 0 : t.node) !== void 0;
|
|
383
|
+
}
|
|
384
|
+
function vt() {
|
|
385
|
+
return typeof window < "u" && typeof document < "u";
|
|
386
|
+
}
|
|
387
|
+
const de = {
|
|
388
|
+
name: "WSX",
|
|
389
|
+
level: ce() ? "info" : "debug",
|
|
390
|
+
pretty: !ce()
|
|
391
|
+
};
|
|
392
|
+
function bt(t = {}) {
|
|
393
|
+
const { name: e, level: n, pretty: r, pinoOptions: s } = { ...de, ...t }, l = {
|
|
394
|
+
name: e || de.name,
|
|
395
|
+
level: n || de.level,
|
|
396
|
+
...s
|
|
397
|
+
};
|
|
398
|
+
if (vt() && (l.browser = {
|
|
399
|
+
asObject: !1,
|
|
400
|
+
// Use console methods directly (default behavior)
|
|
401
|
+
write: void 0,
|
|
402
|
+
// Use default console write
|
|
403
|
+
...(s == null ? void 0 : s.browser) || {}
|
|
404
|
+
// Allow override via pinoOptions
|
|
405
|
+
}), r && pt() && !ce())
|
|
406
|
+
try {
|
|
407
|
+
return se(
|
|
408
|
+
l,
|
|
409
|
+
se.transport({
|
|
410
|
+
target: "pino-pretty",
|
|
411
|
+
options: {
|
|
412
|
+
colorize: !0,
|
|
413
|
+
translateTime: "HH:MM:ss.l",
|
|
414
|
+
ignore: "pid,hostname",
|
|
415
|
+
singleLine: !1
|
|
416
|
+
}
|
|
417
|
+
})
|
|
418
|
+
);
|
|
419
|
+
} catch {
|
|
420
|
+
return console.warn("[wsx-logger] pino-pretty not available, using default formatter"), se(l);
|
|
421
|
+
}
|
|
422
|
+
return se(l);
|
|
423
|
+
}
|
|
424
|
+
class Ne {
|
|
425
|
+
constructor(e = {}) {
|
|
426
|
+
this.isProd = ce(), this.pinoLogger = bt(e);
|
|
427
|
+
}
|
|
428
|
+
debug(e, ...n) {
|
|
429
|
+
this.isProd || (n.length > 0 ? this.pinoLogger.debug({ args: n }, e) : this.pinoLogger.debug(e));
|
|
430
|
+
}
|
|
431
|
+
info(e, ...n) {
|
|
432
|
+
this.isProd ? n.length > 0 ? this.pinoLogger.info({ args: n }, e) : this.pinoLogger.info(e) : n.length > 0 ? this.pinoLogger.info({ args: n }, e) : this.pinoLogger.info(e);
|
|
433
|
+
}
|
|
434
|
+
warn(e, ...n) {
|
|
435
|
+
n.length > 0 ? this.pinoLogger.warn({ args: n }, e) : this.pinoLogger.warn(e);
|
|
436
|
+
}
|
|
437
|
+
error(e, ...n) {
|
|
438
|
+
n.length > 0 ? this.pinoLogger.error({ args: n }, e) : this.pinoLogger.error(e);
|
|
439
|
+
}
|
|
440
|
+
fatal(e, ...n) {
|
|
441
|
+
n.length > 0 ? this.pinoLogger.fatal({ args: n }, e) : this.pinoLogger.fatal(e);
|
|
442
|
+
}
|
|
443
|
+
trace(e, ...n) {
|
|
444
|
+
this.isProd || (n.length > 0 ? this.pinoLogger.trace({ args: n }, e) : this.pinoLogger.trace(e));
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Get the underlying pino logger instance
|
|
448
|
+
*/
|
|
449
|
+
getPinoLogger() {
|
|
450
|
+
return this.pinoLogger;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
new Ne();
|
|
454
|
+
function he(t, e = {}) {
|
|
455
|
+
return new Ne({
|
|
456
|
+
...e,
|
|
457
|
+
name: e.name || `WSX:${t}`
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
const yt = he("RouterUtils"), te = class te {
|
|
461
|
+
/**
|
|
462
|
+
* 设置当前路由信息(由 WsxRouter 内部调用)
|
|
463
|
+
* @internal
|
|
464
|
+
*/
|
|
465
|
+
static _setCurrentRoute(e) {
|
|
466
|
+
te._currentRoute = e;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* 编程式导航
|
|
470
|
+
*/
|
|
471
|
+
static navigate(e, n = !1) {
|
|
472
|
+
n ? window.history.replaceState(null, "", e) : window.history.pushState(null, "", e), window.dispatchEvent(new PopStateEvent("popstate")), yt.debug(`Navigated to: ${e} (replace: ${n})`);
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* 获取当前路由信息
|
|
476
|
+
* 如果路由已匹配(由 WsxRouter 维护),则返回包含参数的路由信息
|
|
477
|
+
* 否则返回基础路由信息(参数为空对象)
|
|
478
|
+
*/
|
|
479
|
+
static getCurrentRoute() {
|
|
480
|
+
if (te._currentRoute)
|
|
481
|
+
return te._currentRoute;
|
|
482
|
+
const e = new URL(window.location.href);
|
|
483
|
+
return {
|
|
484
|
+
path: e.pathname,
|
|
485
|
+
params: {},
|
|
486
|
+
query: Object.fromEntries(e.searchParams.entries()),
|
|
487
|
+
hash: e.hash.slice(1)
|
|
488
|
+
// 移除 # 号
|
|
12
489
|
};
|
|
13
490
|
}
|
|
14
|
-
|
|
15
|
-
|
|
491
|
+
/**
|
|
492
|
+
* 解析路由路径,提取参数
|
|
493
|
+
*/
|
|
494
|
+
static parseRoute(e, n) {
|
|
495
|
+
var r;
|
|
496
|
+
if (e === n)
|
|
497
|
+
return {
|
|
498
|
+
route: e,
|
|
499
|
+
params: {},
|
|
500
|
+
exact: !0
|
|
501
|
+
};
|
|
502
|
+
if (e === "*")
|
|
503
|
+
return {
|
|
504
|
+
route: e,
|
|
505
|
+
params: {},
|
|
506
|
+
exact: !1
|
|
507
|
+
};
|
|
508
|
+
if (e.includes(":")) {
|
|
509
|
+
const s = ((r = e.match(/:([^/]+)/g)) == null ? void 0 : r.map((u) => u.slice(1))) || [], l = e.replace(/:[^/]+/g, "([^/]+)"), m = new RegExp(`^${l}$`), g = n.match(m);
|
|
510
|
+
if (g && s.length > 0) {
|
|
511
|
+
const u = {};
|
|
512
|
+
return s.forEach((i, p) => {
|
|
513
|
+
u[i] = g[p + 1];
|
|
514
|
+
}), {
|
|
515
|
+
route: e,
|
|
516
|
+
params: u,
|
|
517
|
+
exact: !0
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (e.endsWith("/*")) {
|
|
522
|
+
const s = e.slice(0, -2);
|
|
523
|
+
if (n.startsWith(s))
|
|
524
|
+
return {
|
|
525
|
+
route: e,
|
|
526
|
+
params: {},
|
|
527
|
+
exact: !1
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
return null;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* 构建路由路径,替换参数
|
|
534
|
+
*/
|
|
535
|
+
static buildPath(e, n = {}) {
|
|
536
|
+
let r = e;
|
|
537
|
+
return Object.entries(n).forEach(([s, l]) => {
|
|
538
|
+
r = r.replace(`:${s}`, encodeURIComponent(l));
|
|
539
|
+
}), r;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* 检查路由是否匹配当前路径
|
|
543
|
+
*/
|
|
544
|
+
static isRouteActive(e, n = !1) {
|
|
545
|
+
const r = window.location.pathname;
|
|
546
|
+
return n ? r === e : e === "/" ? r === "/" : r.startsWith(e);
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* 获取路由层级
|
|
550
|
+
*/
|
|
551
|
+
static getRouteDepth(e) {
|
|
552
|
+
return e.split("/").filter((n) => n.length > 0).length;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* 获取父级路由
|
|
556
|
+
*/
|
|
557
|
+
static getParentRoute(e) {
|
|
558
|
+
const n = e.split("/").filter((r) => r.length > 0);
|
|
559
|
+
return n.length <= 1 ? "/" : (n.pop(), "/" + n.join("/"));
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* 合并路由路径
|
|
563
|
+
*/
|
|
564
|
+
static joinPaths(...e) {
|
|
565
|
+
return e.map((n) => n.replace(/^\/+|\/+$/g, "")).filter((n) => n.length > 0).join("/").replace(/^/, "/");
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* 检查是否为外部链接
|
|
569
|
+
*/
|
|
570
|
+
static isExternalUrl(e) {
|
|
571
|
+
return /^https?:\/\//.test(e) || /^mailto:/.test(e) || /^tel:/.test(e);
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* 获取查询参数
|
|
575
|
+
*/
|
|
576
|
+
static getQueryParam(e) {
|
|
577
|
+
return new URL(window.location.href).searchParams.get(e);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* 设置查询参数
|
|
581
|
+
*/
|
|
582
|
+
static setQueryParam(e, n, r = !1) {
|
|
583
|
+
const s = new URL(window.location.href);
|
|
584
|
+
s.searchParams.set(e, n);
|
|
585
|
+
const l = s.pathname + s.search + s.hash;
|
|
586
|
+
this.navigate(l, r);
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* 删除查询参数
|
|
590
|
+
*/
|
|
591
|
+
static removeQueryParam(e, n = !1) {
|
|
592
|
+
const r = new URL(window.location.href);
|
|
593
|
+
r.searchParams.delete(e);
|
|
594
|
+
const s = r.pathname + r.search + r.hash;
|
|
595
|
+
this.navigate(s, n);
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* 返回上一页
|
|
599
|
+
*/
|
|
600
|
+
static goBack() {
|
|
601
|
+
window.history.back();
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* 前进一页
|
|
605
|
+
*/
|
|
606
|
+
static goForward() {
|
|
607
|
+
window.history.forward();
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* 替换当前页面
|
|
611
|
+
*/
|
|
612
|
+
static replace(e) {
|
|
613
|
+
this.navigate(e, !0);
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* 获取历史记录长度
|
|
617
|
+
*/
|
|
618
|
+
static getHistoryLength() {
|
|
619
|
+
return window.history.length;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* 监听路由变化
|
|
623
|
+
*
|
|
624
|
+
* 只监听 route-changed 事件,该事件在 RouterUtils._setCurrentRoute() 之后触发。
|
|
625
|
+
* 不监听 popstate 事件,因为:
|
|
626
|
+
* 1. WsxRouter 已经监听 popstate 并会触发 route-changed
|
|
627
|
+
* 2. 同时监听两个事件会导致回调被调用两次,产生竞态条件
|
|
628
|
+
* 3. popstate 触发时 RouterUtils._currentRoute 可能还未更新
|
|
629
|
+
*
|
|
630
|
+
* @see RFC-0035: 路由导航竞态条件修复
|
|
631
|
+
*/
|
|
632
|
+
static onRouteChange(e) {
|
|
633
|
+
const n = () => {
|
|
634
|
+
const r = this.getCurrentRoute();
|
|
635
|
+
e(r);
|
|
636
|
+
};
|
|
637
|
+
return document.addEventListener("route-changed", n), () => {
|
|
638
|
+
document.removeEventListener("route-changed", n);
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
te._currentRoute = null;
|
|
643
|
+
let le = te;
|
|
644
|
+
const $e = ":host{display:grid;width:100%}.router-outlet{width:100%}:host>wsx-view{grid-area:1 / 1}";
|
|
645
|
+
var qe;
|
|
646
|
+
let Fe, He;
|
|
647
|
+
function U(t, e, n) {
|
|
648
|
+
return (e = Ue(e)) in t ? Object.defineProperty(t, e, { value: n, enumerable: !0, configurable: !0, writable: !0 }) : t[e] = n, t;
|
|
649
|
+
}
|
|
650
|
+
function wt(t, e, n, r, s, l) {
|
|
651
|
+
function m(o, c, f) {
|
|
652
|
+
return function(h, d) {
|
|
653
|
+
return f && f(h), o[c].call(h, d);
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
function g(o, c) {
|
|
657
|
+
for (var f = 0; f < o.length; f++) o[f].call(c);
|
|
16
658
|
return c;
|
|
17
659
|
}
|
|
18
|
-
function
|
|
19
|
-
if (typeof
|
|
20
|
-
return
|
|
660
|
+
function u(o, c, f, h) {
|
|
661
|
+
if (typeof o != "function" && (h || o !== void 0)) throw new TypeError(c + " must " + (f || "be") + " a function" + (h ? "" : " or undefined"));
|
|
662
|
+
return o;
|
|
21
663
|
}
|
|
22
|
-
function
|
|
23
|
-
function
|
|
24
|
-
if (!
|
|
664
|
+
function i(o, c, f, h, d, T, V, A, I, _, k, E, R) {
|
|
665
|
+
function j(b) {
|
|
666
|
+
if (!R(b)) throw new TypeError("Attempted to access private element on non-instance");
|
|
25
667
|
}
|
|
26
|
-
var
|
|
27
|
-
if (!
|
|
28
|
-
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
return
|
|
32
|
-
},
|
|
33
|
-
c[4](this,
|
|
34
|
-
} } :
|
|
668
|
+
var y, C = c[0], O = c[3], P = !A;
|
|
669
|
+
if (!P) {
|
|
670
|
+
f || Array.isArray(C) || (C = [C]);
|
|
671
|
+
var a = {}, S = [], L = d === 3 ? "get" : d === 4 || E ? "set" : "value";
|
|
672
|
+
_ ? (k || E ? a = { get: je(function() {
|
|
673
|
+
return O(this);
|
|
674
|
+
}, h, "get"), set: function(b) {
|
|
675
|
+
c[4](this, b);
|
|
676
|
+
} } : a[L] = O, k || je(a[L], h, d === 2 ? "" : L)) : k || (a = Object.getOwnPropertyDescriptor(o, h));
|
|
35
677
|
}
|
|
36
|
-
for (var
|
|
37
|
-
var
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
}).bind(null,
|
|
678
|
+
for (var w = o, q = C.length - 1; q >= 0; q -= f ? 2 : 1) {
|
|
679
|
+
var J = C[q], Q = f ? C[q - 1] : void 0, G = {}, D = { kind: ["field", "accessor", "method", "getter", "setter", "class"][d], name: h, metadata: T, addInitializer: (function(b, W) {
|
|
680
|
+
if (b.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
681
|
+
u(W, "An initializer", "be", !0), V.push(W);
|
|
682
|
+
}).bind(null, G) };
|
|
41
683
|
try {
|
|
42
|
-
if (
|
|
684
|
+
if (P) (y = u(J.call(Q, w, D), "class decorators", "return")) && (w = y);
|
|
43
685
|
else {
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
return
|
|
47
|
-
} : (
|
|
48
|
-
return
|
|
49
|
-
}, (
|
|
50
|
-
|
|
686
|
+
var M, F;
|
|
687
|
+
D.static = I, D.private = _, _ ? d === 2 ? M = function(b) {
|
|
688
|
+
return j(b), a.value;
|
|
689
|
+
} : (d < 4 && (M = m(a, "get", j)), d !== 3 && (F = m(a, "set", j))) : (M = function(b) {
|
|
690
|
+
return b[h];
|
|
691
|
+
}, (d < 2 || d === 4) && (F = function(b, W) {
|
|
692
|
+
b[h] = W;
|
|
51
693
|
}));
|
|
52
|
-
var
|
|
53
|
-
return
|
|
694
|
+
var X = D.access = { has: _ ? R.bind() : function(b) {
|
|
695
|
+
return h in b;
|
|
54
696
|
} };
|
|
55
|
-
if (
|
|
56
|
-
if (typeof
|
|
57
|
-
else if (
|
|
58
|
-
} else
|
|
697
|
+
if (M && (X.get = M), F && (X.set = F), w = J.call(Q, E ? { get: a.get, set: a.set } : a[L], D), E) {
|
|
698
|
+
if (typeof w == "object" && w) (y = u(w.get, "accessor.get")) && (a.get = y), (y = u(w.set, "accessor.set")) && (a.set = y), (y = u(w.init, "accessor.init")) && S.push(y);
|
|
699
|
+
else if (w !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
700
|
+
} else u(w, (k ? "field" : "method") + " decorators", "return") && (k ? S.push(w) : a[L] = w);
|
|
59
701
|
}
|
|
60
702
|
} finally {
|
|
61
|
-
|
|
703
|
+
G.v = !0;
|
|
62
704
|
}
|
|
63
705
|
}
|
|
64
|
-
return (
|
|
65
|
-
for (var
|
|
66
|
-
return
|
|
67
|
-
}),
|
|
68
|
-
}
|
|
69
|
-
function
|
|
70
|
-
return Object.defineProperty(
|
|
71
|
-
}
|
|
72
|
-
if (arguments.length >= 6) var
|
|
73
|
-
var
|
|
74
|
-
var
|
|
75
|
-
return
|
|
76
|
-
},
|
|
77
|
-
function
|
|
78
|
-
|
|
706
|
+
return (k || E) && A.push(function(b, W) {
|
|
707
|
+
for (var H = S.length - 1; H >= 0; H--) W = S[H].call(b, W);
|
|
708
|
+
return W;
|
|
709
|
+
}), k || P || (_ ? E ? A.push(m(a, "get"), m(a, "set")) : A.push(d === 2 ? a[L] : m.call.bind(a[L])) : Object.defineProperty(o, h, a)), w;
|
|
710
|
+
}
|
|
711
|
+
function p(o, c) {
|
|
712
|
+
return Object.defineProperty(o, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
|
|
713
|
+
}
|
|
714
|
+
if (arguments.length >= 6) var v = l[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
715
|
+
var z = Object.create(v ?? null), x = function(o, c, f, h) {
|
|
716
|
+
var d, T, V = [], A = function(L) {
|
|
717
|
+
return Et(L) === o;
|
|
718
|
+
}, I = /* @__PURE__ */ new Map();
|
|
719
|
+
function _(L) {
|
|
720
|
+
L && V.push(g.bind(null, L));
|
|
79
721
|
}
|
|
80
|
-
for (var
|
|
81
|
-
var
|
|
82
|
-
if (Array.isArray(
|
|
83
|
-
var
|
|
84
|
-
if (!
|
|
85
|
-
var
|
|
86
|
-
if (
|
|
87
|
-
|
|
722
|
+
for (var k = 0; k < c.length; k++) {
|
|
723
|
+
var E = c[k];
|
|
724
|
+
if (Array.isArray(E)) {
|
|
725
|
+
var R = E[1], j = E[2], y = E.length > 3, C = 16 & R, O = !!(8 & R), P = (R &= 7) == 0, a = j + "/" + O;
|
|
726
|
+
if (!P && !y) {
|
|
727
|
+
var S = I.get(a);
|
|
728
|
+
if (S === !0 || S === 3 && R !== 4 || S === 4 && R !== 3) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + j);
|
|
729
|
+
I.set(a, !(R > 2) || R);
|
|
88
730
|
}
|
|
89
|
-
|
|
731
|
+
i(O ? o : o.prototype, E, C, y ? "#" + j : Ue(j), R, h, O ? T = T || [] : d = d || [], V, O, y, P, R === 1, O && y ? A : f);
|
|
90
732
|
}
|
|
91
733
|
}
|
|
92
|
-
return
|
|
93
|
-
}(
|
|
94
|
-
return
|
|
95
|
-
var
|
|
96
|
-
return
|
|
734
|
+
return _(d), _(T), V;
|
|
735
|
+
}(t, e, s, z);
|
|
736
|
+
return n.length || p(t, z), { e: x, get c() {
|
|
737
|
+
var o = [];
|
|
738
|
+
return n.length && [p(i(t, [n], r, t.name, 5, z, o), z), g.bind(null, o, t)];
|
|
97
739
|
} };
|
|
98
740
|
}
|
|
99
|
-
function
|
|
100
|
-
var
|
|
101
|
-
return typeof
|
|
741
|
+
function Ue(t) {
|
|
742
|
+
var e = xt(t, "string");
|
|
743
|
+
return typeof e == "symbol" ? e : e + "";
|
|
102
744
|
}
|
|
103
|
-
function
|
|
104
|
-
if (typeof
|
|
105
|
-
var
|
|
106
|
-
if (
|
|
107
|
-
var
|
|
108
|
-
if (typeof
|
|
745
|
+
function xt(t, e) {
|
|
746
|
+
if (typeof t != "object" || !t) return t;
|
|
747
|
+
var n = t[Symbol.toPrimitive];
|
|
748
|
+
if (n !== void 0) {
|
|
749
|
+
var r = n.call(t, e);
|
|
750
|
+
if (typeof r != "object") return r;
|
|
109
751
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
110
752
|
}
|
|
111
|
-
return String(
|
|
753
|
+
return String(t);
|
|
112
754
|
}
|
|
113
|
-
function
|
|
114
|
-
typeof
|
|
755
|
+
function je(t, e, n) {
|
|
756
|
+
typeof e == "symbol" && (e = (e = e.description) ? "[" + e + "]" : "");
|
|
115
757
|
try {
|
|
116
|
-
Object.defineProperty(
|
|
758
|
+
Object.defineProperty(t, "name", { configurable: !0, value: n ? n + " " + e : e });
|
|
117
759
|
} catch {
|
|
118
760
|
}
|
|
119
|
-
return
|
|
761
|
+
return t;
|
|
120
762
|
}
|
|
121
|
-
function
|
|
122
|
-
if (Object(
|
|
123
|
-
return
|
|
763
|
+
function Et(t) {
|
|
764
|
+
if (Object(t) !== t) throw TypeError("right-hand side of 'in' should be an object, got " + (t !== null ? typeof t : "null"));
|
|
765
|
+
return t;
|
|
124
766
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
767
|
+
const $ = he("WsxRouter");
|
|
768
|
+
He = [we({
|
|
127
769
|
tagName: "wsx-router"
|
|
128
770
|
})];
|
|
129
|
-
let
|
|
130
|
-
class
|
|
771
|
+
let Rt;
|
|
772
|
+
class Lt extends oe {
|
|
131
773
|
constructor() {
|
|
132
774
|
super({
|
|
133
|
-
styles:
|
|
775
|
+
styles: $e,
|
|
134
776
|
styleName: "wsx-router"
|
|
135
|
-
}),
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
777
|
+
}), U(this, "_autoStyles", $e), U(this, "views", /* @__PURE__ */ new Map()), U(this, "currentView", null), U(this, "currentPath", ""), U(this, "isHandlingRoute", !1), U(this, "compiledRoutes", /* @__PURE__ */ new Map()), U(this, "matchCache", /* @__PURE__ */ new Map()), U(this, "enableViewTransitions", !0), U(this, "scrollRestoration", "manual"), U(this, "handleRouteChange", () => {
|
|
778
|
+
if (this.isHandlingRoute) {
|
|
779
|
+
$.debug("Route change already in progress, skipping");
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
this.views.size === 0 && (this.collectViews(), $.debug(`WsxRouter re-collected views: ${this.views.size}`)), this.isHandlingRoute = !0;
|
|
783
|
+
try {
|
|
784
|
+
const e = window.location.pathname;
|
|
785
|
+
$.debug(`WsxRouter: Route changed to: ${e}`);
|
|
786
|
+
const n = new CustomEvent("before-navigate", {
|
|
787
|
+
detail: {
|
|
788
|
+
to: e,
|
|
789
|
+
from: this.currentPath
|
|
790
|
+
},
|
|
791
|
+
bubbles: !0,
|
|
792
|
+
cancelable: !0
|
|
793
|
+
});
|
|
794
|
+
if (!this.dispatchEvent(n)) {
|
|
795
|
+
$.debug(`Navigation to ${e} was cancelled`);
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
this.performNavigation(e);
|
|
799
|
+
} finally {
|
|
800
|
+
requestAnimationFrame(() => {
|
|
801
|
+
this.isHandlingRoute = !1;
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
}), U(this, "interceptLinks", (e) => {
|
|
805
|
+
const n = e.target.closest("a");
|
|
806
|
+
if (!n) return;
|
|
807
|
+
const r = n.getAttribute("href");
|
|
808
|
+
!r || r.startsWith("http") || r.startsWith("#") || (e.preventDefault(), this.navigate(r));
|
|
158
809
|
});
|
|
159
810
|
}
|
|
160
811
|
render() {
|
|
161
|
-
return /* @__PURE__ */
|
|
812
|
+
return /* @__PURE__ */ ae("div", { class: "router-outlet" });
|
|
813
|
+
}
|
|
814
|
+
onRendered() {
|
|
815
|
+
this.views.size === 0 && (this.collectViews(), $.debug("WsxRouter collected views in onRendered:", this.views.size)), this.views.size > 0 && !this.currentView && requestAnimationFrame(() => {
|
|
816
|
+
this.handleRouteChange();
|
|
817
|
+
});
|
|
162
818
|
}
|
|
163
819
|
onConnected() {
|
|
164
|
-
|
|
820
|
+
$.debug("WsxRouter connected to DOM"), "scrollRestoration" in history && (history.scrollRestoration = this.scrollRestoration), window.addEventListener("popstate", this.handleRouteChange), this.addEventListener("click", this.interceptLinks), requestAnimationFrame(() => {
|
|
821
|
+
this.views.size === 0 && (this.collectViews(), $.debug(`WsxRouter collected views in onConnected: ${this.views.size}`)), requestAnimationFrame(() => {
|
|
822
|
+
$.debug(`WsxRouter handling initial route: ${window.location.pathname}`), this.handleRouteChange();
|
|
823
|
+
});
|
|
824
|
+
});
|
|
165
825
|
}
|
|
166
826
|
onDisconnected() {
|
|
167
827
|
window.removeEventListener("popstate", this.handleRouteChange);
|
|
168
828
|
}
|
|
169
829
|
collectViews() {
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
this.views.set(
|
|
830
|
+
const e = Array.from(this.children).filter((n) => n.tagName.toLowerCase() === "wsx-view");
|
|
831
|
+
$.debug(`WsxRouter found ${e.length} views`), this.views.clear(), this.compiledRoutes.clear(), this.matchCache.clear(), e.forEach((n) => {
|
|
832
|
+
const r = n.getAttribute("route") || "/";
|
|
833
|
+
if (this.views.set(r, n), $.debug(`WsxRouter registered route: ${r}`), r.includes(":")) {
|
|
834
|
+
const s = r.replace(/:[^/]+/g, "([^/]+)"), l = new RegExp(`^${s}$`);
|
|
835
|
+
this.compiledRoutes.set(r, l), $.debug(`WsxRouter compiled regex for route: ${r} -> ${l}`);
|
|
836
|
+
}
|
|
837
|
+
n.style.display = "none";
|
|
174
838
|
});
|
|
175
839
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
840
|
+
/**
|
|
841
|
+
* RFC 0033: 执行导航(带 View Transitions 支持)
|
|
842
|
+
*/
|
|
843
|
+
performNavigation(e) {
|
|
844
|
+
const n = () => {
|
|
845
|
+
const r = this.matchRoute(e);
|
|
846
|
+
if (r) {
|
|
847
|
+
r.style.display = "block", r.style.visibility = "visible";
|
|
848
|
+
const s = r.getAttribute("route") || "/";
|
|
849
|
+
$.debug(`Showing view for route: ${s}`);
|
|
850
|
+
for (const [p, v] of this.views)
|
|
851
|
+
v !== r && (v.style.display = "none", v.style.visibility = "");
|
|
852
|
+
this.currentView = r;
|
|
853
|
+
const l = this.extractParams(s, e);
|
|
854
|
+
$.debug(`Extracted params for route ${s} and path ${e}:`, l), l && requestAnimationFrame(() => {
|
|
855
|
+
r.setAttribute("params", JSON.stringify(l)), $.debug(`Set params attribute on view: ${JSON.stringify(l)}`);
|
|
856
|
+
});
|
|
857
|
+
const m = window.location.href || `${window.location.pathname}${window.location.search}${window.location.hash}`, g = new URL(m, window.location.origin || "http://localhost"), u = {
|
|
858
|
+
path: e,
|
|
859
|
+
params: l || {},
|
|
860
|
+
query: Object.fromEntries(g.searchParams.entries()),
|
|
861
|
+
hash: g.hash.slice(1)
|
|
862
|
+
};
|
|
863
|
+
le._setCurrentRoute(u), $.debug("Updated RouterUtils._currentRoute:", u);
|
|
864
|
+
const i = new CustomEvent("route-changed", {
|
|
865
|
+
detail: u,
|
|
866
|
+
bubbles: !0
|
|
867
|
+
});
|
|
868
|
+
document.dispatchEvent(i);
|
|
869
|
+
} else {
|
|
870
|
+
for (const [u, i] of this.views)
|
|
871
|
+
i.style.display = "none";
|
|
872
|
+
this.currentView = null, $.warn(`No view found for path: ${e}`);
|
|
873
|
+
const s = window.location.href || `${window.location.pathname}${window.location.search}${window.location.hash}`, l = new URL(s, window.location.origin || "http://localhost"), m = {
|
|
874
|
+
path: e,
|
|
875
|
+
params: {},
|
|
876
|
+
query: Object.fromEntries(l.searchParams.entries()),
|
|
877
|
+
hash: l.hash.slice(1)
|
|
878
|
+
};
|
|
879
|
+
le._setCurrentRoute(m);
|
|
880
|
+
const g = new CustomEvent("route-changed", {
|
|
881
|
+
detail: m,
|
|
882
|
+
bubbles: !0
|
|
883
|
+
});
|
|
884
|
+
document.dispatchEvent(g);
|
|
885
|
+
}
|
|
886
|
+
this.handleScrollRestoration(e), this.dispatchEvent(new CustomEvent("after-navigate", {
|
|
887
|
+
detail: {
|
|
888
|
+
to: e,
|
|
889
|
+
from: this.currentPath
|
|
890
|
+
},
|
|
891
|
+
bubbles: !0
|
|
892
|
+
})), this.currentPath = e;
|
|
893
|
+
};
|
|
894
|
+
this.enableViewTransitions && "startViewTransition" in document ? document.startViewTransition(n) : n();
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* RFC 0033: 滚动恢复处理
|
|
898
|
+
*/
|
|
899
|
+
handleScrollRestoration(e) {
|
|
900
|
+
this.scrollRestoration === "manual" && (this.isBackNavigation() || (window.scrollTo(0, 0), $.debug("Scrolled to top for forward navigation")));
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* RFC 0033: 检测是否是后退导航
|
|
904
|
+
*/
|
|
905
|
+
isBackNavigation() {
|
|
906
|
+
var e;
|
|
907
|
+
return "navigation" in performance && performance.navigation ? performance.navigation.type === 2 : ((e = window.history.state) == null ? void 0 : e.navigationType) === "back";
|
|
908
|
+
}
|
|
909
|
+
matchRoute(e) {
|
|
910
|
+
if ($.warn(`matchRoute called for path: ${e}, views count: ${this.views.size}`), this.matchCache.has(e)) {
|
|
911
|
+
const r = this.matchCache.get(e);
|
|
912
|
+
return $.warn(`matchRoute: found in cache, route: ${r}`), this.views.get(r) || null;
|
|
913
|
+
}
|
|
914
|
+
if (this.views.has(e))
|
|
915
|
+
return this.matchCache.set(e, e), $.warn(`matchRoute: exact match found for ${e}`), this.views.get(e);
|
|
916
|
+
$.warn(`matchRoute: checking parameter routes, compiledRoutes count: ${this.compiledRoutes.size}`);
|
|
917
|
+
for (const [r, s] of this.views)
|
|
918
|
+
if (r.includes(":")) {
|
|
919
|
+
const l = this.compiledRoutes.get(r);
|
|
920
|
+
if (l) {
|
|
921
|
+
const m = l.test(e);
|
|
922
|
+
if ($.warn(`matchRoute: testing route ${r} against ${e}, matches: ${m}`), m)
|
|
923
|
+
return this.matchCache.set(e, r), $.warn(`matchRoute: parameter match found, route: ${r}, path: ${e}`), s;
|
|
924
|
+
} else
|
|
925
|
+
$.warn(`matchRoute: route ${r} has ':' but no compiled regex found`);
|
|
184
926
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
927
|
+
const n = this.views.get("*") || null;
|
|
928
|
+
return n ? (this.matchCache.set(e, "*"), $.warn(`matchRoute: wildcard match found for ${e}`)) : $.warn(`matchRoute: no match found for ${e}, no wildcard view available`), n;
|
|
929
|
+
}
|
|
930
|
+
extractParams(e, n) {
|
|
931
|
+
var u;
|
|
932
|
+
if (!e.includes(":")) return null;
|
|
933
|
+
const r = ((u = e.match(/:([^/]+)/g)) == null ? void 0 : u.map((i) => i.slice(1))) || [], s = e.replace(/:[^/]+/g, "([^/]+)"), l = new RegExp(`^${s}$`), m = n.match(l);
|
|
934
|
+
if (!m || !r.length) return null;
|
|
935
|
+
const g = {};
|
|
936
|
+
return r.forEach((i, p) => {
|
|
937
|
+
g[i] = m[p + 1];
|
|
938
|
+
}), g;
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* RFC 0032: 清除匹配缓存
|
|
942
|
+
* 当路由配置变更时调用,确保使用最新的路由规则
|
|
943
|
+
*/
|
|
944
|
+
clearMatchCache() {
|
|
945
|
+
this.matchCache.clear(), $.debug("WsxRouter cleared match cache");
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* RFC 0033: 配置 View Transitions
|
|
949
|
+
*/
|
|
950
|
+
setViewTransitions(e) {
|
|
951
|
+
this.enableViewTransitions = e, $.debug(`View Transitions ${e ? "enabled" : "disabled"}`);
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* RFC 0033: 配置 Scroll Restoration
|
|
955
|
+
*/
|
|
956
|
+
setScrollRestoration(e) {
|
|
957
|
+
this.scrollRestoration = e, "scrollRestoration" in history && (history.scrollRestoration = e), $.debug(`Scroll Restoration set to ${e}`);
|
|
196
958
|
}
|
|
197
959
|
/**
|
|
198
960
|
* 编程式导航 - 使用原生 History API
|
|
199
961
|
*/
|
|
200
|
-
navigate(
|
|
201
|
-
window.history.pushState(null, "",
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
[
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
var
|
|
209
|
-
let
|
|
210
|
-
function
|
|
211
|
-
return (
|
|
212
|
-
}
|
|
213
|
-
function
|
|
214
|
-
function
|
|
215
|
-
return function(
|
|
216
|
-
return
|
|
962
|
+
navigate(e) {
|
|
963
|
+
window.history.pushState(null, "", e), this.handleRouteChange();
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
qe = Lt;
|
|
967
|
+
[Rt, Fe] = wt(qe, [], He, 0, void 0, oe).c;
|
|
968
|
+
Fe();
|
|
969
|
+
const Ce = ":host{display:block;width:100%;height:100%}.route-view{width:100%;height:100%;position:relative}:host([loading]) .route-view{opacity:.5;transition:opacity .3s ease}:host([error]) .route-view{border:1px solid var(--error-color, #ff0000);padding:1rem}.route-view.entering{animation:fadeIn .3s ease-out}.route-view.leaving{animation:fadeOut .3s ease-in}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}@keyframes fadeOut{0%{opacity:1}to{opacity:0}}";
|
|
970
|
+
var me, ge;
|
|
971
|
+
let Oe, Be, Se;
|
|
972
|
+
function ee(t, e, n) {
|
|
973
|
+
return (e = Ke(e)) in t ? Object.defineProperty(t, e, { value: n, enumerable: !0, configurable: !0, writable: !0 }) : t[e] = n, t;
|
|
974
|
+
}
|
|
975
|
+
function kt(t, e, n, r, s, l) {
|
|
976
|
+
function m(o, c, f) {
|
|
977
|
+
return function(h, d) {
|
|
978
|
+
return f && f(h), o[c].call(h, d);
|
|
217
979
|
};
|
|
218
980
|
}
|
|
219
|
-
function
|
|
220
|
-
for (var
|
|
981
|
+
function g(o, c) {
|
|
982
|
+
for (var f = 0; f < o.length; f++) o[f].call(c);
|
|
221
983
|
return c;
|
|
222
984
|
}
|
|
223
|
-
function
|
|
224
|
-
if (typeof
|
|
225
|
-
return
|
|
985
|
+
function u(o, c, f, h) {
|
|
986
|
+
if (typeof o != "function" && (h || o !== void 0)) throw new TypeError(c + " must " + (f || "be") + " a function" + (h ? "" : " or undefined"));
|
|
987
|
+
return o;
|
|
226
988
|
}
|
|
227
|
-
function
|
|
228
|
-
function
|
|
229
|
-
if (!
|
|
989
|
+
function i(o, c, f, h, d, T, V, A, I, _, k, E, R) {
|
|
990
|
+
function j(b) {
|
|
991
|
+
if (!R(b)) throw new TypeError("Attempted to access private element on non-instance");
|
|
230
992
|
}
|
|
231
|
-
var
|
|
232
|
-
if (!
|
|
233
|
-
|
|
234
|
-
var
|
|
235
|
-
|
|
236
|
-
return
|
|
237
|
-
},
|
|
238
|
-
c[4](this,
|
|
239
|
-
} } :
|
|
993
|
+
var y, C = c[0], O = c[3], P = !A;
|
|
994
|
+
if (!P) {
|
|
995
|
+
f || Array.isArray(C) || (C = [C]);
|
|
996
|
+
var a = {}, S = [], L = d === 3 ? "get" : d === 4 || E ? "set" : "value";
|
|
997
|
+
_ ? (k || E ? a = { get: We(function() {
|
|
998
|
+
return O(this);
|
|
999
|
+
}, h, "get"), set: function(b) {
|
|
1000
|
+
c[4](this, b);
|
|
1001
|
+
} } : a[L] = O, k || We(a[L], h, d === 2 ? "" : L)) : k || (a = Object.getOwnPropertyDescriptor(o, h));
|
|
240
1002
|
}
|
|
241
|
-
for (var
|
|
242
|
-
var
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
}).bind(null,
|
|
1003
|
+
for (var w = o, q = C.length - 1; q >= 0; q -= f ? 2 : 1) {
|
|
1004
|
+
var J = C[q], Q = f ? C[q - 1] : void 0, G = {}, D = { kind: ["field", "accessor", "method", "getter", "setter", "class"][d], name: h, metadata: T, addInitializer: (function(b, W) {
|
|
1005
|
+
if (b.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
1006
|
+
u(W, "An initializer", "be", !0), V.push(W);
|
|
1007
|
+
}).bind(null, G) };
|
|
246
1008
|
try {
|
|
247
|
-
if (
|
|
1009
|
+
if (P) (y = u(J.call(Q, w, D), "class decorators", "return")) && (w = y);
|
|
248
1010
|
else {
|
|
249
|
-
var
|
|
250
|
-
|
|
251
|
-
return
|
|
252
|
-
} : (
|
|
253
|
-
return
|
|
254
|
-
}, (
|
|
255
|
-
|
|
1011
|
+
var M, F;
|
|
1012
|
+
D.static = I, D.private = _, _ ? d === 2 ? M = function(b) {
|
|
1013
|
+
return j(b), a.value;
|
|
1014
|
+
} : (d < 4 && (M = m(a, "get", j)), d !== 3 && (F = m(a, "set", j))) : (M = function(b) {
|
|
1015
|
+
return b[h];
|
|
1016
|
+
}, (d < 2 || d === 4) && (F = function(b, W) {
|
|
1017
|
+
b[h] = W;
|
|
256
1018
|
}));
|
|
257
|
-
var
|
|
258
|
-
return
|
|
1019
|
+
var X = D.access = { has: _ ? R.bind() : function(b) {
|
|
1020
|
+
return h in b;
|
|
259
1021
|
} };
|
|
260
|
-
if (
|
|
261
|
-
if (typeof
|
|
262
|
-
else if (
|
|
263
|
-
} else
|
|
1022
|
+
if (M && (X.get = M), F && (X.set = F), w = J.call(Q, E ? { get: a.get, set: a.set } : a[L], D), E) {
|
|
1023
|
+
if (typeof w == "object" && w) (y = u(w.get, "accessor.get")) && (a.get = y), (y = u(w.set, "accessor.set")) && (a.set = y), (y = u(w.init, "accessor.init")) && S.push(y);
|
|
1024
|
+
else if (w !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
1025
|
+
} else u(w, (k ? "field" : "method") + " decorators", "return") && (k ? S.push(w) : a[L] = w);
|
|
264
1026
|
}
|
|
265
1027
|
} finally {
|
|
266
|
-
|
|
1028
|
+
G.v = !0;
|
|
267
1029
|
}
|
|
268
1030
|
}
|
|
269
|
-
return (
|
|
270
|
-
for (var
|
|
271
|
-
return
|
|
272
|
-
}),
|
|
273
|
-
}
|
|
274
|
-
function
|
|
275
|
-
return Object.defineProperty(
|
|
276
|
-
}
|
|
277
|
-
if (arguments.length >= 6) var
|
|
278
|
-
var
|
|
279
|
-
var
|
|
280
|
-
return
|
|
281
|
-
},
|
|
282
|
-
function
|
|
283
|
-
|
|
1031
|
+
return (k || E) && A.push(function(b, W) {
|
|
1032
|
+
for (var H = S.length - 1; H >= 0; H--) W = S[H].call(b, W);
|
|
1033
|
+
return W;
|
|
1034
|
+
}), k || P || (_ ? E ? A.push(m(a, "get"), m(a, "set")) : A.push(d === 2 ? a[L] : m.call.bind(a[L])) : Object.defineProperty(o, h, a)), w;
|
|
1035
|
+
}
|
|
1036
|
+
function p(o, c) {
|
|
1037
|
+
return Object.defineProperty(o, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
|
|
1038
|
+
}
|
|
1039
|
+
if (arguments.length >= 6) var v = l[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
1040
|
+
var z = Object.create(v ?? null), x = function(o, c, f, h) {
|
|
1041
|
+
var d, T, V = [], A = function(L) {
|
|
1042
|
+
return $t(L) === o;
|
|
1043
|
+
}, I = /* @__PURE__ */ new Map();
|
|
1044
|
+
function _(L) {
|
|
1045
|
+
L && V.push(g.bind(null, L));
|
|
284
1046
|
}
|
|
285
|
-
for (var
|
|
286
|
-
var
|
|
287
|
-
if (Array.isArray(
|
|
288
|
-
var
|
|
289
|
-
if (!
|
|
290
|
-
var
|
|
291
|
-
if (
|
|
292
|
-
|
|
1047
|
+
for (var k = 0; k < c.length; k++) {
|
|
1048
|
+
var E = c[k];
|
|
1049
|
+
if (Array.isArray(E)) {
|
|
1050
|
+
var R = E[1], j = E[2], y = E.length > 3, C = 16 & R, O = !!(8 & R), P = (R &= 7) == 0, a = j + "/" + O;
|
|
1051
|
+
if (!P && !y) {
|
|
1052
|
+
var S = I.get(a);
|
|
1053
|
+
if (S === !0 || S === 3 && R !== 4 || S === 4 && R !== 3) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + j);
|
|
1054
|
+
I.set(a, !(R > 2) || R);
|
|
293
1055
|
}
|
|
294
|
-
|
|
1056
|
+
i(O ? o : o.prototype, E, C, y ? "#" + j : Ke(j), R, h, O ? T = T || [] : d = d || [], V, O, y, P, R === 1, O && y ? A : f);
|
|
295
1057
|
}
|
|
296
1058
|
}
|
|
297
|
-
return
|
|
298
|
-
}(
|
|
299
|
-
return
|
|
300
|
-
var
|
|
301
|
-
return
|
|
1059
|
+
return _(d), _(T), V;
|
|
1060
|
+
}(t, e, s, z);
|
|
1061
|
+
return n.length || p(t, z), { e: x, get c() {
|
|
1062
|
+
var o = [];
|
|
1063
|
+
return n.length && [p(i(t, [n], r, t.name, 5, z, o), z), g.bind(null, o, t)];
|
|
302
1064
|
} };
|
|
303
1065
|
}
|
|
304
|
-
function
|
|
305
|
-
var
|
|
306
|
-
return typeof
|
|
1066
|
+
function Ke(t) {
|
|
1067
|
+
var e = _t(t, "string");
|
|
1068
|
+
return typeof e == "symbol" ? e : e + "";
|
|
307
1069
|
}
|
|
308
|
-
function
|
|
309
|
-
if (typeof
|
|
310
|
-
var
|
|
311
|
-
if (
|
|
312
|
-
var
|
|
313
|
-
if (typeof
|
|
1070
|
+
function _t(t, e) {
|
|
1071
|
+
if (typeof t != "object" || !t) return t;
|
|
1072
|
+
var n = t[Symbol.toPrimitive];
|
|
1073
|
+
if (n !== void 0) {
|
|
1074
|
+
var r = n.call(t, e);
|
|
1075
|
+
if (typeof r != "object") return r;
|
|
314
1076
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
315
1077
|
}
|
|
316
|
-
return (
|
|
1078
|
+
return (e === "string" ? String : Number)(t);
|
|
317
1079
|
}
|
|
318
|
-
function
|
|
319
|
-
typeof
|
|
1080
|
+
function We(t, e, n) {
|
|
1081
|
+
typeof e == "symbol" && (e = (e = e.description) ? "[" + e + "]" : "");
|
|
320
1082
|
try {
|
|
321
|
-
Object.defineProperty(
|
|
1083
|
+
Object.defineProperty(t, "name", { configurable: !0, value: n ? n + " " + e : e });
|
|
322
1084
|
} catch {
|
|
323
1085
|
}
|
|
324
|
-
return
|
|
1086
|
+
return t;
|
|
325
1087
|
}
|
|
326
|
-
function
|
|
327
|
-
if (Object(
|
|
328
|
-
return
|
|
1088
|
+
function $t(t) {
|
|
1089
|
+
if (Object(t) !== t) throw TypeError("right-hand side of 'in' should be an object, got " + (t !== null ? typeof t : "null"));
|
|
1090
|
+
return t;
|
|
329
1091
|
}
|
|
330
|
-
function
|
|
331
|
-
return
|
|
1092
|
+
function jt(t) {
|
|
1093
|
+
return t;
|
|
332
1094
|
}
|
|
333
|
-
const
|
|
334
|
-
|
|
1095
|
+
const N = he("WsxView");
|
|
1096
|
+
Be = [we({
|
|
335
1097
|
tagName: "wsx-view"
|
|
336
1098
|
})];
|
|
337
|
-
let
|
|
338
|
-
new (
|
|
1099
|
+
let ze;
|
|
1100
|
+
new (Se = (ge = class extends oe {
|
|
1101
|
+
// 防止重复加载的标志
|
|
339
1102
|
constructor() {
|
|
340
1103
|
super({
|
|
341
|
-
styles:
|
|
1104
|
+
styles: Ce,
|
|
342
1105
|
styleName: "wsx-view"
|
|
343
|
-
}),
|
|
1106
|
+
}), ee(this, "_autoStyles", Ce), ee(this, "component", null), ee(this, "params", {}), ee(this, "componentInstance", null), ee(this, "isLoading", !1);
|
|
344
1107
|
}
|
|
345
1108
|
render() {
|
|
346
|
-
return /* @__PURE__ */
|
|
1109
|
+
return /* @__PURE__ */ ae("div", { class: "route-view" });
|
|
347
1110
|
}
|
|
348
1111
|
onConnected() {
|
|
349
|
-
|
|
350
|
-
|
|
1112
|
+
requestAnimationFrame(() => {
|
|
1113
|
+
if (!this.connected || this.isLoading || this.componentInstance)
|
|
1114
|
+
return;
|
|
1115
|
+
const e = this.getAttribute("component");
|
|
1116
|
+
e && this.loadComponent(e);
|
|
1117
|
+
});
|
|
351
1118
|
}
|
|
352
|
-
onAttributeChanged(
|
|
353
|
-
if (
|
|
354
|
-
this.
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
this.params = JSON.parse(n), Object.entries(this.params).forEach(([g, C]) => {
|
|
358
|
-
this.componentInstance.setAttribute(g, C);
|
|
1119
|
+
onAttributeChanged(e, n, r) {
|
|
1120
|
+
if (this.connected) {
|
|
1121
|
+
if (e === "component" && r && !this.componentInstance && !this.isLoading)
|
|
1122
|
+
requestAnimationFrame(() => {
|
|
1123
|
+
this.connected && !this.componentInstance && !this.isLoading && this.loadComponent(r);
|
|
359
1124
|
});
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
1125
|
+
else if (e === "params" && this.componentInstance)
|
|
1126
|
+
try {
|
|
1127
|
+
this.params = JSON.parse(r), N.debug("WsxView: params attribute changed, setting on component:", this.params), Object.entries(this.params).forEach(([s, l]) => {
|
|
1128
|
+
this.componentInstance.setAttribute(s, l);
|
|
1129
|
+
}), N.debug(`WsxView: params set on component ${this.componentInstance.tagName}`);
|
|
1130
|
+
} catch (s) {
|
|
1131
|
+
N.warn("Failed to parse params:", s);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
363
1134
|
}
|
|
364
|
-
async loadComponent(
|
|
365
|
-
if (this.
|
|
366
|
-
|
|
1135
|
+
async loadComponent(e) {
|
|
1136
|
+
if (!this.connected || this.isLoading || this.componentInstance) {
|
|
1137
|
+
N.debug(`Skipping loadComponent for ${e}: connected=${this.connected}, isLoading=${this.isLoading}, hasInstance=${!!this.componentInstance}`);
|
|
367
1138
|
return;
|
|
368
1139
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
1140
|
+
N.debug(`WsxView: Loading component ${e}`), this.isLoading = !0;
|
|
1141
|
+
try {
|
|
1142
|
+
const n = this.componentInstance;
|
|
1143
|
+
if (n && (n.remove(), this.componentInstance = null), !customElements.get(e)) {
|
|
1144
|
+
N.warn(`Component ${e} not found in customElements registry`), this.isLoading = !1;
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
N.warn(`WsxView: Creating instance of ${e}`), this.componentInstance = document.createElement(e), Object.keys(this.params).length > 0 && (N.warn(`WsxView: Setting initial params on ${e}:`, this.params), Object.entries(this.params).forEach(([l, m]) => {
|
|
1148
|
+
this.componentInstance.setAttribute(l, m);
|
|
1149
|
+
}));
|
|
1150
|
+
const s = this.querySelector(".route-view");
|
|
1151
|
+
if (s) {
|
|
1152
|
+
if (N.warn(`WsxView: Appending ${e} to container`), !customElements.get(e)) {
|
|
1153
|
+
N.error(`WsxView: Component ${e} is not registered in customElements registry!`), this.isLoading = !1, this.componentInstance = null;
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
s.appendChild(this.componentInstance), N.warn(`WsxView: Component ${e} appended successfully, waiting for connectedCallback...`), setTimeout(() => {
|
|
1157
|
+
this.componentInstance && this.componentInstance.isConnected ? N.warn(`WsxView: Component ${e} is now connected to DOM`) : N.error(`WsxView: Component ${e} was not connected to DOM!`);
|
|
1158
|
+
}, 0);
|
|
1159
|
+
} else
|
|
1160
|
+
N.error("WsxView: Route view container not found"), this.componentInstance = null;
|
|
1161
|
+
} catch (n) {
|
|
1162
|
+
N.warn(`Error loading component ${e}:`, n), this.componentInstance = null;
|
|
1163
|
+
} finally {
|
|
1164
|
+
this.isLoading = !1, N.warn(`WsxView: loadComponent for ${e} completed, isLoading=${this.isLoading}`);
|
|
1165
|
+
}
|
|
374
1166
|
}
|
|
375
1167
|
onDisconnected() {
|
|
376
1168
|
this.componentInstance && (this.componentInstance.remove(), this.componentInstance = null);
|
|
377
1169
|
}
|
|
378
|
-
}, [
|
|
1170
|
+
}, [ze, Oe] = kt(ge, [], Be, 0, void 0, oe).c, ge), me = class extends jt {
|
|
379
1171
|
constructor() {
|
|
380
|
-
super(
|
|
381
|
-
}
|
|
382
|
-
},
|
|
383
|
-
const
|
|
384
|
-
var
|
|
385
|
-
let
|
|
386
|
-
function
|
|
387
|
-
return (
|
|
388
|
-
}
|
|
389
|
-
function
|
|
390
|
-
function
|
|
391
|
-
return function(
|
|
392
|
-
return
|
|
1172
|
+
super(ze), ee(this, "observedAttributes", ["route", "component", "params"]), Oe();
|
|
1173
|
+
}
|
|
1174
|
+
}, ee(me, Se, void 0), me)();
|
|
1175
|
+
const Ct = ':host{display:inline-block;min-width:fit-content;min-height:fit-content;width:auto;height:auto}.wsx-link{color:var(--link-color, #007bff);text-decoration:var(--link-decoration, underline);cursor:pointer;transition:color .2s ease;display:inline-block;min-height:1.2em;line-height:1.2}.wsx-link:hover{color:var(--link-hover-color, #0056b3);text-decoration:var(--link-hover-decoration, underline)}.wsx-link:focus{outline:2px solid var(--link-focus-color, var(--focus-color, #dc2626));outline-offset:2px}.wsx-link.active{color:var(--link-active-color, #6c757d);font-weight:var(--link-active-weight, bold)}:host([disabled]) .wsx-link{color:var(--link-disabled-color, #6c757d);cursor:not-allowed;pointer-events:none}:host([external]) .wsx-link:after{content:"↗";font-size:.8em;margin-left:.2em;opacity:.7}:host([variant="button"]) .wsx-link{background-color:var(--button-bg, #007bff);color:var(--button-color, white);padding:.5rem 1rem;border-radius:.25rem;text-decoration:none;display:inline-block}:host([variant="button"]) .wsx-link:hover{background-color:var(--button-hover-bg, #0056b3);color:var(--button-hover-color, white)}:host([variant="tab"]) .wsx-link{padding:.5rem 1rem;border-bottom:2px solid transparent;text-decoration:none}:host([variant="tab"]) .wsx-link.active{border-bottom-color:var(--tab-active-border, #007bff)}';
|
|
1176
|
+
var pe, ve;
|
|
1177
|
+
let Ae, Je, Te;
|
|
1178
|
+
function B(t, e, n) {
|
|
1179
|
+
return (e = Qe(e)) in t ? Object.defineProperty(t, e, { value: n, enumerable: !0, configurable: !0, writable: !0 }) : t[e] = n, t;
|
|
1180
|
+
}
|
|
1181
|
+
function Ot(t, e, n, r, s, l) {
|
|
1182
|
+
function m(o, c, f) {
|
|
1183
|
+
return function(h, d) {
|
|
1184
|
+
return f && f(h), o[c].call(h, d);
|
|
393
1185
|
};
|
|
394
1186
|
}
|
|
395
|
-
function
|
|
396
|
-
for (var
|
|
1187
|
+
function g(o, c) {
|
|
1188
|
+
for (var f = 0; f < o.length; f++) o[f].call(c);
|
|
397
1189
|
return c;
|
|
398
1190
|
}
|
|
399
|
-
function
|
|
400
|
-
if (typeof
|
|
401
|
-
return
|
|
1191
|
+
function u(o, c, f, h) {
|
|
1192
|
+
if (typeof o != "function" && (h || o !== void 0)) throw new TypeError(c + " must " + (f || "be") + " a function" + (h ? "" : " or undefined"));
|
|
1193
|
+
return o;
|
|
402
1194
|
}
|
|
403
|
-
function
|
|
404
|
-
function
|
|
405
|
-
if (!
|
|
1195
|
+
function i(o, c, f, h, d, T, V, A, I, _, k, E, R) {
|
|
1196
|
+
function j(b) {
|
|
1197
|
+
if (!R(b)) throw new TypeError("Attempted to access private element on non-instance");
|
|
406
1198
|
}
|
|
407
|
-
var
|
|
408
|
-
if (!
|
|
409
|
-
|
|
410
|
-
var
|
|
411
|
-
|
|
412
|
-
return
|
|
413
|
-
},
|
|
414
|
-
c[4](this,
|
|
415
|
-
} } :
|
|
1199
|
+
var y, C = c[0], O = c[3], P = !A;
|
|
1200
|
+
if (!P) {
|
|
1201
|
+
f || Array.isArray(C) || (C = [C]);
|
|
1202
|
+
var a = {}, S = [], L = d === 3 ? "get" : d === 4 || E ? "set" : "value";
|
|
1203
|
+
_ ? (k || E ? a = { get: Ve(function() {
|
|
1204
|
+
return O(this);
|
|
1205
|
+
}, h, "get"), set: function(b) {
|
|
1206
|
+
c[4](this, b);
|
|
1207
|
+
} } : a[L] = O, k || Ve(a[L], h, d === 2 ? "" : L)) : k || (a = Object.getOwnPropertyDescriptor(o, h));
|
|
416
1208
|
}
|
|
417
|
-
for (var
|
|
418
|
-
var
|
|
419
|
-
if (
|
|
420
|
-
|
|
421
|
-
}).bind(null,
|
|
1209
|
+
for (var w = o, q = C.length - 1; q >= 0; q -= f ? 2 : 1) {
|
|
1210
|
+
var J = C[q], Q = f ? C[q - 1] : void 0, G = {}, D = { kind: ["field", "accessor", "method", "getter", "setter", "class"][d], name: h, metadata: T, addInitializer: (function(b, W) {
|
|
1211
|
+
if (b.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
1212
|
+
u(W, "An initializer", "be", !0), V.push(W);
|
|
1213
|
+
}).bind(null, G) };
|
|
422
1214
|
try {
|
|
423
|
-
if (
|
|
1215
|
+
if (P) (y = u(J.call(Q, w, D), "class decorators", "return")) && (w = y);
|
|
424
1216
|
else {
|
|
425
|
-
var
|
|
426
|
-
|
|
427
|
-
return
|
|
428
|
-
} : (
|
|
429
|
-
return
|
|
430
|
-
}, (
|
|
431
|
-
|
|
1217
|
+
var M, F;
|
|
1218
|
+
D.static = I, D.private = _, _ ? d === 2 ? M = function(b) {
|
|
1219
|
+
return j(b), a.value;
|
|
1220
|
+
} : (d < 4 && (M = m(a, "get", j)), d !== 3 && (F = m(a, "set", j))) : (M = function(b) {
|
|
1221
|
+
return b[h];
|
|
1222
|
+
}, (d < 2 || d === 4) && (F = function(b, W) {
|
|
1223
|
+
b[h] = W;
|
|
432
1224
|
}));
|
|
433
|
-
var
|
|
434
|
-
return
|
|
1225
|
+
var X = D.access = { has: _ ? R.bind() : function(b) {
|
|
1226
|
+
return h in b;
|
|
435
1227
|
} };
|
|
436
|
-
if (
|
|
437
|
-
if (typeof
|
|
438
|
-
else if (
|
|
439
|
-
} else
|
|
1228
|
+
if (M && (X.get = M), F && (X.set = F), w = J.call(Q, E ? { get: a.get, set: a.set } : a[L], D), E) {
|
|
1229
|
+
if (typeof w == "object" && w) (y = u(w.get, "accessor.get")) && (a.get = y), (y = u(w.set, "accessor.set")) && (a.set = y), (y = u(w.init, "accessor.init")) && S.push(y);
|
|
1230
|
+
else if (w !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
1231
|
+
} else u(w, (k ? "field" : "method") + " decorators", "return") && (k ? S.push(w) : a[L] = w);
|
|
440
1232
|
}
|
|
441
1233
|
} finally {
|
|
442
|
-
|
|
1234
|
+
G.v = !0;
|
|
443
1235
|
}
|
|
444
1236
|
}
|
|
445
|
-
return (
|
|
446
|
-
for (var
|
|
447
|
-
return
|
|
448
|
-
}),
|
|
449
|
-
}
|
|
450
|
-
function
|
|
451
|
-
return Object.defineProperty(
|
|
452
|
-
}
|
|
453
|
-
if (arguments.length >= 6) var
|
|
454
|
-
var
|
|
455
|
-
var
|
|
456
|
-
return
|
|
457
|
-
},
|
|
458
|
-
function
|
|
459
|
-
|
|
1237
|
+
return (k || E) && A.push(function(b, W) {
|
|
1238
|
+
for (var H = S.length - 1; H >= 0; H--) W = S[H].call(b, W);
|
|
1239
|
+
return W;
|
|
1240
|
+
}), k || P || (_ ? E ? A.push(m(a, "get"), m(a, "set")) : A.push(d === 2 ? a[L] : m.call.bind(a[L])) : Object.defineProperty(o, h, a)), w;
|
|
1241
|
+
}
|
|
1242
|
+
function p(o, c) {
|
|
1243
|
+
return Object.defineProperty(o, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
|
|
1244
|
+
}
|
|
1245
|
+
if (arguments.length >= 6) var v = l[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
1246
|
+
var z = Object.create(v ?? null), x = function(o, c, f, h) {
|
|
1247
|
+
var d, T, V = [], A = function(L) {
|
|
1248
|
+
return Wt(L) === o;
|
|
1249
|
+
}, I = /* @__PURE__ */ new Map();
|
|
1250
|
+
function _(L) {
|
|
1251
|
+
L && V.push(g.bind(null, L));
|
|
460
1252
|
}
|
|
461
|
-
for (var
|
|
462
|
-
var
|
|
463
|
-
if (Array.isArray(
|
|
464
|
-
var
|
|
465
|
-
if (!
|
|
466
|
-
var
|
|
467
|
-
if (
|
|
468
|
-
|
|
1253
|
+
for (var k = 0; k < c.length; k++) {
|
|
1254
|
+
var E = c[k];
|
|
1255
|
+
if (Array.isArray(E)) {
|
|
1256
|
+
var R = E[1], j = E[2], y = E.length > 3, C = 16 & R, O = !!(8 & R), P = (R &= 7) == 0, a = j + "/" + O;
|
|
1257
|
+
if (!P && !y) {
|
|
1258
|
+
var S = I.get(a);
|
|
1259
|
+
if (S === !0 || S === 3 && R !== 4 || S === 4 && R !== 3) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + j);
|
|
1260
|
+
I.set(a, !(R > 2) || R);
|
|
469
1261
|
}
|
|
470
|
-
|
|
1262
|
+
i(O ? o : o.prototype, E, C, y ? "#" + j : Qe(j), R, h, O ? T = T || [] : d = d || [], V, O, y, P, R === 1, O && y ? A : f);
|
|
471
1263
|
}
|
|
472
1264
|
}
|
|
473
|
-
return
|
|
474
|
-
}(
|
|
475
|
-
return
|
|
476
|
-
var
|
|
477
|
-
return
|
|
1265
|
+
return _(d), _(T), V;
|
|
1266
|
+
}(t, e, s, z);
|
|
1267
|
+
return n.length || p(t, z), { e: x, get c() {
|
|
1268
|
+
var o = [];
|
|
1269
|
+
return n.length && [p(i(t, [n], r, t.name, 5, z, o), z), g.bind(null, o, t)];
|
|
478
1270
|
} };
|
|
479
1271
|
}
|
|
480
|
-
function
|
|
481
|
-
var
|
|
482
|
-
return typeof
|
|
1272
|
+
function Qe(t) {
|
|
1273
|
+
var e = St(t, "string");
|
|
1274
|
+
return typeof e == "symbol" ? e : e + "";
|
|
483
1275
|
}
|
|
484
|
-
function
|
|
485
|
-
if (typeof
|
|
486
|
-
var
|
|
487
|
-
if (
|
|
488
|
-
var
|
|
489
|
-
if (typeof
|
|
1276
|
+
function St(t, e) {
|
|
1277
|
+
if (typeof t != "object" || !t) return t;
|
|
1278
|
+
var n = t[Symbol.toPrimitive];
|
|
1279
|
+
if (n !== void 0) {
|
|
1280
|
+
var r = n.call(t, e);
|
|
1281
|
+
if (typeof r != "object") return r;
|
|
490
1282
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
491
1283
|
}
|
|
492
|
-
return (
|
|
1284
|
+
return (e === "string" ? String : Number)(t);
|
|
493
1285
|
}
|
|
494
|
-
function
|
|
495
|
-
typeof
|
|
1286
|
+
function Ve(t, e, n) {
|
|
1287
|
+
typeof e == "symbol" && (e = (e = e.description) ? "[" + e + "]" : "");
|
|
496
1288
|
try {
|
|
497
|
-
Object.defineProperty(
|
|
1289
|
+
Object.defineProperty(t, "name", { configurable: !0, value: n ? n + " " + e : e });
|
|
498
1290
|
} catch {
|
|
499
1291
|
}
|
|
500
|
-
return
|
|
1292
|
+
return t;
|
|
501
1293
|
}
|
|
502
|
-
function
|
|
503
|
-
if (Object(
|
|
504
|
-
return
|
|
1294
|
+
function Wt(t) {
|
|
1295
|
+
if (Object(t) !== t) throw TypeError("right-hand side of 'in' should be an object, got " + (t !== null ? typeof t : "null"));
|
|
1296
|
+
return t;
|
|
505
1297
|
}
|
|
506
|
-
function
|
|
507
|
-
return
|
|
1298
|
+
function zt(t) {
|
|
1299
|
+
return t;
|
|
508
1300
|
}
|
|
509
|
-
const
|
|
510
|
-
|
|
1301
|
+
const Ie = he("WsxLink");
|
|
1302
|
+
Je = [we({
|
|
511
1303
|
tagName: "wsx-link"
|
|
512
1304
|
})];
|
|
513
|
-
let
|
|
514
|
-
new (
|
|
1305
|
+
let Pe;
|
|
1306
|
+
new (Te = (ve = class extends Re {
|
|
515
1307
|
constructor() {
|
|
516
|
-
super(),
|
|
517
|
-
if (
|
|
518
|
-
|
|
1308
|
+
super(), B(this, "_autoStyles", Ct), B(this, "to", void 0), B(this, "replace", void 0), B(this, "activeClass", void 0), B(this, "exact", void 0), B(this, "handleClick", (i) => {
|
|
1309
|
+
if (i.preventDefault(), !this.to) {
|
|
1310
|
+
Ie.warn("No 'to' attribute specified");
|
|
519
1311
|
return;
|
|
520
1312
|
}
|
|
521
1313
|
if (this.isExternalLink(this.to)) {
|
|
522
1314
|
window.open(this.to, "_blank");
|
|
523
1315
|
return;
|
|
524
1316
|
}
|
|
525
|
-
this.replace ? window.history.replaceState(null, "", this.to) : window.history.pushState(null, "", this.to), window.dispatchEvent(new PopStateEvent("popstate")),
|
|
526
|
-
}),
|
|
527
|
-
var
|
|
528
|
-
const
|
|
529
|
-
|
|
1317
|
+
this.replace ? window.history.replaceState(null, "", this.to) : window.history.pushState(null, "", this.to), window.dispatchEvent(new PopStateEvent("popstate")), Ie.debug(`Navigated to: ${this.to}`);
|
|
1318
|
+
}), B(this, "updateActiveState", () => {
|
|
1319
|
+
var z;
|
|
1320
|
+
const i = window.location.pathname, p = this.exact ? i === this.to : i.startsWith(this.to) && this.to !== "/", v = (z = this.shadowRoot) == null ? void 0 : z.querySelector("a");
|
|
1321
|
+
v && (p ? (v.classList.add(this.activeClass), this.setAttribute("active", "")) : (v.classList.remove(this.activeClass), this.removeAttribute("active")));
|
|
530
1322
|
});
|
|
531
|
-
const [
|
|
1323
|
+
const [e, n] = this.useState("to", "");
|
|
532
1324
|
Object.defineProperty(this, "to", {
|
|
533
|
-
get:
|
|
534
|
-
set:
|
|
1325
|
+
get: e,
|
|
1326
|
+
set: n,
|
|
535
1327
|
enumerable: !0,
|
|
536
1328
|
configurable: !0
|
|
537
1329
|
});
|
|
538
|
-
const [
|
|
1330
|
+
const [r, s] = this.useState("replace", !1);
|
|
539
1331
|
Object.defineProperty(this, "replace", {
|
|
540
|
-
get:
|
|
541
|
-
set:
|
|
1332
|
+
get: r,
|
|
1333
|
+
set: s,
|
|
542
1334
|
enumerable: !0,
|
|
543
1335
|
configurable: !0
|
|
544
1336
|
});
|
|
545
|
-
const [
|
|
1337
|
+
const [l, m] = this.useState("activeClass", "active");
|
|
546
1338
|
Object.defineProperty(this, "activeClass", {
|
|
547
|
-
get:
|
|
548
|
-
set:
|
|
1339
|
+
get: l,
|
|
1340
|
+
set: m,
|
|
549
1341
|
enumerable: !0,
|
|
550
1342
|
configurable: !0
|
|
551
1343
|
});
|
|
552
|
-
const [
|
|
1344
|
+
const [g, u] = this.useState("exact", !1);
|
|
553
1345
|
Object.defineProperty(this, "exact", {
|
|
554
|
-
get:
|
|
555
|
-
set:
|
|
1346
|
+
get: g,
|
|
1347
|
+
set: u,
|
|
556
1348
|
enumerable: !0,
|
|
557
1349
|
configurable: !0
|
|
558
1350
|
});
|
|
559
1351
|
}
|
|
560
1352
|
render() {
|
|
561
|
-
return /* @__PURE__ */
|
|
1353
|
+
return /* @__PURE__ */ ae("a", { href: this.to, class: "wsx-link", onClick: this.handleClick, part: "link" }, /* @__PURE__ */ ae("slot", null));
|
|
562
1354
|
}
|
|
563
1355
|
onConnected() {
|
|
564
1356
|
this.to = this.getAttribute("to") || "", this.replace = this.hasAttribute("replace"), this.activeClass = this.getAttribute("active-class") || "active", this.exact = this.hasAttribute("exact");
|
|
565
|
-
const
|
|
566
|
-
|
|
1357
|
+
const e = this.shadowRoot.querySelector(".wsx-link");
|
|
1358
|
+
e && (e.href = this.to), window.addEventListener("popstate", this.updateActiveState), document.addEventListener("route-changed", this.updateActiveState), this.updateActiveState();
|
|
567
1359
|
}
|
|
568
1360
|
onDisconnected() {
|
|
569
1361
|
window.removeEventListener("popstate", this.updateActiveState), document.removeEventListener("route-changed", this.updateActiveState);
|
|
570
1362
|
}
|
|
571
|
-
onAttributeChanged(
|
|
572
|
-
switch (
|
|
1363
|
+
onAttributeChanged(e, n, r) {
|
|
1364
|
+
switch (e) {
|
|
573
1365
|
case "to":
|
|
574
|
-
this.to =
|
|
1366
|
+
this.to = r || "", this.updateActiveState();
|
|
575
1367
|
break;
|
|
576
1368
|
case "replace":
|
|
577
|
-
this.replace =
|
|
1369
|
+
this.replace = r !== null && r !== "false";
|
|
578
1370
|
break;
|
|
579
1371
|
case "active-class":
|
|
580
|
-
this.activeClass =
|
|
1372
|
+
this.activeClass = r || "active", this.updateActiveState();
|
|
581
1373
|
break;
|
|
582
1374
|
case "exact":
|
|
583
|
-
this.exact =
|
|
1375
|
+
this.exact = r !== null && r !== "false", this.updateActiveState();
|
|
584
1376
|
break;
|
|
585
1377
|
}
|
|
586
1378
|
}
|
|
587
|
-
isExternalLink(
|
|
588
|
-
return
|
|
1379
|
+
isExternalLink(e) {
|
|
1380
|
+
return e.startsWith("http://") || e.startsWith("https://") || e.startsWith("mailto:") || e.startsWith("tel:");
|
|
589
1381
|
}
|
|
590
1382
|
/**
|
|
591
1383
|
* 编程式导航
|
|
@@ -596,179 +1388,14 @@ new (vt = (it = class extends st {
|
|
|
596
1388
|
cancelable: !0
|
|
597
1389
|
}));
|
|
598
1390
|
}
|
|
599
|
-
}, [
|
|
1391
|
+
}, [Pe, Ae] = Ot(ve, [], Je, 0, void 0, Re).c, ve), pe = class extends zt {
|
|
600
1392
|
constructor() {
|
|
601
|
-
super(
|
|
602
|
-
}
|
|
603
|
-
}, M(nt, vt, void 0), nt)();
|
|
604
|
-
const Vt = F("RouterUtils");
|
|
605
|
-
class Kt {
|
|
606
|
-
/**
|
|
607
|
-
* 编程式导航
|
|
608
|
-
*/
|
|
609
|
-
static navigate(t, e = !1) {
|
|
610
|
-
e ? window.history.replaceState(null, "", t) : window.history.pushState(null, "", t), window.dispatchEvent(new PopStateEvent("popstate")), Vt.debug(`Navigated to: ${t} (replace: ${e})`);
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* 获取当前路由信息
|
|
614
|
-
*/
|
|
615
|
-
static getCurrentRoute() {
|
|
616
|
-
const t = new URL(window.location.href);
|
|
617
|
-
return {
|
|
618
|
-
path: t.pathname,
|
|
619
|
-
params: {},
|
|
620
|
-
// 需要路由匹配后才能确定
|
|
621
|
-
query: Object.fromEntries(t.searchParams.entries()),
|
|
622
|
-
hash: t.hash.slice(1)
|
|
623
|
-
// 移除 # 号
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
/**
|
|
627
|
-
* 解析路由路径,提取参数
|
|
628
|
-
*/
|
|
629
|
-
static parseRoute(t, e) {
|
|
630
|
-
var n;
|
|
631
|
-
if (t === e)
|
|
632
|
-
return {
|
|
633
|
-
route: t,
|
|
634
|
-
params: {},
|
|
635
|
-
exact: !0
|
|
636
|
-
};
|
|
637
|
-
if (t === "*")
|
|
638
|
-
return {
|
|
639
|
-
route: t,
|
|
640
|
-
params: {},
|
|
641
|
-
exact: !1
|
|
642
|
-
};
|
|
643
|
-
if (t.includes(":")) {
|
|
644
|
-
const g = ((n = t.match(/:([^/]+)/g)) == null ? void 0 : n.map((b) => b.slice(1))) || [], C = t.replace(/:[^/]+/g, "([^/]+)"), S = new RegExp(`^${C}$`), T = e.match(S);
|
|
645
|
-
if (T && g.length > 0) {
|
|
646
|
-
const b = {};
|
|
647
|
-
return g.forEach(($, P) => {
|
|
648
|
-
b[$] = T[P + 1];
|
|
649
|
-
}), {
|
|
650
|
-
route: t,
|
|
651
|
-
params: b,
|
|
652
|
-
exact: !0
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
if (t.endsWith("/*")) {
|
|
657
|
-
const g = t.slice(0, -2);
|
|
658
|
-
if (e.startsWith(g))
|
|
659
|
-
return {
|
|
660
|
-
route: t,
|
|
661
|
-
params: {},
|
|
662
|
-
exact: !1
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
return null;
|
|
1393
|
+
super(Pe), B(this, "observedAttributes", ["to", "replace", "active-class", "exact"]), Ae();
|
|
666
1394
|
}
|
|
667
|
-
|
|
668
|
-
* 构建路由路径,替换参数
|
|
669
|
-
*/
|
|
670
|
-
static buildPath(t, e = {}) {
|
|
671
|
-
let n = t;
|
|
672
|
-
return Object.entries(e).forEach(([g, C]) => {
|
|
673
|
-
n = n.replace(`:${g}`, encodeURIComponent(C));
|
|
674
|
-
}), n;
|
|
675
|
-
}
|
|
676
|
-
/**
|
|
677
|
-
* 检查路由是否匹配当前路径
|
|
678
|
-
*/
|
|
679
|
-
static isRouteActive(t, e = !1) {
|
|
680
|
-
const n = window.location.pathname;
|
|
681
|
-
return e ? n === t : t === "/" ? n === "/" : n.startsWith(t);
|
|
682
|
-
}
|
|
683
|
-
/**
|
|
684
|
-
* 获取路由层级
|
|
685
|
-
*/
|
|
686
|
-
static getRouteDepth(t) {
|
|
687
|
-
return t.split("/").filter((e) => e.length > 0).length;
|
|
688
|
-
}
|
|
689
|
-
/**
|
|
690
|
-
* 获取父级路由
|
|
691
|
-
*/
|
|
692
|
-
static getParentRoute(t) {
|
|
693
|
-
const e = t.split("/").filter((n) => n.length > 0);
|
|
694
|
-
return e.length <= 1 ? "/" : (e.pop(), "/" + e.join("/"));
|
|
695
|
-
}
|
|
696
|
-
/**
|
|
697
|
-
* 合并路由路径
|
|
698
|
-
*/
|
|
699
|
-
static joinPaths(...t) {
|
|
700
|
-
return t.map((e) => e.replace(/^\/+|\/+$/g, "")).filter((e) => e.length > 0).join("/").replace(/^/, "/");
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* 检查是否为外部链接
|
|
704
|
-
*/
|
|
705
|
-
static isExternalUrl(t) {
|
|
706
|
-
return /^https?:\/\//.test(t) || /^mailto:/.test(t) || /^tel:/.test(t);
|
|
707
|
-
}
|
|
708
|
-
/**
|
|
709
|
-
* 获取查询参数
|
|
710
|
-
*/
|
|
711
|
-
static getQueryParam(t) {
|
|
712
|
-
return new URL(window.location.href).searchParams.get(t);
|
|
713
|
-
}
|
|
714
|
-
/**
|
|
715
|
-
* 设置查询参数
|
|
716
|
-
*/
|
|
717
|
-
static setQueryParam(t, e, n = !1) {
|
|
718
|
-
const g = new URL(window.location.href);
|
|
719
|
-
g.searchParams.set(t, e);
|
|
720
|
-
const C = g.pathname + g.search + g.hash;
|
|
721
|
-
this.navigate(C, n);
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* 删除查询参数
|
|
725
|
-
*/
|
|
726
|
-
static removeQueryParam(t, e = !1) {
|
|
727
|
-
const n = new URL(window.location.href);
|
|
728
|
-
n.searchParams.delete(t);
|
|
729
|
-
const g = n.pathname + n.search + n.hash;
|
|
730
|
-
this.navigate(g, e);
|
|
731
|
-
}
|
|
732
|
-
/**
|
|
733
|
-
* 返回上一页
|
|
734
|
-
*/
|
|
735
|
-
static goBack() {
|
|
736
|
-
window.history.back();
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* 前进一页
|
|
740
|
-
*/
|
|
741
|
-
static goForward() {
|
|
742
|
-
window.history.forward();
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* 替换当前页面
|
|
746
|
-
*/
|
|
747
|
-
static replace(t) {
|
|
748
|
-
this.navigate(t, !0);
|
|
749
|
-
}
|
|
750
|
-
/**
|
|
751
|
-
* 获取历史记录长度
|
|
752
|
-
*/
|
|
753
|
-
static getHistoryLength() {
|
|
754
|
-
return window.history.length;
|
|
755
|
-
}
|
|
756
|
-
/**
|
|
757
|
-
* 监听路由变化
|
|
758
|
-
*/
|
|
759
|
-
static onRouteChange(t) {
|
|
760
|
-
const e = () => {
|
|
761
|
-
const n = this.getCurrentRoute();
|
|
762
|
-
t(n);
|
|
763
|
-
};
|
|
764
|
-
return window.addEventListener("popstate", e), document.addEventListener("route-changed", e), () => {
|
|
765
|
-
window.removeEventListener("popstate", e), document.removeEventListener("route-changed", e);
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
}
|
|
1395
|
+
}, B(pe, Te, void 0), pe)();
|
|
769
1396
|
export {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
1397
|
+
le as RouterUtils,
|
|
1398
|
+
Pe as WsxLink,
|
|
1399
|
+
Rt as WsxRouter,
|
|
1400
|
+
ze as WsxView
|
|
774
1401
|
};
|