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