All files / src/ui/carousel transitions.ts

0% Statements 0/7
0% Branches 0/2
0% Functions 0/6
0% Lines 0/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55                                                                                                             
import type {Carousel} from './carousel';
export {DraggableSlideConfig, DraggableSlide} from './draggable-slide';
 
/**
 * Interface a Transition must implement to be used with a carousel.
 */
export interface Transition {
  transition(targetSlide: Element): void;
  init(carousel: Carousel): void;
  getActiveSlide(): HTMLElement;
  hasTransitionedTo(slide: HTMLElement): boolean;
  isInteracting(): boolean;
  dispose(): void;
}
 
/**
 * A transition that doesn't really do anything.
 * This is used for when all effects can be set via CSS and triggered off the
 * default active/before/after classes.
 */
export class CssClassesOnly implements Transition {
  private activeSlide?: HTMLElement;
 
  init(carousel: Carousel) {
    this.activeSlide = carousel.getFirstSlide();
  }
 
  getActiveSlide(): HTMLElement {
    if (!this.activeSlide) {
      throw new Error('CssClassesOnly transition not initialized');
    }
    return this.activeSlide;
  }
 
  transition(targetSlide: HTMLElement) {
    this.activeSlide = targetSlide;
  }
 
  hasTransitionedTo(slide: HTMLElement): boolean {
    return this.activeSlide === slide;
  }
 
  /**
   * Always false, this transition doesn't support any interaction.
   */
  isInteracting(): boolean {
    return false;
  }
 
  /**
   * No special disposal needed.
   */
  dispose() {}
}