pb-sxp-ui 1.0.63 → 1.0.64

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.
@@ -1,5 +1,4 @@
1
1
  import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
- import Hls from 'hls.js';
3
2
  import { useIconLink } from '../SxpPageRender/useIconLink';
4
3
  import FormatImage from '../SxpPageRender/FormatImage';
5
4
  import { useSxpDataSource } from '../../../core/hooks';
@@ -139,8 +138,8 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex, videoPostCo
139
138
  if (!videoRef.current.src) {
140
139
  const videoSrc = rec.video.url;
141
140
  if (videoSrc.includes('.m3u8')) {
142
- if (Hls.isSupported()) {
143
- const hls = new Hls();
141
+ if (typeof window !== 'undefined' && (window === null || window === void 0 ? void 0 : window.Hls.isSupported())) {
142
+ const hls = new window.Hls();
144
143
  hls.loadSource(videoSrc);
145
144
  hls.attachMedia(videoRef.current);
146
145
  }
@@ -1,4 +1,4 @@
1
- import React, { forwardRef, memo, useEffect, useImperativeHandle, useState } from 'react';
1
+ import React, { forwardRef, memo, useEffect, useImperativeHandle, useRef, useState } from 'react';
2
2
  const FormatImage = forwardRef((props, ref) => {
3
3
  const { src, onLoad, style, className, loading } = props;
4
4
  const [imgSrc, setImgSrc] = useState();
@@ -7,10 +7,28 @@ const FormatImage = forwardRef((props, ref) => {
7
7
  setImgSrc(v);
8
8
  }
9
9
  }));
10
+ const imgRef = useRef(null);
10
11
  useEffect(() => {
11
- setImgSrc(src);
12
+ let observer = null;
13
+ const { current } = imgRef;
14
+ if (current) {
15
+ observer = new IntersectionObserver((entries) => {
16
+ entries.forEach((entry) => {
17
+ if (entry.isIntersecting) {
18
+ setImgSrc(src);
19
+ observer.unobserve(current);
20
+ }
21
+ });
22
+ }, { threshold: 0.1 });
23
+ observer.observe(current);
24
+ }
25
+ return () => {
26
+ if (observer && current) {
27
+ observer.unobserve(current);
28
+ }
29
+ };
12
30
  }, [src]);
13
- return (React.createElement(React.Fragment, null, (imgSrc === null || imgSrc === void 0 ? void 0 : imgSrc.includes('.avif')) ? (React.createElement("picture", null,
31
+ return (React.createElement("div", { ref: imgRef }, (imgSrc === null || imgSrc === void 0 ? void 0 : imgSrc.includes('.avif')) ? (React.createElement("picture", null,
14
32
  React.createElement("source", { type: 'image/avif', srcSet: imgSrc }),
15
33
  React.createElement("source", { type: 'image/webp', srcSet: `${imgSrc}?imageMogr2/format/webp` }),
16
34
  React.createElement("source", { type: 'image/jpeg', srcSet: `${imgSrc}?imageMogr2/format/jpg` }),
@@ -181,6 +181,7 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex, videoPostCo
181
181
  const videoSrc = rec.video.url;
182
182
  if (!videoSrc)
183
183
  return;
184
+ videoRef === null || videoRef === void 0 ? void 0 : videoRef.src(videoSrc);
184
185
  setIsPauseVideo(false);
185
186
  const videoPlayerWrapperNode = document.querySelector(`#${videoId}`);
186
187
  const dom = document.querySelector('#player-container-id');
@@ -188,7 +189,6 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex, videoPostCo
188
189
  if (!dom && !dom2)
189
190
  return;
190
191
  videoPlayerWrapperNode === null || videoPlayerWrapperNode === void 0 ? void 0 : videoPlayerWrapperNode.appendChild(dom || dom2);
191
- videoRef === null || videoRef === void 0 ? void 0 : videoRef.src(videoSrc);
192
192
  videoRef === null || videoRef === void 0 ? void 0 : videoRef.on('loadedmetadata', handleLoadedmetadata);
193
193
  videoRef === null || videoRef === void 0 ? void 0 : videoRef.on('loadeddata', handLoadeddata);
194
194
  videoRef === null || videoRef === void 0 ? void 0 : videoRef.on('playing', handlePlaying);
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const react_1 = tslib_1.__importStar(require("react"));
5
- const hls_js_1 = tslib_1.__importDefault(require("hls.js"));
6
5
  const useIconLink_1 = require("../SxpPageRender/useIconLink");
7
6
  const FormatImage_1 = tslib_1.__importDefault(require("../SxpPageRender/FormatImage"));
8
7
  const hooks_1 = require("../../../core/hooks");
@@ -142,8 +141,8 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex, videoPostCo
142
141
  if (!videoRef.current.src) {
143
142
  const videoSrc = rec.video.url;
144
143
  if (videoSrc.includes('.m3u8')) {
145
- if (hls_js_1.default.isSupported()) {
146
- const hls = new hls_js_1.default();
144
+ if (typeof window !== 'undefined' && (window === null || window === void 0 ? void 0 : window.Hls.isSupported())) {
145
+ const hls = new window.Hls();
147
146
  hls.loadSource(videoSrc);
148
147
  hls.attachMedia(videoRef.current);
149
148
  }
@@ -10,10 +10,28 @@ const FormatImage = (0, react_1.forwardRef)((props, ref) => {
10
10
  setImgSrc(v);
11
11
  }
12
12
  }));
13
+ const imgRef = (0, react_1.useRef)(null);
13
14
  (0, react_1.useEffect)(() => {
14
- setImgSrc(src);
15
+ let observer = null;
16
+ const { current } = imgRef;
17
+ if (current) {
18
+ observer = new IntersectionObserver((entries) => {
19
+ entries.forEach((entry) => {
20
+ if (entry.isIntersecting) {
21
+ setImgSrc(src);
22
+ observer.unobserve(current);
23
+ }
24
+ });
25
+ }, { threshold: 0.1 });
26
+ observer.observe(current);
27
+ }
28
+ return () => {
29
+ if (observer && current) {
30
+ observer.unobserve(current);
31
+ }
32
+ };
15
33
  }, [src]);
16
- return (react_1.default.createElement(react_1.default.Fragment, null, (imgSrc === null || imgSrc === void 0 ? void 0 : imgSrc.includes('.avif')) ? (react_1.default.createElement("picture", null,
34
+ return (react_1.default.createElement("div", { ref: imgRef }, (imgSrc === null || imgSrc === void 0 ? void 0 : imgSrc.includes('.avif')) ? (react_1.default.createElement("picture", null,
17
35
  react_1.default.createElement("source", { type: 'image/avif', srcSet: imgSrc }),
18
36
  react_1.default.createElement("source", { type: 'image/webp', srcSet: `${imgSrc}?imageMogr2/format/webp` }),
19
37
  react_1.default.createElement("source", { type: 'image/jpeg', srcSet: `${imgSrc}?imageMogr2/format/jpg` }),
@@ -184,6 +184,7 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex, videoPostCo
184
184
  const videoSrc = rec.video.url;
185
185
  if (!videoSrc)
186
186
  return;
187
+ videoRef === null || videoRef === void 0 ? void 0 : videoRef.src(videoSrc);
187
188
  setIsPauseVideo(false);
188
189
  const videoPlayerWrapperNode = document.querySelector(`#${videoId}`);
189
190
  const dom = document.querySelector('#player-container-id');
@@ -191,7 +192,6 @@ const VideoWidget = ({ rec, index, height, data, muted, activeIndex, videoPostCo
191
192
  if (!dom && !dom2)
192
193
  return;
193
194
  videoPlayerWrapperNode === null || videoPlayerWrapperNode === void 0 ? void 0 : videoPlayerWrapperNode.appendChild(dom || dom2);
194
- videoRef === null || videoRef === void 0 ? void 0 : videoRef.src(videoSrc);
195
195
  videoRef === null || videoRef === void 0 ? void 0 : videoRef.on('loadedmetadata', handleLoadedmetadata);
196
196
  videoRef === null || videoRef === void 0 ? void 0 : videoRef.on('loadeddata', handLoadeddata);
197
197
  videoRef === null || videoRef === void 0 ? void 0 : videoRef.on('playing', handlePlaying);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pb-sxp-ui",
3
- "version": "1.0.63",
3
+ "version": "1.0.64",
4
4
  "description": "React enterprise-class UI components",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -42,7 +42,6 @@
42
42
  "antd": "^5.15.3",
43
43
  "eslint": "^8.48.0",
44
44
  "eventemitter3": "^5.0.1",
45
- "hls.js": "^1.5.8",
46
45
  "less": "^4.2.0",
47
46
  "lodash": "^4.17.21",
48
47
  "pako": "^2.1.0",