lwc 2.50.0 → 3.0.0

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