pb-sxp-ui 1.0.24 → 1.0.26

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.
Files changed (31) hide show
  1. package/dist/index.cjs +100 -34
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +100 -34
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.cjs +3 -3
  6. package/dist/index.min.cjs.map +1 -1
  7. package/dist/index.min.js +3 -3
  8. package/dist/index.min.js.map +1 -1
  9. package/dist/pb-ui.js +100 -34
  10. package/dist/pb-ui.js.map +1 -1
  11. package/dist/pb-ui.min.js +3 -3
  12. package/dist/pb-ui.min.js.map +1 -1
  13. package/es/core/components/SxpPageRender/FormatImage.js +7 -6
  14. package/es/core/components/SxpPageRender/PictureGroup/Picture.d.ts +3 -2
  15. package/es/core/components/SxpPageRender/PictureGroup/Picture.js +13 -13
  16. package/es/core/components/SxpPageRender/PictureGroup/index.d.ts +2 -0
  17. package/es/core/components/SxpPageRender/PictureGroup/index.js +4 -3
  18. package/es/core/components/SxpPageRender/VideoWidget/index.d.ts +2 -0
  19. package/es/core/components/SxpPageRender/VideoWidget/index.js +73 -8
  20. package/es/core/components/SxpPageRender/index.d.ts +8 -1
  21. package/es/core/components/SxpPageRender/index.js +2 -2
  22. package/lib/core/components/SxpPageRender/FormatImage.js +6 -5
  23. package/lib/core/components/SxpPageRender/PictureGroup/Picture.d.ts +3 -2
  24. package/lib/core/components/SxpPageRender/PictureGroup/Picture.js +12 -12
  25. package/lib/core/components/SxpPageRender/PictureGroup/index.d.ts +2 -0
  26. package/lib/core/components/SxpPageRender/PictureGroup/index.js +4 -3
  27. package/lib/core/components/SxpPageRender/VideoWidget/index.d.ts +2 -0
  28. package/lib/core/components/SxpPageRender/VideoWidget/index.js +73 -8
  29. package/lib/core/components/SxpPageRender/index.d.ts +8 -1
  30. package/lib/core/components/SxpPageRender/index.js +2 -2
  31. package/package.json +1 -1
package/dist/pb-ui.js CHANGED
@@ -8303,21 +8303,22 @@
8303
8303
  * @Author: binruan@chatlabs.com
8304
8304
  * @Date: 2024-03-20 10:27:31
8305
8305
  * @LastEditors: binruan@chatlabs.com
8306
- * @LastEditTime: 2024-04-17 20:45:55
8306
+ * @LastEditTime: 2024-04-19 14:12:55
8307
8307
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\FormatImage.tsx
8308
8308
  *
8309
8309
  */
8310
8310
  const FormatImage = React.forwardRef((props, ref) => {
8311
8311
  const { src, onLoad, style, className, loading } = props;
8312
- const [imgSrc, setImgSrc] = React.useState(src);
8312
+ const [imgSrc, setImgSrc] = React.useState();
8313
8313
  React.useImperativeHandle(ref, () => ({
8314
8314
  setSrc: (v) => {
8315
8315
  setImgSrc(v);
8316
8316
  }
8317
8317
  }));
8318
- if (imgSrc === '' || !imgSrc)
8319
- return null;
8320
- return (imgSrc === null || imgSrc === void 0 ? void 0 : imgSrc.includes('.avif')) ? (React.createElement("picture", null,
8318
+ React.useEffect(() => {
8319
+ setImgSrc(src);
8320
+ }, [src]);
8321
+ return (React.createElement(React.Fragment, null, (imgSrc === null || imgSrc === void 0 ? void 0 : imgSrc.includes('.avif')) ? (React.createElement("picture", null,
8321
8322
  React.createElement("source", { type: 'image/avif', srcSet: imgSrc }),
8322
8323
  React.createElement("source", { type: 'image/webp', srcSet: `${imgSrc}?imageMogr2/format/webp` }),
8323
8324
  React.createElement("source", { type: 'image/jpeg', srcSet: `${imgSrc}?imageMogr2/format/jpg` }),
@@ -8325,7 +8326,7 @@
8325
8326
  onLoad === null || onLoad === void 0 ? void 0 : onLoad(e.target);
8326
8327
  } }))) : (React.createElement("img", { className: className, src: imgSrc, style: style, loading: loading, onLoad: (e) => {
8327
8328
  onLoad === null || onLoad === void 0 ? void 0 : onLoad(e.target);
8328
- } }));
8329
+ } }))));
8329
8330
  });
8330
8331
  var FormatImage$1 = React.memo(FormatImage);
8331
8332
 
@@ -11981,7 +11982,7 @@ Made in Italy` })));
11981
11982
  SXP_EVENT_TYPE["PAGE_DID_HIDE"] = "pageDidHide";
11982
11983
  })(SXP_EVENT_TYPE || (SXP_EVENT_TYPE = {}));
11983
11984
 
11984
- const VideoWidget = ({ rec, index, height, data, muted, activeIndex }) => {
11985
+ const VideoWidget = ({ rec, index, height, data, muted, activeIndex, videoPostConfig }) => {
11985
11986
  const [isPauseVideo, setIsPauseVideo] = React.useState(false);
11986
11987
  const videoRef = React.useRef(null);
11987
11988
  const { bffEventReport, sxpParameter, waterFallData, openHashtag } = useSxpDataSource();
@@ -11989,6 +11990,8 @@ Made in Italy` })));
11989
11990
  const [isLoadFinish, setIsLoadFinish] = React.useState(false);
11990
11991
  const [isFirstPlay, setIsFirstPlay] = React.useState(true);
11991
11992
  const { isActive } = useSwiperSlide();
11993
+ const canvasRef = React.useRef(null);
11994
+ const [firstFrameSrc, setFirstFrameSrc] = React.useState('');
11992
11995
  React.useEffect(() => {
11993
11996
  if (!videoRef.current)
11994
11997
  return;
@@ -12082,8 +12085,24 @@ Made in Italy` })));
12082
12085
  });
12083
12086
  }
12084
12087
  }, [data, index, bffEventReport]);
12088
+ const handLoadeddata = React.useCallback(() => {
12089
+ const video = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current;
12090
+ if (!video)
12091
+ return;
12092
+ const canvas = canvasRef === null || canvasRef === void 0 ? void 0 : canvasRef.current;
12093
+ if (!canvas)
12094
+ return;
12095
+ const ctx = canvas.getContext('2d');
12096
+ const targetWidth = window === null || window === void 0 ? void 0 : window.innerWidth;
12097
+ const targetHeight = window === null || window === void 0 ? void 0 : window.innerHeight;
12098
+ canvas.height = targetHeight;
12099
+ canvas.width = targetWidth;
12100
+ ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
12101
+ setFirstFrameSrc(canvas.toDataURL());
12102
+ canvas.remove();
12103
+ }, []);
12085
12104
  React.useEffect(() => {
12086
- var _a, _b;
12105
+ var _a, _b, _c;
12087
12106
  if (!videoRef.current)
12088
12107
  return;
12089
12108
  setIsPauseVideo(false);
@@ -12108,12 +12127,14 @@ Made in Italy` })));
12108
12127
  }
12109
12128
  (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('canplay', handleLoadedMetadata);
12110
12129
  (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.addEventListener('playing', handlePlaying);
12130
+ (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.addEventListener('loadeddata', handLoadeddata);
12111
12131
  return () => {
12112
- var _a, _b;
12132
+ var _a, _b, _c;
12113
12133
  (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('canplay', handleLoadedMetadata);
12114
12134
  (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('playing', handlePlaying);
12135
+ (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.removeEventListener('loadeddata', handLoadeddata);
12115
12136
  };
12116
- }, [handleLoadedMetadata, handlePlaying, rec.video]);
12137
+ }, [handleLoadedMetadata, handlePlaying, rec.video, handLoadeddata]);
12117
12138
  React.useEffect(() => {
12118
12139
  var _a;
12119
12140
  if (!(videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) || !isLoadFinish)
@@ -12170,17 +12191,61 @@ Made in Italy` })));
12170
12191
  window.removeEventListener('beforeunload', handleBeforeUnload);
12171
12192
  };
12172
12193
  }, [activeIndex, index, rec, videoRef, handleClickVideo, isPauseVideo]);
12194
+ const blur = React.useMemo(() => {
12195
+ return (videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.mode) === '2';
12196
+ }, [videoPostConfig]);
12197
+ const translateY = React.useMemo(() => {
12198
+ var _a;
12199
+ return (videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.mode) === '2'
12200
+ ? `translateY(-${50 + ((_a = videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.offsetTop) !== null && _a !== void 0 ? _a : 0)}%)`
12201
+ : 'translateY(-50%)';
12202
+ }, [videoPostConfig]);
12203
+ const blurBgSrc = React.useMemo(() => {
12204
+ var _a;
12205
+ return ((_a = rec === null || rec === void 0 ? void 0 : rec.video) === null || _a === void 0 ? void 0 : _a.cover) || firstFrameSrc;
12206
+ }, [firstFrameSrc, rec]);
12173
12207
  if (!rec.video) {
12174
12208
  return null;
12175
12209
  }
12176
- return (React.createElement("div", { className: 'video-container', key: rec.video.itemId, onClick: handleClickVideo(), style: {
12210
+ return (React.createElement(React.Fragment, null, blur ? (React.createElement("div", { className: 'video-container', key: rec.video.itemId, onClick: handleClickVideo(), style: {
12177
12211
  position: 'relative',
12178
12212
  width: '100%',
12179
- height
12213
+ height,
12214
+ overflow: 'hidden'
12180
12215
  } },
12181
- React.createElement("video", { id: `pb-video-${index}`, className: 'clc-pb-video', ref: videoRef, poster: sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image, muted: true, controls: false, playsInline: true, preload: 'auto', onPause: onPause, onEnded: handleVideoStart }),
12216
+ React.createElement(FormatImage$1, { src: blurBgSrc, style: {
12217
+ height: '100%',
12218
+ width: '100%',
12219
+ objectFit: 'cover',
12220
+ filter: blur ? 'blur(10px)' : 'none',
12221
+ transform: blur ? 'scale(1.2)' : 'none'
12222
+ } }),
12223
+ React.createElement("canvas", { ref: canvasRef, style: { display: 'none' } }),
12224
+ React.createElement("div", { style: {
12225
+ position: 'absolute',
12226
+ width: '100%',
12227
+ height: 'auto',
12228
+ top: '50%',
12229
+ transform: translateY,
12230
+ left: 0,
12231
+ right: 0
12232
+ } },
12233
+ React.createElement("div", { style: { position: 'relative' } },
12234
+ React.createElement("video", { id: `pb-video-${index}`, className: 'clc-pb-video', ref: videoRef, crossOrigin: 'anonymous', poster: sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image, muted: true, controls: false, playsInline: true, preload: 'auto', onPause: onPause, onEnded: handleVideoStart, style: {
12235
+ width: '100%',
12236
+ height: 'auto',
12237
+ objectFit: 'contain'
12238
+ } }),
12239
+ renderPoster,
12240
+ React.createElement("img", { hidden: !isPauseVideo, className: 'clc-pb-video-pause', src: PAUSE_ICON }))))) : (React.createElement("div", { className: 'video-container', key: rec.video.itemId, onClick: handleClickVideo(), style: {
12241
+ position: 'relative',
12242
+ width: '100%',
12243
+ height,
12244
+ overflow: 'hidden'
12245
+ } },
12246
+ React.createElement("video", { id: `pb-video-${index}`, className: 'clc-pb-video', ref: videoRef, crossOrigin: 'anonymous', poster: sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image, muted: true, controls: false, playsInline: true, preload: 'auto', onPause: onPause, onEnded: handleVideoStart }),
12182
12247
  renderPoster,
12183
- React.createElement("img", { hidden: !isPauseVideo, className: 'clc-pb-video-pause', src: PAUSE_ICON })));
12248
+ React.createElement("img", { hidden: !isPauseVideo, className: 'clc-pb-video-pause', src: PAUSE_ICON })))));
12184
12249
  };
12185
12250
  var VideoWidget$1 = React.memo(VideoWidget);
12186
12251
 
@@ -12233,21 +12298,21 @@ Made in Italy` })));
12233
12298
  * @Author: binruan@chatlabs.com
12234
12299
  * @Date: 2024-03-20 10:27:31
12235
12300
  * @LastEditors: binruan@chatlabs.com
12236
- * @LastEditTime: 2024-04-18 10:30:17
12301
+ * @LastEditTime: 2024-04-18 19:27:35
12237
12302
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\PictureGroup\Picture.tsx
12238
12303
  *
12239
12304
  */
12240
12305
  const Picture = (props) => {
12241
- const { src, height, width } = props;
12242
- const [blur, setBlur] = React.useState(false);
12243
- const onLoad = (img) => {
12244
- const aspectRatio = img.naturalHeight / img.naturalWidth;
12245
- const targetAspectRatio = 16 / 9;
12246
- const tolerance = 0.05; // 允许的宽高比误差范围
12247
- if (Math.abs(aspectRatio - targetAspectRatio) > tolerance) {
12248
- setBlur(true);
12249
- }
12250
- };
12306
+ const { src, height, imgUrlsPostConfig } = props;
12307
+ const blur = React.useMemo(() => {
12308
+ return (imgUrlsPostConfig === null || imgUrlsPostConfig === void 0 ? void 0 : imgUrlsPostConfig.mode) === '2';
12309
+ }, [imgUrlsPostConfig]);
12310
+ const translateY = React.useMemo(() => {
12311
+ var _a;
12312
+ return (imgUrlsPostConfig === null || imgUrlsPostConfig === void 0 ? void 0 : imgUrlsPostConfig.mode) === '2'
12313
+ ? `translateY(-${50 + ((_a = imgUrlsPostConfig === null || imgUrlsPostConfig === void 0 ? void 0 : imgUrlsPostConfig.offsetTop) !== null && _a !== void 0 ? _a : 0)}%)`
12314
+ : 'translateY(-50%)';
12315
+ }, [imgUrlsPostConfig]);
12251
12316
  return (React.createElement("div", { style: {
12252
12317
  overflow: 'hidden',
12253
12318
  height,
@@ -12260,13 +12325,13 @@ Made in Italy` })));
12260
12325
  objectFit: 'cover',
12261
12326
  filter: blur ? 'blur(10px)' : 'none',
12262
12327
  transform: blur ? 'scale(1.2)' : 'none'
12263
- }, onLoad: onLoad }),
12328
+ } }),
12264
12329
  blur && (React.createElement(FormatImage$1, { src: src, style: {
12265
12330
  width: '100%',
12266
12331
  objectFit: 'contain',
12267
12332
  position: 'absolute',
12268
12333
  top: '50%',
12269
- transform: 'translateY(-50%)',
12334
+ transform: translateY,
12270
12335
  left: 0,
12271
12336
  right: 0
12272
12337
  } }))));
@@ -12276,10 +12341,11 @@ Made in Italy` })));
12276
12341
  * @Author: lewinlu@chatlabs.com
12277
12342
  * @Date: 2024-01-03 14:39:09
12278
12343
  * @LastEditors: binruan@chatlabs.com
12279
- * @LastEditTime: 2024-04-17 18:52:45
12344
+ * @LastEditTime: 2024-04-18 19:56:22
12280
12345
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\PictureGroup\index.tsx
12281
12346
  */
12282
- const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd, onViewImageStartEvent }) => {
12347
+ const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd, onViewImageStartEvent, imgUrlsPostConfig }) => {
12348
+ var _a;
12283
12349
  const ref = React.useRef();
12284
12350
  const { isActive } = useSwiperSlide();
12285
12351
  const { sxpParameter, openHashtag } = useSxpDataSource();
@@ -12302,9 +12368,9 @@ Made in Italy` })));
12302
12368
  // if (!isActive) {
12303
12369
  // return <img src={sxpParameter?.placeholder_image} style={{ width, height, objectFit: 'cover' }} />;
12304
12370
  // }
12305
- return (React.createElement(Swiper, { ref: ref, defaultValue: 0, direction: 'horizontal', modules: [Pagination, Autoplay], pagination: { clickable: true, bulletActiveClass: 'swipe-item-active-bullet' }, height: height, loop: true, autoplay: { delay: 3000 } }, imgUrls === null || imgUrls === void 0 ? void 0 : imgUrls.map((url) => {
12371
+ return (React.createElement(Swiper, { ref: ref, defaultValue: 0, direction: 'horizontal', modules: [Pagination, Autoplay], pagination: { clickable: true, bulletActiveClass: 'swipe-item-active-bullet' }, height: height, loop: true, autoplay: { delay: ((_a = imgUrlsPostConfig === null || imgUrlsPostConfig === void 0 ? void 0 : imgUrlsPostConfig.delay) !== null && _a !== void 0 ? _a : 3) * 1000 } }, imgUrls === null || imgUrls === void 0 ? void 0 : imgUrls.map((url) => {
12306
12372
  return (React.createElement(SwiperSlide, { key: url },
12307
- React.createElement(Picture, { src: url, width: width, height: height })));
12373
+ React.createElement(Picture, { src: url, height: height, imgUrlsPostConfig: imgUrlsPostConfig })));
12308
12374
  })));
12309
12375
  };
12310
12376
  var PictureGroup$1 = React.memo(PictureGroup);
@@ -12486,7 +12552,7 @@ Made in Italy` })));
12486
12552
  * @Author: binruan@chatlabs.com
12487
12553
  * @Date: 2024-01-15 19:03:09
12488
12554
  * @LastEditors: binruan@chatlabs.com
12489
- * @LastEditTime: 2024-04-18 16:49:34
12555
+ * @LastEditTime: 2024-04-18 19:27:03
12490
12556
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\index.tsx
12491
12557
  *
12492
12558
  */
@@ -12647,10 +12713,10 @@ Made in Italy` })));
12647
12713
  const renderContent = React.useCallback((rec, index) => {
12648
12714
  var _a, _b, _c, _d;
12649
12715
  if ((_a = rec.video) === null || _a === void 0 ? void 0 : _a.url) {
12650
- return (React.createElement(VideoWidget$1, { rec: rec, index: index, muted: isMuted, data: data, height: height, activeIndex: activeIndex }));
12716
+ return (React.createElement(VideoWidget$1, { rec: rec, index: index, muted: isMuted, data: data, height: height, activeIndex: activeIndex, videoPostConfig: globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.videoPost }));
12651
12717
  }
12652
12718
  if ((_b = rec.video) === null || _b === void 0 ? void 0 : _b.imgUrls) {
12653
- return (React.createElement(PictureGroup$1, { key: rec.video.itemId, imgUrls: rec.video.imgUrls, width: containerWidth, height: height, rec: rec, index: index, onReportViewImageEnd: handleReportViewImageEnd, onViewImageStartEvent: handleViewImageStartEvent }));
12719
+ return (React.createElement(PictureGroup$1, { key: rec.video.itemId, imgUrls: rec.video.imgUrls, width: containerWidth, height: height, rec: rec, index: index, onReportViewImageEnd: handleReportViewImageEnd, onViewImageStartEvent: handleViewImageStartEvent, imgUrlsPostConfig: globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.imgUrlsPost }));
12654
12720
  }
12655
12721
  if (rec.product && Array.isArray(globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.productPost) && ((_c = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.productPost) === null || _c === void 0 ? void 0 : _c.length) > 0) {
12656
12722
  return (_d = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.productPost) === null || _d === void 0 ? void 0 : _d.map((value, idx) => {