@spcsn/taro-runtime 0.1.0 → 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.js +36 -27
- 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.js +52 -40
- package/dist/bom/history.js.map +1 -1
- package/dist/bom/location.js +101 -91
- 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 -260
- 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.js +10 -6
- package/dist/perf.js.map +1 -1
- package/dist/runtime.esm.js +392 -260
- 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,74 +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
|
-
#location;
|
|
10
|
-
#stack = [];
|
|
11
|
-
#cur = 0;
|
|
12
|
-
#window;
|
|
13
19
|
constructor(location, options) {
|
|
14
20
|
super();
|
|
15
|
-
this
|
|
16
|
-
this
|
|
17
|
-
this
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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({
|
|
21
33
|
state: null,
|
|
22
34
|
title: "",
|
|
23
35
|
url: href
|
|
24
36
|
});
|
|
25
37
|
}, null);
|
|
26
|
-
this
|
|
27
|
-
this
|
|
38
|
+
_classPrivateFieldGet2(_location, this).on("__reset_history__", (href) => {
|
|
39
|
+
_assertClassBrand(_TaroHistory_brand, this, _reset).call(this, href);
|
|
28
40
|
}, null);
|
|
29
41
|
this.on("0", () => {
|
|
30
|
-
this
|
|
42
|
+
_assertClassBrand(_TaroHistory_brand, this, _reset).call(this);
|
|
31
43
|
}, null);
|
|
32
44
|
this.on("1", (pageId) => {
|
|
33
45
|
cache.set(pageId, {
|
|
34
|
-
location: this
|
|
35
|
-
stack: this
|
|
36
|
-
cur: this
|
|
46
|
+
location: _classPrivateFieldGet2(_location, this),
|
|
47
|
+
stack: _classPrivateFieldGet2(_stack, this).slice(),
|
|
48
|
+
cur: _classPrivateFieldGet2(_cur, this)
|
|
37
49
|
});
|
|
38
50
|
}, null);
|
|
39
51
|
this.on("2", (pageId) => {
|
|
40
52
|
if (cache.has(pageId)) {
|
|
41
53
|
const ctx = cache.get(pageId);
|
|
42
|
-
this
|
|
43
|
-
this
|
|
44
|
-
this
|
|
54
|
+
_classPrivateFieldSet2(_location, this, ctx.location);
|
|
55
|
+
_classPrivateFieldSet2(_stack, this, ctx.stack);
|
|
56
|
+
_classPrivateFieldSet2(_cur, this, ctx.cur);
|
|
45
57
|
}
|
|
46
58
|
}, null);
|
|
47
59
|
this.on("3", (pageId) => {
|
|
48
60
|
cache.delete(pageId);
|
|
49
61
|
}, null);
|
|
50
|
-
this
|
|
51
|
-
}
|
|
52
|
-
#reset(href = "") {
|
|
53
|
-
this.#stack = [{
|
|
54
|
-
state: null,
|
|
55
|
-
title: "",
|
|
56
|
-
url: href || this.#location.href
|
|
57
|
-
}];
|
|
58
|
-
this.#cur = 0;
|
|
62
|
+
_assertClassBrand(_TaroHistory_brand, this, _reset).call(this);
|
|
59
63
|
}
|
|
60
64
|
get length() {
|
|
61
|
-
return this
|
|
65
|
+
return _classPrivateFieldGet2(_stack, this).length;
|
|
62
66
|
}
|
|
63
67
|
get state() {
|
|
64
|
-
return this
|
|
68
|
+
return _classPrivateFieldGet2(_stack, this)[_classPrivateFieldGet2(_cur, this)].state;
|
|
65
69
|
}
|
|
66
70
|
go(delta) {
|
|
67
71
|
if (!isNumber(delta) || isNaN(delta)) return;
|
|
68
|
-
let targetIdx = this
|
|
72
|
+
let targetIdx = _classPrivateFieldGet2(_cur, this) + delta;
|
|
69
73
|
targetIdx = Math.min(Math.max(targetIdx, 0), this.length - 1);
|
|
70
|
-
this
|
|
71
|
-
this
|
|
72
|
-
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)]);
|
|
73
77
|
}
|
|
74
78
|
back() {
|
|
75
79
|
this.go(-1);
|
|
@@ -79,28 +83,36 @@ var TaroHistory = class extends Events {
|
|
|
79
83
|
}
|
|
80
84
|
pushState(state, title, url) {
|
|
81
85
|
if (!url || !isString(url)) return;
|
|
82
|
-
this
|
|
83
|
-
this
|
|
86
|
+
_classPrivateFieldSet2(_stack, this, _classPrivateFieldGet2(_stack, this).slice(0, _classPrivateFieldGet2(_cur, this) + 1));
|
|
87
|
+
_classPrivateFieldGet2(_stack, this).push({
|
|
84
88
|
state,
|
|
85
89
|
title,
|
|
86
90
|
url
|
|
87
91
|
});
|
|
88
|
-
this
|
|
89
|
-
this
|
|
92
|
+
_classPrivateFieldSet2(_cur, this, this.length - 1);
|
|
93
|
+
_classPrivateFieldGet2(_location, this).trigger("__set_href_without_history__", url);
|
|
90
94
|
}
|
|
91
95
|
replaceState(state, title, url) {
|
|
92
96
|
if (!url || !isString(url)) return;
|
|
93
|
-
this
|
|
97
|
+
_classPrivateFieldGet2(_stack, this)[_classPrivateFieldGet2(_cur, this)] = {
|
|
94
98
|
state,
|
|
95
99
|
title,
|
|
96
100
|
url
|
|
97
101
|
};
|
|
98
|
-
this
|
|
102
|
+
_classPrivateFieldGet2(_location, this).trigger("__set_href_without_history__", url);
|
|
99
103
|
}
|
|
100
104
|
get cache() {
|
|
101
105
|
return cache;
|
|
102
106
|
}
|
|
103
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
|
+
}
|
|
104
116
|
const History = process.env.TARO_PLATFORM === "web" ? env.window.History : TaroHistory;
|
|
105
117
|
//#endregion
|
|
106
118
|
export { History };
|
package/dist/bom/history.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.js","names":[
|
|
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,EAAA,KAAA,MAAY,IAAI;EAClB,GACA,IACF;EAIA,KAAK,GAAA,WAEG;GACJ,kBAAA,oBAAA,MAAA,MAAA,EAAA,KAAA,IAAY;EACd,GACA,IACF;EAEA,KAAK,GAAA,MAEF,WAAmB;GAClB,MAAM,IAAI,QAAQ;IAChB,UAAA,uBAAA,WAAU,IAAA;IACV,OAAA,uBAAA,QAAO,IAAA,EAAY,MAAM;IACzB,KAAA,uBAAA,MAAK,IAAA;GACP,CAAC;EACH,GACA,IACF;EAEA,KAAK,GAAA,MAEF,WAAmB;GAClB,IAAI,MAAM,IAAI,MAAM,GAAG;IACrB,MAAM,MAAM,MAAM,IAAI,MAAM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e,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.js
CHANGED
|
@@ -2,29 +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
|
-
#url = new TaroURLProvider(INIT_URL);
|
|
13
|
-
#noCheckUrl = false;
|
|
14
|
-
#window;
|
|
15
21
|
constructor(options) {
|
|
16
22
|
super();
|
|
17
|
-
this
|
|
18
|
-
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);
|
|
19
29
|
this.on("__set_href_without_history__", (href) => {
|
|
20
|
-
this
|
|
21
|
-
const lastHash = this
|
|
22
|
-
this
|
|
23
|
-
if (lastHash !== this
|
|
24
|
-
this
|
|
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);
|
|
25
35
|
}, null);
|
|
26
36
|
this.on("0", () => {
|
|
27
|
-
this
|
|
37
|
+
_assertClassBrand(_TaroLocation_brand, this, _reset).call(this);
|
|
28
38
|
}, null);
|
|
29
39
|
this.on("1", (pageId) => {
|
|
30
40
|
cache.set(pageId, { lastHref: this.href });
|
|
@@ -32,145 +42,104 @@ var TaroLocation = class extends Events {
|
|
|
32
42
|
this.on("2", (pageId) => {
|
|
33
43
|
if (cache.has(pageId)) {
|
|
34
44
|
const ctx = cache.get(pageId);
|
|
35
|
-
this
|
|
36
|
-
this
|
|
37
|
-
this
|
|
45
|
+
_classPrivateFieldSet2(_noCheckUrl, this, true);
|
|
46
|
+
_classPrivateFieldGet2(_url, this).href = ctx.lastHref;
|
|
47
|
+
_classPrivateFieldSet2(_noCheckUrl, this, false);
|
|
38
48
|
}
|
|
39
49
|
}, null);
|
|
40
50
|
this.on("3", (pageId) => {
|
|
41
51
|
cache.delete(pageId);
|
|
42
52
|
}, null);
|
|
43
53
|
}
|
|
44
|
-
#reset() {
|
|
45
|
-
const router = getCurrentInstance().router;
|
|
46
|
-
if (router) {
|
|
47
|
-
const { path, params } = router;
|
|
48
|
-
const searchArr = Object.keys(params).map((key) => {
|
|
49
|
-
return `${key}=${params[key]}`;
|
|
50
|
-
});
|
|
51
|
-
const searchStr = searchArr.length > 0 ? "?" + searchArr.join("&") : "";
|
|
52
|
-
const url = `${INIT_URL}${path.startsWith("/") ? path : "/" + path}${searchStr}`;
|
|
53
|
-
this.#url = new TaroURLProvider(url);
|
|
54
|
-
this.trigger("__reset_history__", this.href);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
#getPreValue() {
|
|
58
|
-
return this.#url._toRaw();
|
|
59
|
-
}
|
|
60
|
-
#rollBack(href) {
|
|
61
|
-
this.#url.href = href;
|
|
62
|
-
}
|
|
63
|
-
#recordHistory() {
|
|
64
|
-
this.trigger("__record_history__", this.href);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* 校验url的变化,是否需要更新history
|
|
68
|
-
*/
|
|
69
|
-
#checkUrlChange(preValue) {
|
|
70
|
-
if (this.#noCheckUrl) return false;
|
|
71
|
-
const { protocol, hostname, port, pathname, search, hash } = this.#url._toRaw();
|
|
72
|
-
if (protocol !== preValue.protocol || hostname !== preValue.hostname || port !== preValue.port) {
|
|
73
|
-
this.#rollBack(preValue.href);
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
if (pathname !== preValue.pathname) return true;
|
|
77
|
-
if (search !== preValue.search) return true;
|
|
78
|
-
if (hash !== preValue.hash) {
|
|
79
|
-
this.#window.trigger("hashchange");
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
this.#rollBack(preValue.href);
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
54
|
get protocol() {
|
|
86
|
-
return this
|
|
55
|
+
return _classPrivateFieldGet2(_url, this).protocol;
|
|
87
56
|
}
|
|
88
57
|
set protocol(val) {
|
|
89
58
|
if (!val || !isString(val) || !/^(http|https):$/i.test(val.trim())) return;
|
|
90
59
|
val = val.trim();
|
|
91
|
-
const preValue = this
|
|
92
|
-
this
|
|
93
|
-
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);
|
|
94
63
|
}
|
|
95
64
|
get host() {
|
|
96
|
-
return this
|
|
65
|
+
return _classPrivateFieldGet2(_url, this).host;
|
|
97
66
|
}
|
|
98
67
|
set host(val) {
|
|
99
68
|
if (!val || !isString(val)) return;
|
|
100
69
|
val = val.trim();
|
|
101
|
-
const preValue = this
|
|
102
|
-
this
|
|
103
|
-
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);
|
|
104
73
|
}
|
|
105
74
|
get hostname() {
|
|
106
|
-
return this
|
|
75
|
+
return _classPrivateFieldGet2(_url, this).hostname;
|
|
107
76
|
}
|
|
108
77
|
set hostname(val) {
|
|
109
78
|
if (!val || !isString(val)) return;
|
|
110
79
|
val = val.trim();
|
|
111
|
-
const preValue = this
|
|
112
|
-
this
|
|
113
|
-
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);
|
|
114
83
|
}
|
|
115
84
|
get port() {
|
|
116
|
-
return this
|
|
85
|
+
return _classPrivateFieldGet2(_url, this).port;
|
|
117
86
|
}
|
|
118
87
|
set port(val) {
|
|
119
88
|
const xVal = Number(val = val.trim());
|
|
120
89
|
if (!isNumber(xVal) || xVal <= 0) return;
|
|
121
|
-
const preValue = this
|
|
122
|
-
this
|
|
123
|
-
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);
|
|
124
93
|
}
|
|
125
94
|
get pathname() {
|
|
126
|
-
return this
|
|
95
|
+
return _classPrivateFieldGet2(_url, this).pathname;
|
|
127
96
|
}
|
|
128
97
|
set pathname(val) {
|
|
129
98
|
if (!val || !isString(val)) return;
|
|
130
99
|
val = val.trim();
|
|
131
|
-
const preValue = this
|
|
132
|
-
this
|
|
133
|
-
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);
|
|
134
103
|
}
|
|
135
104
|
get search() {
|
|
136
|
-
return this
|
|
105
|
+
return _classPrivateFieldGet2(_url, this).search;
|
|
137
106
|
}
|
|
138
107
|
set search(val) {
|
|
139
108
|
if (!val || !isString(val)) return;
|
|
140
109
|
val = val.trim();
|
|
141
110
|
val = val.startsWith("?") ? val : `?${val}`;
|
|
142
|
-
const preValue = this
|
|
143
|
-
this
|
|
144
|
-
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);
|
|
145
114
|
}
|
|
146
115
|
get hash() {
|
|
147
|
-
return this
|
|
116
|
+
return _classPrivateFieldGet2(_url, this).hash;
|
|
148
117
|
}
|
|
149
118
|
set hash(val) {
|
|
150
119
|
if (!val || !isString(val)) return;
|
|
151
120
|
val = val.trim();
|
|
152
121
|
val = val.startsWith("#") ? val : `#${val}`;
|
|
153
|
-
const preValue = this
|
|
154
|
-
this
|
|
155
|
-
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);
|
|
156
125
|
}
|
|
157
126
|
get href() {
|
|
158
|
-
return this
|
|
127
|
+
return _classPrivateFieldGet2(_url, this).href;
|
|
159
128
|
}
|
|
160
129
|
set href(val) {
|
|
161
130
|
if (!val || !isString(val) || !/^(http:|https:)?\/\/.+/.test(val = val.trim())) return;
|
|
162
|
-
const preValue = this
|
|
163
|
-
this
|
|
164
|
-
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);
|
|
165
134
|
}
|
|
166
135
|
get origin() {
|
|
167
|
-
return this
|
|
136
|
+
return _classPrivateFieldGet2(_url, this).origin;
|
|
168
137
|
}
|
|
169
138
|
set origin(val) {
|
|
170
139
|
if (!val || !isString(val) || !/^(http:|https:)?\/\/.+/.test(val = val.trim())) return;
|
|
171
|
-
const preValue = this
|
|
172
|
-
this
|
|
173
|
-
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);
|
|
174
143
|
}
|
|
175
144
|
assign() {
|
|
176
145
|
warn(true, "小程序环境中调用location.assign()无效.");
|
|
@@ -188,6 +157,47 @@ var TaroLocation = class extends Events {
|
|
|
188
157
|
return cache;
|
|
189
158
|
}
|
|
190
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
|
+
}
|
|
191
201
|
const Location = process.env.TARO_PLATFORM === "web" ? env.window.Location : TaroLocation;
|
|
192
202
|
function generateFullUrl(val = "") {
|
|
193
203
|
const origin = INIT_URL;
|
package/dist/bom/location.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location.js","names":["#window","#reset","#noCheckUrl","#url","#rollBack","#getPreValue","#checkUrlChange","#recordHistory"],"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 (/^[/?#]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AAK,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,MAAW,IAAA,EAAU;GAC3B,uBAAA,MAAA,IAAA,EAAU,OAAO,gBAAgB,IAAI;GAErC,IAAI,aAAA,uBAAA,MAAa,IAAA,EAAU,MACzB,uBAAA,SAAA,IAAA,EAAa,QAAQ,YAAY;GAGnC,uBAAA,aAAA,MAAmB,KAAA;EACrB,GACA,IACF;EAGA,KAAK,GAAA,WAEG;GACJ,kBAAA,qBAAA,MAAA,MAAA,EAAA,KAAA,IAAY;EACd,GACA,IACF;EAEA,KAAK,GAAA,MAEF,WAAmB;GAClB,MAAM,IAAI,QAAQ,EAChB,UAAU,KAAK,KACjB,CAAC;EACH,GACA,IACF;EAEA,KAAK,GAAA,MAEF,WAAmB;GAElB,IAAI,MAAM,IAAI,MAAM,GAAG;IACrB,MAAM,MAAM,MAAM,IAAI,MAAM;IAC5B,uBAAA,aAAA,MAAmB,IAAA;IACnB,uBAAA,MAAA,IAAA,EAAU,OAAO,IAAI;IACrB,uBAAA,aAAA,MAAmB,KAAA;GACrB;EACF,GACA,IACF;EAEA,KAAK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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,SAAA,KAAA,OAAS;EAGd,KAAK,WAAW,IAAI,SAAS,EAAE,QAAQ,KAAK,CAAC;EAE7C,KAAK,UAAU,IAAI,QAAQ,KAAK,UAAU,EAAE,QAAQ,KAAK,CAAC;EAE1D,KAAK,UAAU;CACjB;CAEA,YAAY;EACV,MAAM,YAAY,KAAK;EACvB,MAAM,WAAW,KAAK;EAEtB,KAAK,GAAA,MAEF,WAAmB;GAElB,UAAU,QAAA,KAA8B,MAAM;EAChD,GACA,IACF;EAEA,KAAK,GAAA,MAEF,WAAmB;GAElB,UAAU,QAAA,KAAiC,MAAM;GACjD,SAAS,QAAA,KAAiC,MAAM;EAClD,GACA,IACF;EAEA,KAAK,GAAA,MAEF,WAAmB;GAElB,UAAU,QAAA,KAAiC,MAAM;GACjD,SAAS,QAAA,KAAiC,MAAM;EAClD,GACA,IACF;EAEA,KAAK,GAAA,MAEF,WAAmB;GAElB,UAAU,QAAA,KAAiC,MAAM;GACjD,SAAS,QAAA,KAAiC,MAAM;EAClD,GACA,IACF;CACF;CAEA,IAAI,WAAW;EACb,OAAO,IAAI;CACb;CAEA,iBAAiB,OAAe,UAA8B;EAC5D,IAAI,CAAC,SAAS,KAAK,GAAG;EACtB,KAAK,GAAG,OAAO,UAAU,IAAI;CAC/B;CAEA,oBAAoB,OAAe,UAA8B;EAC/D,IAAI,CAAC,SAAS,KAAK,GAAG;EACtB,KAAK,IAAI,OAAO,UAAU,IAAI;CAChC;CAEA,WAAW,GAAG,MAAqC;EACjD,OAAO,WAAW,GAAG,IAAI;CAC3B;CAEA,aAAa,GAAG,MAAuC;EACrD,OAAO,aAAa,GAAG,IAAI;CAC7B;AACF;AAGA,MAAa,qBACX,QAAQ,IAAI,kBAAkB,QAAQ,IAAI,SAAU,IAAI,SAAS,IAAI,WAAW;AAClF,MAAa,uBAAuB,mBAAmB;AACvD,MAAa,sBAAsB,mBAAmB"}
|
|
@@ -3,31 +3,39 @@ import { TaroElement } from "./element.js";
|
|
|
3
3
|
//#region src/dom/anchor-element.ts
|
|
4
4
|
var AnchorElement = class extends TaroElement {
|
|
5
5
|
get href() {
|
|
6
|
-
|
|
6
|
+
var _this$props$AnchorEle;
|
|
7
|
+
return (_this$props$AnchorEle = this.props["href"]) !== null && _this$props$AnchorEle !== void 0 ? _this$props$AnchorEle : "";
|
|
7
8
|
}
|
|
8
9
|
set href(val) {
|
|
9
10
|
this.setAttribute("href", val);
|
|
10
11
|
}
|
|
11
12
|
get protocol() {
|
|
12
|
-
|
|
13
|
+
var _this$props$AnchorEle2;
|
|
14
|
+
return (_this$props$AnchorEle2 = this.props["protocol"]) !== null && _this$props$AnchorEle2 !== void 0 ? _this$props$AnchorEle2 : "";
|
|
13
15
|
}
|
|
14
16
|
get host() {
|
|
15
|
-
|
|
17
|
+
var _this$props$AnchorEle3;
|
|
18
|
+
return (_this$props$AnchorEle3 = this.props["host"]) !== null && _this$props$AnchorEle3 !== void 0 ? _this$props$AnchorEle3 : "";
|
|
16
19
|
}
|
|
17
20
|
get search() {
|
|
18
|
-
|
|
21
|
+
var _this$props$AnchorEle4;
|
|
22
|
+
return (_this$props$AnchorEle4 = this.props["search"]) !== null && _this$props$AnchorEle4 !== void 0 ? _this$props$AnchorEle4 : "";
|
|
19
23
|
}
|
|
20
24
|
get hash() {
|
|
21
|
-
|
|
25
|
+
var _this$props$AnchorEle5;
|
|
26
|
+
return (_this$props$AnchorEle5 = this.props["hash"]) !== null && _this$props$AnchorEle5 !== void 0 ? _this$props$AnchorEle5 : "";
|
|
22
27
|
}
|
|
23
28
|
get hostname() {
|
|
24
|
-
|
|
29
|
+
var _this$props$AnchorEle6;
|
|
30
|
+
return (_this$props$AnchorEle6 = this.props["hostname"]) !== null && _this$props$AnchorEle6 !== void 0 ? _this$props$AnchorEle6 : "";
|
|
25
31
|
}
|
|
26
32
|
get port() {
|
|
27
|
-
|
|
33
|
+
var _this$props$AnchorEle7;
|
|
34
|
+
return (_this$props$AnchorEle7 = this.props["port"]) !== null && _this$props$AnchorEle7 !== void 0 ? _this$props$AnchorEle7 : "";
|
|
28
35
|
}
|
|
29
36
|
get pathname() {
|
|
30
|
-
|
|
37
|
+
var _this$props$AnchorEle8;
|
|
38
|
+
return (_this$props$AnchorEle8 = this.props["pathname"]) !== null && _this$props$AnchorEle8 !== void 0 ? _this$props$AnchorEle8 : "";
|
|
31
39
|
}
|
|
32
40
|
setAttribute(qualifiedName, value) {
|
|
33
41
|
if (qualifiedName === "href") {
|