@fox-js/navigation 4.0.1-1 → 4.0.1-11

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/dist/index.esm.js CHANGED
@@ -1,18 +1,18 @@
1
- import { defineComponent as T, resolveComponent as b, openBlock as y, createBlock as M, ref as _, unref as w, computed as $, createElementBlock as z, createElementVNode as B, normalizeStyle as S, renderSlot as X, reactive as j, onMounted as A, onUnmounted as U, watchEffect as V, normalizeClass as R } from "vue";
1
+ import { defineComponent as P, resolveComponent as S, openBlock as L, createBlock as R, withCtx as C, createVNode as H, Transition as G, resolveDynamicComponent as J, unref as N, computed as O, createElementBlock as K, createElementVNode as Q, normalizeStyle as B, renderSlot as Z, reactive as tt, onMounted as et, onBeforeUnmount as nt, watch as ot, normalizeClass as it } from "vue";
2
+ import { OperationType as b } from "@fox-js/fox";
2
3
  /*!
3
- * @fox-js/navigation v4.0.1-0 Mon Sep 26 2022 15:23:38 GMT+0800 (中国标准时间)
4
+ * @fox-js/navigation v4.0.1-10 Tue Mar 12 2024 21:40:43 GMT+0800 (中国标准时间)
4
5
  */
5
- const Y = /* @__PURE__ */ T({
6
+ const st = /* @__PURE__ */ P({
6
7
  __name: "index",
7
8
  props: {
8
- routerViewName: null,
9
- transition: { type: [Object, Boolean], default: !1 }
9
+ routerViewName: {},
10
+ transition: { type: [Function, Boolean], default: !1 }
10
11
  },
11
12
  setup(t) {
12
- const e = t;
13
- return (n, s) => {
14
- const a = b("fox-router-view");
15
- return y(), M(a, {
13
+ return (e, n) => {
14
+ const o = S("fox-router-view");
15
+ return L(), R(o, {
16
16
  class: "fox-card-navigator",
17
17
  "view-class": "fox-card-navigator__item",
18
18
  "view-active-class": "fox-card-navigator__item-active",
@@ -24,56 +24,95 @@ const Y = /* @__PURE__ */ T({
24
24
  }, null, 8, ["transition", "name"]);
25
25
  };
26
26
  }
27
- });
28
- const k = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
27
+ }), at = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
28
+ __proto__: null,
29
+ default: st
30
+ }, Symbol.toStringTag, { value: "Module" })), rt = /* @__PURE__ */ P({
31
+ __name: "index",
32
+ props: {
33
+ routerViewName: {},
34
+ transition: { type: [Function, Boolean], default: !0 }
35
+ },
36
+ setup(t) {
37
+ return (e, n) => {
38
+ const o = S("fox-router-view");
39
+ return L(), R(o, {
40
+ transition: !1,
41
+ multi: !1,
42
+ name: e.routerViewName
43
+ }, {
44
+ default: C(({ Component: a }) => [
45
+ H(G, { name: "fox-default-navigator__trans" }, {
46
+ default: C(() => [
47
+ (L(), R(J(a)))
48
+ ]),
49
+ _: 2
50
+ }, 1024)
51
+ ]),
52
+ _: 1
53
+ }, 8, ["name"]);
54
+ };
55
+ }
56
+ }), ct = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
29
57
  __proto__: null,
30
- default: Y
31
- }, Symbol.toStringTag, { value: "Module" })), P = 10;
32
- function q(t, e) {
33
- return t > e && t > P ? "horizontal" : e > t && e > P ? "vertical" : "";
58
+ default: rt
59
+ }, Symbol.toStringTag, { value: "Module" })), Y = 10;
60
+ function lt(t, e) {
61
+ return t > e && t > Y ? "horizontal" : e > t && e > Y ? "vertical" : "";
34
62
  }
35
- function W() {
36
- const t = _(0), e = _(0), n = _(0), s = _(0), a = _(0), v = _(0), p = _(0), m = _(0), d = _(0), c = _(0), o = _(""), i = () => o.value === "vertical", h = () => o.value === "horizontal", u = () => {
37
- p.value = 0, m.value = 0, d.value = 0, c.value = 0, o.value = "", n.value = 0;
63
+ function F() {
64
+ const t = {
65
+ startX: 0,
66
+ startY: 0,
67
+ startTime: 0,
68
+ duration: 0,
69
+ moveX: 0,
70
+ moveY: 0,
71
+ deltaX: 0,
72
+ deltaY: 0,
73
+ offsetX: 0,
74
+ offsetY: 0,
75
+ direction: ""
76
+ }, e = () => t.direction === "vertical", n = () => t.direction === "horizontal", o = () => {
77
+ t.deltaX = 0, t.deltaY = 0, t.offsetX = 0, t.offsetY = 0, t.direction = "", t.startTime = 0;
38
78
  };
39
79
  return {
40
- move: (r) => {
41
- const g = r.touches[0];
42
- p.value = g.clientX - t.value, m.value = g.clientY - e.value, a.value = g.clientX, v.value = g.clientY, d.value = Math.abs(p.value), c.value = Math.abs(m.value), s.value = Date.now() - n.value, o.value || (o.value = q(d.value, c.value));
80
+ move: (h) => {
81
+ if (h.touches) {
82
+ const c = h.touches[0];
83
+ t.deltaX = c.clientX - t.startX, t.deltaY = c.clientY - t.startY, t.moveX = c.clientX, t.moveY = c.clientY;
84
+ } else
85
+ t.deltaX = h.clientX - t.startX, t.deltaY = h.clientY - t.startY, t.moveX = h.clientX, t.moveY = h.clientY;
86
+ t.offsetX = Math.abs(t.deltaX), t.offsetY = Math.abs(t.deltaY), t.duration = Date.now() - t.startTime, t.direction || (t.direction = lt(t.offsetX, t.offsetY));
43
87
  },
44
- start: (r) => {
45
- u(), t.value = r.touches[0].clientX, e.value = r.touches[0].clientY, n.value = Date.now();
88
+ start: (h) => {
89
+ if (o(), h.touches) {
90
+ const c = h.touches[0];
91
+ t.startX = c.clientX, t.startY = c.clientY;
92
+ } else
93
+ t.startX = h.clientX, t.startY = h.clientY;
94
+ t.startTime = Date.now();
46
95
  },
47
- reset: u,
48
- startX: t,
49
- startY: e,
50
- startTime: n,
51
- duration: s,
52
- moveX: a,
53
- moveY: v,
54
- deltaX: p,
55
- deltaY: m,
56
- offsetX: d,
57
- offsetY: c,
58
- direction: o,
59
- isVertical: i,
60
- isHorizontal: h
96
+ reset: o,
97
+ isVertical: e,
98
+ isHorizontal: n,
99
+ state: t
61
100
  };
62
101
  }
63
- function F(t) {
102
+ function ut(t) {
64
103
  return t === window;
65
104
  }
66
- const H = (t) => {
67
- const e = w(t);
68
- if (F(e)) {
69
- const n = e.innerWidth, s = e.innerHeight;
105
+ const dt = (t) => {
106
+ const e = N(t);
107
+ if (ut(e)) {
108
+ const n = e.innerWidth, o = e.innerHeight;
70
109
  return {
71
110
  top: 0,
72
111
  left: 0,
73
112
  right: n,
74
- bottom: s,
113
+ bottom: o,
75
114
  width: n,
76
- height: s
115
+ height: o
77
116
  };
78
117
  }
79
118
  return e && e.getBoundingClientRect ? e.getBoundingClientRect() : {
@@ -84,253 +123,359 @@ const H = (t) => {
84
123
  width: 0,
85
124
  height: 0
86
125
  };
87
- }, G = 15, J = 300, K = 200;
88
- function Q(t) {
126
+ }, ft = 15, ht = 300, mt = 200;
127
+ function pt(t) {
89
128
  t.stopPropagation();
90
129
  }
91
- function Z(t, e) {
92
- (typeof t.cancelable != "boolean" || t.cancelable) && t.preventDefault(), e && Q(t);
130
+ function gt(t, e) {
131
+ (typeof t.cancelable != "boolean" || t.cancelable) && t.preventDefault(), e && pt(t);
93
132
  }
94
- function tt(t, e) {
95
- return t = Math.abs(t / e) / 3e-3 * (t < 0 ? -1 : 1), t;
133
+ function vt(t, e, n = 1) {
134
+ return t = Math.abs(t / e) / 3e-3 * (t < 0 ? -1 : 1), t * n;
96
135
  }
97
- function E(t, e = 0, n, s = K) {
98
- n === "end" ? t.style.transition = `transform ${s}ms cubic-bezier(0.17, 0.89, 0.45, 1)` : t.style.transition = "transform 0ms cubic-bezier(0.17, 0.89, 0.45, 1)", t.style.transform = `translate3d(${e}px, 0, 0)`;
136
+ function I(t, e = 0, n, o = mt) {
137
+ n === "end" ? t.style.transition = `transform ${o}ms cubic-bezier(0.17, 0.89, 0.45, 1)` : t.style.transition = "transform 0ms cubic-bezier(0.17, 0.89, 0.45, 1)", t.style.transform = `translate3d(${e}px, 0, 0)`;
99
138
  }
100
- const L = /* @__PURE__ */ new WeakMap();
101
- function et(t, e, n, s = 1e3) {
102
- const a = {
139
+ const V = /* @__PURE__ */ new WeakMap();
140
+ function _t(t, e, n, o, a = 500, d, h = 1e3) {
141
+ const c = {
103
142
  active: !0,
104
143
  startDistance: 0,
105
144
  scrollDistance: 0,
106
145
  scrollTime: 0,
107
146
  moving: !1,
108
147
  transitionEndTrigger: null
109
- }, v = t.previousSibling, p = W(), m = (h, u, f, l) => {
110
- let r = u + a.startDistance;
111
- if (f === "end") {
112
- const g = H(h);
113
- let x = g.width / 3;
114
- r < x ? r = 0 : r = g.width, l && l > 0 && (a.transitionEndTrigger = () => {
115
- a.moving = !1, n && h.classList.remove(n);
116
- }), E(h, r, "end", l), v && E(v, 0, "", 0), r > 0 && typeof e == "function" && e();
148
+ }, v = t.previousSibling, m = F(), p = (s, g, w, x) => {
149
+ let T = g + c.startDistance;
150
+ if (w === "end") {
151
+ const r = dt(s);
152
+ let y = r.width * e;
153
+ T < y ? T = 0 : T = r.width;
154
+ let _ = !1;
155
+ x && x > 0 && (_ = !0, c.transitionEndTrigger = () => {
156
+ c.moving = !1, d && s.classList.remove(d), T > 0 && typeof o == "function" && o();
157
+ }), I(s, T, "end", x), v && I(v, 0, "", 0), !_ && T > 0 && typeof o == "function" && (c.moving = !1, o());
117
158
  } else
118
- r < 0 && (r = 0), E(h, r, "", 0);
119
- }, d = () => {
120
- t.style.transform = "", t.style.transition = "", v && (v.style.transform = "", v.style.transition = ""), a.transitionEndTrigger && (a.transitionEndTrigger(), a.transitionEndTrigger = null);
121
- }, c = (h) => {
122
- if (p.start(h), a.moving) {
123
- const u = t, { transform: f } = window.getComputedStyle(u);
124
- a.scrollDistance = +f.slice(7, f.length - 1).split(", ")[5];
159
+ T < 0 && (T = 0), I(s, T, "", 0);
160
+ }, i = () => {
161
+ t.style.transform = "", t.style.transition = "", c.transitionEndTrigger ? (c.transitionEndTrigger(), c.transitionEndTrigger = null, v && setTimeout(() => {
162
+ v && (v.style.transform = "", v.style.transition = "");
163
+ }, a)) : v && (v.style.transform = "", v.style.transition = "");
164
+ }, u = /^matrix\((.+)\)$/, f = (s) => {
165
+ if (m.start(s), c.scrollDistance = 0, c.moving) {
166
+ const g = t, { transform: w } = window.getComputedStyle(g);
167
+ if (w) {
168
+ const x = u.exec(w);
169
+ if (x) {
170
+ const r = x[1].split(/,\s*/);
171
+ c.scrollDistance = +r[4];
172
+ }
173
+ }
125
174
  }
126
- n && t.classList.add(n), a.startDistance = a.scrollDistance, a.transitionEndTrigger = null, a.moving = !0;
127
- }, o = (h) => {
128
- if (a.moving = !0, p.move(h), p.isVertical()) {
129
- Z(h, !0);
175
+ d && t.classList.add(d), c.startDistance = c.scrollDistance, c.transitionEndTrigger = null, c.moving = !0;
176
+ }, E = (s) => {
177
+ c.moving = !0, m.move(s), !m.isVertical() && (gt(s, !0), p(t, m.state.deltaX, "", 0));
178
+ }, l = () => {
179
+ if (m.isVertical()) {
180
+ p(t, 0, "end", h);
130
181
  return;
131
182
  }
132
- m(t, p.deltaX.value, "", 0);
133
- }, i = () => {
134
- const h = p.deltaX.value;
135
- if (h == 0) {
136
- n && t.classList.remove(n);
183
+ const s = m.state.deltaX;
184
+ if (s === 0) {
185
+ d && t.classList.remove(d), c.moving = !1;
137
186
  return;
138
187
  }
139
- const u = p.duration.value;
140
- if (u < J && Math.abs(h) > G) {
141
- const l = tt(h, u);
142
- m(t, l, "end", s);
188
+ const g = m.state.duration;
189
+ if (g < ht && Math.abs(s) > ft) {
190
+ const x = vt(s, g, n);
191
+ p(t, x, "end", h);
143
192
  } else
144
- m(t, h, "end", s);
193
+ p(t, s, "end", h);
145
194
  };
146
- t.addEventListener("transitionend", d), t.addEventListener("touchstart", c), t.addEventListener("touchmove", o), t.addEventListener("touchend", i), t.addEventListener("touchcancel", i), L.set(t, {
147
- state: a,
148
- transitionend: d,
149
- touchstart: c,
150
- touchmove: o,
151
- touchend: i,
152
- touchcancel: i
195
+ t.addEventListener("transitionend", i), t.addEventListener("touchstart", f), t.addEventListener("touchmove", E), t.addEventListener("touchend", l), t.addEventListener("touchcancel", l), V.set(t, {
196
+ state: c,
197
+ transitionend: i,
198
+ touchstart: f,
199
+ touchmove: E,
200
+ touchend: l,
201
+ touchcancel: l
153
202
  });
154
203
  }
155
- function nt(t) {
156
- const e = L.get(t);
157
- e && (L.delete(t), t.addEventListener("transitionend", e.transitionend), t.addEventListener("touchstart", e.touchstart), t.addEventListener("touchmove", e.touchmove), t.addEventListener("touchend", e.touchend), t.addEventListener("touchcancel", e.touchcancel));
204
+ function wt(t) {
205
+ const e = V.get(t);
206
+ e && (V.delete(t), t.addEventListener("transitionend", e.transitionend), t.addEventListener("touchstart", e.touchstart), t.addEventListener("touchmove", e.touchmove), t.addEventListener("touchend", e.touchend), t.addEventListener("touchcancel", e.touchcancel));
158
207
  }
159
- const ot = /* @__PURE__ */ T({
208
+ const yt = /* @__PURE__ */ P({
160
209
  __name: "index",
161
210
  props: {
162
211
  dragRemove: { type: Boolean, default: !0 },
163
- removePage: null,
164
- routerViewName: null,
165
- viewTag: { default: "div" },
166
- transition: { type: [Object, Boolean], default: !0 }
212
+ removeViewPage: {},
213
+ removeMoveRatio: { default: 0.5 },
214
+ momentumReduceRatio: { default: 1 },
215
+ removeViewPageDuration: { default: 500 },
216
+ routerViewName: {},
217
+ viewTag: { type: [Function, String], default: "div" },
218
+ transition: { type: [Function, Boolean], default: !0 },
219
+ viewClass: { type: [Function, String], default: "fox-root-navigator__item" }
167
220
  },
168
221
  setup(t) {
169
222
  const e = t;
170
- function n(c) {
171
- return (c.params && c.params.animationType) ?? "slide";
223
+ let n = null, o = null;
224
+ function a(i) {
225
+ return (i.params && i.params.animationType) ?? "slide";
172
226
  }
173
- const s = (c, o, i, h) => {
174
- if (i.opsType === 3 || o) {
175
- const u = n(i);
176
- if (u === "pop" && o)
227
+ const d = (i, u, f, E) => {
228
+ if (f.opsType === b.Append || u) {
229
+ const l = a(f), s = u ? "show" : "enter";
230
+ if (s === "show" && (l === "pop" || o !== "leave" || (n ? a(n) : "") === "pop"))
177
231
  return;
178
- const f = o ? "show" : "enter", l = `fox-root-navigator__${u}-${f}-from`, r = `fox-root-navigator__${u}-${f}-active`;
179
- c.classList.add(l), c.classList.add(r);
232
+ s === "enter" && (n = f, o = "enter");
233
+ const g = `fox-root-navigator__${l}-${s}-from`, w = `fox-root-navigator__${l}-${s}-active`;
234
+ i.classList.add(g), i.classList.add(w);
180
235
  }
181
- }, a = (c, o, i, h) => {
182
- if (i.opsType === 3 || o) {
183
- const u = n(i);
184
- if (u === "pop" && o)
236
+ }, h = (i, u, f, E) => {
237
+ if (f.opsType === b.Append || u) {
238
+ const l = a(f), s = u ? "show" : "enter";
239
+ if (s === "show" && (l === "pop" || o !== "leave" || (n ? a(n) : "") === "pop"))
185
240
  return;
186
- const f = o ? "show" : "enter", l = `fox-root-navigator__${u}-${f}-from`, r = `fox-root-navigator__${u}-${f}-to`;
187
- c.classList.remove(l), c.classList.add(r);
241
+ const g = `fox-root-navigator__${l}-${s}-from`, w = `fox-root-navigator__${l}-${s}-to`;
242
+ i.classList.remove(g), i.classList.add(w);
188
243
  }
189
- }, v = (c, o, i, h) => {
190
- if (i.opsType === 3 || o) {
191
- const u = n(i);
192
- if (u !== "pop" || !o) {
193
- const f = o ? "show" : "enter", l = `fox-root-navigator__${u}-${f}-active`, r = `fox-root-navigator__${u}-${f}-to`;
194
- c.classList.remove(l), c.classList.remove(r);
244
+ }, c = (i, u, f, E) => {
245
+ if (f.opsType === b.Append || u) {
246
+ const l = a(f), s = u ? "show" : "enter";
247
+ if (s === "enter" && (n = null, o = null), l !== "pop") {
248
+ const g = `fox-root-navigator__${l}-${s}-active`, w = `fox-root-navigator__${l}-${s}-to`;
249
+ i.classList.remove(g), i.classList.remove(w);
195
250
  }
196
251
  }
197
- e.dragRemove && !o && i.opsType === 3 && et(c, e.removePage, "fox-root-navigator__item-moving", 1e3);
198
- }, p = (c, o, i, h) => {
199
- if (i.opsType === 3 || o) {
200
- const u = n(i);
201
- if (u === "pop" && o)
252
+ e.dragRemove && !u && f.opsType === b.Append && _t(
253
+ i,
254
+ e.removeMoveRatio,
255
+ e.momentumReduceRatio,
256
+ e.removeViewPage,
257
+ e.removeViewPageDuration,
258
+ "fox-root-navigator__item-moving",
259
+ 1e3
260
+ );
261
+ }, v = (i, u, f, E) => {
262
+ if (f.opsType === b.Append || u) {
263
+ const l = a(f), s = u ? "hide" : "leave";
264
+ if (s === "hide" && (l === "pop" || o !== "enter" || (n ? a(n) : "") === "pop"))
202
265
  return;
203
- const f = o ? "hide" : "leave", l = `fox-root-navigator__${u}-${f}-from`, r = `fox-root-navigator__${u}-${f}-active`;
204
- c.classList.add(l), c.classList.add(r);
266
+ s === "leave" && (n = f, o = "leave");
267
+ const g = `fox-root-navigator__${l}-${s}-from`, w = `fox-root-navigator__${l}-${s}-active`;
268
+ i.classList.add(g), i.classList.add(w);
205
269
  }
206
- }, m = (c, o, i, h) => {
207
- if (i.opsType === 3 || o) {
208
- const u = n(i);
209
- if (u === "pop" && o)
270
+ }, m = (i, u, f, E) => {
271
+ if (f.opsType === b.Append || u) {
272
+ const l = a(f), s = u ? "hide" : "leave";
273
+ if (s === "hide" && (l === "pop" || o !== "enter" || (n ? a(n) : "") === "pop"))
210
274
  return;
211
- const f = o ? "hide" : "leave", l = `fox-root-navigator__${u}-${f}-from`, r = `fox-root-navigator__${u}-${f}-to`;
212
- c.classList.remove(l), c.classList.add(r);
275
+ const g = `fox-root-navigator__${l}-${s}-from`, w = `fox-root-navigator__${l}-${s}-to`;
276
+ i.classList.remove(g), i.classList.add(w);
213
277
  }
214
- }, d = (c, o, i, h) => {
215
- if (i.opsType === 3 || o) {
216
- const u = n(i);
217
- if (u !== "pop" || !o) {
218
- const f = o ? "hide" : "leave", l = `fox-root-navigator__${u}-${f}-active`, r = `fox-root-navigator__${u}-${f}-to`;
219
- c.classList.remove(l), c.classList.remove(r);
278
+ }, p = (i, u, f, E) => {
279
+ if (f.opsType === b.Append || u) {
280
+ const l = a(f), s = u ? "hide" : "leave";
281
+ if (s === "leave" && (n = null, o = null), l !== "pop") {
282
+ const g = `fox-root-navigator__${l}-${s}-active`, w = `fox-root-navigator__${l}-${s}-to`;
283
+ i.classList.remove(g), i.classList.remove(w);
220
284
  }
221
285
  }
222
- e.dragRemove && !o && nt(c);
286
+ e.dragRemove && !u && wt(i);
223
287
  };
224
- return (c, o) => {
225
- const i = b("fox-router-view");
226
- return y(), M(i, {
288
+ return (i, u) => {
289
+ const f = S("fox-router-view");
290
+ return L(), R(f, {
227
291
  class: "fox-root-navigator",
228
- "view-class": "fox-root-navigator__item",
229
- "before-enter": s,
230
- enter: a,
231
- "after-enter": v,
232
- "before-leave": p,
292
+ "view-class": i.viewClass,
293
+ "before-enter": d,
294
+ enter: h,
295
+ "after-enter": c,
296
+ "before-leave": v,
233
297
  leave: m,
234
- "after-leave": d,
298
+ "after-leave": p,
235
299
  multi: !0,
236
- name: e.routerViewName,
237
- "view-tag": e.viewTag,
238
- transition: e.transition
239
- }, null, 8, ["name", "view-tag", "transition"]);
300
+ name: i.routerViewName,
301
+ "view-tag": i.viewTag,
302
+ transition: i.transition
303
+ }, null, 8, ["view-class", "name", "view-tag", "transition"]);
240
304
  };
241
305
  }
242
- });
243
- const it = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
306
+ }), xt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
244
307
  __proto__: null,
245
- default: ot
246
- }, Symbol.toStringTag, { value: "Module" })), st = { class: "fox-swiper-navigator" }, at = /* @__PURE__ */ T({
308
+ default: yt
309
+ }, Symbol.toStringTag, { value: "Module" })), Tt = { class: "fox-swiper-navigator" }, Dt = /* @__PURE__ */ P({
247
310
  __name: "swiper",
248
311
  props: {
249
- width: null,
250
- scrollDistance: null,
251
- scrollTime: null
312
+ width: {},
313
+ scrollDistance: {},
314
+ scrollDuration: {},
315
+ direction: {}
252
316
  },
253
317
  setup(t) {
254
- const e = t, n = $(() => ({
255
- transform: `translate3d(${e.scrollDistance}px, 0, 0)`,
256
- width: `${e.width}`
257
- }));
258
- return (s, a) => (y(), z("div", st, [
259
- B("div", {
318
+ const e = t, n = O(() => {
319
+ const o = {
320
+ transform: `translate3d(${e.scrollDistance}px, 0, 0)`,
321
+ width: `${e.width}`
322
+ };
323
+ return e.scrollDuration > 0 && (o["transition-duration"] = `${e.scrollDuration}ms`), o;
324
+ });
325
+ return (o, a) => (L(), K("div", Tt, [
326
+ Q("div", {
260
327
  class: "fox-swiper-navigator__inner",
261
- style: S(w(n))
328
+ style: B(n.value)
262
329
  }, [
263
- X(s.$slots, "default")
330
+ Z(o.$slots, "default")
264
331
  ], 4)
265
332
  ]));
266
333
  }
267
334
  });
268
- let rt = 0;
269
- function ct() {
270
- return ++rt;
335
+ let Et = 0;
336
+ function bt() {
337
+ return ++Et;
271
338
  }
272
- const lt = 15, ut = 300, dt = 200;
273
- function ht(t) {
339
+ const Lt = 15, $t = 300, Mt = 200;
340
+ function Rt(t) {
274
341
  t.stopPropagation();
275
342
  }
276
- function ft(t, e) {
277
- (typeof t.cancelable != "boolean" || t.cancelable) && t.preventDefault(), e && ht(t);
343
+ function Pt(t, e) {
344
+ (typeof t.cancelable != "boolean" || t.cancelable) && t.preventDefault(), e && Rt(t);
278
345
  }
279
- function vt(t, e) {
280
- return t = Math.abs(t / e) / 3e-3 * (t < 0 ? -1 : 1), t;
346
+ function Ot(t, e, n = 1) {
347
+ return t = Math.abs(t / e) / 3e-3 * (t < 0 ? -1 : 1), t * n;
281
348
  }
282
- function O(t, e = 0, n, s = dt) {
283
- n === "end" ? t.style.transition = `transform ${s}ms cubic-bezier(0.17, 0.89, 0.45, 1)` : t.style.transition = "transform 0ms cubic-bezier(0.17, 0.89, 0.45, 1)", t.style.transform = `translate3d(${e}px, 0, 0)`;
349
+ function z(t, e = 0, n, o = Mt) {
350
+ n === "end" ? t.style.transition = `transform ${o}ms cubic-bezier(0.17, 0.89, 0.45, 1)` : t.style.transition = "transform 0ms cubic-bezier(0.17, 0.89, 0.45, 1)", t.style.transform = `translate3d(${e}px, 0, 0)`;
284
351
  }
285
- class pt {
352
+ class St {
353
+ /**
354
+ * width
355
+ */
286
356
  width = 0;
357
+ /**
358
+ * column width
359
+ */
287
360
  columnWidth = 0;
361
+ /**
362
+ * max
363
+ */
288
364
  max = 0;
365
+ /**
366
+ * min
367
+ */
289
368
  min = 0;
369
+ /**
370
+ * element
371
+ */
290
372
  el = null;
373
+ /**
374
+ * swipe duration
375
+ */
291
376
  swipeDuration = 360;
377
+ /**
378
+ * transitionEndTrigger
379
+ */
292
380
  transitionEndTrigger = null;
381
+ /**
382
+ * moving
383
+ */
293
384
  moving = !1;
385
+ /**
386
+ * start distance
387
+ */
294
388
  startDistance = 0;
389
+ /**
390
+ * scroll distance
391
+ */
295
392
  scrollDistance = 0;
393
+ /**
394
+ * 获取start distance
395
+ */
296
396
  getStartDistance;
397
+ /**
398
+ * open page
399
+ */
297
400
  openPage;
401
+ /**
402
+ * is page opened
403
+ */
298
404
  isPageOpened;
405
+ /**
406
+ * page opened
407
+ */
299
408
  pageOpened;
409
+ /**
410
+ *触发移动页面的移动比例(相对页面)
411
+ */
412
+ moveRatio = 0.5;
413
+ /**
414
+ * 惯性削减比例
415
+ */
416
+ momentumReduceRatio = 1;
417
+ /**
418
+ * transitionend
419
+ */
300
420
  transitionend = null;
421
+ /**
422
+ * touchstart
423
+ */
301
424
  touchstart = null;
425
+ /**
426
+ * touchmove
427
+ */
302
428
  touchmove = null;
429
+ /**
430
+ * touchend
431
+ */
303
432
  touchend = null;
433
+ /**
434
+ * touchcancel
435
+ */
304
436
  touchcancel = null;
305
- constructor(e, n, s, a) {
306
- this.getStartDistance = e, this.openPage = n, this.isPageOpened = s, this.pageOpened = a;
437
+ /**
438
+ * 构造函数
439
+ * @param getStartDistance
440
+ * @param openPage
441
+ * @param isPageOpened
442
+ * @param pageOpened
443
+ * @param moveRatio
444
+ * @param momentumReduceRatio
445
+ *
446
+ */
447
+ constructor(e, n, o, a, d, h) {
448
+ this.getStartDistance = e, this.openPage = n, this.isPageOpened = o, this.pageOpened = a, this.moveRatio = d, this.momentumReduceRatio = h;
307
449
  }
450
+ /**
451
+ * 打开drag支持
452
+ */
308
453
  open() {
309
- const e = this.el, n = W(), s = (a, v, p, m) => {
310
- let d = v + this.startDistance;
311
- const c = this.columnWidth / 3;
312
- if (p === "end") {
454
+ const e = this.el, n = F(), o = (a, d, h, c) => {
455
+ let v = d + this.startDistance;
456
+ const m = this.columnWidth * this.moveRatio;
457
+ if (h === "end") {
313
458
  if (d == 0) {
314
459
  this.moving = !1;
315
460
  return;
316
461
  }
317
- Math.abs(v) > c && (v > 0 ? d = this.startDistance + this.columnWidth : d = this.startDistance - this.columnWidth);
318
- let o = -d;
319
- o < 0 ? o = 0 : o > this.width - this.columnWidth && (o = this.width - this.columnWidth);
320
- const i = Math.floor(o / this.columnWidth);
321
- this.isPageOpened(i) || this.openPage(i), d = -i * this.columnWidth, m && m > 0 && (this.transitionEndTrigger = () => {
462
+ Math.abs(d) > m ? d > 0 ? v = this.startDistance + this.columnWidth : v = this.startDistance - this.columnWidth : v = this.startDistance;
463
+ let p = -v;
464
+ p < 0 ? p = 0 : p > this.width - this.columnWidth && (p = this.width - this.columnWidth);
465
+ const i = Math.floor(p / this.columnWidth);
466
+ this.isPageOpened(i) || this.openPage(i), v = -i * this.columnWidth, c && c > 0 && (this.transitionEndTrigger = () => {
322
467
  this.moving = !1, this.pageOpened(i);
323
- }), O(a, d, "end", m), this.scrollDistance = d;
468
+ }), z(a, v, "end", c), this.scrollDistance = v;
324
469
  } else {
325
- if (Math.abs(v) > c) {
470
+ if (Math.abs(d) > m) {
326
471
  let i = 0;
327
- if (v > 0 ? i = Math.abs(this.startDistance + this.columnWidth) : i = Math.abs(this.startDistance - this.columnWidth), i >= 0 && i < this.width) {
328
- const h = Math.floor(i / this.columnWidth);
329
- this.isPageOpened(h) || this.openPage(h);
472
+ if (d > 0 ? i = Math.abs(this.startDistance + this.columnWidth) : i = Math.abs(this.startDistance - this.columnWidth), i >= 0 && i < this.width) {
473
+ const u = Math.floor(i / this.columnWidth);
474
+ this.isPageOpened(u) || this.openPage(u);
330
475
  }
331
476
  }
332
- let o = -d;
333
- o < this.min ? o = this.min : o > this.max && (o = this.max), O(a, -o, "", 0);
477
+ let p = -v;
478
+ p < this.min ? p = this.min : p > this.max && (p = this.max), z(a, -p, "", 0);
334
479
  }
335
480
  };
336
481
  this.transitionend = () => {
@@ -338,131 +483,200 @@ class pt {
338
483
  }, this.touchstart = (a) => {
339
484
  this.moving || (n.start(a), this.startDistance = this.getStartDistance(), this.transitionEndTrigger = null, this.moving = !0);
340
485
  }, this.touchmove = (a) => {
341
- if (n.move(a), n.isVertical()) {
342
- ft(a, !0);
486
+ n.move(a), !n.isVertical() && (Pt(a, !0), o(e, n.state.deltaX, "", 0));
487
+ }, this.touchend = () => {
488
+ if (n.isVertical()) {
489
+ o(e, 0, "end", this.swipeDuration);
343
490
  return;
344
491
  }
345
- s(e, n.deltaX.value, "", 0);
346
- }, this.touchend = () => {
347
- const a = n.deltaX.value;
492
+ const a = n.state.deltaX;
348
493
  if (a == 0)
349
494
  return;
350
- const v = n.duration.value;
351
- if (v < ut && Math.abs(a) > lt) {
352
- const m = vt(a, v);
353
- s(e, m, "end", this.swipeDuration);
495
+ const d = n.state.duration;
496
+ if (d < $t && Math.abs(a) > Lt) {
497
+ const c = Ot(a, d, this.momentumReduceRatio);
498
+ o(e, c, "end", this.swipeDuration);
354
499
  } else
355
- s(e, a, "end", this.swipeDuration);
500
+ o(e, a, "end", this.swipeDuration);
356
501
  }, e.addEventListener("transitionend", this.transitionend), e.addEventListener("touchstart", this.touchstart), e.addEventListener("touchmove", this.touchmove), e.addEventListener("touchend", this.touchend), e.addEventListener("touchcancel", this.touchend);
357
502
  }
503
+ /**
504
+ * 关闭drag支持
505
+ */
358
506
  close() {
359
507
  const e = this.el;
360
508
  this.transitionend && e.addEventListener("transitionend", this.transitionend), this.touchstart && e.addEventListener("touchstart", this.touchstart), this.touchmove && e.addEventListener("touchmove", this.touchmove), this.touchend && e.addEventListener("touchend", this.touchend), this.touchcancel && e.addEventListener("touchcancel", this.touchcancel), this.el = null;
361
509
  }
362
510
  }
363
- function mt(t, e, n, s) {
364
- return new pt(t, e, n, s);
511
+ function Xt(t, e, n, o, a, d) {
512
+ return new St(t, e, n, o, a, d);
513
+ }
514
+ function At(t) {
515
+ const e = N(t), n = window.getComputedStyle(e, null), o = parseFloat(n.getPropertyValue("padding-left")), a = parseFloat(n.getPropertyValue("padding-right")), d = parseFloat(n.getPropertyValue("padding-top")), h = parseFloat(n.getPropertyValue("padding-bottom"));
516
+ return {
517
+ width: e.clientWidth - o - a,
518
+ height: e.clientHeight - d - h
519
+ };
365
520
  }
366
- const gt = /* @__PURE__ */ T({
521
+ const It = /* @__PURE__ */ P({
367
522
  __name: "index",
368
523
  props: {
369
- activePath: null,
370
- routes: null,
371
- height: null,
372
- width: null,
373
- drag: { type: Boolean, default: !0 },
374
- openPage: null,
375
- routerViewName: null,
376
- transition: { type: [Object, Boolean], default: !0 },
524
+ activePath: {},
525
+ routes: {},
526
+ height: { default: -1 },
527
+ width: { default: -1 },
528
+ draggable: { type: Boolean, default: !0 },
529
+ openViewPage: {},
530
+ routerViewName: {},
531
+ moveRatio: { default: 0.5 },
532
+ momentumReduceRatio: { default: 1 },
533
+ direction: { default: "horizontal" },
534
+ transition: { type: [Function, Boolean], default: !0 },
377
535
  swipeDuration: { default: 360 },
378
- scrollTime: { default: 0 }
536
+ scrollDuration: {},
537
+ customClass: {},
538
+ customStyle: {}
379
539
  },
380
540
  emits: ["update:activePath"],
381
541
  setup(t, { emit: e }) {
382
- const n = t, s = j({
542
+ const n = t, o = tt({
383
543
  scrollDistance: 0,
384
544
  index: -1,
385
- openedIndexList: []
386
- }), d = mt(() => s.scrollDistance, (l) => {
387
- if (s.openedIndexList.indexOf(l) === -1) {
388
- s.openedIndexList.push(l);
389
- const r = n.routes[l];
545
+ openedIndexList: [],
546
+ width: n.width,
547
+ height: n.height
548
+ }), a = e, d = () => o.scrollDistance, h = (r) => {
549
+ if (o.openedIndexList.indexOf(r) === -1) {
550
+ o.openedIndexList.push(r);
551
+ const y = n.routes[r];
390
552
  try {
391
- n.openPage(r, l);
392
- } catch (g) {
393
- console.error(g);
553
+ n.openViewPage(y, r);
554
+ } catch (_) {
555
+ console.error(_);
394
556
  }
395
557
  }
396
- }, (l) => s.openedIndexList.indexOf(l) !== -1, (l) => {
397
- s.index = l, s.scrollDistance = -s.index * n.width;
398
- const r = n.routes[l];
399
- e("update:activePath", r.path);
400
- });
401
- A(() => {
402
- const l = h();
403
- d.el = l, d.open();
404
- }), U(() => {
405
- d.close();
406
- }), V(() => {
407
- const l = n.activePath;
408
- s.index = n.routes.findIndex((N) => N.path === l);
409
- const r = n.width;
410
- s.index !== -1 && (s.openedIndexList.push(s.index), s.scrollDistance = -r * s.index);
411
- const g = r * n.routes.length, x = -r / 3, D = r * (n.routes.length - 1) + r / 3;
412
- d.columnWidth = r, d.width = g, d.min = x, d.max = D, d.swipeDuration = n.swipeDuration;
413
- });
414
- const c = `fox-swiper-navigator-${ct()}`, o = $(() => ({ width: `${n.width}px`, height: `${n.height}px` }));
415
- let i = null;
416
- function h() {
417
- return i || (i = document.querySelector(`.${c}>.fox-swiper-navigator__inner`), i);
418
- }
419
- const u = $(() => `${n.width * n.routes.length}px`), f = (l, r) => ({
420
- style: {
421
- left: `${n.routes.findIndex((x) => {
422
- const D = l.path ?? l.name ?? "";
423
- return x.path == D;
424
- }) * n.width}px`,
425
- width: `${n.width}px`
558
+ }, c = (r) => o.openedIndexList.indexOf(r) !== -1, v = (r) => {
559
+ o.index = r, o.width > 0 ? o.scrollDistance = -o.index * o.width : o.scrollDistance = 0;
560
+ const y = n.routes[r];
561
+ a("update:activePath", y.path);
562
+ };
563
+ let m = null;
564
+ n.draggable && (m = Xt(
565
+ d,
566
+ h,
567
+ c,
568
+ v,
569
+ n.moveRatio,
570
+ n.momentumReduceRatio
571
+ ));
572
+ let p = null;
573
+ et(() => {
574
+ const r = s(), y = () => {
575
+ const _ = At(r);
576
+ i(n.activePath, n.routes, _.width, _.height, n.swipeDuration, n.direction);
577
+ };
578
+ if (window.ResizeObserver && (p = new window.ResizeObserver(y), p.observe(r)), y(), m) {
579
+ const _ = w();
580
+ m.el = _, m.open();
426
581
  }
582
+ }), nt(() => {
583
+ p && (p.disconnect(), p = null), m && m.close();
584
+ }), ot(
585
+ [
586
+ () => n.activePath,
587
+ () => n.routes,
588
+ () => n.width,
589
+ () => n.height,
590
+ () => n.swipeDuration,
591
+ () => n.direction
592
+ ],
593
+ ([r, y, _, $, M, X]) => {
594
+ const A = _ <= 0 ? o.width : _, D = $ <= 0 ? o.height : $;
595
+ i(r, y, A, D, M, X);
596
+ }
597
+ );
598
+ const i = (r, y, _, $, M, X = "horizontal") => {
599
+ const A = r;
600
+ if (o.index = y.findIndex((D) => D.path === A), X === "horizontal") {
601
+ const D = _;
602
+ if (D > 0) {
603
+ o.width = _;
604
+ const j = D * n.routes.length, k = -D / 3, q = D * (y.length - 1) + D / 3;
605
+ m && (m.columnWidth = D, m.width = j, m.min = k, m.max = q), o.index !== -1 && (o.openedIndexList.push(o.index), o.scrollDistance = -D * o.index);
606
+ }
607
+ }
608
+ m && (m.swipeDuration = M);
609
+ }, u = `fox-swiper-navigator-${bt()}`, f = O(() => {
610
+ const r = [u];
611
+ return n.customClass && r.push(n.customClass), r;
612
+ }), E = O(() => {
613
+ const r = {}, y = o.width > 0 ? o.width : n.width;
614
+ y > 0 && (r.width = `${y}px`);
615
+ const _ = o.height > 0 ? o.height : n.height;
616
+ return _ > 0 && (r.height = `${_}px`), n.customStyle && Object.assign(r, n.customStyle), r;
427
617
  });
428
- return (l, r) => {
429
- const g = b("fox-router-view");
430
- return y(), M(g, {
431
- class: R(c),
432
- style: S(w(o)),
618
+ let l = null;
619
+ function s() {
620
+ return l || (l = document.querySelector(`.${u}`), l);
621
+ }
622
+ let g = null;
623
+ function w() {
624
+ return g || (g = document.querySelector(`.${u}>.fox-swiper-navigator__inner`), g);
625
+ }
626
+ const x = O(() => o.width > 0 ? `${o.width * n.routes.length}px` : "100%"), T = (r, y) => {
627
+ const _ = n.routes.findIndex(($) => {
628
+ const M = r.path ?? r.name ?? "";
629
+ return $.path == M;
630
+ });
631
+ return o.width <= 0 ? {} : {
632
+ style: {
633
+ left: `${_ * o.width}px`,
634
+ width: `${o.width}px`
635
+ }
636
+ };
637
+ };
638
+ return (r, y) => {
639
+ const _ = S("fox-router-view");
640
+ return L(), R(_, {
641
+ class: it(f.value),
642
+ style: B(E.value),
433
643
  "view-class": "fox-swiper-navigator__item",
434
- tag: at,
435
- "view-tag-props": f,
644
+ tag: Dt,
645
+ "view-tag-props": T,
436
646
  multi: !0,
437
- name: n.routerViewName,
438
- transition: n.transition,
439
- "scroll-distance": s.scrollDistance,
440
- "scroll-time": n.scrollTime,
441
- width: w(u)
442
- }, null, 8, ["style", "name", "transition", "scroll-distance", "scroll-time", "width"]);
647
+ name: r.routerViewName,
648
+ transition: r.transition,
649
+ "scroll-distance": o.scrollDistance,
650
+ "scroll-duration": r.scrollDuration,
651
+ direction: r.direction,
652
+ width: x.value
653
+ }, null, 8, ["class", "style", "name", "transition", "scroll-distance", "scroll-duration", "direction", "width"]);
443
654
  };
444
655
  }
445
- });
446
- const _t = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
656
+ }), Vt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
447
657
  __proto__: null,
448
- default: gt
658
+ default: It
449
659
  }, Symbol.toStringTag, { value: "Module" }));
450
- let xt = "fox-";
451
- const wt = [], I = /* @__PURE__ */ Object.assign({ "/src/components/card-navigator/index.vue": k, "/src/components/root-navigator/index.vue": it, "/src/components/swiper-navigator/index.vue": _t }), C = [];
452
- for (const t in I) {
660
+ let Ct = "fox-";
661
+ const Yt = [], W = /* @__PURE__ */ Object.assign({ "/src/components/card-navigator/index.vue": at, "/src/components/default-navigator/index.vue": ct, "/src/components/root-navigator/index.vue": xt, "/src/components/swiper-navigator/index.vue": Vt }), U = [];
662
+ for (const t in W) {
453
663
  let e = /src\/components\/(.*)\/index.vue/.exec(t)[1];
454
- wt.indexOf(e) === -1 && C.push({
664
+ Yt.indexOf(e) === -1 && U.push({
455
665
  name: e,
456
- component: I[t].default
666
+ component: W[t].default
457
667
  });
458
668
  }
459
- const yt = {
669
+ const Nt = {
670
+ /**
671
+ * 安装
672
+ * @param app
673
+ */
460
674
  install(t) {
461
- C.forEach((e) => {
462
- t.component(`${xt}${e.name}`, e.component);
675
+ U.forEach((e) => {
676
+ t.component(`${Ct}${e.name}`, e.component);
463
677
  });
464
678
  }
465
679
  };
466
680
  export {
467
- yt as default
681
+ Nt as default
468
682
  };