@graupl/graupl 1.0.0-alpha.13 → 1.0.0-alpha.15

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.
Files changed (143) hide show
  1. package/.github/workflows/codeql-analysis.yml +3 -3
  2. package/.husky/commit-msg +0 -1
  3. package/.husky/pre-commit +0 -1
  4. package/CHANGELOG.md +38 -0
  5. package/dist/base/button.css +1 -1
  6. package/dist/base/button.css.map +1 -1
  7. package/dist/base/form.css.map +1 -1
  8. package/dist/base/link.css.map +1 -1
  9. package/dist/base/table.css.map +1 -1
  10. package/dist/base.css +1 -1
  11. package/dist/base.css.map +1 -1
  12. package/dist/component/alert.css +2 -0
  13. package/dist/component/alert.css.map +1 -0
  14. package/dist/component/card.css +1 -1
  15. package/dist/component/card.css.map +1 -1
  16. package/dist/component/carousel.css +2 -0
  17. package/dist/component/carousel.css.map +1 -0
  18. package/dist/component/input-group.css.map +1 -1
  19. package/dist/component/menu.css +1 -1
  20. package/dist/component/menu.css.map +1 -1
  21. package/dist/component/navigation.css.map +1 -1
  22. package/dist/component.css +1 -1
  23. package/dist/component.css.map +1 -1
  24. package/dist/graupl.css +1 -1
  25. package/dist/graupl.css.map +1 -1
  26. package/dist/layout/columns.css.map +1 -1
  27. package/dist/layout/container.css.map +1 -1
  28. package/dist/layout/flex-columns.css.map +1 -1
  29. package/dist/layout.css +1 -1
  30. package/dist/layout.css.map +1 -1
  31. package/dist/normalize.css.map +1 -1
  32. package/dist/state/focus.css.map +1 -1
  33. package/dist/state.css.map +1 -1
  34. package/dist/theme/color.css.map +1 -1
  35. package/dist/theme/typography.css.map +1 -1
  36. package/dist/theme.css.map +1 -1
  37. package/dist/utilities/alignment.css.map +1 -1
  38. package/dist/utilities/color.css.map +1 -1
  39. package/dist/utilities/display.css +1 -1
  40. package/dist/utilities/display.css.map +1 -1
  41. package/dist/utilities/flex.css.map +1 -1
  42. package/dist/utilities/height.css +2 -0
  43. package/dist/utilities/height.css.map +1 -0
  44. package/dist/utilities/inset.css.map +1 -1
  45. package/dist/utilities/justification.css.map +1 -1
  46. package/dist/utilities/list.css.map +1 -1
  47. package/dist/utilities/order.css.map +1 -1
  48. package/dist/utilities/postion.css.map +1 -1
  49. package/dist/utilities/spacing.css.map +1 -1
  50. package/dist/utilities/typography.css.map +1 -1
  51. package/dist/utilities/visibility.css.map +1 -1
  52. package/dist/utilities/width.css +2 -0
  53. package/dist/utilities/width.css.map +1 -0
  54. package/dist/utilities.css +1 -1
  55. package/dist/utilities.css.map +1 -1
  56. package/docs/.vitepress/config.js +39 -12
  57. package/docs/components/alert.md +130 -0
  58. package/docs/components/button.md +84 -0
  59. package/docs/components/card.md +369 -0
  60. package/docs/components/index.md +1 -0
  61. package/docs/components/inputgroup.md +159 -0
  62. package/docs/components/menu.md +326 -0
  63. package/docs/components/navigation.md +158 -0
  64. package/docs/content.md +237 -0
  65. package/docs/defaults.md +121 -0
  66. package/docs/forms.md +79 -0
  67. package/docs/functions.md +9 -0
  68. package/docs/getting-started.md +1 -0
  69. package/docs/index.md +1 -7
  70. package/docs/introduction.md +22 -2
  71. package/docs/layout.md +200 -0
  72. package/docs/mixins.md +47 -0
  73. package/docs/state.md +67 -0
  74. package/docs/theme.md +258 -0
  75. package/docs/utilities.md +357 -0
  76. package/index.html +178 -37
  77. package/package.json +5 -6
  78. package/scss/component/alert.scss +3 -0
  79. package/scss/component/carousel.scss +3 -0
  80. package/scss/utilities/height.scss +3 -0
  81. package/scss/utilities/width.scss +3 -0
  82. package/src/js/alert/Alert.js +511 -0
  83. package/src/js/alert/index.js +21 -0
  84. package/src/js/carousel/Carousel.js +1376 -0
  85. package/src/js/carousel/index.js +20 -0
  86. package/src/js/domHelpers.js +37 -0
  87. package/src/js/eventHandlers.js +32 -0
  88. package/src/js/validate.js +225 -0
  89. package/src/scss/base/_index.scss +1 -1
  90. package/src/scss/base/button/_defaults.scss +7 -0
  91. package/src/scss/base/button/_index.scss +46 -149
  92. package/src/scss/base/button/_mixins.scss +164 -0
  93. package/src/scss/base/form/_index.scss +1 -1
  94. package/src/scss/base/link/_index.scss +1 -1
  95. package/src/scss/base/table/_index.scss +1 -1
  96. package/src/scss/component/_index.scss +3 -1
  97. package/src/scss/component/alert/_defaults.scss +49 -0
  98. package/src/scss/component/alert/_index.scss +118 -0
  99. package/src/scss/component/alert/_variables.scss +170 -0
  100. package/src/scss/component/card/_defaults.scss +3 -0
  101. package/src/scss/component/card/_index.scss +43 -9
  102. package/src/scss/component/carousel/_defaults.scss +43 -0
  103. package/src/scss/component/carousel/_index.scss +182 -0
  104. package/src/scss/component/carousel/_variables.scss +104 -0
  105. package/src/scss/component/input-group/_index.scss +1 -1
  106. package/src/scss/component/menu/_defaults.scss +2 -1
  107. package/src/scss/component/menu/_index.scss +2 -1
  108. package/src/scss/component/menu/_variables.scss +4 -0
  109. package/src/scss/component/navigation/_index.scss +1 -1
  110. package/src/scss/layout/_index.scss +1 -1
  111. package/src/scss/layout/columns/_index.scss +1 -1
  112. package/src/scss/layout/container/_index.scss +1 -1
  113. package/src/scss/layout/flex-columns/_index.scss +1 -1
  114. package/src/scss/mixins/_layer.scss +2 -4
  115. package/src/scss/mixins/_visually-hidden.scss +20 -0
  116. package/src/scss/state/_index.scss +1 -1
  117. package/src/scss/state/focus/_index.scss +1 -1
  118. package/src/scss/theme/_index.scss +1 -1
  119. package/src/scss/theme/color/_index.scss +1 -1
  120. package/src/scss/theme/typography/_index.scss +1 -1
  121. package/src/scss/utilities/_index.scss +3 -1
  122. package/src/scss/utilities/alignment/_index.scss +1 -1
  123. package/src/scss/utilities/color/_index.scss +1 -1
  124. package/src/scss/utilities/display/_defaults.scss +2 -0
  125. package/src/scss/utilities/display/_index.scss +11 -1
  126. package/src/scss/utilities/flex/_index.scss +1 -1
  127. package/src/scss/utilities/height/_defaults.scss +38 -0
  128. package/src/scss/utilities/height/_index.scss +23 -0
  129. package/src/scss/utilities/height/_variables.scss +6 -0
  130. package/src/scss/utilities/inset/_index.scss +1 -1
  131. package/src/scss/utilities/justification/_index.scss +1 -1
  132. package/src/scss/utilities/list/_index.scss +1 -1
  133. package/src/scss/utilities/order/_index.scss +1 -1
  134. package/src/scss/utilities/position/_index.scss +1 -1
  135. package/src/scss/utilities/ratio/_defaults.scss +1 -0
  136. package/src/scss/utilities/ratio/_index.scss +9 -1
  137. package/src/scss/utilities/spacing/_index.scss +1 -1
  138. package/src/scss/utilities/typography/_index.scss +1 -1
  139. package/src/scss/utilities/visibility/_index.scss +1 -1
  140. package/src/scss/utilities/width/_defaults.scss +38 -0
  141. package/src/scss/utilities/width/_index.scss +23 -0
  142. package/src/scss/utilities/width/_variables.scss +6 -0
  143. package/stylelint.config.js +5 -0
@@ -0,0 +1,1376 @@
1
+ /**
2
+ * @file
3
+ * The carousel class.
4
+ */
5
+
6
+ import { addClass, removeClass } from "../domHelpers.js";
7
+ import { preventEvent, keyPress } from "../eventHandlers.js";
8
+ import {
9
+ isQuerySelector,
10
+ isTag,
11
+ isValidClassList,
12
+ isValidInstance,
13
+ isValidType,
14
+ } from "../validate.js";
15
+
16
+ class Carousel {
17
+ /**
18
+ * The DOM elements within the carousel.
19
+ *
20
+ * @protected
21
+ *
22
+ * @type {Object<HTMLElement, HTMLElement[]>}
23
+ *
24
+ * @property {HTMLElement} carousel - The carousel element.
25
+ * @property {HTMLElement[]} carouselItems - The carousel items.
26
+ * @property {HTMLElement} carouselItemContainer - The carousel item container.
27
+ * @property {HTMLElement[]} carouselControls - The carousel controls.
28
+ * @property {HTMLElement} carouselControlContainer - The carousel control container.
29
+ * @property {HTMLElement[]} carouselTabs - The carousel tabs.
30
+ * @property {HTMLElement} carouselTabContainer - The carousel tab container.
31
+ * @property {HTMLElement} autoplay - The autoplay button.
32
+ * @property {HTMLElement} next - The next button.
33
+ * @property {HTMLElement} previous - The previous button.
34
+ */
35
+ _dom = {
36
+ carousel: null,
37
+ carouselItems: [],
38
+ carouselItemContainer: null,
39
+ carouselControls: [],
40
+ carouselControlContainer: null,
41
+ carouselTabs: [],
42
+ carouselTabContainer: null,
43
+ autoplay: null,
44
+ next: null,
45
+ previous: null,
46
+ };
47
+
48
+ /**
49
+ * The query selectors used by the carousel to populate the dom.
50
+ *
51
+ * @protected
52
+ *
53
+ * @type {Object<string>}
54
+ *
55
+ * @property {string} carouselItems - The query selector string for carousel items.
56
+ * @property {string} carouselItemContainer - The query selector string for the carousel item container.
57
+ * @property {string} carouselControls - The query selector string for carousel controls.
58
+ * @property {string} carouselControlContainer - The query selector string for carousel control container.
59
+ * @property {string} carouselTabs - The query selector string for the carousel tabs.
60
+ * @property {string} carouselTabContainer - The query selector string for the carousel tab container.
61
+ * @property {string} autoplay - The query selector string for the autoplay button.
62
+ * @property {string} next - The query selector string for the next button.
63
+ * @property {string} previous - The query selector string for the previous button.
64
+ */
65
+ _selectors = {
66
+ carouselItems: "",
67
+ carouselItemContainer: "",
68
+ carouselControls: "",
69
+ carouselControlContainer: "",
70
+ carouselTabs: "",
71
+ carouselTabContainer: "",
72
+ autoplay: "",
73
+ next: "",
74
+ previous: "",
75
+ };
76
+
77
+ /**
78
+ * The class(es) to apply when a carousel item is active.
79
+ *
80
+ * @protected
81
+ *
82
+ * @type {string|string[]}
83
+ */
84
+ _activeClass = "active";
85
+
86
+ /**
87
+ * The class(es) to apply to a carousel item that is the previously active item.
88
+ *
89
+ * @protected
90
+ *
91
+ * @type {string|string[]}
92
+ */
93
+ _previousClass = "previous";
94
+
95
+ /**
96
+ * The class(es) to apply to a carousel item that is the next active item.
97
+ *
98
+ * @protected
99
+ *
100
+ * @type {string|string[]}
101
+ */
102
+ _nextClass = "next";
103
+
104
+ /**
105
+ * The class(es) to apply to the autoplay button when the carousel is paused.
106
+ *
107
+ * @protected
108
+ *
109
+ * @type {string|string[]}
110
+ */
111
+ _playClass = "play";
112
+
113
+ /**
114
+ * The class(es) to apply to the autoplay button when the carousel is playing.
115
+ *
116
+ * @protected
117
+ *
118
+ * @type {string|string[]}
119
+ */
120
+ _pauseClass = "pause";
121
+
122
+ /**
123
+ * The index of the currently active carousel item.
124
+ *
125
+ * @protected
126
+ *
127
+ * @type {number}
128
+ */
129
+ _currentItem = 0;
130
+
131
+ /**
132
+ * A flag to indicate if the carousel is currently playing.
133
+ *
134
+ * @protected
135
+ *
136
+ * @type {boolean}
137
+ */
138
+ _autoplay = true;
139
+
140
+ /**
141
+ * A variable to delay transition slides in milliseconds.
142
+ *
143
+ * @protected
144
+ *
145
+ * @type {number}
146
+ */
147
+ _transitionDelay = 10000;
148
+
149
+ /**
150
+ * The duration time (in milliseconds) for the transition between carousel items.
151
+ *
152
+ * @protected
153
+ *
154
+ * @type {number}
155
+ */
156
+ _transitionDuration = 500;
157
+
158
+ /**
159
+ * The label for the autoplay button when the carousel is paused.
160
+ *
161
+ * @protected
162
+ *
163
+ * @type {string}
164
+ */
165
+ _playText = "Play";
166
+
167
+ /**
168
+ * The label for the autoplay button when the carousel is playing.
169
+ *
170
+ * @protected
171
+ *
172
+ * @type {string}
173
+ */
174
+ _pauseText = "Pause";
175
+
176
+ /**
177
+ * The current action being performed by the carousel.
178
+ *
179
+ * @protected
180
+ *
181
+ * @type {string}
182
+ */
183
+ _currentAction = "next";
184
+
185
+ /**
186
+ * The stored interval callback for autoplaying the carousel.
187
+ *
188
+ * @protected
189
+ *
190
+ * @type {?Function}
191
+ */
192
+ _autoplayInterval = null;
193
+
194
+ /**
195
+ * The prefix to use for CSS custom properties.
196
+ *
197
+ * @protected
198
+ *
199
+ * @type {string}
200
+ */
201
+ _prefix = "graupl-";
202
+
203
+ /**
204
+ * An array of error messages generated by the carousel.
205
+ *
206
+ * @protected
207
+ *
208
+ * @type {string[]}
209
+ */
210
+ _errors = [];
211
+
212
+ /**
213
+ * Contructs a new `Carousel`.
214
+ *
215
+ * @param {object} options - The options for the generated carousel.
216
+ * @param {HTMLElement} options.carouselElement - The carousel element in the DOM.
217
+ * @param {string} [options.carouselItemSelector = .carousel-item] - The query selector string for carousel items.
218
+ * @param {string} [options.carouselItemContainerSelector = .carousel-item-container] - The query selector string for the carousel item container.
219
+ * @param {string} [options.carouselControlSelector = .carousel-control] - The query selector string for carousel controls.
220
+ * @param {string} [options.carouselControlContainerSelector = .carousel-control-container] - The query selector string for carousel control container.
221
+ * @param {string} [options.carouselTabSelector = .carousel-tab] - The query selector string for carousel tabs.
222
+ * @param {string} [options.carouselTabContainerSelector = .carousel-tab-container] - The query selector string for the carousel tab container.
223
+ * @param {string} [options.autoplaySelector = .autoplay] - The query selector string for the autoplay button.
224
+ * @param {string} [options.nextSelector = .next] - The query selector string for the next button.
225
+ * @param {string} [options.previousSelector = .previous] - The query selector string for the previous button.
226
+ * @param {?(string|string[])} [options.activeClass = active] - The class(es) to apply when a carousel item is active.
227
+ * @param {?(string|string[])} [options.previousClass = previous] - The class(es) to apply to a carousel item that is the previously active item.
228
+ * @param {?(string|string[])} [options.nextClass = next] - The class(es) to apply to a carousel item that is the next active item.
229
+ * @param {?(string|string[])} [options.playClass = play] - The class(es) to apply to the autoplay button when the carousel is paused.
230
+ * @param {?(string|string[])} [options.pauseClass = pause] - The class(es) to apply to the autoplay button when the carousel is playing.
231
+ * @param {boolean} [options.autoplay = true] - A flag to indicate if the carousel should autoplay.
232
+ * @param {number} [options.transitionDelay = 10000] - A flag to initialize the carousel immediately upon creation.
233
+ * @param {number} [options.transitionDuration = 500] - The duration time (in milliseconds) for the transition between carousel items.
234
+ * @param {?string} [options.playText = Play] - The text to use for the play button.
235
+ * @param {?string} [options.pauseText = Pause] - The text to use for the pause button.
236
+ * @param {?string} [options.prefix = graupl-] - The prefix to use for CSS custom properties.
237
+ * @param {boolean} [options.initialize = false] - A flag to initialize the carousel immediately upon creation.
238
+ */
239
+ constructor({
240
+ carouselElement,
241
+ carouselItemSelector = ".carousel-item",
242
+ carouselItemContainerSelector = ".carousel-item-container",
243
+ carouselControlSelector = ".carousel-control",
244
+ carouselControlContainerSelector = ".carousel-control-container",
245
+ carouselTabSelector = ".carousel-tab",
246
+ carouselTabContainerSelector = ".carousel-tab-container",
247
+ autoplaySelector = ".autoplay",
248
+ nextSelector = ".next",
249
+ previousSelector = ".previous",
250
+ activeClass = "active",
251
+ previousClass = "previous",
252
+ nextClass = "next",
253
+ playClass = "play",
254
+ pauseClass = "pause",
255
+ autoplay = true,
256
+ transitionDelay = 10000,
257
+ transitionDuration = 500,
258
+ playText = "Play",
259
+ pauseText = "Pause",
260
+ prefix = "graupl-",
261
+ initialize = false,
262
+ }) {
263
+ // Set DOM elements.
264
+ this._dom.carousel = carouselElement;
265
+
266
+ // Set query selectors.
267
+ this._selectors.carouselItems = carouselItemSelector;
268
+ this._selectors.carouselItemContainer = carouselItemContainerSelector;
269
+ this._selectors.carouselControls = carouselControlSelector;
270
+ this._selectors.carouselControlContainer = carouselControlContainerSelector;
271
+ this._selectors.carouselTabs = carouselTabSelector;
272
+ this._selectors.carouselTabContainer = carouselTabContainerSelector;
273
+ this._selectors.autoplay = autoplaySelector;
274
+ this._selectors.next = nextSelector;
275
+ this._selectors.previous = previousSelector;
276
+
277
+ // Set class names.
278
+ this._activeClass = activeClass || "";
279
+ this._previousClass = previousClass || "";
280
+ this._nextClass = nextClass || "";
281
+ this._playClass = playClass || "";
282
+ this._pauseClass = pauseClass || "";
283
+
284
+ // Set flags.
285
+ this._autoplay = autoplay;
286
+
287
+ // Set transition options.
288
+ this._transitionDelay = transitionDelay;
289
+ this._transitionDuration = transitionDuration;
290
+
291
+ // Set labels.
292
+ this._playText = playText || "";
293
+ this._pauseText = pauseText || "";
294
+
295
+ // Set prefix.
296
+ this._prefix = prefix || "";
297
+
298
+ if (initialize) {
299
+ this.initialize();
300
+ }
301
+ }
302
+
303
+ /**
304
+ * Initializes the carousel.
305
+ */
306
+ initialize() {
307
+ try {
308
+ if (!this._validate()) {
309
+ throw new Error(
310
+ `Graupl Carousel: cannot initialize carousel. The following errors have been found:\n - ${this.errors.join(
311
+ "\n - "
312
+ )}`
313
+ );
314
+ }
315
+
316
+ // Set DOM elements.
317
+ this._setDOMElements();
318
+
319
+ // Set ids.
320
+ this._setIds();
321
+
322
+ // Set aria attributes.
323
+ this._setAriaAttributes();
324
+
325
+ // Activate the first item.
326
+ this.activateFirstItem();
327
+
328
+ // Set the custom props.
329
+ this._setTransitionDuration();
330
+
331
+ // Handle events.
332
+ this._handleAutoplay();
333
+ this._handleFocus();
334
+ this._handleClick();
335
+ this._handleHover();
336
+ this._handleKeydown();
337
+ this._handleKeyup();
338
+ } catch (error) {
339
+ console.error(error);
340
+ }
341
+ }
342
+
343
+ /**
344
+ * The HTML elements for the carousel in the DOM.
345
+ *
346
+ * @readonly
347
+ *
348
+ * @type {Object<HTMLElement>}
349
+ *
350
+ * @see _dom
351
+ */
352
+ get dom() {
353
+ return this._dom;
354
+ }
355
+
356
+ /**
357
+ * The query selectors used by the carousel to populate the dom.
358
+ *
359
+ * @readonly
360
+ *
361
+ * @type {Object<string>}
362
+ *
363
+ * @see _selectors
364
+ */
365
+ get selectors() {
366
+ return this._selectors;
367
+ }
368
+
369
+ /**
370
+ * The class(es) to apply when a carousel item is active.
371
+ *
372
+ * @type {string|string[]}
373
+ *
374
+ * @see _activeClass
375
+ */
376
+ get activeClass() {
377
+ return this._activeClass;
378
+ }
379
+
380
+ /**
381
+ * The class(es) to apply to a carousel item that is the next active item.
382
+ *
383
+ * @type {string|string[]}
384
+ *
385
+ * @see _previousClass
386
+ */
387
+ get previousClass() {
388
+ return this._previousClass;
389
+ }
390
+
391
+ /**
392
+ * The class(es) to apply to a carousel item that is the next active item.
393
+ *
394
+ * @type {string|string[]}
395
+ *
396
+ * @see _nextClass
397
+ */
398
+ get nextClass() {
399
+ return this._nextClass;
400
+ }
401
+
402
+ /**
403
+ * The class(es) to apply to the autoplay button when the carousel is paused.
404
+ *
405
+ * @type {string|string[]}
406
+ *
407
+ * @see _playClass
408
+ */
409
+ get playClass() {
410
+ return this._playClass;
411
+ }
412
+
413
+ /**
414
+ * The class(es) to apply to the autoplay button when the carousel is playing.
415
+ *
416
+ * @type {string|string[]}
417
+ *
418
+ * @see _pauseClass
419
+ */
420
+ get pauseClass() {
421
+ return this._pauseClass;
422
+ }
423
+
424
+ /**
425
+ * The index of the currently active carousel item.
426
+ *
427
+ * @type {number}
428
+ *
429
+ * @see _currentItem
430
+ */
431
+ get currentItem() {
432
+ return this._currentItem;
433
+ }
434
+
435
+ /**
436
+ * The currently active carousel item.
437
+ *
438
+ * @readonly
439
+ *
440
+ * @type {HTMLElement}
441
+ */
442
+ get currentCarouselItem() {
443
+ return this.dom.carouselItems[this.currentItem];
444
+ }
445
+
446
+ /**
447
+ * The currently active carousel tab.
448
+ *
449
+ * @readonly
450
+ *
451
+ * @type {HTMLElement}
452
+ */
453
+ get currentCarouselTab() {
454
+ return this.dom.carouselTabs[this.currentItem];
455
+ }
456
+
457
+ /**
458
+ * A flag to indicate if the carousel is currently playing.
459
+ *
460
+ * @type {boolean}
461
+ *
462
+ * @see _autoplay
463
+ */
464
+ get autoplay() {
465
+ return this._autoplay;
466
+ }
467
+
468
+ /**
469
+ * The delay in milliseconds before transitioning slides.
470
+ *
471
+ * @type {number}
472
+ *
473
+ * @see _transitionDelay
474
+ */
475
+ get transitionDelay() {
476
+ return this._transitionDelay;
477
+ }
478
+
479
+ /**
480
+ * The duration time (in milliseconds) for the transition between carousel items.
481
+ *
482
+ * @type {number}
483
+ *
484
+ * @see _transitionDuration
485
+ */
486
+ get transitionDuration() {
487
+ return this._transitionDuration;
488
+ }
489
+
490
+ /**
491
+ * The label for the autoplay button when the carousel is paused.
492
+ *
493
+ * @type {string}
494
+ *
495
+ * @see _playText
496
+ */
497
+ get playText() {
498
+ return this._playText;
499
+ }
500
+
501
+ /**
502
+ * The label for the autoplay button when the carousel is playing.
503
+ *
504
+ * @type {string}
505
+ *
506
+ * @see _pauseText
507
+ */
508
+ get pauseText() {
509
+ return this._pauseText;
510
+ }
511
+
512
+ /**
513
+ * The prefix to use for CSS custom properties.
514
+ *
515
+ * @type {string}
516
+ *
517
+ * @see _prefix
518
+ */
519
+ get prefix() {
520
+ return this._prefix;
521
+ }
522
+
523
+ /**
524
+ * The current action being performed by the carousel.
525
+ *
526
+ * @type {string}
527
+ *
528
+ * @see _currentAction
529
+ */
530
+ get currentAction() {
531
+ return this._currentAction;
532
+ }
533
+
534
+ /**
535
+ * An array of error messages generated by the carousel.
536
+ *
537
+ * @readonly
538
+ *
539
+ * @type {string[]}
540
+ *
541
+ * @see _errors
542
+ */
543
+ get errors() {
544
+ return this._errors;
545
+ }
546
+
547
+ set currentItem(value) {
548
+ isValidType("number", { value });
549
+
550
+ if (value === this.currentItem) {
551
+ return;
552
+ }
553
+
554
+ if (value < 0) {
555
+ this._currentItem = 0;
556
+ } else if (value >= this.dom.carouselItems.length) {
557
+ this._currentItem = this.dom.carouselItems.length - 1;
558
+ } else {
559
+ this._currentItem = value;
560
+ }
561
+
562
+ // Keep the aria selected in sync with the current item.
563
+ const tabs = this._dom.carousel.querySelectorAll(
564
+ this.selectors.carouselTab
565
+ );
566
+ if (tabs) {
567
+ this.dom.carouselItems.forEach((item, index) => {
568
+ item.setAttribute("aria-selected", index === this._currentItem);
569
+ });
570
+ }
571
+ }
572
+
573
+ set autoplay(value) {
574
+ isValidType("boolean", { value });
575
+
576
+ if (this._autoplay !== value) {
577
+ this._autoplay = value;
578
+ }
579
+ }
580
+
581
+ set activeClass(value) {
582
+ isValidClassList({ activeClass: value });
583
+
584
+ if (this._activeClass !== value) {
585
+ this._activeClass = value;
586
+ }
587
+ }
588
+
589
+ set previousClass(value) {
590
+ isValidClassList({ previousClass: value });
591
+
592
+ if (this._previousClass !== value) {
593
+ this._previousClass = value;
594
+ }
595
+ }
596
+
597
+ set nextClass(value) {
598
+ isValidClassList({ nextClass: value });
599
+
600
+ if (this._nextClass !== value) {
601
+ this._nextClass = value;
602
+ }
603
+ }
604
+
605
+ set playClass(value) {
606
+ isValidClassList({ playClass: value });
607
+
608
+ if (this._playClass !== value) {
609
+ this._playClass = value;
610
+ }
611
+ }
612
+
613
+ set pauseClass(value) {
614
+ isValidClassList({ pauseClass: value });
615
+
616
+ if (this._pauseClass !== value) {
617
+ this._pauseClass = value;
618
+ }
619
+ }
620
+
621
+ set transitionDelay(value) {
622
+ isValidType("number", { value });
623
+
624
+ if (value !== this.transitionDelay && value >= 0) {
625
+ this._currentItem = value;
626
+ }
627
+ }
628
+
629
+ set transitionDuration(value) {
630
+ isValidType("number", { value });
631
+
632
+ if (this._transitionDuration !== value && value >= 0) {
633
+ this._transitionDuration = value;
634
+ this._setTransitionDuration();
635
+ }
636
+ }
637
+
638
+ set playText(value) {
639
+ isValidType("string", { value });
640
+
641
+ if (this._playText !== value) {
642
+ this._playText = value;
643
+ }
644
+ }
645
+
646
+ set pauseText(value) {
647
+ isValidType("string", { value });
648
+
649
+ if (this._pauseText !== value) {
650
+ this._pauseText = value;
651
+ }
652
+ }
653
+
654
+ set prefix(value) {
655
+ isValidType("string", { value });
656
+
657
+ if (this._prefix !== value) {
658
+ this._prefix = value;
659
+ }
660
+ }
661
+
662
+ /**
663
+ * Validates all aspects of the carousel to ensure proper functionality.
664
+ *
665
+ * @protected
666
+ *
667
+ * @return {boolean} - The results of the validation.
668
+ */
669
+ _validate() {
670
+ let check = true;
671
+
672
+ // HTML element checks.
673
+ const htmlElementChecks = isValidInstance(HTMLElement, {
674
+ carousel: this.dom.carousel,
675
+ });
676
+
677
+ if (!htmlElementChecks) {
678
+ this._errors.push(htmlElementChecks.message);
679
+ check = false;
680
+ }
681
+
682
+ // Query selector checks.
683
+ const querySelectorChecks = isQuerySelector({
684
+ carouselItemsSelector: this._selectors.carouselItems,
685
+ carouselItemContainerSelector: this._selectors.carouselItemContainer,
686
+ carouselControlsSelector: this._selectors.carouselControls,
687
+ carouselControlContainerSelector:
688
+ this._selectors.carouselControlContainer,
689
+ carouselTabsSelector: this._selectors.carouselTabs,
690
+ carouselTabContainerSelector: this._selectors.carouselTabContainer,
691
+ autoplaySelector: this._selectors.autoplay,
692
+ nextSelector: this._selectors.next,
693
+ previousSelector: this._selectors.previous,
694
+ });
695
+
696
+ if (!querySelectorChecks) {
697
+ this._errors.push(querySelectorChecks.message);
698
+ check = false;
699
+ }
700
+
701
+ // Autoplay checks.
702
+ const autoplayChecks = isValidType("boolean", { autoplay: this.autoplay });
703
+
704
+ if (!autoplayChecks) {
705
+ this._errors.push(autoplayChecks.message);
706
+ check = false;
707
+ }
708
+
709
+ // Check delay is a valid value.
710
+ const delayCheck = isValidType("number", {
711
+ transitionDelay: this._transitionDelay,
712
+ });
713
+
714
+ if (!delayCheck) {
715
+ this._errors.push(delayCheck.message);
716
+ check = false;
717
+ }
718
+
719
+ // Check duration is a valid value.
720
+ const durationCheck = isValidType("number", {
721
+ transitionDuration: this._transitionDuration,
722
+ });
723
+
724
+ if (!durationCheck) {
725
+ this._errors.push(durationCheck.message);
726
+ check = false;
727
+ }
728
+
729
+ // Active class checks.
730
+ if (this._activeClass !== "") {
731
+ const activeClassChecks = isValidClassList({
732
+ activeClass: this._activeClass,
733
+ });
734
+
735
+ if (!activeClassChecks) {
736
+ this._errors.push(activeClassChecks.message);
737
+ check = false;
738
+ }
739
+ }
740
+
741
+ // Previous class checks.
742
+ if (this._previousClass !== "") {
743
+ const previousClassChecks = isValidClassList({
744
+ previousClass: this._previousClass,
745
+ });
746
+
747
+ if (!previousClassChecks) {
748
+ this._errors.push(previousClassChecks.message);
749
+ check = false;
750
+ }
751
+ }
752
+
753
+ // Next class checks.
754
+ if (this._nextClass !== "") {
755
+ const nextClassChecks = isValidClassList({
756
+ nextClass: this._nextClass,
757
+ });
758
+
759
+ if (!nextClassChecks) {
760
+ this._errors.push(nextClassChecks.message);
761
+ check = false;
762
+ }
763
+ }
764
+
765
+ // Play class checks.
766
+ if (this._playClass !== "") {
767
+ const playClassChecks = isValidClassList({
768
+ playClass: this._playClass,
769
+ });
770
+
771
+ if (!playClassChecks) {
772
+ this._errors.push(playClassChecks.message);
773
+ check = false;
774
+ }
775
+ }
776
+
777
+ // Pause class checks.
778
+ if (this._pauseClass !== "") {
779
+ const pauseClassChecks = isValidClassList({
780
+ pauseClass: this._pauseClass,
781
+ });
782
+
783
+ if (!pauseClassChecks) {
784
+ this._errors.push(pauseClassChecks.message);
785
+ check = false;
786
+ }
787
+ }
788
+
789
+ // Play text checks.
790
+ if (this._playText !== "") {
791
+ const playTextChecks = isValidType("string", {
792
+ playText: this._playText,
793
+ });
794
+
795
+ if (!playTextChecks) {
796
+ this._errors.push(playTextChecks.message);
797
+ check = false;
798
+ }
799
+ }
800
+
801
+ // Pause text checks.
802
+ if (this._pauseText !== "") {
803
+ const pauseTextChecks = isValidType("string", {
804
+ pauseText: this._pauseText,
805
+ });
806
+
807
+ if (!pauseTextChecks) {
808
+ this._errors.push(pauseTextChecks.message);
809
+ check = false;
810
+ }
811
+ }
812
+
813
+ // Prefix checks.
814
+ const prefixChecks = isValidType("string", { prefix: this._prefix });
815
+
816
+ if (!prefixChecks) {
817
+ this._errors.push(prefixChecks.message);
818
+ check = false;
819
+ }
820
+
821
+ return check;
822
+ }
823
+
824
+ /**
825
+ * Sets DOM elements within the carousel.
826
+ *
827
+ * The carousel element _cannot_ be set through this method.
828
+ *
829
+ * @protected
830
+ *
831
+ * @param {string} elementType - The type of element to populate.
832
+ * @param {HTMLElement} [base = this.dom.carousel] - The element used as the base for the querySelector.
833
+ * @param {boolean} [overwrite = true] - A flag to set if the existing elements will be overwritten.
834
+ */
835
+ _setDOMElementType(elementType, base = this.dom.carousel, overwrite = true) {
836
+ if (typeof this.selectors[elementType] === "string") {
837
+ if (elementType === "carousel") {
838
+ throw new Error(
839
+ `Graupl Carousel: "${elementType}" element cannot be set through _setDOMElementType.`
840
+ );
841
+ }
842
+
843
+ if (base !== this.dom.carousel) isValidInstance(HTMLElement, { base });
844
+
845
+ if (Array.isArray(this._dom[elementType])) {
846
+ // Get all the elements matching the selector in the base.
847
+ const domElements = Array.from(
848
+ base.querySelectorAll(this.selectors[elementType])
849
+ );
850
+
851
+ // Filter the elements so only direct children of the base are kept.
852
+ const filteredElements = domElements.filter(
853
+ (item) => item.parentElement === base
854
+ );
855
+
856
+ if (overwrite) {
857
+ this._dom[elementType] = filteredElements;
858
+ } else {
859
+ this._dom[elementType] = [
860
+ ...this._dom[elementType],
861
+ ...filteredElements,
862
+ ];
863
+ }
864
+ } else {
865
+ // Get the single element matching the selector in the base.
866
+ const domElement = base.querySelector(this.selectors[elementType]);
867
+
868
+ // Ensure the element is a direct child of the base.
869
+ if (domElement && domElement.parentElement !== base) {
870
+ return;
871
+ }
872
+
873
+ if (overwrite) {
874
+ this._dom[elementType] = domElement;
875
+ }
876
+ }
877
+ } else {
878
+ throw new Error(
879
+ `Graupl Carousel: "${elementType}" is not a valid element type within the carousel.`
880
+ );
881
+ }
882
+ }
883
+
884
+ /**
885
+ * Resets DOM elements within the menu.
886
+ *
887
+ * The carousel element _cannot_ be reset through this method.
888
+ *
889
+ * @protected
890
+ *
891
+ * @param {string} elementType - The type of element to clear.
892
+ */
893
+ _resetDOMElementType(elementType) {
894
+ if (typeof this.selectors[elementType] === "string") {
895
+ if (elementType === "carousel") {
896
+ throw new Error(
897
+ `Graupl Carousel: "${elementType}" element cannot be reset through _resetDOMElementType.`
898
+ );
899
+ }
900
+
901
+ if (Array.isArray(this._dom[elementType])) {
902
+ this._dom[elementType] = [];
903
+ } else {
904
+ this._dom[elementType] = null;
905
+ }
906
+ } else {
907
+ throw new Error(
908
+ `Graupl Carousel: "${elementType}" is not a valid element type within the carousel.`
909
+ );
910
+ }
911
+ }
912
+
913
+ /**
914
+ * Sets all DOM elements within the carousel.
915
+ *
916
+ * Utilizes _setDOMElementType and _resetDOMElementType.
917
+ *
918
+ * @protected
919
+ */
920
+ _setDOMElements() {
921
+ this._setDOMElementType("carouselItemContainer");
922
+ this._setDOMElementType("carouselControlContainer");
923
+ this._setDOMElementType("carouselTabContainer");
924
+
925
+ if (this.dom.carouselItemContainer) {
926
+ this._setDOMElementType("carouselItems", this.dom.carouselItemContainer);
927
+ }
928
+ if (this.dom.carouselControlContainer) {
929
+ this._setDOMElementType(
930
+ "carouselControls",
931
+ this.dom.carouselControlContainer
932
+ );
933
+ this._setDOMElementType("autoplay", this.dom.carouselControlContainer);
934
+ this._setDOMElementType("next", this.dom.carouselControlContainer);
935
+ this._setDOMElementType("previous", this.dom.carouselControlContainer);
936
+ }
937
+
938
+ if (this._dom.carouselTabContainer) {
939
+ this._setDOMElementType("carouselTabs", this.dom.carouselTabContainer);
940
+ }
941
+ }
942
+
943
+ /**
944
+ * Sets the ids for the carousel items and tabs.
945
+ */
946
+ _setIds() {
947
+ const randomString = Math.random()
948
+ .toString(36)
949
+ .replace(/[^a-z]+/g, "")
950
+ .substring(0, 10);
951
+
952
+ this.dom.carouselItems.forEach((item, index) => {
953
+ item.id = item.id || `carousel-item-${randomString}-${index}`;
954
+ });
955
+
956
+ this.dom.carouselTabs.forEach((tab, index) => {
957
+ tab.id = tab.id || `carousel-tab-${randomString}-${index}`;
958
+ });
959
+ }
960
+
961
+ /**
962
+ * Sets the aria attributes for the carousel.
963
+ */
964
+ _setAriaAttributes() {
965
+ // Make sure the carousel has a proper role.
966
+ // Sections and role="region" are acceptable in certain cases, so
967
+ // we only need to fallback to role="group" if neither of those are present.
968
+ if (
969
+ !isTag("section", { carousel: this.dom.carousel }) &&
970
+ !this.dom.carousel.getAttribute("role") !== "region"
971
+ ) {
972
+ this.dom.carousel.setAttribute("role", "group");
973
+ }
974
+
975
+ // Set the role description for the carousel.
976
+ this._dom.carousel.setAttribute("aria-roledescription", "carousel");
977
+
978
+ if (this.dom.carouselTabContainer) {
979
+ this.dom.carouselTabContainer.setAttribute("role", "tablist");
980
+ }
981
+
982
+ this.dom.carouselTabs.forEach((tab, index) => {
983
+ if (!isTag("button", { tab: tab })) {
984
+ tab.setAttribute("role", "button");
985
+ }
986
+
987
+ tab.setAttribute("aria-selected", index === 0);
988
+ tab.setAttribute("aria-controls", this.dom.carouselItems[index].id);
989
+ });
990
+ }
991
+
992
+ /**
993
+ * Sets the interval for autoplaying the carousel.
994
+ *
995
+ * @protected
996
+ */
997
+ _setInterval() {
998
+ this._clearInterval();
999
+
1000
+ this._autoplayInterval = setInterval(() => {
1001
+ this.activateNextItem();
1002
+ }, this.transitionDelay);
1003
+ }
1004
+
1005
+ /**
1006
+ * Clears the interval for autoplaying the carousel.
1007
+ *
1008
+ * @protected
1009
+ */
1010
+ _clearInterval() {
1011
+ clearInterval(this._autoplayInterval);
1012
+ }
1013
+
1014
+ /**
1015
+ * Handles the autoplay functionality of the carousel.
1016
+ *
1017
+ * - Adds the appropriate class to the autoplay button.
1018
+ * - Removes the appropriate class from the autoplay button.
1019
+ * - Sets the appropriate aria-label for the autoplay button.
1020
+ * - Sets the appropriate aria-live for the carousel.
1021
+ * - Sets/clears the interval for autoplaying the carousel.
1022
+ *
1023
+ * @protected
1024
+ */
1025
+ _handleAutoplay() {
1026
+ if (this.autoplay) {
1027
+ addClass(this.pauseClass, this.dom.autoplay);
1028
+ removeClass(this.playClass, this.dom.autoplay);
1029
+
1030
+ this.dom.autoplay.setAttribute("aria-label", this.pauseText);
1031
+ this.dom.carousel.setAttribute("aria-live", "off");
1032
+
1033
+ this._setInterval();
1034
+ } else {
1035
+ addClass(this.playClass, this.dom.autoplay);
1036
+ removeClass(this.pauseClass, this.dom.autoplay);
1037
+
1038
+ this.dom.autoplay.setAttribute("aria-label", this.playText);
1039
+ this.dom.carousel.setAttribute("aria-live", "polite");
1040
+
1041
+ this._clearInterval();
1042
+ }
1043
+ }
1044
+
1045
+ /**
1046
+ * Handles the focus events throughout the carousel for proper use.
1047
+ *
1048
+ * - Adds a `focusin` listener to the carousel element to pause autoplay.
1049
+ * - Adds a `focusout` listener to the carousel element to resume autoplay.
1050
+ */
1051
+ _handleFocus() {
1052
+ // Pause autoplay when anything in the carousel is focused.
1053
+ this.dom.carousel.addEventListener("focusin", () => {
1054
+ if (this.autoplay) {
1055
+ this._clearInterval();
1056
+ }
1057
+ });
1058
+
1059
+ this.dom.carousel.addEventListener("focusout", () => {
1060
+ if (this.autoplay) {
1061
+ this._setInterval();
1062
+ }
1063
+ });
1064
+ }
1065
+
1066
+ /**
1067
+ * Handles the click events throughout the carousel.
1068
+ *
1069
+ * - Adds a `pointerup` listener to the next control to activate the next item.
1070
+ * - Adds a `pointerup` listener to the previous control to activate the previous item.
1071
+ * - Adds a `pointerup` listener to the autoplay control to toggle autoplay.
1072
+ * - Adds a `pointerup` listener to each tab control to activate the corresponding item.
1073
+ */
1074
+ _handleClick() {
1075
+ this.dom.next.addEventListener("pointerup", () => {
1076
+ this.activateNextItem();
1077
+ });
1078
+
1079
+ this.dom.previous.addEventListener("pointerup", () => {
1080
+ this.activatePreviousItem();
1081
+ });
1082
+
1083
+ this.dom.autoplay.addEventListener("pointerup", () => {
1084
+ this.toggleAutoplay();
1085
+ });
1086
+
1087
+ this.dom.carouselTabs.forEach((tab, index) => {
1088
+ tab.addEventListener("pointerup", () => {
1089
+ if (this.currentItem > index) {
1090
+ this._currentAction = "previous";
1091
+ } else {
1092
+ this._currentAction = "next";
1093
+ }
1094
+
1095
+ this.activateItem(index);
1096
+ });
1097
+ });
1098
+ }
1099
+
1100
+ /**
1101
+ * Handles the hover events throughout the carousel for proper use.
1102
+ *
1103
+ * - Adds a `pointerover` listener to the carousel to pause autoplay.
1104
+ * - Adds a `pointerleave` listener to the carousel to resume autoplay.
1105
+ */
1106
+ _handleHover() {
1107
+ // Pause autoplay when anything in the carousel is hovered.
1108
+ this.dom.carousel.addEventListener("pointerover", () => {
1109
+ if (this.autoplay) {
1110
+ this._clearInterval();
1111
+ }
1112
+ });
1113
+
1114
+ this.dom.carousel.addEventListener("pointerleave", () => {
1115
+ if (this.autoplay) {
1116
+ this._setInterval();
1117
+ }
1118
+ });
1119
+ }
1120
+
1121
+ /**
1122
+ * Handles keydown events throughout the carousel item for proper use.
1123
+ *
1124
+ * - Adds a `keydown` listener to all control elements.
1125
+ * - Prevents Space and Enter key events.
1126
+ * - Adds a `keydown` listener to all tab elements.
1127
+ * - Prevents Space and Enter key events.
1128
+ */
1129
+ _handleKeydown() {
1130
+ this.dom.carouselControls.forEach((control) => {
1131
+ control.addEventListener("keydown", (event) => {
1132
+ const key = keyPress(event);
1133
+
1134
+ switch (key) {
1135
+ case "Space":
1136
+ case "Enter":
1137
+ // Prevent the default action of the event.
1138
+ preventEvent(event);
1139
+
1140
+ break;
1141
+ }
1142
+ });
1143
+ });
1144
+
1145
+ this.dom.carouselTabs.forEach((tab) => {
1146
+ tab.addEventListener("keydown", (event) => {
1147
+ const key = keyPress(event);
1148
+
1149
+ switch (key) {
1150
+ case "Space":
1151
+ case "Enter":
1152
+ // Prevent the default action of the event.
1153
+ preventEvent(event);
1154
+
1155
+ break;
1156
+ }
1157
+ });
1158
+ });
1159
+ }
1160
+
1161
+ /**
1162
+ * Handles keyup events throughout the carousel item for proper use.
1163
+ *
1164
+ * - Adds a `keyup` listener to all control elements.
1165
+ * - Activates the next/previous item depending on which control is pressed.
1166
+ * - Toggles autoplay if the autoplay control is pressed.
1167
+ *
1168
+ */
1169
+ _handleKeyup() {
1170
+ // Activate the next item if the space or enter key on the next control.
1171
+ this.dom.next.addEventListener("keyup", (event) => {
1172
+ const key = keyPress(event);
1173
+
1174
+ switch (key) {
1175
+ case "Space":
1176
+ case "Enter":
1177
+ this.activateNextItem();
1178
+
1179
+ // Prevent the default action of the event.
1180
+ preventEvent(event);
1181
+
1182
+ break;
1183
+ }
1184
+ });
1185
+
1186
+ // Activate the previous item if the space or enter key on the previous control.
1187
+ this.dom.previous.addEventListener("keyup", (event) => {
1188
+ const key = keyPress(event);
1189
+
1190
+ switch (key) {
1191
+ case "Space":
1192
+ case "Enter":
1193
+ this.activatePreviousItem();
1194
+
1195
+ // Prevent the default action of the event.
1196
+ preventEvent(event);
1197
+
1198
+ break;
1199
+ }
1200
+ });
1201
+
1202
+ // Toggle autoplay if the space or enter key on the autoplay control.
1203
+ this.dom.autoplay.addEventListener("keyup", (event) => {
1204
+ const key = keyPress(event);
1205
+
1206
+ switch (key) {
1207
+ case "Space":
1208
+ case "Enter":
1209
+ this.toggleAutoplay();
1210
+
1211
+ // Prevent the default action of the event.
1212
+ preventEvent(event);
1213
+
1214
+ break;
1215
+ }
1216
+ });
1217
+
1218
+ // Activate the item if the space or enter key on the tab control.
1219
+ this.dom.carouselTabs.forEach((tab, index) => {
1220
+ tab.addEventListener("keyup", (event) => {
1221
+ const key = keyPress(event);
1222
+
1223
+ switch (key) {
1224
+ case "Space":
1225
+ case "Enter":
1226
+ this.activateItem(index);
1227
+
1228
+ // Prevent the default action of the event.
1229
+ preventEvent(event);
1230
+
1231
+ break;
1232
+ }
1233
+ });
1234
+ });
1235
+ }
1236
+
1237
+ /**
1238
+ * Sets the transition duration for the carousel as a CSS custom property.
1239
+ *
1240
+ * The custom property is set as `--graupl-carousel-transition-duration`.
1241
+ *
1242
+ * @protected
1243
+ */
1244
+ _setTransitionDuration() {
1245
+ this.dom.carousel.style.setProperty(
1246
+ `--${this.prefix}carousel-transition-duration`,
1247
+ `${this.transitionDuration}ms`
1248
+ );
1249
+ }
1250
+
1251
+ /**
1252
+ * Activates the current carousel item.
1253
+ *
1254
+ * @public
1255
+ */
1256
+ activateCurrentItem() {
1257
+ addClass(this.activeClass, this.currentCarouselItem);
1258
+
1259
+ if (this.currentCarouselTab) {
1260
+ this.currentCarouselTab.setAttribute("aria-selected", true);
1261
+ addClass(this.activeClass, this.currentCarouselTab);
1262
+ }
1263
+ }
1264
+
1265
+ /**
1266
+ * Deactivates the current carousel item.
1267
+ *
1268
+ * @public
1269
+ */
1270
+ deactivateCurrentItem() {
1271
+ removeClass(this.activeClass, this.currentCarouselItem);
1272
+
1273
+ if (this.currentCarouselTab) {
1274
+ this.currentCarouselTab.setAttribute("aria-selected", false);
1275
+ removeClass(this.activeClass, this.currentCarouselTab);
1276
+ }
1277
+ }
1278
+
1279
+ /**
1280
+ * Activates the carousel item at a given index.
1281
+ *
1282
+ * @public
1283
+ *
1284
+ * @param {number} index - The index of the carousel item to activate.
1285
+ */
1286
+ activateItem(index) {
1287
+ const currentIndex = this.currentItem;
1288
+
1289
+ this.dom.carousel.dataset.grauplAction = this._currentAction;
1290
+
1291
+ if (this.autoplay) {
1292
+ this._clearInterval();
1293
+ }
1294
+
1295
+ addClass(this.previousClass, this.currentCarouselItem);
1296
+ addClass(this.nextClass, this.dom.carouselItems[index]);
1297
+
1298
+ requestAnimationFrame(() => {
1299
+ this.deactivateCurrentItem();
1300
+ this.currentItem = index;
1301
+ this.activateCurrentItem();
1302
+
1303
+ requestAnimationFrame(() => {
1304
+ setTimeout(() => {
1305
+ removeClass(this.previousClass, this.dom.carouselItems[currentIndex]);
1306
+ removeClass(this.nextClass, this.currentCarouselItem);
1307
+ }, this.transitionDuration);
1308
+ });
1309
+ });
1310
+
1311
+ if (this.autoplay) {
1312
+ this._setInterval();
1313
+ }
1314
+ }
1315
+
1316
+ /**
1317
+ * Activates the first carousel item.
1318
+ *
1319
+ * @public
1320
+ */
1321
+ activateFirstItem() {
1322
+ this.activateItem(0);
1323
+ }
1324
+
1325
+ /**
1326
+ * Activates the last carousel item.
1327
+ *
1328
+ * @public
1329
+ */
1330
+ activateLastItem() {
1331
+ this.activateItem(this.dom.carouselItems.length - 1);
1332
+ }
1333
+
1334
+ /**
1335
+ * Activates the next carousel item.
1336
+ *
1337
+ * @public
1338
+ */
1339
+ activateNextItem() {
1340
+ this._currentAction = "next";
1341
+
1342
+ if (this.currentItem + 1 >= this.dom.carouselItems.length) {
1343
+ this.activateFirstItem();
1344
+ } else {
1345
+ this.activateItem(this.currentItem + 1);
1346
+ }
1347
+ }
1348
+
1349
+ /**
1350
+ * Activates the previous carousel item.
1351
+ *
1352
+ * @public
1353
+ */
1354
+ activatePreviousItem() {
1355
+ this._currentAction = "previous";
1356
+
1357
+ if (this.currentItem - 1 < 0) {
1358
+ this.activateLastItem();
1359
+ } else {
1360
+ this.activateItem(this.currentItem - 1);
1361
+ }
1362
+ }
1363
+
1364
+ /**
1365
+ * Toggles autoplay on the carousel.
1366
+ *
1367
+ * @public
1368
+ */
1369
+ toggleAutoplay() {
1370
+ this.autoplay = !this.autoplay;
1371
+
1372
+ this._handleAutoplay();
1373
+ }
1374
+ }
1375
+
1376
+ export default Carousel;