@lwc/engine-core 6.5.1 → 6.5.3

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
@@ -2057,7 +2057,7 @@ function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
2057
2057
  }
2058
2058
 
2059
2059
  /*
2060
- * Copyright (c) 2023, salesforce.com, inc.
2060
+ * Copyright (c) 2024, Salesforce, Inc.
2061
2061
  * All rights reserved.
2062
2062
  * SPDX-License-Identifier: MIT
2063
2063
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -2216,7 +2216,8 @@ function installWireAdapters(vm) {
2216
2216
  vm.debugInfo[WIRE_DEBUG_ENTRY] = shared.create(null);
2217
2217
  }
2218
2218
  const wiredConnecting = (context.wiredConnecting = []);
2219
- const wiredDisconnecting = (context.wiredDisconnecting = []);
2219
+ const wiredDisconnecting = (context.wiredDisconnecting =
2220
+ []);
2220
2221
  for (const fieldNameOrMethod in wire) {
2221
2222
  const descriptor = wire[fieldNameOrMethod];
2222
2223
  const wireDef = WireMetaMap.get(descriptor);
@@ -2717,7 +2718,7 @@ function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
2717
2718
  }
2718
2719
 
2719
2720
  /*
2720
- * Copyright (c) 2018, salesforce.com, inc.
2721
+ * Copyright (c) 2024, Salesforce, Inc.
2721
2722
  * All rights reserved.
2722
2723
  * SPDX-License-Identifier: MIT
2723
2724
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -2911,6 +2912,296 @@ const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, baseP
2911
2912
  shared.freeze(BaseBridgeElement);
2912
2913
  shared.seal(BaseBridgeElement.prototype);
2913
2914
 
2915
+ /*
2916
+ * Copyright (c) 2018, salesforce.com, inc.
2917
+ * All rights reserved.
2918
+ * SPDX-License-Identifier: MIT
2919
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2920
+ */
2921
+ // These are only used for HMR in dev mode
2922
+ // The "pure" annotations are so that Rollup knows for sure it can remove these from prod mode
2923
+ let stylesheetsToCssContent = /*@__PURE__@*/ new WeakMap();
2924
+ let cssContentToAbortControllers = /*@__PURE__@*/ new Map();
2925
+ // Only used in LWC's Karma tests
2926
+ if (process.env.NODE_ENV === 'test-karma-lwc') {
2927
+ // Used to reset the global state between test runs
2928
+ window.__lwcResetStylesheetCache = () => {
2929
+ stylesheetsToCssContent = new WeakMap();
2930
+ cssContentToAbortControllers = new Map();
2931
+ };
2932
+ }
2933
+ function linkStylesheetToCssContentInDevMode(stylesheet, cssContent) {
2934
+ // Should never leak to prod; only used for HMR
2935
+ assertNotProd();
2936
+ let cssContents = stylesheetsToCssContent.get(stylesheet);
2937
+ if (shared.isUndefined(cssContents)) {
2938
+ cssContents = new Set();
2939
+ stylesheetsToCssContent.set(stylesheet, cssContents);
2940
+ }
2941
+ cssContents.add(cssContent);
2942
+ }
2943
+ function getOrCreateAbortControllerInDevMode(cssContent) {
2944
+ // Should never leak to prod; only used for HMR
2945
+ assertNotProd();
2946
+ let abortController = cssContentToAbortControllers.get(cssContent);
2947
+ if (shared.isUndefined(abortController)) {
2948
+ abortController = new AbortController();
2949
+ cssContentToAbortControllers.set(cssContent, abortController);
2950
+ }
2951
+ return abortController;
2952
+ }
2953
+ function getOrCreateAbortSignal(cssContent) {
2954
+ // abort controller/signal is only used for HMR in development
2955
+ if (process.env.NODE_ENV !== 'production') {
2956
+ return getOrCreateAbortControllerInDevMode(cssContent).signal;
2957
+ }
2958
+ return undefined;
2959
+ }
2960
+ function makeHostToken(token) {
2961
+ // Note: if this ever changes, update the `cssScopeTokens` returned by `@lwc/compiler`
2962
+ return `${token}-host`;
2963
+ }
2964
+ function createInlineStyleVNode(content) {
2965
+ return api.h('style', {
2966
+ key: 'style', // special key
2967
+ attrs: {
2968
+ type: 'text/css',
2969
+ },
2970
+ }, [api.t(content)]);
2971
+ }
2972
+ // TODO [#3733]: remove support for legacy scope tokens
2973
+ function updateStylesheetToken(vm, template, legacy) {
2974
+ const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
2975
+ const { stylesheets: newStylesheets } = template;
2976
+ const newStylesheetToken = legacy ? template.legacyStylesheetToken : template.stylesheetToken;
2977
+ const { stylesheets: newVmStylesheets } = vm;
2978
+ const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
2979
+ const { hasScopedStyles } = context;
2980
+ let newToken;
2981
+ let newHasTokenInClass;
2982
+ let newHasTokenInAttribute;
2983
+ // Reset the styling token applied to the host element.
2984
+ let oldToken;
2985
+ let oldHasTokenInClass;
2986
+ let oldHasTokenInAttribute;
2987
+ if (legacy) {
2988
+ oldToken = context.legacyStylesheetToken;
2989
+ oldHasTokenInClass = context.hasLegacyTokenInClass;
2990
+ oldHasTokenInAttribute = context.hasLegacyTokenInAttribute;
2991
+ }
2992
+ else {
2993
+ oldToken = context.stylesheetToken;
2994
+ oldHasTokenInClass = context.hasTokenInClass;
2995
+ oldHasTokenInAttribute = context.hasTokenInAttribute;
2996
+ }
2997
+ if (!shared.isUndefined(oldToken)) {
2998
+ if (oldHasTokenInClass) {
2999
+ getClassList(elm).remove(makeHostToken(oldToken));
3000
+ }
3001
+ if (oldHasTokenInAttribute) {
3002
+ removeAttribute(elm, makeHostToken(oldToken));
3003
+ }
3004
+ }
3005
+ // Apply the new template styling token to the host element, if the new template has any
3006
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3007
+ const hasNewStylesheets = hasStyles(newStylesheets);
3008
+ const hasNewVmStylesheets = hasStyles(newVmStylesheets);
3009
+ if (hasNewStylesheets || hasNewVmStylesheets) {
3010
+ newToken = newStylesheetToken;
3011
+ }
3012
+ // Set the new styling token on the host element
3013
+ if (!shared.isUndefined(newToken)) {
3014
+ if (hasScopedStyles) {
3015
+ getClassList(elm).add(makeHostToken(newToken));
3016
+ newHasTokenInClass = true;
3017
+ }
3018
+ if (isSyntheticShadow) {
3019
+ setAttribute(elm, makeHostToken(newToken), '');
3020
+ newHasTokenInAttribute = true;
3021
+ }
3022
+ }
3023
+ // Update the styling tokens present on the context object.
3024
+ if (legacy) {
3025
+ context.legacyStylesheetToken = newToken;
3026
+ context.hasLegacyTokenInClass = newHasTokenInClass;
3027
+ context.hasLegacyTokenInAttribute = newHasTokenInAttribute;
3028
+ }
3029
+ else {
3030
+ context.stylesheetToken = newToken;
3031
+ context.hasTokenInClass = newHasTokenInClass;
3032
+ context.hasTokenInAttribute = newHasTokenInAttribute;
3033
+ }
3034
+ }
3035
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
3036
+ const content = [];
3037
+ let root;
3038
+ for (let i = 0; i < stylesheets.length; i++) {
3039
+ let stylesheet = stylesheets[i];
3040
+ if (shared.isArray(stylesheet)) {
3041
+ shared.ArrayPush.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
3042
+ }
3043
+ else {
3044
+ if (process.env.NODE_ENV !== 'production') {
3045
+ // Check for compiler version mismatch in dev mode only
3046
+ checkVersionMismatch(stylesheet, 'stylesheet');
3047
+ // in dev-mode, we support hot swapping of stylesheet, which means that
3048
+ // the component instance might be attempting to use an old version of
3049
+ // the stylesheet, while internally, we have a replacement for it.
3050
+ stylesheet = getStyleOrSwappedStyle(stylesheet);
3051
+ }
3052
+ const isScopedCss = stylesheet[shared.KEY__SCOPED_CSS];
3053
+ if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS &&
3054
+ !isScopedCss &&
3055
+ vm.renderMode === 0 /* RenderMode.Light */) {
3056
+ logError('Unscoped CSS is not supported in Light DOM in this environment. Please use scoped CSS ' +
3057
+ '(*.scoped.css) instead of unscoped CSS (*.css). See also: https://sfdc.co/scoped-styles-light-dom');
3058
+ continue;
3059
+ }
3060
+ // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
3061
+ const scopeToken = isScopedCss ||
3062
+ (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
3063
+ ? stylesheetToken
3064
+ : undefined;
3065
+ // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
3066
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
3067
+ const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
3068
+ ? !isScopedCss
3069
+ : vm.shadowMode === 0 /* ShadowMode.Native */;
3070
+ // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
3071
+ // we use an attribute selector on the host to simulate :dir().
3072
+ let useNativeDirPseudoclass;
3073
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
3074
+ useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
3075
+ }
3076
+ else {
3077
+ // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
3078
+ // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
3079
+ if (shared.isUndefined(root)) {
3080
+ // Only calculate the root once as necessary
3081
+ root = getNearestShadowComponent(vm);
3082
+ }
3083
+ useNativeDirPseudoclass = shared.isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
3084
+ }
3085
+ const cssContent = stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass);
3086
+ if (process.env.NODE_ENV !== 'production') {
3087
+ linkStylesheetToCssContentInDevMode(stylesheet, cssContent);
3088
+ }
3089
+ shared.ArrayPush.call(content, cssContent);
3090
+ }
3091
+ }
3092
+ return content;
3093
+ }
3094
+ function getStylesheetsContent(vm, template) {
3095
+ const { stylesheets, stylesheetToken } = template;
3096
+ const { stylesheets: vmStylesheets } = vm;
3097
+ let content = [];
3098
+ if (hasStyles(stylesheets)) {
3099
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3100
+ }
3101
+ // VM (component) stylesheets apply after template stylesheets
3102
+ if (hasStyles(vmStylesheets)) {
3103
+ shared.ArrayPush.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3104
+ }
3105
+ return content;
3106
+ }
3107
+ // It might be worth caching this to avoid doing the lookup repeatedly, but
3108
+ // perf testing has not shown it to be a huge improvement yet:
3109
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
3110
+ function getNearestShadowComponent(vm) {
3111
+ let owner = vm;
3112
+ while (!shared.isNull(owner)) {
3113
+ if (owner.renderMode === 1 /* RenderMode.Shadow */) {
3114
+ return owner;
3115
+ }
3116
+ owner = owner.owner;
3117
+ }
3118
+ return owner;
3119
+ }
3120
+ /**
3121
+ * If the component that is currently being rendered uses scoped styles,
3122
+ * this returns the unique token for that scoped stylesheet. Otherwise
3123
+ * it returns null.
3124
+ * @param owner
3125
+ * @param legacy
3126
+ */
3127
+ // TODO [#3733]: remove support for legacy scope tokens
3128
+ function getScopeTokenClass(owner, legacy) {
3129
+ const { cmpTemplate, context } = owner;
3130
+ return ((context.hasScopedStyles &&
3131
+ (legacy ? cmpTemplate?.legacyStylesheetToken : cmpTemplate?.stylesheetToken)) ||
3132
+ null);
3133
+ }
3134
+ /**
3135
+ * This function returns the host style token for a custom element if it
3136
+ * exists. Otherwise it returns null.
3137
+ *
3138
+ * A host style token is applied to the component if scoped styles are used.
3139
+ * @param vnode
3140
+ */
3141
+ function getStylesheetTokenHost(vnode) {
3142
+ const { template } = getComponentInternalDef(vnode.ctor);
3143
+ const { vm } = vnode;
3144
+ const { stylesheetToken } = template;
3145
+ return !shared.isUndefined(stylesheetToken) && computeHasScopedStyles(template, vm)
3146
+ ? makeHostToken(stylesheetToken)
3147
+ : null;
3148
+ }
3149
+ function getNearestNativeShadowComponent(vm) {
3150
+ const owner = getNearestShadowComponent(vm);
3151
+ if (!shared.isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
3152
+ // Synthetic-within-native is impossible. So if the nearest shadow component is
3153
+ // synthetic, we know we won't find a native component if we go any further.
3154
+ return null;
3155
+ }
3156
+ return owner;
3157
+ }
3158
+ function createStylesheet(vm, stylesheets) {
3159
+ const { renderMode, shadowMode, renderer: { insertStylesheet }, } = vm;
3160
+ if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
3161
+ for (let i = 0; i < stylesheets.length; i++) {
3162
+ const stylesheet = stylesheets[i];
3163
+ insertStylesheet(stylesheet, undefined, getOrCreateAbortSignal(stylesheet));
3164
+ }
3165
+ }
3166
+ else if (!process.env.IS_BROWSER || vm.hydrated) {
3167
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3168
+ // This works in the client, because the stylesheets are created, and cached in the VM
3169
+ // the first time the VM renders.
3170
+ // native shadow or light DOM, SSR
3171
+ return shared.ArrayMap.call(stylesheets, createInlineStyleVNode);
3172
+ }
3173
+ else {
3174
+ // native shadow or light DOM, DOM renderer
3175
+ const root = getNearestNativeShadowComponent(vm);
3176
+ // null root means a global style
3177
+ const target = shared.isNull(root) ? undefined : root.shadowRoot;
3178
+ for (let i = 0; i < stylesheets.length; i++) {
3179
+ const stylesheet = stylesheets[i];
3180
+ insertStylesheet(stylesheet, target, getOrCreateAbortSignal(stylesheet));
3181
+ }
3182
+ }
3183
+ return null;
3184
+ }
3185
+ function unrenderStylesheet(stylesheet) {
3186
+ // should never leak to prod; only used for HMR
3187
+ assertNotProd();
3188
+ const cssContents = stylesheetsToCssContent.get(stylesheet);
3189
+ /* istanbul ignore if */
3190
+ if (shared.isUndefined(cssContents)) {
3191
+ throw new Error('Cannot unrender stylesheet which was never rendered');
3192
+ }
3193
+ for (const cssContent of cssContents) {
3194
+ const abortController = cssContentToAbortControllers.get(cssContent);
3195
+ /* istanbul ignore if */
3196
+ if (shared.isUndefined(abortController)) {
3197
+ throw new Error('Cannot find AbortController for CSS content');
3198
+ }
3199
+ abortController.abort();
3200
+ // remove association with AbortController in case stylesheet is rendered again
3201
+ cssContentToAbortControllers.delete(cssContent);
3202
+ }
3203
+ }
3204
+
2914
3205
  /*
2915
3206
  * Copyright (c) 2023, salesforce.com, inc.
2916
3207
  * All rights reserved.
@@ -3004,16 +3295,31 @@ const WeakMultiMap = supportsWeakRefs ? ModernWeakMultiMap : LegacyWeakMultiMap;
3004
3295
  * SPDX-License-Identifier: MIT
3005
3296
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3006
3297
  */
3007
- const swappedTemplateMap = new WeakMap();
3008
- const swappedComponentMap = new WeakMap();
3009
- const swappedStyleMap = new WeakMap();
3298
+ let swappedTemplateMap = /*@__PURE__@*/ new WeakMap();
3299
+ let swappedComponentMap =
3300
+ /*@__PURE__@*/ new WeakMap();
3301
+ let swappedStyleMap = /*@__PURE__@*/ new WeakMap();
3010
3302
  // The important thing here is the weak values – VMs are transient (one per component instance) and should be GC'ed,
3011
3303
  // so we don't want to create strong references to them.
3012
3304
  // The weak keys are kind of useless, because Templates, LightningElementConstructors, and StylesheetFactories are
3013
3305
  // never GC'ed. But maybe they will be someday, so we may as well use weak keys too.
3014
- const activeTemplates = new WeakMultiMap();
3015
- const activeComponents = new WeakMultiMap();
3016
- const activeStyles = new WeakMultiMap();
3306
+ // The "pure" annotations are so that Rollup knows for sure it can remove these from prod mode
3307
+ let activeTemplates = /*@__PURE__@*/ new WeakMultiMap();
3308
+ let activeComponents =
3309
+ /*@__PURE__@*/ new WeakMultiMap();
3310
+ let activeStyles = /*@__PURE__@*/ new WeakMultiMap();
3311
+ // Only used in LWC's Karma tests
3312
+ if (process.env.NODE_ENV === 'test-karma-lwc') {
3313
+ // Used to reset the global state between test runs
3314
+ window.__lwcResetHotSwaps = () => {
3315
+ swappedTemplateMap = new WeakMap();
3316
+ swappedComponentMap = new WeakMap();
3317
+ swappedStyleMap = new WeakMap();
3318
+ activeTemplates = new WeakMultiMap();
3319
+ activeComponents = new WeakMultiMap();
3320
+ activeStyles = new WeakMultiMap();
3321
+ };
3322
+ }
3017
3323
  function rehydrateHotTemplate(tpl) {
3018
3324
  const list = activeTemplates.get(tpl);
3019
3325
  for (const vm of list) {
@@ -3029,8 +3335,9 @@ function rehydrateHotTemplate(tpl) {
3029
3335
  return true;
3030
3336
  }
3031
3337
  function rehydrateHotStyle(style) {
3032
- const list = activeStyles.get(style);
3033
- for (const vm of list) {
3338
+ const activeVMs = activeStyles.get(style);
3339
+ unrenderStylesheet(style);
3340
+ for (const vm of activeVMs) {
3034
3341
  // if a style definition is swapped, we must reset
3035
3342
  // vm's template content in the next micro-task:
3036
3343
  forceRehydration(vm);
@@ -3067,6 +3374,7 @@ function rehydrateHotComponent(Ctor) {
3067
3374
  }
3068
3375
  function getTemplateOrSwappedTemplate(tpl) {
3069
3376
  assertNotProd(); // this method should never leak to prod
3377
+ // TODO [#4154]: shows stale content when swapping content back and forth multiple times
3070
3378
  const visited = new Set();
3071
3379
  while (swappedTemplateMap.has(tpl) && !visited.has(tpl)) {
3072
3380
  visited.add(tpl);
@@ -3076,6 +3384,7 @@ function getTemplateOrSwappedTemplate(tpl) {
3076
3384
  }
3077
3385
  function getComponentOrSwappedComponent(Ctor) {
3078
3386
  assertNotProd(); // this method should never leak to prod
3387
+ // TODO [#4154]: shows stale content when swapping content back and forth multiple times
3079
3388
  const visited = new Set();
3080
3389
  while (swappedComponentMap.has(Ctor) && !visited.has(Ctor)) {
3081
3390
  visited.add(Ctor);
@@ -3085,6 +3394,7 @@ function getComponentOrSwappedComponent(Ctor) {
3085
3394
  }
3086
3395
  function getStyleOrSwappedStyle(style) {
3087
3396
  assertNotProd(); // this method should never leak to prod
3397
+ // TODO [#4154]: shows stale content when swapping content back and forth multiple times
3088
3398
  const visited = new Set();
3089
3399
  while (swappedStyleMap.has(style) && !visited.has(style)) {
3090
3400
  visited.add(style);
@@ -3092,6 +3402,22 @@ function getStyleOrSwappedStyle(style) {
3092
3402
  }
3093
3403
  return style;
3094
3404
  }
3405
+ function addActiveStylesheets(stylesheets, vm) {
3406
+ if (shared.isUndefined(stylesheets) || shared.isNull(stylesheets)) {
3407
+ // Ignore non-existent stylesheets
3408
+ return;
3409
+ }
3410
+ for (const stylesheet of flattenStylesheets(stylesheets)) {
3411
+ // this is necessary because we don't hold the list of styles
3412
+ // in the vm, we only hold the selected (already swapped template)
3413
+ // but the styles attached to the template might not be the actual
3414
+ // active ones, but the swapped versions of those.
3415
+ const swappedStylesheet = getStyleOrSwappedStyle(stylesheet);
3416
+ // this will allow us to keep track of the stylesheet that are
3417
+ // being used by a hot component
3418
+ activeStyles.add(swappedStylesheet, vm);
3419
+ }
3420
+ }
3095
3421
  function setActiveVM(vm) {
3096
3422
  assertNotProd(); // this method should never leak to prod
3097
3423
  // tracking active component
@@ -3099,25 +3425,15 @@ function setActiveVM(vm) {
3099
3425
  // this will allow us to keep track of the hot components
3100
3426
  activeComponents.add(Ctor, vm);
3101
3427
  // tracking active template
3102
- const tpl = vm.cmpTemplate;
3103
- if (tpl) {
3428
+ const template = vm.cmpTemplate;
3429
+ if (!shared.isNull(template)) {
3104
3430
  // this will allow us to keep track of the templates that are
3105
3431
  // being used by a hot component
3106
- activeTemplates.add(tpl, vm);
3107
- // tracking active styles associated to template
3108
- const stylesheets = tpl.stylesheets;
3109
- if (!shared.isUndefined(stylesheets)) {
3110
- for (const stylesheet of flattenStylesheets(stylesheets)) {
3111
- // this is necessary because we don't hold the list of styles
3112
- // in the vm, we only hold the selected (already swapped template)
3113
- // but the styles attached to the template might not be the actual
3114
- // active ones, but the swapped versions of those.
3115
- const swappedStylesheet = getStyleOrSwappedStyle(stylesheet);
3116
- // this will allow us to keep track of the stylesheet that are
3117
- // being used by a hot component
3118
- activeStyles.add(swappedStylesheet, vm);
3119
- }
3120
- }
3432
+ activeTemplates.add(template, vm);
3433
+ // Tracking active styles from the template or the VM. `template.stylesheets` are implicitly associated
3434
+ // (e.g. `foo.css` associated with `foo.html`), whereas `vm.stylesheets` are from `static stylesheets`.
3435
+ addActiveStylesheets(template.stylesheets, vm);
3436
+ addActiveStylesheets(vm.stylesheets, vm);
3121
3437
  }
3122
3438
  }
3123
3439
  function swapTemplate(oldTpl, newTpl) {
@@ -3400,233 +3716,7 @@ function getComponentDef(Ctor) {
3400
3716
  }
3401
3717
 
3402
3718
  /*
3403
- * Copyright (c) 2018, salesforce.com, inc.
3404
- * All rights reserved.
3405
- * SPDX-License-Identifier: MIT
3406
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3407
- */
3408
- function makeHostToken(token) {
3409
- // Note: if this ever changes, update the `cssScopeTokens` returned by `@lwc/compiler`
3410
- return `${token}-host`;
3411
- }
3412
- function createInlineStyleVNode(content) {
3413
- return api.h('style', {
3414
- key: 'style', // special key
3415
- attrs: {
3416
- type: 'text/css',
3417
- },
3418
- }, [api.t(content)]);
3419
- }
3420
- // TODO [#3733]: remove support for legacy scope tokens
3421
- function updateStylesheetToken(vm, template, legacy) {
3422
- const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
3423
- const { stylesheets: newStylesheets } = template;
3424
- const newStylesheetToken = legacy ? template.legacyStylesheetToken : template.stylesheetToken;
3425
- const { stylesheets: newVmStylesheets } = vm;
3426
- const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3427
- const { hasScopedStyles } = context;
3428
- let newToken;
3429
- let newHasTokenInClass;
3430
- let newHasTokenInAttribute;
3431
- // Reset the styling token applied to the host element.
3432
- let oldToken;
3433
- let oldHasTokenInClass;
3434
- let oldHasTokenInAttribute;
3435
- if (legacy) {
3436
- oldToken = context.legacyStylesheetToken;
3437
- oldHasTokenInClass = context.hasLegacyTokenInClass;
3438
- oldHasTokenInAttribute = context.hasLegacyTokenInAttribute;
3439
- }
3440
- else {
3441
- oldToken = context.stylesheetToken;
3442
- oldHasTokenInClass = context.hasTokenInClass;
3443
- oldHasTokenInAttribute = context.hasTokenInAttribute;
3444
- }
3445
- if (!shared.isUndefined(oldToken)) {
3446
- if (oldHasTokenInClass) {
3447
- getClassList(elm).remove(makeHostToken(oldToken));
3448
- }
3449
- if (oldHasTokenInAttribute) {
3450
- removeAttribute(elm, makeHostToken(oldToken));
3451
- }
3452
- }
3453
- // Apply the new template styling token to the host element, if the new template has any
3454
- // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3455
- const hasNewStylesheets = hasStyles(newStylesheets);
3456
- const hasNewVmStylesheets = hasStyles(newVmStylesheets);
3457
- if (hasNewStylesheets || hasNewVmStylesheets) {
3458
- newToken = newStylesheetToken;
3459
- }
3460
- // Set the new styling token on the host element
3461
- if (!shared.isUndefined(newToken)) {
3462
- if (hasScopedStyles) {
3463
- getClassList(elm).add(makeHostToken(newToken));
3464
- newHasTokenInClass = true;
3465
- }
3466
- if (isSyntheticShadow) {
3467
- setAttribute(elm, makeHostToken(newToken), '');
3468
- newHasTokenInAttribute = true;
3469
- }
3470
- }
3471
- // Update the styling tokens present on the context object.
3472
- if (legacy) {
3473
- context.legacyStylesheetToken = newToken;
3474
- context.hasLegacyTokenInClass = newHasTokenInClass;
3475
- context.hasLegacyTokenInAttribute = newHasTokenInAttribute;
3476
- }
3477
- else {
3478
- context.stylesheetToken = newToken;
3479
- context.hasTokenInClass = newHasTokenInClass;
3480
- context.hasTokenInAttribute = newHasTokenInAttribute;
3481
- }
3482
- }
3483
- function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
3484
- const content = [];
3485
- let root;
3486
- for (let i = 0; i < stylesheets.length; i++) {
3487
- let stylesheet = stylesheets[i];
3488
- if (shared.isArray(stylesheet)) {
3489
- shared.ArrayPush.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
3490
- }
3491
- else {
3492
- if (process.env.NODE_ENV !== 'production') {
3493
- // Check for compiler version mismatch in dev mode only
3494
- checkVersionMismatch(stylesheet, 'stylesheet');
3495
- // in dev-mode, we support hot swapping of stylesheet, which means that
3496
- // the component instance might be attempting to use an old version of
3497
- // the stylesheet, while internally, we have a replacement for it.
3498
- stylesheet = getStyleOrSwappedStyle(stylesheet);
3499
- }
3500
- const isScopedCss = stylesheet[shared.KEY__SCOPED_CSS];
3501
- if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS &&
3502
- !isScopedCss &&
3503
- vm.renderMode === 0 /* RenderMode.Light */) {
3504
- logError('Unscoped CSS is not supported in Light DOM in this environment. Please use scoped CSS ' +
3505
- '(*.scoped.css) instead of unscoped CSS (*.css). See also: https://sfdc.co/scoped-styles-light-dom');
3506
- continue;
3507
- }
3508
- // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
3509
- const scopeToken = isScopedCss ||
3510
- (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
3511
- ? stylesheetToken
3512
- : undefined;
3513
- // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
3514
- // native shadow DOM. Synthetic shadow DOM never uses `:host`.
3515
- const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
3516
- ? !isScopedCss
3517
- : vm.shadowMode === 0 /* ShadowMode.Native */;
3518
- // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
3519
- // we use an attribute selector on the host to simulate :dir().
3520
- let useNativeDirPseudoclass;
3521
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
3522
- useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
3523
- }
3524
- else {
3525
- // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
3526
- // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
3527
- if (shared.isUndefined(root)) {
3528
- // Only calculate the root once as necessary
3529
- root = getNearestShadowComponent(vm);
3530
- }
3531
- useNativeDirPseudoclass = shared.isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
3532
- }
3533
- shared.ArrayPush.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
3534
- }
3535
- }
3536
- return content;
3537
- }
3538
- function getStylesheetsContent(vm, template) {
3539
- const { stylesheets, stylesheetToken } = template;
3540
- const { stylesheets: vmStylesheets } = vm;
3541
- let content = [];
3542
- if (hasStyles(stylesheets)) {
3543
- content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3544
- }
3545
- // VM (component) stylesheets apply after template stylesheets
3546
- if (hasStyles(vmStylesheets)) {
3547
- shared.ArrayPush.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3548
- }
3549
- return content;
3550
- }
3551
- // It might be worth caching this to avoid doing the lookup repeatedly, but
3552
- // perf testing has not shown it to be a huge improvement yet:
3553
- // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
3554
- function getNearestShadowComponent(vm) {
3555
- let owner = vm;
3556
- while (!shared.isNull(owner)) {
3557
- if (owner.renderMode === 1 /* RenderMode.Shadow */) {
3558
- return owner;
3559
- }
3560
- owner = owner.owner;
3561
- }
3562
- return owner;
3563
- }
3564
- /**
3565
- * If the component that is currently being rendered uses scoped styles,
3566
- * this returns the unique token for that scoped stylesheet. Otherwise
3567
- * it returns null.
3568
- * @param owner
3569
- * @param legacy
3570
- */
3571
- // TODO [#3733]: remove support for legacy scope tokens
3572
- function getScopeTokenClass(owner, legacy) {
3573
- const { cmpTemplate, context } = owner;
3574
- return ((context.hasScopedStyles &&
3575
- (legacy ? cmpTemplate?.legacyStylesheetToken : cmpTemplate?.stylesheetToken)) ||
3576
- null);
3577
- }
3578
- /**
3579
- * This function returns the host style token for a custom element if it
3580
- * exists. Otherwise it returns null.
3581
- *
3582
- * A host style token is applied to the component if scoped styles are used.
3583
- * @param vnode
3584
- */
3585
- function getStylesheetTokenHost(vnode) {
3586
- const { template } = getComponentInternalDef(vnode.ctor);
3587
- const { vm } = vnode;
3588
- const { stylesheetToken } = template;
3589
- return !shared.isUndefined(stylesheetToken) && computeHasScopedStyles(template, vm)
3590
- ? makeHostToken(stylesheetToken)
3591
- : null;
3592
- }
3593
- function getNearestNativeShadowComponent(vm) {
3594
- const owner = getNearestShadowComponent(vm);
3595
- if (!shared.isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
3596
- // Synthetic-within-native is impossible. So if the nearest shadow component is
3597
- // synthetic, we know we won't find a native component if we go any further.
3598
- return null;
3599
- }
3600
- return owner;
3601
- }
3602
- function createStylesheet(vm, stylesheets) {
3603
- const { renderMode, shadowMode, renderer: { insertStylesheet }, } = vm;
3604
- if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
3605
- for (let i = 0; i < stylesheets.length; i++) {
3606
- insertStylesheet(stylesheets[i]);
3607
- }
3608
- }
3609
- else if (!process.env.IS_BROWSER || vm.hydrated) {
3610
- // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3611
- // This works in the client, because the stylesheets are created, and cached in the VM
3612
- // the first time the VM renders.
3613
- // native shadow or light DOM, SSR
3614
- return shared.ArrayMap.call(stylesheets, createInlineStyleVNode);
3615
- }
3616
- else {
3617
- // native shadow or light DOM, DOM renderer
3618
- const root = getNearestNativeShadowComponent(vm);
3619
- // null root means a global style
3620
- const target = shared.isNull(root) ? undefined : root.shadowRoot;
3621
- for (let i = 0; i < stylesheets.length; i++) {
3622
- insertStylesheet(stylesheets[i], target);
3623
- }
3624
- }
3625
- return null;
3626
- }
3627
-
3628
- /*
3629
- * Copyright (c) 2018, salesforce.com, inc.
3719
+ * Copyright (c) 2024, Salesforce, Inc.
3630
3720
  * All rights reserved.
3631
3721
  * SPDX-License-Identifier: MIT
3632
3722
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -4146,7 +4236,7 @@ function hydrateStaticParts(vnode, renderer) {
4146
4236
  }
4147
4237
 
4148
4238
  /*
4149
- * Copyright (c) 2018, salesforce.com, inc.
4239
+ * Copyright (c) 2024, Salesforce, Inc.
4150
4240
  * All rights reserved.
4151
4241
  * SPDX-License-Identifier: MIT
4152
4242
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -4916,7 +5006,7 @@ function updateStaticChildren(c1, c2, parent, renderer) {
4916
5006
  }
4917
5007
 
4918
5008
  /*
4919
- * Copyright (c) 2018, salesforce.com, inc.
5009
+ * Copyright (c) 2024, Salesforce, Inc.
4920
5010
  * All rights reserved.
4921
5011
  * SPDX-License-Identifier: MIT
4922
5012
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -5198,6 +5288,7 @@ function i(iterable, factory) {
5198
5288
  shared.ArrayPush.apply(list, vnode);
5199
5289
  }
5200
5290
  else {
5291
+ // `isArray` doesn't narrow this block properly...
5201
5292
  shared.ArrayPush.call(list, vnode);
5202
5293
  }
5203
5294
  if (process.env.NODE_ENV !== 'production') {
@@ -5249,6 +5340,7 @@ function f(items) {
5249
5340
  shared.ArrayPush.apply(flattened, item);
5250
5341
  }
5251
5342
  else {
5343
+ // `isArray` doesn't narrow this block properly...
5252
5344
  shared.ArrayPush.call(flattened, item);
5253
5345
  }
5254
5346
  }
@@ -5578,7 +5670,7 @@ function logGlobalOperationEnd(opId, vm) {
5578
5670
  }
5579
5671
 
5580
5672
  /*
5581
- * Copyright (c) 2018, salesforce.com, inc.
5673
+ * Copyright (c) 2024, Salesforce, Inc.
5582
5674
  * All rights reserved.
5583
5675
  * SPDX-License-Identifier: MIT
5584
5676
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -7549,7 +7641,7 @@ function setHooks(hooks) {
7549
7641
  }
7550
7642
 
7551
7643
  /*
7552
- * Copyright (c) 2018, salesforce.com, inc.
7644
+ * Copyright (c) 2024, Salesforce, Inc.
7553
7645
  * All rights reserved.
7554
7646
  * SPDX-License-Identifier: MIT
7555
7647
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -7617,9 +7709,9 @@ function warnOnArrayMutation(stylesheets) {
7617
7709
  // we can at least warn when they use the most common mutation methods.
7618
7710
  for (const prop of ARRAY_MUTATION_METHODS) {
7619
7711
  const originalArrayMethod = getOriginalArrayMethod(prop);
7712
+ // Assertions used here because TypeScript can't handle mapping over our types
7620
7713
  stylesheets[prop] = function arrayMutationWarningWrapper() {
7621
7714
  reportTemplateViolation('stylesheets');
7622
- // @ts-expect-error can't properly determine the right `this`
7623
7715
  return originalArrayMethod.apply(this, arguments);
7624
7716
  };
7625
7717
  }
@@ -7848,5 +7940,5 @@ exports.swapTemplate = swapTemplate;
7848
7940
  exports.track = track;
7849
7941
  exports.unwrap = unwrap;
7850
7942
  exports.wire = wire;
7851
- /** version: 6.5.1 */
7943
+ /** version: 6.5.3 */
7852
7944
  //# sourceMappingURL=index.cjs.js.map