lwc 2.50.0 → 3.0.0

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