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