@websolutespa/bom-mixer-ui 1.7.0 → 1.7.1
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/CHANGELOG.md +8 -0
- package/dist/cjs/index.js +153 -31
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/media/media-image.js +120 -22
- package/dist/esm/components/media/media-image.js.map +1 -1
- package/dist/esm/components/media/media.js +35 -12
- package/dist/esm/components/media/media.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/types/components/media/media-image.d.ts +11 -2
- package/dist/types/components/media/media-image.d.ts.map +1 -1
- package/dist/types/components/media/media.d.ts +17 -5
- package/dist/types/components/media/media.d.ts.map +1 -1
- package/dist/types/forms/radio-card/radio-card-base.d.ts +1 -0
- package/dist/types/forms/radio-card/radio-card-base.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/media/media-image.tsx +153 -73
- package/src/components/media/media.tsx +57 -18
package/CHANGELOG.md
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -11,6 +11,7 @@ var reactDom = require('react-dom');
|
|
|
11
11
|
var bomMixerIcons = require('@websolutespa/bom-mixer-icons');
|
|
12
12
|
var swiperCss = require('!!raw-loader!swiper/css');
|
|
13
13
|
var react = require('swiper/react');
|
|
14
|
+
var bomMixerStore = require('@websolutespa/bom-mixer-store');
|
|
14
15
|
var bomMixerModels = require('@websolutespa/bom-mixer-models');
|
|
15
16
|
var Head = require('next/head');
|
|
16
17
|
var router = require('next/router');
|
|
@@ -4326,15 +4327,31 @@ exports.ImageStrategy = void 0;
|
|
|
4326
4327
|
(function (ImageStrategy) {
|
|
4327
4328
|
ImageStrategy["None"] = "none";
|
|
4328
4329
|
ImageStrategy["Next"] = "next";
|
|
4330
|
+
ImageStrategy["Mixer"] = "mixer";
|
|
4331
|
+
ImageStrategy["Oven"] = "oven";
|
|
4329
4332
|
ImageStrategy["Custom"] = "custom";
|
|
4330
4333
|
})(exports.ImageStrategy || (exports.ImageStrategy = {}));
|
|
4331
|
-
const
|
|
4334
|
+
const IMAGE_SIZE_VARIANTS = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
4332
4335
|
const IMAGE_SIZES = process.env.IMAGE_SIZES ? process.env.IMAGE_SIZES.split(',').map(x => parseInt(x)) : [640, 828, 1080, 1200, 1920];
|
|
4333
|
-
const
|
|
4336
|
+
const IMAGE_SIZEMAP = Object.fromEntries(IMAGE_SIZES.map((x, i) => [IMAGE_SIZE_VARIANTS[i], x]));
|
|
4337
|
+
const IMAGE_QUALITY = process.env.IMAGE_QUALITY ? parseInt(process.env.IMAGE_QUALITY) : 80;
|
|
4338
|
+
const IMAGE_STRATEGY = process.env.IMAGE_STRATEGY ? process.env.IMAGE_STRATEGY : exports.ImageStrategy.Mixer;
|
|
4339
|
+
function isMediaSizeVariant(item) {
|
|
4340
|
+
return typeof item === 'string';
|
|
4341
|
+
// return typeof item === 'string' && IMAGE_SIZE_VARIANTS.includes(item);
|
|
4342
|
+
}
|
|
4343
|
+
function isMediaSizeVariants(item) {
|
|
4344
|
+
return bomCore.isObject(item) && Object.entries(item).reduce((p, _ref) => {
|
|
4345
|
+
let [k, v] = _ref;
|
|
4346
|
+
return p && typeof v === 'number';
|
|
4347
|
+
}, true);
|
|
4348
|
+
// return Array.isArray(item) && item.length > 0 && item.reduce((p, c) => p && typeof c === 'number', true);
|
|
4349
|
+
}
|
|
4334
4350
|
const StyledMediaImage = styled__default.default.img`
|
|
4335
4351
|
max-width: 100%;
|
|
4336
4352
|
// height: auto;
|
|
4337
4353
|
user-select: none;
|
|
4354
|
+
color: transparent;
|
|
4338
4355
|
`;
|
|
4339
4356
|
const MediaImage = _a => {
|
|
4340
4357
|
var {
|
|
@@ -4343,53 +4360,133 @@ const MediaImage = _a => {
|
|
|
4343
4360
|
loading = 'lazy'
|
|
4344
4361
|
} = _a,
|
|
4345
4362
|
props = __rest(_a, ["className", "type", "loading"]);
|
|
4346
|
-
const
|
|
4363
|
+
const theme = React.useContext(styled.ThemeContext);
|
|
4364
|
+
if (!theme) {
|
|
4365
|
+
throw new Error('MediaImage must be used within ThemeProvider');
|
|
4366
|
+
}
|
|
4367
|
+
const classNames = bomCore.getClassNames(className, 'image', props.src && {
|
|
4347
4368
|
'image-svg': isSVG(props.src)
|
|
4348
4369
|
});
|
|
4349
|
-
const imageProps = getImageProps(props);
|
|
4370
|
+
const imageProps = getImageProps(props, theme.mediaQuery);
|
|
4350
4371
|
return jsxRuntime.jsx(StyledMediaImage, Object.assign({
|
|
4351
4372
|
className: classNames,
|
|
4352
4373
|
loading: loading
|
|
4353
|
-
}, imageProps
|
|
4374
|
+
}, imageProps, {
|
|
4375
|
+
draggable: "false",
|
|
4376
|
+
decoding: "async"
|
|
4377
|
+
}));
|
|
4354
4378
|
};
|
|
4355
|
-
function
|
|
4379
|
+
function getMediaSizes(mediaQuery, ratio, size) {
|
|
4380
|
+
if (size) {
|
|
4381
|
+
if (typeof size === 'number') {
|
|
4382
|
+
return Object.entries(ratio).map(_ref2 => {
|
|
4383
|
+
let [k, v] = _ref2;
|
|
4384
|
+
return [size, parseInt(String(mediaQuery[k])), v];
|
|
4385
|
+
});
|
|
4386
|
+
}
|
|
4387
|
+
if (isMediaSizeVariant(size)) {
|
|
4388
|
+
const sizeLimit = IMAGE_SIZEMAP[size] || 0;
|
|
4389
|
+
// console.log(size, ratio[size], sizeLimit);
|
|
4390
|
+
return Object.entries(IMAGE_SIZEMAP).filter(_ref3 => {
|
|
4391
|
+
let [k, v] = _ref3;
|
|
4392
|
+
return v <= sizeLimit;
|
|
4393
|
+
}).map(_ref4 => {
|
|
4394
|
+
let [k, v] = _ref4;
|
|
4395
|
+
return [v, parseInt(String(mediaQuery[k])), ratio[k]];
|
|
4396
|
+
});
|
|
4397
|
+
}
|
|
4398
|
+
}
|
|
4399
|
+
size = size || IMAGE_SIZEMAP;
|
|
4400
|
+
return Object.entries(size).map(_ref5 => {
|
|
4401
|
+
let [k, v] = _ref5;
|
|
4402
|
+
return [v, parseInt(String(mediaQuery[k])), ratio[k]];
|
|
4403
|
+
});
|
|
4404
|
+
}
|
|
4405
|
+
function getImageProps(_a, mediaQuery) {
|
|
4356
4406
|
var {
|
|
4357
4407
|
src
|
|
4358
4408
|
} = _a,
|
|
4359
4409
|
props = __rest(_a, ["src"]);
|
|
4360
|
-
if (IMAGE_STRATEGY === exports.ImageStrategy.None || isSVG(src)) {
|
|
4410
|
+
if (IMAGE_STRATEGY === exports.ImageStrategy.None || !src || isSVG(src)) {
|
|
4361
4411
|
return Object.assign({
|
|
4362
4412
|
src
|
|
4363
4413
|
}, props);
|
|
4364
4414
|
}
|
|
4365
|
-
const
|
|
4366
|
-
|
|
4415
|
+
const {
|
|
4416
|
+
width,
|
|
4417
|
+
height,
|
|
4418
|
+
size
|
|
4419
|
+
} = props,
|
|
4420
|
+
otherProps = __rest(props, ["width", "height", "size"]);
|
|
4421
|
+
const ratio = getMediaRatio(props);
|
|
4422
|
+
const sizes = getMediaSizes(mediaQuery, ratio, size);
|
|
4423
|
+
const imageSrc = getImageSrc(src, sizes[0][0], sizes[0][2]);
|
|
4424
|
+
const imageSrcSet = getImageSrcset(src, sizes);
|
|
4425
|
+
const imageSizes = getImageSizes(sizes);
|
|
4367
4426
|
return Object.assign({
|
|
4368
|
-
src:
|
|
4369
|
-
srcSet:
|
|
4370
|
-
sizes:
|
|
4371
|
-
},
|
|
4427
|
+
src: imageSrc,
|
|
4428
|
+
srcSet: imageSrcSet,
|
|
4429
|
+
sizes: imageSizes
|
|
4430
|
+
}, otherProps);
|
|
4431
|
+
}
|
|
4432
|
+
function getMediaRatio(props) {
|
|
4433
|
+
let width = undefined;
|
|
4434
|
+
let height = undefined;
|
|
4435
|
+
if (props.width) {
|
|
4436
|
+
width = parseInt(String(props.width));
|
|
4437
|
+
}
|
|
4438
|
+
props.width = width;
|
|
4439
|
+
if (props.height) {
|
|
4440
|
+
height = parseInt(String(props.height));
|
|
4441
|
+
}
|
|
4442
|
+
props.height = height;
|
|
4443
|
+
const defaultRatio = width && height ? width / height : 0;
|
|
4444
|
+
const xs = getRatio(props.aspectRatio, defaultRatio);
|
|
4445
|
+
const sm = getRatio(props.aspectRatioSm, xs);
|
|
4446
|
+
const md = getRatio(props.aspectRatioMd, sm);
|
|
4447
|
+
const lg = getRatio(props.aspectRatioLg, md);
|
|
4448
|
+
const xl = getRatio(props.aspectRatioXl, lg);
|
|
4449
|
+
const ratio = {
|
|
4450
|
+
xs,
|
|
4451
|
+
sm,
|
|
4452
|
+
md,
|
|
4453
|
+
lg,
|
|
4454
|
+
xl
|
|
4455
|
+
};
|
|
4456
|
+
return ratio;
|
|
4457
|
+
}
|
|
4458
|
+
function getRatio(aspectRatio, defaultRatio) {
|
|
4459
|
+
if (defaultRatio === void 0) {
|
|
4460
|
+
defaultRatio = 0;
|
|
4461
|
+
}
|
|
4462
|
+
return typeof aspectRatio === 'string' ? parseFloat(aspectRatio) : aspectRatio || defaultRatio;
|
|
4372
4463
|
}
|
|
4373
|
-
|
|
4464
|
+
const BASE_URLS = {
|
|
4465
|
+
[exports.ImageStrategy.Mixer]: '/api/_image',
|
|
4466
|
+
[exports.ImageStrategy.Next]: '/_next/image',
|
|
4467
|
+
[exports.ImageStrategy.Oven]: bomMixerStore.getRemoteApiUrl('/_image')
|
|
4468
|
+
};
|
|
4469
|
+
const BASE_URL = BASE_URLS[IMAGE_STRATEGY];
|
|
4470
|
+
function getImageSrc(src, width, ratio, quality) {
|
|
4374
4471
|
if (quality === void 0) {
|
|
4375
4472
|
quality = IMAGE_QUALITY;
|
|
4376
4473
|
}
|
|
4377
4474
|
if (isSVG(src)) {
|
|
4378
4475
|
return src;
|
|
4379
4476
|
}
|
|
4380
|
-
return ratio !== 0 ?
|
|
4477
|
+
return ratio !== 0 ? `${BASE_URL}?url=${encodeURIComponent(src)}&w=${width}&h=${Math.round(width / ratio)}&q=${quality}` : `${BASE_URL}?url=${encodeURIComponent(src)}&w=${width}&q=${quality}`;
|
|
4381
4478
|
}
|
|
4382
|
-
function getImageSrcset(src,
|
|
4479
|
+
function getImageSrcset(src, sizes, quality) {
|
|
4383
4480
|
if (quality === void 0) {
|
|
4384
4481
|
quality = IMAGE_QUALITY;
|
|
4385
4482
|
}
|
|
4386
4483
|
if (isSVG(src)) {
|
|
4387
4484
|
return undefined;
|
|
4388
4485
|
}
|
|
4389
|
-
return
|
|
4486
|
+
return sizes.length > 1 ? sizes.map(size => getImageSrc(src, size[0], size[2], quality) + ` ${size[0]}w`).join(', ') : undefined;
|
|
4390
4487
|
}
|
|
4391
|
-
function getImageSizes(
|
|
4392
|
-
return
|
|
4488
|
+
function getImageSizes(sizes) {
|
|
4489
|
+
return sizes.length > 1 ? sizes.map((size, i) => `${i < sizes.length - 1 ? `(max-width: ${sizes[i + 1][1]}px) ` : ''}${size[0]}px`).join(', ') : undefined;
|
|
4393
4490
|
}
|
|
4394
4491
|
function isSVG(src) {
|
|
4395
4492
|
return src.indexOf('.svg') !== -1;
|
|
@@ -4440,7 +4537,7 @@ const StyledMedia$1 = styled__default.default.div`
|
|
|
4440
4537
|
&>video,
|
|
4441
4538
|
&>.video {
|
|
4442
4539
|
object-fit: cover;
|
|
4443
|
-
background: var(--color-neutral-200);
|
|
4540
|
+
background: transparent; // var(--color-neutral-200);
|
|
4444
4541
|
}
|
|
4445
4542
|
|
|
4446
4543
|
&>svg {
|
|
@@ -4506,12 +4603,15 @@ const MediaBase = /*#__PURE__*/React.forwardRef((_a, ref) => {
|
|
|
4506
4603
|
item,
|
|
4507
4604
|
onClick,
|
|
4508
4605
|
className,
|
|
4606
|
+
size,
|
|
4607
|
+
width,
|
|
4608
|
+
height,
|
|
4509
4609
|
eager,
|
|
4510
4610
|
alt,
|
|
4511
4611
|
title,
|
|
4512
4612
|
as = 'div'
|
|
4513
4613
|
} = _a,
|
|
4514
|
-
props = __rest(_a, ["children", "item", "onClick", "className", "eager", "alt", "title", "as"]);
|
|
4614
|
+
props = __rest(_a, ["children", "item", "onClick", "className", "size", "width", "height", "eager", "alt", "title", "as"]);
|
|
4515
4615
|
const {
|
|
4516
4616
|
locale
|
|
4517
4617
|
} = bomMixerHooks.useLayout();
|
|
@@ -4523,6 +4623,14 @@ const MediaBase = /*#__PURE__*/React.forwardRef((_a, ref) => {
|
|
|
4523
4623
|
'media--gallery': id
|
|
4524
4624
|
});
|
|
4525
4625
|
const mediaChildren = item && !children ? getMediaItems(item, {
|
|
4626
|
+
width,
|
|
4627
|
+
height,
|
|
4628
|
+
size,
|
|
4629
|
+
aspectRatio: props.aspectRatio,
|
|
4630
|
+
aspectRatioSm: props.aspectRatioSm,
|
|
4631
|
+
aspectRatioMd: props.aspectRatioMd,
|
|
4632
|
+
aspectRatioLg: props.aspectRatioLg,
|
|
4633
|
+
aspectRatioXl: props.aspectRatioXl,
|
|
4526
4634
|
eager,
|
|
4527
4635
|
galleryId: id,
|
|
4528
4636
|
alt,
|
|
@@ -4574,27 +4682,34 @@ function getMediaItems(itemOrItems, options) {
|
|
|
4574
4682
|
if (x.alt) {
|
|
4575
4683
|
mediaItem.alt = x.alt;
|
|
4576
4684
|
}
|
|
4577
|
-
if (x.height) {
|
|
4578
|
-
mediaItem.height = x.height;
|
|
4579
|
-
}
|
|
4580
4685
|
if (x.mimeType) {
|
|
4581
4686
|
mediaItem.mimeType = x.mimeType;
|
|
4582
4687
|
}
|
|
4583
4688
|
if (x.title) {
|
|
4584
4689
|
mediaItem.title = x.title;
|
|
4585
4690
|
}
|
|
4586
|
-
if (
|
|
4691
|
+
if (options.width) {
|
|
4692
|
+
mediaItem.width = parseInt(String(options.width));
|
|
4693
|
+
} else if (x.width) {
|
|
4587
4694
|
mediaItem.width = x.width;
|
|
4588
4695
|
}
|
|
4696
|
+
if (options.height) {
|
|
4697
|
+
mediaItem.height = parseInt(String(options.height));
|
|
4698
|
+
} else if (x.height) {
|
|
4699
|
+
mediaItem.height = x.height;
|
|
4700
|
+
}
|
|
4589
4701
|
return mediaItem;
|
|
4590
4702
|
});
|
|
4591
4703
|
const hasGallery = options.galleryId != null && typeof options.open === 'function';
|
|
4592
4704
|
const getMediaItemProps = media => {
|
|
4593
4705
|
const title = media.title || options.title || media.alt || options.alt;
|
|
4594
4706
|
const alt = media.alt || options.alt || media.title || options.title;
|
|
4707
|
+
const src = media.src || media.url || '';
|
|
4595
4708
|
const props = {
|
|
4709
|
+
src,
|
|
4596
4710
|
title,
|
|
4597
|
-
alt
|
|
4711
|
+
alt,
|
|
4712
|
+
size: options.size
|
|
4598
4713
|
};
|
|
4599
4714
|
if (hasGallery) {
|
|
4600
4715
|
props['data-gallery'] = JSON.stringify({
|
|
@@ -4608,11 +4723,16 @@ function getMediaItems(itemOrItems, options) {
|
|
|
4608
4723
|
};
|
|
4609
4724
|
}
|
|
4610
4725
|
if (bomCore.resolveMediaType(media) === 'image') {
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4726
|
+
let width = undefined;
|
|
4727
|
+
let height = undefined;
|
|
4728
|
+
if (options.width) {
|
|
4729
|
+
width = parseInt(String(options.width));
|
|
4730
|
+
}
|
|
4731
|
+
props.width = width;
|
|
4732
|
+
if (options.height) {
|
|
4733
|
+
height = parseInt(String(options.height));
|
|
4615
4734
|
}
|
|
4735
|
+
props.height = height;
|
|
4616
4736
|
if (options.eager) {
|
|
4617
4737
|
props.loading = 'eager';
|
|
4618
4738
|
}
|
|
@@ -4635,7 +4755,7 @@ function getMediaItems(itemOrItems, options) {
|
|
|
4635
4755
|
srcLang: options.locale,
|
|
4636
4756
|
label: "Video Captions"
|
|
4637
4757
|
})]
|
|
4638
|
-
}), m) : jsxRuntime.jsx(MediaImage, Object.assign({
|
|
4758
|
+
}), m) : jsxRuntime.jsx(MediaImage, Object.assign({
|
|
4639
4759
|
draggable: false
|
|
4640
4760
|
}, getMediaItemProps(media)), m));
|
|
4641
4761
|
}
|
|
@@ -20457,6 +20577,8 @@ exports.isCSSNumberValue = isCSSNumberValue;
|
|
|
20457
20577
|
exports.isChildElement = isChildElement;
|
|
20458
20578
|
exports.isCssProp = isCssProp;
|
|
20459
20579
|
exports.isMac = isMac;
|
|
20580
|
+
exports.isMediaSizeVariant = isMediaSizeVariant;
|
|
20581
|
+
exports.isMediaSizeVariants = isMediaSizeVariants;
|
|
20460
20582
|
exports.isMixerElement = isMixerElement;
|
|
20461
20583
|
exports.labelVariants = labelVariants;
|
|
20462
20584
|
exports.mapChildsByType = mapChildsByType;
|