@contentful/experiences-visual-editor-react 1.36.0-dev-20250415T1354-5590cf8.0 → 1.36.0-dev-20250417T1301-b6204ec.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
@@ -1271,6 +1271,69 @@ var CodeNames$1;
1271
1271
  CodeNames["Custom"] = "custom";
1272
1272
  })(CodeNames$1 || (CodeNames$1 = {}));
1273
1273
 
1274
+ function getOptimizedImageUrl(url, width, quality, format) {
1275
+ if (url.startsWith('//')) {
1276
+ url = 'https:' + url;
1277
+ }
1278
+ const params = new URLSearchParams();
1279
+ if (width) {
1280
+ params.append('w', width.toString());
1281
+ }
1282
+ if (quality && quality > 0 && quality < 100) {
1283
+ params.append('q', quality.toString());
1284
+ }
1285
+ if (format) {
1286
+ params.append('fm', format);
1287
+ }
1288
+ const queryString = params.toString();
1289
+ return `${url}${queryString ? '?' + queryString : ''}`;
1290
+ }
1291
+
1292
+ function validateParams(file, quality, format) {
1293
+ if (!file.details.image) {
1294
+ throw Error('No image in file asset to transform');
1295
+ }
1296
+ if (quality < 0 || quality > 100) {
1297
+ throw Error('Quality must be between 0 and 100');
1298
+ }
1299
+ if (format && !SUPPORTED_IMAGE_FORMATS.includes(format)) {
1300
+ throw Error(`Format must be one of ${SUPPORTED_IMAGE_FORMATS.join(', ')}`);
1301
+ }
1302
+ return true;
1303
+ }
1304
+
1305
+ const MAX_WIDTH_ALLOWED$1 = 2000;
1306
+ const getOptimizedBackgroundImageAsset = (file, widthStyle, quality = '100%', format) => {
1307
+ const qualityNumber = Number(quality.replace('%', ''));
1308
+ if (!validateParams(file, qualityNumber, format)) ;
1309
+ if (!validateParams(file, qualityNumber, format)) ;
1310
+ const url = file.url;
1311
+ const { width1x, width2x } = getWidths(widthStyle, file);
1312
+ const imageUrl1x = getOptimizedImageUrl(url, width1x, qualityNumber, format);
1313
+ const imageUrl2x = getOptimizedImageUrl(url, width2x, qualityNumber, format);
1314
+ const srcSet = [`url(${imageUrl1x}) 1x`, `url(${imageUrl2x}) 2x`];
1315
+ const returnedUrl = getOptimizedImageUrl(url, width2x, qualityNumber, format);
1316
+ const optimizedBackgroundImageAsset = {
1317
+ url: returnedUrl,
1318
+ srcSet,
1319
+ file,
1320
+ };
1321
+ return optimizedBackgroundImageAsset;
1322
+ function getWidths(widthStyle, file) {
1323
+ let width1x = 0;
1324
+ let width2x = 0;
1325
+ const intrinsicImageWidth = file.details.image.width;
1326
+ if (widthStyle.endsWith('px')) {
1327
+ width1x = Math.min(Number(widthStyle.replace('px', '')), intrinsicImageWidth);
1328
+ }
1329
+ else {
1330
+ width1x = Math.min(MAX_WIDTH_ALLOWED$1, intrinsicImageWidth);
1331
+ }
1332
+ width2x = Math.min(width1x * 2, intrinsicImageWidth);
1333
+ return { width1x, width2x };
1334
+ }
1335
+ };
1336
+
1274
1337
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1275
1338
  function get(obj, path) {
1276
1339
  if (!path.length) {
@@ -1341,69 +1404,6 @@ const resolveLinks = (node, entityStore) => {
1341
1404
  }
1342
1405
  };
1343
1406
 
1344
- function getOptimizedImageUrl(url, width, quality, format) {
1345
- if (url.startsWith('//')) {
1346
- url = 'https:' + url;
1347
- }
1348
- const params = new URLSearchParams();
1349
- if (width) {
1350
- params.append('w', width.toString());
1351
- }
1352
- if (quality && quality > 0 && quality < 100) {
1353
- params.append('q', quality.toString());
1354
- }
1355
- if (format) {
1356
- params.append('fm', format);
1357
- }
1358
- const queryString = params.toString();
1359
- return `${url}${queryString ? '?' + queryString : ''}`;
1360
- }
1361
-
1362
- function validateParams(file, quality, format) {
1363
- if (!file.details.image) {
1364
- throw Error('No image in file asset to transform');
1365
- }
1366
- if (quality < 0 || quality > 100) {
1367
- throw Error('Quality must be between 0 and 100');
1368
- }
1369
- if (format && !SUPPORTED_IMAGE_FORMATS.includes(format)) {
1370
- throw Error(`Format must be one of ${SUPPORTED_IMAGE_FORMATS.join(', ')}`);
1371
- }
1372
- return true;
1373
- }
1374
-
1375
- const MAX_WIDTH_ALLOWED$1 = 2000;
1376
- const getOptimizedBackgroundImageAsset = (file, widthStyle, quality = '100%', format) => {
1377
- const qualityNumber = Number(quality.replace('%', ''));
1378
- if (!validateParams(file, qualityNumber, format)) ;
1379
- if (!validateParams(file, qualityNumber, format)) ;
1380
- const url = file.url;
1381
- const { width1x, width2x } = getWidths(widthStyle, file);
1382
- const imageUrl1x = getOptimizedImageUrl(url, width1x, qualityNumber, format);
1383
- const imageUrl2x = getOptimizedImageUrl(url, width2x, qualityNumber, format);
1384
- const srcSet = [`url(${imageUrl1x}) 1x`, `url(${imageUrl2x}) 2x`];
1385
- const returnedUrl = getOptimizedImageUrl(url, width2x, qualityNumber, format);
1386
- const optimizedBackgroundImageAsset = {
1387
- url: returnedUrl,
1388
- srcSet,
1389
- file,
1390
- };
1391
- return optimizedBackgroundImageAsset;
1392
- function getWidths(widthStyle, file) {
1393
- let width1x = 0;
1394
- let width2x = 0;
1395
- const intrinsicImageWidth = file.details.image.width;
1396
- if (widthStyle.endsWith('px')) {
1397
- width1x = Math.min(Number(widthStyle.replace('px', '')), intrinsicImageWidth);
1398
- }
1399
- else {
1400
- width1x = Math.min(MAX_WIDTH_ALLOWED$1, intrinsicImageWidth);
1401
- }
1402
- width2x = Math.min(width1x * 2, intrinsicImageWidth);
1403
- return { width1x, width2x };
1404
- }
1405
- };
1406
-
1407
1407
  const MAX_WIDTH_ALLOWED = 4000;
1408
1408
  const getOptimizedImageAsset = ({ file, sizes, loading, quality = '100%', format, }) => {
1409
1409
  const qualityNumber = Number(quality.replace('%', ''));