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").
|
|
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
|
|
15
|
+
declare var __VLS_1: {
|
|
16
|
+
size: number;
|
|
17
|
+
}, __VLS_4: `item-${number}`, __VLS_5: {
|
|
16
18
|
index: number;
|
|
17
|
-
},
|
|
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
|
|
23
|
+
[K in NonNullable<typeof __VLS_4>]?: (props: typeof __VLS_5) => any;
|
|
22
24
|
} & {
|
|
23
|
-
|
|
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: {
|
package/dist/scroll-slides.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.slider[data-v-
|
|
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}
|
package/dist/scroll-slides.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
const
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
),
|
|
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(
|
|
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:
|
|
47
|
-
translate:
|
|
53
|
+
scale: W,
|
|
54
|
+
translate: O,
|
|
48
55
|
opacity: p
|
|
49
56
|
};
|
|
50
57
|
});
|
|
51
|
-
},
|
|
52
|
-
|
|
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
|
|
60
|
-
|
|
66
|
+
const t = Number(e);
|
|
67
|
+
t >= n.itemCount && delete r[t];
|
|
61
68
|
}), s());
|
|
62
69
|
};
|
|
63
|
-
|
|
70
|
+
L(() => n.itemCount, (e, t) => {
|
|
64
71
|
setTimeout(() => {
|
|
65
|
-
|
|
72
|
+
$();
|
|
66
73
|
}, 0);
|
|
67
74
|
}, { immediate: !1 });
|
|
68
|
-
const
|
|
69
|
-
if (!
|
|
70
|
-
const e =
|
|
71
|
-
let
|
|
72
|
-
if (
|
|
73
|
-
const l =
|
|
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
|
-
|
|
83
|
+
t = o.value ? i.height : i.width;
|
|
77
84
|
}
|
|
78
85
|
}
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
}),
|
|
84
|
-
|
|
85
|
-
}),
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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:
|
|
106
|
+
ref: a
|
|
91
107
|
}, [
|
|
92
|
-
|
|
108
|
+
K(w) ? (y(), h("div", {
|
|
93
109
|
key: 0,
|
|
94
110
|
class: "slider-spacer",
|
|
95
|
-
style:
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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:
|
|
103
|
-
zIndex:
|
|
120
|
+
style: P({
|
|
121
|
+
zIndex: z.value.length - l
|
|
104
122
|
})
|
|
105
123
|
}, [
|
|
106
|
-
|
|
124
|
+
ee("div", {
|
|
107
125
|
class: "slider-slot",
|
|
108
|
-
style:
|
|
109
|
-
transform: `${
|
|
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
|
-
|
|
114
|
-
|
|
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
|
-
}),
|
|
122
|
-
const
|
|
123
|
-
for (const [
|
|
124
|
-
|
|
125
|
-
return
|
|
126
|
-
},
|
|
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
|
-
|
|
146
|
+
ne as ScrollSlide
|
|
129
147
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
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.
|
|
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
|
},
|