lwc 2.12.0 → 2.13.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.
Files changed (43) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +88 -95
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +88 -95
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +2 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +76 -83
  5. package/dist/engine-dom/iife/es5/engine-dom.js +5761 -7323
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +4567 -5868
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +88 -95
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +2 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +76 -83
  11. package/dist/engine-dom/umd/es5/engine-dom.js +5761 -7323
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +4567 -5868
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +88 -95
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +88 -95
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +693 -693
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +693 -693
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +13 -10
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +681 -681
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3725 -4699
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +1 -10
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3600 -4543
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +693 -693
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +13 -10
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +681 -681
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3725 -4699
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +1 -10
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3600 -4543
  30. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  31. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es2017/wire-service.min.js +1 -1
  33. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  34. package/dist/wire-service/iife/es5/wire-service.js +258 -243
  35. package/dist/wire-service/iife/es5/wire-service.min.js +1 -1
  36. package/dist/wire-service/iife/es5/wire-service_debug.js +258 -243
  37. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  38. package/dist/wire-service/umd/es2017/wire-service.min.js +1 -1
  39. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  40. package/dist/wire-service/umd/es5/wire-service.js +258 -243
  41. package/dist/wire-service/umd/es5/wire-service.min.js +1 -1
  42. package/dist/wire-service/umd/es5/wire-service_debug.js +258 -243
  43. package/package.json +7 -7
@@ -149,7 +149,7 @@
149
149
  // We use this to detect symbol support in order to avoid the expensive symbol polyfill. Note that
150
150
  // we can't use typeof since it will fail when transpiling.
151
151
  const hasNativeSymbolSupport = /*@__PURE__*/ (() => Symbol('x').toString() === 'Symbol(x)')();
152
- /** version: 2.12.0 */
152
+ /** version: 2.13.1 */
153
153
 
154
154
  /*
155
155
  * Copyright (c) 2018, salesforce.com, inc.
@@ -456,249 +456,6 @@
456
456
  const eventTargetPrototype = typeof EventTarget !== 'undefined' ? EventTarget.prototype : _Node.prototype;
457
457
  const { addEventListener, dispatchEvent, removeEventListener } = eventTargetPrototype;
458
458
 
459
- /*
460
- * Copyright (c) 2018, salesforce.com, inc.
461
- * All rights reserved.
462
- * SPDX-License-Identifier: MIT
463
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
464
- */
465
- const EventListenerMap = new WeakMap();
466
- const ComposedPathMap = new WeakMap();
467
- function isEventListenerOrEventListenerObject(fnOrObj) {
468
- return (isFunction(fnOrObj) ||
469
- (isObject(fnOrObj) &&
470
- !isNull(fnOrObj) &&
471
- isFunction(fnOrObj.handleEvent)));
472
- }
473
- function shouldInvokeListener(event, target, currentTarget) {
474
- // Subsequent logic assumes that `currentTarget` must be contained in the composed path for the listener to be
475
- // invoked, but this is not always the case. `composedPath()` will sometimes return an empty array, even when the
476
- // listener should be invoked (e.g., a disconnected instance of EventTarget, an instance of XMLHttpRequest, etc).
477
- if (target === currentTarget) {
478
- return true;
479
- }
480
- let composedPath = ComposedPathMap.get(event);
481
- if (isUndefined(composedPath)) {
482
- composedPath = event.composedPath();
483
- ComposedPathMap.set(event, composedPath);
484
- }
485
- return composedPath.includes(currentTarget);
486
- }
487
- function getEventListenerWrapper(fnOrObj) {
488
- if (!isEventListenerOrEventListenerObject(fnOrObj)) {
489
- return fnOrObj;
490
- }
491
- let wrapperFn = EventListenerMap.get(fnOrObj);
492
- if (isUndefined(wrapperFn)) {
493
- wrapperFn = function (event) {
494
- // This function is invoked from an event listener and currentTarget is always defined.
495
- const currentTarget = eventCurrentTargetGetter.call(event);
496
- if (process.env.NODE_ENV !== 'production') {
497
- assert.invariant(isFalse(isSyntheticShadowHost(currentTarget)), 'This routine should not be used to wrap event listeners for host elements and shadow roots.');
498
- }
499
- const actualTarget = getActualTarget(event);
500
- if (!shouldInvokeListener(event, actualTarget, currentTarget)) {
501
- return;
502
- }
503
- return isFunction(fnOrObj)
504
- ? fnOrObj.call(this, event)
505
- : fnOrObj.handleEvent && fnOrObj.handleEvent(event);
506
- };
507
- EventListenerMap.set(fnOrObj, wrapperFn);
508
- }
509
- return wrapperFn;
510
- }
511
-
512
- /*
513
- * Copyright (c) 2018, salesforce.com, inc.
514
- * All rights reserved.
515
- * SPDX-License-Identifier: MIT
516
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
517
- */
518
- const eventToContextMap = new WeakMap();
519
- const customElementToWrappedListeners = new WeakMap();
520
- function getEventMap(elm) {
521
- let listenerInfo = customElementToWrappedListeners.get(elm);
522
- if (isUndefined(listenerInfo)) {
523
- listenerInfo = create(null);
524
- customElementToWrappedListeners.set(elm, listenerInfo);
525
- }
526
- return listenerInfo;
527
- }
528
- /**
529
- * Events dispatched on shadow roots actually end up being dispatched on their hosts. This means that the event.target
530
- * property of events dispatched on shadow roots always resolve to their host. This function understands this
531
- * abstraction and properly returns a reference to the shadow root when appropriate.
532
- */
533
- function getActualTarget(event) {
534
- var _a;
535
- return (_a = eventToShadowRootMap.get(event)) !== null && _a !== void 0 ? _a : eventTargetGetter.call(event);
536
- }
537
- const shadowRootEventListenerMap = new WeakMap();
538
- function getWrappedShadowRootListener(listener) {
539
- if (!isFunction(listener)) {
540
- throw new TypeError(); // avoiding problems with non-valid listeners
541
- }
542
- let shadowRootWrappedListener = shadowRootEventListenerMap.get(listener);
543
- if (isUndefined(shadowRootWrappedListener)) {
544
- shadowRootWrappedListener = function (event) {
545
- // currentTarget is always defined inside an event listener
546
- let currentTarget = eventCurrentTargetGetter.call(event);
547
- // If currentTarget is not an instance of a native shadow root then we're dealing with a
548
- // host element whose synthetic shadow root must be accessed via getShadowRoot().
549
- if (!isInstanceOfNativeShadowRoot(currentTarget)) {
550
- currentTarget = getShadowRoot(currentTarget);
551
- }
552
- const actualTarget = getActualTarget(event);
553
- if (shouldInvokeListener(event, actualTarget, currentTarget)) {
554
- listener.call(currentTarget, event);
555
- }
556
- };
557
- shadowRootWrappedListener.placement = 1 /* SHADOW_ROOT_LISTENER */;
558
- shadowRootEventListenerMap.set(listener, shadowRootWrappedListener);
559
- }
560
- return shadowRootWrappedListener;
561
- }
562
- const customElementEventListenerMap = new WeakMap();
563
- function getWrappedCustomElementListener(listener) {
564
- if (!isFunction(listener)) {
565
- throw new TypeError(); // avoiding problems with non-valid listeners
566
- }
567
- let customElementWrappedListener = customElementEventListenerMap.get(listener);
568
- if (isUndefined(customElementWrappedListener)) {
569
- customElementWrappedListener = function (event) {
570
- // currentTarget is always defined inside an event listener
571
- const currentTarget = eventCurrentTargetGetter.call(event);
572
- const actualTarget = getActualTarget(event);
573
- if (shouldInvokeListener(event, actualTarget, currentTarget)) {
574
- listener.call(currentTarget, event);
575
- }
576
- };
577
- customElementWrappedListener.placement = 0 /* CUSTOM_ELEMENT_LISTENER */;
578
- customElementEventListenerMap.set(listener, customElementWrappedListener);
579
- }
580
- return customElementWrappedListener;
581
- }
582
- function domListener(evt) {
583
- let immediatePropagationStopped = false;
584
- let propagationStopped = false;
585
- const { type, stopImmediatePropagation, stopPropagation } = evt;
586
- // currentTarget is always defined
587
- const currentTarget = eventCurrentTargetGetter.call(evt);
588
- const listenerMap = getEventMap(currentTarget);
589
- const listeners = listenerMap[type]; // it must have listeners at this point
590
- defineProperty(evt, 'stopImmediatePropagation', {
591
- value() {
592
- immediatePropagationStopped = true;
593
- stopImmediatePropagation.call(evt);
594
- },
595
- writable: true,
596
- enumerable: true,
597
- configurable: true,
598
- });
599
- defineProperty(evt, 'stopPropagation', {
600
- value() {
601
- propagationStopped = true;
602
- stopPropagation.call(evt);
603
- },
604
- writable: true,
605
- enumerable: true,
606
- configurable: true,
607
- });
608
- // in case a listener adds or removes other listeners during invocation
609
- const bookkeeping = ArraySlice.call(listeners);
610
- function invokeListenersByPlacement(placement) {
611
- forEach.call(bookkeeping, (listener) => {
612
- if (isFalse(immediatePropagationStopped) && listener.placement === placement) {
613
- // making sure that the listener was not removed from the original listener queue
614
- if (ArrayIndexOf.call(listeners, listener) !== -1) {
615
- // all handlers on the custom element should be called with undefined 'this'
616
- listener.call(undefined, evt);
617
- }
618
- }
619
- });
620
- }
621
- eventToContextMap.set(evt, 1 /* SHADOW_ROOT_LISTENER */);
622
- invokeListenersByPlacement(1 /* SHADOW_ROOT_LISTENER */);
623
- if (isFalse(immediatePropagationStopped) && isFalse(propagationStopped)) {
624
- // doing the second iteration only if the first one didn't interrupt the event propagation
625
- eventToContextMap.set(evt, 0 /* CUSTOM_ELEMENT_LISTENER */);
626
- invokeListenersByPlacement(0 /* CUSTOM_ELEMENT_LISTENER */);
627
- }
628
- eventToContextMap.set(evt, 2 /* UNKNOWN_LISTENER */);
629
- }
630
- function attachDOMListener(elm, type, wrappedListener) {
631
- const listenerMap = getEventMap(elm);
632
- let cmpEventHandlers = listenerMap[type];
633
- if (isUndefined(cmpEventHandlers)) {
634
- cmpEventHandlers = listenerMap[type] = [];
635
- }
636
- // Prevent identical listeners from subscribing to the same event type.
637
- // TODO [#1824]: Options will also play a factor when we introduce support for them (#1824).
638
- if (ArrayIndexOf.call(cmpEventHandlers, wrappedListener) !== -1) {
639
- return;
640
- }
641
- // only add to DOM if there is no other listener on the same placement yet
642
- if (cmpEventHandlers.length === 0) {
643
- // super.addEventListener() - this will not work on
644
- addEventListener.call(elm, type, domListener);
645
- }
646
- ArrayPush.call(cmpEventHandlers, wrappedListener);
647
- }
648
- function detachDOMListener(elm, type, wrappedListener) {
649
- const listenerMap = getEventMap(elm);
650
- let p;
651
- let listeners;
652
- if (!isUndefined((listeners = listenerMap[type])) &&
653
- (p = ArrayIndexOf.call(listeners, wrappedListener)) !== -1) {
654
- ArraySplice.call(listeners, p, 1);
655
- // only remove from DOM if there is no other listener on the same placement
656
- if (listeners.length === 0) {
657
- removeEventListener.call(elm, type, domListener);
658
- }
659
- }
660
- }
661
- function addCustomElementEventListener(type, listener, _options) {
662
- if (process.env.NODE_ENV !== 'production') {
663
- if (!isFunction(listener)) {
664
- throw new TypeError(`Invalid second argument for Element.addEventListener() in ${toString(this)} for event "${type}". Expected an EventListener but received ${listener}.`);
665
- }
666
- }
667
- // TODO [#1824]: Lift this restriction on the option parameter
668
- if (isFunction(listener)) {
669
- const wrappedListener = getWrappedCustomElementListener(listener);
670
- attachDOMListener(this, type, wrappedListener);
671
- }
672
- }
673
- function removeCustomElementEventListener(type, listener, _options) {
674
- // TODO [#1824]: Lift this restriction on the option parameter
675
- if (isFunction(listener)) {
676
- const wrappedListener = getWrappedCustomElementListener(listener);
677
- detachDOMListener(this, type, wrappedListener);
678
- }
679
- }
680
- function addShadowRootEventListener(sr, type, listener, _options) {
681
- if (process.env.NODE_ENV !== 'production') {
682
- if (!isFunction(listener)) {
683
- throw new TypeError(`Invalid second argument for ShadowRoot.addEventListener() in ${toString(sr)} for event "${type}". Expected an EventListener but received ${listener}.`);
684
- }
685
- }
686
- // TODO [#1824]: Lift this restriction on the option parameter
687
- if (isFunction(listener)) {
688
- const elm = getHost(sr);
689
- const wrappedListener = getWrappedShadowRootListener(listener);
690
- attachDOMListener(elm, type, wrappedListener);
691
- }
692
- }
693
- function removeShadowRootEventListener(sr, type, listener, _options) {
694
- // TODO [#1824]: Lift this restriction on the option parameter
695
- if (isFunction(listener)) {
696
- const elm = getHost(sr);
697
- const wrappedListener = getWrappedShadowRootListener(listener);
698
- detachDOMListener(elm, type, wrappedListener);
699
- }
700
- }
701
-
702
459
  /*
703
460
  * Copyright (c) 2018, salesforce.com, inc.
704
461
  * All rights reserved.
@@ -962,19 +719,136 @@
962
719
  * SPDX-License-Identifier: MIT
963
720
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
964
721
  */
965
- function getTextContent(node) {
966
- switch (node.nodeType) {
967
- case ELEMENT_NODE: {
968
- const childNodes = getFilteredChildNodes(node);
969
- let content = '';
970
- for (let i = 0, len = childNodes.length; i < len; i += 1) {
971
- const currentNode = childNodes[i];
972
- if (currentNode.nodeType !== COMMENT_NODE) {
973
- content += getTextContent(currentNode);
974
- }
975
- }
976
- return content;
977
- }
722
+ function getInnerHTML(node) {
723
+ let s = '';
724
+ const childNodes = getFilteredChildNodes(node);
725
+ for (let i = 0, len = childNodes.length; i < len; i += 1) {
726
+ s += getOuterHTML(childNodes[i]);
727
+ }
728
+ return s;
729
+ }
730
+
731
+ /*
732
+ * Copyright (c) 2018, salesforce.com, inc.
733
+ * All rights reserved.
734
+ * SPDX-License-Identifier: MIT
735
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
736
+ */
737
+ // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#escapingString
738
+ const escapeAttrRegExp = /[&\u00A0"]/g;
739
+ const escapeDataRegExp = /[&\u00A0<>]/g;
740
+ const { replace, toLowerCase } = String.prototype;
741
+ function escapeReplace(c) {
742
+ switch (c) {
743
+ case '&':
744
+ return '&amp;';
745
+ case '<':
746
+ return '&lt;';
747
+ case '>':
748
+ return '&gt;';
749
+ case '"':
750
+ return '&quot;';
751
+ case '\u00A0':
752
+ return '&nbsp;';
753
+ default:
754
+ return '';
755
+ }
756
+ }
757
+ function escapeAttr(s) {
758
+ return replace.call(s, escapeAttrRegExp, escapeReplace);
759
+ }
760
+ function escapeData(s) {
761
+ return replace.call(s, escapeDataRegExp, escapeReplace);
762
+ }
763
+ // http://www.whatwg.org/specs/web-apps/current-work/#void-elements
764
+ const voidElements = new Set([
765
+ 'AREA',
766
+ 'BASE',
767
+ 'BR',
768
+ 'COL',
769
+ 'COMMAND',
770
+ 'EMBED',
771
+ 'HR',
772
+ 'IMG',
773
+ 'INPUT',
774
+ 'KEYGEN',
775
+ 'LINK',
776
+ 'META',
777
+ 'PARAM',
778
+ 'SOURCE',
779
+ 'TRACK',
780
+ 'WBR',
781
+ ]);
782
+ const plaintextParents = new Set([
783
+ 'STYLE',
784
+ 'SCRIPT',
785
+ 'XMP',
786
+ 'IFRAME',
787
+ 'NOEMBED',
788
+ 'NOFRAMES',
789
+ 'PLAINTEXT',
790
+ 'NOSCRIPT',
791
+ ]);
792
+ function getOuterHTML(node) {
793
+ switch (node.nodeType) {
794
+ case ELEMENT_NODE: {
795
+ const { attributes: attrs } = node;
796
+ const tagName = tagNameGetter.call(node);
797
+ let s = '<' + toLowerCase.call(tagName);
798
+ for (let i = 0, attr; (attr = attrs[i]); i++) {
799
+ s += ' ' + attr.name + '="' + escapeAttr(attr.value) + '"';
800
+ }
801
+ s += '>';
802
+ if (voidElements.has(tagName)) {
803
+ return s;
804
+ }
805
+ return s + getInnerHTML(node) + '</' + toLowerCase.call(tagName) + '>';
806
+ }
807
+ case TEXT_NODE: {
808
+ const { data, parentNode } = node;
809
+ if (parentNode instanceof Element &&
810
+ plaintextParents.has(tagNameGetter.call(parentNode))) {
811
+ return data;
812
+ }
813
+ return escapeData(data);
814
+ }
815
+ case CDATA_SECTION_NODE: {
816
+ return `<!CDATA[[${node.data}]]>`;
817
+ }
818
+ case PROCESSING_INSTRUCTION_NODE: {
819
+ return `<?${node.target} ${node.data}?>`;
820
+ }
821
+ case COMMENT_NODE: {
822
+ return `<!--${node.data}-->`;
823
+ }
824
+ default: {
825
+ // intentionally ignoring unknown node types
826
+ // Note: since this routine is always invoked for childNodes
827
+ // we can safety ignore type 9, 10 and 99 (document, fragment and doctype)
828
+ return '';
829
+ }
830
+ }
831
+ }
832
+
833
+ /*
834
+ * Copyright (c) 2018, salesforce.com, inc.
835
+ * All rights reserved.
836
+ * SPDX-License-Identifier: MIT
837
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
838
+ */
839
+ function getTextContent(node) {
840
+ switch (node.nodeType) {
841
+ case ELEMENT_NODE: {
842
+ const childNodes = getFilteredChildNodes(node);
843
+ let content = '';
844
+ for (let i = 0, len = childNodes.length; i < len; i += 1) {
845
+ const currentNode = childNodes[i];
846
+ if (currentNode.nodeType !== COMMENT_NODE) {
847
+ content += getTextContent(currentNode);
848
+ }
849
+ }
850
+ return content;
851
+ }
978
852
  default:
979
853
  return node.nodeValue;
980
854
  }
@@ -1096,6 +970,71 @@
1096
970
  return nodeList;
1097
971
  }
1098
972
 
973
+ /*
974
+ * Copyright (c) 2018, salesforce.com, inc.
975
+ * All rights reserved.
976
+ * SPDX-License-Identifier: MIT
977
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
978
+ */
979
+ // Walk up the DOM tree, collecting all shadow roots plus the document root
980
+ function getAllRootNodes(node) {
981
+ var _a;
982
+ const rootNodes = [];
983
+ let currentRootNode = node.getRootNode();
984
+ while (!isUndefined(currentRootNode)) {
985
+ rootNodes.push(currentRootNode);
986
+ currentRootNode = (_a = currentRootNode.host) === null || _a === void 0 ? void 0 : _a.getRootNode();
987
+ }
988
+ return rootNodes;
989
+ }
990
+ // Keep searching up the host tree until we find an element that is within the immediate shadow root
991
+ const findAncestorHostInImmediateShadowRoot = (rootNode, targetRootNode) => {
992
+ let host;
993
+ while (!isUndefined((host = rootNode.host))) {
994
+ const thisRootNode = host.getRootNode();
995
+ if (thisRootNode === targetRootNode) {
996
+ return host;
997
+ }
998
+ rootNode = thisRootNode;
999
+ }
1000
+ };
1001
+ function fauxElementsFromPoint(context, doc, left, top) {
1002
+ const elements = elementsFromPoint.call(doc, left, top);
1003
+ const result = [];
1004
+ const rootNodes = getAllRootNodes(context);
1005
+ // Filter the elements array to only include those elements that are in this shadow root or in one of its
1006
+ // ancestor roots. This matches Chrome and Safari's implementation (but not Firefox's, which only includes
1007
+ // elements in the immediate shadow root: https://crbug.com/1207863#c4).
1008
+ if (!isNull(elements)) {
1009
+ // can be null in IE https://developer.mozilla.org/en-US/docs/Web/API/Document/elementsFromPoint#browser_compatibility
1010
+ for (let i = 0; i < elements.length; i++) {
1011
+ const element = elements[i];
1012
+ if (isSyntheticSlotElement(element)) {
1013
+ continue;
1014
+ }
1015
+ const elementRootNode = element.getRootNode();
1016
+ if (ArrayIndexOf.call(rootNodes, elementRootNode) !== -1) {
1017
+ ArrayPush.call(result, element);
1018
+ continue;
1019
+ }
1020
+ // In cases where the host element is not visible but its shadow descendants are, then
1021
+ // we may get the shadow descendant instead of the host element here. (The
1022
+ // browser doesn't know the difference in synthetic shadow DOM.)
1023
+ // In native shadow DOM, however, elementsFromPoint would return the host but not
1024
+ // the child. So we need to detect if this shadow element's host is accessible from
1025
+ // the context's shadow root. Note we also need to be careful not to add the host
1026
+ // multiple times.
1027
+ const ancestorHost = findAncestorHostInImmediateShadowRoot(elementRootNode, rootNodes[0]);
1028
+ if (!isUndefined(ancestorHost) &&
1029
+ ArrayIndexOf.call(elements, ancestorHost) === -1 &&
1030
+ ArrayIndexOf.call(result, ancestorHost) === -1) {
1031
+ ArrayPush.call(result, ancestorHost);
1032
+ }
1033
+ }
1034
+ }
1035
+ return result;
1036
+ }
1037
+
1099
1038
  /*
1100
1039
  * Copyright (c) 2018, salesforce.com, inc.
1101
1040
  * All rights reserved.
@@ -1133,167 +1072,50 @@
1133
1072
  enumerable: true,
1134
1073
  configurable: true,
1135
1074
  value(name) {
1136
- if (name === '') {
1137
- return null;
1138
- }
1139
- const items = Items.get(this);
1140
- for (let i = 0, len = items.length; i < len; i++) {
1141
- const item = items[len];
1142
- if (name === getAttribute.call(item, 'id') ||
1143
- name === getAttribute.call(item, 'name')) {
1144
- return item;
1145
- }
1146
- }
1147
- return null;
1148
- },
1149
- },
1150
- [Symbol.toStringTag]: {
1151
- configurable: true,
1152
- get() {
1153
- return 'HTMLCollection';
1154
- },
1155
- },
1156
- // IE11 doesn't support Symbol.toStringTag, in which case we
1157
- // provide the regular toString method.
1158
- toString: {
1159
- writable: true,
1160
- configurable: true,
1161
- value() {
1162
- return '[object HTMLCollection]';
1163
- },
1164
- },
1165
- });
1166
- // prototype inheritance dance
1167
- setPrototypeOf(StaticHTMLCollection, HTMLCollection);
1168
- function createStaticHTMLCollection(items) {
1169
- const collection = create(StaticHTMLCollection.prototype);
1170
- Items.set(collection, items);
1171
- // setting static indexes
1172
- forEach.call(items, (item, index) => {
1173
- defineProperty(collection, index, {
1174
- value: item,
1175
- enumerable: true,
1176
- configurable: true,
1177
- });
1178
- });
1179
- return collection;
1180
- }
1181
-
1182
- /*
1183
- * Copyright (c) 2018, salesforce.com, inc.
1184
- * All rights reserved.
1185
- * SPDX-License-Identifier: MIT
1186
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1187
- */
1188
- function getInnerHTML(node) {
1189
- let s = '';
1190
- const childNodes = getFilteredChildNodes(node);
1191
- for (let i = 0, len = childNodes.length; i < len; i += 1) {
1192
- s += getOuterHTML(childNodes[i]);
1193
- }
1194
- return s;
1195
- }
1196
-
1197
- /*
1198
- * Copyright (c) 2018, salesforce.com, inc.
1199
- * All rights reserved.
1200
- * SPDX-License-Identifier: MIT
1201
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1202
- */
1203
- // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#escapingString
1204
- const escapeAttrRegExp = /[&\u00A0"]/g;
1205
- const escapeDataRegExp = /[&\u00A0<>]/g;
1206
- const { replace, toLowerCase } = String.prototype;
1207
- function escapeReplace(c) {
1208
- switch (c) {
1209
- case '&':
1210
- return '&amp;';
1211
- case '<':
1212
- return '&lt;';
1213
- case '>':
1214
- return '&gt;';
1215
- case '"':
1216
- return '&quot;';
1217
- case '\u00A0':
1218
- return '&nbsp;';
1219
- default:
1220
- return '';
1221
- }
1222
- }
1223
- function escapeAttr(s) {
1224
- return replace.call(s, escapeAttrRegExp, escapeReplace);
1225
- }
1226
- function escapeData(s) {
1227
- return replace.call(s, escapeDataRegExp, escapeReplace);
1228
- }
1229
- // http://www.whatwg.org/specs/web-apps/current-work/#void-elements
1230
- const voidElements = new Set([
1231
- 'AREA',
1232
- 'BASE',
1233
- 'BR',
1234
- 'COL',
1235
- 'COMMAND',
1236
- 'EMBED',
1237
- 'HR',
1238
- 'IMG',
1239
- 'INPUT',
1240
- 'KEYGEN',
1241
- 'LINK',
1242
- 'META',
1243
- 'PARAM',
1244
- 'SOURCE',
1245
- 'TRACK',
1246
- 'WBR',
1247
- ]);
1248
- const plaintextParents = new Set([
1249
- 'STYLE',
1250
- 'SCRIPT',
1251
- 'XMP',
1252
- 'IFRAME',
1253
- 'NOEMBED',
1254
- 'NOFRAMES',
1255
- 'PLAINTEXT',
1256
- 'NOSCRIPT',
1257
- ]);
1258
- function getOuterHTML(node) {
1259
- switch (node.nodeType) {
1260
- case ELEMENT_NODE: {
1261
- const { attributes: attrs } = node;
1262
- const tagName = tagNameGetter.call(node);
1263
- let s = '<' + toLowerCase.call(tagName);
1264
- for (let i = 0, attr; (attr = attrs[i]); i++) {
1265
- s += ' ' + attr.name + '="' + escapeAttr(attr.value) + '"';
1266
- }
1267
- s += '>';
1268
- if (voidElements.has(tagName)) {
1269
- return s;
1270
- }
1271
- return s + getInnerHTML(node) + '</' + toLowerCase.call(tagName) + '>';
1272
- }
1273
- case TEXT_NODE: {
1274
- const { data, parentNode } = node;
1275
- if (parentNode instanceof Element &&
1276
- plaintextParents.has(tagNameGetter.call(parentNode))) {
1277
- return data;
1278
- }
1279
- return escapeData(data);
1280
- }
1281
- case CDATA_SECTION_NODE: {
1282
- return `<!CDATA[[${node.data}]]>`;
1283
- }
1284
- case PROCESSING_INSTRUCTION_NODE: {
1285
- return `<?${node.target} ${node.data}?>`;
1286
- }
1287
- case COMMENT_NODE: {
1288
- return `<!--${node.data}-->`;
1289
- }
1290
- default: {
1291
- // intentionally ignoring unknown node types
1292
- // Note: since this routine is always invoked for childNodes
1293
- // we can safety ignore type 9, 10 and 99 (document, fragment and doctype)
1294
- return '';
1295
- }
1296
- }
1075
+ if (name === '') {
1076
+ return null;
1077
+ }
1078
+ const items = Items.get(this);
1079
+ for (let i = 0, len = items.length; i < len; i++) {
1080
+ const item = items[len];
1081
+ if (name === getAttribute.call(item, 'id') ||
1082
+ name === getAttribute.call(item, 'name')) {
1083
+ return item;
1084
+ }
1085
+ }
1086
+ return null;
1087
+ },
1088
+ },
1089
+ [Symbol.toStringTag]: {
1090
+ configurable: true,
1091
+ get() {
1092
+ return 'HTMLCollection';
1093
+ },
1094
+ },
1095
+ // IE11 doesn't support Symbol.toStringTag, in which case we
1096
+ // provide the regular toString method.
1097
+ toString: {
1098
+ writable: true,
1099
+ configurable: true,
1100
+ value() {
1101
+ return '[object HTMLCollection]';
1102
+ },
1103
+ },
1104
+ });
1105
+ // prototype inheritance dance
1106
+ setPrototypeOf(StaticHTMLCollection, HTMLCollection);
1107
+ function createStaticHTMLCollection(items) {
1108
+ const collection = create(StaticHTMLCollection.prototype);
1109
+ Items.set(collection, items);
1110
+ // setting static indexes
1111
+ forEach.call(items, (item, index) => {
1112
+ defineProperty(collection, index, {
1113
+ value: item,
1114
+ enumerable: true,
1115
+ configurable: true,
1116
+ });
1117
+ });
1118
+ return collection;
1297
1119
  }
1298
1120
 
1299
1121
  /**
@@ -1303,7 +1125,7 @@
1303
1125
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
1304
1126
  }
1305
1127
  const runtimeFlags = _globalThis.lwcRuntimeFlags;
1306
- /** version: 2.12.0 */
1128
+ /** version: 2.13.1 */
1307
1129
 
1308
1130
  /*
1309
1131
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1776,63 +1598,241 @@
1776
1598
  * SPDX-License-Identifier: MIT
1777
1599
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1778
1600
  */
1779
- // Walk up the DOM tree, collecting all shadow roots plus the document root
1780
- function getAllRootNodes(node) {
1601
+ const EventListenerMap = new WeakMap();
1602
+ const ComposedPathMap = new WeakMap();
1603
+ function isEventListenerOrEventListenerObject(fnOrObj) {
1604
+ return (isFunction(fnOrObj) ||
1605
+ (isObject(fnOrObj) &&
1606
+ !isNull(fnOrObj) &&
1607
+ isFunction(fnOrObj.handleEvent)));
1608
+ }
1609
+ function shouldInvokeListener(event, target, currentTarget) {
1610
+ // Subsequent logic assumes that `currentTarget` must be contained in the composed path for the listener to be
1611
+ // invoked, but this is not always the case. `composedPath()` will sometimes return an empty array, even when the
1612
+ // listener should be invoked (e.g., a disconnected instance of EventTarget, an instance of XMLHttpRequest, etc).
1613
+ if (target === currentTarget) {
1614
+ return true;
1615
+ }
1616
+ let composedPath = ComposedPathMap.get(event);
1617
+ if (isUndefined(composedPath)) {
1618
+ composedPath = event.composedPath();
1619
+ ComposedPathMap.set(event, composedPath);
1620
+ }
1621
+ return composedPath.includes(currentTarget);
1622
+ }
1623
+ function getEventListenerWrapper(fnOrObj) {
1624
+ if (!isEventListenerOrEventListenerObject(fnOrObj)) {
1625
+ return fnOrObj;
1626
+ }
1627
+ let wrapperFn = EventListenerMap.get(fnOrObj);
1628
+ if (isUndefined(wrapperFn)) {
1629
+ wrapperFn = function (event) {
1630
+ // This function is invoked from an event listener and currentTarget is always defined.
1631
+ const currentTarget = eventCurrentTargetGetter.call(event);
1632
+ if (process.env.NODE_ENV !== 'production') {
1633
+ assert.invariant(isFalse(isSyntheticShadowHost(currentTarget)), 'This routine should not be used to wrap event listeners for host elements and shadow roots.');
1634
+ }
1635
+ const actualTarget = getActualTarget(event);
1636
+ if (!shouldInvokeListener(event, actualTarget, currentTarget)) {
1637
+ return;
1638
+ }
1639
+ return isFunction(fnOrObj)
1640
+ ? fnOrObj.call(this, event)
1641
+ : fnOrObj.handleEvent && fnOrObj.handleEvent(event);
1642
+ };
1643
+ EventListenerMap.set(fnOrObj, wrapperFn);
1644
+ }
1645
+ return wrapperFn;
1646
+ }
1647
+
1648
+ /*
1649
+ * Copyright (c) 2018, salesforce.com, inc.
1650
+ * All rights reserved.
1651
+ * SPDX-License-Identifier: MIT
1652
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1653
+ */
1654
+ const eventToContextMap = new WeakMap();
1655
+ const customElementToWrappedListeners = new WeakMap();
1656
+ function getEventMap(elm) {
1657
+ let listenerInfo = customElementToWrappedListeners.get(elm);
1658
+ if (isUndefined(listenerInfo)) {
1659
+ listenerInfo = create(null);
1660
+ customElementToWrappedListeners.set(elm, listenerInfo);
1661
+ }
1662
+ return listenerInfo;
1663
+ }
1664
+ /**
1665
+ * Events dispatched on shadow roots actually end up being dispatched on their hosts. This means that the event.target
1666
+ * property of events dispatched on shadow roots always resolve to their host. This function understands this
1667
+ * abstraction and properly returns a reference to the shadow root when appropriate.
1668
+ */
1669
+ function getActualTarget(event) {
1781
1670
  var _a;
1782
- const rootNodes = [];
1783
- let currentRootNode = node.getRootNode();
1784
- while (!isUndefined(currentRootNode)) {
1785
- rootNodes.push(currentRootNode);
1786
- currentRootNode = (_a = currentRootNode.host) === null || _a === void 0 ? void 0 : _a.getRootNode();
1671
+ return (_a = eventToShadowRootMap.get(event)) !== null && _a !== void 0 ? _a : eventTargetGetter.call(event);
1672
+ }
1673
+ const shadowRootEventListenerMap = new WeakMap();
1674
+ function getWrappedShadowRootListener(listener) {
1675
+ if (!isFunction(listener)) {
1676
+ throw new TypeError(); // avoiding problems with non-valid listeners
1677
+ }
1678
+ let shadowRootWrappedListener = shadowRootEventListenerMap.get(listener);
1679
+ if (isUndefined(shadowRootWrappedListener)) {
1680
+ shadowRootWrappedListener = function (event) {
1681
+ // currentTarget is always defined inside an event listener
1682
+ let currentTarget = eventCurrentTargetGetter.call(event);
1683
+ // If currentTarget is not an instance of a native shadow root then we're dealing with a
1684
+ // host element whose synthetic shadow root must be accessed via getShadowRoot().
1685
+ if (!isInstanceOfNativeShadowRoot(currentTarget)) {
1686
+ currentTarget = getShadowRoot(currentTarget);
1687
+ }
1688
+ const actualTarget = getActualTarget(event);
1689
+ if (shouldInvokeListener(event, actualTarget, currentTarget)) {
1690
+ listener.call(currentTarget, event);
1691
+ }
1692
+ };
1693
+ shadowRootWrappedListener.placement = 1 /* SHADOW_ROOT_LISTENER */;
1694
+ shadowRootEventListenerMap.set(listener, shadowRootWrappedListener);
1695
+ }
1696
+ return shadowRootWrappedListener;
1697
+ }
1698
+ const customElementEventListenerMap = new WeakMap();
1699
+ function getWrappedCustomElementListener(listener) {
1700
+ if (!isFunction(listener)) {
1701
+ throw new TypeError(); // avoiding problems with non-valid listeners
1702
+ }
1703
+ let customElementWrappedListener = customElementEventListenerMap.get(listener);
1704
+ if (isUndefined(customElementWrappedListener)) {
1705
+ customElementWrappedListener = function (event) {
1706
+ // currentTarget is always defined inside an event listener
1707
+ const currentTarget = eventCurrentTargetGetter.call(event);
1708
+ const actualTarget = getActualTarget(event);
1709
+ if (shouldInvokeListener(event, actualTarget, currentTarget)) {
1710
+ listener.call(currentTarget, event);
1711
+ }
1712
+ };
1713
+ customElementWrappedListener.placement = 0 /* CUSTOM_ELEMENT_LISTENER */;
1714
+ customElementEventListenerMap.set(listener, customElementWrappedListener);
1715
+ }
1716
+ return customElementWrappedListener;
1717
+ }
1718
+ function domListener(evt) {
1719
+ let immediatePropagationStopped = false;
1720
+ let propagationStopped = false;
1721
+ const { type, stopImmediatePropagation, stopPropagation } = evt;
1722
+ // currentTarget is always defined
1723
+ const currentTarget = eventCurrentTargetGetter.call(evt);
1724
+ const listenerMap = getEventMap(currentTarget);
1725
+ const listeners = listenerMap[type]; // it must have listeners at this point
1726
+ defineProperty(evt, 'stopImmediatePropagation', {
1727
+ value() {
1728
+ immediatePropagationStopped = true;
1729
+ stopImmediatePropagation.call(evt);
1730
+ },
1731
+ writable: true,
1732
+ enumerable: true,
1733
+ configurable: true,
1734
+ });
1735
+ defineProperty(evt, 'stopPropagation', {
1736
+ value() {
1737
+ propagationStopped = true;
1738
+ stopPropagation.call(evt);
1739
+ },
1740
+ writable: true,
1741
+ enumerable: true,
1742
+ configurable: true,
1743
+ });
1744
+ // in case a listener adds or removes other listeners during invocation
1745
+ const bookkeeping = ArraySlice.call(listeners);
1746
+ function invokeListenersByPlacement(placement) {
1747
+ forEach.call(bookkeeping, (listener) => {
1748
+ if (isFalse(immediatePropagationStopped) && listener.placement === placement) {
1749
+ // making sure that the listener was not removed from the original listener queue
1750
+ if (ArrayIndexOf.call(listeners, listener) !== -1) {
1751
+ // all handlers on the custom element should be called with undefined 'this'
1752
+ listener.call(undefined, evt);
1753
+ }
1754
+ }
1755
+ });
1756
+ }
1757
+ eventToContextMap.set(evt, 1 /* SHADOW_ROOT_LISTENER */);
1758
+ invokeListenersByPlacement(1 /* SHADOW_ROOT_LISTENER */);
1759
+ if (isFalse(immediatePropagationStopped) && isFalse(propagationStopped)) {
1760
+ // doing the second iteration only if the first one didn't interrupt the event propagation
1761
+ eventToContextMap.set(evt, 0 /* CUSTOM_ELEMENT_LISTENER */);
1762
+ invokeListenersByPlacement(0 /* CUSTOM_ELEMENT_LISTENER */);
1763
+ }
1764
+ eventToContextMap.set(evt, 2 /* UNKNOWN_LISTENER */);
1765
+ }
1766
+ function attachDOMListener(elm, type, wrappedListener) {
1767
+ const listenerMap = getEventMap(elm);
1768
+ let cmpEventHandlers = listenerMap[type];
1769
+ if (isUndefined(cmpEventHandlers)) {
1770
+ cmpEventHandlers = listenerMap[type] = [];
1771
+ }
1772
+ // Prevent identical listeners from subscribing to the same event type.
1773
+ // TODO [#1824]: Options will also play a factor when we introduce support for them (#1824).
1774
+ if (ArrayIndexOf.call(cmpEventHandlers, wrappedListener) !== -1) {
1775
+ return;
1776
+ }
1777
+ // only add to DOM if there is no other listener on the same placement yet
1778
+ if (cmpEventHandlers.length === 0) {
1779
+ // super.addEventListener() - this will not work on
1780
+ addEventListener.call(elm, type, domListener);
1781
+ }
1782
+ ArrayPush.call(cmpEventHandlers, wrappedListener);
1783
+ }
1784
+ function detachDOMListener(elm, type, wrappedListener) {
1785
+ const listenerMap = getEventMap(elm);
1786
+ let p;
1787
+ let listeners;
1788
+ if (!isUndefined((listeners = listenerMap[type])) &&
1789
+ (p = ArrayIndexOf.call(listeners, wrappedListener)) !== -1) {
1790
+ ArraySplice.call(listeners, p, 1);
1791
+ // only remove from DOM if there is no other listener on the same placement
1792
+ if (listeners.length === 0) {
1793
+ removeEventListener.call(elm, type, domListener);
1794
+ }
1795
+ }
1796
+ }
1797
+ function addCustomElementEventListener(type, listener, _options) {
1798
+ if (process.env.NODE_ENV !== 'production') {
1799
+ if (!isFunction(listener)) {
1800
+ throw new TypeError(`Invalid second argument for Element.addEventListener() in ${toString(this)} for event "${type}". Expected an EventListener but received ${listener}.`);
1801
+ }
1802
+ }
1803
+ // TODO [#1824]: Lift this restriction on the option parameter
1804
+ if (isFunction(listener)) {
1805
+ const wrappedListener = getWrappedCustomElementListener(listener);
1806
+ attachDOMListener(this, type, wrappedListener);
1787
1807
  }
1788
- return rootNodes;
1789
1808
  }
1790
- // Keep searching up the host tree until we find an element that is within the immediate shadow root
1791
- const findAncestorHostInImmediateShadowRoot = (rootNode, targetRootNode) => {
1792
- let host;
1793
- while (!isUndefined((host = rootNode.host))) {
1794
- const thisRootNode = host.getRootNode();
1795
- if (thisRootNode === targetRootNode) {
1796
- return host;
1797
- }
1798
- rootNode = thisRootNode;
1809
+ function removeCustomElementEventListener(type, listener, _options) {
1810
+ // TODO [#1824]: Lift this restriction on the option parameter
1811
+ if (isFunction(listener)) {
1812
+ const wrappedListener = getWrappedCustomElementListener(listener);
1813
+ detachDOMListener(this, type, wrappedListener);
1799
1814
  }
1800
- };
1801
- function fauxElementsFromPoint(context, doc, left, top) {
1802
- const elements = elementsFromPoint.call(doc, left, top);
1803
- const result = [];
1804
- const rootNodes = getAllRootNodes(context);
1805
- // Filter the elements array to only include those elements that are in this shadow root or in one of its
1806
- // ancestor roots. This matches Chrome and Safari's implementation (but not Firefox's, which only includes
1807
- // elements in the immediate shadow root: https://crbug.com/1207863#c4).
1808
- if (!isNull(elements)) {
1809
- // can be null in IE https://developer.mozilla.org/en-US/docs/Web/API/Document/elementsFromPoint#browser_compatibility
1810
- for (let i = 0; i < elements.length; i++) {
1811
- const element = elements[i];
1812
- if (isSyntheticSlotElement(element)) {
1813
- continue;
1814
- }
1815
- const elementRootNode = element.getRootNode();
1816
- if (ArrayIndexOf.call(rootNodes, elementRootNode) !== -1) {
1817
- ArrayPush.call(result, element);
1818
- continue;
1819
- }
1820
- // In cases where the host element is not visible but its shadow descendants are, then
1821
- // we may get the shadow descendant instead of the host element here. (The
1822
- // browser doesn't know the difference in synthetic shadow DOM.)
1823
- // In native shadow DOM, however, elementsFromPoint would return the host but not
1824
- // the child. So we need to detect if this shadow element's host is accessible from
1825
- // the context's shadow root. Note we also need to be careful not to add the host
1826
- // multiple times.
1827
- const ancestorHost = findAncestorHostInImmediateShadowRoot(elementRootNode, rootNodes[0]);
1828
- if (!isUndefined(ancestorHost) &&
1829
- ArrayIndexOf.call(elements, ancestorHost) === -1 &&
1830
- ArrayIndexOf.call(result, ancestorHost) === -1) {
1831
- ArrayPush.call(result, ancestorHost);
1832
- }
1815
+ }
1816
+ function addShadowRootEventListener(sr, type, listener, _options) {
1817
+ if (process.env.NODE_ENV !== 'production') {
1818
+ if (!isFunction(listener)) {
1819
+ throw new TypeError(`Invalid second argument for ShadowRoot.addEventListener() in ${toString(sr)} for event "${type}". Expected an EventListener but received ${listener}.`);
1833
1820
  }
1834
1821
  }
1835
- return result;
1822
+ // TODO [#1824]: Lift this restriction on the option parameter
1823
+ if (isFunction(listener)) {
1824
+ const elm = getHost(sr);
1825
+ const wrappedListener = getWrappedShadowRootListener(listener);
1826
+ attachDOMListener(elm, type, wrappedListener);
1827
+ }
1828
+ }
1829
+ function removeShadowRootEventListener(sr, type, listener, _options) {
1830
+ // TODO [#1824]: Lift this restriction on the option parameter
1831
+ if (isFunction(listener)) {
1832
+ const elm = getHost(sr);
1833
+ const wrappedListener = getWrappedShadowRootListener(listener);
1834
+ detachDOMListener(elm, type, wrappedListener);
1835
+ }
1836
1836
  }
1837
1837
 
1838
1838
  /*
@@ -4102,41 +4102,230 @@
4102
4102
  if (!runtimeFlags.ENABLE_HTML_COLLECTIONS_PATCH) {
4103
4103
  return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
4104
4104
  }
4105
-
4106
- const filteredResults = getFilteredArrayOfNodes(this, elements, 1
4107
- /* Enabled */
4108
- );
4109
- return createStaticHTMLCollection(filteredResults);
4110
- },
4111
-
4112
- writable: true,
4113
- enumerable: true,
4114
- configurable: true
4115
- },
4116
- getElementsByTagNameNS: {
4117
- value() {
4118
- const elements = arrayFromCollection(getElementsByTagNameNS$1.apply(this, ArraySlice.call(arguments)));
4119
-
4120
- if (!runtimeFlags.ENABLE_HTML_COLLECTIONS_PATCH) {
4121
- return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
4105
+
4106
+ const filteredResults = getFilteredArrayOfNodes(this, elements, 1
4107
+ /* Enabled */
4108
+ );
4109
+ return createStaticHTMLCollection(filteredResults);
4110
+ },
4111
+
4112
+ writable: true,
4113
+ enumerable: true,
4114
+ configurable: true
4115
+ },
4116
+ getElementsByTagNameNS: {
4117
+ value() {
4118
+ const elements = arrayFromCollection(getElementsByTagNameNS$1.apply(this, ArraySlice.call(arguments)));
4119
+
4120
+ if (!runtimeFlags.ENABLE_HTML_COLLECTIONS_PATCH) {
4121
+ return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
4122
+ }
4123
+
4124
+ const filteredResults = getFilteredArrayOfNodes(this, elements, 1
4125
+ /* Enabled */
4126
+ );
4127
+ return createStaticHTMLCollection(filteredResults);
4128
+ },
4129
+
4130
+ writable: true,
4131
+ enumerable: true,
4132
+ configurable: true
4133
+ }
4134
+ });
4135
+ } // IE11 extra patches for wrong prototypes
4136
+
4137
+
4138
+ if (hasOwnProperty.call(HTMLElement.prototype, 'getElementsByClassName')) {
4139
+ defineProperty(HTMLElement.prototype, 'getElementsByClassName', getOwnPropertyDescriptor(Element.prototype, 'getElementsByClassName'));
4140
+ }
4141
+
4142
+ /*
4143
+ * Copyright (c) 2018, salesforce.com, inc.
4144
+ * All rights reserved.
4145
+ * SPDX-License-Identifier: MIT
4146
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4147
+ */
4148
+ function getElementComputedStyle(element) {
4149
+ const win = getOwnerWindow(element);
4150
+ return windowGetComputedStyle.call(win, element);
4151
+ }
4152
+ function getWindowSelection(node) {
4153
+ const win = getOwnerWindow(node);
4154
+ return windowGetSelection.call(win);
4155
+ }
4156
+ function nodeIsBeingRendered(nodeComputedStyle) {
4157
+ return nodeComputedStyle.visibility === 'visible' && nodeComputedStyle.display !== 'none';
4158
+ }
4159
+ function getSelectionState(element) {
4160
+ const win = getOwnerWindow(element);
4161
+ const selection = getWindowSelection(element);
4162
+ if (selection === null) {
4163
+ return null;
4164
+ }
4165
+ const ranges = [];
4166
+ for (let i = 0; i < selection.rangeCount; i++) {
4167
+ ranges.push(selection.getRangeAt(i));
4168
+ }
4169
+ const state = {
4170
+ element,
4171
+ onselect: win.onselect,
4172
+ onselectstart: win.onselectstart,
4173
+ onselectionchange: win.onselectionchange,
4174
+ ranges,
4175
+ };
4176
+ win.onselect = null;
4177
+ win.onselectstart = null;
4178
+ win.onselectionchange = null;
4179
+ return state;
4180
+ }
4181
+ function restoreSelectionState(state) {
4182
+ if (state === null) {
4183
+ return;
4184
+ }
4185
+ const { element, onselect, onselectstart, onselectionchange, ranges } = state;
4186
+ const win = getOwnerWindow(element);
4187
+ const selection = getWindowSelection(element);
4188
+ selection.removeAllRanges();
4189
+ for (let i = 0; i < ranges.length; i++) {
4190
+ selection.addRange(ranges[i]);
4191
+ }
4192
+ win.onselect = onselect;
4193
+ win.onselectstart = onselectstart;
4194
+ win.onselectionchange = onselectionchange;
4195
+ }
4196
+ /**
4197
+ * Gets the "innerText" of a text node using the Selection API
4198
+ *
4199
+ * NOTE: For performance reasons, since this function will be called multiple times while calculating the innerText of
4200
+ * an element, it does not restore the current selection.
4201
+ */
4202
+ function getTextNodeInnerText(textNode) {
4203
+ const selection = getWindowSelection(textNode);
4204
+ if (selection === null) {
4205
+ return textNode.textContent || '';
4206
+ }
4207
+ const range = document.createRange();
4208
+ range.selectNodeContents(textNode);
4209
+ const domRect = range.getBoundingClientRect();
4210
+ if (domRect.height <= 0 || domRect.width <= 0) {
4211
+ // the text node is not rendered
4212
+ return '';
4213
+ }
4214
+ // Needed to remove non rendered characters from the text node.
4215
+ selection.removeAllRanges();
4216
+ selection.addRange(range);
4217
+ const selectionText = selection.toString();
4218
+ // The textNode is visible, but it may not be selectable. When the text is not selectable,
4219
+ // textContent is the nearest approximation to innerText.
4220
+ return selectionText ? selectionText : textNode.textContent || '';
4221
+ }
4222
+ const nodeIsElement = (node) => node.nodeType === ELEMENT_NODE;
4223
+ const nodeIsText = (node) => node.nodeType === TEXT_NODE;
4224
+ /**
4225
+ * Spec: https://html.spec.whatwg.org/multipage/dom.html#inner-text-collection-steps
4226
+ * One spec implementation: https://github.com/servo/servo/blob/721271dcd3c20db5ca8cf146e2b5907647afb4d6/components/layout/query.rs#L1132
4227
+ */
4228
+ function innerTextCollectionSteps(node) {
4229
+ const items = [];
4230
+ if (nodeIsElement(node)) {
4231
+ const { tagName } = node;
4232
+ const computedStyle = getElementComputedStyle(node);
4233
+ if (tagName === 'OPTION') {
4234
+ // For options, is hard to get the "rendered" text, let's use the original getter.
4235
+ return [1, innerTextGetter.call(node), 1];
4236
+ }
4237
+ else if (tagName === 'TEXTAREA') {
4238
+ return [];
4239
+ }
4240
+ else {
4241
+ const childNodes = node.childNodes;
4242
+ for (let i = 0, n = childNodes.length; i < n; i++) {
4243
+ ArrayPush.apply(items, innerTextCollectionSteps(childNodes[i]));
4244
+ }
4245
+ }
4246
+ if (!nodeIsBeingRendered(computedStyle)) {
4247
+ if (tagName === 'SELECT' || tagName === 'DATALIST') {
4248
+ // the select is either: .visibility != 'visible' or .display === hidden, therefore this select should
4249
+ // not display any value.
4250
+ return [];
4251
+ }
4252
+ return items;
4253
+ }
4254
+ if (tagName === 'BR') {
4255
+ items.push('\u{000A}' /* line feed */);
4256
+ }
4257
+ const { display } = computedStyle;
4258
+ if (display === 'table-cell') {
4259
+ // omitting case: and node's CSS box is not the last 'table-cell' box of its enclosing 'table-row' box
4260
+ items.push('\u{0009}' /* tab */);
4261
+ }
4262
+ if (display === 'table-row') {
4263
+ // omitting case: and node's CSS box is not the last 'table-row' box of the nearest ancestor 'table' box
4264
+ items.push('\u{000A}' /* line feed */);
4265
+ }
4266
+ if (tagName === 'P') {
4267
+ items.unshift(2);
4268
+ items.push(2);
4269
+ }
4270
+ if (display === 'block' ||
4271
+ display === 'table-caption' ||
4272
+ display === 'flex' ||
4273
+ display === 'table') {
4274
+ items.unshift(1);
4275
+ items.push(1);
4276
+ }
4277
+ }
4278
+ else if (nodeIsText(node)) {
4279
+ items.push(getTextNodeInnerText(node));
4280
+ }
4281
+ return items;
4282
+ }
4283
+ /**
4284
+ * InnerText getter spec: https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute
4285
+ *
4286
+ * One spec implementation: https://github.com/servo/servo/blob/721271dcd3c20db5ca8cf146e2b5907647afb4d6/components/layout/query.rs#L1087
4287
+ */
4288
+ function getInnerText(element) {
4289
+ const thisComputedStyle = getElementComputedStyle(element);
4290
+ if (!nodeIsBeingRendered(thisComputedStyle)) {
4291
+ return getTextContent(element) || '';
4292
+ }
4293
+ const selectionState = getSelectionState(element);
4294
+ const results = [];
4295
+ const childNodes = element.childNodes;
4296
+ for (let i = 0, n = childNodes.length; i < n; i++) {
4297
+ ArrayPush.apply(results, innerTextCollectionSteps(childNodes[i]));
4298
+ }
4299
+ restoreSelectionState(selectionState);
4300
+ let elementInnerText = '';
4301
+ let maxReqLineBreakCount = 0;
4302
+ for (let i = 0, n = results.length; i < n; i++) {
4303
+ const item = results[i];
4304
+ if (typeof item === 'string') {
4305
+ if (maxReqLineBreakCount > 0) {
4306
+ for (let j = 0; j < maxReqLineBreakCount; j++) {
4307
+ elementInnerText += '\u{000A}';
4308
+ }
4309
+ maxReqLineBreakCount = 0;
4310
+ }
4311
+ if (item.length > 0) {
4312
+ elementInnerText += item;
4313
+ }
4314
+ }
4315
+ else {
4316
+ if (elementInnerText.length == 0) {
4317
+ // Remove required line break count at the start.
4318
+ continue;
4319
+ }
4320
+ // Store the count if it's the max of this run,
4321
+ // but it may be ignored if no text item is found afterwards,
4322
+ // which means that these are consecutive line breaks at the end.
4323
+ if (item > maxReqLineBreakCount) {
4324
+ maxReqLineBreakCount = item;
4325
+ }
4122
4326
  }
4123
-
4124
- const filteredResults = getFilteredArrayOfNodes(this, elements, 1
4125
- /* Enabled */
4126
- );
4127
- return createStaticHTMLCollection(filteredResults);
4128
- },
4129
-
4130
- writable: true,
4131
- enumerable: true,
4132
- configurable: true
4133
4327
  }
4134
- });
4135
- } // IE11 extra patches for wrong prototypes
4136
-
4137
-
4138
- if (hasOwnProperty.call(HTMLElement.prototype, 'getElementsByClassName')) {
4139
- defineProperty(HTMLElement.prototype, 'getElementsByClassName', getOwnPropertyDescriptor(Element.prototype, 'getElementsByClassName'));
4328
+ return elementInnerText;
4140
4329
  }
4141
4330
 
4142
4331
  /*
@@ -4480,195 +4669,6 @@
4480
4669
  removeEventListener.call(elm, 'focusin', skipShadowHandler, true);
4481
4670
  }
4482
4671
 
4483
- /*
4484
- * Copyright (c) 2018, salesforce.com, inc.
4485
- * All rights reserved.
4486
- * SPDX-License-Identifier: MIT
4487
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4488
- */
4489
- function getElementComputedStyle(element) {
4490
- const win = getOwnerWindow(element);
4491
- return windowGetComputedStyle.call(win, element);
4492
- }
4493
- function getWindowSelection(node) {
4494
- const win = getOwnerWindow(node);
4495
- return windowGetSelection.call(win);
4496
- }
4497
- function nodeIsBeingRendered(nodeComputedStyle) {
4498
- return nodeComputedStyle.visibility === 'visible' && nodeComputedStyle.display !== 'none';
4499
- }
4500
- function getSelectionState(element) {
4501
- const win = getOwnerWindow(element);
4502
- const selection = getWindowSelection(element);
4503
- if (selection === null) {
4504
- return null;
4505
- }
4506
- const ranges = [];
4507
- for (let i = 0; i < selection.rangeCount; i++) {
4508
- ranges.push(selection.getRangeAt(i));
4509
- }
4510
- const state = {
4511
- element,
4512
- onselect: win.onselect,
4513
- onselectstart: win.onselectstart,
4514
- onselectionchange: win.onselectionchange,
4515
- ranges,
4516
- };
4517
- win.onselect = null;
4518
- win.onselectstart = null;
4519
- win.onselectionchange = null;
4520
- return state;
4521
- }
4522
- function restoreSelectionState(state) {
4523
- if (state === null) {
4524
- return;
4525
- }
4526
- const { element, onselect, onselectstart, onselectionchange, ranges } = state;
4527
- const win = getOwnerWindow(element);
4528
- const selection = getWindowSelection(element);
4529
- selection.removeAllRanges();
4530
- for (let i = 0; i < ranges.length; i++) {
4531
- selection.addRange(ranges[i]);
4532
- }
4533
- win.onselect = onselect;
4534
- win.onselectstart = onselectstart;
4535
- win.onselectionchange = onselectionchange;
4536
- }
4537
- /**
4538
- * Gets the "innerText" of a text node using the Selection API
4539
- *
4540
- * NOTE: For performance reasons, since this function will be called multiple times while calculating the innerText of
4541
- * an element, it does not restore the current selection.
4542
- */
4543
- function getTextNodeInnerText(textNode) {
4544
- const selection = getWindowSelection(textNode);
4545
- if (selection === null) {
4546
- return textNode.textContent || '';
4547
- }
4548
- const range = document.createRange();
4549
- range.selectNodeContents(textNode);
4550
- const domRect = range.getBoundingClientRect();
4551
- if (domRect.height <= 0 || domRect.width <= 0) {
4552
- // the text node is not rendered
4553
- return '';
4554
- }
4555
- // Needed to remove non rendered characters from the text node.
4556
- selection.removeAllRanges();
4557
- selection.addRange(range);
4558
- const selectionText = selection.toString();
4559
- // The textNode is visible, but it may not be selectable. When the text is not selectable,
4560
- // textContent is the nearest approximation to innerText.
4561
- return selectionText ? selectionText : textNode.textContent || '';
4562
- }
4563
- const nodeIsElement = (node) => node.nodeType === ELEMENT_NODE;
4564
- const nodeIsText = (node) => node.nodeType === TEXT_NODE;
4565
- /**
4566
- * Spec: https://html.spec.whatwg.org/multipage/dom.html#inner-text-collection-steps
4567
- * One spec implementation: https://github.com/servo/servo/blob/721271dcd3c20db5ca8cf146e2b5907647afb4d6/components/layout/query.rs#L1132
4568
- */
4569
- function innerTextCollectionSteps(node) {
4570
- const items = [];
4571
- if (nodeIsElement(node)) {
4572
- const { tagName } = node;
4573
- const computedStyle = getElementComputedStyle(node);
4574
- if (tagName === 'OPTION') {
4575
- // For options, is hard to get the "rendered" text, let's use the original getter.
4576
- return [1, innerTextGetter.call(node), 1];
4577
- }
4578
- else if (tagName === 'TEXTAREA') {
4579
- return [];
4580
- }
4581
- else {
4582
- const childNodes = node.childNodes;
4583
- for (let i = 0, n = childNodes.length; i < n; i++) {
4584
- ArrayPush.apply(items, innerTextCollectionSteps(childNodes[i]));
4585
- }
4586
- }
4587
- if (!nodeIsBeingRendered(computedStyle)) {
4588
- if (tagName === 'SELECT' || tagName === 'DATALIST') {
4589
- // the select is either: .visibility != 'visible' or .display === hidden, therefore this select should
4590
- // not display any value.
4591
- return [];
4592
- }
4593
- return items;
4594
- }
4595
- if (tagName === 'BR') {
4596
- items.push('\u{000A}' /* line feed */);
4597
- }
4598
- const { display } = computedStyle;
4599
- if (display === 'table-cell') {
4600
- // omitting case: and node's CSS box is not the last 'table-cell' box of its enclosing 'table-row' box
4601
- items.push('\u{0009}' /* tab */);
4602
- }
4603
- if (display === 'table-row') {
4604
- // omitting case: and node's CSS box is not the last 'table-row' box of the nearest ancestor 'table' box
4605
- items.push('\u{000A}' /* line feed */);
4606
- }
4607
- if (tagName === 'P') {
4608
- items.unshift(2);
4609
- items.push(2);
4610
- }
4611
- if (display === 'block' ||
4612
- display === 'table-caption' ||
4613
- display === 'flex' ||
4614
- display === 'table') {
4615
- items.unshift(1);
4616
- items.push(1);
4617
- }
4618
- }
4619
- else if (nodeIsText(node)) {
4620
- items.push(getTextNodeInnerText(node));
4621
- }
4622
- return items;
4623
- }
4624
- /**
4625
- * InnerText getter spec: https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute
4626
- *
4627
- * One spec implementation: https://github.com/servo/servo/blob/721271dcd3c20db5ca8cf146e2b5907647afb4d6/components/layout/query.rs#L1087
4628
- */
4629
- function getInnerText(element) {
4630
- const thisComputedStyle = getElementComputedStyle(element);
4631
- if (!nodeIsBeingRendered(thisComputedStyle)) {
4632
- return getTextContent(element) || '';
4633
- }
4634
- const selectionState = getSelectionState(element);
4635
- const results = [];
4636
- const childNodes = element.childNodes;
4637
- for (let i = 0, n = childNodes.length; i < n; i++) {
4638
- ArrayPush.apply(results, innerTextCollectionSteps(childNodes[i]));
4639
- }
4640
- restoreSelectionState(selectionState);
4641
- let elementInnerText = '';
4642
- let maxReqLineBreakCount = 0;
4643
- for (let i = 0, n = results.length; i < n; i++) {
4644
- const item = results[i];
4645
- if (typeof item === 'string') {
4646
- if (maxReqLineBreakCount > 0) {
4647
- for (let j = 0; j < maxReqLineBreakCount; j++) {
4648
- elementInnerText += '\u{000A}';
4649
- }
4650
- maxReqLineBreakCount = 0;
4651
- }
4652
- if (item.length > 0) {
4653
- elementInnerText += item;
4654
- }
4655
- }
4656
- else {
4657
- if (elementInnerText.length == 0) {
4658
- // Remove required line break count at the start.
4659
- continue;
4660
- }
4661
- // Store the count if it's the max of this run,
4662
- // but it may be ignored if no text item is found afterwards,
4663
- // which means that these are consecutive line breaks at the end.
4664
- if (item > maxReqLineBreakCount) {
4665
- maxReqLineBreakCount = item;
4666
- }
4667
- }
4668
- }
4669
- return elementInnerText;
4670
- }
4671
-
4672
4672
  /*
4673
4673
  * Copyright (c) 2018, salesforce.com, inc.
4674
4674
  * All rights reserved.
@@ -5069,6 +5069,6 @@
5069
5069
  },
5070
5070
  configurable: true,
5071
5071
  });
5072
- /** version: 2.12.0 */
5072
+ /** version: 2.13.1 */
5073
5073
 
5074
5074
  })();