embla-a11y 0.0.0-stage → 1.0.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/CHANGELOG.md +49 -0
- package/LICENSE +21 -0
- package/README.md +169 -2
- package/dist/AttributeStore.d.ts +10 -0
- package/dist/AttributeStore.d.ts.map +1 -0
- package/dist/AttributeStore.js +51 -0
- package/dist/AttributeStore.js.map +1 -0
- package/dist/compat/emblaV8.d.ts +8 -0
- package/dist/compat/emblaV8.d.ts.map +1 -0
- package/dist/compat/emblaV8.js +78 -0
- package/dist/compat/emblaV8.js.map +1 -0
- package/dist/emblaA11y.d.ts +32 -0
- package/dist/emblaA11y.d.ts.map +1 -0
- package/dist/emblaA11y.js +140 -0
- package/dist/emblaA11y.js.map +1 -0
- package/dist/features/Announcer.d.ts +43 -0
- package/dist/features/Announcer.d.ts.map +1 -0
- package/dist/features/Announcer.js +184 -0
- package/dist/features/Announcer.js.map +1 -0
- package/dist/features/DotButtons.d.ts +33 -0
- package/dist/features/DotButtons.d.ts.map +1 -0
- package/dist/features/DotButtons.js +162 -0
- package/dist/features/DotButtons.js.map +1 -0
- package/dist/features/Feature.d.ts +5 -0
- package/dist/features/Feature.d.ts.map +1 -0
- package/dist/features/Feature.js +2 -0
- package/dist/features/Feature.js.map +1 -0
- package/dist/features/FocusRescue.d.ts +36 -0
- package/dist/features/FocusRescue.d.ts.map +1 -0
- package/dist/features/FocusRescue.js +151 -0
- package/dist/features/FocusRescue.js.map +1 -0
- package/dist/features/FollowFocus.d.ts +26 -0
- package/dist/features/FollowFocus.d.ts.map +1 -0
- package/dist/features/FollowFocus.js +92 -0
- package/dist/features/FollowFocus.js.map +1 -0
- package/dist/features/HideOffscreen.d.ts +25 -0
- package/dist/features/HideOffscreen.d.ts.map +1 -0
- package/dist/features/HideOffscreen.js +99 -0
- package/dist/features/HideOffscreen.js.map +1 -0
- package/dist/features/PreviousNextButtons.d.ts +21 -0
- package/dist/features/PreviousNextButtons.d.ts.map +1 -0
- package/dist/features/PreviousNextButtons.js +34 -0
- package/dist/features/PreviousNextButtons.js.map +1 -0
- package/dist/features/Region.d.ts +18 -0
- package/dist/features/Region.d.ts.map +1 -0
- package/dist/features/Region.js +36 -0
- package/dist/features/Region.js.map +1 -0
- package/dist/features/RotationButtonText.d.ts +20 -0
- package/dist/features/RotationButtonText.d.ts.map +1 -0
- package/dist/features/RotationButtonText.js +53 -0
- package/dist/features/RotationButtonText.js.map +1 -0
- package/dist/features/RotationControl.d.ts +61 -0
- package/dist/features/RotationControl.d.ts.map +1 -0
- package/dist/features/RotationControl.js +181 -0
- package/dist/features/RotationControl.js.map +1 -0
- package/dist/features/SingleView.d.ts +8 -0
- package/dist/features/SingleView.d.ts.map +1 -0
- package/dist/features/SingleView.js +12 -0
- package/dist/features/SingleView.js.map +1 -0
- package/dist/features/SlideList.d.ts +8 -0
- package/dist/features/SlideList.d.ts.map +1 -0
- package/dist/features/SlideList.js +29 -0
- package/dist/features/SlideList.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/visibleSlides.d.ts +3 -0
- package/dist/visibleSlides.d.ts.map +1 -0
- package/dist/visibleSlides.js +10 -0
- package/dist/visibleSlides.js.map +1 -0
- package/package.json +89 -4
- package/src/AttributeStore.ts +48 -0
- package/src/compat/emblaV8.ts +95 -0
- package/src/emblaA11y.ts +191 -0
- package/src/features/Announcer.ts +213 -0
- package/src/features/DotButtons.ts +179 -0
- package/src/features/Feature.ts +5 -0
- package/src/features/FocusRescue.ts +162 -0
- package/src/features/FollowFocus.ts +96 -0
- package/src/features/HideOffscreen.ts +104 -0
- package/src/features/PreviousNextButtons.ts +42 -0
- package/src/features/Region.ts +48 -0
- package/src/features/RotationButtonText.ts +63 -0
- package/src/features/RotationControl.ts +211 -0
- package/src/features/SingleView.ts +15 -0
- package/src/features/SlideList.ts +37 -0
- package/src/index.ts +5 -0
- package/src/visibleSlides.ts +12 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are listed here. The project follows [Semantic Versioning](https://semver.org).
|
|
4
|
+
|
|
5
|
+
## 1.0.0 (2026-10-20)
|
|
6
|
+
|
|
7
|
+
The first release. Works with Embla Carousel 8.6 and 9, in Chrome and Edge 110, Firefox 115 and Safari 16 and newer.
|
|
8
|
+
|
|
9
|
+
### Structure
|
|
10
|
+
|
|
11
|
+
- The smallest element around the viewport and all its controls becomes a named region. A named `<div>` gets `role="region"`. The plugin never takes over `<body>` or a landmark such as `<main>`.
|
|
12
|
+
- Slides that are plain `<div>` elements become a list, so screen readers hear the count and the position of each slide.
|
|
13
|
+
- `data-single-view` on the carousel while everything fits in one view, so pages can hide controls that have nothing to do.
|
|
14
|
+
|
|
15
|
+
### Keyboard, focus and screen readers
|
|
16
|
+
|
|
17
|
+
- Only slides on screen are reachable. Slides that are fully off-screen become `inert`, and list items keep their position and the full count. `hideOffscreen: false` keeps every slide reachable.
|
|
18
|
+
- Focus from the keyboard, screen readers, voice control and scripts brings its slide into view. A mouse or touch press and focus the browser restores do not move the carousel.
|
|
19
|
+
- When focused content disappears, focus moves to something nearby instead of the top of the page.
|
|
20
|
+
- Previous and next buttons get `aria-disabled` at the ends, so focus stays on them.
|
|
21
|
+
- The current dot gets `aria-current`. Dots without a name get one from a template in the markup or from `dotLabel`. Visible text, hidden text and image `alt` text are kept.
|
|
22
|
+
- `dotKeys: true` makes the dots one Tab stop, with the arrow keys, Home and End between them.
|
|
23
|
+
|
|
24
|
+
### Announcements
|
|
25
|
+
|
|
26
|
+
- After a user moves the carousel with a button, a dot or a drag, the position is announced once, politely, from a live region in the page. Nothing is said on load, on resize, during Autoplay or when focus moves the carousel. Moves a framework makes up to a second after the click are announced too.
|
|
27
|
+
- Templates in the markup, in the page's language: `{first}`, `{last}`, `{total}`, `{page}`, `{pages}`, `{heading}`, and `{slides}` with `data-announcement-wrapped` for loops that wrap around.
|
|
28
|
+
- The `announcement` callback receives the same values for translation libraries.
|
|
29
|
+
|
|
30
|
+
### Autoplay and AutoScroll
|
|
31
|
+
|
|
32
|
+
- Any focus or press inside the carousel stops the rotation for good. While a mouse is over the carousel, it pauses.
|
|
33
|
+
- People who prefer reduced motion get no rotation until they start it with the rotation button.
|
|
34
|
+
- The rotation button's text always says what pressing it will do, from the markup or `rotationLabel`. It gets `aria-disabled` when there is nothing to rotate.
|
|
35
|
+
- A rotation the user stopped stays stopped through resizes and when a framework swaps in a new plugin instance.
|
|
36
|
+
|
|
37
|
+
### For developers
|
|
38
|
+
|
|
39
|
+
- No English of its own: every text comes from your markup or your callbacks.
|
|
40
|
+
- Console warnings, once per carousel, for missing names, texts, buttons and markup problems. `warnings: false` switches them off.
|
|
41
|
+
- Safe with server rendering and the React, Vue and Solid wrappers.
|
|
42
|
+
- On destroy, every attribute and text goes back to what you wrote.
|
|
43
|
+
- `active`, `breakpoints` and `globalOptions` as in Embla.
|
|
44
|
+
- Exported types: `EmblaA11yType`, `EmblaA11yOptionsType`, `AnnouncementType`, `DotLabelType`, `RotationLabelType`.
|
|
45
|
+
|
|
46
|
+
### Known limits
|
|
47
|
+
|
|
48
|
+
- Works in the normal page DOM only, not inside a shadow root.
|
|
49
|
+
- NVDA counts only the slides on screen while off-screen slides are hidden, because it ignores `aria-setsize`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wolfgang Klinger
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,170 @@
|
|
|
1
|
-
#
|
|
1
|
+
# embla-a11y
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://github.com/wazum/embla-a11y/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/wazum/embla-a11y/ci.yml?branch=main&style=for-the-badge&logo=githubactions&logoColor=white&label=ci&labelColor=24273a" alt="CI status"></a>
|
|
5
|
+
<a href="https://wazum.github.io/embla-a11y/"><img src="https://img.shields.io/badge/demo-live-b5ead7?style=for-the-badge&logo=githubpages&logoColor=white&labelColor=24273a" alt="Live demo"></a>
|
|
6
|
+
<a href="https://www.embla-carousel.com"><img src="https://img.shields.io/badge/Embla-8.6%20%7C%209-c3b1e1?style=for-the-badge&labelColor=24273a" alt="Embla Carousel 8.6 and 9"></a>
|
|
7
|
+
<a href="https://www.w3.org/TR/WCAG22/"><img src="https://img.shields.io/badge/WCAG-2.2%20AA-ffb997?style=for-the-badge&labelColor=24273a" alt="Aims at WCAG 2.2 AA"></a>
|
|
8
|
+
<a href="CONTRIBUTING.md#screen-reader-tests"><img src="https://img.shields.io/badge/tested%20with-VoiceOver%20%7C%20NVDA%20%7C%20Orca-a7c7e7?style=for-the-badge&labelColor=24273a" alt="Tested with VoiceOver, NVDA and Orca"></a>
|
|
9
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/licence-MIT-ffc6d9?style=for-the-badge&labelColor=24273a" alt="MIT licence"></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
An accessibility plugin for [Embla Carousel](https://www.embla-carousel.com) 8.6 and 9. Try it on the [demo site](https://wazum.github.io/embla-a11y/) with your keyboard and screen reader.
|
|
13
|
+
|
|
14
|
+
The plugin never hides content that people can see. It aims at WCAG 2.2 AA, plus the AAA criteria a carousel can meet. Every change runs automated tests in Chromium, Firefox and WebKit against both Embla versions, and screen reader tests with VoiceOver, NVDA and Orca. It needs Chrome or Edge 110, Firefox 115 or Safari 16 and newer.
|
|
15
|
+
|
|
16
|
+
Use it instead of the official `embla-carousel-accessibility` plugin or `@bluecadet/embla-carousel-a11y`, not together with them. See [embla-a11y or the official plugin?](#embla-a11y-or-the-official-plugin)
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm install embla-a11y
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Good markup does most of the work. The plugin fills in what markup cannot do on its own: state that changes while the carousel moves, and focus. All texts come from your markup, in your page's language. The plugin never writes English of its own.
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<section class="embla" aria-labelledby="products-heading">
|
|
28
|
+
<h2 id="products-heading">Featured products</h2>
|
|
29
|
+
|
|
30
|
+
<div class="embla__viewport">
|
|
31
|
+
<ul class="embla__container" role="list">
|
|
32
|
+
<li class="embla__slide">
|
|
33
|
+
<h3>Product 1</h3>
|
|
34
|
+
<a href="/products/1">Details for product 1</a>
|
|
35
|
+
</li>
|
|
36
|
+
<li class="embla__slide">
|
|
37
|
+
<h3>Product 2</h3>
|
|
38
|
+
<a href="/products/2">Details for product 2</a>
|
|
39
|
+
</li>
|
|
40
|
+
</ul>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<button type="button" class="embla__prev">Previous</button>
|
|
44
|
+
<button type="button" class="embla__next">Next</button>
|
|
45
|
+
|
|
46
|
+
<div class="embla__dots">
|
|
47
|
+
<button type="button" class="embla__dot"><span class="visually-hidden">Slide 1</span></button>
|
|
48
|
+
<button type="button" class="embla__dot"><span class="visually-hidden">Slide 2</span></button>
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
<p
|
|
52
|
+
class="embla__announcer visually-hidden"
|
|
53
|
+
aria-live="polite"
|
|
54
|
+
aria-atomic="true"
|
|
55
|
+
data-announcement="Slide {first} of {total}"
|
|
56
|
+
data-announcement-group="Slides {first} to {last} of {total}"
|
|
57
|
+
></p>
|
|
58
|
+
</section>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
import EmblaCarousel from 'embla-carousel'
|
|
63
|
+
import emblaA11y from 'embla-a11y'
|
|
64
|
+
|
|
65
|
+
const viewport = document.querySelector('.embla__viewport')
|
|
66
|
+
const previous = document.querySelector('.embla__prev')
|
|
67
|
+
const next = document.querySelector('.embla__next')
|
|
68
|
+
const dots = document.querySelector('.embla__dots')
|
|
69
|
+
const announcer = document.querySelector('.embla__announcer')
|
|
70
|
+
|
|
71
|
+
const emblaApi = EmblaCarousel(viewport, {}, [
|
|
72
|
+
emblaA11y({ previousButton: previous, nextButton: next, dots, announcer })
|
|
73
|
+
])
|
|
74
|
+
|
|
75
|
+
previous.addEventListener('click', () => emblaApi.goToPrev())
|
|
76
|
+
next.addEventListener('click', () => emblaApi.goToNext())
|
|
77
|
+
dots.querySelectorAll('button').forEach((dot, index) => {
|
|
78
|
+
dot.addEventListener('click', () => emblaApi.goTo(index))
|
|
79
|
+
})
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The plugin treats the smallest element around the viewport and all the controls you pass as the carousel. It becomes the region, and focus or a press inside it stops Autoplay. Keep the viewport and all its controls in one wrapper, like the `<section>` above. The plugin never takes over `<body>` or a landmark such as `<main>`: then it uses the viewport or its parent, and warns in the console.
|
|
83
|
+
|
|
84
|
+
> [!IMPORTANT]
|
|
85
|
+
> Keep the browser console open while you build the carousel. When your markup or options keep the plugin from making the carousel accessible, for example a missing name, a dot without text or Autoplay without a stop button, it warns there once per carousel and says how to fix it. It never fails silently, and it never fills the gap with English text of its own.
|
|
86
|
+
>
|
|
87
|
+
> Switch the warnings off only after you have fixed what they say, for example for tests that fail on console output: `warnings: false` for one carousel, or `emblaA11y.globalOptions = { warnings: false }` for all of them.
|
|
88
|
+
|
|
89
|
+
With Embla 8.6 the methods are `scrollPrev`, `scrollNext` and `scrollTo`. You keep your own click handlers; the plugin never moves the carousel on a click. With other Embla plugins, list `emblaA11y` last ([why](guide/features.md#focus-brings-its-slide-into-view)).
|
|
90
|
+
|
|
91
|
+
The JavaScript and the complete HTML examples in this README and the guides run in the test suite, from the files in [`examples/`](examples).
|
|
92
|
+
|
|
93
|
+
The examples use a common `visually-hidden` class. It hides text on screen and keeps it for screen readers and browser translation:
|
|
94
|
+
|
|
95
|
+
```css
|
|
96
|
+
.visually-hidden {
|
|
97
|
+
position: absolute;
|
|
98
|
+
width: 1px;
|
|
99
|
+
height: 1px;
|
|
100
|
+
margin: -1px;
|
|
101
|
+
padding: 0;
|
|
102
|
+
border: 0;
|
|
103
|
+
overflow: hidden;
|
|
104
|
+
clip-path: inset(50%);
|
|
105
|
+
white-space: nowrap;
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## What it does
|
|
110
|
+
|
|
111
|
+
- [Named region](guide/features.md#named-region): screen reader users can find the carousel by its name.
|
|
112
|
+
- [Only slides on screen are reachable](guide/features.md#only-slides-on-screen-are-reachable): Tab and screen readers move through the slides people see, and never jump to a slide nobody asked for. A slide that is partly on screen stays reachable.
|
|
113
|
+
- [Focus brings its slide into view](guide/features.md#focus-brings-its-slide-into-view): Tab, screen readers and voice control never focus something you can't see.
|
|
114
|
+
- [Previous and next buttons](guide/features.md#previous-and-next-buttons): unavailable at the ends without losing focus, and easy to hide when everything fits in one view.
|
|
115
|
+
- [Dot buttons](guide/features.md#dot-buttons): the current dot is marked, and every dot has a name.
|
|
116
|
+
- [Position announcements](guide/features.md#position-announcements): after a move, screen readers hear "Slides 4 to 6 of 10".
|
|
117
|
+
- [Focus never gets lost](guide/features.md#focus-never-gets-lost): when focused content disappears, focus moves to something nearby.
|
|
118
|
+
- [Autoplay, AutoScroll and the rotation button](guide/features.md#autoplay-autoscroll-and-the-rotation-button): pauses while the mouse is over it, stops for good on interaction, respects reduced motion, and keeps the button text right.
|
|
119
|
+
- [Server rendering and frameworks](guide/features.md#server-rendering-and-frameworks): safe with SSR and the React, Vue and Solid wrappers.
|
|
120
|
+
- [Clean destroy and switching off](guide/features.md#clean-destroy-and-switching-off): everything the plugin added is taken back.
|
|
121
|
+
|
|
122
|
+
## embla-a11y or the official plugin?
|
|
123
|
+
|
|
124
|
+
Use one of them, not both: they manage the same attributes. The official [Accessibility plugin](https://www.embla-carousel.com/docs/plugins/accessibility) is maintained by the Embla team and follows the carousel pattern of the ARIA Authoring Practices, with slides labelled "Slide 3 of 10". Choose embla-a11y if you need:
|
|
125
|
+
|
|
126
|
+
- **Every slide people can see stays readable and reachable.** The official plugin hides every slide outside the selected snap from screen readers and the keyboard, also slides that are fully on screen. With three slides in view and the default `slidesToScroll: 1`, it hides one or two of them. The Embla team keeps this on purpose ([#1389](https://github.com/davidjerleke/embla-carousel/issues/1389)).
|
|
127
|
+
- **All texts come from your page, in its language.** The official plugin writes English names over your own: a button that shows "Zurück" is announced as "Go to previous Slide", which voice control users cannot match, and the carousel is called "Carousel" instead of by your heading.
|
|
128
|
+
- **Autoplay and AutoScroll that people can stop.** A stop button, a pause while the mouse is over the carousel, a stop on any interaction, and reduced motion. The official plugin leaves this to you.
|
|
129
|
+
- **Focus that is never lost or out of sight.** Focus from screen readers, voice control and scripts brings its slide into view, and moves on when the focused element disappears.
|
|
130
|
+
- **Your markup back as it was.** On destroy, every attribute goes back to what you wrote. The official plugin removes names you wrote yourself.
|
|
131
|
+
- **Embla 8.6 as well as 9.**
|
|
132
|
+
|
|
133
|
+
> [!NOTE]
|
|
134
|
+
> Checked in Chromium against `embla-carousel-accessibility` 9.0.0-rc04.
|
|
135
|
+
|
|
136
|
+
To switch, remove `embla-carousel-accessibility` and its `setup…()` calls, move the texts into your markup as in the [quick start](#quick-start), and pass your elements to `emblaA11y()`.
|
|
137
|
+
|
|
138
|
+
## Options
|
|
139
|
+
|
|
140
|
+
All options are optional. Elements you don't pass turn their feature off.
|
|
141
|
+
|
|
142
|
+
| Option | Type | Default | Purpose |
|
|
143
|
+
| ---------------- | --------------------------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
144
|
+
| `previousButton` | `HTMLElement` | `null` | Previous button, marked unavailable at the start |
|
|
145
|
+
| `nextButton` | `HTMLElement` | `null` | Next button, marked unavailable at the end |
|
|
146
|
+
| `dots` | `HTMLElement` | `null` | Element that holds the dot buttons |
|
|
147
|
+
| `announcer` | `HTMLElement` | `null` | Live region for position announcements |
|
|
148
|
+
| `rotationButton` | `HTMLElement` | `null` | Button that starts and stops Autoplay or AutoScroll; needed with either |
|
|
149
|
+
| `hideOffscreen` | `boolean` | `true` | Makes slides that are fully off-screen `inert`; [`false` keeps every slide reachable](guide/features.md#keeping-every-slide-reachable) |
|
|
150
|
+
| `labelledBy` | `string` | `null` | Id of a visible heading, if the markup has no name |
|
|
151
|
+
| `label` | `string` | `null` | Text name, if there is no visible heading |
|
|
152
|
+
| `dotLabel` | `(first, last, page, pages) => string` | `null` | Dot names from your translation library, instead of markup |
|
|
153
|
+
| `dotKeys` | `boolean` | `false` | [Only the current dot is a Tab stop; arrow keys move between dots](guide/features.md#fewer-tab-stops-for-many-dots) |
|
|
154
|
+
| `announcement` | `(first, last, total, page, pages, slides, headings) => string` | `null` | Announcement text from your translation library |
|
|
155
|
+
| `rotationLabel` | `(playing) => string` | `null` | Rotation button text from your translation library |
|
|
156
|
+
| `active` | `boolean` | `true` | Switches the plugin off, also per media query |
|
|
157
|
+
| `breakpoints` | `Record<string, options>` | `{}` | Options per media query, as in Embla |
|
|
158
|
+
| `warnings` | `boolean` | `true` | Console warnings about missing names, texts and buttons |
|
|
159
|
+
|
|
160
|
+
## Best practices
|
|
161
|
+
|
|
162
|
+
The plugin can't fix everything. The [best practices](guide/best-practices.md) cover what is up to your markup and design: a visible heading, a skip link, button size, zoom, autoplay and more.
|
|
163
|
+
|
|
164
|
+
## Contributing
|
|
165
|
+
|
|
166
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class AttributeStore {
|
|
2
|
+
private readonly originals;
|
|
3
|
+
set(element: Element, name: string, value: string): void;
|
|
4
|
+
remove(element: Element, name: string): void;
|
|
5
|
+
reset(element: Element, name: string): void;
|
|
6
|
+
release(element: Element): void;
|
|
7
|
+
restore(): void;
|
|
8
|
+
elements(): Element[];
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=AttributeStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttributeStore.d.ts","sourceRoot":"","sources":["../src/AttributeStore.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiD;IAEpE,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAK9D;IAEM,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAIlD;IAEM,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAOjD;IAEM,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAKrC;IAEM,OAAO,IAAI,IAAI,CAGrB;IAEM,QAAQ,IAAI,OAAO,EAAE,CAE3B;CACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export class AttributeStore {
|
|
2
|
+
originals = new Map();
|
|
3
|
+
set(element, name, value) {
|
|
4
|
+
const attributes = this.originals.get(element) ?? new Map();
|
|
5
|
+
if (!attributes.has(name))
|
|
6
|
+
attributes.set(name, element.getAttribute(name));
|
|
7
|
+
this.originals.set(element, attributes);
|
|
8
|
+
element.setAttribute(name, value);
|
|
9
|
+
}
|
|
10
|
+
remove(element, name) {
|
|
11
|
+
if (!element.hasAttribute(name))
|
|
12
|
+
return;
|
|
13
|
+
this.set(element, name, '');
|
|
14
|
+
element.removeAttribute(name);
|
|
15
|
+
}
|
|
16
|
+
reset(element, name) {
|
|
17
|
+
const attributes = this.originals.get(element);
|
|
18
|
+
if (attributes === undefined || !attributes.has(name))
|
|
19
|
+
return;
|
|
20
|
+
const value = attributes.get(name) ?? null;
|
|
21
|
+
attributes.delete(name);
|
|
22
|
+
if (value === null)
|
|
23
|
+
element.removeAttribute(name);
|
|
24
|
+
else
|
|
25
|
+
element.setAttribute(name, value);
|
|
26
|
+
}
|
|
27
|
+
release(element) {
|
|
28
|
+
const attributes = this.originals.get(element);
|
|
29
|
+
if (attributes === undefined)
|
|
30
|
+
return;
|
|
31
|
+
restoreAttributes(element, attributes);
|
|
32
|
+
this.originals.delete(element);
|
|
33
|
+
}
|
|
34
|
+
restore() {
|
|
35
|
+
for (const [element, attributes] of this.originals)
|
|
36
|
+
restoreAttributes(element, attributes);
|
|
37
|
+
this.originals.clear();
|
|
38
|
+
}
|
|
39
|
+
elements() {
|
|
40
|
+
return Array.from(this.originals.keys());
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function restoreAttributes(element, attributes) {
|
|
44
|
+
for (const [name, value] of attributes) {
|
|
45
|
+
if (value === null)
|
|
46
|
+
element.removeAttribute(name);
|
|
47
|
+
else
|
|
48
|
+
element.setAttribute(name, value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=AttributeStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttributeStore.js","sourceRoot":"","sources":["../src/AttributeStore.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAc;IACR,SAAS,GAAG,IAAI,GAAG,EAAuC,CAAA;IAEpE,GAAG,CAAC,OAAgB,EAAE,IAAY,EAAE,KAAa;QACtD,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,GAAG,EAAyB,CAAA;QAClF,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAA;QAC3E,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;QACvC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IACnC,CAAC;IAEM,MAAM,CAAC,OAAgB,EAAE,IAAY;QAC1C,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC;YAAE,OAAM;QACvC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;QAC3B,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC;IAEM,KAAK,CAAC,OAAgB,EAAE,IAAY;QACzC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAC9C,IAAI,UAAU,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC;Y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|
+
/**
|
|
3
|
+
* Gives an Embla 8.6 instance the Embla 9 methods the plugin uses.
|
|
4
|
+
* The slidefocus event can cancel the jump to the focused slide, as in Embla 9.
|
|
5
|
+
* Everything else passes through unchanged.
|
|
6
|
+
*/
|
|
7
|
+
export declare function asEmblaV9(emblaApi: EmblaCarouselType): EmblaCarouselType;
|
|
8
|
+
//# sourceMappingURL=emblaV8.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emblaV8.d.ts","sourceRoot":"","sources":["../../src/compat/emblaV8.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAwBvD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,iBAAiB,GAAG,iBAAiB,CAqDxE"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const eventNamesV8 = {
|
|
2
|
+
reinit: 'reInit',
|
|
3
|
+
'autoscroll:play': 'autoScroll:play',
|
|
4
|
+
'autoscroll:stop': 'autoScroll:stop'
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Gives an Embla 8.6 instance the Embla 9 methods the plugin uses.
|
|
8
|
+
* The slidefocus event can cancel the jump to the focused slide, as in Embla 9.
|
|
9
|
+
* Everything else passes through unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export function asEmblaV9(emblaApi) {
|
|
12
|
+
if (!isEmblaV8(emblaApi))
|
|
13
|
+
return emblaApi;
|
|
14
|
+
const emblaV8 = emblaApi;
|
|
15
|
+
const slideFocusListeners = new Set();
|
|
16
|
+
let jumpBack = null;
|
|
17
|
+
const onSlideFocusStart = () => {
|
|
18
|
+
const snap = emblaV8.selectedScrollSnap();
|
|
19
|
+
const cancelled = [...slideFocusListeners].some((listener) => listener() === false);
|
|
20
|
+
jumpBack = cancelled ? () => emblaV8.scrollTo(snap, true) : null;
|
|
21
|
+
};
|
|
22
|
+
const onSlideFocus = () => {
|
|
23
|
+
jumpBack?.();
|
|
24
|
+
jumpBack = null;
|
|
25
|
+
};
|
|
26
|
+
const emblaV9 = Object.assign(Object.create(emblaApi), {
|
|
27
|
+
on: (event, listener) => {
|
|
28
|
+
if (event !== 'slidefocus')
|
|
29
|
+
return emblaV8.on(eventNamesV8[event] ?? event, listener);
|
|
30
|
+
if (slideFocusListeners.size === 0) {
|
|
31
|
+
emblaV8.on('slideFocusStart', onSlideFocusStart);
|
|
32
|
+
emblaV8.on('slideFocus', onSlideFocus);
|
|
33
|
+
}
|
|
34
|
+
slideFocusListeners.add(listener);
|
|
35
|
+
return emblaV9;
|
|
36
|
+
},
|
|
37
|
+
off: (event, listener) => {
|
|
38
|
+
if (event !== 'slidefocus')
|
|
39
|
+
return emblaV8.off(eventNamesV8[event] ?? event, listener);
|
|
40
|
+
slideFocusListeners.delete(listener);
|
|
41
|
+
if (slideFocusListeners.size === 0) {
|
|
42
|
+
emblaV8.off('slideFocusStart', onSlideFocusStart);
|
|
43
|
+
emblaV8.off('slideFocus', onSlideFocus);
|
|
44
|
+
}
|
|
45
|
+
return emblaV9;
|
|
46
|
+
},
|
|
47
|
+
canGoToPrev: () => emblaV8.canScrollPrev(),
|
|
48
|
+
canGoToNext: () => emblaV8.canScrollNext(),
|
|
49
|
+
goToPrev: (instant) => emblaV8.scrollPrev(instant),
|
|
50
|
+
goToNext: (instant) => emblaV8.scrollNext(instant),
|
|
51
|
+
goTo: (index, instant) => emblaV8.scrollTo(index, instant),
|
|
52
|
+
selectedSnap: () => emblaV8.selectedScrollSnap(),
|
|
53
|
+
snapList: () => emblaV8.scrollSnapList(),
|
|
54
|
+
plugins: () => emblaV8.plugins() ?? {},
|
|
55
|
+
internalEngine: () => {
|
|
56
|
+
const engine = emblaV8.internalEngine();
|
|
57
|
+
return Object.assign(Object.create(engine), {
|
|
58
|
+
scrollSnapList: {
|
|
59
|
+
slidesBySnap: engine.slideRegistry,
|
|
60
|
+
snapBySlide: snapBySlide(engine.slideRegistry)
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return emblaV9;
|
|
66
|
+
}
|
|
67
|
+
function isEmblaV8(emblaApi) {
|
|
68
|
+
return !('goTo' in emblaApi) && 'scrollTo' in emblaApi;
|
|
69
|
+
}
|
|
70
|
+
function snapBySlide(slideRegistry) {
|
|
71
|
+
const snaps = {};
|
|
72
|
+
slideRegistry.forEach((slides, snap) => {
|
|
73
|
+
for (const slide of slides)
|
|
74
|
+
snaps[slide] = snap;
|
|
75
|
+
});
|
|
76
|
+
return snaps;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=emblaV8.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emblaV8.js","sourceRoot":"","sources":["../../src/compat/emblaV8.ts"],"names":[],"mappings":"AAkBA,MAAM,YAAY,GAA2B;IAC3C,MAAM,EAAE,QAAQ;IAChB,iBAAiB,EAAE,iBAAiB;IACpC,iBAAiB,EAAE,iBAAiB;CACrC,CAAA;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,QAA2B;IACnD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAA;IACzC,MAAM,OAAO,GAAgB,QAAQ,CAAA;IACrC,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAA0B,CAAA;IAC7D,IAAI,QAAQ,GAAwB,IAAI,CAAA;IACxC,MAAM,iBAAiB,GAAG,GAAS,EAAE;QACnC,MAAM,IAAI,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAA;QACzC,MAAM,SAAS,GAAG,CAAC,GAAG,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,CAAA;QACnF,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC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,CAAC,KAAK,CAAC,GAAG,IAAI,CAAA;IACjD,CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CreateOptionsType, CreatePluginType } from 'embla-carousel';
|
|
2
|
+
import { type AnnouncementType } from './features/Announcer.js';
|
|
3
|
+
import { type DotLabelType } from './features/DotButtons.js';
|
|
4
|
+
import type { RotationLabelType } from './features/RotationButtonText.js';
|
|
5
|
+
declare module 'embla-carousel' {
|
|
6
|
+
interface EmblaPluginsType {
|
|
7
|
+
emblaA11y: EmblaA11yType;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
type OptionsType = CreateOptionsType<{
|
|
11
|
+
label: string | null;
|
|
12
|
+
labelledBy: string | null;
|
|
13
|
+
hideOffscreen: boolean;
|
|
14
|
+
previousButton: HTMLElement | null;
|
|
15
|
+
nextButton: HTMLElement | null;
|
|
16
|
+
dots: HTMLElement | null;
|
|
17
|
+
dotLabel: DotLabelType | null;
|
|
18
|
+
dotKeys: boolean;
|
|
19
|
+
rotationButton: HTMLElement | null;
|
|
20
|
+
rotationLabel: RotationLabelType | null;
|
|
21
|
+
announcer: HTMLElement | null;
|
|
22
|
+
announcement: AnnouncementType | null;
|
|
23
|
+
warnings: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
export type EmblaA11yType = CreatePluginType<{}, OptionsType>;
|
|
26
|
+
export type EmblaA11yOptionsType = EmblaA11yType['options'];
|
|
27
|
+
declare function emblaA11y(userOptions?: EmblaA11yOptionsType): EmblaA11yType;
|
|
28
|
+
declare namespace emblaA11y {
|
|
29
|
+
var globalOptions: Partial<CreateOptionsType<OptionsType>> | undefined;
|
|
30
|
+
}
|
|
31
|
+
export default emblaA11y;
|
|
32
|
+
//# sourceMappingURL=emblaA11y.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emblaA11y.d.ts","sourceRoot":"","sources":["../src/emblaA11y.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V9 } from './compat/emblaV8.js';
|
|
2
|
+
import { Announcer } from './features/Announcer.js';
|
|
3
|
+
import { DotButtons } from './features/DotButtons.js';
|
|
4
|
+
import { FocusRescue } from './features/FocusRescue.js';
|
|
5
|
+
import { FollowFocus } from './features/FollowFocus.js';
|
|
6
|
+
import { HideOffscreen } from './features/HideOffscreen.js';
|
|
7
|
+
import { PreviousNextButtons } from './features/PreviousNextButtons.js';
|
|
8
|
+
import { Region } from './features/Region.js';
|
|
9
|
+
import { RotationControl } from './features/RotationControl.js';
|
|
10
|
+
import { SingleView } from './features/SingleView.js';
|
|
11
|
+
import { SlideList } from './features/SlideList.js';
|
|
12
|
+
const defaultOptions = {
|
|
13
|
+
active: true,
|
|
14
|
+
breakpoints: {},
|
|
15
|
+
label: null,
|
|
16
|
+
labelledBy: null,
|
|
17
|
+
hideOffscreen: true,
|
|
18
|
+
previousButton: null,
|
|
19
|
+
nextButton: null,
|
|
20
|
+
dots: null,
|
|
21
|
+
dotLabel: null,
|
|
22
|
+
dotKeys: false,
|
|
23
|
+
rotationButton: null,
|
|
24
|
+
rotationLabel: null,
|
|
25
|
+
announcer: null,
|
|
26
|
+
announcement: null,
|
|
27
|
+
warnings: true
|
|
28
|
+
};
|
|
29
|
+
// Framework wrappers swap in a new plugin instance when an option changes, so state that must
|
|
30
|
+
// outlive it, like a rotation the user stopped, belongs to the carousel, not the instance.
|
|
31
|
+
const carouselStates = new WeakMap();
|
|
32
|
+
function emblaA11y(userOptions = {}) {
|
|
33
|
+
const focusMemory = { focused: null };
|
|
34
|
+
let features = [];
|
|
35
|
+
function init(anyEmblaApi, optionsHandler) {
|
|
36
|
+
const emblaApi = asEmblaV9(anyEmblaApi);
|
|
37
|
+
if (emblaApi.internalEngine().isSsr)
|
|
38
|
+
return;
|
|
39
|
+
const { mergeOptions, optionsAtMedia } = optionsHandler;
|
|
40
|
+
const options = optionsAtMedia(mergeOptions(mergeOptions(defaultOptions, emblaA11y.globalOptions), userOptions));
|
|
41
|
+
if (!options.active)
|
|
42
|
+
return;
|
|
43
|
+
const viewport = emblaApi.rootNode();
|
|
44
|
+
const state = stateOf(viewport);
|
|
45
|
+
const warn = (message) => {
|
|
46
|
+
if (!options.warnings || state.warnings.has(message))
|
|
47
|
+
return;
|
|
48
|
+
state.warnings.add(message);
|
|
49
|
+
console.warn(`embla-a11y: ${message}`);
|
|
50
|
+
};
|
|
51
|
+
const controls = [
|
|
52
|
+
options.previousButton,
|
|
53
|
+
options.nextButton,
|
|
54
|
+
options.dots,
|
|
55
|
+
options.announcer,
|
|
56
|
+
options.rotationButton
|
|
57
|
+
].filter((control) => control !== null);
|
|
58
|
+
const area = carouselArea(viewport, controls, warn);
|
|
59
|
+
features = [
|
|
60
|
+
new Region(area, options, warn),
|
|
61
|
+
new SlideList(emblaApi, warn),
|
|
62
|
+
new SingleView(emblaApi, area),
|
|
63
|
+
new RotationControl(emblaApi, area, state.rotation, options, warn),
|
|
64
|
+
new FollowFocus(emblaApi),
|
|
65
|
+
new PreviousNextButtons(emblaApi, options),
|
|
66
|
+
new FocusRescue(emblaApi, area, options, focusMemory)
|
|
67
|
+
];
|
|
68
|
+
if (options.hideOffscreen)
|
|
69
|
+
features.push(new HideOffscreen(emblaApi));
|
|
70
|
+
if (options.dots !== null) {
|
|
71
|
+
features.push(new DotButtons(emblaApi, options.dots, options, warn));
|
|
72
|
+
}
|
|
73
|
+
if (options.announcer !== null) {
|
|
74
|
+
features.push(new Announcer(emblaApi, options.announcer, options, warn));
|
|
75
|
+
}
|
|
76
|
+
const navigation = [options.previousButton, options.nextButton, options.dots];
|
|
77
|
+
if (emblaApi.snapList().length > 1 && navigation.every((control) => control === null)) {
|
|
78
|
+
warn('the carousel can only be moved by dragging. Keyboard, screen reader and voice control users need buttons, and off-screen slides cannot be reached without them. Pass previousButton and nextButton, or dots.');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function destroy() {
|
|
82
|
+
for (const feature of features)
|
|
83
|
+
feature.destroy();
|
|
84
|
+
features = [];
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
name: 'emblaA11y',
|
|
88
|
+
options: userOptions,
|
|
89
|
+
init,
|
|
90
|
+
destroy
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
emblaA11y.globalOptions = undefined;
|
|
94
|
+
function stateOf(viewport) {
|
|
95
|
+
const existing = carouselStates.get(viewport);
|
|
96
|
+
if (existing !== undefined)
|
|
97
|
+
return existing;
|
|
98
|
+
const created = {
|
|
99
|
+
rotation: { stoppedByUser: false, startedByUser: false, playing: null, pausedByHover: false },
|
|
100
|
+
warnings: new Set()
|
|
101
|
+
};
|
|
102
|
+
carouselStates.set(viewport, created);
|
|
103
|
+
return created;
|
|
104
|
+
}
|
|
105
|
+
function carouselArea(viewport, controls, warn) {
|
|
106
|
+
const parent = viewport.parentElement;
|
|
107
|
+
if (parent === null)
|
|
108
|
+
return viewport;
|
|
109
|
+
if (isOffLimits(parent)) {
|
|
110
|
+
warn('there is no element around the viewport, so the plugin uses the viewport as the carousel area. Wrap the viewport and its buttons in a <section> named by a heading.');
|
|
111
|
+
return viewport;
|
|
112
|
+
}
|
|
113
|
+
let area = parent;
|
|
114
|
+
while (!controls.every((control) => area.contains(control))) {
|
|
115
|
+
const next = area.parentElement;
|
|
116
|
+
if (next === null || isOffLimits(next)) {
|
|
117
|
+
warn('a control is outside the carousel, so it is not part of the region, and pressing it does not stop Autoplay. Put the viewport and all its controls in one element, ideally a <section> named by a heading.');
|
|
118
|
+
return parent;
|
|
119
|
+
}
|
|
120
|
+
area = next;
|
|
121
|
+
}
|
|
122
|
+
return area;
|
|
123
|
+
}
|
|
124
|
+
const landmarkElements = new Set(['main', 'nav', 'header', 'footer', 'aside', 'form']);
|
|
125
|
+
const landmarkRoles = new Set([
|
|
126
|
+
'banner',
|
|
127
|
+
'complementary',
|
|
128
|
+
'contentinfo',
|
|
129
|
+
'form',
|
|
130
|
+
'main',
|
|
131
|
+
'navigation',
|
|
132
|
+
'search'
|
|
133
|
+
]);
|
|
134
|
+
function isOffLimits(element) {
|
|
135
|
+
return (element === element.ownerDocument.body ||
|
|
136
|
+
landmarkElements.has(element.localName) ||
|
|
137
|
+
landmarkRoles.has(element.getAttribute('role') ?? ''));
|
|
138
|
+
}
|
|
139
|
+
export default emblaA11y;
|
|
140
|
+
//# sourceMappingURL=emblaA11y.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emblaA11y.js","sourceRoot":"","sources":["../src/emblaA11y.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAyB,MAAM,yBAAyB,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAqB,MAAM,0BAA0B,CAAA;AAExE,OAAO,EAAE,WAAW,EAAwB,MAAM,2BAA2B,CAAA;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE7C,OAAO,EAAE,eAAe,EAA2B,MAAM,+BAA+B,CAAA;AACxF,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AA4BnD,MAAM,cAAc,GAAgB;IAClC,MAAM,EAAE,IAAI;IACZ,WAAW,EAAE,EAAE;IACf,KAAK,EAAE,IAAI;IACX,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,IAAI;IACnB,cAAc,EAAE,IAAI;IACpB,UAAU,EAAE,IAAI;IAChB,IAAI,EAAE,IAAI;IACV,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,KAAK;IACd,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,IAAI;IACnB,SAAS,EAAE,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