vue3-router-tab 1.1.2 → 1.1.4

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,7 +1,7 @@
1
1
  import './vue3-router-tab.css';
2
- import { reactive as ye, ref as Z, shallowRef as _e, computed as I, watch as P, nextTick as oe, inject as ae, getCurrentInstance as ge, onMounted as ee, defineComponent as Te, provide as Pe, onBeforeUnmount as xe, resolveComponent as $e, createElementBlock as g, openBlock as m, createElementVNode as R, createCommentVNode as w, renderSlot as Y, createVNode as E, TransitionGroup as Ke, mergeProps as j, withCtx as z, Fragment as q, renderList as le, withModifiers as O, normalizeClass as se, createTextVNode as Ie, toDisplayString as re, normalizeProps as Se, Transition as ce, createBlock as W, KeepAlive as Le, resolveDynamicComponent as ue, normalizeStyle as Me } from "vue";
3
- import { RouterView as Ee } from "vue-router";
4
- function je(e = {}) {
2
+ import { reactive as ge, ref as ee, shallowRef as Se, computed as $, watch as P, nextTick as ae, inject as se, getCurrentInstance as Te, onMounted as te, defineComponent as ke, provide as $e, onBeforeUnmount as Ee, resolveComponent as Le, createElementBlock as g, openBlock as h, createElementVNode as R, createCommentVNode as C, renderSlot as q, createVNode as D, TransitionGroup as Me, mergeProps as U, withCtx as j, Fragment as Q, renderList as le, withModifiers as z, normalizeClass as re, createTextVNode as De, toDisplayString as ce, normalizeProps as Ue, Transition as ue, createBlock as W, KeepAlive as je, resolveDynamicComponent as fe, normalizeStyle as ze } from "vue";
3
+ import { RouterView as Oe } from "vue-router";
4
+ function Ve(e = {}) {
5
5
  return {
6
6
  initialTabs: e.initialTabs ?? [],
7
7
  keepAlive: e.keepAlive ?? !0,
@@ -11,13 +11,13 @@ function je(e = {}) {
11
11
  defaultRoute: e.defaultRoute ?? "/"
12
12
  };
13
13
  }
14
- function A(e, i) {
15
- const o = e.resolve(i);
14
+ function A(e, n) {
15
+ const o = e.resolve(n);
16
16
  if (!o || !o.matched.length)
17
- throw new Error(`[RouterTabs] Unable to resolve route: ${String(i)}`);
17
+ throw new Error(`[RouterTabs] Unable to resolve route: ${String(n)}`);
18
18
  return o;
19
19
  }
20
- const ze = {
20
+ const Ne = {
21
21
  path: (e) => e.path,
22
22
  fullpath: (e) => e.fullPath,
23
23
  fullname: (e) => e.fullPath,
@@ -25,65 +25,65 @@ const ze = {
25
25
  name: (e) => e.name ? String(e.name) : e.fullPath
26
26
  };
27
27
  function _(e) {
28
- const i = e.meta?.key;
29
- if (typeof i == "function") {
30
- const o = i(e);
28
+ const n = e.meta?.key;
29
+ if (typeof n == "function") {
30
+ const o = n(e);
31
31
  if (typeof o == "string" && o.length) return o;
32
- } else if (typeof i == "string" && i.length) {
33
- const o = ze[i.toLowerCase()];
34
- return o ? o(e) : i;
32
+ } else if (typeof n == "string" && n.length) {
33
+ const o = Ne[n.toLowerCase()];
34
+ return o ? o(e) : n;
35
35
  }
36
36
  return e.fullPath;
37
37
  }
38
- function te(e, i) {
38
+ function ne(e, n) {
39
39
  const o = e.meta?.keepAlive;
40
- return typeof o == "boolean" ? o : i;
40
+ return typeof o == "boolean" ? o : n;
41
41
  }
42
- function ne(e, i) {
42
+ function oe(e, n) {
43
43
  const o = e.meta?.reuse;
44
- return typeof o == "boolean" ? o : i;
44
+ return typeof o == "boolean" ? o : n;
45
45
  }
46
- function ke(e) {
47
- const i = e.meta ?? {}, o = {};
48
- return "title" in i && (o.title = i.title), "tips" in i && (o.tips = i.tips), "icon" in i && (o.icon = i.icon), "closable" in i && (o.closable = i.closable), "tabClass" in i && (o.tabClass = i.tabClass), "target" in i && (o.target = i.target), "href" in i && (o.href = i.href), o;
46
+ function we(e) {
47
+ const n = e.meta ?? {}, o = {};
48
+ return "title" in n && (o.title = n.title), "tips" in n && (o.tips = n.tips), "icon" in n && (o.icon = n.icon), "closable" in n && (o.closable = n.closable), "tabClass" in n && (o.tabClass = n.tabClass), "target" in n && (o.target = n.target), "href" in n && (o.href = n.href), o;
49
49
  }
50
- function V(e, i, o) {
51
- const t = ke(e);
50
+ function O(e, n, o) {
51
+ const t = we(e);
52
52
  return {
53
53
  id: _(e),
54
54
  to: e.fullPath,
55
55
  fullPath: e.fullPath,
56
56
  matched: e,
57
- alive: te(e, o),
58
- reusable: ne(e, !1),
57
+ alive: ne(e, o),
58
+ reusable: oe(e, !1),
59
59
  closable: t.closable ?? !0,
60
60
  ...t,
61
- ...i
61
+ ...n
62
62
  };
63
63
  }
64
- function X(e, i, o, t) {
65
- if (!e.find((d) => d.id === i.id)) {
64
+ function X(e, n, o, t) {
65
+ if (!e.find((f) => f.id === n.id)) {
66
66
  if (o === "next" && t) {
67
- const d = e.findIndex((b) => b.id === t);
68
- if (d > -1) {
69
- e.splice(d + 1, 0, i);
67
+ const f = e.findIndex((b) => b.id === t);
68
+ if (f > -1) {
69
+ e.splice(f + 1, 0, n);
70
70
  return;
71
71
  }
72
72
  }
73
- e.push(i);
73
+ e.push(n);
74
74
  }
75
75
  }
76
- function fe(e, i, o) {
77
- if (!i || i <= 0) return;
78
- const t = e.filter((r) => r.alive);
79
- for (; t.length > i; ) {
80
- const r = t.shift();
81
- if (!r || r.id === o) continue;
82
- const d = e.findIndex((b) => b.id === r.id);
83
- d > -1 && (e[d].alive = !1);
76
+ function de(e, n, o) {
77
+ if (!n || n <= 0) return;
78
+ const t = e.filter((l) => l.alive);
79
+ for (; t.length > n; ) {
80
+ const l = t.shift();
81
+ if (!l || l.id === o) continue;
82
+ const f = e.findIndex((b) => b.id === l.id);
83
+ f > -1 && (e[f].alive = !1);
84
84
  }
85
85
  }
86
- function Oe(e) {
86
+ function Be(e) {
87
87
  return {
88
88
  to: e.to,
89
89
  title: e.title,
@@ -93,91 +93,91 @@ function Oe(e) {
93
93
  closable: e.closable
94
94
  };
95
95
  }
96
- function Ve(e) {
97
- const i = {};
98
- return "title" in e && (i.title = e.title), "tips" in e && (i.tips = e.tips), "icon" in e && (i.icon = e.icon), "tabClass" in e && (i.tabClass = e.tabClass), "closable" in e && (i.closable = e.closable), i;
96
+ function Ye(e) {
97
+ const n = {};
98
+ return "title" in e && (n.title = e.title), "tips" in e && (n.tips = e.tips), "icon" in e && (n.icon = e.icon), "tabClass" in e && (n.tabClass = e.tabClass), "closable" in e && (n.closable = e.closable), n;
99
99
  }
100
- function De(e, i = {}) {
101
- const o = je(i), t = ye([]), r = Z(null), d = _e(), b = Z(null), l = I(() => t.filter((a) => a.alive).map((a) => a.id));
100
+ function Fe(e, n = {}) {
101
+ const o = Ve(n), t = ge([]), l = ee(null), f = Se(), b = ee(null), s = $(() => t.filter((a) => a.alive).map((a) => a.id));
102
102
  let u = !1;
103
103
  function T(a) {
104
- const s = typeof a.matched == "object" ? a : A(e, a);
104
+ const r = typeof a.matched == "object" ? a : A(e, a);
105
105
  return {
106
- key: _(s),
107
- fullPath: s.fullPath,
108
- alive: te(s, o.keepAlive),
109
- reusable: ne(s, !1),
110
- matched: s
106
+ key: _(r),
107
+ fullPath: r.fullPath,
108
+ alive: ne(r, o.keepAlive),
109
+ reusable: oe(r, !1),
110
+ matched: r
111
111
  };
112
112
  }
113
- function C(a) {
114
- const s = _(a);
115
- let c = t.find((p) => p.id === s);
116
- return c ? (c.fullPath = a.fullPath, c.to = a.fullPath, c.matched = a, c.alive = te(a, o.keepAlive), c.reusable = ne(a, c.reusable), Object.assign(c, ke(a)), c) : (c = V(a, {}, o.keepAlive), X(t, c, o.appendPosition, r.value), fe(t, o.maxAlive, r.value), c);
113
+ function w(a) {
114
+ const r = _(a);
115
+ let c = t.find((p) => p.id === r);
116
+ return c ? (c.fullPath = a.fullPath, c.to = a.fullPath, c.matched = a, c.alive = ne(a, o.keepAlive), c.reusable = oe(a, c.reusable), Object.assign(c, we(a)), c) : (c = O(a, {}, o.keepAlive), X(t, c, o.appendPosition, l.value), de(t, o.maxAlive, l.value), c);
117
117
  }
118
- async function S(a, s = !1, c = !0) {
119
- const p = A(e, a), k = _(p), n = r.value === k;
120
- c === "sameTab" && (c = n), c && await v(k, !0), await e[s ? "replace" : "push"](p), n && await $();
118
+ async function E(a, r = !1, c = !0) {
119
+ const p = A(e, a), k = _(p), i = l.value === k;
120
+ c === "sameTab" && (c = i), c && await y(k, !0), await e[r ? "replace" : "push"](p), i && await K();
121
121
  }
122
122
  function L(a) {
123
- const s = t.findIndex((p) => p.id === a), c = t[s] || t[s - 1] || t[0];
123
+ const r = t.findIndex((p) => p.id === a), c = t[r] || t[r - 1] || t[0];
124
124
  return c ? c.to : o.defaultRoute;
125
125
  }
126
- async function x(a = r.value, s = {}) {
126
+ async function x(a = l.value, r = {}) {
127
127
  if (a) {
128
- if (!s.force && o.keepLastTab && t.length === 1)
128
+ if (!r.force && o.keepLastTab && t.length === 1)
129
129
  throw new Error("[RouterTabs] Unable to close the final tab when keepLastTab is true.");
130
- if (await M(a, { force: s.force }), s.redirect !== null)
131
- if (r.value === a) {
132
- const c = s.redirect ?? L(a);
130
+ if (await M(a, { force: r.force }), r.redirect !== null)
131
+ if (l.value === a) {
132
+ const c = r.redirect ?? L(a);
133
133
  c && await e.replace(c);
134
- } else s.redirect && await e.replace(s.redirect);
134
+ } else r.redirect && await e.replace(r.redirect);
135
135
  }
136
136
  }
137
- async function M(a, s = {}) {
137
+ async function M(a, r = {}) {
138
138
  const c = t.findIndex((p) => p.id === a);
139
- c !== -1 && (t.splice(c, 1), b.value === a && (b.value = null), r.value === a && (r.value = null, d.value = void 0));
139
+ c !== -1 && (t.splice(c, 1), b.value === a && (b.value = null), l.value === a && (l.value = null, f.value = void 0));
140
140
  }
141
- async function v(a = r.value ?? void 0, s = !1) {
142
- a && (b.value = a, await oe(), s || await oe(), b.value = null);
141
+ async function y(a = l.value ?? void 0, r = !1) {
142
+ a && (b.value = a, await ae(), r || await ae(), b.value = null);
143
143
  }
144
- async function U(a = !1) {
145
- for (const s of t)
146
- await v(s.id, a);
144
+ async function B(a = !1) {
145
+ for (const r of t)
146
+ await y(r.id, a);
147
147
  }
148
- async function B(a = o.defaultRoute) {
149
- t.splice(0, t.length), r.value = null, d.value = void 0;
150
- for (const s of o.initialTabs) {
151
- const c = A(e, s.to), p = V(c, s, o.keepAlive);
148
+ async function Y(a = o.defaultRoute) {
149
+ t.splice(0, t.length), l.value = null, f.value = void 0;
150
+ for (const r of o.initialTabs) {
151
+ const c = A(e, r.to), p = O(c, r, o.keepAlive);
152
152
  t.push(p);
153
153
  }
154
154
  await e.replace(a);
155
155
  }
156
- async function $() {
157
- const a = r.value;
158
- a && await v(a, !0);
156
+ async function K() {
157
+ const a = l.value;
158
+ a && await y(a, !0);
159
159
  }
160
160
  function F(a) {
161
161
  return typeof a.matched == "object" ? _(a) : _(A(e, a));
162
162
  }
163
163
  function G() {
164
- const a = t.find((s) => s.id === r.value);
164
+ const a = t.find((r) => r.id === l.value);
165
165
  return {
166
- tabs: t.map(Oe),
166
+ tabs: t.map(Be),
167
167
  active: a ? a.to : null
168
168
  };
169
169
  }
170
- async function K(a) {
171
- u = !0, t.splice(0, t.length), r.value = null, d.value = void 0;
172
- const s = a?.tabs ?? [];
173
- for (const p of s)
170
+ async function I(a) {
171
+ u = !0, t.splice(0, t.length), l.value = null, f.value = void 0;
172
+ const r = a?.tabs ?? [];
173
+ for (const p of r)
174
174
  try {
175
- const k = A(e, p.to), n = Ve(p), f = V(k, n, o.keepAlive);
176
- X(t, f, "last", null);
175
+ const k = A(e, p.to), i = Ye(p), d = O(k, i, o.keepAlive);
176
+ X(t, d, "last", null);
177
177
  } catch {
178
178
  }
179
179
  u = !1;
180
- const c = a?.active ?? s[s.length - 1]?.to ?? o.defaultRoute;
180
+ const c = a?.active ?? r[r.length - 1]?.to ?? o.defaultRoute;
181
181
  if (c)
182
182
  try {
183
183
  await e.replace(c);
@@ -188,78 +188,78 @@ function De(e, i = {}) {
188
188
  () => e.currentRoute.value,
189
189
  (a) => {
190
190
  if (u) return;
191
- const s = C(a);
192
- r.value = s.id, d.value = s, fe(t, o.maxAlive, r.value);
191
+ const r = w(a);
192
+ l.value = r.id, f.value = r, de(t, o.maxAlive, l.value);
193
193
  },
194
194
  { immediate: !0 }
195
195
  ), o.initialTabs.length && o.initialTabs.forEach((a) => {
196
- const s = A(e, a.to), c = V(s, a, o.keepAlive);
196
+ const r = A(e, a.to), c = O(r, a, o.keepAlive);
197
197
  X(t, c, "last", null);
198
198
  }), {
199
199
  options: o,
200
200
  tabs: t,
201
- activeId: r,
202
- current: d,
203
- includeKeys: l,
201
+ activeId: l,
202
+ current: f,
203
+ includeKeys: s,
204
204
  refreshingKey: b,
205
- openTab: S,
205
+ openTab: E,
206
206
  closeTab: x,
207
207
  removeTab: M,
208
- refreshTab: v,
209
- refreshAll: U,
210
- reset: B,
211
- reload: $,
208
+ refreshTab: y,
209
+ refreshAll: B,
210
+ reset: Y,
211
+ reload: K,
212
212
  getRouteKey: F,
213
213
  matchRoute: T,
214
214
  snapshot: G,
215
- hydrate: K
215
+ hydrate: I
216
216
  };
217
217
  }
218
- function de(e) {
218
+ function be(e) {
219
219
  return e ? typeof e == "string" ? { name: e } : e : {};
220
220
  }
221
- const N = Symbol("RouterTabsContext"), D = "router-tabs:snapshot";
222
- function be(e = {}) {
223
- const { optional: i = !1 } = e, o = ae(N, null);
221
+ const N = Symbol("RouterTabsContext"), V = "router-tabs:snapshot";
222
+ function pe(e = {}) {
223
+ const { optional: n = !1 } = e, o = se(N, null);
224
224
  if (o) return o;
225
- const t = ae("$tabs", null);
225
+ const t = se("$tabs", null);
226
226
  if (t) return t;
227
- const d = ge()?.appContext.config.globalProperties.$tabs;
228
- if (d) return d;
229
- if (!i)
227
+ const f = Te()?.appContext.config.globalProperties.$tabs;
228
+ if (f) return f;
229
+ if (!n)
230
230
  throw new Error("[RouterTabs] useRouterTabs must be used within <router-tab>.");
231
231
  return null;
232
232
  }
233
- const Ne = 864e5;
234
- function Ue(e) {
233
+ const Ge = 864e5;
234
+ function Je(e) {
235
235
  if (typeof document > "u") return null;
236
- const i = `${encodeURIComponent(e)}=`, o = document.cookie ? document.cookie.split("; ") : [];
236
+ const n = `${encodeURIComponent(e)}=`, o = document.cookie ? document.cookie.split("; ") : [];
237
237
  for (const t of o)
238
- if (t.startsWith(i))
239
- return decodeURIComponent(t.slice(i.length));
238
+ if (t.startsWith(n))
239
+ return decodeURIComponent(t.slice(n.length));
240
240
  return null;
241
241
  }
242
- function pe(e, i, o) {
242
+ function me(e, n, o) {
243
243
  if (typeof document > "u") return;
244
244
  const {
245
245
  expiresInDays: t = 7,
246
- path: r = "/",
247
- domain: d,
246
+ path: l = "/",
247
+ domain: f,
248
248
  secure: b,
249
- sameSite: l = "lax"
250
- } = o, u = [`${encodeURIComponent(e)}=${encodeURIComponent(i)}`];
249
+ sameSite: s = "lax"
250
+ } = o, u = [`${encodeURIComponent(e)}=${encodeURIComponent(n)}`];
251
251
  if (t !== 1 / 0) {
252
- const T = new Date(Date.now() + t * Ne).toUTCString();
252
+ const T = new Date(Date.now() + t * Ge).toUTCString();
253
253
  u.push(`Expires=${T}`);
254
254
  }
255
- r && u.push(`Path=${r}`), d && u.push(`Domain=${d}`), b && u.push("Secure"), l && u.push(`SameSite=${l.charAt(0).toUpperCase()}${l.slice(1)}`), document.cookie = u.join("; ");
255
+ l && u.push(`Path=${l}`), f && u.push(`Domain=${f}`), b && u.push("Secure"), s && u.push(`SameSite=${s.charAt(0).toUpperCase()}${s.slice(1)}`), document.cookie = u.join("; ");
256
256
  }
257
- function he(e, i) {
257
+ function ye(e, n) {
258
258
  if (typeof document > "u") return;
259
- const { path: o = "/", domain: t } = i, r = [`${encodeURIComponent(e)}=`];
260
- r.push("Expires=Thu, 01 Jan 1970 00:00:01 GMT"), o && r.push(`Path=${o}`), t && r.push(`Domain=${t}`), document.cookie = r.join("; ");
259
+ const { path: o = "/", domain: t } = n, l = [`${encodeURIComponent(e)}=`];
260
+ l.push("Expires=Thu, 01 Jan 1970 00:00:01 GMT"), o && l.push(`Path=${o}`), t && l.push(`Domain=${t}`), document.cookie = l.join("; ");
261
261
  }
262
- const Be = (e) => JSON.stringify(e ?? null), Fe = (e) => {
262
+ const He = (e) => JSON.stringify(e ?? null), qe = (e) => {
263
263
  if (!e) return null;
264
264
  try {
265
265
  return JSON.parse(e);
@@ -267,33 +267,33 @@ const Be = (e) => JSON.stringify(e ?? null), Fe = (e) => {
267
267
  return null;
268
268
  }
269
269
  };
270
- function Ce(e = {}) {
270
+ function Re(e = {}) {
271
271
  const {
272
- cookieKey: i = D,
273
- serialize: o = Be,
274
- deserialize: t = Fe
275
- } = e, r = be({ optional: !0 }), d = Z(!0), b = (l) => {
276
- ee(async () => {
277
- const u = t(Ue(i));
272
+ cookieKey: n = V,
273
+ serialize: o = He,
274
+ deserialize: t = qe
275
+ } = e, l = pe({ optional: !0 }), f = ee(!0), b = (s) => {
276
+ te(async () => {
277
+ const u = t(Je(n));
278
278
  if (u && u.tabs?.length)
279
279
  try {
280
- d.value = !0, await l.hydrate(u);
280
+ f.value = !0, await s.hydrate(u);
281
281
  } finally {
282
- d.value = !1;
282
+ f.value = !1;
283
283
  }
284
284
  else
285
285
  try {
286
- d.value = !0;
287
- const C = e.fallbackRoute ?? l.options.defaultRoute;
288
- await l.reset(C);
286
+ f.value = !0;
287
+ const w = e.fallbackRoute ?? s.options.defaultRoute;
288
+ await s.reset(w);
289
289
  } finally {
290
- d.value = !1;
290
+ f.value = !1;
291
291
  }
292
- const T = l.snapshot();
293
- T.tabs.length ? pe(i, o(T), e) : he(i, e), d.value = !1;
292
+ const T = s.snapshot();
293
+ T.tabs.length ? me(n, o(T), e) : ye(n, e), f.value = !1;
294
294
  }), P(
295
295
  () => ({
296
- tabs: l.tabs.map((u) => ({
296
+ tabs: s.tabs.map((u) => ({
297
297
  to: u.to,
298
298
  title: u.title,
299
299
  tips: u.tips,
@@ -301,24 +301,24 @@ function Ce(e = {}) {
301
301
  tabClass: u.tabClass,
302
302
  closable: u.closable
303
303
  })),
304
- active: l.activeId.value
304
+ active: s.activeId.value
305
305
  }),
306
306
  () => {
307
- if (d.value) return;
308
- const u = l.snapshot();
309
- u.tabs.length ? pe(i, o(u), e) : he(i, e);
307
+ if (f.value) return;
308
+ const u = s.snapshot();
309
+ u.tabs.length ? me(n, o(u), e) : ye(n, e);
310
310
  },
311
311
  { deep: !0 }
312
312
  );
313
313
  };
314
- r ? b(r) : ee(() => {
315
- const l = be({ optional: !0 });
316
- l && b(l);
314
+ l ? b(l) : te(() => {
315
+ const s = pe({ optional: !0 });
316
+ s && b(s);
317
317
  });
318
318
  }
319
- const Ge = Te({
319
+ const Qe = ke({
320
320
  name: "RouterTab",
321
- components: { RouterView: Ee },
321
+ components: { RouterView: Oe },
322
322
  props: {
323
323
  tabs: {
324
324
  type: Array,
@@ -358,7 +358,7 @@ const Ge = Te({
358
358
  },
359
359
  cookieKey: {
360
360
  type: String,
361
- default: D
361
+ default: V
362
362
  },
363
363
  persistence: {
364
364
  type: Object,
@@ -366,13 +366,13 @@ const Ge = Te({
366
366
  }
367
367
  },
368
368
  setup(e) {
369
- const i = ge();
370
- if (!i)
369
+ const n = Te();
370
+ if (!n)
371
371
  throw new Error("[RouterTab] component must be used within a Vue application context.");
372
- const o = i.appContext.app.config.globalProperties.$router;
372
+ const o = n.appContext.app.config.globalProperties.$router;
373
373
  if (!o)
374
374
  throw new Error("[RouterTab] Vue Router is required. Make sure to call app.use(router) before RouterTab.");
375
- const t = De(o, {
375
+ const t = Fe(o, {
376
376
  initialTabs: e.tabs,
377
377
  keepAlive: e.keepAlive,
378
378
  maxAlive: e.maxAlive,
@@ -380,15 +380,15 @@ const Ge = Te({
380
380
  appendPosition: e.append,
381
381
  defaultRoute: e.defaultPage
382
382
  });
383
- Pe(N, t), i.appContext.config.globalProperties.$tabs = t;
384
- const r = I(() => !!i?.slots?.default);
383
+ $e(N, t), n.appContext.config.globalProperties.$tabs = t;
384
+ const l = $(() => !!n?.slots?.default);
385
385
  if (e.cookieKey !== null || e.persistence) {
386
- const n = {
386
+ const i = {
387
387
  ...e.persistence ?? {}
388
388
  };
389
- e.cookieKey !== null ? n.cookieKey = e.cookieKey || D : n.cookieKey || (n.cookieKey = D), Ce(n);
389
+ e.cookieKey !== null ? i.cookieKey = e.cookieKey || V : i.cookieKey || (i.cookieKey = V), Re(i);
390
390
  }
391
- const d = I(() => de(e.tabTransition)), b = I(() => de(e.pageTransition)), l = ye({
391
+ const f = $(() => be(e.tabTransition)), b = $(() => be(e.pageTransition)), s = ge({
392
392
  visible: !1,
393
393
  target: null,
394
394
  position: { x: 0, y: 0 }
@@ -400,33 +400,33 @@ const Ge = Te({
400
400
  "closeRights",
401
401
  "closeOthers"
402
402
  ];
403
- function T(n) {
404
- return t.tabs.findIndex((f) => f.id === n);
403
+ function T(i) {
404
+ return t.tabs.findIndex((d) => d.id === i);
405
405
  }
406
- function C(n) {
407
- const f = T(n.id);
408
- return f > 0 ? t.tabs.slice(0, f) : [];
406
+ function w(i) {
407
+ const d = T(i.id);
408
+ return d > 0 ? t.tabs.slice(0, d) : [];
409
409
  }
410
- function S(n) {
411
- const f = T(n.id);
412
- return f > -1 ? t.tabs.slice(f + 1) : [];
410
+ function E(i) {
411
+ const d = T(i.id);
412
+ return d > -1 ? t.tabs.slice(d + 1) : [];
413
413
  }
414
- function L(n) {
415
- return t.tabs.filter((f) => f.id !== n.id);
414
+ function L(i) {
415
+ return t.tabs.filter((d) => d.id !== i.id);
416
416
  }
417
- async function x(n, f) {
418
- const h = n.filter((y) => y.closable !== !1);
419
- if (h.length) {
420
- for (const y of h)
421
- t.activeId.value === y.id ? await t.closeTab(y.id, { redirect: f.to, force: !0 }) : await t.removeTab(y.id, { force: !0 });
422
- t.activeId.value !== f.id && await t.openTab(f.to, !0, !1);
417
+ async function x(i, d) {
418
+ const m = i.filter((v) => v.closable !== !1);
419
+ if (m.length) {
420
+ for (const v of m)
421
+ t.activeId.value === v.id ? await t.closeTab(v.id, { redirect: d.to, force: !0 }) : await t.removeTab(v.id, { force: !0 });
422
+ t.activeId.value !== d.id && await t.openTab(d.to, !0, !1);
423
423
  }
424
424
  }
425
425
  const M = {
426
426
  refresh: {
427
427
  label: "Refresh",
428
- handler: async ({ target: n }) => {
429
- await t.refreshTab(n.id, !0);
428
+ handler: async ({ target: i }) => {
429
+ await t.refreshTab(i.id, !0);
430
430
  }
431
431
  },
432
432
  refreshAll: {
@@ -437,108 +437,108 @@ const Ge = Te({
437
437
  },
438
438
  close: {
439
439
  label: "Close",
440
- handler: async ({ target: n }) => {
441
- await t.closeTab(n.id);
440
+ handler: async ({ target: i }) => {
441
+ await t.closeTab(i.id);
442
442
  },
443
- enable: ({ target: n }) => K(n)
443
+ enable: ({ target: i }) => I(i)
444
444
  },
445
445
  closeLefts: {
446
446
  label: "Close to the Left",
447
- handler: async ({ target: n }) => {
448
- await x(C(n), n);
447
+ handler: async ({ target: i }) => {
448
+ await x(w(i), i);
449
449
  },
450
- enable: ({ target: n }) => C(n).some((f) => f.closable !== !1)
450
+ enable: ({ target: i }) => w(i).some((d) => d.closable !== !1)
451
451
  },
452
452
  closeRights: {
453
453
  label: "Close to the Right",
454
- handler: async ({ target: n }) => {
455
- await x(S(n), n);
454
+ handler: async ({ target: i }) => {
455
+ await x(E(i), i);
456
456
  },
457
- enable: ({ target: n }) => S(n).some((f) => f.closable !== !1)
457
+ enable: ({ target: i }) => E(i).some((d) => d.closable !== !1)
458
458
  },
459
459
  closeOthers: {
460
460
  label: "Close Others",
461
- handler: async ({ target: n }) => {
462
- await x(L(n), n);
461
+ handler: async ({ target: i }) => {
462
+ await x(L(i), i);
463
463
  },
464
- enable: ({ target: n }) => L(n).some((f) => f.closable !== !1)
464
+ enable: ({ target: i }) => L(i).some((d) => d.closable !== !1)
465
465
  }
466
466
  };
467
- function v() {
468
- l.visible = !1, l.target = null;
467
+ function y() {
468
+ s.visible = !1, s.target = null;
469
469
  }
470
- function U(n, f) {
471
- e.contextmenu && (l.visible = !0, l.target = n, l.position.x = f.clientX, l.position.y = f.clientY, document.addEventListener("click", v, { once: !0 }));
470
+ function B(i, d) {
471
+ e.contextmenu && (s.visible = !0, s.target = i, s.position.x = d.clientX, s.position.y = d.clientY, document.addEventListener("click", y, { once: !0 }));
472
472
  }
473
- function B(n, f) {
474
- const h = typeof n == "string" ? { id: n } : n, y = M[h.id], Re = h.label ?? y?.label ?? String(h.id), J = h.visible ?? y?.visible ?? !0;
475
- if (!(typeof J == "function" ? J(f) : J !== !1)) return null;
476
- const H = h.enable ?? y?.enable ?? !0, we = typeof H == "function" ? H(f) : H !== !1, ie = h.handler ?? y?.handler;
473
+ function Y(i, d) {
474
+ const m = typeof i == "string" ? { id: i } : i, v = M[m.id], xe = m.label ?? v?.label ?? String(m.id), J = m.visible ?? v?.visible ?? !0;
475
+ if (!(typeof J == "function" ? J(d) : J !== !1)) return null;
476
+ const H = m.enable ?? v?.enable ?? !0, Ke = typeof H == "function" ? H(d) : H !== !1, ie = m.handler ?? v?.handler;
477
477
  if (!ie) return null;
478
- const Ae = async () => {
479
- await Promise.resolve(ie(f));
478
+ const Ie = async () => {
479
+ await Promise.resolve(ie(d));
480
480
  };
481
481
  return {
482
- id: String(h.id),
483
- label: Re,
484
- disabled: !we,
485
- action: Ae
482
+ id: String(m.id),
483
+ label: xe,
484
+ disabled: !Ke,
485
+ action: Ie
486
486
  };
487
487
  }
488
- const $ = I(() => {
489
- if (!l.visible || !l.target || e.contextmenu === !1) return [];
490
- const n = Array.isArray(e.contextmenu) ? e.contextmenu : u, f = { target: l.target, controller: t };
491
- return n.map((h) => B(h, f)).filter((h) => !!h);
488
+ const K = $(() => {
489
+ if (!s.visible || !s.target || e.contextmenu === !1) return [];
490
+ const i = Array.isArray(e.contextmenu) ? e.contextmenu : u, d = { target: s.target, controller: t };
491
+ return i.map((m) => Y(m, d)).filter((m) => !!m);
492
492
  });
493
- async function F(n) {
494
- n.disabled || (v(), await n.action());
493
+ async function F(i) {
494
+ i.disabled || (y(), await i.action());
495
495
  }
496
- function G(n) {
497
- return typeof n.title == "string" ? n.title : Array.isArray(n.title) && n.title.length ? String(n.title[0]) : n.fullPath;
496
+ function G(i) {
497
+ return typeof i.title == "string" ? i.title : Array.isArray(i.title) && i.title.length ? String(i.title[0]) : i.fullPath;
498
498
  }
499
- function K(n) {
500
- return !(n.closable === !1 || t.options.keepLastTab && t.tabs.length <= 1);
499
+ function I(i) {
500
+ return !(i.closable === !1 || t.options.keepLastTab && t.tabs.length <= 1);
501
501
  }
502
- async function a(n) {
503
- await t.closeTab(n.id);
502
+ async function a(i) {
503
+ await t.closeTab(i.id);
504
504
  }
505
- function s(n) {
506
- t.activeId.value !== n.id && t.openTab(n.to, !1);
505
+ function r(i) {
506
+ t.activeId.value !== i.id && t.openTab(i.to, !1);
507
507
  }
508
- function c(n) {
508
+ function c(i) {
509
509
  return [
510
510
  "router-tab__item",
511
511
  {
512
- "is-active": t.activeId.value === n.id,
513
- "is-closable": K(n)
512
+ "is-active": t.activeId.value === i.id,
513
+ "is-closable": I(i)
514
514
  },
515
- n.tabClass
515
+ i.tabClass
516
516
  ];
517
517
  }
518
- function p(n) {
519
- return t.refreshingKey.value === t.getRouteKey(n);
518
+ function p(i) {
519
+ return t.refreshingKey.value === t.getRouteKey(i);
520
520
  }
521
- ee(() => {
522
- document.addEventListener("keydown", v);
523
- }), xe(() => {
524
- document.removeEventListener("keydown", v), i.appContext.config.globalProperties.$tabs = null;
521
+ te(() => {
522
+ document.addEventListener("keydown", y);
523
+ }), Ee(() => {
524
+ document.removeEventListener("keydown", y), n.appContext.config.globalProperties.$tabs = null;
525
525
  }), P(
526
526
  () => e.keepAlive,
527
- (n) => {
528
- t.options.keepAlive = n;
527
+ (i) => {
528
+ t.options.keepAlive = i;
529
529
  }
530
530
  ), P(
531
531
  () => t.activeId.value,
532
- () => v()
532
+ () => y()
533
533
  ), P(
534
534
  () => e.contextmenu,
535
- (n) => {
536
- n || v();
535
+ (i) => {
536
+ i || y();
537
537
  }
538
538
  ), P(
539
- () => $.value.length,
540
- (n) => {
541
- l.visible && n === 0 && v();
539
+ () => K.value.length,
540
+ (i) => {
541
+ s.visible && i === 0 && y();
542
542
  }
543
543
  );
544
544
  const k = t.includeKeys;
@@ -546,98 +546,98 @@ const Ge = Te({
546
546
  controller: t,
547
547
  tabs: t.tabs,
548
548
  includeKeys: k,
549
- tabTransitionProps: d,
549
+ tabTransitionProps: f,
550
550
  pageTransitionProps: b,
551
551
  buildTabClass: c,
552
- activate: s,
552
+ activate: r,
553
553
  close: a,
554
- context: l,
555
- menuItems: $,
554
+ context: s,
555
+ menuItems: K,
556
556
  handleMenuAction: F,
557
- showContextMenu: U,
558
- hideContextMenu: v,
557
+ showContextMenu: B,
558
+ hideContextMenu: y,
559
559
  tabTitle: G,
560
- isClosable: K,
560
+ isClosable: I,
561
561
  isRefreshing: p,
562
- hasCustomSlot: r
562
+ hasCustomSlot: l
563
563
  };
564
564
  }
565
- }), Je = (e, i) => {
565
+ }), We = (e, n) => {
566
566
  const o = e.__vccOpts || e;
567
- for (const [t, r] of i)
568
- o[t] = r;
567
+ for (const [t, l] of n)
568
+ o[t] = l;
569
569
  return o;
570
- }, He = { class: "router-tab" }, Ye = { class: "router-tab__header" }, qe = { class: "router-tab__slot-start" }, We = { class: "router-tab__scroll" }, Xe = ["onClick", "onAuxclick", "onContextmenu"], Qe = ["title"], Ze = ["onClick"], et = { class: "router-tab__slot-end" }, tt = { class: "router-tab__container" }, nt = ["aria-disabled", "onClick"];
571
- function it(e, i, o, t, r, d) {
572
- const b = $e("RouterView");
573
- return m(), g("div", He, [
574
- R("header", Ye, [
575
- R("div", qe, [
576
- Y(e.$slots, "start")
570
+ }, Xe = { class: "router-tab" }, Ze = { class: "router-tab__header" }, et = { class: "router-tab__slot-start" }, tt = { class: "router-tab__scroll" }, nt = ["onClick", "onAuxclick", "onContextmenu"], ot = ["title"], it = ["onClick"], at = { class: "router-tab__slot-end" }, st = { class: "router-tab__container" }, lt = ["aria-disabled", "onClick"];
571
+ function rt(e, n, o, t, l, f) {
572
+ const b = Le("RouterView");
573
+ return h(), g("div", Xe, [
574
+ R("header", Ze, [
575
+ R("div", et, [
576
+ q(e.$slots, "start")
577
577
  ]),
578
- R("div", We, [
579
- E(Ke, j({
578
+ R("div", tt, [
579
+ D(Me, U({
580
580
  tag: "ul",
581
581
  class: "router-tab__nav"
582
582
  }, e.tabTransitionProps), {
583
- default: z(() => [
584
- (m(!0), g(q, null, le(e.tabs, (l) => (m(), g("li", {
585
- key: l.id,
586
- class: se(e.buildTabClass(l)),
587
- onClick: (u) => e.activate(l),
588
- onAuxclick: O((u) => e.close(l), ["middle", "prevent"]),
589
- onContextmenu: O((u) => e.showContextMenu(l, u), ["prevent"])
583
+ default: j(() => [
584
+ (h(!0), g(Q, null, le(e.tabs, (s) => (h(), g("li", {
585
+ key: s.id,
586
+ class: re(e.buildTabClass(s)),
587
+ onClick: (u) => e.activate(s),
588
+ onAuxclick: z((u) => e.close(s), ["middle", "prevent"]),
589
+ onContextmenu: z((u) => e.showContextMenu(s, u), ["prevent"])
590
590
  }, [
591
591
  R("span", {
592
592
  class: "router-tab__item-title",
593
- title: e.tabTitle(l)
593
+ title: e.tabTitle(s)
594
594
  }, [
595
- l.icon ? (m(), g("i", {
595
+ s.icon ? (h(), g("i", {
596
596
  key: 0,
597
- class: se(["router-tab__item-icon", l.icon])
598
- }, null, 2)) : w("", !0),
599
- Ie(" " + re(e.tabTitle(l)), 1)
600
- ], 8, Qe),
601
- e.isClosable(l) ? (m(), g("a", {
597
+ class: re(["router-tab__item-icon", s.icon])
598
+ }, null, 2)) : C("", !0),
599
+ De(" " + ce(e.tabTitle(s)), 1)
600
+ ], 8, ot),
601
+ e.isClosable(s) ? (h(), g("a", {
602
602
  key: 0,
603
603
  class: "router-tab__item-close",
604
604
  type: "button",
605
- onClick: O((u) => e.close(l), ["stop"])
606
- }, null, 8, Ze)) : w("", !0)
607
- ], 42, Xe))), 128))
605
+ onClick: z((u) => e.close(s), ["stop"])
606
+ }, null, 8, it)) : C("", !0)
607
+ ], 42, nt))), 128))
608
608
  ]),
609
609
  _: 1
610
610
  }, 16)
611
611
  ]),
612
- R("div", et, [
613
- Y(e.$slots, "end")
612
+ R("div", at, [
613
+ q(e.$slots, "end")
614
614
  ])
615
615
  ]),
616
- R("div", tt, [
617
- E(b, null, {
618
- default: z((l) => [
619
- e.hasCustomSlot ? Y(e.$slots, "default", Se(j({ key: 0 }, { ...l, controller: e.controller }))) : (m(), g(q, { key: 1 }, [
620
- E(ce, j(e.pageTransitionProps, { appear: "" }), {
621
- default: z(() => [
622
- e.controller.options.keepAlive ? (m(), W(Le, {
616
+ R("div", st, [
617
+ D(b, null, {
618
+ default: j((s) => [
619
+ e.hasCustomSlot ? q(e.$slots, "default", Ue(U({ key: 0 }, { ...s, controller: e.controller }))) : (h(), g(Q, { key: 1 }, [
620
+ D(ue, U(e.pageTransitionProps, { appear: "" }), {
621
+ default: j(() => [
622
+ e.controller.options.keepAlive ? (h(), W(je, {
623
623
  key: 0,
624
624
  include: e.includeKeys,
625
625
  max: e.controller.options.maxAlive || void 0
626
626
  }, [
627
- e.isRefreshing(l.route) ? w("", !0) : (m(), W(ue(l.Component), {
628
- key: e.controller.getRouteKey(l.route),
627
+ e.isRefreshing(s.route) ? C("", !0) : (h(), W(fe(s.Component), {
628
+ key: e.controller.getRouteKey(s.route),
629
629
  class: "router-tab-page"
630
630
  }))
631
- ], 1032, ["include", "max"])) : w("", !0)
631
+ ], 1032, ["include", "max"])) : C("", !0)
632
632
  ]),
633
633
  _: 2
634
634
  }, 1040),
635
- E(ce, j(e.pageTransitionProps, { appear: "" }), {
636
- default: z(() => [
637
- !e.controller.options.keepAlive || e.isRefreshing(l.route) ? (m(), W(ue(l.Component), {
638
- key: e.controller.getRouteKey(l.route) + (e.isRefreshing(l.route) ? "-refresh" : ""),
635
+ D(ue, U(e.pageTransitionProps, { appear: "" }), {
636
+ default: j(() => [
637
+ !e.controller.options.keepAlive || e.isRefreshing(s.route) ? (h(), W(fe(s.Component), {
638
+ key: e.controller.getRouteKey(s.route) + (e.isRefreshing(s.route) ? "-refresh" : ""),
639
639
  class: "router-tab-page"
640
- })) : w("", !0)
640
+ })) : C("", !0)
641
641
  ]),
642
642
  _: 2
643
643
  }, 1040)
@@ -646,24 +646,24 @@ function it(e, i, o, t, r, d) {
646
646
  _: 3
647
647
  })
648
648
  ]),
649
- e.context.visible && e.context.target ? (m(), g("div", {
649
+ e.context.visible && e.context.target ? (h(), g("div", {
650
650
  key: 0,
651
651
  class: "router-tab__contextmenu",
652
- style: Me({ left: e.context.position.x + "px", top: e.context.position.y + "px" })
652
+ style: ze({ left: e.context.position.x + "px", top: e.context.position.y + "px" })
653
653
  }, [
654
- (m(!0), g(q, null, le(e.menuItems, (l) => (m(), g("a", {
655
- key: l.id,
654
+ (h(!0), g(Q, null, le(e.menuItems, (s) => (h(), g("a", {
655
+ key: s.id,
656
656
  class: "router-tab__contextmenu-item",
657
- "aria-disabled": l.disabled,
658
- onClick: O((u) => e.handleMenuAction(l), ["prevent"])
659
- }, re(l.label), 9, nt))), 128))
660
- ], 4)) : w("", !0)
657
+ "aria-disabled": s.disabled,
658
+ onClick: z((u) => e.handleMenuAction(s), ["prevent"])
659
+ }, ce(s.label), 9, lt))), 128))
660
+ ], 4)) : C("", !0)
661
661
  ]);
662
662
  }
663
- const ve = /* @__PURE__ */ Je(Ge, [["render", it]]), ot = {
663
+ const he = /* @__PURE__ */ We(Qe, [["render", rt]]), ct = {
664
664
  class: "router-tabs",
665
665
  "aria-hidden": "true"
666
- }, Q = /* @__PURE__ */ Te({
666
+ }, Z = /* @__PURE__ */ ke({
667
667
  name: "RouterTabs",
668
668
  __name: "RouterTabs",
669
669
  props: {
@@ -678,14 +678,46 @@ const ve = /* @__PURE__ */ Je(Ge, [["render", it]]), ot = {
678
678
  fallbackRoute: {}
679
679
  },
680
680
  setup(e) {
681
- return Ce(e), (o, t) => (m(), g("span", ot));
681
+ return Re(e), (o, t) => (h(), g("span", ct));
682
682
  }
683
- }), me = {
683
+ }), Ce = "tab-theme-style", Ae = "tab-theme-primary-color", ut = "system", ft = "#635bff", dt = "(prefers-color-scheme: dark)";
684
+ let S = null;
685
+ function _e(e) {
686
+ typeof document > "u" || (document.documentElement.style.setProperty("--theme-primary", e), document.documentElement.style.setProperty("--router-tab-primary", e));
687
+ }
688
+ function Pe(e) {
689
+ if (typeof document > "u") return;
690
+ const n = document.documentElement, o = window.matchMedia(dt), t = () => {
691
+ n.dataset.theme = o.matches ? "dark" : "light";
692
+ };
693
+ S && (o.removeEventListener("change", S), S = null), e === "system" ? (t(), S = () => t(), o.addEventListener("change", S)) : n.dataset.theme = e;
694
+ }
695
+ function bt(e = {}) {
696
+ if (typeof window > "u") return;
697
+ const {
698
+ styleKey: n = Ce,
699
+ primaryKey: o = Ae,
700
+ defaultStyle: t = ut,
701
+ defaultPrimary: l = ft
702
+ } = e, f = window.localStorage.getItem(n) ?? t, b = window.localStorage.getItem(o) ?? l;
703
+ Pe(f), _e(b);
704
+ }
705
+ function ht(e, n) {
706
+ if (typeof window > "u") return;
707
+ const o = n?.styleKey ?? Ce;
708
+ window.localStorage.setItem(o, e), Pe(e);
709
+ }
710
+ function vt(e, n) {
711
+ if (typeof window > "u") return;
712
+ const o = n?.primaryKey ?? Ae;
713
+ window.localStorage.setItem(o, e), _e(e);
714
+ }
715
+ const ve = {
684
716
  install(e) {
685
- if (me._installed) return;
686
- me._installed = !0;
687
- const i = ve.name || "RouterTab", o = Q.name || "RouterTabs";
688
- e.component(i, ve), e.component(o, Q), o !== "router-tabs" && e.component("router-tabs", Q), Object.defineProperty(e.config.globalProperties, "$tabs", {
717
+ if (ve._installed) return;
718
+ ve._installed = !0, bt();
719
+ const n = he.name || "RouterTab", o = Z.name || "RouterTabs";
720
+ e.component(n, he), e.component(o, Z), o !== "router-tabs" && e.component("router-tabs", Z), Object.defineProperty(e.config.globalProperties, "$tabs", {
689
721
  configurable: !0,
690
722
  enumerable: !1,
691
723
  get() {
@@ -698,10 +730,13 @@ const ve = /* @__PURE__ */ Je(Ge, [["render", it]]), ot = {
698
730
  }
699
731
  };
700
732
  export {
701
- ve as RouterTab,
702
- Q as RouterTabs,
703
- me as default,
733
+ he as RouterTab,
734
+ Z as RouterTabs,
735
+ ve as default,
736
+ bt as initRouterTabsTheme,
704
737
  N as routerTabsKey,
705
- be as useRouterTabs,
706
- Ce as useRouterTabsPersistence
738
+ vt as setRouterTabsPrimary,
739
+ ht as setRouterTabsTheme,
740
+ pe as useRouterTabs,
741
+ Re as useRouterTabsPersistence
707
742
  };