@schukai/monster 3.99.4 → 3.99.6

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.
@@ -10,21 +10,20 @@
10
10
  * For more information about purchasing a commercial license, please contact schukai GmbH.
11
11
  */
12
12
 
13
- import {instanceSymbol} from "../../constants.mjs";
14
- import {ATTRIBUTE_PREFIX, ATTRIBUTE_ROLE} from "../../dom/constants.mjs";
15
- import {CustomElement, getSlottedElements} from "../../dom/customelement.mjs";
13
+ import { instanceSymbol } from "../../constants.mjs";
14
+ import { ATTRIBUTE_PREFIX, ATTRIBUTE_ROLE } from "../../dom/constants.mjs";
15
+ import { CustomElement, getSlottedElements } from "../../dom/customelement.mjs";
16
16
  import {
17
- assembleMethodSymbol,
18
- registerCustomElement,
17
+ assembleMethodSymbol,
18
+ registerCustomElement,
19
19
  } from "../../dom/customelement.mjs";
20
- import {SliderStyleSheet} from "./stylesheet/slider.mjs";
21
- import {fireCustomEvent} from "../../dom/events.mjs";
20
+ import { SliderStyleSheet } from "./stylesheet/slider.mjs";
21
+ import { fireCustomEvent } from "../../dom/events.mjs";
22
22
 
23
- import {getWindow} from "../../dom/util.mjs";
24
- import {isObject, isInteger} from "../../types/is.mjs";
23
+ import { getWindow } from "../../dom/util.mjs";
24
+ import { isObject, isInteger } from "../../types/is.mjs";
25
25
 
26
-
27
- export {Slider};
26
+ export { Slider };
28
27
 
29
28
  /**
30
29
  * @private
@@ -70,349 +69,356 @@ const configSymbol = Symbol("config");
70
69
  * @summary A beautiful Slider that can make your life easier and also looks good.
71
70
  */
72
71
  class Slider extends CustomElement {
73
- /**
74
- * This method is called by the `instanceof` operator.
75
- * @return {symbol}
76
- */
77
- static get [instanceSymbol]() {
78
- return Symbol.for("@schukai/monster/components/layout/slider@@instance");
79
- }
80
-
81
- /**
82
- *
83
- * @return {Components.Layout.Slider
84
- */
85
- [assembleMethodSymbol]() {
86
- super[assembleMethodSymbol]();
87
-
88
- this[configSymbol] = {
89
- currentIndex: 0,
90
-
91
- isDragging: false,
92
- draggingPos: 0,
93
- startPos: 0,
94
- autoPlayInterval: null,
95
- };
96
-
97
- // set --monster-slides-width
98
- const slides = this.shadowRoot.querySelector(`[${ATTRIBUTE_ROLE}="slider"]`);
99
- const slidesVisible = getVisibleSlidesFromContainerWidth.call(this);
100
- slides.style.setProperty("--monster-slides-width", `${100 / slidesVisible}%`);
101
-
102
- initControlReferences.call(this);
103
- initEventHandler.call(this);
104
- initStructure.call(this);
105
-
106
- return this;
107
- }
108
-
109
- /**
110
- * To set the options via the HTML tag, the attribute `data-monster-options` must be used.
111
- * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
112
- *
113
- * The individual configuration values can be found in the table.
114
- *
115
- * @property {Object} templates Template definitions
116
- * @property {string} templates.main Main template
117
- * @property {string} actions.click Callback when clicked
118
- * @property {Object} features Features
119
- * @property {boolean} features.carousel Carousel feature
120
- * @property {boolean} features.autoPlay Auto play feature
121
- * @property {boolean} features.thumbnails Thumbnails feature
122
- * @property {boolean} features.drag Drag feature
123
- * @property {Object} slides Slides configuration, an object with breakpoints and the number of slides to show
124
- * @property {Object} carousel Carousel configuration
125
- * @property {number} carousel.transition Transition time between a full rotation of the carousel
126
- * @property {Object} autoPlay Auto play configuration
127
- * @property {number} autoPlay.delay Delay between slides
128
- * @property {number} autoPlay.startDelay Start delay
129
- * @property {string} autoPlay.direction Direction of the autoplay
130
- * @property {boolean} autoPlay.mouseOverPause Pause on mouse over
131
- * @property {boolean} autoPlay.touchPause Pause on touch
132
- * @property {Object} classes CSS classes
133
- * @property {boolean} disabled Disabled state
134
- */
135
- get defaults() {
136
- return Object.assign({}, super.defaults, {
137
- templates: {
138
- main: getTemplate(),
139
- },
140
-
141
- classes: {},
142
- disabled: false,
143
-
144
- features: {
145
- carousel: true,
146
- autoPlay: true,
147
- thumbnails: true,
148
- drag: true,
149
- },
150
-
151
- slides: {
152
- "0": 1,
153
- },
154
-
155
- carousel: {
156
- transition: 250,
157
- },
158
-
159
- autoPlay: {
160
- delay: 1500,
161
- startDelay: 1000,
162
- direction: "next",
163
- mouseOverPause: true,
164
- touchPause: true,
165
- },
166
- });
167
- }
168
-
169
- /**
170
- * @return {string}
171
- */
172
- static getTag() {
173
- return "monster-slider";
174
- }
175
-
176
- /**
177
- * @return {CSSStyleSheet[]}
178
- */
179
- static getCSSStyleSheet() {
180
- return [SliderStyleSheet];
181
- }
182
-
183
- /**
184
- * moves the slider to the given index
185
- *
186
- * @param index
187
- * @return {void}
188
- */
189
- moveTo(index) {
190
- return moveTo.call(this, index);
191
- }
192
-
193
- /**
194
- * shows the previous slide
195
- *
196
- * @return {void}
197
- */
198
- previous() {
199
- return prev.call(this);
200
- }
201
-
202
- /**
203
- * shows the next slide
204
- *
205
- * @return {void}
206
- */
207
- next() {
208
- return next.call(this);
209
- }
210
-
211
- /**
212
- * stops the auto play
213
- *
214
- * @return {void}
215
- */
216
- stopAutoPlay() {
217
- if (this[configSymbol].autoPlayInterval) {
218
- clearInterval(this[configSymbol].autoPlayInterval);
219
- }
220
- }
221
-
222
- /**
223
- * starts the auto play
224
- *
225
- * @return {void}
226
- */
227
- startAutoPlay() {
228
- initAutoPlay.call(this);
229
- }
72
+ /**
73
+ * This method is called by the `instanceof` operator.
74
+ * @return {symbol}
75
+ */
76
+ static get [instanceSymbol]() {
77
+ return Symbol.for("@schukai/monster/components/layout/slider@@instance");
78
+ }
79
+
80
+ /**
81
+ *
82
+ * @return {Components.Layout.Slider
83
+ */
84
+ [assembleMethodSymbol]() {
85
+ super[assembleMethodSymbol]();
86
+
87
+ this[configSymbol] = {
88
+ currentIndex: 0,
89
+
90
+ isDragging: false,
91
+ draggingPos: 0,
92
+ startPos: 0,
93
+ autoPlayInterval: null,
94
+ };
95
+
96
+ // set --monster-slides-width
97
+ const slides = this.shadowRoot.querySelector(
98
+ `[${ATTRIBUTE_ROLE}="slider"]`,
99
+ );
100
+ const slidesVisible = getVisibleSlidesFromContainerWidth.call(this);
101
+ slides.style.setProperty(
102
+ "--monster-slides-width",
103
+ `${100 / slidesVisible}%`,
104
+ );
105
+
106
+ initControlReferences.call(this);
107
+ initEventHandler.call(this);
108
+ initStructure.call(this);
109
+
110
+ return this;
111
+ }
112
+
113
+ /**
114
+ * To set the options via the HTML tag, the attribute `data-monster-options` must be used.
115
+ * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
116
+ *
117
+ * The individual configuration values can be found in the table.
118
+ *
119
+ * @property {Object} templates Template definitions
120
+ * @property {string} templates.main Main template
121
+ * @property {string} actions.click Callback when clicked
122
+ * @property {Object} features Features
123
+ * @property {boolean} features.carousel Carousel feature
124
+ * @property {boolean} features.autoPlay Auto play feature
125
+ * @property {boolean} features.thumbnails Thumbnails feature
126
+ * @property {boolean} features.drag Drag feature
127
+ * @property {Object} slides Slides configuration, an object with breakpoints and the number of slides to show
128
+ * @property {Object} carousel Carousel configuration
129
+ * @property {number} carousel.transition Transition time between a full rotation of the carousel
130
+ * @property {Object} autoPlay Auto play configuration
131
+ * @property {number} autoPlay.delay Delay between slides
132
+ * @property {number} autoPlay.startDelay Start delay
133
+ * @property {string} autoPlay.direction Direction of the autoplay
134
+ * @property {boolean} autoPlay.mouseOverPause Pause on mouse over
135
+ * @property {boolean} autoPlay.touchPause Pause on touch
136
+ * @property {Object} classes CSS classes
137
+ * @property {boolean} disabled Disabled state
138
+ */
139
+ get defaults() {
140
+ return Object.assign({}, super.defaults, {
141
+ templates: {
142
+ main: getTemplate(),
143
+ },
144
+
145
+ classes: {},
146
+ disabled: false,
147
+
148
+ features: {
149
+ carousel: true,
150
+ autoPlay: true,
151
+ thumbnails: true,
152
+ drag: true,
153
+ },
154
+
155
+ slides: {
156
+ 0: 1,
157
+ },
158
+
159
+ carousel: {
160
+ transition: 250,
161
+ },
162
+
163
+ autoPlay: {
164
+ delay: 1500,
165
+ startDelay: 1000,
166
+ direction: "next",
167
+ mouseOverPause: true,
168
+ touchPause: true,
169
+ },
170
+ });
171
+ }
172
+
173
+ /**
174
+ * @return {string}
175
+ */
176
+ static getTag() {
177
+ return "monster-slider";
178
+ }
179
+
180
+ /**
181
+ * @return {CSSStyleSheet[]}
182
+ */
183
+ static getCSSStyleSheet() {
184
+ return [SliderStyleSheet];
185
+ }
186
+
187
+ /**
188
+ * moves the slider to the given index
189
+ *
190
+ * @param index
191
+ * @return {void}
192
+ */
193
+ moveTo(index) {
194
+ return moveTo.call(this, index);
195
+ }
196
+
197
+ /**
198
+ * shows the previous slide
199
+ *
200
+ * @return {void}
201
+ */
202
+ previous() {
203
+ return prev.call(this);
204
+ }
205
+
206
+ /**
207
+ * shows the next slide
208
+ *
209
+ * @return {void}
210
+ */
211
+ next() {
212
+ return next.call(this);
213
+ }
214
+
215
+ /**
216
+ * stops the auto play
217
+ *
218
+ * @return {void}
219
+ */
220
+ stopAutoPlay() {
221
+ if (this[configSymbol].autoPlayInterval) {
222
+ clearInterval(this[configSymbol].autoPlayInterval);
223
+ }
224
+ }
225
+
226
+ /**
227
+ * starts the auto play
228
+ *
229
+ * @return {void}
230
+ */
231
+ startAutoPlay() {
232
+ initAutoPlay.call(this);
233
+ }
230
234
  }
231
235
 
232
236
  /**
233
237
  * @private
234
238
  * @param name
235
239
  */
236
- function initNavigation(name) {
237
- const element = this.shadowRoot.querySelector("." + name + "");
238
- const elementHeight = element.offsetHeight;
239
- element.style.top = `calc(50% - ${elementHeight / 2}px)`;
240
- }
240
+ //function initNavigation(name) {
241
+ //const element = this.shadowRoot.querySelector("." + name + "");
242
+ //const elementHeight = element.offsetHeight;
243
+ //element.style.top = `calc(50% - ${elementHeight / 2}px)`;
244
+ //}
241
245
 
242
246
  /**
243
247
  * @private
244
248
  */
245
249
  function initStructure() {
250
+ //initNavigation.call(this, "next");
251
+ //initNavigation.call(this, "prev");
246
252
 
247
- initNavigation.call(this, "next");
248
- initNavigation.call(this, "prev");
253
+ if (this.getOption("features.thumbnails")) {
254
+ initThumbnails.call(this);
255
+ }
249
256
 
250
- if (this.getOption("features.thumbnails")) {
251
- initThumbnails.call(this);
252
- }
257
+ initShadows.call(this);
253
258
 
254
- initShadows.call(this);
255
-
256
- if (this.getOption("features.autoPlay")) {
257
- initAutoPlay.call(this);
258
- }
259
+ if (this.getOption("features.autoPlay")) {
260
+ initAutoPlay.call(this);
261
+ }
259
262
  }
260
263
 
261
264
  /**
262
265
  * @private
263
266
  */
264
267
  function initThumbnails() {
265
- const self = this;
266
- const thumbnails = this.shadowRoot.querySelector(
267
- "[data-monster-role='thumbnails']",
268
- );
268
+ const self = this;
269
+ const thumbnails = this.shadowRoot.querySelector(
270
+ "[data-monster-role='thumbnails']",
271
+ );
269
272
 
270
- const {originSlides} = getSlidesAndTotal.call(this);
273
+ const { originSlides } = getSlidesAndTotal.call(this);
271
274
 
272
- originSlides.forEach((x, index) => {
273
- const thumbnail = document.createElement("div");
274
- thumbnail.classList.add("thumbnail");
275
- thumbnail.addEventListener("click", () => {
276
- this.moveTo(index);
277
- });
275
+ originSlides.forEach((x, index) => {
276
+ const thumbnail = document.createElement("div");
277
+ thumbnail.classList.add("thumbnail");
278
+ thumbnail.addEventListener("click", () => {
279
+ this.moveTo(index);
280
+ });
278
281
 
279
- thumbnails.appendChild(thumbnail);
280
- });
282
+ thumbnails.appendChild(thumbnail);
283
+ });
281
284
 
282
- this.addEventListener("monster-slider-moved", (e) => {
283
- const index = e.detail.index;
284
- const thumbnail = thumbnails.children[index];
285
+ this.addEventListener("monster-slider-moved", (e) => {
286
+ const index = e.detail.index;
287
+ const thumbnail = thumbnails.children[index];
285
288
 
286
- if (!thumbnail) {
287
- return;
288
- }
289
+ if (!thumbnail) {
290
+ return;
291
+ }
289
292
 
290
- Array.from(thumbnails.children).forEach((thumb) => {
291
- thumb.classList.remove("current");
292
- });
293
+ Array.from(thumbnails.children).forEach((thumb) => {
294
+ thumb.classList.remove("current");
295
+ });
293
296
 
294
- thumbnail.classList.add("current");
295
- });
297
+ thumbnail.classList.add("current");
298
+ });
296
299
  }
297
300
 
298
301
  /**
299
302
  * @private
300
303
  */
301
304
  function initAutoPlay() {
302
- const self = this;
303
- const autoPlay = this.getOption("autoPlay");
304
- const delay = autoPlay.delay;
305
- const startDelay = autoPlay.startDelay;
306
- const direction = autoPlay.direction;
307
-
308
- function start() {
309
- if (self[configSymbol].autoPlayInterval) {
310
- clearInterval(self[configSymbol].autoPlayInterval);
311
- }
312
-
313
- self[configSymbol].autoPlayInterval = setInterval(() => {
314
-
315
- const {totalOriginSlides} = getSlidesAndTotal.call(self);
316
-
317
- if (direction === "next") {
318
- if (!self.getOption("features.carousel")&& self[configSymbol].currentIndex >= totalOriginSlides - 1) {
319
- self[configSymbol].currentIndex = -1;
320
- }
321
- self.next();
322
- } else {
323
- if (!self.getOption("features.carousel") && self[configSymbol].currentIndex <= 0) {
324
- self[configSymbol].currentIndex = totalOriginSlides;
325
- }
326
- self.previous();
327
- }
328
- }, delay);
329
- }
330
-
331
- setTimeout(() => {
332
- start();
333
- }, startDelay);
334
-
335
- if (autoPlay.mouseOverPause) {
336
- this.addEventListener("mouseover", () => {
337
- clearInterval(this[configSymbol].autoPlayInterval);
338
- });
339
-
340
- this.addEventListener("mouseout", () => {
341
- if (this[configSymbol].isDragging) {
342
- return;
343
- }
344
- start();
345
- });
346
- }
347
-
348
- if (autoPlay.touchPause) {
349
- this.addEventListener("touchstart", () => {
350
- clearInterval(this[configSymbol].autoPlayInterval);
351
- });
352
-
353
- this.addEventListener("touchend", () => {
354
- start();
355
- });
356
- }
305
+ const self = this;
306
+ const autoPlay = this.getOption("autoPlay");
307
+ const delay = autoPlay.delay;
308
+ const startDelay = autoPlay.startDelay;
309
+ const direction = autoPlay.direction;
310
+
311
+ function start() {
312
+ if (self[configSymbol].autoPlayInterval) {
313
+ clearInterval(self[configSymbol].autoPlayInterval);
314
+ }
315
+
316
+ self[configSymbol].autoPlayInterval = setInterval(() => {
317
+ const { totalOriginSlides } = getSlidesAndTotal.call(self);
318
+
319
+ if (direction === "next") {
320
+ if (
321
+ !self.getOption("features.carousel") &&
322
+ self[configSymbol].currentIndex >= totalOriginSlides - 1
323
+ ) {
324
+ self[configSymbol].currentIndex = -1;
325
+ }
326
+ self.next();
327
+ } else {
328
+ if (
329
+ !self.getOption("features.carousel") &&
330
+ self[configSymbol].currentIndex <= 0
331
+ ) {
332
+ self[configSymbol].currentIndex = totalOriginSlides;
333
+ }
334
+ self.previous();
335
+ }
336
+ }, delay);
337
+ }
338
+
339
+ setTimeout(() => {
340
+ start();
341
+ }, startDelay);
342
+
343
+ if (autoPlay.mouseOverPause) {
344
+ this.addEventListener("mouseover", () => {
345
+ clearInterval(this[configSymbol].autoPlayInterval);
346
+ });
347
+
348
+ this.addEventListener("mouseout", () => {
349
+ if (this[configSymbol].isDragging) {
350
+ return;
351
+ }
352
+ start();
353
+ });
354
+ }
355
+
356
+ if (autoPlay.touchPause) {
357
+ this.addEventListener("touchstart", () => {
358
+ clearInterval(this[configSymbol].autoPlayInterval);
359
+ });
360
+
361
+ this.addEventListener("touchend", () => {
362
+ start();
363
+ });
364
+ }
357
365
  }
358
366
 
359
367
  function getVisibleSlidesFromContainerWidth() {
360
-
361
- const containerWidth = this.shadowRoot.querySelector(`[${ATTRIBUTE_ROLE}="slider"]`).offsetWidth;
362
- const slides = this.getOption("slides");
363
- let visibleSlides = 1;
364
-
365
- if (!isObject(slides)) {
366
- return visibleSlides;
367
- }
368
-
369
- for (const key in slides) {
370
- if (containerWidth >= key) {
371
- visibleSlides = slides[key];
372
- }
373
- }
374
-
375
- const {originSlides} = getSlidesAndTotal.call(this);
376
- if (visibleSlides > originSlides.length) {
377
- visibleSlides = originSlides.length - 1;
378
- }
379
-
380
-
381
- return visibleSlides;
368
+ const containerWidth = this.shadowRoot.querySelector(
369
+ `[${ATTRIBUTE_ROLE}="slider"]`,
370
+ ).offsetWidth;
371
+ const slides = this.getOption("slides");
372
+ let visibleSlides = 1;
373
+
374
+ if (!isObject(slides)) {
375
+ return visibleSlides;
376
+ }
377
+
378
+ for (const key in slides) {
379
+ if (containerWidth >= key) {
380
+ visibleSlides = slides[key];
381
+ }
382
+ }
383
+
384
+ const { originSlides } = getSlidesAndTotal.call(this);
385
+ if (visibleSlides > originSlides.length) {
386
+ visibleSlides = originSlides.length - 1;
387
+ }
388
+
389
+ return visibleSlides;
382
390
  }
383
391
 
384
392
  /**
385
393
  * @private
386
394
  */
387
395
  function initShadows() {
388
- const {slides, totalSlides} = getSlidesAndTotal.call(this);
389
- const slidesVisible = getVisibleSlidesFromContainerWidth.call(this);
390
-
391
- if (totalSlides > slidesVisible) {
392
-
393
- let current = slides[0];
394
- let last = slides[totalSlides - 1];
395
- for (let i = 0; i < slidesVisible; i++) {
396
- const clone = current.cloneNode(true);
397
- clone.setAttribute('data-monster-clone-from', i);
398
- last.insertAdjacentElement('afterend', clone);
399
- current = current.nextElementSibling;
400
- last = clone;
401
- }
402
-
403
- current = slides[totalSlides - 1];
404
- let first = slides[0];
405
- for (let i = 0; i < slidesVisible; i++) {
406
- const clone = current.cloneNode(true);
407
- clone.setAttribute('data-monster-clone-from', totalSlides - i);
408
- first.insertAdjacentElement('beforebegin', clone);
409
- current = current.previousElementSibling;
410
- first = clone;
411
- }
412
-
413
- moveTo.call(this, 0);
414
-
415
- }
396
+ const { slides, totalSlides } = getSlidesAndTotal.call(this);
397
+ const slidesVisible = getVisibleSlidesFromContainerWidth.call(this);
398
+
399
+ if (totalSlides > slidesVisible) {
400
+ let current = slides[0];
401
+ let last = slides[totalSlides - 1];
402
+ for (let i = 0; i < slidesVisible; i++) {
403
+ const clone = current.cloneNode(true);
404
+ clone.setAttribute("data-monster-clone-from", i);
405
+ last.insertAdjacentElement("afterend", clone);
406
+ current = current.nextElementSibling;
407
+ last = clone;
408
+ }
409
+
410
+ current = slides[totalSlides - 1];
411
+ let first = slides[0];
412
+ for (let i = 0; i < slidesVisible; i++) {
413
+ const clone = current.cloneNode(true);
414
+ clone.setAttribute("data-monster-clone-from", totalSlides - i);
415
+ first.insertAdjacentElement("beforebegin", clone);
416
+ current = current.previousElementSibling;
417
+ first = clone;
418
+ }
419
+
420
+ moveTo.call(this, 0);
421
+ }
416
422
  }
417
423
 
418
424
  /**
@@ -420,13 +426,19 @@ function initShadows() {
420
426
  * @return {{slides: unknown[], totalSlides: number}}
421
427
  */
422
428
  function getSlidesAndTotal() {
423
- const originSlides = Array.from(getSlottedElements.call(this, ":scope:not([data-monster-clone-from])", null));
424
- const totalOriginSlides = originSlides.length;
425
-
426
- const slides = Array.from(getSlottedElements.call(this, ":scope", null));
427
- const totalSlides = slides.length;
428
-
429
- return {originSlides, totalOriginSlides, slides, totalSlides};
429
+ const originSlides = Array.from(
430
+ getSlottedElements.call(
431
+ this,
432
+ ":scope:not([data-monster-clone-from])",
433
+ null,
434
+ ),
435
+ );
436
+ const totalOriginSlides = originSlides.length;
437
+
438
+ const slides = Array.from(getSlottedElements.call(this, ":scope", null));
439
+ const totalSlides = slides.length;
440
+
441
+ return { originSlides, totalOriginSlides, slides, totalSlides };
430
442
  }
431
443
 
432
444
  /**
@@ -434,17 +446,17 @@ function getSlidesAndTotal() {
434
446
  * @return {number}
435
447
  */
436
448
  function next() {
437
- const nextIndex = this[configSymbol].currentIndex + 1;
449
+ const nextIndex = this[configSymbol].currentIndex + 1;
438
450
 
439
- queueMicrotask(() => {
440
- getWindow().requestAnimationFrame(() => {
441
- getWindow().requestAnimationFrame(() => {
442
- moveTo.call(this, nextIndex);
443
- });
444
- });
445
- });
451
+ queueMicrotask(() => {
452
+ getWindow().requestAnimationFrame(() => {
453
+ getWindow().requestAnimationFrame(() => {
454
+ moveTo.call(this, nextIndex);
455
+ });
456
+ });
457
+ });
446
458
 
447
- return 0;
459
+ return 0;
448
460
  }
449
461
 
450
462
  /**
@@ -452,17 +464,17 @@ function next() {
452
464
  * @return {number}
453
465
  */
454
466
  function prev() {
455
- const prevIndex = this[configSymbol].currentIndex - 1;
467
+ const prevIndex = this[configSymbol].currentIndex - 1;
456
468
 
457
- queueMicrotask(() => {
458
- getWindow().requestAnimationFrame(() => {
459
- getWindow().requestAnimationFrame(() => {
460
- moveTo.call(this, prevIndex);
461
- });
462
- });
463
- });
469
+ queueMicrotask(() => {
470
+ getWindow().requestAnimationFrame(() => {
471
+ getWindow().requestAnimationFrame(() => {
472
+ moveTo.call(this, prevIndex);
473
+ });
474
+ });
475
+ });
464
476
 
465
- return 0;
477
+ return 0;
466
478
  }
467
479
 
468
480
  /**
@@ -471,25 +483,24 @@ function prev() {
471
483
  * @param index
472
484
  */
473
485
  function setMoveProperties(slides, index) {
474
- slides.forEach((slide) => {
475
- slide.classList.remove("current");
476
- });
477
-
478
- let offset = -(index * 100);
479
- const slidesVisible = getVisibleSlidesFromContainerWidth.call(this);
486
+ slides.forEach((slide) => {
487
+ slide.classList.remove("current");
488
+ });
480
489
 
481
- offset = offset / slidesVisible;
490
+ let offset = -(index * 100);
491
+ const slidesVisible = getVisibleSlidesFromContainerWidth.call(this);
482
492
 
483
- if (offset !== 0) {
484
- offset += "%";
485
- }
493
+ offset = offset / slidesVisible;
486
494
 
487
- this[sliderElementSymbol].style.transform =
488
- `translateX(calc(${offset} + ${this[configSymbol].draggingPos}px))`;
495
+ if (offset !== 0) {
496
+ offset += "%";
497
+ }
489
498
 
490
- slides[index].classList.add("current");
491
- this[configSymbol].lastOffset = offset;
499
+ this[sliderElementSymbol].style.transform =
500
+ `translateX(calc(${offset} + ${this[configSymbol].draggingPos}px))`;
492
501
 
502
+ slides[index].classList.add("current");
503
+ this[configSymbol].lastOffset = offset;
493
504
  }
494
505
 
495
506
  /**
@@ -499,70 +510,68 @@ function setMoveProperties(slides, index) {
499
510
  * @fires monster-slider-moved
500
511
  */
501
512
  function moveTo(index, animation) {
502
-
503
- const {slides, totalSlides, originSlides, totalOriginSlides} = getSlidesAndTotal.call(this);
504
-
505
- if (animation === false) {
506
- this[sliderElementSymbol].classList.remove("animate");
507
- } else {
508
- this[sliderElementSymbol].classList.add("animate");
509
- }
510
-
511
- if (this.getOption("features.carousel") === true) {
512
-
513
- if (index < 0) {
514
- index = -1;
515
- }
516
-
517
- if (index > totalOriginSlides) {
518
- index = totalOriginSlides;
519
- }
520
-
521
- } else {
522
-
523
- if (index < 0) {
524
- index = 0;
525
- }
526
-
527
- if (index >= totalOriginSlides) {
528
- index = totalOriginSlides - 1;
529
- }
530
- }
531
-
532
- if (!isInteger(index)) {
533
- return;
534
- }
535
-
536
- this[configSymbol].currentIndex = index;
537
- let slidesIndex = index + getVisibleSlidesFromContainerWidth.call(this);
538
-
539
- if (slidesIndex < 0) {
540
- slidesIndex = totalSlides - 1 - getVisibleSlidesFromContainerWidth.call(this);
541
- this[configSymbol].currentIndex = totalOriginSlides - 1;
542
- } else if (index > totalOriginSlides) {
543
- slidesIndex = 0;
544
- this[configSymbol].currentIndex = 0;
545
- }
546
-
547
- setMoveProperties.call(this, slides, slidesIndex);
548
-
549
- if (index === totalOriginSlides) {
550
- setTimeout(() => {
551
- getWindow().requestAnimationFrame(() => {
552
- moveTo.call(this, 0, false);
553
- });
554
- }, this.getOption("carousel.transition"));
555
- } else if (index === -1) {
556
- setTimeout(() => {
557
- getWindow().requestAnimationFrame(() => {
558
- moveTo.call(this, totalOriginSlides - 1, false);
559
- });
560
- }, this.getOption("carousel.transition"));
561
- }
562
-
563
- fireCustomEvent(this, "monster-slider-moved", {
564
- index: index,
565
- });
513
+ const { slides, totalSlides, originSlides, totalOriginSlides } =
514
+ getSlidesAndTotal.call(this);
515
+
516
+ if (animation === false) {
517
+ this[sliderElementSymbol].classList.remove("animate");
518
+ } else {
519
+ this[sliderElementSymbol].classList.add("animate");
520
+ }
521
+
522
+ if (this.getOption("features.carousel") === true) {
523
+ if (index < 0) {
524
+ index = -1;
525
+ }
526
+
527
+ if (index > totalOriginSlides) {
528
+ index = totalOriginSlides;
529
+ }
530
+ } else {
531
+ if (index < 0) {
532
+ index = 0;
533
+ }
534
+
535
+ if (index >= totalOriginSlides) {
536
+ index = totalOriginSlides - 1;
537
+ }
538
+ }
539
+
540
+ if (!isInteger(index)) {
541
+ return;
542
+ }
543
+
544
+ this[configSymbol].currentIndex = index;
545
+ let slidesIndex = index + getVisibleSlidesFromContainerWidth.call(this);
546
+
547
+ if (slidesIndex < 0) {
548
+ slidesIndex =
549
+ totalSlides - 1 - getVisibleSlidesFromContainerWidth.call(this);
550
+ this[configSymbol].currentIndex = totalOriginSlides - 1;
551
+ } else if (index > totalOriginSlides) {
552
+ slidesIndex = 0;
553
+ this[configSymbol].currentIndex = 0;
554
+ }
555
+
556
+ setMoveProperties.call(this, slides, slidesIndex);
557
+
558
+ if (index === totalOriginSlides) {
559
+ setTimeout(() => {
560
+ getWindow().requestAnimationFrame(() => {
561
+ moveTo.call(this, 0, false);
562
+ });
563
+ }, this.getOption("carousel.transition"));
564
+ } else if (index === -1) {
565
+ setTimeout(() => {
566
+ getWindow().requestAnimationFrame(() => {
567
+ moveTo.call(this, totalOriginSlides - 1, false);
568
+ });
569
+ }, this.getOption("carousel.transition"));
570
+ }
571
+
572
+ fireCustomEvent(this, "monster-slider-moved", {
573
+ index: index,
574
+ });
566
575
  }
567
576
 
568
577
  /**
@@ -570,35 +579,35 @@ function moveTo(index, animation) {
570
579
  * @return {initEventHandler}
571
580
  */
572
581
  function initEventHandler() {
573
- const self = this;
582
+ const self = this;
574
583
 
575
- const nextElements = this[nextElementSymbol];
584
+ const nextElements = this[nextElementSymbol];
576
585
 
577
- if (nextElements) {
578
- nextElements.addEventListener("click", () => {
579
- self.next();
580
- });
581
- }
586
+ if (nextElements) {
587
+ nextElements.addEventListener("click", () => {
588
+ self.next();
589
+ });
590
+ }
582
591
 
583
- const prevElements = this[prevElementSymbol];
592
+ const prevElements = this[prevElementSymbol];
584
593
 
585
- if (prevElements) {
586
- prevElements.addEventListener("click", () => {
587
- self.previous();
588
- });
589
- }
594
+ if (prevElements) {
595
+ prevElements.addEventListener("click", () => {
596
+ self.previous();
597
+ });
598
+ }
590
599
 
591
- if (this.getOption("features.drag")) {
592
- this[sliderElementSymbol].addEventListener("mousedown", (e) =>
593
- startDragging.call(this, e, "mouse"),
594
- );
600
+ if (this.getOption("features.drag")) {
601
+ this[sliderElementSymbol].addEventListener("mousedown", (e) =>
602
+ startDragging.call(this, e, "mouse"),
603
+ );
595
604
 
596
- this[sliderElementSymbol].addEventListener("touchstart", (e) =>
597
- startDragging.call(this, e, "touch"),
598
- );
599
- }
605
+ this[sliderElementSymbol].addEventListener("touchstart", (e) =>
606
+ startDragging.call(this, e, "touch"),
607
+ );
608
+ }
600
609
 
601
- return this;
610
+ return this;
602
611
  }
603
612
 
604
613
  /**
@@ -607,45 +616,44 @@ function initEventHandler() {
607
616
  * @param type
608
617
  */
609
618
  function startDragging(e, type) {
619
+ const { slides } = getSlidesAndTotal.call(this);
610
620
 
611
- const {slides} = getSlidesAndTotal.call(this);
612
-
613
- const widthOfSlider = slides[this[configSymbol].currentIndex]?.offsetWidth
621
+ const widthOfSlider = slides[this[configSymbol].currentIndex]?.offsetWidth;
614
622
 
615
- this[configSymbol].isDragging = true;
616
- this[configSymbol].startPos = getPositionX(e, type);
617
- this[sliderElementSymbol].classList.add("grabbing");
618
- this[sliderElementSymbol].style.transitionProperty = "none";
623
+ this[configSymbol].isDragging = true;
624
+ this[configSymbol].startPos = getPositionX(e, type);
625
+ this[sliderElementSymbol].classList.add("grabbing");
626
+ this[sliderElementSymbol].style.transitionProperty = "none";
619
627
 
620
- const callbackMousemove = (x) => {
621
- dragging.call(this, x, type);
622
- };
628
+ const callbackMousemove = (x) => {
629
+ dragging.call(this, x, type);
630
+ };
623
631
 
624
- const callbackMouseUp = () => {
625
- const endEvent = type === "mouse" ? "mouseup" : "touchend";
626
- const moveEvent = type === "mouse" ? "mousemove" : "touchmove";
632
+ const callbackMouseUp = () => {
633
+ const endEvent = type === "mouse" ? "mouseup" : "touchend";
634
+ const moveEvent = type === "mouse" ? "mousemove" : "touchmove";
627
635
 
628
- document.body.removeEventListener(endEvent, callbackMouseUp);
629
- document.body.removeEventListener(moveEvent, callbackMousemove);
636
+ document.body.removeEventListener(endEvent, callbackMouseUp);
637
+ document.body.removeEventListener(moveEvent, callbackMousemove);
630
638
 
631
- this[configSymbol].isDragging = false;
632
- this[configSymbol].startPos = 0;
633
- this[sliderElementSymbol].classList.remove("grabbing");
634
- this[sliderElementSymbol].style.transitionProperty = "";
639
+ this[configSymbol].isDragging = false;
640
+ this[configSymbol].startPos = 0;
641
+ this[sliderElementSymbol].classList.remove("grabbing");
642
+ this[sliderElementSymbol].style.transitionProperty = "";
635
643
 
636
- const lastPos = this[configSymbol].draggingPos;
637
- this[configSymbol].draggingPos = 0;
644
+ const lastPos = this[configSymbol].draggingPos;
645
+ this[configSymbol].draggingPos = 0;
638
646
 
639
- let newIndex = this[configSymbol].currentIndex;
640
- const shift = lastPos / widthOfSlider;
641
- const shiftIndex = Math.round(shift);
647
+ let newIndex = this[configSymbol].currentIndex;
648
+ const shift = lastPos / widthOfSlider;
649
+ const shiftIndex = Math.round(shift);
642
650
 
643
- newIndex += (shiftIndex * -1);
644
- this.moveTo(newIndex);
645
- };
651
+ newIndex += shiftIndex * -1;
652
+ this.moveTo(newIndex);
653
+ };
646
654
 
647
- document.body.addEventListener("mouseup", callbackMouseUp);
648
- document.body.addEventListener("mousemove", callbackMousemove);
655
+ document.body.addEventListener("mouseup", callbackMouseUp);
656
+ document.body.addEventListener("mousemove", callbackMousemove);
649
657
  }
650
658
 
651
659
  /**
@@ -655,7 +663,7 @@ function startDragging(e, type) {
655
663
  * @return {*|number|number}
656
664
  */
657
665
  function getPositionX(e, type) {
658
- return type === "mouse" ? e.pageX : e.touches[0].clientX;
666
+ return type === "mouse" ? e.pageX : e.touches[0].clientX;
659
667
  }
660
668
 
661
669
  /**
@@ -664,13 +672,12 @@ function getPositionX(e, type) {
664
672
  * @param type
665
673
  */
666
674
  function dragging(e, type) {
667
- if (!this[configSymbol].isDragging) return;
668
- this[configSymbol].draggingPos =
669
- getPositionX(e, type) - this[configSymbol].startPos;
670
-
671
- this[sliderElementSymbol].style.transform =
672
- `translateX(calc(${this[configSymbol].lastOffset} + ${this[configSymbol].draggingPos}px))`;
675
+ if (!this[configSymbol].isDragging) return;
676
+ this[configSymbol].draggingPos =
677
+ getPositionX(e, type) - this[configSymbol].startPos;
673
678
 
679
+ this[sliderElementSymbol].style.transform =
680
+ `translateX(calc(${this[configSymbol].lastOffset} + ${this[configSymbol].draggingPos}px))`;
674
681
  }
675
682
 
676
683
  /**
@@ -678,21 +685,21 @@ function dragging(e, type) {
678
685
  * @return {void}
679
686
  */
680
687
  function initControlReferences() {
681
- this[controlElementSymbol] = this.shadowRoot.querySelector(
682
- `[${ATTRIBUTE_ROLE}="control"]`,
683
- );
688
+ this[controlElementSymbol] = this.shadowRoot.querySelector(
689
+ `[${ATTRIBUTE_ROLE}="control"]`,
690
+ );
684
691
 
685
- this[sliderElementSymbol] = this.shadowRoot.querySelector(
686
- `[${ATTRIBUTE_ROLE}="slider"]`,
687
- );
692
+ this[sliderElementSymbol] = this.shadowRoot.querySelector(
693
+ `[${ATTRIBUTE_ROLE}="slider"]`,
694
+ );
688
695
 
689
- this[prevElementSymbol] = this.shadowRoot.querySelector(
690
- `[${ATTRIBUTE_ROLE}="prev"]`,
691
- );
696
+ this[prevElementSymbol] = this.shadowRoot.querySelector(
697
+ `[${ATTRIBUTE_ROLE}="prev"]`,
698
+ );
692
699
 
693
- this[nextElementSymbol] = this.shadowRoot.querySelector(
694
- `[${ATTRIBUTE_ROLE}="next"]`,
695
- );
700
+ this[nextElementSymbol] = this.shadowRoot.querySelector(
701
+ `[${ATTRIBUTE_ROLE}="next"]`,
702
+ );
696
703
  }
697
704
 
698
705
  /**
@@ -700,8 +707,8 @@ function initControlReferences() {
700
707
  * @return {string}
701
708
  */
702
709
  function getTemplate() {
703
- // language=HTML
704
- return `
710
+ // language=HTML
711
+ return `
705
712
  <div data-monster-role="control" part="control">
706
713
  <div class="prev" data-monster-role="prev" part="prev" part="prev">
707
714
  <slot name="prev"></slot>