@clyrex-digital/clyrex-controls-dev 0.8.1-dev.20261016052853 → 0.8.1-dev.20261016054542

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.
@@ -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 slidePositions = Array.from(
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,242 @@ 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
+ const vids = activeVideosRef.current;
178
+ if (!vids || vids.length === 0) return;
179
+ for (const video of vids) {
180
+ if (isPlaying) {
181
+ video.play().catch(() => {
182
+ });
183
+ } else {
184
+ video.pause();
185
+ }
186
+ }
187
+ }, [isPlaying]);
188
+ useEffect(() => {
189
+ if (!autoplay) return;
190
+ let isEffectActive = true;
191
+ let cleanupVideo = null;
192
+ let timer = null;
193
+ let observer = null;
194
+ const setupVisibleVideos = (videosToPlay) => {
195
+ if (!isEffectActive) return;
196
+ if (timer) {
197
+ clearInterval(timer);
198
+ timer = null;
199
+ }
200
+ const allVisVideos = getVisibleVideos();
201
+ pauseInactiveVideos(allVisVideos);
202
+ activeVideosRef.current = videosToPlay;
203
+ const pendingVideos = videosToPlay.filter((v) => !completedVideosRef.current.has(v));
204
+ if (pendingVideos.length === 0) {
205
+ setVideoProgress(100);
206
+ nextSlideRef.current();
207
+ return;
208
+ }
209
+ const startedVideos = /* @__PURE__ */ new Set();
210
+ let hasTriggeredNext = false;
211
+ const checkAllPendingEnded = () => {
212
+ if (!isEffectActive || hasTriggeredNext) return;
213
+ for (const vid of pendingVideos) {
214
+ if (!completedVideosRef.current.has(vid)) {
215
+ const hasStarted = startedVideos.has(vid);
216
+ const isAtEnd = vid.ended || vid.duration > 0 && vid.currentTime >= vid.duration - 0.25;
217
+ if (hasStarted && isAtEnd) {
218
+ completedVideosRef.current.add(vid);
219
+ }
220
+ }
221
+ }
222
+ const allFinished = pendingVideos.every((v) => completedVideosRef.current.has(v));
223
+ if (allFinished) {
224
+ hasTriggeredNext = true;
225
+ setVideoProgress(100);
226
+ nextSlideRef.current();
227
+ }
228
+ };
229
+ const handleTimeUpdate = () => {
230
+ if (!isEffectActive || hasTriggeredNext) return;
231
+ let maxDuration = 0;
232
+ let activeProgress = 0;
233
+ for (const v of pendingVideos) {
234
+ if (v.currentTime > 0.05 || !v.paused) {
235
+ startedVideos.add(v);
236
+ }
237
+ if (v.duration && !isNaN(v.duration) && v.duration > maxDuration) {
238
+ maxDuration = v.duration;
239
+ activeProgress = v.currentTime / v.duration * 100;
240
+ }
241
+ }
242
+ if (maxDuration > 0) {
243
+ setVideoProgress(Math.min(100, Math.max(0, activeProgress)));
244
+ }
245
+ checkAllPendingEnded();
246
+ };
247
+ const handleVideoEnded = (e) => {
248
+ const vid = e.target;
249
+ if (vid) {
250
+ startedVideos.add(vid);
251
+ completedVideosRef.current.add(vid);
252
+ }
253
+ checkAllPendingEnded();
254
+ };
255
+ const handlePlaying = (e) => {
256
+ const vid = e.target;
257
+ if (vid) {
258
+ startedVideos.add(vid);
259
+ }
260
+ };
261
+ const handleVideoError = (e) => {
262
+ const vid = e.target;
263
+ if (vid) {
264
+ completedVideosRef.current.add(vid);
265
+ }
266
+ checkAllPendingEnded();
267
+ };
268
+ for (const vid of pendingVideos) {
269
+ vid.muted = true;
270
+ vid.defaultMuted = true;
271
+ vid.playsInline = true;
272
+ vid.loop = false;
273
+ vid.removeAttribute("loop");
274
+ if (vid.ended || vid.duration && vid.currentTime >= vid.duration - 0.25) {
275
+ vid.currentTime = 0;
276
+ }
277
+ vid.addEventListener("timeupdate", handleTimeUpdate);
278
+ vid.addEventListener("loadedmetadata", handleTimeUpdate);
279
+ vid.addEventListener("ended", handleVideoEnded);
280
+ vid.addEventListener("playing", handlePlaying);
281
+ vid.addEventListener("error", handleVideoError);
282
+ if (isPlayingRef.current) {
283
+ vid.play().catch(() => {
284
+ });
285
+ } else {
286
+ vid.pause();
287
+ }
288
+ }
289
+ cleanupVideo = () => {
290
+ for (const vid of pendingVideos) {
291
+ vid.removeEventListener("timeupdate", handleTimeUpdate);
292
+ vid.removeEventListener("loadedmetadata", handleTimeUpdate);
293
+ vid.removeEventListener("ended", handleVideoEnded);
294
+ vid.removeEventListener("playing", handlePlaying);
295
+ vid.removeEventListener("error", handleVideoError);
296
+ vid.pause();
297
+ }
298
+ activeVideosRef.current = [];
299
+ setVideoProgress(null);
300
+ };
301
+ };
302
+ const initialVideos = getVisibleVideos();
303
+ const initialPending = initialVideos.filter((v) => !completedVideosRef.current.has(v));
304
+ if (initialPending.length > 0) {
305
+ setupVisibleVideos(initialPending);
306
+ } else {
307
+ pauseInactiveVideos([]);
308
+ activeVideosRef.current = [];
309
+ setVideoProgress(null);
310
+ if (trackRef.current && typeof MutationObserver !== "undefined") {
311
+ observer = new MutationObserver(() => {
312
+ const asyncVideos = getVisibleVideos();
313
+ const asyncPending = asyncVideos.filter((v) => !completedVideosRef.current.has(v));
314
+ if (asyncPending.length > 0) {
315
+ const hasNew = asyncPending.some((v) => !activeVideosRef.current.includes(v));
316
+ if (hasNew) {
317
+ if (observer) {
318
+ observer.disconnect();
319
+ observer = null;
320
+ }
321
+ setupVisibleVideos(asyncPending);
322
+ }
323
+ }
324
+ });
325
+ observer.observe(trackRef.current, { childList: true, subtree: true });
326
+ }
327
+ timer = setInterval(() => {
328
+ const currentVids = getVisibleVideos();
329
+ const currentPending = currentVids.filter((v) => !completedVideosRef.current.has(v));
330
+ if (currentPending.length > 0) {
331
+ clearInterval(timer);
332
+ timer = null;
333
+ setupVisibleVideos(currentPending);
334
+ return;
335
+ }
336
+ if (isPlayingRef.current) {
337
+ nextSlideRef.current();
338
+ }
339
+ }, autoplay_speed);
340
+ }
341
+ return () => {
342
+ isEffectActive = false;
343
+ if (cleanupVideo) {
344
+ cleanupVideo();
345
+ }
346
+ if (timer) {
347
+ clearInterval(timer);
348
+ }
349
+ if (observer) {
350
+ observer.disconnect();
351
+ }
352
+ };
353
+ }, [autoplay, autoplay_speed, currentSlide, slidesToShowState, columns]);
154
354
  const handleMouseEnter = () => {
155
355
  if (autoplay) {
156
356
  setIsPlaying(false);
@@ -346,7 +546,7 @@ var ProgressPill = ({
346
546
  }
347
547
  };
348
548
  const renderProgressBar = () => {
349
- if (style === "modern" && isActive) {
549
+ if ((style === "modern" || style === "cumulative") && isActive) {
350
550
  const displayProgress = customProgress ?? progress;
351
551
  return /* @__PURE__ */ jsx(
352
552
  "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 slidePositions = Array.from(
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,242 @@ 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
+ const vids = activeVideosRef.current;
180
+ if (!vids || vids.length === 0) return;
181
+ for (const video of vids) {
182
+ if (isPlaying) {
183
+ video.play().catch(() => {
184
+ });
185
+ } else {
186
+ video.pause();
187
+ }
188
+ }
189
+ }, [isPlaying]);
190
+ useEffect(() => {
191
+ if (!autoplay) return;
192
+ let isEffectActive = true;
193
+ let cleanupVideo = null;
194
+ let timer = null;
195
+ let observer = null;
196
+ const setupVisibleVideos = (videosToPlay) => {
197
+ if (!isEffectActive) return;
198
+ if (timer) {
199
+ clearInterval(timer);
200
+ timer = null;
201
+ }
202
+ const allVisVideos = getVisibleVideos();
203
+ pauseInactiveVideos(allVisVideos);
204
+ activeVideosRef.current = videosToPlay;
205
+ const pendingVideos = videosToPlay.filter((v) => !completedVideosRef.current.has(v));
206
+ if (pendingVideos.length === 0) {
207
+ setVideoProgress(100);
208
+ nextSlideRef.current();
209
+ return;
210
+ }
211
+ const startedVideos = /* @__PURE__ */ new Set();
212
+ let hasTriggeredNext = false;
213
+ const checkAllPendingEnded = () => {
214
+ if (!isEffectActive || hasTriggeredNext) return;
215
+ for (const vid of pendingVideos) {
216
+ if (!completedVideosRef.current.has(vid)) {
217
+ const hasStarted = startedVideos.has(vid);
218
+ const isAtEnd = vid.ended || vid.duration > 0 && vid.currentTime >= vid.duration - 0.25;
219
+ if (hasStarted && isAtEnd) {
220
+ completedVideosRef.current.add(vid);
221
+ }
222
+ }
223
+ }
224
+ const allFinished = pendingVideos.every((v) => completedVideosRef.current.has(v));
225
+ if (allFinished) {
226
+ hasTriggeredNext = true;
227
+ setVideoProgress(100);
228
+ nextSlideRef.current();
229
+ }
230
+ };
231
+ const handleTimeUpdate = () => {
232
+ if (!isEffectActive || hasTriggeredNext) return;
233
+ let maxDuration = 0;
234
+ let activeProgress = 0;
235
+ for (const v of pendingVideos) {
236
+ if (v.currentTime > 0.05 || !v.paused) {
237
+ startedVideos.add(v);
238
+ }
239
+ if (v.duration && !isNaN(v.duration) && v.duration > maxDuration) {
240
+ maxDuration = v.duration;
241
+ activeProgress = v.currentTime / v.duration * 100;
242
+ }
243
+ }
244
+ if (maxDuration > 0) {
245
+ setVideoProgress(Math.min(100, Math.max(0, activeProgress)));
246
+ }
247
+ checkAllPendingEnded();
248
+ };
249
+ const handleVideoEnded = (e) => {
250
+ const vid = e.target;
251
+ if (vid) {
252
+ startedVideos.add(vid);
253
+ completedVideosRef.current.add(vid);
254
+ }
255
+ checkAllPendingEnded();
256
+ };
257
+ const handlePlaying = (e) => {
258
+ const vid = e.target;
259
+ if (vid) {
260
+ startedVideos.add(vid);
261
+ }
262
+ };
263
+ const handleVideoError = (e) => {
264
+ const vid = e.target;
265
+ if (vid) {
266
+ completedVideosRef.current.add(vid);
267
+ }
268
+ checkAllPendingEnded();
269
+ };
270
+ for (const vid of pendingVideos) {
271
+ vid.muted = true;
272
+ vid.defaultMuted = true;
273
+ vid.playsInline = true;
274
+ vid.loop = false;
275
+ vid.removeAttribute("loop");
276
+ if (vid.ended || vid.duration && vid.currentTime >= vid.duration - 0.25) {
277
+ vid.currentTime = 0;
278
+ }
279
+ vid.addEventListener("timeupdate", handleTimeUpdate);
280
+ vid.addEventListener("loadedmetadata", handleTimeUpdate);
281
+ vid.addEventListener("ended", handleVideoEnded);
282
+ vid.addEventListener("playing", handlePlaying);
283
+ vid.addEventListener("error", handleVideoError);
284
+ if (isPlayingRef.current) {
285
+ vid.play().catch(() => {
286
+ });
287
+ } else {
288
+ vid.pause();
289
+ }
290
+ }
291
+ cleanupVideo = () => {
292
+ for (const vid of pendingVideos) {
293
+ vid.removeEventListener("timeupdate", handleTimeUpdate);
294
+ vid.removeEventListener("loadedmetadata", handleTimeUpdate);
295
+ vid.removeEventListener("ended", handleVideoEnded);
296
+ vid.removeEventListener("playing", handlePlaying);
297
+ vid.removeEventListener("error", handleVideoError);
298
+ vid.pause();
299
+ }
300
+ activeVideosRef.current = [];
301
+ setVideoProgress(null);
302
+ };
303
+ };
304
+ const initialVideos = getVisibleVideos();
305
+ const initialPending = initialVideos.filter((v) => !completedVideosRef.current.has(v));
306
+ if (initialPending.length > 0) {
307
+ setupVisibleVideos(initialPending);
308
+ } else {
309
+ pauseInactiveVideos([]);
310
+ activeVideosRef.current = [];
311
+ setVideoProgress(null);
312
+ if (trackRef.current && typeof MutationObserver !== "undefined") {
313
+ observer = new MutationObserver(() => {
314
+ const asyncVideos = getVisibleVideos();
315
+ const asyncPending = asyncVideos.filter((v) => !completedVideosRef.current.has(v));
316
+ if (asyncPending.length > 0) {
317
+ const hasNew = asyncPending.some((v) => !activeVideosRef.current.includes(v));
318
+ if (hasNew) {
319
+ if (observer) {
320
+ observer.disconnect();
321
+ observer = null;
322
+ }
323
+ setupVisibleVideos(asyncPending);
324
+ }
325
+ }
326
+ });
327
+ observer.observe(trackRef.current, { childList: true, subtree: true });
328
+ }
329
+ timer = setInterval(() => {
330
+ const currentVids = getVisibleVideos();
331
+ const currentPending = currentVids.filter((v) => !completedVideosRef.current.has(v));
332
+ if (currentPending.length > 0) {
333
+ clearInterval(timer);
334
+ timer = null;
335
+ setupVisibleVideos(currentPending);
336
+ return;
337
+ }
338
+ if (isPlayingRef.current) {
339
+ nextSlideRef.current();
340
+ }
341
+ }, autoplay_speed);
342
+ }
343
+ return () => {
344
+ isEffectActive = false;
345
+ if (cleanupVideo) {
346
+ cleanupVideo();
347
+ }
348
+ if (timer) {
349
+ clearInterval(timer);
350
+ }
351
+ if (observer) {
352
+ observer.disconnect();
353
+ }
354
+ };
355
+ }, [autoplay, autoplay_speed, currentSlide, slidesToShowState, columns]);
156
356
  const handleMouseEnter = () => {
157
357
  if (autoplay) {
158
358
  setIsPlaying(false);
@@ -348,7 +548,7 @@ var ProgressPill = ({
348
548
  }
349
549
  };
350
550
  const renderProgressBar = () => {
351
- if (style === "modern" && isActive) {
551
+ if ((style === "modern" || style === "cumulative") && isActive) {
352
552
  const displayProgress = customProgress ?? progress;
353
553
  return /* @__PURE__ */ jsx(
354
554
  "div",