@websolutespa/bom-mixer-ui 1.8.3 → 1.8.5
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 +14 -0
- package/dist/cjs/index.js +98 -70
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/media/media-image.js +92 -65
- package/dist/esm/components/media/media-image.js.map +1 -1
- package/dist/esm/components/media/media-video.js +3 -2
- package/dist/esm/components/media/media-video.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/types/components/media/media-image.d.ts +1 -8
- package/dist/types/components/media/media-image.d.ts.map +1 -1
- package/dist/types/components/media/media-video.d.ts +1 -1
- package/dist/types/components/media/media-video.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/media/media-image.tsx +74 -60
- package/src/components/media/media-video.tsx +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @websolutespa/bom-mixer-ui
|
|
2
2
|
|
|
3
|
+
## 1.8.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Modified: getImageSrc handling latin1 src
|
|
8
|
+
|
|
9
|
+
## 1.8.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Added: ImageStrategy.Token
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @websolutespa/bom-core@1.8.4
|
|
16
|
+
|
|
3
17
|
## 1.8.3
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -4402,21 +4402,13 @@ function useMediaGalleryContext() {
|
|
|
4402
4402
|
return React.useContext(MediaGalleryContext);
|
|
4403
4403
|
}
|
|
4404
4404
|
|
|
4405
|
-
exports.ImageStrategy = void 0;
|
|
4406
|
-
(function (ImageStrategy) {
|
|
4407
|
-
ImageStrategy["None"] = "none";
|
|
4408
|
-
ImageStrategy["Next"] = "next";
|
|
4409
|
-
ImageStrategy["Mixer"] = "mixer";
|
|
4410
|
-
ImageStrategy["Oven"] = "oven";
|
|
4411
|
-
ImageStrategy["Custom"] = "custom";
|
|
4412
|
-
})(exports.ImageStrategy || (exports.ImageStrategy = {}));
|
|
4413
4405
|
const IMAGE_SIZE_VARIANTS = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
4414
4406
|
const IMAGE_SIZES = process.env.IMAGE_SIZES ? process.env.IMAGE_SIZES.split(',').map(x => parseInt(x)) : [750, 960, 1440, 1600, 1920];
|
|
4415
4407
|
const IMAGE_SIZEMAP = Object.fromEntries(IMAGE_SIZES.map((x, i) => [IMAGE_SIZE_VARIANTS[i], x]));
|
|
4416
4408
|
const IMAGE_FOCAL_X = 50;
|
|
4417
4409
|
const IMAGE_FOCAL_Y = 50;
|
|
4418
4410
|
const IMAGE_QUALITY = process.env.IMAGE_QUALITY ? parseInt(process.env.IMAGE_QUALITY) : 90;
|
|
4419
|
-
const IMAGE_STRATEGY = process.env.IMAGE_STRATEGY ? process.env.IMAGE_STRATEGY :
|
|
4411
|
+
const IMAGE_STRATEGY = process.env.IMAGE_STRATEGY ? process.env.IMAGE_STRATEGY : bomCore.ImageStrategy.Mixer;
|
|
4420
4412
|
function isMediaSizeVariant(item) {
|
|
4421
4413
|
return typeof item === 'string';
|
|
4422
4414
|
// return typeof item === 'string' && IMAGE_SIZE_VARIANTS.includes(item);
|
|
@@ -4433,55 +4425,6 @@ const StyledMediaImage = styled__default.default.img`
|
|
|
4433
4425
|
user-select: none;
|
|
4434
4426
|
color: transparent;
|
|
4435
4427
|
`;
|
|
4436
|
-
const MediaImage = _a => {
|
|
4437
|
-
var {
|
|
4438
|
-
className,
|
|
4439
|
-
type,
|
|
4440
|
-
loading = 'lazy',
|
|
4441
|
-
onLoaded,
|
|
4442
|
-
canLoad = true
|
|
4443
|
-
} = _a,
|
|
4444
|
-
props = __rest(_a, ["className", "type", "loading", "onLoaded", "canLoad"]);
|
|
4445
|
-
const theme = React.useContext(styled.ThemeContext);
|
|
4446
|
-
if (!theme) {
|
|
4447
|
-
throw new Error('MediaImage must be used within ThemeProvider');
|
|
4448
|
-
}
|
|
4449
|
-
const imageRef = React.useRef(null);
|
|
4450
|
-
const classNames = bomCore.getClassNames(className, 'image', props.src && {
|
|
4451
|
-
'image-svg': isSVG(props.src)
|
|
4452
|
-
});
|
|
4453
|
-
const imageProps = getImageProps(props, theme.mediaQuery);
|
|
4454
|
-
React.useEffect(() => {
|
|
4455
|
-
if (imageRef.current && canLoad) {
|
|
4456
|
-
const image = imageRef.current;
|
|
4457
|
-
if (image.complete) {
|
|
4458
|
-
if (typeof onLoaded === 'function') {
|
|
4459
|
-
onLoaded(imageRef);
|
|
4460
|
-
}
|
|
4461
|
-
} else {
|
|
4462
|
-
const onLoad = () => {
|
|
4463
|
-
if (typeof onLoaded === 'function') {
|
|
4464
|
-
onLoaded(imageRef);
|
|
4465
|
-
}
|
|
4466
|
-
};
|
|
4467
|
-
image.addEventListener('load', onLoad);
|
|
4468
|
-
return () => {
|
|
4469
|
-
if (image) {
|
|
4470
|
-
image.removeEventListener('load', onLoad);
|
|
4471
|
-
}
|
|
4472
|
-
};
|
|
4473
|
-
}
|
|
4474
|
-
}
|
|
4475
|
-
return () => {};
|
|
4476
|
-
}, [canLoad, onLoaded]);
|
|
4477
|
-
return jsxRuntime.jsx(StyledMediaImage, Object.assign({
|
|
4478
|
-
ref: imageRef
|
|
4479
|
-
}, canLoad ? imageProps : undefined, {
|
|
4480
|
-
className: classNames,
|
|
4481
|
-
loading: loading,
|
|
4482
|
-
draggable: false
|
|
4483
|
-
}));
|
|
4484
|
-
};
|
|
4485
4428
|
function getMediaSizes(mediaQuery, ratio, size, maxWidth, maxHeight) {
|
|
4486
4429
|
if (maxWidth === void 0) {
|
|
4487
4430
|
maxWidth = Number.POSITIVE_INFINITY;
|
|
@@ -4531,7 +4474,7 @@ function getImageProps(_a, mediaQuery) {
|
|
|
4531
4474
|
src
|
|
4532
4475
|
} = _a,
|
|
4533
4476
|
props = __rest(_a, ["src"]);
|
|
4534
|
-
if (IMAGE_STRATEGY ===
|
|
4477
|
+
if (IMAGE_STRATEGY === bomCore.ImageStrategy.None || !src || isSVG(src)) {
|
|
4535
4478
|
return Object.assign({
|
|
4536
4479
|
src
|
|
4537
4480
|
}, props);
|
|
@@ -4594,11 +4537,26 @@ function getRatio(aspectRatio, defaultRatio) {
|
|
|
4594
4537
|
return typeof aspectRatio === 'string' ? parseFloat(aspectRatio) : aspectRatio || defaultRatio;
|
|
4595
4538
|
}
|
|
4596
4539
|
const BASE_URLS = {
|
|
4597
|
-
[
|
|
4598
|
-
[
|
|
4599
|
-
[
|
|
4540
|
+
[bomCore.ImageStrategy.Mixer]: '/api/_image',
|
|
4541
|
+
[bomCore.ImageStrategy.Token]: '/api/_image',
|
|
4542
|
+
[bomCore.ImageStrategy.Next]: '/_next/image',
|
|
4543
|
+
[bomCore.ImageStrategy.Oven]: bomMixerStore.getRemoteApiUrl('/_image')
|
|
4600
4544
|
};
|
|
4601
4545
|
const BASE_URL = BASE_URLS[IMAGE_STRATEGY];
|
|
4546
|
+
function parseUrl(src) {
|
|
4547
|
+
if (src.indexOf('http') === 0) {
|
|
4548
|
+
const url = new URL(src);
|
|
4549
|
+
return url;
|
|
4550
|
+
}
|
|
4551
|
+
const pathname = src.split('/').map(x => encodeURIComponent(x)).join('/');
|
|
4552
|
+
const url = {
|
|
4553
|
+
origin: '',
|
|
4554
|
+
pathname,
|
|
4555
|
+
search: '',
|
|
4556
|
+
href: pathname
|
|
4557
|
+
};
|
|
4558
|
+
return url;
|
|
4559
|
+
}
|
|
4602
4560
|
function getImageSrc(src, width, ratio, focalX, focalY, quality) {
|
|
4603
4561
|
if (focalX === void 0) {
|
|
4604
4562
|
focalX = IMAGE_FOCAL_X;
|
|
@@ -4613,18 +4571,37 @@ function getImageSrc(src, width, ratio, focalX, focalY, quality) {
|
|
|
4613
4571
|
return src;
|
|
4614
4572
|
}
|
|
4615
4573
|
switch (IMAGE_STRATEGY) {
|
|
4616
|
-
case
|
|
4617
|
-
case exports.ImageStrategy.Oven:
|
|
4574
|
+
case bomCore.ImageStrategy.Token:
|
|
4618
4575
|
{
|
|
4619
4576
|
const {
|
|
4620
4577
|
origin,
|
|
4621
4578
|
pathname,
|
|
4622
|
-
search
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4579
|
+
search,
|
|
4580
|
+
href
|
|
4581
|
+
} = parseUrl(src);
|
|
4582
|
+
const imageResize = ratio !== 0 ? {
|
|
4583
|
+
w: width,
|
|
4584
|
+
h: Math.round(width / ratio),
|
|
4585
|
+
x: focalX,
|
|
4586
|
+
y: focalY,
|
|
4587
|
+
q: quality,
|
|
4588
|
+
src: href
|
|
4589
|
+
} : {
|
|
4590
|
+
w: width,
|
|
4591
|
+
q: quality,
|
|
4592
|
+
src: href
|
|
4627
4593
|
};
|
|
4594
|
+
const token = bomCore.encryptImageToken(imageResize);
|
|
4595
|
+
return `${BASE_URL}${pathname}?origin=${encodeURIComponent(origin)}&search=${encodeURIComponent(search)}&t=${encodeURIComponent(token)}`;
|
|
4596
|
+
}
|
|
4597
|
+
case bomCore.ImageStrategy.Mixer:
|
|
4598
|
+
case bomCore.ImageStrategy.Oven:
|
|
4599
|
+
{
|
|
4600
|
+
const {
|
|
4601
|
+
origin,
|
|
4602
|
+
pathname,
|
|
4603
|
+
search
|
|
4604
|
+
} = parseUrl(src);
|
|
4628
4605
|
return ratio !== 0 ? `${BASE_URL}${pathname}?origin=${encodeURIComponent(origin)}&search=${encodeURIComponent(search)}&w=${width}&h=${Math.round(width / ratio)}&x=${focalX}&y=${focalY}&q=${quality}` : `${BASE_URL}${pathname}?origin=${encodeURIComponent(origin)}&search=${encodeURIComponent(search)}&w=${width}&x=${focalX}&y=${focalY}&q=${quality}`;
|
|
4629
4606
|
}
|
|
4630
4607
|
default:
|
|
@@ -4652,6 +4629,56 @@ function getImageSizes(sizes) {
|
|
|
4652
4629
|
function isSVG(src) {
|
|
4653
4630
|
return src.indexOf('.svg') !== -1;
|
|
4654
4631
|
}
|
|
4632
|
+
const MediaImage_ = _a => {
|
|
4633
|
+
var {
|
|
4634
|
+
className,
|
|
4635
|
+
type,
|
|
4636
|
+
loading = 'lazy',
|
|
4637
|
+
onLoaded,
|
|
4638
|
+
canLoad = true
|
|
4639
|
+
} = _a,
|
|
4640
|
+
props = __rest(_a, ["className", "type", "loading", "onLoaded", "canLoad"]);
|
|
4641
|
+
const theme = React.useContext(styled.ThemeContext);
|
|
4642
|
+
if (!theme) {
|
|
4643
|
+
throw new Error('MediaImage must be used within ThemeProvider');
|
|
4644
|
+
}
|
|
4645
|
+
const imageRef = React.useRef(null);
|
|
4646
|
+
const classNames = bomCore.getClassNames(className, 'image', props.src && {
|
|
4647
|
+
'image-svg': isSVG(props.src)
|
|
4648
|
+
});
|
|
4649
|
+
const imageProps = getImageProps(props, theme.mediaQuery);
|
|
4650
|
+
React.useEffect(() => {
|
|
4651
|
+
if (imageRef.current && canLoad) {
|
|
4652
|
+
const image = imageRef.current;
|
|
4653
|
+
if (image.complete) {
|
|
4654
|
+
if (typeof onLoaded === 'function') {
|
|
4655
|
+
onLoaded(imageRef);
|
|
4656
|
+
}
|
|
4657
|
+
} else {
|
|
4658
|
+
const onLoad = () => {
|
|
4659
|
+
if (typeof onLoaded === 'function') {
|
|
4660
|
+
onLoaded(imageRef);
|
|
4661
|
+
}
|
|
4662
|
+
};
|
|
4663
|
+
image.addEventListener('load', onLoad);
|
|
4664
|
+
return () => {
|
|
4665
|
+
if (image) {
|
|
4666
|
+
image.removeEventListener('load', onLoad);
|
|
4667
|
+
}
|
|
4668
|
+
};
|
|
4669
|
+
}
|
|
4670
|
+
}
|
|
4671
|
+
return () => {};
|
|
4672
|
+
}, [canLoad, onLoaded]);
|
|
4673
|
+
return jsxRuntime.jsx(StyledMediaImage, Object.assign({
|
|
4674
|
+
ref: imageRef
|
|
4675
|
+
}, canLoad ? imageProps : undefined, {
|
|
4676
|
+
className: classNames,
|
|
4677
|
+
loading: loading,
|
|
4678
|
+
draggable: false
|
|
4679
|
+
}));
|
|
4680
|
+
};
|
|
4681
|
+
const MediaImage = /*#__PURE__*/React.memo(MediaImage_);
|
|
4655
4682
|
|
|
4656
4683
|
const StyledMediaVideo = styled__default.default.video`
|
|
4657
4684
|
max-width: 100%;
|
|
@@ -4670,7 +4697,7 @@ const StyledMediaVideo = styled__default.default.video`
|
|
|
4670
4697
|
}
|
|
4671
4698
|
}
|
|
4672
4699
|
`;
|
|
4673
|
-
const
|
|
4700
|
+
const MediaVideo_ = _a => {
|
|
4674
4701
|
var {
|
|
4675
4702
|
className,
|
|
4676
4703
|
onLoaded,
|
|
@@ -4725,6 +4752,7 @@ const MediaVideo = _a => {
|
|
|
4725
4752
|
})
|
|
4726
4753
|
}));
|
|
4727
4754
|
};
|
|
4755
|
+
const MediaVideo = /*#__PURE__*/React.memo(MediaVideo_);
|
|
4728
4756
|
|
|
4729
4757
|
const MediaItem = _ref => {
|
|
4730
4758
|
let {
|