@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 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
- import { SLIDE_DIRECTION as v } from "../constant/index.js";
5
- import { checkDirection as U } from "../../utils/slide.js";
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 G } from "../Provide/index.js";
8
- import { defaultState as J } from "../../hooks/defineSlide/default.js";
9
- import { createSlidePrivateProvide as K } from "./provide.js";
10
- const le = /* @__PURE__ */ H({
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 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(
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
- ), m(e.direction, r.value, -s.value);
31
- }, p = K({
32
- name: t.name,
30
+ ), v(e.direction, r.value, -l.value);
31
+ }, p = Q({
32
+ name: n.name,
33
33
  itemsInfo: [],
34
- infinite: t.infinite
35
- }), O = () => {
36
- const n = b(J);
37
- return j(t.name, n), n;
38
- }, e = t.name !== M ? G(t.name) : O(), x = () => t.list.slice(e.currentIndex, e.currentIndex + 3), o = t.infinite ? w(x()) : null;
39
- t.infinite && y(
40
- () => t.list,
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
- ), y(() => e.currentIndex, c);
46
- const r = w(), s = g(
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((n, i) => (n += i[e.direction === v.HORIZONTAL ? "width" : "height"], n), 0)
61
+ p.itemsInfo.slice(0, e.currentIndex).reduce((t, i) => (t += i[e.direction === h.HORIZONTAL ? "width" : "height"], t), 0)
50
62
  )
51
- ), P = g(
63
+ ), C = w(
52
64
  () => e.currentIndex === 0 && !e.isNext || e.currentIndex === p.itemsInfo.length - 1 && e.isNext
53
- ), l = { x: 0, y: 0 };
54
- let a = !1;
55
- const D = (n) => {
56
- a = !0, l.x = n.pageX, l.y = n.pageY;
57
- }, { isConsistent: E, checkDirectionConsistent: C, resetCheckDirection: R } = U(e.direction), T = (n) => {
58
- if (!a) return;
59
- const i = n.pageX - l.x, N = n.pageY - l.y, u = e.direction === v.HORIZONTAL ? i : N;
60
- e.isNext = u < 0, !P.value && (C(i, N), E.value && (F(r.value), m(
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(-s.value + u, e.isNext ? -s.value : 0)
64
- ), e.shouldNext = Math.abs(u) > e.judgeValue));
65
- }, h = () => {
66
- e.shouldNext = !1, a = !1, R();
67
- }, A = () => t.infinite ? e.currentIndex === o.value.length - 1 : !1, B = () => {
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(), h();
81
+ return c(), I();
70
82
  e.currentIndex += e.isNext ? 1 : -1, c();
71
- const n = {
83
+ const t = {
72
84
  index: e.currentIndex
73
85
  };
74
- t.infinite && (n.item = t.list[e.currentIndex]), L("switch", n), h(), A() && q(async () => {
75
- (o == null ? void 0 : o.value.length) === t.list.length && t.loadMore && await t.loadMore();
76
- const i = t.list[e.currentIndex + 1];
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 V(() => {
81
- m(e.direction, r.value, -s.value);
82
- }), (n, i) => ($(), Z(
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: d(D, ["prevent"]),
88
- onPointermove: d(T, ["prevent"]),
89
- onPointerup: d(B, ["prevent"])
99
+ onPointerdown: f(E, ["prevent"]),
100
+ onPointermove: f(A, ["prevent"]),
101
+ onPointerup: f(H, ["prevent"])
90
102
  },
91
103
  [
92
- X(
104
+ Y(
93
105
  "div",
94
106
  {
95
107
  class: "loickit-slide-list",
96
- style: Y({
108
+ style: b({
97
109
  // 根据方向设置 flex-direction
98
- flexDirection: f(e).direction === f(v).HORIZONTAL ? "row" : "column"
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
- t.infinite ? k(n.$slots, "default", {
116
+ n.infinite ? k(t.$slots, "default", {
105
117
  key: 1,
106
- cacheList: f(o)
107
- }) : k(n.$slots, "default", { key: 0 })
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
- le as default
131
+ ae as default
120
132
  };
@@ -1,4 +1,4 @@
1
- import { defineComponent as a, ref as l, watch as c, onMounted as m, onBeforeUnmount as p, createElementBlock as u, openBlock as h, createElementVNode as x, renderSlot as v } from "vue";
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(f) {
11
- const i = f, e = w(), r = I(e.name), o = l(), s = l();
12
- if (e.infinite) {
13
- if (typeof i.index != "number")
14
- throw new Error(
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
- const n = {
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(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loickit-v/swiper",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "loickit swiper components for vue",
5
5
  "type": "module",
6
6
  "types": "./dist/types/index.d.ts",