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