@tarojs/runtime 3.6.0 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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, Events, isNumber, controlledComponent } from '@tarojs/shared';
1
+ import { noop, isFunction, getComponentsAlias as getComponentsAlias$1, internalComponents, EMPTY_OBJ, hooks, toCamelCase, isObject, warn, isArray, ensure, isNull, isUndefined, toDashed, isString, controlledComponent, Events, isNumber } from '@tarojs/shared';
2
2
  export { Events, hooks } from '@tarojs/shared';
3
3
 
4
4
  const PROPERTY_THRESHOLD = 2046;
@@ -52,8 +52,8 @@ const A = 'a';
52
52
  var CONTEXT_ACTIONS;
53
53
  (function (CONTEXT_ACTIONS) {
54
54
  CONTEXT_ACTIONS["INIT"] = "0";
55
- CONTEXT_ACTIONS["RECOVER"] = "1";
56
- CONTEXT_ACTIONS["RESTORE"] = "2";
55
+ CONTEXT_ACTIONS["RESTORE"] = "1";
56
+ CONTEXT_ACTIONS["RECOVER"] = "2";
57
57
  CONTEXT_ACTIONS["DESTORY"] = "3";
58
58
  })(CONTEXT_ACTIONS || (CONTEXT_ACTIONS = {}));
59
59
 
@@ -2757,580 +2757,6 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
2757
2757
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
2758
2758
  }
2759
2759
 
2760
- const Current = {
2761
- app: null,
2762
- router: null,
2763
- page: null
2764
- };
2765
- const getCurrentInstance = () => Current;
2766
-
2767
- const eventCenter = hooks.call('getEventCenter', Events);
2768
-
2769
- /**
2770
- * 一个小型缓存池,用于在切换页面时,存储一些上下文信息
2771
- */
2772
- class RuntimeCache {
2773
- constructor(name) {
2774
- this.cache = new Map();
2775
- this.name = name;
2776
- }
2777
- has(identifier) {
2778
- return this.cache.has(identifier);
2779
- }
2780
- set(identifier, ctx) {
2781
- if (identifier && ctx) {
2782
- this.cache.set(identifier, ctx);
2783
- }
2784
- }
2785
- get(identifier) {
2786
- if (this.has(identifier))
2787
- return this.cache.get(identifier);
2788
- }
2789
- delete(identifier) {
2790
- this.cache.delete(identifier);
2791
- }
2792
- }
2793
-
2794
- 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;
2795
- const DEFAULT_HOSTNAME = 'taro.com';
2796
- const cache$1 = new RuntimeCache('location');
2797
- class Location extends Events {
2798
- constructor(options) {
2799
- super();
2800
- _Location_instances.add(this);
2801
- /* private property */
2802
- _Location_hash.set(this, '');
2803
- _Location_hostname.set(this, DEFAULT_HOSTNAME);
2804
- _Location_pathname.set(this, '/');
2805
- _Location_port.set(this, '');
2806
- _Location_protocol.set(this, 'https:');
2807
- _Location_search.set(this, '');
2808
- _Location_noCheckUrl.set(this, false);
2809
- _Location_window.set(this, void 0);
2810
- __classPrivateFieldSet(this, _Location_window, options.window, "f");
2811
- __classPrivateFieldGet(this, _Location_instances, "m", _Location_reset).call(this);
2812
- this.on('__set_href_without_history__', (href) => {
2813
- __classPrivateFieldSet(this, _Location_noCheckUrl, true, "f");
2814
- const lastHash = __classPrivateFieldGet(this, _Location_hash, "f");
2815
- this.href = generateFullUrl(href);
2816
- if (lastHash !== __classPrivateFieldGet(this, _Location_hash, "f")) {
2817
- __classPrivateFieldGet(this, _Location_window, "f").trigger('hashchange');
2818
- }
2819
- __classPrivateFieldSet(this, _Location_noCheckUrl, false, "f");
2820
- }, null);
2821
- // 切换上下文行为
2822
- this.on(CONTEXT_ACTIONS.INIT, () => {
2823
- __classPrivateFieldGet(this, _Location_instances, "m", _Location_reset).call(this);
2824
- }, null);
2825
- this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
2826
- cache$1.set(pageId, {
2827
- lastHref: this.href
2828
- });
2829
- }, null);
2830
- this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
2831
- // 数据恢复时,不需要执行跳转
2832
- if (cache$1.has(pageId)) {
2833
- const ctx = cache$1.get(pageId);
2834
- __classPrivateFieldSet(this, _Location_noCheckUrl, true, "f");
2835
- this.href = ctx.lastHref;
2836
- __classPrivateFieldSet(this, _Location_noCheckUrl, false, "f");
2837
- }
2838
- }, null);
2839
- this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
2840
- cache$1.delete(pageId);
2841
- }, null);
2842
- }
2843
- /* public property */
2844
- get protocol() {
2845
- return __classPrivateFieldGet(this, _Location_protocol, "f");
2846
- }
2847
- set protocol(val) {
2848
- const reg = /^(http|https):?$/i;
2849
- if (!val || !isString(val) || !reg.test(val.trim()))
2850
- return;
2851
- val = val.trim();
2852
- const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
2853
- __classPrivateFieldSet(this, _Location_protocol, val.endsWith(':') ? val : `${val}:`, "f");
2854
- if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
2855
- __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
2856
- }
2857
- get host() {
2858
- return (__classPrivateFieldGet(this, _Location_hostname, "f") || '') + (__classPrivateFieldGet(this, _Location_port, "f") ? ':' + __classPrivateFieldGet(this, _Location_port, "f") : '');
2859
- }
2860
- set host(val) {
2861
- if (!val || !isString(val))
2862
- return;
2863
- val = val.trim();
2864
- const { hostname, port } = parseUrl(`//${val}`);
2865
- const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
2866
- __classPrivateFieldSet(this, _Location_hostname, hostname, "f");
2867
- __classPrivateFieldSet(this, _Location_port, port, "f");
2868
- if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
2869
- __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
2870
- }
2871
- get hostname() {
2872
- return __classPrivateFieldGet(this, _Location_hostname, "f");
2873
- }
2874
- set hostname(val) {
2875
- if (!val || !isString(val))
2876
- return;
2877
- val = val.trim();
2878
- const { hostname } = parseUrl(`//${val}`);
2879
- const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
2880
- __classPrivateFieldSet(this, _Location_hostname, hostname, "f");
2881
- if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
2882
- __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
2883
- }
2884
- get port() {
2885
- return __classPrivateFieldGet(this, _Location_port, "f");
2886
- }
2887
- set port(val) {
2888
- const xVal = Number((val = val.trim()));
2889
- if (!isNumber(xVal) || xVal <= 0)
2890
- return;
2891
- if (val === __classPrivateFieldGet(this, _Location_port, "f"))
2892
- return;
2893
- const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
2894
- __classPrivateFieldSet(this, _Location_port, val, "f");
2895
- if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
2896
- __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
2897
- }
2898
- get pathname() {
2899
- return __classPrivateFieldGet(this, _Location_pathname, "f");
2900
- }
2901
- set pathname(val) {
2902
- if (!val || !isString(val))
2903
- return;
2904
- val = val.trim();
2905
- const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
2906
- let newPathName = '';
2907
- if (val.startsWith('/')) {
2908
- newPathName = __classPrivateFieldGet(this, _Location_pathname, "f") + val;
2909
- }
2910
- else if (val.startsWith('./')) {
2911
- val = val.replace(/\.\//, '/');
2912
- newPathName = __classPrivateFieldGet(this, _Location_pathname, "f") + val;
2913
- }
2914
- else if (val.startsWith('../')) {
2915
- newPathName = resolveRelativePath(val, preValue.pathname);
2916
- }
2917
- const { pathname, search, hash } = parseUrl(`//${DEFAULT_HOSTNAME}${newPathName}`);
2918
- __classPrivateFieldSet(this, _Location_pathname, pathname, "f");
2919
- __classPrivateFieldSet(this, _Location_search, search, "f");
2920
- __classPrivateFieldSet(this, _Location_hash, hash, "f");
2921
- if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
2922
- __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
2923
- }
2924
- get search() {
2925
- return __classPrivateFieldGet(this, _Location_search, "f");
2926
- }
2927
- set search(val) {
2928
- if (!val || !isString(val))
2929
- return;
2930
- val = val.trim();
2931
- val = val.startsWith('?') ? val : `?${val}`;
2932
- const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
2933
- const { search } = parseUrl(`//${DEFAULT_HOSTNAME}${val}`);
2934
- __classPrivateFieldSet(this, _Location_search, search, "f");
2935
- if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
2936
- __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
2937
- }
2938
- get hash() {
2939
- return __classPrivateFieldGet(this, _Location_hash, "f");
2940
- }
2941
- // 小程序的navigateTo存在截断hash字符串的问题
2942
- set hash(val) {
2943
- if (!val || !isString(val))
2944
- return;
2945
- val = val.trim();
2946
- val = val.startsWith('#') ? val : `#${val}`;
2947
- const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
2948
- const { hash } = parseUrl(`//${DEFAULT_HOSTNAME}${val}`);
2949
- __classPrivateFieldSet(this, _Location_hash, hash, "f");
2950
- if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
2951
- __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
2952
- }
2953
- get href() {
2954
- return `${__classPrivateFieldGet(this, _Location_protocol, "f")}//${this.host}${__classPrivateFieldGet(this, _Location_pathname, "f")}${__classPrivateFieldGet(this, _Location_search, "f")}${__classPrivateFieldGet(this, _Location_hash, "f")}`;
2955
- }
2956
- set href(val) {
2957
- const reg = /^(http:|https:)?\/\/.+/;
2958
- if (!val || !isString(val) || !reg.test((val = val.trim())))
2959
- return;
2960
- const { protocol, hostname, port, hash, search, pathname } = parseUrl(val);
2961
- const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
2962
- __classPrivateFieldSet(this, _Location_protocol, protocol, "f");
2963
- __classPrivateFieldSet(this, _Location_hostname, hostname, "f");
2964
- __classPrivateFieldSet(this, _Location_port, port, "f");
2965
- __classPrivateFieldSet(this, _Location_pathname, pathname, "f");
2966
- __classPrivateFieldSet(this, _Location_search, search, "f");
2967
- __classPrivateFieldSet(this, _Location_hash, hash, "f");
2968
- if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
2969
- __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
2970
- }
2971
- get origin() {
2972
- return `${__classPrivateFieldGet(this, _Location_protocol, "f")}//${this.host}`;
2973
- }
2974
- set origin(val) {
2975
- const reg = /^(http:|https:)?\/\/.+/;
2976
- if (!val || !isString(val) || !reg.test((val = val.trim())))
2977
- return;
2978
- const { protocol, hostname, port } = parseUrl(val);
2979
- const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
2980
- __classPrivateFieldSet(this, _Location_protocol, protocol, "f");
2981
- __classPrivateFieldSet(this, _Location_hostname, hostname, "f");
2982
- __classPrivateFieldSet(this, _Location_port, port, "f");
2983
- if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
2984
- __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
2985
- }
2986
- /* public method */
2987
- assign() {
2988
- warn(true, '小程序环境中调用location.assign()无效.');
2989
- }
2990
- reload() {
2991
- warn(true, '小程序环境中调用location.reload()无效.');
2992
- }
2993
- replace(val) {
2994
- this.trigger('__set_href_without_history__', val);
2995
- }
2996
- toString() {
2997
- return this.href;
2998
- }
2999
- // For debug
3000
- get cache() {
3001
- return cache$1;
3002
- }
3003
- }
3004
- _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() {
3005
- const Current = getCurrentInstance();
3006
- const router = Current.router;
3007
- if (router) {
3008
- const { path, params } = router;
3009
- const searchArr = Object.keys(params).map(key => {
3010
- return `${key}=${params[key]}`;
3011
- });
3012
- const searchStr = searchArr.length > 0 ? '?' + searchArr.join('&') : '';
3013
- const url = `https://${DEFAULT_HOSTNAME}${path.startsWith('/') ? path : '/' + path}${searchStr}`;
3014
- // 初始化页面链接时,默认pathname为 "/"
3015
- // const url = `https://${DEFAULT_HOSTNAME}${searchStr}`
3016
- const { protocol, hostname, port, pathname, search, hash } = parseUrl(url);
3017
- __classPrivateFieldSet(this, _Location_protocol, protocol, "f");
3018
- __classPrivateFieldSet(this, _Location_hostname, hostname, "f");
3019
- __classPrivateFieldSet(this, _Location_port, port, "f");
3020
- __classPrivateFieldSet(this, _Location_pathname, pathname, "f");
3021
- __classPrivateFieldSet(this, _Location_search, search, "f");
3022
- __classPrivateFieldSet(this, _Location_hash, hash, "f");
3023
- this.trigger('__reset_history__', this.href);
3024
- }
3025
- }, _Location_getPreValue = function _Location_getPreValue() {
3026
- return {
3027
- protocol: __classPrivateFieldGet(this, _Location_protocol, "f"),
3028
- hostname: __classPrivateFieldGet(this, _Location_hostname, "f"),
3029
- port: __classPrivateFieldGet(this, _Location_port, "f"),
3030
- pathname: __classPrivateFieldGet(this, _Location_pathname, "f"),
3031
- search: __classPrivateFieldGet(this, _Location_search, "f"),
3032
- hash: __classPrivateFieldGet(this, _Location_hash, "f")
3033
- };
3034
- }, _Location_rollBack = function _Location_rollBack(preValue) {
3035
- __classPrivateFieldSet(this, _Location_protocol, preValue.protocol, "f");
3036
- __classPrivateFieldSet(this, _Location_hostname, preValue.hostname, "f");
3037
- __classPrivateFieldSet(this, _Location_port, preValue.port, "f");
3038
- __classPrivateFieldSet(this, _Location_pathname, preValue.pathname, "f");
3039
- __classPrivateFieldSet(this, _Location_search, preValue.search, "f");
3040
- __classPrivateFieldSet(this, _Location_hash, preValue.hash, "f");
3041
- }, _Location_recordHistory = function _Location_recordHistory() {
3042
- this.trigger('__record_history__', this.href);
3043
- }, _Location_checkUrlChange = function _Location_checkUrlChange(preValue) {
3044
- if (__classPrivateFieldGet(this, _Location_noCheckUrl, "f")) {
3045
- return false;
3046
- }
3047
- // 跨域三要素不允许修改
3048
- if (__classPrivateFieldGet(this, _Location_protocol, "f") !== preValue.protocol || __classPrivateFieldGet(this, _Location_hostname, "f") !== preValue.hostname || this.port !== preValue.port) {
3049
- __classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue);
3050
- return false;
3051
- }
3052
- // pathname
3053
- if (__classPrivateFieldGet(this, _Location_pathname, "f") !== preValue.pathname) {
3054
- return true;
3055
- }
3056
- // search
3057
- if (__classPrivateFieldGet(this, _Location_search, "f") !== preValue.search) {
3058
- return true;
3059
- }
3060
- // hashchange
3061
- if (__classPrivateFieldGet(this, _Location_hash, "f") !== preValue.hash) {
3062
- __classPrivateFieldGet(this, _Location_window, "f").trigger('hashchange');
3063
- return true;
3064
- }
3065
- __classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue);
3066
- return false;
3067
- };
3068
- function resolveRelativePath(path, relative) {
3069
- const relativeArr = relative.split('/');
3070
- const parent = relativeArr.slice(0, relativeArr.length - 1);
3071
- let depth = 0;
3072
- const dests = path.split('../').map(v => {
3073
- v === '' && depth++;
3074
- return v;
3075
- });
3076
- if (depth > parent.length)
3077
- return relative;
3078
- return parent.slice(0, parent.length - depth).concat(dests.filter(v => v !== '')).join('/');
3079
- }
3080
- function generateFullUrl(val = '') {
3081
- const origin = `https://${DEFAULT_HOSTNAME}`;
3082
- if (val.startsWith('/')) {
3083
- return origin + val;
3084
- }
3085
- if (val.startsWith('?')) {
3086
- return origin + val;
3087
- }
3088
- if (val.startsWith('#')) {
3089
- return origin + val;
3090
- }
3091
- if (/(https?:)?\/\//.test(val)) {
3092
- return val;
3093
- }
3094
- return val;
3095
- }
3096
- function parseUrl(url = '') {
3097
- const result = {
3098
- href: '',
3099
- origin: '',
3100
- protocol: '',
3101
- hostname: '',
3102
- host: '',
3103
- port: '',
3104
- pathname: '',
3105
- search: '',
3106
- hash: ''
3107
- };
3108
- if (!url || !isString(url))
3109
- return result;
3110
- url = url.trim();
3111
- const PATTERN = /^(([^:/?#]+):)?\/\/(([^/?#]+):(.+)@)?([^/?#:]*)(:(\d+))?([^?#]*)(\?([^#]*))?(#(.*))?/;
3112
- const matches = url.match(PATTERN);
3113
- if (!matches)
3114
- return result;
3115
- // TODO: username & password ?
3116
- result.protocol = matches[1] || 'https:';
3117
- result.hostname = matches[6] || DEFAULT_HOSTNAME;
3118
- result.port = matches[8] || '';
3119
- result.pathname = matches[9] || '/';
3120
- result.search = matches[10] || '';
3121
- result.hash = matches[12] || '';
3122
- result.href = url;
3123
- result.origin = result.protocol + '//' + result.hostname;
3124
- result.host = result.hostname + (result.port ? `:${result.port}` : '');
3125
- return result;
3126
- }
3127
-
3128
- class AnchorElement extends TaroElement {
3129
- get href() {
3130
- var _a;
3131
- return (_a = this.props["href" /* AnchorElementAttrs.HREF */]) !== null && _a !== void 0 ? _a : '';
3132
- }
3133
- set href(val) {
3134
- this.setAttribute("href" /* AnchorElementAttrs.HREF */, val);
3135
- }
3136
- get protocol() {
3137
- var _a;
3138
- return (_a = this.props["protocol" /* AnchorElementAttrs.PROTOCOL */]) !== null && _a !== void 0 ? _a : '';
3139
- }
3140
- get host() {
3141
- var _a;
3142
- return (_a = this.props["host" /* AnchorElementAttrs.HOST */]) !== null && _a !== void 0 ? _a : '';
3143
- }
3144
- get search() {
3145
- var _a;
3146
- return (_a = this.props["search" /* AnchorElementAttrs.SEARCH */]) !== null && _a !== void 0 ? _a : '';
3147
- }
3148
- get hash() {
3149
- var _a;
3150
- return (_a = this.props["hash" /* AnchorElementAttrs.HASH */]) !== null && _a !== void 0 ? _a : '';
3151
- }
3152
- get hostname() {
3153
- var _a;
3154
- return (_a = this.props["hostname" /* AnchorElementAttrs.HOSTNAME */]) !== null && _a !== void 0 ? _a : '';
3155
- }
3156
- get port() {
3157
- var _a;
3158
- return (_a = this.props["port" /* AnchorElementAttrs.PORT */]) !== null && _a !== void 0 ? _a : '';
3159
- }
3160
- get pathname() {
3161
- var _a;
3162
- return (_a = this.props["pathname" /* AnchorElementAttrs.PATHNAME */]) !== null && _a !== void 0 ? _a : '';
3163
- }
3164
- setAttribute(qualifiedName, value) {
3165
- if (qualifiedName === "href" /* AnchorElementAttrs.HREF */) {
3166
- const willSetAttr = parseUrl(value);
3167
- for (const k in willSetAttr) {
3168
- super.setAttribute(k, willSetAttr[k]);
3169
- }
3170
- }
3171
- else {
3172
- super.setAttribute(qualifiedName, value);
3173
- }
3174
- }
3175
- }
3176
-
3177
- class TaroDocument extends TaroElement {
3178
- constructor() {
3179
- super();
3180
- this.createEvent = createEvent;
3181
- this.nodeType = 9 /* NodeType.DOCUMENT_NODE */;
3182
- this.nodeName = DOCUMENT_ELEMENT_NAME;
3183
- }
3184
- createElement(type) {
3185
- const nodeName = type.toLowerCase();
3186
- let element;
3187
- switch (true) {
3188
- case nodeName === ROOT_STR:
3189
- element = new TaroRootElement();
3190
- return element;
3191
- case controlledComponent.has(nodeName):
3192
- element = new FormElement();
3193
- break;
3194
- case nodeName === A:
3195
- element = new AnchorElement();
3196
- break;
3197
- default:
3198
- element = new TaroElement();
3199
- break;
3200
- }
3201
- element.nodeName = nodeName;
3202
- element.tagName = type.toUpperCase();
3203
- return element;
3204
- }
3205
- // an ugly fake createElementNS to deal with @vue/runtime-dom's
3206
- // support mounting app to svg container since vue@3.0.8
3207
- createElementNS(_svgNS, type) {
3208
- return this.createElement(type);
3209
- }
3210
- createTextNode(text) {
3211
- return new TaroText(text);
3212
- }
3213
- getElementById(id) {
3214
- const el = eventSource.get(id);
3215
- return isUndefined(el) ? null : el;
3216
- }
3217
- querySelector(query) {
3218
- // 为了 Vue3 的乞丐版实现
3219
- if (/^#/.test(query)) {
3220
- return this.getElementById(query.slice(1));
3221
- }
3222
- return null;
3223
- }
3224
- querySelectorAll() {
3225
- // fake hack
3226
- return [];
3227
- }
3228
- // @TODO: @PERF: 在 hydrate 移除掉空的 node
3229
- createComment() {
3230
- const textnode = new TaroText('');
3231
- textnode.nodeName = COMMENT;
3232
- return textnode;
3233
- }
3234
- get defaultView() {
3235
- return env.window;
3236
- }
3237
- }
3238
-
3239
- let document$1;
3240
- if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
3241
- /* eslint-disable no-inner-declarations */
3242
- function createDocument() {
3243
- /**
3244
- * <document>
3245
- * <html>
3246
- * <head></head>
3247
- * <body>
3248
- * <container>
3249
- * <app id="app" />
3250
- * </container>
3251
- * </body>
3252
- * </html>
3253
- * </document>
3254
- */
3255
- const doc = new TaroDocument();
3256
- const documentCreateElement = doc.createElement.bind(doc);
3257
- const html = documentCreateElement(HTML);
3258
- const head = documentCreateElement(HEAD);
3259
- const body = documentCreateElement(BODY);
3260
- const app = documentCreateElement(APP);
3261
- app.id = APP;
3262
- const container = documentCreateElement(CONTAINER); // 多包一层主要为了兼容 vue
3263
- doc.appendChild(html);
3264
- html.appendChild(head);
3265
- html.appendChild(body);
3266
- body.appendChild(container);
3267
- container.appendChild(app);
3268
- doc.documentElement = html;
3269
- doc.head = head;
3270
- doc.body = body;
3271
- return doc;
3272
- }
3273
- document$1 = env.document = createDocument();
3274
- }
3275
- else {
3276
- document$1 = env.document;
3277
- }
3278
-
3279
- function getComputedStyle(element) {
3280
- return element.style;
3281
- }
3282
-
3283
- const machine = 'Macintosh';
3284
- const arch = 'Intel Mac OS X 10_14_5';
3285
- const engine = 'AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36';
3286
- const msg = '(' + machine + '; ' + arch + ') ' + engine;
3287
- const nav = process.env.TARO_ENV === 'h5' ? env.window.navigator : {
3288
- appCodeName: 'Mozilla',
3289
- appName: 'Netscape',
3290
- appVersion: '5.0 ' + msg,
3291
- cookieEnabled: true,
3292
- mimeTypes: [],
3293
- onLine: true,
3294
- platform: 'MacIntel',
3295
- plugins: [],
3296
- product: 'Taro',
3297
- productSub: '20030107',
3298
- userAgent: 'Mozilla/5.0 ' + msg,
3299
- vendor: 'Joyent',
3300
- vendorSub: ''
3301
- };
3302
-
3303
- // https://github.com/myrne/performance-now
3304
- let now;
3305
- (function () {
3306
- let loadTime;
3307
- if ((typeof performance !== 'undefined' && performance !== null) && performance.now) {
3308
- now = () => performance.now();
3309
- }
3310
- else if (Date.now) {
3311
- loadTime = Date.now();
3312
- now = () => Date.now() - loadTime;
3313
- }
3314
- else {
3315
- loadTime = new Date().getTime();
3316
- now = () => new Date().getTime() - loadTime;
3317
- }
3318
- })();
3319
- let lastTime = 0;
3320
- // https://gist.github.com/paulirish/1579671
3321
- // https://gist.github.com/jalbam/5fe05443270fa6d8136238ec72accbc0
3322
- const _raf = typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame !== null ? requestAnimationFrame : function (callback) {
3323
- const _now = now();
3324
- const nextTime = Math.max(lastTime + 16, _now); // First time will execute it immediately but barely noticeable and performance is gained.
3325
- return setTimeout(function () { callback(lastTime = nextTime); }, nextTime - _now);
3326
- };
3327
- const _caf = typeof cancelAnimationFrame !== 'undefined' && cancelAnimationFrame !== null
3328
- ? cancelAnimationFrame
3329
- : function (seed) {
3330
- // fix https://github.com/NervJS/taro/issues/7749
3331
- clearTimeout(seed);
3332
- };
3333
-
3334
2760
  var _URLSearchParams_dict;
3335
2761
  const findReg = /[!'()~]|%20|%00/g;
3336
2762
  const plusReg = /\+/g;
@@ -3510,8 +2936,14 @@ class URL {
3510
2936
  }
3511
2937
  set pathname(val) {
3512
2938
  if (isString(val)) {
3513
- if (val)
3514
- __classPrivateFieldSet(this, _URL_pathname, val.trim(), "f");
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");
3515
2947
  else
3516
2948
  __classPrivateFieldSet(this, _URL_pathname, '/', "f");
3517
2949
  }
@@ -3593,6 +3025,37 @@ class URL {
3593
3025
  }
3594
3026
  }
3595
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
+ }
3596
3059
  function parseUrlBase(url, base) {
3597
3060
  const VALID_URL = /^(https?:)\/\//i;
3598
3061
  let fullUrl = '';
@@ -3620,14 +3083,196 @@ function parseUrlBase(url, base) {
3620
3083
  fullUrl = parsedBase.href;
3621
3084
  }
3622
3085
  }
3623
- else {
3624
- throw new TypeError(`Failed to construct 'URL': Invalid URL`);
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
+
3247
+ const eventCenter = hooks.call('getEventCenter', Events);
3248
+
3249
+ /**
3250
+ * 一个小型缓存池,用于在切换页面时,存储一些上下文信息
3251
+ */
3252
+ class RuntimeCache {
3253
+ constructor(name) {
3254
+ this.cache = new Map();
3255
+ this.name = name;
3256
+ }
3257
+ has(identifier) {
3258
+ return this.cache.has(identifier);
3259
+ }
3260
+ set(identifier, ctx) {
3261
+ if (identifier && ctx) {
3262
+ this.cache.set(identifier, ctx);
3263
+ }
3264
+ }
3265
+ get(identifier) {
3266
+ if (this.has(identifier))
3267
+ return this.cache.get(identifier);
3268
+ }
3269
+ delete(identifier) {
3270
+ this.cache.delete(identifier);
3625
3271
  }
3626
- return parseUrl(fullUrl);
3627
3272
  }
3628
3273
 
3629
3274
  var _History_instances, _History_location, _History_stack, _History_cur, _History_window, _History_reset;
3630
- const cache = new RuntimeCache('history');
3275
+ const cache$1 = new RuntimeCache('history');
3631
3276
  class History extends Events {
3632
3277
  constructor(location, options) {
3633
3278
  super();
@@ -3657,22 +3302,22 @@ class History extends Events {
3657
3302
  __classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this);
3658
3303
  }, null);
3659
3304
  this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
3660
- cache.set(pageId, {
3305
+ cache$1.set(pageId, {
3661
3306
  location: __classPrivateFieldGet(this, _History_location, "f"),
3662
- stack: __classPrivateFieldGet(this, _History_stack, "f"),
3307
+ stack: __classPrivateFieldGet(this, _History_stack, "f").slice(),
3663
3308
  cur: __classPrivateFieldGet(this, _History_cur, "f")
3664
3309
  });
3665
3310
  }, null);
3666
3311
  this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
3667
- if (cache.has(pageId)) {
3668
- const ctx = cache.get(pageId);
3312
+ if (cache$1.has(pageId)) {
3313
+ const ctx = cache$1.get(pageId);
3669
3314
  __classPrivateFieldSet(this, _History_location, ctx.location, "f");
3670
3315
  __classPrivateFieldSet(this, _History_stack, ctx.stack, "f");
3671
3316
  __classPrivateFieldSet(this, _History_cur, ctx.cur, "f");
3672
3317
  }
3673
3318
  }, null);
3674
3319
  this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
3675
- cache.delete(pageId);
3320
+ cache$1.delete(pageId);
3676
3321
  }, null);
3677
3322
  __classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this);
3678
3323
  }
@@ -3723,7 +3368,7 @@ class History extends Events {
3723
3368
  }
3724
3369
  // For debug
3725
3370
  get cache() {
3726
- return cache;
3371
+ return cache$1;
3727
3372
  }
3728
3373
  }
3729
3374
  _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 = '') {
@@ -3737,6 +3382,292 @@ _History_location = new WeakMap(), _History_stack = new WeakMap(), _History_cur
3737
3382
  __classPrivateFieldSet(this, _History_cur, 0, "f");
3738
3383
  };
3739
3384
 
3385
+ const Current = {
3386
+ app: null,
3387
+ router: null,
3388
+ page: null
3389
+ };
3390
+ const getCurrentInstance = () => Current;
3391
+
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';
3394
+ const cache = new RuntimeCache('location');
3395
+ class Location extends Events {
3396
+ constructor(options) {
3397
+ super();
3398
+ _Location_instances.add(this);
3399
+ /* private property */
3400
+ _Location_url.set(this, new URL(INIT_URL));
3401
+ _Location_noCheckUrl.set(this, false);
3402
+ _Location_window.set(this, void 0);
3403
+ __classPrivateFieldSet(this, _Location_window, options.window, "f");
3404
+ __classPrivateFieldGet(this, _Location_instances, "m", _Location_reset).call(this);
3405
+ this.on('__set_href_without_history__', (href) => {
3406
+ __classPrivateFieldSet(this, _Location_noCheckUrl, true, "f");
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) {
3410
+ __classPrivateFieldGet(this, _Location_window, "f").trigger('hashchange');
3411
+ }
3412
+ __classPrivateFieldSet(this, _Location_noCheckUrl, false, "f");
3413
+ }, null);
3414
+ // 切换上下文行为
3415
+ this.on(CONTEXT_ACTIONS.INIT, () => {
3416
+ __classPrivateFieldGet(this, _Location_instances, "m", _Location_reset).call(this);
3417
+ }, null);
3418
+ this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
3419
+ cache.set(pageId, {
3420
+ lastHref: this.href,
3421
+ });
3422
+ }, null);
3423
+ this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
3424
+ // 数据恢复时,不需要执行跳转
3425
+ if (cache.has(pageId)) {
3426
+ const ctx = cache.get(pageId);
3427
+ __classPrivateFieldSet(this, _Location_noCheckUrl, true, "f");
3428
+ __classPrivateFieldGet(this, _Location_url, "f").href = ctx.lastHref;
3429
+ __classPrivateFieldSet(this, _Location_noCheckUrl, false, "f");
3430
+ }
3431
+ }, null);
3432
+ this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
3433
+ cache.delete(pageId);
3434
+ }, null);
3435
+ }
3436
+ /* public property */
3437
+ get protocol() {
3438
+ return __classPrivateFieldGet(this, _Location_url, "f").protocol;
3439
+ }
3440
+ set protocol(val) {
3441
+ const REG = /^(http|https):$/i;
3442
+ if (!val || !isString(val) || !REG.test(val.trim()))
3443
+ return;
3444
+ val = val.trim();
3445
+ const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
3446
+ __classPrivateFieldGet(this, _Location_url, "f").protocol = val;
3447
+ if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
3448
+ __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
3449
+ }
3450
+ get host() {
3451
+ return __classPrivateFieldGet(this, _Location_url, "f").host;
3452
+ }
3453
+ set host(val) {
3454
+ if (!val || !isString(val))
3455
+ return;
3456
+ val = val.trim();
3457
+ const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
3458
+ __classPrivateFieldGet(this, _Location_url, "f").host = val;
3459
+ if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
3460
+ __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
3461
+ }
3462
+ get hostname() {
3463
+ return __classPrivateFieldGet(this, _Location_url, "f").hostname;
3464
+ }
3465
+ set hostname(val) {
3466
+ if (!val || !isString(val))
3467
+ return;
3468
+ val = val.trim();
3469
+ const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
3470
+ __classPrivateFieldGet(this, _Location_url, "f").hostname = val;
3471
+ if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
3472
+ __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
3473
+ }
3474
+ get port() {
3475
+ return __classPrivateFieldGet(this, _Location_url, "f").port;
3476
+ }
3477
+ set port(val) {
3478
+ const xVal = Number((val = val.trim()));
3479
+ if (!isNumber(xVal) || xVal <= 0)
3480
+ return;
3481
+ const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
3482
+ __classPrivateFieldGet(this, _Location_url, "f").port = val;
3483
+ if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
3484
+ __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
3485
+ }
3486
+ get pathname() {
3487
+ return __classPrivateFieldGet(this, _Location_url, "f").pathname;
3488
+ }
3489
+ set pathname(val) {
3490
+ if (!val || !isString(val))
3491
+ return;
3492
+ val = val.trim();
3493
+ const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
3494
+ __classPrivateFieldGet(this, _Location_url, "f").pathname = val;
3495
+ if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
3496
+ __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
3497
+ }
3498
+ get search() {
3499
+ return __classPrivateFieldGet(this, _Location_url, "f").search;
3500
+ }
3501
+ set search(val) {
3502
+ if (!val || !isString(val))
3503
+ return;
3504
+ val = val.trim();
3505
+ val = val.startsWith('?') ? val : `?${val}`;
3506
+ const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
3507
+ __classPrivateFieldGet(this, _Location_url, "f").search = val;
3508
+ if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
3509
+ __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
3510
+ }
3511
+ get hash() {
3512
+ return __classPrivateFieldGet(this, _Location_url, "f").hash;
3513
+ }
3514
+ // 小程序的navigateTo存在截断hash字符串的问题
3515
+ set hash(val) {
3516
+ if (!val || !isString(val))
3517
+ return;
3518
+ val = val.trim();
3519
+ val = val.startsWith('#') ? val : `#${val}`;
3520
+ const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
3521
+ __classPrivateFieldGet(this, _Location_url, "f").hash = val;
3522
+ if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
3523
+ __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
3524
+ }
3525
+ get href() {
3526
+ return __classPrivateFieldGet(this, _Location_url, "f").href;
3527
+ }
3528
+ set href(val) {
3529
+ const REG = /^(http:|https:)?\/\/.+/;
3530
+ if (!val || !isString(val) || !REG.test((val = val.trim())))
3531
+ return;
3532
+ const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
3533
+ __classPrivateFieldGet(this, _Location_url, "f").href = val;
3534
+ if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
3535
+ __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
3536
+ }
3537
+ get origin() {
3538
+ return __classPrivateFieldGet(this, _Location_url, "f").origin;
3539
+ }
3540
+ set origin(val) {
3541
+ const REG = /^(http:|https:)?\/\/.+/;
3542
+ if (!val || !isString(val) || !REG.test((val = val.trim())))
3543
+ return;
3544
+ const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
3545
+ __classPrivateFieldGet(this, _Location_url, "f").origin = val;
3546
+ if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
3547
+ __classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
3548
+ }
3549
+ /* public method */
3550
+ assign() {
3551
+ warn(true, '小程序环境中调用location.assign()无效.');
3552
+ }
3553
+ reload() {
3554
+ warn(true, '小程序环境中调用location.reload()无效.');
3555
+ }
3556
+ replace(url) {
3557
+ this.trigger('__set_href_without_history__', url);
3558
+ }
3559
+ toString() {
3560
+ return this.href;
3561
+ }
3562
+ // For debug
3563
+ get cache() {
3564
+ return cache;
3565
+ }
3566
+ }
3567
+ _Location_url = new WeakMap(), _Location_noCheckUrl = new WeakMap(), _Location_window = new WeakMap(), _Location_instances = new WeakSet(), _Location_reset = function _Location_reset() {
3568
+ const Current = getCurrentInstance();
3569
+ const router = Current.router;
3570
+ if (router) {
3571
+ const { path, params } = router;
3572
+ const searchArr = Object.keys(params).map((key) => {
3573
+ return `${key}=${params[key]}`;
3574
+ });
3575
+ const searchStr = searchArr.length > 0 ? '?' + searchArr.join('&') : '';
3576
+ const url = `${INIT_URL}${path.startsWith('/') ? path : '/' + path}${searchStr}`;
3577
+ __classPrivateFieldSet(this, _Location_url, new URL(url), "f");
3578
+ this.trigger('__reset_history__', this.href);
3579
+ }
3580
+ }, _Location_getPreValue = function _Location_getPreValue() {
3581
+ return __classPrivateFieldGet(this, _Location_url, "f")._toRaw();
3582
+ }, _Location_rollBack = function _Location_rollBack(href) {
3583
+ __classPrivateFieldGet(this, _Location_url, "f").href = href;
3584
+ }, _Location_recordHistory = function _Location_recordHistory() {
3585
+ this.trigger('__record_history__', this.href);
3586
+ }, _Location_checkUrlChange = function _Location_checkUrlChange(preValue) {
3587
+ if (__classPrivateFieldGet(this, _Location_noCheckUrl, "f")) {
3588
+ return false;
3589
+ }
3590
+ const { protocol, hostname, port, pathname, search, hash } = __classPrivateFieldGet(this, _Location_url, "f")._toRaw();
3591
+ // 跨域三要素不允许修改
3592
+ if (protocol !== preValue.protocol || hostname !== preValue.hostname || port !== preValue.port) {
3593
+ __classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue.href);
3594
+ return false;
3595
+ }
3596
+ // pathname
3597
+ if (pathname !== preValue.pathname) {
3598
+ return true;
3599
+ }
3600
+ // search
3601
+ if (search !== preValue.search) {
3602
+ return true;
3603
+ }
3604
+ // hashchange
3605
+ if (hash !== preValue.hash) {
3606
+ __classPrivateFieldGet(this, _Location_window, "f").trigger('hashchange');
3607
+ return true;
3608
+ }
3609
+ __classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue.href);
3610
+ return false;
3611
+ };
3612
+ function generateFullUrl(val = '') {
3613
+ const origin = INIT_URL;
3614
+ if (/^[/?#]/.test(val)) {
3615
+ return origin + val;
3616
+ }
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();
3646
+ }
3647
+ else if (Date.now) {
3648
+ loadTime = Date.now();
3649
+ now = () => Date.now() - loadTime;
3650
+ }
3651
+ else {
3652
+ loadTime = new Date().getTime();
3653
+ now = () => new Date().getTime() - loadTime;
3654
+ }
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);
3669
+ };
3670
+
3740
3671
  let window$1;
3741
3672
  if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
3742
3673
  class Window extends Events {
@@ -4153,5 +4084,5 @@ const nextTick = (cb, ctx) => {
4153
4084
  }
4154
4085
  };
4155
4086
 
4156
- export { Current, FormElement, 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 };
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 };
4157
4088
  //# sourceMappingURL=runtime.esm.js.map