solid-slider 1.3.16 → 1.3.18
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 +55 -17
- package/dist/adaptiveHeight/index.common.js +2 -4
- package/dist/adaptiveHeight/index.common.js.map +1 -1
- package/dist/adaptiveHeight/index.module.js +2 -2
- package/dist/adaptiveHeight/index.module.js.map +1 -1
- package/dist/adaptiveWidth/index.common.js +2 -4
- package/dist/adaptiveWidth/index.common.js.map +1 -1
- package/dist/adaptiveWidth/index.module.js +2 -2
- package/dist/adaptiveWidth/index.module.js.map +1 -1
- package/dist/autoplay/autoplay.d.ts +2 -2
- package/dist/autoplay/autoplay.jsx +4 -4
- package/dist/autoplay/index.common.js +17 -9
- package/dist/autoplay/index.common.js.map +1 -1
- package/dist/autoplay/index.module.js +17 -7
- package/dist/autoplay/index.module.js.map +1 -1
- package/dist/index/components.d.ts +5 -5
- package/dist/index/index.common.js +213 -71
- package/dist/index/index.common.js.map +1 -1
- package/dist/index/index.module.js +214 -66
- package/dist/index/index.module.js.map +1 -1
- package/dist/index/primitive.d.ts +17 -13
- package/dist/index/primitive.js +14 -13
- package/package.json +18 -15
package/README.md
CHANGED
|
@@ -4,22 +4,28 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/solid-slider)
|
|
5
5
|

|
|
6
6
|
|
|
7
|
-
A carousel/slider implementation in TypeScript for
|
|
7
|
+
A carousel/slider implementation in TypeScript for [Solid](https://www.solidjs.com). It's built on Keen-Slider 6, an open-source library agnostic touch slider with native touch/swipe behavior and great performance. It comes with no dependencies, TypeScript support, multitouch support and is compatible with all common browsers.
|
|
8
8
|
|
|
9
9
|
This package providers both primitive & directive as well as components. You may use either according to your preference. Note that for better SSR support, the component is recommended over the directive.
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npm
|
|
15
|
-
|
|
14
|
+
## npm
|
|
15
|
+
npm install solid-slider
|
|
16
|
+
## bun
|
|
17
|
+
bun add solid-slider
|
|
18
|
+
## yarn
|
|
19
|
+
yarn add solid-slider
|
|
20
|
+
## pnpm
|
|
21
|
+
pnpm add solid-slider
|
|
16
22
|
```
|
|
17
23
|
|
|
18
24
|
Import either the directive or component as you'd like:
|
|
19
25
|
|
|
20
26
|
```ts
|
|
21
|
-
import "solid-slider/slider.css";
|
|
22
27
|
import { Slider, createSlider } from "solid-slider";
|
|
28
|
+
import "solid-slider/slider.css";
|
|
23
29
|
```
|
|
24
30
|
|
|
25
31
|
## Demo
|
|
@@ -97,15 +103,15 @@ const MyComponent = () => {
|
|
|
97
103
|
You may include the adaptive height plugin by providing it as a prop:
|
|
98
104
|
|
|
99
105
|
```tsx
|
|
100
|
-
import createSlider from
|
|
101
|
-
import autoplay from
|
|
106
|
+
import createSlider from "solid-slider";
|
|
107
|
+
import autoplay from "solid-slider/plugins/adaptiveHeight";
|
|
102
108
|
|
|
103
109
|
const MyComponent = () => {
|
|
104
110
|
return (
|
|
105
111
|
<Slider options={{ loop: true }} plugins={[adaptiveHeight]}>
|
|
106
|
-
<div class
|
|
107
|
-
<div class
|
|
108
|
-
<div class
|
|
112
|
+
<div class="slide1">1</div>
|
|
113
|
+
<div class="slide2">2</div>
|
|
114
|
+
<div class="slide3">3</div>
|
|
109
115
|
</Slider>
|
|
110
116
|
);
|
|
111
117
|
};
|
|
@@ -116,15 +122,15 @@ const MyComponent = () => {
|
|
|
116
122
|
You may include the adaptive width plugin by providing it as a prop:
|
|
117
123
|
|
|
118
124
|
```tsx
|
|
119
|
-
import createSlider from
|
|
120
|
-
import autoplay from
|
|
125
|
+
import { createSlider } from "solid-slider";
|
|
126
|
+
import { autoplay } from "solid-slider/plugins/adaptiveWidth";
|
|
121
127
|
|
|
122
128
|
const MyComponent = () => {
|
|
123
129
|
return (
|
|
124
130
|
<Slider options={{ loop: true }} plugins={[adaptiveWidth]}>
|
|
125
|
-
<div class
|
|
126
|
-
<div class
|
|
127
|
-
<div class
|
|
131
|
+
<div class="slide1">1</div>
|
|
132
|
+
<div class="slide2">2</div>
|
|
133
|
+
<div class="slide3">3</div>
|
|
128
134
|
</Slider>
|
|
129
135
|
);
|
|
130
136
|
};
|
|
@@ -168,13 +174,33 @@ const MyComponent = () => {
|
|
|
168
174
|
};
|
|
169
175
|
```
|
|
170
176
|
|
|
177
|
+
The primitive itself returns the following shape:
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
type SliderControls<O, P, H extends string> = [
|
|
181
|
+
create: (el: HTMLElement) => void,
|
|
182
|
+
helpers: {
|
|
183
|
+
current: Accessor<number>;
|
|
184
|
+
next: VoidFunction;
|
|
185
|
+
prev: VoidFunction;
|
|
186
|
+
moveTo: (id: number, duration?: number, absolute?: boolean, easing?: (t: number) => number) => void;
|
|
187
|
+
details: () => TrackDetails;
|
|
188
|
+
slider: () => KeenSliderInstance<O, P, H> | undefined;
|
|
189
|
+
destroy: VoidFunction;
|
|
190
|
+
update: VoidFunction;
|
|
191
|
+
},
|
|
192
|
+
];
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Note that only the `current` property returned from the primitive is reactive. If you require additional reactivity on slide change you can use the returns slider instance to bind additional events.
|
|
196
|
+
|
|
171
197
|
### Autoplay
|
|
172
198
|
|
|
173
199
|
The autoplay function extends the slider with pausable playing. You can even supply a signal to control toggling autoplay. [Click here](https://codesandbox.io/s/solid-slider-autoplay-plugin-h2wphk?file=/src/index.tsx) for a demo of autoplay.
|
|
174
200
|
|
|
175
201
|
```ts
|
|
176
|
-
import createSlider from "solid-slider";
|
|
177
|
-
import autoplay from "solid-slider/plugins/autoplay";
|
|
202
|
+
import { createSlider } from "solid-slider";
|
|
203
|
+
import { autoplay } from "solid-slider/plugins/autoplay";
|
|
178
204
|
|
|
179
205
|
const [pause, togglePause] = createSignal(false);
|
|
180
206
|
const [slider] = createSlider(
|
|
@@ -182,10 +208,20 @@ const [slider] = createSlider(
|
|
|
182
208
|
autoplay(2000, {
|
|
183
209
|
pause,
|
|
184
210
|
pauseOnDrag: true,
|
|
185
|
-
})
|
|
211
|
+
}),
|
|
186
212
|
);
|
|
187
213
|
```
|
|
188
214
|
|
|
215
|
+
## SolidStart & Server-Side Rendering
|
|
216
|
+
|
|
217
|
+
So you want to use Solid Slider with [SolidStart](https://start.solidjs.com/). No problem but be mindful of how you use it and how server-side rendering impacts the experience. Remember that by default SolidStart enables SSR meaning that your pages are initially rendered on the server. The server has no context of the dimensions of your browser so it cannot calculate how the slider will appear once it's rendered in the browser.
|
|
218
|
+
|
|
219
|
+
Furthermore there's typically a small window of window between when the slider is sent to the browser and the moment it hydrates and becomes interactive. Given this is how all frameworks operate you're likely to experience the dreaded FOUC (flash of un-styled content).
|
|
220
|
+
|
|
221
|
+
To mitigate this issue you have two options available. You could add CSS styles (`visibility: hidden` or `hidden` in Tailwind) to hide the content and use the `created` callback in options to remove it from the slider once it's been created on the page. You could also initially style your slider correctly so it doesn't flash at all.
|
|
222
|
+
|
|
223
|
+
Alternatively you can use [`clientOnly`](https://docs.solidjs.com/solid-start/reference/client/client-only#clientonly) to ensure it isn't part of the SSR process. This is a bit lazy and not ideal in situations where you want content on your page to render for SEO purposes.
|
|
224
|
+
|
|
189
225
|
## Implementation
|
|
190
226
|
|
|
191
227
|
Solid Slider is meant to be a lightweight and compact wrapper of Keen-Slider. It exposes helpers to make working with the slider convenient. Note that the when the slider mounts it assumes all children in the el are slides. You can override this functionality by passing in a "selector" value to target the specific slides you'd like to include.
|
|
@@ -222,6 +258,8 @@ Thie library exports it's own CSS which is the basic Keen-Slider implementation
|
|
|
222
258
|
- 1.3.14 - Patched npm packaging issue (thanks [joeygrable94 ](https://www.github.com/joeygrable94))
|
|
223
259
|
- 1.3.15 - Updated to Solid 1.7.11
|
|
224
260
|
- 1.3.16 - Updated dependencies and move Solid from dependency to peer
|
|
261
|
+
- 1.3.17 - Added typs definition to exports (thanks [ChristophP](https://github.com/ChristophP))
|
|
262
|
+
- 1.3.18 - Adjusted documentation and minor source cleanup
|
|
225
263
|
|
|
226
264
|
## Keen Options API
|
|
227
265
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Adaptive height is a plugin that adjusts the height of the slider to the content on change.
|
|
7
5
|
*
|
|
@@ -10,8 +8,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
10
8
|
* const [create] = createSlider({}, [adaptiveHeight]);
|
|
11
9
|
* ```
|
|
12
10
|
*/
|
|
13
|
-
|
|
14
|
-
return slider
|
|
11
|
+
var adaptiveHeight = function adaptiveHeight() {
|
|
12
|
+
return function (slider) {
|
|
15
13
|
function updateHeight() {
|
|
16
14
|
slider.container.style.height = slider.slides[slider.track.details.rel].offsetHeight + "px";
|
|
17
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.common.js","sources":["../../src/plugins/adaptiveHeight.tsx"],"sourcesContent":["import { KeenSliderInstance } from \"keen-slider\";\n\n/**\n * Adaptive height is a plugin that adjusts the height of the slider to the content on change.\n *\n * @example\n * ```ts\n * const [create] = createSlider({}, [adaptiveHeight]);\n * ```\n */\nexport const adaptiveHeight = () => {\n return (slider: KeenSliderInstance) => {\n function updateHeight() {\n slider.container.style.height =\n slider.slides[slider.track.details.rel].offsetHeight + \"px\";\n }\n slider.on(\"created\", updateHeight);\n slider.on(\"slideChanged\", updateHeight);\n };\n};\n"],"names":["adaptiveHeight","slider","updateHeight","container","style","height","slides","track","details","rel","offsetHeight","on"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.common.js","sources":["../../src/plugins/adaptiveHeight.tsx"],"sourcesContent":["import { KeenSliderInstance } from \"keen-slider\";\n\n/**\n * Adaptive height is a plugin that adjusts the height of the slider to the content on change.\n *\n * @example\n * ```ts\n * const [create] = createSlider({}, [adaptiveHeight]);\n * ```\n */\nexport const adaptiveHeight = () => {\n return (slider: KeenSliderInstance) => {\n function updateHeight() {\n slider.container.style.height =\n slider.slides[slider.track.details.rel].offsetHeight + \"px\";\n }\n slider.on(\"created\", updateHeight);\n slider.on(\"slideChanged\", updateHeight);\n };\n};\n"],"names":["adaptiveHeight","slider","updateHeight","container","style","height","slides","track","details","rel","offsetHeight","on"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACaA,IAAAA,cAAc,GAAG,SAAjBA,cAAc,GAAS;EAClC,OAAO,UAACC,MAA0B,EAAK;AACrC,IAAA,SAASC,YAAY,GAAG;MACtBD,MAAM,CAACE,SAAS,CAACC,KAAK,CAACC,MAAM,GAC3BJ,MAAM,CAACK,MAAM,CAACL,MAAM,CAACM,KAAK,CAACC,OAAO,CAACC,GAAG,CAAC,CAACC,YAAY,GAAG,IAAI,CAAA;AAC/D,KAAA;AACAT,IAAAA,MAAM,CAACU,EAAE,CAAC,SAAS,EAAET,YAAY,CAAC,CAAA;AAClCD,IAAAA,MAAM,CAACU,EAAE,CAAC,cAAc,EAAET,YAAY,CAAC,CAAA;GACxC,CAAA;AACH;;;;"}
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* const [create] = createSlider({}, [adaptiveHeight]);
|
|
7
7
|
* ```
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
return slider
|
|
9
|
+
var adaptiveHeight = function adaptiveHeight() {
|
|
10
|
+
return function (slider) {
|
|
11
11
|
function updateHeight() {
|
|
12
12
|
slider.container.style.height = slider.slides[slider.track.details.rel].offsetHeight + "px";
|
|
13
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.module.js","sources":["../../src/plugins/adaptiveHeight.tsx"],"sourcesContent":["import { KeenSliderInstance } from \"keen-slider\";\n\n/**\n * Adaptive height is a plugin that adjusts the height of the slider to the content on change.\n *\n * @example\n * ```ts\n * const [create] = createSlider({}, [adaptiveHeight]);\n * ```\n */\nexport const adaptiveHeight = () => {\n return (slider: KeenSliderInstance) => {\n function updateHeight() {\n slider.container.style.height =\n slider.slides[slider.track.details.rel].offsetHeight + \"px\";\n }\n slider.on(\"created\", updateHeight);\n slider.on(\"slideChanged\", updateHeight);\n };\n};\n"],"names":["adaptiveHeight","slider","updateHeight","container","style","height","slides","track","details","rel","offsetHeight","on"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"file":"index.module.js","sources":["../../src/plugins/adaptiveHeight.tsx"],"sourcesContent":["import { KeenSliderInstance } from \"keen-slider\";\n\n/**\n * Adaptive height is a plugin that adjusts the height of the slider to the content on change.\n *\n * @example\n * ```ts\n * const [create] = createSlider({}, [adaptiveHeight]);\n * ```\n */\nexport const adaptiveHeight = () => {\n return (slider: KeenSliderInstance) => {\n function updateHeight() {\n slider.container.style.height =\n slider.slides[slider.track.details.rel].offsetHeight + \"px\";\n }\n slider.on(\"created\", updateHeight);\n slider.on(\"slideChanged\", updateHeight);\n };\n};\n"],"names":["adaptiveHeight","slider","updateHeight","container","style","height","slides","track","details","rel","offsetHeight","on"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACaA,IAAAA,cAAc,GAAG,SAAjBA,cAAc,GAAS;EAClC,OAAO,UAACC,MAA0B,EAAK;AACrC,IAAA,SAASC,YAAY,GAAG;MACtBD,MAAM,CAACE,SAAS,CAACC,KAAK,CAACC,MAAM,GAC3BJ,MAAM,CAACK,MAAM,CAACL,MAAM,CAACM,KAAK,CAACC,OAAO,CAACC,GAAG,CAAC,CAACC,YAAY,GAAG,IAAI,CAAA;AAC/D,KAAA;AACAT,IAAAA,MAAM,CAACU,EAAE,CAAC,SAAS,EAAET,YAAY,CAAC,CAAA;AAClCD,IAAAA,MAAM,CAACU,EAAE,CAAC,cAAc,EAAET,YAAY,CAAC,CAAA;GACxC,CAAA;AACH;;;;"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Adaptive width is a plugin that adjusts the width of the slider to the content on change.
|
|
7
5
|
*
|
|
@@ -10,8 +8,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
10
8
|
* const [create] = createSlider({}, [adaptiveWidth]);
|
|
11
9
|
* ```
|
|
12
10
|
*/
|
|
13
|
-
|
|
14
|
-
return slider
|
|
11
|
+
var adaptiveWidth = function adaptiveWidth() {
|
|
12
|
+
return function (slider) {
|
|
15
13
|
function updateWidth() {
|
|
16
14
|
slider.container.style.width = slider.slides[slider.track.details.rel].offsetWidth + "px";
|
|
17
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.common.js","sources":["../../src/plugins/adaptiveWidth.tsx"],"sourcesContent":["import { KeenSliderInstance } from \"keen-slider\";\n\n/**\n * Adaptive width is a plugin that adjusts the width of the slider to the content on change.\n *\n * @example\n * ```ts\n * const [create] = createSlider({}, [adaptiveWidth]);\n * ```\n */\nexport const adaptiveWidth = () => {\n return (slider: KeenSliderInstance) => {\n function updateWidth() {\n slider.container.style.width =\n slider.slides[slider.track.details.rel].offsetWidth + \"px\";\n }\n slider.on(\"created\", updateWidth);\n slider.on(\"slideChanged\", updateWidth);\n };\n};\n"],"names":["adaptiveWidth","slider","updateWidth","container","style","width","slides","track","details","rel","offsetWidth","on"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.common.js","sources":["../../src/plugins/adaptiveWidth.tsx"],"sourcesContent":["import { KeenSliderInstance } from \"keen-slider\";\n\n/**\n * Adaptive width is a plugin that adjusts the width of the slider to the content on change.\n *\n * @example\n * ```ts\n * const [create] = createSlider({}, [adaptiveWidth]);\n * ```\n */\nexport const adaptiveWidth = () => {\n return (slider: KeenSliderInstance) => {\n function updateWidth() {\n slider.container.style.width =\n slider.slides[slider.track.details.rel].offsetWidth + \"px\";\n }\n slider.on(\"created\", updateWidth);\n slider.on(\"slideChanged\", updateWidth);\n };\n};\n"],"names":["adaptiveWidth","slider","updateWidth","container","style","width","slides","track","details","rel","offsetWidth","on"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACaA,IAAAA,aAAa,GAAG,SAAhBA,aAAa,GAAS;EACjC,OAAO,UAACC,MAA0B,EAAK;AACrC,IAAA,SAASC,WAAW,GAAG;MACrBD,MAAM,CAACE,SAAS,CAACC,KAAK,CAACC,KAAK,GAC1BJ,MAAM,CAACK,MAAM,CAACL,MAAM,CAACM,KAAK,CAACC,OAAO,CAACC,GAAG,CAAC,CAACC,WAAW,GAAG,IAAI,CAAA;AAC9D,KAAA;AACAT,IAAAA,MAAM,CAACU,EAAE,CAAC,SAAS,EAAET,WAAW,CAAC,CAAA;AACjCD,IAAAA,MAAM,CAACU,EAAE,CAAC,cAAc,EAAET,WAAW,CAAC,CAAA;GACvC,CAAA;AACH;;;;"}
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* const [create] = createSlider({}, [adaptiveWidth]);
|
|
7
7
|
* ```
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
return slider
|
|
9
|
+
var adaptiveWidth = function adaptiveWidth() {
|
|
10
|
+
return function (slider) {
|
|
11
11
|
function updateWidth() {
|
|
12
12
|
slider.container.style.width = slider.slides[slider.track.details.rel].offsetWidth + "px";
|
|
13
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.module.js","sources":["../../src/plugins/adaptiveWidth.tsx"],"sourcesContent":["import { KeenSliderInstance } from \"keen-slider\";\n\n/**\n * Adaptive width is a plugin that adjusts the width of the slider to the content on change.\n *\n * @example\n * ```ts\n * const [create] = createSlider({}, [adaptiveWidth]);\n * ```\n */\nexport const adaptiveWidth = () => {\n return (slider: KeenSliderInstance) => {\n function updateWidth() {\n slider.container.style.width =\n slider.slides[slider.track.details.rel].offsetWidth + \"px\";\n }\n slider.on(\"created\", updateWidth);\n slider.on(\"slideChanged\", updateWidth);\n };\n};\n"],"names":["adaptiveWidth","slider","updateWidth","container","style","width","slides","track","details","rel","offsetWidth","on"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"file":"index.module.js","sources":["../../src/plugins/adaptiveWidth.tsx"],"sourcesContent":["import { KeenSliderInstance } from \"keen-slider\";\n\n/**\n * Adaptive width is a plugin that adjusts the width of the slider to the content on change.\n *\n * @example\n * ```ts\n * const [create] = createSlider({}, [adaptiveWidth]);\n * ```\n */\nexport const adaptiveWidth = () => {\n return (slider: KeenSliderInstance) => {\n function updateWidth() {\n slider.container.style.width =\n slider.slides[slider.track.details.rel].offsetWidth + \"px\";\n }\n slider.on(\"created\", updateWidth);\n slider.on(\"slideChanged\", updateWidth);\n };\n};\n"],"names":["adaptiveWidth","slider","updateWidth","container","style","width","slides","track","details","rel","offsetWidth","on"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACaA,IAAAA,aAAa,GAAG,SAAhBA,aAAa,GAAS;EACjC,OAAO,UAACC,MAA0B,EAAK;AACrC,IAAA,SAASC,WAAW,GAAG;MACrBD,MAAM,CAACE,SAAS,CAACC,KAAK,CAACC,KAAK,GAC1BJ,MAAM,CAACK,MAAM,CAACL,MAAM,CAACM,KAAK,CAACC,OAAO,CAACC,GAAG,CAAC,CAACC,WAAW,GAAG,IAAI,CAAA;AAC9D,KAAA;AACAT,IAAAA,MAAM,CAACU,EAAE,CAAC,SAAS,EAAET,WAAW,CAAC,CAAA;AACjCD,IAAAA,MAAM,CAACU,EAAE,CAAC,cAAc,EAAET,WAAW,CAAC,CAAA;GACvC,CAAA;AACH;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { makeTimer } from
|
|
2
|
-
import { createEffect } from
|
|
1
|
+
import { makeTimer } from "@solid-primitives/timer";
|
|
2
|
+
import { createEffect } from "solid-js";
|
|
3
3
|
/**
|
|
4
4
|
* Provides an autoplay plugin.
|
|
5
5
|
*
|
|
@@ -24,8 +24,8 @@ export const autoplay = (interval = 1000, options) => {
|
|
|
24
24
|
};
|
|
25
25
|
// Pause the slider on drag
|
|
26
26
|
if (options.pauseOnDrag !== false) {
|
|
27
|
-
slider.on(
|
|
27
|
+
slider.on("dragStarted", () => dispose?.());
|
|
28
28
|
}
|
|
29
|
-
createEffect(() =>
|
|
29
|
+
createEffect(() => !options.pause || options.pause() === false ? start() : dispose?.());
|
|
30
30
|
};
|
|
31
31
|
};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var timer = require('@solid-primitives/timer');
|
|
6
4
|
var solidJs = require('solid-js');
|
|
7
5
|
|
|
@@ -21,17 +19,27 @@ var solidJs = require('solid-js');
|
|
|
21
19
|
* const [create] = createSlider({}, [autoplay]);
|
|
22
20
|
* ```
|
|
23
21
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
var autoplay = function autoplay() {
|
|
23
|
+
var interval = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
|
|
24
|
+
var options = arguments.length > 1 ? arguments[1] : undefined;
|
|
25
|
+
return function (slider) {
|
|
26
|
+
var dispose;
|
|
27
|
+
var start = function start() {
|
|
28
|
+
dispose = timer.makeTimer(function () {
|
|
29
|
+
return slider.moveToIdx(slider.track.details.position + 1, true, options.animation);
|
|
30
|
+
}, interval, setInterval);
|
|
29
31
|
};
|
|
30
32
|
// Pause the slider on drag
|
|
31
33
|
if (options.pauseOnDrag !== false) {
|
|
32
|
-
slider.on(
|
|
34
|
+
slider.on("dragStarted", function () {
|
|
35
|
+
var _dispose;
|
|
36
|
+
return (_dispose = dispose) === null || _dispose === void 0 ? void 0 : _dispose();
|
|
37
|
+
});
|
|
33
38
|
}
|
|
34
|
-
solidJs.createEffect(
|
|
39
|
+
solidJs.createEffect(function () {
|
|
40
|
+
var _dispose2;
|
|
41
|
+
return !options.pause || options.pause() === false ? start() : (_dispose2 = dispose) === null || _dispose2 === void 0 ? void 0 : _dispose2();
|
|
42
|
+
});
|
|
35
43
|
};
|
|
36
44
|
};
|
|
37
45
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.common.js","sources":["../../src/plugins/autoplay.tsx"],"sourcesContent":["import { makeTimer } from
|
|
1
|
+
{"version":3,"file":"index.common.js","sources":["../../src/plugins/autoplay.tsx"],"sourcesContent":["import { makeTimer } from \"@solid-primitives/timer\";\nimport { KeenSliderInstance } from \"keen-slider\";\nimport { Accessor, createEffect } from \"solid-js\";\n\n/**\n * Provides an autoplay plugin.\n *\n * @param {number} interval Interval in milliseconds for switching slides\n * @param {object} options Options to customize the autoplay\n * @param {Function} options.pause A pause signal to control the autoplay\n * @param {boolean} options.pauseOnDrag Denotes of the autoplay should pause on drag.\n * @param {object} options.animation Allows for control of duration and easing.\n * @param {number} options.duration Duration for transitioning the slide.\n * @param {number} options.easing Easing function for the transition animation.\n *\n * @example\n * ```ts\n * const [create] = createSlider({}, [autoplay]);\n * ```\n */\nexport const autoplay = (\n interval: number = 1000,\n options: {\n pause?: Accessor<boolean>;\n pauseOnDrag?: boolean;\n animation?: {\n duration?: number;\n easing?: (t: number) => number;\n };\n },\n) => {\n return (slider: KeenSliderInstance) => {\n let dispose: Function;\n const start = () => {\n dispose = makeTimer(\n () =>\n slider.moveToIdx(\n slider.track.details.position + 1,\n true,\n options.animation,\n ),\n interval,\n setInterval,\n );\n };\n // Pause the slider on drag\n if (options.pauseOnDrag !== false) {\n slider.on(\"dragStarted\", () => dispose?.());\n }\n createEffect(() =>\n !options.pause || options.pause() === false ? start() : dispose?.(),\n );\n };\n};\n"],"names":["autoplay","interval","options","slider","dispose","start","makeTimer","moveToIdx","track","details","position","animation","setInterval","pauseOnDrag","on","createEffect","pause"],"mappings":";;;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACaA,IAAAA,QAAQ,GAAG,SAAXA,QAAQ,GAUhB;EAAA,IATHC,QAAgB,uEAAG,IAAI,CAAA;AAAA,EAAA,IACvBC,OAOC,GAAA,SAAA,CAAA,MAAA,GAAA,CAAA,GAAA,SAAA,CAAA,CAAA,CAAA,GAAA,SAAA,CAAA;EAED,OAAO,UAACC,MAA0B,EAAK;AACrC,IAAA,IAAIC,OAAiB,CAAA;AACrB,IAAA,IAAMC,KAAK,GAAG,SAARA,KAAK,GAAS;MAClBD,OAAO,GAAGE,eAAS,CACjB,YAAA;AAAA,QAAA,OACEH,MAAM,CAACI,SAAS,CACdJ,MAAM,CAACK,KAAK,CAACC,OAAO,CAACC,QAAQ,GAAG,CAAC,EACjC,IAAI,EACJR,OAAO,CAACS,SAAS,CAClB,CAAA;OACHV,EAAAA,QAAQ,EACRW,WAAW,CACZ,CAAA;KACF,CAAA;AACD;AACA,IAAA,IAAIV,OAAO,CAACW,WAAW,KAAK,KAAK,EAAE;AACjCV,MAAAA,MAAM,CAACW,EAAE,CAAC,aAAa,EAAE,YAAA;AAAA,QAAA,IAAA,QAAA,CAAA;QAAA,OAAMV,CAAAA,QAAAA,GAAAA,OAAO,6CAAP,QAAW,EAAA,CAAA;OAAC,CAAA,CAAA;AAC7C,KAAA;AACAW,IAAAA,oBAAY,CAAC,YAAA;AAAA,MAAA,IAAA,SAAA,CAAA;AAAA,MAAA,OACX,CAACb,OAAO,CAACc,KAAK,IAAId,OAAO,CAACc,KAAK,EAAE,KAAK,KAAK,GAAGX,KAAK,EAAE,GAAGD,CAAAA,SAAAA,GAAAA,OAAO,8CAAP,SAAW,EAAA,CAAA;KACpE,CAAA,CAAA;GACF,CAAA;AACH;;;;"}
|
|
@@ -17,17 +17,27 @@ import { createEffect } from 'solid-js';
|
|
|
17
17
|
* const [create] = createSlider({}, [autoplay]);
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
var autoplay = function autoplay() {
|
|
21
|
+
var interval = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
|
|
22
|
+
var options = arguments.length > 1 ? arguments[1] : undefined;
|
|
23
|
+
return function (slider) {
|
|
24
|
+
var dispose;
|
|
25
|
+
var start = function start() {
|
|
26
|
+
dispose = makeTimer(function () {
|
|
27
|
+
return slider.moveToIdx(slider.track.details.position + 1, true, options.animation);
|
|
28
|
+
}, interval, setInterval);
|
|
25
29
|
};
|
|
26
30
|
// Pause the slider on drag
|
|
27
31
|
if (options.pauseOnDrag !== false) {
|
|
28
|
-
slider.on(
|
|
32
|
+
slider.on("dragStarted", function () {
|
|
33
|
+
var _dispose;
|
|
34
|
+
return (_dispose = dispose) === null || _dispose === void 0 ? void 0 : _dispose();
|
|
35
|
+
});
|
|
29
36
|
}
|
|
30
|
-
createEffect(
|
|
37
|
+
createEffect(function () {
|
|
38
|
+
var _dispose2;
|
|
39
|
+
return !options.pause || options.pause() === false ? start() : (_dispose2 = dispose) === null || _dispose2 === void 0 ? void 0 : _dispose2();
|
|
40
|
+
});
|
|
31
41
|
};
|
|
32
42
|
};
|
|
33
43
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.module.js","sources":["../../src/plugins/autoplay.tsx"],"sourcesContent":["import { makeTimer } from
|
|
1
|
+
{"version":3,"file":"index.module.js","sources":["../../src/plugins/autoplay.tsx"],"sourcesContent":["import { makeTimer } from \"@solid-primitives/timer\";\nimport { KeenSliderInstance } from \"keen-slider\";\nimport { Accessor, createEffect } from \"solid-js\";\n\n/**\n * Provides an autoplay plugin.\n *\n * @param {number} interval Interval in milliseconds for switching slides\n * @param {object} options Options to customize the autoplay\n * @param {Function} options.pause A pause signal to control the autoplay\n * @param {boolean} options.pauseOnDrag Denotes of the autoplay should pause on drag.\n * @param {object} options.animation Allows for control of duration and easing.\n * @param {number} options.duration Duration for transitioning the slide.\n * @param {number} options.easing Easing function for the transition animation.\n *\n * @example\n * ```ts\n * const [create] = createSlider({}, [autoplay]);\n * ```\n */\nexport const autoplay = (\n interval: number = 1000,\n options: {\n pause?: Accessor<boolean>;\n pauseOnDrag?: boolean;\n animation?: {\n duration?: number;\n easing?: (t: number) => number;\n };\n },\n) => {\n return (slider: KeenSliderInstance) => {\n let dispose: Function;\n const start = () => {\n dispose = makeTimer(\n () =>\n slider.moveToIdx(\n slider.track.details.position + 1,\n true,\n options.animation,\n ),\n interval,\n setInterval,\n );\n };\n // Pause the slider on drag\n if (options.pauseOnDrag !== false) {\n slider.on(\"dragStarted\", () => dispose?.());\n }\n createEffect(() =>\n !options.pause || options.pause() === false ? start() : dispose?.(),\n );\n };\n};\n"],"names":["autoplay","interval","options","slider","dispose","start","makeTimer","moveToIdx","track","details","position","animation","setInterval","pauseOnDrag","on","createEffect","pause"],"mappings":";;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACaA,IAAAA,QAAQ,GAAG,SAAXA,QAAQ,GAUhB;EAAA,IATHC,QAAgB,uEAAG,IAAI,CAAA;AAAA,EAAA,IACvBC,OAOC,GAAA,SAAA,CAAA,MAAA,GAAA,CAAA,GAAA,SAAA,CAAA,CAAA,CAAA,GAAA,SAAA,CAAA;EAED,OAAO,UAACC,MAA0B,EAAK;AACrC,IAAA,IAAIC,OAAiB,CAAA;AACrB,IAAA,IAAMC,KAAK,GAAG,SAARA,KAAK,GAAS;MAClBD,OAAO,GAAGE,SAAS,CACjB,YAAA;AAAA,QAAA,OACEH,MAAM,CAACI,SAAS,CACdJ,MAAM,CAACK,KAAK,CAACC,OAAO,CAACC,QAAQ,GAAG,CAAC,EACjC,IAAI,EACJR,OAAO,CAACS,SAAS,CAClB,CAAA;OACHV,EAAAA,QAAQ,EACRW,WAAW,CACZ,CAAA;KACF,CAAA;AACD;AACA,IAAA,IAAIV,OAAO,CAACW,WAAW,KAAK,KAAK,EAAE;AACjCV,MAAAA,MAAM,CAACW,EAAE,CAAC,aAAa,EAAE,YAAA;AAAA,QAAA,IAAA,QAAA,CAAA;QAAA,OAAMV,CAAAA,QAAAA,GAAAA,OAAO,6CAAP,QAAW,EAAA,CAAA;OAAC,CAAA,CAAA;AAC7C,KAAA;AACAW,IAAAA,YAAY,CAAC,YAAA;AAAA,MAAA,IAAA,SAAA,CAAA;AAAA,MAAA,OACX,CAACb,OAAO,CAACc,KAAK,IAAId,OAAO,CAACc,KAAK,EAAE,KAAK,KAAK,GAAGX,KAAK,EAAE,GAAGD,CAAAA,SAAAA,GAAAA,OAAO,8CAAP,SAAW,EAAA,CAAA;KACpE,CAAA,CAAA;GACF,CAAA;AACH;;;;"}
|
|
@@ -6,12 +6,12 @@ interface Func<T> {
|
|
|
6
6
|
export declare function returnType<T>(func: Func<T>): T;
|
|
7
7
|
export declare const SliderContext: import("solid-js").Context<import("solid-js").Signal<{
|
|
8
8
|
current: import("solid-js").Accessor<number>;
|
|
9
|
-
next:
|
|
10
|
-
prev:
|
|
9
|
+
next: VoidFunction;
|
|
10
|
+
prev: VoidFunction;
|
|
11
11
|
moveTo: (id: number, duration?: number, absolute?: boolean, easing?: (t: number) => number) => void;
|
|
12
|
-
details:
|
|
13
|
-
slider:
|
|
14
|
-
destroy:
|
|
12
|
+
details: () => import("keen-slider").TrackDetails;
|
|
13
|
+
slider: () => import("keen-slider").KeenSliderInstance<{}, {}, import("keen-slider").KeenSliderHooks>;
|
|
14
|
+
destroy: VoidFunction;
|
|
15
15
|
update: VoidFunction;
|
|
16
16
|
}>>;
|
|
17
17
|
/**
|