@spcsn/taro-runtime 0.1.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -153
- package/README.md +16 -39
- package/dist/bom/{URL.js → URL2.js} +3 -4
- package/dist/bom/URL2.js.map +1 -0
- package/dist/bom/document.d.ts +0 -1
- package/dist/bom/document.js +1 -55
- package/dist/bom/document.js.map +1 -1
- package/dist/bom/get-computed-style.js +8 -0
- package/dist/bom/get-computed-style.js.map +1 -0
- package/dist/bom/history.js +1 -2
- package/dist/bom/history.js.map +1 -1
- package/dist/bom/location.js +2 -3
- package/dist/bom/location.js.map +1 -1
- package/dist/bom/navigator.js +1 -2
- package/dist/bom/navigator.js.map +1 -1
- package/dist/bom/raf.d.ts +2 -2
- package/dist/bom/raf.js +2 -2
- package/dist/bom/raf.js.map +1 -1
- package/dist/bom/url-search-params.d.ts +14 -0
- package/dist/bom/{URLSearchParams.js → url-search-params.js} +12 -15
- package/dist/bom/url-search-params.js.map +1 -0
- package/dist/bom/{URL.d.ts → url.d.ts} +1 -0
- package/dist/bom/url.js +196 -0
- package/dist/bom/url.js.map +1 -0
- package/dist/bom/window.d.ts +3 -3
- package/dist/bom/window.js +2 -2
- package/dist/bom/window.js.map +1 -1
- package/dist/current.d.ts +3 -0
- package/dist/current.js +10 -1
- package/dist/current.js.map +1 -1
- package/dist/dom/anchor-element.js +1 -1
- package/dist/dom/class-list.js +2 -1
- package/dist/dom/class-list.js.map +1 -1
- package/dist/dom/document.js.map +1 -1
- package/dist/dom/element.js +7 -7
- package/dist/dom/element.js.map +1 -1
- package/dist/dom/event.d.ts +1 -1
- package/dist/dom/event.js +3 -13
- package/dist/dom/event.js.map +1 -1
- package/dist/dom/form.js +1 -1
- package/dist/dom/form.js.map +1 -1
- package/dist/dom/node.d.ts +4 -3
- package/dist/dom/node.js +14 -7
- package/dist/dom/node.js.map +1 -1
- package/dist/dom/root.js +2 -2
- package/dist/dom/root.js.map +1 -1
- package/dist/dom/{style_properties.js → style-properties.js} +2 -2
- package/dist/dom/{style_properties.js.map → style-properties.js.map} +1 -1
- package/dist/dom/style.js +1 -1
- package/dist/dom/style.js.map +1 -1
- package/dist/dom/text.d.ts +1 -1
- package/dist/dom/text.js.map +1 -1
- package/dist/dom/tree.js.map +1 -1
- package/dist/dsl/common.js +26 -47
- package/dist/dsl/common.js.map +1 -1
- package/dist/env.js +2 -2
- package/dist/env.js.map +1 -1
- package/dist/hydrate.js +1 -1
- package/dist/hydrate.js.map +1 -1
- package/dist/index.cjs.d.ts +4 -4
- package/dist/index.cjs.js +331 -708
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -6
- package/dist/next-tick.js +1 -6
- package/dist/next-tick.js.map +1 -1
- package/dist/perf.js +1 -1
- package/dist/perf.js.map +1 -1
- package/dist/polyfill/index.js +1 -6
- package/dist/polyfill/index.js.map +1 -1
- package/dist/runtime.esm.d.ts +4 -4
- package/dist/runtime.esm.js +330 -708
- package/dist/runtime.esm.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +16 -10
- package/dist/bom/URL.js.map +0 -1
- package/dist/bom/URLSearchParams.d.ts +0 -1
- package/dist/bom/URLSearchParams.js.map +0 -1
- package/dist/bom/getComputedStyle.js +0 -9
- package/dist/bom/getComputedStyle.js.map +0 -1
- package/dist/polyfill/intersection-observer.js +0 -494
- package/dist/polyfill/intersection-observer.js.map +0 -1
- /package/dist/bom/{getComputedStyle.d.ts → get-computed-style.d.ts} +0 -0
- /package/dist/dom/{node_types.d.ts → node-types.d.ts} +0 -0
- /package/dist/dom/{style_properties.d.ts → style-properties.d.ts} +0 -0
package/dist/runtime.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EMPTY_OBJ, Events, Shortcuts, controlledComponent, ensure, getComponentsAlias as getComponentsAlias$1, hooks, hooks as hooks$1, internalComponents, isArray, isFunction, isNull, isNumber, isObject, isString, isUndefined, noop, toCamelCase, toDashed, warn } from "@spcsn/taro-shared";
|
|
2
2
|
//#region src/constants/index.ts
|
|
3
3
|
const PROPERTY_THRESHOLD = 2046;
|
|
4
4
|
const TARO_RUNTIME = "Taro runtime";
|
|
@@ -158,7 +158,7 @@ function recordMutation(record) {
|
|
|
158
158
|
}
|
|
159
159
|
//#endregion
|
|
160
160
|
//#region src/dom-external/mutation-observer/index.ts
|
|
161
|
-
var MutationObserver
|
|
161
|
+
var MutationObserver = class {
|
|
162
162
|
constructor(callback) {
|
|
163
163
|
if (ENABLE_MUTATION_OBSERVER) this.core = new MutationObserverImpl(callback);
|
|
164
164
|
else {
|
|
@@ -280,12 +280,12 @@ const eventCenter = hooks$1.call("getEventCenter", Events);
|
|
|
280
280
|
//#endregion
|
|
281
281
|
//#region src/env.ts
|
|
282
282
|
const env = {
|
|
283
|
-
window:
|
|
284
|
-
document:
|
|
283
|
+
window: EMPTY_OBJ,
|
|
284
|
+
document: EMPTY_OBJ
|
|
285
285
|
};
|
|
286
286
|
//#endregion
|
|
287
|
-
//#region src/bom/
|
|
288
|
-
const taroGetComputedStyleProvider =
|
|
287
|
+
//#region src/bom/get-computed-style.ts
|
|
288
|
+
const taroGetComputedStyleProvider = function(element) {
|
|
289
289
|
return element.style;
|
|
290
290
|
};
|
|
291
291
|
//#endregion
|
|
@@ -448,7 +448,7 @@ function _reset$1(href = "") {
|
|
|
448
448
|
}]);
|
|
449
449
|
_classPrivateFieldSet2(_cur, this, 0);
|
|
450
450
|
}
|
|
451
|
-
const History =
|
|
451
|
+
const History = TaroHistory;
|
|
452
452
|
//#endregion
|
|
453
453
|
//#region src/current.ts
|
|
454
454
|
const Current = {
|
|
@@ -456,10 +456,18 @@ const Current = {
|
|
|
456
456
|
router: null,
|
|
457
457
|
page: null
|
|
458
458
|
};
|
|
459
|
+
const appReadyCallbacks = [];
|
|
460
|
+
function setCurrentApp(app) {
|
|
461
|
+
Current.app = app;
|
|
462
|
+
while (appReadyCallbacks.length) appReadyCallbacks.shift()(app);
|
|
463
|
+
}
|
|
464
|
+
function whenAppReady(callback) {
|
|
465
|
+
if (Current.app) callback(Current.app);
|
|
466
|
+
else appReadyCallbacks.push(callback);
|
|
467
|
+
}
|
|
459
468
|
const getCurrentInstance = () => Current;
|
|
460
469
|
//#endregion
|
|
461
|
-
//#region src/bom/
|
|
462
|
-
var _dict;
|
|
470
|
+
//#region src/bom/url-search-params.ts
|
|
463
471
|
const findReg = /[!'()~]|%20|%00/g;
|
|
464
472
|
const plusReg = /\+/g;
|
|
465
473
|
const replaceCharMap = {
|
|
@@ -479,16 +487,14 @@ function appendTo(dict, name, value) {
|
|
|
479
487
|
if (name in dict) dict[name].push(res);
|
|
480
488
|
else dict[name] = [res];
|
|
481
489
|
}
|
|
482
|
-
function addEach(value, key) {
|
|
483
|
-
appendTo(this, key, value);
|
|
484
|
-
}
|
|
485
490
|
function decode(str) {
|
|
486
491
|
return decodeURIComponent(str.replace(plusReg, " "));
|
|
487
492
|
}
|
|
488
493
|
function encode(str) {
|
|
489
494
|
return encodeURIComponent(str).replace(findReg, replacer);
|
|
490
495
|
}
|
|
491
|
-
|
|
496
|
+
var _dict = /* @__PURE__ */ new WeakMap();
|
|
497
|
+
var URLSearchParams = class {
|
|
492
498
|
constructor(query) {
|
|
493
499
|
var _query;
|
|
494
500
|
_classPrivateFieldInitSpec(this, _dict, Object.create(null));
|
|
@@ -510,7 +516,7 @@ const URLSearchParams = process.env.TARO_PLATFORM === "web" ? env.window.URLSear
|
|
|
510
516
|
const value = query[i];
|
|
511
517
|
appendTo(dict, value[0], value[1]);
|
|
512
518
|
}
|
|
513
|
-
else if (query.forEach) query.forEach(
|
|
519
|
+
else if (query.forEach) query.forEach((value, key) => appendTo(dict, key, value));
|
|
514
520
|
else for (const key in query) appendTo(dict, key, query[key]);
|
|
515
521
|
}
|
|
516
522
|
append(name, value) {
|
|
@@ -538,11 +544,12 @@ const URLSearchParams = process.env.TARO_PLATFORM === "web" ? env.window.URLSear
|
|
|
538
544
|
}
|
|
539
545
|
forEach(callback, thisArg) {
|
|
540
546
|
const dict = _classPrivateFieldGet2(_dict, this);
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
547
|
+
const searchParams = this;
|
|
548
|
+
Object.getOwnPropertyNames(dict).forEach((name) => {
|
|
549
|
+
dict[name].forEach((value) => {
|
|
550
|
+
callback.call(thisArg, value, name, searchParams);
|
|
551
|
+
});
|
|
552
|
+
});
|
|
546
553
|
}
|
|
547
554
|
toJSON() {
|
|
548
555
|
return {};
|
|
@@ -556,16 +563,16 @@ const URLSearchParams = process.env.TARO_PLATFORM === "web" ? env.window.URLSear
|
|
|
556
563
|
}
|
|
557
564
|
return query.join("&");
|
|
558
565
|
}
|
|
559
|
-
}
|
|
566
|
+
};
|
|
560
567
|
//#endregion
|
|
561
|
-
//#region src/bom/
|
|
562
|
-
var _hash = /* @__PURE__ */ new WeakMap();
|
|
563
|
-
var _hostname = /* @__PURE__ */ new WeakMap();
|
|
564
|
-
var _pathname = /* @__PURE__ */ new WeakMap();
|
|
565
|
-
var _port = /* @__PURE__ */ new WeakMap();
|
|
566
|
-
var _protocol = /* @__PURE__ */ new WeakMap();
|
|
567
|
-
var _search = /* @__PURE__ */ new WeakMap();
|
|
568
|
-
var TaroURL = class {
|
|
568
|
+
//#region src/bom/url.ts
|
|
569
|
+
var _hash$1 = /* @__PURE__ */ new WeakMap();
|
|
570
|
+
var _hostname$1 = /* @__PURE__ */ new WeakMap();
|
|
571
|
+
var _pathname$1 = /* @__PURE__ */ new WeakMap();
|
|
572
|
+
var _port$1 = /* @__PURE__ */ new WeakMap();
|
|
573
|
+
var _protocol$1 = /* @__PURE__ */ new WeakMap();
|
|
574
|
+
var _search$1 = /* @__PURE__ */ new WeakMap();
|
|
575
|
+
var TaroURL$1 = class {
|
|
569
576
|
static createObjectURL() {
|
|
570
577
|
throw new Error("Oops, not support URL.createObjectURL() in miniprogram.");
|
|
571
578
|
}
|
|
@@ -573,26 +580,26 @@ var TaroURL = class {
|
|
|
573
580
|
throw new Error("Oops, not support URL.revokeObjectURL() in miniprogram.");
|
|
574
581
|
}
|
|
575
582
|
constructor(url, base) {
|
|
576
|
-
_classPrivateFieldInitSpec(this, _hash, "");
|
|
577
|
-
_classPrivateFieldInitSpec(this, _hostname, "");
|
|
578
|
-
_classPrivateFieldInitSpec(this, _pathname, "");
|
|
579
|
-
_classPrivateFieldInitSpec(this, _port, "");
|
|
580
|
-
_classPrivateFieldInitSpec(this, _protocol, "");
|
|
581
|
-
_classPrivateFieldInitSpec(this, _search, void 0);
|
|
583
|
+
_classPrivateFieldInitSpec(this, _hash$1, "");
|
|
584
|
+
_classPrivateFieldInitSpec(this, _hostname$1, "");
|
|
585
|
+
_classPrivateFieldInitSpec(this, _pathname$1, "");
|
|
586
|
+
_classPrivateFieldInitSpec(this, _port$1, "");
|
|
587
|
+
_classPrivateFieldInitSpec(this, _protocol$1, "");
|
|
588
|
+
_classPrivateFieldInitSpec(this, _search$1, void 0);
|
|
582
589
|
if (!isString(url)) url = String(url);
|
|
583
|
-
const { hash, hostname, pathname, port, protocol, search } = parseUrlBase(url, base);
|
|
584
|
-
_classPrivateFieldSet2(_hash, this, hash);
|
|
585
|
-
_classPrivateFieldSet2(_hostname, this, hostname);
|
|
586
|
-
_classPrivateFieldSet2(_pathname, this, pathname || "/");
|
|
587
|
-
_classPrivateFieldSet2(_port, this, port);
|
|
588
|
-
_classPrivateFieldSet2(_protocol, this, protocol);
|
|
589
|
-
_classPrivateFieldSet2(_search, this, new URLSearchParams(search));
|
|
590
|
+
const { hash, hostname, pathname, port, protocol, search } = parseUrlBase$1(url, base);
|
|
591
|
+
_classPrivateFieldSet2(_hash$1, this, hash);
|
|
592
|
+
_classPrivateFieldSet2(_hostname$1, this, hostname);
|
|
593
|
+
_classPrivateFieldSet2(_pathname$1, this, pathname || "/");
|
|
594
|
+
_classPrivateFieldSet2(_port$1, this, port);
|
|
595
|
+
_classPrivateFieldSet2(_protocol$1, this, protocol);
|
|
596
|
+
_classPrivateFieldSet2(_search$1, this, new URLSearchParams(search));
|
|
590
597
|
}
|
|
591
598
|
get protocol() {
|
|
592
|
-
return _classPrivateFieldGet2(_protocol, this);
|
|
599
|
+
return _classPrivateFieldGet2(_protocol$1, this);
|
|
593
600
|
}
|
|
594
601
|
set protocol(val) {
|
|
595
|
-
isString(val) && _classPrivateFieldSet2(_protocol, this, val.trim());
|
|
602
|
+
isString(val) && _classPrivateFieldSet2(_protocol$1, this, val.trim());
|
|
596
603
|
}
|
|
597
604
|
get host() {
|
|
598
605
|
return this.hostname + (this.port ? ":" + this.port : "");
|
|
@@ -600,25 +607,25 @@ var TaroURL = class {
|
|
|
600
607
|
set host(val) {
|
|
601
608
|
if (val && isString(val)) {
|
|
602
609
|
val = val.trim();
|
|
603
|
-
const { hostname, port } = parseUrl(`//${val}`);
|
|
610
|
+
const { hostname, port } = parseUrl$1(`//${val}`);
|
|
604
611
|
this.hostname = hostname;
|
|
605
612
|
this.port = port;
|
|
606
613
|
}
|
|
607
614
|
}
|
|
608
615
|
get hostname() {
|
|
609
|
-
return _classPrivateFieldGet2(_hostname, this);
|
|
616
|
+
return _classPrivateFieldGet2(_hostname$1, this);
|
|
610
617
|
}
|
|
611
618
|
set hostname(val) {
|
|
612
|
-
val && isString(val) && _classPrivateFieldSet2(_hostname, this, val.trim());
|
|
619
|
+
val && isString(val) && _classPrivateFieldSet2(_hostname$1, this, val.trim());
|
|
613
620
|
}
|
|
614
621
|
get port() {
|
|
615
|
-
return _classPrivateFieldGet2(_port, this);
|
|
622
|
+
return _classPrivateFieldGet2(_port$1, this);
|
|
616
623
|
}
|
|
617
624
|
set port(val) {
|
|
618
|
-
isString(val) && _classPrivateFieldSet2(_port, this, val.trim());
|
|
625
|
+
isString(val) && _classPrivateFieldSet2(_port$1, this, val.trim());
|
|
619
626
|
}
|
|
620
627
|
get pathname() {
|
|
621
|
-
return _classPrivateFieldGet2(_pathname, this);
|
|
628
|
+
return _classPrivateFieldGet2(_pathname$1, this);
|
|
622
629
|
}
|
|
623
630
|
set pathname(val) {
|
|
624
631
|
if (isString(val)) {
|
|
@@ -626,28 +633,28 @@ var TaroURL = class {
|
|
|
626
633
|
const HEAD_REG = /^(\/|\.\/|\.\.\/)/;
|
|
627
634
|
let temp = val;
|
|
628
635
|
while (HEAD_REG.test(temp)) temp = temp.replace(HEAD_REG, "");
|
|
629
|
-
if (temp) _classPrivateFieldSet2(_pathname, this, "/" + temp);
|
|
630
|
-
else _classPrivateFieldSet2(_pathname, this, "/");
|
|
636
|
+
if (temp) _classPrivateFieldSet2(_pathname$1, this, "/" + temp);
|
|
637
|
+
else _classPrivateFieldSet2(_pathname$1, this, "/");
|
|
631
638
|
}
|
|
632
639
|
}
|
|
633
640
|
get search() {
|
|
634
|
-
const val = _classPrivateFieldGet2(_search, this).toString();
|
|
641
|
+
const val = _classPrivateFieldGet2(_search$1, this).toString();
|
|
635
642
|
return val.length === 0 || val.startsWith("?") ? val : `?${val}`;
|
|
636
643
|
}
|
|
637
644
|
set search(val) {
|
|
638
645
|
if (isString(val)) {
|
|
639
646
|
val = val.trim();
|
|
640
|
-
_classPrivateFieldSet2(_search, this, new URLSearchParams(val));
|
|
647
|
+
_classPrivateFieldSet2(_search$1, this, new URLSearchParams(val));
|
|
641
648
|
}
|
|
642
649
|
}
|
|
643
650
|
get hash() {
|
|
644
|
-
return _classPrivateFieldGet2(_hash, this);
|
|
651
|
+
return _classPrivateFieldGet2(_hash$1, this);
|
|
645
652
|
}
|
|
646
653
|
set hash(val) {
|
|
647
654
|
if (isString(val)) {
|
|
648
655
|
val = val.trim();
|
|
649
|
-
if (val) _classPrivateFieldSet2(_hash, this, val.startsWith("#") ? val : `#${val}`);
|
|
650
|
-
else _classPrivateFieldSet2(_hash, this, "");
|
|
656
|
+
if (val) _classPrivateFieldSet2(_hash$1, this, val.startsWith("#") ? val : `#${val}`);
|
|
657
|
+
else _classPrivateFieldSet2(_hash$1, this, "");
|
|
651
658
|
}
|
|
652
659
|
}
|
|
653
660
|
get href() {
|
|
@@ -656,7 +663,7 @@ var TaroURL = class {
|
|
|
656
663
|
set href(val) {
|
|
657
664
|
if (val && isString(val)) {
|
|
658
665
|
val = val.trim();
|
|
659
|
-
const { protocol, hostname, port, hash, search, pathname } = parseUrl(val);
|
|
666
|
+
const { protocol, hostname, port, hash, search, pathname } = parseUrl$1(val);
|
|
660
667
|
this.protocol = protocol;
|
|
661
668
|
this.hostname = hostname;
|
|
662
669
|
this.pathname = pathname;
|
|
@@ -671,14 +678,14 @@ var TaroURL = class {
|
|
|
671
678
|
set origin(val) {
|
|
672
679
|
if (val && isString(val)) {
|
|
673
680
|
val = val.trim();
|
|
674
|
-
const { protocol, hostname, port } = parseUrl(val);
|
|
681
|
+
const { protocol, hostname, port } = parseUrl$1(val);
|
|
675
682
|
this.protocol = protocol;
|
|
676
683
|
this.hostname = hostname;
|
|
677
684
|
this.port = port;
|
|
678
685
|
}
|
|
679
686
|
}
|
|
680
687
|
get searchParams() {
|
|
681
|
-
return _classPrivateFieldGet2(_search, this);
|
|
688
|
+
return _classPrivateFieldGet2(_search$1, this);
|
|
682
689
|
}
|
|
683
690
|
toString() {
|
|
684
691
|
return this.href;
|
|
@@ -700,8 +707,8 @@ var TaroURL = class {
|
|
|
700
707
|
};
|
|
701
708
|
}
|
|
702
709
|
};
|
|
703
|
-
const TaroURLProvider =
|
|
704
|
-
function parseUrl(url = "") {
|
|
710
|
+
const TaroURLProvider$1 = TaroURL$1;
|
|
711
|
+
function parseUrl$1(url = "") {
|
|
705
712
|
const result = {
|
|
706
713
|
href: "",
|
|
707
714
|
origin: "",
|
|
@@ -728,14 +735,14 @@ function parseUrl(url = "") {
|
|
|
728
735
|
result.host = result.hostname + (result.port ? `:${result.port}` : "");
|
|
729
736
|
return result;
|
|
730
737
|
}
|
|
731
|
-
function parseUrlBase(url, base) {
|
|
738
|
+
function parseUrlBase$1(url, base) {
|
|
732
739
|
const VALID_URL = /^(https?:)\/\//i;
|
|
733
740
|
let fullUrl = "";
|
|
734
741
|
let parsedBase = null;
|
|
735
742
|
if (!isUndefined(base)) {
|
|
736
743
|
base = String(base).trim();
|
|
737
744
|
if (!VALID_URL.test(base)) throw new TypeError(`Failed to construct 'URL': Invalid base URL`);
|
|
738
|
-
parsedBase = parseUrl(base);
|
|
745
|
+
parsedBase = parseUrl$1(base);
|
|
739
746
|
}
|
|
740
747
|
url = String(url).trim();
|
|
741
748
|
if (VALID_URL.test(url)) fullUrl = url;
|
|
@@ -743,7 +750,7 @@ function parseUrlBase(url, base) {
|
|
|
743
750
|
else fullUrl = parsedBase.origin + (url.startsWith("/") ? url : `/${url}`);
|
|
744
751
|
else fullUrl = parsedBase.href;
|
|
745
752
|
else throw new TypeError(`Failed to construct 'URL': Invalid URL`);
|
|
746
|
-
return parseUrl(fullUrl);
|
|
753
|
+
return parseUrl$1(fullUrl);
|
|
747
754
|
}
|
|
748
755
|
//#endregion
|
|
749
756
|
//#region src/bom/location.ts
|
|
@@ -757,7 +764,7 @@ var TaroLocation = class extends Events {
|
|
|
757
764
|
constructor(options) {
|
|
758
765
|
super();
|
|
759
766
|
_classPrivateMethodInitSpec(this, _TaroLocation_brand);
|
|
760
|
-
_classPrivateFieldInitSpec(this, _url, new TaroURLProvider(INIT_URL));
|
|
767
|
+
_classPrivateFieldInitSpec(this, _url, new TaroURLProvider$1(INIT_URL));
|
|
761
768
|
_classPrivateFieldInitSpec(this, _noCheckUrl, false);
|
|
762
769
|
_classPrivateFieldInitSpec(this, _window, void 0);
|
|
763
770
|
_classPrivateFieldSet2(_window, this, options.window);
|
|
@@ -902,7 +909,7 @@ function _reset() {
|
|
|
902
909
|
});
|
|
903
910
|
const searchStr = searchArr.length > 0 ? "?" + searchArr.join("&") : "";
|
|
904
911
|
const url = `${INIT_URL}${path.startsWith("/") ? path : "/" + path}${searchStr}`;
|
|
905
|
-
_classPrivateFieldSet2(_url, this, new TaroURLProvider(url));
|
|
912
|
+
_classPrivateFieldSet2(_url, this, new TaroURLProvider$1(url));
|
|
906
913
|
this.trigger("__reset_history__", this.href);
|
|
907
914
|
}
|
|
908
915
|
}
|
|
@@ -934,7 +941,7 @@ function _checkUrlChange(preValue) {
|
|
|
934
941
|
_assertClassBrand(_TaroLocation_brand, this, _rollBack).call(this, preValue.href);
|
|
935
942
|
return false;
|
|
936
943
|
}
|
|
937
|
-
const Location =
|
|
944
|
+
const Location = TaroLocation;
|
|
938
945
|
function generateFullUrl(val = "") {
|
|
939
946
|
const origin = INIT_URL;
|
|
940
947
|
if (/^[/?#]/.test(val)) return origin + val;
|
|
@@ -943,7 +950,7 @@ function generateFullUrl(val = "") {
|
|
|
943
950
|
//#endregion
|
|
944
951
|
//#region src/bom/navigator.ts
|
|
945
952
|
const msg = "(Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36";
|
|
946
|
-
const nav =
|
|
953
|
+
const nav = {
|
|
947
954
|
appCodeName: "Mozilla",
|
|
948
955
|
appName: "Netscape",
|
|
949
956
|
appVersion: "5.0 " + msg,
|
|
@@ -973,14 +980,14 @@ let now;
|
|
|
973
980
|
}
|
|
974
981
|
})();
|
|
975
982
|
let lastTime = 0;
|
|
976
|
-
const _raf =
|
|
983
|
+
const _raf = function(callback) {
|
|
977
984
|
const _now = now();
|
|
978
985
|
const nextTime = Math.max(lastTime + 16, _now);
|
|
979
986
|
return setTimeout(function() {
|
|
980
987
|
callback(lastTime = nextTime);
|
|
981
988
|
}, nextTime - _now);
|
|
982
989
|
};
|
|
983
|
-
const _caf =
|
|
990
|
+
const _caf = function(seed) {
|
|
984
991
|
clearTimeout(seed);
|
|
985
992
|
};
|
|
986
993
|
//#endregion
|
|
@@ -1042,7 +1049,7 @@ var TaroWindow = class extends Events {
|
|
|
1042
1049
|
return clearTimeout(...args);
|
|
1043
1050
|
}
|
|
1044
1051
|
};
|
|
1045
|
-
const taroWindowProvider =
|
|
1052
|
+
const taroWindowProvider = env.window = new TaroWindow();
|
|
1046
1053
|
const taroLocationProvider = taroWindowProvider.location;
|
|
1047
1054
|
const taroHistoryProvider = taroWindowProvider.history;
|
|
1048
1055
|
//#endregion
|
|
@@ -1191,7 +1198,8 @@ var ClassList = class {
|
|
|
1191
1198
|
toggle(token, force) {
|
|
1192
1199
|
const result = this.contains(token);
|
|
1193
1200
|
const method = result ? force !== true && "remove" : force !== false && "add";
|
|
1194
|
-
if (method) this
|
|
1201
|
+
if (method === "add") this.add(token);
|
|
1202
|
+
if (method === "remove") this.remove(token);
|
|
1195
1203
|
if (force === true || force === false) return force;
|
|
1196
1204
|
else return !result;
|
|
1197
1205
|
}
|
|
@@ -1268,7 +1276,7 @@ function hydrate(node) {
|
|
|
1268
1276
|
for (const prop in props) {
|
|
1269
1277
|
const propInCamelCase = toCamelCase(prop);
|
|
1270
1278
|
if (!prop.startsWith("data-") && prop !== "class" && prop !== "style" && prop !== "id" && propInCamelCase !== "catchMove" && propInCamelCase !== "compileMode") data[propInCamelCase] = props[prop];
|
|
1271
|
-
if (
|
|
1279
|
+
if (nodeName === "view" && propInCamelCase === "catchMove" && props[prop] !== false) data[Shortcuts.NodeName] = CATCH_VIEW;
|
|
1272
1280
|
if (propInCamelCase === "compileMode") compileModeName = props[prop];
|
|
1273
1281
|
}
|
|
1274
1282
|
data[Shortcuts.Childnodes] = node.childNodes.filter((node) => !isComment(node)).map(hydrate);
|
|
@@ -1370,7 +1378,7 @@ var TaroNode = class TaroNode extends TaroEventTarget {
|
|
|
1370
1378
|
updateChildNodes(isClean) {
|
|
1371
1379
|
const cleanChildNodes = () => [];
|
|
1372
1380
|
const rerenderChildNodes = () => {
|
|
1373
|
-
return this.childNodes.filter((node) => !isComment(node)).map(hydrate);
|
|
1381
|
+
return this.childNodes.filter((node) => !isComment(node)).map((childNode) => hydrate(childNode));
|
|
1374
1382
|
};
|
|
1375
1383
|
this.enqueueUpdate({
|
|
1376
1384
|
path: `${this._path}.${CHILDNODES}`,
|
|
@@ -1425,9 +1433,11 @@ var TaroNode = class TaroNode extends TaroEventTarget {
|
|
|
1425
1433
|
const childNodes = this.childNodes;
|
|
1426
1434
|
return childNodes[childNodes.length - 1] || null;
|
|
1427
1435
|
}
|
|
1436
|
+
get textContent() {
|
|
1437
|
+
return this.childNodes.map((childNode) => childNode.textContent).join("");
|
|
1438
|
+
}
|
|
1428
1439
|
/**
|
|
1429
|
-
* @textContent
|
|
1430
|
-
* @TODO 等待完整 innerHTML 实现
|
|
1440
|
+
* @textContent 当前实现会用纯文本节点替换全部子节点。
|
|
1431
1441
|
*/
|
|
1432
1442
|
set textContent(text) {
|
|
1433
1443
|
const removedNodes = this.childNodes.slice();
|
|
@@ -1436,11 +1446,12 @@ var TaroNode = class TaroNode extends TaroEventTarget {
|
|
|
1436
1446
|
if (text === "") this.updateChildNodes(true);
|
|
1437
1447
|
else {
|
|
1438
1448
|
const newText = env.document.createTextNode(text);
|
|
1449
|
+
newText.parentNode = this;
|
|
1450
|
+
this.childNodes.push(newText);
|
|
1439
1451
|
addedNodes.push(newText);
|
|
1440
|
-
this.appendChild(newText);
|
|
1441
1452
|
this.updateChildNodes();
|
|
1442
1453
|
}
|
|
1443
|
-
MutationObserver
|
|
1454
|
+
MutationObserver.record({
|
|
1444
1455
|
type: "childList",
|
|
1445
1456
|
target: this,
|
|
1446
1457
|
removedNodes,
|
|
@@ -1463,7 +1474,11 @@ var TaroNode = class TaroNode extends TaroEventTarget {
|
|
|
1463
1474
|
}, refChild);
|
|
1464
1475
|
return newChild;
|
|
1465
1476
|
}
|
|
1466
|
-
|
|
1477
|
+
const previousParentNode = newChild.parentNode;
|
|
1478
|
+
newChild.remove({
|
|
1479
|
+
cleanRef: false,
|
|
1480
|
+
recordMutation: !!previousParentNode && previousParentNode !== this
|
|
1481
|
+
});
|
|
1467
1482
|
let index = 0;
|
|
1468
1483
|
newChild.parentNode = this;
|
|
1469
1484
|
if (refChild) {
|
|
@@ -1482,7 +1497,7 @@ var TaroNode = class TaroNode extends TaroEventTarget {
|
|
|
1482
1497
|
});
|
|
1483
1498
|
else if (childNodesLength * 2 / 3 > index) this.updateChildNodes();
|
|
1484
1499
|
else this.updateSingleChild(index);
|
|
1485
|
-
MutationObserver
|
|
1500
|
+
MutationObserver.record({
|
|
1486
1501
|
type: "childList",
|
|
1487
1502
|
target: this,
|
|
1488
1503
|
addedNodes: [newChild],
|
|
@@ -1525,8 +1540,8 @@ var TaroNode = class TaroNode extends TaroEventTarget {
|
|
|
1525
1540
|
* 2. remove C
|
|
1526
1541
|
*/
|
|
1527
1542
|
removeChild(child, options = {}) {
|
|
1528
|
-
const { cleanRef, doUpdate } = options;
|
|
1529
|
-
if (cleanRef !== false && doUpdate !== false) MutationObserver
|
|
1543
|
+
const { cleanRef, doUpdate, recordMutation } = options;
|
|
1544
|
+
if (cleanRef !== false && doUpdate !== false || recordMutation) MutationObserver.record({
|
|
1530
1545
|
type: "childList",
|
|
1531
1546
|
target: this,
|
|
1532
1547
|
removedNodes: [child],
|
|
@@ -1559,7 +1574,7 @@ var TaroNode = class TaroNode extends TaroEventTarget {
|
|
|
1559
1574
|
}
|
|
1560
1575
|
};
|
|
1561
1576
|
//#endregion
|
|
1562
|
-
//#region src/dom/
|
|
1577
|
+
//#region src/dom/style-properties.ts
|
|
1563
1578
|
const WEBKIT = "webkit";
|
|
1564
1579
|
const styleProperties = [
|
|
1565
1580
|
"all",
|
|
@@ -1932,7 +1947,7 @@ combine(WEBKIT, [
|
|
|
1932
1947
|
//#endregion
|
|
1933
1948
|
//#region src/dom/style.ts
|
|
1934
1949
|
function recordCss(obj) {
|
|
1935
|
-
MutationObserver
|
|
1950
|
+
MutationObserver.record({
|
|
1936
1951
|
type: "attributes",
|
|
1937
1952
|
target: obj._element,
|
|
1938
1953
|
attributeName: "style",
|
|
@@ -2100,14 +2115,14 @@ var TaroElement = class TaroElement extends TaroNode {
|
|
|
2100
2115
|
hooks$1.call("patchElement", this);
|
|
2101
2116
|
}
|
|
2102
2117
|
_stopPropagation(event) {
|
|
2103
|
-
let
|
|
2104
|
-
while (
|
|
2105
|
-
const listeners =
|
|
2106
|
-
if (
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
l._stop = true;
|
|
2118
|
+
let parentNode = this.parentNode;
|
|
2119
|
+
while (parentNode) {
|
|
2120
|
+
const listeners = parentNode.__handlers[event.type];
|
|
2121
|
+
if (isArray(listeners)) for (let i = listeners.length; i--;) {
|
|
2122
|
+
const listener = listeners[i];
|
|
2123
|
+
listener._stop = true;
|
|
2110
2124
|
}
|
|
2125
|
+
parentNode = parentNode.parentNode;
|
|
2111
2126
|
}
|
|
2112
2127
|
}
|
|
2113
2128
|
get id() {
|
|
@@ -2172,7 +2187,7 @@ var TaroElement = class TaroElement extends TaroNode {
|
|
|
2172
2187
|
setAttribute(qualifiedName, value) {
|
|
2173
2188
|
warn(isString(value) && value.length > 2046, `元素 ${this.nodeName} 的 ${qualifiedName} 属性值数据量过大,可能会影响渲染性能。考虑降低图片转为 base64 的阈值或在 CSS 中使用 base64。`);
|
|
2174
2189
|
const isPureView = this.nodeName === "view" && !isHasExtractProp(this) && !this.isAnyEventBinded();
|
|
2175
|
-
if (qualifiedName !== "style") MutationObserver
|
|
2190
|
+
if (qualifiedName !== "style") MutationObserver.record({
|
|
2176
2191
|
target: this,
|
|
2177
2192
|
type: "attributes",
|
|
2178
2193
|
attributeName: qualifiedName,
|
|
@@ -2226,7 +2241,7 @@ var TaroElement = class TaroElement extends TaroNode {
|
|
|
2226
2241
|
}
|
|
2227
2242
|
removeAttribute(qualifiedName) {
|
|
2228
2243
|
const isStaticView = this.nodeName === "view" && isHasExtractProp(this) && !this.isAnyEventBinded();
|
|
2229
|
-
MutationObserver
|
|
2244
|
+
MutationObserver.record({
|
|
2230
2245
|
target: this,
|
|
2231
2246
|
type: "attributes",
|
|
2232
2247
|
attributeName: qualifiedName,
|
|
@@ -2410,7 +2425,7 @@ function createEvent(event, node) {
|
|
|
2410
2425
|
}, event);
|
|
2411
2426
|
for (const key in event) if (key === "currentTarget" || key === "target" || key === "type" || key === "timeStamp") continue;
|
|
2412
2427
|
else domEv[key] = event[key];
|
|
2413
|
-
if (domEv.type === "confirm" && (node === null || node === void 0 ? void 0 : node.nodeName) === "input") domEv
|
|
2428
|
+
if (domEv.type === "confirm" && (node === null || node === void 0 ? void 0 : node.nodeName) === "input") domEv.keyCode = 13;
|
|
2414
2429
|
return domEv;
|
|
2415
2430
|
}
|
|
2416
2431
|
const eventsBatch = {};
|
|
@@ -2421,8 +2436,6 @@ function getEventCBResult(event) {
|
|
|
2421
2436
|
}
|
|
2422
2437
|
function eventHandler(event) {
|
|
2423
2438
|
var _currentTarget$datase2, _event$detail;
|
|
2424
|
-
event.type === void 0 && Object.defineProperty(event, "type", { value: event._type });
|
|
2425
|
-
event.detail === void 0 && Object.defineProperty(event, "detail", { value: event._detail || _objectSpread2({}, event) });
|
|
2426
2439
|
event.currentTarget = event.currentTarget || event.target || _objectSpread2({}, event);
|
|
2427
2440
|
hooks$1.call("modifyMpEventImpl", event);
|
|
2428
2441
|
const currentTarget = event.currentTarget;
|
|
@@ -2453,14 +2466,6 @@ function eventHandler(event) {
|
|
|
2453
2466
|
}
|
|
2454
2467
|
}
|
|
2455
2468
|
}
|
|
2456
|
-
function eventHandlerTTDom(ele, listener, event) {
|
|
2457
|
-
Object.assign(event, {
|
|
2458
|
-
mpEvent: event,
|
|
2459
|
-
bubbles: true,
|
|
2460
|
-
cancelable: true
|
|
2461
|
-
});
|
|
2462
|
-
listener(event, ele);
|
|
2463
|
-
}
|
|
2464
2469
|
//#endregion
|
|
2465
2470
|
//#region src/dom/form.ts
|
|
2466
2471
|
var FormElement = class extends TaroElement {
|
|
@@ -2472,7 +2477,7 @@ var FormElement = class extends TaroElement {
|
|
|
2472
2477
|
this.setAttribute(TYPE, val);
|
|
2473
2478
|
}
|
|
2474
2479
|
get value() {
|
|
2475
|
-
const val = this.props
|
|
2480
|
+
const val = this.props.value;
|
|
2476
2481
|
return val == null ? "" : val;
|
|
2477
2482
|
}
|
|
2478
2483
|
set value(val) {
|
|
@@ -2505,7 +2510,7 @@ var Performance = class {
|
|
|
2505
2510
|
if (!(prev >= 0)) return;
|
|
2506
2511
|
this.recorder.delete(id);
|
|
2507
2512
|
const time = now - prev;
|
|
2508
|
-
|
|
2513
|
+
process.stdout.write(`${id} 时长: ${time}ms 开始时间:${_assertClassBrand(_Performance_brand, this, _parseTime).call(this, prev)} 结束时间:${_assertClassBrand(_Performance_brand, this, _parseTime).call(this, now)}\n`);
|
|
2509
2514
|
}
|
|
2510
2515
|
delayStop(id, delay = 500) {
|
|
2511
2516
|
if (!options.debug) return;
|
|
@@ -2613,11 +2618,11 @@ var TaroRootElement = class extends TaroElement {
|
|
|
2613
2618
|
}
|
|
2614
2619
|
};
|
|
2615
2620
|
if (customWrapperCount) customWrapperMap.forEach((data, ctx) => {
|
|
2616
|
-
if (options.debug) console.log("custom wrapper setData: ", data);
|
|
2621
|
+
if (options.debug) globalThis.console.log("custom wrapper setData: ", data);
|
|
2617
2622
|
ctx.setData(data, cb);
|
|
2618
2623
|
});
|
|
2619
2624
|
if (isNeedNormalUpdate) {
|
|
2620
|
-
if (options.debug) console.log("page setData:", normalUpdate);
|
|
2625
|
+
if (options.debug) globalThis.console.log("page setData:", normalUpdate);
|
|
2621
2626
|
ctx.setData(normalUpdate, cb);
|
|
2622
2627
|
}
|
|
2623
2628
|
});
|
|
@@ -2645,7 +2650,7 @@ var TaroText = class extends TaroNode {
|
|
|
2645
2650
|
this._value = value;
|
|
2646
2651
|
}
|
|
2647
2652
|
set textContent(text) {
|
|
2648
|
-
MutationObserver
|
|
2653
|
+
MutationObserver.record({
|
|
2649
2654
|
target: this,
|
|
2650
2655
|
type: "characterData",
|
|
2651
2656
|
oldValue: this._value
|
|
@@ -2673,6 +2678,194 @@ var TaroText = class extends TaroNode {
|
|
|
2673
2678
|
}
|
|
2674
2679
|
};
|
|
2675
2680
|
//#endregion
|
|
2681
|
+
//#region src/bom/URL.ts
|
|
2682
|
+
var _hash = /* @__PURE__ */ new WeakMap();
|
|
2683
|
+
var _hostname = /* @__PURE__ */ new WeakMap();
|
|
2684
|
+
var _pathname = /* @__PURE__ */ new WeakMap();
|
|
2685
|
+
var _port = /* @__PURE__ */ new WeakMap();
|
|
2686
|
+
var _protocol = /* @__PURE__ */ new WeakMap();
|
|
2687
|
+
var _search = /* @__PURE__ */ new WeakMap();
|
|
2688
|
+
var TaroURL = class {
|
|
2689
|
+
static createObjectURL() {
|
|
2690
|
+
throw new Error("Oops, not support URL.createObjectURL() in miniprogram.");
|
|
2691
|
+
}
|
|
2692
|
+
static revokeObjectURL() {
|
|
2693
|
+
throw new Error("Oops, not support URL.revokeObjectURL() in miniprogram.");
|
|
2694
|
+
}
|
|
2695
|
+
constructor(url, base) {
|
|
2696
|
+
_classPrivateFieldInitSpec(this, _hash, "");
|
|
2697
|
+
_classPrivateFieldInitSpec(this, _hostname, "");
|
|
2698
|
+
_classPrivateFieldInitSpec(this, _pathname, "");
|
|
2699
|
+
_classPrivateFieldInitSpec(this, _port, "");
|
|
2700
|
+
_classPrivateFieldInitSpec(this, _protocol, "");
|
|
2701
|
+
_classPrivateFieldInitSpec(this, _search, void 0);
|
|
2702
|
+
if (!isString(url)) url = String(url);
|
|
2703
|
+
const { hash, hostname, pathname, port, protocol, search } = parseUrlBase(url, base);
|
|
2704
|
+
_classPrivateFieldSet2(_hash, this, hash);
|
|
2705
|
+
_classPrivateFieldSet2(_hostname, this, hostname);
|
|
2706
|
+
_classPrivateFieldSet2(_pathname, this, pathname || "/");
|
|
2707
|
+
_classPrivateFieldSet2(_port, this, port);
|
|
2708
|
+
_classPrivateFieldSet2(_protocol, this, protocol);
|
|
2709
|
+
_classPrivateFieldSet2(_search, this, new URLSearchParams(search));
|
|
2710
|
+
}
|
|
2711
|
+
get protocol() {
|
|
2712
|
+
return _classPrivateFieldGet2(_protocol, this);
|
|
2713
|
+
}
|
|
2714
|
+
set protocol(val) {
|
|
2715
|
+
isString(val) && _classPrivateFieldSet2(_protocol, this, val.trim());
|
|
2716
|
+
}
|
|
2717
|
+
get host() {
|
|
2718
|
+
return this.hostname + (this.port ? ":" + this.port : "");
|
|
2719
|
+
}
|
|
2720
|
+
set host(val) {
|
|
2721
|
+
if (val && isString(val)) {
|
|
2722
|
+
val = val.trim();
|
|
2723
|
+
const { hostname, port } = parseUrl(`//${val}`);
|
|
2724
|
+
this.hostname = hostname;
|
|
2725
|
+
this.port = port;
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
get hostname() {
|
|
2729
|
+
return _classPrivateFieldGet2(_hostname, this);
|
|
2730
|
+
}
|
|
2731
|
+
set hostname(val) {
|
|
2732
|
+
val && isString(val) && _classPrivateFieldSet2(_hostname, this, val.trim());
|
|
2733
|
+
}
|
|
2734
|
+
get port() {
|
|
2735
|
+
return _classPrivateFieldGet2(_port, this);
|
|
2736
|
+
}
|
|
2737
|
+
set port(val) {
|
|
2738
|
+
isString(val) && _classPrivateFieldSet2(_port, this, val.trim());
|
|
2739
|
+
}
|
|
2740
|
+
get pathname() {
|
|
2741
|
+
return _classPrivateFieldGet2(_pathname, this);
|
|
2742
|
+
}
|
|
2743
|
+
set pathname(val) {
|
|
2744
|
+
if (isString(val)) {
|
|
2745
|
+
val = val.trim();
|
|
2746
|
+
const HEAD_REG = /^(\/|\.\/|\.\.\/)/;
|
|
2747
|
+
let temp = val;
|
|
2748
|
+
while (HEAD_REG.test(temp)) temp = temp.replace(HEAD_REG, "");
|
|
2749
|
+
if (temp) _classPrivateFieldSet2(_pathname, this, "/" + temp);
|
|
2750
|
+
else _classPrivateFieldSet2(_pathname, this, "/");
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
get search() {
|
|
2754
|
+
const val = _classPrivateFieldGet2(_search, this).toString();
|
|
2755
|
+
return val.length === 0 || val.startsWith("?") ? val : `?${val}`;
|
|
2756
|
+
}
|
|
2757
|
+
set search(val) {
|
|
2758
|
+
if (isString(val)) {
|
|
2759
|
+
val = val.trim();
|
|
2760
|
+
_classPrivateFieldSet2(_search, this, new URLSearchParams(val));
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
get hash() {
|
|
2764
|
+
return _classPrivateFieldGet2(_hash, this);
|
|
2765
|
+
}
|
|
2766
|
+
set hash(val) {
|
|
2767
|
+
if (isString(val)) {
|
|
2768
|
+
val = val.trim();
|
|
2769
|
+
if (val) _classPrivateFieldSet2(_hash, this, val.startsWith("#") ? val : `#${val}`);
|
|
2770
|
+
else _classPrivateFieldSet2(_hash, this, "");
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
get href() {
|
|
2774
|
+
return `${this.protocol}//${this.host}${this.pathname}${this.search}${this.hash}`;
|
|
2775
|
+
}
|
|
2776
|
+
set href(val) {
|
|
2777
|
+
if (val && isString(val)) {
|
|
2778
|
+
val = val.trim();
|
|
2779
|
+
const { protocol, hostname, port, hash, search, pathname } = parseUrl(val);
|
|
2780
|
+
this.protocol = protocol;
|
|
2781
|
+
this.hostname = hostname;
|
|
2782
|
+
this.pathname = pathname;
|
|
2783
|
+
this.port = port;
|
|
2784
|
+
this.hash = hash;
|
|
2785
|
+
this.search = search;
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
get origin() {
|
|
2789
|
+
return `${this.protocol}//${this.host}`;
|
|
2790
|
+
}
|
|
2791
|
+
set origin(val) {
|
|
2792
|
+
if (val && isString(val)) {
|
|
2793
|
+
val = val.trim();
|
|
2794
|
+
const { protocol, hostname, port } = parseUrl(val);
|
|
2795
|
+
this.protocol = protocol;
|
|
2796
|
+
this.hostname = hostname;
|
|
2797
|
+
this.port = port;
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
get searchParams() {
|
|
2801
|
+
return _classPrivateFieldGet2(_search, this);
|
|
2802
|
+
}
|
|
2803
|
+
toString() {
|
|
2804
|
+
return this.href;
|
|
2805
|
+
}
|
|
2806
|
+
toJSON() {
|
|
2807
|
+
return this.toString();
|
|
2808
|
+
}
|
|
2809
|
+
_toRaw() {
|
|
2810
|
+
return {
|
|
2811
|
+
protocol: this.protocol,
|
|
2812
|
+
port: this.port,
|
|
2813
|
+
host: this.host,
|
|
2814
|
+
hostname: this.hostname,
|
|
2815
|
+
pathname: this.pathname,
|
|
2816
|
+
hash: this.hash,
|
|
2817
|
+
search: this.search,
|
|
2818
|
+
origin: this.origin,
|
|
2819
|
+
href: this.href
|
|
2820
|
+
};
|
|
2821
|
+
}
|
|
2822
|
+
};
|
|
2823
|
+
const TaroURLProvider = TaroURL;
|
|
2824
|
+
function parseUrl(url = "") {
|
|
2825
|
+
const result = {
|
|
2826
|
+
href: "",
|
|
2827
|
+
origin: "",
|
|
2828
|
+
protocol: "",
|
|
2829
|
+
hostname: "",
|
|
2830
|
+
host: "",
|
|
2831
|
+
port: "",
|
|
2832
|
+
pathname: "",
|
|
2833
|
+
search: "",
|
|
2834
|
+
hash: ""
|
|
2835
|
+
};
|
|
2836
|
+
if (!url || !isString(url)) return result;
|
|
2837
|
+
url = url.trim();
|
|
2838
|
+
const matches = url.match(/^(([^:/?#]+):)?\/\/(([^/?#]+):(.+)@)?([^/?#:]*)(:(\d+))?([^?#]*)(\?([^#]*))?(#(.*))?/);
|
|
2839
|
+
if (!matches) return result;
|
|
2840
|
+
result.protocol = matches[1] || "https:";
|
|
2841
|
+
result.hostname = matches[6] || "taro.com";
|
|
2842
|
+
result.port = matches[8] || "";
|
|
2843
|
+
result.pathname = matches[9] || "/";
|
|
2844
|
+
result.search = matches[10] || "";
|
|
2845
|
+
result.hash = matches[12] || "";
|
|
2846
|
+
result.href = url;
|
|
2847
|
+
result.origin = result.protocol + "//" + result.hostname + (result.port ? `:${result.port}` : "");
|
|
2848
|
+
result.host = result.hostname + (result.port ? `:${result.port}` : "");
|
|
2849
|
+
return result;
|
|
2850
|
+
}
|
|
2851
|
+
function parseUrlBase(url, base) {
|
|
2852
|
+
const VALID_URL = /^(https?:)\/\//i;
|
|
2853
|
+
let fullUrl = "";
|
|
2854
|
+
let parsedBase = null;
|
|
2855
|
+
if (!isUndefined(base)) {
|
|
2856
|
+
base = String(base).trim();
|
|
2857
|
+
if (!VALID_URL.test(base)) throw new TypeError(`Failed to construct 'URL': Invalid base URL`);
|
|
2858
|
+
parsedBase = parseUrl(base);
|
|
2859
|
+
}
|
|
2860
|
+
url = String(url).trim();
|
|
2861
|
+
if (VALID_URL.test(url)) fullUrl = url;
|
|
2862
|
+
else if (parsedBase) if (url) if (url.startsWith("//")) fullUrl = parsedBase.protocol + url;
|
|
2863
|
+
else fullUrl = parsedBase.origin + (url.startsWith("/") ? url : `/${url}`);
|
|
2864
|
+
else fullUrl = parsedBase.href;
|
|
2865
|
+
else throw new TypeError(`Failed to construct 'URL': Invalid URL`);
|
|
2866
|
+
return parseUrl(fullUrl);
|
|
2867
|
+
}
|
|
2868
|
+
//#endregion
|
|
2676
2869
|
//#region src/dom/anchor-element.ts
|
|
2677
2870
|
var AnchorElement = class extends TaroElement {
|
|
2678
2871
|
get href() {
|
|
@@ -2822,60 +3015,7 @@ function createDocument() {
|
|
|
2822
3015
|
doc.body = body;
|
|
2823
3016
|
return doc;
|
|
2824
3017
|
}
|
|
2825
|
-
|
|
2826
|
-
var _tt$getBuiltInCompone;
|
|
2827
|
-
const document = tt === null || tt === void 0 ? void 0 : tt.appDocument;
|
|
2828
|
-
if (!document) throw new Error("tt.appDocument is not found");
|
|
2829
|
-
const html = document.createElement(HTML);
|
|
2830
|
-
const head = document.createElement(HEAD);
|
|
2831
|
-
const body = document.createElement(BODY);
|
|
2832
|
-
const app = document.createElement("app");
|
|
2833
|
-
app.id = "app";
|
|
2834
|
-
const container = document.createElement(CONTAINER);
|
|
2835
|
-
const emptyFunction = () => {};
|
|
2836
|
-
document.childNodes.push(html);
|
|
2837
|
-
html.childNodes.push(head, body);
|
|
2838
|
-
body.childNodes.push(container);
|
|
2839
|
-
container.childNodes.push(app);
|
|
2840
|
-
document.documentElement = html;
|
|
2841
|
-
document.head = head;
|
|
2842
|
-
document.body = body;
|
|
2843
|
-
document.appElement = app;
|
|
2844
|
-
let builtInComponents = tt === null || tt === void 0 || (_tt$getBuiltInCompone = tt.getBuiltInComponents) === null || _tt$getBuiltInCompone === void 0 ? void 0 : _tt$getBuiltInCompone.call(tt);
|
|
2845
|
-
if (Array.isArray(builtInComponents)) builtInComponents = new Set(builtInComponents);
|
|
2846
|
-
else if (!(builtInComponents instanceof Set)) builtInComponents = new Set([...DEFAULT_COMPONENTS, ...TT_SPECIFIC_COMPONENTS]);
|
|
2847
|
-
document.getElementById = function getElementById(id) {
|
|
2848
|
-
if (id === "app") return app;
|
|
2849
|
-
else return Object.getPrototypeOf(this).getElementById.call(this, id);
|
|
2850
|
-
};
|
|
2851
|
-
document.getLastPage = function getLastPage() {
|
|
2852
|
-
let last;
|
|
2853
|
-
for (const v of this._pageDocumentMap.values()) last = v;
|
|
2854
|
-
return last;
|
|
2855
|
-
};
|
|
2856
|
-
document.createElement = function(type, ...args) {
|
|
2857
|
-
if (type === "root") return this.getLastPage();
|
|
2858
|
-
else {
|
|
2859
|
-
const el = builtInComponents.has(type) ? Object.getPrototypeOf(this).createElement.call(this, type, ...args) : Object.getPrototypeOf(this).createNativeComponent.call(this, type, { __tt__inner__options__: { name: type } });
|
|
2860
|
-
el.setAttribute("class", "");
|
|
2861
|
-
const originalSetAttribute = el.setAttribute.bind(el);
|
|
2862
|
-
const originalRemoveAttribute = el.removeAttribute.bind(el);
|
|
2863
|
-
el.setAttribute = function(name, value) {
|
|
2864
|
-
const result = originalSetAttribute(name, value);
|
|
2865
|
-
if (name === "catchMove" && value) el.addEventListener("catchtouchmove", emptyFunction);
|
|
2866
|
-
return result;
|
|
2867
|
-
};
|
|
2868
|
-
el.removeAttribute = function(name) {
|
|
2869
|
-
const oldValue = el.getAttribute(name);
|
|
2870
|
-
if (name === "catchMove" && oldValue) el.removeEventListener("catchtouchmove", emptyFunction);
|
|
2871
|
-
return originalRemoveAttribute(name);
|
|
2872
|
-
};
|
|
2873
|
-
return el;
|
|
2874
|
-
}
|
|
2875
|
-
};
|
|
2876
|
-
return document;
|
|
2877
|
-
}
|
|
2878
|
-
const taroDocumentProvider = process.env.TARO_PLATFORM === "web" ? env.document : env.document = isEnableTTDom() ? createTTDomDocument() : createDocument();
|
|
3018
|
+
const taroDocumentProvider = env.document = createDocument();
|
|
2879
3019
|
//#endregion
|
|
2880
3020
|
//#region src/dom/svg.ts
|
|
2881
3021
|
var SVGElement = class extends TaroElement {};
|
|
@@ -2910,8 +3050,7 @@ function stringify(obj) {
|
|
|
2910
3050
|
}
|
|
2911
3051
|
function getPath(id, options) {
|
|
2912
3052
|
const idx = id.indexOf("?");
|
|
2913
|
-
|
|
2914
|
-
else return `${idx > -1 ? id.substring(0, idx) : id}${stringify(options)}`;
|
|
3053
|
+
return `${idx > -1 ? id.substring(0, idx) : id}${stringify(options)}`;
|
|
2915
3054
|
}
|
|
2916
3055
|
function getOnReadyEventKey(path) {
|
|
2917
3056
|
return path + ".onReady";
|
|
@@ -2929,7 +3068,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
2929
3068
|
let unmounting = false;
|
|
2930
3069
|
let prepareMountList = [];
|
|
2931
3070
|
function setCurrentRouter(page) {
|
|
2932
|
-
const router =
|
|
3071
|
+
const router = page.route || page.__route__ || page.$taroPath;
|
|
2933
3072
|
Current.router = {
|
|
2934
3073
|
params: page.$taroParams,
|
|
2935
3074
|
path: addLeadingSlash(router),
|
|
@@ -2952,33 +3091,28 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
2952
3091
|
this.config = pageConfig || {};
|
|
2953
3092
|
const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() });
|
|
2954
3093
|
const $taroPath = this.$taroPath = getPath(id, uniqueOptions);
|
|
2955
|
-
if (process.env.TARO_PLATFORM === "web") config.path = $taroPath;
|
|
2956
3094
|
if (this.$taroParams == null) this.$taroParams = uniqueOptions;
|
|
2957
3095
|
setCurrentRouter(this);
|
|
2958
|
-
|
|
3096
|
+
taroWindowProvider.trigger("0", $taroPath);
|
|
2959
3097
|
const mount = () => {
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
else pageElement = env.document.getElementById($taroPath);
|
|
3098
|
+
whenAppReady((app) => app.mount(component, $taroPath, () => {
|
|
3099
|
+
pageElement = env.document.getElementById($taroPath);
|
|
2963
3100
|
ensure(pageElement !== null, "没有找到页面实例。");
|
|
2964
3101
|
safeExecute($taroPath, ON_LOAD, this.$taroParams);
|
|
2965
3102
|
loadResolver();
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
else pageElement.performUpdate(true, cb);
|
|
2970
|
-
} else isFunction(cb) && cb();
|
|
2971
|
-
});
|
|
3103
|
+
pageElement.ctx = this;
|
|
3104
|
+
pageElement.performUpdate(true, cb);
|
|
3105
|
+
}));
|
|
2972
3106
|
};
|
|
2973
3107
|
if (unmounting) prepareMountList.push(mount);
|
|
2974
3108
|
else mount();
|
|
2975
3109
|
},
|
|
2976
3110
|
[ONUNLOAD]() {
|
|
2977
3111
|
const $taroPath = this.$taroPath;
|
|
2978
|
-
|
|
3112
|
+
taroWindowProvider.trigger("3", $taroPath);
|
|
2979
3113
|
safeExecute($taroPath, ONUNLOAD);
|
|
2980
3114
|
unmounting = true;
|
|
2981
|
-
|
|
3115
|
+
whenAppReady((app) => app.unmount($taroPath, () => {
|
|
2982
3116
|
unmounting = false;
|
|
2983
3117
|
instances.delete($taroPath);
|
|
2984
3118
|
if (pageElement) {
|
|
@@ -2989,26 +3123,26 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
2989
3123
|
prepareMountList.forEach((fn) => fn());
|
|
2990
3124
|
prepareMountList = [];
|
|
2991
3125
|
}
|
|
2992
|
-
});
|
|
3126
|
+
}));
|
|
2993
3127
|
},
|
|
2994
3128
|
[ONREADY]() {
|
|
2995
3129
|
hasLoaded.then(() => {
|
|
2996
3130
|
safeExecute(this.$taroPath, ON_READY);
|
|
2997
3131
|
_raf(() => eventCenter.trigger(getOnReadyEventKey(id)));
|
|
2998
|
-
this.
|
|
3132
|
+
this[ONREADY].called = true;
|
|
2999
3133
|
});
|
|
3000
3134
|
},
|
|
3001
3135
|
[ONSHOW](options = {}) {
|
|
3002
3136
|
hasLoaded.then(() => {
|
|
3003
3137
|
Current.page = this;
|
|
3004
3138
|
setCurrentRouter(this);
|
|
3005
|
-
|
|
3139
|
+
taroWindowProvider.trigger("2", this.$taroPath);
|
|
3006
3140
|
safeExecute(this.$taroPath, ON_SHOW, options);
|
|
3007
3141
|
_raf(() => eventCenter.trigger(getOnShowEventKey(id)));
|
|
3008
3142
|
});
|
|
3009
3143
|
},
|
|
3010
3144
|
[ONHIDE]() {
|
|
3011
|
-
|
|
3145
|
+
taroWindowProvider.trigger("1", this.$taroPath);
|
|
3012
3146
|
if (Current.page === this) {
|
|
3013
3147
|
Current.page = null;
|
|
3014
3148
|
Current.router = null;
|
|
@@ -3017,10 +3151,6 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3017
3151
|
eventCenter.trigger(getOnHideEventKey(id));
|
|
3018
3152
|
}
|
|
3019
3153
|
};
|
|
3020
|
-
if (process.env.TARO_PLATFORM === "web") config.getOpenerEventChannel = () => {
|
|
3021
|
-
return EventChannel.pageChannel;
|
|
3022
|
-
};
|
|
3023
|
-
const isSWAN = process.env.TARO_ENV === "swan";
|
|
3024
3154
|
LIFECYCLES.forEach((lifecycle) => {
|
|
3025
3155
|
let isDefer = false;
|
|
3026
3156
|
let isEvent = false;
|
|
@@ -3032,14 +3162,9 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
3032
3162
|
isEvent = true;
|
|
3033
3163
|
return "";
|
|
3034
3164
|
});
|
|
3035
|
-
if (isEvent
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
return safeExecute(this.$taroPath, lifecycle, ...arguments);
|
|
3039
|
-
};
|
|
3040
|
-
} else config[lifecycle] = function() {
|
|
3041
|
-
const exec = () => safeExecute(this.$taroPath, lifecycle, ...arguments);
|
|
3042
|
-
if (isSWAN) return exec();
|
|
3165
|
+
if (isEvent) return;
|
|
3166
|
+
config[lifecycle] = function(...args) {
|
|
3167
|
+
const exec = () => safeExecute(this.$taroPath, lifecycle, ...args);
|
|
3043
3168
|
if (isDefer) hasLoaded.then(exec);
|
|
3044
3169
|
else return exec();
|
|
3045
3170
|
};
|
|
@@ -3072,23 +3197,21 @@ function createComponentConfig(component, componentName, data) {
|
|
|
3072
3197
|
perf.start(PAGE_INIT);
|
|
3073
3198
|
this.pageIdCache = ((_this$getPageId = this.getPageId) === null || _this$getPageId === void 0 ? void 0 : _this$getPageId.call(this)) || pageId();
|
|
3074
3199
|
const path = getPath(id, { id: this.pageIdCache });
|
|
3075
|
-
|
|
3200
|
+
whenAppReady((app) => app.mount(component, path, () => {
|
|
3076
3201
|
componentElement = env.document.getElementById(path);
|
|
3077
3202
|
ensure(componentElement !== null, "没有找到组件实例。");
|
|
3078
3203
|
this.$taroInstances = instances.get(path);
|
|
3079
3204
|
safeExecute(path, ON_LOAD);
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
}
|
|
3084
|
-
});
|
|
3205
|
+
componentElement.ctx = this;
|
|
3206
|
+
componentElement.performUpdate(true);
|
|
3207
|
+
}));
|
|
3085
3208
|
},
|
|
3086
3209
|
[DETACHED]() {
|
|
3087
3210
|
const path = getPath(id, { id: this.pageIdCache });
|
|
3088
|
-
|
|
3211
|
+
whenAppReady((app) => app.unmount(path, () => {
|
|
3089
3212
|
instances.delete(path);
|
|
3090
3213
|
if (componentElement) componentElement.ctx = null;
|
|
3091
|
-
});
|
|
3214
|
+
}));
|
|
3092
3215
|
},
|
|
3093
3216
|
methods: { eh: eventHandler }
|
|
3094
3217
|
};
|
|
@@ -3109,7 +3232,6 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
3109
3232
|
const lifeCycles = isCustomWrapper ? {
|
|
3110
3233
|
[ATTACHED]() {
|
|
3111
3234
|
var _this$data$i, _this$props$i;
|
|
3112
|
-
if (process.env.TARO_ENV === "tt" && isEnableTTDom()) return;
|
|
3113
3235
|
const componentId = ((_this$data$i = this.data.i) === null || _this$data$i === void 0 ? void 0 : _this$data$i.sid) || ((_this$props$i = this.props.i) === null || _this$props$i === void 0 ? void 0 : _this$props$i.sid);
|
|
3114
3236
|
if (isString(componentId)) {
|
|
3115
3237
|
customWrapperCache.set(componentId, this);
|
|
@@ -3119,7 +3241,6 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
3119
3241
|
},
|
|
3120
3242
|
[DETACHED]() {
|
|
3121
3243
|
var _this$data$i2, _this$props$i2;
|
|
3122
|
-
if (process.env.TARO_ENV === "tt" && isEnableTTDom()) return;
|
|
3123
3244
|
const componentId = ((_this$data$i2 = this.data.i) === null || _this$data$i2 === void 0 ? void 0 : _this$data$i2.sid) || ((_this$props$i2 = this.props.i) === null || _this$props$i2 === void 0 ? void 0 : _this$props$i2.sid);
|
|
3124
3245
|
if (isString(componentId)) {
|
|
3125
3246
|
customWrapperCache.delete(componentId);
|
|
@@ -3128,8 +3249,6 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
3128
3249
|
}
|
|
3129
3250
|
}
|
|
3130
3251
|
} : EMPTY_OBJ;
|
|
3131
|
-
const extraOptions = {};
|
|
3132
|
-
if (process.env.TARO_ENV === "jd") extraOptions.addGlobalClass = true;
|
|
3133
3252
|
return hooks$1.call("modifyRecursiveComponentConfig", _objectSpread2({
|
|
3134
3253
|
properties: {
|
|
3135
3254
|
i: {
|
|
@@ -3141,7 +3260,7 @@ function createRecursiveComponentConfig(componentName) {
|
|
|
3141
3260
|
value: ""
|
|
3142
3261
|
}
|
|
3143
3262
|
},
|
|
3144
|
-
options:
|
|
3263
|
+
options: { virtualHost: !isCustomWrapper },
|
|
3145
3264
|
methods: { eh: eventHandler }
|
|
3146
3265
|
}, lifeCycles), { isCustomWrapper });
|
|
3147
3266
|
}
|
|
@@ -3166,12 +3285,7 @@ const nextTick = (cb, ctx) => {
|
|
|
3166
3285
|
*/
|
|
3167
3286
|
function next() {
|
|
3168
3287
|
const pageElement = env.document.getElementById(path);
|
|
3169
|
-
if (pageElement === null || pageElement === void 0 ? void 0 : pageElement.pendingUpdate)
|
|
3170
|
-
var _pageElement$firstChi, _pageElement$firstChi2, _pageElement$firstChi3;
|
|
3171
|
-
(_pageElement$firstChi = (_pageElement$firstChi2 = pageElement.firstChild) === null || _pageElement$firstChi2 === void 0 || (_pageElement$firstChi3 = _pageElement$firstChi2["componentOnReady"]) === null || _pageElement$firstChi3 === void 0 ? void 0 : _pageElement$firstChi3.call(_pageElement$firstChi2).then(() => {
|
|
3172
|
-
timerFunc();
|
|
3173
|
-
})) !== null && _pageElement$firstChi !== void 0 || timerFunc();
|
|
3174
|
-
} else pageElement.enqueueUpdateCallback(cb, ctx);
|
|
3288
|
+
if (pageElement === null || pageElement === void 0 ? void 0 : pageElement.pendingUpdate) pageElement.enqueueUpdateCallback(cb, ctx);
|
|
3175
3289
|
else if (Date.now() - beginTime > TIMEOUT) timerFunc();
|
|
3176
3290
|
else setTimeout(() => next(), 20);
|
|
3177
3291
|
}
|
|
@@ -3210,495 +3324,6 @@ function handleArrayIncludesPolyfill() {
|
|
|
3210
3324
|
} });
|
|
3211
3325
|
}
|
|
3212
3326
|
//#endregion
|
|
3213
|
-
//#region src/polyfill/intersection-observer.ts
|
|
3214
|
-
function handleIntersectionObserverPolyfill() {
|
|
3215
|
-
if ("IntersectionObserver" in window && "IntersectionObserverEntry" in window && "intersectionRatio" in window.IntersectionObserverEntry.prototype) {
|
|
3216
|
-
if (!("isIntersecting" in window.IntersectionObserverEntry.prototype)) Object.defineProperty(window.IntersectionObserverEntry.prototype, "isIntersecting", { get: function() {
|
|
3217
|
-
return this.intersectionRatio > 0;
|
|
3218
|
-
} });
|
|
3219
|
-
} else handleIntersectionObserverObjectPolyfill();
|
|
3220
|
-
}
|
|
3221
|
-
function handleIntersectionObserverObjectPolyfill() {
|
|
3222
|
-
const document = window.document;
|
|
3223
|
-
/**
|
|
3224
|
-
* An IntersectionObserver registry. This registry exists to hold a strong
|
|
3225
|
-
* reference to IntersectionObserver instances currently observing a target
|
|
3226
|
-
* element. Without this registry, instances without another reference may be
|
|
3227
|
-
* garbage collected.
|
|
3228
|
-
*/
|
|
3229
|
-
const registry = [];
|
|
3230
|
-
/**
|
|
3231
|
-
* Creates the global IntersectionObserverEntry constructor.
|
|
3232
|
-
* https://w3c.github.io/IntersectionObserver/#intersection-observer-entry
|
|
3233
|
-
* @param {Object} entry A dictionary of instance properties.
|
|
3234
|
-
* @constructor
|
|
3235
|
-
*/
|
|
3236
|
-
function IntersectionObserverEntry(entry) {
|
|
3237
|
-
this.time = entry.time;
|
|
3238
|
-
this.target = entry.target;
|
|
3239
|
-
this.rootBounds = entry.rootBounds;
|
|
3240
|
-
this.boundingClientRect = entry.boundingClientRect;
|
|
3241
|
-
this.intersectionRect = entry.intersectionRect || getEmptyRect();
|
|
3242
|
-
this.isIntersecting = !!entry.intersectionRect;
|
|
3243
|
-
const targetRect = this.boundingClientRect;
|
|
3244
|
-
const targetArea = targetRect.width * targetRect.height;
|
|
3245
|
-
const intersectionRect = this.intersectionRect;
|
|
3246
|
-
const intersectionArea = intersectionRect.width * intersectionRect.height;
|
|
3247
|
-
if (targetArea) this.intersectionRatio = Number((intersectionArea / targetArea).toFixed(4));
|
|
3248
|
-
else this.intersectionRatio = this.isIntersecting ? 1 : 0;
|
|
3249
|
-
}
|
|
3250
|
-
/**
|
|
3251
|
-
* Creates the global IntersectionObserver constructor.
|
|
3252
|
-
* https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
|
|
3253
|
-
* @param {Function} callback The function to be invoked after intersection
|
|
3254
|
-
* changes have queued. The function is not invoked if the queue has
|
|
3255
|
-
* been emptied by calling the `takeRecords` method.
|
|
3256
|
-
* @param {Object=} opt_options Optional configuration options.
|
|
3257
|
-
* @constructor
|
|
3258
|
-
*/
|
|
3259
|
-
function IntersectionObserver(callback, options = {}) {
|
|
3260
|
-
if (!isFunction(callback)) throw new Error("callback must be a function");
|
|
3261
|
-
if (options.root && options.root.nodeType != 1) throw new Error("root must be an Element");
|
|
3262
|
-
this._checkForIntersections = throttle(this._checkForIntersections.bind(this), this.THROTTLE_TIMEOUT);
|
|
3263
|
-
this._callback = callback;
|
|
3264
|
-
this._observationTargets = [];
|
|
3265
|
-
this._queuedEntries = [];
|
|
3266
|
-
this._rootMarginValues = this._parseRootMargin(options.rootMargin);
|
|
3267
|
-
this.thresholds = this._initThresholds(options.threshold);
|
|
3268
|
-
this.root = options.root || null;
|
|
3269
|
-
this.rootMargin = this._rootMarginValues.map(function(margin) {
|
|
3270
|
-
return margin.value + margin.unit;
|
|
3271
|
-
}).join(" ");
|
|
3272
|
-
}
|
|
3273
|
-
/**
|
|
3274
|
-
* The minimum interval within which the document will be checked for
|
|
3275
|
-
* intersection changes.
|
|
3276
|
-
*/
|
|
3277
|
-
IntersectionObserver.prototype.THROTTLE_TIMEOUT = 100;
|
|
3278
|
-
/**
|
|
3279
|
-
* The frequency in which the polyfill polls for intersection changes.
|
|
3280
|
-
* this can be updated on a per instance basis and must be set prior to
|
|
3281
|
-
* calling `observe` on the first target.
|
|
3282
|
-
*/
|
|
3283
|
-
IntersectionObserver.prototype.POLL_INTERVAL = null;
|
|
3284
|
-
/**
|
|
3285
|
-
* Use a mutation observer on the root element
|
|
3286
|
-
* to detect intersection changes.
|
|
3287
|
-
*/
|
|
3288
|
-
IntersectionObserver.prototype.USE_MUTATION_OBSERVER = true;
|
|
3289
|
-
/**
|
|
3290
|
-
* Starts observing a target element for intersection changes based on
|
|
3291
|
-
* the thresholds values.
|
|
3292
|
-
* @param {Element} target The DOM element to observe.
|
|
3293
|
-
*/
|
|
3294
|
-
IntersectionObserver.prototype.observe = function(target) {
|
|
3295
|
-
if (this._observationTargets.some(function(item) {
|
|
3296
|
-
return item.element == target;
|
|
3297
|
-
})) return;
|
|
3298
|
-
if (!(target && target.nodeType == 1)) throw new Error("target must be an Element");
|
|
3299
|
-
this._registerInstance();
|
|
3300
|
-
this._observationTargets.push({
|
|
3301
|
-
element: target,
|
|
3302
|
-
entry: null
|
|
3303
|
-
});
|
|
3304
|
-
this._monitorIntersections();
|
|
3305
|
-
this._checkForIntersections();
|
|
3306
|
-
};
|
|
3307
|
-
/**
|
|
3308
|
-
* Stops observing a target element for intersection changes.
|
|
3309
|
-
* @param {Element} target The DOM element to observe.
|
|
3310
|
-
*/
|
|
3311
|
-
IntersectionObserver.prototype.unobserve = function(target) {
|
|
3312
|
-
this._observationTargets = this._observationTargets.filter(function(item) {
|
|
3313
|
-
return item.element != target;
|
|
3314
|
-
});
|
|
3315
|
-
if (!this._observationTargets.length) {
|
|
3316
|
-
this._unmonitorIntersections();
|
|
3317
|
-
this._unregisterInstance();
|
|
3318
|
-
}
|
|
3319
|
-
};
|
|
3320
|
-
/**
|
|
3321
|
-
* Stops observing all target elements for intersection changes.
|
|
3322
|
-
*/
|
|
3323
|
-
IntersectionObserver.prototype.disconnect = function() {
|
|
3324
|
-
this._observationTargets = [];
|
|
3325
|
-
this._unmonitorIntersections();
|
|
3326
|
-
this._unregisterInstance();
|
|
3327
|
-
};
|
|
3328
|
-
/**
|
|
3329
|
-
* Returns any queue entries that have not yet been reported to the
|
|
3330
|
-
* callback and clears the queue. This can be used in conjunction with the
|
|
3331
|
-
* callback to obtain the absolute most up-to-date intersection information.
|
|
3332
|
-
* @return {Array} The currently queued entries.
|
|
3333
|
-
*/
|
|
3334
|
-
IntersectionObserver.prototype.takeRecords = function() {
|
|
3335
|
-
const records = this._queuedEntries.slice();
|
|
3336
|
-
this._queuedEntries = [];
|
|
3337
|
-
return records;
|
|
3338
|
-
};
|
|
3339
|
-
/**
|
|
3340
|
-
* Accepts the threshold value from the user configuration object and
|
|
3341
|
-
* returns a sorted array of unique threshold values. If a value is not
|
|
3342
|
-
* between 0 and 1 and error is thrown.
|
|
3343
|
-
* @private
|
|
3344
|
-
* @param {Array|number=} opt_threshold An optional threshold value or
|
|
3345
|
-
* a list of threshold values, defaulting to [0].
|
|
3346
|
-
* @return {Array} A sorted list of unique and valid threshold values.
|
|
3347
|
-
*/
|
|
3348
|
-
IntersectionObserver.prototype._initThresholds = function(opt_threshold) {
|
|
3349
|
-
let threshold = opt_threshold || [0];
|
|
3350
|
-
if (!Array.isArray(threshold)) threshold = [threshold];
|
|
3351
|
-
return threshold.sort().filter(function(t, i, a) {
|
|
3352
|
-
if (!isNumber(t) || isNaN(t) || t < 0 || t > 1) throw new Error("threshold must be a number between 0 and 1 inclusively");
|
|
3353
|
-
return t !== a[i - 1];
|
|
3354
|
-
});
|
|
3355
|
-
};
|
|
3356
|
-
/**
|
|
3357
|
-
* Accepts the rootMargin value from the user configuration object
|
|
3358
|
-
* and returns an array of the four margin values as an object containing
|
|
3359
|
-
* the value and unit properties. If any of the values are not properly
|
|
3360
|
-
* formatted or use a unit other than px or %, and error is thrown.
|
|
3361
|
-
* @private
|
|
3362
|
-
* @param {string=} opt_rootMargin An optional rootMargin value,
|
|
3363
|
-
* defaulting to '0px'.
|
|
3364
|
-
* @return {Array<Object>} An array of margin objects with the keys
|
|
3365
|
-
* value and unit.
|
|
3366
|
-
*/
|
|
3367
|
-
IntersectionObserver.prototype._parseRootMargin = function(opt_rootMargin) {
|
|
3368
|
-
const margins = (opt_rootMargin || "0px").split(/\s+/).map(function(margin) {
|
|
3369
|
-
const parts = /^(-?\d*\.?\d+)(px|%)$/.exec(margin);
|
|
3370
|
-
if (!parts) throw new Error("rootMargin must be specified in pixels or percent");
|
|
3371
|
-
return {
|
|
3372
|
-
value: parseFloat(parts[1]),
|
|
3373
|
-
unit: parts[2]
|
|
3374
|
-
};
|
|
3375
|
-
});
|
|
3376
|
-
margins[1] = margins[1] || margins[0];
|
|
3377
|
-
margins[2] = margins[2] || margins[0];
|
|
3378
|
-
margins[3] = margins[3] || margins[1];
|
|
3379
|
-
return margins;
|
|
3380
|
-
};
|
|
3381
|
-
/**
|
|
3382
|
-
* Starts polling for intersection changes if the polling is not already
|
|
3383
|
-
* happening, and if the page's visibility state is visible.
|
|
3384
|
-
* @private
|
|
3385
|
-
*/
|
|
3386
|
-
IntersectionObserver.prototype._monitorIntersections = function() {
|
|
3387
|
-
if (!this._monitoringIntersections) {
|
|
3388
|
-
this._monitoringIntersections = true;
|
|
3389
|
-
if (this.POLL_INTERVAL) this._monitoringInterval = setInterval(this._checkForIntersections, this.POLL_INTERVAL);
|
|
3390
|
-
else {
|
|
3391
|
-
addEvent(window, "resize", this._checkForIntersections, true);
|
|
3392
|
-
addEvent(document, "scroll", this._checkForIntersections, true);
|
|
3393
|
-
if (this.USE_MUTATION_OBSERVER && "MutationObserver" in window) {
|
|
3394
|
-
this._domObserver = new MutationObserver(this._checkForIntersections);
|
|
3395
|
-
this._domObserver.observe(document, {
|
|
3396
|
-
attributes: true,
|
|
3397
|
-
childList: true,
|
|
3398
|
-
characterData: true,
|
|
3399
|
-
subtree: true
|
|
3400
|
-
});
|
|
3401
|
-
}
|
|
3402
|
-
}
|
|
3403
|
-
}
|
|
3404
|
-
};
|
|
3405
|
-
/**
|
|
3406
|
-
* Stops polling for intersection changes.
|
|
3407
|
-
* @private
|
|
3408
|
-
*/
|
|
3409
|
-
IntersectionObserver.prototype._unmonitorIntersections = function() {
|
|
3410
|
-
if (this._monitoringIntersections) {
|
|
3411
|
-
this._monitoringIntersections = false;
|
|
3412
|
-
clearInterval(this._monitoringInterval);
|
|
3413
|
-
this._monitoringInterval = null;
|
|
3414
|
-
removeEvent(window, "resize", this._checkForIntersections, true);
|
|
3415
|
-
removeEvent(document, "scroll", this._checkForIntersections, true);
|
|
3416
|
-
if (this._domObserver) {
|
|
3417
|
-
this._domObserver.disconnect();
|
|
3418
|
-
this._domObserver = null;
|
|
3419
|
-
}
|
|
3420
|
-
}
|
|
3421
|
-
};
|
|
3422
|
-
/**
|
|
3423
|
-
* Scans each observation target for intersection changes and adds them
|
|
3424
|
-
* to the internal entries queue. If new entries are found, it
|
|
3425
|
-
* schedules the callback to be invoked.
|
|
3426
|
-
* @private
|
|
3427
|
-
*/
|
|
3428
|
-
IntersectionObserver.prototype._checkForIntersections = function() {
|
|
3429
|
-
const rootIsInDom = this._rootIsInDom();
|
|
3430
|
-
const rootRect = rootIsInDom ? this._getRootRect() : getEmptyRect();
|
|
3431
|
-
this._observationTargets.forEach(function(item) {
|
|
3432
|
-
const target = item.element;
|
|
3433
|
-
const targetRect = getBoundingClientRect(target);
|
|
3434
|
-
const rootContainsTarget = this._rootContainsTarget(target);
|
|
3435
|
-
const oldEntry = item.entry;
|
|
3436
|
-
const intersectionRect = rootIsInDom && rootContainsTarget && this._computeTargetAndRootIntersection(target, rootRect);
|
|
3437
|
-
const newEntry = item.entry = new IntersectionObserverEntry({
|
|
3438
|
-
time: now(),
|
|
3439
|
-
target,
|
|
3440
|
-
boundingClientRect: targetRect,
|
|
3441
|
-
rootBounds: rootRect,
|
|
3442
|
-
intersectionRect,
|
|
3443
|
-
intersectionRatio: -1,
|
|
3444
|
-
isIntersecting: false
|
|
3445
|
-
});
|
|
3446
|
-
if (!oldEntry) this._queuedEntries.push(newEntry);
|
|
3447
|
-
else if (rootIsInDom && rootContainsTarget) {
|
|
3448
|
-
if (this._hasCrossedThreshold(oldEntry, newEntry)) this._queuedEntries.push(newEntry);
|
|
3449
|
-
} else if (oldEntry && oldEntry.isIntersecting) this._queuedEntries.push(newEntry);
|
|
3450
|
-
}, this);
|
|
3451
|
-
if (this._queuedEntries.length) this._callback(this.takeRecords(), this);
|
|
3452
|
-
};
|
|
3453
|
-
/**
|
|
3454
|
-
* Accepts a target and root rect computes the intersection between then
|
|
3455
|
-
* following the algorithm in the spec.
|
|
3456
|
-
* TODO(philipwalton): at this time clip-path is not considered.
|
|
3457
|
-
* https://w3c.github.io/IntersectionObserver/#calculate-intersection-rect-algo
|
|
3458
|
-
* @param {Element} target The target DOM element
|
|
3459
|
-
* @param {Object} rootRect The bounding rect of the root after being
|
|
3460
|
-
* expanded by the rootMargin value.
|
|
3461
|
-
* @return {?Object} The final intersection rect object or undefined if no
|
|
3462
|
-
* intersection is found.
|
|
3463
|
-
* @private
|
|
3464
|
-
*/
|
|
3465
|
-
IntersectionObserver.prototype._computeTargetAndRootIntersection = function(target, rootRect) {
|
|
3466
|
-
if (window.getComputedStyle(target).display === "none") return;
|
|
3467
|
-
let intersectionRect = getBoundingClientRect(target);
|
|
3468
|
-
let parent = getParentNode(target);
|
|
3469
|
-
let atRoot = false;
|
|
3470
|
-
while (!atRoot) {
|
|
3471
|
-
let parentRect = null;
|
|
3472
|
-
const parentComputedStyle = parent.nodeType == 1 ? window.getComputedStyle(parent) : {};
|
|
3473
|
-
if (parentComputedStyle.display === "none") return;
|
|
3474
|
-
if (parent == this.root || parent == document) {
|
|
3475
|
-
atRoot = true;
|
|
3476
|
-
parentRect = rootRect;
|
|
3477
|
-
} else if (parent != document.body && parent != document.documentElement && parentComputedStyle.overflow != "visible") parentRect = getBoundingClientRect(parent);
|
|
3478
|
-
if (parentRect) {
|
|
3479
|
-
intersectionRect = computeRectIntersection(parentRect, intersectionRect);
|
|
3480
|
-
if (!intersectionRect) break;
|
|
3481
|
-
}
|
|
3482
|
-
parent = getParentNode(parent);
|
|
3483
|
-
}
|
|
3484
|
-
return intersectionRect;
|
|
3485
|
-
};
|
|
3486
|
-
/**
|
|
3487
|
-
* Returns the root rect after being expanded by the rootMargin value.
|
|
3488
|
-
* @return {Object} The expanded root rect.
|
|
3489
|
-
* @private
|
|
3490
|
-
*/
|
|
3491
|
-
IntersectionObserver.prototype._getRootRect = function() {
|
|
3492
|
-
let rootRect;
|
|
3493
|
-
if (this.root) rootRect = getBoundingClientRect(this.root);
|
|
3494
|
-
else {
|
|
3495
|
-
const html = document.documentElement;
|
|
3496
|
-
const body = document.body;
|
|
3497
|
-
rootRect = {
|
|
3498
|
-
top: 0,
|
|
3499
|
-
left: 0,
|
|
3500
|
-
right: html.clientWidth || body.clientWidth,
|
|
3501
|
-
width: html.clientWidth || body.clientWidth,
|
|
3502
|
-
bottom: html.clientHeight || body.clientHeight,
|
|
3503
|
-
height: html.clientHeight || body.clientHeight
|
|
3504
|
-
};
|
|
3505
|
-
}
|
|
3506
|
-
return this._expandRectByRootMargin(rootRect);
|
|
3507
|
-
};
|
|
3508
|
-
/**
|
|
3509
|
-
* Accepts a rect and expands it by the rootMargin value.
|
|
3510
|
-
* @param {Object} rect The rect object to expand.
|
|
3511
|
-
* @return {Object} The expanded rect.
|
|
3512
|
-
* @private
|
|
3513
|
-
*/
|
|
3514
|
-
IntersectionObserver.prototype._expandRectByRootMargin = function(rect) {
|
|
3515
|
-
const margins = this._rootMarginValues.map(function(margin, i) {
|
|
3516
|
-
return margin.unit === "px" ? margin.value : margin.value * (i % 2 ? rect.width : rect.height) / 100;
|
|
3517
|
-
});
|
|
3518
|
-
const newRect = {
|
|
3519
|
-
top: rect.top - margins[0],
|
|
3520
|
-
right: rect.right + margins[1],
|
|
3521
|
-
bottom: rect.bottom + margins[2],
|
|
3522
|
-
left: rect.left - margins[3]
|
|
3523
|
-
};
|
|
3524
|
-
newRect.width = newRect.right - newRect.left;
|
|
3525
|
-
newRect.height = newRect.bottom - newRect.top;
|
|
3526
|
-
return newRect;
|
|
3527
|
-
};
|
|
3528
|
-
/**
|
|
3529
|
-
* Accepts an old and new entry and returns true if at least one of the
|
|
3530
|
-
* threshold values has been crossed.
|
|
3531
|
-
* @param {?IntersectionObserverEntry} oldEntry The previous entry for a
|
|
3532
|
-
* particular target element or null if no previous entry exists.
|
|
3533
|
-
* @param {IntersectionObserverEntry} newEntry The current entry for a
|
|
3534
|
-
* particular target element.
|
|
3535
|
-
* @return {boolean} Returns true if a any threshold has been crossed.
|
|
3536
|
-
* @private
|
|
3537
|
-
*/
|
|
3538
|
-
IntersectionObserver.prototype._hasCrossedThreshold = function(oldEntry, newEntry) {
|
|
3539
|
-
const oldRatio = oldEntry && oldEntry.isIntersecting ? oldEntry.intersectionRatio || 0 : -1;
|
|
3540
|
-
const newRatio = newEntry.isIntersecting ? newEntry.intersectionRatio || 0 : -1;
|
|
3541
|
-
if (oldRatio === newRatio) return;
|
|
3542
|
-
for (let i = 0; i < this.thresholds.length; i++) {
|
|
3543
|
-
const threshold = this.thresholds[i];
|
|
3544
|
-
if (threshold == oldRatio || threshold == newRatio || threshold < oldRatio !== threshold < newRatio) return true;
|
|
3545
|
-
}
|
|
3546
|
-
};
|
|
3547
|
-
/**
|
|
3548
|
-
* Returns whether or not the root element is an element and is in the DOM.
|
|
3549
|
-
* @return {boolean} True if the root element is an element and is in the DOM.
|
|
3550
|
-
* @private
|
|
3551
|
-
*/
|
|
3552
|
-
IntersectionObserver.prototype._rootIsInDom = function() {
|
|
3553
|
-
return !this.root || containsDeep(document, this.root);
|
|
3554
|
-
};
|
|
3555
|
-
/**
|
|
3556
|
-
* Returns whether or not the target element is a child of root.
|
|
3557
|
-
* @param {Element} target The target element to check.
|
|
3558
|
-
* @return {boolean} True if the target element is a child of root.
|
|
3559
|
-
* @private
|
|
3560
|
-
*/
|
|
3561
|
-
IntersectionObserver.prototype._rootContainsTarget = function(target) {
|
|
3562
|
-
return containsDeep(this.root || document, target);
|
|
3563
|
-
};
|
|
3564
|
-
/**
|
|
3565
|
-
* Adds the instance to the global IntersectionObserver registry if it isn't
|
|
3566
|
-
* already present.
|
|
3567
|
-
* @private
|
|
3568
|
-
*/
|
|
3569
|
-
IntersectionObserver.prototype._registerInstance = function() {
|
|
3570
|
-
if (registry.indexOf(this) < 0) registry.push(this);
|
|
3571
|
-
};
|
|
3572
|
-
/**
|
|
3573
|
-
* Removes the instance from the global IntersectionObserver registry.
|
|
3574
|
-
* @private
|
|
3575
|
-
*/
|
|
3576
|
-
IntersectionObserver.prototype._unregisterInstance = function() {
|
|
3577
|
-
const index = registry.indexOf(this);
|
|
3578
|
-
if (index != -1) registry.splice(index, 1);
|
|
3579
|
-
};
|
|
3580
|
-
/**
|
|
3581
|
-
* Returns the result of the performance.now() method or null in browsers
|
|
3582
|
-
* that don't support the API.
|
|
3583
|
-
* @return {number} The elapsed time since the page was requested.
|
|
3584
|
-
*/
|
|
3585
|
-
function now() {
|
|
3586
|
-
return window.performance && performance.now && performance.now();
|
|
3587
|
-
}
|
|
3588
|
-
/**
|
|
3589
|
-
* Adds an event handler to a DOM node ensuring cross-browser compatibility.
|
|
3590
|
-
* @param {Node} node The DOM node to add the event handler to.
|
|
3591
|
-
* @param {string} event The event name.
|
|
3592
|
-
* @param {Function} fn The event handler to add.
|
|
3593
|
-
* @param {boolean} opt_useCapture Optionally adds the even to the capture
|
|
3594
|
-
* phase. Note: this only works in modern browsers.
|
|
3595
|
-
*/
|
|
3596
|
-
function addEvent(node, event, fn, opt_useCapture) {
|
|
3597
|
-
if (isFunction(node.addEventListener)) node.addEventListener(event, fn, opt_useCapture || false);
|
|
3598
|
-
else if (isFunction(node.attachEvent)) node.attachEvent("on" + event, fn);
|
|
3599
|
-
}
|
|
3600
|
-
/**
|
|
3601
|
-
* Removes a previously added event handler from a DOM node.
|
|
3602
|
-
* @param {Node} node The DOM node to remove the event handler from.
|
|
3603
|
-
* @param {string} event The event name.
|
|
3604
|
-
* @param {Function} fn The event handler to remove.
|
|
3605
|
-
* @param {boolean} opt_useCapture If the event handler was added with this
|
|
3606
|
-
* flag set to true, it should be set to true here in order to remove it.
|
|
3607
|
-
*/
|
|
3608
|
-
function removeEvent(node, event, fn, opt_useCapture) {
|
|
3609
|
-
if (isFunction(node.removeEventListener)) node.removeEventListener(event, fn, opt_useCapture || false);
|
|
3610
|
-
else if (isFunction(node.detatchEvent)) node.detatchEvent("on" + event, fn);
|
|
3611
|
-
}
|
|
3612
|
-
/**
|
|
3613
|
-
* Returns the intersection between two rect objects.
|
|
3614
|
-
* @param {Object} rect1 The first rect.
|
|
3615
|
-
* @param {Object} rect2 The second rect.
|
|
3616
|
-
* @return {?Object} The intersection rect or undefined if no intersection
|
|
3617
|
-
* is found.
|
|
3618
|
-
*/
|
|
3619
|
-
function computeRectIntersection(rect1, rect2) {
|
|
3620
|
-
const top = Math.max(rect1.top, rect2.top);
|
|
3621
|
-
const bottom = Math.min(rect1.bottom, rect2.bottom);
|
|
3622
|
-
const left = Math.max(rect1.left, rect2.left);
|
|
3623
|
-
const right = Math.min(rect1.right, rect2.right);
|
|
3624
|
-
const width = right - left;
|
|
3625
|
-
const height = bottom - top;
|
|
3626
|
-
return width >= 0 && height >= 0 && {
|
|
3627
|
-
top,
|
|
3628
|
-
bottom,
|
|
3629
|
-
left,
|
|
3630
|
-
right,
|
|
3631
|
-
width,
|
|
3632
|
-
height
|
|
3633
|
-
};
|
|
3634
|
-
}
|
|
3635
|
-
/**
|
|
3636
|
-
* Shims the native getBoundingClientRect for compatibility with older IE.
|
|
3637
|
-
* @param {Element} el The element whose bounding rect to get.
|
|
3638
|
-
* @return {Object} The (possibly shimmed) rect of the element.
|
|
3639
|
-
*/
|
|
3640
|
-
function getBoundingClientRect(el) {
|
|
3641
|
-
let rect;
|
|
3642
|
-
try {
|
|
3643
|
-
rect = el.getBoundingClientRect();
|
|
3644
|
-
} catch (err) {}
|
|
3645
|
-
if (!rect) return getEmptyRect();
|
|
3646
|
-
if (!(rect.width && rect.height)) rect = {
|
|
3647
|
-
top: rect.top,
|
|
3648
|
-
right: rect.right,
|
|
3649
|
-
bottom: rect.bottom,
|
|
3650
|
-
left: rect.left,
|
|
3651
|
-
width: rect.right - rect.left,
|
|
3652
|
-
height: rect.bottom - rect.top
|
|
3653
|
-
};
|
|
3654
|
-
return rect;
|
|
3655
|
-
}
|
|
3656
|
-
/**
|
|
3657
|
-
* Returns an empty rect object. An empty rect is returned when an element
|
|
3658
|
-
* is not in the DOM.
|
|
3659
|
-
* @return {Object} The empty rect.
|
|
3660
|
-
*/
|
|
3661
|
-
function getEmptyRect() {
|
|
3662
|
-
return {
|
|
3663
|
-
top: 0,
|
|
3664
|
-
bottom: 0,
|
|
3665
|
-
left: 0,
|
|
3666
|
-
right: 0,
|
|
3667
|
-
width: 0,
|
|
3668
|
-
height: 0
|
|
3669
|
-
};
|
|
3670
|
-
}
|
|
3671
|
-
/**
|
|
3672
|
-
* Checks to see if a parent element contains a child element (including inside
|
|
3673
|
-
* shadow DOM).
|
|
3674
|
-
* @param {Node} parent The parent element.
|
|
3675
|
-
* @param {Node} child The child element.
|
|
3676
|
-
* @return {boolean} True if the parent node contains the child node.
|
|
3677
|
-
*/
|
|
3678
|
-
function containsDeep(parent, child) {
|
|
3679
|
-
let node = child;
|
|
3680
|
-
while (node) {
|
|
3681
|
-
if (node == parent) return true;
|
|
3682
|
-
node = getParentNode(node);
|
|
3683
|
-
}
|
|
3684
|
-
return false;
|
|
3685
|
-
}
|
|
3686
|
-
/**
|
|
3687
|
-
* Gets the parent node of an element or its host element if the parent node
|
|
3688
|
-
* is a shadow root.
|
|
3689
|
-
* @param {Node} node The node whose parent to get.
|
|
3690
|
-
* @return {Node|null} The parent node or null if no parent exists.
|
|
3691
|
-
*/
|
|
3692
|
-
function getParentNode(node) {
|
|
3693
|
-
const parent = node.parentNode;
|
|
3694
|
-
if (parent && parent.nodeType == 11 && parent.host) return parent.host;
|
|
3695
|
-
if (parent && parent.assignedSlot) return parent.assignedSlot.parentNode;
|
|
3696
|
-
return parent;
|
|
3697
|
-
}
|
|
3698
|
-
window.IntersectionObserver = IntersectionObserver;
|
|
3699
|
-
window.IntersectionObserverEntry = IntersectionObserverEntry;
|
|
3700
|
-
}
|
|
3701
|
-
//#endregion
|
|
3702
3327
|
//#region src/polyfill/object.ts
|
|
3703
3328
|
function handleObjectAssignPolyfill() {
|
|
3704
3329
|
if (!isFunction(Object.assign)) Object.assign = function(target) {
|
|
@@ -3765,12 +3390,9 @@ function handlePolyfill() {
|
|
|
3765
3390
|
if (process.env.SUPPORT_TARO_POLYFILL === "enabled" || process.env.SUPPORT_TARO_POLYFILL === "Object" || process.env.SUPPORT_TARO_POLYFILL === "Object.defineProperty") handleObjectDefinePropertyPolyfill();
|
|
3766
3391
|
if (process.env.SUPPORT_TARO_POLYFILL === "enabled" || process.env.SUPPORT_TARO_POLYFILL === "Array" || process.env.SUPPORT_TARO_POLYFILL === "Array.find") handleArrayFindPolyfill();
|
|
3767
3392
|
if (process.env.SUPPORT_TARO_POLYFILL === "enabled" || process.env.SUPPORT_TARO_POLYFILL === "Array" || process.env.SUPPORT_TARO_POLYFILL === "Array.includes") handleArrayIncludesPolyfill();
|
|
3768
|
-
if (process.env.TARO_PLATFORM === "web" && isObject(window)) {
|
|
3769
|
-
if (process.env.SUPPORT_TARO_POLYFILL === "enabled" || process.env.SUPPORT_TARO_POLYFILL === "IntersectionObserver") handleIntersectionObserverPolyfill();
|
|
3770
|
-
}
|
|
3771
3393
|
}
|
|
3772
|
-
if (process.env.SUPPORT_TARO_POLYFILL !== "disabled"
|
|
3394
|
+
if (process.env.SUPPORT_TARO_POLYFILL !== "disabled") handlePolyfill();
|
|
3773
3395
|
//#endregion
|
|
3774
|
-
export { A, APP, BEHAVIORS, BODY, CATCHMOVE, CATCH_VIEW, CHANGE, CLASS, CLICK_VIEW, COMMENT, COMPILE_MODE, CONFIRM, CONTAINER, CONTEXT_ACTIONS, CURRENT_TARGET, CUSTOM_WRAPPER, Current, DATASET, DATE, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, EVENT_CALLBACK_RESULT, EXTERNAL_CLASSES, Events, FOCUS, FormElement, HEAD, HOOKS_APP_ID, HTML, History, ID, INPUT, KEY_CODE, Location, MutationObserver
|
|
3396
|
+
export { A, APP, BEHAVIORS, BODY, CATCHMOVE, CATCH_VIEW, CHANGE, CLASS, CLICK_VIEW, COMMENT, COMPILE_MODE, CONFIRM, CONTAINER, CONTEXT_ACTIONS, CURRENT_TARGET, CUSTOM_WRAPPER, Current, DATASET, DATE, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, EVENT_CALLBACK_RESULT, EXTERNAL_CLASSES, Events, FOCUS, FormElement, HEAD, HOOKS_APP_ID, HTML, History, ID, INPUT, KEY_CODE, Location, 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, TaroURLProvider as URL, URLSearchParams, VALUE, VIEW, addLeadingSlash, _caf as cancelAnimationFrame, convertNumber2PX, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, customWrapperCache, debounce, taroDocumentProvider as document, env, eventCenter, eventHandler, eventSource, extend, getComponentsAlias, taroGetComputedStyleProvider as getComputedStyle, getCurrentInstance, getCurrentPage, getHomePage, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, handlePolyfill, hasBasename, taroHistoryProvider as history, hooks, hydrate, incrementId, injectPageInstance, isComment, isElement, isHasExtractProp, isParentBound, isText, taroLocationProvider as location, nav as navigator, nextTick, now, options, parseUrl, perf, removePageInstance, _raf as requestAnimationFrame, safeExecute, setCurrentApp, shortcutAttr, stringify, stripBasename, stripSuffix, stripTrailing, throttle, whenAppReady, taroWindowProvider as window };
|
|
3775
3397
|
|
|
3776
3398
|
//# sourceMappingURL=runtime.esm.js.map
|