@lwc/ssr-runtime 8.7.0 → 8.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -11,9 +11,6 @@
11
11
  function api(..._) {
12
12
  throw new Error('@api cannot be used in SSR context.');
13
13
  }
14
- function createContextProvider(..._) {
15
- throw new Error('createContextProvider cannot be used in SSR context.');
16
- }
17
14
  function createElement(..._) {
18
15
  throw new Error('createElement cannot be used in SSR context.');
19
16
  }
@@ -65,7 +62,7 @@ function swapTemplate(..._) {
65
62
  function track(..._) {
66
63
  throw new Error('@track cannot be used in SSR context.');
67
64
  }
68
- function unwrap(..._) {
65
+ function unwrap$1(..._) {
69
66
  throw new Error('unwrap cannot be used in SSR context.');
70
67
  }
71
68
  function wire(..._) {
@@ -266,17 +263,17 @@ freeze,
266
263
  /** Detached {@linkcode Object.fromEntries}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries MDN Reference}. */
267
264
  fromEntries,
268
265
  /** Detached {@linkcode Object.getOwnPropertyDescriptor}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor MDN Reference}. */
269
- getOwnPropertyDescriptor,
266
+ getOwnPropertyDescriptor: getOwnPropertyDescriptor$1,
270
267
  /** Detached {@linkcode Object.getOwnPropertyDescriptors}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors MDN Reference}. */
271
268
  getOwnPropertyDescriptors,
272
269
  /** Detached {@linkcode Object.getOwnPropertyNames}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames MDN Reference}. */
273
- getOwnPropertyNames,
270
+ getOwnPropertyNames: getOwnPropertyNames$1,
274
271
  /** Detached {@linkcode Object.getOwnPropertySymbols}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols MDN Reference}. */
275
- getOwnPropertySymbols,
272
+ getOwnPropertySymbols: getOwnPropertySymbols$1,
276
273
  /** Detached {@linkcode Object.getPrototypeOf}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf MDN Reference}. */
277
- getPrototypeOf,
274
+ getPrototypeOf: getPrototypeOf$1,
278
275
  /** Detached {@linkcode Object.hasOwnProperty}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty MDN Reference}. */
279
- hasOwnProperty,
276
+ hasOwnProperty: hasOwnProperty$1,
280
277
  /** Detached {@linkcode Object.isFrozen}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen MDN Reference}. */
281
278
  isFrozen,
282
279
  /** Detached {@linkcode Object.keys}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys MDN Reference}. */
@@ -287,13 +284,13 @@ seal,
287
284
  setPrototypeOf, } = Object;
288
285
  const {
289
286
  /** Detached {@linkcode Array.isArray}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray MDN Reference}. */
290
- isArray,
287
+ isArray: isArray$1,
291
288
  /** Detached {@linkcode Array.from}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from MDN Reference}. */
292
289
  from: ArrayFrom, } = Array;
293
290
  // For some reason, JSDoc don't get picked up for multiple renamed destructured constants (even
294
291
  // though it works fine for one, e.g. isArray), so comments for these are added to the export
295
292
  // statement, rather than this declaration.
296
- const { concat: ArrayConcat, copyWithin: ArrayCopyWithin, every: ArrayEvery, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, findIndex: ArrayFindIndex, includes: ArrayIncludes, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, some: ArraySome, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, // Weird anomaly!
293
+ const { concat: ArrayConcat$1, copyWithin: ArrayCopyWithin, every: ArrayEvery, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, findIndex: ArrayFindIndex, includes: ArrayIncludes, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush$1, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, some: ArraySome, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, // Weird anomaly!
297
294
  } = Array.prototype;
298
295
  /** Detached {@linkcode String.fromCharCode}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode MDN Reference}. */
299
296
  const { fromCharCode: StringFromCharCode } = String;
@@ -304,7 +301,7 @@ const { charAt: StringCharAt, charCodeAt: StringCharCodeAt, replace: StringRepla
304
301
  * @param obj Value to test
305
302
  * @returns `true` if the value is `undefined`.
306
303
  */
307
- function isUndefined(obj) {
304
+ function isUndefined$1(obj) {
308
305
  return obj === undefined;
309
306
  }
310
307
  /**
@@ -316,26 +313,26 @@ function isNull(obj) {
316
313
  return obj === null;
317
314
  }
318
315
  /**
319
- * Determines whether the argument is an object or null.
316
+ * Determines whether the argument is a string.
320
317
  * @param obj Value to test
321
- * @returns `true` if the value is an object or null.
318
+ * @returns `true` if the value is a string.
322
319
  */
323
- function isObject(obj) {
324
- return typeof obj === 'object';
320
+ function isString(obj) {
321
+ return typeof obj === 'string';
325
322
  }
326
- const OtS = {}.toString;
323
+ const OtS$1 = {}.toString;
327
324
  /**
328
325
  * Converts the argument to a string, safely accounting for objects with "null" prototype.
329
326
  * Note that `toString(null)` returns `"[object Null]"` rather than `"null"`.
330
327
  * @param obj Value to convert to a string.
331
328
  * @returns String representation of the value.
332
329
  */
333
- function toString(obj) {
330
+ function toString$1(obj) {
334
331
  if (obj?.toString) {
335
332
  // Arrays might hold objects with "null" prototype So using
336
333
  // Array.prototype.toString directly will cause an error Iterate through
337
334
  // all the items and handle individually.
338
- if (isArray(obj)) {
335
+ if (isArray$1(obj)) {
339
336
  // This behavior is slightly different from Array#toString:
340
337
  // 1. Array#toString calls `this.join`, rather than Array#join
341
338
  // Ex: arr = []; arr.join = () => 1; arr.toString() === 1; toString(arr) === ''
@@ -346,13 +343,13 @@ function toString(obj) {
346
343
  // 4. Array#toString converts recursive references to arrays to ''
347
344
  // Ex: arr = [1]; arr.push(arr, 2); arr.toString() === '1,,2'; toString(arr) throws
348
345
  // Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString
349
- return ArrayJoin.call(ArrayMap.call(obj, toString), ',');
346
+ return ArrayJoin.call(ArrayMap.call(obj, toString$1), ',');
350
347
  }
351
348
  return obj.toString();
352
349
  }
353
350
  else if (typeof obj === 'object') {
354
351
  // This catches null and returns "[object Null]". Weird, but kept for backwards compatibility.
355
- return OtS.call(obj);
352
+ return OtS$1.call(obj);
356
353
  }
357
354
  else {
358
355
  return String(obj);
@@ -519,15 +516,15 @@ const CACHED_PROPERTY_ATTRIBUTE_MAPPING = /*@__PURE__@*/ new Map();
519
516
  */
520
517
  function htmlPropertyToAttribute(propName) {
521
518
  const ariaAttributeName = AriaPropNameToAttrNameMap[propName];
522
- if (!isUndefined(ariaAttributeName)) {
519
+ if (!isUndefined$1(ariaAttributeName)) {
523
520
  return ariaAttributeName;
524
521
  }
525
522
  const specialAttributeName = SPECIAL_PROPERTY_ATTRIBUTE_MAPPING.get(propName);
526
- if (!isUndefined(specialAttributeName)) {
523
+ if (!isUndefined$1(specialAttributeName)) {
527
524
  return specialAttributeName;
528
525
  }
529
526
  const cachedAttributeName = CACHED_PROPERTY_ATTRIBUTE_MAPPING.get(propName);
530
- if (!isUndefined(cachedAttributeName)) {
527
+ if (!isUndefined$1(cachedAttributeName)) {
531
528
  return cachedAttributeName;
532
529
  }
533
530
  let attributeName = '';
@@ -594,7 +591,7 @@ function setHooks(hooks) {
594
591
  function flattenStylesheets(stylesheets) {
595
592
  const list = [];
596
593
  for (const stylesheet of stylesheets) {
597
- if (!isArray(stylesheet)) {
594
+ if (!isArray$1(stylesheet)) {
598
595
  list.push(stylesheet);
599
596
  }
600
597
  else {
@@ -603,7 +600,7 @@ function flattenStylesheets(stylesheets) {
603
600
  }
604
601
  return list;
605
602
  }
606
- /** version: 8.7.0 */
603
+ /** version: 8.8.0 */
607
604
 
608
605
  /*
609
606
  * Copyright (c) 2024, Salesforce, Inc.
@@ -858,7 +855,7 @@ const ariaDescriptor = (attrName) => ({
858
855
  this.removeAttribute(attrName);
859
856
  }
860
857
  else {
861
- this.setAttribute(attrName, toString(newValue));
858
+ this.setAttribute(attrName, toString$1(newValue));
862
859
  }
863
860
  }
864
861
  },
@@ -882,7 +879,7 @@ const descriptors = {
882
879
  const num = Number(newValue);
883
880
  const normalizedValue = isFinite(num) ? String(Math.trunc(num)) : '0';
884
881
  if (normalizedValue !== currentValue) {
885
- this.setAttribute('tabindex', toString(newValue));
882
+ this.setAttribute('tabindex', toString$1(newValue));
886
883
  }
887
884
  },
888
885
  },
@@ -931,24 +928,24 @@ class LightningElement {
931
928
  return (__classPrivateFieldSet(this, _LightningElement_classList, new ClassList(this), "f"));
932
929
  }
933
930
  setAttribute(attrName, attrValue) {
934
- const normalizedName = StringToLowerCase.call(toString(attrName));
931
+ const normalizedName = StringToLowerCase.call(toString$1(attrName));
935
932
  const normalizedValue = String(attrValue);
936
933
  __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName] = normalizedValue;
937
934
  mutationTracker.add(this, normalizedName);
938
935
  }
939
936
  getAttribute(attrName) {
940
- const normalizedName = StringToLowerCase.call(toString(attrName));
941
- if (hasOwnProperty.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName)) {
937
+ const normalizedName = StringToLowerCase.call(toString$1(attrName));
938
+ if (hasOwnProperty$1.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName)) {
942
939
  return __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
943
940
  }
944
941
  return null;
945
942
  }
946
943
  hasAttribute(attrName) {
947
- const normalizedName = StringToLowerCase.call(toString(attrName));
948
- return hasOwnProperty.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName);
944
+ const normalizedName = StringToLowerCase.call(toString$1(attrName));
945
+ return hasOwnProperty$1.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName);
949
946
  }
950
947
  removeAttribute(attrName) {
951
- const normalizedName = StringToLowerCase.call(toString(attrName));
948
+ const normalizedName = StringToLowerCase.call(toString$1(attrName));
952
949
  delete __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
953
950
  // Track mutations for removal of non-existing attributes
954
951
  mutationTracker.add(this, normalizedName);
@@ -1035,36 +1032,42 @@ defineProperties(LightningElement.prototype, descriptors);
1035
1032
  * SPDX-License-Identifier: MIT
1036
1033
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1037
1034
  */
1038
- const escapeAttrVal = (attrVal) => attrVal.replaceAll('&', '&').replaceAll('"', '"');
1039
- function* renderAttrs(instance, attrs) {
1040
- if (!attrs) {
1041
- return;
1042
- }
1043
- for (const attrName of Object.getOwnPropertyNames(attrs)) {
1044
- const attrVal = attrs[attrName];
1045
- if (typeof attrVal === 'string') {
1046
- yield attrVal === '' ? ` ${attrName}` : ` ${attrName}="${escapeAttrVal(attrVal)}"`;
1035
+ const escapeAttrVal = (attrValue) => attrValue.replaceAll('&', '&').replaceAll('"', '"');
1036
+ function renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken) {
1037
+ // The scopeToken is e.g. `lwc-xyz123` which is the token our parent gives us.
1038
+ // The hostScopeToken is e.g. `lwc-abc456-host` which is the token for our own component.
1039
+ // It's possible to have both, one, the other, or neither.
1040
+ const combinedScopeToken = scopeToken && hostScopeToken
1041
+ ? `${scopeToken} ${hostScopeToken}`
1042
+ : scopeToken || hostScopeToken || '';
1043
+ let result = '';
1044
+ let hasClassAttribute = false;
1045
+ for (const attrName of getOwnPropertyNames$1(attrs)) {
1046
+ let attrValue = attrs[attrName];
1047
+ if (isNull(attrValue) || isUndefined$1(attrValue)) {
1048
+ attrValue = '';
1047
1049
  }
1048
- else if (attrVal === null) {
1049
- yield '';
1050
+ else if (!isString(attrValue)) {
1051
+ attrValue = String(attrValue);
1050
1052
  }
1051
- }
1052
- yield mutationTracker.renderMutatedAttrs(instance);
1053
- }
1054
- function renderAttrsNoYield(emit, instance, attrs) {
1055
- if (!attrs) {
1056
- return;
1057
- }
1058
- for (const attrName of Object.getOwnPropertyNames(attrs)) {
1059
- const attrVal = attrs[attrName];
1060
- if (typeof attrVal === 'string') {
1061
- emit(attrVal === '' ? ` ${attrName}` : ` ${attrName}="${escapeAttrVal(attrVal)}"`);
1062
- }
1063
- else if (attrVal === null) {
1064
- emit('');
1053
+ if (combinedScopeToken && attrName === 'class') {
1054
+ attrValue += ' ' + combinedScopeToken;
1055
+ hasClassAttribute = true;
1065
1056
  }
1057
+ result += attrValue === '' ? ` ${attrName}` : ` ${attrName}="${escapeAttrVal(attrValue)}"`;
1066
1058
  }
1067
- emit(mutationTracker.renderMutatedAttrs(instance));
1059
+ // If we didn't render any `class` attribute, render one for the scope token(s)
1060
+ if (!hasClassAttribute && combinedScopeToken) {
1061
+ result += ` class="${combinedScopeToken}"`;
1062
+ }
1063
+ result += mutationTracker.renderMutatedAttrs(instance);
1064
+ return result;
1065
+ }
1066
+ function* renderAttrs(instance, attrs, hostScopeToken, scopeToken) {
1067
+ yield renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken);
1068
+ }
1069
+ function renderAttrsNoYield(emit, instance, attrs, hostScopeToken, scopeToken) {
1070
+ emit(renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken));
1068
1071
  }
1069
1072
  function* fallbackTmpl(_props, _attrs, _slotted, Cmp, _instance) {
1070
1073
  if (Cmp.renderMode !== 'light') {
@@ -1218,39 +1221,622 @@ function* toIteratorDirective(iterable) {
1218
1221
  }
1219
1222
  }
1220
1223
 
1224
+ /**
1225
+ * Copyright (C) 2017 salesforce.com, inc.
1226
+ */
1227
+ const { isArray } = Array;
1228
+ const { prototype: ObjectDotPrototype, getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, } = Object;
1229
+ const { push: ArrayPush, concat: ArrayConcat } = Array.prototype;
1230
+ const OtS = {}.toString;
1231
+ function toString(obj) {
1232
+ if (obj && obj.toString) {
1233
+ return obj.toString();
1234
+ }
1235
+ else if (typeof obj === 'object') {
1236
+ return OtS.call(obj);
1237
+ }
1238
+ else {
1239
+ return obj + '';
1240
+ }
1241
+ }
1242
+ function isUndefined(obj) {
1243
+ return obj === undefined;
1244
+ }
1245
+ function isFunction(obj) {
1246
+ return typeof obj === 'function';
1247
+ }
1248
+ const proxyToValueMap = new WeakMap();
1249
+ function registerProxy(proxy, value) {
1250
+ proxyToValueMap.set(proxy, value);
1251
+ }
1252
+ const unwrap = (replicaOrAny) => proxyToValueMap.get(replicaOrAny) || replicaOrAny;
1253
+
1254
+ class BaseProxyHandler {
1255
+ constructor(membrane, value) {
1256
+ this.originalTarget = value;
1257
+ this.membrane = membrane;
1258
+ }
1259
+ // Shared utility methods
1260
+ wrapDescriptor(descriptor) {
1261
+ if (hasOwnProperty.call(descriptor, 'value')) {
1262
+ descriptor.value = this.wrapValue(descriptor.value);
1263
+ }
1264
+ else {
1265
+ const { set: originalSet, get: originalGet } = descriptor;
1266
+ if (!isUndefined(originalGet)) {
1267
+ descriptor.get = this.wrapGetter(originalGet);
1268
+ }
1269
+ if (!isUndefined(originalSet)) {
1270
+ descriptor.set = this.wrapSetter(originalSet);
1271
+ }
1272
+ }
1273
+ return descriptor;
1274
+ }
1275
+ copyDescriptorIntoShadowTarget(shadowTarget, key) {
1276
+ const { originalTarget } = this;
1277
+ // Note: a property might get defined multiple times in the shadowTarget
1278
+ // but it will always be compatible with the previous descriptor
1279
+ // to preserve the object invariants, which makes these lines safe.
1280
+ const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key);
1281
+ // TODO: it should be impossible for the originalDescriptor to ever be undefined, this `if` can be removed
1282
+ /* istanbul ignore else */
1283
+ if (!isUndefined(originalDescriptor)) {
1284
+ const wrappedDesc = this.wrapDescriptor(originalDescriptor);
1285
+ ObjectDefineProperty(shadowTarget, key, wrappedDesc);
1286
+ }
1287
+ }
1288
+ lockShadowTarget(shadowTarget) {
1289
+ const { originalTarget } = this;
1290
+ const targetKeys = ArrayConcat.call(getOwnPropertyNames(originalTarget), getOwnPropertySymbols(originalTarget));
1291
+ targetKeys.forEach((key) => {
1292
+ this.copyDescriptorIntoShadowTarget(shadowTarget, key);
1293
+ });
1294
+ const { membrane: { tagPropertyKey }, } = this;
1295
+ if (!isUndefined(tagPropertyKey) && !hasOwnProperty.call(shadowTarget, tagPropertyKey)) {
1296
+ ObjectDefineProperty(shadowTarget, tagPropertyKey, ObjectCreate(null));
1297
+ }
1298
+ preventExtensions(shadowTarget);
1299
+ }
1300
+ // Shared Traps
1301
+ // TODO: apply() is never called
1302
+ /* istanbul ignore next */
1303
+ apply(shadowTarget, thisArg, argArray) {
1304
+ /* No op */
1305
+ }
1306
+ // TODO: construct() is never called
1307
+ /* istanbul ignore next */
1308
+ construct(shadowTarget, argArray, newTarget) {
1309
+ /* No op */
1310
+ }
1311
+ get(shadowTarget, key) {
1312
+ const { originalTarget, membrane: { valueObserved }, } = this;
1313
+ const value = originalTarget[key];
1314
+ valueObserved(originalTarget, key);
1315
+ return this.wrapValue(value);
1316
+ }
1317
+ has(shadowTarget, key) {
1318
+ const { originalTarget, membrane: { tagPropertyKey, valueObserved }, } = this;
1319
+ valueObserved(originalTarget, key);
1320
+ // since key is never going to be undefined, and tagPropertyKey might be undefined
1321
+ // we can simply compare them as the second part of the condition.
1322
+ return key in originalTarget || key === tagPropertyKey;
1323
+ }
1324
+ ownKeys(shadowTarget) {
1325
+ const { originalTarget, membrane: { tagPropertyKey }, } = this;
1326
+ // if the membrane tag key exists and it is not in the original target, we add it to the keys.
1327
+ const keys = isUndefined(tagPropertyKey) || hasOwnProperty.call(originalTarget, tagPropertyKey)
1328
+ ? []
1329
+ : [tagPropertyKey];
1330
+ // small perf optimization using push instead of concat to avoid creating an extra array
1331
+ ArrayPush.apply(keys, getOwnPropertyNames(originalTarget));
1332
+ ArrayPush.apply(keys, getOwnPropertySymbols(originalTarget));
1333
+ return keys;
1334
+ }
1335
+ isExtensible(shadowTarget) {
1336
+ const { originalTarget } = this;
1337
+ // optimization to avoid attempting to lock down the shadowTarget multiple times
1338
+ if (!isExtensible(shadowTarget)) {
1339
+ return false; // was already locked down
1340
+ }
1341
+ if (!isExtensible(originalTarget)) {
1342
+ this.lockShadowTarget(shadowTarget);
1343
+ return false;
1344
+ }
1345
+ return true;
1346
+ }
1347
+ getPrototypeOf(shadowTarget) {
1348
+ const { originalTarget } = this;
1349
+ return getPrototypeOf(originalTarget);
1350
+ }
1351
+ getOwnPropertyDescriptor(shadowTarget, key) {
1352
+ const { originalTarget, membrane: { valueObserved, tagPropertyKey }, } = this;
1353
+ // keys looked up via getOwnPropertyDescriptor need to be reactive
1354
+ valueObserved(originalTarget, key);
1355
+ let desc = getOwnPropertyDescriptor(originalTarget, key);
1356
+ if (isUndefined(desc)) {
1357
+ if (key !== tagPropertyKey) {
1358
+ return undefined;
1359
+ }
1360
+ // if the key is the membrane tag key, and is not in the original target,
1361
+ // we produce a synthetic descriptor and install it on the shadow target
1362
+ desc = { value: undefined, writable: false, configurable: false, enumerable: false };
1363
+ ObjectDefineProperty(shadowTarget, tagPropertyKey, desc);
1364
+ return desc;
1365
+ }
1366
+ if (desc.configurable === false) {
1367
+ // updating the descriptor to non-configurable on the shadow
1368
+ this.copyDescriptorIntoShadowTarget(shadowTarget, key);
1369
+ }
1370
+ // Note: by accessing the descriptor, the key is marked as observed
1371
+ // but access to the value, setter or getter (if available) cannot observe
1372
+ // mutations, just like regular methods, in which case we just do nothing.
1373
+ return this.wrapDescriptor(desc);
1374
+ }
1375
+ }
1376
+
1377
+ const getterMap$1 = new WeakMap();
1378
+ const setterMap$1 = new WeakMap();
1379
+ const reverseGetterMap = new WeakMap();
1380
+ const reverseSetterMap = new WeakMap();
1381
+ class ReactiveProxyHandler extends BaseProxyHandler {
1382
+ wrapValue(value) {
1383
+ return this.membrane.getProxy(value);
1384
+ }
1385
+ wrapGetter(originalGet) {
1386
+ const wrappedGetter = getterMap$1.get(originalGet);
1387
+ if (!isUndefined(wrappedGetter)) {
1388
+ return wrappedGetter;
1389
+ }
1390
+ const handler = this;
1391
+ const get = function () {
1392
+ // invoking the original getter with the original target
1393
+ return handler.wrapValue(originalGet.call(unwrap(this)));
1394
+ };
1395
+ getterMap$1.set(originalGet, get);
1396
+ reverseGetterMap.set(get, originalGet);
1397
+ return get;
1398
+ }
1399
+ wrapSetter(originalSet) {
1400
+ const wrappedSetter = setterMap$1.get(originalSet);
1401
+ if (!isUndefined(wrappedSetter)) {
1402
+ return wrappedSetter;
1403
+ }
1404
+ const set = function (v) {
1405
+ // invoking the original setter with the original target
1406
+ originalSet.call(unwrap(this), unwrap(v));
1407
+ };
1408
+ setterMap$1.set(originalSet, set);
1409
+ reverseSetterMap.set(set, originalSet);
1410
+ return set;
1411
+ }
1412
+ unwrapDescriptor(descriptor) {
1413
+ if (hasOwnProperty.call(descriptor, 'value')) {
1414
+ // dealing with a data descriptor
1415
+ descriptor.value = unwrap(descriptor.value);
1416
+ }
1417
+ else {
1418
+ const { set, get } = descriptor;
1419
+ if (!isUndefined(get)) {
1420
+ descriptor.get = this.unwrapGetter(get);
1421
+ }
1422
+ if (!isUndefined(set)) {
1423
+ descriptor.set = this.unwrapSetter(set);
1424
+ }
1425
+ }
1426
+ return descriptor;
1427
+ }
1428
+ unwrapGetter(redGet) {
1429
+ const reverseGetter = reverseGetterMap.get(redGet);
1430
+ if (!isUndefined(reverseGetter)) {
1431
+ return reverseGetter;
1432
+ }
1433
+ const handler = this;
1434
+ const get = function () {
1435
+ // invoking the red getter with the proxy of this
1436
+ return unwrap(redGet.call(handler.wrapValue(this)));
1437
+ };
1438
+ getterMap$1.set(get, redGet);
1439
+ reverseGetterMap.set(redGet, get);
1440
+ return get;
1441
+ }
1442
+ unwrapSetter(redSet) {
1443
+ const reverseSetter = reverseSetterMap.get(redSet);
1444
+ if (!isUndefined(reverseSetter)) {
1445
+ return reverseSetter;
1446
+ }
1447
+ const handler = this;
1448
+ const set = function (v) {
1449
+ // invoking the red setter with the proxy of this
1450
+ redSet.call(handler.wrapValue(this), handler.wrapValue(v));
1451
+ };
1452
+ setterMap$1.set(set, redSet);
1453
+ reverseSetterMap.set(redSet, set);
1454
+ return set;
1455
+ }
1456
+ set(shadowTarget, key, value) {
1457
+ const { originalTarget, membrane: { valueMutated }, } = this;
1458
+ const oldValue = originalTarget[key];
1459
+ if (oldValue !== value) {
1460
+ originalTarget[key] = value;
1461
+ valueMutated(originalTarget, key);
1462
+ }
1463
+ else if (key === 'length' && isArray(originalTarget)) {
1464
+ // fix for issue #236: push will add the new index, and by the time length
1465
+ // is updated, the internal length is already equal to the new length value
1466
+ // therefore, the oldValue is equal to the value. This is the forking logic
1467
+ // to support this use case.
1468
+ valueMutated(originalTarget, key);
1469
+ }
1470
+ return true;
1471
+ }
1472
+ deleteProperty(shadowTarget, key) {
1473
+ const { originalTarget, membrane: { valueMutated }, } = this;
1474
+ delete originalTarget[key];
1475
+ valueMutated(originalTarget, key);
1476
+ return true;
1477
+ }
1478
+ setPrototypeOf(shadowTarget, prototype) {
1479
+ /* istanbul ignore else */
1480
+ if (process.env.NODE_ENV !== 'production') {
1481
+ throw new Error(`Invalid setPrototypeOf invocation for reactive proxy ${toString(this.originalTarget)}. Prototype of reactive objects cannot be changed.`);
1482
+ }
1483
+ }
1484
+ preventExtensions(shadowTarget) {
1485
+ if (isExtensible(shadowTarget)) {
1486
+ const { originalTarget } = this;
1487
+ preventExtensions(originalTarget);
1488
+ // if the originalTarget is a proxy itself, it might reject
1489
+ // the preventExtension call, in which case we should not attempt to lock down
1490
+ // the shadow target.
1491
+ // TODO: It should not actually be possible to reach this `if` statement.
1492
+ // If a proxy rejects extensions, then calling preventExtensions will throw an error:
1493
+ // https://codepen.io/nolanlawson-the-selector/pen/QWMOjbY
1494
+ /* istanbul ignore if */
1495
+ if (isExtensible(originalTarget)) {
1496
+ return false;
1497
+ }
1498
+ this.lockShadowTarget(shadowTarget);
1499
+ }
1500
+ return true;
1501
+ }
1502
+ defineProperty(shadowTarget, key, descriptor) {
1503
+ const { originalTarget, membrane: { valueMutated, tagPropertyKey }, } = this;
1504
+ if (key === tagPropertyKey && !hasOwnProperty.call(originalTarget, key)) {
1505
+ // To avoid leaking the membrane tag property into the original target, we must
1506
+ // be sure that the original target doesn't have yet.
1507
+ // NOTE: we do not return false here because Object.freeze and equivalent operations
1508
+ // will attempt to set the descriptor to the same value, and expect no to throw. This
1509
+ // is an small compromise for the sake of not having to diff the descriptors.
1510
+ return true;
1511
+ }
1512
+ ObjectDefineProperty(originalTarget, key, this.unwrapDescriptor(descriptor));
1513
+ // intentionally testing if false since it could be undefined as well
1514
+ if (descriptor.configurable === false) {
1515
+ this.copyDescriptorIntoShadowTarget(shadowTarget, key);
1516
+ }
1517
+ valueMutated(originalTarget, key);
1518
+ return true;
1519
+ }
1520
+ }
1521
+
1522
+ const getterMap = new WeakMap();
1523
+ const setterMap = new WeakMap();
1524
+ class ReadOnlyHandler extends BaseProxyHandler {
1525
+ wrapValue(value) {
1526
+ return this.membrane.getReadOnlyProxy(value);
1527
+ }
1528
+ wrapGetter(originalGet) {
1529
+ const wrappedGetter = getterMap.get(originalGet);
1530
+ if (!isUndefined(wrappedGetter)) {
1531
+ return wrappedGetter;
1532
+ }
1533
+ const handler = this;
1534
+ const get = function () {
1535
+ // invoking the original getter with the original target
1536
+ return handler.wrapValue(originalGet.call(unwrap(this)));
1537
+ };
1538
+ getterMap.set(originalGet, get);
1539
+ return get;
1540
+ }
1541
+ wrapSetter(originalSet) {
1542
+ const wrappedSetter = setterMap.get(originalSet);
1543
+ if (!isUndefined(wrappedSetter)) {
1544
+ return wrappedSetter;
1545
+ }
1546
+ const handler = this;
1547
+ const set = function (v) {
1548
+ /* istanbul ignore else */
1549
+ if (process.env.NODE_ENV !== 'production') {
1550
+ const { originalTarget } = handler;
1551
+ throw new Error(`Invalid mutation: Cannot invoke a setter on "${originalTarget}". "${originalTarget}" is read-only.`);
1552
+ }
1553
+ };
1554
+ setterMap.set(originalSet, set);
1555
+ return set;
1556
+ }
1557
+ set(shadowTarget, key, value) {
1558
+ /* istanbul ignore else */
1559
+ if (process.env.NODE_ENV !== 'production') {
1560
+ const { originalTarget } = this;
1561
+ const msg = isArray(originalTarget)
1562
+ ? `Invalid mutation: Cannot mutate array at index ${key.toString()}. Array is read-only.`
1563
+ : `Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`;
1564
+ throw new Error(msg);
1565
+ }
1566
+ /* istanbul ignore next */
1567
+ return false;
1568
+ }
1569
+ deleteProperty(shadowTarget, key) {
1570
+ /* istanbul ignore else */
1571
+ if (process.env.NODE_ENV !== 'production') {
1572
+ const { originalTarget } = this;
1573
+ throw new Error(`Invalid mutation: Cannot delete "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1574
+ }
1575
+ /* istanbul ignore next */
1576
+ return false;
1577
+ }
1578
+ setPrototypeOf(shadowTarget, prototype) {
1579
+ /* istanbul ignore else */
1580
+ if (process.env.NODE_ENV !== 'production') {
1581
+ const { originalTarget } = this;
1582
+ throw new Error(`Invalid prototype mutation: Cannot set prototype on "${originalTarget}". "${originalTarget}" prototype is read-only.`);
1583
+ }
1584
+ }
1585
+ preventExtensions(shadowTarget) {
1586
+ /* istanbul ignore else */
1587
+ if (process.env.NODE_ENV !== 'production') {
1588
+ const { originalTarget } = this;
1589
+ throw new Error(`Invalid mutation: Cannot preventExtensions on ${originalTarget}". "${originalTarget} is read-only.`);
1590
+ }
1591
+ /* istanbul ignore next */
1592
+ return false;
1593
+ }
1594
+ defineProperty(shadowTarget, key, descriptor) {
1595
+ /* istanbul ignore else */
1596
+ if (process.env.NODE_ENV !== 'production') {
1597
+ const { originalTarget } = this;
1598
+ throw new Error(`Invalid mutation: Cannot defineProperty "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1599
+ }
1600
+ /* istanbul ignore next */
1601
+ return false;
1602
+ }
1603
+ }
1604
+
1605
+ function extract(objectOrArray) {
1606
+ if (isArray(objectOrArray)) {
1607
+ return objectOrArray.map((item) => {
1608
+ const original = unwrap(item);
1609
+ if (original !== item) {
1610
+ return extract(original);
1611
+ }
1612
+ return item;
1613
+ });
1614
+ }
1615
+ const obj = ObjectCreate(getPrototypeOf(objectOrArray));
1616
+ const names = getOwnPropertyNames(objectOrArray);
1617
+ return ArrayConcat.call(names, getOwnPropertySymbols(objectOrArray)).reduce((seed, key) => {
1618
+ const item = objectOrArray[key];
1619
+ const original = unwrap(item);
1620
+ if (original !== item) {
1621
+ seed[key] = extract(original);
1622
+ }
1623
+ else {
1624
+ seed[key] = item;
1625
+ }
1626
+ return seed;
1627
+ }, obj);
1628
+ }
1629
+ const formatter = {
1630
+ header: (plainOrProxy) => {
1631
+ const originalTarget = unwrap(plainOrProxy);
1632
+ // if originalTarget is falsy or not unwrappable, exit
1633
+ if (!originalTarget || originalTarget === plainOrProxy) {
1634
+ return null;
1635
+ }
1636
+ const obj = extract(plainOrProxy);
1637
+ return ['object', { object: obj }];
1638
+ },
1639
+ hasBody: () => {
1640
+ return false;
1641
+ },
1642
+ body: () => {
1643
+ return null;
1644
+ },
1645
+ };
1646
+ // Inspired from paulmillr/es6-shim
1647
+ // https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L176-L185
1648
+ /* istanbul ignore next */
1649
+ function getGlobal() {
1650
+ // the only reliable means to get the global object is `Function('return this')()`
1651
+ // However, this causes CSP violations in Chrome apps.
1652
+ if (typeof globalThis !== 'undefined') {
1653
+ return globalThis;
1654
+ }
1655
+ if (typeof self !== 'undefined') {
1656
+ return self;
1657
+ }
1658
+ if (typeof window !== 'undefined') {
1659
+ return window;
1660
+ }
1661
+ if (typeof global !== 'undefined') {
1662
+ return global;
1663
+ }
1664
+ // Gracefully degrade if not able to locate the global object
1665
+ return {};
1666
+ }
1667
+ function init() {
1668
+ /* istanbul ignore if */
1669
+ if (process.env.NODE_ENV === 'production') {
1670
+ // this method should never leak to prod
1671
+ throw new ReferenceError();
1672
+ }
1673
+ const global = getGlobal();
1674
+ // Custom Formatter for Dev Tools. To enable this, open Chrome Dev Tools
1675
+ // - Go to Settings,
1676
+ // - Under console, select "Enable custom formatters"
1677
+ // For more information, https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview
1678
+ const devtoolsFormatters = global.devtoolsFormatters || [];
1679
+ ArrayPush.call(devtoolsFormatters, formatter);
1680
+ global.devtoolsFormatters = devtoolsFormatters;
1681
+ }
1682
+
1683
+ /* istanbul ignore else */
1684
+ if (process.env.NODE_ENV !== 'production') {
1685
+ init();
1686
+ }
1687
+ function defaultValueIsObservable(value) {
1688
+ // intentionally checking for null
1689
+ if (value === null) {
1690
+ return false;
1691
+ }
1692
+ // treat all non-object types, including undefined, as non-observable values
1693
+ if (typeof value !== 'object') {
1694
+ return false;
1695
+ }
1696
+ if (isArray(value)) {
1697
+ return true;
1698
+ }
1699
+ const proto = getPrototypeOf(value);
1700
+ return proto === ObjectDotPrototype || proto === null || getPrototypeOf(proto) === null;
1701
+ }
1702
+ const defaultValueObserved = (obj, key) => {
1703
+ /* do nothing */
1704
+ };
1705
+ const defaultValueMutated = (obj, key) => {
1706
+ /* do nothing */
1707
+ };
1708
+ function createShadowTarget(value) {
1709
+ return isArray(value) ? [] : {};
1710
+ }
1711
+ class ObservableMembrane {
1712
+ constructor(options = {}) {
1713
+ this.readOnlyObjectGraph = new WeakMap();
1714
+ this.reactiveObjectGraph = new WeakMap();
1715
+ const { valueMutated, valueObserved, valueIsObservable, tagPropertyKey } = options;
1716
+ this.valueMutated = isFunction(valueMutated) ? valueMutated : defaultValueMutated;
1717
+ this.valueObserved = isFunction(valueObserved) ? valueObserved : defaultValueObserved;
1718
+ this.valueIsObservable = isFunction(valueIsObservable)
1719
+ ? valueIsObservable
1720
+ : defaultValueIsObservable;
1721
+ this.tagPropertyKey = tagPropertyKey;
1722
+ }
1723
+ getProxy(value) {
1724
+ const unwrappedValue = unwrap(value);
1725
+ if (this.valueIsObservable(unwrappedValue)) {
1726
+ // When trying to extract the writable version of a readonly we return the readonly.
1727
+ if (this.readOnlyObjectGraph.get(unwrappedValue) === value) {
1728
+ return value;
1729
+ }
1730
+ return this.getReactiveHandler(unwrappedValue);
1731
+ }
1732
+ return unwrappedValue;
1733
+ }
1734
+ getReadOnlyProxy(value) {
1735
+ value = unwrap(value);
1736
+ if (this.valueIsObservable(value)) {
1737
+ return this.getReadOnlyHandler(value);
1738
+ }
1739
+ return value;
1740
+ }
1741
+ unwrapProxy(p) {
1742
+ return unwrap(p);
1743
+ }
1744
+ getReactiveHandler(value) {
1745
+ let proxy = this.reactiveObjectGraph.get(value);
1746
+ if (isUndefined(proxy)) {
1747
+ // caching the proxy after the first time it is accessed
1748
+ const handler = new ReactiveProxyHandler(this, value);
1749
+ proxy = new Proxy(createShadowTarget(value), handler);
1750
+ registerProxy(proxy, value);
1751
+ this.reactiveObjectGraph.set(value, proxy);
1752
+ }
1753
+ return proxy;
1754
+ }
1755
+ getReadOnlyHandler(value) {
1756
+ let proxy = this.readOnlyObjectGraph.get(value);
1757
+ if (isUndefined(proxy)) {
1758
+ // caching the proxy after the first time it is accessed
1759
+ const handler = new ReadOnlyHandler(this, value);
1760
+ proxy = new Proxy(createShadowTarget(value), handler);
1761
+ registerProxy(proxy, value);
1762
+ this.readOnlyObjectGraph.set(value, proxy);
1763
+ }
1764
+ return proxy;
1765
+ }
1766
+ }
1767
+ /** version: 2.0.0 */
1768
+
1221
1769
  /*
1222
1770
  * Copyright (c) 2024, Salesforce, Inc.
1223
1771
  * All rights reserved.
1224
1772
  * SPDX-License-Identifier: MIT
1225
1773
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1226
1774
  */
1227
- // Deep freeze and clone an object. Designed for cloning/freezing child props when passed from a parent to a child so
1228
- // that they are immutable. This is one of the normal guarantees of both engine-dom and engine-server that we want to
1229
- // emulate in ssr-runtime. The goal here is that a child cannot mutate the props of its parent and thus affect
1230
- // the parent's rendering, which would lead to bidirectional reactivity and mischief.
1231
- function cloneAndDeepFreeze(obj) {
1232
- if (isArray(obj)) {
1233
- const res = [];
1234
- for (const item of obj) {
1235
- ArrayPush.call(res, cloneAndDeepFreeze(item));
1236
- }
1237
- freeze(res);
1238
- return res;
1775
+ const reactiveMembrane = new ObservableMembrane();
1776
+ // Modeled after `getReadOnlyProxy` in `membrane.ts` in `engine-core`
1777
+ // Return a proxy over the given object so that access is immutable
1778
+ // https://github.com/salesforce/lwc/blob/e9db491/packages/%40lwc/engine-core/src/framework/membrane.ts#L29-L33
1779
+ function getReadOnlyProxy(value) {
1780
+ return reactiveMembrane.getReadOnlyProxy(value);
1781
+ }
1782
+
1783
+ /*
1784
+ * Copyright (c) 2024, salesforce.com, inc.
1785
+ * All rights reserved.
1786
+ * SPDX-License-Identifier: MIT
1787
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1788
+ */
1789
+ const contextfulRelationships = new WeakMap();
1790
+ function establishContextfulRelationship(parentLe, childLe) {
1791
+ contextfulRelationships.set(childLe, parentLe);
1792
+ }
1793
+ function getContextfulStack(le) {
1794
+ const contextfulParent = contextfulRelationships.get(le);
1795
+ if (!contextfulParent) {
1796
+ return [];
1239
1797
  }
1240
- else if (isObject(obj) && !isNull(obj)) {
1241
- const res = create(null);
1242
- for (const [key, value] of entries(obj)) {
1243
- res[key] = cloneAndDeepFreeze(value);
1244
- }
1245
- freeze(res);
1246
- return res;
1798
+ return [contextfulParent, ...getContextfulStack(contextfulParent)];
1799
+ }
1800
+ const contextProviders = new WeakMap();
1801
+ function registerContextProvider(adapter, attachedLe, consumerCallback) {
1802
+ let elementMap = contextProviders.get(adapter);
1803
+ if (!elementMap) {
1804
+ elementMap = new WeakMap();
1805
+ contextProviders.set(adapter, elementMap);
1806
+ }
1807
+ elementMap.set(attachedLe, consumerCallback);
1808
+ }
1809
+ function connectContext(adapter, contextConsumer, onNewValue) {
1810
+ const elementMap = contextProviders.get(adapter);
1811
+ if (!elementMap) {
1812
+ return;
1247
1813
  }
1248
- else {
1249
- // primitive
1250
- return obj;
1814
+ const contextfulStack = getContextfulStack(contextConsumer);
1815
+ for (const ancestor of contextfulStack) {
1816
+ const onConsumerConnected = elementMap.get(ancestor);
1817
+ if (onConsumerConnected) {
1818
+ onConsumerConnected({
1819
+ provide(newContextValue) {
1820
+ onNewValue(newContextValue);
1821
+ },
1822
+ });
1823
+ return;
1824
+ }
1251
1825
  }
1252
1826
  }
1827
+ function createContextProvider(adapter) {
1828
+ return (le, options) => {
1829
+ if (!(le instanceof LightningElement)) {
1830
+ throw new Error('Unable to register context provider on provided `elm`.');
1831
+ }
1832
+ if (!le.isConnected || !options?.consumerConnectedCallback) {
1833
+ return;
1834
+ }
1835
+ const { consumerConnectedCallback } = options;
1836
+ registerContextProvider(adapter, le, (consumer) => consumerConnectedCallback(consumer));
1837
+ };
1838
+ }
1253
1839
 
1254
- export { ClassList, LightningElement, SYMBOL__GENERATE_MARKUP, SYMBOL__SET_INTERNALS, api, cloneAndDeepFreeze, createContextProvider, createElement, fallbackTmpl, fallbackTmplNoYield, filterProperties, freezeTemplate, getComponentDef, 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, validateStyleTextContents, wire };
1255
- /** version: 8.7.0 */
1840
+ export { ClassList, LightningElement, 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 };
1841
+ /** version: 8.8.0 */
1256
1842
  //# sourceMappingURL=index.js.map