@tarojs/runtime 3.6.22 → 3.6.23
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 +123 -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 +3 -4
- 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 +151 -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 +3 -2
- 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 +216 -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 +6 -5
- package/dist/dom-external/inner-html/tags.js +26 -0
- package/dist/dom-external/inner-html/tags.js.map +1 -0
- package/dist/dom-external/inner-html/utils.d.ts +2 -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 +74 -0
- package/dist/dom-external/node.js.map +1 -0
- package/dist/dsl/common.d.ts +15 -16
- package/dist/dsl/common.js +332 -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 +84 -0
- package/dist/hydrate.js.map +1 -0
- package/dist/index-26658829.d.ts +23 -0
- package/dist/index.cjs.d.ts +784 -0
- package/dist/index.cjs.js +5129 -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} +19 -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 +91 -89
- package/dist/runtime.esm.js +1165 -398
- 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 } 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,7 +169,7 @@ 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);
|
|
@@ -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 = () => {
|
|
@@ -393,10 +414,9 @@ 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;
|
|
@@ -650,7 +670,7 @@ class TaroNode extends TaroEventTarget {
|
|
|
650
670
|
this.updateChildNodes();
|
|
651
671
|
}
|
|
652
672
|
// @Todo: appendChild 会多触发一次
|
|
653
|
-
MutationObserver.record({
|
|
673
|
+
MutationObserver$1.record({
|
|
654
674
|
type: "childList" /* MutationRecordType.CHILD_LIST */,
|
|
655
675
|
target: this,
|
|
656
676
|
removedNodes,
|
|
@@ -735,7 +755,7 @@ class TaroNode extends TaroEventTarget {
|
|
|
735
755
|
}
|
|
736
756
|
}
|
|
737
757
|
}
|
|
738
|
-
MutationObserver.record({
|
|
758
|
+
MutationObserver$1.record({
|
|
739
759
|
type: "childList" /* MutationRecordType.CHILD_LIST */,
|
|
740
760
|
target: this,
|
|
741
761
|
addedNodes: [newChild],
|
|
@@ -791,7 +811,7 @@ class TaroNode extends TaroEventTarget {
|
|
|
791
811
|
if (cleanRef !== false && doUpdate !== false) {
|
|
792
812
|
// appendChild/replaceChild/insertBefore 不应该触发
|
|
793
813
|
// @Todo: 但其实如果 newChild 的父节点是另一颗子树的节点,应该是要触发的
|
|
794
|
-
MutationObserver.record({
|
|
814
|
+
MutationObserver$1.record({
|
|
795
815
|
type: "childList" /* MutationRecordType.CHILD_LIST */,
|
|
796
816
|
target: this,
|
|
797
817
|
removedNodes: [child],
|
|
@@ -1017,7 +1037,7 @@ combine('box', ['DecorationBreak', 'Shadow', 'Sizing', 'Snap'], true);
|
|
|
1017
1037
|
combine(WEBKIT, ['LineClamp', 'BoxOrient', 'TextFillColor', 'TextStroke', 'TextStrokeColor', 'TextStrokeWidth'], true);
|
|
1018
1038
|
|
|
1019
1039
|
function recordCss(obj) {
|
|
1020
|
-
MutationObserver.record({
|
|
1040
|
+
MutationObserver$1.record({
|
|
1021
1041
|
type: "attributes" /* MutationRecordType.ATTRIBUTES */,
|
|
1022
1042
|
target: obj._element,
|
|
1023
1043
|
attributeName: 'style',
|
|
@@ -1298,7 +1318,7 @@ class TaroElement extends TaroNode {
|
|
|
1298
1318
|
process.env.NODE_ENV !== 'production' && warn(isString(value) && value.length > PROPERTY_THRESHOLD, `元素 ${this.nodeName} 的 ${qualifiedName} 属性值数据量过大,可能会影响渲染性能。考虑降低图片转为 base64 的阈值或在 CSS 中使用 base64。`);
|
|
1299
1319
|
const isPureView = this.nodeName === VIEW && !isHasExtractProp(this) && !this.isAnyEventBinded();
|
|
1300
1320
|
if (qualifiedName !== STYLE) {
|
|
1301
|
-
MutationObserver.record({
|
|
1321
|
+
MutationObserver$1.record({
|
|
1302
1322
|
target: this,
|
|
1303
1323
|
type: "attributes" /* MutationRecordType.ATTRIBUTES */,
|
|
1304
1324
|
attributeName: qualifiedName,
|
|
@@ -1370,7 +1390,7 @@ class TaroElement extends TaroNode {
|
|
|
1370
1390
|
}
|
|
1371
1391
|
removeAttribute(qualifiedName) {
|
|
1372
1392
|
const isStaticView = this.nodeName === VIEW && isHasExtractProp(this) && !this.isAnyEventBinded();
|
|
1373
|
-
MutationObserver.record({
|
|
1393
|
+
MutationObserver$1.record({
|
|
1374
1394
|
target: this,
|
|
1375
1395
|
type: "attributes" /* MutationRecordType.ATTRIBUTES */,
|
|
1376
1396
|
attributeName: qualifiedName,
|
|
@@ -2410,7 +2430,7 @@ function contains(node) {
|
|
|
2410
2430
|
return isContains;
|
|
2411
2431
|
}
|
|
2412
2432
|
|
|
2413
|
-
if (
|
|
2433
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
2414
2434
|
if (ENABLE_INNER_HTML) {
|
|
2415
2435
|
TaroNode.extend('innerHTML', {
|
|
2416
2436
|
set(html) {
|
|
@@ -2811,7 +2831,7 @@ class TaroText extends TaroNode {
|
|
|
2811
2831
|
this._value = value;
|
|
2812
2832
|
}
|
|
2813
2833
|
set textContent(text) {
|
|
2814
|
-
MutationObserver.record({
|
|
2834
|
+
MutationObserver$1.record({
|
|
2815
2835
|
target: this,
|
|
2816
2836
|
type: "characterData" /* MutationRecordType.CHARACTER_DATA */,
|
|
2817
2837
|
oldValue: this._value
|
|
@@ -2839,35 +2859,7 @@ class TaroText extends TaroNode {
|
|
|
2839
2859
|
}
|
|
2840
2860
|
}
|
|
2841
2861
|
|
|
2842
|
-
|
|
2843
|
-
Copyright (c) Microsoft Corporation.
|
|
2844
|
-
|
|
2845
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
2846
|
-
purpose with or without fee is hereby granted.
|
|
2847
|
-
|
|
2848
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
2849
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
2850
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
2851
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
2852
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
2853
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
2854
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
2855
|
-
***************************************************************************** */
|
|
2856
|
-
|
|
2857
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
2858
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
2859
|
-
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");
|
|
2860
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
2861
|
-
}
|
|
2862
|
-
|
|
2863
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
2864
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
2865
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
2866
|
-
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");
|
|
2867
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
2868
|
-
}
|
|
2869
|
-
|
|
2870
|
-
var _URLSearchParams_dict;
|
|
2862
|
+
var _dict, _a;
|
|
2871
2863
|
const findReg = /[!'()~]|%20|%00/g;
|
|
2872
2864
|
const plusReg = /\+/g;
|
|
2873
2865
|
const replaceCharMap = {
|
|
@@ -2898,93 +2890,94 @@ function decode(str) {
|
|
|
2898
2890
|
function encode(str) {
|
|
2899
2891
|
return encodeURIComponent(str).replace(findReg, replacer);
|
|
2900
2892
|
}
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
}
|
|
2910
|
-
for (let pairs = query.split('&'), i = 0, length = pairs.length; i < length; i++) {
|
|
2911
|
-
const value = pairs[i];
|
|
2912
|
-
const index = value.indexOf('=');
|
|
2913
|
-
if (index > -1) {
|
|
2914
|
-
appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));
|
|
2893
|
+
const URLSearchParams = process.env.TARO_PLATFORM === 'web' ? env.window.URLSearchParams : (_a = class {
|
|
2894
|
+
constructor(query) {
|
|
2895
|
+
_dict.set(this, Object.create(null));
|
|
2896
|
+
query !== null && query !== void 0 ? query : (query = '');
|
|
2897
|
+
const dict = __classPrivateFieldGet(this, _dict, "f");
|
|
2898
|
+
if (typeof query === 'string') {
|
|
2899
|
+
if (query.charAt(0) === '?') {
|
|
2900
|
+
query = query.slice(1);
|
|
2915
2901
|
}
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
appendTo(dict, value[0], value[1]);
|
|
2902
|
+
for (let pairs = query.split('&'), i = 0, length = pairs.length; i < length; i++) {
|
|
2903
|
+
const value = pairs[i];
|
|
2904
|
+
const index = value.indexOf('=');
|
|
2905
|
+
if (index > -1) {
|
|
2906
|
+
appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));
|
|
2907
|
+
}
|
|
2908
|
+
else if (value.length) {
|
|
2909
|
+
appendTo(dict, decode(value), '');
|
|
2910
|
+
}
|
|
2926
2911
|
}
|
|
2927
2912
|
}
|
|
2928
|
-
else if (query.forEach) {
|
|
2929
|
-
query.forEach(addEach, dict);
|
|
2930
|
-
}
|
|
2931
2913
|
else {
|
|
2932
|
-
|
|
2933
|
-
|
|
2914
|
+
if (isArray(query)) {
|
|
2915
|
+
for (let i = 0, length = query.length; i < length; i++) {
|
|
2916
|
+
const value = query[i];
|
|
2917
|
+
appendTo(dict, value[0], value[1]);
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
else if (query.forEach) {
|
|
2921
|
+
query.forEach(addEach, dict);
|
|
2922
|
+
}
|
|
2923
|
+
else {
|
|
2924
|
+
for (const key in query) {
|
|
2925
|
+
appendTo(dict, key, query[key]);
|
|
2926
|
+
}
|
|
2934
2927
|
}
|
|
2935
2928
|
}
|
|
2936
2929
|
}
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2930
|
+
append(name, value) {
|
|
2931
|
+
appendTo(__classPrivateFieldGet(this, _dict, "f"), name, value);
|
|
2932
|
+
}
|
|
2933
|
+
delete(name) {
|
|
2934
|
+
delete __classPrivateFieldGet(this, _dict, "f")[name];
|
|
2935
|
+
}
|
|
2936
|
+
get(name) {
|
|
2937
|
+
const dict = __classPrivateFieldGet(this, _dict, "f");
|
|
2938
|
+
return name in dict ? dict[name][0] : null;
|
|
2939
|
+
}
|
|
2940
|
+
getAll(name) {
|
|
2941
|
+
const dict = __classPrivateFieldGet(this, _dict, "f");
|
|
2942
|
+
return name in dict ? dict[name].slice(0) : [];
|
|
2943
|
+
}
|
|
2944
|
+
has(name) {
|
|
2945
|
+
return name in __classPrivateFieldGet(this, _dict, "f");
|
|
2946
|
+
}
|
|
2947
|
+
keys() {
|
|
2948
|
+
return Object.keys(__classPrivateFieldGet(this, _dict, "f"));
|
|
2949
|
+
}
|
|
2950
|
+
set(name, value) {
|
|
2951
|
+
__classPrivateFieldGet(this, _dict, "f")[name] = ['' + value];
|
|
2952
|
+
}
|
|
2953
|
+
forEach(callback, thisArg) {
|
|
2954
|
+
const dict = __classPrivateFieldGet(this, _dict, "f");
|
|
2955
|
+
Object.getOwnPropertyNames(dict).forEach(function (name) {
|
|
2956
|
+
dict[name].forEach(function (value) {
|
|
2957
|
+
callback.call(thisArg, value, name, this);
|
|
2958
|
+
}, this);
|
|
2966
2959
|
}, this);
|
|
2967
|
-
}
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2960
|
+
}
|
|
2961
|
+
toJSON() {
|
|
2962
|
+
return {};
|
|
2963
|
+
}
|
|
2964
|
+
toString() {
|
|
2965
|
+
const dict = __classPrivateFieldGet(this, _dict, "f");
|
|
2966
|
+
const query = [];
|
|
2967
|
+
for (const key in dict) {
|
|
2968
|
+
const name = encode(key);
|
|
2969
|
+
for (let i = 0, value = dict[key]; i < value.length; i++) {
|
|
2970
|
+
query.push(name + '=' + encode(value[i]));
|
|
2971
|
+
}
|
|
2979
2972
|
}
|
|
2973
|
+
return query.join('&');
|
|
2980
2974
|
}
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
_URLSearchParams_dict = new WeakMap();
|
|
2975
|
+
},
|
|
2976
|
+
_dict = new WeakMap(),
|
|
2977
|
+
_a);
|
|
2985
2978
|
|
|
2986
|
-
var
|
|
2987
|
-
class
|
|
2979
|
+
var _TaroURL_hash, _TaroURL_hostname, _TaroURL_pathname, _TaroURL_port, _TaroURL_protocol, _TaroURL_search;
|
|
2980
|
+
class TaroURL {
|
|
2988
2981
|
static createObjectURL() {
|
|
2989
2982
|
throw new Error('Oops, not support URL.createObjectURL() in miniprogram.');
|
|
2990
2983
|
}
|
|
@@ -2993,29 +2986,29 @@ class URL {
|
|
|
2993
2986
|
}
|
|
2994
2987
|
constructor(url, base) {
|
|
2995
2988
|
/* private property */
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
2989
|
+
_TaroURL_hash.set(this, '');
|
|
2990
|
+
_TaroURL_hostname.set(this, '');
|
|
2991
|
+
_TaroURL_pathname.set(this, '');
|
|
2992
|
+
_TaroURL_port.set(this, '');
|
|
2993
|
+
_TaroURL_protocol.set(this, '');
|
|
2994
|
+
_TaroURL_search.set(this, void 0);
|
|
3002
2995
|
if (!isString(url))
|
|
3003
2996
|
url = String(url);
|
|
3004
2997
|
const parseResult = parseUrlBase(url, base);
|
|
3005
2998
|
const { hash, hostname, pathname, port, protocol, search } = parseResult;
|
|
3006
|
-
__classPrivateFieldSet(this,
|
|
3007
|
-
__classPrivateFieldSet(this,
|
|
3008
|
-
__classPrivateFieldSet(this,
|
|
3009
|
-
__classPrivateFieldSet(this,
|
|
3010
|
-
__classPrivateFieldSet(this,
|
|
3011
|
-
__classPrivateFieldSet(this,
|
|
2999
|
+
__classPrivateFieldSet(this, _TaroURL_hash, hash, "f");
|
|
3000
|
+
__classPrivateFieldSet(this, _TaroURL_hostname, hostname, "f");
|
|
3001
|
+
__classPrivateFieldSet(this, _TaroURL_pathname, pathname || '/', "f");
|
|
3002
|
+
__classPrivateFieldSet(this, _TaroURL_port, port, "f");
|
|
3003
|
+
__classPrivateFieldSet(this, _TaroURL_protocol, protocol, "f");
|
|
3004
|
+
__classPrivateFieldSet(this, _TaroURL_search, new URLSearchParams(search), "f");
|
|
3012
3005
|
}
|
|
3013
3006
|
/* public property */
|
|
3014
3007
|
get protocol() {
|
|
3015
|
-
return __classPrivateFieldGet(this,
|
|
3008
|
+
return __classPrivateFieldGet(this, _TaroURL_protocol, "f");
|
|
3016
3009
|
}
|
|
3017
3010
|
set protocol(val) {
|
|
3018
|
-
isString(val) && (__classPrivateFieldSet(this,
|
|
3011
|
+
isString(val) && (__classPrivateFieldSet(this, _TaroURL_protocol, val.trim(), "f"));
|
|
3019
3012
|
}
|
|
3020
3013
|
get host() {
|
|
3021
3014
|
return this.hostname + (this.port ? ':' + this.port : '');
|
|
@@ -3029,19 +3022,19 @@ class URL {
|
|
|
3029
3022
|
}
|
|
3030
3023
|
}
|
|
3031
3024
|
get hostname() {
|
|
3032
|
-
return __classPrivateFieldGet(this,
|
|
3025
|
+
return __classPrivateFieldGet(this, _TaroURL_hostname, "f");
|
|
3033
3026
|
}
|
|
3034
3027
|
set hostname(val) {
|
|
3035
|
-
val && isString(val) && (__classPrivateFieldSet(this,
|
|
3028
|
+
val && isString(val) && (__classPrivateFieldSet(this, _TaroURL_hostname, val.trim(), "f"));
|
|
3036
3029
|
}
|
|
3037
3030
|
get port() {
|
|
3038
|
-
return __classPrivateFieldGet(this,
|
|
3031
|
+
return __classPrivateFieldGet(this, _TaroURL_port, "f");
|
|
3039
3032
|
}
|
|
3040
3033
|
set port(val) {
|
|
3041
|
-
isString(val) && (__classPrivateFieldSet(this,
|
|
3034
|
+
isString(val) && (__classPrivateFieldSet(this, _TaroURL_port, val.trim(), "f"));
|
|
3042
3035
|
}
|
|
3043
3036
|
get pathname() {
|
|
3044
|
-
return __classPrivateFieldGet(this,
|
|
3037
|
+
return __classPrivateFieldGet(this, _TaroURL_pathname, "f");
|
|
3045
3038
|
}
|
|
3046
3039
|
set pathname(val) {
|
|
3047
3040
|
if (isString(val)) {
|
|
@@ -3052,31 +3045,31 @@ class URL {
|
|
|
3052
3045
|
temp = temp.replace(HEAD_REG, '');
|
|
3053
3046
|
}
|
|
3054
3047
|
if (temp)
|
|
3055
|
-
__classPrivateFieldSet(this,
|
|
3048
|
+
__classPrivateFieldSet(this, _TaroURL_pathname, '/' + temp, "f");
|
|
3056
3049
|
else
|
|
3057
|
-
__classPrivateFieldSet(this,
|
|
3050
|
+
__classPrivateFieldSet(this, _TaroURL_pathname, '/', "f");
|
|
3058
3051
|
}
|
|
3059
3052
|
}
|
|
3060
3053
|
get search() {
|
|
3061
|
-
const val = __classPrivateFieldGet(this,
|
|
3054
|
+
const val = __classPrivateFieldGet(this, _TaroURL_search, "f").toString();
|
|
3062
3055
|
return (val.length === 0 || val.startsWith('?')) ? val : `?${val}`;
|
|
3063
3056
|
}
|
|
3064
3057
|
set search(val) {
|
|
3065
3058
|
if (isString(val)) {
|
|
3066
3059
|
val = val.trim();
|
|
3067
|
-
__classPrivateFieldSet(this,
|
|
3060
|
+
__classPrivateFieldSet(this, _TaroURL_search, new URLSearchParams(val), "f");
|
|
3068
3061
|
}
|
|
3069
3062
|
}
|
|
3070
3063
|
get hash() {
|
|
3071
|
-
return __classPrivateFieldGet(this,
|
|
3064
|
+
return __classPrivateFieldGet(this, _TaroURL_hash, "f");
|
|
3072
3065
|
}
|
|
3073
3066
|
set hash(val) {
|
|
3074
3067
|
if (isString(val)) {
|
|
3075
3068
|
val = val.trim();
|
|
3076
3069
|
if (val)
|
|
3077
|
-
__classPrivateFieldSet(this,
|
|
3070
|
+
__classPrivateFieldSet(this, _TaroURL_hash, val.startsWith('#') ? val : `#${val}`, "f");
|
|
3078
3071
|
else
|
|
3079
|
-
__classPrivateFieldSet(this,
|
|
3072
|
+
__classPrivateFieldSet(this, _TaroURL_hash, '', "f");
|
|
3080
3073
|
}
|
|
3081
3074
|
}
|
|
3082
3075
|
get href() {
|
|
@@ -3107,7 +3100,7 @@ class URL {
|
|
|
3107
3100
|
}
|
|
3108
3101
|
}
|
|
3109
3102
|
get searchParams() {
|
|
3110
|
-
return __classPrivateFieldGet(this,
|
|
3103
|
+
return __classPrivateFieldGet(this, _TaroURL_search, "f");
|
|
3111
3104
|
}
|
|
3112
3105
|
// public method
|
|
3113
3106
|
toString() {
|
|
@@ -3131,7 +3124,8 @@ class URL {
|
|
|
3131
3124
|
};
|
|
3132
3125
|
}
|
|
3133
3126
|
}
|
|
3134
|
-
|
|
3127
|
+
_TaroURL_hash = new WeakMap(), _TaroURL_hostname = new WeakMap(), _TaroURL_pathname = new WeakMap(), _TaroURL_port = new WeakMap(), _TaroURL_protocol = new WeakMap(), _TaroURL_search = new WeakMap();
|
|
3128
|
+
const URL = process.env.TARO_PLATFORM === 'web' ? env.window.URL : TaroURL;
|
|
3135
3129
|
function parseUrl(url = '') {
|
|
3136
3130
|
const result = {
|
|
3137
3131
|
href: '',
|
|
@@ -3322,49 +3316,42 @@ class TaroDocument extends TaroElement {
|
|
|
3322
3316
|
}
|
|
3323
3317
|
}
|
|
3324
3318
|
|
|
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
|
-
|
|
3355
|
-
doc.head = head;
|
|
3356
|
-
doc.body = body;
|
|
3357
|
-
return doc;
|
|
3358
|
-
}
|
|
3359
|
-
document$1 = env.document = createDocument();
|
|
3360
|
-
}
|
|
3361
|
-
else {
|
|
3362
|
-
document$1 = env.document;
|
|
3319
|
+
function createDocument() {
|
|
3320
|
+
/**
|
|
3321
|
+
* <document>
|
|
3322
|
+
* <html>
|
|
3323
|
+
* <head></head>
|
|
3324
|
+
* <body>
|
|
3325
|
+
* <container>
|
|
3326
|
+
* <app id="app" />
|
|
3327
|
+
* </container>
|
|
3328
|
+
* </body>
|
|
3329
|
+
* </html>
|
|
3330
|
+
* </document>
|
|
3331
|
+
*/
|
|
3332
|
+
const doc = new TaroDocument();
|
|
3333
|
+
const documentCreateElement = doc.createElement.bind(doc);
|
|
3334
|
+
const html = documentCreateElement(HTML);
|
|
3335
|
+
const head = documentCreateElement(HEAD);
|
|
3336
|
+
const body = documentCreateElement(BODY);
|
|
3337
|
+
const app = documentCreateElement(APP);
|
|
3338
|
+
app.id = APP;
|
|
3339
|
+
const container = documentCreateElement(CONTAINER); // 多包一层主要为了兼容 vue
|
|
3340
|
+
doc.appendChild(html);
|
|
3341
|
+
html.appendChild(head);
|
|
3342
|
+
html.appendChild(body);
|
|
3343
|
+
body.appendChild(container);
|
|
3344
|
+
container.appendChild(app);
|
|
3345
|
+
doc.documentElement = html;
|
|
3346
|
+
doc.head = head;
|
|
3347
|
+
doc.body = body;
|
|
3348
|
+
return doc;
|
|
3363
3349
|
}
|
|
3350
|
+
const document$1 = process.env.TARO_PLATFORM === 'web' ? env.document : (env.document = createDocument());
|
|
3364
3351
|
|
|
3365
|
-
function
|
|
3352
|
+
const getComputedStyle = process.env.TARO_PLATFORM === 'web' ? env.window.getComputedStyle : function (element) {
|
|
3366
3353
|
return element.style;
|
|
3367
|
-
}
|
|
3354
|
+
};
|
|
3368
3355
|
|
|
3369
3356
|
const eventCenter = hooks.call('getEventCenter', Events);
|
|
3370
3357
|
|
|
@@ -3393,72 +3380,72 @@ class RuntimeCache {
|
|
|
3393
3380
|
}
|
|
3394
3381
|
}
|
|
3395
3382
|
|
|
3396
|
-
var
|
|
3383
|
+
var _TaroHistory_instances, _TaroHistory_location, _TaroHistory_stack, _TaroHistory_cur, _TaroHistory_window, _TaroHistory_reset;
|
|
3397
3384
|
const cache$1 = new RuntimeCache('history');
|
|
3398
|
-
class
|
|
3385
|
+
class TaroHistory extends Events {
|
|
3399
3386
|
constructor(location, options) {
|
|
3400
3387
|
super();
|
|
3401
|
-
|
|
3388
|
+
_TaroHistory_instances.add(this);
|
|
3402
3389
|
/* private property */
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
__classPrivateFieldSet(this,
|
|
3408
|
-
__classPrivateFieldSet(this,
|
|
3409
|
-
__classPrivateFieldGet(this,
|
|
3390
|
+
_TaroHistory_location.set(this, void 0);
|
|
3391
|
+
_TaroHistory_stack.set(this, []);
|
|
3392
|
+
_TaroHistory_cur.set(this, 0);
|
|
3393
|
+
_TaroHistory_window.set(this, void 0);
|
|
3394
|
+
__classPrivateFieldSet(this, _TaroHistory_window, options.window, "f");
|
|
3395
|
+
__classPrivateFieldSet(this, _TaroHistory_location, location, "f");
|
|
3396
|
+
__classPrivateFieldGet(this, _TaroHistory_location, "f").on('__record_history__', (href) => {
|
|
3410
3397
|
var _a;
|
|
3411
|
-
__classPrivateFieldSet(this,
|
|
3412
|
-
__classPrivateFieldSet(this,
|
|
3413
|
-
__classPrivateFieldGet(this,
|
|
3398
|
+
__classPrivateFieldSet(this, _TaroHistory_cur, (_a = __classPrivateFieldGet(this, _TaroHistory_cur, "f"), _a++, _a), "f");
|
|
3399
|
+
__classPrivateFieldSet(this, _TaroHistory_stack, __classPrivateFieldGet(this, _TaroHistory_stack, "f").slice(0, __classPrivateFieldGet(this, _TaroHistory_cur, "f")), "f");
|
|
3400
|
+
__classPrivateFieldGet(this, _TaroHistory_stack, "f").push({
|
|
3414
3401
|
state: null,
|
|
3415
3402
|
title: '',
|
|
3416
3403
|
url: href
|
|
3417
3404
|
});
|
|
3418
3405
|
}, null);
|
|
3419
|
-
__classPrivateFieldGet(this,
|
|
3420
|
-
__classPrivateFieldGet(this,
|
|
3406
|
+
__classPrivateFieldGet(this, _TaroHistory_location, "f").on('__reset_history__', (href) => {
|
|
3407
|
+
__classPrivateFieldGet(this, _TaroHistory_instances, "m", _TaroHistory_reset).call(this, href);
|
|
3421
3408
|
}, null);
|
|
3422
3409
|
// 切换上下文行为
|
|
3423
3410
|
this.on(CONTEXT_ACTIONS.INIT, () => {
|
|
3424
|
-
__classPrivateFieldGet(this,
|
|
3411
|
+
__classPrivateFieldGet(this, _TaroHistory_instances, "m", _TaroHistory_reset).call(this);
|
|
3425
3412
|
}, null);
|
|
3426
3413
|
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3427
3414
|
cache$1.set(pageId, {
|
|
3428
|
-
location: __classPrivateFieldGet(this,
|
|
3429
|
-
stack: __classPrivateFieldGet(this,
|
|
3430
|
-
cur: __classPrivateFieldGet(this,
|
|
3415
|
+
location: __classPrivateFieldGet(this, _TaroHistory_location, "f"),
|
|
3416
|
+
stack: __classPrivateFieldGet(this, _TaroHistory_stack, "f").slice(),
|
|
3417
|
+
cur: __classPrivateFieldGet(this, _TaroHistory_cur, "f")
|
|
3431
3418
|
});
|
|
3432
3419
|
}, null);
|
|
3433
3420
|
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
3434
3421
|
if (cache$1.has(pageId)) {
|
|
3435
3422
|
const ctx = cache$1.get(pageId);
|
|
3436
|
-
__classPrivateFieldSet(this,
|
|
3437
|
-
__classPrivateFieldSet(this,
|
|
3438
|
-
__classPrivateFieldSet(this,
|
|
3423
|
+
__classPrivateFieldSet(this, _TaroHistory_location, ctx.location, "f");
|
|
3424
|
+
__classPrivateFieldSet(this, _TaroHistory_stack, ctx.stack, "f");
|
|
3425
|
+
__classPrivateFieldSet(this, _TaroHistory_cur, ctx.cur, "f");
|
|
3439
3426
|
}
|
|
3440
3427
|
}, null);
|
|
3441
3428
|
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
3442
3429
|
cache$1.delete(pageId);
|
|
3443
3430
|
}, null);
|
|
3444
|
-
__classPrivateFieldGet(this,
|
|
3431
|
+
__classPrivateFieldGet(this, _TaroHistory_instances, "m", _TaroHistory_reset).call(this);
|
|
3445
3432
|
}
|
|
3446
3433
|
/* public property */
|
|
3447
3434
|
get length() {
|
|
3448
|
-
return __classPrivateFieldGet(this,
|
|
3435
|
+
return __classPrivateFieldGet(this, _TaroHistory_stack, "f").length;
|
|
3449
3436
|
}
|
|
3450
3437
|
get state() {
|
|
3451
|
-
return __classPrivateFieldGet(this,
|
|
3438
|
+
return __classPrivateFieldGet(this, _TaroHistory_stack, "f")[__classPrivateFieldGet(this, _TaroHistory_cur, "f")].state;
|
|
3452
3439
|
}
|
|
3453
3440
|
/* public method */
|
|
3454
3441
|
go(delta) {
|
|
3455
3442
|
if (!isNumber(delta) || isNaN(delta))
|
|
3456
3443
|
return;
|
|
3457
|
-
let targetIdx = __classPrivateFieldGet(this,
|
|
3444
|
+
let targetIdx = __classPrivateFieldGet(this, _TaroHistory_cur, "f") + delta;
|
|
3458
3445
|
targetIdx = Math.min(Math.max(targetIdx, 0), this.length - 1);
|
|
3459
|
-
__classPrivateFieldSet(this,
|
|
3460
|
-
__classPrivateFieldGet(this,
|
|
3461
|
-
__classPrivateFieldGet(this,
|
|
3446
|
+
__classPrivateFieldSet(this, _TaroHistory_cur, targetIdx, "f");
|
|
3447
|
+
__classPrivateFieldGet(this, _TaroHistory_location, "f").trigger('__set_href_without_history__', __classPrivateFieldGet(this, _TaroHistory_stack, "f")[__classPrivateFieldGet(this, _TaroHistory_cur, "f")].url);
|
|
3448
|
+
__classPrivateFieldGet(this, _TaroHistory_window, "f").trigger('popstate', __classPrivateFieldGet(this, _TaroHistory_stack, "f")[__classPrivateFieldGet(this, _TaroHistory_cur, "f")]);
|
|
3462
3449
|
}
|
|
3463
3450
|
back() {
|
|
3464
3451
|
this.go(-1);
|
|
@@ -3469,40 +3456,41 @@ class History extends Events {
|
|
|
3469
3456
|
pushState(state, title, url) {
|
|
3470
3457
|
if (!url || !isString(url))
|
|
3471
3458
|
return;
|
|
3472
|
-
__classPrivateFieldSet(this,
|
|
3473
|
-
__classPrivateFieldGet(this,
|
|
3459
|
+
__classPrivateFieldSet(this, _TaroHistory_stack, __classPrivateFieldGet(this, _TaroHistory_stack, "f").slice(0, __classPrivateFieldGet(this, _TaroHistory_cur, "f") + 1), "f");
|
|
3460
|
+
__classPrivateFieldGet(this, _TaroHistory_stack, "f").push({
|
|
3474
3461
|
state,
|
|
3475
3462
|
title,
|
|
3476
3463
|
url
|
|
3477
3464
|
});
|
|
3478
|
-
__classPrivateFieldSet(this,
|
|
3479
|
-
__classPrivateFieldGet(this,
|
|
3465
|
+
__classPrivateFieldSet(this, _TaroHistory_cur, this.length - 1, "f");
|
|
3466
|
+
__classPrivateFieldGet(this, _TaroHistory_location, "f").trigger('__set_href_without_history__', url);
|
|
3480
3467
|
}
|
|
3481
3468
|
replaceState(state, title, url) {
|
|
3482
3469
|
if (!url || !isString(url))
|
|
3483
3470
|
return;
|
|
3484
|
-
__classPrivateFieldGet(this,
|
|
3471
|
+
__classPrivateFieldGet(this, _TaroHistory_stack, "f")[__classPrivateFieldGet(this, _TaroHistory_cur, "f")] = {
|
|
3485
3472
|
state,
|
|
3486
3473
|
title,
|
|
3487
3474
|
url
|
|
3488
3475
|
};
|
|
3489
|
-
__classPrivateFieldGet(this,
|
|
3476
|
+
__classPrivateFieldGet(this, _TaroHistory_location, "f").trigger('__set_href_without_history__', url);
|
|
3490
3477
|
}
|
|
3491
3478
|
// For debug
|
|
3492
3479
|
get cache() {
|
|
3493
3480
|
return cache$1;
|
|
3494
3481
|
}
|
|
3495
3482
|
}
|
|
3496
|
-
|
|
3497
|
-
__classPrivateFieldSet(this,
|
|
3483
|
+
_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 = '') {
|
|
3484
|
+
__classPrivateFieldSet(this, _TaroHistory_stack, [
|
|
3498
3485
|
{
|
|
3499
3486
|
state: null,
|
|
3500
3487
|
title: '',
|
|
3501
|
-
url: href || __classPrivateFieldGet(this,
|
|
3488
|
+
url: href || __classPrivateFieldGet(this, _TaroHistory_location, "f").href
|
|
3502
3489
|
}
|
|
3503
3490
|
], "f");
|
|
3504
|
-
__classPrivateFieldSet(this,
|
|
3491
|
+
__classPrivateFieldSet(this, _TaroHistory_cur, 0, "f");
|
|
3505
3492
|
};
|
|
3493
|
+
const History = process.env.TARO_PLATFORM === 'web' ? env.window.History : TaroHistory;
|
|
3506
3494
|
|
|
3507
3495
|
const Current = {
|
|
3508
3496
|
app: null,
|
|
@@ -3511,31 +3499,31 @@ const Current = {
|
|
|
3511
3499
|
};
|
|
3512
3500
|
const getCurrentInstance = () => Current;
|
|
3513
3501
|
|
|
3514
|
-
var
|
|
3502
|
+
var _TaroLocation_instances, _TaroLocation_url, _TaroLocation_noCheckUrl, _TaroLocation_window, _TaroLocation_reset, _TaroLocation_getPreValue, _TaroLocation_rollBack, _TaroLocation_recordHistory, _TaroLocation_checkUrlChange;
|
|
3515
3503
|
const INIT_URL = 'https://taro.com';
|
|
3516
3504
|
const cache = new RuntimeCache('location');
|
|
3517
|
-
class
|
|
3505
|
+
class TaroLocation extends Events {
|
|
3518
3506
|
constructor(options) {
|
|
3519
3507
|
super();
|
|
3520
|
-
|
|
3508
|
+
_TaroLocation_instances.add(this);
|
|
3521
3509
|
/* private property */
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
__classPrivateFieldSet(this,
|
|
3526
|
-
__classPrivateFieldGet(this,
|
|
3510
|
+
_TaroLocation_url.set(this, new URL(INIT_URL));
|
|
3511
|
+
_TaroLocation_noCheckUrl.set(this, false);
|
|
3512
|
+
_TaroLocation_window.set(this, void 0);
|
|
3513
|
+
__classPrivateFieldSet(this, _TaroLocation_window, options.window, "f");
|
|
3514
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_reset).call(this);
|
|
3527
3515
|
this.on('__set_href_without_history__', (href) => {
|
|
3528
|
-
__classPrivateFieldSet(this,
|
|
3529
|
-
const lastHash = __classPrivateFieldGet(this,
|
|
3530
|
-
__classPrivateFieldGet(this,
|
|
3531
|
-
if (lastHash !== __classPrivateFieldGet(this,
|
|
3532
|
-
__classPrivateFieldGet(this,
|
|
3516
|
+
__classPrivateFieldSet(this, _TaroLocation_noCheckUrl, true, "f");
|
|
3517
|
+
const lastHash = __classPrivateFieldGet(this, _TaroLocation_url, "f").hash;
|
|
3518
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").href = generateFullUrl(href);
|
|
3519
|
+
if (lastHash !== __classPrivateFieldGet(this, _TaroLocation_url, "f").hash) {
|
|
3520
|
+
__classPrivateFieldGet(this, _TaroLocation_window, "f").trigger('hashchange');
|
|
3533
3521
|
}
|
|
3534
|
-
__classPrivateFieldSet(this,
|
|
3522
|
+
__classPrivateFieldSet(this, _TaroLocation_noCheckUrl, false, "f");
|
|
3535
3523
|
}, null);
|
|
3536
3524
|
// 切换上下文行为
|
|
3537
3525
|
this.on(CONTEXT_ACTIONS.INIT, () => {
|
|
3538
|
-
__classPrivateFieldGet(this,
|
|
3526
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_reset).call(this);
|
|
3539
3527
|
}, null);
|
|
3540
3528
|
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3541
3529
|
cache.set(pageId, {
|
|
@@ -3546,9 +3534,9 @@ class Location extends Events {
|
|
|
3546
3534
|
// 数据恢复时,不需要执行跳转
|
|
3547
3535
|
if (cache.has(pageId)) {
|
|
3548
3536
|
const ctx = cache.get(pageId);
|
|
3549
|
-
__classPrivateFieldSet(this,
|
|
3550
|
-
__classPrivateFieldGet(this,
|
|
3551
|
-
__classPrivateFieldSet(this,
|
|
3537
|
+
__classPrivateFieldSet(this, _TaroLocation_noCheckUrl, true, "f");
|
|
3538
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").href = ctx.lastHref;
|
|
3539
|
+
__classPrivateFieldSet(this, _TaroLocation_noCheckUrl, false, "f");
|
|
3552
3540
|
}
|
|
3553
3541
|
}, null);
|
|
3554
3542
|
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
@@ -3557,81 +3545,81 @@ class Location extends Events {
|
|
|
3557
3545
|
}
|
|
3558
3546
|
/* public property */
|
|
3559
3547
|
get protocol() {
|
|
3560
|
-
return __classPrivateFieldGet(this,
|
|
3548
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").protocol;
|
|
3561
3549
|
}
|
|
3562
3550
|
set protocol(val) {
|
|
3563
3551
|
const REG = /^(http|https):$/i;
|
|
3564
3552
|
if (!val || !isString(val) || !REG.test(val.trim()))
|
|
3565
3553
|
return;
|
|
3566
3554
|
val = val.trim();
|
|
3567
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3568
|
-
__classPrivateFieldGet(this,
|
|
3569
|
-
if (__classPrivateFieldGet(this,
|
|
3570
|
-
__classPrivateFieldGet(this,
|
|
3555
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3556
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").protocol = val;
|
|
3557
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3558
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3571
3559
|
}
|
|
3572
3560
|
get host() {
|
|
3573
|
-
return __classPrivateFieldGet(this,
|
|
3561
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").host;
|
|
3574
3562
|
}
|
|
3575
3563
|
set host(val) {
|
|
3576
3564
|
if (!val || !isString(val))
|
|
3577
3565
|
return;
|
|
3578
3566
|
val = val.trim();
|
|
3579
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3580
|
-
__classPrivateFieldGet(this,
|
|
3581
|
-
if (__classPrivateFieldGet(this,
|
|
3582
|
-
__classPrivateFieldGet(this,
|
|
3567
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3568
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").host = val;
|
|
3569
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3570
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3583
3571
|
}
|
|
3584
3572
|
get hostname() {
|
|
3585
|
-
return __classPrivateFieldGet(this,
|
|
3573
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").hostname;
|
|
3586
3574
|
}
|
|
3587
3575
|
set hostname(val) {
|
|
3588
3576
|
if (!val || !isString(val))
|
|
3589
3577
|
return;
|
|
3590
3578
|
val = val.trim();
|
|
3591
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3592
|
-
__classPrivateFieldGet(this,
|
|
3593
|
-
if (__classPrivateFieldGet(this,
|
|
3594
|
-
__classPrivateFieldGet(this,
|
|
3579
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3580
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").hostname = val;
|
|
3581
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3582
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3595
3583
|
}
|
|
3596
3584
|
get port() {
|
|
3597
|
-
return __classPrivateFieldGet(this,
|
|
3585
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").port;
|
|
3598
3586
|
}
|
|
3599
3587
|
set port(val) {
|
|
3600
3588
|
const xVal = Number((val = val.trim()));
|
|
3601
3589
|
if (!isNumber(xVal) || xVal <= 0)
|
|
3602
3590
|
return;
|
|
3603
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3604
|
-
__classPrivateFieldGet(this,
|
|
3605
|
-
if (__classPrivateFieldGet(this,
|
|
3606
|
-
__classPrivateFieldGet(this,
|
|
3591
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3592
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").port = val;
|
|
3593
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3594
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3607
3595
|
}
|
|
3608
3596
|
get pathname() {
|
|
3609
|
-
return __classPrivateFieldGet(this,
|
|
3597
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").pathname;
|
|
3610
3598
|
}
|
|
3611
3599
|
set pathname(val) {
|
|
3612
3600
|
if (!val || !isString(val))
|
|
3613
3601
|
return;
|
|
3614
3602
|
val = val.trim();
|
|
3615
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3616
|
-
__classPrivateFieldGet(this,
|
|
3617
|
-
if (__classPrivateFieldGet(this,
|
|
3618
|
-
__classPrivateFieldGet(this,
|
|
3603
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3604
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").pathname = val;
|
|
3605
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3606
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3619
3607
|
}
|
|
3620
3608
|
get search() {
|
|
3621
|
-
return __classPrivateFieldGet(this,
|
|
3609
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").search;
|
|
3622
3610
|
}
|
|
3623
3611
|
set search(val) {
|
|
3624
3612
|
if (!val || !isString(val))
|
|
3625
3613
|
return;
|
|
3626
3614
|
val = val.trim();
|
|
3627
3615
|
val = val.startsWith('?') ? val : `?${val}`;
|
|
3628
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3629
|
-
__classPrivateFieldGet(this,
|
|
3630
|
-
if (__classPrivateFieldGet(this,
|
|
3631
|
-
__classPrivateFieldGet(this,
|
|
3616
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3617
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").search = val;
|
|
3618
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3619
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3632
3620
|
}
|
|
3633
3621
|
get hash() {
|
|
3634
|
-
return __classPrivateFieldGet(this,
|
|
3622
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").hash;
|
|
3635
3623
|
}
|
|
3636
3624
|
// 小程序的navigateTo存在截断hash字符串的问题
|
|
3637
3625
|
set hash(val) {
|
|
@@ -3639,34 +3627,34 @@ class Location extends Events {
|
|
|
3639
3627
|
return;
|
|
3640
3628
|
val = val.trim();
|
|
3641
3629
|
val = val.startsWith('#') ? val : `#${val}`;
|
|
3642
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3643
|
-
__classPrivateFieldGet(this,
|
|
3644
|
-
if (__classPrivateFieldGet(this,
|
|
3645
|
-
__classPrivateFieldGet(this,
|
|
3630
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3631
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").hash = val;
|
|
3632
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3633
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3646
3634
|
}
|
|
3647
3635
|
get href() {
|
|
3648
|
-
return __classPrivateFieldGet(this,
|
|
3636
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").href;
|
|
3649
3637
|
}
|
|
3650
3638
|
set href(val) {
|
|
3651
3639
|
const REG = /^(http:|https:)?\/\/.+/;
|
|
3652
3640
|
if (!val || !isString(val) || !REG.test((val = val.trim())))
|
|
3653
3641
|
return;
|
|
3654
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3655
|
-
__classPrivateFieldGet(this,
|
|
3656
|
-
if (__classPrivateFieldGet(this,
|
|
3657
|
-
__classPrivateFieldGet(this,
|
|
3642
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3643
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").href = val;
|
|
3644
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3645
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3658
3646
|
}
|
|
3659
3647
|
get origin() {
|
|
3660
|
-
return __classPrivateFieldGet(this,
|
|
3648
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f").origin;
|
|
3661
3649
|
}
|
|
3662
3650
|
set origin(val) {
|
|
3663
3651
|
const REG = /^(http:|https:)?\/\/.+/;
|
|
3664
3652
|
if (!val || !isString(val) || !REG.test((val = val.trim())))
|
|
3665
3653
|
return;
|
|
3666
|
-
const preValue = __classPrivateFieldGet(this,
|
|
3667
|
-
__classPrivateFieldGet(this,
|
|
3668
|
-
if (__classPrivateFieldGet(this,
|
|
3669
|
-
__classPrivateFieldGet(this,
|
|
3654
|
+
const preValue = __classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_getPreValue).call(this);
|
|
3655
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").origin = val;
|
|
3656
|
+
if (__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_checkUrlChange).call(this, preValue))
|
|
3657
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_recordHistory).call(this);
|
|
3670
3658
|
}
|
|
3671
3659
|
/* public method */
|
|
3672
3660
|
assign() {
|
|
@@ -3686,7 +3674,7 @@ class Location extends Events {
|
|
|
3686
3674
|
return cache;
|
|
3687
3675
|
}
|
|
3688
3676
|
}
|
|
3689
|
-
|
|
3677
|
+
_TaroLocation_url = new WeakMap(), _TaroLocation_noCheckUrl = new WeakMap(), _TaroLocation_window = new WeakMap(), _TaroLocation_instances = new WeakSet(), _TaroLocation_reset = function _TaroLocation_reset() {
|
|
3690
3678
|
const Current = getCurrentInstance();
|
|
3691
3679
|
const router = Current.router;
|
|
3692
3680
|
if (router) {
|
|
@@ -3696,23 +3684,23 @@ _Location_url = new WeakMap(), _Location_noCheckUrl = new WeakMap(), _Location_w
|
|
|
3696
3684
|
});
|
|
3697
3685
|
const searchStr = searchArr.length > 0 ? '?' + searchArr.join('&') : '';
|
|
3698
3686
|
const url = `${INIT_URL}${path.startsWith('/') ? path : '/' + path}${searchStr}`;
|
|
3699
|
-
__classPrivateFieldSet(this,
|
|
3687
|
+
__classPrivateFieldSet(this, _TaroLocation_url, new URL(url), "f");
|
|
3700
3688
|
this.trigger('__reset_history__', this.href);
|
|
3701
3689
|
}
|
|
3702
|
-
},
|
|
3703
|
-
return __classPrivateFieldGet(this,
|
|
3704
|
-
},
|
|
3705
|
-
__classPrivateFieldGet(this,
|
|
3706
|
-
},
|
|
3690
|
+
}, _TaroLocation_getPreValue = function _TaroLocation_getPreValue() {
|
|
3691
|
+
return __classPrivateFieldGet(this, _TaroLocation_url, "f")._toRaw();
|
|
3692
|
+
}, _TaroLocation_rollBack = function _TaroLocation_rollBack(href) {
|
|
3693
|
+
__classPrivateFieldGet(this, _TaroLocation_url, "f").href = href;
|
|
3694
|
+
}, _TaroLocation_recordHistory = function _TaroLocation_recordHistory() {
|
|
3707
3695
|
this.trigger('__record_history__', this.href);
|
|
3708
|
-
},
|
|
3709
|
-
if (__classPrivateFieldGet(this,
|
|
3696
|
+
}, _TaroLocation_checkUrlChange = function _TaroLocation_checkUrlChange(preValue) {
|
|
3697
|
+
if (__classPrivateFieldGet(this, _TaroLocation_noCheckUrl, "f")) {
|
|
3710
3698
|
return false;
|
|
3711
3699
|
}
|
|
3712
|
-
const { protocol, hostname, port, pathname, search, hash } = __classPrivateFieldGet(this,
|
|
3700
|
+
const { protocol, hostname, port, pathname, search, hash } = __classPrivateFieldGet(this, _TaroLocation_url, "f")._toRaw();
|
|
3713
3701
|
// 跨域三要素不允许修改
|
|
3714
3702
|
if (protocol !== preValue.protocol || hostname !== preValue.hostname || port !== preValue.port) {
|
|
3715
|
-
__classPrivateFieldGet(this,
|
|
3703
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_rollBack).call(this, preValue.href);
|
|
3716
3704
|
return false;
|
|
3717
3705
|
}
|
|
3718
3706
|
// pathname
|
|
@@ -3725,12 +3713,13 @@ _Location_url = new WeakMap(), _Location_noCheckUrl = new WeakMap(), _Location_w
|
|
|
3725
3713
|
}
|
|
3726
3714
|
// hashchange
|
|
3727
3715
|
if (hash !== preValue.hash) {
|
|
3728
|
-
__classPrivateFieldGet(this,
|
|
3716
|
+
__classPrivateFieldGet(this, _TaroLocation_window, "f").trigger('hashchange');
|
|
3729
3717
|
return true;
|
|
3730
3718
|
}
|
|
3731
|
-
__classPrivateFieldGet(this,
|
|
3719
|
+
__classPrivateFieldGet(this, _TaroLocation_instances, "m", _TaroLocation_rollBack).call(this, preValue.href);
|
|
3732
3720
|
return false;
|
|
3733
3721
|
};
|
|
3722
|
+
const Location = process.env.TARO_PLATFORM === 'web' ? env.window.Location : TaroLocation;
|
|
3734
3723
|
function generateFullUrl(val = '') {
|
|
3735
3724
|
const origin = INIT_URL;
|
|
3736
3725
|
if (/^[/?#]/.test(val)) {
|
|
@@ -3743,7 +3732,7 @@ const machine = 'Macintosh';
|
|
|
3743
3732
|
const arch = 'Intel Mac OS X 10_14_5';
|
|
3744
3733
|
const engine = 'AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36';
|
|
3745
3734
|
const msg = '(' + machine + '; ' + arch + ') ' + engine;
|
|
3746
|
-
const nav =
|
|
3735
|
+
const nav = process.env.TARO_PLATFORM === 'web' ? env.window.navigator : {
|
|
3747
3736
|
appCodeName: 'Mozilla',
|
|
3748
3737
|
appName: 'Netscape',
|
|
3749
3738
|
appVersion: '5.0 ' + msg,
|
|
@@ -3790,88 +3779,83 @@ const _caf = typeof cancelAnimationFrame !== 'undefined' && cancelAnimationFrame
|
|
|
3790
3779
|
clearTimeout(seed);
|
|
3791
3780
|
};
|
|
3792
3781
|
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
3816
|
-
console.warn(`[Taro warn] window.${String(property)} 在赋值到 window 时报错`);
|
|
3817
|
-
}
|
|
3782
|
+
class TaroWindow extends Events {
|
|
3783
|
+
constructor() {
|
|
3784
|
+
super();
|
|
3785
|
+
this.navigator = nav;
|
|
3786
|
+
this.requestAnimationFrame = _raf;
|
|
3787
|
+
this.cancelAnimationFrame = _caf;
|
|
3788
|
+
this.getComputedStyle = getComputedStyle;
|
|
3789
|
+
const globalProperties = [
|
|
3790
|
+
...Object.getOwnPropertyNames(global || {}),
|
|
3791
|
+
...Object.getOwnPropertySymbols(global || {})
|
|
3792
|
+
];
|
|
3793
|
+
globalProperties.forEach(property => {
|
|
3794
|
+
if (property === 'atob' || property === 'document')
|
|
3795
|
+
return;
|
|
3796
|
+
if (!Object.prototype.hasOwnProperty.call(this, property)) {
|
|
3797
|
+
// 防止小程序环境下,window 上的某些 get 属性在赋值时报错
|
|
3798
|
+
try {
|
|
3799
|
+
this[property] = global[property];
|
|
3800
|
+
}
|
|
3801
|
+
catch (e) {
|
|
3802
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3803
|
+
console.warn(`[Taro warn] window.${String(property)} 在赋值到 window 时报错`);
|
|
3818
3804
|
}
|
|
3819
3805
|
}
|
|
3820
|
-
}
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
}
|
|
3827
|
-
initEvent()
|
|
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
|
-
|
|
3868
|
-
|
|
3806
|
+
}
|
|
3807
|
+
});
|
|
3808
|
+
this.Date || (this.Date = Date);
|
|
3809
|
+
// 应用启动时,提供给需要读取历史信息的库使用
|
|
3810
|
+
this.location = new Location({ window: this });
|
|
3811
|
+
// @ts-ignore
|
|
3812
|
+
this.history = new History(this.location, { window: this });
|
|
3813
|
+
this.initEvent();
|
|
3814
|
+
}
|
|
3815
|
+
initEvent() {
|
|
3816
|
+
const _location = this.location;
|
|
3817
|
+
const _history = this.history;
|
|
3818
|
+
this.on(CONTEXT_ACTIONS.INIT, (pageId) => {
|
|
3819
|
+
// 页面onload,为该页面建立新的上下文信息
|
|
3820
|
+
_location.trigger(CONTEXT_ACTIONS.INIT, pageId);
|
|
3821
|
+
}, null);
|
|
3822
|
+
this.on(CONTEXT_ACTIONS.RECOVER, (pageId) => {
|
|
3823
|
+
// 页面onshow,恢复当前页面的上下文信息
|
|
3824
|
+
_location.trigger(CONTEXT_ACTIONS.RECOVER, pageId);
|
|
3825
|
+
_history.trigger(CONTEXT_ACTIONS.RECOVER, pageId);
|
|
3826
|
+
}, null);
|
|
3827
|
+
this.on(CONTEXT_ACTIONS.RESTORE, (pageId) => {
|
|
3828
|
+
// 页面onhide,缓存当前页面的上下文信息
|
|
3829
|
+
_location.trigger(CONTEXT_ACTIONS.RESTORE, pageId);
|
|
3830
|
+
_history.trigger(CONTEXT_ACTIONS.RESTORE, pageId);
|
|
3831
|
+
}, null);
|
|
3832
|
+
this.on(CONTEXT_ACTIONS.DESTORY, (pageId) => {
|
|
3833
|
+
// 页面onunload,清除当前页面的上下文信息
|
|
3834
|
+
_location.trigger(CONTEXT_ACTIONS.DESTORY, pageId);
|
|
3835
|
+
_history.trigger(CONTEXT_ACTIONS.DESTORY, pageId);
|
|
3836
|
+
}, null);
|
|
3837
|
+
}
|
|
3838
|
+
get document() {
|
|
3839
|
+
return env.document;
|
|
3840
|
+
}
|
|
3841
|
+
addEventListener(event, callback) {
|
|
3842
|
+
if (!isString(event))
|
|
3843
|
+
return;
|
|
3844
|
+
this.on(event, callback, null);
|
|
3845
|
+
}
|
|
3846
|
+
removeEventListener(event, callback) {
|
|
3847
|
+
if (!isString(event))
|
|
3848
|
+
return;
|
|
3849
|
+
this.off(event, callback, null);
|
|
3850
|
+
}
|
|
3851
|
+
setTimeout(...args) {
|
|
3852
|
+
return setTimeout(...args);
|
|
3853
|
+
}
|
|
3854
|
+
clearTimeout(...args) {
|
|
3855
|
+
return clearTimeout(...args);
|
|
3869
3856
|
}
|
|
3870
|
-
window$1 = env.window = new Window();
|
|
3871
|
-
}
|
|
3872
|
-
else {
|
|
3873
|
-
window$1 = env.window;
|
|
3874
3857
|
}
|
|
3858
|
+
const window$1 = process.env.TARO_PLATFORM === 'web' ? env.window : (env.window = new TaroWindow());
|
|
3875
3859
|
const location = window$1.location;
|
|
3876
3860
|
const history = window$1.history;
|
|
3877
3861
|
|
|
@@ -3879,10 +3863,29 @@ const history = window$1.history;
|
|
|
3879
3863
|
class SVGElement extends TaroElement {
|
|
3880
3864
|
}
|
|
3881
3865
|
|
|
3866
|
+
// export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
|
|
3867
|
+
// export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
|
|
3868
|
+
const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
|
|
3869
|
+
const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
|
|
3870
|
+
const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
|
|
3871
|
+
const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
|
|
3872
|
+
const stripSuffix = (path = '', suffix = '') => path.includes(suffix) ? path.substring(0, path.length - suffix.length) : path;
|
|
3873
|
+
const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
|
|
3874
|
+
var _a;
|
|
3875
|
+
const routePath = addLeadingSlash(stripBasename(path, basename));
|
|
3876
|
+
const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
|
|
3877
|
+
return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
|
|
3878
|
+
};
|
|
3879
|
+
const getCurrentPage = (routerMode = 'hash', basename = '/') => {
|
|
3880
|
+
const pagePath = routerMode === 'hash'
|
|
3881
|
+
? location.hash.slice(1).split('?')[0]
|
|
3882
|
+
: location.pathname;
|
|
3883
|
+
return addLeadingSlash(stripBasename(pagePath, basename));
|
|
3884
|
+
};
|
|
3885
|
+
|
|
3882
3886
|
/* eslint-disable dot-notation */
|
|
3883
3887
|
const instances = new Map();
|
|
3884
3888
|
const pageId = incrementId();
|
|
3885
|
-
const isWeb = isWebPlatform();
|
|
3886
3889
|
function injectPageInstance(inst, id) {
|
|
3887
3890
|
hooks.call('mergePageInstance', instances.get(id), inst);
|
|
3888
3891
|
instances.set(id, inst);
|
|
@@ -3893,12 +3896,6 @@ function getPageInstance(id) {
|
|
|
3893
3896
|
function removePageInstance(id) {
|
|
3894
3897
|
instances.delete(id);
|
|
3895
3898
|
}
|
|
3896
|
-
function addLeadingSlash(path) {
|
|
3897
|
-
if (path == null) {
|
|
3898
|
-
return '';
|
|
3899
|
-
}
|
|
3900
|
-
return path.charAt(0) === '/' ? path : '/' + path;
|
|
3901
|
-
}
|
|
3902
3899
|
function safeExecute(path, lifecycle, ...args) {
|
|
3903
3900
|
const instance = instances.get(path);
|
|
3904
3901
|
if (instance == null) {
|
|
@@ -3925,7 +3922,7 @@ function stringify(obj) {
|
|
|
3925
3922
|
}
|
|
3926
3923
|
function getPath(id, options) {
|
|
3927
3924
|
const idx = id.indexOf('?');
|
|
3928
|
-
if (
|
|
3925
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
3929
3926
|
return `${idx > -1 ? id.substring(0, idx) : id}${stringify((options === null || options === void 0 ? void 0 : options.stamp) ? { stamp: options.stamp } : {})}`;
|
|
3930
3927
|
}
|
|
3931
3928
|
else {
|
|
@@ -3949,7 +3946,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3949
3946
|
let unmounting = false;
|
|
3950
3947
|
let prepareMountList = [];
|
|
3951
3948
|
function setCurrentRouter(page) {
|
|
3952
|
-
const router =
|
|
3949
|
+
const router = process.env.TARO_PLATFORM === 'web' ? page.$taroPath : page.route || page.__route__ || page.$taroPath;
|
|
3953
3950
|
Current.router = {
|
|
3954
3951
|
params: page.$taroParams,
|
|
3955
3952
|
path: addLeadingSlash(router),
|
|
@@ -3973,7 +3970,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3973
3970
|
// this.$taroPath 是页面唯一标识
|
|
3974
3971
|
const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() });
|
|
3975
3972
|
const $taroPath = this.$taroPath = getPath(id, uniqueOptions);
|
|
3976
|
-
if (
|
|
3973
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
3977
3974
|
config.path = $taroPath;
|
|
3978
3975
|
}
|
|
3979
3976
|
// this.$taroParams 作为暴露给开发者的页面参数对象,可以被随意修改
|
|
@@ -3982,7 +3979,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3982
3979
|
}
|
|
3983
3980
|
setCurrentRouter(this);
|
|
3984
3981
|
// 初始化当前页面的上下文信息
|
|
3985
|
-
if (
|
|
3982
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
3986
3983
|
window$1.trigger(CONTEXT_ACTIONS.INIT, $taroPath);
|
|
3987
3984
|
}
|
|
3988
3985
|
const mount = () => {
|
|
@@ -3991,7 +3988,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3991
3988
|
ensure(pageElement !== null, '没有找到页面实例。');
|
|
3992
3989
|
safeExecute($taroPath, ON_LOAD, this.$taroParams);
|
|
3993
3990
|
loadResolver();
|
|
3994
|
-
if (
|
|
3991
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
3995
3992
|
pageElement.ctx = this;
|
|
3996
3993
|
pageElement.performUpdate(true, cb);
|
|
3997
3994
|
}
|
|
@@ -4010,7 +4007,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4010
4007
|
[ONUNLOAD]() {
|
|
4011
4008
|
const $taroPath = this.$taroPath;
|
|
4012
4009
|
// 销毁当前页面的上下文信息
|
|
4013
|
-
if (
|
|
4010
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
4014
4011
|
window$1.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath);
|
|
4015
4012
|
}
|
|
4016
4013
|
// 触发onUnload生命周期
|
|
@@ -4044,7 +4041,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4044
4041
|
Current.page = this;
|
|
4045
4042
|
setCurrentRouter(this);
|
|
4046
4043
|
// 恢复上下文信息
|
|
4047
|
-
if (
|
|
4044
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
4048
4045
|
window$1.trigger(CONTEXT_ACTIONS.RECOVER, this.$taroPath);
|
|
4049
4046
|
}
|
|
4050
4047
|
// 触发生命周期
|
|
@@ -4055,7 +4052,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4055
4052
|
},
|
|
4056
4053
|
[ONHIDE]() {
|
|
4057
4054
|
// 缓存当前页面上下文信息
|
|
4058
|
-
if (
|
|
4055
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
4059
4056
|
window$1.trigger(CONTEXT_ACTIONS.RESTORE, this.$taroPath);
|
|
4060
4057
|
}
|
|
4061
4058
|
// 设置 Current 的 page 和 router
|
|
@@ -4128,7 +4125,7 @@ function createComponentConfig(component, componentName, data) {
|
|
|
4128
4125
|
ensure(componentElement !== null, '没有找到组件实例。');
|
|
4129
4126
|
this.$taroInstances = instances.get(path);
|
|
4130
4127
|
safeExecute(path, ON_LOAD);
|
|
4131
|
-
if (
|
|
4128
|
+
if (process.env.TARO_PLATFORM !== 'web') {
|
|
4132
4129
|
componentElement.ctx = this;
|
|
4133
4130
|
componentElement.performUpdate(true);
|
|
4134
4131
|
}
|
|
@@ -4226,7 +4223,7 @@ const nextTick = (cb, ctx) => {
|
|
|
4226
4223
|
var _a, _b, _c;
|
|
4227
4224
|
const pageElement = env.document.getElementById(path);
|
|
4228
4225
|
if (pageElement === null || pageElement === void 0 ? void 0 : pageElement.pendingUpdate) {
|
|
4229
|
-
if (
|
|
4226
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
4230
4227
|
// eslint-disable-next-line dot-notation
|
|
4231
4228
|
(_c = (_b = (_a = pageElement.firstChild) === null || _a === void 0 ? void 0 : _a['componentOnReady']) === null || _b === void 0 ? void 0 : _b.call(_a).then(() => {
|
|
4232
4229
|
timerFunc();
|
|
@@ -4246,5 +4243,775 @@ const nextTick = (cb, ctx) => {
|
|
|
4246
4243
|
next();
|
|
4247
4244
|
};
|
|
4248
4245
|
|
|
4249
|
-
|
|
4246
|
+
function handleArrayFindPolyfill() {
|
|
4247
|
+
if (!isFunction(Array.prototype.find)) {
|
|
4248
|
+
Object.defineProperty(Array.prototype, 'find', {
|
|
4249
|
+
value(predicate) {
|
|
4250
|
+
if (this == null) {
|
|
4251
|
+
throw new TypeError('"this" is null or not defined');
|
|
4252
|
+
}
|
|
4253
|
+
const o = Object(this);
|
|
4254
|
+
const len = o.length >>> 0;
|
|
4255
|
+
if (!isFunction(predicate)) {
|
|
4256
|
+
throw new TypeError('predicate must be a function');
|
|
4257
|
+
}
|
|
4258
|
+
const thisArg = arguments[1];
|
|
4259
|
+
let k = 0;
|
|
4260
|
+
while (k < len) {
|
|
4261
|
+
const kValue = o[k];
|
|
4262
|
+
if (predicate.call(thisArg, kValue, k, o)) {
|
|
4263
|
+
return kValue;
|
|
4264
|
+
}
|
|
4265
|
+
k++;
|
|
4266
|
+
}
|
|
4267
|
+
return undefined;
|
|
4268
|
+
}
|
|
4269
|
+
});
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
function handleArrayIncludesPolyfill() {
|
|
4273
|
+
if (!isFunction(Array.prototype.includes)) {
|
|
4274
|
+
Object.defineProperty(Array.prototype, 'includes', {
|
|
4275
|
+
value(searchElement, fromIndex) {
|
|
4276
|
+
if (this == null) {
|
|
4277
|
+
throw new TypeError('"this" is null or not defined');
|
|
4278
|
+
}
|
|
4279
|
+
const o = Object(this);
|
|
4280
|
+
const len = o.length >>> 0;
|
|
4281
|
+
if (len === 0) {
|
|
4282
|
+
return false;
|
|
4283
|
+
}
|
|
4284
|
+
const n = fromIndex | 0;
|
|
4285
|
+
let k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
|
|
4286
|
+
while (k < len) {
|
|
4287
|
+
if (o[k] === searchElement) {
|
|
4288
|
+
return true;
|
|
4289
|
+
}
|
|
4290
|
+
k++;
|
|
4291
|
+
}
|
|
4292
|
+
return false;
|
|
4293
|
+
}
|
|
4294
|
+
});
|
|
4295
|
+
}
|
|
4296
|
+
}
|
|
4297
|
+
|
|
4298
|
+
/* eslint-disable eqeqeq */
|
|
4299
|
+
function handleIntersectionObserverPolyfill() {
|
|
4300
|
+
// Exit early if all IntersectionObserver and IntersectionObserverEntry
|
|
4301
|
+
// features are natively supported.
|
|
4302
|
+
if ('IntersectionObserver' in window &&
|
|
4303
|
+
'IntersectionObserverEntry' in window &&
|
|
4304
|
+
'intersectionRatio' in window.IntersectionObserverEntry.prototype) {
|
|
4305
|
+
if (!('isIntersecting' in window.IntersectionObserverEntry.prototype)) {
|
|
4306
|
+
// Minimal polyfill for Edge 15's lack of `isIntersecting`
|
|
4307
|
+
// See: https://github.com/w3c/IntersectionObserver/issues/211
|
|
4308
|
+
Object.defineProperty(window.IntersectionObserverEntry.prototype, 'isIntersecting', {
|
|
4309
|
+
get: function () {
|
|
4310
|
+
return this.intersectionRatio > 0;
|
|
4311
|
+
}
|
|
4312
|
+
});
|
|
4313
|
+
}
|
|
4314
|
+
}
|
|
4315
|
+
else {
|
|
4316
|
+
handleIntersectionObserverObjectPolyfill();
|
|
4317
|
+
}
|
|
4318
|
+
}
|
|
4319
|
+
function handleIntersectionObserverObjectPolyfill() {
|
|
4320
|
+
const document = window.document;
|
|
4321
|
+
/**
|
|
4322
|
+
* Creates the global IntersectionObserverEntry constructor.
|
|
4323
|
+
* https://w3c.github.io/IntersectionObserver/#intersection-observer-entry
|
|
4324
|
+
* @param {Object} entry A dictionary of instance properties.
|
|
4325
|
+
* @constructor
|
|
4326
|
+
*/
|
|
4327
|
+
function IntersectionObserverEntry(entry) {
|
|
4328
|
+
this.time = entry.time;
|
|
4329
|
+
this.target = entry.target;
|
|
4330
|
+
this.rootBounds = entry.rootBounds;
|
|
4331
|
+
this.boundingClientRect = entry.boundingClientRect;
|
|
4332
|
+
this.intersectionRect = entry.intersectionRect || getEmptyRect();
|
|
4333
|
+
this.isIntersecting = !!entry.intersectionRect;
|
|
4334
|
+
// Calculates the intersection ratio.
|
|
4335
|
+
const targetRect = this.boundingClientRect;
|
|
4336
|
+
const targetArea = targetRect.width * targetRect.height;
|
|
4337
|
+
const intersectionRect = this.intersectionRect;
|
|
4338
|
+
const intersectionArea = intersectionRect.width * intersectionRect.height;
|
|
4339
|
+
// Sets intersection ratio.
|
|
4340
|
+
if (targetArea) {
|
|
4341
|
+
// Round the intersection ratio to avoid floating point math issues:
|
|
4342
|
+
// https://github.com/w3c/IntersectionObserver/issues/324
|
|
4343
|
+
this.intersectionRatio = Number((intersectionArea / targetArea).toFixed(4));
|
|
4344
|
+
}
|
|
4345
|
+
else {
|
|
4346
|
+
// If area is zero and is intersecting, sets to 1, otherwise to 0
|
|
4347
|
+
this.intersectionRatio = this.isIntersecting ? 1 : 0;
|
|
4348
|
+
}
|
|
4349
|
+
}
|
|
4350
|
+
/**
|
|
4351
|
+
* Creates the global IntersectionObserver constructor.
|
|
4352
|
+
* https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
|
|
4353
|
+
* @param {Function} callback The function to be invoked after intersection
|
|
4354
|
+
* changes have queued. The function is not invoked if the queue has
|
|
4355
|
+
* been emptied by calling the `takeRecords` method.
|
|
4356
|
+
* @param {Object=} opt_options Optional configuration options.
|
|
4357
|
+
* @constructor
|
|
4358
|
+
*/
|
|
4359
|
+
function IntersectionObserver(callback, options = {}) {
|
|
4360
|
+
if (!isFunction(callback)) {
|
|
4361
|
+
throw new Error('callback must be a function');
|
|
4362
|
+
}
|
|
4363
|
+
if (options.root && options.root.nodeType != 1) {
|
|
4364
|
+
throw new Error('root must be an Element');
|
|
4365
|
+
}
|
|
4366
|
+
// Binds and throttles `this._checkForIntersections`.
|
|
4367
|
+
this._checkForIntersections = throttle(this._checkForIntersections.bind(this), this.THROTTLE_TIMEOUT);
|
|
4368
|
+
// Private properties.
|
|
4369
|
+
this._callback = callback;
|
|
4370
|
+
this._observationTargets = [];
|
|
4371
|
+
this._queuedEntries = [];
|
|
4372
|
+
this._rootMarginValues = this._parseRootMargin(options.rootMargin);
|
|
4373
|
+
// Public properties.
|
|
4374
|
+
this.thresholds = this._initThresholds(options.threshold);
|
|
4375
|
+
this.root = options.root || null;
|
|
4376
|
+
this.rootMargin = this._rootMarginValues.map(function (margin) {
|
|
4377
|
+
return margin.value + margin.unit;
|
|
4378
|
+
}).join(' ');
|
|
4379
|
+
}
|
|
4380
|
+
/**
|
|
4381
|
+
* The minimum interval within which the document will be checked for
|
|
4382
|
+
* intersection changes.
|
|
4383
|
+
*/
|
|
4384
|
+
IntersectionObserver.prototype.THROTTLE_TIMEOUT = 100;
|
|
4385
|
+
/**
|
|
4386
|
+
* The frequency in which the polyfill polls for intersection changes.
|
|
4387
|
+
* this can be updated on a per instance basis and must be set prior to
|
|
4388
|
+
* calling `observe` on the first target.
|
|
4389
|
+
*/
|
|
4390
|
+
IntersectionObserver.prototype.POLL_INTERVAL = null;
|
|
4391
|
+
/**
|
|
4392
|
+
* Use a mutation observer on the root element
|
|
4393
|
+
* to detect intersection changes.
|
|
4394
|
+
*/
|
|
4395
|
+
IntersectionObserver.prototype.USE_MUTATION_OBSERVER = true;
|
|
4396
|
+
/**
|
|
4397
|
+
* Starts observing a target element for intersection changes based on
|
|
4398
|
+
* the thresholds values.
|
|
4399
|
+
* @param {Element} target The DOM element to observe.
|
|
4400
|
+
*/
|
|
4401
|
+
IntersectionObserver.prototype.observe = function (target) {
|
|
4402
|
+
const isTargetAlreadyObserved = this._observationTargets.some(function (item) {
|
|
4403
|
+
return item.element == target;
|
|
4404
|
+
});
|
|
4405
|
+
if (isTargetAlreadyObserved)
|
|
4406
|
+
return;
|
|
4407
|
+
if (!(target && target.nodeType == 1)) {
|
|
4408
|
+
throw new Error('target must be an Element');
|
|
4409
|
+
}
|
|
4410
|
+
this._registerInstance();
|
|
4411
|
+
this._observationTargets.push({ element: target, entry: null });
|
|
4412
|
+
this._monitorIntersections();
|
|
4413
|
+
this._checkForIntersections();
|
|
4414
|
+
};
|
|
4415
|
+
/**
|
|
4416
|
+
* Stops observing a target element for intersection changes.
|
|
4417
|
+
* @param {Element} target The DOM element to observe.
|
|
4418
|
+
*/
|
|
4419
|
+
IntersectionObserver.prototype.unobserve = function (target) {
|
|
4420
|
+
this._observationTargets =
|
|
4421
|
+
this._observationTargets.filter(function (item) {
|
|
4422
|
+
return item.element != target;
|
|
4423
|
+
});
|
|
4424
|
+
if (!this._observationTargets.length) {
|
|
4425
|
+
this._unmonitorIntersections();
|
|
4426
|
+
this._unregisterInstance();
|
|
4427
|
+
}
|
|
4428
|
+
};
|
|
4429
|
+
/**
|
|
4430
|
+
* Stops observing all target elements for intersection changes.
|
|
4431
|
+
*/
|
|
4432
|
+
IntersectionObserver.prototype.disconnect = function () {
|
|
4433
|
+
this._observationTargets = [];
|
|
4434
|
+
this._unmonitorIntersections();
|
|
4435
|
+
this._unregisterInstance();
|
|
4436
|
+
};
|
|
4437
|
+
/**
|
|
4438
|
+
* Returns any queue entries that have not yet been reported to the
|
|
4439
|
+
* callback and clears the queue. This can be used in conjunction with the
|
|
4440
|
+
* callback to obtain the absolute most up-to-date intersection information.
|
|
4441
|
+
* @return {Array} The currently queued entries.
|
|
4442
|
+
*/
|
|
4443
|
+
IntersectionObserver.prototype.takeRecords = function () {
|
|
4444
|
+
const records = this._queuedEntries.slice();
|
|
4445
|
+
this._queuedEntries = [];
|
|
4446
|
+
return records;
|
|
4447
|
+
};
|
|
4448
|
+
/**
|
|
4449
|
+
* Accepts the threshold value from the user configuration object and
|
|
4450
|
+
* returns a sorted array of unique threshold values. If a value is not
|
|
4451
|
+
* between 0 and 1 and error is thrown.
|
|
4452
|
+
* @private
|
|
4453
|
+
* @param {Array|number=} opt_threshold An optional threshold value or
|
|
4454
|
+
* a list of threshold values, defaulting to [0].
|
|
4455
|
+
* @return {Array} A sorted list of unique and valid threshold values.
|
|
4456
|
+
*/
|
|
4457
|
+
IntersectionObserver.prototype._initThresholds = function (opt_threshold) {
|
|
4458
|
+
let threshold = opt_threshold || [0];
|
|
4459
|
+
if (!Array.isArray(threshold))
|
|
4460
|
+
threshold = [threshold];
|
|
4461
|
+
return threshold.sort().filter(function (t, i, a) {
|
|
4462
|
+
if (!isNumber(t) || isNaN(t) || t < 0 || t > 1) {
|
|
4463
|
+
throw new Error('threshold must be a number between 0 and 1 inclusively');
|
|
4464
|
+
}
|
|
4465
|
+
return t !== a[i - 1];
|
|
4466
|
+
});
|
|
4467
|
+
};
|
|
4468
|
+
/**
|
|
4469
|
+
* Accepts the rootMargin value from the user configuration object
|
|
4470
|
+
* and returns an array of the four margin values as an object containing
|
|
4471
|
+
* the value and unit properties. If any of the values are not properly
|
|
4472
|
+
* formatted or use a unit other than px or %, and error is thrown.
|
|
4473
|
+
* @private
|
|
4474
|
+
* @param {string=} opt_rootMargin An optional rootMargin value,
|
|
4475
|
+
* defaulting to '0px'.
|
|
4476
|
+
* @return {Array<Object>} An array of margin objects with the keys
|
|
4477
|
+
* value and unit.
|
|
4478
|
+
*/
|
|
4479
|
+
IntersectionObserver.prototype._parseRootMargin = function (opt_rootMargin) {
|
|
4480
|
+
const marginString = opt_rootMargin || '0px';
|
|
4481
|
+
const margins = marginString.split(/\s+/).map(function (margin) {
|
|
4482
|
+
const parts = /^(-?\d*\.?\d+)(px|%)$/.exec(margin);
|
|
4483
|
+
if (!parts) {
|
|
4484
|
+
throw new Error('rootMargin must be specified in pixels or percent');
|
|
4485
|
+
}
|
|
4486
|
+
return { value: parseFloat(parts[1]), unit: parts[2] };
|
|
4487
|
+
});
|
|
4488
|
+
// Handles shorthand.
|
|
4489
|
+
margins[1] = margins[1] || margins[0];
|
|
4490
|
+
margins[2] = margins[2] || margins[0];
|
|
4491
|
+
margins[3] = margins[3] || margins[1];
|
|
4492
|
+
return margins;
|
|
4493
|
+
};
|
|
4494
|
+
/**
|
|
4495
|
+
* Starts polling for intersection changes if the polling is not already
|
|
4496
|
+
* happening, and if the page's visibility state is visible.
|
|
4497
|
+
* @private
|
|
4498
|
+
*/
|
|
4499
|
+
IntersectionObserver.prototype._monitorIntersections = function () {
|
|
4500
|
+
if (!this._monitoringIntersections) {
|
|
4501
|
+
this._monitoringIntersections = true;
|
|
4502
|
+
// If a poll interval is set, use polling instead of listening to
|
|
4503
|
+
// resize and scroll events or DOM mutations.
|
|
4504
|
+
if (this.POLL_INTERVAL) {
|
|
4505
|
+
this._monitoringInterval = setInterval(this._checkForIntersections, this.POLL_INTERVAL);
|
|
4506
|
+
}
|
|
4507
|
+
else {
|
|
4508
|
+
addEvent(window, 'resize', this._checkForIntersections, true);
|
|
4509
|
+
addEvent(document, 'scroll', this._checkForIntersections, true);
|
|
4510
|
+
if (this.USE_MUTATION_OBSERVER && 'MutationObserver' in window) {
|
|
4511
|
+
this._domObserver = new MutationObserver(this._checkForIntersections);
|
|
4512
|
+
this._domObserver.observe(document, {
|
|
4513
|
+
attributes: true,
|
|
4514
|
+
childList: true,
|
|
4515
|
+
characterData: true,
|
|
4516
|
+
subtree: true
|
|
4517
|
+
});
|
|
4518
|
+
}
|
|
4519
|
+
}
|
|
4520
|
+
}
|
|
4521
|
+
};
|
|
4522
|
+
/**
|
|
4523
|
+
* Stops polling for intersection changes.
|
|
4524
|
+
* @private
|
|
4525
|
+
*/
|
|
4526
|
+
IntersectionObserver.prototype._unmonitorIntersections = function () {
|
|
4527
|
+
if (this._monitoringIntersections) {
|
|
4528
|
+
this._monitoringIntersections = false;
|
|
4529
|
+
clearInterval(this._monitoringInterval);
|
|
4530
|
+
this._monitoringInterval = null;
|
|
4531
|
+
removeEvent(window, 'resize', this._checkForIntersections, true);
|
|
4532
|
+
removeEvent(document, 'scroll', this._checkForIntersections, true);
|
|
4533
|
+
if (this._domObserver) {
|
|
4534
|
+
this._domObserver.disconnect();
|
|
4535
|
+
this._domObserver = null;
|
|
4536
|
+
}
|
|
4537
|
+
}
|
|
4538
|
+
};
|
|
4539
|
+
/**
|
|
4540
|
+
* Scans each observation target for intersection changes and adds them
|
|
4541
|
+
* to the internal entries queue. If new entries are found, it
|
|
4542
|
+
* schedules the callback to be invoked.
|
|
4543
|
+
* @private
|
|
4544
|
+
*/
|
|
4545
|
+
IntersectionObserver.prototype._checkForIntersections = function () {
|
|
4546
|
+
const rootIsInDom = this._rootIsInDom();
|
|
4547
|
+
const rootRect = rootIsInDom ? this._getRootRect() : getEmptyRect();
|
|
4548
|
+
this._observationTargets.forEach(function (item) {
|
|
4549
|
+
const target = item.element;
|
|
4550
|
+
const targetRect = getBoundingClientRect(target);
|
|
4551
|
+
const rootContainsTarget = this._rootContainsTarget(target);
|
|
4552
|
+
const oldEntry = item.entry;
|
|
4553
|
+
const intersectionRect = rootIsInDom && rootContainsTarget &&
|
|
4554
|
+
this._computeTargetAndRootIntersection(target, rootRect);
|
|
4555
|
+
const newEntry = item.entry = new IntersectionObserverEntry({
|
|
4556
|
+
time: now(),
|
|
4557
|
+
target: target,
|
|
4558
|
+
boundingClientRect: targetRect,
|
|
4559
|
+
rootBounds: rootRect,
|
|
4560
|
+
intersectionRect: intersectionRect,
|
|
4561
|
+
intersectionRatio: -1,
|
|
4562
|
+
isIntersecting: false,
|
|
4563
|
+
});
|
|
4564
|
+
if (!oldEntry) {
|
|
4565
|
+
this._queuedEntries.push(newEntry);
|
|
4566
|
+
}
|
|
4567
|
+
else if (rootIsInDom && rootContainsTarget) {
|
|
4568
|
+
// If the new entry intersection ratio has crossed any of the
|
|
4569
|
+
// thresholds, add a new entry.
|
|
4570
|
+
if (this._hasCrossedThreshold(oldEntry, newEntry)) {
|
|
4571
|
+
this._queuedEntries.push(newEntry);
|
|
4572
|
+
}
|
|
4573
|
+
}
|
|
4574
|
+
else {
|
|
4575
|
+
// If the root is not in the DOM or target is not contained within
|
|
4576
|
+
// root but the previous entry for this target had an intersection,
|
|
4577
|
+
// add a new record indicating removal.
|
|
4578
|
+
if (oldEntry && oldEntry.isIntersecting) {
|
|
4579
|
+
this._queuedEntries.push(newEntry);
|
|
4580
|
+
}
|
|
4581
|
+
}
|
|
4582
|
+
}, this);
|
|
4583
|
+
if (this._queuedEntries.length) {
|
|
4584
|
+
this._callback(this.takeRecords(), this);
|
|
4585
|
+
}
|
|
4586
|
+
};
|
|
4587
|
+
/**
|
|
4588
|
+
* Accepts a target and root rect computes the intersection between then
|
|
4589
|
+
* following the algorithm in the spec.
|
|
4590
|
+
* TODO(philipwalton): at this time clip-path is not considered.
|
|
4591
|
+
* https://w3c.github.io/IntersectionObserver/#calculate-intersection-rect-algo
|
|
4592
|
+
* @param {Element} target The target DOM element
|
|
4593
|
+
* @param {Object} rootRect The bounding rect of the root after being
|
|
4594
|
+
* expanded by the rootMargin value.
|
|
4595
|
+
* @return {?Object} The final intersection rect object or undefined if no
|
|
4596
|
+
* intersection is found.
|
|
4597
|
+
* @private
|
|
4598
|
+
*/
|
|
4599
|
+
IntersectionObserver.prototype._computeTargetAndRootIntersection = function (target, rootRect) {
|
|
4600
|
+
// If the element isn't displayed, an intersection can't happen.
|
|
4601
|
+
if (window.getComputedStyle(target).display === 'none')
|
|
4602
|
+
return;
|
|
4603
|
+
const targetRect = getBoundingClientRect(target);
|
|
4604
|
+
let intersectionRect = targetRect;
|
|
4605
|
+
let parent = getParentNode(target);
|
|
4606
|
+
let atRoot = false;
|
|
4607
|
+
while (!atRoot) {
|
|
4608
|
+
let parentRect = null;
|
|
4609
|
+
const parentComputedStyle = parent.nodeType == 1 ?
|
|
4610
|
+
window.getComputedStyle(parent) : {};
|
|
4611
|
+
// If the parent isn't displayed, an intersection can't happen.
|
|
4612
|
+
if (parentComputedStyle.display === 'none')
|
|
4613
|
+
return;
|
|
4614
|
+
if (parent == this.root || parent == document) {
|
|
4615
|
+
atRoot = true;
|
|
4616
|
+
parentRect = rootRect;
|
|
4617
|
+
}
|
|
4618
|
+
else {
|
|
4619
|
+
// If the element has a non-visible overflow, and it's not the <body>
|
|
4620
|
+
// or <html> element, update the intersection rect.
|
|
4621
|
+
// Note: <body> and <html> cannot be clipped to a rect that's not also
|
|
4622
|
+
// the document rect, so no need to compute a new intersection.
|
|
4623
|
+
if (parent != document.body &&
|
|
4624
|
+
parent != document.documentElement &&
|
|
4625
|
+
parentComputedStyle.overflow != 'visible') {
|
|
4626
|
+
parentRect = getBoundingClientRect(parent);
|
|
4627
|
+
}
|
|
4628
|
+
}
|
|
4629
|
+
// If either of the above conditionals set a new parentRect,
|
|
4630
|
+
// calculate new intersection data.
|
|
4631
|
+
if (parentRect) {
|
|
4632
|
+
intersectionRect = computeRectIntersection(parentRect, intersectionRect);
|
|
4633
|
+
if (!intersectionRect)
|
|
4634
|
+
break;
|
|
4635
|
+
}
|
|
4636
|
+
parent = getParentNode(parent);
|
|
4637
|
+
}
|
|
4638
|
+
return intersectionRect;
|
|
4639
|
+
};
|
|
4640
|
+
/**
|
|
4641
|
+
* Returns the root rect after being expanded by the rootMargin value.
|
|
4642
|
+
* @return {Object} The expanded root rect.
|
|
4643
|
+
* @private
|
|
4644
|
+
*/
|
|
4645
|
+
IntersectionObserver.prototype._getRootRect = function () {
|
|
4646
|
+
let rootRect;
|
|
4647
|
+
if (this.root) {
|
|
4648
|
+
rootRect = getBoundingClientRect(this.root);
|
|
4649
|
+
}
|
|
4650
|
+
else {
|
|
4651
|
+
// Use <html>/<body> instead of window since scroll bars affect size.
|
|
4652
|
+
const html = document.documentElement;
|
|
4653
|
+
const body = document.body;
|
|
4654
|
+
rootRect = {
|
|
4655
|
+
top: 0,
|
|
4656
|
+
left: 0,
|
|
4657
|
+
right: html.clientWidth || body.clientWidth,
|
|
4658
|
+
width: html.clientWidth || body.clientWidth,
|
|
4659
|
+
bottom: html.clientHeight || body.clientHeight,
|
|
4660
|
+
height: html.clientHeight || body.clientHeight
|
|
4661
|
+
};
|
|
4662
|
+
}
|
|
4663
|
+
return this._expandRectByRootMargin(rootRect);
|
|
4664
|
+
};
|
|
4665
|
+
/**
|
|
4666
|
+
* Accepts a rect and expands it by the rootMargin value.
|
|
4667
|
+
* @param {Object} rect The rect object to expand.
|
|
4668
|
+
* @return {Object} The expanded rect.
|
|
4669
|
+
* @private
|
|
4670
|
+
*/
|
|
4671
|
+
IntersectionObserver.prototype._expandRectByRootMargin = function (rect) {
|
|
4672
|
+
const margins = this._rootMarginValues.map(function (margin, i) {
|
|
4673
|
+
return margin.unit === 'px' ? margin.value :
|
|
4674
|
+
margin.value * (i % 2 ? rect.width : rect.height) / 100;
|
|
4675
|
+
});
|
|
4676
|
+
const newRect = {
|
|
4677
|
+
top: rect.top - margins[0],
|
|
4678
|
+
right: rect.right + margins[1],
|
|
4679
|
+
bottom: rect.bottom + margins[2],
|
|
4680
|
+
left: rect.left - margins[3]
|
|
4681
|
+
};
|
|
4682
|
+
newRect.width = newRect.right - newRect.left;
|
|
4683
|
+
newRect.height = newRect.bottom - newRect.top;
|
|
4684
|
+
return newRect;
|
|
4685
|
+
};
|
|
4686
|
+
/**
|
|
4687
|
+
* Accepts an old and new entry and returns true if at least one of the
|
|
4688
|
+
* threshold values has been crossed.
|
|
4689
|
+
* @param {?IntersectionObserverEntry} oldEntry The previous entry for a
|
|
4690
|
+
* particular target element or null if no previous entry exists.
|
|
4691
|
+
* @param {IntersectionObserverEntry} newEntry The current entry for a
|
|
4692
|
+
* particular target element.
|
|
4693
|
+
* @return {boolean} Returns true if a any threshold has been crossed.
|
|
4694
|
+
* @private
|
|
4695
|
+
*/
|
|
4696
|
+
IntersectionObserver.prototype._hasCrossedThreshold =
|
|
4697
|
+
function (oldEntry, newEntry) {
|
|
4698
|
+
// To make comparing easier, an entry that has a ratio of 0
|
|
4699
|
+
// but does not actually intersect is given a value of -1
|
|
4700
|
+
const oldRatio = oldEntry && oldEntry.isIntersecting ? oldEntry.intersectionRatio || 0 : -1;
|
|
4701
|
+
const newRatio = newEntry.isIntersecting ? newEntry.intersectionRatio || 0 : -1;
|
|
4702
|
+
// Ignore unchanged ratios
|
|
4703
|
+
if (oldRatio === newRatio)
|
|
4704
|
+
return;
|
|
4705
|
+
for (let i = 0; i < this.thresholds.length; i++) {
|
|
4706
|
+
const threshold = this.thresholds[i];
|
|
4707
|
+
// Return true if an entry matches a threshold or if the new ratio
|
|
4708
|
+
// and the old ratio are on the opposite sides of a threshold.
|
|
4709
|
+
if (threshold == oldRatio || threshold == newRatio ||
|
|
4710
|
+
threshold < oldRatio !== threshold < newRatio) {
|
|
4711
|
+
return true;
|
|
4712
|
+
}
|
|
4713
|
+
}
|
|
4714
|
+
};
|
|
4715
|
+
/**
|
|
4716
|
+
* Returns whether or not the root element is an element and is in the DOM.
|
|
4717
|
+
* @return {boolean} True if the root element is an element and is in the DOM.
|
|
4718
|
+
* @private
|
|
4719
|
+
*/
|
|
4720
|
+
IntersectionObserver.prototype._rootIsInDom = function () {
|
|
4721
|
+
return !this.root || containsDeep(document, this.root);
|
|
4722
|
+
};
|
|
4723
|
+
/**
|
|
4724
|
+
* Returns whether or not the target element is a child of root.
|
|
4725
|
+
* @param {Element} target The target element to check.
|
|
4726
|
+
* @return {boolean} True if the target element is a child of root.
|
|
4727
|
+
* @private
|
|
4728
|
+
*/
|
|
4729
|
+
IntersectionObserver.prototype._rootContainsTarget = function (target) {
|
|
4730
|
+
return containsDeep(this.root || document, target);
|
|
4731
|
+
};
|
|
4732
|
+
/**
|
|
4733
|
+
* Adds the instance to the global IntersectionObserver registry if it isn't
|
|
4734
|
+
* already present.
|
|
4735
|
+
* @private
|
|
4736
|
+
*/
|
|
4737
|
+
IntersectionObserver.prototype._registerInstance = function () {
|
|
4738
|
+
};
|
|
4739
|
+
/**
|
|
4740
|
+
* Removes the instance from the global IntersectionObserver registry.
|
|
4741
|
+
* @private
|
|
4742
|
+
*/
|
|
4743
|
+
IntersectionObserver.prototype._unregisterInstance = function () {
|
|
4744
|
+
};
|
|
4745
|
+
/**
|
|
4746
|
+
* Returns the result of the performance.now() method or null in browsers
|
|
4747
|
+
* that don't support the API.
|
|
4748
|
+
* @return {number} The elapsed time since the page was requested.
|
|
4749
|
+
*/
|
|
4750
|
+
function now() {
|
|
4751
|
+
return window.performance && performance.now && performance.now();
|
|
4752
|
+
}
|
|
4753
|
+
/**
|
|
4754
|
+
* Adds an event handler to a DOM node ensuring cross-browser compatibility.
|
|
4755
|
+
* @param {Node} node The DOM node to add the event handler to.
|
|
4756
|
+
* @param {string} event The event name.
|
|
4757
|
+
* @param {Function} fn The event handler to add.
|
|
4758
|
+
* @param {boolean} opt_useCapture Optionally adds the even to the capture
|
|
4759
|
+
* phase. Note: this only works in modern browsers.
|
|
4760
|
+
*/
|
|
4761
|
+
function addEvent(node, event, fn, opt_useCapture) {
|
|
4762
|
+
if (isFunction(node.addEventListener)) {
|
|
4763
|
+
node.addEventListener(event, fn, opt_useCapture || false);
|
|
4764
|
+
}
|
|
4765
|
+
else if (isFunction(node.attachEvent)) {
|
|
4766
|
+
node.attachEvent('on' + event, fn);
|
|
4767
|
+
}
|
|
4768
|
+
}
|
|
4769
|
+
/**
|
|
4770
|
+
* Removes a previously added event handler from a DOM node.
|
|
4771
|
+
* @param {Node} node The DOM node to remove the event handler from.
|
|
4772
|
+
* @param {string} event The event name.
|
|
4773
|
+
* @param {Function} fn The event handler to remove.
|
|
4774
|
+
* @param {boolean} opt_useCapture If the event handler was added with this
|
|
4775
|
+
* flag set to true, it should be set to true here in order to remove it.
|
|
4776
|
+
*/
|
|
4777
|
+
function removeEvent(node, event, fn, opt_useCapture) {
|
|
4778
|
+
if (isFunction(node.removeEventListener)) {
|
|
4779
|
+
node.removeEventListener(event, fn, opt_useCapture || false);
|
|
4780
|
+
}
|
|
4781
|
+
else if (isFunction(node.detatchEvent)) {
|
|
4782
|
+
node.detatchEvent('on' + event, fn);
|
|
4783
|
+
}
|
|
4784
|
+
}
|
|
4785
|
+
/**
|
|
4786
|
+
* Returns the intersection between two rect objects.
|
|
4787
|
+
* @param {Object} rect1 The first rect.
|
|
4788
|
+
* @param {Object} rect2 The second rect.
|
|
4789
|
+
* @return {?Object} The intersection rect or undefined if no intersection
|
|
4790
|
+
* is found.
|
|
4791
|
+
*/
|
|
4792
|
+
function computeRectIntersection(rect1, rect2) {
|
|
4793
|
+
const top = Math.max(rect1.top, rect2.top);
|
|
4794
|
+
const bottom = Math.min(rect1.bottom, rect2.bottom);
|
|
4795
|
+
const left = Math.max(rect1.left, rect2.left);
|
|
4796
|
+
const right = Math.min(rect1.right, rect2.right);
|
|
4797
|
+
const width = right - left;
|
|
4798
|
+
const height = bottom - top;
|
|
4799
|
+
return (width >= 0 && height >= 0) && {
|
|
4800
|
+
top: top,
|
|
4801
|
+
bottom: bottom,
|
|
4802
|
+
left: left,
|
|
4803
|
+
right: right,
|
|
4804
|
+
width: width,
|
|
4805
|
+
height: height
|
|
4806
|
+
};
|
|
4807
|
+
}
|
|
4808
|
+
/**
|
|
4809
|
+
* Shims the native getBoundingClientRect for compatibility with older IE.
|
|
4810
|
+
* @param {Element} el The element whose bounding rect to get.
|
|
4811
|
+
* @return {Object} The (possibly shimmed) rect of the element.
|
|
4812
|
+
*/
|
|
4813
|
+
function getBoundingClientRect(el) {
|
|
4814
|
+
let rect;
|
|
4815
|
+
try {
|
|
4816
|
+
rect = el.getBoundingClientRect();
|
|
4817
|
+
}
|
|
4818
|
+
catch (err) {
|
|
4819
|
+
// Ignore Windows 7 IE11 "Unspecified error"
|
|
4820
|
+
// https://github.com/w3c/IntersectionObserver/pull/205
|
|
4821
|
+
}
|
|
4822
|
+
if (!rect)
|
|
4823
|
+
return getEmptyRect();
|
|
4824
|
+
// Older IE
|
|
4825
|
+
if (!(rect.width && rect.height)) {
|
|
4826
|
+
rect = {
|
|
4827
|
+
top: rect.top,
|
|
4828
|
+
right: rect.right,
|
|
4829
|
+
bottom: rect.bottom,
|
|
4830
|
+
left: rect.left,
|
|
4831
|
+
width: rect.right - rect.left,
|
|
4832
|
+
height: rect.bottom - rect.top
|
|
4833
|
+
};
|
|
4834
|
+
}
|
|
4835
|
+
return rect;
|
|
4836
|
+
}
|
|
4837
|
+
/**
|
|
4838
|
+
* Returns an empty rect object. An empty rect is returned when an element
|
|
4839
|
+
* is not in the DOM.
|
|
4840
|
+
* @return {Object} The empty rect.
|
|
4841
|
+
*/
|
|
4842
|
+
function getEmptyRect() {
|
|
4843
|
+
return {
|
|
4844
|
+
top: 0,
|
|
4845
|
+
bottom: 0,
|
|
4846
|
+
left: 0,
|
|
4847
|
+
right: 0,
|
|
4848
|
+
width: 0,
|
|
4849
|
+
height: 0
|
|
4850
|
+
};
|
|
4851
|
+
}
|
|
4852
|
+
/**
|
|
4853
|
+
* Checks to see if a parent element contains a child element (including inside
|
|
4854
|
+
* shadow DOM).
|
|
4855
|
+
* @param {Node} parent The parent element.
|
|
4856
|
+
* @param {Node} child The child element.
|
|
4857
|
+
* @return {boolean} True if the parent node contains the child node.
|
|
4858
|
+
*/
|
|
4859
|
+
function containsDeep(parent, child) {
|
|
4860
|
+
let node = child;
|
|
4861
|
+
while (node) {
|
|
4862
|
+
if (node == parent)
|
|
4863
|
+
return true;
|
|
4864
|
+
node = getParentNode(node);
|
|
4865
|
+
}
|
|
4866
|
+
return false;
|
|
4867
|
+
}
|
|
4868
|
+
/**
|
|
4869
|
+
* Gets the parent node of an element or its host element if the parent node
|
|
4870
|
+
* is a shadow root.
|
|
4871
|
+
* @param {Node} node The node whose parent to get.
|
|
4872
|
+
* @return {Node|null} The parent node or null if no parent exists.
|
|
4873
|
+
*/
|
|
4874
|
+
function getParentNode(node) {
|
|
4875
|
+
const parent = node.parentNode;
|
|
4876
|
+
if (parent && parent.nodeType == 11 && parent.host) {
|
|
4877
|
+
// If the parent is a shadow root, return the host element.
|
|
4878
|
+
return parent.host;
|
|
4879
|
+
}
|
|
4880
|
+
if (parent && parent.assignedSlot) {
|
|
4881
|
+
// If the parent is distributed in a <slot>, return the parent of a slot.
|
|
4882
|
+
return parent.assignedSlot.parentNode;
|
|
4883
|
+
}
|
|
4884
|
+
return parent;
|
|
4885
|
+
}
|
|
4886
|
+
// Exposes the constructors globally.
|
|
4887
|
+
window.IntersectionObserver = IntersectionObserver;
|
|
4888
|
+
window.IntersectionObserverEntry = IntersectionObserverEntry;
|
|
4889
|
+
}
|
|
4890
|
+
|
|
4891
|
+
function handleObjectAssignPolyfill() {
|
|
4892
|
+
if (!isFunction(Object.assign)) {
|
|
4893
|
+
// Must be writable: true, enumerable: false, configurable: true
|
|
4894
|
+
Object.assign = function (target) {
|
|
4895
|
+
if (target == null) { // TypeError if undefined or null
|
|
4896
|
+
throw new TypeError('Cannot convert undefined or null to object');
|
|
4897
|
+
}
|
|
4898
|
+
const to = Object(target);
|
|
4899
|
+
for (let index = 1; index < arguments.length; index++) {
|
|
4900
|
+
const nextSource = arguments[index];
|
|
4901
|
+
if (nextSource != null) { // Skip over if undefined or null
|
|
4902
|
+
for (const nextKey in nextSource) {
|
|
4903
|
+
// Avoid bugs when hasOwnProperty is shadowed
|
|
4904
|
+
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
|
4905
|
+
to[nextKey] = nextSource[nextKey];
|
|
4906
|
+
}
|
|
4907
|
+
}
|
|
4908
|
+
}
|
|
4909
|
+
}
|
|
4910
|
+
return to;
|
|
4911
|
+
};
|
|
4912
|
+
}
|
|
4913
|
+
}
|
|
4914
|
+
function handleObjectEntriesPolyfill() {
|
|
4915
|
+
if (!isFunction(Object.entries)) {
|
|
4916
|
+
// Must be writable: true, enumerable: false, configurable: true
|
|
4917
|
+
Object.entries = function (obj) {
|
|
4918
|
+
if (obj == null) { // TypeError if undefined or null
|
|
4919
|
+
throw new TypeError('Cannot convert undefined or null to object');
|
|
4920
|
+
}
|
|
4921
|
+
const to = [];
|
|
4922
|
+
if (obj != null) { // Skip over if undefined or null
|
|
4923
|
+
for (const key in obj) {
|
|
4924
|
+
// Avoid bugs when hasOwnProperty is shadowed
|
|
4925
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
4926
|
+
to.push([key, obj[key]]);
|
|
4927
|
+
}
|
|
4928
|
+
}
|
|
4929
|
+
}
|
|
4930
|
+
return to;
|
|
4931
|
+
};
|
|
4932
|
+
}
|
|
4933
|
+
}
|
|
4934
|
+
function handleObjectDefinePropertyPolyfill() {
|
|
4935
|
+
if (!isFunction(Object.defineProperties)) {
|
|
4936
|
+
Object.defineProperties = function (obj, properties) {
|
|
4937
|
+
function convertToDescriptor(desc) {
|
|
4938
|
+
function hasProperty(obj, prop) {
|
|
4939
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
4940
|
+
}
|
|
4941
|
+
if (!isObject(desc)) {
|
|
4942
|
+
throw new TypeError('bad desc');
|
|
4943
|
+
}
|
|
4944
|
+
const d = {};
|
|
4945
|
+
if (hasProperty(desc, 'enumerable'))
|
|
4946
|
+
d.enumerable = !!desc.enumerable;
|
|
4947
|
+
if (hasProperty(desc, 'configurable')) {
|
|
4948
|
+
d.configurable = !!desc.configurable;
|
|
4949
|
+
}
|
|
4950
|
+
if (hasProperty(desc, 'value'))
|
|
4951
|
+
d.value = desc.value;
|
|
4952
|
+
if (hasProperty(desc, 'writable'))
|
|
4953
|
+
d.writable = !!desc.writable;
|
|
4954
|
+
if (hasProperty(desc, 'get')) {
|
|
4955
|
+
const g = desc.get;
|
|
4956
|
+
if (!isFunction(g) && !isUndefined(g)) {
|
|
4957
|
+
throw new TypeError('bad get');
|
|
4958
|
+
}
|
|
4959
|
+
d.get = g;
|
|
4960
|
+
}
|
|
4961
|
+
if (hasProperty(desc, 'set')) {
|
|
4962
|
+
const s = desc.set;
|
|
4963
|
+
if (!isFunction(s) && !isUndefined(s)) {
|
|
4964
|
+
throw new TypeError('bad set');
|
|
4965
|
+
}
|
|
4966
|
+
d.set = s;
|
|
4967
|
+
}
|
|
4968
|
+
if (('get' in d || 'set' in d) && ('value' in d || 'writable' in d)) {
|
|
4969
|
+
throw new TypeError('identity-confused descriptor');
|
|
4970
|
+
}
|
|
4971
|
+
return d;
|
|
4972
|
+
}
|
|
4973
|
+
if (!isObject(obj))
|
|
4974
|
+
throw new TypeError('bad obj');
|
|
4975
|
+
properties = Object(properties);
|
|
4976
|
+
const keys = Object.keys(properties);
|
|
4977
|
+
const descs = [];
|
|
4978
|
+
for (let i = 0; i < keys.length; i++) {
|
|
4979
|
+
descs.push([keys[i], convertToDescriptor(properties[keys[i]])]);
|
|
4980
|
+
}
|
|
4981
|
+
for (let i = 0; i < descs.length; i++) {
|
|
4982
|
+
Object.defineProperty(obj, descs[i][0], descs[i][1]);
|
|
4983
|
+
}
|
|
4984
|
+
return obj;
|
|
4985
|
+
};
|
|
4986
|
+
}
|
|
4987
|
+
}
|
|
4988
|
+
|
|
4989
|
+
function handlePolyfill() {
|
|
4990
|
+
if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Object' || process.env.SUPPORT_TARO_POLYFILL === 'Object.assign') {
|
|
4991
|
+
handleObjectAssignPolyfill();
|
|
4992
|
+
}
|
|
4993
|
+
if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Object' || process.env.SUPPORT_TARO_POLYFILL === 'Object.entries') {
|
|
4994
|
+
handleObjectEntriesPolyfill();
|
|
4995
|
+
}
|
|
4996
|
+
if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Object' || process.env.SUPPORT_TARO_POLYFILL === 'Object.defineProperty') {
|
|
4997
|
+
handleObjectDefinePropertyPolyfill();
|
|
4998
|
+
}
|
|
4999
|
+
if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Array' || process.env.SUPPORT_TARO_POLYFILL === 'Array.find') {
|
|
5000
|
+
handleArrayFindPolyfill();
|
|
5001
|
+
}
|
|
5002
|
+
if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'Array' || process.env.SUPPORT_TARO_POLYFILL === 'Array.includes') {
|
|
5003
|
+
handleArrayIncludesPolyfill();
|
|
5004
|
+
}
|
|
5005
|
+
// Exit early if we're not running in a browser.
|
|
5006
|
+
if (process.env.TARO_PLATFORM === 'web' && isObject(window)) {
|
|
5007
|
+
if (process.env.SUPPORT_TARO_POLYFILL === 'enabled' || process.env.SUPPORT_TARO_POLYFILL === 'IntersectionObserver') {
|
|
5008
|
+
handleIntersectionObserverPolyfill();
|
|
5009
|
+
}
|
|
5010
|
+
}
|
|
5011
|
+
}
|
|
5012
|
+
if (process.env.SUPPORT_TARO_POLYFILL !== 'disabled' && process.env.TARO_PLATFORM !== 'web') {
|
|
5013
|
+
handlePolyfill();
|
|
5014
|
+
}
|
|
5015
|
+
|
|
5016
|
+
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 };
|
|
4250
5017
|
//# sourceMappingURL=runtime.esm.js.map
|