@evermade/overflow-slider 3.2.0 → 3.2.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.
- package/README.md +283 -5
- package/dist/core/slider.esm.js +3 -2
- package/dist/core/utils.esm.js +2 -1
- package/dist/core/utils.min.js +1 -1
- package/docs/dist/core/slider.esm.js +3 -2
- package/docs/dist/core/utils.esm.js +2 -1
- package/docs/dist/core/utils.min.js +1 -1
- package/package.json +1 -1
- package/src/core/slider.ts +8 -6
- package/src/core/types.ts +7 -3
- package/src/core/utils.ts +9 -5
- package/src/plugins/arrows/index.ts +1 -1
- package/src/plugins/dots/index.ts +1 -1
- package/src/plugins/drag-scrolling/index.ts +1 -1
- package/src/plugins/fade/index.ts +1 -1
- package/src/plugins/full-width/index.ts +1 -1
- package/src/plugins/scroll-indicator/index.ts +1 -1
- package/src/plugins/skip-links/index.ts +1 -1
- package/src/plugins/thumbnails/index.ts +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ npm install @evermade/overflow-slider
|
|
|
33
33
|
|
|
34
34
|
Import the `OverflowSlider` along with plugins you want to use.
|
|
35
35
|
|
|
36
|
-
```
|
|
36
|
+
```ts
|
|
37
37
|
import { OverflowSlider } from '@evermade/overflow-slider';
|
|
38
38
|
import DragScrollingPlugin from '@evermade/overflow-slider/plugins/drag-scrolling';
|
|
39
39
|
import SkipLinksPlugin from '@evermade/overflow-slider/plugins/skip-links';
|
|
@@ -135,9 +135,9 @@ Usage:
|
|
|
135
135
|
--gap: 1.5rem;
|
|
136
136
|
gap: var(--gap);
|
|
137
137
|
> * {
|
|
138
|
-
--
|
|
138
|
+
--slides-per-view: 3;
|
|
139
139
|
@include slideWidth(
|
|
140
|
-
var(--
|
|
140
|
+
var(--slides-per-view),
|
|
141
141
|
var(--gap),
|
|
142
142
|
var(--slider-container-width)
|
|
143
143
|
);
|
|
@@ -149,7 +149,280 @@ Note that if you are using FullWidthPlugin, you should use container width from
|
|
|
149
149
|
|
|
150
150
|
## Plugins
|
|
151
151
|
|
|
152
|
-
|
|
152
|
+
### DragScrollingPlugin
|
|
153
|
+
|
|
154
|
+
This plugin allows you to scroll the slider by dragging with a mouse. This works with items that have links or are links themselves.
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import DragScrollingPlugin from '@evermade/overflow-slider/plugins/drag-scrolling';
|
|
158
|
+
|
|
159
|
+
const slider = new OverflowSlider(
|
|
160
|
+
document.querySelector( '.slider-container-here' ),
|
|
161
|
+
{},
|
|
162
|
+
[
|
|
163
|
+
DragScrollingPlugin(), // add options here or don't
|
|
164
|
+
]
|
|
165
|
+
);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
All options are optional.
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
type DragScrollingOptions = {
|
|
172
|
+
draggedDistanceThatPreventsClick: number, // default 10, how much user can drag before it's considered a drag and not a click in case of links
|
|
173
|
+
};
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### ArrowsPlugin
|
|
177
|
+
|
|
178
|
+
This plugin adds previous and next arrows to the slider. You can customize the text, icons and class names.
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
import ArrowsPlugin from '@evermade/overflow-slider/plugins/arrows';
|
|
182
|
+
|
|
183
|
+
const slider = new OverflowSlider(
|
|
184
|
+
document.querySelector( '.slider-container-here' ),
|
|
185
|
+
{},
|
|
186
|
+
[
|
|
187
|
+
ArrowsPlugin(), // add options here or don't
|
|
188
|
+
]
|
|
189
|
+
);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
All options are optional.
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
type ArrowsOptions = {
|
|
196
|
+
texts: {
|
|
197
|
+
buttonPrevious: string;
|
|
198
|
+
buttonNext: string;
|
|
199
|
+
},
|
|
200
|
+
icons: {
|
|
201
|
+
prev: string; // SVG or other HTML
|
|
202
|
+
next: string; // SVG or other HTML
|
|
203
|
+
},
|
|
204
|
+
classNames: {
|
|
205
|
+
navContainer: string;
|
|
206
|
+
prevButton: string;
|
|
207
|
+
nextButton: string;
|
|
208
|
+
},
|
|
209
|
+
container: HTMLElement | null, // container for both arrows
|
|
210
|
+
containerPrev: HTMLElement | null, // container for previous arrow
|
|
211
|
+
containerNext: HTMLElement | null, // container for next arrow
|
|
212
|
+
};
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### ScrollIndicatorPlugin
|
|
216
|
+
|
|
217
|
+
This plugin adds a scroll indicator to the slider. The indicator is a bar that shows how much of the slider is scrolled. Scroll indicator is like a custom scrollbar that is always visible.
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
import ScrollIndicatorPlugin from '@evermade/overflow-slider/plugins/scroll-indicator';
|
|
221
|
+
|
|
222
|
+
const slider = new OverflowSlider(
|
|
223
|
+
document.querySelector( '.slider-container-here' ),
|
|
224
|
+
{},
|
|
225
|
+
[
|
|
226
|
+
ScrollIndicatorPlugin(), // add options here or don't
|
|
227
|
+
]
|
|
228
|
+
);
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
All options are optional.
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
type ScrollIndicatorOptions = {
|
|
235
|
+
classNames: {
|
|
236
|
+
scrollIndicator: string;
|
|
237
|
+
scrollIndicatorBar: string;
|
|
238
|
+
scrollIndicatorButton: string;
|
|
239
|
+
},
|
|
240
|
+
container: HTMLElement | null, // container for the scroll indicator
|
|
241
|
+
};
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### DotsPlugin
|
|
245
|
+
|
|
246
|
+
This plugin adds dots to the slider. Dots are like pagination that shows how many slides there are and which one is active. For usability, scroll indicator is preferable.
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
import DotsPlugin from '@evermade/overflow-slider/plugins/dots';
|
|
250
|
+
|
|
251
|
+
const slider = new OverflowSlider(
|
|
252
|
+
document.querySelector( '.slider-container-here' ),
|
|
253
|
+
{},
|
|
254
|
+
[
|
|
255
|
+
DotsPlugin(), // add options here or don't
|
|
256
|
+
]
|
|
257
|
+
);
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
All options are optional.
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
type DotsOptions = {
|
|
264
|
+
texts: {
|
|
265
|
+
dotDescription: string;
|
|
266
|
+
},
|
|
267
|
+
classNames: {
|
|
268
|
+
dotsContainer: string;
|
|
269
|
+
dotsItem: string;
|
|
270
|
+
},
|
|
271
|
+
container: HTMLElement | null,
|
|
272
|
+
};
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### SkipLinksPlugin
|
|
276
|
+
|
|
277
|
+
This plugin adds skip links to the slider for keyboard users. Skip links are links that allow users to skip the whole slider and land after it. This is useful for accessibility.
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
import SkipLinksPlugin from '@evermade/overflow-slider/plugins/skip-links';
|
|
281
|
+
|
|
282
|
+
const slider = new OverflowSlider(
|
|
283
|
+
document.querySelector( '.slider-container-here' ),
|
|
284
|
+
{},
|
|
285
|
+
[
|
|
286
|
+
SkipLinksPlugin(), // add options here or don't
|
|
287
|
+
]
|
|
288
|
+
);
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
All options are optional.
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
type SkipLinkOptions = {
|
|
295
|
+
texts: {
|
|
296
|
+
skipList: string;
|
|
297
|
+
},
|
|
298
|
+
classNames: {
|
|
299
|
+
skipLink: string;
|
|
300
|
+
skipLinkTarget: string;
|
|
301
|
+
},
|
|
302
|
+
containerBefore: HTMLElement | null,
|
|
303
|
+
containerAfter: HTMLElement | null,
|
|
304
|
+
};
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### FullWidthPlugin
|
|
308
|
+
|
|
309
|
+
This plugin allows you to make the slider full width but have the start of the sliders aligned to your content width. They are scrollable to the full width but the slides are aligned to the content width for the start and end.
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
import FullWidthPlugin from '@evermade/overflow-slider/plugins/full-width';
|
|
313
|
+
|
|
314
|
+
const slider = new OverflowSlider(
|
|
315
|
+
document.querySelector( '.slider-container-here' ),
|
|
316
|
+
{},
|
|
317
|
+
[
|
|
318
|
+
FullWidthPlugin(), // add options here or don't
|
|
319
|
+
]
|
|
320
|
+
);
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
All options are optional.
|
|
324
|
+
|
|
325
|
+
```ts
|
|
326
|
+
type FullWidthOptions = {
|
|
327
|
+
targetWidth: ( slider: Slider ) => number,
|
|
328
|
+
addMarginBefore: boolean,
|
|
329
|
+
addMarginAfter: boolean,
|
|
330
|
+
};
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Example of `targetWidth` function:
|
|
334
|
+
|
|
335
|
+
```ts
|
|
336
|
+
const sliderElement = document.querySelector( '.slider-container-here' );
|
|
337
|
+
const sliderWrapper = document.querySelector( '.slider-wrapper' );
|
|
338
|
+
if ( !sliderElement || !sliderWrapper ) {
|
|
339
|
+
throw new Error( 'Slider element or wrapper not found' );
|
|
340
|
+
}
|
|
341
|
+
const slider = new OverflowSlider(
|
|
342
|
+
sliderElement,
|
|
343
|
+
{},
|
|
344
|
+
[
|
|
345
|
+
FullWidthPlugin({
|
|
346
|
+
targetWidth: ( slider ) => {
|
|
347
|
+
return sliderWrapper.offsetWidth;
|
|
348
|
+
},
|
|
349
|
+
}),
|
|
350
|
+
]
|
|
351
|
+
);
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### FadePlugin
|
|
355
|
+
|
|
356
|
+
This plugin adds a hint that there are more slides to scroll to. It fades the slides at the start and end of the slider to hint that there are more slides to scroll to.
|
|
357
|
+
|
|
358
|
+
```ts
|
|
359
|
+
import FadePlugin from '@evermade/overflow-slider/plugins/fade';
|
|
360
|
+
|
|
361
|
+
const slider = new OverflowSlider(
|
|
362
|
+
document.querySelector( '.slider-container-here' ),
|
|
363
|
+
{},
|
|
364
|
+
[
|
|
365
|
+
FadePlugin(), // add options here or don't
|
|
366
|
+
]
|
|
367
|
+
);
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
All options are optional.
|
|
371
|
+
|
|
372
|
+
```ts
|
|
373
|
+
type FadeOptions = {
|
|
374
|
+
classNames: {
|
|
375
|
+
fadeItem: string;
|
|
376
|
+
fadeItemStart: string;
|
|
377
|
+
fadeItemEnd: string;
|
|
378
|
+
},
|
|
379
|
+
container: HTMLElement | null,
|
|
380
|
+
containerStart: HTMLElement | null,
|
|
381
|
+
containerEnd: HTMLElement | null,
|
|
382
|
+
};
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### ThumbnailsPlugin
|
|
386
|
+
|
|
387
|
+
This plugin adds synchronized thumbnails to the slider. Thumbnails are like dots but they are images of the slides. They are synchronized with the main slider.
|
|
388
|
+
|
|
389
|
+
```ts
|
|
390
|
+
import ThumbnailsPlugin from '@evermade/overflow-slider/plugins/thumbnails';
|
|
391
|
+
|
|
392
|
+
const slider = new OverflowSlider(
|
|
393
|
+
document.querySelector( '.slider-container-here' ),
|
|
394
|
+
{},
|
|
395
|
+
[
|
|
396
|
+
ThumbnailsPlugin(), // add options here or don't
|
|
397
|
+
]
|
|
398
|
+
);
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
You need to set mainSlider reference.
|
|
402
|
+
|
|
403
|
+
```ts
|
|
404
|
+
type ThumbnailsOptions = {
|
|
405
|
+
mainSlider: Slider,
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
Example:
|
|
410
|
+
|
|
411
|
+
```ts
|
|
412
|
+
const mainSlider = new OverflowSlider(
|
|
413
|
+
document.querySelector( '.slider-container-here' ),
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
const thumbnailsSlider = new OverflowSlider(
|
|
417
|
+
document.querySelector( '.thumbnails-container-here' ),
|
|
418
|
+
{},
|
|
419
|
+
[
|
|
420
|
+
ThumbnailsPlugin({
|
|
421
|
+
mainSlider: mainSlider,
|
|
422
|
+
}),
|
|
423
|
+
]
|
|
424
|
+
);
|
|
425
|
+
```
|
|
153
426
|
|
|
154
427
|
## Known issues
|
|
155
428
|
|
|
@@ -159,7 +432,7 @@ You can use use Overflow Slider within CSS grid but if you are using `fr` units
|
|
|
159
432
|
|
|
160
433
|
### CSS scroll-snap can be buggy
|
|
161
434
|
|
|
162
|
-
If you are using `scroll-snap-type` CSS property, you might encounter some bugs like browser wants to snap to a slide regardless of margins.
|
|
435
|
+
If you are using `scroll-snap-type` CSS property, you might encounter some bugs like browser wants to snap to a slide regardless of margins. It's most reliable when there's only one slide per view.
|
|
163
436
|
|
|
164
437
|
## Limitations
|
|
165
438
|
|
|
@@ -183,6 +456,11 @@ Auto-play is not supported at the moment but can probably be implemented as a pl
|
|
|
183
456
|
|
|
184
457
|
## Changelog
|
|
185
458
|
|
|
459
|
+
### 3.2.1
|
|
460
|
+
|
|
461
|
+
* Add: Documentation on plugins
|
|
462
|
+
* Fix: Make types more strict and remove all "any" types
|
|
463
|
+
|
|
186
464
|
### 3.2.0
|
|
187
465
|
|
|
188
466
|
* Add: RTL support
|
package/dist/core/slider.esm.js
CHANGED
|
@@ -78,7 +78,7 @@ function Slider(container, options, plugins) {
|
|
|
78
78
|
let isScrolling = false;
|
|
79
79
|
let isUserScrolling = false;
|
|
80
80
|
let isProgrammaticScrolling = false;
|
|
81
|
-
//
|
|
81
|
+
// all types of scroll
|
|
82
82
|
slider.container.addEventListener('scroll', () => {
|
|
83
83
|
const newScrollLeft = slider.container.scrollLeft;
|
|
84
84
|
if (Math.floor(scrollLeft) !== Math.floor(newScrollLeft)) {
|
|
@@ -463,8 +463,9 @@ function Slider(container, options, plugins) {
|
|
|
463
463
|
});
|
|
464
464
|
}
|
|
465
465
|
const optionCallBack = (_a = slider === null || slider === void 0 ? void 0 : slider.options) === null || _a === void 0 ? void 0 : _a[name];
|
|
466
|
+
// Type guard to check if the option callback is a function
|
|
466
467
|
if (typeof optionCallBack === 'function') {
|
|
467
|
-
optionCallBack(slider);
|
|
468
|
+
optionCallBack(slider); // Type assertion here
|
|
468
469
|
}
|
|
469
470
|
}
|
|
470
471
|
slider = {
|
package/dist/core/utils.esm.js
CHANGED
|
@@ -12,7 +12,8 @@ function objectsAreEqual(obj1, obj2) {
|
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
14
|
for (let key of keys1) {
|
|
15
|
-
|
|
15
|
+
// Use `Object.prototype.hasOwnProperty.call` for better safety
|
|
16
|
+
if (!Object.prototype.hasOwnProperty.call(obj2, key) || obj1[key] !== obj2[key]) {
|
|
16
17
|
return false;
|
|
17
18
|
}
|
|
18
19
|
}
|
package/dist/core/utils.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e
|
|
1
|
+
function t(e,n=1){const r=`${e}-${n}`;return document.getElementById(r)?t(e,n+1):r}function e(t,e){const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(let r of n)if(!Object.prototype.hasOwnProperty.call(e,r)||t[r]!==e[r])return!1;return!0}function n(t){if(0===t.children.length)return 0;const e=t.children[0],n=getComputedStyle(e),r=parseFloat(n.marginLeft),o=t.children[t.children.length-1],l=getComputedStyle(o);return r+parseFloat(l.marginRight)}export{t as generateId,n as getOutermostChildrenEdgeMarginSum,e as objectsAreEqual};
|
|
@@ -78,7 +78,7 @@ function Slider(container, options, plugins) {
|
|
|
78
78
|
let isScrolling = false;
|
|
79
79
|
let isUserScrolling = false;
|
|
80
80
|
let isProgrammaticScrolling = false;
|
|
81
|
-
//
|
|
81
|
+
// all types of scroll
|
|
82
82
|
slider.container.addEventListener('scroll', () => {
|
|
83
83
|
const newScrollLeft = slider.container.scrollLeft;
|
|
84
84
|
if (Math.floor(scrollLeft) !== Math.floor(newScrollLeft)) {
|
|
@@ -463,8 +463,9 @@ function Slider(container, options, plugins) {
|
|
|
463
463
|
});
|
|
464
464
|
}
|
|
465
465
|
const optionCallBack = (_a = slider === null || slider === void 0 ? void 0 : slider.options) === null || _a === void 0 ? void 0 : _a[name];
|
|
466
|
+
// Type guard to check if the option callback is a function
|
|
466
467
|
if (typeof optionCallBack === 'function') {
|
|
467
|
-
optionCallBack(slider);
|
|
468
|
+
optionCallBack(slider); // Type assertion here
|
|
468
469
|
}
|
|
469
470
|
}
|
|
470
471
|
slider = {
|
|
@@ -12,7 +12,8 @@ function objectsAreEqual(obj1, obj2) {
|
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
14
|
for (let key of keys1) {
|
|
15
|
-
|
|
15
|
+
// Use `Object.prototype.hasOwnProperty.call` for better safety
|
|
16
|
+
if (!Object.prototype.hasOwnProperty.call(obj2, key) || obj1[key] !== obj2[key]) {
|
|
16
17
|
return false;
|
|
17
18
|
}
|
|
18
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e
|
|
1
|
+
function t(e,n=1){const r=`${e}-${n}`;return document.getElementById(r)?t(e,n+1):r}function e(t,e){const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(let r of n)if(!Object.prototype.hasOwnProperty.call(e,r)||t[r]!==e[r])return!1;return!0}function n(t){if(0===t.children.length)return 0;const e=t.children[0],n=getComputedStyle(e),r=parseFloat(n.marginLeft),o=t.children[t.children.length-1],l=getComputedStyle(o);return r+parseFloat(l.marginRight)}export{t as generateId,n as getOutermostChildrenEdgeMarginSum,e as objectsAreEqual};
|
package/package.json
CHANGED
package/src/core/slider.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Slider, SliderOptions, SliderPlugin } from './types';
|
|
1
|
+
import { Slider, SliderOptions, SliderPlugin, SliderCallback } from './types';
|
|
2
2
|
import details from './details';
|
|
3
3
|
import { generateId, objectsAreEqual, getOutermostChildrenEdgeMarginSum } from './utils';
|
|
4
4
|
|
|
5
5
|
export default function Slider( container: HTMLElement, options : SliderOptions, plugins? : SliderPlugin[] ) {
|
|
6
6
|
let slider: Slider;
|
|
7
|
-
let subs: { [key: string]:
|
|
7
|
+
let subs: { [key: string]: SliderCallback[] } = {};
|
|
8
8
|
|
|
9
9
|
function init() {
|
|
10
10
|
slider.container = container;
|
|
@@ -91,7 +91,7 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
|
|
|
91
91
|
let isUserScrolling = false;
|
|
92
92
|
let isProgrammaticScrolling = false;
|
|
93
93
|
|
|
94
|
-
//
|
|
94
|
+
// all types of scroll
|
|
95
95
|
slider.container.addEventListener('scroll', () => {
|
|
96
96
|
const newScrollLeft = slider.container.scrollLeft;
|
|
97
97
|
if ( Math.floor( scrollLeft ) !== Math.floor( newScrollLeft ) ) {
|
|
@@ -490,7 +490,7 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
|
|
|
490
490
|
}
|
|
491
491
|
};
|
|
492
492
|
|
|
493
|
-
function on(name: string, cb:
|
|
493
|
+
function on(name: string, cb: SliderCallback) {
|
|
494
494
|
if (!subs[name]) {
|
|
495
495
|
subs[name] = [];
|
|
496
496
|
}
|
|
@@ -500,12 +500,14 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
|
|
|
500
500
|
function emit(name: string) {
|
|
501
501
|
if (subs && subs[name]) {
|
|
502
502
|
subs[name].forEach(cb => {
|
|
503
|
-
|
|
503
|
+
cb(slider);
|
|
504
504
|
});
|
|
505
505
|
}
|
|
506
|
+
|
|
506
507
|
const optionCallBack = slider?.options?.[name];
|
|
508
|
+
// Type guard to check if the option callback is a function
|
|
507
509
|
if (typeof optionCallBack === 'function') {
|
|
508
|
-
|
|
510
|
+
(optionCallBack as SliderCallback)(slider); // Type assertion here
|
|
509
511
|
}
|
|
510
512
|
};
|
|
511
513
|
|
package/src/core/types.ts
CHANGED
|
@@ -17,13 +17,17 @@ export type Slider<O = {}, C = {}, H extends string = string> = {
|
|
|
17
17
|
setScrollLeft: (value: number) => void
|
|
18
18
|
on: (
|
|
19
19
|
name: H | SliderHooks,
|
|
20
|
-
cb:
|
|
20
|
+
cb: SliderCallback
|
|
21
21
|
) => void
|
|
22
22
|
options: SliderOptions,
|
|
23
23
|
details: SliderDetails,
|
|
24
24
|
activeSlideIdx: number,
|
|
25
25
|
} & C;
|
|
26
26
|
|
|
27
|
+
export type SliderCallback<O = {}, C = {}, H extends string = string> = (
|
|
28
|
+
props: Slider<O, C, H>
|
|
29
|
+
) => void;
|
|
30
|
+
|
|
27
31
|
export type SliderOptions = {
|
|
28
32
|
scrollBehavior: string;
|
|
29
33
|
scrollStrategy: string;
|
|
@@ -31,7 +35,7 @@ export type SliderOptions = {
|
|
|
31
35
|
emulateScrollSnap: boolean;
|
|
32
36
|
emulateScrollSnapMaxThreshold: number;
|
|
33
37
|
rtl: boolean;
|
|
34
|
-
[key: string]:
|
|
38
|
+
[key: string]: unknown;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
export type SliderDetails = {
|
|
@@ -65,7 +69,7 @@ export type HOOK_CONTENTS_CHANGED = 'contentsChanged';
|
|
|
65
69
|
export type HOOK_CONTAINER_SIZE_CHANGED = 'containerSizeChanged';
|
|
66
70
|
export type HOOK_ACTIVE_SLIDE_CHANGED = 'activeSlideChanged';
|
|
67
71
|
|
|
68
|
-
//
|
|
72
|
+
// all types of scroll
|
|
69
73
|
export type HOOK_SCROLL_START = 'scrollStart';
|
|
70
74
|
export type HOOK_SCROLL = 'scroll';
|
|
71
75
|
export type HOOK_SCROLL_END = 'scrollEnd';
|
package/src/core/utils.ts
CHANGED
|
@@ -7,17 +7,21 @@ function generateId( prefix : string, i = 1 ): string {
|
|
|
7
7
|
return id;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
function objectsAreEqual(
|
|
10
|
+
function objectsAreEqual(obj1: Record<string, unknown>, obj2: Record<string, unknown>): boolean {
|
|
11
11
|
const keys1 = Object.keys(obj1);
|
|
12
12
|
const keys2 = Object.keys(obj2);
|
|
13
|
+
|
|
13
14
|
if (keys1.length !== keys2.length) {
|
|
14
|
-
|
|
15
|
+
return false;
|
|
15
16
|
}
|
|
17
|
+
|
|
16
18
|
for (let key of keys1) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
// Use `Object.prototype.hasOwnProperty.call` for better safety
|
|
20
|
+
if (!Object.prototype.hasOwnProperty.call(obj2, key) || obj1[key] !== obj2[key]) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
20
23
|
}
|
|
24
|
+
|
|
21
25
|
return true;
|
|
22
26
|
}
|
|
23
27
|
|
|
@@ -35,7 +35,7 @@ export type ArrowsOptions = {
|
|
|
35
35
|
containerNext: HTMLElement | null,
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
export default function ArrowsPlugin( args: { [key: string]:
|
|
38
|
+
export default function ArrowsPlugin( args: { [key: string]: unknown } ) {
|
|
39
39
|
return ( slider: Slider ) => {
|
|
40
40
|
|
|
41
41
|
const options = <ArrowsOptions>{
|
|
@@ -20,7 +20,7 @@ const DEFAULT_CLASS_NAMES = {
|
|
|
20
20
|
dotsItem: 'overflow-slider__dot-item',
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export default function DotsPlugin( args: { [key: string]:
|
|
23
|
+
export default function DotsPlugin( args: { [key: string]: unknown } ) {
|
|
24
24
|
return ( slider: Slider ) => {
|
|
25
25
|
const options = <DotsOptions>{
|
|
26
26
|
texts: {
|
|
@@ -6,7 +6,7 @@ export type DragScrollingOptions = {
|
|
|
6
6
|
draggedDistanceThatPreventsClick: number,
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
export default function DragScrollingPlugin( args: { [key: string]:
|
|
9
|
+
export default function DragScrollingPlugin( args: { [key: string]: unknown } ) {
|
|
10
10
|
const options = <DragScrollingOptions>{
|
|
11
11
|
draggedDistanceThatPreventsClick: args?.draggedDistanceThatPreventsClick ?? DEFAULT_DRAGGED_DISTANCE_THAT_PREVENTS_CLICK,
|
|
12
12
|
};
|
|
@@ -11,7 +11,7 @@ export type FadeOptions = {
|
|
|
11
11
|
containerEnd: HTMLElement | null,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export default function FadePlugin( args: { [key: string]:
|
|
14
|
+
export default function FadePlugin( args: { [key: string]: unknown } ) {
|
|
15
15
|
return ( slider: Slider ) => {
|
|
16
16
|
|
|
17
17
|
const options = <FadeOptions>{
|
|
@@ -8,7 +8,7 @@ export type FullWidthOptions = {
|
|
|
8
8
|
addMarginAfter: boolean,
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export default function FullWidthPlugin( args: { [key: string]:
|
|
11
|
+
export default function FullWidthPlugin( args: { [key: string]: unknown } ) {
|
|
12
12
|
return ( slider: Slider ) => {
|
|
13
13
|
|
|
14
14
|
const options = <FullWidthOptions>{
|
|
@@ -15,7 +15,7 @@ export type ScrollIndicatorOptions = {
|
|
|
15
15
|
container: HTMLElement | null,
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export default function ScrollIndicatorPlugin(args: { [key: string]:
|
|
18
|
+
export default function ScrollIndicatorPlugin(args: { [key: string]: unknown }) {
|
|
19
19
|
return (slider: Slider) => {
|
|
20
20
|
|
|
21
21
|
const options = <ScrollIndicatorOptions>{
|
|
@@ -22,7 +22,7 @@ export type SkipLinkOptions = {
|
|
|
22
22
|
containerAfter: HTMLElement | null,
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
export default function SkipLinksPlugin( args: { [key: string]:
|
|
25
|
+
export default function SkipLinksPlugin( args: { [key: string]: unknown } ) {
|
|
26
26
|
return ( slider: Slider ) => {
|
|
27
27
|
const options = <SkipLinkOptions>{
|
|
28
28
|
texts: {
|
|
@@ -4,7 +4,7 @@ export type ThumbnailsOptions = {
|
|
|
4
4
|
mainSlider: Slider,
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
export default function FullWidthPlugin( args: { [key: string]:
|
|
7
|
+
export default function FullWidthPlugin( args: { [key: string]: unknown } ) {
|
|
8
8
|
return ( slider: Slider ) => {
|
|
9
9
|
|
|
10
10
|
const options = <ThumbnailsOptions>{
|