@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 CHANGED
@@ -4,149 +4,70 @@
4
4
 
5
5
  ### LSlide
6
6
 
7
- the Slide Component
7
+ Slide Component
8
8
 
9
9
  #### Props
10
10
 
11
- - name
11
+ - `name`
12
+ The unique identifier of the slide, which should be obtained via `defineSlide`.
12
13
 
13
- identification of this slide, get by `defineSlide`
14
+ - `list <Array>`
15
+ Only effective in `infinite` mode; automatic cached rendering will be performed.
14
16
 
15
- - list \<Array>
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
- **defineSlide**
26
-
27
- define a slide object
28
-
29
- argument:
30
-
31
- - provideKey \<string>
32
-
33
- the identification of target slide
34
-
35
- return \[createSlide, useSlide]
36
-
37
- - createSlide
38
-
39
- create a slide states, use return value to registe a slide
40
-
41
- params:
42
-
43
- - initial \<SlideState>
44
-
45
- - direction \<SLIDE\*DIRECTION> _optional_
46
-
47
- default: SLIDE_DIRECTION.HORIZONTAL
48
-
49
- direction
50
-
51
- - currentIndex \<number> _optional_
52
-
53
- pointer
54
-
55
- - duration \<number> _optional_
56
-
57
- slide switch animation duration
58
-
59
- - infinite \<boolean> `infinite` _optional_
60
-
61
- mode enable
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
- - cacheList
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
- - index \<number> optional
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 T, reactive as A, provide as H, ref as N, watch as k, computed as _, onMounted as V, createElementBlock as Z, openBlock as $, withModifiers as f, createElementVNode as B, normalizeStyle as X, unref as c, renderSlot as y, nextTick as Y } from "vue";
2
- import { u_setStyle as b } from "@likcheung/shared";
3
- import { u_setTransform as m, u_setFlush as j } from "../../utils/index.js";
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 z } from "../../utils/slide.js";
6
- import { COMMON_SLIDE_PROVIDE_NAME as O } from "../constant/private.js";
7
- import { useSlideState as F } from "../Provide/index.js";
8
- import { defaultState as U } from "../../hooks/defineSlide/default.js";
9
- import { useSlidePrivateProvide as q } from "./provide.js";
10
- const oe = /* @__PURE__ */ T({
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: O },
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: g }) {
20
- const n = S, w = g, a = () => {
21
- b(r.value, "transition-duration", `${e.duration}ms`), m(e.direction, r.value, -s.value);
22
- }, x = q({
23
- name: n.name,
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
- }), e = n.name !== O ? F(n.name) : (() => {
26
- const t = A(U);
27
- return H(n.name, t), t;
28
- })(), p = () => n.list.slice(e.currentIndex, e.currentIndex + 3), o = e.infinite ? N(p()) : null;
29
- e.infinite && k(
30
- () => n.list,
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 = p();
41
+ o.value = x();
33
42
  },
34
43
  { once: !0 }
35
- ), k(() => e.currentIndex, a);
36
- const r = N(), s = _(
44
+ ), y(() => e.currentIndex, c);
45
+ const r = w(), s = g(
37
46
  () => (
38
47
  // 通过收集所有 slide-item 的宽和高, 叠加计算
39
- x.itemsInfo.slice(0, e.currentIndex).reduce((t, i) => (t += i[e.direction === v.HORIZONTAL ? "width" : "height"], t), 0)
48
+ p.itemsInfo.slice(0, e.currentIndex).reduce((n, i) => (n += i[e.direction === v.HORIZONTAL ? "width" : "height"], n), 0)
40
49
  )
41
- ), D = _(
42
- () => e.currentIndex === 0 && !e.isNext || e.currentIndex === x.itemsInfo.length - 1 && e.isNext
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 u = !1;
45
- const L = (t) => {
46
- u = !0, l.x = t.pageX, l.y = t.pageY;
47
- }, { isConsistent: M, checkDirectionConsistent: P, resetCheckDirection: C } = z(e.direction), E = (t) => {
48
- if (!u) return;
49
- const i = t.pageX - l.x, I = t.pageY - l.y, d = e.direction === v.HORIZONTAL ? i : I;
50
- e.isNext = d < 0, !D.value && (P(i, I), M.value && (j(r.value), m(
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 + d, e.isNext ? -s.value : 0)
54
- ), e.shouldNext = Math.abs(d) > e.judgeValue));
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, u = !1, C();
57
- }, R = () => {
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 a(), h();
60
- e.currentIndex += e.isNext ? 1 : -1, a(), w("switch", {
68
+ return c(), h();
69
+ e.currentIndex += e.isNext ? 1 : -1, c();
70
+ const n = {
61
71
  index: e.currentIndex
62
- }), h(), e.infinite && e.currentIndex === o.value.length - 1 && Y(async () => {
63
- var i;
64
- (o == null ? void 0 : o.value.length) === n.list.length && await ((i = n.loadMore) == null ? void 0 : i.call(n));
65
- const t = n.list[e.currentIndex + 1];
66
- t && o.value.push(t);
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
- }), (t, i) => ($(), Z(
81
+ }), (n, i) => ($(), Z(
72
82
  "div",
73
83
  {
74
84
  class: "loickit-slide",
75
85
  id: "loickit-slide",
76
- onPointerdown: f(L, ["prevent"]),
77
- onPointermove: f(E, ["prevent"]),
78
- onPointerup: f(R, ["prevent"])
86
+ onPointerdown: d(D, ["prevent"]),
87
+ onPointermove: d(T, ["prevent"]),
88
+ onPointerup: d(B, ["prevent"])
79
89
  },
80
90
  [
81
- B(
91
+ X(
82
92
  "div",
83
93
  {
84
94
  class: "loickit-slide-list",
85
- style: X({
95
+ style: Y({
86
96
  // 根据方向设置 flex-direction
87
- flexDirection: c(e).direction === c(v).HORIZONTAL ? "row" : "column"
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
- c(e).infinite ? y(t.$slots, "default", {
103
+ t.infinite ? k(n.$slots, "default", {
94
104
  key: 1,
95
- cacheList: c(o)
96
- }) : y(t.$slots, "default", { key: 0 })
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
- oe as default
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?: (() => Promise<T>) | undefined;
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?: () => Promise<T>;
10
+ loadMore?: () => any;
10
11
  } & Partial<{}>> & import("vue").PublicProps;
11
12
  expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
12
13
  attrs: any;
@@ -6,8 +6,8 @@ export type SlideState = {
6
6
  currentIndex: number;
7
7
  shouldNext: boolean;
8
8
  isNext: boolean;
9
- infinite?: boolean;
10
9
  };
11
10
  export type SlideSwitchEvent = {
12
11
  index: number;
12
+ item?: any;
13
13
  };
@@ -8,7 +8,6 @@ export declare const defineSlide: (provideKey: SlideNameType) => readonly [(init
8
8
  currentIndex: number;
9
9
  shouldNext: boolean;
10
10
  isNext: boolean;
11
- infinite?: boolean | undefined;
12
11
  };
13
12
  name: symbol;
14
13
  }, () => SlideState];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loickit-v/swiper",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "loickit swiper components for vue",
5
5
  "type": "module",
6
6
  "types": "./dist/types/index.d.ts",