solid-slider 1.2.6 → 1.2.9

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 CHANGED
@@ -4,7 +4,7 @@
4
4
  [![size](https://img.shields.io/npm/v/solid-slider?style=for-the-badge)](https://www.npmjs.com/package/solid-slider)
5
5
  ![npm](https://img.shields.io/npm/dw/solid-slider?style=for-the-badge)
6
6
 
7
- A carousel/slider implementation in TypeScript for SolidJS. It's built on KeenSlider 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.
7
+ A carousel/slider implementation in TypeScript for SolidJS. 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
  ## Installation
10
10
 
@@ -16,7 +16,7 @@ yarn add solid-slider ## or in yarn
16
16
  Add as a module:
17
17
 
18
18
  ```ts
19
- import "solid-slider/dist/slider.css";
19
+ import "solid-slider/slider.css";
20
20
  import createSlider from "solid-slider";
21
21
  ```
22
22
 
@@ -26,7 +26,11 @@ You can find a functional demo of the slider with most features implemented here
26
26
 
27
27
  ## Plugins
28
28
 
29
- Plugins may be added directly via the createSlider primitive. You may add a KeenSlider plugin directly or built-in plugins shipped with this package. Currently an autoplay plugin is available that will assist with autoplaying actions in the slider. Simply add the plugins after the options parameter.
29
+ Plugins may be added directly via the createSlider primitive. You may add a Keen-Slider plugin directly or built-in plugins shipped with this package. Currently an autoplay plugin is available that will assist with autoplaying actions in the slider. Simply add the plugins after the options parameter. Please feel free to post requests for additional plugins or submit PRs if you decide to improve the base functionality. Some ideas for additional plugins include:
30
+
31
+ - Slider nav (dot, arrow controls even thumbnails)
32
+ - Lazy loaded images
33
+ - Slide transitions
30
34
 
31
35
  ### Autoplay
32
36
 
@@ -86,17 +90,18 @@ const MyComponent = () => {
86
90
 
87
91
  ## Implementation
88
92
 
89
- Solid Slider is meant to be a lightweight and compact wrapper of KeenSlider. 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.
93
+ 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.
90
94
 
91
- Thie library exports it's own CSS which is the basic KeenSlider implementation for convenience. If you supply options as an accessor function, the slider will reactively update the configuration so that you don't have to destroy and recreate the slider. As of KeenSlider 6 plugins are now fully supported. You may supply them as a param in createSlider. Note that plugins are not reactively updated and must be supplied on creation.
95
+ Thie library exports it's own CSS which is the basic Keen-Slider implementation for convenience. If you supply options as an accessor function, the slider will reactively update the configuration so that you don't have to destroy and recreate the slider. As of Keen-Slider 6 plugins are now fully supported. You may supply them as a param in createSlider. Note that plugins are not reactively updated and must be supplied on creation.
92
96
 
93
97
  ## Changelog
94
98
 
95
99
  - 1.0.0 - Initial release
96
100
  - 1.0.3 - Changed the exported API to be slightly more flexible.
97
- - 1.1.1 - Upgraded to KeenSlider 6 and improved general reactivity.
101
+ - 1.1.1 - Upgraded to Keen-Slider 6 and improved general reactivity.
98
102
  - 1.2.5 - Added autoplay plugin and general plugin structure
99
- - 1.2.6 - Maybe I should actually export the .css? That'd be a good idea, right?
103
+ - 1.2.7 - Maybe I should actually export the .css? That'd be a good idea, right?
104
+ - 1.2.9 - Updated timer primitive and patched issue with current slide setting from initial options.
100
105
 
101
106
  ## Keen Options API
102
107
 
@@ -0,0 +1,20 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+
18
+ export {
19
+ __spreadValues
20
+ };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { Accessor } from "solid-js";
2
- import { KeenSliderHooks, KeenSliderInstance, KeenSliderOptions, KeenSliderPlugin, TrackDetails } from "keen-slider";
1
+ import { Accessor } from 'solid-js';
2
+ import { KeenSliderHooks, KeenSliderOptions, KeenSliderPlugin, TrackDetails, KeenSliderInstance } from 'keen-slider';
3
+
3
4
  declare module "solid-js" {
4
5
  namespace JSX {
5
6
  interface Directives {
@@ -37,4 +38,5 @@ declare const createSlider: <O = {}, P = {}, H extends string = KeenSliderHooks>
37
38
  slider: Accessor<KeenSliderInstance<O, P, H> | undefined>;
38
39
  destroy: Accessor<void>;
39
40
  }];
40
- export default createSlider;
41
+
42
+ export { createSlider as default };
package/dist/index.js CHANGED
@@ -1,58 +1,78 @@
1
- import { on, onMount, createSignal, onCleanup, createEffect } from "solid-js";
2
- import KeenSlider from "keen-slider";
3
- /**
4
- * Creates a slider powered by KeenSlider.
5
- *
6
- * @param {Object} options Values to initialize the slider with
7
- * @param {Array} plugins Extensions that enhance KeenSlider options
8
- * @returns {[create: Function, helpers: Object]} Returns mount and helper methods
9
- * @returns {Function} create Mounts the slider on provided element
10
- * @returns {Function} helpers.current Current slide number
11
- * @returns {Function} helpers.current Current slide number
12
- * @returns {Function} helpers.next Function to trigger the next slide
13
- * @returns {Function} helpers.prev Function to trigger the previous slide
14
- * @returns {Function<Object>} helpers.details Provides details about the current slider
15
- * @returns {Function} helpers.slider Returns the KeenSlider instance
16
- * @returns {Function} helpers.destroy Manual destroy function
17
- *
18
- * @example
19
- * ```ts
20
- * const [create, { prev, next }] = createSlider();
21
- * <div use:slider>...</div>
22
- * ```
23
- */
24
- const createSlider = (options, ...plugins) => {
25
- let slider;
26
- const [current, setCurrent] = createSignal(0);
27
- const destroy = () => slider && slider.destroy();
28
- // Slider creation method and directive function
29
- const create = (el) => {
30
- el.classList.add("keen-slider");
31
- // @ts-ignore
32
- const opts = () => ({
33
- selector: el.childNodes,
34
- ...(typeof options == "function" ? options() : options)
35
- });
36
- onMount(() => {
37
- slider = new KeenSlider(el, opts(), plugins);
38
- slider.on("slideChanged", () => setCurrent(slider.track.details.rel));
39
- });
40
- onCleanup(destroy);
41
- if (typeof options === "function") {
42
- createEffect(on(() => options, () => slider && slider.update(opts())));
43
- }
44
- };
45
- return [
46
- create,
47
- {
48
- current,
49
- next: () => slider && slider.next(),
50
- prev: () => slider && slider.prev(),
51
- details: () => (slider ? slider.track.details : {}),
52
- slider: () => slider,
53
- moveTo: (id, duration = 250, absolute = false, easing) => slider?.moveToIdx(id, absolute, { duration, easing: easing }),
54
- destroy
55
- }
56
- ];
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
57
20
  };
58
- export default createSlider;
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
24
+ };
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
+ }
31
+ return to;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+
36
+ // src/index.ts
37
+ var src_exports = {};
38
+ __export(src_exports, {
39
+ default: () => src_default
40
+ });
41
+ module.exports = __toCommonJS(src_exports);
42
+ var import_solid_js = require("solid-js");
43
+ var import_keen_slider = __toESM(require("keen-slider"));
44
+ var createSlider = (options, ...plugins) => {
45
+ let slider;
46
+ const [current, setCurrent] = (0, import_solid_js.createSignal)(0);
47
+ const destroy = () => slider && slider.destroy();
48
+ const create = (el) => {
49
+ el.classList.add("keen-slider");
50
+ const opts = () => __spreadValues({
51
+ selector: el.childNodes
52
+ }, typeof options == "function" ? options() : options);
53
+ (0, import_solid_js.onMount)(() => {
54
+ slider = new import_keen_slider.default(el, opts(), plugins);
55
+ setCurrent(slider.track.details.rel);
56
+ slider.on("slideChanged", () => setCurrent(slider.track.details.rel));
57
+ });
58
+ (0, import_solid_js.onCleanup)(destroy);
59
+ if (typeof options === "function") {
60
+ (0, import_solid_js.createEffect)((0, import_solid_js.on)(() => options, () => slider && slider.update(opts())));
61
+ }
62
+ };
63
+ return [
64
+ create,
65
+ {
66
+ current,
67
+ next: () => slider && slider.next(),
68
+ prev: () => slider && slider.prev(),
69
+ details: () => slider ? slider.track.details : {},
70
+ slider: () => slider,
71
+ moveTo: (id, duration = 250, absolute = false, easing) => slider == null ? void 0 : slider.moveToIdx(id, absolute, { duration, easing }),
72
+ destroy
73
+ }
74
+ ];
75
+ };
76
+ var src_default = createSlider;
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {});
package/dist/index.mjs ADDED
@@ -0,0 +1,43 @@
1
+ import {
2
+ __spreadValues
3
+ } from "./chunk-NXJS66U5.mjs";
4
+
5
+ // src/index.ts
6
+ import { on, onMount, createSignal, onCleanup, createEffect } from "solid-js";
7
+ import KeenSlider from "keen-slider";
8
+ var createSlider = (options, ...plugins) => {
9
+ let slider;
10
+ const [current, setCurrent] = createSignal(0);
11
+ const destroy = () => slider && slider.destroy();
12
+ const create = (el) => {
13
+ el.classList.add("keen-slider");
14
+ const opts = () => __spreadValues({
15
+ selector: el.childNodes
16
+ }, typeof options == "function" ? options() : options);
17
+ onMount(() => {
18
+ slider = new KeenSlider(el, opts(), plugins);
19
+ setCurrent(slider.track.details.rel);
20
+ slider.on("slideChanged", () => setCurrent(slider.track.details.rel));
21
+ });
22
+ onCleanup(destroy);
23
+ if (typeof options === "function") {
24
+ createEffect(on(() => options, () => slider && slider.update(opts())));
25
+ }
26
+ };
27
+ return [
28
+ create,
29
+ {
30
+ current,
31
+ next: () => slider && slider.next(),
32
+ prev: () => slider && slider.prev(),
33
+ details: () => slider ? slider.track.details : {},
34
+ slider: () => slider,
35
+ moveTo: (id, duration = 250, absolute = false, easing) => slider == null ? void 0 : slider.moveToIdx(id, absolute, { duration, easing }),
36
+ destroy
37
+ }
38
+ ];
39
+ };
40
+ var src_default = createSlider;
41
+ export {
42
+ src_default as default
43
+ };
@@ -1,33 +1,41 @@
1
- import { createEffect } from "solid-js";
2
- import createTimer, { Schedule } from "@solid-primitives/timer";
3
- /**
4
- * Provides an autoplay plugin.
5
- *
6
- * @param {number} interval Interval in milliseconds for switching slides
7
- * @param {object} options Options to customize the autoplay
8
- * @param {Function} options.pause A pause signal to control the autoplay
9
- * @param {boolean} options.pauseOnDrag Denotes of the autoplay should pause on drag.
10
- * @param {object} options.animation Allows for control of duration and easing.
11
- * @param {number} options.duration Duration for transitioning the slide.
12
- * @param {number} options.easing Easing function for the transition animation.
13
- *
14
- * @example
15
- * ```ts
16
- * const [create, { prev, next }] = createSlider();
17
- * <div use:slider>...</div>
18
- * ```
19
- */
20
- const autoplay = (interval = 1000, options) => {
21
- return (slider) => {
22
- let clear;
23
- const start = () => {
24
- clear = createTimer(() => slider.moveToIdx(slider.track.details.position + 1, true, options.animation), interval, Schedule.Interval);
25
- };
26
- // Pause the slider on drag
27
- if (options.pauseOnDrag || true) {
28
- slider.on("dragStarted", () => clear());
29
- }
30
- createEffect(() => (!options.pause || options.pause() === false ? start() : clear()));
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/plugins/autoplay.ts
20
+ var autoplay_exports = {};
21
+ __export(autoplay_exports, {
22
+ default: () => autoplay_default
23
+ });
24
+ module.exports = __toCommonJS(autoplay_exports);
25
+ var import_solid_js = require("solid-js");
26
+ var import_timer = require("@solid-primitives/timer");
27
+ var autoplay = (interval = 1e3, options) => {
28
+ return (slider) => {
29
+ let dispose;
30
+ const start = () => {
31
+ dispose = (0, import_timer.makeTimer)(() => slider.moveToIdx(slider.track.details.position + 1, true, options.animation), interval, setInterval);
31
32
  };
33
+ if (options.pauseOnDrag || true) {
34
+ slider.on("dragStarted", () => dispose());
35
+ }
36
+ (0, import_solid_js.createEffect)(() => !options.pause || options.pause() === false ? start() : dispose());
37
+ };
32
38
  };
33
- export default autoplay;
39
+ var autoplay_default = autoplay;
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {});
@@ -0,0 +1,21 @@
1
+ import "../chunk-NXJS66U5.mjs";
2
+
3
+ // src/plugins/autoplay.ts
4
+ import { createEffect } from "solid-js";
5
+ import { makeTimer } from "@solid-primitives/timer";
6
+ var autoplay = (interval = 1e3, options) => {
7
+ return (slider) => {
8
+ let dispose;
9
+ const start = () => {
10
+ dispose = makeTimer(() => slider.moveToIdx(slider.track.details.position + 1, true, options.animation), interval, setInterval);
11
+ };
12
+ if (options.pauseOnDrag || true) {
13
+ slider.on("dragStarted", () => dispose());
14
+ }
15
+ createEffect(() => !options.pause || options.pause() === false ? start() : dispose());
16
+ };
17
+ };
18
+ var autoplay_default = autoplay;
19
+ export {
20
+ autoplay_default as default
21
+ };
package/package.json CHANGED
@@ -1,35 +1,33 @@
1
1
  {
2
2
  "name": "solid-slider",
3
- "version": "1.2.6",
3
+ "version": "1.2.9",
4
4
  "description": "A slider utility for SolidJS.",
5
5
  "author": "David Di Biase",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://davedbase@github.com/davedbase/solid-slider.git"
9
+ },
6
10
  "license": "ISC",
7
11
  "bugs": {
8
12
  "url": "https://github.com/davedbase/solid-slider/issues"
9
13
  },
10
14
  "homepage": "https://github.com/davedbase/solid-slider#readme",
11
15
  "scripts": {
12
- "prebuild": "npm run clean",
13
- "clean": "rimraf dist/",
14
16
  "format": "prettier -w \"src/**/*.{js,ts,json,css,tsx,jsx}\"",
15
- "build": "tsc && cp src/slider.css dist/slider.css"
17
+ "build": "tsup && cp src/slider.css dist/slider.css"
16
18
  },
17
19
  "main": "dist/index.js",
18
- "module": "dist/index.js",
20
+ "module": "dist/index.mjs",
19
21
  "exports": {
20
22
  ".": "./dist/index.js",
21
23
  "./plugins/autoplay": "./dist/plugins/autoplay.js",
22
24
  "./slider.css": "./dist/slider.css"
23
25
  },
24
26
  "types": "dist/index.d.ts",
25
- "sideEffects": "false",
27
+ "sideEffects": false,
26
28
  "files": [
27
29
  "dist"
28
30
  ],
29
- "repository": {
30
- "type": "git",
31
- "url": "git+https://davedbase@github.com/davedbase/solid-slider.git"
32
- },
33
31
  "keywords": [
34
32
  "slider",
35
33
  "carousel",
@@ -43,13 +41,13 @@
43
41
  "plugin"
44
42
  ],
45
43
  "dependencies": {
46
- "@solid-primitives/timer": "^1.1.0",
47
- "keen-slider": "^6.6.3",
48
- "rimraf": "^3.0.2",
49
- "solid-js": "^1.3.5",
50
- "typescript": "^4.5.5"
44
+ "@solid-primitives/timer": "1.3.0",
45
+ "keen-slider": "^6.6.10",
46
+ "solid-js": "^1.3.16"
51
47
  },
52
48
  "devDependencies": {
53
- "prettier": "^2.5.1"
49
+ "prettier": "^2.5.1",
50
+ "tsup": "^5.12.6",
51
+ "typescript": "^4.5.5"
54
52
  }
55
53
  }
@@ -1,28 +0,0 @@
1
- import { Accessor } from "solid-js";
2
- import { KeenSliderInstance } from "keen-slider";
3
- /**
4
- * Provides an autoplay plugin.
5
- *
6
- * @param {number} interval Interval in milliseconds for switching slides
7
- * @param {object} options Options to customize the autoplay
8
- * @param {Function} options.pause A pause signal to control the autoplay
9
- * @param {boolean} options.pauseOnDrag Denotes of the autoplay should pause on drag.
10
- * @param {object} options.animation Allows for control of duration and easing.
11
- * @param {number} options.duration Duration for transitioning the slide.
12
- * @param {number} options.easing Easing function for the transition animation.
13
- *
14
- * @example
15
- * ```ts
16
- * const [create, { prev, next }] = createSlider();
17
- * <div use:slider>...</div>
18
- * ```
19
- */
20
- declare const autoplay: (interval: number | undefined, options: {
21
- pause?: Accessor<boolean> | undefined;
22
- pauseOnDrag?: boolean | undefined;
23
- animation?: {
24
- duration?: number | undefined;
25
- easing?: ((t: number) => number) | undefined;
26
- } | undefined;
27
- }) => (slider: KeenSliderInstance) => void;
28
- export default autoplay;