pb-sxp-ui 1.0.25 → 1.0.27

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
@@ -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
 
@@ -11974,6 +11975,8 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex, videoPostCo
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, videoPostCo
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, videoPostCo
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)
@@ -12164,21 +12185,27 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex, videoPostCo
12164
12185
  ? `translateY(-${50 + ((_a = videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.offsetTop) !== null && _a !== void 0 ? _a : 0)}%)`
12165
12186
  : 'translateY(-50%)';
12166
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]);
12167
12192
  if (!rec.video) {
12168
12193
  return null;
12169
12194
  }
12170
12195
  return (React.createElement(React.Fragment, null, blur ? (React.createElement("div", { className: 'video-container', key: rec.video.itemId, onClick: handleClickVideo(), style: {
12171
12196
  position: 'relative',
12172
12197
  width: '100%',
12173
- height
12198
+ height,
12199
+ overflow: 'hidden'
12174
12200
  } },
12175
- React.createElement(FormatImage$1, { src: sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image, style: {
12201
+ React.createElement(FormatImage$1, { src: blurBgSrc, style: {
12176
12202
  height: '100%',
12177
12203
  width: '100%',
12178
12204
  objectFit: 'cover',
12179
12205
  filter: blur ? 'blur(10px)' : 'none',
12180
12206
  transform: blur ? 'scale(1.2)' : 'none'
12181
12207
  } }),
12208
+ React.createElement("canvas", { ref: canvasRef, style: { display: 'none' } }),
12182
12209
  React.createElement("div", { style: {
12183
12210
  position: 'absolute',
12184
12211
  width: '100%',
@@ -12189,18 +12216,19 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex, videoPostCo
12189
12216
  right: 0
12190
12217
  } },
12191
12218
  React.createElement("div", { style: { position: 'relative' } },
12192
- 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, style: {
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: {
12193
12220
  width: '100%',
12194
12221
  height: 'auto',
12195
12222
  objectFit: 'contain'
12196
12223
  } }),
12197
- renderPoster,
12198
- 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: {
12224
+ React.createElement("img", { hidden: !isPauseVideo, className: 'clc-pb-video-pause', src: PAUSE_ICON }))),
12225
+ renderPoster)) : (React.createElement("div", { className: 'video-container', key: rec.video.itemId, onClick: handleClickVideo(), style: {
12199
12226
  position: 'relative',
12200
12227
  width: '100%',
12201
- height
12228
+ height,
12229
+ overflow: 'hidden'
12202
12230
  } },
12203
- 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 }),
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 }),
12204
12232
  renderPoster,
12205
12233
  React.createElement("img", { hidden: !isPauseVideo, className: 'clc-pb-video-pause', src: PAUSE_ICON })))));
12206
12234
  };
@@ -13053,4 +13081,3 @@ function useEditorDataProvider() {
13053
13081
  */
13054
13082
 
13055
13083
  export { EditorDataProvider, Modal$1 as Modal, SxpDataSourceProvider$1 as SxpDataSourceProvider, index as SxpPageCore, SxpPageRender, index$1 as core, Pagebuilder as default, defaultSetting, _materials_ as materials, useEditorDataProvider };
13056
- //# sourceMappingURL=index.js.map