@tarojs/router 3.3.16 → 3.4.0-beta.1

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,264 +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');
17
+ var taro = require('@tarojs/taro');
18
+
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
+ };
6
43
 
7
- function _extends() {
8
- _extends = Object.assign || function (target) {
9
- var arguments$1 = arguments;
44
+ function D(b, h) {
45
+ if (!b) {
46
+ "undefined" !== typeof console && console.warn(h);
10
47
 
11
- for (var i = 1; i < arguments.length; i++) {
12
- var source = arguments$1[i];
48
+ try {
49
+ throw Error(h);
50
+ } catch (k) {}
51
+ }
52
+ }
13
53
 
14
- for (var key in source) {
15
- if (Object.prototype.hasOwnProperty.call(source, key)) {
16
- target[key] = source[key];
17
- }
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);
18
172
  }
173
+
174
+ z(l);
175
+ }
176
+ }
177
+
178
+ function y(c, a) {
179
+ function e() {
180
+ y(c, a);
19
181
  }
20
182
 
21
- return target;
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
+ }
199
+
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
+ }
22
264
  };
265
+ }
23
266
 
24
- return _extends.apply(this, arguments);
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
+ }
338
+
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
+ };
25
439
  }
26
440
 
27
- var r,B=r||(r={});B.Pop="POP";B.Push="PUSH";B.Replace="REPLACE";var C="production"!==process.env.NODE_ENV?function(b){return Object.freeze(b)}:function(b){return b};function D(b,h){if(!b){"undefined"!==typeof console&&console.warn(h);try{throw Error(h);}catch(k){}}}function E(b){b.preventDefault();b.returnValue="";}
28
- function F(){var b=[];return {get length(){return b.length},push:function(h){b.push(h);return function(){b=b.filter(function(k){return k!==h});}},call:function(h){b.forEach(function(k){return k&&k(h)});}}}function H(){return Math.random().toString(36).substr(2,8)}function I(b){var h=b.pathname,k=b.search;b=b.hash;return (void 0===h?"/":h)+(void 0===k?"":k)+(void 0===b?"":b)}
29
- function J(b){var h={};if(b){var k=b.indexOf("#");0<=k&&(h.hash=b.substr(k),b=b.substr(0,k));k=b.indexOf("?");0<=k&&(h.search=b.substr(k),b=b.substr(0,k));b&&(h.pathname=b);}return h}
30
- function createBrowserHistory(b){function h(){var c=p.location,a=m.state||{};return [a.idx,C({pathname:c.pathname,search:c.search,hash:c.hash,state:a.usr||null,key:a.key||"default"})]}function k(c){return "string"===typeof c?c:I(c)}function x(c,a){void 0===a&&(a=null);return C(_extends({pathname:q.pathname,hash:"",search:""},"string"===typeof c?J(c):c,{state:a,key:H()}))}function z(c){t=c;c=h();v=c[0];q=c[1];d.call({action:t,location:q});}function A(c,a){function e(){A(c,a);}var l=r.Push,g=x(c,
31
- a);if(!f.length||(f.call({action:l,location:g,retry:e}),!1)){var n=[{usr:g.state,key:g.key,idx:v+1},k(g)];g=n[0];n=n[1];try{m.pushState(g,"",n);}catch(G){p.location.assign(n);}z(l);}}function y(c,a){function e(){y(c,a);}var l=r.Replace,g=x(c,a);f.length&&(f.call({action:l,location:g,retry:e}),1)||(g=[{usr:g.state,key:g.key,idx:v},k(g)],m.replaceState(g[0],"",g[1]),z(l));}function w(c){m.go(c);}void 0===b&&(b={});b=b.window;var p=void 0===b?document.defaultView:b,m=p.history,u=null;p.addEventListener("popstate",
32
- function(){if(u){ f.call(u),u=null; }else {var c=r.Pop,a=h(),e=a[0];a=a[1];if(f.length){ if(null!=e){var l=v-e;l&&(u={action:c,location:a,retry:function(){w(-1*l);}},w(l));}else { "production"!==process.env.NODE_ENV?D(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."):
33
- void 0; } }else { z(c); }}});var t=r.Pop;b=h();var v=b[0],q=b[1],d=F(),f=F();null==v&&(v=0,m.replaceState(_extends({},m.state,{idx:v}),""));return {get action(){return t},get location(){return q},createHref:k,push:A,replace:y,go:w,back:function(){w(-1);},forward:function(){w(1);},listen:function(c){return d.push(c)},block:function(c){var a=f.push(c);1===f.length&&p.addEventListener("beforeunload",E);return function(){a();f.length||p.removeEventListener("beforeunload",E);}}}}function createHashHistory(b){function h(){var a=J(m.location.hash.substr(1)),e=a.pathname,l=a.search;a=a.hash;var g=u.state||{};return [g.idx,C({pathname:void 0===e?"/":e,search:void 0===l?"":l,hash:void 0===a?"":a,state:g.usr||null,key:g.key||"default"})]}function k(){if(t){ c.call(t),t=null; }else {var a=r.Pop,e=h(),l=e[0];e=e[1];if(c.length){ if(null!=l){var g=q-l;g&&(t={action:a,location:e,retry:function(){p(-1*g);}},p(g));}else { "production"!==process.env.NODE_ENV?D(!1,"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."):
34
- void 0; } }else { A(a); }}}function x(a){var e=document.querySelector("base"),l="";e&&e.getAttribute("href")&&(e=m.location.href,l=e.indexOf("#"),l=-1===l?e:e.slice(0,l));return l+"#"+("string"===typeof a?a:I(a))}function z(a,e){void 0===e&&(e=null);return C(_extends({pathname:d.pathname,hash:"",search:""},"string"===typeof a?J(a):a,{state:e,key:H()}))}function A(a){v=a;a=h();q=a[0];d=a[1];f.call({action:v,location:d});}function y(a,e){function l(){y(a,e);}var g=r.Push,n=z(a,e);"production"!==process.env.NODE_ENV?
35
- D("/"===n.pathname.charAt(0),"Relative pathnames are not supported in hash history.push("+JSON.stringify(a)+")"):void 0;if(!c.length||(c.call({action:g,location:n,retry:l}),!1)){var G=[{usr:n.state,key:n.key,idx:q+1},x(n)];n=G[0];G=G[1];try{u.pushState(n,"",G);}catch(K){m.location.assign(G);}A(g);}}function w(a,e){function l(){w(a,e);}var g=r.Replace,n=z(a,e);"production"!==process.env.NODE_ENV?D("/"===n.pathname.charAt(0),"Relative pathnames are not supported in hash history.replace("+JSON.stringify(a)+
36
- ")"):void 0;c.length&&(c.call({action:g,location:n,retry:l}),1)||(n=[{usr:n.state,key:n.key,idx:q},x(n)],u.replaceState(n[0],"",n[1]),A(g));}function p(a){u.go(a);}void 0===b&&(b={});b=b.window;var m=void 0===b?document.defaultView:b,u=m.history,t=null;m.addEventListener("popstate",k);m.addEventListener("hashchange",function(){var a=h()[1];I(a)!==I(d)&&k();});var v=r.Pop;b=h();var q=b[0],d=b[1],f=F(),c=F();null==q&&(q=0,u.replaceState(_extends({},u.state,{idx:q}),""));return {get action(){return v},get location(){return d},
37
- createHref:x,push:y,replace:w,go:p,back:function(){p(-1);},forward:function(){p(1);},listen:function(a){return f.push(a)},block:function(a){var e=c.push(a);1===c.length&&m.addEventListener("beforeunload",E);return function(){e();c.length||m.removeEventListener("beforeunload",E);}}}}
38
-
39
- var basename = '/';
40
- function setHistoryMode(mode, base) {
41
- if ( base === void 0 ) base = '/';
42
-
43
- var options = {
44
- window: window
45
- };
46
- basename = base;
47
- if (mode === 'browser') {
48
- exports.history = createBrowserHistory(options);
49
- }
50
- else {
51
- // default is hash
52
- exports.history = createHashHistory(options);
53
- }
54
- }
55
- function prependBasename(url) {
56
- if ( url === void 0 ) url = '';
57
-
58
- return basename.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
59
- }
60
- var hasBasename = function (path, prefix) { return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path); };
61
- var stripBasename = function (path, prefix) { return hasBasename(path, prefix) ? path.substr(prefix.length) : path; };
62
-
63
- var Stacks = function Stacks() {
64
- this.stacks = [];
65
- this.backDelta = 0;
66
- };
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;
67
449
 
68
- var prototypeAccessors = { delta: { configurable: true },length: { configurable: true },last: { configurable: true } };
69
- prototypeAccessors.delta.set = function (delta) {
70
- if (delta > 0) {
71
- this.backDelta = delta;
72
- }
73
- else {
74
- --this.backDelta;
75
- }
76
- };
77
- prototypeAccessors.length.get = function () {
78
- return this.stacks.length;
79
- };
80
- prototypeAccessors.last.get = function () {
81
- return this.stacks[this.length - 1];
82
- };
83
- Stacks.prototype.get = function get () {
84
- return this.stacks;
85
- };
86
- Stacks.prototype.getItem = function getItem (index) {
87
- return this.stacks[index];
88
- };
89
- Stacks.prototype.getLastIndex = function getLastIndex (pathname) {
90
- var list = [].concat( this.stacks ).reverse();
91
- return list.findIndex(function (page) { var _a; return ((_a = page.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) === pathname; });
92
- };
93
- Stacks.prototype.getDelta = function getDelta (pathname) {
94
- if (this.backDelta >= 1) {
95
- return this.backDelta;
96
- }
97
- // NOTE: 此处为了修复浏览器后退多级页面,在大量重复路由状况下可能出现判断错误的情况 (增强判断能力只能考虑在 query 中新增参数来判断,暂时搁置)
98
- return this.getLastIndex(pathname) || 1;
99
- };
100
- Stacks.prototype.getPrevIndex = function getPrevIndex (pathname) {
101
- var lastIndex = this.getLastIndex(pathname);
102
- if (lastIndex < 0) {
103
- return -1;
104
- }
105
- return this.length - 1 - lastIndex;
106
- };
107
- Stacks.prototype.pop = function pop () {
108
- return this.stacks.pop();
109
- };
110
- Stacks.prototype.push = function push (page) {
111
- 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);
112
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;
470
+ };
471
+
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
+ }();
113
559
 
114
- Object.defineProperties( Stacks.prototype, prototypeAccessors );
115
560
  var stacks = new Stacks();
116
561
 
117
- var routesAlias = {};
118
- function setRoutesAlias(alias) {
119
- routesAlias = alias;
120
- }
121
- function addLeadingSlash(path) {
122
- if (path == null) {
123
- return '';
124
- }
125
- return path.charAt(0) === '/' ? path : '/' + path;
126
- }
127
- var isTabBar = function (config) {
128
- var _a, _b;
129
- var ref = config.router;
130
- var customRoutes = ref.customRoutes; if ( customRoutes === void 0 ) customRoutes = {};
131
- var basename = ref.basename; if ( basename === void 0 ) basename = '';
132
- var pathname = ref.pathname;
133
- var routePath = stripBasename(pathname, basename);
134
- var pagePath = ((_a = Object.entries(customRoutes).find(function (ref) {
135
- var target = ref[1];
136
-
137
- return target === routePath;
138
- })) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
139
- return !!pagePath && (((_b = config.tabBar) === null || _b === void 0 ? void 0 : _b.list) || []).some(function (t) { return t.pagePath === pagePath; });
140
- };
562
+ function addLeadingSlash(path) {
563
+ if (path == null) {
564
+ return '';
565
+ }
141
566
 
142
- function processNavigateUrl(option) {
143
- var _a;
144
- var pathPieces = J(option.url);
145
- // 处理自定义路由
146
- Object.keys(routesAlias).forEach(function (key) {
147
- if (addLeadingSlash(key) === addLeadingSlash(pathPieces.pathname)) {
148
- pathPieces.pathname = routesAlias[key];
149
- }
150
- });
151
- // 处理相对路径
152
- if ((_a = pathPieces === null || pathPieces === void 0 ? void 0 : pathPieces.pathname) === null || _a === void 0 ? void 0 : _a.includes('./')) {
153
- var parts = exports.history.location.pathname.split('/');
154
- parts.pop();
155
- pathPieces.pathname.split('/').forEach(function (item) {
156
- if (item === '.') {
157
- return;
158
- }
159
- item === '..' ? parts.pop() : parts.push(item);
160
- });
161
- pathPieces.pathname = parts.join('/');
162
- }
163
- // 处理 basename
164
- pathPieces.pathname = prependBasename(pathPieces.pathname);
165
- // hack fix history v5 bug: https://github.com/remix-run/history/issues/814
166
- if (!pathPieces.search)
167
- { pathPieces.search = ''; }
168
- return pathPieces;
169
- }
170
- async function navigate(option, method) {
171
- return new Promise(function (resolve, reject) {
172
- var success = option.success;
173
- var complete = option.complete;
174
- var fail = option.fail;
175
- var unListen = exports.history.listen(function () {
176
- success === null || success === void 0 ? void 0 : success();
177
- complete === null || complete === void 0 ? void 0 : complete();
178
- resolve();
179
- unListen();
180
- });
181
- try {
182
- if ('url' in option) {
183
- var pathPieces = processNavigateUrl(option);
184
- var state = { timestamp: Date.now() };
185
- if (method === 'navigateTo') {
186
- exports.history.push(pathPieces, state);
187
- }
188
- else if (method === 'redirectTo') {
189
- exports.history.replace(pathPieces, state);
190
- }
191
- }
192
- else if (method === 'navigateBack') {
193
- stacks.delta = option.delta;
194
- exports.history.go(-option.delta);
195
- }
196
- }
197
- catch (error) {
198
- fail === null || fail === void 0 ? void 0 : fail(error);
199
- complete === null || complete === void 0 ? void 0 : complete();
200
- reject(error);
201
- }
202
- });
203
- }
204
- function navigateTo(option) {
205
- return navigate(option, 'navigateTo');
206
- }
207
- function redirectTo(option) {
208
- return navigate(option, 'redirectTo');
209
- }
210
- function navigateBack(options) {
211
- if ( options === void 0 ) options = { delta: 1 };
212
-
213
- if (!options.delta || options.delta < 1) {
214
- options.delta = 1;
215
- }
216
- return navigate(options, 'navigateBack');
217
- }
218
- function switchTab(option) {
219
- // TODO: 清除掉所有的栈去目标页面
220
- return redirectTo(option);
221
- }
222
- function reLaunch(option) {
223
- // TODO: 清除掉所有的栈去目标页面
224
- return redirectTo(option);
225
- }
226
- function getCurrentPages() {
227
- return stacks.get();
567
+ return path.charAt(0) === '/' ? path : '/' + path;
228
568
  }
229
569
 
230
- /**
231
- * Expose `pathToRegexp`.
232
- */
233
- var pathToRegexp_1 = pathToRegexp;
234
- var match_1 = match;
235
- var regexpToFunction_1 = regexpToFunction;
236
- var parse_1 = parse;
237
- var compile_1 = compile;
238
- var tokensToFunction_1 = tokensToFunction;
239
- var tokensToRegExp_1 = tokensToRegExp;
570
+ var RoutesAlias = /*#__PURE__*/function () {
571
+ function RoutesAlias() {
572
+ var _this = this;
573
+
574
+ _classCallCheck__default['default'](this, RoutesAlias);
575
+
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
+ });
240
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;
673
+ }
674
+
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: {}};
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;
241
779
  /**
242
780
  * Default configs.
243
781
  */
244
- var DEFAULT_DELIMITER = '/';
245
782
 
783
+ var DEFAULT_DELIMITER = '/';
246
784
  /**
247
785
  * The main path matching regexp utility.
248
786
  *
249
787
  * @type {RegExp}
250
788
  */
251
- var PATH_REGEXP = new RegExp([
252
- // Match escaped characters that would otherwise appear in future matches.
253
- // This allows the user to escape special characters that won't transform.
254
- '(\\\\.)',
255
- // Match Express-style parameters and un-named parameters with a prefix
256
- // and optional suffixes. Matches appear as:
257
- //
258
- // ":test(\\d+)?" => ["test", "\d+", undefined, "?"]
259
- // "(\\d+)" => [undefined, undefined, "\d+", undefined]
260
- '(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?'
261
- ].join('|'), 'g');
262
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');
263
798
  /**
264
799
  * Parse a string for the raw tokens.
265
800
  *
@@ -267,13 +802,14 @@ var PATH_REGEXP = new RegExp([
267
802
  * @param {Object=} options
268
803
  * @return {!Array}
269
804
  */
270
- function parse (str, options) {
805
+
806
+ function parse(str, options) {
271
807
  var tokens = [];
272
808
  var key = 0;
273
809
  var index = 0;
274
810
  var path = '';
275
- var defaultDelimiter = (options && options.delimiter) || DEFAULT_DELIMITER;
276
- var whitelist = (options && options.whitelist) || undefined;
811
+ var defaultDelimiter = options && options.delimiter || DEFAULT_DELIMITER;
812
+ var whitelist = options && options.whitelist || undefined;
277
813
  var pathEscaped = false;
278
814
  var res;
279
815
 
@@ -282,13 +818,12 @@ function parse (str, options) {
282
818
  var escaped = res[1];
283
819
  var offset = res.index;
284
820
  path += str.slice(index, offset);
285
- index = offset + m.length;
821
+ index = offset + m.length; // Ignore already escaped sequences.
286
822
 
287
- // Ignore already escaped sequences.
288
823
  if (escaped) {
289
824
  path += escaped[1];
290
825
  pathEscaped = true;
291
- continue
826
+ continue;
292
827
  }
293
828
 
294
829
  var prev = '';
@@ -306,9 +841,9 @@ function parse (str, options) {
306
841
  prev = c;
307
842
  path = path.slice(0, k);
308
843
  }
309
- }
844
+ } // Push the current path onto the tokens.
845
+
310
846
 
311
- // Push the current path onto the tokens.
312
847
  if (path) {
313
848
  tokens.push(path);
314
849
  path = '';
@@ -319,27 +854,23 @@ function parse (str, options) {
319
854
  var optional = modifier === '?' || modifier === '*';
320
855
  var pattern = capture || group;
321
856
  var delimiter = prev || defaultDelimiter;
322
-
323
857
  tokens.push({
324
858
  name: name || key++,
325
859
  prefix: prev,
326
860
  delimiter: delimiter,
327
861
  optional: optional,
328
862
  repeat: repeat,
329
- pattern: pattern
330
- ? escapeGroup(pattern)
331
- : '[^' + escapeString(delimiter === defaultDelimiter ? delimiter : (delimiter + defaultDelimiter)) + ']+?'
863
+ pattern: pattern ? escapeGroup(pattern) : '[^' + escapeString(delimiter === defaultDelimiter ? delimiter : delimiter + defaultDelimiter) + ']+?'
332
864
  });
333
- }
865
+ } // Push any remaining characters.
866
+
334
867
 
335
- // Push any remaining characters.
336
868
  if (path || index < str.length) {
337
869
  tokens.push(path + str.substr(index));
338
870
  }
339
871
 
340
- return tokens
872
+ return tokens;
341
873
  }
342
-
343
874
  /**
344
875
  * Compile a string to a template function for the path.
345
876
  *
@@ -347,67 +878,73 @@ function parse (str, options) {
347
878
  * @param {Object=} options
348
879
  * @return {!function(Object=, Object=)}
349
880
  */
350
- function compile (str, options) {
351
- return tokensToFunction(parse(str, options), options)
352
- }
353
881
 
882
+
883
+ function compile(str, options) {
884
+ return tokensToFunction(parse(str, options), options);
885
+ }
354
886
  /**
355
887
  * Create path match function from `path-to-regexp` spec.
356
888
  */
357
- function match (str, options) {
889
+
890
+
891
+ function match(str, options) {
358
892
  var keys = [];
359
893
  var re = pathToRegexp(str, keys, options);
360
- return regexpToFunction(re, keys)
894
+ return regexpToFunction(re, keys);
361
895
  }
362
-
363
896
  /**
364
897
  * Create a path match function from `path-to-regexp` output.
365
898
  */
366
- function regexpToFunction (re, keys) {
899
+
900
+
901
+ function regexpToFunction(re, keys) {
367
902
  return function (pathname, options) {
368
903
  var m = re.exec(pathname);
369
- if (!m) { return false }
370
-
904
+ if (!m) return false;
371
905
  var path = m[0];
372
906
  var index = m.index;
373
907
  var params = {};
374
- var decode = (options && options.decode) || decodeURIComponent;
908
+ var decode = options && options.decode || decodeURIComponent;
375
909
 
376
910
  for (var i = 1; i < m.length; i++) {
377
- if (m[i] === undefined) { continue }
378
-
911
+ if (m[i] === undefined) continue;
379
912
  var key = keys[i - 1];
380
913
 
381
914
  if (key.repeat) {
382
915
  params[key.name] = m[i].split(key.delimiter).map(function (value) {
383
- return decode(value, key)
916
+ return decode(value, key);
384
917
  });
385
918
  } else {
386
919
  params[key.name] = decode(m[i], key);
387
920
  }
388
921
  }
389
922
 
390
- return { path: path, index: index, params: params }
391
- }
923
+ return {
924
+ path: path,
925
+ index: index,
926
+ params: params
927
+ };
928
+ };
392
929
  }
393
-
394
930
  /**
395
931
  * Expose a method for transforming tokens into the path function.
396
932
  */
397
- function tokensToFunction (tokens, options) {
933
+
934
+
935
+ function tokensToFunction(tokens, options) {
398
936
  // Compile all the tokens into regexps.
399
- var matches = new Array(tokens.length);
937
+ var matches = new Array(tokens.length); // Compile all the patterns before compilation.
400
938
 
401
- // Compile all the patterns before compilation.
402
939
  for (var i = 0; i < tokens.length; i++) {
403
- if (typeof tokens[i] === 'object') {
940
+ if (_typeof__default['default'](tokens[i]) === 'object') {
404
941
  matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$', flags(options));
405
942
  }
406
943
  }
407
944
 
408
945
  return function (data, options) {
409
946
  var path = '';
410
- var encode = (options && options.encode) || encodeURIComponent;
947
+ var encode = options && options.encode || encodeURIComponent;
411
948
  var validate = options ? options.validate !== false : true;
412
949
 
413
950
  for (var i = 0; i < tokens.length; i++) {
@@ -415,7 +952,7 @@ function tokensToFunction (tokens, options) {
415
952
 
416
953
  if (typeof token === 'string') {
417
954
  path += token;
418
- continue
955
+ continue;
419
956
  }
420
957
 
421
958
  var value = data ? data[token.name] : undefined;
@@ -423,78 +960,78 @@ function tokensToFunction (tokens, options) {
423
960
 
424
961
  if (Array.isArray(value)) {
425
962
  if (!token.repeat) {
426
- 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');
427
964
  }
428
965
 
429
966
  if (value.length === 0) {
430
- if (token.optional) { continue }
431
-
432
- 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');
433
969
  }
434
970
 
435
971
  for (var j = 0; j < value.length; j++) {
436
972
  segment = encode(value[j], token);
437
973
 
438
974
  if (validate && !matches[i].test(segment)) {
439
- throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '"')
975
+ throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '"');
440
976
  }
441
977
 
442
978
  path += (j === 0 ? token.prefix : token.delimiter) + segment;
443
979
  }
444
980
 
445
- continue
981
+ continue;
446
982
  }
447
983
 
448
984
  if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
449
985
  segment = encode(String(value), token);
450
986
 
451
987
  if (validate && !matches[i].test(segment)) {
452
- 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 + '"');
453
989
  }
454
990
 
455
991
  path += token.prefix + segment;
456
- continue
992
+ continue;
457
993
  }
458
994
 
459
- if (token.optional) { continue }
460
-
461
- 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'));
462
997
  }
463
998
 
464
- return path
465
- }
999
+ return path;
1000
+ };
466
1001
  }
467
-
468
1002
  /**
469
1003
  * Escape a regular expression string.
470
1004
  *
471
1005
  * @param {string} str
472
1006
  * @return {string}
473
1007
  */
474
- function escapeString (str) {
475
- return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1')
476
- }
477
1008
 
1009
+
1010
+ function escapeString(str) {
1011
+ return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1');
1012
+ }
478
1013
  /**
479
1014
  * Escape the capturing group by escaping special characters and meaning.
480
1015
  *
481
1016
  * @param {string} group
482
1017
  * @return {string}
483
1018
  */
484
- function escapeGroup (group) {
485
- return group.replace(/([=!:$/()])/g, '\\$1')
486
- }
487
1019
 
1020
+
1021
+ function escapeGroup(group) {
1022
+ return group.replace(/([=!:$/()])/g, '\\$1');
1023
+ }
488
1024
  /**
489
1025
  * Get the flags for a regexp from the options.
490
1026
  *
491
1027
  * @param {Object} options
492
1028
  * @return {string}
493
1029
  */
494
- function flags (options) {
495
- return options && options.sensitive ? '' : 'i'
496
- }
497
1030
 
1031
+
1032
+ function flags(options) {
1033
+ return options && options.sensitive ? '' : 'i';
1034
+ }
498
1035
  /**
499
1036
  * Pull out keys from a regexp.
500
1037
  *
@@ -502,10 +1039,11 @@ function flags (options) {
502
1039
  * @param {Array=} keys
503
1040
  * @return {!RegExp}
504
1041
  */
505
- function regexpToRegexp (path, keys) {
506
- if (!keys) { return path }
507
1042
 
508
- // 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
+
509
1047
  var groups = path.source.match(/\((?!\?)/g);
510
1048
 
511
1049
  if (groups) {
@@ -521,9 +1059,8 @@ function regexpToRegexp (path, keys) {
521
1059
  }
522
1060
  }
523
1061
 
524
- return path
1062
+ return path;
525
1063
  }
526
-
527
1064
  /**
528
1065
  * Transform an array into a regexp.
529
1066
  *
@@ -532,16 +1069,17 @@ function regexpToRegexp (path, keys) {
532
1069
  * @param {Object=} options
533
1070
  * @return {!RegExp}
534
1071
  */
535
- function arrayToRegexp (path, keys, options) {
1072
+
1073
+
1074
+ function arrayToRegexp(path, keys, options) {
536
1075
  var parts = [];
537
1076
 
538
1077
  for (var i = 0; i < path.length; i++) {
539
1078
  parts.push(pathToRegexp(path[i], keys, options).source);
540
1079
  }
541
1080
 
542
- return new RegExp('(?:' + parts.join('|') + ')', flags(options))
1081
+ return new RegExp('(?:' + parts.join('|') + ')', flags(options));
543
1082
  }
544
-
545
1083
  /**
546
1084
  * Create a path regexp from string input.
547
1085
  *
@@ -550,10 +1088,11 @@ function arrayToRegexp (path, keys, options) {
550
1088
  * @param {Object=} options
551
1089
  * @return {!RegExp}
552
1090
  */
553
- function stringToRegexp (path, keys, options) {
554
- return tokensToRegExp(parse(path, options), keys, options)
555
- }
556
1091
 
1092
+
1093
+ function stringToRegexp(path, keys, options) {
1094
+ return tokensToRegExp(parse(path, options), keys, options);
1095
+ }
557
1096
  /**
558
1097
  * Expose a function for taking tokens and returning a RegExp.
559
1098
  *
@@ -562,28 +1101,25 @@ function stringToRegexp (path, keys, options) {
562
1101
  * @param {Object=} options
563
1102
  * @return {!RegExp}
564
1103
  */
565
- function tokensToRegExp (tokens, keys, options) {
566
- options = options || {};
567
1104
 
1105
+
1106
+ function tokensToRegExp(tokens, keys, options) {
1107
+ options = options || {};
568
1108
  var strict = options.strict;
569
1109
  var start = options.start !== false;
570
1110
  var end = options.end !== false;
571
1111
  var delimiter = options.delimiter || DEFAULT_DELIMITER;
572
1112
  var endsWith = [].concat(options.endsWith || []).map(escapeString).concat('$').join('|');
573
- var route = start ? '^' : '';
1113
+ var route = start ? '^' : ''; // Iterate over the tokens and create our regexp string.
574
1114
 
575
- // Iterate over the tokens and create our regexp string.
576
1115
  for (var i = 0; i < tokens.length; i++) {
577
1116
  var token = tokens[i];
578
1117
 
579
1118
  if (typeof token === 'string') {
580
1119
  route += escapeString(token);
581
1120
  } else {
582
- var capture = token.repeat
583
- ? '(?:' + token.pattern + ')(?:' + escapeString(token.delimiter) + '(?:' + token.pattern + '))*'
584
- : token.pattern;
585
-
586
- 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);
587
1123
 
588
1124
  if (token.optional) {
589
1125
  if (!token.prefix) {
@@ -598,22 +1134,17 @@ function tokensToRegExp (tokens, keys, options) {
598
1134
  }
599
1135
 
600
1136
  if (end) {
601
- if (!strict) { route += '(?:' + escapeString(delimiter) + ')?'; }
602
-
1137
+ if (!strict) route += '(?:' + escapeString(delimiter) + ')?';
603
1138
  route += endsWith === '$' ? '$' : '(?=' + endsWith + ')';
604
1139
  } else {
605
1140
  var endToken = tokens[tokens.length - 1];
606
- var isEndDelimited = typeof endToken === 'string'
607
- ? endToken[endToken.length - 1] === delimiter
608
- : endToken === undefined;
609
-
610
- if (!strict) { route += '(?:' + escapeString(delimiter) + '(?=' + endsWith + '))?'; }
611
- 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 + ')';
612
1144
  }
613
1145
 
614
- return new RegExp(route, flags(options))
1146
+ return new RegExp(route, flags(options));
615
1147
  }
616
-
617
1148
  /**
618
1149
  * Normalize the given path string, returning a regular expression.
619
1150
  *
@@ -626,25 +1157,21 @@ function tokensToRegExp (tokens, keys, options) {
626
1157
  * @param {Object=} options
627
1158
  * @return {!RegExp}
628
1159
  */
629
- function pathToRegexp (path, keys, options) {
1160
+
1161
+
1162
+ function pathToRegexp(path, keys, options) {
630
1163
  if (path instanceof RegExp) {
631
- return regexpToRegexp(path, keys)
1164
+ return regexpToRegexp(path, keys);
632
1165
  }
633
1166
 
634
1167
  if (Array.isArray(path)) {
635
- return arrayToRegexp(/** @type {!Array} */ (path), keys, options)
1168
+ return arrayToRegexp(path, keys, options);
636
1169
  }
637
1170
 
638
- return stringToRegexp(/** @type {string} */ (path), keys, options)
1171
+ return stringToRegexp(path, keys, options);
639
1172
  }
640
- pathToRegexp_1.match = match_1;
641
- pathToRegexp_1.regexpToFunction = regexpToFunction_1;
642
- pathToRegexp_1.parse = parse_1;
643
- pathToRegexp_1.compile = compile_1;
644
- pathToRegexp_1.tokensToFunction = tokensToFunction_1;
645
- pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
646
1173
 
647
- /*! Universal Router | MIT License | https://www.kriasoft.com/universal-router/ */
1174
+ var pathToRegexp$1 = pathToRegexp$2.exports;
648
1175
 
649
1176
  var hasOwnProperty = Object.prototype.hasOwnProperty;
650
1177
  var cache = new Map();
@@ -666,7 +1193,7 @@ function matchPath(route, pathname, parentKeys, parentParams) {
666
1193
  var keys = [];
667
1194
  regexp = {
668
1195
  keys: keys,
669
- pattern: pathToRegexp_1(route.path || '', keys, {
1196
+ pattern: pathToRegexp$1(route.path || '', keys, {
670
1197
  end: end
671
1198
  })
672
1199
  };
@@ -789,7 +1316,7 @@ var UniversalRouter = function () {
789
1316
  options = {};
790
1317
  }
791
1318
 
792
- if (!routes || typeof routes !== 'object') {
1319
+ if (!routes || _typeof__default['default'](routes) !== 'object') {
793
1320
  throw new TypeError('Invalid routes');
794
1321
  }
795
1322
 
@@ -868,871 +1395,1204 @@ var UniversalRouter = function () {
868
1395
  return UniversalRouter;
869
1396
  }();
870
1397
 
871
- UniversalRouter.pathToRegexp = pathToRegexp_1;
872
-
873
- var Taro = require('@tarojs/taro-h5');
874
- function initTabbar(config) {
875
- if (config.tabBar == null) {
876
- return;
877
- }
878
- // TODO: 找到 tabbar 的类型
879
- var tabbar = document.createElement('taro-tabbar');
880
- var homePage = config.pages ? config.pages[0] : '';
881
- tabbar.conf = config.tabBar;
882
- tabbar.conf.homePage = exports.history.location.pathname === '/' ? homePage : exports.history.location.pathname;
883
- var routerConfig = config.router;
884
- tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
885
- if (routerConfig.customRoutes) {
886
- tabbar.conf.custom = true;
887
- tabbar.conf.customRoutes = routerConfig.customRoutes;
888
- }
889
- else {
890
- tabbar.conf.custom = false;
891
- tabbar.conf.customRoutes = {};
892
- }
893
- if (typeof routerConfig.basename !== 'undefined') {
894
- tabbar.conf.basename = routerConfig.basename;
895
- }
896
- var container = document.getElementById('container');
897
- // eslint-disable-next-line no-unused-expressions
898
- container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
899
- Taro.initTabBarApis(config);
900
- }
901
-
902
- var routerConfig = Object.create(null);
903
- function init(config) {
904
- var _a;
905
- config.router.mode = config.router.mode || 'hash';
906
- setHistoryMode(config.router.mode, config.router.basename);
907
- Object.assign(routerConfig, config);
908
- (_a = document.getElementById('app')) === null || _a === void 0 ? void 0 : _a.remove();
909
- var container = document.createElement('div');
910
- container.classList.add('taro-tabbar__container');
911
- container.id = 'container';
912
- var panel = document.createElement('div');
913
- panel.classList.add('taro-tabbar__panel');
914
- var app = document.createElement('div');
915
- app.id = 'app';
916
- app.classList.add('taro_router');
917
- panel.appendChild(app);
918
- container.appendChild(panel);
919
- document.body.appendChild(container);
920
- initTabbar(config);
921
- }
1398
+ UniversalRouter.pathToRegexp = pathToRegexp$1;
922
1399
 
923
- var pageScrollFn;
924
- var pageDOM = window;
925
- function bindPageScroll(page, config) {
926
- pageDOM.removeEventListener('scroll', pageScrollFn);
927
- pageDOM = getScrollContainer();
928
- var distance = config.onReachBottomDistance || 50;
929
- var isReachBottom = false;
930
- pageScrollFn = function () {
931
- page.onPageScroll && page.onPageScroll({
932
- scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
933
- });
934
- if (isReachBottom && getOffset() > distance) {
935
- isReachBottom = false;
936
- }
937
- if (page.onReachBottom &&
938
- !isReachBottom &&
939
- getOffset() < distance) {
940
- isReachBottom = true;
941
- page.onReachBottom();
942
- }
943
- };
944
- pageDOM.addEventListener('scroll', pageScrollFn, false);
945
- }
946
- window.addEventListener('DOMSubtreeModified', function (e) {
947
- var _a;
948
- // @ts-ignore
949
- var className = (_a = e.target) === null || _a === void 0 ? void 0 : _a.className;
950
- if (className && /taro-tabbar__/.test(className)) {
951
- pageDOM.removeEventListener('scroll', pageScrollFn);
952
- pageDOM = getScrollContainer();
953
- pageDOM.addEventListener('scroll', pageScrollFn, false);
954
- }
955
- }, false);
956
- function getScrollContainer() {
957
- if (document.querySelector('.taro-tabbar__tabbar') === null) {
958
- // 没设置tabbar
959
- return window;
960
- }
961
- else {
962
- // 有设置tabbar
963
- return document.querySelector('.taro-tabbar__panel') || window;
964
- }
965
- }
966
- function getOffset() {
967
- if (pageDOM instanceof Window) {
968
- return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
969
- }
970
- else {
971
- return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
972
- }
973
- }
1400
+ var queryString = {};
974
1401
 
975
- function createCommonjsModule(fn, module) {
976
- return module = { exports: {} }, fn(module, module.exports), module.exports;
977
- }
978
-
979
- 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
+ };
980
1407
 
981
1408
  var token = '%[a-f0-9]{2}';
982
1409
  var singleMatcher = new RegExp(token, 'gi');
983
1410
  var multiMatcher = new RegExp('(' + token + ')+', 'gi');
984
1411
 
985
1412
  function decodeComponents(components, split) {
986
- try {
987
- // Try to decode the entire string first
988
- return decodeURIComponent(components.join(''));
989
- } catch (err) {
990
- // Do nothing
991
- }
992
-
993
- if (components.length === 1) {
994
- return components;
995
- }
1413
+ try {
1414
+ // Try to decode the entire string first
1415
+ return decodeURIComponent(components.join(''));
1416
+ } catch (err) {// Do nothing
1417
+ }
996
1418
 
997
- split = split || 1;
1419
+ if (components.length === 1) {
1420
+ return components;
1421
+ }
998
1422
 
999
- // Split the array in 2 parts
1000
- var left = components.slice(0, split);
1001
- var right = components.slice(split);
1423
+ split = split || 1; // Split the array in 2 parts
1002
1424
 
1003
- 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));
1004
1428
  }
1005
1429
 
1006
1430
  function decode(input) {
1007
- try {
1008
- return decodeURIComponent(input);
1009
- } catch (err) {
1010
- var tokens = input.match(singleMatcher);
1011
-
1012
- for (var i = 1; i < tokens.length; i++) {
1013
- input = decodeComponents(tokens, i).join('');
1431
+ try {
1432
+ return decodeURIComponent(input);
1433
+ } catch (err) {
1434
+ var tokens = input.match(singleMatcher);
1014
1435
 
1015
- tokens = input.match(singleMatcher);
1016
- }
1436
+ for (var i = 1; i < tokens.length; i++) {
1437
+ input = decodeComponents(tokens, i).join('');
1438
+ tokens = input.match(singleMatcher);
1439
+ }
1017
1440
 
1018
- return input;
1019
- }
1441
+ return input;
1442
+ }
1020
1443
  }
1021
1444
 
1022
1445
  function customDecodeURIComponent(input) {
1023
- // Keep track of all the replacements and prefill the map with the `BOM`
1024
- var replaceMap = {
1025
- '%FE%FF': '\uFFFD\uFFFD',
1026
- '%FF%FE': '\uFFFD\uFFFD'
1027
- };
1028
-
1029
- var match = multiMatcher.exec(input);
1030
- while (match) {
1031
- try {
1032
- // Decode as big chunks as possible
1033
- replaceMap[match[0]] = decodeURIComponent(match[0]);
1034
- } catch (err) {
1035
- var result = decode(match[0]);
1036
-
1037
- if (result !== match[0]) {
1038
- replaceMap[match[0]] = result;
1039
- }
1040
- }
1041
-
1042
- match = multiMatcher.exec(input);
1043
- }
1044
-
1045
- // Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
1046
- replaceMap['%C2'] = '\uFFFD';
1047
-
1048
- var entries = Object.keys(replaceMap);
1049
-
1050
- for (var i = 0; i < entries.length; i++) {
1051
- // Replace all decoded components
1052
- var key = entries[i];
1053
- input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
1054
- }
1055
-
1056
- 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;
1057
1479
  }
1058
1480
 
1059
- var decodeUriComponent = function (encodedURI) {
1060
- if (typeof encodedURI !== 'string') {
1061
- throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + typeof encodedURI + '`');
1062
- }
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
+ }
1063
1485
 
1064
- try {
1065
- encodedURI = encodedURI.replace(/\+/g, ' ');
1486
+ try {
1487
+ encodedURI = encodedURI.replace(/\+/g, ' '); // Try the built in decoder first
1066
1488
 
1067
- // Try the built in decoder first
1068
- return decodeURIComponent(encodedURI);
1069
- } catch (err) {
1070
- // Fallback to a more advanced decoder
1071
- return customDecodeURIComponent(encodedURI);
1072
- }
1489
+ return decodeURIComponent(encodedURI);
1490
+ } catch (err) {
1491
+ // Fallback to a more advanced decoder
1492
+ return customDecodeURIComponent(encodedURI);
1493
+ }
1073
1494
  };
1074
1495
 
1075
- var splitOnFirst = function (string, separator) {
1076
- if (!(typeof string === 'string' && typeof separator === 'string')) {
1077
- throw new TypeError('Expected the arguments to be of type `string`');
1078
- }
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
+ }
1079
1500
 
1080
- if (separator === '') {
1081
- return [string];
1082
- }
1501
+ if (separator === '') {
1502
+ return [string];
1503
+ }
1083
1504
 
1084
- var separatorIndex = string.indexOf(separator);
1505
+ var separatorIndex = string.indexOf(separator);
1085
1506
 
1086
- if (separatorIndex === -1) {
1087
- return [string];
1088
- }
1507
+ if (separatorIndex === -1) {
1508
+ return [string];
1509
+ }
1089
1510
 
1090
- return [
1091
- string.slice(0, separatorIndex),
1092
- string.slice(separatorIndex + separator.length)
1093
- ];
1511
+ return [string.slice(0, separatorIndex), string.slice(separatorIndex + separator.length)];
1094
1512
  };
1095
1513
 
1096
- var filterObj = function (obj, predicate) {
1097
- var ret = {};
1098
- var keys = Object.keys(obj);
1099
- 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);
1100
1518
 
1101
- for (var i = 0; i < keys.length; i++) {
1102
- var key = keys[i];
1103
- var val = obj[key];
1519
+ for (var i = 0; i < keys.length; i++) {
1520
+ var key = keys[i];
1521
+ var val = obj[key];
1104
1522
 
1105
- if (isArr ? predicate.indexOf(key) !== -1 : predicate(key, val, obj)) {
1106
- ret[key] = val;
1107
- }
1108
- }
1523
+ if (isArr ? predicate.indexOf(key) !== -1 : predicate(key, val, obj)) {
1524
+ ret[key] = val;
1525
+ }
1526
+ }
1109
1527
 
1110
- return ret;
1528
+ return ret;
1111
1529
  };
1112
1530
 
1113
- var queryString = createCommonjsModule(function (module, exports) {
1531
+ (function (exports) {
1114
1532
 
1533
+ var strictUriEncode$1 = strictUriEncode;
1534
+ var decodeComponent = decodeUriComponent;
1535
+ var splitOnFirst$1 = splitOnFirst;
1536
+ var filterObject = filterObj;
1115
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
+ }
1116
1571
 
1572
+ return [].concat(_toConsumableArray__default['default'](result), [[encode(key, options), '[]=', encode(value, options)].join('')]);
1573
+ };
1574
+ };
1117
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
+ }
1118
1583
 
1119
- var isNullOrUndefined = function (value) { return value === null || value === undefined; };
1584
+ if (result.length === 0) {
1585
+ return [[encode(key, options), '=', encode(value, options)].join('')];
1586
+ }
1120
1587
 
1121
- function encoderForArrayFormat(options) {
1122
- switch (options.arrayFormat) {
1123
- case 'index':
1124
- return function (key) { return function (result, value) {
1125
- var index = result.length;
1588
+ return [[result, encode(value, options)].join(options.arrayFormatSeparator)];
1589
+ };
1590
+ };
1126
1591
 
1127
- if (
1128
- value === undefined ||
1129
- (options.skipNull && value === null) ||
1130
- (options.skipEmptyString && value === '')
1131
- ) {
1132
- return result;
1133
- }
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
+ }
1134
1598
 
1135
- if (value === null) {
1136
- return result.concat( [[encode(key, options), '[', index, ']'].join('')]);
1137
- }
1599
+ if (value === null) {
1600
+ return [].concat(_toConsumableArray__default['default'](result), [encode(key, options)]);
1601
+ }
1138
1602
 
1139
- return result.concat( [[encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join('')]
1140
- );
1141
- }; };
1603
+ return [].concat(_toConsumableArray__default['default'](result), [[encode(key, options), '=', encode(value, options)].join('')]);
1604
+ };
1605
+ };
1606
+ }
1607
+ }
1142
1608
 
1143
- case 'bracket':
1144
- return function (key) { return function (result, value) {
1145
- if (
1146
- value === undefined ||
1147
- (options.skipNull && value === null) ||
1148
- (options.skipEmptyString && value === '')
1149
- ) {
1150
- return result;
1151
- }
1609
+ function parserForArrayFormat(options) {
1610
+ var result;
1152
1611
 
1153
- if (value === null) {
1154
- return result.concat( [[encode(key, options), '[]'].join('')]);
1155
- }
1612
+ switch (options.arrayFormat) {
1613
+ case 'index':
1614
+ return function (key, value, accumulator) {
1615
+ result = /\[(\d*)\]$/.exec(key);
1616
+ key = key.replace(/\[\d*\]$/, '');
1156
1617
 
1157
- return result.concat( [[encode(key, options), '[]=', encode(value, options)].join('')]);
1158
- }; };
1618
+ if (!result) {
1619
+ accumulator[key] = value;
1620
+ return;
1621
+ }
1159
1622
 
1160
- case 'comma':
1161
- case 'separator':
1162
- return function (key) { return function (result, value) {
1163
- if (value === null || value === undefined || value.length === 0) {
1164
- return result;
1165
- }
1623
+ if (accumulator[key] === undefined) {
1624
+ accumulator[key] = {};
1625
+ }
1166
1626
 
1167
- if (result.length === 0) {
1168
- return [[encode(key, options), '=', encode(value, options)].join('')];
1169
- }
1627
+ accumulator[key][result[1]] = value;
1628
+ };
1170
1629
 
1171
- return [[result, encode(value, options)].join(options.arrayFormatSeparator)];
1172
- }; };
1630
+ case 'bracket':
1631
+ return function (key, value, accumulator) {
1632
+ result = /(\[\])$/.exec(key);
1633
+ key = key.replace(/\[\]$/, '');
1173
1634
 
1174
- default:
1175
- return function (key) { return function (result, value) {
1176
- if (
1177
- value === undefined ||
1178
- (options.skipNull && value === null) ||
1179
- (options.skipEmptyString && value === '')
1180
- ) {
1181
- return result;
1182
- }
1635
+ if (!result) {
1636
+ accumulator[key] = value;
1637
+ return;
1638
+ }
1183
1639
 
1184
- if (value === null) {
1185
- return result.concat( [encode(key, options)]);
1186
- }
1640
+ if (accumulator[key] === undefined) {
1641
+ accumulator[key] = [value];
1642
+ return;
1643
+ }
1187
1644
 
1188
- return result.concat( [[encode(key, options), '=', encode(value, options)].join('')]);
1189
- }; };
1190
- }
1191
- }
1645
+ accumulator[key] = [].concat(accumulator[key], value);
1646
+ };
1192
1647
 
1193
- function parserForArrayFormat(options) {
1194
- var result;
1195
-
1196
- switch (options.arrayFormat) {
1197
- case 'index':
1198
- return function (key, value, accumulator) {
1199
- result = /\[(\d*)\]$/.exec(key);
1200
-
1201
- key = key.replace(/\[\d*\]$/, '');
1202
-
1203
- if (!result) {
1204
- accumulator[key] = value;
1205
- return;
1206
- }
1207
-
1208
- if (accumulator[key] === undefined) {
1209
- accumulator[key] = {};
1210
- }
1211
-
1212
- accumulator[key][result[1]] = value;
1213
- };
1214
-
1215
- case 'bracket':
1216
- return function (key, value, accumulator) {
1217
- result = /(\[\])$/.exec(key);
1218
- key = key.replace(/\[\]$/, '');
1219
-
1220
- if (!result) {
1221
- accumulator[key] = value;
1222
- return;
1223
- }
1224
-
1225
- if (accumulator[key] === undefined) {
1226
- accumulator[key] = [value];
1227
- return;
1228
- }
1229
-
1230
- accumulator[key] = [].concat(accumulator[key], value);
1231
- };
1232
-
1233
- case 'comma':
1234
- case 'separator':
1235
- return function (key, value, accumulator) {
1236
- var isArray = typeof value === 'string' && value.includes(options.arrayFormatSeparator);
1237
- var isEncodedArray = (typeof value === 'string' && !isArray && decode(value, options).includes(options.arrayFormatSeparator));
1238
- value = isEncodedArray ? decode(value, options) : value;
1239
- var newValue = isArray || isEncodedArray ? value.split(options.arrayFormatSeparator).map(function (item) { return decode(item, options); }) : value === null ? value : decode(value, options);
1240
- accumulator[key] = newValue;
1241
- };
1242
-
1243
- default:
1244
- return function (key, value, accumulator) {
1245
- if (accumulator[key] === undefined) {
1246
- accumulator[key] = value;
1247
- return;
1248
- }
1249
-
1250
- accumulator[key] = [].concat(accumulator[key], value);
1251
- };
1252
- }
1253
- }
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
+ };
1254
1659
 
1255
- function validateArrayFormatSeparator(value) {
1256
- if (typeof value !== 'string' || value.length !== 1) {
1257
- throw new TypeError('arrayFormatSeparator must be single character string');
1258
- }
1259
- }
1660
+ default:
1661
+ return function (key, value, accumulator) {
1662
+ if (accumulator[key] === undefined) {
1663
+ accumulator[key] = value;
1664
+ return;
1665
+ }
1260
1666
 
1261
- function encode(value, options) {
1262
- if (options.encode) {
1263
- return options.strict ? strictUriEncode(value) : encodeURIComponent(value);
1264
- }
1667
+ accumulator[key] = [].concat(accumulator[key], value);
1668
+ };
1669
+ }
1670
+ }
1265
1671
 
1266
- return value;
1267
- }
1672
+ function validateArrayFormatSeparator(value) {
1673
+ if (typeof value !== 'string' || value.length !== 1) {
1674
+ throw new TypeError('arrayFormatSeparator must be single character string');
1675
+ }
1676
+ }
1268
1677
 
1269
- function decode(value, options) {
1270
- if (options.decode) {
1271
- return decodeUriComponent(value);
1272
- }
1678
+ function encode(value, options) {
1679
+ if (options.encode) {
1680
+ return options.strict ? strictUriEncode$1(value) : encodeURIComponent(value);
1681
+ }
1273
1682
 
1274
- return value;
1275
- }
1683
+ return value;
1684
+ }
1276
1685
 
1277
- function keysSorter(input) {
1278
- if (Array.isArray(input)) {
1279
- return input.sort();
1280
- }
1686
+ function decode(value, options) {
1687
+ if (options.decode) {
1688
+ return decodeComponent(value);
1689
+ }
1281
1690
 
1282
- if (typeof input === 'object') {
1283
- return keysSorter(Object.keys(input))
1284
- .sort(function (a, b) { return Number(a) - Number(b); })
1285
- .map(function (key) { return input[key]; });
1286
- }
1691
+ return value;
1692
+ }
1287
1693
 
1288
- return input;
1289
- }
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
+ }
1290
1980
 
1291
- function removeHash(input) {
1292
- var hashStart = input.indexOf('#');
1293
- if (hashStart !== -1) {
1294
- input = input.slice(0, hashStart);
1295
- }
1981
+ if (page.onReachBottom && !isReachBottom && getOffset() < distance) {
1982
+ isReachBottom = true;
1983
+ page.onReachBottom();
1984
+ }
1985
+ };
1296
1986
 
1297
- return input;
1987
+ pageDOM.addEventListener('scroll', pageScrollFn, false);
1298
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);
1299
1999
 
1300
- function getHash(url) {
1301
- var hash = '';
1302
- var hashStart = url.indexOf('#');
1303
- if (hashStart !== -1) {
1304
- hash = url.slice(hashStart);
1305
- }
2000
+ function getScrollContainer() {
2001
+ var _Current$page;
1306
2002
 
1307
- 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;
1308
2006
  }
1309
2007
 
1310
- function extract(input) {
1311
- input = removeHash(input);
1312
- var queryStart = input.indexOf('?');
1313
- if (queryStart === -1) {
1314
- return '';
1315
- }
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
+ }
1316
2015
 
1317
- 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);
1318
2025
  }
1319
2026
 
1320
- function parseValue(value, options) {
1321
- if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
1322
- value = Number(value);
1323
- } else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
1324
- value = value.toLowerCase() === 'true';
1325
- }
2027
+ // @ts-nocheck
2028
+ function initTabbar(config) {
2029
+ if (config.tabBar == null) {
2030
+ return;
2031
+ } // TODO: custom-tab-bar
1326
2032
 
1327
- 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);
1328
2056
  }
1329
2057
 
1330
- function parse(query, options) {
1331
- options = Object.assign({
1332
- decode: true,
1333
- sort: true,
1334
- arrayFormat: 'none',
1335
- arrayFormatSeparator: ',',
1336
- parseNumbers: false,
1337
- parseBooleans: false
1338
- }, options);
1339
-
1340
- validateArrayFormatSeparator(options.arrayFormatSeparator);
1341
-
1342
- var formatter = parserForArrayFormat(options);
1343
-
1344
- // Create an object with no prototype
1345
- var ret = Object.create(null);
1346
-
1347
- if (typeof query !== 'string') {
1348
- return ret;
1349
- }
1350
-
1351
- query = query.trim().replace(/^[?#&]/, '');
1352
-
1353
- if (!query) {
1354
- return ret;
1355
- }
1356
-
1357
- for (var param of query.split('&')) {
1358
- if (param === '') {
1359
- continue;
1360
- }
1361
-
1362
- var ref = splitOnFirst(options.decode ? param.replace(/\+/g, ' ') : param, '=');
1363
- var key = ref[0];
1364
- var value = ref[1];
1365
-
1366
- // Missing `=` should be `null`:
1367
- // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
1368
- value = value === undefined ? null : ['comma', 'separator'].includes(options.arrayFormat) ? value : decode(value, options);
1369
- formatter(decode(key, options), value, ret);
1370
- }
1371
-
1372
- for (var key$1 of Object.keys(ret)) {
1373
- var value$1 = ret[key$1];
1374
- if (typeof value$1 === 'object' && value$1 !== null) {
1375
- for (var k of Object.keys(value$1)) {
1376
- value$1[k] = parseValue(value$1[k], options);
1377
- }
1378
- } else {
1379
- ret[key$1] = parseValue(value$1, options);
1380
- }
1381
- }
1382
-
1383
- if (options.sort === false) {
1384
- return ret;
1385
- }
1386
-
1387
- return (options.sort === true ? Object.keys(ret).sort() : Object.keys(ret).sort(options.sort)).reduce(function (result, key) {
1388
- var value = ret[key];
1389
- if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) {
1390
- // Sort object keys, not values
1391
- result[key] = keysSorter(value);
1392
- } else {
1393
- result[key] = value;
1394
- }
1395
-
1396
- return result;
1397
- }, 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
+ }
1398
2064
  }
1399
2065
 
1400
- exports.extract = extract;
1401
- exports.parse = parse;
2066
+ var PageHandler = /*#__PURE__*/function () {
2067
+ function PageHandler(config) {
2068
+ _classCallCheck__default['default'](this, PageHandler);
1402
2069
 
1403
- exports.stringify = function (object, options) {
1404
- if (!object) {
1405
- return '';
1406
- }
2070
+ _defineProperty__default['default'](this, "config", void 0);
1407
2071
 
1408
- options = Object.assign({
1409
- encode: true,
1410
- strict: true,
1411
- arrayFormat: 'none',
1412
- arrayFormatSeparator: ','
1413
- }, options);
2072
+ _defineProperty__default['default'](this, "defaultAnimation", {
2073
+ duration: 300,
2074
+ delay: 50
2075
+ });
1414
2076
 
1415
- validateArrayFormatSeparator(options.arrayFormatSeparator);
2077
+ _defineProperty__default['default'](this, "hideTimer", void 0);
1416
2078
 
1417
- var shouldFilter = function (key) { return (
1418
- (options.skipNull && isNullOrUndefined(object[key])) ||
1419
- (options.skipEmptyString && object[key] === '')
1420
- ); };
2079
+ _defineProperty__default['default'](this, "unloadTimer", void 0);
1421
2080
 
1422
- var formatter = encoderForArrayFormat(options);
2081
+ _defineProperty__default['default'](this, "lastHidePage", void 0);
1423
2082
 
1424
- var objectCopy = {};
2083
+ _defineProperty__default['default'](this, "lastUnloadPage", void 0);
1425
2084
 
1426
- for (var key of Object.keys(object)) {
1427
- if (!shouldFilter(key)) {
1428
- objectCopy[key] = object[key];
1429
- }
1430
- }
2085
+ this.config = config;
2086
+ this.mount();
2087
+ }
1431
2088
 
1432
- 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;
1433
2118
 
1434
- if (options.sort !== false) {
1435
- keys.sort(options.sort);
1436
- }
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;
1437
2130
 
1438
- return keys.map(function (key) {
1439
- 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;
1440
2137
 
1441
- if (value === undefined) {
1442
- return '';
1443
- }
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;
1444
2144
 
1445
- if (value === null) {
1446
- return encode(key, options);
1447
- }
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;
1448
2164
 
1449
- if (Array.isArray(value)) {
1450
- return value
1451
- .reduce(formatter(key), [])
1452
- .join('&');
1453
- }
2165
+ return this.routes.find(function (r) {
2166
+ var _routesAlias$getConfi;
1454
2167
 
1455
- return encode(key, options) + '=' + encode(value, options);
1456
- }).filter(function (x) { return x.length > 0; }).join('&');
1457
- };
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
+ }
1458
2188
 
1459
- exports.parseUrl = function (url, options) {
1460
- options = Object.assign({
1461
- decode: true
1462
- }, options);
1463
-
1464
- var ref = splitOnFirst(url, '#');
1465
- var url_ = ref[0];
1466
- var hash = ref[1];
1467
-
1468
- return Object.assign(
1469
- {
1470
- url: url_.split('?')[0] || '',
1471
- query: parse(extract(url), options)
1472
- },
1473
- options && options.parseFragmentIdentifier && hash ? {fragmentIdentifier: decode(hash, options)} : {}
1474
- );
1475
- };
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('?');
1476
2209
 
1477
- exports.stringifyUrl = function (object, options) {
1478
- options = Object.assign({
1479
- encode: true,
1480
- strict: true
1481
- }, 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
+ }
1482
2229
 
1483
- var url = removeHash(object.url).split('?')[0] || '';
1484
- var queryFromUrl = exports.extract(object.url);
1485
- 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;
1486
2293
 
1487
- var query = Object.assign(parsedQueryFromUrl, object.query);
1488
- var queryString = exports.stringify(query, options);
1489
- if (queryString) {
1490
- queryString = "?" + queryString;
1491
- }
2294
+ (_page$onLoad = page.onLoad) === null || _page$onLoad === void 0 ? void 0 : _page$onLoad.call(page, this.getQuery(stacksIndex), function () {
2295
+ var _pageEl;
1492
2296
 
1493
- var hash = getHash(object.url);
1494
- if (object.fragmentIdentifier) {
1495
- hash = "#" + (encode(object.fragmentIdentifier, options));
1496
- }
2297
+ pageEl = document.getElementById(page.path);
2298
+ _this2.isTabBar && ((_pageEl = pageEl) === null || _pageEl === void 0 ? void 0 : _pageEl.classList.add('taro_tabbar_page'));
1497
2299
 
1498
- return ("" + url + queryString + hash);
1499
- };
2300
+ _this2.addAnimation(pageEl, stacksIndex === 0);
1500
2301
 
1501
- exports.pick = function (input, filter, options) {
1502
- options = Object.assign({
1503
- parseFragmentIdentifier: true
1504
- }, options);
1505
-
1506
- var ref = exports.parseUrl(input, options);
1507
- var url = ref.url;
1508
- var query = ref.query;
1509
- var fragmentIdentifier = ref.fragmentIdentifier;
1510
- return exports.stringifyUrl({
1511
- url: url,
1512
- query: filterObj(query, filter),
1513
- fragmentIdentifier: fragmentIdentifier
1514
- }, options);
1515
- };
2302
+ _this2.onReady(page, true);
2303
+ });
2304
+ }
1516
2305
 
1517
- exports.exclude = function (input, filter, options) {
1518
- 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
+ }
1519
2329
 
1520
- return exports.pick(input, exclusionFilter, options);
1521
- };
1522
- });
1523
- var queryString_1 = queryString.extract;
1524
- var queryString_2 = queryString.parse;
1525
- var queryString_3 = queryString.stringify;
1526
- var queryString_4 = queryString.parseUrl;
1527
- var queryString_5 = queryString.stringifyUrl;
1528
- var queryString_6 = queryString.pick;
1529
- var queryString_7 = queryString.exclude;
1530
-
1531
- function getSearch() {
1532
- var search = '?';
1533
- if (routerConfig.router.mode === 'hash') {
1534
- var idx = location.hash.indexOf('?');
1535
- if (idx > -1) {
1536
- search = location.hash.slice(idx);
1537
- }
1538
- }
1539
- else {
1540
- search = location.search;
1541
- }
1542
- return search.substr(1);
1543
- }
1544
- var qs = function (stamp) {
1545
- if ( stamp === void 0 ) stamp = 0;
1546
-
1547
- var search = getSearch();
1548
- var query = search
1549
- ? queryString.parse(search)
1550
- : {};
1551
- if (stamp) {
1552
- query.stamp = stamp.toString();
1553
- }
1554
- return query;
1555
- };
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;
1556
2335
 
1557
- /* eslint-disable dot-notation */
1558
- function pageOnReady(page, onLoad) {
1559
- if ( onLoad === void 0 ) onLoad = true;
1560
-
1561
- var _a, _b;
1562
- var pageEl = document.getElementById(page.path);
1563
- if (pageEl && !(pageEl === null || pageEl === void 0 ? void 0 : pageEl['__isReady'])) {
1564
- var el = pageEl.firstElementChild;
1565
- (_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 () {
1566
- runtime.requestAnimationFrame(function () {
1567
- page.onReady();
1568
- pageEl['__isReady'] = true;
1569
- });
1570
- });
1571
- onLoad && (pageEl['__page'] = page);
1572
- }
1573
- }
1574
- function loadPage(page, pageConfig, stacksIndex) {
1575
- if ( pageConfig === void 0 ) pageConfig = {};
1576
- if ( stacksIndex === void 0 ) stacksIndex = 0;
1577
-
1578
- if (!page)
1579
- { return; }
1580
- var pageEl = document.getElementById(page.path);
1581
- if (pageEl) {
1582
- pageEl.style.display = 'block';
1583
- }
1584
- else {
1585
- page.onLoad(qs(stacksIndex), function () { return pageOnReady(page, true); });
1586
- }
1587
- stacks.push(page);
1588
- page.onShow();
1589
- bindPageScroll(page, pageConfig);
1590
- }
1591
- function unloadPage(page, delta) {
1592
- if ( delta === void 0 ) delta = 1;
1593
-
1594
- if (!page)
1595
- { return; }
1596
- stacks.delta = --delta;
1597
- stacks.pop();
1598
- page.onUnload();
1599
- if (delta >= 1)
1600
- { unloadPage(stacks.last, delta); }
1601
- }
1602
- function showPage(page, pageConfig, stacksIndex) {
1603
- if ( pageConfig === void 0 ) pageConfig = {};
1604
- if ( stacksIndex === void 0 ) stacksIndex = 0;
1605
-
1606
- if (!page)
1607
- { return; }
1608
- page.onShow();
1609
- var pageEl = document.getElementById(page.path);
1610
- if (pageEl) {
1611
- pageEl.style.display = 'block';
1612
- }
1613
- else {
1614
- page.onLoad(qs(stacksIndex), function () { return pageOnReady(page, false); });
1615
- }
1616
- bindPageScroll(page, pageConfig);
1617
- }
1618
- function hidePage(page) {
1619
- if (!page)
1620
- { return; }
1621
- // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
1622
- var pageEl = document.getElementById(page.path);
1623
- if (pageEl) {
1624
- pageEl.style.display = 'none';
1625
- page.onHide();
1626
- }
1627
- else {
1628
- setTimeout(function () { return hidePage(page); }, 0);
1629
- }
1630
- }
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
+ }
1631
2589
 
1632
- /* eslint-disable dot-notation */
1633
- function createRouter(app, config, framework) {
1634
- var _a;
1635
- init(config);
1636
- var routes = [];
1637
- var alias = (_a = config.router.customRoutes) !== null && _a !== void 0 ? _a : {};
1638
- var runtimeHooks = runtime.container.get(runtime.SERVICE_IDENTIFIER.Hooks);
1639
- setRoutesAlias(alias);
1640
- for (var i = 0; i < config.routes.length; i++) {
1641
- var route = config.routes[i];
1642
- var path = addLeadingSlash(route.path);
1643
- routes.push({
1644
- path: alias[path] || path,
1645
- action: route.load
1646
- });
1647
- }
1648
- var basename = config.router.basename;
1649
- var router = new UniversalRouter(routes, { baseUrl: basename || '' });
1650
- app.onLaunch();
1651
- var render = async function (ref) {
1652
- var location = ref.location;
1653
- var action = ref.action;
1654
-
1655
- var _a, _b, _c, _d;
1656
- routerConfig.router.pathname = location.pathname;
1657
- var element;
1658
- try {
1659
- element = await router.resolve(config.router.forcePath || location.pathname);
1660
- }
1661
- catch (error) {
1662
- if (error.status === 404) {
1663
- (_a = app.onPageNotFound) === null || _a === void 0 ? void 0 : _a.call(app, {
1664
- path: location.pathname
1665
- });
1666
- }
1667
- else {
1668
- throw new Error(error);
1669
- }
1670
- }
1671
- if (!element)
1672
- { return; }
1673
- var pageConfig = config.routes.find(function (r) {
1674
- var path = addLeadingSlash(r.path);
1675
- return path === location.pathname || alias[path] === location.pathname;
1676
- });
1677
- var enablePullDownRefresh = false;
1678
- runtime.eventCenter.trigger('__taroRouterChange', {
1679
- toLocation: {
1680
- path: location.pathname
1681
- }
1682
- });
1683
- if (pageConfig) {
1684
- document.title = (_b = pageConfig.navigationBarTitleText) !== null && _b !== void 0 ? _b : document.title;
1685
- enablePullDownRefresh = pageConfig.enablePullDownRefresh;
1686
- }
1687
- var currentPage = runtime.Current.page;
1688
- var pathname = location.pathname;
1689
- var shouldLoad = false;
1690
- if (action === 'POP') {
1691
- // NOTE: 浏览器事件退后多次时,该事件只会被触发一次
1692
- var prevIndex = stacks.getPrevIndex(pathname);
1693
- var delta = stacks.getDelta(pathname);
1694
- unloadPage(currentPage, delta);
1695
- if (prevIndex > -1) {
1696
- showPage(stacks.getItem(prevIndex), pageConfig, prevIndex);
1697
- }
1698
- else {
1699
- shouldLoad = true;
1700
- }
1701
- }
1702
- else if (action === 'PUSH') {
1703
- hidePage(currentPage);
1704
- shouldLoad = true;
1705
- }
1706
- else if (action === 'REPLACE') {
1707
- if (isTabBar(config)) {
1708
- hidePage(currentPage);
1709
- var prevIndex$1 = stacks.getPrevIndex(pathname);
1710
- if (prevIndex$1 > -1) {
1711
- // NOTE: tabbar 页且之前出现过,直接复用
1712
- return showPage(stacks.getItem(prevIndex$1), pageConfig, prevIndex$1);
1713
- }
1714
- }
1715
- else {
1716
- unloadPage(currentPage);
1717
- }
1718
- shouldLoad = true;
1719
- }
1720
- if (shouldLoad || stacks.length < 1) {
1721
- var el = (_c = element.default) !== null && _c !== void 0 ? _c : element;
1722
- var loadConfig = Object.assign({}, pageConfig);
1723
- var stacksIndex = stacks.length;
1724
- delete loadConfig['path'];
1725
- delete loadConfig['load'];
1726
- 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);
1727
- return loadPage(page, pageConfig, stacksIndex);
1728
- }
1729
- };
1730
- if (exports.history.location.pathname === '/') {
1731
- exports.history.replace(prependBasename(routes[0].path + exports.history.location.search));
1732
- }
1733
- render({ location: exports.history.location, action: r.Push });
1734
- app.onShow(qs(stacks.length));
1735
- 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);
1736
2596
  }
1737
2597
 
1738
2598
  exports.createRouter = createRouter;