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