@v-c/virtual-list 0.0.1
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/LICENSE +21 -0
- package/dist/Filler.cjs +1 -0
- package/dist/Filler.d.ts +33 -0
- package/dist/Filler.js +57 -0
- package/dist/Item.cjs +1 -0
- package/dist/Item.d.ts +18 -0
- package/dist/Item.js +27 -0
- package/dist/List.cjs +1 -0
- package/dist/List.d.ts +108 -0
- package/dist/List.js +276 -0
- package/dist/ScrollBar.cjs +1 -0
- package/dist/ScrollBar.d.ts +116 -0
- package/dist/ScrollBar.js +193 -0
- package/dist/hooks/useDiffItem.cjs +1 -0
- package/dist/hooks/useDiffItem.d.ts +2 -0
- package/dist/hooks/useDiffItem.js +21 -0
- package/dist/hooks/useFrameWheel.cjs +1 -0
- package/dist/hooks/useFrameWheel.d.ts +11 -0
- package/dist/hooks/useFrameWheel.js +52 -0
- package/dist/hooks/useGetSize.cjs +1 -0
- package/dist/hooks/useGetSize.d.ts +7 -0
- package/dist/hooks/useGetSize.js +24 -0
- package/dist/hooks/useHeights.cjs +1 -0
- package/dist/hooks/useHeights.d.ts +9 -0
- package/dist/hooks/useHeights.js +43 -0
- package/dist/hooks/useMobileTouchMove.cjs +1 -0
- package/dist/hooks/useMobileTouchMove.d.ts +2 -0
- package/dist/hooks/useMobileTouchMove.js +44 -0
- package/dist/hooks/useOriginScroll.cjs +1 -0
- package/dist/hooks/useOriginScroll.d.ts +2 -0
- package/dist/hooks/useOriginScroll.js +17 -0
- package/dist/hooks/useScrollDrag.cjs +1 -0
- package/dist/hooks/useScrollDrag.d.ts +3 -0
- package/dist/hooks/useScrollDrag.js +51 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/interface.cjs +1 -0
- package/dist/interface.d.ts +27 -0
- package/dist/interface.js +1 -0
- package/dist/utils/CacheMap.cjs +1 -0
- package/dist/utils/CacheMap.d.ts +16 -0
- package/dist/utils/CacheMap.js +29 -0
- package/dist/utils/isFirefox.cjs +1 -0
- package/dist/utils/isFirefox.d.ts +2 -0
- package/dist/utils/isFirefox.js +4 -0
- package/dist/utils/scrollbarUtil.cjs +1 -0
- package/dist/utils/scrollbarUtil.d.ts +1 -0
- package/dist/utils/scrollbarUtil.js +7 -0
- package/docs/basic.vue +175 -0
- package/docs/height.vue +48 -0
- package/docs/nest.vue +60 -0
- package/docs/no-virtual.vue +127 -0
- package/docs/switch.vue +101 -0
- package/docs/virtual-list.stories.vue +31 -0
- package/package.json +38 -0
- package/src/Filler.tsx +72 -0
- package/src/Item.tsx +34 -0
- package/src/List.tsx +577 -0
- package/src/ScrollBar.tsx +298 -0
- package/src/__tests__/List.test.ts +59 -0
- package/src/hooks/useDiffItem.ts +27 -0
- package/src/hooks/useFrameWheel.ts +141 -0
- package/src/hooks/useGetSize.ts +44 -0
- package/src/hooks/useHeights.ts +106 -0
- package/src/hooks/useMobileTouchMove.ts +131 -0
- package/src/hooks/useOriginScroll.ts +47 -0
- package/src/hooks/useScrollDrag.ts +123 -0
- package/src/index.ts +5 -0
- package/src/interface.ts +32 -0
- package/src/utils/CacheMap.ts +42 -0
- package/src/utils/isFirefox.ts +3 -0
- package/src/utils/scrollbarUtil.ts +10 -0
- package/vite.config.ts +18 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { CSSProperties, PropType } from 'vue';
|
|
2
|
+
export interface ScrollBarProps {
|
|
3
|
+
prefixCls: string;
|
|
4
|
+
scrollOffset: number;
|
|
5
|
+
scrollRange: number;
|
|
6
|
+
rtl: boolean;
|
|
7
|
+
onScroll: (scrollOffset: number, horizontal?: boolean) => void;
|
|
8
|
+
onStartMove: () => void;
|
|
9
|
+
onStopMove: () => void;
|
|
10
|
+
horizontal?: boolean;
|
|
11
|
+
style?: CSSProperties;
|
|
12
|
+
thumbStyle?: CSSProperties;
|
|
13
|
+
spinSize: number;
|
|
14
|
+
containerSize: number;
|
|
15
|
+
showScrollBar?: boolean | 'optional';
|
|
16
|
+
}
|
|
17
|
+
export interface ScrollBarRef {
|
|
18
|
+
delayHidden: () => void;
|
|
19
|
+
}
|
|
20
|
+
declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
21
|
+
prefixCls: {
|
|
22
|
+
type: StringConstructor;
|
|
23
|
+
required: true;
|
|
24
|
+
};
|
|
25
|
+
scrollOffset: {
|
|
26
|
+
type: NumberConstructor;
|
|
27
|
+
required: true;
|
|
28
|
+
};
|
|
29
|
+
scrollRange: {
|
|
30
|
+
type: NumberConstructor;
|
|
31
|
+
required: true;
|
|
32
|
+
};
|
|
33
|
+
rtl: {
|
|
34
|
+
type: BooleanConstructor;
|
|
35
|
+
default: boolean;
|
|
36
|
+
};
|
|
37
|
+
onScroll: {
|
|
38
|
+
type: PropType<(scrollOffset: number, horizontal?: boolean) => void>;
|
|
39
|
+
required: true;
|
|
40
|
+
};
|
|
41
|
+
onStartMove: {
|
|
42
|
+
type: PropType<() => void>;
|
|
43
|
+
required: true;
|
|
44
|
+
};
|
|
45
|
+
onStopMove: {
|
|
46
|
+
type: PropType<() => void>;
|
|
47
|
+
required: true;
|
|
48
|
+
};
|
|
49
|
+
horizontal: {
|
|
50
|
+
type: BooleanConstructor;
|
|
51
|
+
default: boolean;
|
|
52
|
+
};
|
|
53
|
+
style: PropType<CSSProperties>;
|
|
54
|
+
thumbStyle: PropType<CSSProperties>;
|
|
55
|
+
spinSize: {
|
|
56
|
+
type: NumberConstructor;
|
|
57
|
+
required: true;
|
|
58
|
+
};
|
|
59
|
+
containerSize: {
|
|
60
|
+
type: NumberConstructor;
|
|
61
|
+
required: true;
|
|
62
|
+
};
|
|
63
|
+
showScrollBar: {
|
|
64
|
+
type: PropType<boolean | "optional">;
|
|
65
|
+
};
|
|
66
|
+
}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
67
|
+
prefixCls: {
|
|
68
|
+
type: StringConstructor;
|
|
69
|
+
required: true;
|
|
70
|
+
};
|
|
71
|
+
scrollOffset: {
|
|
72
|
+
type: NumberConstructor;
|
|
73
|
+
required: true;
|
|
74
|
+
};
|
|
75
|
+
scrollRange: {
|
|
76
|
+
type: NumberConstructor;
|
|
77
|
+
required: true;
|
|
78
|
+
};
|
|
79
|
+
rtl: {
|
|
80
|
+
type: BooleanConstructor;
|
|
81
|
+
default: boolean;
|
|
82
|
+
};
|
|
83
|
+
onScroll: {
|
|
84
|
+
type: PropType<(scrollOffset: number, horizontal?: boolean) => void>;
|
|
85
|
+
required: true;
|
|
86
|
+
};
|
|
87
|
+
onStartMove: {
|
|
88
|
+
type: PropType<() => void>;
|
|
89
|
+
required: true;
|
|
90
|
+
};
|
|
91
|
+
onStopMove: {
|
|
92
|
+
type: PropType<() => void>;
|
|
93
|
+
required: true;
|
|
94
|
+
};
|
|
95
|
+
horizontal: {
|
|
96
|
+
type: BooleanConstructor;
|
|
97
|
+
default: boolean;
|
|
98
|
+
};
|
|
99
|
+
style: PropType<CSSProperties>;
|
|
100
|
+
thumbStyle: PropType<CSSProperties>;
|
|
101
|
+
spinSize: {
|
|
102
|
+
type: NumberConstructor;
|
|
103
|
+
required: true;
|
|
104
|
+
};
|
|
105
|
+
containerSize: {
|
|
106
|
+
type: NumberConstructor;
|
|
107
|
+
required: true;
|
|
108
|
+
};
|
|
109
|
+
showScrollBar: {
|
|
110
|
+
type: PropType<boolean | "optional">;
|
|
111
|
+
};
|
|
112
|
+
}>> & Readonly<{}>, {
|
|
113
|
+
rtl: boolean;
|
|
114
|
+
horizontal: boolean;
|
|
115
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
116
|
+
export default _default;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { defineComponent as X, ref as f, computed as g, shallowRef as z, watch as E, onMounted as A, onUnmounted as M, createVNode as $ } from "vue";
|
|
2
|
+
function q(e, u) {
|
|
3
|
+
return ("touches" in e ? e.touches[0] : e)[u ? "pageX" : "pageY"] - window[u ? "scrollX" : "scrollY"];
|
|
4
|
+
}
|
|
5
|
+
const k = /* @__PURE__ */ X({
|
|
6
|
+
name: "ScrollBar",
|
|
7
|
+
props: {
|
|
8
|
+
prefixCls: {
|
|
9
|
+
type: String,
|
|
10
|
+
required: !0
|
|
11
|
+
},
|
|
12
|
+
scrollOffset: {
|
|
13
|
+
type: Number,
|
|
14
|
+
required: !0
|
|
15
|
+
},
|
|
16
|
+
scrollRange: {
|
|
17
|
+
type: Number,
|
|
18
|
+
required: !0
|
|
19
|
+
},
|
|
20
|
+
rtl: {
|
|
21
|
+
type: Boolean,
|
|
22
|
+
default: !1
|
|
23
|
+
},
|
|
24
|
+
onScroll: {
|
|
25
|
+
type: Function,
|
|
26
|
+
required: !0
|
|
27
|
+
},
|
|
28
|
+
onStartMove: {
|
|
29
|
+
type: Function,
|
|
30
|
+
required: !0
|
|
31
|
+
},
|
|
32
|
+
onStopMove: {
|
|
33
|
+
type: Function,
|
|
34
|
+
required: !0
|
|
35
|
+
},
|
|
36
|
+
horizontal: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: !1
|
|
39
|
+
},
|
|
40
|
+
style: Object,
|
|
41
|
+
thumbStyle: Object,
|
|
42
|
+
spinSize: {
|
|
43
|
+
type: Number,
|
|
44
|
+
required: !0
|
|
45
|
+
},
|
|
46
|
+
containerSize: {
|
|
47
|
+
type: Number,
|
|
48
|
+
required: !0
|
|
49
|
+
},
|
|
50
|
+
showScrollBar: {
|
|
51
|
+
type: [Boolean, String]
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
setup(e, {
|
|
55
|
+
expose: u
|
|
56
|
+
}) {
|
|
57
|
+
const l = f(!1), c = f(null), v = f(null), h = g(() => !e.rtl), m = z(), R = z(), d = f(e.showScrollBar === "optional" ? !0 : e.showScrollBar);
|
|
58
|
+
let r = null;
|
|
59
|
+
const b = () => {
|
|
60
|
+
e.showScrollBar === !0 || e.showScrollBar === !1 || (r && clearTimeout(r), d.value = !0, r = setTimeout(() => {
|
|
61
|
+
d.value = !1;
|
|
62
|
+
}, 3e3));
|
|
63
|
+
}, w = g(() => e.scrollRange - e.containerSize || 0), T = g(() => e.containerSize - e.spinSize || 0), i = g(() => e.scrollOffset === 0 || w.value === 0 ? 0 : e.scrollOffset / w.value * T.value), S = z({
|
|
64
|
+
top: i.value,
|
|
65
|
+
dragging: l.value,
|
|
66
|
+
pageY: c.value,
|
|
67
|
+
startTop: v.value
|
|
68
|
+
});
|
|
69
|
+
E([i, l, c, v], () => {
|
|
70
|
+
S.value = {
|
|
71
|
+
top: i.value,
|
|
72
|
+
dragging: l.value,
|
|
73
|
+
pageY: c.value,
|
|
74
|
+
startTop: v.value
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
const j = (t) => {
|
|
78
|
+
t.stopPropagation(), t.preventDefault();
|
|
79
|
+
}, p = (t) => {
|
|
80
|
+
l.value = !0, c.value = q(t, e.horizontal || !1), v.value = S.value.top, e.onStartMove(), t.stopPropagation(), t.preventDefault();
|
|
81
|
+
};
|
|
82
|
+
return A(() => {
|
|
83
|
+
const t = (a) => {
|
|
84
|
+
a.preventDefault();
|
|
85
|
+
}, o = m.value, n = R.value;
|
|
86
|
+
o && n && (o.addEventListener("touchstart", t, {
|
|
87
|
+
passive: !1
|
|
88
|
+
}), n.addEventListener("touchstart", p, {
|
|
89
|
+
passive: !1
|
|
90
|
+
}), M(() => {
|
|
91
|
+
o.removeEventListener("touchstart", t), n.removeEventListener("touchstart", p);
|
|
92
|
+
}));
|
|
93
|
+
}), E(l, (t) => {
|
|
94
|
+
if (t) {
|
|
95
|
+
let o = null;
|
|
96
|
+
const n = (Y) => {
|
|
97
|
+
const {
|
|
98
|
+
dragging: C,
|
|
99
|
+
pageY: D,
|
|
100
|
+
startTop: F
|
|
101
|
+
} = S.value;
|
|
102
|
+
o && cancelAnimationFrame(o);
|
|
103
|
+
const L = m.value.getBoundingClientRect(), N = e.containerSize / (e.horizontal ? L.width : L.height);
|
|
104
|
+
if (C) {
|
|
105
|
+
const x = (q(Y, e.horizontal || !1) - (D || 0)) * N;
|
|
106
|
+
let y = F || 0;
|
|
107
|
+
!h.value && e.horizontal ? y -= x : y += x;
|
|
108
|
+
const O = w.value, B = T.value, P = B ? y / B : 0;
|
|
109
|
+
let s = Math.ceil(P * O);
|
|
110
|
+
s = Math.max(s, 0), s = Math.min(s, O), o = requestAnimationFrame(() => {
|
|
111
|
+
e.onScroll(s, e.horizontal);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}, a = () => {
|
|
115
|
+
l.value = !1, e.onStopMove();
|
|
116
|
+
};
|
|
117
|
+
window.addEventListener("mousemove", n, {
|
|
118
|
+
passive: !0
|
|
119
|
+
}), window.addEventListener("touchmove", n, {
|
|
120
|
+
passive: !0
|
|
121
|
+
}), window.addEventListener("mouseup", a, {
|
|
122
|
+
passive: !0
|
|
123
|
+
}), window.addEventListener("touchend", a, {
|
|
124
|
+
passive: !0
|
|
125
|
+
}), M(() => {
|
|
126
|
+
window.removeEventListener("mousemove", n), window.removeEventListener("touchmove", n), window.removeEventListener("mouseup", a), window.removeEventListener("touchend", a), o && cancelAnimationFrame(o);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}), E(() => e.scrollOffset, () => {
|
|
130
|
+
b();
|
|
131
|
+
}), M(() => {
|
|
132
|
+
r && clearTimeout(r);
|
|
133
|
+
}), u({
|
|
134
|
+
delayHidden: b
|
|
135
|
+
}), () => {
|
|
136
|
+
const t = `${e.prefixCls}-scrollbar`, o = {
|
|
137
|
+
position: "absolute",
|
|
138
|
+
visibility: d.value ? void 0 : "hidden"
|
|
139
|
+
}, n = {
|
|
140
|
+
position: "absolute",
|
|
141
|
+
borderRadius: "99px",
|
|
142
|
+
background: "var(--vc-virtual-list-scrollbar-bg, rgba(0, 0, 0, 0.5))",
|
|
143
|
+
cursor: "pointer",
|
|
144
|
+
userSelect: "none"
|
|
145
|
+
};
|
|
146
|
+
return e.horizontal ? (Object.assign(o, {
|
|
147
|
+
height: "8px",
|
|
148
|
+
left: 0,
|
|
149
|
+
right: 0,
|
|
150
|
+
bottom: 0
|
|
151
|
+
}), Object.assign(n, {
|
|
152
|
+
height: "100%",
|
|
153
|
+
width: `${e.spinSize}px`,
|
|
154
|
+
[h.value ? "left" : "right"]: `${i.value}px`
|
|
155
|
+
})) : (Object.assign(o, {
|
|
156
|
+
width: "8px",
|
|
157
|
+
top: 0,
|
|
158
|
+
bottom: 0,
|
|
159
|
+
[h.value ? "right" : "left"]: 0
|
|
160
|
+
}), Object.assign(n, {
|
|
161
|
+
width: "100%",
|
|
162
|
+
height: `${e.spinSize}px`,
|
|
163
|
+
top: `${i.value}px`
|
|
164
|
+
})), $("div", {
|
|
165
|
+
ref: m,
|
|
166
|
+
class: [t, {
|
|
167
|
+
[`${t}-horizontal`]: e.horizontal,
|
|
168
|
+
[`${t}-vertical`]: !e.horizontal,
|
|
169
|
+
[`${t}-visible`]: d.value
|
|
170
|
+
}],
|
|
171
|
+
style: {
|
|
172
|
+
...o,
|
|
173
|
+
...e.style
|
|
174
|
+
},
|
|
175
|
+
onMousedown: j,
|
|
176
|
+
onMousemove: b
|
|
177
|
+
}, [$("div", {
|
|
178
|
+
ref: R,
|
|
179
|
+
class: [`${t}-thumb`, {
|
|
180
|
+
[`${t}-thumb-moving`]: l.value
|
|
181
|
+
}],
|
|
182
|
+
style: {
|
|
183
|
+
...n,
|
|
184
|
+
...e.thumbStyle
|
|
185
|
+
},
|
|
186
|
+
onMousedown: p
|
|
187
|
+
}, null)]);
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
export {
|
|
192
|
+
k as default
|
|
193
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue");function d(i,u){const r=t.ref([]),o=t.ref();return t.watch(i,e=>{const f=r.value;if(e!==f){const s=e.find(n=>{const a=u(n);return!f.some(c=>u(c)===a)});o.value=s,r.value=e}},{immediate:!0}),o}exports.default=d;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ref as u, watch as c } from "vue";
|
|
2
|
+
function v(a, t) {
|
|
3
|
+
const f = u([]), r = u();
|
|
4
|
+
return c(
|
|
5
|
+
a,
|
|
6
|
+
(e) => {
|
|
7
|
+
const o = f.value;
|
|
8
|
+
if (e !== o) {
|
|
9
|
+
const i = e.find((m) => {
|
|
10
|
+
const n = t(m);
|
|
11
|
+
return !o.some((s) => t(s) === n);
|
|
12
|
+
});
|
|
13
|
+
r.value = i, f.value = e;
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{ immediate: !0 }
|
|
17
|
+
), r;
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
v as default
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("vue"),F=require("../utils/isFirefox.cjs"),X=require("./useOriginScroll.cjs");function _(c,h,b,g,x,A,v){const r=i.ref(0);let a=null;const m=i.ref(null),d=i.ref(!1),M=X.default(h,b,g,x);function S(e,l){if(a&&cancelAnimationFrame(a),M(!1,l))return;const t=e;if(!t._virtualHandled)t._virtualHandled=!0;else return;r.value+=l,m.value=l,F.default||t.preventDefault(),a=requestAnimationFrame(()=>{const o=d.value?10:1;v(r.value*o,!1),r.value=0})}function p(e,l){v(l,!0),F.default||e.preventDefault()}const n=i.ref(null);let u=null;function q(e){if(!c.value)return;u&&cancelAnimationFrame(u),u=requestAnimationFrame(()=>{n.value=null});const{deltaX:l,deltaY:t,shiftKey:o}=e;let f=l,s=t;(n.value==="sx"||!n.value&&o&&t&&!l)&&(f=t,s=0,n.value="sx");const y=Math.abs(f),R=Math.abs(s);n.value===null&&(n.value=A&&y>R?"x":"y"),n.value==="y"?S(e,s):p(e,f)}function D(e){c.value&&(d.value=e.detail===m.value)}return i.onUnmounted(()=>{a&&cancelAnimationFrame(a),u&&cancelAnimationFrame(u)}),[q,D]}exports.default=_;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
interface FireFoxDOMMouseScrollEvent {
|
|
3
|
+
detail: number;
|
|
4
|
+
preventDefault: VoidFunction;
|
|
5
|
+
}
|
|
6
|
+
export default function useFrameWheel(inVirtual: Ref<boolean>, isScrollAtTop: Ref<boolean>, isScrollAtBottom: Ref<boolean>, isScrollAtLeft: Ref<boolean>, isScrollAtRight: Ref<boolean>, horizontalScroll: boolean,
|
|
7
|
+
/**
|
|
8
|
+
* Return `true` when you need to prevent default event
|
|
9
|
+
*/
|
|
10
|
+
onWheelDelta: (offset: number, horizontal: boolean) => void): [(e: WheelEvent) => void, (e: FireFoxDOMMouseScrollEvent) => void];
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ref as u, onUnmounted as y } from "vue";
|
|
2
|
+
import h from "../utils/isFirefox.js";
|
|
3
|
+
import W from "./useOriginScroll.js";
|
|
4
|
+
function _(c, d, p, x, A, D, m) {
|
|
5
|
+
const r = u(0);
|
|
6
|
+
let t = null;
|
|
7
|
+
const v = u(null), F = u(!1), b = W(
|
|
8
|
+
d,
|
|
9
|
+
p,
|
|
10
|
+
x,
|
|
11
|
+
A
|
|
12
|
+
);
|
|
13
|
+
function g(e, l) {
|
|
14
|
+
if (t && cancelAnimationFrame(t), b(!1, l))
|
|
15
|
+
return;
|
|
16
|
+
const a = e;
|
|
17
|
+
if (!a._virtualHandled)
|
|
18
|
+
a._virtualHandled = !0;
|
|
19
|
+
else
|
|
20
|
+
return;
|
|
21
|
+
r.value += l, v.value = l, h || a.preventDefault(), t = requestAnimationFrame(() => {
|
|
22
|
+
const o = F.value ? 10 : 1;
|
|
23
|
+
m(r.value * o, !1), r.value = 0;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function M(e, l) {
|
|
27
|
+
m(l, !0), h || e.preventDefault();
|
|
28
|
+
}
|
|
29
|
+
const n = u(null);
|
|
30
|
+
let i = null;
|
|
31
|
+
function R(e) {
|
|
32
|
+
if (!c.value)
|
|
33
|
+
return;
|
|
34
|
+
i && cancelAnimationFrame(i), i = requestAnimationFrame(() => {
|
|
35
|
+
n.value = null;
|
|
36
|
+
});
|
|
37
|
+
const { deltaX: l, deltaY: a, shiftKey: o } = e;
|
|
38
|
+
let f = l, s = a;
|
|
39
|
+
(n.value === "sx" || !n.value && o && a && !l) && (f = a, s = 0, n.value = "sx");
|
|
40
|
+
const X = Math.abs(f), w = Math.abs(s);
|
|
41
|
+
n.value === null && (n.value = D && X > w ? "x" : "y"), n.value === "y" ? g(e, s) : M(e, f);
|
|
42
|
+
}
|
|
43
|
+
function S(e) {
|
|
44
|
+
c.value && (F.value = e.detail === v.value);
|
|
45
|
+
}
|
|
46
|
+
return y(() => {
|
|
47
|
+
t && cancelAnimationFrame(t), i && cancelAnimationFrame(i);
|
|
48
|
+
}), [R, S];
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
_ as default
|
|
52
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("vue");function p(e,t,c,v){return b.computed(()=>(n,u)=>{let f=0,r=e.value.length-1;n!=null&&(f=e.value.findIndex(o=>t(o)===n)),u!=null&&(r=e.value.findIndex(o=>t(o)===u));let d=0;for(let o=0;o<f;o+=1){const i=t(e.value[o]),l=c.get(i);d+=l===void 0?v:l}let s=0;for(let o=e.value.length-1;o>r;o-=1){const i=t(e.value[o]),l=c.get(i);s+=l===void 0?v:l}return{top:d,bottom:s}})}exports.useGetSize=p;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GetKey } from '../interface';
|
|
2
|
+
import { default as CacheMap } from '../utils/CacheMap';
|
|
3
|
+
import { ComputedRef, Ref } from 'vue';
|
|
4
|
+
export declare function useGetSize<T>(mergedData: Ref<T[]>, getKey: GetKey<T>, heights: CacheMap, itemHeight: number): ComputedRef<(startKey: any, endKey?: any) => {
|
|
5
|
+
top: number;
|
|
6
|
+
bottom: number;
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { computed as r } from "vue";
|
|
2
|
+
function h(l, t, v, e) {
|
|
3
|
+
return r(() => (u, i) => {
|
|
4
|
+
let f = 0, p = l.value.length - 1;
|
|
5
|
+
u != null && (f = l.value.findIndex((o) => t(o) === u)), i != null && (p = l.value.findIndex((o) => t(o) === i));
|
|
6
|
+
let x = 0;
|
|
7
|
+
for (let o = 0; o < f; o += 1) {
|
|
8
|
+
const c = t(l.value[o]), n = v.get(c);
|
|
9
|
+
x += n === void 0 ? e : n;
|
|
10
|
+
}
|
|
11
|
+
let d = 0;
|
|
12
|
+
for (let o = l.value.length - 1; o > p; o -= 1) {
|
|
13
|
+
const c = t(l.value[o]), n = v.get(c);
|
|
14
|
+
d += n === void 0 ? e : n;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
top: x,
|
|
18
|
+
bottom: d
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
h as useGetSize
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("vue"),C=require("../utils/CacheMap.cjs");function h(f){const s=parseFloat(f);return isNaN(s)?0:s}function P(f,s,m){const i=n.ref(0),a=n.ref(new Map),l=n.ref(new C.default),r=n.ref(0);function c(){r.value+=1}function g(u=!1){c();const e=()=>{let t=!1;a.value.forEach((o,v)=>{if(o&&o.offsetParent){const{offsetHeight:M}=o,{marginTop:N,marginBottom:R}=getComputedStyle(o),H=h(N),b=h(R),d=M+H+b;l.value.get(v)!==d&&(l.value.set(v,d),t=!0)}}),t&&(i.value+=1)};if(u)e();else{r.value+=1;const t=r.value;Promise.resolve().then(()=>{t===r.value&&e()})}}function p(u,e){const t=f(u),o=a.value.get(t);o!==e&&(e?(a.value.set(t,e),g()):a.value.delete(t),!o!=!e&&(e?s?.(u):m?.(u)))}return n.onUnmounted(()=>{c()}),[p,g,l.value,i]}exports.default=P;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GetKey } from '../interface';
|
|
2
|
+
import { Ref } from 'vue';
|
|
3
|
+
import { default as CacheMap } from '../utils/CacheMap';
|
|
4
|
+
export default function useHeights<T>(getKey: GetKey<T>, onItemAdd?: (item: T) => void, onItemRemove?: (item: T) => void): [
|
|
5
|
+
setInstanceRef: (item: T, instance: HTMLElement | null) => void,
|
|
6
|
+
collectHeight: (sync?: boolean) => void,
|
|
7
|
+
cacheMap: CacheMap,
|
|
8
|
+
updatedMark: Ref<number>
|
|
9
|
+
];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ref as u, onUnmounted as w } from "vue";
|
|
2
|
+
import B from "../utils/CacheMap.js";
|
|
3
|
+
function p(r) {
|
|
4
|
+
const a = parseFloat(r);
|
|
5
|
+
return isNaN(a) ? 0 : a;
|
|
6
|
+
}
|
|
7
|
+
function T(r, a, d) {
|
|
8
|
+
const l = u(0), s = u(/* @__PURE__ */ new Map()), i = u(new B()), f = u(0);
|
|
9
|
+
function c() {
|
|
10
|
+
f.value += 1;
|
|
11
|
+
}
|
|
12
|
+
function g(n = !1) {
|
|
13
|
+
c();
|
|
14
|
+
const e = () => {
|
|
15
|
+
let t = !1;
|
|
16
|
+
s.value.forEach((o, m) => {
|
|
17
|
+
if (o && o.offsetParent) {
|
|
18
|
+
const { offsetHeight: N } = o, { marginTop: R, marginBottom: H } = getComputedStyle(o), C = p(R), M = p(H), v = N + C + M;
|
|
19
|
+
i.value.get(m) !== v && (i.value.set(m, v), t = !0);
|
|
20
|
+
}
|
|
21
|
+
}), t && (l.value += 1);
|
|
22
|
+
};
|
|
23
|
+
if (n)
|
|
24
|
+
e();
|
|
25
|
+
else {
|
|
26
|
+
f.value += 1;
|
|
27
|
+
const t = f.value;
|
|
28
|
+
Promise.resolve().then(() => {
|
|
29
|
+
t === f.value && e();
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function h(n, e) {
|
|
34
|
+
const t = r(n), o = s.value.get(t);
|
|
35
|
+
o !== e && (e ? (s.value.set(t, e), g()) : s.value.delete(t), !o != !e && (e ? a?.(n) : d?.(n)));
|
|
36
|
+
}
|
|
37
|
+
return w(() => {
|
|
38
|
+
c();
|
|
39
|
+
}), [h, g, i.value, l];
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
T as default
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("vue"),L=14/15;function X(S,b,M){const u=s.ref(!1),v=s.ref(0),f=s.ref(0);let o=null,r=null,t=null,c;const m=e=>{if(u.value){const n=Math.ceil(e.touches[0].pageX),d=Math.ceil(e.touches[0].pageY);let l=v.value-n,i=f.value-d;const a=Math.abs(l)>Math.abs(i);a?v.value=n:f.value=d;const g=M(a,a?l:i,!1,e);g&&e.preventDefault(),t&&clearInterval(t),g&&(t=setInterval(()=>{a?l*=L:i*=L;const T=Math.floor(a?l:i);(!M(a,T,!0)||Math.abs(T)<=.1)&&t&&clearInterval(t)},16))}},p=()=>{u.value=!1,c()},E=e=>{c(),e.touches.length===1&&!u.value&&(u.value=!0,v.value=Math.ceil(e.touches[0].pageX),f.value=Math.ceil(e.touches[0].pageY),o=e.target,o.addEventListener("touchmove",m,{passive:!1}),o.addEventListener("touchend",p,{passive:!0}))};c=()=>{o&&(o.removeEventListener("touchmove",m),o.removeEventListener("touchend",p),o=null)};const I=()=>{r&&(r.removeEventListener("touchstart",E),r=null)},h=()=>{I(),c(),t&&(clearInterval(t),t=null)};s.onUnmounted(h),s.watch([S,b],([e,n],d,l)=>{e&&n?(r=n,n.addEventListener("touchstart",E,{passive:!0}),l(()=>{h()})):h()},{immediate:!0})}exports.default=X;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ref as d, onUnmounted as R, watch as S } from "vue";
|
|
2
|
+
const g = 14 / 15;
|
|
3
|
+
function H(I, X, m) {
|
|
4
|
+
const s = d(!1), i = d(0), v = d(0);
|
|
5
|
+
let o = null, u = null, t = null, c;
|
|
6
|
+
const p = (e) => {
|
|
7
|
+
if (s.value) {
|
|
8
|
+
const n = Math.ceil(e.touches[0].pageX), h = Math.ceil(e.touches[0].pageY);
|
|
9
|
+
let a = i.value - n, r = v.value - h;
|
|
10
|
+
const l = Math.abs(a) > Math.abs(r);
|
|
11
|
+
l ? i.value = n : v.value = h;
|
|
12
|
+
const L = m(l, l ? a : r, !1, e);
|
|
13
|
+
L && e.preventDefault(), t && clearInterval(t), L && (t = setInterval(() => {
|
|
14
|
+
l ? a *= g : r *= g;
|
|
15
|
+
const T = Math.floor(l ? a : r);
|
|
16
|
+
(!m(l, T, !0) || Math.abs(T) <= 0.1) && t && clearInterval(t);
|
|
17
|
+
}, 16));
|
|
18
|
+
}
|
|
19
|
+
}, M = () => {
|
|
20
|
+
s.value = !1, c();
|
|
21
|
+
}, E = (e) => {
|
|
22
|
+
c(), e.touches.length === 1 && !s.value && (s.value = !0, i.value = Math.ceil(e.touches[0].pageX), v.value = Math.ceil(e.touches[0].pageY), o = e.target, o.addEventListener("touchmove", p, { passive: !1 }), o.addEventListener("touchend", M, { passive: !0 }));
|
|
23
|
+
};
|
|
24
|
+
c = () => {
|
|
25
|
+
o && (o.removeEventListener("touchmove", p), o.removeEventListener("touchend", M), o = null);
|
|
26
|
+
};
|
|
27
|
+
const Y = () => {
|
|
28
|
+
u && (u.removeEventListener("touchstart", E), u = null);
|
|
29
|
+
}, f = () => {
|
|
30
|
+
Y(), c(), t && (clearInterval(t), t = null);
|
|
31
|
+
};
|
|
32
|
+
R(f), S(
|
|
33
|
+
[I, X],
|
|
34
|
+
([e, n], h, a) => {
|
|
35
|
+
e && n ? (u = n, n.addEventListener("touchstart", E, { passive: !0 }), a(() => {
|
|
36
|
+
f();
|
|
37
|
+
})) : f();
|
|
38
|
+
},
|
|
39
|
+
{ immediate: !0 }
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
H as default
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("vue");function v(r,i,t,a){const e=s.ref(!1);let l=null;function c(){l&&clearTimeout(l),e.value=!0,l=setTimeout(()=>{e.value=!1},50)}return(f,u,n=!1)=>{const o=f?u<0&&t.value||u>0&&a.value:u<0&&r.value||u>0&&i.value;return n&&o?(l&&clearTimeout(l),e.value=!1):(!o||e.value)&&c(),!e.value&&o}}exports.default=v;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ref as s } from "vue";
|
|
2
|
+
function m(r, i, a, f) {
|
|
3
|
+
const e = s(!1);
|
|
4
|
+
let l = null;
|
|
5
|
+
function t() {
|
|
6
|
+
l && clearTimeout(l), e.value = !0, l = setTimeout(() => {
|
|
7
|
+
e.value = !1;
|
|
8
|
+
}, 50);
|
|
9
|
+
}
|
|
10
|
+
return (c, u, n = !1) => {
|
|
11
|
+
const o = c ? u < 0 && a.value || u > 0 && f.value : u < 0 && r.value || u > 0 && i.value;
|
|
12
|
+
return n && o ? (l && clearTimeout(l), e.value = !1) : (!o || e.value) && t(), !e.value && o;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
m as default
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("vue");function b(n){return Math.floor(n**.5)}function S(n,r){return("touches"in n?n.touches[0]:n)[r?"pageX":"pageY"]-window[r?"scrollX":"scrollY"]}function h(n,r,w){let o=null,t=null,c=!1,u=null,i=0;const d=()=>{u!==null&&(cancelAnimationFrame(u),u=null)},f=()=>{d(),u=requestAnimationFrame(()=>{w(i),f()})},l=()=>{c=!1,d()},E=s=>{if(s.target.draggable||s.button!==0)return;const e=s;e._virtualHandled||(e._virtualHandled=!0,c=!0)},L=s=>{if(c&&o){const e=S(s,!1),{top:v,bottom:a}=o.getBoundingClientRect();if(e<=v){const g=v-e;i=-b(g),f()}else if(e>=a){const g=e-a;i=b(g),f()}else d()}},m=()=>{o&&(o.removeEventListener("mousedown",E),o=null),t&&(t.removeEventListener("mouseup",l),t.removeEventListener("mousemove",L),t.removeEventListener("dragend",l),t=null),l()};p.onUnmounted(m),p.watch([n,r],([s,e],v,a)=>{s&&e?(o=e,t=e.ownerDocument,o.addEventListener("mousedown",E),t.addEventListener("mouseup",l),t.addEventListener("mousemove",L),t.addEventListener("dragend",l),a(()=>{m()})):m()},{immediate:!0})}exports.default=h;exports.getPageXY=S;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
export declare function getPageXY(e: MouseEvent | TouchEvent, horizontal: boolean): number;
|
|
3
|
+
export default function useScrollDrag(inVirtual: Ref<boolean>, componentRef: Ref<HTMLElement | null | undefined>, onScrollOffset: (offset: number) => void): void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { onUnmounted as h, watch as D } from "vue";
|
|
2
|
+
function L(n) {
|
|
3
|
+
return Math.floor(n ** 0.5);
|
|
4
|
+
}
|
|
5
|
+
function b(n, l) {
|
|
6
|
+
return ("touches" in n ? n.touches[0] : n)[l ? "pageX" : "pageY"] - window[l ? "scrollX" : "scrollY"];
|
|
7
|
+
}
|
|
8
|
+
function M(n, l, p) {
|
|
9
|
+
let o = null, t = null, c = !1, u = null, i = 0;
|
|
10
|
+
const d = () => {
|
|
11
|
+
u !== null && (cancelAnimationFrame(u), u = null);
|
|
12
|
+
}, m = () => {
|
|
13
|
+
d(), u = requestAnimationFrame(() => {
|
|
14
|
+
p(i), m();
|
|
15
|
+
});
|
|
16
|
+
}, r = () => {
|
|
17
|
+
c = !1, d();
|
|
18
|
+
}, w = (s) => {
|
|
19
|
+
if (s.target.draggable || s.button !== 0)
|
|
20
|
+
return;
|
|
21
|
+
const e = s;
|
|
22
|
+
e._virtualHandled || (e._virtualHandled = !0, c = !0);
|
|
23
|
+
}, E = (s) => {
|
|
24
|
+
if (c && o) {
|
|
25
|
+
const e = b(s, !1), { top: v, bottom: a } = o.getBoundingClientRect();
|
|
26
|
+
if (e <= v) {
|
|
27
|
+
const g = v - e;
|
|
28
|
+
i = -L(g), m();
|
|
29
|
+
} else if (e >= a) {
|
|
30
|
+
const g = e - a;
|
|
31
|
+
i = L(g), m();
|
|
32
|
+
} else
|
|
33
|
+
d();
|
|
34
|
+
}
|
|
35
|
+
}, f = () => {
|
|
36
|
+
o && (o.removeEventListener("mousedown", w), o = null), t && (t.removeEventListener("mouseup", r), t.removeEventListener("mousemove", E), t.removeEventListener("dragend", r), t = null), r();
|
|
37
|
+
};
|
|
38
|
+
h(f), D(
|
|
39
|
+
[n, l],
|
|
40
|
+
([s, e], v, a) => {
|
|
41
|
+
s && e ? (o = e, t = e.ownerDocument, o.addEventListener("mousedown", w), t.addEventListener("mouseup", r), t.addEventListener("mousemove", E), t.addEventListener("dragend", r), a(() => {
|
|
42
|
+
f();
|
|
43
|
+
})) : f();
|
|
44
|
+
},
|
|
45
|
+
{ immediate: !0 }
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
M as default,
|
|
50
|
+
b as getPageXY
|
|
51
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./List.cjs");exports.default=e.default;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|