lwc 2.50.0 → 3.0.1

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