wj-elements 0.0.11 → 0.0.13

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.
Files changed (79) hide show
  1. package/dist/localize-20081fd1.js +55 -0
  2. package/dist/router-links-26e4a166.js +204 -0
  3. package/dist/style.css +2243 -2
  4. package/dist/wj-animation.js +35 -23
  5. package/dist/wj-aside.js +22 -16
  6. package/dist/wj-avatar.js +49 -30
  7. package/dist/wj-badge.js +22 -18
  8. package/dist/wj-breadcrumb.js +102 -50
  9. package/dist/wj-breadcrumbs.js +36 -19
  10. package/dist/wj-button-group.js +36 -22
  11. package/dist/wj-button.js +104 -39
  12. package/dist/wj-card-content.js +18 -14
  13. package/dist/wj-card-controls.js +18 -14
  14. package/dist/wj-card-header.js +20 -14
  15. package/dist/wj-card-subtitle.js +19 -15
  16. package/dist/wj-card-title.js +18 -14
  17. package/dist/wj-card.js +20 -14
  18. package/dist/wj-carousel-item.js +22 -16
  19. package/dist/wj-carousel.js +169 -92
  20. package/dist/wj-checkbox.js +46 -24
  21. package/dist/wj-chip.js +39 -21
  22. package/dist/wj-col.js +31 -17
  23. package/dist/wj-color-picker.js +877 -509
  24. package/dist/wj-container.js +20 -16
  25. package/dist/wj-copy-button.js +112 -64
  26. package/dist/wj-dialog.js +68 -42
  27. package/dist/wj-divider.js +20 -14
  28. package/dist/wj-dropdown.js +29 -17
  29. package/dist/wj-element.js +415 -241
  30. package/dist/wj-fetchAndParseCSS.js +49 -32
  31. package/dist/wj-file-upload-item.js +64 -38
  32. package/dist/wj-file-upload.js +237 -137
  33. package/dist/wj-footer.js +18 -14
  34. package/dist/wj-form.js +18 -14
  35. package/dist/wj-format-digital.js +40 -25
  36. package/dist/wj-grid.js +20 -16
  37. package/dist/wj-header.js +22 -16
  38. package/dist/wj-icon-picker.js +122 -68
  39. package/dist/wj-icon.js +144 -64
  40. package/dist/wj-img-comparer.js +72 -41
  41. package/dist/wj-img.js +31 -19
  42. package/dist/wj-infinite-scroll.js +90 -52
  43. package/dist/wj-input-file.js +50 -27
  44. package/dist/wj-input.js +169 -70
  45. package/dist/wj-item.js +34 -17
  46. package/dist/wj-label.js +21 -19
  47. package/dist/wj-list.js +20 -15
  48. package/dist/wj-main.js +18 -14
  49. package/dist/wj-masonry.js +140 -83
  50. package/dist/wj-master.js +492 -350
  51. package/dist/wj-menu-button.js +19 -15
  52. package/dist/wj-menu-item.js +150 -64
  53. package/dist/wj-menu-label.js +21 -17
  54. package/dist/wj-menu.js +24 -18
  55. package/dist/wj-popup.js +1140 -712
  56. package/dist/wj-progress-bar.js +100 -40
  57. package/dist/wj-radio-group.js +38 -25
  58. package/dist/wj-radio.js +46 -22
  59. package/dist/wj-rate.js +121 -71
  60. package/dist/wj-relative-time.js +48 -24
  61. package/dist/wj-route.js +11 -8
  62. package/dist/wj-router-link.js +22 -17
  63. package/dist/wj-router-outlet.js +135 -71
  64. package/dist/wj-routerx.js +1124 -641
  65. package/dist/wj-row.js +21 -19
  66. package/dist/wj-slider.js +97 -55
  67. package/dist/wj-split-view.js +81 -43
  68. package/dist/wj-store.js +195 -110
  69. package/dist/wj-textarea.js +86 -37
  70. package/dist/wj-thumbnail.js +19 -15
  71. package/dist/wj-toast.js +87 -34
  72. package/dist/wj-toggle.js +42 -24
  73. package/dist/wj-toolbar-action.js +27 -16
  74. package/dist/wj-toolbar.js +26 -19
  75. package/dist/wj-tooltip.js +40 -24
  76. package/dist/wj-visually-hidden.js +18 -14
  77. package/package.json +1 -1
  78. package/dist/localize-762a9f0f.js +0 -43
  79. package/dist/router-links-e0087f84.js +0 -146
@@ -1,254 +1,379 @@
1
- var st = Object.defineProperty;
2
- var ot = (r, t, e) => t in r ? st(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var A = (r, t, e) => (ot(r, typeof t != "symbol" ? t + "" : t, e), e);
4
- import at from "./wj-element.js";
5
- import { r as ct } from "./router-links-e0087f84.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import WJElement from "./wj-element.js";
8
+ import { r as routerLinks } from "./router-links-26e4a166.js";
6
9
  import "./wj-store.js";
7
- var z = "/";
8
- function ut(r, t, e, n) {
9
- for (var i = 0, s = n; s < e.length; ) {
10
- if (e[s] === "\\") {
11
- s += 2;
10
+ var DEFAULT_DELIMITER = "/";
11
+ function balanced(open, close, str, index) {
12
+ var count = 0;
13
+ var i = index;
14
+ while (i < str.length) {
15
+ if (str[i] === "\\") {
16
+ i += 2;
12
17
  continue;
13
18
  }
14
- if (e[s] === t && (i--, i === 0))
15
- return s + 1;
16
- e[s] === r && i++, s++;
19
+ if (str[i] === close) {
20
+ count--;
21
+ if (count === 0)
22
+ return i + 1;
23
+ }
24
+ if (str[i] === open) {
25
+ count++;
26
+ }
27
+ i++;
17
28
  }
18
29
  return -1;
19
30
  }
20
- function ht(r, t) {
21
- t === void 0 && (t = {});
22
- for (var e, n, i = [], s = (e = t.delimiter, e ?? z), c = (n = t.whitelist, n ?? void 0), o = 0, u = 0, a = "", h = !1; o < r.length; ) {
23
- var g = "", m = "", f = "";
24
- if (r[o] === "\\") {
25
- o++, a += r[o++], h = !0;
31
+ function parse(str, options) {
32
+ if (options === void 0) {
33
+ options = {};
34
+ }
35
+ var _a, _b;
36
+ var tokens = [];
37
+ var defaultDelimiter = (_a = options.delimiter, _a !== null && _a !== void 0 ? _a : DEFAULT_DELIMITER);
38
+ var whitelist = (_b = options.whitelist, _b !== null && _b !== void 0 ? _b : void 0);
39
+ var i = 0;
40
+ var key = 0;
41
+ var path = "";
42
+ var isEscaped = false;
43
+ while (i < str.length) {
44
+ var prefix = "";
45
+ var name = "";
46
+ var pattern = "";
47
+ if (str[i] === "\\") {
48
+ i++;
49
+ path += str[i++];
50
+ isEscaped = true;
26
51
  continue;
27
52
  }
28
- if (r[o] === ":") {
29
- for (; ++o < r.length; ) {
30
- var d = r.charCodeAt(o);
53
+ if (str[i] === ":") {
54
+ while (++i < str.length) {
55
+ var code = str.charCodeAt(i);
31
56
  if (
32
57
  // `0-9`
33
- d >= 48 && d <= 57 || // `A-Z`
34
- d >= 65 && d <= 90 || // `a-z`
35
- d >= 97 && d <= 122 || // `_`
36
- d === 95
58
+ code >= 48 && code <= 57 || // `A-Z`
59
+ code >= 65 && code <= 90 || // `a-z`
60
+ code >= 97 && code <= 122 || // `_`
61
+ code === 95
37
62
  ) {
38
- m += r[o];
63
+ name += str[i];
39
64
  continue;
40
65
  }
41
66
  break;
42
67
  }
43
- m || o--;
68
+ if (!name)
69
+ i--;
44
70
  }
45
- if (r[o] === "(") {
46
- var w = ut("(", ")", r, o);
47
- if (w > -1) {
48
- if (f = r.slice(o + 1, w - 1), o = w, f[0] === "?")
71
+ if (str[i] === "(") {
72
+ var end = balanced("(", ")", str, i);
73
+ if (end > -1) {
74
+ pattern = str.slice(i + 1, end - 1);
75
+ i = end;
76
+ if (pattern[0] === "?") {
49
77
  throw new TypeError("Path pattern must be a capturing group");
50
- if (/\((?=[^?])/.test(f)) {
51
- var p = f.replace(/\((?=[^?])/, "(?:");
52
- throw new TypeError("Capturing groups are not allowed in pattern, use a non-capturing group: (" + p + ")");
78
+ }
79
+ if (/\((?=[^?])/.test(pattern)) {
80
+ var validPattern = pattern.replace(/\((?=[^?])/, "(?:");
81
+ throw new TypeError("Capturing groups are not allowed in pattern, use a non-capturing group: (" + validPattern + ")");
53
82
  }
54
83
  }
55
84
  }
56
- if (m === "" && f === "") {
57
- a += r[o++], h = !1;
85
+ if (name === "" && pattern === "") {
86
+ path += str[i++];
87
+ isEscaped = false;
58
88
  continue;
59
89
  }
60
- if (a.length && !h) {
61
- var y = a[a.length - 1], l = c ? c.indexOf(y) > -1 : !0;
62
- l && (g = y, a = a.slice(0, -1));
63
- }
64
- a.length && (i.push(a), a = "");
65
- var v = r[o] === "+" || r[o] === "*", E = r[o] === "?" || r[o] === "*", b = g || s;
66
- (v || E) && o++, i.push({
67
- name: m || u++,
68
- prefix: g,
69
- delimiter: b,
70
- optional: E,
71
- repeat: v,
72
- pattern: f || "[^" + R(b === s ? b : b + s) + "]+?"
90
+ if (path.length && !isEscaped) {
91
+ var char = path[path.length - 1];
92
+ var matches = whitelist ? whitelist.indexOf(char) > -1 : true;
93
+ if (matches) {
94
+ prefix = char;
95
+ path = path.slice(0, -1);
96
+ }
97
+ }
98
+ if (path.length) {
99
+ tokens.push(path);
100
+ path = "";
101
+ }
102
+ var repeat = str[i] === "+" || str[i] === "*";
103
+ var optional = str[i] === "?" || str[i] === "*";
104
+ var delimiter = prefix || defaultDelimiter;
105
+ if (repeat || optional)
106
+ i++;
107
+ tokens.push({
108
+ name: name || key++,
109
+ prefix,
110
+ delimiter,
111
+ optional,
112
+ repeat,
113
+ pattern: pattern || "[^" + escapeString(delimiter === defaultDelimiter ? delimiter : delimiter + defaultDelimiter) + "]+?"
73
114
  });
74
115
  }
75
- return a.length && i.push(a), i;
116
+ if (path.length)
117
+ tokens.push(path);
118
+ return tokens;
76
119
  }
77
- function R(r) {
78
- return r.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
120
+ function escapeString(str) {
121
+ return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
79
122
  }
80
- function J(r) {
81
- return r && r.sensitive ? "" : "i";
123
+ function flags(options) {
124
+ return options && options.sensitive ? "" : "i";
82
125
  }
83
- function lt(r, t) {
84
- if (!t)
85
- return r;
86
- var e = r.source.match(/\((?!\?)/g);
87
- if (e)
88
- for (var n = 0; n < e.length; n++)
89
- t.push({
90
- name: n,
126
+ function regexpToRegexp(path, keys2) {
127
+ if (!keys2)
128
+ return path;
129
+ var groups = path.source.match(/\((?!\?)/g);
130
+ if (groups) {
131
+ for (var i = 0; i < groups.length; i++) {
132
+ keys2.push({
133
+ name: i,
91
134
  prefix: "",
92
135
  delimiter: "",
93
- optional: !1,
94
- repeat: !1,
136
+ optional: false,
137
+ repeat: false,
95
138
  pattern: ""
96
139
  });
97
- return r;
140
+ }
141
+ }
142
+ return path;
98
143
  }
99
- function ft(r, t, e) {
100
- var n = r.map(function(i) {
101
- return Z(i, t, e).source;
144
+ function arrayToRegexp(paths, keys2, options) {
145
+ var parts = paths.map(function(path) {
146
+ return pathToRegexp(path, keys2, options).source;
102
147
  });
103
- return new RegExp("(?:" + n.join("|") + ")", J(e));
148
+ return new RegExp("(?:" + parts.join("|") + ")", flags(options));
104
149
  }
105
- function pt(r, t, e) {
106
- return dt(ht(r, e), t, e);
150
+ function stringToRegexp(path, keys2, options) {
151
+ return tokensToRegexp(parse(path, options), keys2, options);
107
152
  }
108
- function dt(r, t, e) {
109
- e === void 0 && (e = {});
110
- for (var n = e.strict, i = e.start, s = i === void 0 ? !0 : i, c = e.end, o = c === void 0 ? !0 : c, u = e.delimiter, a = u === void 0 ? z : u, h = e.encode, g = h === void 0 ? function(E) {
111
- return E;
112
- } : h, m = (typeof e.endsWith == "string" ? e.endsWith.split("") : e.endsWith || []).map(R).concat("$").join("|"), f = s ? "^" : "", d = 0, w = r; d < w.length; d++) {
113
- var p = w[d];
114
- if (typeof p == "string")
115
- f += R(g(p));
116
- else {
117
- var y = p.repeat ? "(?:" + p.pattern + ")(?:" + R(p.delimiter) + "(?:" + p.pattern + "))*" : p.pattern;
118
- t && t.push(p), p.optional ? p.prefix ? f += "(?:" + R(p.prefix) + "(" + y + "))?" : f += "(" + y + ")?" : f += R(p.prefix) + "(" + y + ")";
119
- }
120
- }
121
- if (o)
122
- n || (f += "(?:" + R(a) + ")?"), f += m === "$" ? "$" : "(?=" + m + ")";
123
- else {
124
- var l = r[r.length - 1], v = typeof l == "string" ? l[l.length - 1] === a : (
153
+ function tokensToRegexp(tokens, keys2, options) {
154
+ if (options === void 0) {
155
+ options = {};
156
+ }
157
+ var strict = options.strict, _a = options.start, start = _a === void 0 ? true : _a, _b = options.end, end = _b === void 0 ? true : _b, _c = options.delimiter, delimiter = _c === void 0 ? DEFAULT_DELIMITER : _c, _d = options.encode, encode = _d === void 0 ? function(x) {
158
+ return x;
159
+ } : _d;
160
+ var endsWith = (typeof options.endsWith === "string" ? options.endsWith.split("") : options.endsWith || []).map(escapeString).concat("$").join("|");
161
+ var route = start ? "^" : "";
162
+ for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
163
+ var token = tokens_1[_i];
164
+ if (typeof token === "string") {
165
+ route += escapeString(encode(token));
166
+ } else {
167
+ var capture = token.repeat ? "(?:" + token.pattern + ")(?:" + escapeString(token.delimiter) + "(?:" + token.pattern + "))*" : token.pattern;
168
+ if (keys2)
169
+ keys2.push(token);
170
+ if (token.optional) {
171
+ if (!token.prefix) {
172
+ route += "(" + capture + ")?";
173
+ } else {
174
+ route += "(?:" + escapeString(token.prefix) + "(" + capture + "))?";
175
+ }
176
+ } else {
177
+ route += escapeString(token.prefix) + "(" + capture + ")";
178
+ }
179
+ }
180
+ }
181
+ if (end) {
182
+ if (!strict)
183
+ route += "(?:" + escapeString(delimiter) + ")?";
184
+ route += endsWith === "$" ? "$" : "(?=" + endsWith + ")";
185
+ } else {
186
+ var endToken = tokens[tokens.length - 1];
187
+ var isEndDelimited = typeof endToken === "string" ? endToken[endToken.length - 1] === delimiter : (
125
188
  // tslint:disable-next-line
126
- l === void 0
189
+ endToken === void 0
127
190
  );
128
- n || (f += "(?:" + R(a) + "(?=" + m + "))?"), v || (f += "(?=" + R(a) + "|" + m + ")");
191
+ if (!strict) {
192
+ route += "(?:" + escapeString(delimiter) + "(?=" + endsWith + "))?";
193
+ }
194
+ if (!isEndDelimited) {
195
+ route += "(?=" + escapeString(delimiter) + "|" + endsWith + ")";
196
+ }
129
197
  }
130
- return new RegExp(f, J(e));
198
+ return new RegExp(route, flags(options));
131
199
  }
132
- function Z(r, t, e) {
133
- return r instanceof RegExp ? lt(r, t) : Array.isArray(r) ? ft(r, t, e) : pt(r, t, e);
200
+ function pathToRegexp(path, keys2, options) {
201
+ if (path instanceof RegExp) {
202
+ return regexpToRegexp(path, keys2);
203
+ }
204
+ if (Array.isArray(path)) {
205
+ return arrayToRegexp(path, keys2, options);
206
+ }
207
+ return stringToRegexp(path, keys2, options);
134
208
  }
135
- const mt = (r, t, e) => (r[t] = e, r), gt = Array.isArray, O = Object.keys, L = (r) => r && (gt(r) ? r.slice(0) : C({}, r)), F = (r, t) => t.reduce((e, n) => r[n] === void 0 ? e : mt(e, n, r[n]), {}), H = (r, t) => {
136
- const e = O(r);
137
- return e.length === O(t).length && e.every((n) => t[n] === r[n]);
138
- }, C = Object.assign;
139
- function q(r, t, ...e) {
140
- if (!r) {
141
- let n = 0;
209
+ const assoc = (obj, attr, val) => {
210
+ obj[attr] = val;
211
+ return obj;
212
+ };
213
+ const isArray = Array.isArray;
214
+ const keys = Object.keys;
215
+ const clone = (obj) => obj ? isArray(obj) ? obj.slice(0) : extend({}, obj) : obj;
216
+ const pick = (obj, attrs) => attrs.reduce((acc, attr) => obj[attr] === void 0 ? acc : assoc(acc, attr, obj[attr]), {});
217
+ const isEqual$1 = (obj1, obj2) => {
218
+ const keys1 = keys(obj1);
219
+ return keys1.length === keys(obj2).length && keys1.every((key) => obj2[key] === obj1[key]);
220
+ };
221
+ const extend = Object.assign;
222
+ function invariant(condition, format, ...args) {
223
+ if (!condition) {
224
+ let argIndex = 0;
142
225
  throw new Error(
143
- "Invariant Violation: " + t.replace(/%s/g, () => e[n++])
226
+ "Invariant Violation: " + format.replace(/%s/g, () => args[argIndex++])
144
227
  );
145
228
  }
146
229
  }
147
- function vt(r) {
148
- let t = [];
149
- const e = {}, n = {};
150
- r(function(u, a, h) {
151
- let g;
152
- if (q(!n[u], 'Route names must be unique, but route "%s" is declared multiple times', u), n[u] = !0, arguments.length === 1 && (a = {}), arguments.length === 2 && typeof a == "function" && (h = a, a = {}), typeof a.path != "string") {
153
- const m = u.split(".");
154
- a.path = m[m.length - 1];
155
- }
156
- h && (t = t.concat(u), h(), g = i(), t.splice(-1)), s({
157
- name: u,
158
- path: a.path,
159
- routes: g || [],
160
- options: a
230
+ function functionDsl(callback) {
231
+ let ancestors = [];
232
+ const matches = {};
233
+ const names = {};
234
+ callback(function route(name, options, childrenCallback) {
235
+ let routes;
236
+ invariant(!names[name], 'Route names must be unique, but route "%s" is declared multiple times', name);
237
+ names[name] = true;
238
+ if (arguments.length === 1) {
239
+ options = {};
240
+ }
241
+ if (arguments.length === 2 && typeof options === "function") {
242
+ childrenCallback = options;
243
+ options = {};
244
+ }
245
+ if (typeof options.path !== "string") {
246
+ const parts = name.split(".");
247
+ options.path = parts[parts.length - 1];
248
+ }
249
+ if (childrenCallback) {
250
+ ancestors = ancestors.concat(name);
251
+ childrenCallback();
252
+ routes = pop();
253
+ ancestors.splice(-1);
254
+ }
255
+ push({
256
+ name,
257
+ path: options.path,
258
+ routes: routes || [],
259
+ options
161
260
  });
162
261
  });
163
- function i() {
164
- return e[c()] || [];
262
+ function pop() {
263
+ return matches[currentLevel()] || [];
165
264
  }
166
- function s(o) {
167
- const u = c();
168
- e[u] = e[u] || [], e[u].push(o);
265
+ function push(route) {
266
+ const level = currentLevel();
267
+ matches[level] = matches[level] || [];
268
+ matches[level].push(route);
169
269
  }
170
- function c() {
171
- return t.join(".");
270
+ function currentLevel() {
271
+ return ancestors.join(".");
172
272
  }
173
- return i();
273
+ return pop();
174
274
  }
175
- function G(r) {
176
- const t = [];
177
- return r.forEach(({ name: e, children: n, ...i }) => {
178
- if (typeof i.path != "string") {
179
- const s = e.split(".");
180
- i.path = s[s.length - 1];
181
- }
182
- t.push(
275
+ function arrayDsl(routes) {
276
+ const result = [];
277
+ routes.forEach(({ name, children, ...options }) => {
278
+ if (typeof options.path !== "string") {
279
+ const parts = name.split(".");
280
+ options.path = parts[parts.length - 1];
281
+ }
282
+ result.push(
183
283
  {
184
- name: e,
185
- path: i.path,
186
- options: i,
187
- routes: n ? G(n) : []
284
+ name,
285
+ path: options.path,
286
+ options,
287
+ routes: children ? arrayDsl(children) : []
188
288
  }
189
289
  );
190
- }), t;
290
+ });
291
+ return result;
191
292
  }
192
- const wt = /:([a-zA-Z_$][a-zA-Z0-9_$?]*[?+*]?)/g, yt = /[+*?]$/g, X = /\?(.+)/, D = {};
193
- function Y(r) {
194
- if (!(r in D)) {
195
- const t = [], e = Z(r, t);
196
- D[r] = {
197
- matcher: e,
198
- paramNames: t.map((n) => n.name)
293
+ const paramInjectMatcher = /:([a-zA-Z_$][a-zA-Z0-9_$?]*[?+*]?)/g;
294
+ const specialParamChars = /[+*?]$/g;
295
+ const queryMatcher = /\?(.+)/;
296
+ const _compiledPatterns = {};
297
+ function compilePattern(pattern) {
298
+ if (!(pattern in _compiledPatterns)) {
299
+ const paramNames = [];
300
+ const re = pathToRegexp(pattern, paramNames);
301
+ _compiledPatterns[pattern] = {
302
+ matcher: re,
303
+ paramNames: paramNames.map((p) => p.name)
199
304
  };
200
305
  }
201
- return D[r];
306
+ return _compiledPatterns[pattern];
202
307
  }
203
- function Et(r) {
204
- return Y(r).paramNames;
308
+ function extractParamNames(pattern) {
309
+ return compilePattern(pattern).paramNames;
205
310
  }
206
- function bt(r, t) {
207
- const e = Y(r), n = e.matcher, i = e.paramNames, s = t.match(n);
208
- if (!s)
311
+ function extractParams(pattern, path) {
312
+ const cp = compilePattern(pattern);
313
+ const matcher = cp.matcher;
314
+ const paramNames = cp.paramNames;
315
+ const match = path.match(matcher);
316
+ if (!match) {
209
317
  return null;
210
- const c = {};
211
- return i.forEach(function(o, u) {
212
- c[o] = s[u + 1] && decodeURIComponent(s[u + 1]);
213
- }), c;
318
+ }
319
+ const params = {};
320
+ paramNames.forEach(function(paramName, index) {
321
+ params[paramName] = match[index + 1] && decodeURIComponent(match[index + 1]);
322
+ });
323
+ return params;
214
324
  }
215
- function Rt(r, t) {
216
- return t = t || {}, r.replace(wt, function(e, n) {
217
- const i = n.replace(yt, ""), s = n.slice(-1);
218
- if (s === "?" || s === "*") {
219
- if (t[i] == null)
325
+ function injectParams(pattern, params) {
326
+ params = params || {};
327
+ return pattern.replace(paramInjectMatcher, function(match, param) {
328
+ const paramName = param.replace(specialParamChars, "");
329
+ const lastChar = param.slice(-1);
330
+ if (lastChar === "?" || lastChar === "*") {
331
+ if (params[paramName] == null) {
220
332
  return "";
221
- } else
222
- q(
223
- t[i] != null,
333
+ }
334
+ } else {
335
+ invariant(
336
+ params[paramName] != null,
224
337
  "Missing '%s' parameter for path '%s'",
225
- i,
226
- r
338
+ paramName,
339
+ pattern
227
340
  );
228
- let c = encodeURIComponent(t[i]);
229
- return (s === "*" || s === "+") && (c = c.replaceAll("%2F", "/")), c;
341
+ }
342
+ let paramValue = encodeURIComponent(params[paramName]);
343
+ if (lastChar === "*" || lastChar === "+") {
344
+ paramValue = paramValue.replaceAll("%2F", "/");
345
+ }
346
+ return paramValue;
230
347
  });
231
348
  }
232
- function Tt(r, t) {
233
- const e = t.match(X);
234
- return e && r.parse(e[1]);
349
+ function extractQuery(qs2, path) {
350
+ const match = path.match(queryMatcher);
351
+ return match && qs2.parse(match[1]);
235
352
  }
236
- function Lt(r, t, e) {
237
- const n = r.stringify(e, { indices: !1 });
238
- return n ? tt(t) + "?" + n : t;
353
+ function withQuery(qs2, path, query) {
354
+ const queryString = qs2.stringify(query, { indices: false });
355
+ if (queryString) {
356
+ return withoutQuery(path) + "?" + queryString;
357
+ }
358
+ return path;
239
359
  }
240
- function tt(r) {
241
- return r.replace(X, "");
360
+ function withoutQuery(path) {
361
+ return path.replace(queryMatcher, "");
242
362
  }
243
- function et(r, t, e) {
244
- return r.addEventListener(t, e), e;
363
+ function bindEvent(el, type, fn) {
364
+ el.addEventListener(type, fn);
365
+ return fn;
245
366
  }
246
- function rt(r, t, e) {
247
- return r.removeEventListener(t, e), e;
367
+ function unbindEvent(el, type, fn) {
368
+ el.removeEventListener(type, fn);
369
+ return fn;
248
370
  }
249
- class Ct {
371
+ class History {
250
372
  constructor() {
251
- this.handlers = [], this.checkUrl = this.checkUrl.bind(this), this.location = window.location, this.history = window.history;
373
+ this.handlers = [];
374
+ this.checkUrl = this.checkUrl.bind(this);
375
+ this.location = window.location;
376
+ this.history = window.history;
252
377
  }
253
378
  // Set up all inheritable **Backbone.History** properties and methods.
254
379
  // Are we at the app root?
@@ -258,32 +383,49 @@ class Ct {
258
383
  // Gets the true hash value. Cannot use location.hash directly due to bug
259
384
  // in Firefox where location.hash will always be decoded.
260
385
  getHash() {
261
- const t = this.location.href.match(/#(.*)$/);
262
- return t ? t[1] : "";
386
+ const match = this.location.href.match(/#(.*)$/);
387
+ return match ? match[1] : "";
263
388
  }
264
389
  // Get the cross-browser normalized URL fragment, either from the URL,
265
390
  // the hash, or the override.
266
- getFragment(t, e) {
267
- if (t == null)
268
- if (this._hasPushState || !this._wantsHashChange || e) {
269
- t = decodeURI(this.location.pathname + this.location.search);
270
- const n = this.root.replace(Ut, "");
271
- t.indexOf(n) || (t = t.slice(n.length));
272
- } else
273
- t = this.getHash();
274
- return t.replace(B, "");
391
+ getFragment(fragment, forcePushState) {
392
+ if (fragment == null) {
393
+ if (this._hasPushState || !this._wantsHashChange || forcePushState) {
394
+ fragment = decodeURI(this.location.pathname + this.location.search);
395
+ const root = this.root.replace(trailingSlash, "");
396
+ if (!fragment.indexOf(root))
397
+ fragment = fragment.slice(root.length);
398
+ } else {
399
+ fragment = this.getHash();
400
+ }
401
+ }
402
+ return fragment.replace(routeStripper, "");
275
403
  }
276
404
  // Start the hash change handling, returning `true` if the current URL matches
277
405
  // an existing route, and `false` otherwise.
278
- start(t = {}) {
279
- this.started = !0, this.options = C({ root: "/" }, t), this.location = this.options.location || this.location, this.history = this.options.history || this.history, this.root = this.options.root, this._wantsHashChange = this.options.hashChange !== !1, this._wantsPushState = !!this.options.pushState, this._hasPushState = this._wantsPushState;
280
- const e = this.getFragment();
281
- this.root = `/${this.root}/`.replace($t, "/"), et(window, this._hasPushState ? "popstate" : "hashchange", this.checkUrl), this.fragment = e;
282
- const n = this.location;
406
+ start(options = {}) {
407
+ this.started = true;
408
+ this.options = extend({ root: "/" }, options);
409
+ this.location = this.options.location || this.location;
410
+ this.history = this.options.history || this.history;
411
+ this.root = this.options.root;
412
+ this._wantsHashChange = this.options.hashChange !== false;
413
+ this._wantsPushState = !!this.options.pushState;
414
+ this._hasPushState = this._wantsPushState;
415
+ const fragment = this.getFragment();
416
+ this.root = `/${this.root}/`.replace(rootStripper, "/");
417
+ bindEvent(window, this._hasPushState ? "popstate" : "hashchange", this.checkUrl);
418
+ this.fragment = fragment;
419
+ const loc = this.location;
283
420
  if (this._wantsHashChange && this._wantsPushState) {
284
- if (!this._hasPushState && !this.atRoot())
285
- return this.fragment = this.getFragment(null, !0), this.location.replace(`${this.root}#${this.fragment}`), !0;
286
- this._hasPushState && this.atRoot() && n.hash && (this.fragment = this.getHash().replace(B, ""), this.history.replaceState({}, document.title, this.root + this.fragment));
421
+ if (!this._hasPushState && !this.atRoot()) {
422
+ this.fragment = this.getFragment(null, true);
423
+ this.location.replace(`${this.root}#${this.fragment}`);
424
+ return true;
425
+ } else if (this._hasPushState && this.atRoot() && loc.hash) {
426
+ this.fragment = this.getHash().replace(routeStripper, "");
427
+ this.history.replaceState({}, document.title, this.root + this.fragment);
428
+ }
287
429
  }
288
430
  if (!this.options.silent)
289
431
  return this.loadUrl();
@@ -291,27 +433,32 @@ class Ct {
291
433
  // Disable Backbone.history, perhaps temporarily. Not useful in a real app,
292
434
  // but possibly useful for unit testing Routers.
293
435
  stop() {
294
- rt(window, this._hasPushState ? "popstate" : "hashchange", this.checkUrl), this.started = !1;
436
+ unbindEvent(window, this._hasPushState ? "popstate" : "hashchange", this.checkUrl);
437
+ this.started = false;
295
438
  }
296
439
  // Add a route to be tested when the fragment changes. Routes added later
297
440
  // may override previous routes.
298
- route(t, e) {
299
- this.handlers.unshift({ route: t, callback: e });
441
+ route(route, callback) {
442
+ this.handlers.unshift({ route, callback });
300
443
  }
301
444
  // Checks the current URL to see if it has changed, and if it has,
302
445
  // calls `loadUrl`.
303
446
  checkUrl() {
304
- if (this.getFragment() === this.fragment)
305
- return !1;
447
+ const current = this.getFragment();
448
+ if (current === this.fragment)
449
+ return false;
306
450
  this.loadUrl();
307
451
  }
308
452
  // Attempt to load the current URL fragment. If a route succeeds with a
309
453
  // match, returns `true`. If no defined routes matches the fragment,
310
454
  // returns `false`.
311
- loadUrl(t) {
312
- return t = this.fragment = this.getFragment(t), this.handlers.some((e) => {
313
- if (e.route.test(t))
314
- return e.callback(t), !0;
455
+ loadUrl(fragment) {
456
+ fragment = this.fragment = this.getFragment(fragment);
457
+ return this.handlers.some((handler) => {
458
+ if (handler.route.test(fragment)) {
459
+ handler.callback(fragment);
460
+ return true;
461
+ }
315
462
  });
316
463
  }
317
464
  // Save a fragment into the hash history, or replace the URL state if the
@@ -321,52 +468,67 @@ class Ct {
321
468
  // The options object can contain `trigger: true` if you wish to have the
322
469
  // route callback be fired (not usually desirable), or `replace: true`, if
323
470
  // you wish to modify the current URL without adding an entry to the history.
324
- update(t, e) {
471
+ update(fragment, options) {
325
472
  if (!this.started)
326
- return !1;
327
- (!e || e === !0) && (e = { trigger: !!e });
328
- let n = this.root + (t = this.getFragment(t || ""));
329
- if (t = t.replace(St, ""), this.fragment !== t) {
330
- if (this.fragment = t, t === "" && n !== "/" && (n = n.slice(0, -1)), this._hasPushState)
331
- this.history[e.replace ? "replaceState" : "pushState"]({}, document.title, n);
332
- else if (this._wantsHashChange)
333
- this._updateHash(this.location, t, e.replace);
334
- else
335
- return this.location.assign(n);
336
- if (e.trigger)
337
- return this.loadUrl(t);
473
+ return false;
474
+ if (!options || options === true)
475
+ options = { trigger: !!options };
476
+ let url = this.root + (fragment = this.getFragment(fragment || ""));
477
+ fragment = fragment.replace(pathStripper, "");
478
+ if (this.fragment === fragment)
479
+ return;
480
+ this.fragment = fragment;
481
+ if (fragment === "" && url !== "/")
482
+ url = url.slice(0, -1);
483
+ if (this._hasPushState) {
484
+ this.history[options.replace ? "replaceState" : "pushState"]({}, document.title, url);
485
+ } else if (this._wantsHashChange) {
486
+ this._updateHash(this.location, fragment, options.replace);
487
+ } else {
488
+ return this.location.assign(url);
338
489
  }
490
+ if (options.trigger)
491
+ return this.loadUrl(fragment);
339
492
  }
340
493
  // Update the hash location, either replacing the current entry, or adding
341
494
  // a new one to the browser history.
342
- _updateHash(t, e, n) {
343
- if (n) {
344
- const i = t.href.replace(/(javascript:|#).*$/, "");
345
- t.replace(`${i}#${e}`);
346
- } else
347
- t.hash = `#${e}`;
495
+ _updateHash(location, fragment, replace) {
496
+ if (replace) {
497
+ const href = location.href.replace(/(javascript:|#).*$/, "");
498
+ location.replace(`${href}#${fragment}`);
499
+ } else {
500
+ location.hash = `#${fragment}`;
501
+ }
348
502
  }
349
503
  // add some features to History
350
504
  // a generic callback for any changes
351
- onChange(t) {
352
- this.route(/^(.*?)$/, t);
505
+ onChange(callback) {
506
+ this.route(/^(.*?)$/, callback);
353
507
  }
354
508
  // checks if the browser has pushstate support
355
509
  hasPushState() {
356
- if (!this.started)
510
+ if (!this.started) {
357
511
  throw new Error("only available after LocationBar.start()");
512
+ }
358
513
  return this._hasPushState;
359
514
  }
360
515
  }
361
- const B = /^[#\/]|\s+$/g, $t = /^\/+|\/+$/g, Ut = /\/$/, St = /#.*$/;
362
- class xt {
363
- constructor(t = {}) {
364
- this.path = t.path || "", this.options = C({
365
- pushState: !1,
516
+ const routeStripper = /^[#\/]|\s+$/g;
517
+ const rootStripper = /^\/+|\/+$/g;
518
+ const trailingSlash = /\/$/;
519
+ const pathStripper = /#.*$/;
520
+ class BrowserLocation {
521
+ constructor(options = {}) {
522
+ this.path = options.path || "";
523
+ this.options = extend({
524
+ pushState: false,
366
525
  root: "/"
367
- }, t), this.locationBar = new Ct(), this.locationBar.onChange((e) => {
368
- this.handleURL(`/${e || ""}`);
369
- }), this.locationBar.start(t);
526
+ }, options);
527
+ this.locationBar = new History();
528
+ this.locationBar.onChange((path) => {
529
+ this.handleURL(`/${path || ""}`);
530
+ });
531
+ this.locationBar.start(options);
370
532
  }
371
533
  /**
372
534
  * Get the current URL
@@ -378,33 +540,46 @@ class xt {
378
540
  * Set the current URL without triggering any events
379
541
  * back to the router. Add a new entry in browser's history.
380
542
  */
381
- setURL(t, e = {}) {
382
- this.path !== t && (this.path = t, this.locationBar.update(t, C({ trigger: !0 }, e)));
543
+ setURL(path, options = {}) {
544
+ if (this.path !== path) {
545
+ this.path = path;
546
+ this.locationBar.update(path, extend({ trigger: true }, options));
547
+ }
383
548
  }
384
549
  /**
385
550
  * Set the current URL without triggering any events
386
551
  * back to the router. Replace the latest entry in broser's history.
387
552
  */
388
- replaceURL(t, e = {}) {
389
- this.path !== t && (this.path = t, this.locationBar.update(t, C({ trigger: !0, replace: !0 }, e)));
553
+ replaceURL(path, options = {}) {
554
+ if (this.path !== path) {
555
+ this.path = path;
556
+ this.locationBar.update(path, extend({ trigger: true, replace: true }, options));
557
+ }
390
558
  }
391
559
  /**
392
560
  * Setup a URL change handler
393
561
  * @param {Function} callback
394
562
  */
395
- onChange(t) {
396
- this.changeCallback = t;
563
+ onChange(callback) {
564
+ this.changeCallback = callback;
397
565
  }
398
566
  /**
399
567
  * Given a path, generate a URL appending root
400
568
  * if pushState is used and # if hash state is used
401
569
  */
402
- formatURL(t) {
570
+ formatURL(path) {
403
571
  if (this.locationBar.hasPushState()) {
404
- let e = this.options.root;
405
- return t !== "" && (e = e.replace(/\/$/, "")), e + t;
406
- } else
407
- return t[0] === "/" && (t = t.substr(1)), `#${t}`;
572
+ let rootURL = this.options.root;
573
+ if (path !== "") {
574
+ rootURL = rootURL.replace(/\/$/, "");
575
+ }
576
+ return rootURL + path;
577
+ } else {
578
+ if (path[0] === "/") {
579
+ path = path.substr(1);
580
+ }
581
+ return `#${path}`;
582
+ }
408
583
  }
409
584
  /**
410
585
  * When we use pushState with a custom root option,
@@ -414,8 +589,12 @@ class xt {
414
589
  * - LocationBar expects all .update() calls to be called without root
415
590
  * - this method is public so that we could dispatch URLs without root in router
416
591
  */
417
- removeRoot(t) {
418
- return this.options.pushState && this.options.root && this.options.root !== "/" ? t.replace(this.options.root, "") : t;
592
+ removeRoot(url) {
593
+ if (this.options.pushState && this.options.root && this.options.root !== "/") {
594
+ return url.replace(this.options.root, "");
595
+ } else {
596
+ return url;
597
+ }
419
598
  }
420
599
  /**
421
600
  * Stop listening to URL changes and link clicks
@@ -432,182 +611,298 @@ class xt {
432
611
 
433
612
  @private
434
613
  */
435
- handleURL(t) {
436
- this.path = t, this.changeCallback && this.changeCallback(t);
614
+ handleURL(url) {
615
+ this.path = url;
616
+ if (this.changeCallback) {
617
+ this.changeCallback(url);
618
+ }
437
619
  }
438
620
  }
439
- class Pt {
440
- constructor({ path: t }) {
441
- this.path = t || "";
621
+ class MemoryLocation {
622
+ constructor({ path }) {
623
+ this.path = path || "";
442
624
  }
443
625
  getURL() {
444
626
  return this.path;
445
627
  }
446
- setURL(t, e) {
447
- this.path !== t && (this.path = t, this.handleURL(this.getURL(), e));
628
+ setURL(path, options) {
629
+ if (this.path !== path) {
630
+ this.path = path;
631
+ this.handleURL(this.getURL(), options);
632
+ }
448
633
  }
449
- replaceURL(t, e) {
450
- this.path !== t && this.setURL(t, e);
634
+ replaceURL(path, options) {
635
+ if (this.path !== path) {
636
+ this.setURL(path, options);
637
+ }
451
638
  }
452
- onChange(t) {
453
- this.changeCallback = t;
639
+ onChange(callback) {
640
+ this.changeCallback = callback;
454
641
  }
455
- handleURL(t, e = {}) {
456
- this.path = t, e = C({ trigger: !0 }, e), this.changeCallback && e.trigger && this.changeCallback(t);
642
+ handleURL(url, options = {}) {
643
+ this.path = url;
644
+ options = extend({ trigger: true }, options);
645
+ if (this.changeCallback && options.trigger) {
646
+ this.changeCallback(url);
647
+ }
457
648
  }
458
- removeRoot(t) {
459
- return t;
649
+ removeRoot(url) {
650
+ return url;
460
651
  }
461
- formatURL(t) {
462
- return t;
652
+ formatURL(url) {
653
+ return url;
463
654
  }
464
655
  }
465
- const N = "TransitionRedirected", P = "TransitionCancelled";
466
- function W(r, t, e) {
467
- r.middleware.forEach((n) => {
468
- n.error && n.error(t, e);
656
+ const TRANSITION_REDIRECTED = "TransitionRedirected";
657
+ const TRANSITION_CANCELLED = "TransitionCancelled";
658
+ function runError(router2, transition2, err) {
659
+ router2.middleware.forEach((m) => {
660
+ m.error && m.error(transition2, err);
469
661
  });
470
662
  }
471
- function k(r) {
472
- r = r || {};
473
- const t = r.router, e = t.log, n = t.logError, i = r.path, s = r.match, c = s.routes, o = s.params, u = s.pathname, a = s.query, h = r.id, g = Date.now();
474
- e("---"), e("Transition #" + h, "to", i), e("Transition #" + h, "routes:", c.map((l) => l.name)), e("Transition #" + h, "params:", o), e("Transition #" + h, "query:", a);
475
- let m, f;
476
- const d = new Promise(function(l, v) {
477
- m = l, f = v;
663
+ function transition(options) {
664
+ options = options || {};
665
+ const router2 = options.router;
666
+ const log = router2.log;
667
+ const logError = router2.logError;
668
+ const path = options.path;
669
+ const match = options.match;
670
+ const routes = match.routes;
671
+ const params = match.params;
672
+ const pathname = match.pathname;
673
+ const query = match.query;
674
+ const id = options.id;
675
+ const startTime = Date.now();
676
+ log("---");
677
+ log("Transition #" + id, "to", path);
678
+ log("Transition #" + id, "routes:", routes.map((r) => r.name));
679
+ log("Transition #" + id, "params:", params);
680
+ log("Transition #" + id, "query:", query);
681
+ let resolve2, reject;
682
+ const promise = new Promise(function(res, rej) {
683
+ resolve2 = res;
684
+ reject = rej;
478
685
  });
479
- d.then(function() {
480
- e("Transition #" + h, "completed in", Date.now() - g + "ms");
481
- }).catch(function(l) {
482
- l.type !== N && l.type !== P && (e("Transition #" + h, "FAILED"), n(l));
686
+ promise.then(function() {
687
+ log("Transition #" + id, "completed in", Date.now() - startTime + "ms");
688
+ }).catch(function(err) {
689
+ if (err.type !== TRANSITION_REDIRECTED && err.type !== TRANSITION_CANCELLED) {
690
+ log("Transition #" + id, "FAILED");
691
+ logError(err);
692
+ }
483
693
  });
484
- let w = !1;
485
- const p = {
486
- id: h,
694
+ let cancelled = false;
695
+ const transition2 = {
696
+ id,
487
697
  prev: {
488
- routes: L(t.state.routes) || [],
489
- path: t.state.path || "",
490
- pathname: t.state.pathname || "",
491
- params: L(t.state.params) || {},
492
- query: L(t.state.query) || {}
698
+ routes: clone(router2.state.routes) || [],
699
+ path: router2.state.path || "",
700
+ pathname: router2.state.pathname || "",
701
+ params: clone(router2.state.params) || {},
702
+ query: clone(router2.state.query) || {}
493
703
  },
494
- routes: L(c),
495
- path: i,
496
- pathname: u,
497
- params: L(o),
498
- query: L(a),
499
- redirectTo: function(...l) {
500
- return t.transitionTo(...l);
704
+ routes: clone(routes),
705
+ path,
706
+ pathname,
707
+ params: clone(params),
708
+ query: clone(query),
709
+ redirectTo: function(...args) {
710
+ return router2.transitionTo(...args);
501
711
  },
502
712
  retry: function() {
503
- return t.transitionTo(i);
713
+ return router2.transitionTo(path);
504
714
  },
505
- cancel: function(l) {
506
- t.state.activeTransition === p && (p.isCancelled || (t.state.activeTransition = null, p.isCancelled = !0, w = !0, l || (l = new Error(P), l.type = P), l.type === P && e("Transition #" + h, "cancelled"), l.type === N && e("Transition #" + h, "redirected"), t.middleware.forEach((v) => {
507
- v.cancel && v.cancel(p, l);
508
- }), f(l)));
715
+ cancel: function(err) {
716
+ if (router2.state.activeTransition !== transition2) {
717
+ return;
718
+ }
719
+ if (transition2.isCancelled) {
720
+ return;
721
+ }
722
+ router2.state.activeTransition = null;
723
+ transition2.isCancelled = true;
724
+ cancelled = true;
725
+ if (!err) {
726
+ err = new Error(TRANSITION_CANCELLED);
727
+ err.type = TRANSITION_CANCELLED;
728
+ }
729
+ if (err.type === TRANSITION_CANCELLED) {
730
+ log("Transition #" + id, "cancelled");
731
+ }
732
+ if (err.type === TRANSITION_REDIRECTED) {
733
+ log("Transition #" + id, "redirected");
734
+ }
735
+ router2.middleware.forEach((m) => {
736
+ m.cancel && m.cancel(transition2, err);
737
+ });
738
+ reject(err);
509
739
  },
510
740
  followRedirects: function() {
511
- return d.catch(function(l) {
512
- return t.state.activeTransition ? t.state.activeTransition.followRedirects() : Promise.reject(l);
741
+ return promise.catch(function(reason) {
742
+ if (router2.state.activeTransition) {
743
+ return router2.state.activeTransition.followRedirects();
744
+ }
745
+ return Promise.reject(reason);
513
746
  });
514
747
  },
515
- then: d.then.bind(d),
516
- catch: d.catch.bind(d)
748
+ then: promise.then.bind(promise),
749
+ catch: promise.catch.bind(promise)
517
750
  };
518
- t.middleware.forEach((l) => {
519
- l.before && l.before(p);
751
+ router2.middleware.forEach((m) => {
752
+ m.before && m.before(transition2);
520
753
  });
521
- function y(l, v) {
522
- let E, b;
523
- if (!w)
524
- if (l < t.middleware.length) {
525
- E = t.middleware[l], b = E.name || "anonymous", e("Transition #" + h, "resolving middleware:", b);
526
- let U;
527
- try {
528
- U = E.resolve ? E.resolve(p, v) : v, q(p !== U, "Middleware %s returned a transition which resulted in a deadlock", b);
529
- } catch (T) {
530
- return t.state.activeTransition = null, W(t, p, T), f(T);
531
- }
532
- Promise.resolve(U).then(function(T) {
533
- y(l + 1, T);
534
- }).catch(function(T) {
535
- e("Transition #" + h, "resolving middleware:", b, "FAILED"), t.state.activeTransition = null, W(t, p, T), f(T);
536
- });
537
- } else
538
- t.state = {
539
- activeTransition: null,
540
- routes: c,
541
- path: i,
542
- pathname: u,
543
- params: o,
544
- query: a
545
- }, t.middleware.forEach((U) => {
546
- U.done && U.done(p);
547
- }), m();
548
- }
549
- return r.noop ? m() : Promise.resolve().then(() => y(0)), r.noop && (p.noop = !0), p;
754
+ function callNext(i, prevResult) {
755
+ let middleware;
756
+ let middlewareName;
757
+ if (cancelled) {
758
+ return;
759
+ }
760
+ if (i < router2.middleware.length) {
761
+ middleware = router2.middleware[i];
762
+ middlewareName = middleware.name || "anonymous";
763
+ log("Transition #" + id, "resolving middleware:", middlewareName);
764
+ let middlewarePromise;
765
+ try {
766
+ middlewarePromise = middleware.resolve ? middleware.resolve(transition2, prevResult) : prevResult;
767
+ invariant(transition2 !== middlewarePromise, "Middleware %s returned a transition which resulted in a deadlock", middlewareName);
768
+ } catch (err) {
769
+ router2.state.activeTransition = null;
770
+ runError(router2, transition2, err);
771
+ return reject(err);
772
+ }
773
+ Promise.resolve(middlewarePromise).then(function(result) {
774
+ callNext(i + 1, result);
775
+ }).catch(function(err) {
776
+ log("Transition #" + id, "resolving middleware:", middlewareName, "FAILED");
777
+ router2.state.activeTransition = null;
778
+ runError(router2, transition2, err);
779
+ reject(err);
780
+ });
781
+ } else {
782
+ router2.state = {
783
+ activeTransition: null,
784
+ routes,
785
+ path,
786
+ pathname,
787
+ params,
788
+ query
789
+ };
790
+ router2.middleware.forEach((m) => {
791
+ m.done && m.done(transition2);
792
+ });
793
+ resolve2();
794
+ }
795
+ }
796
+ if (!options.noop) {
797
+ Promise.resolve().then(() => callNext(0));
798
+ } else {
799
+ resolve2();
800
+ }
801
+ if (options.noop) {
802
+ transition2.noop = true;
803
+ }
804
+ return transition2;
550
805
  }
551
- function _t(r, t) {
552
- const e = Ot(r, "click", function(n, i) {
553
- It(n, i) && t(n, i);
806
+ function intercept(el, fn) {
807
+ const cb = delegate(el, "click", function(e, el2) {
808
+ if (clickable(e, el2))
809
+ fn(e, el2);
554
810
  });
555
- return function() {
556
- Nt(r, "click", e);
811
+ return function dispose() {
812
+ undelegate(el, "click", cb);
557
813
  };
558
814
  }
559
- function At(r) {
560
- var e;
561
- r = { parentNode: r };
562
- const t = document;
563
- for (; (r = r.parentNode) && r !== document; ) {
564
- if (((e = r.tagName) == null ? void 0 : e.toLowerCase()) === "a")
565
- return r;
566
- if (r === t)
815
+ function link(element) {
816
+ var _a;
817
+ element = { parentNode: element };
818
+ const root = document;
819
+ while ((element = element.parentNode) && element !== document) {
820
+ if (((_a = element.tagName) == null ? void 0 : _a.toLowerCase()) === "a") {
821
+ return element;
822
+ }
823
+ if (element === root) {
567
824
  return;
825
+ }
568
826
  }
569
827
  }
570
- function Ot(r, t, e) {
571
- return et(r, t, function(n) {
572
- const i = n.target || n.srcElement, s = At(i);
573
- s && e(n, s);
828
+ function delegate(el, type, fn) {
829
+ return bindEvent(el, type, function(e) {
830
+ const target = e.target || e.srcElement;
831
+ const el2 = link(target);
832
+ if (el2) {
833
+ fn(e, el2);
834
+ }
574
835
  });
575
836
  }
576
- function Nt(r, t, e) {
577
- rt(r, t, e);
837
+ function undelegate(el, type, fn) {
838
+ unbindEvent(el, type, fn);
578
839
  }
579
- function It(r, t) {
580
- if (qt(r) !== 1 || r.metaKey || r.ctrlKey || r.shiftKey || r.defaultPrevented || t.target || t.getAttribute("data-bypass") !== null)
840
+ function clickable(e, el) {
841
+ if (which(e) !== 1)
581
842
  return;
582
- const e = t.getAttribute("href");
583
- if (!(!e || e.length === 0) && e[0] !== "#" && !(e.indexOf("http://") === 0 || e.indexOf("https://") === 0) && e.indexOf("mailto:") !== 0 && e.indexOf("javascript:") !== 0)
584
- return !0;
843
+ if (e.metaKey || e.ctrlKey || e.shiftKey)
844
+ return;
845
+ if (e.defaultPrevented)
846
+ return;
847
+ if (el.target)
848
+ return;
849
+ if (el.getAttribute("data-bypass") !== null)
850
+ return;
851
+ const href = el.getAttribute("href");
852
+ if (!href || href.length === 0)
853
+ return;
854
+ if (href[0] === "#")
855
+ return;
856
+ if (href.indexOf("http://") === 0 || href.indexOf("https://") === 0)
857
+ return;
858
+ if (href.indexOf("mailto:") === 0)
859
+ return;
860
+ if (href.indexOf("javascript:") === 0)
861
+ return;
862
+ return true;
585
863
  }
586
- function qt(r) {
587
- return r = r || window.event, r.which === null ? r.button : r.which;
864
+ function which(e) {
865
+ e = e || window.event;
866
+ return e.which === null ? e.button : e.which;
588
867
  }
589
- function V(r, t, e) {
590
- e !== !0 && (r[t] = typeof e == "function" ? e : () => {
591
- });
868
+ function defineLogger(router2, method, fn) {
869
+ if (fn === true)
870
+ return;
871
+ router2[method] = typeof fn === "function" ? fn : () => {
872
+ };
592
873
  }
593
- var Dt = {
594
- parse(r) {
595
- return r.split("&").reduce((t, e) => {
596
- const n = e.split("=");
597
- return t[n[0]] = decodeURIComponent(n[1]), t;
874
+ var qs = {
875
+ parse(querystring) {
876
+ return querystring.split("&").reduce((acc, pair) => {
877
+ const parts = pair.split("=");
878
+ acc[parts[0]] = decodeURIComponent(parts[1]);
879
+ return acc;
598
880
  }, {});
599
881
  },
600
- stringify(r) {
601
- return Object.keys(r).reduce((t, e) => (r[e] !== void 0 && t.push(e + "=" + encodeURIComponent(r[e])), t), []).join("&");
882
+ stringify(params) {
883
+ return Object.keys(params).reduce((acc, key) => {
884
+ if (params[key] !== void 0) {
885
+ acc.push(key + "=" + encodeURIComponent(params[key]));
886
+ }
887
+ return acc;
888
+ }, []).join("&");
602
889
  }
603
890
  };
604
- class Mt {
605
- constructor(t = {}) {
606
- this.nextId = 1, this.state = {}, this.middleware = [], this.options = C({
891
+ class Router {
892
+ constructor(options = {}) {
893
+ this.nextId = 1;
894
+ this.state = {};
895
+ this.middleware = [];
896
+ this.options = extend({
607
897
  location: "browser",
608
- logError: !0,
609
- qs: Dt
610
- }, t), V(this, "log", this.options.log), V(this, "logError", this.options.logError), t.routes && this.map(t.routes);
898
+ logError: true,
899
+ qs
900
+ }, options);
901
+ defineLogger(this, "log", this.options.log);
902
+ defineLogger(this, "logError", this.options.logError);
903
+ if (options.routes) {
904
+ this.map(options.routes);
905
+ }
611
906
  }
612
907
  /**
613
908
  * Add a middleware
@@ -615,9 +910,11 @@ class Mt {
615
910
  * @return {Object} router
616
911
  * @api public
617
912
  */
618
- use(t, e = {}) {
619
- const n = typeof t == "function" ? { resolve: t } : t;
620
- return typeof e.at == "number" ? this.middleware.splice(e.at, 0, n) : this.middleware.push(n), n.create && n.create(this), this;
913
+ use(middleware, options = {}) {
914
+ const m = typeof middleware === "function" ? { resolve: middleware } : middleware;
915
+ typeof options.at === "number" ? this.middleware.splice(options.at, 0, m) : this.middleware.push(m);
916
+ m.create && m.create(this);
917
+ return this;
621
918
  }
622
919
  /**
623
920
  * Add the route map
@@ -625,43 +922,59 @@ class Mt {
625
922
  * @return {Object} router
626
923
  * @api public
627
924
  */
628
- map(t) {
629
- this.routes = Array.isArray(t) ? G(t) : vt(t);
630
- const e = this.matchers = [], n = {}, i = {};
631
- s({ routes: this.routes }, [], (c) => {
632
- let o = c.reduce((a, h) => (
925
+ map(routes) {
926
+ this.routes = Array.isArray(routes) ? arrayDsl(routes) : functionDsl(routes);
927
+ const matchers = this.matchers = [];
928
+ const dupes = {};
929
+ const abstracts = {};
930
+ eachBranch({ routes: this.routes }, [], (routes2) => {
931
+ let path = routes2.reduce((memo, r) => (
633
932
  // reset if there's a leading slash, otherwise concat
634
933
  // and keep resetting the trailing slash
635
- (h.path[0] === "/" ? h.path : `${a}/${h.path}`).replace(/\/$/, "")
934
+ (r.path[0] === "/" ? r.path : `${memo}/${r.path}`).replace(/\/$/, "")
636
935
  ), "");
637
- o === "" && (o = "/");
638
- const u = c[c.length - 1];
639
- if (u.options.abstract) {
640
- i[o] = u.name;
936
+ if (path === "") {
937
+ path = "/";
938
+ }
939
+ const lastRoute = routes2[routes2.length - 1];
940
+ if (lastRoute.options.abstract) {
941
+ abstracts[path] = lastRoute.name;
641
942
  return;
642
943
  }
643
- if (u.path === "") {
644
- let a;
645
- e.some((h) => {
646
- if (h.path === o)
647
- return a = h, !0;
648
- }), a ? a.routes = c : i[o] && e.push({
649
- routes: c,
650
- name: i[o],
651
- path: o
944
+ if (lastRoute.path === "") {
945
+ let matcher;
946
+ matchers.some((m) => {
947
+ if (m.path === path) {
948
+ matcher = m;
949
+ return true;
950
+ }
652
951
  });
952
+ if (matcher) {
953
+ matcher.routes = routes2;
954
+ } else if (abstracts[path]) {
955
+ matchers.push({
956
+ routes: routes2,
957
+ name: abstracts[path],
958
+ path
959
+ });
960
+ }
653
961
  }
654
- if (e.push({
655
- routes: c,
656
- name: u.name,
657
- path: o
658
- }), n[o] && u.path !== "")
659
- throw new Error(`Routes ${n[o]} and ${u.name} have the same url path '${o}'`);
660
- n[o] = u.name;
962
+ matchers.push({
963
+ routes: routes2,
964
+ name: lastRoute.name,
965
+ path
966
+ });
967
+ if (dupes[path] && lastRoute.path !== "") {
968
+ throw new Error(`Routes ${dupes[path]} and ${lastRoute.name} have the same url path '${path}'`);
969
+ }
970
+ dupes[path] = lastRoute.name;
661
971
  });
662
- function s(c, o, u) {
663
- c.routes.forEach((a) => {
664
- u(o.concat(a)), a.routes.length && s(a, o.concat(a), u);
972
+ function eachBranch(node, memo, fn) {
973
+ node.routes.forEach((route) => {
974
+ fn(memo.concat(route));
975
+ if (route.routes.length) {
976
+ eachBranch(route, memo.concat(route), fn);
977
+ }
665
978
  });
666
979
  }
667
980
  return this;
@@ -673,12 +986,18 @@ class Mt {
673
986
  *
674
987
  * @api public
675
988
  */
676
- listen(t) {
677
- const e = this.location = this.createLocation(t || "");
678
- return e.onChange((n) => {
679
- const i = this.state.path;
680
- this.dispatch(n).catch((s) => (s && s.type === P && this.location.replaceURL(i, { trigger: !1 }), s));
681
- }), this.dispatch(e.getURL());
989
+ listen(path) {
990
+ const location = this.location = this.createLocation(path || "");
991
+ location.onChange((url) => {
992
+ const previousUrl = this.state.path;
993
+ this.dispatch(url).catch((err) => {
994
+ if (err && err.type === TRANSITION_CANCELLED) {
995
+ this.location.replaceURL(previousUrl, { trigger: false });
996
+ }
997
+ return err;
998
+ });
999
+ });
1000
+ return this.dispatch(location.getURL());
682
1001
  }
683
1002
  /**
684
1003
  * Transition to a different route. Passe in url or a route name followed by params and query
@@ -689,8 +1008,11 @@ class Mt {
689
1008
  *
690
1009
  * @api public
691
1010
  */
692
- transitionTo(t, e, n) {
693
- return this.state.activeTransition ? this.replaceWith(t, e, n) : this.doTransition("setURL", t, e, n);
1011
+ transitionTo(name, params, query) {
1012
+ if (this.state.activeTransition) {
1013
+ return this.replaceWith(name, params, query);
1014
+ }
1015
+ return this.doTransition("setURL", name, params, query);
694
1016
  }
695
1017
  /**
696
1018
  * Like transitionTo, but doesn't leave an entry in the browser's history,
@@ -702,8 +1024,8 @@ class Mt {
702
1024
  *
703
1025
  * @api public
704
1026
  */
705
- replaceWith(t, e, n) {
706
- return this.doTransition("replaceURL", t, e, n);
1027
+ replaceWith(name, params, query) {
1028
+ return this.doTransition("replaceURL", name, params, query);
707
1029
  }
708
1030
  /**
709
1031
  * Create an href
@@ -714,23 +1036,35 @@ class Mt {
714
1036
  *
715
1037
  * @api public
716
1038
  */
717
- generate(t, e, n) {
718
- q(this.location, "call .listen() before using .generate()");
719
- let i;
720
- if (n = n || {}, this.matchers.forEach((c) => {
721
- c.name === t && (i = c);
722
- }), !i)
723
- throw new Error(`No route is named ${t}`);
724
- const s = Lt(this.options.qs, Rt(i.path, e), n);
725
- return this.location.formatURL(s);
1039
+ generate(name, params, query) {
1040
+ invariant(this.location, "call .listen() before using .generate()");
1041
+ let matcher;
1042
+ query = query || {};
1043
+ this.matchers.forEach((m) => {
1044
+ if (m.name === name) {
1045
+ matcher = m;
1046
+ }
1047
+ });
1048
+ if (!matcher) {
1049
+ throw new Error(`No route is named ${name}`);
1050
+ }
1051
+ const url = withQuery(this.options.qs, injectParams(matcher.path, params), query);
1052
+ return this.location.formatURL(url);
726
1053
  }
727
1054
  /**
728
1055
  * Stop listening to URL changes
729
1056
  * @api public
730
1057
  */
731
1058
  destroy() {
732
- this.location && this.location.destroy && this.location.destroy(), this.state.activeTransition && this.state.activeTransition.cancel(), this.state = {}, this.middleware.forEach((t) => {
733
- t.destroy && t.destroy(this);
1059
+ if (this.location && this.location.destroy) {
1060
+ this.location.destroy();
1061
+ }
1062
+ if (this.state.activeTransition) {
1063
+ this.state.activeTransition.cancel();
1064
+ }
1065
+ this.state = {};
1066
+ this.middleware.forEach((m) => {
1067
+ m.destroy && m.destroy(this);
734
1068
  });
735
1069
  }
736
1070
  /**
@@ -742,20 +1076,37 @@ class Mt {
742
1076
  *
743
1077
  * @api public
744
1078
  */
745
- isActive(t, e, n, i) {
746
- const s = this.state.routes || [], c = this.state.params, o = this.state.query;
747
- let u = s.some((a) => a.name === t) && (!i || s[s.length - 1].name === t);
748
- return u = u && (!e || O(e).every((a) => c[a] === e[a])), u = u && (!n || O(n).every((a) => o[a] === n[a])), u;
1079
+ isActive(name, params, query, exact) {
1080
+ const activeRoutes = this.state.routes || [];
1081
+ const activeParams = this.state.params;
1082
+ const activeQuery = this.state.query;
1083
+ let isActive = activeRoutes.some((route) => route.name === name) && (!exact || activeRoutes[activeRoutes.length - 1].name === name);
1084
+ isActive = isActive && (!params || keys(params).every((key) => activeParams[key] === params[key]));
1085
+ isActive = isActive && (!query || keys(query).every((key) => activeQuery[key] === query[key]));
1086
+ return isActive;
749
1087
  }
750
1088
  /**
751
1089
  * @api private
752
1090
  */
753
- doTransition(t, e, n, i) {
754
- const s = this.location.getURL();
755
- let c = e;
756
- c[0] !== "/" && (c = this.generate(e, n, i), c = c.replace(/^#/, "/")), this.options.pushState && (c = this.location.removeRoot(c));
757
- const o = this.dispatch(c);
758
- return o.catch((u) => (u && u.type === P && this.location.replaceURL(s, { trigger: !1 }), u)), this.location[t](c, { trigger: !1 }), o;
1091
+ doTransition(method, name, params, query) {
1092
+ const previousUrl = this.location.getURL();
1093
+ let url = name;
1094
+ if (url[0] !== "/") {
1095
+ url = this.generate(name, params, query);
1096
+ url = url.replace(/^#/, "/");
1097
+ }
1098
+ if (this.options.pushState) {
1099
+ url = this.location.removeRoot(url);
1100
+ }
1101
+ const transition2 = this.dispatch(url);
1102
+ transition2.catch((err) => {
1103
+ if (err && err.type === TRANSITION_CANCELLED) {
1104
+ this.location.replaceURL(previousUrl, { trigger: false });
1105
+ }
1106
+ return err;
1107
+ });
1108
+ this.location[method](url, { trigger: false });
1109
+ return transition2;
759
1110
  }
760
1111
  /**
761
1112
  * Match the path against the routes
@@ -764,51 +1115,67 @@ class Mt {
764
1115
  *
765
1116
  * @api private
766
1117
  */
767
- match(t) {
768
- t = (t || "").replace(/\/$/, "") || "/";
769
- let e, n = [];
770
- const i = tt(t), s = this.options.qs;
771
- return this.matchers.some((o) => {
772
- if (e = bt(o.path, i), e)
773
- return n = o.routes, !0;
774
- }), {
775
- routes: n.map(c),
776
- params: e || {},
777
- pathname: i,
778
- query: Tt(s, t) || {}
1118
+ match(path) {
1119
+ path = (path || "").replace(/\/$/, "") || "/";
1120
+ let params;
1121
+ let routes = [];
1122
+ const pathWithoutQuery = withoutQuery(path);
1123
+ const qs2 = this.options.qs;
1124
+ this.matchers.some((matcher) => {
1125
+ params = extractParams(matcher.path, pathWithoutQuery);
1126
+ if (params) {
1127
+ routes = matcher.routes;
1128
+ return true;
1129
+ }
1130
+ });
1131
+ return {
1132
+ routes: routes.map(descriptor),
1133
+ params: params || {},
1134
+ pathname: pathWithoutQuery,
1135
+ query: extractQuery(qs2, path) || {}
779
1136
  };
780
- function c(o) {
1137
+ function descriptor(route) {
781
1138
  return {
782
- name: o.name,
783
- path: o.path,
784
- params: F(e, Et(o.path)),
785
- options: L(o.options)
1139
+ name: route.name,
1140
+ path: route.path,
1141
+ params: pick(params, extractParamNames(route.path)),
1142
+ options: clone(route.options)
786
1143
  };
787
1144
  }
788
1145
  }
789
- dispatch(t) {
790
- const e = this.match(t), n = e.query, i = e.pathname, s = this.state.activeTransition;
791
- if (s && s.pathname === i && H(s.query, n))
792
- return s;
793
- if (s) {
794
- const o = new Error(N);
795
- o.type = N, o.nextPath = t, s.cancel(o);
796
- }
797
- if (!s && this.state.pathname === i && H(this.state.query, n))
798
- return k({
799
- id: this.nextId++,
800
- path: t,
801
- match: e,
802
- noop: !0,
803
- router: this
804
- });
805
- const c = k({
1146
+ dispatch(path) {
1147
+ const match = this.match(path);
1148
+ const query = match.query;
1149
+ const pathname = match.pathname;
1150
+ const activeTransition = this.state.activeTransition;
1151
+ if (activeTransition && activeTransition.pathname === pathname && isEqual$1(activeTransition.query, query)) {
1152
+ return activeTransition;
1153
+ }
1154
+ if (activeTransition) {
1155
+ const err = new Error(TRANSITION_REDIRECTED);
1156
+ err.type = TRANSITION_REDIRECTED;
1157
+ err.nextPath = path;
1158
+ activeTransition.cancel(err);
1159
+ }
1160
+ if (!activeTransition) {
1161
+ if (this.state.pathname === pathname && isEqual$1(this.state.query, query)) {
1162
+ return transition({
1163
+ id: this.nextId++,
1164
+ path,
1165
+ match,
1166
+ noop: true,
1167
+ router: this
1168
+ });
1169
+ }
1170
+ }
1171
+ const t = transition({
806
1172
  id: this.nextId++,
807
- path: t,
808
- match: e,
1173
+ path,
1174
+ match,
809
1175
  router: this
810
1176
  });
811
- return this.state.activeTransition = c, c;
1177
+ this.state.activeTransition = t;
1178
+ return t;
812
1179
  }
813
1180
  /**
814
1181
  * Create the default location.
@@ -818,198 +1185,284 @@ class Mt {
818
1185
  *
819
1186
  * @api private
820
1187
  */
821
- createLocation(t) {
822
- const e = this.options.location;
823
- if (typeof e != "string")
824
- return e;
825
- if (e === "browser")
826
- return new xt(F(this.options, ["pushState", "root"]));
827
- if (e === "memory")
828
- return new Pt({ path: t });
829
- throw new Error("Location can be `browser`, `memory` or a custom implementation");
830
- }
831
- log(...t) {
832
- console.info(...t);
833
- }
834
- logError(...t) {
835
- console.error(...t);
1188
+ createLocation(path) {
1189
+ const location = this.options.location;
1190
+ if (typeof location !== "string") {
1191
+ return location;
1192
+ }
1193
+ if (location === "browser") {
1194
+ return new BrowserLocation(pick(this.options, ["pushState", "root"]));
1195
+ } else if (location === "memory") {
1196
+ return new MemoryLocation({ path });
1197
+ } else {
1198
+ throw new Error("Location can be `browser`, `memory` or a custom implementation");
1199
+ }
1200
+ }
1201
+ log(...args) {
1202
+ console.info(...args);
1203
+ }
1204
+ logError(...args) {
1205
+ console.error(...args);
836
1206
  }
837
1207
  }
838
- function jt(r, t, e) {
839
- !t.hasAttribute("download") && !t.hasAttribute("data-phone-number") && (r.preventDefault(), e.transitionTo(e.location.removeRoot(t.getAttribute("href"))));
1208
+ function defaultClickHandler(event, link2, router2) {
1209
+ if (!link2.hasAttribute("download") && !link2.hasAttribute("data-phone-number")) {
1210
+ event.preventDefault();
1211
+ router2.transitionTo(router2.location.removeRoot(link2.getAttribute("href")));
1212
+ }
840
1213
  }
841
- function Ft(r, t = document, e = jt) {
842
- return _t(t, (n, i) => e(n, i, r));
1214
+ function interceptLinks(router2, el = document, clickHandler = defaultClickHandler) {
1215
+ return intercept(el, (event, link2) => clickHandler(event, link2, router2));
843
1216
  }
844
- const Ht = Promise.resolve();
845
- let $ = /* @__PURE__ */ Object.create(null), M = /* @__PURE__ */ Object.create(null), j, S, x;
846
- function Bt(r) {
847
- const t = parseFloat(r);
848
- return r == t ? t : r;
1217
+ const resolved = Promise.resolve();
1218
+ let routeElMap = /* @__PURE__ */ Object.create(null);
1219
+ let routeComponentMap = /* @__PURE__ */ Object.create(null);
1220
+ let router, rootOutlet, rootOutletEl;
1221
+ function parseNumber(value) {
1222
+ const n = parseFloat(value);
1223
+ const isNumeric = value == n;
1224
+ return isNumeric ? n : value;
849
1225
  }
850
- class Wt {
851
- constructor(t, e) {
852
- this.key = t, this.format = e;
853
- }
854
- value(t) {
855
- let e = this.getValue(t);
856
- if (e !== void 0) {
857
- const n = this.format;
858
- n === "number" ? e = Bt(e) : typeof n == "function" && (e = n(e));
1226
+ class TransitionValue {
1227
+ constructor(key, format) {
1228
+ this.key = key;
1229
+ this.format = format;
1230
+ }
1231
+ value(transition2) {
1232
+ let result = this.getValue(transition2);
1233
+ if (result !== void 0) {
1234
+ const format = this.format;
1235
+ if (format === "number") {
1236
+ result = parseNumber(result);
1237
+ } else if (typeof format === "function") {
1238
+ result = format(result);
1239
+ }
859
1240
  }
860
- return e;
1241
+ return result;
861
1242
  }
862
1243
  }
863
- function kt(r) {
864
- j = r, S = r.options.outlet;
1244
+ function create(instance) {
1245
+ router = instance;
1246
+ rootOutlet = instance.options.outlet;
865
1247
  }
866
- function Vt() {
867
- j = null, $ = /* @__PURE__ */ Object.create(null), M = /* @__PURE__ */ Object.create(null), x = null;
1248
+ function destroy() {
1249
+ router = null;
1250
+ routeElMap = /* @__PURE__ */ Object.create(null);
1251
+ routeComponentMap = /* @__PURE__ */ Object.create(null);
1252
+ rootOutletEl = null;
868
1253
  }
869
- function Qt(r, t) {
870
- const e = Object.keys(r);
871
- return e.length === Object.keys(t).length && e.every((n) => t[n] === r[n]);
1254
+ function isEqual(obj1, obj2) {
1255
+ const keys1 = Object.keys(obj1);
1256
+ return keys1.length === Object.keys(obj2).length && keys1.every((key) => obj2[key] === obj1[key]);
872
1257
  }
873
- function Kt(r) {
874
- return (r.shadowRoot || r).querySelector(r.constructor.outlet || "wj-router-outlet");
1258
+ function getOutlet(el) {
1259
+ const renderRoot = el.shadowRoot || el;
1260
+ return renderRoot.querySelector(el.constructor.outlet || "wj-router-outlet");
875
1261
  }
876
- function zt() {
877
- if (x)
878
- return x;
879
- if (!S)
1262
+ function resolveRootOutlet() {
1263
+ if (rootOutletEl)
1264
+ return rootOutletEl;
1265
+ if (!rootOutlet)
880
1266
  return document.body;
881
- if (x = typeof S == "string" ? document.querySelector(S) : S, !x)
882
- throw new Error(`slick-router(wc): Invalid outlet option ${S}`);
883
- return x;
1267
+ rootOutletEl = typeof rootOutlet === "string" ? document.querySelector(rootOutlet) : rootOutlet;
1268
+ if (!rootOutletEl) {
1269
+ throw new Error(`slick-router(wc): Invalid outlet option ${rootOutlet}`);
1270
+ }
1271
+ return rootOutletEl;
884
1272
  }
885
- function Jt(r, t) {
886
- let e = r.routes[t];
887
- for (; e; ) {
888
- if (e.options.component)
889
- return $[e.name];
890
- e = r.routes[--t];
1273
+ function getParentEl(transition2, parentIndex) {
1274
+ let parent = transition2.routes[parentIndex];
1275
+ while (parent) {
1276
+ if (parent.options.component) {
1277
+ return routeElMap[parent.name];
1278
+ }
1279
+ parent = transition2.routes[--parentIndex];
891
1280
  }
892
1281
  }
893
- function Zt(r, t) {
894
- let e, n, i;
895
- const s = Math.max(r.length, t.length);
896
- for (e = 0; e < s && (n = r[e], i = t[e], !(!(n && i) || n.name !== i.name || !Qt(n.params, i.params))); e++)
897
- ;
898
- return e;
1282
+ function getChangingIndex(prevRoutes, currentRoutes) {
1283
+ let index, prev, current;
1284
+ const count = Math.max(prevRoutes.length, currentRoutes.length);
1285
+ for (index = 0; index < count; index++) {
1286
+ prev = prevRoutes[index];
1287
+ current = currentRoutes[index];
1288
+ if (!(prev && current) || prev.name !== current.name || !isEqual(prev.params, current.params)) {
1289
+ break;
1290
+ }
1291
+ }
1292
+ return index;
899
1293
  }
900
- async function I(r, t, e, n) {
901
- for (let i = 0; i < t.length; i++) {
902
- let s;
903
- const { route: c, el: o } = t[i], u = c.options[`${e}${n}`];
904
- if (typeof u == "function" && (s = await u(r), s === !1 && r.cancel()), r.isCancelled)
1294
+ async function runLifeCycle(transition2, routes, prefix, suffix) {
1295
+ for (let i = 0; i < routes.length; i++) {
1296
+ let result;
1297
+ const { route, el } = routes[i];
1298
+ const routeMethod = route.options[`${prefix}${suffix}`];
1299
+ if (typeof routeMethod === "function") {
1300
+ result = await routeMethod(transition2);
1301
+ if (result === false) {
1302
+ transition2.cancel();
1303
+ }
1304
+ }
1305
+ if (transition2.isCancelled)
905
1306
  break;
906
- const a = o && o[`${e}Route${n}`];
907
- if (typeof a == "function" && (s = await a.call(o, r), s === !1 && r.cancel()), r.isCancelled)
1307
+ const elMethod = el && el[`${prefix}Route${suffix}`];
1308
+ if (typeof elMethod === "function") {
1309
+ result = await elMethod.call(el, transition2);
1310
+ if (result === false) {
1311
+ transition2.cancel();
1312
+ }
1313
+ }
1314
+ if (transition2.isCancelled)
908
1315
  break;
909
1316
  }
910
1317
  }
911
- function Gt(r) {
912
- return r && r.__esModule ? r.default : r;
1318
+ function resolveModule(value) {
1319
+ return value && value.__esModule ? value.default : value;
913
1320
  }
914
- async function Xt(r) {
915
- const t = [];
916
- for (const e of r) {
917
- let n = e.options.reuse ? $[e.name] : void 0, i = e.options.component;
918
- !n && i && (typeof i == "function" && !(i.prototype instanceof HTMLElement) && (i = M[e.name] || (M[e.name] = Gt(await i(e)))), n = typeof i == "string" ? document.createElement(i) : new i(), $[e.name] = n, n.$router = j), t.push({ el: n, route: e });
1321
+ async function resolveComponents(routes) {
1322
+ const result = [];
1323
+ for (const route of routes) {
1324
+ let el = route.options.reuse ? routeElMap[route.name] : void 0;
1325
+ let Component = route.options.component;
1326
+ if (!el && Component) {
1327
+ if (typeof Component === "function" && !(Component.prototype instanceof HTMLElement)) {
1328
+ Component = routeComponentMap[route.name] || (routeComponentMap[route.name] = resolveModule(await Component(route)));
1329
+ }
1330
+ el = typeof Component === "string" ? document.createElement(Component) : new Component();
1331
+ routeElMap[route.name] = el;
1332
+ el.$router = router;
1333
+ }
1334
+ result.push({ el, route });
919
1335
  }
920
- return t;
1336
+ return result;
921
1337
  }
922
- function Q(r, t, e) {
923
- e && Object.keys(e).forEach((n) => {
924
- const i = e[n];
925
- t[n] = i instanceof Wt ? i.value(r) : i;
926
- });
1338
+ function applyProperties(transition2, el, properties) {
1339
+ if (properties) {
1340
+ Object.keys(properties).forEach((key) => {
1341
+ const value = properties[key];
1342
+ el[key] = value instanceof TransitionValue ? value.value(transition2) : value;
1343
+ });
1344
+ }
927
1345
  }
928
- const nt = /* @__PURE__ */ new WeakSet(), K = /* @__PURE__ */ new WeakMap();
929
- async function Yt(r, t, e) {
930
- const { path: n, pathname: i, routes: s, params: c, query: o } = r, u = { path: n, pathname: i, routes: s, params: c, query: o };
931
- for (let a = 0; a < e; a++) {
932
- const h = r.routes[a], g = $[h.name];
933
- g && (g.$route = u, Q(r, g, h.options.properties));
934
- }
935
- for (let a = 0; a < t.length; a++) {
936
- const { el: h, route: g } = t[a];
937
- if (h) {
938
- const m = Jt(r, e + a - 1), f = m ? Kt(m) : zt();
939
- if (f) {
940
- const d = K.get(f) || f.firstElementChild;
941
- d && (f.removeChild(d), nt.add(d)), h.$route = u, Q(r, h, g.options.properties), f.appendChild(h), K.set(f, h), await (h.updateComplete || Ht);
1346
+ const removedEls = /* @__PURE__ */ new WeakSet();
1347
+ const outletCurrentEl = /* @__PURE__ */ new WeakMap();
1348
+ async function renderElements(transition2, activated, changingIndex) {
1349
+ const { path, pathname, routes, params, query } = transition2;
1350
+ const routeState = { path, pathname, routes, params, query };
1351
+ for (let k = 0; k < changingIndex; k++) {
1352
+ const route = transition2.routes[k];
1353
+ const el = routeElMap[route.name];
1354
+ if (el) {
1355
+ el.$route = routeState;
1356
+ applyProperties(transition2, el, route.options.properties);
1357
+ }
1358
+ }
1359
+ for (let i = 0; i < activated.length; i++) {
1360
+ const { el, route } = activated[i];
1361
+ if (el) {
1362
+ const parentEl = getParentEl(transition2, changingIndex + i - 1);
1363
+ const outletEl = parentEl ? getOutlet(parentEl) : resolveRootOutlet();
1364
+ if (outletEl) {
1365
+ const currentEl = outletCurrentEl.get(outletEl) || outletEl.firstElementChild;
1366
+ if (currentEl) {
1367
+ outletEl.removeChild(currentEl);
1368
+ removedEls.add(currentEl);
1369
+ }
1370
+ el.$route = routeState;
1371
+ applyProperties(transition2, el, route.options.properties);
1372
+ outletEl.appendChild(el);
1373
+ outletCurrentEl.set(outletEl, el);
1374
+ await (el.updateComplete || resolved);
942
1375
  }
943
1376
  }
944
1377
  }
945
1378
  }
946
- function te(r, t) {
947
- let e;
948
- for (let n = t.length - 1; n >= 0; n--) {
949
- const { route: i, el: s } = t[n];
950
- r.some(({ route: c }) => c.name === i.name) || (s && (!e && !nt.has(s) && s.remove(), e = !0), $[i.name] = void 0);
1379
+ function updateDOMTree(activated, deactivated) {
1380
+ let parentElRemoved;
1381
+ for (let routeIndex = deactivated.length - 1; routeIndex >= 0; routeIndex--) {
1382
+ const { route, el } = deactivated[routeIndex];
1383
+ if (!activated.some(({ route: activeRoute }) => activeRoute.name === route.name)) {
1384
+ if (el) {
1385
+ if (!parentElRemoved && !removedEls.has(el))
1386
+ el.remove();
1387
+ parentElRemoved = true;
1388
+ }
1389
+ routeElMap[route.name] = void 0;
1390
+ }
951
1391
  }
952
1392
  }
953
- async function ee(r) {
954
- const t = r.prev.routes, e = Zt(t, r.routes), n = [];
955
- for (let s = t.length - 1; s >= e; s--) {
956
- const c = t[s];
957
- n.push({ el: $[c.name], route: c });
958
- }
959
- if (await I(r, n, "before", "Leave"), r.isCancelled)
1393
+ async function resolve(transition2) {
1394
+ const prevRoutes = transition2.prev.routes;
1395
+ const changingIndex = getChangingIndex(prevRoutes, transition2.routes);
1396
+ const deactivated = [];
1397
+ for (let routeIndex = prevRoutes.length - 1; routeIndex >= changingIndex; routeIndex--) {
1398
+ const route = prevRoutes[routeIndex];
1399
+ deactivated.push({ el: routeElMap[route.name], route });
1400
+ }
1401
+ await runLifeCycle(transition2, deactivated, "before", "Leave");
1402
+ if (transition2.isCancelled)
960
1403
  return;
961
- const i = await Xt(r.routes.slice(e));
962
- await I(r, i, "before", "Enter"), !r.isCancelled && (await Yt(r, i, e), te(i, n), r.activated = i, r.deactivated = n);
1404
+ const activated = await resolveComponents(transition2.routes.slice(changingIndex));
1405
+ await runLifeCycle(transition2, activated, "before", "Enter");
1406
+ if (transition2.isCancelled)
1407
+ return;
1408
+ await renderElements(transition2, activated, changingIndex);
1409
+ updateDOMTree(activated, deactivated);
1410
+ transition2.activated = activated;
1411
+ transition2.deactivated = deactivated;
963
1412
  }
964
- function re(r) {
965
- I(r, r.deactivated, "after", "Leave"), I(r, r.activated, "after", "Enter");
1413
+ function done(transition2) {
1414
+ runLifeCycle(transition2, transition2.deactivated, "after", "Leave");
1415
+ runLifeCycle(transition2, transition2.activated, "after", "Enter");
966
1416
  }
967
- const ne = {
968
- create: kt,
969
- destroy: Vt,
970
- resolve: ee,
971
- done: re
1417
+ const wc = {
1418
+ create,
1419
+ destroy,
1420
+ resolve,
1421
+ done
972
1422
  };
973
- let it;
974
- function _(r, t) {
975
- window.dispatchEvent(new CustomEvent(`${it}${r}`, { detail: t }));
1423
+ let eventPrefix;
1424
+ function trigger(name, detail) {
1425
+ window.dispatchEvent(new CustomEvent(`${eventPrefix}${name}`, { detail }));
976
1426
  }
977
- const ie = {
978
- create: function(r) {
979
- it = r.options.eventPrefix || "router-";
1427
+ const events = {
1428
+ create: function(router2) {
1429
+ eventPrefix = router2.options.eventPrefix || "router-";
980
1430
  },
981
- before: function(r) {
982
- _("before:transition", { transition: r });
1431
+ before: function(transition2) {
1432
+ trigger("before:transition", { transition: transition2 });
983
1433
  },
984
- done: function(r) {
985
- _("transition", { transition: r });
1434
+ done: function(transition2) {
1435
+ trigger("transition", { transition: transition2 });
986
1436
  },
987
- cancel: function(r, t) {
988
- t.type !== "TransitionRedirected" && _("abort", { transition: r, error: t });
1437
+ cancel: function(transition2, error) {
1438
+ if (error.type !== "TransitionRedirected") {
1439
+ trigger("abort", { transition: transition2, error });
1440
+ }
989
1441
  },
990
- error: function(r, t) {
991
- _("abort", { transition: r, error: t }), _("error", { transition: r, error: t });
1442
+ error: function(transition2, error) {
1443
+ trigger("abort", { transition: transition2, error });
1444
+ trigger("error", { transition: transition2, error });
992
1445
  }
993
1446
  };
994
- class se extends at {
1447
+ class Routerx extends WJElement {
995
1448
  constructor() {
996
1449
  super();
997
- A(this, "className", "Routerx");
998
- A(this, "setBreadcrumb", (e) => {
999
- let n = [
1000
- ...e.routes.filter((i) => "breadcrumb" in i.options).map((i, s) => {
1001
- var c, o;
1450
+ __publicField(this, "className", "Routerx");
1451
+ __publicField(this, "setBreadcrumb", (transition2) => {
1452
+ let breadcrumb = [
1453
+ ...transition2.routes.filter((obj) => "breadcrumb" in obj.options).map((b, i) => {
1454
+ var _a, _b;
1002
1455
  return {
1003
- name: i.options.breadcrumbPath || i.name,
1004
- text: i.options.breadcrumb instanceof Function ? (o = (c = i.options).breadcrumb) == null ? void 0 : o.call(c, e) : i.options.breadcrumb,
1005
- params: { ...i.params, ...e.params },
1006
- path: this.router.generate(i.name, { ...i.params, ...e.params })
1456
+ name: b.options.breadcrumbPath || b.name,
1457
+ text: b.options.breadcrumb instanceof Function ? (_b = (_a = b.options).breadcrumb) == null ? void 0 : _b.call(_a, transition2) : b.options.breadcrumb,
1458
+ params: { ...b.params, ...transition2.params },
1459
+ path: this.router.generate(b.name, { ...b.params, ...transition2.params })
1007
1460
  };
1008
1461
  })
1009
1462
  ];
1010
- e.breadcrumbs = n;
1463
+ transition2.breadcrumbs = breadcrumb;
1011
1464
  });
1012
- A(this, "resetScrollPosition", (e) => {
1465
+ __publicField(this, "resetScrollPosition", (transition2) => {
1013
1466
  window.scrollTo(0, 0);
1014
1467
  });
1015
1468
  }
@@ -1020,28 +1473,58 @@ class se extends at {
1020
1473
  this.isShadowRoot = "open";
1021
1474
  }
1022
1475
  afterDraw() {
1023
- const e = this.outerHTML, s = new DOMParser().parseFromString(e, "text/html").querySelector("wj-router"), c = this.parseElement(s).root;
1024
- this.router = new Mt({
1476
+ const htmlString = this.outerHTML;
1477
+ const parser = new DOMParser();
1478
+ const htmlDocument = parser.parseFromString(htmlString, "text/html");
1479
+ const rootElement = htmlDocument.querySelector("wj-router");
1480
+ const routes = this.parseElement(rootElement).root;
1481
+ this.router = new Router({
1025
1482
  outlet: this.outlet || "wj-router-outlet",
1026
- log: !1,
1027
- logError: !1,
1483
+ log: false,
1484
+ logError: false,
1028
1485
  root: this.root || "/",
1029
- pushState: !0
1030
- }), this.router.map(c), this.router.use(this.setBreadcrumb), this.router.use(ne), this.router.use(ct), this.router.use(ie), this.router.use(this.resetScrollPosition), this.router.listen(), Ft(this.router);
1031
- }
1032
- parseElement(e) {
1033
- const n = {}, i = e.attributes;
1034
- for (let o = 0; o < i.length; o++) {
1035
- const u = i[o].name, a = i[o].value;
1036
- u === "component" && a.indexOf(".js") > -1 ? (console.log("attributeValue", a, new URL(a, import.meta.url).href), n.component = () => import(new URL(a, import.meta.url).href)) : u !== "shadow" && (n[u] = a);
1486
+ pushState: true
1487
+ });
1488
+ this.router.map(routes);
1489
+ this.router.use(this.setBreadcrumb);
1490
+ this.router.use(wc);
1491
+ this.router.use(routerLinks);
1492
+ this.router.use(events);
1493
+ this.router.use(this.resetScrollPosition);
1494
+ this.router.listen();
1495
+ this.unbindIntercept = interceptLinks(this.router);
1496
+ }
1497
+ parseElement(element) {
1498
+ const obj = {};
1499
+ const attributes = element.attributes;
1500
+ for (let i = 0; i < attributes.length; i++) {
1501
+ const attributeName = attributes[i].name;
1502
+ const attributeValue = attributes[i].value;
1503
+ if (attributeName === "component" && attributeValue.indexOf(".js") > -1) {
1504
+ obj.component = () => import(new URL(attributeValue, import.meta.url).href);
1505
+ } else {
1506
+ if (attributeName !== "shadow") {
1507
+ obj[attributeName] = attributeValue;
1508
+ }
1509
+ }
1510
+ }
1511
+ const children = [];
1512
+ const childElements = Array.from(element.children);
1513
+ childElements.forEach((childElement) => {
1514
+ children.push(this.parseElement(childElement));
1515
+ });
1516
+ if (children.length > 0 && element.tagName === "WJ-ROUTE") {
1517
+ obj.children = children;
1518
+ } else {
1519
+ obj.root = children;
1037
1520
  }
1038
- const s = [];
1039
- return Array.from(e.children).forEach((o) => {
1040
- s.push(this.parseElement(o));
1041
- }), s.length > 0 && e.tagName === "WJ-ROUTE" ? n.children = s : n.root = s, n;
1521
+ return obj;
1522
+ }
1523
+ beforeDisconnect() {
1524
+ this.unbindIntercept();
1042
1525
  }
1043
1526
  }
1044
- customElements.get("wj-router") || window.customElements.define("wj-router", se);
1527
+ customElements.get("wj-router") || window.customElements.define("wj-router", Routerx);
1045
1528
  export {
1046
- se as Routerx
1529
+ Routerx
1047
1530
  };