kmaterialize 2.3.3-1.0.21 → 2.3.3-1.0.23

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 (47) hide show
  1. package/components/air-datepicker/air-datepicker.js +152 -0
  2. package/components/alert/alert.js +54 -0
  3. package/components/button/buttons.js +220 -0
  4. package/components/card/cards.js +149 -0
  5. package/components/carousel/carousel.js +574 -0
  6. package/components/carousel/slider.js +340 -0
  7. package/components/chip/chips.js +341 -0
  8. package/components/collapsible/collapsible.js +156 -0
  9. package/components/color-input/color-input.js +166 -0
  10. package/components/datepicker/datepicker.js +1035 -0
  11. package/components/dialog/materialbox.js +377 -0
  12. package/components/dialog/modal.js +72 -0
  13. package/components/dropdown/dropdown.js +505 -0
  14. package/components/file-input/file-input.js +169 -0
  15. package/components/kanban/_kanban.scss +69 -0
  16. package/components/kanban/kanban.js +168 -0
  17. package/components/kanban/kanban.ts +57 -8
  18. package/components/loading/_loading.scss +68 -0
  19. package/components/loading/loading.ts +104 -0
  20. package/components/loading/loadingSpec.js +102 -0
  21. package/components/navigation-drawer/sidenav.js +454 -0
  22. package/components/number-input/number-input.js +68 -0
  23. package/components/password-input/password-input.js +49 -0
  24. package/components/popup/_popup.scss +106 -0
  25. package/components/popup/popup.ts +113 -0
  26. package/components/popup/popupSpec.js +140 -0
  27. package/components/search/autocomplete.js +470 -0
  28. package/components/slider/range.js +169 -0
  29. package/components/snackbar/toasts.js +244 -0
  30. package/components/tabs/tabs.js +289 -0
  31. package/components/textfield/forms.js +172 -0
  32. package/components/textfield/select.js +385 -0
  33. package/components/timepicker/timepicker.js +698 -0
  34. package/components/tom-select/tom-select-field.js +130 -0
  35. package/components/toolbar/toolbar.js +134 -0
  36. package/components/tooltip/tooltip.js +270 -0
  37. package/dist/css/materialize.colors.min.css +1 -1
  38. package/dist/css/materialize.css +322 -1
  39. package/dist/css/materialize.min.css +2 -2
  40. package/dist/css/materialize.min.css.map +1 -1
  41. package/dist/js/materialize.cjs.js +258 -42
  42. package/dist/js/materialize.d.ts +50 -3
  43. package/dist/js/materialize.js +258 -42
  44. package/dist/js/materialize.min.js +2 -2
  45. package/dist/js/materialize.mjs +257 -43
  46. package/package.json +6 -1
  47. package/sass/materialize.scss +2 -0
@@ -0,0 +1,574 @@
1
+ import { Utils } from '../../src/utils';
2
+ import { Component } from '../../src/component';
3
+ const _defaults = {
4
+ duration: 200, // ms
5
+ dist: -100, // zoom scale TODO: make this more intuitive as an option
6
+ shift: 0, // spacing for center image
7
+ padding: 0, // Padding between non center items
8
+ numVisible: 5, // Number of visible items in carousel
9
+ fullWidth: false, // Change to full width styles
10
+ indicators: false, // Toggle indicators
11
+ noWrap: false, // Don't wrap around and cycle through items.
12
+ onCycleTo: null // Callback for when a new slide is cycled to.
13
+ };
14
+ export class Carousel extends Component {
15
+ hasMultipleSlides;
16
+ showIndicators;
17
+ noWrap;
18
+ /** If the carousel is being clicked or tapped. */
19
+ pressed;
20
+ /** If the carousel is currently being dragged. */
21
+ dragged;
22
+ offset;
23
+ target;
24
+ images;
25
+ itemWidth;
26
+ itemHeight;
27
+ dim;
28
+ _indicators;
29
+ count;
30
+ xform;
31
+ verticalDragged;
32
+ reference;
33
+ referenceY;
34
+ velocity;
35
+ frame;
36
+ timestamp;
37
+ ticker;
38
+ amplitude;
39
+ /** The index of the center carousel item. */
40
+ center = 0;
41
+ imageHeight;
42
+ scrollingTimeout;
43
+ oneTimeCallback;
44
+ constructor(el, options) {
45
+ super(el, options, Carousel);
46
+ this.el['M_Carousel'] = this;
47
+ this.options = {
48
+ ...Carousel.defaults,
49
+ ...options
50
+ };
51
+ // Setup
52
+ this.hasMultipleSlides = this.el.querySelectorAll('.carousel-item').length > 1;
53
+ this.showIndicators = this.options.indicators && this.hasMultipleSlides;
54
+ this.noWrap = this.options.noWrap || !this.hasMultipleSlides;
55
+ this.pressed = false;
56
+ this.dragged = false;
57
+ this.offset = this.target = 0;
58
+ this.images = [];
59
+ this.itemWidth = this.el.querySelector('.carousel-item').clientWidth;
60
+ this.itemHeight = this.el.querySelector('.carousel-item').clientHeight;
61
+ this.dim = this.itemWidth * 2 + this.options.padding || 1; // Make sure dim is non zero for divisions.
62
+ // Full Width carousel setup
63
+ if (this.options.fullWidth) {
64
+ this.options.dist = 0;
65
+ this._setCarouselHeight();
66
+ // Offset fixed items when indicators.
67
+ if (this.showIndicators) {
68
+ this.el.querySelector('.carousel-fixed-item')?.classList.add('with-indicators');
69
+ }
70
+ }
71
+ // Iterate through slides
72
+ this._indicators = document.createElement('ul');
73
+ this._indicators.classList.add('indicators');
74
+ this.el.querySelectorAll('.carousel-item').forEach((item, i) => {
75
+ this.images.push(item);
76
+ if (this.showIndicators) {
77
+ const indicator = document.createElement('li');
78
+ indicator.classList.add('indicator-item');
79
+ indicator.tabIndex = 0;
80
+ if (i === 0) {
81
+ indicator.classList.add('active');
82
+ }
83
+ this._indicators.appendChild(indicator);
84
+ }
85
+ });
86
+ if (this.showIndicators)
87
+ this.el.appendChild(this._indicators);
88
+ this.count = this.images.length;
89
+ // Cap numVisible at count
90
+ this.options.numVisible = Math.min(this.count, this.options.numVisible);
91
+ // Setup cross browser string
92
+ this.xform = 'transform';
93
+ ['webkit', 'Moz', 'O', 'ms'].every((prefix) => {
94
+ const e = prefix + 'Transform';
95
+ if (typeof document.body.style[e] !== 'undefined') {
96
+ this.xform = e;
97
+ return false;
98
+ }
99
+ return true;
100
+ });
101
+ this._setupEventHandlers();
102
+ this._scroll(this.offset);
103
+ }
104
+ static get defaults() {
105
+ return _defaults;
106
+ }
107
+ /**
108
+ * Initializes instances of Carousel.
109
+ * @param els HTML elements.
110
+ * @param options Component options.
111
+ */
112
+ static init(els, options = {}) {
113
+ return super.init(els, options, Carousel);
114
+ }
115
+ static getInstance(el) {
116
+ return el['M_Carousel'];
117
+ }
118
+ destroy() {
119
+ this._removeEventHandlers();
120
+ this.el['M_Carousel'] = undefined;
121
+ }
122
+ _setupEventHandlers() {
123
+ if (typeof window.ontouchstart !== 'undefined') {
124
+ this.el.addEventListener('touchstart', this._handleCarouselTap);
125
+ this.el.addEventListener('touchmove', this._handleCarouselDrag);
126
+ this.el.addEventListener('touchend', this._handleCarouselRelease);
127
+ }
128
+ this.el.addEventListener('mousedown', this._handleCarouselTap);
129
+ this.el.addEventListener('mousemove', this._handleCarouselDrag);
130
+ this.el.addEventListener('mouseup', this._handleCarouselRelease);
131
+ this.el.addEventListener('mouseleave', this._handleCarouselRelease);
132
+ this.el.addEventListener('click', this._handleCarouselClick);
133
+ if (this.showIndicators && this._indicators) {
134
+ this._indicators.querySelectorAll('.indicator-item').forEach((el) => {
135
+ el.addEventListener('click', this._handleIndicatorClick);
136
+ el.addEventListener('keypress', this._handleIndicatorKeyPress);
137
+ });
138
+ }
139
+ // Resize
140
+ window.addEventListener('resize', this._handleThrottledResize);
141
+ }
142
+ _removeEventHandlers() {
143
+ if (typeof window.ontouchstart !== 'undefined') {
144
+ this.el.removeEventListener('touchstart', this._handleCarouselTap);
145
+ this.el.removeEventListener('touchmove', this._handleCarouselDrag);
146
+ this.el.removeEventListener('touchend', this._handleCarouselRelease);
147
+ }
148
+ this.el.removeEventListener('mousedown', this._handleCarouselTap);
149
+ this.el.removeEventListener('mousemove', this._handleCarouselDrag);
150
+ this.el.removeEventListener('mouseup', this._handleCarouselRelease);
151
+ this.el.removeEventListener('mouseleave', this._handleCarouselRelease);
152
+ this.el.removeEventListener('click', this._handleCarouselClick);
153
+ if (this.showIndicators && this._indicators) {
154
+ this._indicators.querySelectorAll('.indicator-item').forEach((el) => {
155
+ el.removeEventListener('click', this._handleIndicatorClick);
156
+ });
157
+ }
158
+ window.removeEventListener('resize', this._handleThrottledResize);
159
+ }
160
+ _handleThrottledResize = () => Utils.throttle(this._handleResize, 200, null).bind(this);
161
+ _handleCarouselTap = (e) => {
162
+ // Fixes firefox draggable image bug
163
+ if (e.type === 'mousedown' && e.target.tagName === 'IMG') {
164
+ e.preventDefault();
165
+ }
166
+ this.pressed = true;
167
+ this.dragged = false;
168
+ this.verticalDragged = false;
169
+ this.reference = this._xpos(e);
170
+ this.referenceY = this._ypos(e);
171
+ this.velocity = this.amplitude = 0;
172
+ this.frame = this.offset;
173
+ this.timestamp = Date.now();
174
+ clearInterval(this.ticker);
175
+ this.ticker = setInterval(this._track, 100);
176
+ };
177
+ _handleCarouselDrag = (e) => {
178
+ let x, y, delta, deltaY;
179
+ if (this.pressed) {
180
+ x = this._xpos(e);
181
+ y = this._ypos(e);
182
+ delta = this.reference - x;
183
+ deltaY = Math.abs(this.referenceY - y);
184
+ if (deltaY < 30 && !this.verticalDragged) {
185
+ // If vertical scrolling don't allow dragging.
186
+ if (delta > 2 || delta < -2) {
187
+ this.dragged = true;
188
+ this.reference = x;
189
+ this._scroll(this.offset + delta);
190
+ }
191
+ }
192
+ else if (this.dragged) {
193
+ // If dragging don't allow vertical scroll.
194
+ e.preventDefault();
195
+ e.stopPropagation();
196
+ return false;
197
+ }
198
+ else {
199
+ // Vertical scrolling.
200
+ this.verticalDragged = true;
201
+ }
202
+ }
203
+ if (this.dragged) {
204
+ // If dragging don't allow vertical scroll.
205
+ e.preventDefault();
206
+ e.stopPropagation();
207
+ return false;
208
+ }
209
+ };
210
+ _handleCarouselRelease = (e) => {
211
+ if (this.pressed) {
212
+ this.pressed = false;
213
+ }
214
+ else {
215
+ return;
216
+ }
217
+ clearInterval(this.ticker);
218
+ this.target = this.offset;
219
+ if (this.velocity > 10 || this.velocity < -10) {
220
+ this.amplitude = 0.9 * this.velocity;
221
+ this.target = this.offset + this.amplitude;
222
+ }
223
+ this.target = Math.round(this.target / this.dim) * this.dim;
224
+ // No wrap of items.
225
+ if (this.noWrap) {
226
+ if (this.target >= this.dim * (this.count - 1)) {
227
+ this.target = this.dim * (this.count - 1);
228
+ }
229
+ else if (this.target < 0) {
230
+ this.target = 0;
231
+ }
232
+ }
233
+ this.amplitude = this.target - this.offset;
234
+ this.timestamp = Date.now();
235
+ requestAnimationFrame(this._autoScroll);
236
+ if (this.dragged) {
237
+ e.preventDefault();
238
+ e.stopPropagation();
239
+ }
240
+ return false;
241
+ };
242
+ _handleCarouselClick = (e) => {
243
+ // Disable clicks if carousel was dragged.
244
+ if (this.dragged) {
245
+ e.preventDefault();
246
+ e.stopPropagation();
247
+ return false;
248
+ }
249
+ else if (!this.options.fullWidth) {
250
+ const clickedElem = e.target.closest('.carousel-item');
251
+ if (!clickedElem)
252
+ return;
253
+ const clickedIndex = [...clickedElem.parentNode.children].indexOf(clickedElem);
254
+ const diff = this._wrap(this.center) - clickedIndex;
255
+ // Disable clicks if carousel was shifted by click
256
+ if (diff !== 0) {
257
+ e.preventDefault();
258
+ e.stopPropagation();
259
+ }
260
+ // fixes https://github.com/materializecss/materialize/issues/180
261
+ if (clickedIndex < 0) {
262
+ // relative X position > center of carousel = clicked at the right part of the carousel
263
+ if (e.clientX - e.target.getBoundingClientRect().left >
264
+ this.el.clientWidth / 2) {
265
+ this.next();
266
+ }
267
+ else {
268
+ this.prev();
269
+ }
270
+ }
271
+ else {
272
+ this._cycleTo(clickedIndex);
273
+ }
274
+ }
275
+ };
276
+ _handleIndicatorClick = (e) => {
277
+ e.stopPropagation();
278
+ this._handleIndicatorInteraction(e);
279
+ };
280
+ _handleIndicatorKeyPress = (e) => {
281
+ e.stopPropagation();
282
+ if (Utils.keys.ENTER.includes(e.key)) {
283
+ this._handleIndicatorInteraction(e);
284
+ }
285
+ };
286
+ _handleIndicatorInteraction = (e) => {
287
+ const indicator = e.target.closest('.indicator-item');
288
+ if (indicator) {
289
+ const index = [...indicator.parentNode.children].indexOf(indicator);
290
+ this._cycleTo(index);
291
+ }
292
+ };
293
+ _handleResize = () => {
294
+ if (this.options.fullWidth) {
295
+ this.itemWidth = this.el.querySelector('.carousel-item').clientWidth;
296
+ this.imageHeight = this.el.querySelector('.carousel-item.active').clientHeight;
297
+ this.dim = this.itemWidth * 2 + this.options.padding;
298
+ this.offset = this.center * 2 * this.itemWidth;
299
+ this.target = this.offset;
300
+ this._setCarouselHeight(true);
301
+ }
302
+ else {
303
+ this._scroll();
304
+ }
305
+ };
306
+ _setCarouselHeight(imageOnly = false) {
307
+ const firstSlide = this.el.querySelector('.carousel-item.active')
308
+ ? this.el.querySelector('.carousel-item.active')
309
+ : this.el.querySelector('.carousel-item');
310
+ const firstImage = firstSlide.querySelector('img');
311
+ if (firstImage) {
312
+ if (firstImage.complete) {
313
+ // If image won't trigger the load event
314
+ const imageHeight = firstImage.clientHeight;
315
+ if (imageHeight > 0) {
316
+ this.el.style.height = imageHeight + 'px';
317
+ }
318
+ else {
319
+ // If image still has no height, use the natural dimensions to calculate
320
+ const naturalWidth = firstImage.naturalWidth;
321
+ const naturalHeight = firstImage.naturalHeight;
322
+ const adjustedHeight = (this.el.clientWidth / naturalWidth) * naturalHeight;
323
+ this.el.style.height = adjustedHeight + 'px';
324
+ }
325
+ }
326
+ else {
327
+ // Get height when image is loaded normally
328
+ firstImage.addEventListener('load', () => {
329
+ this.el.style.height = firstImage.offsetHeight + 'px';
330
+ });
331
+ }
332
+ }
333
+ else if (!imageOnly) {
334
+ const slideHeight = firstSlide.clientHeight;
335
+ this.el.style.height = slideHeight + 'px';
336
+ }
337
+ }
338
+ _xpos(e) {
339
+ // touch event
340
+ if (e.type.startsWith('touch') && e.targetTouches.length >= 1) {
341
+ return e.targetTouches[0].clientX;
342
+ }
343
+ // mouse event
344
+ return e.clientX;
345
+ }
346
+ _ypos(e) {
347
+ // touch event
348
+ if (e.type.startsWith('touch') && e.targetTouches.length >= 1) {
349
+ return e.targetTouches[0].clientY;
350
+ }
351
+ // mouse event
352
+ return e.clientY;
353
+ }
354
+ _wrap(x) {
355
+ return x >= this.count ? x % this.count : x < 0 ? this._wrap(this.count + (x % this.count)) : x;
356
+ }
357
+ _track = () => {
358
+ const now = Date.now(), elapsed = now - this.timestamp, delta = this.offset - this.frame, v = (1000 * delta) / (1 + elapsed);
359
+ // now = Date.now();
360
+ // elapsed = now - this.timestamp;
361
+ this.timestamp = now;
362
+ // delta = this.offset - this.frame;
363
+ this.frame = this.offset;
364
+ // v = (1000 * delta) / (1 + elapsed);
365
+ this.velocity = 0.8 * v + 0.2 * this.velocity;
366
+ };
367
+ _autoScroll = () => {
368
+ let elapsed, delta;
369
+ if (this.amplitude) {
370
+ elapsed = Date.now() - this.timestamp;
371
+ delta = this.amplitude * Math.exp(-elapsed / this.options.duration);
372
+ if (delta > 2 || delta < -2) {
373
+ this._scroll(this.target - delta);
374
+ requestAnimationFrame(this._autoScroll);
375
+ }
376
+ else {
377
+ this._scroll(this.target);
378
+ }
379
+ }
380
+ };
381
+ _scroll(x = 0) {
382
+ // Track scrolling state
383
+ if (!this.el.classList.contains('scrolling')) {
384
+ this.el.classList.add('scrolling');
385
+ }
386
+ if (this.scrollingTimeout != null) {
387
+ clearTimeout(this.scrollingTimeout);
388
+ }
389
+ this.scrollingTimeout = setTimeout(() => {
390
+ this.el.classList.remove('scrolling');
391
+ }, this.options.duration);
392
+ // Save last center before updating the center for onCycleTo callback
393
+ const lastCenter = this.center;
394
+ // Start actual scroll
395
+ this.offset = typeof x === 'number' ? x : this.offset;
396
+ this.center = Math.floor((this.offset + this.dim / 2) / this.dim);
397
+ const half = this.count >> 1, delta = this.offset - this.center * this.dim, dir = delta < 0 ? 1 : -1, tween = (-dir * delta * 2) / this.dim;
398
+ let i, el, alignment, zTranslation, tweenedOpacity, centerTweenedOpacity;
399
+ const numVisibleOffset = 1 / this.options.numVisible;
400
+ // delta = this.offset - this.center * this.dim;
401
+ // dir = delta < 0 ? 1 : -1;
402
+ // tween = (-dir * delta * 2) / this.dim;
403
+ // half = this.count >> 1;
404
+ if (this.options.fullWidth) {
405
+ alignment = 'translateX(0)';
406
+ centerTweenedOpacity = 1;
407
+ }
408
+ else {
409
+ alignment = 'translateX(' + (this.el.clientWidth - this.itemWidth) / 2 + 'px) ';
410
+ alignment += 'translateY(' + (this.el.clientHeight - this.itemHeight) / 2 + 'px)';
411
+ centerTweenedOpacity = 1 - numVisibleOffset * tween;
412
+ }
413
+ // Set indicator active
414
+ if (this.showIndicators) {
415
+ const diff = this.center % this.count;
416
+ const activeIndicator = this._indicators.querySelector('.indicator-item.active');
417
+ const activeIndicatorIndex = [...activeIndicator.parentNode.children].indexOf(activeIndicator);
418
+ if (activeIndicatorIndex !== diff) {
419
+ activeIndicator.classList.remove('active');
420
+ const pos = diff < 0 ? this.count + diff : diff;
421
+ this._indicators.querySelectorAll('.indicator-item')[pos].classList.add('active');
422
+ }
423
+ }
424
+ // center
425
+ // Don't show wrapped items.
426
+ if (!this.noWrap || (this.center >= 0 && this.center < this.count)) {
427
+ el = this.images[this._wrap(this.center)];
428
+ // Add active class to center item.
429
+ if (!el.classList.contains('active')) {
430
+ this.el.querySelector('.carousel-item').classList.remove('active');
431
+ el.classList.add('active');
432
+ }
433
+ const transformString = `${alignment} translateX(${-delta / 2}px) translateX(${dir * this.options.shift * tween * i}px) translateZ(${this.options.dist * tween}px)`;
434
+ this._updateItemStyle(el, centerTweenedOpacity, 0, transformString);
435
+ }
436
+ for (i = 1; i <= half; ++i) {
437
+ // right side
438
+ if (this.options.fullWidth) {
439
+ zTranslation = this.options.dist;
440
+ tweenedOpacity = i === half && delta < 0 ? 1 - tween : 1;
441
+ }
442
+ else {
443
+ zTranslation = this.options.dist * (i * 2 + tween * dir);
444
+ tweenedOpacity = 1 - numVisibleOffset * (i * 2 + tween * dir);
445
+ }
446
+ // Don't show wrapped items.
447
+ if (!this.noWrap || this.center + i < this.count) {
448
+ el = this.images[this._wrap(this.center + i)];
449
+ const transformString = `${alignment} translateX(${this.options.shift + (this.dim * i - delta) / 2}px) translateZ(${zTranslation}px)`;
450
+ this._updateItemStyle(el, tweenedOpacity, -i, transformString);
451
+ }
452
+ // left side
453
+ if (this.options.fullWidth) {
454
+ zTranslation = this.options.dist;
455
+ tweenedOpacity = i === half && delta > 0 ? 1 - tween : 1;
456
+ }
457
+ else {
458
+ zTranslation = this.options.dist * (i * 2 - tween * dir);
459
+ tweenedOpacity = 1 - numVisibleOffset * (i * 2 - tween * dir);
460
+ }
461
+ // Don't show wrapped items.
462
+ if (!this.noWrap || this.center - i >= 0) {
463
+ el = this.images[this._wrap(this.center - i)];
464
+ const transformString = `${alignment} translateX(${-this.options.shift + (-this.dim * i - delta) / 2}px) translateZ(${zTranslation}px)`;
465
+ this._updateItemStyle(el, tweenedOpacity, -i, transformString);
466
+ }
467
+ }
468
+ // center
469
+ // Don't show wrapped items.
470
+ if (!this.noWrap || (this.center >= 0 && this.center < this.count)) {
471
+ el = this.images[this._wrap(this.center)];
472
+ const transformString = `${alignment} translateX(${-delta / 2}px) translateX(${dir * this.options.shift * tween}px) translateZ(${this.options.dist * tween}px)`;
473
+ this._updateItemStyle(el, centerTweenedOpacity, 0, transformString);
474
+ }
475
+ // onCycleTo callback
476
+ const _currItem = this.el.querySelectorAll('.carousel-item')[this._wrap(this.center)];
477
+ if (lastCenter !== this.center && typeof this.options.onCycleTo === 'function') {
478
+ this.options.onCycleTo.call(this, _currItem, this.dragged);
479
+ }
480
+ // One time callback
481
+ if (typeof this.oneTimeCallback === 'function') {
482
+ this.oneTimeCallback.call(this, _currItem, this.dragged);
483
+ this.oneTimeCallback = null;
484
+ }
485
+ }
486
+ _updateItemStyle(el, opacity, zIndex, transform) {
487
+ el.style[this.xform] = transform;
488
+ el.style.zIndex = zIndex.toString();
489
+ el.style.opacity = opacity.toString();
490
+ el.style.visibility = 'visible';
491
+ }
492
+ _cycleTo(n, callback = null) {
493
+ let diff = (this.center % this.count) - n;
494
+ // Account for wraparound.
495
+ if (!this.noWrap) {
496
+ if (diff < 0) {
497
+ if (Math.abs(diff + this.count) < Math.abs(diff)) {
498
+ diff += this.count;
499
+ }
500
+ }
501
+ else if (diff > 0) {
502
+ if (Math.abs(diff - this.count) < diff) {
503
+ diff -= this.count;
504
+ }
505
+ }
506
+ }
507
+ this.target = this.dim * Math.round(this.offset / this.dim);
508
+ // Next
509
+ if (diff < 0) {
510
+ this.target += this.dim * Math.abs(diff);
511
+ } // Prev
512
+ else if (diff > 0) {
513
+ this.target -= this.dim * diff;
514
+ }
515
+ // Set one time callback
516
+ if (typeof callback === 'function') {
517
+ this.oneTimeCallback = callback;
518
+ }
519
+ // Scroll
520
+ if (this.offset !== this.target) {
521
+ this.amplitude = this.target - this.offset;
522
+ this.timestamp = Date.now();
523
+ requestAnimationFrame(this._autoScroll);
524
+ }
525
+ }
526
+ /**
527
+ * Move carousel to next slide or go forward a given amount of slides.
528
+ * @param n How many times the carousel slides.
529
+ */
530
+ next(n = 1) {
531
+ if (n === undefined || isNaN(n)) {
532
+ n = 1;
533
+ }
534
+ let index = this.center + n;
535
+ if (index >= this.count || index < 0) {
536
+ if (this.noWrap)
537
+ return;
538
+ index = this._wrap(index);
539
+ }
540
+ this._cycleTo(index);
541
+ }
542
+ /**
543
+ * Move carousel to previous slide or go back a given amount of slides.
544
+ * @param n How many times the carousel slides.
545
+ */
546
+ prev(n = 1) {
547
+ if (n === undefined || isNaN(n)) {
548
+ n = 1;
549
+ }
550
+ let index = this.center - n;
551
+ if (index >= this.count || index < 0) {
552
+ if (this.noWrap)
553
+ return;
554
+ index = this._wrap(index);
555
+ }
556
+ this._cycleTo(index);
557
+ }
558
+ /**
559
+ * Move carousel to nth slide.
560
+ * @param n Index of slide.
561
+ * @param callback "onCycleTo" optional callback.
562
+ */
563
+ set(n, callback) {
564
+ if (n === undefined || isNaN(n)) {
565
+ n = 0;
566
+ }
567
+ if (n > this.count || n < 0) {
568
+ if (this.noWrap)
569
+ return;
570
+ n = this._wrap(n);
571
+ }
572
+ this._cycleTo(n, callback);
573
+ }
574
+ }