@gospore/theme 1.0.141 → 1.0.142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/theme.es.js CHANGED
@@ -1,565 +1,501 @@
1
- import { inject as Ut, computed as ot, ref as G, watch as H, onBeforeUnmount as $t, provide as mt, createElementBlock as Pt, openBlock as _t, normalizeStyle as Ht, renderSlot as Ft, createElementVNode as Ct, createBlock as Vt, unref as w, withCtx as bt, createVNode as K } from "vue";
1
+ import { computed as e, createBlock as t, createElementBlock as n, createElementVNode as r, createVNode as i, inject as a, normalizeStyle as o, onBeforeUnmount as s, openBlock as c, provide as l, ref as u, renderSlot as d, unref as f, watch as p, withCtx as m } from "vue";
2
2
  import "what-input";
3
- import { DropdownMenu as Gt, DropdownItemGroup as jt, DropdownItemRadio as Z } from "@gospore/dropdown-menu";
4
- const Q = ["auto", "light", "dark"], vt = "gospore-theme-mode", Kt = 3600 * 24 * 365, Yt = "(prefers-color-scheme: dark)";
5
- function nt() {
6
- if (typeof document > "u")
7
- return null;
8
- const a = Xt(vt);
9
- return a && Q.includes(a) ? a : null;
3
+ import { DropdownItemGroup as h, DropdownItemRadio as g, DropdownMenu as _ } from "@gospore/dropdown-menu";
4
+ //#region src/modeStorage.js
5
+ var v = [
6
+ "auto",
7
+ "light",
8
+ "dark"
9
+ ], y = "gospore-theme-mode", b = 3600 * 24 * 365, x = "(prefers-color-scheme: dark)";
10
+ function S() {
11
+ if (typeof document > "u") return null;
12
+ let e = T(y);
13
+ return e && v.includes(e) ? e : null;
10
14
  }
11
- function Qt(a) {
12
- if (typeof document > "u" || !Q.includes(a))
13
- return;
14
- const l = typeof window < "u" ? window.location.hostname : "", m = typeof window < "u" ? window.location.protocol : "", u = qt(l), D = m === "https:", I = [
15
- "path=/",
16
- `max-age=${Kt}`,
17
- "SameSite=Lax"
18
- ];
19
- u && I.push(`domain=${u}`), D && I.push("Secure"), document.cookie = [
20
- `${encodeURIComponent(vt)}=${encodeURIComponent(a)}`,
21
- ...I
22
- ].join("; ");
15
+ function C(e) {
16
+ if (typeof document > "u" || !v.includes(e)) return;
17
+ let t = typeof window < "u" ? window.location.hostname : "", n = typeof window < "u" ? window.location.protocol : "", r = E(t), i = n === "https:", a = [
18
+ "path=/",
19
+ `max-age=${b}`,
20
+ "SameSite=Lax"
21
+ ];
22
+ r && a.push(`domain=${r}`), i && a.push("Secure"), document.cookie = [`${encodeURIComponent(y)}=${encodeURIComponent(e)}`, ...a].join("; ");
23
23
  }
24
- function Rt(a) {
25
- if (typeof document > "u")
26
- return;
27
- const l = typeof a == "string" && Q.includes(a) ? a : nt() ?? "auto";
28
- console.log("Applying theme mode:", l);
29
- const m = zt(l);
30
- document.documentElement.setAttribute("dark-mode", m);
24
+ function w(e) {
25
+ if (typeof document > "u") return;
26
+ let t = typeof e == "string" && v.includes(e) ? e : S() ?? "auto";
27
+ console.log("Applying theme mode:", t);
28
+ let n = D(t);
29
+ document.documentElement.setAttribute("dark-mode", n);
31
30
  }
32
- function Xt(a) {
33
- if (typeof document > "u" || !document.cookie)
34
- return null;
35
- const l = `${encodeURIComponent(a)}=`, m = document.cookie.split("; ");
36
- for (const u of m)
37
- if (u.startsWith(l))
38
- return decodeURIComponent(u.slice(l.length));
39
- return null;
31
+ function T(e) {
32
+ if (typeof document > "u" || !document.cookie) return null;
33
+ let t = `${encodeURIComponent(e)}=`, n = document.cookie.split("; ");
34
+ for (let e of n) if (e.startsWith(t)) return decodeURIComponent(e.slice(t.length));
35
+ return null;
40
36
  }
41
- function qt(a) {
42
- if (!a || a === "localhost")
43
- return null;
44
- if (/^\d+(?:\.\d+){3}$/.test(a))
45
- return a;
46
- const m = a.split(".");
47
- return m.length <= 1 ? null : m.length === 2 ? a : m.slice(-2).join(".");
37
+ function E(e) {
38
+ if (!e || e === "localhost") return null;
39
+ if (/^\d+(?:\.\d+){3}$/.test(e)) return e;
40
+ let t = e.split(".");
41
+ return t.length <= 1 ? null : t.length === 2 ? e : t.slice(-2).join(".");
48
42
  }
49
- function zt(a) {
50
- if (a === "dark")
51
- return !0;
52
- if (a === "light" || typeof window > "u")
53
- return !1;
54
- try {
55
- const l = typeof window.matchMedia == "function" ? window.matchMedia(Yt) : null;
56
- return l ? l.matches : !1;
57
- } catch {
58
- return !1;
59
- }
43
+ function D(e) {
44
+ if (e === "dark") return !0;
45
+ if (e === "light" || typeof window > "u") return !1;
46
+ try {
47
+ let e = typeof window.matchMedia == "function" ? window.matchMedia(x) : null;
48
+ return e ? e.matches : !1;
49
+ } catch {
50
+ return !1;
51
+ }
60
52
  }
61
- const Tt = /* @__PURE__ */ Symbol.for("gospore.theme.portalHost");
62
- function ae() {
63
- const a = Ut(Tt, null);
64
- console.log("Using theme portal host:", a);
65
- const l = typeof document < "u" ? document.body : "body";
66
- return ot(() => a?.value ?? l);
53
+ //#endregion
54
+ //#region src/portalHost.js
55
+ var O = Symbol.for("gospore.theme.portalHost");
56
+ function k() {
57
+ let t = a(O, null);
58
+ console.log("Using theme portal host:", t);
59
+ let n = typeof document < "u" ? document.body : "body";
60
+ return e(() => t?.value ?? n);
67
61
  }
68
- const Wt = "(prefers-color-scheme: dark)", Jt = "(prefers-reduced-motion: reduce)", Zt = 200, B = 3.8, pt = 1.8, St = 1.15, kt = 1.08, Y = 2.5, Mt = 3, tt = "#ffffff", et = "#1f2228", ce = /* @__PURE__ */ Object.assign({
69
- name: "Theme"
70
- }, {
71
- __name: "Theme",
72
- props: {
73
- mode: {
74
- type: String,
75
- validator: (a) => ["auto", "light", "dark"].includes(a)
76
- },
77
- /**
78
- * Optional hex accent color ("#RRGGBB" or "#RGB"). When provided,
79
- * Theme derives contrast-safe semantic brand tokens and exposes them on
80
- * the root .theme element (and the global document for portals).
81
- */
82
- accentColor: {
83
- type: String,
84
- required: !1,
85
- default: void 0
86
- },
87
- /**
88
- * When true the brand vars are also exposed on <html>, allowing portals
89
- * attached outside the Theme subtree to inherit the accent colors.
90
- */
91
- exposeGlobalAccent: {
92
- type: Boolean,
93
- default: !1
94
- }
95
- },
96
- setup(a) {
97
- const l = a, m = [], u = /* @__PURE__ */ new Set();
98
- function D() {
99
- const t = document.documentElement;
100
- if (!t)
101
- return;
102
- u.forEach((o) => {
103
- t.style.removeProperty(o);
104
- }), u.clear();
105
- const e = [...m].reverse().find(
106
- (o) => o.enabled && o.vars && Object.keys(o.vars).length > 0
107
- );
108
- e && Object.entries(e.vars).forEach(([o, r]) => {
109
- t.style.setProperty(o, r), u.add(o);
110
- });
111
- }
112
- const I = window.matchMedia(Wt), X = window.matchMedia(
113
- Jt
114
- ), L = ct();
115
- Rt(L);
116
- const F = G(L), S = G({
117
- darkMode: y(L)
118
- }), _ = G(null);
119
- I.addEventListener("change", rt), H(
120
- () => l.mode,
121
- () => {
122
- M();
123
- },
124
- { immediate: !0 }
125
- ), H(
126
- () => S.value.darkMode,
127
- (t, e) => {
128
- if (e === void 0) {
129
- at(t);
130
- return;
131
- }
132
- Et(() => {
133
- at(t);
134
- });
135
- },
136
- { immediate: !0 }
137
- ), $t(() => {
138
- I.removeEventListener("change", rt);
139
- const t = m.indexOf(V);
140
- t !== -1 && m.splice(t, 1), D();
141
- });
142
- function M() {
143
- const t = ct();
144
- F.value = t, S.value.darkMode = y(t);
145
- }
146
- function y(t) {
147
- return t === "dark" ? !0 : t === "light" ? !1 : I.matches;
148
- }
149
- function rt(t) {
150
- !t || F.value !== "auto" || (S.value.darkMode = t.matches);
151
- }
152
- function at(t) {
153
- document.documentElement.setAttribute("dark-mode", t);
154
- }
155
- function Et(t) {
156
- if (X.matches) {
157
- t();
158
- return;
159
- }
160
- const e = document.startViewTransition?.bind(document);
161
- if (e) {
162
- e(() => {
163
- t();
164
- });
165
- return;
166
- }
167
- t();
168
- const o = document.documentElement;
169
- typeof o.animate == "function" && window.requestAnimationFrame(() => {
170
- o.animate([{ opacity: 0.85 }, { opacity: 1 }], {
171
- duration: Zt,
172
- easing: "ease-in-out"
173
- });
174
- });
175
- }
176
- function ct() {
177
- return l.mode ?? nt() ?? "auto";
178
- }
179
- mt("theme", S), mt(Tt, _);
180
- function st(t) {
181
- if (!t) return null;
182
- const e = t.trim().toLowerCase();
183
- if (!/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e)) return null;
184
- if (e.length === 4) {
185
- const r = e[1], n = e[2], c = e[3];
186
- return `#${r}${r}${n}${n}${c}${c}`;
187
- }
188
- return e;
189
- }
190
- function lt(t) {
191
- const e = st(t);
192
- if (!e) return null;
193
- const o = parseInt(e.slice(1, 3), 16), r = parseInt(e.slice(3, 5), 16), n = parseInt(e.slice(5, 7), 16);
194
- return { r: o, g: r, b: n };
195
- }
196
- function q({ r: t, g: e, b: o }) {
197
- const r = (n) => n.toString(16).padStart(2, "0");
198
- return `#${r(t)}${r(e)}${r(o)}`;
199
- }
200
- function C(t) {
201
- return Math.max(0, Math.min(1, t));
202
- }
203
- function U(t) {
204
- return t <= 0.04045 ? t / 12.92 : Math.pow((t + 0.055) / 1.055, 2.4);
205
- }
206
- function z(t) {
207
- const e = C(t);
208
- return e <= 31308e-7 ? 12.92 * e : 1.055 * Math.pow(e, 1 / 2.4) - 0.055;
209
- }
210
- function At({ r: t, g: e, b: o }) {
211
- const r = t / 255, n = e / 255, c = o / 255, i = U(r), f = U(n), v = U(c), d = 0.4122214708 * i + 0.5363325363 * f + 0.0514459929 * v, h = 0.2119034982 * i + 0.6806995451 * f + 0.1073969566 * v, b = 0.0883024619 * i + 0.2817188376 * f + 0.6299787005 * v, p = Math.cbrt(d), R = Math.cbrt(h), E = Math.cbrt(b), A = 0.2104542553 * p + 0.793617785 * R - 0.0040720468 * E, g = 1.9779984951 * p - 2.428592205 * R + 0.4505937099 * E, k = 0.0259040371 * p + 0.7827717662 * R - 0.808675766 * E, T = Math.sqrt(g * g + k * k);
212
- let x = Math.atan2(k, g) * (180 / Math.PI);
213
- return x < 0 && (x += 360), { l: A, c: T, h: x };
214
- }
215
- function it(t, e, o, r = !1) {
216
- const n = o * Math.PI / 180, c = e * Math.cos(n), i = e * Math.sin(n), f = t + 0.3963377774 * c + 0.2158037573 * i, v = t - 0.1055613458 * c - 0.0638541728 * i, d = t - 0.0894841775 * c - 1.291485548 * i, h = r ? C(f) : f, b = r ? C(v) : v, p = r ? C(d) : d;
217
- if (!r && (h < -1e-4 || h > 1.0001 || b < -1e-4 || b > 1.0001 || p < -1e-4 || p > 1.0001))
218
- return null;
219
- const R = h * h * h, E = b * b * b, A = p * p * p;
220
- let g = 4.0767416621 * R - 3.3077115913 * E + 0.2309699292 * A, k = -1.2684380046 * R + 2.6097574011 * E - 0.3413193965 * A, T = -0.0041960863 * R - 0.7034186147 * E + 1.707614701 * A;
221
- if (r)
222
- g = C(g), k = C(k), T = C(T);
223
- else if (g < -1e-4 || g > 1.0001 || k < -1e-4 || k > 1.0001 || T < -1e-4 || T > 1.0001)
224
- return null;
225
- const x = C(z(g)), J = C(z(k)), O = C(z(T));
226
- return {
227
- r: Math.round(x * 255),
228
- g: Math.round(J * 255),
229
- b: Math.round(O * 255)
230
- };
231
- }
232
- function W(t, e, o) {
233
- let r = e;
234
- for (let n = 0; n < 8; n += 1) {
235
- const c = it(t, r, o);
236
- if (c)
237
- return c;
238
- r *= 0.9;
239
- }
240
- return it(t, C(r), o, !0) || { r: 0, g: 0, b: 0 };
241
- }
242
- function dt(t) {
243
- const e = lt(t);
244
- if (!e)
245
- return 0;
246
- const o = U(e.r / 255), r = U(e.g / 255), n = U(e.b / 255);
247
- return 0.2126 * o + 0.7152 * r + 0.0722 * n;
248
- }
249
- function N(t, e) {
250
- const o = dt(t), r = dt(e), n = Math.max(o, r), c = Math.min(o, r);
251
- return (n + 0.05) / (c + 0.05);
252
- }
253
- function Dt(t, e, o = {}) {
254
- const r = o.minContrast ?? B, n = o.preferDark !== !1, c = Math.max(
255
- 0.01,
256
- Math.min(0.06, (t.c || 0.12) * (o.chromaScale ?? 0.25))
257
- ), i = o.initialLightness ?? (n ? 0.24 : 0.94), f = n ? -1 : 1, v = o.step ?? 0.03;
258
- let d = C(i), h = q(W(d, c, t.h)), b = N(e, h);
259
- for (let g = 0; g < 48; g += 1) {
260
- const k = q(
261
- W(d, c, t.h)
262
- ), T = N(e, k);
263
- if (T > b && (b = T, h = k), T >= r)
264
- return k;
265
- if (d = C(d + f * v), d === 0 || d === 1)
266
- break;
267
- }
268
- const p = "#101214", R = "#ffffff", E = N(e, p), A = N(e, R);
269
- return E >= r || A >= r ? E >= A ? p : R : h;
270
- }
271
- function $(t, e, o = {}) {
272
- const r = o.minContrast ?? B, n = o.darkCandidate ?? "#101214", c = o.lightCandidate ?? "#ffffff", i = o.preferredCandidate, f = o.preferredMinContrast ?? r, v = o.preferredSwitchDelta ?? 0, d = N(e, n), h = N(e, c), b = d >= r, p = h >= r, R = h >= f, E = d >= f;
273
- if (b || p)
274
- return i === "light" && R ? c : i === "dark" && E ? n : i === "light" && p ? !b || d - h <= v ? c : n : i === "dark" && b ? !p || h - d <= v ? n : c : b && p ? d >= h ? n : c : b ? n : c;
275
- const A = d >= h;
276
- return Dt(t, e, {
277
- minContrast: r,
278
- preferDark: A,
279
- initialLightness: A ? 0.2 : 0.96,
280
- chromaScale: 0.1
281
- });
282
- }
283
- const wt = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1e3], ut = [
284
- 0.9,
285
- 0.84,
286
- 0.78,
287
- 0.72,
288
- 0.67,
289
- 0.62,
290
- 0.56,
291
- 0.5,
292
- 0.44,
293
- 0.38
294
- ], It = [
295
- 0.28,
296
- 0.4,
297
- 0.54,
298
- 0.7,
299
- 0.86,
300
- 1,
301
- 1.08,
302
- 1.14,
303
- 1.2,
304
- 1.24
305
- ];
306
- function P(t, e, o, r) {
307
- const n = e[e.length - 1];
308
- for (const c of e) {
309
- const i = t[c];
310
- if (i && N(i, o) >= r)
311
- return c;
312
- }
313
- return n;
314
- }
315
- function yt(t) {
316
- const e = t.l - ut[5], o = t.c > 0.02 ? 0.02 : 0;
317
- return wt.reduce((r, n, c) => {
318
- const i = C(
319
- ut[c] + e
320
- ), f = Math.min(
321
- 0.4,
322
- Math.max(
323
- o,
324
- t.c * It[c]
325
- )
326
- );
327
- return r[n] = q(W(i, f, t.h)), r;
328
- }, {});
329
- }
330
- function Nt(t, e) {
331
- const o = [100, 200, 300, 400, 500, 600, 700], r = P(
332
- e,
333
- o,
334
- tt,
335
- kt
336
- ), n = o.indexOf(r), c = o[Math.min(n + 1, o.length - 1)], i = o[Math.min(n + 2, o.length - 1)], f = [1e3, 900, 800, 700, 600, 500], v = P(
337
- e,
338
- f,
339
- et,
340
- kt
341
- ), d = f.indexOf(v), h = f[Math.min(d + 1, f.length - 1)], b = f[Math.min(d + 2, f.length - 1)], R = P(
342
- e,
343
- [200, 300, 400, 500, 600, 700, 800],
344
- tt,
345
- St
346
- ), A = P(
347
- e,
348
- [900, 800, 700, 600, 500, 400],
349
- et,
350
- St
351
- ), g = [600, 700, 800, 900, 1e3], k = P(
352
- e,
353
- g,
354
- tt,
355
- pt
356
- ), T = g.indexOf(k), x = g[Math.min(T + 1, g.length - 1)], J = g[Math.min(T + 2, g.length - 1)], O = [400, 300, 200, 100], j = P(
357
- e,
358
- O,
359
- et,
360
- pt
361
- ), ht = O.indexOf(j), Lt = O[Math.min(ht + 1, O.length - 1)], xt = O[Math.min(ht + 2, O.length - 1)], s = {
362
- "--color-brand-surface-soft-light": e[r],
363
- "--color-brand-surface-soft-hovered-light": e[c],
364
- "--color-brand-surface-soft-pressed-light": e[i],
365
- "--color-brand-surface-soft-dark": e[v],
366
- "--color-brand-surface-soft-hovered-dark": e[h],
367
- "--color-brand-surface-soft-pressed-dark": e[b],
368
- "--color-brand-surface-subtle-light": e[R],
369
- "--color-brand-surface-subtle-dark": e[A],
370
- "--color-brand-surface-strong-light": e[k],
371
- "--color-brand-surface-strong-hovered-light": e[x],
372
- "--color-brand-surface-strong-pressed-light": e[J],
373
- "--color-brand-surface-strong-dark": e[j],
374
- "--color-brand-surface-strong-hovered-dark": e[Lt],
375
- "--color-brand-surface-strong-pressed-dark": e[xt]
376
- }, gt = e[600], Bt = N(
377
- s["--color-brand-surface-soft-light"],
378
- gt
379
- );
380
- return s["--color-brand-on-soft-light"] = Bt >= B ? gt : $(
381
- t,
382
- s["--color-brand-surface-soft-light"],
383
- {
384
- minContrast: B
385
- }
386
- ), s["--color-brand-on-soft-dark"] = $(
387
- t,
388
- s["--color-brand-surface-soft-dark"],
389
- {
390
- minContrast: B
391
- }
392
- ), s["--color-brand-on-subtle-light"] = $(
393
- t,
394
- s["--color-brand-surface-subtle-light"],
395
- {
396
- minContrast: Y,
397
- preferredCandidate: "light",
398
- preferredMinContrast: Y,
399
- preferredSwitchDelta: Mt
400
- }
401
- ), s["--color-brand-on-subtle-dark"] = $(
402
- t,
403
- s["--color-brand-surface-subtle-dark"],
404
- {
405
- minContrast: B
406
- }
407
- ), s["--color-brand-on-strong-light"] = $(
408
- t,
409
- s["--color-brand-surface-strong-light"],
410
- {
411
- minContrast: Y,
412
- preferredCandidate: "light",
413
- preferredMinContrast: Y,
414
- preferredSwitchDelta: Mt
415
- }
416
- ), s["--color-brand-on-strong-dark"] = $(
417
- t,
418
- s["--color-brand-surface-strong-dark"],
419
- {
420
- minContrast: B
421
- }
422
- ), s["--color-brand-text-light"] = s["--color-brand-surface-strong-light"], s["--color-brand-text-dark"] = s["--color-brand-surface-strong-dark"], s["--color-brand-icon-light"] = s["--color-brand-surface-strong-light"], s["--color-brand-icon-dark"] = s["--color-brand-surface-strong-dark"], s["--color-brand-border-light"] = s["--color-brand-surface-strong-light"], s["--color-brand-border-dark"] = s["--color-brand-surface-strong-dark"], s;
423
- }
424
- function Ot(t) {
425
- const e = st(t);
426
- if (!e)
427
- return null;
428
- const o = lt(e);
429
- if (!o)
430
- return null;
431
- const r = At(o), n = yt(r);
432
- return n[600] = e, {
433
- "--color-brand-seed": e,
434
- "--color-brand-100": n[100],
435
- "--color-brand-200": n[200],
436
- "--color-brand-300": n[300],
437
- "--color-brand-400": n[400],
438
- "--color-brand-500": n[500],
439
- "--color-brand-600": n[600],
440
- "--color-brand-700": n[700],
441
- "--color-brand-800": n[800],
442
- "--color-brand-900": n[900],
443
- "--color-brand-1000": n[1e3],
444
- ...Nt(r, n)
445
- };
446
- }
447
- const ft = ot(() => Ot(l.accentColor) ?? {}), V = {
448
- vars: {},
449
- enabled: !!l.exposeGlobalAccent
450
- };
451
- return m.push(V), H(
452
- () => l.exposeGlobalAccent,
453
- (t) => {
454
- V.enabled = !!t, D();
455
- },
456
- { immediate: !0 }
457
- ), H(
458
- ft,
459
- (t) => {
460
- t && Object.keys(t).length > 0 ? V.vars = { ...t } : V.vars = {}, D();
461
- },
462
- { immediate: !0 }
463
- ), (t, e) => (_t(), Pt("div", {
464
- class: "theme",
465
- style: Ht(ft.value)
466
- }, [
467
- Ft(t.$slots, "default"),
468
- Ct("div", {
469
- ref_key: "portalHost",
470
- ref: _,
471
- class: "theme__portal-host"
472
- }, null, 512)
473
- ], 4));
474
- }
475
- }), te = (a, l) => {
476
- const m = a.__vccOpts || a;
477
- for (const [u, D] of l)
478
- m[u] = D;
479
- return m;
480
- }, ee = {
481
- __name: "ThemeSwitcher",
482
- props: {
483
- mode: {
484
- type: String,
485
- default: "auto",
486
- validator: (a) => ["auto", "light", "dark"].includes(a)
487
- }
488
- },
489
- emits: ["update:mode"],
490
- setup(a, { emit: l }) {
491
- const u = [
492
- { value: "auto", label: "System" },
493
- { value: "light", label: "Light" },
494
- { value: "dark", label: "Dark" }
495
- ].reduce((_, M) => (_[M.value] = M.label, _), {}), D = Q, I = a, X = l;
496
- Rt();
497
- const L = G(!1), F = nt() ?? I.mode, S = G(
498
- D.includes(F) ? F : "auto"
499
- );
500
- return ot(
501
- () => u[S.value] ?? u.auto
502
- ), H(
503
- () => I.mode,
504
- (_) => {
505
- D.includes(_) && _ !== S.value && (S.value = _);
506
- }
507
- ), H(
508
- S,
509
- (_) => {
510
- if (!D.includes(_)) {
511
- S.value = "auto";
512
- return;
513
- }
514
- L.value = !1, X("update:mode", _), Qt(_);
515
- },
516
- { immediate: !0 }
517
- ), (_, M) => (_t(), Vt(w(Gt), {
518
- open: L.value,
519
- "onUpdate:open": M[3] || (M[3] = (y) => L.value = y),
520
- text: "Theme",
521
- "aria-label": "Select theme mode"
522
- }, {
523
- default: bt(() => [
524
- K(w(jt), { title: "Theme" }, {
525
- default: bt(() => [
526
- K(w(Z), {
527
- checked: S.value,
528
- "onUpdate:checked": M[0] || (M[0] = (y) => S.value = y),
529
- value: "auto",
530
- label: w(u).auto,
531
- "aria-label": `${w(u).auto} mode`
532
- }, null, 8, ["checked", "label", "aria-label"]),
533
- M[4] || (M[4] = Ct("hr", {
534
- class: "theme-switcher-divider",
535
- role: "separator"
536
- }, null, -1)),
537
- K(w(Z), {
538
- checked: S.value,
539
- "onUpdate:checked": M[1] || (M[1] = (y) => S.value = y),
540
- value: "light",
541
- label: w(u).light,
542
- "aria-label": `${w(u).light} mode`
543
- }, null, 8, ["checked", "label", "aria-label"]),
544
- K(w(Z), {
545
- checked: S.value,
546
- "onUpdate:checked": M[2] || (M[2] = (y) => S.value = y),
547
- value: "dark",
548
- label: w(u).dark,
549
- "aria-label": `${w(u).dark} mode`
550
- }, null, 8, ["checked", "label", "aria-label"])
551
- ]),
552
- _: 1
553
- })
554
- ]),
555
- _: 1
556
- }, 8, ["open"]));
557
- }
558
- }, se = /* @__PURE__ */ te(ee, [["__scopeId", "data-v-bcbc87cb"]]);
559
- export {
560
- ce as Theme,
561
- se as ThemeSwitcher,
562
- Tt as themePortalHostKey,
563
- ae as useThemePortalTarget
564
- };
565
- //# sourceMappingURL=theme.es.js.map
62
+ //#endregion
63
+ //#region src/Theme.vue
64
+ var ee = "(prefers-color-scheme: dark)", te = "(prefers-reduced-motion: reduce)", ne = 200, A = 3.8, j = 1.8, M = 1.15, N = 1.08, P = 2.5, F = 3, I = "#ffffff", L = "#1f2228", R = /* @__PURE__ */ Object.assign({ name: "Theme" }, {
65
+ __name: "Theme",
66
+ props: {
67
+ mode: {
68
+ type: String,
69
+ validator: (e) => [
70
+ "auto",
71
+ "light",
72
+ "dark"
73
+ ].includes(e)
74
+ },
75
+ accentColor: {
76
+ type: String,
77
+ required: !1,
78
+ default: void 0
79
+ },
80
+ exposeGlobalAccent: {
81
+ type: Boolean,
82
+ default: !1
83
+ }
84
+ },
85
+ setup(t) {
86
+ let i = t, a = [], f = /* @__PURE__ */ new Set();
87
+ function m() {
88
+ let e = document.documentElement;
89
+ if (!e) return;
90
+ f.forEach((t) => {
91
+ e.style.removeProperty(t);
92
+ }), f.clear();
93
+ let t = [...a].reverse().find((e) => e.enabled && e.vars && Object.keys(e.vars).length > 0);
94
+ t && Object.entries(t.vars).forEach(([t, n]) => {
95
+ e.style.setProperty(t, n), f.add(t);
96
+ });
97
+ }
98
+ let h = window.matchMedia(ee), g = window.matchMedia(te), _ = k();
99
+ w(_);
100
+ let v = u(_), y = u({ darkMode: C(_) }), b = u(null);
101
+ h.addEventListener("change", T), p(() => i.mode, () => {
102
+ x();
103
+ }, { immediate: !0 }), p(() => y.value.darkMode, (e, t) => {
104
+ if (t === void 0) {
105
+ E(e);
106
+ return;
107
+ }
108
+ D(() => {
109
+ E(e);
110
+ });
111
+ }, { immediate: !0 }), s(() => {
112
+ h.removeEventListener("change", T);
113
+ let e = a.indexOf($);
114
+ e !== -1 && a.splice(e, 1), m();
115
+ });
116
+ function x() {
117
+ let e = k();
118
+ v.value = e, y.value.darkMode = C(e);
119
+ }
120
+ function C(e) {
121
+ return e === "dark" ? !0 : e === "light" ? !1 : h.matches;
122
+ }
123
+ function T(e) {
124
+ !e || v.value !== "auto" || (y.value.darkMode = e.matches);
125
+ }
126
+ function E(e) {
127
+ document.documentElement.setAttribute("dark-mode", e);
128
+ }
129
+ function D(e) {
130
+ if (g.matches) {
131
+ e();
132
+ return;
133
+ }
134
+ let t = document.startViewTransition?.bind(document);
135
+ if (t) {
136
+ t(() => {
137
+ e();
138
+ });
139
+ return;
140
+ }
141
+ e();
142
+ let n = document.documentElement;
143
+ typeof n.animate == "function" && window.requestAnimationFrame(() => {
144
+ n.animate([{ opacity: .85 }, { opacity: 1 }], {
145
+ duration: ne,
146
+ easing: "ease-in-out"
147
+ });
148
+ });
149
+ }
150
+ function k() {
151
+ return i.mode ?? S() ?? "auto";
152
+ }
153
+ l("theme", y), l(O, b);
154
+ function R(e) {
155
+ if (!e) return null;
156
+ let t = e.trim().toLowerCase();
157
+ if (!/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t)) return null;
158
+ if (t.length === 4) {
159
+ let e = t[1], n = t[2], r = t[3];
160
+ return `#${e}${e}${n}${n}${r}${r}`;
161
+ }
162
+ return t;
163
+ }
164
+ function z(e) {
165
+ let t = R(e);
166
+ return t ? {
167
+ r: parseInt(t.slice(1, 3), 16),
168
+ g: parseInt(t.slice(3, 5), 16),
169
+ b: parseInt(t.slice(5, 7), 16)
170
+ } : null;
171
+ }
172
+ function B({ r: e, g: t, b: n }) {
173
+ let r = (e) => e.toString(16).padStart(2, "0");
174
+ return `#${r(e)}${r(t)}${r(n)}`;
175
+ }
176
+ function V(e) {
177
+ return Math.max(0, Math.min(1, e));
178
+ }
179
+ function H(e) {
180
+ return e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4;
181
+ }
182
+ function U(e) {
183
+ let t = V(e);
184
+ return t <= .0031308 ? 12.92 * t : 1.055 * t ** (1 / 2.4) - .055;
185
+ }
186
+ function W({ r: e, g: t, b: n }) {
187
+ let r = e / 255, i = t / 255, a = n / 255, o = H(r), s = H(i), c = H(a), l = .4122214708 * o + .5363325363 * s + .0514459929 * c, u = .2119034982 * o + .6806995451 * s + .1073969566 * c, d = .0883024619 * o + .2817188376 * s + .6299787005 * c, f = Math.cbrt(l), p = Math.cbrt(u), m = Math.cbrt(d), h = .2104542553 * f + .793617785 * p - .0040720468 * m, g = 1.9779984951 * f - 2.428592205 * p + .4505937099 * m, _ = .0259040371 * f + .7827717662 * p - .808675766 * m, v = Math.sqrt(g * g + _ * _), y = 180 / Math.PI * Math.atan2(_, g);
188
+ return y < 0 && (y += 360), {
189
+ l: h,
190
+ c: v,
191
+ h: y
192
+ };
193
+ }
194
+ function G(e, t, n, r = !1) {
195
+ let i = n * Math.PI / 180, a = t * Math.cos(i), o = t * Math.sin(i), s = e + .3963377774 * a + .2158037573 * o, c = e - .1055613458 * a - .0638541728 * o, l = e - .0894841775 * a - 1.291485548 * o, u = r ? V(s) : s, d = r ? V(c) : c, f = r ? V(l) : l;
196
+ if (!r && (u < -1e-4 || u > 1.0001 || d < -1e-4 || d > 1.0001 || f < -1e-4 || f > 1.0001)) return null;
197
+ let p = u * u * u, m = d * d * d, h = f * f * f, g = 4.0767416621 * p - 3.3077115913 * m + .2309699292 * h, _ = -1.2684380046 * p + 2.6097574011 * m - .3413193965 * h, v = -.0041960863 * p - .7034186147 * m + 1.707614701 * h;
198
+ if (r) g = V(g), _ = V(_), v = V(v);
199
+ else if (g < -1e-4 || g > 1.0001 || _ < -1e-4 || _ > 1.0001 || v < -1e-4 || v > 1.0001) return null;
200
+ let y = V(U(g)), b = V(U(_)), x = V(U(v));
201
+ return {
202
+ r: Math.round(y * 255),
203
+ g: Math.round(b * 255),
204
+ b: Math.round(x * 255)
205
+ };
206
+ }
207
+ function K(e, t, n) {
208
+ let r = t;
209
+ for (let t = 0; t < 8; t += 1) {
210
+ let t = G(e, r, n);
211
+ if (t) return t;
212
+ r *= .9;
213
+ }
214
+ return G(e, V(r), n, !0) || {
215
+ r: 0,
216
+ g: 0,
217
+ b: 0
218
+ };
219
+ }
220
+ function q(e) {
221
+ let t = z(e);
222
+ if (!t) return 0;
223
+ let n = H(t.r / 255), r = H(t.g / 255), i = H(t.b / 255);
224
+ return .2126 * n + .7152 * r + .0722 * i;
225
+ }
226
+ function J(e, t) {
227
+ let n = q(e), r = q(t), i = Math.max(n, r), a = Math.min(n, r);
228
+ return (i + .05) / (a + .05);
229
+ }
230
+ function re(e, t, n = {}) {
231
+ let r = n.minContrast ?? A, i = n.preferDark !== !1, a = Math.max(.01, Math.min(.06, (e.c || .12) * (n.chromaScale ?? .25))), o = n.initialLightness ?? (i ? .24 : .94), s = i ? -1 : 1, c = n.step ?? .03, l = V(o), u = B(K(l, a, e.h)), d = J(t, u);
232
+ for (let n = 0; n < 48; n += 1) {
233
+ let n = B(K(l, a, e.h)), i = J(t, n);
234
+ if (i > d && (d = i, u = n), i >= r) return n;
235
+ if (l = V(l + s * c), l === 0 || l === 1) break;
236
+ }
237
+ let f = "#101214", p = "#ffffff", m = J(t, f), h = J(t, p);
238
+ return m >= r || h >= r ? m >= h ? f : p : u;
239
+ }
240
+ function Y(e, t, n = {}) {
241
+ let r = n.minContrast ?? A, i = n.darkCandidate ?? "#101214", a = n.lightCandidate ?? "#ffffff", o = n.preferredCandidate, s = n.preferredMinContrast ?? r, c = n.preferredSwitchDelta ?? 0, l = J(t, i), u = J(t, a), d = l >= r, f = u >= r, p = u >= s, m = l >= s;
242
+ if (d || f) return o === "light" && p ? a : o === "dark" && m ? i : o === "light" && f ? !d || l - u <= c ? a : i : o === "dark" && d ? !f || u - l <= c ? i : a : d && f ? l >= u ? i : a : d ? i : a;
243
+ let h = l >= u;
244
+ return re(e, t, {
245
+ minContrast: r,
246
+ preferDark: h,
247
+ initialLightness: h ? .2 : .96,
248
+ chromaScale: .1
249
+ });
250
+ }
251
+ let ie = [
252
+ 100,
253
+ 200,
254
+ 300,
255
+ 400,
256
+ 500,
257
+ 600,
258
+ 700,
259
+ 800,
260
+ 900,
261
+ 1e3
262
+ ], X = [
263
+ .9,
264
+ .84,
265
+ .78,
266
+ .72,
267
+ .67,
268
+ .62,
269
+ .56,
270
+ .5,
271
+ .44,
272
+ .38
273
+ ], ae = [
274
+ .28,
275
+ .4,
276
+ .54,
277
+ .7,
278
+ .86,
279
+ 1,
280
+ 1.08,
281
+ 1.14,
282
+ 1.2,
283
+ 1.24
284
+ ];
285
+ function Z(e, t, n, r) {
286
+ let i = t[t.length - 1];
287
+ for (let i of t) {
288
+ let t = e[i];
289
+ if (t && J(t, n) >= r) return i;
290
+ }
291
+ return i;
292
+ }
293
+ function oe(e) {
294
+ let t = e.l - X[5], n = e.c > .02 ? .02 : 0;
295
+ return ie.reduce((r, i, a) => (r[i] = B(K(V(X[a] + t), Math.min(.4, Math.max(n, e.c * ae[a])), e.h)), r), {});
296
+ }
297
+ function se(e, t) {
298
+ let n = [
299
+ 100,
300
+ 200,
301
+ 300,
302
+ 400,
303
+ 500,
304
+ 600,
305
+ 700
306
+ ], r = Z(t, n, I, N), i = n.indexOf(r), a = n[Math.min(i + 1, n.length - 1)], o = n[Math.min(i + 2, n.length - 1)], s = [
307
+ 1e3,
308
+ 900,
309
+ 800,
310
+ 700,
311
+ 600,
312
+ 500
313
+ ], c = Z(t, s, L, N), l = s.indexOf(c), u = s[Math.min(l + 1, s.length - 1)], d = s[Math.min(l + 2, s.length - 1)], f = Z(t, [
314
+ 200,
315
+ 300,
316
+ 400,
317
+ 500,
318
+ 600,
319
+ 700,
320
+ 800
321
+ ], I, M), p = Z(t, [
322
+ 900,
323
+ 800,
324
+ 700,
325
+ 600,
326
+ 500,
327
+ 400
328
+ ], L, M), m = [
329
+ 600,
330
+ 700,
331
+ 800,
332
+ 900,
333
+ 1e3
334
+ ], h = Z(t, m, I, j), g = m.indexOf(h), _ = m[Math.min(g + 1, m.length - 1)], v = m[Math.min(g + 2, m.length - 1)], y = [
335
+ 400,
336
+ 300,
337
+ 200,
338
+ 100
339
+ ], b = Z(t, y, L, j), x = y.indexOf(b), S = y[Math.min(x + 1, y.length - 1)], C = y[Math.min(x + 2, y.length - 1)], w = {
340
+ "--color-brand-surface-soft-light": t[r],
341
+ "--color-brand-surface-soft-hovered-light": t[a],
342
+ "--color-brand-surface-soft-pressed-light": t[o],
343
+ "--color-brand-surface-soft-dark": t[c],
344
+ "--color-brand-surface-soft-hovered-dark": t[u],
345
+ "--color-brand-surface-soft-pressed-dark": t[d],
346
+ "--color-brand-surface-subtle-light": t[f],
347
+ "--color-brand-surface-subtle-dark": t[p],
348
+ "--color-brand-surface-strong-light": t[h],
349
+ "--color-brand-surface-strong-hovered-light": t[_],
350
+ "--color-brand-surface-strong-pressed-light": t[v],
351
+ "--color-brand-surface-strong-dark": t[b],
352
+ "--color-brand-surface-strong-hovered-dark": t[S],
353
+ "--color-brand-surface-strong-pressed-dark": t[C]
354
+ }, T = t[600];
355
+ return w["--color-brand-on-soft-light"] = J(w["--color-brand-surface-soft-light"], T) >= A ? T : Y(e, w["--color-brand-surface-soft-light"], { minContrast: A }), w["--color-brand-on-soft-dark"] = Y(e, w["--color-brand-surface-soft-dark"], { minContrast: A }), w["--color-brand-on-subtle-light"] = Y(e, w["--color-brand-surface-subtle-light"], {
356
+ minContrast: P,
357
+ preferredCandidate: "light",
358
+ preferredMinContrast: P,
359
+ preferredSwitchDelta: F
360
+ }), w["--color-brand-on-subtle-dark"] = Y(e, w["--color-brand-surface-subtle-dark"], { minContrast: A }), w["--color-brand-on-strong-light"] = Y(e, w["--color-brand-surface-strong-light"], {
361
+ minContrast: P,
362
+ preferredCandidate: "light",
363
+ preferredMinContrast: P,
364
+ preferredSwitchDelta: F
365
+ }), w["--color-brand-on-strong-dark"] = Y(e, w["--color-brand-surface-strong-dark"], { minContrast: A }), w["--color-brand-text-light"] = w["--color-brand-surface-strong-light"], w["--color-brand-text-dark"] = w["--color-brand-surface-strong-dark"], w["--color-brand-icon-light"] = w["--color-brand-surface-strong-light"], w["--color-brand-icon-dark"] = w["--color-brand-surface-strong-dark"], w["--color-brand-border-light"] = w["--color-brand-surface-strong-light"], w["--color-brand-border-dark"] = w["--color-brand-surface-strong-dark"], w;
366
+ }
367
+ function ce(e) {
368
+ let t = R(e);
369
+ if (!t) return null;
370
+ let n = z(t);
371
+ if (!n) return null;
372
+ let r = W(n), i = oe(r);
373
+ return i[600] = t, {
374
+ "--color-brand-seed": t,
375
+ "--color-brand-100": i[100],
376
+ "--color-brand-200": i[200],
377
+ "--color-brand-300": i[300],
378
+ "--color-brand-400": i[400],
379
+ "--color-brand-500": i[500],
380
+ "--color-brand-600": i[600],
381
+ "--color-brand-700": i[700],
382
+ "--color-brand-800": i[800],
383
+ "--color-brand-900": i[900],
384
+ "--color-brand-1000": i[1e3],
385
+ ...se(r, i)
386
+ };
387
+ }
388
+ let Q = e(() => ce(i.accentColor) ?? {}), $ = {
389
+ vars: {},
390
+ enabled: !!i.exposeGlobalAccent
391
+ };
392
+ return a.push($), p(() => i.exposeGlobalAccent, (e) => {
393
+ $.enabled = !!e, m();
394
+ }, { immediate: !0 }), p(Q, (e) => {
395
+ e && Object.keys(e).length > 0 ? $.vars = { ...e } : $.vars = {}, m();
396
+ }, { immediate: !0 }), (e, t) => (c(), n("div", {
397
+ class: "theme",
398
+ style: o(Q.value)
399
+ }, [d(e.$slots, "default"), r("div", {
400
+ ref_key: "portalHost",
401
+ ref: b,
402
+ class: "theme__portal-host"
403
+ }, null, 512)], 4));
404
+ }
405
+ }), z = /* @__PURE__ */ ((e, t) => {
406
+ let n = e.__vccOpts || e;
407
+ for (let [e, r] of t) n[e] = r;
408
+ return n;
409
+ })({
410
+ __name: "ThemeSwitcher",
411
+ props: { mode: {
412
+ type: String,
413
+ default: "auto",
414
+ validator: (e) => [
415
+ "auto",
416
+ "light",
417
+ "dark"
418
+ ].includes(e)
419
+ } },
420
+ emits: ["update:mode"],
421
+ setup(n, { emit: a }) {
422
+ let o = [
423
+ {
424
+ value: "auto",
425
+ label: "System"
426
+ },
427
+ {
428
+ value: "light",
429
+ label: "Light"
430
+ },
431
+ {
432
+ value: "dark",
433
+ label: "Dark"
434
+ }
435
+ ].reduce((e, t) => (e[t.value] = t.label, e), {}), s = v, l = n, d = a;
436
+ w();
437
+ let y = u(!1), b = S() ?? l.mode, x = u(s.includes(b) ? b : "auto");
438
+ return e(() => o[x.value] ?? o.auto), p(() => l.mode, (e) => {
439
+ s.includes(e) && e !== x.value && (x.value = e);
440
+ }), p(x, (e) => {
441
+ if (!s.includes(e)) {
442
+ x.value = "auto";
443
+ return;
444
+ }
445
+ y.value = !1, d("update:mode", e), C(e);
446
+ }, { immediate: !0 }), (e, n) => (c(), t(f(_), {
447
+ open: y.value,
448
+ "onUpdate:open": n[3] ||= (e) => y.value = e,
449
+ text: "Theme",
450
+ "aria-label": "Select theme mode"
451
+ }, {
452
+ default: m(() => [i(f(h), { title: "Theme" }, {
453
+ default: m(() => [
454
+ i(f(g), {
455
+ checked: x.value,
456
+ "onUpdate:checked": n[0] ||= (e) => x.value = e,
457
+ value: "auto",
458
+ label: f(o).auto,
459
+ "aria-label": `${f(o).auto} mode`
460
+ }, null, 8, [
461
+ "checked",
462
+ "label",
463
+ "aria-label"
464
+ ]),
465
+ n[4] ||= r("hr", {
466
+ class: "theme-switcher-divider",
467
+ role: "separator"
468
+ }, null, -1),
469
+ i(f(g), {
470
+ checked: x.value,
471
+ "onUpdate:checked": n[1] ||= (e) => x.value = e,
472
+ value: "light",
473
+ label: f(o).light,
474
+ "aria-label": `${f(o).light} mode`
475
+ }, null, 8, [
476
+ "checked",
477
+ "label",
478
+ "aria-label"
479
+ ]),
480
+ i(f(g), {
481
+ checked: x.value,
482
+ "onUpdate:checked": n[2] ||= (e) => x.value = e,
483
+ value: "dark",
484
+ label: f(o).dark,
485
+ "aria-label": `${f(o).dark} mode`
486
+ }, null, 8, [
487
+ "checked",
488
+ "label",
489
+ "aria-label"
490
+ ])
491
+ ]),
492
+ _: 1
493
+ })]),
494
+ _: 1
495
+ }, 8, ["open"]));
496
+ }
497
+ }, [["__scopeId", "data-v-bcbc87cb"]]);
498
+ //#endregion
499
+ export { R as Theme, z as ThemeSwitcher, O as themePortalHostKey, k as useThemePortalTarget };
500
+
501
+ //# sourceMappingURL=theme.es.js.map