pb-sxp-ui 1.15.12-alpha.8 → 1.15.13-alpha.2

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 (43) hide show
  1. package/dist/index.cjs +666 -56
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +664 -55
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.cjs +6 -6
  6. package/dist/index.min.cjs.map +1 -1
  7. package/dist/index.min.js +6 -6
  8. package/dist/index.min.js.map +1 -1
  9. package/dist/pb-ui.js +666 -56
  10. package/dist/pb-ui.js.map +1 -1
  11. package/dist/pb-ui.min.js +6 -6
  12. package/dist/pb-ui.min.js.map +1 -1
  13. package/es/core/components/DiyStoryPreview/PictureGroup.d.ts +16 -0
  14. package/es/core/components/DiyStoryPreview/PictureGroup.js +34 -0
  15. package/es/core/components/DiyStoryPreview/VideoWidget.d.ts +17 -0
  16. package/es/core/components/DiyStoryPreview/VideoWidget.js +196 -0
  17. package/es/core/components/DiyStoryPreview/index.d.ts +28 -0
  18. package/es/core/components/DiyStoryPreview/index.js +377 -0
  19. package/es/core/components/SxpPageRender/ExpandableText.js +10 -2
  20. package/es/core/components/SxpPageRender/RenderCard.js +4 -4
  21. package/es/core/context/SxpDataSourceProvider.js +5 -17
  22. package/es/index.d.ts +1 -0
  23. package/es/index.js +1 -0
  24. package/es/materials/sxp/template/MultiCommodity/index.js +1 -1
  25. package/es/materials/sxp/template/MultiCommodityDiro/index.js +2 -1
  26. package/es/materials/sxp/template/MultiCommodityDiroNew/index.js +2 -1
  27. package/es/materials/sxp/template/components/EventProvider.js +2 -2
  28. package/lib/core/components/DiyStoryPreview/PictureGroup.d.ts +16 -0
  29. package/lib/core/components/DiyStoryPreview/PictureGroup.js +37 -0
  30. package/lib/core/components/DiyStoryPreview/VideoWidget.d.ts +17 -0
  31. package/lib/core/components/DiyStoryPreview/VideoWidget.js +199 -0
  32. package/lib/core/components/DiyStoryPreview/index.d.ts +28 -0
  33. package/lib/core/components/DiyStoryPreview/index.js +380 -0
  34. package/lib/core/components/SxpPageRender/ExpandableText.js +10 -2
  35. package/lib/core/components/SxpPageRender/RenderCard.js +4 -4
  36. package/lib/core/context/SxpDataSourceProvider.js +5 -17
  37. package/lib/index.d.ts +1 -0
  38. package/lib/index.js +3 -1
  39. package/lib/materials/sxp/template/MultiCommodity/index.js +1 -1
  40. package/lib/materials/sxp/template/MultiCommodityDiro/index.js +2 -1
  41. package/lib/materials/sxp/template/MultiCommodityDiroNew/index.js +2 -1
  42. package/lib/materials/sxp/template/components/EventProvider.js +2 -2
  43. package/package.json +1 -1
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { postConfigType } from '../SxpPageRender';
3
+ import { IScene, ScenesType } from '.';
4
+ interface IPictureGroupProps {
5
+ imgUrls?: string[];
6
+ width: number;
7
+ height: number;
8
+ rec: IScene;
9
+ index: number;
10
+ imgUrlsPostConfig?: postConfigType;
11
+ swiperRef?: any;
12
+ data?: ScenesType;
13
+ loopPlay?: boolean;
14
+ }
15
+ declare const _default: React.NamedExoticComponent<IPictureGroupProps>;
16
+ export default _default;
@@ -0,0 +1,34 @@
1
+ import React, { memo, useEffect, useState } from 'react';
2
+ import { Autoplay, Pagination } from 'swiper/modules';
3
+ import { Swiper, SwiperSlide, useSwiperSlide } from 'swiper/react';
4
+ import Picture from '../SxpPageRender/PictureGroup/Picture';
5
+ const PictureGroup = ({ imgUrls, width, height, imgUrlsPostConfig, rec, index, swiperRef, data = [], loopPlay }) => {
6
+ const { isActive } = useSwiperSlide();
7
+ const [isload, setIsLoad] = useState(false);
8
+ useEffect(() => {
9
+ if (isActive && isload && loopPlay) {
10
+ setTimeout(() => {
11
+ var _a, _b, _c, _d;
12
+ if (index === (data === null || data === void 0 ? void 0 : data.length) - 1) {
13
+ (_a = swiperRef === null || swiperRef === void 0 ? void 0 : swiperRef.current) === null || _a === void 0 ? void 0 : _a.swiper.slideTo(0);
14
+ }
15
+ else {
16
+ const i = (_c = (_b = swiperRef === null || swiperRef === void 0 ? void 0 : swiperRef.current) === null || _b === void 0 ? void 0 : _b.swiper) === null || _c === void 0 ? void 0 : _c.activeIndex;
17
+ (_d = swiperRef === null || swiperRef === void 0 ? void 0 : swiperRef.current) === null || _d === void 0 ? void 0 : _d.swiper.slideTo(i + 1);
18
+ }
19
+ }, 3000);
20
+ }
21
+ }, [isActive, isload, data, index, swiperRef, loopPlay]);
22
+ const loadFinishImage = () => {
23
+ setIsLoad(true);
24
+ };
25
+ return (React.createElement(Swiper, { defaultValue: 0, direction: 'horizontal', modules: [Pagination, Autoplay], pagination: {
26
+ clickable: true,
27
+ bulletActiveClass: 'swipe-item-active-bullet',
28
+ bulletElement: 'button'
29
+ }, height: height, style: { width }, loop: true, autoplay: false }, imgUrls === null || imgUrls === void 0 ? void 0 : imgUrls.map((url) => {
30
+ return (React.createElement(SwiperSlide, { key: url },
31
+ React.createElement(Picture, { src: url, height: height, imgUrlsPostConfig: imgUrlsPostConfig, onShowFirstImage: loadFinishImage })));
32
+ })));
33
+ };
34
+ export default memo(PictureGroup);
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { postConfigType } from '../SxpPageRender';
3
+ import { IScene, ScenesType } from '.';
4
+ interface IVideoWidgetProps {
5
+ rec: IScene;
6
+ index: number;
7
+ height: number;
8
+ width: number;
9
+ data: ScenesType;
10
+ muted: boolean;
11
+ activeIndex?: number;
12
+ videoPostConfig?: postConfigType;
13
+ swiperRef?: any;
14
+ loopPlay?: boolean;
15
+ }
16
+ declare const _default: React.NamedExoticComponent<IVideoWidgetProps>;
17
+ export default _default;
@@ -0,0 +1,196 @@
1
+ import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { useSwiperSlide } from 'swiper/react';
3
+ import { useIconLink } from '../SxpPageRender/useIconLink';
4
+ import { mountVideoPlayerAtNode } from '../SxpPageRender/VideoWidget/VideoPlayer';
5
+ import { useSxpDataSource } from '../../../core/hooks';
6
+ const VideoWidget = ({ rec, index, height, data, muted, activeIndex, videoPostConfig, width, swiperRef, loopPlay }) => {
7
+ const { isActive } = useSwiperSlide();
8
+ const [isPauseVideo, setIsPauseVideo] = useState(false);
9
+ const videoRef = useRef(null);
10
+ const { bffEventReport, sxpParameter, waterFallData, openHashtag } = useSxpDataSource();
11
+ const videoStartTime = useRef(0);
12
+ const [isLoadFinish, setIsLoadFinish] = useState(false);
13
+ const [isFirstPlay, setIsFirstPlay] = useState(true);
14
+ const canvasRef = useRef(null);
15
+ const [firstFrameSrc, setFirstFrameSrc] = useState('');
16
+ const videoId = `pb-cache-video-${index}`;
17
+ const hlsRef = useRef(null);
18
+ useEffect(() => {
19
+ if (!videoRef.current)
20
+ return;
21
+ videoRef.current.muted = muted;
22
+ }, [muted]);
23
+ const handleVideoStart = useCallback(() => {
24
+ var _a;
25
+ (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.play();
26
+ }, []);
27
+ const PAUSE_ICON = useIconLink('/pb_static/06f28a2025c74c1cb49be6767316d827.png');
28
+ const handlePlaying = useCallback(() => {
29
+ var _a, _b, _c, _d, _e, _f;
30
+ setIsPauseVideo(false);
31
+ const item = data[index];
32
+ if (item && ((_a = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _a === void 0 ? void 0 : _a.duration)) {
33
+ videoStartTime.current = ((_b = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _b === void 0 ? void 0 : _b.currentTime) || 0;
34
+ const videoDuration = ((_d = (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.duration) !== null && _d !== void 0 ? _d : 0).toFixed(2);
35
+ const videoCurrentTime = ((_f = (_e = videoRef.current) === null || _e === void 0 ? void 0 : _e.currentTime) !== null && _f !== void 0 ? _f : 0).toFixed(2);
36
+ const playType = isFirstPlay ? '0' : '1';
37
+ setIsFirstPlay(false);
38
+ }
39
+ }, [bffEventReport, data, index, isFirstPlay]);
40
+ const handleLoadedMetadata = useCallback(() => {
41
+ var _a;
42
+ videoRef.current.currentTime = rec === null || rec === void 0 ? void 0 : rec.startTime;
43
+ (_a = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _a === void 0 ? void 0 : _a.play();
44
+ setIsLoadFinish(true);
45
+ }, []);
46
+ const handleClickVideo = useCallback((type) => () => {
47
+ var _a, _b, _c, _d, _e;
48
+ if (!isLoadFinish)
49
+ return;
50
+ const isPause = (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.paused;
51
+ switch (type) {
52
+ case 'start':
53
+ if (!isPause)
54
+ return;
55
+ (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.play();
56
+ setIsPauseVideo(false);
57
+ break;
58
+ case 'pause':
59
+ if (isPause)
60
+ return;
61
+ (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.pause();
62
+ setIsPauseVideo(true);
63
+ break;
64
+ default:
65
+ if (isPause) {
66
+ (_d = videoRef.current) === null || _d === void 0 ? void 0 : _d.play();
67
+ }
68
+ else {
69
+ (_e = videoRef.current) === null || _e === void 0 ? void 0 : _e.pause();
70
+ }
71
+ setIsPauseVideo(!isPause);
72
+ break;
73
+ }
74
+ }, [isLoadFinish]);
75
+ const onPause = useCallback(() => {
76
+ var _a, _b, _c, _d, _e, _f;
77
+ const item = data[index];
78
+ const videoDuration = ((_b = (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.duration) !== null && _b !== void 0 ? _b : 0).toFixed(2);
79
+ const videoCurrentTime = ((_d = (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.currentTime) !== null && _d !== void 0 ? _d : 0).toFixed(2);
80
+ if ((_e = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _e === void 0 ? void 0 : _e.duration) {
81
+ const playDuration = (((_f = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _f === void 0 ? void 0 : _f.currentTime) - videoStartTime.current).toFixed(2);
82
+ }
83
+ }, [data, index, bffEventReport]);
84
+ const blur = useMemo(() => {
85
+ return (videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.mode) === '2';
86
+ }, [videoPostConfig]);
87
+ const translateY = useMemo(() => {
88
+ var _a;
89
+ return (videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.mode) === '2'
90
+ ? `translateY(-${50 + ((_a = videoPostConfig === null || videoPostConfig === void 0 ? void 0 : videoPostConfig.offsetTop) !== null && _a !== void 0 ? _a : 0)}%) translate3d(0px, 0px, 0px)`
91
+ : 'translateY(-50%)';
92
+ }, [videoPostConfig]);
93
+ const handLoadeddata = useCallback(() => {
94
+ if (!canvasRef || !videoRef || !videoRef.current || !canvasRef.current)
95
+ return;
96
+ const video = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current;
97
+ const canvas = canvasRef === null || canvasRef === void 0 ? void 0 : canvasRef.current;
98
+ const ctx = canvas.getContext('2d');
99
+ const targetWidth = window === null || window === void 0 ? void 0 : window.innerWidth;
100
+ const targetHeight = window === null || window === void 0 ? void 0 : window.innerHeight;
101
+ canvas.height = targetHeight;
102
+ canvas.width = targetWidth;
103
+ ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
104
+ setFirstFrameSrc(canvas.toDataURL());
105
+ }, []);
106
+ const handleTimeUpload = useCallback(() => {
107
+ var _a, _b, _c;
108
+ if (!videoRef.current)
109
+ return;
110
+ if (((_a = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _a === void 0 ? void 0 : _a.currentTime) >= ((_b = rec === null || rec === void 0 ? void 0 : rec.endTime) !== null && _b !== void 0 ? _b : 0)) {
111
+ (_c = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _c === void 0 ? void 0 : _c.pause();
112
+ }
113
+ }, []);
114
+ const handlePause = () => {
115
+ var _a, _b, _c, _d, _e, _f;
116
+ if (!videoRef.current || !isActive)
117
+ return;
118
+ if (!loopPlay)
119
+ return;
120
+ if (index === (data === null || data === void 0 ? void 0 : data.length) - 1) {
121
+ (_b = (_a = swiperRef === null || swiperRef === void 0 ? void 0 : swiperRef.current) === null || _a === void 0 ? void 0 : _a.swiper) === null || _b === void 0 ? void 0 : _b.slideTo(0);
122
+ }
123
+ else {
124
+ const i = (_d = (_c = swiperRef === null || swiperRef === void 0 ? void 0 : swiperRef.current) === null || _c === void 0 ? void 0 : _c.swiper) === null || _d === void 0 ? void 0 : _d.activeIndex;
125
+ (_f = (_e = swiperRef === null || swiperRef === void 0 ? void 0 : swiperRef.current) === null || _e === void 0 ? void 0 : _e.swiper) === null || _f === void 0 ? void 0 : _f.slideTo(i + 1);
126
+ }
127
+ };
128
+ useEffect(() => {
129
+ var _a, _b, _c;
130
+ if (!isActive)
131
+ return;
132
+ const videoSrc = rec === null || rec === void 0 ? void 0 : rec.mediaUrl;
133
+ if (!videoSrc)
134
+ return;
135
+ setIsPauseVideo(false);
136
+ const videoPlayerWrapperNode = document.querySelector(`#${videoId}`);
137
+ if (!videoPlayerWrapperNode)
138
+ return;
139
+ videoRef.current = mountVideoPlayerAtNode === null || mountVideoPlayerAtNode === void 0 ? void 0 : mountVideoPlayerAtNode(videoPlayerWrapperNode);
140
+ if (!(videoRef === null || videoRef === void 0 ? void 0 : videoRef.current))
141
+ return;
142
+ const Hls = window === null || window === void 0 ? void 0 : window.Hls;
143
+ let hls = hlsRef === null || hlsRef === void 0 ? void 0 : hlsRef.current;
144
+ if (videoSrc.includes('.m3u8') && Hls && Hls.isSupported()) {
145
+ hls = new Hls();
146
+ hls === null || hls === void 0 ? void 0 : hls.loadSource(videoSrc);
147
+ hls === null || hls === void 0 ? void 0 : hls.attachMedia(videoRef === null || videoRef === void 0 ? void 0 : videoRef.current);
148
+ hls === null || hls === void 0 ? void 0 : hls.on(Hls.Events.MANIFEST_PARSED, function () {
149
+ var _a;
150
+ videoRef.current.currentTime = rec === null || rec === void 0 ? void 0 : rec.startTime;
151
+ (_a = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _a === void 0 ? void 0 : _a.play();
152
+ });
153
+ }
154
+ else {
155
+ videoRef.current.src = videoSrc;
156
+ }
157
+ (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('loadedmetadata', handleLoadedMetadata);
158
+ (_b = videoRef === null || videoRef === void 0 ? void 0 : videoRef.current) === null || _b === void 0 ? void 0 : _b.addEventListener('pause', handlePause);
159
+ (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.addEventListener('timeupdate', handleTimeUpload);
160
+ return () => {
161
+ var _a, _b, _c, _d;
162
+ if (hlsRef === null || hlsRef === void 0 ? void 0 : hlsRef.current)
163
+ (_a = hlsRef === null || hlsRef === void 0 ? void 0 : hlsRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
164
+ setIsLoadFinish(false);
165
+ (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('loadedmetadata', handleLoadedMetadata);
166
+ (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.removeEventListener('pause', handlePause);
167
+ (_d = videoRef.current) === null || _d === void 0 ? void 0 : _d.removeEventListener('timeupdate', handleTimeUpload);
168
+ };
169
+ }, [handleLoadedMetadata, handlePlaying, rec, handLoadeddata, isActive, loopPlay]);
170
+ const renderPoster = useMemo(() => {
171
+ if (!(sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image) || isLoadFinish) {
172
+ return null;
173
+ }
174
+ return (React.createElement("img", { style: { position: 'absolute', left: 0, top: 0, width: '100%', height: '100%', objectFit: 'cover' }, src: sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image, alt: 'video poster' }));
175
+ }, [isLoadFinish, sxpParameter === null || sxpParameter === void 0 ? void 0 : sxpParameter.placeholder_image]);
176
+ const blurStyle = useMemo(() => {
177
+ return blur
178
+ ? {
179
+ filter: 'blur(10px)',
180
+ transform: 'translate3d(0px, 0px, 0px) scale(1.2)'
181
+ }
182
+ : {};
183
+ }, [blur]);
184
+ if (!(rec === null || rec === void 0 ? void 0 : rec.mediaUrl)) {
185
+ return null;
186
+ }
187
+ return (React.createElement("div", { className: 'video-container', key: rec.itemId, style: {
188
+ position: 'relative',
189
+ width: '100%',
190
+ height,
191
+ overflow: 'hidden',
192
+ pointerEvents: 'none'
193
+ } },
194
+ React.createElement("div", { className: 'n-full-screen', id: videoId, style: { width: '100%', height: '100%' } })));
195
+ };
196
+ export default memo(VideoWidget);
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { ISxpPageRenderProps } from '../SxpPageRender';
3
+ import '../SxpPageRender/index.less';
4
+ export interface IScene {
5
+ blueprintStep: number;
6
+ endTime: number;
7
+ itemId: string;
8
+ mediaFileNo: string;
9
+ mediaUrl: string;
10
+ position: number;
11
+ postId: string;
12
+ sceneId: string;
13
+ sceneInfo: string;
14
+ sceneTag: string;
15
+ startTime: number;
16
+ traceInfo: string;
17
+ bindProducts?: any[];
18
+ }
19
+ export type ScenesType = IScene[];
20
+ export type DiyStoryPreviewType = ISxpPageRenderProps & {
21
+ appDomain?: string;
22
+ scenes?: ScenesType;
23
+ activeIndex?: number;
24
+ onActiveChange?: (v: number) => void;
25
+ loopPlay?: boolean;
26
+ };
27
+ declare const _default: React.NamedExoticComponent<DiyStoryPreviewType>;
28
+ export default _default;