@v-c/slick 0.0.1

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.
@@ -0,0 +1,566 @@
1
+ import default_props_default from "../default-props.js";
2
+ import { getStylePxValue } from "@v-c/util/dist/props-util";
3
+ function getTrackNode(trackRef) {
4
+ if (!trackRef) return null;
5
+ return trackRef.node ?? trackRef;
6
+ }
7
+ function clamp(number, lowerBound, upperBound) {
8
+ return Math.max(lowerBound, Math.min(number, upperBound));
9
+ }
10
+ function safePreventDefault(event) {
11
+ if (!event || typeof event.preventDefault !== "function") return;
12
+ if ("cancelable" in event && event.cancelable === false) return;
13
+ event.preventDefault();
14
+ }
15
+ function getOnDemandLazySlides(spec) {
16
+ const onDemandSlides = [];
17
+ const startIndex = lazyStartIndex(spec);
18
+ const endIndex = lazyEndIndex(spec);
19
+ for (let slideIndex = startIndex; slideIndex < endIndex; slideIndex++) if (!spec.lazyLoadedList.includes(slideIndex)) onDemandSlides.push(slideIndex);
20
+ return onDemandSlides;
21
+ }
22
+ function getRequiredLazySlides(spec) {
23
+ const requiredSlides = [];
24
+ const startIndex = lazyStartIndex(spec);
25
+ const endIndex = lazyEndIndex(spec);
26
+ for (let slideIndex = startIndex; slideIndex < endIndex; slideIndex++) requiredSlides.push(slideIndex);
27
+ return requiredSlides;
28
+ }
29
+ function lazyStartIndex(spec) {
30
+ return spec.currentSlide - lazySlidesOnLeft(spec);
31
+ }
32
+ function lazyEndIndex(spec) {
33
+ return spec.currentSlide + lazySlidesOnRight(spec);
34
+ }
35
+ function lazySlidesOnLeft(spec) {
36
+ return spec.centerMode ? Math.floor(spec.slidesToShow / 2) + (parseInt(spec.centerPadding) > 0 ? 1 : 0) : 0;
37
+ }
38
+ function lazySlidesOnRight(spec) {
39
+ return spec.centerMode ? Math.floor((spec.slidesToShow - 1) / 2) + 1 + (parseInt(spec.centerPadding) > 0 ? 1 : 0) : spec.slidesToShow;
40
+ }
41
+ const getWidth = (elem) => elem && elem.offsetWidth || 0;
42
+ const getHeight = (elem) => elem && elem.offsetHeight || 0;
43
+ function getSwipeDirection(touchObject, verticalSwiping = false) {
44
+ let xDist = 0;
45
+ let yDist = 0;
46
+ let r = 0;
47
+ let swipeAngle = 0;
48
+ xDist = touchObject.startX - touchObject.curX;
49
+ yDist = touchObject.startY - touchObject.curY;
50
+ r = Math.atan2(yDist, xDist);
51
+ swipeAngle = Math.round(r * 180 / Math.PI);
52
+ if (swipeAngle < 0) swipeAngle = 360 - Math.abs(swipeAngle);
53
+ if (swipeAngle <= 45 && swipeAngle >= 0 || swipeAngle <= 360 && swipeAngle >= 315) return "left";
54
+ if (swipeAngle >= 135 && swipeAngle <= 225) return "right";
55
+ if (verticalSwiping === true) if (swipeAngle >= 35 && swipeAngle <= 135) return "up";
56
+ else return "down";
57
+ return "vertical";
58
+ }
59
+ function canGoNext(spec) {
60
+ let canGo = true;
61
+ if (!spec.infinite) {
62
+ if (spec.centerMode && spec.currentSlide >= spec.slideCount - 1) canGo = false;
63
+ else if (spec.slideCount <= spec.slidesToShow || spec.currentSlide >= spec.slideCount - spec.slidesToShow) canGo = false;
64
+ }
65
+ return canGo;
66
+ }
67
+ function extractObject(spec, keys) {
68
+ const newObject = {};
69
+ keys.forEach((key) => newObject[key] = spec[key]);
70
+ return newObject;
71
+ }
72
+ function initializedState(spec) {
73
+ const slideCount = Array.isArray(spec.children) ? spec.children.length : 0;
74
+ const listNode = spec.listRef;
75
+ const listWidth = Math.ceil(getWidth(listNode));
76
+ const trackNode = getTrackNode(spec.trackRef);
77
+ const trackWidth = Math.ceil(getWidth(trackNode));
78
+ let slideWidth = 0;
79
+ if (!spec.vertical) {
80
+ let centerPaddingAdj = spec.centerMode ? parseInt(spec.centerPadding) * 2 : 0;
81
+ if (typeof spec.centerPadding === "string" && spec.centerPadding.slice(-1) === "%") centerPaddingAdj *= listWidth / 100;
82
+ slideWidth = Math.ceil((listWidth - centerPaddingAdj) / spec.slidesToShow);
83
+ } else slideWidth = listWidth;
84
+ const slideHeight = listNode ? getHeight(listNode.querySelector("[data-index=\"0\"]")) : 0;
85
+ const listHeight = slideHeight * spec.slidesToShow;
86
+ let currentSlide = spec.currentSlide === void 0 ? spec.initialSlide : spec.currentSlide;
87
+ if (spec.rtl && spec.currentSlide === void 0) currentSlide = slideCount - 1 - spec.initialSlide;
88
+ let lazyLoadedList = spec.lazyLoadedList || [];
89
+ const slidesToLoad = getOnDemandLazySlides({
90
+ ...spec,
91
+ currentSlide,
92
+ lazyLoadedList
93
+ });
94
+ lazyLoadedList = lazyLoadedList.concat(slidesToLoad);
95
+ const state = {
96
+ slideCount,
97
+ slideWidth,
98
+ listWidth,
99
+ trackWidth,
100
+ currentSlide,
101
+ slideHeight,
102
+ listHeight,
103
+ lazyLoadedList
104
+ };
105
+ if (spec.autoplaying === null && spec.autoplay) state.autoplaying = "playing";
106
+ return state;
107
+ }
108
+ function slideHandler(spec) {
109
+ const { waitForAnimate, animating, fade, infinite, index, slideCount, lazyLoad, currentSlide, centerMode, slidesToScroll, slidesToShow, useCSS } = spec;
110
+ let { lazyLoadedList } = spec;
111
+ if (waitForAnimate && animating) return {};
112
+ let animationSlide = index;
113
+ let finalSlide = 0;
114
+ let animationLeft = 0;
115
+ let finalLeft = 0;
116
+ let state = {};
117
+ let nextState = {};
118
+ const targetSlide = infinite ? index : clamp(index, 0, slideCount - 1);
119
+ if (fade) {
120
+ if (!infinite && (index < 0 || index >= slideCount)) return {};
121
+ if (index < 0) animationSlide = index + slideCount;
122
+ else if (index >= slideCount) animationSlide = index - slideCount;
123
+ if (lazyLoad && !lazyLoadedList.includes(animationSlide)) lazyLoadedList = lazyLoadedList.concat(animationSlide);
124
+ state = {
125
+ animating: true,
126
+ currentSlide: animationSlide,
127
+ lazyLoadedList,
128
+ targetSlide: animationSlide
129
+ };
130
+ nextState = {
131
+ animating: false,
132
+ targetSlide: animationSlide
133
+ };
134
+ } else {
135
+ finalSlide = animationSlide;
136
+ if (animationSlide < 0) {
137
+ finalSlide = animationSlide + slideCount;
138
+ if (!infinite) finalSlide = 0;
139
+ else if (slideCount % slidesToScroll !== 0) finalSlide = slideCount - slideCount % slidesToScroll;
140
+ } else if (!canGoNext(spec) && animationSlide > currentSlide) animationSlide = finalSlide = currentSlide;
141
+ else if (centerMode && animationSlide >= slideCount) {
142
+ animationSlide = infinite ? slideCount : slideCount - 1;
143
+ finalSlide = infinite ? 0 : slideCount - 1;
144
+ } else if (animationSlide >= slideCount) {
145
+ finalSlide = animationSlide - slideCount;
146
+ if (!infinite) finalSlide = slideCount - slidesToShow;
147
+ else if (slideCount % slidesToScroll !== 0) finalSlide = 0;
148
+ }
149
+ if (!infinite && animationSlide + slidesToShow >= slideCount) finalSlide = slideCount - slidesToShow;
150
+ animationLeft = getTrackLeft({
151
+ ...spec,
152
+ slideIndex: animationSlide
153
+ });
154
+ finalLeft = getTrackLeft({
155
+ ...spec,
156
+ slideIndex: finalSlide
157
+ });
158
+ if (!infinite) {
159
+ if (animationLeft === finalLeft) animationSlide = finalSlide;
160
+ animationLeft = finalLeft;
161
+ }
162
+ if (lazyLoad) lazyLoadedList = lazyLoadedList.concat(getOnDemandLazySlides({
163
+ ...spec,
164
+ currentSlide: animationSlide
165
+ }));
166
+ if (!useCSS) state = {
167
+ currentSlide: finalSlide,
168
+ trackStyle: getTrackCSS({
169
+ ...spec,
170
+ left: finalLeft
171
+ }),
172
+ lazyLoadedList,
173
+ targetSlide
174
+ };
175
+ else {
176
+ state = {
177
+ animating: true,
178
+ currentSlide: finalSlide,
179
+ trackStyle: getTrackAnimateCSS({
180
+ ...spec,
181
+ left: animationLeft
182
+ }),
183
+ lazyLoadedList,
184
+ targetSlide
185
+ };
186
+ nextState = {
187
+ animating: false,
188
+ currentSlide: finalSlide,
189
+ trackStyle: getTrackCSS({
190
+ ...spec,
191
+ left: finalLeft
192
+ }),
193
+ swipeLeft: null,
194
+ targetSlide
195
+ };
196
+ }
197
+ }
198
+ return {
199
+ state,
200
+ nextState
201
+ };
202
+ }
203
+ function changeSlide(spec, options) {
204
+ let indexOffset = 0;
205
+ let previousInt = 0;
206
+ let slideOffset = 0;
207
+ let unevenOffset = false;
208
+ let targetSlide = 0;
209
+ const { slidesToScroll, slidesToShow, slideCount, currentSlide, targetSlide: previousTargetSlide, lazyLoad, infinite } = spec;
210
+ unevenOffset = slideCount % slidesToScroll !== 0;
211
+ indexOffset = unevenOffset ? 0 : (slideCount - currentSlide) % slidesToScroll;
212
+ if (options.message === "previous") {
213
+ slideOffset = indexOffset === 0 ? slidesToScroll : slidesToShow - indexOffset;
214
+ targetSlide = currentSlide - slideOffset;
215
+ if (lazyLoad && !infinite) {
216
+ previousInt = currentSlide - slideOffset;
217
+ targetSlide = previousInt === -1 ? slideCount - 1 : previousInt;
218
+ }
219
+ if (!infinite) targetSlide = previousTargetSlide - slidesToScroll;
220
+ } else if (options.message === "next") {
221
+ slideOffset = indexOffset === 0 ? slidesToScroll : indexOffset;
222
+ targetSlide = currentSlide + slideOffset;
223
+ if (lazyLoad && !infinite) targetSlide = (currentSlide + slidesToScroll) % slideCount + indexOffset;
224
+ if (!infinite) targetSlide = previousTargetSlide + slidesToScroll;
225
+ } else if (options.message === "dots") targetSlide = options.index * options.slidesToScroll;
226
+ else if (options.message === "children") {
227
+ targetSlide = options.index;
228
+ if (infinite) {
229
+ const direction = siblingDirection({
230
+ ...spec,
231
+ targetSlide
232
+ });
233
+ if (targetSlide > options.currentSlide && direction === "left") targetSlide = targetSlide - slideCount;
234
+ else if (targetSlide < options.currentSlide && direction === "right") targetSlide = targetSlide + slideCount;
235
+ }
236
+ } else if (options.message === "index") targetSlide = Number(options.index);
237
+ return targetSlide;
238
+ }
239
+ function keyHandler(e, accessibility, rtl) {
240
+ if (e.target.tagName.match("TEXTAREA|INPUT|SELECT") || !accessibility) return "";
241
+ if (e.keyCode === 37) return rtl ? "next" : "previous";
242
+ if (e.keyCode === 39) return rtl ? "previous" : "next";
243
+ return "";
244
+ }
245
+ function swipeStart(e, swipe, draggable) {
246
+ e.target.tagName === "IMG" && safePreventDefault(e);
247
+ if (!swipe || !draggable && e.type.includes("mouse")) return "";
248
+ return {
249
+ dragging: true,
250
+ touchObject: {
251
+ startX: e.touches ? e.touches[0].pageX : e.clientX,
252
+ startY: e.touches ? e.touches[0].pageY : e.clientY,
253
+ curX: e.touches ? e.touches[0].pageX : e.clientX,
254
+ curY: e.touches ? e.touches[0].pageY : e.clientY
255
+ }
256
+ };
257
+ }
258
+ function swipeMove(e, spec) {
259
+ const { scrolling, animating, vertical, swipeToSlide, verticalSwiping, rtl, currentSlide, edgeFriction, edgeDragged, onEdge, swiped, swiping, slideCount, slidesToScroll, infinite, touchObject, swipeEvent, listHeight, listWidth } = spec;
260
+ if (scrolling) return;
261
+ if (animating) return safePreventDefault(e);
262
+ if (vertical && swipeToSlide && verticalSwiping) safePreventDefault(e);
263
+ let swipeLeft = 0;
264
+ let state = {};
265
+ const curLeft = getTrackLeft(spec);
266
+ touchObject.curX = e.touches ? e.touches[0].pageX : e.clientX;
267
+ touchObject.curY = e.touches ? e.touches[0].pageY : e.clientY;
268
+ touchObject.swipeLength = Math.round(Math.sqrt((touchObject.curX - touchObject.startX) ** 2));
269
+ const verticalSwipeLength = Math.round(Math.sqrt((touchObject.curY - touchObject.startY) ** 2));
270
+ if (!verticalSwiping && !swiping && verticalSwipeLength > 10) return { scrolling: true };
271
+ if (verticalSwiping) touchObject.swipeLength = verticalSwipeLength;
272
+ let positionOffset = (!rtl ? 1 : -1) * (touchObject.curX > touchObject.startX ? 1 : -1);
273
+ if (verticalSwiping) positionOffset = touchObject.curY > touchObject.startY ? 1 : -1;
274
+ const dotCount = Math.ceil(slideCount / slidesToScroll);
275
+ const swipeDirection = getSwipeDirection(spec.touchObject, verticalSwiping);
276
+ let touchSwipeLength = touchObject.swipeLength;
277
+ if (!infinite) {
278
+ if (currentSlide === 0 && (swipeDirection === "right" || swipeDirection === "down") || currentSlide + 1 >= dotCount && (swipeDirection === "left" || swipeDirection === "up") || !canGoNext(spec) && (swipeDirection === "left" || swipeDirection === "up")) {
279
+ touchSwipeLength = touchObject.swipeLength * edgeFriction;
280
+ if (edgeDragged === false && onEdge) {
281
+ onEdge(swipeDirection);
282
+ state.edgeDragged = true;
283
+ }
284
+ }
285
+ }
286
+ if (!swiped && swipeEvent) {
287
+ swipeEvent(swipeDirection);
288
+ state.swiped = true;
289
+ }
290
+ if (!vertical) if (!rtl) swipeLeft = curLeft + touchSwipeLength * positionOffset;
291
+ else swipeLeft = curLeft - touchSwipeLength * positionOffset;
292
+ else swipeLeft = curLeft + touchSwipeLength * (listHeight / listWidth) * positionOffset;
293
+ if (verticalSwiping) swipeLeft = curLeft + touchSwipeLength * positionOffset;
294
+ state = {
295
+ ...state,
296
+ touchObject,
297
+ swipeLeft,
298
+ trackStyle: getTrackCSS({
299
+ ...spec,
300
+ left: swipeLeft
301
+ })
302
+ };
303
+ if (Math.abs(touchObject.curX - touchObject.startX) < Math.abs(touchObject.curY - touchObject.startY) * .8) return state;
304
+ if (touchObject.swipeLength > 10) {
305
+ state.swiping = true;
306
+ safePreventDefault(e);
307
+ }
308
+ return state;
309
+ }
310
+ function swipeEnd(e, spec) {
311
+ const { dragging, swipe, touchObject, listWidth, touchThreshold, verticalSwiping, listHeight, swipeToSlide, scrolling, onSwipe, targetSlide, currentSlide, infinite } = spec;
312
+ if (!dragging) {
313
+ if (swipe) safePreventDefault(e);
314
+ return {};
315
+ }
316
+ const minSwipe = verticalSwiping ? listHeight / touchThreshold : listWidth / touchThreshold;
317
+ const swipeDirection = getSwipeDirection(touchObject, verticalSwiping);
318
+ const state = {
319
+ dragging: false,
320
+ edgeDragged: false,
321
+ scrolling: false,
322
+ swiping: false,
323
+ swiped: false,
324
+ swipeLeft: null,
325
+ touchObject: {}
326
+ };
327
+ if (scrolling) return state;
328
+ if (!touchObject.swipeLength) return state;
329
+ if (touchObject.swipeLength > minSwipe) {
330
+ safePreventDefault(e);
331
+ if (onSwipe) onSwipe(swipeDirection);
332
+ let slideCount = 0;
333
+ let newSlide = 0;
334
+ const activeSlide = infinite ? currentSlide : targetSlide;
335
+ switch (swipeDirection) {
336
+ case "left":
337
+ case "up":
338
+ newSlide = activeSlide + getSlideCount(spec);
339
+ slideCount = swipeToSlide ? checkNavigable(spec, newSlide) : newSlide;
340
+ state.currentDirection = 0;
341
+ break;
342
+ case "right":
343
+ case "down":
344
+ newSlide = activeSlide - getSlideCount(spec);
345
+ slideCount = swipeToSlide ? checkNavigable(spec, newSlide) : newSlide;
346
+ state.currentDirection = 1;
347
+ break;
348
+ default: slideCount = activeSlide;
349
+ }
350
+ state.triggerSlideHandler = slideCount;
351
+ } else {
352
+ const currentLeft = getTrackLeft(spec);
353
+ state.trackStyle = getTrackAnimateCSS({
354
+ ...spec,
355
+ left: currentLeft
356
+ });
357
+ }
358
+ return state;
359
+ }
360
+ function getNavigableIndexes(spec) {
361
+ const max = spec.infinite ? spec.slideCount * 2 : spec.slideCount;
362
+ let breakpoint = spec.infinite ? spec.slidesToShow * -1 : 0;
363
+ let counter = spec.infinite ? spec.slidesToShow * -1 : 0;
364
+ const indexes = [];
365
+ while (breakpoint < max) {
366
+ indexes.push(breakpoint);
367
+ breakpoint = counter + spec.slidesToScroll;
368
+ counter += Math.min(spec.slidesToScroll, spec.slidesToShow);
369
+ }
370
+ return indexes;
371
+ }
372
+ function checkNavigable(spec, index) {
373
+ const navigables = getNavigableIndexes(spec);
374
+ let prevNavigable = 0;
375
+ if (index > navigables[navigables.length - 1]) index = navigables[navigables.length - 1];
376
+ else for (const n in navigables) {
377
+ if (index < navigables[n]) {
378
+ index = prevNavigable;
379
+ break;
380
+ }
381
+ prevNavigable = navigables[n];
382
+ }
383
+ return index;
384
+ }
385
+ function getSlideCount(spec) {
386
+ const centerOffset = spec.centerMode ? spec.slideWidth * Math.floor(spec.slidesToShow / 2) : 0;
387
+ if (spec.swipeToSlide) {
388
+ let swipedSlide = null;
389
+ const slickList = spec.listRef;
390
+ const slides = slickList.querySelectorAll && slickList.querySelectorAll(".slick-slide") || [];
391
+ Array.from(slides).every((slide) => {
392
+ if (!spec.vertical) {
393
+ if (slide.offsetLeft - centerOffset + getWidth(slide) / 2 > spec.swipeLeft * -1) {
394
+ swipedSlide = slide;
395
+ return false;
396
+ }
397
+ } else if (slide.offsetTop + getHeight(slide) / 2 > spec.swipeLeft * -1) {
398
+ swipedSlide = slide;
399
+ return false;
400
+ }
401
+ return true;
402
+ });
403
+ if (!swipedSlide) return 0;
404
+ const currentIndex = spec.rtl === true ? spec.slideCount - spec.currentSlide : spec.currentSlide;
405
+ return Math.abs(swipedSlide.dataset.index - currentIndex) || 1;
406
+ } else return spec.slidesToScroll;
407
+ }
408
+ function checkSpecKeys(spec, keysArray) {
409
+ return keysArray.reduce((value, key) => value && Object.prototype.hasOwnProperty.call(spec, key), true) ? null : console.error("Keys Missing:", spec);
410
+ }
411
+ function getTrackCSS(spec) {
412
+ checkSpecKeys(spec, [
413
+ "left",
414
+ "variableWidth",
415
+ "slideCount",
416
+ "slidesToShow",
417
+ "slideWidth"
418
+ ]);
419
+ let trackWidth = 0;
420
+ let trackHeight = 0;
421
+ if (!spec.vertical) trackWidth = getTotalSlides(spec) * spec.slideWidth;
422
+ else trackHeight = (spec.unslick ? spec.slideCount : spec.slideCount + 2 * spec.slidesToShow) * spec.slideHeight;
423
+ let style = {
424
+ opacity: 1,
425
+ transition: "",
426
+ WebkitTransition: ""
427
+ };
428
+ if (spec.useTransform) {
429
+ const WebkitTransform = !spec.vertical ? `translate3d(${spec.left}px, 0px, 0px)` : `translate3d(0px, ${spec.left}px, 0px)`;
430
+ const transform = !spec.vertical ? `translate3d(${spec.left}px, 0px, 0px)` : `translate3d(0px, ${spec.left}px, 0px)`;
431
+ const msTransform = !spec.vertical ? `translateX(${spec.left}px)` : `translateY(${spec.left}px)`;
432
+ style = {
433
+ ...style,
434
+ WebkitTransform,
435
+ transform,
436
+ msTransform
437
+ };
438
+ } else if (spec.vertical) style.top = spec.left;
439
+ else style.left = spec.left;
440
+ if (spec.fade) style = { opacity: 1 };
441
+ if (trackWidth) style.width = getStylePxValue(trackWidth);
442
+ if (trackHeight) style.height = getStylePxValue(trackHeight);
443
+ return style;
444
+ }
445
+ function getTrackAnimateCSS(spec) {
446
+ checkSpecKeys(spec, [
447
+ "left",
448
+ "variableWidth",
449
+ "slideCount",
450
+ "slidesToShow",
451
+ "slideWidth",
452
+ "speed",
453
+ "cssEase"
454
+ ]);
455
+ const style = getTrackCSS(spec);
456
+ if (spec.useTransform) {
457
+ style.WebkitTransition = `-webkit-transform ${spec.speed}ms ${spec.cssEase}`;
458
+ style.transition = `transform ${spec.speed}ms ${spec.cssEase}`;
459
+ } else if (spec.vertical) style.transition = `top ${spec.speed}ms ${spec.cssEase}`;
460
+ else style.transition = `left ${spec.speed}ms ${spec.cssEase}`;
461
+ return style;
462
+ }
463
+ function getTrackLeft(spec) {
464
+ if (spec.unslick) return 0;
465
+ checkSpecKeys(spec, [
466
+ "slideIndex",
467
+ "trackRef",
468
+ "infinite",
469
+ "centerMode",
470
+ "slideCount",
471
+ "slidesToShow",
472
+ "slidesToScroll",
473
+ "slideWidth",
474
+ "listWidth",
475
+ "variableWidth",
476
+ "slideHeight"
477
+ ]);
478
+ const { slideIndex, trackRef, infinite, centerMode, slideCount, slidesToShow, slidesToScroll, slideWidth, listWidth, variableWidth, slideHeight, fade, vertical } = spec;
479
+ let slideOffset = 0;
480
+ let targetLeft = 0;
481
+ let targetSlide = null;
482
+ let verticalOffset = 0;
483
+ if (fade || spec.slideCount === 1) return 0;
484
+ let slidesToOffset = 0;
485
+ if (infinite) {
486
+ slidesToOffset = -getPreClones(spec);
487
+ if (slideCount % slidesToScroll !== 0 && slideIndex + slidesToScroll > slideCount) slidesToOffset = -(slideIndex > slideCount ? slidesToShow - (slideIndex - slideCount) : slideCount % slidesToScroll);
488
+ if (centerMode) slidesToOffset += parseInt(String(slidesToShow / 2));
489
+ } else {
490
+ if (slideCount % slidesToScroll !== 0 && slideIndex + slidesToScroll > slideCount) slidesToOffset = slidesToShow - slideCount % slidesToScroll;
491
+ if (centerMode) slidesToOffset = parseInt(String(slidesToShow / 2));
492
+ }
493
+ slideOffset = slidesToOffset * slideWidth;
494
+ verticalOffset = slidesToOffset * slideHeight;
495
+ if (!vertical) targetLeft = slideIndex * slideWidth * -1 + slideOffset;
496
+ else targetLeft = slideIndex * slideHeight * -1 + verticalOffset;
497
+ if (variableWidth === true) {
498
+ let targetSlideIndex = 0;
499
+ const trackElem = getTrackNode(trackRef);
500
+ targetSlideIndex = slideIndex + getPreClones(spec);
501
+ targetSlide = trackElem && trackElem.childNodes[targetSlideIndex];
502
+ targetLeft = targetSlide ? targetSlide.offsetLeft * -1 : 0;
503
+ if (centerMode === true) {
504
+ targetSlideIndex = infinite ? slideIndex + getPreClones(spec) : slideIndex;
505
+ targetSlide = trackElem && trackElem.children[targetSlideIndex];
506
+ targetLeft = 0;
507
+ for (let slide = 0; slide < targetSlideIndex; slide++) targetLeft -= trackElem && trackElem.children[slide] && trackElem.children[slide].offsetWidth;
508
+ targetLeft -= parseInt(spec.centerPadding);
509
+ targetLeft += targetSlide && (listWidth - targetSlide.offsetWidth) / 2;
510
+ }
511
+ }
512
+ return targetLeft;
513
+ }
514
+ function getPreClones(spec) {
515
+ if (spec.unslick || !spec.infinite) return 0;
516
+ if (spec.variableWidth) return spec.slideCount;
517
+ return spec.slidesToShow + (spec.centerMode ? 1 : 0);
518
+ }
519
+ function getPostClones(spec) {
520
+ if (spec.unslick || !spec.infinite) return 0;
521
+ if (spec.variableWidth) return spec.slideCount;
522
+ return spec.slidesToShow + (spec.centerMode ? 1 : 0);
523
+ }
524
+ function getTotalSlides(spec) {
525
+ return spec.slideCount === 1 ? 1 : getPreClones(spec) + spec.slideCount + getPostClones(spec);
526
+ }
527
+ function siblingDirection(spec) {
528
+ if (spec.targetSlide > spec.currentSlide) {
529
+ if (spec.targetSlide > spec.currentSlide + slidesOnRight(spec)) return "left";
530
+ return "right";
531
+ } else {
532
+ if (spec.targetSlide < spec.currentSlide - slidesOnLeft(spec)) return "right";
533
+ return "left";
534
+ }
535
+ }
536
+ function slidesOnRight({ slidesToShow, centerMode, rtl, centerPadding }) {
537
+ if (centerMode) {
538
+ let right = (slidesToShow - 1) / 2 + 1;
539
+ if (parseInt(centerPadding || "0") > 0) right += 1;
540
+ if (rtl && slidesToShow % 2 === 0) right += 1;
541
+ return right;
542
+ }
543
+ if (rtl) return 0;
544
+ return slidesToShow - 1;
545
+ }
546
+ function slidesOnLeft({ slidesToShow, centerMode, rtl, centerPadding }) {
547
+ if (centerMode) {
548
+ let left = (slidesToShow - 1) / 2 + 1;
549
+ if (parseInt(centerPadding || "0") > 0) left += 1;
550
+ if (!rtl && slidesToShow % 2 === 0) left += 1;
551
+ return left;
552
+ }
553
+ if (rtl) return slidesToShow - 1;
554
+ return 0;
555
+ }
556
+ function canUseDOM() {
557
+ return !!(typeof window !== "undefined" && window.document && window.document.createElement);
558
+ }
559
+ const validSettings = Object.keys(default_props_default);
560
+ function filterSettings(settings) {
561
+ return validSettings.reduce((acc, settingName) => {
562
+ if (settings.hasOwnProperty(settingName)) acc[settingName] = settings[settingName];
563
+ return acc;
564
+ }, {});
565
+ }
566
+ export { canGoNext, canUseDOM, changeSlide, checkNavigable, checkSpecKeys, clamp, extractObject, filterSettings, getHeight, getNavigableIndexes, getOnDemandLazySlides, getPostClones, getPreClones, getRequiredLazySlides, getSlideCount, getSwipeDirection, getTotalSlides, getTrackAnimateCSS, getTrackCSS, getTrackLeft, getWidth, initializedState, keyHandler, lazyEndIndex, lazySlidesOnLeft, lazySlidesOnRight, lazyStartIndex, safePreventDefault, siblingDirection, slideHandler, slidesOnLeft, slidesOnRight, swipeEnd, swipeMove, swipeStart, validSettings };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@v-c/slick",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "description": "",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./dist/*": "./dist/*",
16
+ "./package.json": "./package.json"
17
+ },
18
+ "main": "dist/index.js",
19
+ "files": [
20
+ "dist",
21
+ "package.json"
22
+ ],
23
+ "peerDependencies": {
24
+ "vue": "^3.0.0"
25
+ },
26
+ "dependencies": {
27
+ "es-toolkit": "^1.43.0",
28
+ "@v-c/util": "^1.0.4"
29
+ },
30
+ "devDependencies": {},
31
+ "scripts": {
32
+ "build": "vite build",
33
+ "prepublish": "pnpm build",
34
+ "test": "vitest run",
35
+ "patch": "bumpp --release patch",
36
+ "bump": "bumpp"
37
+ }
38
+ }