@lwc/synthetic-shadow 3.1.2 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -7,11 +7,8 @@ import './env/document';
7
7
  import './env/window';
8
8
  import './env/mutation-observer';
9
9
  import './env/shadow-root';
10
- import './polyfills/HTMLSlotElement/main';
11
10
  import './polyfills/document-shadow/main';
12
11
  import './polyfills/shadow-root/main';
13
- import './polyfills/click-event-composed/main';
14
- import './polyfills/event-composed/main';
15
12
  import './polyfills/custom-event-composed/main';
16
13
  import './polyfills/clipboard-event-composed/main';
17
14
  import './polyfills/mutation-observer/main';
package/dist/index.js CHANGED
@@ -46,7 +46,6 @@ var assert = /*#__PURE__*/Object.freeze({
46
46
  const { assign, create, defineProperties, defineProperty, freeze, getOwnPropertyDescriptor, getOwnPropertyNames, getPrototypeOf, hasOwnProperty, isFrozen, keys, seal, setPrototypeOf, } = Object;
47
47
  const { isArray } = Array;
48
48
  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;
49
- const { charCodeAt: StringCharCodeAt, replace: StringReplace, split: StringSplit, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
50
49
  function isUndefined(obj) {
51
50
  return obj === undefined;
52
51
  }
@@ -97,12 +96,11 @@ function toString(obj) {
97
96
  const _globalThis = typeof globalThis === 'object' ? globalThis : window;
98
97
 
99
98
  /*
100
- * Copyright (c) 2018, salesforce.com, inc.
99
+ * Copyright (c) 2023, Salesforce.com, inc.
101
100
  * All rights reserved.
102
101
  * SPDX-License-Identifier: MIT
103
102
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
104
103
  */
105
- const KEY__IS_NATIVE_SHADOW_ROOT_DEFINED = '$isNativeShadowRootDefined$';
106
104
  const KEY__SHADOW_RESOLVER = '$shadowResolver$';
107
105
  const KEY__SHADOW_RESOLVER_PRIVATE = '$$ShadowResolverKey$$';
108
106
  const KEY__SHADOW_STATIC = '$shadowStaticNode$';
@@ -112,7 +110,7 @@ const KEY__SHADOW_TOKEN_PRIVATE = '$$ShadowTokenKey$$';
112
110
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
113
111
  const KEY__NATIVE_GET_ELEMENT_BY_ID = '$nativeGetElementById$';
114
112
  const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
115
- /** version: 3.1.2 */
113
+ /** version: 3.1.3 */
116
114
 
117
115
  /**
118
116
  * Copyright (C) 2023 salesforce.com, inc.
@@ -121,7 +119,7 @@ const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
121
119
  if (!_globalThis.lwcRuntimeFlags) {
122
120
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
123
121
  }
124
- /** version: 3.1.2 */
122
+ /** version: 3.1.3 */
125
123
 
126
124
  /*
127
125
  * Copyright (c) 2018, salesforce.com, inc.
@@ -209,24 +207,13 @@ const assignedSlotGetter$1 = hasOwnProperty.call(Element.prototype, 'assignedSlo
209
207
  : () => null;
210
208
 
211
209
  /*
212
- * Copyright (c) 2018, salesforce.com, inc.
210
+ * Copyright (c) 2023, Salesforce.com, inc.
213
211
  * All rights reserved.
214
212
  * SPDX-License-Identifier: MIT
215
213
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
216
214
  */
217
- let assignedNodes, assignedElements;
218
- if (typeof HTMLSlotElement !== 'undefined') {
219
- assignedNodes = HTMLSlotElement.prototype.assignedNodes;
220
- assignedElements = HTMLSlotElement.prototype.assignedElements;
221
- }
222
- else {
223
- assignedNodes = () => {
224
- 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");
225
- };
226
- assignedElements = () => {
227
- 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");
228
- };
229
- }
215
+ const assignedNodes = HTMLSlotElement.prototype.assignedNodes;
216
+ const assignedElements = HTMLSlotElement.prototype.assignedElements;
230
217
 
231
218
  /*
232
219
  * Copyright (c) 2018, salesforce.com, inc.
@@ -282,79 +269,14 @@ const MO = MutationObserver;
282
269
  const MutationObserverObserve = MO.prototype.observe;
283
270
 
284
271
  /*
285
- * Copyright (c) 2018, salesforce.com, inc.
286
- * All rights reserved.
287
- * SPDX-License-Identifier: MIT
288
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
289
- */
290
- let NativeShadowRoot = null;
291
- if (typeof ShadowRoot !== 'undefined') {
292
- NativeShadowRoot = ShadowRoot;
293
- }
294
- const isNativeShadowRootDefined = !isNull(NativeShadowRoot);
295
- const isInstanceOfNativeShadowRoot = isNull(NativeShadowRoot)
296
- ? () => false
297
- : (node) => node instanceof NativeShadowRoot;
298
-
299
- /*
300
- * Copyright (c) 2018, salesforce.com, inc.
301
- * All rights reserved.
302
- * SPDX-License-Identifier: MIT
303
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
304
- */
305
- function detect$2 () {
306
- return typeof HTMLSlotElement === 'undefined';
307
- }
308
-
309
- /*
310
- * Copyright (c) 2018, salesforce.com, inc.
311
- * All rights reserved.
312
- * SPDX-License-Identifier: MIT
313
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
314
- */
315
- const { createElement } = Document.prototype;
316
- const CHAR_S = 115;
317
- const CHAR_L = 108;
318
- const CHAR_O = 111;
319
- const CHAR_T = 116;
320
- function apply$2() {
321
- // IE11 does not have this element definition
322
- // we don't care much about the construction phase, just the prototype
323
- class HTMLSlotElement {
324
- }
325
- // prototype inheritance dance
326
- setPrototypeOf(HTMLSlotElement, HTMLElement.constructor);
327
- setPrototypeOf(HTMLSlotElement.prototype, HTMLElement.prototype);
328
- Window.prototype.HTMLSlotElement = HTMLSlotElement;
329
- // IE11 doesn't have HTMLSlotElement, in which case we
330
- // need to patch Document.prototype.createElement to remap `slot`
331
- // elements to the right prototype
332
- defineProperty(Document.prototype, 'createElement', {
333
- value: function (tagName, _options) {
334
- const elm = createElement.apply(this, ArraySlice.call(arguments));
335
- if (tagName.length === 4 &&
336
- StringCharCodeAt.call(tagName, 0) === CHAR_S &&
337
- StringCharCodeAt.call(tagName, 1) === CHAR_L &&
338
- StringCharCodeAt.call(tagName, 2) === CHAR_O &&
339
- StringCharCodeAt.call(tagName, 3) === CHAR_T) {
340
- // the new element is the `slot`, resetting the proto chain
341
- // the new newly created global HTMLSlotElement.prototype
342
- setPrototypeOf(elm, HTMLSlotElement.prototype);
343
- }
344
- return elm;
345
- },
346
- });
347
- }
348
-
349
- /*
350
- * Copyright (c) 2018, salesforce.com, inc.
272
+ * Copyright (c) 2023, Salesforce.com, inc.
351
273
  * All rights reserved.
352
274
  * SPDX-License-Identifier: MIT
353
275
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
354
276
  */
355
- if (detect$2()) {
356
- apply$2();
357
- }
277
+ // Capture the global `ShadowRoot` since synthetic shadow will override it later
278
+ const NativeShadowRoot = ShadowRoot;
279
+ const isInstanceOfNativeShadowRoot = (node) => node instanceof NativeShadowRoot;
358
280
 
359
281
  /*
360
282
  * Copyright (c) 2018, salesforce.com, inc.
@@ -405,12 +327,12 @@ function arrayFromCollection(collection) {
405
327
  }
406
328
 
407
329
  /*
408
- * Copyright (c) 2018, salesforce.com, inc.
330
+ * Copyright (c) 2023, Salesforce.com, inc.
409
331
  * All rights reserved.
410
332
  * SPDX-License-Identifier: MIT
411
333
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
412
334
  */
413
- const eventTargetPrototype = typeof EventTarget !== 'undefined' ? EventTarget.prototype : _Node.prototype;
335
+ const eventTargetPrototype = EventTarget.prototype;
414
336
  const { addEventListener, dispatchEvent, removeEventListener } = eventTargetPrototype;
415
337
 
416
338
  /*
@@ -1738,7 +1660,7 @@ function removeShadowRootEventListener(sr, type, listener, _options) {
1738
1660
  }
1739
1661
 
1740
1662
  /*
1741
- * Copyright (c) 2018, salesforce.com, inc.
1663
+ * Copyright (c) 2023, Salesforce.com, inc.
1742
1664
  * All rights reserved.
1743
1665
  * SPDX-License-Identifier: MIT
1744
1666
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -1769,9 +1691,6 @@ defineProperty(_Node.prototype, KEY__SHADOW_RESOLVER, {
1769
1691
  configurable: true,
1770
1692
  enumerable: true,
1771
1693
  });
1772
- defineProperty(_globalThis, KEY__IS_NATIVE_SHADOW_ROOT_DEFINED, {
1773
- value: isNativeShadowRootDefined,
1774
- });
1775
1694
  // The isUndefined check is because two copies of synthetic shadow may be loaded on the same page, and this
1776
1695
  // would throw an error if we tried to redefine it. Plus the whole point is to expose the native method.
1777
1696
  if (isUndefined(_globalThis[KEY__NATIVE_GET_ELEMENT_BY_ID])) {
@@ -2549,181 +2468,6 @@ Object.defineProperty(window, 'ShadowRoot', {
2549
2468
  writable: true,
2550
2469
  });
2551
2470
 
2552
- /*
2553
- * Copyright (c) 2018, salesforce.com, inc.
2554
- * All rights reserved.
2555
- * SPDX-License-Identifier: MIT
2556
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2557
- */
2558
- const composedDescriptor = Object.getOwnPropertyDescriptor(Event.prototype, 'composed');
2559
- function detect$1() {
2560
- if (!composedDescriptor) {
2561
- // No need to apply this polyfill if this client completely lacks
2562
- // support for the composed property.
2563
- return false;
2564
- }
2565
- // Assigning a throwaway click event here to suppress a ts error when we
2566
- // pass clickEvent into the composed getter below. The error is:
2567
- // [ts] Variable 'clickEvent' is used before being assigned.
2568
- let clickEvent = new Event('click');
2569
- const button = document.createElement('button');
2570
- button.addEventListener('click', (event) => (clickEvent = event));
2571
- button.click();
2572
- return !composedDescriptor.get.call(clickEvent);
2573
- }
2574
-
2575
- /*
2576
- * Copyright (c) 2018, salesforce.com, inc.
2577
- * All rights reserved.
2578
- * SPDX-License-Identifier: MIT
2579
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2580
- */
2581
- const originalClickDescriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'click');
2582
- function handleClick(event) {
2583
- Object.defineProperty(event, 'composed', {
2584
- configurable: true,
2585
- enumerable: true,
2586
- get() {
2587
- return true;
2588
- },
2589
- });
2590
- }
2591
- function apply$1() {
2592
- HTMLElement.prototype.click = function () {
2593
- addEventListener.call(this, 'click', handleClick);
2594
- try {
2595
- originalClickDescriptor.value.call(this);
2596
- }
2597
- finally {
2598
- removeEventListener.call(this, 'click', handleClick);
2599
- }
2600
- };
2601
- }
2602
-
2603
- /*
2604
- * Copyright (c) 2018, salesforce.com, inc.
2605
- * All rights reserved.
2606
- * SPDX-License-Identifier: MIT
2607
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2608
- */
2609
- if (detect$1()) {
2610
- apply$1();
2611
- }
2612
-
2613
- /*
2614
- * Copyright (c) 2018, salesforce.com, inc.
2615
- * All rights reserved.
2616
- * SPDX-License-Identifier: MIT
2617
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2618
- */
2619
- function detect() {
2620
- return new Event('test', { composed: true }).composed !== true;
2621
- }
2622
-
2623
- /*
2624
- * Copyright (c) 2018, salesforce.com, inc.
2625
- * All rights reserved.
2626
- * SPDX-License-Identifier: MIT
2627
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2628
- */
2629
- function apply() {
2630
- // https://github.com/w3c/webcomponents/issues/513#issuecomment-224183937
2631
- const composedEvents = assign(create(null), {
2632
- beforeinput: 1,
2633
- blur: 1,
2634
- click: 1,
2635
- compositionend: 1,
2636
- compositionstart: 1,
2637
- compositionupdate: 1,
2638
- copy: 1,
2639
- cut: 1,
2640
- dblclick: 1,
2641
- DOMActivate: 1,
2642
- DOMFocusIn: 1,
2643
- DOMFocusOut: 1,
2644
- drag: 1,
2645
- dragend: 1,
2646
- dragenter: 1,
2647
- dragleave: 1,
2648
- dragover: 1,
2649
- dragstart: 1,
2650
- drop: 1,
2651
- focus: 1,
2652
- focusin: 1,
2653
- focusout: 1,
2654
- gotpointercapture: 1,
2655
- input: 1,
2656
- keydown: 1,
2657
- keypress: 1,
2658
- keyup: 1,
2659
- lostpointercapture: 1,
2660
- mousedown: 1,
2661
- mouseenter: 1,
2662
- mouseleave: 1,
2663
- mousemove: 1,
2664
- mouseout: 1,
2665
- mouseover: 1,
2666
- mouseup: 1,
2667
- paste: 1,
2668
- pointercancel: 1,
2669
- pointerdown: 1,
2670
- pointerenter: 1,
2671
- pointerleave: 1,
2672
- pointermove: 1,
2673
- pointerout: 1,
2674
- pointerover: 1,
2675
- pointerup: 1,
2676
- touchcancel: 1,
2677
- touchend: 1,
2678
- touchmove: 1,
2679
- touchstart: 1,
2680
- wheel: 1,
2681
- });
2682
- const EventConstructor = Event;
2683
- // Patch Event constructor to add the composed property on events created via new Event.
2684
- function PatchedEvent(type, eventInitDict) {
2685
- const event = new EventConstructor(type, eventInitDict);
2686
- const isComposed = !!(eventInitDict && eventInitDict.composed);
2687
- Object.defineProperties(event, {
2688
- composed: {
2689
- get() {
2690
- return isComposed;
2691
- },
2692
- configurable: true,
2693
- enumerable: true,
2694
- },
2695
- });
2696
- return event;
2697
- }
2698
- PatchedEvent.prototype = EventConstructor.prototype;
2699
- PatchedEvent.AT_TARGET = EventConstructor.AT_TARGET;
2700
- PatchedEvent.BUBBLING_PHASE = EventConstructor.BUBBLING_PHASE;
2701
- PatchedEvent.CAPTURING_PHASE = EventConstructor.CAPTURING_PHASE;
2702
- PatchedEvent.NONE = EventConstructor.NONE;
2703
- window.Event = PatchedEvent;
2704
- // Patch the Event prototype to add the composed property on user agent dispatched event.
2705
- Object.defineProperties(Event.prototype, {
2706
- composed: {
2707
- get() {
2708
- const { type } = this;
2709
- return composedEvents[type] === 1;
2710
- },
2711
- configurable: true,
2712
- enumerable: true,
2713
- },
2714
- });
2715
- }
2716
-
2717
- /*
2718
- * Copyright (c) 2018, salesforce.com, inc.
2719
- * All rights reserved.
2720
- * SPDX-License-Identifier: MIT
2721
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2722
- */
2723
- if (detect()) {
2724
- apply();
2725
- }
2726
-
2727
2471
  /*
2728
2472
  * Copyright (c) 2018, salesforce.com, inc.
2729
2473
  * All rights reserved.
@@ -2749,11 +2493,13 @@ PatchedCustomEvent.prototype = CustomEventConstructor.prototype;
2749
2493
  window.CustomEvent = PatchedCustomEvent;
2750
2494
 
2751
2495
  /*
2752
- * Copyright (c) 2018, salesforce.com, inc.
2496
+ * Copyright (c) 2023, Salesforce.com, inc.
2753
2497
  * All rights reserved.
2754
2498
  * SPDX-License-Identifier: MIT
2755
2499
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2756
2500
  */
2501
+ // Note that ClipboardEvent is undefined in Jest/jsdom
2502
+ // See: https://github.com/jsdom/jsdom/issues/1568
2757
2503
  if (typeof ClipboardEvent !== 'undefined') {
2758
2504
  const isComposedType = assign(create(null), {
2759
2505
  copy: 1,
@@ -4465,5 +4211,5 @@ defineProperty(Element.prototype, '$domManual$', {
4465
4211
  },
4466
4212
  configurable: true,
4467
4213
  });
4468
- /** version: 3.1.2 */
4214
+ /** version: 3.1.3 */
4469
4215
  //# sourceMappingURL=index.js.map