@spcsn/taro-runtime 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bom/URL.d.ts +6 -1
- package/dist/bom/URL.js +26 -27
- package/dist/bom/URL.js.map +1 -1
- package/dist/bom/URLSearchParams.js +11 -11
- package/dist/bom/URLSearchParams.js.map +1 -1
- package/dist/bom/history.d.ts +5 -1
- package/dist/bom/history.js +34 -36
- package/dist/bom/history.js.map +1 -1
- package/dist/bom/location.d.ts +11 -1
- package/dist/bom/location.js +62 -63
- package/dist/bom/location.js.map +1 -1
- package/dist/index.cjs.js +135 -139
- package/dist/index.cjs.js.map +1 -1
- package/dist/perf.d.ts +1 -1
- package/dist/perf.js +2 -2
- package/dist/perf.js.map +1 -1
- package/dist/runtime.esm.js +135 -139
- package/dist/runtime.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/perf.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
declare class Performance {
|
|
2
|
-
#private;
|
|
3
2
|
private recorder;
|
|
4
3
|
start(id: string): void;
|
|
5
4
|
stop(id: string, now?: number): void;
|
|
6
5
|
delayStop(id: string, delay?: number): ((...args: any[]) => void) | undefined;
|
|
6
|
+
private parseTime;
|
|
7
7
|
}
|
|
8
8
|
export declare const perf: Performance;
|
|
9
9
|
export {};
|
package/dist/perf.js
CHANGED
|
@@ -15,7 +15,7 @@ var Performance = class {
|
|
|
15
15
|
if (!(prev >= 0)) return;
|
|
16
16
|
this.recorder.delete(id);
|
|
17
17
|
const time = now - prev;
|
|
18
|
-
console.log(`${id} 时长: ${time}ms 开始时间:${this
|
|
18
|
+
console.log(`${id} 时长: ${time}ms 开始时间:${this.parseTime(prev)} 结束时间:${this.parseTime(now)}`);
|
|
19
19
|
}
|
|
20
20
|
delayStop(id, delay = 500) {
|
|
21
21
|
if (!options.debug) return;
|
|
@@ -24,7 +24,7 @@ var Performance = class {
|
|
|
24
24
|
cb?.();
|
|
25
25
|
}, delay);
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
parseTime(time) {
|
|
28
28
|
const d = new Date(time);
|
|
29
29
|
return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${`${d.getMilliseconds()}`.padStart(3, "0")}`;
|
|
30
30
|
}
|
package/dist/perf.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perf.js","names":[
|
|
1
|
+
{"version":3,"file":"perf.js","names":[],"sources":["../src/perf.ts"],"sourcesContent":["import { options } from './options';\nimport { debounce } from './utils';\n\nimport type { TFunc } from './interface';\n\nclass Performance {\n private recorder = new Map<string, number>();\n\n public start(id: string) {\n if (!options.debug) {\n return;\n }\n this.recorder.set(id, Date.now());\n }\n\n public stop(id: string, now = Date.now()) {\n if (!options.debug) {\n return;\n }\n const prev = this.recorder.get(id)!;\n if (!(prev >= 0)) return;\n\n this.recorder.delete(id);\n const time = now - prev;\n // eslint-disable-next-line no-console\n console.log(`${id} 时长: ${time}ms 开始时间:${this.parseTime(prev)} 结束时间:${this.parseTime(now)}`);\n }\n\n public delayStop(id: string, delay = 500) {\n if (!options.debug) {\n return;\n }\n\n return debounce((now = Date.now(), cb?: TFunc) => {\n this.stop(id, now);\n cb?.();\n }, delay);\n }\n\n private parseTime(time: number) {\n const d = new Date(time);\n return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${`${d.getMilliseconds()}`.padStart(3, '0')}`;\n }\n}\n\nexport const perf = new Performance();\n"],"mappings":";;;AAKA,IAAM,cAAN,MAAkB;;kCACG,IAAI,IAAoB;;CAE3C,MAAa,IAAY;EACvB,IAAI,CAAC,QAAQ,OACX;EAEF,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,CAAC;CAClC;CAEA,KAAY,IAAY,MAAM,KAAK,IAAI,GAAG;EACxC,IAAI,CAAC,QAAQ,OACX;EAEF,MAAM,OAAO,KAAK,SAAS,IAAI,EAAE;EACjC,IAAI,EAAE,QAAQ,IAAI;EAElB,KAAK,SAAS,OAAO,EAAE;EACvB,MAAM,OAAO,MAAM;EAEnB,QAAQ,IAAI,GAAG,GAAG,OAAO,KAAK,UAAU,KAAK,UAAU,IAAI,EAAE,QAAQ,KAAK,UAAU,GAAG,GAAG;CAC5F;CAEA,UAAiB,IAAY,QAAQ,KAAK;EACxC,IAAI,CAAC,QAAQ,OACX;EAGF,OAAO,UAAU,MAAM,KAAK,IAAI,GAAG,OAAe;GAChD,KAAK,KAAK,IAAI,GAAG;GACjB,KAAK;EACP,GAAG,KAAK;CACV;CAEA,UAAkB,MAAc;EAC9B,MAAM,IAAI,IAAI,KAAK,IAAI;EACvB,OAAO,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,GAAG,EAAE,gBAAgB,IAAI,SAAS,GAAG,GAAG;CACxG;AACF;AAEA,MAAa,OAAO,IAAI,YAAY"}
|
package/dist/runtime.esm.js
CHANGED
|
@@ -254,70 +254,68 @@ var RuntimeCache = class {
|
|
|
254
254
|
//#region src/bom/history.ts
|
|
255
255
|
const cache$1 = new RuntimeCache("history");
|
|
256
256
|
var TaroHistory = class extends Events {
|
|
257
|
-
#location;
|
|
258
|
-
#stack = [];
|
|
259
|
-
#cur = 0;
|
|
260
|
-
#window;
|
|
261
257
|
constructor(location, options) {
|
|
262
258
|
super();
|
|
263
|
-
this
|
|
264
|
-
this
|
|
265
|
-
this
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
this
|
|
259
|
+
this._stack = [];
|
|
260
|
+
this._cur = 0;
|
|
261
|
+
this._window = options.window;
|
|
262
|
+
this._location = location;
|
|
263
|
+
this._location.on("__record_history__", (href) => {
|
|
264
|
+
this._cur++;
|
|
265
|
+
this._stack = this._stack.slice(0, this._cur);
|
|
266
|
+
this._stack.push({
|
|
269
267
|
state: null,
|
|
270
268
|
title: "",
|
|
271
269
|
url: href
|
|
272
270
|
});
|
|
273
271
|
}, null);
|
|
274
|
-
this
|
|
275
|
-
this
|
|
272
|
+
this._location.on("__reset_history__", (href) => {
|
|
273
|
+
this._reset(href);
|
|
276
274
|
}, null);
|
|
277
275
|
this.on("0", () => {
|
|
278
|
-
this
|
|
276
|
+
this._reset();
|
|
279
277
|
}, null);
|
|
280
278
|
this.on("1", (pageId) => {
|
|
281
279
|
cache$1.set(pageId, {
|
|
282
|
-
location: this
|
|
283
|
-
stack: this
|
|
284
|
-
cur: this
|
|
280
|
+
location: this._location,
|
|
281
|
+
stack: this._stack.slice(),
|
|
282
|
+
cur: this._cur
|
|
285
283
|
});
|
|
286
284
|
}, null);
|
|
287
285
|
this.on("2", (pageId) => {
|
|
288
286
|
if (cache$1.has(pageId)) {
|
|
289
287
|
const ctx = cache$1.get(pageId);
|
|
290
|
-
this
|
|
291
|
-
this
|
|
292
|
-
this
|
|
288
|
+
this._location = ctx.location;
|
|
289
|
+
this._stack = ctx.stack;
|
|
290
|
+
this._cur = ctx.cur;
|
|
293
291
|
}
|
|
294
292
|
}, null);
|
|
295
293
|
this.on("3", (pageId) => {
|
|
296
294
|
cache$1.delete(pageId);
|
|
297
295
|
}, null);
|
|
298
|
-
this
|
|
296
|
+
this._reset();
|
|
299
297
|
}
|
|
300
|
-
|
|
301
|
-
this
|
|
298
|
+
_reset(href = "") {
|
|
299
|
+
this._stack = [{
|
|
302
300
|
state: null,
|
|
303
301
|
title: "",
|
|
304
|
-
url: href || this
|
|
302
|
+
url: href || this._location.href
|
|
305
303
|
}];
|
|
306
|
-
this
|
|
304
|
+
this._cur = 0;
|
|
307
305
|
}
|
|
308
306
|
get length() {
|
|
309
|
-
return this
|
|
307
|
+
return this._stack.length;
|
|
310
308
|
}
|
|
311
309
|
get state() {
|
|
312
|
-
return this
|
|
310
|
+
return this._stack[this._cur].state;
|
|
313
311
|
}
|
|
314
312
|
go(delta) {
|
|
315
313
|
if (!isNumber(delta) || isNaN(delta)) return;
|
|
316
|
-
let targetIdx = this
|
|
314
|
+
let targetIdx = this._cur + delta;
|
|
317
315
|
targetIdx = Math.min(Math.max(targetIdx, 0), this.length - 1);
|
|
318
|
-
this
|
|
319
|
-
this
|
|
320
|
-
this
|
|
316
|
+
this._cur = targetIdx;
|
|
317
|
+
this._location.trigger("__set_href_without_history__", this._stack[this._cur].url);
|
|
318
|
+
this._window.trigger("popstate", this._stack[this._cur]);
|
|
321
319
|
}
|
|
322
320
|
back() {
|
|
323
321
|
this.go(-1);
|
|
@@ -327,23 +325,23 @@ var TaroHistory = class extends Events {
|
|
|
327
325
|
}
|
|
328
326
|
pushState(state, title, url) {
|
|
329
327
|
if (!url || !isString(url)) return;
|
|
330
|
-
this
|
|
331
|
-
this
|
|
328
|
+
this._stack = this._stack.slice(0, this._cur + 1);
|
|
329
|
+
this._stack.push({
|
|
332
330
|
state,
|
|
333
331
|
title,
|
|
334
332
|
url
|
|
335
333
|
});
|
|
336
|
-
this
|
|
337
|
-
this
|
|
334
|
+
this._cur = this.length - 1;
|
|
335
|
+
this._location.trigger("__set_href_without_history__", url);
|
|
338
336
|
}
|
|
339
337
|
replaceState(state, title, url) {
|
|
340
338
|
if (!url || !isString(url)) return;
|
|
341
|
-
this
|
|
339
|
+
this._stack[this._cur] = {
|
|
342
340
|
state,
|
|
343
341
|
title,
|
|
344
342
|
url
|
|
345
343
|
};
|
|
346
|
-
this
|
|
344
|
+
this._location.trigger("__set_href_without_history__", url);
|
|
347
345
|
}
|
|
348
346
|
get cache() {
|
|
349
347
|
return cache$1;
|
|
@@ -389,10 +387,10 @@ function encode(str) {
|
|
|
389
387
|
return encodeURIComponent(str).replace(findReg, replacer);
|
|
390
388
|
}
|
|
391
389
|
const URLSearchParams = process.env.TARO_PLATFORM === "web" ? env.window.URLSearchParams : class {
|
|
392
|
-
#dict = Object.create(null);
|
|
393
390
|
constructor(query) {
|
|
391
|
+
this._dict = Object.create(null);
|
|
394
392
|
query ??= "";
|
|
395
|
-
const dict = this
|
|
393
|
+
const dict = this._dict;
|
|
396
394
|
if (typeof query === "string") {
|
|
397
395
|
if (query.charAt(0) === "?") query = query.slice(1);
|
|
398
396
|
for (let pairs = query.split("&"), i = 0, length = pairs.length; i < length; i++) {
|
|
@@ -413,30 +411,30 @@ const URLSearchParams = process.env.TARO_PLATFORM === "web" ? env.window.URLSear
|
|
|
413
411
|
else for (const key in query) appendTo(dict, key, query[key]);
|
|
414
412
|
}
|
|
415
413
|
append(name, value) {
|
|
416
|
-
appendTo(this
|
|
414
|
+
appendTo(this._dict, name, value);
|
|
417
415
|
}
|
|
418
416
|
delete(name) {
|
|
419
|
-
delete this
|
|
417
|
+
delete this._dict[name];
|
|
420
418
|
}
|
|
421
419
|
get(name) {
|
|
422
|
-
const dict = this
|
|
420
|
+
const dict = this._dict;
|
|
423
421
|
return name in dict ? dict[name][0] : null;
|
|
424
422
|
}
|
|
425
423
|
getAll(name) {
|
|
426
|
-
const dict = this
|
|
424
|
+
const dict = this._dict;
|
|
427
425
|
return name in dict ? dict[name].slice(0) : [];
|
|
428
426
|
}
|
|
429
427
|
has(name) {
|
|
430
|
-
return name in this
|
|
428
|
+
return name in this._dict;
|
|
431
429
|
}
|
|
432
430
|
keys() {
|
|
433
|
-
return Object.keys(this
|
|
431
|
+
return Object.keys(this._dict);
|
|
434
432
|
}
|
|
435
433
|
set(name, value) {
|
|
436
|
-
this
|
|
434
|
+
this._dict[name] = ["" + value];
|
|
437
435
|
}
|
|
438
436
|
forEach(callback, thisArg) {
|
|
439
|
-
const dict = this
|
|
437
|
+
const dict = this._dict;
|
|
440
438
|
Object.getOwnPropertyNames(dict).forEach(function(name) {
|
|
441
439
|
dict[name].forEach(function(value) {
|
|
442
440
|
callback.call(thisArg, value, name, this);
|
|
@@ -447,7 +445,7 @@ const URLSearchParams = process.env.TARO_PLATFORM === "web" ? env.window.URLSear
|
|
|
447
445
|
return {};
|
|
448
446
|
}
|
|
449
447
|
toString() {
|
|
450
|
-
const dict = this
|
|
448
|
+
const dict = this._dict;
|
|
451
449
|
const query = [];
|
|
452
450
|
for (const key in dict) {
|
|
453
451
|
const name = encode(key);
|
|
@@ -465,27 +463,26 @@ var TaroURL = class {
|
|
|
465
463
|
static revokeObjectURL() {
|
|
466
464
|
throw new Error("Oops, not support URL.revokeObjectURL() in miniprogram.");
|
|
467
465
|
}
|
|
468
|
-
#hash = "";
|
|
469
|
-
#hostname = "";
|
|
470
|
-
#pathname = "";
|
|
471
|
-
#port = "";
|
|
472
|
-
#protocol = "";
|
|
473
|
-
#search;
|
|
474
466
|
constructor(url, base) {
|
|
467
|
+
this._hash = "";
|
|
468
|
+
this._hostname = "";
|
|
469
|
+
this._pathname = "";
|
|
470
|
+
this._port = "";
|
|
471
|
+
this._protocol = "";
|
|
475
472
|
if (!isString(url)) url = String(url);
|
|
476
473
|
const { hash, hostname, pathname, port, protocol, search } = parseUrlBase(url, base);
|
|
477
|
-
this
|
|
478
|
-
this
|
|
479
|
-
this
|
|
480
|
-
this
|
|
481
|
-
this
|
|
482
|
-
this
|
|
474
|
+
this._hash = hash;
|
|
475
|
+
this._hostname = hostname;
|
|
476
|
+
this._pathname = pathname || "/";
|
|
477
|
+
this._port = port;
|
|
478
|
+
this._protocol = protocol;
|
|
479
|
+
this._search = new URLSearchParams(search);
|
|
483
480
|
}
|
|
484
481
|
get protocol() {
|
|
485
|
-
return this
|
|
482
|
+
return this._protocol;
|
|
486
483
|
}
|
|
487
484
|
set protocol(val) {
|
|
488
|
-
isString(val) && (this
|
|
485
|
+
isString(val) && (this._protocol = val.trim());
|
|
489
486
|
}
|
|
490
487
|
get host() {
|
|
491
488
|
return this.hostname + (this.port ? ":" + this.port : "");
|
|
@@ -499,19 +496,19 @@ var TaroURL = class {
|
|
|
499
496
|
}
|
|
500
497
|
}
|
|
501
498
|
get hostname() {
|
|
502
|
-
return this
|
|
499
|
+
return this._hostname;
|
|
503
500
|
}
|
|
504
501
|
set hostname(val) {
|
|
505
|
-
val && isString(val) && (this
|
|
502
|
+
val && isString(val) && (this._hostname = val.trim());
|
|
506
503
|
}
|
|
507
504
|
get port() {
|
|
508
|
-
return this
|
|
505
|
+
return this._port;
|
|
509
506
|
}
|
|
510
507
|
set port(val) {
|
|
511
|
-
isString(val) && (this
|
|
508
|
+
isString(val) && (this._port = val.trim());
|
|
512
509
|
}
|
|
513
510
|
get pathname() {
|
|
514
|
-
return this
|
|
511
|
+
return this._pathname;
|
|
515
512
|
}
|
|
516
513
|
set pathname(val) {
|
|
517
514
|
if (isString(val)) {
|
|
@@ -519,28 +516,28 @@ var TaroURL = class {
|
|
|
519
516
|
const HEAD_REG = /^(\/|\.\/|\.\.\/)/;
|
|
520
517
|
let temp = val;
|
|
521
518
|
while (HEAD_REG.test(temp)) temp = temp.replace(HEAD_REG, "");
|
|
522
|
-
if (temp) this
|
|
523
|
-
else this
|
|
519
|
+
if (temp) this._pathname = "/" + temp;
|
|
520
|
+
else this._pathname = "/";
|
|
524
521
|
}
|
|
525
522
|
}
|
|
526
523
|
get search() {
|
|
527
|
-
const val = this
|
|
524
|
+
const val = this._search.toString();
|
|
528
525
|
return val.length === 0 || val.startsWith("?") ? val : `?${val}`;
|
|
529
526
|
}
|
|
530
527
|
set search(val) {
|
|
531
528
|
if (isString(val)) {
|
|
532
529
|
val = val.trim();
|
|
533
|
-
this
|
|
530
|
+
this._search = new URLSearchParams(val);
|
|
534
531
|
}
|
|
535
532
|
}
|
|
536
533
|
get hash() {
|
|
537
|
-
return this
|
|
534
|
+
return this._hash;
|
|
538
535
|
}
|
|
539
536
|
set hash(val) {
|
|
540
537
|
if (isString(val)) {
|
|
541
538
|
val = val.trim();
|
|
542
|
-
if (val) this
|
|
543
|
-
else this
|
|
539
|
+
if (val) this._hash = val.startsWith("#") ? val : `#${val}`;
|
|
540
|
+
else this._hash = "";
|
|
544
541
|
}
|
|
545
542
|
}
|
|
546
543
|
get href() {
|
|
@@ -571,7 +568,7 @@ var TaroURL = class {
|
|
|
571
568
|
}
|
|
572
569
|
}
|
|
573
570
|
get searchParams() {
|
|
574
|
-
return this
|
|
571
|
+
return this._search;
|
|
575
572
|
}
|
|
576
573
|
toString() {
|
|
577
574
|
return this.href;
|
|
@@ -643,22 +640,21 @@ function parseUrlBase(url, base) {
|
|
|
643
640
|
const INIT_URL = "https://taro.com";
|
|
644
641
|
const cache = new RuntimeCache("location");
|
|
645
642
|
var TaroLocation = class extends Events {
|
|
646
|
-
#url = new TaroURLProvider(INIT_URL);
|
|
647
|
-
#noCheckUrl = false;
|
|
648
|
-
#window;
|
|
649
643
|
constructor(options) {
|
|
650
644
|
super();
|
|
651
|
-
this
|
|
652
|
-
this
|
|
645
|
+
this._url = new TaroURLProvider(INIT_URL);
|
|
646
|
+
this._noCheckUrl = false;
|
|
647
|
+
this._window = options.window;
|
|
648
|
+
this._reset();
|
|
653
649
|
this.on("__set_href_without_history__", (href) => {
|
|
654
|
-
this
|
|
655
|
-
const lastHash = this
|
|
656
|
-
this
|
|
657
|
-
if (lastHash !== this
|
|
658
|
-
this
|
|
650
|
+
this._noCheckUrl = true;
|
|
651
|
+
const lastHash = this._url.hash;
|
|
652
|
+
this._url.href = generateFullUrl(href);
|
|
653
|
+
if (lastHash !== this._url.hash) this._window.trigger("hashchange");
|
|
654
|
+
this._noCheckUrl = false;
|
|
659
655
|
}, null);
|
|
660
656
|
this.on("0", () => {
|
|
661
|
-
this
|
|
657
|
+
this._reset();
|
|
662
658
|
}, null);
|
|
663
659
|
this.on("1", (pageId) => {
|
|
664
660
|
cache.set(pageId, { lastHref: this.href });
|
|
@@ -666,16 +662,16 @@ var TaroLocation = class extends Events {
|
|
|
666
662
|
this.on("2", (pageId) => {
|
|
667
663
|
if (cache.has(pageId)) {
|
|
668
664
|
const ctx = cache.get(pageId);
|
|
669
|
-
this
|
|
670
|
-
this
|
|
671
|
-
this
|
|
665
|
+
this._noCheckUrl = true;
|
|
666
|
+
this._url.href = ctx.lastHref;
|
|
667
|
+
this._noCheckUrl = false;
|
|
672
668
|
}
|
|
673
669
|
}, null);
|
|
674
670
|
this.on("3", (pageId) => {
|
|
675
671
|
cache.delete(pageId);
|
|
676
672
|
}, null);
|
|
677
673
|
}
|
|
678
|
-
|
|
674
|
+
_reset() {
|
|
679
675
|
const router = getCurrentInstance().router;
|
|
680
676
|
if (router) {
|
|
681
677
|
const { path, params } = router;
|
|
@@ -684,127 +680,127 @@ var TaroLocation = class extends Events {
|
|
|
684
680
|
});
|
|
685
681
|
const searchStr = searchArr.length > 0 ? "?" + searchArr.join("&") : "";
|
|
686
682
|
const url = `${INIT_URL}${path.startsWith("/") ? path : "/" + path}${searchStr}`;
|
|
687
|
-
this
|
|
683
|
+
this._url = new TaroURLProvider(url);
|
|
688
684
|
this.trigger("__reset_history__", this.href);
|
|
689
685
|
}
|
|
690
686
|
}
|
|
691
|
-
|
|
692
|
-
return this
|
|
687
|
+
_getPreValue() {
|
|
688
|
+
return this._url._toRaw();
|
|
693
689
|
}
|
|
694
|
-
|
|
695
|
-
this
|
|
690
|
+
_rollBack(href) {
|
|
691
|
+
this._url.href = href;
|
|
696
692
|
}
|
|
697
|
-
|
|
693
|
+
_recordHistory() {
|
|
698
694
|
this.trigger("__record_history__", this.href);
|
|
699
695
|
}
|
|
700
696
|
/**
|
|
701
697
|
* 校验url的变化,是否需要更新history
|
|
702
698
|
*/
|
|
703
|
-
|
|
704
|
-
if (this
|
|
705
|
-
const { protocol, hostname, port, pathname, search, hash } = this
|
|
699
|
+
_checkUrlChange(preValue) {
|
|
700
|
+
if (this._noCheckUrl) return false;
|
|
701
|
+
const { protocol, hostname, port, pathname, search, hash } = this._url._toRaw();
|
|
706
702
|
if (protocol !== preValue.protocol || hostname !== preValue.hostname || port !== preValue.port) {
|
|
707
|
-
this
|
|
703
|
+
this._rollBack(preValue.href);
|
|
708
704
|
return false;
|
|
709
705
|
}
|
|
710
706
|
if (pathname !== preValue.pathname) return true;
|
|
711
707
|
if (search !== preValue.search) return true;
|
|
712
708
|
if (hash !== preValue.hash) {
|
|
713
|
-
this
|
|
709
|
+
this._window.trigger("hashchange");
|
|
714
710
|
return true;
|
|
715
711
|
}
|
|
716
|
-
this
|
|
712
|
+
this._rollBack(preValue.href);
|
|
717
713
|
return false;
|
|
718
714
|
}
|
|
719
715
|
get protocol() {
|
|
720
|
-
return this
|
|
716
|
+
return this._url.protocol;
|
|
721
717
|
}
|
|
722
718
|
set protocol(val) {
|
|
723
719
|
if (!val || !isString(val) || !/^(http|https):$/i.test(val.trim())) return;
|
|
724
720
|
val = val.trim();
|
|
725
|
-
const preValue = this
|
|
726
|
-
this
|
|
727
|
-
if (this
|
|
721
|
+
const preValue = this._getPreValue();
|
|
722
|
+
this._url.protocol = val;
|
|
723
|
+
if (this._checkUrlChange(preValue)) this._recordHistory();
|
|
728
724
|
}
|
|
729
725
|
get host() {
|
|
730
|
-
return this
|
|
726
|
+
return this._url.host;
|
|
731
727
|
}
|
|
732
728
|
set host(val) {
|
|
733
729
|
if (!val || !isString(val)) return;
|
|
734
730
|
val = val.trim();
|
|
735
|
-
const preValue = this
|
|
736
|
-
this
|
|
737
|
-
if (this
|
|
731
|
+
const preValue = this._getPreValue();
|
|
732
|
+
this._url.host = val;
|
|
733
|
+
if (this._checkUrlChange(preValue)) this._recordHistory();
|
|
738
734
|
}
|
|
739
735
|
get hostname() {
|
|
740
|
-
return this
|
|
736
|
+
return this._url.hostname;
|
|
741
737
|
}
|
|
742
738
|
set hostname(val) {
|
|
743
739
|
if (!val || !isString(val)) return;
|
|
744
740
|
val = val.trim();
|
|
745
|
-
const preValue = this
|
|
746
|
-
this
|
|
747
|
-
if (this
|
|
741
|
+
const preValue = this._getPreValue();
|
|
742
|
+
this._url.hostname = val;
|
|
743
|
+
if (this._checkUrlChange(preValue)) this._recordHistory();
|
|
748
744
|
}
|
|
749
745
|
get port() {
|
|
750
|
-
return this
|
|
746
|
+
return this._url.port;
|
|
751
747
|
}
|
|
752
748
|
set port(val) {
|
|
753
749
|
const xVal = Number(val = val.trim());
|
|
754
750
|
if (!isNumber(xVal) || xVal <= 0) return;
|
|
755
|
-
const preValue = this
|
|
756
|
-
this
|
|
757
|
-
if (this
|
|
751
|
+
const preValue = this._getPreValue();
|
|
752
|
+
this._url.port = val;
|
|
753
|
+
if (this._checkUrlChange(preValue)) this._recordHistory();
|
|
758
754
|
}
|
|
759
755
|
get pathname() {
|
|
760
|
-
return this
|
|
756
|
+
return this._url.pathname;
|
|
761
757
|
}
|
|
762
758
|
set pathname(val) {
|
|
763
759
|
if (!val || !isString(val)) return;
|
|
764
760
|
val = val.trim();
|
|
765
|
-
const preValue = this
|
|
766
|
-
this
|
|
767
|
-
if (this
|
|
761
|
+
const preValue = this._getPreValue();
|
|
762
|
+
this._url.pathname = val;
|
|
763
|
+
if (this._checkUrlChange(preValue)) this._recordHistory();
|
|
768
764
|
}
|
|
769
765
|
get search() {
|
|
770
|
-
return this
|
|
766
|
+
return this._url.search;
|
|
771
767
|
}
|
|
772
768
|
set search(val) {
|
|
773
769
|
if (!val || !isString(val)) return;
|
|
774
770
|
val = val.trim();
|
|
775
771
|
val = val.startsWith("?") ? val : `?${val}`;
|
|
776
|
-
const preValue = this
|
|
777
|
-
this
|
|
778
|
-
if (this
|
|
772
|
+
const preValue = this._getPreValue();
|
|
773
|
+
this._url.search = val;
|
|
774
|
+
if (this._checkUrlChange(preValue)) this._recordHistory();
|
|
779
775
|
}
|
|
780
776
|
get hash() {
|
|
781
|
-
return this
|
|
777
|
+
return this._url.hash;
|
|
782
778
|
}
|
|
783
779
|
set hash(val) {
|
|
784
780
|
if (!val || !isString(val)) return;
|
|
785
781
|
val = val.trim();
|
|
786
782
|
val = val.startsWith("#") ? val : `#${val}`;
|
|
787
|
-
const preValue = this
|
|
788
|
-
this
|
|
789
|
-
if (this
|
|
783
|
+
const preValue = this._getPreValue();
|
|
784
|
+
this._url.hash = val;
|
|
785
|
+
if (this._checkUrlChange(preValue)) this._recordHistory();
|
|
790
786
|
}
|
|
791
787
|
get href() {
|
|
792
|
-
return this
|
|
788
|
+
return this._url.href;
|
|
793
789
|
}
|
|
794
790
|
set href(val) {
|
|
795
791
|
if (!val || !isString(val) || !/^(http:|https:)?\/\/.+/.test(val = val.trim())) return;
|
|
796
|
-
const preValue = this
|
|
797
|
-
this
|
|
798
|
-
if (this
|
|
792
|
+
const preValue = this._getPreValue();
|
|
793
|
+
this._url.href = val;
|
|
794
|
+
if (this._checkUrlChange(preValue)) this._recordHistory();
|
|
799
795
|
}
|
|
800
796
|
get origin() {
|
|
801
|
-
return this
|
|
797
|
+
return this._url.origin;
|
|
802
798
|
}
|
|
803
799
|
set origin(val) {
|
|
804
800
|
if (!val || !isString(val) || !/^(http:|https:)?\/\/.+/.test(val = val.trim())) return;
|
|
805
|
-
const preValue = this
|
|
806
|
-
this
|
|
807
|
-
if (this
|
|
801
|
+
const preValue = this._getPreValue();
|
|
802
|
+
this._url.origin = val;
|
|
803
|
+
if (this._checkUrlChange(preValue)) this._recordHistory();
|
|
808
804
|
}
|
|
809
805
|
assign() {
|
|
810
806
|
warn(true, "小程序环境中调用location.assign()无效.");
|
|
@@ -2383,7 +2379,7 @@ var Performance = class {
|
|
|
2383
2379
|
if (!(prev >= 0)) return;
|
|
2384
2380
|
this.recorder.delete(id);
|
|
2385
2381
|
const time = now - prev;
|
|
2386
|
-
console.log(`${id} 时长: ${time}ms 开始时间:${this
|
|
2382
|
+
console.log(`${id} 时长: ${time}ms 开始时间:${this.parseTime(prev)} 结束时间:${this.parseTime(now)}`);
|
|
2387
2383
|
}
|
|
2388
2384
|
delayStop(id, delay = 500) {
|
|
2389
2385
|
if (!options.debug) return;
|
|
@@ -2392,7 +2388,7 @@ var Performance = class {
|
|
|
2392
2388
|
cb?.();
|
|
2393
2389
|
}, delay);
|
|
2394
2390
|
}
|
|
2395
|
-
|
|
2391
|
+
parseTime(time) {
|
|
2396
2392
|
const d = new Date(time);
|
|
2397
2393
|
return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${`${d.getMilliseconds()}`.padStart(3, "0")}`;
|
|
2398
2394
|
}
|