@evermade/overflow-slider 1.0.0 → 2.0.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.
- package/README.md +74 -8
- package/dist/core/details.esm.js +35 -0
- package/dist/core/details.min.js +1 -0
- package/dist/core/overflow-slider.esm.js +26 -0
- package/dist/core/overflow-slider.min.js +1 -0
- package/dist/core/slider.esm.js +260 -0
- package/dist/core/slider.min.js +1 -0
- package/dist/core/utils.esm.js +22 -0
- package/dist/core/utils.min.js +1 -0
- package/dist/index.esm.js +1 -694
- package/dist/index.min.js +1 -2
- package/dist/overflow-slider.css +1 -1
- package/dist/plugins/arrows/arrows/index.esm.js +82 -0
- package/dist/plugins/arrows/arrows/index.min.js +1 -0
- package/dist/plugins/dots/dots/index.esm.js +99 -0
- package/dist/plugins/dots/dots/index.min.js +1 -0
- package/dist/plugins/drag-scrolling/drag-scrolling/index.esm.js +70 -0
- package/dist/plugins/drag-scrolling/drag-scrolling/index.min.js +1 -0
- package/dist/plugins/full-width/full-width/index.esm.js +31 -0
- package/dist/plugins/full-width/full-width/index.min.js +1 -0
- package/dist/plugins/scroll-indicator/scroll-indicator/index.esm.js +133 -0
- package/dist/plugins/scroll-indicator/scroll-indicator/index.min.js +1 -0
- package/dist/plugins/skip-links/skip-links/index.esm.js +42 -0
- package/dist/plugins/skip-links/skip-links/index.min.js +1 -0
- package/dist/plugins/thumbnails/thumbnails/index.esm.js +41 -0
- package/dist/plugins/thumbnails/thumbnails/index.min.js +1 -0
- package/docs/assets/demo.css +151 -5
- package/docs/assets/demo.js +107 -10
- package/docs/dist/core/details.esm.js +35 -0
- package/docs/dist/core/details.min.js +1 -0
- package/docs/dist/core/overflow-slider.esm.js +26 -0
- package/docs/dist/core/overflow-slider.min.js +1 -0
- package/docs/dist/core/slider.esm.js +260 -0
- package/docs/dist/core/slider.min.js +1 -0
- package/docs/dist/core/utils.esm.js +22 -0
- package/docs/dist/core/utils.min.js +1 -0
- package/docs/dist/index.esm.js +1 -0
- package/docs/dist/index.min.js +1 -0
- package/docs/dist/overflow-slider.css +1 -1
- package/docs/dist/plugins/arrows/arrows/index.esm.js +82 -0
- package/docs/dist/plugins/arrows/arrows/index.min.js +1 -0
- package/docs/dist/plugins/dots/dots/index.esm.js +99 -0
- package/docs/dist/plugins/dots/dots/index.min.js +1 -0
- package/docs/dist/plugins/drag-scrolling/drag-scrolling/index.esm.js +70 -0
- package/docs/dist/plugins/drag-scrolling/drag-scrolling/index.min.js +1 -0
- package/docs/dist/plugins/full-width/full-width/index.esm.js +31 -0
- package/docs/dist/plugins/full-width/full-width/index.min.js +1 -0
- package/docs/dist/plugins/scroll-indicator/scroll-indicator/index.esm.js +133 -0
- package/docs/dist/plugins/scroll-indicator/scroll-indicator/index.min.js +1 -0
- package/docs/dist/plugins/skip-links/skip-links/index.esm.js +42 -0
- package/docs/dist/plugins/skip-links/skip-links/index.min.js +1 -0
- package/docs/dist/plugins/thumbnails/thumbnails/index.esm.js +41 -0
- package/docs/dist/plugins/thumbnails/thumbnails/index.min.js +1 -0
- package/docs/index.html +136 -2
- package/package.json +35 -6
- package/rollup.config.js +58 -32
- package/src/core/details.ts +1 -1
- package/src/{overflow-slider.ts → core/overflow-slider.ts} +3 -2
- package/src/core/slider.ts +62 -16
- package/src/core/types.ts +9 -1
- package/src/index.ts +1 -12
- package/src/overflow-slider.scss +10 -183
- package/src/plugins/{arrows.ts → arrows/index.ts} +13 -4
- package/src/plugins/arrows/styles.scss +29 -0
- package/src/plugins/{dots.ts → dots/index.ts} +1 -1
- package/src/plugins/dots/styles.scss +56 -0
- package/src/plugins/{drag-scrolling.ts → drag-scrolling/index.ts} +39 -35
- package/src/plugins/drag-scrolling/styles.scss +12 -0
- package/src/plugins/full-width/index.ts +43 -0
- package/src/plugins/{scroll-indicator.ts → scroll-indicator/index.ts} +36 -20
- package/src/plugins/scroll-indicator/styles.scss +59 -0
- package/src/plugins/{skip-links.ts → skip-links/index.ts} +2 -2
- package/src/plugins/skip-links/styles.scss +35 -0
- package/src/plugins/thumbnails/index.ts +53 -0
- package/tsconfig.json +14 -2
- package/dist/index.esm.min.js +0 -2
- package/dist/index.js +0 -709
- package/docs/dist/overflow-slider.esm.js +0 -694
package/docs/index.html
CHANGED
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
|
|
54
54
|
<div class="entry__item">
|
|
55
55
|
<h3>Mouse Dragging</h3>
|
|
56
|
-
<p>Drag slides with mouse. Uses DragScrollingPlugin.</p>
|
|
57
|
-
<div class="overflow-slider example-container example-container-1-drag-scrolling">
|
|
56
|
+
<p>Drag slides with mouse. Uses DragScrollingPlugin. These slides are clickable.</p>
|
|
57
|
+
<div class="overflow-slider example-container example-container-1-drag-scrolling-clickable">
|
|
58
58
|
<a href="#1" class="example-item example-item--1">1</a>
|
|
59
59
|
<a href="#2" class="example-item example-item--2">2</a>
|
|
60
60
|
<a href="#3" class="example-item example-item--3">3</a>
|
|
@@ -69,6 +69,22 @@
|
|
|
69
69
|
<a href="#12" class="example-item example-item--12">12</a>
|
|
70
70
|
<a href="#13" class="example-item example-item--13">13</a>
|
|
71
71
|
</div>
|
|
72
|
+
<p style="margin-top:1.5rem;">These slides are not clickable</p>
|
|
73
|
+
<div class="overflow-slider example-container example-container-1-drag-scrolling-not-clickable">
|
|
74
|
+
<div class="example-item example-item--1">1</div>
|
|
75
|
+
<div class="example-item example-item--2">2</div>
|
|
76
|
+
<div class="example-item example-item--3">3</div>
|
|
77
|
+
<div class="example-item example-item--4">4</div>
|
|
78
|
+
<div class="example-item example-item--5">5</div>
|
|
79
|
+
<div class="example-item example-item--6">6</div>
|
|
80
|
+
<div class="example-item example-item--7">7</div>
|
|
81
|
+
<div class="example-item example-item--8">8</div>
|
|
82
|
+
<div class="example-item example-item--9">9</div>
|
|
83
|
+
<div class="example-item example-item--10">10</div>
|
|
84
|
+
<div class="example-item example-item--11">11</div>
|
|
85
|
+
<div class="example-item example-item--12">12</div>
|
|
86
|
+
<div class="example-item example-item--13">13</div>
|
|
87
|
+
</div>
|
|
72
88
|
</div>
|
|
73
89
|
|
|
74
90
|
<div class="entry__item">
|
|
@@ -214,6 +230,124 @@
|
|
|
214
230
|
</div>
|
|
215
231
|
</div>
|
|
216
232
|
|
|
233
|
+
<div class="entry__item">
|
|
234
|
+
<h3>Entrance and Exit Animations</h3>
|
|
235
|
+
<p>Animate slides when they appear and disappear.</p>
|
|
236
|
+
<div class="overflow-slider example-container example-container-3-entrance-animation">
|
|
237
|
+
<a href="#1" class="example-item example-item--1">1</a>
|
|
238
|
+
<a href="#2" class="example-item example-item--2">2</a>
|
|
239
|
+
<a href="#3" class="example-item example-item--3">3</a>
|
|
240
|
+
<a href="#4" class="example-item example-item--4">4</a>
|
|
241
|
+
<a href="#5" class="example-item example-item--5">5</a>
|
|
242
|
+
<a href="#6" class="example-item example-item--6">6</a>
|
|
243
|
+
<a href="#7" class="example-item example-item--7">7</a>
|
|
244
|
+
<a href="#8" class="example-item example-item--8">8</a>
|
|
245
|
+
<a href="#9" class="example-item example-item--9">9</a>
|
|
246
|
+
<a href="#10" class="example-item example-item--10">10</a>
|
|
247
|
+
</div>
|
|
248
|
+
</div>
|
|
249
|
+
|
|
250
|
+
</section>
|
|
251
|
+
|
|
252
|
+
<section class="entry__section">
|
|
253
|
+
|
|
254
|
+
<h2>Real Life Usage</h2>
|
|
255
|
+
|
|
256
|
+
<div class="entry__item">
|
|
257
|
+
<h3>Filters</h3>
|
|
258
|
+
<p>Display filter buttons in one line that overflows when necessary.</p>
|
|
259
|
+
<div class="example-4-filters-wrapper">
|
|
260
|
+
<div class="example-4-filters-previous">
|
|
261
|
+
</div>
|
|
262
|
+
<div class="overflow-slider example-container-4-filters">
|
|
263
|
+
<a href="#1" class="example-filter">Development</a>
|
|
264
|
+
<a href="#2" class="example-filter">Design</a>
|
|
265
|
+
<a href="#3" class="example-filter">Marketing</a>
|
|
266
|
+
<a href="#4" class="example-filter">Sales</a>
|
|
267
|
+
<a href="#5" class="example-filter">Support</a>
|
|
268
|
+
<a href="#6" class="example-filter">Management</a>
|
|
269
|
+
<a href="#7" class="example-filter">HR</a>
|
|
270
|
+
<a href="#8" class="example-filter">Finance</a>
|
|
271
|
+
<a href="#9" class="example-filter">Legal</a>
|
|
272
|
+
<a href="#10" class="example-filter">Customer Service</a>
|
|
273
|
+
<a href="#11" class="example-filter">Operations</a>
|
|
274
|
+
<a href="#12" class="example-filter">Other</a>
|
|
275
|
+
</div>
|
|
276
|
+
<div class="example-4-filters-next"></div>
|
|
277
|
+
</div>
|
|
278
|
+
</div>
|
|
279
|
+
|
|
280
|
+
<div class="entry__item">
|
|
281
|
+
<h3>Grid On Desktop, Slider On Mobile</h3>
|
|
282
|
+
<p>Display contents differently for different sized screens.</p>
|
|
283
|
+
<div class="overflow-slider example-container-4-grid-or-slider">
|
|
284
|
+
<a href="#1" class="example-item example-item--1">1</a>
|
|
285
|
+
<a href="#2" class="example-item example-item--2">2</a>
|
|
286
|
+
<a href="#3" class="example-item example-item--3">3</a>
|
|
287
|
+
<a href="#4" class="example-item example-item--4">4</a>
|
|
288
|
+
<a href="#5" class="example-item example-item--5">5</a>
|
|
289
|
+
<a href="#6" class="example-item example-item--6">6</a>
|
|
290
|
+
<a href="#7" class="example-item example-item--7">7</a>
|
|
291
|
+
<a href="#8" class="example-item example-item--8">8</a>
|
|
292
|
+
</div>
|
|
293
|
+
</div>
|
|
294
|
+
|
|
295
|
+
<div class="entry__item">
|
|
296
|
+
<h3>Full Width Slider</h3>
|
|
297
|
+
<p>Allow slides to flow in full screen but center them accoring to your content. Uses FullWidthPlugin.</p>
|
|
298
|
+
<div class="example-container-4-full-width-wrapper">
|
|
299
|
+
<div class="overflow-slider example-container-4-full-width">
|
|
300
|
+
<a href="#1" class="example-item example-item--1">1</a>
|
|
301
|
+
<a href="#2" class="example-item example-item--2">2</a>
|
|
302
|
+
<a href="#3" class="example-item example-item--3">3</a>
|
|
303
|
+
<a href="#4" class="example-item example-item--4">4</a>
|
|
304
|
+
<a href="#5" class="example-item example-item--5">5</a>
|
|
305
|
+
<a href="#6" class="example-item example-item--6">6</a>
|
|
306
|
+
<a href="#7" class="example-item example-item--7">7</a>
|
|
307
|
+
<a href="#8" class="example-item example-item--8">8</a>
|
|
308
|
+
<a href="#9" class="example-item example-item--9">9</a>
|
|
309
|
+
<a href="#10" class="example-item example-item--10">10</a>
|
|
310
|
+
<a href="#11" class="example-item example-item--11">11</a>
|
|
311
|
+
<a href="#12" class="example-item example-item--12">12</a>
|
|
312
|
+
</div>
|
|
313
|
+
</div>
|
|
314
|
+
</div>
|
|
315
|
+
|
|
316
|
+
<div class="entry__item">
|
|
317
|
+
<h3>Synced Slider</h3>
|
|
318
|
+
<p>Sync slides from thumbnails. </p>
|
|
319
|
+
<div class="example-container-4-thumbnails-wrapper">
|
|
320
|
+
<div class="overflow-slider example-container-4-synced-main">
|
|
321
|
+
<a href="#1" class="example-item example-item--1">1</a>
|
|
322
|
+
<a href="#2" class="example-item example-item--2">2</a>
|
|
323
|
+
<a href="#3" class="example-item example-item--3">3</a>
|
|
324
|
+
<a href="#4" class="example-item example-item--4">4</a>
|
|
325
|
+
<a href="#5" class="example-item example-item--5">5</a>
|
|
326
|
+
<a href="#6" class="example-item example-item--6">6</a>
|
|
327
|
+
<a href="#7" class="example-item example-item--7">7</a>
|
|
328
|
+
<a href="#8" class="example-item example-item--8">8</a>
|
|
329
|
+
<a href="#9" class="example-item example-item--9">9</a>
|
|
330
|
+
<a href="#10" class="example-item example-item--10">10</a>
|
|
331
|
+
<a href="#11" class="example-item example-item--11">11</a>
|
|
332
|
+
<a href="#12" class="example-item example-item--12">12</a>
|
|
333
|
+
</div>
|
|
334
|
+
<div class="overflow-slider example-container-4-synced-thumbnails">
|
|
335
|
+
<button class="example-item example-item--1">1</button>
|
|
336
|
+
<button class="example-item example-item--2">2</button>
|
|
337
|
+
<button class="example-item example-item--3">3</button>
|
|
338
|
+
<button class="example-item example-item--4">4</button>
|
|
339
|
+
<button class="example-item example-item--5">5</button>
|
|
340
|
+
<button class="example-item example-item--6">6</button>
|
|
341
|
+
<button class="example-item example-item--7">7</button>
|
|
342
|
+
<button class="example-item example-item--8">8</button>
|
|
343
|
+
<button class="example-item example-item--9">9</button>
|
|
344
|
+
<button class="example-item example-item--10">10</button>
|
|
345
|
+
<button class="example-item example-item--11">11</button>
|
|
346
|
+
<button class="example-item example-item--12">12</button>
|
|
347
|
+
</div>
|
|
348
|
+
</div>
|
|
349
|
+
</div>
|
|
350
|
+
|
|
217
351
|
</section>
|
|
218
352
|
|
|
219
353
|
</div>
|
package/package.json
CHANGED
|
@@ -1,11 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evermade/overflow-slider",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Accessible slider tha works with overflow: auto.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.esm.js",
|
|
12
|
+
"require": "./dist/index.min.js"
|
|
13
|
+
},
|
|
14
|
+
"./plugins/drag-scrolling": {
|
|
15
|
+
"import": "./dist/plugins/drag-scrolling/drag-scrolling/index.esm.js",
|
|
16
|
+
"require": "./dist/plugins/drag-scrolling/drag-scrolling/index.min.js"
|
|
17
|
+
},
|
|
18
|
+
"./plugins/skip-links": {
|
|
19
|
+
"import": "./dist/plugins/skip-links/skip-links/index.esm.js",
|
|
20
|
+
"require": "./dist/plugins/skip-links/skip-links/index.min.js"
|
|
21
|
+
},
|
|
22
|
+
"./plugins/scroll-indicator": {
|
|
23
|
+
"import": "./dist/plugins/scroll-indicator/scroll-indicator/index.esm.js",
|
|
24
|
+
"require": "./dist/plugins/scroll-indicator/scroll-indicator/index.min.js"
|
|
25
|
+
},
|
|
26
|
+
"./plugins/arrows": {
|
|
27
|
+
"import": "./dist/plugins/arrows/arrows/index.esm.js",
|
|
28
|
+
"require": "./dist/plugins/arrows/arrows/index.min.js"
|
|
29
|
+
},
|
|
30
|
+
"./plugins/full-width": {
|
|
31
|
+
"import": "./dist/plugins/full-width/full-width/index.esm.js",
|
|
32
|
+
"require": "./dist/plugins/full-width/full-width/index.min.js"
|
|
33
|
+
},
|
|
34
|
+
"./plugins/dots": {
|
|
35
|
+
"import": "./dist/plugins/dots/dots/index.esm.js",
|
|
36
|
+
"require": "./dist/plugins/dots/dots/index.min.js"
|
|
37
|
+
},
|
|
38
|
+
"./plugins/thumbnails": {
|
|
39
|
+
"import": "./dist/plugins/thumbnails/thumbnails/index.esm.js",
|
|
40
|
+
"require": "./dist/plugins/thumbnails/thumbnails/index.min.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
9
43
|
"repository": {
|
|
10
44
|
"type": "git",
|
|
11
45
|
"url": "git+https://github.com/evermade/overflow-slider.git"
|
|
@@ -46,10 +80,5 @@
|
|
|
46
80
|
"homepage": "https://github.com/evermade/overflow-slider#readme",
|
|
47
81
|
"publishConfig": {
|
|
48
82
|
"access": "public"
|
|
49
|
-
},
|
|
50
|
-
"dependencies": {
|
|
51
|
-
"resize-observer-polyfill": "^1.5.1",
|
|
52
|
-
"scrollbooster": "^3.0.2",
|
|
53
|
-
"simplebar": "^6.2.5"
|
|
54
83
|
}
|
|
55
84
|
}
|
package/rollup.config.js
CHANGED
|
@@ -1,45 +1,71 @@
|
|
|
1
1
|
import { terser } from 'rollup-plugin-terser';
|
|
2
|
-
import pkg from './package.json';
|
|
3
2
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
4
3
|
import commonjs from '@rollup/plugin-commonjs';
|
|
5
4
|
import typescript from '@rollup/plugin-typescript';
|
|
6
5
|
import postcss from 'rollup-plugin-postcss';
|
|
7
6
|
import copy from 'rollup-plugin-copy';
|
|
7
|
+
import glob from 'glob';
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const es = { format: 'es' };
|
|
11
|
-
const minify = {
|
|
12
|
-
plugins: [terser()],
|
|
13
|
-
banner: () => `/*! ${pkg.name} ${pkg.version} */`,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export default {
|
|
17
|
-
input: 'src/index.ts',
|
|
18
|
-
output: [
|
|
19
|
-
// Main files
|
|
20
|
-
{ file: 'dist/index.js', ...umd },
|
|
21
|
-
{ file: 'dist/index.esm.js', ...es },
|
|
22
|
-
{ file: 'docs/dist/overflow-slider.esm.js', ...es },
|
|
23
|
-
// Minified versions
|
|
24
|
-
{ file: 'dist/index.min.js', ...umd, ...minify },
|
|
25
|
-
{ file: 'dist/index.esm.min.js', ...es, ...minify },
|
|
26
|
-
],
|
|
27
|
-
plugins: [
|
|
9
|
+
const plugins = [
|
|
28
10
|
typescript(),
|
|
29
11
|
nodeResolve(),
|
|
30
12
|
commonjs({ include: 'node_modules/**' }),
|
|
31
13
|
postcss({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
minimize: true,
|
|
41
|
-
sourceMap: false,
|
|
42
|
-
extensions: ['.scss', '.css'],
|
|
14
|
+
extract: 'overflow-slider.css',
|
|
15
|
+
plugins: [
|
|
16
|
+
require('autoprefixer'),
|
|
17
|
+
require('cssnano')({ preset: 'default', }),
|
|
18
|
+
],
|
|
19
|
+
minimize: true,
|
|
20
|
+
sourceMap: false,
|
|
21
|
+
extensions: ['.scss', '.css'],
|
|
43
22
|
}),
|
|
44
|
-
|
|
23
|
+
copy({
|
|
24
|
+
targets: [
|
|
25
|
+
{
|
|
26
|
+
src: 'dist/*',
|
|
27
|
+
dest: 'docs/dist',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
hook: 'writeBundle'
|
|
31
|
+
})
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
// Adjusting here to include the core file
|
|
35
|
+
const pluginEntries = {
|
|
36
|
+
index: 'src/index.ts', // Adding the core file
|
|
37
|
+
...glob.sync('src/plugins/**/*.ts').reduce((entries, path) => {
|
|
38
|
+
const name = path.replace(/^src\/plugins\//, '').replace(/\.ts$/, '');
|
|
39
|
+
entries[name] = path;
|
|
40
|
+
return entries;
|
|
41
|
+
}, {}),
|
|
45
42
|
};
|
|
43
|
+
|
|
44
|
+
const baseOutput = {
|
|
45
|
+
preserveModules: true,
|
|
46
|
+
preserveModulesRoot: 'src',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default [
|
|
50
|
+
{
|
|
51
|
+
input: pluginEntries,
|
|
52
|
+
output: {
|
|
53
|
+
...baseOutput,
|
|
54
|
+
dir: 'dist',
|
|
55
|
+
format: 'es',
|
|
56
|
+
entryFileNames: '[name].esm.js',
|
|
57
|
+
},
|
|
58
|
+
plugins,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
input: pluginEntries,
|
|
62
|
+
output: {
|
|
63
|
+
...baseOutput,
|
|
64
|
+
dir: 'dist',
|
|
65
|
+
format: 'es',
|
|
66
|
+
entryFileNames: '[name].min.js',
|
|
67
|
+
plugins: [terser()],
|
|
68
|
+
},
|
|
69
|
+
plugins,
|
|
70
|
+
},
|
|
71
|
+
];
|
package/src/core/details.ts
CHANGED
|
@@ -15,7 +15,7 @@ export default function details( slider: Slider) {
|
|
|
15
15
|
hasOverflow = true;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
slideCount =
|
|
18
|
+
slideCount = slider.slides.length ?? 0;
|
|
19
19
|
|
|
20
20
|
containerWidth = slider.container.offsetWidth;
|
|
21
21
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Slider from './
|
|
1
|
+
import Slider from './slider';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
SliderOptions,
|
|
5
5
|
SliderPlugin,
|
|
6
|
-
} from './
|
|
6
|
+
} from './types';
|
|
7
7
|
|
|
8
8
|
export default function OverflowSlider (
|
|
9
9
|
container: HTMLElement,
|
|
@@ -20,6 +20,7 @@ export default function OverflowSlider (
|
|
|
20
20
|
const defaults = {
|
|
21
21
|
scrollBehavior: "smooth",
|
|
22
22
|
scrollStrategy: "fullSlide",
|
|
23
|
+
slidesSelector: ":scope > *",
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
const sliderOptions = { ...defaults, ...options };
|
package/src/core/slider.ts
CHANGED
|
@@ -14,8 +14,14 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
|
|
|
14
14
|
containerId = generateId( 'overflow-slider' );
|
|
15
15
|
container.setAttribute( 'id', containerId );
|
|
16
16
|
}
|
|
17
|
+
setSlides();
|
|
17
18
|
setDetails(true);
|
|
18
|
-
|
|
19
|
+
setActiveSlideIdx();
|
|
20
|
+
slider.on('contentsChanged', () => {
|
|
21
|
+
setSlides();
|
|
22
|
+
setDetails();
|
|
23
|
+
setActiveSlideIdx();
|
|
24
|
+
});
|
|
19
25
|
slider.on('containerSizeChanged', () => setDetails());
|
|
20
26
|
|
|
21
27
|
let requestId = 0;
|
|
@@ -25,6 +31,7 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
|
|
|
25
31
|
}
|
|
26
32
|
requestId = window.requestAnimationFrame(() => {
|
|
27
33
|
setDetails();
|
|
34
|
+
setActiveSlideIdx();
|
|
28
35
|
});
|
|
29
36
|
};
|
|
30
37
|
slider.on('scroll', setDetailsDebounce);
|
|
@@ -42,6 +49,7 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
|
|
|
42
49
|
setCSSVariables();
|
|
43
50
|
});
|
|
44
51
|
slider.emit('created');
|
|
52
|
+
slider.container.setAttribute('data-ready', 'true');
|
|
45
53
|
};
|
|
46
54
|
|
|
47
55
|
function setDetails( isInit = false ) {
|
|
@@ -55,6 +63,10 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
|
|
|
55
63
|
}
|
|
56
64
|
};
|
|
57
65
|
|
|
66
|
+
function setSlides() {
|
|
67
|
+
slider.slides = Array.from(slider.container.querySelectorAll(slider.options.slidesSelector));
|
|
68
|
+
}
|
|
69
|
+
|
|
58
70
|
function addEventListeners() {
|
|
59
71
|
|
|
60
72
|
// changes to DOM
|
|
@@ -119,8 +131,10 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
|
|
|
119
131
|
scrollTarget = slideStart;
|
|
120
132
|
} else if (slideEnd > scrollLeft + containerWidth) {
|
|
121
133
|
scrollTarget = slideEnd - containerWidth;
|
|
134
|
+
} else if (slideStart === 0) {
|
|
135
|
+
scrollTarget = 0;
|
|
122
136
|
}
|
|
123
|
-
if (scrollTarget) {
|
|
137
|
+
if (scrollTarget !== null) {
|
|
124
138
|
slider.container.style.scrollSnapType = 'none';
|
|
125
139
|
slider.container.scrollLeft = scrollTarget;
|
|
126
140
|
// @todo resume scroll snapping but at least proximity gives a lot of trouble
|
|
@@ -129,6 +143,46 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
|
|
|
129
143
|
}
|
|
130
144
|
};
|
|
131
145
|
|
|
146
|
+
function setActiveSlideIdx() {
|
|
147
|
+
const sliderRect = slider.container.getBoundingClientRect();
|
|
148
|
+
const scrollLeft = slider.container.scrollLeft;
|
|
149
|
+
const slides = slider.slides;
|
|
150
|
+
let activeSlideIdx = 0;
|
|
151
|
+
|
|
152
|
+
for (let i = 0; i < slides.length; i++) {
|
|
153
|
+
const slideRect = slides[i].getBoundingClientRect();
|
|
154
|
+
const slideStart = slideRect.left - sliderRect.left + scrollLeft + getGapSize();
|
|
155
|
+
|
|
156
|
+
if (slideStart > scrollLeft) {
|
|
157
|
+
activeSlideIdx = i;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const oldActiveSlideIdx = slider.activeSlideIdx;
|
|
163
|
+
slider.activeSlideIdx = activeSlideIdx;
|
|
164
|
+
if (oldActiveSlideIdx !== activeSlideIdx) {
|
|
165
|
+
slider.emit('activeSlideChanged');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function moveToSlide( idx: number ) {
|
|
170
|
+
const slide = slider.slides[idx];
|
|
171
|
+
if (slide) {
|
|
172
|
+
ensureSlideIsInView(slide);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
function getGapSize() : number {
|
|
177
|
+
let gapSize = 0;
|
|
178
|
+
if (slider.slides.length > 1) {
|
|
179
|
+
const firstSlideRect = slider.slides[0].getBoundingClientRect();
|
|
180
|
+
const secondSlideRect = slider.slides[1].getBoundingClientRect();
|
|
181
|
+
gapSize = secondSlideRect.left - firstSlideRect.right;
|
|
182
|
+
}
|
|
183
|
+
return gapSize;
|
|
184
|
+
}
|
|
185
|
+
|
|
132
186
|
function moveToDirection(direction = "prev") {
|
|
133
187
|
const scrollStrategy = slider.options.scrollStrategy;
|
|
134
188
|
const scrollLeft = slider.container.scrollLeft;
|
|
@@ -142,26 +196,17 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
|
|
|
142
196
|
}
|
|
143
197
|
if (scrollStrategy === 'fullSlide') {
|
|
144
198
|
let fullSldeTargetScrollPosition = null;
|
|
145
|
-
const slides = Array.from(slider.container.querySelectorAll(':scope > *'));
|
|
146
|
-
|
|
147
|
-
let gapSize = 0;
|
|
148
|
-
|
|
149
|
-
if (slides.length > 1) {
|
|
150
|
-
const firstSlideRect = slides[0].getBoundingClientRect();
|
|
151
|
-
const secondSlideRect = slides[1].getBoundingClientRect();
|
|
152
|
-
gapSize = secondSlideRect.left - firstSlideRect.right;
|
|
153
|
-
}
|
|
154
199
|
|
|
155
200
|
// extend targetScrollPosition to include gap
|
|
156
201
|
if (direction === 'prev') {
|
|
157
|
-
fullSldeTargetScrollPosition = Math.max(0, targetScrollPosition -
|
|
202
|
+
fullSldeTargetScrollPosition = Math.max(0, targetScrollPosition - getGapSize());
|
|
158
203
|
} else {
|
|
159
|
-
fullSldeTargetScrollPosition = Math.min(slider.container.scrollWidth, targetScrollPosition +
|
|
204
|
+
fullSldeTargetScrollPosition = Math.min(slider.container.scrollWidth, targetScrollPosition + getGapSize());
|
|
160
205
|
}
|
|
161
206
|
|
|
162
207
|
if (direction === 'next') {
|
|
163
208
|
let partialSlideFound = false;
|
|
164
|
-
for (let slide of slides) {
|
|
209
|
+
for (let slide of slider.slides) {
|
|
165
210
|
const slideRect = slide.getBoundingClientRect();
|
|
166
211
|
const slideStart = slideRect.left - sliderRect.left + scrollLeft;
|
|
167
212
|
const slideEnd = slideStart + slideRect.width;
|
|
@@ -179,7 +224,7 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
|
|
|
179
224
|
}
|
|
180
225
|
} else {
|
|
181
226
|
let partialSlideFound = false;
|
|
182
|
-
for (let slide of slides) {
|
|
227
|
+
for (let slide of slider.slides) {
|
|
183
228
|
const slideRect = slide.getBoundingClientRect();
|
|
184
229
|
const slideStart = slideRect.left - sliderRect.left + scrollLeft;
|
|
185
230
|
const slideEnd = slideStart + slideRect.width;
|
|
@@ -197,7 +242,7 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
|
|
|
197
242
|
}
|
|
198
243
|
}
|
|
199
244
|
}
|
|
200
|
-
slider.container.style.scrollBehavior =
|
|
245
|
+
slider.container.style.scrollBehavior = slider.options.scrollBehavior;
|
|
201
246
|
slider.container.scrollLeft = targetScrollPosition;
|
|
202
247
|
setTimeout(() => slider.container.style.scrollBehavior = '', 50);
|
|
203
248
|
}
|
|
@@ -224,6 +269,7 @@ export default function Slider( container: HTMLElement, options : SliderOptions,
|
|
|
224
269
|
slider = <Slider>{
|
|
225
270
|
emit,
|
|
226
271
|
moveToDirection,
|
|
272
|
+
moveToSlide,
|
|
227
273
|
on,
|
|
228
274
|
options,
|
|
229
275
|
};
|
package/src/core/types.ts
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
export type Slider<O = {}, C = {}, H extends string = string> = {
|
|
2
2
|
container: HTMLElement
|
|
3
|
+
slides: HTMLElement[]
|
|
3
4
|
emit: (name: H | SliderHooks) => void
|
|
4
5
|
moveToDirection: (
|
|
5
6
|
direction: 'prev' | 'next'
|
|
6
7
|
) => void
|
|
8
|
+
moveToSlide: (
|
|
9
|
+
index: number
|
|
10
|
+
) => void
|
|
7
11
|
on: (
|
|
8
12
|
name: H | SliderHooks,
|
|
9
13
|
cb: (props: Slider<O, C, H>) => void
|
|
10
14
|
) => void
|
|
11
15
|
options: SliderOptions,
|
|
12
16
|
details: SliderDetails,
|
|
17
|
+
activeSlideIdx: number,
|
|
13
18
|
} & C;
|
|
14
19
|
|
|
15
20
|
export type SliderOptions = {
|
|
16
21
|
scrollBehavior: string;
|
|
17
22
|
scrollStrategy: string;
|
|
23
|
+
slidesSelector: string;
|
|
18
24
|
[key: string]: any;
|
|
19
25
|
}
|
|
20
26
|
|
|
@@ -31,11 +37,13 @@ export type SliderHooks =
|
|
|
31
37
|
| HOOK_CREATED
|
|
32
38
|
| HOOK_CONTENTS_CHANGED
|
|
33
39
|
| HOOK_DETAILS_CHANGED
|
|
34
|
-
| HOOK_CONTAINER_SIZE_CHANGED
|
|
40
|
+
| HOOK_CONTAINER_SIZE_CHANGED
|
|
41
|
+
| HOOK_ACTIVE_SLIDE_CHANGED;
|
|
35
42
|
|
|
36
43
|
export type HOOK_CREATED = 'created';
|
|
37
44
|
export type HOOK_DETAILS_CHANGED = 'detailsChanged';
|
|
38
45
|
export type HOOK_CONTENTS_CHANGED = 'contentsChanged';
|
|
39
46
|
export type HOOK_CONTAINER_SIZE_CHANGED = 'containerSizeChanged';
|
|
47
|
+
export type HOOK_ACTIVE_SLIDE_CHANGED = 'activeSlideChanged';
|
|
40
48
|
|
|
41
49
|
export type SliderPlugin = (slider: Slider) => void;
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import './overflow-slider.scss';
|
|
2
2
|
|
|
3
|
-
import OverflowSlider from './overflow-slider';
|
|
4
|
-
|
|
5
|
-
import SkipLinksPlugin from './plugins/skip-links';
|
|
6
|
-
import ArrowsPlugin from './plugins/arrows';
|
|
7
|
-
import ScrollIndicatorPlugin from './plugins/scroll-indicator';
|
|
8
|
-
import DragScrollingPlugin from './plugins/drag-scrolling';
|
|
9
|
-
import DotsPlugin from './plugins/dots';
|
|
3
|
+
import OverflowSlider from './core/overflow-slider';
|
|
10
4
|
|
|
11
5
|
export {
|
|
12
6
|
OverflowSlider,
|
|
13
|
-
DragScrollingPlugin,
|
|
14
|
-
SkipLinksPlugin,
|
|
15
|
-
ArrowsPlugin,
|
|
16
|
-
ScrollIndicatorPlugin,
|
|
17
|
-
DotsPlugin
|
|
18
7
|
};
|