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