pixuireactcomponents 1.4.4 → 1.4.6
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/package.json
CHANGED
|
@@ -12,8 +12,9 @@ import { useEffect, useRef, useState } from 'preact/hooks';
|
|
|
12
12
|
export var LoadChecker = function (props) {
|
|
13
13
|
var children = props.children, _a = props.rootClass, rootClass = _a === void 0 ? '' : _a, _b = props.timeoutPeriod, timeoutPeriod = _b === void 0 ? 500 : _b, onLoad = props.onLoad;
|
|
14
14
|
var _c = useState(false), loaded = _c[0], setLoaded = _c[1];
|
|
15
|
-
var _d = useState(
|
|
15
|
+
var _d = useState(false), collectFinish = _d[0], setCollectFinish = _d[1];
|
|
16
16
|
var _e = useState([]), loadedElements = _e[0], setLoadedElements = _e[1];
|
|
17
|
+
var _f = useState([]), collectSrcs = _f[0], setCollectSrcs = _f[1];
|
|
17
18
|
var ref = useRef(null);
|
|
18
19
|
//0.5s后直接显示
|
|
19
20
|
useEffect(function () {
|
|
@@ -25,42 +26,60 @@ export var LoadChecker = function (props) {
|
|
|
25
26
|
setLoaded(true);
|
|
26
27
|
return;
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
+
getLoadCount(node);
|
|
30
|
+
setCollectFinish(true);
|
|
29
31
|
return function () {
|
|
30
32
|
clearTimeout(timer);
|
|
31
33
|
};
|
|
32
34
|
}, []);
|
|
33
|
-
|
|
35
|
+
useEffect(function () {
|
|
36
|
+
if (!collectFinish)
|
|
37
|
+
return;
|
|
38
|
+
if (collectSrcs.length == 0 || loadedElements.length >= collectSrcs.length) {
|
|
39
|
+
setLoaded(true);
|
|
40
|
+
onLoad && onLoad();
|
|
41
|
+
}
|
|
42
|
+
}, [loadedElements, collectFinish]);
|
|
43
|
+
var getLoadCount = function (node) {
|
|
34
44
|
if (!node)
|
|
35
|
-
return
|
|
36
|
-
var temp = 0;
|
|
45
|
+
return;
|
|
37
46
|
if (node.tagName.toLowerCase() === 'img' || (node.style && node.style.backgroundImage)) {
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
// node.id = 'img_' + cnt++;
|
|
48
|
+
setCollectSrcs(function (prevRecords) {
|
|
49
|
+
var src = getEleSrc(node);
|
|
50
|
+
if (src == '' || prevRecords.includes(src)) {
|
|
51
|
+
return prevRecords;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return __spreadArray(__spreadArray([], prevRecords, true), [src], false);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
40
57
|
node.addEventListener('load', handleLoad);
|
|
41
58
|
}
|
|
42
59
|
node.childNodes &&
|
|
43
60
|
node.childNodes.forEach(function (child) {
|
|
44
|
-
|
|
61
|
+
getLoadCount(child);
|
|
45
62
|
});
|
|
46
|
-
return
|
|
63
|
+
return;
|
|
47
64
|
};
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
65
|
+
var getEleSrc = function (node) {
|
|
66
|
+
if (node.tagName.toLowerCase() === 'img' || (node.style && node.style.backgroundImage)) {
|
|
67
|
+
var src = node.src || node.style.backgroundImage || '';
|
|
68
|
+
if (src.startsWith('url(')) {
|
|
69
|
+
src = src.substring(4, src.length - 1);
|
|
70
|
+
}
|
|
71
|
+
return src;
|
|
51
72
|
}
|
|
52
|
-
|
|
73
|
+
return '';
|
|
74
|
+
};
|
|
53
75
|
var handleLoad = function (event) {
|
|
54
76
|
setLoadedElements(function (prevElements) {
|
|
55
|
-
|
|
77
|
+
var src = getEleSrc(event.target);
|
|
78
|
+
if (src == '' || prevElements.includes(src)) {
|
|
56
79
|
return prevElements;
|
|
57
80
|
}
|
|
58
81
|
else {
|
|
59
|
-
|
|
60
|
-
if (newElements.length >= total) {
|
|
61
|
-
setLoaded(true);
|
|
62
|
-
}
|
|
63
|
-
return newElements;
|
|
82
|
+
return __spreadArray(__spreadArray([], prevElements, true), [src], false);
|
|
64
83
|
}
|
|
65
84
|
});
|
|
66
85
|
};
|
|
@@ -52,7 +52,7 @@ export var VideoPlayer = function (props) {
|
|
|
52
52
|
var _b = props.playUrl, playUrl = _b === void 0 ? '' : _b, _c = props.autoPlay, autoPlay = _c === void 0 ? true : _c, playEvent = props.playEvent, elementClass = props.elementClass, _d = props.hideSliderDuration, hideSliderDuration = _d === void 0 ? 3000 : _d, sliderBG = props.sliderBG, videoDuration = props.videoDuration, compRef = props.compRef, rootClassName = props.rootClassName;
|
|
53
53
|
var isStreaming = !playUrl.endsWith('.mp4');
|
|
54
54
|
var refVideo = useRef(null);
|
|
55
|
-
var _e = useState(VideoStatus.
|
|
55
|
+
var _e = useState(VideoStatus.Loading), videoStatus = _e[0], setVideoStatus = _e[1];
|
|
56
56
|
var _f = useState(0), currentTime = _f[0], setCurrentTime = _f[1];
|
|
57
57
|
var _g = useState(0), totalTime = _g[0], setTotalTime = _g[1];
|
|
58
58
|
var _h = useState(false), showSlider = _h[0], setShowSlider = _h[1];
|
|
@@ -155,6 +155,10 @@ export var VideoPlayer = function (props) {
|
|
|
155
155
|
videoLog('-----------onpause');
|
|
156
156
|
setVideoStatus(VideoStatus.Pause);
|
|
157
157
|
};
|
|
158
|
+
var onwaiting = function () {
|
|
159
|
+
videoLog('-----------onwaiting');
|
|
160
|
+
setVideoStatus(VideoStatus.Loading);
|
|
161
|
+
};
|
|
158
162
|
var onended = function () {
|
|
159
163
|
// 视频播放结束
|
|
160
164
|
videoLog('-----------onended');
|
|
@@ -226,7 +230,7 @@ export var VideoPlayer = function (props) {
|
|
|
226
230
|
}
|
|
227
231
|
videoLog('currentTime', currentTime, 'totalTime', totalTime);
|
|
228
232
|
return (h("div", { className: rootClassName, ref: rootRef },
|
|
229
|
-
h("video", { ref: refVideo, src: playUrl, "object-fit": "no", autoPlay: autoPlay, style: { width: '100%', height: '100%' }, onPlaying: onplaying, onPlay: onplaying, onError: onerror, onEnded: onended, onPause: onpause, onLoadStart: function () {
|
|
233
|
+
h("video", { ref: refVideo, src: playUrl, "object-fit": "no", autoPlay: autoPlay, style: { width: '100%', height: '100%' }, onPlaying: onplaying, onPlay: onplaying, onError: onerror, onEnded: onended, onPause: onpause, onWaiting: onwaiting, onLoadStart: function () {
|
|
230
234
|
console.warn('onloadstart');
|
|
231
235
|
}, onLoadedData: function () {
|
|
232
236
|
console.warn('onloadeddata');
|