@tarojs/router 3.3.17 → 3.4.0-beta.2

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