@tarojs/runtime 3.8.0-canary.0 → 3.8.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +14 -0
- package/dist/bom/URL.d.ts +7 -14
- package/dist/bom/URL.js +221 -0
- package/dist/bom/URL.js.map +1 -0
- package/dist/bom/URLSearchParams.d.ts +2 -14
- package/dist/bom/URLSearchParams.js +131 -0
- package/dist/bom/URLSearchParams.js.map +1 -0
- package/dist/bom/document.d.ts +2 -1
- package/dist/bom/document.js +39 -0
- package/dist/bom/document.js.map +1 -0
- package/dist/bom/getComputedStyle.d.ts +5 -3
- package/dist/bom/getComputedStyle.js +8 -0
- package/dist/bom/getComputedStyle.js.map +1 -0
- package/dist/bom/history.d.ts +11 -8
- package/dist/bom/history.js +121 -0
- package/dist/bom/history.js.map +1 -0
- package/dist/bom/location.d.ts +7 -4
- package/dist/bom/location.js +240 -0
- package/dist/bom/location.js.map +1 -0
- package/dist/bom/navigator.d.ts +2 -1
- package/dist/bom/navigator.js +24 -0
- package/dist/bom/navigator.js.map +1 -0
- package/dist/bom/raf.d.ts +2 -3
- package/dist/bom/raf.js +33 -0
- package/dist/bom/raf.js.map +1 -0
- package/dist/bom/window.d.ts +25 -4
- package/dist/bom/window.js +92 -0
- package/dist/bom/window.js.map +1 -0
- package/dist/constants/index.d.ts +52 -51
- package/dist/constants/index.js +63 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/current.d.ts +5 -5
- package/dist/current.js +9 -0
- package/dist/current.js.map +1 -0
- package/dist/dom/anchor-element.d.ts +3 -2
- package/dist/dom/anchor-element.js +54 -0
- package/dist/dom/anchor-element.js.map +1 -0
- package/dist/dom/class-list.d.ts +3 -2
- package/dist/dom/class-list.js +92 -0
- package/dist/dom/class-list.js.map +1 -0
- package/dist/dom/document.d.ts +11 -6
- package/dist/dom/document.js +80 -0
- package/dist/dom/document.js.map +1 -0
- package/dist/dom/element.d.ts +8 -7
- package/dist/dom/element.js +318 -0
- package/dist/dom/element.js.map +1 -0
- package/dist/dom/event-source.d.ts +3 -3
- package/dist/dom/event-source.js +17 -0
- package/dist/dom/event-source.js.map +1 -0
- package/dist/dom/event-target.d.ts +3 -2
- package/dist/dom/event-target.js +78 -0
- package/dist/dom/event-target.js.map +1 -0
- package/dist/dom/event.d.ts +6 -5
- package/dist/dom/event.js +152 -0
- package/dist/dom/event.js.map +1 -0
- package/dist/dom/form.d.ts +4 -3
- package/dist/dom/form.js +38 -0
- package/dist/dom/form.js.map +1 -0
- package/dist/dom/node.d.ts +40 -9
- package/dist/dom/node.js +292 -0
- package/dist/dom/node.js.map +1 -0
- package/dist/dom/root.d.ts +6 -5
- package/dist/dom/root.js +169 -0
- package/dist/dom/root.js.map +1 -0
- package/dist/dom/style.d.ts +3 -2
- package/dist/dom/style.js +168 -0
- package/dist/dom/style.js.map +1 -0
- package/dist/dom/style_properties.js +186 -0
- package/dist/dom/style_properties.js.map +1 -0
- package/dist/dom/svg.d.ts +3 -2
- package/dist/dom/svg.js +8 -0
- package/dist/dom/svg.js.map +1 -0
- package/dist/dom/text.d.ts +4 -3
- 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 +3 -3
- package/dist/dom/tree.js +38 -0
- package/dist/dom/tree.js.map +1 -0
- package/dist/dom-external/element.d.ts +4 -3
- package/dist/dom-external/element.js +29 -0
- package/dist/dom-external/element.js.map +1 -0
- package/dist/dom-external/index.js +38 -0
- package/dist/dom-external/index.js.map +1 -0
- package/dist/dom-external/inner-html/html.d.ts +3 -2
- 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 +7 -7
- package/dist/dom-external/inner-html/parser.js +257 -0
- package/dist/dom-external/inner-html/parser.js.map +1 -0
- package/dist/dom-external/inner-html/scaner.d.ts +3 -3
- 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 +3 -3
- 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 +11 -5
- package/dist/dom-external/inner-html/tags.js +41 -0
- package/dist/dom-external/inner-html/tags.js.map +1 -0
- package/dist/dom-external/inner-html/utils.d.ts +2 -1
- 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 +25 -6
- 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 +5 -6
- 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 +6 -5
- package/dist/dom-external/node.js +75 -0
- package/dist/dom-external/node.js.map +1 -0
- package/dist/dsl/common.d.ts +15 -16
- package/dist/dsl/common.js +337 -0
- package/dist/dsl/common.js.map +1 -0
- package/dist/emitter/emitter.d.ts +2 -2
- package/dist/emitter/emitter.js +7 -0
- package/dist/emitter/emitter.js.map +1 -0
- package/dist/env.d.ts +2 -2
- package/dist/env.js +9 -0
- package/dist/env.js.map +1 -0
- package/dist/hydrate.d.ts +5 -4
- package/dist/hydrate.js +91 -0
- package/dist/hydrate.js.map +1 -0
- package/dist/index-26658829.d.ts +23 -0
- package/dist/index.cjs.d.ts +788 -0
- package/dist/index.cjs.js +5207 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +32 -31
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/{dsl/instance.d.ts → instance-0f017c6e.d.ts} +22 -18
- package/dist/next-tick.d.ts +3 -2
- package/dist/next-tick.js +47 -0
- package/dist/next-tick.js.map +1 -0
- package/dist/{dom/node_types.d.ts → node_types-9ac5b4dd.d.ts} +2 -1
- package/dist/{interface/options.d.ts → options-0f017c6e.d.ts} +5 -4
- package/dist/options.d.ts +3 -2
- package/dist/options.js +7 -0
- package/dist/options.js.map +1 -0
- package/dist/perf.d.ts +2 -2
- 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/{dom-external/mutation-observer/record.d.ts → record-32b054d8.d.ts} +4 -3
- package/dist/runtime.esm.d.ts +95 -88
- package/dist/runtime.esm.js +1315 -469
- package/dist/runtime.esm.js.map +1 -1
- package/dist/utils/cache.d.ts +2 -1
- package/dist/utils/cache.js +27 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/index.d.ts +16 -15
- package/dist/utils/index.js +95 -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 +20 -10
- package/dist/interface/element.d.ts +0 -4
- package/dist/interface/event-target.d.ts +0 -10
- package/dist/interface/event.d.ts +0 -15
- package/dist/interface/hydrate.d.ts +0 -29
- package/dist/interface/index.d.ts +0 -7
- package/dist/interface/node.d.ts +0 -7
- package/dist/interface/utils.d.ts +0 -2
package/dist/runtime.esm.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { noop, isFunction, getComponentsAlias as getComponentsAlias$1, internalComponents,
|
|
1
|
+
import { noop, isFunction, getComponentsAlias as getComponentsAlias$1, internalComponents, EMPTY_OBJ, hooks, toCamelCase, isObject, warn, isArray, ensure, isNull, isUndefined, toDashed, isString, controlledComponent, Events, isNumber, EventChannel } from '@tarojs/shared';
|
|
2
2
|
export { Events, hooks } from '@tarojs/shared';
|
|
3
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from 'tslib';
|
|
3
4
|
|
|
4
5
|
const PROPERTY_THRESHOLD = 2046;
|
|
5
6
|
const TARO_RUNTIME = 'Taro runtime';
|
|
@@ -168,14 +169,14 @@ function recordMutation(record) {
|
|
|
168
169
|
});
|
|
169
170
|
}
|
|
170
171
|
|
|
171
|
-
class MutationObserver {
|
|
172
|
+
let MutationObserver$1 = class MutationObserver {
|
|
172
173
|
constructor(callback) {
|
|
173
174
|
if (ENABLE_MUTATION_OBSERVER) {
|
|
174
175
|
this.core = new MutationObserverImpl(callback);
|
|
175
176
|
}
|
|
176
177
|
else {
|
|
177
178
|
if (process.env.NODE_ENV !== 'production') {
|
|
178
|
-
console.warn('[Taro Warning] 若要使用 MutationObserver,请在 Taro 编译配置中设置 \'mini.enableMutationObserver: true\'');
|
|
179
|
+
console.warn('[Taro Warning] 若要使用 MutationObserver,请在 Taro 编译配置中设置 \'mini.runtime.enableMutationObserver: true\'');
|
|
179
180
|
}
|
|
180
181
|
this.core = {
|
|
181
182
|
observe: noop,
|
|
@@ -196,6 +197,26 @@ class MutationObserver {
|
|
|
196
197
|
static record(record) {
|
|
197
198
|
recordMutation(record);
|
|
198
199
|
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
function throttle(fn, threshold = 250, scope) {
|
|
203
|
+
let lastTime = 0;
|
|
204
|
+
let deferTimer;
|
|
205
|
+
return function (...args) {
|
|
206
|
+
const context = scope || this;
|
|
207
|
+
const now = Date.now();
|
|
208
|
+
if (now - lastTime > threshold) {
|
|
209
|
+
fn.apply(this, args);
|
|
210
|
+
lastTime = now;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
clearTimeout(deferTimer);
|
|
214
|
+
deferTimer = setTimeout(() => {
|
|
215
|
+
lastTime = now;
|
|
216
|
+
fn.apply(context, args);
|
|
217
|
+
}, threshold);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
199
220
|
}
|
|
200
221
|
|
|
201
222
|
const incrementId = () => {
|
|
@@ -249,15 +270,15 @@ function isHasExtractProp(el) {
|
|
|
249
270
|
*/
|
|
250
271
|
function isParentBinded(node, type) {
|
|
251
272
|
var _a;
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
273
|
+
while ((node = (node === null || node === void 0 ? void 0 : node.parentElement) || null)) {
|
|
274
|
+
if (!node || node.nodeName === ROOT_STR || node.nodeName === 'root-portal') {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
else if ((_a = node.__handlers[type]) === null || _a === void 0 ? void 0 : _a.length) {
|
|
278
|
+
return true;
|
|
257
279
|
}
|
|
258
|
-
node = node.parentElement;
|
|
259
280
|
}
|
|
260
|
-
return
|
|
281
|
+
return false;
|
|
261
282
|
}
|
|
262
283
|
function shortcutAttr(key) {
|
|
263
284
|
switch (key) {
|
|
@@ -393,55 +414,47 @@ class EventSource extends Map {
|
|
|
393
414
|
}
|
|
394
415
|
const eventSource = new EventSource();
|
|
395
416
|
|
|
396
|
-
const isWeb$1 = isWebPlatform();
|
|
397
417
|
const env = {
|
|
398
|
-
window:
|
|
399
|
-
document:
|
|
418
|
+
window: process.env.TARO_PLATFORM === 'web' ? window : EMPTY_OBJ,
|
|
419
|
+
document: process.env.TARO_PLATFORM === 'web' ? document : EMPTY_OBJ
|
|
400
420
|
};
|
|
401
421
|
|
|
402
422
|
let SPECIAL_NODES;
|
|
403
423
|
let componentsAlias;
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
424
|
+
/**
|
|
425
|
+
* React also has a fancy function's name for this: `hydrate()`.
|
|
426
|
+
* You may have been heard `hydrate` as a SSR-related function,
|
|
427
|
+
* actually, `hydrate` basicly do the `render()` thing, but ignore some properties,
|
|
428
|
+
* it's a vnode traverser and modifier: that's exactly what Taro's doing in here.
|
|
429
|
+
*/
|
|
430
|
+
function hydrate(node) {
|
|
431
|
+
var _a;
|
|
407
432
|
// 初始化 componentsAlias
|
|
408
433
|
componentsAlias || (componentsAlias = getComponentsAlias());
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
var _a;
|
|
412
|
-
return {
|
|
413
|
-
["v" /* Shortcuts.Text */]: node.nodeValue,
|
|
414
|
-
["nn" /* Shortcuts.NodeName */]: ((_a = componentsAlias[node.nodeName]) === null || _a === void 0 ? void 0 : _a._num) || '8'
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
function hydrateElementNode(node) {
|
|
434
|
+
// 初始化 SPECIAL_NODES
|
|
435
|
+
SPECIAL_NODES || (SPECIAL_NODES = hooks.call('getSpecialNodes'));
|
|
418
436
|
const nodeName = node.nodeName;
|
|
419
|
-
let
|
|
437
|
+
let compileModeName = null;
|
|
438
|
+
if (isText(node)) {
|
|
439
|
+
return {
|
|
440
|
+
sid: node.sid,
|
|
441
|
+
["v" /* Shortcuts.Text */]: node.nodeValue,
|
|
442
|
+
["nn" /* Shortcuts.NodeName */]: ((_a = componentsAlias[nodeName]) === null || _a === void 0 ? void 0 : _a._num) || '8'
|
|
443
|
+
};
|
|
444
|
+
}
|
|
420
445
|
const data = {
|
|
421
446
|
["nn" /* Shortcuts.NodeName */]: nodeName,
|
|
422
447
|
sid: node.sid
|
|
423
448
|
};
|
|
424
|
-
|
|
449
|
+
if (node.uid !== node.sid) {
|
|
450
|
+
data.uid = node.uid;
|
|
451
|
+
}
|
|
425
452
|
if (!node.isAnyEventBinded() && SPECIAL_NODES.indexOf(nodeName) > -1) {
|
|
426
453
|
data["nn" /* Shortcuts.NodeName */] = `static-${nodeName}`;
|
|
427
454
|
if (nodeName === VIEW && !isHasExtractProp(node)) {
|
|
428
455
|
data["nn" /* Shortcuts.NodeName */] = PURE_VIEW;
|
|
429
456
|
}
|
|
430
457
|
}
|
|
431
|
-
// Id
|
|
432
|
-
if (node.uid !== node.sid) {
|
|
433
|
-
data.uid = node.uid;
|
|
434
|
-
}
|
|
435
|
-
// Class
|
|
436
|
-
if (node.className !== '') {
|
|
437
|
-
data["cl" /* Shortcuts.Class */] = node.className;
|
|
438
|
-
}
|
|
439
|
-
// Style
|
|
440
|
-
const cssText = node.cssText;
|
|
441
|
-
if (cssText !== '' && nodeName !== 'swiper-item') {
|
|
442
|
-
data["st" /* Shortcuts.Style */] = cssText;
|
|
443
|
-
}
|
|
444
|
-
// Attributes
|
|
445
458
|
const { props } = node;
|
|
446
459
|
for (const prop in props) {
|
|
447
460
|
const propInCamelCase = toCamelCase(prop);
|
|
@@ -453,18 +466,26 @@ function hydrateElementNode(node) {
|
|
|
453
466
|
propInCamelCase !== COMPILE_MODE) {
|
|
454
467
|
data[propInCamelCase] = props[prop];
|
|
455
468
|
}
|
|
456
|
-
if (
|
|
469
|
+
if (process.env.TARO_ENV !== 'swan' &&
|
|
470
|
+
nodeName === VIEW &&
|
|
471
|
+
propInCamelCase === CATCHMOVE &&
|
|
472
|
+
props[prop] !== false) {
|
|
457
473
|
data["nn" /* Shortcuts.NodeName */] = CATCH_VIEW;
|
|
458
474
|
}
|
|
459
475
|
if (propInCamelCase === COMPILE_MODE) {
|
|
460
|
-
|
|
476
|
+
compileModeName = props[prop];
|
|
461
477
|
}
|
|
462
478
|
}
|
|
463
479
|
// Children
|
|
464
|
-
data["cn" /* Shortcuts.Childnodes */] = node.childNodes.filter(
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
480
|
+
data["cn" /* Shortcuts.Childnodes */] = node.childNodes.filter(node => !isComment(node)).map(hydrate);
|
|
481
|
+
if (node.className !== '') {
|
|
482
|
+
data["cl" /* Shortcuts.Class */] = node.className;
|
|
483
|
+
}
|
|
484
|
+
const cssText = node.cssText;
|
|
485
|
+
if (cssText !== '' && nodeName !== 'swiper-item') {
|
|
486
|
+
data["st" /* Shortcuts.Style */] = cssText;
|
|
487
|
+
}
|
|
488
|
+
hooks.call('modifyHydrateData', data, node);
|
|
468
489
|
const nn = data["nn" /* Shortcuts.NodeName */];
|
|
469
490
|
const componentAlias = componentsAlias[nn];
|
|
470
491
|
if (componentAlias) {
|
|
@@ -476,25 +497,11 @@ function hydrateElementNode(node) {
|
|
|
476
497
|
}
|
|
477
498
|
}
|
|
478
499
|
}
|
|
479
|
-
if (
|
|
480
|
-
data["nn" /* Shortcuts.NodeName */] =
|
|
481
|
-
}
|
|
482
|
-
return data;
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* React also has a fancy function's name for this: `hydrate()`.
|
|
486
|
-
* You may have been heard `hydrate` as a SSR-related function,
|
|
487
|
-
* actually, `hydrate` basicly do the `render()` thing, but ignore some properties,
|
|
488
|
-
* it's a vnode traverser and modifier: that's exactly what Taro's doing in here.
|
|
489
|
-
*/
|
|
490
|
-
function hydrate(node) {
|
|
491
|
-
initConfig();
|
|
492
|
-
if (isText(node)) {
|
|
493
|
-
return hydrateTextNode(node);
|
|
494
|
-
}
|
|
495
|
-
else {
|
|
496
|
-
return hydrateElementNode(node);
|
|
500
|
+
if (compileModeName !== null) {
|
|
501
|
+
data["nn" /* Shortcuts.NodeName */] = compileModeName;
|
|
497
502
|
}
|
|
503
|
+
const resData = hooks.call('transferHydrateData', data, node, componentAlias);
|
|
504
|
+
return resData || data;
|
|
498
505
|
}
|
|
499
506
|
|
|
500
507
|
class TaroEventTarget {
|
|
@@ -670,7 +677,7 @@ class TaroNode extends TaroEventTarget {
|
|
|
670
677
|
this.updateChildNodes();
|
|
671
678
|
}
|
|
672
679
|
// @Todo: appendChild 会多触发一次
|
|
673
|
-
MutationObserver.record({
|
|
680
|
+
MutationObserver$1.record({
|
|
674
681
|
type: "childList" /* MutationRecordType.CHILD_LIST */,
|
|
675
682
|
target: this,
|
|
676
683
|
removedNodes,
|
|
@@ -755,7 +762,7 @@ class TaroNode extends TaroEventTarget {
|
|
|
755
762
|
}
|
|
756
763
|
}
|
|
757
764
|
}
|
|
758
|
-
MutationObserver.record({
|
|
765
|
+
MutationObserver$1.record({
|
|
759
766
|
type: "childList" /* MutationRecordType.CHILD_LIST */,
|
|
760
767
|
target: this,
|
|
761
768
|
addedNodes: [newChild],
|
|
@@ -811,7 +818,7 @@ class TaroNode extends TaroEventTarget {
|
|
|
811
818
|
if (cleanRef !== false && doUpdate !== false) {
|
|
812
819
|
// appendChild/replaceChild/insertBefore 不应该触发
|
|
813
820
|
// @Todo: 但其实如果 newChild 的父节点是另一颗子树的节点,应该是要触发的
|
|
814
|
-
MutationObserver.record({
|
|
821
|
+
MutationObserver$1.record({
|
|
815
822
|
type: "childList" /* MutationRecordType.CHILD_LIST */,
|
|
816
823
|
target: this,
|
|
817
824
|
removedNodes: [child],
|
|
@@ -1037,7 +1044,7 @@ combine('box', ['DecorationBreak', 'Shadow', 'Sizing', 'Snap'], true);
|
|
|
1037
1044
|
combine(WEBKIT, ['LineClamp', 'BoxOrient', 'TextFillColor', 'TextStroke', 'TextStrokeColor', 'TextStrokeWidth'], true);
|
|
1038
1045
|
|
|
1039
1046
|
function recordCss(obj) {
|
|
1040
|
-
MutationObserver.record({
|
|
1047
|
+
MutationObserver$1.record({
|
|
1041
1048
|
type: "attributes" /* MutationRecordType.ATTRIBUTES */,
|
|
1042
1049
|
target: obj._element,
|
|
1043
1050
|
attributeName: 'style',
|
|
@@ -1059,7 +1066,7 @@ function setStyle(newVal, styleKey) {
|
|
|
1059
1066
|
if (old === newVal)
|
|
1060
1067
|
return;
|
|
1061
1068
|
!this._pending && recordCss(this);
|
|
1062
|
-
if (isNull(newVal) || isUndefined(newVal)) {
|
|
1069
|
+
if (isNull(newVal) || isUndefined(newVal) || newVal === '') {
|
|
1063
1070
|
this._usedStyleProp.delete(styleKey);
|
|
1064
1071
|
delete this._value[styleKey];
|
|
1065
1072
|
}
|
|
@@ -1318,7 +1325,7 @@ class TaroElement extends TaroNode {
|
|
|
1318
1325
|
process.env.NODE_ENV !== 'production' && warn(isString(value) && value.length > PROPERTY_THRESHOLD, `元素 ${this.nodeName} 的 ${qualifiedName} 属性值数据量过大,可能会影响渲染性能。考虑降低图片转为 base64 的阈值或在 CSS 中使用 base64。`);
|
|
1319
1326
|
const isPureView = this.nodeName === VIEW && !isHasExtractProp(this) && !this.isAnyEventBinded();
|
|
1320
1327
|
if (qualifiedName !== STYLE) {
|
|
1321
|
-
MutationObserver.record({
|
|
1328
|
+
MutationObserver$1.record({
|
|
1322
1329
|
target: this,
|
|
1323
1330
|
type: "attributes" /* MutationRecordType.ATTRIBUTES */,
|
|
1324
1331
|
attributeName: qualifiedName,
|
|
@@ -1390,7 +1397,7 @@ class TaroElement extends TaroNode {
|
|
|
1390
1397
|
}
|
|
1391
1398
|
removeAttribute(qualifiedName) {
|
|
1392
1399
|
const isStaticView = this.nodeName === VIEW && isHasExtractProp(this) && !this.isAnyEventBinded();
|
|
1393
|
-
MutationObserver.record({
|
|
1400
|
+
MutationObserver$1.record({
|
|
1394
1401
|
target: this,
|
|
1395
1402
|
type: "attributes" /* MutationRecordType.ATTRIBUTES */,
|
|
1396
1403
|
attributeName: qualifiedName,
|
|
@@ -1483,7 +1490,10 @@ class TaroElement extends TaroNode {
|
|
|
1483
1490
|
event.defaultPrevented = true;
|
|
1484
1491
|
}
|
|
1485
1492
|
if (!isUndefined(result) && event.mpEvent) {
|
|
1486
|
-
|
|
1493
|
+
const res = hooks.call('modifyTaroEventReturn', this, event, result);
|
|
1494
|
+
if (res) {
|
|
1495
|
+
event.mpEvent[EVENT_CALLBACK_RESULT] = result;
|
|
1496
|
+
}
|
|
1487
1497
|
}
|
|
1488
1498
|
if (event._end && event._stop) {
|
|
1489
1499
|
break;
|
|
@@ -1505,6 +1515,7 @@ class TaroElement extends TaroNode {
|
|
|
1505
1515
|
sideEffect = false;
|
|
1506
1516
|
delete options.sideEffect;
|
|
1507
1517
|
}
|
|
1518
|
+
hooks.call('modifyAddEventListener', this, sideEffect, getComponentsAlias);
|
|
1508
1519
|
if (sideEffect !== false && !this.isAnyEventBinded() && SPECIAL_NODES.indexOf(name) > -1) {
|
|
1509
1520
|
const componentsAlias = getComponentsAlias();
|
|
1510
1521
|
const alias = componentsAlias[name]._num;
|
|
@@ -1519,6 +1530,7 @@ class TaroElement extends TaroNode {
|
|
|
1519
1530
|
super.removeEventListener(type, handler);
|
|
1520
1531
|
const name = this.nodeName;
|
|
1521
1532
|
const SPECIAL_NODES = hooks.call('getSpecialNodes');
|
|
1533
|
+
hooks.call('modifyRemoveEventListener', this, sideEffect, getComponentsAlias);
|
|
1522
1534
|
if (sideEffect !== false && !this.isAnyEventBinded() && SPECIAL_NODES.indexOf(name) > -1) {
|
|
1523
1535
|
const componentsAlias = getComponentsAlias();
|
|
1524
1536
|
const value = isHasExtractProp(this) ? `static-${name}` : `pure-${name}`;
|
|
@@ -2092,15 +2104,30 @@ const specialMiniElements = {
|
|
|
2092
2104
|
img: 'image',
|
|
2093
2105
|
iframe: 'web-view'
|
|
2094
2106
|
};
|
|
2107
|
+
const specialElements = new Map([
|
|
2108
|
+
['a', {
|
|
2109
|
+
mapName(props) {
|
|
2110
|
+
if (props.as && isString(props.as))
|
|
2111
|
+
return props.as.toLowerCase();
|
|
2112
|
+
return !props.href || isString(props.href) && (/^javascript/.test(props.href)) ? 'view' : 'navigator';
|
|
2113
|
+
}
|
|
2114
|
+
}],
|
|
2115
|
+
]);
|
|
2116
|
+
const getSpecialElementMapping = (tag, expectsLowerCase = true) => {
|
|
2117
|
+
tag = expectsLowerCase ? tag.toLowerCase() : tag;
|
|
2118
|
+
return specialElements.get(tag);
|
|
2119
|
+
};
|
|
2095
2120
|
const internalCompsList = Object.keys(internalComponents)
|
|
2096
2121
|
.map(i => i.toLowerCase())
|
|
2097
2122
|
.join(',');
|
|
2098
2123
|
// https://developers.weixin.qq.com/miniprogram/dev/component
|
|
2099
2124
|
const isMiniElements = makeMap(internalCompsList, true);
|
|
2100
2125
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
|
|
2101
|
-
const isInlineElements = makeMap('
|
|
2126
|
+
const isInlineElements = makeMap('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);
|
|
2102
2127
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
|
|
2103
2128
|
const isBlockElements = makeMap('address,fieldset,li,article,figcaption,main,aside,figure,nav,blockquote,footer,ol,details,form,p,dialog,h1,h2,h3,h4,h5,h6,pre,dd,header,section,div,hgroup,table,dl,hr,ul,dt', true);
|
|
2129
|
+
// specialElements
|
|
2130
|
+
const isSpecialElements = makeMap('a', true);
|
|
2104
2131
|
|
|
2105
2132
|
const closingTagAncestorBreakers = {
|
|
2106
2133
|
li: ['ul', 'ol', 'menu'],
|
|
@@ -2129,7 +2156,21 @@ function hasTerminalParent(tagName, stack) {
|
|
|
2129
2156
|
}
|
|
2130
2157
|
return false;
|
|
2131
2158
|
}
|
|
2132
|
-
|
|
2159
|
+
/**
|
|
2160
|
+
* 将属性数组转换为属性对象
|
|
2161
|
+
* @param attributes 字符串数组,包含属性信息
|
|
2162
|
+
* @returns 属性对象,键为属性名,值为属性值或true
|
|
2163
|
+
*/
|
|
2164
|
+
function attributesArray2Props(attributes) {
|
|
2165
|
+
const props = {};
|
|
2166
|
+
for (let i = 0; i < attributes.length; i++) {
|
|
2167
|
+
const attr = attributes[i];
|
|
2168
|
+
const [key, value] = splitEqual(attr);
|
|
2169
|
+
props[key] = value == null ? true : unquote(value);
|
|
2170
|
+
}
|
|
2171
|
+
return props;
|
|
2172
|
+
}
|
|
2173
|
+
function getTagName(tag, attributes) {
|
|
2133
2174
|
if (options.html.renderHTMLTag) {
|
|
2134
2175
|
return tag;
|
|
2135
2176
|
}
|
|
@@ -2145,6 +2186,14 @@ function getTagName(tag) {
|
|
|
2145
2186
|
else if (isInlineElements(tag)) {
|
|
2146
2187
|
return 'text';
|
|
2147
2188
|
}
|
|
2189
|
+
else if (isSpecialElements(tag)) {
|
|
2190
|
+
// if it's special tag, the real tag is determined by the config mapping
|
|
2191
|
+
const mapping = getSpecialElementMapping(tag);
|
|
2192
|
+
const props = attributesArray2Props(attributes);
|
|
2193
|
+
if (mapping) {
|
|
2194
|
+
return mapping.mapName(props);
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2148
2197
|
return 'view';
|
|
2149
2198
|
}
|
|
2150
2199
|
function splitEqual(str) {
|
|
@@ -2178,7 +2227,26 @@ function format(children, document, styleOptions, parent) {
|
|
|
2178
2227
|
parent === null || parent === void 0 ? void 0 : parent.appendChild(text);
|
|
2179
2228
|
return text;
|
|
2180
2229
|
}
|
|
2181
|
-
|
|
2230
|
+
// img标签,把width和height写入style,删除原有的width、height和style属性
|
|
2231
|
+
if (child.tagName === 'img') {
|
|
2232
|
+
let styleText = '';
|
|
2233
|
+
const toBeRemovedIndexs = [];
|
|
2234
|
+
for (let i = 0; i < child.attributes.length; i++) {
|
|
2235
|
+
const attr = child.attributes[i];
|
|
2236
|
+
const [key, value] = splitEqual(attr);
|
|
2237
|
+
if (key === 'width' || key === 'height') {
|
|
2238
|
+
styleText += `${key}:${value};`;
|
|
2239
|
+
toBeRemovedIndexs.push(i);
|
|
2240
|
+
}
|
|
2241
|
+
else if (key === 'style') {
|
|
2242
|
+
styleText = `${styleText}${value};`;
|
|
2243
|
+
toBeRemovedIndexs.push(i);
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
child.attributes = child.attributes.filter((_, index) => !toBeRemovedIndexs.includes(index));
|
|
2247
|
+
child.attributes.push(`style=${styleText.replace(/['"]/g, '')}`);
|
|
2248
|
+
}
|
|
2249
|
+
const el = document.createElement(getTagName(child.tagName, child.attributes));
|
|
2182
2250
|
el.h5tagName = child.tagName;
|
|
2183
2251
|
parent === null || parent === void 0 ? void 0 : parent.appendChild(el);
|
|
2184
2252
|
if (!options.html.renderHTMLTag) {
|
|
@@ -2397,6 +2465,7 @@ function cloneNode(isDeep = false) {
|
|
|
2397
2465
|
}
|
|
2398
2466
|
for (const key in this) {
|
|
2399
2467
|
const value = this[key];
|
|
2468
|
+
// eslint-disable-next-line valid-typeof
|
|
2400
2469
|
if ([PROPS, DATASET].includes(key) && typeof value === OBJECT) {
|
|
2401
2470
|
newNode[key] = Object.assign({}, value);
|
|
2402
2471
|
}
|
|
@@ -2425,7 +2494,7 @@ function contains(node) {
|
|
|
2425
2494
|
return isContains;
|
|
2426
2495
|
}
|
|
2427
2496
|
|
|
2428
|
-
if (
|
|
2497
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
2429
2498
|
if (ENABLE_INNER_HTML) {
|
|
2430
2499
|
TaroNode.extend('innerHTML', {
|
|
2431
2500
|
set(html) {
|
|
@@ -2483,13 +2552,15 @@ class TaroEvent {
|
|
|
2483
2552
|
this.defaultPrevented = true;
|
|
2484
2553
|
}
|
|
2485
2554
|
get target() {
|
|
2486
|
-
var _a, _b, _c;
|
|
2555
|
+
var _a, _b, _c, _d, _e;
|
|
2487
2556
|
const cacheTarget = this.cacheTarget;
|
|
2488
2557
|
if (!cacheTarget) {
|
|
2489
2558
|
const target = Object.create(((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.target) || null);
|
|
2490
|
-
const
|
|
2491
|
-
|
|
2492
|
-
|
|
2559
|
+
const currentEle = env.document.getElementById(((_b = target.dataset) === null || _b === void 0 ? void 0 : _b.sid) || target.id || null);
|
|
2560
|
+
// Note:优先判断冒泡场景alipay的targetDataset的sid, 不然冒泡场景target属性吐出不对,其余拿取当前绑定id
|
|
2561
|
+
const element = env.document.getElementById(((_c = target.targetDataset) === null || _c === void 0 ? void 0 : _c.sid) || ((_d = target.dataset) === null || _d === void 0 ? void 0 : _d.sid) || target.id || null);
|
|
2562
|
+
target.dataset = Object.assign(Object.assign({}, (currentEle !== null ? currentEle.dataset : EMPTY_OBJ)), (element !== null ? element.dataset : EMPTY_OBJ));
|
|
2563
|
+
for (const key in (_e = this.mpEvent) === null || _e === void 0 ? void 0 : _e.detail) {
|
|
2493
2564
|
target[key] = this.mpEvent.detail[key];
|
|
2494
2565
|
}
|
|
2495
2566
|
this.cacheTarget = target;
|
|
@@ -2825,7 +2896,7 @@ class TaroText extends TaroNode {
|
|
|
2825
2896
|
this._value = value;
|
|
2826
2897
|
}
|
|
2827
2898
|
set textContent(text) {
|
|
2828
|
-
MutationObserver.record({
|
|
2899
|
+
MutationObserver$1.record({
|
|
2829
2900
|
target: this,
|
|
2830
2901
|
type: "characterData" /* MutationRecordType.CHARACTER_DATA */,
|
|
2831
2902
|
oldValue: this._value
|
|
@@ -2853,35 +2924,7 @@ class TaroText extends TaroNode {
|
|
|
2853
2924
|
}
|
|
2854
2925
|
}
|
|
2855
2926
|
|
|
2856
|
-
|
|
2857
|
-
Copyright (c) Microsoft Corporation.
|
|
2858
|
-
|
|
2859
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
2860
|
-
purpose with or without fee is hereby granted.
|
|
2861
|
-
|
|
2862
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
2863
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
2864
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
2865
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
2866
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
2867
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
2868
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
2869
|
-
***************************************************************************** */
|
|
2870
|
-
|
|
2871
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
2872
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
2873
|
-
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");
|
|
2874
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
2875
|
-
}
|
|
2876
|
-
|
|
2877
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
2878
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
2879
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
2880
|
-
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");
|
|
2881
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
2882
|
-
}
|
|
2883
|
-
|
|
2884
|
-
var _URLSearchParams_dict;
|
|
2927
|
+
var _dict, _a;
|
|
2885
2928
|
const findReg = /[!'()~]|%20|%00/g;
|
|
2886
2929
|
const plusReg = /\+/g;
|
|
2887
2930
|
const replaceCharMap = {
|
|
@@ -2912,93 +2955,102 @@ function decode(str) {
|
|
|
2912
2955
|
function encode(str) {
|
|
2913
2956
|
return encodeURIComponent(str).replace(findReg, replacer);
|
|
2914
2957
|
}
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
}
|
|
2924
|
-
for (let pairs = query.split('&'), i = 0, length = pairs.length; i < length; i++) {
|
|
2925
|
-
const value = pairs[i];
|
|
2926
|
-
const index = value.indexOf('=');
|
|
2927
|
-
if (index > -1) {
|
|
2928
|
-
appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));
|
|
2929
|
-
}
|
|
2930
|
-
else if (value.length) {
|
|
2931
|
-
appendTo(dict, decode(value), '');
|
|
2958
|
+
const URLSearchParams = process.env.TARO_PLATFORM === 'web' ? env.window.URLSearchParams : (_a = class {
|
|
2959
|
+
constructor(query) {
|
|
2960
|
+
_dict.set(this, Object.create(null));
|
|
2961
|
+
query !== null && query !== void 0 ? query : (query = '');
|
|
2962
|
+
const dict = __classPrivateFieldGet(this, _dict, "f");
|
|
2963
|
+
if (typeof query === 'string') {
|
|
2964
|
+
if (query.charAt(0) === '?') {
|
|
2965
|
+
query = query.slice(1);
|
|
2932
2966
|
}
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2967
|
+
for (let pairs = query.split('&'), i = 0, length = pairs.length; i < length; i++) {
|
|
2968
|
+
const value = pairs[i];
|
|
2969
|
+
const index = value.indexOf('=');
|
|
2970
|
+
// 针对不规范的 url 参数做容错处理,如:word=你%好
|
|
2971
|
+
try {
|
|
2972
|
+
if (index > -1) {
|
|
2973
|
+
appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));
|
|
2974
|
+
}
|
|
2975
|
+
else if (value.length) {
|
|
2976
|
+
appendTo(dict, decode(value), '');
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
catch (err) {
|
|
2980
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2981
|
+
console.warn(`[Taro warn] URL 参数 ${value} decode 异常`);
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2940
2984
|
}
|
|
2941
2985
|
}
|
|
2942
|
-
else if (query.forEach) {
|
|
2943
|
-
query.forEach(addEach, dict);
|
|
2944
|
-
}
|
|
2945
2986
|
else {
|
|
2946
|
-
|
|
2947
|
-
|
|
2987
|
+
if (isArray(query)) {
|
|
2988
|
+
for (let i = 0, length = query.length; i < length; i++) {
|
|
2989
|
+
const value = query[i];
|
|
2990
|
+
appendTo(dict, value[0], value[1]);
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
else if (query.forEach) {
|
|
2994
|
+
query.forEach(addEach, dict);
|
|
2995
|
+
}
|
|
2996
|
+
else {
|
|
2997
|
+
for (const key in query) {
|
|
2998
|
+
appendTo(dict, key, query[key]);
|
|
2999
|
+
}
|
|
2948
3000
|
}
|
|
2949
3001
|
}
|
|
2950
3002
|
}
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
3003
|
+
append(name, value) {
|
|
3004
|
+
appendTo(__classPrivateFieldGet(this, _dict, "f"), name, value);
|
|
3005
|
+
}
|
|
3006
|
+
delete(name) {
|
|
3007
|
+
delete __classPrivateFieldGet(this, _dict, "f")[name];
|
|
3008
|
+
}
|
|
3009
|
+
get(name) {
|
|
3010
|
+
const dict = __classPrivateFieldGet(this, _dict, "f");
|
|
3011
|
+
return name in dict ? dict[name][0] : null;
|
|
3012
|
+
}
|
|
3013
|
+
getAll(name) {
|
|
3014
|
+
const dict = __classPrivateFieldGet(this, _dict, "f");
|
|
3015
|
+
return name in dict ? dict[name].slice(0) : [];
|
|
3016
|
+
}
|
|
3017
|
+
has(name) {
|
|
3018
|
+
return name in __classPrivateFieldGet(this, _dict, "f");
|
|
3019
|
+
}
|
|
3020
|
+
keys() {
|
|
3021
|
+
return Object.keys(__classPrivateFieldGet(this, _dict, "f"));
|
|
3022
|
+
}
|
|
3023
|
+
set(name, value) {
|
|
3024
|
+
__classPrivateFieldGet(this, _dict, "f")[name] = ['' + value];
|
|
3025
|
+
}
|
|
3026
|
+
forEach(callback, thisArg) {
|
|
3027
|
+
const dict = __classPrivateFieldGet(this, _dict, "f");
|
|
3028
|
+
Object.getOwnPropertyNames(dict).forEach(function (name) {
|
|
3029
|
+
dict[name].forEach(function (value) {
|
|
3030
|
+
callback.call(thisArg, value, name, this);
|
|
3031
|
+
}, this);
|
|
2980
3032
|
}, this);
|
|
2981
|
-
}
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
3033
|
+
}
|
|
3034
|
+
toJSON() {
|
|
3035
|
+
return {};
|
|
3036
|
+
}
|
|
3037
|
+
toString() {
|
|
3038
|
+
const dict = __classPrivateFieldGet(this, _dict, "f");
|
|
3039
|
+
const query = [];
|
|
3040
|
+
for (const key in dict) {
|
|
3041
|
+
const name = encode(key);
|
|
3042
|
+
for (let i = 0, value = dict[key]; i < value.length; i++) {
|
|
3043
|
+
query.push(name + '=' + encode(value[i]));
|
|
3044
|
+
}
|
|
2993
3045
|
}
|
|
3046
|
+
return query.join('&');
|
|
2994
3047
|
}
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
_URLSearchParams_dict = new WeakMap();
|
|
3048
|
+
},
|
|
3049
|
+
_dict = new WeakMap(),
|
|
3050
|
+
_a);
|
|
2999
3051
|
|
|
3000
|
-
var
|
|
3001
|
-
class
|
|
3052
|
+
var _TaroURL_hash, _TaroURL_hostname, _TaroURL_pathname, _TaroURL_port, _TaroURL_protocol, _TaroURL_search;
|
|
3053
|
+
class TaroURL {
|
|
3002
3054
|
static createObjectURL() {
|
|
3003
3055
|
throw new Error('Oops, not support URL.createObjectURL() in miniprogram.');
|
|
3004
3056
|
}
|
|
@@ -3007,29 +3059,29 @@ class URL {
|
|
|
3007
3059
|
}
|
|
3008
3060
|
constructor(url, base) {
|
|
3009
3061
|
/* private property */
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3062
|
+
_TaroURL_hash.set(this, '');
|
|
3063
|
+
_TaroURL_hostname.set(this, '');
|
|
3064
|
+
_TaroURL_pathname.set(this, '');
|
|
3065
|
+
_TaroURL_port.set(this, '');
|
|
3066
|
+
_TaroURL_protocol.set(this, '');
|
|
3067
|
+
_TaroURL_search.set(this, void 0);
|
|
3016
3068
|
if (!isString(url))
|
|
3017
3069
|
url = String(url);
|
|
3018
3070
|
const parseResult = parseUrlBase(url, base);
|
|
3019
3071
|
const { hash, hostname, pathname, port, protocol, search } = parseResult;
|
|
3020
|
-
__classPrivateFieldSet(this,
|
|
3021
|
-
__classPrivateFieldSet(this,
|
|
3022
|
-
__classPrivateFieldSet(this,
|
|
3023
|
-
__classPrivateFieldSet(this,
|
|
3024
|
-
__classPrivateFieldSet(this,
|
|
3025
|
-
__classPrivateFieldSet(this,
|
|
3072
|
+
__classPrivateFieldSet(this, _TaroURL_hash, hash, "f");
|
|
3073
|
+
__classPrivateFieldSet(this, _TaroURL_hostname, hostname, "f");
|
|
3074
|
+
__classPrivateFieldSet(this, _TaroURL_pathname, pathname || '/', "f");
|
|
3075
|
+
__classPrivateFieldSet(this, _TaroURL_port, port, "f");
|
|
3076
|
+
__classPrivateFieldSet(this, _TaroURL_protocol, protocol, "f");
|
|
3077
|
+
__classPrivateFieldSet(this, _TaroURL_search, new URLSearchParams(search), "f");
|
|
3026
3078
|
}
|
|
3027
3079
|
/* public property */
|
|
3028
3080
|
get protocol() {
|
|
3029
|
-
return __classPrivateFieldGet(this,
|
|
3081
|
+
return __classPrivateFieldGet(this, _TaroURL_protocol, "f");
|
|
3030
3082
|
}
|
|
3031
3083
|
set protocol(val) {
|
|
3032
|
-
isString(val) && (__classPrivateFieldSet(this,
|
|
3084
|
+
isString(val) && (__classPrivateFieldSet(this, _TaroURL_protocol, val.trim(), "f"));
|
|
3033
3085
|
}
|
|
3034
3086
|
get host() {
|
|
3035
3087
|
return this.hostname + (this.port ? ':' + this.port : '');
|
|
@@ -3043,19 +3095,19 @@ class URL {
|
|
|
3043
3095
|
}
|
|
3044
3096
|
}
|
|
3045
3097
|
get hostname() {
|
|
3046
|
-
return __classPrivateFieldGet(this,
|
|
3098
|
+
return __classPrivateFieldGet(this, _TaroURL_hostname, "f");
|
|
3047
3099
|
}
|
|
3048
3100
|
set hostname(val) {
|
|
3049
|
-
val && isString(val) && (__classPrivateFieldSet(this,
|
|
3101
|
+
val && isString(val) && (__classPrivateFieldSet(this, _TaroURL_hostname, val.trim(), "f"));
|
|
3050
3102
|
}
|
|
3051
3103
|
get port() {
|
|
3052
|
-
return __classPrivateFieldGet(this,
|
|
3104
|
+
return __classPrivateFieldGet(this, _TaroURL_port, "f");
|
|
3053
3105
|
}
|
|
3054
3106
|
set port(val) {
|
|
3055
|
-
isString(val) && (__classPrivateFieldSet(this,
|
|
3107
|
+
isString(val) && (__classPrivateFieldSet(this, _TaroURL_port, val.trim(), "f"));
|
|
3056
3108
|
}
|
|
3057
3109
|
get pathname() {
|
|
3058
|
-
return __classPrivateFieldGet(this,
|
|
3110
|
+
return __classPrivateFieldGet(this, _TaroURL_pathname, "f");
|
|
3059
3111
|
}
|
|
3060
3112
|
set pathname(val) {
|
|
3061
3113
|
if (isString(val)) {
|
|
@@ -3066,31 +3118,31 @@ class URL {
|
|
|
3066
3118
|
temp = temp.replace(HEAD_REG, '');
|
|
3067
3119
|
}
|
|
3068
3120
|
if (temp)
|
|
3069
|
-
__classPrivateFieldSet(this,
|
|
3121
|
+
__classPrivateFieldSet(this, _TaroURL_pathname, '/' + temp, "f");
|
|
3070
3122
|
else
|
|
3071
|
-
__classPrivateFieldSet(this,
|
|
3123
|
+
__classPrivateFieldSet(this, _TaroURL_pathname, '/', "f");
|
|
3072
3124
|
}
|
|
3073
3125
|
}
|
|
3074
3126
|
get search() {
|
|
3075
|
-
const val = __classPrivateFieldGet(this,
|
|
3127
|
+
const val = __classPrivateFieldGet(this, _TaroURL_search, "f").toString();
|
|
3076
3128
|
return (val.length === 0 || val.startsWith('?')) ? val : `?${val}`;
|
|
3077
3129
|
}
|
|
3078
3130
|
set search(val) {
|
|
3079
3131
|
if (isString(val)) {
|
|
3080
3132
|
val = val.trim();
|
|
3081
|
-
__classPrivateFieldSet(this,
|
|
3133
|
+
__classPrivateFieldSet(this, _TaroURL_search, new URLSearchParams(val), "f");
|
|
3082
3134
|
}
|
|
3083
3135
|
}
|
|
3084
3136
|
get hash() {
|
|
3085
|
-
return __classPrivateFieldGet(this,
|
|
3137
|
+
return __classPrivateFieldGet(this, _TaroURL_hash, "f");
|
|
3086
3138
|
}
|
|
3087
3139
|
set hash(val) {
|
|
3088
3140
|
if (isString(val)) {
|
|
3089
3141
|
val = val.trim();
|
|
3090
3142
|
if (val)
|
|
3091
|
-
__classPrivateFieldSet(this,
|
|
3143
|
+
__classPrivateFieldSet(this, _TaroURL_hash, val.startsWith('#') ? val : `#${val}`, "f");
|
|
3092
3144
|
else
|
|
3093
|
-
__classPrivateFieldSet(this,
|
|
3145
|
+
__classPrivateFieldSet(this, _TaroURL_hash, '', "f");
|
|
3094
3146
|
}
|
|
3095
3147
|
}
|
|
3096
3148
|
get href() {
|
|
@@ -3121,7 +3173,7 @@ class URL {
|
|
|
3121
3173
|
}
|
|
3122
3174
|
}
|
|
3123
3175
|
get searchParams() {
|
|
3124
|
-
return __classPrivateFieldGet(this,
|
|
3176
|
+
return __classPrivateFieldGet(this, _TaroURL_search, "f");
|
|
3125
3177
|
}
|
|
3126
3178
|
// public method
|
|
3127
3179
|
toString() {
|
|
@@ -3145,7 +3197,8 @@ class URL {
|
|
|
3145
3197
|
};
|
|
3146
3198
|
}
|
|
3147
3199
|
}
|
|
3148
|
-
|
|
3200
|
+
_TaroURL_hash = new WeakMap(), _TaroURL_hostname = new WeakMap(), _TaroURL_pathname = new WeakMap(), _TaroURL_port = new WeakMap(), _TaroURL_protocol = new WeakMap(), _TaroURL_search = new WeakMap();
|
|
3201
|
+
const URL = process.env.TARO_PLATFORM === 'web' ? env.window.URL : TaroURL;
|
|
3149
3202
|
function parseUrl(url = '') {
|
|
3150
3203
|
const result = {
|
|
3151
3204
|
href: '',
|
|
@@ -3259,6 +3312,17 @@ class AnchorElement extends TaroElement {
|
|
|
3259
3312
|
}
|
|
3260
3313
|
}
|
|
3261
3314
|
|
|
3315
|
+
class TransferElement extends TaroElement {
|
|
3316
|
+
constructor(dataName) {
|
|
3317
|
+
super();
|
|
3318
|
+
this.dataName = dataName;
|
|
3319
|
+
this.isTransferElement = true;
|
|
3320
|
+
}
|
|
3321
|
+
get _path() {
|
|
3322
|
+
return this.dataName;
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
|
|
3262
3326
|
class TaroDocument extends TaroElement {
|
|
3263
3327
|
constructor() {
|
|
3264
3328
|
super();
|
|
@@ -3279,6 +3343,10 @@ class TaroDocument extends TaroElement {
|
|
|
3279
3343
|
case nodeName === A:
|
|
3280
3344
|
element = new AnchorElement();
|
|
3281
3345
|
break;
|
|
3346
|
+
case nodeName === 'page-meta':
|
|
3347
|
+
case nodeName === 'navigation-bar':
|
|
3348
|
+
element = new TransferElement(toCamelCase(nodeName));
|
|
3349
|
+
break;
|
|
3282
3350
|
default:
|
|
3283
3351
|
element = new TaroElement();
|
|
3284
3352
|
break;
|
|
@@ -3321,49 +3389,42 @@ class TaroDocument extends TaroElement {
|
|
|
3321
3389
|
}
|
|
3322
3390
|
}
|
|
3323
3391
|
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
doc.head = head;
|
|
3355
|
-
doc.body = body;
|
|
3356
|
-
return doc;
|
|
3357
|
-
}
|
|
3358
|
-
document$1 = env.document = createDocument();
|
|
3359
|
-
}
|
|
3360
|
-
else {
|
|
3361
|
-
document$1 = env.document;
|
|
3392
|
+
function createDocument() {
|
|
3393
|
+
/**
|
|
3394
|
+
* <document>
|
|
3395
|
+
* <html>
|
|
3396
|
+
* <head></head>
|
|
3397
|
+
* <body>
|
|
3398
|
+
* <container>
|
|
3399
|
+
* <app id="app" />
|
|
3400
|
+
* </container>
|
|
3401
|
+
* </body>
|
|
3402
|
+
* </html>
|
|
3403
|
+
* </document>
|
|
3404
|
+
*/
|
|
3405
|
+
const doc = new TaroDocument();
|
|
3406
|
+
const documentCreateElement = doc.createElement.bind(doc);
|
|
3407
|
+
const html = documentCreateElement(HTML);
|
|
3408
|
+
const head = documentCreateElement(HEAD);
|
|
3409
|
+
const body = documentCreateElement(BODY);
|
|
3410
|
+
const app = documentCreateElement(APP);
|
|
3411
|
+
app.id = APP;
|
|
3412
|
+
const container = documentCreateElement(CONTAINER); // 多包一层主要为了兼容 vue
|
|
3413
|
+
doc.appendChild(html);
|
|
3414
|
+
html.appendChild(head);
|
|
3415
|
+
html.appendChild(body);
|
|
3416
|
+
body.appendChild(container);
|
|
3417
|
+
container.appendChild(app);
|
|
3418
|
+
doc.documentElement = html;
|
|
3419
|
+
doc.head = head;
|
|
3420
|
+
doc.body = body;
|
|
3421
|
+
return doc;
|
|
3362
3422
|
}
|
|
3423
|
+
const document$1 = process.env.TARO_PLATFORM === 'web' ? env.document : (env.document = createDocument());
|
|
3363
3424
|
|
|
3364
|
-
function
|
|
3425
|
+
const getComputedStyle = process.env.TARO_PLATFORM === 'web' ? env.window.getComputedStyle : function (element) {
|
|
3365
3426
|
return element.style;
|
|
3366
|
-
}
|
|
3427
|
+
};
|
|
3367
3428
|
|
|
3368
3429
|
const eventCenter = hooks.call('getEventCenter', Events);
|
|
3369
3430
|
|
|
@@ -3392,72 +3453,72 @@ class RuntimeCache {
|
|
|
3392
3453
|
}
|
|
3393
3454
|
}
|
|
3394
3455
|
|
|
3395
|
-
var
|
|
3456
|
+
var _TaroHistory_instances, _TaroHistory_location, _TaroHistory_stack, _TaroHistory_cur, _TaroHistory_window, _TaroHistory_reset;
|
|
3396
3457
|
const cache$1 = new RuntimeCache('history');
|
|
3397
|
-
class
|
|
3458
|
+
class TaroHistory extends Events {
|
|
3398
3459
|
constructor(location, options) {
|
|
3399
3460
|
super();
|
|
3400
|
-
|
|
3461
|
+
_TaroHistory_instances.add(this);
|
|
3401
3462
|
/* private property */
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
__classPrivateFieldSet(this,
|
|
3407
|
-
__classPrivateFieldSet(this,
|
|
3408
|
-
__classPrivateFieldGet(this,
|
|
3463
|
+
_TaroHistory_location.set(this, void 0);
|
|
3464
|
+
_TaroHistory_stack.set(this, []);
|
|
3465
|
+
_TaroHistory_cur.set(this, 0);
|
|
3466
|
+
_TaroHistory_window.set(this, void 0);
|
|
3467
|
+
__classPrivateFieldSet(this, _TaroHistory_window, options.window, "f");
|
|
3468
|
+
__classPrivateFieldSet(this, _TaroHistory_location, location, "f");
|
|
3469
|
+
__classPrivateFieldGet(this, _TaroHistory_location, "f").on('__record_history__', (href) => {
|
|
3409
3470
|
var _a;
|
|
3410
|
-
__classPrivateFieldSet(this,
|
|
3411
|
-
__classPrivateFieldSet(this,
|
|
3412
|
-
__classPrivateFieldGet(this,
|
|
3471
|
+
__classPrivateFieldSet(this, _TaroHistory_cur, (_a = __classPrivateFieldGet(this, _TaroHistory_cur, "f"), _a++, _a), "f");
|
|
3472
|
+
__classPrivateFieldSet(this, _TaroHistory_stack, __classPrivateFieldGet(this, _TaroHistory_stack, "f").slice(0, __classPrivateFieldGet(this, _TaroHistory_cur, "f")), "f");
|
|
3473
|
+
__classPrivateFieldGet(this, _TaroHistory_stack, "f").push({
|
|
3413
3474
|
state: null,
|
|
3414
3475
|
title: '',
|
|
3415
3476
|
url: href
|
|
3416
3477
|
});
|
|
3417
3478
|
}, null);
|
|
3418
|
-
__classPrivateFieldGet(this,
|
|
3419
|
-
__classPrivateFieldGet(this,
|
|
3479
|
+
__classPrivateFieldGet(this, _TaroHistory_location, "f").on('__reset_history__', (href) => {
|
|
3480
|
+
__classPrivateFieldGet(this, _TaroHistory_instances, "m", _TaroHistory_reset).call(this, href);
|
|
3420
3481
|
}, null);
|
|
3421
3482
|
// 切换上下文行为
|
|
3422
3483
|
this.on(CONTEXT_ACTIONS.INIT, () => {
|
|
3423
|
-
__classPrivateFieldGet(this,
|
|
3484
|
+
__classPrivateFieldGet(this, _TaroHistory_instances, "m", _TaroHistory_reset).call(this);
|
|
3424
3485
|
}, null);
|
|
3425
3486
|
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3426
3487
|
cache$1.set(pageId, {
|
|
3427
|
-
location: __classPrivateFieldGet(this,
|
|
3428
|
-
stack: __classPrivateFieldGet(this,
|
|
3429
|
-
cur: __classPrivateFieldGet(this,
|
|
3488
|
+
location: __classPrivateFieldGet(this, _TaroHistory_location, "f"),
|
|
3489
|
+
stack: __classPrivateFieldGet(this, _TaroHistory_stack, "f").slice(),
|
|
3490
|
+
cur: __classPrivateFieldGet(this, _TaroHistory_cur, "f")
|
|
3430
3491
|
});
|
|
3431
3492
|
}, null);
|
|
3432
3493
|
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
3433
3494
|
if (cache$1.has(pageId)) {
|
|
3434
3495
|
const ctx = cache$1.get(pageId);
|
|
3435
|
-
__classPrivateFieldSet(this,
|
|
3436
|
-
__classPrivateFieldSet(this,
|
|
3437
|
-
__classPrivateFieldSet(this,
|
|
3496
|
+
__classPrivateFieldSet(this, _TaroHistory_location, ctx.location, "f");
|
|
3497
|
+
__classPrivateFieldSet(this, _TaroHistory_stack, ctx.stack, "f");
|
|
3498
|
+
__classPrivateFieldSet(this, _TaroHistory_cur, ctx.cur, "f");
|
|
3438
3499
|
}
|
|
3439
3500
|
}, null);
|
|
3440
3501
|
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
3441
3502
|
cache$1.delete(pageId);
|
|
3442
3503
|
}, null);
|
|
3443
|
-
__classPrivateFieldGet(this,
|
|
3504
|
+
__classPrivateFieldGet(this, _TaroHistory_instances, "m", _TaroHistory_reset).call(this);
|
|
3444
3505
|
}
|
|
3445
3506
|
/* public property */
|
|
3446
3507
|
get length() {
|
|
3447
|
-
return __classPrivateFieldGet(this,
|
|
3508
|
+
return __classPrivateFieldGet(this, _TaroHistory_stack, "f").length;
|
|
3448
3509
|
}
|
|
3449
3510
|
get state() {
|
|
3450
|
-
return __classPrivateFieldGet(this,
|
|
3511
|
+
return __classPrivateFieldGet(this, _TaroHistory_stack, "f")[__classPrivateFieldGet(this, _TaroHistory_cur, "f")].state;
|
|
3451
3512
|
}
|
|
3452
3513
|
/* public method */
|
|
3453
3514
|
go(delta) {
|
|
3454
3515
|
if (!isNumber(delta) || isNaN(delta))
|
|
3455
3516
|
return;
|
|
3456
|
-
let targetIdx = __classPrivateFieldGet(this,
|
|
3517
|
+
let targetIdx = __classPrivateFieldGet(this, _TaroHistory_cur, "f") + delta;
|
|
3457
3518
|
targetIdx = Math.min(Math.max(targetIdx, 0), this.length - 1);
|
|
3458
|
-
__classPrivateFieldSet(this,
|
|
3459
|
-
__classPrivateFieldGet(this,
|
|
3460
|
-
__classPrivateFieldGet(this,
|
|
3519
|
+
__classPrivateFieldSet(this, _TaroHistory_cur, targetIdx, "f");
|
|
3520
|
+
__classPrivateFieldGet(this, _TaroHistory_location, "f").trigger('__set_href_without_history__', __classPrivateFieldGet(this, _TaroHistory_stack, "f")[__classPrivateFieldGet(this, _TaroHistory_cur, "f")].url);
|
|
3521
|
+
__classPrivateFieldGet(this, _TaroHistory_window, "f").trigger('popstate', __classPrivateFieldGet(this, _TaroHistory_stack, "f")[__classPrivateFieldGet(this, _TaroHistory_cur, "f")]);
|
|
3461
3522
|
}
|
|
3462
3523
|
back() {
|
|
3463
3524
|
this.go(-1);
|
|
@@ -3468,40 +3529,41 @@ class History extends Events {
|
|
|
3468
3529
|
pushState(state, title, url) {
|
|
3469
3530
|
if (!url || !isString(url))
|
|
3470
3531
|
return;
|
|
3471
|
-
__classPrivateFieldSet(this,
|
|
3472
|
-
__classPrivateFieldGet(this,
|
|
3532
|
+
__classPrivateFieldSet(this, _TaroHistory_stack, __classPrivateFieldGet(this, _TaroHistory_stack, "f").slice(0, __classPrivateFieldGet(this, _TaroHistory_cur, "f") + 1), "f");
|
|
3533
|
+
__classPrivateFieldGet(this, _TaroHistory_stack, "f").push({
|
|
3473
3534
|
state,
|
|
3474
3535
|
title,
|
|
3475
3536
|
url
|
|
3476
3537
|
});
|
|
3477
|
-
__classPrivateFieldSet(this,
|
|
3478
|
-
__classPrivateFieldGet(this,
|
|
3538
|
+
__classPrivateFieldSet(this, _TaroHistory_cur, this.length - 1, "f");
|
|
3539
|
+
__classPrivateFieldGet(this, _TaroHistory_location, "f").trigger('__set_href_without_history__', url);
|
|
3479
3540
|
}
|
|
3480
3541
|
replaceState(state, title, url) {
|
|
3481
3542
|
if (!url || !isString(url))
|
|
3482
3543
|
return;
|
|
3483
|
-
__classPrivateFieldGet(this,
|
|
3544
|
+
__classPrivateFieldGet(this, _TaroHistory_stack, "f")[__classPrivateFieldGet(this, _TaroHistory_cur, "f")] = {
|
|
3484
3545
|
state,
|
|
3485
3546
|
title,
|
|
3486
3547
|
url
|
|
3487
3548
|
};
|
|
3488
|
-
__classPrivateFieldGet(this,
|
|
3549
|
+
__classPrivateFieldGet(this, _TaroHistory_location, "f").trigger('__set_href_without_history__', url);
|
|
3489
3550
|
}
|
|
3490
3551
|
// For debug
|
|
3491
3552
|
get cache() {
|
|
3492
3553
|
return cache$1;
|
|
3493
3554
|
}
|
|
3494
3555
|
}
|
|
3495
|
-
|
|
3496
|
-
__classPrivateFieldSet(this,
|
|
3556
|
+
_TaroHistory_location = new WeakMap(), _TaroHistory_stack = new WeakMap(), _TaroHistory_cur = new WeakMap(), _TaroHistory_window = new WeakMap(), _TaroHistory_instances = new WeakSet(), _TaroHistory_reset = function _TaroHistory_reset(href = '') {
|
|
3557
|
+
__classPrivateFieldSet(this, _TaroHistory_stack, [
|
|
3497
3558
|
{
|
|
3498
3559
|
state: null,
|
|
3499
3560
|
title: '',
|
|
3500
|
-
url: href || __classPrivateFieldGet(this,
|
|
3561
|
+
url: href || __classPrivateFieldGet(this, _TaroHistory_location, "f").href
|
|
3501
3562
|
}
|
|
3502
3563
|
], "f");
|
|
3503
|
-
__classPrivateFieldSet(this,
|
|
3564
|
+
__classPrivateFieldSet(this, _TaroHistory_cur, 0, "f");
|
|
3504
3565
|
};
|
|
3566
|
+
const History = process.env.TARO_PLATFORM === 'web' ? env.window.History : TaroHistory;
|
|
3505
3567
|
|
|
3506
3568
|
const Current = {
|
|
3507
3569
|
app: null,
|
|
@@ -3510,31 +3572,31 @@ const Current = {
|
|
|
3510
3572
|
};
|
|
3511
3573
|
const getCurrentInstance = () => Current;
|
|
3512
3574
|
|
|
3513
|
-
var
|
|
3575
|
+
var _TaroLocation_instances, _TaroLocation_url, _TaroLocation_noCheckUrl, _TaroLocation_window, _TaroLocation_reset, _TaroLocation_getPreValue, _TaroLocation_rollBack, _TaroLocation_recordHistory, _TaroLocation_checkUrlChange;
|
|
3514
3576
|
const INIT_URL = 'https://taro.com';
|
|
3515
3577
|
const cache = new RuntimeCache('location');
|
|
3516
|
-
class
|
|
3578
|
+
class TaroLocation extends Events {
|
|
3517
3579
|
constructor(options) {
|
|
3518
3580
|
super();
|
|
3519
|
-
|
|
3581
|
+
_TaroLocation_instances.add(this);
|
|
3520
3582
|
/* private property */
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
__classPrivateFieldSet(this,
|
|
3525
|
-
__classPrivateFieldGet(this,
|
|
3583
|
+
_TaroLocation_url.set(this, new URL(INIT_URL));
|
|
3584
|
+
_TaroLocation_noCheckUrl.set(this, false);
|
|
3585
|
+
_TaroLocation_window.set(this, void 0);
|
|
3586
|
+
__classPrivateFieldSet(this, _TaroLocation_window, options.window, "f");
|
|
3587
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_reset).call(this);
|
|
3526
3588
|
this.on('__set_href_without_history__', (href) => {
|
|
3527
|
-
__classPrivateFieldSet(this,
|
|
3528
|
-
const lastHash = __classPrivateFieldGet(this,
|
|
3529
|
-
__classPrivateFieldGet(this,
|
|
3530
|
-
if (lastHash !== __classPrivateFieldGet(this,
|
|
3531
|
-
__classPrivateFieldGet(this,
|
|
3589
|
+
__classPrivateFieldSet(this, _TaroLocation_noCheckUrl, true, "f");
|
|
3590
|
+
const lastHash = __classPrivateFieldGet(this, _TaroLocation_url, "f").hash;
|
|
3591
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").href = generateFullUrl(href);
|
|
3592
|
+
if (lastHash !== __classPrivateFieldGet(this, _TaroLocation_url, "f").hash) {
|
|
3593
|
+
__classPrivateFieldGet(this, _TaroLocation_window, "f").trigger('hashchange');
|
|
3532
3594
|
}
|
|
3533
|
-
__classPrivateFieldSet(this,
|
|
3595
|
+
__classPrivateFieldSet(this, _TaroLocation_noCheckUrl, false, "f");
|
|
3534
3596
|
}, null);
|
|
3535
3597
|
// 切换上下文行为
|
|
3536
3598
|
this.on(CONTEXT_ACTIONS.INIT, () => {
|
|
3537
|
-
__classPrivateFieldGet(this,
|
|
3599
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_reset).call(this);
|
|
3538
3600
|
}, null);
|
|
3539
3601
|
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3540
3602
|
cache.set(pageId, {
|
|
@@ -3545,9 +3607,9 @@ class Location extends Events {
|
|
|
3545
3607
|
// 数据恢复时,不需要执行跳转
|
|
3546
3608
|
if (cache.has(pageId)) {
|
|
3547
3609
|
const ctx = cache.get(pageId);
|
|
3548
|
-
__classPrivateFieldSet(this,
|
|
3549
|
-
__classPrivateFieldGet(this,
|
|
3550
|
-
__classPrivateFieldSet(this,
|
|
3610
|
+
__classPrivateFieldSet(this, _TaroLocation_noCheckUrl, true, "f");
|
|
3611
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").href = ctx.lastHref;
|
|
3612
|
+
__classPrivateFieldSet(this, _TaroLocation_noCheckUrl, false, "f");
|
|
3551
3613
|
}
|
|
3552
3614
|
}, null);
|
|
3553
3615
|
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
@@ -3556,81 +3618,81 @@ class Location extends Events {
|
|
|
3556
3618
|
}
|
|
3557
3619
|
/* public property */
|
|
3558
3620
|
get protocol() {
|
|
3559
|
-
return __classPrivateFieldGet(this,
|
|
3621
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").protocol;
|
|
3560
3622
|
}
|
|
3561
3623
|
set protocol(val) {
|
|
3562
3624
|
const REG = /^(http|https):$/i;
|
|
3563
3625
|
if (!val || !isString(val) || !REG.test(val.trim()))
|
|
3564
3626
|
return;
|
|
3565
3627
|
val = val.trim();
|
|
3566
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3567
|
-
__classPrivateFieldGet(this,
|
|
3568
|
-
if (__classPrivateFieldGet(this,
|
|
3569
|
-
__classPrivateFieldGet(this,
|
|
3628
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3629
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").protocol = val;
|
|
3630
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3631
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3570
3632
|
}
|
|
3571
3633
|
get host() {
|
|
3572
|
-
return __classPrivateFieldGet(this,
|
|
3634
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").host;
|
|
3573
3635
|
}
|
|
3574
3636
|
set host(val) {
|
|
3575
3637
|
if (!val || !isString(val))
|
|
3576
3638
|
return;
|
|
3577
3639
|
val = val.trim();
|
|
3578
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3579
|
-
__classPrivateFieldGet(this,
|
|
3580
|
-
if (__classPrivateFieldGet(this,
|
|
3581
|
-
__classPrivateFieldGet(this,
|
|
3640
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3641
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").host = val;
|
|
3642
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3643
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3582
3644
|
}
|
|
3583
3645
|
get hostname() {
|
|
3584
|
-
return __classPrivateFieldGet(this,
|
|
3646
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").hostname;
|
|
3585
3647
|
}
|
|
3586
3648
|
set hostname(val) {
|
|
3587
3649
|
if (!val || !isString(val))
|
|
3588
3650
|
return;
|
|
3589
3651
|
val = val.trim();
|
|
3590
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3591
|
-
__classPrivateFieldGet(this,
|
|
3592
|
-
if (__classPrivateFieldGet(this,
|
|
3593
|
-
__classPrivateFieldGet(this,
|
|
3652
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3653
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").hostname = val;
|
|
3654
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3655
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3594
3656
|
}
|
|
3595
3657
|
get port() {
|
|
3596
|
-
return __classPrivateFieldGet(this,
|
|
3658
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").port;
|
|
3597
3659
|
}
|
|
3598
3660
|
set port(val) {
|
|
3599
3661
|
const xVal = Number((val = val.trim()));
|
|
3600
3662
|
if (!isNumber(xVal) || xVal <= 0)
|
|
3601
3663
|
return;
|
|
3602
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3603
|
-
__classPrivateFieldGet(this,
|
|
3604
|
-
if (__classPrivateFieldGet(this,
|
|
3605
|
-
__classPrivateFieldGet(this,
|
|
3664
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3665
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").port = val;
|
|
3666
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3667
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3606
3668
|
}
|
|
3607
3669
|
get pathname() {
|
|
3608
|
-
return __classPrivateFieldGet(this,
|
|
3670
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").pathname;
|
|
3609
3671
|
}
|
|
3610
3672
|
set pathname(val) {
|
|
3611
3673
|
if (!val || !isString(val))
|
|
3612
3674
|
return;
|
|
3613
3675
|
val = val.trim();
|
|
3614
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3615
|
-
__classPrivateFieldGet(this,
|
|
3616
|
-
if (__classPrivateFieldGet(this,
|
|
3617
|
-
__classPrivateFieldGet(this,
|
|
3676
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3677
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").pathname = val;
|
|
3678
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3679
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3618
3680
|
}
|
|
3619
3681
|
get search() {
|
|
3620
|
-
return __classPrivateFieldGet(this,
|
|
3682
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").search;
|
|
3621
3683
|
}
|
|
3622
3684
|
set search(val) {
|
|
3623
3685
|
if (!val || !isString(val))
|
|
3624
3686
|
return;
|
|
3625
3687
|
val = val.trim();
|
|
3626
3688
|
val = val.startsWith('?') ? val : `?${val}`;
|
|
3627
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3628
|
-
__classPrivateFieldGet(this,
|
|
3629
|
-
if (__classPrivateFieldGet(this,
|
|
3630
|
-
__classPrivateFieldGet(this,
|
|
3689
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3690
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").search = val;
|
|
3691
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3692
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3631
3693
|
}
|
|
3632
3694
|
get hash() {
|
|
3633
|
-
return __classPrivateFieldGet(this,
|
|
3695
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").hash;
|
|
3634
3696
|
}
|
|
3635
3697
|
// 小程序的navigateTo存在截断hash字符串的问题
|
|
3636
3698
|
set hash(val) {
|
|
@@ -3638,34 +3700,34 @@ class Location extends Events {
|
|
|
3638
3700
|
return;
|
|
3639
3701
|
val = val.trim();
|
|
3640
3702
|
val = val.startsWith('#') ? val : `#${val}`;
|
|
3641
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3642
|
-
__classPrivateFieldGet(this,
|
|
3643
|
-
if (__classPrivateFieldGet(this,
|
|
3644
|
-
__classPrivateFieldGet(this,
|
|
3703
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3704
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").hash = val;
|
|
3705
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3706
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3645
3707
|
}
|
|
3646
3708
|
get href() {
|
|
3647
|
-
return __classPrivateFieldGet(this,
|
|
3709
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").href;
|
|
3648
3710
|
}
|
|
3649
3711
|
set href(val) {
|
|
3650
3712
|
const REG = /^(http:|https:)?\/\/.+/;
|
|
3651
3713
|
if (!val || !isString(val) || !REG.test((val = val.trim())))
|
|
3652
3714
|
return;
|
|
3653
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3654
|
-
__classPrivateFieldGet(this,
|
|
3655
|
-
if (__classPrivateFieldGet(this,
|
|
3656
|
-
__classPrivateFieldGet(this,
|
|
3715
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3716
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").href = val;
|
|
3717
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3718
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3657
3719
|
}
|
|
3658
3720
|
get origin() {
|
|
3659
|
-
return __classPrivateFieldGet(this,
|
|
3721
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").origin;
|
|
3660
3722
|
}
|
|
3661
3723
|
set origin(val) {
|
|
3662
3724
|
const REG = /^(http:|https:)?\/\/.+/;
|
|
3663
3725
|
if (!val || !isString(val) || !REG.test((val = val.trim())))
|
|
3664
3726
|
return;
|
|
3665
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3666
|
-
__classPrivateFieldGet(this,
|
|
3667
|
-
if (__classPrivateFieldGet(this,
|
|
3668
|
-
__classPrivateFieldGet(this,
|
|
3727
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3728
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").origin = val;
|
|
3729
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3730
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3669
3731
|
}
|
|
3670
3732
|
/* public method */
|
|
3671
3733
|
assign() {
|
|
@@ -3685,7 +3747,7 @@ class Location extends Events {
|
|
|
3685
3747
|
return cache;
|
|
3686
3748
|
}
|
|
3687
3749
|
}
|
|
3688
|
-
|
|
3750
|
+
_TaroLocation_url = new WeakMap(), _TaroLocation_noCheckUrl = new WeakMap(), _TaroLocation_window = new WeakMap(), _TaroLocation_instances = new WeakSet(), _TaroLocation_reset = function _TaroLocation_reset() {
|
|
3689
3751
|
const Current = getCurrentInstance();
|
|
3690
3752
|
const router = Current.router;
|
|
3691
3753
|
if (router) {
|
|
@@ -3695,23 +3757,23 @@ _Location_url = new WeakMap(), _Location_noCheckUrl = new WeakMap(), _Location_w
|
|
|
3695
3757
|
});
|
|
3696
3758
|
const searchStr = searchArr.length > 0 ? '?' + searchArr.join('&') : '';
|
|
3697
3759
|
const url = `${INIT_URL}${path.startsWith('/') ? path : '/' + path}${searchStr}`;
|
|
3698
|
-
__classPrivateFieldSet(this,
|
|
3760
|
+
__classPrivateFieldSet(this, _TaroLocation_url, new URL(url), "f");
|
|
3699
3761
|
this.trigger('__reset_history__', this.href);
|
|
3700
3762
|
}
|
|
3701
|
-
},
|
|
3702
|
-
return __classPrivateFieldGet(this,
|
|
3703
|
-
},
|
|
3704
|
-
__classPrivateFieldGet(this,
|
|
3705
|
-
},
|
|
3763
|
+
}, _TaroLocation_getPreValue = function _TaroLocation_getPreValue() {
|
|
3764
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f")._toRaw();
|
|
3765
|
+
}, _TaroLocation_rollBack = function _TaroLocation_rollBack(href) {
|
|
3766
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").href = href;
|
|
3767
|
+
}, _TaroLocation_recordHistory = function _TaroLocation_recordHistory() {
|
|
3706
3768
|
this.trigger('__record_history__', this.href);
|
|
3707
|
-
},
|
|
3708
|
-
if (__classPrivateFieldGet(this,
|
|
3769
|
+
}, _TaroLocation_checkUrlChange = function _TaroLocation_checkUrlChange(preValue) {
|
|
3770
|
+
if (__classPrivateFieldGet(this, _TaroLocation_noCheckUrl, "f")) {
|
|
3709
3771
|
return false;
|
|
3710
3772
|
}
|
|
3711
|
-
const { protocol, hostname, port, pathname, search, hash } = __classPrivateFieldGet(this,
|
|
3773
|
+
const { protocol, hostname, port, pathname, search, hash } = __classPrivateFieldGet(this, _TaroLocation_url, "f")._toRaw();
|
|
3712
3774
|
// 跨域三要素不允许修改
|
|
3713
3775
|
if (protocol !== preValue.protocol || hostname !== preValue.hostname || port !== preValue.port) {
|
|
3714
|
-
__classPrivateFieldGet(this,
|
|
3776
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_rollBack).call(this, preValue.href);
|
|
3715
3777
|
return false;
|
|
3716
3778
|
}
|
|
3717
3779
|
// pathname
|
|
@@ -3724,12 +3786,13 @@ _Location_url = new WeakMap(), _Location_noCheckUrl = new WeakMap(), _Location_w
|
|
|
3724
3786
|
}
|
|
3725
3787
|
// hashchange
|
|
3726
3788
|
if (hash !== preValue.hash) {
|
|
3727
|
-
__classPrivateFieldGet(this,
|
|
3789
|
+
__classPrivateFieldGet(this, _TaroLocation_window, "f").trigger('hashchange');
|
|
3728
3790
|
return true;
|
|
3729
3791
|
}
|
|
3730
|
-
__classPrivateFieldGet(this,
|
|
3792
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_rollBack).call(this, preValue.href);
|
|
3731
3793
|
return false;
|
|
3732
3794
|
};
|
|
3795
|
+
const Location = process.env.TARO_PLATFORM === 'web' ? env.window.Location : TaroLocation;
|
|
3733
3796
|
function generateFullUrl(val = '') {
|
|
3734
3797
|
const origin = INIT_URL;
|
|
3735
3798
|
if (/^[/?#]/.test(val)) {
|
|
@@ -3742,7 +3805,7 @@ const machine = 'Macintosh';
|
|
|
3742
3805
|
const arch = 'Intel Mac OS X 10_14_5';
|
|
3743
3806
|
const engine = 'AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36';
|
|
3744
3807
|
const msg = '(' + machine + '; ' + arch + ') ' + engine;
|
|
3745
|
-
const nav =
|
|
3808
|
+
const nav = process.env.TARO_PLATFORM === 'web' ? env.window.navigator : {
|
|
3746
3809
|
appCodeName: 'Mozilla',
|
|
3747
3810
|
appName: 'Netscape',
|
|
3748
3811
|
appVersion: '5.0 ' + msg,
|
|
@@ -3789,88 +3852,83 @@ const _caf = typeof cancelAnimationFrame !== 'undefined' && cancelAnimationFrame
|
|
|
3789
3852
|
clearTimeout(seed);
|
|
3790
3853
|
};
|
|
3791
3854
|
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
3815
|
-
console.warn(`[Taro warn] window.${String(property)} 在赋值到 window 时报错`);
|
|
3816
|
-
}
|
|
3855
|
+
class TaroWindow extends Events {
|
|
3856
|
+
constructor() {
|
|
3857
|
+
super();
|
|
3858
|
+
this.navigator = nav;
|
|
3859
|
+
this.requestAnimationFrame = _raf;
|
|
3860
|
+
this.cancelAnimationFrame = _caf;
|
|
3861
|
+
this.getComputedStyle = getComputedStyle;
|
|
3862
|
+
const globalProperties = [
|
|
3863
|
+
...Object.getOwnPropertyNames(global || {}),
|
|
3864
|
+
...Object.getOwnPropertySymbols(global || {})
|
|
3865
|
+
];
|
|
3866
|
+
globalProperties.forEach(property => {
|
|
3867
|
+
if (property === 'atob' || property === 'document')
|
|
3868
|
+
return;
|
|
3869
|
+
if (!Object.prototype.hasOwnProperty.call(this, property)) {
|
|
3870
|
+
// 防止小程序环境下,window 上的某些 get 属性在赋值时报错
|
|
3871
|
+
try {
|
|
3872
|
+
this[property] = global[property];
|
|
3873
|
+
}
|
|
3874
|
+
catch (e) {
|
|
3875
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3876
|
+
console.warn(`[Taro warn] window.${String(property)} 在赋值到 window 时报错`);
|
|
3817
3877
|
}
|
|
3818
3878
|
}
|
|
3819
|
-
}
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
}
|
|
3826
|
-
initEvent()
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3879
|
+
}
|
|
3880
|
+
});
|
|
3881
|
+
this.Date || (this.Date = Date);
|
|
3882
|
+
// 应用启动时,提供给需要读取历史信息的库使用
|
|
3883
|
+
this.location = new Location({ window: this });
|
|
3884
|
+
// @ts-ignore
|
|
3885
|
+
this.history = new History(this.location, { window: this });
|
|
3886
|
+
this.initEvent();
|
|
3887
|
+
}
|
|
3888
|
+
initEvent() {
|
|
3889
|
+
const _location = this.location;
|
|
3890
|
+
const _history = this.history;
|
|
3891
|
+
this.on(CONTEXT_ACTIONS.INIT, (pageId) => {
|
|
3892
|
+
// 页面onload,为该页面建立新的上下文信息
|
|
3893
|
+
_location.trigger(CONTEXT_ACTIONS.INIT, pageId);
|
|
3894
|
+
}, null);
|
|
3895
|
+
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
3896
|
+
// 页面onshow,恢复当前页面的上下文信息
|
|
3897
|
+
_location.trigger(CONTEXT_ACTIONS.RECOVER, pageId);
|
|
3898
|
+
_history.trigger(CONTEXT_ACTIONS.RECOVER, pageId);
|
|
3899
|
+
}, null);
|
|
3900
|
+
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3901
|
+
// 页面onhide,缓存当前页面的上下文信息
|
|
3902
|
+
_location.trigger(CONTEXT_ACTIONS.RESTORE, pageId);
|
|
3903
|
+
_history.trigger(CONTEXT_ACTIONS.RESTORE, pageId);
|
|
3904
|
+
}, null);
|
|
3905
|
+
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
3906
|
+
// 页面onunload,清除当前页面的上下文信息
|
|
3907
|
+
_location.trigger(CONTEXT_ACTIONS.DESTORY, pageId);
|
|
3908
|
+
_history.trigger(CONTEXT_ACTIONS.DESTORY, pageId);
|
|
3909
|
+
}, null);
|
|
3910
|
+
}
|
|
3911
|
+
get document() {
|
|
3912
|
+
return env.document;
|
|
3913
|
+
}
|
|
3914
|
+
addEventListener(event, callback) {
|
|
3915
|
+
if (!isString(event))
|
|
3916
|
+
return;
|
|
3917
|
+
this.on(event, callback, null);
|
|
3918
|
+
}
|
|
3919
|
+
removeEventListener(event, callback) {
|
|
3920
|
+
if (!isString(event))
|
|
3921
|
+
return;
|
|
3922
|
+
this.off(event, callback, null);
|
|
3923
|
+
}
|
|
3924
|
+
setTimeout(...args) {
|
|
3925
|
+
return setTimeout(...args);
|
|
3926
|
+
}
|
|
3927
|
+
clearTimeout(...args) {
|
|
3928
|
+
return clearTimeout(...args);
|
|
3868
3929
|
}
|
|
3869
|
-
window$1 = env.window = new Window();
|
|
3870
|
-
}
|
|
3871
|
-
else {
|
|
3872
|
-
window$1 = env.window;
|
|
3873
3930
|
}
|
|
3931
|
+
const window$1 = process.env.TARO_PLATFORM === 'web' ? env.window : (env.window = new TaroWindow());
|
|
3874
3932
|
const location = window$1.location;
|
|
3875
3933
|
const history = window$1.history;
|
|
3876
3934
|
|
|
@@ -3878,10 +3936,29 @@ const history = window$1.history;
|
|
|
3878
3936
|
class SVGElement extends TaroElement {
|
|
3879
3937
|
}
|
|
3880
3938
|
|
|
3939
|
+
// export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
|
|
3940
|
+
// export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
|
|
3941
|
+
const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
|
|
3942
|
+
const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
|
|
3943
|
+
const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
|
|
3944
|
+
const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
|
|
3945
|
+
const stripSuffix = (path = '', suffix = '') => path.includes(suffix) ? path.substring(0, path.length - suffix.length) : path;
|
|
3946
|
+
const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
|
|
3947
|
+
var _a;
|
|
3948
|
+
const routePath = addLeadingSlash(stripBasename(path, basename));
|
|
3949
|
+
const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
|
|
3950
|
+
return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
|
|
3951
|
+
};
|
|
3952
|
+
const getCurrentPage = (routerMode = 'hash', basename = '/') => {
|
|
3953
|
+
const pagePath = routerMode === 'hash'
|
|
3954
|
+
? location.hash.slice(1).split('?')[0]
|
|
3955
|
+
: location.pathname;
|
|
3956
|
+
return addLeadingSlash(stripBasename(pagePath, basename));
|
|
3957
|
+
};
|
|
3958
|
+
|
|
3881
3959
|
/* eslint-disable dot-notation */
|
|
3882
3960
|
const instances = new Map();
|
|
3883
3961
|
const pageId = incrementId();
|
|
3884
|
-
const isWeb = isWebPlatform();
|
|
3885
3962
|
function injectPageInstance(inst, id) {
|
|
3886
3963
|
hooks.call('mergePageInstance', instances.get(id), inst);
|
|
3887
3964
|
instances.set(id, inst);
|
|
@@ -3892,12 +3969,6 @@ function getPageInstance(id) {
|
|
|
3892
3969
|
function removePageInstance(id) {
|
|
3893
3970
|
instances.delete(id);
|
|
3894
3971
|
}
|
|
3895
|
-
function addLeadingSlash(path) {
|
|
3896
|
-
if (path == null) {
|
|
3897
|
-
return '';
|
|
3898
|
-
}
|
|
3899
|
-
return path.charAt(0) === '/' ? path : '/' + path;
|
|
3900
|
-
}
|
|
3901
3972
|
function safeExecute(path, lifecycle, ...args) {
|
|
3902
3973
|
const instance = instances.get(path);
|
|
3903
3974
|
if (instance == null) {
|
|
@@ -3924,7 +3995,7 @@ function stringify(obj) {
|
|
|
3924
3995
|
}
|
|
3925
3996
|
function getPath(id, options) {
|
|
3926
3997
|
const idx = id.indexOf('?');
|
|
3927
|
-
if (
|
|
3998
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
3928
3999
|
return `${idx > -1 ? id.substring(0, idx) : id}${stringify((options === null || options === void 0 ? void 0 : options.stamp) ? { stamp: options.stamp } : {})}`;
|
|
3929
4000
|
}
|
|
3930
4001
|
else {
|
|
@@ -3948,7 +4019,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3948
4019
|
let unmounting = false;
|
|
3949
4020
|
let prepareMountList = [];
|
|
3950
4021
|
function setCurrentRouter(page) {
|
|
3951
|
-
const router =
|
|
4022
|
+
const router = process.env.TARO_PLATFORM === 'web' ? page.$taroPath : page.route || page.__route__ || page.$taroPath;
|
|
3952
4023
|
Current.router = {
|
|
3953
4024
|
params: page.$taroParams,
|
|
3954
4025
|
path: addLeadingSlash(router),
|
|
@@ -3972,7 +4043,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3972
4043
|
// this.$taroPath 是页面唯一标识
|
|
3973
4044
|
const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() });
|
|
3974
4045
|
const $taroPath = this.$taroPath = getPath(id, uniqueOptions);
|
|
3975
|
-
if (
|
|
4046
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
3976
4047
|
config.path = $taroPath;
|
|
3977
4048
|
}
|
|
3978
4049
|
// this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
|
|
@@ -3981,7 +4052,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3981
4052
|
}
|
|
3982
4053
|
setCurrentRouter(this);
|
|
3983
4054
|
// 初始化当前页面的上下文信息
|
|
3984
|
-
if (
|
|
4055
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
3985
4056
|
window$1.trigger(CONTEXT_ACTIONS.INIT, $taroPath);
|
|
3986
4057
|
}
|
|
3987
4058
|
const mount = () => {
|
|
@@ -3990,7 +4061,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3990
4061
|
ensure(pageElement !== null, '没有找到页面实例。');
|
|
3991
4062
|
safeExecute($taroPath, ON_LOAD, this.$taroParams);
|
|
3992
4063
|
loadResolver();
|
|
3993
|
-
if (
|
|
4064
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
3994
4065
|
pageElement.ctx = this;
|
|
3995
4066
|
pageElement.performUpdate(true, cb);
|
|
3996
4067
|
}
|
|
@@ -4009,7 +4080,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4009
4080
|
[ONUNLOAD]() {
|
|
4010
4081
|
const $taroPath = this.$taroPath;
|
|
4011
4082
|
// 销毁当前页面的上下文信息
|
|
4012
|
-
if (
|
|
4083
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
4013
4084
|
window$1.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath);
|
|
4014
4085
|
}
|
|
4015
4086
|
// 触发onUnload生命周期
|
|
@@ -4043,7 +4114,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4043
4114
|
Current.page = this;
|
|
4044
4115
|
setCurrentRouter(this);
|
|
4045
4116
|
// 恢复上下文信息
|
|
4046
|
-
if (
|
|
4117
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
4047
4118
|
window$1.trigger(CONTEXT_ACTIONS.RECOVER, this.$taroPath);
|
|
4048
4119
|
}
|
|
4049
4120
|
// 触发生命周期
|
|
@@ -4054,7 +4125,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4054
4125
|
},
|
|
4055
4126
|
[ONHIDE]() {
|
|
4056
4127
|
// 缓存当前页面上下文信息
|
|
4057
|
-
if (
|
|
4128
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
4058
4129
|
window$1.trigger(CONTEXT_ACTIONS.RESTORE, this.$taroPath);
|
|
4059
4130
|
}
|
|
4060
4131
|
// 设置 Current 的 page 和 router
|
|
@@ -4068,6 +4139,11 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4068
4139
|
eventCenter.trigger(getOnHideEventKey(id));
|
|
4069
4140
|
}
|
|
4070
4141
|
};
|
|
4142
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
4143
|
+
config.getOpenerEventChannel = () => {
|
|
4144
|
+
return EventChannel.pageChannel;
|
|
4145
|
+
};
|
|
4146
|
+
}
|
|
4071
4147
|
LIFECYCLES.forEach((lifecycle) => {
|
|
4072
4148
|
let isDefer = false;
|
|
4073
4149
|
lifecycle = lifecycle.replace(/^defer:/, () => {
|
|
@@ -4127,7 +4203,7 @@ function createComponentConfig(component, componentName, data) {
|
|
|
4127
4203
|
ensure(componentElement !== null, '没有找到组件实例。');
|
|
4128
4204
|
this.$taroInstances = instances.get(path);
|
|
4129
4205
|
safeExecute(path, ON_LOAD);
|
|
4130
|
-
if (
|
|
4206
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
4131
4207
|
componentElement.ctx = this;
|
|
4132
4208
|
componentElement.performUpdate(true);
|
|
4133
4209
|
}
|
|
@@ -4184,7 +4260,7 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
4184
4260
|
}
|
|
4185
4261
|
}
|
|
4186
4262
|
: EMPTY_OBJ;
|
|
4187
|
-
return Object.assign({ properties: {
|
|
4263
|
+
return hooks.call('modifyRecursiveComponentConfig', Object.assign({ properties: {
|
|
4188
4264
|
i: {
|
|
4189
4265
|
type: Object,
|
|
4190
4266
|
value: {
|
|
@@ -4200,7 +4276,7 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
4200
4276
|
virtualHost: !isCustomWrapper
|
|
4201
4277
|
}, methods: {
|
|
4202
4278
|
eh: eventHandler
|
|
4203
|
-
} }, lifeCycles);
|
|
4279
|
+
} }, lifeCycles), { isCustomWrapper });
|
|
4204
4280
|
}
|
|
4205
4281
|
|
|
4206
4282
|
const TIMEOUT = 100;
|
|
@@ -4225,7 +4301,7 @@ const nextTick = (cb, ctx) => {
|
|
|
4225
4301
|
var _a, _b, _c;
|
|
4226
4302
|
const pageElement = env.document.getElementById(path);
|
|
4227
4303
|
if (pageElement === null || pageElement === void 0 ? void 0 : pageElement.pendingUpdate) {
|
|
4228
|
-
if (
|
|
4304
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
4229
4305
|
// eslint-disable-next-line dot-notation
|
|
4230
4306
|
(_c = (_b = (_a = pageElement.firstChild) === null || _a === void 0 ? void 0 : _a['componentOnReady']) === null || _b === void 0 ? void 0 : _b.call(_a).then(() => {
|
|
4231
4307
|
timerFunc();
|
|
@@ -4245,5 +4321,775 @@ const nextTick = (cb, ctx) => {
|
|
|
4245
4321
|
next();
|
|
4246
4322
|
};
|
|
4247
4323
|
|
|
4248
|
-
|
|
4324
|
+
function handleArrayFindPolyfill() {
|
|
4325
|
+
if (!isFunction(Array.prototype.find)) {
|
|
4326
|
+
Object.defineProperty(Array.prototype, 'find', {
|
|
4327
|
+
value(predicate) {
|
|
4328
|
+
if (this == null) {
|
|
4329
|
+
throw new TypeError('"this" is null or not defined');
|
|
4330
|
+
}
|
|
4331
|
+
const o = Object(this);
|
|
4332
|
+
const len = o.length >>> 0;
|
|
4333
|
+
if (!isFunction(predicate)) {
|
|
4334
|
+
throw new TypeError('predicate must be a function');
|
|
4335
|
+
}
|
|
4336
|
+
const thisArg = arguments[1];
|
|
4337
|
+
let k = 0;
|
|
4338
|
+
while (k < len) {
|
|
4339
|
+
const kValue = o[k];
|
|
4340
|
+
if (predicate.call(thisArg, kValue, k, o)) {
|
|
4341
|
+
return kValue;
|
|
4342
|
+
}
|
|
4343
|
+
k++;
|
|
4344
|
+
}
|
|
4345
|
+
return undefined;
|
|
4346
|
+
}
|
|
4347
|
+
});
|
|
4348
|
+
}
|
|
4349
|
+
}
|
|
4350
|
+
function handleArrayIncludesPolyfill() {
|
|
4351
|
+
if (!isFunction(Array.prototype.includes)) {
|
|
4352
|
+
Object.defineProperty(Array.prototype, 'includes', {
|
|
4353
|
+
value(searchElement, fromIndex) {
|
|
4354
|
+
if (this == null) {
|
|
4355
|
+
throw new TypeError('"this" is null or not defined');
|
|
4356
|
+
}
|
|
4357
|
+
const o = Object(this);
|
|
4358
|
+
const len = o.length >>> 0;
|
|
4359
|
+
if (len === 0) {
|
|
4360
|
+
return false;
|
|
4361
|
+
}
|
|
4362
|
+
const n = fromIndex | 0;
|
|
4363
|
+
let k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
|
|
4364
|
+
while (k < len) {
|
|
4365
|
+
if (o[k] === searchElement) {
|
|
4366
|
+
return true;
|
|
4367
|
+
}
|
|
4368
|
+
k++;
|
|
4369
|
+
}
|
|
4370
|
+
return false;
|
|
4371
|
+
}
|
|
4372
|
+
});
|
|
4373
|
+
}
|
|
4374
|
+
}
|
|
4375
|
+
|
|
4376
|
+
/* eslint-disable eqeqeq */
|
|
4377
|
+
function handleIntersectionObserverPolyfill() {
|
|
4378
|
+
// Exit early if all IntersectionObserver and IntersectionObserverEntry
|
|
4379
|
+
// features are natively supported.
|
|
4380
|
+
if ('IntersectionObserver' in window &&
|
|
4381
|
+
'IntersectionObserverEntry' in window &&
|
|
4382
|
+
'intersectionRatio' in window.IntersectionObserverEntry.prototype) {
|
|
4383
|
+
if (!('isIntersecting' in window.IntersectionObserverEntry.prototype)) {
|
|
4384
|
+
// Minimal polyfill for Edge 15's lack of `isIntersecting`
|
|
4385
|
+
// See: https://github.com/w3c/IntersectionObserver/issues/211
|
|
4386
|
+
Object.defineProperty(window.IntersectionObserverEntry.prototype, 'isIntersecting', {
|
|
4387
|
+
get: function () {
|
|
4388
|
+
return this.intersectionRatio > 0;
|
|
4389
|
+
}
|
|
4390
|
+
});
|
|
4391
|
+
}
|
|
4392
|
+
}
|
|
4393
|
+
else {
|
|
4394
|
+
handleIntersectionObserverObjectPolyfill();
|
|
4395
|
+
}
|
|
4396
|
+
}
|
|
4397
|
+
function handleIntersectionObserverObjectPolyfill() {
|
|
4398
|
+
const document = window.document;
|
|
4399
|
+
/**
|
|
4400
|
+
* Creates the global IntersectionObserverEntry constructor.
|
|
4401
|
+
* https://w3c.github.io/IntersectionObserver/#intersection-observer-entry
|
|
4402
|
+
* @param {Object} entry A dictionary of instance properties.
|
|
4403
|
+
* @constructor
|
|
4404
|
+
*/
|
|
4405
|
+
function IntersectionObserverEntry(entry) {
|
|
4406
|
+
this.time = entry.time;
|
|
4407
|
+
this.target = entry.target;
|
|
4408
|
+
this.rootBounds = entry.rootBounds;
|
|
4409
|
+
this.boundingClientRect = entry.boundingClientRect;
|
|
4410
|
+
this.intersectionRect = entry.intersectionRect || getEmptyRect();
|
|
4411
|
+
this.isIntersecting = !!entry.intersectionRect;
|
|
4412
|
+
// Calculates the intersection ratio.
|
|
4413
|
+
const targetRect = this.boundingClientRect;
|
|
4414
|
+
const targetArea = targetRect.width * targetRect.height;
|
|
4415
|
+
const intersectionRect = this.intersectionRect;
|
|
4416
|
+
const intersectionArea = intersectionRect.width * intersectionRect.height;
|
|
4417
|
+
// Sets intersection ratio.
|
|
4418
|
+
if (targetArea) {
|
|
4419
|
+
// Round the intersection ratio to avoid floating point math issues:
|
|
4420
|
+
// https://github.com/w3c/IntersectionObserver/issues/324
|
|
4421
|
+
this.intersectionRatio = Number((intersectionArea / targetArea).toFixed(4));
|
|
4422
|
+
}
|
|
4423
|
+
else {
|
|
4424
|
+
// If area is zero and is intersecting, sets to 1, otherwise to 0
|
|
4425
|
+
this.intersectionRatio = this.isIntersecting ? 1 : 0;
|
|
4426
|
+
}
|
|
4427
|
+
}
|
|
4428
|
+
/**
|
|
4429
|
+
* Creates the global IntersectionObserver constructor.
|
|
4430
|
+
* https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
|
|
4431
|
+
* @param {Function} callback The function to be invoked after intersection
|
|
4432
|
+
* changes have queued. The function is not invoked if the queue has
|
|
4433
|
+
* been emptied by calling the `takeRecords` method.
|
|
4434
|
+
* @param {Object=} opt_options Optional configuration options.
|
|
4435
|
+
* @constructor
|
|
4436
|
+
*/
|
|
4437
|
+
function IntersectionObserver(callback, options = {}) {
|
|
4438
|
+
if (!isFunction(callback)) {
|
|
4439
|
+
throw new Error('callback must be a function');
|
|
4440
|
+
}
|
|
4441
|
+
if (options.root && options.root.nodeType != 1) {
|
|
4442
|
+
throw new Error('root must be an Element');
|
|
4443
|
+
}
|
|
4444
|
+
// Binds and throttles `this._checkForIntersections`.
|
|
4445
|
+
this._checkForIntersections = throttle(this._checkForIntersections.bind(this), this.THROTTLE_TIMEOUT);
|
|
4446
|
+
// Private properties.
|
|
4447
|
+
this._callback = callback;
|
|
4448
|
+
this._observationTargets = [];
|
|
4449
|
+
this._queuedEntries = [];
|
|
4450
|
+
this._rootMarginValues = this._parseRootMargin(options.rootMargin);
|
|
4451
|
+
// Public properties.
|
|
4452
|
+
this.thresholds = this._initThresholds(options.threshold);
|
|
4453
|
+
this.root = options.root || null;
|
|
4454
|
+
this.rootMargin = this._rootMarginValues.map(function (margin) {
|
|
4455
|
+
return margin.value + margin.unit;
|
|
4456
|
+
}).join(' ');
|
|
4457
|
+
}
|
|
4458
|
+
/**
|
|
4459
|
+
* The minimum interval within which the document will be checked for
|
|
4460
|
+
* intersection changes.
|
|
4461
|
+
*/
|
|
4462
|
+
IntersectionObserver.prototype.THROTTLE_TIMEOUT = 100;
|
|
4463
|
+
/**
|
|
4464
|
+
* The frequency in which the polyfill polls for intersection changes.
|
|
4465
|
+
* this can be updated on a per instance basis and must be set prior to
|
|
4466
|
+
* calling `observe` on the first target.
|
|
4467
|
+
*/
|
|
4468
|
+
IntersectionObserver.prototype.POLL_INTERVAL = null;
|
|
4469
|
+
/**
|
|
4470
|
+
* Use a mutation observer on the root element
|
|
4471
|
+
* to detect intersection changes.
|
|
4472
|
+
*/
|
|
4473
|
+
IntersectionObserver.prototype.USE_MUTATION_OBSERVER = true;
|
|
4474
|
+
/**
|
|
4475
|
+
* Starts observing a target element for intersection changes based on
|
|
4476
|
+
* the thresholds values.
|
|
4477
|
+
* @param {Element} target The DOM element to observe.
|
|
4478
|
+
*/
|
|
4479
|
+
IntersectionObserver.prototype.observe = function (target) {
|
|
4480
|
+
const isTargetAlreadyObserved = this._observationTargets.some(function (item) {
|
|
4481
|
+
return item.element == target;
|
|
4482
|
+
});
|
|
4483
|
+
if (isTargetAlreadyObserved)
|
|
4484
|
+
return;
|
|
4485
|
+
if (!(target && target.nodeType == 1)) {
|
|
4486
|
+
throw new Error('target must be an Element');
|
|
4487
|
+
}
|
|
4488
|
+
this._registerInstance();
|
|
4489
|
+
this._observationTargets.push({ element: target, entry: null });
|
|
4490
|
+
this._monitorIntersections();
|
|
4491
|
+
this._checkForIntersections();
|
|
4492
|
+
};
|
|
4493
|
+
/**
|
|
4494
|
+
* Stops observing a target element for intersection changes.
|
|
4495
|
+
* @param {Element} target The DOM element to observe.
|
|
4496
|
+
*/
|
|
4497
|
+
IntersectionObserver.prototype.unobserve = function (target) {
|
|
4498
|
+
this._observationTargets =
|
|
4499
|
+
this._observationTargets.filter(function (item) {
|
|
4500
|
+
return item.element != target;
|
|
4501
|
+
});
|
|
4502
|
+
if (!this._observationTargets.length) {
|
|
4503
|
+
this._unmonitorIntersections();
|
|
4504
|
+
this._unregisterInstance();
|
|
4505
|
+
}
|
|
4506
|
+
};
|
|
4507
|
+
/**
|
|
4508
|
+
* Stops observing all target elements for intersection changes.
|
|
4509
|
+
*/
|
|
4510
|
+
IntersectionObserver.prototype.disconnect = function () {
|
|
4511
|
+
this._observationTargets = [];
|
|
4512
|
+
this._unmonitorIntersections();
|
|
4513
|
+
this._unregisterInstance();
|
|
4514
|
+
};
|
|
4515
|
+
/**
|
|
4516
|
+
* Returns any queue entries that have not yet been reported to the
|
|
4517
|
+
* callback and clears the queue. This can be used in conjunction with the
|
|
4518
|
+
* callback to obtain the absolute most up-to-date intersection information.
|
|
4519
|
+
* @return {Array} The currently queued entries.
|
|
4520
|
+
*/
|
|
4521
|
+
IntersectionObserver.prototype.takeRecords = function () {
|
|
4522
|
+
const records = this._queuedEntries.slice();
|
|
4523
|
+
this._queuedEntries = [];
|
|
4524
|
+
return records;
|
|
4525
|
+
};
|
|
4526
|
+
/**
|
|
4527
|
+
* Accepts the threshold value from the user configuration object and
|
|
4528
|
+
* returns a sorted array of unique threshold values. If a value is not
|
|
4529
|
+
* between 0 and 1 and error is thrown.
|
|
4530
|
+
* @private
|
|
4531
|
+
* @param {Array|number=} opt_threshold An optional threshold value or
|
|
4532
|
+
* a list of threshold values, defaulting to [0].
|
|
4533
|
+
* @return {Array} A sorted list of unique and valid threshold values.
|
|
4534
|
+
*/
|
|
4535
|
+
IntersectionObserver.prototype._initThresholds = function (opt_threshold) {
|
|
4536
|
+
let threshold = opt_threshold || [0];
|
|
4537
|
+
if (!Array.isArray(threshold))
|
|
4538
|
+
threshold = [threshold];
|
|
4539
|
+
return threshold.sort().filter(function (t, i, a) {
|
|
4540
|
+
if (!isNumber(t) || isNaN(t) || t < 0 || t > 1) {
|
|
4541
|
+
throw new Error('threshold must be a number between 0 and 1 inclusively');
|
|
4542
|
+
}
|
|
4543
|
+
return t !== a[i - 1];
|
|
4544
|
+
});
|
|
4545
|
+
};
|
|
4546
|
+
/**
|
|
4547
|
+
* Accepts the rootMargin value from the user configuration object
|
|
4548
|
+
* and returns an array of the four margin values as an object containing
|
|
4549
|
+
* the value and unit properties. If any of the values are not properly
|
|
4550
|
+
* formatted or use a unit other than px or %, and error is thrown.
|
|
4551
|
+
* @private
|
|
4552
|
+
* @param {string=} opt_rootMargin An optional rootMargin value,
|
|
4553
|
+
* defaulting to '0px'.
|
|
4554
|
+
* @return {Array<Object>} An array of margin objects with the keys
|
|
4555
|
+
* value and unit.
|
|
4556
|
+
*/
|
|
4557
|
+
IntersectionObserver.prototype._parseRootMargin = function (opt_rootMargin) {
|
|
4558
|
+
const marginString = opt_rootMargin || '0px';
|
|
4559
|
+
const margins = marginString.split(/\s+/).map(function (margin) {
|
|
4560
|
+
const parts = /^(-?\d*\.?\d+)(px|%)$/.exec(margin);
|
|
4561
|
+
if (!parts) {
|
|
4562
|
+
throw new Error('rootMargin must be specified in pixels or percent');
|
|
4563
|
+
}
|
|
4564
|
+
return { value: parseFloat(parts[1]), unit: parts[2] };
|
|
4565
|
+
});
|
|
4566
|
+
// Handles shorthand.
|
|
4567
|
+
margins[1] = margins[1] || margins[0];
|
|
4568
|
+
margins[2] = margins[2] || margins[0];
|
|
4569
|
+
margins[3] = margins[3] || margins[1];
|
|
4570
|
+
return margins;
|
|
4571
|
+
};
|
|
4572
|
+
/**
|
|
4573
|
+
* Starts polling for intersection changes if the polling is not already
|
|
4574
|
+
* happening, and if the page's visibility state is visible.
|
|
4575
|
+
* @private
|
|
4576
|
+
*/
|
|
4577
|
+
IntersectionObserver.prototype._monitorIntersections = function () {
|
|
4578
|
+
if (!this._monitoringIntersections) {
|
|
4579
|
+
this._monitoringIntersections = true;
|
|
4580
|
+
// If a poll interval is set, use polling instead of listening to
|
|
4581
|
+
// resize and scroll events or DOM mutations.
|
|
4582
|
+
if (this.POLL_INTERVAL) {
|
|
4583
|
+
this._monitoringInterval = setInterval(this._checkForIntersections, this.POLL_INTERVAL);
|
|
4584
|
+
}
|
|
4585
|
+
else {
|
|
4586
|
+
addEvent(window, 'resize', this._checkForIntersections, true);
|
|
4587
|
+
addEvent(document, 'scroll', this._checkForIntersections, true);
|
|
4588
|
+
if (this.USE_MUTATION_OBSERVER && 'MutationObserver' in window) {
|
|
4589
|
+
this._domObserver = new MutationObserver(this._checkForIntersections);
|
|
4590
|
+
this._domObserver.observe(document, {
|
|
4591
|
+
attributes: true,
|
|
4592
|
+
childList: true,
|
|
4593
|
+
characterData: true,
|
|
4594
|
+
subtree: true
|
|
4595
|
+
});
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
}
|
|
4599
|
+
};
|
|
4600
|
+
/**
|
|
4601
|
+
* Stops polling for intersection changes.
|
|
4602
|
+
* @private
|
|
4603
|
+
*/
|
|
4604
|
+
IntersectionObserver.prototype._unmonitorIntersections = function () {
|
|
4605
|
+
if (this._monitoringIntersections) {
|
|
4606
|
+
this._monitoringIntersections = false;
|
|
4607
|
+
clearInterval(this._monitoringInterval);
|
|
4608
|
+
this._monitoringInterval = null;
|
|
4609
|
+
removeEvent(window, 'resize', this._checkForIntersections, true);
|
|
4610
|
+
removeEvent(document, 'scroll', this._checkForIntersections, true);
|
|
4611
|
+
if (this._domObserver) {
|
|
4612
|
+
this._domObserver.disconnect();
|
|
4613
|
+
this._domObserver = null;
|
|
4614
|
+
}
|
|
4615
|
+
}
|
|
4616
|
+
};
|
|
4617
|
+
/**
|
|
4618
|
+
* Scans each observation target for intersection changes and adds them
|
|
4619
|
+
* to the internal entries queue. If new entries are found, it
|
|
4620
|
+
* schedules the callback to be invoked.
|
|
4621
|
+
* @private
|
|
4622
|
+
*/
|
|
4623
|
+
IntersectionObserver.prototype._checkForIntersections = function () {
|
|
4624
|
+
const rootIsInDom = this._rootIsInDom();
|
|
4625
|
+
const rootRect = rootIsInDom ? this._getRootRect() : getEmptyRect();
|
|
4626
|
+
this._observationTargets.forEach(function (item) {
|
|
4627
|
+
const target = item.element;
|
|
4628
|
+
const targetRect = getBoundingClientRect(target);
|
|
4629
|
+
const rootContainsTarget = this._rootContainsTarget(target);
|
|
4630
|
+
const oldEntry = item.entry;
|
|
4631
|
+
const intersectionRect = rootIsInDom && rootContainsTarget &&
|
|
4632
|
+
this._computeTargetAndRootIntersection(target, rootRect);
|
|
4633
|
+
const newEntry = item.entry = new IntersectionObserverEntry({
|
|
4634
|
+
time: now(),
|
|
4635
|
+
target: target,
|
|
4636
|
+
boundingClientRect: targetRect,
|
|
4637
|
+
rootBounds: rootRect,
|
|
4638
|
+
intersectionRect: intersectionRect,
|
|
4639
|
+
intersectionRatio: -1,
|
|
4640
|
+
isIntersecting: false,
|
|
4641
|
+
});
|
|
4642
|
+
if (!oldEntry) {
|
|
4643
|
+
this._queuedEntries.push(newEntry);
|
|
4644
|
+
}
|
|
4645
|
+
else if (rootIsInDom && rootContainsTarget) {
|
|
4646
|
+
// If the new entry intersection ratio has crossed any of the
|
|
4647
|
+
// thresholds, add a new entry.
|
|
4648
|
+
if (this._hasCrossedThreshold(oldEntry, newEntry)) {
|
|
4649
|
+
this._queuedEntries.push(newEntry);
|
|
4650
|
+
}
|
|
4651
|
+
}
|
|
4652
|
+
else {
|
|
4653
|
+
// If the root is not in the DOM or target is not contained within
|
|
4654
|
+
// root but the previous entry for this target had an intersection,
|
|
4655
|
+
// add a new record indicating removal.
|
|
4656
|
+
if (oldEntry && oldEntry.isIntersecting) {
|
|
4657
|
+
this._queuedEntries.push(newEntry);
|
|
4658
|
+
}
|
|
4659
|
+
}
|
|
4660
|
+
}, this);
|
|
4661
|
+
if (this._queuedEntries.length) {
|
|
4662
|
+
this._callback(this.takeRecords(), this);
|
|
4663
|
+
}
|
|
4664
|
+
};
|
|
4665
|
+
/**
|
|
4666
|
+
* Accepts a target and root rect computes the intersection between then
|
|
4667
|
+
* following the algorithm in the spec.
|
|
4668
|
+
* TODO(philipwalton): at this time clip-path is not considered.
|
|
4669
|
+
* https://w3c.github.io/IntersectionObserver/#calculate-intersection-rect-algo
|
|
4670
|
+
* @param {Element} target The target DOM element
|
|
4671
|
+
* @param {Object} rootRect The bounding rect of the root after being
|
|
4672
|
+
* expanded by the rootMargin value.
|
|
4673
|
+
* @return {?Object} The final intersection rect object or undefined if no
|
|
4674
|
+
* intersection is found.
|
|
4675
|
+
* @private
|
|
4676
|
+
*/
|
|
4677
|
+
IntersectionObserver.prototype._computeTargetAndRootIntersection = function (target, rootRect) {
|
|
4678
|
+
// If the element isn't displayed, an intersection can't happen.
|
|
4679
|
+
if (window.getComputedStyle(target).display === 'none')
|
|
4680
|
+
return;
|
|
4681
|
+
const targetRect = getBoundingClientRect(target);
|
|
4682
|
+
let intersectionRect = targetRect;
|
|
4683
|
+
let parent = getParentNode(target);
|
|
4684
|
+
let atRoot = false;
|
|
4685
|
+
while (!atRoot) {
|
|
4686
|
+
let parentRect = null;
|
|
4687
|
+
const parentComputedStyle = parent.nodeType == 1 ?
|
|
4688
|
+
window.getComputedStyle(parent) : {};
|
|
4689
|
+
// If the parent isn't displayed, an intersection can't happen.
|
|
4690
|
+
if (parentComputedStyle.display === 'none')
|
|
4691
|
+
return;
|
|
4692
|
+
if (parent == this.root || parent == document) {
|
|
4693
|
+
atRoot = true;
|
|
4694
|
+
parentRect = rootRect;
|
|
4695
|
+
}
|
|
4696
|
+
else {
|
|
4697
|
+
// If the element has a non-visible overflow, and it's not the <body>
|
|
4698
|
+
// or <html> element, update the intersection rect.
|
|
4699
|
+
// Note: <body> and <html> cannot be clipped to a rect that's not also
|
|
4700
|
+
// the document rect, so no need to compute a new intersection.
|
|
4701
|
+
if (parent != document.body &&
|
|
4702
|
+
parent != document.documentElement &&
|
|
4703
|
+
parentComputedStyle.overflow != 'visible') {
|
|
4704
|
+
parentRect = getBoundingClientRect(parent);
|
|
4705
|
+
}
|
|
4706
|
+
}
|
|
4707
|
+
// If either of the above conditionals set a new parentRect,
|
|
4708
|
+
// calculate new intersection data.
|
|
4709
|
+
if (parentRect) {
|
|
4710
|
+
intersectionRect = computeRectIntersection(parentRect, intersectionRect);
|
|
4711
|
+
if (!intersectionRect)
|
|
4712
|
+
break;
|
|
4713
|
+
}
|
|
4714
|
+
parent = getParentNode(parent);
|
|
4715
|
+
}
|
|
4716
|
+
return intersectionRect;
|
|
4717
|
+
};
|
|
4718
|
+
/**
|
|
4719
|
+
* Returns the root rect after being expanded by the rootMargin value.
|
|
4720
|
+
* @return {Object} The expanded root rect.
|
|
4721
|
+
* @private
|
|
4722
|
+
*/
|
|
4723
|
+
IntersectionObserver.prototype._getRootRect = function () {
|
|
4724
|
+
let rootRect;
|
|
4725
|
+
if (this.root) {
|
|
4726
|
+
rootRect = getBoundingClientRect(this.root);
|
|
4727
|
+
}
|
|
4728
|
+
else {
|
|
4729
|
+
// Use <html>/<body> instead of window since scroll bars affect size.
|
|
4730
|
+
const html = document.documentElement;
|
|
4731
|
+
const body = document.body;
|
|
4732
|
+
rootRect = {
|
|
4733
|
+
top: 0,
|
|
4734
|
+
left: 0,
|
|
4735
|
+
right: html.clientWidth || body.clientWidth,
|
|
4736
|
+
width: html.clientWidth || body.clientWidth,
|
|
4737
|
+
bottom: html.clientHeight || body.clientHeight,
|
|
4738
|
+
height: html.clientHeight || body.clientHeight
|
|
4739
|
+
};
|
|
4740
|
+
}
|
|
4741
|
+
return this._expandRectByRootMargin(rootRect);
|
|
4742
|
+
};
|
|
4743
|
+
/**
|
|
4744
|
+
* Accepts a rect and expands it by the rootMargin value.
|
|
4745
|
+
* @param {Object} rect The rect object to expand.
|
|
4746
|
+
* @return {Object} The expanded rect.
|
|
4747
|
+
* @private
|
|
4748
|
+
*/
|
|
4749
|
+
IntersectionObserver.prototype._expandRectByRootMargin = function (rect) {
|
|
4750
|
+
const margins = this._rootMarginValues.map(function (margin, i) {
|
|
4751
|
+
return margin.unit === 'px' ? margin.value :
|
|
4752
|
+
margin.value * (i % 2 ? rect.width : rect.height) / 100;
|
|
4753
|
+
});
|
|
4754
|
+
const newRect = {
|
|
4755
|
+
top: rect.top - margins[0],
|
|
4756
|
+
right: rect.right + margins[1],
|
|
4757
|
+
bottom: rect.bottom + margins[2],
|
|
4758
|
+
left: rect.left - margins[3]
|
|
4759
|
+
};
|
|
4760
|
+
newRect.width = newRect.right - newRect.left;
|
|
4761
|
+
newRect.height = newRect.bottom - newRect.top;
|
|
4762
|
+
return newRect;
|
|
4763
|
+
};
|
|
4764
|
+
/**
|
|
4765
|
+
* Accepts an old and new entry and returns true if at least one of the
|
|
4766
|
+
* threshold values has been crossed.
|
|
4767
|
+
* @param {?IntersectionObserverEntry} oldEntry The previous entry for a
|
|
4768
|
+
* particular target element or null if no previous entry exists.
|
|
4769
|
+
* @param {IntersectionObserverEntry} newEntry The current entry for a
|
|
4770
|
+
* particular target element.
|
|
4771
|
+
* @return {boolean} Returns true if a any threshold has been crossed.
|
|
4772
|
+
* @private
|
|
4773
|
+
*/
|
|
4774
|
+
IntersectionObserver.prototype._hasCrossedThreshold =
|
|
4775
|
+
function (oldEntry, newEntry) {
|
|
4776
|
+
// To make comparing easier, an entry that has a ratio of 0
|
|
4777
|
+
// but does not actually intersect is given a value of -1
|
|
4778
|
+
const oldRatio = oldEntry && oldEntry.isIntersecting ? oldEntry.intersectionRatio || 0 : -1;
|
|
4779
|
+
const newRatio = newEntry.isIntersecting ? newEntry.intersectionRatio || 0 : -1;
|
|
4780
|
+
// Ignore unchanged ratios
|
|
4781
|
+
if (oldRatio === newRatio)
|
|
4782
|
+
return;
|
|
4783
|
+
for (let i = 0; i < this.thresholds.length; i++) {
|
|
4784
|
+
const threshold = this.thresholds[i];
|
|
4785
|
+
// Return true if an entry matches a threshold or if the new ratio
|
|
4786
|
+
// and the old ratio are on the opposite sides of a threshold.
|
|
4787
|
+
if (threshold == oldRatio || threshold == newRatio ||
|
|
4788
|
+
threshold < oldRatio !== threshold < newRatio) {
|
|
4789
|
+
return true;
|
|
4790
|
+
}
|
|
4791
|
+
}
|
|
4792
|
+
};
|
|
4793
|
+
/**
|
|
4794
|
+
* Returns whether or not the root element is an element and is in the DOM.
|
|
4795
|
+
* @return {boolean} True if the root element is an element and is in the DOM.
|
|
4796
|
+
* @private
|
|
4797
|
+
*/
|
|
4798
|
+
IntersectionObserver.prototype._rootIsInDom = function () {
|
|
4799
|
+
return !this.root || containsDeep(document, this.root);
|
|
4800
|
+
};
|
|
4801
|
+
/**
|
|
4802
|
+
* Returns whether or not the target element is a child of root.
|
|
4803
|
+
* @param {Element} target The target element to check.
|
|
4804
|
+
* @return {boolean} True if the target element is a child of root.
|
|
4805
|
+
* @private
|
|
4806
|
+
*/
|
|
4807
|
+
IntersectionObserver.prototype._rootContainsTarget = function (target) {
|
|
4808
|
+
return containsDeep(this.root || document, target);
|
|
4809
|
+
};
|
|
4810
|
+
/**
|
|
4811
|
+
* Adds the instance to the global IntersectionObserver registry if it isn't
|
|
4812
|
+
* already present.
|
|
4813
|
+
* @private
|
|
4814
|
+
*/
|
|
4815
|
+
IntersectionObserver.prototype._registerInstance = function () {
|
|
4816
|
+
};
|
|
4817
|
+
/**
|
|
4818
|
+
* Removes the instance from the global IntersectionObserver registry.
|
|
4819
|
+
* @private
|
|
4820
|
+
*/
|
|
4821
|
+
IntersectionObserver.prototype._unregisterInstance = function () {
|
|
4822
|
+
};
|
|
4823
|
+
/**
|
|
4824
|
+
* Returns the result of the performance.now() method or null in browsers
|
|
4825
|
+
* that don't support the API.
|
|
4826
|
+
* @return {number} The elapsed time since the page was requested.
|
|
4827
|
+
*/
|
|
4828
|
+
function now() {
|
|
4829
|
+
return window.performance && performance.now && performance.now();
|
|
4830
|
+
}
|
|
4831
|
+
/**
|
|
4832
|
+
* Adds an event handler to a DOM node ensuring cross-browser compatibility.
|
|
4833
|
+
* @param {Node} node The DOM node to add the event handler to.
|
|
4834
|
+
* @param {string} event The event name.
|
|
4835
|
+
* @param {Function} fn The event handler to add.
|
|
4836
|
+
* @param {boolean} opt_useCapture Optionally adds the even to the capture
|
|
4837
|
+
* phase. Note: this only works in modern browsers.
|
|
4838
|
+
*/
|
|
4839
|
+
function addEvent(node, event, fn, opt_useCapture) {
|
|
4840
|
+
if (isFunction(node.addEventListener)) {
|
|
4841
|
+
node.addEventListener(event, fn, opt_useCapture || false);
|
|
4842
|
+
}
|
|
4843
|
+
else if (isFunction(node.attachEvent)) {
|
|
4844
|
+
node.attachEvent('on' + event, fn);
|
|
4845
|
+
}
|
|
4846
|
+
}
|
|
4847
|
+
/**
|
|
4848
|
+
* Removes a previously added event handler from a DOM node.
|
|
4849
|
+
* @param {Node} node The DOM node to remove the event handler from.
|
|
4850
|
+
* @param {string} event The event name.
|
|
4851
|
+
* @param {Function} fn The event handler to remove.
|
|
4852
|
+
* @param {boolean} opt_useCapture If the event handler was added with this
|
|
4853
|
+
* flag set to true, it should be set to true here in order to remove it.
|
|
4854
|
+
*/
|
|
4855
|
+
function removeEvent(node, event, fn, opt_useCapture) {
|
|
4856
|
+
if (isFunction(node.removeEventListener)) {
|
|
4857
|
+
node.removeEventListener(event, fn, opt_useCapture || false);
|
|
4858
|
+
}
|
|
4859
|
+
else if (isFunction(node.detatchEvent)) {
|
|
4860
|
+
node.detatchEvent('on' + event, fn);
|
|
4861
|
+
}
|
|
4862
|
+
}
|
|
4863
|
+
/**
|
|
4864
|
+
* Returns the intersection between two rect objects.
|
|
4865
|
+
* @param {Object} rect1 The first rect.
|
|
4866
|
+
* @param {Object} rect2 The second rect.
|
|
4867
|
+
* @return {?Object} The intersection rect or undefined if no intersection
|
|
4868
|
+
* is found.
|
|
4869
|
+
*/
|
|
4870
|
+
function computeRectIntersection(rect1, rect2) {
|
|
4871
|
+
const top = Math.max(rect1.top, rect2.top);
|
|
4872
|
+
const bottom = Math.min(rect1.bottom, rect2.bottom);
|
|
4873
|
+
const left = Math.max(rect1.left, rect2.left);
|
|
4874
|
+
const right = Math.min(rect1.right, rect2.right);
|
|
4875
|
+
const width = right - left;
|
|
4876
|
+
const height = bottom - top;
|
|
4877
|
+
return (width >= 0 && height >= 0) && {
|
|
4878
|
+
top: top,
|
|
4879
|
+
bottom: bottom,
|
|
4880
|
+
left: left,
|
|
4881
|
+
right: right,
|
|
4882
|
+
width: width,
|
|
4883
|
+
height: height
|
|
4884
|
+
};
|
|
4885
|
+
}
|
|
4886
|
+
/**
|
|
4887
|
+
* Shims the native getBoundingClientRect for compatibility with older IE.
|
|
4888
|
+
* @param {Element} el The element whose bounding rect to get.
|
|
4889
|
+
* @return {Object} The (possibly shimmed) rect of the element.
|
|
4890
|
+
*/
|
|
4891
|
+
function getBoundingClientRect(el) {
|
|
4892
|
+
let rect;
|
|
4893
|
+
try {
|
|
4894
|
+
rect = el.getBoundingClientRect();
|
|
4895
|
+
}
|
|
4896
|
+
catch (err) {
|
|
4897
|
+
// Ignore Windows 7 IE11 "Unspecified error"
|
|
4898
|
+
// https://github.com/w3c/IntersectionObserver/pull/205
|
|
4899
|
+
}
|
|
4900
|
+
if (!rect)
|
|
4901
|
+
return getEmptyRect();
|
|
4902
|
+
// Older IE
|
|
4903
|
+
if (!(rect.width && rect.height)) {
|
|
4904
|
+
rect = {
|
|
4905
|
+
top: rect.top,
|
|
4906
|
+
right: rect.right,
|
|
4907
|
+
bottom: rect.bottom,
|
|
4908
|
+
left: rect.left,
|
|
4909
|
+
width: rect.right - rect.left,
|
|
4910
|
+
height: rect.bottom - rect.top
|
|
4911
|
+
};
|
|
4912
|
+
}
|
|
4913
|
+
return rect;
|
|
4914
|
+
}
|
|
4915
|
+
/**
|
|
4916
|
+
* Returns an empty rect object. An empty rect is returned when an element
|
|
4917
|
+
* is not in the DOM.
|
|
4918
|
+
* @return {Object} The empty rect.
|
|
4919
|
+
*/
|
|
4920
|
+
function getEmptyRect() {
|
|
4921
|
+
return {
|
|
4922
|
+
top: 0,
|
|
4923
|
+
bottom: 0,
|
|
4924
|
+
left: 0,
|
|
4925
|
+
right: 0,
|
|
4926
|
+
width: 0,
|
|
4927
|
+
height: 0
|
|
4928
|
+
};
|
|
4929
|
+
}
|
|
4930
|
+
/**
|
|
4931
|
+
* Checks to see if a parent element contains a child element (including inside
|
|
4932
|
+
* shadow DOM).
|
|
4933
|
+
* @param {Node} parent The parent element.
|
|
4934
|
+
* @param {Node} child The child element.
|
|
4935
|
+
* @return {boolean} True if the parent node contains the child node.
|
|
4936
|
+
*/
|
|
4937
|
+
function containsDeep(parent, child) {
|
|
4938
|
+
let node = child;
|
|
4939
|
+
while (node) {
|
|
4940
|
+
if (node == parent)
|
|
4941
|
+
return true;
|
|
4942
|
+
node = getParentNode(node);
|
|
4943
|
+
}
|
|
4944
|
+
return false;
|
|
4945
|
+
}
|
|
4946
|
+
/**
|
|
4947
|
+
* Gets the parent node of an element or its host element if the parent node
|
|
4948
|
+
* is a shadow root.
|
|
4949
|
+
* @param {Node} node The node whose parent to get.
|
|
4950
|
+
* @return {Node|null} The parent node or null if no parent exists.
|
|
4951
|
+
*/
|
|
4952
|
+
function getParentNode(node) {
|
|
4953
|
+
const parent = node.parentNode;
|
|
4954
|
+
if (parent && parent.nodeType == 11 && parent.host) {
|
|
4955
|
+
// If the parent is a shadow root, return the host element.
|
|
4956
|
+
return parent.host;
|
|
4957
|
+
}
|
|
4958
|
+
if (parent && parent.assignedSlot) {
|
|
4959
|
+
// If the parent is distributed in a <slot>, return the parent of a slot.
|
|
4960
|
+
return parent.assignedSlot.parentNode;
|
|
4961
|
+
}
|
|
4962
|
+
return parent;
|
|
4963
|
+
}
|
|
4964
|
+
// Exposes the constructors globally.
|
|
4965
|
+
window.IntersectionObserver = IntersectionObserver;
|
|
4966
|
+
window.IntersectionObserverEntry = IntersectionObserverEntry;
|
|
4967
|
+
}
|
|
4968
|
+
|
|
4969
|
+
function handleObjectAssignPolyfill() {
|
|
4970
|
+
if (!isFunction(Object.assign)) {
|
|
4971
|
+
// Must be writable: true, enumerable: false, configurable: true
|
|
4972
|
+
Object.assign = function (target) {
|
|
4973
|
+
if (target == null) { // TypeError if undefined or null
|
|
4974
|
+
throw new TypeError('Cannot convert undefined or null to object');
|
|
4975
|
+
}
|
|
4976
|
+
const to = Object(target);
|
|
4977
|
+
for (let index = 1; index < arguments.length; index++) {
|
|
4978
|
+
const nextSource = arguments[index];
|
|
4979
|
+
if (nextSource != null) { // Skip over if undefined or null
|
|
4980
|
+
for (const nextKey in nextSource) {
|
|
4981
|
+
// Avoid bugs when hasOwnProperty is shadowed
|
|
4982
|
+
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
|
4983
|
+
to[nextKey] = nextSource[nextKey];
|
|
4984
|
+
}
|
|
4985
|
+
}
|
|
4986
|
+
}
|
|
4987
|
+
}
|
|
4988
|
+
return to;
|
|
4989
|
+
};
|
|
4990
|
+
}
|
|
4991
|
+
}
|
|
4992
|
+
function handleObjectEntriesPolyfill() {
|
|
4993
|
+
if (!isFunction(Object.entries)) {
|
|
4994
|
+
// Must be writable: true, enumerable: false, configurable: true
|
|
4995
|
+
Object.entries = function (obj) {
|
|
4996
|
+
if (obj == null) { // TypeError if undefined or null
|
|
4997
|
+
throw new TypeError('Cannot convert undefined or null to object');
|
|
4998
|
+
}
|
|
4999
|
+
const to = [];
|
|
5000
|
+
if (obj != null) { // Skip over if undefined or null
|
|
5001
|
+
for (const key in obj) {
|
|
5002
|
+
// Avoid bugs when hasOwnProperty is shadowed
|
|
5003
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
5004
|
+
to.push([key, obj[key]]);
|
|
5005
|
+
}
|
|
5006
|
+
}
|
|
5007
|
+
}
|
|
5008
|
+
return to;
|
|
5009
|
+
};
|
|
5010
|
+
}
|
|
5011
|
+
}
|
|
5012
|
+
function handleObjectDefinePropertyPolyfill() {
|
|
5013
|
+
if (!isFunction(Object.defineProperties)) {
|
|
5014
|
+
Object.defineProperties = function (obj, properties) {
|
|
5015
|
+
function convertToDescriptor(desc) {
|
|
5016
|
+
function hasProperty(obj, prop) {
|
|
5017
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
5018
|
+
}
|
|
5019
|
+
if (!isObject(desc)) {
|
|
5020
|
+
throw new TypeError('bad desc');
|
|
5021
|
+
}
|
|
5022
|
+
const d = {};
|
|
5023
|
+
if (hasProperty(desc, 'enumerable'))
|
|
5024
|
+
d.enumerable = !!desc.enumerable;
|
|
5025
|
+
if (hasProperty(desc, 'configurable')) {
|
|
5026
|
+
d.configurable = !!desc.configurable;
|
|
5027
|
+
}
|
|
5028
|
+
if (hasProperty(desc, 'value'))
|
|
5029
|
+
d.value = desc.value;
|
|
5030
|
+
if (hasProperty(desc, 'writable'))
|
|
5031
|
+
d.writable = !!desc.writable;
|
|
5032
|
+
if (hasProperty(desc, 'get')) {
|
|
5033
|
+
const g = desc.get;
|
|
5034
|
+
if (!isFunction(g) && !isUndefined(g)) {
|
|
5035
|
+
throw new TypeError('bad get');
|
|
5036
|
+
}
|
|
5037
|
+
d.get = g;
|
|
5038
|
+
}
|
|
5039
|
+
if (hasProperty(desc, 'set')) {
|
|
5040
|
+
const s = desc.set;
|
|
5041
|
+
if (!isFunction(s) && !isUndefined(s)) {
|
|
5042
|
+
throw new TypeError('bad set');
|
|
5043
|
+
}
|
|
5044
|
+
d.set = s;
|
|
5045
|
+
}
|
|
5046
|
+
if (('get' in d || 'set' in d) && ('value' in d || 'writable' in d)) {
|
|
5047
|
+
throw new TypeError('identity-confused descriptor');
|
|
5048
|
+
}
|
|
5049
|
+
return d;
|
|
5050
|
+
}
|
|
5051
|
+
if (!isObject(obj))
|
|
5052
|
+
throw new TypeError('bad obj');
|
|
5053
|
+
properties = Object(properties);
|
|
5054
|
+
const keys = Object.keys(properties);
|
|
5055
|
+
const descs = [];
|
|
5056
|
+
for (let i = 0; i < keys.length; i++) {
|
|
5057
|
+
descs.push([keys[i], convertToDescriptor(properties[keys[i]])]);
|
|
5058
|
+
}
|
|
5059
|
+
for (let i = 0; i < descs.length; i++) {
|
|
5060
|
+
Object.defineProperty(obj, descs[i][0], descs[i][1]);
|
|
5061
|
+
}
|
|
5062
|
+
return obj;
|
|
5063
|
+
};
|
|
5064
|
+
}
|
|
5065
|
+
}
|
|
5066
|
+
|
|
5067
|
+
function handlePolyfill() {
|
|
5068
|
+
if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Object' || process.env.SUPPORT_TARO_POLYFILL === 'Object.assign') {
|
|
5069
|
+
handleObjectAssignPolyfill();
|
|
5070
|
+
}
|
|
5071
|
+
if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Object' || process.env.SUPPORT_TARO_POLYFILL === 'Object.entries') {
|
|
5072
|
+
handleObjectEntriesPolyfill();
|
|
5073
|
+
}
|
|
5074
|
+
if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Object' || process.env.SUPPORT_TARO_POLYFILL === 'Object.defineProperty') {
|
|
5075
|
+
handleObjectDefinePropertyPolyfill();
|
|
5076
|
+
}
|
|
5077
|
+
if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Array' || process.env.SUPPORT_TARO_POLYFILL === 'Array.find') {
|
|
5078
|
+
handleArrayFindPolyfill();
|
|
5079
|
+
}
|
|
5080
|
+
if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Array' || process.env.SUPPORT_TARO_POLYFILL === 'Array.includes') {
|
|
5081
|
+
handleArrayIncludesPolyfill();
|
|
5082
|
+
}
|
|
5083
|
+
// Exit early if we're not running in a browser.
|
|
5084
|
+
if (process.env.TARO_PLATFORM === 'web' && isObject(window)) {
|
|
5085
|
+
if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'IntersectionObserver') {
|
|
5086
|
+
handleIntersectionObserverPolyfill();
|
|
5087
|
+
}
|
|
5088
|
+
}
|
|
5089
|
+
}
|
|
5090
|
+
if (process.env.SUPPORT_TARO_POLYFILL !== 'disabled' && process.env.TARO_PLATFORM !== 'web') {
|
|
5091
|
+
handlePolyfill();
|
|
5092
|
+
}
|
|
5093
|
+
|
|
5094
|
+
export { A, APP, BEHAVIORS, BODY, CATCHMOVE, CATCH_VIEW, CHANGE, CLASS, COMMENT, COMPILE_MODE, CONFIRM, CONTAINER, CONTEXT_ACTIONS, CURRENT_TARGET, CUSTOM_WRAPPER, Current, DATASET, DATE, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, EVENT_CALLBACK_RESULT, EXTERNAL_CLASSES, FOCUS, FormElement, HEAD, HOOKS_APP_ID, HTML, History, ID, INPUT, KEY_CODE, Location, MutationObserver$1 as MutationObserver, OBJECT, ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, OPTIONS, PAGE_INIT, PROPERTY_THRESHOLD, PROPS, PURE_VIEW, ROOT_STR, SET_DATA, SET_TIMEOUT, STATIC_VIEW, STYLE, SVGElement, Style, TARGET, TARO_RUNTIME, TIME_STAMP, TOUCHMOVE, TYPE, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, UID, URL, URLSearchParams, VALUE, VIEW, addLeadingSlash, _caf as cancelAnimationFrame, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, document$1 as document, env, eventCenter, eventHandler, eventSource, getComputedStyle, getCurrentInstance, getCurrentPage, getHomePage, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, handlePolyfill, hasBasename, history, hydrate, incrementId, injectPageInstance, isHasExtractProp, location, nav as navigator, nextTick, now, options, parseUrl, removePageInstance, _raf as requestAnimationFrame, safeExecute, stringify, stripBasename, stripSuffix, stripTrailing, window$1 as window };
|
|
4249
5095
|
//# sourceMappingURL=runtime.esm.js.map
|