@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.
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 slidePositions = Array.from(
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,242 @@ 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
+ const vids = activeVideosRef.current;
7342
+ if (!vids || vids.length === 0) return;
7343
+ for (const video of vids) {
7344
+ if (isPlaying) {
7345
+ video.play().catch(() => {
7346
+ });
7347
+ } else {
7348
+ video.pause();
7349
+ }
7350
+ }
7351
+ }, [isPlaying]);
7352
+ (0, import_react62.useEffect)(() => {
7353
+ if (!autoplay) return;
7354
+ let isEffectActive = true;
7355
+ let cleanupVideo = null;
7356
+ let timer = null;
7357
+ let observer = null;
7358
+ const setupVisibleVideos = (videosToPlay) => {
7359
+ if (!isEffectActive) return;
7360
+ if (timer) {
7361
+ clearInterval(timer);
7362
+ timer = null;
7363
+ }
7364
+ const allVisVideos = getVisibleVideos();
7365
+ pauseInactiveVideos(allVisVideos);
7366
+ activeVideosRef.current = videosToPlay;
7367
+ const pendingVideos = videosToPlay.filter((v) => !completedVideosRef.current.has(v));
7368
+ if (pendingVideos.length === 0) {
7369
+ setVideoProgress(100);
7370
+ nextSlideRef.current();
7371
+ return;
7372
+ }
7373
+ const startedVideos = /* @__PURE__ */ new Set();
7374
+ let hasTriggeredNext = false;
7375
+ const checkAllPendingEnded = () => {
7376
+ if (!isEffectActive || hasTriggeredNext) return;
7377
+ for (const vid of pendingVideos) {
7378
+ if (!completedVideosRef.current.has(vid)) {
7379
+ const hasStarted = startedVideos.has(vid);
7380
+ const isAtEnd = vid.ended || vid.duration > 0 && vid.currentTime >= vid.duration - 0.25;
7381
+ if (hasStarted && isAtEnd) {
7382
+ completedVideosRef.current.add(vid);
7383
+ }
7384
+ }
7385
+ }
7386
+ const allFinished = pendingVideos.every((v) => completedVideosRef.current.has(v));
7387
+ if (allFinished) {
7388
+ hasTriggeredNext = true;
7389
+ setVideoProgress(100);
7390
+ nextSlideRef.current();
7391
+ }
7392
+ };
7393
+ const handleTimeUpdate = () => {
7394
+ if (!isEffectActive || hasTriggeredNext) return;
7395
+ let maxDuration = 0;
7396
+ let activeProgress = 0;
7397
+ for (const v of pendingVideos) {
7398
+ if (v.currentTime > 0.05 || !v.paused) {
7399
+ startedVideos.add(v);
7400
+ }
7401
+ if (v.duration && !isNaN(v.duration) && v.duration > maxDuration) {
7402
+ maxDuration = v.duration;
7403
+ activeProgress = v.currentTime / v.duration * 100;
7404
+ }
7405
+ }
7406
+ if (maxDuration > 0) {
7407
+ setVideoProgress(Math.min(100, Math.max(0, activeProgress)));
7408
+ }
7409
+ checkAllPendingEnded();
7410
+ };
7411
+ const handleVideoEnded = (e) => {
7412
+ const vid = e.target;
7413
+ if (vid) {
7414
+ startedVideos.add(vid);
7415
+ completedVideosRef.current.add(vid);
7416
+ }
7417
+ checkAllPendingEnded();
7418
+ };
7419
+ const handlePlaying = (e) => {
7420
+ const vid = e.target;
7421
+ if (vid) {
7422
+ startedVideos.add(vid);
7423
+ }
7424
+ };
7425
+ const handleVideoError = (e) => {
7426
+ const vid = e.target;
7427
+ if (vid) {
7428
+ completedVideosRef.current.add(vid);
7429
+ }
7430
+ checkAllPendingEnded();
7431
+ };
7432
+ for (const vid of pendingVideos) {
7433
+ vid.muted = true;
7434
+ vid.defaultMuted = true;
7435
+ vid.playsInline = true;
7436
+ vid.loop = false;
7437
+ vid.removeAttribute("loop");
7438
+ if (vid.ended || vid.duration && vid.currentTime >= vid.duration - 0.25) {
7439
+ vid.currentTime = 0;
7440
+ }
7441
+ vid.addEventListener("timeupdate", handleTimeUpdate);
7442
+ vid.addEventListener("loadedmetadata", handleTimeUpdate);
7443
+ vid.addEventListener("ended", handleVideoEnded);
7444
+ vid.addEventListener("playing", handlePlaying);
7445
+ vid.addEventListener("error", handleVideoError);
7446
+ if (isPlayingRef.current) {
7447
+ vid.play().catch(() => {
7448
+ });
7449
+ } else {
7450
+ vid.pause();
7451
+ }
7452
+ }
7453
+ cleanupVideo = () => {
7454
+ for (const vid of pendingVideos) {
7455
+ vid.removeEventListener("timeupdate", handleTimeUpdate);
7456
+ vid.removeEventListener("loadedmetadata", handleTimeUpdate);
7457
+ vid.removeEventListener("ended", handleVideoEnded);
7458
+ vid.removeEventListener("playing", handlePlaying);
7459
+ vid.removeEventListener("error", handleVideoError);
7460
+ vid.pause();
7461
+ }
7462
+ activeVideosRef.current = [];
7463
+ setVideoProgress(null);
7464
+ };
7465
+ };
7466
+ const initialVideos = getVisibleVideos();
7467
+ const initialPending = initialVideos.filter((v) => !completedVideosRef.current.has(v));
7468
+ if (initialPending.length > 0) {
7469
+ setupVisibleVideos(initialPending);
7470
+ } else {
7471
+ pauseInactiveVideos([]);
7472
+ activeVideosRef.current = [];
7473
+ setVideoProgress(null);
7474
+ if (trackRef.current && typeof MutationObserver !== "undefined") {
7475
+ observer = new MutationObserver(() => {
7476
+ const asyncVideos = getVisibleVideos();
7477
+ const asyncPending = asyncVideos.filter((v) => !completedVideosRef.current.has(v));
7478
+ if (asyncPending.length > 0) {
7479
+ const hasNew = asyncPending.some((v) => !activeVideosRef.current.includes(v));
7480
+ if (hasNew) {
7481
+ if (observer) {
7482
+ observer.disconnect();
7483
+ observer = null;
7484
+ }
7485
+ setupVisibleVideos(asyncPending);
7486
+ }
7487
+ }
7488
+ });
7489
+ observer.observe(trackRef.current, { childList: true, subtree: true });
7490
+ }
7491
+ timer = setInterval(() => {
7492
+ const currentVids = getVisibleVideos();
7493
+ const currentPending = currentVids.filter((v) => !completedVideosRef.current.has(v));
7494
+ if (currentPending.length > 0) {
7495
+ clearInterval(timer);
7496
+ timer = null;
7497
+ setupVisibleVideos(currentPending);
7498
+ return;
7499
+ }
7500
+ if (isPlayingRef.current) {
7501
+ nextSlideRef.current();
7502
+ }
7503
+ }, autoplay_speed);
7504
+ }
7505
+ return () => {
7506
+ isEffectActive = false;
7507
+ if (cleanupVideo) {
7508
+ cleanupVideo();
7509
+ }
7510
+ if (timer) {
7511
+ clearInterval(timer);
7512
+ }
7513
+ if (observer) {
7514
+ observer.disconnect();
7515
+ }
7516
+ };
7517
+ }, [autoplay, autoplay_speed, currentSlide, slidesToShowState, columns]);
7318
7518
  const handleMouseEnter = () => {
7319
7519
  if (autoplay) {
7320
7520
  setIsPlaying(false);
@@ -7510,7 +7710,7 @@ var init_Slider = __esm({
7510
7710
  }
7511
7711
  };
7512
7712
  const renderProgressBar = () => {
7513
- if (style === "modern" && isActive) {
7713
+ if ((style === "modern" || style === "cumulative") && isActive) {
7514
7714
  const displayProgress = customProgress ?? progress;
7515
7715
  return /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
7516
7716
  "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-XDYPGJYI.mjs"), {
2554
+ var Slider = dynamic16(() => import("./Slider-TMKPDMQ4.mjs"), {
2555
2555
  ssr: false
2556
2556
  });
2557
2557
  function toCamelCase(str) {