@lwc/synthetic-shadow 2.13.0 → 2.13.1

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