@v-c/virtual-list 0.0.1 → 1.0.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.
Files changed (66) hide show
  1. package/bump.config.ts +6 -0
  2. package/dist/Filler.cjs +51 -1
  3. package/dist/Filler.js +47 -56
  4. package/dist/Item.cjs +26 -1
  5. package/dist/Item.js +23 -26
  6. package/dist/List.cjs +408 -1
  7. package/dist/List.d.ts +45 -9
  8. package/dist/List.js +403 -274
  9. package/dist/ScrollBar.cjs +259 -1
  10. package/dist/ScrollBar.d.ts +3 -97
  11. package/dist/ScrollBar.js +254 -191
  12. package/dist/_virtual/rolldown_runtime.cjs +21 -0
  13. package/dist/hooks/useDiffItem.cjs +19 -1
  14. package/dist/hooks/useDiffItem.js +16 -20
  15. package/dist/hooks/useFrameWheel.cjs +63 -1
  16. package/dist/hooks/useFrameWheel.js +60 -51
  17. package/dist/hooks/useGetSize.cjs +29 -1
  18. package/dist/hooks/useGetSize.d.ts +2 -2
  19. package/dist/hooks/useGetSize.js +27 -23
  20. package/dist/hooks/useHeights.cjs +66 -1
  21. package/dist/hooks/useHeights.d.ts +1 -1
  22. package/dist/hooks/useHeights.js +62 -41
  23. package/dist/hooks/useMobileTouchMove.cjs +82 -1
  24. package/dist/hooks/useMobileTouchMove.js +79 -43
  25. package/dist/hooks/useOriginScroll.cjs +23 -1
  26. package/dist/hooks/useOriginScroll.js +20 -16
  27. package/dist/hooks/useScrollDrag.cjs +83 -1
  28. package/dist/hooks/useScrollDrag.js +77 -48
  29. package/dist/hooks/useScrollTo.cjs +97 -0
  30. package/dist/hooks/useScrollTo.d.ts +19 -0
  31. package/dist/hooks/useScrollTo.js +94 -0
  32. package/dist/index.cjs +4 -1
  33. package/dist/index.d.ts +1 -1
  34. package/dist/index.js +3 -4
  35. package/dist/interface.cjs +0 -1
  36. package/dist/interface.d.ts +1 -1
  37. package/dist/interface.js +0 -1
  38. package/dist/utils/CacheMap.cjs +25 -1
  39. package/dist/utils/CacheMap.d.ts +1 -1
  40. package/dist/utils/CacheMap.js +23 -28
  41. package/dist/utils/isFirefox.cjs +4 -1
  42. package/dist/utils/isFirefox.js +2 -4
  43. package/dist/utils/scrollbarUtil.cjs +8 -1
  44. package/dist/utils/scrollbarUtil.js +7 -6
  45. package/docs/animate.less +31 -0
  46. package/docs/animate.vue +159 -0
  47. package/docs/basic.vue +2 -1
  48. package/docs/nest.vue +1 -1
  49. package/docs/switch.vue +2 -1
  50. package/docs/virtual-list.stories.vue +4 -0
  51. package/package.json +16 -14
  52. package/src/Filler.tsx +2 -1
  53. package/src/Item.tsx +2 -1
  54. package/src/List.tsx +189 -124
  55. package/src/ScrollBar.tsx +33 -44
  56. package/src/hooks/useDiffItem.ts +3 -2
  57. package/src/hooks/useFrameWheel.ts +2 -1
  58. package/src/hooks/useGetSize.ts +5 -4
  59. package/src/hooks/useHeights.ts +7 -6
  60. package/src/hooks/useMobileTouchMove.ts +2 -1
  61. package/src/hooks/useOriginScroll.ts +2 -1
  62. package/src/hooks/useScrollDrag.ts +2 -1
  63. package/src/hooks/useScrollTo.tsx +184 -0
  64. package/src/index.ts +1 -1
  65. package/tsconfig.json +7 -0
  66. package/vitest.config.ts +1 -1
package/dist/ScrollBar.js CHANGED
@@ -1,193 +1,256 @@
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"];
1
+ import { computed, createVNode, defineComponent, onMounted, onUnmounted, ref, shallowRef, watch } from "vue";
2
+ import raf from "@v-c/util/dist/raf";
3
+ function getPageXY(e, horizontal) {
4
+ return ("touches" in e ? e.touches[0] : e)[horizontal ? "pageX" : "pageY"] - window[horizontal ? "scrollX" : "scrollY"];
4
5
  }
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
- }
6
+ var ScrollBar_default = /* @__PURE__ */ defineComponent({
7
+ props: {
8
+ prefixCls: {
9
+ type: String,
10
+ required: true,
11
+ default: void 0
12
+ },
13
+ scrollOffset: {
14
+ type: Number,
15
+ required: true,
16
+ default: void 0
17
+ },
18
+ scrollRange: {
19
+ type: Number,
20
+ required: true,
21
+ default: void 0
22
+ },
23
+ rtl: {
24
+ type: Boolean,
25
+ required: true,
26
+ default: void 0
27
+ },
28
+ onScroll: {
29
+ type: Function,
30
+ required: true,
31
+ default: void 0
32
+ },
33
+ onStartMove: {
34
+ type: Function,
35
+ required: true,
36
+ default: void 0
37
+ },
38
+ onStopMove: {
39
+ type: Function,
40
+ required: true,
41
+ default: void 0
42
+ },
43
+ horizontal: {
44
+ type: Boolean,
45
+ required: false,
46
+ default: void 0
47
+ },
48
+ style: {
49
+ type: Object,
50
+ required: false,
51
+ default: void 0
52
+ },
53
+ thumbStyle: {
54
+ type: Object,
55
+ required: false,
56
+ default: void 0
57
+ },
58
+ spinSize: {
59
+ type: Number,
60
+ required: true,
61
+ default: void 0
62
+ },
63
+ containerSize: {
64
+ type: Number,
65
+ required: true,
66
+ default: void 0
67
+ },
68
+ showScrollBar: {
69
+ type: [Boolean, String],
70
+ required: false,
71
+ default: void 0
72
+ }
73
+ },
74
+ name: "ScrollBar",
75
+ setup(props, { expose }) {
76
+ const dragging = ref(false);
77
+ const pageXY = ref(null);
78
+ const startTop = ref(null);
79
+ const isLTR = computed(() => !props.rtl);
80
+ const scrollbarRef = shallowRef();
81
+ const thumbRef = shallowRef();
82
+ const visible = ref(props.showScrollBar === "optional" ? true : props.showScrollBar);
83
+ let visibleTimeout = null;
84
+ const delayHidden = () => {
85
+ if (props.showScrollBar === true || props.showScrollBar === false) return;
86
+ if (visibleTimeout) clearTimeout(visibleTimeout);
87
+ visible.value = true;
88
+ visibleTimeout = setTimeout(() => {
89
+ visible.value = false;
90
+ }, 3e3);
91
+ };
92
+ const enableScrollRange = computed(() => props.scrollRange - props.containerSize || 0);
93
+ const enableOffsetRange = computed(() => props.containerSize - props.spinSize || 0);
94
+ const top = computed(() => {
95
+ if (props.scrollOffset === 0 || enableScrollRange.value === 0) return 0;
96
+ return props.scrollOffset / enableScrollRange.value * enableOffsetRange.value;
97
+ });
98
+ const stateRef = shallowRef({
99
+ top: top.value,
100
+ dragging: dragging.value,
101
+ pageY: pageXY.value,
102
+ startTop: startTop.value
103
+ });
104
+ watch([
105
+ top,
106
+ dragging,
107
+ pageXY,
108
+ startTop
109
+ ], () => {
110
+ stateRef.value = {
111
+ top: top.value,
112
+ dragging: dragging.value,
113
+ pageY: pageXY.value,
114
+ startTop: startTop.value
115
+ };
116
+ });
117
+ const onContainerMouseDown = (e) => {
118
+ e.stopPropagation();
119
+ e.preventDefault();
120
+ };
121
+ const onThumbMouseDown = (e) => {
122
+ dragging.value = true;
123
+ pageXY.value = getPageXY(e, props.horizontal || false);
124
+ startTop.value = stateRef.value.top;
125
+ props?.onStartMove?.();
126
+ e.stopPropagation();
127
+ e.preventDefault();
128
+ };
129
+ onMounted(() => {
130
+ const onScrollbarTouchStart = (e) => {
131
+ e.preventDefault();
132
+ };
133
+ const scrollbarEle = scrollbarRef.value;
134
+ const thumbEle = thumbRef.value;
135
+ if (scrollbarEle && thumbEle) {
136
+ scrollbarEle.addEventListener("touchstart", onScrollbarTouchStart, { passive: false });
137
+ thumbEle.addEventListener("touchstart", onThumbMouseDown, { passive: false });
138
+ onUnmounted(() => {
139
+ scrollbarEle.removeEventListener("touchstart", onScrollbarTouchStart);
140
+ thumbEle.removeEventListener("touchstart", onThumbMouseDown);
141
+ });
142
+ }
143
+ });
144
+ watch(dragging, (isDragging, _O, onCleanup) => {
145
+ if (isDragging) {
146
+ let moveRafId = null;
147
+ const onMouseMove = (e) => {
148
+ const { dragging: stateDragging, pageY: statePageY, startTop: stateStartTop } = stateRef.value;
149
+ raf.cancel(moveRafId);
150
+ const rect = scrollbarRef.value.getBoundingClientRect();
151
+ const scale = props.containerSize / (props.horizontal ? rect.width : rect.height);
152
+ if (stateDragging) {
153
+ const offset = (getPageXY(e, props.horizontal || false) - (statePageY || 0)) * scale;
154
+ let newTop = stateStartTop || 0;
155
+ if (!isLTR.value && props.horizontal) newTop -= offset;
156
+ else newTop += offset;
157
+ const tmpEnableScrollRange = enableScrollRange.value;
158
+ const tmpEnableOffsetRange = enableOffsetRange.value;
159
+ const ptg = tmpEnableOffsetRange ? newTop / tmpEnableOffsetRange : 0;
160
+ let newScrollTop = Math.ceil(ptg * tmpEnableScrollRange);
161
+ newScrollTop = Math.max(newScrollTop, 0);
162
+ newScrollTop = Math.min(newScrollTop, tmpEnableScrollRange);
163
+ moveRafId = raf(() => {
164
+ props?.onScroll?.(newScrollTop, props.horizontal);
165
+ });
166
+ }
167
+ };
168
+ const onMouseUp = () => {
169
+ dragging.value = false;
170
+ props.onStopMove();
171
+ };
172
+ window.addEventListener("mousemove", onMouseMove, { passive: true });
173
+ window.addEventListener("touchmove", onMouseMove, { passive: true });
174
+ window.addEventListener("mouseup", onMouseUp, { passive: true });
175
+ window.addEventListener("touchend", onMouseUp, { passive: true });
176
+ onCleanup(() => {
177
+ window.removeEventListener("mousemove", onMouseMove);
178
+ window.removeEventListener("touchmove", onMouseMove);
179
+ window.removeEventListener("mouseup", onMouseUp);
180
+ window.removeEventListener("touchend", onMouseUp);
181
+ raf.cancel(moveRafId);
182
+ });
183
+ }
184
+ });
185
+ watch(() => props.scrollOffset, (_n, _o, onCleanup) => {
186
+ delayHidden();
187
+ onCleanup(() => {
188
+ if (visibleTimeout) clearTimeout(visibleTimeout);
189
+ });
190
+ });
191
+ expose({ delayHidden });
192
+ return () => {
193
+ const { prefixCls, horizontal } = props;
194
+ const scrollbarPrefixCls = `${prefixCls}-scrollbar`;
195
+ const containerStyle = {
196
+ position: "absolute",
197
+ visibility: visible.value ? void 0 : "hidden"
198
+ };
199
+ const thumbStyle = {
200
+ position: "absolute",
201
+ borderRadius: "99px",
202
+ background: "var(--vc-virtual-list-scrollbar-bg, rgba(0, 0, 0, 0.5))",
203
+ cursor: "pointer",
204
+ userSelect: "none"
205
+ };
206
+ if (props.horizontal) {
207
+ Object.assign(containerStyle, {
208
+ height: "8px",
209
+ left: 0,
210
+ right: 0,
211
+ bottom: 0
212
+ });
213
+ Object.assign(thumbStyle, {
214
+ height: "100%",
215
+ width: `${props.spinSize}px`,
216
+ [isLTR.value ? "left" : "right"]: `${top.value}px`
217
+ });
218
+ } else {
219
+ Object.assign(containerStyle, {
220
+ width: "8px",
221
+ top: 0,
222
+ bottom: 0,
223
+ [isLTR.value ? "right" : "left"]: 0
224
+ });
225
+ Object.assign(thumbStyle, {
226
+ width: "100%",
227
+ height: `${props.spinSize}px`,
228
+ top: `${top.value}px`
229
+ });
230
+ }
231
+ return createVNode("div", {
232
+ "ref": scrollbarRef,
233
+ "class": [scrollbarPrefixCls, {
234
+ [`${scrollbarPrefixCls}-horizontal`]: horizontal,
235
+ [`${scrollbarPrefixCls}-vertical`]: !horizontal,
236
+ [`${scrollbarPrefixCls}-visible`]: visible.value
237
+ }],
238
+ "style": {
239
+ ...containerStyle,
240
+ ...props.style
241
+ },
242
+ "onMousedown": onContainerMouseDown,
243
+ "onMousemove": delayHidden
244
+ }, [createVNode("div", {
245
+ "ref": thumbRef,
246
+ "class": [`${scrollbarPrefixCls}-thumb`, { [`${scrollbarPrefixCls}-thumb-moving`]: dragging.value }],
247
+ "style": {
248
+ ...thumbStyle,
249
+ ...props.thumbStyle
250
+ },
251
+ "onMousedown": onThumbMouseDown
252
+ }, null)]);
253
+ };
254
+ }
190
255
  });
191
- export {
192
- k as default
193
- };
256
+ export { ScrollBar_default as default };
@@ -0,0 +1,21 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
9
+ key = keys[i];
10
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
11
+ get: ((k) => from[k]).bind(null, key),
12
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
13
+ });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
18
+ value: mod,
19
+ enumerable: true
20
+ }) : target, mod));
21
+ exports.__toESM = __toESM;
@@ -1 +1,19 @@
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;
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
3
+ let vue = require("vue");
4
+ function useDiffItem(data, getKey) {
5
+ const prevDataRef = (0, vue.ref)([]);
6
+ const diffItem = (0, vue.ref)();
7
+ (0, vue.watch)(data, (newData) => {
8
+ const prevData = prevDataRef.value;
9
+ if (newData !== prevData) {
10
+ diffItem.value = newData.find((item) => {
11
+ const key = getKey(item);
12
+ return !prevData.some((prevItem) => getKey(prevItem) === key);
13
+ });
14
+ prevDataRef.value = newData;
15
+ }
16
+ }, { immediate: true });
17
+ return diffItem;
18
+ }
19
+ exports.default = useDiffItem;
@@ -1,21 +1,17 @@
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;
1
+ import { ref, watch } from "vue";
2
+ function useDiffItem(data, getKey) {
3
+ const prevDataRef = ref([]);
4
+ const diffItem = ref();
5
+ watch(data, (newData) => {
6
+ const prevData = prevDataRef.value;
7
+ if (newData !== prevData) {
8
+ diffItem.value = newData.find((item) => {
9
+ const key = getKey(item);
10
+ return !prevData.some((prevItem) => getKey(prevItem) === key);
11
+ });
12
+ prevDataRef.value = newData;
13
+ }
14
+ }, { immediate: true });
15
+ return diffItem;
18
16
  }
19
- export {
20
- v as default
21
- };
17
+ export { useDiffItem as default };
@@ -1 +1,63 @@
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=_;
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
3
+ const require_isFirefox = require("../utils/isFirefox.cjs");
4
+ const require_useOriginScroll = require("./useOriginScroll.cjs");
5
+ let vue = require("vue");
6
+ function useFrameWheel(inVirtual, isScrollAtTop, isScrollAtBottom, isScrollAtLeft, isScrollAtRight, horizontalScroll, onWheelDelta) {
7
+ const offsetRef = (0, vue.ref)(0);
8
+ let nextFrame = null;
9
+ const wheelValueRef = (0, vue.ref)(null);
10
+ const isMouseScrollRef = (0, vue.ref)(false);
11
+ const originScroll = require_useOriginScroll.default(isScrollAtTop, isScrollAtBottom, isScrollAtLeft, isScrollAtRight);
12
+ function onWheelY(e, deltaY) {
13
+ if (nextFrame) cancelAnimationFrame(nextFrame);
14
+ if (originScroll(false, deltaY)) return;
15
+ const event = e;
16
+ if (!event._virtualHandled) event._virtualHandled = true;
17
+ else return;
18
+ offsetRef.value += deltaY;
19
+ wheelValueRef.value = deltaY;
20
+ if (!require_isFirefox.default) event.preventDefault();
21
+ nextFrame = requestAnimationFrame(() => {
22
+ const patchMultiple = isMouseScrollRef.value ? 10 : 1;
23
+ onWheelDelta(offsetRef.value * patchMultiple, false);
24
+ offsetRef.value = 0;
25
+ });
26
+ }
27
+ function onWheelX(event, deltaX) {
28
+ onWheelDelta(deltaX, true);
29
+ if (!require_isFirefox.default) event.preventDefault();
30
+ }
31
+ const wheelDirectionRef = (0, vue.ref)(null);
32
+ let wheelDirectionClean = null;
33
+ function onWheel(event) {
34
+ if (!inVirtual.value) return;
35
+ if (wheelDirectionClean) cancelAnimationFrame(wheelDirectionClean);
36
+ wheelDirectionClean = requestAnimationFrame(() => {
37
+ wheelDirectionRef.value = null;
38
+ });
39
+ const { deltaX, deltaY, shiftKey } = event;
40
+ let mergedDeltaX = deltaX;
41
+ let mergedDeltaY = deltaY;
42
+ if (wheelDirectionRef.value === "sx" || !wheelDirectionRef.value && (shiftKey || false) && deltaY && !deltaX) {
43
+ mergedDeltaX = deltaY;
44
+ mergedDeltaY = 0;
45
+ wheelDirectionRef.value = "sx";
46
+ }
47
+ const absX = Math.abs(mergedDeltaX);
48
+ const absY = Math.abs(mergedDeltaY);
49
+ if (wheelDirectionRef.value === null) wheelDirectionRef.value = horizontalScroll && absX > absY ? "x" : "y";
50
+ if (wheelDirectionRef.value === "y") onWheelY(event, mergedDeltaY);
51
+ else onWheelX(event, mergedDeltaX);
52
+ }
53
+ function onFireFoxScroll(event) {
54
+ if (!inVirtual.value) return;
55
+ isMouseScrollRef.value = event.detail === wheelValueRef.value;
56
+ }
57
+ (0, vue.onUnmounted)(() => {
58
+ if (nextFrame) cancelAnimationFrame(nextFrame);
59
+ if (wheelDirectionClean) cancelAnimationFrame(wheelDirectionClean);
60
+ });
61
+ return [onWheel, onFireFoxScroll];
62
+ }
63
+ exports.default = useFrameWheel;