@spcsn/taro-runtime 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/assertClassBrand.js +7 -0
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/checkPrivateRedeclaration.js +6 -0
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/classPrivateFieldGet2.js +7 -0
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/classPrivateFieldInitSpec.js +7 -0
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/classPrivateFieldSet2.js +7 -0
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/classPrivateMethodInitSpec.js +7 -0
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/defineProperty.js +12 -0
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/objectSpread2.js +25 -0
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/toPrimitive.js +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/toPropertyKey.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/typeof.js +11 -0
- package/dist/bom/URL.d.ts +1 -6
- package/dist/bom/URL.js +36 -26
- package/dist/bom/URL.js.map +1 -1
- package/dist/bom/URLSearchParams.js +18 -14
- package/dist/bom/URLSearchParams.js.map +1 -1
- package/dist/bom/document.js +3 -2
- package/dist/bom/document.js.map +1 -1
- package/dist/bom/history.d.ts +1 -5
- package/dist/bom/history.js +52 -38
- package/dist/bom/history.js.map +1 -1
- package/dist/bom/location.d.ts +1 -11
- package/dist/bom/location.js +101 -90
- package/dist/bom/location.js.map +1 -1
- package/dist/bom/window.js +1 -1
- package/dist/bom/window.js.map +1 -1
- package/dist/dom/anchor-element.js +16 -8
- package/dist/dom/anchor-element.js.map +1 -1
- package/dist/dom/class-list.js.map +1 -1
- package/dist/dom/document.js.map +1 -1
- package/dist/dom/element.js +2 -1
- package/dist/dom/element.js.map +1 -1
- package/dist/dom/event-target.js +2 -4
- package/dist/dom/event-target.js.map +1 -1
- package/dist/dom/event.js +18 -17
- package/dist/dom/event.js.map +1 -1
- package/dist/dom/form.js +2 -1
- package/dist/dom/form.js.map +1 -1
- package/dist/dom/node.js +9 -6
- package/dist/dom/node.js.map +1 -1
- package/dist/dom/root.js +2 -4
- package/dist/dom/root.js.map +1 -1
- package/dist/dom/text.js.map +1 -1
- package/dist/dom/transfer.js.map +1 -1
- package/dist/dom/tree.js +1 -1
- package/dist/dom/tree.js.map +1 -1
- package/dist/dom-external/mutation-observer/implements.js +1 -1
- package/dist/dom-external/mutation-observer/implements.js.map +1 -1
- package/dist/dsl/common.js +21 -18
- package/dist/dsl/common.js.map +1 -1
- package/dist/hydrate.js +10 -7
- package/dist/hydrate.js.map +1 -1
- package/dist/index.cjs.js +392 -256
- package/dist/index.cjs.js.map +1 -1
- package/dist/next-tick.js +6 -4
- package/dist/next-tick.js.map +1 -1
- package/dist/perf.d.ts +1 -1
- package/dist/perf.js +10 -6
- package/dist/perf.js.map +1 -1
- package/dist/runtime.esm.js +392 -256
- package/dist/runtime.esm.js.map +1 -1
- package/dist/utils/cache.js.map +1 -1
- package/dist/utils/index.js +9 -6
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/router.js +2 -1
- package/dist/utils/router.js.map +1 -1
- package/package.json +2 -2
package/dist/bom/history.js
CHANGED
|
@@ -2,72 +2,78 @@ import "../constants/index.js";
|
|
|
2
2
|
import { Events } from "../emitter/emitter.js";
|
|
3
3
|
import env from "../env.js";
|
|
4
4
|
import { RuntimeCache } from "../utils/cache.js";
|
|
5
|
+
import { _classPrivateMethodInitSpec } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/classPrivateMethodInitSpec.js";
|
|
6
|
+
import { _classPrivateFieldInitSpec } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/classPrivateFieldInitSpec.js";
|
|
7
|
+
import { _assertClassBrand } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/assertClassBrand.js";
|
|
8
|
+
import { _classPrivateFieldSet2 } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/classPrivateFieldSet2.js";
|
|
9
|
+
import { _classPrivateFieldGet2 } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/classPrivateFieldGet2.js";
|
|
5
10
|
import { isNumber, isString } from "@spcsn/taro-shared";
|
|
6
11
|
//#region src/bom/history.ts
|
|
7
12
|
const cache = new RuntimeCache("history");
|
|
13
|
+
var _location = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
var _stack = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
var _cur = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
var _window = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
var _TaroHistory_brand = /* @__PURE__ */ new WeakSet();
|
|
8
18
|
var TaroHistory = class extends Events {
|
|
9
19
|
constructor(location, options) {
|
|
10
20
|
super();
|
|
11
|
-
this
|
|
12
|
-
this
|
|
13
|
-
this
|
|
14
|
-
this
|
|
15
|
-
this
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
_classPrivateMethodInitSpec(this, _TaroHistory_brand);
|
|
22
|
+
_classPrivateFieldInitSpec(this, _location, void 0);
|
|
23
|
+
_classPrivateFieldInitSpec(this, _stack, []);
|
|
24
|
+
_classPrivateFieldInitSpec(this, _cur, 0);
|
|
25
|
+
_classPrivateFieldInitSpec(this, _window, void 0);
|
|
26
|
+
_classPrivateFieldSet2(_window, this, options.window);
|
|
27
|
+
_classPrivateFieldSet2(_location, this, location);
|
|
28
|
+
_classPrivateFieldGet2(_location, this).on("__record_history__", (href) => {
|
|
29
|
+
var _this$cur;
|
|
30
|
+
_classPrivateFieldSet2(_cur, this, (_this$cur = _classPrivateFieldGet2(_cur, this), _this$cur++, _this$cur));
|
|
31
|
+
_classPrivateFieldSet2(_stack, this, _classPrivateFieldGet2(_stack, this).slice(0, _classPrivateFieldGet2(_cur, this)));
|
|
32
|
+
_classPrivateFieldGet2(_stack, this).push({
|
|
19
33
|
state: null,
|
|
20
34
|
title: "",
|
|
21
35
|
url: href
|
|
22
36
|
});
|
|
23
37
|
}, null);
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
38
|
+
_classPrivateFieldGet2(_location, this).on("__reset_history__", (href) => {
|
|
39
|
+
_assertClassBrand(_TaroHistory_brand, this, _reset).call(this, href);
|
|
26
40
|
}, null);
|
|
27
41
|
this.on("0", () => {
|
|
28
|
-
this.
|
|
42
|
+
_assertClassBrand(_TaroHistory_brand, this, _reset).call(this);
|
|
29
43
|
}, null);
|
|
30
44
|
this.on("1", (pageId) => {
|
|
31
45
|
cache.set(pageId, {
|
|
32
|
-
location:
|
|
33
|
-
stack: this.
|
|
34
|
-
cur: this
|
|
46
|
+
location: _classPrivateFieldGet2(_location, this),
|
|
47
|
+
stack: _classPrivateFieldGet2(_stack, this).slice(),
|
|
48
|
+
cur: _classPrivateFieldGet2(_cur, this)
|
|
35
49
|
});
|
|
36
50
|
}, null);
|
|
37
51
|
this.on("2", (pageId) => {
|
|
38
52
|
if (cache.has(pageId)) {
|
|
39
53
|
const ctx = cache.get(pageId);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
_classPrivateFieldSet2(_location, this, ctx.location);
|
|
55
|
+
_classPrivateFieldSet2(_stack, this, ctx.stack);
|
|
56
|
+
_classPrivateFieldSet2(_cur, this, ctx.cur);
|
|
43
57
|
}
|
|
44
58
|
}, null);
|
|
45
59
|
this.on("3", (pageId) => {
|
|
46
60
|
cache.delete(pageId);
|
|
47
61
|
}, null);
|
|
48
|
-
this.
|
|
49
|
-
}
|
|
50
|
-
_reset(href = "") {
|
|
51
|
-
this._stack = [{
|
|
52
|
-
state: null,
|
|
53
|
-
title: "",
|
|
54
|
-
url: href || this._location.href
|
|
55
|
-
}];
|
|
56
|
-
this._cur = 0;
|
|
62
|
+
_assertClassBrand(_TaroHistory_brand, this, _reset).call(this);
|
|
57
63
|
}
|
|
58
64
|
get length() {
|
|
59
|
-
return this.
|
|
65
|
+
return _classPrivateFieldGet2(_stack, this).length;
|
|
60
66
|
}
|
|
61
67
|
get state() {
|
|
62
|
-
return this
|
|
68
|
+
return _classPrivateFieldGet2(_stack, this)[_classPrivateFieldGet2(_cur, this)].state;
|
|
63
69
|
}
|
|
64
70
|
go(delta) {
|
|
65
71
|
if (!isNumber(delta) || isNaN(delta)) return;
|
|
66
|
-
let targetIdx =
|
|
72
|
+
let targetIdx = _classPrivateFieldGet2(_cur, this) + delta;
|
|
67
73
|
targetIdx = Math.min(Math.max(targetIdx, 0), this.length - 1);
|
|
68
|
-
|
|
69
|
-
this.
|
|
70
|
-
this.
|
|
74
|
+
_classPrivateFieldSet2(_cur, this, targetIdx);
|
|
75
|
+
_classPrivateFieldGet2(_location, this).trigger("__set_href_without_history__", _classPrivateFieldGet2(_stack, this)[_classPrivateFieldGet2(_cur, this)].url);
|
|
76
|
+
_classPrivateFieldGet2(_window, this).trigger("popstate", _classPrivateFieldGet2(_stack, this)[_classPrivateFieldGet2(_cur, this)]);
|
|
71
77
|
}
|
|
72
78
|
back() {
|
|
73
79
|
this.go(-1);
|
|
@@ -77,28 +83,36 @@ var TaroHistory = class extends Events {
|
|
|
77
83
|
}
|
|
78
84
|
pushState(state, title, url) {
|
|
79
85
|
if (!url || !isString(url)) return;
|
|
80
|
-
this
|
|
81
|
-
this.
|
|
86
|
+
_classPrivateFieldSet2(_stack, this, _classPrivateFieldGet2(_stack, this).slice(0, _classPrivateFieldGet2(_cur, this) + 1));
|
|
87
|
+
_classPrivateFieldGet2(_stack, this).push({
|
|
82
88
|
state,
|
|
83
89
|
title,
|
|
84
90
|
url
|
|
85
91
|
});
|
|
86
|
-
|
|
87
|
-
this.
|
|
92
|
+
_classPrivateFieldSet2(_cur, this, this.length - 1);
|
|
93
|
+
_classPrivateFieldGet2(_location, this).trigger("__set_href_without_history__", url);
|
|
88
94
|
}
|
|
89
95
|
replaceState(state, title, url) {
|
|
90
96
|
if (!url || !isString(url)) return;
|
|
91
|
-
this
|
|
97
|
+
_classPrivateFieldGet2(_stack, this)[_classPrivateFieldGet2(_cur, this)] = {
|
|
92
98
|
state,
|
|
93
99
|
title,
|
|
94
100
|
url
|
|
95
101
|
};
|
|
96
|
-
this.
|
|
102
|
+
_classPrivateFieldGet2(_location, this).trigger("__set_href_without_history__", url);
|
|
97
103
|
}
|
|
98
104
|
get cache() {
|
|
99
105
|
return cache;
|
|
100
106
|
}
|
|
101
107
|
};
|
|
108
|
+
function _reset(href = "") {
|
|
109
|
+
_classPrivateFieldSet2(_stack, this, [{
|
|
110
|
+
state: null,
|
|
111
|
+
title: "",
|
|
112
|
+
url: href || _classPrivateFieldGet2(_location, this).href
|
|
113
|
+
}]);
|
|
114
|
+
_classPrivateFieldSet2(_cur, this, 0);
|
|
115
|
+
}
|
|
102
116
|
const History = process.env.TARO_PLATFORM === "web" ? env.window.History : TaroHistory;
|
|
103
117
|
//#endregion
|
|
104
118
|
export { History };
|
package/dist/bom/history.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.js","names":[],"sources":["../../src/bom/history.ts"],"sourcesContent":["import { isNumber, isString } from '@spcsn/taro-shared';\n\nimport { CONTEXT_ACTIONS } from '../constants';\nimport { Events } from '../emitter/emitter';\nimport env from '../env';\nimport { RuntimeCache } from '../utils/cache';\n\nimport type { TaroLocation } from './location';\n\nexport interface HistoryState {\n state: Record<string, any> | null;\n title: string;\n url: string;\n}\n\ntype Options = {\n window: any;\n};\ntype HistoryContext = {\n location: TaroLocation;\n stack: HistoryState[];\n cur: number;\n};\nconst cache = new RuntimeCache<HistoryContext>('history');\n\nclass TaroHistory extends Events {\n /* private property */\n
|
|
1
|
+
{"version":3,"file":"history.js","names":[],"sources":["../../src/bom/history.ts"],"sourcesContent":["import { isNumber, isString } from '@spcsn/taro-shared';\n\nimport { CONTEXT_ACTIONS } from '../constants';\nimport { Events } from '../emitter/emitter';\nimport env from '../env';\nimport { RuntimeCache } from '../utils/cache';\n\nimport type { TaroLocation } from './location';\n\nexport interface HistoryState {\n state: Record<string, any> | null;\n title: string;\n url: string;\n}\n\ntype Options = {\n window: any;\n};\ntype HistoryContext = {\n location: TaroLocation;\n stack: HistoryState[];\n cur: number;\n};\nconst cache = new RuntimeCache<HistoryContext>('history');\n\nclass TaroHistory extends Events {\n /* private property */\n #location: TaroLocation;\n #stack: HistoryState[] = [];\n #cur = 0;\n\n #window: any;\n\n constructor(location: TaroLocation, options: Options) {\n super();\n\n this.#window = options.window;\n this.#location = location;\n\n this.#location.on(\n '__record_history__',\n (href: string) => {\n this.#cur++;\n this.#stack = this.#stack.slice(0, this.#cur);\n this.#stack.push({\n state: null,\n title: '',\n url: href,\n });\n },\n null,\n );\n\n this.#location.on(\n '__reset_history__',\n (href: string) => {\n this.#reset(href);\n },\n null,\n );\n\n // 切换上下文行为\n\n this.on(\n CONTEXT_ACTIONS.INIT,\n () => {\n this.#reset();\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RESTORE,\n (pageId: string) => {\n cache.set(pageId, {\n location: this.#location,\n stack: this.#stack.slice(),\n cur: this.#cur,\n });\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RECOVER,\n (pageId: string) => {\n if (cache.has(pageId)) {\n const ctx = cache.get(pageId)!;\n this.#location = ctx.location;\n this.#stack = ctx.stack;\n this.#cur = ctx.cur;\n }\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.DESTROY,\n (pageId: string) => {\n cache.delete(pageId);\n },\n null,\n );\n\n this.#reset();\n }\n\n #reset(href = '') {\n this.#stack = [\n {\n state: null,\n title: '',\n url: href || this.#location.href,\n },\n ];\n this.#cur = 0;\n }\n\n /* public property */\n get length() {\n return this.#stack.length;\n }\n\n get state() {\n return this.#stack[this.#cur].state;\n }\n\n /* public method */\n go(delta: number) {\n if (!isNumber(delta) || isNaN(delta)) return;\n\n let targetIdx = this.#cur + delta;\n targetIdx = Math.min(Math.max(targetIdx, 0), this.length - 1);\n\n this.#cur = targetIdx;\n\n this.#location.trigger('__set_href_without_history__', this.#stack[this.#cur].url);\n this.#window.trigger('popstate', this.#stack[this.#cur]);\n }\n\n back() {\n this.go(-1);\n }\n\n forward() {\n this.go(1);\n }\n\n pushState(state: any, title: string, url: string) {\n if (!url || !isString(url)) return;\n this.#stack = this.#stack.slice(0, this.#cur + 1);\n this.#stack.push({\n state,\n title,\n url,\n });\n this.#cur = this.length - 1;\n\n this.#location.trigger('__set_href_without_history__', url);\n }\n\n replaceState(state: any, title: string, url: string) {\n if (!url || !isString(url)) return;\n this.#stack[this.#cur] = {\n state,\n title,\n url,\n };\n\n this.#location.trigger('__set_href_without_history__', url);\n }\n\n // For debug\n get cache() {\n return cache;\n }\n}\n\nexport type { TaroHistory };\nexport const History: typeof TaroHistory = process.env.TARO_PLATFORM === 'web' ? env.window.History : TaroHistory;\n"],"mappings":";;;;;;;;;;;AAuBA,MAAM,QAAQ,IAAI,aAA6B,SAAS;;;;;;AAExD,IAAM,cAAN,cAA0B,OAAO;CAQ/B,YAAY,UAAwB,SAAkB;EACpD,MAAM;;;2CANiB,CAAC,CAAA;yCACnB,CAAA;;EAOL,uBAAA,SAAA,MAAe,QAAQ,MAAA;EACvB,uBAAA,WAAA,MAAiB,QAAA;EAEjB,uBAAA,WAAA,IAAA,EAAe,GACb,uBACC,SAAiB;;gCAChB,OAAA,YAAA,uBAAA,MAAA,IAAA,GAAA,aAAA,UAAA;GACA,uBAAA,QAAA,MAAA,uBAAA,QAAc,IAAA,EAAY,MAAM,GAAA,uBAAA,MAAG,IAAA,CAAS,CAAA;GAC5C,uBAAA,QAAA,IAAA,EAAY,KAAK;IACf,OAAO;IACP,OAAO;IACP,KAAK;GACP,CAAC;EACH,GACA,IACF;EAEA,uBAAA,WAAA,IAAA,EAAe,GACb,sBACC,SAAiB;GAChB,kBAAA,oBAAA,MAAA,MAAA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MAAY,IAAA,EAAU;CACzD;CAEA,OAAO;EACL,KAAK,GAAG,EAAE;CACZ;CAEA,UAAU;EACR,KAAK,GAAG,CAAC;CACX;CAEA,UAAU,OAAY,OAAe,KAAa;EAChD,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,GAAG;EAC5B,uBAAA,QAAA,MAAA,uBAAA,QAAc,IAAA,EAAY,MAAM,GAAA,uBAAA,MAAG,IAAA,IAAY,CAAC,CAAA;EAChD,uBAAA,QAAA,IAAA,EAAY,KAAK;GACf;GACA;GACA;EACF,CAAC;EACD,uBAAA,MAAA,MAAY,KAAK,SAAS,CAAA;EAE1B,uBAAA,WAAA,IAAA,EAAe,QAAQ,gCAAgC,GAAG;CAC5D;CAEA,aAAa,OAAY,OAAe,KAAa;EACnD,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,GAAG;EAC5B,uBAAA,QAAA,IAAA,EAAA,uBAAA,MAAY,IAAA,KAAa;GACvB;GACA;GACA;EACF;EAEA,uBAAA,WAAA,IAAA,EAAe,QAAQ,gCAAgC,GAAG;CAC5D;CAGA,IAAI,QAAQ;EACV,OAAO;CACT;AACF;AArEE,SAAA,OAAO,OAAO,IAAI;CAChB,uBAAA,QAAA,MAAc,CACZ;EACE,OAAO;EACP,OAAO;EACP,KAAK,QAAA,uBAAA,WAAQ,IAAA,EAAe;CAC9B,CACF,CAAA;CACA,uBAAA,MAAA,MAAY,CAAA;AACd;AA+DF,MAAa,UAA8B,QAAQ,IAAI,kBAAkB,QAAQ,IAAI,OAAO,UAAU"}
|
package/dist/bom/location.d.ts
CHANGED
|
@@ -7,18 +7,8 @@ type LocationContext = {
|
|
|
7
7
|
lastHref: string;
|
|
8
8
|
};
|
|
9
9
|
declare class TaroLocation extends Events {
|
|
10
|
-
private
|
|
11
|
-
private _noCheckUrl;
|
|
12
|
-
private _window;
|
|
10
|
+
#private;
|
|
13
11
|
constructor(options: Options);
|
|
14
|
-
private _reset;
|
|
15
|
-
private _getPreValue;
|
|
16
|
-
private _rollBack;
|
|
17
|
-
private _recordHistory;
|
|
18
|
-
/**
|
|
19
|
-
* 校验url的变化,是否需要更新history
|
|
20
|
-
*/
|
|
21
|
-
private _checkUrlChange;
|
|
22
12
|
get protocol(): string;
|
|
23
13
|
set protocol(val: string);
|
|
24
14
|
get host(): string;
|
package/dist/bom/location.js
CHANGED
|
@@ -2,28 +2,39 @@ import "../constants/index.js";
|
|
|
2
2
|
import { Events } from "../emitter/emitter.js";
|
|
3
3
|
import env from "../env.js";
|
|
4
4
|
import { RuntimeCache } from "../utils/cache.js";
|
|
5
|
+
import { _classPrivateMethodInitSpec } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/classPrivateMethodInitSpec.js";
|
|
6
|
+
import { _classPrivateFieldInitSpec } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/classPrivateFieldInitSpec.js";
|
|
7
|
+
import { _assertClassBrand } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/assertClassBrand.js";
|
|
8
|
+
import { _classPrivateFieldSet2 } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/classPrivateFieldSet2.js";
|
|
9
|
+
import { _classPrivateFieldGet2 } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/classPrivateFieldGet2.js";
|
|
5
10
|
import { getCurrentInstance } from "../current.js";
|
|
6
11
|
import { TaroURLProvider } from "./URL.js";
|
|
7
12
|
import { isNumber, isString, warn } from "@spcsn/taro-shared";
|
|
8
13
|
//#region src/bom/location.ts
|
|
9
14
|
const INIT_URL = "https://taro.com";
|
|
10
15
|
const cache = new RuntimeCache("location");
|
|
16
|
+
var _url = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
var _noCheckUrl = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
var _window = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
var _TaroLocation_brand = /* @__PURE__ */ new WeakSet();
|
|
11
20
|
var TaroLocation = class extends Events {
|
|
12
21
|
constructor(options) {
|
|
13
22
|
super();
|
|
14
|
-
this
|
|
15
|
-
this
|
|
16
|
-
this
|
|
17
|
-
this
|
|
23
|
+
_classPrivateMethodInitSpec(this, _TaroLocation_brand);
|
|
24
|
+
_classPrivateFieldInitSpec(this, _url, new TaroURLProvider(INIT_URL));
|
|
25
|
+
_classPrivateFieldInitSpec(this, _noCheckUrl, false);
|
|
26
|
+
_classPrivateFieldInitSpec(this, _window, void 0);
|
|
27
|
+
_classPrivateFieldSet2(_window, this, options.window);
|
|
28
|
+
_assertClassBrand(_TaroLocation_brand, this, _reset).call(this);
|
|
18
29
|
this.on("__set_href_without_history__", (href) => {
|
|
19
|
-
|
|
20
|
-
const lastHash = this.
|
|
21
|
-
this.
|
|
22
|
-
if (lastHash !== this.
|
|
23
|
-
|
|
30
|
+
_classPrivateFieldSet2(_noCheckUrl, this, true);
|
|
31
|
+
const lastHash = _classPrivateFieldGet2(_url, this).hash;
|
|
32
|
+
_classPrivateFieldGet2(_url, this).href = generateFullUrl(href);
|
|
33
|
+
if (lastHash !== _classPrivateFieldGet2(_url, this).hash) _classPrivateFieldGet2(_window, this).trigger("hashchange");
|
|
34
|
+
_classPrivateFieldSet2(_noCheckUrl, this, false);
|
|
24
35
|
}, null);
|
|
25
36
|
this.on("0", () => {
|
|
26
|
-
this.
|
|
37
|
+
_assertClassBrand(_TaroLocation_brand, this, _reset).call(this);
|
|
27
38
|
}, null);
|
|
28
39
|
this.on("1", (pageId) => {
|
|
29
40
|
cache.set(pageId, { lastHref: this.href });
|
|
@@ -31,145 +42,104 @@ var TaroLocation = class extends Events {
|
|
|
31
42
|
this.on("2", (pageId) => {
|
|
32
43
|
if (cache.has(pageId)) {
|
|
33
44
|
const ctx = cache.get(pageId);
|
|
34
|
-
|
|
35
|
-
this.
|
|
36
|
-
|
|
45
|
+
_classPrivateFieldSet2(_noCheckUrl, this, true);
|
|
46
|
+
_classPrivateFieldGet2(_url, this).href = ctx.lastHref;
|
|
47
|
+
_classPrivateFieldSet2(_noCheckUrl, this, false);
|
|
37
48
|
}
|
|
38
49
|
}, null);
|
|
39
50
|
this.on("3", (pageId) => {
|
|
40
51
|
cache.delete(pageId);
|
|
41
52
|
}, null);
|
|
42
53
|
}
|
|
43
|
-
_reset() {
|
|
44
|
-
const router = getCurrentInstance().router;
|
|
45
|
-
if (router) {
|
|
46
|
-
const { path, params } = router;
|
|
47
|
-
const searchArr = Object.keys(params).map((key) => {
|
|
48
|
-
return `${key}=${params[key]}`;
|
|
49
|
-
});
|
|
50
|
-
const searchStr = searchArr.length > 0 ? "?" + searchArr.join("&") : "";
|
|
51
|
-
const url = `${INIT_URL}${path.startsWith("/") ? path : "/" + path}${searchStr}`;
|
|
52
|
-
this._url = new TaroURLProvider(url);
|
|
53
|
-
this.trigger("__reset_history__", this.href);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
_getPreValue() {
|
|
57
|
-
return this._url._toRaw();
|
|
58
|
-
}
|
|
59
|
-
_rollBack(href) {
|
|
60
|
-
this._url.href = href;
|
|
61
|
-
}
|
|
62
|
-
_recordHistory() {
|
|
63
|
-
this.trigger("__record_history__", this.href);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* 校验url的变化,是否需要更新history
|
|
67
|
-
*/
|
|
68
|
-
_checkUrlChange(preValue) {
|
|
69
|
-
if (this._noCheckUrl) return false;
|
|
70
|
-
const { protocol, hostname, port, pathname, search, hash } = this._url._toRaw();
|
|
71
|
-
if (protocol !== preValue.protocol || hostname !== preValue.hostname || port !== preValue.port) {
|
|
72
|
-
this._rollBack(preValue.href);
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
if (pathname !== preValue.pathname) return true;
|
|
76
|
-
if (search !== preValue.search) return true;
|
|
77
|
-
if (hash !== preValue.hash) {
|
|
78
|
-
this._window.trigger("hashchange");
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
this._rollBack(preValue.href);
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
54
|
get protocol() {
|
|
85
|
-
return this.
|
|
55
|
+
return _classPrivateFieldGet2(_url, this).protocol;
|
|
86
56
|
}
|
|
87
57
|
set protocol(val) {
|
|
88
58
|
if (!val || !isString(val) || !/^(http|https):$/i.test(val.trim())) return;
|
|
89
59
|
val = val.trim();
|
|
90
|
-
const preValue = this.
|
|
91
|
-
this.
|
|
92
|
-
if (this.
|
|
60
|
+
const preValue = _assertClassBrand(_TaroLocation_brand, this, _getPreValue).call(this);
|
|
61
|
+
_classPrivateFieldGet2(_url, this).protocol = val;
|
|
62
|
+
if (_assertClassBrand(_TaroLocation_brand, this, _checkUrlChange).call(this, preValue)) _assertClassBrand(_TaroLocation_brand, this, _recordHistory).call(this);
|
|
93
63
|
}
|
|
94
64
|
get host() {
|
|
95
|
-
return this.
|
|
65
|
+
return _classPrivateFieldGet2(_url, this).host;
|
|
96
66
|
}
|
|
97
67
|
set host(val) {
|
|
98
68
|
if (!val || !isString(val)) return;
|
|
99
69
|
val = val.trim();
|
|
100
|
-
const preValue = this.
|
|
101
|
-
this.
|
|
102
|
-
if (this.
|
|
70
|
+
const preValue = _assertClassBrand(_TaroLocation_brand, this, _getPreValue).call(this);
|
|
71
|
+
_classPrivateFieldGet2(_url, this).host = val;
|
|
72
|
+
if (_assertClassBrand(_TaroLocation_brand, this, _checkUrlChange).call(this, preValue)) _assertClassBrand(_TaroLocation_brand, this, _recordHistory).call(this);
|
|
103
73
|
}
|
|
104
74
|
get hostname() {
|
|
105
|
-
return this.
|
|
75
|
+
return _classPrivateFieldGet2(_url, this).hostname;
|
|
106
76
|
}
|
|
107
77
|
set hostname(val) {
|
|
108
78
|
if (!val || !isString(val)) return;
|
|
109
79
|
val = val.trim();
|
|
110
|
-
const preValue = this.
|
|
111
|
-
this.
|
|
112
|
-
if (this.
|
|
80
|
+
const preValue = _assertClassBrand(_TaroLocation_brand, this, _getPreValue).call(this);
|
|
81
|
+
_classPrivateFieldGet2(_url, this).hostname = val;
|
|
82
|
+
if (_assertClassBrand(_TaroLocation_brand, this, _checkUrlChange).call(this, preValue)) _assertClassBrand(_TaroLocation_brand, this, _recordHistory).call(this);
|
|
113
83
|
}
|
|
114
84
|
get port() {
|
|
115
|
-
return this.
|
|
85
|
+
return _classPrivateFieldGet2(_url, this).port;
|
|
116
86
|
}
|
|
117
87
|
set port(val) {
|
|
118
88
|
const xVal = Number(val = val.trim());
|
|
119
89
|
if (!isNumber(xVal) || xVal <= 0) return;
|
|
120
|
-
const preValue = this.
|
|
121
|
-
this.
|
|
122
|
-
if (this.
|
|
90
|
+
const preValue = _assertClassBrand(_TaroLocation_brand, this, _getPreValue).call(this);
|
|
91
|
+
_classPrivateFieldGet2(_url, this).port = val;
|
|
92
|
+
if (_assertClassBrand(_TaroLocation_brand, this, _checkUrlChange).call(this, preValue)) _assertClassBrand(_TaroLocation_brand, this, _recordHistory).call(this);
|
|
123
93
|
}
|
|
124
94
|
get pathname() {
|
|
125
|
-
return this.
|
|
95
|
+
return _classPrivateFieldGet2(_url, this).pathname;
|
|
126
96
|
}
|
|
127
97
|
set pathname(val) {
|
|
128
98
|
if (!val || !isString(val)) return;
|
|
129
99
|
val = val.trim();
|
|
130
|
-
const preValue = this.
|
|
131
|
-
this.
|
|
132
|
-
if (this.
|
|
100
|
+
const preValue = _assertClassBrand(_TaroLocation_brand, this, _getPreValue).call(this);
|
|
101
|
+
_classPrivateFieldGet2(_url, this).pathname = val;
|
|
102
|
+
if (_assertClassBrand(_TaroLocation_brand, this, _checkUrlChange).call(this, preValue)) _assertClassBrand(_TaroLocation_brand, this, _recordHistory).call(this);
|
|
133
103
|
}
|
|
134
104
|
get search() {
|
|
135
|
-
return this.
|
|
105
|
+
return _classPrivateFieldGet2(_url, this).search;
|
|
136
106
|
}
|
|
137
107
|
set search(val) {
|
|
138
108
|
if (!val || !isString(val)) return;
|
|
139
109
|
val = val.trim();
|
|
140
110
|
val = val.startsWith("?") ? val : `?${val}`;
|
|
141
|
-
const preValue = this.
|
|
142
|
-
this.
|
|
143
|
-
if (this.
|
|
111
|
+
const preValue = _assertClassBrand(_TaroLocation_brand, this, _getPreValue).call(this);
|
|
112
|
+
_classPrivateFieldGet2(_url, this).search = val;
|
|
113
|
+
if (_assertClassBrand(_TaroLocation_brand, this, _checkUrlChange).call(this, preValue)) _assertClassBrand(_TaroLocation_brand, this, _recordHistory).call(this);
|
|
144
114
|
}
|
|
145
115
|
get hash() {
|
|
146
|
-
return this.
|
|
116
|
+
return _classPrivateFieldGet2(_url, this).hash;
|
|
147
117
|
}
|
|
148
118
|
set hash(val) {
|
|
149
119
|
if (!val || !isString(val)) return;
|
|
150
120
|
val = val.trim();
|
|
151
121
|
val = val.startsWith("#") ? val : `#${val}`;
|
|
152
|
-
const preValue = this.
|
|
153
|
-
this.
|
|
154
|
-
if (this.
|
|
122
|
+
const preValue = _assertClassBrand(_TaroLocation_brand, this, _getPreValue).call(this);
|
|
123
|
+
_classPrivateFieldGet2(_url, this).hash = val;
|
|
124
|
+
if (_assertClassBrand(_TaroLocation_brand, this, _checkUrlChange).call(this, preValue)) _assertClassBrand(_TaroLocation_brand, this, _recordHistory).call(this);
|
|
155
125
|
}
|
|
156
126
|
get href() {
|
|
157
|
-
return this.
|
|
127
|
+
return _classPrivateFieldGet2(_url, this).href;
|
|
158
128
|
}
|
|
159
129
|
set href(val) {
|
|
160
130
|
if (!val || !isString(val) || !/^(http:|https:)?\/\/.+/.test(val = val.trim())) return;
|
|
161
|
-
const preValue = this.
|
|
162
|
-
this.
|
|
163
|
-
if (this.
|
|
131
|
+
const preValue = _assertClassBrand(_TaroLocation_brand, this, _getPreValue).call(this);
|
|
132
|
+
_classPrivateFieldGet2(_url, this).href = val;
|
|
133
|
+
if (_assertClassBrand(_TaroLocation_brand, this, _checkUrlChange).call(this, preValue)) _assertClassBrand(_TaroLocation_brand, this, _recordHistory).call(this);
|
|
164
134
|
}
|
|
165
135
|
get origin() {
|
|
166
|
-
return this.
|
|
136
|
+
return _classPrivateFieldGet2(_url, this).origin;
|
|
167
137
|
}
|
|
168
138
|
set origin(val) {
|
|
169
139
|
if (!val || !isString(val) || !/^(http:|https:)?\/\/.+/.test(val = val.trim())) return;
|
|
170
|
-
const preValue = this.
|
|
171
|
-
this.
|
|
172
|
-
if (this.
|
|
140
|
+
const preValue = _assertClassBrand(_TaroLocation_brand, this, _getPreValue).call(this);
|
|
141
|
+
_classPrivateFieldGet2(_url, this).origin = val;
|
|
142
|
+
if (_assertClassBrand(_TaroLocation_brand, this, _checkUrlChange).call(this, preValue)) _assertClassBrand(_TaroLocation_brand, this, _recordHistory).call(this);
|
|
173
143
|
}
|
|
174
144
|
assign() {
|
|
175
145
|
warn(true, "小程序环境中调用location.assign()无效.");
|
|
@@ -187,6 +157,47 @@ var TaroLocation = class extends Events {
|
|
|
187
157
|
return cache;
|
|
188
158
|
}
|
|
189
159
|
};
|
|
160
|
+
function _reset() {
|
|
161
|
+
const router = getCurrentInstance().router;
|
|
162
|
+
if (router) {
|
|
163
|
+
const { path, params } = router;
|
|
164
|
+
const searchArr = Object.keys(params).map((key) => {
|
|
165
|
+
return `${key}=${params[key]}`;
|
|
166
|
+
});
|
|
167
|
+
const searchStr = searchArr.length > 0 ? "?" + searchArr.join("&") : "";
|
|
168
|
+
const url = `${INIT_URL}${path.startsWith("/") ? path : "/" + path}${searchStr}`;
|
|
169
|
+
_classPrivateFieldSet2(_url, this, new TaroURLProvider(url));
|
|
170
|
+
this.trigger("__reset_history__", this.href);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function _getPreValue() {
|
|
174
|
+
return _classPrivateFieldGet2(_url, this)._toRaw();
|
|
175
|
+
}
|
|
176
|
+
function _rollBack(href) {
|
|
177
|
+
_classPrivateFieldGet2(_url, this).href = href;
|
|
178
|
+
}
|
|
179
|
+
function _recordHistory() {
|
|
180
|
+
this.trigger("__record_history__", this.href);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* 校验url的变化,是否需要更新history
|
|
184
|
+
*/
|
|
185
|
+
function _checkUrlChange(preValue) {
|
|
186
|
+
if (_classPrivateFieldGet2(_noCheckUrl, this)) return false;
|
|
187
|
+
const { protocol, hostname, port, pathname, search, hash } = _classPrivateFieldGet2(_url, this)._toRaw();
|
|
188
|
+
if (protocol !== preValue.protocol || hostname !== preValue.hostname || port !== preValue.port) {
|
|
189
|
+
_assertClassBrand(_TaroLocation_brand, this, _rollBack).call(this, preValue.href);
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
if (pathname !== preValue.pathname) return true;
|
|
193
|
+
if (search !== preValue.search) return true;
|
|
194
|
+
if (hash !== preValue.hash) {
|
|
195
|
+
_classPrivateFieldGet2(_window, this).trigger("hashchange");
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
_assertClassBrand(_TaroLocation_brand, this, _rollBack).call(this, preValue.href);
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
190
201
|
const Location = process.env.TARO_PLATFORM === "web" ? env.window.Location : TaroLocation;
|
|
191
202
|
function generateFullUrl(val = "") {
|
|
192
203
|
const origin = INIT_URL;
|
package/dist/bom/location.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location.js","names":[],"sources":["../../src/bom/location.ts"],"sourcesContent":["import { isNumber, isString, warn } from '@spcsn/taro-shared';\n\nimport { CONTEXT_ACTIONS } from '../constants';\nimport { getCurrentInstance } from '../current';\nimport { Events } from '../emitter/emitter';\nimport env from '../env';\nimport { RuntimeCache } from '../utils/cache';\nimport { TaroURLProvider } from './URL';\n\ntype PreValue = ReturnType<typeof TaroURLProvider.prototype._toRaw>;\n\ntype Options = {\n window: any;\n};\ntype LocationContext = {\n lastHref: string;\n};\n\nconst INIT_URL = 'https://taro.com';\nconst cache = new RuntimeCache<LocationContext>('location');\n\nclass TaroLocation extends Events {\n /* private property */\n private _url = new TaroURLProvider(INIT_URL);\n private _noCheckUrl = false;\n private _window: any;\n\n constructor(options: Options) {\n super();\n\n this._window = options.window;\n\n this._reset();\n\n this.on(\n '__set_href_without_history__',\n (href: string) => {\n this._noCheckUrl = true;\n\n const lastHash = this._url.hash;\n this._url.href = generateFullUrl(href);\n\n if (lastHash !== this._url.hash) {\n this._window.trigger('hashchange');\n }\n\n this._noCheckUrl = false;\n },\n null,\n );\n\n // 切换上下文行为\n this.on(\n CONTEXT_ACTIONS.INIT,\n () => {\n this._reset();\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RESTORE,\n (pageId: string) => {\n cache.set(pageId, {\n lastHref: this.href,\n });\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RECOVER,\n (pageId: string) => {\n // 数据恢复时,不需要执行跳转\n if (cache.has(pageId)) {\n const ctx = cache.get(pageId)!;\n this._noCheckUrl = true;\n this._url.href = ctx.lastHref;\n this._noCheckUrl = false;\n }\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.DESTROY,\n (pageId: string) => {\n cache.delete(pageId);\n },\n null,\n );\n }\n\n /* private method */\n private _reset() {\n const Current = getCurrentInstance();\n const router = Current.router;\n if (router) {\n const { path, params } = router;\n const searchArr = Object.keys(params).map((key) => {\n return `${key}=${params[key]}`;\n });\n const searchStr = searchArr.length > 0 ? '?' + searchArr.join('&') : '';\n const url = `${INIT_URL}${path.startsWith('/') ? path : '/' + path}${searchStr}`;\n\n this._url = new TaroURLProvider(url);\n\n this.trigger('__reset_history__', this.href);\n }\n }\n\n private _getPreValue(): PreValue {\n return this._url._toRaw();\n }\n\n private _rollBack(href: string) {\n this._url.href = href;\n }\n\n private _recordHistory() {\n this.trigger('__record_history__', this.href);\n }\n\n /**\n * 校验url的变化,是否需要更新history\n */\n private _checkUrlChange(preValue: PreValue): boolean {\n if (this._noCheckUrl) {\n return false;\n }\n\n const { protocol, hostname, port, pathname, search, hash } = this._url._toRaw();\n\n // 跨域三要素不允许修改\n if (protocol !== preValue.protocol || hostname !== preValue.hostname || port !== preValue.port) {\n this._rollBack(preValue.href);\n return false;\n }\n\n // pathname\n if (pathname !== preValue.pathname) {\n return true;\n }\n\n // search\n if (search !== preValue.search) {\n return true;\n }\n\n // hashchange\n if (hash !== preValue.hash) {\n this._window.trigger('hashchange');\n return true;\n }\n\n this._rollBack(preValue.href);\n return false;\n }\n\n /* public property */\n get protocol() {\n return this._url.protocol;\n }\n\n set protocol(val: string) {\n const REG = /^(http|https):$/i;\n if (!val || !isString(val) || !REG.test(val.trim())) return;\n\n val = val.trim();\n const preValue = this._getPreValue();\n this._url.protocol = val;\n\n if (this._checkUrlChange(preValue)) this._recordHistory();\n }\n\n get host() {\n return this._url.host;\n }\n\n set host(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n\n const preValue = this._getPreValue();\n this._url.host = val;\n\n if (this._checkUrlChange(preValue)) this._recordHistory();\n }\n\n get hostname() {\n return this._url.hostname;\n }\n\n set hostname(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n\n const preValue = this._getPreValue();\n this._url.hostname = val;\n\n if (this._checkUrlChange(preValue)) this._recordHistory();\n }\n\n get port() {\n return this._url.port;\n }\n\n set port(val: string) {\n const xVal = Number((val = val.trim()));\n if (!isNumber(xVal) || xVal <= 0) return;\n\n const preValue = this._getPreValue();\n this._url.port = val;\n\n if (this._checkUrlChange(preValue)) this._recordHistory();\n }\n\n get pathname() {\n return this._url.pathname;\n }\n\n set pathname(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n\n const preValue = this._getPreValue();\n this._url.pathname = val;\n\n if (this._checkUrlChange(preValue)) this._recordHistory();\n }\n\n get search() {\n return this._url.search;\n }\n\n set search(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n val = val.startsWith('?') ? val : `?${val}`;\n\n const preValue = this._getPreValue();\n this._url.search = val;\n\n if (this._checkUrlChange(preValue)) this._recordHistory();\n }\n\n get hash() {\n return this._url.hash;\n }\n\n // 小程序的navigateTo存在截断hash字符串的问题\n set hash(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n val = val.startsWith('#') ? val : `#${val}`;\n\n const preValue = this._getPreValue();\n this._url.hash = val;\n\n if (this._checkUrlChange(preValue)) this._recordHistory();\n }\n\n get href() {\n return this._url.href;\n }\n\n set href(val: string) {\n const REG = /^(http:|https:)?\\/\\/.+/;\n if (!val || !isString(val) || !REG.test((val = val.trim()))) return;\n\n const preValue = this._getPreValue();\n this._url.href = val;\n\n if (this._checkUrlChange(preValue)) this._recordHistory();\n }\n\n get origin() {\n return this._url.origin;\n }\n\n set origin(val: string) {\n const REG = /^(http:|https:)?\\/\\/.+/;\n if (!val || !isString(val) || !REG.test((val = val.trim()))) return;\n\n const preValue = this._getPreValue();\n this._url.origin = val;\n\n if (this._checkUrlChange(preValue)) this._recordHistory();\n }\n\n /* public method */\n assign() {\n warn(true, '小程序环境中调用location.assign()无效.');\n }\n\n reload() {\n warn(true, '小程序环境中调用location.reload()无效.');\n }\n\n replace(url: string) {\n this.trigger('__set_href_without_history__', url);\n }\n\n toString() {\n return this.href;\n }\n\n // For debug\n get cache() {\n return cache;\n }\n}\n\nexport type { TaroLocation };\nexport const Location: typeof TaroLocation = process.env.TARO_PLATFORM === 'web' ? env.window.Location : TaroLocation;\n\nfunction generateFullUrl(val = '') {\n const origin = INIT_URL;\n if (/^[/?#]/.test(val)) {\n return origin + val;\n }\n return val;\n}\n"],"mappings":";;;;;;;;AAkBA,MAAM,WAAW;AACjB,MAAM,QAAQ,IAAI,aAA8B,UAAU;AAE1D,IAAM,eAAN,cAA2B,OAAO;CAMhC,YAAY,SAAkB;EAC5B,MAAM;cALO,IAAI,gBAAgB,QAAQ;qBACrB;EAMpB,KAAK,UAAU,QAAQ;EAEvB,KAAK,OAAO;EAEZ,KAAK,GACH,iCACC,SAAiB;GAChB,KAAK,cAAc;GAEnB,MAAM,WAAW,KAAK,KAAK;GAC3B,KAAK,KAAK,OAAO,gBAAgB,IAAI;GAErC,IAAI,aAAa,KAAK,KAAK,MACzB,KAAK,QAAQ,QAAQ,YAAY;GAGnC,KAAK,cAAc;EACrB,GACA,IACF;EAGA,KAAK,GAAA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AEA,IAAI,SAAS;EACX,OAAO,KAAK,KAAK;CACnB;CAEA,IAAI,OAAO,KAAa;EAEtB,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC,yBAAI,KAAM,MAAM,IAAI,KAAK,CAAE,GAAG;EAE7D,MAAM,WAAW,KAAK,aAAa;EACnC,KAAK,KAAK,SAAS;EAEnB,IAAI,KAAK,gBAAgB,QAAQ,GAAG,KAAK,eAAe;CAC1D;CAGA,SAAS;EACP,KAAK,MAAM,8BAA8B;CAC3C;CAEA,SAAS;EACP,KAAK,MAAM,8BAA8B;CAC3C;CAEA,QAAQ,KAAa;EACnB,KAAK,QAAQ,gCAAgC,GAAG;CAClD;CAEA,WAAW;EACT,OAAO,KAAK;CACd;CAGA,IAAI,QAAQ;EACV,OAAO;CACT;AACF;AAGA,MAAa,WAAgC,QAAQ,IAAI,kBAAkB,QAAQ,IAAI,OAAO,WAAW;AAEzG,SAAS,gBAAgB,MAAM,IAAI;CACjC,MAAM,SAAS;CACf,IAAI,SAAS,KAAK,GAAG,GACnB,OAAO,SAAS;CAElB,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"location.js","names":[],"sources":["../../src/bom/location.ts"],"sourcesContent":["import { isNumber, isString, warn } from '@spcsn/taro-shared';\n\nimport { CONTEXT_ACTIONS } from '../constants';\nimport { getCurrentInstance } from '../current';\nimport { Events } from '../emitter/emitter';\nimport env from '../env';\nimport { RuntimeCache } from '../utils/cache';\nimport { TaroURLProvider } from './URL';\n\ntype PreValue = ReturnType<typeof TaroURLProvider.prototype._toRaw>;\n\ntype Options = {\n window: any;\n};\ntype LocationContext = {\n lastHref: string;\n};\n\nconst INIT_URL = 'https://taro.com';\nconst cache = new RuntimeCache<LocationContext>('location');\n\nclass TaroLocation extends Events {\n /* private property */\n #url = new TaroURLProvider(INIT_URL);\n #noCheckUrl = false;\n #window: any;\n\n constructor(options: Options) {\n super();\n\n this.#window = options.window;\n\n this.#reset();\n\n this.on(\n '__set_href_without_history__',\n (href: string) => {\n this.#noCheckUrl = true;\n\n const lastHash = this.#url.hash;\n this.#url.href = generateFullUrl(href);\n\n if (lastHash !== this.#url.hash) {\n this.#window.trigger('hashchange');\n }\n\n this.#noCheckUrl = false;\n },\n null,\n );\n\n // 切换上下文行为\n this.on(\n CONTEXT_ACTIONS.INIT,\n () => {\n this.#reset();\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RESTORE,\n (pageId: string) => {\n cache.set(pageId, {\n lastHref: this.href,\n });\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RECOVER,\n (pageId: string) => {\n // 数据恢复时,不需要执行跳转\n if (cache.has(pageId)) {\n const ctx = cache.get(pageId)!;\n this.#noCheckUrl = true;\n this.#url.href = ctx.lastHref;\n this.#noCheckUrl = false;\n }\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.DESTROY,\n (pageId: string) => {\n cache.delete(pageId);\n },\n null,\n );\n }\n\n /* private method */\n #reset() {\n const Current = getCurrentInstance();\n const router = Current.router;\n if (router) {\n const { path, params } = router;\n const searchArr = Object.keys(params).map((key) => {\n return `${key}=${params[key]}`;\n });\n const searchStr = searchArr.length > 0 ? '?' + searchArr.join('&') : '';\n const url = `${INIT_URL}${path.startsWith('/') ? path : '/' + path}${searchStr}`;\n\n this.#url = new TaroURLProvider(url);\n\n this.trigger('__reset_history__', this.href);\n }\n }\n\n #getPreValue(): PreValue {\n return this.#url._toRaw();\n }\n\n #rollBack(href: string) {\n this.#url.href = href;\n }\n\n #recordHistory() {\n this.trigger('__record_history__', this.href);\n }\n\n /**\n * 校验url的变化,是否需要更新history\n */\n #checkUrlChange(preValue: PreValue): boolean {\n if (this.#noCheckUrl) {\n return false;\n }\n\n const { protocol, hostname, port, pathname, search, hash } = this.#url._toRaw();\n\n // 跨域三要素不允许修改\n if (protocol !== preValue.protocol || hostname !== preValue.hostname || port !== preValue.port) {\n this.#rollBack(preValue.href);\n return false;\n }\n\n // pathname\n if (pathname !== preValue.pathname) {\n return true;\n }\n\n // search\n if (search !== preValue.search) {\n return true;\n }\n\n // hashchange\n if (hash !== preValue.hash) {\n this.#window.trigger('hashchange');\n return true;\n }\n\n this.#rollBack(preValue.href);\n return false;\n }\n\n /* public property */\n get protocol() {\n return this.#url.protocol;\n }\n\n set protocol(val: string) {\n const REG = /^(http|https):$/i;\n if (!val || !isString(val) || !REG.test(val.trim())) return;\n\n val = val.trim();\n const preValue = this.#getPreValue();\n this.#url.protocol = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get host() {\n return this.#url.host;\n }\n\n set host(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n\n const preValue = this.#getPreValue();\n this.#url.host = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get hostname() {\n return this.#url.hostname;\n }\n\n set hostname(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n\n const preValue = this.#getPreValue();\n this.#url.hostname = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get port() {\n return this.#url.port;\n }\n\n set port(val: string) {\n const xVal = Number((val = val.trim()));\n if (!isNumber(xVal) || xVal <= 0) return;\n\n const preValue = this.#getPreValue();\n this.#url.port = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get pathname() {\n return this.#url.pathname;\n }\n\n set pathname(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n\n const preValue = this.#getPreValue();\n this.#url.pathname = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get search() {\n return this.#url.search;\n }\n\n set search(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n val = val.startsWith('?') ? val : `?${val}`;\n\n const preValue = this.#getPreValue();\n this.#url.search = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get hash() {\n return this.#url.hash;\n }\n\n // 小程序的navigateTo存在截断hash字符串的问题\n set hash(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n val = val.startsWith('#') ? val : `#${val}`;\n\n const preValue = this.#getPreValue();\n this.#url.hash = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get href() {\n return this.#url.href;\n }\n\n set href(val: string) {\n const REG = /^(http:|https:)?\\/\\/.+/;\n if (!val || !isString(val) || !REG.test((val = val.trim()))) return;\n\n const preValue = this.#getPreValue();\n this.#url.href = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get origin() {\n return this.#url.origin;\n }\n\n set origin(val: string) {\n const REG = /^(http:|https:)?\\/\\/.+/;\n if (!val || !isString(val) || !REG.test((val = val.trim()))) return;\n\n const preValue = this.#getPreValue();\n this.#url.origin = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n /* public method */\n assign() {\n warn(true, '小程序环境中调用location.assign()无效.');\n }\n\n reload() {\n warn(true, '小程序环境中调用location.reload()无效.');\n }\n\n replace(url: string) {\n this.trigger('__set_href_without_history__', url);\n }\n\n toString() {\n return this.href;\n }\n\n // For debug\n get cache() {\n return cache;\n }\n}\n\nexport type { TaroLocation };\nexport const Location: typeof TaroLocation = process.env.TARO_PLATFORM === 'web' ? env.window.Location : TaroLocation;\n\nfunction generateFullUrl(val = '') {\n const origin = INIT_URL;\n if (/^[/?#]/.test(val)) {\n return origin + val;\n }\n return val;\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,MAAM,WAAW;AACjB,MAAM,QAAQ,IAAI,aAA8B,UAAU;;;;;AAE1D,IAAM,eAAN,cAA2B,OAAO;CAMhC,YAAY,SAAkB;EAC5B,MAAM;;yCALD,IAAI,gBAAgB,QAAQ,CAAA;gDACrB,KAAA;;EAMZ,uBAAA,SAAA,MAAe,QAAQ,MAAA;EAEvB,kBAAA,qBAAA,MAAA,MAAA,EAAA,KAAA,IAAY;EAEZ,KAAK,GACH,iCACC,SAAiB;GAChB,uBAAA,aAAA,MAAmB,IAAA;GAEnB,MAAM,WAAA,uBAAA,M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AAO;EAErE,uBAAA,MAAA,MAAY,IAAI,gBAAgB,GAAG,CAAA;EAEnC,KAAK,QAAQ,qBAAqB,KAAK,IAAI;CAC7C;AACF;AAEA,SAAA,eAAyB;CACvB,OAAA,uBAAA,MAAO,IAAA,EAAU,OAAO;AAC1B;AAEA,SAAA,UAAU,MAAc;CACtB,uBAAA,MAAA,IAAA,EAAU,OAAO;AACnB;AAEA,SAAA,iBAAiB;CACf,KAAK,QAAQ,sBAAsB,KAAK,IAAI;AAC9C;;;;AAKA,SAAA,gBAAgB,UAA6B;CAC3C,IAAA,uBAAA,aAAI,IAAA,GACF,OAAO;CAGT,MAAM,EAAE,UAAU,UAAU,MAAM,UAAU,QAAQ,SAAA,uBAAA,MAAS,IAAA,EAAU,OAAO;CAG9E,IAAI,aAAa,SAAS,YAAY,aAAa,SAAS,YAAY,SAAS,SAAS,MAAM;EAC9F,kBAAA,qBAAA,MAAA,SAAA,EAAA,KAAA,MAAe,SAAS,IAAI;EAC5B,OAAO;CACT;CAGA,IAAI,aAAa,SAAS,UACxB,OAAO;CAIT,IAAI,WAAW,SAAS,QACtB,OAAO;CAIT,IAAI,SAAS,SAAS,MAAM;EAC1B,uBAAA,SAAA,IAAA,EAAa,QAAQ,YAAY;EACjC,OAAO;CACT;CAEA,kBAAA,qBAAA,MAAA,SAAA,EAAA,KAAA,MAAe,SAAS,IAAI;CAC5B,OAAO;AACT;AA6JF,MAAa,WAAgC,QAAQ,IAAI,kBAAkB,QAAQ,IAAI,OAAO,WAAW;AAEzG,SAAS,gBAAgB,MAAM,IAAI;CACjC,MAAM,SAAS;CACf,IAAI,SAAS,KAAK,GAAG,GACnB,OAAO,SAAS;CAElB,OAAO;AACT"}
|
package/dist/bom/window.js
CHANGED
|
@@ -23,7 +23,7 @@ var TaroWindow = class extends Events {
|
|
|
23
23
|
console.warn(`[Taro warn] window.${String(property)} 在赋值到 window 时报错`);
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
|
-
this.Date
|
|
26
|
+
this.Date || (this.Date = Date);
|
|
27
27
|
this.location = new Location({ window: this });
|
|
28
28
|
this.history = new History(this.location, { window: this });
|
|
29
29
|
this.initEvent();
|
package/dist/bom/window.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"window.js","names":["navigator","raf","caf"],"sources":["../../src/bom/window.ts"],"sourcesContent":["import { isString } from '@spcsn/taro-shared';\n\nimport { CONTEXT_ACTIONS } from '../constants';\nimport { Events } from '../emitter/emitter';\nimport env from '../env';\nimport { taroGetComputedStyleProvider } from './getComputedStyle';\nimport { History } from './history';\nimport { Location } from './location';\nimport { nav as navigator } from './navigator';\nimport { caf, raf } from './raf';\n\nimport type { TaroHistory } from './history';\nimport type { TaroLocation } from './location';\n\nexport class TaroWindow extends Events {\n navigator = navigator;\n requestAnimationFrame = raf;\n cancelAnimationFrame = caf;\n getComputedStyle = taroGetComputedStyleProvider;\n Date: DateConstructor;\n\n location: TaroLocation;\n history: TaroHistory;\n XMLHttpRequest?: Partial<XMLHttpRequest>;\n\n constructor() {\n super();\n\n const globalProperties = [\n ...Object.getOwnPropertyNames(global || {}),\n ...Object.getOwnPropertySymbols(global || {}),\n ];\n\n globalProperties.forEach((property) => {\n if (property === 'atob' || property === 'document') return;\n if (!Object.prototype.hasOwnProperty.call(this, property)) {\n // 防止小程序环境下,window 上的某些 get 属性在赋值时报错\n try {\n this[property] = global[property];\n } catch (e) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`[Taro warn] window.${String(property)} 在赋值到 window 时报错`);\n }\n }\n }\n });\n\n this.Date ||= Date;\n\n // 应用启动时,提供给需要读取历史信息的库使用\n this.location = new Location({ window: this }) as any;\n // @ts-ignore\n this.history = new History(this.location, { window: this });\n\n this.initEvent();\n }\n\n initEvent() {\n const _location = this.location;\n const _history = this.history;\n\n this.on(\n CONTEXT_ACTIONS.INIT,\n (pageId: string) => {\n // 页面 onload,为该页面建立新的上下文信息\n _location.trigger(CONTEXT_ACTIONS.INIT, pageId);\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RECOVER,\n (pageId: string) => {\n // 页面 onshow,恢复当前页面的上下文信息\n _location.trigger(CONTEXT_ACTIONS.RECOVER, pageId);\n _history.trigger(CONTEXT_ACTIONS.RECOVER, pageId);\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RESTORE,\n (pageId: string) => {\n // 页面 onhide,缓存当前页面的上下文信息\n _location.trigger(CONTEXT_ACTIONS.RESTORE, pageId);\n _history.trigger(CONTEXT_ACTIONS.RESTORE, pageId);\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.DESTROY,\n (pageId: string) => {\n // 页面 onunload,清除当前页面的上下文信息\n _location.trigger(CONTEXT_ACTIONS.DESTROY, pageId);\n _history.trigger(CONTEXT_ACTIONS.DESTROY, pageId);\n },\n null,\n );\n }\n\n get document() {\n return env.document;\n }\n\n addEventListener(event: string, callback: (arg: any) => void) {\n if (!isString(event)) return;\n this.on(event, callback, null);\n }\n\n removeEventListener(event: string, callback: (arg: any) => void) {\n if (!isString(event)) return;\n this.off(event, callback, null);\n }\n\n setTimeout(...args: Parameters<typeof setTimeout>) {\n return setTimeout(...args);\n }\n\n clearTimeout(...args: Parameters<typeof clearTimeout>) {\n return clearTimeout(...args);\n }\n}\n\n// Note: 小程序端 vite 打包成 commonjs,const window = xxx 会报错,所以把 window 改为 taroWindowProvider,location 和 history 同理\nexport const taroWindowProvider: TaroWindow =\n process.env.TARO_PLATFORM === 'web' ? env.window : (env.window = new TaroWindow());\nexport const taroLocationProvider = taroWindowProvider.location;\nexport const taroHistoryProvider = taroWindowProvider.history;\n"],"mappings":";;;;;;;;;;AAcA,IAAa,aAAb,cAAgC,OAAO;CAWrC,cAAc;EACZ,MAAM;
|
|
1
|
+
{"version":3,"file":"window.js","names":["navigator","raf","caf"],"sources":["../../src/bom/window.ts"],"sourcesContent":["import { isString } from '@spcsn/taro-shared';\n\nimport { CONTEXT_ACTIONS } from '../constants';\nimport { Events } from '../emitter/emitter';\nimport env from '../env';\nimport { taroGetComputedStyleProvider } from './getComputedStyle';\nimport { History } from './history';\nimport { Location } from './location';\nimport { nav as navigator } from './navigator';\nimport { caf, raf } from './raf';\n\nimport type { TaroHistory } from './history';\nimport type { TaroLocation } from './location';\n\nexport class TaroWindow extends Events {\n navigator = navigator;\n requestAnimationFrame = raf;\n cancelAnimationFrame = caf;\n getComputedStyle = taroGetComputedStyleProvider;\n Date: DateConstructor;\n\n location: TaroLocation;\n history: TaroHistory;\n XMLHttpRequest?: Partial<XMLHttpRequest>;\n\n constructor() {\n super();\n\n const globalProperties = [\n ...Object.getOwnPropertyNames(global || {}),\n ...Object.getOwnPropertySymbols(global || {}),\n ];\n\n globalProperties.forEach((property) => {\n if (property === 'atob' || property === 'document') return;\n if (!Object.prototype.hasOwnProperty.call(this, property)) {\n // 防止小程序环境下,window 上的某些 get 属性在赋值时报错\n try {\n this[property] = global[property];\n } catch (e) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`[Taro warn] window.${String(property)} 在赋值到 window 时报错`);\n }\n }\n }\n });\n\n this.Date ||= Date;\n\n // 应用启动时,提供给需要读取历史信息的库使用\n this.location = new Location({ window: this }) as any;\n // @ts-ignore\n this.history = new History(this.location, { window: this });\n\n this.initEvent();\n }\n\n initEvent() {\n const _location = this.location;\n const _history = this.history;\n\n this.on(\n CONTEXT_ACTIONS.INIT,\n (pageId: string) => {\n // 页面 onload,为该页面建立新的上下文信息\n _location.trigger(CONTEXT_ACTIONS.INIT, pageId);\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RECOVER,\n (pageId: string) => {\n // 页面 onshow,恢复当前页面的上下文信息\n _location.trigger(CONTEXT_ACTIONS.RECOVER, pageId);\n _history.trigger(CONTEXT_ACTIONS.RECOVER, pageId);\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RESTORE,\n (pageId: string) => {\n // 页面 onhide,缓存当前页面的上下文信息\n _location.trigger(CONTEXT_ACTIONS.RESTORE, pageId);\n _history.trigger(CONTEXT_ACTIONS.RESTORE, pageId);\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.DESTROY,\n (pageId: string) => {\n // 页面 onunload,清除当前页面的上下文信息\n _location.trigger(CONTEXT_ACTIONS.DESTROY, pageId);\n _history.trigger(CONTEXT_ACTIONS.DESTROY, pageId);\n },\n null,\n );\n }\n\n get document() {\n return env.document;\n }\n\n addEventListener(event: string, callback: (arg: any) => void) {\n if (!isString(event)) return;\n this.on(event, callback, null);\n }\n\n removeEventListener(event: string, callback: (arg: any) => void) {\n if (!isString(event)) return;\n this.off(event, callback, null);\n }\n\n setTimeout(...args: Parameters<typeof setTimeout>) {\n return setTimeout(...args);\n }\n\n clearTimeout(...args: Parameters<typeof clearTimeout>) {\n return clearTimeout(...args);\n }\n}\n\n// Note: 小程序端 vite 打包成 commonjs,const window = xxx 会报错,所以把 window 改为 taroWindowProvider,location 和 history 同理\nexport const taroWindowProvider: TaroWindow =\n process.env.TARO_PLATFORM === 'web' ? env.window : (env.window = new TaroWindow());\nexport const taroLocationProvider = taroWindowProvider.location;\nexport const taroHistoryProvider = taroWindowProvider.history;\n"],"mappings":";;;;;;;;;;AAcA,IAAa,aAAb,cAAgC,OAAO;CAWrC,cAAc;EACZ,MAAM;EAXR,KAAA,YAAYA;EACZ,KAAA,wBAAwBC;EACxB,KAAA,uBAAuBC;EACvB,KAAA,mBAAmB;EAejB,CAJE,GAAG,OAAO,oBAAoB,UAAU,CAAC,CAAC,GAC1C,GAAG,OAAO,sBAAsB,UAAU,CAAC,CAAC,CAG/B,EAAE,SAAS,aAAa;GACrC,IAAI,aAAa,UAAU,aAAa,YAAY;GACpD,IAAI,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,QAAQ,GAEtD,IAAI;IACF,KAAK,YAAY,OAAO;GAC1B,SAAS,GAAG;IAER,QAAQ,KAAK,sBAAsB,OAAO,QAAQ,EAAE,iBAAiB;GAEzE;EAEJ,CAAC;EAED,KAAK,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