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