@spcsn/taro-runtime 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bom/URL.d.ts +6 -1
- package/dist/bom/URL.js +26 -27
- package/dist/bom/URL.js.map +1 -1
- package/dist/bom/URLSearchParams.js +11 -11
- package/dist/bom/URLSearchParams.js.map +1 -1
- package/dist/bom/history.d.ts +5 -1
- package/dist/bom/history.js +34 -36
- package/dist/bom/history.js.map +1 -1
- package/dist/bom/location.d.ts +11 -1
- package/dist/bom/location.js +62 -63
- package/dist/bom/location.js.map +1 -1
- package/dist/index.cjs.js +135 -139
- package/dist/index.cjs.js.map +1 -1
- package/dist/perf.d.ts +1 -1
- package/dist/perf.js +2 -2
- package/dist/perf.js.map +1 -1
- package/dist/runtime.esm.js +135 -139
- package/dist/runtime.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/bom/URL.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
declare class TaroURL {
|
|
2
|
-
#private;
|
|
3
2
|
static createObjectURL(): void;
|
|
4
3
|
static revokeObjectURL(): void;
|
|
4
|
+
private _hash;
|
|
5
|
+
private _hostname;
|
|
6
|
+
private _pathname;
|
|
7
|
+
private _port;
|
|
8
|
+
private _protocol;
|
|
9
|
+
private _search;
|
|
5
10
|
constructor(url: string, base?: string);
|
|
6
11
|
get protocol(): string;
|
|
7
12
|
set protocol(val: string);
|
package/dist/bom/URL.js
CHANGED
|
@@ -9,27 +9,26 @@ var TaroURL = class {
|
|
|
9
9
|
static revokeObjectURL() {
|
|
10
10
|
throw new Error("Oops, not support URL.revokeObjectURL() in miniprogram.");
|
|
11
11
|
}
|
|
12
|
-
#hash = "";
|
|
13
|
-
#hostname = "";
|
|
14
|
-
#pathname = "";
|
|
15
|
-
#port = "";
|
|
16
|
-
#protocol = "";
|
|
17
|
-
#search;
|
|
18
12
|
constructor(url, base) {
|
|
13
|
+
this._hash = "";
|
|
14
|
+
this._hostname = "";
|
|
15
|
+
this._pathname = "";
|
|
16
|
+
this._port = "";
|
|
17
|
+
this._protocol = "";
|
|
19
18
|
if (!isString(url)) url = String(url);
|
|
20
19
|
const { hash, hostname, pathname, port, protocol, search } = parseUrlBase(url, base);
|
|
21
|
-
this
|
|
22
|
-
this
|
|
23
|
-
this
|
|
24
|
-
this
|
|
25
|
-
this
|
|
26
|
-
this
|
|
20
|
+
this._hash = hash;
|
|
21
|
+
this._hostname = hostname;
|
|
22
|
+
this._pathname = pathname || "/";
|
|
23
|
+
this._port = port;
|
|
24
|
+
this._protocol = protocol;
|
|
25
|
+
this._search = new URLSearchParams(search);
|
|
27
26
|
}
|
|
28
27
|
get protocol() {
|
|
29
|
-
return this
|
|
28
|
+
return this._protocol;
|
|
30
29
|
}
|
|
31
30
|
set protocol(val) {
|
|
32
|
-
isString(val) && (this
|
|
31
|
+
isString(val) && (this._protocol = val.trim());
|
|
33
32
|
}
|
|
34
33
|
get host() {
|
|
35
34
|
return this.hostname + (this.port ? ":" + this.port : "");
|
|
@@ -43,19 +42,19 @@ var TaroURL = class {
|
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
get hostname() {
|
|
46
|
-
return this
|
|
45
|
+
return this._hostname;
|
|
47
46
|
}
|
|
48
47
|
set hostname(val) {
|
|
49
|
-
val && isString(val) && (this
|
|
48
|
+
val && isString(val) && (this._hostname = val.trim());
|
|
50
49
|
}
|
|
51
50
|
get port() {
|
|
52
|
-
return this
|
|
51
|
+
return this._port;
|
|
53
52
|
}
|
|
54
53
|
set port(val) {
|
|
55
|
-
isString(val) && (this
|
|
54
|
+
isString(val) && (this._port = val.trim());
|
|
56
55
|
}
|
|
57
56
|
get pathname() {
|
|
58
|
-
return this
|
|
57
|
+
return this._pathname;
|
|
59
58
|
}
|
|
60
59
|
set pathname(val) {
|
|
61
60
|
if (isString(val)) {
|
|
@@ -63,28 +62,28 @@ var TaroURL = class {
|
|
|
63
62
|
const HEAD_REG = /^(\/|\.\/|\.\.\/)/;
|
|
64
63
|
let temp = val;
|
|
65
64
|
while (HEAD_REG.test(temp)) temp = temp.replace(HEAD_REG, "");
|
|
66
|
-
if (temp) this
|
|
67
|
-
else this
|
|
65
|
+
if (temp) this._pathname = "/" + temp;
|
|
66
|
+
else this._pathname = "/";
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
get search() {
|
|
71
|
-
const val = this
|
|
70
|
+
const val = this._search.toString();
|
|
72
71
|
return val.length === 0 || val.startsWith("?") ? val : `?${val}`;
|
|
73
72
|
}
|
|
74
73
|
set search(val) {
|
|
75
74
|
if (isString(val)) {
|
|
76
75
|
val = val.trim();
|
|
77
|
-
this
|
|
76
|
+
this._search = new URLSearchParams(val);
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
get hash() {
|
|
81
|
-
return this
|
|
80
|
+
return this._hash;
|
|
82
81
|
}
|
|
83
82
|
set hash(val) {
|
|
84
83
|
if (isString(val)) {
|
|
85
84
|
val = val.trim();
|
|
86
|
-
if (val) this
|
|
87
|
-
else this
|
|
85
|
+
if (val) this._hash = val.startsWith("#") ? val : `#${val}`;
|
|
86
|
+
else this._hash = "";
|
|
88
87
|
}
|
|
89
88
|
}
|
|
90
89
|
get href() {
|
|
@@ -115,7 +114,7 @@ var TaroURL = class {
|
|
|
115
114
|
}
|
|
116
115
|
}
|
|
117
116
|
get searchParams() {
|
|
118
|
-
return this
|
|
117
|
+
return this._search;
|
|
119
118
|
}
|
|
120
119
|
toString() {
|
|
121
120
|
return this.href;
|
package/dist/bom/URL.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"URL.js","names":[
|
|
1
|
+
{"version":3,"file":"URL.js","names":[],"sources":["../../src/bom/URL.ts"],"sourcesContent":["import { isString, isUndefined } from '@spcsn/taro-shared';\n\nimport env from '../env';\nimport { URLSearchParams } from './URLSearchParams';\n\nclass TaroURL {\n static createObjectURL() {\n throw new Error('Oops, not support URL.createObjectURL() in miniprogram.');\n }\n\n static revokeObjectURL() {\n throw new Error('Oops, not support URL.revokeObjectURL() in miniprogram.');\n }\n\n /* private property */\n private _hash = '';\n private _hostname = '';\n private _pathname = '';\n private _port = '';\n private _protocol = '';\n private _search: URLSearchParams;\n\n constructor(url: string, base?: string) {\n if (!isString(url)) url = String(url);\n\n const parseResult = parseUrlBase(url, base);\n const { hash, hostname, pathname, port, protocol, search } = parseResult;\n\n this._hash = hash;\n this._hostname = hostname;\n this._pathname = pathname || '/';\n this._port = port;\n this._protocol = protocol;\n this._search = new URLSearchParams(search);\n }\n\n /* public property */\n get protocol() {\n return this._protocol;\n }\n\n set protocol(val: string) {\n isString(val) && (this._protocol = val.trim());\n }\n\n get host() {\n return this.hostname + (this.port ? ':' + this.port : '');\n }\n\n set host(val: string) {\n if (val && isString(val)) {\n val = val.trim();\n const { hostname, port } = parseUrl(`//${val}`);\n this.hostname = hostname;\n this.port = port;\n }\n }\n\n get hostname() {\n return this._hostname;\n }\n\n set hostname(val: string) {\n val && isString(val) && (this._hostname = val.trim());\n }\n\n get port() {\n return this._port;\n }\n\n set port(val: string) {\n isString(val) && (this._port = val.trim());\n }\n\n get pathname() {\n return this._pathname;\n }\n\n set pathname(val: string) {\n if (isString(val)) {\n val = val.trim();\n const HEAD_REG = /^(\\/|\\.\\/|\\.\\.\\/)/;\n let temp = val;\n while (HEAD_REG.test(temp)) {\n temp = temp.replace(HEAD_REG, '');\n }\n if (temp) this._pathname = '/' + temp;\n else this._pathname = '/';\n }\n }\n\n get search() {\n const val = this._search.toString();\n return val.length === 0 || val.startsWith('?') ? val : `?${val}`;\n }\n\n set search(val: string) {\n if (isString(val)) {\n val = val.trim();\n this._search = new URLSearchParams(val);\n }\n }\n\n get hash() {\n return this._hash;\n }\n\n set hash(val: string) {\n if (isString(val)) {\n val = val.trim();\n if (val) this._hash = val.startsWith('#') ? val : `#${val}`;\n else this._hash = '';\n }\n }\n\n get href() {\n return `${this.protocol}//${this.host}${this.pathname}${this.search}${this.hash}`;\n }\n\n set href(val: string) {\n if (val && isString(val)) {\n val = val.trim();\n const { protocol, hostname, port, hash, search, pathname } = parseUrl(val);\n this.protocol = protocol;\n this.hostname = hostname;\n this.pathname = pathname;\n this.port = port;\n this.hash = hash;\n this.search = search;\n }\n }\n\n get origin() {\n return `${this.protocol}//${this.host}`;\n }\n\n set origin(val: string) {\n if (val && isString(val)) {\n val = val.trim();\n const { protocol, hostname, port } = parseUrl(val);\n this.protocol = protocol;\n this.hostname = hostname;\n this.port = port;\n }\n }\n\n get searchParams() {\n return this._search;\n }\n\n // public method\n toString() {\n return this.href;\n }\n\n toJSON() {\n return this.toString();\n }\n\n // convenient for deconstructor\n _toRaw() {\n return {\n protocol: this.protocol,\n port: this.port,\n host: this.host,\n hostname: this.hostname,\n pathname: this.pathname,\n hash: this.hash,\n search: this.search,\n origin: this.origin,\n href: this.href,\n };\n }\n}\n\nexport type { TaroURL };\n\n// Note: 小程序端 vite 打包成 commonjs,const URL = xxx 会报错,所以把 URL 改为 TaroURLProvider\nexport const TaroURLProvider: typeof TaroURL = process.env.TARO_PLATFORM === 'web' ? env.window.URL : TaroURL;\n\nexport function parseUrl(url = '') {\n const result = {\n href: '',\n origin: '',\n protocol: '',\n hostname: '',\n host: '',\n port: '',\n pathname: '',\n search: '',\n hash: '',\n };\n if (!url || !isString(url)) return result;\n\n url = url.trim();\n const PATTERN = /^(([^:/?#]+):)?\\/\\/(([^/?#]+):(.+)@)?([^/?#:]*)(:(\\d+))?([^?#]*)(\\?([^#]*))?(#(.*))?/;\n const matches = url.match(PATTERN);\n\n if (!matches) return result;\n\n // TODO: username & password ?\n result.protocol = matches[1] || 'https:';\n result.hostname = matches[6] || 'taro.com';\n result.port = matches[8] || '';\n result.pathname = matches[9] || '/';\n result.search = matches[10] || '';\n result.hash = matches[12] || '';\n result.href = url;\n result.origin = result.protocol + '//' + result.hostname + (result.port ? `:${result.port}` : '');\n result.host = result.hostname + (result.port ? `:${result.port}` : '');\n\n return result;\n}\n\nfunction parseUrlBase(url: string, base?: string) {\n const VALID_URL = /^(https?:)\\/\\//i;\n\n let fullUrl = '';\n let parsedBase: ReturnType<typeof parseUrl> | null = null;\n\n if (!isUndefined(base)) {\n base = String(base).trim();\n if (!VALID_URL.test(base)) throw new TypeError(`Failed to construct 'URL': Invalid base URL`);\n parsedBase = parseUrl(base);\n }\n\n url = String(url).trim();\n\n if (VALID_URL.test(url)) {\n fullUrl = url;\n } else if (parsedBase) {\n if (url) {\n if (url.startsWith('//')) {\n fullUrl = parsedBase.protocol + url;\n } else {\n fullUrl = parsedBase.origin + (url.startsWith('/') ? url : `/${url}`);\n }\n } else {\n fullUrl = parsedBase.href;\n }\n } else {\n throw new TypeError(`Failed to construct 'URL': Invalid URL`);\n }\n\n return parseUrl(fullUrl);\n}\n"],"mappings":";;;;AAKA,IAAM,UAAN,MAAc;CACZ,OAAO,kBAAkB;EACvB,MAAM,IAAI,MAAM,yDAAyD;CAC3E;CAEA,OAAO,kBAAkB;EACvB,MAAM,IAAI,MAAM,yDAAyD;CAC3E;CAUA,YAAY,KAAa,MAAe;eAPxB;mBACI;mBACA;eACJ;mBACI;EAIlB,IAAI,CAAC,SAAS,GAAG,GAAG,MAAM,OAAO,GAAG;EAGpC,MAAM,EAAE,MAAM,UAAU,UAAU,MAAM,UAAU,WAD9B,aAAa,KAAK,IACiC;EAEvE,KAAK,QAAQ;EACb,KAAK,YAAY;EACjB,KAAK,YAAY,YAAY;EAC7B,KAAK,QAAQ;EACb,KAAK,YAAY;EACjB,KAAK,UAAU,IAAI,gBAAgB,MAAM;CAC3C;CAGA,IAAI,WAAW;EACb,OAAO,KAAK;CACd;CAEA,IAAI,SAAS,KAAa;EACxB,SAAS,GAAG,MAAM,KAAK,YAAY,IAAI,KAAK;CAC9C;CAEA,IAAI,OAAO;EACT,OAAO,KAAK,YAAY,KAAK,OAAO,MAAM,KAAK,OAAO;CACxD;CAEA,IAAI,KAAK,KAAa;EACpB,IAAI,OAAO,SAAS,G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M;CAChC,OAAO,WAAW,QAAQ,MAAM;CAChC,OAAO,OAAO,QAAQ,MAAM;CAC5B,OAAO,WAAW,QAAQ,MAAM;CAChC,OAAO,SAAS,QAAQ,OAAO;CAC/B,OAAO,OAAO,QAAQ,OAAO;CAC7B,OAAO,OAAO;CACd,OAAO,SAAS,OAAO,WAAW,OAAO,OAAO,YAAY,OAAO,OAAO,IAAI,OAAO,SAAS;CAC9F,OAAO,OAAO,OAAO,YAAY,OAAO,OAAO,IAAI,OAAO,SAAS;CAEnE,OAAO;AACT;AAEA,SAAS,aAAa,KAAa,MAAe;CAChD,MAAM,YAAY;CAElB,IAAI,UAAU;CACd,IAAI,aAAiD;CAErD,IAAI,CAAC,YAAY,IAAI,GAAG;EACtB,OAAO,OAAO,IAAI,EAAE,KAAK;EACzB,IAAI,CAAC,UAAU,KAAK,IAAI,GAAG,MAAM,IAAI,UAAU,6CAA6C;EAC5F,aAAa,SAAS,IAAI;CAC5B;CAEA,MAAM,OAAO,GAAG,EAAE,KAAK;CAEvB,IAAI,UAAU,KAAK,GAAG,GACpB,UAAU;MACL,IAAI,YACT,IAAI,KACF,IAAI,IAAI,WAAW,IAAI,GACrB,UAAU,WAAW,WAAW;MAEhC,UAAU,WAAW,UAAU,IAAI,WAAW,GAAG,IAAI,MAAM,IAAI;MAGjE,UAAU,WAAW;MAGvB,MAAM,IAAI,UAAU,wCAAwC;CAG9D,OAAO,SAAS,OAAO;AACzB"}
|
|
@@ -30,10 +30,10 @@ function encode(str) {
|
|
|
30
30
|
return encodeURIComponent(str).replace(findReg, replacer);
|
|
31
31
|
}
|
|
32
32
|
const URLSearchParams = process.env.TARO_PLATFORM === "web" ? env.window.URLSearchParams : class {
|
|
33
|
-
#dict = Object.create(null);
|
|
34
33
|
constructor(query) {
|
|
34
|
+
this._dict = Object.create(null);
|
|
35
35
|
query ??= "";
|
|
36
|
-
const dict = this
|
|
36
|
+
const dict = this._dict;
|
|
37
37
|
if (typeof query === "string") {
|
|
38
38
|
if (query.charAt(0) === "?") query = query.slice(1);
|
|
39
39
|
for (let pairs = query.split("&"), i = 0, length = pairs.length; i < length; i++) {
|
|
@@ -54,30 +54,30 @@ const URLSearchParams = process.env.TARO_PLATFORM === "web" ? env.window.URLSear
|
|
|
54
54
|
else for (const key in query) appendTo(dict, key, query[key]);
|
|
55
55
|
}
|
|
56
56
|
append(name, value) {
|
|
57
|
-
appendTo(this
|
|
57
|
+
appendTo(this._dict, name, value);
|
|
58
58
|
}
|
|
59
59
|
delete(name) {
|
|
60
|
-
delete this
|
|
60
|
+
delete this._dict[name];
|
|
61
61
|
}
|
|
62
62
|
get(name) {
|
|
63
|
-
const dict = this
|
|
63
|
+
const dict = this._dict;
|
|
64
64
|
return name in dict ? dict[name][0] : null;
|
|
65
65
|
}
|
|
66
66
|
getAll(name) {
|
|
67
|
-
const dict = this
|
|
67
|
+
const dict = this._dict;
|
|
68
68
|
return name in dict ? dict[name].slice(0) : [];
|
|
69
69
|
}
|
|
70
70
|
has(name) {
|
|
71
|
-
return name in this
|
|
71
|
+
return name in this._dict;
|
|
72
72
|
}
|
|
73
73
|
keys() {
|
|
74
|
-
return Object.keys(this
|
|
74
|
+
return Object.keys(this._dict);
|
|
75
75
|
}
|
|
76
76
|
set(name, value) {
|
|
77
|
-
this
|
|
77
|
+
this._dict[name] = ["" + value];
|
|
78
78
|
}
|
|
79
79
|
forEach(callback, thisArg) {
|
|
80
|
-
const dict = this
|
|
80
|
+
const dict = this._dict;
|
|
81
81
|
Object.getOwnPropertyNames(dict).forEach(function(name) {
|
|
82
82
|
dict[name].forEach(function(value) {
|
|
83
83
|
callback.call(thisArg, value, name, this);
|
|
@@ -88,7 +88,7 @@ const URLSearchParams = process.env.TARO_PLATFORM === "web" ? env.window.URLSear
|
|
|
88
88
|
return {};
|
|
89
89
|
}
|
|
90
90
|
toString() {
|
|
91
|
-
const dict = this
|
|
91
|
+
const dict = this._dict;
|
|
92
92
|
const query = [];
|
|
93
93
|
for (const key in dict) {
|
|
94
94
|
const name = encode(key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"URLSearchParams.js","names":[
|
|
1
|
+
{"version":3,"file":"URLSearchParams.js","names":[],"sources":["../../src/bom/URLSearchParams.ts"],"sourcesContent":["import { isArray } from '@spcsn/taro-shared';\n\nimport env from '../env';\n\nconst findReg = /[!'()~]|%20|%00/g;\nconst plusReg = /\\+/g;\nconst replaceCharMap = {\n '!': '%21',\n \"'\": '%27',\n '(': '%28',\n ')': '%29',\n '~': '%7E',\n '%20': '+',\n '%00': '\\x00',\n};\n\nfunction replacer(match: string) {\n return replaceCharMap[match];\n}\n\nfunction appendTo(dict: Record<string, string[]>, name: string, value: string) {\n const res = isArray(value) ? value.join(',') : value;\n if (name in dict) dict[name].push(res);\n else dict[name] = [res];\n}\n\nfunction addEach(value: string, key: string) {\n appendTo(this, key, value);\n}\n\nfunction decode(str: string) {\n return decodeURIComponent(str.replace(plusReg, ' '));\n}\n\nfunction encode(str: string) {\n return encodeURIComponent(str).replace(findReg, replacer);\n}\n\nexport const URLSearchParams =\n process.env.TARO_PLATFORM === 'web'\n ? env.window.URLSearchParams\n : class {\n private _dict = Object.create(null);\n\n constructor(query) {\n query ??= '';\n\n const dict = this._dict;\n\n if (typeof query === 'string') {\n if (query.charAt(0) === '?') {\n query = query.slice(1);\n }\n for (let pairs = query.split('&'), i = 0, length = pairs.length; i < length; i++) {\n const value = pairs[i];\n const index = value.indexOf('=');\n\n // 针对不规范的 url 参数做容错处理,如:word=你%好\n try {\n if (index > -1) {\n appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));\n } else if (value.length) {\n appendTo(dict, decode(value), '');\n }\n } catch (err) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`[Taro warn] URL 参数 ${value} decode 异常`);\n }\n }\n }\n } else {\n if (isArray(query)) {\n for (let i = 0, length = query.length; i < length; i++) {\n const value = query[i];\n appendTo(dict, value[0], value[1]);\n }\n } else if (query.forEach) {\n query.forEach(addEach, dict);\n } else {\n for (const key in query) {\n appendTo(dict, key, query[key]);\n }\n }\n }\n }\n\n append(name: string, value: string) {\n appendTo(this._dict, name, value);\n }\n\n delete(name: string) {\n delete this._dict[name];\n }\n\n get(name: string) {\n const dict = this._dict;\n return name in dict ? dict[name][0] : null;\n }\n\n getAll(name: string) {\n const dict = this._dict;\n return name in dict ? dict[name].slice(0) : [];\n }\n\n has(name: string) {\n return name in this._dict;\n }\n\n keys() {\n return Object.keys(this._dict);\n }\n\n set(name: string, value: string) {\n this._dict[name] = ['' + value];\n }\n\n forEach(callback, thisArg) {\n const dict = this._dict;\n Object.getOwnPropertyNames(dict).forEach(function (name) {\n dict[name].forEach(function (value: string) {\n callback.call(thisArg, value, name, this);\n }, this);\n }, this);\n }\n\n toJSON() {\n return {};\n }\n\n toString() {\n const dict = this._dict;\n const query: any[] = [];\n for (const key in dict) {\n const name = encode(key);\n for (let i = 0, value = dict[key]; i < value.length; i++) {\n query.push(name + '=' + encode(value[i]));\n }\n }\n return query.join('&');\n }\n };\n"],"mappings":";;;AAIA,MAAM,UAAU;AAChB,MAAM,UAAU;AAChB,MAAM,iBAAiB;CACrB,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,OAAO;CACP,OAAO;AACT;AAEA,SAAS,SAAS,OAAe;CAC/B,OAAO,eAAe;AACxB;AAEA,SAAS,SAAS,MAAgC,MAAc,OAAe;CAC7E,MAAM,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,GAAG,IAAI;CAC/C,IAAI,QAAQ,MAAM,KAAK,MAAM,KAAK,GAAG;MAChC,KAAK,QAAQ,CAAC,GAAG;AACxB;AAEA,SAAS,QAAQ,OAAe,KAAa;CAC3C,SAAS,MAAM,KAAK,KAAK;AAC3B;AAEA,SAAS,OAAO,KAAa;CAC3B,OAAO,mBAAmB,IAAI,QAAQ,SAAS,GAAG,CAAC;AACrD;AAEA,SAAS,OAAO,KAAa;CAC3B,OAAO,mBAAmB,GAA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,OAAO,KAAK;EAClB,OAAO,QAAQ,OAAO,KAAK,MAAM,MAAM,CAAC,IAAI,CAAC;CAC/C;CAEA,IAAI,MAAc;EAChB,OAAO,QAAQ,KAAK;CACtB;CAEA,OAAO;EACL,OAAO,OAAO,KAAK,KAAK,KAAK;CAC/B;CAEA,IAAI,MAAc,OAAe;EAC/B,KAAK,MAAM,QAAQ,CAAC,KAAK,KAAK;CAChC;CAEA,QAAQ,UAAU,SAAS;EACzB,MAAM,OAAO,KAAK;EAClB,OAAO,oBAAoB,IAAI,EAAE,QAAQ,SAAU,MAAM;GACvD,KAAK,MAAM,QAAQ,SAAU,OAAe;IAC1C,SAAS,KAAK,SAAS,OAAO,MAAM,IAAI;GAC1C,GAAG,IAAI;EACT,GAAG,IAAI;CACT;CAEA,SAAS;EACP,OAAO,CAAC;CACV;CAEA,WAAW;EACT,MAAM,OAAO,KAAK;EAClB,MAAM,QAAe,CAAC;EACtB,KAAK,MAAM,OAAO,MAAM;GACtB,MAAM,OAAO,OAAO,GAAG;GACvB,KAAK,IAAI,IAAI,GAAG,QAAQ,KAAK,MAAM,IAAI,MAAM,QAAQ,KACnD,MAAM,KAAK,OAAO,MAAM,OAAO,MAAM,EAAE,CAAC;EAE5C;EACA,OAAO,MAAM,KAAK,GAAG;CACvB;AACF"}
|
package/dist/bom/history.d.ts
CHANGED
|
@@ -15,8 +15,12 @@ type HistoryContext = {
|
|
|
15
15
|
cur: number;
|
|
16
16
|
};
|
|
17
17
|
declare class TaroHistory extends Events {
|
|
18
|
-
|
|
18
|
+
private _location;
|
|
19
|
+
private _stack;
|
|
20
|
+
private _cur;
|
|
21
|
+
private _window;
|
|
19
22
|
constructor(location: TaroLocation, options: Options);
|
|
23
|
+
private _reset;
|
|
20
24
|
get length(): number;
|
|
21
25
|
get state(): Record<string, any> | null;
|
|
22
26
|
go(delta: number): void;
|
package/dist/bom/history.js
CHANGED
|
@@ -6,70 +6,68 @@ import { isNumber, isString } from "@spcsn/taro-shared";
|
|
|
6
6
|
//#region src/bom/history.ts
|
|
7
7
|
const cache = new RuntimeCache("history");
|
|
8
8
|
var TaroHistory = class extends Events {
|
|
9
|
-
#location;
|
|
10
|
-
#stack = [];
|
|
11
|
-
#cur = 0;
|
|
12
|
-
#window;
|
|
13
9
|
constructor(location, options) {
|
|
14
10
|
super();
|
|
15
|
-
this
|
|
16
|
-
this
|
|
17
|
-
this
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this
|
|
11
|
+
this._stack = [];
|
|
12
|
+
this._cur = 0;
|
|
13
|
+
this._window = options.window;
|
|
14
|
+
this._location = location;
|
|
15
|
+
this._location.on("__record_history__", (href) => {
|
|
16
|
+
this._cur++;
|
|
17
|
+
this._stack = this._stack.slice(0, this._cur);
|
|
18
|
+
this._stack.push({
|
|
21
19
|
state: null,
|
|
22
20
|
title: "",
|
|
23
21
|
url: href
|
|
24
22
|
});
|
|
25
23
|
}, null);
|
|
26
|
-
this
|
|
27
|
-
this
|
|
24
|
+
this._location.on("__reset_history__", (href) => {
|
|
25
|
+
this._reset(href);
|
|
28
26
|
}, null);
|
|
29
27
|
this.on("0", () => {
|
|
30
|
-
this
|
|
28
|
+
this._reset();
|
|
31
29
|
}, null);
|
|
32
30
|
this.on("1", (pageId) => {
|
|
33
31
|
cache.set(pageId, {
|
|
34
|
-
location: this
|
|
35
|
-
stack: this
|
|
36
|
-
cur: this
|
|
32
|
+
location: this._location,
|
|
33
|
+
stack: this._stack.slice(),
|
|
34
|
+
cur: this._cur
|
|
37
35
|
});
|
|
38
36
|
}, null);
|
|
39
37
|
this.on("2", (pageId) => {
|
|
40
38
|
if (cache.has(pageId)) {
|
|
41
39
|
const ctx = cache.get(pageId);
|
|
42
|
-
this
|
|
43
|
-
this
|
|
44
|
-
this
|
|
40
|
+
this._location = ctx.location;
|
|
41
|
+
this._stack = ctx.stack;
|
|
42
|
+
this._cur = ctx.cur;
|
|
45
43
|
}
|
|
46
44
|
}, null);
|
|
47
45
|
this.on("3", (pageId) => {
|
|
48
46
|
cache.delete(pageId);
|
|
49
47
|
}, null);
|
|
50
|
-
this
|
|
48
|
+
this._reset();
|
|
51
49
|
}
|
|
52
|
-
|
|
53
|
-
this
|
|
50
|
+
_reset(href = "") {
|
|
51
|
+
this._stack = [{
|
|
54
52
|
state: null,
|
|
55
53
|
title: "",
|
|
56
|
-
url: href || this
|
|
54
|
+
url: href || this._location.href
|
|
57
55
|
}];
|
|
58
|
-
this
|
|
56
|
+
this._cur = 0;
|
|
59
57
|
}
|
|
60
58
|
get length() {
|
|
61
|
-
return this
|
|
59
|
+
return this._stack.length;
|
|
62
60
|
}
|
|
63
61
|
get state() {
|
|
64
|
-
return this
|
|
62
|
+
return this._stack[this._cur].state;
|
|
65
63
|
}
|
|
66
64
|
go(delta) {
|
|
67
65
|
if (!isNumber(delta) || isNaN(delta)) return;
|
|
68
|
-
let targetIdx = this
|
|
66
|
+
let targetIdx = this._cur + delta;
|
|
69
67
|
targetIdx = Math.min(Math.max(targetIdx, 0), this.length - 1);
|
|
70
|
-
this
|
|
71
|
-
this
|
|
72
|
-
this
|
|
68
|
+
this._cur = targetIdx;
|
|
69
|
+
this._location.trigger("__set_href_without_history__", this._stack[this._cur].url);
|
|
70
|
+
this._window.trigger("popstate", this._stack[this._cur]);
|
|
73
71
|
}
|
|
74
72
|
back() {
|
|
75
73
|
this.go(-1);
|
|
@@ -79,23 +77,23 @@ var TaroHistory = class extends Events {
|
|
|
79
77
|
}
|
|
80
78
|
pushState(state, title, url) {
|
|
81
79
|
if (!url || !isString(url)) return;
|
|
82
|
-
this
|
|
83
|
-
this
|
|
80
|
+
this._stack = this._stack.slice(0, this._cur + 1);
|
|
81
|
+
this._stack.push({
|
|
84
82
|
state,
|
|
85
83
|
title,
|
|
86
84
|
url
|
|
87
85
|
});
|
|
88
|
-
this
|
|
89
|
-
this
|
|
86
|
+
this._cur = this.length - 1;
|
|
87
|
+
this._location.trigger("__set_href_without_history__", url);
|
|
90
88
|
}
|
|
91
89
|
replaceState(state, title, url) {
|
|
92
90
|
if (!url || !isString(url)) return;
|
|
93
|
-
this
|
|
91
|
+
this._stack[this._cur] = {
|
|
94
92
|
state,
|
|
95
93
|
title,
|
|
96
94
|
url
|
|
97
95
|
};
|
|
98
|
-
this
|
|
96
|
+
this._location.trigger("__set_href_without_history__", url);
|
|
99
97
|
}
|
|
100
98
|
get cache() {
|
|
101
99
|
return cache;
|
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 private _location: TaroLocation;\n private _stack: HistoryState[] = [];\n private _cur = 0;\n\n private _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 private _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;gBANyB,CAAC;cACnB;EAOb,KAAK,UAAU,QAAQ;EACvB,KAAK,YAAY;EAEjB,KAAK,UAAU,GACb,uBACC,SAAiB;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,QAAQ,QAAQ,YAAY,KAAK,OAAO,KAAK,KAAK;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,KAAK,SAAS,KAAK,OAAO,MAAM,GAAG,KAAK,OAAO,CAAC;EAChD,KAAK,OAAO,KAAK;GACf;GACA;GACA;EACF,CAAC;EACD,KAAK,OAAO,KAAK,SAAS;EAE1B,KAAK,UAAU,QAAQ,gCAAgC,GAAG;CAC5D;CAEA,aAAa,OAAY,OAAe,KAAa;EACnD,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,GAAG;EAC5B,KAAK,OAAO,KAAK,QAAQ;GACvB;GACA;GACA;EACF;EAEA,KAAK,UAAU,QAAQ,gCAAgC,GAAG;CAC5D;CAGA,IAAI,QAAQ;EACV,OAAO;CACT;AACF;AAGA,MAAa,UAA8B,QAAQ,IAAI,kBAAkB,QAAQ,IAAI,OAAO,UAAU"}
|
package/dist/bom/location.d.ts
CHANGED
|
@@ -7,8 +7,18 @@ type LocationContext = {
|
|
|
7
7
|
lastHref: string;
|
|
8
8
|
};
|
|
9
9
|
declare class TaroLocation extends Events {
|
|
10
|
-
|
|
10
|
+
private _url;
|
|
11
|
+
private _noCheckUrl;
|
|
12
|
+
private _window;
|
|
11
13
|
constructor(options: Options);
|
|
14
|
+
private _reset;
|
|
15
|
+
private _getPreValue;
|
|
16
|
+
private _rollBack;
|
|
17
|
+
private _recordHistory;
|
|
18
|
+
/**
|
|
19
|
+
* 校验url的变化,是否需要更新history
|
|
20
|
+
*/
|
|
21
|
+
private _checkUrlChange;
|
|
12
22
|
get protocol(): string;
|
|
13
23
|
set protocol(val: string);
|
|
14
24
|
get host(): string;
|