@aplus-frontend/ui 0.4.9 → 0.4.10

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.
@@ -0,0 +1,26 @@
1
+ import { ScrollBarDirection } from '../../scroll-bar';
2
+ import { Ref } from 'vue';
3
+ type ScrollBackOptions = {
4
+ scrollOffset: {
5
+ x: number;
6
+ y: number;
7
+ };
8
+ maxScrollDistance: {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ timer?: number;
13
+ onScroll?: (direction: ScrollBarDirection) => void;
14
+ onScrollEnd?: (direction: ScrollBarDirection) => void;
15
+ };
16
+ /**
17
+ * 在特定的时间内滚动到0
18
+ * @param options
19
+ * @returns
20
+ */
21
+ declare const useScrollBack: ({ scrollOffset, maxScrollDistance, timer, onScroll, onScrollEnd }: ScrollBackOptions) => {
22
+ start: (direction: ScrollBarDirection) => void;
23
+ stop: () => void;
24
+ isActive: Readonly< Ref<boolean, boolean>>;
25
+ };
26
+ export { useScrollBack };
@@ -0,0 +1,37 @@
1
+ import "../../scroll-bar/index.mjs";
2
+ import { useRafFn as x } from "@vueuse/core";
3
+ import { ensureRangeValue as u } from "../../scroll-bar/utils/index.mjs";
4
+ const m = {
5
+ horizontal: "x",
6
+ vertical: "y"
7
+ }, p = () => {
8
+ }, M = (e) => 1 - Math.pow(1 - e, 3), y = ({
9
+ scrollOffset: e,
10
+ maxScrollDistance: d,
11
+ timer: l = 500,
12
+ onScroll: n = p,
13
+ onScrollEnd: f = p
14
+ }) => {
15
+ let a, t, i;
16
+ const { pause: r, resume: g, isActive: h } = x(
17
+ () => {
18
+ const o = Date.now(), s = m[t], T = o - a, c = u(T / l, 0, 1), v = M(c);
19
+ c === 1 ? (e[s] = 0, r(), n(t), f(t)) : (e[s] = u(
20
+ i * (1 - v),
21
+ 0,
22
+ d[s]
23
+ ), n(t));
24
+ },
25
+ { immediate: !1 }
26
+ );
27
+ function w(o) {
28
+ t = o, a = Date.now(), i = e[m[o]], g();
29
+ }
30
+ function D() {
31
+ r();
32
+ }
33
+ return { start: w, stop: D, isActive: h };
34
+ };
35
+ export {
36
+ y as useScrollBack
37
+ };
@@ -0,0 +1,26 @@
1
+ import { ScrollOffsetType } from '../interface';
2
+ import { Ref } from 'vue';
3
+ type ScrollBackOptions = {
4
+ scrollOffset: {
5
+ x: number;
6
+ y: number;
7
+ };
8
+ maxScrollDistance: {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ timer?: number;
13
+ onScroll?: (x: boolean, y: boolean) => void;
14
+ onScrollEnd?: (x: boolean, y: boolean) => void;
15
+ };
16
+ /**
17
+ * 在特定的时间内滚动到0
18
+ * @param options
19
+ * @returns
20
+ */
21
+ declare const useScrollSmooth: ({ scrollOffset, maxScrollDistance, timer, onScroll, onScrollEnd }: ScrollBackOptions) => {
22
+ start: (target: Partial<ScrollOffsetType>) => void;
23
+ stop: () => void;
24
+ isActive: Readonly< Ref<boolean, boolean>>;
25
+ };
26
+ export { useScrollSmooth };
@@ -0,0 +1,50 @@
1
+ import "../../scroll-bar/index.mjs";
2
+ import { useRafFn as R } from "@vueuse/core";
3
+ import { isDef as f } from "../../utils/index.mjs";
4
+ import { ensureRangeValue as s } from "../../scroll-bar/utils/index.mjs";
5
+ const g = () => {
6
+ }, b = (i) => 1 - Math.pow(1 - i, 3), V = ({
7
+ scrollOffset: i,
8
+ maxScrollDistance: r,
9
+ timer: l = 500,
10
+ onScroll: u = g,
11
+ onScrollEnd: T = g
12
+ }) => {
13
+ let m, e, t, o, n;
14
+ const { pause: a, resume: w, isActive: p } = R(
15
+ () => {
16
+ const v = Date.now() - m, c = s(v / l, 0, 1), y = b(c);
17
+ c === 1 ? (o && (i.x = t.x), n && (i.y = t.y), a(), u(o, n), T(o, n)) : (o && (t.x > e.x ? i.x = s(
18
+ e.x + (t.x - e.x) * y,
19
+ e.x,
20
+ r.x
21
+ ) : i.x = s(
22
+ t.x + (e.x - t.x) * (1 - y),
23
+ 0,
24
+ e.x
25
+ )), n && (t.y > e.y ? i.y = s(
26
+ e.y + (t.y - e.y) * y,
27
+ e.y,
28
+ r.y
29
+ ) : i.y = s(
30
+ t.y + (e.y - t.y) * (1 - y),
31
+ 0,
32
+ e.y
33
+ )), u(o, n));
34
+ },
35
+ { immediate: !1 }
36
+ );
37
+ function d(x) {
38
+ p.value && a(), m = Date.now(), e = {
39
+ x: i.x,
40
+ y: i.y
41
+ }, t = x, o = f(x.x), n = f(x.y), w();
42
+ }
43
+ function h() {
44
+ a();
45
+ }
46
+ return { start: d, stop: h, isActive: p };
47
+ };
48
+ export {
49
+ V as useScrollSmooth
50
+ };
@@ -1,6 +1,9 @@
1
- import { ScrollViewProps } from './interface';
1
+ import { ScrollOptions, ScrollViewProps } from './interface';
2
2
  import { ScrollBarDirection, InternalScrollBarProps } from '../scroll-bar';
3
- import { CreateComponentPublicInstanceWithMixins, Ref, ComponentOptionsMixin, PublicProps, GlobalComponents, GlobalDirectives, ComponentProvideOptions, DefineComponent } from 'vue';
3
+ import { CreateComponentPublicInstanceWithMixins, Ref, ComponentOptionsMixin, PublicProps, GlobalComponents, GlobalDirectives, ComponentProvideOptions, DefineComponent, ComputedRef } from 'vue';
4
+ declare function scroll(x?: number, y?: number): void;
5
+ declare function scrollTo({ smooth, left, top }: ScrollOptions): void;
6
+ declare function scrollIntoView(element: HTMLElement, position?: 'start' | 'center' | 'end'): void;
4
7
  declare function __VLS_template(): {
5
8
  attrs: Partial<{}>;
6
9
  slots: {
@@ -89,7 +92,13 @@ declare function __VLS_template(): {
89
92
  rootEl: HTMLDivElement;
90
93
  };
91
94
  type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
92
- declare const __VLS_component: DefineComponent<ScrollViewProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ScrollViewProps> & Readonly<{}>, {
95
+ declare const __VLS_component: DefineComponent<ScrollViewProps, {
96
+ scrollTop: ComputedRef<number>;
97
+ scrollLeft: ComputedRef<number>;
98
+ scroll: typeof scroll;
99
+ scrollTo: typeof scrollTo;
100
+ scrollIntoView: typeof scrollIntoView;
101
+ }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ScrollViewProps> & Readonly<{}>, {
93
102
  showXBar: boolean;
94
103
  showYBar: boolean;
95
104
  xBarProps: {
@@ -1,15 +1,18 @@
1
- import { defineComponent as re, ref as ae, reactive as oe, computed as m, unref as o, watchEffect as N, watch as ie, openBlock as v, createElementBlock as ne, normalizeClass as h, normalizeStyle as $, withModifiers as V, createElementVNode as x, renderSlot as le, createBlock as X, mergeProps as C, createCommentVNode as D } from "vue";
1
+ import { defineComponent as fe, ref as ue, reactive as he, computed as v, unref as l, watchEffect as _, watch as pe, openBlock as P, createElementBlock as ye, normalizeClass as B, normalizeStyle as M, withModifiers as A, createElementVNode as z, renderSlot as me, createBlock as L, mergeProps as O, createCommentVNode as T } from "vue";
2
2
  import "../config-provider/index.mjs";
3
3
  import "../scroll-bar/index.mjs";
4
- import { isDef as Y } from "../utils/index.mjs";
5
- import { ensureRangeValue as c, getScrollable as B } from "../scroll-bar/utils/index.mjs";
6
- import se from "./hooks/use-scroll-wrapper.mjs";
7
- import { isString as _ } from "lodash-unified";
8
- import { useElementSize as E, useRafFn as ce } from "@vueuse/core";
9
- import { wait as fe } from "@aplus-frontend/utils";
10
- import { useNamespace as ue } from "../config-provider/hooks/use-namespace.mjs";
11
- import M from "../scroll-bar/internal.vue.mjs";
12
- const Pe = /* @__PURE__ */ re({
4
+ import { isDef as f } from "../utils/index.mjs";
5
+ import { ensureRangeValue as n, getScrollable as k } from "../scroll-bar/utils/index.mjs";
6
+ import de from "./hooks/use-scroll-wrapper.mjs";
7
+ import { isString as j } from "lodash-unified";
8
+ import { useElementSize as F, useRafFn as ve } from "@vueuse/core";
9
+ import { wait as R } from "@aplus-frontend/utils";
10
+ import { useScrollBack as xe } from "./hooks/use-scroll-back.mjs";
11
+ import { useScrollSmooth as Be } from "./hooks/use-scroll-smooth.mjs";
12
+ import { getElementScrollOffset as we } from "./utils/index.mjs";
13
+ import { useNamespace as ge } from "../config-provider/hooks/use-namespace.mjs";
14
+ import H from "../scroll-bar/internal.vue.mjs";
15
+ const Ye = /* @__PURE__ */ fe({
13
16
  name: "ScrollView",
14
17
  __name: "index",
15
18
  props: {
@@ -22,180 +25,229 @@ const Pe = /* @__PURE__ */ re({
22
25
  yBarProps: { default: () => ({}) },
23
26
  onWheel: {}
24
27
  },
25
- setup(A) {
26
- const e = A, L = {
28
+ setup(I, { expose: q }) {
29
+ const o = I, G = {
27
30
  direction: "vertical",
28
31
  rate: 1,
29
32
  repeat: !0
30
- }, { b: O, e: p, em: g } = ue("scroll-view"), f = ae(), i = oe({ x: 30, y: 30 }), {
31
- scrollOffset: a,
32
- maxScrollDistance: n,
33
- xBarRef: j,
34
- yBarRef: F,
35
- containerRef: l,
36
- scrollYBar: w,
37
- scrollXBar: b,
38
- updateMaxScrollDistance: H
39
- } = se(), { width: q, height: G } = E(f), { width: I, height: J } = E(l), { resume: K, pause: u, isActive: Q } = ce(
33
+ }, { b: J, e: w, em: W } = ge("scroll-view"), u = ue(), c = he({ x: 30, y: 30 });
34
+ let g = !1;
35
+ const {
36
+ scrollOffset: r,
37
+ maxScrollDistance: i,
38
+ xBarRef: K,
39
+ yBarRef: Q,
40
+ containerRef: s,
41
+ scrollYBar: h,
42
+ scrollXBar: p,
43
+ updateMaxScrollDistance: U
44
+ } = de(), { width: Z, height: ee } = F(u), { width: te, height: re } = F(s), { start: N } = xe({
45
+ scrollOffset: r,
46
+ maxScrollDistance: i,
47
+ onScroll: (t) => {
48
+ t === "horizontal" ? p() : h();
49
+ },
50
+ async onScrollEnd() {
51
+ await R(200), S();
52
+ }
53
+ }), { start: $ } = Be({
54
+ scrollOffset: r,
55
+ maxScrollDistance: i,
56
+ onScroll(t, e) {
57
+ V.value && (y(), g = !0), t && p(), e && h();
58
+ },
59
+ async onScrollEnd() {
60
+ g && (await R(200), S(), g = !1);
61
+ }
62
+ }), { resume: S, pause: y, isActive: V } = ve(
40
63
  () => {
41
- if (!e.autoPlay) {
42
- u();
64
+ if (!o.autoPlay) {
65
+ y();
43
66
  return;
44
67
  }
45
- const r = e.autoPlay === !0 ? {} : e.autoPlay, t = {
46
- ...L,
47
- ...r
68
+ const t = o.autoPlay === !0 ? {} : o.autoPlay, e = {
69
+ ...G,
70
+ ...t
48
71
  };
49
- if (t.direction === "horizontal") {
50
- if (a.x === n.x) {
51
- t.repeat ? a.x = 0 : u();
72
+ if (e.direction === "horizontal") {
73
+ if (r.x === i.x) {
74
+ y(), e.repeat && N("horizontal");
52
75
  return;
53
76
  }
54
- a.x = c(
55
- a.x + t.rate,
77
+ r.x = n(
78
+ r.x + e.rate,
56
79
  0,
57
- n.x
58
- ), b();
80
+ i.x
81
+ ), p();
59
82
  } else {
60
- if (a.y === n.y) {
61
- t.repeat ? a.y = 0 : u();
83
+ if (r.y === i.y) {
84
+ y(), e.repeat && N("vertical");
62
85
  return;
63
86
  }
64
- a.y = c(
65
- a.y + t.rate,
87
+ r.y = n(
88
+ r.y + e.rate,
66
89
  0,
67
- n.y
68
- ), w();
90
+ i.y
91
+ ), h();
69
92
  }
70
93
  },
71
94
  { immediate: !0 }
72
- ), d = m(() => e.showXBar && i.x !== 100), P = m(() => e.showYBar && i.y !== 100), T = m(() => ({
73
- width: Y(e.width) ? _(e.width) ? e.width : Number.isNaN(e.width) ? void 0 : `${e.width}px` : void 0,
74
- height: Y(e.heigth) ? _(e.heigth) ? e.heigth : Number.isNaN(e.heigth) ? void 0 : `${e.heigth}px` : void 0,
75
- padding: `${e.xBarProps.trackWidth || 10}px ${e.yBarProps.trackWidth || 10}px`
95
+ ), m = v(() => o.showXBar && c.x !== 100), x = v(() => o.showYBar && c.y !== 100), oe = v(() => ({
96
+ width: f(o.width) ? j(o.width) ? o.width : Number.isNaN(o.width) ? void 0 : `${o.width}px` : void 0,
97
+ height: f(o.heigth) ? j(o.heigth) ? o.heigth : Number.isNaN(o.heigth) ? void 0 : `${o.heigth}px` : void 0,
98
+ padding: `${o.xBarProps.trackWidth || 10}px ${o.yBarProps.trackWidth || 10}px`
76
99
  }));
77
- async function y() {
78
- Q.value && (u(), await fe(500), K());
100
+ async function b() {
101
+ V.value && (y(), await R(500), S());
79
102
  }
80
- async function U(r) {
81
- var t;
82
- if (o(P))
83
- r.preventDefault(), r.stopPropagation();
103
+ async function ae(t) {
104
+ var e;
105
+ if (l(x))
106
+ t.preventDefault(), t.stopPropagation();
84
107
  else
85
108
  return;
86
- a.y = c(
87
- a.y + r.deltaY,
109
+ r.y = n(
110
+ r.y + t.deltaY,
88
111
  0,
89
- n.y
90
- ), w(), (t = e.onWheel) == null || t.call(e, "vertical", a.y), y();
112
+ i.y
113
+ ), h(), (e = o.onWheel) == null || e.call(o, "vertical", r.y), b();
91
114
  }
92
- function Z(r) {
93
- var t;
94
- if (o(d))
95
- r.preventDefault(), r.stopPropagation();
115
+ function le(t) {
116
+ var e;
117
+ if (l(m))
118
+ t.preventDefault(), t.stopPropagation();
96
119
  else
97
120
  return;
98
- a.x = c(
99
- a.x + r.deltaX,
121
+ r.x = n(
122
+ r.x + t.deltaX,
100
123
  0,
101
- n.x
102
- ), b(), (t = e.onWheel) == null || t.call(e, "horizontal", a.x), y();
124
+ i.x
125
+ ), p(), (e = o.onWheel) == null || e.call(o, "horizontal", r.x), b();
103
126
  }
104
- function S() {
105
- if (e.showYBar) {
106
- const { visibleSize: r, totalSize: t } = B(
107
- l.value,
127
+ function E() {
128
+ if (o.showYBar) {
129
+ const { visibleSize: t, totalSize: e } = k(
130
+ s.value,
108
131
  "vertical"
109
132
  );
110
- i.y = c(
111
- Math.min(r / (t || 1) * 100)
133
+ c.y = n(
134
+ Math.min(t / (e || 1) * 100)
112
135
  );
113
136
  }
114
- if (e.showXBar) {
115
- const { visibleSize: r, totalSize: t } = B(
116
- l.value,
137
+ if (o.showXBar) {
138
+ const { visibleSize: t, totalSize: e } = k(
139
+ s.value,
117
140
  "horizontal"
118
141
  );
119
- i.x = c(
120
- Math.min(r / (t || 1) * 100)
142
+ c.x = n(
143
+ Math.min(t / (e || 1) * 100)
121
144
  );
122
145
  }
123
146
  }
124
- function z(r, t) {
125
- const s = o(l), ee = o(f);
126
- if (!s || !ee) return;
127
- const { visibleSize: k, totalSize: R } = B(s, t);
128
- if (R <= k) return;
129
- const W = (R - k) * r / 100, te = t === "vertical";
130
- if (y(), te) {
131
- a.y = W;
147
+ function X(t, e) {
148
+ const a = l(s), d = l(u);
149
+ if (!a || !d) return;
150
+ const { visibleSize: C, totalSize: D } = k(a, e);
151
+ if (D <= C) return;
152
+ const Y = (D - C) * t / 100, ce = e === "vertical";
153
+ if (b(), ce) {
154
+ r.y = Y;
132
155
  return;
133
156
  }
134
- a.x = W;
157
+ r.x = Y;
135
158
  }
136
- return N(
159
+ _(
137
160
  () => {
138
- o(l.value) && S();
161
+ l(s.value) && E();
139
162
  },
140
163
  { flush: "post" }
141
- ), ie(
164
+ ), pe(
142
165
  () => [
143
- q.value,
144
- G.value,
145
- I.value,
146
- J.value
166
+ Z.value,
167
+ ee.value,
168
+ te.value,
169
+ re.value
147
170
  ],
148
171
  () => {
149
- S(), H();
172
+ E(), U();
150
173
  }
151
- ), N(() => {
152
- f.value && (f.value.style.transform = `translate3d(-${a.x}px, -${a.y}px, 0px)`);
153
- }), (r, t) => (v(), ne("div", {
174
+ ), _(() => {
175
+ u.value && (u.value.style.transform = `translate3d(-${r.x}px, -${r.y}px, 0px)`);
176
+ });
177
+ function ie(t, e) {
178
+ f(t) && m.value && (r.x = n(t, 0, i.x), p()), f(e) && x.value && (r.y = n(e, 0, i.y), h());
179
+ }
180
+ function ne({ smooth: t, left: e, top: a }) {
181
+ t ? $({ x: e, y: a }) : (f(e) && (r.x = e), f(a) && (r.y = a));
182
+ }
183
+ function se(t, e = "start") {
184
+ const a = we(
185
+ s.value,
186
+ t,
187
+ e
188
+ ), d = {};
189
+ m.value && (d.x = n(
190
+ r.x + a.x,
191
+ 0,
192
+ i.x
193
+ )), x.value && (d.y = n(
194
+ r.y + a.y,
195
+ 0,
196
+ i.y
197
+ )), $(d);
198
+ }
199
+ return q({
200
+ scrollTop: v(() => r.y),
201
+ scrollLeft: v(() => r.x),
202
+ scroll: ie,
203
+ scrollTo: ne,
204
+ scrollIntoView: se
205
+ }), (t, e) => (P(), ye("div", {
154
206
  ref_key: "containerRef",
155
- ref: l,
156
- class: h(o(O)()),
157
- style: $(T.value),
207
+ ref: s,
208
+ class: B(l(J)()),
209
+ style: M(oe.value),
158
210
  onWheel: [
159
- V(U, ["exact"]),
160
- V(Z, ["shift"])
211
+ A(ae, ["exact"]),
212
+ A(le, ["shift"])
161
213
  ]
162
214
  }, [
163
- x("div", {
215
+ z("div", {
164
216
  ref_key: "contentRef",
165
- ref: f,
166
- class: h(o(p)("content"))
217
+ ref: u,
218
+ class: B(l(w)("content"))
167
219
  }, [
168
- le(r.$slots, "default")
220
+ me(t.$slots, "default")
169
221
  ], 2),
170
- x("div", {
171
- class: h([o(p)("bar-wrapper"), o(g)("bar-wrapper", "vertical")]),
172
- style: $(`height: calc(100% - ${d.value ? r.xBarProps.trackWidth || 10 : 0}px)`)
222
+ z("div", {
223
+ class: B([l(w)("bar-wrapper"), l(W)("bar-wrapper", "vertical")]),
224
+ style: M(`height: calc(100% - ${m.value ? t.xBarProps.trackWidth || 10 : 0}px)`)
173
225
  }, [
174
- P.value ? (v(), X(o(M), C({
226
+ x.value ? (P(), L(l(H), O({
175
227
  key: 0,
176
228
  ref_key: "yBarRef",
177
- ref: F
178
- }, r.yBarProps, {
179
- "bar-length": i.y,
180
- onScroll: t[0] || (t[0] = (s) => z(s, "vertical"))
181
- }), null, 16, ["bar-length"])) : D("", !0)
229
+ ref: Q
230
+ }, t.yBarProps, {
231
+ "bar-length": c.y,
232
+ onScroll: e[0] || (e[0] = (a) => X(a, "vertical"))
233
+ }), null, 16, ["bar-length"])) : T("", !0)
182
234
  ], 6),
183
- x("div", {
184
- class: h([o(p)("bar-wrapper"), o(g)("bar-wrapper", "horizontal")])
235
+ z("div", {
236
+ class: B([l(w)("bar-wrapper"), l(W)("bar-wrapper", "horizontal")])
185
237
  }, [
186
- d.value ? (v(), X(o(M), C({
238
+ m.value ? (P(), L(l(H), O({
187
239
  key: 0,
188
240
  ref_key: "xBarRef",
189
- ref: j
190
- }, r.xBarProps, {
241
+ ref: K
242
+ }, t.xBarProps, {
191
243
  direction: "horizontal",
192
- "bar-length": i.x,
193
- onScroll: t[1] || (t[1] = (s) => z(s, "horizontal"))
194
- }), null, 16, ["bar-length"])) : D("", !0)
244
+ "bar-length": c.x,
245
+ onScroll: e[1] || (e[1] = (a) => X(a, "horizontal"))
246
+ }), null, 16, ["bar-length"])) : T("", !0)
195
247
  ], 2)
196
248
  ], 38));
197
249
  }
198
250
  });
199
251
  export {
200
- Pe as default
252
+ Ye as default
201
253
  };
@@ -1,5 +1,10 @@
1
1
  import { InternalScrollBarProps, ScrollBarDirection } from '../scroll-bar';
2
+ import { Ref } from 'vue';
2
3
  type BarExtraProps = Omit<InternalScrollBarProps, 'direction' | 'scroll' | 'barLength'>;
4
+ export type ScrollOffsetType = {
5
+ x: number;
6
+ y: number;
7
+ };
3
8
  export type AutoPlayConfig = {
4
9
  /**
5
10
  * 自动滚动的方向
@@ -49,4 +54,39 @@ export interface ScrollViewProps {
49
54
  */
50
55
  onWheel?: (direction: ScrollBarDirection, offset: number) => void;
51
56
  }
57
+ export type ScrollOptions = {
58
+ top?: number;
59
+ left?: number;
60
+ smooth?: boolean;
61
+ };
62
+ export type ScrollViewExpose = {
63
+ /**
64
+ * 当前滚动距离顶部的位置
65
+ */
66
+ scrollTop: Ref<number>;
67
+ /**
68
+ * 当前滚动距离左侧的位置
69
+ */
70
+ scrollLeft: Ref<number>;
71
+ /**
72
+ * 滚动到指定位置
73
+ * @param x
74
+ * @param y
75
+ * @returns
76
+ */
77
+ scroll: (x?: number, y?: number) => void;
78
+ /**
79
+ * 滚动到指定位置(支持指定平滑滚动)
80
+ * @param options
81
+ * @returns
82
+ */
83
+ scrollTo: (options: ScrollOptions) => void;
84
+ /**
85
+ * 将子元素滚动到可视区域
86
+ * @param element
87
+ * @param position
88
+ * @returns
89
+ */
90
+ scrollIntoView: (element: Element, position?: 'start' | 'center' | 'end') => void;
91
+ };
52
92
  export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 获取某个元素相对滚动容器可见应该滚动的偏移量(绝对值)
3
+ * @param container
4
+ * @param element
5
+ * @param position
6
+ * @returns
7
+ */
8
+ export declare function getElementScrollOffset(container: HTMLElement, element: HTMLElement, position: 'start' | 'center' | 'end'): {
9
+ x: number;
10
+ y: number;
11
+ };
@@ -0,0 +1,18 @@
1
+ function i(o, c, t) {
2
+ const e = o.getBoundingClientRect(), n = c.getBoundingClientRect(), s = t === "x" ? "left" : "top", f = t === "x" ? "right" : "bottom", g = t === "x" ? "width" : "height";
3
+ return {
4
+ start: n[s] - e[s],
5
+ end: n[f] - e[f],
6
+ center: n[f] - e[f] + (e[g] - n[g]) / 2
7
+ };
8
+ }
9
+ function r(o, c, t) {
10
+ const e = i(o, c, "x"), n = i(o, c, "y");
11
+ return {
12
+ x: e[t],
13
+ y: n[t]
14
+ };
15
+ }
16
+ export {
17
+ r as getElementScrollOffset
18
+ };
@@ -0,0 +1,26 @@
1
+ import { ScrollBarDirection } from '../../scroll-bar';
2
+ import { Ref } from 'vue';
3
+ type ScrollBackOptions = {
4
+ scrollOffset: {
5
+ x: number;
6
+ y: number;
7
+ };
8
+ maxScrollDistance: {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ timer?: number;
13
+ onScroll?: (direction: ScrollBarDirection) => void;
14
+ onScrollEnd?: (direction: ScrollBarDirection) => void;
15
+ };
16
+ /**
17
+ * 在特定的时间内滚动到0
18
+ * @param options
19
+ * @returns
20
+ */
21
+ declare const useScrollBack: ({ scrollOffset, maxScrollDistance, timer, onScroll, onScrollEnd }: ScrollBackOptions) => {
22
+ start: (direction: ScrollBarDirection) => void;
23
+ stop: () => void;
24
+ isActive: Readonly< Ref<boolean, boolean>>;
25
+ };
26
+ export { useScrollBack };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../../scroll-bar/index.js");const y=require("@vueuse/core"),u=require("../../scroll-bar/utils/index.js"),l={horizontal:"x",vertical:"y"},d=()=>{},D=e=>1-Math.pow(1-e,3),M=({scrollOffset:e,maxScrollDistance:p,timer:m=500,onScroll:a=d,onScrollEnd:g=d})=>{let o,t,r;const{pause:c,resume:T,isActive:b}=y.useRafFn(()=>{const n=Date.now(),s=l[t],v=n-o,i=u.ensureRangeValue(v/m,0,1),w=D(i);i===1?(e[s]=0,c(),a(t),g(t)):(e[s]=u.ensureRangeValue(r*(1-w),0,p[s]),a(t))},{immediate:!1});function h(n){t=n,o=Date.now(),r=e[l[n]],T()}function q(){c()}return{start:h,stop:q,isActive:b}};exports.useScrollBack=M;
@@ -0,0 +1,26 @@
1
+ import { ScrollOffsetType } from '../interface';
2
+ import { Ref } from 'vue';
3
+ type ScrollBackOptions = {
4
+ scrollOffset: {
5
+ x: number;
6
+ y: number;
7
+ };
8
+ maxScrollDistance: {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ timer?: number;
13
+ onScroll?: (x: boolean, y: boolean) => void;
14
+ onScrollEnd?: (x: boolean, y: boolean) => void;
15
+ };
16
+ /**
17
+ * 在特定的时间内滚动到0
18
+ * @param options
19
+ * @returns
20
+ */
21
+ declare const useScrollSmooth: ({ scrollOffset, maxScrollDistance, timer, onScroll, onScrollEnd }: ScrollBackOptions) => {
22
+ start: (target: Partial<ScrollOffsetType>) => void;
23
+ stop: () => void;
24
+ isActive: Readonly< Ref<boolean, boolean>>;
25
+ };
26
+ export { useScrollSmooth };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../../scroll-bar/index.js");const b=require("@vueuse/core"),m=require("../../utils/index.js"),i=require("../../scroll-bar/utils/index.js"),f=()=>{},h=t=>1-Math.pow(1-t,3),v=({scrollOffset:t,maxScrollDistance:y,timer:p=500,onScroll:x=f,onScrollEnd:d=f})=>{let c,e,n,u,s;const{pause:r,resume:R,isActive:l}=b.useRafFn(()=>{const q=Date.now()-c,g=i.ensureRangeValue(q/p,0,1),o=h(g);g===1?(u&&(t.x=n.x),s&&(t.y=n.y),r(),x(u,s),d(u,s)):(u&&(n.x>e.x?t.x=i.ensureRangeValue(e.x+(n.x-e.x)*o,e.x,y.x):t.x=i.ensureRangeValue(n.x+(e.x-n.x)*(1-o),0,e.x)),s&&(n.y>e.y?t.y=i.ensureRangeValue(e.y+(n.y-e.y)*o,e.y,y.y):t.y=i.ensureRangeValue(n.y+(e.y-n.y)*(1-o),0,e.y)),x(u,s))},{immediate:!1});function T(a){l.value&&r(),c=Date.now(),e={x:t.x,y:t.y},n=a,u=m.isDef(a.x),s=m.isDef(a.y),R()}function V(){r()}return{start:T,stop:V,isActive:l}};exports.useScrollSmooth=v;
@@ -1,6 +1,9 @@
1
- import { ScrollViewProps } from './interface';
1
+ import { ScrollOptions, ScrollViewProps } from './interface';
2
2
  import { ScrollBarDirection, InternalScrollBarProps } from '../scroll-bar';
3
- import { CreateComponentPublicInstanceWithMixins, Ref, ComponentOptionsMixin, PublicProps, GlobalComponents, GlobalDirectives, ComponentProvideOptions, DefineComponent } from 'vue';
3
+ import { CreateComponentPublicInstanceWithMixins, Ref, ComponentOptionsMixin, PublicProps, GlobalComponents, GlobalDirectives, ComponentProvideOptions, DefineComponent, ComputedRef } from 'vue';
4
+ declare function scroll(x?: number, y?: number): void;
5
+ declare function scrollTo({ smooth, left, top }: ScrollOptions): void;
6
+ declare function scrollIntoView(element: HTMLElement, position?: 'start' | 'center' | 'end'): void;
4
7
  declare function __VLS_template(): {
5
8
  attrs: Partial<{}>;
6
9
  slots: {
@@ -89,7 +92,13 @@ declare function __VLS_template(): {
89
92
  rootEl: HTMLDivElement;
90
93
  };
91
94
  type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
92
- declare const __VLS_component: DefineComponent<ScrollViewProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ScrollViewProps> & Readonly<{}>, {
95
+ declare const __VLS_component: DefineComponent<ScrollViewProps, {
96
+ scrollTop: ComputedRef<number>;
97
+ scrollLeft: ComputedRef<number>;
98
+ scroll: typeof scroll;
99
+ scrollTo: typeof scrollTo;
100
+ scrollIntoView: typeof scrollIntoView;
101
+ }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ScrollViewProps> & Readonly<{}>, {
93
102
  showXBar: boolean;
94
103
  showYBar: boolean;
95
104
  xBarProps: {
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue");require("../config-provider/index.js");require("../scroll-bar/index.js");const z=require("../utils/index.js"),l=require("../scroll-bar/utils/index.js"),H=require("./hooks/use-scroll-wrapper.js"),R=require("lodash-unified"),y=require("@vueuse/core"),T=require("@aplus-frontend/utils"),U=require("../config-provider/hooks/use-namespace.js"),k=require("../scroll-bar/internal.vue.js"),G=e.defineComponent({name:"ScrollView",__name:"index",props:{width:{},heigth:{},showXBar:{type:Boolean,default:!0},showYBar:{type:Boolean,default:!0},autoPlay:{type:[Boolean,Object]},xBarProps:{default:()=>({})},yBarProps:{default:()=>({})},onWheel:{}},setup(V){const t=V,N={direction:"vertical",rate:1,repeat:!0},{b:_,e:h,em:v}=U.useNamespace("scroll-view"),c=e.ref(),o=e.reactive({x:30,y:30}),{scrollOffset:n,maxScrollDistance:i,xBarRef:q,yBarRef:W,containerRef:s,scrollYBar:g,scrollXBar:m,updateMaxScrollDistance:C}=H.default(),{width:$,height:E}=y.useElementSize(c),{width:M,height:D}=y.useElementSize(s),{resume:X,pause:f,isActive:Y}=y.useRafFn(()=>{if(!t.autoPlay){f();return}const a=t.autoPlay===!0?{}:t.autoPlay,r={...N,...a};if(r.direction==="horizontal"){if(n.x===i.x){r.repeat?n.x=0:f();return}n.x=l.ensureRangeValue(n.x+r.rate,0,i.x),m()}else{if(n.y===i.y){r.repeat?n.y=0:f();return}n.y=l.ensureRangeValue(n.y+r.rate,0,i.y),g()}},{immediate:!0}),d=e.computed(()=>t.showXBar&&o.x!==100),x=e.computed(()=>t.showYBar&&o.y!==100),A=e.computed(()=>({width:z.isDef(t.width)?R.isString(t.width)?t.width:Number.isNaN(t.width)?void 0:`${t.width}px`:void 0,height:z.isDef(t.heigth)?R.isString(t.heigth)?t.heigth:Number.isNaN(t.heigth)?void 0:`${t.heigth}px`:void 0,padding:`${t.xBarProps.trackWidth||10}px ${t.yBarProps.trackWidth||10}px`}));async function p(){Y.value&&(f(),await T.wait(500),X())}async function O(a){var r;if(e.unref(x))a.preventDefault(),a.stopPropagation();else return;n.y=l.ensureRangeValue(n.y+a.deltaY,0,i.y),g(),(r=t.onWheel)==null||r.call(t,"vertical",n.y),p()}function j(a){var r;if(e.unref(d))a.preventDefault(),a.stopPropagation();else return;n.x=l.ensureRangeValue(n.x+a.deltaX,0,i.x),m(),(r=t.onWheel)==null||r.call(t,"horizontal",n.x),p()}function B(){if(t.showYBar){const{visibleSize:a,totalSize:r}=l.getScrollable(s.value,"vertical");o.y=l.ensureRangeValue(Math.min(a/(r||1)*100))}if(t.showXBar){const{visibleSize:a,totalSize:r}=l.getScrollable(s.value,"horizontal");o.x=l.ensureRangeValue(Math.min(a/(r||1)*100))}}function w(a,r){const u=e.unref(s),L=e.unref(c);if(!u||!L)return;const{visibleSize:S,totalSize:b}=l.getScrollable(u,r);if(b<=S)return;const P=(b-S)*a/100,F=r==="vertical";if(p(),F){n.y=P;return}n.x=P}return e.watchEffect(()=>{e.unref(s.value)&&B()},{flush:"post"}),e.watch(()=>[$.value,E.value,M.value,D.value],()=>{B(),C()}),e.watchEffect(()=>{c.value&&(c.value.style.transform=`translate3d(-${n.x}px, -${n.y}px, 0px)`)}),(a,r)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"containerRef",ref:s,class:e.normalizeClass(e.unref(_)()),style:e.normalizeStyle(A.value),onWheel:[e.withModifiers(O,["exact"]),e.withModifiers(j,["shift"])]},[e.createElementVNode("div",{ref_key:"contentRef",ref:c,class:e.normalizeClass(e.unref(h)("content"))},[e.renderSlot(a.$slots,"default")],2),e.createElementVNode("div",{class:e.normalizeClass([e.unref(h)("bar-wrapper"),e.unref(v)("bar-wrapper","vertical")]),style:e.normalizeStyle(`height: calc(100% - ${d.value?a.xBarProps.trackWidth||10:0}px)`)},[x.value?(e.openBlock(),e.createBlock(e.unref(k.default),e.mergeProps({key:0,ref_key:"yBarRef",ref:W},a.yBarProps,{"bar-length":o.y,onScroll:r[0]||(r[0]=u=>w(u,"vertical"))}),null,16,["bar-length"])):e.createCommentVNode("",!0)],6),e.createElementVNode("div",{class:e.normalizeClass([e.unref(h)("bar-wrapper"),e.unref(v)("bar-wrapper","horizontal")])},[d.value?(e.openBlock(),e.createBlock(e.unref(k.default),e.mergeProps({key:0,ref_key:"xBarRef",ref:q},a.xBarProps,{direction:"horizontal","bar-length":o.x,onScroll:r[1]||(r[1]=u=>w(u,"horizontal"))}),null,16,["bar-length"])):e.createCommentVNode("",!0)],2)],38))}});exports.default=G;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue");require("../config-provider/index.js");require("../scroll-bar/index.js");const c=require("../utils/index.js"),o=require("../scroll-bar/utils/index.js"),Z=require("./hooks/use-scroll-wrapper.js"),W=require("lodash-unified"),w=require("@vueuse/core"),b=require("@aplus-frontend/utils"),ee=require("./hooks/use-scroll-back.js"),te=require("./hooks/use-scroll-smooth.js"),re=require("./utils/index.js"),ae=require("../config-provider/hooks/use-namespace.js"),D=require("../scroll-bar/internal.vue.js"),ne=e.defineComponent({name:"ScrollView",__name:"index",props:{width:{},heigth:{},showXBar:{type:Boolean,default:!0},showYBar:{type:Boolean,default:!0},autoPlay:{type:[Boolean,Object]},xBarProps:{default:()=>({})},yBarProps:{default:()=>({})},onWheel:{}},setup($,{expose:C}){const n=$,M={direction:"vertical",rate:1,repeat:!0},{b:X,e:g,em:z}=ae.useNamespace("scroll-view"),f=e.ref(),u=e.reactive({x:30,y:30});let m=!1;const{scrollOffset:a,maxScrollDistance:i,xBarRef:Y,yBarRef:O,containerRef:s,scrollYBar:h,scrollXBar:d,updateMaxScrollDistance:A}=Z.default(),{width:L,height:T}=w.useElementSize(f),{width:j,height:F}=w.useElementSize(s),{start:P}=ee.useScrollBack({scrollOffset:a,maxScrollDistance:i,onScroll:r=>{r==="horizontal"?d():h()},async onScrollEnd(){await b.wait(200),S()}}),{start:R}=te.useScrollSmooth({scrollOffset:a,maxScrollDistance:i,onScroll(r,t){V.value&&(y(),m=!0),r&&d(),t&&h()},async onScrollEnd(){m&&(await b.wait(200),S(),m=!1)}}),{resume:S,pause:y,isActive:V}=w.useRafFn(()=>{if(!n.autoPlay){y();return}const r=n.autoPlay===!0?{}:n.autoPlay,t={...M,...r};if(t.direction==="horizontal"){if(a.x===i.x){y(),t.repeat&&P("horizontal");return}a.x=o.ensureRangeValue(a.x+t.rate,0,i.x),d()}else{if(a.y===i.y){y(),t.repeat&&P("vertical");return}a.y=o.ensureRangeValue(a.y+t.rate,0,i.y),h()}},{immediate:!0}),p=e.computed(()=>n.showXBar&&u.x!==100),x=e.computed(()=>n.showYBar&&u.y!==100),H=e.computed(()=>({width:c.isDef(n.width)?W.isString(n.width)?n.width:Number.isNaN(n.width)?void 0:`${n.width}px`:void 0,height:c.isDef(n.heigth)?W.isString(n.heigth)?n.heigth:Number.isNaN(n.heigth)?void 0:`${n.heigth}px`:void 0,padding:`${n.xBarProps.trackWidth||10}px ${n.yBarProps.trackWidth||10}px`}));async function B(){V.value&&(y(),await b.wait(500),S())}async function I(r){var t;if(e.unref(x))r.preventDefault(),r.stopPropagation();else return;a.y=o.ensureRangeValue(a.y+r.deltaY,0,i.y),h(),(t=n.onWheel)==null||t.call(n,"vertical",a.y),B()}function U(r){var t;if(e.unref(p))r.preventDefault(),r.stopPropagation();else return;a.x=o.ensureRangeValue(a.x+r.deltaX,0,i.x),d(),(t=n.onWheel)==null||t.call(n,"horizontal",a.x),B()}function k(){if(n.showYBar){const{visibleSize:r,totalSize:t}=o.getScrollable(s.value,"vertical");u.y=o.ensureRangeValue(Math.min(r/(t||1)*100))}if(n.showXBar){const{visibleSize:r,totalSize:t}=o.getScrollable(s.value,"horizontal");u.x=o.ensureRangeValue(Math.min(r/(t||1)*100))}}function q(r,t){const l=e.unref(s),v=e.unref(f);if(!l||!v)return;const{visibleSize:N,totalSize:_}=o.getScrollable(l,t);if(_<=N)return;const E=(_-N)*r/100,Q=t==="vertical";if(B(),Q){a.y=E;return}a.x=E}e.watchEffect(()=>{e.unref(s.value)&&k()},{flush:"post"}),e.watch(()=>[L.value,T.value,j.value,F.value],()=>{k(),A()}),e.watchEffect(()=>{f.value&&(f.value.style.transform=`translate3d(-${a.x}px, -${a.y}px, 0px)`)});function G(r,t){c.isDef(r)&&p.value&&(a.x=o.ensureRangeValue(r,0,i.x),d()),c.isDef(t)&&x.value&&(a.y=o.ensureRangeValue(t,0,i.y),h())}function J({smooth:r,left:t,top:l}){r?R({x:t,y:l}):(c.isDef(t)&&(a.x=t),c.isDef(l)&&(a.y=l))}function K(r,t="start"){const l=re.getElementScrollOffset(s.value,r,t),v={};p.value&&(v.x=o.ensureRangeValue(a.x+l.x,0,i.x)),x.value&&(v.y=o.ensureRangeValue(a.y+l.y,0,i.y)),R(v)}return C({scrollTop:e.computed(()=>a.y),scrollLeft:e.computed(()=>a.x),scroll:G,scrollTo:J,scrollIntoView:K}),(r,t)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"containerRef",ref:s,class:e.normalizeClass(e.unref(X)()),style:e.normalizeStyle(H.value),onWheel:[e.withModifiers(I,["exact"]),e.withModifiers(U,["shift"])]},[e.createElementVNode("div",{ref_key:"contentRef",ref:f,class:e.normalizeClass(e.unref(g)("content"))},[e.renderSlot(r.$slots,"default")],2),e.createElementVNode("div",{class:e.normalizeClass([e.unref(g)("bar-wrapper"),e.unref(z)("bar-wrapper","vertical")]),style:e.normalizeStyle(`height: calc(100% - ${p.value?r.xBarProps.trackWidth||10:0}px)`)},[x.value?(e.openBlock(),e.createBlock(e.unref(D.default),e.mergeProps({key:0,ref_key:"yBarRef",ref:O},r.yBarProps,{"bar-length":u.y,onScroll:t[0]||(t[0]=l=>q(l,"vertical"))}),null,16,["bar-length"])):e.createCommentVNode("",!0)],6),e.createElementVNode("div",{class:e.normalizeClass([e.unref(g)("bar-wrapper"),e.unref(z)("bar-wrapper","horizontal")])},[p.value?(e.openBlock(),e.createBlock(e.unref(D.default),e.mergeProps({key:0,ref_key:"xBarRef",ref:Y},r.xBarProps,{direction:"horizontal","bar-length":u.x,onScroll:t[1]||(t[1]=l=>q(l,"horizontal"))}),null,16,["bar-length"])):e.createCommentVNode("",!0)],2)],38))}});exports.default=ne;
@@ -1,5 +1,10 @@
1
1
  import { InternalScrollBarProps, ScrollBarDirection } from '../scroll-bar';
2
+ import { Ref } from 'vue';
2
3
  type BarExtraProps = Omit<InternalScrollBarProps, 'direction' | 'scroll' | 'barLength'>;
4
+ export type ScrollOffsetType = {
5
+ x: number;
6
+ y: number;
7
+ };
3
8
  export type AutoPlayConfig = {
4
9
  /**
5
10
  * 自动滚动的方向
@@ -49,4 +54,39 @@ export interface ScrollViewProps {
49
54
  */
50
55
  onWheel?: (direction: ScrollBarDirection, offset: number) => void;
51
56
  }
57
+ export type ScrollOptions = {
58
+ top?: number;
59
+ left?: number;
60
+ smooth?: boolean;
61
+ };
62
+ export type ScrollViewExpose = {
63
+ /**
64
+ * 当前滚动距离顶部的位置
65
+ */
66
+ scrollTop: Ref<number>;
67
+ /**
68
+ * 当前滚动距离左侧的位置
69
+ */
70
+ scrollLeft: Ref<number>;
71
+ /**
72
+ * 滚动到指定位置
73
+ * @param x
74
+ * @param y
75
+ * @returns
76
+ */
77
+ scroll: (x?: number, y?: number) => void;
78
+ /**
79
+ * 滚动到指定位置(支持指定平滑滚动)
80
+ * @param options
81
+ * @returns
82
+ */
83
+ scrollTo: (options: ScrollOptions) => void;
84
+ /**
85
+ * 将子元素滚动到可视区域
86
+ * @param element
87
+ * @param position
88
+ * @returns
89
+ */
90
+ scrollIntoView: (element: Element, position?: 'start' | 'center' | 'end') => void;
91
+ };
52
92
  export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 获取某个元素相对滚动容器可见应该滚动的偏移量(绝对值)
3
+ * @param container
4
+ * @param element
5
+ * @param position
6
+ * @returns
7
+ */
8
+ export declare function getElementScrollOffset(container: HTMLElement, element: HTMLElement, position: 'start' | 'center' | 'end'): {
9
+ x: number;
10
+ y: number;
11
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(o,c,t){const e=o.getBoundingClientRect(),n=c.getBoundingClientRect(),s=t==="x"?"left":"top",f=t==="x"?"right":"bottom",l=t==="x"?"width":"height";return{start:n[s]-e[s],end:n[f]-e[f],center:n[f]-e[f]+(e[l]-n[l])/2}}function r(o,c,t){const e=g(o,c,"x"),n=g(o,c,"y");return{x:e[t],y:n[t]}}exports.getElementScrollOffset=r;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aplus-frontend/ui",
3
- "version": "0.4.9",
3
+ "version": "0.4.10",
4
4
  "main": "./lib/index.js",
5
5
  "type": "module",
6
6
  "files": [