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