@twistedandy/better-carousel 0.0.0-stage → 1.1.0

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.
@@ -0,0 +1,323 @@
1
+ // The class prefix, the same as the "classes" option. The root class is the prefix.
2
+ $better: 'better' !default;
3
+
4
+ // The prefix of the state classes, the same as the "state" option
5
+ $better-state: '' !default;
6
+
7
+ // Add the look of the buttons and the dots
8
+ $better-look: true !default;
9
+
10
+ // The icon of the arrows, if the --button-arrow variable is not set
11
+ $better-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 12'%3E%3Cpath d='m1 1 5 5-5 5' fill='none' stroke='black' stroke-width='1.5'/%3E%3C/svg%3E") !default;
12
+
13
+ .#{$better} {
14
+ display: block;
15
+ position: relative;
16
+
17
+ // No "user-select" here: its change paints all layers of the carousel. The drag stops the text selection with script.
18
+ &.#{$better-state}dragging {
19
+ cursor: grabbing;
20
+ }
21
+
22
+ }
23
+
24
+ .#{$better}_viewport {
25
+ position: relative;
26
+ overflow: hidden;
27
+ width: 100%;
28
+ margin: 0;
29
+ z-index: 1;
30
+ }
31
+
32
+ .#{$better}_horizontal .#{$better}_container {
33
+ overflow: visible;
34
+ --gap-grid-y: 0px;
35
+ }
36
+
37
+ .#{$better}_vertical {
38
+
39
+ .#{$better}_viewport {
40
+ height: 100%;
41
+ }
42
+
43
+ .#{$better}_container {
44
+ overflow: visible;
45
+ height: calc(100% + var(--gap-grid-y, 0px));
46
+ margin-bottom: calc(-1 * var(--gap-grid-y, 0px));
47
+ --gap-grid-x: 0px;
48
+ }
49
+
50
+ }
51
+
52
+ .#{$better}_auto_height {
53
+
54
+ .#{$better}_viewport {
55
+ transition: height 0.3s;
56
+ }
57
+
58
+ .#{$better}_container {
59
+ align-items: flex-start;
60
+ }
61
+
62
+ }
63
+
64
+ @if $better-look {
65
+
66
+ .#{$better}_button {
67
+ display: block;
68
+ position: absolute;
69
+ bottom: 0;
70
+ inset-inline-end: 0;
71
+ width: var(--height-button);
72
+ height: var(--height-button);
73
+ padding: 0;
74
+ border: 1px solid var(--button-border, #222);
75
+ border-radius: var(--radius-regular, 10px);
76
+ background-color: var(--button-base, #222);
77
+ color: var(--button-text, #fff);
78
+ transition: 0.2s;
79
+ cursor: pointer;
80
+ z-index: 5;
81
+ --height-button: 2.5rem;
82
+
83
+ &:focus-visible {
84
+ outline: 2px solid var(--button-border-active, #000);
85
+ outline-offset: 2px;
86
+ }
87
+
88
+ &:before {
89
+ content: '';
90
+ display: block;
91
+ position: absolute;
92
+ top: 50%;
93
+ left: 50%;
94
+ width: 0.5rem;
95
+ height: 0.75rem;
96
+ margin: -0.375rem 0 0 -0.25rem;
97
+ background-color: currentColor;
98
+ -webkit-mask: var(--button-arrow, #{$better-arrow}) 50% 50% no-repeat;
99
+ mask: var(--button-arrow, #{$better-arrow}) 50% 50% no-repeat;
100
+ }
101
+
102
+ @media (hover: hover) {
103
+ &:hover {
104
+ border-color: var(--button-border-active, #000);
105
+ background-color: var(--button-base-active, #000);
106
+ color: var(--button-text-active, #fff);
107
+ }
108
+ }
109
+
110
+ &:disabled {
111
+ border-color: var(--button-border-disabled, #eee);
112
+ background-color: var(--button-base-disabled, #eee);
113
+ color: var(--button-text-disabled, #aaa);
114
+ cursor: default;
115
+ }
116
+
117
+ }
118
+
119
+ .#{$better}_prev {
120
+ inset-inline-start: 0;
121
+ inset-inline-end: auto;
122
+ }
123
+
124
+ // The arrow icon points to the right. It points to the left for the previous slide, and for the next slide in a right-to-left carousel.
125
+ .#{$better}_prev:dir(ltr):before,
126
+ .#{$better}_next:dir(rtl):before {
127
+ transform: scaleX(-1);
128
+ }
129
+
130
+ // The play and pause button of the autoplay and the auto scroll: a triangle, or two bars while it plays
131
+ .#{$better}_play {
132
+ inset-inline-start: calc(var(--height-button) + 0.5rem);
133
+ inset-inline-end: auto;
134
+
135
+ &:before {
136
+ width: 0.625rem;
137
+ margin-left: -0.3125rem;
138
+ -webkit-mask: none;
139
+ mask: none;
140
+ clip-path: polygon(0 0, 100% 50%, 0 100%);
141
+ }
142
+
143
+ }
144
+
145
+ .#{$better}.#{$better-state}playing .#{$better}_play:before {
146
+ background: linear-gradient(90deg, currentColor 35%, transparent 35% 65%, currentColor 65%);
147
+ clip-path: none;
148
+ }
149
+
150
+ // The dots: a window of 5 dots. The track of the dots slides with "translate", and the marker of the selected dot glides with "translate".
151
+ // Only these two elements animate. Each animation costs work on the main thread at its start and its end, so the dots change size at once.
152
+ .#{$better}_dots {
153
+ display: flex;
154
+ position: relative;
155
+ align-items: center;
156
+ width: 7.5rem;
157
+ height: var(--height-button);
158
+ margin: var(--gap-grid-y, 20px) auto 0;
159
+ overflow: hidden;
160
+ z-index: 3;
161
+ --height-button: 2.5rem;
162
+ }
163
+
164
+ .#{$better}_dot {
165
+ display: flex;
166
+ flex: none;
167
+ align-items: center;
168
+ justify-content: center;
169
+ width: 1.5rem;
170
+ height: 1.5rem;
171
+ padding: 0;
172
+ border: 0;
173
+ border-radius: 50%;
174
+ background: none;
175
+ color: var(--button-text-disabled, #767676);
176
+ // A color transition runs on the main thread. It runs only on hover: a select does not change the color of a dot.
177
+ transition: color 0.2s;
178
+ cursor: pointer;
179
+
180
+ // In the dot, because the window of the dots cuts what is outside
181
+ &:focus-visible {
182
+ outline: 2px solid var(--button-border-active, #000);
183
+ outline-offset: -2px;
184
+ }
185
+
186
+ &:before {
187
+ content: '';
188
+ display: block;
189
+ width: 0.875rem;
190
+ height: 0.875rem;
191
+ border-radius: 50%;
192
+ background: currentColor;
193
+ transform: scale(0);
194
+ }
195
+
196
+ &.#{$better-state}last:before,
197
+ &.#{$better-state}first:before {
198
+ transform: scale(0.333);
199
+ }
200
+
201
+ &.#{$better-state}prev:before,
202
+ &.#{$better-state}next:before {
203
+ transform: scale(0.666);
204
+ }
205
+
206
+ // The marker covers the selected dot
207
+ &.#{$better-state}current:before {
208
+ transform: scale(1);
209
+ }
210
+
211
+ @media (hover: hover) {
212
+ &:hover {
213
+ color: var(--button-base-active, #000);
214
+ }
215
+ }
216
+
217
+ }
218
+
219
+ .#{$better}_dots_track {
220
+ display: flex;
221
+ position: relative;
222
+ flex: none;
223
+ translate: calc(var(--better-shift, 0) * 1.5rem);
224
+ transition: translate 0.4s;
225
+
226
+ // In a right-to-left carousel, the first dot is at the right
227
+ &:dir(rtl) {
228
+ translate: calc(var(--better-shift, 0) * -1.5rem);
229
+ }
230
+
231
+ }
232
+
233
+ // The selected dot, on top of the dots, also if the CSS of the site positions the buttons. It does not get the clicks.
234
+ .#{$better}_dots_marker {
235
+ position: absolute;
236
+ z-index: 1;
237
+ top: 0.3125rem;
238
+ inset-inline-start: 0.3125rem;
239
+ width: 0.875rem;
240
+ height: 0.875rem;
241
+ border-radius: 50%;
242
+ background: var(--button-base, #222);
243
+ translate: calc(var(--better-dot, 0) * 1.5rem);
244
+ transition: translate 0.4s;
245
+ pointer-events: none;
246
+
247
+ &:dir(rtl) {
248
+ translate: calc(var(--better-dot, 0) * -1.5rem);
249
+ }
250
+
251
+ }
252
+
253
+ // dotsStyle: 'all'. All dots show with the same size, and the track does not slide.
254
+ .#{$better}_dots.#{$better}_dots_all {
255
+ width: max-content;
256
+ max-width: 100%;
257
+
258
+ .#{$better}_dots_track {
259
+ translate: none;
260
+ }
261
+
262
+ .#{$better}_dot:before {
263
+ transform: scale(0.666);
264
+ }
265
+
266
+ }
267
+
268
+ .#{$better}_vertical {
269
+
270
+ .#{$better}_button {
271
+ top: auto;
272
+ right: 0;
273
+ bottom: 0;
274
+ left: 0;
275
+ width: auto;
276
+ height: 30px;
277
+ margin: 0;
278
+
279
+ &:before {
280
+ transform: rotate(90deg);
281
+ }
282
+
283
+ }
284
+
285
+ .#{$better}_prev {
286
+ top: 0;
287
+ bottom: auto;
288
+
289
+ &:before {
290
+ transform: rotate(-90deg);
291
+ }
292
+
293
+ }
294
+
295
+ // One column of dots on the right side, in the middle of the carousel height
296
+ .#{$better}_dots {
297
+ position: absolute;
298
+ top: 50%;
299
+ right: 0;
300
+ flex-direction: column;
301
+ width: var(--height-button);
302
+ height: 7.5rem;
303
+ margin: 0;
304
+ transform: translateY(-50%);
305
+ }
306
+
307
+ .#{$better}_dots_track {
308
+ flex-direction: column;
309
+ translate: 0 calc(var(--better-shift, 0) * 1.5rem);
310
+ }
311
+
312
+ .#{$better}_dots_marker {
313
+ translate: 0 calc(var(--better-dot, 0) * 1.5rem);
314
+ }
315
+
316
+ .#{$better}_dots_all {
317
+ height: auto;
318
+ max-height: 100%;
319
+ }
320
+
321
+ }
322
+
323
+ }
@@ -0,0 +1,309 @@
1
+ // The types of Better Carousel. The members of Options come from scripts/reference.js: run "npm run docs" after a change there.
2
+ // The other types are written by hand. tests/docs.test.js compares the options and the events with the code.
3
+
4
+ /** The options of the autoplay. */
5
+ export interface AutoplayOptions {
6
+ /** The time on each slide, in ms, or an array with one time for each snap. A `data-delay` attribute on a slide sets the time of that slide. @default 4000 */
7
+ delay?: number | number[];
8
+ /** A drag, an arrow or a dot stops the autoplay. @default true */
9
+ stopOnInteraction?: boolean;
10
+ /** Pause while the mouse is on the carousel. @default false */
11
+ pauseOnHover?: boolean;
12
+ /** Pause while the keyboard focus is in the carousel. @default true */
13
+ pauseOnFocus?: boolean;
14
+ /** Stop at the last snap, if `loop` is `false`. @default false */
15
+ stopOnLastSnap?: boolean;
16
+ /** Start with the carousel. @default true */
17
+ playOnInit?: boolean;
18
+ /** Jump to the next slide with no motion. @default false */
19
+ instant?: boolean;
20
+ /**
21
+ * Show the time to the next slide. The carousel calls this function when the timer starts, with the delay in ms.
22
+ * The function can return a function that the carousel calls when this timer ends or stops. @default null
23
+ */
24
+ timer?: ((delay: number, carousel: Carousel) => (() => void) | void) | null;
25
+ }
26
+
27
+ /** The options of the auto scroll. */
28
+ export interface AutoScrollOptions {
29
+ /** The speed in px per second. @default 120 */
30
+ speed?: number;
31
+ /** @default 'next' */
32
+ direction?: 'next' | 'prev';
33
+ /** The time in ms before the start, and after an interaction. @default 1000 */
34
+ startDelay?: number;
35
+ /** A drag, an arrow or a dot stops the auto scroll. @default true */
36
+ stopOnInteraction?: boolean;
37
+ /** Pause while the mouse is on the carousel. @default false */
38
+ pauseOnHover?: boolean;
39
+ /** Pause while the keyboard focus is in the carousel. @default true */
40
+ pauseOnFocus?: boolean;
41
+ /** Start with the carousel. @default true */
42
+ playOnInit?: boolean;
43
+ }
44
+
45
+ /** The state that the `progress` callback gets. The carousel uses the same object for each call: read the values during the call. */
46
+ export interface ProgressState {
47
+ /** The progress, from 0 to 1. In loop mode, it goes from 1 back to 0. */
48
+ progress: number;
49
+ /** The position between the snaps: 2.4 is between snap 2 and snap 3. */
50
+ snap: number;
51
+ }
52
+
53
+ /** The state that the `offset` callback gets for a slide. The carousel uses the same object for each call: read the values during the call. */
54
+ export interface OffsetState {
55
+ /** The slide element, or a clone of it. */
56
+ node: HTMLElement;
57
+ /** The slide index. A clone gives the index of its slide. */
58
+ index: number;
59
+ /** The distance from the snap position of the slide, in slides: 0 at the snap position, 1 for the next slide, -1 for the previous slide. */
60
+ offset: number;
61
+ /** The same distance in px, on the screen: a positive value is to the right or down. */
62
+ distance: number;
63
+ /** The size of the slide on the main axis, in px. */
64
+ size: number;
65
+ /** The part of the slide in the viewport, from 0 to 1. */
66
+ visible: number;
67
+ }
68
+
69
+ /** The texts for screen readers. `%d` is the slide number, and `%n` is the number of slides. */
70
+ export interface Labels {
71
+ /** @default 'Carousel' */
72
+ carousel?: string;
73
+ /** @default '%d of %n' */
74
+ slide?: string;
75
+ /** @default 'Previous slide' */
76
+ prev?: string;
77
+ /** @default 'Next slide' */
78
+ next?: string;
79
+ /** @default 'Go to slide %d' */
80
+ dot?: string;
81
+ /** @default 'Start the slide show' */
82
+ play?: string;
83
+ /** @default 'Stop the slide show' */
84
+ pause?: string;
85
+ }
86
+
87
+ /** The class names to change. `prefix` sets the names that the object does not change. */
88
+ export interface ClassNames {
89
+ /** @default 'better' */
90
+ prefix?: string;
91
+ root?: string;
92
+ viewport?: string;
93
+ container?: string;
94
+ /** On the root, if all slides fit. */
95
+ fit?: string;
96
+ horizontal?: string;
97
+ vertical?: string;
98
+ /** On the root, with `autoHeight`. */
99
+ autoHeight?: string;
100
+ button?: string;
101
+ prevButton?: string;
102
+ nextButton?: string;
103
+ /** The window of the dots. */
104
+ dots?: string;
105
+ /** The row of the dots that slides in the window. */
106
+ dotsTrack?: string;
107
+ /** The marker of the selected dot, on top of the dots. */
108
+ dotsMarker?: string;
109
+ /** On the window of the dots, with `dotsStyle: 'all'`. */
110
+ dotsAll?: string;
111
+ dot?: string;
112
+ playButton?: string;
113
+ /** @default 'clone' */
114
+ clone?: string;
115
+ /** The selected slide. @default 'selected' */
116
+ selected?: string;
117
+ /** The slides in view. The default is an empty string: no class. */
118
+ inView?: string;
119
+ /** @default 'dragging' */
120
+ dragging?: string;
121
+ /** @default 'playing' */
122
+ playing?: string;
123
+ /** The dot two places before the selected dot. @default 'first' */
124
+ first?: string;
125
+ /** The dot before the selected dot. @default 'prev' */
126
+ prev?: string;
127
+ /** The selected dot. @default 'current' */
128
+ current?: string;
129
+ /** The dot after the selected dot. @default 'next' */
130
+ next?: string;
131
+ /** The dot two places after the selected dot. @default 'last' */
132
+ last?: string;
133
+ }
134
+
135
+ /** The options. Set them in the call, in the `data-carousel` attribute as JSON, or in `BetterCarousel.defaults`. */
136
+ export interface Options {
137
+ // <!-- generated:options -->
138
+ /** The axis of the motion. With `'auto'`, the CSS of the container sets the axis. @default 'auto' @see {@link https://twistedandy.github.io/better-carousel/#switch | example} */
139
+ axis?: 'x' | 'y' | 'auto';
140
+ /** The position of the selected snap in the viewport. A function gets `(viewSize, snapSize, index)` and returns the offset in px. With `'auto'`, `justify-content` sets the alignment. @default 'auto' @see {@link https://twistedandy.github.io/better-carousel/#center | example} */
141
+ align?: 'start' | 'center' | 'end' | 'auto' | ((viewSize: number, snapSize: number, index: number) => number);
142
+ /** The text direction. With `'auto'`, the CSS `direction` sets it. @default 'auto' @see {@link https://twistedandy.github.io/better-carousel/#rtl | example} */
143
+ dir?: 'ltr' | 'rtl' | 'auto';
144
+ /** The first slide comes after the last slide. @default false @see {@link https://twistedandy.github.io/better-carousel/#loop | example} */
145
+ loop?: boolean;
146
+ /** `'auto'`: add clones only if the loop needs them. `'fill'`: add clones that fill the window. `false`: add no clones. @default 'auto' @see {@link https://twistedandy.github.io/better-carousel/#clones | example} */
147
+ clones?: 'auto' | 'fill' | false;
148
+ /** `true`: glide after a drag and stop at any position. `'snap'`: glide and stop at the nearest snap. @default false @see {@link https://twistedandy.github.io/better-carousel/#free | example} */
149
+ dragFree?: boolean | 'snap';
150
+ /** The length of the glide after a fast drag: the glide distance is divided by this number. `2`: half the distance. `0.5`: 2 times the distance. It also changes how many snaps a flick moves. The value must be more than 0. @default 1 @see {@link https://twistedandy.github.io/better-carousel/#free | example} */
151
+ dragFriction?: number;
152
+ /** `'trimSnaps'`: no empty space at the ends. `'keepSnaps'`: no empty space, but keep a snap for each group. `false`: snaps can show empty space. @default 'trimSnaps' @see {@link https://twistedandy.github.io/better-carousel/#contain | example} */
153
+ containScroll?: 'trimSnaps' | 'keepSnaps' | false;
154
+ /** The number of slides in one snap. `'auto'`: the slides that fit in the viewport. @default 1 @see {@link https://twistedandy.github.io/better-carousel/#groups | example} */
155
+ slidesPerSnap?: number | 'auto';
156
+ /** A fast flick can move more than one snap. `false`: one snap. A number: the maximum number of snaps. @default true @see {@link https://twistedandy.github.io/better-carousel/#skip | example} */
157
+ skipSnaps?: boolean | number;
158
+ /** The distance in px that the pointer moves before a drag starts. @default 10 */
159
+ dragThreshold?: number;
160
+ /** The duration of a motion by one snap, in ms. A longer motion takes more time, to a maximum of 2 times this value. @default 400 @see {@link https://twistedandy.github.io/better-carousel/#options-usage | example} */
161
+ duration?: number;
162
+ /** The index of the snap at the start. @default 0 @see {@link https://twistedandy.github.io/better-carousel/#options-usage | example} */
163
+ startSnap?: number;
164
+ /** `true`: start when the carousel comes within one screen of the view. A number: the distance in px. @default false @see {@link https://twistedandy.github.io/better-carousel/#lazy | example} */
165
+ lazy?: boolean | number;
166
+ /** Drag with the mouse, the pen and the finger. @default true */
167
+ drag?: boolean;
168
+ /** The mouse wheel moves a vertical carousel. `'both'`: also a horizontal carousel. `false`: the wheel does not move the carousel. @default true @see {@link https://twistedandy.github.io/better-carousel/#vertical | example} */
169
+ wheel?: boolean | 'both';
170
+ /** The arrow keys move the carousel while the keyboard focus is in it: left and right in a horizontal carousel, up and down in a vertical carousel. A key in a form field does not move the carousel. @default true */
171
+ keys?: boolean;
172
+ /** Measure again when a size changes. @default true @see {@link https://twistedandy.github.io/better-carousel/#options-usage | example} */
173
+ resize?: boolean;
174
+ /** Measure again when the page adds or removes a slide. @default true @see {@link https://twistedandy.github.io/better-carousel/#changes | example} */
175
+ slideChanges?: boolean;
176
+ /** Go to a slide when it gets the keyboard focus. @default true @see {@link https://twistedandy.github.io/better-carousel/#controls | example} */
177
+ focus?: boolean;
178
+ /** The part of a slide, from 0 to 1, that must show for `slidesInView()`. @default 0 @see {@link https://twistedandy.github.io/better-carousel/#options-usage | example} */
179
+ inViewThreshold?: number;
180
+ /** `false`: do not start the carousel. Use it in `breakpoints`. @default true @see {@link https://twistedandy.github.io/better-carousel/#breakpoints | example} */
181
+ active?: boolean;
182
+ /** The options for media queries: `{ '(min-width: 768px)': { loop: true } }`. @default {} @see {@link https://twistedandy.github.io/better-carousel/#breakpoints | example} */
183
+ breakpoints?: Record<string, Options>;
184
+ /** The selector of the container, if the element is the root. @default null */
185
+ container?: string | null;
186
+ /** The selector of the slides. With `null`, all children of the container are slides. @default null */
187
+ slides?: string | null;
188
+ /** Add the root and the viewport if the page does not have them. @default true @see {@link https://twistedandy.github.io/better-carousel/#options-usage | example} */
189
+ wrapper?: boolean;
190
+ /** Add the arrows to the root. `false`: no arrows. An element or a selector: add the arrows to that element. @default true @see {@link https://twistedandy.github.io/better-carousel/#heading | example} */
191
+ arrows?: boolean | Element | string;
192
+ /** Add the dots. The values are the same as for `arrows`. @default true @see {@link https://twistedandy.github.io/better-carousel/#heading | example} */
193
+ dots?: boolean | Element | string;
194
+ /** The style of the dots. `'zoom'`: a window of 5 dots that slides, with smaller dots at the ends. `'all'`: all dots with the same size. @default 'zoom' */
195
+ dotsStyle?: 'zoom' | 'all';
196
+ /** The texts for screen readers: `carousel`, `slide` (`'%d of %n'`), `prev`, `next`, `dot` (`'Go to slide %d'`), `play`, `pause`. `%d` is the slide number, and `%n` is the number of slides. @see {@link https://twistedandy.github.io/better-carousel/#accessibility | example} */
197
+ labels?: Labels;
198
+ /** A class prefix such as `'embla'`, or an object with the names to change. The Classes table gives all names. @default null @see {@link https://twistedandy.github.io/better-carousel/#embla | example} */
199
+ classes?: string | ClassNames | null;
200
+ /** The prefix of the state classes, such as `'is_'`. @default '' @see {@link https://twistedandy.github.io/better-carousel/#embla | example} */
201
+ state?: string;
202
+ /** Another carousel, its container or a selector. This carousel follows the selected slide of the other carousel. A click on a slide selects it in the other carousel. @default null @see {@link https://twistedandy.github.io/better-carousel/#product | example} */
203
+ sync?: Carousel | Element | string | null;
204
+ /** Go to the next slide after a delay. `true`, a delay in ms, or an object. @default false @see {@link https://twistedandy.github.io/better-carousel/#autoplay | example} */
205
+ autoplay?: boolean | number | AutoplayOptions;
206
+ /** Move the slides at a constant speed. `true`, a speed in px/s, or an object. @default false @see {@link https://twistedandy.github.io/better-carousel/#logos | example} */
207
+ autoScroll?: boolean | number | AutoScrollOptions;
208
+ /** The viewport gets the height of the tallest slide in view. @default false @see {@link https://twistedandy.github.io/better-carousel/#height | example} */
209
+ autoHeight?: boolean;
210
+ /** Follow the progress, from 0 to 1. `true` sets `--better-progress` on the root. A function gets `{ progress, snap }` on each frame of a motion. See Progress and offset. @default false */
211
+ progress?: boolean | ((state: ProgressState, carousel: Carousel) => void);
212
+ /** Follow the distance of each slide from its snap position, in slides. `true` sets `--better-offset` on each slide. A function gets `{ node, index, offset, distance, size, visible }` for each slide on each frame of a motion. @default false */
213
+ offset?: boolean | ((state: OffsetState, carousel: Carousel) => void);
214
+ // <!-- /generated -->
215
+ }
216
+
217
+ /** The names of the events. */
218
+ export type EventName =
219
+ | 'init'
220
+ | 'reinit'
221
+ | 'resize'
222
+ | 'select'
223
+ | 'scroll'
224
+ | 'settle'
225
+ | 'dragstart'
226
+ | 'dragend'
227
+ | 'slidesinview'
228
+ | 'slideschanged'
229
+ | 'slidefocus'
230
+ | 'autoplay:play'
231
+ | 'autoplay:stop'
232
+ | 'autoscroll:play'
233
+ | 'autoscroll:stop'
234
+ | 'destroy';
235
+
236
+ export type EventHandler = (carousel: Carousel, name: EventName) => void;
237
+
238
+ /** The control of the auto scroll. */
239
+ export interface PlayControl {
240
+ play(): void;
241
+ stop(): void;
242
+ isPlaying(): boolean;
243
+ }
244
+
245
+ /** The control of the autoplay. */
246
+ export interface AutoplayControl extends PlayControl {
247
+ /** Start the delay again. */
248
+ reset(): void;
249
+ }
250
+
251
+ /** A carousel. A snap index and a slide index are different: a snap can show more than one slide. */
252
+ export interface Carousel {
253
+ /** Go to a snap. With `instant` set to `true`, jump with no motion. */
254
+ goToSnap(snap: number, instant?: boolean): void;
255
+ goToNext(instant?: boolean): void;
256
+ goToPrev(instant?: boolean): void;
257
+ /** Go to the snap that shows a slide. This slide becomes the selected slide. */
258
+ goToSlide(slide: number, instant?: boolean): void;
259
+ /** `true` if a next snap exists. In a loop, `true` if not all slides fit. */
260
+ canGoToNext(): boolean;
261
+ /** `true` if a previous snap exists. In a loop, `true` if not all slides fit. */
262
+ canGoToPrev(): boolean;
263
+ /** The index of the selected snap. */
264
+ selectedSnap(): number;
265
+ /** The index of the snap before the selected snap. */
266
+ previousSnap(): number;
267
+ /** The index of the selected slide. With `sync`, the slide that is selected in the other carousel. */
268
+ selectedSlide(): number;
269
+ /** The index of the snap that shows a slide. */
270
+ snapOfSlide(slide: number): number;
271
+ /** The progress of each snap, from 0 to 1. */
272
+ snapProgress(): number[];
273
+ /** The progress now, from 0 to 1, also during a motion. */
274
+ progress(): number;
275
+ /** The indexes of the slides in view. */
276
+ slidesInView(): number[];
277
+ /** The slides. The list does not include the clones. */
278
+ slideNodes(): HTMLElement[];
279
+ rootNode(): HTMLElement;
280
+ viewportNode(): HTMLElement;
281
+ containerNode(): HTMLElement;
282
+ /** `true` if all slides fit in the viewport. */
283
+ isFit(): boolean;
284
+ /** The options that apply now, after the breakpoints. */
285
+ options(): Options;
286
+ /** Merge new options and start again. The selected slide stays. */
287
+ reinit(options?: Options): void;
288
+ /** Stop the carousel and restore the markup. */
289
+ destroy(): void;
290
+ on(name: EventName, handler: EventHandler): Carousel;
291
+ off(name: EventName, handler: EventHandler): Carousel;
292
+ /** Only with the `autoplay` option. */
293
+ autoplay?: AutoplayControl;
294
+ /** Only with the `autoScroll` option. */
295
+ autoScroll?: PlayControl;
296
+ }
297
+
298
+ declare const BetterCarousel: {
299
+ /** Start a carousel on a container or on its viewport. If the element has a carousel, return that carousel. */
300
+ (element: HTMLElement, options?: Options): Carousel;
301
+ /** The options for all carousels. Set it before you start the carousels. */
302
+ defaults: Options;
303
+ /** The carousel of a root, a viewport or a container. */
304
+ get(element: Element): Carousel | undefined;
305
+ /** Start a carousel on each element that matches the selector. */
306
+ initAll(selector: string, options?: Options): Carousel[];
307
+ };
308
+
309
+ export default BetterCarousel;