@lanrenbang/basecoat-ultra 0.1.4 → 0.1.5

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.
@@ -89,7 +89,44 @@
89
89
  color-scheme: dark;
90
90
  }
91
91
 
92
- @import "../config.css";
92
+ @theme {
93
+ --radius-sm: calc(var(--radius) - 4px);
94
+ --radius-md: calc(var(--radius) - 2px);
95
+ --radius-lg: var(--radius);
96
+ --radius-xl: calc(var(--radius) + 4px);
97
+ --color-background: var(--background);
98
+ --color-foreground: var(--foreground);
99
+ --color-card: var(--card);
100
+ --color-card-foreground: var(--card-foreground);
101
+ --color-popover: var(--popover);
102
+ --color-popover-foreground: var(--popover-foreground);
103
+ --color-primary: var(--primary);
104
+ --color-primary-foreground: var(--primary-foreground);
105
+ --color-secondary: var(--secondary);
106
+ --color-secondary-foreground: var(--secondary-foreground);
107
+ --color-muted: var(--muted);
108
+ --color-muted-foreground: var(--muted-foreground);
109
+ --color-accent: var(--accent);
110
+ --color-accent-foreground: var(--accent-foreground);
111
+ --color-destructive: var(--destructive);
112
+ --color-border: var(--border);
113
+ --color-input: var(--input);
114
+ --color-ring: var(--ring);
115
+ --color-chart-1: var(--chart-1);
116
+ --color-chart-2: var(--chart-2);
117
+ --color-chart-3: var(--chart-3);
118
+ --color-chart-4: var(--chart-4);
119
+ --color-chart-5: var(--chart-5);
120
+ --color-sidebar: var(--sidebar);
121
+ --color-sidebar-foreground: var(--sidebar-foreground);
122
+ --color-sidebar-primary: var(--sidebar-primary);
123
+ --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
124
+ --color-sidebar-accent: var(--sidebar-accent);
125
+ --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
126
+ --color-sidebar-border: var(--sidebar-border);
127
+ --color-sidebar-ring: var(--sidebar-ring);
128
+ }
129
+
93
130
 
94
131
  @layer base {
95
132
  * {
@@ -39,6 +39,7 @@
39
39
  try {
40
40
  localStorage.setItem("catppuccin-theme", theme);
41
41
  localStorage.setItem("catppuccin-accent", accent);
42
+ localStorage.removeItem("basecoat-mode");
42
43
  } catch (e) {
43
44
  }
44
45
  }
@@ -46,10 +47,21 @@
46
47
  try {
47
48
  const savedTheme = localStorage.getItem("catppuccin-theme");
48
49
  const savedAccent = localStorage.getItem("catppuccin-accent");
50
+ const savedMode = localStorage.getItem("basecoat-mode");
49
51
  if (savedTheme && savedAccent) {
50
52
  setTheme(savedTheme, savedAccent);
53
+ } else if (savedMode) {
54
+ if (savedMode === "dark") {
55
+ document.documentElement.classList.add("dark");
56
+ } else {
57
+ document.documentElement.classList.remove("dark");
58
+ }
59
+ } else {
60
+ const isSystemDark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
61
+ document.documentElement.classList.toggle("dark", isSystemDark);
51
62
  }
52
63
  } catch (e) {
64
+ console.error("Basecoat: Theme initialization failed", e);
53
65
  }
54
66
  }
55
67
  initTheme();
@@ -57,8 +69,10 @@
57
69
  const flavorGroup = container.querySelector(".theme-flavors");
58
70
  const accentGrid = container.querySelector(".theme-accents");
59
71
  const resetButton = container.querySelector(".theme-reset");
60
- let currentFlavor = localStorage.getItem("catppuccin-theme") || "latte";
61
- if (!THEMES.includes(currentFlavor)) currentFlavor = "latte";
72
+ let currentFlavor = localStorage.getItem("catppuccin-theme");
73
+ if (!currentFlavor || !THEMES.includes(currentFlavor)) {
74
+ currentFlavor = document.documentElement.classList.contains("dark") ? "mocha" : "latte";
75
+ }
62
76
  if (flavorGroup) {
63
77
  flavorGroup.innerHTML = "";
64
78
  flavorGroup.className = "button-group w-full";
@@ -100,6 +114,7 @@
100
114
  btn.dataset.side = "top";
101
115
  btn.onclick = () => {
102
116
  setTheme(currentFlavor, acc);
117
+ updateFlavorUI();
103
118
  };
104
119
  accentGrid.appendChild(btn);
105
120
  });
@@ -116,15 +131,20 @@
116
131
  if (resetButton) {
117
132
  resetButton.addEventListener("click", () => {
118
133
  const root = document.documentElement;
134
+ const wasDark = root.classList.contains("dark");
119
135
  THEMES.forEach((t) => root.classList.remove(`theme-${t}`));
120
136
  ACCENTS.forEach((a) => root.classList.remove(`accent-${a}`));
121
137
  localStorage.removeItem("catppuccin-theme");
122
138
  localStorage.removeItem("catppuccin-accent");
123
- if (DARK_THEMES.includes(currentFlavor)) {
139
+ localStorage.setItem("basecoat-mode", wasDark ? "dark" : "light");
140
+ if (wasDark) {
124
141
  root.classList.add("dark");
125
142
  } else {
126
143
  root.classList.remove("dark");
127
144
  }
145
+ currentFlavor = wasDark ? "mocha" : "latte";
146
+ updateFlavorUI();
147
+ renderAccents();
128
148
  });
129
149
  }
130
150
  updateFlavorUI();
@@ -1,5 +1,5 @@
1
1
  (() => {
2
- const l = ["latte", "frappe", "macchiato", "mocha"], d = ["frappe", "macchiato", "mocha"], i = [
2
+ const l = ["latte", "frappe", "macchiato", "mocha"], p = ["frappe", "macchiato", "mocha"], i = [
3
3
  "rosewater",
4
4
  "flamingo",
5
5
  "pink",
@@ -15,59 +15,67 @@
15
15
  "blue",
16
16
  "lavender"
17
17
  ];
18
- function f(c) {
19
- if (!l.includes(c)) return {};
20
- const t = { background: `var(--ctp-${c}-base)` };
21
- return i.forEach((o) => {
22
- t[o] = `var(--ctp-${c}-${o})`;
23
- }), t;
18
+ function f(o) {
19
+ if (!l.includes(o)) return {};
20
+ const a = { background: `var(--ctp-${o}-base)` };
21
+ return i.forEach((t) => {
22
+ a[t] = `var(--ctp-${o}-${t})`;
23
+ }), a;
24
24
  }
25
- function u(c, t) {
26
- const o = document.documentElement;
27
- l.forEach((s) => o.classList.remove(`theme-${s}`)), i.forEach((s) => o.classList.remove(`accent-${s}`)), o.classList.add(`theme-${c}`), o.classList.add(`accent-${t}`), d.includes(c) ? o.classList.add("dark") : o.classList.remove("dark");
25
+ function u(o, a) {
26
+ const t = document.documentElement;
27
+ l.forEach((r) => t.classList.remove(`theme-${r}`)), i.forEach((r) => t.classList.remove(`accent-${r}`)), t.classList.add(`theme-${o}`), t.classList.add(`accent-${a}`), p.includes(o) ? t.classList.add("dark") : t.classList.remove("dark");
28
28
  try {
29
- localStorage.setItem("catppuccin-theme", c), localStorage.setItem("catppuccin-accent", t);
29
+ localStorage.setItem("catppuccin-theme", o), localStorage.setItem("catppuccin-accent", a), localStorage.removeItem("basecoat-mode");
30
30
  } catch {
31
31
  }
32
32
  }
33
33
  function h() {
34
34
  try {
35
- const c = localStorage.getItem("catppuccin-theme"), t = localStorage.getItem("catppuccin-accent");
36
- c && t && u(c, t);
37
- } catch {
35
+ const o = localStorage.getItem("catppuccin-theme"), a = localStorage.getItem("catppuccin-accent"), t = localStorage.getItem("basecoat-mode");
36
+ if (o && a)
37
+ u(o, a);
38
+ else if (t)
39
+ t === "dark" ? document.documentElement.classList.add("dark") : document.documentElement.classList.remove("dark");
40
+ else {
41
+ const r = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
42
+ document.documentElement.classList.toggle("dark", r);
43
+ }
44
+ } catch (o) {
45
+ console.error("Basecoat: Theme initialization failed", o);
38
46
  }
39
47
  }
40
48
  h();
41
- const v = (c) => {
42
- const t = c.querySelector(".theme-flavors"), o = c.querySelector(".theme-accents"), s = c.querySelector(".theme-reset");
43
- let n = localStorage.getItem("catppuccin-theme") || "latte";
44
- l.includes(n) || (n = "latte"), t && (t.innerHTML = "", t.className = "button-group w-full", l.forEach((a) => {
49
+ const g = (o) => {
50
+ const a = o.querySelector(".theme-flavors"), t = o.querySelector(".theme-accents"), r = o.querySelector(".theme-reset");
51
+ let n = localStorage.getItem("catppuccin-theme");
52
+ (!n || !l.includes(n)) && (n = document.documentElement.classList.contains("dark") ? "mocha" : "latte"), a && (a.innerHTML = "", a.className = "button-group w-full", l.forEach((c) => {
45
53
  const e = document.createElement("button");
46
- e.type = "button", e.className = "btn btn-sm capitalize flex-1", e.textContent = a, e.dataset.flavor = a, t.appendChild(e);
54
+ e.type = "button", e.className = "btn btn-sm capitalize flex-1", e.textContent = c, e.dataset.flavor = c, a.appendChild(e);
47
55
  }));
48
- const m = () => {
49
- if (!t) return;
50
- t.querySelectorAll("[data-flavor]").forEach((e) => {
56
+ const d = () => {
57
+ if (!a) return;
58
+ a.querySelectorAll("[data-flavor]").forEach((e) => {
51
59
  e.dataset.flavor === n ? (e.classList.remove("btn-outline", "btn-ghost"), e.classList.add("btn-primary")) : (e.classList.remove("btn-primary"), e.classList.add("btn-ghost"));
52
60
  });
53
- }, p = () => {
54
- if (!o) return;
55
- o.innerHTML = "";
56
- const a = f(n);
57
- o.className = "theme-accents grid grid-cols-7 gap-3 place-items-center p-4 rounded-xl border border-border/50 mt-4 transition-colors duration-300", o.style.backgroundColor = a.background, i.forEach((e) => {
58
- const r = document.createElement("button");
59
- r.type = "button", r.className = "size-6 rounded-full border border-border/20 shadow-sm transition-transform hover:scale-110 focus:outline-none focus:ring-2 focus:ring-ring", r.title = e, r.style.backgroundColor = a[e], r.dataset.tooltip = e, r.dataset.side = "top", r.onclick = () => {
60
- u(n, e);
61
- }, o.appendChild(r);
61
+ }, m = () => {
62
+ if (!t) return;
63
+ t.innerHTML = "";
64
+ const c = f(n);
65
+ t.className = "theme-accents grid grid-cols-7 gap-3 place-items-center p-4 rounded-xl border border-border/50 mt-4 transition-colors duration-300", t.style.backgroundColor = c.background, i.forEach((e) => {
66
+ const s = document.createElement("button");
67
+ s.type = "button", s.className = "size-6 rounded-full border border-border/20 shadow-sm transition-transform hover:scale-110 focus:outline-none focus:ring-2 focus:ring-ring", s.title = e, s.style.backgroundColor = c[e], s.dataset.tooltip = e, s.dataset.side = "top", s.onclick = () => {
68
+ u(n, e), d();
69
+ }, t.appendChild(s);
62
70
  });
63
71
  };
64
- t && t.addEventListener("click", (a) => {
65
- const e = a.target.closest("[data-flavor]");
66
- e && (n = e.dataset.flavor, m(), p());
67
- }), s && s.addEventListener("click", () => {
68
- const a = document.documentElement;
69
- l.forEach((e) => a.classList.remove(`theme-${e}`)), i.forEach((e) => a.classList.remove(`accent-${e}`)), localStorage.removeItem("catppuccin-theme"), localStorage.removeItem("catppuccin-accent"), d.includes(n) ? a.classList.add("dark") : a.classList.remove("dark");
70
- }), m(), p();
72
+ a && a.addEventListener("click", (c) => {
73
+ const e = c.target.closest("[data-flavor]");
74
+ e && (n = e.dataset.flavor, d(), m());
75
+ }), r && r.addEventListener("click", () => {
76
+ const c = document.documentElement, e = c.classList.contains("dark");
77
+ l.forEach((s) => c.classList.remove(`theme-${s}`)), i.forEach((s) => c.classList.remove(`accent-${s}`)), localStorage.removeItem("catppuccin-theme"), localStorage.removeItem("catppuccin-accent"), localStorage.setItem("basecoat-mode", e ? "dark" : "light"), e ? c.classList.add("dark") : c.classList.remove("dark"), n = e ? "mocha" : "latte", d(), m();
78
+ }), d(), m();
71
79
  };
72
- window.basecoat && window.basecoat.register("catppuccin-theme-switcher", ".catppuccin-theme-switcher", v);
80
+ window.basecoat && window.basecoat.register("catppuccin-theme-switcher", ".catppuccin-theme-switcher", g);
73
81
  })();
@@ -121,7 +121,6 @@
121
121
  input.addEventListener("keydown", handleKeyNavigation);
122
122
  if (visibleMenuItems.length > 0) {
123
123
  setActiveItem(menuItems.indexOf(visibleMenuItems[0]));
124
- visibleMenuItems[0].scrollIntoView({ block: "nearest" });
125
124
  }
126
125
  container.dataset.commandInitialized = true;
127
126
  container.dispatchEvent(new CustomEvent("basecoat:initialized"));
@@ -70,7 +70,7 @@
70
70
  const n = r.closest("dialog.command-dialog");
71
71
  n && !e.hasAttribute("data-keep-command-open") && n.close();
72
72
  }
73
- }), o.addEventListener("keydown", h), i.length > 0 && (d(s.indexOf(i[0])), i[0].scrollIntoView({ block: "nearest" })), r.dataset.commandInitialized = !0, r.dispatchEvent(new CustomEvent("basecoat:initialized"));
73
+ }), o.addEventListener("keydown", h), i.length > 0 && d(s.indexOf(i[0])), r.dataset.commandInitialized = !0, r.dispatchEvent(new CustomEvent("basecoat:initialized"));
74
74
  };
75
75
  window.basecoat && window.basecoat.register("command", ".command:not([data-command-initialized])", f);
76
76
  })();
@@ -18,14 +18,25 @@
18
18
  const breakpoint = parseInt(sidebarComponent.dataset.breakpoint) || 768;
19
19
  let open = breakpoint > 0 ? window.innerWidth >= breakpoint ? initialOpen : initialMobileOpen : initialOpen;
20
20
  const updateCurrentPageLinks = () => {
21
- const currentPath = window.location.pathname.replace(/\/$/, "");
21
+ const currentUrl = new URL(window.location.href);
22
+ const currentPath = currentUrl.pathname.replace(/\/$/, "");
22
23
  sidebarComponent.querySelectorAll("a").forEach((link) => {
23
24
  if (link.hasAttribute("data-ignore-current")) return;
25
+ const linkUrl = new URL(link.href, window.location.origin);
26
+ if (linkUrl.hash) {
27
+ const linkPath2 = linkUrl.pathname.replace(/\/$/, "");
28
+ if (linkPath2 === currentPath && linkUrl.hash === currentUrl.hash) {
29
+ link.setAttribute("aria-current", "page");
30
+ } else {
31
+ link.removeAttribute("aria-current");
32
+ }
33
+ return;
34
+ }
24
35
  if (link.getAttribute("href") === "#") {
25
36
  link.removeAttribute("aria-current");
26
37
  return;
27
38
  }
28
- const linkPath = new URL(link.href).pathname.replace(/\/$/, "");
39
+ const linkPath = linkUrl.pathname.replace(/\/$/, "");
29
40
  if (linkPath === currentPath) {
30
41
  link.setAttribute("aria-current", "page");
31
42
  } else {
@@ -1,53 +1,58 @@
1
1
  (() => {
2
2
  if (!window.history.__basecoatPatched) {
3
3
  const t = window.history.pushState;
4
- window.history.pushState = function(...i) {
5
- t.apply(this, i), window.dispatchEvent(new Event("basecoat:locationchange"));
4
+ window.history.pushState = function(...n) {
5
+ t.apply(this, n), window.dispatchEvent(new Event("basecoat:locationchange"));
6
6
  };
7
- const r = window.history.replaceState;
8
- window.history.replaceState = function(...i) {
9
- r.apply(this, i), window.dispatchEvent(new Event("basecoat:locationchange"));
7
+ const s = window.history.replaceState;
8
+ window.history.replaceState = function(...n) {
9
+ s.apply(this, n), window.dispatchEvent(new Event("basecoat:locationchange"));
10
10
  }, window.history.__basecoatPatched = !0;
11
11
  }
12
- const u = (t) => {
13
- const r = t.dataset.initialOpen !== "false", i = t.dataset.initialMobileOpen === "true", s = parseInt(t.dataset.breakpoint) || 768;
14
- let c = s > 0 ? window.innerWidth >= s ? r : i : r;
15
- const o = () => {
16
- const a = window.location.pathname.replace(/\/$/, "");
12
+ const h = (t) => {
13
+ const s = t.dataset.initialOpen !== "false", n = t.dataset.initialMobileOpen === "true", d = parseInt(t.dataset.breakpoint) || 768;
14
+ let o = d > 0 ? window.innerWidth >= d ? s : n : s;
15
+ const l = () => {
16
+ const a = new URL(window.location.href), i = a.pathname.replace(/\/$/, "");
17
17
  t.querySelectorAll("a").forEach((e) => {
18
18
  if (e.hasAttribute("data-ignore-current")) return;
19
+ const c = new URL(e.href, window.location.origin);
20
+ if (c.hash) {
21
+ c.pathname.replace(/\/$/, "") === i && c.hash === a.hash ? e.setAttribute("aria-current", "page") : e.removeAttribute("aria-current");
22
+ return;
23
+ }
19
24
  if (e.getAttribute("href") === "#") {
20
25
  e.removeAttribute("aria-current");
21
26
  return;
22
27
  }
23
- new URL(e.href).pathname.replace(/\/$/, "") === a ? e.setAttribute("aria-current", "page") : e.removeAttribute("aria-current");
28
+ c.pathname.replace(/\/$/, "") === i ? e.setAttribute("aria-current", "page") : e.removeAttribute("aria-current");
24
29
  });
25
- }, l = () => {
26
- t.setAttribute("aria-hidden", !c), c ? t.removeAttribute("inert") : t.setAttribute("inert", "");
27
- }, n = (a) => {
28
- c = a, l();
30
+ }, u = () => {
31
+ t.setAttribute("aria-hidden", !o), o ? t.removeAttribute("inert") : t.setAttribute("inert", "");
32
+ }, r = (a) => {
33
+ o = a, u();
29
34
  }, w = t.id;
30
35
  document.addEventListener("basecoat:sidebar", (a) => {
31
36
  if (!(a.detail?.id && a.detail.id !== w))
32
37
  switch (a.detail?.action) {
33
38
  case "open":
34
- n(!0);
39
+ r(!0);
35
40
  break;
36
41
  case "close":
37
- n(!1);
42
+ r(!1);
38
43
  break;
39
44
  default:
40
- n(!c);
45
+ r(!o);
41
46
  break;
42
47
  }
43
48
  }), t.addEventListener("click", (a) => {
44
- const e = a.target, d = t.querySelector("nav");
45
- if (window.innerWidth < s && e.closest("a, button") && !e.closest("[data-keep-mobile-sidebar-open]")) {
46
- document.activeElement && document.activeElement.blur(), n(!1);
49
+ const i = a.target, e = t.querySelector("nav");
50
+ if (window.innerWidth < d && i.closest("a, button") && !i.closest("[data-keep-mobile-sidebar-open]")) {
51
+ document.activeElement && document.activeElement.blur(), r(!1);
47
52
  return;
48
53
  }
49
- (e === t || d && !d.contains(e)) && (document.activeElement && document.activeElement.blur(), n(!1));
50
- }), window.addEventListener("popstate", o), window.addEventListener("basecoat:locationchange", o), l(), o(), t.dataset.sidebarInitialized = !0, t.dispatchEvent(new CustomEvent("basecoat:initialized"));
54
+ (i === t || e && !e.contains(i)) && (document.activeElement && document.activeElement.blur(), r(!1));
55
+ }), window.addEventListener("popstate", l), window.addEventListener("basecoat:locationchange", l), u(), l(), t.dataset.sidebarInitialized = !0, t.dispatchEvent(new CustomEvent("basecoat:initialized"));
51
56
  };
52
- window.basecoat && window.basecoat.register("sidebar", ".sidebar:not([data-sidebar-initialized])", u);
57
+ window.basecoat && window.basecoat.register("sidebar", ".sidebar:not([data-sidebar-initialized])", h);
53
58
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lanrenbang/basecoat-ultra",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Basecoat UI - Ultra edition. A Tailwind-first component library.",
5
5
  "type": "module",
6
6
  "main": "./dist/js/all.js",