| 13 | }; |
| 14 | |
| 15 | export class CarouselEngine extends Emitter { |
| 16 | element: HTMLElement | null = null; |
| 17 | snapPoints: number[] = []; |
| 18 | |
| 19 | #_index = 0; |
| 20 | |
| 21 | #layoutTimeout = 0; |
| 22 | #scrollThrottle = 0; |
| 23 | #resizeTimeout = 0; |
| 24 | #width = 0; |
| 25 | #maxScroll = 0; |
| 26 | #touching = false; |
| 27 | #snap = false; |
| 28 | #initialized = false; |
| 29 | #inertia = false; |
| 30 | #mouseDrag = false; |
| 31 | #disableUpdate = false; |
| 32 | |
| 33 | #dragger?: DragEngine; |
| 34 | #motion?: Motion; |
| 35 | |
| 36 | #wheelTimeout = 0; |
| 37 | #focusTimeout = 0; |
| 38 | |
| 39 | get #length() { |
| 40 | return this.snapPoints.length; |
| 41 | } |
| 42 | |
| 43 | get #index() { |
| 44 | return this.#_index; |
| 45 | } |
| 46 | set #index(val) { |
| 47 | if (val >= 0 && val < this.#length && val !== this.#index) { |
| 48 | this.#_index = val; |
| 49 | this.emit('change'); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // used for controlling the carousel from userland |
| 54 | get index() { |
| 55 | return this.#index; |
| 56 | } |
| 57 | set index(val: number) { |
| 58 | const prevIndex = this.#index; |
| 59 | this.#index = val; |
| 60 | // if the index has changed then we need to sync the scroll to the new index |
| 61 | if (prevIndex !== this.#index) { |
| 62 | this.#disableUpdate = true; |
| 63 | this.#syncScroll(); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | get canScrollPrev() { |
| 68 | return this.index > 0; |
| 69 | } |
| 70 | get canScrollNext() { |
| 71 | return this.index < this.#length - 1; |
| 72 | } |
nothing calls this directly
no test coverage detected