@tarojs/router 3.3.16 → 3.4.0-beta.1

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