@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.
package/README.md CHANGED
@@ -1,3 +1,840 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <a href="https://twistedandy.github.io/better-carousel/"><img src="demo/assets/logo.svg" alt="Better Carousel" width="560" /></a>
4
+
5
+ <p>A small, fast and accessible JavaScript carousel.<br />The CSS sets the layout, and the motion runs on the compositor, also on slow phones.</p>
6
+
7
+ [![Gzip size](https://flat.badgen.net/static/gzip/12.6%20KB/green)](dist/better-carousel.min.js)
8
+ [![MIT license](https://flat.badgen.net/static/license/MIT/purple)](LICENSE)
9
+ [![No dependencies](https://flat.badgen.net/static/dependencies/0/blue)](package.json)
10
+
11
+ **[Documentation and live examples](https://twistedandy.github.io/better-carousel/)** · [Issues](https://github.com/TwistedAndy/better-carousel/issues)
12
+
13
+ </div>
14
+
15
+ ## Features
16
+
17
+ - **Layout from CSS** - Your CSS sets the sizes of the slides, the space between them, the axis and the alignment. One carousel can show 1 slide on a phone and 4 slides on a desktop.
18
+ - **Smooth** - Each motion is a Web Animations API animation of `translate`. No script runs on each frame, also during the auto scroll.
19
+ - **Small** - <!-- generated:gzip -->12.6 KB<!-- /generated --> gzip with loop, autoplay, auto scroll, auto height, sync and the mouse wheel.
20
+ - **Loop** - The loop moves the original slides. It adds clones only if the slides are too few.
21
+ - **Vertical and grid** - A column layout makes a vertical carousel. A CSS grid with more rows also works.
22
+ - **Accessible** - WCAG 2.1 AA: names for the carousel, the slides and the buttons, the keyboard focus, a live region and reduced motion.
23
+ - **Lazy start** - With the `lazy` option, a carousel out of view starts when it comes near the screen.
24
+
25
+ ## Install
26
+
27
+ Load the minified script and the stylesheet from jsDelivr. The script adds the global `BetterCarousel` function.
28
+
29
+ ```html
30
+ <link
31
+ rel="stylesheet"
32
+ href="https://cdn.jsdelivr.net/gh/TwistedAndy/better-carousel@v1.1.0/dist/better-carousel.css"
33
+ integrity="sha384-3ROtqpAC1ZPhSpDul73SGiTOv1L5kTr/08sUr6FPY6S79RIDi7mpI22ttbuxI/w8"
34
+ crossorigin="anonymous"
35
+ />
36
+ <script
37
+ src="https://cdn.jsdelivr.net/gh/TwistedAndy/better-carousel@v1.1.0/dist/better-carousel.min.js"
38
+ integrity="sha384-UjCkof+Hhn4+1TwAy29U/sKHOeabjJs4q+6SKn0GrTEDkuWVfGy0vkZncDkmjlzZ"
39
+ crossorigin="anonymous"
40
+ ></script>
41
+ ```
42
+
43
+ Or install the package from npm, and import the script and the stylesheet with a bundler:
44
+
45
+ ```sh
46
+ npm install @twistedandy/better-carousel
47
+ ```
48
+
49
+ ```js
50
+ import BetterCarousel from '@twistedandy/better-carousel'
51
+ import '@twistedandy/better-carousel/css'
52
+ ```
53
+
54
+ | File | Format | Use |
55
+ | --- | --- | --- |
56
+ | `dist/better-carousel.min.js` | IIFE, minified | For a `script` tag. It adds the global `BetterCarousel` function. |
57
+ | `dist/better-carousel.js` | ES module | For a bundler: `import BetterCarousel from '@twistedandy/better-carousel'`. |
58
+ | `dist/better-carousel.css` | CSS | The styles with the default class names. |
59
+ | `src/types/better-carousel.d.ts` | TypeScript | The types. TypeScript and the editors find them automatically. |
60
+ | `src/styles/better-carousel.scss` | SCSS | The styles with your class names: `@twistedandy/better-carousel/scss`. See [Styling](#styling). |
61
+
62
+ ## Quick start
63
+
64
+ 1. Put the slides into a container.
65
+ 2. Give the container a flex row with CSS.
66
+ 3. Give each slide a width and a right margin.
67
+ 4. Start the carousel.
68
+
69
+ ```html
70
+ <div class="items carousel">
71
+ <div class="item"><img src="photo-1.jpg" alt="Photo 1" /></div>
72
+ <div class="item"><img src="photo-2.jpg" alt="Photo 2" /></div>
73
+ <div class="item"><img src="photo-3.jpg" alt="Photo 3" /></div>
74
+ <div class="item"><img src="photo-4.jpg" alt="Photo 4" /></div>
75
+ </div>
76
+ ```
77
+
78
+ ```css
79
+ /* The negative margin of the container cancels the margin of the last slide in the row */
80
+ .items {
81
+ --gap: 20px;
82
+ display: flex;
83
+ width: calc(100% + var(--gap));
84
+ margin-right: calc(-1 * var(--gap));
85
+ }
86
+
87
+ .items .item {
88
+ flex: none;
89
+ width: calc(100% / 3 - var(--gap));
90
+ margin-right: var(--gap);
91
+ }
92
+ ```
93
+
94
+ ```js
95
+ // One carousel
96
+ const carousel = BetterCarousel(document.querySelector('.items'))
97
+
98
+ // All carousels on the page
99
+ const carousels = BetterCarousel.initAll('.items.carousel')
100
+ ```
101
+
102
+ The [documentation](https://twistedandy.github.io/better-carousel/) has live examples: alignment, vertical carousels, grids, free drag, thumbnails, autoplay, auto scroll and auto height.
103
+
104
+ ## Concepts
105
+
106
+ The library puts the container into a viewport and a root. Then it adds the arrows and the dots to the root:
107
+
108
+ ```html
109
+ <div class="better" role="region" aria-roledescription="carousel" aria-label="Carousel">
110
+ <div class="better_viewport">
111
+ <div class="items carousel better_container">
112
+ <div class="item">...</div>
113
+ </div>
114
+ </div>
115
+ <button class="better_button better_prev" aria-label="Previous slide"></button>
116
+ <button class="better_button better_next" aria-label="Next slide"></button>
117
+ <div class="better_dots">...</div>
118
+ </div>
119
+ ```
120
+
121
+ | Term | Meaning |
122
+ | --- | --- |
123
+ | Root | The outer element. It holds the viewport, the arrows and the dots. The library adds it if the page does not have it. |
124
+ | Viewport | The element that clips the slides. Its size is the visible area. |
125
+ | Container | The element that moves. Your CSS sets its layout, and the library sets its `translate`. |
126
+ | Slide | A child of the container, or an element that matches the `slides` selector. |
127
+ | Snap | A position where the carousel can stop. A snap shows one slide or a group of slides. |
128
+ | Selected snap | The snap that shows now. `selectedSnap()` gives its index. |
129
+ | Selected slide | The slide at the selected snap. It gets the `selected` class. `selectedSlide()` gives its index. |
130
+ | Clone | A copy of a slide that the loop adds when the slides are too few. Clones are not in `slideNodes()`, and they have no index. A change in the content of a slide also changes its clones. |
131
+ | Motion | A change of position with an animation. When a motion stops, the `settle` event occurs. |
132
+ | Fit | All slides show in the viewport. The carousel does not move, and it does not show the arrows and the dots. |
133
+
134
+ A carousel can have fewer snaps than slides. For example, `slidesPerSnap: 2` puts two slides into each snap. Also, `containScroll: 'trimSnaps'` removes the snaps that show empty space at the ends. For this reason, the methods use two types of index:
135
+
136
+ - `goToSnap()`, `selectedSnap()` and `snapProgress()` use a snap index.
137
+ - `goToSlide()`, `selectedSlide()`, `slidesInView()` and `slideNodes()` use a slide index.
138
+ - `snapOfSlide(index)` gives the snap index of a slide.
139
+
140
+ ## CSS layout
141
+
142
+ The library does not set the size of the slides or the space between them. It reads these values from the CSS and moves only the container.
143
+
144
+ | The CSS of the container | The result |
145
+ | --- | --- |
146
+ | `display: flex`, a row | A horizontal carousel |
147
+ | `flex-direction: column` | A vertical carousel |
148
+ | `display: grid` with `grid-auto-flow: column` | A horizontal carousel with more rows |
149
+ | `justify-content: center` | The selected slide is in the center |
150
+ | `justify-content: flex-end` | The selected slide is at the end |
151
+ | The margins of the slides and a negative margin of the container | The space between the slides. In a loop, also the space between the last slide and the first slide. |
152
+ | `direction: rtl` | A right-to-left carousel |
153
+ | The padding of the viewport | The snaps align to the inner edge of the padding. The padding shows parts of the slides next to the selected slide. |
154
+
155
+ The carousel measures again when the CSS changes, when the page adds or removes a slide, and when an image loads. A slide with `display: none` gets no snap. The `template`, `script` and `style` elements in the container are not slides. A CSS `scale` or `rotate` on a parent, such as the open animation of a modal window, does not change the snaps. To add or remove a slide, change the elements in the container.
156
+
157
+ A carousel can start in a hidden element, such as a tab, an accordion or a modal window. It has no size, so it shows no arrows and no dots. When the element shows, the carousel measures and starts to move.
158
+
159
+ ## Frameworks
160
+
161
+ 1. Render the root and the viewport in the component.
162
+ 2. When the component mounts, start the carousel on the viewport. The library finds the container in the viewport and adds no wrapper.
163
+ 3. Before the component unmounts, destroy the carousel.
164
+
165
+ The library does not move the elements that the framework controls.
166
+
167
+ ### React
168
+
169
+ In Strict Mode, React runs each effect two times in development. The cleanup function destroys the first carousel, and the second carousel replaces it.
170
+
171
+ ```jsx
172
+ import { useEffect, useRef } from 'react'
173
+ import BetterCarousel from '@twistedandy/better-carousel'
174
+ import '@twistedandy/better-carousel/css'
175
+
176
+ export default function Carousel({ slides, options }) {
177
+ const viewport = useRef(null)
178
+ const carousel = useRef(null)
179
+
180
+ useEffect(() => {
181
+ carousel.current = BetterCarousel(viewport.current, options)
182
+ return () => carousel.current.destroy()
183
+ }, [])
184
+
185
+ return (
186
+ <>
187
+ <div className="better">
188
+ <div className="better_viewport" ref={viewport}>
189
+ <div className="items">
190
+ {slides.map((slide) => (
191
+ <div className="item" key={slide.id}>
192
+ <img src={slide.src} alt={slide.alt} />
193
+ </div>
194
+ ))}
195
+ </div>
196
+ </div>
197
+ </div>
198
+ <button type="button" onClick={() => carousel.current.goToNext()}>Next slide</button>
199
+ </>
200
+ )
201
+ }
202
+ ```
203
+
204
+ ### Vue
205
+
206
+ ```vue
207
+ <script setup>
208
+ import { onMounted, onBeforeUnmount, ref } from 'vue'
209
+ import BetterCarousel from '@twistedandy/better-carousel'
210
+ import '@twistedandy/better-carousel/css'
211
+
212
+ const props = defineProps({ slides: Array, options: Object })
213
+ const viewport = ref(null)
214
+ let carousel = null
215
+
216
+ onMounted(() => {
217
+ carousel = BetterCarousel(viewport.value, props.options)
218
+ })
219
+
220
+ onBeforeUnmount(() => carousel?.destroy())
221
+ </script>
222
+
223
+ <template>
224
+ <div class="better">
225
+ <div ref="viewport" class="better_viewport">
226
+ <div class="items">
227
+ <div v-for="slide in slides" :key="slide.id" class="item">
228
+ <img :src="slide.src" :alt="slide.alt" />
229
+ </div>
230
+ </div>
231
+ </div>
232
+ </div>
233
+ </template>
234
+ ```
235
+
236
+ ### Svelte
237
+
238
+ This example is for Svelte 5. For Svelte 4, use `export let slides` and `export let options` in place of `$props()`.
239
+
240
+ ```svelte
241
+ <script>
242
+ import { onMount } from 'svelte'
243
+ import BetterCarousel from '@twistedandy/better-carousel'
244
+ import '@twistedandy/better-carousel/css'
245
+
246
+ let { slides, options } = $props()
247
+ let viewport
248
+
249
+ onMount(() => {
250
+ const carousel = BetterCarousel(viewport, options)
251
+ return () => carousel.destroy()
252
+ })
253
+ </script>
254
+
255
+ <div class="better">
256
+ <div class="better_viewport" bind:this={viewport}>
257
+ <div class="items">
258
+ {#each slides as slide (slide.id)}
259
+ <div class="item"><img src={slide.src} alt={slide.alt} /></div>
260
+ {/each}
261
+ </div>
262
+ </div>
263
+ </div>
264
+ ```
265
+
266
+ ### Solid
267
+
268
+ ```jsx
269
+ import { onMount, onCleanup, For } from 'solid-js'
270
+ import BetterCarousel from '@twistedandy/better-carousel'
271
+ import '@twistedandy/better-carousel/css'
272
+
273
+ export default function Carousel(props) {
274
+ let viewport
275
+
276
+ onMount(() => {
277
+ const carousel = BetterCarousel(viewport, props.options)
278
+ onCleanup(() => carousel.destroy())
279
+ })
280
+
281
+ return (
282
+ <div class="better">
283
+ <div class="better_viewport" ref={viewport}>
284
+ <div class="items">
285
+ <For each={props.slides}>
286
+ {(slide) => <div class="item"><img src={slide.src} alt={slide.alt} /></div>}
287
+ </For>
288
+ </div>
289
+ </div>
290
+ </div>
291
+ )
292
+ }
293
+ ```
294
+
295
+ ### Rules for frameworks
296
+
297
+ - Do not render other elements after the viewport in the root. The library adds the arrows and the dots at the end of the root. To put them in a different element, set the [`arrows`](#options) and [`dots`](#options) options.
298
+ - To change the options, call `reinit(newOptions)`. The selected slide stays.
299
+ - With server-side rendering, start the carousel only in the browser: in `useEffect`, `onMounted` or `onMount`. The library needs the DOM.
300
+
301
+ NOTE: When the framework adds or removes a slide, the carousel measures again. A `reinit()` call is not necessary.
302
+
303
+ ## Options
304
+
305
+ Set the options in one of these places:
306
+
307
+ - In the call: `BetterCarousel(element, options)`.
308
+ - In the `data-carousel` attribute, as JSON.
309
+ - In `BetterCarousel.defaults`, for all carousels.
310
+
311
+ If the call and the attribute set the same option, the value of the attribute applies.
312
+
313
+ ```html
314
+ <div class="items carousel" data-carousel='{"loop":true,"autoplay":3000}'>...</div>
315
+ ```
316
+
317
+ ```js
318
+ // All carousels of the site
319
+ BetterCarousel.defaults = { dragThreshold: 2 }
320
+
321
+ // One carousel, with different options for a media query
322
+ BetterCarousel(element, {
323
+ align: 'center',
324
+ breakpoints: {
325
+ '(min-width: 1024px)': { drag: false },
326
+ },
327
+ })
328
+
329
+ // The options that need no example of their own
330
+ BetterCarousel(element, {
331
+ startSnap: 2, // Start at the third snap
332
+ duration: 600, // The duration of a motion by one snap, in ms
333
+ inViewThreshold: 0.5, // A slide is in view when half of it shows
334
+ resize: false, // Do not measure again when a size changes
335
+ slideChanges: false, // Do not watch for added and removed slides
336
+ wrapper: false, // Add no root and viewport: the page has them
337
+ })
338
+ ```
339
+
340
+ <!-- generated:options -->
341
+ | Option | Type | Default | Description |
342
+ | --- | --- | --- | --- |
343
+ | `axis` | `'x'`, `'y'`, `'auto'` | `'auto'` | The axis of the motion. With `'auto'`, the CSS of the container sets the axis. ([example](https://twistedandy.github.io/better-carousel/#switch)) |
344
+ | `align` | `'start'`, `'center'`, `'end'`, `'auto'`, `function` | `'auto'` | 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. ([example](https://twistedandy.github.io/better-carousel/#center)) |
345
+ | `dir` | `'ltr'`, `'rtl'`, `'auto'` | `'auto'` | The text direction. With `'auto'`, the CSS `direction` sets it. ([example](https://twistedandy.github.io/better-carousel/#rtl)) |
346
+ | `loop` | `boolean` | `false` | The first slide comes after the last slide. ([example](https://twistedandy.github.io/better-carousel/#loop)) |
347
+ | `clones` | `'auto'`, `'fill'`, `false` | `'auto'` | `'auto'`: add clones only if the loop needs them. `'fill'`: add clones that fill the window. `false`: add no clones. ([example](https://twistedandy.github.io/better-carousel/#clones)) |
348
+ | `dragFree` | `boolean`, `'snap'` | `false` | `true`: glide after a drag and stop at any position. `'snap'`: glide and stop at the nearest snap. ([example](https://twistedandy.github.io/better-carousel/#free)) |
349
+ | `dragFriction` | `number` | `1` | 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. ([example](https://twistedandy.github.io/better-carousel/#free)) |
350
+ | `containScroll` | `'trimSnaps'`, `'keepSnaps'`, `false` | `'trimSnaps'` | `'trimSnaps'`: no empty space at the ends. `'keepSnaps'`: no empty space, but keep a snap for each group. `false`: snaps can show empty space. ([example](https://twistedandy.github.io/better-carousel/#contain)) |
351
+ | `slidesPerSnap` | `number`, `'auto'` | `1` | The number of slides in one snap. `'auto'`: the slides that fit in the viewport. ([example](https://twistedandy.github.io/better-carousel/#groups)) |
352
+ | `skipSnaps` | `boolean`, `number` | `true` | A fast flick can move more than one snap. `false`: one snap. A number: the maximum number of snaps. ([example](https://twistedandy.github.io/better-carousel/#skip)) |
353
+ | `dragThreshold` | `number` | `10` | The distance in px that the pointer moves before a drag starts. |
354
+ | `duration` | `number` | `400` | The duration of a motion by one snap, in ms. A longer motion takes more time, to a maximum of 2 times this value. ([example](https://twistedandy.github.io/better-carousel/#options-usage)) |
355
+ | `startSnap` | `number` | `0` | The index of the snap at the start. ([example](https://twistedandy.github.io/better-carousel/#options-usage)) |
356
+ | `lazy` | `boolean`, `number` | `false` | `true`: start when the carousel comes within one screen of the view. A number: the distance in px. ([example](https://twistedandy.github.io/better-carousel/#lazy)) |
357
+ | `drag` | `boolean` | `true` | Drag with the mouse, the pen and the finger. |
358
+ | `wheel` | `boolean`, `'both'` | `true` | The mouse wheel moves a vertical carousel. `'both'`: also a horizontal carousel. `false`: the wheel does not move the carousel. ([example](https://twistedandy.github.io/better-carousel/#vertical)) |
359
+ | `keys` | `boolean` | `true` | 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. |
360
+ | `resize` | `boolean` | `true` | Measure again when a size changes. ([example](https://twistedandy.github.io/better-carousel/#options-usage)) |
361
+ | `slideChanges` | `boolean` | `true` | Measure again when the page adds or removes a slide. ([example](https://twistedandy.github.io/better-carousel/#changes)) |
362
+ | `focus` | `boolean` | `true` | Go to a slide when it gets the keyboard focus. ([example](https://twistedandy.github.io/better-carousel/#controls)) |
363
+ | `inViewThreshold` | `number` | `0` | The part of a slide, from 0 to 1, that must show for `slidesInView()`. ([example](https://twistedandy.github.io/better-carousel/#options-usage)) |
364
+ | `active` | `boolean` | `true` | `false`: do not start the carousel. Use it in `breakpoints`. ([example](https://twistedandy.github.io/better-carousel/#breakpoints)) |
365
+ | `breakpoints` | `object` | `{}` | The options for media queries: `{ '(min-width: 768px)': { loop: true } }`. ([example](https://twistedandy.github.io/better-carousel/#breakpoints)) |
366
+ | `container` | `string` | `null` | The selector of the container, if the element is the root. |
367
+ | `slides` | `string` | `null` | The selector of the slides. With `null`, all children of the container are slides. |
368
+ | `wrapper` | `boolean` | `true` | Add the root and the viewport if the page does not have them. ([example](https://twistedandy.github.io/better-carousel/#options-usage)) |
369
+ | `arrows` | `boolean`, `Element`, `string` | `true` | Add the arrows to the root. `false`: no arrows. An element or a selector: add the arrows to that element. ([example](https://twistedandy.github.io/better-carousel/#heading)) |
370
+ | `dots` | `boolean`, `Element`, `string` | `true` | Add the dots. The values are the same as for `arrows`. ([example](https://twistedandy.github.io/better-carousel/#heading)) |
371
+ | `dotsStyle` | `'zoom'`, `'all'` | `'zoom'` | 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. |
372
+ | `labels` | `object` | English | 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. ([example](#accessibility)) |
373
+ | `classes` | `string`, `object` | `null` | A class prefix such as `'embla'`, or an object with the names to change. The [Classes](#classes) table gives all names. ([example](https://twistedandy.github.io/better-carousel/#embla)) |
374
+ | `state` | `string` | `''` | The prefix of the state classes, such as `'is_'`. ([example](https://twistedandy.github.io/better-carousel/#embla)) |
375
+ | `sync` | carousel, `Element`, `string` | `null` | 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. ([example](https://twistedandy.github.io/better-carousel/#product)) |
376
+ | `autoplay` | `boolean`, `number`, `object` | `false` | Go to the next slide after a delay. `true`, a delay in ms, or an object. ([example](#autoplay)) |
377
+ | `autoScroll` | `boolean`, `number`, `object` | `false` | Move the slides at a constant speed. `true`, a speed in px/s, or an object. ([example](https://twistedandy.github.io/better-carousel/#logos)) |
378
+ | `autoHeight` | `boolean` | `false` | The viewport gets the height of the tallest slide in view. ([example](https://twistedandy.github.io/better-carousel/#height)) |
379
+ | `progress` | `boolean`, `function` | `false` | 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](#progress-and-offset). |
380
+ | `offset` | `boolean`, `function` | `false` | 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. |
381
+ <!-- /generated -->
382
+
383
+ ### autoplay
384
+
385
+ The value is `true`, a delay in ms, or an object. In the object, `delay` can also be an array with one delay for each snap. A `data-delay` attribute on a slide sets the delay of that slide, and it has priority over `delay`.
386
+
387
+ The autoplay pauses in these conditions:
388
+
389
+ - The keyboard focus is in the carousel.
390
+ - The tab is hidden.
391
+ - The carousel is out of view.
392
+
393
+ If the user prefers reduced motion, the autoplay does not start. A breakpoint change keeps the play state: a stopped autoplay stays stopped. These are the default values:
394
+
395
+ ```js
396
+ BetterCarousel(element, {
397
+ autoplay: {
398
+ delay: 4000, // ms on each slide, or an array with ms for each snap
399
+ stopOnInteraction: true, // A drag, an arrow or a dot stops the autoplay
400
+ pauseOnHover: false, // Pause while the mouse is on the carousel
401
+ pauseOnFocus: true, // Pause while the keyboard focus is in the carousel
402
+ stopOnLastSnap: false, // Stop at the last snap, if loop is false
403
+ playOnInit: true,
404
+ instant: false, // Jump to the next slide with no motion
405
+ timer: null, // A function that shows the time to the next slide
406
+ },
407
+ })
408
+ ```
409
+
410
+ To show the time to the next slide, set `timer` to a function. The carousel calls it when the timer starts, with the delay in ms and the carousel. The function can return a cleanup function. The carousel calls the cleanup function when this timer ends or stops, for example at a pause. The library has no styles for a progress indicator.
411
+
412
+ ```js
413
+ const bar = document.querySelector('.progress')
414
+
415
+ BetterCarousel(element, {
416
+ autoplay: {
417
+ timer: (delay) => {
418
+ const animation = bar.animate([{ scale: '0 1' }, { scale: '1 1' }], delay)
419
+ return () => animation.cancel()
420
+ },
421
+ },
422
+ })
423
+ ```
424
+
425
+ An animation of `scale`, `translate` or `opacity` runs on the compositor: no script runs for each frame.
426
+
427
+ ### autoScroll
428
+
429
+ The value is `true`, a speed in px/s, or an object. The motion is one animation on the compositor. The pause conditions are the same as for the autoplay. A press on the slides also stops them. If the pointer does not drag, the motion starts again after `startDelay`. These are the default values:
430
+
431
+ ```js
432
+ BetterCarousel(element, {
433
+ loop: true,
434
+ autoScroll: {
435
+ speed: 120, // px per second
436
+ direction: 'next', // or 'prev'
437
+ startDelay: 1000, // ms before the start, and after an interaction
438
+ stopOnInteraction: true,
439
+ pauseOnHover: false,
440
+ pauseOnFocus: true,
441
+ playOnInit: true,
442
+ },
443
+ })
444
+ ```
445
+
446
+ ### sync
447
+
448
+ The `sync` option links two carousels, for example a gallery and its thumbnails:
449
+
450
+ 1. Put the same slides into the two carousels, in the same order.
451
+ 2. Use buttons for the thumbnails, so that the keyboard can select them.
452
+ 3. Set `sync` on the thumbnails carousel.
453
+
454
+ The thumbnails follow the main gallery, and a click on a thumbnail selects its photo. A drag moves only the thumbnails. The thumbnail of the selected photo gets the `selected` class. In this example, the `arrows` option puts the arrows of the main gallery next to the thumbnails.
455
+
456
+ ```html
457
+ <div class="items carousel gallery_main" data-carousel='{"dots":false,"arrows":".gallery_nav"}'>...</div>
458
+ <div class="gallery_nav">
459
+ <div class="items carousel gallery_thumbs" data-carousel='{"sync":".gallery_main","arrows":false,"dots":false}'>
460
+ <button type="button" class="item"><img src="thumb-1.jpg" alt="Show photo 1" /></button>
461
+ ...
462
+ </div>
463
+ </div>
464
+ ```
465
+
466
+ The value of `sync` can be a selector, a container or a carousel. The library searches for a selector in the root of the carousel first, and then in each parent of the root. A carousel can follow only one other carousel.
467
+
468
+ ### progress and offset
469
+
470
+ The `progress` and `offset` options give the position of the carousel on each frame of a motion. Use them for a progress bar, a parallax effect, or a fade. They are off by default, because a script runs on each frame while they are on.
471
+
472
+ With `true`, the carousel sets CSS variables:
473
+
474
+ - `--better-progress` on the root: the progress, from 0 to 1;
475
+ - `--better-offset` on each slide: the distance from the snap position of the slide, in slides. The value is 0 at the snap position, 1 for the next slide and -1 for the previous slide.
476
+
477
+ ```html
478
+ <div class="items carousel" data-carousel='{"progress":true,"offset":true}'>...</div>
479
+ ```
480
+
481
+ A progress bar at the bottom of the slides:
482
+
483
+ ```css
484
+ .better_viewport::after {
485
+ content: "";
486
+ position: absolute;
487
+ inset: auto 0 0;
488
+ z-index: 3;
489
+ height: 4px;
490
+ background: currentColor;
491
+ transform-origin: left;
492
+ scale: var(--better-progress, 0) 1;
493
+ }
494
+ ```
495
+
496
+ Parallax: each photo is larger than its slide, and it moves slower than the slide.
497
+
498
+ ```css
499
+ .better .item {
500
+ overflow: hidden;
501
+ }
502
+
503
+ .better .item img {
504
+ scale: 1.3;
505
+ translate: calc(clamp(-1, var(--better-offset, 0), 1) * -10%) 0;
506
+ }
507
+ ```
508
+
509
+ Scale and fade: the photos far from the selected snap are smaller and lighter.
510
+
511
+ ```css
512
+ .better .item {
513
+ --distance: min(1, max(var(--better-offset, 0), -1 * var(--better-offset, 0)));
514
+ }
515
+
516
+ .better .item img {
517
+ scale: calc(1 - 0.25 * var(--distance));
518
+ opacity: calc(1 - 0.6 * var(--distance));
519
+ }
520
+ ```
521
+
522
+ Change an element in the slide, not the slide. The carousel measures the slides, and a `scale` on a slide changes its size for the carousel.
523
+
524
+ A function gets a state object and the carousel. The carousel uses the same object for each call, so read the values during the call:
525
+
526
+ ```js
527
+ BetterCarousel(element, {
528
+ // { progress, snap }: snap is the position between the snaps, for example 2.4
529
+ progress: ({ progress, snap }) => {
530
+ bar.style.scale = progress + ' 1';
531
+ },
532
+ // { node, index, offset, distance, size, visible }, one call for each slide
533
+ offset: ({ node, offset, visible }) => {
534
+ node.style.opacity = 0.4 + 0.6 * visible;
535
+ },
536
+ })
537
+ ```
538
+
539
+ - `distance` is the same distance as `offset`, in px on the screen. A positive value is to the right or down.
540
+ - `size` is the size of the slide on the main axis, in px.
541
+ - `visible` is the part of the slide in the viewport, from 0 to 1.
542
+ - `index` is the index of the slide. A clone gives the index of its slide.
543
+
544
+ In loop mode, the progress goes from 1 back to 0. The auto scroll is a motion that does not stop: with these options, a script runs on each frame while it plays.
545
+
546
+ ## Methods
547
+
548
+ `BetterCarousel(element, options)` returns the carousel. The methods below are the methods of the carousel, and of the `BetterCarousel` function.
549
+
550
+ <!-- generated:methods -->
551
+ | Method | Returns | Description |
552
+ | --- | --- | --- |
553
+ | `BetterCarousel(element, options)` | carousel | Start a carousel on a container or on its viewport. If the element has a carousel, return that carousel. |
554
+ | `goToSnap(index, instant)` | - | Go to a snap. `index` is a snap index. With `instant` set to `true`, jump with no motion. |
555
+ | `goToNext(instant)`, `goToPrev(instant)` | - | Go to the next or the previous snap. |
556
+ | `goToSlide(index, instant)` | - | Go to the snap that shows a slide. `index` is a slide index. This slide becomes the selected slide. |
557
+ | `canGoToNext()`, `canGoToPrev()` | `boolean` | `true` if a next or a previous snap exists. In a loop, `true` if not all slides fit. |
558
+ | `selectedSnap()`, `previousSnap()` | `number` | The index of the selected snap, or of the snap before it. |
559
+ | `selectedSlide()` | `number` | The index of the selected slide. With `sync`, the slide that is selected in the other carousel. |
560
+ | `snapOfSlide(index)` | `number` | The index of the snap that shows a slide. |
561
+ | `snapProgress()` | `number[]` | The progress of each snap, from 0 to 1. |
562
+ | `progress()` | `number` | The progress now, from 0 to 1, also during a motion. |
563
+ | `slidesInView()` | `number[]` | The indexes of the slides in view. |
564
+ | `slideNodes()` | `HTMLElement[]` | The slides. The list does not include the clones. |
565
+ | `rootNode()`, `viewportNode()`, `containerNode()` | `HTMLElement` | The root, the viewport and the container. |
566
+ | `isFit()` | `boolean` | `true` if all slides fit in the viewport. |
567
+ | `options()` | `object` | The options that apply now, after the breakpoints. |
568
+ | `reinit(options)` | - | Merge new options and start again. The selected slide stays. |
569
+ | `destroy()` | - | Stop the carousel and restore the markup. |
570
+ | `on(name, handler)`, `off(name, handler)` | carousel | Add or remove an event handler. The handler gets `(carousel, name)`. |
571
+ | `autoplay` | `object` | Only with the `autoplay` option: `play()`, `stop()`, `reset()` and `isPlaying()`. |
572
+ | `autoScroll` | `object` | Only with the `autoScroll` option: `play()`, `stop()` and `isPlaying()`. |
573
+ | `BetterCarousel.get(element)` | carousel, `undefined` | The carousel of a root, a viewport or a container. |
574
+ | `BetterCarousel.initAll(selector, options)` | carousel[] | Start a carousel on each element that matches the selector. |
575
+ | `BetterCarousel.defaults` | `object` | The options for all carousels. Set it before you start the carousels. |
576
+ <!-- /generated -->
577
+
578
+ ```js
579
+ const carousel = BetterCarousel(element, { loop: true })
580
+
581
+ carousel.on('select', (carousel) => {
582
+ console.log('Slide', carousel.selectedSlide())
583
+ })
584
+
585
+ document.querySelector('.next').addEventListener('click', () => carousel.goToNext())
586
+ ```
587
+
588
+ ## Events
589
+
590
+ Add a handler with `on(name, handler)`, and remove it with `off(name, handler)`. The handler gets `(carousel, name)`.
591
+
592
+ <!-- generated:events -->
593
+ | Event | When |
594
+ | --- | --- |
595
+ | `init` | The carousel measured the layout for the first time. |
596
+ | `reinit` | A `reinit()` call or a breakpoint started the carousel again. |
597
+ | `resize` | The layout changed. |
598
+ | `select` | The selected snap changed. |
599
+ | `scroll` | The position changed during a motion or a drag. |
600
+ | `settle` | A motion stopped. |
601
+ | `dragstart`, `dragend` | A drag started or stopped. |
602
+ | `slidesinview` | The slides in view changed. |
603
+ | `slideschanged` | The page added or removed a slide. |
604
+ | `slidefocus` | A slide got the keyboard focus. |
605
+ | `autoplay:play`, `autoplay:stop` | The autoplay started or stopped. |
606
+ | `autoscroll:play`, `autoscroll:stop` | The auto scroll started or stopped. |
607
+ | `destroy` | The carousel stopped and restored the markup. |
608
+ <!-- /generated -->
609
+
610
+ CAUTION: Add a `scroll` handler only if you need it. With this handler, each motion runs in a `requestAnimationFrame` loop on the main thread.
611
+
612
+ ## Styling
613
+
614
+ The stylesheet has the rules that the carousel needs. It also has the look of the arrows, the dots and the play button.
615
+
616
+ - To change the colors, set the CSS variables.
617
+ - To change the class names, compile the SCSS file.
618
+
619
+ ### CSS variables
620
+
621
+ The buttons and the dots use the button variables of the theme. The arrow icon is an inline SVG in the stylesheet. To use a different icon, set `--button-arrow`.
622
+
623
+ ```css
624
+ :root {
625
+ --height-button: 2.5rem; /* The size of the buttons */
626
+ --button-arrow: url(arrow.svg); /* Optional: the default is a chevron */
627
+ --button-border: #7c3aed;
628
+ --button-base: #7c3aed; /* Also the selected dot */
629
+ --button-text: #fff;
630
+ --button-border-active: #6d28d9;
631
+ --button-base-active: #6d28d9;
632
+ --button-text-active: #fff;
633
+ --button-border-disabled: #e8e8e8;
634
+ --button-base-disabled: #f5f5f5;
635
+ --button-text-disabled: #74787d; /* Also the dots */
636
+ }
637
+ ```
638
+
639
+ ### SCSS
640
+
641
+ The SCSS file uses `@import` and global variables, so it compiles with Dart Sass and with node-sass. Set the variables before the import:
642
+
643
+ ```scss
644
+ $better: 'embla'; // The class prefix: .embla, .embla_viewport, .embla_button
645
+ $better-state: 'is_'; // The prefix of the state classes: .is_selected, .is_current
646
+ $better-look: false; // Only the rules that the carousel needs
647
+ $better-arrow: url(arrow.svg); // The default icon of the arrows. The --button-arrow variable comes first.
648
+
649
+ @import 'better-carousel';
650
+ ```
651
+
652
+ Then set the same names in the options: `{ classes: 'embla', state: 'is_' }`.
653
+
654
+ ### Classes
655
+
656
+ These are the default class names. A prefix in `classes` changes the first part of the names. The `state` prefix changes the state classes: `selected`, `dragging`, `playing` and the classes of the dots.
657
+
658
+ <!-- generated:classes -->
659
+ | Class | Element |
660
+ | --- | --- |
661
+ | `better` | The root |
662
+ | `better_viewport` | The viewport |
663
+ | `better_container` | The container |
664
+ | `better_horizontal`, `better_vertical` | The axis, on the root |
665
+ | `better_fit` | On the root, if all slides fit |
666
+ | `better_auto_height` | On the root, with `autoHeight` |
667
+ | `better_button`, `better_prev`, `better_next`, `better_play` | The buttons |
668
+ | `better_dots`, `better_dots_track`, `better_dot` | The window of the dots, the row that slides in it, and the dots |
669
+ | `better_dots_marker` | The marker of the selected dot |
670
+ | `better_dots_all` | On the window of the dots, with `dotsStyle: 'all'` |
671
+ | `selected` | The selected slide |
672
+ | `clone` | A clone of a slide |
673
+ | `dragging` | On the root, during a drag |
674
+ | `playing` | On the root, while the autoplay or the auto scroll plays |
675
+ | `current`, `prev`, `next`, `first`, `last` | The selected dot and the four dots around it |
676
+ <!-- /generated -->
677
+
678
+ ```js
679
+ // .embla, .embla_viewport, .embla_button, .is_selected
680
+ BetterCarousel(element, { classes: 'embla', state: 'is_' })
681
+
682
+ // Change one name
683
+ BetterCarousel(element, { classes: { selected: 'snapped' } })
684
+ ```
685
+
686
+ ## Accessibility
687
+
688
+ The carousel follows the carousel pattern of the WAI-ARIA Authoring Practices and WCAG 2.1 AA.
689
+
690
+ - The root is a region with the name "Carousel". Each slide has a name such as "2 of 8". A slide that is an `article` or a list item keeps its own role.
691
+ - The arrows and the dots are buttons with names. A screen reader reads each new slide (`aria-live`), but not during the autoplay.
692
+ - Tab moves the focus through the links and the fields in the slides. The carousel moves to show the focused element.
693
+ - While the focus is in the carousel, the arrow keys go to the previous and the next slide. To turn them off, set `keys: false`.
694
+ - Clones are `inert` and hidden from screen readers.
695
+ - The autoplay and the auto scroll have a play and pause button (WCAG 2.2.2). The keyboard focus pauses them. If the user prefers reduced motion, they do not start.
696
+ - A drag across the axis scrolls the page. A link opens on a click, but not after a drag.
697
+
698
+ To translate the labels, set `labels`. In the texts, `%d` is the slide number, and `%n` is the number of slides:
699
+
700
+ ```js
701
+ BetterCarousel.defaults = {
702
+ labels: {
703
+ carousel: 'Karussell',
704
+ slide: '%d von %n',
705
+ prev: 'Vorheriges Bild',
706
+ next: 'Nächstes Bild',
707
+ dot: 'Zu Bild %d',
708
+ play: 'Diashow starten',
709
+ pause: 'Diashow anhalten',
710
+ },
711
+ }
712
+ ```
713
+
714
+ ## Performance
715
+
716
+ The library is made for slow phones. A motion runs on the compositor, and a carousel at rest uses no CPU.
717
+
718
+ <!-- generated:sizes -->
719
+ | File | Minified | Gzip | Brotli |
720
+ | --- | --- | --- | --- |
721
+ | `better-carousel.min.js` | 31.6 KB | 12.6 KB | 11.5 KB |
722
+ | `better-carousel.css` | 4.7 KB | 1.3 KB | 1.1 KB |
723
+ | Total | 36.3 KB | 13.9 KB | 12.6 KB |
724
+ <!-- /generated -->
725
+
726
+ The [Comparison](#comparison) section gives the sizes and the runtime costs of other carousel libraries.
727
+
728
+ | Measure, on a phone with a CPU 4 times slower | Better Carousel |
729
+ | --- | --- |
730
+ | CPU load during 10 s of auto scroll | 0.5% |
731
+ | CPU load during 10 s of autoplay | 1.1% |
732
+ | Total Blocking Time added at page load | 0 ms |
733
+ | Layout shift | 0 |
734
+
735
+ - A motion is a Web Animations API animation of `translate`. No script runs on each frame.
736
+ - The auto scroll is one animation that does not stop. During the motion, the browser does no script, style, layout or paint work.
737
+ - One `ResizeObserver` serves all carousels. It reads the layout of all carousels first, and then it writes. For this reason, the browser calculates the layout only one time.
738
+ - Only two elements of the dots animate: the row of the dots and the marker of the selected dot. Both move with `translate`. A click on a dot causes no layout work.
739
+ - The listeners for the autoplay and the mouse wheel exist only while they can do something.
740
+ - The `progress` and `offset` options run a script on each frame of a motion. For this reason, they are off by default.
741
+
742
+ ## Comparison
743
+
744
+ This benchmark compares Better Carousel with Swiper, Embla Carousel and Glide in Chrome. All libraries make the same carousel: 10 slides, the loop, the drag, the arrows, the dots and a motion of 400 ms. Embla uses the arrows, the dots and the CSS of its own examples, and the plugins for the same features. [bench/README.md](bench/README.md) gives the method, the metrics, the profiles and the steps to run the benchmark on your computer.
745
+
746
+ On a phone with a CPU 4 times slower:
747
+
748
+ - With all features, Better Carousel is 13.3 KB gzip. Embla is 13.5 KB and Swiper 32.9 KB with the same features. Embla still has no names for screen readers and no arrow keys. Glide does not have all of these features.
749
+ - 6 slide changes take 180 ms of main-thread time. Swiper takes 221 ms, Glide 329 ms and Embla 1584 ms.
750
+ - The autoplay uses 0.9% of the CPU. Glide uses 2.4%, Swiper 24.4% and Embla 32.2%.
751
+ - 5 drags take 1053 ms, about the same as Swiper (1024 ms). Glide takes 1732 ms and Embla 3587 ms. A drag causes the fewest paints of all libraries, and no layout shift.
752
+ - A page with 10 carousels has 28 ms of Total Blocking Time. Swiper has 61 ms and Glide 42 ms. Embla has 18 ms.
753
+
754
+ Measured with Chrome 157.0.8103.51 (headless) on 12th Gen Intel(R) Core(TM) i9-12900HK, 20 threads, 64 GB of memory, 2026-11-17. Each value is the median of 3 rounds.
755
+
756
+ ### Bundle size
757
+
758
+ ![Typical setup, JS + CSS, gzip](bench/results/charts/size.svg)
759
+
760
+ | Library | Core | Typical | Typical, brotli | All features | Shipped files |
761
+ | --- | ---: | ---: | ---: | ---: | ---: |
762
+ | **Better Carousel 1.0.0** | 13.3 | **13.3** | 12.1 | 13.3 | 12.9 |
763
+ | Swiper 14.4.0 | 21.7 | **29.7** | 26.2 | 32.9 | 46.2 |
764
+ | Embla Carousel 8.6.0 | 7.6 | **9.7** | 8.7 | 13.5 | 7.0 |
765
+ | Glide 3.7.1 | 6.9 | **8.3** | 7.4 | not available | 8.7 |
766
+
767
+ KB after gzip, JS and CSS. Core: the smallest setup that the user can drag. Typical: the setup of the tests below, with the loop, the arrows, the dots, the autoplay and the accessibility module. All features: the typical setup, the mouse wheel, the auto scroll, the auto height, the free drag and the sync. Shipped files: the minified JS and CSS files of the package, as they are.
768
+
769
+ ### Mobile, CPU 4 times slower
770
+
771
+ ![Mobile: main-thread time, 6 slide changes](bench/results/charts/navigate.svg)
772
+
773
+ ![Mobile: main-thread time, 5 drags](bench/results/charts/drag.svg)
774
+
775
+ ![Mobile: CPU load of the autoplay](bench/results/charts/autoplay.svg)
776
+
777
+ ![Mobile: Total Blocking Time, page with 10 carousels](bench/results/charts/blocking.svg)
778
+
779
+ | Library | Load, ms | Blocking, ms | Layout shift | Idle CPU, % | Navigate, ms | Navigate paints | Autoplay CPU, % | Drag, ms | Drag paints | Busy: bad frames, % |
780
+ | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
781
+ | **Better Carousel** | 198 | 28 | 0.000 | 0.2 | 180 | 12 | 0.9 | 1053 | 8 | 3.2 |
782
+ | Swiper | 239 | 61 | 0.000 | 0.1 | 221 | 12 | 24.4 | 1024 | 10 | 4.3 |
783
+ | Embla Carousel | 190 | 18 | 0.000 | 0.2 | 1584 | 12 | 32.2 | 3587 | 10 | 26.2 |
784
+ | Glide | 221 | 42 | 0.000 | 0.1 | 329 | 22 | 2.4 | 1732 | 20 | 1.3 |
785
+ | No carousel | 117 | 0 | 0.000 | 0.2 | 14 | 0 | 0.1 | 354 | 0 | - |
786
+
787
+ ### Desktop
788
+
789
+ | Library | Load, ms | Blocking, ms | Layout shift | Idle CPU, % | Navigate, ms | Navigate paints | Autoplay CPU, % | Drag, ms | Drag paints | Busy: bad frames, % |
790
+ | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
791
+ | **Better Carousel** | 40 | 0 | 0.000 | 0.0 | 37 | 12 | 0.4 | 174 | 30 | 1.5 |
792
+ | Swiper | 51 | 0 | 0.000 | 0.0 | 29 | 12 | 3.3 | 146 | 16 | 1.2 |
793
+ | Embla Carousel | 42 | 0 | 0.000 | 0.0 | 266 | 12 | 5.6 | 518 | 60 | 15.7 |
794
+ | Glide | 47 | 0 | 0.000 | 0.0 | 49 | 26 | 0.6 | 303 | 22 | 0.7 |
795
+ | No carousel | 30 | 0 | 0.000 | 0.1 | 3 | 0 | 0.0 | 45 | 0 | - |
796
+
797
+ Load: the main-thread time and the Total Blocking Time of a page with 10 carousels. Navigate: 6 calls of `next()`. Drag: 5 drags. Busy: the share of frames that were dropped or late during navigate, while another script blocks the main thread. Less is better in all columns.
798
+
799
+ ### Features
800
+
801
+ | Feature | Better | Swiper | Embla | Glide |
802
+ | --- | ---: | ---: | ---: | ---: |
803
+ | Slide sizes and gaps from CSS | yes | partly (`slidesPerView: 'auto'`) | yes | no |
804
+ | Loop without clones | yes | yes | yes | no |
805
+ | Vertical | yes | yes | yes | no |
806
+ | Right-to-left | yes | yes | yes | yes |
807
+ | Breakpoints | yes | yes | yes | yes |
808
+ | Free drag with momentum | yes | module | yes | no |
809
+ | Arrows and dots | yes | modules | no | your markup |
810
+ | Autoplay | yes | module | plugin | yes |
811
+ | Auto scroll without stops | yes | partly (autoplay with delay 0) | plugin | no |
812
+ | Auto height | yes | yes | plugin | no |
813
+ | Sync of two carousels | yes | module | no | no |
814
+ | Mouse wheel | yes | module | plugin of a third party | no |
815
+ | Arrow keys | yes | module | no | yes |
816
+ | Names for screen readers | yes | module | no | no |
817
+ | Start only when near the screen | yes | no | no | no |
818
+ | Fade and other effects | no | modules (fade, cube, flip, coverflow, cards, creative) | plugin (fade) | no |
819
+ | TypeScript types | yes | yes | yes | separate package |
820
+
821
+ Run the benchmark: `npm run bench`. The [bench/README.md](bench/README.md) file gives the method and the options.
822
+
823
+ ## Development
824
+
825
+ ```sh
826
+ npm install
827
+ npm run dev # build again after each change
828
+ npm run build # build dist/ and demo/demo.css, then update the docs
829
+ npm run docs # update the generated parts of README.md and index.html
830
+ npm test # unit tests
831
+ npm run e2e # browser tests in Chrome
832
+ ```
833
+
834
+ The browser tests open `http://better.test/` in Chrome. To use a different address or a different Chrome, set `URL` and `CHROME`.
835
+
836
+ The docs page is [`index.html`](index.html). Its scripts and styles are in [`demo/`](demo). The reference tables and the file sizes in README.md and index.html, and the `Options` interface in [`src/types/better-carousel.d.ts`](src/types/better-carousel.d.ts), come from [`scripts/reference.js`](scripts/reference.js). Do not edit the parts in the `generated` HTML comments. Edit `scripts/reference.js`, and then run `npm run docs`.
837
+
838
+ ## License
839
+
840
+ [MIT](LICENSE)