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