slickless 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,571 @@
1
+ //#region src/defaults.ts
2
+ var e = {
3
+ arrows: !0,
4
+ dots: !1,
5
+ autoplay: !1,
6
+ autoplaySpeed: 3e3,
7
+ speed: 400,
8
+ cssEase: "cubic-bezier(0.22, 1, 0.36, 1)",
9
+ slidesToShow: 1,
10
+ slidesToScroll: 1,
11
+ infinite: !0,
12
+ fade: !1,
13
+ vertical: !1,
14
+ initialSlide: 0,
15
+ variableWidth: !1,
16
+ centerMode: !1,
17
+ centerPadding: "50px",
18
+ rtl: !1,
19
+ draggable: !0,
20
+ swipeThreshold: 24,
21
+ pauseOnHover: !0,
22
+ pauseOnFocus: !0,
23
+ accessibility: !0,
24
+ adaptiveHeight: !1,
25
+ lazyLoad: !1,
26
+ respectReducedMotion: !0,
27
+ prevArrow: null,
28
+ nextArrow: null,
29
+ customPaging: null,
30
+ ariaRoleDescription: "carousel",
31
+ responsive: null,
32
+ asNavFor: null,
33
+ focusOnSelect: !1,
34
+ autoplayDirection: "forward"
35
+ };
36
+ function t(e, t) {
37
+ return {
38
+ ...e,
39
+ ...t
40
+ };
41
+ }
42
+ //#endregion
43
+ //#region src/utils.ts
44
+ function n(e, t, n) {
45
+ return Math.max(t, Math.min(n, e));
46
+ }
47
+ function r(e, t) {
48
+ return (e % t + t) % t;
49
+ }
50
+ function i() {
51
+ return typeof window > "u" || !window.matchMedia ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
52
+ }
53
+ function a(e, t, n) {
54
+ let r = document.createElement(e);
55
+ if (t && (r.className = t), n) for (let [e, t] of Object.entries(n)) r.setAttribute(e, t);
56
+ return r;
57
+ }
58
+ function o(e) {
59
+ return e ? typeof e == "string" ? document.querySelector(e) : e : null;
60
+ }
61
+ //#endregion
62
+ //#region src/slickless.ts
63
+ var s = {
64
+ root: "slickless",
65
+ initialized: "slickless--initialized",
66
+ viewport: "slickless__viewport",
67
+ track: "slickless__track",
68
+ slide: "slickless__slide",
69
+ slideActive: "slickless__slide--active",
70
+ slideCenter: "slickless__slide--center",
71
+ slideCloned: "slickless__slide--cloned",
72
+ slideCurrent: "slickless__slide--current",
73
+ arrow: "slickless__arrow",
74
+ arrowPrev: "slickless__arrow--prev",
75
+ arrowNext: "slickless__arrow--next",
76
+ arrowDisabled: "slickless__arrow--disabled",
77
+ dots: "slickless__dots",
78
+ dot: "slickless__dot",
79
+ dotBullet: "slickless__dot--bullet",
80
+ dotActive: "slickless__dot--active",
81
+ vertical: "slickless--vertical",
82
+ fade: "slickless--fade",
83
+ rtl: "slickless--rtl",
84
+ dragging: "slickless--dragging",
85
+ centerMode: "slickless--center",
86
+ adaptive: "slickless--adaptive-height"
87
+ }, c = class {
88
+ constructor(n, r = {}) {
89
+ this.originalChildren = [], this.slides = [], this.prevArrow = null, this.nextArrow = null, this.dotsList = null, this.cloneCount = 0, this.currentIndex = 0, this.animatingTo = null, this.slideCount = 0, this.animating = !1, this.lastRootWidth = 0, this.destroyed = !1, this.currentBreakpoint = null, this.resizeObserver = null, this.autoplayTimer = null, this.autoplayPaused = !1, this.listeners = /* @__PURE__ */ new Map(), this.pointer = null, this.pointerHandlers = {}, this.linkedNav = null, this.linkedFromExternal = !1, this.handlePrevClick = (e) => {
90
+ e.preventDefault(), this.prev();
91
+ }, this.handleNextClick = (e) => {
92
+ e.preventDefault(), this.next();
93
+ }, this.handleResize = () => {
94
+ let e = this.root.getBoundingClientRect().width;
95
+ e !== this.lastRootWidth && (this.lastRootWidth = e, this.applyResponsive(), this.applyLayout());
96
+ }, this.handleKey = (e) => {
97
+ this.options.accessibility && (e.key === "ArrowLeft" ? (e.preventDefault(), this.options.rtl ? this.next() : this.prev()) : e.key === "ArrowRight" ? (e.preventDefault(), this.options.rtl ? this.prev() : this.next()) : e.key === "Home" ? (e.preventDefault(), this.goTo(0)) : e.key === "End" && (e.preventDefault(), this.goTo(this.slideCount - 1)));
98
+ }, this.handleMouseEnter = () => {
99
+ this.options.pauseOnHover && this.options.autoplay && (this.autoplayPaused = !0, this.autoplayTimer && clearTimeout(this.autoplayTimer));
100
+ }, this.handleMouseLeave = () => {
101
+ this.options.pauseOnHover && this.options.autoplay && (this.autoplayPaused = !1, this.scheduleAutoplay());
102
+ }, this.handleFocusIn = () => {
103
+ this.options.pauseOnFocus && this.options.autoplay && (this.autoplayPaused = !0, this.autoplayTimer && clearTimeout(this.autoplayTimer));
104
+ }, this.handleFocusOut = (e) => {
105
+ if (this.options.pauseOnFocus && this.options.autoplay) {
106
+ let t = e.relatedTarget;
107
+ (!t || !this.root.contains(t)) && (this.autoplayPaused = !1, this.scheduleAutoplay());
108
+ }
109
+ };
110
+ let i = typeof n == "string" ? document.querySelector(n) : n;
111
+ if (!i) throw Error(`[slickless] Root element not found: ${String(n)}`);
112
+ this.root = i, this.userOptions = r, this.options = t(e, r), this.init();
113
+ }
114
+ init() {
115
+ this.captureChildren(), this.applyResponsive(), this.build(), this.bindEvents(), this.goTo(this.options.initialSlide, !0), this.options.autoplay && this.play(), this.linkAsNavFor(), this.root.__slickless = this, this.root.classList.add(s.initialized);
116
+ let e = () => {
117
+ this.destroyed || this.emit("init", { slickless: this });
118
+ };
119
+ typeof queueMicrotask == "function" ? queueMicrotask(e) : Promise.resolve().then(e);
120
+ }
121
+ destroy() {
122
+ if (!this.destroyed) {
123
+ this.pause(), this.unbindEvents(), this.resizeObserver && this.resizeObserver.disconnect(), this.root.innerHTML = "";
124
+ for (let e of this.originalChildren) this.root.appendChild(e), e.removeAttribute("aria-hidden"), e.removeAttribute("tabindex"), e.removeAttribute("role"), e.removeAttribute("aria-roledescription"), e.removeAttribute("aria-label"), e.style.cssText = "";
125
+ this.root.className = this.root.className.split(/\s+/).filter((e) => !e.startsWith("slickless")).join(" ").trim(), this.root.removeAttribute("role"), this.root.removeAttribute("aria-roledescription"), this.root.removeAttribute("dir"), this.destroyed = !0, this.emit("destroy", { slickless: this }), this.listeners.clear();
126
+ }
127
+ }
128
+ reInit() {
129
+ let r = this.currentIndex, i = this.options.autoplay && !this.autoplayPaused;
130
+ this.pause(), this.unbindEvents(), this.resizeObserver && this.resizeObserver.disconnect(), this.root.innerHTML = "";
131
+ for (let e of this.originalChildren) this.root.appendChild(e);
132
+ this.options = t(e, this.userOptions), this.applyResponsive(), this.build(), this.bindEvents(), this.goTo(n(r, 0, this.slideCount - 1), !0), i && this.play(), this.emit("reInit", { slickless: this });
133
+ }
134
+ captureChildren() {
135
+ this.originalChildren.length === 0 && (this.originalChildren = Array.from(this.root.children));
136
+ }
137
+ applyResponsive() {
138
+ let n = this.options.responsive;
139
+ if (!n || n.length === 0 || typeof window > "u") return;
140
+ let r = window.innerWidth, i = [...n].sort((e, t) => e.breakpoint - t.breakpoint), a = null;
141
+ for (let e of i) if (r <= e.breakpoint) {
142
+ a = e;
143
+ break;
144
+ }
145
+ let o = a ? a.breakpoint : null;
146
+ if (o === this.currentBreakpoint) return;
147
+ if (this.currentBreakpoint = o, a) {
148
+ if (a.settings === "unslick") {
149
+ this.destroy();
150
+ return;
151
+ }
152
+ this.options = t(t(e, this.userOptions), a.settings);
153
+ } else this.options = t(e, this.userOptions);
154
+ let s = { breakpoint: o };
155
+ this.emit("breakpoint", s);
156
+ }
157
+ build() {
158
+ this.root.innerHTML = "", this.root.classList.add(s.root), this.root.classList.toggle(s.vertical, this.options.vertical), this.root.classList.toggle(s.fade, this.options.fade), this.root.classList.toggle(s.rtl, this.options.rtl), this.root.classList.toggle(s.centerMode, this.options.centerMode), this.root.classList.toggle(s.adaptive, this.options.adaptiveHeight), this.root.style.setProperty("--slickless-transition-duration", `${this.effectiveSpeed()}ms`), this.root.setAttribute("role", "region"), this.root.setAttribute("aria-roledescription", this.options.ariaRoleDescription), this.options.rtl && this.root.setAttribute("dir", "rtl"), this.viewport = a("div", s.viewport), this.track = a("div", s.track, { role: "presentation" });
159
+ let e = this.originalChildren.map((e, t) => this.wrapAsSlide(e, t));
160
+ if (this.slideCount = e.length, this.options.infinite && !this.options.fade && this.slideCount > 0) {
161
+ let t = this.options.variableWidth ? this.slideCount : Math.max(this.options.slidesToShow, 1);
162
+ this.cloneCount = Math.min(t, this.slideCount);
163
+ let n = e.slice(-this.cloneCount).map((e) => this.cloneSlide(e)), r = e.slice(0, this.cloneCount).map((e) => this.cloneSlide(e));
164
+ this.slides = [
165
+ ...n,
166
+ ...e,
167
+ ...r
168
+ ];
169
+ } else this.cloneCount = 0, this.slides = e;
170
+ for (let e of this.slides) this.track.appendChild(e);
171
+ this.viewport.appendChild(this.track), this.root.appendChild(this.viewport), this.options.arrows && this.slideCount > this.options.slidesToShow && this.buildArrows(), this.options.dots && this.slideCount > 0 && this.buildDots(), this.applyLayout(), this.applyLazyLoad();
172
+ }
173
+ wrapAsSlide(e, t) {
174
+ let n = a("div", s.slide, {
175
+ role: "group",
176
+ "aria-roledescription": "slide",
177
+ "aria-label": `${t + 1} of ${this.originalChildren.length}`,
178
+ "data-slick-index": String(t)
179
+ });
180
+ return n.appendChild(e), n;
181
+ }
182
+ cloneSlide(e) {
183
+ let t = e.cloneNode(!0);
184
+ return t.classList.add(s.slideCloned), t.setAttribute("aria-hidden", "true"), t.setAttribute("tabindex", "-1"), t;
185
+ }
186
+ buildArrows() {
187
+ let e = this.options.prevArrow, t = this.options.nextArrow;
188
+ this.prevArrow = this.resolveArrow(e, "prev"), this.nextArrow = this.resolveArrow(t, "next"), this.root.appendChild(this.prevArrow), this.root.appendChild(this.nextArrow), this.prevArrow.addEventListener("click", this.handlePrevClick), this.nextArrow.addEventListener("click", this.handleNextClick);
189
+ }
190
+ resolveArrow(e, t) {
191
+ let n;
192
+ if (e instanceof HTMLElement) n = e.cloneNode(!0);
193
+ else if (typeof e == "string" && e.trim()) {
194
+ let t = document.createElement("div");
195
+ t.innerHTML = e.trim(), n = t.firstElementChild ?? a("button");
196
+ } else n = a("button", "", { type: "button" }), n.innerHTML = t === "prev" ? "<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M15 6l-6 6 6 6\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>" : "<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 6l6 6-6 6\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>";
197
+ return n.classList.add(s.arrow, t === "prev" ? s.arrowPrev : s.arrowNext), n.setAttribute("aria-label", t === "prev" ? "Previous slide" : "Next slide"), n.tagName !== "BUTTON" && n.setAttribute("role", "button"), n;
198
+ }
199
+ buildDots() {
200
+ this.dotsList = a("ul", s.dots, { role: "tablist" });
201
+ let e = this.pageCount();
202
+ for (let t = 0; t < e; t++) {
203
+ let n = a("li", "", { role: "presentation" }), r = t * this.options.slidesToScroll, i = this.options.customPaging ? this.options.customPaging(t, e) : a("button", `${s.dot} ${s.dotBullet}`, {
204
+ type: "button",
205
+ "aria-label": `Go to slide ${t + 1}`,
206
+ role: "tab"
207
+ }), o = typeof i == "string" ? this.htmlToElement(i) : i;
208
+ o.classList.add(s.dot), o.setAttribute("data-slick-target", String(r)), o.addEventListener("click", () => this.goTo(r)), n.appendChild(o), this.dotsList.appendChild(n);
209
+ }
210
+ this.root.appendChild(this.dotsList);
211
+ }
212
+ htmlToElement(e) {
213
+ let t = document.createElement("div");
214
+ t.innerHTML = e.trim();
215
+ let n = t.firstElementChild;
216
+ if (n) return n;
217
+ let r = a("button", "", { type: "button" });
218
+ return r.textContent = e, r;
219
+ }
220
+ viewportSize() {
221
+ let e = this.viewport.getBoundingClientRect();
222
+ return this.options.vertical ? e.height : e.width;
223
+ }
224
+ slideSize() {
225
+ if (this.options.variableWidth) {
226
+ let e = this.slides[this.cloneCount];
227
+ if (e) {
228
+ let t = e.getBoundingClientRect();
229
+ return this.options.vertical ? t.height : t.width;
230
+ }
231
+ }
232
+ let e = this.viewportSize();
233
+ if (this.options.centerMode) {
234
+ let t = this.parseCenterPadding(e);
235
+ return Math.max(1, (e - 2 * t) / Math.max(1, this.options.slidesToShow));
236
+ }
237
+ return e / Math.max(1, this.options.slidesToShow);
238
+ }
239
+ parseCenterPadding(e) {
240
+ let t = (this.options.centerPadding ?? "").trim();
241
+ if (!t) return 0;
242
+ let n = /^(-?\d+(?:\.\d+)?)\s*(px|%)?$/.exec(t);
243
+ if (!n || n[1] === void 0) return 0;
244
+ let r = parseFloat(n[1]);
245
+ return !Number.isFinite(r) || r < 0 ? 0 : (n[2] ?? "px") === "%" ? r / 100 * e : r;
246
+ }
247
+ applyLayout() {
248
+ if (this.slideCount === 0) return;
249
+ if (this.viewportSize(), this.options.fade) {
250
+ this.track.style.transform = "";
251
+ for (let e = 0; e < this.slides.length; e++) {
252
+ let t = this.slides[e];
253
+ t && (t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.width = "100%", t.style.height = "100%", t.style.opacity = e === this.realToTrackIndex(this.currentIndex) ? "1" : "0", t.style.zIndex = e === this.realToTrackIndex(this.currentIndex) ? "1" : "0", t.style.transition = `opacity ${this.effectiveSpeed()}ms ${this.options.cssEase}`, t.style.pointerEvents = e === this.realToTrackIndex(this.currentIndex) ? "auto" : "none");
254
+ }
255
+ this.updateAria(), this.updateArrows(), this.updateDots();
256
+ return;
257
+ }
258
+ let e = this.options.variableWidth ? null : this.slideSize();
259
+ for (let t of this.slides) t.style.position = "", t.style.top = "", t.style.left = "", t.style.height = "", t.style.opacity = "", t.style.zIndex = "", t.style.transition = "", t.style.pointerEvents = "", e !== null && (this.options.vertical ? (t.style.width = "100%", t.style.height = `${e}px`) : (t.style.height = "", t.style.width = `${e}px`));
260
+ this.translateTo(this.indexToOffset(this.realToTrackIndex(this.currentIndex)), !1), this.updateAria(), this.updateArrows(), this.updateDots(), this.updateAdaptiveHeight();
261
+ }
262
+ effectiveSpeed() {
263
+ return this.options.respectReducedMotion && i() ? 0 : this.options.speed;
264
+ }
265
+ indexToOffset(e) {
266
+ if (this.options.variableWidth) {
267
+ let t = 0;
268
+ for (let n = 0; n < e; n++) {
269
+ let e = this.slides[n];
270
+ if (!e) continue;
271
+ let r = e.getBoundingClientRect();
272
+ t += this.options.vertical ? r.height : r.width;
273
+ }
274
+ if (this.options.centerMode) {
275
+ let n = this.slides[e];
276
+ if (n) {
277
+ let e = n.getBoundingClientRect();
278
+ t -= (this.viewportSize() - (this.options.vertical ? e.height : e.width)) / 2;
279
+ }
280
+ }
281
+ return t;
282
+ }
283
+ let t = this.slideSize(), n = e * t;
284
+ if (this.options.centerMode) n -= (this.viewportSize() - t) / 2;
285
+ else if (!this.options.infinite && !this.options.fade) {
286
+ let e = Math.max(0, (this.slideCount - this.options.slidesToShow) * t);
287
+ n = Math.min(n, e);
288
+ }
289
+ return n;
290
+ }
291
+ translateTo(e, t) {
292
+ let n = t ? this.effectiveSpeed() : 0, r = this.options.vertical ? "Y" : "X", i = this.options.rtl && !this.options.vertical ? 1 : -1;
293
+ this.track.style.transition = n > 0 ? `transform ${n}ms ${this.options.cssEase}` : "", this.track.style.transform = `translate${r}(${i * e}px)`;
294
+ }
295
+ next() {
296
+ this.goTo(this.currentIndex + this.options.slidesToScroll);
297
+ }
298
+ prev() {
299
+ this.goTo(this.currentIndex - this.options.slidesToScroll);
300
+ }
301
+ goTo(e, t = !1) {
302
+ if (this.destroyed || this.slideCount === 0 || this.animating && !t) return;
303
+ let n = e, i = this.options.infinite && !this.options.fade;
304
+ if (!i) {
305
+ let e = Math.max(0, this.slideCount - 1);
306
+ n < 0 && (this.emit("edge", { direction: this.options.rtl ? "right" : "left" }), n = 0), n > e && (this.emit("edge", { direction: this.options.rtl ? "left" : "right" }), n = e);
307
+ }
308
+ let a = {
309
+ currentSlide: this.currentIndex,
310
+ nextSlide: i ? r(n, this.slideCount) : n
311
+ };
312
+ if (this.emit("beforeChange", a), !i || this.options.fade) {
313
+ this.currentIndex = n, this.applyLayout();
314
+ let e = { currentSlide: this.currentIndex };
315
+ this.emit("afterChange", e), this.applyLazyLoad(), this.notifyLinked();
316
+ return;
317
+ }
318
+ this.animating = !0;
319
+ let o = n + this.cloneCount;
320
+ this.animatingTo = o;
321
+ let s = this.indexToOffset(o);
322
+ this.translateTo(s, !t), this.updateAdaptiveHeight(o), this.updateCenterMode(o), this.updateDots(r(n, this.slideCount));
323
+ let c = !1, l = () => {
324
+ if (c) return;
325
+ c = !0, this.animating = !1;
326
+ let e = r(n, this.slideCount), t = e !== n;
327
+ if (this.currentIndex = e, t) {
328
+ let t = e + this.cloneCount;
329
+ this.suppressSlideTransitionsForOneFrame(), this.translateTo(this.indexToOffset(t), !1);
330
+ }
331
+ this.animatingTo = null, this.updateAria(), this.updateArrows(), this.updateDots();
332
+ let i = { currentSlide: this.currentIndex };
333
+ this.emit("afterChange", i), this.applyLazyLoad(), this.notifyLinked();
334
+ };
335
+ if (t || this.effectiveSpeed() === 0) l();
336
+ else {
337
+ let e = (t) => {
338
+ t.target === this.track && t.propertyName === "transform" && (this.track.removeEventListener("transitionend", e), l());
339
+ };
340
+ this.track.addEventListener("transitionend", e), setTimeout(() => {
341
+ this.animating && (this.track.removeEventListener("transitionend", e), l());
342
+ }, this.effectiveSpeed() + 50);
343
+ }
344
+ }
345
+ play() {
346
+ this.destroyed || (this.options.autoplay = !0, this.autoplayPaused = !1, this.scheduleAutoplay());
347
+ }
348
+ pause() {
349
+ this.autoplayPaused = !0, this.autoplayTimer &&= (clearTimeout(this.autoplayTimer), null);
350
+ }
351
+ scheduleAutoplay() {
352
+ !this.options.autoplay || this.autoplayPaused || (this.autoplayTimer && clearTimeout(this.autoplayTimer), this.autoplayTimer = setTimeout(() => {
353
+ this.options.autoplayDirection === "backward" ? this.prev() : this.next(), this.scheduleAutoplay();
354
+ }, this.options.autoplaySpeed));
355
+ }
356
+ on(e, t) {
357
+ this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set());
358
+ let n = this.listeners.get(e);
359
+ return n.add(t), () => n.delete(t);
360
+ }
361
+ off(e, t) {
362
+ this.listeners.get(e)?.delete(t);
363
+ }
364
+ emit(e, t) {
365
+ this.listeners.get(e)?.forEach((e) => e(t)), this.root.dispatchEvent(new CustomEvent(`slickless:${e}`, {
366
+ detail: t,
367
+ bubbles: !1
368
+ }));
369
+ }
370
+ bindEvents() {
371
+ this.root.addEventListener("keydown", this.handleKey), this.root.addEventListener("mouseenter", this.handleMouseEnter), this.root.addEventListener("mouseleave", this.handleMouseLeave), this.root.addEventListener("focusin", this.handleFocusIn), this.root.addEventListener("focusout", this.handleFocusOut), this.root.setAttribute("tabindex", "0"), typeof ResizeObserver < "u" ? (this.resizeObserver = new ResizeObserver(() => this.handleResize()), this.resizeObserver.observe(this.root)) : typeof window < "u" && window.addEventListener("resize", this.handleResize), this.options.draggable && !this.options.fade && this.bindPointerEvents(), this.options.focusOnSelect && this.bindFocusOnSelect();
372
+ }
373
+ unbindEvents() {
374
+ this.root.removeEventListener("keydown", this.handleKey), this.root.removeEventListener("mouseenter", this.handleMouseEnter), this.root.removeEventListener("mouseleave", this.handleMouseLeave), this.root.removeEventListener("focusin", this.handleFocusIn), this.root.removeEventListener("focusout", this.handleFocusOut), typeof window < "u" && window.removeEventListener("resize", this.handleResize), this.prevArrow && this.prevArrow.removeEventListener("click", this.handlePrevClick), this.nextArrow && this.nextArrow.removeEventListener("click", this.handleNextClick), this.unbindPointerEvents();
375
+ }
376
+ bindPointerEvents() {
377
+ let e = (e) => {
378
+ if (this.animating || e.button !== void 0 && e.button !== 0) return;
379
+ let t = this.parseTranslate();
380
+ this.pointer = {
381
+ id: e.pointerId,
382
+ startX: e.clientX,
383
+ startY: e.clientY,
384
+ startTime: performance.now(),
385
+ startTransform: t,
386
+ active: !0,
387
+ decided: !1,
388
+ isHorizontal: !this.options.vertical
389
+ }, this.track.style.transition = "", this.root.classList.add(s.dragging);
390
+ }, t = (e) => {
391
+ if (!this.pointer || !this.pointer.active || this.pointer.id !== e.pointerId) return;
392
+ let t = e.clientX - this.pointer.startX, n = e.clientY - this.pointer.startY;
393
+ if (!this.pointer.decided) {
394
+ let e = Math.abs(t), r = Math.abs(n);
395
+ if (e < 6 && r < 6) return;
396
+ if (this.pointer.isHorizontal = e > r, this.pointer.decided = !0, this.options.vertical ? this.pointer.isHorizontal : !this.pointer.isHorizontal) {
397
+ this.pointer.active = !1, this.root.classList.remove(s.dragging);
398
+ return;
399
+ }
400
+ }
401
+ let r = this.options.vertical ? n : t, i = this.options.rtl && !this.options.vertical ? -1 : 1, a = this.pointer.startTransform - i * r, o = this.options.vertical ? "Y" : "X", c = this.options.rtl && !this.options.vertical ? 1 : -1;
402
+ this.track.style.transform = `translate${o}(${c * a}px)`, typeof e.preventDefault == "function" && e.preventDefault();
403
+ }, n = (e) => {
404
+ if (!this.pointer || this.pointer.id !== e.pointerId) return;
405
+ let t = this.pointer.active, n = e.clientX - this.pointer.startX, r = e.clientY - this.pointer.startY, i = performance.now() - this.pointer.startTime;
406
+ if (this.root.classList.remove(s.dragging), this.pointer = null, !t) return;
407
+ let a = this.options.vertical ? r : n, o = Math.abs(a) / Math.max(1, i), c = this.options.swipeThreshold;
408
+ Math.abs(a) > c || o > .6 ? (this.options.rtl && !this.options.vertical ? a < 0 : a > 0) ? (this.emit("swipe", { direction: this.options.vertical ? "down" : "right" }), this.prev()) : (this.emit("swipe", { direction: this.options.vertical ? "up" : "left" }), this.next()) : this.goTo(this.currentIndex, !0);
409
+ }, r = (e) => {
410
+ !this.pointer || this.pointer.id !== e.pointerId || (this.root.classList.remove(s.dragging), this.pointer = null, this.goTo(this.currentIndex, !0));
411
+ }, i = e, a = t, o = n, c = r;
412
+ this.pointerHandlers = {
413
+ down: i,
414
+ move: a,
415
+ up: o,
416
+ cancel: c
417
+ }, this.viewport.addEventListener("pointerdown", i), window.addEventListener("pointermove", a, { passive: !1 }), window.addEventListener("pointerup", o), window.addEventListener("pointercancel", c);
418
+ }
419
+ unbindPointerEvents() {
420
+ let { down: e, move: t, up: n, cancel: r } = this.pointerHandlers;
421
+ e && (this.viewport.removeEventListener("pointerdown", e), t && window.removeEventListener("pointermove", t), n && window.removeEventListener("pointerup", n), r && window.removeEventListener("pointercancel", r), this.pointerHandlers = {});
422
+ }
423
+ parseTranslate() {
424
+ let e = this.track.style.transform, t = /translate[XY]\((-?\d+(?:\.\d+)?)px\)/.exec(e);
425
+ return !t || !t[1] ? this.indexToOffset(this.realToTrackIndex(this.currentIndex)) : parseFloat(t[1]) / (this.options.rtl && !this.options.vertical ? 1 : -1);
426
+ }
427
+ bindFocusOnSelect() {
428
+ for (let e = 0; e < this.slides.length; e++) {
429
+ let t = this.slides[e];
430
+ t && t.addEventListener("click", () => {
431
+ let t = e - this.cloneCount;
432
+ t >= 0 && t < this.slideCount && this.goTo(t);
433
+ });
434
+ }
435
+ }
436
+ realToTrackIndex(e) {
437
+ return e + this.cloneCount;
438
+ }
439
+ updateAria() {
440
+ let e = this.realToTrackIndex(this.currentIndex);
441
+ for (let t = 0; t < this.slides.length; t++) {
442
+ let n = this.slides[t];
443
+ if (!n) continue;
444
+ let r = this.isSlideInActiveRange(t, e), i = t === e;
445
+ n.classList.toggle(s.slideActive, r), n.classList.toggle(s.slideCurrent, i), n.classList.contains(s.slideCloned) || (n.setAttribute("aria-hidden", r ? "false" : "true"), n.setAttribute("tabindex", r ? "0" : "-1"));
446
+ }
447
+ this.updateCenterMode(e);
448
+ }
449
+ suppressSlideTransitionsForOneFrame() {
450
+ this.root.classList.add("slickless--snap"), this.root.offsetWidth, typeof requestAnimationFrame == "function" ? requestAnimationFrame(() => {
451
+ requestAnimationFrame(() => this.root.classList.remove("slickless--snap"));
452
+ }) : setTimeout(() => this.root.classList.remove("slickless--snap"), 16);
453
+ }
454
+ updateCenterMode(e) {
455
+ if (this.options.centerMode) for (let t = 0; t < this.slides.length; t++) {
456
+ let n = this.slides[t];
457
+ n && n.classList.toggle(s.slideCenter, t === e);
458
+ }
459
+ }
460
+ isSlideInActiveRange(e, t) {
461
+ let n = Math.max(1, this.options.slidesToShow);
462
+ if (this.options.centerMode) {
463
+ let r = Math.floor(n / 2);
464
+ return e >= t - r && e < t + n - r;
465
+ }
466
+ return e >= t && e < t + n;
467
+ }
468
+ updateArrows() {
469
+ if (!this.prevArrow || !this.nextArrow) return;
470
+ if (this.options.infinite || this.options.fade) {
471
+ this.prevArrow.classList.remove(s.arrowDisabled), this.nextArrow.classList.remove(s.arrowDisabled), this.prevArrow.removeAttribute("aria-disabled"), this.nextArrow.removeAttribute("aria-disabled");
472
+ return;
473
+ }
474
+ let e = this.currentIndex <= 0, t = this.currentIndex >= this.slideCount - this.options.slidesToShow;
475
+ this.prevArrow.classList.toggle(s.arrowDisabled, e), this.nextArrow.classList.toggle(s.arrowDisabled, t), this.prevArrow.setAttribute("aria-disabled", String(e)), this.nextArrow.setAttribute("aria-disabled", String(t)), this.prevArrow.tagName === "BUTTON" && (this.prevArrow.disabled = !1), this.nextArrow.tagName === "BUTTON" && (this.nextArrow.disabled = !1);
476
+ }
477
+ pageCount() {
478
+ if (this.slideCount === 0) return 0;
479
+ let e = Math.ceil((this.slideCount - (this.options.infinite ? 0 : this.options.slidesToShow - 1)) / Math.max(1, this.options.slidesToScroll));
480
+ return Math.max(1, e);
481
+ }
482
+ updateDots(e) {
483
+ if (!this.dotsList) return;
484
+ let t = e ?? this.currentIndex, n = Math.floor(t / Math.max(1, this.options.slidesToScroll));
485
+ this.dotsList.querySelectorAll(`.${s.dot}`).forEach((e, t) => {
486
+ e.classList.toggle(s.dotActive, t === n), e.setAttribute("aria-selected", t === n ? "true" : "false");
487
+ });
488
+ }
489
+ updateAdaptiveHeight(e) {
490
+ if (!this.options.adaptiveHeight || this.options.vertical) return;
491
+ let t = e ?? this.animatingTo ?? this.realToTrackIndex(this.currentIndex), n = this.slides[t];
492
+ if (!n) return;
493
+ let r = n.getBoundingClientRect().height;
494
+ r > 0 && (this.viewport.style.height = `${r}px`);
495
+ }
496
+ applyLazyLoad() {
497
+ if (!this.options.lazyLoad) return;
498
+ if (this.options.lazyLoad === "progressive") {
499
+ this.loadImagesIn(this.slides);
500
+ return;
501
+ }
502
+ let e = Math.max(1, this.options.slidesToShow), t = this.realToTrackIndex(this.currentIndex), n = t - 1, i = t + e + 1, a = [];
503
+ for (let e = n; e < i; e++) {
504
+ let t = this.options.infinite ? r(e, this.slides.length) : e;
505
+ if (t < 0 || t >= this.slides.length) continue;
506
+ let n = this.slides[t];
507
+ n && a.push(n);
508
+ }
509
+ this.loadImagesIn(a);
510
+ }
511
+ loadImagesIn(e) {
512
+ for (let t of e) t.querySelectorAll("img[data-lazy]").forEach((e) => this.activateLazyImage(e));
513
+ }
514
+ activateLazyImage(e) {
515
+ let t = e.getAttribute("data-lazy");
516
+ t && (e.removeAttribute("data-lazy"), e.addEventListener("load", () => this.emit("lazyLoaded", {
517
+ image: e,
518
+ src: t
519
+ }), { once: !0 }), e.addEventListener("error", () => this.emit("lazyLoadError", {
520
+ image: e,
521
+ src: t
522
+ }), { once: !0 }), e.src = t);
523
+ }
524
+ linkAsNavFor() {
525
+ let e = this.options.asNavFor;
526
+ if (!e) return;
527
+ let t = o(e);
528
+ if (!t) return;
529
+ let n = t.__slickless;
530
+ n && (this.linkedNav = n, n.on("afterChange", (e) => {
531
+ this.linkedFromExternal ||= (this.linkedFromExternal = !0, this.goTo(e.currentSlide), !1);
532
+ }));
533
+ }
534
+ notifyLinked() {
535
+ this.linkedNav && (this.linkedFromExternal ||= (this.linkedFromExternal = !0, this.linkedNav.goTo(this.currentIndex), !1));
536
+ }
537
+ getCurrentSlide() {
538
+ return this.currentIndex;
539
+ }
540
+ getSlideCount() {
541
+ return this.slideCount;
542
+ }
543
+ getSlides() {
544
+ return this.slides.slice(this.cloneCount, this.cloneCount + this.slideCount);
545
+ }
546
+ setOptions(e, n = !0) {
547
+ this.userOptions = {
548
+ ...this.userOptions,
549
+ ...e
550
+ }, n ? this.reInit() : this.options = t(this.options, e);
551
+ }
552
+ refresh() {
553
+ this.destroyed || this.applyLayout();
554
+ }
555
+ addSlide(e, t) {
556
+ typeof t == "number" ? this.originalChildren.splice(t, 0, e) : this.originalChildren.push(e), this.reInit();
557
+ }
558
+ removeSlide(e) {
559
+ e < 0 || e >= this.originalChildren.length || (this.originalChildren.splice(e, 1), this.reInit());
560
+ }
561
+ };
562
+ //#endregion
563
+ //#region src/index.ts
564
+ function l(e, t = {}) {
565
+ return new c(e, t);
566
+ }
567
+ var u = c;
568
+ //#endregion
569
+ export { e as DEFAULTS, c as Slickless, u as default, l as slickless };
570
+
571
+ //# sourceMappingURL=slickless.js.map