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