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