@tarojs/router 3.3.17 → 3.4.0-beta.2

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