@lwc/ssr-runtime 8.11.0 → 8.12.1

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