@lwc/synthetic-shadow 9.0.1 → 9.0.3

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