@lwc/ssr-runtime 8.10.1 → 8.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -258,24 +258,44 @@ defineProperties,
258
258
  defineProperty,
259
259
  /** Detached {@linkcode Object.entries}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries MDN Reference}. */
260
260
  entries,
261
+ /** Detached {@linkcode Object.freeze}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze MDN Reference}. */
262
+ freeze,
263
+ /** Detached {@linkcode Object.fromEntries}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries MDN Reference}. */
264
+ fromEntries,
265
+ /** Detached {@linkcode Object.getOwnPropertyDescriptor}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor MDN Reference}. */
266
+ getOwnPropertyDescriptor: getOwnPropertyDescriptor$1,
267
+ /** Detached {@linkcode Object.getOwnPropertyDescriptors}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors MDN Reference}. */
268
+ getOwnPropertyDescriptors,
261
269
  /** Detached {@linkcode Object.getOwnPropertyNames}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames MDN Reference}. */
262
270
  getOwnPropertyNames: getOwnPropertyNames$1,
271
+ /** Detached {@linkcode Object.getOwnPropertySymbols}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols MDN Reference}. */
272
+ getOwnPropertySymbols: getOwnPropertySymbols$1,
273
+ /** Detached {@linkcode Object.getPrototypeOf}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf MDN Reference}. */
274
+ getPrototypeOf: getPrototypeOf$1,
263
275
  /** Detached {@linkcode Object.hasOwnProperty}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty MDN Reference}. */
264
276
  hasOwnProperty: hasOwnProperty$1,
277
+ /** Detached {@linkcode Object.isFrozen}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen MDN Reference}. */
278
+ isFrozen,
265
279
  /** Detached {@linkcode Object.keys}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys MDN Reference}. */
266
- keys} = Object;
280
+ keys,
281
+ /** Detached {@linkcode Object.seal}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal MDN Reference}. */
282
+ seal,
283
+ /** Detached {@linkcode Object.setPrototypeOf}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf MDN Reference}. */
284
+ setPrototypeOf, } = Object;
267
285
  const {
268
286
  /** Detached {@linkcode Array.isArray}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray MDN Reference}. */
269
- isArray: isArray$1} = Array;
287
+ isArray: isArray$1,
288
+ /** Detached {@linkcode Array.from}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from MDN Reference}. */
289
+ from: ArrayFrom, } = Array;
270
290
  // For some reason, JSDoc don't get picked up for multiple renamed destructured constants (even
271
291
  // though it works fine for one, e.g. isArray), so comments for these are added to the export
272
292
  // statement, rather than this declaration.
273
- const { join: ArrayJoin, map: ArrayMap, forEach, // Weird anomaly!
293
+ const { concat: ArrayConcat$1, copyWithin: ArrayCopyWithin, every: ArrayEvery, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, findIndex: ArrayFindIndex, includes: ArrayIncludes, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush$1, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, some: ArraySome, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, // Weird anomaly!
274
294
  } = Array.prototype;
275
295
  /** Detached {@linkcode String.fromCharCode}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode MDN Reference}. */
276
296
  const { fromCharCode: StringFromCharCode } = String;
277
297
  // No JSDocs here - see comment for Array.prototype
278
- const { charCodeAt: StringCharCodeAt, replace: StringReplace, toLowerCase: StringToLowerCase} = String.prototype;
298
+ const { charAt: StringCharAt, charCodeAt: StringCharCodeAt, replace: StringReplace, split: StringSplit, slice: StringSlice, toLowerCase: StringToLowerCase, trim: StringTrim, } = String.prototype;
279
299
  /**
280
300
  * Determines whether the argument is `undefined`.
281
301
  * @param obj Value to test
@@ -292,6 +312,14 @@ function isUndefined$1(obj) {
292
312
  function isNull(obj) {
293
313
  return obj === null;
294
314
  }
315
+ /**
316
+ * Determines whether the argument is an object or null.
317
+ * @param obj Value to test
318
+ * @returns `true` if the value is an object or null.
319
+ */
320
+ function isObject(obj) {
321
+ return typeof obj === 'object';
322
+ }
295
323
  /**
296
324
  * Determines whether the argument is a string.
297
325
  * @param obj Value to test
@@ -545,6 +573,52 @@ function htmlEscape(str, attrMode = false) {
545
573
  return str.replace(searchValue, (char) => ESCAPED_CHARS[char]);
546
574
  }
547
575
 
576
+ /*
577
+ * Copyright (c) 2020, salesforce.com, inc.
578
+ * All rights reserved.
579
+ * SPDX-License-Identifier: MIT
580
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
581
+ */
582
+ /**
583
+ * [ncls] - Normalize class name attribute.
584
+ *
585
+ * Transforms the provided class property value from an object/string into a string the diffing algo
586
+ * can operate on.
587
+ *
588
+ * This implementation is borrowed from Vue:
589
+ * https://github.com/vuejs/core/blob/e790e1bdd7df7be39e14780529db86e4da47a3db/packages/shared/src/normalizeProp.ts#L63-L82
590
+ */
591
+ function normalizeClass(value) {
592
+ if (isUndefined$1(value) || isNull(value)) {
593
+ // Returning undefined here improves initial render cost, because the old vnode's class will be considered
594
+ // undefined in the `patchClassAttribute` routine, so `oldClass === newClass` will be true so we return early
595
+ return undefined;
596
+ }
597
+ let res = '';
598
+ if (isString(value)) {
599
+ res = value;
600
+ }
601
+ else if (isArray$1(value)) {
602
+ for (let i = 0; i < value.length; i++) {
603
+ const normalized = normalizeClass(value[i]);
604
+ if (normalized) {
605
+ res += normalized + ' ';
606
+ }
607
+ }
608
+ }
609
+ else if (isObject(value) && !isNull(value)) {
610
+ // Iterate own enumerable keys of the object
611
+ const _keys = keys(value);
612
+ for (let i = 0; i < _keys.length; i += 1) {
613
+ const key = _keys[i];
614
+ if (value[key]) {
615
+ res += key + ' ';
616
+ }
617
+ }
618
+ }
619
+ return StringTrim.call(res);
620
+ }
621
+
548
622
  /*
549
623
  * Copyright (c) 2024, Salesforce, Inc.
550
624
  * All rights reserved.
@@ -567,18 +641,6 @@ function setHooks(hooks) {
567
641
  hooksAreSet = true;
568
642
  sanitizeHtmlContent = hooks.sanitizeHtmlContent;
569
643
  }
570
- function flattenStylesheets(stylesheets) {
571
- const list = [];
572
- for (const stylesheet of stylesheets) {
573
- if (!isArray$1(stylesheet)) {
574
- list.push(stylesheet);
575
- }
576
- else {
577
- list.push(...flattenStylesheets(stylesheet));
578
- }
579
- }
580
- return list;
581
- }
582
644
 
583
645
  /*
584
646
  * Copyright (c) 2024, Salesforce, Inc.
@@ -587,7 +649,7 @@ function flattenStylesheets(stylesheets) {
587
649
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
588
650
  */
589
651
  const DEFAULT_SSR_MODE = 'sync';
590
- /** version: 8.10.1 */
652
+ /** version: 8.12.0 */
591
653
 
592
654
  /*
593
655
  * Copyright (c) 2024, Salesforce, Inc.
@@ -665,493 +727,550 @@ class ClassList {
665
727
  }
666
728
  }
667
729
 
668
- /******************************************************************************
669
- Copyright (c) Microsoft Corporation.
670
-
671
- Permission to use, copy, modify, and/or distribute this software for any
672
- purpose with or without fee is hereby granted.
673
-
674
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
675
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
676
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
677
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
678
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
679
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
680
- PERFORMANCE OF THIS SOFTWARE.
681
- ***************************************************************************** */
682
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
683
-
684
-
685
- function __classPrivateFieldGet(receiver, state, kind, f) {
686
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
687
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
688
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
689
- }
690
-
691
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
692
- if (kind === "m") throw new TypeError("Private method is not writable");
693
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
694
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
695
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
696
- }
697
-
698
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
699
- var e = new Error(message);
700
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
701
- };
702
-
703
- /*
704
- * Copyright (c) 2024, Salesforce, Inc.
705
- * All rights reserved.
706
- * SPDX-License-Identifier: MIT
707
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
730
+ /**
731
+ * Copyright (C) 2017 salesforce.com, inc.
708
732
  */
709
- var _MutationTracker_enabledSet, _MutationTracker_mutationMap;
710
- class MutationTracker {
711
- constructor() {
712
- _MutationTracker_enabledSet.set(this, new WeakSet());
713
- _MutationTracker_mutationMap.set(this, new WeakMap());
733
+ const { isArray } = Array;
734
+ const { prototype: ObjectDotPrototype, getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, } = Object;
735
+ const { push: ArrayPush, concat: ArrayConcat } = Array.prototype;
736
+ const OtS = {}.toString;
737
+ function toString(obj) {
738
+ if (obj && obj.toString) {
739
+ return obj.toString();
714
740
  }
715
- add(instance, attrName) {
716
- if (__classPrivateFieldGet(this, _MutationTracker_enabledSet, "f").has(instance)) {
717
- let mutatedAttrs = __classPrivateFieldGet(this, _MutationTracker_mutationMap, "f").get(instance);
718
- if (!mutatedAttrs) {
719
- mutatedAttrs = new Set();
720
- __classPrivateFieldGet(this, _MutationTracker_mutationMap, "f").set(instance, mutatedAttrs);
741
+ else if (typeof obj === 'object') {
742
+ return OtS.call(obj);
743
+ }
744
+ else {
745
+ return obj + '';
746
+ }
747
+ }
748
+ function isUndefined(obj) {
749
+ return obj === undefined;
750
+ }
751
+ function isFunction(obj) {
752
+ return typeof obj === 'function';
753
+ }
754
+ const proxyToValueMap = new WeakMap();
755
+ function registerProxy(proxy, value) {
756
+ proxyToValueMap.set(proxy, value);
757
+ }
758
+ const unwrap = (replicaOrAny) => proxyToValueMap.get(replicaOrAny) || replicaOrAny;
759
+
760
+ class BaseProxyHandler {
761
+ constructor(membrane, value) {
762
+ this.originalTarget = value;
763
+ this.membrane = membrane;
764
+ }
765
+ // Shared utility methods
766
+ wrapDescriptor(descriptor) {
767
+ if (hasOwnProperty.call(descriptor, 'value')) {
768
+ descriptor.value = this.wrapValue(descriptor.value);
769
+ }
770
+ else {
771
+ const { set: originalSet, get: originalGet } = descriptor;
772
+ if (!isUndefined(originalGet)) {
773
+ descriptor.get = this.wrapGetter(originalGet);
774
+ }
775
+ if (!isUndefined(originalSet)) {
776
+ descriptor.set = this.wrapSetter(originalSet);
721
777
  }
722
- mutatedAttrs.add(attrName.toLowerCase());
723
778
  }
779
+ return descriptor;
724
780
  }
725
- enable(instance) {
726
- __classPrivateFieldGet(this, _MutationTracker_enabledSet, "f").add(instance);
781
+ copyDescriptorIntoShadowTarget(shadowTarget, key) {
782
+ const { originalTarget } = this;
783
+ // Note: a property might get defined multiple times in the shadowTarget
784
+ // but it will always be compatible with the previous descriptor
785
+ // to preserve the object invariants, which makes these lines safe.
786
+ const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key);
787
+ // TODO: it should be impossible for the originalDescriptor to ever be undefined, this `if` can be removed
788
+ /* istanbul ignore else */
789
+ if (!isUndefined(originalDescriptor)) {
790
+ const wrappedDesc = this.wrapDescriptor(originalDescriptor);
791
+ ObjectDefineProperty(shadowTarget, key, wrappedDesc);
792
+ }
727
793
  }
728
- disable(instance) {
729
- __classPrivateFieldGet(this, _MutationTracker_enabledSet, "f").delete(instance);
794
+ lockShadowTarget(shadowTarget) {
795
+ const { originalTarget } = this;
796
+ const targetKeys = ArrayConcat.call(getOwnPropertyNames(originalTarget), getOwnPropertySymbols(originalTarget));
797
+ targetKeys.forEach((key) => {
798
+ this.copyDescriptorIntoShadowTarget(shadowTarget, key);
799
+ });
800
+ const { membrane: { tagPropertyKey }, } = this;
801
+ if (!isUndefined(tagPropertyKey) && !hasOwnProperty.call(shadowTarget, tagPropertyKey)) {
802
+ ObjectDefineProperty(shadowTarget, tagPropertyKey, ObjectCreate(null));
803
+ }
804
+ preventExtensions(shadowTarget);
730
805
  }
731
- renderMutatedAttrs(instance) {
732
- const mutatedAttrs = __classPrivateFieldGet(this, _MutationTracker_mutationMap, "f").get(instance);
733
- if (mutatedAttrs) {
734
- return ` data-lwc-host-mutated="${[...mutatedAttrs].sort().join(' ')}"`;
806
+ // Shared Traps
807
+ // TODO: apply() is never called
808
+ /* istanbul ignore next */
809
+ apply(shadowTarget, thisArg, argArray) {
810
+ /* No op */
811
+ }
812
+ // TODO: construct() is never called
813
+ /* istanbul ignore next */
814
+ construct(shadowTarget, argArray, newTarget) {
815
+ /* No op */
816
+ }
817
+ get(shadowTarget, key) {
818
+ const { originalTarget, membrane: { valueObserved }, } = this;
819
+ const value = originalTarget[key];
820
+ valueObserved(originalTarget, key);
821
+ return this.wrapValue(value);
822
+ }
823
+ has(shadowTarget, key) {
824
+ const { originalTarget, membrane: { tagPropertyKey, valueObserved }, } = this;
825
+ valueObserved(originalTarget, key);
826
+ // since key is never going to be undefined, and tagPropertyKey might be undefined
827
+ // we can simply compare them as the second part of the condition.
828
+ return key in originalTarget || key === tagPropertyKey;
829
+ }
830
+ ownKeys(shadowTarget) {
831
+ const { originalTarget, membrane: { tagPropertyKey }, } = this;
832
+ // if the membrane tag key exists and it is not in the original target, we add it to the keys.
833
+ const keys = isUndefined(tagPropertyKey) || hasOwnProperty.call(originalTarget, tagPropertyKey)
834
+ ? []
835
+ : [tagPropertyKey];
836
+ // small perf optimization using push instead of concat to avoid creating an extra array
837
+ ArrayPush.apply(keys, getOwnPropertyNames(originalTarget));
838
+ ArrayPush.apply(keys, getOwnPropertySymbols(originalTarget));
839
+ return keys;
840
+ }
841
+ isExtensible(shadowTarget) {
842
+ const { originalTarget } = this;
843
+ // optimization to avoid attempting to lock down the shadowTarget multiple times
844
+ if (!isExtensible(shadowTarget)) {
845
+ return false; // was already locked down
735
846
  }
736
- else {
737
- return '';
847
+ if (!isExtensible(originalTarget)) {
848
+ this.lockShadowTarget(shadowTarget);
849
+ return false;
850
+ }
851
+ return true;
852
+ }
853
+ getPrototypeOf(shadowTarget) {
854
+ const { originalTarget } = this;
855
+ return getPrototypeOf(originalTarget);
856
+ }
857
+ getOwnPropertyDescriptor(shadowTarget, key) {
858
+ const { originalTarget, membrane: { valueObserved, tagPropertyKey }, } = this;
859
+ // keys looked up via getOwnPropertyDescriptor need to be reactive
860
+ valueObserved(originalTarget, key);
861
+ let desc = getOwnPropertyDescriptor(originalTarget, key);
862
+ if (isUndefined(desc)) {
863
+ if (key !== tagPropertyKey) {
864
+ return undefined;
865
+ }
866
+ // if the key is the membrane tag key, and is not in the original target,
867
+ // we produce a synthetic descriptor and install it on the shadow target
868
+ desc = { value: undefined, writable: false, configurable: false, enumerable: false };
869
+ ObjectDefineProperty(shadowTarget, tagPropertyKey, desc);
870
+ return desc;
871
+ }
872
+ if (desc.configurable === false) {
873
+ // updating the descriptor to non-configurable on the shadow
874
+ this.copyDescriptorIntoShadowTarget(shadowTarget, key);
738
875
  }
876
+ // Note: by accessing the descriptor, the key is marked as observed
877
+ // but access to the value, setter or getter (if available) cannot observe
878
+ // mutations, just like regular methods, in which case we just do nothing.
879
+ return this.wrapDescriptor(desc);
739
880
  }
740
881
  }
741
- _MutationTracker_enabledSet = new WeakMap(), _MutationTracker_mutationMap = new WeakMap();
742
- const mutationTracker = new MutationTracker();
743
882
 
744
- /*
745
- * Copyright (c) 2024, Salesforce, Inc.
746
- * All rights reserved.
747
- * SPDX-License-Identifier: MIT
748
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
749
- */
750
- /**
751
- * Filters out the following types of properties that should not be set.
752
- * - Properties that are not public.
753
- * - Properties that are not global.
754
- * - Properties that are global but are internally overridden.
755
- */
756
- function filterProperties(props, publicFields, privateFields) {
757
- const propsToAssign = create(null);
758
- const publicFieldSet = new Set(publicFields);
759
- const privateFieldSet = new Set(privateFields);
760
- keys(props).forEach((propName) => {
761
- const attrName = htmlPropertyToAttribute(propName);
762
- if (publicFieldSet.has(propName) ||
763
- ((isGlobalHtmlAttribute(attrName) || isAriaAttribute(attrName)) &&
764
- !privateFieldSet.has(propName))) {
765
- propsToAssign[propName] = props[propName];
766
- }
767
- });
768
- return propsToAssign;
769
- }
770
- /**
771
- * Descriptor for IDL attribute reflections that merely reflect the string, e.g. `title`.
772
- */
773
- const stringDescriptor = (attrName) => ({
774
- configurable: true,
775
- enumerable: true,
776
- get() {
777
- return this.getAttribute(attrName);
778
- },
779
- set(newValue) {
780
- const currentValue = this.getAttribute(attrName);
781
- const normalizedValue = String(newValue);
782
- if (normalizedValue !== currentValue) {
783
- this.setAttribute(attrName, normalizedValue);
883
+ const getterMap$1 = new WeakMap();
884
+ const setterMap$1 = new WeakMap();
885
+ const reverseGetterMap = new WeakMap();
886
+ const reverseSetterMap = new WeakMap();
887
+ class ReactiveProxyHandler extends BaseProxyHandler {
888
+ wrapValue(value) {
889
+ return this.membrane.getProxy(value);
890
+ }
891
+ wrapGetter(originalGet) {
892
+ const wrappedGetter = getterMap$1.get(originalGet);
893
+ if (!isUndefined(wrappedGetter)) {
894
+ return wrappedGetter;
784
895
  }
785
- },
786
- });
787
- /** Descriptor for a boolean that checks for `attr="true"` or `attr="false"`, e.g. `spellcheck` and `draggable`. */
788
- const explicitBooleanDescriptor = (attrName, defaultValue) => ({
789
- configurable: true,
790
- enumerable: true,
791
- get() {
792
- const value = this.getAttribute(attrName);
793
- if (value === null)
794
- return defaultValue;
795
- // spellcheck=false => false, everything else => true
796
- // draggable=true => true, everything else => false
797
- return value.toLowerCase() === String(defaultValue) ? defaultValue : !defaultValue;
798
- },
799
- set(newValue) {
800
- const currentValue = this.getAttribute(attrName);
801
- const normalizedValue = String(Boolean(newValue));
802
- if (normalizedValue !== currentValue) {
803
- this.setAttribute(attrName, normalizedValue);
896
+ const handler = this;
897
+ const get = function () {
898
+ // invoking the original getter with the original target
899
+ return handler.wrapValue(originalGet.call(unwrap(this)));
900
+ };
901
+ getterMap$1.set(originalGet, get);
902
+ reverseGetterMap.set(get, originalGet);
903
+ return get;
904
+ }
905
+ wrapSetter(originalSet) {
906
+ const wrappedSetter = setterMap$1.get(originalSet);
907
+ if (!isUndefined(wrappedSetter)) {
908
+ return wrappedSetter;
804
909
  }
805
- },
806
- });
807
- /**
808
- * Descriptor for a "true" boolean attribute that checks solely for presence, e.g. `hidden`.
809
- */
810
- const booleanAttributeDescriptor = (attrName) => ({
811
- configurable: true,
812
- enumerable: true,
813
- get() {
814
- return this.hasAttribute(attrName);
815
- },
816
- set(newValue) {
817
- const hasAttribute = this.hasAttribute(attrName);
818
- if (newValue) {
819
- if (!hasAttribute) {
820
- this.setAttribute(attrName, '');
821
- }
910
+ const set = function (v) {
911
+ // invoking the original setter with the original target
912
+ originalSet.call(unwrap(this), unwrap(v));
913
+ };
914
+ setterMap$1.set(originalSet, set);
915
+ reverseSetterMap.set(set, originalSet);
916
+ return set;
917
+ }
918
+ unwrapDescriptor(descriptor) {
919
+ if (hasOwnProperty.call(descriptor, 'value')) {
920
+ // dealing with a data descriptor
921
+ descriptor.value = unwrap(descriptor.value);
822
922
  }
823
923
  else {
824
- if (hasAttribute) {
825
- this.removeAttribute(attrName);
826
- }
827
- }
828
- },
829
- });
830
- /**
831
- * Descriptor for ARIA reflections, e.g. `ariaLabel` and `role`.
832
- */
833
- const ariaDescriptor = (attrName) => ({
834
- configurable: true,
835
- enumerable: true,
836
- get() {
837
- return this.getAttribute(attrName);
838
- },
839
- set(newValue) {
840
- const currentValue = this.getAttribute(attrName);
841
- if (newValue !== currentValue) {
842
- // TODO [#3284]: According to the spec, IDL nullable type values
843
- // (null and undefined) should remove the attribute; however, we
844
- // only do so in the case of null for historical reasons.
845
- if (isNull(newValue)) {
846
- this.removeAttribute(attrName);
924
+ const { set, get } = descriptor;
925
+ if (!isUndefined(get)) {
926
+ descriptor.get = this.unwrapGetter(get);
847
927
  }
848
- else {
849
- this.setAttribute(attrName, toString$1(newValue));
928
+ if (!isUndefined(set)) {
929
+ descriptor.set = this.unwrapSetter(set);
850
930
  }
851
931
  }
852
- },
853
- });
854
- const tabIndexDescriptor = () => ({
855
- configurable: true,
856
- enumerable: true,
857
- get() {
858
- const str = this.getAttribute('tabindex');
859
- const num = Number(str);
860
- return isFinite(num) ? Math.trunc(num) : -1;
861
- },
862
- set(newValue) {
863
- const currentValue = this.getAttribute('tabindex');
864
- const num = Number(newValue);
865
- const normalizedValue = isFinite(num) ? String(Math.trunc(num)) : '0';
866
- if (normalizedValue !== currentValue) {
867
- this.setAttribute('tabindex', toString$1(newValue));
868
- }
869
- },
870
- });
871
- const descriptors = {
872
- accessKey: stringDescriptor('accesskey'),
873
- dir: stringDescriptor('dir'),
874
- draggable: explicitBooleanDescriptor('draggable', true),
875
- hidden: booleanAttributeDescriptor('hidden'),
876
- id: stringDescriptor('id'),
877
- lang: stringDescriptor('lang'),
878
- spellcheck: explicitBooleanDescriptor('spellcheck', false),
879
- tabIndex: tabIndexDescriptor(),
880
- title: stringDescriptor('title'),
881
- };
882
- // Add descriptors for ARIA attributes
883
- for (const [attrName, propName] of entries(AriaAttrNameToPropNameMap)) {
884
- descriptors[propName] = ariaDescriptor(attrName);
885
- }
886
-
887
- /*
888
- * Copyright (c) 2024, salesforce.com, inc.
889
- * All rights reserved.
890
- * SPDX-License-Identifier: MIT
891
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
892
- */
893
- var _LightningElement_attrs, _LightningElement_classList;
894
- const SYMBOL__SET_INTERNALS = Symbol('set-internals');
895
- const SYMBOL__GENERATE_MARKUP = Symbol('generate-markup');
896
- const SYMBOL__DEFAULT_TEMPLATE = Symbol('default-template');
897
- class LightningElement {
898
- constructor(propsAvailableAtConstruction) {
899
- this.isConnected = false;
900
- this.className = '';
901
- _LightningElement_attrs.set(this, void 0);
902
- _LightningElement_classList.set(this, null);
903
- assign(this, propsAvailableAtConstruction);
904
- }
905
- [(_LightningElement_attrs = new WeakMap(), _LightningElement_classList = new WeakMap(), SYMBOL__SET_INTERNALS)](props, attrs) {
906
- __classPrivateFieldSet(this, _LightningElement_attrs, attrs, "f");
907
- assign(this, props);
908
- defineProperty(this, 'className', {
909
- get() {
910
- return props.class ?? '';
911
- },
912
- set(newVal) {
913
- props.class = newVal;
914
- attrs.class = newVal;
915
- mutationTracker.add(this, 'class');
916
- },
917
- });
932
+ return descriptor;
918
933
  }
919
- get classList() {
920
- if (__classPrivateFieldGet(this, _LightningElement_classList, "f")) {
921
- return __classPrivateFieldGet(this, _LightningElement_classList, "f");
934
+ unwrapGetter(redGet) {
935
+ const reverseGetter = reverseGetterMap.get(redGet);
936
+ if (!isUndefined(reverseGetter)) {
937
+ return reverseGetter;
922
938
  }
923
- return (__classPrivateFieldSet(this, _LightningElement_classList, new ClassList(this), "f"));
924
- }
925
- setAttribute(attrName, attrValue) {
926
- const normalizedName = StringToLowerCase.call(toString$1(attrName));
927
- const normalizedValue = String(attrValue);
928
- __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName] = normalizedValue;
929
- mutationTracker.add(this, normalizedName);
939
+ const handler = this;
940
+ const get = function () {
941
+ // invoking the red getter with the proxy of this
942
+ return unwrap(redGet.call(handler.wrapValue(this)));
943
+ };
944
+ getterMap$1.set(get, redGet);
945
+ reverseGetterMap.set(redGet, get);
946
+ return get;
930
947
  }
931
- getAttribute(attrName) {
932
- const normalizedName = StringToLowerCase.call(toString$1(attrName));
933
- if (hasOwnProperty$1.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName)) {
934
- return __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
948
+ unwrapSetter(redSet) {
949
+ const reverseSetter = reverseSetterMap.get(redSet);
950
+ if (!isUndefined(reverseSetter)) {
951
+ return reverseSetter;
935
952
  }
936
- return null;
937
- }
938
- hasAttribute(attrName) {
939
- const normalizedName = StringToLowerCase.call(toString$1(attrName));
940
- return hasOwnProperty$1.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName);
941
- }
942
- removeAttribute(attrName) {
943
- const normalizedName = StringToLowerCase.call(toString$1(attrName));
944
- delete __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
945
- // Track mutations for removal of non-existing attributes
946
- mutationTracker.add(this, normalizedName);
947
- }
948
- addEventListener(_type, _listener, _options) {
949
- // noop
950
- }
951
- removeEventListener(_type, _listener, _options) {
952
- // noop
953
- }
954
- // ----------------------------------------------------------- //
955
- // Props/methods explicitly not available in this environment //
956
- // Getters are named "get*" for parity with @lwc/engine-server //
957
- // ----------------------------------------------------------- //
958
- get children() {
959
- throw new TypeError('"getChildren" is not supported in this environment');
960
- }
961
- get childNodes() {
962
- throw new TypeError('"getChildNodes" is not supported in this environment');
963
- }
964
- get firstChild() {
965
- throw new TypeError('"getFirstChild" is not supported in this environment');
966
- }
967
- get firstElementChild() {
968
- throw new TypeError('"getFirstElementChild" is not supported in this environment');
969
- }
970
- get hostElement() {
971
- // Intentionally different to match @lwc/engine-*core*
972
- throw new TypeError('this.hostElement is not supported in this environment');
973
- }
974
- get lastChild() {
975
- throw new TypeError('"getLastChild" is not supported in this environment');
976
- }
977
- get lastElementChild() {
978
- throw new TypeError('"getLastElementChild" is not supported in this environment');
953
+ const handler = this;
954
+ const set = function (v) {
955
+ // invoking the red setter with the proxy of this
956
+ redSet.call(handler.wrapValue(this), handler.wrapValue(v));
957
+ };
958
+ setterMap$1.set(set, redSet);
959
+ reverseSetterMap.set(redSet, set);
960
+ return set;
979
961
  }
980
- get ownerDocument() {
981
- // Intentionally not "get*" to match @lwc/engine-server
982
- throw new TypeError('"ownerDocument" is not supported in this environment');
962
+ set(shadowTarget, key, value) {
963
+ const { originalTarget, membrane: { valueMutated }, } = this;
964
+ const oldValue = originalTarget[key];
965
+ if (oldValue !== value) {
966
+ originalTarget[key] = value;
967
+ valueMutated(originalTarget, key);
968
+ }
969
+ else if (key === 'length' && isArray(originalTarget)) {
970
+ // fix for issue #236: push will add the new index, and by the time length
971
+ // is updated, the internal length is already equal to the new length value
972
+ // therefore, the oldValue is equal to the value. This is the forking logic
973
+ // to support this use case.
974
+ valueMutated(originalTarget, key);
975
+ }
976
+ return true;
983
977
  }
984
- get style() {
985
- // Intentionally not "get*" to match @lwc/engine-server
986
- throw new TypeError('"style" is not supported in this environment');
978
+ deleteProperty(shadowTarget, key) {
979
+ const { originalTarget, membrane: { valueMutated }, } = this;
980
+ delete originalTarget[key];
981
+ valueMutated(originalTarget, key);
982
+ return true;
987
983
  }
988
- attachInternals() {
989
- throw new TypeError('"attachInternals" is not supported in this environment');
984
+ setPrototypeOf(shadowTarget, prototype) {
985
+ /* istanbul ignore else */
986
+ if (process.env.NODE_ENV !== 'production') {
987
+ throw new Error(`Invalid setPrototypeOf invocation for reactive proxy ${toString(this.originalTarget)}. Prototype of reactive objects cannot be changed.`);
988
+ }
990
989
  }
991
- dispatchEvent(_event) {
992
- throw new TypeError('"dispatchEvent" is not supported in this environment');
990
+ preventExtensions(shadowTarget) {
991
+ if (isExtensible(shadowTarget)) {
992
+ const { originalTarget } = this;
993
+ preventExtensions(originalTarget);
994
+ // if the originalTarget is a proxy itself, it might reject
995
+ // the preventExtension call, in which case we should not attempt to lock down
996
+ // the shadow target.
997
+ // TODO: It should not actually be possible to reach this `if` statement.
998
+ // If a proxy rejects extensions, then calling preventExtensions will throw an error:
999
+ // https://codepen.io/nolanlawson-the-selector/pen/QWMOjbY
1000
+ /* istanbul ignore if */
1001
+ if (isExtensible(originalTarget)) {
1002
+ return false;
1003
+ }
1004
+ this.lockShadowTarget(shadowTarget);
1005
+ }
1006
+ return true;
993
1007
  }
994
- getBoundingClientRect() {
995
- throw new TypeError('"getBoundingClientRect" is not supported in this environment');
1008
+ defineProperty(shadowTarget, key, descriptor) {
1009
+ const { originalTarget, membrane: { valueMutated, tagPropertyKey }, } = this;
1010
+ if (key === tagPropertyKey && !hasOwnProperty.call(originalTarget, key)) {
1011
+ // To avoid leaking the membrane tag property into the original target, we must
1012
+ // be sure that the original target doesn't have yet.
1013
+ // NOTE: we do not return false here because Object.freeze and equivalent operations
1014
+ // will attempt to set the descriptor to the same value, and expect no to throw. This
1015
+ // is an small compromise for the sake of not having to diff the descriptors.
1016
+ return true;
1017
+ }
1018
+ ObjectDefineProperty(originalTarget, key, this.unwrapDescriptor(descriptor));
1019
+ // intentionally testing if false since it could be undefined as well
1020
+ if (descriptor.configurable === false) {
1021
+ this.copyDescriptorIntoShadowTarget(shadowTarget, key);
1022
+ }
1023
+ valueMutated(originalTarget, key);
1024
+ return true;
996
1025
  }
997
- getElementsByClassName(_classNames) {
998
- throw new TypeError('"getElementsByClassName" is not supported in this environment');
1026
+ }
1027
+
1028
+ const getterMap = new WeakMap();
1029
+ const setterMap = new WeakMap();
1030
+ class ReadOnlyHandler extends BaseProxyHandler {
1031
+ wrapValue(value) {
1032
+ return this.membrane.getReadOnlyProxy(value);
999
1033
  }
1000
- getElementsByTagName(_qualifiedName) {
1001
- throw new TypeError('"getElementsByTagName" is not supported in this environment');
1034
+ wrapGetter(originalGet) {
1035
+ const wrappedGetter = getterMap.get(originalGet);
1036
+ if (!isUndefined(wrappedGetter)) {
1037
+ return wrappedGetter;
1038
+ }
1039
+ const handler = this;
1040
+ const get = function () {
1041
+ // invoking the original getter with the original target
1042
+ return handler.wrapValue(originalGet.call(unwrap(this)));
1043
+ };
1044
+ getterMap.set(originalGet, get);
1045
+ return get;
1002
1046
  }
1003
- querySelector(_selectors) {
1004
- throw new TypeError('"querySelector" is not supported in this environment');
1047
+ wrapSetter(originalSet) {
1048
+ const wrappedSetter = setterMap.get(originalSet);
1049
+ if (!isUndefined(wrappedSetter)) {
1050
+ return wrappedSetter;
1051
+ }
1052
+ const handler = this;
1053
+ const set = function (v) {
1054
+ /* istanbul ignore else */
1055
+ if (process.env.NODE_ENV !== 'production') {
1056
+ const { originalTarget } = handler;
1057
+ throw new Error(`Invalid mutation: Cannot invoke a setter on "${originalTarget}". "${originalTarget}" is read-only.`);
1058
+ }
1059
+ };
1060
+ setterMap.set(originalSet, set);
1061
+ return set;
1005
1062
  }
1006
- querySelectorAll(_selectors) {
1007
- throw new TypeError('"querySelectorAll" is not supported in this environment');
1063
+ set(shadowTarget, key, value) {
1064
+ /* istanbul ignore else */
1065
+ if (process.env.NODE_ENV !== 'production') {
1066
+ const { originalTarget } = this;
1067
+ const msg = isArray(originalTarget)
1068
+ ? `Invalid mutation: Cannot mutate array at index ${key.toString()}. Array is read-only.`
1069
+ : `Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`;
1070
+ throw new Error(msg);
1071
+ }
1072
+ /* istanbul ignore next */
1073
+ return false;
1008
1074
  }
1009
- getAttributeNS(_namespace, _localName) {
1010
- throw new Error('Method "getAttributeNS" not implemented.');
1075
+ deleteProperty(shadowTarget, key) {
1076
+ /* istanbul ignore else */
1077
+ if (process.env.NODE_ENV !== 'production') {
1078
+ const { originalTarget } = this;
1079
+ throw new Error(`Invalid mutation: Cannot delete "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1080
+ }
1081
+ /* istanbul ignore next */
1082
+ return false;
1011
1083
  }
1012
- hasAttributeNS(_namespace, _localName) {
1013
- throw new Error('Method "hasAttributeNS" not implemented.');
1084
+ setPrototypeOf(shadowTarget, prototype) {
1085
+ /* istanbul ignore else */
1086
+ if (process.env.NODE_ENV !== 'production') {
1087
+ const { originalTarget } = this;
1088
+ throw new Error(`Invalid prototype mutation: Cannot set prototype on "${originalTarget}". "${originalTarget}" prototype is read-only.`);
1089
+ }
1014
1090
  }
1015
- removeAttributeNS(_namespace, _localName) {
1016
- throw new Error('Method "removeAttributeNS" not implemented.');
1091
+ preventExtensions(shadowTarget) {
1092
+ /* istanbul ignore else */
1093
+ if (process.env.NODE_ENV !== 'production') {
1094
+ const { originalTarget } = this;
1095
+ throw new Error(`Invalid mutation: Cannot preventExtensions on ${originalTarget}". "${originalTarget} is read-only.`);
1096
+ }
1097
+ /* istanbul ignore next */
1098
+ return false;
1017
1099
  }
1018
- setAttributeNS(_namespace, _qualifiedName, _value) {
1019
- throw new Error('Method "setAttributeNS" not implemented.');
1100
+ defineProperty(shadowTarget, key, descriptor) {
1101
+ /* istanbul ignore else */
1102
+ if (process.env.NODE_ENV !== 'production') {
1103
+ const { originalTarget } = this;
1104
+ throw new Error(`Invalid mutation: Cannot defineProperty "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1105
+ }
1106
+ /* istanbul ignore next */
1107
+ return false;
1020
1108
  }
1021
1109
  }
1022
- defineProperties(LightningElement.prototype, descriptors);
1023
1110
 
1024
- /*
1025
- * Copyright (c) 2024, salesforce.com, inc.
1026
- * All rights reserved.
1027
- * SPDX-License-Identifier: MIT
1028
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1029
- */
1030
- const escapeAttrVal = (attrValue) => attrValue.replaceAll('&', '&amp;').replaceAll('"', '&quot;');
1031
- function renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken) {
1032
- // The scopeToken is e.g. `lwc-xyz123` which is the token our parent gives us.
1033
- // The hostScopeToken is e.g. `lwc-abc456-host` which is the token for our own component.
1034
- // It's possible to have both, one, the other, or neither.
1035
- const combinedScopeToken = scopeToken && hostScopeToken
1036
- ? `${scopeToken} ${hostScopeToken}`
1037
- : scopeToken || hostScopeToken || '';
1038
- let result = '';
1039
- let hasClassAttribute = false;
1040
- for (const attrName of getOwnPropertyNames$1(attrs)) {
1041
- let attrValue = attrs[attrName];
1042
- if (isNull(attrValue) || isUndefined$1(attrValue)) {
1043
- attrValue = '';
1111
+ function extract(objectOrArray) {
1112
+ if (isArray(objectOrArray)) {
1113
+ return objectOrArray.map((item) => {
1114
+ const original = unwrap(item);
1115
+ if (original !== item) {
1116
+ return extract(original);
1117
+ }
1118
+ return item;
1119
+ });
1120
+ }
1121
+ const obj = ObjectCreate(getPrototypeOf(objectOrArray));
1122
+ const names = getOwnPropertyNames(objectOrArray);
1123
+ return ArrayConcat.call(names, getOwnPropertySymbols(objectOrArray)).reduce((seed, key) => {
1124
+ const item = objectOrArray[key];
1125
+ const original = unwrap(item);
1126
+ if (original !== item) {
1127
+ seed[key] = extract(original);
1044
1128
  }
1045
- else if (!isString(attrValue)) {
1046
- attrValue = String(attrValue);
1129
+ else {
1130
+ seed[key] = item;
1047
1131
  }
1048
- if (combinedScopeToken && attrName === 'class') {
1049
- attrValue += ' ' + combinedScopeToken;
1050
- hasClassAttribute = true;
1132
+ return seed;
1133
+ }, obj);
1134
+ }
1135
+ const formatter = {
1136
+ header: (plainOrProxy) => {
1137
+ const originalTarget = unwrap(plainOrProxy);
1138
+ // if originalTarget is falsy or not unwrappable, exit
1139
+ if (!originalTarget || originalTarget === plainOrProxy) {
1140
+ return null;
1051
1141
  }
1052
- result += attrValue === '' ? ` ${attrName}` : ` ${attrName}="${escapeAttrVal(attrValue)}"`;
1142
+ const obj = extract(plainOrProxy);
1143
+ return ['object', { object: obj }];
1144
+ },
1145
+ hasBody: () => {
1146
+ return false;
1147
+ },
1148
+ body: () => {
1149
+ return null;
1150
+ },
1151
+ };
1152
+ // Inspired from paulmillr/es6-shim
1153
+ // https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L176-L185
1154
+ /* istanbul ignore next */
1155
+ function getGlobal() {
1156
+ // the only reliable means to get the global object is `Function('return this')()`
1157
+ // However, this causes CSP violations in Chrome apps.
1158
+ if (typeof globalThis !== 'undefined') {
1159
+ return globalThis;
1053
1160
  }
1054
- // If we didn't render any `class` attribute, render one for the scope token(s)
1055
- if (!hasClassAttribute && combinedScopeToken) {
1056
- result += ` class="${combinedScopeToken}"`;
1161
+ if (typeof self !== 'undefined') {
1162
+ return self;
1057
1163
  }
1058
- // For the host scope token only, we encode a special attribute for hydration
1059
- if (hostScopeToken) {
1060
- result += ` data-lwc-host-scope-token="${hostScopeToken}"`;
1164
+ if (typeof window !== 'undefined') {
1165
+ return window;
1061
1166
  }
1062
- result += mutationTracker.renderMutatedAttrs(instance);
1063
- return result;
1167
+ if (typeof global !== 'undefined') {
1168
+ return global;
1169
+ }
1170
+ // Gracefully degrade if not able to locate the global object
1171
+ return {};
1064
1172
  }
1065
- function* renderAttrs(instance, attrs, hostScopeToken, scopeToken) {
1066
- yield renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken);
1173
+ function init() {
1174
+ /* istanbul ignore if */
1175
+ if (process.env.NODE_ENV === 'production') {
1176
+ // this method should never leak to prod
1177
+ throw new ReferenceError();
1178
+ }
1179
+ const global = getGlobal();
1180
+ // Custom Formatter for Dev Tools. To enable this, open Chrome Dev Tools
1181
+ // - Go to Settings,
1182
+ // - Under console, select "Enable custom formatters"
1183
+ // For more information, https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview
1184
+ const devtoolsFormatters = global.devtoolsFormatters || [];
1185
+ ArrayPush.call(devtoolsFormatters, formatter);
1186
+ global.devtoolsFormatters = devtoolsFormatters;
1067
1187
  }
1068
- function renderAttrsNoYield(emit, instance, attrs, hostScopeToken, scopeToken) {
1069
- emit(renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken));
1188
+
1189
+ /* istanbul ignore else */
1190
+ if (process.env.NODE_ENV !== 'production') {
1191
+ init();
1070
1192
  }
1071
- function* fallbackTmpl(_props, _attrs, _slotted, Cmp, _instance) {
1072
- if (Cmp.renderMode !== 'light') {
1073
- yield '<template shadowrootmode="open"></template>';
1193
+ function defaultValueIsObservable(value) {
1194
+ // intentionally checking for null
1195
+ if (value === null) {
1196
+ return false;
1074
1197
  }
1075
- }
1076
- function fallbackTmplNoYield(emit, _props, _attrs, _slotted, Cmp, _instance) {
1077
- if (Cmp.renderMode !== 'light') {
1078
- emit('<template shadowrootmode="open"></template>');
1198
+ // treat all non-object types, including undefined, as non-observable values
1199
+ if (typeof value !== 'object') {
1200
+ return false;
1201
+ }
1202
+ if (isArray(value)) {
1203
+ return true;
1079
1204
  }
1205
+ const proto = getPrototypeOf(value);
1206
+ return proto === ObjectDotPrototype || proto === null || getPrototypeOf(proto) === null;
1080
1207
  }
1081
- async function serverSideRenderComponent(tagName, Component, props = {}, mode = DEFAULT_SSR_MODE) {
1082
- if (typeof tagName !== 'string') {
1083
- throw new Error(`tagName must be a string, found: ${tagName}`);
1208
+ const defaultValueObserved = (obj, key) => {
1209
+ /* do nothing */
1210
+ };
1211
+ const defaultValueMutated = (obj, key) => {
1212
+ /* do nothing */
1213
+ };
1214
+ function createShadowTarget(value) {
1215
+ return isArray(value) ? [] : {};
1216
+ }
1217
+ class ObservableMembrane {
1218
+ constructor(options = {}) {
1219
+ this.readOnlyObjectGraph = new WeakMap();
1220
+ this.reactiveObjectGraph = new WeakMap();
1221
+ const { valueMutated, valueObserved, valueIsObservable, tagPropertyKey } = options;
1222
+ this.valueMutated = isFunction(valueMutated) ? valueMutated : defaultValueMutated;
1223
+ this.valueObserved = isFunction(valueObserved) ? valueObserved : defaultValueObserved;
1224
+ this.valueIsObservable = isFunction(valueIsObservable)
1225
+ ? valueIsObservable
1226
+ : defaultValueIsObservable;
1227
+ this.tagPropertyKey = tagPropertyKey;
1084
1228
  }
1085
- // TODO [#4726]: remove `generateMarkup` export
1086
- const generateMarkup = SYMBOL__GENERATE_MARKUP in Component ? Component[SYMBOL__GENERATE_MARKUP] : Component;
1087
- let markup = '';
1088
- const emit = (segment) => {
1089
- markup += segment;
1090
- };
1091
- if (mode === 'asyncYield') {
1092
- for await (const segment of generateMarkup(tagName, props, null, null)) {
1093
- markup += segment;
1229
+ getProxy(value) {
1230
+ const unwrappedValue = unwrap(value);
1231
+ if (this.valueIsObservable(unwrappedValue)) {
1232
+ // When trying to extract the writable version of a readonly we return the readonly.
1233
+ if (this.readOnlyObjectGraph.get(unwrappedValue) === value) {
1234
+ return value;
1235
+ }
1236
+ return this.getReactiveHandler(unwrappedValue);
1094
1237
  }
1238
+ return unwrappedValue;
1095
1239
  }
1096
- else if (mode === 'async') {
1097
- await generateMarkup(emit, tagName, props, null, null);
1240
+ getReadOnlyProxy(value) {
1241
+ value = unwrap(value);
1242
+ if (this.valueIsObservable(value)) {
1243
+ return this.getReadOnlyHandler(value);
1244
+ }
1245
+ return value;
1098
1246
  }
1099
- else if (mode === 'sync') {
1100
- generateMarkup(emit, tagName, props, null, null);
1247
+ unwrapProxy(p) {
1248
+ return unwrap(p);
1101
1249
  }
1102
- else {
1103
- throw new Error(`Invalid mode: ${mode}`);
1250
+ getReactiveHandler(value) {
1251
+ let proxy = this.reactiveObjectGraph.get(value);
1252
+ if (isUndefined(proxy)) {
1253
+ // caching the proxy after the first time it is accessed
1254
+ const handler = new ReactiveProxyHandler(this, value);
1255
+ proxy = new Proxy(createShadowTarget(value), handler);
1256
+ registerProxy(proxy, value);
1257
+ this.reactiveObjectGraph.set(value, proxy);
1258
+ }
1259
+ return proxy;
1104
1260
  }
1105
- return markup;
1106
- }
1107
-
1108
- /*
1109
- * Copyright (c) 2024, Salesforce, Inc.
1110
- * All rights reserved.
1111
- * SPDX-License-Identifier: MIT
1112
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1113
- */
1114
- /**
1115
- * Per the HTML spec on restrictions for "raw text elements" like `<style>`:
1116
- *
1117
- * > The text in raw text and escapable raw text elements must not contain any occurrences of the string
1118
- * > "</" (U+003C LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that case-insensitively match the tag name of
1119
- * > the element followed by one of:
1120
- * > - U+0009 CHARACTER TABULATION (tab)
1121
- * > - U+000A LINE FEED (LF)
1122
- * > - U+000C FORM FEED (FF)
1123
- * > - U+000D CARRIAGE RETURN (CR)
1124
- * > - U+0020 SPACE
1125
- * > - U+003E GREATER-THAN SIGN (>), or
1126
- * > - U+002F SOLIDUS (/)
1127
- * @see https://html.spec.whatwg.org/multipage/syntax.html#cdata-rcdata-restrictions
1128
- */
1129
- const INVALID_STYLE_CONTENT = /<\/style[\t\n\f\r >/]/i;
1130
- /**
1131
- * The text content inside `<style>` is a special case. It is _only_ rendered by the LWC engine itself; `<style>` tags
1132
- * are disallowed inside of HTML templates.
1133
- *
1134
- * The `<style>` tag is unusual in how it's defined in HTML. Like `<script>`, it is considered a "raw text element,"
1135
- * which means that it is parsed as raw text, but certain character sequences are disallowed, namely to avoid XSS
1136
- * attacks like `</style><script>alert("pwned")</script>`.
1137
- *
1138
- * This also means that we cannot use "normal" HTML escaping inside `<style>` tags, e.g. we cannot use `&lt;`,
1139
- * `&gt;`, etc., because these are treated as-is by the HTML parser.
1140
- *
1141
- *
1142
- * @param contents CSS source to validate
1143
- * @throws Throws if the contents provided are not valid.
1144
- * @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
1145
- * @see https://github.com/salesforce/lwc/issues/3439
1146
- * @example
1147
- * validateStyleTextContents('div { color: red }') // Ok
1148
- * validateStyleTextContents('</style><script>alert("pwned")</script>') // Throws
1149
- */
1150
- function validateStyleTextContents(contents) {
1151
- if (INVALID_STYLE_CONTENT.test(contents)) {
1152
- throw new Error('CSS contains unsafe characters and cannot be serialized inside a style element');
1261
+ getReadOnlyHandler(value) {
1262
+ let proxy = this.readOnlyObjectGraph.get(value);
1263
+ if (isUndefined(proxy)) {
1264
+ // caching the proxy after the first time it is accessed
1265
+ const handler = new ReadOnlyHandler(this, value);
1266
+ proxy = new Proxy(createShadowTarget(value), handler);
1267
+ registerProxy(proxy, value);
1268
+ this.readOnlyObjectGraph.set(value, proxy);
1269
+ }
1270
+ return proxy;
1153
1271
  }
1154
1272
  }
1273
+ /** version: 2.0.0 */
1155
1274
 
1156
1275
  /*
1157
1276
  * Copyright (c) 2024, Salesforce, Inc.
@@ -1159,611 +1278,522 @@ function validateStyleTextContents(contents) {
1159
1278
  * SPDX-License-Identifier: MIT
1160
1279
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1161
1280
  */
1162
- function hasScopedStaticStylesheets(Component) {
1163
- const { stylesheets } = Component;
1164
- if (stylesheets) {
1165
- return flattenStylesheets(stylesheets).some((stylesheet) => stylesheet.$scoped$);
1166
- }
1167
- return false;
1168
- }
1169
- function renderStylesheets(stylesheets, scopeToken, Component, hasScopedTemplateStyles) {
1170
- const hasAnyScopedStyles = hasScopedTemplateStyles || hasScopedStaticStylesheets(Component);
1171
- let result = '';
1172
- const truthyStylesheets = stylesheets.filter(Boolean);
1173
- for (const stylesheet of flattenStylesheets(truthyStylesheets)) {
1174
- // TODO [#2869]: `<style>`s should not have scope token classes
1175
- result += `<style${hasAnyScopedStyles ? ` class="${scopeToken}"` : ''} type="text/css">`;
1176
- const token = stylesheet.$scoped$ ? scopeToken : undefined;
1177
- const useActualHostSelector = !stylesheet.$scoped$ || Component.renderMode !== 'light';
1178
- const useNativeDirPseudoclass = true;
1179
- const styleContents = stylesheet(token, useActualHostSelector, useNativeDirPseudoclass);
1180
- validateStyleTextContents(styleContents);
1181
- result += styleContents + '</style>';
1182
- }
1183
- return result;
1281
+ const reactiveMembrane = new ObservableMembrane();
1282
+ // Modeled after `getReadOnlyProxy` in `membrane.ts` in `engine-core`
1283
+ // Return a proxy over the given object so that access is immutable
1284
+ // https://github.com/salesforce/lwc/blob/e9db491/packages/%40lwc/engine-core/src/framework/membrane.ts#L29-L33
1285
+ function getReadOnlyProxy(value) {
1286
+ return reactiveMembrane.getReadOnlyProxy(value);
1184
1287
  }
1185
1288
 
1289
+ /******************************************************************************
1290
+ Copyright (c) Microsoft Corporation.
1291
+
1292
+ Permission to use, copy, modify, and/or distribute this software for any
1293
+ purpose with or without fee is hereby granted.
1294
+
1295
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1296
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1297
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1298
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1299
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1300
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1301
+ PERFORMANCE OF THIS SOFTWARE.
1302
+ ***************************************************************************** */
1303
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
1304
+
1305
+
1306
+ function __classPrivateFieldGet(receiver, state, kind, f) {
1307
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1308
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1309
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1310
+ }
1311
+
1312
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
1313
+ if (kind === "m") throw new TypeError("Private method is not writable");
1314
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1315
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
1316
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1317
+ }
1318
+
1319
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1320
+ var e = new Error(message);
1321
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1322
+ };
1323
+
1186
1324
  /*
1187
- * Copyright (c) 2024, salesforce.com, inc.
1325
+ * Copyright (c) 2024, Salesforce, Inc.
1188
1326
  * All rights reserved.
1189
1327
  * SPDX-License-Identifier: MIT
1190
1328
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1191
1329
  */
1192
- /**
1193
- * Converts an iterable into one that emits the object used by the [`iterator` directive](
1194
- * https://lwc.dev/guide/html_templates#iterator).
1195
- */
1196
- function* toIteratorDirective(iterable) {
1197
- if (iterable === undefined || iterable === null)
1198
- return;
1199
- if (!iterable[Symbol.iterator]) {
1200
- throw new Error(
1201
- // Mimic error message from "[i]terable node" in engine-core's api.ts
1202
- `Invalid template iteration for value \`${iterable}\`. It must be an array-like object.`);
1330
+ var _MutationTracker_enabledSet, _MutationTracker_mutationMap;
1331
+ class MutationTracker {
1332
+ constructor() {
1333
+ _MutationTracker_enabledSet.set(this, new WeakSet());
1334
+ _MutationTracker_mutationMap.set(this, new WeakMap());
1203
1335
  }
1204
- const iterator = iterable[Symbol.iterator]();
1205
- let next = iterator.next();
1206
- let index = 0;
1207
- let { value, done: last = false } = next;
1208
- while (last === false) {
1209
- // using a look-back approach because we need to know if the element is the last
1210
- next = iterator.next();
1211
- last = next.done ?? false;
1212
- yield {
1213
- value,
1214
- index,
1215
- first: index === 0,
1216
- last,
1217
- };
1218
- index += 1;
1219
- value = next.value;
1336
+ add(instance, attrName) {
1337
+ if (__classPrivateFieldGet(this, _MutationTracker_enabledSet, "f").has(instance)) {
1338
+ let mutatedAttrs = __classPrivateFieldGet(this, _MutationTracker_mutationMap, "f").get(instance);
1339
+ if (!mutatedAttrs) {
1340
+ mutatedAttrs = new Set();
1341
+ __classPrivateFieldGet(this, _MutationTracker_mutationMap, "f").set(instance, mutatedAttrs);
1342
+ }
1343
+ mutatedAttrs.add(attrName.toLowerCase());
1344
+ }
1220
1345
  }
1221
- }
1222
-
1223
- /**
1224
- * Copyright (C) 2017 salesforce.com, inc.
1225
- */
1226
- const { isArray } = Array;
1227
- const { prototype: ObjectDotPrototype, getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, } = Object;
1228
- const { push: ArrayPush, concat: ArrayConcat } = Array.prototype;
1229
- const OtS = {}.toString;
1230
- function toString(obj) {
1231
- if (obj && obj.toString) {
1232
- return obj.toString();
1346
+ enable(instance) {
1347
+ __classPrivateFieldGet(this, _MutationTracker_enabledSet, "f").add(instance);
1233
1348
  }
1234
- else if (typeof obj === 'object') {
1235
- return OtS.call(obj);
1349
+ disable(instance) {
1350
+ __classPrivateFieldGet(this, _MutationTracker_enabledSet, "f").delete(instance);
1236
1351
  }
1237
- else {
1238
- return obj + '';
1352
+ renderMutatedAttrs(instance) {
1353
+ const mutatedAttrs = __classPrivateFieldGet(this, _MutationTracker_mutationMap, "f").get(instance);
1354
+ if (mutatedAttrs) {
1355
+ return ` data-lwc-host-mutated="${[...mutatedAttrs].sort().join(' ')}"`;
1356
+ }
1357
+ else {
1358
+ return '';
1359
+ }
1239
1360
  }
1240
1361
  }
1241
- function isUndefined(obj) {
1242
- return obj === undefined;
1243
- }
1244
- function isFunction(obj) {
1245
- return typeof obj === 'function';
1246
- }
1247
- const proxyToValueMap = new WeakMap();
1248
- function registerProxy(proxy, value) {
1249
- proxyToValueMap.set(proxy, value);
1250
- }
1251
- const unwrap = (replicaOrAny) => proxyToValueMap.get(replicaOrAny) || replicaOrAny;
1362
+ _MutationTracker_enabledSet = new WeakMap(), _MutationTracker_mutationMap = new WeakMap();
1363
+ const mutationTracker = new MutationTracker();
1252
1364
 
1253
- class BaseProxyHandler {
1254
- constructor(membrane, value) {
1255
- this.originalTarget = value;
1256
- this.membrane = membrane;
1257
- }
1258
- // Shared utility methods
1259
- wrapDescriptor(descriptor) {
1260
- if (hasOwnProperty.call(descriptor, 'value')) {
1261
- descriptor.value = this.wrapValue(descriptor.value);
1365
+ /*
1366
+ * Copyright (c) 2024, Salesforce, Inc.
1367
+ * All rights reserved.
1368
+ * SPDX-License-Identifier: MIT
1369
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1370
+ */
1371
+ /**
1372
+ * Filters out the following types of properties that should not be set.
1373
+ * - Properties that are not public.
1374
+ * - Properties that are not global.
1375
+ * - Properties that are global but are internally overridden.
1376
+ */
1377
+ function filterProperties(props, publicFields, privateFields) {
1378
+ const propsToAssign = create(null);
1379
+ const publicFieldSet = new Set(publicFields);
1380
+ const privateFieldSet = new Set(privateFields);
1381
+ keys(props).forEach((propName) => {
1382
+ const attrName = htmlPropertyToAttribute(propName);
1383
+ if (publicFieldSet.has(propName) ||
1384
+ ((isGlobalHtmlAttribute(attrName) || isAriaAttribute(attrName)) &&
1385
+ !privateFieldSet.has(propName))) {
1386
+ propsToAssign[propName] = props[propName];
1387
+ }
1388
+ });
1389
+ return propsToAssign;
1390
+ }
1391
+ /**
1392
+ * Descriptor for IDL attribute reflections that merely reflect the string, e.g. `title`.
1393
+ */
1394
+ const stringDescriptor = (attrName) => ({
1395
+ configurable: true,
1396
+ enumerable: true,
1397
+ get() {
1398
+ return this.getAttribute(attrName);
1399
+ },
1400
+ set(newValue) {
1401
+ const currentValue = this.getAttribute(attrName);
1402
+ const normalizedValue = String(newValue);
1403
+ if (normalizedValue !== currentValue) {
1404
+ this.setAttribute(attrName, normalizedValue);
1405
+ }
1406
+ },
1407
+ });
1408
+ /** Descriptor for a boolean that checks for `attr="true"` or `attr="false"`, e.g. `spellcheck` and `draggable`. */
1409
+ const explicitBooleanDescriptor = (attrName, defaultValue) => ({
1410
+ configurable: true,
1411
+ enumerable: true,
1412
+ get() {
1413
+ const value = this.getAttribute(attrName);
1414
+ if (value === null)
1415
+ return defaultValue;
1416
+ // spellcheck=false => false, everything else => true
1417
+ // draggable=true => true, everything else => false
1418
+ return value.toLowerCase() === String(defaultValue) ? defaultValue : !defaultValue;
1419
+ },
1420
+ set(newValue) {
1421
+ const currentValue = this.getAttribute(attrName);
1422
+ const normalizedValue = String(Boolean(newValue));
1423
+ if (normalizedValue !== currentValue) {
1424
+ this.setAttribute(attrName, normalizedValue);
1425
+ }
1426
+ },
1427
+ });
1428
+ /**
1429
+ * Descriptor for a "true" boolean attribute that checks solely for presence, e.g. `hidden`.
1430
+ */
1431
+ const booleanAttributeDescriptor = (attrName) => ({
1432
+ configurable: true,
1433
+ enumerable: true,
1434
+ get() {
1435
+ return this.hasAttribute(attrName);
1436
+ },
1437
+ set(newValue) {
1438
+ const hasAttribute = this.hasAttribute(attrName);
1439
+ if (newValue) {
1440
+ if (!hasAttribute) {
1441
+ this.setAttribute(attrName, '');
1442
+ }
1262
1443
  }
1263
1444
  else {
1264
- const { set: originalSet, get: originalGet } = descriptor;
1265
- if (!isUndefined(originalGet)) {
1266
- descriptor.get = this.wrapGetter(originalGet);
1445
+ if (hasAttribute) {
1446
+ this.removeAttribute(attrName);
1267
1447
  }
1268
- if (!isUndefined(originalSet)) {
1269
- descriptor.set = this.wrapSetter(originalSet);
1448
+ }
1449
+ },
1450
+ });
1451
+ /**
1452
+ * Descriptor for ARIA reflections, e.g. `ariaLabel` and `role`.
1453
+ */
1454
+ const ariaDescriptor = (attrName) => ({
1455
+ configurable: true,
1456
+ enumerable: true,
1457
+ get() {
1458
+ return this.getAttribute(attrName);
1459
+ },
1460
+ set(newValue) {
1461
+ const currentValue = this.getAttribute(attrName);
1462
+ if (newValue !== currentValue) {
1463
+ // TODO [#3284]: According to the spec, IDL nullable type values
1464
+ // (null and undefined) should remove the attribute; however, we
1465
+ // only do so in the case of null for historical reasons.
1466
+ if (isNull(newValue)) {
1467
+ this.removeAttribute(attrName);
1468
+ }
1469
+ else {
1470
+ this.setAttribute(attrName, toString$1(newValue));
1270
1471
  }
1271
1472
  }
1272
- return descriptor;
1273
- }
1274
- copyDescriptorIntoShadowTarget(shadowTarget, key) {
1275
- const { originalTarget } = this;
1276
- // Note: a property might get defined multiple times in the shadowTarget
1277
- // but it will always be compatible with the previous descriptor
1278
- // to preserve the object invariants, which makes these lines safe.
1279
- const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key);
1280
- // TODO: it should be impossible for the originalDescriptor to ever be undefined, this `if` can be removed
1281
- /* istanbul ignore else */
1282
- if (!isUndefined(originalDescriptor)) {
1283
- const wrappedDesc = this.wrapDescriptor(originalDescriptor);
1284
- ObjectDefineProperty(shadowTarget, key, wrappedDesc);
1473
+ },
1474
+ });
1475
+ const tabIndexDescriptor = () => ({
1476
+ configurable: true,
1477
+ enumerable: true,
1478
+ get() {
1479
+ const str = this.getAttribute('tabindex');
1480
+ const num = Number(str);
1481
+ return isFinite(num) ? Math.trunc(num) : -1;
1482
+ },
1483
+ set(newValue) {
1484
+ const currentValue = this.getAttribute('tabindex');
1485
+ const num = Number(newValue);
1486
+ const normalizedValue = isFinite(num) ? String(Math.trunc(num)) : '0';
1487
+ if (normalizedValue !== currentValue) {
1488
+ this.setAttribute('tabindex', toString$1(newValue));
1285
1489
  }
1490
+ },
1491
+ });
1492
+ const descriptors = {
1493
+ accessKey: stringDescriptor('accesskey'),
1494
+ dir: stringDescriptor('dir'),
1495
+ draggable: explicitBooleanDescriptor('draggable', true),
1496
+ hidden: booleanAttributeDescriptor('hidden'),
1497
+ id: stringDescriptor('id'),
1498
+ lang: stringDescriptor('lang'),
1499
+ spellcheck: explicitBooleanDescriptor('spellcheck', false),
1500
+ tabIndex: tabIndexDescriptor(),
1501
+ title: stringDescriptor('title'),
1502
+ };
1503
+ // Add descriptors for ARIA attributes
1504
+ for (const [attrName, propName] of entries(AriaAttrNameToPropNameMap)) {
1505
+ descriptors[propName] = ariaDescriptor(attrName);
1506
+ }
1507
+
1508
+ /*
1509
+ * Copyright (c) 2024, salesforce.com, inc.
1510
+ * All rights reserved.
1511
+ * SPDX-License-Identifier: MIT
1512
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1513
+ */
1514
+ var _LightningElement_attrs, _LightningElement_classList;
1515
+ const SYMBOL__SET_INTERNALS = Symbol('set-internals');
1516
+ const SYMBOL__GENERATE_MARKUP = Symbol('generate-markup');
1517
+ const SYMBOL__DEFAULT_TEMPLATE = Symbol('default-template');
1518
+ class LightningElement {
1519
+ constructor(propsAvailableAtConstruction) {
1520
+ this.isConnected = false;
1521
+ this.className = '';
1522
+ _LightningElement_attrs.set(this, void 0);
1523
+ _LightningElement_classList.set(this, null);
1524
+ assign(this, propsAvailableAtConstruction);
1286
1525
  }
1287
- lockShadowTarget(shadowTarget) {
1288
- const { originalTarget } = this;
1289
- const targetKeys = ArrayConcat.call(getOwnPropertyNames(originalTarget), getOwnPropertySymbols(originalTarget));
1290
- targetKeys.forEach((key) => {
1291
- this.copyDescriptorIntoShadowTarget(shadowTarget, key);
1526
+ [(_LightningElement_attrs = new WeakMap(), _LightningElement_classList = new WeakMap(), SYMBOL__SET_INTERNALS)](props, attrs) {
1527
+ __classPrivateFieldSet(this, _LightningElement_attrs, attrs, "f");
1528
+ assign(this, props);
1529
+ defineProperty(this, 'className', {
1530
+ get() {
1531
+ return props.class ?? '';
1532
+ },
1533
+ set(newVal) {
1534
+ props.class = newVal;
1535
+ attrs.class = newVal;
1536
+ mutationTracker.add(this, 'class');
1537
+ },
1292
1538
  });
1293
- const { membrane: { tagPropertyKey }, } = this;
1294
- if (!isUndefined(tagPropertyKey) && !hasOwnProperty.call(shadowTarget, tagPropertyKey)) {
1295
- ObjectDefineProperty(shadowTarget, tagPropertyKey, ObjectCreate(null));
1296
- }
1297
- preventExtensions(shadowTarget);
1298
- }
1299
- // Shared Traps
1300
- // TODO: apply() is never called
1301
- /* istanbul ignore next */
1302
- apply(shadowTarget, thisArg, argArray) {
1303
- /* No op */
1304
- }
1305
- // TODO: construct() is never called
1306
- /* istanbul ignore next */
1307
- construct(shadowTarget, argArray, newTarget) {
1308
- /* No op */
1309
- }
1310
- get(shadowTarget, key) {
1311
- const { originalTarget, membrane: { valueObserved }, } = this;
1312
- const value = originalTarget[key];
1313
- valueObserved(originalTarget, key);
1314
- return this.wrapValue(value);
1315
- }
1316
- has(shadowTarget, key) {
1317
- const { originalTarget, membrane: { tagPropertyKey, valueObserved }, } = this;
1318
- valueObserved(originalTarget, key);
1319
- // since key is never going to be undefined, and tagPropertyKey might be undefined
1320
- // we can simply compare them as the second part of the condition.
1321
- return key in originalTarget || key === tagPropertyKey;
1322
- }
1323
- ownKeys(shadowTarget) {
1324
- const { originalTarget, membrane: { tagPropertyKey }, } = this;
1325
- // if the membrane tag key exists and it is not in the original target, we add it to the keys.
1326
- const keys = isUndefined(tagPropertyKey) || hasOwnProperty.call(originalTarget, tagPropertyKey)
1327
- ? []
1328
- : [tagPropertyKey];
1329
- // small perf optimization using push instead of concat to avoid creating an extra array
1330
- ArrayPush.apply(keys, getOwnPropertyNames(originalTarget));
1331
- ArrayPush.apply(keys, getOwnPropertySymbols(originalTarget));
1332
- return keys;
1333
1539
  }
1334
- isExtensible(shadowTarget) {
1335
- const { originalTarget } = this;
1336
- // optimization to avoid attempting to lock down the shadowTarget multiple times
1337
- if (!isExtensible(shadowTarget)) {
1338
- return false; // was already locked down
1339
- }
1340
- if (!isExtensible(originalTarget)) {
1341
- this.lockShadowTarget(shadowTarget);
1342
- return false;
1540
+ get classList() {
1541
+ if (__classPrivateFieldGet(this, _LightningElement_classList, "f")) {
1542
+ return __classPrivateFieldGet(this, _LightningElement_classList, "f");
1343
1543
  }
1344
- return true;
1544
+ return (__classPrivateFieldSet(this, _LightningElement_classList, new ClassList(this), "f"));
1345
1545
  }
1346
- getPrototypeOf(shadowTarget) {
1347
- const { originalTarget } = this;
1348
- return getPrototypeOf(originalTarget);
1546
+ setAttribute(attrName, attrValue) {
1547
+ const normalizedName = StringToLowerCase.call(toString$1(attrName));
1548
+ const normalizedValue = String(attrValue);
1549
+ __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName] = normalizedValue;
1550
+ mutationTracker.add(this, normalizedName);
1349
1551
  }
1350
- getOwnPropertyDescriptor(shadowTarget, key) {
1351
- const { originalTarget, membrane: { valueObserved, tagPropertyKey }, } = this;
1352
- // keys looked up via getOwnPropertyDescriptor need to be reactive
1353
- valueObserved(originalTarget, key);
1354
- let desc = getOwnPropertyDescriptor(originalTarget, key);
1355
- if (isUndefined(desc)) {
1356
- if (key !== tagPropertyKey) {
1357
- return undefined;
1358
- }
1359
- // if the key is the membrane tag key, and is not in the original target,
1360
- // we produce a synthetic descriptor and install it on the shadow target
1361
- desc = { value: undefined, writable: false, configurable: false, enumerable: false };
1362
- ObjectDefineProperty(shadowTarget, tagPropertyKey, desc);
1363
- return desc;
1364
- }
1365
- if (desc.configurable === false) {
1366
- // updating the descriptor to non-configurable on the shadow
1367
- this.copyDescriptorIntoShadowTarget(shadowTarget, key);
1552
+ getAttribute(attrName) {
1553
+ const normalizedName = StringToLowerCase.call(toString$1(attrName));
1554
+ if (hasOwnProperty$1.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName)) {
1555
+ return __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
1368
1556
  }
1369
- // Note: by accessing the descriptor, the key is marked as observed
1370
- // but access to the value, setter or getter (if available) cannot observe
1371
- // mutations, just like regular methods, in which case we just do nothing.
1372
- return this.wrapDescriptor(desc);
1557
+ return null;
1373
1558
  }
1374
- }
1375
-
1376
- const getterMap$1 = new WeakMap();
1377
- const setterMap$1 = new WeakMap();
1378
- const reverseGetterMap = new WeakMap();
1379
- const reverseSetterMap = new WeakMap();
1380
- class ReactiveProxyHandler extends BaseProxyHandler {
1381
- wrapValue(value) {
1382
- return this.membrane.getProxy(value);
1559
+ hasAttribute(attrName) {
1560
+ const normalizedName = StringToLowerCase.call(toString$1(attrName));
1561
+ return hasOwnProperty$1.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName);
1383
1562
  }
1384
- wrapGetter(originalGet) {
1385
- const wrappedGetter = getterMap$1.get(originalGet);
1386
- if (!isUndefined(wrappedGetter)) {
1387
- return wrappedGetter;
1388
- }
1389
- const handler = this;
1390
- const get = function () {
1391
- // invoking the original getter with the original target
1392
- return handler.wrapValue(originalGet.call(unwrap(this)));
1393
- };
1394
- getterMap$1.set(originalGet, get);
1395
- reverseGetterMap.set(get, originalGet);
1396
- return get;
1563
+ removeAttribute(attrName) {
1564
+ const normalizedName = StringToLowerCase.call(toString$1(attrName));
1565
+ delete __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
1566
+ // Track mutations for removal of non-existing attributes
1567
+ mutationTracker.add(this, normalizedName);
1397
1568
  }
1398
- wrapSetter(originalSet) {
1399
- const wrappedSetter = setterMap$1.get(originalSet);
1400
- if (!isUndefined(wrappedSetter)) {
1401
- return wrappedSetter;
1402
- }
1403
- const set = function (v) {
1404
- // invoking the original setter with the original target
1405
- originalSet.call(unwrap(this), unwrap(v));
1406
- };
1407
- setterMap$1.set(originalSet, set);
1408
- reverseSetterMap.set(set, originalSet);
1409
- return set;
1569
+ addEventListener(_type, _listener, _options) {
1570
+ // noop
1410
1571
  }
1411
- unwrapDescriptor(descriptor) {
1412
- if (hasOwnProperty.call(descriptor, 'value')) {
1413
- // dealing with a data descriptor
1414
- descriptor.value = unwrap(descriptor.value);
1415
- }
1416
- else {
1417
- const { set, get } = descriptor;
1418
- if (!isUndefined(get)) {
1419
- descriptor.get = this.unwrapGetter(get);
1420
- }
1421
- if (!isUndefined(set)) {
1422
- descriptor.set = this.unwrapSetter(set);
1423
- }
1424
- }
1425
- return descriptor;
1572
+ removeEventListener(_type, _listener, _options) {
1573
+ // noop
1426
1574
  }
1427
- unwrapGetter(redGet) {
1428
- const reverseGetter = reverseGetterMap.get(redGet);
1429
- if (!isUndefined(reverseGetter)) {
1430
- return reverseGetter;
1431
- }
1432
- const handler = this;
1433
- const get = function () {
1434
- // invoking the red getter with the proxy of this
1435
- return unwrap(redGet.call(handler.wrapValue(this)));
1436
- };
1437
- getterMap$1.set(get, redGet);
1438
- reverseGetterMap.set(redGet, get);
1439
- return get;
1575
+ // ----------------------------------------------------------- //
1576
+ // Props/methods explicitly not available in this environment //
1577
+ // Getters are named "get*" for parity with @lwc/engine-server //
1578
+ // ----------------------------------------------------------- //
1579
+ get children() {
1580
+ throw new TypeError('"getChildren" is not supported in this environment');
1581
+ }
1582
+ get childNodes() {
1583
+ throw new TypeError('"getChildNodes" is not supported in this environment');
1440
1584
  }
1441
- unwrapSetter(redSet) {
1442
- const reverseSetter = reverseSetterMap.get(redSet);
1443
- if (!isUndefined(reverseSetter)) {
1444
- return reverseSetter;
1445
- }
1446
- const handler = this;
1447
- const set = function (v) {
1448
- // invoking the red setter with the proxy of this
1449
- redSet.call(handler.wrapValue(this), handler.wrapValue(v));
1450
- };
1451
- setterMap$1.set(set, redSet);
1452
- reverseSetterMap.set(redSet, set);
1453
- return set;
1585
+ get firstChild() {
1586
+ throw new TypeError('"getFirstChild" is not supported in this environment');
1454
1587
  }
1455
- set(shadowTarget, key, value) {
1456
- const { originalTarget, membrane: { valueMutated }, } = this;
1457
- const oldValue = originalTarget[key];
1458
- if (oldValue !== value) {
1459
- originalTarget[key] = value;
1460
- valueMutated(originalTarget, key);
1461
- }
1462
- else if (key === 'length' && isArray(originalTarget)) {
1463
- // fix for issue #236: push will add the new index, and by the time length
1464
- // is updated, the internal length is already equal to the new length value
1465
- // therefore, the oldValue is equal to the value. This is the forking logic
1466
- // to support this use case.
1467
- valueMutated(originalTarget, key);
1468
- }
1469
- return true;
1588
+ get firstElementChild() {
1589
+ throw new TypeError('"getFirstElementChild" is not supported in this environment');
1470
1590
  }
1471
- deleteProperty(shadowTarget, key) {
1472
- const { originalTarget, membrane: { valueMutated }, } = this;
1473
- delete originalTarget[key];
1474
- valueMutated(originalTarget, key);
1475
- return true;
1591
+ get hostElement() {
1592
+ // Intentionally different to match @lwc/engine-*core*
1593
+ throw new TypeError('this.hostElement is not supported in this environment');
1476
1594
  }
1477
- setPrototypeOf(shadowTarget, prototype) {
1478
- /* istanbul ignore else */
1479
- if (process.env.NODE_ENV !== 'production') {
1480
- throw new Error(`Invalid setPrototypeOf invocation for reactive proxy ${toString(this.originalTarget)}. Prototype of reactive objects cannot be changed.`);
1481
- }
1595
+ get lastChild() {
1596
+ throw new TypeError('"getLastChild" is not supported in this environment');
1482
1597
  }
1483
- preventExtensions(shadowTarget) {
1484
- if (isExtensible(shadowTarget)) {
1485
- const { originalTarget } = this;
1486
- preventExtensions(originalTarget);
1487
- // if the originalTarget is a proxy itself, it might reject
1488
- // the preventExtension call, in which case we should not attempt to lock down
1489
- // the shadow target.
1490
- // TODO: It should not actually be possible to reach this `if` statement.
1491
- // If a proxy rejects extensions, then calling preventExtensions will throw an error:
1492
- // https://codepen.io/nolanlawson-the-selector/pen/QWMOjbY
1493
- /* istanbul ignore if */
1494
- if (isExtensible(originalTarget)) {
1495
- return false;
1496
- }
1497
- this.lockShadowTarget(shadowTarget);
1498
- }
1499
- return true;
1598
+ get lastElementChild() {
1599
+ throw new TypeError('"getLastElementChild" is not supported in this environment');
1500
1600
  }
1501
- defineProperty(shadowTarget, key, descriptor) {
1502
- const { originalTarget, membrane: { valueMutated, tagPropertyKey }, } = this;
1503
- if (key === tagPropertyKey && !hasOwnProperty.call(originalTarget, key)) {
1504
- // To avoid leaking the membrane tag property into the original target, we must
1505
- // be sure that the original target doesn't have yet.
1506
- // NOTE: we do not return false here because Object.freeze and equivalent operations
1507
- // will attempt to set the descriptor to the same value, and expect no to throw. This
1508
- // is an small compromise for the sake of not having to diff the descriptors.
1509
- return true;
1510
- }
1511
- ObjectDefineProperty(originalTarget, key, this.unwrapDescriptor(descriptor));
1512
- // intentionally testing if false since it could be undefined as well
1513
- if (descriptor.configurable === false) {
1514
- this.copyDescriptorIntoShadowTarget(shadowTarget, key);
1515
- }
1516
- valueMutated(originalTarget, key);
1517
- return true;
1601
+ get ownerDocument() {
1602
+ // Intentionally not "get*" to match @lwc/engine-server
1603
+ throw new TypeError('"ownerDocument" is not supported in this environment');
1518
1604
  }
1519
- }
1520
-
1521
- const getterMap = new WeakMap();
1522
- const setterMap = new WeakMap();
1523
- class ReadOnlyHandler extends BaseProxyHandler {
1524
- wrapValue(value) {
1525
- return this.membrane.getReadOnlyProxy(value);
1605
+ get style() {
1606
+ // Intentionally not "get*" to match @lwc/engine-server
1607
+ throw new TypeError('"style" is not supported in this environment');
1526
1608
  }
1527
- wrapGetter(originalGet) {
1528
- const wrappedGetter = getterMap.get(originalGet);
1529
- if (!isUndefined(wrappedGetter)) {
1530
- return wrappedGetter;
1531
- }
1532
- const handler = this;
1533
- const get = function () {
1534
- // invoking the original getter with the original target
1535
- return handler.wrapValue(originalGet.call(unwrap(this)));
1536
- };
1537
- getterMap.set(originalGet, get);
1538
- return get;
1609
+ attachInternals() {
1610
+ throw new TypeError('"attachInternals" is not supported in this environment');
1539
1611
  }
1540
- wrapSetter(originalSet) {
1541
- const wrappedSetter = setterMap.get(originalSet);
1542
- if (!isUndefined(wrappedSetter)) {
1543
- return wrappedSetter;
1544
- }
1545
- const handler = this;
1546
- const set = function (v) {
1547
- /* istanbul ignore else */
1548
- if (process.env.NODE_ENV !== 'production') {
1549
- const { originalTarget } = handler;
1550
- throw new Error(`Invalid mutation: Cannot invoke a setter on "${originalTarget}". "${originalTarget}" is read-only.`);
1551
- }
1552
- };
1553
- setterMap.set(originalSet, set);
1554
- return set;
1612
+ dispatchEvent(_event) {
1613
+ throw new TypeError('"dispatchEvent" is not supported in this environment');
1555
1614
  }
1556
- set(shadowTarget, key, value) {
1557
- /* istanbul ignore else */
1558
- if (process.env.NODE_ENV !== 'production') {
1559
- const { originalTarget } = this;
1560
- const msg = isArray(originalTarget)
1561
- ? `Invalid mutation: Cannot mutate array at index ${key.toString()}. Array is read-only.`
1562
- : `Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`;
1563
- throw new Error(msg);
1564
- }
1565
- /* istanbul ignore next */
1566
- return false;
1615
+ getBoundingClientRect() {
1616
+ throw new TypeError('"getBoundingClientRect" is not supported in this environment');
1567
1617
  }
1568
- deleteProperty(shadowTarget, key) {
1569
- /* istanbul ignore else */
1570
- if (process.env.NODE_ENV !== 'production') {
1571
- const { originalTarget } = this;
1572
- throw new Error(`Invalid mutation: Cannot delete "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1573
- }
1574
- /* istanbul ignore next */
1575
- return false;
1618
+ getElementsByClassName(_classNames) {
1619
+ throw new TypeError('"getElementsByClassName" is not supported in this environment');
1576
1620
  }
1577
- setPrototypeOf(shadowTarget, prototype) {
1578
- /* istanbul ignore else */
1579
- if (process.env.NODE_ENV !== 'production') {
1580
- const { originalTarget } = this;
1581
- throw new Error(`Invalid prototype mutation: Cannot set prototype on "${originalTarget}". "${originalTarget}" prototype is read-only.`);
1582
- }
1621
+ getElementsByTagName(_qualifiedName) {
1622
+ throw new TypeError('"getElementsByTagName" is not supported in this environment');
1583
1623
  }
1584
- preventExtensions(shadowTarget) {
1585
- /* istanbul ignore else */
1586
- if (process.env.NODE_ENV !== 'production') {
1587
- const { originalTarget } = this;
1588
- throw new Error(`Invalid mutation: Cannot preventExtensions on ${originalTarget}". "${originalTarget} is read-only.`);
1589
- }
1590
- /* istanbul ignore next */
1591
- return false;
1624
+ querySelector(_selectors) {
1625
+ throw new TypeError('"querySelector" is not supported in this environment');
1592
1626
  }
1593
- defineProperty(shadowTarget, key, descriptor) {
1594
- /* istanbul ignore else */
1595
- if (process.env.NODE_ENV !== 'production') {
1596
- const { originalTarget } = this;
1597
- throw new Error(`Invalid mutation: Cannot defineProperty "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1598
- }
1599
- /* istanbul ignore next */
1600
- return false;
1627
+ querySelectorAll(_selectors) {
1628
+ throw new TypeError('"querySelectorAll" is not supported in this environment');
1601
1629
  }
1602
- }
1603
-
1604
- function extract(objectOrArray) {
1605
- if (isArray(objectOrArray)) {
1606
- return objectOrArray.map((item) => {
1607
- const original = unwrap(item);
1608
- if (original !== item) {
1609
- return extract(original);
1610
- }
1611
- return item;
1612
- });
1630
+ getAttributeNS(_namespace, _localName) {
1631
+ throw new Error('Method "getAttributeNS" not implemented.');
1613
1632
  }
1614
- const obj = ObjectCreate(getPrototypeOf(objectOrArray));
1615
- const names = getOwnPropertyNames(objectOrArray);
1616
- return ArrayConcat.call(names, getOwnPropertySymbols(objectOrArray)).reduce((seed, key) => {
1617
- const item = objectOrArray[key];
1618
- const original = unwrap(item);
1619
- if (original !== item) {
1620
- seed[key] = extract(original);
1621
- }
1622
- else {
1623
- seed[key] = item;
1624
- }
1625
- return seed;
1626
- }, obj);
1627
- }
1628
- const formatter = {
1629
- header: (plainOrProxy) => {
1630
- const originalTarget = unwrap(plainOrProxy);
1631
- // if originalTarget is falsy or not unwrappable, exit
1632
- if (!originalTarget || originalTarget === plainOrProxy) {
1633
- return null;
1634
- }
1635
- const obj = extract(plainOrProxy);
1636
- return ['object', { object: obj }];
1637
- },
1638
- hasBody: () => {
1639
- return false;
1640
- },
1641
- body: () => {
1642
- return null;
1643
- },
1644
- };
1645
- // Inspired from paulmillr/es6-shim
1646
- // https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L176-L185
1647
- /* istanbul ignore next */
1648
- function getGlobal() {
1649
- // the only reliable means to get the global object is `Function('return this')()`
1650
- // However, this causes CSP violations in Chrome apps.
1651
- if (typeof globalThis !== 'undefined') {
1652
- return globalThis;
1633
+ hasAttributeNS(_namespace, _localName) {
1634
+ throw new Error('Method "hasAttributeNS" not implemented.');
1653
1635
  }
1654
- if (typeof self !== 'undefined') {
1655
- return self;
1636
+ removeAttributeNS(_namespace, _localName) {
1637
+ throw new Error('Method "removeAttributeNS" not implemented.');
1638
+ }
1639
+ setAttributeNS(_namespace, _qualifiedName, _value) {
1640
+ throw new Error('Method "setAttributeNS" not implemented.');
1641
+ }
1642
+ }
1643
+ defineProperties(LightningElement.prototype, descriptors);
1644
+
1645
+ /*
1646
+ * Copyright (c) 2024, salesforce.com, inc.
1647
+ * All rights reserved.
1648
+ * SPDX-License-Identifier: MIT
1649
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1650
+ */
1651
+ const escapeAttrVal = (attrValue) => attrValue.replaceAll('&', '&amp;').replaceAll('"', '&quot;');
1652
+ function renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken) {
1653
+ // The scopeToken is e.g. `lwc-xyz123` which is the token our parent gives us.
1654
+ // The hostScopeToken is e.g. `lwc-abc456-host` which is the token for our own component.
1655
+ // It's possible to have both, one, the other, or neither.
1656
+ const combinedScopeToken = scopeToken && hostScopeToken
1657
+ ? `${scopeToken} ${hostScopeToken}`
1658
+ : scopeToken || hostScopeToken || '';
1659
+ let result = '';
1660
+ let hasClassAttribute = false;
1661
+ for (const attrName of getOwnPropertyNames$1(attrs)) {
1662
+ let attrValue = attrs[attrName];
1663
+ if (isNull(attrValue) || isUndefined$1(attrValue)) {
1664
+ attrValue = '';
1665
+ }
1666
+ else if (!isString(attrValue)) {
1667
+ attrValue = String(attrValue);
1668
+ }
1669
+ if (attrName === 'class') {
1670
+ if (attrValue === '') {
1671
+ // If the class attribute is empty, we don't render it.
1672
+ continue;
1673
+ }
1674
+ if (combinedScopeToken) {
1675
+ attrValue += ' ' + combinedScopeToken;
1676
+ hasClassAttribute = true;
1677
+ }
1678
+ }
1679
+ result += attrValue === '' ? ` ${attrName}` : ` ${attrName}="${escapeAttrVal(attrValue)}"`;
1656
1680
  }
1657
- if (typeof window !== 'undefined') {
1658
- return window;
1681
+ // If we didn't render any `class` attribute, render one for the scope token(s)
1682
+ if (!hasClassAttribute && combinedScopeToken) {
1683
+ result += ` class="${combinedScopeToken}"`;
1659
1684
  }
1660
- if (typeof global !== 'undefined') {
1661
- return global;
1685
+ // For the host scope token only, we encode a special attribute for hydration
1686
+ if (hostScopeToken) {
1687
+ result += ` data-lwc-host-scope-token="${hostScopeToken}"`;
1662
1688
  }
1663
- // Gracefully degrade if not able to locate the global object
1664
- return {};
1689
+ result += mutationTracker.renderMutatedAttrs(instance);
1690
+ return result;
1665
1691
  }
1666
- function init() {
1667
- /* istanbul ignore if */
1668
- if (process.env.NODE_ENV === 'production') {
1669
- // this method should never leak to prod
1670
- throw new ReferenceError();
1671
- }
1672
- const global = getGlobal();
1673
- // Custom Formatter for Dev Tools. To enable this, open Chrome Dev Tools
1674
- // - Go to Settings,
1675
- // - Under console, select "Enable custom formatters"
1676
- // For more information, https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview
1677
- const devtoolsFormatters = global.devtoolsFormatters || [];
1678
- ArrayPush.call(devtoolsFormatters, formatter);
1679
- global.devtoolsFormatters = devtoolsFormatters;
1692
+ function* renderAttrs(instance, attrs, hostScopeToken, scopeToken) {
1693
+ yield renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken);
1680
1694
  }
1681
-
1682
- /* istanbul ignore else */
1683
- if (process.env.NODE_ENV !== 'production') {
1684
- init();
1695
+ function renderAttrsNoYield(emit, instance, attrs, hostScopeToken, scopeToken) {
1696
+ emit(renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken));
1685
1697
  }
1686
- function defaultValueIsObservable(value) {
1687
- // intentionally checking for null
1688
- if (value === null) {
1689
- return false;
1690
- }
1691
- // treat all non-object types, including undefined, as non-observable values
1692
- if (typeof value !== 'object') {
1693
- return false;
1694
- }
1695
- if (isArray(value)) {
1696
- return true;
1698
+ function* fallbackTmpl(_props, _attrs, _shadowSlottedContent, _lightSlottedContent, Cmp, _instance) {
1699
+ if (Cmp.renderMode !== 'light') {
1700
+ yield '<template shadowrootmode="open"></template>';
1697
1701
  }
1698
- const proto = getPrototypeOf(value);
1699
- return proto === ObjectDotPrototype || proto === null || getPrototypeOf(proto) === null;
1700
1702
  }
1701
- const defaultValueObserved = (obj, key) => {
1702
- /* do nothing */
1703
- };
1704
- const defaultValueMutated = (obj, key) => {
1705
- /* do nothing */
1706
- };
1707
- function createShadowTarget(value) {
1708
- return isArray(value) ? [] : {};
1703
+ function fallbackTmplNoYield(emit, _props, _attrs, _shadowSlottedContent, _lightSlottedContent, Cmp, _instance) {
1704
+ if (Cmp.renderMode !== 'light') {
1705
+ emit('<template shadowrootmode="open"></template>');
1706
+ }
1709
1707
  }
1710
- class ObservableMembrane {
1711
- constructor(options = {}) {
1712
- this.readOnlyObjectGraph = new WeakMap();
1713
- this.reactiveObjectGraph = new WeakMap();
1714
- const { valueMutated, valueObserved, valueIsObservable, tagPropertyKey } = options;
1715
- this.valueMutated = isFunction(valueMutated) ? valueMutated : defaultValueMutated;
1716
- this.valueObserved = isFunction(valueObserved) ? valueObserved : defaultValueObserved;
1717
- this.valueIsObservable = isFunction(valueIsObservable)
1718
- ? valueIsObservable
1719
- : defaultValueIsObservable;
1720
- this.tagPropertyKey = tagPropertyKey;
1708
+ async function serverSideRenderComponent(tagName, Component, props = {}, mode = DEFAULT_SSR_MODE) {
1709
+ if (typeof tagName !== 'string') {
1710
+ throw new Error(`tagName must be a string, found: ${tagName}`);
1721
1711
  }
1722
- getProxy(value) {
1723
- const unwrappedValue = unwrap(value);
1724
- if (this.valueIsObservable(unwrappedValue)) {
1725
- // When trying to extract the writable version of a readonly we return the readonly.
1726
- if (this.readOnlyObjectGraph.get(unwrappedValue) === value) {
1727
- return value;
1728
- }
1729
- return this.getReactiveHandler(unwrappedValue);
1712
+ const generateMarkup = Component[SYMBOL__GENERATE_MARKUP];
1713
+ let markup = '';
1714
+ const emit = (segment) => {
1715
+ markup += segment;
1716
+ };
1717
+ if (mode === 'asyncYield') {
1718
+ for await (const segment of generateMarkup(tagName, props, null, null, null, null, null, null)) {
1719
+ markup += segment;
1730
1720
  }
1731
- return unwrappedValue;
1732
1721
  }
1733
- getReadOnlyProxy(value) {
1734
- value = unwrap(value);
1735
- if (this.valueIsObservable(value)) {
1736
- return this.getReadOnlyHandler(value);
1737
- }
1738
- return value;
1722
+ else if (mode === 'async') {
1723
+ await generateMarkup(emit, tagName, props, null, null, null, null, null, null);
1739
1724
  }
1740
- unwrapProxy(p) {
1741
- return unwrap(p);
1725
+ else if (mode === 'sync') {
1726
+ generateMarkup(emit, tagName, props, null, null, null, null, null, null);
1742
1727
  }
1743
- getReactiveHandler(value) {
1744
- let proxy = this.reactiveObjectGraph.get(value);
1745
- if (isUndefined(proxy)) {
1746
- // caching the proxy after the first time it is accessed
1747
- const handler = new ReactiveProxyHandler(this, value);
1748
- proxy = new Proxy(createShadowTarget(value), handler);
1749
- registerProxy(proxy, value);
1750
- this.reactiveObjectGraph.set(value, proxy);
1751
- }
1752
- return proxy;
1728
+ else {
1729
+ throw new Error(`Invalid mode: ${mode}`);
1753
1730
  }
1754
- getReadOnlyHandler(value) {
1755
- let proxy = this.readOnlyObjectGraph.get(value);
1756
- if (isUndefined(proxy)) {
1757
- // caching the proxy after the first time it is accessed
1758
- const handler = new ReadOnlyHandler(this, value);
1759
- proxy = new Proxy(createShadowTarget(value), handler);
1760
- registerProxy(proxy, value);
1761
- this.readOnlyObjectGraph.set(value, proxy);
1762
- }
1763
- return proxy;
1731
+ return markup;
1732
+ }
1733
+
1734
+ /*
1735
+ * Copyright (c) 2024, Salesforce, Inc.
1736
+ * All rights reserved.
1737
+ * SPDX-License-Identifier: MIT
1738
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1739
+ */
1740
+ /**
1741
+ * Given an object, render it for use as a text content node.
1742
+ * @param value
1743
+ */
1744
+ function massageTextContent(value) {
1745
+ // Using non strict equality to align with original implementation (ex. undefined == null)
1746
+ // See: https://github.com/salesforce/lwc/blob/348130f/packages/%40lwc/engine-core/src/framework/api.ts#L548
1747
+ return value == null ? '' : String(value);
1748
+ }
1749
+
1750
+ /*
1751
+ * Copyright (c) 2024, Salesforce, Inc.
1752
+ * All rights reserved.
1753
+ * SPDX-License-Identifier: MIT
1754
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1755
+ */
1756
+ /**
1757
+ * Per the HTML spec on restrictions for "raw text elements" like `<style>`:
1758
+ *
1759
+ * > The text in raw text and escapable raw text elements must not contain any occurrences of the string
1760
+ * > "</" (U+003C LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that case-insensitively match the tag name of
1761
+ * > the element followed by one of:
1762
+ * > - U+0009 CHARACTER TABULATION (tab)
1763
+ * > - U+000A LINE FEED (LF)
1764
+ * > - U+000C FORM FEED (FF)
1765
+ * > - U+000D CARRIAGE RETURN (CR)
1766
+ * > - U+0020 SPACE
1767
+ * > - U+003E GREATER-THAN SIGN (>), or
1768
+ * > - U+002F SOLIDUS (/)
1769
+ * @see https://html.spec.whatwg.org/multipage/syntax.html#cdata-rcdata-restrictions
1770
+ */
1771
+ const INVALID_STYLE_CONTENT = /<\/style[\t\n\f\r >/]/i;
1772
+ /**
1773
+ * The text content inside `<style>` is a special case. It is _only_ rendered by the LWC engine itself; `<style>` tags
1774
+ * are disallowed inside of HTML templates.
1775
+ *
1776
+ * The `<style>` tag is unusual in how it's defined in HTML. Like `<script>`, it is considered a "raw text element,"
1777
+ * which means that it is parsed as raw text, but certain character sequences are disallowed, namely to avoid XSS
1778
+ * attacks like `</style><script>alert("pwned")</script>`.
1779
+ *
1780
+ * This also means that we cannot use "normal" HTML escaping inside `<style>` tags, e.g. we cannot use `&lt;`,
1781
+ * `&gt;`, etc., because these are treated as-is by the HTML parser.
1782
+ *
1783
+ *
1784
+ * @param contents CSS source to validate
1785
+ * @throws Throws if the contents provided are not valid.
1786
+ * @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
1787
+ * @see https://github.com/salesforce/lwc/issues/3439
1788
+ * @example
1789
+ * validateStyleTextContents('div { color: red }') // Ok
1790
+ * validateStyleTextContents('</style><script>alert("pwned")</script>') // Throws
1791
+ */
1792
+ function validateStyleTextContents(contents) {
1793
+ if (INVALID_STYLE_CONTENT.test(contents)) {
1794
+ throw new Error('CSS contains unsafe characters and cannot be serialized inside a style element');
1764
1795
  }
1765
1796
  }
1766
- /** version: 2.0.0 */
1767
1797
 
1768
1798
  /*
1769
1799
  * Copyright (c) 2024, Salesforce, Inc.
@@ -1771,12 +1801,79 @@ class ObservableMembrane {
1771
1801
  * SPDX-License-Identifier: MIT
1772
1802
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1773
1803
  */
1774
- const reactiveMembrane = new ObservableMembrane();
1775
- // Modeled after `getReadOnlyProxy` in `membrane.ts` in `engine-core`
1776
- // Return a proxy over the given object so that access is immutable
1777
- // https://github.com/salesforce/lwc/blob/e9db491/packages/%40lwc/engine-core/src/framework/membrane.ts#L29-L33
1778
- function getReadOnlyProxy(value) {
1779
- return reactiveMembrane.getReadOnlyProxy(value);
1804
+ // Traverse in the same order as `flattenStylesheets` but without creating unnecessary additional arrays
1805
+ function traverseStylesheets(stylesheets, callback) {
1806
+ if (isArray$1(stylesheets)) {
1807
+ for (let i = 0; i < stylesheets.length; i++) {
1808
+ traverseStylesheets(stylesheets[i], callback);
1809
+ }
1810
+ }
1811
+ else if (stylesheets) {
1812
+ callback(stylesheets);
1813
+ }
1814
+ }
1815
+ function hasScopedStaticStylesheets(Component) {
1816
+ let scoped = false;
1817
+ traverseStylesheets(Component.stylesheets, (stylesheet) => {
1818
+ scoped ||= !!stylesheet.$scoped$;
1819
+ });
1820
+ return scoped;
1821
+ }
1822
+ function renderStylesheets(defaultStylesheets, defaultScopedStylesheets, staticStylesheets, scopeToken, Component, hasScopedTemplateStyles) {
1823
+ const hasAnyScopedStyles = hasScopedTemplateStyles || hasScopedStaticStylesheets(Component);
1824
+ const { renderMode } = Component;
1825
+ let result = '';
1826
+ const renderStylesheet = (stylesheet) => {
1827
+ const { $scoped$: scoped } = stylesheet;
1828
+ const token = scoped ? scopeToken : undefined;
1829
+ const useActualHostSelector = !scoped || renderMode !== 'light';
1830
+ const useNativeDirPseudoclass = true;
1831
+ const styleContents = stylesheet(token, useActualHostSelector, useNativeDirPseudoclass);
1832
+ validateStyleTextContents(styleContents);
1833
+ // TODO [#2869]: `<style>`s should not have scope token classes
1834
+ result += `<style${hasAnyScopedStyles ? ` class="${scopeToken}"` : ''} type="text/css">${styleContents}</style>`;
1835
+ };
1836
+ traverseStylesheets(defaultStylesheets, renderStylesheet);
1837
+ traverseStylesheets(defaultScopedStylesheets, renderStylesheet);
1838
+ traverseStylesheets(staticStylesheets, renderStylesheet);
1839
+ return result;
1840
+ }
1841
+
1842
+ /*
1843
+ * Copyright (c) 2024, salesforce.com, inc.
1844
+ * All rights reserved.
1845
+ * SPDX-License-Identifier: MIT
1846
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1847
+ */
1848
+ /**
1849
+ * Converts an iterable into one that emits the object used by the [`iterator` directive](
1850
+ * https://lwc.dev/guide/html_templates#iterator).
1851
+ */
1852
+ function* toIteratorDirective(iterable) {
1853
+ if (iterable === undefined || iterable === null)
1854
+ return;
1855
+ if (!iterable[Symbol.iterator]) {
1856
+ throw new Error(
1857
+ // Mimic error message from "[i]terable node" in engine-core's api.ts
1858
+ `Invalid template iteration for value \`${iterable}\`. It must be an array-like object.`);
1859
+ }
1860
+ const iterator = iterable[Symbol.iterator]();
1861
+ let next = iterator.next();
1862
+ let index = 0;
1863
+ let { value, done: last = false } = next;
1864
+ while (last === false) {
1865
+ // using a look-back approach because we need to know if the element is the last
1866
+ next = iterator.next();
1867
+ last = next.done ?? false;
1868
+ yield {
1869
+ value,
1870
+ index,
1871
+ first: index === 0,
1872
+ last,
1873
+ };
1874
+ index += 1;
1875
+ value = next.value;
1876
+ }
1780
1877
  }
1781
1878
 
1782
1879
  /*
@@ -1836,6 +1933,6 @@ function createContextProvider(adapter) {
1836
1933
  };
1837
1934
  }
1838
1935
 
1839
- export { ClassList, LightningElement, SYMBOL__DEFAULT_TEMPLATE, SYMBOL__GENERATE_MARKUP, SYMBOL__SET_INTERNALS, api, connectContext, createContextProvider, createElement, establishContextfulRelationship, fallbackTmpl, fallbackTmplNoYield, filterProperties, freezeTemplate, getComponentDef, getReadOnlyProxy, hasScopedStaticStylesheets, hot, htmlEscape, isComponentConstructor, mutationTracker, parseFragment, parseSVGFragment, readonly, registerComponent, registerDecorators, registerTemplate, renderAttrs, renderAttrsNoYield, serverSideRenderComponent as renderComponent, renderStylesheets, renderer, sanitizeAttribute, sanitizeHtmlContent, serverSideRenderComponent, setFeatureFlag, setFeatureFlagForTest, setHooks, swapComponent, swapStyle, swapTemplate, toIteratorDirective, track, unwrap$1 as unwrap, validateStyleTextContents, wire };
1840
- /** version: 8.10.1 */
1936
+ export { ClassList, LightningElement, SYMBOL__DEFAULT_TEMPLATE, SYMBOL__GENERATE_MARKUP, SYMBOL__SET_INTERNALS, api, connectContext, createContextProvider, createElement, establishContextfulRelationship, fallbackTmpl, fallbackTmplNoYield, filterProperties, freezeTemplate, getComponentDef, getReadOnlyProxy, hasScopedStaticStylesheets, hot, htmlEscape, isComponentConstructor, massageTextContent, mutationTracker, normalizeClass, parseFragment, parseSVGFragment, readonly, registerComponent, registerDecorators, registerTemplate, renderAttrs, renderAttrsNoYield, serverSideRenderComponent as renderComponent, renderStylesheets, renderer, sanitizeAttribute, sanitizeHtmlContent, serverSideRenderComponent, setFeatureFlag, setFeatureFlagForTest, setHooks, swapComponent, swapStyle, swapTemplate, toIteratorDirective, track, unwrap$1 as unwrap, validateStyleTextContents, wire };
1937
+ /** version: 8.12.0 */
1841
1938
  //# sourceMappingURL=index.js.map