@lwc/synthetic-shadow 6.2.0 → 6.2.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.
package/dist/index.js CHANGED
@@ -14,21 +14,40 @@ if (!lwcRuntimeFlags.ENABLE_FORCE_SHADOW_MIGRATE_MODE) {
14
14
  * SPDX-License-Identifier: MIT
15
15
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
16
16
  */
17
+ /**
18
+ *
19
+ * @param value
20
+ * @param msg
21
+ */
17
22
  function invariant(value, msg) {
18
23
  if (!value) {
19
24
  throw new Error(`Invariant Violation: ${msg}`);
20
25
  }
21
26
  }
27
+ /**
28
+ *
29
+ * @param value
30
+ * @param msg
31
+ */
22
32
  function isTrue$1(value, msg) {
23
33
  if (!value) {
24
34
  throw new Error(`Assert Violation: ${msg}`);
25
35
  }
26
36
  }
37
+ /**
38
+ *
39
+ * @param value
40
+ * @param msg
41
+ */
27
42
  function isFalse$1(value, msg) {
28
43
  if (value) {
29
44
  throw new Error(`Assert Violation: ${msg}`);
30
45
  }
31
46
  }
47
+ /**
48
+ *
49
+ * @param msg
50
+ */
32
51
  function fail(msg) {
33
52
  throw new Error(msg);
34
53
  }
@@ -42,50 +61,132 @@ var assert = /*#__PURE__*/Object.freeze({
42
61
  });
43
62
 
44
63
  /*
45
- * Copyright (c) 2018, salesforce.com, inc.
64
+ * Copyright (c) 2024, Salesforce, Inc.
46
65
  * All rights reserved.
47
66
  * SPDX-License-Identifier: MIT
48
67
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
49
68
  */
50
- const { assign, create, defineProperties, defineProperty, entries, freeze, getOwnPropertyDescriptor, getOwnPropertyDescriptors, getOwnPropertyNames, getPrototypeOf, hasOwnProperty, isFrozen, keys, seal, setPrototypeOf, } = Object;
69
+ const {
70
+ /** Detached {@linkcode Object.assign}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign MDN Reference}. */
71
+ assign,
72
+ /** Detached {@linkcode Object.create}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create MDN Reference}. */
73
+ create,
74
+ /** Detached {@linkcode Object.defineProperties}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties MDN Reference}. */
75
+ defineProperties,
76
+ /** Detached {@linkcode Object.defineProperty}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty MDN Reference}. */
77
+ defineProperty,
78
+ /** Detached {@linkcode Object.entries}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries MDN Reference}. */
79
+ entries,
80
+ /** Detached {@linkcode Object.freeze}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze MDN Reference}. */
81
+ freeze,
82
+ /** Detached {@linkcode Object.getOwnPropertyDescriptor}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor MDN Reference}. */
83
+ getOwnPropertyDescriptor,
84
+ /** Detached {@linkcode Object.getOwnPropertyDescriptors}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors MDN Reference}. */
85
+ getOwnPropertyDescriptors,
86
+ /** Detached {@linkcode Object.getOwnPropertyNames}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames MDN Reference}. */
87
+ getOwnPropertyNames,
88
+ /** Detached {@linkcode Object.getPrototypeOf}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf MDN Reference}. */
89
+ getPrototypeOf,
90
+ /** Detached {@linkcode Object.hasOwnProperty}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty MDN Reference}. */
91
+ hasOwnProperty,
92
+ /** Detached {@linkcode Object.isFrozen}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen MDN Reference}. */
93
+ isFrozen,
94
+ /** Detached {@linkcode Object.keys}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys MDN Reference}. */
95
+ keys,
96
+ /** Detached {@linkcode Object.seal}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal MDN Reference}. */
97
+ seal,
98
+ /** Detached {@linkcode Object.setPrototypeOf}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf MDN Reference}. */
99
+ setPrototypeOf, } = Object;
100
+ /** Detached {@linkcode Array.isArray}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray MDN Reference}. */
51
101
  const { isArray } = Array;
52
- const { concat: ArrayConcat, copyWithin: ArrayCopyWithin, every: ArrayEvery, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, findIndex: ArrayFindIndex, includes: ArrayIncludes, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, some: ArraySome, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, } = Array.prototype;
102
+ // For some reason, JSDoc don't get picked up for multiple renamed destructured constants (even
103
+ // though it works fine for one, e.g. isArray), so comments for these are added to the export
104
+ // statement, rather than this declaration.
105
+ const { concat: ArrayConcat, copyWithin: ArrayCopyWithin, every: ArrayEvery, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, findIndex: ArrayFindIndex, includes: ArrayIncludes, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, some: ArraySome, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, // Weird anomaly!
106
+ } = Array.prototype;
107
+ /**
108
+ * Determines whether the argument is `undefined`.
109
+ * @param obj Value to test
110
+ * @returns `true` if the value is `undefined`.
111
+ */
53
112
  function isUndefined(obj) {
54
113
  return obj === undefined;
55
114
  }
115
+ /**
116
+ * Determines whether the argument is `null`.
117
+ * @param obj Value to test
118
+ * @returns `true` if the value is `null`.
119
+ */
56
120
  function isNull(obj) {
57
121
  return obj === null;
58
122
  }
123
+ /**
124
+ * Determines whether the argument is `true`.
125
+ * @param obj Value to test
126
+ * @returns `true` if the value is `true`.
127
+ */
59
128
  function isTrue(obj) {
60
129
  return obj === true;
61
130
  }
131
+ /**
132
+ * Determines whether the argument is `false`.
133
+ * @param obj Value to test
134
+ * @returns `true` if the value is `false`.
135
+ */
62
136
  function isFalse(obj) {
63
137
  return obj === false;
64
138
  }
139
+ /**
140
+ * Determines whether the argument is a function.
141
+ * @param obj Value to test
142
+ * @returns `true` if the value is a function.
143
+ */
65
144
  // Replacing `Function` with a narrower type that works for all our use cases is tricky...
66
145
  // eslint-disable-next-line @typescript-eslint/ban-types
67
146
  function isFunction(obj) {
68
147
  return typeof obj === 'function';
69
148
  }
149
+ /**
150
+ * Determines whether the argument is an object or null.
151
+ * @param obj Value to test
152
+ * @returns `true` if the value is an object or null.
153
+ */
70
154
  function isObject(obj) {
71
155
  return typeof obj === 'object';
72
156
  }
73
157
  const OtS = {}.toString;
158
+ /**
159
+ * Converts the argument to a string, safely accounting for objects with "null" prototype.
160
+ * Note that `toString(null)` returns `"[object Null]"` rather than `"null"`.
161
+ * @param obj Value to convert to a string.
162
+ * @returns String representation of the value.
163
+ */
74
164
  function toString(obj) {
75
- if (obj && obj.toString) {
165
+ if (obj?.toString) {
76
166
  // Arrays might hold objects with "null" prototype So using
77
167
  // Array.prototype.toString directly will cause an error Iterate through
78
168
  // all the items and handle individually.
79
169
  if (isArray(obj)) {
170
+ // This behavior is slightly different from Array#toString:
171
+ // 1. Array#toString calls `this.join`, rather than Array#join
172
+ // Ex: arr = []; arr.join = () => 1; arr.toString() === 1; toString(arr) === ''
173
+ // 2. Array#toString delegates to Object#toString if `this.join` is not a function
174
+ // Ex: arr = []; arr.join = 'no'; arr.toString() === '[object Array]; toString(arr) = ''
175
+ // 3. Array#toString converts null/undefined to ''
176
+ // Ex: arr = [null, undefined]; arr.toString() === ','; toString(arr) === '[object Null],undefined'
177
+ // 4. Array#toString converts recursive references to arrays to ''
178
+ // Ex: arr = [1]; arr.push(arr, 2); arr.toString() === '1,,2'; toString(arr) throws
179
+ // Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString
80
180
  return ArrayJoin.call(ArrayMap.call(obj, toString), ',');
81
181
  }
82
182
  return obj.toString();
83
183
  }
84
184
  else if (typeof obj === 'object') {
185
+ // This catches null and returns "[object Null]". Weird, but kept for backwards compatibility.
85
186
  return OtS.call(obj);
86
187
  }
87
188
  else {
88
- return obj + '';
189
+ return String(obj);
89
190
  }
90
191
  }
91
192
 
@@ -107,7 +208,7 @@ const KEY__LEGACY_SHADOW_TOKEN_PRIVATE = '$$LegacyShadowTokenKey$$';
107
208
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
108
209
  const KEY__NATIVE_GET_ELEMENT_BY_ID = '$nativeGetElementById$';
109
210
  const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
110
- /** version: 6.2.0 */
211
+ /** version: 6.2.1 */
111
212
 
112
213
  /**
113
214
  * Copyright (c) 2024 Salesforce, Inc.
@@ -115,7 +216,7 @@ const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
115
216
  if (!globalThis.lwcRuntimeFlags) {
116
217
  Object.defineProperty(globalThis, 'lwcRuntimeFlags', { value: create(null) });
117
218
  }
118
- /** version: 6.2.0 */
219
+ /** version: 6.2.1 */
119
220
 
120
221
  /*
121
222
  * Copyright (c) 2018, salesforce.com, inc.
@@ -384,6 +485,7 @@ function getNodeKey(node) {
384
485
  * This function does not traverse up for performance reasons, but is sufficient for most use
385
486
  * cases. If we need to traverse up and verify those nodes that don't have owner key, use
386
487
  * isNodeDeepShadowed instead.
488
+ * @param node
387
489
  */
388
490
  function isNodeShadowed(node) {
389
491
  return !isUndefined(getNodeOwnerKey(node));
@@ -440,7 +542,7 @@ function isNodeSlotted(host, node) {
440
542
  // have different owner key. for slotted elements, this is possible
441
543
  // if the parent happens to be a slot.
442
544
  if (isSlotElement(parent)) {
443
- /**
545
+ /*
444
546
  * the slot parent might be allocated inside another slot, think of:
445
547
  * <x-root> (<--- root element)
446
548
  * <x-parent> (<--- own by x-root)
@@ -1064,6 +1166,7 @@ function createStaticHTMLCollection(items) {
1064
1166
  * based on the light-dom slotting mechanism. This applies to synthetic slot elements
1065
1167
  * and elements with shadow dom attached to them. It doesn't apply to native slot elements
1066
1168
  * because we don't want to patch the children getters for those elements.
1169
+ * @param node
1067
1170
  */
1068
1171
  function hasMountedChildren(node) {
1069
1172
  return isSyntheticSlotElement(node) || isSyntheticShadowHost(node);
@@ -1198,10 +1301,10 @@ const getDocumentOrRootNode = !isUndefined(nativeGetRootNode)
1198
1301
  * Get the shadow root
1199
1302
  * getNodeOwner() returns the host element that owns the given node
1200
1303
  * Note: getNodeOwner() returns null when running in native-shadow mode.
1201
- * Fallback to using the native getRootNode() to discover the root node.
1202
- * This is because, it is not possible to inspect the node and decide if it is part
1203
- * of a native shadow or the synthetic shadow.
1204
- * @param {Node} node
1304
+ * Fallback to using the native getRootNode() to discover the root node.
1305
+ * This is because, it is not possible to inspect the node and decide if it is part
1306
+ * of a native shadow or the synthetic shadow.
1307
+ * @param node
1205
1308
  */
1206
1309
  function getNearestRoot(node) {
1207
1310
  const ownerNode = getNodeOwner(node);
@@ -1219,17 +1322,17 @@ function getNearestRoot(node) {
1219
1322
  *
1220
1323
  * If looking for a shadow root of a node by calling `node.getRootNode({composed: false})` or `node.getRootNode()`,
1221
1324
  *
1222
- * 1. Try to identify the host element that owns the give node.
1223
- * i. Identify the shadow tree that the node belongs to
1224
- * ii. If the node belongs to a shadow tree created by engine, return the shadowRoot of the host element that owns the shadow tree
1225
- * 2. The host identification logic returns null in two cases:
1226
- * i. The node does not belong to a shadow tree created by engine
1227
- * ii. The engine is running in native shadow dom mode
1228
- * If so, use the original Node.prototype.getRootNode to fetch the root node(or manually climb up the dom tree where getRootNode() is unsupported)
1325
+ * 1. Try to identify the host element that owns the give node.
1326
+ * i. Identify the shadow tree that the node belongs to
1327
+ * ii. If the node belongs to a shadow tree created by engine, return the shadowRoot of the host element that owns the shadow tree
1328
+ * 2. The host identification logic returns null in two cases:
1329
+ * i. The node does not belong to a shadow tree created by engine
1330
+ * ii. The engine is running in native shadow dom mode
1331
+ * If so, use the original Node.prototype.getRootNode to fetch the root node(or manually climb up the dom tree where getRootNode() is unsupported)
1229
1332
  *
1230
1333
  * _Spec_: https://dom.spec.whatwg.org/#dom-node-getrootnode
1231
- *
1232
- **/
1334
+ * @param options
1335
+ */
1233
1336
  function getRootNodePatched(options) {
1234
1337
  const composed = isUndefined(options) ? false : !!options.composed;
1235
1338
  return isTrue(composed) ? getDocumentOrRootNode.call(this, options) : getNearestRoot(this);
@@ -1481,6 +1584,7 @@ function getEventMap(elm) {
1481
1584
  * Events dispatched on shadow roots actually end up being dispatched on their hosts. This means that the event.target
1482
1585
  * property of events dispatched on shadow roots always resolve to their host. This function understands this
1483
1586
  * abstraction and properly returns a reference to the shadow root when appropriate.
1587
+ * @param event
1484
1588
  */
1485
1589
  function getActualTarget(event) {
1486
1590
  return eventToShadowRootMap.get(event) ?? eventTargetGetter.call(event);
@@ -2288,7 +2392,7 @@ function retarget(refNode, path) {
2288
2392
  rootIdx = refNodePath.indexOf(root);
2289
2393
  lastRoot = root;
2290
2394
  }
2291
- if (!isSyntheticShadowRoot(root) || (!isUndefined(rootIdx) && rootIdx > -1)) {
2395
+ if (!isUndefined(rootIdx) && rootIdx > -1) {
2292
2396
  return ancestor;
2293
2397
  }
2294
2398
  }
@@ -2534,7 +2638,7 @@ function setNodeObservers(node, observers) {
2534
2638
  }
2535
2639
  /**
2536
2640
  * Retarget the mutation record's target value to its shadowRoot
2537
- * @param {MutationRecord} originalRecord
2641
+ * @param originalRecord
2538
2642
  */
2539
2643
  function retargetMutationRecord(originalRecord) {
2540
2644
  const { addedNodes, removedNodes, target, type } = originalRecord;
@@ -2574,8 +2678,8 @@ function retargetMutationRecord(originalRecord) {
2574
2678
  /**
2575
2679
  * Utility to identify if a target node is being observed by the given observer
2576
2680
  * Start at the current node, if the observer is registered to observe the current node, the mutation qualifies
2577
- * @param {MutationObserver} observer
2578
- * @param {Node} target
2681
+ * @param observer
2682
+ * @param target
2579
2683
  */
2580
2684
  function isQualifiedObserver(observer, target) {
2581
2685
  let parentNode = target;
@@ -2596,8 +2700,8 @@ function isQualifiedObserver(observer, target) {
2596
2700
  * The key logic here is to determine if a given observer has been registered to observe any nodes
2597
2701
  * between the target node of a mutation record to the target's root node.
2598
2702
  * This function also retargets records when mutations occur directly under the shadow root
2599
- * @param {MutationRecords[]} mutations
2600
- * @param {MutationObserver} observer
2703
+ * @param mutations
2704
+ * @param observer
2601
2705
  */
2602
2706
  function filterMutationRecords(mutations, observer) {
2603
2707
  const result = [];
@@ -2679,7 +2783,7 @@ function getWrappedCallback(callback) {
2679
2783
  * Patched MutationObserver constructor.
2680
2784
  * 1. Wrap the callback to filter out MutationRecords based on dom ownership
2681
2785
  * 2. Add a property field to track all observed targets of the observer instance
2682
- * @param {MutationCallback} callback
2786
+ * @param callback
2683
2787
  */
2684
2788
  function PatchedMutationObserver(callback) {
2685
2789
  const wrappedCallback = getWrappedCallback(callback);
@@ -2706,8 +2810,8 @@ function patchedDisconnect() {
2706
2810
  /**
2707
2811
  * A single mutation observer can observe multiple nodes(target).
2708
2812
  * Maintain a list of all targets that the observer chooses to observe
2709
- * @param {Node} target
2710
- * @param {Object} options
2813
+ * @param target
2814
+ * @param options
2711
2815
  */
2712
2816
  function patchedObserve(target, options) {
2713
2817
  let targetObservers = getNodeObservers(target);
@@ -3045,9 +3149,8 @@ function assignedSlotGetterPatched() {
3045
3149
  }
3046
3150
  /**
3047
3151
  * The node is assigned to a slot if:
3048
- * - it has a parent and its parent is a slot element
3049
- * - and if the slot owner key is different than the node owner key.
3050
- *
3152
+ * - it has a parent and its parent is a slot element
3153
+ * - and if the slot owner key is different than the node owner key.
3051
3154
  * When the slot and the slotted node are 2 different shadow trees, the owner keys will be
3052
3155
  * different. When the slot is in a shadow tree and the slotted content is a light DOM node,
3053
3156
  * the light DOM node doesn't have an owner key and therefor the slot owner key will be
@@ -3162,6 +3265,8 @@ defineProperties(Text.prototype, {
3162
3265
  /**
3163
3266
  * This methods filters out elements that are not in the same shadow root of context.
3164
3267
  * It does not enforce shadow dom semantics if $context is not managed by LWC
3268
+ * @param context
3269
+ * @param unfilteredNodes
3165
3270
  */
3166
3271
  function getNonPatchedFilteredArrayOfNodes(context, unfilteredNodes) {
3167
3272
  let filtered;
@@ -3870,6 +3975,7 @@ function tabIndexGetterPatched() {
3870
3975
  }
3871
3976
  /**
3872
3977
  * This method only applies to elements with a shadow attached to them
3978
+ * @param value
3873
3979
  */
3874
3980
  function tabIndexSetterPatched(value) {
3875
3981
  // This tabIndex setter might be confusing unless it is understood that HTML
@@ -4050,13 +4156,10 @@ function setShadowToken(node, shadowToken) {
4050
4156
  }
4051
4157
  /**
4052
4158
  * Patching Element.prototype.$shadowToken$ to mark elements a portal:
4053
- *
4054
- * - we use a property to allow engines to set a custom attribute that should be
4055
- * placed into the element to sandbox the css rules defined for the template.
4056
- *
4057
- * - this custom attribute must be unique.
4058
- *
4059
- **/
4159
+ * - we use a property to allow engines to set a custom attribute that should be
4160
+ * placed into the element to sandbox the css rules defined for the template.
4161
+ * - this custom attribute must be unique.
4162
+ */
4060
4163
  defineProperty(Element.prototype, KEY__SHADOW_TOKEN, {
4061
4164
  set(shadowToken) {
4062
4165
  const oldShadowToken = this[KEY__SHADOW_TOKEN_PRIVATE];
@@ -4111,7 +4214,7 @@ function setLegacyShadowToken(node, shadowToken) {
4111
4214
  /**
4112
4215
  * Patching Element.prototype.$legacyShadowToken$ to mark elements a portal:
4113
4216
  * Same as $shadowToken$ but for legacy CSS scope tokens.
4114
- **/
4217
+ */
4115
4218
  defineProperty(Element.prototype, KEY__LEGACY_SHADOW_TOKEN, {
4116
4219
  set(shadowToken) {
4117
4220
  const oldShadowToken = this[KEY__LEGACY_SHADOW_TOKEN_PRIVATE];
@@ -4225,18 +4328,14 @@ function markElementAsPortal(elm) {
4225
4328
  }
4226
4329
  /**
4227
4330
  * Patching Element.prototype.$domManual$ to mark elements as portal:
4228
- *
4229
- * - we use a property to allow engines to signal that a particular element in
4230
- * a shadow supports manual insertion of child nodes.
4231
- *
4232
- * - this signal comes as a boolean value, and we use it to install the MO instance
4233
- * onto the element, to propagate the $ownerKey$ and $shadowToken$ to all new
4234
- * child nodes.
4235
- *
4236
- * - at the moment, there is no way to undo this operation, once the element is
4237
- * marked as $domManual$, setting it to false does nothing.
4238
- *
4239
- **/
4331
+ * - we use a property to allow engines to signal that a particular element in
4332
+ * a shadow supports manual insertion of child nodes.
4333
+ * - this signal comes as a boolean value, and we use it to install the MO instance
4334
+ * onto the element, to propagate the $ownerKey$ and $shadowToken$ to all new
4335
+ * child nodes.
4336
+ * - at the moment, there is no way to undo this operation, once the element is
4337
+ * marked as $domManual$, setting it to false does nothing.
4338
+ */
4240
4339
  // TODO [#1306]: rename this to $observerConnection$
4241
4340
  defineProperty(Element.prototype, '$domManual$', {
4242
4341
  set(v) {
@@ -4250,6 +4349,6 @@ defineProperty(Element.prototype, '$domManual$', {
4250
4349
  },
4251
4350
  configurable: true,
4252
4351
  });
4253
- /** version: 6.2.0 */
4352
+ /** version: 6.2.1 */
4254
4353
  }
4255
4354
  //# sourceMappingURL=index.js.map