scroll-slides 0.1.2 → 0.2.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.
@@ -10,17 +10,21 @@ declare const itemStates: {
10
10
  declare const isVertical: import("vue").ComputedRef<boolean>;
11
11
  declare const transformProperty: import("vue").ComputedRef<"translateY" | "translateX">;
12
12
  declare const itemIndices: import("vue").ComputedRef<number[]>;
13
- declare const spacerSize: import("vue").ComputedRef<number>;
13
+ declare const spacerSize: import("vue").Ref<number, number>;
14
14
  declare const __VLS_ctx: InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>;
15
- declare var __VLS_2: `item-${number}`, __VLS_3: {
15
+ declare var __VLS_1: {
16
+ size: number;
17
+ }, __VLS_4: `item-${number}`, __VLS_5: {
16
18
  index: number;
17
- }, __VLS_5: {
19
+ }, __VLS_7: {
18
20
  index: number;
19
21
  };
20
22
  type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.$slots> & {
21
- [K in NonNullable<typeof __VLS_2>]?: (props: typeof __VLS_3) => any;
23
+ [K in NonNullable<typeof __VLS_4>]?: (props: typeof __VLS_5) => any;
22
24
  } & {
23
- item?: (props: typeof __VLS_5) => any;
25
+ spacer?: (props: typeof __VLS_1) => any;
26
+ } & {
27
+ item?: (props: typeof __VLS_7) => any;
24
28
  }>;
25
29
  declare const __VLS_self: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
26
30
  direction: {
@@ -1 +1 @@
1
- .slider[data-v-68d7cf0e]{position:relative;width:100%;height:100%;overflow-y:auto;overflow-x:hidden;box-sizing:border-box}.slider.horizontal[data-v-68d7cf0e]{overflow-x:auto;overflow-y:hidden;white-space:nowrap}.slider-item[data-v-68d7cf0e]{position:relative}.slider-item .slider-slot[data-v-68d7cf0e]{position:relative;transition:transform .04s}.horizontal .slider-item[data-v-68d7cf0e]{display:inline-block;vertical-align:middle;transform-origin:center right}.slider-spacer[data-v-68d7cf0e]{pointer-events:none}
1
+ .slider[data-v-2ecb83b3]{position:relative;width:100%;height:100%;overflow-y:auto;overflow-x:hidden;box-sizing:border-box}.slider.horizontal[data-v-2ecb83b3]{display:flex;align-items:center;overflow-x:auto;overflow-y:hidden;white-space:nowrap}.slider-item[data-v-2ecb83b3]{position:relative}.slider-item .slider-slot[data-v-2ecb83b3]{position:relative;transition:transform .04s}.horizontal .slider-item[data-v-2ecb83b3]{display:inline-block;vertical-align:middle;transform-origin:center right}.slider-spacer[data-v-2ecb83b3]{width:100%;height:100%;pointer-events:none}
@@ -1,5 +1,5 @@
1
- import { defineComponent as A, toRefs as F, ref as R, reactive as H, computed as h, watch as b, onMounted as V, onUnmounted as W, createElementBlock as y, openBlock as g, normalizeClass as O, createCommentVNode as T, unref as j, normalizeStyle as z, Fragment as q, renderList as U, createElementVNode as X, renderSlot as P } from "vue";
2
- const Y = /* @__PURE__ */ A({
1
+ import { defineComponent as U, toRefs as j, ref as _, reactive as q, computed as b, watch as L, onMounted as X, onUnmounted as Y, nextTick as D, createElementBlock as h, openBlock as y, normalizeClass as G, createCommentVNode as J, unref as K, normalizeStyle as P, renderSlot as R, Fragment as Q, renderList as Z, createElementVNode as ee } from "vue";
2
+ const te = /* @__PURE__ */ U({
3
3
  __name: "ScrollSlide",
4
4
  props: {
5
5
  direction: {
@@ -31,99 +31,117 @@ const Y = /* @__PURE__ */ A({
31
31
  },
32
32
  setup(c) {
33
33
  const n = c, {
34
- spacerEnabled: v
35
- } = F(n), t = R(null), u = R([]), r = H({}), o = h(() => n.direction === "vertical"), $ = h(() => o.value ? "translateY" : "translateX"), k = (e, a) => Math.min(Math.max(e / a, 0), 1), M = (e) => e * e * (3 - 2 * e), S = h(() => Array.from({ length: n.itemCount }, (e, a) => a)), s = () => {
36
- if (!t.value) return;
37
- const e = t.value, a = e[o.value ? "clientHeight" : "clientWidth"];
38
- u.value.forEach((l, i) => {
39
- const m = l.getBoundingClientRect(), f = o.value ? m.top : m.left, w = e.getBoundingClientRect(), L = f - (o.value ? w.top : w.left), N = Math.min(
40
- Math.max(0, (a - L) / a),
34
+ direction: m,
35
+ itemCount: g,
36
+ scaleRatio: S,
37
+ scaleStartPercent: N,
38
+ translateFactor: B,
39
+ spacerEnabled: w
40
+ } = j(n), a = _(null), d = _([]), r = q({}), o = b(() => n.direction === "vertical"), I = b(() => o.value ? "translateY" : "translateX"), F = (e, t) => Math.min(Math.max(e / t, 0), 1), x = (e) => e * e * (3 - 2 * e), z = b(() => Array.from({ length: n.itemCount }, (e, t) => t)), s = () => {
41
+ A(), k();
42
+ }, A = () => {
43
+ if (!a.value) return;
44
+ const e = a.value, t = e[o.value ? "clientHeight" : "clientWidth"];
45
+ d.value.forEach((l, i) => {
46
+ const v = l.getBoundingClientRect(), f = o.value ? v.top : v.left, M = e.getBoundingClientRect(), H = f - (o.value ? M.top : M.left), T = Math.min(
47
+ Math.max(0, (t - H) / t),
41
48
  1
42
- ), B = k(1 - N - n.scaleStartPercent, 1 - n.scaleStartPercent), _ = M(B), I = 1 + (n.scaleRatio - 1) * _, x = _ * n.translateFactor;
49
+ ), V = F(1 - T - n.scaleStartPercent, 1 - n.scaleStartPercent), C = x(V), W = 1 + (n.scaleRatio - 1) * C, O = C * n.translateFactor;
43
50
  let p;
44
- const E = Math.min(Math.max(_ || 0, 0), 1);
51
+ const E = Math.min(Math.max(C || 0, 0), 1);
45
52
  E > 0.6 ? p = 0 : E < 0.4 ? p = 1 : p = (0.6 - E) / 0.2, r[i] = {
46
- scale: I,
47
- translate: x,
53
+ scale: W,
54
+ translate: O,
48
55
  opacity: p
49
56
  };
50
57
  });
51
- }, C = () => {
52
- t.value && (u.value = Array.from(t.value.querySelectorAll(".slider-item")), S.value.forEach((e) => {
58
+ }, $ = () => {
59
+ a.value && (d.value = Array.from(a.value.querySelectorAll(".slider-item")), z.value.forEach((e) => {
53
60
  r[e] || (r[e] = {
54
61
  scale: 1,
55
62
  translate: 0,
56
63
  opacity: 1
57
64
  });
58
65
  }), Object.keys(r).forEach((e) => {
59
- const a = Number(e);
60
- a >= n.itemCount && delete r[a];
66
+ const t = Number(e);
67
+ t >= n.itemCount && delete r[t];
61
68
  }), s());
62
69
  };
63
- b(() => n.itemCount, (e, a) => {
70
+ L(() => n.itemCount, (e, t) => {
64
71
  setTimeout(() => {
65
- C();
72
+ $();
66
73
  }, 0);
67
74
  }, { immediate: !1 });
68
- const d = h(() => {
69
- if (!t.value) return 0;
70
- const e = t.value[o.value ? "clientHeight" : "clientWidth"];
71
- let a = 0;
72
- if (u.value.length > 0) {
73
- const l = u.value[0];
75
+ const u = _(0), k = () => {
76
+ if (!a.value) return 0;
77
+ const e = a.value[o.value ? "clientHeight" : "clientWidth"];
78
+ let t = 0;
79
+ if (d.value.length > 0) {
80
+ const l = d.value[0];
74
81
  if (l) {
75
82
  const i = l.getBoundingClientRect();
76
- a = o.value ? i.height : i.width;
83
+ t = o.value ? i.height : i.width;
77
84
  }
78
85
  }
79
- return Math.max(0, e - a);
80
- });
81
- return V(() => {
82
- t.value && (t.value.addEventListener("scroll", s), window.addEventListener("resize", s), t.value.addEventListener("touchmove", s, { passive: !0 }), C());
83
- }), W(() => {
84
- t.value && (t.value.removeEventListener("scroll", s), t.value.removeEventListener("touchmove", s)), window.removeEventListener("resize", s);
85
- }), b(v, () => {
86
- s();
87
- }), (e, a) => (g(), y("div", {
88
- class: O(["slider", { horizontal: !o.value }]),
86
+ u.value = Math.max(0, e - t);
87
+ };
88
+ return k(), X(() => {
89
+ a.value && (a.value.addEventListener("scroll", s), window.addEventListener("resize", s), a.value.addEventListener("touchmove", s, { passive: !0 }), $());
90
+ }), Y(() => {
91
+ a.value && (a.value.removeEventListener("scroll", s), a.value.removeEventListener("touchmove", s)), window.removeEventListener("resize", s);
92
+ }), L([
93
+ m,
94
+ g,
95
+ S,
96
+ N,
97
+ B,
98
+ w
99
+ ], () => {
100
+ console.log("Props changed, reinitializing items"), D(() => {
101
+ s();
102
+ });
103
+ }), (e, t) => (y(), h("div", {
104
+ class: G(["slider", { horizontal: !o.value }]),
89
105
  ref_key: "sliderRef",
90
- ref: t
106
+ ref: a
91
107
  }, [
92
- j(v) ? (g(), y("div", {
108
+ K(w) ? (y(), h("div", {
93
109
  key: 0,
94
110
  class: "slider-spacer",
95
- style: z(o.value ? { height: `${d.value}px`, minHeight: `${d.value}px` } : { width: `${d.value}px`, minWidth: `${d.value}px`, display: "inline-block" })
96
- }, null, 4)) : T("", !0),
97
- (g(!0), y(q, null, U(S.value, (l) => {
98
- var i, m, f;
99
- return g(), y("div", {
111
+ style: P(o.value ? { height: `${u.value}px`, minHeight: `${u.value}px` } : { width: `${u.value}px`, minWidth: `${u.value}px`, display: "inline-block" })
112
+ }, [
113
+ R(e.$slots, "spacer", { size: u.value }, void 0, !0)
114
+ ], 4)) : J("", !0),
115
+ (y(!0), h(Q, null, Z(z.value, (l) => {
116
+ var i, v, f;
117
+ return y(), h("div", {
100
118
  key: l,
101
119
  class: "slider-item",
102
- style: z({
103
- zIndex: S.value.length - l
120
+ style: P({
121
+ zIndex: z.value.length - l
104
122
  })
105
123
  }, [
106
- X("div", {
124
+ ee("div", {
107
125
  class: "slider-slot",
108
- style: z({
109
- transform: `${$.value}(${-((i = r[l]) == null ? void 0 : i.translate) || 0}%) scale(${((m = r[l]) == null ? void 0 : m.scale) || 1})`,
126
+ style: P({
127
+ transform: `${I.value}(${-((i = r[l]) == null ? void 0 : i.translate) || 0}%) scale(${((v = r[l]) == null ? void 0 : v.scale) || 1})`,
110
128
  opacity: (f = r[l]) == null ? void 0 : f.opacity
111
129
  })
112
130
  }, [
113
- P(e.$slots, `item-${l}`, { index: l }, () => [
114
- P(e.$slots, "item", { index: l }, void 0, !0)
131
+ R(e.$slots, `item-${l}`, { index: l }, () => [
132
+ R(e.$slots, "item", { index: l }, void 0, !0)
115
133
  ], !0)
116
134
  ], 4)
117
135
  ], 4);
118
136
  }), 128))
119
137
  ], 2));
120
138
  }
121
- }), D = (c, n) => {
122
- const v = c.__vccOpts || c;
123
- for (const [t, u] of n)
124
- v[t] = u;
125
- return v;
126
- }, J = /* @__PURE__ */ D(Y, [["__scopeId", "data-v-68d7cf0e"]]);
139
+ }), ae = (c, n) => {
140
+ const m = c.__vccOpts || c;
141
+ for (const [g, S] of n)
142
+ m[g] = S;
143
+ return m;
144
+ }, ne = /* @__PURE__ */ ae(te, [["__scopeId", "data-v-2ecb83b3"]]);
127
145
  export {
128
- J as ScrollSlide
146
+ ne as ScrollSlide
129
147
  };
@@ -1 +1 @@
1
- (function(s,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(s=typeof globalThis<"u"?globalThis:s||self,e(s.ScrollSlide={},s.Vue))})(this,function(s,e){"use strict";const z=((m,a)=>{const f=m.__vccOpts||m;for(const[l,u]of a)f[l]=u;return f})(e.defineComponent({__name:"ScrollSlide",props:{direction:{type:String,default:"vertical",validator:m=>["vertical","horizontal"].includes(m)},itemCount:{type:Number,default:0},scaleRatio:{type:Number,default:.7},scaleStartPercent:{type:Number,default:.8},translateFactor:{type:Number,default:100},spacerEnabled:{type:Boolean,default:!1}},setup(m){const a=m,{spacerEnabled:f}=e.toRefs(a),l=e.ref(null),u=e.ref([]),r=e.reactive({}),i=e.computed(()=>a.direction==="vertical"),b=e.computed(()=>i.value?"translateY":"translateX"),w=(t,n)=>Math.min(Math.max(t/n,0),1),B=t=>t*t*(3-2*t),S=e.computed(()=>Array.from({length:a.itemCount},(t,n)=>n)),c=()=>{if(!l.value)return;const t=l.value,n=t[i.value?"clientHeight":"clientWidth"];u.value.forEach((o,d)=>{const p=o.getBoundingClientRect(),v=i.value?p.top:p.left,k=t.getBoundingClientRect(),C=v-(i.value?k.top:k.left),P=Math.min(Math.max(0,(n-C)/n),1),R=w(1-P-a.scaleStartPercent,1-a.scaleStartPercent),g=B(R),$=1+(a.scaleRatio-1)*g,M=g*a.translateFactor;let y;const _=Math.min(Math.max(g||0,0),1);_>.6?y=0:_<.4?y=1:y=(.6-_)/.2,r[d]={scale:$,translate:M,opacity:y}})},E=()=>{l.value&&(u.value=Array.from(l.value.querySelectorAll(".slider-item")),S.value.forEach(t=>{r[t]||(r[t]={scale:1,translate:0,opacity:1})}),Object.keys(r).forEach(t=>{const n=Number(t);n>=a.itemCount&&delete r[n]}),c())};e.watch(()=>a.itemCount,(t,n)=>{setTimeout(()=>{E()},0)},{immediate:!1});const h=e.computed(()=>{if(!l.value)return 0;const t=l.value[i.value?"clientHeight":"clientWidth"];let n=0;if(u.value.length>0){const o=u.value[0];if(o){const d=o.getBoundingClientRect();n=i.value?d.height:d.width}}return Math.max(0,t-n)});return e.onMounted(()=>{l.value&&(l.value.addEventListener("scroll",c),window.addEventListener("resize",c),l.value.addEventListener("touchmove",c,{passive:!0}),E())}),e.onUnmounted(()=>{l.value&&(l.value.removeEventListener("scroll",c),l.value.removeEventListener("touchmove",c)),window.removeEventListener("resize",c)}),e.watch(f,()=>{c()}),(t,n)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["slider",{horizontal:!i.value}]),ref_key:"sliderRef",ref:l},[e.unref(f)?(e.openBlock(),e.createElementBlock("div",{key:0,class:"slider-spacer",style:e.normalizeStyle(i.value?{height:`${h.value}px`,minHeight:`${h.value}px`}:{width:`${h.value}px`,minWidth:`${h.value}px`,display:"inline-block"})},null,4)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(S.value,o=>{var d,p,v;return e.openBlock(),e.createElementBlock("div",{key:o,class:"slider-item",style:e.normalizeStyle({zIndex:S.value.length-o})},[e.createElementVNode("div",{class:"slider-slot",style:e.normalizeStyle({transform:`${b.value}(${-((d=r[o])==null?void 0:d.translate)||0}%) scale(${((p=r[o])==null?void 0:p.scale)||1})`,opacity:(v=r[o])==null?void 0:v.opacity})},[e.renderSlot(t.$slots,`item-${o}`,{index:o},()=>[e.renderSlot(t.$slots,"item",{index:o},void 0,!0)],!0)],4)],4)}),128))],2))}}),[["__scopeId","data-v-68d7cf0e"]]);s.ScrollSlide=z,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(c,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(c=typeof globalThis<"u"?globalThis:c||self,e(c.ScrollSlide={},c.Vue))})(this,function(c,e){"use strict";const w=((m,o)=>{const p=m.__vccOpts||m;for(const[S,g]of o)p[S]=g;return p})(e.defineComponent({__name:"ScrollSlide",props:{direction:{type:String,default:"vertical",validator:m=>["vertical","horizontal"].includes(m)},itemCount:{type:Number,default:0},scaleRatio:{type:Number,default:.7},scaleStartPercent:{type:Number,default:.8},translateFactor:{type:Number,default:100},spacerEnabled:{type:Boolean,default:!1}},setup(m){const o=m,{direction:p,itemCount:S,scaleRatio:g,scaleStartPercent:B,translateFactor:R,spacerEnabled:k}=e.toRefs(o),l=e.ref(null),h=e.ref([]),r=e.reactive({}),i=e.computed(()=>o.direction==="vertical"),$=e.computed(()=>i.value?"translateY":"translateX"),M=(t,n)=>Math.min(Math.max(t/n,0),1),L=t=>t*t*(3-2*t),z=e.computed(()=>Array.from({length:o.itemCount},(t,n)=>n)),s=()=>{N(),C()},N=()=>{if(!l.value)return;const t=l.value,n=t[i.value?"clientHeight":"clientWidth"];h.value.forEach((a,d)=>{const f=a.getBoundingClientRect(),v=i.value?f.top:f.left,P=t.getBoundingClientRect(),I=v-(i.value?P.top:P.left),T=Math.min(Math.max(0,(n-I)/n),1),x=M(1-T-o.scaleStartPercent,1-o.scaleStartPercent),_=L(x),F=1+(o.scaleRatio-1)*_,V=_*o.translateFactor;let y;const E=Math.min(Math.max(_||0,0),1);E>.6?y=0:E<.4?y=1:y=(.6-E)/.2,r[d]={scale:F,translate:V,opacity:y}})},b=()=>{l.value&&(h.value=Array.from(l.value.querySelectorAll(".slider-item")),z.value.forEach(t=>{r[t]||(r[t]={scale:1,translate:0,opacity:1})}),Object.keys(r).forEach(t=>{const n=Number(t);n>=o.itemCount&&delete r[n]}),s())};e.watch(()=>o.itemCount,(t,n)=>{setTimeout(()=>{b()},0)},{immediate:!1});const u=e.ref(0),C=()=>{if(!l.value)return 0;const t=l.value[i.value?"clientHeight":"clientWidth"];let n=0;if(h.value.length>0){const a=h.value[0];if(a){const d=a.getBoundingClientRect();n=i.value?d.height:d.width}}u.value=Math.max(0,t-n)};return C(),e.onMounted(()=>{l.value&&(l.value.addEventListener("scroll",s),window.addEventListener("resize",s),l.value.addEventListener("touchmove",s,{passive:!0}),b())}),e.onUnmounted(()=>{l.value&&(l.value.removeEventListener("scroll",s),l.value.removeEventListener("touchmove",s)),window.removeEventListener("resize",s)}),e.watch([p,S,g,B,R,k],()=>{console.log("Props changed, reinitializing items"),e.nextTick(()=>{s()})}),(t,n)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["slider",{horizontal:!i.value}]),ref_key:"sliderRef",ref:l},[e.unref(k)?(e.openBlock(),e.createElementBlock("div",{key:0,class:"slider-spacer",style:e.normalizeStyle(i.value?{height:`${u.value}px`,minHeight:`${u.value}px`}:{width:`${u.value}px`,minWidth:`${u.value}px`,display:"inline-block"})},[e.renderSlot(t.$slots,"spacer",{size:u.value},void 0,!0)],4)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(z.value,a=>{var d,f,v;return e.openBlock(),e.createElementBlock("div",{key:a,class:"slider-item",style:e.normalizeStyle({zIndex:z.value.length-a})},[e.createElementVNode("div",{class:"slider-slot",style:e.normalizeStyle({transform:`${$.value}(${-((d=r[a])==null?void 0:d.translate)||0}%) scale(${((f=r[a])==null?void 0:f.scale)||1})`,opacity:(v=r[a])==null?void 0:v.opacity})},[e.renderSlot(t.$slots,`item-${a}`,{index:a},()=>[e.renderSlot(t.$slots,"item",{index:a},void 0,!0)],!0)],4)],4)}),128))],2))}}),[["__scopeId","data-v-2ecb83b3"]]);c.ScrollSlide=w,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scroll-slides",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -17,6 +17,7 @@
17
17
  "scripts": {
18
18
  "dev": "vite",
19
19
  "build": "vite build && vue-tsc --emitDeclarationOnly --project tsconfig.app.json",
20
+ "build:demo": "vite build --config vite.demo.config.ts",
20
21
  "types": "vue-tsc --declaration --emitDeclarationOnly --project tsconfig.app.json",
21
22
  "preview": "vite preview"
22
23
  },