@tarojs/components-advanced 3.6.2 → 3.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/_virtual/_commonjsHelpers.js +35 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/arrayLikeToArray.js +7 -0
- package/dist/_virtual/arrayLikeToArray.js.map +1 -0
- package/dist/_virtual/arrayLikeToArray2.js +4 -0
- package/dist/_virtual/arrayLikeToArray2.js.map +1 -0
- package/dist/_virtual/arrayWithoutHoles.js +7 -0
- package/dist/_virtual/arrayWithoutHoles.js.map +1 -0
- package/dist/_virtual/arrayWithoutHoles2.js +4 -0
- package/dist/_virtual/arrayWithoutHoles2.js.map +1 -0
- package/dist/_virtual/assertThisInitialized.js +7 -0
- package/dist/_virtual/assertThisInitialized.js.map +1 -0
- package/dist/_virtual/assertThisInitialized2.js +4 -0
- package/dist/_virtual/assertThisInitialized2.js.map +1 -0
- package/dist/_virtual/classCallCheck.js +4 -0
- package/dist/_virtual/classCallCheck.js.map +1 -0
- package/dist/_virtual/createClass.js +4 -0
- package/dist/_virtual/createClass.js.map +1 -0
- package/dist/_virtual/createSuper.js +4 -0
- package/dist/_virtual/createSuper.js.map +1 -0
- package/dist/_virtual/defineProperty.js +4 -0
- package/dist/_virtual/defineProperty.js.map +1 -0
- package/dist/_virtual/defineProperty2.js +7 -0
- package/dist/_virtual/defineProperty2.js.map +1 -0
- package/dist/_virtual/getPrototypeOf.js +7 -0
- package/dist/_virtual/getPrototypeOf.js.map +1 -0
- package/dist/_virtual/getPrototypeOf2.js +4 -0
- package/dist/_virtual/getPrototypeOf2.js.map +1 -0
- package/dist/_virtual/index.esm.js +7 -0
- package/dist/_virtual/index.esm.js.map +1 -0
- package/dist/_virtual/index.js +4 -0
- package/dist/_virtual/index.js.map +1 -0
- package/dist/_virtual/inherits.js +4 -0
- package/dist/_virtual/inherits.js.map +1 -0
- package/dist/_virtual/isNativeReflectConstruct.js +7 -0
- package/dist/_virtual/isNativeReflectConstruct.js.map +1 -0
- package/dist/_virtual/isNativeReflectConstruct2.js +4 -0
- package/dist/_virtual/isNativeReflectConstruct2.js.map +1 -0
- package/dist/_virtual/iterableToArray.js +7 -0
- package/dist/_virtual/iterableToArray.js.map +1 -0
- package/dist/_virtual/iterableToArray2.js +4 -0
- package/dist/_virtual/iterableToArray2.js.map +1 -0
- package/dist/_virtual/nonIterableSpread.js +7 -0
- package/dist/_virtual/nonIterableSpread.js.map +1 -0
- package/dist/_virtual/nonIterableSpread2.js +4 -0
- package/dist/_virtual/nonIterableSpread2.js.map +1 -0
- package/dist/_virtual/objectSpread2.js +4 -0
- package/dist/_virtual/objectSpread2.js.map +1 -0
- package/dist/_virtual/possibleConstructorReturn.js +7 -0
- package/dist/_virtual/possibleConstructorReturn.js.map +1 -0
- package/dist/_virtual/possibleConstructorReturn2.js +4 -0
- package/dist/_virtual/possibleConstructorReturn2.js.map +1 -0
- package/dist/_virtual/runtime.esm.js +7 -0
- package/dist/_virtual/runtime.esm.js.map +1 -0
- package/dist/_virtual/setPrototypeOf.js +7 -0
- package/dist/_virtual/setPrototypeOf.js.map +1 -0
- package/dist/_virtual/setPrototypeOf2.js +4 -0
- package/dist/_virtual/setPrototypeOf2.js.map +1 -0
- package/dist/_virtual/toConsumableArray.js +4 -0
- package/dist/_virtual/toConsumableArray.js.map +1 -0
- package/dist/_virtual/typeof.js +4 -0
- package/dist/_virtual/typeof.js.map +1 -0
- package/dist/_virtual/typeof2.js +7 -0
- package/dist/_virtual/typeof2.js.map +1 -0
- package/dist/_virtual/unsupportedIterableToArray.js +7 -0
- package/dist/_virtual/unsupportedIterableToArray.js.map +1 -0
- package/dist/_virtual/unsupportedIterableToArray2.js +4 -0
- package/dist/_virtual/unsupportedIterableToArray2.js.map +1 -0
- package/dist/components/virtual-list/index.d.ts +29 -0
- package/dist/components/virtual-list/index.js.map +1 -1
- package/dist/components/virtual-list/react/index.js +1 -1
- package/dist/components/virtual-list/react/list.js +3 -5
- package/dist/components/virtual-list/react/list.js.map +1 -1
- package/dist/components/virtual-list/utils.js +4 -3
- package/dist/components/virtual-list/utils.js.map +1 -1
- package/dist/components/virtual-list/vue/list.js +8 -6
- package/dist/components/virtual-list/vue/list.js.map +1 -1
- package/dist/components/virtual-list/vue/render.js +3 -2
- package/dist/components/virtual-list/vue/render.js.map +1 -1
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/arrayLikeToArray.js +21 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/arrayLikeToArray.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/arrayWithoutHoles.js +20 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/arrayWithoutHoles.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/assertThisInitialized.js +19 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/assertThisInitialized.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/classCallCheck.js +17 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/classCallCheck.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/createClass.js +30 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/createClass.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/createSuper.js +43 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/createSuper.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/defineProperty.js +26 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/defineProperty.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/getPrototypeOf.js +18 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/getPrototypeOf.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/inherits.js +34 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/inherits.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/isNativeReflectConstruct.js +24 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/isNativeReflectConstruct.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/iterableToArray.js +15 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/iterableToArray.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/nonIterableSpread.js +15 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/nonIterableSpread.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/objectSpread2.js +42 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/objectSpread2.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js +31 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/setPrototypeOf.js +19 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/setPrototypeOf.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/toConsumableArray.js +35 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/toConsumableArray.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/typeof.js +21 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/typeof.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js +25 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@babel_runtime@7.18.3/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@vue_reactivity@3.2.37/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js +1252 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@vue_reactivity@3.2.37/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@vue_runtime-core@3.2.37/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js +7856 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@vue_runtime-core@3.2.37/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@vue_runtime-dom@3.2.37/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js +1702 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@vue_runtime-dom@3.2.37/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@vue_shared@3.2.37/node_modules/@vue/shared/dist/shared.esm-bundler.js +597 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_@vue_shared@3.2.37/node_modules/@vue/shared/dist/shared.esm-bundler.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_tslib@1.14.1/node_modules/tslib/tslib.es6.js +221 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_tslib@1.14.1/node_modules/tslib/tslib.es6.js.map +1 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_vue@3.2.37/node_modules/vue/dist/vue.runtime.esm-bundler.js +24 -0
- package/dist/node_modules/.pnpm/registry.npmjs.org_vue@3.2.37/node_modules/vue/dist/vue.runtime.esm-bundler.js.map +1 -0
- package/dist/packages/taro/index.js +23 -0
- package/dist/packages/taro/index.js.map +1 -0
- package/dist/packages/taro-api/dist/index.esm.js +861 -0
- package/dist/packages/taro-api/dist/index.esm.js.map +1 -0
- package/dist/packages/taro-runtime/dist/runtime.esm.js +4107 -0
- package/dist/packages/taro-runtime/dist/runtime.esm.js.map +1 -0
- package/dist/utils/timer.js +4 -4
- package/dist/utils/timer.js.map +1 -1
- package/package.json +6 -5
|
@@ -0,0 +1,4107 @@
|
|
|
1
|
+
import { noop, isFunction, getComponentsAlias as getComponentsAlias$1, internalComponents, isWebPlatform, EMPTY_OBJ, hooks, toCamelCase, isObject, warn, isArray, ensure, isString, isNull, isUndefined, toDashed, controlledComponent, Events, isNumber } from '@tarojs/shared';
|
|
2
|
+
export { Events, hooks } from '@tarojs/shared';
|
|
3
|
+
|
|
4
|
+
const PROPERTY_THRESHOLD = 2046;
|
|
5
|
+
const SET_DATA = '小程序 setData';
|
|
6
|
+
const PAGE_INIT = '页面初始化';
|
|
7
|
+
const ROOT_STR = 'root';
|
|
8
|
+
const HTML = 'html';
|
|
9
|
+
const HEAD = 'head';
|
|
10
|
+
const BODY = 'body';
|
|
11
|
+
const APP = 'app';
|
|
12
|
+
const CONTAINER = 'container';
|
|
13
|
+
const DOCUMENT_ELEMENT_NAME = '#document';
|
|
14
|
+
const DOCUMENT_FRAGMENT = 'document-fragment';
|
|
15
|
+
const ID = 'id';
|
|
16
|
+
const UID = 'uid';
|
|
17
|
+
const CLASS = 'class';
|
|
18
|
+
const STYLE = 'style';
|
|
19
|
+
const FOCUS = 'focus';
|
|
20
|
+
const VIEW = 'view';
|
|
21
|
+
const STATIC_VIEW = 'static-view';
|
|
22
|
+
const PURE_VIEW = 'pure-view';
|
|
23
|
+
const PROPS = 'props';
|
|
24
|
+
const DATASET = 'dataset';
|
|
25
|
+
const OBJECT = 'object';
|
|
26
|
+
const VALUE = 'value';
|
|
27
|
+
const INPUT = 'input';
|
|
28
|
+
const CHANGE = 'change';
|
|
29
|
+
const CUSTOM_WRAPPER = 'custom-wrapper';
|
|
30
|
+
const TARGET = 'target';
|
|
31
|
+
const CURRENT_TARGET = 'currentTarget';
|
|
32
|
+
const TYPE = 'type';
|
|
33
|
+
const CONFIRM = 'confirm';
|
|
34
|
+
const TIME_STAMP = 'timeStamp';
|
|
35
|
+
const KEY_CODE = 'keyCode';
|
|
36
|
+
const TOUCHMOVE = 'touchmove';
|
|
37
|
+
const CATCHMOVE = 'catchMove';
|
|
38
|
+
const CATCH_VIEW = 'catch-view';
|
|
39
|
+
const COMMENT = 'comment';
|
|
40
|
+
const ON_LOAD = 'onLoad';
|
|
41
|
+
const ON_READY = 'onReady';
|
|
42
|
+
const ON_SHOW = 'onShow';
|
|
43
|
+
const ON_HIDE = 'onHide';
|
|
44
|
+
const OPTIONS = 'options';
|
|
45
|
+
const EXTERNAL_CLASSES = 'externalClasses';
|
|
46
|
+
const EVENT_CALLBACK_RESULT = 'e_result';
|
|
47
|
+
const BEHAVIORS = 'behaviors';
|
|
48
|
+
const A = 'a';
|
|
49
|
+
/**
|
|
50
|
+
* 页面上下文切换时的行为
|
|
51
|
+
*/
|
|
52
|
+
var CONTEXT_ACTIONS;
|
|
53
|
+
(function (CONTEXT_ACTIONS) {
|
|
54
|
+
CONTEXT_ACTIONS["INIT"] = "0";
|
|
55
|
+
CONTEXT_ACTIONS["RESTORE"] = "1";
|
|
56
|
+
CONTEXT_ACTIONS["RECOVER"] = "2";
|
|
57
|
+
CONTEXT_ACTIONS["DESTORY"] = "3";
|
|
58
|
+
})(CONTEXT_ACTIONS || (CONTEXT_ACTIONS = {}));
|
|
59
|
+
|
|
60
|
+
const observers = [];
|
|
61
|
+
/**
|
|
62
|
+
* The MutationObserver provides the ability
|
|
63
|
+
* to watch for changes being made to the DOM tree.
|
|
64
|
+
* It will invoke a specified callback function
|
|
65
|
+
* when DOM changes occur.
|
|
66
|
+
* @see https://dom.spec.whatwg.org/#mutationobserver
|
|
67
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
|
|
68
|
+
*/
|
|
69
|
+
class MutationObserverImpl {
|
|
70
|
+
constructor(callback) {
|
|
71
|
+
this.records = [];
|
|
72
|
+
this.callback = callback;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Configures the MutationObserver
|
|
76
|
+
* to begin receiving notifications
|
|
77
|
+
* through its callback function
|
|
78
|
+
* when DOM changes matching the given options occur.
|
|
79
|
+
*
|
|
80
|
+
* Options matching is to be implemented.
|
|
81
|
+
*/
|
|
82
|
+
observe(target, options) {
|
|
83
|
+
this.disconnect();
|
|
84
|
+
this.target = target;
|
|
85
|
+
this.options = options || {};
|
|
86
|
+
observers.push(this);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Stop the MutationObserver instance
|
|
90
|
+
* from receiving further notifications
|
|
91
|
+
* until and unless observe() is called again.
|
|
92
|
+
*/
|
|
93
|
+
disconnect() {
|
|
94
|
+
this.target = null;
|
|
95
|
+
const index = observers.indexOf(this);
|
|
96
|
+
if (index >= 0) {
|
|
97
|
+
observers.splice(index, 1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Removes all pending notifications
|
|
102
|
+
* from the MutationObserver's notification queue
|
|
103
|
+
* and returns them in a new Array of MutationRecord objects.
|
|
104
|
+
*/
|
|
105
|
+
takeRecords() {
|
|
106
|
+
return this.records.splice(0, this.records.length);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** Match two TaroNodes by sid. */
|
|
110
|
+
const sidMatches = (observerTarget, target) => {
|
|
111
|
+
return !!observerTarget && observerTarget.sid === (target === null || target === void 0 ? void 0 : target.sid);
|
|
112
|
+
};
|
|
113
|
+
const isConcerned = (record, options) => {
|
|
114
|
+
const { characterData, characterDataOldValue, attributes, attributeOldValue, childList } = options;
|
|
115
|
+
switch (record.type) {
|
|
116
|
+
case "characterData" /* MutationRecordType.CHARACTER_DATA */:
|
|
117
|
+
if (characterData) {
|
|
118
|
+
if (!characterDataOldValue)
|
|
119
|
+
record.oldValue = null;
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
case "attributes" /* MutationRecordType.ATTRIBUTES */:
|
|
124
|
+
if (attributes) {
|
|
125
|
+
if (!attributeOldValue)
|
|
126
|
+
record.oldValue = null;
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
case "childList" /* MutationRecordType.CHILD_LIST */:
|
|
131
|
+
if (childList) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
let pendingMuatations = false;
|
|
138
|
+
function logMutation(observer, record) {
|
|
139
|
+
observer.records.push(record);
|
|
140
|
+
if (!pendingMuatations) {
|
|
141
|
+
pendingMuatations = true;
|
|
142
|
+
Promise
|
|
143
|
+
.resolve()
|
|
144
|
+
.then(() => {
|
|
145
|
+
pendingMuatations = false;
|
|
146
|
+
observers.forEach(observer => {
|
|
147
|
+
return observer.callback(observer.takeRecords());
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function recordMutation(record) {
|
|
153
|
+
observers.forEach(observer => {
|
|
154
|
+
const { options } = observer;
|
|
155
|
+
for (let t = record.target; t; t = t.parentNode) {
|
|
156
|
+
if (sidMatches(observer.target, t) && isConcerned(record, options)) {
|
|
157
|
+
logMutation(observer, record);
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
if (!options.subtree)
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
class MutationObserver {
|
|
167
|
+
constructor(callback) {
|
|
168
|
+
if (ENABLE_MUTATION_OBSERVER) {
|
|
169
|
+
this.core = new MutationObserverImpl(callback);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
173
|
+
console.warn('[Taro Warning] 若要使用 MutationObserver,请在 Taro 编译配置中设置 \'mini.enableMutationObserver: true\'');
|
|
174
|
+
}
|
|
175
|
+
this.core = {
|
|
176
|
+
observe: noop,
|
|
177
|
+
disconnect: noop,
|
|
178
|
+
takeRecords: noop
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
observe(...args) {
|
|
183
|
+
this.core.observe(...args);
|
|
184
|
+
}
|
|
185
|
+
disconnect() {
|
|
186
|
+
this.core.disconnect();
|
|
187
|
+
}
|
|
188
|
+
takeRecords() {
|
|
189
|
+
return this.core.takeRecords();
|
|
190
|
+
}
|
|
191
|
+
static record(record) {
|
|
192
|
+
recordMutation(record);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const incrementId = () => {
|
|
197
|
+
const chatCodes = [];
|
|
198
|
+
// A-Z
|
|
199
|
+
for (let i = 65; i <= 90; i++) {
|
|
200
|
+
chatCodes.push(i);
|
|
201
|
+
}
|
|
202
|
+
// a-z
|
|
203
|
+
for (let i = 97; i <= 122; i++) {
|
|
204
|
+
chatCodes.push(i);
|
|
205
|
+
}
|
|
206
|
+
const chatCodesLen = chatCodes.length - 1;
|
|
207
|
+
const list = [0, 0];
|
|
208
|
+
return () => {
|
|
209
|
+
const target = list.map(item => chatCodes[item]);
|
|
210
|
+
const res = String.fromCharCode(...target);
|
|
211
|
+
let tailIdx = list.length - 1;
|
|
212
|
+
list[tailIdx]++;
|
|
213
|
+
while (list[tailIdx] > chatCodesLen) {
|
|
214
|
+
list[tailIdx] = 0;
|
|
215
|
+
tailIdx = tailIdx - 1;
|
|
216
|
+
if (tailIdx < 0) {
|
|
217
|
+
list.push(0);
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
list[tailIdx]++;
|
|
221
|
+
}
|
|
222
|
+
return res;
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
function isElement(node) {
|
|
226
|
+
return node.nodeType === 1 /* NodeType.ELEMENT_NODE */;
|
|
227
|
+
}
|
|
228
|
+
function isText(node) {
|
|
229
|
+
return node.nodeType === 3 /* NodeType.TEXT_NODE */;
|
|
230
|
+
}
|
|
231
|
+
function isComment(node) {
|
|
232
|
+
return node.nodeName === COMMENT;
|
|
233
|
+
}
|
|
234
|
+
function isHasExtractProp(el) {
|
|
235
|
+
const res = Object.keys(el.props).find(prop => {
|
|
236
|
+
return !(/^(class|style|id)$/.test(prop) || prop.startsWith('data-'));
|
|
237
|
+
});
|
|
238
|
+
return Boolean(res);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* 往上寻找组件树直到 root,寻找是否有祖先组件绑定了同类型的事件
|
|
242
|
+
* @param node 当前组件
|
|
243
|
+
* @param type 事件类型
|
|
244
|
+
*/
|
|
245
|
+
function isParentBinded(node, type) {
|
|
246
|
+
var _a;
|
|
247
|
+
let res = false;
|
|
248
|
+
while ((node === null || node === void 0 ? void 0 : node.parentElement) && node.parentElement._path !== ROOT_STR) {
|
|
249
|
+
if ((_a = node.parentElement.__handlers[type]) === null || _a === void 0 ? void 0 : _a.length) {
|
|
250
|
+
res = true;
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
node = node.parentElement;
|
|
254
|
+
}
|
|
255
|
+
return res;
|
|
256
|
+
}
|
|
257
|
+
function shortcutAttr(key) {
|
|
258
|
+
switch (key) {
|
|
259
|
+
case STYLE:
|
|
260
|
+
return "st" /* Shortcuts.Style */;
|
|
261
|
+
case ID:
|
|
262
|
+
return UID;
|
|
263
|
+
case CLASS:
|
|
264
|
+
return "cl" /* Shortcuts.Class */;
|
|
265
|
+
default:
|
|
266
|
+
return key;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const customWrapperCache = new Map();
|
|
270
|
+
function extend(ctor, methodName, options) {
|
|
271
|
+
if (isFunction(options)) {
|
|
272
|
+
options = {
|
|
273
|
+
value: options
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
Object.defineProperty(ctor.prototype, methodName, Object.assign({ configurable: true, enumerable: true }, options));
|
|
277
|
+
}
|
|
278
|
+
let componentsAlias$1;
|
|
279
|
+
function getComponentsAlias() {
|
|
280
|
+
if (!componentsAlias$1) {
|
|
281
|
+
componentsAlias$1 = getComponentsAlias$1(internalComponents);
|
|
282
|
+
}
|
|
283
|
+
return componentsAlias$1;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
class ClassList extends Set {
|
|
287
|
+
constructor(className, el) {
|
|
288
|
+
super();
|
|
289
|
+
className.trim().split(/\s+/).forEach(super.add.bind(this));
|
|
290
|
+
this.el = el;
|
|
291
|
+
}
|
|
292
|
+
get value() {
|
|
293
|
+
return [...this].filter(v => v !== '').join(' ');
|
|
294
|
+
}
|
|
295
|
+
add(s) {
|
|
296
|
+
super.add(s);
|
|
297
|
+
this._update();
|
|
298
|
+
return this;
|
|
299
|
+
}
|
|
300
|
+
get length() {
|
|
301
|
+
return this.size;
|
|
302
|
+
}
|
|
303
|
+
remove(s) {
|
|
304
|
+
super.delete(s);
|
|
305
|
+
this._update();
|
|
306
|
+
}
|
|
307
|
+
toggle(s) {
|
|
308
|
+
if (super.has(s)) {
|
|
309
|
+
super.delete(s);
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
super.add(s);
|
|
313
|
+
}
|
|
314
|
+
this._update();
|
|
315
|
+
}
|
|
316
|
+
replace(s1, s2) {
|
|
317
|
+
super.delete(s1);
|
|
318
|
+
super.add(s2);
|
|
319
|
+
this._update();
|
|
320
|
+
}
|
|
321
|
+
contains(s) {
|
|
322
|
+
return super.has(s);
|
|
323
|
+
}
|
|
324
|
+
toString() {
|
|
325
|
+
return this.value;
|
|
326
|
+
}
|
|
327
|
+
_update() {
|
|
328
|
+
this.el.className = this.value;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
class EventSource extends Map {
|
|
333
|
+
removeNode(child) {
|
|
334
|
+
const { sid, uid } = child;
|
|
335
|
+
this.delete(sid);
|
|
336
|
+
if (uid !== sid && uid)
|
|
337
|
+
this.delete(uid);
|
|
338
|
+
}
|
|
339
|
+
removeNodeTree(child) {
|
|
340
|
+
this.removeNode(child);
|
|
341
|
+
const { childNodes } = child;
|
|
342
|
+
childNodes.forEach(node => this.removeNodeTree(node));
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const eventSource = new EventSource();
|
|
346
|
+
|
|
347
|
+
const isWeb$1 = isWebPlatform();
|
|
348
|
+
const env = {
|
|
349
|
+
window: isWeb$1 ? window : EMPTY_OBJ,
|
|
350
|
+
document: isWeb$1 ? document : EMPTY_OBJ
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
let SPECIAL_NODES;
|
|
354
|
+
let componentsAlias;
|
|
355
|
+
/**
|
|
356
|
+
* React also has a fancy function's name for this: `hydrate()`.
|
|
357
|
+
* You may have been heard `hydrate` as a SSR-related function,
|
|
358
|
+
* actually, `hydrate` basicly do the `render()` thing, but ignore some properties,
|
|
359
|
+
* it's a vnode traverser and modifier: that's exactly what Taro's doing in here.
|
|
360
|
+
*/
|
|
361
|
+
function hydrate(node) {
|
|
362
|
+
if (!componentsAlias) {
|
|
363
|
+
// 初始化 componentsAlias
|
|
364
|
+
componentsAlias = getComponentsAlias();
|
|
365
|
+
}
|
|
366
|
+
if (!SPECIAL_NODES) {
|
|
367
|
+
// 初始化 SPECIAL_NODES
|
|
368
|
+
SPECIAL_NODES = hooks.call('getSpecialNodes');
|
|
369
|
+
}
|
|
370
|
+
const nodeName = node.nodeName;
|
|
371
|
+
if (isText(node)) {
|
|
372
|
+
return {
|
|
373
|
+
["v" /* Shortcuts.Text */]: node.nodeValue,
|
|
374
|
+
["nn" /* Shortcuts.NodeName */]: componentsAlias[nodeName]._num
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
const data = {
|
|
378
|
+
["nn" /* Shortcuts.NodeName */]: nodeName,
|
|
379
|
+
sid: node.sid
|
|
380
|
+
};
|
|
381
|
+
if (node.uid !== node.sid) {
|
|
382
|
+
data.uid = node.uid;
|
|
383
|
+
}
|
|
384
|
+
if (!node.isAnyEventBinded() && SPECIAL_NODES.indexOf(nodeName) > -1) {
|
|
385
|
+
data["nn" /* Shortcuts.NodeName */] = `static-${nodeName}`;
|
|
386
|
+
if (nodeName === VIEW && !isHasExtractProp(node)) {
|
|
387
|
+
data["nn" /* Shortcuts.NodeName */] = PURE_VIEW;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const { props } = node;
|
|
391
|
+
for (const prop in props) {
|
|
392
|
+
const propInCamelCase = toCamelCase(prop);
|
|
393
|
+
if (!prop.startsWith('data-') && // 在 node.dataset 的数据
|
|
394
|
+
prop !== CLASS &&
|
|
395
|
+
prop !== STYLE &&
|
|
396
|
+
prop !== ID &&
|
|
397
|
+
propInCamelCase !== CATCHMOVE) {
|
|
398
|
+
data[propInCamelCase] = props[prop];
|
|
399
|
+
}
|
|
400
|
+
if (nodeName === VIEW && propInCamelCase === CATCHMOVE && props[prop] !== false) {
|
|
401
|
+
data["nn" /* Shortcuts.NodeName */] = CATCH_VIEW;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
let { childNodes } = node;
|
|
405
|
+
// 过滤 comment 节点
|
|
406
|
+
childNodes = childNodes.filter(node => !isComment(node));
|
|
407
|
+
if (childNodes.length > 0) {
|
|
408
|
+
data["cn" /* Shortcuts.Childnodes */] = childNodes.map(hydrate);
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
data["cn" /* Shortcuts.Childnodes */] = [];
|
|
412
|
+
}
|
|
413
|
+
if (node.className !== '') {
|
|
414
|
+
data["cl" /* Shortcuts.Class */] = node.className;
|
|
415
|
+
}
|
|
416
|
+
const cssText = node.cssText;
|
|
417
|
+
if (cssText !== '' && nodeName !== 'swiper-item') {
|
|
418
|
+
data["st" /* Shortcuts.Style */] = cssText;
|
|
419
|
+
}
|
|
420
|
+
hooks.call('modifyHydrateData', data);
|
|
421
|
+
const nn = data["nn" /* Shortcuts.NodeName */];
|
|
422
|
+
const componentAlias = componentsAlias[nn];
|
|
423
|
+
if (componentAlias) {
|
|
424
|
+
data["nn" /* Shortcuts.NodeName */] = componentAlias._num;
|
|
425
|
+
for (const prop in data) {
|
|
426
|
+
if (prop in componentAlias) {
|
|
427
|
+
data[componentAlias[prop]] = data[prop];
|
|
428
|
+
delete data[prop];
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return data;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
class TaroEventTarget {
|
|
436
|
+
constructor() {
|
|
437
|
+
this.__handlers = {};
|
|
438
|
+
}
|
|
439
|
+
addEventListener(type, handler, options) {
|
|
440
|
+
type = type.toLowerCase();
|
|
441
|
+
hooks.call('onAddEvent', type, handler, options, this);
|
|
442
|
+
if (type === 'regionchange') {
|
|
443
|
+
// map 组件的 regionchange 事件非常特殊,详情:https://github.com/NervJS/taro/issues/5766
|
|
444
|
+
this.addEventListener('begin', handler, options);
|
|
445
|
+
this.addEventListener('end', handler, options);
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
let isCapture = Boolean(options);
|
|
449
|
+
let isOnce = false;
|
|
450
|
+
if (isObject(options)) {
|
|
451
|
+
isCapture = Boolean(options.capture);
|
|
452
|
+
isOnce = Boolean(options.once);
|
|
453
|
+
}
|
|
454
|
+
if (isOnce) {
|
|
455
|
+
const wrapper = function () {
|
|
456
|
+
handler.apply(this, arguments); // this 指向 Element
|
|
457
|
+
this.removeEventListener(type, wrapper);
|
|
458
|
+
};
|
|
459
|
+
this.addEventListener(type, wrapper, Object.assign(Object.assign({}, options), { once: false }));
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
process.env.NODE_ENV !== 'production' && warn(isCapture, 'Taro 暂未实现 event 的 capture 特性。');
|
|
463
|
+
// 某些框架,如 PReact 有委托的机制,handler 始终是同一个函数
|
|
464
|
+
// 这会导致多层停止冒泡失败:view -> view(handler.stop = false) -> view(handler.stop = true)
|
|
465
|
+
// 这样解决:view -> view(handlerA.stop = false) -> view(handlerB.stop = false)
|
|
466
|
+
// 因此每次绑定事件都新建一个函数,如果带来了性能问题,可以把这段逻辑抽取到 PReact 插件中。
|
|
467
|
+
const oldHandler = handler;
|
|
468
|
+
handler = function () {
|
|
469
|
+
return oldHandler.apply(this, arguments); // this 指向 Element
|
|
470
|
+
};
|
|
471
|
+
handler.oldHandler = oldHandler;
|
|
472
|
+
const handlers = this.__handlers[type];
|
|
473
|
+
if (isArray(handlers)) {
|
|
474
|
+
handlers.push(handler);
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
this.__handlers[type] = [handler];
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
removeEventListener(type, handler) {
|
|
481
|
+
type = type.toLowerCase();
|
|
482
|
+
if (type === 'regionchange') {
|
|
483
|
+
// map 组件的 regionchange 事件非常特殊,详情:https://github.com/NervJS/taro/issues/5766
|
|
484
|
+
this.removeEventListener('begin', handler);
|
|
485
|
+
this.removeEventListener('end', handler);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
if (!handler) {
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
const handlers = this.__handlers[type];
|
|
492
|
+
if (!isArray(handlers)) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
const index = handlers.findIndex(item => {
|
|
496
|
+
if (item === handler || item.oldHandler === handler)
|
|
497
|
+
return true;
|
|
498
|
+
});
|
|
499
|
+
process.env.NODE_ENV !== 'production' && warn(index === -1, `事件: '${type}' 没有注册在 DOM 中,因此不会被移除。`);
|
|
500
|
+
handlers.splice(index, 1);
|
|
501
|
+
}
|
|
502
|
+
isAnyEventBinded() {
|
|
503
|
+
const handlers = this.__handlers;
|
|
504
|
+
const isAnyEventBinded = Object.keys(handlers).find(key => handlers[key].length);
|
|
505
|
+
return Boolean(isAnyEventBinded);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
const CHILDNODES = "cn" /* Shortcuts.Childnodes */;
|
|
510
|
+
const nodeId = incrementId();
|
|
511
|
+
class TaroNode extends TaroEventTarget {
|
|
512
|
+
constructor() {
|
|
513
|
+
super();
|
|
514
|
+
this.parentNode = null;
|
|
515
|
+
this.childNodes = [];
|
|
516
|
+
this.hydrate = (node) => () => hydrate(node);
|
|
517
|
+
this.uid = '_' + nodeId(); // dom 节点 id,开发者可修改
|
|
518
|
+
this.sid = this.uid; // dom 节点全局唯一 id,不可被修改
|
|
519
|
+
eventSource.set(this.sid, this);
|
|
520
|
+
}
|
|
521
|
+
updateChildNodes(isClean) {
|
|
522
|
+
const cleanChildNodes = () => [];
|
|
523
|
+
const rerenderChildNodes = () => {
|
|
524
|
+
const childNodes = this.childNodes.filter(node => !isComment(node));
|
|
525
|
+
return childNodes.map(hydrate);
|
|
526
|
+
};
|
|
527
|
+
this.enqueueUpdate({
|
|
528
|
+
path: `${this._path}.${CHILDNODES}`,
|
|
529
|
+
value: isClean ? cleanChildNodes : rerenderChildNodes
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
get _root() {
|
|
533
|
+
var _a;
|
|
534
|
+
return ((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a._root) || null;
|
|
535
|
+
}
|
|
536
|
+
findIndex(refChild) {
|
|
537
|
+
const index = this.childNodes.indexOf(refChild);
|
|
538
|
+
ensure(index !== -1, 'The node to be replaced is not a child of this node.');
|
|
539
|
+
return index;
|
|
540
|
+
}
|
|
541
|
+
get _path() {
|
|
542
|
+
const parentNode = this.parentNode;
|
|
543
|
+
if (parentNode) {
|
|
544
|
+
// 计算路径时,先过滤掉 comment 节点
|
|
545
|
+
const list = parentNode.childNodes.filter(node => !isComment(node));
|
|
546
|
+
const indexOfNode = list.indexOf(this);
|
|
547
|
+
const index = hooks.call('getPathIndex', indexOfNode);
|
|
548
|
+
return `${parentNode._path}.${CHILDNODES}.${index}`;
|
|
549
|
+
}
|
|
550
|
+
return '';
|
|
551
|
+
}
|
|
552
|
+
get nextSibling() {
|
|
553
|
+
const parentNode = this.parentNode;
|
|
554
|
+
return (parentNode === null || parentNode === void 0 ? void 0 : parentNode.childNodes[parentNode.findIndex(this) + 1]) || null;
|
|
555
|
+
}
|
|
556
|
+
get previousSibling() {
|
|
557
|
+
const parentNode = this.parentNode;
|
|
558
|
+
return (parentNode === null || parentNode === void 0 ? void 0 : parentNode.childNodes[parentNode.findIndex(this) - 1]) || null;
|
|
559
|
+
}
|
|
560
|
+
get parentElement() {
|
|
561
|
+
const parentNode = this.parentNode;
|
|
562
|
+
if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.nodeType) === 1 /* NodeType.ELEMENT_NODE */) {
|
|
563
|
+
return parentNode;
|
|
564
|
+
}
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
get firstChild() {
|
|
568
|
+
return this.childNodes[0] || null;
|
|
569
|
+
}
|
|
570
|
+
get lastChild() {
|
|
571
|
+
const childNodes = this.childNodes;
|
|
572
|
+
return childNodes[childNodes.length - 1] || null;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* @textContent 目前只能置空子元素
|
|
576
|
+
* @TODO 等待完整 innerHTML 实现
|
|
577
|
+
*/
|
|
578
|
+
// eslint-disable-next-line accessor-pairs
|
|
579
|
+
set textContent(text) {
|
|
580
|
+
const removedNodes = this.childNodes.slice();
|
|
581
|
+
const addedNodes = [];
|
|
582
|
+
// Handle old children' data structure & ref
|
|
583
|
+
while (this.firstChild) {
|
|
584
|
+
this.removeChild(this.firstChild, { doUpdate: false });
|
|
585
|
+
}
|
|
586
|
+
if (text === '') {
|
|
587
|
+
this.updateChildNodes(true);
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
const newText = env.document.createTextNode(text);
|
|
591
|
+
addedNodes.push(newText);
|
|
592
|
+
this.appendChild(newText);
|
|
593
|
+
this.updateChildNodes();
|
|
594
|
+
}
|
|
595
|
+
// @Todo: appendChild 会多触发一次
|
|
596
|
+
MutationObserver.record({
|
|
597
|
+
type: "childList" /* MutationRecordType.CHILD_LIST */,
|
|
598
|
+
target: this,
|
|
599
|
+
removedNodes,
|
|
600
|
+
addedNodes
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/insertBefore
|
|
605
|
+
* @scenario
|
|
606
|
+
* [A,B,C]
|
|
607
|
+
* 1. insert D before C, D has no parent
|
|
608
|
+
* 2. insert D before C, D has the same parent of C
|
|
609
|
+
* 3. insert D before C, D has the different parent of C
|
|
610
|
+
*/
|
|
611
|
+
insertBefore(newChild, refChild, isReplace) {
|
|
612
|
+
if (newChild.nodeName === DOCUMENT_FRAGMENT) {
|
|
613
|
+
newChild.childNodes.reduceRight((previousValue, currentValue) => {
|
|
614
|
+
this.insertBefore(currentValue, previousValue);
|
|
615
|
+
return currentValue;
|
|
616
|
+
}, refChild);
|
|
617
|
+
return newChild;
|
|
618
|
+
}
|
|
619
|
+
// Parent release newChild
|
|
620
|
+
// - cleanRef: false (No need to clean eventSource, because newChild is about to be inserted)
|
|
621
|
+
// - update: true (Need to update parent.childNodes, because parent.childNodes is reordered)
|
|
622
|
+
newChild.remove({ cleanRef: false });
|
|
623
|
+
// Data structure
|
|
624
|
+
newChild.parentNode = this;
|
|
625
|
+
if (refChild) {
|
|
626
|
+
// insertBefore & replaceChild
|
|
627
|
+
const index = this.findIndex(refChild);
|
|
628
|
+
this.childNodes.splice(index, 0, newChild);
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
// appendChild
|
|
632
|
+
this.childNodes.push(newChild);
|
|
633
|
+
}
|
|
634
|
+
// Serialization
|
|
635
|
+
if (this._root) {
|
|
636
|
+
if (!refChild) {
|
|
637
|
+
// appendChild
|
|
638
|
+
const isOnlyChild = this.childNodes.length === 1;
|
|
639
|
+
if (isOnlyChild) {
|
|
640
|
+
this.updateChildNodes();
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
this.enqueueUpdate({
|
|
644
|
+
path: newChild._path,
|
|
645
|
+
value: this.hydrate(newChild)
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
else if (isReplace) {
|
|
650
|
+
// replaceChild
|
|
651
|
+
this.enqueueUpdate({
|
|
652
|
+
path: newChild._path,
|
|
653
|
+
value: this.hydrate(newChild)
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
else {
|
|
657
|
+
// insertBefore
|
|
658
|
+
this.updateChildNodes();
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
MutationObserver.record({
|
|
662
|
+
type: "childList" /* MutationRecordType.CHILD_LIST */,
|
|
663
|
+
target: this,
|
|
664
|
+
addedNodes: [newChild],
|
|
665
|
+
removedNodes: isReplace
|
|
666
|
+
? [refChild] /** replaceChild */
|
|
667
|
+
: [],
|
|
668
|
+
nextSibling: isReplace
|
|
669
|
+
? refChild.nextSibling /** replaceChild */
|
|
670
|
+
: (refChild || null),
|
|
671
|
+
previousSibling: newChild.previousSibling
|
|
672
|
+
});
|
|
673
|
+
return newChild;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/appendChild
|
|
677
|
+
* @scenario
|
|
678
|
+
* [A,B,C]
|
|
679
|
+
* 1. append C, C has no parent
|
|
680
|
+
* 2. append C, C has the same parent of B
|
|
681
|
+
* 3. append C, C has the different parent of B
|
|
682
|
+
*/
|
|
683
|
+
appendChild(newChild) {
|
|
684
|
+
return this.insertBefore(newChild);
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/replaceChild
|
|
688
|
+
* @scenario
|
|
689
|
+
* [A,B,C]
|
|
690
|
+
* 1. replace B with C, C has no parent
|
|
691
|
+
* 2. replace B with C, C has no parent, C has the same parent of B
|
|
692
|
+
* 3. replace B with C, C has no parent, C has the different parent of B
|
|
693
|
+
*/
|
|
694
|
+
replaceChild(newChild, oldChild) {
|
|
695
|
+
if (oldChild.parentNode !== this)
|
|
696
|
+
return;
|
|
697
|
+
// Insert the newChild
|
|
698
|
+
this.insertBefore(newChild, oldChild, true);
|
|
699
|
+
// Destroy the oldChild
|
|
700
|
+
// - cleanRef: true (Need to clean eventSource, because the oldChild was detached from the DOM tree)
|
|
701
|
+
// - update: false (No need to update parent.childNodes, because replace will not cause the parent.childNodes being reordered)
|
|
702
|
+
oldChild.remove({ doUpdate: false });
|
|
703
|
+
return oldChild;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/removeChild
|
|
707
|
+
* @scenario
|
|
708
|
+
* [A,B,C]
|
|
709
|
+
* 1. remove A or B
|
|
710
|
+
* 2. remove C
|
|
711
|
+
*/
|
|
712
|
+
removeChild(child, options = {}) {
|
|
713
|
+
const { cleanRef, doUpdate } = options;
|
|
714
|
+
if (cleanRef !== false && doUpdate !== false) {
|
|
715
|
+
// appendChild/replaceChild/insertBefore 不应该触发
|
|
716
|
+
// @Todo: 但其实如果 newChild 的父节点是另一颗子树的节点,应该是要触发的
|
|
717
|
+
MutationObserver.record({
|
|
718
|
+
type: "childList" /* MutationRecordType.CHILD_LIST */,
|
|
719
|
+
target: this,
|
|
720
|
+
removedNodes: [child],
|
|
721
|
+
nextSibling: child.nextSibling,
|
|
722
|
+
previousSibling: child.previousSibling
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
// Data Structure
|
|
726
|
+
const index = this.findIndex(child);
|
|
727
|
+
this.childNodes.splice(index, 1);
|
|
728
|
+
child.parentNode = null;
|
|
729
|
+
// Set eventSource
|
|
730
|
+
if (cleanRef !== false) {
|
|
731
|
+
eventSource.removeNodeTree(child);
|
|
732
|
+
}
|
|
733
|
+
// Serialization
|
|
734
|
+
if (this._root && doUpdate !== false) {
|
|
735
|
+
this.updateChildNodes();
|
|
736
|
+
}
|
|
737
|
+
return child;
|
|
738
|
+
}
|
|
739
|
+
remove(options) {
|
|
740
|
+
var _a;
|
|
741
|
+
(_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this, options);
|
|
742
|
+
}
|
|
743
|
+
hasChildNodes() {
|
|
744
|
+
return this.childNodes.length > 0;
|
|
745
|
+
}
|
|
746
|
+
enqueueUpdate(payload) {
|
|
747
|
+
var _a;
|
|
748
|
+
(_a = this._root) === null || _a === void 0 ? void 0 : _a.enqueueUpdate(payload);
|
|
749
|
+
}
|
|
750
|
+
get ownerDocument() {
|
|
751
|
+
return env.document;
|
|
752
|
+
}
|
|
753
|
+
static extend(methodName, options) {
|
|
754
|
+
extend(TaroNode, methodName, options);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/*
|
|
759
|
+
*
|
|
760
|
+
* https://www.w3.org/Style/CSS/all-properties.en.html
|
|
761
|
+
*/
|
|
762
|
+
const WEBKIT = 'webkit';
|
|
763
|
+
const styleProperties = [
|
|
764
|
+
'all',
|
|
765
|
+
'appearance',
|
|
766
|
+
'blockOverflow',
|
|
767
|
+
'blockSize',
|
|
768
|
+
'bottom',
|
|
769
|
+
'clear',
|
|
770
|
+
'contain',
|
|
771
|
+
'content',
|
|
772
|
+
'continue',
|
|
773
|
+
'cursor',
|
|
774
|
+
'direction',
|
|
775
|
+
'display',
|
|
776
|
+
'filter',
|
|
777
|
+
'float',
|
|
778
|
+
'gap',
|
|
779
|
+
'height',
|
|
780
|
+
'inset',
|
|
781
|
+
'isolation',
|
|
782
|
+
'left',
|
|
783
|
+
'letterSpacing',
|
|
784
|
+
'lightingColor',
|
|
785
|
+
'markerSide',
|
|
786
|
+
'mixBlendMode',
|
|
787
|
+
'opacity',
|
|
788
|
+
'order',
|
|
789
|
+
'position',
|
|
790
|
+
'quotes',
|
|
791
|
+
'resize',
|
|
792
|
+
'right',
|
|
793
|
+
'rowGap',
|
|
794
|
+
'tabSize',
|
|
795
|
+
'tableLayout',
|
|
796
|
+
'top',
|
|
797
|
+
'userSelect',
|
|
798
|
+
'verticalAlign',
|
|
799
|
+
'visibility',
|
|
800
|
+
'voiceFamily',
|
|
801
|
+
'volume',
|
|
802
|
+
'whiteSpace',
|
|
803
|
+
'widows',
|
|
804
|
+
'width',
|
|
805
|
+
'zIndex',
|
|
806
|
+
'pointerEvents'
|
|
807
|
+
/** 非常用 style */
|
|
808
|
+
// 'azimuth',
|
|
809
|
+
// 'backfaceVisibility',
|
|
810
|
+
// 'baselineShift',
|
|
811
|
+
// 'captionSide',
|
|
812
|
+
// 'chains',
|
|
813
|
+
// 'dominantBaseline',
|
|
814
|
+
// 'elevation',
|
|
815
|
+
// 'emptyCells',
|
|
816
|
+
// 'forcedColorAdjust',
|
|
817
|
+
// 'glyphOrientationVertical',
|
|
818
|
+
// 'hangingPunctuation',
|
|
819
|
+
// 'hyphenateCharacter',
|
|
820
|
+
// 'hyphens',
|
|
821
|
+
// 'imageOrientation',
|
|
822
|
+
// 'imageResolution',
|
|
823
|
+
// 'orphans',
|
|
824
|
+
// 'playDuring',
|
|
825
|
+
// 'pointerEvents',
|
|
826
|
+
// 'regionFragment',
|
|
827
|
+
// 'richness',
|
|
828
|
+
// 'running',
|
|
829
|
+
// 'scrollBehavior',
|
|
830
|
+
// 'speechRate',
|
|
831
|
+
// 'stress',
|
|
832
|
+
// 'stringSet',
|
|
833
|
+
// 'unicodeBidi',
|
|
834
|
+
// 'willChange',
|
|
835
|
+
// 'writingMode',
|
|
836
|
+
];
|
|
837
|
+
// 减少文件体积
|
|
838
|
+
function combine(prefix, list, excludeSelf) {
|
|
839
|
+
!excludeSelf && styleProperties.push(prefix);
|
|
840
|
+
list.forEach(item => {
|
|
841
|
+
styleProperties.push(prefix + item);
|
|
842
|
+
if (prefix === WEBKIT) {
|
|
843
|
+
styleProperties.push('Webkit' + item);
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
const color = 'Color';
|
|
848
|
+
const style = 'Style';
|
|
849
|
+
const width = 'Width';
|
|
850
|
+
const image = 'Image';
|
|
851
|
+
const size = 'Size';
|
|
852
|
+
const color_style_width = [color, style, width];
|
|
853
|
+
const fitlength_fitwidth_image = ['FitLength', 'FitWidth', image];
|
|
854
|
+
const fitlength_fitwidth_image_radius = [...fitlength_fitwidth_image, 'Radius'];
|
|
855
|
+
const color_style_width_fitlength_fitwidth_image = [...color_style_width, ...fitlength_fitwidth_image];
|
|
856
|
+
const endRadius_startRadius = ['EndRadius', 'StartRadius'];
|
|
857
|
+
const bottom_left_right_top = ['Bottom', 'Left', 'Right', 'Top'];
|
|
858
|
+
const end_start = ['End', 'Start'];
|
|
859
|
+
const content_items_self = ['Content', 'Items', 'Self'];
|
|
860
|
+
const blockSize_height_inlineSize_width = ['BlockSize', 'Height', 'InlineSize', width];
|
|
861
|
+
const after_before = ['After', 'Before'];
|
|
862
|
+
combine('borderBlock', color_style_width);
|
|
863
|
+
combine('borderBlockEnd', color_style_width);
|
|
864
|
+
combine('borderBlockStart', color_style_width);
|
|
865
|
+
combine('outline', [...color_style_width, 'Offset']);
|
|
866
|
+
combine('border', [...color_style_width, 'Boundary', 'Break', 'Collapse', 'Radius', 'Spacing']);
|
|
867
|
+
combine('borderFit', ['Length', width]);
|
|
868
|
+
combine('borderInline', color_style_width);
|
|
869
|
+
combine('borderInlineEnd', color_style_width);
|
|
870
|
+
combine('borderInlineStart', color_style_width);
|
|
871
|
+
combine('borderLeft', color_style_width_fitlength_fitwidth_image);
|
|
872
|
+
combine('borderRight', color_style_width_fitlength_fitwidth_image);
|
|
873
|
+
combine('borderTop', color_style_width_fitlength_fitwidth_image);
|
|
874
|
+
combine('borderBottom', color_style_width_fitlength_fitwidth_image);
|
|
875
|
+
combine('textDecoration', [color, style, 'Line']);
|
|
876
|
+
combine('textEmphasis', [color, style, 'Position']);
|
|
877
|
+
combine('scrollMargin', bottom_left_right_top);
|
|
878
|
+
combine('scrollPadding', bottom_left_right_top);
|
|
879
|
+
combine('padding', bottom_left_right_top);
|
|
880
|
+
combine('margin', [...bottom_left_right_top, 'Trim']);
|
|
881
|
+
combine('scrollMarginBlock', end_start);
|
|
882
|
+
combine('scrollMarginInline', end_start);
|
|
883
|
+
combine('scrollPaddingBlock', end_start);
|
|
884
|
+
combine('scrollPaddingInline', end_start);
|
|
885
|
+
combine('gridColumn', end_start);
|
|
886
|
+
combine('gridRow', end_start);
|
|
887
|
+
combine('insetBlock', end_start);
|
|
888
|
+
combine('insetInline', end_start);
|
|
889
|
+
combine('marginBlock', end_start);
|
|
890
|
+
combine('marginInline', end_start);
|
|
891
|
+
combine('paddingBlock', end_start);
|
|
892
|
+
combine('paddingInline', end_start);
|
|
893
|
+
combine('pause', after_before);
|
|
894
|
+
combine('cue', after_before);
|
|
895
|
+
combine('mask', ['Clip', 'Composite', image, 'Mode', 'Origin', 'Position', 'Repeat', size, 'Type']);
|
|
896
|
+
combine('borderImage', ['Outset', 'Repeat', 'Slice', 'Source', 'Transform', width]);
|
|
897
|
+
combine('maskBorder', ['Mode', 'Outset', 'Repeat', 'Slice', 'Source', width]);
|
|
898
|
+
combine('font', ['Family', 'FeatureSettings', 'Kerning', 'LanguageOverride', 'MaxSize', 'MinSize', 'OpticalSizing', 'Palette', size, 'SizeAdjust', 'Stretch', style, 'Weight', 'VariationSettings']);
|
|
899
|
+
combine('transform', ['Box', 'Origin', style]);
|
|
900
|
+
combine('background', [color, image, 'Attachment', 'BlendMode', 'Clip', 'Origin', 'Position', 'Repeat', size]);
|
|
901
|
+
combine('listStyle', [image, 'Position', 'Type']);
|
|
902
|
+
combine('scrollSnap', ['Align', 'Stop', 'Type']);
|
|
903
|
+
combine('grid', ['Area', 'AutoColumns', 'AutoFlow', 'AutoRows']);
|
|
904
|
+
combine('gridTemplate', ['Areas', 'Columns', 'Rows']);
|
|
905
|
+
combine('overflow', ['Block', 'Inline', 'Wrap', 'X', 'Y']);
|
|
906
|
+
combine('transition', ['Delay', 'Duration', 'Property', 'TimingFunction']);
|
|
907
|
+
combine('color', ['Adjust', 'InterpolationFilters', 'Scheme']);
|
|
908
|
+
combine('textAlign', ['All', 'Last']);
|
|
909
|
+
combine('page', ['BreakAfter', 'BreakBefore', 'BreakInside']);
|
|
910
|
+
combine('animation', ['Delay', 'Direction', 'Duration', 'FillMode', 'IterationCount', 'Name', 'PlayState', 'TimingFunction']);
|
|
911
|
+
combine('flex', ['Basis', 'Direction', 'Flow', 'Grow', 'Shrink', 'Wrap']);
|
|
912
|
+
combine('offset', [...after_before, ...end_start, 'Anchor', 'Distance', 'Path', 'Position', 'Rotate']);
|
|
913
|
+
combine('perspective', ['Origin']);
|
|
914
|
+
combine('clip', ['Path', 'Rule']);
|
|
915
|
+
combine('flow', ['From', 'Into']);
|
|
916
|
+
combine('align', ['Content', 'Items', 'Self'], true);
|
|
917
|
+
combine('alignment', ['Adjust', 'Baseline'], true);
|
|
918
|
+
combine('borderStart', endRadius_startRadius, true);
|
|
919
|
+
combine('borderEnd', endRadius_startRadius, true);
|
|
920
|
+
combine('borderCorner', ['Fit', image, 'ImageTransform'], true);
|
|
921
|
+
combine('borderTopLeft', fitlength_fitwidth_image_radius, true);
|
|
922
|
+
combine('borderTopRight', fitlength_fitwidth_image_radius, true);
|
|
923
|
+
combine('borderBottomLeft', fitlength_fitwidth_image_radius, true);
|
|
924
|
+
combine('borderBottomRight', fitlength_fitwidth_image_radius, true);
|
|
925
|
+
combine('column', ['s', 'Count', 'Fill', 'Gap', 'Rule', 'RuleColor', 'RuleStyle', 'RuleWidth', 'Span', width], true);
|
|
926
|
+
combine('break', [...after_before, 'Inside'], true);
|
|
927
|
+
combine('wrap', [...after_before, 'Flow', 'Inside', 'Through'], true);
|
|
928
|
+
combine('justify', content_items_self, true);
|
|
929
|
+
combine('place', content_items_self, true);
|
|
930
|
+
combine('max', [...blockSize_height_inlineSize_width, 'Lines'], true);
|
|
931
|
+
combine('min', blockSize_height_inlineSize_width, true);
|
|
932
|
+
combine('line', ['Break', 'Clamp', 'Grid', 'Height', 'Padding', 'Snap'], true);
|
|
933
|
+
combine('inline', ['BoxAlign', size, 'Sizing'], true);
|
|
934
|
+
combine('text', ['CombineUpright', 'GroupAlign', 'Height', 'Indent', 'Justify', 'Orientation', 'Overflow', 'Shadow', 'SpaceCollapse', 'SpaceTrim', 'Spacing', 'Transform', 'UnderlinePosition', 'Wrap'], true);
|
|
935
|
+
combine('shape', ['ImageThreshold', 'Inside', 'Margin', 'Outside'], true);
|
|
936
|
+
combine('word', ['Break', 'Spacing', 'Wrap'], true);
|
|
937
|
+
combine('object', ['Fit', 'Position'], true);
|
|
938
|
+
combine('box', ['DecorationBreak', 'Shadow', 'Sizing', 'Snap'], true);
|
|
939
|
+
combine(WEBKIT, ['LineClamp', 'BoxOrient', 'TextFillColor', 'TextStroke', 'TextStrokeColor', 'TextStrokeWidth'], true);
|
|
940
|
+
|
|
941
|
+
function recordCss(obj) {
|
|
942
|
+
MutationObserver.record({
|
|
943
|
+
type: "attributes" /* MutationRecordType.ATTRIBUTES */,
|
|
944
|
+
target: obj._element,
|
|
945
|
+
attributeName: 'style',
|
|
946
|
+
oldValue: obj.cssText
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
function enqueueUpdate(obj) {
|
|
950
|
+
const element = obj._element;
|
|
951
|
+
if (element._root) {
|
|
952
|
+
element.enqueueUpdate({
|
|
953
|
+
path: `${element._path}.${"st" /* Shortcuts.Style */}`,
|
|
954
|
+
value: obj.cssText
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
function setStyle(newVal, styleKey) {
|
|
959
|
+
process.env.NODE_ENV !== 'production' && warn(isString(newVal) && newVal.length > PROPERTY_THRESHOLD, `Style 属性 ${styleKey} 的值数据量过大,可能会影响渲染性能,考虑使用 CSS 类或其它方案替代。`);
|
|
960
|
+
const old = this[styleKey];
|
|
961
|
+
if (old === newVal)
|
|
962
|
+
return;
|
|
963
|
+
!this._pending && recordCss(this);
|
|
964
|
+
if (isNull(newVal) || isUndefined(newVal)) {
|
|
965
|
+
this._usedStyleProp.delete(styleKey);
|
|
966
|
+
delete this._value[styleKey];
|
|
967
|
+
}
|
|
968
|
+
else {
|
|
969
|
+
this._usedStyleProp.add(styleKey);
|
|
970
|
+
this._value[styleKey] = newVal;
|
|
971
|
+
}
|
|
972
|
+
!this._pending && enqueueUpdate(this);
|
|
973
|
+
}
|
|
974
|
+
function initStyle(ctor) {
|
|
975
|
+
const properties = {};
|
|
976
|
+
for (let i = 0; i < styleProperties.length; i++) {
|
|
977
|
+
const styleKey = styleProperties[i];
|
|
978
|
+
properties[styleKey] = {
|
|
979
|
+
get() {
|
|
980
|
+
const val = this._value[styleKey];
|
|
981
|
+
return isNull(val) || isUndefined(val) ? '' : val;
|
|
982
|
+
},
|
|
983
|
+
set(newVal) {
|
|
984
|
+
setStyle.call(this, newVal, styleKey);
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
Object.defineProperties(ctor.prototype, properties);
|
|
989
|
+
}
|
|
990
|
+
function isCssVariable(propertyName) {
|
|
991
|
+
return /^--/.test(propertyName);
|
|
992
|
+
}
|
|
993
|
+
class Style {
|
|
994
|
+
constructor(element) {
|
|
995
|
+
this._element = element;
|
|
996
|
+
this._usedStyleProp = new Set();
|
|
997
|
+
this._value = {};
|
|
998
|
+
}
|
|
999
|
+
setCssVariables(styleKey) {
|
|
1000
|
+
this.hasOwnProperty(styleKey) || Object.defineProperty(this, styleKey, {
|
|
1001
|
+
enumerable: true,
|
|
1002
|
+
configurable: true,
|
|
1003
|
+
get: () => {
|
|
1004
|
+
return this._value[styleKey] || '';
|
|
1005
|
+
},
|
|
1006
|
+
set: (newVal) => {
|
|
1007
|
+
setStyle.call(this, newVal, styleKey);
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
get cssText() {
|
|
1012
|
+
if (!this._usedStyleProp.size)
|
|
1013
|
+
return '';
|
|
1014
|
+
const texts = [];
|
|
1015
|
+
this._usedStyleProp.forEach(key => {
|
|
1016
|
+
const val = this[key];
|
|
1017
|
+
if (isNull(val) || isUndefined(val))
|
|
1018
|
+
return;
|
|
1019
|
+
let styleName = isCssVariable(key) ? key : toDashed(key);
|
|
1020
|
+
if (styleName.indexOf('webkit') === 0 || styleName.indexOf('Webkit') === 0) {
|
|
1021
|
+
styleName = `-${styleName}`;
|
|
1022
|
+
}
|
|
1023
|
+
texts.push(`${styleName}: ${val};`);
|
|
1024
|
+
});
|
|
1025
|
+
return texts.join(' ');
|
|
1026
|
+
}
|
|
1027
|
+
set cssText(str) {
|
|
1028
|
+
this._pending = true;
|
|
1029
|
+
recordCss(this);
|
|
1030
|
+
this._usedStyleProp.forEach(prop => {
|
|
1031
|
+
this.removeProperty(prop);
|
|
1032
|
+
});
|
|
1033
|
+
if (str === '' || isUndefined(str) || isNull(str)) {
|
|
1034
|
+
this._pending = false;
|
|
1035
|
+
enqueueUpdate(this);
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
const rules = str.split(';');
|
|
1039
|
+
for (let i = 0; i < rules.length; i++) {
|
|
1040
|
+
const rule = rules[i].trim();
|
|
1041
|
+
if (rule === '') {
|
|
1042
|
+
continue;
|
|
1043
|
+
}
|
|
1044
|
+
// 可能存在 'background: url(http:x/y/z)' 的情况
|
|
1045
|
+
const [propName, ...valList] = rule.split(':');
|
|
1046
|
+
const val = valList.join(':');
|
|
1047
|
+
if (isUndefined(val)) {
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
this.setProperty(propName.trim(), val.trim());
|
|
1051
|
+
}
|
|
1052
|
+
this._pending = false;
|
|
1053
|
+
enqueueUpdate(this);
|
|
1054
|
+
}
|
|
1055
|
+
setProperty(propertyName, value) {
|
|
1056
|
+
if (propertyName[0] === '-') {
|
|
1057
|
+
// 支持 webkit 属性或 css 变量
|
|
1058
|
+
this.setCssVariables(propertyName);
|
|
1059
|
+
}
|
|
1060
|
+
else {
|
|
1061
|
+
propertyName = toCamelCase(propertyName);
|
|
1062
|
+
}
|
|
1063
|
+
if (isNull(value) || isUndefined(value)) {
|
|
1064
|
+
this.removeProperty(propertyName);
|
|
1065
|
+
}
|
|
1066
|
+
else {
|
|
1067
|
+
this[propertyName] = value;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
removeProperty(propertyName) {
|
|
1071
|
+
propertyName = toCamelCase(propertyName);
|
|
1072
|
+
if (!this._usedStyleProp.has(propertyName)) {
|
|
1073
|
+
return '';
|
|
1074
|
+
}
|
|
1075
|
+
const value = this[propertyName];
|
|
1076
|
+
this[propertyName] = undefined;
|
|
1077
|
+
return value;
|
|
1078
|
+
}
|
|
1079
|
+
getPropertyValue(propertyName) {
|
|
1080
|
+
propertyName = toCamelCase(propertyName);
|
|
1081
|
+
const value = this[propertyName];
|
|
1082
|
+
if (!value) {
|
|
1083
|
+
return '';
|
|
1084
|
+
}
|
|
1085
|
+
return value;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
initStyle(Style);
|
|
1089
|
+
|
|
1090
|
+
function returnTrue() {
|
|
1091
|
+
return true;
|
|
1092
|
+
}
|
|
1093
|
+
function treeToArray(root, predict) {
|
|
1094
|
+
const array = [];
|
|
1095
|
+
const filter = predict !== null && predict !== void 0 ? predict : returnTrue;
|
|
1096
|
+
let object = root;
|
|
1097
|
+
while (object) {
|
|
1098
|
+
if (object.nodeType === 1 /* NodeType.ELEMENT_NODE */ && filter(object)) {
|
|
1099
|
+
array.push(object);
|
|
1100
|
+
}
|
|
1101
|
+
object = following(object, root);
|
|
1102
|
+
}
|
|
1103
|
+
return array;
|
|
1104
|
+
}
|
|
1105
|
+
function following(el, root) {
|
|
1106
|
+
const firstChild = el.firstChild;
|
|
1107
|
+
if (firstChild) {
|
|
1108
|
+
return firstChild;
|
|
1109
|
+
}
|
|
1110
|
+
let current = el;
|
|
1111
|
+
do {
|
|
1112
|
+
if (current === root) {
|
|
1113
|
+
return null;
|
|
1114
|
+
}
|
|
1115
|
+
const nextSibling = current.nextSibling;
|
|
1116
|
+
if (nextSibling) {
|
|
1117
|
+
return nextSibling;
|
|
1118
|
+
}
|
|
1119
|
+
current = current.parentElement;
|
|
1120
|
+
} while (current);
|
|
1121
|
+
return null;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
class TaroElement extends TaroNode {
|
|
1125
|
+
constructor() {
|
|
1126
|
+
super();
|
|
1127
|
+
this.props = {};
|
|
1128
|
+
this.dataset = EMPTY_OBJ;
|
|
1129
|
+
this.nodeType = 1 /* NodeType.ELEMENT_NODE */;
|
|
1130
|
+
this.style = new Style(this);
|
|
1131
|
+
hooks.call('patchElement', this);
|
|
1132
|
+
}
|
|
1133
|
+
_stopPropagation(event) {
|
|
1134
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
1135
|
+
let target = this;
|
|
1136
|
+
// eslint-disable-next-line no-cond-assign
|
|
1137
|
+
while ((target = target.parentNode)) {
|
|
1138
|
+
const listeners = target.__handlers[event.type];
|
|
1139
|
+
if (!isArray(listeners)) {
|
|
1140
|
+
continue;
|
|
1141
|
+
}
|
|
1142
|
+
for (let i = listeners.length; i--;) {
|
|
1143
|
+
const l = listeners[i];
|
|
1144
|
+
l._stop = true;
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
get id() {
|
|
1149
|
+
return this.getAttribute(ID);
|
|
1150
|
+
}
|
|
1151
|
+
set id(val) {
|
|
1152
|
+
this.setAttribute(ID, val);
|
|
1153
|
+
}
|
|
1154
|
+
get className() {
|
|
1155
|
+
return this.getAttribute(CLASS) || '';
|
|
1156
|
+
}
|
|
1157
|
+
set className(val) {
|
|
1158
|
+
this.setAttribute(CLASS, val);
|
|
1159
|
+
}
|
|
1160
|
+
get cssText() {
|
|
1161
|
+
return this.getAttribute(STYLE) || '';
|
|
1162
|
+
}
|
|
1163
|
+
get classList() {
|
|
1164
|
+
return new ClassList(this.className, this);
|
|
1165
|
+
}
|
|
1166
|
+
get children() {
|
|
1167
|
+
return this.childNodes.filter(isElement);
|
|
1168
|
+
}
|
|
1169
|
+
get attributes() {
|
|
1170
|
+
const props = this.props;
|
|
1171
|
+
const propKeys = Object.keys(props);
|
|
1172
|
+
const style = this.style.cssText;
|
|
1173
|
+
const attrs = propKeys.map(key => ({ name: key, value: props[key] }));
|
|
1174
|
+
return attrs.concat(style ? { name: STYLE, value: style } : []);
|
|
1175
|
+
}
|
|
1176
|
+
get textContent() {
|
|
1177
|
+
let text = '';
|
|
1178
|
+
const childNodes = this.childNodes;
|
|
1179
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
1180
|
+
text += childNodes[i].textContent;
|
|
1181
|
+
}
|
|
1182
|
+
return text;
|
|
1183
|
+
}
|
|
1184
|
+
set textContent(text) {
|
|
1185
|
+
super.textContent = text;
|
|
1186
|
+
}
|
|
1187
|
+
hasAttribute(qualifiedName) {
|
|
1188
|
+
return !isUndefined(this.props[qualifiedName]);
|
|
1189
|
+
}
|
|
1190
|
+
hasAttributes() {
|
|
1191
|
+
return this.attributes.length > 0;
|
|
1192
|
+
}
|
|
1193
|
+
get focus() {
|
|
1194
|
+
return function () {
|
|
1195
|
+
this.setAttribute(FOCUS, true);
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
// 兼容 Vue3,详情请见:https://github.com/NervJS/taro/issues/10579
|
|
1199
|
+
set focus(value) {
|
|
1200
|
+
this.setAttribute(FOCUS, value);
|
|
1201
|
+
}
|
|
1202
|
+
blur() {
|
|
1203
|
+
this.setAttribute(FOCUS, false);
|
|
1204
|
+
}
|
|
1205
|
+
setAttribute(qualifiedName, value) {
|
|
1206
|
+
process.env.NODE_ENV !== 'production' && warn(isString(value) && value.length > PROPERTY_THRESHOLD, `元素 ${this.nodeName} 的 ${qualifiedName} 属性值数据量过大,可能会影响渲染性能。考虑降低图片转为 base64 的阈值或在 CSS 中使用 base64。`);
|
|
1207
|
+
const isPureView = this.nodeName === VIEW && !isHasExtractProp(this) && !this.isAnyEventBinded();
|
|
1208
|
+
if (qualifiedName !== STYLE) {
|
|
1209
|
+
MutationObserver.record({
|
|
1210
|
+
target: this,
|
|
1211
|
+
type: "attributes" /* MutationRecordType.ATTRIBUTES */,
|
|
1212
|
+
attributeName: qualifiedName,
|
|
1213
|
+
oldValue: this.getAttribute(qualifiedName)
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
switch (qualifiedName) {
|
|
1217
|
+
case STYLE:
|
|
1218
|
+
this.style.cssText = value;
|
|
1219
|
+
break;
|
|
1220
|
+
case ID:
|
|
1221
|
+
if (this.uid !== this.sid) {
|
|
1222
|
+
// eventSource[sid] 永远保留,直到组件卸载
|
|
1223
|
+
// eventSource[uid] 可变
|
|
1224
|
+
eventSource.delete(this.uid);
|
|
1225
|
+
}
|
|
1226
|
+
value = String(value);
|
|
1227
|
+
this.props[qualifiedName] = this.uid = value;
|
|
1228
|
+
eventSource.set(value, this);
|
|
1229
|
+
break;
|
|
1230
|
+
default:
|
|
1231
|
+
this.props[qualifiedName] = value;
|
|
1232
|
+
if (qualifiedName.startsWith('data-')) {
|
|
1233
|
+
if (this.dataset === EMPTY_OBJ) {
|
|
1234
|
+
this.dataset = Object.create(null);
|
|
1235
|
+
}
|
|
1236
|
+
this.dataset[toCamelCase(qualifiedName.replace(/^data-/, ''))] = value;
|
|
1237
|
+
}
|
|
1238
|
+
break;
|
|
1239
|
+
}
|
|
1240
|
+
// Serialization
|
|
1241
|
+
if (!this._root)
|
|
1242
|
+
return;
|
|
1243
|
+
const componentsAlias = getComponentsAlias();
|
|
1244
|
+
const _alias = componentsAlias[this.nodeName];
|
|
1245
|
+
const viewAlias = componentsAlias[VIEW]._num;
|
|
1246
|
+
const staticViewAlias = componentsAlias[STATIC_VIEW]._num;
|
|
1247
|
+
const catchViewAlias = componentsAlias[CATCH_VIEW]._num;
|
|
1248
|
+
const _path = this._path;
|
|
1249
|
+
qualifiedName = shortcutAttr(qualifiedName);
|
|
1250
|
+
const qualifiedNameInCamelCase = toCamelCase(qualifiedName);
|
|
1251
|
+
const payload = {
|
|
1252
|
+
path: `${_path}.${qualifiedNameInCamelCase}`,
|
|
1253
|
+
value: isFunction(value) ? () => value : value
|
|
1254
|
+
};
|
|
1255
|
+
hooks.call('modifySetAttrPayload', this, qualifiedName, payload, componentsAlias);
|
|
1256
|
+
if (_alias) {
|
|
1257
|
+
const qualifiedNameAlias = _alias[qualifiedNameInCamelCase] || qualifiedName;
|
|
1258
|
+
payload.path = `${_path}.${toCamelCase(qualifiedNameAlias)}`;
|
|
1259
|
+
}
|
|
1260
|
+
this.enqueueUpdate(payload);
|
|
1261
|
+
if (this.nodeName === VIEW) {
|
|
1262
|
+
if (qualifiedNameInCamelCase === CATCHMOVE) {
|
|
1263
|
+
// catchMove = true: catch-view
|
|
1264
|
+
// catchMove = false: view or static-view
|
|
1265
|
+
this.enqueueUpdate({
|
|
1266
|
+
path: `${_path}.${"nn" /* Shortcuts.NodeName */}`,
|
|
1267
|
+
value: value ? catchViewAlias : (this.isAnyEventBinded() ? viewAlias : staticViewAlias)
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
else if (isPureView && isHasExtractProp(this)) {
|
|
1271
|
+
// pure-view => static-view
|
|
1272
|
+
this.enqueueUpdate({
|
|
1273
|
+
path: `${_path}.${"nn" /* Shortcuts.NodeName */}`,
|
|
1274
|
+
value: staticViewAlias
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
removeAttribute(qualifiedName) {
|
|
1280
|
+
const isStaticView = this.nodeName === VIEW && isHasExtractProp(this) && !this.isAnyEventBinded();
|
|
1281
|
+
MutationObserver.record({
|
|
1282
|
+
target: this,
|
|
1283
|
+
type: "attributes" /* MutationRecordType.ATTRIBUTES */,
|
|
1284
|
+
attributeName: qualifiedName,
|
|
1285
|
+
oldValue: this.getAttribute(qualifiedName)
|
|
1286
|
+
});
|
|
1287
|
+
if (qualifiedName === STYLE) {
|
|
1288
|
+
this.style.cssText = '';
|
|
1289
|
+
}
|
|
1290
|
+
else {
|
|
1291
|
+
const isInterrupt = hooks.call('onRemoveAttribute', this, qualifiedName);
|
|
1292
|
+
if (isInterrupt) {
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
if (!this.props.hasOwnProperty(qualifiedName)) {
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
delete this.props[qualifiedName];
|
|
1299
|
+
}
|
|
1300
|
+
// Serialization
|
|
1301
|
+
if (!this._root)
|
|
1302
|
+
return;
|
|
1303
|
+
const componentsAlias = getComponentsAlias();
|
|
1304
|
+
const _alias = componentsAlias[this.nodeName];
|
|
1305
|
+
const viewAlias = componentsAlias[VIEW]._num;
|
|
1306
|
+
const staticViewAlias = componentsAlias[STATIC_VIEW]._num;
|
|
1307
|
+
const pureViewAlias = componentsAlias[PURE_VIEW]._num;
|
|
1308
|
+
const _path = this._path;
|
|
1309
|
+
qualifiedName = shortcutAttr(qualifiedName);
|
|
1310
|
+
const qualifiedNameInCamelCase = toCamelCase(qualifiedName);
|
|
1311
|
+
const payload = {
|
|
1312
|
+
path: `${_path}.${qualifiedNameInCamelCase}`,
|
|
1313
|
+
value: ''
|
|
1314
|
+
};
|
|
1315
|
+
hooks.call('modifyRmAttrPayload', this, qualifiedName, payload, componentsAlias);
|
|
1316
|
+
if (_alias) {
|
|
1317
|
+
const qualifiedNameAlias = _alias[qualifiedNameInCamelCase] || qualifiedName;
|
|
1318
|
+
payload.path = `${_path}.${toCamelCase(qualifiedNameAlias)}`;
|
|
1319
|
+
}
|
|
1320
|
+
this.enqueueUpdate(payload);
|
|
1321
|
+
if (this.nodeName === VIEW) {
|
|
1322
|
+
if (qualifiedNameInCamelCase === CATCHMOVE) {
|
|
1323
|
+
// catch-view => view or static-view or pure-view
|
|
1324
|
+
this.enqueueUpdate({
|
|
1325
|
+
path: `${_path}.${"nn" /* Shortcuts.NodeName */}`,
|
|
1326
|
+
value: this.isAnyEventBinded() ? viewAlias : (isHasExtractProp(this) ? staticViewAlias : pureViewAlias)
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
else if (isStaticView && !isHasExtractProp(this)) {
|
|
1330
|
+
// static-view => pure-view
|
|
1331
|
+
this.enqueueUpdate({
|
|
1332
|
+
path: `${_path}.${"nn" /* Shortcuts.NodeName */}`,
|
|
1333
|
+
value: pureViewAlias
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
getAttribute(qualifiedName) {
|
|
1339
|
+
const attr = qualifiedName === STYLE ? this.style.cssText : this.props[qualifiedName];
|
|
1340
|
+
return attr !== null && attr !== void 0 ? attr : '';
|
|
1341
|
+
}
|
|
1342
|
+
getElementsByTagName(tagName) {
|
|
1343
|
+
return treeToArray(this, (el) => {
|
|
1344
|
+
return el.nodeName === tagName || (tagName === '*' && this !== el);
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
getElementsByClassName(className) {
|
|
1348
|
+
return treeToArray(this, (el) => {
|
|
1349
|
+
const classList = el.classList;
|
|
1350
|
+
const classNames = className.trim().split(/\s+/);
|
|
1351
|
+
return classNames.every(c => classList.has(c));
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
dispatchEvent(event) {
|
|
1355
|
+
const cancelable = event.cancelable;
|
|
1356
|
+
const listeners = this.__handlers[event.type];
|
|
1357
|
+
if (!isArray(listeners)) {
|
|
1358
|
+
return false;
|
|
1359
|
+
}
|
|
1360
|
+
for (let i = listeners.length; i--;) {
|
|
1361
|
+
const listener = listeners[i];
|
|
1362
|
+
let result;
|
|
1363
|
+
if (listener._stop) {
|
|
1364
|
+
listener._stop = false;
|
|
1365
|
+
}
|
|
1366
|
+
else {
|
|
1367
|
+
hooks.call('modifyDispatchEvent', event, this);
|
|
1368
|
+
result = listener.call(this, event);
|
|
1369
|
+
}
|
|
1370
|
+
if ((result === false || event._end) && cancelable) {
|
|
1371
|
+
event.defaultPrevented = true;
|
|
1372
|
+
}
|
|
1373
|
+
if (!isUndefined(result) && event.mpEvent) {
|
|
1374
|
+
event.mpEvent[EVENT_CALLBACK_RESULT] = result;
|
|
1375
|
+
}
|
|
1376
|
+
if (event._end && event._stop) {
|
|
1377
|
+
break;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
if (event._stop) {
|
|
1381
|
+
this._stopPropagation(event);
|
|
1382
|
+
}
|
|
1383
|
+
else {
|
|
1384
|
+
event._stop = true;
|
|
1385
|
+
}
|
|
1386
|
+
return listeners != null;
|
|
1387
|
+
}
|
|
1388
|
+
addEventListener(type, handler, options) {
|
|
1389
|
+
const name = this.nodeName;
|
|
1390
|
+
const SPECIAL_NODES = hooks.call('getSpecialNodes');
|
|
1391
|
+
let sideEffect = true;
|
|
1392
|
+
if (isObject(options) && options.sideEffect === false) {
|
|
1393
|
+
sideEffect = false;
|
|
1394
|
+
delete options.sideEffect;
|
|
1395
|
+
}
|
|
1396
|
+
if (sideEffect !== false && !this.isAnyEventBinded() && SPECIAL_NODES.indexOf(name) > -1) {
|
|
1397
|
+
const componentsAlias = getComponentsAlias();
|
|
1398
|
+
const alias = componentsAlias[name]._num;
|
|
1399
|
+
this.enqueueUpdate({
|
|
1400
|
+
path: `${this._path}.${"nn" /* Shortcuts.NodeName */}`,
|
|
1401
|
+
value: alias
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
super.addEventListener(type, handler, options);
|
|
1405
|
+
}
|
|
1406
|
+
removeEventListener(type, handler, sideEffect = true) {
|
|
1407
|
+
super.removeEventListener(type, handler);
|
|
1408
|
+
const name = this.nodeName;
|
|
1409
|
+
const SPECIAL_NODES = hooks.call('getSpecialNodes');
|
|
1410
|
+
if (sideEffect !== false && !this.isAnyEventBinded() && SPECIAL_NODES.indexOf(name) > -1) {
|
|
1411
|
+
const componentsAlias = getComponentsAlias();
|
|
1412
|
+
const value = isHasExtractProp(this) ? `static-${name}` : `pure-${name}`;
|
|
1413
|
+
const valueAlias = componentsAlias[value]._num;
|
|
1414
|
+
this.enqueueUpdate({
|
|
1415
|
+
path: `${this._path}.${"nn" /* Shortcuts.NodeName */}`,
|
|
1416
|
+
value: valueAlias
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
static extend(methodName, options) {
|
|
1421
|
+
extend(TaroElement, methodName, options);
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
const options = {
|
|
1426
|
+
prerender: true,
|
|
1427
|
+
debug: false
|
|
1428
|
+
};
|
|
1429
|
+
|
|
1430
|
+
function initPosition() {
|
|
1431
|
+
return {
|
|
1432
|
+
index: 0,
|
|
1433
|
+
column: 0,
|
|
1434
|
+
line: 0
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
function feedPosition(position, str, len) {
|
|
1438
|
+
const start = position.index;
|
|
1439
|
+
const end = position.index = start + len;
|
|
1440
|
+
for (let i = start; i < end; i++) {
|
|
1441
|
+
const char = str.charAt(i);
|
|
1442
|
+
if (char === '\n') {
|
|
1443
|
+
position.line++;
|
|
1444
|
+
position.column = 0;
|
|
1445
|
+
}
|
|
1446
|
+
else {
|
|
1447
|
+
position.column++;
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
function jumpPosition(position, str, end) {
|
|
1452
|
+
const len = end - position.index;
|
|
1453
|
+
return feedPosition(position, str, len);
|
|
1454
|
+
}
|
|
1455
|
+
function copyPosition(position) {
|
|
1456
|
+
return {
|
|
1457
|
+
index: position.index,
|
|
1458
|
+
line: position.line,
|
|
1459
|
+
column: position.column
|
|
1460
|
+
};
|
|
1461
|
+
}
|
|
1462
|
+
const whitespace = /\s/;
|
|
1463
|
+
function isWhitespaceChar(char) {
|
|
1464
|
+
return whitespace.test(char);
|
|
1465
|
+
}
|
|
1466
|
+
const equalSign = /=/;
|
|
1467
|
+
function isEqualSignChar(char) {
|
|
1468
|
+
return equalSign.test(char);
|
|
1469
|
+
}
|
|
1470
|
+
function shouldBeIgnore(tagName) {
|
|
1471
|
+
const name = tagName.toLowerCase();
|
|
1472
|
+
if (options.html.skipElements.has(name)) {
|
|
1473
|
+
return true;
|
|
1474
|
+
}
|
|
1475
|
+
return false;
|
|
1476
|
+
}
|
|
1477
|
+
const alphanumeric = /[A-Za-z0-9]/;
|
|
1478
|
+
function findTextEnd(str, index) {
|
|
1479
|
+
while (true) {
|
|
1480
|
+
const textEnd = str.indexOf('<', index);
|
|
1481
|
+
if (textEnd === -1) {
|
|
1482
|
+
return textEnd;
|
|
1483
|
+
}
|
|
1484
|
+
const char = str.charAt(textEnd + 1);
|
|
1485
|
+
if (char === '/' || char === '!' || alphanumeric.test(char)) {
|
|
1486
|
+
return textEnd;
|
|
1487
|
+
}
|
|
1488
|
+
index = textEnd + 1;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
function isWordEnd(cursor, wordBegin, html) {
|
|
1492
|
+
if (!isWhitespaceChar(html.charAt(cursor)))
|
|
1493
|
+
return false;
|
|
1494
|
+
const len = html.length;
|
|
1495
|
+
// backwrad
|
|
1496
|
+
for (let i = cursor - 1; i > wordBegin; i--) {
|
|
1497
|
+
const char = html.charAt(i);
|
|
1498
|
+
if (!isWhitespaceChar(char)) {
|
|
1499
|
+
if (isEqualSignChar(char))
|
|
1500
|
+
return false;
|
|
1501
|
+
break;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
// forward
|
|
1505
|
+
for (let i = cursor + 1; i < len; i++) {
|
|
1506
|
+
const char = html.charAt(i);
|
|
1507
|
+
if (!isWhitespaceChar(char)) {
|
|
1508
|
+
if (isEqualSignChar(char))
|
|
1509
|
+
return false;
|
|
1510
|
+
return true;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
class Scaner {
|
|
1515
|
+
constructor(html) {
|
|
1516
|
+
this.tokens = [];
|
|
1517
|
+
this.position = initPosition();
|
|
1518
|
+
this.html = html;
|
|
1519
|
+
}
|
|
1520
|
+
scan() {
|
|
1521
|
+
const { html, position } = this;
|
|
1522
|
+
const len = html.length;
|
|
1523
|
+
while (position.index < len) {
|
|
1524
|
+
const start = position.index;
|
|
1525
|
+
this.scanText();
|
|
1526
|
+
if (position.index === start) {
|
|
1527
|
+
const isComment = html.startsWith('!--', start + 1);
|
|
1528
|
+
if (isComment) {
|
|
1529
|
+
this.scanComment();
|
|
1530
|
+
}
|
|
1531
|
+
else {
|
|
1532
|
+
const tagName = this.scanTag();
|
|
1533
|
+
if (shouldBeIgnore(tagName)) {
|
|
1534
|
+
this.scanSkipTag(tagName);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
return this.tokens;
|
|
1540
|
+
}
|
|
1541
|
+
scanText() {
|
|
1542
|
+
const type = 'text';
|
|
1543
|
+
const { html, position } = this;
|
|
1544
|
+
let textEnd = findTextEnd(html, position.index);
|
|
1545
|
+
if (textEnd === position.index) {
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
if (textEnd === -1) {
|
|
1549
|
+
textEnd = html.length;
|
|
1550
|
+
}
|
|
1551
|
+
const start = copyPosition(position);
|
|
1552
|
+
const content = html.slice(position.index, textEnd);
|
|
1553
|
+
jumpPosition(position, html, textEnd);
|
|
1554
|
+
const end = copyPosition(position);
|
|
1555
|
+
this.tokens.push({ type, content, position: { start, end } });
|
|
1556
|
+
}
|
|
1557
|
+
scanComment() {
|
|
1558
|
+
const type = 'comment';
|
|
1559
|
+
const { html, position } = this;
|
|
1560
|
+
const start = copyPosition(position);
|
|
1561
|
+
feedPosition(position, html, 4); // "<!--".length
|
|
1562
|
+
let contentEnd = html.indexOf('-->', position.index);
|
|
1563
|
+
let commentEnd = contentEnd + 3; // "-->".length
|
|
1564
|
+
if (contentEnd === -1) {
|
|
1565
|
+
contentEnd = commentEnd = html.length;
|
|
1566
|
+
}
|
|
1567
|
+
const content = html.slice(position.index, contentEnd);
|
|
1568
|
+
jumpPosition(position, html, commentEnd);
|
|
1569
|
+
this.tokens.push({
|
|
1570
|
+
type,
|
|
1571
|
+
content,
|
|
1572
|
+
position: {
|
|
1573
|
+
start,
|
|
1574
|
+
end: copyPosition(position)
|
|
1575
|
+
}
|
|
1576
|
+
});
|
|
1577
|
+
}
|
|
1578
|
+
scanTag() {
|
|
1579
|
+
this.scanTagStart();
|
|
1580
|
+
const tagName = this.scanTagName();
|
|
1581
|
+
this.scanAttrs();
|
|
1582
|
+
this.scanTagEnd();
|
|
1583
|
+
return tagName;
|
|
1584
|
+
}
|
|
1585
|
+
scanTagStart() {
|
|
1586
|
+
const type = 'tag-start';
|
|
1587
|
+
const { html, position } = this;
|
|
1588
|
+
const secondChar = html.charAt(position.index + 1);
|
|
1589
|
+
const close = secondChar === '/';
|
|
1590
|
+
const start = copyPosition(position);
|
|
1591
|
+
feedPosition(position, html, close ? 2 : 1);
|
|
1592
|
+
this.tokens.push({ type, close, position: { start } });
|
|
1593
|
+
}
|
|
1594
|
+
scanTagEnd() {
|
|
1595
|
+
const type = 'tag-end';
|
|
1596
|
+
const { html, position } = this;
|
|
1597
|
+
const firstChar = html.charAt(position.index);
|
|
1598
|
+
const close = firstChar === '/';
|
|
1599
|
+
feedPosition(position, html, close ? 2 : 1);
|
|
1600
|
+
const end = copyPosition(position);
|
|
1601
|
+
this.tokens.push({ type, close, position: { end } });
|
|
1602
|
+
}
|
|
1603
|
+
scanTagName() {
|
|
1604
|
+
const type = 'tag';
|
|
1605
|
+
const { html, position } = this;
|
|
1606
|
+
const len = html.length;
|
|
1607
|
+
let start = position.index;
|
|
1608
|
+
while (start < len) {
|
|
1609
|
+
const char = html.charAt(start);
|
|
1610
|
+
const isTagChar = !(isWhitespaceChar(char) || char === '/' || char === '>');
|
|
1611
|
+
if (isTagChar)
|
|
1612
|
+
break;
|
|
1613
|
+
start++;
|
|
1614
|
+
}
|
|
1615
|
+
let end = start + 1;
|
|
1616
|
+
while (end < len) {
|
|
1617
|
+
const char = html.charAt(end);
|
|
1618
|
+
const isTagChar = !(isWhitespaceChar(char) || char === '/' || char === '>');
|
|
1619
|
+
if (!isTagChar)
|
|
1620
|
+
break;
|
|
1621
|
+
end++;
|
|
1622
|
+
}
|
|
1623
|
+
jumpPosition(position, html, end);
|
|
1624
|
+
const tagName = html.slice(start, end);
|
|
1625
|
+
this.tokens.push({
|
|
1626
|
+
type,
|
|
1627
|
+
content: tagName
|
|
1628
|
+
});
|
|
1629
|
+
return tagName;
|
|
1630
|
+
}
|
|
1631
|
+
scanAttrs() {
|
|
1632
|
+
const { html, position, tokens } = this;
|
|
1633
|
+
let cursor = position.index;
|
|
1634
|
+
let quote = null; // null, single-, or double-quote
|
|
1635
|
+
let wordBegin = cursor; // index of word start
|
|
1636
|
+
const words = []; // "key", "key=value", "key='value'", etc
|
|
1637
|
+
const len = html.length;
|
|
1638
|
+
while (cursor < len) {
|
|
1639
|
+
const char = html.charAt(cursor);
|
|
1640
|
+
if (quote) {
|
|
1641
|
+
const isQuoteEnd = char === quote;
|
|
1642
|
+
if (isQuoteEnd) {
|
|
1643
|
+
quote = null;
|
|
1644
|
+
}
|
|
1645
|
+
cursor++;
|
|
1646
|
+
continue;
|
|
1647
|
+
}
|
|
1648
|
+
const isTagEnd = char === '/' || char === '>';
|
|
1649
|
+
if (isTagEnd) {
|
|
1650
|
+
if (cursor !== wordBegin) {
|
|
1651
|
+
words.push(html.slice(wordBegin, cursor));
|
|
1652
|
+
}
|
|
1653
|
+
break;
|
|
1654
|
+
}
|
|
1655
|
+
if (isWordEnd(cursor, wordBegin, html)) {
|
|
1656
|
+
if (cursor !== wordBegin) {
|
|
1657
|
+
words.push(html.slice(wordBegin, cursor));
|
|
1658
|
+
}
|
|
1659
|
+
wordBegin = cursor + 1;
|
|
1660
|
+
cursor++;
|
|
1661
|
+
continue;
|
|
1662
|
+
}
|
|
1663
|
+
const isQuoteStart = char === '\'' || char === '"';
|
|
1664
|
+
if (isQuoteStart) {
|
|
1665
|
+
quote = char;
|
|
1666
|
+
cursor++;
|
|
1667
|
+
continue;
|
|
1668
|
+
}
|
|
1669
|
+
cursor++;
|
|
1670
|
+
}
|
|
1671
|
+
jumpPosition(position, html, cursor);
|
|
1672
|
+
const wLen = words.length;
|
|
1673
|
+
const type = 'attribute';
|
|
1674
|
+
for (let i = 0; i < wLen; i++) {
|
|
1675
|
+
const word = words[i];
|
|
1676
|
+
const isNotPair = word.includes('=');
|
|
1677
|
+
if (isNotPair) {
|
|
1678
|
+
const secondWord = words[i + 1];
|
|
1679
|
+
if (secondWord && secondWord.startsWith('=')) {
|
|
1680
|
+
if (secondWord.length > 1) {
|
|
1681
|
+
const newWord = word + secondWord;
|
|
1682
|
+
tokens.push({ type, content: newWord });
|
|
1683
|
+
i += 1;
|
|
1684
|
+
continue;
|
|
1685
|
+
}
|
|
1686
|
+
const thirdWord = words[i + 2];
|
|
1687
|
+
i += 1;
|
|
1688
|
+
if (thirdWord) {
|
|
1689
|
+
const newWord = word + '=' + thirdWord;
|
|
1690
|
+
tokens.push({ type, content: newWord });
|
|
1691
|
+
i += 1;
|
|
1692
|
+
continue;
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
if (word.endsWith('=')) {
|
|
1697
|
+
const secondWord = words[i + 1];
|
|
1698
|
+
if (secondWord && !secondWord.includes('=')) {
|
|
1699
|
+
const newWord = word + secondWord;
|
|
1700
|
+
tokens.push({ type, content: newWord });
|
|
1701
|
+
i += 1;
|
|
1702
|
+
continue;
|
|
1703
|
+
}
|
|
1704
|
+
const newWord = word.slice(0, -1);
|
|
1705
|
+
tokens.push({ type, content: newWord });
|
|
1706
|
+
continue;
|
|
1707
|
+
}
|
|
1708
|
+
tokens.push({ type, content: word });
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
scanSkipTag(tagName) {
|
|
1712
|
+
const { html, position } = this;
|
|
1713
|
+
const safeTagName = tagName.toLowerCase();
|
|
1714
|
+
const len = html.length;
|
|
1715
|
+
while (position.index < len) {
|
|
1716
|
+
const nextTag = html.indexOf('</', position.index);
|
|
1717
|
+
if (nextTag === -1) {
|
|
1718
|
+
this.scanText();
|
|
1719
|
+
break;
|
|
1720
|
+
}
|
|
1721
|
+
jumpPosition(position, html, nextTag);
|
|
1722
|
+
const name = this.scanTag();
|
|
1723
|
+
if (safeTagName === name.toLowerCase()) {
|
|
1724
|
+
break;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
function unquote(str) {
|
|
1731
|
+
const car = str.charAt(0);
|
|
1732
|
+
const end = str.length - 1;
|
|
1733
|
+
const isQuoteStart = car === '"' || car === "'";
|
|
1734
|
+
if (isQuoteStart && car === str.charAt(end)) {
|
|
1735
|
+
return str.slice(1, end);
|
|
1736
|
+
}
|
|
1737
|
+
return str;
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
const LEFT_BRACKET = '{';
|
|
1741
|
+
const RIGHT_BRACKET = '}';
|
|
1742
|
+
const CLASS_SELECTOR = '.';
|
|
1743
|
+
const ID_SELECTOR = '#';
|
|
1744
|
+
const CHILD_COMBINATOR = '>';
|
|
1745
|
+
const GENERAL_SIBLING_COMBINATOR = '~';
|
|
1746
|
+
const ADJACENT_SIBLING_COMBINATOR = '+';
|
|
1747
|
+
class StyleTagParser {
|
|
1748
|
+
constructor() {
|
|
1749
|
+
this.styles = [];
|
|
1750
|
+
}
|
|
1751
|
+
extractStyle(src) {
|
|
1752
|
+
const REG_STYLE = /<style\s?[^>]*>((.|\n|\s)+?)<\/style>/g;
|
|
1753
|
+
let html = src;
|
|
1754
|
+
// let html = src.replace(/\n/g, '')
|
|
1755
|
+
html = html.replace(REG_STYLE, (_, $1) => {
|
|
1756
|
+
const style = $1.trim();
|
|
1757
|
+
this.stringToSelector(style);
|
|
1758
|
+
return '';
|
|
1759
|
+
});
|
|
1760
|
+
return html.trim();
|
|
1761
|
+
}
|
|
1762
|
+
stringToSelector(style) {
|
|
1763
|
+
let lb = style.indexOf(LEFT_BRACKET);
|
|
1764
|
+
while (lb > -1) {
|
|
1765
|
+
const rb = style.indexOf(RIGHT_BRACKET);
|
|
1766
|
+
const selectors = style.slice(0, lb).trim();
|
|
1767
|
+
let content = style.slice(lb + 1, rb);
|
|
1768
|
+
content = content.replace(/:(.*);/g, function (_, $1) {
|
|
1769
|
+
const t = $1.trim().replace(/ +/g, '+++');
|
|
1770
|
+
return `:${t};`;
|
|
1771
|
+
});
|
|
1772
|
+
content = content.replace(/ /g, '');
|
|
1773
|
+
content = content.replace(/\+\+\+/g, ' ');
|
|
1774
|
+
if (!(/;$/.test(content))) {
|
|
1775
|
+
content += ';';
|
|
1776
|
+
}
|
|
1777
|
+
selectors.split(',').forEach(src => {
|
|
1778
|
+
const selectorList = this.parseSelector(src);
|
|
1779
|
+
this.styles.push({
|
|
1780
|
+
content,
|
|
1781
|
+
selectorList
|
|
1782
|
+
});
|
|
1783
|
+
});
|
|
1784
|
+
style = style.slice(rb + 1);
|
|
1785
|
+
lb = style.indexOf(LEFT_BRACKET);
|
|
1786
|
+
}
|
|
1787
|
+
// console.log('res this.styles: ', this.styles)
|
|
1788
|
+
}
|
|
1789
|
+
parseSelector(src) {
|
|
1790
|
+
const list = src
|
|
1791
|
+
.trim()
|
|
1792
|
+
.replace(/ *([>~+]) */g, ' $1')
|
|
1793
|
+
.replace(/ +/g, ' ')
|
|
1794
|
+
.replace(/\[\s*([^[\]=\s]+)\s*=\s*([^[\]=\s]+)\s*\]/g, '[$1=$2]')
|
|
1795
|
+
.split(' ');
|
|
1796
|
+
const selectors = list.map(item => {
|
|
1797
|
+
const firstChar = item.charAt(0);
|
|
1798
|
+
const selector = {
|
|
1799
|
+
isChild: firstChar === CHILD_COMBINATOR,
|
|
1800
|
+
isGeneralSibling: firstChar === GENERAL_SIBLING_COMBINATOR,
|
|
1801
|
+
isAdjacentSibling: firstChar === ADJACENT_SIBLING_COMBINATOR,
|
|
1802
|
+
tag: null,
|
|
1803
|
+
id: null,
|
|
1804
|
+
class: [],
|
|
1805
|
+
attrs: []
|
|
1806
|
+
};
|
|
1807
|
+
item = item.replace(/^[>~+]/, '');
|
|
1808
|
+
// 属性选择器
|
|
1809
|
+
item = item.replace(/\[(.+?)\]/g, function (_, $1) {
|
|
1810
|
+
const [key, value] = $1.split('=');
|
|
1811
|
+
const all = $1.indexOf('=') === -1;
|
|
1812
|
+
const attr = {
|
|
1813
|
+
all,
|
|
1814
|
+
key,
|
|
1815
|
+
value: all ? null : value
|
|
1816
|
+
};
|
|
1817
|
+
selector.attrs.push(attr);
|
|
1818
|
+
return '';
|
|
1819
|
+
});
|
|
1820
|
+
item = item.replace(/([.#][A-Za-z0-9-_]+)/g, function (_, $1) {
|
|
1821
|
+
if ($1[0] === ID_SELECTOR) {
|
|
1822
|
+
// id 选择器
|
|
1823
|
+
selector.id = $1.substr(1);
|
|
1824
|
+
}
|
|
1825
|
+
else if ($1[0] === CLASS_SELECTOR) {
|
|
1826
|
+
// class 选择器
|
|
1827
|
+
selector.class.push($1.substr(1));
|
|
1828
|
+
}
|
|
1829
|
+
return '';
|
|
1830
|
+
});
|
|
1831
|
+
// 标签选择器
|
|
1832
|
+
if (item !== '') {
|
|
1833
|
+
selector.tag = item;
|
|
1834
|
+
}
|
|
1835
|
+
return selector;
|
|
1836
|
+
});
|
|
1837
|
+
return selectors;
|
|
1838
|
+
}
|
|
1839
|
+
matchStyle(tagName, el, list) {
|
|
1840
|
+
const res = sortStyles(this.styles).reduce((str, { content, selectorList }, i) => {
|
|
1841
|
+
let idx = list[i];
|
|
1842
|
+
let selector = selectorList[idx];
|
|
1843
|
+
const nextSelector = selectorList[idx + 1];
|
|
1844
|
+
if ((nextSelector === null || nextSelector === void 0 ? void 0 : nextSelector.isGeneralSibling) || (nextSelector === null || nextSelector === void 0 ? void 0 : nextSelector.isAdjacentSibling)) {
|
|
1845
|
+
selector = nextSelector;
|
|
1846
|
+
idx += 1;
|
|
1847
|
+
list[i] += 1;
|
|
1848
|
+
}
|
|
1849
|
+
let isMatch = this.matchCurrent(tagName, el, selector);
|
|
1850
|
+
if (isMatch && selector.isGeneralSibling) {
|
|
1851
|
+
let prev = getPreviousElement(el);
|
|
1852
|
+
while (prev) {
|
|
1853
|
+
if (prev.h5tagName && this.matchCurrent(prev.h5tagName, prev, selectorList[idx - 1])) {
|
|
1854
|
+
isMatch = true;
|
|
1855
|
+
break;
|
|
1856
|
+
}
|
|
1857
|
+
prev = getPreviousElement(prev);
|
|
1858
|
+
isMatch = false;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
if (isMatch && selector.isAdjacentSibling) {
|
|
1862
|
+
const prev = getPreviousElement(el);
|
|
1863
|
+
if (!prev || !prev.h5tagName) {
|
|
1864
|
+
isMatch = false;
|
|
1865
|
+
}
|
|
1866
|
+
else {
|
|
1867
|
+
const isSiblingMatch = this.matchCurrent(prev.h5tagName, prev, selectorList[idx - 1]);
|
|
1868
|
+
if (!isSiblingMatch) {
|
|
1869
|
+
isMatch = false;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
if (isMatch) {
|
|
1874
|
+
if (idx === selectorList.length - 1) {
|
|
1875
|
+
return str + content;
|
|
1876
|
+
}
|
|
1877
|
+
else if (idx < selectorList.length - 1) {
|
|
1878
|
+
list[i] += 1;
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
else {
|
|
1882
|
+
// 直接子代组合器: >
|
|
1883
|
+
if (selector.isChild && idx > 0) {
|
|
1884
|
+
list[i] -= 1;
|
|
1885
|
+
if (this.matchCurrent(tagName, el, selectorList[list[i]])) {
|
|
1886
|
+
list[i] += 1;
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
return str;
|
|
1891
|
+
}, '');
|
|
1892
|
+
return res;
|
|
1893
|
+
}
|
|
1894
|
+
matchCurrent(tagName, el, selector) {
|
|
1895
|
+
// 标签选择器
|
|
1896
|
+
if (selector.tag && selector.tag !== tagName)
|
|
1897
|
+
return false;
|
|
1898
|
+
// id 选择器
|
|
1899
|
+
if (selector.id && selector.id !== el.id)
|
|
1900
|
+
return false;
|
|
1901
|
+
// class 选择器
|
|
1902
|
+
if (selector.class.length) {
|
|
1903
|
+
const classList = el.className.split(' ');
|
|
1904
|
+
for (let i = 0; i < selector.class.length; i++) {
|
|
1905
|
+
const cls = selector.class[i];
|
|
1906
|
+
if (classList.indexOf(cls) === -1) {
|
|
1907
|
+
return false;
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
// 属性选择器
|
|
1912
|
+
if (selector.attrs.length) {
|
|
1913
|
+
for (let i = 0; i < selector.attrs.length; i++) {
|
|
1914
|
+
const { all, key, value } = selector.attrs[i];
|
|
1915
|
+
if (all && !el.hasAttribute(key)) {
|
|
1916
|
+
return false;
|
|
1917
|
+
}
|
|
1918
|
+
else {
|
|
1919
|
+
const attr = el.getAttribute(key);
|
|
1920
|
+
if (attr !== unquote(value || '')) {
|
|
1921
|
+
return false;
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
return true;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
function getPreviousElement(el) {
|
|
1930
|
+
const parent = el.parentElement;
|
|
1931
|
+
if (!parent)
|
|
1932
|
+
return null;
|
|
1933
|
+
const prev = el.previousSibling;
|
|
1934
|
+
if (!prev)
|
|
1935
|
+
return null;
|
|
1936
|
+
if (prev.nodeType === 1 /* NodeType.ELEMENT_NODE */) {
|
|
1937
|
+
return prev;
|
|
1938
|
+
}
|
|
1939
|
+
else {
|
|
1940
|
+
return getPreviousElement(prev);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
// 根据 css selector 权重排序: 权重大的靠后
|
|
1944
|
+
// @WARN 不考虑伪类
|
|
1945
|
+
// https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance#specificity_2
|
|
1946
|
+
function sortStyles(styles) {
|
|
1947
|
+
return styles.sort((s1, s2) => {
|
|
1948
|
+
const hundreds1 = getHundredsWeight(s1.selectorList);
|
|
1949
|
+
const hundreds2 = getHundredsWeight(s2.selectorList);
|
|
1950
|
+
if (hundreds1 !== hundreds2)
|
|
1951
|
+
return hundreds1 - hundreds2;
|
|
1952
|
+
const tens1 = getTensWeight(s1.selectorList);
|
|
1953
|
+
const tens2 = getTensWeight(s2.selectorList);
|
|
1954
|
+
if (tens1 !== tens2)
|
|
1955
|
+
return tens1 - tens2;
|
|
1956
|
+
const ones1 = getOnesWeight(s1.selectorList);
|
|
1957
|
+
const ones2 = getOnesWeight(s2.selectorList);
|
|
1958
|
+
return ones1 - ones2;
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
function getHundredsWeight(selectors) {
|
|
1962
|
+
return selectors.reduce((pre, cur) => pre + (cur.id ? 1 : 0), 0);
|
|
1963
|
+
}
|
|
1964
|
+
function getTensWeight(selectors) {
|
|
1965
|
+
return selectors.reduce((pre, cur) => pre + cur.class.length + cur.attrs.length, 0);
|
|
1966
|
+
}
|
|
1967
|
+
function getOnesWeight(selectors) {
|
|
1968
|
+
return selectors.reduce((pre, cur) => pre + (cur.tag ? 1 : 0), 0);
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
function makeMap(str, expectsLowerCase) {
|
|
1972
|
+
const map = Object.create(null);
|
|
1973
|
+
const list = str.split(',');
|
|
1974
|
+
for (let i = 0; i < list.length; i++) {
|
|
1975
|
+
map[list[i]] = true;
|
|
1976
|
+
}
|
|
1977
|
+
return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
|
|
1978
|
+
}
|
|
1979
|
+
const specialMiniElements = {
|
|
1980
|
+
img: 'image',
|
|
1981
|
+
iframe: 'web-view'
|
|
1982
|
+
};
|
|
1983
|
+
const internalCompsList = Object.keys(internalComponents)
|
|
1984
|
+
.map(i => i.toLowerCase())
|
|
1985
|
+
.join(',');
|
|
1986
|
+
// https://developers.weixin.qq.com/miniprogram/dev/component
|
|
1987
|
+
const isMiniElements = makeMap(internalCompsList, true);
|
|
1988
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
|
|
1989
|
+
const isInlineElements = makeMap('a,i,abbr,iframe,select,acronym,slot,small,span,bdi,kbd,strong,big,map,sub,sup,br,mark,mark,meter,template,canvas,textarea,cite,object,time,code,output,u,data,picture,tt,datalist,var,dfn,del,q,em,s,embed,samp,b', true);
|
|
1990
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
|
|
1991
|
+
const isBlockElements = makeMap('address,fieldset,li,article,figcaption,main,aside,figure,nav,blockquote,footer,ol,details,form,p,dialog,h1,h2,h3,h4,h5,h6,pre,dd,header,section,div,hgroup,table,dl,hr,ul,dt', true);
|
|
1992
|
+
|
|
1993
|
+
const closingTagAncestorBreakers = {
|
|
1994
|
+
li: ['ul', 'ol', 'menu'],
|
|
1995
|
+
dt: ['dl'],
|
|
1996
|
+
dd: ['dl'],
|
|
1997
|
+
tbody: ['table'],
|
|
1998
|
+
thead: ['table'],
|
|
1999
|
+
tfoot: ['table'],
|
|
2000
|
+
tr: ['table'],
|
|
2001
|
+
td: ['table']
|
|
2002
|
+
};
|
|
2003
|
+
function hasTerminalParent(tagName, stack) {
|
|
2004
|
+
const tagParents = closingTagAncestorBreakers[tagName];
|
|
2005
|
+
if (tagParents) {
|
|
2006
|
+
let currentIndex = stack.length - 1;
|
|
2007
|
+
while (currentIndex >= 0) {
|
|
2008
|
+
const parentTagName = stack[currentIndex].tagName;
|
|
2009
|
+
if (parentTagName === tagName) {
|
|
2010
|
+
break;
|
|
2011
|
+
}
|
|
2012
|
+
if (tagParents && tagParents.includes(parentTagName)) {
|
|
2013
|
+
return true;
|
|
2014
|
+
}
|
|
2015
|
+
currentIndex--;
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
return false;
|
|
2019
|
+
}
|
|
2020
|
+
function getTagName(tag) {
|
|
2021
|
+
if (options.html.renderHTMLTag) {
|
|
2022
|
+
return tag;
|
|
2023
|
+
}
|
|
2024
|
+
if (specialMiniElements[tag]) {
|
|
2025
|
+
return specialMiniElements[tag];
|
|
2026
|
+
}
|
|
2027
|
+
else if (isMiniElements(tag)) {
|
|
2028
|
+
return tag;
|
|
2029
|
+
}
|
|
2030
|
+
else if (isBlockElements(tag)) {
|
|
2031
|
+
return 'view';
|
|
2032
|
+
}
|
|
2033
|
+
else if (isInlineElements(tag)) {
|
|
2034
|
+
return 'text';
|
|
2035
|
+
}
|
|
2036
|
+
return 'view';
|
|
2037
|
+
}
|
|
2038
|
+
function splitEqual(str) {
|
|
2039
|
+
const sep = '=';
|
|
2040
|
+
const idx = str.indexOf(sep);
|
|
2041
|
+
if (idx === -1)
|
|
2042
|
+
return [str];
|
|
2043
|
+
const key = str.slice(0, idx).trim();
|
|
2044
|
+
const value = str.slice(idx + sep.length).trim();
|
|
2045
|
+
return [key, value];
|
|
2046
|
+
}
|
|
2047
|
+
function format(children, document, styleOptions, parent) {
|
|
2048
|
+
return children
|
|
2049
|
+
.filter(child => {
|
|
2050
|
+
// 过滤注释和空文本节点
|
|
2051
|
+
if (child.type === 'comment') {
|
|
2052
|
+
return false;
|
|
2053
|
+
}
|
|
2054
|
+
else if (child.type === 'text') {
|
|
2055
|
+
return child.content !== '';
|
|
2056
|
+
}
|
|
2057
|
+
return true;
|
|
2058
|
+
})
|
|
2059
|
+
.map((child) => {
|
|
2060
|
+
// 文本节点
|
|
2061
|
+
if (child.type === 'text') {
|
|
2062
|
+
let text = document.createTextNode(child.content);
|
|
2063
|
+
if (isFunction(options.html.transformText)) {
|
|
2064
|
+
text = options.html.transformText(text, child);
|
|
2065
|
+
}
|
|
2066
|
+
parent === null || parent === void 0 ? void 0 : parent.appendChild(text);
|
|
2067
|
+
return text;
|
|
2068
|
+
}
|
|
2069
|
+
const el = document.createElement(getTagName(child.tagName));
|
|
2070
|
+
el.h5tagName = child.tagName;
|
|
2071
|
+
parent === null || parent === void 0 ? void 0 : parent.appendChild(el);
|
|
2072
|
+
if (!options.html.renderHTMLTag) {
|
|
2073
|
+
el.className = `h5-${child.tagName}`;
|
|
2074
|
+
}
|
|
2075
|
+
for (let i = 0; i < child.attributes.length; i++) {
|
|
2076
|
+
const attr = child.attributes[i];
|
|
2077
|
+
const [key, value] = splitEqual(attr);
|
|
2078
|
+
if (key === 'class') {
|
|
2079
|
+
el.className += ' ' + unquote(value);
|
|
2080
|
+
}
|
|
2081
|
+
else if (key[0] === 'o' && key[1] === 'n') {
|
|
2082
|
+
continue;
|
|
2083
|
+
}
|
|
2084
|
+
else {
|
|
2085
|
+
el.setAttribute(key, value == null ? true : unquote(value));
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
const { styleTagParser, descendantList } = styleOptions;
|
|
2089
|
+
const list = descendantList.slice();
|
|
2090
|
+
const style = styleTagParser.matchStyle(child.tagName, el, list);
|
|
2091
|
+
el.setAttribute('style', style + el.style.cssText);
|
|
2092
|
+
// console.log('style, ', style)
|
|
2093
|
+
format(child.children, document, {
|
|
2094
|
+
styleTagParser,
|
|
2095
|
+
descendantList: list
|
|
2096
|
+
}, el);
|
|
2097
|
+
if (isFunction(options.html.transformElement)) {
|
|
2098
|
+
return options.html.transformElement(el, child);
|
|
2099
|
+
}
|
|
2100
|
+
return el;
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
function parser(html, document) {
|
|
2104
|
+
const styleTagParser = new StyleTagParser();
|
|
2105
|
+
html = styleTagParser.extractStyle(html);
|
|
2106
|
+
const tokens = new Scaner(html).scan();
|
|
2107
|
+
const root = { tagName: '', children: [], type: 'element', attributes: [] };
|
|
2108
|
+
const state = { tokens, options, cursor: 0, stack: [root] };
|
|
2109
|
+
parse(state);
|
|
2110
|
+
return format(root.children, document, {
|
|
2111
|
+
styleTagParser,
|
|
2112
|
+
descendantList: Array(styleTagParser.styles.length).fill(0)
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
function parse(state) {
|
|
2116
|
+
const { tokens, stack } = state;
|
|
2117
|
+
let { cursor } = state;
|
|
2118
|
+
const len = tokens.length;
|
|
2119
|
+
let nodes = stack[stack.length - 1].children;
|
|
2120
|
+
while (cursor < len) {
|
|
2121
|
+
const token = tokens[cursor];
|
|
2122
|
+
if (token.type !== 'tag-start') {
|
|
2123
|
+
// comment or text
|
|
2124
|
+
nodes.push(token);
|
|
2125
|
+
cursor++;
|
|
2126
|
+
continue;
|
|
2127
|
+
}
|
|
2128
|
+
const tagToken = tokens[++cursor];
|
|
2129
|
+
cursor++;
|
|
2130
|
+
const tagName = tagToken.content.toLowerCase();
|
|
2131
|
+
if (token.close) {
|
|
2132
|
+
let index = stack.length;
|
|
2133
|
+
let shouldRewind = false;
|
|
2134
|
+
while (--index > -1) {
|
|
2135
|
+
if (stack[index].tagName === tagName) {
|
|
2136
|
+
shouldRewind = true;
|
|
2137
|
+
break;
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
while (cursor < len) {
|
|
2141
|
+
const endToken = tokens[cursor];
|
|
2142
|
+
if (endToken.type !== 'tag-end')
|
|
2143
|
+
break;
|
|
2144
|
+
cursor++;
|
|
2145
|
+
}
|
|
2146
|
+
if (shouldRewind) {
|
|
2147
|
+
stack.splice(index);
|
|
2148
|
+
break;
|
|
2149
|
+
}
|
|
2150
|
+
else {
|
|
2151
|
+
continue;
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
const isClosingTag = options.html.closingElements.has(tagName);
|
|
2155
|
+
let shouldRewindToAutoClose = isClosingTag;
|
|
2156
|
+
if (shouldRewindToAutoClose) {
|
|
2157
|
+
shouldRewindToAutoClose = !hasTerminalParent(tagName, stack);
|
|
2158
|
+
}
|
|
2159
|
+
if (shouldRewindToAutoClose) {
|
|
2160
|
+
let currentIndex = stack.length - 1;
|
|
2161
|
+
while (currentIndex > 0) {
|
|
2162
|
+
if (tagName === stack[currentIndex].tagName) {
|
|
2163
|
+
stack.splice(currentIndex);
|
|
2164
|
+
const previousIndex = currentIndex - 1;
|
|
2165
|
+
nodes = stack[previousIndex].children;
|
|
2166
|
+
break;
|
|
2167
|
+
}
|
|
2168
|
+
currentIndex = currentIndex - 1;
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
const attributes = [];
|
|
2172
|
+
let attrToken;
|
|
2173
|
+
while (cursor < len) {
|
|
2174
|
+
attrToken = tokens[cursor];
|
|
2175
|
+
if (attrToken.type === 'tag-end')
|
|
2176
|
+
break;
|
|
2177
|
+
attributes.push(attrToken.content);
|
|
2178
|
+
cursor++;
|
|
2179
|
+
}
|
|
2180
|
+
cursor++;
|
|
2181
|
+
const children = [];
|
|
2182
|
+
const element = {
|
|
2183
|
+
type: 'element',
|
|
2184
|
+
tagName: tagToken.content,
|
|
2185
|
+
attributes,
|
|
2186
|
+
children
|
|
2187
|
+
};
|
|
2188
|
+
nodes.push(element);
|
|
2189
|
+
const hasChildren = !(attrToken.close || options.html.voidElements.has(tagName));
|
|
2190
|
+
if (hasChildren) {
|
|
2191
|
+
stack.push({ tagName, children });
|
|
2192
|
+
const innerState = { tokens, cursor, stack };
|
|
2193
|
+
parse(innerState);
|
|
2194
|
+
cursor = innerState.cursor;
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
state.cursor = cursor;
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
options.html = {
|
|
2201
|
+
skipElements: new Set(['style', 'script']),
|
|
2202
|
+
voidElements: new Set([
|
|
2203
|
+
'!doctype', 'area', 'base', 'br', 'col', 'command',
|
|
2204
|
+
'embed', 'hr', 'img', 'input', 'keygen', 'link',
|
|
2205
|
+
'meta', 'param', 'source', 'track', 'wbr'
|
|
2206
|
+
]),
|
|
2207
|
+
closingElements: new Set([
|
|
2208
|
+
'html', 'head', 'body', 'p', 'dt', 'dd', 'li', 'option',
|
|
2209
|
+
'thead', 'th', 'tbody', 'tr', 'td', 'tfoot', 'colgroup'
|
|
2210
|
+
]),
|
|
2211
|
+
renderHTMLTag: false
|
|
2212
|
+
};
|
|
2213
|
+
function setInnerHTML(element, html) {
|
|
2214
|
+
while (element.firstChild) {
|
|
2215
|
+
element.removeChild(element.firstChild);
|
|
2216
|
+
}
|
|
2217
|
+
const children = parser(html, element.ownerDocument);
|
|
2218
|
+
for (let i = 0; i < children.length; i++) {
|
|
2219
|
+
element.appendChild(children[i]);
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
function getBoundingClientRectImpl() {
|
|
2224
|
+
if (!options.miniGlobal)
|
|
2225
|
+
return Promise.resolve(null);
|
|
2226
|
+
return new Promise(resolve => {
|
|
2227
|
+
const query = options.miniGlobal.createSelectorQuery();
|
|
2228
|
+
query.select(`#${this.uid}`).boundingClientRect(res => {
|
|
2229
|
+
resolve(res);
|
|
2230
|
+
}).exec();
|
|
2231
|
+
});
|
|
2232
|
+
}
|
|
2233
|
+
function getTemplateContent(ctx) {
|
|
2234
|
+
if (ctx.nodeName === 'template') {
|
|
2235
|
+
const document = ctx.ownerDocument;
|
|
2236
|
+
const content = document.createElement(DOCUMENT_FRAGMENT);
|
|
2237
|
+
content.childNodes = ctx.childNodes;
|
|
2238
|
+
ctx.childNodes = [content];
|
|
2239
|
+
content.parentNode = ctx;
|
|
2240
|
+
content.childNodes.forEach(nodes => {
|
|
2241
|
+
nodes.parentNode = content;
|
|
2242
|
+
});
|
|
2243
|
+
return content;
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
/**
|
|
2248
|
+
* An implementation of `Element.insertAdjacentHTML()`
|
|
2249
|
+
* to support Vue 3 with a version of or greater than `vue@3.1.2`
|
|
2250
|
+
*/
|
|
2251
|
+
function insertAdjacentHTML(position, html) {
|
|
2252
|
+
var _a, _b;
|
|
2253
|
+
const parsedNodes = parser(html, this.ownerDocument);
|
|
2254
|
+
for (let i = 0; i < parsedNodes.length; i++) {
|
|
2255
|
+
const n = parsedNodes[i];
|
|
2256
|
+
switch (position) {
|
|
2257
|
+
case 'beforebegin':
|
|
2258
|
+
(_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(n, this);
|
|
2259
|
+
break;
|
|
2260
|
+
case 'afterbegin':
|
|
2261
|
+
if (this.hasChildNodes()) {
|
|
2262
|
+
this.insertBefore(n, this.childNodes[0]);
|
|
2263
|
+
}
|
|
2264
|
+
else {
|
|
2265
|
+
this.appendChild(n);
|
|
2266
|
+
}
|
|
2267
|
+
break;
|
|
2268
|
+
case 'beforeend':
|
|
2269
|
+
this.appendChild(n);
|
|
2270
|
+
break;
|
|
2271
|
+
case 'afterend':
|
|
2272
|
+
(_b = this.parentNode) === null || _b === void 0 ? void 0 : _b.appendChild(n);
|
|
2273
|
+
break;
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
function cloneNode(isDeep = false) {
|
|
2278
|
+
const document = this.ownerDocument;
|
|
2279
|
+
let newNode;
|
|
2280
|
+
if (this.nodeType === 1 /* NodeType.ELEMENT_NODE */) {
|
|
2281
|
+
newNode = document.createElement(this.nodeName);
|
|
2282
|
+
}
|
|
2283
|
+
else if (this.nodeType === 3 /* NodeType.TEXT_NODE */) {
|
|
2284
|
+
newNode = document.createTextNode('');
|
|
2285
|
+
}
|
|
2286
|
+
for (const key in this) {
|
|
2287
|
+
const value = this[key];
|
|
2288
|
+
if ([PROPS, DATASET].includes(key) && typeof value === OBJECT) {
|
|
2289
|
+
newNode[key] = Object.assign({}, value);
|
|
2290
|
+
}
|
|
2291
|
+
else if (key === '_value') {
|
|
2292
|
+
newNode[key] = value;
|
|
2293
|
+
}
|
|
2294
|
+
else if (key === STYLE) {
|
|
2295
|
+
newNode.style._value = Object.assign({}, value._value);
|
|
2296
|
+
newNode.style._usedStyleProp = new Set(Array.from(value._usedStyleProp));
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
if (isDeep) {
|
|
2300
|
+
newNode.childNodes = this.childNodes.map(node => node.cloneNode(true));
|
|
2301
|
+
}
|
|
2302
|
+
return newNode;
|
|
2303
|
+
}
|
|
2304
|
+
function contains(node) {
|
|
2305
|
+
let isContains = false;
|
|
2306
|
+
this.childNodes.some(childNode => {
|
|
2307
|
+
const { uid } = childNode;
|
|
2308
|
+
if (uid === node.uid || uid === node.id || childNode.contains(node)) {
|
|
2309
|
+
isContains = true;
|
|
2310
|
+
return true;
|
|
2311
|
+
}
|
|
2312
|
+
});
|
|
2313
|
+
return isContains;
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
if (!isWebPlatform()) {
|
|
2317
|
+
if (ENABLE_INNER_HTML) {
|
|
2318
|
+
TaroNode.extend('innerHTML', {
|
|
2319
|
+
set(html) {
|
|
2320
|
+
setInnerHTML.call(this, this, html);
|
|
2321
|
+
},
|
|
2322
|
+
get() {
|
|
2323
|
+
return '';
|
|
2324
|
+
}
|
|
2325
|
+
});
|
|
2326
|
+
if (ENABLE_ADJACENT_HTML) {
|
|
2327
|
+
TaroNode.extend('insertAdjacentHTML', insertAdjacentHTML);
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
if (ENABLE_CLONE_NODE) {
|
|
2331
|
+
TaroNode.extend('cloneNode', cloneNode);
|
|
2332
|
+
}
|
|
2333
|
+
if (ENABLE_CONTAINS) {
|
|
2334
|
+
TaroNode.extend('contains', contains);
|
|
2335
|
+
}
|
|
2336
|
+
if (ENABLE_SIZE_APIS) {
|
|
2337
|
+
TaroElement.extend('getBoundingClientRect', getBoundingClientRectImpl);
|
|
2338
|
+
}
|
|
2339
|
+
if (ENABLE_TEMPLATE_CONTENT) {
|
|
2340
|
+
TaroElement.extend('content', {
|
|
2341
|
+
get() {
|
|
2342
|
+
return getTemplateContent(this);
|
|
2343
|
+
}
|
|
2344
|
+
});
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2348
|
+
// Taro 事件对象。以 Web 标准的事件对象为基础,加入小程序事件对象中携带的部分信息,并模拟实现事件冒泡。
|
|
2349
|
+
class TaroEvent {
|
|
2350
|
+
constructor(type, opts, event) {
|
|
2351
|
+
this._stop = false;
|
|
2352
|
+
this._end = false;
|
|
2353
|
+
this.defaultPrevented = false;
|
|
2354
|
+
// Mouse Event botton property, it's used in 3rd lib, like react-router. default 0 in general
|
|
2355
|
+
this.button = 0;
|
|
2356
|
+
// timestamp can either be hi-res ( relative to page load) or low-res (relative to UNIX epoch)
|
|
2357
|
+
// here use hi-res timestamp
|
|
2358
|
+
this.timeStamp = Date.now();
|
|
2359
|
+
this.type = type.toLowerCase();
|
|
2360
|
+
this.mpEvent = event;
|
|
2361
|
+
this.bubbles = Boolean(opts && opts.bubbles);
|
|
2362
|
+
this.cancelable = Boolean(opts && opts.cancelable);
|
|
2363
|
+
}
|
|
2364
|
+
stopPropagation() {
|
|
2365
|
+
this._stop = true;
|
|
2366
|
+
}
|
|
2367
|
+
stopImmediatePropagation() {
|
|
2368
|
+
this._end = this._stop = true;
|
|
2369
|
+
}
|
|
2370
|
+
preventDefault() {
|
|
2371
|
+
this.defaultPrevented = true;
|
|
2372
|
+
}
|
|
2373
|
+
get target() {
|
|
2374
|
+
var _a, _b;
|
|
2375
|
+
const cacheTarget = this.cacheTarget;
|
|
2376
|
+
if (!cacheTarget) {
|
|
2377
|
+
const target = Object.create(((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.target) || null);
|
|
2378
|
+
const element = env.document.getElementById(target.id);
|
|
2379
|
+
target.dataset = element !== null ? element.dataset : EMPTY_OBJ;
|
|
2380
|
+
for (const key in (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.detail) {
|
|
2381
|
+
target[key] = this.mpEvent.detail[key];
|
|
2382
|
+
}
|
|
2383
|
+
this.cacheTarget = target;
|
|
2384
|
+
return target;
|
|
2385
|
+
}
|
|
2386
|
+
else {
|
|
2387
|
+
return cacheTarget;
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
get currentTarget() {
|
|
2391
|
+
var _a, _b, _c, _d;
|
|
2392
|
+
const cacheCurrentTarget = this.cacheCurrentTarget;
|
|
2393
|
+
if (!cacheCurrentTarget) {
|
|
2394
|
+
const doc = env.document;
|
|
2395
|
+
const currentTarget = Object.create(((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.currentTarget) || null);
|
|
2396
|
+
const element = doc.getElementById(currentTarget.id);
|
|
2397
|
+
const targetElement = doc.getElementById(((_c = (_b = this.mpEvent) === null || _b === void 0 ? void 0 : _b.target) === null || _c === void 0 ? void 0 : _c.id) || null);
|
|
2398
|
+
if (element === null || (element && element === targetElement)) {
|
|
2399
|
+
this.cacheCurrentTarget = this.target;
|
|
2400
|
+
return this.target;
|
|
2401
|
+
}
|
|
2402
|
+
currentTarget.dataset = element.dataset;
|
|
2403
|
+
for (const key in (_d = this.mpEvent) === null || _d === void 0 ? void 0 : _d.detail) {
|
|
2404
|
+
currentTarget[key] = this.mpEvent.detail[key];
|
|
2405
|
+
}
|
|
2406
|
+
this.cacheCurrentTarget = currentTarget;
|
|
2407
|
+
return currentTarget;
|
|
2408
|
+
}
|
|
2409
|
+
else {
|
|
2410
|
+
return cacheCurrentTarget;
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
function createEvent(event, node) {
|
|
2415
|
+
if (typeof event === 'string') {
|
|
2416
|
+
// For Vue3 using document.createEvent
|
|
2417
|
+
return new TaroEvent(event, { bubbles: true, cancelable: true });
|
|
2418
|
+
}
|
|
2419
|
+
const domEv = new TaroEvent(event.type, { bubbles: true, cancelable: true }, event);
|
|
2420
|
+
for (const key in event) {
|
|
2421
|
+
if (key === CURRENT_TARGET || key === TARGET || key === TYPE || key === TIME_STAMP) {
|
|
2422
|
+
continue;
|
|
2423
|
+
}
|
|
2424
|
+
else {
|
|
2425
|
+
domEv[key] = event[key];
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
if (domEv.type === CONFIRM && (node === null || node === void 0 ? void 0 : node.nodeName) === INPUT) {
|
|
2429
|
+
// eslint-disable-next-line dot-notation
|
|
2430
|
+
domEv[KEY_CODE] = 13;
|
|
2431
|
+
}
|
|
2432
|
+
return domEv;
|
|
2433
|
+
}
|
|
2434
|
+
const eventsBatch = {};
|
|
2435
|
+
function getEventCBResult(event) {
|
|
2436
|
+
const result = event[EVENT_CALLBACK_RESULT];
|
|
2437
|
+
if (!isUndefined(result)) {
|
|
2438
|
+
delete event[EVENT_CALLBACK_RESULT];
|
|
2439
|
+
}
|
|
2440
|
+
return result;
|
|
2441
|
+
}
|
|
2442
|
+
// 小程序的事件代理回调函数
|
|
2443
|
+
function eventHandler(event) {
|
|
2444
|
+
var _a, _b;
|
|
2445
|
+
// Note: ohos 上事件没有设置 type、detail 类型 setter 方法,且部分事件(例如 load 等)缺失 target 导致事件错误
|
|
2446
|
+
event.type === undefined && Object.defineProperty(event, 'type', {
|
|
2447
|
+
value: event._type // ohos only
|
|
2448
|
+
});
|
|
2449
|
+
event.detail === undefined && Object.defineProperty(event, 'detail', {
|
|
2450
|
+
value: event._detail || Object.assign({}, event) // ohos only
|
|
2451
|
+
});
|
|
2452
|
+
event.currentTarget = event.currentTarget || event.target || Object.assign({}, event);
|
|
2453
|
+
hooks.call('modifyMpEventImpl', event);
|
|
2454
|
+
const currentTarget = event.currentTarget;
|
|
2455
|
+
const id = ((_a = currentTarget.dataset) === null || _a === void 0 ? void 0 : _a.sid /** sid */) || currentTarget.id /** uid */ || ((_b = event.detail) === null || _b === void 0 ? void 0 : _b.id) || '';
|
|
2456
|
+
const node = env.document.getElementById(id);
|
|
2457
|
+
if (node) {
|
|
2458
|
+
const dispatch = () => {
|
|
2459
|
+
const e = createEvent(event, node);
|
|
2460
|
+
hooks.call('modifyTaroEvent', e, node);
|
|
2461
|
+
node.dispatchEvent(e);
|
|
2462
|
+
};
|
|
2463
|
+
if (hooks.isExist('batchedEventUpdates')) {
|
|
2464
|
+
const type = event.type;
|
|
2465
|
+
if (!hooks.call('isBubbleEvents', type) ||
|
|
2466
|
+
!isParentBinded(node, type) ||
|
|
2467
|
+
(type === TOUCHMOVE && !!node.props.catchMove)) {
|
|
2468
|
+
// 最上层组件统一 batchUpdate
|
|
2469
|
+
hooks.call('batchedEventUpdates', () => {
|
|
2470
|
+
if (eventsBatch[type]) {
|
|
2471
|
+
eventsBatch[type].forEach(fn => fn());
|
|
2472
|
+
delete eventsBatch[type];
|
|
2473
|
+
}
|
|
2474
|
+
dispatch();
|
|
2475
|
+
});
|
|
2476
|
+
return getEventCBResult(event);
|
|
2477
|
+
}
|
|
2478
|
+
else {
|
|
2479
|
+
// 如果上层组件也有绑定同类型的组件,委托给上层组件调用事件回调
|
|
2480
|
+
(eventsBatch[type] || (eventsBatch[type] = [])).push(dispatch);
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
else {
|
|
2484
|
+
dispatch();
|
|
2485
|
+
return getEventCBResult(event);
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
|
|
2490
|
+
class FormElement extends TaroElement {
|
|
2491
|
+
get value() {
|
|
2492
|
+
// eslint-disable-next-line dot-notation
|
|
2493
|
+
const val = this.props[VALUE];
|
|
2494
|
+
return val == null ? '' : val;
|
|
2495
|
+
}
|
|
2496
|
+
set value(val) {
|
|
2497
|
+
this.setAttribute(VALUE, val);
|
|
2498
|
+
}
|
|
2499
|
+
dispatchEvent(event) {
|
|
2500
|
+
if (event.mpEvent) {
|
|
2501
|
+
const val = event.mpEvent.detail.value;
|
|
2502
|
+
if (event.type === CHANGE) {
|
|
2503
|
+
this.props.value = val;
|
|
2504
|
+
}
|
|
2505
|
+
else if (event.type === INPUT) {
|
|
2506
|
+
// Web 规范中表单组件的 value 应该跟着输入改变
|
|
2507
|
+
// 只是改 this.props.value 的话不会进行 setData,因此这里修改 this.value。
|
|
2508
|
+
// 只测试了 React、Vue、Vue3 input 组件的 onInput 事件,onChange 事件不确定有没有副作用,所以暂不修改。
|
|
2509
|
+
this.value = val;
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
return super.dispatchEvent(event);
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
class Performance {
|
|
2517
|
+
constructor() {
|
|
2518
|
+
this.recorder = new Map();
|
|
2519
|
+
}
|
|
2520
|
+
start(id) {
|
|
2521
|
+
if (!options.debug) {
|
|
2522
|
+
return;
|
|
2523
|
+
}
|
|
2524
|
+
this.recorder.set(id, Date.now());
|
|
2525
|
+
}
|
|
2526
|
+
stop(id) {
|
|
2527
|
+
if (!options.debug) {
|
|
2528
|
+
return;
|
|
2529
|
+
}
|
|
2530
|
+
const now = Date.now();
|
|
2531
|
+
const prev = this.recorder.get(id);
|
|
2532
|
+
this.recorder.delete(id);
|
|
2533
|
+
const time = now - prev;
|
|
2534
|
+
// eslint-disable-next-line no-console
|
|
2535
|
+
console.log(`${id} 时长: ${time}ms`);
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
const perf = new Performance();
|
|
2539
|
+
|
|
2540
|
+
function findCustomWrapper(root, dataPathArr) {
|
|
2541
|
+
// ['root', 'cn', '[0]'] remove 'root' => ['cn', '[0]']
|
|
2542
|
+
const list = dataPathArr.slice(1);
|
|
2543
|
+
let currentData = root;
|
|
2544
|
+
let customWrapper;
|
|
2545
|
+
let splitedPath = '';
|
|
2546
|
+
list.some((item, i) => {
|
|
2547
|
+
const key = item
|
|
2548
|
+
// '[0]' => '0'
|
|
2549
|
+
.replace(/^\[(.+)\]$/, '$1')
|
|
2550
|
+
// 'cn' => 'childNodes'
|
|
2551
|
+
.replace(/\bcn\b/g, 'childNodes');
|
|
2552
|
+
currentData = currentData[key];
|
|
2553
|
+
if (isArray(currentData)) {
|
|
2554
|
+
currentData = currentData.filter(el => !isComment(el));
|
|
2555
|
+
}
|
|
2556
|
+
if (isUndefined(currentData))
|
|
2557
|
+
return true;
|
|
2558
|
+
if (currentData.nodeName === CUSTOM_WRAPPER) {
|
|
2559
|
+
const res = customWrapperCache.get(currentData.sid);
|
|
2560
|
+
if (res) {
|
|
2561
|
+
customWrapper = res;
|
|
2562
|
+
splitedPath = dataPathArr.slice(i + 2).join('.');
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
});
|
|
2566
|
+
if (customWrapper) {
|
|
2567
|
+
return {
|
|
2568
|
+
customWrapper,
|
|
2569
|
+
splitedPath
|
|
2570
|
+
};
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
class TaroRootElement extends TaroElement {
|
|
2574
|
+
constructor() {
|
|
2575
|
+
super();
|
|
2576
|
+
this.updatePayloads = [];
|
|
2577
|
+
this.updateCallbacks = [];
|
|
2578
|
+
this.pendingUpdate = false;
|
|
2579
|
+
this.ctx = null;
|
|
2580
|
+
this.nodeName = ROOT_STR;
|
|
2581
|
+
this.tagName = ROOT_STR.toUpperCase();
|
|
2582
|
+
}
|
|
2583
|
+
get _path() {
|
|
2584
|
+
return ROOT_STR;
|
|
2585
|
+
}
|
|
2586
|
+
get _root() {
|
|
2587
|
+
return this;
|
|
2588
|
+
}
|
|
2589
|
+
enqueueUpdate(payload) {
|
|
2590
|
+
this.updatePayloads.push(payload);
|
|
2591
|
+
if (!this.pendingUpdate && this.ctx) {
|
|
2592
|
+
this.performUpdate();
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
performUpdate(initRender = false, prerender) {
|
|
2596
|
+
this.pendingUpdate = true;
|
|
2597
|
+
const ctx = this.ctx;
|
|
2598
|
+
setTimeout(() => {
|
|
2599
|
+
const setDataMark = `${SET_DATA} 开始时间戳 ${Date.now()}`;
|
|
2600
|
+
perf.start(setDataMark);
|
|
2601
|
+
const data = Object.create(null);
|
|
2602
|
+
const resetPaths = new Set(initRender
|
|
2603
|
+
? ['root.cn.[0]', 'root.cn[0]']
|
|
2604
|
+
: []);
|
|
2605
|
+
while (this.updatePayloads.length > 0) {
|
|
2606
|
+
const { path, value } = this.updatePayloads.shift();
|
|
2607
|
+
if (path.endsWith("cn" /* Shortcuts.Childnodes */)) {
|
|
2608
|
+
resetPaths.add(path);
|
|
2609
|
+
}
|
|
2610
|
+
data[path] = value;
|
|
2611
|
+
}
|
|
2612
|
+
for (const path in data) {
|
|
2613
|
+
resetPaths.forEach(p => {
|
|
2614
|
+
// 已经重置了数组,就不需要分别再设置了
|
|
2615
|
+
if (path.includes(p) && path !== p) {
|
|
2616
|
+
delete data[path];
|
|
2617
|
+
}
|
|
2618
|
+
});
|
|
2619
|
+
const value = data[path];
|
|
2620
|
+
if (isFunction(value)) {
|
|
2621
|
+
data[path] = value();
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
// 预渲染
|
|
2625
|
+
if (isFunction(prerender))
|
|
2626
|
+
return prerender(data);
|
|
2627
|
+
// 正常渲染
|
|
2628
|
+
this.pendingUpdate = false;
|
|
2629
|
+
let normalUpdate = {};
|
|
2630
|
+
const customWrapperMap = new Map();
|
|
2631
|
+
if (initRender) {
|
|
2632
|
+
// 初次渲染,使用页面级别的 setData
|
|
2633
|
+
normalUpdate = data;
|
|
2634
|
+
}
|
|
2635
|
+
else {
|
|
2636
|
+
// 更新渲染,区分 CustomWrapper 与页面级别的 setData
|
|
2637
|
+
for (const p in data) {
|
|
2638
|
+
const dataPathArr = p.split('.');
|
|
2639
|
+
const found = findCustomWrapper(this, dataPathArr);
|
|
2640
|
+
if (found) {
|
|
2641
|
+
// 此项数据使用 CustomWrapper 去更新
|
|
2642
|
+
const { customWrapper, splitedPath } = found;
|
|
2643
|
+
// 合并同一个 customWrapper 的相关更新到一次 setData 中
|
|
2644
|
+
customWrapperMap.set(customWrapper, Object.assign(Object.assign({}, (customWrapperMap.get(customWrapper) || {})), { [`i.${splitedPath}`]: data[p] }));
|
|
2645
|
+
}
|
|
2646
|
+
else {
|
|
2647
|
+
// 此项数据使用页面去更新
|
|
2648
|
+
normalUpdate[p] = data[p];
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
const customWrapperCount = customWrapperMap.size;
|
|
2653
|
+
const isNeedNormalUpdate = Object.keys(normalUpdate).length > 0;
|
|
2654
|
+
const updateArrLen = customWrapperCount + (isNeedNormalUpdate ? 1 : 0);
|
|
2655
|
+
let executeTime = 0;
|
|
2656
|
+
const cb = () => {
|
|
2657
|
+
if (++executeTime === updateArrLen) {
|
|
2658
|
+
perf.stop(setDataMark);
|
|
2659
|
+
this.flushUpdateCallback();
|
|
2660
|
+
initRender && perf.stop(PAGE_INIT);
|
|
2661
|
+
}
|
|
2662
|
+
};
|
|
2663
|
+
// custom-wrapper setData
|
|
2664
|
+
if (customWrapperCount) {
|
|
2665
|
+
customWrapperMap.forEach((data, ctx) => {
|
|
2666
|
+
if (process.env.NODE_ENV !== 'production' && options.debug) {
|
|
2667
|
+
// eslint-disable-next-line no-console
|
|
2668
|
+
console.log('custom wrapper setData: ', data);
|
|
2669
|
+
}
|
|
2670
|
+
ctx.setData(data, cb);
|
|
2671
|
+
});
|
|
2672
|
+
}
|
|
2673
|
+
// page setData
|
|
2674
|
+
if (isNeedNormalUpdate) {
|
|
2675
|
+
if (process.env.NODE_ENV !== 'production' && options.debug) {
|
|
2676
|
+
// eslint-disable-next-line no-console
|
|
2677
|
+
console.log('page setData:', normalUpdate);
|
|
2678
|
+
}
|
|
2679
|
+
ctx.setData(normalUpdate, cb);
|
|
2680
|
+
}
|
|
2681
|
+
}, 0);
|
|
2682
|
+
}
|
|
2683
|
+
enqueueUpdateCallback(cb, ctx) {
|
|
2684
|
+
this.updateCallbacks.push(() => {
|
|
2685
|
+
ctx ? cb.call(ctx) : cb();
|
|
2686
|
+
});
|
|
2687
|
+
}
|
|
2688
|
+
flushUpdateCallback() {
|
|
2689
|
+
const updateCallbacks = this.updateCallbacks;
|
|
2690
|
+
if (!updateCallbacks.length)
|
|
2691
|
+
return;
|
|
2692
|
+
const copies = updateCallbacks.slice(0);
|
|
2693
|
+
this.updateCallbacks.length = 0;
|
|
2694
|
+
for (let i = 0; i < copies.length; i++) {
|
|
2695
|
+
copies[i]();
|
|
2696
|
+
}
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
class TaroText extends TaroNode {
|
|
2701
|
+
constructor(value) {
|
|
2702
|
+
super();
|
|
2703
|
+
this.nodeType = 3 /* NodeType.TEXT_NODE */;
|
|
2704
|
+
this.nodeName = '#text';
|
|
2705
|
+
this._value = value;
|
|
2706
|
+
}
|
|
2707
|
+
set textContent(text) {
|
|
2708
|
+
MutationObserver.record({
|
|
2709
|
+
target: this,
|
|
2710
|
+
type: "characterData" /* MutationRecordType.CHARACTER_DATA */,
|
|
2711
|
+
oldValue: this._value
|
|
2712
|
+
});
|
|
2713
|
+
this._value = text;
|
|
2714
|
+
this.enqueueUpdate({
|
|
2715
|
+
path: `${this._path}.${"v" /* Shortcuts.Text */}`,
|
|
2716
|
+
value: text
|
|
2717
|
+
});
|
|
2718
|
+
}
|
|
2719
|
+
get textContent() {
|
|
2720
|
+
return this._value;
|
|
2721
|
+
}
|
|
2722
|
+
set nodeValue(text) {
|
|
2723
|
+
this.textContent = text;
|
|
2724
|
+
}
|
|
2725
|
+
get nodeValue() {
|
|
2726
|
+
return this._value;
|
|
2727
|
+
}
|
|
2728
|
+
set data(text) {
|
|
2729
|
+
this.textContent = text;
|
|
2730
|
+
}
|
|
2731
|
+
get data() {
|
|
2732
|
+
return this._value;
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
/******************************************************************************
|
|
2737
|
+
Copyright (c) Microsoft Corporation.
|
|
2738
|
+
|
|
2739
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
2740
|
+
purpose with or without fee is hereby granted.
|
|
2741
|
+
|
|
2742
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
2743
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
2744
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
2745
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
2746
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
2747
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
2748
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
2749
|
+
***************************************************************************** */
|
|
2750
|
+
|
|
2751
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
2752
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
2753
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
2754
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
2755
|
+
}
|
|
2756
|
+
|
|
2757
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
2758
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
2759
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
2760
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
2761
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
2762
|
+
}
|
|
2763
|
+
|
|
2764
|
+
var _URLSearchParams_dict;
|
|
2765
|
+
const findReg = /[!'()~]|%20|%00/g;
|
|
2766
|
+
const plusReg = /\+/g;
|
|
2767
|
+
const replaceCharMap = {
|
|
2768
|
+
'!': '%21',
|
|
2769
|
+
"'": '%27',
|
|
2770
|
+
'(': '%28',
|
|
2771
|
+
')': '%29',
|
|
2772
|
+
'~': '%7E',
|
|
2773
|
+
'%20': '+',
|
|
2774
|
+
'%00': '\x00',
|
|
2775
|
+
};
|
|
2776
|
+
function replacer(match) {
|
|
2777
|
+
return replaceCharMap[match];
|
|
2778
|
+
}
|
|
2779
|
+
function appendTo(dict, name, value) {
|
|
2780
|
+
const res = isArray(value) ? value.join(',') : value;
|
|
2781
|
+
if (name in dict)
|
|
2782
|
+
dict[name].push(res);
|
|
2783
|
+
else
|
|
2784
|
+
dict[name] = [res];
|
|
2785
|
+
}
|
|
2786
|
+
function addEach(value, key) {
|
|
2787
|
+
appendTo(this, key, value);
|
|
2788
|
+
}
|
|
2789
|
+
function decode(str) {
|
|
2790
|
+
return decodeURIComponent(str.replace(plusReg, ' '));
|
|
2791
|
+
}
|
|
2792
|
+
function encode(str) {
|
|
2793
|
+
return encodeURIComponent(str).replace(findReg, replacer);
|
|
2794
|
+
}
|
|
2795
|
+
class URLSearchParams {
|
|
2796
|
+
constructor(query) {
|
|
2797
|
+
_URLSearchParams_dict.set(this, Object.create(null));
|
|
2798
|
+
if (!query)
|
|
2799
|
+
return;
|
|
2800
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2801
|
+
if (typeof query === 'string') {
|
|
2802
|
+
if (query.charAt(0) === '?') {
|
|
2803
|
+
query = query.slice(1);
|
|
2804
|
+
}
|
|
2805
|
+
for (let pairs = query.split('&'), i = 0, length = pairs.length; i < length; i++) {
|
|
2806
|
+
const value = pairs[i];
|
|
2807
|
+
const index = value.indexOf('=');
|
|
2808
|
+
if (index > -1) {
|
|
2809
|
+
appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));
|
|
2810
|
+
}
|
|
2811
|
+
else if (value.length) {
|
|
2812
|
+
appendTo(dict, decode(value), '');
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
else {
|
|
2817
|
+
if (isArray(query)) {
|
|
2818
|
+
for (let i = 0, length = query.length; i < length; i++) {
|
|
2819
|
+
const value = query[i];
|
|
2820
|
+
appendTo(dict, value[0], value[1]);
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
else if (query.forEach) {
|
|
2824
|
+
query.forEach(addEach, dict);
|
|
2825
|
+
}
|
|
2826
|
+
else {
|
|
2827
|
+
for (const key in query) {
|
|
2828
|
+
appendTo(dict, key, query[key]);
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
append(name, value) {
|
|
2834
|
+
appendTo(__classPrivateFieldGet(this, _URLSearchParams_dict, "f"), name, value);
|
|
2835
|
+
}
|
|
2836
|
+
delete(name) {
|
|
2837
|
+
delete __classPrivateFieldGet(this, _URLSearchParams_dict, "f")[name];
|
|
2838
|
+
}
|
|
2839
|
+
get(name) {
|
|
2840
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2841
|
+
return name in dict ? dict[name][0] : null;
|
|
2842
|
+
}
|
|
2843
|
+
getAll(name) {
|
|
2844
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2845
|
+
return name in dict ? dict[name].slice(0) : [];
|
|
2846
|
+
}
|
|
2847
|
+
has(name) {
|
|
2848
|
+
return name in __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2849
|
+
}
|
|
2850
|
+
keys() {
|
|
2851
|
+
return Object.keys(__classPrivateFieldGet(this, _URLSearchParams_dict, "f"));
|
|
2852
|
+
}
|
|
2853
|
+
set(name, value) {
|
|
2854
|
+
__classPrivateFieldGet(this, _URLSearchParams_dict, "f")[name] = ['' + value];
|
|
2855
|
+
}
|
|
2856
|
+
forEach(callback, thisArg) {
|
|
2857
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2858
|
+
Object.getOwnPropertyNames(dict).forEach(function (name) {
|
|
2859
|
+
dict[name].forEach(function (value) {
|
|
2860
|
+
callback.call(thisArg, value, name, this);
|
|
2861
|
+
}, this);
|
|
2862
|
+
}, this);
|
|
2863
|
+
}
|
|
2864
|
+
toJSON() {
|
|
2865
|
+
return {};
|
|
2866
|
+
}
|
|
2867
|
+
toString() {
|
|
2868
|
+
const dict = __classPrivateFieldGet(this, _URLSearchParams_dict, "f");
|
|
2869
|
+
const query = [];
|
|
2870
|
+
for (const key in dict) {
|
|
2871
|
+
const name = encode(key);
|
|
2872
|
+
for (let i = 0, value = dict[key]; i < value.length; i++) {
|
|
2873
|
+
query.push(name + '=' + encode(value[i]));
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
return query.join('&');
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2879
|
+
_URLSearchParams_dict = new WeakMap();
|
|
2880
|
+
|
|
2881
|
+
var _URL_hash, _URL_hostname, _URL_pathname, _URL_port, _URL_protocol, _URL_search;
|
|
2882
|
+
class URL {
|
|
2883
|
+
constructor(url, base) {
|
|
2884
|
+
/* private property */
|
|
2885
|
+
_URL_hash.set(this, '');
|
|
2886
|
+
_URL_hostname.set(this, '');
|
|
2887
|
+
_URL_pathname.set(this, '');
|
|
2888
|
+
_URL_port.set(this, '');
|
|
2889
|
+
_URL_protocol.set(this, '');
|
|
2890
|
+
_URL_search.set(this, '');
|
|
2891
|
+
if (!isString(url))
|
|
2892
|
+
url = String(url);
|
|
2893
|
+
const parseResult = parseUrlBase(url, base);
|
|
2894
|
+
const { hash, hostname, pathname, port, protocol, search } = parseResult;
|
|
2895
|
+
__classPrivateFieldSet(this, _URL_hash, hash, "f");
|
|
2896
|
+
__classPrivateFieldSet(this, _URL_hostname, hostname, "f");
|
|
2897
|
+
__classPrivateFieldSet(this, _URL_pathname, pathname || '/', "f");
|
|
2898
|
+
__classPrivateFieldSet(this, _URL_port, port, "f");
|
|
2899
|
+
__classPrivateFieldSet(this, _URL_protocol, protocol, "f");
|
|
2900
|
+
__classPrivateFieldSet(this, _URL_search, search, "f");
|
|
2901
|
+
}
|
|
2902
|
+
static createObjectURL() {
|
|
2903
|
+
throw new Error('Oops, not support URL.createObjectURL() in miniprogram.');
|
|
2904
|
+
}
|
|
2905
|
+
static revokeObjectURL() {
|
|
2906
|
+
throw new Error('Oops, not support URL.revokeObjectURL() in miniprogram.');
|
|
2907
|
+
}
|
|
2908
|
+
/* public property */
|
|
2909
|
+
get protocol() {
|
|
2910
|
+
return __classPrivateFieldGet(this, _URL_protocol, "f");
|
|
2911
|
+
}
|
|
2912
|
+
set protocol(val) {
|
|
2913
|
+
isString(val) && (__classPrivateFieldSet(this, _URL_protocol, val.trim(), "f"));
|
|
2914
|
+
}
|
|
2915
|
+
get host() {
|
|
2916
|
+
return this.hostname + (this.port ? ':' + this.port : '');
|
|
2917
|
+
}
|
|
2918
|
+
set host(val) {
|
|
2919
|
+
if (val && isString(val)) {
|
|
2920
|
+
val = val.trim();
|
|
2921
|
+
const { hostname, port } = parseUrl(`//${val}`);
|
|
2922
|
+
this.hostname = hostname;
|
|
2923
|
+
this.port = port;
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
get hostname() {
|
|
2927
|
+
return __classPrivateFieldGet(this, _URL_hostname, "f");
|
|
2928
|
+
}
|
|
2929
|
+
set hostname(val) {
|
|
2930
|
+
val && isString(val) && (__classPrivateFieldSet(this, _URL_hostname, val.trim(), "f"));
|
|
2931
|
+
}
|
|
2932
|
+
get port() {
|
|
2933
|
+
return __classPrivateFieldGet(this, _URL_port, "f");
|
|
2934
|
+
}
|
|
2935
|
+
set port(val) {
|
|
2936
|
+
isString(val) && (__classPrivateFieldSet(this, _URL_port, val.trim(), "f"));
|
|
2937
|
+
}
|
|
2938
|
+
get pathname() {
|
|
2939
|
+
return __classPrivateFieldGet(this, _URL_pathname, "f");
|
|
2940
|
+
}
|
|
2941
|
+
set pathname(val) {
|
|
2942
|
+
if (isString(val)) {
|
|
2943
|
+
val = val.trim();
|
|
2944
|
+
const HEAD_REG = /^(\/|\.\/|\.\.\/)/;
|
|
2945
|
+
let temp = val;
|
|
2946
|
+
while (HEAD_REG.test(temp)) {
|
|
2947
|
+
temp = temp.replace(HEAD_REG, '');
|
|
2948
|
+
}
|
|
2949
|
+
if (temp)
|
|
2950
|
+
__classPrivateFieldSet(this, _URL_pathname, '/' + temp, "f");
|
|
2951
|
+
else
|
|
2952
|
+
__classPrivateFieldSet(this, _URL_pathname, '/', "f");
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2955
|
+
get search() {
|
|
2956
|
+
return __classPrivateFieldGet(this, _URL_search, "f");
|
|
2957
|
+
}
|
|
2958
|
+
set search(val) {
|
|
2959
|
+
if (isString(val)) {
|
|
2960
|
+
val = val.trim();
|
|
2961
|
+
if (val)
|
|
2962
|
+
__classPrivateFieldSet(this, _URL_search, val.startsWith('?') ? val : `?${val}`, "f");
|
|
2963
|
+
else
|
|
2964
|
+
__classPrivateFieldSet(this, _URL_search, '', "f");
|
|
2965
|
+
}
|
|
2966
|
+
}
|
|
2967
|
+
get hash() {
|
|
2968
|
+
return __classPrivateFieldGet(this, _URL_hash, "f");
|
|
2969
|
+
}
|
|
2970
|
+
set hash(val) {
|
|
2971
|
+
if (isString(val)) {
|
|
2972
|
+
val = val.trim();
|
|
2973
|
+
if (val)
|
|
2974
|
+
__classPrivateFieldSet(this, _URL_hash, val.startsWith('#') ? val : `#${val}`, "f");
|
|
2975
|
+
else
|
|
2976
|
+
__classPrivateFieldSet(this, _URL_hash, '', "f");
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
get href() {
|
|
2980
|
+
return `${this.protocol}//${this.host}${this.pathname}${this.search}${this.hash}`;
|
|
2981
|
+
}
|
|
2982
|
+
set href(val) {
|
|
2983
|
+
if (val && isString(val)) {
|
|
2984
|
+
val = val.trim();
|
|
2985
|
+
const { protocol, hostname, port, hash, search, pathname } = parseUrl(val);
|
|
2986
|
+
this.protocol = protocol;
|
|
2987
|
+
this.hostname = hostname;
|
|
2988
|
+
this.pathname = pathname;
|
|
2989
|
+
this.port = port;
|
|
2990
|
+
this.hash = hash;
|
|
2991
|
+
this.search = search;
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
get origin() {
|
|
2995
|
+
return `${this.protocol}//${this.host}`;
|
|
2996
|
+
}
|
|
2997
|
+
set origin(val) {
|
|
2998
|
+
if (val && isString(val)) {
|
|
2999
|
+
val = val.trim();
|
|
3000
|
+
const { protocol, hostname, port } = parseUrl(val);
|
|
3001
|
+
this.protocol = protocol;
|
|
3002
|
+
this.hostname = hostname;
|
|
3003
|
+
this.port = port;
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
get searchParams() {
|
|
3007
|
+
return new URLSearchParams(this.search);
|
|
3008
|
+
}
|
|
3009
|
+
// public method
|
|
3010
|
+
toString() {
|
|
3011
|
+
return this.href;
|
|
3012
|
+
}
|
|
3013
|
+
toJSON() {
|
|
3014
|
+
return this.toString();
|
|
3015
|
+
}
|
|
3016
|
+
// convenient for deconstructor
|
|
3017
|
+
_toRaw() {
|
|
3018
|
+
return {
|
|
3019
|
+
protocol: this.protocol,
|
|
3020
|
+
port: this.port,
|
|
3021
|
+
host: this.host,
|
|
3022
|
+
hostname: this.hostname,
|
|
3023
|
+
pathname: this.pathname,
|
|
3024
|
+
hash: this.hash,
|
|
3025
|
+
search: this.search,
|
|
3026
|
+
origin: this.origin,
|
|
3027
|
+
href: this.href,
|
|
3028
|
+
};
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
3031
|
+
_URL_hash = new WeakMap(), _URL_hostname = new WeakMap(), _URL_pathname = new WeakMap(), _URL_port = new WeakMap(), _URL_protocol = new WeakMap(), _URL_search = new WeakMap();
|
|
3032
|
+
function parseUrl(url = '') {
|
|
3033
|
+
const result = {
|
|
3034
|
+
href: '',
|
|
3035
|
+
origin: '',
|
|
3036
|
+
protocol: '',
|
|
3037
|
+
hostname: '',
|
|
3038
|
+
host: '',
|
|
3039
|
+
port: '',
|
|
3040
|
+
pathname: '',
|
|
3041
|
+
search: '',
|
|
3042
|
+
hash: ''
|
|
3043
|
+
};
|
|
3044
|
+
if (!url || !isString(url))
|
|
3045
|
+
return result;
|
|
3046
|
+
url = url.trim();
|
|
3047
|
+
const PATTERN = /^(([^:/?#]+):)?\/\/(([^/?#]+):(.+)@)?([^/?#:]*)(:(\d+))?([^?#]*)(\?([^#]*))?(#(.*))?/;
|
|
3048
|
+
const matches = url.match(PATTERN);
|
|
3049
|
+
if (!matches)
|
|
3050
|
+
return result;
|
|
3051
|
+
// TODO: username & password ?
|
|
3052
|
+
result.protocol = matches[1] || 'https:';
|
|
3053
|
+
result.hostname = matches[6] || 'taro.com';
|
|
3054
|
+
result.port = matches[8] || '';
|
|
3055
|
+
result.pathname = matches[9] || '/';
|
|
3056
|
+
result.search = matches[10] || '';
|
|
3057
|
+
result.hash = matches[12] || '';
|
|
3058
|
+
result.href = url;
|
|
3059
|
+
result.origin = result.protocol + '//' + result.hostname;
|
|
3060
|
+
result.host = result.hostname + (result.port ? `:${result.port}` : '');
|
|
3061
|
+
return result;
|
|
3062
|
+
}
|
|
3063
|
+
function parseUrlBase(url, base) {
|
|
3064
|
+
const VALID_URL = /^(https?:)\/\//i;
|
|
3065
|
+
let fullUrl = '';
|
|
3066
|
+
let parsedBase = null;
|
|
3067
|
+
if (!isUndefined(base)) {
|
|
3068
|
+
base = String(base).trim();
|
|
3069
|
+
if (!VALID_URL.test(base))
|
|
3070
|
+
throw new TypeError(`Failed to construct 'URL': Invalid base URL`);
|
|
3071
|
+
parsedBase = parseUrl(base);
|
|
3072
|
+
}
|
|
3073
|
+
url = String(url).trim();
|
|
3074
|
+
if (VALID_URL.test(url)) {
|
|
3075
|
+
fullUrl = url;
|
|
3076
|
+
}
|
|
3077
|
+
else if (parsedBase) {
|
|
3078
|
+
if (url) {
|
|
3079
|
+
if (url.startsWith('//')) {
|
|
3080
|
+
fullUrl = parsedBase.protocol + url;
|
|
3081
|
+
}
|
|
3082
|
+
else {
|
|
3083
|
+
fullUrl = parsedBase.origin + (url.startsWith('/') ? url : `/${url}`);
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
else {
|
|
3087
|
+
fullUrl = parsedBase.href;
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
else {
|
|
3091
|
+
throw new TypeError(`Failed to construct 'URL': Invalid URL`);
|
|
3092
|
+
}
|
|
3093
|
+
return parseUrl(fullUrl);
|
|
3094
|
+
}
|
|
3095
|
+
|
|
3096
|
+
class AnchorElement extends TaroElement {
|
|
3097
|
+
get href() {
|
|
3098
|
+
var _a;
|
|
3099
|
+
return (_a = this.props["href" /* AnchorElementAttrs.HREF */]) !== null && _a !== void 0 ? _a : '';
|
|
3100
|
+
}
|
|
3101
|
+
set href(val) {
|
|
3102
|
+
this.setAttribute("href" /* AnchorElementAttrs.HREF */, val);
|
|
3103
|
+
}
|
|
3104
|
+
get protocol() {
|
|
3105
|
+
var _a;
|
|
3106
|
+
return (_a = this.props["protocol" /* AnchorElementAttrs.PROTOCOL */]) !== null && _a !== void 0 ? _a : '';
|
|
3107
|
+
}
|
|
3108
|
+
get host() {
|
|
3109
|
+
var _a;
|
|
3110
|
+
return (_a = this.props["host" /* AnchorElementAttrs.HOST */]) !== null && _a !== void 0 ? _a : '';
|
|
3111
|
+
}
|
|
3112
|
+
get search() {
|
|
3113
|
+
var _a;
|
|
3114
|
+
return (_a = this.props["search" /* AnchorElementAttrs.SEARCH */]) !== null && _a !== void 0 ? _a : '';
|
|
3115
|
+
}
|
|
3116
|
+
get hash() {
|
|
3117
|
+
var _a;
|
|
3118
|
+
return (_a = this.props["hash" /* AnchorElementAttrs.HASH */]) !== null && _a !== void 0 ? _a : '';
|
|
3119
|
+
}
|
|
3120
|
+
get hostname() {
|
|
3121
|
+
var _a;
|
|
3122
|
+
return (_a = this.props["hostname" /* AnchorElementAttrs.HOSTNAME */]) !== null && _a !== void 0 ? _a : '';
|
|
3123
|
+
}
|
|
3124
|
+
get port() {
|
|
3125
|
+
var _a;
|
|
3126
|
+
return (_a = this.props["port" /* AnchorElementAttrs.PORT */]) !== null && _a !== void 0 ? _a : '';
|
|
3127
|
+
}
|
|
3128
|
+
get pathname() {
|
|
3129
|
+
var _a;
|
|
3130
|
+
return (_a = this.props["pathname" /* AnchorElementAttrs.PATHNAME */]) !== null && _a !== void 0 ? _a : '';
|
|
3131
|
+
}
|
|
3132
|
+
setAttribute(qualifiedName, value) {
|
|
3133
|
+
if (qualifiedName === "href" /* AnchorElementAttrs.HREF */) {
|
|
3134
|
+
const willSetAttr = parseUrl(value);
|
|
3135
|
+
for (const k in willSetAttr) {
|
|
3136
|
+
super.setAttribute(k, willSetAttr[k]);
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
else {
|
|
3140
|
+
super.setAttribute(qualifiedName, value);
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
|
|
3145
|
+
class CustomWrapperElement extends TaroElement {
|
|
3146
|
+
}
|
|
3147
|
+
|
|
3148
|
+
class TaroDocument extends TaroElement {
|
|
3149
|
+
constructor() {
|
|
3150
|
+
super();
|
|
3151
|
+
this.createEvent = createEvent;
|
|
3152
|
+
this.nodeType = 9 /* NodeType.DOCUMENT_NODE */;
|
|
3153
|
+
this.nodeName = DOCUMENT_ELEMENT_NAME;
|
|
3154
|
+
}
|
|
3155
|
+
createElement(type) {
|
|
3156
|
+
const nodeName = type.toLowerCase();
|
|
3157
|
+
let element;
|
|
3158
|
+
switch (true) {
|
|
3159
|
+
case nodeName === ROOT_STR:
|
|
3160
|
+
element = new TaroRootElement();
|
|
3161
|
+
return element;
|
|
3162
|
+
case controlledComponent.has(nodeName):
|
|
3163
|
+
element = new FormElement();
|
|
3164
|
+
break;
|
|
3165
|
+
case nodeName === A:
|
|
3166
|
+
element = new AnchorElement();
|
|
3167
|
+
break;
|
|
3168
|
+
case nodeName === CUSTOM_WRAPPER:
|
|
3169
|
+
element = new CustomWrapperElement();
|
|
3170
|
+
break;
|
|
3171
|
+
default:
|
|
3172
|
+
element = new TaroElement();
|
|
3173
|
+
break;
|
|
3174
|
+
}
|
|
3175
|
+
element.nodeName = nodeName;
|
|
3176
|
+
element.tagName = type.toUpperCase();
|
|
3177
|
+
return element;
|
|
3178
|
+
}
|
|
3179
|
+
// an ugly fake createElementNS to deal with @vue/runtime-dom's
|
|
3180
|
+
// support mounting app to svg container since vue@3.0.8
|
|
3181
|
+
createElementNS(_svgNS, type) {
|
|
3182
|
+
return this.createElement(type);
|
|
3183
|
+
}
|
|
3184
|
+
createTextNode(text) {
|
|
3185
|
+
return new TaroText(text);
|
|
3186
|
+
}
|
|
3187
|
+
getElementById(id) {
|
|
3188
|
+
const el = eventSource.get(id);
|
|
3189
|
+
return isUndefined(el) ? null : el;
|
|
3190
|
+
}
|
|
3191
|
+
querySelector(query) {
|
|
3192
|
+
// 为了 Vue3 的乞丐版实现
|
|
3193
|
+
if (/^#/.test(query)) {
|
|
3194
|
+
return this.getElementById(query.slice(1));
|
|
3195
|
+
}
|
|
3196
|
+
return null;
|
|
3197
|
+
}
|
|
3198
|
+
querySelectorAll() {
|
|
3199
|
+
// fake hack
|
|
3200
|
+
return [];
|
|
3201
|
+
}
|
|
3202
|
+
// @TODO: @PERF: 在 hydrate 移除掉空的 node
|
|
3203
|
+
createComment() {
|
|
3204
|
+
const textnode = new TaroText('');
|
|
3205
|
+
textnode.nodeName = COMMENT;
|
|
3206
|
+
return textnode;
|
|
3207
|
+
}
|
|
3208
|
+
get defaultView() {
|
|
3209
|
+
return env.window;
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
|
|
3213
|
+
let document$1;
|
|
3214
|
+
if (process.env.TARO_ENV && !isWebPlatform()) {
|
|
3215
|
+
/* eslint-disable no-inner-declarations */
|
|
3216
|
+
function createDocument() {
|
|
3217
|
+
/**
|
|
3218
|
+
* <document>
|
|
3219
|
+
* <html>
|
|
3220
|
+
* <head></head>
|
|
3221
|
+
* <body>
|
|
3222
|
+
* <container>
|
|
3223
|
+
* <app id="app" />
|
|
3224
|
+
* </container>
|
|
3225
|
+
* </body>
|
|
3226
|
+
* </html>
|
|
3227
|
+
* </document>
|
|
3228
|
+
*/
|
|
3229
|
+
const doc = new TaroDocument();
|
|
3230
|
+
const documentCreateElement = doc.createElement.bind(doc);
|
|
3231
|
+
const html = documentCreateElement(HTML);
|
|
3232
|
+
const head = documentCreateElement(HEAD);
|
|
3233
|
+
const body = documentCreateElement(BODY);
|
|
3234
|
+
const app = documentCreateElement(APP);
|
|
3235
|
+
app.id = APP;
|
|
3236
|
+
const container = documentCreateElement(CONTAINER); // 多包一层主要为了兼容 vue
|
|
3237
|
+
doc.appendChild(html);
|
|
3238
|
+
html.appendChild(head);
|
|
3239
|
+
html.appendChild(body);
|
|
3240
|
+
body.appendChild(container);
|
|
3241
|
+
container.appendChild(app);
|
|
3242
|
+
doc.documentElement = html;
|
|
3243
|
+
doc.head = head;
|
|
3244
|
+
doc.body = body;
|
|
3245
|
+
return doc;
|
|
3246
|
+
}
|
|
3247
|
+
document$1 = env.document = createDocument();
|
|
3248
|
+
}
|
|
3249
|
+
else {
|
|
3250
|
+
document$1 = env.document;
|
|
3251
|
+
}
|
|
3252
|
+
|
|
3253
|
+
function getComputedStyle(element) {
|
|
3254
|
+
return element.style;
|
|
3255
|
+
}
|
|
3256
|
+
|
|
3257
|
+
const eventCenter = hooks.call('getEventCenter', Events);
|
|
3258
|
+
|
|
3259
|
+
/**
|
|
3260
|
+
* 一个小型缓存池,用于在切换页面时,存储一些上下文信息
|
|
3261
|
+
*/
|
|
3262
|
+
class RuntimeCache {
|
|
3263
|
+
constructor(name) {
|
|
3264
|
+
this.cache = new Map();
|
|
3265
|
+
this.name = name;
|
|
3266
|
+
}
|
|
3267
|
+
has(identifier) {
|
|
3268
|
+
return this.cache.has(identifier);
|
|
3269
|
+
}
|
|
3270
|
+
set(identifier, ctx) {
|
|
3271
|
+
if (identifier && ctx) {
|
|
3272
|
+
this.cache.set(identifier, ctx);
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
get(identifier) {
|
|
3276
|
+
if (this.has(identifier))
|
|
3277
|
+
return this.cache.get(identifier);
|
|
3278
|
+
}
|
|
3279
|
+
delete(identifier) {
|
|
3280
|
+
this.cache.delete(identifier);
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
|
|
3284
|
+
var _History_instances, _History_location, _History_stack, _History_cur, _History_window, _History_reset;
|
|
3285
|
+
const cache$1 = new RuntimeCache('history');
|
|
3286
|
+
class History extends Events {
|
|
3287
|
+
constructor(location, options) {
|
|
3288
|
+
super();
|
|
3289
|
+
_History_instances.add(this);
|
|
3290
|
+
/* private property */
|
|
3291
|
+
_History_location.set(this, void 0);
|
|
3292
|
+
_History_stack.set(this, []);
|
|
3293
|
+
_History_cur.set(this, 0);
|
|
3294
|
+
_History_window.set(this, void 0);
|
|
3295
|
+
__classPrivateFieldSet(this, _History_window, options.window, "f");
|
|
3296
|
+
__classPrivateFieldSet(this, _History_location, location, "f");
|
|
3297
|
+
__classPrivateFieldGet(this, _History_location, "f").on('__record_history__', (href) => {
|
|
3298
|
+
var _a;
|
|
3299
|
+
__classPrivateFieldSet(this, _History_cur, (_a = __classPrivateFieldGet(this, _History_cur, "f"), _a++, _a), "f");
|
|
3300
|
+
__classPrivateFieldSet(this, _History_stack, __classPrivateFieldGet(this, _History_stack, "f").slice(0, __classPrivateFieldGet(this, _History_cur, "f")), "f");
|
|
3301
|
+
__classPrivateFieldGet(this, _History_stack, "f").push({
|
|
3302
|
+
state: null,
|
|
3303
|
+
title: '',
|
|
3304
|
+
url: href
|
|
3305
|
+
});
|
|
3306
|
+
}, null);
|
|
3307
|
+
__classPrivateFieldGet(this, _History_location, "f").on('__reset_history__', (href) => {
|
|
3308
|
+
__classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this, href);
|
|
3309
|
+
}, null);
|
|
3310
|
+
// 切换上下文行为
|
|
3311
|
+
this.on(CONTEXT_ACTIONS.INIT, () => {
|
|
3312
|
+
__classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this);
|
|
3313
|
+
}, null);
|
|
3314
|
+
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3315
|
+
cache$1.set(pageId, {
|
|
3316
|
+
location: __classPrivateFieldGet(this, _History_location, "f"),
|
|
3317
|
+
stack: __classPrivateFieldGet(this, _History_stack, "f").slice(),
|
|
3318
|
+
cur: __classPrivateFieldGet(this, _History_cur, "f")
|
|
3319
|
+
});
|
|
3320
|
+
}, null);
|
|
3321
|
+
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
3322
|
+
if (cache$1.has(pageId)) {
|
|
3323
|
+
const ctx = cache$1.get(pageId);
|
|
3324
|
+
__classPrivateFieldSet(this, _History_location, ctx.location, "f");
|
|
3325
|
+
__classPrivateFieldSet(this, _History_stack, ctx.stack, "f");
|
|
3326
|
+
__classPrivateFieldSet(this, _History_cur, ctx.cur, "f");
|
|
3327
|
+
}
|
|
3328
|
+
}, null);
|
|
3329
|
+
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
3330
|
+
cache$1.delete(pageId);
|
|
3331
|
+
}, null);
|
|
3332
|
+
__classPrivateFieldGet(this, _History_instances, "m", _History_reset).call(this);
|
|
3333
|
+
}
|
|
3334
|
+
/* public property */
|
|
3335
|
+
get length() {
|
|
3336
|
+
return __classPrivateFieldGet(this, _History_stack, "f").length;
|
|
3337
|
+
}
|
|
3338
|
+
get state() {
|
|
3339
|
+
return __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")];
|
|
3340
|
+
}
|
|
3341
|
+
/* public method */
|
|
3342
|
+
go(delta) {
|
|
3343
|
+
if (!isNumber(delta) || isNaN(delta))
|
|
3344
|
+
return;
|
|
3345
|
+
let targetIdx = __classPrivateFieldGet(this, _History_cur, "f") + delta;
|
|
3346
|
+
targetIdx = Math.min(Math.max(targetIdx, 0), this.length - 1);
|
|
3347
|
+
__classPrivateFieldSet(this, _History_cur, targetIdx, "f");
|
|
3348
|
+
__classPrivateFieldGet(this, _History_location, "f").trigger('__set_href_without_history__', __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")].url);
|
|
3349
|
+
__classPrivateFieldGet(this, _History_window, "f").trigger('popstate', __classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")]);
|
|
3350
|
+
}
|
|
3351
|
+
back() {
|
|
3352
|
+
this.go(-1);
|
|
3353
|
+
}
|
|
3354
|
+
forward() {
|
|
3355
|
+
this.go(1);
|
|
3356
|
+
}
|
|
3357
|
+
pushState(state, title, url) {
|
|
3358
|
+
if (!url || !isString(url))
|
|
3359
|
+
return;
|
|
3360
|
+
__classPrivateFieldSet(this, _History_stack, __classPrivateFieldGet(this, _History_stack, "f").slice(0, __classPrivateFieldGet(this, _History_cur, "f") + 1), "f");
|
|
3361
|
+
__classPrivateFieldGet(this, _History_stack, "f").push({
|
|
3362
|
+
state,
|
|
3363
|
+
title,
|
|
3364
|
+
url
|
|
3365
|
+
});
|
|
3366
|
+
__classPrivateFieldSet(this, _History_cur, this.length - 1, "f");
|
|
3367
|
+
__classPrivateFieldGet(this, _History_location, "f").trigger('__set_href_without_history__', url);
|
|
3368
|
+
}
|
|
3369
|
+
replaceState(state, title, url) {
|
|
3370
|
+
if (!url || !isString(url))
|
|
3371
|
+
return;
|
|
3372
|
+
__classPrivateFieldGet(this, _History_stack, "f")[__classPrivateFieldGet(this, _History_cur, "f")] = {
|
|
3373
|
+
state,
|
|
3374
|
+
title,
|
|
3375
|
+
url
|
|
3376
|
+
};
|
|
3377
|
+
__classPrivateFieldGet(this, _History_location, "f").trigger('__set_href_without_history__', url);
|
|
3378
|
+
}
|
|
3379
|
+
// For debug
|
|
3380
|
+
get cache() {
|
|
3381
|
+
return cache$1;
|
|
3382
|
+
}
|
|
3383
|
+
}
|
|
3384
|
+
_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 = '') {
|
|
3385
|
+
__classPrivateFieldSet(this, _History_stack, [
|
|
3386
|
+
{
|
|
3387
|
+
state: null,
|
|
3388
|
+
title: '',
|
|
3389
|
+
url: href || __classPrivateFieldGet(this, _History_location, "f").href
|
|
3390
|
+
}
|
|
3391
|
+
], "f");
|
|
3392
|
+
__classPrivateFieldSet(this, _History_cur, 0, "f");
|
|
3393
|
+
};
|
|
3394
|
+
|
|
3395
|
+
const Current = {
|
|
3396
|
+
app: null,
|
|
3397
|
+
router: null,
|
|
3398
|
+
page: null
|
|
3399
|
+
};
|
|
3400
|
+
const getCurrentInstance = () => Current;
|
|
3401
|
+
|
|
3402
|
+
var _Location_instances, _Location_url, _Location_noCheckUrl, _Location_window, _Location_reset, _Location_getPreValue, _Location_rollBack, _Location_recordHistory, _Location_checkUrlChange;
|
|
3403
|
+
const INIT_URL = 'https://taro.com';
|
|
3404
|
+
const cache = new RuntimeCache('location');
|
|
3405
|
+
class Location extends Events {
|
|
3406
|
+
constructor(options) {
|
|
3407
|
+
super();
|
|
3408
|
+
_Location_instances.add(this);
|
|
3409
|
+
/* private property */
|
|
3410
|
+
_Location_url.set(this, new URL(INIT_URL));
|
|
3411
|
+
_Location_noCheckUrl.set(this, false);
|
|
3412
|
+
_Location_window.set(this, void 0);
|
|
3413
|
+
__classPrivateFieldSet(this, _Location_window, options.window, "f");
|
|
3414
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_reset).call(this);
|
|
3415
|
+
this.on('__set_href_without_history__', (href) => {
|
|
3416
|
+
__classPrivateFieldSet(this, _Location_noCheckUrl, true, "f");
|
|
3417
|
+
const lastHash = __classPrivateFieldGet(this, _Location_url, "f").hash;
|
|
3418
|
+
__classPrivateFieldGet(this, _Location_url, "f").href = generateFullUrl(href);
|
|
3419
|
+
if (lastHash !== __classPrivateFieldGet(this, _Location_url, "f").hash) {
|
|
3420
|
+
__classPrivateFieldGet(this, _Location_window, "f").trigger('hashchange');
|
|
3421
|
+
}
|
|
3422
|
+
__classPrivateFieldSet(this, _Location_noCheckUrl, false, "f");
|
|
3423
|
+
}, null);
|
|
3424
|
+
// 切换上下文行为
|
|
3425
|
+
this.on(CONTEXT_ACTIONS.INIT, () => {
|
|
3426
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_reset).call(this);
|
|
3427
|
+
}, null);
|
|
3428
|
+
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3429
|
+
cache.set(pageId, {
|
|
3430
|
+
lastHref: this.href,
|
|
3431
|
+
});
|
|
3432
|
+
}, null);
|
|
3433
|
+
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
3434
|
+
// 数据恢复时,不需要执行跳转
|
|
3435
|
+
if (cache.has(pageId)) {
|
|
3436
|
+
const ctx = cache.get(pageId);
|
|
3437
|
+
__classPrivateFieldSet(this, _Location_noCheckUrl, true, "f");
|
|
3438
|
+
__classPrivateFieldGet(this, _Location_url, "f").href = ctx.lastHref;
|
|
3439
|
+
__classPrivateFieldSet(this, _Location_noCheckUrl, false, "f");
|
|
3440
|
+
}
|
|
3441
|
+
}, null);
|
|
3442
|
+
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
3443
|
+
cache.delete(pageId);
|
|
3444
|
+
}, null);
|
|
3445
|
+
}
|
|
3446
|
+
/* public property */
|
|
3447
|
+
get protocol() {
|
|
3448
|
+
return __classPrivateFieldGet(this, _Location_url, "f").protocol;
|
|
3449
|
+
}
|
|
3450
|
+
set protocol(val) {
|
|
3451
|
+
const REG = /^(http|https):$/i;
|
|
3452
|
+
if (!val || !isString(val) || !REG.test(val.trim()))
|
|
3453
|
+
return;
|
|
3454
|
+
val = val.trim();
|
|
3455
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3456
|
+
__classPrivateFieldGet(this, _Location_url, "f").protocol = val;
|
|
3457
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3458
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3459
|
+
}
|
|
3460
|
+
get host() {
|
|
3461
|
+
return __classPrivateFieldGet(this, _Location_url, "f").host;
|
|
3462
|
+
}
|
|
3463
|
+
set host(val) {
|
|
3464
|
+
if (!val || !isString(val))
|
|
3465
|
+
return;
|
|
3466
|
+
val = val.trim();
|
|
3467
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3468
|
+
__classPrivateFieldGet(this, _Location_url, "f").host = val;
|
|
3469
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3470
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3471
|
+
}
|
|
3472
|
+
get hostname() {
|
|
3473
|
+
return __classPrivateFieldGet(this, _Location_url, "f").hostname;
|
|
3474
|
+
}
|
|
3475
|
+
set hostname(val) {
|
|
3476
|
+
if (!val || !isString(val))
|
|
3477
|
+
return;
|
|
3478
|
+
val = val.trim();
|
|
3479
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3480
|
+
__classPrivateFieldGet(this, _Location_url, "f").hostname = val;
|
|
3481
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3482
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3483
|
+
}
|
|
3484
|
+
get port() {
|
|
3485
|
+
return __classPrivateFieldGet(this, _Location_url, "f").port;
|
|
3486
|
+
}
|
|
3487
|
+
set port(val) {
|
|
3488
|
+
const xVal = Number((val = val.trim()));
|
|
3489
|
+
if (!isNumber(xVal) || xVal <= 0)
|
|
3490
|
+
return;
|
|
3491
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3492
|
+
__classPrivateFieldGet(this, _Location_url, "f").port = val;
|
|
3493
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3494
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3495
|
+
}
|
|
3496
|
+
get pathname() {
|
|
3497
|
+
return __classPrivateFieldGet(this, _Location_url, "f").pathname;
|
|
3498
|
+
}
|
|
3499
|
+
set pathname(val) {
|
|
3500
|
+
if (!val || !isString(val))
|
|
3501
|
+
return;
|
|
3502
|
+
val = val.trim();
|
|
3503
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3504
|
+
__classPrivateFieldGet(this, _Location_url, "f").pathname = val;
|
|
3505
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3506
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3507
|
+
}
|
|
3508
|
+
get search() {
|
|
3509
|
+
return __classPrivateFieldGet(this, _Location_url, "f").search;
|
|
3510
|
+
}
|
|
3511
|
+
set search(val) {
|
|
3512
|
+
if (!val || !isString(val))
|
|
3513
|
+
return;
|
|
3514
|
+
val = val.trim();
|
|
3515
|
+
val = val.startsWith('?') ? val : `?${val}`;
|
|
3516
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3517
|
+
__classPrivateFieldGet(this, _Location_url, "f").search = val;
|
|
3518
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3519
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3520
|
+
}
|
|
3521
|
+
get hash() {
|
|
3522
|
+
return __classPrivateFieldGet(this, _Location_url, "f").hash;
|
|
3523
|
+
}
|
|
3524
|
+
// 小程序的navigateTo存在截断hash字符串的问题
|
|
3525
|
+
set hash(val) {
|
|
3526
|
+
if (!val || !isString(val))
|
|
3527
|
+
return;
|
|
3528
|
+
val = val.trim();
|
|
3529
|
+
val = val.startsWith('#') ? val : `#${val}`;
|
|
3530
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3531
|
+
__classPrivateFieldGet(this, _Location_url, "f").hash = val;
|
|
3532
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3533
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3534
|
+
}
|
|
3535
|
+
get href() {
|
|
3536
|
+
return __classPrivateFieldGet(this, _Location_url, "f").href;
|
|
3537
|
+
}
|
|
3538
|
+
set href(val) {
|
|
3539
|
+
const REG = /^(http:|https:)?\/\/.+/;
|
|
3540
|
+
if (!val || !isString(val) || !REG.test((val = val.trim())))
|
|
3541
|
+
return;
|
|
3542
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3543
|
+
__classPrivateFieldGet(this, _Location_url, "f").href = val;
|
|
3544
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3545
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3546
|
+
}
|
|
3547
|
+
get origin() {
|
|
3548
|
+
return __classPrivateFieldGet(this, _Location_url, "f").origin;
|
|
3549
|
+
}
|
|
3550
|
+
set origin(val) {
|
|
3551
|
+
const REG = /^(http:|https:)?\/\/.+/;
|
|
3552
|
+
if (!val || !isString(val) || !REG.test((val = val.trim())))
|
|
3553
|
+
return;
|
|
3554
|
+
const preValue = __classPrivateFieldGet(this, _Location_instances, "m", _Location_getPreValue).call(this);
|
|
3555
|
+
__classPrivateFieldGet(this, _Location_url, "f").origin = val;
|
|
3556
|
+
if (__classPrivateFieldGet(this, _Location_instances, "m", _Location_checkUrlChange).call(this, preValue))
|
|
3557
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_recordHistory).call(this);
|
|
3558
|
+
}
|
|
3559
|
+
/* public method */
|
|
3560
|
+
assign() {
|
|
3561
|
+
warn(true, '小程序环境中调用location.assign()无效.');
|
|
3562
|
+
}
|
|
3563
|
+
reload() {
|
|
3564
|
+
warn(true, '小程序环境中调用location.reload()无效.');
|
|
3565
|
+
}
|
|
3566
|
+
replace(url) {
|
|
3567
|
+
this.trigger('__set_href_without_history__', url);
|
|
3568
|
+
}
|
|
3569
|
+
toString() {
|
|
3570
|
+
return this.href;
|
|
3571
|
+
}
|
|
3572
|
+
// For debug
|
|
3573
|
+
get cache() {
|
|
3574
|
+
return cache;
|
|
3575
|
+
}
|
|
3576
|
+
}
|
|
3577
|
+
_Location_url = new WeakMap(), _Location_noCheckUrl = new WeakMap(), _Location_window = new WeakMap(), _Location_instances = new WeakSet(), _Location_reset = function _Location_reset() {
|
|
3578
|
+
const Current = getCurrentInstance();
|
|
3579
|
+
const router = Current.router;
|
|
3580
|
+
if (router) {
|
|
3581
|
+
const { path, params } = router;
|
|
3582
|
+
const searchArr = Object.keys(params).map((key) => {
|
|
3583
|
+
return `${key}=${params[key]}`;
|
|
3584
|
+
});
|
|
3585
|
+
const searchStr = searchArr.length > 0 ? '?' + searchArr.join('&') : '';
|
|
3586
|
+
const url = `${INIT_URL}${path.startsWith('/') ? path : '/' + path}${searchStr}`;
|
|
3587
|
+
__classPrivateFieldSet(this, _Location_url, new URL(url), "f");
|
|
3588
|
+
this.trigger('__reset_history__', this.href);
|
|
3589
|
+
}
|
|
3590
|
+
}, _Location_getPreValue = function _Location_getPreValue() {
|
|
3591
|
+
return __classPrivateFieldGet(this, _Location_url, "f")._toRaw();
|
|
3592
|
+
}, _Location_rollBack = function _Location_rollBack(href) {
|
|
3593
|
+
__classPrivateFieldGet(this, _Location_url, "f").href = href;
|
|
3594
|
+
}, _Location_recordHistory = function _Location_recordHistory() {
|
|
3595
|
+
this.trigger('__record_history__', this.href);
|
|
3596
|
+
}, _Location_checkUrlChange = function _Location_checkUrlChange(preValue) {
|
|
3597
|
+
if (__classPrivateFieldGet(this, _Location_noCheckUrl, "f")) {
|
|
3598
|
+
return false;
|
|
3599
|
+
}
|
|
3600
|
+
const { protocol, hostname, port, pathname, search, hash } = __classPrivateFieldGet(this, _Location_url, "f")._toRaw();
|
|
3601
|
+
// 跨域三要素不允许修改
|
|
3602
|
+
if (protocol !== preValue.protocol || hostname !== preValue.hostname || port !== preValue.port) {
|
|
3603
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue.href);
|
|
3604
|
+
return false;
|
|
3605
|
+
}
|
|
3606
|
+
// pathname
|
|
3607
|
+
if (pathname !== preValue.pathname) {
|
|
3608
|
+
return true;
|
|
3609
|
+
}
|
|
3610
|
+
// search
|
|
3611
|
+
if (search !== preValue.search) {
|
|
3612
|
+
return true;
|
|
3613
|
+
}
|
|
3614
|
+
// hashchange
|
|
3615
|
+
if (hash !== preValue.hash) {
|
|
3616
|
+
__classPrivateFieldGet(this, _Location_window, "f").trigger('hashchange');
|
|
3617
|
+
return true;
|
|
3618
|
+
}
|
|
3619
|
+
__classPrivateFieldGet(this, _Location_instances, "m", _Location_rollBack).call(this, preValue.href);
|
|
3620
|
+
return false;
|
|
3621
|
+
};
|
|
3622
|
+
function generateFullUrl(val = '') {
|
|
3623
|
+
const origin = INIT_URL;
|
|
3624
|
+
if (/^[/?#]/.test(val)) {
|
|
3625
|
+
return origin + val;
|
|
3626
|
+
}
|
|
3627
|
+
return val;
|
|
3628
|
+
}
|
|
3629
|
+
|
|
3630
|
+
const machine = 'Macintosh';
|
|
3631
|
+
const arch = 'Intel Mac OS X 10_14_5';
|
|
3632
|
+
const engine = 'AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36';
|
|
3633
|
+
const msg = '(' + machine + '; ' + arch + ') ' + engine;
|
|
3634
|
+
const nav = isWebPlatform() ? env.window.navigator : {
|
|
3635
|
+
appCodeName: 'Mozilla',
|
|
3636
|
+
appName: 'Netscape',
|
|
3637
|
+
appVersion: '5.0 ' + msg,
|
|
3638
|
+
cookieEnabled: true,
|
|
3639
|
+
mimeTypes: [],
|
|
3640
|
+
onLine: true,
|
|
3641
|
+
platform: 'MacIntel',
|
|
3642
|
+
plugins: [],
|
|
3643
|
+
product: 'Taro',
|
|
3644
|
+
productSub: '20030107',
|
|
3645
|
+
userAgent: 'Mozilla/5.0 ' + msg,
|
|
3646
|
+
vendor: 'Joyent',
|
|
3647
|
+
vendorSub: ''
|
|
3648
|
+
};
|
|
3649
|
+
|
|
3650
|
+
// https://github.com/myrne/performance-now
|
|
3651
|
+
let now;
|
|
3652
|
+
(function () {
|
|
3653
|
+
let loadTime;
|
|
3654
|
+
if ((typeof performance !== 'undefined' && performance !== null) && performance.now) {
|
|
3655
|
+
now = () => performance.now();
|
|
3656
|
+
}
|
|
3657
|
+
else if (Date.now) {
|
|
3658
|
+
loadTime = Date.now();
|
|
3659
|
+
now = () => Date.now() - loadTime;
|
|
3660
|
+
}
|
|
3661
|
+
else {
|
|
3662
|
+
loadTime = new Date().getTime();
|
|
3663
|
+
now = () => new Date().getTime() - loadTime;
|
|
3664
|
+
}
|
|
3665
|
+
})();
|
|
3666
|
+
let lastTime = 0;
|
|
3667
|
+
// https://gist.github.com/paulirish/1579671
|
|
3668
|
+
// https://gist.github.com/jalbam/5fe05443270fa6d8136238ec72accbc0
|
|
3669
|
+
const _raf = typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame !== null ? requestAnimationFrame : function (callback) {
|
|
3670
|
+
const _now = now();
|
|
3671
|
+
const nextTime = Math.max(lastTime + 16, _now); // First time will execute it immediately but barely noticeable and performance is gained.
|
|
3672
|
+
return setTimeout(function () { callback(lastTime = nextTime); }, nextTime - _now);
|
|
3673
|
+
};
|
|
3674
|
+
const _caf = typeof cancelAnimationFrame !== 'undefined' && cancelAnimationFrame !== null
|
|
3675
|
+
? cancelAnimationFrame
|
|
3676
|
+
: function (seed) {
|
|
3677
|
+
// fix https://github.com/NervJS/taro/issues/7749
|
|
3678
|
+
clearTimeout(seed);
|
|
3679
|
+
};
|
|
3680
|
+
|
|
3681
|
+
let window$1;
|
|
3682
|
+
if (process.env.TARO_ENV && !isWebPlatform()) {
|
|
3683
|
+
class Window extends Events {
|
|
3684
|
+
constructor() {
|
|
3685
|
+
super();
|
|
3686
|
+
this.navigator = nav;
|
|
3687
|
+
this.requestAnimationFrame = _raf;
|
|
3688
|
+
this.cancelAnimationFrame = _caf;
|
|
3689
|
+
this.getComputedStyle = getComputedStyle;
|
|
3690
|
+
const globalProperties = [
|
|
3691
|
+
...Object.getOwnPropertyNames(global || {}),
|
|
3692
|
+
...Object.getOwnPropertySymbols(global || {})
|
|
3693
|
+
];
|
|
3694
|
+
globalProperties.forEach(property => {
|
|
3695
|
+
if (property === 'atob' || property === 'document')
|
|
3696
|
+
return;
|
|
3697
|
+
if (!Object.prototype.hasOwnProperty.call(this, property)) {
|
|
3698
|
+
this[property] = global[property];
|
|
3699
|
+
}
|
|
3700
|
+
});
|
|
3701
|
+
this.Date || (this.Date = Date);
|
|
3702
|
+
// 应用启动时,提供给需要读取历史信息的库使用
|
|
3703
|
+
this.location = new Location({ window: this });
|
|
3704
|
+
this.history = new History(this.location, { window: this });
|
|
3705
|
+
this.initEvent();
|
|
3706
|
+
}
|
|
3707
|
+
initEvent() {
|
|
3708
|
+
const _location = this.location;
|
|
3709
|
+
const _history = this.history;
|
|
3710
|
+
this.on(CONTEXT_ACTIONS.INIT, (pageId) => {
|
|
3711
|
+
// 页面onload,为该页面建立新的上下文信息
|
|
3712
|
+
_location.trigger(CONTEXT_ACTIONS.INIT, pageId);
|
|
3713
|
+
}, null);
|
|
3714
|
+
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
3715
|
+
// 页面onshow,恢复当前页面的上下文信息
|
|
3716
|
+
_location.trigger(CONTEXT_ACTIONS.RECOVER, pageId);
|
|
3717
|
+
_history.trigger(CONTEXT_ACTIONS.RECOVER, pageId);
|
|
3718
|
+
}, null);
|
|
3719
|
+
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3720
|
+
// 页面onhide,缓存当前页面的上下文信息
|
|
3721
|
+
_location.trigger(CONTEXT_ACTIONS.RESTORE, pageId);
|
|
3722
|
+
_history.trigger(CONTEXT_ACTIONS.RESTORE, pageId);
|
|
3723
|
+
}, null);
|
|
3724
|
+
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
3725
|
+
// 页面onunload,清除当前页面的上下文信息
|
|
3726
|
+
_location.trigger(CONTEXT_ACTIONS.DESTORY, pageId);
|
|
3727
|
+
_history.trigger(CONTEXT_ACTIONS.DESTORY, pageId);
|
|
3728
|
+
}, null);
|
|
3729
|
+
}
|
|
3730
|
+
get document() {
|
|
3731
|
+
return env.document;
|
|
3732
|
+
}
|
|
3733
|
+
addEventListener(event, callback) {
|
|
3734
|
+
if (!isString(event))
|
|
3735
|
+
return;
|
|
3736
|
+
this.on(event, callback, null);
|
|
3737
|
+
}
|
|
3738
|
+
removeEventListener(event, callback) {
|
|
3739
|
+
if (!isString(event))
|
|
3740
|
+
return;
|
|
3741
|
+
this.off(event, callback, null);
|
|
3742
|
+
}
|
|
3743
|
+
setTimeout(...args) {
|
|
3744
|
+
return setTimeout(...args);
|
|
3745
|
+
}
|
|
3746
|
+
clearTimeout(...args) {
|
|
3747
|
+
return clearTimeout(...args);
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
window$1 = env.window = new Window();
|
|
3751
|
+
}
|
|
3752
|
+
else {
|
|
3753
|
+
window$1 = env.window;
|
|
3754
|
+
}
|
|
3755
|
+
const location = window$1.location;
|
|
3756
|
+
const history = window$1.history;
|
|
3757
|
+
|
|
3758
|
+
// for Vue3
|
|
3759
|
+
class SVGElement extends TaroElement {
|
|
3760
|
+
}
|
|
3761
|
+
|
|
3762
|
+
/* eslint-disable dot-notation */
|
|
3763
|
+
const instances = new Map();
|
|
3764
|
+
const pageId = incrementId();
|
|
3765
|
+
const isWeb = isWebPlatform();
|
|
3766
|
+
function injectPageInstance(inst, id) {
|
|
3767
|
+
hooks.call('mergePageInstance', instances.get(id), inst);
|
|
3768
|
+
instances.set(id, inst);
|
|
3769
|
+
}
|
|
3770
|
+
function getPageInstance(id) {
|
|
3771
|
+
return instances.get(id);
|
|
3772
|
+
}
|
|
3773
|
+
function removePageInstance(id) {
|
|
3774
|
+
instances.delete(id);
|
|
3775
|
+
}
|
|
3776
|
+
function addLeadingSlash(path) {
|
|
3777
|
+
if (path == null) {
|
|
3778
|
+
return '';
|
|
3779
|
+
}
|
|
3780
|
+
return path.charAt(0) === '/' ? path : '/' + path;
|
|
3781
|
+
}
|
|
3782
|
+
function safeExecute(path, lifecycle, ...args) {
|
|
3783
|
+
const instance = instances.get(path);
|
|
3784
|
+
if (instance == null) {
|
|
3785
|
+
return;
|
|
3786
|
+
}
|
|
3787
|
+
const func = hooks.call('getLifecycle', instance, lifecycle);
|
|
3788
|
+
if (isArray(func)) {
|
|
3789
|
+
const res = func.map(fn => fn.apply(instance, args));
|
|
3790
|
+
return res[0];
|
|
3791
|
+
}
|
|
3792
|
+
if (!isFunction(func)) {
|
|
3793
|
+
return;
|
|
3794
|
+
}
|
|
3795
|
+
return func.apply(instance, args);
|
|
3796
|
+
}
|
|
3797
|
+
function stringify(obj) {
|
|
3798
|
+
if (obj == null) {
|
|
3799
|
+
return '';
|
|
3800
|
+
}
|
|
3801
|
+
const path = Object.keys(obj).map((key) => {
|
|
3802
|
+
return key + '=' + obj[key];
|
|
3803
|
+
}).join('&');
|
|
3804
|
+
return path === '' ? path : '?' + path;
|
|
3805
|
+
}
|
|
3806
|
+
function getPath(id, options) {
|
|
3807
|
+
const idx = id.indexOf('?');
|
|
3808
|
+
if (isWeb) {
|
|
3809
|
+
return `${idx > -1 ? id.substring(0, idx) : id}${stringify((options === null || options === void 0 ? void 0 : options.stamp) ? { stamp: options.stamp } : {})}`;
|
|
3810
|
+
}
|
|
3811
|
+
else {
|
|
3812
|
+
return `${idx > -1 ? id.substring(0, idx) : id}${stringify(options)}`;
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3815
|
+
function getOnReadyEventKey(path) {
|
|
3816
|
+
return path + '.' + ON_READY;
|
|
3817
|
+
}
|
|
3818
|
+
function getOnShowEventKey(path) {
|
|
3819
|
+
return path + '.' + ON_SHOW;
|
|
3820
|
+
}
|
|
3821
|
+
function getOnHideEventKey(path) {
|
|
3822
|
+
return path + '.' + ON_HIDE;
|
|
3823
|
+
}
|
|
3824
|
+
function createPageConfig(component, pageName, data, pageConfig) {
|
|
3825
|
+
// 小程序 Page 构造器是一个傲娇小公主,不能把复杂的对象挂载到参数上
|
|
3826
|
+
const id = pageName !== null && pageName !== void 0 ? pageName : `taro_page_${pageId()}`;
|
|
3827
|
+
const [ONLOAD, ONUNLOAD, ONREADY, ONSHOW, ONHIDE, LIFECYCLES, SIDE_EFFECT_LIFECYCLES] = hooks.call('getMiniLifecycleImpl').page;
|
|
3828
|
+
let pageElement = null;
|
|
3829
|
+
let unmounting = false;
|
|
3830
|
+
let prepareMountList = [];
|
|
3831
|
+
function setCurrentRouter(page) {
|
|
3832
|
+
const router = isWeb ? page.$taroPath : page.route || page.__route__ || page.$taroPath;
|
|
3833
|
+
Current.router = {
|
|
3834
|
+
params: page.$taroParams,
|
|
3835
|
+
path: addLeadingSlash(router),
|
|
3836
|
+
$taroPath: page.$taroPath,
|
|
3837
|
+
onReady: getOnReadyEventKey(id),
|
|
3838
|
+
onShow: getOnShowEventKey(id),
|
|
3839
|
+
onHide: getOnHideEventKey(id)
|
|
3840
|
+
};
|
|
3841
|
+
if (!isUndefined(page.exitState)) {
|
|
3842
|
+
Current.router.exitState = page.exitState;
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
let loadResolver;
|
|
3846
|
+
let hasLoaded;
|
|
3847
|
+
const config = {
|
|
3848
|
+
[ONLOAD](options = {}, cb) {
|
|
3849
|
+
hasLoaded = new Promise(resolve => { loadResolver = resolve; });
|
|
3850
|
+
perf.start(PAGE_INIT);
|
|
3851
|
+
Current.page = this;
|
|
3852
|
+
this.config = pageConfig || {};
|
|
3853
|
+
// this.$taroPath 是页面唯一标识
|
|
3854
|
+
const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() });
|
|
3855
|
+
const $taroPath = this.$taroPath = getPath(id, uniqueOptions);
|
|
3856
|
+
if (isWeb) {
|
|
3857
|
+
config.path = $taroPath;
|
|
3858
|
+
}
|
|
3859
|
+
// this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
|
|
3860
|
+
if (this.$taroParams == null) {
|
|
3861
|
+
this.$taroParams = uniqueOptions;
|
|
3862
|
+
}
|
|
3863
|
+
setCurrentRouter(this);
|
|
3864
|
+
// 初始化当前页面的上下文信息
|
|
3865
|
+
if (!isWeb) {
|
|
3866
|
+
window$1.trigger(CONTEXT_ACTIONS.INIT, $taroPath);
|
|
3867
|
+
}
|
|
3868
|
+
const mount = () => {
|
|
3869
|
+
Current.app.mount(component, $taroPath, () => {
|
|
3870
|
+
pageElement = env.document.getElementById($taroPath);
|
|
3871
|
+
ensure(pageElement !== null, '没有找到页面实例。');
|
|
3872
|
+
safeExecute($taroPath, ON_LOAD, this.$taroParams);
|
|
3873
|
+
loadResolver();
|
|
3874
|
+
if (!isWeb) {
|
|
3875
|
+
pageElement.ctx = this;
|
|
3876
|
+
pageElement.performUpdate(true, cb);
|
|
3877
|
+
}
|
|
3878
|
+
else {
|
|
3879
|
+
isFunction(cb) && cb();
|
|
3880
|
+
}
|
|
3881
|
+
});
|
|
3882
|
+
};
|
|
3883
|
+
if (unmounting) {
|
|
3884
|
+
prepareMountList.push(mount);
|
|
3885
|
+
}
|
|
3886
|
+
else {
|
|
3887
|
+
mount();
|
|
3888
|
+
}
|
|
3889
|
+
},
|
|
3890
|
+
[ONUNLOAD]() {
|
|
3891
|
+
const $taroPath = this.$taroPath;
|
|
3892
|
+
// 销毁当前页面的上下文信息
|
|
3893
|
+
if (!isWeb) {
|
|
3894
|
+
window$1.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath);
|
|
3895
|
+
}
|
|
3896
|
+
// 触发onUnload生命周期
|
|
3897
|
+
safeExecute($taroPath, ONUNLOAD);
|
|
3898
|
+
unmounting = true;
|
|
3899
|
+
Current.app.unmount($taroPath, () => {
|
|
3900
|
+
unmounting = false;
|
|
3901
|
+
instances.delete($taroPath);
|
|
3902
|
+
if (pageElement) {
|
|
3903
|
+
pageElement.ctx = null;
|
|
3904
|
+
pageElement = null;
|
|
3905
|
+
}
|
|
3906
|
+
if (prepareMountList.length) {
|
|
3907
|
+
prepareMountList.forEach(fn => fn());
|
|
3908
|
+
prepareMountList = [];
|
|
3909
|
+
}
|
|
3910
|
+
});
|
|
3911
|
+
},
|
|
3912
|
+
[ONREADY]() {
|
|
3913
|
+
hasLoaded.then(() => {
|
|
3914
|
+
// 触发生命周期
|
|
3915
|
+
safeExecute(this.$taroPath, ON_READY);
|
|
3916
|
+
// 通过事件触发子组件的生命周期
|
|
3917
|
+
_raf(() => eventCenter.trigger(getOnReadyEventKey(id)));
|
|
3918
|
+
this.onReady.called = true;
|
|
3919
|
+
});
|
|
3920
|
+
},
|
|
3921
|
+
[ONSHOW](options = {}) {
|
|
3922
|
+
hasLoaded.then(() => {
|
|
3923
|
+
// 设置 Current 的 page 和 router
|
|
3924
|
+
Current.page = this;
|
|
3925
|
+
setCurrentRouter(this);
|
|
3926
|
+
// 恢复上下文信息
|
|
3927
|
+
if (!isWeb) {
|
|
3928
|
+
window$1.trigger(CONTEXT_ACTIONS.RECOVER, this.$taroPath);
|
|
3929
|
+
}
|
|
3930
|
+
// 触发生命周期
|
|
3931
|
+
safeExecute(this.$taroPath, ON_SHOW, options);
|
|
3932
|
+
// 通过事件触发子组件的生命周期
|
|
3933
|
+
_raf(() => eventCenter.trigger(getOnShowEventKey(id)));
|
|
3934
|
+
});
|
|
3935
|
+
},
|
|
3936
|
+
[ONHIDE]() {
|
|
3937
|
+
// 缓存当前页面上下文信息
|
|
3938
|
+
if (!isWeb) {
|
|
3939
|
+
window$1.trigger(CONTEXT_ACTIONS.RESTORE, this.$taroPath);
|
|
3940
|
+
}
|
|
3941
|
+
// 设置 Current 的 page 和 router
|
|
3942
|
+
if (Current.page === this) {
|
|
3943
|
+
Current.page = null;
|
|
3944
|
+
Current.router = null;
|
|
3945
|
+
}
|
|
3946
|
+
// 触发生命周期
|
|
3947
|
+
safeExecute(this.$taroPath, ON_HIDE);
|
|
3948
|
+
// 通过事件触发子组件的生命周期
|
|
3949
|
+
eventCenter.trigger(getOnHideEventKey(id));
|
|
3950
|
+
}
|
|
3951
|
+
};
|
|
3952
|
+
LIFECYCLES.forEach((lifecycle) => {
|
|
3953
|
+
config[lifecycle] = function () {
|
|
3954
|
+
return safeExecute(this.$taroPath, lifecycle, ...arguments);
|
|
3955
|
+
};
|
|
3956
|
+
});
|
|
3957
|
+
// onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。
|
|
3958
|
+
SIDE_EFFECT_LIFECYCLES.forEach(lifecycle => {
|
|
3959
|
+
var _a;
|
|
3960
|
+
if (component[lifecycle] ||
|
|
3961
|
+
((_a = component.prototype) === null || _a === void 0 ? void 0 : _a[lifecycle]) ||
|
|
3962
|
+
component[lifecycle.replace(/^on/, 'enable')]) {
|
|
3963
|
+
config[lifecycle] = function (...args) {
|
|
3964
|
+
var _a;
|
|
3965
|
+
const target = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.target;
|
|
3966
|
+
if (target === null || target === void 0 ? void 0 : target.id) {
|
|
3967
|
+
const id = target.id;
|
|
3968
|
+
const element = env.document.getElementById(id);
|
|
3969
|
+
if (element) {
|
|
3970
|
+
target.dataset = element.dataset;
|
|
3971
|
+
}
|
|
3972
|
+
}
|
|
3973
|
+
return safeExecute(this.$taroPath, lifecycle, ...args);
|
|
3974
|
+
};
|
|
3975
|
+
}
|
|
3976
|
+
});
|
|
3977
|
+
config.eh = eventHandler;
|
|
3978
|
+
if (!isUndefined(data)) {
|
|
3979
|
+
config.data = data;
|
|
3980
|
+
}
|
|
3981
|
+
hooks.call('modifyPageObject', config);
|
|
3982
|
+
return config;
|
|
3983
|
+
}
|
|
3984
|
+
function createComponentConfig(component, componentName, data) {
|
|
3985
|
+
const id = componentName !== null && componentName !== void 0 ? componentName : `taro_component_${pageId()}`;
|
|
3986
|
+
let componentElement = null;
|
|
3987
|
+
const [ATTACHED, DETACHED] = hooks.call('getMiniLifecycleImpl').component;
|
|
3988
|
+
const config = {
|
|
3989
|
+
[ATTACHED]() {
|
|
3990
|
+
var _a;
|
|
3991
|
+
perf.start(PAGE_INIT);
|
|
3992
|
+
const path = getPath(id, { id: ((_a = this.getPageId) === null || _a === void 0 ? void 0 : _a.call(this)) || pageId() });
|
|
3993
|
+
Current.app.mount(component, path, () => {
|
|
3994
|
+
componentElement = env.document.getElementById(path);
|
|
3995
|
+
ensure(componentElement !== null, '没有找到组件实例。');
|
|
3996
|
+
this.$taroInstances = instances.get(path);
|
|
3997
|
+
safeExecute(path, ON_LOAD);
|
|
3998
|
+
if (!isWeb) {
|
|
3999
|
+
componentElement.ctx = this;
|
|
4000
|
+
componentElement.performUpdate(true);
|
|
4001
|
+
}
|
|
4002
|
+
});
|
|
4003
|
+
},
|
|
4004
|
+
[DETACHED]() {
|
|
4005
|
+
const path = getPath(id, { id: this.getPageId() });
|
|
4006
|
+
Current.app.unmount(path, () => {
|
|
4007
|
+
instances.delete(path);
|
|
4008
|
+
if (componentElement) {
|
|
4009
|
+
componentElement.ctx = null;
|
|
4010
|
+
}
|
|
4011
|
+
});
|
|
4012
|
+
},
|
|
4013
|
+
methods: {
|
|
4014
|
+
eh: eventHandler
|
|
4015
|
+
}
|
|
4016
|
+
};
|
|
4017
|
+
if (!isUndefined(data)) {
|
|
4018
|
+
config.data = data;
|
|
4019
|
+
}
|
|
4020
|
+
[OPTIONS, EXTERNAL_CLASSES, BEHAVIORS].forEach(key => {
|
|
4021
|
+
var _a;
|
|
4022
|
+
config[key] = (_a = component[key]) !== null && _a !== void 0 ? _a : EMPTY_OBJ;
|
|
4023
|
+
});
|
|
4024
|
+
return config;
|
|
4025
|
+
}
|
|
4026
|
+
function createRecursiveComponentConfig(componentName) {
|
|
4027
|
+
const isCustomWrapper = componentName === CUSTOM_WRAPPER;
|
|
4028
|
+
const [ATTACHED, DETACHED] = hooks.call('getMiniLifecycleImpl').component;
|
|
4029
|
+
const lifeCycles = isCustomWrapper
|
|
4030
|
+
? {
|
|
4031
|
+
[ATTACHED]() {
|
|
4032
|
+
var _a, _b;
|
|
4033
|
+
const componentId = ((_a = this.data.i) === null || _a === void 0 ? void 0 : _a.sid) || ((_b = this.props.i) === null || _b === void 0 ? void 0 : _b.sid);
|
|
4034
|
+
if (isString(componentId)) {
|
|
4035
|
+
customWrapperCache.set(componentId, this);
|
|
4036
|
+
const el = env.document.getElementById(componentId);
|
|
4037
|
+
if (el) {
|
|
4038
|
+
el.ctx = this;
|
|
4039
|
+
}
|
|
4040
|
+
}
|
|
4041
|
+
},
|
|
4042
|
+
[DETACHED]() {
|
|
4043
|
+
var _a, _b;
|
|
4044
|
+
const componentId = ((_a = this.data.i) === null || _a === void 0 ? void 0 : _a.sid) || ((_b = this.props.i) === null || _b === void 0 ? void 0 : _b.sid);
|
|
4045
|
+
if (isString(componentId)) {
|
|
4046
|
+
customWrapperCache.delete(componentId);
|
|
4047
|
+
const el = env.document.getElementById(componentId);
|
|
4048
|
+
if (el) {
|
|
4049
|
+
el.ctx = null;
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
}
|
|
4053
|
+
}
|
|
4054
|
+
: EMPTY_OBJ;
|
|
4055
|
+
return Object.assign({ properties: {
|
|
4056
|
+
i: {
|
|
4057
|
+
type: Object,
|
|
4058
|
+
value: {
|
|
4059
|
+
["nn" /* Shortcuts.NodeName */]: getComponentsAlias$1(internalComponents)[VIEW]._num
|
|
4060
|
+
}
|
|
4061
|
+
},
|
|
4062
|
+
l: {
|
|
4063
|
+
type: String,
|
|
4064
|
+
value: ''
|
|
4065
|
+
}
|
|
4066
|
+
}, options: {
|
|
4067
|
+
addGlobalClass: true,
|
|
4068
|
+
virtualHost: !isCustomWrapper
|
|
4069
|
+
}, methods: {
|
|
4070
|
+
eh: eventHandler
|
|
4071
|
+
} }, lifeCycles);
|
|
4072
|
+
}
|
|
4073
|
+
|
|
4074
|
+
const nextTick = (cb, ctx) => {
|
|
4075
|
+
var _a, _b, _c;
|
|
4076
|
+
const router = Current.router;
|
|
4077
|
+
const timerFunc = () => {
|
|
4078
|
+
setTimeout(function () {
|
|
4079
|
+
ctx ? cb.call(ctx) : cb();
|
|
4080
|
+
}, 1);
|
|
4081
|
+
};
|
|
4082
|
+
if (router !== null) {
|
|
4083
|
+
let pageElement = null;
|
|
4084
|
+
const path = router.$taroPath;
|
|
4085
|
+
pageElement = env.document.getElementById(path);
|
|
4086
|
+
if (pageElement === null || pageElement === void 0 ? void 0 : pageElement.pendingUpdate) {
|
|
4087
|
+
if (isWebPlatform()) {
|
|
4088
|
+
// eslint-disable-next-line dot-notation
|
|
4089
|
+
(_c = (_b = (_a = pageElement.firstChild) === null || _a === void 0 ? void 0 : _a['componentOnReady']) === null || _b === void 0 ? void 0 : _b.call(_a).then(() => {
|
|
4090
|
+
timerFunc();
|
|
4091
|
+
})) !== null && _c !== void 0 ? _c : timerFunc();
|
|
4092
|
+
}
|
|
4093
|
+
else {
|
|
4094
|
+
pageElement.enqueueUpdateCallback(cb, ctx);
|
|
4095
|
+
}
|
|
4096
|
+
}
|
|
4097
|
+
else {
|
|
4098
|
+
timerFunc();
|
|
4099
|
+
}
|
|
4100
|
+
}
|
|
4101
|
+
else {
|
|
4102
|
+
timerFunc();
|
|
4103
|
+
}
|
|
4104
|
+
};
|
|
4105
|
+
|
|
4106
|
+
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 };
|
|
4107
|
+
//# sourceMappingURL=runtime.esm.js.map
|