vue-snap 1.2.0 → 1.4.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 CHANGED
@@ -31,6 +31,7 @@ The idea behind this plugin is to create a fully responsive and well-optimized c
31
31
  - **No calculations or heavy logic** – performance-first approach
32
32
  - **Fully responsive** – most customization is handled via CSS (e.g. number of visible slides)
33
33
  - **ESM bundle with tree-shaking** – dead code is automatically eliminated
34
+ - **TypeScript support** – ships with bundled type declarations out of the box
34
35
  - **SSR support** – works with frameworks like Nuxt.js 🎉 [More here](https://github.com/bartdominiak/vue-snap/tree/master/examples)
35
36
  - **Vue 3 support** 🎉 [More here](#installation--usage)
36
37
  - **Modern browser support** – compatible with all common browsers [More here](https://caniuse.com/css-snappoints)
@@ -52,7 +53,7 @@ import { createApp } from 'vue'
52
53
  import App from './App.vue'
53
54
 
54
55
  import VueSnap from 'vue-snap'
55
- import 'vue-snap/dist/vue-snap.css'
56
+ import 'vue-snap/style.css'
56
57
 
57
58
  const myApp = createApp(App)
58
59
 
@@ -64,7 +65,7 @@ myApp.mount('#app')
64
65
 
65
66
  ```js
66
67
  import { Carousel, Slide } from 'vue-snap'
67
- import 'vue-snap/dist/vue-snap.css'
68
+ import 'vue-snap/style.css'
68
69
 
69
70
  export default {
70
71
  components: {
@@ -0,0 +1,55 @@
1
+ interface CarouselProps {
2
+ tag?: string;
3
+ hideArrows?: boolean;
4
+ hideArrowsOnBound?: boolean;
5
+ autoplay?: boolean;
6
+ autoplayInterval?: number;
7
+ i18n?: {
8
+ slideLeft: string;
9
+ slideRight: string;
10
+ };
11
+ }
12
+ declare var __VLS_9: {}, __VLS_11: {
13
+ changeSlide: (direction: number) => void;
14
+ isBoundLeft: boolean;
15
+ isBoundRight: boolean;
16
+ };
17
+ type __VLS_Slots = {} & {
18
+ default?: (props: typeof __VLS_9) => any;
19
+ } & {
20
+ arrows?: (props: typeof __VLS_11) => any;
21
+ };
22
+ declare const __VLS_base: import('vue').DefineComponent<CarouselProps, {
23
+ changeSlide: (direction: number) => void;
24
+ goToSlide: (index: number) => void;
25
+ }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
26
+ mounted: (...args: any[]) => void;
27
+ slideChange: (...args: any[]) => void;
28
+ leftBound: (...args: any[]) => void;
29
+ rightBound: (...args: any[]) => void;
30
+ autoplay: (...args: any[]) => void;
31
+ }, string, import('vue').PublicProps, Readonly<CarouselProps> & Readonly<{
32
+ onMounted?: ((...args: any[]) => any) | undefined;
33
+ onSlideChange?: ((...args: any[]) => any) | undefined;
34
+ onLeftBound?: ((...args: any[]) => any) | undefined;
35
+ onRightBound?: ((...args: any[]) => any) | undefined;
36
+ onAutoplay?: ((...args: any[]) => any) | undefined;
37
+ }>, {
38
+ autoplay: boolean;
39
+ autoplayInterval: number;
40
+ tag: string;
41
+ hideArrows: boolean;
42
+ hideArrowsOnBound: boolean;
43
+ i18n: {
44
+ slideLeft: string;
45
+ slideRight: string;
46
+ };
47
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
48
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
49
+ declare const _default: typeof __VLS_export;
50
+ export default _default;
51
+ type __VLS_WithSlots<T, S> = T & {
52
+ new (): {
53
+ $slots: S;
54
+ };
55
+ };
@@ -0,0 +1,31 @@
1
+ declare var __VLS_9: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_9) => any;
4
+ };
5
+ declare const __VLS_base: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
6
+ /**
7
+ * Custom tag
8
+ */
9
+ tag: {
10
+ type: StringConstructor;
11
+ default: string;
12
+ };
13
+ }>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
14
+ /**
15
+ * Custom tag
16
+ */
17
+ tag: {
18
+ type: StringConstructor;
19
+ default: string;
20
+ };
21
+ }>> & Readonly<{}>, {
22
+ tag: string;
23
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
24
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
25
+ declare const _default: typeof __VLS_export;
26
+ export default _default;
27
+ type __VLS_WithSlots<T, S> = T & {
28
+ new (): {
29
+ $slots: S;
30
+ };
31
+ };
@@ -0,0 +1,8 @@
1
+ import { App } from 'vue';
2
+ import { default as Carousel } from './components/Carousel.vue';
3
+ import { default as Slide } from './components/Slide.vue';
4
+ export declare const VueSnap: {
5
+ install: (app: App) => void;
6
+ };
7
+ export { Carousel, Slide };
8
+ export default VueSnap;
@@ -0,0 +1,21 @@
1
+ import { Ref } from 'vue';
2
+ type CarouselEmits = {
3
+ (e: 'mounted', value: boolean): void;
4
+ (e: 'slideChange', index: number): void;
5
+ (e: 'leftBound', value: boolean): void;
6
+ (e: 'rightBound', value: boolean): void;
7
+ (e: 'autoplay', value: boolean): void;
8
+ };
9
+ type AutoplayOptions = {
10
+ autoplay: Ref<boolean>;
11
+ autoplayInterval: Ref<number>;
12
+ };
13
+ export declare function useCarousel(emit: CarouselEmits, vsWrapper: Ref<HTMLElement | null>, { autoplay, autoplayInterval }: AutoplayOptions): {
14
+ goToSlide: (index: number) => void;
15
+ changeSlide: (direction: number) => void;
16
+ isBoundLeft: Ref<boolean, boolean>;
17
+ isBoundRight: Ref<boolean, boolean>;
18
+ pauseAutoplay: () => void;
19
+ resumeAutoplay: () => void;
20
+ };
21
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare const isClient: boolean;
2
+ export declare const approximatelyEqual: (v1: number, v2: number, epsilon?: number) => boolean;
3
+ export declare function debounce<T extends (...args: unknown[]) => void>(fn: T, wait: number): {
4
+ (...args: Parameters<T>): void;
5
+ cancel: () => void;
6
+ };
@@ -1,7 +1,7 @@
1
- import { createBlock as e, createElementBlock as t, createElementVNode as n, defineComponent as r, guardReactiveProps as i, normalizeProps as a, onBeforeUnmount as o, onMounted as s, openBlock as c, ref as l, renderSlot as u, resolveDynamicComponent as d, toRef as f, unref as p, vShow as m, watch as h, withCtx as g, withDirectives as _ } from "vue";
1
+ import { createBlock as e, createCommentVNode as t, createElementBlock as n, createElementVNode as r, defineComponent as i, mergeProps as a, normalizeProps as o, onBeforeUnmount as s, onMounted as c, openBlock as l, ref as u, renderSlot as d, resolveDynamicComponent as f, toRef as p, unref as m, vShow as h, watch as g, withCtx as _, withDirectives as v } from "vue";
2
2
  //#region src/utils/helpers.ts
3
- var v = typeof window < "u", y = (e, t, n = 5) => Math.abs(e - t) <= n;
4
- function b(e, t) {
3
+ var y = typeof window < "u", b = (e, t, n = 5) => Math.abs(e - t) <= n;
4
+ function x(e, t) {
5
5
  let n = null, r = (...r) => {
6
6
  n && clearTimeout(n), n = setTimeout(() => {
7
7
  e(...r);
@@ -13,9 +13,9 @@ function b(e, t) {
13
13
  }
14
14
  //#endregion
15
15
  //#region src/hooks/useCarousel.ts
16
- var x = 100;
17
- function S(e, t, { autoplay: n, autoplayInterval: r }) {
18
- let i = l(!0), a = l(!1), c = l(0), u = null, d = () => t.value ? Array.from(t.value.children ?? []).map((e) => ({
16
+ var S = 100;
17
+ function C(e, t, { autoplay: n, autoplayInterval: r }) {
18
+ let i = u(!0), a = u(!1), o = u(0), l = null, d = () => t.value ? Array.from(t.value.children ?? []).map((e) => ({
19
19
  offsetLeft: e.offsetLeft,
20
20
  offsetWidth: e.offsetWidth
21
21
  })) : [], f = (e) => {
@@ -23,50 +23,50 @@ function S(e, t, { autoplay: n, autoplayInterval: r }) {
23
23
  return !n || e.length === 0 ? -1 : e.reduce((t, r, i) => Math.abs(r.offsetLeft - n.scrollLeft) < Math.abs(e[t].offsetLeft - n.scrollLeft) ? i : t, 0);
24
24
  }, p = (n) => {
25
25
  if (!t.value) return;
26
- let { scrollLeft: r, offsetWidth: o, scrollWidth: s } = t.value;
27
- n !== c.value && e("slideChange", n), c.value = n;
28
- let l = n === 0, u = y(r + o, s, 10);
26
+ let { scrollLeft: r, offsetWidth: s, scrollWidth: c } = t.value;
27
+ n !== o.value && e("slideChange", n), o.value = n;
28
+ let l = n === 0, u = b(r + s, c, 10);
29
29
  l && !i.value && e("leftBound", !0), i.value = l, u && !a.value && e("rightBound", !0), a.value = u;
30
30
  }, m = (n) => {
31
31
  let r = d(), i = f(r);
32
32
  if (i === -1) return;
33
- let a = i + n, o = r[a];
34
- !o || !t.value || (t.value.scrollTo({
35
- left: o.offsetLeft,
33
+ let a = i + n, s = r[a];
34
+ !s || !t.value || (t.value.scrollTo({
35
+ left: s.offsetLeft,
36
36
  behavior: "smooth"
37
- }), c.value = a, e("slideChange", a), w());
38
- }, g = (n) => {
37
+ }), o.value = a, e("slideChange", a), w());
38
+ }, h = (n) => {
39
39
  let r = d()[n];
40
40
  !r || !t.value || (t.value.scrollTo({
41
41
  left: r.offsetLeft,
42
42
  behavior: "smooth"
43
- }), c.value = n, e("slideChange", n), w());
43
+ }), o.value = n, e("slideChange", n), w());
44
44
  }, _ = () => {
45
- a.value ? g(0) : m(1);
46
- }, S = () => {
47
- u &&= (clearInterval(u), null);
45
+ a.value ? h(0) : m(1);
46
+ }, v = () => {
47
+ l &&= (clearInterval(l), null);
48
48
  }, C = () => {
49
- S(), !(!v || !n.value) && (u = setInterval(_, r.value));
49
+ v(), !(!y || !n.value) && (l = setInterval(_, r.value));
50
50
  }, w = () => {
51
51
  n.value && C();
52
52
  }, T = () => {
53
- !n.value || !u || (S(), e("autoplay", !1));
53
+ !n.value || !l || (v(), e("autoplay", !1));
54
54
  }, E = () => {
55
- !n.value || u || (C(), e("autoplay", !0));
55
+ !n.value || l || (C(), e("autoplay", !0));
56
56
  }, D = () => {
57
57
  let e = d(), t = f(e);
58
58
  t !== -1 && p(t);
59
- }, O = b(D, x);
60
- return h(n, (e) => {
61
- e ? C() : S();
62
- }), h(r, () => {
59
+ }, O = x(D, S);
60
+ return g(n, (e) => {
61
+ e ? C() : v();
62
+ }), g(r, () => {
63
63
  n.value && C();
64
+ }), c(() => {
65
+ !y || !t.value || (D(), t.value.addEventListener("scroll", O), e("mounted", !0), C());
64
66
  }), s(() => {
65
- !v || !t.value || (D(), t.value.addEventListener("scroll", O), e("mounted", !0), C());
66
- }), o(() => {
67
- S(), !(!v || !t.value) && t.value.removeEventListener("scroll", O);
67
+ v(), !(!y || !t.value) && t.value.removeEventListener("scroll", O);
68
68
  }), {
69
- goToSlide: g,
69
+ goToSlide: h,
70
70
  changeSlide: m,
71
71
  isBoundLeft: i,
72
72
  isBoundRight: a,
@@ -76,10 +76,14 @@ function S(e, t, { autoplay: n, autoplayInterval: r }) {
76
76
  }
77
77
  //#endregion
78
78
  //#region src/components/Carousel.vue?vue&type=script&setup=true&lang.ts
79
- var C = ["aria-label", "disabled"], w = ["aria-label", "disabled"], T = /* @__PURE__ */ r({
79
+ var w = ["aria-label", "disabled"], T = ["aria-label", "disabled"], E = /* @__PURE__ */ i({
80
80
  __name: "Carousel",
81
81
  props: {
82
82
  tag: { default: "ul" },
83
+ hideArrows: {
84
+ type: Boolean,
85
+ default: !1
86
+ },
83
87
  hideArrowsOnBound: {
84
88
  type: Boolean,
85
89
  default: !1
@@ -101,61 +105,61 @@ var C = ["aria-label", "disabled"], w = ["aria-label", "disabled"], T = /* @__PU
101
105
  "rightBound",
102
106
  "autoplay"
103
107
  ],
104
- setup(r, { expose: o, emit: s }) {
105
- let h = r, v = s, y = l(null), { changeSlide: b, goToSlide: x, isBoundLeft: T, isBoundRight: E, pauseAutoplay: D, resumeAutoplay: O } = S(v, y, {
106
- autoplay: f(h, "autoplay"),
107
- autoplayInterval: f(h, "autoplayInterval")
108
+ setup(i, { expose: s, emit: c }) {
109
+ let g = i, y = c, b = u(null), { changeSlide: x, goToSlide: S, isBoundLeft: E, isBoundRight: D, pauseAutoplay: O, resumeAutoplay: k } = C(y, b, {
110
+ autoplay: p(g, "autoplay"),
111
+ autoplayInterval: p(g, "autoplayInterval")
108
112
  });
109
- return o({
110
- changeSlide: b,
111
- goToSlide: x
112
- }), (r, o) => (c(), t("div", {
113
+ return s({
114
+ changeSlide: x,
115
+ goToSlide: S
116
+ }), (i, s) => (l(), n("div", {
113
117
  class: "vs-carousel",
114
- onMouseenter: o[2] ||= (...e) => p(D) && p(D)(...e),
115
- onMouseleave: o[3] ||= (...e) => p(O) && p(O)(...e)
116
- }, [(c(), e(d(r.tag), {
118
+ onMouseenter: s[2] ||= (...e) => m(O) && m(O)(...e),
119
+ onMouseleave: s[3] ||= (...e) => m(k) && m(k)(...e)
120
+ }, [(l(), e(f(i.tag), {
117
121
  ref_key: "vsWrapper",
118
- ref: y,
122
+ ref: b,
119
123
  class: "vs-carousel__wrapper"
120
124
  }, {
121
- default: g(() => [u(r.$slots, "default")]),
125
+ default: _(() => [d(i.$slots, "default")]),
122
126
  _: 3
123
- }, 512)), u(r.$slots, "arrows", a(i({
124
- changeSlide: p(b),
125
- isBoundLeft: p(T),
126
- isBoundRight: p(E)
127
- })), () => [_(n("button", {
127
+ }, 512)), i.hideArrows ? t("", !0) : d(i.$slots, "arrows", o(a({ key: 0 }, {
128
+ changeSlide: m(x),
129
+ isBoundLeft: m(E),
130
+ isBoundRight: m(D)
131
+ })), () => [v(r("button", {
128
132
  type: "button",
129
- "aria-label": r.i18n.slideLeft,
130
- disabled: p(T),
133
+ "aria-label": i.i18n.slideLeft,
134
+ disabled: m(E),
131
135
  class: "vs-carousel__arrows vs-carousel__arrows--left",
132
- onClick: o[0] ||= (e) => p(b)(-1)
133
- }, " ← ", 8, C), [[m, !r.hideArrowsOnBound || !p(T)]]), _(n("button", {
136
+ onClick: s[0] ||= (e) => m(x)(-1)
137
+ }, " ← ", 8, w), [[h, !i.hideArrowsOnBound || !m(E)]]), v(r("button", {
134
138
  type: "button",
135
- "aria-label": r.i18n.slideRight,
136
- disabled: p(E),
139
+ "aria-label": i.i18n.slideRight,
140
+ disabled: m(D),
137
141
  class: "vs-carousel__arrows vs-carousel__arrows--right",
138
- onClick: o[1] ||= (e) => p(b)(1)
139
- }, " → ", 8, w), [[m, !r.hideArrowsOnBound || !p(E)]])])], 32));
142
+ onClick: s[1] ||= (e) => m(x)(1)
143
+ }, " → ", 8, T), [[h, !i.hideArrowsOnBound || !m(D)]])])], 32));
140
144
  }
141
- }), E = /* @__PURE__ */ r({
145
+ }), D = /* @__PURE__ */ i({
142
146
  __name: "Slide",
143
147
  props: { tag: {
144
148
  type: String,
145
149
  default: "li"
146
150
  } },
147
151
  setup(t) {
148
- return (n, r) => (c(), e(d(t.tag), {
152
+ return (n, r) => (l(), e(f(t.tag), {
149
153
  ref: "vsSlide",
150
154
  class: "vs-carousel__slide",
151
155
  tabindex: "0"
152
156
  }, {
153
- default: g(() => [u(n.$slots, "default")]),
157
+ default: _(() => [d(n.$slots, "default")]),
154
158
  _: 3
155
159
  }, 512));
156
160
  }
157
- }), D = { install: (e) => {
158
- e.component("Carousel", T), e.component("Slide", E);
161
+ }), O = { install: (e) => {
162
+ e.component("Carousel", E), e.component("Slide", D);
159
163
  } };
160
164
  //#endregion
161
- export { T as Carousel, E as Slide, D as VueSnap, D as default };
165
+ export { E as Carousel, D as Slide, O as VueSnap, O as default };
package/dist/vue-snap.js CHANGED
@@ -1 +1 @@
1
- var VueSnap=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n=typeof window<`u`,r=(e,t,n=5)=>Math.abs(e-t)<=n;function i(e,t){let n=null,r=(...r)=>{n&&clearTimeout(n),n=setTimeout(()=>{e(...r)},t)};return r.cancel=()=>{n&&clearTimeout(n),n=null},r}var a=100;function o(e,o,{autoplay:s,autoplayInterval:c}){let l=(0,t.ref)(!0),u=(0,t.ref)(!1),d=(0,t.ref)(0),f=null,p=()=>o.value?Array.from(o.value.children??[]).map(e=>({offsetLeft:e.offsetLeft,offsetWidth:e.offsetWidth})):[],m=e=>{let t=o.value;return!t||e.length===0?-1:e.reduce((n,r,i)=>Math.abs(r.offsetLeft-t.scrollLeft)<Math.abs(e[n].offsetLeft-t.scrollLeft)?i:n,0)},h=t=>{if(!o.value)return;let{scrollLeft:n,offsetWidth:i,scrollWidth:a}=o.value;t!==d.value&&e(`slideChange`,t),d.value=t;let s=t===0,c=r(n+i,a,10);s&&!l.value&&e(`leftBound`,!0),l.value=s,c&&!u.value&&e(`rightBound`,!0),u.value=c},g=t=>{let n=p(),r=m(n);if(r===-1)return;let i=r+t,a=n[i];!a||!o.value||(o.value.scrollTo({left:a.offsetLeft,behavior:`smooth`}),d.value=i,e(`slideChange`,i),x())},_=t=>{let n=p()[t];!n||!o.value||(o.value.scrollTo({left:n.offsetLeft,behavior:`smooth`}),d.value=t,e(`slideChange`,t),x())},v=()=>{u.value?_(0):g(1)},y=()=>{f&&=(clearInterval(f),null)},b=()=>{y(),!(!n||!s.value)&&(f=setInterval(v,c.value))},x=()=>{s.value&&b()},S=()=>{!s.value||!f||(y(),e(`autoplay`,!1))},C=()=>{!s.value||f||(b(),e(`autoplay`,!0))},w=()=>{let e=p(),t=m(e);t!==-1&&h(t)},T=i(w,a);return(0,t.watch)(s,e=>{e?b():y()}),(0,t.watch)(c,()=>{s.value&&b()}),(0,t.onMounted)(()=>{!n||!o.value||(w(),o.value.addEventListener(`scroll`,T),e(`mounted`,!0),b())}),(0,t.onBeforeUnmount)(()=>{y(),!(!n||!o.value)&&o.value.removeEventListener(`scroll`,T)}),{goToSlide:_,changeSlide:g,isBoundLeft:l,isBoundRight:u,pauseAutoplay:S,resumeAutoplay:C}}var s=[`aria-label`,`disabled`],c=[`aria-label`,`disabled`],l=(0,t.defineComponent)({__name:`Carousel`,props:{tag:{default:`ul`},hideArrowsOnBound:{type:Boolean,default:!1},autoplay:{type:Boolean,default:!1},autoplayInterval:{default:3e3},i18n:{default:()=>({slideLeft:`Slide left`,slideRight:`Slide right`})}},emits:[`mounted`,`slideChange`,`leftBound`,`rightBound`,`autoplay`],setup(e,{expose:n,emit:r}){let i=e,a=r,l=(0,t.ref)(null),{changeSlide:u,goToSlide:d,isBoundLeft:f,isBoundRight:p,pauseAutoplay:m,resumeAutoplay:h}=o(a,l,{autoplay:(0,t.toRef)(i,`autoplay`),autoplayInterval:(0,t.toRef)(i,`autoplayInterval`)});return n({changeSlide:u,goToSlide:d}),(e,n)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{class:`vs-carousel`,onMouseenter:n[2]||=(...e)=>(0,t.unref)(m)&&(0,t.unref)(m)(...e),onMouseleave:n[3]||=(...e)=>(0,t.unref)(h)&&(0,t.unref)(h)(...e)},[((0,t.openBlock)(),(0,t.createBlock)((0,t.resolveDynamicComponent)(e.tag),{ref_key:`vsWrapper`,ref:l,class:`vs-carousel__wrapper`},{default:(0,t.withCtx)(()=>[(0,t.renderSlot)(e.$slots,`default`)]),_:3},512)),(0,t.renderSlot)(e.$slots,`arrows`,(0,t.normalizeProps)((0,t.guardReactiveProps)({changeSlide:(0,t.unref)(u),isBoundLeft:(0,t.unref)(f),isBoundRight:(0,t.unref)(p)})),()=>[(0,t.withDirectives)((0,t.createElementVNode)(`button`,{type:`button`,"aria-label":e.i18n.slideLeft,disabled:(0,t.unref)(f),class:`vs-carousel__arrows vs-carousel__arrows--left`,onClick:n[0]||=e=>(0,t.unref)(u)(-1)},` ← `,8,s),[[t.vShow,!e.hideArrowsOnBound||!(0,t.unref)(f)]]),(0,t.withDirectives)((0,t.createElementVNode)(`button`,{type:`button`,"aria-label":e.i18n.slideRight,disabled:(0,t.unref)(p),class:`vs-carousel__arrows vs-carousel__arrows--right`,onClick:n[1]||=e=>(0,t.unref)(u)(1)},` → `,8,c),[[t.vShow,!e.hideArrowsOnBound||!(0,t.unref)(p)]])])],32))}}),u=(0,t.defineComponent)({__name:`Slide`,props:{tag:{type:String,default:`li`}},setup(e){return(n,r)=>((0,t.openBlock)(),(0,t.createBlock)((0,t.resolveDynamicComponent)(e.tag),{ref:`vsSlide`,class:`vs-carousel__slide`,tabindex:`0`},{default:(0,t.withCtx)(()=>[(0,t.renderSlot)(n.$slots,`default`)]),_:3},512))}}),d={install:e=>{e.component(`Carousel`,l),e.component(`Slide`,u)}};return e.Carousel=l,e.Slide=u,e.VueSnap=d,e.default=d,e})({},Vue);
1
+ var VueSnap=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n=typeof window<`u`,r=(e,t,n=5)=>Math.abs(e-t)<=n;function i(e,t){let n=null,r=(...r)=>{n&&clearTimeout(n),n=setTimeout(()=>{e(...r)},t)};return r.cancel=()=>{n&&clearTimeout(n),n=null},r}var a=100;function o(e,o,{autoplay:s,autoplayInterval:c}){let l=(0,t.ref)(!0),u=(0,t.ref)(!1),d=(0,t.ref)(0),f=null,p=()=>o.value?Array.from(o.value.children??[]).map(e=>({offsetLeft:e.offsetLeft,offsetWidth:e.offsetWidth})):[],m=e=>{let t=o.value;return!t||e.length===0?-1:e.reduce((n,r,i)=>Math.abs(r.offsetLeft-t.scrollLeft)<Math.abs(e[n].offsetLeft-t.scrollLeft)?i:n,0)},h=t=>{if(!o.value)return;let{scrollLeft:n,offsetWidth:i,scrollWidth:a}=o.value;t!==d.value&&e(`slideChange`,t),d.value=t;let s=t===0,c=r(n+i,a,10);s&&!l.value&&e(`leftBound`,!0),l.value=s,c&&!u.value&&e(`rightBound`,!0),u.value=c},g=t=>{let n=p(),r=m(n);if(r===-1)return;let i=r+t,a=n[i];!a||!o.value||(o.value.scrollTo({left:a.offsetLeft,behavior:`smooth`}),d.value=i,e(`slideChange`,i),x())},_=t=>{let n=p()[t];!n||!o.value||(o.value.scrollTo({left:n.offsetLeft,behavior:`smooth`}),d.value=t,e(`slideChange`,t),x())},v=()=>{u.value?_(0):g(1)},y=()=>{f&&=(clearInterval(f),null)},b=()=>{y(),!(!n||!s.value)&&(f=setInterval(v,c.value))},x=()=>{s.value&&b()},S=()=>{!s.value||!f||(y(),e(`autoplay`,!1))},C=()=>{!s.value||f||(b(),e(`autoplay`,!0))},w=()=>{let e=p(),t=m(e);t!==-1&&h(t)},T=i(w,a);return(0,t.watch)(s,e=>{e?b():y()}),(0,t.watch)(c,()=>{s.value&&b()}),(0,t.onMounted)(()=>{!n||!o.value||(w(),o.value.addEventListener(`scroll`,T),e(`mounted`,!0),b())}),(0,t.onBeforeUnmount)(()=>{y(),!(!n||!o.value)&&o.value.removeEventListener(`scroll`,T)}),{goToSlide:_,changeSlide:g,isBoundLeft:l,isBoundRight:u,pauseAutoplay:S,resumeAutoplay:C}}var s=[`aria-label`,`disabled`],c=[`aria-label`,`disabled`],l=(0,t.defineComponent)({__name:`Carousel`,props:{tag:{default:`ul`},hideArrows:{type:Boolean,default:!1},hideArrowsOnBound:{type:Boolean,default:!1},autoplay:{type:Boolean,default:!1},autoplayInterval:{default:3e3},i18n:{default:()=>({slideLeft:`Slide left`,slideRight:`Slide right`})}},emits:[`mounted`,`slideChange`,`leftBound`,`rightBound`,`autoplay`],setup(e,{expose:n,emit:r}){let i=e,a=r,l=(0,t.ref)(null),{changeSlide:u,goToSlide:d,isBoundLeft:f,isBoundRight:p,pauseAutoplay:m,resumeAutoplay:h}=o(a,l,{autoplay:(0,t.toRef)(i,`autoplay`),autoplayInterval:(0,t.toRef)(i,`autoplayInterval`)});return n({changeSlide:u,goToSlide:d}),(e,n)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{class:`vs-carousel`,onMouseenter:n[2]||=(...e)=>(0,t.unref)(m)&&(0,t.unref)(m)(...e),onMouseleave:n[3]||=(...e)=>(0,t.unref)(h)&&(0,t.unref)(h)(...e)},[((0,t.openBlock)(),(0,t.createBlock)((0,t.resolveDynamicComponent)(e.tag),{ref_key:`vsWrapper`,ref:l,class:`vs-carousel__wrapper`},{default:(0,t.withCtx)(()=>[(0,t.renderSlot)(e.$slots,`default`)]),_:3},512)),e.hideArrows?(0,t.createCommentVNode)(``,!0):(0,t.renderSlot)(e.$slots,`arrows`,(0,t.normalizeProps)((0,t.mergeProps)({key:0},{changeSlide:(0,t.unref)(u),isBoundLeft:(0,t.unref)(f),isBoundRight:(0,t.unref)(p)})),()=>[(0,t.withDirectives)((0,t.createElementVNode)(`button`,{type:`button`,"aria-label":e.i18n.slideLeft,disabled:(0,t.unref)(f),class:`vs-carousel__arrows vs-carousel__arrows--left`,onClick:n[0]||=e=>(0,t.unref)(u)(-1)},` ← `,8,s),[[t.vShow,!e.hideArrowsOnBound||!(0,t.unref)(f)]]),(0,t.withDirectives)((0,t.createElementVNode)(`button`,{type:`button`,"aria-label":e.i18n.slideRight,disabled:(0,t.unref)(p),class:`vs-carousel__arrows vs-carousel__arrows--right`,onClick:n[1]||=e=>(0,t.unref)(u)(1)},` → `,8,c),[[t.vShow,!e.hideArrowsOnBound||!(0,t.unref)(p)]])])],32))}}),u=(0,t.defineComponent)({__name:`Slide`,props:{tag:{type:String,default:`li`}},setup(e){return(n,r)=>((0,t.openBlock)(),(0,t.createBlock)((0,t.resolveDynamicComponent)(e.tag),{ref:`vsSlide`,class:`vs-carousel__slide`,tabindex:`0`},{default:(0,t.withCtx)(()=>[(0,t.renderSlot)(n.$slots,`default`)]),_:3},512))}}),d={install:e=>{e.component(`Carousel`,l),e.component(`Slide`,u)}};return e.Carousel=l,e.Slide=u,e.VueSnap=d,e.default=d,e})({},Vue);
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("vue")):typeof define==`function`&&define.amd?define([`exports`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.VueSnap={},e.Vue))})(this,function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n=typeof window<`u`,r=(e,t,n=5)=>Math.abs(e-t)<=n;function i(e,t){let n=null,r=(...r)=>{n&&clearTimeout(n),n=setTimeout(()=>{e(...r)},t)};return r.cancel=()=>{n&&clearTimeout(n),n=null},r}var a=100;function o(e,o,{autoplay:s,autoplayInterval:c}){let l=(0,t.ref)(!0),u=(0,t.ref)(!1),d=(0,t.ref)(0),f=null,p=()=>o.value?Array.from(o.value.children??[]).map(e=>({offsetLeft:e.offsetLeft,offsetWidth:e.offsetWidth})):[],m=e=>{let t=o.value;return!t||e.length===0?-1:e.reduce((n,r,i)=>Math.abs(r.offsetLeft-t.scrollLeft)<Math.abs(e[n].offsetLeft-t.scrollLeft)?i:n,0)},h=t=>{if(!o.value)return;let{scrollLeft:n,offsetWidth:i,scrollWidth:a}=o.value;t!==d.value&&e(`slideChange`,t),d.value=t;let s=t===0,c=r(n+i,a,10);s&&!l.value&&e(`leftBound`,!0),l.value=s,c&&!u.value&&e(`rightBound`,!0),u.value=c},g=t=>{let n=p(),r=m(n);if(r===-1)return;let i=r+t,a=n[i];!a||!o.value||(o.value.scrollTo({left:a.offsetLeft,behavior:`smooth`}),d.value=i,e(`slideChange`,i),x())},_=t=>{let n=p()[t];!n||!o.value||(o.value.scrollTo({left:n.offsetLeft,behavior:`smooth`}),d.value=t,e(`slideChange`,t),x())},v=()=>{u.value?_(0):g(1)},y=()=>{f&&=(clearInterval(f),null)},b=()=>{y(),!(!n||!s.value)&&(f=setInterval(v,c.value))},x=()=>{s.value&&b()},S=()=>{!s.value||!f||(y(),e(`autoplay`,!1))},C=()=>{!s.value||f||(b(),e(`autoplay`,!0))},w=()=>{let e=p(),t=m(e);t!==-1&&h(t)},T=i(w,a);return(0,t.watch)(s,e=>{e?b():y()}),(0,t.watch)(c,()=>{s.value&&b()}),(0,t.onMounted)(()=>{!n||!o.value||(w(),o.value.addEventListener(`scroll`,T),e(`mounted`,!0),b())}),(0,t.onBeforeUnmount)(()=>{y(),!(!n||!o.value)&&o.value.removeEventListener(`scroll`,T)}),{goToSlide:_,changeSlide:g,isBoundLeft:l,isBoundRight:u,pauseAutoplay:S,resumeAutoplay:C}}var s=[`aria-label`,`disabled`],c=[`aria-label`,`disabled`],l=(0,t.defineComponent)({__name:`Carousel`,props:{tag:{default:`ul`},hideArrowsOnBound:{type:Boolean,default:!1},autoplay:{type:Boolean,default:!1},autoplayInterval:{default:3e3},i18n:{default:()=>({slideLeft:`Slide left`,slideRight:`Slide right`})}},emits:[`mounted`,`slideChange`,`leftBound`,`rightBound`,`autoplay`],setup(e,{expose:n,emit:r}){let i=e,a=r,l=(0,t.ref)(null),{changeSlide:u,goToSlide:d,isBoundLeft:f,isBoundRight:p,pauseAutoplay:m,resumeAutoplay:h}=o(a,l,{autoplay:(0,t.toRef)(i,`autoplay`),autoplayInterval:(0,t.toRef)(i,`autoplayInterval`)});return n({changeSlide:u,goToSlide:d}),(e,n)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{class:`vs-carousel`,onMouseenter:n[2]||=(...e)=>(0,t.unref)(m)&&(0,t.unref)(m)(...e),onMouseleave:n[3]||=(...e)=>(0,t.unref)(h)&&(0,t.unref)(h)(...e)},[((0,t.openBlock)(),(0,t.createBlock)((0,t.resolveDynamicComponent)(e.tag),{ref_key:`vsWrapper`,ref:l,class:`vs-carousel__wrapper`},{default:(0,t.withCtx)(()=>[(0,t.renderSlot)(e.$slots,`default`)]),_:3},512)),(0,t.renderSlot)(e.$slots,`arrows`,(0,t.normalizeProps)((0,t.guardReactiveProps)({changeSlide:(0,t.unref)(u),isBoundLeft:(0,t.unref)(f),isBoundRight:(0,t.unref)(p)})),()=>[(0,t.withDirectives)((0,t.createElementVNode)(`button`,{type:`button`,"aria-label":e.i18n.slideLeft,disabled:(0,t.unref)(f),class:`vs-carousel__arrows vs-carousel__arrows--left`,onClick:n[0]||=e=>(0,t.unref)(u)(-1)},` ← `,8,s),[[t.vShow,!e.hideArrowsOnBound||!(0,t.unref)(f)]]),(0,t.withDirectives)((0,t.createElementVNode)(`button`,{type:`button`,"aria-label":e.i18n.slideRight,disabled:(0,t.unref)(p),class:`vs-carousel__arrows vs-carousel__arrows--right`,onClick:n[1]||=e=>(0,t.unref)(u)(1)},` → `,8,c),[[t.vShow,!e.hideArrowsOnBound||!(0,t.unref)(p)]])])],32))}}),u=(0,t.defineComponent)({__name:`Slide`,props:{tag:{type:String,default:`li`}},setup(e){return(n,r)=>((0,t.openBlock)(),(0,t.createBlock)((0,t.resolveDynamicComponent)(e.tag),{ref:`vsSlide`,class:`vs-carousel__slide`,tabindex:`0`},{default:(0,t.withCtx)(()=>[(0,t.renderSlot)(n.$slots,`default`)]),_:3},512))}}),d={install:e=>{e.component(`Carousel`,l),e.component(`Slide`,u)}};e.Carousel=l,e.Slide=u,e.VueSnap=d,e.default=d});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("vue")):typeof define==`function`&&define.amd?define([`exports`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.VueSnap={},e.Vue))})(this,function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n=typeof window<`u`,r=(e,t,n=5)=>Math.abs(e-t)<=n;function i(e,t){let n=null,r=(...r)=>{n&&clearTimeout(n),n=setTimeout(()=>{e(...r)},t)};return r.cancel=()=>{n&&clearTimeout(n),n=null},r}var a=100;function o(e,o,{autoplay:s,autoplayInterval:c}){let l=(0,t.ref)(!0),u=(0,t.ref)(!1),d=(0,t.ref)(0),f=null,p=()=>o.value?Array.from(o.value.children??[]).map(e=>({offsetLeft:e.offsetLeft,offsetWidth:e.offsetWidth})):[],m=e=>{let t=o.value;return!t||e.length===0?-1:e.reduce((n,r,i)=>Math.abs(r.offsetLeft-t.scrollLeft)<Math.abs(e[n].offsetLeft-t.scrollLeft)?i:n,0)},h=t=>{if(!o.value)return;let{scrollLeft:n,offsetWidth:i,scrollWidth:a}=o.value;t!==d.value&&e(`slideChange`,t),d.value=t;let s=t===0,c=r(n+i,a,10);s&&!l.value&&e(`leftBound`,!0),l.value=s,c&&!u.value&&e(`rightBound`,!0),u.value=c},g=t=>{let n=p(),r=m(n);if(r===-1)return;let i=r+t,a=n[i];!a||!o.value||(o.value.scrollTo({left:a.offsetLeft,behavior:`smooth`}),d.value=i,e(`slideChange`,i),x())},_=t=>{let n=p()[t];!n||!o.value||(o.value.scrollTo({left:n.offsetLeft,behavior:`smooth`}),d.value=t,e(`slideChange`,t),x())},v=()=>{u.value?_(0):g(1)},y=()=>{f&&=(clearInterval(f),null)},b=()=>{y(),!(!n||!s.value)&&(f=setInterval(v,c.value))},x=()=>{s.value&&b()},S=()=>{!s.value||!f||(y(),e(`autoplay`,!1))},C=()=>{!s.value||f||(b(),e(`autoplay`,!0))},w=()=>{let e=p(),t=m(e);t!==-1&&h(t)},T=i(w,a);return(0,t.watch)(s,e=>{e?b():y()}),(0,t.watch)(c,()=>{s.value&&b()}),(0,t.onMounted)(()=>{!n||!o.value||(w(),o.value.addEventListener(`scroll`,T),e(`mounted`,!0),b())}),(0,t.onBeforeUnmount)(()=>{y(),!(!n||!o.value)&&o.value.removeEventListener(`scroll`,T)}),{goToSlide:_,changeSlide:g,isBoundLeft:l,isBoundRight:u,pauseAutoplay:S,resumeAutoplay:C}}var s=[`aria-label`,`disabled`],c=[`aria-label`,`disabled`],l=(0,t.defineComponent)({__name:`Carousel`,props:{tag:{default:`ul`},hideArrows:{type:Boolean,default:!1},hideArrowsOnBound:{type:Boolean,default:!1},autoplay:{type:Boolean,default:!1},autoplayInterval:{default:3e3},i18n:{default:()=>({slideLeft:`Slide left`,slideRight:`Slide right`})}},emits:[`mounted`,`slideChange`,`leftBound`,`rightBound`,`autoplay`],setup(e,{expose:n,emit:r}){let i=e,a=r,l=(0,t.ref)(null),{changeSlide:u,goToSlide:d,isBoundLeft:f,isBoundRight:p,pauseAutoplay:m,resumeAutoplay:h}=o(a,l,{autoplay:(0,t.toRef)(i,`autoplay`),autoplayInterval:(0,t.toRef)(i,`autoplayInterval`)});return n({changeSlide:u,goToSlide:d}),(e,n)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{class:`vs-carousel`,onMouseenter:n[2]||=(...e)=>(0,t.unref)(m)&&(0,t.unref)(m)(...e),onMouseleave:n[3]||=(...e)=>(0,t.unref)(h)&&(0,t.unref)(h)(...e)},[((0,t.openBlock)(),(0,t.createBlock)((0,t.resolveDynamicComponent)(e.tag),{ref_key:`vsWrapper`,ref:l,class:`vs-carousel__wrapper`},{default:(0,t.withCtx)(()=>[(0,t.renderSlot)(e.$slots,`default`)]),_:3},512)),e.hideArrows?(0,t.createCommentVNode)(``,!0):(0,t.renderSlot)(e.$slots,`arrows`,(0,t.normalizeProps)((0,t.mergeProps)({key:0},{changeSlide:(0,t.unref)(u),isBoundLeft:(0,t.unref)(f),isBoundRight:(0,t.unref)(p)})),()=>[(0,t.withDirectives)((0,t.createElementVNode)(`button`,{type:`button`,"aria-label":e.i18n.slideLeft,disabled:(0,t.unref)(f),class:`vs-carousel__arrows vs-carousel__arrows--left`,onClick:n[0]||=e=>(0,t.unref)(u)(-1)},` ← `,8,s),[[t.vShow,!e.hideArrowsOnBound||!(0,t.unref)(f)]]),(0,t.withDirectives)((0,t.createElementVNode)(`button`,{type:`button`,"aria-label":e.i18n.slideRight,disabled:(0,t.unref)(p),class:`vs-carousel__arrows vs-carousel__arrows--right`,onClick:n[1]||=e=>(0,t.unref)(u)(1)},` → `,8,c),[[t.vShow,!e.hideArrowsOnBound||!(0,t.unref)(p)]])])],32))}}),u=(0,t.defineComponent)({__name:`Slide`,props:{tag:{type:String,default:`li`}},setup(e){return(n,r)=>((0,t.openBlock)(),(0,t.createBlock)((0,t.resolveDynamicComponent)(e.tag),{ref:`vsSlide`,class:`vs-carousel__slide`,tabindex:`0`},{default:(0,t.withCtx)(()=>[(0,t.renderSlot)(n.$slots,`default`)]),_:3},512))}}),d={install:e=>{e.component(`Carousel`,l),e.component(`Slide`,u)}};e.Carousel=l,e.Slide=u,e.VueSnap=d,e.default=d});
package/package.json CHANGED
@@ -1,19 +1,25 @@
1
1
  {
2
2
  "name": "vue-snap",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "description": "Lightweight Carousel based on CSS Scroll Snap",
6
6
  "main": "dist/vue-snap.umd.js",
7
7
  "module": "dist/vue-snap.es.js",
8
8
  "unpkg": "dist/vue-snap.js",
9
+ "types": "dist/entry.d.ts",
10
+ "files": [
11
+ "dist"
12
+ ],
9
13
  "engines": {
10
14
  "node": ">=22"
11
15
  },
12
16
  "exports": {
13
17
  ".": {
18
+ "types": "./dist/entry.d.ts",
14
19
  "import": "./dist/vue-snap.es.js",
15
20
  "require": "./dist/vue-snap.umd.js"
16
21
  },
22
+ "./style.css": "./dist/vue-snap.css",
17
23
  "./dist/vue-snap.css": "./dist/vue-snap.css"
18
24
  },
19
25
  "scripts": {
@@ -50,6 +56,7 @@
50
56
  "sass-embedded": "^1.100.0",
51
57
  "typescript": "5",
52
58
  "vite": "^8.1.4",
59
+ "vite-plugin-dts": "^5.0.3",
53
60
  "vue-tsc": "^3.3.7"
54
61
  }
55
62
  }
@@ -1,44 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(pnpm --version)",
5
- "Bash(pnpm add *)",
6
- "Bash(pnpm remove *)",
7
- "Bash(npx biome *)",
8
- "Bash(curl -s https://biomejs.dev/schemas/2.5.3/schema.json)",
9
- "Bash(python3 -c ' *)",
10
- "Bash(python3 *)",
11
- "Bash(pnpm lint *)",
12
- "Bash(echo \"exit=$?\")",
13
- "Bash(npx vue-tsc *)",
14
- "Bash(pnpm run *)",
15
- "Bash(pnpm install *)",
16
- "Bash(node -e \"console.log\\(require.resolve\\('vue-snap/package.json'\\)\\)\")",
17
- "Bash(node -e ' *)",
18
- "Bash(bun --version)",
19
- "Bash(bun add *)",
20
- "Bash(bun run *)",
21
- "Bash(gh pr *)",
22
- "Bash(git fetch *)",
23
- "Bash(git rev-list *)",
24
- "Bash(bunx vue-tsc *)",
25
- "Bash(open *)",
26
- "Bash(bun x *)",
27
- "Bash(git add *)",
28
- "Bash(git commit -m ' *)",
29
- "Bash(git branch *)",
30
- "Bash(git checkout *)",
31
- "Bash(git reset *)",
32
- "Bash(git -C /Users/bartek/Sites/vue-snap log --oneline -5 -- index.html)",
33
- "Bash(curl -sI http://localhost:8123/index.html)",
34
- "Bash(curl -sI http://localhost:8123/dist/vue-snap.js)",
35
- "Bash(pkill -f \"http-server -p 8123\")",
36
- "Bash(git -C /Users/bartek/Sites/vue-snap status)",
37
- "Bash(curl -s http://localhost:5173/)",
38
- "Skill(run)",
39
- "Bash(command -v chromium-cli)",
40
- "Bash(bunx --help)",
41
- "Bash(pkill -f \"vite\")"
42
- ]
43
- }
44
- }