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/index.cjs CHANGED
@@ -8311,21 +8311,22 @@ var ExpandableText$1 = React.memo(ExpandableText);
8311
8311
  * @Author: binruan@chatlabs.com
8312
8312
  * @Date: 2024-03-20 10:27:31
8313
8313
  * @LastEditors: binruan@chatlabs.com
8314
- * @LastEditTime: 2024-04-17 20:45:55
8314
+ * @LastEditTime: 2024-04-19 14:12:55
8315
8315
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\FormatImage.tsx
8316
8316
  *
8317
8317
  */
8318
8318
  const FormatImage = React.forwardRef((props, ref) => {
8319
8319
  const { src, onLoad, style, className, loading } = props;
8320
- const [imgSrc, setImgSrc] = React.useState(src);
8320
+ const [imgSrc, setImgSrc] = React.useState();
8321
8321
  React.useImperativeHandle(ref, () => ({
8322
8322
  setSrc: (v) => {
8323
8323
  setImgSrc(v);
8324
8324
  }
8325
8325
  }));
8326
- if (imgSrc === '' || !imgSrc)
8327
- return null;
8328
- return (imgSrc === null || imgSrc === void 0 ? void 0 : imgSrc.includes('.avif')) ? (React.createElement("picture", null,
8326
+ React.useEffect(() => {
8327
+ setImgSrc(src);
8328
+ }, [src]);
8329
+ return (React.createElement(React.Fragment, null, (imgSrc === null || imgSrc === void 0 ? void 0 : imgSrc.includes('.avif')) ? (React.createElement("picture", null,
8329
8330
  React.createElement("source", { type: 'image/avif', srcSet: imgSrc }),
8330
8331
  React.createElement("source", { type: 'image/webp', srcSet: `${imgSrc}?imageMogr2/format/webp` }),
8331
8332
  React.createElement("source", { type: 'image/jpeg', srcSet: `${imgSrc}?imageMogr2/format/jpg` }),
@@ -8333,7 +8334,7 @@ const FormatImage = React.forwardRef((props, ref) => {
8333
8334
  onLoad === null || onLoad === void 0 ? void 0 : onLoad(e.target);
8334
8335
  } }))) : (React.createElement("img", { className: className, src: imgSrc, style: style, loading: loading, onLoad: (e) => {
8335
8336
  onLoad === null || onLoad === void 0 ? void 0 : onLoad(e.target);
8336
- } }));
8337
+ } }))));
8337
8338
  });
8338
8339
  var FormatImage$1 = React.memo(FormatImage);
8339
8340
 
@@ -11989,7 +11990,7 @@ var SXP_EVENT_TYPE;
11989
11990
  SXP_EVENT_TYPE["PAGE_DID_HIDE"] = "pageDidHide";
11990
11991
  })(SXP_EVENT_TYPE || (SXP_EVENT_TYPE = {}));
11991
11992
 
11992
- const VideoWidget = ({ rec, index, height, data, muted, activeIndex }) => {
11993
+ const VideoWidget = ({ rec, index, height, data, muted, activeIndex, videoPostConfig }) => {
11993
11994
  const [isPauseVideo, setIsPauseVideo] = React.useState(false);
11994
11995
  const videoRef = React.useRef(null);
11995
11996
  const { bffEventReport, sxpParameter, waterFallData, openHashtag } = useSxpDataSource();
@@ -11997,6 +11998,8 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex }) => {
11997
11998
  const [isLoadFinish, setIsLoadFinish] = React.useState(false);
11998
11999
  const [isFirstPlay, setIsFirstPlay] = React.useState(true);
11999
12000
  const { isActive } = useSwiperSlide();
12001
+ const canvasRef = React.useRef(null);
12002
+ const [firstFrameSrc, setFirstFrameSrc] = React.useState('');
12000
12003
  React.useEffect(() => {
12001
12004
  if (!videoRef.current)
12002
12005
  return;
@@ -12090,8 +12093,24 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex }) => {
12090
12093
  });
12091
12094
  }
12092
12095
  }, [data, index, bffEventReport]);
12096
+ const handLoadeddata = React.useCallback(() => {
12097
+ const video = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current;
12098
+ if (!video)
12099
+ return;
12100
+ const canvas = canvasRef === null || canvasRef === void 0 ? void 0 : canvasRef.current;
12101
+ if (!canvas)
12102
+ return;
12103
+ const ctx = canvas.getContext('2d');
12104
+ const targetWidth = window === null || window === void 0 ? void 0 : window.innerWidth;
12105
+ const targetHeight = window === null || window === void 0 ? void 0 : window.innerHeight;
12106
+ canvas.height = targetHeight;
12107
+ canvas.width = targetWidth;
12108
+ ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
12109
+ setFirstFrameSrc(canvas.toDataURL());
12110
+ canvas.remove();
12111
+ }, []);
12093
12112
  React.useEffect(() => {
12094
- var _a, _b;
12113
+ var _a, _b, _c;
12095
12114
  if (!videoRef.current)
12096
12115
  return;
12097
12116
  setIsPauseVideo(false);
@@ -12116,12 +12135,14 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex }) => {
12116
12135
  }
12117
12136
  (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('canplay', handleLoadedMetadata);
12118
12137
  (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.addEventListener('playing', handlePlaying);
12138
+ (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.addEventListener('loadeddata', handLoadeddata);
12119
12139
  return () => {
12120
- var _a, _b;
12140
+ var _a, _b, _c;
12121
12141
  (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('canplay', handleLoadedMetadata);
12122
12142
  (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('playing', handlePlaying);
12143
+ (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.removeEventListener('loadeddata', handLoadeddata);
12123
12144
  };
12124
- }, [handleLoadedMetadata, handlePlaying, rec.video]);
12145
+ }, [handleLoadedMetadata, handlePlaying, rec.video, handLoadeddata]);
12125
12146
  React.useEffect(() => {
12126
12147
  var _a;
12127
12148
  if (!(videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) || !isLoadFinish)
@@ -12178,17 +12199,61 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex }) => {
12178
12199
  window.removeEventListener('beforeunload', handleBeforeUnload);
12179
12200
  };
12180
12201
  }, [activeIndex, index, rec, videoRef, handleClickVideo, isPauseVideo]);
12202
+ const blur = React.useMemo(() => {
12203
+ return (videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.mode) === '2';
12204
+ }, [videoPostConfig]);
12205
+ const translateY = React.useMemo(() => {
12206
+ var _a;
12207
+ return (videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.mode) === '2'
12208
+ ? `translateY(-${50 + ((_a = videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.offsetTop) !== null && _a !== void 0 ? _a : 0)}%)`
12209
+ : 'translateY(-50%)';
12210
+ }, [videoPostConfig]);
12211
+ const blurBgSrc = React.useMemo(() => {
12212
+ var _a;
12213
+ return ((_a = rec === null || rec === void 0 ? void 0 : rec.video) === null || _a === void 0 ? void 0 : _a.cover) || firstFrameSrc;
12214
+ }, [firstFrameSrc, rec]);
12181
12215
  if (!rec.video) {
12182
12216
  return null;
12183
12217
  }
12184
- return (React.createElement("div", { className: 'video-container', key: rec.video.itemId, onClick: handleClickVideo(), style: {
12218
+ return (React.createElement(React.Fragment, null, blur ? (React.createElement("div", { className: 'video-container', key: rec.video.itemId, onClick: handleClickVideo(), style: {
12185
12219
  position: 'relative',
12186
12220
  width: '100%',
12187
- height
12221
+ height,
12222
+ overflow: 'hidden'
12188
12223
  } },
12189
- 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 }),
12224
+ React.createElement(FormatImage$1, { src: blurBgSrc, style: {
12225
+ height: '100%',
12226
+ width: '100%',
12227
+ objectFit: 'cover',
12228
+ filter: blur ? 'blur(10px)' : 'none',
12229
+ transform: blur ? 'scale(1.2)' : 'none'
12230
+ } }),
12231
+ React.createElement("canvas", { ref: canvasRef, style: { display: 'none' } }),
12232
+ React.createElement("div", { style: {
12233
+ position: 'absolute',
12234
+ width: '100%',
12235
+ height: 'auto',
12236
+ top: '50%',
12237
+ transform: translateY,
12238
+ left: 0,
12239
+ right: 0
12240
+ } },
12241
+ React.createElement("div", { style: { position: 'relative' } },
12242
+ 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: {
12243
+ width: '100%',
12244
+ height: 'auto',
12245
+ objectFit: 'contain'
12246
+ } }),
12247
+ renderPoster,
12248
+ 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: {
12249
+ position: 'relative',
12250
+ width: '100%',
12251
+ height,
12252
+ overflow: 'hidden'
12253
+ } },
12254
+ 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 }),
12190
12255
  renderPoster,
12191
- React.createElement("img", { hidden: !isPauseVideo, className: 'clc-pb-video-pause', src: PAUSE_ICON })));
12256
+ React.createElement("img", { hidden: !isPauseVideo, className: 'clc-pb-video-pause', src: PAUSE_ICON })))));
12192
12257
  };
12193
12258
  var VideoWidget$1 = React.memo(VideoWidget);
12194
12259
 
@@ -12241,21 +12306,21 @@ const FingerSwipeTip = ({ imageUrl }) => {
12241
12306
  * @Author: binruan@chatlabs.com
12242
12307
  * @Date: 2024-03-20 10:27:31
12243
12308
  * @LastEditors: binruan@chatlabs.com
12244
- * @LastEditTime: 2024-04-18 10:30:17
12309
+ * @LastEditTime: 2024-04-18 19:27:35
12245
12310
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\PictureGroup\Picture.tsx
12246
12311
  *
12247
12312
  */
12248
12313
  const Picture = (props) => {
12249
- const { src, height, width } = props;
12250
- const [blur, setBlur] = React.useState(false);
12251
- const onLoad = (img) => {
12252
- const aspectRatio = img.naturalHeight / img.naturalWidth;
12253
- const targetAspectRatio = 16 / 9;
12254
- const tolerance = 0.05; // 允许的宽高比误差范围
12255
- if (Math.abs(aspectRatio - targetAspectRatio) > tolerance) {
12256
- setBlur(true);
12257
- }
12258
- };
12314
+ const { src, height, imgUrlsPostConfig } = props;
12315
+ const blur = React.useMemo(() => {
12316
+ return (imgUrlsPostConfig === null || imgUrlsPostConfig === void 0 ? void 0 : imgUrlsPostConfig.mode) === '2';
12317
+ }, [imgUrlsPostConfig]);
12318
+ const translateY = React.useMemo(() => {
12319
+ var _a;
12320
+ return (imgUrlsPostConfig === null || imgUrlsPostConfig === void 0 ? void 0 : imgUrlsPostConfig.mode) === '2'
12321
+ ? `translateY(-${50 + ((_a = imgUrlsPostConfig === null || imgUrlsPostConfig === void 0 ? void 0 : imgUrlsPostConfig.offsetTop) !== null && _a !== void 0 ? _a : 0)}%)`
12322
+ : 'translateY(-50%)';
12323
+ }, [imgUrlsPostConfig]);
12259
12324
  return (React.createElement("div", { style: {
12260
12325
  overflow: 'hidden',
12261
12326
  height,
@@ -12268,13 +12333,13 @@ const Picture = (props) => {
12268
12333
  objectFit: 'cover',
12269
12334
  filter: blur ? 'blur(10px)' : 'none',
12270
12335
  transform: blur ? 'scale(1.2)' : 'none'
12271
- }, onLoad: onLoad }),
12336
+ } }),
12272
12337
  blur && (React.createElement(FormatImage$1, { src: src, style: {
12273
12338
  width: '100%',
12274
12339
  objectFit: 'contain',
12275
12340
  position: 'absolute',
12276
12341
  top: '50%',
12277
- transform: 'translateY(-50%)',
12342
+ transform: translateY,
12278
12343
  left: 0,
12279
12344
  right: 0
12280
12345
  } }))));
@@ -12284,10 +12349,11 @@ const Picture = (props) => {
12284
12349
  * @Author: lewinlu@chatlabs.com
12285
12350
  * @Date: 2024-01-03 14:39:09
12286
12351
  * @LastEditors: binruan@chatlabs.com
12287
- * @LastEditTime: 2024-04-17 18:52:45
12352
+ * @LastEditTime: 2024-04-18 19:56:22
12288
12353
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\PictureGroup\index.tsx
12289
12354
  */
12290
- const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd, onViewImageStartEvent }) => {
12355
+ const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd, onViewImageStartEvent, imgUrlsPostConfig }) => {
12356
+ var _a;
12291
12357
  const ref = React.useRef();
12292
12358
  const { isActive } = useSwiperSlide();
12293
12359
  const { sxpParameter, openHashtag } = useSxpDataSource();
@@ -12310,9 +12376,9 @@ const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd
12310
12376
  // if (!isActive) {
12311
12377
  // return <img src={sxpParameter?.placeholder_image} style={{ width, height, objectFit: 'cover' }} />;
12312
12378
  // }
12313
- 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) => {
12379
+ 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) => {
12314
12380
  return (React.createElement(SwiperSlide, { key: url },
12315
- React.createElement(Picture, { src: url, width: width, height: height })));
12381
+ React.createElement(Picture, { src: url, height: height, imgUrlsPostConfig: imgUrlsPostConfig })));
12316
12382
  })));
12317
12383
  };
12318
12384
  var PictureGroup$1 = React.memo(PictureGroup);
@@ -12494,7 +12560,7 @@ const Nudge = ({ nudge }) => {
12494
12560
  * @Author: binruan@chatlabs.com
12495
12561
  * @Date: 2024-01-15 19:03:09
12496
12562
  * @LastEditors: binruan@chatlabs.com
12497
- * @LastEditTime: 2024-04-18 16:49:34
12563
+ * @LastEditTime: 2024-04-18 19:27:03
12498
12564
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\index.tsx
12499
12565
  *
12500
12566
  */
@@ -12655,10 +12721,10 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
12655
12721
  const renderContent = React.useCallback((rec, index) => {
12656
12722
  var _a, _b, _c, _d;
12657
12723
  if ((_a = rec.video) === null || _a === void 0 ? void 0 : _a.url) {
12658
- return (React.createElement(VideoWidget$1, { rec: rec, index: index, muted: isMuted, data: data, height: height, activeIndex: activeIndex }));
12724
+ 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 }));
12659
12725
  }
12660
12726
  if ((_b = rec.video) === null || _b === void 0 ? void 0 : _b.imgUrls) {
12661
- 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 }));
12727
+ 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 }));
12662
12728
  }
12663
12729
  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) {
12664
12730
  return (_d = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.productPost) === null || _d === void 0 ? void 0 : _d.map((value, idx) => {