lwc 2.50.0 → 3.0.1

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