@contentful/experiences-core 1.23.0-dev-20241126T1532-544ff28.0 → 1.23.0-dev-20241127T2203-79f4a14.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.d.ts +1 -1
- package/dist/index.js +34 -2
- package/dist/index.js.map +1 -1
- package/dist/utils/utils.d.ts +7 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { doesMismatchMessageSchema, tryParseMessage, validateExperienceBuilderCo
|
|
|
4
4
|
export { buildCfStyles, buildStyleTag, calculateNodeDefaultHeight, toCSSAttribute } from './utils/styleUtils/stylesUtils.js';
|
|
5
5
|
export { detachExperienceStyles, flattenDesignTokenRegistry, indexByBreakpoint, isCfStyleAttribute, maybePopulateDesignTokenValue, resolveBackgroundImageBinding, toCSSString, toMediaQuery } from './utils/styleUtils/ssrStyles.js';
|
|
6
6
|
export { transformBoundContentValue } from './utils/transformers/transformBoundContentValue.js';
|
|
7
|
-
export { checkIsAssembly, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, generateRandomId, getDataFromTree, getInsertionData } from './utils/utils.js';
|
|
7
|
+
export { checkIsAssembly, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, generateRandomId, getDataFromTree, getInsertionData, getTargetValueInPixels, parseCSSValue } from './utils/utils.js';
|
|
8
8
|
export { isExperienceEntry } from './utils/typeguards.js';
|
|
9
9
|
export { MEDIA_QUERY_REGEXP, getActiveBreakpointIndex, getFallbackBreakpointIndex, getValueForBreakpoint, isValidBreakpointValue, mediaQueryMatcher } from './utils/breakpoints.js';
|
|
10
10
|
export { isLinkToAsset } from './utils/isLinkToAsset.js';
|
package/dist/index.js
CHANGED
|
@@ -2162,7 +2162,7 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
|
|
|
2162
2162
|
return;
|
|
2163
2163
|
}
|
|
2164
2164
|
if (variableName === 'cfBackgroundImageUrl') {
|
|
2165
|
-
|
|
2165
|
+
let width = resolveDesignValue(variables['cfWidth']?.type === 'DesignValue' ? variables['cfWidth'].valuesByBreakpoint : {}, 'cfWidth') || '100%';
|
|
2166
2166
|
const optionsVariableName = 'cfBackgroundImageOptions';
|
|
2167
2167
|
const options = resolveDesignValue(variables[optionsVariableName]?.type === 'DesignValue'
|
|
2168
2168
|
? variables[optionsVariableName].valuesByBreakpoint
|
|
@@ -2172,6 +2172,15 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
|
|
|
2172
2172
|
return;
|
|
2173
2173
|
}
|
|
2174
2174
|
try {
|
|
2175
|
+
// Target width (px/rem/em) will be applied to the css url if it's lower than the original image width (in px)
|
|
2176
|
+
const assetDetails = asset.fields.file?.details;
|
|
2177
|
+
const assetWidth = assetDetails?.image?.width || 0; // This is always in px
|
|
2178
|
+
const targetWidthObject = parseCSSValue(options.targetSize); // Contains value and unit (px/rem/em) so convert and then compare to assetWidth
|
|
2179
|
+
const targetValue = targetWidthObject
|
|
2180
|
+
? getTargetValueInPixels(targetWidthObject)
|
|
2181
|
+
: assetWidth;
|
|
2182
|
+
if (targetValue < assetWidth)
|
|
2183
|
+
width = `${targetValue}px`;
|
|
2175
2184
|
value = getOptimizedBackgroundImageAsset(asset.fields.file, width, options.quality, options.format);
|
|
2176
2185
|
return value;
|
|
2177
2186
|
}
|
|
@@ -2365,6 +2374,29 @@ const checkIsAssemblyEntry = (entry) => {
|
|
|
2365
2374
|
return Boolean(entry.fields?.componentSettings);
|
|
2366
2375
|
};
|
|
2367
2376
|
const checkIsAssemblyDefinition = (component) => component?.category === ASSEMBLY_DEFAULT_CATEGORY;
|
|
2377
|
+
function parseCSSValue(input) {
|
|
2378
|
+
const regex = /^(\d+(\.\d+)?)(px|em|rem)$/;
|
|
2379
|
+
const match = input.match(regex);
|
|
2380
|
+
if (match) {
|
|
2381
|
+
return {
|
|
2382
|
+
value: parseFloat(match[1]),
|
|
2383
|
+
unit: match[3],
|
|
2384
|
+
};
|
|
2385
|
+
}
|
|
2386
|
+
return null;
|
|
2387
|
+
}
|
|
2388
|
+
function getTargetValueInPixels(targetWidthObject) {
|
|
2389
|
+
switch (targetWidthObject.unit) {
|
|
2390
|
+
case 'px':
|
|
2391
|
+
return targetWidthObject.value;
|
|
2392
|
+
case 'em':
|
|
2393
|
+
return targetWidthObject.value * 16;
|
|
2394
|
+
case 'rem':
|
|
2395
|
+
return targetWidthObject.value * 16;
|
|
2396
|
+
default:
|
|
2397
|
+
return targetWidthObject.value;
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2368
2400
|
|
|
2369
2401
|
const isExperienceEntry = (entry) => {
|
|
2370
2402
|
return (entry?.sys?.type === 'Entry' &&
|
|
@@ -3617,5 +3649,5 @@ async function fetchById({ client, experienceTypeId, id, localeCode, }) {
|
|
|
3617
3649
|
}
|
|
3618
3650
|
}
|
|
3619
3651
|
|
|
3620
|
-
export { DeepReference, EditorModeEntityStore, EntityStore, EntityStoreBase, MEDIA_QUERY_REGEXP, VisualEditorMode, addLocale, breakpointsRegistry, buildCfStyles, buildStyleTag, buildTemplate, builtInStyles, calculateNodeDefaultHeight, checkIsAssembly, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, columnsBuiltInStyles, containerBuiltInStyles, createExperience, defineBreakpoints, defineDesignTokens, designTokensRegistry, detachExperienceStyles, dividerBuiltInStyles, doesMismatchMessageSchema, fetchAllAssets, fetchAllEntries, fetchById, fetchBySlug, findOutermostCoordinates, flattenDesignTokenRegistry, gatherDeepReferencesFromExperienceEntry, gatherDeepReferencesFromTree, generateRandomId, getActiveBreakpointIndex, getBreakpointRegistration, getDataFromTree, getDesignTokenRegistration, getElementCoordinates, getFallbackBreakpointIndex, getInsertionData, getTemplateValue, getValueForBreakpoint, indexByBreakpoint, isCfStyleAttribute, isComponentAllowedOnRoot, isContentfulComponent, isContentfulStructureComponent, isDeepPath, isExperienceEntry, isLink, isLinkToAsset, isPatternComponent, isStructureWithRelativeHeight, isValidBreakpointValue, lastPathNamedSegmentEq, maybePopulateDesignTokenValue, mediaQueryMatcher, optionalBuiltInStyles, parseDataSourcePathIntoFieldset, parseDataSourcePathWithL1DeepBindings, resetBreakpointsRegistry, resetDesignTokenRegistry, resolveBackgroundImageBinding, resolveHyperlinkPattern, runBreakpointsValidation, sanitizeNodeProps, sectionBuiltInStyles, sendMessage, singleColumnBuiltInStyles, toCSSAttribute, toCSSString, toMediaQuery, transformBoundContentValue, tryParseMessage, validateExperienceBuilderConfig };
|
|
3652
|
+
export { DeepReference, EditorModeEntityStore, EntityStore, EntityStoreBase, MEDIA_QUERY_REGEXP, VisualEditorMode, addLocale, breakpointsRegistry, buildCfStyles, buildStyleTag, buildTemplate, builtInStyles, calculateNodeDefaultHeight, checkIsAssembly, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, columnsBuiltInStyles, containerBuiltInStyles, createExperience, defineBreakpoints, defineDesignTokens, designTokensRegistry, detachExperienceStyles, dividerBuiltInStyles, doesMismatchMessageSchema, fetchAllAssets, fetchAllEntries, fetchById, fetchBySlug, findOutermostCoordinates, flattenDesignTokenRegistry, gatherDeepReferencesFromExperienceEntry, gatherDeepReferencesFromTree, generateRandomId, getActiveBreakpointIndex, getBreakpointRegistration, getDataFromTree, getDesignTokenRegistration, getElementCoordinates, getFallbackBreakpointIndex, getInsertionData, getTargetValueInPixels, getTemplateValue, getValueForBreakpoint, indexByBreakpoint, isCfStyleAttribute, isComponentAllowedOnRoot, isContentfulComponent, isContentfulStructureComponent, isDeepPath, isExperienceEntry, isLink, isLinkToAsset, isPatternComponent, isStructureWithRelativeHeight, isValidBreakpointValue, lastPathNamedSegmentEq, maybePopulateDesignTokenValue, mediaQueryMatcher, optionalBuiltInStyles, parseCSSValue, parseDataSourcePathIntoFieldset, parseDataSourcePathWithL1DeepBindings, resetBreakpointsRegistry, resetDesignTokenRegistry, resolveBackgroundImageBinding, resolveHyperlinkPattern, runBreakpointsValidation, sanitizeNodeProps, sectionBuiltInStyles, sendMessage, singleColumnBuiltInStyles, toCSSAttribute, toCSSString, toMediaQuery, transformBoundContentValue, tryParseMessage, validateExperienceBuilderConfig };
|
|
3621
3653
|
//# sourceMappingURL=index.js.map
|