Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue3-carousel

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue3-carousel - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

examples/basic.vue

192

dist/carousel.es.js
/**
* Vue 3 Carousel 0.1.2
* Vue 3 Carousel 0.1.3
* (c) 2020

@@ -27,6 +27,9 @@ * @license MIT

var slidesCounter = new Proxy({ value: 0 }, {
var slidesCounter = new Proxy({ value: 0, read: 0 }, {
get(obj, prop) {
if (!(prop in obj))
return 0;
if (prop === 'read') {
return obj[prop];
}
return obj[prop]++;

@@ -124,7 +127,8 @@ },

provide('currentSlide', currentSlide);
const { default: slotDefault, slides: slotSlides, addons: slotAddons } = slots;
const slidesElements = (slotSlides === null || slotSlides === void 0 ? void 0 : slotSlides()) || (slotDefault === null || slotDefault === void 0 ? void 0 : slotDefault()) || [];
const addonsElements = (slotAddons === null || slotAddons === void 0 ? void 0 : slotAddons()) || [];
watchEffect(() => {
var _a, _b;
if (slots.slides) {
slides.value = ((_b = (_a = slots.slides()) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.children) || [];
}
var _a;
slides.value = ((_a = slidesElements[0]) === null || _a === void 0 ? void 0 : _a.children) || [];
// Handel when slides added/removed

@@ -135,2 +139,4 @@ const needToUpdate = slidesCount.value !== slides.value.length;

updateSlidesBuffer();
}
if (slidesCounter.read) {
slidesCounter.value = slides.value.length - 1;

@@ -157,7 +163,7 @@ }

}
const handleWindowResize = () => debounce(() => {
const handleWindowResize = debounce(() => {
if (breakpoints.value)
updateConfig();
updateSlideWidth();
}, 500);
}, 300);
/**

@@ -190,2 +196,3 @@ * Setup functions

updateConfig();
// @ts-ignore
window.addEventListener('resize', handleWindowResize, { passive: true });

@@ -201,3 +208,3 @@ });

const isDragging = ref(false);
const handleDrag = () => function (event) {
const handleDrag = function (event) {
endPosition.x = isTouch ? event.touches[0].clientX : event.clientX;

@@ -221,2 +228,3 @@ endPosition.y = isTouch ? event.touches[0].clientY : event.clientY;

startPosition.y = isTouch ? event.touches[0].clientY : event.clientY;
// @ts-ignore
document.addEventListener(isTouch ? 'touchmove' : 'mousemove', handleDrag);

@@ -231,2 +239,3 @@ document.addEventListener(isTouch ? 'touchend' : 'mouseup', handleDragEnd);

dragged.y = 0;
// @ts-ignore
document.removeEventListener(isTouch ? 'touchmove' : 'mousemove', handleDrag);

@@ -285,9 +294,9 @@ document.removeEventListener(isTouch ? 'touchend' : 'mouseup', handleDragEnd);

*/
const trackStyle = computed(() => {
let slidesToScroll = slidesBuffer.value.indexOf(currentSlide.value);
const slidesToScroll = computed(() => {
let output = slidesBuffer.value.indexOf(currentSlide.value);
if (config.mode === 'center') {
slidesToScroll -= (config.itemsToShow - 1) / 2;
output -= (config.itemsToShow - 1) / 2;
}
if (config.mode === 'end') {
slidesToScroll -= config.itemsToShow - 1;
output -= config.itemsToShow - 1;
}

@@ -297,5 +306,8 @@ if (!config.wrapAround) {

const min = 0;
slidesToScroll = Math.max(Math.min(slidesToScroll, max), min);
output = Math.max(Math.min(output, max), min);
}
const xScroll = slidesToScroll * slideWidth.value - dragged.x;
return output;
});
const trackStyle = computed(() => {
const xScroll = slidesToScroll.value * slideWidth.value - dragged.x;
return {

@@ -306,19 +318,16 @@ transform: `translateX(-${xScroll}px)`,

});
const { default: slotDefault, slides: slotSlides, addons: slotAddons } = slots;
const slidesEl = (slotSlides === null || slotSlides === void 0 ? void 0 : slotSlides()) || (slotDefault === null || slotDefault === void 0 ? void 0 : slotDefault()) || [];
const addonsEl = (slotAddons === null || slotAddons === void 0 ? void 0 : slotAddons()) || [];
const trackEl = h('ol', {
class: 'carousel__track',
style: trackStyle,
on: { mousedown: handleDragStart, touchstrat: handleDragStart },
}, slidesEl);
const viewPortEl = h('div', { class: 'carousel__viewport' }, trackEl);
return () => h('section', {
inheritAttrs: false,
ref: 'root',
class: 'carousel',
attrs: {
return () => {
const trackEl = h('ol', {
class: 'carousel__track',
style: trackStyle.value,
onMousedown: handleDragStart,
onTouchstart: handleDragStart,
}, slidesElements);
const viewPortEl = h('div', { class: 'carousel__viewport' }, trackEl);
return h('section', {
ref: root,
class: 'carousel',
'aria-label': 'Gallery',
},
}, [viewPortEl, addonsEl]);
}, [viewPortEl, addonsElements]);
};
},

@@ -334,41 +343,26 @@ });

var Icon = defineComponent({
name: 'Icon',
props: { name: String, title: String },
setup(props) {
const iconName = props.name;
if (!iconName || typeof iconName !== 'string') {
return;
}
const path = icons[iconName];
const pathEl = h('path', { attrs: { d: path } });
const iconTitle = props.title || iconName;
const titleEl = h('title', null, iconName);
return () => h('svg', {
class: 'carousel__icon',
attrs: { viewBox: '0 0 24 24', role: 'img' },
}, [titleEl, pathEl]);
},
});
const Icon = (props) => {
const iconName = props.name;
if (!iconName || typeof iconName !== 'string') {
return;
}
const path = icons[iconName];
const pathEl = h('path', { d: path });
const iconTitle = props.title || iconName;
const titleEl = h('title', null, iconName);
return h('svg', {
class: 'carousel__icon',
viewBox: '0 0 24 24',
role: 'img',
}, [titleEl, pathEl]);
};
Icon.props = { name: String, title: String };
var Navigation = defineComponent({
name: 'Navigation',
components: {
Icon,
},
setup(_, { emit }) {
const nav = inject('nav', {});
function handleNextClick() {
nav.next();
emit('next');
}
function handlePrevClick() {
nav.prev();
emit('prev');
}
const prevButton = h('button', { class: 'carousel__prev', on: { click: handlePrevClick } }, h(Icon, { props: { name: 'arrowLeft' } }));
const nextButton = h('button', { class: 'carousel__next', on: { click: handleNextClick } }, h(Icon, { props: { name: 'arrowRight' } }));
return () => h('div', [prevButton, nextButton]);
},
});
const Navigation = (props, { slots }) => {
const { next: slotNext, prev: slotPrev } = slots;
const nav = inject('nav', {});
const prevButton = h('button', { class: 'carousel__prev', onClick: nav.prev }, (slotPrev === null || slotPrev === void 0 ? void 0 : slotPrev()) || h(Icon, { name: 'arrowLeft' }));
const nextButton = h('button', { class: 'carousel__next', onClick: nav.next }, (slotNext === null || slotNext === void 0 ? void 0 : slotNext()) || h(Icon, { name: 'arrowRight' }));
return [prevButton, nextButton];
};

@@ -386,4 +380,4 @@ var Slide = defineComponent({

const slidesBuffer = inject('slidesBuffer', ref([]));
const slideOrder = ref(slidesCounter.value);
const wrapOrder = ref(slideOrder.value);
const slideOrder = slidesCounter.value;
const wrapOrder = ref(slideOrder);
if (config.wrapAround) {

@@ -393,2 +387,5 @@ updateOrder();

}
function updateOrder() {
wrapOrder.value = slidesBuffer.value.indexOf(slideOrder);
}
const slideStyle = computed(() => {

@@ -402,37 +399,28 @@ const items = config.itemsToShow;

});
function updateOrder() {
wrapOrder.value = slidesBuffer.value.indexOf(slideOrder.value);
}
return () => { var _a; return h('li', { style: slideStyle, class: 'carousel__slide' }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };
return () => { var _a; return h('li', { style: slideStyle.value, class: 'carousel__slide' }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };
},
});
var Pagination = defineComponent({
name: 'Pagination',
setup(_, { emit }) {
const slidesCount = inject('slidesCount', ref(0));
const currentSlide = inject('currentSlide', ref(1));
const nav = inject('nav', {});
function handleButtonClick(slideNumber) {
nav.slideTo(slideNumber);
emit('slide', slideNumber);
}
const children = [];
for (let slide = 0; slide < slidesCount.value; slide++) {
const button = h('button', {
class: {
'carousel__pagination-button': true,
'carousel__pagination-button--active': currentSlide.value === slide,
},
on: {
click: () => handleButtonClick(slide),
},
});
const item = h('li', { class: 'carousel__pagination-item', key: slide }, button);
children.push(item);
}
return () => h('ol', { class: 'carousel__pagination' }, children);
},
});
const Pagination = () => {
const slidesCount = inject('slidesCount', ref(1));
const currentSlide = inject('currentSlide', ref(1));
const nav = inject('nav', {});
function handleButtonClick(slideNumber) {
nav.slideTo(slideNumber);
}
const children = [];
for (let slide = 0; slide < slidesCount.value; slide++) {
const button = h('button', {
class: {
'carousel__pagination-button': true,
'carousel__pagination-button--active': currentSlide.value === slide,
},
onClick: () => handleButtonClick(slide),
});
const item = h('li', { class: 'carousel__pagination-item', key: slide }, button);
children.push(item);
}
return h('ol', { class: 'carousel__pagination' }, children);
};
export { Carousel, Icon, Navigation, Pagination, Slide };
/**
* Vue 3 Carousel 0.1.2
* Vue 3 Carousel 0.1.3
* (c) 2020

@@ -31,6 +31,9 @@ * @license MIT

var slidesCounter = new Proxy({ value: 0 }, {
var slidesCounter = new Proxy({ value: 0, read: 0 }, {
get(obj, prop) {
if (!(prop in obj))
return 0;
if (prop === 'read') {
return obj[prop];
}
return obj[prop]++;

@@ -128,7 +131,8 @@ },

vue.provide('currentSlide', currentSlide);
const { default: slotDefault, slides: slotSlides, addons: slotAddons } = slots;
const slidesElements = (slotSlides === null || slotSlides === void 0 ? void 0 : slotSlides()) || (slotDefault === null || slotDefault === void 0 ? void 0 : slotDefault()) || [];
const addonsElements = (slotAddons === null || slotAddons === void 0 ? void 0 : slotAddons()) || [];
vue.watchEffect(() => {
var _a, _b;
if (slots.slides) {
slides.value = ((_b = (_a = slots.slides()) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.children) || [];
}
var _a;
slides.value = ((_a = slidesElements[0]) === null || _a === void 0 ? void 0 : _a.children) || [];
// Handel when slides added/removed

@@ -139,2 +143,4 @@ const needToUpdate = slidesCount.value !== slides.value.length;

updateSlidesBuffer();
}
if (slidesCounter.read) {
slidesCounter.value = slides.value.length - 1;

@@ -161,7 +167,7 @@ }

}
const handleWindowResize = () => debounce(() => {
const handleWindowResize = debounce(() => {
if (breakpoints.value)
updateConfig();
updateSlideWidth();
}, 500);
}, 300);
/**

@@ -194,2 +200,3 @@ * Setup functions

updateConfig();
// @ts-ignore
window.addEventListener('resize', handleWindowResize, { passive: true });

@@ -205,3 +212,3 @@ });

const isDragging = vue.ref(false);
const handleDrag = () => function (event) {
const handleDrag = function (event) {
endPosition.x = isTouch ? event.touches[0].clientX : event.clientX;

@@ -225,2 +232,3 @@ endPosition.y = isTouch ? event.touches[0].clientY : event.clientY;

startPosition.y = isTouch ? event.touches[0].clientY : event.clientY;
// @ts-ignore
document.addEventListener(isTouch ? 'touchmove' : 'mousemove', handleDrag);

@@ -235,2 +243,3 @@ document.addEventListener(isTouch ? 'touchend' : 'mouseup', handleDragEnd);

dragged.y = 0;
// @ts-ignore
document.removeEventListener(isTouch ? 'touchmove' : 'mousemove', handleDrag);

@@ -289,9 +298,9 @@ document.removeEventListener(isTouch ? 'touchend' : 'mouseup', handleDragEnd);

*/
const trackStyle = vue.computed(() => {
let slidesToScroll = slidesBuffer.value.indexOf(currentSlide.value);
const slidesToScroll = vue.computed(() => {
let output = slidesBuffer.value.indexOf(currentSlide.value);
if (config.mode === 'center') {
slidesToScroll -= (config.itemsToShow - 1) / 2;
output -= (config.itemsToShow - 1) / 2;
}
if (config.mode === 'end') {
slidesToScroll -= config.itemsToShow - 1;
output -= config.itemsToShow - 1;
}

@@ -301,5 +310,8 @@ if (!config.wrapAround) {

const min = 0;
slidesToScroll = Math.max(Math.min(slidesToScroll, max), min);
output = Math.max(Math.min(output, max), min);
}
const xScroll = slidesToScroll * slideWidth.value - dragged.x;
return output;
});
const trackStyle = vue.computed(() => {
const xScroll = slidesToScroll.value * slideWidth.value - dragged.x;
return {

@@ -310,19 +322,16 @@ transform: `translateX(-${xScroll}px)`,

});
const { default: slotDefault, slides: slotSlides, addons: slotAddons } = slots;
const slidesEl = (slotSlides === null || slotSlides === void 0 ? void 0 : slotSlides()) || (slotDefault === null || slotDefault === void 0 ? void 0 : slotDefault()) || [];
const addonsEl = (slotAddons === null || slotAddons === void 0 ? void 0 : slotAddons()) || [];
const trackEl = vue.h('ol', {
class: 'carousel__track',
style: trackStyle,
on: { mousedown: handleDragStart, touchstrat: handleDragStart },
}, slidesEl);
const viewPortEl = vue.h('div', { class: 'carousel__viewport' }, trackEl);
return () => vue.h('section', {
inheritAttrs: false,
ref: 'root',
class: 'carousel',
attrs: {
return () => {
const trackEl = vue.h('ol', {
class: 'carousel__track',
style: trackStyle.value,
onMousedown: handleDragStart,
onTouchstart: handleDragStart,
}, slidesElements);
const viewPortEl = vue.h('div', { class: 'carousel__viewport' }, trackEl);
return vue.h('section', {
ref: root,
class: 'carousel',
'aria-label': 'Gallery',
},
}, [viewPortEl, addonsEl]);
}, [viewPortEl, addonsElements]);
};
},

@@ -338,41 +347,26 @@ });

var Icon = vue.defineComponent({
name: 'Icon',
props: { name: String, title: String },
setup(props) {
const iconName = props.name;
if (!iconName || typeof iconName !== 'string') {
return;
}
const path = icons[iconName];
const pathEl = vue.h('path', { attrs: { d: path } });
const iconTitle = props.title || iconName;
const titleEl = vue.h('title', null, iconName);
return () => vue.h('svg', {
class: 'carousel__icon',
attrs: { viewBox: '0 0 24 24', role: 'img' },
}, [titleEl, pathEl]);
},
});
const Icon = (props) => {
const iconName = props.name;
if (!iconName || typeof iconName !== 'string') {
return;
}
const path = icons[iconName];
const pathEl = vue.h('path', { d: path });
const iconTitle = props.title || iconName;
const titleEl = vue.h('title', null, iconName);
return vue.h('svg', {
class: 'carousel__icon',
viewBox: '0 0 24 24',
role: 'img',
}, [titleEl, pathEl]);
};
Icon.props = { name: String, title: String };
var Navigation = vue.defineComponent({
name: 'Navigation',
components: {
Icon,
},
setup(_, { emit }) {
const nav = vue.inject('nav', {});
function handleNextClick() {
nav.next();
emit('next');
}
function handlePrevClick() {
nav.prev();
emit('prev');
}
const prevButton = vue.h('button', { class: 'carousel__prev', on: { click: handlePrevClick } }, vue.h(Icon, { props: { name: 'arrowLeft' } }));
const nextButton = vue.h('button', { class: 'carousel__next', on: { click: handleNextClick } }, vue.h(Icon, { props: { name: 'arrowRight' } }));
return () => vue.h('div', [prevButton, nextButton]);
},
});
const Navigation = (props, { slots }) => {
const { next: slotNext, prev: slotPrev } = slots;
const nav = vue.inject('nav', {});
const prevButton = vue.h('button', { class: 'carousel__prev', onClick: nav.prev }, (slotPrev === null || slotPrev === void 0 ? void 0 : slotPrev()) || vue.h(Icon, { name: 'arrowLeft' }));
const nextButton = vue.h('button', { class: 'carousel__next', onClick: nav.next }, (slotNext === null || slotNext === void 0 ? void 0 : slotNext()) || vue.h(Icon, { name: 'arrowRight' }));
return [prevButton, nextButton];
};

@@ -390,4 +384,4 @@ var Slide = vue.defineComponent({

const slidesBuffer = vue.inject('slidesBuffer', vue.ref([]));
const slideOrder = vue.ref(slidesCounter.value);
const wrapOrder = vue.ref(slideOrder.value);
const slideOrder = slidesCounter.value;
const wrapOrder = vue.ref(slideOrder);
if (config.wrapAround) {

@@ -397,2 +391,5 @@ updateOrder();

}
function updateOrder() {
wrapOrder.value = slidesBuffer.value.indexOf(slideOrder);
}
const slideStyle = vue.computed(() => {

@@ -406,36 +403,27 @@ const items = config.itemsToShow;

});
function updateOrder() {
wrapOrder.value = slidesBuffer.value.indexOf(slideOrder.value);
}
return () => { var _a; return vue.h('li', { style: slideStyle, class: 'carousel__slide' }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };
return () => { var _a; return vue.h('li', { style: slideStyle.value, class: 'carousel__slide' }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };
},
});
var Pagination = vue.defineComponent({
name: 'Pagination',
setup(_, { emit }) {
const slidesCount = vue.inject('slidesCount', vue.ref(0));
const currentSlide = vue.inject('currentSlide', vue.ref(1));
const nav = vue.inject('nav', {});
function handleButtonClick(slideNumber) {
nav.slideTo(slideNumber);
emit('slide', slideNumber);
}
const children = [];
for (let slide = 0; slide < slidesCount.value; slide++) {
const button = vue.h('button', {
class: {
'carousel__pagination-button': true,
'carousel__pagination-button--active': currentSlide.value === slide,
},
on: {
click: () => handleButtonClick(slide),
},
});
const item = vue.h('li', { class: 'carousel__pagination-item', key: slide }, button);
children.push(item);
}
return () => vue.h('ol', { class: 'carousel__pagination' }, children);
},
});
const Pagination = () => {
const slidesCount = vue.inject('slidesCount', vue.ref(1));
const currentSlide = vue.inject('currentSlide', vue.ref(1));
const nav = vue.inject('nav', {});
function handleButtonClick(slideNumber) {
nav.slideTo(slideNumber);
}
const children = [];
for (let slide = 0; slide < slidesCount.value; slide++) {
const button = vue.h('button', {
class: {
'carousel__pagination-button': true,
'carousel__pagination-button--active': currentSlide.value === slide,
},
onClick: () => handleButtonClick(slide),
});
const item = vue.h('li', { class: 'carousel__pagination-item', key: slide }, button);
children.push(item);
}
return vue.h('ol', { class: 'carousel__pagination' }, children);
};

@@ -442,0 +430,0 @@ exports.Carousel = Carousel;

@@ -1,2 +0,9 @@

declare const _default: never;
export default _default;
import { Data } from '../types';
declare const Icon: {
(props: Data): import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement> | undefined;
props: {
name: StringConstructor;
title: StringConstructor;
};
};
export default Icon;

@@ -1,2 +0,2 @@

declare const _default: never;
export default _default;
declare const Navigation: (props: any, { slots }: any) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement>[];
export default Navigation;

@@ -1,2 +0,3 @@

declare const _default: never;
export default _default;
import { VNode } from '../types';
declare const Pagination: () => VNode<import("vue").RendererNode, import("vue").RendererElement>;
export default Pagination;

@@ -1,4 +0,6 @@

declare const _default: {
interface Counter {
value: number;
};
[name: string]: any;
}
declare const _default: Counter;
export default _default;
{
"name": "vue3-carousel",
"version": "0.1.2",
"version": "0.1.3",
"scripts": {

@@ -18,3 +18,3 @@ "build": "rollup -c",

"typescript": "^3.9.2",
"vue": "^3.0.0-beta.13"
"vue": "^3.0.0-beta.14"
},

@@ -28,3 +28,4 @@ "peerDependencies": {

"not dead"
]
],
"license": "MIT"
}

@@ -5,2 +5,13 @@ # Vue 3 Carousel

## TODO
- [x] Responsive breakpoints
- [x] Mouse/touch dragging
- [x] Infinity scroll (wrapping around)
- [ ] Auto play
- [ ] RTL
- [ ] Vertical scroll
- [ ] Sync multiple carousel
- [ ] Enrich a11y
## Getting started

@@ -36,2 +47,3 @@

<script>
// If you are using PurgeCSS, make sure to whitelist the carousel CSS classes
import 'vue3-carousel/dist/carousel.css';

@@ -38,0 +50,0 @@ import { Carousel, Slide, Pagination, Navigation } from 'vue3-carousel';

{
"compilerOptions": {
"target": "es6",
"moduleResolution": "node",
"strict": true,

@@ -5,0 +6,0 @@ "importHelpers": true,

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc