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