pb-sxp-ui 1.0.18 → 1.0.19

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/dist/index.js CHANGED
@@ -12214,24 +12214,19 @@ const FingerSwipeTip = ({ imageUrl }) => {
12214
12214
  * @Author: binruan@chatlabs.com
12215
12215
  * @Date: 2024-03-20 10:27:31
12216
12216
  * @LastEditors: binruan@chatlabs.com
12217
- * @LastEditTime: 2024-04-17 13:55:13
12217
+ * @LastEditTime: 2024-04-17 15:37:47
12218
12218
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\PictureGroup\Picture.tsx
12219
12219
  *
12220
12220
  */
12221
12221
  const Picture = (props) => {
12222
12222
  const { src, height, width } = props;
12223
12223
  const [blur, setBlur] = useState(false);
12224
- const imgDom = useRef(null);
12225
12224
  const { sxpParameter } = useSxpDataSource();
12226
- const getAvifToPng = useCallback((src) => {
12227
- return src.indexOf('avif') !== -1 ? `${src}?imageMogr2/format/webp` : src;
12228
- }, []);
12229
12225
  useEffect(() => {
12230
- if (imgDom.current === null || src === '') {
12226
+ if (src === '' || !src)
12231
12227
  return;
12232
- }
12233
12228
  const img = new Image();
12234
- img.src = src;
12229
+ img.src = `${src}?imageMogr2/format/jpg`;
12235
12230
  img.onload = () => {
12236
12231
  const aspectRatio = img.height / img.width;
12237
12232
  const targetAspectRatio = 16 / 9;
@@ -12240,22 +12235,31 @@ const Picture = (props) => {
12240
12235
  setBlur(true);
12241
12236
  }
12242
12237
  };
12243
- imgDom.current.src = getAvifToPng(src);
12244
- }, [src, getAvifToPng]);
12238
+ }, [src]);
12239
+ const getImg = useCallback((src, style) => {
12240
+ if (src === '' || !src)
12241
+ return;
12242
+ return (React.createElement("picture", null,
12243
+ React.createElement("source", { type: 'image/avif', srcSet: `${src}?imageMogr2/format/avif` }),
12244
+ React.createElement("source", { type: 'image/webp', srcSet: `${src}?imageMogr2/format/webp` }),
12245
+ React.createElement("source", { type: 'image/jpeg', srcSet: `${src}?imageMogr2/format/jpg` }),
12246
+ React.createElement("img", { loading: 'lazy', src: src, style: style })));
12247
+ }, []);
12245
12248
  return (React.createElement("div", { style: {
12246
12249
  overflow: 'hidden',
12247
12250
  height,
12248
12251
  width: '100%',
12249
12252
  position: 'relative'
12250
12253
  } },
12251
- React.createElement("img", { ref: imgDom, loading: 'lazy', src: src ? getAvifToPng(src) : sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image, style: {
12252
- height: '100%',
12253
- width: '100%',
12254
- objectFit: 'cover',
12255
- filter: blur ? 'blur(10px)' : 'none',
12256
- transform: blur ? 'scale(1.2)' : 'none'
12257
- } }),
12258
- blur && (React.createElement("img", { ref: imgDom, src: getAvifToPng(src), loading: 'lazy', style: {
12254
+ getImg(src !== null && src !== void 0 ? src : sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image, {
12255
+ height: '100%',
12256
+ width: '100%',
12257
+ objectFit: 'cover',
12258
+ filter: blur ? 'blur(10px)' : 'none',
12259
+ transform: blur ? 'scale(1.2)' : 'none'
12260
+ }),
12261
+ blur &&
12262
+ getImg(src, {
12259
12263
  width: '100%',
12260
12264
  objectFit: 'contain',
12261
12265
  position: 'absolute',
@@ -12263,22 +12267,24 @@ const Picture = (props) => {
12263
12267
  transform: 'translateY(-50%)',
12264
12268
  left: 0,
12265
12269
  right: 0
12266
- } }))));
12270
+ })));
12267
12271
  };
12268
12272
 
12269
12273
  /*
12270
12274
  * @Author: lewinlu@chatlabs.com
12271
12275
  * @Date: 2024-01-03 14:39:09
12272
12276
  * @LastEditors: binruan@chatlabs.com
12273
- * @LastEditTime: 2024-04-17 13:53:34
12277
+ * @LastEditTime: 2024-04-17 15:15:33
12274
12278
  * @FilePath: \pb-sxp-ui\src\core\components\SxpPageRender\PictureGroup\index.tsx
12275
12279
  */
12276
12280
  const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd, onViewImageStartEvent }) => {
12281
+ const ref = useRef();
12277
12282
  const { isActive } = useSwiperSlide();
12278
12283
  const { sxpParameter, openHashtag } = useSxpDataSource();
12279
12284
  const [isLoad, setIsLoad] = useState(false);
12280
12285
  useEffect(() => {
12281
12286
  if (isLoad && isActive) {
12287
+ (ref === null || ref === void 0 ? void 0 : ref.current) && ref.current.swiper.autoplay.start();
12282
12288
  if (openHashtag) {
12283
12289
  onReportViewImageEnd(rec);
12284
12290
  }
@@ -12288,12 +12294,13 @@ const PictureGroup = ({ imgUrls, width, height, rec, index, onReportViewImageEnd
12288
12294
  }
12289
12295
  else {
12290
12296
  setIsLoad(true);
12297
+ (ref === null || ref === void 0 ? void 0 : ref.current) && ref.current.swiper.autoplay.stop();
12291
12298
  }
12292
12299
  }, [rec, isActive, onReportViewImageEnd, openHashtag, index, onViewImageStartEvent, isLoad]);
12293
12300
  // if (!isActive) {
12294
12301
  // return <img src={sxpParameter?.placeholder_image} style={{ width, height, objectFit: 'cover' }} />;
12295
12302
  // }
12296
- return (React.createElement(Swiper, { defaultValue: 0, direction: 'horizontal', modules: [Pagination, Autoplay], pagination: { clickable: true, bulletActiveClass: 'swipe-item-active-bullet' }, height: height, loop: true, autoplay: isActive ? { delay: 3000 } : false }, imgUrls === null || imgUrls === void 0 ? void 0 : imgUrls.map((url) => {
12303
+ 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) => {
12297
12304
  return (React.createElement(SwiperSlide, { key: url },
12298
12305
  React.createElement(Picture, { src: url, width: width, height: height })));
12299
12306
  })));