@clyrex-digital/clyrex-controls-dev 0.8.1-dev.20261016052853 → 0.8.1-dev.20261016064336
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/{Slider-BH5S4XRN.mjs → Slider-S5M6EEBG.mjs} +235 -49
- package/dist/{Slider-XDYPGJYI.mjs → Slider-XF4ZPNIN.mjs} +235 -49
- package/dist/index.js +235 -49
- package/dist/index.mjs +1 -1
- package/dist/server.js +235 -49
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
|
@@ -31,8 +31,15 @@ var Slider = ({
|
|
|
31
31
|
);
|
|
32
32
|
const [isPlaying, setIsPlaying] = useState(autoplay);
|
|
33
33
|
const trackRef = useRef(null);
|
|
34
|
-
console.log("trackRef:", trackRef);
|
|
35
34
|
const [videoProgress, setVideoProgress] = useState(null);
|
|
35
|
+
const activeVideosRef = useRef([]);
|
|
36
|
+
const completedVideosRef = useRef(/* @__PURE__ */ new Set());
|
|
37
|
+
const nextSlideRef = useRef(() => {
|
|
38
|
+
});
|
|
39
|
+
const isPlayingRef = useRef(isPlaying);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
isPlayingRef.current = isPlaying;
|
|
42
|
+
}, [isPlaying]);
|
|
36
43
|
useEffect(() => {
|
|
37
44
|
if (typeof initialSlidesToShow === "number") {
|
|
38
45
|
setSlidesToShowState(initialSlidesToShow);
|
|
@@ -51,51 +58,6 @@ var Slider = ({
|
|
|
51
58
|
window.addEventListener("resize", handleResize);
|
|
52
59
|
return () => window.removeEventListener("resize", handleResize);
|
|
53
60
|
}, [initialSlidesToShow]);
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (!autoplay) return;
|
|
56
|
-
const activeSlideElement = trackRef.current?.children[currentSlide];
|
|
57
|
-
const videoElement = activeSlideElement?.querySelector("video");
|
|
58
|
-
if (videoElement) {
|
|
59
|
-
videoElement.loop = false;
|
|
60
|
-
setVideoProgress(0);
|
|
61
|
-
if (videoElement.ended) {
|
|
62
|
-
videoElement.currentTime = 0;
|
|
63
|
-
}
|
|
64
|
-
videoElement.play().catch(() => {
|
|
65
|
-
});
|
|
66
|
-
const handleTimeUpdate = () => {
|
|
67
|
-
if (videoElement.duration && !isNaN(videoElement.duration) && videoElement.duration > 0) {
|
|
68
|
-
const pct = videoElement.currentTime / videoElement.duration * 100;
|
|
69
|
-
setVideoProgress(pct);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
const handleVideoEnded = () => {
|
|
73
|
-
setVideoProgress(100);
|
|
74
|
-
nextSlide();
|
|
75
|
-
};
|
|
76
|
-
const handleVideoError = () => {
|
|
77
|
-
nextSlide();
|
|
78
|
-
};
|
|
79
|
-
videoElement.addEventListener("timeupdate", handleTimeUpdate);
|
|
80
|
-
videoElement.addEventListener("loadedmetadata", handleTimeUpdate);
|
|
81
|
-
videoElement.addEventListener("ended", handleVideoEnded, { once: true });
|
|
82
|
-
videoElement.addEventListener("error", handleVideoError, { once: true });
|
|
83
|
-
return () => {
|
|
84
|
-
videoElement.removeEventListener("timeupdate", handleTimeUpdate);
|
|
85
|
-
videoElement.removeEventListener("loadedmetadata", handleTimeUpdate);
|
|
86
|
-
videoElement.removeEventListener("ended", handleVideoEnded);
|
|
87
|
-
videoElement.removeEventListener("error", handleVideoError);
|
|
88
|
-
videoElement.pause();
|
|
89
|
-
setVideoProgress(null);
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
const timer = setInterval(() => {
|
|
93
|
-
if (isPlaying) {
|
|
94
|
-
nextSlide();
|
|
95
|
-
}
|
|
96
|
-
}, autoplay_speed);
|
|
97
|
-
return () => clearInterval(timer);
|
|
98
|
-
}, [autoplay, autoplay_speed, currentSlide, isPlaying]);
|
|
99
61
|
const totalSlides = Children.count(children);
|
|
100
62
|
const numColumns = columns ?? slidesToShowState;
|
|
101
63
|
const slideWidthPercentage = (() => {
|
|
@@ -111,17 +73,18 @@ var Slider = ({
|
|
|
111
73
|
const effectiveSlidesToShow = 100 / slideWidthPercentage;
|
|
112
74
|
const maxSlide = Math.max(0, Math.ceil(totalSlides - effectiveSlidesToShow));
|
|
113
75
|
const step = scrollByColumns ? Math.max(1, Math.floor(effectiveSlidesToShow)) : 1;
|
|
114
|
-
const
|
|
76
|
+
const rawPositions = Array.from(
|
|
115
77
|
{ length: Math.ceil(maxSlide / step) + 1 },
|
|
116
78
|
(_, index) => Math.min(index * step, maxSlide)
|
|
117
79
|
);
|
|
80
|
+
const slidePositions = Array.from(new Set(rawPositions));
|
|
118
81
|
const currentStepIndex = slidePositions.reduce(
|
|
119
82
|
(closestIndex, position, index) => Math.abs(position - currentSlide) < Math.abs(slidePositions[closestIndex] - currentSlide) ? index : closestIndex,
|
|
120
83
|
0
|
|
121
84
|
);
|
|
122
85
|
const nextSlide = () => {
|
|
123
86
|
if (currentStepIndex >= slidePositions.length - 1) {
|
|
124
|
-
if (infinite_scroll) {
|
|
87
|
+
if (infinite_scroll || autoplay) {
|
|
125
88
|
setTransition(true);
|
|
126
89
|
setCurrentSlide(0);
|
|
127
90
|
}
|
|
@@ -130,6 +93,7 @@ var Slider = ({
|
|
|
130
93
|
setCurrentSlide(slidePositions[currentStepIndex + 1]);
|
|
131
94
|
}
|
|
132
95
|
};
|
|
96
|
+
nextSlideRef.current = nextSlide;
|
|
133
97
|
const prevSlide = () => {
|
|
134
98
|
if (currentStepIndex <= 0) {
|
|
135
99
|
if (infinite_scroll) {
|
|
@@ -151,6 +115,228 @@ var Slider = ({
|
|
|
151
115
|
setIsPlaying(true);
|
|
152
116
|
}
|
|
153
117
|
};
|
|
118
|
+
const getVisibleSlideElements = () => {
|
|
119
|
+
if (!trackRef.current) return [];
|
|
120
|
+
const childEls = Array.from(trackRef.current.children);
|
|
121
|
+
if (childEls.length === 0) return [];
|
|
122
|
+
const container = trackRef.current.parentElement;
|
|
123
|
+
if (container) {
|
|
124
|
+
const containerRect = container.getBoundingClientRect();
|
|
125
|
+
if (containerRect.width > 0) {
|
|
126
|
+
const visibleByRect = childEls.filter((child) => {
|
|
127
|
+
const rect = child.getBoundingClientRect();
|
|
128
|
+
const visibleLeft = Math.max(containerRect.left, rect.left);
|
|
129
|
+
const visibleRight = Math.min(containerRect.right, rect.right);
|
|
130
|
+
const visibleWidth = visibleRight - visibleLeft;
|
|
131
|
+
return visibleWidth > 20 || visibleWidth / (rect.width || 1) > 0.15;
|
|
132
|
+
});
|
|
133
|
+
if (visibleByRect.length > 0) {
|
|
134
|
+
return visibleByRect;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const cols = columns ?? slidesToShowState ?? 1;
|
|
139
|
+
const numCols = Math.max(1, Math.round(effectiveSlidesToShow || cols || 1));
|
|
140
|
+
const startIndex = Math.max(0, Math.min(currentSlide, childEls.length - 1));
|
|
141
|
+
return childEls.slice(startIndex, Math.min(childEls.length, startIndex + numCols));
|
|
142
|
+
};
|
|
143
|
+
const getVisibleVideos = () => {
|
|
144
|
+
const slideEls = getVisibleSlideElements();
|
|
145
|
+
const vids = [];
|
|
146
|
+
for (const el of slideEls) {
|
|
147
|
+
const found = el.querySelectorAll("video");
|
|
148
|
+
found.forEach((v) => {
|
|
149
|
+
if (!vids.includes(v)) {
|
|
150
|
+
vids.push(v);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return vids;
|
|
155
|
+
};
|
|
156
|
+
const pauseInactiveVideos = (activeVids) => {
|
|
157
|
+
if (!trackRef.current) return;
|
|
158
|
+
const allVideos = Array.from(trackRef.current.querySelectorAll("video"));
|
|
159
|
+
for (const vid of allVideos) {
|
|
160
|
+
if (!activeVids.includes(vid)) {
|
|
161
|
+
vid.pause();
|
|
162
|
+
try {
|
|
163
|
+
if (!vid.ended && vid.currentTime > 0) {
|
|
164
|
+
vid.currentTime = 0;
|
|
165
|
+
}
|
|
166
|
+
} catch {
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (const vid of Array.from(completedVideosRef.current)) {
|
|
171
|
+
if (!activeVids.includes(vid)) {
|
|
172
|
+
completedVideosRef.current.delete(vid);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
if (!autoplay) return;
|
|
178
|
+
let isEffectActive = true;
|
|
179
|
+
let cleanupVideo = null;
|
|
180
|
+
let timer = null;
|
|
181
|
+
let observer = null;
|
|
182
|
+
const setupVisibleVideos = (videosToPlay) => {
|
|
183
|
+
if (!isEffectActive) return;
|
|
184
|
+
if (timer) {
|
|
185
|
+
clearInterval(timer);
|
|
186
|
+
timer = null;
|
|
187
|
+
}
|
|
188
|
+
const allVisVideos = getVisibleVideos();
|
|
189
|
+
pauseInactiveVideos(allVisVideos);
|
|
190
|
+
activeVideosRef.current = videosToPlay;
|
|
191
|
+
const pendingVideos = videosToPlay.filter((v) => !completedVideosRef.current.has(v));
|
|
192
|
+
if (pendingVideos.length === 0) {
|
|
193
|
+
setVideoProgress(100);
|
|
194
|
+
nextSlideRef.current();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const startedVideos = /* @__PURE__ */ new Set();
|
|
198
|
+
let hasTriggeredNext = false;
|
|
199
|
+
const checkAllPendingEnded = () => {
|
|
200
|
+
if (!isEffectActive || hasTriggeredNext) return;
|
|
201
|
+
for (const vid of pendingVideos) {
|
|
202
|
+
if (!completedVideosRef.current.has(vid)) {
|
|
203
|
+
const hasStarted = startedVideos.has(vid);
|
|
204
|
+
const isAtEnd = vid.ended || vid.duration > 0 && vid.currentTime >= vid.duration - 0.25;
|
|
205
|
+
if (hasStarted && isAtEnd) {
|
|
206
|
+
completedVideosRef.current.add(vid);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const allFinished = pendingVideos.every((v) => completedVideosRef.current.has(v));
|
|
211
|
+
if (allFinished) {
|
|
212
|
+
hasTriggeredNext = true;
|
|
213
|
+
setVideoProgress(100);
|
|
214
|
+
nextSlideRef.current();
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
const handleTimeUpdate = () => {
|
|
218
|
+
if (!isEffectActive || hasTriggeredNext) return;
|
|
219
|
+
let maxDuration = 0;
|
|
220
|
+
let activeProgress = 0;
|
|
221
|
+
for (const v of pendingVideos) {
|
|
222
|
+
if (v.currentTime > 0.05 || !v.paused) {
|
|
223
|
+
startedVideos.add(v);
|
|
224
|
+
}
|
|
225
|
+
if (v.duration && !isNaN(v.duration) && v.duration > maxDuration) {
|
|
226
|
+
maxDuration = v.duration;
|
|
227
|
+
activeProgress = v.currentTime / v.duration * 100;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (maxDuration > 0) {
|
|
231
|
+
setVideoProgress(Math.min(100, Math.max(0, activeProgress)));
|
|
232
|
+
}
|
|
233
|
+
checkAllPendingEnded();
|
|
234
|
+
};
|
|
235
|
+
const handleVideoEnded = (e) => {
|
|
236
|
+
const vid = e.target;
|
|
237
|
+
if (vid) {
|
|
238
|
+
startedVideos.add(vid);
|
|
239
|
+
completedVideosRef.current.add(vid);
|
|
240
|
+
}
|
|
241
|
+
checkAllPendingEnded();
|
|
242
|
+
};
|
|
243
|
+
const handlePlaying = (e) => {
|
|
244
|
+
const vid = e.target;
|
|
245
|
+
if (vid) {
|
|
246
|
+
startedVideos.add(vid);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
const handleVideoError = (e) => {
|
|
250
|
+
const vid = e.target;
|
|
251
|
+
if (vid) {
|
|
252
|
+
completedVideosRef.current.add(vid);
|
|
253
|
+
}
|
|
254
|
+
checkAllPendingEnded();
|
|
255
|
+
};
|
|
256
|
+
for (const vid of pendingVideos) {
|
|
257
|
+
vid.muted = true;
|
|
258
|
+
vid.defaultMuted = true;
|
|
259
|
+
vid.playsInline = true;
|
|
260
|
+
vid.loop = false;
|
|
261
|
+
vid.removeAttribute("loop");
|
|
262
|
+
if (vid.ended || vid.duration && vid.currentTime >= vid.duration - 0.25) {
|
|
263
|
+
vid.currentTime = 0;
|
|
264
|
+
vid.play().catch(() => {
|
|
265
|
+
});
|
|
266
|
+
} else if (vid.paused && vid.currentTime === 0) {
|
|
267
|
+
vid.play().catch(() => {
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
vid.addEventListener("timeupdate", handleTimeUpdate);
|
|
271
|
+
vid.addEventListener("loadedmetadata", handleTimeUpdate);
|
|
272
|
+
vid.addEventListener("ended", handleVideoEnded);
|
|
273
|
+
vid.addEventListener("playing", handlePlaying);
|
|
274
|
+
vid.addEventListener("error", handleVideoError);
|
|
275
|
+
}
|
|
276
|
+
cleanupVideo = () => {
|
|
277
|
+
for (const vid of pendingVideos) {
|
|
278
|
+
vid.removeEventListener("timeupdate", handleTimeUpdate);
|
|
279
|
+
vid.removeEventListener("loadedmetadata", handleTimeUpdate);
|
|
280
|
+
vid.removeEventListener("ended", handleVideoEnded);
|
|
281
|
+
vid.removeEventListener("playing", handlePlaying);
|
|
282
|
+
vid.removeEventListener("error", handleVideoError);
|
|
283
|
+
}
|
|
284
|
+
activeVideosRef.current = [];
|
|
285
|
+
setVideoProgress(null);
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
const initialVideos = getVisibleVideos();
|
|
289
|
+
const initialPending = initialVideos.filter((v) => !completedVideosRef.current.has(v));
|
|
290
|
+
if (initialPending.length > 0) {
|
|
291
|
+
setupVisibleVideos(initialPending);
|
|
292
|
+
} else {
|
|
293
|
+
pauseInactiveVideos([]);
|
|
294
|
+
activeVideosRef.current = [];
|
|
295
|
+
setVideoProgress(null);
|
|
296
|
+
if (trackRef.current && typeof MutationObserver !== "undefined") {
|
|
297
|
+
observer = new MutationObserver(() => {
|
|
298
|
+
const asyncVideos = getVisibleVideos();
|
|
299
|
+
const asyncPending = asyncVideos.filter((v) => !completedVideosRef.current.has(v));
|
|
300
|
+
if (asyncPending.length > 0) {
|
|
301
|
+
const hasNew = asyncPending.some((v) => !activeVideosRef.current.includes(v));
|
|
302
|
+
if (hasNew) {
|
|
303
|
+
if (observer) {
|
|
304
|
+
observer.disconnect();
|
|
305
|
+
observer = null;
|
|
306
|
+
}
|
|
307
|
+
setupVisibleVideos(asyncPending);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
observer.observe(trackRef.current, { childList: true, subtree: true });
|
|
312
|
+
}
|
|
313
|
+
timer = setInterval(() => {
|
|
314
|
+
const currentVids = getVisibleVideos();
|
|
315
|
+
const currentPending = currentVids.filter((v) => !completedVideosRef.current.has(v));
|
|
316
|
+
if (currentPending.length > 0) {
|
|
317
|
+
clearInterval(timer);
|
|
318
|
+
timer = null;
|
|
319
|
+
setupVisibleVideos(currentPending);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (isPlayingRef.current) {
|
|
323
|
+
nextSlideRef.current();
|
|
324
|
+
}
|
|
325
|
+
}, autoplay_speed);
|
|
326
|
+
}
|
|
327
|
+
return () => {
|
|
328
|
+
isEffectActive = false;
|
|
329
|
+
if (cleanupVideo) {
|
|
330
|
+
cleanupVideo();
|
|
331
|
+
}
|
|
332
|
+
if (timer) {
|
|
333
|
+
clearInterval(timer);
|
|
334
|
+
}
|
|
335
|
+
if (observer) {
|
|
336
|
+
observer.disconnect();
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
}, [autoplay, autoplay_speed, currentSlide, slidesToShowState, columns]);
|
|
154
340
|
const handleMouseEnter = () => {
|
|
155
341
|
if (autoplay) {
|
|
156
342
|
setIsPlaying(false);
|
|
@@ -346,7 +532,7 @@ var ProgressPill = ({
|
|
|
346
532
|
}
|
|
347
533
|
};
|
|
348
534
|
const renderProgressBar = () => {
|
|
349
|
-
if (style === "modern" && isActive) {
|
|
535
|
+
if ((style === "modern" || style === "cumulative") && isActive) {
|
|
350
536
|
const displayProgress = customProgress ?? progress;
|
|
351
537
|
return /* @__PURE__ */ jsx(
|
|
352
538
|
"div",
|
|
@@ -33,8 +33,15 @@ var Slider = ({
|
|
|
33
33
|
);
|
|
34
34
|
const [isPlaying, setIsPlaying] = useState(autoplay);
|
|
35
35
|
const trackRef = useRef(null);
|
|
36
|
-
console.log("trackRef:", trackRef);
|
|
37
36
|
const [videoProgress, setVideoProgress] = useState(null);
|
|
37
|
+
const activeVideosRef = useRef([]);
|
|
38
|
+
const completedVideosRef = useRef(/* @__PURE__ */ new Set());
|
|
39
|
+
const nextSlideRef = useRef(() => {
|
|
40
|
+
});
|
|
41
|
+
const isPlayingRef = useRef(isPlaying);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
isPlayingRef.current = isPlaying;
|
|
44
|
+
}, [isPlaying]);
|
|
38
45
|
useEffect(() => {
|
|
39
46
|
if (typeof initialSlidesToShow === "number") {
|
|
40
47
|
setSlidesToShowState(initialSlidesToShow);
|
|
@@ -53,51 +60,6 @@ var Slider = ({
|
|
|
53
60
|
window.addEventListener("resize", handleResize);
|
|
54
61
|
return () => window.removeEventListener("resize", handleResize);
|
|
55
62
|
}, [initialSlidesToShow]);
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
if (!autoplay) return;
|
|
58
|
-
const activeSlideElement = trackRef.current?.children[currentSlide];
|
|
59
|
-
const videoElement = activeSlideElement?.querySelector("video");
|
|
60
|
-
if (videoElement) {
|
|
61
|
-
videoElement.loop = false;
|
|
62
|
-
setVideoProgress(0);
|
|
63
|
-
if (videoElement.ended) {
|
|
64
|
-
videoElement.currentTime = 0;
|
|
65
|
-
}
|
|
66
|
-
videoElement.play().catch(() => {
|
|
67
|
-
});
|
|
68
|
-
const handleTimeUpdate = () => {
|
|
69
|
-
if (videoElement.duration && !isNaN(videoElement.duration) && videoElement.duration > 0) {
|
|
70
|
-
const pct = videoElement.currentTime / videoElement.duration * 100;
|
|
71
|
-
setVideoProgress(pct);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
const handleVideoEnded = () => {
|
|
75
|
-
setVideoProgress(100);
|
|
76
|
-
nextSlide();
|
|
77
|
-
};
|
|
78
|
-
const handleVideoError = () => {
|
|
79
|
-
nextSlide();
|
|
80
|
-
};
|
|
81
|
-
videoElement.addEventListener("timeupdate", handleTimeUpdate);
|
|
82
|
-
videoElement.addEventListener("loadedmetadata", handleTimeUpdate);
|
|
83
|
-
videoElement.addEventListener("ended", handleVideoEnded, { once: true });
|
|
84
|
-
videoElement.addEventListener("error", handleVideoError, { once: true });
|
|
85
|
-
return () => {
|
|
86
|
-
videoElement.removeEventListener("timeupdate", handleTimeUpdate);
|
|
87
|
-
videoElement.removeEventListener("loadedmetadata", handleTimeUpdate);
|
|
88
|
-
videoElement.removeEventListener("ended", handleVideoEnded);
|
|
89
|
-
videoElement.removeEventListener("error", handleVideoError);
|
|
90
|
-
videoElement.pause();
|
|
91
|
-
setVideoProgress(null);
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
const timer = setInterval(() => {
|
|
95
|
-
if (isPlaying) {
|
|
96
|
-
nextSlide();
|
|
97
|
-
}
|
|
98
|
-
}, autoplay_speed);
|
|
99
|
-
return () => clearInterval(timer);
|
|
100
|
-
}, [autoplay, autoplay_speed, currentSlide, isPlaying]);
|
|
101
63
|
const totalSlides = Children.count(children);
|
|
102
64
|
const numColumns = columns ?? slidesToShowState;
|
|
103
65
|
const slideWidthPercentage = (() => {
|
|
@@ -113,17 +75,18 @@ var Slider = ({
|
|
|
113
75
|
const effectiveSlidesToShow = 100 / slideWidthPercentage;
|
|
114
76
|
const maxSlide = Math.max(0, Math.ceil(totalSlides - effectiveSlidesToShow));
|
|
115
77
|
const step = scrollByColumns ? Math.max(1, Math.floor(effectiveSlidesToShow)) : 1;
|
|
116
|
-
const
|
|
78
|
+
const rawPositions = Array.from(
|
|
117
79
|
{ length: Math.ceil(maxSlide / step) + 1 },
|
|
118
80
|
(_, index) => Math.min(index * step, maxSlide)
|
|
119
81
|
);
|
|
82
|
+
const slidePositions = Array.from(new Set(rawPositions));
|
|
120
83
|
const currentStepIndex = slidePositions.reduce(
|
|
121
84
|
(closestIndex, position, index) => Math.abs(position - currentSlide) < Math.abs(slidePositions[closestIndex] - currentSlide) ? index : closestIndex,
|
|
122
85
|
0
|
|
123
86
|
);
|
|
124
87
|
const nextSlide = () => {
|
|
125
88
|
if (currentStepIndex >= slidePositions.length - 1) {
|
|
126
|
-
if (infinite_scroll) {
|
|
89
|
+
if (infinite_scroll || autoplay) {
|
|
127
90
|
setTransition(true);
|
|
128
91
|
setCurrentSlide(0);
|
|
129
92
|
}
|
|
@@ -132,6 +95,7 @@ var Slider = ({
|
|
|
132
95
|
setCurrentSlide(slidePositions[currentStepIndex + 1]);
|
|
133
96
|
}
|
|
134
97
|
};
|
|
98
|
+
nextSlideRef.current = nextSlide;
|
|
135
99
|
const prevSlide = () => {
|
|
136
100
|
if (currentStepIndex <= 0) {
|
|
137
101
|
if (infinite_scroll) {
|
|
@@ -153,6 +117,228 @@ var Slider = ({
|
|
|
153
117
|
setIsPlaying(true);
|
|
154
118
|
}
|
|
155
119
|
};
|
|
120
|
+
const getVisibleSlideElements = () => {
|
|
121
|
+
if (!trackRef.current) return [];
|
|
122
|
+
const childEls = Array.from(trackRef.current.children);
|
|
123
|
+
if (childEls.length === 0) return [];
|
|
124
|
+
const container = trackRef.current.parentElement;
|
|
125
|
+
if (container) {
|
|
126
|
+
const containerRect = container.getBoundingClientRect();
|
|
127
|
+
if (containerRect.width > 0) {
|
|
128
|
+
const visibleByRect = childEls.filter((child) => {
|
|
129
|
+
const rect = child.getBoundingClientRect();
|
|
130
|
+
const visibleLeft = Math.max(containerRect.left, rect.left);
|
|
131
|
+
const visibleRight = Math.min(containerRect.right, rect.right);
|
|
132
|
+
const visibleWidth = visibleRight - visibleLeft;
|
|
133
|
+
return visibleWidth > 20 || visibleWidth / (rect.width || 1) > 0.15;
|
|
134
|
+
});
|
|
135
|
+
if (visibleByRect.length > 0) {
|
|
136
|
+
return visibleByRect;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const cols = columns ?? slidesToShowState ?? 1;
|
|
141
|
+
const numCols = Math.max(1, Math.round(effectiveSlidesToShow || cols || 1));
|
|
142
|
+
const startIndex = Math.max(0, Math.min(currentSlide, childEls.length - 1));
|
|
143
|
+
return childEls.slice(startIndex, Math.min(childEls.length, startIndex + numCols));
|
|
144
|
+
};
|
|
145
|
+
const getVisibleVideos = () => {
|
|
146
|
+
const slideEls = getVisibleSlideElements();
|
|
147
|
+
const vids = [];
|
|
148
|
+
for (const el of slideEls) {
|
|
149
|
+
const found = el.querySelectorAll("video");
|
|
150
|
+
found.forEach((v) => {
|
|
151
|
+
if (!vids.includes(v)) {
|
|
152
|
+
vids.push(v);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return vids;
|
|
157
|
+
};
|
|
158
|
+
const pauseInactiveVideos = (activeVids) => {
|
|
159
|
+
if (!trackRef.current) return;
|
|
160
|
+
const allVideos = Array.from(trackRef.current.querySelectorAll("video"));
|
|
161
|
+
for (const vid of allVideos) {
|
|
162
|
+
if (!activeVids.includes(vid)) {
|
|
163
|
+
vid.pause();
|
|
164
|
+
try {
|
|
165
|
+
if (!vid.ended && vid.currentTime > 0) {
|
|
166
|
+
vid.currentTime = 0;
|
|
167
|
+
}
|
|
168
|
+
} catch {
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
for (const vid of Array.from(completedVideosRef.current)) {
|
|
173
|
+
if (!activeVids.includes(vid)) {
|
|
174
|
+
completedVideosRef.current.delete(vid);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
if (!autoplay) return;
|
|
180
|
+
let isEffectActive = true;
|
|
181
|
+
let cleanupVideo = null;
|
|
182
|
+
let timer = null;
|
|
183
|
+
let observer = null;
|
|
184
|
+
const setupVisibleVideos = (videosToPlay) => {
|
|
185
|
+
if (!isEffectActive) return;
|
|
186
|
+
if (timer) {
|
|
187
|
+
clearInterval(timer);
|
|
188
|
+
timer = null;
|
|
189
|
+
}
|
|
190
|
+
const allVisVideos = getVisibleVideos();
|
|
191
|
+
pauseInactiveVideos(allVisVideos);
|
|
192
|
+
activeVideosRef.current = videosToPlay;
|
|
193
|
+
const pendingVideos = videosToPlay.filter((v) => !completedVideosRef.current.has(v));
|
|
194
|
+
if (pendingVideos.length === 0) {
|
|
195
|
+
setVideoProgress(100);
|
|
196
|
+
nextSlideRef.current();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const startedVideos = /* @__PURE__ */ new Set();
|
|
200
|
+
let hasTriggeredNext = false;
|
|
201
|
+
const checkAllPendingEnded = () => {
|
|
202
|
+
if (!isEffectActive || hasTriggeredNext) return;
|
|
203
|
+
for (const vid of pendingVideos) {
|
|
204
|
+
if (!completedVideosRef.current.has(vid)) {
|
|
205
|
+
const hasStarted = startedVideos.has(vid);
|
|
206
|
+
const isAtEnd = vid.ended || vid.duration > 0 && vid.currentTime >= vid.duration - 0.25;
|
|
207
|
+
if (hasStarted && isAtEnd) {
|
|
208
|
+
completedVideosRef.current.add(vid);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const allFinished = pendingVideos.every((v) => completedVideosRef.current.has(v));
|
|
213
|
+
if (allFinished) {
|
|
214
|
+
hasTriggeredNext = true;
|
|
215
|
+
setVideoProgress(100);
|
|
216
|
+
nextSlideRef.current();
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
const handleTimeUpdate = () => {
|
|
220
|
+
if (!isEffectActive || hasTriggeredNext) return;
|
|
221
|
+
let maxDuration = 0;
|
|
222
|
+
let activeProgress = 0;
|
|
223
|
+
for (const v of pendingVideos) {
|
|
224
|
+
if (v.currentTime > 0.05 || !v.paused) {
|
|
225
|
+
startedVideos.add(v);
|
|
226
|
+
}
|
|
227
|
+
if (v.duration && !isNaN(v.duration) && v.duration > maxDuration) {
|
|
228
|
+
maxDuration = v.duration;
|
|
229
|
+
activeProgress = v.currentTime / v.duration * 100;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (maxDuration > 0) {
|
|
233
|
+
setVideoProgress(Math.min(100, Math.max(0, activeProgress)));
|
|
234
|
+
}
|
|
235
|
+
checkAllPendingEnded();
|
|
236
|
+
};
|
|
237
|
+
const handleVideoEnded = (e) => {
|
|
238
|
+
const vid = e.target;
|
|
239
|
+
if (vid) {
|
|
240
|
+
startedVideos.add(vid);
|
|
241
|
+
completedVideosRef.current.add(vid);
|
|
242
|
+
}
|
|
243
|
+
checkAllPendingEnded();
|
|
244
|
+
};
|
|
245
|
+
const handlePlaying = (e) => {
|
|
246
|
+
const vid = e.target;
|
|
247
|
+
if (vid) {
|
|
248
|
+
startedVideos.add(vid);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
const handleVideoError = (e) => {
|
|
252
|
+
const vid = e.target;
|
|
253
|
+
if (vid) {
|
|
254
|
+
completedVideosRef.current.add(vid);
|
|
255
|
+
}
|
|
256
|
+
checkAllPendingEnded();
|
|
257
|
+
};
|
|
258
|
+
for (const vid of pendingVideos) {
|
|
259
|
+
vid.muted = true;
|
|
260
|
+
vid.defaultMuted = true;
|
|
261
|
+
vid.playsInline = true;
|
|
262
|
+
vid.loop = false;
|
|
263
|
+
vid.removeAttribute("loop");
|
|
264
|
+
if (vid.ended || vid.duration && vid.currentTime >= vid.duration - 0.25) {
|
|
265
|
+
vid.currentTime = 0;
|
|
266
|
+
vid.play().catch(() => {
|
|
267
|
+
});
|
|
268
|
+
} else if (vid.paused && vid.currentTime === 0) {
|
|
269
|
+
vid.play().catch(() => {
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
vid.addEventListener("timeupdate", handleTimeUpdate);
|
|
273
|
+
vid.addEventListener("loadedmetadata", handleTimeUpdate);
|
|
274
|
+
vid.addEventListener("ended", handleVideoEnded);
|
|
275
|
+
vid.addEventListener("playing", handlePlaying);
|
|
276
|
+
vid.addEventListener("error", handleVideoError);
|
|
277
|
+
}
|
|
278
|
+
cleanupVideo = () => {
|
|
279
|
+
for (const vid of pendingVideos) {
|
|
280
|
+
vid.removeEventListener("timeupdate", handleTimeUpdate);
|
|
281
|
+
vid.removeEventListener("loadedmetadata", handleTimeUpdate);
|
|
282
|
+
vid.removeEventListener("ended", handleVideoEnded);
|
|
283
|
+
vid.removeEventListener("playing", handlePlaying);
|
|
284
|
+
vid.removeEventListener("error", handleVideoError);
|
|
285
|
+
}
|
|
286
|
+
activeVideosRef.current = [];
|
|
287
|
+
setVideoProgress(null);
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
const initialVideos = getVisibleVideos();
|
|
291
|
+
const initialPending = initialVideos.filter((v) => !completedVideosRef.current.has(v));
|
|
292
|
+
if (initialPending.length > 0) {
|
|
293
|
+
setupVisibleVideos(initialPending);
|
|
294
|
+
} else {
|
|
295
|
+
pauseInactiveVideos([]);
|
|
296
|
+
activeVideosRef.current = [];
|
|
297
|
+
setVideoProgress(null);
|
|
298
|
+
if (trackRef.current && typeof MutationObserver !== "undefined") {
|
|
299
|
+
observer = new MutationObserver(() => {
|
|
300
|
+
const asyncVideos = getVisibleVideos();
|
|
301
|
+
const asyncPending = asyncVideos.filter((v) => !completedVideosRef.current.has(v));
|
|
302
|
+
if (asyncPending.length > 0) {
|
|
303
|
+
const hasNew = asyncPending.some((v) => !activeVideosRef.current.includes(v));
|
|
304
|
+
if (hasNew) {
|
|
305
|
+
if (observer) {
|
|
306
|
+
observer.disconnect();
|
|
307
|
+
observer = null;
|
|
308
|
+
}
|
|
309
|
+
setupVisibleVideos(asyncPending);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
observer.observe(trackRef.current, { childList: true, subtree: true });
|
|
314
|
+
}
|
|
315
|
+
timer = setInterval(() => {
|
|
316
|
+
const currentVids = getVisibleVideos();
|
|
317
|
+
const currentPending = currentVids.filter((v) => !completedVideosRef.current.has(v));
|
|
318
|
+
if (currentPending.length > 0) {
|
|
319
|
+
clearInterval(timer);
|
|
320
|
+
timer = null;
|
|
321
|
+
setupVisibleVideos(currentPending);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (isPlayingRef.current) {
|
|
325
|
+
nextSlideRef.current();
|
|
326
|
+
}
|
|
327
|
+
}, autoplay_speed);
|
|
328
|
+
}
|
|
329
|
+
return () => {
|
|
330
|
+
isEffectActive = false;
|
|
331
|
+
if (cleanupVideo) {
|
|
332
|
+
cleanupVideo();
|
|
333
|
+
}
|
|
334
|
+
if (timer) {
|
|
335
|
+
clearInterval(timer);
|
|
336
|
+
}
|
|
337
|
+
if (observer) {
|
|
338
|
+
observer.disconnect();
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
}, [autoplay, autoplay_speed, currentSlide, slidesToShowState, columns]);
|
|
156
342
|
const handleMouseEnter = () => {
|
|
157
343
|
if (autoplay) {
|
|
158
344
|
setIsPlaying(false);
|
|
@@ -348,7 +534,7 @@ var ProgressPill = ({
|
|
|
348
534
|
}
|
|
349
535
|
};
|
|
350
536
|
const renderProgressBar = () => {
|
|
351
|
-
if (style === "modern" && isActive) {
|
|
537
|
+
if ((style === "modern" || style === "cumulative") && isActive) {
|
|
352
538
|
const displayProgress = customProgress ?? progress;
|
|
353
539
|
return /* @__PURE__ */ jsx(
|
|
354
540
|
"div",
|
package/dist/index.js
CHANGED
|
@@ -7195,8 +7195,15 @@ var init_Slider = __esm({
|
|
|
7195
7195
|
);
|
|
7196
7196
|
const [isPlaying, setIsPlaying] = (0, import_react62.useState)(autoplay);
|
|
7197
7197
|
const trackRef = (0, import_react62.useRef)(null);
|
|
7198
|
-
console.log("trackRef:", trackRef);
|
|
7199
7198
|
const [videoProgress, setVideoProgress] = (0, import_react62.useState)(null);
|
|
7199
|
+
const activeVideosRef = (0, import_react62.useRef)([]);
|
|
7200
|
+
const completedVideosRef = (0, import_react62.useRef)(/* @__PURE__ */ new Set());
|
|
7201
|
+
const nextSlideRef = (0, import_react62.useRef)(() => {
|
|
7202
|
+
});
|
|
7203
|
+
const isPlayingRef = (0, import_react62.useRef)(isPlaying);
|
|
7204
|
+
(0, import_react62.useEffect)(() => {
|
|
7205
|
+
isPlayingRef.current = isPlaying;
|
|
7206
|
+
}, [isPlaying]);
|
|
7200
7207
|
(0, import_react62.useEffect)(() => {
|
|
7201
7208
|
if (typeof initialSlidesToShow === "number") {
|
|
7202
7209
|
setSlidesToShowState(initialSlidesToShow);
|
|
@@ -7215,51 +7222,6 @@ var init_Slider = __esm({
|
|
|
7215
7222
|
window.addEventListener("resize", handleResize);
|
|
7216
7223
|
return () => window.removeEventListener("resize", handleResize);
|
|
7217
7224
|
}, [initialSlidesToShow]);
|
|
7218
|
-
(0, import_react62.useEffect)(() => {
|
|
7219
|
-
if (!autoplay) return;
|
|
7220
|
-
const activeSlideElement = trackRef.current?.children[currentSlide];
|
|
7221
|
-
const videoElement = activeSlideElement?.querySelector("video");
|
|
7222
|
-
if (videoElement) {
|
|
7223
|
-
videoElement.loop = false;
|
|
7224
|
-
setVideoProgress(0);
|
|
7225
|
-
if (videoElement.ended) {
|
|
7226
|
-
videoElement.currentTime = 0;
|
|
7227
|
-
}
|
|
7228
|
-
videoElement.play().catch(() => {
|
|
7229
|
-
});
|
|
7230
|
-
const handleTimeUpdate = () => {
|
|
7231
|
-
if (videoElement.duration && !isNaN(videoElement.duration) && videoElement.duration > 0) {
|
|
7232
|
-
const pct = videoElement.currentTime / videoElement.duration * 100;
|
|
7233
|
-
setVideoProgress(pct);
|
|
7234
|
-
}
|
|
7235
|
-
};
|
|
7236
|
-
const handleVideoEnded = () => {
|
|
7237
|
-
setVideoProgress(100);
|
|
7238
|
-
nextSlide();
|
|
7239
|
-
};
|
|
7240
|
-
const handleVideoError = () => {
|
|
7241
|
-
nextSlide();
|
|
7242
|
-
};
|
|
7243
|
-
videoElement.addEventListener("timeupdate", handleTimeUpdate);
|
|
7244
|
-
videoElement.addEventListener("loadedmetadata", handleTimeUpdate);
|
|
7245
|
-
videoElement.addEventListener("ended", handleVideoEnded, { once: true });
|
|
7246
|
-
videoElement.addEventListener("error", handleVideoError, { once: true });
|
|
7247
|
-
return () => {
|
|
7248
|
-
videoElement.removeEventListener("timeupdate", handleTimeUpdate);
|
|
7249
|
-
videoElement.removeEventListener("loadedmetadata", handleTimeUpdate);
|
|
7250
|
-
videoElement.removeEventListener("ended", handleVideoEnded);
|
|
7251
|
-
videoElement.removeEventListener("error", handleVideoError);
|
|
7252
|
-
videoElement.pause();
|
|
7253
|
-
setVideoProgress(null);
|
|
7254
|
-
};
|
|
7255
|
-
}
|
|
7256
|
-
const timer = setInterval(() => {
|
|
7257
|
-
if (isPlaying) {
|
|
7258
|
-
nextSlide();
|
|
7259
|
-
}
|
|
7260
|
-
}, autoplay_speed);
|
|
7261
|
-
return () => clearInterval(timer);
|
|
7262
|
-
}, [autoplay, autoplay_speed, currentSlide, isPlaying]);
|
|
7263
7225
|
const totalSlides = import_react62.Children.count(children);
|
|
7264
7226
|
const numColumns = columns ?? slidesToShowState;
|
|
7265
7227
|
const slideWidthPercentage = (() => {
|
|
@@ -7275,17 +7237,18 @@ var init_Slider = __esm({
|
|
|
7275
7237
|
const effectiveSlidesToShow = 100 / slideWidthPercentage;
|
|
7276
7238
|
const maxSlide = Math.max(0, Math.ceil(totalSlides - effectiveSlidesToShow));
|
|
7277
7239
|
const step = scrollByColumns ? Math.max(1, Math.floor(effectiveSlidesToShow)) : 1;
|
|
7278
|
-
const
|
|
7240
|
+
const rawPositions = Array.from(
|
|
7279
7241
|
{ length: Math.ceil(maxSlide / step) + 1 },
|
|
7280
7242
|
(_, index) => Math.min(index * step, maxSlide)
|
|
7281
7243
|
);
|
|
7244
|
+
const slidePositions = Array.from(new Set(rawPositions));
|
|
7282
7245
|
const currentStepIndex = slidePositions.reduce(
|
|
7283
7246
|
(closestIndex, position, index) => Math.abs(position - currentSlide) < Math.abs(slidePositions[closestIndex] - currentSlide) ? index : closestIndex,
|
|
7284
7247
|
0
|
|
7285
7248
|
);
|
|
7286
7249
|
const nextSlide = () => {
|
|
7287
7250
|
if (currentStepIndex >= slidePositions.length - 1) {
|
|
7288
|
-
if (infinite_scroll) {
|
|
7251
|
+
if (infinite_scroll || autoplay) {
|
|
7289
7252
|
setTransition(true);
|
|
7290
7253
|
setCurrentSlide(0);
|
|
7291
7254
|
}
|
|
@@ -7294,6 +7257,7 @@ var init_Slider = __esm({
|
|
|
7294
7257
|
setCurrentSlide(slidePositions[currentStepIndex + 1]);
|
|
7295
7258
|
}
|
|
7296
7259
|
};
|
|
7260
|
+
nextSlideRef.current = nextSlide;
|
|
7297
7261
|
const prevSlide = () => {
|
|
7298
7262
|
if (currentStepIndex <= 0) {
|
|
7299
7263
|
if (infinite_scroll) {
|
|
@@ -7315,6 +7279,228 @@ var init_Slider = __esm({
|
|
|
7315
7279
|
setIsPlaying(true);
|
|
7316
7280
|
}
|
|
7317
7281
|
};
|
|
7282
|
+
const getVisibleSlideElements = () => {
|
|
7283
|
+
if (!trackRef.current) return [];
|
|
7284
|
+
const childEls = Array.from(trackRef.current.children);
|
|
7285
|
+
if (childEls.length === 0) return [];
|
|
7286
|
+
const container = trackRef.current.parentElement;
|
|
7287
|
+
if (container) {
|
|
7288
|
+
const containerRect = container.getBoundingClientRect();
|
|
7289
|
+
if (containerRect.width > 0) {
|
|
7290
|
+
const visibleByRect = childEls.filter((child) => {
|
|
7291
|
+
const rect = child.getBoundingClientRect();
|
|
7292
|
+
const visibleLeft = Math.max(containerRect.left, rect.left);
|
|
7293
|
+
const visibleRight = Math.min(containerRect.right, rect.right);
|
|
7294
|
+
const visibleWidth = visibleRight - visibleLeft;
|
|
7295
|
+
return visibleWidth > 20 || visibleWidth / (rect.width || 1) > 0.15;
|
|
7296
|
+
});
|
|
7297
|
+
if (visibleByRect.length > 0) {
|
|
7298
|
+
return visibleByRect;
|
|
7299
|
+
}
|
|
7300
|
+
}
|
|
7301
|
+
}
|
|
7302
|
+
const cols = columns ?? slidesToShowState ?? 1;
|
|
7303
|
+
const numCols = Math.max(1, Math.round(effectiveSlidesToShow || cols || 1));
|
|
7304
|
+
const startIndex = Math.max(0, Math.min(currentSlide, childEls.length - 1));
|
|
7305
|
+
return childEls.slice(startIndex, Math.min(childEls.length, startIndex + numCols));
|
|
7306
|
+
};
|
|
7307
|
+
const getVisibleVideos = () => {
|
|
7308
|
+
const slideEls = getVisibleSlideElements();
|
|
7309
|
+
const vids = [];
|
|
7310
|
+
for (const el of slideEls) {
|
|
7311
|
+
const found = el.querySelectorAll("video");
|
|
7312
|
+
found.forEach((v) => {
|
|
7313
|
+
if (!vids.includes(v)) {
|
|
7314
|
+
vids.push(v);
|
|
7315
|
+
}
|
|
7316
|
+
});
|
|
7317
|
+
}
|
|
7318
|
+
return vids;
|
|
7319
|
+
};
|
|
7320
|
+
const pauseInactiveVideos = (activeVids) => {
|
|
7321
|
+
if (!trackRef.current) return;
|
|
7322
|
+
const allVideos = Array.from(trackRef.current.querySelectorAll("video"));
|
|
7323
|
+
for (const vid of allVideos) {
|
|
7324
|
+
if (!activeVids.includes(vid)) {
|
|
7325
|
+
vid.pause();
|
|
7326
|
+
try {
|
|
7327
|
+
if (!vid.ended && vid.currentTime > 0) {
|
|
7328
|
+
vid.currentTime = 0;
|
|
7329
|
+
}
|
|
7330
|
+
} catch {
|
|
7331
|
+
}
|
|
7332
|
+
}
|
|
7333
|
+
}
|
|
7334
|
+
for (const vid of Array.from(completedVideosRef.current)) {
|
|
7335
|
+
if (!activeVids.includes(vid)) {
|
|
7336
|
+
completedVideosRef.current.delete(vid);
|
|
7337
|
+
}
|
|
7338
|
+
}
|
|
7339
|
+
};
|
|
7340
|
+
(0, import_react62.useEffect)(() => {
|
|
7341
|
+
if (!autoplay) return;
|
|
7342
|
+
let isEffectActive = true;
|
|
7343
|
+
let cleanupVideo = null;
|
|
7344
|
+
let timer = null;
|
|
7345
|
+
let observer = null;
|
|
7346
|
+
const setupVisibleVideos = (videosToPlay) => {
|
|
7347
|
+
if (!isEffectActive) return;
|
|
7348
|
+
if (timer) {
|
|
7349
|
+
clearInterval(timer);
|
|
7350
|
+
timer = null;
|
|
7351
|
+
}
|
|
7352
|
+
const allVisVideos = getVisibleVideos();
|
|
7353
|
+
pauseInactiveVideos(allVisVideos);
|
|
7354
|
+
activeVideosRef.current = videosToPlay;
|
|
7355
|
+
const pendingVideos = videosToPlay.filter((v) => !completedVideosRef.current.has(v));
|
|
7356
|
+
if (pendingVideos.length === 0) {
|
|
7357
|
+
setVideoProgress(100);
|
|
7358
|
+
nextSlideRef.current();
|
|
7359
|
+
return;
|
|
7360
|
+
}
|
|
7361
|
+
const startedVideos = /* @__PURE__ */ new Set();
|
|
7362
|
+
let hasTriggeredNext = false;
|
|
7363
|
+
const checkAllPendingEnded = () => {
|
|
7364
|
+
if (!isEffectActive || hasTriggeredNext) return;
|
|
7365
|
+
for (const vid of pendingVideos) {
|
|
7366
|
+
if (!completedVideosRef.current.has(vid)) {
|
|
7367
|
+
const hasStarted = startedVideos.has(vid);
|
|
7368
|
+
const isAtEnd = vid.ended || vid.duration > 0 && vid.currentTime >= vid.duration - 0.25;
|
|
7369
|
+
if (hasStarted && isAtEnd) {
|
|
7370
|
+
completedVideosRef.current.add(vid);
|
|
7371
|
+
}
|
|
7372
|
+
}
|
|
7373
|
+
}
|
|
7374
|
+
const allFinished = pendingVideos.every((v) => completedVideosRef.current.has(v));
|
|
7375
|
+
if (allFinished) {
|
|
7376
|
+
hasTriggeredNext = true;
|
|
7377
|
+
setVideoProgress(100);
|
|
7378
|
+
nextSlideRef.current();
|
|
7379
|
+
}
|
|
7380
|
+
};
|
|
7381
|
+
const handleTimeUpdate = () => {
|
|
7382
|
+
if (!isEffectActive || hasTriggeredNext) return;
|
|
7383
|
+
let maxDuration = 0;
|
|
7384
|
+
let activeProgress = 0;
|
|
7385
|
+
for (const v of pendingVideos) {
|
|
7386
|
+
if (v.currentTime > 0.05 || !v.paused) {
|
|
7387
|
+
startedVideos.add(v);
|
|
7388
|
+
}
|
|
7389
|
+
if (v.duration && !isNaN(v.duration) && v.duration > maxDuration) {
|
|
7390
|
+
maxDuration = v.duration;
|
|
7391
|
+
activeProgress = v.currentTime / v.duration * 100;
|
|
7392
|
+
}
|
|
7393
|
+
}
|
|
7394
|
+
if (maxDuration > 0) {
|
|
7395
|
+
setVideoProgress(Math.min(100, Math.max(0, activeProgress)));
|
|
7396
|
+
}
|
|
7397
|
+
checkAllPendingEnded();
|
|
7398
|
+
};
|
|
7399
|
+
const handleVideoEnded = (e) => {
|
|
7400
|
+
const vid = e.target;
|
|
7401
|
+
if (vid) {
|
|
7402
|
+
startedVideos.add(vid);
|
|
7403
|
+
completedVideosRef.current.add(vid);
|
|
7404
|
+
}
|
|
7405
|
+
checkAllPendingEnded();
|
|
7406
|
+
};
|
|
7407
|
+
const handlePlaying = (e) => {
|
|
7408
|
+
const vid = e.target;
|
|
7409
|
+
if (vid) {
|
|
7410
|
+
startedVideos.add(vid);
|
|
7411
|
+
}
|
|
7412
|
+
};
|
|
7413
|
+
const handleVideoError = (e) => {
|
|
7414
|
+
const vid = e.target;
|
|
7415
|
+
if (vid) {
|
|
7416
|
+
completedVideosRef.current.add(vid);
|
|
7417
|
+
}
|
|
7418
|
+
checkAllPendingEnded();
|
|
7419
|
+
};
|
|
7420
|
+
for (const vid of pendingVideos) {
|
|
7421
|
+
vid.muted = true;
|
|
7422
|
+
vid.defaultMuted = true;
|
|
7423
|
+
vid.playsInline = true;
|
|
7424
|
+
vid.loop = false;
|
|
7425
|
+
vid.removeAttribute("loop");
|
|
7426
|
+
if (vid.ended || vid.duration && vid.currentTime >= vid.duration - 0.25) {
|
|
7427
|
+
vid.currentTime = 0;
|
|
7428
|
+
vid.play().catch(() => {
|
|
7429
|
+
});
|
|
7430
|
+
} else if (vid.paused && vid.currentTime === 0) {
|
|
7431
|
+
vid.play().catch(() => {
|
|
7432
|
+
});
|
|
7433
|
+
}
|
|
7434
|
+
vid.addEventListener("timeupdate", handleTimeUpdate);
|
|
7435
|
+
vid.addEventListener("loadedmetadata", handleTimeUpdate);
|
|
7436
|
+
vid.addEventListener("ended", handleVideoEnded);
|
|
7437
|
+
vid.addEventListener("playing", handlePlaying);
|
|
7438
|
+
vid.addEventListener("error", handleVideoError);
|
|
7439
|
+
}
|
|
7440
|
+
cleanupVideo = () => {
|
|
7441
|
+
for (const vid of pendingVideos) {
|
|
7442
|
+
vid.removeEventListener("timeupdate", handleTimeUpdate);
|
|
7443
|
+
vid.removeEventListener("loadedmetadata", handleTimeUpdate);
|
|
7444
|
+
vid.removeEventListener("ended", handleVideoEnded);
|
|
7445
|
+
vid.removeEventListener("playing", handlePlaying);
|
|
7446
|
+
vid.removeEventListener("error", handleVideoError);
|
|
7447
|
+
}
|
|
7448
|
+
activeVideosRef.current = [];
|
|
7449
|
+
setVideoProgress(null);
|
|
7450
|
+
};
|
|
7451
|
+
};
|
|
7452
|
+
const initialVideos = getVisibleVideos();
|
|
7453
|
+
const initialPending = initialVideos.filter((v) => !completedVideosRef.current.has(v));
|
|
7454
|
+
if (initialPending.length > 0) {
|
|
7455
|
+
setupVisibleVideos(initialPending);
|
|
7456
|
+
} else {
|
|
7457
|
+
pauseInactiveVideos([]);
|
|
7458
|
+
activeVideosRef.current = [];
|
|
7459
|
+
setVideoProgress(null);
|
|
7460
|
+
if (trackRef.current && typeof MutationObserver !== "undefined") {
|
|
7461
|
+
observer = new MutationObserver(() => {
|
|
7462
|
+
const asyncVideos = getVisibleVideos();
|
|
7463
|
+
const asyncPending = asyncVideos.filter((v) => !completedVideosRef.current.has(v));
|
|
7464
|
+
if (asyncPending.length > 0) {
|
|
7465
|
+
const hasNew = asyncPending.some((v) => !activeVideosRef.current.includes(v));
|
|
7466
|
+
if (hasNew) {
|
|
7467
|
+
if (observer) {
|
|
7468
|
+
observer.disconnect();
|
|
7469
|
+
observer = null;
|
|
7470
|
+
}
|
|
7471
|
+
setupVisibleVideos(asyncPending);
|
|
7472
|
+
}
|
|
7473
|
+
}
|
|
7474
|
+
});
|
|
7475
|
+
observer.observe(trackRef.current, { childList: true, subtree: true });
|
|
7476
|
+
}
|
|
7477
|
+
timer = setInterval(() => {
|
|
7478
|
+
const currentVids = getVisibleVideos();
|
|
7479
|
+
const currentPending = currentVids.filter((v) => !completedVideosRef.current.has(v));
|
|
7480
|
+
if (currentPending.length > 0) {
|
|
7481
|
+
clearInterval(timer);
|
|
7482
|
+
timer = null;
|
|
7483
|
+
setupVisibleVideos(currentPending);
|
|
7484
|
+
return;
|
|
7485
|
+
}
|
|
7486
|
+
if (isPlayingRef.current) {
|
|
7487
|
+
nextSlideRef.current();
|
|
7488
|
+
}
|
|
7489
|
+
}, autoplay_speed);
|
|
7490
|
+
}
|
|
7491
|
+
return () => {
|
|
7492
|
+
isEffectActive = false;
|
|
7493
|
+
if (cleanupVideo) {
|
|
7494
|
+
cleanupVideo();
|
|
7495
|
+
}
|
|
7496
|
+
if (timer) {
|
|
7497
|
+
clearInterval(timer);
|
|
7498
|
+
}
|
|
7499
|
+
if (observer) {
|
|
7500
|
+
observer.disconnect();
|
|
7501
|
+
}
|
|
7502
|
+
};
|
|
7503
|
+
}, [autoplay, autoplay_speed, currentSlide, slidesToShowState, columns]);
|
|
7318
7504
|
const handleMouseEnter = () => {
|
|
7319
7505
|
if (autoplay) {
|
|
7320
7506
|
setIsPlaying(false);
|
|
@@ -7510,7 +7696,7 @@ var init_Slider = __esm({
|
|
|
7510
7696
|
}
|
|
7511
7697
|
};
|
|
7512
7698
|
const renderProgressBar = () => {
|
|
7513
|
-
if (style === "modern" && isActive) {
|
|
7699
|
+
if ((style === "modern" || style === "cumulative") && isActive) {
|
|
7514
7700
|
const displayProgress = customProgress ?? progress;
|
|
7515
7701
|
return /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
|
|
7516
7702
|
"div",
|
package/dist/index.mjs
CHANGED
|
@@ -2551,7 +2551,7 @@ var Pagination = dynamic16(() => import("./Pagination-6R4XZLF6.mjs"), { ssr: tru
|
|
|
2551
2551
|
var DataBindingControls = dynamic16(() => import("./DataBindingControls-VSLL4WV2.mjs"), {
|
|
2552
2552
|
ssr: true
|
|
2553
2553
|
});
|
|
2554
|
-
var Slider = dynamic16(() => import("./Slider-
|
|
2554
|
+
var Slider = dynamic16(() => import("./Slider-XF4ZPNIN.mjs"), {
|
|
2555
2555
|
ssr: false
|
|
2556
2556
|
});
|
|
2557
2557
|
function toCamelCase(str) {
|
package/dist/server.js
CHANGED
|
@@ -4829,8 +4829,15 @@ var init_Slider = __esm({
|
|
|
4829
4829
|
);
|
|
4830
4830
|
const [isPlaying, setIsPlaying] = (0, import_react42.useState)(autoplay);
|
|
4831
4831
|
const trackRef = (0, import_react42.useRef)(null);
|
|
4832
|
-
console.log("trackRef:", trackRef);
|
|
4833
4832
|
const [videoProgress, setVideoProgress] = (0, import_react42.useState)(null);
|
|
4833
|
+
const activeVideosRef = (0, import_react42.useRef)([]);
|
|
4834
|
+
const completedVideosRef = (0, import_react42.useRef)(/* @__PURE__ */ new Set());
|
|
4835
|
+
const nextSlideRef = (0, import_react42.useRef)(() => {
|
|
4836
|
+
});
|
|
4837
|
+
const isPlayingRef = (0, import_react42.useRef)(isPlaying);
|
|
4838
|
+
(0, import_react42.useEffect)(() => {
|
|
4839
|
+
isPlayingRef.current = isPlaying;
|
|
4840
|
+
}, [isPlaying]);
|
|
4834
4841
|
(0, import_react42.useEffect)(() => {
|
|
4835
4842
|
if (typeof initialSlidesToShow === "number") {
|
|
4836
4843
|
setSlidesToShowState(initialSlidesToShow);
|
|
@@ -4849,51 +4856,6 @@ var init_Slider = __esm({
|
|
|
4849
4856
|
window.addEventListener("resize", handleResize);
|
|
4850
4857
|
return () => window.removeEventListener("resize", handleResize);
|
|
4851
4858
|
}, [initialSlidesToShow]);
|
|
4852
|
-
(0, import_react42.useEffect)(() => {
|
|
4853
|
-
if (!autoplay) return;
|
|
4854
|
-
const activeSlideElement = trackRef.current?.children[currentSlide];
|
|
4855
|
-
const videoElement = activeSlideElement?.querySelector("video");
|
|
4856
|
-
if (videoElement) {
|
|
4857
|
-
videoElement.loop = false;
|
|
4858
|
-
setVideoProgress(0);
|
|
4859
|
-
if (videoElement.ended) {
|
|
4860
|
-
videoElement.currentTime = 0;
|
|
4861
|
-
}
|
|
4862
|
-
videoElement.play().catch(() => {
|
|
4863
|
-
});
|
|
4864
|
-
const handleTimeUpdate = () => {
|
|
4865
|
-
if (videoElement.duration && !isNaN(videoElement.duration) && videoElement.duration > 0) {
|
|
4866
|
-
const pct = videoElement.currentTime / videoElement.duration * 100;
|
|
4867
|
-
setVideoProgress(pct);
|
|
4868
|
-
}
|
|
4869
|
-
};
|
|
4870
|
-
const handleVideoEnded = () => {
|
|
4871
|
-
setVideoProgress(100);
|
|
4872
|
-
nextSlide();
|
|
4873
|
-
};
|
|
4874
|
-
const handleVideoError = () => {
|
|
4875
|
-
nextSlide();
|
|
4876
|
-
};
|
|
4877
|
-
videoElement.addEventListener("timeupdate", handleTimeUpdate);
|
|
4878
|
-
videoElement.addEventListener("loadedmetadata", handleTimeUpdate);
|
|
4879
|
-
videoElement.addEventListener("ended", handleVideoEnded, { once: true });
|
|
4880
|
-
videoElement.addEventListener("error", handleVideoError, { once: true });
|
|
4881
|
-
return () => {
|
|
4882
|
-
videoElement.removeEventListener("timeupdate", handleTimeUpdate);
|
|
4883
|
-
videoElement.removeEventListener("loadedmetadata", handleTimeUpdate);
|
|
4884
|
-
videoElement.removeEventListener("ended", handleVideoEnded);
|
|
4885
|
-
videoElement.removeEventListener("error", handleVideoError);
|
|
4886
|
-
videoElement.pause();
|
|
4887
|
-
setVideoProgress(null);
|
|
4888
|
-
};
|
|
4889
|
-
}
|
|
4890
|
-
const timer = setInterval(() => {
|
|
4891
|
-
if (isPlaying) {
|
|
4892
|
-
nextSlide();
|
|
4893
|
-
}
|
|
4894
|
-
}, autoplay_speed);
|
|
4895
|
-
return () => clearInterval(timer);
|
|
4896
|
-
}, [autoplay, autoplay_speed, currentSlide, isPlaying]);
|
|
4897
4859
|
const totalSlides = import_react42.Children.count(children);
|
|
4898
4860
|
const numColumns = columns ?? slidesToShowState;
|
|
4899
4861
|
const slideWidthPercentage = (() => {
|
|
@@ -4909,17 +4871,18 @@ var init_Slider = __esm({
|
|
|
4909
4871
|
const effectiveSlidesToShow = 100 / slideWidthPercentage;
|
|
4910
4872
|
const maxSlide = Math.max(0, Math.ceil(totalSlides - effectiveSlidesToShow));
|
|
4911
4873
|
const step = scrollByColumns ? Math.max(1, Math.floor(effectiveSlidesToShow)) : 1;
|
|
4912
|
-
const
|
|
4874
|
+
const rawPositions = Array.from(
|
|
4913
4875
|
{ length: Math.ceil(maxSlide / step) + 1 },
|
|
4914
4876
|
(_, index) => Math.min(index * step, maxSlide)
|
|
4915
4877
|
);
|
|
4878
|
+
const slidePositions = Array.from(new Set(rawPositions));
|
|
4916
4879
|
const currentStepIndex = slidePositions.reduce(
|
|
4917
4880
|
(closestIndex, position, index) => Math.abs(position - currentSlide) < Math.abs(slidePositions[closestIndex] - currentSlide) ? index : closestIndex,
|
|
4918
4881
|
0
|
|
4919
4882
|
);
|
|
4920
4883
|
const nextSlide = () => {
|
|
4921
4884
|
if (currentStepIndex >= slidePositions.length - 1) {
|
|
4922
|
-
if (infinite_scroll) {
|
|
4885
|
+
if (infinite_scroll || autoplay) {
|
|
4923
4886
|
setTransition(true);
|
|
4924
4887
|
setCurrentSlide(0);
|
|
4925
4888
|
}
|
|
@@ -4928,6 +4891,7 @@ var init_Slider = __esm({
|
|
|
4928
4891
|
setCurrentSlide(slidePositions[currentStepIndex + 1]);
|
|
4929
4892
|
}
|
|
4930
4893
|
};
|
|
4894
|
+
nextSlideRef.current = nextSlide;
|
|
4931
4895
|
const prevSlide = () => {
|
|
4932
4896
|
if (currentStepIndex <= 0) {
|
|
4933
4897
|
if (infinite_scroll) {
|
|
@@ -4949,6 +4913,228 @@ var init_Slider = __esm({
|
|
|
4949
4913
|
setIsPlaying(true);
|
|
4950
4914
|
}
|
|
4951
4915
|
};
|
|
4916
|
+
const getVisibleSlideElements = () => {
|
|
4917
|
+
if (!trackRef.current) return [];
|
|
4918
|
+
const childEls = Array.from(trackRef.current.children);
|
|
4919
|
+
if (childEls.length === 0) return [];
|
|
4920
|
+
const container = trackRef.current.parentElement;
|
|
4921
|
+
if (container) {
|
|
4922
|
+
const containerRect = container.getBoundingClientRect();
|
|
4923
|
+
if (containerRect.width > 0) {
|
|
4924
|
+
const visibleByRect = childEls.filter((child) => {
|
|
4925
|
+
const rect = child.getBoundingClientRect();
|
|
4926
|
+
const visibleLeft = Math.max(containerRect.left, rect.left);
|
|
4927
|
+
const visibleRight = Math.min(containerRect.right, rect.right);
|
|
4928
|
+
const visibleWidth = visibleRight - visibleLeft;
|
|
4929
|
+
return visibleWidth > 20 || visibleWidth / (rect.width || 1) > 0.15;
|
|
4930
|
+
});
|
|
4931
|
+
if (visibleByRect.length > 0) {
|
|
4932
|
+
return visibleByRect;
|
|
4933
|
+
}
|
|
4934
|
+
}
|
|
4935
|
+
}
|
|
4936
|
+
const cols = columns ?? slidesToShowState ?? 1;
|
|
4937
|
+
const numCols = Math.max(1, Math.round(effectiveSlidesToShow || cols || 1));
|
|
4938
|
+
const startIndex = Math.max(0, Math.min(currentSlide, childEls.length - 1));
|
|
4939
|
+
return childEls.slice(startIndex, Math.min(childEls.length, startIndex + numCols));
|
|
4940
|
+
};
|
|
4941
|
+
const getVisibleVideos = () => {
|
|
4942
|
+
const slideEls = getVisibleSlideElements();
|
|
4943
|
+
const vids = [];
|
|
4944
|
+
for (const el of slideEls) {
|
|
4945
|
+
const found = el.querySelectorAll("video");
|
|
4946
|
+
found.forEach((v) => {
|
|
4947
|
+
if (!vids.includes(v)) {
|
|
4948
|
+
vids.push(v);
|
|
4949
|
+
}
|
|
4950
|
+
});
|
|
4951
|
+
}
|
|
4952
|
+
return vids;
|
|
4953
|
+
};
|
|
4954
|
+
const pauseInactiveVideos = (activeVids) => {
|
|
4955
|
+
if (!trackRef.current) return;
|
|
4956
|
+
const allVideos = Array.from(trackRef.current.querySelectorAll("video"));
|
|
4957
|
+
for (const vid of allVideos) {
|
|
4958
|
+
if (!activeVids.includes(vid)) {
|
|
4959
|
+
vid.pause();
|
|
4960
|
+
try {
|
|
4961
|
+
if (!vid.ended && vid.currentTime > 0) {
|
|
4962
|
+
vid.currentTime = 0;
|
|
4963
|
+
}
|
|
4964
|
+
} catch {
|
|
4965
|
+
}
|
|
4966
|
+
}
|
|
4967
|
+
}
|
|
4968
|
+
for (const vid of Array.from(completedVideosRef.current)) {
|
|
4969
|
+
if (!activeVids.includes(vid)) {
|
|
4970
|
+
completedVideosRef.current.delete(vid);
|
|
4971
|
+
}
|
|
4972
|
+
}
|
|
4973
|
+
};
|
|
4974
|
+
(0, import_react42.useEffect)(() => {
|
|
4975
|
+
if (!autoplay) return;
|
|
4976
|
+
let isEffectActive = true;
|
|
4977
|
+
let cleanupVideo = null;
|
|
4978
|
+
let timer = null;
|
|
4979
|
+
let observer = null;
|
|
4980
|
+
const setupVisibleVideos = (videosToPlay) => {
|
|
4981
|
+
if (!isEffectActive) return;
|
|
4982
|
+
if (timer) {
|
|
4983
|
+
clearInterval(timer);
|
|
4984
|
+
timer = null;
|
|
4985
|
+
}
|
|
4986
|
+
const allVisVideos = getVisibleVideos();
|
|
4987
|
+
pauseInactiveVideos(allVisVideos);
|
|
4988
|
+
activeVideosRef.current = videosToPlay;
|
|
4989
|
+
const pendingVideos = videosToPlay.filter((v) => !completedVideosRef.current.has(v));
|
|
4990
|
+
if (pendingVideos.length === 0) {
|
|
4991
|
+
setVideoProgress(100);
|
|
4992
|
+
nextSlideRef.current();
|
|
4993
|
+
return;
|
|
4994
|
+
}
|
|
4995
|
+
const startedVideos = /* @__PURE__ */ new Set();
|
|
4996
|
+
let hasTriggeredNext = false;
|
|
4997
|
+
const checkAllPendingEnded = () => {
|
|
4998
|
+
if (!isEffectActive || hasTriggeredNext) return;
|
|
4999
|
+
for (const vid of pendingVideos) {
|
|
5000
|
+
if (!completedVideosRef.current.has(vid)) {
|
|
5001
|
+
const hasStarted = startedVideos.has(vid);
|
|
5002
|
+
const isAtEnd = vid.ended || vid.duration > 0 && vid.currentTime >= vid.duration - 0.25;
|
|
5003
|
+
if (hasStarted && isAtEnd) {
|
|
5004
|
+
completedVideosRef.current.add(vid);
|
|
5005
|
+
}
|
|
5006
|
+
}
|
|
5007
|
+
}
|
|
5008
|
+
const allFinished = pendingVideos.every((v) => completedVideosRef.current.has(v));
|
|
5009
|
+
if (allFinished) {
|
|
5010
|
+
hasTriggeredNext = true;
|
|
5011
|
+
setVideoProgress(100);
|
|
5012
|
+
nextSlideRef.current();
|
|
5013
|
+
}
|
|
5014
|
+
};
|
|
5015
|
+
const handleTimeUpdate = () => {
|
|
5016
|
+
if (!isEffectActive || hasTriggeredNext) return;
|
|
5017
|
+
let maxDuration = 0;
|
|
5018
|
+
let activeProgress = 0;
|
|
5019
|
+
for (const v of pendingVideos) {
|
|
5020
|
+
if (v.currentTime > 0.05 || !v.paused) {
|
|
5021
|
+
startedVideos.add(v);
|
|
5022
|
+
}
|
|
5023
|
+
if (v.duration && !isNaN(v.duration) && v.duration > maxDuration) {
|
|
5024
|
+
maxDuration = v.duration;
|
|
5025
|
+
activeProgress = v.currentTime / v.duration * 100;
|
|
5026
|
+
}
|
|
5027
|
+
}
|
|
5028
|
+
if (maxDuration > 0) {
|
|
5029
|
+
setVideoProgress(Math.min(100, Math.max(0, activeProgress)));
|
|
5030
|
+
}
|
|
5031
|
+
checkAllPendingEnded();
|
|
5032
|
+
};
|
|
5033
|
+
const handleVideoEnded = (e) => {
|
|
5034
|
+
const vid = e.target;
|
|
5035
|
+
if (vid) {
|
|
5036
|
+
startedVideos.add(vid);
|
|
5037
|
+
completedVideosRef.current.add(vid);
|
|
5038
|
+
}
|
|
5039
|
+
checkAllPendingEnded();
|
|
5040
|
+
};
|
|
5041
|
+
const handlePlaying = (e) => {
|
|
5042
|
+
const vid = e.target;
|
|
5043
|
+
if (vid) {
|
|
5044
|
+
startedVideos.add(vid);
|
|
5045
|
+
}
|
|
5046
|
+
};
|
|
5047
|
+
const handleVideoError = (e) => {
|
|
5048
|
+
const vid = e.target;
|
|
5049
|
+
if (vid) {
|
|
5050
|
+
completedVideosRef.current.add(vid);
|
|
5051
|
+
}
|
|
5052
|
+
checkAllPendingEnded();
|
|
5053
|
+
};
|
|
5054
|
+
for (const vid of pendingVideos) {
|
|
5055
|
+
vid.muted = true;
|
|
5056
|
+
vid.defaultMuted = true;
|
|
5057
|
+
vid.playsInline = true;
|
|
5058
|
+
vid.loop = false;
|
|
5059
|
+
vid.removeAttribute("loop");
|
|
5060
|
+
if (vid.ended || vid.duration && vid.currentTime >= vid.duration - 0.25) {
|
|
5061
|
+
vid.currentTime = 0;
|
|
5062
|
+
vid.play().catch(() => {
|
|
5063
|
+
});
|
|
5064
|
+
} else if (vid.paused && vid.currentTime === 0) {
|
|
5065
|
+
vid.play().catch(() => {
|
|
5066
|
+
});
|
|
5067
|
+
}
|
|
5068
|
+
vid.addEventListener("timeupdate", handleTimeUpdate);
|
|
5069
|
+
vid.addEventListener("loadedmetadata", handleTimeUpdate);
|
|
5070
|
+
vid.addEventListener("ended", handleVideoEnded);
|
|
5071
|
+
vid.addEventListener("playing", handlePlaying);
|
|
5072
|
+
vid.addEventListener("error", handleVideoError);
|
|
5073
|
+
}
|
|
5074
|
+
cleanupVideo = () => {
|
|
5075
|
+
for (const vid of pendingVideos) {
|
|
5076
|
+
vid.removeEventListener("timeupdate", handleTimeUpdate);
|
|
5077
|
+
vid.removeEventListener("loadedmetadata", handleTimeUpdate);
|
|
5078
|
+
vid.removeEventListener("ended", handleVideoEnded);
|
|
5079
|
+
vid.removeEventListener("playing", handlePlaying);
|
|
5080
|
+
vid.removeEventListener("error", handleVideoError);
|
|
5081
|
+
}
|
|
5082
|
+
activeVideosRef.current = [];
|
|
5083
|
+
setVideoProgress(null);
|
|
5084
|
+
};
|
|
5085
|
+
};
|
|
5086
|
+
const initialVideos = getVisibleVideos();
|
|
5087
|
+
const initialPending = initialVideos.filter((v) => !completedVideosRef.current.has(v));
|
|
5088
|
+
if (initialPending.length > 0) {
|
|
5089
|
+
setupVisibleVideos(initialPending);
|
|
5090
|
+
} else {
|
|
5091
|
+
pauseInactiveVideos([]);
|
|
5092
|
+
activeVideosRef.current = [];
|
|
5093
|
+
setVideoProgress(null);
|
|
5094
|
+
if (trackRef.current && typeof MutationObserver !== "undefined") {
|
|
5095
|
+
observer = new MutationObserver(() => {
|
|
5096
|
+
const asyncVideos = getVisibleVideos();
|
|
5097
|
+
const asyncPending = asyncVideos.filter((v) => !completedVideosRef.current.has(v));
|
|
5098
|
+
if (asyncPending.length > 0) {
|
|
5099
|
+
const hasNew = asyncPending.some((v) => !activeVideosRef.current.includes(v));
|
|
5100
|
+
if (hasNew) {
|
|
5101
|
+
if (observer) {
|
|
5102
|
+
observer.disconnect();
|
|
5103
|
+
observer = null;
|
|
5104
|
+
}
|
|
5105
|
+
setupVisibleVideos(asyncPending);
|
|
5106
|
+
}
|
|
5107
|
+
}
|
|
5108
|
+
});
|
|
5109
|
+
observer.observe(trackRef.current, { childList: true, subtree: true });
|
|
5110
|
+
}
|
|
5111
|
+
timer = setInterval(() => {
|
|
5112
|
+
const currentVids = getVisibleVideos();
|
|
5113
|
+
const currentPending = currentVids.filter((v) => !completedVideosRef.current.has(v));
|
|
5114
|
+
if (currentPending.length > 0) {
|
|
5115
|
+
clearInterval(timer);
|
|
5116
|
+
timer = null;
|
|
5117
|
+
setupVisibleVideos(currentPending);
|
|
5118
|
+
return;
|
|
5119
|
+
}
|
|
5120
|
+
if (isPlayingRef.current) {
|
|
5121
|
+
nextSlideRef.current();
|
|
5122
|
+
}
|
|
5123
|
+
}, autoplay_speed);
|
|
5124
|
+
}
|
|
5125
|
+
return () => {
|
|
5126
|
+
isEffectActive = false;
|
|
5127
|
+
if (cleanupVideo) {
|
|
5128
|
+
cleanupVideo();
|
|
5129
|
+
}
|
|
5130
|
+
if (timer) {
|
|
5131
|
+
clearInterval(timer);
|
|
5132
|
+
}
|
|
5133
|
+
if (observer) {
|
|
5134
|
+
observer.disconnect();
|
|
5135
|
+
}
|
|
5136
|
+
};
|
|
5137
|
+
}, [autoplay, autoplay_speed, currentSlide, slidesToShowState, columns]);
|
|
4952
5138
|
const handleMouseEnter = () => {
|
|
4953
5139
|
if (autoplay) {
|
|
4954
5140
|
setIsPlaying(false);
|
|
@@ -5144,7 +5330,7 @@ var init_Slider = __esm({
|
|
|
5144
5330
|
}
|
|
5145
5331
|
};
|
|
5146
5332
|
const renderProgressBar = () => {
|
|
5147
|
-
if (style === "modern" && isActive) {
|
|
5333
|
+
if ((style === "modern" || style === "cumulative") && isActive) {
|
|
5148
5334
|
const displayProgress = customProgress ?? progress;
|
|
5149
5335
|
return /* @__PURE__ */ (0, import_jsx_runtime70.jsx)(
|
|
5150
5336
|
"div",
|
package/dist/server.mjs
CHANGED
|
@@ -2507,7 +2507,7 @@ var Pagination = dynamic15(() => import("./Pagination-RMAXCIL7.mjs"), { ssr: tru
|
|
|
2507
2507
|
var DataBindingControls = dynamic15(() => import("./DataBindingControls-Z2AHWFYX.mjs"), {
|
|
2508
2508
|
ssr: true
|
|
2509
2509
|
});
|
|
2510
|
-
var Slider = dynamic15(() => import("./Slider-
|
|
2510
|
+
var Slider = dynamic15(() => import("./Slider-S5M6EEBG.mjs"), {
|
|
2511
2511
|
ssr: false
|
|
2512
2512
|
});
|
|
2513
2513
|
function toCamelCase(str) {
|