@elxjs/ui 0.0.253 → 0.0.254

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.
@@ -1609,6 +1609,7 @@ class EluxCarouselComponent {
1609
1609
  this.clickListeners = [];
1610
1610
  this.itemsChangesSubscription = null;
1611
1611
  this.autoplaySubscription = null;
1612
+ this.finishAutoplayWrap = null;
1612
1613
  this.hasDragged = false;
1613
1614
  this.resizeHandler = () => this.onResize();
1614
1615
  this.windowPointerUpHandler = (event) => this.onWindowPointerUp(event);
@@ -1630,13 +1631,13 @@ class EluxCarouselComponent {
1630
1631
  if (!this.autoplay || this.isHovered)
1631
1632
  return;
1632
1633
  this.autoplaySubscription = interval(this.autoplayInterval).subscribe(() => {
1633
- if (this.getTotalSteps() <= 1)
1634
+ if (this.getTotalSteps() <= 1 || this.finishAutoplayWrap || this.isDragging)
1634
1635
  return;
1635
1636
  if (this.canGoNext()) {
1636
1637
  this.nextSlide();
1637
1638
  }
1638
1639
  else {
1639
- this.goToFirstSlide();
1640
+ this.wrapAutoplay();
1640
1641
  }
1641
1642
  });
1642
1643
  }
@@ -1645,6 +1646,7 @@ class EluxCarouselComponent {
1645
1646
  this.configureAutoplay();
1646
1647
  this.setupClickPrevention();
1647
1648
  this.itemsChangesSubscription = this.items.changes.subscribe(() => {
1649
+ this.finishAutoplayWrap?.();
1648
1650
  this.refreshLayout();
1649
1651
  this.goToFirstSlide();
1650
1652
  this.setupClickPrevention();
@@ -1653,6 +1655,7 @@ class EluxCarouselComponent {
1653
1655
  window.addEventListener('resize', this.resizeHandler);
1654
1656
  }
1655
1657
  ngOnDestroy() {
1658
+ this.finishAutoplayWrap?.();
1656
1659
  this.itemsChangesSubscription?.unsubscribe();
1657
1660
  this.itemsChangesSubscription = null;
1658
1661
  this.removeWindowPointerListeners();
@@ -1692,6 +1695,7 @@ class EluxCarouselComponent {
1692
1695
  return this.currentStepIndex > 0;
1693
1696
  }
1694
1697
  onResize() {
1698
+ this.finishAutoplayWrap?.();
1695
1699
  this.calculateDimensions();
1696
1700
  this.updateOffset();
1697
1701
  }
@@ -1717,6 +1721,8 @@ class EluxCarouselComponent {
1717
1721
  this.configureAutoplay();
1718
1722
  }
1719
1723
  onPointerDown(event) {
1724
+ if (this.finishAutoplayWrap)
1725
+ return;
1720
1726
  if (event.pointerType === 'mouse' && event.button !== 0)
1721
1727
  return;
1722
1728
  this.activePointerId = event.pointerId;
@@ -1976,12 +1982,16 @@ class EluxCarouselComponent {
1976
1982
  this.scrollActiveDotIntoView(0);
1977
1983
  }
1978
1984
  goToSlide(index) {
1985
+ if (this.finishAutoplayWrap)
1986
+ return;
1979
1987
  this.currentStepIndex = index;
1980
1988
  this.updateOffset();
1981
1989
  this.scrollActiveDotIntoView(index);
1982
1990
  this.dotClickEventEmitter.emit();
1983
1991
  }
1984
1992
  prevSlide() {
1993
+ if (this.finishAutoplayWrap)
1994
+ return;
1985
1995
  if (!this.canGoPrevious())
1986
1996
  return;
1987
1997
  this.currentStepIndex--;
@@ -1990,6 +2000,8 @@ class EluxCarouselComponent {
1990
2000
  this.previousClickEventEmitter.emit();
1991
2001
  }
1992
2002
  nextSlide() {
2003
+ if (this.finishAutoplayWrap)
2004
+ return;
1993
2005
  if (!this.canGoNext())
1994
2006
  return;
1995
2007
  this.currentStepIndex++;
@@ -2003,6 +2015,54 @@ class EluxCarouselComponent {
2003
2015
  this.renderer.setStyle(this.slidesContainer.nativeElement, 'transform', `translateX(${this.offset}%)`);
2004
2016
  }
2005
2017
  }
2018
+ wrapAutoplay() {
2019
+ const slides = this.slidesContainer.nativeElement;
2020
+ const viewport = slides.parentElement;
2021
+ if (!viewport)
2022
+ throw new Error('Carousel slides have no container');
2023
+ const clone = this.renderer.createElement('div');
2024
+ const previousPosition = slides.style.position;
2025
+ const previousTransition = slides.style.transition;
2026
+ const previousOverflow = viewport.style.overflow;
2027
+ const steps = this.getTotalSteps();
2028
+ this.renderer.setAttribute(clone, 'aria-hidden', 'true');
2029
+ this.renderer.setAttribute(clone, 'inert', '');
2030
+ this.renderer.setStyle(clone, 'display', 'flex');
2031
+ this.renderer.setStyle(clone, 'position', 'absolute');
2032
+ this.renderer.setStyle(clone, 'left', `calc(${steps * 100}% + ${steps * this.gap}px)`);
2033
+ this.renderer.setStyle(clone, 'top', '0');
2034
+ this.renderer.setStyle(clone, 'width', '100%');
2035
+ this.renderer.setStyle(clone, 'gap', `${this.gap}px`);
2036
+ this.items.toArray().slice(0, this.itemsPerSlide).forEach((item) => {
2037
+ const copy = item.nativeElement.cloneNode(true);
2038
+ copy.removeAttribute('id');
2039
+ copy.querySelectorAll('[id]').forEach((element) => element.removeAttribute('id'));
2040
+ this.renderer.appendChild(clone, copy);
2041
+ });
2042
+ this.renderer.setStyle(slides, 'position', 'relative');
2043
+ this.renderer.setStyle(viewport, 'overflow', 'hidden');
2044
+ this.renderer.appendChild(slides, clone);
2045
+ const finish = () => {
2046
+ slides.removeEventListener('transitionend', onTransitionEnd);
2047
+ clearTimeout(timeout);
2048
+ this.renderer.setStyle(slides, 'transition', 'none');
2049
+ this.goToFirstSlide();
2050
+ void slides.offsetWidth;
2051
+ this.renderer.setStyle(slides, 'transition', previousTransition);
2052
+ this.renderer.setStyle(slides, 'position', previousPosition);
2053
+ this.renderer.setStyle(viewport, 'overflow', previousOverflow);
2054
+ this.renderer.removeChild(slides, clone);
2055
+ this.finishAutoplayWrap = null;
2056
+ };
2057
+ const onTransitionEnd = (event) => {
2058
+ if (event.target === slides && event.propertyName === 'transform')
2059
+ finish();
2060
+ };
2061
+ const timeout = setTimeout(finish, 600);
2062
+ this.finishAutoplayWrap = finish;
2063
+ slides.addEventListener('transitionend', onTransitionEnd);
2064
+ this.renderer.setStyle(slides, 'transform', `translateX(-${steps * this.getPageWidthPercent()}%)`);
2065
+ }
2006
2066
  scrollActiveDotIntoView(index) {
2007
2067
  setTimeout(() => {
2008
2068
  const dotsContainer = this.dotsContainer?.nativeElement;