embla-a11y 1.1.1 → 1.1.3
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 +14 -0
- package/dist/compat/emblaV8.d.ts.map +1 -1
- package/dist/compat/emblaV8.js +8 -2
- package/dist/compat/emblaV8.js.map +1 -1
- package/dist/features/FollowFocus.d.ts +7 -2
- package/dist/features/FollowFocus.d.ts.map +1 -1
- package/dist/features/FollowFocus.js +56 -16
- package/dist/features/FollowFocus.js.map +1 -1
- package/dist/features/HideOffscreen.d.ts +1 -4
- package/dist/features/HideOffscreen.d.ts.map +1 -1
- package/dist/features/HideOffscreen.js +5 -29
- package/dist/features/HideOffscreen.js.map +1 -1
- package/package.json +1 -1
- package/src/compat/emblaV8.ts +8 -2
- package/src/features/FollowFocus.ts +53 -15
- package/src/features/HideOffscreen.ts +5 -30
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are listed here. The project follows [Semantic Versioning](https://semver.org).
|
|
4
4
|
|
|
5
|
+
## 1.1.3 (2026-10-22)
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- A slide that leaves the screen becomes `inert` while the carousel still moves, not only once it stops. Embla says it has stopped up to two seconds after the slides look still, and until then Tab and Shift+Tab could reach slides that had left the screen, and the carousel jumped back to them.
|
|
10
|
+
- Focus on a partly visible slide now also moves it only into full view when the slides have fractional widths, for example 60% of a 952 px carousel. Before, the slide ended a fraction of a pixel short of the edge, the carousel jumped to its snap point, and Tab walked through every slide again.
|
|
11
|
+
- With Embla 8.6, focus on a slide that is already in full view no longer moves the carousel to the nearest snap point when it rests between two of them.
|
|
12
|
+
|
|
13
|
+
## 1.1.2 (2026-10-22)
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- Focus on a partly visible slide moves the carousel just far enough to show that slide in full, instead of jumping to its snap point. The jump pulled the next slide in, so Tab walked through every slide of a carousel with peeking slides. Now Tab reaches the slides on screen and then the buttons, as in other layouts. After such a move the carousel can rest between two snap points until the next button press, drag or key.
|
|
18
|
+
|
|
5
19
|
## 1.1.1 (2026-10-22)
|
|
6
20
|
|
|
7
21
|
### Fixed
|
|
@@ -1 +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,
|
|
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,CA2DxE"}
|
package/dist/compat/emblaV8.js
CHANGED
|
@@ -15,9 +15,15 @@ export function asEmblaV9(emblaApi) {
|
|
|
15
15
|
const slideFocusListeners = new Set();
|
|
16
16
|
let jumpBack = null;
|
|
17
17
|
const onSlideFocusStart = () => {
|
|
18
|
-
const
|
|
18
|
+
const engine = emblaApi.internalEngine();
|
|
19
|
+
const start = engine.target.get();
|
|
19
20
|
const cancelled = [...slideFocusListeners].some((listener) => listener() === false);
|
|
20
|
-
jumpBack = cancelled
|
|
21
|
+
jumpBack = cancelled
|
|
22
|
+
? () => {
|
|
23
|
+
engine.scrollBody.useBaseFriction().useDuration(0);
|
|
24
|
+
engine.scrollTo.distance(start - engine.target.get(), false);
|
|
25
|
+
}
|
|
26
|
+
: null;
|
|
21
27
|
};
|
|
22
28
|
const onSlideFocus = () => {
|
|
23
29
|
jumpBack?.();
|
|
@@ -1 +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,
|
|
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,MAAM,GAAG,QAAQ,CAAC,cAAc,EAAE,CAAA;QACxC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAA;QACjC,MAAM,SAAS,GAAG,CAAC,GAAG,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE,KAAK,KAAK,CAA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,OAAO,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,IAAI,UAAU,IAAI,QAAQ,CAAA;AACxD,CAAC;AAED,SAAS,WAAW,CAAC,aAAyB;IAC5C,MAAM,KAAK,GAA2B,EAAE,CAAA;IACxC,aAAa,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;QACrC,KAAK,MAAM,KAAK,IAAI,MAAM;YAAE,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,CAAA;IACjD,CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { EmblaCarouselType } from 'embla-carousel';
|
|
2
2
|
import type { Feature } from './Feature.js';
|
|
3
3
|
/**
|
|
4
|
-
* Moves the carousel
|
|
4
|
+
* Moves the carousel just far enough to show the slide that got focus in full, and never to the slide's snap,
|
|
5
|
+
* so the slide after it does not peek in and Tab stays with the slides on screen.
|
|
5
6
|
* It follows keyboard, screen reader and script focus, but not mouse or touch presses or focus the browser restores.
|
|
6
7
|
* It also undoes the browser's own scrolling of the viewport, and moves the carousel to what the browser scrolled to
|
|
7
8
|
* without focus, as find in page or a link to a slide do.
|
|
@@ -17,13 +18,17 @@ export declare class FollowFocus implements Feature {
|
|
|
17
18
|
private readonly onWindowFocus;
|
|
18
19
|
private windowWasLeft;
|
|
19
20
|
private pressed;
|
|
21
|
+
private wantedStart;
|
|
20
22
|
private restoreTimeout;
|
|
21
23
|
constructor(emblaApi: EmblaCarouselType);
|
|
22
24
|
destroy(): void;
|
|
23
25
|
private follow;
|
|
24
|
-
private resetNativeScroll;
|
|
25
26
|
private goToSlideOf;
|
|
27
|
+
private resetNativeScroll;
|
|
28
|
+
private boxOf;
|
|
29
|
+
private startOf;
|
|
26
30
|
private moveBy;
|
|
27
31
|
private overflow;
|
|
32
|
+
private edges;
|
|
28
33
|
}
|
|
29
34
|
//# sourceMappingURL=FollowFocus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FollowFocus.d.ts","sourceRoot":"","sources":["../../src/features/FollowFocus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C
|
|
1
|
+
{"version":3,"file":"FollowFocus.d.ts","sourceRoot":"","sources":["../../src/features/FollowFocus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C;;;;;;GAMG;AACH,qBAAa,WAAY,YAAW,OAAO;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyD;IACnF,OAAO,CAAC,QAAQ,CAAC,aAAa,CAE7B;IACD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAEzB;IACD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAU5B;IACD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAM9B;IACD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAE5B;IACD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAK7B;IACD,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,cAAc,CAA2C;IAEjE,YAAmB,QAAQ,EAAE,iBAAiB,EAS7C;IAEM,OAAO,IAAI,IAAI,CASrB;IAED,OAAO,CAAC,MAAM;IAuBd,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,KAAK;IASb,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,MAAM;IAYd,OAAO,CAAC,QAAQ;IAUhB,OAAO,CAAC,KAAK;CAKd"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Moves the carousel
|
|
2
|
+
* Moves the carousel just far enough to show the slide that got focus in full, and never to the slide's snap,
|
|
3
|
+
* so the slide after it does not peek in and Tab stays with the slides on screen.
|
|
3
4
|
* It follows keyboard, screen reader and script focus, but not mouse or touch presses or focus the browser restores.
|
|
4
5
|
* It also undoes the browser's own scrolling of the viewport, and moves the carousel to what the browser scrolled to
|
|
5
6
|
* without focus, as find in page or a link to a slide do.
|
|
@@ -16,7 +17,15 @@ export class FollowFocus {
|
|
|
16
17
|
onSlideFocus = () => {
|
|
17
18
|
this.resetNativeScroll();
|
|
18
19
|
const focused = document.activeElement;
|
|
19
|
-
|
|
20
|
+
if (!(focused instanceof Element))
|
|
21
|
+
return true;
|
|
22
|
+
const box = this.boxOf(focused);
|
|
23
|
+
const clipped = this.overflow(box);
|
|
24
|
+
if (clipped === 0)
|
|
25
|
+
return false;
|
|
26
|
+
// Embla jumps to the snap next; follow() corrects it to this.
|
|
27
|
+
this.wantedStart = this.startOf(box) - clipped;
|
|
28
|
+
return true;
|
|
20
29
|
};
|
|
21
30
|
onNativeScroll = () => {
|
|
22
31
|
const root = this.emblaApi.rootNode();
|
|
@@ -36,6 +45,7 @@ export class FollowFocus {
|
|
|
36
45
|
};
|
|
37
46
|
windowWasLeft = false;
|
|
38
47
|
pressed = null;
|
|
48
|
+
wantedStart = null;
|
|
39
49
|
restoreTimeout;
|
|
40
50
|
constructor(emblaApi) {
|
|
41
51
|
this.emblaApi = emblaApi;
|
|
@@ -59,48 +69,78 @@ export class FollowFocus {
|
|
|
59
69
|
}
|
|
60
70
|
follow(target) {
|
|
61
71
|
this.resetNativeScroll();
|
|
72
|
+
const wantedStart = this.wantedStart;
|
|
62
73
|
const restoredByBrowser = this.windowWasLeft;
|
|
63
74
|
const pressed = this.pressed;
|
|
75
|
+
this.wantedStart = null;
|
|
64
76
|
this.windowWasLeft = false;
|
|
65
77
|
this.pressed = null;
|
|
66
78
|
if (restoredByBrowser || !(target instanceof Element))
|
|
67
79
|
return;
|
|
68
80
|
if (pressed !== null && target.contains(pressed))
|
|
69
81
|
return;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.
|
|
82
|
+
const box = this.boxOf(target);
|
|
83
|
+
const start = wantedStart ?? this.startOf(box) - this.overflow(box);
|
|
84
|
+
const distance = start - this.startOf(box);
|
|
85
|
+
if (distance !== 0)
|
|
86
|
+
this.moveBy(distance);
|
|
87
|
+
// Under Fade only the snap shows the slide.
|
|
88
|
+
if (this.overflow(box) !== 0)
|
|
89
|
+
this.goToSlideOf(target);
|
|
90
|
+
// A wide button can stick out of its slide.
|
|
73
91
|
const clipped = this.overflow(target);
|
|
74
92
|
if (clipped !== 0)
|
|
75
93
|
this.moveBy(-clipped);
|
|
76
94
|
}
|
|
77
|
-
resetNativeScroll() {
|
|
78
|
-
const root = this.emblaApi.rootNode();
|
|
79
|
-
root.scrollLeft = 0;
|
|
80
|
-
root.scrollTop = 0;
|
|
81
|
-
}
|
|
82
95
|
goToSlideOf(target) {
|
|
83
96
|
const slideIndex = this.emblaApi.slideNodes().findIndex((slide) => slide.contains(target));
|
|
84
97
|
const snapIndex = this.emblaApi.internalEngine().scrollSnapList.snapBySlide[slideIndex];
|
|
85
98
|
if (snapIndex !== undefined)
|
|
86
99
|
this.emblaApi.goTo(snapIndex, true);
|
|
87
100
|
}
|
|
101
|
+
resetNativeScroll() {
|
|
102
|
+
const root = this.emblaApi.rootNode();
|
|
103
|
+
root.scrollLeft = 0;
|
|
104
|
+
root.scrollTop = 0;
|
|
105
|
+
}
|
|
106
|
+
boxOf(target) {
|
|
107
|
+
const slide = this.emblaApi.slideNodes().find((candidate) => candidate.contains(target));
|
|
108
|
+
if (slide === undefined)
|
|
109
|
+
return target;
|
|
110
|
+
const [start, end] = this.edges();
|
|
111
|
+
const inner = slide.getBoundingClientRect();
|
|
112
|
+
const outer = this.emblaApi.rootNode().getBoundingClientRect();
|
|
113
|
+
return inner[end] - inner[start] <= outer[end] - outer[start] ? slide : target;
|
|
114
|
+
}
|
|
115
|
+
startOf(element) {
|
|
116
|
+
return element.getBoundingClientRect()[this.edges()[0]];
|
|
117
|
+
}
|
|
88
118
|
moveBy(distance) {
|
|
89
119
|
const engine = this.emblaApi.internalEngine();
|
|
120
|
+
const current = engine.target.get();
|
|
121
|
+
const wanted = current + engine.axis.direction(distance);
|
|
122
|
+
// Past the limit, an instant move never settles.
|
|
123
|
+
const reachable = engine.options.loop
|
|
124
|
+
? wanted
|
|
125
|
+
: Math.min(Math.max(wanted, engine.limit.min), engine.limit.max);
|
|
90
126
|
engine.scrollBody.useBaseFriction().useDuration(0);
|
|
91
|
-
engine.scrollTo.distance(
|
|
127
|
+
engine.scrollTo.distance(reachable - current, false);
|
|
92
128
|
}
|
|
93
129
|
overflow(element) {
|
|
94
130
|
const inner = element.getBoundingClientRect();
|
|
95
131
|
const outer = this.emblaApi.rootNode().getBoundingClientRect();
|
|
96
|
-
const [start, end] = this.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (inner[start] < outer[start])
|
|
132
|
+
const [start, end] = this.edges();
|
|
133
|
+
// Slides with fractional widths stop a fraction of a pixel off the edge.
|
|
134
|
+
if (inner[start] < outer[start] - 1)
|
|
100
135
|
return inner[start] - outer[start];
|
|
101
|
-
if (inner[end] > outer[end])
|
|
136
|
+
if (inner[end] > outer[end] + 1)
|
|
102
137
|
return inner[end] - outer[end];
|
|
103
138
|
return 0;
|
|
104
139
|
}
|
|
140
|
+
edges() {
|
|
141
|
+
return this.emblaApi.internalEngine().axis.scroll === 'x'
|
|
142
|
+
? ['left', 'right']
|
|
143
|
+
: ['top', 'bottom'];
|
|
144
|
+
}
|
|
105
145
|
}
|
|
106
146
|
//# sourceMappingURL=FollowFocus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FollowFocus.js","sourceRoot":"","sources":["../../src/features/FollowFocus.ts"],"names":[],"mappings":"AAGA
|
|
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|
1
1
|
import type { EmblaCarouselType } from 'embla-carousel';
|
|
2
2
|
import type { Feature } from './Feature.js';
|
|
3
3
|
/**
|
|
4
|
-
* Makes slides inert when they are completely outside the viewport
|
|
4
|
+
* Makes slides inert when they are completely outside the viewport, except the one with focus.
|
|
5
5
|
* A slide comes back as soon as any part of it is on screen.
|
|
6
6
|
* List items keep their position and the full count, so screen readers don't count only the visible ones.
|
|
7
7
|
*/
|
|
@@ -13,13 +13,10 @@ export declare class HideOffscreen implements Feature {
|
|
|
13
13
|
private readonly onFocusOut;
|
|
14
14
|
private readonly scheduleRefresh;
|
|
15
15
|
private pendingFrame;
|
|
16
|
-
private moving;
|
|
17
16
|
constructor(emblaApi: EmblaCarouselType);
|
|
18
17
|
destroy(): void;
|
|
19
18
|
private keepListCount;
|
|
20
|
-
private refresh;
|
|
21
19
|
private update;
|
|
22
|
-
private showVisibleSlides;
|
|
23
20
|
private autoScrolling;
|
|
24
21
|
}
|
|
25
22
|
//# sourceMappingURL=HideOffscreen.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HideOffscreen.d.ts","sourceRoot":"","sources":["../../src/features/HideOffscreen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAGvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C;;;;GAIG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;IAC5C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;IAClD,OAAO,CAAC,QAAQ,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"HideOffscreen.d.ts","sourceRoot":"","sources":["../../src/features/HideOffscreen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAGvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C;;;;GAIG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;IAC5C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;IAClD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAIxB;IACD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA4B;IACrD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAG1B;IACD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAG/B;IACD,OAAO,CAAC,YAAY,CAAI;IAExB,YAAmB,QAAQ,EAAE,iBAAiB,EAQ7C;IAEM,OAAO,IAAI,IAAI,CAOrB;IAED,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,MAAM;IAYd,OAAO,CAAC,aAAa;CAKtB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AttributeStore } from '../AttributeStore.js';
|
|
2
2
|
import { slidesOnScreen } from '../visibleSlides.js';
|
|
3
3
|
/**
|
|
4
|
-
* Makes slides inert when they are completely outside the viewport
|
|
4
|
+
* Makes slides inert when they are completely outside the viewport, except the one with focus.
|
|
5
5
|
* A slide comes back as soon as any part of it is on screen.
|
|
6
6
|
* List items keep their position and the full count, so screen readers don't count only the visible ones.
|
|
7
7
|
*/
|
|
@@ -9,29 +9,24 @@ export class HideOffscreen {
|
|
|
9
9
|
emblaApi;
|
|
10
10
|
attributes = new AttributeStore();
|
|
11
11
|
onScroll = () => {
|
|
12
|
-
this.moving = true;
|
|
13
12
|
// Embla has just moved the slides, so a later frame would only see positions that are already stale.
|
|
14
13
|
if (this.autoScrolling())
|
|
15
|
-
this.
|
|
14
|
+
this.update();
|
|
16
15
|
else
|
|
17
16
|
this.scheduleRefresh();
|
|
18
17
|
};
|
|
19
|
-
onSettle = () =>
|
|
20
|
-
this.moving = false;
|
|
21
|
-
this.update();
|
|
22
|
-
};
|
|
18
|
+
onSettle = () => this.update();
|
|
23
19
|
onFocusOut = (event) => {
|
|
24
20
|
if (event.relatedTarget instanceof Element)
|
|
25
|
-
this.
|
|
21
|
+
this.update(event.relatedTarget);
|
|
26
22
|
else
|
|
27
23
|
this.scheduleRefresh();
|
|
28
24
|
};
|
|
29
25
|
scheduleRefresh = () => {
|
|
30
26
|
cancelAnimationFrame(this.pendingFrame);
|
|
31
|
-
this.pendingFrame = requestAnimationFrame(() => this.
|
|
27
|
+
this.pendingFrame = requestAnimationFrame(() => this.update());
|
|
32
28
|
};
|
|
33
29
|
pendingFrame = 0;
|
|
34
|
-
moving = false;
|
|
35
30
|
constructor(emblaApi) {
|
|
36
31
|
this.emblaApi = emblaApi;
|
|
37
32
|
this.keepListCount();
|
|
@@ -61,17 +56,6 @@ export class HideOffscreen {
|
|
|
61
56
|
this.attributes.set(slide, 'aria-setsize', String(slides.length));
|
|
62
57
|
});
|
|
63
58
|
}
|
|
64
|
-
refresh(focused = document.activeElement) {
|
|
65
|
-
// Embla 8.6 emits no settle after an instant jump, so moving is also over once the scroll body has settled.
|
|
66
|
-
// AutoScroll never settles, and any interaction stops it, so it gets the full update on every frame.
|
|
67
|
-
const settled = this.emblaApi.internalEngine().scrollBody.settled();
|
|
68
|
-
if (this.moving && !settled && !this.autoScrolling()) {
|
|
69
|
-
this.showVisibleSlides();
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
this.moving = false;
|
|
73
|
-
this.update(focused);
|
|
74
|
-
}
|
|
75
59
|
update(focused = document.activeElement) {
|
|
76
60
|
const slides = this.emblaApi.slideNodes();
|
|
77
61
|
const visible = slidesOnScreen(slides, this.emblaApi.rootNode());
|
|
@@ -84,14 +68,6 @@ export class HideOffscreen {
|
|
|
84
68
|
}
|
|
85
69
|
});
|
|
86
70
|
}
|
|
87
|
-
showVisibleSlides() {
|
|
88
|
-
const slides = this.emblaApi.slideNodes();
|
|
89
|
-
const visible = slidesOnScreen(slides, this.emblaApi.rootNode());
|
|
90
|
-
slides.forEach((slide, index) => {
|
|
91
|
-
if (visible[index] === true)
|
|
92
|
-
this.attributes.reset(slide, 'inert');
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
71
|
autoScrolling() {
|
|
96
72
|
return Object.entries(this.emblaApi.plugins()).some(([name, plugin]) => name === 'autoScroll' && isPlaying(plugin));
|
|
97
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HideOffscreen.js","sourceRoot":"","sources":["../../src/features/HideOffscreen.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGpD;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACP,QAAQ,CAAmB;IAC3B,UAAU,GAAG,IAAI,cAAc,EAAE,CAAA;IACjC,QAAQ,GAAG,GAAS,EAAE;QACrC,
|
|
1
|
+
{"version":3,"file":"HideOffscreen.js","sourceRoot":"","sources":["../../src/features/HideOffscreen.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGpD;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACP,QAAQ,CAAmB;IAC3B,UAAU,GAAG,IAAI,cAAc,EAAE,CAAA;IACjC,QAAQ,GAAG,GAAS,EAAE;QACrC,qGAAqG;QACrG,IAAI,IAAI,CAAC,aAAa,EAAE;YAAE,IAAI,CAAC,MAAM,EAAE,CAAA;;YAClC,IAAI,CAAC,eAAe,EAAE,CAAA;IAC7B,CAAC,CAAA;IACgB,QAAQ,GAAG,GAAS,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAA;IACpC,UAAU,GAAG,CAAC,KAAiB,EAAQ,EAAE;QACxD,IAAI,KAAK,CAAC,aAAa,YAAY,OAAO;YAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;;YACvE,IAAI,CAA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AM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CACjD,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,YAAY,IAAI,SAAS,CAAC,MAAM,CAAC,CAC/D,CAAA;IACH,CAAC;CACF;AAED,SAAS,SAAS,CAAC,MAAe;IAChC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,CAAC,WAAW,IAAI,MAAM,CAAC;QAAE,OAAO,KAAK,CAAA;IAC3F,OAAO,OAAO,MAAM,CAAC,SAAS,KAAK,UAAU,IAAI,MAAM,CAAC,SAAS,EAAE,KAAK,IAAI,CAAA;AAC9E,CAAC"}
|
package/package.json
CHANGED
package/src/compat/emblaV8.ts
CHANGED
|
@@ -33,9 +33,15 @@ export function asEmblaV9(emblaApi: EmblaCarouselType): EmblaCarouselType {
|
|
|
33
33
|
const slideFocusListeners = new Set<SlideFocusListenerType>()
|
|
34
34
|
let jumpBack: (() => void) | null = null
|
|
35
35
|
const onSlideFocusStart = (): void => {
|
|
36
|
-
const
|
|
36
|
+
const engine = emblaApi.internalEngine()
|
|
37
|
+
const start = engine.target.get()
|
|
37
38
|
const cancelled = [...slideFocusListeners].some((listener) => listener() === false)
|
|
38
|
-
jumpBack = cancelled
|
|
39
|
+
jumpBack = cancelled
|
|
40
|
+
? () => {
|
|
41
|
+
engine.scrollBody.useBaseFriction().useDuration(0)
|
|
42
|
+
engine.scrollTo.distance(start - engine.target.get(), false)
|
|
43
|
+
}
|
|
44
|
+
: null
|
|
39
45
|
}
|
|
40
46
|
const onSlideFocus = (): void => {
|
|
41
47
|
jumpBack?.()
|
|
@@ -2,7 +2,8 @@ import type { EmblaCarouselType } from 'embla-carousel'
|
|
|
2
2
|
import type { Feature } from './Feature.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Moves the carousel
|
|
5
|
+
* Moves the carousel just far enough to show the slide that got focus in full, and never to the slide's snap,
|
|
6
|
+
* so the slide after it does not peek in and Tab stays with the slides on screen.
|
|
6
7
|
* It follows keyboard, screen reader and script focus, but not mouse or touch presses or focus the browser restores.
|
|
7
8
|
* It also undoes the browser's own scrolling of the viewport, and moves the carousel to what the browser scrolled to
|
|
8
9
|
* without focus, as find in page or a link to a slide do.
|
|
@@ -19,7 +20,13 @@ export class FollowFocus implements Feature {
|
|
|
19
20
|
private readonly onSlideFocus = (): boolean => {
|
|
20
21
|
this.resetNativeScroll()
|
|
21
22
|
const focused = document.activeElement
|
|
22
|
-
|
|
23
|
+
if (!(focused instanceof Element)) return true
|
|
24
|
+
const box = this.boxOf(focused)
|
|
25
|
+
const clipped = this.overflow(box)
|
|
26
|
+
if (clipped === 0) return false
|
|
27
|
+
// Embla jumps to the snap next; follow() corrects it to this.
|
|
28
|
+
this.wantedStart = this.startOf(box) - clipped
|
|
29
|
+
return true
|
|
23
30
|
}
|
|
24
31
|
private readonly onNativeScroll = (): void => {
|
|
25
32
|
const root = this.emblaApi.rootNode()
|
|
@@ -39,6 +46,7 @@ export class FollowFocus implements Feature {
|
|
|
39
46
|
}
|
|
40
47
|
private windowWasLeft = false
|
|
41
48
|
private pressed: Node | null = null
|
|
49
|
+
private wantedStart: number | null = null
|
|
42
50
|
private restoreTimeout: ReturnType<typeof setTimeout> | undefined
|
|
43
51
|
|
|
44
52
|
public constructor(emblaApi: EmblaCarouselType) {
|
|
@@ -66,46 +74,76 @@ export class FollowFocus implements Feature {
|
|
|
66
74
|
private follow(target: EventTarget | null): void {
|
|
67
75
|
this.resetNativeScroll()
|
|
68
76
|
|
|
77
|
+
const wantedStart = this.wantedStart
|
|
69
78
|
const restoredByBrowser = this.windowWasLeft
|
|
70
79
|
const pressed = this.pressed
|
|
80
|
+
this.wantedStart = null
|
|
71
81
|
this.windowWasLeft = false
|
|
72
82
|
this.pressed = null
|
|
73
83
|
if (restoredByBrowser || !(target instanceof Element)) return
|
|
74
84
|
if (pressed !== null && target.contains(pressed)) return
|
|
75
|
-
if (this.overflow(target) === 0) return
|
|
76
|
-
this.goToSlideOf(target)
|
|
77
85
|
|
|
86
|
+
const box = this.boxOf(target)
|
|
87
|
+
const start = wantedStart ?? this.startOf(box) - this.overflow(box)
|
|
88
|
+
const distance = start - this.startOf(box)
|
|
89
|
+
if (distance !== 0) this.moveBy(distance)
|
|
90
|
+
// Under Fade only the snap shows the slide.
|
|
91
|
+
if (this.overflow(box) !== 0) this.goToSlideOf(target)
|
|
92
|
+
// A wide button can stick out of its slide.
|
|
78
93
|
const clipped = this.overflow(target)
|
|
79
94
|
if (clipped !== 0) this.moveBy(-clipped)
|
|
80
95
|
}
|
|
81
96
|
|
|
97
|
+
private goToSlideOf(target: Element): void {
|
|
98
|
+
const slideIndex = this.emblaApi.slideNodes().findIndex((slide) => slide.contains(target))
|
|
99
|
+
const snapIndex = this.emblaApi.internalEngine().scrollSnapList.snapBySlide[slideIndex]
|
|
100
|
+
if (snapIndex !== undefined) this.emblaApi.goTo(snapIndex, true)
|
|
101
|
+
}
|
|
102
|
+
|
|
82
103
|
private resetNativeScroll(): void {
|
|
83
104
|
const root = this.emblaApi.rootNode()
|
|
84
105
|
root.scrollLeft = 0
|
|
85
106
|
root.scrollTop = 0
|
|
86
107
|
}
|
|
87
108
|
|
|
88
|
-
private
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
109
|
+
private boxOf(target: Element): Element {
|
|
110
|
+
const slide = this.emblaApi.slideNodes().find((candidate) => candidate.contains(target))
|
|
111
|
+
if (slide === undefined) return target
|
|
112
|
+
const [start, end] = this.edges()
|
|
113
|
+
const inner = slide.getBoundingClientRect()
|
|
114
|
+
const outer = this.emblaApi.rootNode().getBoundingClientRect()
|
|
115
|
+
return inner[end] - inner[start] <= outer[end] - outer[start] ? slide : target
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private startOf(element: Element): number {
|
|
119
|
+
return element.getBoundingClientRect()[this.edges()[0]]
|
|
92
120
|
}
|
|
93
121
|
|
|
94
122
|
private moveBy(distance: number): void {
|
|
95
123
|
const engine = this.emblaApi.internalEngine()
|
|
124
|
+
const current = engine.target.get()
|
|
125
|
+
const wanted = current + engine.axis.direction(distance)
|
|
126
|
+
// Past the limit, an instant move never settles.
|
|
127
|
+
const reachable = engine.options.loop
|
|
128
|
+
? wanted
|
|
129
|
+
: Math.min(Math.max(wanted, engine.limit.min), engine.limit.max)
|
|
96
130
|
engine.scrollBody.useBaseFriction().useDuration(0)
|
|
97
|
-
engine.scrollTo.distance(
|
|
131
|
+
engine.scrollTo.distance(reachable - current, false)
|
|
98
132
|
}
|
|
99
133
|
|
|
100
134
|
private overflow(element: Element): number {
|
|
101
135
|
const inner = element.getBoundingClientRect()
|
|
102
136
|
const outer = this.emblaApi.rootNode().getBoundingClientRect()
|
|
103
|
-
const [start, end] =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (inner[start] < outer[start]) return inner[start] - outer[start]
|
|
108
|
-
if (inner[end] > outer[end]) return inner[end] - outer[end]
|
|
137
|
+
const [start, end] = this.edges()
|
|
138
|
+
// Slides with fractional widths stop a fraction of a pixel off the edge.
|
|
139
|
+
if (inner[start] < outer[start] - 1) return inner[start] - outer[start]
|
|
140
|
+
if (inner[end] > outer[end] + 1) return inner[end] - outer[end]
|
|
109
141
|
return 0
|
|
110
142
|
}
|
|
143
|
+
|
|
144
|
+
private edges(): readonly ['left', 'right'] | readonly ['top', 'bottom'] {
|
|
145
|
+
return this.emblaApi.internalEngine().axis.scroll === 'x'
|
|
146
|
+
? (['left', 'right'] as const)
|
|
147
|
+
: (['top', 'bottom'] as const)
|
|
148
|
+
}
|
|
111
149
|
}
|
|
@@ -4,7 +4,7 @@ import { slidesOnScreen } from '../visibleSlides.js'
|
|
|
4
4
|
import type { Feature } from './Feature.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Makes slides inert when they are completely outside the viewport
|
|
7
|
+
* Makes slides inert when they are completely outside the viewport, except the one with focus.
|
|
8
8
|
* A slide comes back as soon as any part of it is on screen.
|
|
9
9
|
* List items keep their position and the full count, so screen readers don't count only the visible ones.
|
|
10
10
|
*/
|
|
@@ -12,25 +12,20 @@ export class HideOffscreen implements Feature {
|
|
|
12
12
|
private readonly emblaApi: EmblaCarouselType
|
|
13
13
|
private readonly attributes = new AttributeStore()
|
|
14
14
|
private readonly onScroll = (): void => {
|
|
15
|
-
this.moving = true
|
|
16
15
|
// Embla has just moved the slides, so a later frame would only see positions that are already stale.
|
|
17
|
-
if (this.autoScrolling()) this.
|
|
16
|
+
if (this.autoScrolling()) this.update()
|
|
18
17
|
else this.scheduleRefresh()
|
|
19
18
|
}
|
|
20
|
-
private readonly onSettle = (): void =>
|
|
21
|
-
this.moving = false
|
|
22
|
-
this.update()
|
|
23
|
-
}
|
|
19
|
+
private readonly onSettle = (): void => this.update()
|
|
24
20
|
private readonly onFocusOut = (event: FocusEvent): void => {
|
|
25
|
-
if (event.relatedTarget instanceof Element) this.
|
|
21
|
+
if (event.relatedTarget instanceof Element) this.update(event.relatedTarget)
|
|
26
22
|
else this.scheduleRefresh()
|
|
27
23
|
}
|
|
28
24
|
private readonly scheduleRefresh = (): void => {
|
|
29
25
|
cancelAnimationFrame(this.pendingFrame)
|
|
30
|
-
this.pendingFrame = requestAnimationFrame(() => this.
|
|
26
|
+
this.pendingFrame = requestAnimationFrame(() => this.update())
|
|
31
27
|
}
|
|
32
28
|
private pendingFrame = 0
|
|
33
|
-
private moving = false
|
|
34
29
|
|
|
35
30
|
public constructor(emblaApi: EmblaCarouselType) {
|
|
36
31
|
this.emblaApi = emblaApi
|
|
@@ -63,18 +58,6 @@ export class HideOffscreen implements Feature {
|
|
|
63
58
|
})
|
|
64
59
|
}
|
|
65
60
|
|
|
66
|
-
private refresh(focused: Element | null = document.activeElement): void {
|
|
67
|
-
// Embla 8.6 emits no settle after an instant jump, so moving is also over once the scroll body has settled.
|
|
68
|
-
// AutoScroll never settles, and any interaction stops it, so it gets the full update on every frame.
|
|
69
|
-
const settled = this.emblaApi.internalEngine().scrollBody.settled()
|
|
70
|
-
if (this.moving && !settled && !this.autoScrolling()) {
|
|
71
|
-
this.showVisibleSlides()
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
this.moving = false
|
|
75
|
-
this.update(focused)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
61
|
private update(focused: Element | null = document.activeElement): void {
|
|
79
62
|
const slides = this.emblaApi.slideNodes()
|
|
80
63
|
const visible = slidesOnScreen(slides, this.emblaApi.rootNode())
|
|
@@ -87,14 +70,6 @@ export class HideOffscreen implements Feature {
|
|
|
87
70
|
})
|
|
88
71
|
}
|
|
89
72
|
|
|
90
|
-
private showVisibleSlides(): void {
|
|
91
|
-
const slides = this.emblaApi.slideNodes()
|
|
92
|
-
const visible = slidesOnScreen(slides, this.emblaApi.rootNode())
|
|
93
|
-
slides.forEach((slide, index) => {
|
|
94
|
-
if (visible[index] === true) this.attributes.reset(slide, 'inert')
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
|
|
98
73
|
private autoScrolling(): boolean {
|
|
99
74
|
return Object.entries(this.emblaApi.plugins()).some(
|
|
100
75
|
([name, plugin]) => name === 'autoScroll' && isPlaying(plugin)
|