@loickit-v/swiper 0.0.6 → 0.0.7
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/README.md +49 -128
- package/dist/components/Slide/index.vue.js +66 -56
- package/dist/types/components/Slide/index.d.ts +3 -2
- package/dist/types/components/Slide/index.vue.d.ts +3 -2
- package/dist/types/components/types/index.d.ts +1 -1
- package/dist/types/hooks/defineSlide/index.d.ts +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -4,149 +4,70 @@
|
|
4
4
|
|
5
5
|
### LSlide
|
6
6
|
|
7
|
-
|
7
|
+
Slide Component
|
8
8
|
|
9
9
|
#### Props
|
10
10
|
|
11
|
-
-
|
11
|
+
- `name`
|
12
|
+
The unique identifier of the slide, which should be obtained via `defineSlide`.
|
12
13
|
|
13
|
-
|
14
|
+
- `list <Array>`
|
15
|
+
Only effective in `infinite` mode; automatic cached rendering will be performed.
|
14
16
|
|
15
|
-
-
|
16
|
-
|
17
|
-
just avaliable `infinite` mode, the long list of render, will cached by `slotScope.cacheList`
|
18
|
-
|
19
|
-
- loadMore \<Function>
|
20
|
-
|
21
|
-
just avaliable `infinite` mode, when the pointer points to the cacheList end, will trigger.
|
17
|
+
- `loadMore <Function>`
|
18
|
+
Only effective in `infinite` mode; triggered when the sliding pointer points to the end of the list.
|
22
19
|
|
23
20
|
#### Hooks
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
return:
|
64
|
-
|
65
|
-
- name
|
66
|
-
|
67
|
-
the identification of target slide
|
68
|
-
|
69
|
-
- state \<SlideState>
|
70
|
-
|
71
|
-
the slide state
|
72
|
-
|
73
|
-
- useSlide
|
74
|
-
|
75
|
-
return: \<SlideSate>
|
76
|
-
|
77
|
-
use it to get slide state in any child component
|
22
|
+
##### `defineSlide`
|
23
|
+
|
24
|
+
Define a slide.
|
25
|
+
|
26
|
+
Parameters:
|
27
|
+
|
28
|
+
- `provideKey <string>`
|
29
|
+
Set a unique identifier for the current slide.
|
30
|
+
|
31
|
+
Returns:
|
32
|
+
`[createSlide, useSlide]`
|
33
|
+
|
34
|
+
- `createSlide`
|
35
|
+
Create a slide state; register the `l-slide` component through its return value.
|
36
|
+
Parameters:
|
37
|
+
|
38
|
+
- `initial <SlideState>`
|
39
|
+
- `direction <SLIDE_DIRECTION>` _optional_
|
40
|
+
Sliding direction.
|
41
|
+
Default value: SLIDE_DIRECTION.HORIZONTAL
|
42
|
+
- `currentIndex <number>` _optional_
|
43
|
+
Pointer.
|
44
|
+
Default value: 0
|
45
|
+
- `duration <number>` _optional_
|
46
|
+
Animation duration for slide switching.
|
47
|
+
Default value: 300 (ms)
|
48
|
+
- `infinite <boolean>` _optional_
|
49
|
+
Whether to enable infinite mode.
|
50
|
+
Default value: false
|
51
|
+
Return value:
|
52
|
+
- `name`
|
53
|
+
The unique identifier of the slide, which should be assigned to the `name` prop of `l-slide`.
|
54
|
+
- `state <SlideState>`
|
55
|
+
The slide state.
|
56
|
+
|
57
|
+
- `useSlide`
|
58
|
+
Return value: `<SlideState>`
|
59
|
+
Use it to get the slide state in any child component.
|
78
60
|
|
79
61
|
#### Slot
|
80
62
|
|
81
63
|
**default**
|
82
64
|
|
83
|
-
-
|
84
|
-
|
85
|
-
the cache data of list, just cache 3, just avaliable `infinite` mode
|
65
|
+
- `cacheList`
|
66
|
+
Only effective in `infinite` mode; caches the list data.
|
86
67
|
|
87
68
|
### LSlideItem
|
88
69
|
|
89
70
|
#### Props
|
90
71
|
|
91
|
-
-
|
92
|
-
|
93
|
-
the index of this slide item, required when `infinite` mode
|
94
|
-
|
95
|
-
### Usage
|
96
|
-
|
97
|
-
```vue
|
98
|
-
<script setup lang="ts">
|
99
|
-
import {
|
100
|
-
defineSlide,
|
101
|
-
LSlide,
|
102
|
-
LSlideItem,
|
103
|
-
SLIDE_DIRECTION
|
104
|
-
} from '@loickit-v/swiper';
|
105
|
-
|
106
|
-
defineOptions({ name: 'App' });
|
107
|
-
|
108
|
-
const [createSlide] = defineSlide('one');
|
109
|
-
|
110
|
-
const oneSlide = createSlide({
|
111
|
-
currentIndex: 1
|
112
|
-
});
|
113
|
-
|
114
|
-
const [createSlide2] = defineSlide('two');
|
115
|
-
|
116
|
-
const twoSlide = createSlide2({
|
117
|
-
direction: SLIDE_DIRECTION.VERTICAL
|
118
|
-
});
|
119
|
-
|
120
|
-
const oneToTwo = () => {
|
121
|
-
oneSlide.state.currentIndex = 2;
|
122
|
-
};
|
123
|
-
</script>
|
124
|
-
|
125
|
-
<template>
|
126
|
-
<LSlide :name="oneSlide.name">
|
127
|
-
<LSlideItem style="background-color: red; width: 30%">1</LSlideItem>
|
128
|
-
<LSlideItem style="background-color: blue">2</LSlideItem>
|
129
|
-
<LSlideItem style="background-color: green">
|
130
|
-
<LSlide :name="twoSlide.name">
|
131
|
-
<LSlideItem style="background-color: pink; height: 30%">1</LSlideItem>
|
132
|
-
<LSlideItem style="background-color: orange">2</LSlideItem>
|
133
|
-
<LSlideItem style="background-color: yellow">3</LSlideItem>
|
134
|
-
</LSlide>
|
135
|
-
</LSlideItem>
|
136
|
-
</LSlide>
|
137
|
-
|
138
|
-
<p>one currentIndex: {{ oneSlide.state.currentIndex }}</p>
|
139
|
-
<p>two currentIndex: {{ twoSlide.state.currentIndex }}</p>
|
140
|
-
|
141
|
-
<button @click="oneToTwo">click to two slide</button>
|
142
|
-
</template>
|
143
|
-
|
144
|
-
<style lang="scss">
|
145
|
-
body,
|
146
|
-
#app {
|
147
|
-
background-color: #ccc;
|
148
|
-
height: 800px;
|
149
|
-
width: 800px;
|
150
|
-
}
|
151
|
-
</style>
|
152
|
-
```
|
72
|
+
- `index <number>` _optional_
|
73
|
+
Must be passed in `infinite` mode, used for dynamic rendering calculation.
|
@@ -1,99 +1,109 @@
|
|
1
|
-
import { defineComponent as
|
2
|
-
import { u_setStyle as
|
3
|
-
import { u_setTransform as m, u_setFlush as
|
1
|
+
import { defineComponent as H, ref as w, watch as y, computed as g, onMounted as V, createElementBlock as Z, openBlock as $, withModifiers as d, createElementVNode as X, normalizeStyle as Y, unref as f, renderSlot as k, reactive as b, provide as j, nextTick as q } from "vue";
|
2
|
+
import { u_setStyle as z } from "@likcheung/shared";
|
3
|
+
import { u_setTransform as m, u_setFlush as F } from "../../utils/index.js";
|
4
4
|
import { SLIDE_DIRECTION as v } from "../constant/index.js";
|
5
|
-
import { checkDirection as
|
6
|
-
import { COMMON_SLIDE_PROVIDE_NAME as
|
7
|
-
import { useSlideState as
|
8
|
-
import { defaultState as
|
9
|
-
import { useSlidePrivateProvide as
|
10
|
-
const
|
5
|
+
import { checkDirection as U } from "../../utils/slide.js";
|
6
|
+
import { COMMON_SLIDE_PROVIDE_NAME as M } from "../constant/private.js";
|
7
|
+
import { useSlideState as G } from "../Provide/index.js";
|
8
|
+
import { defaultState as J } from "../../hooks/defineSlide/default.js";
|
9
|
+
import { useSlidePrivateProvide as K } from "./provide.js";
|
10
|
+
const le = /* @__PURE__ */ H({
|
11
11
|
name: "LSlide",
|
12
12
|
__name: "index",
|
13
13
|
props: {
|
14
|
-
name: { default:
|
14
|
+
name: { default: M },
|
15
|
+
infinite: { type: Boolean },
|
15
16
|
list: { default: () => [] },
|
16
17
|
loadMore: {}
|
17
18
|
},
|
18
19
|
emits: ["switch"],
|
19
|
-
setup(S, { emit:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
setup(S, { emit: _ }) {
|
21
|
+
var I;
|
22
|
+
const t = S;
|
23
|
+
if (t.infinite && !((I = t.list) != null && I.length))
|
24
|
+
throw new Error("list is required when infinite is true");
|
25
|
+
const L = _, c = () => {
|
26
|
+
z(
|
27
|
+
r.value,
|
28
|
+
"transition-duration",
|
29
|
+
`${e.duration}ms`
|
30
|
+
), m(e.direction, r.value, -s.value);
|
31
|
+
}, p = K({
|
32
|
+
name: t.name,
|
24
33
|
itemsInfo: []
|
25
|
-
}),
|
26
|
-
const
|
27
|
-
return
|
28
|
-
})(),
|
29
|
-
|
30
|
-
() =>
|
34
|
+
}), O = () => {
|
35
|
+
const n = b(J);
|
36
|
+
return j(t.name, n), n;
|
37
|
+
}, e = t.name !== M ? G(t.name) : O(), x = () => t.list.slice(e.currentIndex, e.currentIndex + 3), o = t.infinite ? w(x()) : null;
|
38
|
+
t.infinite && y(
|
39
|
+
() => t.list,
|
31
40
|
() => {
|
32
|
-
o.value =
|
41
|
+
o.value = x();
|
33
42
|
},
|
34
43
|
{ once: !0 }
|
35
|
-
),
|
36
|
-
const r =
|
44
|
+
), y(() => e.currentIndex, c);
|
45
|
+
const r = w(), s = g(
|
37
46
|
() => (
|
38
47
|
// 通过收集所有 slide-item 的宽和高, 叠加计算
|
39
|
-
|
48
|
+
p.itemsInfo.slice(0, e.currentIndex).reduce((n, i) => (n += i[e.direction === v.HORIZONTAL ? "width" : "height"], n), 0)
|
40
49
|
)
|
41
|
-
),
|
42
|
-
() => e.currentIndex === 0 && !e.isNext || e.currentIndex ===
|
50
|
+
), P = g(
|
51
|
+
() => e.currentIndex === 0 && !e.isNext || e.currentIndex === p.itemsInfo.length - 1 && e.isNext
|
43
52
|
), l = { x: 0, y: 0 };
|
44
|
-
let
|
45
|
-
const
|
46
|
-
|
47
|
-
}, { isConsistent:
|
48
|
-
if (!
|
49
|
-
const i =
|
50
|
-
e.isNext =
|
53
|
+
let a = !1;
|
54
|
+
const D = (n) => {
|
55
|
+
a = !0, l.x = n.pageX, l.y = n.pageY;
|
56
|
+
}, { isConsistent: E, checkDirectionConsistent: C, resetCheckDirection: R } = U(e.direction), T = (n) => {
|
57
|
+
if (!a) return;
|
58
|
+
const i = n.pageX - l.x, N = n.pageY - l.y, u = e.direction === v.HORIZONTAL ? i : N;
|
59
|
+
e.isNext = u < 0, !P.value && (C(i, N), E.value && (F(r.value), m(
|
51
60
|
e.direction,
|
52
61
|
r.value,
|
53
|
-
Math.min(-s.value +
|
54
|
-
), e.shouldNext = Math.abs(
|
62
|
+
Math.min(-s.value + u, e.isNext ? -s.value : 0)
|
63
|
+
), e.shouldNext = Math.abs(u) > e.judgeValue));
|
55
64
|
}, h = () => {
|
56
|
-
e.shouldNext = !1,
|
57
|
-
},
|
65
|
+
e.shouldNext = !1, a = !1, R();
|
66
|
+
}, A = () => t.infinite ? e.currentIndex === o.value.length - 1 : !1, B = () => {
|
58
67
|
if (!e.shouldNext)
|
59
|
-
return
|
60
|
-
e.currentIndex += e.isNext ? 1 : -1,
|
68
|
+
return c(), h();
|
69
|
+
e.currentIndex += e.isNext ? 1 : -1, c();
|
70
|
+
const n = {
|
61
71
|
index: e.currentIndex
|
62
|
-
}
|
63
|
-
|
64
|
-
(o == null ? void 0 : o.value.length) ===
|
65
|
-
const
|
66
|
-
|
72
|
+
};
|
73
|
+
t.infinite && (n.item = t.list[e.currentIndex]), L("switch", n), h(), A() && q(async () => {
|
74
|
+
(o == null ? void 0 : o.value.length) === t.list.length && t.loadMore && await t.loadMore();
|
75
|
+
const i = t.list[e.currentIndex + 1];
|
76
|
+
i && o.value.push(i);
|
67
77
|
});
|
68
78
|
};
|
69
79
|
return V(() => {
|
70
80
|
m(e.direction, r.value, -s.value);
|
71
|
-
}), (
|
81
|
+
}), (n, i) => ($(), Z(
|
72
82
|
"div",
|
73
83
|
{
|
74
84
|
class: "loickit-slide",
|
75
85
|
id: "loickit-slide",
|
76
|
-
onPointerdown:
|
77
|
-
onPointermove:
|
78
|
-
onPointerup:
|
86
|
+
onPointerdown: d(D, ["prevent"]),
|
87
|
+
onPointermove: d(T, ["prevent"]),
|
88
|
+
onPointerup: d(B, ["prevent"])
|
79
89
|
},
|
80
90
|
[
|
81
|
-
|
91
|
+
X(
|
82
92
|
"div",
|
83
93
|
{
|
84
94
|
class: "loickit-slide-list",
|
85
|
-
style:
|
95
|
+
style: Y({
|
86
96
|
// 根据方向设置 flex-direction
|
87
|
-
flexDirection:
|
97
|
+
flexDirection: f(e).direction === f(v).HORIZONTAL ? "row" : "column"
|
88
98
|
}),
|
89
99
|
ref_key: "slideListRef",
|
90
100
|
ref: r
|
91
101
|
},
|
92
102
|
[
|
93
|
-
|
103
|
+
t.infinite ? k(n.$slots, "default", {
|
94
104
|
key: 1,
|
95
|
-
cacheList:
|
96
|
-
}) :
|
105
|
+
cacheList: f(o)
|
106
|
+
}) : k(n.$slots, "default", { key: 0 })
|
97
107
|
],
|
98
108
|
4
|
99
109
|
/* STYLE */
|
@@ -105,5 +115,5 @@ const oe = /* @__PURE__ */ T({
|
|
105
115
|
}
|
106
116
|
});
|
107
117
|
export {
|
108
|
-
|
118
|
+
le as default
|
109
119
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export declare const LSlide: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: {
|
1
|
+
export declare const LSlide: <T = any>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: {
|
2
2
|
attrs: any;
|
3
3
|
emit: (e: "switch", value: import("../types/index.js").SlideSwitchEvent) => void;
|
4
4
|
slots: {
|
@@ -10,8 +10,9 @@ export declare const LSlide: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_s
|
|
10
10
|
props: {
|
11
11
|
readonly onSwitch?: ((value: import("../types/index.js").SlideSwitchEvent) => any) | undefined;
|
12
12
|
name?: import("../types/private.js").SlideNameType | undefined;
|
13
|
+
infinite?: boolean | undefined;
|
13
14
|
list?: T[] | undefined;
|
14
|
-
loadMore?: (() =>
|
15
|
+
loadMore?: (() => any) | undefined;
|
15
16
|
} & import("vue").PublicProps;
|
16
17
|
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
|
17
18
|
attrs: any;
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import type { SlideNameType } from '../types/private';
|
2
2
|
import type { SlideSwitchEvent } from '../types';
|
3
|
-
declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
3
|
+
declare const _default: <T = any>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
4
4
|
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
|
5
5
|
readonly onSwitch?: ((value: SlideSwitchEvent) => any) | undefined;
|
6
6
|
} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onSwitch"> & {
|
7
7
|
name?: SlideNameType;
|
8
|
+
infinite?: boolean;
|
8
9
|
list?: T[];
|
9
|
-
loadMore?: () =>
|
10
|
+
loadMore?: () => any;
|
10
11
|
} & Partial<{}>> & import("vue").PublicProps;
|
11
12
|
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
|
12
13
|
attrs: any;
|