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