@tarojs/runtime 3.6.0-canary.9 → 3.6.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +119 -1
- package/dist/bom/URL.d.ts +61 -0
- package/dist/bom/location.d.ts +1 -1
- package/dist/constants/index.d.ts +4 -2
- package/dist/dom/anchor-element.d.ts +13 -0
- package/dist/dom/event.d.ts +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/runtime.esm.d.ts +149 -4
- package/dist/runtime.esm.js +496 -311
- package/dist/runtime.esm.js.map +1 -1
- package/package.json +3 -2
package/dist/runtime.esm.js
CHANGED
|
@@ -43,15 +43,17 @@ const ON_SHOW = 'onShow';
|
|
|
43
43
|
const ON_HIDE = 'onHide';
|
|
44
44
|
const OPTIONS = 'options';
|
|
45
45
|
const EXTERNAL_CLASSES = 'externalClasses';
|
|
46
|
+
const EVENT_CALLBACK_RESULT = 'e_result';
|
|
46
47
|
const BEHAVIORS = 'behaviors';
|
|
48
|
+
const A = 'a';
|
|
47
49
|
/**
|
|
48
50
|
* 页面上下文切换时的行为
|
|
49
51
|
*/
|
|
50
52
|
var CONTEXT_ACTIONS;
|
|
51
53
|
(function (CONTEXT_ACTIONS) {
|
|
52
54
|
CONTEXT_ACTIONS["INIT"] = "0";
|
|
53
|
-
CONTEXT_ACTIONS["
|
|
54
|
-
CONTEXT_ACTIONS["
|
|
55
|
+
CONTEXT_ACTIONS["RESTORE"] = "1";
|
|
56
|
+
CONTEXT_ACTIONS["RECOVER"] = "2";
|
|
55
57
|
CONTEXT_ACTIONS["DESTORY"] = "3";
|
|
56
58
|
})(CONTEXT_ACTIONS || (CONTEXT_ACTIONS = {}));
|
|
57
59
|
|
|
@@ -463,7 +465,7 @@ class TaroEventTarget {
|
|
|
463
465
|
// 因此每次绑定事件都新建一个函数,如果带来了性能问题,可以把这段逻辑抽取到 PReact 插件中。
|
|
464
466
|
const oldHandler = handler;
|
|
465
467
|
handler = function () {
|
|
466
|
-
oldHandler.apply(this, arguments); // this 指向 Element
|
|
468
|
+
return oldHandler.apply(this, arguments); // this 指向 Element
|
|
467
469
|
};
|
|
468
470
|
handler.oldHandler = oldHandler;
|
|
469
471
|
const handlers = this.__handlers[type];
|
|
@@ -1367,6 +1369,9 @@ class TaroElement extends TaroNode {
|
|
|
1367
1369
|
if ((result === false || event._end) && cancelable) {
|
|
1368
1370
|
event.defaultPrevented = true;
|
|
1369
1371
|
}
|
|
1372
|
+
if (!isUndefined(result) && event.mpEvent) {
|
|
1373
|
+
event.mpEvent[EVENT_CALLBACK_RESULT] = result;
|
|
1374
|
+
}
|
|
1370
1375
|
if (event._end && event._stop) {
|
|
1371
1376
|
break;
|
|
1372
1377
|
}
|
|
@@ -2426,6 +2431,13 @@ function createEvent(event, node) {
|
|
|
2426
2431
|
return domEv;
|
|
2427
2432
|
}
|
|
2428
2433
|
const eventsBatch = {};
|
|
2434
|
+
function getEventCBResult(event) {
|
|
2435
|
+
const result = event[EVENT_CALLBACK_RESULT];
|
|
2436
|
+
if (!isUndefined(result)) {
|
|
2437
|
+
delete event[EVENT_CALLBACK_RESULT];
|
|
2438
|
+
}
|
|
2439
|
+
return result;
|
|
2440
|
+
}
|
|
2429
2441
|
// 小程序的事件代理回调函数
|
|
2430
2442
|
function eventHandler(event) {
|
|
2431
2443
|
var _a, _b;
|
|
@@ -2460,6 +2472,7 @@ function eventHandler(event) {
|
|
|
2460
2472
|
}
|
|
2461
2473
|
dispatch();
|
|
2462
2474
|
});
|
|
2475
|
+
return getEventCBResult(event);
|
|
2463
2476
|
}
|
|
2464
2477
|
else {
|
|
2465
2478
|
// 如果上层组件也有绑定同类型的组件,委托给上层组件调用事件回调
|
|
@@ -2468,6 +2481,7 @@ function eventHandler(event) {
|
|
|
2468
2481
|
}
|
|
2469
2482
|
else {
|
|
2470
2483
|
dispatch();
|
|
2484
|
+
return getEventCBResult(event);
|
|
2471
2485
|
}
|
|
2472
2486
|
}
|
|
2473
2487
|
}
|
|
@@ -2715,153 +2729,6 @@ class TaroText extends TaroNode {
|
|
|
2715
2729
|
}
|
|
2716
2730
|
}
|
|
2717
2731
|
|
|
2718
|
-
class TaroDocument extends TaroElement {
|
|
2719
|
-
constructor() {
|
|
2720
|
-
super();
|
|
2721
|
-
this.createEvent = createEvent;
|
|
2722
|
-
this.nodeType = 9 /* NodeType.DOCUMENT_NODE */;
|
|
2723
|
-
this.nodeName = DOCUMENT_ELEMENT_NAME;
|
|
2724
|
-
}
|
|
2725
|
-
createElement(type) {
|
|
2726
|
-
if (type === ROOT_STR) {
|
|
2727
|
-
return new TaroRootElement();
|
|
2728
|
-
}
|
|
2729
|
-
const element = controlledComponent.has(type)
|
|
2730
|
-
? new FormElement()
|
|
2731
|
-
: new TaroElement();
|
|
2732
|
-
element.nodeName = type;
|
|
2733
|
-
element.tagName = type.toUpperCase();
|
|
2734
|
-
return element;
|
|
2735
|
-
}
|
|
2736
|
-
// an ugly fake createElementNS to deal with @vue/runtime-dom's
|
|
2737
|
-
// support mounting app to svg container since vue@3.0.8
|
|
2738
|
-
createElementNS(_svgNS, type) {
|
|
2739
|
-
return this.createElement(type);
|
|
2740
|
-
}
|
|
2741
|
-
createTextNode(text) {
|
|
2742
|
-
return new TaroText(text);
|
|
2743
|
-
}
|
|
2744
|
-
getElementById(id) {
|
|
2745
|
-
const el = eventSource.get(id);
|
|
2746
|
-
return isUndefined(el) ? null : el;
|
|
2747
|
-
}
|
|
2748
|
-
querySelector(query) {
|
|
2749
|
-
// 为了 Vue3 的乞丐版实现
|
|
2750
|
-
if (/^#/.test(query)) {
|
|
2751
|
-
return this.getElementById(query.slice(1));
|
|
2752
|
-
}
|
|
2753
|
-
return null;
|
|
2754
|
-
}
|
|
2755
|
-
querySelectorAll() {
|
|
2756
|
-
// fake hack
|
|
2757
|
-
return [];
|
|
2758
|
-
}
|
|
2759
|
-
// @TODO: @PERF: 在 hydrate 移除掉空的 node
|
|
2760
|
-
createComment() {
|
|
2761
|
-
const textnode = new TaroText('');
|
|
2762
|
-
textnode.nodeName = COMMENT;
|
|
2763
|
-
return textnode;
|
|
2764
|
-
}
|
|
2765
|
-
get defaultView() {
|
|
2766
|
-
return env.window;
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
|
|
2770
|
-
let document$1;
|
|
2771
|
-
if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
2772
|
-
/* eslint-disable no-inner-declarations */
|
|
2773
|
-
function createDocument() {
|
|
2774
|
-
/**
|
|
2775
|
-
* <document>
|
|
2776
|
-
* <html>
|
|
2777
|
-
* <head></head>
|
|
2778
|
-
* <body>
|
|
2779
|
-
* <container>
|
|
2780
|
-
* <app id="app" />
|
|
2781
|
-
* </container>
|
|
2782
|
-
* </body>
|
|
2783
|
-
* </html>
|
|
2784
|
-
* </document>
|
|
2785
|
-
*/
|
|
2786
|
-
const doc = new TaroDocument();
|
|
2787
|
-
const documentCreateElement = doc.createElement.bind(doc);
|
|
2788
|
-
const html = documentCreateElement(HTML);
|
|
2789
|
-
const head = documentCreateElement(HEAD);
|
|
2790
|
-
const body = documentCreateElement(BODY);
|
|
2791
|
-
const app = documentCreateElement(APP);
|
|
2792
|
-
app.id = APP;
|
|
2793
|
-
const container = documentCreateElement(CONTAINER); // 多包一层主要为了兼容 vue
|
|
2794
|
-
doc.appendChild(html);
|
|
2795
|
-
html.appendChild(head);
|
|
2796
|
-
html.appendChild(body);
|
|
2797
|
-
body.appendChild(container);
|
|
2798
|
-
container.appendChild(app);
|
|
2799
|
-
doc.documentElement = html;
|
|
2800
|
-
doc.head = head;
|
|
2801
|
-
doc.body = body;
|
|
2802
|
-
return doc;
|
|
2803
|
-
}
|
|
2804
|
-
document$1 = env.document = createDocument();
|
|
2805
|
-
}
|
|
2806
|
-
else {
|
|
2807
|
-
document$1 = env.document;
|
|
2808
|
-
}
|
|
2809
|
-
|
|
2810
|
-
function getComputedStyle(element) {
|
|
2811
|
-
return element.style;
|
|
2812
|
-
}
|
|
2813
|
-
|
|
2814
|
-
const machine = 'Macintosh';
|
|
2815
|
-
const arch = 'Intel Mac OS X 10_14_5';
|
|
2816
|
-
const engine = 'AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36';
|
|
2817
|
-
const msg = '(' + machine + '; ' + arch + ') ' + engine;
|
|
2818
|
-
const nav = process.env.TARO_ENV === 'h5' ? env.window.navigator : {
|
|
2819
|
-
appCodeName: 'Mozilla',
|
|
2820
|
-
appName: 'Netscape',
|
|
2821
|
-
appVersion: '5.0 ' + msg,
|
|
2822
|
-
cookieEnabled: true,
|
|
2823
|
-
mimeTypes: [],
|
|
2824
|
-
onLine: true,
|
|
2825
|
-
platform: 'MacIntel',
|
|
2826
|
-
plugins: [],
|
|
2827
|
-
product: 'Taro',
|
|
2828
|
-
productSub: '20030107',
|
|
2829
|
-
userAgent: 'Mozilla/5.0 ' + msg,
|
|
2830
|
-
vendor: 'Joyent',
|
|
2831
|
-
vendorSub: ''
|
|
2832
|
-
};
|
|
2833
|
-
|
|
2834
|
-
// https://github.com/myrne/performance-now
|
|
2835
|
-
let now;
|
|
2836
|
-
(function () {
|
|
2837
|
-
let loadTime;
|
|
2838
|
-
if ((typeof performance !== 'undefined' && performance !== null) && performance.now) {
|
|
2839
|
-
now = () => performance.now();
|
|
2840
|
-
}
|
|
2841
|
-
else if (Date.now) {
|
|
2842
|
-
loadTime = Date.now();
|
|
2843
|
-
now = () => Date.now() - loadTime;
|
|
2844
|
-
}
|
|
2845
|
-
else {
|
|
2846
|
-
loadTime = new Date().getTime();
|
|
2847
|
-
now = () => new Date().getTime() - loadTime;
|
|
2848
|
-
}
|
|
2849
|
-
})();
|
|
2850
|
-
let lastTime = 0;
|
|
2851
|
-
// https://gist.github.com/paulirish/1579671
|
|
2852
|
-
// https://gist.github.com/jalbam/5fe05443270fa6d8136238ec72accbc0
|
|
2853
|
-
const _raf = typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame !== null ? requestAnimationFrame : function (callback) {
|
|
2854
|
-
const _now = now();
|
|
2855
|
-
const nextTime = Math.max(lastTime + 16, _now); // First time will execute it immediately but barely noticeable and performance is gained.
|
|
2856
|
-
return setTimeout(function () { callback(lastTime = nextTime); }, nextTime - _now);
|
|
2857
|
-
};
|
|
2858
|
-
const _caf = typeof cancelAnimationFrame !== 'undefined' && cancelAnimationFrame !== null
|
|
2859
|
-
? cancelAnimationFrame
|
|
2860
|
-
: function (seed) {
|
|
2861
|
-
// fix https://github.com/NervJS/taro/issues/7749
|
|
2862
|
-
clearTimeout(seed);
|
|
2863
|
-
};
|
|
2864
|
-
|
|
2865
2732
|
/******************************************************************************
|
|
2866
2733
|
Copyright (c) Microsoft Corporation.
|
|
2867
2734
|
|
|
@@ -3007,6 +2874,376 @@ class URLSearchParams {
|
|
|
3007
2874
|
}
|
|
3008
2875
|
_URLSearchParams_dict = new WeakMap();
|
|
3009
2876
|
|
|
2877
|
+
var _URL_hash, _URL_hostname, _URL_pathname, _URL_port, _URL_protocol, _URL_search;
|
|
2878
|
+
class URL {
|
|
2879
|
+
constructor(url, base) {
|
|
2880
|
+
/* private property */
|
|
2881
|
+
_URL_hash.set(this, '');
|
|
2882
|
+
_URL_hostname.set(this, '');
|
|
2883
|
+
_URL_pathname.set(this, '');
|
|
2884
|
+
_URL_port.set(this, '');
|
|
2885
|
+
_URL_protocol.set(this, '');
|
|
2886
|
+
_URL_search.set(this, '');
|
|
2887
|
+
if (!isString(url))
|
|
2888
|
+
url = String(url);
|
|
2889
|
+
const parseResult = parseUrlBase(url, base);
|
|
2890
|
+
const { hash, hostname, pathname, port, protocol, search } = parseResult;
|
|
2891
|
+
__classPrivateFieldSet(this, _URL_hash, hash, "f");
|
|
2892
|
+
__classPrivateFieldSet(this, _URL_hostname, hostname, "f");
|
|
2893
|
+
__classPrivateFieldSet(this, _URL_pathname, pathname || '/', "f");
|
|
2894
|
+
__classPrivateFieldSet(this, _URL_port, port, "f");
|
|
2895
|
+
__classPrivateFieldSet(this, _URL_protocol, protocol, "f");
|
|
2896
|
+
__classPrivateFieldSet(this, _URL_search, search, "f");
|
|
2897
|
+
}
|
|
2898
|
+
static createObjectURL() {
|
|
2899
|
+
throw new Error('Oops, not support URL.createObjectURL() in miniprogram.');
|
|
2900
|
+
}
|
|
2901
|
+
static revokeObjectURL() {
|
|
2902
|
+
throw new Error('Oops, not support URL.revokeObjectURL() in miniprogram.');
|
|
2903
|
+
}
|
|
2904
|
+
/* public property */
|
|
2905
|
+
get protocol() {
|
|
2906
|
+
return __classPrivateFieldGet(this, _URL_protocol, "f");
|
|
2907
|
+
}
|
|
2908
|
+
set protocol(val) {
|
|
2909
|
+
isString(val) && (__classPrivateFieldSet(this, _URL_protocol, val.trim(), "f"));
|
|
2910
|
+
}
|
|
2911
|
+
get host() {
|
|
2912
|
+
return this.hostname + (this.port ? ':' + this.port : '');
|
|
2913
|
+
}
|
|
2914
|
+
set host(val) {
|
|
2915
|
+
if (val && isString(val)) {
|
|
2916
|
+
val = val.trim();
|
|
2917
|
+
const { hostname, port } = parseUrl(`//${val}`);
|
|
2918
|
+
this.hostname = hostname;
|
|
2919
|
+
this.port = port;
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
get hostname() {
|
|
2923
|
+
return __classPrivateFieldGet(this, _URL_hostname, "f");
|
|
2924
|
+
}
|
|
2925
|
+
set hostname(val) {
|
|
2926
|
+
val && isString(val) && (__classPrivateFieldSet(this, _URL_hostname, val.trim(), "f"));
|
|
2927
|
+
}
|
|
2928
|
+
get port() {
|
|
2929
|
+
return __classPrivateFieldGet(this, _URL_port, "f");
|
|
2930
|
+
}
|
|
2931
|
+
set port(val) {
|
|
2932
|
+
isString(val) && (__classPrivateFieldSet(this, _URL_port, val.trim(), "f"));
|
|
2933
|
+
}
|
|
2934
|
+
get pathname() {
|
|
2935
|
+
return __classPrivateFieldGet(this, _URL_pathname, "f");
|
|
2936
|
+
}
|
|
2937
|
+
set pathname(val) {
|
|
2938
|
+
if (isString(val)) {
|
|
2939
|
+
val = val.trim();
|
|
2940
|
+
const HEAD_REG = /^(\/|\.\/|\.\.\/)/;
|
|
2941
|
+
let temp = val;
|
|
2942
|
+
while (HEAD_REG.test(temp)) {
|
|
2943
|
+
temp = temp.replace(HEAD_REG, '');
|
|
2944
|
+
}
|
|
2945
|
+
if (temp)
|
|
2946
|
+
__classPrivateFieldSet(this, _URL_pathname, '/' + temp, "f");
|
|
2947
|
+
else
|
|
2948
|
+
__classPrivateFieldSet(this, _URL_pathname, '/', "f");
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
get search() {
|
|
2952
|
+
return __classPrivateFieldGet(this, _URL_search, "f");
|
|
2953
|
+
}
|
|
2954
|
+
set search(val) {
|
|
2955
|
+
if (isString(val)) {
|
|
2956
|
+
val = val.trim();
|
|
2957
|
+
if (val)
|
|
2958
|
+
__classPrivateFieldSet(this, _URL_search, val.startsWith('?') ? val : `?${val}`, "f");
|
|
2959
|
+
else
|
|
2960
|
+
__classPrivateFieldSet(this, _URL_search, '', "f");
|
|
2961
|
+
}
|
|
2962
|
+
}
|
|
2963
|
+
get hash() {
|
|
2964
|
+
return __classPrivateFieldGet(this, _URL_hash, "f");
|
|
2965
|
+
}
|
|
2966
|
+
set hash(val) {
|
|
2967
|
+
if (isString(val)) {
|
|
2968
|
+
val = val.trim();
|
|
2969
|
+
if (val)
|
|
2970
|
+
__classPrivateFieldSet(this, _URL_hash, val.startsWith('#') ? val : `#${val}`, "f");
|
|
2971
|
+
else
|
|
2972
|
+
__classPrivateFieldSet(this, _URL_hash, '', "f");
|
|
2973
|
+
}
|
|
2974
|
+
}
|
|
2975
|
+
get href() {
|
|
2976
|
+
return `${this.protocol}//${this.host}${this.pathname}${this.search}${this.hash}`;
|
|
2977
|
+
}
|
|
2978
|
+
set href(val) {
|
|
2979
|
+
if (val && isString(val)) {
|
|
2980
|
+
val = val.trim();
|
|
2981
|
+
const { protocol, hostname, port, hash, search, pathname } = parseUrl(val);
|
|
2982
|
+
this.protocol = protocol;
|
|
2983
|
+
this.hostname = hostname;
|
|
2984
|
+
this.pathname = pathname;
|
|
2985
|
+
this.port = port;
|
|
2986
|
+
this.hash = hash;
|
|
2987
|
+
this.search = search;
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
get origin() {
|
|
2991
|
+
return `${this.protocol}//${this.host}`;
|
|
2992
|
+
}
|
|
2993
|
+
set origin(val) {
|
|
2994
|
+
if (val && isString(val)) {
|
|
2995
|
+
val = val.trim();
|
|
2996
|
+
const { protocol, hostname, port } = parseUrl(val);
|
|
2997
|
+
this.protocol = protocol;
|
|
2998
|
+
this.hostname = hostname;
|
|
2999
|
+
this.port = port;
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
get searchParams() {
|
|
3003
|
+
return new URLSearchParams(this.search);
|
|
3004
|
+
}
|
|
3005
|
+
// public method
|
|
3006
|
+
toString() {
|
|
3007
|
+
return this.href;
|
|
3008
|
+
}
|
|
3009
|
+
toJSON() {
|
|
3010
|
+
return this.toString();
|
|
3011
|
+
}
|
|
3012
|
+
// convenient for deconstructor
|
|
3013
|
+
_toRaw() {
|
|
3014
|
+
return {
|
|
3015
|
+
protocol: this.protocol,
|
|
3016
|
+
port: this.port,
|
|
3017
|
+
host: this.host,
|
|
3018
|
+
hostname: this.hostname,
|
|
3019
|
+
pathname: this.pathname,
|
|
3020
|
+
hash: this.hash,
|
|
3021
|
+
search: this.search,
|
|
3022
|
+
origin: this.origin,
|
|
3023
|
+
href: this.href,
|
|
3024
|
+
};
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
_URL_hash = new WeakMap(), _URL_hostname = new WeakMap(), _URL_pathname = new WeakMap(), _URL_port = new WeakMap(), _URL_protocol = new WeakMap(), _URL_search = new WeakMap();
|
|
3028
|
+
function parseUrl(url = '') {
|
|
3029
|
+
const result = {
|
|
3030
|
+
href: '',
|
|
3031
|
+
origin: '',
|
|
3032
|
+
protocol: '',
|
|
3033
|
+
hostname: '',
|
|
3034
|
+
host: '',
|
|
3035
|
+
port: '',
|
|
3036
|
+
pathname: '',
|
|
3037
|
+
search: '',
|
|
3038
|
+
hash: ''
|
|
3039
|
+
};
|
|
3040
|
+
if (!url || !isString(url))
|
|
3041
|
+
return result;
|
|
3042
|
+
url = url.trim();
|
|
3043
|
+
const PATTERN = /^(([^:/?#]+):)?\/\/(([^/?#]+):(.+)@)?([^/?#:]*)(:(\d+))?([^?#]*)(\?([^#]*))?(#(.*))?/;
|
|
3044
|
+
const matches = url.match(PATTERN);
|
|
3045
|
+
if (!matches)
|
|
3046
|
+
return result;
|
|
3047
|
+
// TODO: username & password ?
|
|
3048
|
+
result.protocol = matches[1] || 'https:';
|
|
3049
|
+
result.hostname = matches[6] || 'taro.com';
|
|
3050
|
+
result.port = matches[8] || '';
|
|
3051
|
+
result.pathname = matches[9] || '/';
|
|
3052
|
+
result.search = matches[10] || '';
|
|
3053
|
+
result.hash = matches[12] || '';
|
|
3054
|
+
result.href = url;
|
|
3055
|
+
result.origin = result.protocol + '//' + result.hostname;
|
|
3056
|
+
result.host = result.hostname + (result.port ? `:${result.port}` : '');
|
|
3057
|
+
return result;
|
|
3058
|
+
}
|
|
3059
|
+
function parseUrlBase(url, base) {
|
|
3060
|
+
const VALID_URL = /^(https?:)\/\//i;
|
|
3061
|
+
let fullUrl = '';
|
|
3062
|
+
let parsedBase = null;
|
|
3063
|
+
if (!isUndefined(base)) {
|
|
3064
|
+
base = String(base).trim();
|
|
3065
|
+
if (!VALID_URL.test(base))
|
|
3066
|
+
throw new TypeError(`Failed to construct 'URL': Invalid base URL`);
|
|
3067
|
+
parsedBase = parseUrl(base);
|
|
3068
|
+
}
|
|
3069
|
+
url = String(url).trim();
|
|
3070
|
+
if (VALID_URL.test(url)) {
|
|
3071
|
+
fullUrl = url;
|
|
3072
|
+
}
|
|
3073
|
+
else if (parsedBase) {
|
|
3074
|
+
if (url) {
|
|
3075
|
+
if (url.startsWith('//')) {
|
|
3076
|
+
fullUrl = parsedBase.protocol + url;
|
|
3077
|
+
}
|
|
3078
|
+
else {
|
|
3079
|
+
fullUrl = parsedBase.origin + (url.startsWith('/') ? url : `/${url}`);
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
else {
|
|
3083
|
+
fullUrl = parsedBase.href;
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
else {
|
|
3087
|
+
throw new TypeError(`Failed to construct 'URL': Invalid URL`);
|
|
3088
|
+
}
|
|
3089
|
+
return parseUrl(fullUrl);
|
|
3090
|
+
}
|
|
3091
|
+
|
|
3092
|
+
class AnchorElement extends TaroElement {
|
|
3093
|
+
get href() {
|
|
3094
|
+
var _a;
|
|
3095
|
+
return (_a = this.props["href" /* AnchorElementAttrs.HREF */]) !== null && _a !== void 0 ? _a : '';
|
|
3096
|
+
}
|
|
3097
|
+
set href(val) {
|
|
3098
|
+
this.setAttribute("href" /* AnchorElementAttrs.HREF */, val);
|
|
3099
|
+
}
|
|
3100
|
+
get protocol() {
|
|
3101
|
+
var _a;
|
|
3102
|
+
return (_a = this.props["protocol" /* AnchorElementAttrs.PROTOCOL */]) !== null && _a !== void 0 ? _a : '';
|
|
3103
|
+
}
|
|
3104
|
+
get host() {
|
|
3105
|
+
var _a;
|
|
3106
|
+
return (_a = this.props["host" /* AnchorElementAttrs.HOST */]) !== null && _a !== void 0 ? _a : '';
|
|
3107
|
+
}
|
|
3108
|
+
get search() {
|
|
3109
|
+
var _a;
|
|
3110
|
+
return (_a = this.props["search" /* AnchorElementAttrs.SEARCH */]) !== null && _a !== void 0 ? _a : '';
|
|
3111
|
+
}
|
|
3112
|
+
get hash() {
|
|
3113
|
+
var _a;
|
|
3114
|
+
return (_a = this.props["hash" /* AnchorElementAttrs.HASH */]) !== null && _a !== void 0 ? _a : '';
|
|
3115
|
+
}
|
|
3116
|
+
get hostname() {
|
|
3117
|
+
var _a;
|
|
3118
|
+
return (_a = this.props["hostname" /* AnchorElementAttrs.HOSTNAME */]) !== null && _a !== void 0 ? _a : '';
|
|
3119
|
+
}
|
|
3120
|
+
get port() {
|
|
3121
|
+
var _a;
|
|
3122
|
+
return (_a = this.props["port" /* AnchorElementAttrs.PORT */]) !== null && _a !== void 0 ? _a : '';
|
|
3123
|
+
}
|
|
3124
|
+
get pathname() {
|
|
3125
|
+
var _a;
|
|
3126
|
+
return (_a = this.props["pathname" /* AnchorElementAttrs.PATHNAME */]) !== null && _a !== void 0 ? _a : '';
|
|
3127
|
+
}
|
|
3128
|
+
setAttribute(qualifiedName, value) {
|
|
3129
|
+
if (qualifiedName === "href" /* AnchorElementAttrs.HREF */) {
|
|
3130
|
+
const willSetAttr = parseUrl(value);
|
|
3131
|
+
for (const k in willSetAttr) {
|
|
3132
|
+
super.setAttribute(k, willSetAttr[k]);
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
else {
|
|
3136
|
+
super.setAttribute(qualifiedName, value);
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
|
|
3141
|
+
class TaroDocument extends TaroElement {
|
|
3142
|
+
constructor() {
|
|
3143
|
+
super();
|
|
3144
|
+
this.createEvent = createEvent;
|
|
3145
|
+
this.nodeType = 9 /* NodeType.DOCUMENT_NODE */;
|
|
3146
|
+
this.nodeName = DOCUMENT_ELEMENT_NAME;
|
|
3147
|
+
}
|
|
3148
|
+
createElement(type) {
|
|
3149
|
+
const nodeName = type.toLowerCase();
|
|
3150
|
+
let element;
|
|
3151
|
+
switch (true) {
|
|
3152
|
+
case nodeName === ROOT_STR:
|
|
3153
|
+
element = new TaroRootElement();
|
|
3154
|
+
return element;
|
|
3155
|
+
case controlledComponent.has(nodeName):
|
|
3156
|
+
element = new FormElement();
|
|
3157
|
+
break;
|
|
3158
|
+
case nodeName === A:
|
|
3159
|
+
element = new AnchorElement();
|
|
3160
|
+
break;
|
|
3161
|
+
default:
|
|
3162
|
+
element = new TaroElement();
|
|
3163
|
+
break;
|
|
3164
|
+
}
|
|
3165
|
+
element.nodeName = nodeName;
|
|
3166
|
+
element.tagName = type.toUpperCase();
|
|
3167
|
+
return element;
|
|
3168
|
+
}
|
|
3169
|
+
// an ugly fake createElementNS to deal with @vue/runtime-dom's
|
|
3170
|
+
// support mounting app to svg container since vue@3.0.8
|
|
3171
|
+
createElementNS(_svgNS, type) {
|
|
3172
|
+
return this.createElement(type);
|
|
3173
|
+
}
|
|
3174
|
+
createTextNode(text) {
|
|
3175
|
+
return new TaroText(text);
|
|
3176
|
+
}
|
|
3177
|
+
getElementById(id) {
|
|
3178
|
+
const el = eventSource.get(id);
|
|
3179
|
+
return isUndefined(el) ? null : el;
|
|
3180
|
+
}
|
|
3181
|
+
querySelector(query) {
|
|
3182
|
+
// 为了 Vue3 的乞丐版实现
|
|
3183
|
+
if (/^#/.test(query)) {
|
|
3184
|
+
return this.getElementById(query.slice(1));
|
|
3185
|
+
}
|
|
3186
|
+
return null;
|
|
3187
|
+
}
|
|
3188
|
+
querySelectorAll() {
|
|
3189
|
+
// fake hack
|
|
3190
|
+
return [];
|
|
3191
|
+
}
|
|
3192
|
+
// @TODO: @PERF: 在 hydrate 移除掉空的 node
|
|
3193
|
+
createComment() {
|
|
3194
|
+
const textnode = new TaroText('');
|
|
3195
|
+
textnode.nodeName = COMMENT;
|
|
3196
|
+
return textnode;
|
|
3197
|
+
}
|
|
3198
|
+
get defaultView() {
|
|
3199
|
+
return env.window;
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
|
|
3203
|
+
let document$1;
|
|
3204
|
+
if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
3205
|
+
/* eslint-disable no-inner-declarations */
|
|
3206
|
+
function createDocument() {
|
|
3207
|
+
/**
|
|
3208
|
+
* <document>
|
|
3209
|
+
* <html>
|
|
3210
|
+
* <head></head>
|
|
3211
|
+
* <body>
|
|
3212
|
+
* <container>
|
|
3213
|
+
* <app id="app" />
|
|
3214
|
+
* </container>
|
|
3215
|
+
* </body>
|
|
3216
|
+
* </html>
|
|
3217
|
+
* </document>
|
|
3218
|
+
*/
|
|
3219
|
+
const doc = new TaroDocument();
|
|
3220
|
+
const documentCreateElement = doc.createElement.bind(doc);
|
|
3221
|
+
const html = documentCreateElement(HTML);
|
|
3222
|
+
const head = documentCreateElement(HEAD);
|
|
3223
|
+
const body = documentCreateElement(BODY);
|
|
3224
|
+
const app = documentCreateElement(APP);
|
|
3225
|
+
app.id = APP;
|
|
3226
|
+
const container = documentCreateElement(CONTAINER); // 多包一层主要为了兼容 vue
|
|
3227
|
+
doc.appendChild(html);
|
|
3228
|
+
html.appendChild(head);
|
|
3229
|
+
html.appendChild(body);
|
|
3230
|
+
body.appendChild(container);
|
|
3231
|
+
container.appendChild(app);
|
|
3232
|
+
doc.documentElement = html;
|
|
3233
|
+
doc.head = head;
|
|
3234
|
+
doc.body = body;
|
|
3235
|
+
return doc;
|
|
3236
|
+
}
|
|
3237
|
+
document$1 = env.document = createDocument();
|
|
3238
|
+
}
|
|
3239
|
+
else {
|
|
3240
|
+
document$1 = env.document;
|
|
3241
|
+
}
|
|
3242
|
+
|
|
3243
|
+
function getComputedStyle(element) {
|
|
3244
|
+
return element.style;
|
|
3245
|
+
}
|
|
3246
|
+
|
|
3010
3247
|
const eventCenter = hooks.call('getEventCenter', Events);
|
|
3011
3248
|
|
|
3012
3249
|
/**
|
|
@@ -3067,7 +3304,7 @@ class History extends Events {
|
|
|
3067
3304
|
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3068
3305
|
cache$1.set(pageId, {
|
|
3069
3306
|
location: __classPrivateFieldGet(this, _History_location, "f"),
|
|
3070
|
-
stack: __classPrivateFieldGet(this, _History_stack, "f"),
|
|
3307
|
+
stack: __classPrivateFieldGet(this, _History_stack, "f").slice(),
|
|
3071
3308
|
cur: __classPrivateFieldGet(this, _History_cur, "f")
|
|
3072
3309
|
});
|
|
3073
3310
|
}, null);
|
|
@@ -3152,29 +3389,24 @@ const Current = {
|
|
|
3152
3389
|
};
|
|
3153
3390
|
const getCurrentInstance = () => Current;
|
|
3154
3391
|
|
|
3155
|
-
var _Location_instances,
|
|
3156
|
-
const
|
|
3392
|
+
var _Location_instances, _Location_url, _Location_noCheckUrl, _Location_window, _Location_reset, _Location_getPreValue, _Location_rollBack, _Location_recordHistory, _Location_checkUrlChange;
|
|
3393
|
+
const INIT_URL = 'https://taro.com';
|
|
3157
3394
|
const cache = new RuntimeCache('location');
|
|
3158
3395
|
class Location extends Events {
|
|
3159
3396
|
constructor(options) {
|
|
3160
3397
|
super();
|
|
3161
3398
|
_Location_instances.add(this);
|
|
3162
3399
|
/* private property */
|
|
3163
|
-
|
|
3164
|
-
_Location_hostname.set(this, DEFAULT_HOSTNAME);
|
|
3165
|
-
_Location_pathname.set(this, '/');
|
|
3166
|
-
_Location_port.set(this, '');
|
|
3167
|
-
_Location_protocol.set(this, 'https:');
|
|
3168
|
-
_Location_search.set(this, '');
|
|
3400
|
+
_Location_url.set(this, new URL(INIT_URL));
|
|
3169
3401
|
_Location_noCheckUrl.set(this, false);
|
|
3170
3402
|
_Location_window.set(this, void 0);
|
|
3171
3403
|
__classPrivateFieldSet(this, _Location_window, options.window, "f");
|
|
3172
3404
|
__classPrivateFieldGet(this, _Location_instances, "m", _Location_reset).call(this);
|
|
3173
3405
|
this.on('__set_href_without_history__', (href) => {
|
|
3174
3406
|
__classPrivateFieldSet(this, _Location_noCheckUrl, true, "f");
|
|
3175
|
-
const lastHash = __classPrivateFieldGet(this,
|
|
3176
|
-
this.href = generateFullUrl(href);
|
|
3177
|
-
if (lastHash !== __classPrivateFieldGet(this,
|
|
3407
|
+
const lastHash = __classPrivateFieldGet(this, _Location_url, "f").hash;
|
|
3408
|
+
__classPrivateFieldGet(this, _Location_url, "f").href = generateFullUrl(href);
|
|
3409
|
+
if (lastHash !== __classPrivateFieldGet(this, _Location_url, "f").hash) {
|
|
3178
3410
|
__classPrivateFieldGet(this, _Location_window, "f").trigger('hashchange');
|
|
3179
3411
|
}
|
|
3180
3412
|
__classPrivateFieldSet(this, _Location_noCheckUrl, false, "f");
|
|
@@ -3185,7 +3417,7 @@ class Location extends Events {
|
|
|
3185
3417
|
}, null);
|
|
3186
3418
|
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3187
3419
|
cache.set(pageId, {
|
|
3188
|
-
lastHref: this.href
|
|
3420
|
+
lastHref: this.href,
|
|
3189
3421
|
});
|
|
3190
3422
|
}, null);
|
|
3191
3423
|
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
@@ -3193,7 +3425,7 @@ class Location extends Events {
|
|
|
3193
3425
|
if (cache.has(pageId)) {
|
|
3194
3426
|
const ctx = cache.get(pageId);
|
|
3195
3427
|
__classPrivateFieldSet(this, _Location_noCheckUrl, true, "f");
|
|
3196
|
-
this.href = ctx.lastHref;
|
|
3428
|
+
__classPrivateFieldGet(this, _Location_url, "f").href = ctx.lastHref;
|
|
3197
3429
|
__classPrivateFieldSet(this, _Location_noCheckUrl, false, "f");
|
|
3198
3430
|
}
|
|
3199
3431
|
}, null);
|
|
@@ -3203,87 +3435,68 @@ class Location extends Events {
|
|
|
3203
3435
|
}
|
|
3204
3436
|
/* public property */
|
|
3205
3437
|
get protocol() {
|
|
3206
|
-
return __classPrivateFieldGet(this,
|
|
3438
|
+
return __classPrivateFieldGet(this, _Location_url, "f").protocol;
|
|
3207
3439
|
}
|
|
3208
3440
|
set protocol(val) {
|
|
3209
|
-
const
|
|
3210
|
-
if (!val || !isString(val) || !
|
|
3441
|
+
const REG = /^(http|https):$/i;
|
|
3442
|
+
if (!val || !isString(val) || !REG.test(val.trim()))
|
|
3211
3443
|
return;
|
|
3212
3444
|
val = val.trim();
|
|
3213
3445
|
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3214
|
-
|
|
3446
|
+
__classPrivateFieldGet(this, _Location_url, "f").protocol = val;
|
|
3215
3447
|
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3216
3448
|
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3217
3449
|
}
|
|
3218
3450
|
get host() {
|
|
3219
|
-
return
|
|
3451
|
+
return __classPrivateFieldGet(this, _Location_url, "f").host;
|
|
3220
3452
|
}
|
|
3221
3453
|
set host(val) {
|
|
3222
3454
|
if (!val || !isString(val))
|
|
3223
3455
|
return;
|
|
3224
3456
|
val = val.trim();
|
|
3225
|
-
const { hostname, port } = parseUrl(`//${val}`);
|
|
3226
3457
|
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3227
|
-
|
|
3228
|
-
__classPrivateFieldSet(this, _Location_port, port, "f");
|
|
3458
|
+
__classPrivateFieldGet(this, _Location_url, "f").host = val;
|
|
3229
3459
|
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3230
3460
|
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3231
3461
|
}
|
|
3232
3462
|
get hostname() {
|
|
3233
|
-
return __classPrivateFieldGet(this,
|
|
3463
|
+
return __classPrivateFieldGet(this, _Location_url, "f").hostname;
|
|
3234
3464
|
}
|
|
3235
3465
|
set hostname(val) {
|
|
3236
3466
|
if (!val || !isString(val))
|
|
3237
3467
|
return;
|
|
3238
3468
|
val = val.trim();
|
|
3239
|
-
const { hostname } = parseUrl(`//${val}`);
|
|
3240
3469
|
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3241
|
-
|
|
3470
|
+
__classPrivateFieldGet(this, _Location_url, "f").hostname = val;
|
|
3242
3471
|
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3243
3472
|
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3244
3473
|
}
|
|
3245
3474
|
get port() {
|
|
3246
|
-
return __classPrivateFieldGet(this,
|
|
3475
|
+
return __classPrivateFieldGet(this, _Location_url, "f").port;
|
|
3247
3476
|
}
|
|
3248
3477
|
set port(val) {
|
|
3249
3478
|
const xVal = Number((val = val.trim()));
|
|
3250
3479
|
if (!isNumber(xVal) || xVal <= 0)
|
|
3251
3480
|
return;
|
|
3252
|
-
if (val === __classPrivateFieldGet(this, _Location_port, "f"))
|
|
3253
|
-
return;
|
|
3254
3481
|
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3255
|
-
|
|
3482
|
+
__classPrivateFieldGet(this, _Location_url, "f").port = val;
|
|
3256
3483
|
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3257
3484
|
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3258
3485
|
}
|
|
3259
3486
|
get pathname() {
|
|
3260
|
-
return __classPrivateFieldGet(this,
|
|
3487
|
+
return __classPrivateFieldGet(this, _Location_url, "f").pathname;
|
|
3261
3488
|
}
|
|
3262
3489
|
set pathname(val) {
|
|
3263
3490
|
if (!val || !isString(val))
|
|
3264
3491
|
return;
|
|
3265
3492
|
val = val.trim();
|
|
3266
3493
|
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3267
|
-
|
|
3268
|
-
if (val.startsWith('/')) {
|
|
3269
|
-
newPathName = __classPrivateFieldGet(this, _Location_pathname, "f") + val;
|
|
3270
|
-
}
|
|
3271
|
-
else if (val.startsWith('./')) {
|
|
3272
|
-
val = val.replace(/\.\//, '/');
|
|
3273
|
-
newPathName = __classPrivateFieldGet(this, _Location_pathname, "f") + val;
|
|
3274
|
-
}
|
|
3275
|
-
else if (val.startsWith('../')) {
|
|
3276
|
-
newPathName = resolveRelativePath(val, preValue.pathname);
|
|
3277
|
-
}
|
|
3278
|
-
const { pathname, search, hash } = parseUrl(`//${DEFAULT_HOSTNAME}${newPathName}`);
|
|
3279
|
-
__classPrivateFieldSet(this, _Location_pathname, pathname, "f");
|
|
3280
|
-
__classPrivateFieldSet(this, _Location_search, search, "f");
|
|
3281
|
-
__classPrivateFieldSet(this, _Location_hash, hash, "f");
|
|
3494
|
+
__classPrivateFieldGet(this, _Location_url, "f").pathname = val;
|
|
3282
3495
|
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3283
3496
|
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3284
3497
|
}
|
|
3285
3498
|
get search() {
|
|
3286
|
-
return __classPrivateFieldGet(this,
|
|
3499
|
+
return __classPrivateFieldGet(this, _Location_url, "f").search;
|
|
3287
3500
|
}
|
|
3288
3501
|
set search(val) {
|
|
3289
3502
|
if (!val || !isString(val))
|
|
@@ -3291,13 +3504,12 @@ class Location extends Events {
|
|
|
3291
3504
|
val = val.trim();
|
|
3292
3505
|
val = val.startsWith('?') ? val : `?${val}`;
|
|
3293
3506
|
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3294
|
-
|
|
3295
|
-
__classPrivateFieldSet(this, _Location_search, search, "f");
|
|
3507
|
+
__classPrivateFieldGet(this, _Location_url, "f").search = val;
|
|
3296
3508
|
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3297
3509
|
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3298
3510
|
}
|
|
3299
3511
|
get hash() {
|
|
3300
|
-
return __classPrivateFieldGet(this,
|
|
3512
|
+
return __classPrivateFieldGet(this, _Location_url, "f").hash;
|
|
3301
3513
|
}
|
|
3302
3514
|
// 小程序的navigateTo存在截断hash字符串的问题
|
|
3303
3515
|
set hash(val) {
|
|
@@ -3306,41 +3518,31 @@ class Location extends Events {
|
|
|
3306
3518
|
val = val.trim();
|
|
3307
3519
|
val = val.startsWith('#') ? val : `#${val}`;
|
|
3308
3520
|
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3309
|
-
|
|
3310
|
-
__classPrivateFieldSet(this, _Location_hash, hash, "f");
|
|
3521
|
+
__classPrivateFieldGet(this, _Location_url, "f").hash = val;
|
|
3311
3522
|
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3312
3523
|
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3313
3524
|
}
|
|
3314
3525
|
get href() {
|
|
3315
|
-
return
|
|
3526
|
+
return __classPrivateFieldGet(this, _Location_url, "f").href;
|
|
3316
3527
|
}
|
|
3317
3528
|
set href(val) {
|
|
3318
|
-
const
|
|
3319
|
-
if (!val || !isString(val) || !
|
|
3529
|
+
const REG = /^(http:|https:)?\/\/.+/;
|
|
3530
|
+
if (!val || !isString(val) || !REG.test((val = val.trim())))
|
|
3320
3531
|
return;
|
|
3321
|
-
const { protocol, hostname, port, hash, search, pathname } = parseUrl(val);
|
|
3322
3532
|
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3323
|
-
|
|
3324
|
-
__classPrivateFieldSet(this, _Location_hostname, hostname, "f");
|
|
3325
|
-
__classPrivateFieldSet(this, _Location_port, port, "f");
|
|
3326
|
-
__classPrivateFieldSet(this, _Location_pathname, pathname, "f");
|
|
3327
|
-
__classPrivateFieldSet(this, _Location_search, search, "f");
|
|
3328
|
-
__classPrivateFieldSet(this, _Location_hash, hash, "f");
|
|
3533
|
+
__classPrivateFieldGet(this, _Location_url, "f").href = val;
|
|
3329
3534
|
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3330
3535
|
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3331
3536
|
}
|
|
3332
3537
|
get origin() {
|
|
3333
|
-
return
|
|
3538
|
+
return __classPrivateFieldGet(this, _Location_url, "f").origin;
|
|
3334
3539
|
}
|
|
3335
3540
|
set origin(val) {
|
|
3336
|
-
const
|
|
3337
|
-
if (!val || !isString(val) || !
|
|
3541
|
+
const REG = /^(http:|https:)?\/\/.+/;
|
|
3542
|
+
if (!val || !isString(val) || !REG.test((val = val.trim())))
|
|
3338
3543
|
return;
|
|
3339
|
-
const { protocol, hostname, port } = parseUrl(val);
|
|
3340
3544
|
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3341
|
-
|
|
3342
|
-
__classPrivateFieldSet(this, _Location_hostname, hostname, "f");
|
|
3343
|
-
__classPrivateFieldSet(this, _Location_port, port, "f");
|
|
3545
|
+
__classPrivateFieldGet(this, _Location_url, "f").origin = val;
|
|
3344
3546
|
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3345
3547
|
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3346
3548
|
}
|
|
@@ -3351,8 +3553,8 @@ class Location extends Events {
|
|
|
3351
3553
|
reload() {
|
|
3352
3554
|
warn(true, '小程序环境中调用location.reload()无效.');
|
|
3353
3555
|
}
|
|
3354
|
-
replace(
|
|
3355
|
-
this.trigger('__set_href_without_history__',
|
|
3556
|
+
replace(url) {
|
|
3557
|
+
this.trigger('__set_href_without_history__', url);
|
|
3356
3558
|
}
|
|
3357
3559
|
toString() {
|
|
3358
3560
|
return this.href;
|
|
@@ -3362,128 +3564,109 @@ class Location extends Events {
|
|
|
3362
3564
|
return cache;
|
|
3363
3565
|
}
|
|
3364
3566
|
}
|
|
3365
|
-
|
|
3567
|
+
_Location_url = new WeakMap(), _Location_noCheckUrl = new WeakMap(), _Location_window = new WeakMap(), _Location_instances = new WeakSet(), _Location_reset = function _Location_reset() {
|
|
3366
3568
|
const Current = getCurrentInstance();
|
|
3367
3569
|
const router = Current.router;
|
|
3368
3570
|
if (router) {
|
|
3369
3571
|
const { path, params } = router;
|
|
3370
|
-
const searchArr = Object.keys(params).map(key => {
|
|
3572
|
+
const searchArr = Object.keys(params).map((key) => {
|
|
3371
3573
|
return `${key}=${params[key]}`;
|
|
3372
3574
|
});
|
|
3373
3575
|
const searchStr = searchArr.length > 0 ? '?' + searchArr.join('&') : '';
|
|
3374
|
-
const url =
|
|
3375
|
-
|
|
3376
|
-
// const url = `https://${DEFAULT_HOSTNAME}${searchStr}`
|
|
3377
|
-
const { protocol, hostname, port, pathname, search, hash } = parseUrl(url);
|
|
3378
|
-
__classPrivateFieldSet(this, _Location_protocol, protocol, "f");
|
|
3379
|
-
__classPrivateFieldSet(this, _Location_hostname, hostname, "f");
|
|
3380
|
-
__classPrivateFieldSet(this, _Location_port, port, "f");
|
|
3381
|
-
__classPrivateFieldSet(this, _Location_pathname, pathname, "f");
|
|
3382
|
-
__classPrivateFieldSet(this, _Location_search, search, "f");
|
|
3383
|
-
__classPrivateFieldSet(this, _Location_hash, hash, "f");
|
|
3576
|
+
const url = `${INIT_URL}${path.startsWith('/') ? path : '/' + path}${searchStr}`;
|
|
3577
|
+
__classPrivateFieldSet(this, _Location_url, new URL(url), "f");
|
|
3384
3578
|
this.trigger('__reset_history__', this.href);
|
|
3385
3579
|
}
|
|
3386
3580
|
}, _Location_getPreValue = function _Location_getPreValue() {
|
|
3387
|
-
return
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
port: __classPrivateFieldGet(this, _Location_port, "f"),
|
|
3391
|
-
pathname: __classPrivateFieldGet(this, _Location_pathname, "f"),
|
|
3392
|
-
search: __classPrivateFieldGet(this, _Location_search, "f"),
|
|
3393
|
-
hash: __classPrivateFieldGet(this, _Location_hash, "f")
|
|
3394
|
-
};
|
|
3395
|
-
}, _Location_rollBack = function _Location_rollBack(preValue) {
|
|
3396
|
-
__classPrivateFieldSet(this, _Location_protocol, preValue.protocol, "f");
|
|
3397
|
-
__classPrivateFieldSet(this, _Location_hostname, preValue.hostname, "f");
|
|
3398
|
-
__classPrivateFieldSet(this, _Location_port, preValue.port, "f");
|
|
3399
|
-
__classPrivateFieldSet(this, _Location_pathname, preValue.pathname, "f");
|
|
3400
|
-
__classPrivateFieldSet(this, _Location_search, preValue.search, "f");
|
|
3401
|
-
__classPrivateFieldSet(this, _Location_hash, preValue.hash, "f");
|
|
3581
|
+
return __classPrivateFieldGet(this, _Location_url, "f")._toRaw();
|
|
3582
|
+
}, _Location_rollBack = function _Location_rollBack(href) {
|
|
3583
|
+
__classPrivateFieldGet(this, _Location_url, "f").href = href;
|
|
3402
3584
|
}, _Location_recordHistory = function _Location_recordHistory() {
|
|
3403
3585
|
this.trigger('__record_history__', this.href);
|
|
3404
3586
|
}, _Location_checkUrlChange = function _Location_checkUrlChange(preValue) {
|
|
3405
3587
|
if (__classPrivateFieldGet(this, _Location_noCheckUrl, "f")) {
|
|
3406
3588
|
return false;
|
|
3407
3589
|
}
|
|
3590
|
+
const { protocol, hostname, port, pathname, search, hash } = __classPrivateFieldGet(this, _Location_url, "f")._toRaw();
|
|
3408
3591
|
// 跨域三要素不允许修改
|
|
3409
|
-
if (
|
|
3410
|
-
__classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue);
|
|
3592
|
+
if (protocol !== preValue.protocol || hostname !== preValue.hostname || port !== preValue.port) {
|
|
3593
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue.href);
|
|
3411
3594
|
return false;
|
|
3412
3595
|
}
|
|
3413
3596
|
// pathname
|
|
3414
|
-
if (
|
|
3597
|
+
if (pathname !== preValue.pathname) {
|
|
3415
3598
|
return true;
|
|
3416
3599
|
}
|
|
3417
3600
|
// search
|
|
3418
|
-
if (
|
|
3601
|
+
if (search !== preValue.search) {
|
|
3419
3602
|
return true;
|
|
3420
3603
|
}
|
|
3421
3604
|
// hashchange
|
|
3422
|
-
if (
|
|
3605
|
+
if (hash !== preValue.hash) {
|
|
3423
3606
|
__classPrivateFieldGet(this, _Location_window, "f").trigger('hashchange');
|
|
3424
3607
|
return true;
|
|
3425
3608
|
}
|
|
3426
|
-
__classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue);
|
|
3609
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue.href);
|
|
3427
3610
|
return false;
|
|
3428
3611
|
};
|
|
3429
|
-
function resolveRelativePath(path, relative) {
|
|
3430
|
-
const relativeArr = relative.split('/');
|
|
3431
|
-
const parent = relativeArr.slice(0, relativeArr.length - 1);
|
|
3432
|
-
let depth = 0;
|
|
3433
|
-
const dests = path.split('../').map(v => {
|
|
3434
|
-
v === '' && depth++;
|
|
3435
|
-
return v;
|
|
3436
|
-
});
|
|
3437
|
-
if (depth > parent.length)
|
|
3438
|
-
return relative;
|
|
3439
|
-
return parent.slice(0, parent.length - depth).concat(dests.filter(v => v !== '')).join('/');
|
|
3440
|
-
}
|
|
3441
3612
|
function generateFullUrl(val = '') {
|
|
3442
|
-
const origin =
|
|
3443
|
-
if (val
|
|
3613
|
+
const origin = INIT_URL;
|
|
3614
|
+
if (/^[/?#]/.test(val)) {
|
|
3444
3615
|
return origin + val;
|
|
3445
3616
|
}
|
|
3446
|
-
|
|
3447
|
-
|
|
3617
|
+
return val;
|
|
3618
|
+
}
|
|
3619
|
+
|
|
3620
|
+
const machine = 'Macintosh';
|
|
3621
|
+
const arch = 'Intel Mac OS X 10_14_5';
|
|
3622
|
+
const engine = 'AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36';
|
|
3623
|
+
const msg = '(' + machine + '; ' + arch + ') ' + engine;
|
|
3624
|
+
const nav = process.env.TARO_ENV === 'h5' ? env.window.navigator : {
|
|
3625
|
+
appCodeName: 'Mozilla',
|
|
3626
|
+
appName: 'Netscape',
|
|
3627
|
+
appVersion: '5.0 ' + msg,
|
|
3628
|
+
cookieEnabled: true,
|
|
3629
|
+
mimeTypes: [],
|
|
3630
|
+
onLine: true,
|
|
3631
|
+
platform: 'MacIntel',
|
|
3632
|
+
plugins: [],
|
|
3633
|
+
product: 'Taro',
|
|
3634
|
+
productSub: '20030107',
|
|
3635
|
+
userAgent: 'Mozilla/5.0 ' + msg,
|
|
3636
|
+
vendor: 'Joyent',
|
|
3637
|
+
vendorSub: ''
|
|
3638
|
+
};
|
|
3639
|
+
|
|
3640
|
+
// https://github.com/myrne/performance-now
|
|
3641
|
+
let now;
|
|
3642
|
+
(function () {
|
|
3643
|
+
let loadTime;
|
|
3644
|
+
if ((typeof performance !== 'undefined' && performance !== null) && performance.now) {
|
|
3645
|
+
now = () => performance.now();
|
|
3448
3646
|
}
|
|
3449
|
-
if (
|
|
3450
|
-
|
|
3647
|
+
else if (Date.now) {
|
|
3648
|
+
loadTime = Date.now();
|
|
3649
|
+
now = () => Date.now() - loadTime;
|
|
3451
3650
|
}
|
|
3452
|
-
|
|
3453
|
-
|
|
3651
|
+
else {
|
|
3652
|
+
loadTime = new Date().getTime();
|
|
3653
|
+
now = () => new Date().getTime() - loadTime;
|
|
3454
3654
|
}
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3655
|
+
})();
|
|
3656
|
+
let lastTime = 0;
|
|
3657
|
+
// https://gist.github.com/paulirish/1579671
|
|
3658
|
+
// https://gist.github.com/jalbam/5fe05443270fa6d8136238ec72accbc0
|
|
3659
|
+
const _raf = typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame !== null ? requestAnimationFrame : function (callback) {
|
|
3660
|
+
const _now = now();
|
|
3661
|
+
const nextTime = Math.max(lastTime + 16, _now); // First time will execute it immediately but barely noticeable and performance is gained.
|
|
3662
|
+
return setTimeout(function () { callback(lastTime = nextTime); }, nextTime - _now);
|
|
3663
|
+
};
|
|
3664
|
+
const _caf = typeof cancelAnimationFrame !== 'undefined' && cancelAnimationFrame !== null
|
|
3665
|
+
? cancelAnimationFrame
|
|
3666
|
+
: function (seed) {
|
|
3667
|
+
// fix https://github.com/NervJS/taro/issues/7749
|
|
3668
|
+
clearTimeout(seed);
|
|
3468
3669
|
};
|
|
3469
|
-
if (!url || !isString(url))
|
|
3470
|
-
return result;
|
|
3471
|
-
url = url.trim();
|
|
3472
|
-
const PATTERN = /^(([^:/?#]+):)?\/\/(([^/?#]+):(.+)@)?([^/?#:]*)(:(\d+))?([^?#]*)(\?([^#]*))?(#(.*))?/;
|
|
3473
|
-
const matches = url.match(PATTERN);
|
|
3474
|
-
if (!matches)
|
|
3475
|
-
return result;
|
|
3476
|
-
result.protocol = matches[1] || 'https:';
|
|
3477
|
-
result.hostname = matches[6] || DEFAULT_HOSTNAME;
|
|
3478
|
-
result.port = matches[8] || '';
|
|
3479
|
-
result.pathname = matches[9] || '/';
|
|
3480
|
-
result.search = matches[10] || '';
|
|
3481
|
-
result.hash = matches[12] || '';
|
|
3482
|
-
result.href = url;
|
|
3483
|
-
result.origin = result.protocol + '//' + result.hostname;
|
|
3484
|
-
result.host = result.hostname + (result.port ? `:${result.port}` : '');
|
|
3485
|
-
return result;
|
|
3486
|
-
}
|
|
3487
3670
|
|
|
3488
3671
|
let window$1;
|
|
3489
3672
|
if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
@@ -3716,11 +3899,13 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3716
3899
|
});
|
|
3717
3900
|
},
|
|
3718
3901
|
[ONREADY]() {
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3902
|
+
hasLoaded.then(() => {
|
|
3903
|
+
// 触发生命周期
|
|
3904
|
+
safeExecute(this.$taroPath, ON_READY);
|
|
3905
|
+
// 通过事件触发子组件的生命周期
|
|
3906
|
+
_raf(() => eventCenter.trigger(getOnReadyEventKey(id)));
|
|
3907
|
+
this.onReady.called = true;
|
|
3908
|
+
});
|
|
3724
3909
|
},
|
|
3725
3910
|
[ONSHOW](options = {}) {
|
|
3726
3911
|
hasLoaded.then(() => {
|
|
@@ -3852,7 +4037,7 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
3852
4037
|
i: {
|
|
3853
4038
|
type: Object,
|
|
3854
4039
|
value: {
|
|
3855
|
-
["nn" /* Shortcuts.NodeName */]: getComponentsAlias()[VIEW]._num
|
|
4040
|
+
["nn" /* Shortcuts.NodeName */]: getComponentsAlias$1(internalComponents)[VIEW]._num
|
|
3856
4041
|
}
|
|
3857
4042
|
},
|
|
3858
4043
|
l: {
|
|
@@ -3899,5 +4084,5 @@ const nextTick = (cb, ctx) => {
|
|
|
3899
4084
|
}
|
|
3900
4085
|
};
|
|
3901
4086
|
|
|
3902
|
-
export { Current, FormElement, MutationObserver, SVGElement, Style, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, URLSearchParams, addLeadingSlash, _caf as cancelAnimationFrame, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, document$1 as document, eventCenter, eventHandler, eventSource, getComputedStyle, getCurrentInstance, getPageInstance, history, hydrate, incrementId, injectPageInstance, location, nav as navigator, nextTick, now, options, removePageInstance, _raf as requestAnimationFrame, safeExecute, stringify, window$1 as window };
|
|
4087
|
+
export { Current, FormElement, History, Location, MutationObserver, SVGElement, Style, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, URL, URLSearchParams, addLeadingSlash, _caf as cancelAnimationFrame, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, document$1 as document, eventCenter, eventHandler, eventSource, getComputedStyle, getCurrentInstance, getPageInstance, history, hydrate, incrementId, injectPageInstance, location, nav as navigator, nextTick, now, options, parseUrl, removePageInstance, _raf as requestAnimationFrame, safeExecute, stringify, window$1 as window };
|
|
3903
4088
|
//# sourceMappingURL=runtime.esm.js.map
|