@lwc/synthetic-shadow 2.45.2 → 2.45.4

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