@websolutespa/bom-mixer-ui 1.7.13 → 1.7.14

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @websolutespa/bom-mixer-ui
2
2
 
3
+ ## 1.7.14
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: Media width & height style support & source image size limits
8
+
3
9
  ## 1.7.13
4
10
 
5
11
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -4380,7 +4380,6 @@ function isMediaSizeVariants(item) {
4380
4380
  }
4381
4381
  const StyledMediaImage = styled__default.default.img`
4382
4382
  max-width: 100%;
4383
- // height: auto;
4384
4383
  user-select: none;
4385
4384
  color: transparent;
4386
4385
  `;
@@ -4402,28 +4401,29 @@ const MediaImage = _a => {
4402
4401
  'image-svg': isSVG(props.src)
4403
4402
  });
4404
4403
  const imageProps = getImageProps(props, theme.mediaQuery);
4405
- const onLoad = () => {
4406
- if (typeof onLoaded === 'function') {
4407
- onLoaded(imageRef);
4408
- }
4409
- };
4410
4404
  React.useEffect(() => {
4411
4405
  if (imageRef.current && canLoad) {
4412
- if (imageRef.current.complete) {
4406
+ const image = imageRef.current;
4407
+ if (image.complete) {
4413
4408
  if (typeof onLoaded === 'function') {
4414
4409
  onLoaded(imageRef);
4415
4410
  }
4416
4411
  } else {
4417
- imageRef.current.addEventListener('load', onLoad);
4412
+ const onLoad = () => {
4413
+ if (typeof onLoaded === 'function') {
4414
+ onLoaded(imageRef);
4415
+ }
4416
+ };
4417
+ image.addEventListener('load', onLoad);
4418
4418
  return () => {
4419
- if (imageRef.current) {
4420
- imageRef.current.removeEventListener('load', onLoad);
4419
+ if (image) {
4420
+ image.removeEventListener('load', onLoad);
4421
4421
  }
4422
4422
  };
4423
4423
  }
4424
4424
  }
4425
4425
  return () => {};
4426
- }, [imageRef, canLoad]);
4426
+ }, [canLoad, onLoaded]);
4427
4427
  return jsxRuntime.jsx(StyledMediaImage, Object.assign({
4428
4428
  ref: imageRef
4429
4429
  }, canLoad ? imageProps : undefined, {
@@ -4432,25 +4432,30 @@ const MediaImage = _a => {
4432
4432
  draggable: false
4433
4433
  }));
4434
4434
  };
4435
- function getMediaSizes(mediaQuery, ratio, size) {
4436
- // console.log('getMediaSizes', size, ratio);
4435
+ function getMediaSizes(mediaQuery, ratio, size, maxWidth, maxHeight) {
4436
+ if (maxWidth === void 0) {
4437
+ maxWidth = Number.POSITIVE_INFINITY;
4438
+ }
4439
+ if (maxHeight === void 0) {
4440
+ maxHeight = Number.POSITIVE_INFINITY;
4441
+ }
4442
+ // console.log('getMediaSizes', size, ratio, maxWidth);
4443
+ let sizes = [];
4437
4444
  if (size) {
4438
4445
  if (typeof size === 'number') {
4439
4446
  const s = size;
4440
4447
  // console.log('typeof size === \'number\'', size);
4441
- const sizes = Object.entries(ratio).map(_ref2 => {
4448
+ sizes = Object.entries(ratio).map(_ref2 => {
4442
4449
  let [k, v] = _ref2;
4443
4450
  const w = IMAGE_SIZEMAP[k];
4444
4451
  return [w && s > w ? w : s, parseInt(String(mediaQuery[k])), v];
4445
4452
  }).filter(x => x[0] >= x[1]);
4446
4453
  // console.log(size, 'sizes', sizes);
4447
- return sizes;
4448
- }
4449
- if (isMediaSizeVariant(size)) {
4454
+ } else if (isMediaSizeVariant(size)) {
4450
4455
  // console.log('isMediaSizeVariant');
4451
4456
  const sizeLimit = IMAGE_SIZEMAP[size] || 0;
4452
4457
  // console.log(size, ratio[size], sizeLimit);
4453
- return Object.entries(IMAGE_SIZEMAP).filter(_ref3 => {
4458
+ sizes = Object.entries(IMAGE_SIZEMAP).filter(_ref3 => {
4454
4459
  let [k, v] = _ref3;
4455
4460
  return v <= sizeLimit;
4456
4461
  }).map(_ref4 => {
@@ -4458,14 +4463,17 @@ function getMediaSizes(mediaQuery, ratio, size) {
4458
4463
  return [v, parseInt(String(mediaQuery[k])), ratio[k]];
4459
4464
  });
4460
4465
  }
4466
+ } else {
4467
+ size = size || IMAGE_SIZEMAP;
4468
+ // console.log('size || IMAGE_SIZEMAP', size, IMAGE_SIZEMAP);
4469
+ sizes = Object.entries(size).map(_ref5 => {
4470
+ let [k, v] = _ref5;
4471
+ return [v, parseInt(String(mediaQuery[k])), ratio[k]];
4472
+ });
4461
4473
  }
4462
- size = size || IMAGE_SIZEMAP;
4463
- // console.log('size || IMAGE_SIZEMAP', size, IMAGE_SIZEMAP);
4464
- const sizes = Object.entries(size).map(_ref5 => {
4465
- let [k, v] = _ref5;
4466
- return [v, parseInt(String(mediaQuery[k])), ratio[k]];
4467
- });
4468
4474
  // console.log(size, 'sizes', sizes, ratio);
4475
+ sizes = sizes.filter((size, i) => i === 0 || size[0] <= maxWidth && (size[2] === 0 || size[0] / size[2] <= maxHeight));
4476
+ // console.log(sizes[0][2] ? sizes[0][0] / sizes[0][2] : 0, maxHeight);
4469
4477
  return sizes;
4470
4478
  }
4471
4479
  function getImageProps(_a, mediaQuery) {
@@ -4485,18 +4493,25 @@ function getImageProps(_a, mediaQuery) {
4485
4493
  } = props,
4486
4494
  otherProps = __rest(props, ["width", "height", "size"]);
4487
4495
  let useSize = size;
4496
+ let useWidth = undefined;
4488
4497
  if (typeof width === 'string' && width.indexOf('px') !== -1) {
4489
- useSize = parseInt(width);
4498
+ useWidth = parseInt(width);
4499
+ useSize = useWidth;
4500
+ } else if (typeof width === 'number') {
4501
+ useWidth = width;
4502
+ }
4503
+ let useHeight = undefined;
4504
+ if (typeof height === 'string' && height.indexOf('px') !== -1) {
4505
+ useHeight = parseInt(height);
4506
+ } else if (typeof height === 'number') {
4507
+ useHeight = height;
4490
4508
  }
4491
- // console.log(useSize, width);
4492
4509
  const ratio = getMediaRatio(props);
4493
- const sizes = getMediaSizes(mediaQuery, ratio, useSize);
4510
+ const sizes = getMediaSizes(mediaQuery, ratio, useSize, props.mediaWidth, props.mediaHeight);
4494
4511
  const imageSrc = getImageSrc(src, sizes[0][0], sizes[0][2]);
4495
4512
  const imageSrcSet = getImageSrcset(src, sizes);
4496
4513
  const imageSizes = getImageSizes(sizes);
4497
- let useWidth = typeof width === 'string' ? parseInt(width) : width;
4498
- let useHeight = typeof height === 'string' ? parseInt(height) : height;
4499
- // console.log('width', width, 'useWidth', useWidth, 'height', height, 'useHeight', useHeight, 'useSize', useSize);
4514
+ // console.log('useSize', useSize, 'width', width, useWidth, 'height', height, useHeight);
4500
4515
  return Object.assign({
4501
4516
  src: imageSrc,
4502
4517
  srcSet: imageSrcSet,
@@ -4647,81 +4662,8 @@ const MediaItem = _ref => {
4647
4662
  item,
4648
4663
  options = {}
4649
4664
  } = _ref;
4650
- const mediaItem = React.useMemo(() => {
4651
- if (typeof item['media'] === 'object') {
4652
- item = item['media'];
4653
- }
4654
- const mediaItem = {
4655
- type: item.type,
4656
- src: item.src
4657
- };
4658
- if (item.abstract) {
4659
- mediaItem.abstract = item.abstract;
4660
- }
4661
- if (item.alt) {
4662
- mediaItem.alt = item.alt;
4663
- }
4664
- if (item.mimeType) {
4665
- mediaItem.mimeType = item.mimeType;
4666
- }
4667
- if (item.url) {
4668
- mediaItem.src = item.url;
4669
- }
4670
- if (item.title) {
4671
- mediaItem.title = item.title;
4672
- }
4673
- mediaItem.width = options.width || item.width;
4674
- mediaItem.height = options.height || item.height;
4675
- mediaItem.aspectRatio = options.aspectRatio;
4676
- mediaItem.aspectRatioSm = options.aspectRatioSm;
4677
- mediaItem.aspectRatioMd = options.aspectRatioMd;
4678
- mediaItem.aspectRatioLg = options.aspectRatioLg;
4679
- mediaItem.aspectRatioXl = options.aspectRatioXl;
4680
- mediaItem.onLoaded = options.onLoaded;
4681
- mediaItem.canLoad = options.canLoad;
4682
- return mediaItem;
4683
- }, [item, options]);
4684
- const mediaItemProps = React.useMemo(() => {
4685
- const media = __rest(mediaItem, ["width", "height", "sizes"]);
4686
- const title = media.title || options.title || media.alt || options.alt;
4687
- const alt = media.alt || options.alt || media.title || options.title;
4688
- const src = media.src || media.url || '';
4689
- const mediaItemProps = {
4690
- src,
4691
- title,
4692
- alt,
4693
- size: options.size,
4694
- onLoaded: mediaItem.onLoaded,
4695
- canLoad: mediaItem.canLoad
4696
- };
4697
- const hasGallery = options.galleryId != null && typeof options.open === 'function';
4698
- if (hasGallery) {
4699
- mediaItemProps['data-gallery'] = JSON.stringify({
4700
- galleryId: options.galleryId,
4701
- media
4702
- });
4703
- mediaItemProps.onClick = event => {
4704
- if (options.open) {
4705
- options.open(media);
4706
- }
4707
- };
4708
- }
4709
- if (bomCore.isMediaImage(media)) {
4710
- if (options.width) {
4711
- mediaItemProps.width = options.width;
4712
- }
4713
- mediaItemProps.height = options.height;
4714
- mediaItemProps.aspectRatio = options.aspectRatio;
4715
- mediaItemProps.aspectRatioSm = options.aspectRatioSm;
4716
- mediaItemProps.aspectRatioMd = options.aspectRatioMd;
4717
- mediaItemProps.aspectRatioLg = options.aspectRatioLg;
4718
- mediaItemProps.aspectRatioXl = options.aspectRatioXl;
4719
- if (options.eager) {
4720
- mediaItemProps.loading = 'eager';
4721
- }
4722
- }
4723
- return mediaItemProps;
4724
- }, [mediaItem]);
4665
+ const mediaItem = React.useMemo(() => getMediaItem(item, options), [item, options]);
4666
+ const mediaItemProps = React.useMemo(() => getMediaItemProps(mediaItem, options), [mediaItem, options]);
4725
4667
  return bomCore.isMediaVideo(mediaItem) ? jsxRuntime.jsx(MediaVideo, Object.assign({}, mediaItemProps)) : jsxRuntime.jsx(MediaImage, Object.assign({}, mediaItemProps));
4726
4668
  };
4727
4669
  const MediaItems = _ref2 => {
@@ -4735,6 +4677,87 @@ const MediaItems = _ref2 => {
4735
4677
  options: options
4736
4678
  }, m));
4737
4679
  };
4680
+ function getMediaItem(item, options) {
4681
+ if (typeof item['media'] === 'object') {
4682
+ item = item['media'];
4683
+ }
4684
+ const mediaItem = {
4685
+ type: item.type,
4686
+ src: item.src
4687
+ };
4688
+ if (item.abstract) {
4689
+ mediaItem.abstract = item.abstract;
4690
+ }
4691
+ if (item.alt) {
4692
+ mediaItem.alt = item.alt;
4693
+ }
4694
+ if (item.mimeType) {
4695
+ mediaItem.mimeType = item.mimeType;
4696
+ }
4697
+ if (item.url) {
4698
+ mediaItem.src = item.url;
4699
+ }
4700
+ if (item.title) {
4701
+ mediaItem.title = item.title;
4702
+ }
4703
+ if (typeof item.width === 'number') {
4704
+ mediaItem.mediaWidth = item.width;
4705
+ }
4706
+ if (typeof item.height === 'number') {
4707
+ mediaItem.mediaHeight = item.height;
4708
+ }
4709
+ mediaItem.width = options.width;
4710
+ mediaItem.height = options.height;
4711
+ mediaItem.aspectRatio = options.aspectRatio;
4712
+ mediaItem.aspectRatioSm = options.aspectRatioSm;
4713
+ mediaItem.aspectRatioMd = options.aspectRatioMd;
4714
+ mediaItem.aspectRatioLg = options.aspectRatioLg;
4715
+ mediaItem.aspectRatioXl = options.aspectRatioXl;
4716
+ mediaItem.onLoaded = options.onLoaded;
4717
+ mediaItem.canLoad = options.canLoad;
4718
+ return mediaItem;
4719
+ }
4720
+ function getMediaItemProps(mediaItem, options) {
4721
+ const media = __rest(mediaItem, ["width", "height", "sizes"]);
4722
+ const title = media.title || options.title || media.alt || options.alt;
4723
+ const alt = media.alt || options.alt || media.title || options.title;
4724
+ const src = media.src || media.url || '';
4725
+ const mediaItemProps = {
4726
+ src,
4727
+ title,
4728
+ alt,
4729
+ size: options.size,
4730
+ onLoaded: mediaItem.onLoaded,
4731
+ canLoad: mediaItem.canLoad
4732
+ };
4733
+ const hasGallery = options.galleryId != null && typeof options.open === 'function';
4734
+ if (hasGallery) {
4735
+ mediaItemProps['data-gallery'] = JSON.stringify({
4736
+ galleryId: options.galleryId,
4737
+ media
4738
+ });
4739
+ mediaItemProps.onClick = event => {
4740
+ if (options.open) {
4741
+ options.open(media);
4742
+ }
4743
+ };
4744
+ }
4745
+ if (bomCore.isMediaImage(media)) {
4746
+ mediaItemProps.mediaWidth = mediaItem.mediaWidth;
4747
+ mediaItemProps.mediaHeight = mediaItem.mediaHeight;
4748
+ mediaItemProps.width = options.width;
4749
+ mediaItemProps.height = options.height;
4750
+ mediaItemProps.aspectRatio = options.aspectRatio;
4751
+ mediaItemProps.aspectRatioSm = options.aspectRatioSm;
4752
+ mediaItemProps.aspectRatioMd = options.aspectRatioMd;
4753
+ mediaItemProps.aspectRatioLg = options.aspectRatioLg;
4754
+ mediaItemProps.aspectRatioXl = options.aspectRatioXl;
4755
+ if (options.eager) {
4756
+ mediaItemProps.loading = 'eager';
4757
+ }
4758
+ }
4759
+ return mediaItemProps;
4760
+ }
4738
4761
 
4739
4762
  const StyledMediaInfo = styled__default.default.div`
4740
4763
  position: absolute;
@@ -4836,7 +4859,7 @@ const StyledMedia$1 = styled__default.default.div`
4836
4859
  left: 0;
4837
4860
  width: 100%;
4838
4861
  height: 100%;
4839
- ${typeof props.overlay === 'number' ? `background: rgba(0,0,0,${props.overlay});` : `background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.1) 15.9%, rgba(0, 0, 0, 0) 41.67%, rgba(0, 0, 0, 0.1) 61.79%, rgba(0, 0, 0, 0.6) 100%);`}
4862
+ ${typeof props.overlay === 'number' ? `background: rgba(0,0,0,${props.overlay});` : 'background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.1) 15.9%, rgba(0, 0, 0, 0) 41.67%, rgba(0, 0, 0, 0.1) 61.79%, rgba(0, 0, 0, 0.6) 100%);'}
4840
4863
  }
4841
4864
  ` : ''}
4842
4865
  `;
@@ -4865,10 +4888,10 @@ const MediaBase = /*#__PURE__*/React.forwardRef((_a, ref) => {
4865
4888
  'media--gallery': id
4866
4889
  });
4867
4890
  const style = {};
4868
- if (typeof width === 'string' && width.indexOf('px') !== -1) {
4891
+ if (typeof width === 'string') {
4869
4892
  style.width = width;
4870
4893
  }
4871
- if (typeof height === 'string' && height.indexOf('px') !== -1) {
4894
+ if (typeof height === 'string') {
4872
4895
  style.height = height;
4873
4896
  }
4874
4897
  return jsxRuntime.jsx(StyledMedia$1, Object.assign({