lwc 2.50.0 → 3.0.1

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