@tarojs/runtime 3.6.0-beta.1 → 3.6.0-beta.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/bom/location.d.ts +11 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/dom/anchor-element.d.ts +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/runtime.esm.d.ts +17 -3
- package/dist/runtime.esm.js +599 -537
- package/dist/runtime.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/runtime.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { noop, isFunction, getComponentsAlias as getComponentsAlias$1, internalComponents, EMPTY_OBJ, hooks, toCamelCase, isObject, warn, isArray, ensure, isNull, isUndefined, toDashed, isString,
|
|
1
|
+
import { noop, isFunction, getComponentsAlias as getComponentsAlias$1, internalComponents, EMPTY_OBJ, hooks, toCamelCase, isObject, warn, isArray, ensure, isNull, isUndefined, toDashed, isString, Events, isNumber, controlledComponent } from '@tarojs/shared';
|
|
2
2
|
export { Events, hooks } from '@tarojs/shared';
|
|
3
3
|
|
|
4
4
|
const PROPERTY_THRESHOLD = 2046;
|
|
@@ -44,6 +44,7 @@ const ON_HIDE = 'onHide';
|
|
|
44
44
|
const OPTIONS = 'options';
|
|
45
45
|
const EXTERNAL_CLASSES = 'externalClasses';
|
|
46
46
|
const BEHAVIORS = 'behaviors';
|
|
47
|
+
const A = 'a';
|
|
47
48
|
/**
|
|
48
49
|
* 页面上下文切换时的行为
|
|
49
50
|
*/
|
|
@@ -2715,153 +2716,6 @@ class TaroText extends TaroNode {
|
|
|
2715
2716
|
}
|
|
2716
2717
|
}
|
|
2717
2718
|
|
|
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
2719
|
/******************************************************************************
|
|
2866
2720
|
Copyright (c) Microsoft Corporation.
|
|
2867
2721
|
|
|
@@ -2890,271 +2744,43 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
|
2890
2744
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
2891
2745
|
}
|
|
2892
2746
|
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
'!': '%21',
|
|
2898
|
-
"'": '%27',
|
|
2899
|
-
'(': '%28',
|
|
2900
|
-
')': '%29',
|
|
2901
|
-
'~': '%7E',
|
|
2902
|
-
'%20': '+',
|
|
2903
|
-
'%00': '\x00',
|
|
2747
|
+
const Current = {
|
|
2748
|
+
app: null,
|
|
2749
|
+
router: null,
|
|
2750
|
+
page: null
|
|
2904
2751
|
};
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
appendTo(this, key, value);
|
|
2917
|
-
}
|
|
2918
|
-
function decode(str) {
|
|
2919
|
-
return decodeURIComponent(str.replace(plusReg, ' '));
|
|
2920
|
-
}
|
|
2921
|
-
function encode(str) {
|
|
2922
|
-
return encodeURIComponent(str).replace(findReg, replacer);
|
|
2923
|
-
}
|
|
2924
|
-
class URLSearchParams {
|
|
2925
|
-
constructor(query) {
|
|
2926
|
-
_URLSearchParams_dict.set(this, Object.create(null));
|
|
2927
|
-
if (!query)
|
|
2928
|
-
return;
|
|
2929
|
-
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2930
|
-
if (typeof query === 'string') {
|
|
2931
|
-
if (query.charAt(0) === '?') {
|
|
2932
|
-
query = query.slice(1);
|
|
2933
|
-
}
|
|
2934
|
-
for (let pairs = query.split('&'), i = 0, length = pairs.length; i < length; i++) {
|
|
2935
|
-
const value = pairs[i];
|
|
2936
|
-
const index = value.indexOf('=');
|
|
2937
|
-
if (index > -1) {
|
|
2938
|
-
appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));
|
|
2939
|
-
}
|
|
2940
|
-
else if (value.length) {
|
|
2941
|
-
appendTo(dict, decode(value), '');
|
|
2942
|
-
}
|
|
2943
|
-
}
|
|
2944
|
-
}
|
|
2945
|
-
else {
|
|
2946
|
-
if (isArray(query)) {
|
|
2947
|
-
for (let i = 0, length = query.length; i < length; i++) {
|
|
2948
|
-
const value = query[i];
|
|
2949
|
-
appendTo(dict, value[0], value[1]);
|
|
2950
|
-
}
|
|
2951
|
-
}
|
|
2952
|
-
else if (query.forEach) {
|
|
2953
|
-
query.forEach(addEach, dict);
|
|
2954
|
-
}
|
|
2955
|
-
else {
|
|
2956
|
-
for (const key in query) {
|
|
2957
|
-
appendTo(dict, key, query[key]);
|
|
2958
|
-
}
|
|
2959
|
-
}
|
|
2960
|
-
}
|
|
2961
|
-
}
|
|
2962
|
-
append(name, value) {
|
|
2963
|
-
appendTo(__classPrivateFieldGet(this, _URLSearchParams_dict, "f"), name, value);
|
|
2964
|
-
}
|
|
2965
|
-
delete(name) {
|
|
2966
|
-
delete __classPrivateFieldGet(this, _URLSearchParams_dict, "f")[name];
|
|
2967
|
-
}
|
|
2968
|
-
get(name) {
|
|
2969
|
-
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2970
|
-
return name in dict ? dict[name][0] : null;
|
|
2752
|
+
const getCurrentInstance = () => Current;
|
|
2753
|
+
|
|
2754
|
+
const eventCenter = hooks.call('getEventCenter', Events);
|
|
2755
|
+
|
|
2756
|
+
/**
|
|
2757
|
+
* 一个小型缓存池,用于在切换页面时,存储一些上下文信息
|
|
2758
|
+
*/
|
|
2759
|
+
class RuntimeCache {
|
|
2760
|
+
constructor(name) {
|
|
2761
|
+
this.cache = new Map();
|
|
2762
|
+
this.name = name;
|
|
2971
2763
|
}
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
return name in dict ? dict[name].slice(0) : [];
|
|
2764
|
+
has(identifier) {
|
|
2765
|
+
return this.cache.has(identifier);
|
|
2975
2766
|
}
|
|
2976
|
-
|
|
2977
|
-
|
|
2767
|
+
set(identifier, ctx) {
|
|
2768
|
+
if (identifier && ctx) {
|
|
2769
|
+
this.cache.set(identifier, ctx);
|
|
2770
|
+
}
|
|
2978
2771
|
}
|
|
2979
|
-
|
|
2980
|
-
|
|
2772
|
+
get(identifier) {
|
|
2773
|
+
if (this.has(identifier))
|
|
2774
|
+
return this.cache.get(identifier);
|
|
2981
2775
|
}
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
}
|
|
2985
|
-
forEach(callback, thisArg) {
|
|
2986
|
-
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2987
|
-
Object.getOwnPropertyNames(dict).forEach(function (name) {
|
|
2988
|
-
dict[name].forEach(function (value) {
|
|
2989
|
-
callback.call(thisArg, value, name, this);
|
|
2990
|
-
}, this);
|
|
2991
|
-
}, this);
|
|
2992
|
-
}
|
|
2993
|
-
toJSON() {
|
|
2994
|
-
return {};
|
|
2995
|
-
}
|
|
2996
|
-
toString() {
|
|
2997
|
-
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2998
|
-
const query = [];
|
|
2999
|
-
for (const key in dict) {
|
|
3000
|
-
const name = encode(key);
|
|
3001
|
-
for (let i = 0, value = dict[key]; i < value.length; i++) {
|
|
3002
|
-
query.push(name + '=' + encode(value[i]));
|
|
3003
|
-
}
|
|
3004
|
-
}
|
|
3005
|
-
return query.join('&');
|
|
3006
|
-
}
|
|
3007
|
-
}
|
|
3008
|
-
_URLSearchParams_dict = new WeakMap();
|
|
3009
|
-
|
|
3010
|
-
const eventCenter = hooks.call('getEventCenter', Events);
|
|
3011
|
-
|
|
3012
|
-
/**
|
|
3013
|
-
* 一个小型缓存池,用于在切换页面时,存储一些上下文信息
|
|
3014
|
-
*/
|
|
3015
|
-
class RuntimeCache {
|
|
3016
|
-
constructor(name) {
|
|
3017
|
-
this.cache = new Map();
|
|
3018
|
-
this.name = name;
|
|
3019
|
-
}
|
|
3020
|
-
has(identifier) {
|
|
3021
|
-
return this.cache.has(identifier);
|
|
3022
|
-
}
|
|
3023
|
-
set(identifier, ctx) {
|
|
3024
|
-
if (identifier && ctx) {
|
|
3025
|
-
this.cache.set(identifier, ctx);
|
|
3026
|
-
}
|
|
3027
|
-
}
|
|
3028
|
-
get(identifier) {
|
|
3029
|
-
if (this.has(identifier))
|
|
3030
|
-
return this.cache.get(identifier);
|
|
3031
|
-
}
|
|
3032
|
-
delete(identifier) {
|
|
3033
|
-
this.cache.delete(identifier);
|
|
3034
|
-
}
|
|
3035
|
-
}
|
|
3036
|
-
|
|
3037
|
-
var _History_instances, _History_location, _History_stack, _History_cur, _History_window, _History_reset;
|
|
3038
|
-
const cache$1 = new RuntimeCache('history');
|
|
3039
|
-
class History extends Events {
|
|
3040
|
-
constructor(location, options) {
|
|
3041
|
-
super();
|
|
3042
|
-
_History_instances.add(this);
|
|
3043
|
-
/* private property */
|
|
3044
|
-
_History_location.set(this, void 0);
|
|
3045
|
-
_History_stack.set(this, []);
|
|
3046
|
-
_History_cur.set(this, 0);
|
|
3047
|
-
_History_window.set(this, void 0);
|
|
3048
|
-
__classPrivateFieldSet(this, _History_window, options.window, "f");
|
|
3049
|
-
__classPrivateFieldSet(this, _History_location, location, "f");
|
|
3050
|
-
__classPrivateFieldGet(this, _History_location, "f").on('__record_history__', (href) => {
|
|
3051
|
-
var _a;
|
|
3052
|
-
__classPrivateFieldSet(this, _History_cur, (_a = __classPrivateFieldGet(this, _History_cur, "f"), _a++, _a), "f");
|
|
3053
|
-
__classPrivateFieldSet(this, _History_stack, __classPrivateFieldGet(this, _History_stack, "f").slice(0, __classPrivateFieldGet(this, _History_cur, "f")), "f");
|
|
3054
|
-
__classPrivateFieldGet(this, _History_stack, "f").push({
|
|
3055
|
-
state: null,
|
|
3056
|
-
title: '',
|
|
3057
|
-
url: href
|
|
3058
|
-
});
|
|
3059
|
-
}, null);
|
|
3060
|
-
__classPrivateFieldGet(this, _History_location, "f").on('__reset_history__', (href) => {
|
|
3061
|
-
__classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this, href);
|
|
3062
|
-
}, null);
|
|
3063
|
-
// 切换上下文行为
|
|
3064
|
-
this.on(CONTEXT_ACTIONS.INIT, () => {
|
|
3065
|
-
__classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this);
|
|
3066
|
-
}, null);
|
|
3067
|
-
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3068
|
-
cache$1.set(pageId, {
|
|
3069
|
-
location: __classPrivateFieldGet(this, _History_location, "f"),
|
|
3070
|
-
stack: __classPrivateFieldGet(this, _History_stack, "f"),
|
|
3071
|
-
cur: __classPrivateFieldGet(this, _History_cur, "f")
|
|
3072
|
-
});
|
|
3073
|
-
}, null);
|
|
3074
|
-
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
3075
|
-
if (cache$1.has(pageId)) {
|
|
3076
|
-
const ctx = cache$1.get(pageId);
|
|
3077
|
-
__classPrivateFieldSet(this, _History_location, ctx.location, "f");
|
|
3078
|
-
__classPrivateFieldSet(this, _History_stack, ctx.stack, "f");
|
|
3079
|
-
__classPrivateFieldSet(this, _History_cur, ctx.cur, "f");
|
|
3080
|
-
}
|
|
3081
|
-
}, null);
|
|
3082
|
-
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
3083
|
-
cache$1.delete(pageId);
|
|
3084
|
-
}, null);
|
|
3085
|
-
__classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this);
|
|
3086
|
-
}
|
|
3087
|
-
/* public property */
|
|
3088
|
-
get length() {
|
|
3089
|
-
return __classPrivateFieldGet(this, _History_stack, "f").length;
|
|
3090
|
-
}
|
|
3091
|
-
get state() {
|
|
3092
|
-
return __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")];
|
|
3093
|
-
}
|
|
3094
|
-
/* public method */
|
|
3095
|
-
go(delta) {
|
|
3096
|
-
if (!isNumber(delta) || isNaN(delta))
|
|
3097
|
-
return;
|
|
3098
|
-
let targetIdx = __classPrivateFieldGet(this, _History_cur, "f") + delta;
|
|
3099
|
-
targetIdx = Math.min(Math.max(targetIdx, 0), this.length - 1);
|
|
3100
|
-
__classPrivateFieldSet(this, _History_cur, targetIdx, "f");
|
|
3101
|
-
__classPrivateFieldGet(this, _History_location, "f").trigger('__set_href_without_history__', __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")].url);
|
|
3102
|
-
__classPrivateFieldGet(this, _History_window, "f").trigger('popstate', __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")]);
|
|
3103
|
-
}
|
|
3104
|
-
back() {
|
|
3105
|
-
this.go(-1);
|
|
3106
|
-
}
|
|
3107
|
-
forward() {
|
|
3108
|
-
this.go(1);
|
|
3109
|
-
}
|
|
3110
|
-
pushState(state, title, url) {
|
|
3111
|
-
if (!url || !isString(url))
|
|
3112
|
-
return;
|
|
3113
|
-
__classPrivateFieldSet(this, _History_stack, __classPrivateFieldGet(this, _History_stack, "f").slice(0, __classPrivateFieldGet(this, _History_cur, "f") + 1), "f");
|
|
3114
|
-
__classPrivateFieldGet(this, _History_stack, "f").push({
|
|
3115
|
-
state,
|
|
3116
|
-
title,
|
|
3117
|
-
url
|
|
3118
|
-
});
|
|
3119
|
-
__classPrivateFieldSet(this, _History_cur, this.length - 1, "f");
|
|
3120
|
-
__classPrivateFieldGet(this, _History_location, "f").trigger('__set_href_without_history__', url);
|
|
3121
|
-
}
|
|
3122
|
-
replaceState(state, title, url) {
|
|
3123
|
-
if (!url || !isString(url))
|
|
3124
|
-
return;
|
|
3125
|
-
__classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")] = {
|
|
3126
|
-
state,
|
|
3127
|
-
title,
|
|
3128
|
-
url
|
|
3129
|
-
};
|
|
3130
|
-
__classPrivateFieldGet(this, _History_location, "f").trigger('__set_href_without_history__', url);
|
|
3131
|
-
}
|
|
3132
|
-
// For debug
|
|
3133
|
-
get cache() {
|
|
3134
|
-
return cache$1;
|
|
2776
|
+
delete(identifier) {
|
|
2777
|
+
this.cache.delete(identifier);
|
|
3135
2778
|
}
|
|
3136
2779
|
}
|
|
3137
|
-
_History_location = new WeakMap(), _History_stack = new WeakMap(), _History_cur = new WeakMap(), _History_window = new WeakMap(), _History_instances = new WeakSet(), _History_reset = function _History_reset(href = '') {
|
|
3138
|
-
__classPrivateFieldSet(this, _History_stack, [
|
|
3139
|
-
{
|
|
3140
|
-
state: null,
|
|
3141
|
-
title: '',
|
|
3142
|
-
url: href || __classPrivateFieldGet(this, _History_location, "f").href
|
|
3143
|
-
}
|
|
3144
|
-
], "f");
|
|
3145
|
-
__classPrivateFieldSet(this, _History_cur, 0, "f");
|
|
3146
|
-
};
|
|
3147
|
-
|
|
3148
|
-
const Current = {
|
|
3149
|
-
app: null,
|
|
3150
|
-
router: null,
|
|
3151
|
-
page: null
|
|
3152
|
-
};
|
|
3153
|
-
const getCurrentInstance = () => Current;
|
|
3154
2780
|
|
|
3155
2781
|
var _Location_instances, _Location_hash, _Location_hostname, _Location_pathname, _Location_port, _Location_protocol, _Location_search, _Location_noCheckUrl, _Location_window, _Location_reset, _Location_getPreValue, _Location_rollBack, _Location_recordHistory, _Location_checkUrlChange;
|
|
3156
2782
|
const DEFAULT_HOSTNAME = 'taro.com';
|
|
3157
|
-
const cache = new RuntimeCache('location');
|
|
2783
|
+
const cache$1 = new RuntimeCache('location');
|
|
3158
2784
|
class Location extends Events {
|
|
3159
2785
|
constructor(options) {
|
|
3160
2786
|
super();
|
|
@@ -3184,21 +2810,21 @@ class Location extends Events {
|
|
|
3184
2810
|
__classPrivateFieldGet(this, _Location_instances, "m", _Location_reset).call(this);
|
|
3185
2811
|
}, null);
|
|
3186
2812
|
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3187
|
-
cache.set(pageId, {
|
|
2813
|
+
cache$1.set(pageId, {
|
|
3188
2814
|
lastHref: this.href
|
|
3189
2815
|
});
|
|
3190
2816
|
}, null);
|
|
3191
2817
|
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
3192
2818
|
// 数据恢复时,不需要执行跳转
|
|
3193
|
-
if (cache.has(pageId)) {
|
|
3194
|
-
const ctx = cache.get(pageId);
|
|
2819
|
+
if (cache$1.has(pageId)) {
|
|
2820
|
+
const ctx = cache$1.get(pageId);
|
|
3195
2821
|
__classPrivateFieldSet(this, _Location_noCheckUrl, true, "f");
|
|
3196
2822
|
this.href = ctx.lastHref;
|
|
3197
2823
|
__classPrivateFieldSet(this, _Location_noCheckUrl, false, "f");
|
|
3198
2824
|
}
|
|
3199
2825
|
}, null);
|
|
3200
2826
|
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
3201
|
-
cache.delete(pageId);
|
|
2827
|
+
cache$1.delete(pageId);
|
|
3202
2828
|
}, null);
|
|
3203
2829
|
}
|
|
3204
2830
|
/* public property */
|
|
@@ -3344,146 +2970,580 @@ class Location extends Events {
|
|
|
3344
2970
|
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3345
2971
|
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3346
2972
|
}
|
|
3347
|
-
/* public method */
|
|
3348
|
-
assign() {
|
|
3349
|
-
warn(true, '小程序环境中调用location.assign()无效.');
|
|
2973
|
+
/* public method */
|
|
2974
|
+
assign() {
|
|
2975
|
+
warn(true, '小程序环境中调用location.assign()无效.');
|
|
2976
|
+
}
|
|
2977
|
+
reload() {
|
|
2978
|
+
warn(true, '小程序环境中调用location.reload()无效.');
|
|
2979
|
+
}
|
|
2980
|
+
replace(val) {
|
|
2981
|
+
this.trigger('__set_href_without_history__', val);
|
|
2982
|
+
}
|
|
2983
|
+
toString() {
|
|
2984
|
+
return this.href;
|
|
2985
|
+
}
|
|
2986
|
+
// For debug
|
|
2987
|
+
get cache() {
|
|
2988
|
+
return cache$1;
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
_Location_hash = new WeakMap(), _Location_hostname = new WeakMap(), _Location_pathname = new WeakMap(), _Location_port = new WeakMap(), _Location_protocol = new WeakMap(), _Location_search = new WeakMap(), _Location_noCheckUrl = new WeakMap(), _Location_window = new WeakMap(), _Location_instances = new WeakSet(), _Location_reset = function _Location_reset() {
|
|
2992
|
+
const Current = getCurrentInstance();
|
|
2993
|
+
const router = Current.router;
|
|
2994
|
+
if (router) {
|
|
2995
|
+
const { path, params } = router;
|
|
2996
|
+
const searchArr = Object.keys(params).map(key => {
|
|
2997
|
+
return `${key}=${params[key]}`;
|
|
2998
|
+
});
|
|
2999
|
+
const searchStr = searchArr.length > 0 ? '?' + searchArr.join('&') : '';
|
|
3000
|
+
const url = `https://${DEFAULT_HOSTNAME}${path.startsWith('/') ? path : '/' + path}${searchStr}`;
|
|
3001
|
+
// 初始化页面链接时,默认pathname为 "/"
|
|
3002
|
+
// const url = `https://${DEFAULT_HOSTNAME}${searchStr}`
|
|
3003
|
+
const { protocol, hostname, port, pathname, search, hash } = parseUrl(url);
|
|
3004
|
+
__classPrivateFieldSet(this, _Location_protocol, protocol, "f");
|
|
3005
|
+
__classPrivateFieldSet(this, _Location_hostname, hostname, "f");
|
|
3006
|
+
__classPrivateFieldSet(this, _Location_port, port, "f");
|
|
3007
|
+
__classPrivateFieldSet(this, _Location_pathname, pathname, "f");
|
|
3008
|
+
__classPrivateFieldSet(this, _Location_search, search, "f");
|
|
3009
|
+
__classPrivateFieldSet(this, _Location_hash, hash, "f");
|
|
3010
|
+
this.trigger('__reset_history__', this.href);
|
|
3011
|
+
}
|
|
3012
|
+
}, _Location_getPreValue = function _Location_getPreValue() {
|
|
3013
|
+
return {
|
|
3014
|
+
protocol: __classPrivateFieldGet(this, _Location_protocol, "f"),
|
|
3015
|
+
hostname: __classPrivateFieldGet(this, _Location_hostname, "f"),
|
|
3016
|
+
port: __classPrivateFieldGet(this, _Location_port, "f"),
|
|
3017
|
+
pathname: __classPrivateFieldGet(this, _Location_pathname, "f"),
|
|
3018
|
+
search: __classPrivateFieldGet(this, _Location_search, "f"),
|
|
3019
|
+
hash: __classPrivateFieldGet(this, _Location_hash, "f")
|
|
3020
|
+
};
|
|
3021
|
+
}, _Location_rollBack = function _Location_rollBack(preValue) {
|
|
3022
|
+
__classPrivateFieldSet(this, _Location_protocol, preValue.protocol, "f");
|
|
3023
|
+
__classPrivateFieldSet(this, _Location_hostname, preValue.hostname, "f");
|
|
3024
|
+
__classPrivateFieldSet(this, _Location_port, preValue.port, "f");
|
|
3025
|
+
__classPrivateFieldSet(this, _Location_pathname, preValue.pathname, "f");
|
|
3026
|
+
__classPrivateFieldSet(this, _Location_search, preValue.search, "f");
|
|
3027
|
+
__classPrivateFieldSet(this, _Location_hash, preValue.hash, "f");
|
|
3028
|
+
}, _Location_recordHistory = function _Location_recordHistory() {
|
|
3029
|
+
this.trigger('__record_history__', this.href);
|
|
3030
|
+
}, _Location_checkUrlChange = function _Location_checkUrlChange(preValue) {
|
|
3031
|
+
if (__classPrivateFieldGet(this, _Location_noCheckUrl, "f")) {
|
|
3032
|
+
return false;
|
|
3033
|
+
}
|
|
3034
|
+
// 跨域三要素不允许修改
|
|
3035
|
+
if (__classPrivateFieldGet(this, _Location_protocol, "f") !== preValue.protocol || __classPrivateFieldGet(this, _Location_hostname, "f") !== preValue.hostname || this.port !== preValue.port) {
|
|
3036
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue);
|
|
3037
|
+
return false;
|
|
3038
|
+
}
|
|
3039
|
+
// pathname
|
|
3040
|
+
if (__classPrivateFieldGet(this, _Location_pathname, "f") !== preValue.pathname) {
|
|
3041
|
+
return true;
|
|
3042
|
+
}
|
|
3043
|
+
// search
|
|
3044
|
+
if (__classPrivateFieldGet(this, _Location_search, "f") !== preValue.search) {
|
|
3045
|
+
return true;
|
|
3046
|
+
}
|
|
3047
|
+
// hashchange
|
|
3048
|
+
if (__classPrivateFieldGet(this, _Location_hash, "f") !== preValue.hash) {
|
|
3049
|
+
__classPrivateFieldGet(this, _Location_window, "f").trigger('hashchange');
|
|
3050
|
+
return true;
|
|
3051
|
+
}
|
|
3052
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue);
|
|
3053
|
+
return false;
|
|
3054
|
+
};
|
|
3055
|
+
function resolveRelativePath(path, relative) {
|
|
3056
|
+
const relativeArr = relative.split('/');
|
|
3057
|
+
const parent = relativeArr.slice(0, relativeArr.length - 1);
|
|
3058
|
+
let depth = 0;
|
|
3059
|
+
const dests = path.split('../').map(v => {
|
|
3060
|
+
v === '' && depth++;
|
|
3061
|
+
return v;
|
|
3062
|
+
});
|
|
3063
|
+
if (depth > parent.length)
|
|
3064
|
+
return relative;
|
|
3065
|
+
return parent.slice(0, parent.length - depth).concat(dests.filter(v => v !== '')).join('/');
|
|
3066
|
+
}
|
|
3067
|
+
function generateFullUrl(val = '') {
|
|
3068
|
+
const origin = `https://${DEFAULT_HOSTNAME}`;
|
|
3069
|
+
if (val.startsWith('/')) {
|
|
3070
|
+
return origin + val;
|
|
3071
|
+
}
|
|
3072
|
+
if (val.startsWith('?')) {
|
|
3073
|
+
return origin + val;
|
|
3074
|
+
}
|
|
3075
|
+
if (val.startsWith('#')) {
|
|
3076
|
+
return origin + val;
|
|
3077
|
+
}
|
|
3078
|
+
if (/(https?:)?\/\//.test(val)) {
|
|
3079
|
+
return val;
|
|
3080
|
+
}
|
|
3081
|
+
return val;
|
|
3082
|
+
}
|
|
3083
|
+
function parseUrl(url = '') {
|
|
3084
|
+
const result = {
|
|
3085
|
+
href: '',
|
|
3086
|
+
origin: '',
|
|
3087
|
+
protocol: '',
|
|
3088
|
+
hostname: '',
|
|
3089
|
+
host: '',
|
|
3090
|
+
port: '',
|
|
3091
|
+
pathname: '',
|
|
3092
|
+
search: '',
|
|
3093
|
+
hash: ''
|
|
3094
|
+
};
|
|
3095
|
+
if (!url || !isString(url))
|
|
3096
|
+
return result;
|
|
3097
|
+
url = url.trim();
|
|
3098
|
+
const PATTERN = /^(([^:/?#]+):)?\/\/(([^/?#]+):(.+)@)?([^/?#:]*)(:(\d+))?([^?#]*)(\?([^#]*))?(#(.*))?/;
|
|
3099
|
+
const matches = url.match(PATTERN);
|
|
3100
|
+
if (!matches)
|
|
3101
|
+
return result;
|
|
3102
|
+
result.protocol = matches[1] || 'https:';
|
|
3103
|
+
result.hostname = matches[6] || DEFAULT_HOSTNAME;
|
|
3104
|
+
result.port = matches[8] || '';
|
|
3105
|
+
result.pathname = matches[9] || '/';
|
|
3106
|
+
result.search = matches[10] || '';
|
|
3107
|
+
result.hash = matches[12] || '';
|
|
3108
|
+
result.href = url;
|
|
3109
|
+
result.origin = result.protocol + '//' + result.hostname;
|
|
3110
|
+
result.host = result.hostname + (result.port ? `:${result.port}` : '');
|
|
3111
|
+
return result;
|
|
3112
|
+
}
|
|
3113
|
+
|
|
3114
|
+
class AnchorElement extends TaroElement {
|
|
3115
|
+
get href() {
|
|
3116
|
+
var _a;
|
|
3117
|
+
return (_a = this.props["href" /* AnchorElementAttrs.HREF */]) !== null && _a !== void 0 ? _a : '';
|
|
3118
|
+
}
|
|
3119
|
+
set href(val) {
|
|
3120
|
+
this.setAttribute("href" /* AnchorElementAttrs.HREF */, val);
|
|
3121
|
+
}
|
|
3122
|
+
get protocol() {
|
|
3123
|
+
var _a;
|
|
3124
|
+
return (_a = this.props["protocol" /* AnchorElementAttrs.PROTOCOL */]) !== null && _a !== void 0 ? _a : '';
|
|
3125
|
+
}
|
|
3126
|
+
get host() {
|
|
3127
|
+
var _a;
|
|
3128
|
+
return (_a = this.props["host" /* AnchorElementAttrs.HOST */]) !== null && _a !== void 0 ? _a : '';
|
|
3129
|
+
}
|
|
3130
|
+
get search() {
|
|
3131
|
+
var _a;
|
|
3132
|
+
return (_a = this.props["search" /* AnchorElementAttrs.SEARCH */]) !== null && _a !== void 0 ? _a : '';
|
|
3133
|
+
}
|
|
3134
|
+
get hash() {
|
|
3135
|
+
var _a;
|
|
3136
|
+
return (_a = this.props["hash" /* AnchorElementAttrs.HASH */]) !== null && _a !== void 0 ? _a : '';
|
|
3137
|
+
}
|
|
3138
|
+
get hostname() {
|
|
3139
|
+
var _a;
|
|
3140
|
+
return (_a = this.props["hostname" /* AnchorElementAttrs.HOSTNAME */]) !== null && _a !== void 0 ? _a : '';
|
|
3141
|
+
}
|
|
3142
|
+
get port() {
|
|
3143
|
+
var _a;
|
|
3144
|
+
return (_a = this.props["port" /* AnchorElementAttrs.PORT */]) !== null && _a !== void 0 ? _a : '';
|
|
3145
|
+
}
|
|
3146
|
+
get pathname() {
|
|
3147
|
+
var _a;
|
|
3148
|
+
return (_a = this.props["pathname" /* AnchorElementAttrs.PATHNAME */]) !== null && _a !== void 0 ? _a : '';
|
|
3149
|
+
}
|
|
3150
|
+
setAttribute(qualifiedName, value) {
|
|
3151
|
+
if (qualifiedName === "href" /* AnchorElementAttrs.HREF */) {
|
|
3152
|
+
const willSetAttr = parseUrl(value);
|
|
3153
|
+
for (const k in willSetAttr) {
|
|
3154
|
+
super.setAttribute(k, willSetAttr[k]);
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
else {
|
|
3158
|
+
super.setAttribute(qualifiedName, value);
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
}
|
|
3162
|
+
|
|
3163
|
+
class TaroDocument extends TaroElement {
|
|
3164
|
+
constructor() {
|
|
3165
|
+
super();
|
|
3166
|
+
this.createEvent = createEvent;
|
|
3167
|
+
this.nodeType = 9 /* NodeType.DOCUMENT_NODE */;
|
|
3168
|
+
this.nodeName = DOCUMENT_ELEMENT_NAME;
|
|
3169
|
+
}
|
|
3170
|
+
createElement(type) {
|
|
3171
|
+
const nodeName = type.toLowerCase();
|
|
3172
|
+
let element;
|
|
3173
|
+
switch (true) {
|
|
3174
|
+
case nodeName === ROOT_STR:
|
|
3175
|
+
element = new TaroRootElement();
|
|
3176
|
+
return element;
|
|
3177
|
+
case controlledComponent.has(nodeName):
|
|
3178
|
+
element = new FormElement();
|
|
3179
|
+
break;
|
|
3180
|
+
case nodeName === A:
|
|
3181
|
+
element = new AnchorElement();
|
|
3182
|
+
break;
|
|
3183
|
+
default:
|
|
3184
|
+
element = new TaroElement();
|
|
3185
|
+
break;
|
|
3186
|
+
}
|
|
3187
|
+
element.nodeName = nodeName;
|
|
3188
|
+
element.tagName = type.toUpperCase();
|
|
3189
|
+
return element;
|
|
3190
|
+
}
|
|
3191
|
+
// an ugly fake createElementNS to deal with @vue/runtime-dom's
|
|
3192
|
+
// support mounting app to svg container since vue@3.0.8
|
|
3193
|
+
createElementNS(_svgNS, type) {
|
|
3194
|
+
return this.createElement(type);
|
|
3195
|
+
}
|
|
3196
|
+
createTextNode(text) {
|
|
3197
|
+
return new TaroText(text);
|
|
3198
|
+
}
|
|
3199
|
+
getElementById(id) {
|
|
3200
|
+
const el = eventSource.get(id);
|
|
3201
|
+
return isUndefined(el) ? null : el;
|
|
3202
|
+
}
|
|
3203
|
+
querySelector(query) {
|
|
3204
|
+
// 为了 Vue3 的乞丐版实现
|
|
3205
|
+
if (/^#/.test(query)) {
|
|
3206
|
+
return this.getElementById(query.slice(1));
|
|
3207
|
+
}
|
|
3208
|
+
return null;
|
|
3209
|
+
}
|
|
3210
|
+
querySelectorAll() {
|
|
3211
|
+
// fake hack
|
|
3212
|
+
return [];
|
|
3213
|
+
}
|
|
3214
|
+
// @TODO: @PERF: 在 hydrate 移除掉空的 node
|
|
3215
|
+
createComment() {
|
|
3216
|
+
const textnode = new TaroText('');
|
|
3217
|
+
textnode.nodeName = COMMENT;
|
|
3218
|
+
return textnode;
|
|
3219
|
+
}
|
|
3220
|
+
get defaultView() {
|
|
3221
|
+
return env.window;
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
|
|
3225
|
+
let document$1;
|
|
3226
|
+
if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
3227
|
+
/* eslint-disable no-inner-declarations */
|
|
3228
|
+
function createDocument() {
|
|
3229
|
+
/**
|
|
3230
|
+
* <document>
|
|
3231
|
+
* <html>
|
|
3232
|
+
* <head></head>
|
|
3233
|
+
* <body>
|
|
3234
|
+
* <container>
|
|
3235
|
+
* <app id="app" />
|
|
3236
|
+
* </container>
|
|
3237
|
+
* </body>
|
|
3238
|
+
* </html>
|
|
3239
|
+
* </document>
|
|
3240
|
+
*/
|
|
3241
|
+
const doc = new TaroDocument();
|
|
3242
|
+
const documentCreateElement = doc.createElement.bind(doc);
|
|
3243
|
+
const html = documentCreateElement(HTML);
|
|
3244
|
+
const head = documentCreateElement(HEAD);
|
|
3245
|
+
const body = documentCreateElement(BODY);
|
|
3246
|
+
const app = documentCreateElement(APP);
|
|
3247
|
+
app.id = APP;
|
|
3248
|
+
const container = documentCreateElement(CONTAINER); // 多包一层主要为了兼容 vue
|
|
3249
|
+
doc.appendChild(html);
|
|
3250
|
+
html.appendChild(head);
|
|
3251
|
+
html.appendChild(body);
|
|
3252
|
+
body.appendChild(container);
|
|
3253
|
+
container.appendChild(app);
|
|
3254
|
+
doc.documentElement = html;
|
|
3255
|
+
doc.head = head;
|
|
3256
|
+
doc.body = body;
|
|
3257
|
+
return doc;
|
|
3258
|
+
}
|
|
3259
|
+
document$1 = env.document = createDocument();
|
|
3260
|
+
}
|
|
3261
|
+
else {
|
|
3262
|
+
document$1 = env.document;
|
|
3263
|
+
}
|
|
3264
|
+
|
|
3265
|
+
function getComputedStyle(element) {
|
|
3266
|
+
return element.style;
|
|
3267
|
+
}
|
|
3268
|
+
|
|
3269
|
+
const machine = 'Macintosh';
|
|
3270
|
+
const arch = 'Intel Mac OS X 10_14_5';
|
|
3271
|
+
const engine = 'AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36';
|
|
3272
|
+
const msg = '(' + machine + '; ' + arch + ') ' + engine;
|
|
3273
|
+
const nav = process.env.TARO_ENV === 'h5' ? env.window.navigator : {
|
|
3274
|
+
appCodeName: 'Mozilla',
|
|
3275
|
+
appName: 'Netscape',
|
|
3276
|
+
appVersion: '5.0 ' + msg,
|
|
3277
|
+
cookieEnabled: true,
|
|
3278
|
+
mimeTypes: [],
|
|
3279
|
+
onLine: true,
|
|
3280
|
+
platform: 'MacIntel',
|
|
3281
|
+
plugins: [],
|
|
3282
|
+
product: 'Taro',
|
|
3283
|
+
productSub: '20030107',
|
|
3284
|
+
userAgent: 'Mozilla/5.0 ' + msg,
|
|
3285
|
+
vendor: 'Joyent',
|
|
3286
|
+
vendorSub: ''
|
|
3287
|
+
};
|
|
3288
|
+
|
|
3289
|
+
// https://github.com/myrne/performance-now
|
|
3290
|
+
let now;
|
|
3291
|
+
(function () {
|
|
3292
|
+
let loadTime;
|
|
3293
|
+
if ((typeof performance !== 'undefined' && performance !== null) && performance.now) {
|
|
3294
|
+
now = () => performance.now();
|
|
3295
|
+
}
|
|
3296
|
+
else if (Date.now) {
|
|
3297
|
+
loadTime = Date.now();
|
|
3298
|
+
now = () => Date.now() - loadTime;
|
|
3299
|
+
}
|
|
3300
|
+
else {
|
|
3301
|
+
loadTime = new Date().getTime();
|
|
3302
|
+
now = () => new Date().getTime() - loadTime;
|
|
3303
|
+
}
|
|
3304
|
+
})();
|
|
3305
|
+
let lastTime = 0;
|
|
3306
|
+
// https://gist.github.com/paulirish/1579671
|
|
3307
|
+
// https://gist.github.com/jalbam/5fe05443270fa6d8136238ec72accbc0
|
|
3308
|
+
const _raf = typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame !== null ? requestAnimationFrame : function (callback) {
|
|
3309
|
+
const _now = now();
|
|
3310
|
+
const nextTime = Math.max(lastTime + 16, _now); // First time will execute it immediately but barely noticeable and performance is gained.
|
|
3311
|
+
return setTimeout(function () { callback(lastTime = nextTime); }, nextTime - _now);
|
|
3312
|
+
};
|
|
3313
|
+
const _caf = typeof cancelAnimationFrame !== 'undefined' && cancelAnimationFrame !== null
|
|
3314
|
+
? cancelAnimationFrame
|
|
3315
|
+
: function (seed) {
|
|
3316
|
+
// fix https://github.com/NervJS/taro/issues/7749
|
|
3317
|
+
clearTimeout(seed);
|
|
3318
|
+
};
|
|
3319
|
+
|
|
3320
|
+
var _URLSearchParams_dict;
|
|
3321
|
+
const findReg = /[!'()~]|%20|%00/g;
|
|
3322
|
+
const plusReg = /\+/g;
|
|
3323
|
+
const replaceCharMap = {
|
|
3324
|
+
'!': '%21',
|
|
3325
|
+
"'": '%27',
|
|
3326
|
+
'(': '%28',
|
|
3327
|
+
')': '%29',
|
|
3328
|
+
'~': '%7E',
|
|
3329
|
+
'%20': '+',
|
|
3330
|
+
'%00': '\x00',
|
|
3331
|
+
};
|
|
3332
|
+
function replacer(match) {
|
|
3333
|
+
return replaceCharMap[match];
|
|
3334
|
+
}
|
|
3335
|
+
function appendTo(dict, name, value) {
|
|
3336
|
+
const res = isArray(value) ? value.join(',') : value;
|
|
3337
|
+
if (name in dict)
|
|
3338
|
+
dict[name].push(res);
|
|
3339
|
+
else
|
|
3340
|
+
dict[name] = [res];
|
|
3341
|
+
}
|
|
3342
|
+
function addEach(value, key) {
|
|
3343
|
+
appendTo(this, key, value);
|
|
3344
|
+
}
|
|
3345
|
+
function decode(str) {
|
|
3346
|
+
return decodeURIComponent(str.replace(plusReg, ' '));
|
|
3347
|
+
}
|
|
3348
|
+
function encode(str) {
|
|
3349
|
+
return encodeURIComponent(str).replace(findReg, replacer);
|
|
3350
|
+
}
|
|
3351
|
+
class URLSearchParams {
|
|
3352
|
+
constructor(query) {
|
|
3353
|
+
_URLSearchParams_dict.set(this, Object.create(null));
|
|
3354
|
+
if (!query)
|
|
3355
|
+
return;
|
|
3356
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
3357
|
+
if (typeof query === 'string') {
|
|
3358
|
+
if (query.charAt(0) === '?') {
|
|
3359
|
+
query = query.slice(1);
|
|
3360
|
+
}
|
|
3361
|
+
for (let pairs = query.split('&'), i = 0, length = pairs.length; i < length; i++) {
|
|
3362
|
+
const value = pairs[i];
|
|
3363
|
+
const index = value.indexOf('=');
|
|
3364
|
+
if (index > -1) {
|
|
3365
|
+
appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));
|
|
3366
|
+
}
|
|
3367
|
+
else if (value.length) {
|
|
3368
|
+
appendTo(dict, decode(value), '');
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
else {
|
|
3373
|
+
if (isArray(query)) {
|
|
3374
|
+
for (let i = 0, length = query.length; i < length; i++) {
|
|
3375
|
+
const value = query[i];
|
|
3376
|
+
appendTo(dict, value[0], value[1]);
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3379
|
+
else if (query.forEach) {
|
|
3380
|
+
query.forEach(addEach, dict);
|
|
3381
|
+
}
|
|
3382
|
+
else {
|
|
3383
|
+
for (const key in query) {
|
|
3384
|
+
appendTo(dict, key, query[key]);
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
append(name, value) {
|
|
3390
|
+
appendTo(__classPrivateFieldGet(this, _URLSearchParams_dict, "f"), name, value);
|
|
3391
|
+
}
|
|
3392
|
+
delete(name) {
|
|
3393
|
+
delete __classPrivateFieldGet(this, _URLSearchParams_dict, "f")[name];
|
|
3394
|
+
}
|
|
3395
|
+
get(name) {
|
|
3396
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
3397
|
+
return name in dict ? dict[name][0] : null;
|
|
3398
|
+
}
|
|
3399
|
+
getAll(name) {
|
|
3400
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
3401
|
+
return name in dict ? dict[name].slice(0) : [];
|
|
3402
|
+
}
|
|
3403
|
+
has(name) {
|
|
3404
|
+
return name in __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
3405
|
+
}
|
|
3406
|
+
keys() {
|
|
3407
|
+
return Object.keys(__classPrivateFieldGet(this, _URLSearchParams_dict, "f"));
|
|
3350
3408
|
}
|
|
3351
|
-
|
|
3352
|
-
|
|
3409
|
+
set(name, value) {
|
|
3410
|
+
__classPrivateFieldGet(this, _URLSearchParams_dict, "f")[name] = ['' + value];
|
|
3353
3411
|
}
|
|
3354
|
-
|
|
3355
|
-
this
|
|
3412
|
+
forEach(callback, thisArg) {
|
|
3413
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
3414
|
+
Object.getOwnPropertyNames(dict).forEach(function (name) {
|
|
3415
|
+
dict[name].forEach(function (value) {
|
|
3416
|
+
callback.call(thisArg, value, name, this);
|
|
3417
|
+
}, this);
|
|
3418
|
+
}, this);
|
|
3356
3419
|
}
|
|
3357
|
-
|
|
3358
|
-
return
|
|
3420
|
+
toJSON() {
|
|
3421
|
+
return {};
|
|
3359
3422
|
}
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3423
|
+
toString() {
|
|
3424
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
3425
|
+
const query = [];
|
|
3426
|
+
for (const key in dict) {
|
|
3427
|
+
const name = encode(key);
|
|
3428
|
+
for (let i = 0, value = dict[key]; i < value.length; i++) {
|
|
3429
|
+
query.push(name + '=' + encode(value[i]));
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
return query.join('&');
|
|
3363
3433
|
}
|
|
3364
3434
|
}
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
__classPrivateFieldSet(this,
|
|
3379
|
-
__classPrivateFieldSet(this,
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
}
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3435
|
+
_URLSearchParams_dict = new WeakMap();
|
|
3436
|
+
|
|
3437
|
+
var _History_instances, _History_location, _History_stack, _History_cur, _History_window, _History_reset;
|
|
3438
|
+
const cache = new RuntimeCache('history');
|
|
3439
|
+
class History extends Events {
|
|
3440
|
+
constructor(location, options) {
|
|
3441
|
+
super();
|
|
3442
|
+
_History_instances.add(this);
|
|
3443
|
+
/* private property */
|
|
3444
|
+
_History_location.set(this, void 0);
|
|
3445
|
+
_History_stack.set(this, []);
|
|
3446
|
+
_History_cur.set(this, 0);
|
|
3447
|
+
_History_window.set(this, void 0);
|
|
3448
|
+
__classPrivateFieldSet(this, _History_window, options.window, "f");
|
|
3449
|
+
__classPrivateFieldSet(this, _History_location, location, "f");
|
|
3450
|
+
__classPrivateFieldGet(this, _History_location, "f").on('__record_history__', (href) => {
|
|
3451
|
+
var _a;
|
|
3452
|
+
__classPrivateFieldSet(this, _History_cur, (_a = __classPrivateFieldGet(this, _History_cur, "f"), _a++, _a), "f");
|
|
3453
|
+
__classPrivateFieldSet(this, _History_stack, __classPrivateFieldGet(this, _History_stack, "f").slice(0, __classPrivateFieldGet(this, _History_cur, "f")), "f");
|
|
3454
|
+
__classPrivateFieldGet(this, _History_stack, "f").push({
|
|
3455
|
+
state: null,
|
|
3456
|
+
title: '',
|
|
3457
|
+
url: href
|
|
3458
|
+
});
|
|
3459
|
+
}, null);
|
|
3460
|
+
__classPrivateFieldGet(this, _History_location, "f").on('__reset_history__', (href) => {
|
|
3461
|
+
__classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this, href);
|
|
3462
|
+
}, null);
|
|
3463
|
+
// 切换上下文行为
|
|
3464
|
+
this.on(CONTEXT_ACTIONS.INIT, () => {
|
|
3465
|
+
__classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this);
|
|
3466
|
+
}, null);
|
|
3467
|
+
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3468
|
+
cache.set(pageId, {
|
|
3469
|
+
location: __classPrivateFieldGet(this, _History_location, "f"),
|
|
3470
|
+
stack: __classPrivateFieldGet(this, _History_stack, "f"),
|
|
3471
|
+
cur: __classPrivateFieldGet(this, _History_cur, "f")
|
|
3472
|
+
});
|
|
3473
|
+
}, null);
|
|
3474
|
+
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
3475
|
+
if (cache.has(pageId)) {
|
|
3476
|
+
const ctx = cache.get(pageId);
|
|
3477
|
+
__classPrivateFieldSet(this, _History_location, ctx.location, "f");
|
|
3478
|
+
__classPrivateFieldSet(this, _History_stack, ctx.stack, "f");
|
|
3479
|
+
__classPrivateFieldSet(this, _History_cur, ctx.cur, "f");
|
|
3480
|
+
}
|
|
3481
|
+
}, null);
|
|
3482
|
+
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
3483
|
+
cache.delete(pageId);
|
|
3484
|
+
}, null);
|
|
3485
|
+
__classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this);
|
|
3407
3486
|
}
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
__classPrivateFieldGet(this,
|
|
3411
|
-
return false;
|
|
3487
|
+
/* public property */
|
|
3488
|
+
get length() {
|
|
3489
|
+
return __classPrivateFieldGet(this, _History_stack, "f").length;
|
|
3412
3490
|
}
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
return true;
|
|
3491
|
+
get state() {
|
|
3492
|
+
return __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")];
|
|
3416
3493
|
}
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3494
|
+
/* public method */
|
|
3495
|
+
go(delta) {
|
|
3496
|
+
if (!isNumber(delta) || isNaN(delta))
|
|
3497
|
+
return;
|
|
3498
|
+
let targetIdx = __classPrivateFieldGet(this, _History_cur, "f") + delta;
|
|
3499
|
+
targetIdx = Math.min(Math.max(targetIdx, 0), this.length - 1);
|
|
3500
|
+
__classPrivateFieldSet(this, _History_cur, targetIdx, "f");
|
|
3501
|
+
__classPrivateFieldGet(this, _History_location, "f").trigger('__set_href_without_history__', __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")].url);
|
|
3502
|
+
__classPrivateFieldGet(this, _History_window, "f").trigger('popstate', __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")]);
|
|
3420
3503
|
}
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
__classPrivateFieldGet(this, _Location_window, "f").trigger('hashchange');
|
|
3424
|
-
return true;
|
|
3504
|
+
back() {
|
|
3505
|
+
this.go(-1);
|
|
3425
3506
|
}
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
};
|
|
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
|
-
function generateFullUrl(val = '') {
|
|
3442
|
-
const origin = `https://${DEFAULT_HOSTNAME}`;
|
|
3443
|
-
if (val.startsWith('/')) {
|
|
3444
|
-
return origin + val;
|
|
3507
|
+
forward() {
|
|
3508
|
+
this.go(1);
|
|
3445
3509
|
}
|
|
3446
|
-
|
|
3447
|
-
|
|
3510
|
+
pushState(state, title, url) {
|
|
3511
|
+
if (!url || !isString(url))
|
|
3512
|
+
return;
|
|
3513
|
+
__classPrivateFieldSet(this, _History_stack, __classPrivateFieldGet(this, _History_stack, "f").slice(0, __classPrivateFieldGet(this, _History_cur, "f") + 1), "f");
|
|
3514
|
+
__classPrivateFieldGet(this, _History_stack, "f").push({
|
|
3515
|
+
state,
|
|
3516
|
+
title,
|
|
3517
|
+
url
|
|
3518
|
+
});
|
|
3519
|
+
__classPrivateFieldSet(this, _History_cur, this.length - 1, "f");
|
|
3520
|
+
__classPrivateFieldGet(this, _History_location, "f").trigger('__set_href_without_history__', url);
|
|
3448
3521
|
}
|
|
3449
|
-
|
|
3450
|
-
|
|
3522
|
+
replaceState(state, title, url) {
|
|
3523
|
+
if (!url || !isString(url))
|
|
3524
|
+
return;
|
|
3525
|
+
__classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")] = {
|
|
3526
|
+
state,
|
|
3527
|
+
title,
|
|
3528
|
+
url
|
|
3529
|
+
};
|
|
3530
|
+
__classPrivateFieldGet(this, _History_location, "f").trigger('__set_href_without_history__', url);
|
|
3451
3531
|
}
|
|
3452
|
-
|
|
3453
|
-
|
|
3532
|
+
// For debug
|
|
3533
|
+
get cache() {
|
|
3534
|
+
return cache;
|
|
3454
3535
|
}
|
|
3455
|
-
return val;
|
|
3456
|
-
}
|
|
3457
|
-
function parseUrl(url = '') {
|
|
3458
|
-
const result = {
|
|
3459
|
-
href: '',
|
|
3460
|
-
origin: '',
|
|
3461
|
-
protocol: '',
|
|
3462
|
-
hostname: '',
|
|
3463
|
-
host: '',
|
|
3464
|
-
port: '',
|
|
3465
|
-
pathname: '',
|
|
3466
|
-
search: '',
|
|
3467
|
-
hash: ''
|
|
3468
|
-
};
|
|
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
3536
|
}
|
|
3537
|
+
_History_location = new WeakMap(), _History_stack = new WeakMap(), _History_cur = new WeakMap(), _History_window = new WeakMap(), _History_instances = new WeakSet(), _History_reset = function _History_reset(href = '') {
|
|
3538
|
+
__classPrivateFieldSet(this, _History_stack, [
|
|
3539
|
+
{
|
|
3540
|
+
state: null,
|
|
3541
|
+
title: '',
|
|
3542
|
+
url: href || __classPrivateFieldGet(this, _History_location, "f").href
|
|
3543
|
+
}
|
|
3544
|
+
], "f");
|
|
3545
|
+
__classPrivateFieldSet(this, _History_cur, 0, "f");
|
|
3546
|
+
};
|
|
3487
3547
|
|
|
3488
3548
|
let window$1;
|
|
3489
3549
|
if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
|
|
@@ -3716,11 +3776,13 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3716
3776
|
});
|
|
3717
3777
|
},
|
|
3718
3778
|
[ONREADY]() {
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3779
|
+
hasLoaded.then(() => {
|
|
3780
|
+
// 触发生命周期
|
|
3781
|
+
safeExecute(this.$taroPath, ON_READY);
|
|
3782
|
+
// 通过事件触发子组件的生命周期
|
|
3783
|
+
_raf(() => eventCenter.trigger(getOnReadyEventKey(id)));
|
|
3784
|
+
this.onReady.called = true;
|
|
3785
|
+
});
|
|
3724
3786
|
},
|
|
3725
3787
|
[ONSHOW](options = {}) {
|
|
3726
3788
|
hasLoaded.then(() => {
|
|
@@ -3899,5 +3961,5 @@ const nextTick = (cb, ctx) => {
|
|
|
3899
3961
|
}
|
|
3900
3962
|
};
|
|
3901
3963
|
|
|
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 };
|
|
3964
|
+
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, parseUrl, removePageInstance, _raf as requestAnimationFrame, safeExecute, stringify, window$1 as window };
|
|
3903
3965
|
//# sourceMappingURL=runtime.esm.js.map
|