@twistedandy/better-carousel 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/LICENSE +21 -0
- package/README.md +838 -2
- package/dist/better-carousel.css +1 -0
- package/dist/better-carousel.js +3175 -0
- package/dist/better-carousel.min.js +1 -0
- package/package.json +55 -5
- package/src/index.js +49 -0
- package/src/scripts/autoplay.js +288 -0
- package/src/scripts/carousel.js +834 -0
- package/src/scripts/geometry.js +429 -0
- package/src/scripts/input.js +432 -0
- package/src/scripts/layout.js +205 -0
- package/src/scripts/loop.js +83 -0
- package/src/scripts/markup.js +268 -0
- package/src/scripts/motion.js +232 -0
- package/src/scripts/navigation.js +209 -0
- package/src/scripts/options.js +153 -0
- package/src/styles/better-carousel.scss +323 -0
- package/src/types/better-carousel.d.ts +309 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Navigation: the arrows, the dots, and the link to another carousel (the sync option).
|
|
3
|
+
*
|
|
4
|
+
* Each feature takes the context of a carousel (see carousel.js). It returns nothing if its option is off, or an object with remove().
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { find } from './carousel.js';
|
|
8
|
+
import { create, optionElement, setAttribute, setClass } from './markup.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Make the arrows and the dots of a carousel. They update on the carousel events.
|
|
12
|
+
*
|
|
13
|
+
* @param {object} context What the features share. See carousel.js.
|
|
14
|
+
* @returns {{remove: () => void}|undefined} remove() removes the arrows and the dots.
|
|
15
|
+
*/
|
|
16
|
+
export function nav(context) {
|
|
17
|
+
const { api, root, cls, options } = context,
|
|
18
|
+
labels = options.labels,
|
|
19
|
+
arrows = optionElement(options.arrows, root),
|
|
20
|
+
box = optionElement(options.dots, root),
|
|
21
|
+
buttons = [],
|
|
22
|
+
dots = [],
|
|
23
|
+
// The window of 5 dots, or all dots with dotsStyle: 'all'
|
|
24
|
+
windowed = options.dotsStyle !== 'all',
|
|
25
|
+
// The window of the dots, the track that slides in it, and the marker of the selected dot
|
|
26
|
+
list = box && create('div', windowed ? cls.dots : cls.dots + ' ' + cls.dotsAll),
|
|
27
|
+
track = list && create('div', cls.dotsTrack);
|
|
28
|
+
|
|
29
|
+
let marks = new Map();
|
|
30
|
+
|
|
31
|
+
if (!arrows && !box) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Add the window of the dots now: its CSS height is fixed, so the dots that the first measure adds do not shift the page
|
|
36
|
+
if (list) {
|
|
37
|
+
track.append(create('span', cls.dotsMarker));
|
|
38
|
+
list.append(track);
|
|
39
|
+
box.append(list);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (arrows) {
|
|
43
|
+
[['prev', 'goToPrev'], ['next', 'goToNext']].forEach(([key, method]) => {
|
|
44
|
+
const button = create('button', cls.button + ' ' + cls[key + 'Button']);
|
|
45
|
+
button.type = 'button';
|
|
46
|
+
button.setAttribute('aria-label', labels[key]);
|
|
47
|
+
button.setAttribute('aria-controls', context.container.id);
|
|
48
|
+
button.addEventListener('click', () => api[method]());
|
|
49
|
+
buttons.push(button);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function update() {
|
|
54
|
+
const fit = api.isFit(),
|
|
55
|
+
count = fit ? 0 : api.snapProgress().length,
|
|
56
|
+
selected = api.selectedSnap();
|
|
57
|
+
|
|
58
|
+
buttons.forEach((button, index) => {
|
|
59
|
+
if (fit) {
|
|
60
|
+
button.remove();
|
|
61
|
+
} else {
|
|
62
|
+
if (!button.isConnected) {
|
|
63
|
+
// Before the dots, for the tab order
|
|
64
|
+
list?.parentNode === arrows ? list.before(button) : arrows.append(button);
|
|
65
|
+
}
|
|
66
|
+
const disabled = !(index ? api.canGoToNext() : api.canGoToPrev());
|
|
67
|
+
if (button.disabled !== disabled) {
|
|
68
|
+
button.disabled = disabled;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (!list) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (count < 2) {
|
|
78
|
+
list.remove();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
while (dots.length > count) {
|
|
83
|
+
dots.pop().remove();
|
|
84
|
+
marks.delete(dots.length);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
while (dots.length < count) {
|
|
88
|
+
const dot = create('button', cls.dot),
|
|
89
|
+
index = dots.length;
|
|
90
|
+
dot.type = 'button';
|
|
91
|
+
dot.setAttribute('aria-label', labels.dot.replace('%d', index + 1));
|
|
92
|
+
dot.setAttribute('aria-controls', context.container.id);
|
|
93
|
+
// The window of the dots hides the dots out of the zoom: keep them out of the tab order
|
|
94
|
+
if (windowed) {
|
|
95
|
+
dot.tabIndex = -1;
|
|
96
|
+
}
|
|
97
|
+
dot.addEventListener('click', () => api.goToSnap(index));
|
|
98
|
+
dots.push(dot);
|
|
99
|
+
track.append(dot);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!list.isConnected) {
|
|
103
|
+
box.append(list);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// The zoom effect: the 5 dots around the selected dot get state classes
|
|
107
|
+
const next = new Map();
|
|
108
|
+
|
|
109
|
+
['first', 'prev', 'current', 'next', 'last'].forEach((key, offset) => {
|
|
110
|
+
if (dots[selected + offset - 2]) {
|
|
111
|
+
next.set(selected + offset - 2, cls[key]);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
marks.forEach((name, index) => {
|
|
116
|
+
if (next.get(index) !== name) {
|
|
117
|
+
setClass(dots[index], name, false);
|
|
118
|
+
setAttribute(dots[index], 'aria-current', false);
|
|
119
|
+
dots[index].tabIndex = windowed ? -1 : 0;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
next.forEach((name, index) => {
|
|
124
|
+
setClass(dots[index], name, true);
|
|
125
|
+
setAttribute(dots[index], 'aria-current', index === selected && 'true');
|
|
126
|
+
dots[index].tabIndex = 0;
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
marks = next;
|
|
130
|
+
|
|
131
|
+
// Center the group of up to 5 dots in the window of the dots, and move the marker to the selected dot. The CSS moves the track and the marker with "translate".
|
|
132
|
+
if (windowed) {
|
|
133
|
+
variable('--better-shift', 2 - (Math.max(0, selected - 2) + Math.min(count - 1, selected + 2)) / 2);
|
|
134
|
+
}
|
|
135
|
+
variable('--better-dot', selected);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Set a CSS variable on the window of the dots, if its value changes
|
|
139
|
+
function variable(name, value) {
|
|
140
|
+
if (list.style.getPropertyValue(name) !== String(value)) {
|
|
141
|
+
list.style.setProperty(name, value);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
['init', 'reinit', 'resize', 'select', 'slideschanged'].forEach((name) => context.on(name, update));
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
remove() {
|
|
149
|
+
buttons.forEach((button) => button.remove());
|
|
150
|
+
list?.remove();
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Connect a carousel to another carousel with the same slides, such as thumbnails to a main gallery. This carousel follows the slide
|
|
157
|
+
* that the other carousel selects. Only a click on a slide of this carousel selects that slide in the other carousel: a drag does not.
|
|
158
|
+
*
|
|
159
|
+
* @param {object} context What the features share. See carousel.js. The "sync" option is the other carousel, its container or a selector.
|
|
160
|
+
* @returns {{remove: () => void}|undefined} remove() disconnects the carousels.
|
|
161
|
+
*/
|
|
162
|
+
export function sync(context) {
|
|
163
|
+
const { api, container } = context,
|
|
164
|
+
target = context.options.sync;
|
|
165
|
+
|
|
166
|
+
let other = null;
|
|
167
|
+
|
|
168
|
+
if (!target) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Show the slide that the other carousel selects
|
|
173
|
+
function show(instant) {
|
|
174
|
+
const index = other.selectedSlide();
|
|
175
|
+
context.follow(index);
|
|
176
|
+
api.goToSlide(index, instant === true);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function click(event) {
|
|
180
|
+
// The slide or the clone that gets the click, and then its original slide
|
|
181
|
+
const index = context.nodes().findIndex((node) => node.contains(event.target));
|
|
182
|
+
if (other && index > -1) {
|
|
183
|
+
other.goToSlide(index % api.slideNodes().length);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// The other carousel can come later than this one, so find it at the init
|
|
188
|
+
function connect() {
|
|
189
|
+
if (other) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
other = target.goToSnap ? target : find(typeof target === 'string' ? optionElement(target, context.root) : target);
|
|
193
|
+
if (other) {
|
|
194
|
+
other.on('select', show);
|
|
195
|
+
show(true);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
context.on('init', connect);
|
|
200
|
+
context.on('reinit', connect);
|
|
201
|
+
container.addEventListener('click', click);
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
remove() {
|
|
205
|
+
other?.off('select', show);
|
|
206
|
+
container.removeEventListener('click', click);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Options: the defaults, the class names, the merge of the option sources, and the breakpoints.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const defaults = {
|
|
6
|
+
axis: 'auto',
|
|
7
|
+
align: 'auto',
|
|
8
|
+
dir: 'auto',
|
|
9
|
+
loop: false,
|
|
10
|
+
dragFree: false,
|
|
11
|
+
dragFriction: 1,
|
|
12
|
+
containScroll: 'trimSnaps',
|
|
13
|
+
slidesPerSnap: 1,
|
|
14
|
+
skipSnaps: true,
|
|
15
|
+
dragThreshold: 10,
|
|
16
|
+
duration: 400,
|
|
17
|
+
startSnap: 0,
|
|
18
|
+
lazy: false,
|
|
19
|
+
drag: true,
|
|
20
|
+
wheel: true,
|
|
21
|
+
keys: true,
|
|
22
|
+
resize: true,
|
|
23
|
+
slideChanges: true,
|
|
24
|
+
focus: true,
|
|
25
|
+
inViewThreshold: 0,
|
|
26
|
+
active: true,
|
|
27
|
+
breakpoints: {},
|
|
28
|
+
container: null,
|
|
29
|
+
slides: null,
|
|
30
|
+
wrapper: true,
|
|
31
|
+
arrows: true,
|
|
32
|
+
dots: true,
|
|
33
|
+
dotsStyle: 'zoom',
|
|
34
|
+
labels: { carousel: 'Carousel', slide: '%d of %n', prev: 'Previous slide', next: 'Next slide', dot: 'Go to slide %d', play: 'Start the slide show', pause: 'Stop the slide show' },
|
|
35
|
+
classes: null,
|
|
36
|
+
state: '',
|
|
37
|
+
sync: null,
|
|
38
|
+
clones: 'auto',
|
|
39
|
+
autoplay: false,
|
|
40
|
+
autoScroll: false,
|
|
41
|
+
autoHeight: false,
|
|
42
|
+
progress: false,
|
|
43
|
+
offset: false
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// The class names of a prefix. The root class is the prefix, such as "better" or "embla".
|
|
47
|
+
const names = (prefix) => ({
|
|
48
|
+
root: prefix,
|
|
49
|
+
viewport: prefix + '_viewport',
|
|
50
|
+
container: prefix + '_container',
|
|
51
|
+
fit: prefix + '_fit',
|
|
52
|
+
horizontal: prefix + '_horizontal',
|
|
53
|
+
vertical: prefix + '_vertical',
|
|
54
|
+
autoHeight: prefix + '_auto_height',
|
|
55
|
+
button: prefix + '_button',
|
|
56
|
+
prevButton: prefix + '_prev',
|
|
57
|
+
nextButton: prefix + '_next',
|
|
58
|
+
dots: prefix + '_dots',
|
|
59
|
+
dotsTrack: prefix + '_dots_track',
|
|
60
|
+
dotsMarker: prefix + '_dots_marker',
|
|
61
|
+
dotsAll: prefix + '_dots_all',
|
|
62
|
+
dot: prefix + '_dot',
|
|
63
|
+
playButton: prefix + '_play',
|
|
64
|
+
clone: 'clone',
|
|
65
|
+
selected: 'selected',
|
|
66
|
+
inView: '',
|
|
67
|
+
dragging: 'dragging',
|
|
68
|
+
playing: 'playing',
|
|
69
|
+
first: 'first',
|
|
70
|
+
prev: 'prev',
|
|
71
|
+
current: 'current',
|
|
72
|
+
next: 'next',
|
|
73
|
+
last: 'last'
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// The state classes get the "state" prefix
|
|
77
|
+
const states = ['selected', 'inView', 'dragging', 'playing', 'first', 'prev', 'current', 'next', 'last'];
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get the class names from the "classes" and "state" options.
|
|
81
|
+
*
|
|
82
|
+
* @param {string|object|null} classes A prefix, such as 'embla', or an object with the names to change. The default prefix is 'better'.
|
|
83
|
+
* The object can have a "prefix" key for the names that it does not change: { prefix: 'embla', selected: 'snapped' }.
|
|
84
|
+
* @param {string} state The prefix of the state classes.
|
|
85
|
+
* @returns {object}
|
|
86
|
+
*/
|
|
87
|
+
export function classNames(classes, state) {
|
|
88
|
+
const result = typeof classes === 'string' ? names(classes) : { ...names(classes?.prefix || 'better'), ...classes };
|
|
89
|
+
|
|
90
|
+
for (const key of states) {
|
|
91
|
+
if (result[key]) {
|
|
92
|
+
result[key] = state + result[key];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Merge the option sources. A later source wins. Objects such as "labels" merge one level deep.
|
|
101
|
+
*
|
|
102
|
+
* @param {...object} sources
|
|
103
|
+
* @returns {object}
|
|
104
|
+
*/
|
|
105
|
+
export function merge(...sources) {
|
|
106
|
+
const result = {};
|
|
107
|
+
|
|
108
|
+
for (const source of sources) {
|
|
109
|
+
for (const key in source) {
|
|
110
|
+
const value = source[key],
|
|
111
|
+
old = result[key];
|
|
112
|
+
result[key] = value && old && typeof value === 'object' && typeof old === 'object' && value.constructor === Object && old.constructor === Object ? { ...old, ...value } : value;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Get the options of an element: the library defaults, then the sources, then the JSON options of the data-carousel attribute.
|
|
121
|
+
*
|
|
122
|
+
* @param {HTMLElement} element
|
|
123
|
+
* @param {...object} sources The site defaults and the options of the call.
|
|
124
|
+
* @returns {object}
|
|
125
|
+
*/
|
|
126
|
+
export function resolve(element, ...sources) {
|
|
127
|
+
let data = {};
|
|
128
|
+
try {
|
|
129
|
+
data = JSON.parse(element.dataset.carousel || '{}');
|
|
130
|
+
} catch {
|
|
131
|
+
// The library ignores an attribute that is not valid JSON
|
|
132
|
+
}
|
|
133
|
+
return merge(defaults, ...sources, data);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Merge the options of the breakpoints whose media query matches, and watch the media queries.
|
|
138
|
+
*
|
|
139
|
+
* @param {object} base The options, with the "breakpoints" option.
|
|
140
|
+
* @param {() => void} change Called when a media query starts or stops to match.
|
|
141
|
+
* @returns {{options: object, remove: () => void}} The options, and a function that stops the watch.
|
|
142
|
+
*/
|
|
143
|
+
export function breakpoints(base, change) {
|
|
144
|
+
// Keep the key of each query: the browser can write MediaQueryList.media in a different form.
|
|
145
|
+
const list = Object.entries(base.breakpoints || {}).map(([query, value]) => [matchMedia(query), value]);
|
|
146
|
+
|
|
147
|
+
list.forEach(([query]) => query.addEventListener('change', change));
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
options: merge(base, ...list.filter(([query]) => query.matches).map(([, value]) => value)),
|
|
151
|
+
remove: () => list.forEach(([query]) => query.removeEventListener('change', change))
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
// The class prefix, the same as the "classes" option. The root class is the prefix.
|
|
2
|
+
$better: 'better' !default;
|
|
3
|
+
|
|
4
|
+
// The prefix of the state classes, the same as the "state" option
|
|
5
|
+
$better-state: '' !default;
|
|
6
|
+
|
|
7
|
+
// Add the look of the buttons and the dots
|
|
8
|
+
$better-look: true !default;
|
|
9
|
+
|
|
10
|
+
// The icon of the arrows, if the --button-arrow variable is not set
|
|
11
|
+
$better-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 12'%3E%3Cpath d='m1 1 5 5-5 5' fill='none' stroke='black' stroke-width='1.5'/%3E%3C/svg%3E") !default;
|
|
12
|
+
|
|
13
|
+
.#{$better} {
|
|
14
|
+
display: block;
|
|
15
|
+
position: relative;
|
|
16
|
+
|
|
17
|
+
// No "user-select" here: its change paints all layers of the carousel. The drag stops the text selection with script.
|
|
18
|
+
&.#{$better-state}dragging {
|
|
19
|
+
cursor: grabbing;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.#{$better}_viewport {
|
|
25
|
+
position: relative;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
width: 100%;
|
|
28
|
+
margin: 0;
|
|
29
|
+
z-index: 1;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.#{$better}_horizontal .#{$better}_container {
|
|
33
|
+
overflow: visible;
|
|
34
|
+
--gap-grid-y: 0px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.#{$better}_vertical {
|
|
38
|
+
|
|
39
|
+
.#{$better}_viewport {
|
|
40
|
+
height: 100%;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.#{$better}_container {
|
|
44
|
+
overflow: visible;
|
|
45
|
+
height: calc(100% + var(--gap-grid-y, 0px));
|
|
46
|
+
margin-bottom: calc(-1 * var(--gap-grid-y, 0px));
|
|
47
|
+
--gap-grid-x: 0px;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.#{$better}_auto_height {
|
|
53
|
+
|
|
54
|
+
.#{$better}_viewport {
|
|
55
|
+
transition: height 0.3s;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.#{$better}_container {
|
|
59
|
+
align-items: flex-start;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@if $better-look {
|
|
65
|
+
|
|
66
|
+
.#{$better}_button {
|
|
67
|
+
display: block;
|
|
68
|
+
position: absolute;
|
|
69
|
+
bottom: 0;
|
|
70
|
+
inset-inline-end: 0;
|
|
71
|
+
width: var(--height-button);
|
|
72
|
+
height: var(--height-button);
|
|
73
|
+
padding: 0;
|
|
74
|
+
border: 1px solid var(--button-border, #222);
|
|
75
|
+
border-radius: var(--radius-regular, 10px);
|
|
76
|
+
background-color: var(--button-base, #222);
|
|
77
|
+
color: var(--button-text, #fff);
|
|
78
|
+
transition: 0.2s;
|
|
79
|
+
cursor: pointer;
|
|
80
|
+
z-index: 5;
|
|
81
|
+
--height-button: 2.5rem;
|
|
82
|
+
|
|
83
|
+
&:focus-visible {
|
|
84
|
+
outline: 2px solid var(--button-border-active, #000);
|
|
85
|
+
outline-offset: 2px;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&:before {
|
|
89
|
+
content: '';
|
|
90
|
+
display: block;
|
|
91
|
+
position: absolute;
|
|
92
|
+
top: 50%;
|
|
93
|
+
left: 50%;
|
|
94
|
+
width: 0.5rem;
|
|
95
|
+
height: 0.75rem;
|
|
96
|
+
margin: -0.375rem 0 0 -0.25rem;
|
|
97
|
+
background-color: currentColor;
|
|
98
|
+
-webkit-mask: var(--button-arrow, #{$better-arrow}) 50% 50% no-repeat;
|
|
99
|
+
mask: var(--button-arrow, #{$better-arrow}) 50% 50% no-repeat;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@media (hover: hover) {
|
|
103
|
+
&:hover {
|
|
104
|
+
border-color: var(--button-border-active, #000);
|
|
105
|
+
background-color: var(--button-base-active, #000);
|
|
106
|
+
color: var(--button-text-active, #fff);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
&:disabled {
|
|
111
|
+
border-color: var(--button-border-disabled, #eee);
|
|
112
|
+
background-color: var(--button-base-disabled, #eee);
|
|
113
|
+
color: var(--button-text-disabled, #aaa);
|
|
114
|
+
cursor: default;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.#{$better}_prev {
|
|
120
|
+
inset-inline-start: 0;
|
|
121
|
+
inset-inline-end: auto;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// The arrow icon points to the right. It points to the left for the previous slide, and for the next slide in a right-to-left carousel.
|
|
125
|
+
.#{$better}_prev:dir(ltr):before,
|
|
126
|
+
.#{$better}_next:dir(rtl):before {
|
|
127
|
+
transform: scaleX(-1);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// The play and pause button of the autoplay and the auto scroll: a triangle, or two bars while it plays
|
|
131
|
+
.#{$better}_play {
|
|
132
|
+
inset-inline-start: calc(var(--height-button) + 0.5rem);
|
|
133
|
+
inset-inline-end: auto;
|
|
134
|
+
|
|
135
|
+
&:before {
|
|
136
|
+
width: 0.625rem;
|
|
137
|
+
margin-left: -0.3125rem;
|
|
138
|
+
-webkit-mask: none;
|
|
139
|
+
mask: none;
|
|
140
|
+
clip-path: polygon(0 0, 100% 50%, 0 100%);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.#{$better}.#{$better-state}playing .#{$better}_play:before {
|
|
146
|
+
background: linear-gradient(90deg, currentColor 35%, transparent 35% 65%, currentColor 65%);
|
|
147
|
+
clip-path: none;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// The dots: a window of 5 dots. The track of the dots slides with "translate", and the marker of the selected dot glides with "translate".
|
|
151
|
+
// Only these two elements animate. Each animation costs work on the main thread at its start and its end, so the dots change size at once.
|
|
152
|
+
.#{$better}_dots {
|
|
153
|
+
display: flex;
|
|
154
|
+
position: relative;
|
|
155
|
+
align-items: center;
|
|
156
|
+
width: 7.5rem;
|
|
157
|
+
height: var(--height-button);
|
|
158
|
+
margin: var(--gap-grid-y, 20px) auto 0;
|
|
159
|
+
overflow: hidden;
|
|
160
|
+
z-index: 3;
|
|
161
|
+
--height-button: 2.5rem;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.#{$better}_dot {
|
|
165
|
+
display: flex;
|
|
166
|
+
flex: none;
|
|
167
|
+
align-items: center;
|
|
168
|
+
justify-content: center;
|
|
169
|
+
width: 1.5rem;
|
|
170
|
+
height: 1.5rem;
|
|
171
|
+
padding: 0;
|
|
172
|
+
border: 0;
|
|
173
|
+
border-radius: 50%;
|
|
174
|
+
background: none;
|
|
175
|
+
color: var(--button-text-disabled, #767676);
|
|
176
|
+
// A color transition runs on the main thread. It runs only on hover: a select does not change the color of a dot.
|
|
177
|
+
transition: color 0.2s;
|
|
178
|
+
cursor: pointer;
|
|
179
|
+
|
|
180
|
+
// In the dot, because the window of the dots cuts what is outside
|
|
181
|
+
&:focus-visible {
|
|
182
|
+
outline: 2px solid var(--button-border-active, #000);
|
|
183
|
+
outline-offset: -2px;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
&:before {
|
|
187
|
+
content: '';
|
|
188
|
+
display: block;
|
|
189
|
+
width: 0.875rem;
|
|
190
|
+
height: 0.875rem;
|
|
191
|
+
border-radius: 50%;
|
|
192
|
+
background: currentColor;
|
|
193
|
+
transform: scale(0);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
&.#{$better-state}last:before,
|
|
197
|
+
&.#{$better-state}first:before {
|
|
198
|
+
transform: scale(0.333);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
&.#{$better-state}prev:before,
|
|
202
|
+
&.#{$better-state}next:before {
|
|
203
|
+
transform: scale(0.666);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// The marker covers the selected dot
|
|
207
|
+
&.#{$better-state}current:before {
|
|
208
|
+
transform: scale(1);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@media (hover: hover) {
|
|
212
|
+
&:hover {
|
|
213
|
+
color: var(--button-base-active, #000);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.#{$better}_dots_track {
|
|
220
|
+
display: flex;
|
|
221
|
+
position: relative;
|
|
222
|
+
flex: none;
|
|
223
|
+
translate: calc(var(--better-shift, 0) * 1.5rem);
|
|
224
|
+
transition: translate 0.4s;
|
|
225
|
+
|
|
226
|
+
// In a right-to-left carousel, the first dot is at the right
|
|
227
|
+
&:dir(rtl) {
|
|
228
|
+
translate: calc(var(--better-shift, 0) * -1.5rem);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// The selected dot, on top of the dots, also if the CSS of the site positions the buttons. It does not get the clicks.
|
|
234
|
+
.#{$better}_dots_marker {
|
|
235
|
+
position: absolute;
|
|
236
|
+
z-index: 1;
|
|
237
|
+
top: 0.3125rem;
|
|
238
|
+
inset-inline-start: 0.3125rem;
|
|
239
|
+
width: 0.875rem;
|
|
240
|
+
height: 0.875rem;
|
|
241
|
+
border-radius: 50%;
|
|
242
|
+
background: var(--button-base, #222);
|
|
243
|
+
translate: calc(var(--better-dot, 0) * 1.5rem);
|
|
244
|
+
transition: translate 0.4s;
|
|
245
|
+
pointer-events: none;
|
|
246
|
+
|
|
247
|
+
&:dir(rtl) {
|
|
248
|
+
translate: calc(var(--better-dot, 0) * -1.5rem);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// dotsStyle: 'all'. All dots show with the same size, and the track does not slide.
|
|
254
|
+
.#{$better}_dots.#{$better}_dots_all {
|
|
255
|
+
width: max-content;
|
|
256
|
+
max-width: 100%;
|
|
257
|
+
|
|
258
|
+
.#{$better}_dots_track {
|
|
259
|
+
translate: none;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.#{$better}_dot:before {
|
|
263
|
+
transform: scale(0.666);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.#{$better}_vertical {
|
|
269
|
+
|
|
270
|
+
.#{$better}_button {
|
|
271
|
+
top: auto;
|
|
272
|
+
right: 0;
|
|
273
|
+
bottom: 0;
|
|
274
|
+
left: 0;
|
|
275
|
+
width: auto;
|
|
276
|
+
height: 30px;
|
|
277
|
+
margin: 0;
|
|
278
|
+
|
|
279
|
+
&:before {
|
|
280
|
+
transform: rotate(90deg);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
.#{$better}_prev {
|
|
286
|
+
top: 0;
|
|
287
|
+
bottom: auto;
|
|
288
|
+
|
|
289
|
+
&:before {
|
|
290
|
+
transform: rotate(-90deg);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// One column of dots on the right side, in the middle of the carousel height
|
|
296
|
+
.#{$better}_dots {
|
|
297
|
+
position: absolute;
|
|
298
|
+
top: 50%;
|
|
299
|
+
right: 0;
|
|
300
|
+
flex-direction: column;
|
|
301
|
+
width: var(--height-button);
|
|
302
|
+
height: 7.5rem;
|
|
303
|
+
margin: 0;
|
|
304
|
+
transform: translateY(-50%);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.#{$better}_dots_track {
|
|
308
|
+
flex-direction: column;
|
|
309
|
+
translate: 0 calc(var(--better-shift, 0) * 1.5rem);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.#{$better}_dots_marker {
|
|
313
|
+
translate: 0 calc(var(--better-dot, 0) * 1.5rem);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
.#{$better}_dots_all {
|
|
317
|
+
height: auto;
|
|
318
|
+
max-height: 100%;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
}
|