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.js CHANGED
@@ -8288,21 +8288,22 @@ var ExpandableText$1 = memo(ExpandableText);
8288
8288
  * @Author: binruan@chatlabs.com
8289
8289
  * @Date: 2024-03-20 10:27:31
8290
8290
  * @LastEditors: binruan@chatlabs.com
8291
- * @LastEditTime: 2024-04-17 20:45:55
8291
+ * @LastEditTime: 2024-04-19 14:12:55
8292
8292
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\FormatImage.tsx
8293
8293
  *
8294
8294
  */
8295
8295
  const FormatImage = forwardRef((props, ref) => {
8296
8296
  const { src, onLoad, style, className, loading } = props;
8297
- const [imgSrc, setImgSrc] = useState(src);
8297
+ const [imgSrc, setImgSrc] = useState();
8298
8298
  useImperativeHandle(ref, () => ({
8299
8299
  setSrc: (v) => {
8300
8300
  setImgSrc(v);
8301
8301
  }
8302
8302
  }));
8303
- if (imgSrc === '' || !imgSrc)
8304
- return null;
8305
- return (imgSrc === null || imgSrc === void 0 ? void 0 : imgSrc.includes('.avif')) ? (React.createElement("picture", null,
8303
+ useEffect(() => {
8304
+ setImgSrc(src);
8305
+ }, [src]);
8306
+ return (React.createElement(React.Fragment, null, (imgSrc === null || imgSrc === void 0 ? void 0 : imgSrc.includes('.avif')) ? (React.createElement("picture", null,
8306
8307
  React.createElement("source", { type: 'image/avif', srcSet: imgSrc }),
8307
8308
  React.createElement("source", { type: 'image/webp', srcSet: `${imgSrc}?imageMogr2/format/webp` }),
8308
8309
  React.createElement("source", { type: 'image/jpeg', srcSet: `${imgSrc}?imageMogr2/format/jpg` }),
@@ -8310,7 +8311,7 @@ const FormatImage = forwardRef((props, ref) => {
8310
8311
  onLoad === null || onLoad === void 0 ? void 0 : onLoad(e.target);
8311
8312
  } }))) : (React.createElement("img", { className: className, src: imgSrc, style: style, loading: loading, onLoad: (e) => {
8312
8313
  onLoad === null || onLoad === void 0 ? void 0 : onLoad(e.target);
8313
- } }));
8314
+ } }))));
8314
8315
  });
8315
8316
  var FormatImage$1 = memo(FormatImage);
8316
8317
 
@@ -11966,7 +11967,7 @@ var SXP_EVENT_TYPE;
11966
11967
  SXP_EVENT_TYPE["PAGE_DID_HIDE"] = "pageDidHide";
11967
11968
  })(SXP_EVENT_TYPE || (SXP_EVENT_TYPE = {}));
11968
11969
 
11969
- const VideoWidget = ({ rec, index, height, data, muted, activeIndex }) => {
11970
+ const VideoWidget = ({ rec, index, height, data, muted, activeIndex, videoPostConfig }) => {
11970
11971
  const [isPauseVideo, setIsPauseVideo] = useState(false);
11971
11972
  const videoRef = useRef(null);
11972
11973
  const { bffEventReport, sxpParameter, waterFallData, openHashtag } = useSxpDataSource();
@@ -11974,6 +11975,8 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex }) => {
11974
11975
  const [isLoadFinish, setIsLoadFinish] = useState(false);
11975
11976
  const [isFirstPlay, setIsFirstPlay] = useState(true);
11976
11977
  const { isActive } = useSwiperSlide();
11978
+ const canvasRef = useRef(null);
11979
+ const [firstFrameSrc, setFirstFrameSrc] = useState('');
11977
11980
  useEffect(() => {
11978
11981
  if (!videoRef.current)
11979
11982
  return;
@@ -12067,8 +12070,24 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex }) => {
12067
12070
  });
12068
12071
  }
12069
12072
  }, [data, index, bffEventReport]);
12073
+ const handLoadeddata = useCallback(() => {
12074
+ const video = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current;
12075
+ if (!video)
12076
+ return;
12077
+ const canvas = canvasRef === null || canvasRef === void 0 ? void 0 : canvasRef.current;
12078
+ if (!canvas)
12079
+ return;
12080
+ const ctx = canvas.getContext('2d');
12081
+ const targetWidth = window === null || window === void 0 ? void 0 : window.innerWidth;
12082
+ const targetHeight = window === null || window === void 0 ? void 0 : window.innerHeight;
12083
+ canvas.height = targetHeight;
12084
+ canvas.width = targetWidth;
12085
+ ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
12086
+ setFirstFrameSrc(canvas.toDataURL());
12087
+ canvas.remove();
12088
+ }, []);
12070
12089
  useEffect(() => {
12071
- var _a, _b;
12090
+ var _a, _b, _c;
12072
12091
  if (!videoRef.current)
12073
12092
  return;
12074
12093
  setIsPauseVideo(false);
@@ -12093,12 +12112,14 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex }) => {
12093
12112
  }
12094
12113
  (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('canplay', handleLoadedMetadata);
12095
12114
  (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.addEventListener('playing', handlePlaying);
12115
+ (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.addEventListener('loadeddata', handLoadeddata);
12096
12116
  return () => {
12097
- var _a, _b;
12117
+ var _a, _b, _c;
12098
12118
  (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('canplay', handleLoadedMetadata);
12099
12119
  (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('playing', handlePlaying);
12120
+ (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.removeEventListener('loadeddata', handLoadeddata);
12100
12121
  };
12101
- }, [handleLoadedMetadata, handlePlaying, rec.video]);
12122
+ }, [handleLoadedMetadata, handlePlaying, rec.video, handLoadeddata]);
12102
12123
  useEffect(() => {
12103
12124
  var _a;
12104
12125
  if (!(videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) || !isLoadFinish)
@@ -12155,17 +12176,61 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex }) => {
12155
12176
  window.removeEventListener('beforeunload', handleBeforeUnload);
12156
12177
  };
12157
12178
  }, [activeIndex, index, rec, videoRef, handleClickVideo, isPauseVideo]);
12179
+ const blur = useMemo(() => {
12180
+ return (videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.mode) === '2';
12181
+ }, [videoPostConfig]);
12182
+ const translateY = useMemo(() => {
12183
+ var _a;
12184
+ return (videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.mode) === '2'
12185
+ ? `translateY(-${50 + ((_a = videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.offsetTop) !== null && _a !== void 0 ? _a : 0)}%)`
12186
+ : 'translateY(-50%)';
12187
+ }, [videoPostConfig]);
12188
+ const blurBgSrc = useMemo(() => {
12189
+ var _a;
12190
+ return ((_a = rec === null || rec === void 0 ? void 0 : rec.video) === null || _a === void 0 ? void 0 : _a.cover) || firstFrameSrc;
12191
+ }, [firstFrameSrc, rec]);
12158
12192
  if (!rec.video) {
12159
12193
  return null;
12160
12194
  }
12161
- return (React.createElement("div", { className: 'video-container', key: rec.video.itemId, onClick: handleClickVideo(), style: {
12195
+ return (React.createElement(React.Fragment, null, blur ? (React.createElement("div", { className: 'video-container', key: rec.video.itemId, onClick: handleClickVideo(), style: {
12162
12196
  position: 'relative',
12163
12197
  width: '100%',
12164
- height
12198
+ height,
12199
+ overflow: 'hidden'
12165
12200
  } },
12166
- 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 }),
12201
+ React.createElement(FormatImage$1, { src: blurBgSrc, style: {
12202
+ height: '100%',
12203
+ width: '100%',
12204
+ objectFit: 'cover',
12205
+ filter: blur ? 'blur(10px)' : 'none',
12206
+ transform: blur ? 'scale(1.2)' : 'none'
12207
+ } }),
12208
+ React.createElement("canvas", { ref: canvasRef, style: { display: 'none' } }),
12209
+ React.createElement("div", { style: {
12210
+ position: 'absolute',
12211
+ width: '100%',
12212
+ height: 'auto',
12213
+ top: '50%',
12214
+ transform: translateY,
12215
+ left: 0,
12216
+ right: 0
12217
+ } },
12218
+ React.createElement("div", { style: { position: 'relative' } },
12219
+ 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: {
12220
+ width: '100%',
12221
+ height: 'auto',
12222
+ objectFit: 'contain'
12223
+ } }),
12224
+ renderPoster,
12225
+ 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: {
12226
+ position: 'relative',
12227
+ width: '100%',
12228
+ height,
12229
+ overflow: 'hidden'
12230
+ } },
12231
+ 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 }),
12167
12232
  renderPoster,
12168
- React.createElement("img", { hidden: !isPauseVideo, className: 'clc-pb-video-pause', src: PAUSE_ICON })));
12233
+ React.createElement("img", { hidden: !isPauseVideo, className: 'clc-pb-video-pause', src: PAUSE_ICON })))));
12169
12234
  };
12170
12235
  var VideoWidget$1 = memo(VideoWidget);
12171
12236
 
@@ -12218,21 +12283,21 @@ const FingerSwipeTip = ({ imageUrl }) => {
12218
12283
  * @Author: binruan@chatlabs.com
12219
12284
  * @Date: 2024-03-20 10:27:31
12220
12285
  * @LastEditors: binruan@chatlabs.com
12221
- * @LastEditTime: 2024-04-18 10:30:17
12286
+ * @LastEditTime: 2024-04-18 19:27:35
12222
12287
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\PictureGroup\Picture.tsx
12223
12288
  *
12224
12289
  */
12225
12290
  const Picture = (props) => {
12226
- const { src, height, width } = props;
12227
- const [blur, setBlur] = useState(false);
12228
- const onLoad = (img) => {
12229
- const aspectRatio = img.naturalHeight / img.naturalWidth;
12230
- const targetAspectRatio = 16 / 9;
12231
- const tolerance = 0.05; // 允许的宽高比误差范围
12232
- if (Math.abs(aspectRatio - targetAspectRatio) > tolerance) {
12233
- setBlur(true);
12234
- }
12235
- };
12291
+ const { src, height, imgUrlsPostConfig } = props;
12292
+ const blur = useMemo(() => {
12293
+ return (imgUrlsPostConfig === null || imgUrlsPostConfig === void 0 ? void 0 : imgUrlsPostConfig.mode) === '2';
12294
+ }, [imgUrlsPostConfig]);
12295
+ const translateY = useMemo(() => {
12296
+ var _a;
12297
+ return (imgUrlsPostConfig === null || imgUrlsPostConfig === void 0 ? void 0 : imgUrlsPostConfig.mode) === '2'
12298
+ ? `translateY(-${50 + ((_a = imgUrlsPostConfig === null || imgUrlsPostConfig === void 0 ? void 0 : imgUrlsPostConfig.offsetTop) !== null && _a !== void 0 ? _a : 0)}%)`
12299
+ : 'translateY(-50%)';
12300
+ }, [imgUrlsPostConfig]);
12236
12301
  return (React.createElement("div", { style: {
12237
12302
  overflow: 'hidden',
12238
12303
  height,
@@ -12245,13 +12310,13 @@ const Picture = (props) => {
12245
12310
  objectFit: 'cover',
12246
12311
  filter: blur ? 'blur(10px)' : 'none',
12247
12312
  transform: blur ? 'scale(1.2)' : 'none'
12248
- }, onLoad: onLoad }),
12313
+ } }),
12249
12314
  blur && (React.createElement(FormatImage$1, { src: src, style: {
12250
12315
  width: '100%',
12251
12316
  objectFit: 'contain',
12252
12317
  position: 'absolute',
12253
12318
  top: '50%',
12254
- transform: 'translateY(-50%)',
12319
+ transform: translateY,
12255
12320
  left: 0,
12256
12321
  right: 0
12257
12322
  } }))));
@@ -12261,10 +12326,11 @@ const Picture = (props) => {
12261
12326
  * @Author: lewinlu@chatlabs.com
12262
12327
  * @Date: 2024-01-03 14:39:09
12263
12328
  * @LastEditors: binruan@chatlabs.com
12264
- * @LastEditTime: 2024-04-17 18:52:45
12329
+ * @LastEditTime: 2024-04-18 19:56:22
12265
12330
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\PictureGroup\index.tsx
12266
12331
  */
12267
- const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd, onViewImageStartEvent }) => {
12332
+ const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd, onViewImageStartEvent, imgUrlsPostConfig }) => {
12333
+ var _a;
12268
12334
  const ref = useRef();
12269
12335
  const { isActive } = useSwiperSlide();
12270
12336
  const { sxpParameter, openHashtag } = useSxpDataSource();
@@ -12287,9 +12353,9 @@ const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd
12287
12353
  // if (!isActive) {
12288
12354
  // return <img src={sxpParameter?.placeholder_image} style={{ width, height, objectFit: 'cover' }} />;
12289
12355
  // }
12290
- 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) => {
12356
+ 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) => {
12291
12357
  return (React.createElement(SwiperSlide, { key: url },
12292
- React.createElement(Picture, { src: url, width: width, height: height })));
12358
+ React.createElement(Picture, { src: url, height: height, imgUrlsPostConfig: imgUrlsPostConfig })));
12293
12359
  })));
12294
12360
  };
12295
12361
  var PictureGroup$1 = memo(PictureGroup);
@@ -12471,7 +12537,7 @@ const Nudge = ({ nudge }) => {
12471
12537
  * @Author: binruan@chatlabs.com
12472
12538
  * @Date: 2024-01-15 19:03:09
12473
12539
  * @LastEditors: binruan@chatlabs.com
12474
- * @LastEditTime: 2024-04-18 16:49:34
12540
+ * @LastEditTime: 2024-04-18 19:27:03
12475
12541
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\index.tsx
12476
12542
  *
12477
12543
  */
@@ -12632,10 +12698,10 @@ const SxpPageRender = ({ globalConfig, descStyle, containerHeight = window.inner
12632
12698
  const renderContent = useCallback((rec, index) => {
12633
12699
  var _a, _b, _c, _d;
12634
12700
  if ((_a = rec.video) === null || _a === void 0 ? void 0 : _a.url) {
12635
- return (React.createElement(VideoWidget$1, { rec: rec, index: index, muted: isMuted, data: data, height: height, activeIndex: activeIndex }));
12701
+ 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 }));
12636
12702
  }
12637
12703
  if ((_b = rec.video) === null || _b === void 0 ? void 0 : _b.imgUrls) {
12638
- 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 }));
12704
+ 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 }));
12639
12705
  }
12640
12706
  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) {
12641
12707
  return (_d = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.productPost) === null || _d === void 0 ? void 0 : _d.map((value, idx) => {