@tarojs/router 3.3.15 → 3.4.0-beta.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.
@@ -1,236 +1,700 @@
1
- import { requestAnimationFrame, container, SERVICE_IDENTIFIER, eventCenter, Current, createPageConfig, stringify } from '@tarojs/runtime';
1
+ import _extends from '@babel/runtime/helpers/esm/extends';
2
+ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
3
+ import _regeneratorRuntime from '@babel/runtime/regenerator';
4
+ import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
5
+ import _createClass from '@babel/runtime/helpers/createClass';
6
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
7
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
8
+ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
9
+ import { requestAnimationFrame, container, SERVICE_IDENTIFIER, eventCenter, createPageConfig, stringify, Current } from '@tarojs/runtime';
10
+ import _typeof from '@babel/runtime/helpers/typeof';
11
+ import _createForOfIteratorHelper from '@babel/runtime/helpers/createForOfIteratorHelper';
12
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
13
+
14
+ var r,
15
+ B = r || (r = {});
16
+ B.Pop = "POP";
17
+ B.Push = "PUSH";
18
+ B.Replace = "REPLACE";
19
+ var C = "production" !== process.env.NODE_ENV ? function (b) {
20
+ return Object.freeze(b);
21
+ } : function (b) {
22
+ return b;
23
+ };
2
24
 
3
- function _extends() {
4
- _extends = Object.assign || function (target) {
5
- for (var i = 1; i < arguments.length; i++) {
6
- var source = arguments[i];
25
+ function D(b, h) {
26
+ if (!b) {
27
+ "undefined" !== typeof console && console.warn(h);
7
28
 
8
- for (var key in source) {
9
- if (Object.prototype.hasOwnProperty.call(source, key)) {
10
- target[key] = source[key];
11
- }
29
+ try {
30
+ throw Error(h);
31
+ } catch (k) {}
32
+ }
33
+ }
34
+
35
+ function E(b) {
36
+ b.preventDefault();
37
+ b.returnValue = "";
38
+ }
39
+
40
+ function F() {
41
+ var b = [];
42
+ return {
43
+ get length() {
44
+ return b.length;
45
+ },
46
+
47
+ push: function push(h) {
48
+ b.push(h);
49
+ return function () {
50
+ b = b.filter(function (k) {
51
+ return k !== h;
52
+ });
53
+ };
54
+ },
55
+ call: function call(h) {
56
+ b.forEach(function (k) {
57
+ return k && k(h);
58
+ });
59
+ }
60
+ };
61
+ }
62
+
63
+ function H() {
64
+ return Math.random().toString(36).substr(2, 8);
65
+ }
66
+
67
+ function I(b) {
68
+ var h = b.pathname,
69
+ k = b.search;
70
+ b = b.hash;
71
+ return (void 0 === h ? "/" : h) + (void 0 === k ? "" : k) + (void 0 === b ? "" : b);
72
+ }
73
+
74
+ function J(b) {
75
+ var h = {};
76
+
77
+ if (b) {
78
+ var k = b.indexOf("#");
79
+ 0 <= k && (h.hash = b.substr(k), b = b.substr(0, k));
80
+ k = b.indexOf("?");
81
+ 0 <= k && (h.search = b.substr(k), b = b.substr(0, k));
82
+ b && (h.pathname = b);
83
+ }
84
+
85
+ return h;
86
+ }
87
+
88
+ function createBrowserHistory(b) {
89
+ function h() {
90
+ var c = p.location,
91
+ a = m.state || {};
92
+ return [a.idx, C({
93
+ pathname: c.pathname,
94
+ search: c.search,
95
+ hash: c.hash,
96
+ state: a.usr || null,
97
+ key: a.key || "default"
98
+ })];
99
+ }
100
+
101
+ function k(c) {
102
+ return "string" === typeof c ? c : I(c);
103
+ }
104
+
105
+ function x(c, a) {
106
+ void 0 === a && (a = null);
107
+ return C(_extends({
108
+ pathname: q.pathname,
109
+ hash: "",
110
+ search: ""
111
+ }, "string" === typeof c ? J(c) : c, {
112
+ state: a,
113
+ key: H()
114
+ }));
115
+ }
116
+
117
+ function z(c) {
118
+ t = c;
119
+ c = h();
120
+ v = c[0];
121
+ q = c[1];
122
+ d.call({
123
+ action: t,
124
+ location: q
125
+ });
126
+ }
127
+
128
+ function A(c, a) {
129
+ function e() {
130
+ A(c, a);
131
+ }
132
+
133
+ var l = r.Push,
134
+ g = x(c, a);
135
+
136
+ if (!f.length || (f.call({
137
+ action: l,
138
+ location: g,
139
+ retry: e
140
+ }), !1)) {
141
+ var n = [{
142
+ usr: g.state,
143
+ key: g.key,
144
+ idx: v + 1
145
+ }, k(g)];
146
+ g = n[0];
147
+ n = n[1];
148
+
149
+ try {
150
+ m.pushState(g, "", n);
151
+ } catch (G) {
152
+ p.location.assign(n);
12
153
  }
154
+
155
+ z(l);
156
+ }
157
+ }
158
+
159
+ function y(c, a) {
160
+ function e() {
161
+ y(c, a);
13
162
  }
14
163
 
15
- return target;
164
+ var l = r.Replace,
165
+ g = x(c, a);
166
+ f.length && (f.call({
167
+ action: l,
168
+ location: g,
169
+ retry: e
170
+ }), 1) || (g = [{
171
+ usr: g.state,
172
+ key: g.key,
173
+ idx: v
174
+ }, k(g)], m.replaceState(g[0], "", g[1]), z(l));
175
+ }
176
+
177
+ function w(c) {
178
+ m.go(c);
179
+ }
180
+
181
+ void 0 === b && (b = {});
182
+ b = b.window;
183
+ var p = void 0 === b ? document.defaultView : b,
184
+ m = p.history,
185
+ u = null;
186
+ p.addEventListener("popstate", function () {
187
+ if (u) f.call(u), u = null;else {
188
+ var c = r.Pop,
189
+ a = h(),
190
+ e = a[0];
191
+ a = a[1];
192
+ if (f.length) {
193
+ if (null != e) {
194
+ var l = v - e;
195
+ l && (u = {
196
+ action: c,
197
+ location: a,
198
+ retry: function retry() {
199
+ w(-1 * l);
200
+ }
201
+ }, w(l));
202
+ } else "production" !== process.env.NODE_ENV ? D(!1, "You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.") : void 0;
203
+ } else z(c);
204
+ }
205
+ });
206
+ var t = r.Pop;
207
+ b = h();
208
+ var v = b[0],
209
+ q = b[1],
210
+ d = F(),
211
+ f = F();
212
+ null == v && (v = 0, m.replaceState(_extends({}, m.state, {
213
+ idx: v
214
+ }), ""));
215
+ return {
216
+ get action() {
217
+ return t;
218
+ },
219
+
220
+ get location() {
221
+ return q;
222
+ },
223
+
224
+ createHref: k,
225
+ push: A,
226
+ replace: y,
227
+ go: w,
228
+ back: function back() {
229
+ w(-1);
230
+ },
231
+ forward: function forward() {
232
+ w(1);
233
+ },
234
+ listen: function listen(c) {
235
+ return d.push(c);
236
+ },
237
+ block: function block(c) {
238
+ var a = f.push(c);
239
+ 1 === f.length && p.addEventListener("beforeunload", E);
240
+ return function () {
241
+ a();
242
+ f.length || p.removeEventListener("beforeunload", E);
243
+ };
244
+ }
16
245
  };
246
+ }
247
+
248
+ function createHashHistory(b) {
249
+ function h() {
250
+ var a = J(m.location.hash.substr(1)),
251
+ e = a.pathname,
252
+ l = a.search;
253
+ a = a.hash;
254
+ var g = u.state || {};
255
+ return [g.idx, C({
256
+ pathname: void 0 === e ? "/" : e,
257
+ search: void 0 === l ? "" : l,
258
+ hash: void 0 === a ? "" : a,
259
+ state: g.usr || null,
260
+ key: g.key || "default"
261
+ })];
262
+ }
263
+
264
+ function k() {
265
+ if (t) c.call(t), t = null;else {
266
+ var a = r.Pop,
267
+ e = h(),
268
+ l = e[0];
269
+ e = e[1];
270
+ if (c.length) {
271
+ if (null != l) {
272
+ var g = q - l;
273
+ g && (t = {
274
+ action: a,
275
+ location: e,
276
+ retry: function retry() {
277
+ p(-1 * g);
278
+ }
279
+ }, p(g));
280
+ } else "production" !== process.env.NODE_ENV ? D(!1, "You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation.") : void 0;
281
+ } else A(a);
282
+ }
283
+ }
17
284
 
18
- return _extends.apply(this, arguments);
285
+ function x(a) {
286
+ var e = document.querySelector("base"),
287
+ l = "";
288
+ e && e.getAttribute("href") && (e = m.location.href, l = e.indexOf("#"), l = -1 === l ? e : e.slice(0, l));
289
+ return l + "#" + ("string" === typeof a ? a : I(a));
290
+ }
291
+
292
+ function z(a, e) {
293
+ void 0 === e && (e = null);
294
+ return C(_extends({
295
+ pathname: d.pathname,
296
+ hash: "",
297
+ search: ""
298
+ }, "string" === typeof a ? J(a) : a, {
299
+ state: e,
300
+ key: H()
301
+ }));
302
+ }
303
+
304
+ function A(a) {
305
+ v = a;
306
+ a = h();
307
+ q = a[0];
308
+ d = a[1];
309
+ f.call({
310
+ action: v,
311
+ location: d
312
+ });
313
+ }
314
+
315
+ function y(a, e) {
316
+ function l() {
317
+ y(a, e);
318
+ }
319
+
320
+ var g = r.Push,
321
+ n = z(a, e);
322
+ "production" !== process.env.NODE_ENV ? D("/" === n.pathname.charAt(0), "Relative pathnames are not supported in hash history.push(" + JSON.stringify(a) + ")") : void 0;
323
+
324
+ if (!c.length || (c.call({
325
+ action: g,
326
+ location: n,
327
+ retry: l
328
+ }), !1)) {
329
+ var G = [{
330
+ usr: n.state,
331
+ key: n.key,
332
+ idx: q + 1
333
+ }, x(n)];
334
+ n = G[0];
335
+ G = G[1];
336
+
337
+ try {
338
+ u.pushState(n, "", G);
339
+ } catch (K) {
340
+ m.location.assign(G);
341
+ }
342
+
343
+ A(g);
344
+ }
345
+ }
346
+
347
+ function w(a, e) {
348
+ function l() {
349
+ w(a, e);
350
+ }
351
+
352
+ var g = r.Replace,
353
+ n = z(a, e);
354
+ "production" !== process.env.NODE_ENV ? D("/" === n.pathname.charAt(0), "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(a) + ")") : void 0;
355
+ c.length && (c.call({
356
+ action: g,
357
+ location: n,
358
+ retry: l
359
+ }), 1) || (n = [{
360
+ usr: n.state,
361
+ key: n.key,
362
+ idx: q
363
+ }, x(n)], u.replaceState(n[0], "", n[1]), A(g));
364
+ }
365
+
366
+ function p(a) {
367
+ u.go(a);
368
+ }
369
+
370
+ void 0 === b && (b = {});
371
+ b = b.window;
372
+ var m = void 0 === b ? document.defaultView : b,
373
+ u = m.history,
374
+ t = null;
375
+ m.addEventListener("popstate", k);
376
+ m.addEventListener("hashchange", function () {
377
+ var a = h()[1];
378
+ I(a) !== I(d) && k();
379
+ });
380
+ var v = r.Pop;
381
+ b = h();
382
+ var q = b[0],
383
+ d = b[1],
384
+ f = F(),
385
+ c = F();
386
+ null == q && (q = 0, u.replaceState(_extends({}, u.state, {
387
+ idx: q
388
+ }), ""));
389
+ return {
390
+ get action() {
391
+ return v;
392
+ },
393
+
394
+ get location() {
395
+ return d;
396
+ },
397
+
398
+ createHref: x,
399
+ push: y,
400
+ replace: w,
401
+ go: p,
402
+ back: function back() {
403
+ p(-1);
404
+ },
405
+ forward: function forward() {
406
+ p(1);
407
+ },
408
+ listen: function listen(a) {
409
+ return f.push(a);
410
+ },
411
+ block: function block(a) {
412
+ var e = c.push(a);
413
+ 1 === c.length && m.addEventListener("beforeunload", E);
414
+ return function () {
415
+ e();
416
+ c.length || m.removeEventListener("beforeunload", E);
417
+ };
418
+ }
419
+ };
19
420
  }
20
421
 
21
- var r,B=r||(r={});B.Pop="POP";B.Push="PUSH";B.Replace="REPLACE";var C="production"!==process.env.NODE_ENV?function(b){return Object.freeze(b)}:function(b){return b};function D(b,h){if(!b){"undefined"!==typeof console&&console.warn(h);try{throw Error(h);}catch(k){}}}function E(b){b.preventDefault();b.returnValue="";}
22
- function F(){var b=[];return {get length(){return b.length},push:function(h){b.push(h);return function(){b=b.filter(function(k){return k!==h});}},call:function(h){b.forEach(function(k){return k&&k(h)});}}}function H(){return Math.random().toString(36).substr(2,8)}function I(b){var h=b.pathname,k=b.search;b=b.hash;return (void 0===h?"/":h)+(void 0===k?"":k)+(void 0===b?"":b)}
23
- function J(b){var h={};if(b){var k=b.indexOf("#");0<=k&&(h.hash=b.substr(k),b=b.substr(0,k));k=b.indexOf("?");0<=k&&(h.search=b.substr(k),b=b.substr(0,k));b&&(h.pathname=b);}return h}
24
- function createBrowserHistory(b){function h(){var c=p.location,a=m.state||{};return [a.idx,C({pathname:c.pathname,search:c.search,hash:c.hash,state:a.usr||null,key:a.key||"default"})]}function k(c){return "string"===typeof c?c:I(c)}function x(c,a){void 0===a&&(a=null);return C(_extends({pathname:q.pathname,hash:"",search:""},"string"===typeof c?J(c):c,{state:a,key:H()}))}function z(c){t=c;c=h();v=c[0];q=c[1];d.call({action:t,location:q});}function A(c,a){function e(){A(c,a);}var l=r.Push,g=x(c,
25
- a);if(!f.length||(f.call({action:l,location:g,retry:e}),!1)){var n=[{usr:g.state,key:g.key,idx:v+1},k(g)];g=n[0];n=n[1];try{m.pushState(g,"",n);}catch(G){p.location.assign(n);}z(l);}}function y(c,a){function e(){y(c,a);}var l=r.Replace,g=x(c,a);f.length&&(f.call({action:l,location:g,retry:e}),1)||(g=[{usr:g.state,key:g.key,idx:v},k(g)],m.replaceState(g[0],"",g[1]),z(l));}function w(c){m.go(c);}void 0===b&&(b={});b=b.window;var p=void 0===b?document.defaultView:b,m=p.history,u=null;p.addEventListener("popstate",
26
- function(){if(u)f.call(u),u=null;else {var c=r.Pop,a=h(),e=a[0];a=a[1];if(f.length)if(null!=e){var l=v-e;l&&(u={action:c,location:a,retry:function(){w(-1*l);}},w(l));}else "production"!==process.env.NODE_ENV?D(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."):
27
- void 0;else z(c);}});var t=r.Pop;b=h();var v=b[0],q=b[1],d=F(),f=F();null==v&&(v=0,m.replaceState(_extends({},m.state,{idx:v}),""));return {get action(){return t},get location(){return q},createHref:k,push:A,replace:y,go:w,back:function(){w(-1);},forward:function(){w(1);},listen:function(c){return d.push(c)},block:function(c){var a=f.push(c);1===f.length&&p.addEventListener("beforeunload",E);return function(){a();f.length||p.removeEventListener("beforeunload",E);}}}}function createHashHistory(b){function h(){var a=J(m.location.hash.substr(1)),e=a.pathname,l=a.search;a=a.hash;var g=u.state||{};return [g.idx,C({pathname:void 0===e?"/":e,search:void 0===l?"":l,hash:void 0===a?"":a,state:g.usr||null,key:g.key||"default"})]}function k(){if(t)c.call(t),t=null;else {var a=r.Pop,e=h(),l=e[0];e=e[1];if(c.length)if(null!=l){var g=q-l;g&&(t={action:a,location:e,retry:function(){p(-1*g);}},p(g));}else "production"!==process.env.NODE_ENV?D(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."):
28
- void 0;else A(a);}}function x(a){var e=document.querySelector("base"),l="";e&&e.getAttribute("href")&&(e=m.location.href,l=e.indexOf("#"),l=-1===l?e:e.slice(0,l));return l+"#"+("string"===typeof a?a:I(a))}function z(a,e){void 0===e&&(e=null);return C(_extends({pathname:d.pathname,hash:"",search:""},"string"===typeof a?J(a):a,{state:e,key:H()}))}function A(a){v=a;a=h();q=a[0];d=a[1];f.call({action:v,location:d});}function y(a,e){function l(){y(a,e);}var g=r.Push,n=z(a,e);"production"!==process.env.NODE_ENV?
29
- D("/"===n.pathname.charAt(0),"Relative pathnames are not supported in hash history.push("+JSON.stringify(a)+")"):void 0;if(!c.length||(c.call({action:g,location:n,retry:l}),!1)){var G=[{usr:n.state,key:n.key,idx:q+1},x(n)];n=G[0];G=G[1];try{u.pushState(n,"",G);}catch(K){m.location.assign(G);}A(g);}}function w(a,e){function l(){w(a,e);}var g=r.Replace,n=z(a,e);"production"!==process.env.NODE_ENV?D("/"===n.pathname.charAt(0),"Relative pathnames are not supported in hash history.replace("+JSON.stringify(a)+
30
- ")"):void 0;c.length&&(c.call({action:g,location:n,retry:l}),1)||(n=[{usr:n.state,key:n.key,idx:q},x(n)],u.replaceState(n[0],"",n[1]),A(g));}function p(a){u.go(a);}void 0===b&&(b={});b=b.window;var m=void 0===b?document.defaultView:b,u=m.history,t=null;m.addEventListener("popstate",k);m.addEventListener("hashchange",function(){var a=h()[1];I(a)!==I(d)&&k();});var v=r.Pop;b=h();var q=b[0],d=b[1],f=F(),c=F();null==q&&(q=0,u.replaceState(_extends({},u.state,{idx:q}),""));return {get action(){return v},get location(){return d},
31
- createHref:x,push:y,replace:w,go:p,back:function(){p(-1);},forward:function(){p(1);},listen:function(a){return f.push(a)},block:function(a){var e=c.push(a);1===c.length&&m.addEventListener("beforeunload",E);return function(){e();c.length||m.removeEventListener("beforeunload",E);}}}}
32
-
33
- let history;
34
- let basename = '/';
35
- function setHistoryMode(mode, base = '/') {
36
- const options = {
37
- window
38
- };
39
- basename = base;
40
- if (mode === 'browser') {
41
- history = createBrowserHistory(options);
42
- }
43
- else {
44
- // default is hash
45
- history = createHashHistory(options);
46
- }
47
- }
48
- function prependBasename(url = '') {
49
- return basename.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
50
- }
51
- const hasBasename = (path, prefix) => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path);
52
- const stripBasename = (path, prefix) => hasBasename(path, prefix) ? path.substr(prefix.length) : path;
53
-
54
- class Stacks {
55
- constructor() {
56
- this.stacks = [];
57
- this.backDelta = 0;
58
- }
59
- set delta(delta) {
60
- if (delta > 0) {
61
- this.backDelta = delta;
62
- }
63
- else {
64
- --this.backDelta;
65
- }
66
- }
67
- get length() {
68
- return this.stacks.length;
69
- }
70
- get last() {
71
- return this.stacks[this.length - 1];
72
- }
73
- get() {
74
- return this.stacks;
75
- }
76
- getItem(index) {
77
- return this.stacks[index];
78
- }
79
- getDelta(pathname) {
80
- if (this.backDelta >= 1) {
81
- return this.backDelta;
82
- }
83
- // NOTE: 此处为了修复浏览器后退多级页面,在大量重复路由状况下可能出现判断错误的情况 (增强判断能力只能考虑在 query 中新增参数来判断,暂时搁置)
84
- const prevIndex = this.stacks.findIndex(r => { var _a; return ((_a = r.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) === pathname; });
85
- return this.length - 1 - prevIndex;
86
- }
87
- getPrevIndex(pathname) {
88
- return this.length - 1 - this.getDelta(pathname);
89
- }
90
- pop() {
91
- return this.stacks.pop();
92
- }
93
- push(page) {
94
- return this.stacks.push(page);
95
- }
96
- }
97
- const stacks = new Stacks();
98
-
99
- let routesAlias = {};
100
- function setRoutesAlias(alias) {
101
- routesAlias = alias;
102
- }
103
- function addLeadingSlash(path) {
104
- if (path == null) {
105
- return '';
106
- }
107
- return path.charAt(0) === '/' ? path : '/' + path;
108
- }
109
- const isTabBar = (config) => {
110
- var _a, _b;
111
- const { customRoutes = {}, basename = '', pathname } = config.router;
112
- const routePath = stripBasename(pathname, basename);
113
- const pagePath = ((_a = Object.entries(customRoutes).find(([, target]) => target === routePath)) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
114
- return !!pagePath && (((_b = config.tabBar) === null || _b === void 0 ? void 0 : _b.list) || []).some(t => t.pagePath === pagePath);
422
+ var history;
423
+ var basename = '/';
424
+ function setHistoryMode(mode) {
425
+ var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '/';
426
+ var options = {
427
+ window: window
428
+ };
429
+ basename = base;
430
+
431
+ if (mode === 'browser') {
432
+ history = createBrowserHistory(options);
433
+ } else {
434
+ // default is hash
435
+ history = createHashHistory(options);
436
+ }
437
+ }
438
+ function prependBasename() {
439
+ var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
440
+ return basename.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
441
+ }
442
+ var hasBasename = function hasBasename(path, prefix) {
443
+ return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path);
444
+ };
445
+ var stripBasename = function stripBasename(path, prefix) {
446
+ return hasBasename(path, prefix) ? path.substr(prefix.length) : path;
115
447
  };
116
448
 
117
- function processNavigateUrl(option) {
118
- var _a;
119
- const pathPieces = J(option.url);
120
- // 处理自定义路由
121
- Object.keys(routesAlias).forEach(key => {
122
- if (addLeadingSlash(key) === addLeadingSlash(pathPieces.pathname)) {
123
- pathPieces.pathname = routesAlias[key];
124
- }
125
- });
126
- // 处理相对路径
127
- if ((_a = pathPieces === null || pathPieces === void 0 ? void 0 : pathPieces.pathname) === null || _a === void 0 ? void 0 : _a.includes('./')) {
128
- const parts = history.location.pathname.split('/');
129
- parts.pop();
130
- pathPieces.pathname.split('/').forEach((item) => {
131
- if (item === '.') {
132
- return;
133
- }
134
- item === '..' ? parts.pop() : parts.push(item);
135
- });
136
- pathPieces.pathname = parts.join('/');
137
- }
138
- // 处理 basename
139
- pathPieces.pathname = prependBasename(pathPieces.pathname);
140
- // hack fix history v5 bug: https://github.com/remix-run/history/issues/814
141
- if (!pathPieces.search)
142
- pathPieces.search = '';
143
- return pathPieces;
144
- }
145
- async function navigate(option, method) {
146
- return new Promise((resolve, reject) => {
147
- const { success, complete, fail } = option;
148
- const unListen = history.listen(() => {
149
- success === null || success === void 0 ? void 0 : success();
150
- complete === null || complete === void 0 ? void 0 : complete();
151
- resolve();
152
- unListen();
153
- });
154
- try {
155
- if ('url' in option) {
156
- const pathPieces = processNavigateUrl(option);
157
- const state = { timestamp: Date.now() };
158
- if (method === 'navigateTo') {
159
- history.push(pathPieces, state);
160
- }
161
- else if (method === 'redirectTo') {
162
- history.replace(pathPieces, state);
163
- }
164
- }
165
- else if (method === 'navigateBack') {
166
- stacks.delta = option.delta;
167
- history.go(-option.delta);
168
- }
169
- }
170
- catch (error) {
171
- fail === null || fail === void 0 ? void 0 : fail(error);
172
- complete === null || complete === void 0 ? void 0 : complete();
173
- reject(error);
174
- }
175
- });
176
- }
177
- function navigateTo(option) {
178
- return navigate(option, 'navigateTo');
179
- }
180
- function redirectTo(option) {
181
- return navigate(option, 'redirectTo');
182
- }
183
- function navigateBack(options = { delta: 1 }) {
184
- if (!options.delta || options.delta < 1) {
185
- options.delta = 1;
186
- }
187
- return navigate(options, 'navigateBack');
188
- }
189
- function switchTab(option) {
190
- // TODO: 清除掉所有的栈去目标页面
191
- return redirectTo(option);
192
- }
193
- function reLaunch(option) {
194
- // TODO: 清除掉所有的栈去目标页面
195
- return redirectTo(option);
196
- }
197
- function getCurrentPages() {
198
- return stacks.get();
449
+ var Stacks = /*#__PURE__*/function () {
450
+ function Stacks() {
451
+ _classCallCheck(this, Stacks);
452
+
453
+ _defineProperty(this, "stacks", []);
454
+
455
+ _defineProperty(this, "backDelta", 0);
456
+ }
457
+
458
+ _createClass(Stacks, [{
459
+ key: "delta",
460
+ set: function set(delta) {
461
+ if (delta > 0) {
462
+ this.backDelta = delta;
463
+ } else {
464
+ --this.backDelta;
465
+ }
466
+ }
467
+ }, {
468
+ key: "length",
469
+ get: function get() {
470
+ return this.stacks.length;
471
+ }
472
+ }, {
473
+ key: "last",
474
+ get: function get() {
475
+ return this.stacks[this.length - 1];
476
+ }
477
+ }, {
478
+ key: "get",
479
+ value: function get() {
480
+ return this.stacks;
481
+ }
482
+ }, {
483
+ key: "getItem",
484
+ value: function getItem(index) {
485
+ return this.stacks[index];
486
+ }
487
+ }, {
488
+ key: "getDelta",
489
+ value: function getDelta(pathname) {
490
+ if (this.backDelta >= 1) {
491
+ return this.backDelta;
492
+ } // NOTE: 此处为了修复浏览器后退多级页面,在大量重复路由状况下可能出现判断错误的情况 (增强判断能力只能考虑在 query 中新增参数来判断,暂时搁置)
493
+
494
+
495
+ var prevIndex = this.stacks.findIndex(function (r) {
496
+ var _r$path;
497
+
498
+ return ((_r$path = r.path) === null || _r$path === void 0 ? void 0 : _r$path.replace(/\?.*/g, '')) === pathname;
499
+ });
500
+ return this.length - 1 - prevIndex;
501
+ }
502
+ }, {
503
+ key: "getPrevIndex",
504
+ value: function getPrevIndex(pathname) {
505
+ return this.length - 1 - this.getDelta(pathname);
506
+ }
507
+ }, {
508
+ key: "pop",
509
+ value: function pop() {
510
+ return this.stacks.pop();
511
+ }
512
+ }, {
513
+ key: "push",
514
+ value: function push(page) {
515
+ return this.stacks.push(page);
516
+ }
517
+ }]);
518
+
519
+ return Stacks;
520
+ }();
521
+
522
+ var stacks = new Stacks();
523
+
524
+ var routesAlias = {};
525
+ function setRoutesAlias(alias) {
526
+ routesAlias = alias;
199
527
  }
528
+ function addLeadingSlash(path) {
529
+ if (path == null) {
530
+ return '';
531
+ }
200
532
 
201
- /**
202
- * Expose `pathToRegexp`.
203
- */
204
- var pathToRegexp_1 = pathToRegexp;
205
- var match_1 = match;
206
- var regexpToFunction_1 = regexpToFunction;
207
- var parse_1 = parse;
208
- var compile_1 = compile;
209
- var tokensToFunction_1 = tokensToFunction;
210
- var tokensToRegExp_1 = tokensToRegExp;
533
+ return path.charAt(0) === '/' ? path : '/' + path;
534
+ } // eslint-disable-next-line @typescript-eslint/ban-types
535
+ var isTabBar = function isTabBar(config) {
536
+ var _Object$entries$find, _config$tabBar;
537
+
538
+ var _config$router = config.router,
539
+ _config$router$custom = _config$router.customRoutes,
540
+ customRoutes = _config$router$custom === void 0 ? {} : _config$router$custom,
541
+ _config$router$basena = _config$router.basename,
542
+ basename = _config$router$basena === void 0 ? '' : _config$router$basena,
543
+ pathname = _config$router.pathname;
544
+ var routePath = stripBasename(pathname, basename);
545
+ var pagePath = ((_Object$entries$find = Object.entries(customRoutes).find(function (_ref) {
546
+ var _ref2 = _slicedToArray(_ref, 2),
547
+ target = _ref2[1];
548
+
549
+ return target === routePath;
550
+ })) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[0]) || routePath;
551
+ return !!pagePath && (((_config$tabBar = config.tabBar) === null || _config$tabBar === void 0 ? void 0 : _config$tabBar.list) || []).some(function (t) {
552
+ return t.pagePath === pagePath;
553
+ });
554
+ };
555
+
556
+ function processNavigateUrl(option) {
557
+ var _pathPieces$pathname;
558
+
559
+ var pathPieces = J(option.url); // 处理自定义路由
560
+
561
+ Object.keys(routesAlias).forEach(function (key) {
562
+ if (addLeadingSlash(key) === addLeadingSlash(pathPieces.pathname)) {
563
+ pathPieces.pathname = routesAlias[key];
564
+ }
565
+ }); // 处理相对路径
566
+
567
+ if (pathPieces !== null && pathPieces !== void 0 && (_pathPieces$pathname = pathPieces.pathname) !== null && _pathPieces$pathname !== void 0 && _pathPieces$pathname.includes('./')) {
568
+ var parts = history.location.pathname.split('/');
569
+ parts.pop();
570
+ pathPieces.pathname.split('/').forEach(function (item) {
571
+ if (item === '.') {
572
+ return;
573
+ }
574
+
575
+ item === '..' ? parts.pop() : parts.push(item);
576
+ });
577
+ pathPieces.pathname = parts.join('/');
578
+ } // 处理 basename
579
+
580
+
581
+ pathPieces.pathname = prependBasename(pathPieces.pathname); // hack fix history v5 bug: https://github.com/remix-run/history/issues/814
582
+
583
+ if (!pathPieces.search) pathPieces.search = '';
584
+ return pathPieces;
585
+ }
586
+
587
+ function navigate(_x, _x2) {
588
+ return _navigate.apply(this, arguments);
589
+ }
590
+
591
+ function _navigate() {
592
+ _navigate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(option, method) {
593
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
594
+ while (1) {
595
+ switch (_context.prev = _context.next) {
596
+ case 0:
597
+ return _context.abrupt("return", new Promise(function (resolve, reject) {
598
+ var success = option.success,
599
+ complete = option.complete,
600
+ fail = option.fail;
601
+ var unListen = history.listen(function () {
602
+ success === null || success === void 0 ? void 0 : success();
603
+ complete === null || complete === void 0 ? void 0 : complete();
604
+ resolve();
605
+ unListen();
606
+ });
607
+
608
+ try {
609
+ if ('url' in option) {
610
+ var pathPieces = processNavigateUrl(option);
611
+ var state = {
612
+ timestamp: Date.now()
613
+ };
614
+
615
+ if (method === 'navigateTo') {
616
+ history.push(pathPieces, state);
617
+ } else if (method === 'redirectTo') {
618
+ history.replace(pathPieces, state);
619
+ }
620
+ } else if (method === 'navigateBack') {
621
+ stacks.delta = option.delta;
622
+ history.go(-option.delta);
623
+ }
624
+ } catch (error) {
625
+ fail === null || fail === void 0 ? void 0 : fail(error);
626
+ complete === null || complete === void 0 ? void 0 : complete();
627
+ reject(error);
628
+ }
629
+ }));
630
+
631
+ case 1:
632
+ case "end":
633
+ return _context.stop();
634
+ }
635
+ }
636
+ }, _callee);
637
+ }));
638
+ return _navigate.apply(this, arguments);
639
+ }
640
+
641
+ function navigateTo(option) {
642
+ return navigate(option, 'navigateTo');
643
+ }
644
+ function redirectTo(option) {
645
+ return navigate(option, 'redirectTo');
646
+ }
647
+ function navigateBack() {
648
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
649
+ delta: 1
650
+ };
651
+
652
+ if (!options.delta || options.delta < 1) {
653
+ options.delta = 1;
654
+ }
211
655
 
656
+ return navigate(options, 'navigateBack');
657
+ }
658
+ function switchTab(option) {
659
+ // TODO: 清除掉所有的栈去目标页面
660
+ return redirectTo(option);
661
+ }
662
+ function reLaunch(option) {
663
+ // TODO: 清除掉所有的栈去目标页面
664
+ return redirectTo(option);
665
+ }
666
+ function getCurrentPages() {
667
+ return stacks.get();
668
+ }
669
+
670
+ var pathToRegexp$2 = {exports: {}};
671
+
672
+ pathToRegexp$2.exports = pathToRegexp;
673
+ pathToRegexp$2.exports.match = match;
674
+ pathToRegexp$2.exports.regexpToFunction = regexpToFunction;
675
+ pathToRegexp$2.exports.parse = parse;
676
+ pathToRegexp$2.exports.compile = compile;
677
+ pathToRegexp$2.exports.tokensToFunction = tokensToFunction;
678
+ pathToRegexp$2.exports.tokensToRegExp = tokensToRegExp;
212
679
  /**
213
680
  * Default configs.
214
681
  */
215
- var DEFAULT_DELIMITER = '/';
216
682
 
683
+ var DEFAULT_DELIMITER = '/';
217
684
  /**
218
685
  * The main path matching regexp utility.
219
686
  *
220
687
  * @type {RegExp}
221
688
  */
222
- var PATH_REGEXP = new RegExp([
223
- // Match escaped characters that would otherwise appear in future matches.
224
- // This allows the user to escape special characters that won't transform.
225
- '(\\\\.)',
226
- // Match Express-style parameters and un-named parameters with a prefix
227
- // and optional suffixes. Matches appear as:
228
- //
229
- // ":test(\\d+)?" => ["test", "\d+", undefined, "?"]
230
- // "(\\d+)" => [undefined, undefined, "\d+", undefined]
231
- '(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?'
232
- ].join('|'), 'g');
233
689
 
690
+ var PATH_REGEXP = new RegExp([// Match escaped characters that would otherwise appear in future matches.
691
+ // This allows the user to escape special characters that won't transform.
692
+ '(\\\\.)', // Match Express-style parameters and un-named parameters with a prefix
693
+ // and optional suffixes. Matches appear as:
694
+ //
695
+ // ":test(\\d+)?" => ["test", "\d+", undefined, "?"]
696
+ // "(\\d+)" => [undefined, undefined, "\d+", undefined]
697
+ '(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?'].join('|'), 'g');
234
698
  /**
235
699
  * Parse a string for the raw tokens.
236
700
  *
@@ -238,13 +702,14 @@ var PATH_REGEXP = new RegExp([
238
702
  * @param {Object=} options
239
703
  * @return {!Array}
240
704
  */
241
- function parse (str, options) {
705
+
706
+ function parse(str, options) {
242
707
  var tokens = [];
243
708
  var key = 0;
244
709
  var index = 0;
245
710
  var path = '';
246
- var defaultDelimiter = (options && options.delimiter) || DEFAULT_DELIMITER;
247
- var whitelist = (options && options.whitelist) || undefined;
711
+ var defaultDelimiter = options && options.delimiter || DEFAULT_DELIMITER;
712
+ var whitelist = options && options.whitelist || undefined;
248
713
  var pathEscaped = false;
249
714
  var res;
250
715
 
@@ -253,13 +718,12 @@ function parse (str, options) {
253
718
  var escaped = res[1];
254
719
  var offset = res.index;
255
720
  path += str.slice(index, offset);
256
- index = offset + m.length;
721
+ index = offset + m.length; // Ignore already escaped sequences.
257
722
 
258
- // Ignore already escaped sequences.
259
723
  if (escaped) {
260
724
  path += escaped[1];
261
725
  pathEscaped = true;
262
- continue
726
+ continue;
263
727
  }
264
728
 
265
729
  var prev = '';
@@ -277,9 +741,9 @@ function parse (str, options) {
277
741
  prev = c;
278
742
  path = path.slice(0, k);
279
743
  }
280
- }
744
+ } // Push the current path onto the tokens.
745
+
281
746
 
282
- // Push the current path onto the tokens.
283
747
  if (path) {
284
748
  tokens.push(path);
285
749
  path = '';
@@ -290,27 +754,23 @@ function parse (str, options) {
290
754
  var optional = modifier === '?' || modifier === '*';
291
755
  var pattern = capture || group;
292
756
  var delimiter = prev || defaultDelimiter;
293
-
294
757
  tokens.push({
295
758
  name: name || key++,
296
759
  prefix: prev,
297
760
  delimiter: delimiter,
298
761
  optional: optional,
299
762
  repeat: repeat,
300
- pattern: pattern
301
- ? escapeGroup(pattern)
302
- : '[^' + escapeString(delimiter === defaultDelimiter ? delimiter : (delimiter + defaultDelimiter)) + ']+?'
763
+ pattern: pattern ? escapeGroup(pattern) : '[^' + escapeString(delimiter === defaultDelimiter ? delimiter : delimiter + defaultDelimiter) + ']+?'
303
764
  });
304
- }
765
+ } // Push any remaining characters.
766
+
305
767
 
306
- // Push any remaining characters.
307
768
  if (path || index < str.length) {
308
769
  tokens.push(path + str.substr(index));
309
770
  }
310
771
 
311
- return tokens
772
+ return tokens;
312
773
  }
313
-
314
774
  /**
315
775
  * Compile a string to a template function for the path.
316
776
  *
@@ -318,67 +778,73 @@ function parse (str, options) {
318
778
  * @param {Object=} options
319
779
  * @return {!function(Object=, Object=)}
320
780
  */
321
- function compile (str, options) {
322
- return tokensToFunction(parse(str, options), options)
323
- }
324
781
 
782
+
783
+ function compile(str, options) {
784
+ return tokensToFunction(parse(str, options), options);
785
+ }
325
786
  /**
326
787
  * Create path match function from `path-to-regexp` spec.
327
788
  */
328
- function match (str, options) {
789
+
790
+
791
+ function match(str, options) {
329
792
  var keys = [];
330
793
  var re = pathToRegexp(str, keys, options);
331
- return regexpToFunction(re, keys)
794
+ return regexpToFunction(re, keys);
332
795
  }
333
-
334
796
  /**
335
797
  * Create a path match function from `path-to-regexp` output.
336
798
  */
337
- function regexpToFunction (re, keys) {
799
+
800
+
801
+ function regexpToFunction(re, keys) {
338
802
  return function (pathname, options) {
339
803
  var m = re.exec(pathname);
340
- if (!m) return false
341
-
804
+ if (!m) return false;
342
805
  var path = m[0];
343
806
  var index = m.index;
344
807
  var params = {};
345
- var decode = (options && options.decode) || decodeURIComponent;
808
+ var decode = options && options.decode || decodeURIComponent;
346
809
 
347
810
  for (var i = 1; i < m.length; i++) {
348
- if (m[i] === undefined) continue
349
-
811
+ if (m[i] === undefined) continue;
350
812
  var key = keys[i - 1];
351
813
 
352
814
  if (key.repeat) {
353
815
  params[key.name] = m[i].split(key.delimiter).map(function (value) {
354
- return decode(value, key)
816
+ return decode(value, key);
355
817
  });
356
818
  } else {
357
819
  params[key.name] = decode(m[i], key);
358
820
  }
359
821
  }
360
822
 
361
- return { path: path, index: index, params: params }
362
- }
823
+ return {
824
+ path: path,
825
+ index: index,
826
+ params: params
827
+ };
828
+ };
363
829
  }
364
-
365
830
  /**
366
831
  * Expose a method for transforming tokens into the path function.
367
832
  */
368
- function tokensToFunction (tokens, options) {
833
+
834
+
835
+ function tokensToFunction(tokens, options) {
369
836
  // Compile all the tokens into regexps.
370
- var matches = new Array(tokens.length);
837
+ var matches = new Array(tokens.length); // Compile all the patterns before compilation.
371
838
 
372
- // Compile all the patterns before compilation.
373
839
  for (var i = 0; i < tokens.length; i++) {
374
- if (typeof tokens[i] === 'object') {
840
+ if (_typeof(tokens[i]) === 'object') {
375
841
  matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$', flags(options));
376
842
  }
377
843
  }
378
844
 
379
845
  return function (data, options) {
380
846
  var path = '';
381
- var encode = (options && options.encode) || encodeURIComponent;
847
+ var encode = options && options.encode || encodeURIComponent;
382
848
  var validate = options ? options.validate !== false : true;
383
849
 
384
850
  for (var i = 0; i < tokens.length; i++) {
@@ -386,7 +852,7 @@ function tokensToFunction (tokens, options) {
386
852
 
387
853
  if (typeof token === 'string') {
388
854
  path += token;
389
- continue
855
+ continue;
390
856
  }
391
857
 
392
858
  var value = data ? data[token.name] : undefined;
@@ -394,78 +860,78 @@ function tokensToFunction (tokens, options) {
394
860
 
395
861
  if (Array.isArray(value)) {
396
862
  if (!token.repeat) {
397
- throw new TypeError('Expected "' + token.name + '" to not repeat, but got array')
863
+ throw new TypeError('Expected "' + token.name + '" to not repeat, but got array');
398
864
  }
399
865
 
400
866
  if (value.length === 0) {
401
- if (token.optional) continue
402
-
403
- throw new TypeError('Expected "' + token.name + '" to not be empty')
867
+ if (token.optional) continue;
868
+ throw new TypeError('Expected "' + token.name + '" to not be empty');
404
869
  }
405
870
 
406
871
  for (var j = 0; j < value.length; j++) {
407
872
  segment = encode(value[j], token);
408
873
 
409
874
  if (validate && !matches[i].test(segment)) {
410
- throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '"')
875
+ throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '"');
411
876
  }
412
877
 
413
878
  path += (j === 0 ? token.prefix : token.delimiter) + segment;
414
879
  }
415
880
 
416
- continue
881
+ continue;
417
882
  }
418
883
 
419
884
  if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
420
885
  segment = encode(String(value), token);
421
886
 
422
887
  if (validate && !matches[i].test(segment)) {
423
- throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"')
888
+ throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"');
424
889
  }
425
890
 
426
891
  path += token.prefix + segment;
427
- continue
892
+ continue;
428
893
  }
429
894
 
430
- if (token.optional) continue
431
-
432
- throw new TypeError('Expected "' + token.name + '" to be ' + (token.repeat ? 'an array' : 'a string'))
895
+ if (token.optional) continue;
896
+ throw new TypeError('Expected "' + token.name + '" to be ' + (token.repeat ? 'an array' : 'a string'));
433
897
  }
434
898
 
435
- return path
436
- }
899
+ return path;
900
+ };
437
901
  }
438
-
439
902
  /**
440
903
  * Escape a regular expression string.
441
904
  *
442
905
  * @param {string} str
443
906
  * @return {string}
444
907
  */
445
- function escapeString (str) {
446
- return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1')
447
- }
448
908
 
909
+
910
+ function escapeString(str) {
911
+ return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1');
912
+ }
449
913
  /**
450
914
  * Escape the capturing group by escaping special characters and meaning.
451
915
  *
452
916
  * @param {string} group
453
917
  * @return {string}
454
918
  */
455
- function escapeGroup (group) {
456
- return group.replace(/([=!:$/()])/g, '\\$1')
457
- }
458
919
 
920
+
921
+ function escapeGroup(group) {
922
+ return group.replace(/([=!:$/()])/g, '\\$1');
923
+ }
459
924
  /**
460
925
  * Get the flags for a regexp from the options.
461
926
  *
462
927
  * @param {Object} options
463
928
  * @return {string}
464
929
  */
465
- function flags (options) {
466
- return options && options.sensitive ? '' : 'i'
467
- }
468
930
 
931
+
932
+ function flags(options) {
933
+ return options && options.sensitive ? '' : 'i';
934
+ }
469
935
  /**
470
936
  * Pull out keys from a regexp.
471
937
  *
@@ -473,10 +939,11 @@ function flags (options) {
473
939
  * @param {Array=} keys
474
940
  * @return {!RegExp}
475
941
  */
476
- function regexpToRegexp (path, keys) {
477
- if (!keys) return path
478
942
 
479
- // Use a negative lookahead to match only capturing groups.
943
+
944
+ function regexpToRegexp(path, keys) {
945
+ if (!keys) return path; // Use a negative lookahead to match only capturing groups.
946
+
480
947
  var groups = path.source.match(/\((?!\?)/g);
481
948
 
482
949
  if (groups) {
@@ -492,9 +959,8 @@ function regexpToRegexp (path, keys) {
492
959
  }
493
960
  }
494
961
 
495
- return path
962
+ return path;
496
963
  }
497
-
498
964
  /**
499
965
  * Transform an array into a regexp.
500
966
  *
@@ -503,16 +969,17 @@ function regexpToRegexp (path, keys) {
503
969
  * @param {Object=} options
504
970
  * @return {!RegExp}
505
971
  */
506
- function arrayToRegexp (path, keys, options) {
972
+
973
+
974
+ function arrayToRegexp(path, keys, options) {
507
975
  var parts = [];
508
976
 
509
977
  for (var i = 0; i < path.length; i++) {
510
978
  parts.push(pathToRegexp(path[i], keys, options).source);
511
979
  }
512
980
 
513
- return new RegExp('(?:' + parts.join('|') + ')', flags(options))
981
+ return new RegExp('(?:' + parts.join('|') + ')', flags(options));
514
982
  }
515
-
516
983
  /**
517
984
  * Create a path regexp from string input.
518
985
  *
@@ -521,10 +988,11 @@ function arrayToRegexp (path, keys, options) {
521
988
  * @param {Object=} options
522
989
  * @return {!RegExp}
523
990
  */
524
- function stringToRegexp (path, keys, options) {
525
- return tokensToRegExp(parse(path, options), keys, options)
526
- }
527
991
 
992
+
993
+ function stringToRegexp(path, keys, options) {
994
+ return tokensToRegExp(parse(path, options), keys, options);
995
+ }
528
996
  /**
529
997
  * Expose a function for taking tokens and returning a RegExp.
530
998
  *
@@ -533,27 +1001,24 @@ function stringToRegexp (path, keys, options) {
533
1001
  * @param {Object=} options
534
1002
  * @return {!RegExp}
535
1003
  */
536
- function tokensToRegExp (tokens, keys, options) {
537
- options = options || {};
538
1004
 
1005
+
1006
+ function tokensToRegExp(tokens, keys, options) {
1007
+ options = options || {};
539
1008
  var strict = options.strict;
540
1009
  var start = options.start !== false;
541
1010
  var end = options.end !== false;
542
1011
  var delimiter = options.delimiter || DEFAULT_DELIMITER;
543
1012
  var endsWith = [].concat(options.endsWith || []).map(escapeString).concat('$').join('|');
544
- var route = start ? '^' : '';
1013
+ var route = start ? '^' : ''; // Iterate over the tokens and create our regexp string.
545
1014
 
546
- // Iterate over the tokens and create our regexp string.
547
1015
  for (var i = 0; i < tokens.length; i++) {
548
1016
  var token = tokens[i];
549
1017
 
550
1018
  if (typeof token === 'string') {
551
1019
  route += escapeString(token);
552
1020
  } else {
553
- var capture = token.repeat
554
- ? '(?:' + token.pattern + ')(?:' + escapeString(token.delimiter) + '(?:' + token.pattern + '))*'
555
- : token.pattern;
556
-
1021
+ var capture = token.repeat ? '(?:' + token.pattern + ')(?:' + escapeString(token.delimiter) + '(?:' + token.pattern + '))*' : token.pattern;
557
1022
  if (keys) keys.push(token);
558
1023
 
559
1024
  if (token.optional) {
@@ -570,21 +1035,16 @@ function tokensToRegExp (tokens, keys, options) {
570
1035
 
571
1036
  if (end) {
572
1037
  if (!strict) route += '(?:' + escapeString(delimiter) + ')?';
573
-
574
1038
  route += endsWith === '$' ? '$' : '(?=' + endsWith + ')';
575
1039
  } else {
576
1040
  var endToken = tokens[tokens.length - 1];
577
- var isEndDelimited = typeof endToken === 'string'
578
- ? endToken[endToken.length - 1] === delimiter
579
- : endToken === undefined;
580
-
1041
+ var isEndDelimited = typeof endToken === 'string' ? endToken[endToken.length - 1] === delimiter : endToken === undefined;
581
1042
  if (!strict) route += '(?:' + escapeString(delimiter) + '(?=' + endsWith + '))?';
582
1043
  if (!isEndDelimited) route += '(?=' + escapeString(delimiter) + '|' + endsWith + ')';
583
1044
  }
584
1045
 
585
- return new RegExp(route, flags(options))
1046
+ return new RegExp(route, flags(options));
586
1047
  }
587
-
588
1048
  /**
589
1049
  * Normalize the given path string, returning a regular expression.
590
1050
  *
@@ -597,25 +1057,21 @@ function tokensToRegExp (tokens, keys, options) {
597
1057
  * @param {Object=} options
598
1058
  * @return {!RegExp}
599
1059
  */
600
- function pathToRegexp (path, keys, options) {
1060
+
1061
+
1062
+ function pathToRegexp(path, keys, options) {
601
1063
  if (path instanceof RegExp) {
602
- return regexpToRegexp(path, keys)
1064
+ return regexpToRegexp(path, keys);
603
1065
  }
604
1066
 
605
1067
  if (Array.isArray(path)) {
606
- return arrayToRegexp(/** @type {!Array} */ (path), keys, options)
1068
+ return arrayToRegexp(path, keys, options);
607
1069
  }
608
1070
 
609
- return stringToRegexp(/** @type {string} */ (path), keys, options)
1071
+ return stringToRegexp(path, keys, options);
610
1072
  }
611
- pathToRegexp_1.match = match_1;
612
- pathToRegexp_1.regexpToFunction = regexpToFunction_1;
613
- pathToRegexp_1.parse = parse_1;
614
- pathToRegexp_1.compile = compile_1;
615
- pathToRegexp_1.tokensToFunction = tokensToFunction_1;
616
- pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
617
1073
 
618
- /*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */
1074
+ var pathToRegexp$1 = pathToRegexp$2.exports;
619
1075
 
620
1076
  var hasOwnProperty = Object.prototype.hasOwnProperty;
621
1077
  var cache = new Map();
@@ -637,7 +1093,7 @@ function matchPath(route, pathname, parentKeys, parentParams) {
637
1093
  var keys = [];
638
1094
  regexp = {
639
1095
  keys: keys,
640
- pattern: pathToRegexp_1(route.path || '', keys, {
1096
+ pattern: pathToRegexp$1(route.path || '', keys, {
641
1097
  end: end
642
1098
  })
643
1099
  };
@@ -760,7 +1216,7 @@ var UniversalRouter = function () {
760
1216
  options = {};
761
1217
  }
762
1218
 
763
- if (!routes || typeof routes !== 'object') {
1219
+ if (!routes || _typeof(routes) !== 'object') {
764
1220
  throw new TypeError('Invalid routes');
765
1221
  }
766
1222
 
@@ -839,851 +1295,975 @@ var UniversalRouter = function () {
839
1295
  return UniversalRouter;
840
1296
  }();
841
1297
 
842
- UniversalRouter.pathToRegexp = pathToRegexp_1;
843
-
844
- const Taro = require('@tarojs/taro-h5');
845
- function initTabbar(config) {
846
- if (config.tabBar == null) {
847
- return;
848
- }
849
- // TODO: 找到 tabbar 的类型
850
- const tabbar = document.createElement('taro-tabbar');
851
- const homePage = config.pages ? config.pages[0] : '';
852
- tabbar.conf = config.tabBar;
853
- tabbar.conf.homePage = history.location.pathname === '/' ? homePage : history.location.pathname;
854
- const routerConfig = config.router;
855
- tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
856
- if (routerConfig.customRoutes) {
857
- tabbar.conf.custom = true;
858
- tabbar.conf.customRoutes = routerConfig.customRoutes;
859
- }
860
- else {
861
- tabbar.conf.custom = false;
862
- tabbar.conf.customRoutes = {};
863
- }
864
- if (typeof routerConfig.basename !== 'undefined') {
865
- tabbar.conf.basename = routerConfig.basename;
866
- }
867
- const container = document.getElementById('container');
868
- // eslint-disable-next-line no-unused-expressions
869
- container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
870
- Taro.initTabBarApis(config);
1298
+ UniversalRouter.pathToRegexp = pathToRegexp$1;
1299
+
1300
+ var Taro = require('@tarojs/taro-h5');
1301
+
1302
+ function initTabbar(config) {
1303
+ if (config.tabBar == null) {
1304
+ return;
1305
+ } // TODO: 找到 tabbar 的类型
1306
+
1307
+
1308
+ var tabbar = document.createElement('taro-tabbar');
1309
+ var homePage = config.pages ? config.pages[0] : '';
1310
+ tabbar.conf = config.tabBar;
1311
+ tabbar.conf.homePage = history.location.pathname === '/' ? homePage : history.location.pathname;
1312
+ var routerConfig = config.router;
1313
+ tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
1314
+
1315
+ if (routerConfig.customRoutes) {
1316
+ tabbar.conf.custom = true;
1317
+ tabbar.conf.customRoutes = routerConfig.customRoutes;
1318
+ } else {
1319
+ tabbar.conf.custom = false;
1320
+ tabbar.conf.customRoutes = {};
1321
+ }
1322
+
1323
+ if (typeof routerConfig.basename !== 'undefined') {
1324
+ tabbar.conf.basename = routerConfig.basename;
1325
+ }
1326
+
1327
+ var container = document.getElementById('container'); // eslint-disable-next-line no-unused-expressions
1328
+
1329
+ container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
1330
+ Taro.initTabBarApis(config);
871
1331
  }
872
1332
 
873
- const routerConfig = Object.create(null);
874
- function init(config) {
875
- var _a;
876
- config.router.mode = config.router.mode || 'hash';
877
- setHistoryMode(config.router.mode, config.router.basename);
878
- Object.assign(routerConfig, config);
879
- (_a = document.getElementById('app')) === null || _a === void 0 ? void 0 : _a.remove();
880
- const container = document.createElement('div');
881
- container.classList.add('taro-tabbar__container');
882
- container.id = 'container';
883
- const panel = document.createElement('div');
884
- panel.classList.add('taro-tabbar__panel');
885
- const app = document.createElement('div');
886
- app.id = 'app';
887
- app.classList.add('taro_router');
888
- panel.appendChild(app);
889
- container.appendChild(panel);
890
- document.body.appendChild(container);
891
- initTabbar(config);
1333
+ var routerConfig = Object.create(null);
1334
+ function init(config) {
1335
+ var _document$getElementB;
1336
+
1337
+ config.router.mode = config.router.mode || 'hash';
1338
+ setHistoryMode(config.router.mode, config.router.basename);
1339
+ Object.assign(routerConfig, config);
1340
+ (_document$getElementB = document.getElementById('app')) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
1341
+ var container = document.createElement('div');
1342
+ container.classList.add('taro-tabbar__container');
1343
+ container.id = 'container';
1344
+ var panel = document.createElement('div');
1345
+ panel.classList.add('taro-tabbar__panel');
1346
+ var app = document.createElement('div');
1347
+ app.id = 'app';
1348
+ app.classList.add('taro_router');
1349
+ panel.appendChild(app);
1350
+ container.appendChild(panel);
1351
+ document.body.appendChild(container);
1352
+ initTabbar(config);
1353
+ }
1354
+
1355
+ var pageScrollFn;
1356
+ var pageDOM = window;
1357
+ function bindPageScroll(page, config) {
1358
+ pageDOM.removeEventListener('scroll', pageScrollFn);
1359
+ pageDOM = getScrollContainer();
1360
+ var distance = config.onReachBottomDistance || 50;
1361
+ var isReachBottom = false;
1362
+
1363
+ pageScrollFn = function pageScrollFn() {
1364
+ page.onPageScroll && page.onPageScroll({
1365
+ scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
1366
+ });
1367
+
1368
+ if (isReachBottom && getOffset() > distance) {
1369
+ isReachBottom = false;
1370
+ }
1371
+
1372
+ if (page.onReachBottom && !isReachBottom && getOffset() < distance) {
1373
+ isReachBottom = true;
1374
+ page.onReachBottom();
1375
+ }
1376
+ };
1377
+
1378
+ pageDOM.addEventListener('scroll', pageScrollFn, false);
892
1379
  }
1380
+ window.addEventListener('DOMSubtreeModified', function (e) {
1381
+ var _e$target;
893
1382
 
894
- let pageScrollFn;
895
- let pageDOM = window;
896
- function bindPageScroll(page, config) {
897
- pageDOM.removeEventListener('scroll', pageScrollFn);
898
- pageDOM = getScrollContainer();
899
- const distance = config.onReachBottomDistance || 50;
900
- let isReachBottom = false;
901
- pageScrollFn = function () {
902
- page.onPageScroll && page.onPageScroll({
903
- scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
904
- });
905
- if (isReachBottom && getOffset() > distance) {
906
- isReachBottom = false;
907
- }
908
- if (page.onReachBottom &&
909
- !isReachBottom &&
910
- getOffset() < distance) {
911
- isReachBottom = true;
912
- page.onReachBottom();
913
- }
914
- };
915
- pageDOM.addEventListener('scroll', pageScrollFn, false);
916
- }
917
- window.addEventListener('DOMSubtreeModified', (e) => {
918
- var _a;
919
- // @ts-ignore
920
- const className = (_a = e.target) === null || _a === void 0 ? void 0 : _a.className;
921
- if (className && /taro-tabbar__/.test(className)) {
922
- pageDOM.removeEventListener('scroll', pageScrollFn);
923
- pageDOM = getScrollContainer();
924
- pageDOM.addEventListener('scroll', pageScrollFn, false);
925
- }
926
- }, false);
927
- function getScrollContainer() {
928
- if (document.querySelector('.taro-tabbar__tabbar') === null) {
929
- // 没设置tabbar
930
- return window;
931
- }
932
- else {
933
- // 有设置tabbar
934
- return document.querySelector('.taro-tabbar__panel') || window;
935
- }
936
- }
937
- function getOffset() {
938
- if (pageDOM instanceof Window) {
939
- return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
940
- }
941
- else {
942
- return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
943
- }
1383
+ // @ts-ignore
1384
+ var className = (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.className;
1385
+
1386
+ if (className && /taro-tabbar__/.test(className)) {
1387
+ pageDOM.removeEventListener('scroll', pageScrollFn);
1388
+ pageDOM = getScrollContainer();
1389
+ pageDOM.addEventListener('scroll', pageScrollFn, false);
1390
+ }
1391
+ }, false);
1392
+
1393
+ function getScrollContainer() {
1394
+ if (document.querySelector('.taro-tabbar__tabbar') === null) {
1395
+ // 没设置tabbar
1396
+ return window;
1397
+ } else {
1398
+ // 有设置tabbar
1399
+ return document.querySelector('.taro-tabbar__panel') || window;
1400
+ }
944
1401
  }
945
1402
 
946
- function createCommonjsModule(fn, module) {
947
- return module = { exports: {} }, fn(module, module.exports), module.exports;
1403
+ function getOffset() {
1404
+ if (pageDOM instanceof Window) {
1405
+ return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
1406
+ } else {
1407
+ return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
1408
+ }
948
1409
  }
949
1410
 
950
- var strictUriEncode = str => encodeURIComponent(str).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`);
1411
+ var queryString = {};
1412
+
1413
+ var strictUriEncode = function strictUriEncode(str) {
1414
+ return encodeURIComponent(str).replace(/[!'()*]/g, function (x) {
1415
+ return "%".concat(x.charCodeAt(0).toString(16).toUpperCase());
1416
+ });
1417
+ };
951
1418
 
952
1419
  var token = '%[a-f0-9]{2}';
953
1420
  var singleMatcher = new RegExp(token, 'gi');
954
1421
  var multiMatcher = new RegExp('(' + token + ')+', 'gi');
955
1422
 
956
1423
  function decodeComponents(components, split) {
957
- try {
958
- // Try to decode the entire string first
959
- return decodeURIComponent(components.join(''));
960
- } catch (err) {
961
- // Do nothing
962
- }
963
-
964
- if (components.length === 1) {
965
- return components;
966
- }
1424
+ try {
1425
+ // Try to decode the entire string first
1426
+ return decodeURIComponent(components.join(''));
1427
+ } catch (err) {// Do nothing
1428
+ }
967
1429
 
968
- split = split || 1;
1430
+ if (components.length === 1) {
1431
+ return components;
1432
+ }
969
1433
 
970
- // Split the array in 2 parts
971
- var left = components.slice(0, split);
972
- var right = components.slice(split);
1434
+ split = split || 1; // Split the array in 2 parts
973
1435
 
974
- return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
1436
+ var left = components.slice(0, split);
1437
+ var right = components.slice(split);
1438
+ return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
975
1439
  }
976
1440
 
977
1441
  function decode(input) {
978
- try {
979
- return decodeURIComponent(input);
980
- } catch (err) {
981
- var tokens = input.match(singleMatcher);
982
-
983
- for (var i = 1; i < tokens.length; i++) {
984
- input = decodeComponents(tokens, i).join('');
1442
+ try {
1443
+ return decodeURIComponent(input);
1444
+ } catch (err) {
1445
+ var tokens = input.match(singleMatcher);
985
1446
 
986
- tokens = input.match(singleMatcher);
987
- }
1447
+ for (var i = 1; i < tokens.length; i++) {
1448
+ input = decodeComponents(tokens, i).join('');
1449
+ tokens = input.match(singleMatcher);
1450
+ }
988
1451
 
989
- return input;
990
- }
1452
+ return input;
1453
+ }
991
1454
  }
992
1455
 
993
1456
  function customDecodeURIComponent(input) {
994
- // Keep track of all the replacements and prefill the map with the `BOM`
995
- var replaceMap = {
996
- '%FE%FF': '\uFFFD\uFFFD',
997
- '%FF%FE': '\uFFFD\uFFFD'
998
- };
999
-
1000
- var match = multiMatcher.exec(input);
1001
- while (match) {
1002
- try {
1003
- // Decode as big chunks as possible
1004
- replaceMap[match[0]] = decodeURIComponent(match[0]);
1005
- } catch (err) {
1006
- var result = decode(match[0]);
1007
-
1008
- if (result !== match[0]) {
1009
- replaceMap[match[0]] = result;
1010
- }
1011
- }
1012
-
1013
- match = multiMatcher.exec(input);
1014
- }
1015
-
1016
- // Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
1017
- replaceMap['%C2'] = '\uFFFD';
1018
-
1019
- var entries = Object.keys(replaceMap);
1020
-
1021
- for (var i = 0; i < entries.length; i++) {
1022
- // Replace all decoded components
1023
- var key = entries[i];
1024
- input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
1025
- }
1026
-
1027
- return input;
1457
+ // Keep track of all the replacements and prefill the map with the `BOM`
1458
+ var replaceMap = {
1459
+ '%FE%FF': "\uFFFD\uFFFD",
1460
+ '%FF%FE': "\uFFFD\uFFFD"
1461
+ };
1462
+ var match = multiMatcher.exec(input);
1463
+
1464
+ while (match) {
1465
+ try {
1466
+ // Decode as big chunks as possible
1467
+ replaceMap[match[0]] = decodeURIComponent(match[0]);
1468
+ } catch (err) {
1469
+ var result = decode(match[0]);
1470
+
1471
+ if (result !== match[0]) {
1472
+ replaceMap[match[0]] = result;
1473
+ }
1474
+ }
1475
+
1476
+ match = multiMatcher.exec(input);
1477
+ } // Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
1478
+
1479
+
1480
+ replaceMap['%C2'] = "\uFFFD";
1481
+ var entries = Object.keys(replaceMap);
1482
+
1483
+ for (var i = 0; i < entries.length; i++) {
1484
+ // Replace all decoded components
1485
+ var key = entries[i];
1486
+ input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
1487
+ }
1488
+
1489
+ return input;
1028
1490
  }
1029
1491
 
1030
- var decodeUriComponent = function (encodedURI) {
1031
- if (typeof encodedURI !== 'string') {
1032
- throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + typeof encodedURI + '`');
1033
- }
1492
+ var decodeUriComponent = function decodeUriComponent(encodedURI) {
1493
+ if (typeof encodedURI !== 'string') {
1494
+ throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + _typeof(encodedURI) + '`');
1495
+ }
1034
1496
 
1035
- try {
1036
- encodedURI = encodedURI.replace(/\+/g, ' ');
1497
+ try {
1498
+ encodedURI = encodedURI.replace(/\+/g, ' '); // Try the built in decoder first
1037
1499
 
1038
- // Try the built in decoder first
1039
- return decodeURIComponent(encodedURI);
1040
- } catch (err) {
1041
- // Fallback to a more advanced decoder
1042
- return customDecodeURIComponent(encodedURI);
1043
- }
1500
+ return decodeURIComponent(encodedURI);
1501
+ } catch (err) {
1502
+ // Fallback to a more advanced decoder
1503
+ return customDecodeURIComponent(encodedURI);
1504
+ }
1044
1505
  };
1045
1506
 
1046
- var splitOnFirst = (string, separator) => {
1047
- if (!(typeof string === 'string' && typeof separator === 'string')) {
1048
- throw new TypeError('Expected the arguments to be of type `string`');
1049
- }
1507
+ var splitOnFirst = function splitOnFirst(string, separator) {
1508
+ if (!(typeof string === 'string' && typeof separator === 'string')) {
1509
+ throw new TypeError('Expected the arguments to be of type `string`');
1510
+ }
1050
1511
 
1051
- if (separator === '') {
1052
- return [string];
1053
- }
1512
+ if (separator === '') {
1513
+ return [string];
1514
+ }
1054
1515
 
1055
- const separatorIndex = string.indexOf(separator);
1516
+ var separatorIndex = string.indexOf(separator);
1056
1517
 
1057
- if (separatorIndex === -1) {
1058
- return [string];
1059
- }
1518
+ if (separatorIndex === -1) {
1519
+ return [string];
1520
+ }
1060
1521
 
1061
- return [
1062
- string.slice(0, separatorIndex),
1063
- string.slice(separatorIndex + separator.length)
1064
- ];
1522
+ return [string.slice(0, separatorIndex), string.slice(separatorIndex + separator.length)];
1065
1523
  };
1066
1524
 
1067
- var filterObj = function (obj, predicate) {
1068
- var ret = {};
1069
- var keys = Object.keys(obj);
1070
- var isArr = Array.isArray(predicate);
1525
+ var filterObj = function filterObj(obj, predicate) {
1526
+ var ret = {};
1527
+ var keys = Object.keys(obj);
1528
+ var isArr = Array.isArray(predicate);
1071
1529
 
1072
- for (var i = 0; i < keys.length; i++) {
1073
- var key = keys[i];
1074
- var val = obj[key];
1530
+ for (var i = 0; i < keys.length; i++) {
1531
+ var key = keys[i];
1532
+ var val = obj[key];
1075
1533
 
1076
- if (isArr ? predicate.indexOf(key) !== -1 : predicate(key, val, obj)) {
1077
- ret[key] = val;
1078
- }
1079
- }
1534
+ if (isArr ? predicate.indexOf(key) !== -1 : predicate(key, val, obj)) {
1535
+ ret[key] = val;
1536
+ }
1537
+ }
1080
1538
 
1081
- return ret;
1539
+ return ret;
1082
1540
  };
1083
1541
 
1084
- var queryString = createCommonjsModule(function (module, exports) {
1085
-
1086
-
1087
-
1088
-
1089
-
1090
- const isNullOrUndefined = value => value === null || value === undefined;
1091
-
1092
- function encoderForArrayFormat(options) {
1093
- switch (options.arrayFormat) {
1094
- case 'index':
1095
- return key => (result, value) => {
1096
- const index = result.length;
1097
-
1098
- if (
1099
- value === undefined ||
1100
- (options.skipNull && value === null) ||
1101
- (options.skipEmptyString && value === '')
1102
- ) {
1103
- return result;
1104
- }
1105
-
1106
- if (value === null) {
1107
- return [...result, [encode(key, options), '[', index, ']'].join('')];
1108
- }
1109
-
1110
- return [
1111
- ...result,
1112
- [encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join('')
1113
- ];
1114
- };
1115
-
1116
- case 'bracket':
1117
- return key => (result, value) => {
1118
- if (
1119
- value === undefined ||
1120
- (options.skipNull && value === null) ||
1121
- (options.skipEmptyString && value === '')
1122
- ) {
1123
- return result;
1124
- }
1125
-
1126
- if (value === null) {
1127
- return [...result, [encode(key, options), '[]'].join('')];
1128
- }
1129
-
1130
- return [...result, [encode(key, options), '[]=', encode(value, options)].join('')];
1131
- };
1132
-
1133
- case 'comma':
1134
- case 'separator':
1135
- return key => (result, value) => {
1136
- if (value === null || value === undefined || value.length === 0) {
1137
- return result;
1138
- }
1139
-
1140
- if (result.length === 0) {
1141
- return [[encode(key, options), '=', encode(value, options)].join('')];
1142
- }
1143
-
1144
- return [[result, encode(value, options)].join(options.arrayFormatSeparator)];
1145
- };
1146
-
1147
- default:
1148
- return key => (result, value) => {
1149
- if (
1150
- value === undefined ||
1151
- (options.skipNull && value === null) ||
1152
- (options.skipEmptyString && value === '')
1153
- ) {
1154
- return result;
1155
- }
1156
-
1157
- if (value === null) {
1158
- return [...result, encode(key, options)];
1159
- }
1160
-
1161
- return [...result, [encode(key, options), '=', encode(value, options)].join('')];
1162
- };
1163
- }
1164
- }
1542
+ (function (exports) {
1165
1543
 
1166
- function parserForArrayFormat(options) {
1167
- let result;
1168
-
1169
- switch (options.arrayFormat) {
1170
- case 'index':
1171
- return (key, value, accumulator) => {
1172
- result = /\[(\d*)\]$/.exec(key);
1173
-
1174
- key = key.replace(/\[\d*\]$/, '');
1175
-
1176
- if (!result) {
1177
- accumulator[key] = value;
1178
- return;
1179
- }
1180
-
1181
- if (accumulator[key] === undefined) {
1182
- accumulator[key] = {};
1183
- }
1184
-
1185
- accumulator[key][result[1]] = value;
1186
- };
1187
-
1188
- case 'bracket':
1189
- return (key, value, accumulator) => {
1190
- result = /(\[\])$/.exec(key);
1191
- key = key.replace(/\[\]$/, '');
1192
-
1193
- if (!result) {
1194
- accumulator[key] = value;
1195
- return;
1196
- }
1197
-
1198
- if (accumulator[key] === undefined) {
1199
- accumulator[key] = [value];
1200
- return;
1201
- }
1202
-
1203
- accumulator[key] = [].concat(accumulator[key], value);
1204
- };
1205
-
1206
- case 'comma':
1207
- case 'separator':
1208
- return (key, value, accumulator) => {
1209
- const isArray = typeof value === 'string' && value.includes(options.arrayFormatSeparator);
1210
- const isEncodedArray = (typeof value === 'string' && !isArray && decode(value, options).includes(options.arrayFormatSeparator));
1211
- value = isEncodedArray ? decode(value, options) : value;
1212
- const newValue = isArray || isEncodedArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : value === null ? value : decode(value, options);
1213
- accumulator[key] = newValue;
1214
- };
1215
-
1216
- default:
1217
- return (key, value, accumulator) => {
1218
- if (accumulator[key] === undefined) {
1219
- accumulator[key] = value;
1220
- return;
1221
- }
1222
-
1223
- accumulator[key] = [].concat(accumulator[key], value);
1224
- };
1225
- }
1226
- }
1544
+ var strictUriEncode$1 = strictUriEncode;
1545
+ var decodeComponent = decodeUriComponent;
1546
+ var splitOnFirst$1 = splitOnFirst;
1547
+ var filterObject = filterObj;
1227
1548
 
1228
- function validateArrayFormatSeparator(value) {
1229
- if (typeof value !== 'string' || value.length !== 1) {
1230
- throw new TypeError('arrayFormatSeparator must be single character string');
1231
- }
1232
- }
1549
+ var isNullOrUndefined = function isNullOrUndefined(value) {
1550
+ return value === null || value === undefined;
1551
+ };
1233
1552
 
1234
- function encode(value, options) {
1235
- if (options.encode) {
1236
- return options.strict ? strictUriEncode(value) : encodeURIComponent(value);
1237
- }
1553
+ function encoderForArrayFormat(options) {
1554
+ switch (options.arrayFormat) {
1555
+ case 'index':
1556
+ return function (key) {
1557
+ return function (result, value) {
1558
+ var index = result.length;
1238
1559
 
1239
- return value;
1240
- }
1560
+ if (value === undefined || options.skipNull && value === null || options.skipEmptyString && value === '') {
1561
+ return result;
1562
+ }
1241
1563
 
1242
- function decode(value, options) {
1243
- if (options.decode) {
1244
- return decodeUriComponent(value);
1245
- }
1564
+ if (value === null) {
1565
+ return [].concat(_toConsumableArray(result), [[encode(key, options), '[', index, ']'].join('')]);
1566
+ }
1246
1567
 
1247
- return value;
1248
- }
1568
+ return [].concat(_toConsumableArray(result), [[encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join('')]);
1569
+ };
1570
+ };
1249
1571
 
1250
- function keysSorter(input) {
1251
- if (Array.isArray(input)) {
1252
- return input.sort();
1253
- }
1572
+ case 'bracket':
1573
+ return function (key) {
1574
+ return function (result, value) {
1575
+ if (value === undefined || options.skipNull && value === null || options.skipEmptyString && value === '') {
1576
+ return result;
1577
+ }
1254
1578
 
1255
- if (typeof input === 'object') {
1256
- return keysSorter(Object.keys(input))
1257
- .sort((a, b) => Number(a) - Number(b))
1258
- .map(key => input[key]);
1259
- }
1579
+ if (value === null) {
1580
+ return [].concat(_toConsumableArray(result), [[encode(key, options), '[]'].join('')]);
1581
+ }
1260
1582
 
1261
- return input;
1262
- }
1583
+ return [].concat(_toConsumableArray(result), [[encode(key, options), '[]=', encode(value, options)].join('')]);
1584
+ };
1585
+ };
1263
1586
 
1264
- function removeHash(input) {
1265
- const hashStart = input.indexOf('#');
1266
- if (hashStart !== -1) {
1267
- input = input.slice(0, hashStart);
1268
- }
1587
+ case 'comma':
1588
+ case 'separator':
1589
+ return function (key) {
1590
+ return function (result, value) {
1591
+ if (value === null || value === undefined || value.length === 0) {
1592
+ return result;
1593
+ }
1269
1594
 
1270
- return input;
1271
- }
1595
+ if (result.length === 0) {
1596
+ return [[encode(key, options), '=', encode(value, options)].join('')];
1597
+ }
1272
1598
 
1273
- function getHash(url) {
1274
- let hash = '';
1275
- const hashStart = url.indexOf('#');
1276
- if (hashStart !== -1) {
1277
- hash = url.slice(hashStart);
1278
- }
1599
+ return [[result, encode(value, options)].join(options.arrayFormatSeparator)];
1600
+ };
1601
+ };
1279
1602
 
1280
- return hash;
1281
- }
1603
+ default:
1604
+ return function (key) {
1605
+ return function (result, value) {
1606
+ if (value === undefined || options.skipNull && value === null || options.skipEmptyString && value === '') {
1607
+ return result;
1608
+ }
1282
1609
 
1283
- function extract(input) {
1284
- input = removeHash(input);
1285
- const queryStart = input.indexOf('?');
1286
- if (queryStart === -1) {
1287
- return '';
1288
- }
1610
+ if (value === null) {
1611
+ return [].concat(_toConsumableArray(result), [encode(key, options)]);
1612
+ }
1289
1613
 
1290
- return input.slice(queryStart + 1);
1291
- }
1614
+ return [].concat(_toConsumableArray(result), [[encode(key, options), '=', encode(value, options)].join('')]);
1615
+ };
1616
+ };
1617
+ }
1618
+ }
1292
1619
 
1293
- function parseValue(value, options) {
1294
- if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
1295
- value = Number(value);
1296
- } else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
1297
- value = value.toLowerCase() === 'true';
1298
- }
1620
+ function parserForArrayFormat(options) {
1621
+ var result;
1299
1622
 
1300
- return value;
1301
- }
1623
+ switch (options.arrayFormat) {
1624
+ case 'index':
1625
+ return function (key, value, accumulator) {
1626
+ result = /\[(\d*)\]$/.exec(key);
1627
+ key = key.replace(/\[\d*\]$/, '');
1302
1628
 
1303
- function parse(query, options) {
1304
- options = Object.assign({
1305
- decode: true,
1306
- sort: true,
1307
- arrayFormat: 'none',
1308
- arrayFormatSeparator: ',',
1309
- parseNumbers: false,
1310
- parseBooleans: false
1311
- }, options);
1312
-
1313
- validateArrayFormatSeparator(options.arrayFormatSeparator);
1314
-
1315
- const formatter = parserForArrayFormat(options);
1316
-
1317
- // Create an object with no prototype
1318
- const ret = Object.create(null);
1319
-
1320
- if (typeof query !== 'string') {
1321
- return ret;
1322
- }
1323
-
1324
- query = query.trim().replace(/^[?#&]/, '');
1325
-
1326
- if (!query) {
1327
- return ret;
1328
- }
1329
-
1330
- for (const param of query.split('&')) {
1331
- if (param === '') {
1332
- continue;
1333
- }
1334
-
1335
- let [key, value] = splitOnFirst(options.decode ? param.replace(/\+/g, ' ') : param, '=');
1336
-
1337
- // Missing `=` should be `null`:
1338
- // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
1339
- value = value === undefined ? null : ['comma', 'separator'].includes(options.arrayFormat) ? value : decode(value, options);
1340
- formatter(decode(key, options), value, ret);
1341
- }
1342
-
1343
- for (const key of Object.keys(ret)) {
1344
- const value = ret[key];
1345
- if (typeof value === 'object' && value !== null) {
1346
- for (const k of Object.keys(value)) {
1347
- value[k] = parseValue(value[k], options);
1348
- }
1349
- } else {
1350
- ret[key] = parseValue(value, options);
1351
- }
1352
- }
1353
-
1354
- if (options.sort === false) {
1355
- return ret;
1356
- }
1357
-
1358
- return (options.sort === true ? Object.keys(ret).sort() : Object.keys(ret).sort(options.sort)).reduce((result, key) => {
1359
- const value = ret[key];
1360
- if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) {
1361
- // Sort object keys, not values
1362
- result[key] = keysSorter(value);
1363
- } else {
1364
- result[key] = value;
1365
- }
1366
-
1367
- return result;
1368
- }, Object.create(null));
1369
- }
1629
+ if (!result) {
1630
+ accumulator[key] = value;
1631
+ return;
1632
+ }
1370
1633
 
1371
- exports.extract = extract;
1372
- exports.parse = parse;
1634
+ if (accumulator[key] === undefined) {
1635
+ accumulator[key] = {};
1636
+ }
1373
1637
 
1374
- exports.stringify = (object, options) => {
1375
- if (!object) {
1376
- return '';
1377
- }
1638
+ accumulator[key][result[1]] = value;
1639
+ };
1378
1640
 
1379
- options = Object.assign({
1380
- encode: true,
1381
- strict: true,
1382
- arrayFormat: 'none',
1383
- arrayFormatSeparator: ','
1384
- }, options);
1641
+ case 'bracket':
1642
+ return function (key, value, accumulator) {
1643
+ result = /(\[\])$/.exec(key);
1644
+ key = key.replace(/\[\]$/, '');
1385
1645
 
1386
- validateArrayFormatSeparator(options.arrayFormatSeparator);
1646
+ if (!result) {
1647
+ accumulator[key] = value;
1648
+ return;
1649
+ }
1650
+
1651
+ if (accumulator[key] === undefined) {
1652
+ accumulator[key] = [value];
1653
+ return;
1654
+ }
1655
+
1656
+ accumulator[key] = [].concat(accumulator[key], value);
1657
+ };
1658
+
1659
+ case 'comma':
1660
+ case 'separator':
1661
+ return function (key, value, accumulator) {
1662
+ var isArray = typeof value === 'string' && value.includes(options.arrayFormatSeparator);
1663
+ var isEncodedArray = typeof value === 'string' && !isArray && decode(value, options).includes(options.arrayFormatSeparator);
1664
+ value = isEncodedArray ? decode(value, options) : value;
1665
+ var newValue = isArray || isEncodedArray ? value.split(options.arrayFormatSeparator).map(function (item) {
1666
+ return decode(item, options);
1667
+ }) : value === null ? value : decode(value, options);
1668
+ accumulator[key] = newValue;
1669
+ };
1670
+
1671
+ default:
1672
+ return function (key, value, accumulator) {
1673
+ if (accumulator[key] === undefined) {
1674
+ accumulator[key] = value;
1675
+ return;
1676
+ }
1387
1677
 
1388
- const shouldFilter = key => (
1389
- (options.skipNull && isNullOrUndefined(object[key])) ||
1390
- (options.skipEmptyString && object[key] === '')
1391
- );
1678
+ accumulator[key] = [].concat(accumulator[key], value);
1679
+ };
1680
+ }
1681
+ }
1392
1682
 
1393
- const formatter = encoderForArrayFormat(options);
1683
+ function validateArrayFormatSeparator(value) {
1684
+ if (typeof value !== 'string' || value.length !== 1) {
1685
+ throw new TypeError('arrayFormatSeparator must be single character string');
1686
+ }
1687
+ }
1394
1688
 
1395
- const objectCopy = {};
1689
+ function encode(value, options) {
1690
+ if (options.encode) {
1691
+ return options.strict ? strictUriEncode$1(value) : encodeURIComponent(value);
1692
+ }
1396
1693
 
1397
- for (const key of Object.keys(object)) {
1398
- if (!shouldFilter(key)) {
1399
- objectCopy[key] = object[key];
1400
- }
1401
- }
1694
+ return value;
1695
+ }
1402
1696
 
1403
- const keys = Object.keys(objectCopy);
1697
+ function decode(value, options) {
1698
+ if (options.decode) {
1699
+ return decodeComponent(value);
1700
+ }
1404
1701
 
1405
- if (options.sort !== false) {
1406
- keys.sort(options.sort);
1407
- }
1702
+ return value;
1703
+ }
1408
1704
 
1409
- return keys.map(key => {
1410
- const value = object[key];
1705
+ function keysSorter(input) {
1706
+ if (Array.isArray(input)) {
1707
+ return input.sort();
1708
+ }
1411
1709
 
1412
- if (value === undefined) {
1413
- return '';
1414
- }
1710
+ if (_typeof(input) === 'object') {
1711
+ return keysSorter(Object.keys(input)).sort(function (a, b) {
1712
+ return Number(a) - Number(b);
1713
+ }).map(function (key) {
1714
+ return input[key];
1715
+ });
1716
+ }
1415
1717
 
1416
- if (value === null) {
1417
- return encode(key, options);
1418
- }
1718
+ return input;
1719
+ }
1419
1720
 
1420
- if (Array.isArray(value)) {
1421
- return value
1422
- .reduce(formatter(key), [])
1423
- .join('&');
1424
- }
1721
+ function removeHash(input) {
1722
+ var hashStart = input.indexOf('#');
1425
1723
 
1426
- return encode(key, options) + '=' + encode(value, options);
1427
- }).filter(x => x.length > 0).join('&');
1428
- };
1724
+ if (hashStart !== -1) {
1725
+ input = input.slice(0, hashStart);
1726
+ }
1429
1727
 
1430
- exports.parseUrl = (url, options) => {
1431
- options = Object.assign({
1432
- decode: true
1433
- }, options);
1728
+ return input;
1729
+ }
1434
1730
 
1435
- const [url_, hash] = splitOnFirst(url, '#');
1731
+ function getHash(url) {
1732
+ var hash = '';
1733
+ var hashStart = url.indexOf('#');
1436
1734
 
1437
- return Object.assign(
1438
- {
1439
- url: url_.split('?')[0] || '',
1440
- query: parse(extract(url), options)
1441
- },
1442
- options && options.parseFragmentIdentifier && hash ? {fragmentIdentifier: decode(hash, options)} : {}
1443
- );
1444
- };
1735
+ if (hashStart !== -1) {
1736
+ hash = url.slice(hashStart);
1737
+ }
1445
1738
 
1446
- exports.stringifyUrl = (object, options) => {
1447
- options = Object.assign({
1448
- encode: true,
1449
- strict: true
1450
- }, options);
1739
+ return hash;
1740
+ }
1451
1741
 
1452
- const url = removeHash(object.url).split('?')[0] || '';
1453
- const queryFromUrl = exports.extract(object.url);
1454
- const parsedQueryFromUrl = exports.parse(queryFromUrl, {sort: false});
1742
+ function extract(input) {
1743
+ input = removeHash(input);
1744
+ var queryStart = input.indexOf('?');
1455
1745
 
1456
- const query = Object.assign(parsedQueryFromUrl, object.query);
1457
- let queryString = exports.stringify(query, options);
1458
- if (queryString) {
1459
- queryString = `?${queryString}`;
1460
- }
1746
+ if (queryStart === -1) {
1747
+ return '';
1748
+ }
1461
1749
 
1462
- let hash = getHash(object.url);
1463
- if (object.fragmentIdentifier) {
1464
- hash = `#${encode(object.fragmentIdentifier, options)}`;
1465
- }
1750
+ return input.slice(queryStart + 1);
1751
+ }
1466
1752
 
1467
- return `${url}${queryString}${hash}`;
1468
- };
1753
+ function parseValue(value, options) {
1754
+ if (options.parseNumbers && !Number.isNaN(Number(value)) && typeof value === 'string' && value.trim() !== '') {
1755
+ value = Number(value);
1756
+ } else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
1757
+ value = value.toLowerCase() === 'true';
1758
+ }
1469
1759
 
1470
- exports.pick = (input, filter, options) => {
1471
- options = Object.assign({
1472
- parseFragmentIdentifier: true
1473
- }, options);
1474
-
1475
- const {url, query, fragmentIdentifier} = exports.parseUrl(input, options);
1476
- return exports.stringifyUrl({
1477
- url,
1478
- query: filterObj(query, filter),
1479
- fragmentIdentifier
1480
- }, options);
1481
- };
1760
+ return value;
1761
+ }
1482
1762
 
1483
- exports.exclude = (input, filter, options) => {
1484
- const exclusionFilter = Array.isArray(filter) ? key => !filter.includes(key) : (key, value) => !filter(key, value);
1763
+ function parse(query, options) {
1764
+ options = Object.assign({
1765
+ decode: true,
1766
+ sort: true,
1767
+ arrayFormat: 'none',
1768
+ arrayFormatSeparator: ',',
1769
+ parseNumbers: false,
1770
+ parseBooleans: false
1771
+ }, options);
1772
+ validateArrayFormatSeparator(options.arrayFormatSeparator);
1773
+ var formatter = parserForArrayFormat(options); // Create an object with no prototype
1774
+
1775
+ var ret = Object.create(null);
1776
+
1777
+ if (typeof query !== 'string') {
1778
+ return ret;
1779
+ }
1485
1780
 
1486
- return exports.pick(input, exclusionFilter, options);
1487
- };
1488
- });
1489
- var queryString_1 = queryString.extract;
1490
- var queryString_2 = queryString.parse;
1491
- var queryString_3 = queryString.stringify;
1492
- var queryString_4 = queryString.parseUrl;
1493
- var queryString_5 = queryString.stringifyUrl;
1494
- var queryString_6 = queryString.pick;
1495
- var queryString_7 = queryString.exclude;
1496
-
1497
- function getSearch() {
1498
- let search = '?';
1499
- if (routerConfig.router.mode === 'hash') {
1500
- const idx = location.hash.indexOf('?');
1501
- if (idx > -1) {
1502
- search = location.hash.slice(idx);
1503
- }
1504
- }
1505
- else {
1506
- search = location.search;
1507
- }
1508
- return search.substr(1);
1509
- }
1510
- const qs = function (stamp = 0) {
1511
- const search = getSearch();
1512
- const query = search
1513
- ? queryString.parse(search)
1514
- : {};
1515
- if (stamp) {
1516
- query.stamp = stamp.toString();
1517
- }
1518
- return query;
1781
+ query = query.trim().replace(/^[?#&]/, '');
1782
+
1783
+ if (!query) {
1784
+ return ret;
1785
+ }
1786
+
1787
+ var _iterator = _createForOfIteratorHelper(query.split('&')),
1788
+ _step;
1789
+
1790
+ try {
1791
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1792
+ var param = _step.value;
1793
+
1794
+ if (param === '') {
1795
+ continue;
1796
+ }
1797
+
1798
+ var _splitOnFirst = splitOnFirst$1(options.decode ? param.replace(/\+/g, ' ') : param, '='),
1799
+ _splitOnFirst2 = _slicedToArray(_splitOnFirst, 2),
1800
+ _key = _splitOnFirst2[0],
1801
+ _value = _splitOnFirst2[1]; // Missing `=` should be `null`:
1802
+ // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
1803
+
1804
+
1805
+ _value = _value === undefined ? null : ['comma', 'separator'].includes(options.arrayFormat) ? _value : decode(_value, options);
1806
+ formatter(decode(_key, options), _value, ret);
1807
+ }
1808
+ } catch (err) {
1809
+ _iterator.e(err);
1810
+ } finally {
1811
+ _iterator.f();
1812
+ }
1813
+
1814
+ for (var _i = 0, _Object$keys = Object.keys(ret); _i < _Object$keys.length; _i++) {
1815
+ var key = _Object$keys[_i];
1816
+ var value = ret[key];
1817
+
1818
+ if (_typeof(value) === 'object' && value !== null) {
1819
+ for (var _i2 = 0, _Object$keys2 = Object.keys(value); _i2 < _Object$keys2.length; _i2++) {
1820
+ var k = _Object$keys2[_i2];
1821
+ value[k] = parseValue(value[k], options);
1822
+ }
1823
+ } else {
1824
+ ret[key] = parseValue(value, options);
1825
+ }
1826
+ }
1827
+
1828
+ if (options.sort === false) {
1829
+ return ret;
1830
+ }
1831
+
1832
+ return (options.sort === true ? Object.keys(ret).sort() : Object.keys(ret).sort(options.sort)).reduce(function (result, key) {
1833
+ var value = ret[key];
1834
+
1835
+ if (Boolean(value) && _typeof(value) === 'object' && !Array.isArray(value)) {
1836
+ // Sort object keys, not values
1837
+ result[key] = keysSorter(value);
1838
+ } else {
1839
+ result[key] = value;
1840
+ }
1841
+
1842
+ return result;
1843
+ }, Object.create(null));
1844
+ }
1845
+
1846
+ exports.extract = extract;
1847
+ exports.parse = parse;
1848
+
1849
+ exports.stringify = function (object, options) {
1850
+ if (!object) {
1851
+ return '';
1852
+ }
1853
+
1854
+ options = Object.assign({
1855
+ encode: true,
1856
+ strict: true,
1857
+ arrayFormat: 'none',
1858
+ arrayFormatSeparator: ','
1859
+ }, options);
1860
+ validateArrayFormatSeparator(options.arrayFormatSeparator);
1861
+
1862
+ var shouldFilter = function shouldFilter(key) {
1863
+ return options.skipNull && isNullOrUndefined(object[key]) || options.skipEmptyString && object[key] === '';
1864
+ };
1865
+
1866
+ var formatter = encoderForArrayFormat(options);
1867
+ var objectCopy = {};
1868
+
1869
+ for (var _i3 = 0, _Object$keys3 = Object.keys(object); _i3 < _Object$keys3.length; _i3++) {
1870
+ var key = _Object$keys3[_i3];
1871
+
1872
+ if (!shouldFilter(key)) {
1873
+ objectCopy[key] = object[key];
1874
+ }
1875
+ }
1876
+
1877
+ var keys = Object.keys(objectCopy);
1878
+
1879
+ if (options.sort !== false) {
1880
+ keys.sort(options.sort);
1881
+ }
1882
+
1883
+ return keys.map(function (key) {
1884
+ var value = object[key];
1885
+
1886
+ if (value === undefined) {
1887
+ return '';
1888
+ }
1889
+
1890
+ if (value === null) {
1891
+ return encode(key, options);
1892
+ }
1893
+
1894
+ if (Array.isArray(value)) {
1895
+ return value.reduce(formatter(key), []).join('&');
1896
+ }
1897
+
1898
+ return encode(key, options) + '=' + encode(value, options);
1899
+ }).filter(function (x) {
1900
+ return x.length > 0;
1901
+ }).join('&');
1902
+ };
1903
+
1904
+ exports.parseUrl = function (url, options) {
1905
+ options = Object.assign({
1906
+ decode: true
1907
+ }, options);
1908
+
1909
+ var _splitOnFirst3 = splitOnFirst$1(url, '#'),
1910
+ _splitOnFirst4 = _slicedToArray(_splitOnFirst3, 2),
1911
+ url_ = _splitOnFirst4[0],
1912
+ hash = _splitOnFirst4[1];
1913
+
1914
+ return Object.assign({
1915
+ url: url_.split('?')[0] || '',
1916
+ query: parse(extract(url), options)
1917
+ }, options && options.parseFragmentIdentifier && hash ? {
1918
+ fragmentIdentifier: decode(hash, options)
1919
+ } : {});
1920
+ };
1921
+
1922
+ exports.stringifyUrl = function (object, options) {
1923
+ options = Object.assign({
1924
+ encode: true,
1925
+ strict: true
1926
+ }, options);
1927
+ var url = removeHash(object.url).split('?')[0] || '';
1928
+ var queryFromUrl = exports.extract(object.url);
1929
+ var parsedQueryFromUrl = exports.parse(queryFromUrl, {
1930
+ sort: false
1931
+ });
1932
+ var query = Object.assign(parsedQueryFromUrl, object.query);
1933
+ var queryString = exports.stringify(query, options);
1934
+
1935
+ if (queryString) {
1936
+ queryString = "?".concat(queryString);
1937
+ }
1938
+
1939
+ var hash = getHash(object.url);
1940
+
1941
+ if (object.fragmentIdentifier) {
1942
+ hash = "#".concat(encode(object.fragmentIdentifier, options));
1943
+ }
1944
+
1945
+ return "".concat(url).concat(queryString).concat(hash);
1946
+ };
1947
+
1948
+ exports.pick = function (input, filter, options) {
1949
+ options = Object.assign({
1950
+ parseFragmentIdentifier: true
1951
+ }, options);
1952
+
1953
+ var _exports$parseUrl = exports.parseUrl(input, options),
1954
+ url = _exports$parseUrl.url,
1955
+ query = _exports$parseUrl.query,
1956
+ fragmentIdentifier = _exports$parseUrl.fragmentIdentifier;
1957
+
1958
+ return exports.stringifyUrl({
1959
+ url: url,
1960
+ query: filterObject(query, filter),
1961
+ fragmentIdentifier: fragmentIdentifier
1962
+ }, options);
1963
+ };
1964
+
1965
+ exports.exclude = function (input, filter, options) {
1966
+ var exclusionFilter = Array.isArray(filter) ? function (key) {
1967
+ return !filter.includes(key);
1968
+ } : function (key, value) {
1969
+ return !filter(key, value);
1970
+ };
1971
+ return exports.pick(input, exclusionFilter, options);
1972
+ };
1973
+ })(queryString);
1974
+
1975
+ function getSearch() {
1976
+ var search = '?';
1977
+
1978
+ if (routerConfig.router.mode === 'hash') {
1979
+ var idx = location.hash.indexOf('?');
1980
+
1981
+ if (idx > -1) {
1982
+ search = location.hash.slice(idx);
1983
+ }
1984
+ } else {
1985
+ search = location.search;
1986
+ }
1987
+
1988
+ return search.substr(1);
1989
+ }
1990
+
1991
+ var qs = function qs() {
1992
+ var stamp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1993
+ var search = getSearch();
1994
+ var query = search ? queryString.parse(search) : {};
1995
+
1996
+ if (stamp) {
1997
+ query.stamp = stamp.toString();
1998
+ }
1999
+
2000
+ return query;
1519
2001
  };
1520
2002
 
1521
- /* eslint-disable dot-notation */
1522
- function pageOnReady(page, onLoad = true) {
1523
- var _a;
1524
- const pageEl = document.getElementById(page.path);
1525
- if (pageEl && !(pageEl === null || pageEl === void 0 ? void 0 : pageEl['__isReady'])) {
1526
- const el = pageEl.firstElementChild;
1527
- (_a = el === null || el === void 0 ? void 0 : el['componentOnReady']) === null || _a === void 0 ? void 0 : _a.call(el).then(() => {
1528
- requestAnimationFrame(() => {
1529
- page.onReady();
1530
- pageEl['__isReady'] = true;
1531
- });
1532
- });
1533
- onLoad && (pageEl['__page'] = page);
1534
- }
1535
- }
1536
- function loadPage(page, pageConfig = {}, stacksIndex = 0) {
1537
- if (!page)
1538
- return;
1539
- const pageEl = document.getElementById(page.path);
1540
- if (pageEl) {
1541
- pageEl.style.display = 'block';
1542
- }
1543
- else {
1544
- page.onLoad(qs(stacksIndex), () => pageOnReady(page, true));
1545
- }
1546
- stacks.push(page);
1547
- page.onShow();
1548
- bindPageScroll(page, pageConfig);
1549
- }
1550
- function unloadPage(page, delta = 1) {
1551
- if (!page)
1552
- return;
1553
- stacks.delta = --delta;
1554
- stacks.pop();
1555
- page.onUnload();
1556
- if (delta >= 1)
1557
- unloadPage(stacks.last, delta);
1558
- }
1559
- function showPage(page, pageConfig = {}, stacksIndex = 0) {
1560
- if (!page)
1561
- return;
1562
- page.onShow();
1563
- const pageEl = document.getElementById(page.path);
1564
- if (pageEl) {
1565
- pageEl.style.display = 'block';
1566
- }
1567
- else {
1568
- page.onLoad(qs(stacksIndex), () => pageOnReady(page, false));
1569
- }
1570
- bindPageScroll(page, pageConfig);
1571
- }
1572
- function hidePage(page) {
1573
- if (!page)
1574
- return;
1575
- // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
1576
- const pageEl = document.getElementById(page.path);
1577
- if (pageEl) {
1578
- pageEl.style.display = 'none';
1579
- page.onHide();
1580
- }
1581
- else {
1582
- setTimeout(() => hidePage(page), 0);
1583
- }
2003
+ /* eslint-disable dot-notation */
2004
+ function pageOnReady(page) {
2005
+ var onLoad = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
2006
+ var pageEl = document.getElementById(page.path);
2007
+
2008
+ if (pageEl && !(pageEl !== null && pageEl !== void 0 && pageEl['__isReady'])) {
2009
+ var _el$componentOnReady;
2010
+
2011
+ var el = pageEl.firstElementChild;
2012
+ el === null || el === void 0 ? void 0 : (_el$componentOnReady = el['componentOnReady']) === null || _el$componentOnReady === void 0 ? void 0 : _el$componentOnReady.call(el).then(function () {
2013
+ requestAnimationFrame(function () {
2014
+ page.onReady();
2015
+ pageEl['__isReady'] = true;
2016
+ });
2017
+ });
2018
+ onLoad && (pageEl['__page'] = page);
2019
+ }
2020
+ }
2021
+ function loadPage(page) {
2022
+ var pageConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2023
+ var stacksIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
2024
+ if (!page) return;
2025
+ var pageEl = document.getElementById(page.path);
2026
+
2027
+ if (pageEl) {
2028
+ pageEl.style.display = 'block';
2029
+ } else {
2030
+ page.onLoad(qs(stacksIndex), function () {
2031
+ return pageOnReady(page, true);
2032
+ });
2033
+ }
2034
+
2035
+ stacks.push(page);
2036
+ page.onShow();
2037
+ bindPageScroll(page, pageConfig);
2038
+ }
2039
+ function unloadPage(page) {
2040
+ var delta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
2041
+ if (!page) return;
2042
+ stacks.delta = --delta;
2043
+ stacks.pop();
2044
+ page.onUnload();
2045
+ if (delta >= 1) unloadPage(stacks.last, delta);
2046
+ }
2047
+ function showPage(page) {
2048
+ var pageConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2049
+ var stacksIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
2050
+ if (!page) return;
2051
+ page.onShow();
2052
+ var pageEl = document.getElementById(page.path);
2053
+
2054
+ if (pageEl) {
2055
+ pageEl.style.display = 'block';
2056
+ } else {
2057
+ page.onLoad(qs(stacksIndex), function () {
2058
+ return pageOnReady(page, false);
2059
+ });
2060
+ }
2061
+
2062
+ bindPageScroll(page, pageConfig);
1584
2063
  }
2064
+ function hidePage(page) {
2065
+ if (!page) return; // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
2066
+
2067
+ var pageEl = document.getElementById(page.path);
2068
+
2069
+ if (pageEl) {
2070
+ pageEl.style.display = 'none';
2071
+ page.onHide();
2072
+ } else {
2073
+ setTimeout(function () {
2074
+ return hidePage(page);
2075
+ }, 0);
2076
+ }
2077
+ }
2078
+
2079
+ function createRouter(app, config, framework) {
2080
+ var _config$router$custom;
2081
+
2082
+ init(config);
2083
+ var routes = [];
2084
+ var alias = (_config$router$custom = config.router.customRoutes) !== null && _config$router$custom !== void 0 ? _config$router$custom : {};
2085
+ var runtimeHooks = container.get(SERVICE_IDENTIFIER.Hooks);
2086
+ setRoutesAlias(alias);
2087
+
2088
+ for (var i = 0; i < config.routes.length; i++) {
2089
+ var route = config.routes[i];
2090
+ var path = addLeadingSlash(route.path);
2091
+ routes.push({
2092
+ path: alias[path] || path,
2093
+ action: route.load
2094
+ });
2095
+ }
2096
+
2097
+ var basename = config.router.basename;
2098
+ var router = new UniversalRouter(routes, {
2099
+ baseUrl: basename || ''
2100
+ });
2101
+ app.onLaunch();
2102
+
2103
+ var render = /*#__PURE__*/function () {
2104
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
2105
+ var location, action, element, _app$onPageNotFound, pageConfig, enablePullDownRefresh, _pageConfig$navigatio, currentPage, pathname, shouldLoad, prevIndex, delta, _prevIndex, _element$default, _runtimeHooks$createP, el, loadConfig, stacksIndex, page;
2106
+
2107
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
2108
+ while (1) {
2109
+ switch (_context.prev = _context.next) {
2110
+ case 0:
2111
+ location = _ref.location, action = _ref.action;
2112
+ routerConfig.router.pathname = location.pathname;
2113
+ _context.prev = 2;
2114
+ _context.next = 5;
2115
+ return router.resolve(config.router.forcePath || location.pathname);
2116
+
2117
+ case 5:
2118
+ element = _context.sent;
2119
+ _context.next = 15;
2120
+ break;
2121
+
2122
+ case 8:
2123
+ _context.prev = 8;
2124
+ _context.t0 = _context["catch"](2);
2125
+
2126
+ if (!(_context.t0.status === 404)) {
2127
+ _context.next = 14;
2128
+ break;
2129
+ }
2130
+
2131
+ (_app$onPageNotFound = app.onPageNotFound) === null || _app$onPageNotFound === void 0 ? void 0 : _app$onPageNotFound.call(app, {
2132
+ path: location.pathname
2133
+ });
2134
+ _context.next = 15;
2135
+ break;
2136
+
2137
+ case 14:
2138
+ throw new Error(_context.t0);
2139
+
2140
+ case 15:
2141
+ if (element) {
2142
+ _context.next = 17;
2143
+ break;
2144
+ }
2145
+
2146
+ return _context.abrupt("return");
2147
+
2148
+ case 17:
2149
+ pageConfig = config.routes.find(function (r) {
2150
+ var path = addLeadingSlash(r.path);
2151
+ return path === location.pathname || alias[path] === location.pathname;
2152
+ });
2153
+ enablePullDownRefresh = false;
2154
+ eventCenter.trigger('__taroRouterChange', {
2155
+ toLocation: {
2156
+ path: location.pathname
2157
+ }
2158
+ });
2159
+
2160
+ if (pageConfig) {
2161
+ document.title = (_pageConfig$navigatio = pageConfig.navigationBarTitleText) !== null && _pageConfig$navigatio !== void 0 ? _pageConfig$navigatio : document.title;
2162
+ enablePullDownRefresh = pageConfig.enablePullDownRefresh;
2163
+ }
2164
+
2165
+ currentPage = Current.page;
2166
+ pathname = location.pathname;
2167
+ shouldLoad = false;
2168
+
2169
+ if (!(action === 'POP')) {
2170
+ _context.next = 31;
2171
+ break;
2172
+ }
2173
+
2174
+ // NOTE: 浏览器事件退后多次时,该事件只会被触发一次
2175
+ prevIndex = stacks.getPrevIndex(pathname);
2176
+ delta = stacks.getDelta(pathname);
2177
+ unloadPage(currentPage, delta);
2178
+
2179
+ if (prevIndex > -1) {
2180
+ showPage(stacks.getItem(prevIndex), pageConfig, prevIndex);
2181
+ } else {
2182
+ shouldLoad = true;
2183
+ }
2184
+
2185
+ _context.next = 46;
2186
+ break;
2187
+
2188
+ case 31:
2189
+ if (!(action === 'PUSH')) {
2190
+ _context.next = 36;
2191
+ break;
2192
+ }
2193
+
2194
+ hidePage(currentPage);
2195
+ shouldLoad = true;
2196
+ _context.next = 46;
2197
+ break;
2198
+
2199
+ case 36:
2200
+ if (!(action === 'REPLACE')) {
2201
+ _context.next = 46;
2202
+ break;
2203
+ }
2204
+
2205
+ if (!isTabBar(config)) {
2206
+ _context.next = 44;
2207
+ break;
2208
+ }
2209
+
2210
+ hidePage(currentPage);
2211
+ _prevIndex = stacks.getPrevIndex(pathname);
2212
+
2213
+ if (!(_prevIndex > -1)) {
2214
+ _context.next = 42;
2215
+ break;
2216
+ }
2217
+
2218
+ return _context.abrupt("return", showPage(stacks.getItem(_prevIndex), pageConfig, _prevIndex));
2219
+
2220
+ case 42:
2221
+ _context.next = 45;
2222
+ break;
2223
+
2224
+ case 44:
2225
+ unloadPage(currentPage);
2226
+
2227
+ case 45:
2228
+ shouldLoad = true;
2229
+
2230
+ case 46:
2231
+ if (!shouldLoad) {
2232
+ _context.next = 54;
2233
+ break;
2234
+ }
2235
+
2236
+ el = (_element$default = element.default) !== null && _element$default !== void 0 ? _element$default : element;
2237
+ loadConfig = _objectSpread({}, pageConfig);
2238
+ stacksIndex = stacks.length;
2239
+ delete loadConfig['path'];
2240
+ delete loadConfig['load'];
2241
+ page = createPageConfig(enablePullDownRefresh ? (_runtimeHooks$createP = runtimeHooks.createPullDownComponent) === null || _runtimeHooks$createP === void 0 ? void 0 : _runtimeHooks$createP.call(runtimeHooks, el, location.pathname, framework, routerConfig.PullDownRefresh) : el, pathname + stringify(qs(stacksIndex)), {}, loadConfig);
2242
+ return _context.abrupt("return", loadPage(page, pageConfig, stacksIndex));
2243
+
2244
+ case 54:
2245
+ case "end":
2246
+ return _context.stop();
2247
+ }
2248
+ }
2249
+ }, _callee, null, [[2, 8]]);
2250
+ }));
2251
+
2252
+ return function render(_x) {
2253
+ return _ref2.apply(this, arguments);
2254
+ };
2255
+ }();
2256
+
2257
+ if (history.location.pathname === '/') {
2258
+ history.replace(prependBasename(routes[0].path + history.location.search));
2259
+ }
1585
2260
 
1586
- /* eslint-disable dot-notation */
1587
- function createRouter(app, config, framework) {
1588
- var _a;
1589
- init(config);
1590
- const routes = [];
1591
- const alias = (_a = config.router.customRoutes) !== null && _a !== void 0 ? _a : {};
1592
- const runtimeHooks = container.get(SERVICE_IDENTIFIER.Hooks);
1593
- setRoutesAlias(alias);
1594
- for (let i = 0; i < config.routes.length; i++) {
1595
- const route = config.routes[i];
1596
- const path = addLeadingSlash(route.path);
1597
- routes.push({
1598
- path: alias[path] || path,
1599
- action: route.load
1600
- });
1601
- }
1602
- const basename = config.router.basename;
1603
- const router = new UniversalRouter(routes, { baseUrl: basename || '' });
1604
- app.onLaunch();
1605
- const render = async ({ location, action }) => {
1606
- var _a, _b, _c, _d;
1607
- routerConfig.router.pathname = location.pathname;
1608
- let element;
1609
- try {
1610
- element = await router.resolve(config.router.forcePath || location.pathname);
1611
- }
1612
- catch (error) {
1613
- if (error.status === 404) {
1614
- (_a = app.onPageNotFound) === null || _a === void 0 ? void 0 : _a.call(app, {
1615
- path: location.pathname
1616
- });
1617
- }
1618
- else {
1619
- throw new Error(error);
1620
- }
1621
- }
1622
- if (!element)
1623
- return;
1624
- const pageConfig = config.routes.find(r => {
1625
- const path = addLeadingSlash(r.path);
1626
- return path === location.pathname || alias[path] === location.pathname;
1627
- });
1628
- let enablePullDownRefresh = false;
1629
- eventCenter.trigger('__taroRouterChange', {
1630
- toLocation: {
1631
- path: location.pathname
1632
- }
1633
- });
1634
- if (pageConfig) {
1635
- document.title = (_b = pageConfig.navigationBarTitleText) !== null && _b !== void 0 ? _b : document.title;
1636
- enablePullDownRefresh = pageConfig.enablePullDownRefresh;
1637
- }
1638
- const currentPage = Current.page;
1639
- const pathname = location.pathname;
1640
- let shouldLoad = false;
1641
- if (action === 'POP') {
1642
- // NOTE: 浏览器事件退后多次时,该事件只会被触发一次
1643
- const prevIndex = stacks.getPrevIndex(pathname);
1644
- const delta = stacks.getDelta(pathname);
1645
- unloadPage(currentPage, delta);
1646
- if (prevIndex > -1) {
1647
- showPage(stacks.getItem(prevIndex), pageConfig, prevIndex);
1648
- }
1649
- else {
1650
- shouldLoad = true;
1651
- }
1652
- }
1653
- else if (action === 'PUSH') {
1654
- hidePage(currentPage);
1655
- shouldLoad = true;
1656
- }
1657
- else if (action === 'REPLACE') {
1658
- if (isTabBar(config)) {
1659
- hidePage(currentPage);
1660
- const prevIndex = stacks.getPrevIndex(pathname);
1661
- if (prevIndex > -1) {
1662
- // NOTE: tabbar 页且之前出现过,直接复用
1663
- return showPage(stacks.getItem(prevIndex), pageConfig, prevIndex);
1664
- }
1665
- }
1666
- else {
1667
- unloadPage(currentPage);
1668
- }
1669
- shouldLoad = true;
1670
- }
1671
- if (shouldLoad) {
1672
- const el = (_c = element.default) !== null && _c !== void 0 ? _c : element;
1673
- const loadConfig = Object.assign({}, pageConfig);
1674
- const stacksIndex = stacks.length;
1675
- delete loadConfig['path'];
1676
- delete loadConfig['load'];
1677
- const page = createPageConfig(enablePullDownRefresh ? (_d = runtimeHooks.createPullDownComponent) === null || _d === void 0 ? void 0 : _d.call(runtimeHooks, el, location.pathname, framework, routerConfig.PullDownRefresh) : el, pathname + stringify(qs(stacksIndex)), {}, loadConfig);
1678
- return loadPage(page, pageConfig, stacksIndex);
1679
- }
1680
- };
1681
- if (history.location.pathname === '/') {
1682
- history.replace(prependBasename(routes[0].path + history.location.search));
1683
- }
1684
- render({ location: history.location, action: r.Push });
1685
- app.onShow(qs(stacks.length));
1686
- return history.listen(render);
2261
+ render({
2262
+ location: history.location,
2263
+ action: r.Push
2264
+ });
2265
+ app.onShow(qs(stacks.length));
2266
+ return history.listen(render);
1687
2267
  }
1688
2268
 
1689
2269
  export { createRouter, getCurrentPages, history, navigateBack, navigateTo, reLaunch, redirectTo, switchTab };