wj-elements 0.7.7 → 0.8.0

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