scroll-slides 0.1.0 → 0.1.2
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 +10 -1
- package/dist/components/ScrollSlide.vue.d.ts +2 -18
- package/dist/scroll-slides.css +1 -1
- package/dist/scroll-slides.js +57 -58
- package/dist/scroll-slides.umd.cjs +1 -1
- package/package.json +33 -27
package/README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
declare const spacerEnabled: import("vue").Ref<boolean, boolean>;
|
|
1
2
|
declare const sliderRef: import("vue").Ref<HTMLElement | null, HTMLElement | null>;
|
|
2
3
|
declare const itemStates: {
|
|
3
4
|
[key: number]: {
|
|
@@ -43,15 +44,12 @@ declare const __VLS_self: import("vue").DefineComponent<import("vue").ExtractPro
|
|
|
43
44
|
type: NumberConstructor;
|
|
44
45
|
default: number;
|
|
45
46
|
};
|
|
46
|
-
allowScrollToFirst: {
|
|
47
|
-
type: BooleanConstructor;
|
|
48
|
-
default: boolean;
|
|
49
|
-
};
|
|
50
47
|
spacerEnabled: {
|
|
51
48
|
type: BooleanConstructor;
|
|
52
49
|
default: boolean;
|
|
53
50
|
};
|
|
54
51
|
}>, {
|
|
52
|
+
spacerEnabled: typeof spacerEnabled;
|
|
55
53
|
sliderRef: typeof sliderRef;
|
|
56
54
|
itemStates: typeof itemStates;
|
|
57
55
|
isVertical: typeof isVertical;
|
|
@@ -80,10 +78,6 @@ declare const __VLS_self: import("vue").DefineComponent<import("vue").ExtractPro
|
|
|
80
78
|
type: NumberConstructor;
|
|
81
79
|
default: number;
|
|
82
80
|
};
|
|
83
|
-
allowScrollToFirst: {
|
|
84
|
-
type: BooleanConstructor;
|
|
85
|
-
default: boolean;
|
|
86
|
-
};
|
|
87
81
|
spacerEnabled: {
|
|
88
82
|
type: BooleanConstructor;
|
|
89
83
|
default: boolean;
|
|
@@ -94,7 +88,6 @@ declare const __VLS_self: import("vue").DefineComponent<import("vue").ExtractPro
|
|
|
94
88
|
scaleRatio: number;
|
|
95
89
|
scaleStartPercent: number;
|
|
96
90
|
translateFactor: number;
|
|
97
|
-
allowScrollToFirst: boolean;
|
|
98
91
|
spacerEnabled: boolean;
|
|
99
92
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
100
93
|
declare const __VLS_component: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
@@ -119,10 +112,6 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
119
112
|
type: NumberConstructor;
|
|
120
113
|
default: number;
|
|
121
114
|
};
|
|
122
|
-
allowScrollToFirst: {
|
|
123
|
-
type: BooleanConstructor;
|
|
124
|
-
default: boolean;
|
|
125
|
-
};
|
|
126
115
|
spacerEnabled: {
|
|
127
116
|
type: BooleanConstructor;
|
|
128
117
|
default: boolean;
|
|
@@ -149,10 +138,6 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
149
138
|
type: NumberConstructor;
|
|
150
139
|
default: number;
|
|
151
140
|
};
|
|
152
|
-
allowScrollToFirst: {
|
|
153
|
-
type: BooleanConstructor;
|
|
154
|
-
default: boolean;
|
|
155
|
-
};
|
|
156
141
|
spacerEnabled: {
|
|
157
142
|
type: BooleanConstructor;
|
|
158
143
|
default: boolean;
|
|
@@ -163,7 +148,6 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
163
148
|
scaleRatio: number;
|
|
164
149
|
scaleStartPercent: number;
|
|
165
150
|
translateFactor: number;
|
|
166
|
-
allowScrollToFirst: boolean;
|
|
167
151
|
spacerEnabled: boolean;
|
|
168
152
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
169
153
|
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
package/dist/scroll-slides.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.slider[data-v-
|
|
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}
|
package/dist/scroll-slides.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
const
|
|
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({
|
|
3
3
|
__name: "ScrollSlide",
|
|
4
4
|
props: {
|
|
5
5
|
direction: {
|
|
6
6
|
type: String,
|
|
7
7
|
default: "vertical",
|
|
8
8
|
// 'vertical' or 'horizontal'
|
|
9
|
-
validator: (
|
|
9
|
+
validator: (c) => ["vertical", "horizontal"].includes(c)
|
|
10
10
|
},
|
|
11
11
|
itemCount: {
|
|
12
12
|
type: Number,
|
|
@@ -24,107 +24,106 @@ const q = /* @__PURE__ */ I({
|
|
|
24
24
|
type: Number,
|
|
25
25
|
default: 100
|
|
26
26
|
},
|
|
27
|
-
allowScrollToFirst: {
|
|
28
|
-
type: Boolean,
|
|
29
|
-
default: !1
|
|
30
|
-
},
|
|
31
|
-
// Updating prop name to be clearer
|
|
32
27
|
spacerEnabled: {
|
|
33
28
|
type: Boolean,
|
|
34
29
|
default: !1
|
|
35
30
|
}
|
|
36
31
|
},
|
|
37
|
-
setup(
|
|
38
|
-
const
|
|
32
|
+
setup(c) {
|
|
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 = () => {
|
|
39
36
|
if (!t.value) return;
|
|
40
37
|
const e = t.value, a = e[o.value ? "clientHeight" : "clientWidth"];
|
|
41
|
-
u.value.forEach((l,
|
|
42
|
-
const
|
|
43
|
-
Math.max(0, (a -
|
|
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),
|
|
44
41
|
1
|
|
45
|
-
), B =
|
|
46
|
-
let
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
scale:
|
|
50
|
-
translate:
|
|
51
|
-
opacity:
|
|
42
|
+
), B = k(1 - N - n.scaleStartPercent, 1 - n.scaleStartPercent), _ = M(B), I = 1 + (n.scaleRatio - 1) * _, x = _ * n.translateFactor;
|
|
43
|
+
let p;
|
|
44
|
+
const E = Math.min(Math.max(_ || 0, 0), 1);
|
|
45
|
+
E > 0.6 ? p = 0 : E < 0.4 ? p = 1 : p = (0.6 - E) / 0.2, r[i] = {
|
|
46
|
+
scale: I,
|
|
47
|
+
translate: x,
|
|
48
|
+
opacity: p
|
|
52
49
|
};
|
|
53
50
|
});
|
|
54
|
-
},
|
|
55
|
-
t.value && (u.value = Array.from(t.value.querySelectorAll(".slider-item")),
|
|
56
|
-
|
|
51
|
+
}, C = () => {
|
|
52
|
+
t.value && (u.value = Array.from(t.value.querySelectorAll(".slider-item")), S.value.forEach((e) => {
|
|
53
|
+
r[e] || (r[e] = {
|
|
57
54
|
scale: 1,
|
|
58
55
|
translate: 0,
|
|
59
56
|
opacity: 1
|
|
60
57
|
});
|
|
61
|
-
}), Object.keys(
|
|
58
|
+
}), Object.keys(r).forEach((e) => {
|
|
62
59
|
const a = Number(e);
|
|
63
|
-
a >=
|
|
64
|
-
}),
|
|
60
|
+
a >= n.itemCount && delete r[a];
|
|
61
|
+
}), s());
|
|
65
62
|
};
|
|
66
|
-
|
|
63
|
+
b(() => n.itemCount, (e, a) => {
|
|
67
64
|
setTimeout(() => {
|
|
68
|
-
|
|
65
|
+
C();
|
|
69
66
|
}, 0);
|
|
70
67
|
}, { immediate: !1 });
|
|
71
|
-
const
|
|
68
|
+
const d = h(() => {
|
|
72
69
|
if (!t.value) return 0;
|
|
73
70
|
const e = t.value[o.value ? "clientHeight" : "clientWidth"];
|
|
74
71
|
let a = 0;
|
|
75
72
|
if (u.value.length > 0) {
|
|
76
73
|
const l = u.value[0];
|
|
77
74
|
if (l) {
|
|
78
|
-
const
|
|
79
|
-
a = o.value ?
|
|
75
|
+
const i = l.getBoundingClientRect();
|
|
76
|
+
a = o.value ? i.height : i.width;
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
79
|
return Math.max(0, e - a);
|
|
83
80
|
});
|
|
84
|
-
return
|
|
85
|
-
t.value && (t.value.addEventListener("scroll",
|
|
86
|
-
}),
|
|
87
|
-
t.value && (t.value.removeEventListener("scroll",
|
|
88
|
-
}), (
|
|
89
|
-
|
|
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 }]),
|
|
90
89
|
ref_key: "sliderRef",
|
|
91
90
|
ref: t
|
|
92
91
|
}, [
|
|
93
|
-
|
|
92
|
+
j(v) ? (g(), y("div", {
|
|
94
93
|
key: 0,
|
|
95
94
|
class: "slider-spacer",
|
|
96
|
-
style:
|
|
97
|
-
}, null, 4)) :
|
|
98
|
-
(
|
|
99
|
-
var
|
|
100
|
-
return
|
|
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", {
|
|
101
100
|
key: l,
|
|
102
101
|
class: "slider-item",
|
|
103
|
-
style:
|
|
104
|
-
zIndex:
|
|
102
|
+
style: z({
|
|
103
|
+
zIndex: S.value.length - l
|
|
105
104
|
})
|
|
106
105
|
}, [
|
|
107
|
-
|
|
106
|
+
X("div", {
|
|
108
107
|
class: "slider-slot",
|
|
109
|
-
style:
|
|
110
|
-
transform: `${
|
|
111
|
-
opacity: (
|
|
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})`,
|
|
110
|
+
opacity: (f = r[l]) == null ? void 0 : f.opacity
|
|
112
111
|
})
|
|
113
112
|
}, [
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
P(e.$slots, `item-${l}`, { index: l }, () => [
|
|
114
|
+
P(e.$slots, "item", { index: l }, void 0, !0)
|
|
116
115
|
], !0)
|
|
117
116
|
], 4)
|
|
118
117
|
], 4);
|
|
119
118
|
}), 128))
|
|
120
119
|
], 2));
|
|
121
120
|
}
|
|
122
|
-
}),
|
|
123
|
-
const
|
|
124
|
-
for (const [
|
|
125
|
-
t
|
|
126
|
-
return
|
|
127
|
-
},
|
|
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"]]);
|
|
128
127
|
export {
|
|
129
|
-
|
|
128
|
+
J as ScrollSlide
|
|
130
129
|
};
|
|
@@ -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
|
|
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"})});
|
package/package.json
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "scroll-slides",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"types": "./dist/index.d.ts",
|
|
6
|
-
"files": [
|
|
7
|
-
"dist"
|
|
8
|
-
],
|
|
9
|
-
"main": "./dist/scroll-slides.umd.cjs",
|
|
10
|
-
"module": "./dist/scroll-slides.js",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "scroll-slides",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"main": "./dist/scroll-slides.umd.cjs",
|
|
10
|
+
"module": "./dist/scroll-slides.js",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "agoudbg",
|
|
13
|
+
"email": "agoudbg@gmail.com",
|
|
14
|
+
"url": "https://github.com/agoudbg"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/agoudbg/scroll-slides",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"dev": "vite",
|
|
19
|
+
"build": "vite build && vue-tsc --emitDeclarationOnly --project tsconfig.app.json",
|
|
20
|
+
"types": "vue-tsc --declaration --emitDeclarationOnly --project tsconfig.app.json",
|
|
21
|
+
"preview": "vite preview"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"vue": "^3.5.13"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^22.14.0",
|
|
28
|
+
"@vitejs/plugin-vue": "^5.2.1",
|
|
29
|
+
"@vue/tsconfig": "^0.7.0",
|
|
30
|
+
"typescript": "~5.7.2",
|
|
31
|
+
"vite": "^6.2.0",
|
|
32
|
+
"vue-tsc": "^2.2.4"
|
|
33
|
+
}
|
|
28
34
|
}
|