@loickit-v/swiper 0.0.8 → 0.0.9
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.
@@ -1,13 +1,13 @@
|
|
1
|
-
import { defineComponent as
|
2
|
-
import { u_setStyle as
|
3
|
-
import { u_setTransform as
|
4
|
-
import { SLIDE_DIRECTION as
|
5
|
-
import { checkDirection as
|
1
|
+
import { defineComponent as V, ref as g, watch as y, computed as w, onMounted as Z, createElementBlock as $, openBlock as X, withModifiers as f, createElementVNode as Y, normalizeStyle as b, unref as m, renderSlot as k, reactive as j, provide as q, nextTick as z } from "vue";
|
2
|
+
import { u_setStyle as F } from "@likcheung/shared";
|
3
|
+
import { u_setTransform as v, u_setFlush as U } from "../../utils/index.js";
|
4
|
+
import { SLIDE_DIRECTION as h } from "../constant/index.js";
|
5
|
+
import { checkDirection as G } from "../../utils/slide.js";
|
6
6
|
import { COMMON_SLIDE_PROVIDE_NAME as M } from "../constant/private.js";
|
7
|
-
import { useSlideState as
|
8
|
-
import { defaultState as
|
9
|
-
import { createSlidePrivateProvide as
|
10
|
-
const
|
7
|
+
import { useSlideState as J } from "../Provide/index.js";
|
8
|
+
import { defaultState as K } from "../../hooks/defineSlide/default.js";
|
9
|
+
import { createSlidePrivateProvide as Q } from "./provide.js";
|
10
|
+
const ae = /* @__PURE__ */ V({
|
11
11
|
name: "LSlide",
|
12
12
|
__name: "index",
|
13
13
|
props: {
|
@@ -18,93 +18,105 @@ const le = /* @__PURE__ */ H({
|
|
18
18
|
},
|
19
19
|
emits: ["switch"],
|
20
20
|
setup(S, { emit: _ }) {
|
21
|
-
var
|
22
|
-
const
|
23
|
-
if (
|
24
|
-
throw new Error("list is required when infinite
|
25
|
-
const
|
26
|
-
|
21
|
+
var N;
|
22
|
+
const n = S;
|
23
|
+
if (n.infinite && !((N = n.list) != null && N.length))
|
24
|
+
throw new Error("list is required when use infinite mode");
|
25
|
+
const O = _, c = () => {
|
26
|
+
F(
|
27
27
|
r.value,
|
28
28
|
"transition-duration",
|
29
29
|
`${e.duration}ms`
|
30
|
-
),
|
31
|
-
}, p =
|
32
|
-
name:
|
30
|
+
), v(e.direction, r.value, -l.value);
|
31
|
+
}, p = Q({
|
32
|
+
name: n.name,
|
33
33
|
itemsInfo: [],
|
34
|
-
infinite:
|
35
|
-
}),
|
36
|
-
const
|
37
|
-
return
|
38
|
-
}, e =
|
39
|
-
|
40
|
-
() =>
|
34
|
+
infinite: n.infinite
|
35
|
+
}), P = () => {
|
36
|
+
const t = j(K);
|
37
|
+
return q(n.name, t), t;
|
38
|
+
}, e = n.name !== M ? J(n.name) : P(), x = () => n.list.slice(e.currentIndex, e.currentIndex + 3), o = n.infinite ? g(x()) : null;
|
39
|
+
n.infinite && y(
|
40
|
+
() => n.list,
|
41
41
|
() => {
|
42
42
|
o.value = x();
|
43
43
|
},
|
44
44
|
{ once: !0 }
|
45
|
-
)
|
46
|
-
const
|
45
|
+
);
|
46
|
+
const D = (t) => {
|
47
|
+
var s;
|
48
|
+
const i = r.value ? r.value.childElementCount : n.infinite ? n.list.length || ((s = o == null ? void 0 : o.value) == null ? void 0 : s.length) || 0 : 1 / 0;
|
49
|
+
return t < 0 || t > i - 1;
|
50
|
+
};
|
51
|
+
y(
|
52
|
+
() => e.currentIndex,
|
53
|
+
(t, i) => {
|
54
|
+
if (D(t)) return e.currentIndex = i;
|
55
|
+
c();
|
56
|
+
}
|
57
|
+
);
|
58
|
+
const r = g(), l = w(
|
47
59
|
() => (
|
48
60
|
// 通过收集所有 slide-item 的宽和高, 叠加计算
|
49
|
-
p.itemsInfo.slice(0, e.currentIndex).reduce((
|
61
|
+
p.itemsInfo.slice(0, e.currentIndex).reduce((t, i) => (t += i[e.direction === h.HORIZONTAL ? "width" : "height"], t), 0)
|
50
62
|
)
|
51
|
-
),
|
63
|
+
), C = w(
|
52
64
|
() => e.currentIndex === 0 && !e.isNext || e.currentIndex === p.itemsInfo.length - 1 && e.isNext
|
53
|
-
),
|
54
|
-
let
|
55
|
-
const
|
56
|
-
|
57
|
-
}, { isConsistent:
|
58
|
-
if (!
|
59
|
-
const i =
|
60
|
-
e.isNext =
|
65
|
+
), a = { x: 0, y: 0 };
|
66
|
+
let u = !1;
|
67
|
+
const E = (t) => {
|
68
|
+
u = !0, a.x = t.pageX, a.y = t.pageY;
|
69
|
+
}, { isConsistent: L, checkDirectionConsistent: T, resetCheckDirection: R } = G(e.direction), A = (t) => {
|
70
|
+
if (!u) return;
|
71
|
+
const i = t.pageX - a.x, s = t.pageY - a.y, d = e.direction === h.HORIZONTAL ? i : s;
|
72
|
+
e.isNext = d < 0, !C.value && (T(i, s), L.value && (U(r.value), v(
|
61
73
|
e.direction,
|
62
74
|
r.value,
|
63
|
-
Math.min(-
|
64
|
-
), e.shouldNext = Math.abs(
|
65
|
-
},
|
66
|
-
e.shouldNext = !1,
|
67
|
-
},
|
75
|
+
Math.min(-l.value + d, e.isNext ? -l.value : 0)
|
76
|
+
), e.shouldNext = Math.abs(d) > e.judgeValue));
|
77
|
+
}, I = () => {
|
78
|
+
e.shouldNext = !1, u = !1, R();
|
79
|
+
}, B = () => n.infinite ? e.currentIndex === o.value.length - 1 : !1, H = () => {
|
68
80
|
if (!e.shouldNext)
|
69
|
-
return c(),
|
81
|
+
return c(), I();
|
70
82
|
e.currentIndex += e.isNext ? 1 : -1, c();
|
71
|
-
const
|
83
|
+
const t = {
|
72
84
|
index: e.currentIndex
|
73
85
|
};
|
74
|
-
|
75
|
-
(o == null ? void 0 : o.value.length) ===
|
76
|
-
const i =
|
86
|
+
n.infinite && (t.item = n.list[e.currentIndex]), O("switch", t), I(), B() && z(async () => {
|
87
|
+
(o == null ? void 0 : o.value.length) === n.list.length && n.loadMore && await n.loadMore();
|
88
|
+
const i = n.list[e.currentIndex + 1];
|
77
89
|
i && o.value.push(i);
|
78
90
|
});
|
79
91
|
};
|
80
|
-
return
|
81
|
-
|
82
|
-
}), (
|
92
|
+
return Z(() => {
|
93
|
+
v(e.direction, r.value, -l.value);
|
94
|
+
}), (t, i) => (X(), $(
|
83
95
|
"div",
|
84
96
|
{
|
85
97
|
class: "loickit-slide",
|
86
98
|
id: "loickit-slide",
|
87
|
-
onPointerdown:
|
88
|
-
onPointermove:
|
89
|
-
onPointerup:
|
99
|
+
onPointerdown: f(E, ["prevent"]),
|
100
|
+
onPointermove: f(A, ["prevent"]),
|
101
|
+
onPointerup: f(H, ["prevent"])
|
90
102
|
},
|
91
103
|
[
|
92
|
-
|
104
|
+
Y(
|
93
105
|
"div",
|
94
106
|
{
|
95
107
|
class: "loickit-slide-list",
|
96
|
-
style:
|
108
|
+
style: b({
|
97
109
|
// 根据方向设置 flex-direction
|
98
|
-
flexDirection:
|
110
|
+
flexDirection: m(e).direction === m(h).HORIZONTAL ? "row" : "column"
|
99
111
|
}),
|
100
112
|
ref_key: "slideListRef",
|
101
113
|
ref: r
|
102
114
|
},
|
103
115
|
[
|
104
|
-
|
116
|
+
n.infinite ? k(t.$slots, "default", {
|
105
117
|
key: 1,
|
106
|
-
cacheList:
|
107
|
-
}) : k(
|
118
|
+
cacheList: m(o)
|
119
|
+
}) : k(t.$slots, "default", { key: 0 })
|
108
120
|
],
|
109
121
|
4
|
110
122
|
/* STYLE */
|
@@ -116,5 +128,5 @@ const le = /* @__PURE__ */ H({
|
|
116
128
|
}
|
117
129
|
});
|
118
130
|
export {
|
119
|
-
|
131
|
+
ae as default
|
120
132
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { defineComponent as a,
|
1
|
+
import { defineComponent as a, watch as c, ref as f, onMounted as m, onBeforeUnmount as p, createElementBlock as u, openBlock as h, createElementVNode as x, renderSlot as v } from "vue";
|
2
2
|
import { useSlideState as I } from "../Provide/index.js";
|
3
3
|
import { useSlidePrivateState as w } from "../Slide/provide.js";
|
4
4
|
const C = /* @__PURE__ */ a({
|
@@ -7,25 +7,24 @@ const C = /* @__PURE__ */ a({
|
|
7
7
|
props: {
|
8
8
|
index: {}
|
9
9
|
},
|
10
|
-
setup(
|
11
|
-
const i =
|
12
|
-
if (e.infinite)
|
13
|
-
|
14
|
-
|
15
|
-
`index is required when infinite is true
|
10
|
+
setup(l) {
|
11
|
+
const i = l, e = w();
|
12
|
+
if (e.infinite && typeof i.index != "number")
|
13
|
+
throw new Error(
|
14
|
+
`index is required when infinite is true
|
16
15
|
please use the second parameter of the "v-for" directive`
|
17
|
-
);
|
18
|
-
c(
|
19
|
-
() => r.currentIndex,
|
20
|
-
() => {
|
21
|
-
var t;
|
22
|
-
r.currentIndex <= i.index + 1 && r.currentIndex >= i.index - 1 ? (t = o.value) == null || t.appendChild(
|
23
|
-
e.itemsInfo[i.index].el
|
24
|
-
) : s.value.remove();
|
25
|
-
}
|
26
16
|
);
|
27
|
-
|
28
|
-
|
17
|
+
const r = I(e.name);
|
18
|
+
e.infinite && c(
|
19
|
+
() => r.currentIndex,
|
20
|
+
() => {
|
21
|
+
var t;
|
22
|
+
r.currentIndex <= i.index + 1 && r.currentIndex >= i.index - 1 ? (t = o.value) == null || t.appendChild(
|
23
|
+
e.itemsInfo[i.index].el
|
24
|
+
) : s.value.remove();
|
25
|
+
}
|
26
|
+
);
|
27
|
+
const o = f(), s = f(), n = {
|
29
28
|
index: i.index
|
30
29
|
};
|
31
30
|
return m(() => {
|