@lwc/ssr-runtime 8.11.0 → 8.12.0

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