vue3-router-tab 1.1.1 → 1.1.3

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 me, ref as Q, shallowRef as Ae, computed as K, watch as P, nextTick as ie, inject as oe, getCurrentInstance as ye, onMounted as Z, defineComponent as ge, provide as _e, onBeforeUnmount as Pe, resolveComponent as xe, createElementBlock as g, openBlock as m, createElementVNode as R, createCommentVNode as w, renderSlot as H, createVNode as E, TransitionGroup as $e, mergeProps as j, withCtx as z, Fragment as Y, renderList as ae, withModifiers as O, normalizeClass as le, createTextVNode as Ie, toDisplayString as se, normalizeProps as Ke, Transition as re, createBlock as q, KeepAlive as Se, resolveDynamicComponent as ce, normalizeStyle as Le } from "vue";
3
- import { RouterView as Me } from "vue-router";
4
- function Ee(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,
@@ -17,7 +17,7 @@ function A(e, n) {
17
17
  throw new Error(`[RouterTabs] Unable to resolve route: ${String(n)}`);
18
18
  return o;
19
19
  }
20
- const je = {
20
+ const Ne = {
21
21
  path: (e) => e.path,
22
22
  fullpath: (e) => e.fullPath,
23
23
  fullname: (e) => e.fullPath,
@@ -30,60 +30,60 @@ function _(e) {
30
30
  const o = n(e);
31
31
  if (typeof o == "string" && o.length) return o;
32
32
  } else if (typeof n == "string" && n.length) {
33
- const o = je[n.toLowerCase()];
33
+ const o = Ne[n.toLowerCase()];
34
34
  return o ? o(e) : n;
35
35
  }
36
36
  return e.fullPath;
37
37
  }
38
- function ee(e, n) {
38
+ function ne(e, n) {
39
39
  const o = e.meta?.keepAlive;
40
40
  return typeof o == "boolean" ? o : n;
41
41
  }
42
- function te(e, n) {
42
+ function oe(e, n) {
43
43
  const o = e.meta?.reuse;
44
44
  return typeof o == "boolean" ? o : n;
45
45
  }
46
- function Te(e) {
46
+ function we(e) {
47
47
  const n = e.meta ?? {}, o = {};
48
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, n, o) {
51
- const t = Te(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: ee(e, o),
58
- reusable: te(e, !1),
57
+ alive: ne(e, o),
58
+ reusable: oe(e, !1),
59
59
  closable: t.closable ?? !0,
60
60
  ...t,
61
61
  ...n
62
62
  };
63
63
  }
64
- function W(e, n, o, t) {
65
- if (!e.find((d) => d.id === n.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, n);
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
73
  e.push(n);
74
74
  }
75
75
  }
76
- function ue(e, n, o) {
76
+ function de(e, n, o) {
77
77
  if (!n || n <= 0) return;
78
- const t = e.filter((r) => r.alive);
78
+ const t = e.filter((l) => l.alive);
79
79
  for (; t.length > n; ) {
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);
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 ze(e) {
86
+ function Be(e) {
87
87
  return {
88
88
  to: e.to,
89
89
  title: e.title,
@@ -93,91 +93,91 @@ function ze(e) {
93
93
  closable: e.closable
94
94
  };
95
95
  }
96
- function Oe(e) {
96
+ function Ye(e) {
97
97
  const n = {};
98
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 Ve(e, n = {}) {
101
- const o = Ee(n), t = me([]), r = Q(null), d = Ae(), b = Q(null), l = K(() => 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: ee(s, o.keepAlive),
109
- reusable: te(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 = ee(a, o.keepAlive), c.reusable = te(a, c.reusable), Object.assign(c, Te(a)), c) : (c = V(a, {}, o.keepAlive), W(t, c, o.appendPosition, r.value), ue(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), i = r.value === k;
120
- c === "sameTab" && (c = i), c && await v(k, !0), await e[s ? "replace" : "push"](p), i && 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 ie(), s || await ie(), 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 N(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 U(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
- function B(a) {
160
+ function F(a) {
161
161
  return typeof a.matched == "object" ? _(a) : _(A(e, a));
162
162
  }
163
- function F() {
164
- const a = t.find((s) => s.id === r.value);
163
+ function G() {
164
+ const a = t.find((r) => r.id === l.value);
165
165
  return {
166
- tabs: t.map(ze),
166
+ tabs: t.map(Be),
167
167
  active: a ? a.to : null
168
168
  };
169
169
  }
170
170
  async function I(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)
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), i = Oe(p), f = V(k, i, o.keepAlive);
176
- W(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,50 +188,50 @@ function Ve(e, n = {}) {
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, ue(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);
197
- W(t, c, "last", null);
196
+ const r = A(e, a.to), c = O(r, a, o.keepAlive);
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: N,
210
- reset: U,
211
- reload: $,
212
- getRouteKey: B,
208
+ refreshTab: y,
209
+ refreshAll: B,
210
+ reset: Y,
211
+ reload: K,
212
+ getRouteKey: F,
213
213
  matchRoute: T,
214
- snapshot: F,
214
+ snapshot: G,
215
215
  hydrate: I
216
216
  };
217
217
  }
218
- function fe(e) {
218
+ function be(e) {
219
219
  return e ? typeof e == "string" ? { name: e } : e : {};
220
220
  }
221
- const D = Symbol("RouterTabsContext"), De = "router-tabs:snapshot";
222
- function de(e = {}) {
223
- const { optional: n = !1 } = e, o = oe(D, 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 = oe("$tabs", null);
225
+ const t = se("$tabs", null);
226
226
  if (t) return t;
227
- const d = ye()?.appContext.config.globalProperties.$tabs;
228
- if (d) return d;
227
+ const f = Te()?.appContext.config.globalProperties.$tabs;
228
+ if (f) return f;
229
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
236
  const n = `${encodeURIComponent(e)}=`, o = document.cookie ? document.cookie.split("; ") : [];
237
237
  for (const t of o)
@@ -239,27 +239,27 @@ function Ue(e) {
239
239
  return decodeURIComponent(t.slice(n.length));
240
240
  return null;
241
241
  }
242
- function be(e, n, 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"
249
+ sameSite: s = "lax"
250
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 pe(e, n) {
257
+ function ye(e, n) {
258
258
  if (typeof document > "u") return;
259
- const { path: o = "/", domain: t } = n, 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 ke(e = {}) {
270
+ function Re(e = {}) {
271
271
  const {
272
- cookieKey: n = De,
273
- serialize: o = Be,
274
- deserialize: t = Fe
275
- } = e, r = de({ optional: !0 }), d = Q(!1), b = (l) => {
276
- Z(async () => {
277
- const u = t(Ue(n));
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 ? be(n, o(T), e) : pe(n, e);
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 ke(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 ? be(n, o(u), e) : pe(n, 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) : Z(() => {
315
- const l = de({ 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 = ge({
319
+ const Qe = ke({
320
320
  name: "RouterTab",
321
- components: { RouterView: Me },
321
+ components: { RouterView: Oe },
322
322
  props: {
323
323
  tabs: {
324
324
  type: Array,
@@ -358,7 +358,7 @@ const Ge = ge({
358
358
  },
359
359
  cookieKey: {
360
360
  type: String,
361
- default: null
361
+ default: V
362
362
  },
363
363
  persistence: {
364
364
  type: Object,
@@ -366,13 +366,13 @@ const Ge = ge({
366
366
  }
367
367
  },
368
368
  setup(e) {
369
- const n = ye();
369
+ const n = Te();
370
370
  if (!n)
371
371
  throw new Error("[RouterTab] component must be used within a Vue application context.");
372
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 = Ve(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 = ge({
380
380
  appendPosition: e.append,
381
381
  defaultRoute: e.defaultPage
382
382
  });
383
- _e(D, t), n.appContext.config.globalProperties.$tabs = t;
384
- const r = K(() => !!n?.slots?.default);
385
- if (e.cookieKey || e.persistence) {
383
+ $e(N, t), n.appContext.config.globalProperties.$tabs = t;
384
+ const l = $(() => !!n?.slots?.default);
385
+ if (e.cookieKey !== null || e.persistence) {
386
386
  const i = {
387
387
  ...e.persistence ?? {}
388
388
  };
389
- e.cookieKey && (i.cookieKey = e.cookieKey), ke(i);
389
+ e.cookieKey !== null ? i.cookieKey = e.cookieKey || V : i.cookieKey || (i.cookieKey = V), Re(i);
390
390
  }
391
- const d = K(() => fe(e.tabTransition)), b = K(() => fe(e.pageTransition)), l = me({
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 }
@@ -401,25 +401,25 @@ const Ge = ge({
401
401
  "closeOthers"
402
402
  ];
403
403
  function T(i) {
404
- return t.tabs.findIndex((f) => f.id === i);
404
+ return t.tabs.findIndex((d) => d.id === i);
405
405
  }
406
- function C(i) {
407
- const f = T(i.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(i) {
411
- const f = T(i.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
414
  function L(i) {
415
- return t.tabs.filter((f) => f.id !== i.id);
415
+ return t.tabs.filter((d) => d.id !== i.id);
416
416
  }
417
- async function x(i, f) {
418
- const h = i.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 = {
@@ -445,55 +445,55 @@ const Ge = ge({
445
445
  closeLefts: {
446
446
  label: "Close to the Left",
447
447
  handler: async ({ target: i }) => {
448
- await x(C(i), i);
448
+ await x(w(i), i);
449
449
  },
450
- enable: ({ target: i }) => C(i).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
454
  handler: async ({ target: i }) => {
455
- await x(S(i), i);
455
+ await x(E(i), i);
456
456
  },
457
- enable: ({ target: i }) => S(i).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
461
  handler: async ({ target: i }) => {
462
462
  await x(L(i), i);
463
463
  },
464
- enable: ({ target: i }) => L(i).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 N(i, f) {
471
- e.contextmenu && (l.visible = !0, l.target = i, 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 U(i, f) {
474
- const h = typeof i == "string" ? { id: i } : i, y = M[h.id], Ce = h.label ?? y?.label ?? String(h.id), G = h.visible ?? y?.visible ?? !0;
475
- if (!(typeof G == "function" ? G(f) : G !== !1)) return null;
476
- const J = h.enable ?? y?.enable ?? !0, Re = typeof J == "function" ? J(f) : J !== !1, ne = h.handler ?? y?.handler;
477
- if (!ne) return null;
478
- const we = async () => {
479
- await Promise.resolve(ne(f));
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
+ if (!ie) return null;
478
+ const Ie = async () => {
479
+ await Promise.resolve(ie(d));
480
480
  };
481
481
  return {
482
- id: String(h.id),
483
- label: Ce,
484
- disabled: !Re,
485
- action: we
482
+ id: String(m.id),
483
+ label: xe,
484
+ disabled: !Ke,
485
+ action: Ie
486
486
  };
487
487
  }
488
- const $ = K(() => {
489
- if (!l.visible || !l.target || e.contextmenu === !1) return [];
490
- const i = Array.isArray(e.contextmenu) ? e.contextmenu : u, f = { target: l.target, controller: t };
491
- return i.map((h) => U(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 B(i) {
494
- i.disabled || (v(), await i.action());
493
+ async function F(i) {
494
+ i.disabled || (y(), await i.action());
495
495
  }
496
- function F(i) {
496
+ function G(i) {
497
497
  return typeof i.title == "string" ? i.title : Array.isArray(i.title) && i.title.length ? String(i.title[0]) : i.fullPath;
498
498
  }
499
499
  function I(i) {
@@ -502,7 +502,7 @@ const Ge = ge({
502
502
  async function a(i) {
503
503
  await t.closeTab(i.id);
504
504
  }
505
- function s(i) {
505
+ function r(i) {
506
506
  t.activeId.value !== i.id && t.openTab(i.to, !1);
507
507
  }
508
508
  function c(i) {
@@ -518,10 +518,10 @@ const Ge = ge({
518
518
  function p(i) {
519
519
  return t.refreshingKey.value === t.getRouteKey(i);
520
520
  }
521
- Z(() => {
522
- document.addEventListener("keydown", v);
523
- }), Pe(() => {
524
- document.removeEventListener("keydown", v), n.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
527
  (i) => {
@@ -529,16 +529,16 @@ const Ge = ge({
529
529
  }
530
530
  ), P(
531
531
  () => t.activeId.value,
532
- () => v()
532
+ () => y()
533
533
  ), P(
534
534
  () => e.contextmenu,
535
535
  (i) => {
536
- i || v();
536
+ i || y();
537
537
  }
538
538
  ), P(
539
- () => $.value.length,
539
+ () => K.value.length,
540
540
  (i) => {
541
- l.visible && i === 0 && v();
541
+ s.visible && i === 0 && y();
542
542
  }
543
543
  );
544
544
  const k = t.includeKeys;
@@ -546,98 +546,98 @@ const Ge = ge({
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: $,
556
- handleMenuAction: B,
557
- showContextMenu: N,
558
- hideContextMenu: v,
559
- tabTitle: F,
554
+ context: s,
555
+ menuItems: K,
556
+ handleMenuAction: F,
557
+ showContextMenu: B,
558
+ hideContextMenu: y,
559
+ tabTitle: G,
560
560
  isClosable: I,
561
561
  isRefreshing: p,
562
- hasCustomSlot: r
562
+ hasCustomSlot: l
563
563
  };
564
564
  }
565
- }), Je = (e, n) => {
565
+ }), We = (e, n) => {
566
566
  const o = e.__vccOpts || e;
567
- for (const [t, r] of n)
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, n, o, t, r, d) {
572
- const b = xe("RouterView");
573
- return m(), g("div", He, [
574
- R("header", Ye, [
575
- R("div", qe, [
576
- H(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($e, 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(Y, null, ae(e.tabs, (l) => (m(), g("li", {
585
- key: l.id,
586
- class: le(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: le(["router-tab__item-icon", l.icon])
598
- }, null, 2)) : w("", !0),
599
- Ie(" " + se(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
- H(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 ? H(e.$slots, "default", Ke(j({ key: 0 }, { ...l, controller: e.controller }))) : (m(), g(Y, { key: 1 }, [
620
- E(re, j(e.pageTransitionProps, { appear: "" }), {
621
- default: z(() => [
622
- e.controller.options.keepAlive ? (m(), q(Se, {
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(), q(ce(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(re, j(e.pageTransitionProps, { appear: "" }), {
636
- default: z(() => [
637
- !e.controller.options.keepAlive || e.isRefreshing(l.route) ? (m(), q(ce(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, n, 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: Le({ 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(Y, null, ae(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
- }, se(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 he = /* @__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
- }, X = /* @__PURE__ */ ge({
666
+ }, Z = /* @__PURE__ */ ke({
667
667
  name: "RouterTabs",
668
668
  __name: "RouterTabs",
669
669
  props: {
@@ -678,30 +678,65 @@ const he = /* @__PURE__ */ Je(Ge, [["render", it]]), ot = {
678
678
  fallbackRoute: {}
679
679
  },
680
680
  setup(e) {
681
- return ke(e), (o, t) => (m(), g("span", ot));
681
+ return Re(e), (o, t) => (h(), g("span", ct));
682
682
  }
683
- }), ve = {
683
+ }), Ce = "theme-style", Ae = "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
717
  if (ve._installed) return;
686
- ve._installed = !0;
687
- const n = he.name || "RouterTab", o = X.name || "RouterTabs";
688
- e.component(n, he), e.component(o, X), o !== "router-tabs" && e.component("router-tabs", X), Object.defineProperty(e.config.globalProperties, "$tabs", {
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() {
692
- return e._context.provides[D];
724
+ return e._context.provides[N];
693
725
  },
694
726
  set(t) {
695
- t && e.provide(D, t);
727
+ t && e.provide(N, t);
696
728
  }
697
729
  });
698
730
  }
699
731
  };
700
732
  export {
701
733
  he as RouterTab,
702
- X as RouterTabs,
734
+ Z as RouterTabs,
703
735
  ve as default,
704
- D as routerTabsKey,
705
- de as useRouterTabs,
706
- ke as useRouterTabsPersistence
736
+ bt as initRouterTabsTheme,
737
+ N as routerTabsKey,
738
+ vt as setRouterTabsPrimary,
739
+ ht as setRouterTabsTheme,
740
+ pe as useRouterTabs,
741
+ Re as useRouterTabsPersistence
707
742
  };