@wsxjs/wsx-router 0.0.23 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +611 -739
- package/package.json +5 -5
- package/src/WsxRouter.wsx +14 -2
package/dist/index.js
CHANGED
|
@@ -1,277 +1,143 @@
|
|
|
1
|
-
import { autoRegister as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
n.exports ? n.exports = t() : e.log = t();
|
|
10
|
-
})(We, function() {
|
|
11
|
-
var e = function() {
|
|
12
|
-
}, t = "undefined", r = typeof window !== t && typeof window.navigator !== t && /Trident\/|MSIE /.test(window.navigator.userAgent), g = [
|
|
13
|
-
"trace",
|
|
14
|
-
"debug",
|
|
15
|
-
"info",
|
|
16
|
-
"warn",
|
|
17
|
-
"error"
|
|
18
|
-
], v = {}, d = null;
|
|
19
|
-
function _(o, c) {
|
|
20
|
-
var i = o[c];
|
|
21
|
-
if (typeof i.bind == "function")
|
|
22
|
-
return i.bind(o);
|
|
23
|
-
try {
|
|
24
|
-
return Function.prototype.bind.call(i, o);
|
|
25
|
-
} catch {
|
|
26
|
-
return function() {
|
|
27
|
-
return Function.prototype.apply.apply(i, [o, arguments]);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function b() {
|
|
32
|
-
console.log && (console.log.apply ? console.log.apply(console, arguments) : Function.prototype.apply.apply(console.log, [console, arguments])), console.trace && console.trace();
|
|
33
|
-
}
|
|
34
|
-
function T(o) {
|
|
35
|
-
return o === "debug" && (o = "log"), typeof console === t ? !1 : o === "trace" && r ? b : console[o] !== void 0 ? _(console, o) : console.log !== void 0 ? _(console, "log") : e;
|
|
36
|
-
}
|
|
37
|
-
function O() {
|
|
38
|
-
for (var o = this.getLevel(), c = 0; c < g.length; c++) {
|
|
39
|
-
var i = g[c];
|
|
40
|
-
this[i] = c < o ? e : this.methodFactory(i, o, this.name);
|
|
41
|
-
}
|
|
42
|
-
if (this.log = this.debug, typeof console === t && o < this.levels.SILENT)
|
|
43
|
-
return "No console available for logging";
|
|
44
|
-
}
|
|
45
|
-
function V(o) {
|
|
46
|
-
return function() {
|
|
47
|
-
typeof console !== t && (O.call(this), this[o].apply(this, arguments));
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function M(o, c, i) {
|
|
51
|
-
return T(o) || V.apply(this, arguments);
|
|
52
|
-
}
|
|
53
|
-
function H(o, c) {
|
|
54
|
-
var i = this, u, A, k, L = "loglevel";
|
|
55
|
-
typeof o == "string" ? L += ":" + o : typeof o == "symbol" && (L = void 0);
|
|
56
|
-
function P(h) {
|
|
57
|
-
var l = (g[h] || "silent").toUpperCase();
|
|
58
|
-
if (!(typeof window === t || !L)) {
|
|
59
|
-
try {
|
|
60
|
-
window.localStorage[L] = l;
|
|
61
|
-
return;
|
|
62
|
-
} catch {
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
window.document.cookie = encodeURIComponent(L) + "=" + l + ";";
|
|
66
|
-
} catch {
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function E() {
|
|
71
|
-
var h;
|
|
72
|
-
if (!(typeof window === t || !L)) {
|
|
73
|
-
try {
|
|
74
|
-
h = window.localStorage[L];
|
|
75
|
-
} catch {
|
|
76
|
-
}
|
|
77
|
-
if (typeof h === t)
|
|
78
|
-
try {
|
|
79
|
-
var l = window.document.cookie, x = encodeURIComponent(L), C = l.indexOf(x + "=");
|
|
80
|
-
C !== -1 && (h = /^([^;]+)/.exec(
|
|
81
|
-
l.slice(C + x.length + 1)
|
|
82
|
-
)[1]);
|
|
83
|
-
} catch {
|
|
84
|
-
}
|
|
85
|
-
return i.levels[h] === void 0 && (h = void 0), h;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
function R() {
|
|
89
|
-
if (!(typeof window === t || !L)) {
|
|
90
|
-
try {
|
|
91
|
-
window.localStorage.removeItem(L);
|
|
92
|
-
} catch {
|
|
93
|
-
}
|
|
94
|
-
try {
|
|
95
|
-
window.document.cookie = encodeURIComponent(L) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
|
96
|
-
} catch {
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function p(h) {
|
|
101
|
-
var l = h;
|
|
102
|
-
if (typeof l == "string" && i.levels[l.toUpperCase()] !== void 0 && (l = i.levels[l.toUpperCase()]), typeof l == "number" && l >= 0 && l <= i.levels.SILENT)
|
|
103
|
-
return l;
|
|
104
|
-
throw new TypeError("log.setLevel() called with invalid level: " + h);
|
|
105
|
-
}
|
|
106
|
-
i.name = o, i.levels = {
|
|
107
|
-
TRACE: 0,
|
|
108
|
-
DEBUG: 1,
|
|
109
|
-
INFO: 2,
|
|
110
|
-
WARN: 3,
|
|
111
|
-
ERROR: 4,
|
|
112
|
-
SILENT: 5
|
|
113
|
-
}, i.methodFactory = c || M, i.getLevel = function() {
|
|
114
|
-
return k ?? A ?? u;
|
|
115
|
-
}, i.setLevel = function(h, l) {
|
|
116
|
-
return k = p(h), l !== !1 && P(k), O.call(i);
|
|
117
|
-
}, i.setDefaultLevel = function(h) {
|
|
118
|
-
A = p(h), E() || i.setLevel(h, !1);
|
|
119
|
-
}, i.resetLevel = function() {
|
|
120
|
-
k = null, R(), O.call(i);
|
|
121
|
-
}, i.enableAll = function(h) {
|
|
122
|
-
i.setLevel(i.levels.TRACE, h);
|
|
123
|
-
}, i.disableAll = function(h) {
|
|
124
|
-
i.setLevel(i.levels.SILENT, h);
|
|
125
|
-
}, i.rebuild = function() {
|
|
126
|
-
if (d !== i && (u = p(d.getLevel())), O.call(i), d === i)
|
|
127
|
-
for (var h in v)
|
|
128
|
-
v[h].rebuild();
|
|
129
|
-
}, u = p(
|
|
130
|
-
d ? d.getLevel() : "WARN"
|
|
131
|
-
);
|
|
132
|
-
var m = E();
|
|
133
|
-
m != null && (k = p(m)), O.call(i);
|
|
134
|
-
}
|
|
135
|
-
d = new H(), d.getLogger = function(c) {
|
|
136
|
-
if (typeof c != "symbol" && typeof c != "string" || c === "")
|
|
137
|
-
throw new TypeError("You must supply a name when creating a logger.");
|
|
138
|
-
var i = v[c];
|
|
139
|
-
return i || (i = v[c] = new H(
|
|
140
|
-
c,
|
|
141
|
-
d.methodFactory
|
|
142
|
-
)), i;
|
|
143
|
-
};
|
|
144
|
-
var s = typeof window !== t ? window.log : void 0;
|
|
145
|
-
return d.noConflict = function() {
|
|
146
|
-
return typeof window !== t && window.log === d && (window.log = s), d;
|
|
147
|
-
}, d.getLoggers = function() {
|
|
148
|
-
return v;
|
|
149
|
-
}, d.default = d, d;
|
|
150
|
-
});
|
|
151
|
-
})(ye);
|
|
152
|
-
var Te = ye.exports;
|
|
153
|
-
const Oe = /* @__PURE__ */ Ae(Te), be = {
|
|
154
|
-
trace: "trace",
|
|
155
|
-
debug: "debug",
|
|
156
|
-
info: "info",
|
|
157
|
-
warn: "warn",
|
|
158
|
-
error: "error",
|
|
159
|
-
silent: "silent"
|
|
160
|
-
}, je = {
|
|
161
|
-
0: "trace",
|
|
162
|
-
1: "debug",
|
|
163
|
-
2: "info",
|
|
164
|
-
3: "warn",
|
|
165
|
-
4: "error",
|
|
166
|
-
5: "silent"
|
|
1
|
+
import { autoRegister as ct, LightComponent as nt, jsx as tt, WebComponent as lt } from "@wsxjs/wsx-core";
|
|
2
|
+
const it = {
|
|
3
|
+
trace: 0,
|
|
4
|
+
debug: 1,
|
|
5
|
+
info: 2,
|
|
6
|
+
warn: 3,
|
|
7
|
+
error: 4,
|
|
8
|
+
silent: 5
|
|
167
9
|
};
|
|
168
|
-
function
|
|
169
|
-
var
|
|
10
|
+
function at() {
|
|
11
|
+
var r, t;
|
|
170
12
|
if (typeof process < "u")
|
|
171
13
|
return process.env.NODE_ENV === "production" || process.env.MODE === "production";
|
|
172
14
|
try {
|
|
173
|
-
const
|
|
174
|
-
if ((
|
|
175
|
-
const
|
|
176
|
-
return
|
|
15
|
+
const e = globalThis;
|
|
16
|
+
if ((t = (r = e.import) == null ? void 0 : r.meta) != null && t.env) {
|
|
17
|
+
const n = e.import.meta.env;
|
|
18
|
+
return n.MODE === "production" || n.PROD === !0;
|
|
177
19
|
}
|
|
178
20
|
} catch {
|
|
179
21
|
}
|
|
180
22
|
return !1;
|
|
181
23
|
}
|
|
182
|
-
const
|
|
24
|
+
const ut = {
|
|
183
25
|
name: "WSX",
|
|
184
|
-
level:
|
|
185
|
-
pretty: !
|
|
26
|
+
level: at() ? "info" : "debug",
|
|
27
|
+
pretty: !at()
|
|
186
28
|
};
|
|
187
|
-
function
|
|
188
|
-
|
|
189
|
-
return g.setLevel(be[v]), g;
|
|
29
|
+
function G(r, t) {
|
|
30
|
+
return r ? `[${r}] ${t}` : t;
|
|
190
31
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
32
|
+
class Wt {
|
|
33
|
+
constructor(t, e) {
|
|
34
|
+
this.name = t, this.level = e, this.levelValue = it[e], this.isProd = at();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check if a log level should be logged
|
|
38
|
+
*/
|
|
39
|
+
shouldLog(t) {
|
|
40
|
+
return this.level === "silent" ? !1 : it[t] >= this.levelValue;
|
|
197
41
|
}
|
|
198
|
-
|
|
42
|
+
trace(t, ...e) {
|
|
43
|
+
if (!this.isProd || this.shouldLog("trace")) {
|
|
44
|
+
const n = G(this.name, t);
|
|
45
|
+
e.length > 0 ? console.debug(n, ...e) : console.debug(n);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
debug(t, ...e) {
|
|
199
49
|
if (!this.isProd || this.shouldLog("debug")) {
|
|
200
|
-
const
|
|
201
|
-
|
|
50
|
+
const n = G(this.name, t);
|
|
51
|
+
e.length > 0 ? console.debug(n, ...e) : console.debug(n);
|
|
202
52
|
}
|
|
203
53
|
}
|
|
204
|
-
info(
|
|
54
|
+
info(t, ...e) {
|
|
205
55
|
if (this.shouldLog("info")) {
|
|
206
|
-
const
|
|
207
|
-
|
|
56
|
+
const n = G(this.name, t);
|
|
57
|
+
e.length > 0 ? console.info(n, ...e) : console.info(n);
|
|
208
58
|
}
|
|
209
59
|
}
|
|
210
|
-
warn(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const r = X(this.name, e);
|
|
216
|
-
t.length > 0 ? this.logInstance.error(r, ...t) : this.logInstance.error(r);
|
|
217
|
-
}
|
|
218
|
-
fatal(e, ...t) {
|
|
219
|
-
const r = X(this.name, e);
|
|
220
|
-
t.length > 0 ? this.logInstance.error(`[FATAL] ${r}`, ...t) : this.logInstance.error(`[FATAL] ${r}`);
|
|
60
|
+
warn(t, ...e) {
|
|
61
|
+
if (this.shouldLog("warn")) {
|
|
62
|
+
const n = G(this.name, t);
|
|
63
|
+
e.length > 0 ? console.warn(n, ...e) : console.warn(n);
|
|
64
|
+
}
|
|
221
65
|
}
|
|
222
|
-
|
|
223
|
-
if (
|
|
224
|
-
const
|
|
225
|
-
|
|
66
|
+
error(t, ...e) {
|
|
67
|
+
if (this.shouldLog("error")) {
|
|
68
|
+
const n = G(this.name, t);
|
|
69
|
+
e.length > 0 ? console.error(n, ...e) : console.error(n);
|
|
226
70
|
}
|
|
227
71
|
}
|
|
228
72
|
/**
|
|
229
|
-
*
|
|
73
|
+
* Set the log level dynamically
|
|
230
74
|
*/
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return t.indexOf(e) >= r;
|
|
75
|
+
setLevel(t) {
|
|
76
|
+
this.level = t, this.levelValue = it[t];
|
|
234
77
|
}
|
|
235
78
|
/**
|
|
236
|
-
* Get the
|
|
79
|
+
* Get the current log level
|
|
237
80
|
*/
|
|
238
|
-
|
|
239
|
-
return this.
|
|
81
|
+
getLevel() {
|
|
82
|
+
return this.level;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
class wt {
|
|
86
|
+
constructor(t = {}) {
|
|
87
|
+
this.name = t.name || ut.name, this.currentLevel = t.level || ut.level, this.nativeLogger = new Wt(this.name, this.currentLevel);
|
|
88
|
+
}
|
|
89
|
+
debug(t, ...e) {
|
|
90
|
+
this.nativeLogger.debug(t, ...e);
|
|
91
|
+
}
|
|
92
|
+
info(t, ...e) {
|
|
93
|
+
this.nativeLogger.info(t, ...e);
|
|
94
|
+
}
|
|
95
|
+
warn(t, ...e) {
|
|
96
|
+
this.nativeLogger.warn(t, ...e);
|
|
97
|
+
}
|
|
98
|
+
error(t, ...e) {
|
|
99
|
+
this.nativeLogger.error(t, ...e);
|
|
100
|
+
}
|
|
101
|
+
fatal(t, ...e) {
|
|
102
|
+
const n = G(this.name, `[FATAL] ${t}`);
|
|
103
|
+
e.length > 0 ? console.error(n, ...e) : console.error(n);
|
|
104
|
+
}
|
|
105
|
+
trace(t, ...e) {
|
|
106
|
+
this.nativeLogger.trace(t, ...e);
|
|
240
107
|
}
|
|
241
108
|
/**
|
|
242
109
|
* Set the log level dynamically
|
|
243
110
|
*/
|
|
244
|
-
setLevel(
|
|
245
|
-
this.currentLevel =
|
|
111
|
+
setLevel(t) {
|
|
112
|
+
this.currentLevel = t, this.nativeLogger.setLevel(t);
|
|
246
113
|
}
|
|
247
114
|
/**
|
|
248
115
|
* Get the current log level
|
|
249
116
|
*/
|
|
250
117
|
getLevel() {
|
|
251
|
-
|
|
252
|
-
return je[e] || this.currentLevel;
|
|
118
|
+
return this.nativeLogger.getLevel();
|
|
253
119
|
}
|
|
254
120
|
}
|
|
255
|
-
new
|
|
256
|
-
function
|
|
257
|
-
return new
|
|
258
|
-
...
|
|
259
|
-
name:
|
|
121
|
+
new wt();
|
|
122
|
+
function rt(r, t = {}) {
|
|
123
|
+
return new wt({
|
|
124
|
+
...t,
|
|
125
|
+
name: t.name || `WSX:${r}`
|
|
260
126
|
});
|
|
261
127
|
}
|
|
262
|
-
const
|
|
128
|
+
const jt = rt("RouterUtils"), J = class J {
|
|
263
129
|
/**
|
|
264
130
|
* 设置当前路由信息(由 WsxRouter 内部调用)
|
|
265
131
|
* @internal
|
|
266
132
|
*/
|
|
267
|
-
static _setCurrentRoute(
|
|
268
|
-
|
|
133
|
+
static _setCurrentRoute(t) {
|
|
134
|
+
J._currentRoute = t;
|
|
269
135
|
}
|
|
270
136
|
/**
|
|
271
137
|
* 编程式导航
|
|
272
138
|
*/
|
|
273
|
-
static navigate(
|
|
274
|
-
|
|
139
|
+
static navigate(t, e = !1) {
|
|
140
|
+
e ? window.history.replaceState(null, "", t) : window.history.pushState(null, "", t), window.dispatchEvent(new PopStateEvent("popstate")), jt.debug(`Navigated to: ${t} (replace: ${e})`);
|
|
275
141
|
}
|
|
276
142
|
/**
|
|
277
143
|
* 获取当前路由信息
|
|
@@ -279,52 +145,52 @@ const Me = ie("RouterUtils"), Y = class Y {
|
|
|
279
145
|
* 否则返回基础路由信息(参数为空对象)
|
|
280
146
|
*/
|
|
281
147
|
static getCurrentRoute() {
|
|
282
|
-
if (
|
|
283
|
-
return
|
|
284
|
-
const
|
|
148
|
+
if (J._currentRoute)
|
|
149
|
+
return J._currentRoute;
|
|
150
|
+
const t = new URL(window.location.href);
|
|
285
151
|
return {
|
|
286
|
-
path:
|
|
152
|
+
path: t.pathname,
|
|
287
153
|
params: {},
|
|
288
|
-
query: Object.fromEntries(
|
|
289
|
-
hash:
|
|
154
|
+
query: Object.fromEntries(t.searchParams.entries()),
|
|
155
|
+
hash: t.hash.slice(1)
|
|
290
156
|
// 移除 # 号
|
|
291
157
|
};
|
|
292
158
|
}
|
|
293
159
|
/**
|
|
294
160
|
* 解析路由路径,提取参数
|
|
295
161
|
*/
|
|
296
|
-
static parseRoute(
|
|
297
|
-
var
|
|
298
|
-
if (
|
|
162
|
+
static parseRoute(t, e) {
|
|
163
|
+
var n;
|
|
164
|
+
if (t === e)
|
|
299
165
|
return {
|
|
300
|
-
route:
|
|
166
|
+
route: t,
|
|
301
167
|
params: {},
|
|
302
168
|
exact: !0
|
|
303
169
|
};
|
|
304
|
-
if (
|
|
170
|
+
if (t === "*")
|
|
305
171
|
return {
|
|
306
|
-
route:
|
|
172
|
+
route: t,
|
|
307
173
|
params: {},
|
|
308
174
|
exact: !1
|
|
309
175
|
};
|
|
310
|
-
if (
|
|
311
|
-
const
|
|
312
|
-
if (
|
|
176
|
+
if (t.includes(":")) {
|
|
177
|
+
const f = ((n = t.match(/:([^/]+)/g)) == null ? void 0 : n.map((b) => b.slice(1))) || [], v = t.replace(/:[^/]+/g, "([^/]+)"), y = new RegExp(`^${v}$`), k = e.match(y);
|
|
178
|
+
if (k && f.length > 0) {
|
|
313
179
|
const b = {};
|
|
314
|
-
return
|
|
315
|
-
b[
|
|
180
|
+
return f.forEach((j, z) => {
|
|
181
|
+
b[j] = k[z + 1];
|
|
316
182
|
}), {
|
|
317
|
-
route:
|
|
183
|
+
route: t,
|
|
318
184
|
params: b,
|
|
319
185
|
exact: !0
|
|
320
186
|
};
|
|
321
187
|
}
|
|
322
188
|
}
|
|
323
|
-
if (
|
|
324
|
-
const
|
|
325
|
-
if (
|
|
189
|
+
if (t.endsWith("/*")) {
|
|
190
|
+
const f = t.slice(0, -2);
|
|
191
|
+
if (e.startsWith(f))
|
|
326
192
|
return {
|
|
327
|
-
route:
|
|
193
|
+
route: t,
|
|
328
194
|
params: {},
|
|
329
195
|
exact: !1
|
|
330
196
|
};
|
|
@@ -334,67 +200,67 @@ const Me = ie("RouterUtils"), Y = class Y {
|
|
|
334
200
|
/**
|
|
335
201
|
* 构建路由路径,替换参数
|
|
336
202
|
*/
|
|
337
|
-
static buildPath(
|
|
338
|
-
let
|
|
339
|
-
return Object.entries(
|
|
340
|
-
|
|
341
|
-
}),
|
|
203
|
+
static buildPath(t, e = {}) {
|
|
204
|
+
let n = t;
|
|
205
|
+
return Object.entries(e).forEach(([f, v]) => {
|
|
206
|
+
n = n.replace(`:${f}`, encodeURIComponent(v));
|
|
207
|
+
}), n;
|
|
342
208
|
}
|
|
343
209
|
/**
|
|
344
210
|
* 检查路由是否匹配当前路径
|
|
345
211
|
*/
|
|
346
|
-
static isRouteActive(
|
|
347
|
-
const
|
|
348
|
-
return
|
|
212
|
+
static isRouteActive(t, e = !1) {
|
|
213
|
+
const n = window.location.pathname;
|
|
214
|
+
return e ? n === t : t === "/" ? n === "/" : n.startsWith(t);
|
|
349
215
|
}
|
|
350
216
|
/**
|
|
351
217
|
* 获取路由层级
|
|
352
218
|
*/
|
|
353
|
-
static getRouteDepth(
|
|
354
|
-
return
|
|
219
|
+
static getRouteDepth(t) {
|
|
220
|
+
return t.split("/").filter((e) => e.length > 0).length;
|
|
355
221
|
}
|
|
356
222
|
/**
|
|
357
223
|
* 获取父级路由
|
|
358
224
|
*/
|
|
359
|
-
static getParentRoute(
|
|
360
|
-
const
|
|
361
|
-
return
|
|
225
|
+
static getParentRoute(t) {
|
|
226
|
+
const e = t.split("/").filter((n) => n.length > 0);
|
|
227
|
+
return e.length <= 1 ? "/" : (e.pop(), "/" + e.join("/"));
|
|
362
228
|
}
|
|
363
229
|
/**
|
|
364
230
|
* 合并路由路径
|
|
365
231
|
*/
|
|
366
|
-
static joinPaths(...
|
|
367
|
-
return
|
|
232
|
+
static joinPaths(...t) {
|
|
233
|
+
return t.map((e) => e.replace(/^\/+|\/+$/g, "")).filter((e) => e.length > 0).join("/").replace(/^/, "/");
|
|
368
234
|
}
|
|
369
235
|
/**
|
|
370
236
|
* 检查是否为外部链接
|
|
371
237
|
*/
|
|
372
|
-
static isExternalUrl(
|
|
373
|
-
return /^https?:\/\//.test(
|
|
238
|
+
static isExternalUrl(t) {
|
|
239
|
+
return /^https?:\/\//.test(t) || /^mailto:/.test(t) || /^tel:/.test(t);
|
|
374
240
|
}
|
|
375
241
|
/**
|
|
376
242
|
* 获取查询参数
|
|
377
243
|
*/
|
|
378
|
-
static getQueryParam(
|
|
379
|
-
return new URL(window.location.href).searchParams.get(
|
|
244
|
+
static getQueryParam(t) {
|
|
245
|
+
return new URL(window.location.href).searchParams.get(t);
|
|
380
246
|
}
|
|
381
247
|
/**
|
|
382
248
|
* 设置查询参数
|
|
383
249
|
*/
|
|
384
|
-
static setQueryParam(
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
const v =
|
|
388
|
-
this.navigate(v,
|
|
250
|
+
static setQueryParam(t, e, n = !1) {
|
|
251
|
+
const f = new URL(window.location.href);
|
|
252
|
+
f.searchParams.set(t, e);
|
|
253
|
+
const v = f.pathname + f.search + f.hash;
|
|
254
|
+
this.navigate(v, n);
|
|
389
255
|
}
|
|
390
256
|
/**
|
|
391
257
|
* 删除查询参数
|
|
392
258
|
*/
|
|
393
|
-
static removeQueryParam(
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
const
|
|
397
|
-
this.navigate(
|
|
259
|
+
static removeQueryParam(t, e = !1) {
|
|
260
|
+
const n = new URL(window.location.href);
|
|
261
|
+
n.searchParams.delete(t);
|
|
262
|
+
const f = n.pathname + n.search + n.hash;
|
|
263
|
+
this.navigate(f, e);
|
|
398
264
|
}
|
|
399
265
|
/**
|
|
400
266
|
* 返回上一页
|
|
@@ -411,8 +277,8 @@ const Me = ie("RouterUtils"), Y = class Y {
|
|
|
411
277
|
/**
|
|
412
278
|
* 替换当前页面
|
|
413
279
|
*/
|
|
414
|
-
static replace(
|
|
415
|
-
this.navigate(
|
|
280
|
+
static replace(t) {
|
|
281
|
+
this.navigate(t, !0);
|
|
416
282
|
}
|
|
417
283
|
/**
|
|
418
284
|
* 获取历史记录长度
|
|
@@ -431,482 +297,488 @@ const Me = ie("RouterUtils"), Y = class Y {
|
|
|
431
297
|
*
|
|
432
298
|
* @see RFC-0035: 路由导航竞态条件修复
|
|
433
299
|
*/
|
|
434
|
-
static onRouteChange(
|
|
435
|
-
const
|
|
436
|
-
const
|
|
437
|
-
|
|
300
|
+
static onRouteChange(t) {
|
|
301
|
+
const e = () => {
|
|
302
|
+
const n = this.getCurrentRoute();
|
|
303
|
+
t(n);
|
|
438
304
|
};
|
|
439
|
-
return document.addEventListener("route-changed",
|
|
440
|
-
document.removeEventListener("route-changed",
|
|
305
|
+
return document.addEventListener("route-changed", e), () => {
|
|
306
|
+
document.removeEventListener("route-changed", e);
|
|
441
307
|
};
|
|
442
308
|
}
|
|
443
309
|
};
|
|
444
|
-
|
|
445
|
-
let
|
|
446
|
-
const
|
|
447
|
-
var
|
|
448
|
-
let
|
|
449
|
-
function
|
|
450
|
-
return (
|
|
310
|
+
J._currentRoute = null;
|
|
311
|
+
let et = J;
|
|
312
|
+
const ht = ":host{display:grid;width:100%}.router-outlet{width:100%}:host>wsx-view{grid-area:1 / 1}";
|
|
313
|
+
var yt;
|
|
314
|
+
let Rt, xt;
|
|
315
|
+
function U(r, t, e) {
|
|
316
|
+
return (t = $t(t)) in r ? Object.defineProperty(r, t, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = e, r;
|
|
451
317
|
}
|
|
452
|
-
function
|
|
453
|
-
function
|
|
454
|
-
return function(
|
|
455
|
-
return
|
|
318
|
+
function At(r, t, e, n, f, v) {
|
|
319
|
+
function y(i, c, u) {
|
|
320
|
+
return function(s, a) {
|
|
321
|
+
return u && u(s), i[c].call(s, a);
|
|
456
322
|
};
|
|
457
323
|
}
|
|
458
|
-
function
|
|
459
|
-
for (var
|
|
460
|
-
return
|
|
324
|
+
function k(i, c) {
|
|
325
|
+
for (var u = 0; u < i.length; u++) i[u].call(c);
|
|
326
|
+
return c;
|
|
461
327
|
}
|
|
462
|
-
function b(
|
|
463
|
-
if (typeof
|
|
464
|
-
return
|
|
328
|
+
function b(i, c, u, s) {
|
|
329
|
+
if (typeof i != "function" && (s || i !== void 0)) throw new TypeError(c + " must " + (u || "be") + " a function" + (s ? "" : " or undefined"));
|
|
330
|
+
return i;
|
|
465
331
|
}
|
|
466
|
-
function
|
|
467
|
-
function
|
|
468
|
-
if (!m(
|
|
332
|
+
function j(i, c, u, s, a, A, O, S, D, x, w, g, m) {
|
|
333
|
+
function $(l) {
|
|
334
|
+
if (!m(l)) throw new TypeError("Attempted to access private element on non-instance");
|
|
469
335
|
}
|
|
470
|
-
var
|
|
336
|
+
var h, C = c[0], E = c[3], W = !S;
|
|
471
337
|
if (!W) {
|
|
472
|
-
|
|
473
|
-
var
|
|
474
|
-
|
|
475
|
-
return
|
|
476
|
-
},
|
|
477
|
-
|
|
478
|
-
} } :
|
|
338
|
+
u || Array.isArray(C) || (C = [C]);
|
|
339
|
+
var o = {}, L = [], p = a === 3 ? "get" : a === 4 || g ? "set" : "value";
|
|
340
|
+
x ? (w || g ? o = { get: dt(function() {
|
|
341
|
+
return E(this);
|
|
342
|
+
}, s, "get"), set: function(l) {
|
|
343
|
+
c[4](this, l);
|
|
344
|
+
} } : o[p] = E, w || dt(o[p], s, a === 2 ? "" : p)) : w || (o = Object.getOwnPropertyDescriptor(i, s));
|
|
479
345
|
}
|
|
480
|
-
for (var
|
|
481
|
-
var B =
|
|
482
|
-
if (
|
|
483
|
-
b(
|
|
346
|
+
for (var d = i, P = C.length - 1; P >= 0; P -= u ? 2 : 1) {
|
|
347
|
+
var B = C[P], F = u ? C[P - 1] : void 0, K = {}, T = { kind: ["field", "accessor", "method", "getter", "setter", "class"][a], name: s, metadata: A, addInitializer: (function(l, _) {
|
|
348
|
+
if (l.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
349
|
+
b(_, "An initializer", "be", !0), O.push(_);
|
|
484
350
|
}).bind(null, K) };
|
|
485
351
|
try {
|
|
486
|
-
if (W) (
|
|
352
|
+
if (W) (h = b(B.call(F, d, T), "class decorators", "return")) && (d = h);
|
|
487
353
|
else {
|
|
488
|
-
var
|
|
489
|
-
|
|
490
|
-
return
|
|
491
|
-
} : (
|
|
492
|
-
return
|
|
493
|
-
}, (
|
|
494
|
-
|
|
354
|
+
var I, M;
|
|
355
|
+
T.static = D, T.private = x, x ? a === 2 ? I = function(l) {
|
|
356
|
+
return $(l), o.value;
|
|
357
|
+
} : (a < 4 && (I = y(o, "get", $)), a !== 3 && (M = y(o, "set", $))) : (I = function(l) {
|
|
358
|
+
return l[s];
|
|
359
|
+
}, (a < 2 || a === 4) && (M = function(l, _) {
|
|
360
|
+
l[s] = _;
|
|
495
361
|
}));
|
|
496
|
-
var
|
|
497
|
-
return
|
|
362
|
+
var Q = T.access = { has: x ? m.bind() : function(l) {
|
|
363
|
+
return s in l;
|
|
498
364
|
} };
|
|
499
|
-
if (
|
|
500
|
-
if (typeof
|
|
501
|
-
else if (
|
|
502
|
-
} else b(
|
|
365
|
+
if (I && (Q.get = I), M && (Q.set = M), d = B.call(F, g ? { get: o.get, set: o.set } : o[p], T), g) {
|
|
366
|
+
if (typeof d == "object" && d) (h = b(d.get, "accessor.get")) && (o.get = h), (h = b(d.set, "accessor.set")) && (o.set = h), (h = b(d.init, "accessor.init")) && L.push(h);
|
|
367
|
+
else if (d !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
368
|
+
} else b(d, (w ? "field" : "method") + " decorators", "return") && (w ? L.push(d) : o[p] = d);
|
|
503
369
|
}
|
|
504
370
|
} finally {
|
|
505
371
|
K.v = !0;
|
|
506
372
|
}
|
|
507
373
|
}
|
|
508
|
-
return (
|
|
509
|
-
for (var N =
|
|
510
|
-
return
|
|
511
|
-
}),
|
|
512
|
-
}
|
|
513
|
-
function
|
|
514
|
-
return Object.defineProperty(
|
|
515
|
-
}
|
|
516
|
-
if (arguments.length >= 6) var
|
|
517
|
-
var
|
|
518
|
-
var
|
|
519
|
-
return
|
|
520
|
-
},
|
|
521
|
-
function
|
|
522
|
-
|
|
374
|
+
return (w || g) && S.push(function(l, _) {
|
|
375
|
+
for (var N = L.length - 1; N >= 0; N--) _ = L[N].call(l, _);
|
|
376
|
+
return _;
|
|
377
|
+
}), w || W || (x ? g ? S.push(y(o, "get"), y(o, "set")) : S.push(a === 2 ? o[p] : y.call.bind(o[p])) : Object.defineProperty(i, s, o)), d;
|
|
378
|
+
}
|
|
379
|
+
function z(i, c) {
|
|
380
|
+
return Object.defineProperty(i, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
|
|
381
|
+
}
|
|
382
|
+
if (arguments.length >= 6) var q = v[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
383
|
+
var V = Object.create(q ?? null), Y = function(i, c, u, s) {
|
|
384
|
+
var a, A, O = [], S = function(p) {
|
|
385
|
+
return Tt(p) === i;
|
|
386
|
+
}, D = /* @__PURE__ */ new Map();
|
|
387
|
+
function x(p) {
|
|
388
|
+
p && O.push(k.bind(null, p));
|
|
523
389
|
}
|
|
524
|
-
for (var
|
|
525
|
-
var
|
|
526
|
-
if (Array.isArray(
|
|
527
|
-
var m =
|
|
528
|
-
if (!W && !
|
|
529
|
-
var
|
|
530
|
-
if (
|
|
531
|
-
|
|
390
|
+
for (var w = 0; w < c.length; w++) {
|
|
391
|
+
var g = c[w];
|
|
392
|
+
if (Array.isArray(g)) {
|
|
393
|
+
var m = g[1], $ = g[2], h = g.length > 3, C = 16 & m, E = !!(8 & m), W = (m &= 7) == 0, o = $ + "/" + E;
|
|
394
|
+
if (!W && !h) {
|
|
395
|
+
var L = D.get(o);
|
|
396
|
+
if (L === !0 || L === 3 && m !== 4 || L === 4 && m !== 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: " + $);
|
|
397
|
+
D.set(o, !(m > 2) || m);
|
|
532
398
|
}
|
|
533
|
-
|
|
399
|
+
j(E ? i : i.prototype, g, C, h ? "#" + $ : $t($), m, s, E ? A = A || [] : a = a || [], O, E, h, W, m === 1, E && h ? S : u);
|
|
534
400
|
}
|
|
535
401
|
}
|
|
536
|
-
return
|
|
537
|
-
}(
|
|
538
|
-
return
|
|
539
|
-
var
|
|
540
|
-
return
|
|
402
|
+
return x(a), x(A), O;
|
|
403
|
+
}(r, t, f, V);
|
|
404
|
+
return e.length || z(r, V), { e: Y, get c() {
|
|
405
|
+
var i = [];
|
|
406
|
+
return e.length && [z(j(r, [e], n, r.name, 5, V, i), V), k.bind(null, i, r)];
|
|
541
407
|
} };
|
|
542
408
|
}
|
|
543
|
-
function
|
|
544
|
-
var
|
|
545
|
-
return typeof
|
|
409
|
+
function $t(r) {
|
|
410
|
+
var t = Ot(r, "string");
|
|
411
|
+
return typeof t == "symbol" ? t : t + "";
|
|
546
412
|
}
|
|
547
|
-
function
|
|
548
|
-
if (typeof
|
|
549
|
-
var
|
|
550
|
-
if (
|
|
551
|
-
var
|
|
552
|
-
if (typeof
|
|
413
|
+
function Ot(r, t) {
|
|
414
|
+
if (typeof r != "object" || !r) return r;
|
|
415
|
+
var e = r[Symbol.toPrimitive];
|
|
416
|
+
if (e !== void 0) {
|
|
417
|
+
var n = e.call(r, t);
|
|
418
|
+
if (typeof n != "object") return n;
|
|
553
419
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
554
420
|
}
|
|
555
|
-
return String(
|
|
421
|
+
return String(r);
|
|
556
422
|
}
|
|
557
|
-
function
|
|
558
|
-
typeof
|
|
423
|
+
function dt(r, t, e) {
|
|
424
|
+
typeof t == "symbol" && (t = (t = t.description) ? "[" + t + "]" : "");
|
|
559
425
|
try {
|
|
560
|
-
Object.defineProperty(
|
|
426
|
+
Object.defineProperty(r, "name", { configurable: !0, value: e ? e + " " + t : t });
|
|
561
427
|
} catch {
|
|
562
428
|
}
|
|
563
|
-
return
|
|
429
|
+
return r;
|
|
564
430
|
}
|
|
565
|
-
function
|
|
566
|
-
if (Object(
|
|
567
|
-
return
|
|
431
|
+
function Tt(r) {
|
|
432
|
+
if (Object(r) !== r) throw TypeError("right-hand side of 'in' should be an object, got " + (r !== null ? typeof r : "null"));
|
|
433
|
+
return r;
|
|
568
434
|
}
|
|
569
|
-
const
|
|
570
|
-
|
|
435
|
+
const R = rt("WsxRouter");
|
|
436
|
+
xt = [ct({
|
|
571
437
|
tagName: "wsx-router"
|
|
572
438
|
})];
|
|
573
|
-
let
|
|
574
|
-
class
|
|
439
|
+
let It;
|
|
440
|
+
class Vt extends nt {
|
|
575
441
|
constructor() {
|
|
576
442
|
super({
|
|
577
|
-
styles:
|
|
443
|
+
styles: ht,
|
|
578
444
|
styleName: "wsx-router"
|
|
579
|
-
}),
|
|
445
|
+
}), U(this, "_autoStyles", ht), 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", () => {
|
|
580
446
|
if (this.isHandlingRoute) {
|
|
581
|
-
|
|
447
|
+
R.debug("Route change already in progress, skipping");
|
|
582
448
|
return;
|
|
583
449
|
}
|
|
584
|
-
this.views.size === 0 && (this.collectViews(),
|
|
450
|
+
this.views.size === 0 && (this.collectViews(), R.debug(`WsxRouter re-collected views: ${this.views.size}`)), this.isHandlingRoute = !0;
|
|
585
451
|
try {
|
|
586
|
-
const
|
|
587
|
-
|
|
588
|
-
const
|
|
452
|
+
const t = window.location.pathname;
|
|
453
|
+
R.debug(`WsxRouter: Route changed to: ${t}`);
|
|
454
|
+
const e = new CustomEvent("before-navigate", {
|
|
589
455
|
detail: {
|
|
590
|
-
to:
|
|
456
|
+
to: t,
|
|
591
457
|
from: this.currentPath
|
|
592
458
|
},
|
|
593
459
|
bubbles: !0,
|
|
594
460
|
cancelable: !0
|
|
595
461
|
});
|
|
596
|
-
if (!this.dispatchEvent(
|
|
597
|
-
|
|
462
|
+
if (!this.dispatchEvent(e)) {
|
|
463
|
+
R.debug(`Navigation to ${t} was cancelled`);
|
|
598
464
|
return;
|
|
599
465
|
}
|
|
600
|
-
this.performNavigation(
|
|
466
|
+
this.performNavigation(t);
|
|
601
467
|
} finally {
|
|
602
468
|
requestAnimationFrame(() => {
|
|
603
469
|
this.isHandlingRoute = !1;
|
|
604
470
|
});
|
|
605
471
|
}
|
|
606
|
-
}),
|
|
607
|
-
const
|
|
608
|
-
if (!
|
|
609
|
-
const
|
|
610
|
-
!
|
|
472
|
+
}), U(this, "interceptLinks", (t) => {
|
|
473
|
+
const e = t.target.closest("a");
|
|
474
|
+
if (!e) return;
|
|
475
|
+
const n = e.getAttribute("href");
|
|
476
|
+
!n || n.startsWith("http") || n.startsWith("#") || (t.preventDefault(), this.navigate(n));
|
|
611
477
|
});
|
|
612
478
|
}
|
|
613
479
|
render() {
|
|
614
|
-
return /* @__PURE__ */
|
|
480
|
+
return /* @__PURE__ */ tt("div", { class: "router-outlet" });
|
|
615
481
|
}
|
|
616
482
|
onRendered() {
|
|
617
|
-
var
|
|
618
|
-
(
|
|
483
|
+
var t;
|
|
484
|
+
(t = super.onRendered) == null || t.call(this), this.views.size === 0 && (this.collectViews(), R.debug("WsxRouter collected views in onRendered:", this.views.size)), this.views.size > 0 && !this.currentView && requestAnimationFrame(() => {
|
|
619
485
|
this.handleRouteChange();
|
|
620
486
|
});
|
|
621
487
|
}
|
|
622
488
|
onConnected() {
|
|
623
|
-
var
|
|
624
|
-
(
|
|
625
|
-
this.views.size === 0 && (this.collectViews(),
|
|
626
|
-
|
|
489
|
+
var t;
|
|
490
|
+
(t = super.onConnected) == null || t.call(this), R.debug("WsxRouter connected to DOM"), "scrollRestoration" in history && (history.scrollRestoration = this.scrollRestoration), window.addEventListener("popstate", this.handleRouteChange), this.addEventListener("click", this.interceptLinks), requestAnimationFrame(() => {
|
|
491
|
+
this.views.size === 0 && (this.collectViews(), R.debug(`WsxRouter collected views in onConnected: ${this.views.size}`)), requestAnimationFrame(() => {
|
|
492
|
+
R.debug(`WsxRouter handling initial route: ${window.location.pathname}`), this.handleRouteChange();
|
|
627
493
|
});
|
|
628
494
|
});
|
|
629
495
|
}
|
|
630
496
|
onDisconnected() {
|
|
631
|
-
var
|
|
632
|
-
(
|
|
497
|
+
var t;
|
|
498
|
+
(t = super.onDisconnected) == null || t.call(this), window.removeEventListener("popstate", this.handleRouteChange);
|
|
633
499
|
}
|
|
634
500
|
collectViews() {
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
const
|
|
638
|
-
if (this.views.set(
|
|
639
|
-
const
|
|
640
|
-
this.compiledRoutes.set(
|
|
501
|
+
const t = Array.from(this.children).filter((e) => e.tagName.toLowerCase() === "wsx-view");
|
|
502
|
+
R.debug(`WsxRouter found ${t.length} views`), this.views.clear(), this.compiledRoutes.clear(), this.matchCache.clear(), t.forEach((e) => {
|
|
503
|
+
const n = e.getAttribute("route") || "/";
|
|
504
|
+
if (this.views.set(n, e), R.debug(`WsxRouter registered route: ${n}`), n.includes(":")) {
|
|
505
|
+
const f = n.replace(/:[^/]+/g, "([^/]+)"), v = new RegExp(`^${f}$`);
|
|
506
|
+
this.compiledRoutes.set(n, v), R.debug(`WsxRouter compiled regex for route: ${n} -> ${v}`);
|
|
641
507
|
}
|
|
642
|
-
|
|
508
|
+
e.style.display = "none";
|
|
643
509
|
});
|
|
644
510
|
}
|
|
645
511
|
/**
|
|
646
512
|
* RFC 0033: 执行导航(带 View Transitions 支持)
|
|
647
513
|
*/
|
|
648
|
-
performNavigation(
|
|
649
|
-
const
|
|
650
|
-
const
|
|
651
|
-
if (
|
|
652
|
-
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
for (const [
|
|
656
|
-
|
|
657
|
-
this.currentView =
|
|
658
|
-
const v = this.extractParams(
|
|
659
|
-
|
|
660
|
-
|
|
514
|
+
performNavigation(t) {
|
|
515
|
+
const e = () => {
|
|
516
|
+
const n = this.matchRoute(t);
|
|
517
|
+
if (n) {
|
|
518
|
+
n.style.display = "block", n.style.visibility = "visible";
|
|
519
|
+
const f = n.getAttribute("route") || "/";
|
|
520
|
+
R.debug(`Showing view for route: ${f}`);
|
|
521
|
+
for (const [z, q] of this.views)
|
|
522
|
+
q !== n && (q.style.display = "none", q.style.visibility = "");
|
|
523
|
+
this.currentView = n;
|
|
524
|
+
const v = this.extractParams(f, t);
|
|
525
|
+
R.debug(`Extracted params for route ${f} and path ${t}:`, v), v && requestAnimationFrame(() => {
|
|
526
|
+
n.setAttribute("params", JSON.stringify(v)), R.debug(`Set params attribute on view: ${JSON.stringify(v)}`);
|
|
661
527
|
});
|
|
662
|
-
const
|
|
663
|
-
path:
|
|
528
|
+
const y = window.location.href || `${window.location.pathname}${window.location.search}${window.location.hash}`, k = new URL(y, window.location.origin || "http://localhost"), b = {
|
|
529
|
+
path: t,
|
|
664
530
|
params: v || {},
|
|
665
|
-
query: Object.fromEntries(
|
|
666
|
-
hash:
|
|
531
|
+
query: Object.fromEntries(k.searchParams.entries()),
|
|
532
|
+
hash: k.hash.slice(1)
|
|
667
533
|
};
|
|
668
|
-
|
|
669
|
-
const
|
|
534
|
+
et._setCurrentRoute(b), R.debug("Updated RouterUtils._currentRoute:", b);
|
|
535
|
+
const j = new CustomEvent("route-changed", {
|
|
670
536
|
detail: b,
|
|
671
537
|
bubbles: !0
|
|
672
538
|
});
|
|
673
|
-
document.dispatchEvent(
|
|
539
|
+
document.dispatchEvent(j);
|
|
674
540
|
} else {
|
|
675
|
-
for (const [b,
|
|
676
|
-
|
|
677
|
-
this.currentView = null,
|
|
678
|
-
const
|
|
679
|
-
path:
|
|
541
|
+
for (const [b, j] of this.views)
|
|
542
|
+
j.style.display = "none";
|
|
543
|
+
this.currentView = null, R.warn(`No view found for path: ${t}`);
|
|
544
|
+
const f = window.location.href || `${window.location.pathname}${window.location.search}${window.location.hash}`, v = new URL(f, window.location.origin || "http://localhost"), y = {
|
|
545
|
+
path: t,
|
|
680
546
|
params: {},
|
|
681
547
|
query: Object.fromEntries(v.searchParams.entries()),
|
|
682
548
|
hash: v.hash.slice(1)
|
|
683
549
|
};
|
|
684
|
-
|
|
685
|
-
const
|
|
686
|
-
detail:
|
|
550
|
+
et._setCurrentRoute(y);
|
|
551
|
+
const k = new CustomEvent("route-changed", {
|
|
552
|
+
detail: y,
|
|
687
553
|
bubbles: !0
|
|
688
554
|
});
|
|
689
|
-
document.dispatchEvent(
|
|
555
|
+
document.dispatchEvent(k);
|
|
690
556
|
}
|
|
691
|
-
this.handleScrollRestoration(
|
|
557
|
+
this.handleScrollRestoration(t), this.dispatchEvent(new CustomEvent("after-navigate", {
|
|
692
558
|
detail: {
|
|
693
|
-
to:
|
|
559
|
+
to: t,
|
|
694
560
|
from: this.currentPath
|
|
695
561
|
},
|
|
696
562
|
bubbles: !0
|
|
697
|
-
})), this.currentPath =
|
|
563
|
+
})), this.currentPath = t;
|
|
698
564
|
};
|
|
699
|
-
this.enableViewTransitions && "startViewTransition" in document ? document.startViewTransition(
|
|
565
|
+
this.enableViewTransitions && "startViewTransition" in document ? document.startViewTransition(e) : e();
|
|
700
566
|
}
|
|
701
567
|
/**
|
|
702
568
|
* RFC 0033: 滚动恢复处理
|
|
703
569
|
*/
|
|
704
|
-
handleScrollRestoration(
|
|
705
|
-
this.scrollRestoration === "manual" && (this.isBackNavigation() || (window.scrollTo(0, 0),
|
|
570
|
+
handleScrollRestoration(t) {
|
|
571
|
+
this.scrollRestoration === "manual" && (this.isBackNavigation() || (window.scrollTo(0, 0), R.debug("Scrolled to top for forward navigation")));
|
|
706
572
|
}
|
|
707
573
|
/**
|
|
708
574
|
* RFC 0033: 检测是否是后退导航
|
|
709
575
|
*/
|
|
710
576
|
isBackNavigation() {
|
|
711
|
-
var
|
|
712
|
-
return "navigation" in performance && performance.navigation ? performance.navigation.type === 2 : ((
|
|
577
|
+
var t;
|
|
578
|
+
return "navigation" in performance && performance.navigation ? performance.navigation.type === 2 : ((t = window.history.state) == null ? void 0 : t.navigationType) === "back";
|
|
713
579
|
}
|
|
714
|
-
matchRoute(
|
|
715
|
-
if (
|
|
716
|
-
const
|
|
717
|
-
return
|
|
580
|
+
matchRoute(t) {
|
|
581
|
+
if (R.warn(`matchRoute called for path: ${t}, views count: ${this.views.size}`), this.matchCache.has(t)) {
|
|
582
|
+
const n = this.matchCache.get(t);
|
|
583
|
+
return R.warn(`matchRoute: found in cache, route: ${n}`), this.views.get(n) || null;
|
|
718
584
|
}
|
|
719
|
-
if (this.views.has(
|
|
720
|
-
return this.matchCache.set(
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
585
|
+
if (this.views.has(t))
|
|
586
|
+
return this.matchCache.set(t, t), R.warn(`matchRoute: exact match found for ${t}`), this.views.get(t);
|
|
587
|
+
for (const [n, f] of this.views)
|
|
588
|
+
if (n.endsWith("/*")) {
|
|
589
|
+
const v = n.slice(0, -2);
|
|
590
|
+
if (t.startsWith(v))
|
|
591
|
+
return this.matchCache.set(t, n), R.warn(`matchRoute: prefix match found, route: ${n}, path: ${t}`), f;
|
|
592
|
+
}
|
|
593
|
+
R.warn(`matchRoute: checking parameter routes, compiledRoutes count: ${this.compiledRoutes.size}`);
|
|
594
|
+
for (const [n, f] of this.views)
|
|
595
|
+
if (n.includes(":")) {
|
|
596
|
+
const v = this.compiledRoutes.get(n);
|
|
725
597
|
if (v) {
|
|
726
|
-
const
|
|
727
|
-
if (
|
|
728
|
-
return this.matchCache.set(
|
|
598
|
+
const y = v.test(t);
|
|
599
|
+
if (R.warn(`matchRoute: testing route ${n} against ${t}, matches: ${y}`), y)
|
|
600
|
+
return this.matchCache.set(t, n), R.warn(`matchRoute: parameter match found, route: ${n}, path: ${t}`), f;
|
|
729
601
|
} else
|
|
730
|
-
|
|
602
|
+
R.warn(`matchRoute: route ${n} has ':' but no compiled regex found`);
|
|
731
603
|
}
|
|
732
|
-
const
|
|
733
|
-
return
|
|
604
|
+
const e = this.views.get("*") || null;
|
|
605
|
+
return e ? (this.matchCache.set(t, "*"), R.warn(`matchRoute: wildcard match found for ${t}`)) : R.warn(`matchRoute: no match found for ${t}, no wildcard view available`), e;
|
|
734
606
|
}
|
|
735
|
-
extractParams(
|
|
607
|
+
extractParams(t, e) {
|
|
736
608
|
var b;
|
|
737
|
-
if (!
|
|
738
|
-
const
|
|
739
|
-
if (!
|
|
740
|
-
const
|
|
741
|
-
return
|
|
742
|
-
|
|
743
|
-
}),
|
|
609
|
+
if (!t.includes(":")) return null;
|
|
610
|
+
const n = ((b = t.match(/:([^/]+)/g)) == null ? void 0 : b.map((j) => j.slice(1))) || [], f = t.replace(/:[^/]+/g, "([^/]+)"), v = new RegExp(`^${f}$`), y = e.match(v);
|
|
611
|
+
if (!y || !n.length) return null;
|
|
612
|
+
const k = {};
|
|
613
|
+
return n.forEach((j, z) => {
|
|
614
|
+
k[j] = y[z + 1];
|
|
615
|
+
}), k;
|
|
744
616
|
}
|
|
745
617
|
/**
|
|
746
618
|
* RFC 0032: 清除匹配缓存
|
|
747
619
|
* 当路由配置变更时调用,确保使用最新的路由规则
|
|
748
620
|
*/
|
|
749
621
|
clearMatchCache() {
|
|
750
|
-
this.matchCache.clear(),
|
|
622
|
+
this.matchCache.clear(), R.debug("WsxRouter cleared match cache");
|
|
751
623
|
}
|
|
752
624
|
/**
|
|
753
625
|
* RFC 0033: 配置 View Transitions
|
|
754
626
|
*/
|
|
755
|
-
setViewTransitions(
|
|
756
|
-
this.enableViewTransitions =
|
|
627
|
+
setViewTransitions(t) {
|
|
628
|
+
this.enableViewTransitions = t, R.debug(`View Transitions ${t ? "enabled" : "disabled"}`);
|
|
757
629
|
}
|
|
758
630
|
/**
|
|
759
631
|
* RFC 0033: 配置 Scroll Restoration
|
|
760
632
|
*/
|
|
761
|
-
setScrollRestoration(
|
|
762
|
-
this.scrollRestoration =
|
|
633
|
+
setScrollRestoration(t) {
|
|
634
|
+
this.scrollRestoration = t, "scrollRestoration" in history && (history.scrollRestoration = t), R.debug(`Scroll Restoration set to ${t}`);
|
|
763
635
|
}
|
|
764
636
|
/**
|
|
765
637
|
* 编程式导航 - 使用原生 History API
|
|
766
638
|
*/
|
|
767
|
-
navigate(
|
|
768
|
-
window.history.pushState(null, "",
|
|
639
|
+
navigate(t) {
|
|
640
|
+
window.history.pushState(null, "", t), this.handleRouteChange();
|
|
769
641
|
}
|
|
770
642
|
}
|
|
771
|
-
|
|
772
|
-
[
|
|
773
|
-
|
|
774
|
-
const
|
|
775
|
-
var
|
|
776
|
-
let
|
|
777
|
-
function Z(
|
|
778
|
-
return (
|
|
643
|
+
yt = Vt;
|
|
644
|
+
[It, Rt] = At(yt, [], xt, 0, void 0, nt).c;
|
|
645
|
+
Rt();
|
|
646
|
+
const Dt = ":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}}";
|
|
647
|
+
var Ct;
|
|
648
|
+
let Et, Lt;
|
|
649
|
+
function Z(r, t, e) {
|
|
650
|
+
return (t = _t(t)) in r ? Object.defineProperty(r, t, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = e, r;
|
|
779
651
|
}
|
|
780
|
-
function
|
|
781
|
-
function
|
|
782
|
-
return function(
|
|
783
|
-
return
|
|
652
|
+
function Pt(r, t, e, n, f, v) {
|
|
653
|
+
function y(i, c, u) {
|
|
654
|
+
return function(s, a) {
|
|
655
|
+
return u && u(s), i[c].call(s, a);
|
|
784
656
|
};
|
|
785
657
|
}
|
|
786
|
-
function
|
|
787
|
-
for (var
|
|
788
|
-
return
|
|
658
|
+
function k(i, c) {
|
|
659
|
+
for (var u = 0; u < i.length; u++) i[u].call(c);
|
|
660
|
+
return c;
|
|
789
661
|
}
|
|
790
|
-
function b(
|
|
791
|
-
if (typeof
|
|
792
|
-
return
|
|
662
|
+
function b(i, c, u, s) {
|
|
663
|
+
if (typeof i != "function" && (s || i !== void 0)) throw new TypeError(c + " must " + (u || "be") + " a function" + (s ? "" : " or undefined"));
|
|
664
|
+
return i;
|
|
793
665
|
}
|
|
794
|
-
function
|
|
795
|
-
function
|
|
796
|
-
if (!m(
|
|
666
|
+
function j(i, c, u, s, a, A, O, S, D, x, w, g, m) {
|
|
667
|
+
function $(l) {
|
|
668
|
+
if (!m(l)) throw new TypeError("Attempted to access private element on non-instance");
|
|
797
669
|
}
|
|
798
|
-
var
|
|
670
|
+
var h, C = c[0], E = c[3], W = !S;
|
|
799
671
|
if (!W) {
|
|
800
|
-
|
|
801
|
-
var
|
|
802
|
-
|
|
803
|
-
return
|
|
804
|
-
},
|
|
805
|
-
|
|
806
|
-
} } :
|
|
672
|
+
u || Array.isArray(C) || (C = [C]);
|
|
673
|
+
var o = {}, L = [], p = a === 3 ? "get" : a === 4 || g ? "set" : "value";
|
|
674
|
+
x ? (w || g ? o = { get: ft(function() {
|
|
675
|
+
return E(this);
|
|
676
|
+
}, s, "get"), set: function(l) {
|
|
677
|
+
c[4](this, l);
|
|
678
|
+
} } : o[p] = E, w || ft(o[p], s, a === 2 ? "" : p)) : w || (o = Object.getOwnPropertyDescriptor(i, s));
|
|
807
679
|
}
|
|
808
|
-
for (var
|
|
809
|
-
var B =
|
|
810
|
-
if (
|
|
811
|
-
b(
|
|
680
|
+
for (var d = i, P = C.length - 1; P >= 0; P -= u ? 2 : 1) {
|
|
681
|
+
var B = C[P], F = u ? C[P - 1] : void 0, K = {}, T = { kind: ["field", "accessor", "method", "getter", "setter", "class"][a], name: s, metadata: A, addInitializer: (function(l, _) {
|
|
682
|
+
if (l.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
683
|
+
b(_, "An initializer", "be", !0), O.push(_);
|
|
812
684
|
}).bind(null, K) };
|
|
813
685
|
try {
|
|
814
|
-
if (W) (
|
|
686
|
+
if (W) (h = b(B.call(F, d, T), "class decorators", "return")) && (d = h);
|
|
815
687
|
else {
|
|
816
|
-
var
|
|
817
|
-
|
|
818
|
-
return
|
|
819
|
-
} : (
|
|
820
|
-
return
|
|
821
|
-
}, (
|
|
822
|
-
|
|
688
|
+
var I, M;
|
|
689
|
+
T.static = D, T.private = x, x ? a === 2 ? I = function(l) {
|
|
690
|
+
return $(l), o.value;
|
|
691
|
+
} : (a < 4 && (I = y(o, "get", $)), a !== 3 && (M = y(o, "set", $))) : (I = function(l) {
|
|
692
|
+
return l[s];
|
|
693
|
+
}, (a < 2 || a === 4) && (M = function(l, _) {
|
|
694
|
+
l[s] = _;
|
|
823
695
|
}));
|
|
824
|
-
var
|
|
825
|
-
return
|
|
696
|
+
var Q = T.access = { has: x ? m.bind() : function(l) {
|
|
697
|
+
return s in l;
|
|
826
698
|
} };
|
|
827
|
-
if (
|
|
828
|
-
if (typeof
|
|
829
|
-
else if (
|
|
830
|
-
} else b(
|
|
699
|
+
if (I && (Q.get = I), M && (Q.set = M), d = B.call(F, g ? { get: o.get, set: o.set } : o[p], T), g) {
|
|
700
|
+
if (typeof d == "object" && d) (h = b(d.get, "accessor.get")) && (o.get = h), (h = b(d.set, "accessor.set")) && (o.set = h), (h = b(d.init, "accessor.init")) && L.push(h);
|
|
701
|
+
else if (d !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
702
|
+
} else b(d, (w ? "field" : "method") + " decorators", "return") && (w ? L.push(d) : o[p] = d);
|
|
831
703
|
}
|
|
832
704
|
} finally {
|
|
833
705
|
K.v = !0;
|
|
834
706
|
}
|
|
835
707
|
}
|
|
836
|
-
return (
|
|
837
|
-
for (var N =
|
|
838
|
-
return
|
|
839
|
-
}),
|
|
840
|
-
}
|
|
841
|
-
function
|
|
842
|
-
return Object.defineProperty(
|
|
843
|
-
}
|
|
844
|
-
if (arguments.length >= 6) var
|
|
845
|
-
var
|
|
846
|
-
var
|
|
847
|
-
return
|
|
848
|
-
},
|
|
849
|
-
function
|
|
850
|
-
|
|
708
|
+
return (w || g) && S.push(function(l, _) {
|
|
709
|
+
for (var N = L.length - 1; N >= 0; N--) _ = L[N].call(l, _);
|
|
710
|
+
return _;
|
|
711
|
+
}), w || W || (x ? g ? S.push(y(o, "get"), y(o, "set")) : S.push(a === 2 ? o[p] : y.call.bind(o[p])) : Object.defineProperty(i, s, o)), d;
|
|
712
|
+
}
|
|
713
|
+
function z(i, c) {
|
|
714
|
+
return Object.defineProperty(i, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
|
|
715
|
+
}
|
|
716
|
+
if (arguments.length >= 6) var q = v[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
717
|
+
var V = Object.create(q ?? null), Y = function(i, c, u, s) {
|
|
718
|
+
var a, A, O = [], S = function(p) {
|
|
719
|
+
return zt(p) === i;
|
|
720
|
+
}, D = /* @__PURE__ */ new Map();
|
|
721
|
+
function x(p) {
|
|
722
|
+
p && O.push(k.bind(null, p));
|
|
851
723
|
}
|
|
852
|
-
for (var
|
|
853
|
-
var
|
|
854
|
-
if (Array.isArray(
|
|
855
|
-
var m =
|
|
856
|
-
if (!W && !
|
|
857
|
-
var
|
|
858
|
-
if (
|
|
859
|
-
|
|
724
|
+
for (var w = 0; w < c.length; w++) {
|
|
725
|
+
var g = c[w];
|
|
726
|
+
if (Array.isArray(g)) {
|
|
727
|
+
var m = g[1], $ = g[2], h = g.length > 3, C = 16 & m, E = !!(8 & m), W = (m &= 7) == 0, o = $ + "/" + E;
|
|
728
|
+
if (!W && !h) {
|
|
729
|
+
var L = D.get(o);
|
|
730
|
+
if (L === !0 || L === 3 && m !== 4 || L === 4 && m !== 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: " + $);
|
|
731
|
+
D.set(o, !(m > 2) || m);
|
|
860
732
|
}
|
|
861
|
-
|
|
733
|
+
j(E ? i : i.prototype, g, C, h ? "#" + $ : _t($), m, s, E ? A = A || [] : a = a || [], O, E, h, W, m === 1, E && h ? S : u);
|
|
862
734
|
}
|
|
863
735
|
}
|
|
864
|
-
return
|
|
865
|
-
}(
|
|
866
|
-
return
|
|
867
|
-
var
|
|
868
|
-
return
|
|
736
|
+
return x(a), x(A), O;
|
|
737
|
+
}(r, t, f, V);
|
|
738
|
+
return e.length || z(r, V), { e: Y, get c() {
|
|
739
|
+
var i = [];
|
|
740
|
+
return e.length && [z(j(r, [e], n, r.name, 5, V, i), V), k.bind(null, i, r)];
|
|
869
741
|
} };
|
|
870
742
|
}
|
|
871
|
-
function
|
|
872
|
-
var
|
|
873
|
-
return typeof
|
|
743
|
+
function _t(r) {
|
|
744
|
+
var t = Mt(r, "string");
|
|
745
|
+
return typeof t == "symbol" ? t : t + "";
|
|
874
746
|
}
|
|
875
|
-
function
|
|
876
|
-
if (typeof
|
|
877
|
-
var
|
|
878
|
-
if (
|
|
879
|
-
var
|
|
880
|
-
if (typeof
|
|
747
|
+
function Mt(r, t) {
|
|
748
|
+
if (typeof r != "object" || !r) return r;
|
|
749
|
+
var e = r[Symbol.toPrimitive];
|
|
750
|
+
if (e !== void 0) {
|
|
751
|
+
var n = e.call(r, t);
|
|
752
|
+
if (typeof n != "object") return n;
|
|
881
753
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
882
754
|
}
|
|
883
|
-
return String(
|
|
755
|
+
return String(r);
|
|
884
756
|
}
|
|
885
|
-
function
|
|
886
|
-
typeof
|
|
757
|
+
function ft(r, t, e) {
|
|
758
|
+
typeof t == "symbol" && (t = (t = t.description) ? "[" + t + "]" : "");
|
|
887
759
|
try {
|
|
888
|
-
Object.defineProperty(
|
|
760
|
+
Object.defineProperty(r, "name", { configurable: !0, value: e ? e + " " + t : t });
|
|
889
761
|
} catch {
|
|
890
762
|
}
|
|
891
|
-
return
|
|
763
|
+
return r;
|
|
892
764
|
}
|
|
893
|
-
function
|
|
894
|
-
if (Object(
|
|
895
|
-
return
|
|
765
|
+
function zt(r) {
|
|
766
|
+
if (Object(r) !== r) throw TypeError("right-hand side of 'in' should be an object, got " + (r !== null ? typeof r : "null"));
|
|
767
|
+
return r;
|
|
896
768
|
}
|
|
897
|
-
const
|
|
898
|
-
|
|
769
|
+
const H = rt("WsxView");
|
|
770
|
+
Lt = [ct({
|
|
899
771
|
tagName: "wsx-view"
|
|
900
772
|
})];
|
|
901
|
-
let
|
|
902
|
-
class
|
|
773
|
+
let qt;
|
|
774
|
+
class Nt extends nt {
|
|
903
775
|
constructor() {
|
|
904
|
-
super(), Z(this, "_autoStyles",
|
|
905
|
-
let
|
|
776
|
+
super(), Z(this, "_autoStyles", Dt), Z(this, "_component", ""), Z(this, "params", void 0), Z(this, "componentInstance", null), Z(this, "isLoading", !1);
|
|
777
|
+
let t = this.reactive({});
|
|
906
778
|
Object.defineProperty(this, "params", {
|
|
907
|
-
get: () =>
|
|
908
|
-
set: (
|
|
909
|
-
|
|
779
|
+
get: () => t,
|
|
780
|
+
set: (e) => {
|
|
781
|
+
t = e !== null && typeof e < "u" && (Array.isArray(e) || typeof e == "object") ? this.reactive(e) : e, this.scheduleRerender();
|
|
910
782
|
},
|
|
911
783
|
enumerable: !0,
|
|
912
784
|
configurable: !0
|
|
@@ -915,218 +787,218 @@ class Ke extends re {
|
|
|
915
787
|
get component() {
|
|
916
788
|
return this._component;
|
|
917
789
|
}
|
|
918
|
-
set component(
|
|
919
|
-
this._component =
|
|
790
|
+
set component(t) {
|
|
791
|
+
this._component = t || "", this._component && requestAnimationFrame(() => {
|
|
920
792
|
this.connected && !this.componentInstance && !this.isLoading && this.loadComponent(this._component || "");
|
|
921
793
|
});
|
|
922
794
|
}
|
|
923
795
|
// 防止重复加载的标志
|
|
924
796
|
render() {
|
|
925
|
-
return /* @__PURE__ */
|
|
797
|
+
return /* @__PURE__ */ tt("div", { class: "route-view" });
|
|
926
798
|
}
|
|
927
799
|
onConnected() {
|
|
928
|
-
var
|
|
929
|
-
(
|
|
800
|
+
var t;
|
|
801
|
+
(t = super.onConnected) == null || t.call(this), requestAnimationFrame(() => {
|
|
930
802
|
!this.connected || this.isLoading || this.componentInstance || this.component && this.loadComponent(this.component);
|
|
931
803
|
});
|
|
932
804
|
}
|
|
933
|
-
async loadComponent(
|
|
805
|
+
async loadComponent(t) {
|
|
934
806
|
if (!(!this.connected || this.isLoading || this.componentInstance)) {
|
|
935
807
|
this.isLoading = !0;
|
|
936
808
|
try {
|
|
937
|
-
const
|
|
938
|
-
if (
|
|
939
|
-
|
|
809
|
+
const e = this.componentInstance;
|
|
810
|
+
if (e && (e.remove(), this.componentInstance = null), !customElements.get(t)) {
|
|
811
|
+
H.warn(`Component ${t} not found in customElements registry`), this.isLoading = !1;
|
|
940
812
|
return;
|
|
941
813
|
}
|
|
942
|
-
|
|
943
|
-
this.componentInstance.setAttribute(v,
|
|
814
|
+
H.warn(`WsxView: Creating instance of ${t}`), this.componentInstance = document.createElement(t), Object.keys(this.params).length > 0 && (H.warn(`WsxView: Setting initial params on ${t}:`, this.params), Object.entries(this.params).forEach(([v, y]) => {
|
|
815
|
+
this.componentInstance.setAttribute(v, y);
|
|
944
816
|
}));
|
|
945
|
-
const
|
|
946
|
-
if (
|
|
947
|
-
if (
|
|
948
|
-
|
|
817
|
+
const f = this.querySelector(".route-view");
|
|
818
|
+
if (f) {
|
|
819
|
+
if (H.warn(`WsxView: Appending ${t} to container`), !customElements.get(t)) {
|
|
820
|
+
H.error(`WsxView: Component ${t} is not registered in customElements registry!`), this.isLoading = !1, this.componentInstance = null;
|
|
949
821
|
return;
|
|
950
822
|
}
|
|
951
|
-
|
|
952
|
-
this.componentInstance && this.componentInstance.isConnected ?
|
|
823
|
+
f.appendChild(this.componentInstance), H.warn(`WsxView: Component ${t} appended successfully, waiting for connectedCallback...`), setTimeout(() => {
|
|
824
|
+
this.componentInstance && this.componentInstance.isConnected ? H.warn(`WsxView: Component ${t} is now connected to DOM`) : H.error(`WsxView: Component ${t} was not connected to DOM!`);
|
|
953
825
|
}, 0);
|
|
954
826
|
} else
|
|
955
|
-
|
|
956
|
-
} catch (
|
|
957
|
-
|
|
827
|
+
H.error("WsxView: Route view container not found"), this.componentInstance = null;
|
|
828
|
+
} catch (e) {
|
|
829
|
+
H.warn(`Error loading component ${t}:`, e), this.componentInstance = null;
|
|
958
830
|
} finally {
|
|
959
|
-
this.isLoading = !1,
|
|
831
|
+
this.isLoading = !1, H.warn(`WsxView: loadComponent for ${t} completed, isLoading=${this.isLoading}`);
|
|
960
832
|
}
|
|
961
833
|
}
|
|
962
834
|
}
|
|
963
835
|
onDisconnected() {
|
|
964
|
-
var
|
|
965
|
-
(
|
|
836
|
+
var t;
|
|
837
|
+
(t = super.onDisconnected) == null || t.call(this), this.componentInstance && (this.componentInstance.remove(), this.componentInstance = null);
|
|
966
838
|
}
|
|
967
839
|
}
|
|
968
|
-
|
|
969
|
-
[
|
|
970
|
-
|
|
971
|
-
const
|
|
972
|
-
var
|
|
973
|
-
let
|
|
974
|
-
function
|
|
975
|
-
return (
|
|
840
|
+
Ct = Nt;
|
|
841
|
+
[qt, Et] = Pt(Ct, [], Lt, 0, void 0, nt).c;
|
|
842
|
+
Et();
|
|
843
|
+
const Ut = ':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)}';
|
|
844
|
+
var ot, st;
|
|
845
|
+
let gt, kt, mt;
|
|
846
|
+
function X(r, t, e) {
|
|
847
|
+
return (t = St(t)) in r ? Object.defineProperty(r, t, { value: e, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = e, r;
|
|
976
848
|
}
|
|
977
|
-
function
|
|
978
|
-
function
|
|
979
|
-
return function(
|
|
980
|
-
return
|
|
849
|
+
function Ht(r, t, e, n, f, v) {
|
|
850
|
+
function y(i, c, u) {
|
|
851
|
+
return function(s, a) {
|
|
852
|
+
return u && u(s), i[c].call(s, a);
|
|
981
853
|
};
|
|
982
854
|
}
|
|
983
|
-
function
|
|
984
|
-
for (var
|
|
985
|
-
return
|
|
855
|
+
function k(i, c) {
|
|
856
|
+
for (var u = 0; u < i.length; u++) i[u].call(c);
|
|
857
|
+
return c;
|
|
986
858
|
}
|
|
987
|
-
function b(
|
|
988
|
-
if (typeof
|
|
989
|
-
return
|
|
859
|
+
function b(i, c, u, s) {
|
|
860
|
+
if (typeof i != "function" && (s || i !== void 0)) throw new TypeError(c + " must " + (u || "be") + " a function" + (s ? "" : " or undefined"));
|
|
861
|
+
return i;
|
|
990
862
|
}
|
|
991
|
-
function
|
|
992
|
-
function
|
|
993
|
-
if (!m(
|
|
863
|
+
function j(i, c, u, s, a, A, O, S, D, x, w, g, m) {
|
|
864
|
+
function $(l) {
|
|
865
|
+
if (!m(l)) throw new TypeError("Attempted to access private element on non-instance");
|
|
994
866
|
}
|
|
995
|
-
var
|
|
867
|
+
var h, C = c[0], E = c[3], W = !S;
|
|
996
868
|
if (!W) {
|
|
997
|
-
|
|
998
|
-
var
|
|
999
|
-
|
|
1000
|
-
return
|
|
1001
|
-
},
|
|
1002
|
-
|
|
1003
|
-
} } :
|
|
869
|
+
u || Array.isArray(C) || (C = [C]);
|
|
870
|
+
var o = {}, L = [], p = a === 3 ? "get" : a === 4 || g ? "set" : "value";
|
|
871
|
+
x ? (w || g ? o = { get: pt(function() {
|
|
872
|
+
return E(this);
|
|
873
|
+
}, s, "get"), set: function(l) {
|
|
874
|
+
c[4](this, l);
|
|
875
|
+
} } : o[p] = E, w || pt(o[p], s, a === 2 ? "" : p)) : w || (o = Object.getOwnPropertyDescriptor(i, s));
|
|
1004
876
|
}
|
|
1005
|
-
for (var
|
|
1006
|
-
var B =
|
|
1007
|
-
if (
|
|
1008
|
-
b(
|
|
877
|
+
for (var d = i, P = C.length - 1; P >= 0; P -= u ? 2 : 1) {
|
|
878
|
+
var B = C[P], F = u ? C[P - 1] : void 0, K = {}, T = { kind: ["field", "accessor", "method", "getter", "setter", "class"][a], name: s, metadata: A, addInitializer: (function(l, _) {
|
|
879
|
+
if (l.v) throw Error("attempted to call addInitializer after decoration was finished");
|
|
880
|
+
b(_, "An initializer", "be", !0), O.push(_);
|
|
1009
881
|
}).bind(null, K) };
|
|
1010
882
|
try {
|
|
1011
|
-
if (W) (
|
|
883
|
+
if (W) (h = b(B.call(F, d, T), "class decorators", "return")) && (d = h);
|
|
1012
884
|
else {
|
|
1013
|
-
var
|
|
1014
|
-
|
|
1015
|
-
return
|
|
1016
|
-
} : (
|
|
1017
|
-
return
|
|
1018
|
-
}, (
|
|
1019
|
-
|
|
885
|
+
var I, M;
|
|
886
|
+
T.static = D, T.private = x, x ? a === 2 ? I = function(l) {
|
|
887
|
+
return $(l), o.value;
|
|
888
|
+
} : (a < 4 && (I = y(o, "get", $)), a !== 3 && (M = y(o, "set", $))) : (I = function(l) {
|
|
889
|
+
return l[s];
|
|
890
|
+
}, (a < 2 || a === 4) && (M = function(l, _) {
|
|
891
|
+
l[s] = _;
|
|
1020
892
|
}));
|
|
1021
|
-
var
|
|
1022
|
-
return
|
|
893
|
+
var Q = T.access = { has: x ? m.bind() : function(l) {
|
|
894
|
+
return s in l;
|
|
1023
895
|
} };
|
|
1024
|
-
if (
|
|
1025
|
-
if (typeof
|
|
1026
|
-
else if (
|
|
1027
|
-
} else b(
|
|
896
|
+
if (I && (Q.get = I), M && (Q.set = M), d = B.call(F, g ? { get: o.get, set: o.set } : o[p], T), g) {
|
|
897
|
+
if (typeof d == "object" && d) (h = b(d.get, "accessor.get")) && (o.get = h), (h = b(d.set, "accessor.set")) && (o.set = h), (h = b(d.init, "accessor.init")) && L.push(h);
|
|
898
|
+
else if (d !== void 0) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
899
|
+
} else b(d, (w ? "field" : "method") + " decorators", "return") && (w ? L.push(d) : o[p] = d);
|
|
1028
900
|
}
|
|
1029
901
|
} finally {
|
|
1030
902
|
K.v = !0;
|
|
1031
903
|
}
|
|
1032
904
|
}
|
|
1033
|
-
return (
|
|
1034
|
-
for (var N =
|
|
1035
|
-
return
|
|
1036
|
-
}),
|
|
1037
|
-
}
|
|
1038
|
-
function
|
|
1039
|
-
return Object.defineProperty(
|
|
1040
|
-
}
|
|
1041
|
-
if (arguments.length >= 6) var
|
|
1042
|
-
var
|
|
1043
|
-
var
|
|
1044
|
-
return
|
|
1045
|
-
},
|
|
1046
|
-
function
|
|
1047
|
-
|
|
905
|
+
return (w || g) && S.push(function(l, _) {
|
|
906
|
+
for (var N = L.length - 1; N >= 0; N--) _ = L[N].call(l, _);
|
|
907
|
+
return _;
|
|
908
|
+
}), w || W || (x ? g ? S.push(y(o, "get"), y(o, "set")) : S.push(a === 2 ? o[p] : y.call.bind(o[p])) : Object.defineProperty(i, s, o)), d;
|
|
909
|
+
}
|
|
910
|
+
function z(i, c) {
|
|
911
|
+
return Object.defineProperty(i, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: c });
|
|
912
|
+
}
|
|
913
|
+
if (arguments.length >= 6) var q = v[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
914
|
+
var V = Object.create(q ?? null), Y = function(i, c, u, s) {
|
|
915
|
+
var a, A, O = [], S = function(p) {
|
|
916
|
+
return Ft(p) === i;
|
|
917
|
+
}, D = /* @__PURE__ */ new Map();
|
|
918
|
+
function x(p) {
|
|
919
|
+
p && O.push(k.bind(null, p));
|
|
1048
920
|
}
|
|
1049
|
-
for (var
|
|
1050
|
-
var
|
|
1051
|
-
if (Array.isArray(
|
|
1052
|
-
var m =
|
|
1053
|
-
if (!W && !
|
|
1054
|
-
var
|
|
1055
|
-
if (
|
|
1056
|
-
|
|
921
|
+
for (var w = 0; w < c.length; w++) {
|
|
922
|
+
var g = c[w];
|
|
923
|
+
if (Array.isArray(g)) {
|
|
924
|
+
var m = g[1], $ = g[2], h = g.length > 3, C = 16 & m, E = !!(8 & m), W = (m &= 7) == 0, o = $ + "/" + E;
|
|
925
|
+
if (!W && !h) {
|
|
926
|
+
var L = D.get(o);
|
|
927
|
+
if (L === !0 || L === 3 && m !== 4 || L === 4 && m !== 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: " + $);
|
|
928
|
+
D.set(o, !(m > 2) || m);
|
|
1057
929
|
}
|
|
1058
|
-
|
|
930
|
+
j(E ? i : i.prototype, g, C, h ? "#" + $ : St($), m, s, E ? A = A || [] : a = a || [], O, E, h, W, m === 1, E && h ? S : u);
|
|
1059
931
|
}
|
|
1060
932
|
}
|
|
1061
|
-
return
|
|
1062
|
-
}(
|
|
1063
|
-
return
|
|
1064
|
-
var
|
|
1065
|
-
return
|
|
933
|
+
return x(a), x(A), O;
|
|
934
|
+
}(r, t, f, V);
|
|
935
|
+
return e.length || z(r, V), { e: Y, get c() {
|
|
936
|
+
var i = [];
|
|
937
|
+
return e.length && [z(j(r, [e], n, r.name, 5, V, i), V), k.bind(null, i, r)];
|
|
1066
938
|
} };
|
|
1067
939
|
}
|
|
1068
|
-
function
|
|
1069
|
-
var
|
|
1070
|
-
return typeof
|
|
940
|
+
function St(r) {
|
|
941
|
+
var t = Bt(r, "string");
|
|
942
|
+
return typeof t == "symbol" ? t : t + "";
|
|
1071
943
|
}
|
|
1072
|
-
function
|
|
1073
|
-
if (typeof
|
|
1074
|
-
var
|
|
1075
|
-
if (
|
|
1076
|
-
var
|
|
1077
|
-
if (typeof
|
|
944
|
+
function Bt(r, t) {
|
|
945
|
+
if (typeof r != "object" || !r) return r;
|
|
946
|
+
var e = r[Symbol.toPrimitive];
|
|
947
|
+
if (e !== void 0) {
|
|
948
|
+
var n = e.call(r, t);
|
|
949
|
+
if (typeof n != "object") return n;
|
|
1078
950
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1079
951
|
}
|
|
1080
|
-
return (
|
|
952
|
+
return (t === "string" ? String : Number)(r);
|
|
1081
953
|
}
|
|
1082
|
-
function
|
|
1083
|
-
typeof
|
|
954
|
+
function pt(r, t, e) {
|
|
955
|
+
typeof t == "symbol" && (t = (t = t.description) ? "[" + t + "]" : "");
|
|
1084
956
|
try {
|
|
1085
|
-
Object.defineProperty(
|
|
957
|
+
Object.defineProperty(r, "name", { configurable: !0, value: e ? e + " " + t : t });
|
|
1086
958
|
} catch {
|
|
1087
959
|
}
|
|
1088
|
-
return
|
|
960
|
+
return r;
|
|
1089
961
|
}
|
|
1090
|
-
function
|
|
1091
|
-
if (Object(
|
|
1092
|
-
return
|
|
962
|
+
function Ft(r) {
|
|
963
|
+
if (Object(r) !== r) throw TypeError("right-hand side of 'in' should be an object, got " + (r !== null ? typeof r : "null"));
|
|
964
|
+
return r;
|
|
1093
965
|
}
|
|
1094
|
-
function
|
|
1095
|
-
return
|
|
966
|
+
function Kt(r) {
|
|
967
|
+
return r;
|
|
1096
968
|
}
|
|
1097
|
-
const
|
|
1098
|
-
|
|
969
|
+
const vt = rt("WsxLink");
|
|
970
|
+
kt = [ct({
|
|
1099
971
|
tagName: "wsx-link"
|
|
1100
972
|
})];
|
|
1101
|
-
let
|
|
1102
|
-
new (
|
|
973
|
+
let bt;
|
|
974
|
+
new (mt = (st = class extends lt {
|
|
1103
975
|
constructor() {
|
|
1104
|
-
super(),
|
|
976
|
+
super(), X(this, "_autoStyles", Ut), X(this, "to", void 0), X(this, "activeClass", void 0), X(this, "handleClick", (v) => {
|
|
1105
977
|
if (v.preventDefault(), !this.to) {
|
|
1106
|
-
|
|
978
|
+
vt.warn("No 'to' attribute specified");
|
|
1107
979
|
return;
|
|
1108
980
|
}
|
|
1109
981
|
if (this.isExternalLink(this.to)) {
|
|
1110
982
|
window.open(this.to, "_blank");
|
|
1111
983
|
return;
|
|
1112
984
|
}
|
|
1113
|
-
this.replace ? window.history.replaceState(null, "", this.to) : window.history.pushState(null, "", this.to), window.dispatchEvent(new PopStateEvent("popstate")),
|
|
1114
|
-
}),
|
|
985
|
+
this.replace ? window.history.replaceState(null, "", this.to) : window.history.pushState(null, "", this.to), window.dispatchEvent(new PopStateEvent("popstate")), vt.debug(`Navigated to: ${this.to}`);
|
|
986
|
+
}), X(this, "updateActiveState", () => {
|
|
1115
987
|
var b;
|
|
1116
|
-
const v = window.location.pathname,
|
|
1117
|
-
|
|
988
|
+
const v = window.location.pathname, y = this.exact ? v === this.to : v.startsWith(this.to) && this.to !== "/", k = (b = this.shadowRoot) == null ? void 0 : b.querySelector("a");
|
|
989
|
+
k && (y ? (k.classList.add(this.activeClass), this.setAttribute("active", "")) : (k.classList.remove(this.activeClass), this.removeAttribute("active")));
|
|
1118
990
|
});
|
|
1119
|
-
const [
|
|
991
|
+
const [t, e] = this.useState("to", "");
|
|
1120
992
|
Object.defineProperty(this, "to", {
|
|
1121
|
-
get:
|
|
1122
|
-
set:
|
|
993
|
+
get: t,
|
|
994
|
+
set: e,
|
|
1123
995
|
enumerable: !0,
|
|
1124
996
|
configurable: !0
|
|
1125
997
|
});
|
|
1126
|
-
const [
|
|
998
|
+
const [n, f] = this.useState("activeClass", "active");
|
|
1127
999
|
Object.defineProperty(this, "activeClass", {
|
|
1128
|
-
get:
|
|
1129
|
-
set:
|
|
1000
|
+
get: n,
|
|
1001
|
+
set: f,
|
|
1130
1002
|
enumerable: !0,
|
|
1131
1003
|
configurable: !0
|
|
1132
1004
|
});
|
|
@@ -1138,36 +1010,36 @@ new (ge = (se = class extends le {
|
|
|
1138
1010
|
return this.hasAttribute("exact");
|
|
1139
1011
|
}
|
|
1140
1012
|
render() {
|
|
1141
|
-
return /* @__PURE__ */
|
|
1013
|
+
return /* @__PURE__ */ tt("a", { href: this.to, class: "wsx-link", onClick: this.handleClick, part: "link" }, /* @__PURE__ */ tt("slot", null));
|
|
1142
1014
|
}
|
|
1143
1015
|
onConnected() {
|
|
1144
|
-
var
|
|
1145
|
-
(
|
|
1146
|
-
const
|
|
1147
|
-
|
|
1016
|
+
var e;
|
|
1017
|
+
(e = super.onConnected) == null || e.call(this), this.to = this.to || "", this.activeClass = this.activeClass || "active";
|
|
1018
|
+
const t = this.shadowRoot.querySelector(".wsx-link");
|
|
1019
|
+
t && (t.href = this.to), window.addEventListener("popstate", this.updateActiveState), document.addEventListener("route-changed", this.updateActiveState), this.updateActiveState();
|
|
1148
1020
|
}
|
|
1149
1021
|
onDisconnected() {
|
|
1150
|
-
var
|
|
1151
|
-
(
|
|
1022
|
+
var t;
|
|
1023
|
+
(t = super.onDisconnected) == null || t.call(this), window.removeEventListener("popstate", this.updateActiveState), document.removeEventListener("route-changed", this.updateActiveState);
|
|
1152
1024
|
}
|
|
1153
|
-
onAttributeChanged(
|
|
1154
|
-
switch (
|
|
1025
|
+
onAttributeChanged(t, e, n) {
|
|
1026
|
+
switch (t) {
|
|
1155
1027
|
case "to":
|
|
1156
|
-
this.to =
|
|
1028
|
+
this.to = n || "", this.updateActiveState();
|
|
1157
1029
|
break;
|
|
1158
1030
|
case "replace":
|
|
1159
|
-
this.replace =
|
|
1031
|
+
this.replace = n !== null && n !== "false";
|
|
1160
1032
|
break;
|
|
1161
1033
|
case "active-class":
|
|
1162
|
-
this.activeClass =
|
|
1034
|
+
this.activeClass = n || "active", this.updateActiveState();
|
|
1163
1035
|
break;
|
|
1164
1036
|
case "exact":
|
|
1165
|
-
this.exact =
|
|
1037
|
+
this.exact = n !== null && n !== "false", this.updateActiveState();
|
|
1166
1038
|
break;
|
|
1167
1039
|
}
|
|
1168
1040
|
}
|
|
1169
|
-
isExternalLink(
|
|
1170
|
-
return
|
|
1041
|
+
isExternalLink(t) {
|
|
1042
|
+
return t.startsWith("http://") || t.startsWith("https://") || t.startsWith("mailto:") || t.startsWith("tel:");
|
|
1171
1043
|
}
|
|
1172
1044
|
/**
|
|
1173
1045
|
* 编程式导航
|
|
@@ -1178,14 +1050,14 @@ new (ge = (se = class extends le {
|
|
|
1178
1050
|
cancelable: !0
|
|
1179
1051
|
}));
|
|
1180
1052
|
}
|
|
1181
|
-
}, [
|
|
1053
|
+
}, [bt, gt] = Ht(st, [], kt, 0, void 0, lt).c, st), ot = class extends Kt {
|
|
1182
1054
|
constructor() {
|
|
1183
|
-
super(
|
|
1055
|
+
super(bt), X(this, "observedAttributes", ["to", "replace", "active-class", "exact"]), gt();
|
|
1184
1056
|
}
|
|
1185
|
-
},
|
|
1057
|
+
}, X(ot, mt, void 0), ot)();
|
|
1186
1058
|
export {
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1059
|
+
et as RouterUtils,
|
|
1060
|
+
bt as WsxLink,
|
|
1061
|
+
It as WsxRouter,
|
|
1062
|
+
qt as WsxView
|
|
1191
1063
|
};
|