@lwc/synthetic-shadow 2.45.1 → 2.45.3

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 (76) hide show
  1. package/dist/3rdparty/polymer/inner-html.d.ts +10 -0
  2. package/dist/3rdparty/polymer/outer-html.d.ts +10 -0
  3. package/dist/3rdparty/polymer/path-composer.d.ts +1 -0
  4. package/dist/3rdparty/polymer/retarget.d.ts +10 -0
  5. package/dist/3rdparty/polymer/text-content.d.ts +10 -0
  6. package/dist/env/document.d.ts +24 -0
  7. package/dist/env/dom.d.ts +5 -0
  8. package/dist/env/element.d.ts +45 -0
  9. package/dist/env/event-target.d.ts +3 -0
  10. package/dist/env/mutation-observer.d.ts +6 -0
  11. package/dist/env/node.d.ts +35 -0
  12. package/dist/env/shadow-root.d.ts +2 -0
  13. package/dist/env/slot.d.ts +2 -0
  14. package/dist/env/text.d.ts +1 -0
  15. package/dist/env/window.d.ts +8 -0
  16. package/dist/faux-shadow/element.d.ts +1 -0
  17. package/dist/faux-shadow/events.d.ts +16 -0
  18. package/dist/faux-shadow/focus.d.ts +9 -0
  19. package/dist/faux-shadow/html-element.d.ts +1 -0
  20. package/dist/faux-shadow/no-patch-utils.d.ts +5 -0
  21. package/dist/faux-shadow/node.d.ts +15 -0
  22. package/dist/faux-shadow/portal.d.ts +1 -0
  23. package/dist/faux-shadow/shadow-root.d.ts +22 -0
  24. package/dist/faux-shadow/shadow-token.d.ts +2 -0
  25. package/dist/faux-shadow/slot.d.ts +1 -0
  26. package/dist/faux-shadow/text.d.ts +1 -0
  27. package/dist/faux-shadow/traverse.d.ts +13 -0
  28. package/dist/index.cjs.js +4756 -0
  29. package/dist/index.cjs.js.map +1 -0
  30. package/dist/index.d.ts +30 -0
  31. package/dist/index.js +4754 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/polyfills/HTMLSlotElement/detect.d.ts +1 -0
  34. package/dist/polyfills/HTMLSlotElement/main.d.ts +1 -0
  35. package/dist/polyfills/HTMLSlotElement/polyfill.d.ts +1 -0
  36. package/dist/polyfills/click-event-composed/detect.d.ts +1 -0
  37. package/dist/polyfills/click-event-composed/main.d.ts +1 -0
  38. package/dist/polyfills/click-event-composed/polyfill.d.ts +1 -0
  39. package/dist/polyfills/clipboard-event-composed/main.d.ts +1 -0
  40. package/dist/polyfills/custom-event-composed/main.d.ts +1 -0
  41. package/dist/polyfills/custom-event-composed/polyfill.d.ts +8 -0
  42. package/dist/polyfills/document-shadow/main.d.ts +1 -0
  43. package/dist/polyfills/document-shadow/polyfill.d.ts +1 -0
  44. package/dist/polyfills/event/main.d.ts +1 -0
  45. package/dist/polyfills/event/polyfill.d.ts +1 -0
  46. package/dist/polyfills/event-composed/detect.d.ts +1 -0
  47. package/dist/polyfills/event-composed/main.d.ts +1 -0
  48. package/dist/polyfills/event-composed/polyfill.d.ts +1 -0
  49. package/dist/polyfills/event-target/main.d.ts +1 -0
  50. package/dist/polyfills/event-target/polyfill.d.ts +1 -0
  51. package/dist/polyfills/focus-event/main.d.ts +1 -0
  52. package/dist/polyfills/focus-event/polyfill.d.ts +1 -0
  53. package/dist/polyfills/iframe-content-window/detect.d.ts +1 -0
  54. package/dist/polyfills/iframe-content-window/main.d.ts +1 -0
  55. package/dist/polyfills/iframe-content-window/patch.d.ts +1 -0
  56. package/dist/polyfills/mouse-event/main.d.ts +1 -0
  57. package/dist/polyfills/mouse-event/polyfill.d.ts +1 -0
  58. package/dist/polyfills/mutation-observer/main.d.ts +1 -0
  59. package/dist/polyfills/mutation-observer/polyfill.d.ts +1 -0
  60. package/dist/polyfills/shadow-root/main.d.ts +1 -0
  61. package/dist/polyfills/shadow-root/polyfill.d.ts +1 -0
  62. package/dist/polyfills/window-event-target/detect.d.ts +1 -0
  63. package/dist/polyfills/window-event-target/main.d.ts +1 -0
  64. package/dist/polyfills/window-event-target/polyfill.d.ts +1 -0
  65. package/dist/shared/event-target.d.ts +2 -0
  66. package/dist/shared/faux-element-from-point.d.ts +1 -0
  67. package/dist/shared/faux-elements-from-point.d.ts +1 -0
  68. package/dist/shared/node-ownership.d.ts +11 -0
  69. package/dist/shared/retarget-related-target.d.ts +1 -0
  70. package/dist/shared/static-html-collection.d.ts +1 -0
  71. package/dist/shared/static-node-list.d.ts +1 -0
  72. package/dist/shared/utils.d.ts +9 -0
  73. package/dist/synthetic-shadow.js +73 -14
  74. package/package.json +33 -25
  75. package/dist/synthetic-shadow.js.map +0 -1
  76. package/index.js +0 -8
@@ -0,0 +1,4756 @@
1
+ /**
2
+ * Copyright (C) 2023 salesforce.com, inc.
3
+ */
4
+ 'use strict';
5
+
6
+ /**
7
+ * Copyright (C) 2023 salesforce.com, inc.
8
+ */
9
+ /*
10
+ * Copyright (c) 2018, salesforce.com, inc.
11
+ * All rights reserved.
12
+ * SPDX-License-Identifier: MIT
13
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
14
+ */
15
+ function invariant(value, msg) {
16
+ if (!value) {
17
+ throw new Error(`Invariant Violation: ${msg}`);
18
+ }
19
+ }
20
+ function isTrue$1(value, msg) {
21
+ if (!value) {
22
+ throw new Error(`Assert Violation: ${msg}`);
23
+ }
24
+ }
25
+ function isFalse$1(value, msg) {
26
+ if (value) {
27
+ throw new Error(`Assert Violation: ${msg}`);
28
+ }
29
+ }
30
+ function fail(msg) {
31
+ throw new Error(msg);
32
+ }
33
+
34
+ var assert = /*#__PURE__*/Object.freeze({
35
+ __proto__: null,
36
+ fail: fail,
37
+ invariant: invariant,
38
+ isFalse: isFalse$1,
39
+ isTrue: isTrue$1
40
+ });
41
+
42
+ /*
43
+ * Copyright (c) 2018, salesforce.com, inc.
44
+ * All rights reserved.
45
+ * SPDX-License-Identifier: MIT
46
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
47
+ */
48
+ const { assign, create, defineProperties, defineProperty, freeze, getOwnPropertyDescriptor, getOwnPropertyNames, getPrototypeOf, hasOwnProperty, isFrozen, keys, seal, setPrototypeOf, } = Object;
49
+ const { isArray } = Array;
50
+ const { concat: ArrayConcat, copyWithin: ArrayCopyWithin, every: ArrayEvery, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, findIndex: ArrayFindIndex, includes: ArrayIncludes, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, some: ArraySome, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, } = Array.prototype;
51
+ const { charCodeAt: StringCharCodeAt, replace: StringReplace, split: StringSplit, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
52
+ function isUndefined(obj) {
53
+ return obj === undefined;
54
+ }
55
+ function isNull(obj) {
56
+ return obj === null;
57
+ }
58
+ function isTrue(obj) {
59
+ return obj === true;
60
+ }
61
+ function isFalse(obj) {
62
+ return obj === false;
63
+ }
64
+ function isFunction(obj) {
65
+ return typeof obj === 'function';
66
+ }
67
+ function isObject(obj) {
68
+ return typeof obj === 'object';
69
+ }
70
+ const OtS = {}.toString;
71
+ function toString(obj) {
72
+ if (obj && obj.toString) {
73
+ // Arrays might hold objects with "null" prototype So using
74
+ // Array.prototype.toString directly will cause an error Iterate through
75
+ // all the items and handle individually.
76
+ if (isArray(obj)) {
77
+ return ArrayJoin.call(ArrayMap.call(obj, toString), ',');
78
+ }
79
+ return obj.toString();
80
+ }
81
+ else if (typeof obj === 'object') {
82
+ return OtS.call(obj);
83
+ }
84
+ else {
85
+ return obj + '';
86
+ }
87
+ }
88
+
89
+ /*
90
+ * Copyright (c) 2018, salesforce.com, inc.
91
+ * All rights reserved.
92
+ * SPDX-License-Identifier: MIT
93
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
94
+ */
95
+ // See browser support for globalThis:
96
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis#browser_compatibility
97
+ /* istanbul ignore next */
98
+ // @ts-ignore
99
+ const _globalThis = typeof globalThis === 'object' ? globalThis : window;
100
+
101
+ /*
102
+ * Copyright (c) 2018, salesforce.com, inc.
103
+ * All rights reserved.
104
+ * SPDX-License-Identifier: MIT
105
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
106
+ */
107
+ const KEY__IS_NATIVE_SHADOW_ROOT_DEFINED = '$isNativeShadowRootDefined$';
108
+ const KEY__SHADOW_RESOLVER = '$shadowResolver$';
109
+ const KEY__SHADOW_RESOLVER_PRIVATE = '$$ShadowResolverKey$$';
110
+ const KEY__SHADOW_STATIC = '$shadowStaticNode$';
111
+ const KEY__SHADOW_STATIC_PRIVATE = '$shadowStaticNodeKey$';
112
+ const KEY__SHADOW_TOKEN = '$shadowToken$';
113
+ const KEY__SHADOW_TOKEN_PRIVATE = '$$ShadowTokenKey$$';
114
+ const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
115
+ const KEY__NATIVE_GET_ELEMENT_BY_ID = '$nativeGetElementById$';
116
+ const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
117
+
118
+ /*
119
+ * Copyright (c) 2018, salesforce.com, inc.
120
+ * All rights reserved.
121
+ * SPDX-License-Identifier: MIT
122
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
123
+ */
124
+ // We use this to detect symbol support in order to avoid the expensive symbol polyfill. Note that
125
+ // we can't use typeof since it will fail when transpiling.
126
+ const hasNativeSymbolSupport = /*@__PURE__*/ (() => Symbol('x').toString() === 'Symbol(x)')();
127
+ /** version: 2.45.3 */
128
+
129
+ /**
130
+ * Copyright (C) 2023 salesforce.com, inc.
131
+ */
132
+ // eslint-disable-next-line no-restricted-properties
133
+ if (!_globalThis.lwcRuntimeFlags) {
134
+ Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
135
+ }
136
+ /** version: 2.45.3 */
137
+
138
+ /*
139
+ * Copyright (c) 2018, salesforce.com, inc.
140
+ * All rights reserved.
141
+ * SPDX-License-Identifier: MIT
142
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
143
+ */
144
+ // TODO [#2472]: Remove this workaround when appropriate.
145
+ // eslint-disable-next-line @lwc/lwc-internal/no-global-node
146
+ const _Node = Node;
147
+ const nodePrototype = _Node.prototype;
148
+ const { DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_PRECEDING, DOCUMENT_POSITION_FOLLOWING, ELEMENT_NODE, TEXT_NODE, CDATA_SECTION_NODE, PROCESSING_INSTRUCTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, } = _Node;
149
+ const { appendChild, cloneNode, compareDocumentPosition, insertBefore, removeChild, replaceChild, hasChildNodes, } = nodePrototype;
150
+ const { contains } = HTMLElement.prototype;
151
+ const firstChildGetter = getOwnPropertyDescriptor(nodePrototype, 'firstChild').get;
152
+ const lastChildGetter = getOwnPropertyDescriptor(nodePrototype, 'lastChild').get;
153
+ const textContentGetter = getOwnPropertyDescriptor(nodePrototype, 'textContent').get;
154
+ const parentNodeGetter = getOwnPropertyDescriptor(nodePrototype, 'parentNode').get;
155
+ const ownerDocumentGetter = getOwnPropertyDescriptor(nodePrototype, 'ownerDocument').get;
156
+ const parentElementGetter = hasOwnProperty.call(nodePrototype, 'parentElement')
157
+ ? getOwnPropertyDescriptor(nodePrototype, 'parentElement').get
158
+ : getOwnPropertyDescriptor(HTMLElement.prototype, 'parentElement').get; // IE11
159
+ const textContextSetter = getOwnPropertyDescriptor(nodePrototype, 'textContent').set;
160
+ const childNodesGetter = hasOwnProperty.call(nodePrototype, 'childNodes')
161
+ ? getOwnPropertyDescriptor(nodePrototype, 'childNodes').get
162
+ : getOwnPropertyDescriptor(HTMLElement.prototype, 'childNodes').get; // IE11
163
+ const isConnected = hasOwnProperty.call(nodePrototype, 'isConnected')
164
+ ? getOwnPropertyDescriptor(nodePrototype, 'isConnected').get
165
+ : function () {
166
+ const doc = ownerDocumentGetter.call(this);
167
+ // IE11
168
+ return (
169
+ // if doc is null, it means `this` is actually a document instance which
170
+ // is always connected
171
+ doc === null ||
172
+ (compareDocumentPosition.call(doc, this) & DOCUMENT_POSITION_CONTAINED_BY) !== 0);
173
+ };
174
+
175
+ /*
176
+ * Copyright (c) 2018, salesforce.com, inc.
177
+ * All rights reserved.
178
+ * SPDX-License-Identifier: MIT
179
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
180
+ */
181
+ const { getAttribute, getBoundingClientRect, getElementsByTagName: getElementsByTagName$1, getElementsByTagNameNS: getElementsByTagNameNS$1, hasAttribute, querySelector, querySelectorAll: querySelectorAll$1, removeAttribute, setAttribute, } = Element.prototype;
182
+ const attachShadow$1 = hasOwnProperty.call(Element.prototype, 'attachShadow')
183
+ ? Element.prototype.attachShadow
184
+ : () => {
185
+ throw new TypeError('attachShadow() is not supported in current browser. Load the @lwc/synthetic-shadow polyfill and use Lightning Web Components');
186
+ };
187
+ const childElementCountGetter = getOwnPropertyDescriptor(Element.prototype, 'childElementCount').get;
188
+ const firstElementChildGetter = getOwnPropertyDescriptor(Element.prototype, 'firstElementChild').get;
189
+ const lastElementChildGetter = getOwnPropertyDescriptor(Element.prototype, 'lastElementChild').get;
190
+ const innerTextDescriptor = getOwnPropertyDescriptor(HTMLElement.prototype, 'innerText');
191
+ const innerTextGetter = innerTextDescriptor
192
+ ? innerTextDescriptor.get
193
+ : null;
194
+ const innerTextSetter = innerTextDescriptor
195
+ ? innerTextDescriptor.set
196
+ : null;
197
+ // Note: Firefox does not have outerText, https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/outerText
198
+ const outerTextDescriptor = getOwnPropertyDescriptor(HTMLElement.prototype, 'outerText');
199
+ const outerTextGetter = outerTextDescriptor
200
+ ? outerTextDescriptor.get
201
+ : null;
202
+ const outerTextSetter = outerTextDescriptor
203
+ ? outerTextDescriptor.set
204
+ : null;
205
+ const innerHTMLDescriptor = hasOwnProperty.call(Element.prototype, 'innerHTML')
206
+ ? getOwnPropertyDescriptor(Element.prototype, 'innerHTML')
207
+ : getOwnPropertyDescriptor(HTMLElement.prototype, 'innerHTML'); // IE11
208
+ const innerHTMLGetter = innerHTMLDescriptor.get;
209
+ const innerHTMLSetter = innerHTMLDescriptor.set;
210
+ const outerHTMLDescriptor = hasOwnProperty.call(Element.prototype, 'outerHTML')
211
+ ? getOwnPropertyDescriptor(Element.prototype, 'outerHTML')
212
+ : getOwnPropertyDescriptor(HTMLElement.prototype, 'outerHTML'); // IE11
213
+ const outerHTMLGetter = outerHTMLDescriptor.get;
214
+ const outerHTMLSetter = outerHTMLDescriptor.set;
215
+ const tagNameGetter = getOwnPropertyDescriptor(Element.prototype, 'tagName').get;
216
+ const tabIndexDescriptor = getOwnPropertyDescriptor(HTMLElement.prototype, 'tabIndex');
217
+ const tabIndexGetter = tabIndexDescriptor.get;
218
+ const tabIndexSetter = tabIndexDescriptor.set;
219
+ const matches = hasOwnProperty.call(Element.prototype, 'matches')
220
+ ? Element.prototype.matches
221
+ : Element.prototype.msMatchesSelector; // IE11
222
+ const childrenGetter = hasOwnProperty.call(Element.prototype, 'children')
223
+ ? getOwnPropertyDescriptor(Element.prototype, 'children').get
224
+ : getOwnPropertyDescriptor(HTMLElement.prototype, 'children').get; // IE11
225
+ // for IE11, access from HTMLElement
226
+ // for all other browsers access the method from the parent Element interface
227
+ const { getElementsByClassName: getElementsByClassName$1 } = HTMLElement.prototype;
228
+ const shadowRootGetter = hasOwnProperty.call(Element.prototype, 'shadowRoot')
229
+ ? getOwnPropertyDescriptor(Element.prototype, 'shadowRoot').get
230
+ : () => null;
231
+ const assignedSlotGetter$1 = hasOwnProperty.call(Element.prototype, 'assignedSlot')
232
+ ? getOwnPropertyDescriptor(Element.prototype, 'assignedSlot').get
233
+ : () => null;
234
+
235
+ /*
236
+ * Copyright (c) 2018, salesforce.com, inc.
237
+ * All rights reserved.
238
+ * SPDX-License-Identifier: MIT
239
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
240
+ */
241
+ let assignedNodes, assignedElements;
242
+ if (typeof HTMLSlotElement !== 'undefined') {
243
+ assignedNodes = HTMLSlotElement.prototype.assignedNodes;
244
+ assignedElements = HTMLSlotElement.prototype.assignedElements;
245
+ }
246
+ else {
247
+ assignedNodes = () => {
248
+ throw new TypeError("assignedNodes() is not supported in current browser. Load the @lwc/synthetic-shadow polyfill to start using <slot> elements in your Lightning Web Component's template");
249
+ };
250
+ assignedElements = () => {
251
+ throw new TypeError("assignedElements() is not supported in current browser. Load the @lwc/synthetic-shadow polyfill to start using <slot> elements in your Lightning Web Component's template");
252
+ };
253
+ }
254
+
255
+ /*
256
+ * Copyright (c) 2018, salesforce.com, inc.
257
+ * All rights reserved.
258
+ * SPDX-License-Identifier: MIT
259
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
260
+ */
261
+ const eventTargetGetter = getOwnPropertyDescriptor(Event.prototype, 'target').get;
262
+ const eventCurrentTargetGetter = getOwnPropertyDescriptor(Event.prototype, 'currentTarget').get;
263
+ const focusEventRelatedTargetGetter = getOwnPropertyDescriptor(FocusEvent.prototype, 'relatedTarget').get;
264
+ // IE does not implement composedPath() but that's ok because we only use this instead of our
265
+ // composedPath() polyfill when dealing with native shadow DOM components in mixed mode. Defaulting
266
+ // to a NOOP just to be safe, even though this is almost guaranteed to be defined such a scenario.
267
+ const composedPath = hasOwnProperty.call(Event.prototype, 'composedPath')
268
+ ? Event.prototype.composedPath
269
+ : () => [];
270
+
271
+ /*
272
+ * Copyright (c) 2018, salesforce.com, inc.
273
+ * All rights reserved.
274
+ * SPDX-License-Identifier: MIT
275
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
276
+ */
277
+ const DocumentPrototypeActiveElement = getOwnPropertyDescriptor(Document.prototype, 'activeElement').get;
278
+ const elementFromPoint = hasOwnProperty.call(Document.prototype, 'elementFromPoint')
279
+ ? Document.prototype.elementFromPoint
280
+ : Document.prototype.msElementFromPoint; // IE11
281
+ const elementsFromPoint = hasOwnProperty.call(Document.prototype, 'elementsFromPoint')
282
+ ? Document.prototype.elementsFromPoint
283
+ : Document.prototype.msElementsFromPoint; // IE11
284
+ // defaultView can be null when a document has no browsing context. For example, the owner document
285
+ // of a node in a template doesn't have a default view: https://jsfiddle.net/hv9z0q5a/
286
+ const defaultViewGetter = getOwnPropertyDescriptor(Document.prototype, 'defaultView').get;
287
+ const { createComment, querySelectorAll, getElementById, getElementsByClassName, getElementsByTagName, getElementsByTagNameNS, } = Document.prototype;
288
+ // In Firefox v57 and lower, getElementsByName is defined on HTMLDocument.prototype
289
+ // In all other browsers have the method on Document.prototype
290
+ const { getElementsByName } = HTMLDocument.prototype;
291
+
292
+ /*
293
+ * Copyright (c) 2018, salesforce.com, inc.
294
+ * All rights reserved.
295
+ * SPDX-License-Identifier: MIT
296
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
297
+ */
298
+ const { addEventListener: windowAddEventListener, removeEventListener: windowRemoveEventListener, getComputedStyle: windowGetComputedStyle, getSelection: windowGetSelection, } = window;
299
+
300
+ /*
301
+ * Copyright (c) 2018, salesforce.com, inc.
302
+ * All rights reserved.
303
+ * SPDX-License-Identifier: MIT
304
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
305
+ */
306
+ // There is code in the polyfills that requires access to the unpatched
307
+ // Mutation Observer constructor, this the code for that.
308
+ // Eventually, the polyfill should uses the patched version, and this file can be removed.
309
+ const MO = MutationObserver;
310
+ const MutationObserverObserve = MO.prototype.observe;
311
+
312
+ /*
313
+ * Copyright (c) 2018, salesforce.com, inc.
314
+ * All rights reserved.
315
+ * SPDX-License-Identifier: MIT
316
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
317
+ */
318
+ let NativeShadowRoot = null;
319
+ if (typeof ShadowRoot !== 'undefined') {
320
+ NativeShadowRoot = ShadowRoot;
321
+ }
322
+ const isNativeShadowRootDefined = !isNull(NativeShadowRoot);
323
+ const isInstanceOfNativeShadowRoot = isNull(NativeShadowRoot)
324
+ ? () => false
325
+ : (node) => node instanceof NativeShadowRoot;
326
+
327
+ /*
328
+ * Copyright (c) 2018, salesforce.com, inc.
329
+ * All rights reserved.
330
+ * SPDX-License-Identifier: MIT
331
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
332
+ */
333
+ function detect$4 () {
334
+ return typeof HTMLSlotElement === 'undefined';
335
+ }
336
+
337
+ /*
338
+ * Copyright (c) 2018, salesforce.com, inc.
339
+ * All rights reserved.
340
+ * SPDX-License-Identifier: MIT
341
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
342
+ */
343
+ const { createElement } = Document.prototype;
344
+ const CHAR_S = 115;
345
+ const CHAR_L = 108;
346
+ const CHAR_O = 111;
347
+ const CHAR_T = 116;
348
+ function apply$4() {
349
+ // IE11 does not have this element definition
350
+ // we don't care much about the construction phase, just the prototype
351
+ class HTMLSlotElement {
352
+ }
353
+ // prototype inheritance dance
354
+ setPrototypeOf(HTMLSlotElement, HTMLElement.constructor);
355
+ setPrototypeOf(HTMLSlotElement.prototype, HTMLElement.prototype);
356
+ Window.prototype.HTMLSlotElement = HTMLSlotElement;
357
+ // IE11 doesn't have HTMLSlotElement, in which case we
358
+ // need to patch Document.prototype.createElement to remap `slot`
359
+ // elements to the right prototype
360
+ defineProperty(Document.prototype, 'createElement', {
361
+ value: function (tagName, _options) {
362
+ const elm = createElement.apply(this, ArraySlice.call(arguments));
363
+ if (tagName.length === 4 &&
364
+ StringCharCodeAt.call(tagName, 0) === CHAR_S &&
365
+ StringCharCodeAt.call(tagName, 1) === CHAR_L &&
366
+ StringCharCodeAt.call(tagName, 2) === CHAR_O &&
367
+ StringCharCodeAt.call(tagName, 3) === CHAR_T) {
368
+ // the new element is the `slot`, resetting the proto chain
369
+ // the new newly created global HTMLSlotElement.prototype
370
+ setPrototypeOf(elm, HTMLSlotElement.prototype);
371
+ }
372
+ return elm;
373
+ },
374
+ });
375
+ }
376
+
377
+ /*
378
+ * Copyright (c) 2018, salesforce.com, inc.
379
+ * All rights reserved.
380
+ * SPDX-License-Identifier: MIT
381
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
382
+ */
383
+ if (detect$4()) {
384
+ apply$4();
385
+ }
386
+
387
+ /*
388
+ * Copyright (c) 2018, salesforce.com, inc.
389
+ * All rights reserved.
390
+ * SPDX-License-Identifier: MIT
391
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
392
+ */
393
+ // Helpful for tests running with jsdom
394
+ function getOwnerDocument(node) {
395
+ const doc = ownerDocumentGetter.call(node);
396
+ // if doc is null, it means `this` is actually a document instance
397
+ return doc === null ? node : doc;
398
+ }
399
+ function getOwnerWindow(node) {
400
+ const doc = getOwnerDocument(node);
401
+ const win = defaultViewGetter.call(doc);
402
+ if (win === null) {
403
+ // this method should never be called with a node that is not part
404
+ // of a qualifying connected node.
405
+ throw new TypeError();
406
+ }
407
+ return win;
408
+ }
409
+ let skipGlobalPatching;
410
+ // Note: we deviate from native shadow here, but are not fixing
411
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
412
+ function isGlobalPatchingSkipped(node) {
413
+ // we lazily compute this value instead of doing it during evaluation, this helps
414
+ // for apps that are setting this after the engine code is evaluated.
415
+ if (isUndefined(skipGlobalPatching)) {
416
+ const ownerDocument = getOwnerDocument(node);
417
+ skipGlobalPatching =
418
+ ownerDocument.body &&
419
+ getAttribute.call(ownerDocument.body, 'data-global-patching-bypass') ===
420
+ 'temporary-bypass';
421
+ }
422
+ return isTrue(skipGlobalPatching);
423
+ }
424
+ function arrayFromCollection(collection) {
425
+ const size = collection.length;
426
+ const cloned = [];
427
+ if (size > 0) {
428
+ for (let i = 0; i < size; i++) {
429
+ cloned[i] = collection[i];
430
+ }
431
+ }
432
+ return cloned;
433
+ }
434
+
435
+ /*
436
+ * Copyright (c) 2018, salesforce.com, inc.
437
+ * All rights reserved.
438
+ * SPDX-License-Identifier: MIT
439
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
440
+ */
441
+ const eventTargetPrototype = typeof EventTarget !== 'undefined' ? EventTarget.prototype : _Node.prototype;
442
+ const { addEventListener, dispatchEvent, removeEventListener } = eventTargetPrototype;
443
+
444
+ /*
445
+ * Copyright (c) 2018, salesforce.com, inc.
446
+ * All rights reserved.
447
+ * SPDX-License-Identifier: MIT
448
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
449
+ */
450
+ // Used as a back reference to identify the host element
451
+ const HostElementKey = '$$HostElementKey$$';
452
+ const ShadowedNodeKey = '$$ShadowedNodeKey$$';
453
+ function fastDefineProperty(node, propName, config) {
454
+ const shadowedNode = node;
455
+ if (process.env.NODE_ENV !== 'production') {
456
+ // in dev, we are more restrictive
457
+ defineProperty(shadowedNode, propName, config);
458
+ }
459
+ else {
460
+ const { value } = config;
461
+ // in prod, we prioritize performance
462
+ shadowedNode[propName] = value;
463
+ }
464
+ }
465
+ function setNodeOwnerKey(node, value) {
466
+ fastDefineProperty(node, HostElementKey, { value, configurable: true });
467
+ }
468
+ function setNodeKey(node, value) {
469
+ fastDefineProperty(node, ShadowedNodeKey, { value });
470
+ }
471
+ function getNodeOwnerKey(node) {
472
+ return node[HostElementKey];
473
+ }
474
+ function getNodeNearestOwnerKey(node) {
475
+ let host = node;
476
+ let hostKey;
477
+ // search for the first element with owner identity
478
+ // in case of manually inserted elements and elements slotted from Light DOM
479
+ while (!isNull(host)) {
480
+ hostKey = getNodeOwnerKey(host);
481
+ if (!isUndefined(hostKey)) {
482
+ return hostKey;
483
+ }
484
+ host = parentNodeGetter.call(host);
485
+ if (!isNull(host) && isSyntheticSlotElement(host)) {
486
+ return undefined;
487
+ }
488
+ }
489
+ }
490
+ function getNodeKey(node) {
491
+ return node[ShadowedNodeKey];
492
+ }
493
+ /**
494
+ * This function does not traverse up for performance reasons, but is sufficient for most use
495
+ * cases. If we need to traverse up and verify those nodes that don't have owner key, use
496
+ * isNodeDeepShadowed instead.
497
+ */
498
+ function isNodeShadowed(node) {
499
+ return !isUndefined(getNodeOwnerKey(node));
500
+ }
501
+
502
+ /*
503
+ * Copyright (c) 2018, salesforce.com, inc.
504
+ * All rights reserved.
505
+ * SPDX-License-Identifier: MIT
506
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
507
+ */
508
+ // when finding a slot in the DOM, we can fold it if it is contained
509
+ // inside another slot.
510
+ function foldSlotElement(slot) {
511
+ let parent = parentElementGetter.call(slot);
512
+ while (!isNull(parent) && isSlotElement(parent)) {
513
+ slot = parent;
514
+ parent = parentElementGetter.call(slot);
515
+ }
516
+ return slot;
517
+ }
518
+ function isNodeSlotted(host, node) {
519
+ if (process.env.NODE_ENV !== 'production') {
520
+ if (!(host instanceof HTMLElement)) {
521
+ // eslint-disable-next-line no-console
522
+ console.error(`isNodeSlotted() should be called with a host as the first argument`);
523
+ }
524
+ if (!(node instanceof _Node)) {
525
+ // eslint-disable-next-line no-console
526
+ console.error(`isNodeSlotted() should be called with a node as the second argument`);
527
+ }
528
+ if (!(compareDocumentPosition.call(node, host) & DOCUMENT_POSITION_CONTAINS)) {
529
+ // eslint-disable-next-line no-console
530
+ console.error(`isNodeSlotted() should never be called with a node that is not a child node of the given host`);
531
+ }
532
+ }
533
+ const hostKey = getNodeKey(host);
534
+ // this routine assumes that the node is coming from a different shadow (it is not owned by the host)
535
+ // just in case the provided node is not an element
536
+ let currentElement = node instanceof Element ? node : parentElementGetter.call(node);
537
+ while (!isNull(currentElement) && currentElement !== host) {
538
+ const elmOwnerKey = getNodeNearestOwnerKey(currentElement);
539
+ const parent = parentElementGetter.call(currentElement);
540
+ if (elmOwnerKey === hostKey) {
541
+ // we have reached an element inside the host's template, and only if
542
+ // that element is an slot, then the node is considered slotted
543
+ return isSlotElement(currentElement);
544
+ }
545
+ else if (parent === host) {
546
+ return false;
547
+ }
548
+ else if (!isNull(parent) && getNodeNearestOwnerKey(parent) !== elmOwnerKey) {
549
+ // we are crossing a boundary of some sort since the elm and its parent
550
+ // have different owner key. for slotted elements, this is possible
551
+ // if the parent happens to be a slot.
552
+ if (isSlotElement(parent)) {
553
+ /**
554
+ * the slot parent might be allocated inside another slot, think of:
555
+ * <x-root> (<--- root element)
556
+ * <x-parent> (<--- own by x-root)
557
+ * <x-child> (<--- own by x-root)
558
+ * <slot> (<--- own by x-child)
559
+ * <slot> (<--- own by x-parent)
560
+ * <div> (<--- own by x-root)
561
+ *
562
+ * while checking if x-parent has the div slotted, we need to traverse
563
+ * up, but when finding the first slot, we skip that one in favor of the
564
+ * most outer slot parent before jumping into its corresponding host.
565
+ */
566
+ currentElement = getNodeOwner(foldSlotElement(parent));
567
+ if (!isNull(currentElement)) {
568
+ if (currentElement === host) {
569
+ // the slot element is a top level element inside the shadow
570
+ // of a host that was allocated into host in question
571
+ return true;
572
+ }
573
+ else if (getNodeNearestOwnerKey(currentElement) === hostKey) {
574
+ // the slot element is an element inside the shadow
575
+ // of a host that was allocated into host in question
576
+ return true;
577
+ }
578
+ }
579
+ }
580
+ else {
581
+ return false;
582
+ }
583
+ }
584
+ else {
585
+ currentElement = parent;
586
+ }
587
+ }
588
+ return false;
589
+ }
590
+ function getNodeOwner(node) {
591
+ if (!(node instanceof _Node)) {
592
+ return null;
593
+ }
594
+ const ownerKey = getNodeNearestOwnerKey(node);
595
+ if (isUndefined(ownerKey)) {
596
+ return null;
597
+ }
598
+ let nodeOwner = node;
599
+ // At this point, node is a valid node with owner identity, now we need to find the owner node
600
+ // search for a custom element with a VM that owns the first element with owner identity attached to it
601
+ while (!isNull(nodeOwner) && getNodeKey(nodeOwner) !== ownerKey) {
602
+ nodeOwner = parentNodeGetter.call(nodeOwner);
603
+ }
604
+ if (isNull(nodeOwner)) {
605
+ return null;
606
+ }
607
+ return nodeOwner;
608
+ }
609
+ function isSyntheticSlotElement(node) {
610
+ return isSlotElement(node) && isNodeShadowed(node);
611
+ }
612
+ function isSlotElement(node) {
613
+ return node instanceof HTMLSlotElement;
614
+ }
615
+ function isNodeOwnedBy(owner, node) {
616
+ if (process.env.NODE_ENV !== 'production') {
617
+ if (!(owner instanceof HTMLElement)) {
618
+ // eslint-disable-next-line no-console
619
+ console.error(`isNodeOwnedBy() should be called with an element as the first argument`);
620
+ }
621
+ if (!(node instanceof _Node)) {
622
+ // eslint-disable-next-line no-console
623
+ console.error(`isNodeOwnedBy() should be called with a node as the second argument`);
624
+ }
625
+ if (!(compareDocumentPosition.call(node, owner) & DOCUMENT_POSITION_CONTAINS)) {
626
+ // eslint-disable-next-line no-console
627
+ console.error(`isNodeOwnedBy() should never be called with a node that is not a child node of of the given owner`);
628
+ }
629
+ }
630
+ const ownerKey = getNodeNearestOwnerKey(node);
631
+ if (isUndefined(ownerKey)) {
632
+ // in case of root level light DOM element slotting into a synthetic shadow
633
+ const host = parentNodeGetter.call(node);
634
+ if (!isNull(host) && isSyntheticSlotElement(host)) {
635
+ return false;
636
+ }
637
+ // in case of manually inserted elements
638
+ return true;
639
+ }
640
+ return getNodeKey(owner) === ownerKey;
641
+ }
642
+ function shadowRootChildNodes(root) {
643
+ const elm = getHost(root);
644
+ return getAllMatches(elm, arrayFromCollection(childNodesGetter.call(elm)));
645
+ }
646
+ function getAllSlottedMatches(host, nodeList) {
647
+ const filteredAndPatched = [];
648
+ for (let i = 0, len = nodeList.length; i < len; i += 1) {
649
+ const node = nodeList[i];
650
+ if (!isNodeOwnedBy(host, node) && isNodeSlotted(host, node)) {
651
+ ArrayPush.call(filteredAndPatched, node);
652
+ }
653
+ }
654
+ return filteredAndPatched;
655
+ }
656
+ function getFirstSlottedMatch(host, nodeList) {
657
+ for (let i = 0, len = nodeList.length; i < len; i += 1) {
658
+ const node = nodeList[i];
659
+ if (!isNodeOwnedBy(host, node) && isNodeSlotted(host, node)) {
660
+ return node;
661
+ }
662
+ }
663
+ return null;
664
+ }
665
+ function getAllMatches(owner, nodeList) {
666
+ const filteredAndPatched = [];
667
+ for (let i = 0, len = nodeList.length; i < len; i += 1) {
668
+ const node = nodeList[i];
669
+ const isOwned = isNodeOwnedBy(owner, node);
670
+ if (isOwned) {
671
+ // Patch querySelector, querySelectorAll, etc
672
+ // if element is owned by VM
673
+ ArrayPush.call(filteredAndPatched, node);
674
+ }
675
+ }
676
+ return filteredAndPatched;
677
+ }
678
+ function getFirstMatch(owner, nodeList) {
679
+ for (let i = 0, len = nodeList.length; i < len; i += 1) {
680
+ if (isNodeOwnedBy(owner, nodeList[i])) {
681
+ return nodeList[i];
682
+ }
683
+ }
684
+ return null;
685
+ }
686
+ function shadowRootQuerySelector(root, selector) {
687
+ const elm = getHost(root);
688
+ const nodeList = arrayFromCollection(querySelectorAll$1.call(elm, selector));
689
+ return getFirstMatch(elm, nodeList);
690
+ }
691
+ function shadowRootQuerySelectorAll(root, selector) {
692
+ const elm = getHost(root);
693
+ const nodeList = querySelectorAll$1.call(elm, selector);
694
+ return getAllMatches(elm, arrayFromCollection(nodeList));
695
+ }
696
+ function getFilteredChildNodes(node) {
697
+ if (!isSyntheticShadowHost(node) && !isSlotElement(node)) {
698
+ // regular element - fast path
699
+ const children = childNodesGetter.call(node);
700
+ return arrayFromCollection(children);
701
+ }
702
+ if (isSyntheticShadowHost(node)) {
703
+ // we need to get only the nodes that were slotted
704
+ const slots = arrayFromCollection(querySelectorAll$1.call(node, 'slot'));
705
+ const resolver = getShadowRootResolver(getShadowRoot(node));
706
+ // Typescript is inferring the wrong function type for this particular
707
+ // overloaded method: https://github.com/Microsoft/TypeScript/issues/27972
708
+ // @ts-ignore type-mismatch
709
+ return ArrayReduce.call(slots, (seed, slot) => {
710
+ if (resolver === getShadowRootResolver(slot)) {
711
+ ArrayPush.apply(seed, getFilteredSlotAssignedNodes(slot));
712
+ }
713
+ return seed;
714
+ }, []);
715
+ }
716
+ else {
717
+ // slot element
718
+ const children = arrayFromCollection(childNodesGetter.call(node));
719
+ const resolver = getShadowRootResolver(node);
720
+ return ArrayFilter.call(children, (child) => resolver === getShadowRootResolver(child));
721
+ }
722
+ }
723
+ function getFilteredSlotAssignedNodes(slot) {
724
+ const owner = getNodeOwner(slot);
725
+ if (isNull(owner)) {
726
+ return [];
727
+ }
728
+ const childNodes = arrayFromCollection(childNodesGetter.call(slot));
729
+ return ArrayFilter.call(childNodes, (child) => !isNodeShadowed(child) || !isNodeOwnedBy(owner, child));
730
+ }
731
+
732
+ /*
733
+ * Copyright (c) 2018, salesforce.com, inc.
734
+ * All rights reserved.
735
+ * SPDX-License-Identifier: MIT
736
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
737
+ */
738
+ /**
739
+ @license
740
+ Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
741
+ This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
742
+ The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
743
+ The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
744
+ Code distributed by Google as part of the polymer project is also
745
+ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
746
+ */
747
+ // This code is inspired by Polymer ShadyDOM Polyfill
748
+ function getInnerHTML(node) {
749
+ let s = '';
750
+ const childNodes = getFilteredChildNodes(node);
751
+ for (let i = 0, len = childNodes.length; i < len; i += 1) {
752
+ s += getOuterHTML(childNodes[i]);
753
+ }
754
+ return s;
755
+ }
756
+
757
+ /*
758
+ * Copyright (c) 2018, salesforce.com, inc.
759
+ * All rights reserved.
760
+ * SPDX-License-Identifier: MIT
761
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
762
+ */
763
+ /**
764
+ @license
765
+ Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
766
+ This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
767
+ The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
768
+ The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
769
+ Code distributed by Google as part of the polymer project is also
770
+ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
771
+ */
772
+ // This code is inspired by Polymer ShadyDOM Polyfill
773
+ // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#escapingString
774
+ const escapeAttrRegExp = /[&\u00A0"]/g;
775
+ const escapeDataRegExp = /[&\u00A0<>]/g;
776
+ const { replace, toLowerCase } = String.prototype;
777
+ function escapeReplace(c) {
778
+ switch (c) {
779
+ case '&':
780
+ return '&amp;';
781
+ case '<':
782
+ return '&lt;';
783
+ case '>':
784
+ return '&gt;';
785
+ case '"':
786
+ return '&quot;';
787
+ case '\u00A0':
788
+ return '&nbsp;';
789
+ default:
790
+ return '';
791
+ }
792
+ }
793
+ function escapeAttr(s) {
794
+ return replace.call(s, escapeAttrRegExp, escapeReplace);
795
+ }
796
+ function escapeData(s) {
797
+ return replace.call(s, escapeDataRegExp, escapeReplace);
798
+ }
799
+ // http://www.whatwg.org/specs/web-apps/current-work/#void-elements
800
+ const voidElements = new Set([
801
+ 'AREA',
802
+ 'BASE',
803
+ 'BR',
804
+ 'COL',
805
+ 'COMMAND',
806
+ 'EMBED',
807
+ 'HR',
808
+ 'IMG',
809
+ 'INPUT',
810
+ 'KEYGEN',
811
+ 'LINK',
812
+ 'META',
813
+ 'PARAM',
814
+ 'SOURCE',
815
+ 'TRACK',
816
+ 'WBR',
817
+ ]);
818
+ const plaintextParents = new Set([
819
+ 'STYLE',
820
+ 'SCRIPT',
821
+ 'XMP',
822
+ 'IFRAME',
823
+ 'NOEMBED',
824
+ 'NOFRAMES',
825
+ 'PLAINTEXT',
826
+ 'NOSCRIPT',
827
+ ]);
828
+ function getOuterHTML(node) {
829
+ switch (node.nodeType) {
830
+ case ELEMENT_NODE: {
831
+ const { attributes: attrs } = node;
832
+ const tagName = tagNameGetter.call(node);
833
+ let s = '<' + toLowerCase.call(tagName);
834
+ for (let i = 0, attr; (attr = attrs[i]); i++) {
835
+ s += ' ' + attr.name + '="' + escapeAttr(attr.value) + '"';
836
+ }
837
+ s += '>';
838
+ if (voidElements.has(tagName)) {
839
+ return s;
840
+ }
841
+ return s + getInnerHTML(node) + '</' + toLowerCase.call(tagName) + '>';
842
+ }
843
+ case TEXT_NODE: {
844
+ const { data, parentNode } = node;
845
+ if (parentNode instanceof Element &&
846
+ plaintextParents.has(tagNameGetter.call(parentNode))) {
847
+ return data;
848
+ }
849
+ return escapeData(data);
850
+ }
851
+ case CDATA_SECTION_NODE: {
852
+ return `<!CDATA[[${node.data}]]>`;
853
+ }
854
+ case PROCESSING_INSTRUCTION_NODE: {
855
+ return `<?${node.target} ${node.data}?>`;
856
+ }
857
+ case COMMENT_NODE: {
858
+ return `<!--${node.data}-->`;
859
+ }
860
+ default: {
861
+ // intentionally ignoring unknown node types
862
+ // Note: since this routine is always invoked for childNodes
863
+ // we can safety ignore type 9, 10 and 99 (document, fragment and doctype)
864
+ return '';
865
+ }
866
+ }
867
+ }
868
+
869
+ /*
870
+ * Copyright (c) 2018, salesforce.com, inc.
871
+ * All rights reserved.
872
+ * SPDX-License-Identifier: MIT
873
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
874
+ */
875
+ /**
876
+ @license
877
+ Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
878
+ This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
879
+ The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
880
+ The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
881
+ Code distributed by Google as part of the polymer project is also
882
+ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
883
+ */
884
+ // This code is inspired by Polymer ShadyDOM Polyfill
885
+ function getTextContent(node) {
886
+ switch (node.nodeType) {
887
+ case ELEMENT_NODE: {
888
+ const childNodes = getFilteredChildNodes(node);
889
+ let content = '';
890
+ for (let i = 0, len = childNodes.length; i < len; i += 1) {
891
+ const currentNode = childNodes[i];
892
+ if (currentNode.nodeType !== COMMENT_NODE) {
893
+ content += getTextContent(currentNode);
894
+ }
895
+ }
896
+ return content;
897
+ }
898
+ default:
899
+ return node.nodeValue;
900
+ }
901
+ }
902
+
903
+ /*
904
+ * Copyright (c) 2018, salesforce.com, inc.
905
+ * All rights reserved.
906
+ * SPDX-License-Identifier: MIT
907
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
908
+ */
909
+ const Items$1 = new WeakMap();
910
+ function StaticNodeList() {
911
+ throw new TypeError('Illegal constructor');
912
+ }
913
+ StaticNodeList.prototype = create(NodeList.prototype, {
914
+ constructor: {
915
+ writable: true,
916
+ configurable: true,
917
+ value: StaticNodeList,
918
+ },
919
+ item: {
920
+ writable: true,
921
+ enumerable: true,
922
+ configurable: true,
923
+ value(index) {
924
+ return this[index];
925
+ },
926
+ },
927
+ length: {
928
+ enumerable: true,
929
+ configurable: true,
930
+ get() {
931
+ return Items$1.get(this).length;
932
+ },
933
+ },
934
+ // Iterator protocol
935
+ forEach: {
936
+ writable: true,
937
+ enumerable: true,
938
+ configurable: true,
939
+ value(cb, thisArg) {
940
+ forEach.call(Items$1.get(this), cb, thisArg);
941
+ },
942
+ },
943
+ entries: {
944
+ writable: true,
945
+ enumerable: true,
946
+ configurable: true,
947
+ value() {
948
+ return ArrayMap.call(Items$1.get(this), (v, i) => [i, v]);
949
+ },
950
+ },
951
+ keys: {
952
+ writable: true,
953
+ enumerable: true,
954
+ configurable: true,
955
+ value() {
956
+ return ArrayMap.call(Items$1.get(this), (_v, i) => i);
957
+ },
958
+ },
959
+ values: {
960
+ writable: true,
961
+ enumerable: true,
962
+ configurable: true,
963
+ value() {
964
+ return Items$1.get(this);
965
+ },
966
+ },
967
+ [Symbol.iterator]: {
968
+ writable: true,
969
+ configurable: true,
970
+ value() {
971
+ let nextIndex = 0;
972
+ return {
973
+ next: () => {
974
+ const items = Items$1.get(this);
975
+ return nextIndex < items.length
976
+ ? {
977
+ value: items[nextIndex++],
978
+ done: false,
979
+ }
980
+ : {
981
+ done: true,
982
+ };
983
+ },
984
+ };
985
+ },
986
+ },
987
+ [Symbol.toStringTag]: {
988
+ configurable: true,
989
+ get() {
990
+ return 'NodeList';
991
+ },
992
+ },
993
+ // IE11 doesn't support Symbol.toStringTag, in which case we
994
+ // provide the regular toString method.
995
+ toString: {
996
+ writable: true,
997
+ configurable: true,
998
+ value() {
999
+ return '[object NodeList]';
1000
+ },
1001
+ },
1002
+ });
1003
+ // prototype inheritance dance
1004
+ setPrototypeOf(StaticNodeList, NodeList);
1005
+ function createStaticNodeList(items) {
1006
+ const nodeList = create(StaticNodeList.prototype);
1007
+ Items$1.set(nodeList, items);
1008
+ // setting static indexes
1009
+ forEach.call(items, (item, index) => {
1010
+ defineProperty(nodeList, index, {
1011
+ value: item,
1012
+ enumerable: true,
1013
+ configurable: true,
1014
+ });
1015
+ });
1016
+ return nodeList;
1017
+ }
1018
+
1019
+ /*
1020
+ * Copyright (c) 2018, salesforce.com, inc.
1021
+ * All rights reserved.
1022
+ * SPDX-License-Identifier: MIT
1023
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1024
+ */
1025
+ // Walk up the DOM tree, collecting all shadow roots plus the document root
1026
+ function getAllRootNodes(node) {
1027
+ var _a;
1028
+ const rootNodes = [];
1029
+ let currentRootNode = node.getRootNode();
1030
+ while (!isUndefined(currentRootNode)) {
1031
+ rootNodes.push(currentRootNode);
1032
+ currentRootNode = (_a = currentRootNode.host) === null || _a === void 0 ? void 0 : _a.getRootNode();
1033
+ }
1034
+ return rootNodes;
1035
+ }
1036
+ // Keep searching up the host tree until we find an element that is within the immediate shadow root
1037
+ const findAncestorHostInImmediateShadowRoot = (rootNode, targetRootNode) => {
1038
+ let host;
1039
+ while (!isUndefined((host = rootNode.host))) {
1040
+ const thisRootNode = host.getRootNode();
1041
+ if (thisRootNode === targetRootNode) {
1042
+ return host;
1043
+ }
1044
+ rootNode = thisRootNode;
1045
+ }
1046
+ };
1047
+ function fauxElementsFromPoint(context, doc, left, top) {
1048
+ const elements = elementsFromPoint.call(doc, left, top);
1049
+ const result = [];
1050
+ const rootNodes = getAllRootNodes(context);
1051
+ // Filter the elements array to only include those elements that are in this shadow root or in one of its
1052
+ // ancestor roots. This matches Chrome and Safari's implementation (but not Firefox's, which only includes
1053
+ // elements in the immediate shadow root: https://crbug.com/1207863#c4).
1054
+ if (!isNull(elements)) {
1055
+ // can be null in IE https://developer.mozilla.org/en-US/docs/Web/API/Document/elementsFromPoint#browser_compatibility
1056
+ for (let i = 0; i < elements.length; i++) {
1057
+ const element = elements[i];
1058
+ if (isSyntheticSlotElement(element)) {
1059
+ continue;
1060
+ }
1061
+ const elementRootNode = element.getRootNode();
1062
+ if (ArrayIndexOf.call(rootNodes, elementRootNode) !== -1) {
1063
+ ArrayPush.call(result, element);
1064
+ continue;
1065
+ }
1066
+ // In cases where the host element is not visible but its shadow descendants are, then
1067
+ // we may get the shadow descendant instead of the host element here. (The
1068
+ // browser doesn't know the difference in synthetic shadow DOM.)
1069
+ // In native shadow DOM, however, elementsFromPoint would return the host but not
1070
+ // the child. So we need to detect if this shadow element's host is accessible from
1071
+ // the context's shadow root. Note we also need to be careful not to add the host
1072
+ // multiple times.
1073
+ const ancestorHost = findAncestorHostInImmediateShadowRoot(elementRootNode, rootNodes[0]);
1074
+ if (!isUndefined(ancestorHost) &&
1075
+ ArrayIndexOf.call(elements, ancestorHost) === -1 &&
1076
+ ArrayIndexOf.call(result, ancestorHost) === -1) {
1077
+ ArrayPush.call(result, ancestorHost);
1078
+ }
1079
+ }
1080
+ }
1081
+ return result;
1082
+ }
1083
+
1084
+ /*
1085
+ * Copyright (c) 2018, salesforce.com, inc.
1086
+ * All rights reserved.
1087
+ * SPDX-License-Identifier: MIT
1088
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1089
+ */
1090
+ const Items = new WeakMap();
1091
+ function StaticHTMLCollection() {
1092
+ throw new TypeError('Illegal constructor');
1093
+ }
1094
+ StaticHTMLCollection.prototype = create(HTMLCollection.prototype, {
1095
+ constructor: {
1096
+ writable: true,
1097
+ configurable: true,
1098
+ value: StaticHTMLCollection,
1099
+ },
1100
+ item: {
1101
+ writable: true,
1102
+ enumerable: true,
1103
+ configurable: true,
1104
+ value(index) {
1105
+ return this[index];
1106
+ },
1107
+ },
1108
+ length: {
1109
+ enumerable: true,
1110
+ configurable: true,
1111
+ get() {
1112
+ return Items.get(this).length;
1113
+ },
1114
+ },
1115
+ // https://dom.spec.whatwg.org/#dom-htmlcollection-nameditem-key
1116
+ namedItem: {
1117
+ writable: true,
1118
+ enumerable: true,
1119
+ configurable: true,
1120
+ value(name) {
1121
+ if (name === '') {
1122
+ return null;
1123
+ }
1124
+ const items = Items.get(this);
1125
+ for (let i = 0, len = items.length; i < len; i++) {
1126
+ const item = items[len];
1127
+ if (name === getAttribute.call(item, 'id') ||
1128
+ name === getAttribute.call(item, 'name')) {
1129
+ return item;
1130
+ }
1131
+ }
1132
+ return null;
1133
+ },
1134
+ },
1135
+ [Symbol.toStringTag]: {
1136
+ configurable: true,
1137
+ get() {
1138
+ return 'HTMLCollection';
1139
+ },
1140
+ },
1141
+ // IE11 doesn't support Symbol.toStringTag, in which case we
1142
+ // provide the regular toString method.
1143
+ toString: {
1144
+ writable: true,
1145
+ configurable: true,
1146
+ value() {
1147
+ return '[object HTMLCollection]';
1148
+ },
1149
+ },
1150
+ });
1151
+ // prototype inheritance dance
1152
+ setPrototypeOf(StaticHTMLCollection, HTMLCollection);
1153
+ function createStaticHTMLCollection(items) {
1154
+ const collection = create(StaticHTMLCollection.prototype);
1155
+ Items.set(collection, items);
1156
+ // setting static indexes
1157
+ forEach.call(items, (item, index) => {
1158
+ defineProperty(collection, index, {
1159
+ value: item,
1160
+ enumerable: true,
1161
+ configurable: true,
1162
+ });
1163
+ });
1164
+ return collection;
1165
+ }
1166
+
1167
+ /*
1168
+ * Copyright (c) 2018, salesforce.com, inc.
1169
+ * All rights reserved.
1170
+ * SPDX-License-Identifier: MIT
1171
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1172
+ */
1173
+ /**
1174
+ * This method checks whether or not the content of the node is computed
1175
+ * based on the light-dom slotting mechanism. This applies to synthetic slot elements
1176
+ * and elements with shadow dom attached to them. It doesn't apply to native slot elements
1177
+ * because we don't want to patch the children getters for those elements.
1178
+ */
1179
+ function hasMountedChildren(node) {
1180
+ return isSyntheticSlotElement(node) || isSyntheticShadowHost(node);
1181
+ }
1182
+ function getShadowParent(node, value) {
1183
+ const owner = getNodeOwner(node);
1184
+ if (value === owner) {
1185
+ // walking up via parent chain might end up in the shadow root element
1186
+ return getShadowRoot(owner);
1187
+ }
1188
+ else if (value instanceof Element) {
1189
+ if (getNodeNearestOwnerKey(node) === getNodeNearestOwnerKey(value)) {
1190
+ // the element and its parent node belong to the same shadow root
1191
+ return value;
1192
+ }
1193
+ else if (!isNull(owner) && isSlotElement(value)) {
1194
+ // slotted elements must be top level childNodes of the slot element
1195
+ // where they slotted into, but its shadowed parent is always the
1196
+ // owner of the slot.
1197
+ const slotOwner = getNodeOwner(value);
1198
+ if (!isNull(slotOwner) && isNodeOwnedBy(owner, slotOwner)) {
1199
+ // it is a slotted element, and therefore its parent is always going to be the host of the slot
1200
+ return slotOwner;
1201
+ }
1202
+ }
1203
+ }
1204
+ return null;
1205
+ }
1206
+ function hasChildNodesPatched() {
1207
+ return getInternalChildNodes(this).length > 0;
1208
+ }
1209
+ function firstChildGetterPatched() {
1210
+ const childNodes = getInternalChildNodes(this);
1211
+ return childNodes[0] || null;
1212
+ }
1213
+ function lastChildGetterPatched() {
1214
+ const childNodes = getInternalChildNodes(this);
1215
+ return childNodes[childNodes.length - 1] || null;
1216
+ }
1217
+ function textContentGetterPatched() {
1218
+ return getTextContent(this);
1219
+ }
1220
+ function textContentSetterPatched(value) {
1221
+ textContextSetter.call(this, value);
1222
+ }
1223
+ function parentNodeGetterPatched() {
1224
+ const value = parentNodeGetter.call(this);
1225
+ if (isNull(value)) {
1226
+ return value;
1227
+ }
1228
+ // TODO [#1635]: this needs optimization, maybe implementing it based on this.assignedSlot
1229
+ return getShadowParent(this, value);
1230
+ }
1231
+ function parentElementGetterPatched() {
1232
+ const value = parentNodeGetter.call(this);
1233
+ if (isNull(value)) {
1234
+ return null;
1235
+ }
1236
+ const parentNode = getShadowParent(this, value);
1237
+ // it could be that the parentNode is the shadowRoot, in which case
1238
+ // we need to return null.
1239
+ // TODO [#1635]: this needs optimization, maybe implementing it based on this.assignedSlot
1240
+ return parentNode instanceof Element ? parentNode : null;
1241
+ }
1242
+ function compareDocumentPositionPatched(otherNode) {
1243
+ if (this === otherNode) {
1244
+ return 0;
1245
+ }
1246
+ else if (this.getRootNode() === otherNode) {
1247
+ // "this" is in a shadow tree where the shadow root is the "otherNode".
1248
+ return 10; // Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING
1249
+ }
1250
+ else if (getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
1251
+ // "this" and "otherNode" belongs to 2 different shadow tree.
1252
+ return 35; // Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | Node.DOCUMENT_POSITION_PRECEDING
1253
+ }
1254
+ // Since "this" and "otherNode" are part of the same shadow tree we can safely rely to the native
1255
+ // Node.compareDocumentPosition implementation.
1256
+ return compareDocumentPosition.call(this, otherNode);
1257
+ }
1258
+ function containsPatched(otherNode) {
1259
+ if (otherNode == null || getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
1260
+ // it is from another shadow
1261
+ return false;
1262
+ }
1263
+ return (compareDocumentPosition.call(this, otherNode) & DOCUMENT_POSITION_CONTAINED_BY) !== 0;
1264
+ }
1265
+ function cloneNodePatched(deep) {
1266
+ const clone = cloneNode.call(this, false);
1267
+ // Per spec, browsers only care about truthy values
1268
+ // Not strict true or false
1269
+ if (!deep) {
1270
+ return clone;
1271
+ }
1272
+ const childNodes = getInternalChildNodes(this);
1273
+ for (let i = 0, len = childNodes.length; i < len; i += 1) {
1274
+ clone.appendChild(childNodes[i].cloneNode(true));
1275
+ }
1276
+ return clone;
1277
+ }
1278
+ /**
1279
+ * This method only applies to elements with a shadow or slots
1280
+ */
1281
+ function childNodesGetterPatched() {
1282
+ if (isSyntheticShadowHost(this)) {
1283
+ const owner = getNodeOwner(this);
1284
+ const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
1285
+ if (process.env.NODE_ENV !== 'production' &&
1286
+ isFalse(hasNativeSymbolSupport) &&
1287
+ isExternalChildNodeAccessorFlagOn()) {
1288
+ // inserting a comment node as the first childNode to trick the IE11
1289
+ // DevTool to show the content of the shadowRoot, this should only happen
1290
+ // in dev-mode and in IE11 (which we detect by looking at the symbol).
1291
+ // Plus it should only be in place if we know it is an external invoker.
1292
+ ArrayUnshift.call(childNodes, getIE11FakeShadowRootPlaceholder(this));
1293
+ }
1294
+ return createStaticNodeList(childNodes);
1295
+ }
1296
+ // nothing to do here since this does not have a synthetic shadow attached to it
1297
+ // TODO [#1636]: what about slot elements?
1298
+ return childNodesGetter.call(this);
1299
+ }
1300
+ const nativeGetRootNode = _Node.prototype.getRootNode;
1301
+ /**
1302
+ * Get the root by climbing up the dom tree, beyond the shadow root
1303
+ * If Node.prototype.getRootNode is supported, use it
1304
+ * else, assume we are working in non-native shadow mode and climb using parentNode
1305
+ */
1306
+ const getDocumentOrRootNode = !isUndefined(nativeGetRootNode)
1307
+ ? nativeGetRootNode
1308
+ : function () {
1309
+ let node = this;
1310
+ let nodeParent;
1311
+ while (!isNull((nodeParent = parentNodeGetter.call(node)))) {
1312
+ node = nodeParent;
1313
+ }
1314
+ return node;
1315
+ };
1316
+ /**
1317
+ * Get the shadow root
1318
+ * getNodeOwner() returns the host element that owns the given node
1319
+ * Note: getNodeOwner() returns null when running in native-shadow mode.
1320
+ * Fallback to using the native getRootNode() to discover the root node.
1321
+ * This is because, it is not possible to inspect the node and decide if it is part
1322
+ * of a native shadow or the synthetic shadow.
1323
+ * @param {Node} node
1324
+ */
1325
+ function getNearestRoot(node) {
1326
+ const ownerNode = getNodeOwner(node);
1327
+ if (isNull(ownerNode)) {
1328
+ // we hit a wall, either we are in native shadow mode or the node is not in lwc boundary.
1329
+ return getDocumentOrRootNode.call(node);
1330
+ }
1331
+ return getShadowRoot(ownerNode);
1332
+ }
1333
+ /**
1334
+ * If looking for a root node beyond shadow root by calling `node.getRootNode({composed: true})`, use the original `Node.prototype.getRootNode` method
1335
+ * to return the root of the dom tree. In IE11 and Edge, Node.prototype.getRootNode is
1336
+ * [not supported](https://developer.mozilla.org/en-US/docs/Web/API/Node/getRootNode#Browser_compatibility). The root node is discovered by manually
1337
+ * climbing up the dom tree.
1338
+ *
1339
+ * If looking for a shadow root of a node by calling `node.getRootNode({composed: false})` or `node.getRootNode()`,
1340
+ *
1341
+ * 1. Try to identify the host element that owns the give node.
1342
+ * i. Identify the shadow tree that the node belongs to
1343
+ * ii. If the node belongs to a shadow tree created by engine, return the shadowRoot of the host element that owns the shadow tree
1344
+ * 2. The host identification logic returns null in two cases:
1345
+ * i. The node does not belong to a shadow tree created by engine
1346
+ * ii. The engine is running in native shadow dom mode
1347
+ * If so, use the original Node.prototype.getRootNode to fetch the root node(or manually climb up the dom tree where getRootNode() is unsupported)
1348
+ *
1349
+ * _Spec_: https://dom.spec.whatwg.org/#dom-node-getrootnode
1350
+ *
1351
+ **/
1352
+ function getRootNodePatched(options) {
1353
+ const composed = isUndefined(options) ? false : !!options.composed;
1354
+ return isTrue(composed) ? getDocumentOrRootNode.call(this, options) : getNearestRoot(this);
1355
+ }
1356
+ // Non-deep-traversing patches: this descriptor map includes all descriptors that
1357
+ // do not give access to nodes beyond the immediate children.
1358
+ defineProperties(_Node.prototype, {
1359
+ firstChild: {
1360
+ get() {
1361
+ if (hasMountedChildren(this)) {
1362
+ return firstChildGetterPatched.call(this);
1363
+ }
1364
+ return firstChildGetter.call(this);
1365
+ },
1366
+ enumerable: true,
1367
+ configurable: true,
1368
+ },
1369
+ lastChild: {
1370
+ get() {
1371
+ if (hasMountedChildren(this)) {
1372
+ return lastChildGetterPatched.call(this);
1373
+ }
1374
+ return lastChildGetter.call(this);
1375
+ },
1376
+ enumerable: true,
1377
+ configurable: true,
1378
+ },
1379
+ textContent: {
1380
+ get() {
1381
+ // Note: we deviate from native shadow here, but are not fixing
1382
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
1383
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1384
+ return textContentGetterPatched.call(this);
1385
+ }
1386
+ return textContentGetter.call(this);
1387
+ },
1388
+ set: textContentSetterPatched,
1389
+ enumerable: true,
1390
+ configurable: true,
1391
+ },
1392
+ parentNode: {
1393
+ get() {
1394
+ if (isNodeShadowed(this)) {
1395
+ return parentNodeGetterPatched.call(this);
1396
+ }
1397
+ const parentNode = parentNodeGetter.call(this);
1398
+ // Handle the case where a top level light DOM element is slotted into a synthetic
1399
+ // shadow slot.
1400
+ if (!isNull(parentNode) && isSyntheticSlotElement(parentNode)) {
1401
+ return getNodeOwner(parentNode);
1402
+ }
1403
+ return parentNode;
1404
+ },
1405
+ enumerable: true,
1406
+ configurable: true,
1407
+ },
1408
+ parentElement: {
1409
+ get() {
1410
+ if (isNodeShadowed(this)) {
1411
+ return parentElementGetterPatched.call(this);
1412
+ }
1413
+ const parentElement = parentElementGetter.call(this);
1414
+ // Handle the case where a top level light DOM element is slotted into a synthetic
1415
+ // shadow slot.
1416
+ if (!isNull(parentElement) && isSyntheticSlotElement(parentElement)) {
1417
+ return getNodeOwner(parentElement);
1418
+ }
1419
+ return parentElement;
1420
+ },
1421
+ enumerable: true,
1422
+ configurable: true,
1423
+ },
1424
+ childNodes: {
1425
+ get() {
1426
+ if (hasMountedChildren(this)) {
1427
+ return childNodesGetterPatched.call(this);
1428
+ }
1429
+ return childNodesGetter.call(this);
1430
+ },
1431
+ enumerable: true,
1432
+ configurable: true,
1433
+ },
1434
+ hasChildNodes: {
1435
+ value() {
1436
+ if (hasMountedChildren(this)) {
1437
+ return hasChildNodesPatched.call(this);
1438
+ }
1439
+ return hasChildNodes.call(this);
1440
+ },
1441
+ enumerable: true,
1442
+ writable: true,
1443
+ configurable: true,
1444
+ },
1445
+ compareDocumentPosition: {
1446
+ value(otherNode) {
1447
+ // Note: we deviate from native shadow here, but are not fixing
1448
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
1449
+ if (isGlobalPatchingSkipped(this)) {
1450
+ return compareDocumentPosition.call(this, otherNode);
1451
+ }
1452
+ return compareDocumentPositionPatched.call(this, otherNode);
1453
+ },
1454
+ enumerable: true,
1455
+ writable: true,
1456
+ configurable: true,
1457
+ },
1458
+ contains: {
1459
+ value(otherNode) {
1460
+ // 1. Node.prototype.contains() returns true if otherNode is an inclusive descendant
1461
+ // spec: https://dom.spec.whatwg.org/#dom-node-contains
1462
+ // 2. This normalizes the behavior of this api across all browsers.
1463
+ // In IE11, a disconnected dom element without children invoking contains() on self, returns false
1464
+ if (this === otherNode) {
1465
+ return true;
1466
+ }
1467
+ // Note: we deviate from native shadow here, but are not fixing
1468
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
1469
+ if (otherNode == null) {
1470
+ return false;
1471
+ }
1472
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1473
+ return containsPatched.call(this, otherNode);
1474
+ }
1475
+ return contains.call(this, otherNode);
1476
+ },
1477
+ enumerable: true,
1478
+ writable: true,
1479
+ configurable: true,
1480
+ },
1481
+ cloneNode: {
1482
+ value(deep) {
1483
+ // Note: we deviate from native shadow here, but are not fixing
1484
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
1485
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
1486
+ return cloneNodePatched.call(this, deep);
1487
+ }
1488
+ return cloneNode.call(this, deep);
1489
+ },
1490
+ enumerable: true,
1491
+ writable: true,
1492
+ configurable: true,
1493
+ },
1494
+ getRootNode: {
1495
+ value: getRootNodePatched,
1496
+ enumerable: true,
1497
+ configurable: true,
1498
+ writable: true,
1499
+ },
1500
+ isConnected: {
1501
+ enumerable: true,
1502
+ configurable: true,
1503
+ get() {
1504
+ return isConnected.call(this);
1505
+ },
1506
+ },
1507
+ });
1508
+ let internalChildNodeAccessorFlag = false;
1509
+ /**
1510
+ * These 2 methods are providing a machinery to understand who is accessing the
1511
+ * .childNodes member property of a node. If it is used from inside the synthetic shadow
1512
+ * or from an external invoker. This helps to produce the right output in one very peculiar
1513
+ * case, the IE11 debugging comment for shadowRoot representation on the devtool.
1514
+ */
1515
+ function isExternalChildNodeAccessorFlagOn() {
1516
+ return !internalChildNodeAccessorFlag;
1517
+ }
1518
+ const getInternalChildNodes = process.env.NODE_ENV !== 'production' && isFalse(hasNativeSymbolSupport)
1519
+ ? function (node) {
1520
+ internalChildNodeAccessorFlag = true;
1521
+ let childNodes;
1522
+ let error = null;
1523
+ try {
1524
+ childNodes = node.childNodes;
1525
+ }
1526
+ catch (e) {
1527
+ // childNodes accessor should never throw, but just in case!
1528
+ error = e;
1529
+ }
1530
+ finally {
1531
+ internalChildNodeAccessorFlag = false;
1532
+ if (!isNull(error)) {
1533
+ // re-throwing after restoring the state machinery for setInternalChildNodeAccessorFlag
1534
+ throw error; // eslint-disable-line no-unsafe-finally
1535
+ }
1536
+ }
1537
+ return childNodes;
1538
+ }
1539
+ : function (node) {
1540
+ return node.childNodes;
1541
+ };
1542
+ // IE11 extra patches for wrong prototypes
1543
+ if (hasOwnProperty.call(HTMLElement.prototype, 'contains')) {
1544
+ defineProperty(HTMLElement.prototype, 'contains', getOwnPropertyDescriptor(_Node.prototype, 'contains'));
1545
+ }
1546
+ if (hasOwnProperty.call(HTMLElement.prototype, 'parentElement')) {
1547
+ defineProperty(HTMLElement.prototype, 'parentElement', getOwnPropertyDescriptor(_Node.prototype, 'parentElement'));
1548
+ }
1549
+
1550
+ /*
1551
+ * Copyright (c) 2018, salesforce.com, inc.
1552
+ * All rights reserved.
1553
+ * SPDX-License-Identifier: MIT
1554
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1555
+ */
1556
+ const EventListenerMap = new WeakMap();
1557
+ const ComposedPathMap = new WeakMap();
1558
+ function isEventListenerOrEventListenerObject$1(fnOrObj) {
1559
+ return (isFunction(fnOrObj) ||
1560
+ (isObject(fnOrObj) &&
1561
+ !isNull(fnOrObj) &&
1562
+ isFunction(fnOrObj.handleEvent)));
1563
+ }
1564
+ function shouldInvokeListener(event, target, currentTarget) {
1565
+ // Subsequent logic assumes that `currentTarget` must be contained in the composed path for the listener to be
1566
+ // invoked, but this is not always the case. `composedPath()` will sometimes return an empty array, even when the
1567
+ // listener should be invoked (e.g., a disconnected instance of EventTarget, an instance of XMLHttpRequest, etc).
1568
+ if (target === currentTarget) {
1569
+ return true;
1570
+ }
1571
+ let composedPath = ComposedPathMap.get(event);
1572
+ if (isUndefined(composedPath)) {
1573
+ composedPath = event.composedPath();
1574
+ ComposedPathMap.set(event, composedPath);
1575
+ }
1576
+ return composedPath.includes(currentTarget);
1577
+ }
1578
+ function getEventListenerWrapper(fnOrObj) {
1579
+ if (!isEventListenerOrEventListenerObject$1(fnOrObj)) {
1580
+ return fnOrObj;
1581
+ }
1582
+ let wrapperFn = EventListenerMap.get(fnOrObj);
1583
+ if (isUndefined(wrapperFn)) {
1584
+ wrapperFn = function (event) {
1585
+ // This function is invoked from an event listener and currentTarget is always defined.
1586
+ const currentTarget = eventCurrentTargetGetter.call(event);
1587
+ if (process.env.NODE_ENV !== 'production') {
1588
+ assert.invariant(isFalse(isSyntheticShadowHost(currentTarget)), 'This routine should not be used to wrap event listeners for host elements and shadow roots.');
1589
+ }
1590
+ const actualTarget = getActualTarget(event);
1591
+ if (!shouldInvokeListener(event, actualTarget, currentTarget)) {
1592
+ return;
1593
+ }
1594
+ return isFunction(fnOrObj)
1595
+ ? fnOrObj.call(this, event)
1596
+ : fnOrObj.handleEvent && fnOrObj.handleEvent(event);
1597
+ };
1598
+ EventListenerMap.set(fnOrObj, wrapperFn);
1599
+ }
1600
+ return wrapperFn;
1601
+ }
1602
+
1603
+ /*
1604
+ * Copyright (c) 2018, salesforce.com, inc.
1605
+ * All rights reserved.
1606
+ * SPDX-License-Identifier: MIT
1607
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1608
+ */
1609
+ const eventToContextMap = new WeakMap();
1610
+ function getEventHandler(listener) {
1611
+ if (isFunction(listener)) {
1612
+ return listener;
1613
+ }
1614
+ else {
1615
+ return listener.handleEvent;
1616
+ }
1617
+ }
1618
+ function isEventListenerOrEventListenerObject(listener) {
1619
+ return isFunction(listener) || isFunction(listener === null || listener === void 0 ? void 0 : listener.handleEvent);
1620
+ }
1621
+ const customElementToWrappedListeners = new WeakMap();
1622
+ function getEventMap(elm) {
1623
+ let listenerInfo = customElementToWrappedListeners.get(elm);
1624
+ if (isUndefined(listenerInfo)) {
1625
+ listenerInfo = create(null);
1626
+ customElementToWrappedListeners.set(elm, listenerInfo);
1627
+ }
1628
+ return listenerInfo;
1629
+ }
1630
+ /**
1631
+ * Events dispatched on shadow roots actually end up being dispatched on their hosts. This means that the event.target
1632
+ * property of events dispatched on shadow roots always resolve to their host. This function understands this
1633
+ * abstraction and properly returns a reference to the shadow root when appropriate.
1634
+ */
1635
+ function getActualTarget(event) {
1636
+ var _a;
1637
+ return (_a = eventToShadowRootMap.get(event)) !== null && _a !== void 0 ? _a : eventTargetGetter.call(event);
1638
+ }
1639
+ const shadowRootEventListenerMap = new WeakMap();
1640
+ function getManagedShadowRootListener(listener) {
1641
+ if (!isEventListenerOrEventListenerObject(listener)) {
1642
+ throw new TypeError(); // avoiding problems with non-valid listeners
1643
+ }
1644
+ let managedListener = shadowRootEventListenerMap.get(listener);
1645
+ if (isUndefined(managedListener)) {
1646
+ managedListener = {
1647
+ identity: listener,
1648
+ placement: 1 /* EventListenerContext.SHADOW_ROOT_LISTENER */,
1649
+ handleEvent(event) {
1650
+ // currentTarget is always defined inside an event listener
1651
+ let currentTarget = eventCurrentTargetGetter.call(event);
1652
+ // If currentTarget is not an instance of a native shadow root then we're dealing with a
1653
+ // host element whose synthetic shadow root must be accessed via getShadowRoot().
1654
+ if (!isInstanceOfNativeShadowRoot(currentTarget)) {
1655
+ currentTarget = getShadowRoot(currentTarget);
1656
+ }
1657
+ const actualTarget = getActualTarget(event);
1658
+ if (shouldInvokeListener(event, actualTarget, currentTarget)) {
1659
+ getEventHandler(listener).call(currentTarget, event);
1660
+ }
1661
+ },
1662
+ };
1663
+ shadowRootEventListenerMap.set(listener, managedListener);
1664
+ }
1665
+ return managedListener;
1666
+ }
1667
+ const customElementEventListenerMap = new WeakMap();
1668
+ function getManagedCustomElementListener(listener) {
1669
+ if (!isEventListenerOrEventListenerObject(listener)) {
1670
+ throw new TypeError(); // avoiding problems with non-valid listeners
1671
+ }
1672
+ let managedListener = customElementEventListenerMap.get(listener);
1673
+ if (isUndefined(managedListener)) {
1674
+ managedListener = {
1675
+ identity: listener,
1676
+ placement: 0 /* EventListenerContext.CUSTOM_ELEMENT_LISTENER */,
1677
+ handleEvent(event) {
1678
+ // currentTarget is always defined inside an event listener
1679
+ const currentTarget = eventCurrentTargetGetter.call(event);
1680
+ const actualTarget = getActualTarget(event);
1681
+ if (shouldInvokeListener(event, actualTarget, currentTarget)) {
1682
+ getEventHandler(listener).call(currentTarget, event);
1683
+ }
1684
+ },
1685
+ };
1686
+ customElementEventListenerMap.set(listener, managedListener);
1687
+ }
1688
+ return managedListener;
1689
+ }
1690
+ function indexOfManagedListener(listeners, listener) {
1691
+ return ArrayFindIndex.call(listeners, (l) => l.identity === listener.identity);
1692
+ }
1693
+ function domListener(evt) {
1694
+ let immediatePropagationStopped = false;
1695
+ let propagationStopped = false;
1696
+ const { type, stopImmediatePropagation, stopPropagation } = evt;
1697
+ // currentTarget is always defined
1698
+ const currentTarget = eventCurrentTargetGetter.call(evt);
1699
+ const listenerMap = getEventMap(currentTarget);
1700
+ const listeners = listenerMap[type]; // it must have listeners at this point
1701
+ defineProperty(evt, 'stopImmediatePropagation', {
1702
+ value() {
1703
+ immediatePropagationStopped = true;
1704
+ stopImmediatePropagation.call(evt);
1705
+ },
1706
+ writable: true,
1707
+ enumerable: true,
1708
+ configurable: true,
1709
+ });
1710
+ defineProperty(evt, 'stopPropagation', {
1711
+ value() {
1712
+ propagationStopped = true;
1713
+ stopPropagation.call(evt);
1714
+ },
1715
+ writable: true,
1716
+ enumerable: true,
1717
+ configurable: true,
1718
+ });
1719
+ // in case a listener adds or removes other listeners during invocation
1720
+ const bookkeeping = ArraySlice.call(listeners);
1721
+ function invokeListenersByPlacement(placement) {
1722
+ forEach.call(bookkeeping, (listener) => {
1723
+ if (isFalse(immediatePropagationStopped) && listener.placement === placement) {
1724
+ // making sure that the listener was not removed from the original listener queue
1725
+ if (indexOfManagedListener(listeners, listener) !== -1) {
1726
+ // all handlers on the custom element should be called with undefined 'this'
1727
+ listener.handleEvent.call(undefined, evt);
1728
+ }
1729
+ }
1730
+ });
1731
+ }
1732
+ eventToContextMap.set(evt, 1 /* EventListenerContext.SHADOW_ROOT_LISTENER */);
1733
+ invokeListenersByPlacement(1 /* EventListenerContext.SHADOW_ROOT_LISTENER */);
1734
+ if (isFalse(immediatePropagationStopped) && isFalse(propagationStopped)) {
1735
+ // doing the second iteration only if the first one didn't interrupt the event propagation
1736
+ eventToContextMap.set(evt, 0 /* EventListenerContext.CUSTOM_ELEMENT_LISTENER */);
1737
+ invokeListenersByPlacement(0 /* EventListenerContext.CUSTOM_ELEMENT_LISTENER */);
1738
+ }
1739
+ eventToContextMap.set(evt, 2 /* EventListenerContext.UNKNOWN_LISTENER */);
1740
+ }
1741
+ function attachDOMListener(elm, type, managedListener) {
1742
+ const listenerMap = getEventMap(elm);
1743
+ let listeners = listenerMap[type];
1744
+ if (isUndefined(listeners)) {
1745
+ listeners = listenerMap[type] = [];
1746
+ }
1747
+ // Prevent identical listeners from subscribing to the same event type.
1748
+ // TODO [#1824]: Options will also play a factor in deduping if we introduce options support
1749
+ if (indexOfManagedListener(listeners, managedListener) !== -1) {
1750
+ return;
1751
+ }
1752
+ // only add to DOM if there is no other listener on the same placement yet
1753
+ if (listeners.length === 0) {
1754
+ addEventListener.call(elm, type, domListener);
1755
+ }
1756
+ ArrayPush.call(listeners, managedListener);
1757
+ }
1758
+ function detachDOMListener(elm, type, managedListener) {
1759
+ const listenerMap = getEventMap(elm);
1760
+ let index;
1761
+ let listeners;
1762
+ if (!isUndefined((listeners = listenerMap[type])) &&
1763
+ (index = indexOfManagedListener(listeners, managedListener)) !== -1) {
1764
+ ArraySplice.call(listeners, index, 1);
1765
+ // only remove from DOM if there is no other listener on the same placement
1766
+ if (listeners.length === 0) {
1767
+ removeEventListener.call(elm, type, domListener);
1768
+ }
1769
+ }
1770
+ }
1771
+ function addCustomElementEventListener(type, listener, _options) {
1772
+ if (process.env.NODE_ENV !== 'production') {
1773
+ if (!isEventListenerOrEventListenerObject(listener)) {
1774
+ throw new TypeError(`Invalid second argument for Element.addEventListener() in ${toString(this)} for event "${type}". Expected EventListener or EventListenerObject but received ${listener}.`);
1775
+ }
1776
+ }
1777
+ if (isEventListenerOrEventListenerObject(listener)) {
1778
+ const managedListener = getManagedCustomElementListener(listener);
1779
+ attachDOMListener(this, type, managedListener);
1780
+ }
1781
+ }
1782
+ function removeCustomElementEventListener(type, listener, _options) {
1783
+ if (isEventListenerOrEventListenerObject(listener)) {
1784
+ const managedListener = getManagedCustomElementListener(listener);
1785
+ detachDOMListener(this, type, managedListener);
1786
+ }
1787
+ }
1788
+ function addShadowRootEventListener(sr, type, listener, _options) {
1789
+ if (process.env.NODE_ENV !== 'production') {
1790
+ if (!isEventListenerOrEventListenerObject(listener)) {
1791
+ throw new TypeError(`Invalid second argument for ShadowRoot.addEventListener() in ${toString(sr)} for event "${type}". Expected EventListener or EventListenerObject but received ${listener}.`);
1792
+ }
1793
+ }
1794
+ if (isEventListenerOrEventListenerObject(listener)) {
1795
+ const elm = getHost(sr);
1796
+ const managedListener = getManagedShadowRootListener(listener);
1797
+ attachDOMListener(elm, type, managedListener);
1798
+ }
1799
+ }
1800
+ function removeShadowRootEventListener(sr, type, listener, _options) {
1801
+ if (isEventListenerOrEventListenerObject(listener)) {
1802
+ const elm = getHost(sr);
1803
+ const managedListener = getManagedShadowRootListener(listener);
1804
+ detachDOMListener(elm, type, managedListener);
1805
+ }
1806
+ }
1807
+
1808
+ /*
1809
+ * Copyright (c) 2018, salesforce.com, inc.
1810
+ * All rights reserved.
1811
+ * SPDX-License-Identifier: MIT
1812
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1813
+ */
1814
+ const InternalSlot = new WeakMap();
1815
+ const { createDocumentFragment } = document;
1816
+ function hasInternalSlot(root) {
1817
+ return InternalSlot.has(root);
1818
+ }
1819
+ function getInternalSlot(root) {
1820
+ const record = InternalSlot.get(root);
1821
+ if (isUndefined(record)) {
1822
+ throw new TypeError();
1823
+ }
1824
+ return record;
1825
+ }
1826
+ defineProperty(_Node.prototype, KEY__SHADOW_RESOLVER, {
1827
+ set(fn) {
1828
+ if (isUndefined(fn))
1829
+ return;
1830
+ this[KEY__SHADOW_RESOLVER_PRIVATE] = fn;
1831
+ // TODO [#1164]: temporary propagation of the key
1832
+ setNodeOwnerKey(this, fn.nodeKey);
1833
+ },
1834
+ get() {
1835
+ return this[KEY__SHADOW_RESOLVER_PRIVATE];
1836
+ },
1837
+ configurable: true,
1838
+ enumerable: true,
1839
+ });
1840
+ defineProperty(_globalThis, KEY__IS_NATIVE_SHADOW_ROOT_DEFINED, {
1841
+ value: isNativeShadowRootDefined,
1842
+ });
1843
+ // The isUndefined check is because two copies of synthetic shadow may be loaded on the same page, and this
1844
+ // would throw an error if we tried to redefine it. Plus the whole point is to expose the native method.
1845
+ if (isUndefined(_globalThis[KEY__NATIVE_GET_ELEMENT_BY_ID])) {
1846
+ defineProperty(_globalThis, KEY__NATIVE_GET_ELEMENT_BY_ID, {
1847
+ value: getElementById,
1848
+ configurable: true,
1849
+ });
1850
+ }
1851
+ // See note above.
1852
+ if (isUndefined(_globalThis[KEY__NATIVE_QUERY_SELECTOR_ALL])) {
1853
+ defineProperty(_globalThis, KEY__NATIVE_QUERY_SELECTOR_ALL, {
1854
+ value: querySelectorAll,
1855
+ configurable: true,
1856
+ });
1857
+ }
1858
+ function getShadowRootResolver(node) {
1859
+ return node[KEY__SHADOW_RESOLVER];
1860
+ }
1861
+ function setShadowRootResolver(node, fn) {
1862
+ node[KEY__SHADOW_RESOLVER] = fn;
1863
+ }
1864
+ function isDelegatingFocus(host) {
1865
+ return getInternalSlot(host).delegatesFocus;
1866
+ }
1867
+ function getHost(root) {
1868
+ return getInternalSlot(root).host;
1869
+ }
1870
+ function getShadowRoot(elm) {
1871
+ return getInternalSlot(elm).shadowRoot;
1872
+ }
1873
+ // Intentionally adding `Node` here in addition to `Element` since this check is harmless for nodes
1874
+ // and we can avoid having to cast the type before calling this method in a few places.
1875
+ function isSyntheticShadowHost(node) {
1876
+ const shadowRootRecord = InternalSlot.get(node);
1877
+ return !isUndefined(shadowRootRecord) && node === shadowRootRecord.host;
1878
+ }
1879
+ function isSyntheticShadowRoot(node) {
1880
+ const shadowRootRecord = InternalSlot.get(node);
1881
+ return !isUndefined(shadowRootRecord) && node === shadowRootRecord.shadowRoot;
1882
+ }
1883
+ let uid = 0;
1884
+ function attachShadow(elm, options) {
1885
+ if (InternalSlot.has(elm)) {
1886
+ throw new Error(`Failed to execute 'attachShadow' on 'Element': Shadow root cannot be created on a host which already hosts a shadow tree.`);
1887
+ }
1888
+ const { mode, delegatesFocus } = options;
1889
+ // creating a real fragment for shadowRoot instance
1890
+ const doc = getOwnerDocument(elm);
1891
+ const sr = createDocumentFragment.call(doc);
1892
+ // creating shadow internal record
1893
+ const record = {
1894
+ mode,
1895
+ delegatesFocus: !!delegatesFocus,
1896
+ host: elm,
1897
+ shadowRoot: sr,
1898
+ };
1899
+ InternalSlot.set(sr, record);
1900
+ InternalSlot.set(elm, record);
1901
+ const shadowResolver = () => sr;
1902
+ const x = (shadowResolver.nodeKey = uid++);
1903
+ setNodeKey(elm, x);
1904
+ setShadowRootResolver(sr, shadowResolver);
1905
+ // correcting the proto chain
1906
+ setPrototypeOf(sr, SyntheticShadowRoot.prototype);
1907
+ return sr;
1908
+ }
1909
+ const SyntheticShadowRootDescriptors = {
1910
+ constructor: {
1911
+ writable: true,
1912
+ configurable: true,
1913
+ value: SyntheticShadowRoot,
1914
+ },
1915
+ toString: {
1916
+ writable: true,
1917
+ configurable: true,
1918
+ value() {
1919
+ return `[object ShadowRoot]`;
1920
+ },
1921
+ },
1922
+ synthetic: {
1923
+ writable: false,
1924
+ enumerable: false,
1925
+ configurable: false,
1926
+ value: true,
1927
+ },
1928
+ };
1929
+ const ShadowRootDescriptors = {
1930
+ activeElement: {
1931
+ enumerable: true,
1932
+ configurable: true,
1933
+ get() {
1934
+ const host = getHost(this);
1935
+ const doc = getOwnerDocument(host);
1936
+ const activeElement = DocumentPrototypeActiveElement.call(doc);
1937
+ if (isNull(activeElement)) {
1938
+ return activeElement;
1939
+ }
1940
+ if ((compareDocumentPosition.call(host, activeElement) &
1941
+ DOCUMENT_POSITION_CONTAINED_BY) ===
1942
+ 0) {
1943
+ return null;
1944
+ }
1945
+ // activeElement must be child of the host and owned by it
1946
+ let node = activeElement;
1947
+ while (!isNodeOwnedBy(host, node)) {
1948
+ // parentElement is always an element because we are talking up the tree knowing
1949
+ // that it is a child of the host.
1950
+ node = parentElementGetter.call(node);
1951
+ }
1952
+ // If we have a slot element here that means that we were dealing
1953
+ // with an element that was passed to one of our slots. In this
1954
+ // case, activeElement returns null.
1955
+ if (isSlotElement(node)) {
1956
+ return null;
1957
+ }
1958
+ return node;
1959
+ },
1960
+ },
1961
+ delegatesFocus: {
1962
+ configurable: true,
1963
+ get() {
1964
+ return getInternalSlot(this).delegatesFocus;
1965
+ },
1966
+ },
1967
+ elementFromPoint: {
1968
+ writable: true,
1969
+ enumerable: true,
1970
+ configurable: true,
1971
+ value(left, top) {
1972
+ const host = getHost(this);
1973
+ const doc = getOwnerDocument(host);
1974
+ return fauxElementFromPoint(this, doc, left, top);
1975
+ },
1976
+ },
1977
+ elementsFromPoint: {
1978
+ writable: true,
1979
+ enumerable: true,
1980
+ configurable: true,
1981
+ value(left, top) {
1982
+ const host = getHost(this);
1983
+ const doc = getOwnerDocument(host);
1984
+ return fauxElementsFromPoint(this, doc, left, top);
1985
+ },
1986
+ },
1987
+ getSelection: {
1988
+ writable: true,
1989
+ enumerable: true,
1990
+ configurable: true,
1991
+ value() {
1992
+ throw new Error('Disallowed method "getSelection" on ShadowRoot.');
1993
+ },
1994
+ },
1995
+ host: {
1996
+ enumerable: true,
1997
+ configurable: true,
1998
+ get() {
1999
+ return getHost(this);
2000
+ },
2001
+ },
2002
+ mode: {
2003
+ configurable: true,
2004
+ get() {
2005
+ return getInternalSlot(this).mode;
2006
+ },
2007
+ },
2008
+ styleSheets: {
2009
+ enumerable: true,
2010
+ configurable: true,
2011
+ get() {
2012
+ throw new Error();
2013
+ },
2014
+ },
2015
+ };
2016
+ const eventToShadowRootMap = new WeakMap();
2017
+ const NodePatchDescriptors = {
2018
+ insertBefore: {
2019
+ writable: true,
2020
+ enumerable: true,
2021
+ configurable: true,
2022
+ value(newChild, refChild) {
2023
+ insertBefore.call(getHost(this), newChild, refChild);
2024
+ return newChild;
2025
+ },
2026
+ },
2027
+ removeChild: {
2028
+ writable: true,
2029
+ enumerable: true,
2030
+ configurable: true,
2031
+ value(oldChild) {
2032
+ removeChild.call(getHost(this), oldChild);
2033
+ return oldChild;
2034
+ },
2035
+ },
2036
+ appendChild: {
2037
+ writable: true,
2038
+ enumerable: true,
2039
+ configurable: true,
2040
+ value(newChild) {
2041
+ appendChild.call(getHost(this), newChild);
2042
+ return newChild;
2043
+ },
2044
+ },
2045
+ replaceChild: {
2046
+ writable: true,
2047
+ enumerable: true,
2048
+ configurable: true,
2049
+ value(newChild, oldChild) {
2050
+ replaceChild.call(getHost(this), newChild, oldChild);
2051
+ return oldChild;
2052
+ },
2053
+ },
2054
+ addEventListener: {
2055
+ writable: true,
2056
+ enumerable: true,
2057
+ configurable: true,
2058
+ value(type, listener, options) {
2059
+ addShadowRootEventListener(this, type, listener);
2060
+ },
2061
+ },
2062
+ dispatchEvent: {
2063
+ writable: true,
2064
+ enumerable: true,
2065
+ configurable: true,
2066
+ value(evt) {
2067
+ eventToShadowRootMap.set(evt, this);
2068
+ // Typescript does not like it when you treat the `arguments` object as an array
2069
+ // @ts-ignore type-mismatch
2070
+ return dispatchEvent.apply(getHost(this), arguments);
2071
+ },
2072
+ },
2073
+ removeEventListener: {
2074
+ writable: true,
2075
+ enumerable: true,
2076
+ configurable: true,
2077
+ value(type, listener, options) {
2078
+ removeShadowRootEventListener(this, type, listener);
2079
+ },
2080
+ },
2081
+ baseURI: {
2082
+ enumerable: true,
2083
+ configurable: true,
2084
+ get() {
2085
+ return getHost(this).baseURI;
2086
+ },
2087
+ },
2088
+ childNodes: {
2089
+ enumerable: true,
2090
+ configurable: true,
2091
+ get() {
2092
+ return createStaticNodeList(shadowRootChildNodes(this));
2093
+ },
2094
+ },
2095
+ cloneNode: {
2096
+ writable: true,
2097
+ enumerable: true,
2098
+ configurable: true,
2099
+ value() {
2100
+ throw new Error('Disallowed method "cloneNode" on ShadowRoot.');
2101
+ },
2102
+ },
2103
+ compareDocumentPosition: {
2104
+ writable: true,
2105
+ enumerable: true,
2106
+ configurable: true,
2107
+ value(otherNode) {
2108
+ const host = getHost(this);
2109
+ if (this === otherNode) {
2110
+ // "this" and "otherNode" are the same shadow root.
2111
+ return 0;
2112
+ }
2113
+ else if (this.contains(otherNode)) {
2114
+ // "otherNode" belongs to the shadow tree where "this" is the shadow root.
2115
+ return 20; // Node.DOCUMENT_POSITION_CONTAINED_BY | Node.DOCUMENT_POSITION_FOLLOWING
2116
+ }
2117
+ else if (compareDocumentPosition.call(host, otherNode) & DOCUMENT_POSITION_CONTAINED_BY) {
2118
+ // "otherNode" is in a different shadow tree contained by the shadow tree where "this" is the shadow root.
2119
+ return 37; // Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_FOLLOWING | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
2120
+ }
2121
+ else {
2122
+ // "otherNode" is in a different shadow tree that is not contained by the shadow tree where "this" is the shadow root.
2123
+ return 35; // Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_PRECEDING | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
2124
+ }
2125
+ },
2126
+ },
2127
+ contains: {
2128
+ writable: true,
2129
+ enumerable: true,
2130
+ configurable: true,
2131
+ value(otherNode) {
2132
+ if (this === otherNode) {
2133
+ return true;
2134
+ }
2135
+ const host = getHost(this);
2136
+ // must be child of the host and owned by it.
2137
+ return ((compareDocumentPosition.call(host, otherNode) & DOCUMENT_POSITION_CONTAINED_BY) !==
2138
+ 0 && isNodeOwnedBy(host, otherNode));
2139
+ },
2140
+ },
2141
+ firstChild: {
2142
+ enumerable: true,
2143
+ configurable: true,
2144
+ get() {
2145
+ const childNodes = getInternalChildNodes(this);
2146
+ return childNodes[0] || null;
2147
+ },
2148
+ },
2149
+ lastChild: {
2150
+ enumerable: true,
2151
+ configurable: true,
2152
+ get() {
2153
+ const childNodes = getInternalChildNodes(this);
2154
+ return childNodes[childNodes.length - 1] || null;
2155
+ },
2156
+ },
2157
+ hasChildNodes: {
2158
+ writable: true,
2159
+ enumerable: true,
2160
+ configurable: true,
2161
+ value() {
2162
+ const childNodes = getInternalChildNodes(this);
2163
+ return childNodes.length > 0;
2164
+ },
2165
+ },
2166
+ isConnected: {
2167
+ enumerable: true,
2168
+ configurable: true,
2169
+ get() {
2170
+ return isConnected.call(getHost(this));
2171
+ },
2172
+ },
2173
+ nextSibling: {
2174
+ enumerable: true,
2175
+ configurable: true,
2176
+ get() {
2177
+ return null;
2178
+ },
2179
+ },
2180
+ previousSibling: {
2181
+ enumerable: true,
2182
+ configurable: true,
2183
+ get() {
2184
+ return null;
2185
+ },
2186
+ },
2187
+ nodeName: {
2188
+ enumerable: true,
2189
+ configurable: true,
2190
+ get() {
2191
+ return '#document-fragment';
2192
+ },
2193
+ },
2194
+ nodeType: {
2195
+ enumerable: true,
2196
+ configurable: true,
2197
+ get() {
2198
+ return 11; // Node.DOCUMENT_FRAGMENT_NODE
2199
+ },
2200
+ },
2201
+ nodeValue: {
2202
+ enumerable: true,
2203
+ configurable: true,
2204
+ get() {
2205
+ return null;
2206
+ },
2207
+ },
2208
+ ownerDocument: {
2209
+ enumerable: true,
2210
+ configurable: true,
2211
+ get() {
2212
+ return getHost(this).ownerDocument;
2213
+ },
2214
+ },
2215
+ parentElement: {
2216
+ enumerable: true,
2217
+ configurable: true,
2218
+ get() {
2219
+ return null;
2220
+ },
2221
+ },
2222
+ parentNode: {
2223
+ enumerable: true,
2224
+ configurable: true,
2225
+ get() {
2226
+ return null;
2227
+ },
2228
+ },
2229
+ textContent: {
2230
+ enumerable: true,
2231
+ configurable: true,
2232
+ get() {
2233
+ const childNodes = getInternalChildNodes(this);
2234
+ let textContent = '';
2235
+ for (let i = 0, len = childNodes.length; i < len; i += 1) {
2236
+ const currentNode = childNodes[i];
2237
+ if (currentNode.nodeType !== COMMENT_NODE) {
2238
+ textContent += getTextContent(currentNode);
2239
+ }
2240
+ }
2241
+ return textContent;
2242
+ },
2243
+ set(v) {
2244
+ const host = getHost(this);
2245
+ textContextSetter.call(host, v);
2246
+ },
2247
+ },
2248
+ // Since the synthetic shadow root is a detached DocumentFragment, short-circuit the getRootNode behavior
2249
+ getRootNode: {
2250
+ writable: true,
2251
+ enumerable: true,
2252
+ configurable: true,
2253
+ value(options) {
2254
+ return !isUndefined(options) && isTrue(options.composed)
2255
+ ? getHost(this).getRootNode(options)
2256
+ : this;
2257
+ },
2258
+ },
2259
+ };
2260
+ const ElementPatchDescriptors = {
2261
+ innerHTML: {
2262
+ enumerable: true,
2263
+ configurable: true,
2264
+ get() {
2265
+ const childNodes = getInternalChildNodes(this);
2266
+ let innerHTML = '';
2267
+ for (let i = 0, len = childNodes.length; i < len; i += 1) {
2268
+ innerHTML += getOuterHTML(childNodes[i]);
2269
+ }
2270
+ return innerHTML;
2271
+ },
2272
+ set(v) {
2273
+ const host = getHost(this);
2274
+ innerHTMLSetter.call(host, v);
2275
+ },
2276
+ },
2277
+ };
2278
+ const ParentNodePatchDescriptors = {
2279
+ childElementCount: {
2280
+ enumerable: true,
2281
+ configurable: true,
2282
+ get() {
2283
+ return this.children.length;
2284
+ },
2285
+ },
2286
+ children: {
2287
+ enumerable: true,
2288
+ configurable: true,
2289
+ get() {
2290
+ return createStaticHTMLCollection(ArrayFilter.call(shadowRootChildNodes(this), (elm) => elm instanceof Element));
2291
+ },
2292
+ },
2293
+ firstElementChild: {
2294
+ enumerable: true,
2295
+ configurable: true,
2296
+ get() {
2297
+ return this.children[0] || null;
2298
+ },
2299
+ },
2300
+ lastElementChild: {
2301
+ enumerable: true,
2302
+ configurable: true,
2303
+ get() {
2304
+ const { children } = this;
2305
+ return children.item(children.length - 1) || null;
2306
+ },
2307
+ },
2308
+ getElementById: {
2309
+ writable: true,
2310
+ enumerable: true,
2311
+ configurable: true,
2312
+ value() {
2313
+ throw new Error('Disallowed method "getElementById" on ShadowRoot.');
2314
+ },
2315
+ },
2316
+ querySelector: {
2317
+ writable: true,
2318
+ enumerable: true,
2319
+ configurable: true,
2320
+ value(selectors) {
2321
+ return shadowRootQuerySelector(this, selectors);
2322
+ },
2323
+ },
2324
+ querySelectorAll: {
2325
+ writable: true,
2326
+ enumerable: true,
2327
+ configurable: true,
2328
+ value(selectors) {
2329
+ return createStaticNodeList(shadowRootQuerySelectorAll(this, selectors));
2330
+ },
2331
+ },
2332
+ };
2333
+ assign(SyntheticShadowRootDescriptors, NodePatchDescriptors, ParentNodePatchDescriptors, ElementPatchDescriptors, ShadowRootDescriptors);
2334
+ function SyntheticShadowRoot() {
2335
+ throw new TypeError('Illegal constructor');
2336
+ }
2337
+ SyntheticShadowRoot.prototype = create(DocumentFragment.prototype, SyntheticShadowRootDescriptors);
2338
+ // `this.shadowRoot instanceof ShadowRoot` should evaluate to true even for synthetic shadow
2339
+ defineProperty(SyntheticShadowRoot, Symbol.hasInstance, {
2340
+ value: function (object) {
2341
+ // Technically we should walk up the entire prototype chain, but with SyntheticShadowRoot
2342
+ // it's reasonable to assume that no one is doing any deep subclasses here.
2343
+ return (isObject(object) &&
2344
+ !isNull(object) &&
2345
+ (isInstanceOfNativeShadowRoot(object) ||
2346
+ getPrototypeOf(object) === SyntheticShadowRoot.prototype));
2347
+ },
2348
+ });
2349
+ /**
2350
+ * This method is only intended to be used in non-production mode in IE11
2351
+ * and its role is to produce a 1-1 mapping between a shadowRoot instance
2352
+ * and a comment node that is intended to use to trick the IE11 DevTools
2353
+ * to show the content of the shadowRoot in the DOM Explorer.
2354
+ */
2355
+ function getIE11FakeShadowRootPlaceholder(host) {
2356
+ const shadowRoot = getShadowRoot(host);
2357
+ // @ts-ignore this $$placeholder$$ is not a security issue because you must
2358
+ // have access to the shadowRoot in order to extract the fake node, which give
2359
+ // you access to the same childNodes of the shadowRoot, so, who cares.
2360
+ let c = shadowRoot.$$placeholder$$;
2361
+ if (!isUndefined(c)) {
2362
+ return c;
2363
+ }
2364
+ const doc = getOwnerDocument(host);
2365
+ // @ts-ignore $$placeholder$$ is fine, read the node above.
2366
+ c = shadowRoot.$$placeholder$$ = createComment.call(doc, '');
2367
+ defineProperties(c, {
2368
+ childNodes: {
2369
+ get() {
2370
+ return shadowRoot.childNodes;
2371
+ },
2372
+ enumerable: true,
2373
+ configurable: true,
2374
+ },
2375
+ tagName: {
2376
+ get() {
2377
+ return `#shadow-root (${shadowRoot.mode})`;
2378
+ },
2379
+ enumerable: true,
2380
+ configurable: true,
2381
+ },
2382
+ });
2383
+ return c;
2384
+ }
2385
+
2386
+ /*
2387
+ * Copyright (c) 2018, salesforce.com, inc.
2388
+ * All rights reserved.
2389
+ * SPDX-License-Identifier: MIT
2390
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2391
+ */
2392
+ /**
2393
+ @license
2394
+ Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
2395
+ This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
2396
+ The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
2397
+ The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
2398
+ Code distributed by Google as part of the polymer project is also
2399
+ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
2400
+ */
2401
+ function pathComposer(startNode, composed) {
2402
+ const composedPath = [];
2403
+ let startRoot;
2404
+ if (startNode instanceof Window) {
2405
+ startRoot = startNode;
2406
+ }
2407
+ else if (startNode instanceof _Node) {
2408
+ startRoot = startNode.getRootNode();
2409
+ }
2410
+ else {
2411
+ return composedPath;
2412
+ }
2413
+ let current = startNode;
2414
+ while (!isNull(current)) {
2415
+ composedPath.push(current);
2416
+ if (current instanceof Element || current instanceof Text) {
2417
+ const assignedSlot = current.assignedSlot;
2418
+ if (!isNull(assignedSlot)) {
2419
+ current = assignedSlot;
2420
+ }
2421
+ else {
2422
+ current = current.parentNode;
2423
+ }
2424
+ }
2425
+ else if ((isSyntheticShadowRoot(current) || isInstanceOfNativeShadowRoot(current)) &&
2426
+ (composed || current !== startRoot)) {
2427
+ current = current.host;
2428
+ }
2429
+ else if (current instanceof _Node) {
2430
+ current = current.parentNode;
2431
+ }
2432
+ else {
2433
+ // could be Window
2434
+ current = null;
2435
+ }
2436
+ }
2437
+ let doc;
2438
+ if (startNode instanceof Window) {
2439
+ doc = startNode.document;
2440
+ }
2441
+ else {
2442
+ doc = getOwnerDocument(startNode);
2443
+ }
2444
+ // event composedPath includes window when startNode's ownerRoot is document
2445
+ if (composedPath[composedPath.length - 1] === doc) {
2446
+ composedPath.push(window);
2447
+ }
2448
+ return composedPath;
2449
+ }
2450
+
2451
+ /*
2452
+ * Copyright (c) 2018, salesforce.com, inc.
2453
+ * All rights reserved.
2454
+ * SPDX-License-Identifier: MIT
2455
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2456
+ */
2457
+ /**
2458
+ @license
2459
+ Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
2460
+ This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
2461
+ The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
2462
+ The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
2463
+ Code distributed by Google as part of the polymer project is also
2464
+ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
2465
+ */
2466
+ function retarget(refNode, path) {
2467
+ if (isNull(refNode)) {
2468
+ return null;
2469
+ }
2470
+ // If ANCESTOR's root is not a shadow root or ANCESTOR's root is BASE's
2471
+ // shadow-including inclusive ancestor, return ANCESTOR.
2472
+ const refNodePath = pathComposer(refNode, true);
2473
+ const p$ = path;
2474
+ for (let i = 0, ancestor, lastRoot, root, rootIdx; i < p$.length; i++) {
2475
+ ancestor = p$[i];
2476
+ root = ancestor instanceof Window ? ancestor : ancestor.getRootNode();
2477
+ if (root !== lastRoot) {
2478
+ rootIdx = refNodePath.indexOf(root);
2479
+ lastRoot = root;
2480
+ }
2481
+ if (!isSyntheticShadowRoot(root) || (!isUndefined(rootIdx) && rootIdx > -1)) {
2482
+ return ancestor;
2483
+ }
2484
+ }
2485
+ return null;
2486
+ }
2487
+
2488
+ /*
2489
+ * Copyright (c) 2018, salesforce.com, inc.
2490
+ * All rights reserved.
2491
+ * SPDX-License-Identifier: MIT
2492
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2493
+ */
2494
+ function fauxElementFromPoint(context, doc, left, top) {
2495
+ const element = elementFromPoint.call(doc, left, top);
2496
+ if (isNull(element)) {
2497
+ return element;
2498
+ }
2499
+ return retarget(context, pathComposer(element, true));
2500
+ }
2501
+
2502
+ /*
2503
+ * Copyright (c) 2018, salesforce.com, inc.
2504
+ * All rights reserved.
2505
+ * SPDX-License-Identifier: MIT
2506
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2507
+ */
2508
+ function elemFromPoint(left, top) {
2509
+ return fauxElementFromPoint(this, this, left, top);
2510
+ }
2511
+ Document.prototype.elementFromPoint = elemFromPoint;
2512
+ function elemsFromPoint(left, top) {
2513
+ return fauxElementsFromPoint(this, this, left, top);
2514
+ }
2515
+ Document.prototype.elementsFromPoint = elemsFromPoint;
2516
+ // Go until we reach to top of the LWC tree
2517
+ defineProperty(Document.prototype, 'activeElement', {
2518
+ get() {
2519
+ let node = DocumentPrototypeActiveElement.call(this);
2520
+ if (isNull(node)) {
2521
+ return node;
2522
+ }
2523
+ while (!isUndefined(getNodeOwnerKey(node))) {
2524
+ node = parentElementGetter.call(node);
2525
+ if (isNull(node)) {
2526
+ return null;
2527
+ }
2528
+ }
2529
+ if (node.tagName === 'HTML') {
2530
+ // IE 11. Active element should never be html element
2531
+ node = this.body;
2532
+ }
2533
+ return node;
2534
+ },
2535
+ enumerable: true,
2536
+ configurable: true,
2537
+ });
2538
+ // The following patched methods hide shadowed elements from global
2539
+ // traversing mechanisms. They are simplified for performance reasons to
2540
+ // filter by ownership and do not account for slotted elements. This
2541
+ // compromise is fine for our synthetic shadow dom because root elements
2542
+ // cannot have slotted elements.
2543
+ // Another compromise here is that all these traversing methods will return
2544
+ // static HTMLCollection or static NodeList. We decided that this compromise
2545
+ // is not a big problem considering the amount of code that is relying on
2546
+ // the liveliness of these results are rare.
2547
+ defineProperty(Document.prototype, 'getElementById', {
2548
+ value() {
2549
+ const elm = getElementById.apply(this, ArraySlice.call(arguments));
2550
+ if (isNull(elm)) {
2551
+ return null;
2552
+ }
2553
+ // Note: we deviate from native shadow here, but are not fixing
2554
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2555
+ return isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm) ? elm : null;
2556
+ },
2557
+ writable: true,
2558
+ enumerable: true,
2559
+ configurable: true,
2560
+ });
2561
+ defineProperty(Document.prototype, 'querySelector', {
2562
+ value() {
2563
+ const elements = arrayFromCollection(querySelectorAll.apply(this, ArraySlice.call(arguments)));
2564
+ const filtered = ArrayFind.call(elements,
2565
+ // Note: we deviate from native shadow here, but are not fixing
2566
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2567
+ (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2568
+ return !isUndefined(filtered) ? filtered : null;
2569
+ },
2570
+ writable: true,
2571
+ enumerable: true,
2572
+ configurable: true,
2573
+ });
2574
+ defineProperty(Document.prototype, 'querySelectorAll', {
2575
+ value() {
2576
+ const elements = arrayFromCollection(querySelectorAll.apply(this, ArraySlice.call(arguments)));
2577
+ const filtered = ArrayFilter.call(elements,
2578
+ // Note: we deviate from native shadow here, but are not fixing
2579
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2580
+ (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2581
+ return createStaticNodeList(filtered);
2582
+ },
2583
+ writable: true,
2584
+ enumerable: true,
2585
+ configurable: true,
2586
+ });
2587
+ defineProperty(Document.prototype, 'getElementsByClassName', {
2588
+ value() {
2589
+ const elements = arrayFromCollection(getElementsByClassName.apply(this, ArraySlice.call(arguments)));
2590
+ const filtered = ArrayFilter.call(elements,
2591
+ // Note: we deviate from native shadow here, but are not fixing
2592
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2593
+ (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2594
+ return createStaticHTMLCollection(filtered);
2595
+ },
2596
+ writable: true,
2597
+ enumerable: true,
2598
+ configurable: true,
2599
+ });
2600
+ defineProperty(Document.prototype, 'getElementsByTagName', {
2601
+ value() {
2602
+ const elements = arrayFromCollection(getElementsByTagName.apply(this, ArraySlice.call(arguments)));
2603
+ const filtered = ArrayFilter.call(elements,
2604
+ // Note: we deviate from native shadow here, but are not fixing
2605
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2606
+ (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2607
+ return createStaticHTMLCollection(filtered);
2608
+ },
2609
+ writable: true,
2610
+ enumerable: true,
2611
+ configurable: true,
2612
+ });
2613
+ defineProperty(Document.prototype, 'getElementsByTagNameNS', {
2614
+ value() {
2615
+ const elements = arrayFromCollection(getElementsByTagNameNS.apply(this, ArraySlice.call(arguments)));
2616
+ const filtered = ArrayFilter.call(elements,
2617
+ // Note: we deviate from native shadow here, but are not fixing
2618
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2619
+ (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2620
+ return createStaticHTMLCollection(filtered);
2621
+ },
2622
+ writable: true,
2623
+ enumerable: true,
2624
+ configurable: true,
2625
+ });
2626
+ defineProperty(
2627
+ // In Firefox v57 and lower, getElementsByName is defined on HTMLDocument.prototype
2628
+ getOwnPropertyDescriptor(HTMLDocument.prototype, 'getElementsByName')
2629
+ ? HTMLDocument.prototype
2630
+ : Document.prototype, 'getElementsByName', {
2631
+ value() {
2632
+ const elements = arrayFromCollection(getElementsByName.apply(this, ArraySlice.call(arguments)));
2633
+ const filtered = ArrayFilter.call(elements,
2634
+ // Note: we deviate from native shadow here, but are not fixing
2635
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
2636
+ (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
2637
+ return createStaticNodeList(filtered);
2638
+ },
2639
+ writable: true,
2640
+ enumerable: true,
2641
+ configurable: true,
2642
+ });
2643
+
2644
+ /*
2645
+ * Copyright (c) 2018, salesforce.com, inc.
2646
+ * All rights reserved.
2647
+ * SPDX-License-Identifier: MIT
2648
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2649
+ */
2650
+ Object.defineProperty(window, 'ShadowRoot', {
2651
+ value: SyntheticShadowRoot,
2652
+ configurable: true,
2653
+ writable: true,
2654
+ });
2655
+
2656
+ /*
2657
+ * Copyright (c) 2018, salesforce.com, inc.
2658
+ * All rights reserved.
2659
+ * SPDX-License-Identifier: MIT
2660
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2661
+ */
2662
+ const composedDescriptor = Object.getOwnPropertyDescriptor(Event.prototype, 'composed');
2663
+ function detect$3() {
2664
+ if (!composedDescriptor) {
2665
+ // No need to apply this polyfill if this client completely lacks
2666
+ // support for the composed property.
2667
+ return false;
2668
+ }
2669
+ // Assigning a throwaway click event here to suppress a ts error when we
2670
+ // pass clickEvent into the composed getter below. The error is:
2671
+ // [ts] Variable 'clickEvent' is used before being assigned.
2672
+ let clickEvent = new Event('click');
2673
+ const button = document.createElement('button');
2674
+ button.addEventListener('click', (event) => (clickEvent = event));
2675
+ button.click();
2676
+ return !composedDescriptor.get.call(clickEvent);
2677
+ }
2678
+
2679
+ /*
2680
+ * Copyright (c) 2018, salesforce.com, inc.
2681
+ * All rights reserved.
2682
+ * SPDX-License-Identifier: MIT
2683
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2684
+ */
2685
+ const originalClickDescriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'click');
2686
+ function handleClick(event) {
2687
+ Object.defineProperty(event, 'composed', {
2688
+ configurable: true,
2689
+ enumerable: true,
2690
+ get() {
2691
+ return true;
2692
+ },
2693
+ });
2694
+ }
2695
+ function apply$3() {
2696
+ HTMLElement.prototype.click = function () {
2697
+ addEventListener.call(this, 'click', handleClick);
2698
+ try {
2699
+ originalClickDescriptor.value.call(this);
2700
+ }
2701
+ finally {
2702
+ removeEventListener.call(this, 'click', handleClick);
2703
+ }
2704
+ };
2705
+ }
2706
+
2707
+ /*
2708
+ * Copyright (c) 2018, salesforce.com, inc.
2709
+ * All rights reserved.
2710
+ * SPDX-License-Identifier: MIT
2711
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2712
+ */
2713
+ if (detect$3()) {
2714
+ apply$3();
2715
+ }
2716
+
2717
+ /*
2718
+ * Copyright (c) 2018, salesforce.com, inc.
2719
+ * All rights reserved.
2720
+ * SPDX-License-Identifier: MIT
2721
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2722
+ */
2723
+ function detect$2() {
2724
+ return new Event('test', { composed: true }).composed !== true;
2725
+ }
2726
+
2727
+ /*
2728
+ * Copyright (c) 2018, salesforce.com, inc.
2729
+ * All rights reserved.
2730
+ * SPDX-License-Identifier: MIT
2731
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2732
+ */
2733
+ function apply$2() {
2734
+ // https://github.com/w3c/webcomponents/issues/513#issuecomment-224183937
2735
+ const composedEvents = assign(create(null), {
2736
+ beforeinput: 1,
2737
+ blur: 1,
2738
+ click: 1,
2739
+ compositionend: 1,
2740
+ compositionstart: 1,
2741
+ compositionupdate: 1,
2742
+ copy: 1,
2743
+ cut: 1,
2744
+ dblclick: 1,
2745
+ DOMActivate: 1,
2746
+ DOMFocusIn: 1,
2747
+ DOMFocusOut: 1,
2748
+ drag: 1,
2749
+ dragend: 1,
2750
+ dragenter: 1,
2751
+ dragleave: 1,
2752
+ dragover: 1,
2753
+ dragstart: 1,
2754
+ drop: 1,
2755
+ focus: 1,
2756
+ focusin: 1,
2757
+ focusout: 1,
2758
+ gotpointercapture: 1,
2759
+ input: 1,
2760
+ keydown: 1,
2761
+ keypress: 1,
2762
+ keyup: 1,
2763
+ lostpointercapture: 1,
2764
+ mousedown: 1,
2765
+ mouseenter: 1,
2766
+ mouseleave: 1,
2767
+ mousemove: 1,
2768
+ mouseout: 1,
2769
+ mouseover: 1,
2770
+ mouseup: 1,
2771
+ paste: 1,
2772
+ pointercancel: 1,
2773
+ pointerdown: 1,
2774
+ pointerenter: 1,
2775
+ pointerleave: 1,
2776
+ pointermove: 1,
2777
+ pointerout: 1,
2778
+ pointerover: 1,
2779
+ pointerup: 1,
2780
+ touchcancel: 1,
2781
+ touchend: 1,
2782
+ touchmove: 1,
2783
+ touchstart: 1,
2784
+ wheel: 1,
2785
+ });
2786
+ const EventConstructor = Event;
2787
+ // Patch Event constructor to add the composed property on events created via new Event.
2788
+ function PatchedEvent(type, eventInitDict) {
2789
+ const event = new EventConstructor(type, eventInitDict);
2790
+ const isComposed = !!(eventInitDict && eventInitDict.composed);
2791
+ Object.defineProperties(event, {
2792
+ composed: {
2793
+ get() {
2794
+ return isComposed;
2795
+ },
2796
+ configurable: true,
2797
+ enumerable: true,
2798
+ },
2799
+ });
2800
+ return event;
2801
+ }
2802
+ PatchedEvent.prototype = EventConstructor.prototype;
2803
+ PatchedEvent.AT_TARGET = EventConstructor.AT_TARGET;
2804
+ PatchedEvent.BUBBLING_PHASE = EventConstructor.BUBBLING_PHASE;
2805
+ PatchedEvent.CAPTURING_PHASE = EventConstructor.CAPTURING_PHASE;
2806
+ PatchedEvent.NONE = EventConstructor.NONE;
2807
+ window.Event = PatchedEvent;
2808
+ // Patch the Event prototype to add the composed property on user agent dispatched event.
2809
+ Object.defineProperties(Event.prototype, {
2810
+ composed: {
2811
+ get() {
2812
+ const { type } = this;
2813
+ return composedEvents[type] === 1;
2814
+ },
2815
+ configurable: true,
2816
+ enumerable: true,
2817
+ },
2818
+ });
2819
+ }
2820
+
2821
+ /*
2822
+ * Copyright (c) 2018, salesforce.com, inc.
2823
+ * All rights reserved.
2824
+ * SPDX-License-Identifier: MIT
2825
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2826
+ */
2827
+ if (detect$2()) {
2828
+ apply$2();
2829
+ }
2830
+
2831
+ /*
2832
+ * Copyright (c) 2018, salesforce.com, inc.
2833
+ * All rights reserved.
2834
+ * SPDX-License-Identifier: MIT
2835
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2836
+ */
2837
+ const CustomEventConstructor = CustomEvent;
2838
+ function PatchedCustomEvent(type, eventInitDict) {
2839
+ const event = new CustomEventConstructor(type, eventInitDict);
2840
+ const isComposed = !!(eventInitDict && eventInitDict.composed);
2841
+ Object.defineProperties(event, {
2842
+ composed: {
2843
+ get() {
2844
+ return isComposed;
2845
+ },
2846
+ configurable: true,
2847
+ enumerable: true,
2848
+ },
2849
+ });
2850
+ return event;
2851
+ }
2852
+ PatchedCustomEvent.prototype = CustomEventConstructor.prototype;
2853
+ window.CustomEvent = PatchedCustomEvent;
2854
+
2855
+ /*
2856
+ * Copyright (c) 2018, salesforce.com, inc.
2857
+ * All rights reserved.
2858
+ * SPDX-License-Identifier: MIT
2859
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2860
+ */
2861
+ if (typeof ClipboardEvent !== 'undefined') {
2862
+ const isComposedType = assign(create(null), {
2863
+ copy: 1,
2864
+ cut: 1,
2865
+ paste: 1,
2866
+ });
2867
+ // Patch the prototype to override the composed property on user-agent dispatched events
2868
+ defineProperties(ClipboardEvent.prototype, {
2869
+ composed: {
2870
+ get() {
2871
+ const { type } = this;
2872
+ return isComposedType[type] === 1;
2873
+ },
2874
+ configurable: true,
2875
+ enumerable: true,
2876
+ },
2877
+ });
2878
+ }
2879
+
2880
+ /*
2881
+ * Copyright (c) 2018, salesforce.com, inc.
2882
+ * All rights reserved.
2883
+ * SPDX-License-Identifier: MIT
2884
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2885
+ */
2886
+ function detect$1() {
2887
+ // Note: when using this in mobile apps, we might have a DOM that does not support iframes.
2888
+ const hasIframe = typeof HTMLIFrameElement !== 'undefined';
2889
+ // This polyfill should only apply in compat mode; see https://github.com/salesforce/lwc/issues/1513
2890
+ const isCompat = typeof Proxy !== 'undefined' && isTrue(Proxy.isCompat);
2891
+ return hasIframe && isCompat;
2892
+ }
2893
+
2894
+ /*
2895
+ * Copyright (c) 2018, salesforce.com, inc.
2896
+ * All rights reserved.
2897
+ * SPDX-License-Identifier: MIT
2898
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2899
+ */
2900
+ function apply$1() {
2901
+ // the iframe property descriptor for `contentWindow` should always be available, otherwise this method should never be called
2902
+ const desc = getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentWindow');
2903
+ const { get: originalGetter } = desc;
2904
+ desc.get = function () {
2905
+ const original = originalGetter.call(this);
2906
+ // If the original iframe element is not a keyed node, then do not wrap it
2907
+ if (isNull(original) || isUndefined(getNodeOwnerKey(this))) {
2908
+ return original;
2909
+ }
2910
+ // only if the element is an iframe inside a shadowRoot, we care about this problem
2911
+ // because in that case, the code that is accessing the iframe, is very likely code
2912
+ // compiled with proxy-compat transformation. It is true that other code without those
2913
+ // transformations might also access an iframe from within a shadowRoot, but in that,
2914
+ // case, which is more rare, we still return the wrapper, and it should work the same,
2915
+ // this part is just an optimization.
2916
+ return wrapIframeWindow(original);
2917
+ };
2918
+ defineProperty(HTMLIFrameElement.prototype, 'contentWindow', desc);
2919
+ }
2920
+ function wrapIframeWindow(win) {
2921
+ return {
2922
+ addEventListener() {
2923
+ // Typescript does not like it when you treat the `arguments` object as an array
2924
+ // @ts-ignore type-mismatch
2925
+ return win.addEventListener.apply(win, arguments);
2926
+ },
2927
+ blur() {
2928
+ // Typescript does not like it when you treat the `arguments` object as an array
2929
+ // @ts-ignore type-mismatch
2930
+ return win.blur.apply(win, arguments);
2931
+ },
2932
+ close() {
2933
+ // Typescript does not like it when you treat the `arguments` object as an array
2934
+ // @ts-ignore type-mismatch
2935
+ return win.close.apply(win, arguments);
2936
+ },
2937
+ focus() {
2938
+ // Typescript does not like it when you treat the `arguments` object as an array
2939
+ // @ts-ignore type-mismatch
2940
+ return win.focus.apply(win, arguments);
2941
+ },
2942
+ postMessage() {
2943
+ // Typescript does not like it when you treat the `arguments` object as an array
2944
+ // @ts-ignore type-mismatch
2945
+ return win.postMessage.apply(win, arguments);
2946
+ },
2947
+ removeEventListener() {
2948
+ // Typescript does not like it when you treat the `arguments` object as an array
2949
+ // @ts-ignore type-mismatch
2950
+ return win.removeEventListener.apply(win, arguments);
2951
+ },
2952
+ get closed() {
2953
+ return win.closed;
2954
+ },
2955
+ get frames() {
2956
+ return win.frames;
2957
+ },
2958
+ get length() {
2959
+ return win.length;
2960
+ },
2961
+ get location() {
2962
+ return win.location;
2963
+ },
2964
+ set location(value) {
2965
+ win.location = value;
2966
+ },
2967
+ get opener() {
2968
+ return win.opener;
2969
+ },
2970
+ get parent() {
2971
+ return win.parent;
2972
+ },
2973
+ get self() {
2974
+ return win.self;
2975
+ },
2976
+ get top() {
2977
+ return win.top;
2978
+ },
2979
+ get window() {
2980
+ return win.window;
2981
+ },
2982
+ }; // this is limited
2983
+ }
2984
+
2985
+ /*
2986
+ * Copyright (c) 2018, salesforce.com, inc.
2987
+ * All rights reserved.
2988
+ * SPDX-License-Identifier: MIT
2989
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2990
+ */
2991
+ if (detect$1()) {
2992
+ apply$1();
2993
+ }
2994
+
2995
+ /*
2996
+ * Copyright (c) 2018, salesforce.com, inc.
2997
+ * All rights reserved.
2998
+ * SPDX-License-Identifier: MIT
2999
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3000
+ */
3001
+ const OriginalMutationObserver = MutationObserver;
3002
+ const { disconnect: originalDisconnect, observe: originalObserve, takeRecords: originalTakeRecords, } = OriginalMutationObserver.prototype;
3003
+ // Internal fields to maintain relationships
3004
+ const wrapperLookupField = '$$lwcObserverCallbackWrapper$$';
3005
+ const observerLookupField = '$$lwcNodeObservers$$';
3006
+ const observerToNodesMap = new WeakMap();
3007
+ function getNodeObservers(node) {
3008
+ return node[observerLookupField];
3009
+ }
3010
+ function setNodeObservers(node, observers) {
3011
+ node[observerLookupField] = observers;
3012
+ }
3013
+ /**
3014
+ * Retarget the mutation record's target value to its shadowRoot
3015
+ * @param {MutationRecord} originalRecord
3016
+ */
3017
+ function retargetMutationRecord(originalRecord) {
3018
+ const { addedNodes, removedNodes, target, type } = originalRecord;
3019
+ const retargetedRecord = create(MutationRecord.prototype);
3020
+ defineProperties(retargetedRecord, {
3021
+ addedNodes: {
3022
+ get() {
3023
+ return addedNodes;
3024
+ },
3025
+ enumerable: true,
3026
+ configurable: true,
3027
+ },
3028
+ removedNodes: {
3029
+ get() {
3030
+ return removedNodes;
3031
+ },
3032
+ enumerable: true,
3033
+ configurable: true,
3034
+ },
3035
+ type: {
3036
+ get() {
3037
+ return type;
3038
+ },
3039
+ enumerable: true,
3040
+ configurable: true,
3041
+ },
3042
+ target: {
3043
+ get() {
3044
+ return target.shadowRoot;
3045
+ },
3046
+ enumerable: true,
3047
+ configurable: true,
3048
+ },
3049
+ });
3050
+ return retargetedRecord;
3051
+ }
3052
+ /**
3053
+ * Utility to identify if a target node is being observed by the given observer
3054
+ * Start at the current node, if the observer is registered to observe the current node, the mutation qualifies
3055
+ * @param {MutationObserver} observer
3056
+ * @param {Node} target
3057
+ */
3058
+ function isQualifiedObserver(observer, target) {
3059
+ let parentNode = target;
3060
+ while (!isNull(parentNode)) {
3061
+ const parentNodeObservers = getNodeObservers(parentNode);
3062
+ if (!isUndefined(parentNodeObservers) &&
3063
+ (parentNodeObservers[0] === observer || // perf optimization to check for the first item is a match
3064
+ ArrayIndexOf.call(parentNodeObservers, observer) !== -1)) {
3065
+ return true;
3066
+ }
3067
+ parentNode = parentNode.parentNode;
3068
+ }
3069
+ return false;
3070
+ }
3071
+ /**
3072
+ * This function provides a shadow dom compliant filtered view of mutation records for a given observer.
3073
+ *
3074
+ * The key logic here is to determine if a given observer has been registered to observe any nodes
3075
+ * between the target node of a mutation record to the target's root node.
3076
+ * This function also retargets records when mutations occur directly under the shadow root
3077
+ * @param {MutationRecords[]} mutations
3078
+ * @param {MutationObserver} observer
3079
+ */
3080
+ function filterMutationRecords(mutations, observer) {
3081
+ return ArrayReduce.call(mutations, (filteredSet, record) => {
3082
+ const { target, addedNodes, removedNodes, type } = record;
3083
+ // If target is an lwc host,
3084
+ // Determine if the mutations affected the host or the shadowRoot
3085
+ // Mutations affecting host: changes to slot content
3086
+ // Mutations affecting shadowRoot: changes to template content
3087
+ if (type === 'childList' && !isUndefined(getNodeKey(target))) {
3088
+ // In case of added nodes, we can climb up the tree and determine eligibility
3089
+ if (addedNodes.length > 0) {
3090
+ // Optimization: Peek in and test one node to decide if the MutationRecord qualifies
3091
+ // The remaining nodes in this MutationRecord will have the same ownerKey
3092
+ const sampleNode = addedNodes[0];
3093
+ if (isQualifiedObserver(observer, sampleNode)) {
3094
+ // If the target was being observed, then return record as-is
3095
+ // this will be the case for slot content
3096
+ const nodeObservers = getNodeObservers(target);
3097
+ if (nodeObservers &&
3098
+ (nodeObservers[0] === observer ||
3099
+ ArrayIndexOf.call(nodeObservers, observer) !== -1)) {
3100
+ ArrayPush.call(filteredSet, record);
3101
+ }
3102
+ else {
3103
+ // else, must be observing the shadowRoot
3104
+ ArrayPush.call(filteredSet, retargetMutationRecord(record));
3105
+ }
3106
+ }
3107
+ }
3108
+ else {
3109
+ // In the case of removed nodes, climbing the tree is not an option as the nodes are disconnected
3110
+ // We can only check if either the host or shadow root was observed and qualify the record
3111
+ const shadowRoot = target.shadowRoot;
3112
+ const sampleNode = removedNodes[0];
3113
+ if (getNodeNearestOwnerKey(target) === getNodeNearestOwnerKey(sampleNode) && // trickery: sampleNode is slot content
3114
+ isQualifiedObserver(observer, target) // use target as a close enough reference to climb up
3115
+ ) {
3116
+ ArrayPush.call(filteredSet, record);
3117
+ }
3118
+ else if (shadowRoot) {
3119
+ const shadowRootObservers = getNodeObservers(shadowRoot);
3120
+ if (shadowRootObservers &&
3121
+ (shadowRootObservers[0] === observer ||
3122
+ ArrayIndexOf.call(shadowRootObservers, observer) !== -1)) {
3123
+ ArrayPush.call(filteredSet, retargetMutationRecord(record));
3124
+ }
3125
+ }
3126
+ }
3127
+ }
3128
+ else {
3129
+ // Mutation happened under a root node(shadow root or document) and the decision is straighforward
3130
+ // Ascend the tree starting from target and check if observer is qualified
3131
+ if (isQualifiedObserver(observer, target)) {
3132
+ ArrayPush.call(filteredSet, record);
3133
+ }
3134
+ }
3135
+ return filteredSet;
3136
+ }, []);
3137
+ }
3138
+ function getWrappedCallback(callback) {
3139
+ let wrappedCallback = callback[wrapperLookupField];
3140
+ if (isUndefined(wrappedCallback)) {
3141
+ wrappedCallback = callback[wrapperLookupField] = (mutations, observer) => {
3142
+ // Filter mutation records
3143
+ const filteredRecords = filterMutationRecords(mutations, observer);
3144
+ // If not records are eligible for the observer, do not invoke callback
3145
+ if (filteredRecords.length === 0) {
3146
+ return;
3147
+ }
3148
+ callback.call(observer, filteredRecords, observer);
3149
+ };
3150
+ }
3151
+ return wrappedCallback;
3152
+ }
3153
+ /**
3154
+ * Patched MutationObserver constructor.
3155
+ * 1. Wrap the callback to filter out MutationRecords based on dom ownership
3156
+ * 2. Add a property field to track all observed targets of the observer instance
3157
+ * @param {MutationCallback} callback
3158
+ */
3159
+ function PatchedMutationObserver(callback) {
3160
+ const wrappedCallback = getWrappedCallback(callback);
3161
+ const observer = new OriginalMutationObserver(wrappedCallback);
3162
+ return observer;
3163
+ }
3164
+ function patchedDisconnect() {
3165
+ originalDisconnect.call(this);
3166
+ // Clear the node to observer reference which is a strong references
3167
+ const observedNodes = observerToNodesMap.get(this);
3168
+ if (!isUndefined(observedNodes)) {
3169
+ forEach.call(observedNodes, (observedNode) => {
3170
+ const observers = observedNode[observerLookupField];
3171
+ if (!isUndefined(observers)) {
3172
+ const index = ArrayIndexOf.call(observers, this);
3173
+ if (index !== -1) {
3174
+ ArraySplice.call(observers, index, 1);
3175
+ }
3176
+ }
3177
+ });
3178
+ observedNodes.length = 0;
3179
+ }
3180
+ }
3181
+ /**
3182
+ * A single mutation observer can observe multiple nodes(target).
3183
+ * Maintain a list of all targets that the observer chooses to observe
3184
+ * @param {Node} target
3185
+ * @param {Object} options
3186
+ */
3187
+ function patchedObserve(target, options) {
3188
+ let targetObservers = getNodeObservers(target);
3189
+ // Maintain a list of all observers that want to observe a node
3190
+ if (isUndefined(targetObservers)) {
3191
+ targetObservers = [];
3192
+ setNodeObservers(target, targetObservers);
3193
+ }
3194
+ // Same observer trying to observe the same node
3195
+ if (ArrayIndexOf.call(targetObservers, this) === -1) {
3196
+ ArrayPush.call(targetObservers, this);
3197
+ } // else There is more bookkeeping to do here https://dom.spec.whatwg.org/#dom-mutationobserver-observe Step #7
3198
+ // SyntheticShadowRoot instances are not actually a part of the DOM so observe the host instead.
3199
+ if (isSyntheticShadowRoot(target)) {
3200
+ target = target.host;
3201
+ }
3202
+ // maintain a list of all nodes observed by this observer
3203
+ if (observerToNodesMap.has(this)) {
3204
+ const observedNodes = observerToNodesMap.get(this);
3205
+ if (ArrayIndexOf.call(observedNodes, target) === -1) {
3206
+ ArrayPush.call(observedNodes, target);
3207
+ }
3208
+ }
3209
+ else {
3210
+ observerToNodesMap.set(this, [target]);
3211
+ }
3212
+ return originalObserve.call(this, target, options);
3213
+ }
3214
+ /**
3215
+ * Patch the takeRecords() api to filter MutationRecords based on the observed targets
3216
+ */
3217
+ function patchedTakeRecords() {
3218
+ return filterMutationRecords(originalTakeRecords.call(this), this);
3219
+ }
3220
+ PatchedMutationObserver.prototype = OriginalMutationObserver.prototype;
3221
+ PatchedMutationObserver.prototype.disconnect = patchedDisconnect;
3222
+ PatchedMutationObserver.prototype.observe = patchedObserve;
3223
+ PatchedMutationObserver.prototype.takeRecords = patchedTakeRecords;
3224
+ defineProperty(window, 'MutationObserver', {
3225
+ value: PatchedMutationObserver,
3226
+ configurable: true,
3227
+ writable: true,
3228
+ });
3229
+
3230
+ /*
3231
+ * Copyright (c) 2018, salesforce.com, inc.
3232
+ * All rights reserved.
3233
+ * SPDX-License-Identifier: MIT
3234
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3235
+ */
3236
+ function patchedAddEventListener$1(type, listener, optionsOrCapture) {
3237
+ if (isSyntheticShadowHost(this)) {
3238
+ // Typescript does not like it when you treat the `arguments` object as an array
3239
+ // @ts-ignore type-mismatch
3240
+ return addCustomElementEventListener.apply(this, arguments);
3241
+ }
3242
+ if (arguments.length < 2) {
3243
+ // Slow path, unlikely to be called frequently. We expect modern browsers to throw:
3244
+ // https://googlechrome.github.io/samples/event-listeners-mandatory-arguments/
3245
+ const args = ArraySlice.call(arguments);
3246
+ if (args.length > 1) {
3247
+ args[1] = getEventListenerWrapper(args[1]);
3248
+ }
3249
+ // Ignore types because we're passing through to native method
3250
+ // @ts-ignore type-mismatch
3251
+ return addEventListener.apply(this, args);
3252
+ }
3253
+ // Fast path. This function is optimized to avoid ArraySlice because addEventListener is called
3254
+ // very frequently, and it provides a measurable perf boost to avoid so much array cloning.
3255
+ const wrappedListener = getEventListenerWrapper(listener);
3256
+ // The third argument is optional, so passing in `undefined` for `optionsOrCapture` gives capture=false
3257
+ return addEventListener.call(this, type, wrappedListener, optionsOrCapture);
3258
+ }
3259
+ function patchedRemoveEventListener$1(_type, _listener, _optionsOrCapture) {
3260
+ if (isSyntheticShadowHost(this)) {
3261
+ // Typescript does not like it when you treat the `arguments` object as an array
3262
+ // @ts-ignore type-mismatch
3263
+ return removeCustomElementEventListener.apply(this, arguments);
3264
+ }
3265
+ const args = ArraySlice.call(arguments);
3266
+ if (arguments.length > 1) {
3267
+ args[1] = getEventListenerWrapper(args[1]);
3268
+ }
3269
+ // Ignore types because we're passing through to native method
3270
+ // @ts-ignore type-mismatch
3271
+ removeEventListener.apply(this, args);
3272
+ // Account for listeners that were added before this polyfill was applied
3273
+ // Typescript does not like it when you treat the `arguments` object as an array
3274
+ // @ts-ignore type-mismatch
3275
+ removeEventListener.apply(this, arguments);
3276
+ }
3277
+ defineProperties(eventTargetPrototype, {
3278
+ addEventListener: {
3279
+ value: patchedAddEventListener$1,
3280
+ enumerable: true,
3281
+ writable: true,
3282
+ configurable: true,
3283
+ },
3284
+ removeEventListener: {
3285
+ value: patchedRemoveEventListener$1,
3286
+ enumerable: true,
3287
+ writable: true,
3288
+ configurable: true,
3289
+ },
3290
+ });
3291
+
3292
+ /*
3293
+ * Copyright (c) 2018, salesforce.com, inc.
3294
+ * All rights reserved.
3295
+ * SPDX-License-Identifier: MIT
3296
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3297
+ */
3298
+ function detect() {
3299
+ return typeof EventTarget === 'undefined';
3300
+ }
3301
+
3302
+ /*
3303
+ * Copyright (c) 2018, salesforce.com, inc.
3304
+ * All rights reserved.
3305
+ * SPDX-License-Identifier: MIT
3306
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3307
+ */
3308
+ function patchedAddEventListener(_type, _listener, _options) {
3309
+ if (arguments.length > 1) {
3310
+ const args = ArraySlice.call(arguments);
3311
+ args[1] = getEventListenerWrapper(args[1]);
3312
+ // Ignore types because we're passing through to native method
3313
+ // @ts-ignore type-mismatch
3314
+ return windowAddEventListener.apply(this, args);
3315
+ }
3316
+ // Typescript does not like it when you treat the `arguments` object as an array
3317
+ // @ts-ignore type-mismatch
3318
+ return windowAddEventListener.apply(this, arguments);
3319
+ }
3320
+ function patchedRemoveEventListener(_type, _listener, _options) {
3321
+ if (arguments.length > 1) {
3322
+ const args = ArraySlice.call(arguments);
3323
+ args[1] = getEventListenerWrapper(args[1]);
3324
+ // Ignore types because we're passing through to native method
3325
+ // @ts-ignore type-mismatch
3326
+ windowRemoveEventListener.apply(this, args);
3327
+ }
3328
+ // Account for listeners that were added before this polyfill was applied
3329
+ // Typescript does not like it when you treat the `arguments` object as an array
3330
+ // @ts-ignore type-mismatch
3331
+ windowRemoveEventListener.apply(this, arguments);
3332
+ }
3333
+ function apply() {
3334
+ defineProperties(Window.prototype, {
3335
+ addEventListener: {
3336
+ value: patchedAddEventListener,
3337
+ enumerable: true,
3338
+ writable: true,
3339
+ configurable: true,
3340
+ },
3341
+ removeEventListener: {
3342
+ value: patchedRemoveEventListener,
3343
+ enumerable: true,
3344
+ writable: true,
3345
+ configurable: true,
3346
+ },
3347
+ });
3348
+ }
3349
+
3350
+ /*
3351
+ * Copyright (c) 2018, salesforce.com, inc.
3352
+ * All rights reserved.
3353
+ * SPDX-License-Identifier: MIT
3354
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3355
+ */
3356
+ if (detect()) {
3357
+ apply();
3358
+ }
3359
+
3360
+ /*
3361
+ * Copyright (c) 2018, salesforce.com, inc.
3362
+ * All rights reserved.
3363
+ * SPDX-License-Identifier: MIT
3364
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3365
+ */
3366
+ function patchedCurrentTargetGetter() {
3367
+ const currentTarget = eventCurrentTargetGetter.call(this);
3368
+ if (isNull(currentTarget)) {
3369
+ return null;
3370
+ }
3371
+ if (eventToContextMap.get(this) === 1 /* EventListenerContext.SHADOW_ROOT_LISTENER */) {
3372
+ return getShadowRoot(currentTarget);
3373
+ }
3374
+ return currentTarget;
3375
+ }
3376
+ function patchedTargetGetter() {
3377
+ const originalTarget = eventTargetGetter.call(this);
3378
+ if (!(originalTarget instanceof _Node)) {
3379
+ return originalTarget;
3380
+ }
3381
+ const doc = getOwnerDocument(originalTarget);
3382
+ const composedPath = pathComposer(originalTarget, this.composed);
3383
+ const originalCurrentTarget = eventCurrentTargetGetter.call(this);
3384
+ // Handle cases where the currentTarget is null (for async events), and when an event has been
3385
+ // added to Window
3386
+ if (!(originalCurrentTarget instanceof _Node)) {
3387
+ // TODO [#1511]: Special escape hatch to support legacy behavior. Should be fixed.
3388
+ // If the event's target is being accessed async and originalTarget is not a keyed element, do not retarget
3389
+ if (isNull(originalCurrentTarget) && isUndefined(getNodeOwnerKey(originalTarget))) {
3390
+ return originalTarget;
3391
+ }
3392
+ return retarget(doc, composedPath);
3393
+ }
3394
+ else if (originalCurrentTarget === doc || originalCurrentTarget === doc.body) {
3395
+ // TODO [#1530]: If currentTarget is document or document.body (Third party libraries that have global event listeners)
3396
+ // and the originalTarget is not a keyed element, do not retarget
3397
+ if (isUndefined(getNodeOwnerKey(originalTarget))) {
3398
+ return originalTarget;
3399
+ }
3400
+ return retarget(doc, composedPath);
3401
+ }
3402
+ let actualCurrentTarget = originalCurrentTarget;
3403
+ let actualPath = composedPath;
3404
+ // Address the possibility that `currentTarget` is a shadow root
3405
+ if (isSyntheticShadowHost(originalCurrentTarget)) {
3406
+ const context = eventToContextMap.get(this);
3407
+ if (context === 1 /* EventListenerContext.SHADOW_ROOT_LISTENER */) {
3408
+ actualCurrentTarget = getShadowRoot(originalCurrentTarget);
3409
+ }
3410
+ }
3411
+ // Address the possibility that `target` is a shadow root
3412
+ if (isSyntheticShadowHost(originalTarget) && eventToShadowRootMap.has(this)) {
3413
+ actualPath = pathComposer(getShadowRoot(originalTarget), this.composed);
3414
+ }
3415
+ return retarget(actualCurrentTarget, actualPath);
3416
+ }
3417
+ function patchedComposedPathValue() {
3418
+ const originalTarget = eventTargetGetter.call(this);
3419
+ // Account for events with targets that are not instances of Node (e.g., when a readystatechange
3420
+ // handler is listening on an instance of XMLHttpRequest).
3421
+ if (!(originalTarget instanceof _Node)) {
3422
+ return [];
3423
+ }
3424
+ // If the original target is inside a native shadow root, then just call the native
3425
+ // composePath() method. The event is already retargeted and this causes our composedPath()
3426
+ // polyfill to compute the wrong value. This is only an issue when you have a native web
3427
+ // component inside an LWC component (see test in same commit) but this scenario is unlikely
3428
+ // because we don't yet support that. Workaround specifically for W-9846457. Mixed mode solution
3429
+ // will likely be more involved.
3430
+ const hasShadowRoot = Boolean(originalTarget.shadowRoot);
3431
+ const hasSyntheticShadowRootAttached = hasInternalSlot(originalTarget);
3432
+ if (hasShadowRoot && !hasSyntheticShadowRootAttached) {
3433
+ return composedPath.call(this);
3434
+ }
3435
+ const originalCurrentTarget = eventCurrentTargetGetter.call(this);
3436
+ // If the event has completed propagation, the composedPath should be an empty array.
3437
+ if (isNull(originalCurrentTarget)) {
3438
+ return [];
3439
+ }
3440
+ // Address the possibility that `target` is a shadow root
3441
+ let actualTarget = originalTarget;
3442
+ if (isSyntheticShadowHost(originalTarget) && eventToShadowRootMap.has(this)) {
3443
+ actualTarget = getShadowRoot(originalTarget);
3444
+ }
3445
+ return pathComposer(actualTarget, this.composed);
3446
+ }
3447
+ defineProperties(Event.prototype, {
3448
+ target: {
3449
+ get: patchedTargetGetter,
3450
+ enumerable: true,
3451
+ configurable: true,
3452
+ },
3453
+ currentTarget: {
3454
+ get: patchedCurrentTargetGetter,
3455
+ enumerable: true,
3456
+ configurable: true,
3457
+ },
3458
+ composedPath: {
3459
+ value: patchedComposedPathValue,
3460
+ writable: true,
3461
+ enumerable: true,
3462
+ configurable: true,
3463
+ },
3464
+ // Non-standard but widely supported for backwards-compatibility
3465
+ srcElement: {
3466
+ get: patchedTargetGetter,
3467
+ enumerable: true,
3468
+ configurable: true,
3469
+ },
3470
+ // Non-standard but implemented in Chrome and continues to exist for backwards-compatibility
3471
+ // https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/dom/events/event.idl;l=58?q=event.idl&ss=chromium
3472
+ path: {
3473
+ get: patchedComposedPathValue,
3474
+ enumerable: true,
3475
+ configurable: true,
3476
+ },
3477
+ });
3478
+
3479
+ /*
3480
+ * Copyright (c) 2018, salesforce.com, inc.
3481
+ * All rights reserved.
3482
+ * SPDX-License-Identifier: MIT
3483
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3484
+ */
3485
+ function retargetRelatedTarget(Ctor) {
3486
+ const relatedTargetGetter = getOwnPropertyDescriptor(Ctor.prototype, 'relatedTarget')
3487
+ .get;
3488
+ defineProperty(Ctor.prototype, 'relatedTarget', {
3489
+ get() {
3490
+ const relatedTarget = relatedTargetGetter.call(this);
3491
+ if (isNull(relatedTarget)) {
3492
+ return null;
3493
+ }
3494
+ if (!(relatedTarget instanceof _Node) || !isNodeShadowed(relatedTarget)) {
3495
+ return relatedTarget;
3496
+ }
3497
+ let pointOfReference = eventCurrentTargetGetter.call(this);
3498
+ if (isNull(pointOfReference)) {
3499
+ pointOfReference = getOwnerDocument(relatedTarget);
3500
+ }
3501
+ return retarget(pointOfReference, pathComposer(relatedTarget, true));
3502
+ },
3503
+ enumerable: true,
3504
+ configurable: true,
3505
+ });
3506
+ }
3507
+
3508
+ /*
3509
+ * Copyright (c) 2018, salesforce.com, inc.
3510
+ * All rights reserved.
3511
+ * SPDX-License-Identifier: MIT
3512
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3513
+ */
3514
+ retargetRelatedTarget(FocusEvent);
3515
+
3516
+ /*
3517
+ * Copyright (c) 2018, salesforce.com, inc.
3518
+ * All rights reserved.
3519
+ * SPDX-License-Identifier: MIT
3520
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3521
+ */
3522
+ retargetRelatedTarget(MouseEvent);
3523
+
3524
+ /*
3525
+ * Copyright (c) 2021, salesforce.com, inc.
3526
+ * All rights reserved.
3527
+ * SPDX-License-Identifier: MIT
3528
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3529
+ */
3530
+ const assignedSlotGetter = hasOwnProperty.call(Text.prototype, 'assignedSlot')
3531
+ ? getOwnPropertyDescriptor(Text.prototype, 'assignedSlot').get
3532
+ : () => null;
3533
+
3534
+ /*
3535
+ * Copyright (c) 2018, salesforce.com, inc.
3536
+ * All rights reserved.
3537
+ * SPDX-License-Identifier: MIT
3538
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3539
+ */
3540
+ // We can use a single observer without having to worry about leaking because
3541
+ // "Registered observers in a node’s registered observer list have a weak
3542
+ // reference to the node."
3543
+ // https://dom.spec.whatwg.org/#garbage-collection
3544
+ let observer;
3545
+ const observerConfig = { childList: true };
3546
+ const SlotChangeKey = new WeakMap();
3547
+ function initSlotObserver() {
3548
+ return new MO((mutations) => {
3549
+ const slots = [];
3550
+ forEach.call(mutations, (mutation) => {
3551
+ if (process.env.NODE_ENV !== 'production') {
3552
+ assert.invariant(mutation.type === 'childList', `Invalid mutation type: ${mutation.type}. This mutation handler for slots should only handle "childList" mutations.`);
3553
+ }
3554
+ const { target: slot } = mutation;
3555
+ if (ArrayIndexOf.call(slots, slot) === -1) {
3556
+ ArrayPush.call(slots, slot);
3557
+ dispatchEvent.call(slot, new CustomEvent('slotchange'));
3558
+ }
3559
+ });
3560
+ });
3561
+ }
3562
+ function getFilteredSlotFlattenNodes(slot) {
3563
+ const childNodes = arrayFromCollection(childNodesGetter.call(slot));
3564
+ // Typescript is inferring the wrong function type for this particular
3565
+ // overloaded method: https://github.com/Microsoft/TypeScript/issues/27972
3566
+ // @ts-ignore type-mismatch
3567
+ return ArrayReduce.call(childNodes, (seed, child) => {
3568
+ if (child instanceof Element && isSlotElement(child)) {
3569
+ ArrayPush.apply(seed, getFilteredSlotFlattenNodes(child));
3570
+ }
3571
+ else {
3572
+ ArrayPush.call(seed, child);
3573
+ }
3574
+ return seed;
3575
+ }, []);
3576
+ }
3577
+ function assignedSlotGetterPatched() {
3578
+ const parentNode = parentNodeGetter.call(this);
3579
+ // use original assignedSlot if parent has a native shdow root
3580
+ if (parentNode instanceof Element) {
3581
+ const sr = shadowRootGetter.call(parentNode);
3582
+ if (isInstanceOfNativeShadowRoot(sr)) {
3583
+ if (this instanceof Text) {
3584
+ return assignedSlotGetter.call(this);
3585
+ }
3586
+ return assignedSlotGetter$1.call(this);
3587
+ }
3588
+ }
3589
+ /**
3590
+ * The node is assigned to a slot if:
3591
+ * - it has a parent and its parent is a slot element
3592
+ * - and if the slot owner key is different than the node owner key.
3593
+ *
3594
+ * When the slot and the slotted node are 2 different shadow trees, the owner keys will be
3595
+ * different. When the slot is in a shadow tree and the slotted content is a light DOM node,
3596
+ * the light DOM node doesn't have an owner key and therefor the slot owner key will be
3597
+ * different than the node owner key (always `undefined`).
3598
+ */
3599
+ if (!isNull(parentNode) &&
3600
+ isSlotElement(parentNode) &&
3601
+ getNodeOwnerKey(parentNode) !== getNodeOwnerKey(this)) {
3602
+ return parentNode;
3603
+ }
3604
+ return null;
3605
+ }
3606
+ defineProperties(HTMLSlotElement.prototype, {
3607
+ addEventListener: {
3608
+ value(type, listener, options) {
3609
+ // super.addEventListener - but that doesn't work with typescript
3610
+ HTMLElement.prototype.addEventListener.call(this, type, listener, options);
3611
+ if (type === 'slotchange' && !SlotChangeKey.get(this)) {
3612
+ SlotChangeKey.set(this, true);
3613
+ if (!observer) {
3614
+ observer = initSlotObserver();
3615
+ }
3616
+ MutationObserverObserve.call(observer, this, observerConfig);
3617
+ }
3618
+ },
3619
+ writable: true,
3620
+ enumerable: true,
3621
+ configurable: true,
3622
+ },
3623
+ assignedElements: {
3624
+ value(options) {
3625
+ if (isNodeShadowed(this)) {
3626
+ const flatten = !isUndefined(options) && isTrue(options.flatten);
3627
+ const nodes = flatten
3628
+ ? getFilteredSlotFlattenNodes(this)
3629
+ : getFilteredSlotAssignedNodes(this);
3630
+ return ArrayFilter.call(nodes, (node) => node instanceof Element);
3631
+ }
3632
+ else {
3633
+ return assignedElements.apply(this, ArraySlice.call(arguments));
3634
+ }
3635
+ },
3636
+ writable: true,
3637
+ enumerable: true,
3638
+ configurable: true,
3639
+ },
3640
+ assignedNodes: {
3641
+ value(options) {
3642
+ if (isNodeShadowed(this)) {
3643
+ const flatten = !isUndefined(options) && isTrue(options.flatten);
3644
+ return flatten
3645
+ ? getFilteredSlotFlattenNodes(this)
3646
+ : getFilteredSlotAssignedNodes(this);
3647
+ }
3648
+ else {
3649
+ return assignedNodes.apply(this, ArraySlice.call(arguments));
3650
+ }
3651
+ },
3652
+ writable: true,
3653
+ enumerable: true,
3654
+ configurable: true,
3655
+ },
3656
+ name: {
3657
+ get() {
3658
+ const name = getAttribute.call(this, 'name');
3659
+ return isNull(name) ? '' : name;
3660
+ },
3661
+ set(value) {
3662
+ setAttribute.call(this, 'name', value);
3663
+ },
3664
+ enumerable: true,
3665
+ configurable: true,
3666
+ },
3667
+ childNodes: {
3668
+ get() {
3669
+ if (isNodeShadowed(this)) {
3670
+ const owner = getNodeOwner(this);
3671
+ const childNodes = isNull(owner)
3672
+ ? []
3673
+ : getAllMatches(owner, getFilteredChildNodes(this));
3674
+ return createStaticNodeList(childNodes);
3675
+ }
3676
+ return childNodesGetter.call(this);
3677
+ },
3678
+ enumerable: true,
3679
+ configurable: true,
3680
+ },
3681
+ });
3682
+
3683
+ /*
3684
+ * Copyright (c) 2018, salesforce.com, inc.
3685
+ * All rights reserved.
3686
+ * SPDX-License-Identifier: MIT
3687
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3688
+ */
3689
+ // Non-deep-traversing patches: this descriptor map includes all descriptors that
3690
+ // do not five access to nodes beyond the immediate children.
3691
+ defineProperties(Text.prototype, {
3692
+ assignedSlot: {
3693
+ get: assignedSlotGetterPatched,
3694
+ enumerable: true,
3695
+ configurable: true,
3696
+ },
3697
+ });
3698
+
3699
+ /*
3700
+ * Copyright (c) 2018, salesforce.com, inc.
3701
+ * All rights reserved.
3702
+ * SPDX-License-Identifier: MIT
3703
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3704
+ */
3705
+ /**
3706
+ * This methods filters out elements that are not in the same shadow root of context.
3707
+ * It does not enforce shadow dom semantics if $context is not managed by LWC
3708
+ */
3709
+ function getNonPatchedFilteredArrayOfNodes(context, unfilteredNodes) {
3710
+ let filtered;
3711
+ const ownerKey = getNodeOwnerKey(context);
3712
+ // a node inside a shadow.
3713
+ if (!isUndefined(ownerKey)) {
3714
+ if (isSyntheticShadowHost(context)) {
3715
+ // element with shadowRoot attached
3716
+ const owner = getNodeOwner(context);
3717
+ if (isNull(owner)) {
3718
+ filtered = [];
3719
+ }
3720
+ else if (getNodeKey(context)) {
3721
+ // it is a custom element, and we should then filter by slotted elements
3722
+ filtered = getAllSlottedMatches(context, unfilteredNodes);
3723
+ }
3724
+ else {
3725
+ // regular element, we should then filter by ownership
3726
+ filtered = getAllMatches(owner, unfilteredNodes);
3727
+ }
3728
+ }
3729
+ else {
3730
+ // context is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
3731
+ filtered = ArrayFilter.call(unfilteredNodes, (elm) => getNodeNearestOwnerKey(elm) === ownerKey);
3732
+ }
3733
+ }
3734
+ else if (context instanceof HTMLBodyElement) {
3735
+ // `context` is document.body which is already patched.
3736
+ filtered = ArrayFilter.call(unfilteredNodes,
3737
+ // Note: we deviate from native shadow here, but are not fixing
3738
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3739
+ (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(context));
3740
+ }
3741
+ else {
3742
+ // `context` is outside the lwc boundary, return unfiltered list.
3743
+ filtered = ArraySlice.call(unfilteredNodes);
3744
+ }
3745
+ return filtered;
3746
+ }
3747
+
3748
+ /*
3749
+ * Copyright (c) 2018, salesforce.com, inc.
3750
+ * All rights reserved.
3751
+ * SPDX-License-Identifier: MIT
3752
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3753
+ */
3754
+ function innerHTMLGetterPatched() {
3755
+ const childNodes = getInternalChildNodes(this);
3756
+ let innerHTML = '';
3757
+ for (let i = 0, len = childNodes.length; i < len; i += 1) {
3758
+ innerHTML += getOuterHTML(childNodes[i]);
3759
+ }
3760
+ return innerHTML;
3761
+ }
3762
+ function outerHTMLGetterPatched() {
3763
+ return getOuterHTML(this);
3764
+ }
3765
+ function attachShadowPatched(options) {
3766
+ // To retain native behavior of the API, provide synthetic shadowRoot only when specified
3767
+ if (options[KEY__SYNTHETIC_MODE]) {
3768
+ return attachShadow(this, options);
3769
+ }
3770
+ return attachShadow$1.call(this, options);
3771
+ }
3772
+ function shadowRootGetterPatched() {
3773
+ if (isSyntheticShadowHost(this)) {
3774
+ const shadow = getShadowRoot(this);
3775
+ if (shadow.mode === 'open') {
3776
+ return shadow;
3777
+ }
3778
+ }
3779
+ return shadowRootGetter.call(this);
3780
+ }
3781
+ function childrenGetterPatched() {
3782
+ const owner = getNodeOwner(this);
3783
+ const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
3784
+ return createStaticHTMLCollection(ArrayFilter.call(childNodes, (node) => node instanceof Element));
3785
+ }
3786
+ function childElementCountGetterPatched() {
3787
+ return this.children.length;
3788
+ }
3789
+ function firstElementChildGetterPatched() {
3790
+ return this.children[0] || null;
3791
+ }
3792
+ function lastElementChildGetterPatched() {
3793
+ const { children } = this;
3794
+ return children.item(children.length - 1) || null;
3795
+ }
3796
+ // Non-deep-traversing patches: this descriptor map includes all descriptors that
3797
+ // do not five access to nodes beyond the immediate children.
3798
+ defineProperties(Element.prototype, {
3799
+ innerHTML: {
3800
+ get() {
3801
+ // Note: we deviate from native shadow here, but are not fixing
3802
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3803
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
3804
+ return innerHTMLGetterPatched.call(this);
3805
+ }
3806
+ return innerHTMLGetter.call(this);
3807
+ },
3808
+ set(v) {
3809
+ innerHTMLSetter.call(this, v);
3810
+ },
3811
+ enumerable: true,
3812
+ configurable: true,
3813
+ },
3814
+ outerHTML: {
3815
+ get() {
3816
+ // Note: we deviate from native shadow here, but are not fixing
3817
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3818
+ if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
3819
+ return outerHTMLGetterPatched.call(this);
3820
+ }
3821
+ return outerHTMLGetter.call(this);
3822
+ },
3823
+ set(v) {
3824
+ outerHTMLSetter.call(this, v);
3825
+ },
3826
+ enumerable: true,
3827
+ configurable: true,
3828
+ },
3829
+ attachShadow: {
3830
+ value: attachShadowPatched,
3831
+ enumerable: true,
3832
+ writable: true,
3833
+ configurable: true,
3834
+ },
3835
+ shadowRoot: {
3836
+ get: shadowRootGetterPatched,
3837
+ enumerable: true,
3838
+ configurable: true,
3839
+ },
3840
+ // patched in HTMLElement if exists (IE11 is the one off here)
3841
+ children: {
3842
+ get() {
3843
+ if (hasMountedChildren(this)) {
3844
+ return childrenGetterPatched.call(this);
3845
+ }
3846
+ return childrenGetter.call(this);
3847
+ },
3848
+ enumerable: true,
3849
+ configurable: true,
3850
+ },
3851
+ childElementCount: {
3852
+ get() {
3853
+ if (hasMountedChildren(this)) {
3854
+ return childElementCountGetterPatched.call(this);
3855
+ }
3856
+ return childElementCountGetter.call(this);
3857
+ },
3858
+ enumerable: true,
3859
+ configurable: true,
3860
+ },
3861
+ firstElementChild: {
3862
+ get() {
3863
+ if (hasMountedChildren(this)) {
3864
+ return firstElementChildGetterPatched.call(this);
3865
+ }
3866
+ return firstElementChildGetter.call(this);
3867
+ },
3868
+ enumerable: true,
3869
+ configurable: true,
3870
+ },
3871
+ lastElementChild: {
3872
+ get() {
3873
+ if (hasMountedChildren(this)) {
3874
+ return lastElementChildGetterPatched.call(this);
3875
+ }
3876
+ return lastElementChildGetter.call(this);
3877
+ },
3878
+ enumerable: true,
3879
+ configurable: true,
3880
+ },
3881
+ assignedSlot: {
3882
+ get: assignedSlotGetterPatched,
3883
+ enumerable: true,
3884
+ configurable: true,
3885
+ },
3886
+ });
3887
+ // IE11 extra patches for wrong prototypes
3888
+ if (hasOwnProperty.call(HTMLElement.prototype, 'innerHTML')) {
3889
+ defineProperty(HTMLElement.prototype, 'innerHTML', getOwnPropertyDescriptor(Element.prototype, 'innerHTML'));
3890
+ }
3891
+ if (hasOwnProperty.call(HTMLElement.prototype, 'outerHTML')) {
3892
+ defineProperty(HTMLElement.prototype, 'outerHTML', getOwnPropertyDescriptor(Element.prototype, 'outerHTML'));
3893
+ }
3894
+ if (hasOwnProperty.call(HTMLElement.prototype, 'children')) {
3895
+ defineProperty(HTMLElement.prototype, 'children', getOwnPropertyDescriptor(Element.prototype, 'children'));
3896
+ }
3897
+ // Deep-traversing patches from this point on:
3898
+ function querySelectorPatched() {
3899
+ const nodeList = arrayFromCollection(querySelectorAll$1.apply(this, ArraySlice.call(arguments)));
3900
+ if (isSyntheticShadowHost(this)) {
3901
+ // element with shadowRoot attached
3902
+ const owner = getNodeOwner(this);
3903
+ if (!isUndefined(getNodeKey(this))) {
3904
+ // it is a custom element, and we should then filter by slotted elements
3905
+ return getFirstSlottedMatch(this, nodeList);
3906
+ }
3907
+ else if (isNull(owner)) {
3908
+ return null;
3909
+ }
3910
+ else {
3911
+ // regular element, we should then filter by ownership
3912
+ return getFirstMatch(owner, nodeList);
3913
+ }
3914
+ }
3915
+ else if (isNodeShadowed(this)) {
3916
+ // element inside a shadowRoot
3917
+ const ownerKey = getNodeOwnerKey(this);
3918
+ if (!isUndefined(ownerKey)) {
3919
+ // `this` is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
3920
+ const elm = ArrayFind.call(nodeList, (elm) => getNodeNearestOwnerKey(elm) === ownerKey);
3921
+ return isUndefined(elm) ? null : elm;
3922
+ }
3923
+ else {
3924
+ // Note: we deviate from native shadow here, but are not fixing
3925
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3926
+ // `this` is a manually inserted element inside a shadowRoot, return the first element.
3927
+ return nodeList.length === 0 ? null : nodeList[0];
3928
+ }
3929
+ }
3930
+ else {
3931
+ if (!(this instanceof HTMLBodyElement)) {
3932
+ const elm = nodeList[0];
3933
+ return isUndefined(elm) ? null : elm;
3934
+ }
3935
+ // element belonging to the document
3936
+ const elm = ArrayFind.call(nodeList, (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(this));
3937
+ return isUndefined(elm) ? null : elm;
3938
+ }
3939
+ }
3940
+ function getFilteredArrayOfNodes(context, unfilteredNodes) {
3941
+ let filtered;
3942
+ if (isSyntheticShadowHost(context)) {
3943
+ // element with shadowRoot attached
3944
+ const owner = getNodeOwner(context);
3945
+ if (!isUndefined(getNodeKey(context))) {
3946
+ // it is a custom element, and we should then filter by slotted elements
3947
+ filtered = getAllSlottedMatches(context, unfilteredNodes);
3948
+ }
3949
+ else if (isNull(owner)) {
3950
+ filtered = [];
3951
+ }
3952
+ else {
3953
+ // regular element, we should then filter by ownership
3954
+ filtered = getAllMatches(owner, unfilteredNodes);
3955
+ }
3956
+ }
3957
+ else if (isNodeShadowed(context)) {
3958
+ // element inside a shadowRoot
3959
+ const ownerKey = getNodeOwnerKey(context);
3960
+ if (!isUndefined(ownerKey)) {
3961
+ // context is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
3962
+ filtered = ArrayFilter.call(unfilteredNodes, (elm) => getNodeNearestOwnerKey(elm) === ownerKey);
3963
+ }
3964
+ else {
3965
+ // Note: we deviate from native shadow here, but are not fixing
3966
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
3967
+ // context is manually inserted without lwc:dom-manual, return everything
3968
+ filtered = ArraySlice.call(unfilteredNodes);
3969
+ }
3970
+ }
3971
+ else {
3972
+ if (context instanceof HTMLBodyElement) {
3973
+ // `context` is document.body or element belonging to the document with the patch enabled
3974
+ filtered = ArrayFilter.call(unfilteredNodes, (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(context));
3975
+ }
3976
+ else {
3977
+ // `context` is outside the lwc boundary and patch is not enabled.
3978
+ filtered = ArraySlice.call(unfilteredNodes);
3979
+ }
3980
+ }
3981
+ return filtered;
3982
+ }
3983
+ // The following patched methods hide shadowed elements from global
3984
+ // traversing mechanisms. They are simplified for performance reasons to
3985
+ // filter by ownership and do not account for slotted elements. This
3986
+ // compromise is fine for our synthetic shadow dom because root elements
3987
+ // cannot have slotted elements.
3988
+ // Another compromise here is that all these traversing methods will return
3989
+ // static HTMLCollection or static NodeList. We decided that this compromise
3990
+ // is not a big problem considering the amount of code that is relying on
3991
+ // the liveliness of these results are rare.
3992
+ defineProperties(Element.prototype, {
3993
+ querySelector: {
3994
+ value: querySelectorPatched,
3995
+ writable: true,
3996
+ enumerable: true,
3997
+ configurable: true,
3998
+ },
3999
+ querySelectorAll: {
4000
+ value() {
4001
+ const nodeList = arrayFromCollection(querySelectorAll$1.apply(this, ArraySlice.call(arguments)));
4002
+ // Note: we deviate from native shadow here, but are not fixing
4003
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
4004
+ const filteredResults = getFilteredArrayOfNodes(this, nodeList);
4005
+ return createStaticNodeList(filteredResults);
4006
+ },
4007
+ writable: true,
4008
+ enumerable: true,
4009
+ configurable: true,
4010
+ },
4011
+ });
4012
+ // The following APIs are used directly by Jest internally so we avoid patching them during testing.
4013
+ if (process.env.NODE_ENV !== 'test') {
4014
+ defineProperties(Element.prototype, {
4015
+ getElementsByClassName: {
4016
+ value() {
4017
+ const elements = arrayFromCollection(getElementsByClassName$1.apply(this, ArraySlice.call(arguments)));
4018
+ // Note: we deviate from native shadow here, but are not fixing
4019
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
4020
+ return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
4021
+ },
4022
+ writable: true,
4023
+ enumerable: true,
4024
+ configurable: true,
4025
+ },
4026
+ getElementsByTagName: {
4027
+ value() {
4028
+ const elements = arrayFromCollection(getElementsByTagName$1.apply(this, ArraySlice.call(arguments)));
4029
+ // Note: we deviate from native shadow here, but are not fixing
4030
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
4031
+ return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
4032
+ },
4033
+ writable: true,
4034
+ enumerable: true,
4035
+ configurable: true,
4036
+ },
4037
+ getElementsByTagNameNS: {
4038
+ value() {
4039
+ const elements = arrayFromCollection(getElementsByTagNameNS$1.apply(this, ArraySlice.call(arguments)));
4040
+ // Note: we deviate from native shadow here, but are not fixing
4041
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
4042
+ return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
4043
+ },
4044
+ writable: true,
4045
+ enumerable: true,
4046
+ configurable: true,
4047
+ },
4048
+ });
4049
+ }
4050
+ // IE11 extra patches for wrong prototypes
4051
+ if (hasOwnProperty.call(HTMLElement.prototype, 'getElementsByClassName')) {
4052
+ defineProperty(HTMLElement.prototype, 'getElementsByClassName', getOwnPropertyDescriptor(Element.prototype, 'getElementsByClassName'));
4053
+ }
4054
+
4055
+ /*
4056
+ * Copyright (c) 2018, salesforce.com, inc.
4057
+ * All rights reserved.
4058
+ * SPDX-License-Identifier: MIT
4059
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4060
+ */
4061
+ const FocusableSelector = `
4062
+ [contenteditable],
4063
+ [tabindex],
4064
+ a[href],
4065
+ area[href],
4066
+ audio[controls],
4067
+ button,
4068
+ iframe,
4069
+ input,
4070
+ select,
4071
+ textarea,
4072
+ video[controls]
4073
+ `;
4074
+ const formElementTagNames = new Set(['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA']);
4075
+ function filterSequentiallyFocusableElements(elements) {
4076
+ return elements.filter((element) => {
4077
+ if (hasAttribute.call(element, 'tabindex')) {
4078
+ // Even though LWC only supports tabindex values of 0 or -1,
4079
+ // passing through elements with tabindex="0" is a tighter criteria
4080
+ // than filtering out elements based on tabindex="-1".
4081
+ return getAttribute.call(element, 'tabindex') === '0';
4082
+ }
4083
+ if (formElementTagNames.has(tagNameGetter.call(element))) {
4084
+ return !hasAttribute.call(element, 'disabled');
4085
+ }
4086
+ return true;
4087
+ });
4088
+ }
4089
+ const DidAddMouseEventListeners = new WeakMap();
4090
+ // Due to browser differences, it is impossible to know what is focusable until
4091
+ // we actually try to focus it. We need to refactor our focus delegation logic
4092
+ // to verify whether or not the target was actually focused instead of trying
4093
+ // to predict focusability like we do here.
4094
+ function isVisible(element) {
4095
+ const { width, height } = getBoundingClientRect.call(element);
4096
+ const noZeroSize = width > 0 || height > 0;
4097
+ // The area element can be 0x0 and focusable. Hardcoding this is not ideal
4098
+ // but it will minimize changes in the current behavior.
4099
+ const isAreaElement = element.tagName === 'AREA';
4100
+ return (noZeroSize || isAreaElement) && getComputedStyle(element).visibility !== 'hidden';
4101
+ }
4102
+ // This function based on https://allyjs.io/data-tables/focusable.html
4103
+ // It won't catch everything, but should be good enough
4104
+ // There are a lot of edge cases here that we can't realistically handle
4105
+ // Determines if a particular element is tabbable, as opposed to simply focusable
4106
+ function isTabbable(element) {
4107
+ if (isSyntheticShadowHost(element) && isDelegatingFocus(element)) {
4108
+ return false;
4109
+ }
4110
+ return matches.call(element, FocusableSelector) && isVisible(element);
4111
+ }
4112
+ function hostElementFocus() {
4113
+ const _rootNode = this.getRootNode();
4114
+ if (_rootNode === this) {
4115
+ // We invoke the focus() method even if the host is disconnected in order to eliminate
4116
+ // observable differences for component authors between synthetic and native.
4117
+ const focusable = querySelector.call(this, FocusableSelector);
4118
+ if (!isNull(focusable)) {
4119
+ // @ts-ignore type-mismatch
4120
+ focusable.focus.apply(focusable, arguments);
4121
+ }
4122
+ return;
4123
+ }
4124
+ // If the root node is not the host element then it's either the document or a shadow root.
4125
+ const rootNode = _rootNode;
4126
+ if (rootNode.activeElement === this) {
4127
+ // The focused element should not change if the focus method is invoked
4128
+ // on the shadow-including ancestor of the currently focused element.
4129
+ return;
4130
+ }
4131
+ const focusables = arrayFromCollection(querySelectorAll$1.call(this, FocusableSelector));
4132
+ let didFocus = false;
4133
+ while (!didFocus && focusables.length !== 0) {
4134
+ const focusable = focusables.shift();
4135
+ // @ts-ignore type-mismatch
4136
+ focusable.focus.apply(focusable, arguments);
4137
+ // Get the root node of the current focusable in case it was slotted.
4138
+ const currentRootNode = focusable.getRootNode();
4139
+ didFocus = currentRootNode.activeElement === focusable;
4140
+ }
4141
+ }
4142
+ function getTabbableSegments(host) {
4143
+ const doc = getOwnerDocument(host);
4144
+ const all = filterSequentiallyFocusableElements(arrayFromCollection(querySelectorAll.call(doc, FocusableSelector)));
4145
+ const inner = filterSequentiallyFocusableElements(arrayFromCollection(querySelectorAll$1.call(host, FocusableSelector)));
4146
+ if (process.env.NODE_ENV !== 'production') {
4147
+ assert.invariant(getAttribute.call(host, 'tabindex') === '-1' || isDelegatingFocus(host), `The focusin event is only relevant when the tabIndex property is -1 on the host.`);
4148
+ }
4149
+ const firstChild = inner[0];
4150
+ const lastChild = inner[inner.length - 1];
4151
+ const hostIndex = ArrayIndexOf.call(all, host);
4152
+ // Host element can show up in our "previous" section if its tabindex is 0
4153
+ // We want to filter that out here
4154
+ const firstChildIndex = hostIndex > -1 ? hostIndex : ArrayIndexOf.call(all, firstChild);
4155
+ // Account for an empty inner list
4156
+ const lastChildIndex = inner.length === 0 ? firstChildIndex + 1 : ArrayIndexOf.call(all, lastChild) + 1;
4157
+ const prev = ArraySlice.call(all, 0, firstChildIndex);
4158
+ const next = ArraySlice.call(all, lastChildIndex);
4159
+ return {
4160
+ prev,
4161
+ inner,
4162
+ next,
4163
+ };
4164
+ }
4165
+ function getActiveElement(host) {
4166
+ const doc = getOwnerDocument(host);
4167
+ const activeElement = DocumentPrototypeActiveElement.call(doc);
4168
+ if (isNull(activeElement)) {
4169
+ return activeElement;
4170
+ }
4171
+ // activeElement must be child of the host and owned by it
4172
+ return (compareDocumentPosition.call(host, activeElement) & DOCUMENT_POSITION_CONTAINED_BY) !==
4173
+ 0
4174
+ ? activeElement
4175
+ : null;
4176
+ }
4177
+ function relatedTargetPosition(host, relatedTarget) {
4178
+ // assert: target must be child of host
4179
+ const pos = compareDocumentPosition.call(host, relatedTarget);
4180
+ if (pos & DOCUMENT_POSITION_CONTAINED_BY) {
4181
+ // focus remains inside the host
4182
+ return 0;
4183
+ }
4184
+ else if (pos & DOCUMENT_POSITION_PRECEDING) {
4185
+ // focus is coming from above
4186
+ return 1;
4187
+ }
4188
+ else if (pos & DOCUMENT_POSITION_FOLLOWING) {
4189
+ // focus is coming from below
4190
+ return 2;
4191
+ }
4192
+ // we don't know what's going on.
4193
+ return -1;
4194
+ }
4195
+ function muteEvent(event) {
4196
+ event.preventDefault();
4197
+ event.stopPropagation();
4198
+ }
4199
+ function muteFocusEventsDuringExecution(win, func) {
4200
+ windowAddEventListener.call(win, 'focusin', muteEvent, true);
4201
+ windowAddEventListener.call(win, 'focusout', muteEvent, true);
4202
+ func();
4203
+ windowRemoveEventListener.call(win, 'focusin', muteEvent, true);
4204
+ windowRemoveEventListener.call(win, 'focusout', muteEvent, true);
4205
+ }
4206
+ function focusOnNextOrBlur(segment, target, relatedTarget) {
4207
+ const win = getOwnerWindow(relatedTarget);
4208
+ const next = getNextTabbable(segment, relatedTarget);
4209
+ if (isNull(next)) {
4210
+ // nothing to focus on, blur to invalidate the operation
4211
+ muteFocusEventsDuringExecution(win, () => {
4212
+ target.blur();
4213
+ });
4214
+ }
4215
+ else {
4216
+ muteFocusEventsDuringExecution(win, () => {
4217
+ next.focus();
4218
+ });
4219
+ }
4220
+ }
4221
+ let letBrowserHandleFocus = false;
4222
+ function disableKeyboardFocusNavigationRoutines() {
4223
+ letBrowserHandleFocus = true;
4224
+ }
4225
+ function enableKeyboardFocusNavigationRoutines() {
4226
+ letBrowserHandleFocus = false;
4227
+ }
4228
+ function isKeyboardFocusNavigationRoutineEnabled() {
4229
+ return !letBrowserHandleFocus;
4230
+ }
4231
+ function skipHostHandler(event) {
4232
+ if (letBrowserHandleFocus) {
4233
+ return;
4234
+ }
4235
+ const host = eventCurrentTargetGetter.call(event);
4236
+ const target = eventTargetGetter.call(event);
4237
+ // If the host delegating focus with tabindex=0 is not the target, we know
4238
+ // that the event was dispatched on a descendant node of the host. This
4239
+ // means the focus is coming from below and we don't need to do anything.
4240
+ if (host !== target) {
4241
+ // Focus is coming from above
4242
+ return;
4243
+ }
4244
+ const relatedTarget = focusEventRelatedTargetGetter.call(event);
4245
+ if (isNull(relatedTarget)) {
4246
+ // If relatedTarget is null, the user is most likely tabbing into the document from the
4247
+ // browser chrome. We could probably deduce whether focus is coming in from the top or the
4248
+ // bottom by comparing the position of the target to all tabbable elements. This is an edge
4249
+ // case and only comes up if the custom element is the first or last tabbable element in the
4250
+ // document.
4251
+ return;
4252
+ }
4253
+ const segments = getTabbableSegments(host);
4254
+ const position = relatedTargetPosition(host, relatedTarget);
4255
+ if (position === 1) {
4256
+ // Focus is coming from above
4257
+ const findTabbableElms = isTabbableFrom.bind(null, host.getRootNode());
4258
+ const first = ArrayFind.call(segments.inner, findTabbableElms);
4259
+ if (!isUndefined(first)) {
4260
+ const win = getOwnerWindow(first);
4261
+ muteFocusEventsDuringExecution(win, () => {
4262
+ first.focus();
4263
+ });
4264
+ }
4265
+ else {
4266
+ focusOnNextOrBlur(segments.next, target, relatedTarget);
4267
+ }
4268
+ }
4269
+ else if (host === target) {
4270
+ // Host is receiving focus from below, either from its shadow or from a sibling
4271
+ focusOnNextOrBlur(ArrayReverse.call(segments.prev), target, relatedTarget);
4272
+ }
4273
+ }
4274
+ function skipShadowHandler(event) {
4275
+ if (letBrowserHandleFocus) {
4276
+ return;
4277
+ }
4278
+ const relatedTarget = focusEventRelatedTargetGetter.call(event);
4279
+ if (isNull(relatedTarget)) {
4280
+ // If relatedTarget is null, the user is most likely tabbing into the document from the
4281
+ // browser chrome. We could probably deduce whether focus is coming in from the top or the
4282
+ // bottom by comparing the position of the target to all tabbable elements. This is an edge
4283
+ // case and only comes up if the custom element is the first or last tabbable element in the
4284
+ // document.
4285
+ return;
4286
+ }
4287
+ const host = eventCurrentTargetGetter.call(event);
4288
+ const segments = getTabbableSegments(host);
4289
+ if (ArrayIndexOf.call(segments.inner, relatedTarget) !== -1) {
4290
+ // If relatedTarget is contained by the host's subtree we can assume that the user is
4291
+ // tabbing between elements inside of the shadow. Do nothing.
4292
+ return;
4293
+ }
4294
+ const target = eventTargetGetter.call(event);
4295
+ // Determine where the focus is coming from (Tab or Shift+Tab)
4296
+ const position = relatedTargetPosition(host, relatedTarget);
4297
+ if (position === 1) {
4298
+ // Focus is coming from above
4299
+ focusOnNextOrBlur(segments.next, target, relatedTarget);
4300
+ }
4301
+ if (position === 2) {
4302
+ // Focus is coming from below
4303
+ focusOnNextOrBlur(ArrayReverse.call(segments.prev), target, relatedTarget);
4304
+ }
4305
+ }
4306
+ // Use this function to determine whether you can start from one root and end up
4307
+ // at another element via tabbing.
4308
+ function isTabbableFrom(fromRoot, toElm) {
4309
+ if (!isTabbable(toElm)) {
4310
+ return false;
4311
+ }
4312
+ const ownerDocument = getOwnerDocument(toElm);
4313
+ let root = toElm.getRootNode();
4314
+ while (root !== ownerDocument && root !== fromRoot) {
4315
+ const sr = root;
4316
+ const host = sr.host;
4317
+ if (getAttribute.call(host, 'tabindex') === '-1') {
4318
+ return false;
4319
+ }
4320
+ root = host && host.getRootNode();
4321
+ }
4322
+ return true;
4323
+ }
4324
+ function getNextTabbable(tabbables, relatedTarget) {
4325
+ const len = tabbables.length;
4326
+ if (len > 0) {
4327
+ for (let i = 0; i < len; i += 1) {
4328
+ const next = tabbables[i];
4329
+ if (isTabbableFrom(relatedTarget.getRootNode(), next)) {
4330
+ return next;
4331
+ }
4332
+ }
4333
+ }
4334
+ return null;
4335
+ }
4336
+ // Skips the host element
4337
+ function handleFocus(elm) {
4338
+ if (process.env.NODE_ENV !== 'production') {
4339
+ assert.invariant(isDelegatingFocus(elm), `Invalid attempt to handle focus event for ${toString(elm)}. ${toString(elm)} should have delegates focus true, but is not delegating focus`);
4340
+ }
4341
+ bindDocumentMousedownMouseupHandlers(elm);
4342
+ // Unbind any focusin listeners we may have going on
4343
+ ignoreFocusIn(elm);
4344
+ addEventListener.call(elm, 'focusin', skipHostHandler, true);
4345
+ }
4346
+ function ignoreFocus(elm) {
4347
+ removeEventListener.call(elm, 'focusin', skipHostHandler, true);
4348
+ }
4349
+ function bindDocumentMousedownMouseupHandlers(elm) {
4350
+ const ownerDocument = getOwnerDocument(elm);
4351
+ if (!DidAddMouseEventListeners.get(ownerDocument)) {
4352
+ DidAddMouseEventListeners.set(ownerDocument, true);
4353
+ addEventListener.call(ownerDocument, 'mousedown', disableKeyboardFocusNavigationRoutines, true);
4354
+ addEventListener.call(ownerDocument, 'mouseup', () => {
4355
+ // We schedule this as an async task in the mouseup handler (as
4356
+ // opposed to the mousedown handler) because we want to guarantee
4357
+ // that it will never run before the focusin handler:
4358
+ //
4359
+ // Click form element | Click form element label
4360
+ // ==================================================
4361
+ // mousedown | mousedown
4362
+ // FOCUSIN | mousedown-setTimeout
4363
+ // mousedown-setTimeout | mouseup
4364
+ // mouseup | FOCUSIN
4365
+ // mouseup-setTimeout | mouseup-setTimeout
4366
+ setTimeout(enableKeyboardFocusNavigationRoutines);
4367
+ }, true);
4368
+ // [W-7824445] If the element is draggable, the mousedown event is dispatched before the
4369
+ // element is starting to be dragged, which disable the keyboard focus navigation routine.
4370
+ // But by specification, the mouseup event is never dispatched once the element is dropped.
4371
+ //
4372
+ // For all draggable element, we need to add an event listener to re-enable the keyboard
4373
+ // navigation routine after dragging starts.
4374
+ addEventListener.call(ownerDocument, 'dragstart', enableKeyboardFocusNavigationRoutines, true);
4375
+ }
4376
+ }
4377
+ // Skips the shadow tree
4378
+ function handleFocusIn(elm) {
4379
+ if (process.env.NODE_ENV !== 'production') {
4380
+ assert.invariant(tabIndexGetter.call(elm) === -1, `Invalid attempt to handle focus in ${toString(elm)}. ${toString(elm)} should have tabIndex -1, but has tabIndex ${tabIndexGetter.call(elm)}`);
4381
+ }
4382
+ bindDocumentMousedownMouseupHandlers(elm);
4383
+ // Unbind any focus listeners we may have going on
4384
+ ignoreFocus(elm);
4385
+ // This focusin listener is to catch focusin events from keyboard interactions
4386
+ // A better solution would perhaps be to listen for keydown events, but
4387
+ // the keydown event happens on whatever element already has focus (or no element
4388
+ // at all in the case of the location bar. So, instead we have to assume that focusin
4389
+ // without a mousedown means keyboard navigation
4390
+ addEventListener.call(elm, 'focusin', skipShadowHandler, true);
4391
+ }
4392
+ function ignoreFocusIn(elm) {
4393
+ removeEventListener.call(elm, 'focusin', skipShadowHandler, true);
4394
+ }
4395
+
4396
+ /*
4397
+ * Copyright (c) 2018, salesforce.com, inc.
4398
+ * All rights reserved.
4399
+ * SPDX-License-Identifier: MIT
4400
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4401
+ */
4402
+ const { blur, focus } = HTMLElement.prototype;
4403
+ /**
4404
+ * This method only applies to elements with a shadow attached to them
4405
+ */
4406
+ function tabIndexGetterPatched() {
4407
+ if (isDelegatingFocus(this) && isFalse(hasAttribute.call(this, 'tabindex'))) {
4408
+ // this covers the case where the default tabindex should be 0 because the
4409
+ // custom element is delegating its focus
4410
+ return 0;
4411
+ }
4412
+ return tabIndexGetter.call(this);
4413
+ }
4414
+ /**
4415
+ * This method only applies to elements with a shadow attached to them
4416
+ */
4417
+ function tabIndexSetterPatched(value) {
4418
+ // This tabIndex setter might be confusing unless it is understood that HTML
4419
+ // elements have default tabIndex property values. Natively focusable elements have
4420
+ // a default tabIndex value of 0 and all other elements have a default tabIndex
4421
+ // value of -1. For example, the tabIndex property value is -1 for both <x-foo> and
4422
+ // <x-foo tabindex="-1">, but our delegatesFocus polyfill should only kick in for
4423
+ // the latter case when the value of the tabindex attribute is -1.
4424
+ const delegatesFocus = isDelegatingFocus(this);
4425
+ // Record the state of things before invoking component setter.
4426
+ const prevValue = tabIndexGetter.call(this);
4427
+ const prevHasAttr = hasAttribute.call(this, 'tabindex');
4428
+ tabIndexSetter.call(this, value);
4429
+ // Record the state of things after invoking component setter.
4430
+ const currValue = tabIndexGetter.call(this);
4431
+ const currHasAttr = hasAttribute.call(this, 'tabindex');
4432
+ const didValueChange = prevValue !== currValue;
4433
+ // If the tabindex attribute is initially rendered, we can assume that this setter has
4434
+ // previously executed and a listener has been added. We must remove that listener if
4435
+ // the tabIndex property value has changed or if the component no longer renders a
4436
+ // tabindex attribute.
4437
+ if (prevHasAttr && (didValueChange || isFalse(currHasAttr))) {
4438
+ if (prevValue === -1) {
4439
+ ignoreFocusIn(this);
4440
+ }
4441
+ if (prevValue === 0 && delegatesFocus) {
4442
+ ignoreFocus(this);
4443
+ }
4444
+ }
4445
+ // If a tabindex attribute was not rendered after invoking its setter, it means the
4446
+ // component is taking control. Do nothing.
4447
+ if (isFalse(currHasAttr)) {
4448
+ return;
4449
+ }
4450
+ // If the tabindex attribute is initially rendered, we can assume that this setter has
4451
+ // previously executed and a listener has been added. If the tabindex attribute is still
4452
+ // rendered after invoking the setter AND the tabIndex property value has not changed,
4453
+ // we don't need to do any work.
4454
+ if (prevHasAttr && currHasAttr && isFalse(didValueChange)) {
4455
+ return;
4456
+ }
4457
+ // At this point we know that a tabindex attribute was rendered after invoking the
4458
+ // setter and that either:
4459
+ // 1) This is the first time this setter is being invoked.
4460
+ // 2) This is not the first time this setter is being invoked and the value is changing.
4461
+ // We need to add the appropriate listeners in either case.
4462
+ if (currValue === -1) {
4463
+ // Add the magic to skip the shadow tree
4464
+ handleFocusIn(this);
4465
+ }
4466
+ if (currValue === 0 && delegatesFocus) {
4467
+ // Add the magic to skip the host element
4468
+ handleFocus(this);
4469
+ }
4470
+ }
4471
+ /**
4472
+ * This method only applies to elements with a shadow attached to them
4473
+ */
4474
+ function blurPatched() {
4475
+ if (isDelegatingFocus(this)) {
4476
+ const currentActiveElement = getActiveElement(this);
4477
+ if (!isNull(currentActiveElement)) {
4478
+ // if there is an active element, blur it (intentionally using the dot notation in case the user defines the blur routine)
4479
+ currentActiveElement.blur();
4480
+ return;
4481
+ }
4482
+ }
4483
+ return blur.call(this);
4484
+ }
4485
+ function focusPatched() {
4486
+ // Save enabled state
4487
+ const originallyEnabled = isKeyboardFocusNavigationRoutineEnabled();
4488
+ // Change state by disabling if originally enabled
4489
+ if (originallyEnabled) {
4490
+ disableKeyboardFocusNavigationRoutines();
4491
+ }
4492
+ if (isSyntheticShadowHost(this) && isDelegatingFocus(this)) {
4493
+ hostElementFocus.call(this);
4494
+ return;
4495
+ }
4496
+ // Typescript does not like it when you treat the `arguments` object as an array
4497
+ // @ts-ignore type-mismatch
4498
+ focus.apply(this, arguments);
4499
+ // Restore state by enabling if originally enabled
4500
+ if (originallyEnabled) {
4501
+ enableKeyboardFocusNavigationRoutines();
4502
+ }
4503
+ }
4504
+ // Non-deep-traversing patches: this descriptor map includes all descriptors that
4505
+ // do not five access to nodes beyond the immediate children.
4506
+ defineProperties(HTMLElement.prototype, {
4507
+ tabIndex: {
4508
+ get() {
4509
+ if (isSyntheticShadowHost(this)) {
4510
+ return tabIndexGetterPatched.call(this);
4511
+ }
4512
+ return tabIndexGetter.call(this);
4513
+ },
4514
+ set(v) {
4515
+ if (isSyntheticShadowHost(this)) {
4516
+ return tabIndexSetterPatched.call(this, v);
4517
+ }
4518
+ return tabIndexSetter.call(this, v);
4519
+ },
4520
+ enumerable: true,
4521
+ configurable: true,
4522
+ },
4523
+ blur: {
4524
+ value() {
4525
+ if (isSyntheticShadowHost(this)) {
4526
+ return blurPatched.call(this);
4527
+ }
4528
+ blur.call(this);
4529
+ },
4530
+ enumerable: true,
4531
+ writable: true,
4532
+ configurable: true,
4533
+ },
4534
+ focus: {
4535
+ value() {
4536
+ // Typescript does not like it when you treat the `arguments` object as an array
4537
+ // @ts-ignore type-mismatch
4538
+ focusPatched.apply(this, arguments);
4539
+ },
4540
+ enumerable: true,
4541
+ writable: true,
4542
+ configurable: true,
4543
+ },
4544
+ });
4545
+ // Note: In JSDOM innerText is not implemented: https://github.com/jsdom/jsdom/issues/1245
4546
+ if (innerTextGetter !== null && innerTextSetter !== null) {
4547
+ defineProperty(HTMLElement.prototype, 'innerText', {
4548
+ get() {
4549
+ // Note: we deviate from native shadow here, but are not fixing
4550
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
4551
+ return innerTextGetter.call(this);
4552
+ },
4553
+ set(v) {
4554
+ innerTextSetter.call(this, v);
4555
+ },
4556
+ enumerable: true,
4557
+ configurable: true,
4558
+ });
4559
+ }
4560
+ // Note: Firefox does not have outerText, https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/outerText
4561
+ if (outerTextGetter !== null && outerTextSetter !== null) {
4562
+ // From https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/outerText :
4563
+ // HTMLElement.outerText is a non-standard property. As a getter, it returns the same value as Node.innerText.
4564
+ // As a setter, it removes the current node and replaces it with the given text.
4565
+ defineProperty(HTMLElement.prototype, 'outerText', {
4566
+ get() {
4567
+ // Note: we deviate from native shadow here, but are not fixing
4568
+ // due to backwards compat: https://github.com/salesforce/lwc/pull/3103
4569
+ return outerTextGetter.call(this);
4570
+ },
4571
+ set(v) {
4572
+ // Invoking the `outerText` setter on a host element should trigger its disconnection, but until we merge node reactions, it will not work.
4573
+ // We could reimplement the outerText setter in JavaScript ([blink implementation](https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/html/html_element.cc;l=841-879;drc=6e8b402a6231405b753919029c9027404325ea00;bpv=0;bpt=1))
4574
+ // but the benefits don't worth the efforts.
4575
+ outerTextSetter.call(this, v);
4576
+ },
4577
+ enumerable: true,
4578
+ configurable: true,
4579
+ });
4580
+ }
4581
+
4582
+ /*
4583
+ * Copyright (c) 2018, salesforce.com, inc.
4584
+ * All rights reserved.
4585
+ * SPDX-License-Identifier: MIT
4586
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4587
+ */
4588
+ function getShadowToken(node) {
4589
+ return node[KEY__SHADOW_TOKEN];
4590
+ }
4591
+ function setShadowToken(node, shadowToken) {
4592
+ node[KEY__SHADOW_TOKEN] = shadowToken;
4593
+ }
4594
+ /**
4595
+ * Patching Element.prototype.$shadowToken$ to mark elements a portal:
4596
+ *
4597
+ * - we use a property to allow engines to set a custom attribute that should be
4598
+ * placed into the element to sandbox the css rules defined for the template.
4599
+ *
4600
+ * - this custom attribute must be unique.
4601
+ *
4602
+ **/
4603
+ defineProperty(Element.prototype, KEY__SHADOW_TOKEN, {
4604
+ set(shadowToken) {
4605
+ const oldShadowToken = this[KEY__SHADOW_TOKEN_PRIVATE];
4606
+ if (!isUndefined(oldShadowToken) && oldShadowToken !== shadowToken) {
4607
+ removeAttribute.call(this, oldShadowToken);
4608
+ }
4609
+ if (!isUndefined(shadowToken)) {
4610
+ setAttribute.call(this, shadowToken, '');
4611
+ }
4612
+ this[KEY__SHADOW_TOKEN_PRIVATE] = shadowToken;
4613
+ },
4614
+ get() {
4615
+ return this[KEY__SHADOW_TOKEN_PRIVATE];
4616
+ },
4617
+ configurable: true,
4618
+ });
4619
+ function recursivelySetShadowResolver(node, fn) {
4620
+ node[KEY__SHADOW_RESOLVER] = fn;
4621
+ const childNodes = childNodesGetter.call(node);
4622
+ for (let i = 0, n = childNodes.length; i < n; i++) {
4623
+ recursivelySetShadowResolver(childNodes[i], fn);
4624
+ }
4625
+ }
4626
+ defineProperty(Element.prototype, KEY__SHADOW_STATIC, {
4627
+ set(v) {
4628
+ // Marking an element as static will propagate the shadow resolver to the children.
4629
+ if (v) {
4630
+ const fn = this[KEY__SHADOW_RESOLVER];
4631
+ recursivelySetShadowResolver(this, fn);
4632
+ }
4633
+ this[KEY__SHADOW_STATIC_PRIVATE] = v;
4634
+ },
4635
+ get() {
4636
+ return this[KEY__SHADOW_STATIC_PRIVATE];
4637
+ },
4638
+ configurable: true,
4639
+ });
4640
+
4641
+ /*
4642
+ * Copyright (c) 2018, salesforce.com, inc.
4643
+ * All rights reserved.
4644
+ * SPDX-License-Identifier: MIT
4645
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4646
+ */
4647
+ const DomManualPrivateKey = '$$DomManualKey$$';
4648
+ // Resolver function used when a node is removed from within a portal
4649
+ const DocumentResolverFn = function () { };
4650
+ // We can use a single observer without having to worry about leaking because
4651
+ // "Registered observers in a node’s registered observer list have a weak
4652
+ // reference to the node."
4653
+ // https://dom.spec.whatwg.org/#garbage-collection
4654
+ let portalObserver;
4655
+ const portalObserverConfig = {
4656
+ childList: true,
4657
+ };
4658
+ function adoptChildNode(node, fn, shadowToken) {
4659
+ const previousNodeShadowResolver = getShadowRootResolver(node);
4660
+ if (previousNodeShadowResolver === fn) {
4661
+ return; // nothing to do here, it is already correctly patched
4662
+ }
4663
+ setShadowRootResolver(node, fn);
4664
+ if (node instanceof Element) {
4665
+ setShadowToken(node, shadowToken);
4666
+ if (isSyntheticShadowHost(node)) {
4667
+ // Root LWC elements can't get content slotted into them, therefore we don't observe their children.
4668
+ return;
4669
+ }
4670
+ if (isUndefined(previousNodeShadowResolver)) {
4671
+ // we only care about Element without shadowResolver (no MO.observe has been called)
4672
+ MutationObserverObserve.call(portalObserver, node, portalObserverConfig);
4673
+ }
4674
+ // recursively patching all children as well
4675
+ const childNodes = childNodesGetter.call(node);
4676
+ for (let i = 0, len = childNodes.length; i < len; i += 1) {
4677
+ adoptChildNode(childNodes[i], fn, shadowToken);
4678
+ }
4679
+ }
4680
+ }
4681
+ function initPortalObserver() {
4682
+ return new MO((mutations) => {
4683
+ forEach.call(mutations, (mutation) => {
4684
+ /**
4685
+ * This routine will process all nodes added or removed from elm (which is marked as a portal)
4686
+ * When adding a node to the portal element, we should add the ownership.
4687
+ * When removing a node from the portal element, this ownership should be removed.
4688
+ *
4689
+ * There is some special cases in which MutationObserver may call with stacked mutations (the same node
4690
+ * will be in addedNodes and removedNodes) or with false positives (a node that is removed and re-appended
4691
+ * in the same tick) for those cases, we cover by checking that the node is contained
4692
+ * (or not in the case of removal) by the element.
4693
+ */
4694
+ const { target: elm, addedNodes, removedNodes } = mutation;
4695
+ // the target of the mutation should always have a ShadowRootResolver attached to it
4696
+ const fn = getShadowRootResolver(elm);
4697
+ const shadowToken = getShadowToken(elm);
4698
+ // Process removals first to handle the case where an element is removed and reinserted
4699
+ for (let i = 0, len = removedNodes.length; i < len; i += 1) {
4700
+ const node = removedNodes[i];
4701
+ if (!(compareDocumentPosition.call(elm, node) & _Node.DOCUMENT_POSITION_CONTAINED_BY)) {
4702
+ adoptChildNode(node, DocumentResolverFn, undefined);
4703
+ }
4704
+ }
4705
+ for (let i = 0, len = addedNodes.length; i < len; i += 1) {
4706
+ const node = addedNodes[i];
4707
+ if (compareDocumentPosition.call(elm, node) & _Node.DOCUMENT_POSITION_CONTAINED_BY) {
4708
+ adoptChildNode(node, fn, shadowToken);
4709
+ }
4710
+ }
4711
+ });
4712
+ });
4713
+ }
4714
+ function markElementAsPortal(elm) {
4715
+ if (isUndefined(portalObserver)) {
4716
+ portalObserver = initPortalObserver();
4717
+ }
4718
+ if (isUndefined(getShadowRootResolver(elm))) {
4719
+ // only an element from a within a shadowRoot should be used here
4720
+ throw new Error(`Invalid Element`);
4721
+ }
4722
+ // install mutation observer for portals
4723
+ MutationObserverObserve.call(portalObserver, elm, portalObserverConfig);
4724
+ // TODO [#1253]: optimization to synchronously adopt new child nodes added
4725
+ // to this elm, we can do that by patching the most common operations
4726
+ // on the node itself
4727
+ }
4728
+ /**
4729
+ * Patching Element.prototype.$domManual$ to mark elements as portal:
4730
+ *
4731
+ * - we use a property to allow engines to signal that a particular element in
4732
+ * a shadow supports manual insertion of child nodes.
4733
+ *
4734
+ * - this signal comes as a boolean value, and we use it to install the MO instance
4735
+ * onto the element, to propagate the $ownerKey$ and $shadowToken$ to all new
4736
+ * child nodes.
4737
+ *
4738
+ * - at the moment, there is no way to undo this operation, once the element is
4739
+ * marked as $domManual$, setting it to false does nothing.
4740
+ *
4741
+ **/
4742
+ // TODO [#1306]: rename this to $observerConnection$
4743
+ defineProperty(Element.prototype, '$domManual$', {
4744
+ set(v) {
4745
+ this[DomManualPrivateKey] = v;
4746
+ if (isTrue(v)) {
4747
+ markElementAsPortal(this);
4748
+ }
4749
+ },
4750
+ get() {
4751
+ return this[DomManualPrivateKey];
4752
+ },
4753
+ configurable: true,
4754
+ });
4755
+ /** version: 2.45.3 */
4756
+ //# sourceMappingURL=index.cjs.js.map