diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index df58d0a30..4e6efc5b5 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -118,8 +118,9 @@ body.window .top { padding-left: 88px; height: 50px; padding-top: 2px; } /* the background: var(--pill); } body.panel .seg { display: none; } -.seg button { height: 24px; padding: 0 12px; border-radius: 6px; font-size: 12.5px; color: var(--muted); transition: background .15s, color .15s, box-shadow .15s; } -.seg button.on { background: var(--card); color: var(--fg); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .06); } +.seg button { position: relative; z-index: 1; height: 24px; padding: 0 12px; border-radius: 6px; font-size: 12.5px; color: var(--muted); transition: color .18s var(--ease), transform .14s var(--ease); } +.seg button.on { color: var(--fg); } +.seg button:hover:not(.on) { color: var(--fg-2); } .actions { margin-left: auto; display: flex; gap: 2px; } .icon { width: 26px; height: 26px; border-radius: 7px; @@ -132,7 +133,8 @@ body.panel .seg { display: none; } @keyframes spin { to { transform: rotate(360deg); } } /* ---- lists ---------------------------------------------------------------- */ -.view { flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 4px; display: flex; flex-direction: column; } +.view { flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 4px; display: flex; flex-direction: column; animation: view-in .24s var(--ease); } +@keyframes view-in { from { opacity: 0; transform: translateY(5px); } } body.window .view { padding: 2px 16px 8px; } .view::-webkit-scrollbar { width: 0; } .list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; flex: none; } @@ -405,13 +407,9 @@ body.window .foot { padding-left: 18px; } .tile.added:hover { opacity: .8; } .tile .check { margin-left: auto; color: var(--green); display: inline-flex; flex: none; } .tile.custom { border-style: dashed; } -.sheet .editor { margin-top: 10px; border-radius: 12px; border: 1px solid var(--line); } - -/* the inline editor under a provider row */ -.editor { background: var(--card-2); padding: 12px 14px 12px 48px; display: grid; grid-template-columns: 72px 1fr; gap: 10px 14px; align-items: start; } -.editor.new { padding-left: 14px; } -body.panel .editor { padding-left: 14px; } -.editor .ehead { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding-bottom: 2px; } +/* the provider editor, in a dialog */ +.editor { padding: 16px 18px 14px; display: grid; grid-template-columns: 72px 1fr; gap: 10px 14px; align-items: start; } +.editor .ehead { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding-bottom: 8px; margin-bottom: 2px; border-bottom: 1px solid var(--line-2); } .editor .ehead .ic { width: 20px; height: 20px; } .editor .ehead b { font-weight: 600; } .editor .ehead .note { font-size: 12px; color: var(--muted); } @@ -430,9 +428,18 @@ body.panel .editor { padding-left: 14px; } .editor .side { display: flex; gap: 4px; align-items: center; flex: none; } .editor .side .text { padding: 3px 6px; } .editor .stack { display: flex; flex-direction: column; gap: 6px; } -.segs { display: inline-flex; padding: 2px; border-radius: 7px; background: var(--pill); align-self: flex-start; } -.opt { height: 22px; padding: 0 10px; border-radius: 5px; font-size: 12px; color: var(--muted); transition: background .12s, color .12s; } -.opt.on { background: var(--card); color: var(--fg); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .06); } +.segs { position: relative; display: inline-flex; padding: 2px; border-radius: 7px; background: var(--pill); align-self: flex-start; } +.opt { position: relative; z-index: 1; height: 22px; padding: 0 10px; border-radius: 5px; font-size: 12px; color: var(--muted); transition: color .18s var(--ease), transform .14s var(--ease); } +.opt.on { color: var(--fg); } +.opt:hover:not(.on) { color: var(--fg-2); } +.thumb { + position: absolute; top: 2px; bottom: 2px; left: 0; width: 0; border-radius: 6px; + background: var(--card); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .06); + transition: transform .28s var(--ease), width .28s var(--ease), opacity .15s; + pointer-events: none; +} +.segs .thumb { border-radius: 5px; } +.thumb.still { transition: none; } .link { font-size: 12px; color: var(--accent); padding: 3px 4px; white-space: nowrap; } .link:hover { text-decoration: underline; text-underline-offset: 2px; } .editor .more { grid-column: 1 / -1; } @@ -503,3 +510,54 @@ body.panel .editor { padding-left: 14px; } .prefs .val code { font-size: 12px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; user-select: text; -webkit-user-select: text; padding: 0 6px; } .prefs .val .text { padding: 3px 6px; } + +/* ---------- motion ---------- + One easing everywhere (iOS-ish: quick start, soft landing), short + durations, small distances. Pressing gives a little, pages settle in, + dialogs lift. */ +:root { --ease: cubic-bezier(.2, .8, .2, 1); } +.text, .icon, .tile, .achip, .mchip, .use, .link { + transition-property: background, background-color, color, border-color, box-shadow, filter, opacity, transform; + transition-duration: .16s; transition-timing-function: var(--ease); +} +.text:active, .tile:active, .achip:active, .mchip:active, .use:active, .opt:active, .seg button:active { transform: scale(.96); } +.icon:active { transform: scale(.9); } +.row.provider { transition: background .16s var(--ease); } +.row.provider:active { background: var(--card-2); } +.chips .chip { transition: background .16s var(--ease), color .16s var(--ease), transform .14s var(--ease); } +.chips .chip:active { transform: scale(.96); } +.status { transition: opacity .2s var(--ease); } + +/* the theme crossfades instead of snapping */ +html.theming, html.theming *, html.theming *::before, html.theming *::after { + transition: background-color .35s var(--ease), background .35s var(--ease), color .35s var(--ease), border-color .35s var(--ease), box-shadow .35s var(--ease) !important; +} + +/* ---------- modal ---------- */ +.modal { + position: fixed; inset: 0; z-index: 20; + display: flex; align-items: center; justify-content: center; padding: 28px 24px; + background: rgba(0, 0, 0, .28); + -webkit-backdrop-filter: blur(8px) saturate(1.1); backdrop-filter: blur(8px) saturate(1.1); + animation: fade-in .2s var(--ease); +} +.modal.out { animation: fade-out .16s var(--ease) forwards; pointer-events: none; } +.modal .dialog { + width: min(600px, 100%); max-height: 100%; overflow-y: auto; + border-radius: 14px; background: var(--card); + box-shadow: 0 0 0 1px var(--line), 0 24px 60px rgba(0, 0, 0, .32), 0 2px 8px rgba(0, 0, 0, .12); + animation: dialog-in .26s var(--ease); +} +.modal .dialog.swap { animation: content-in .22s var(--ease); } +.modal.out .dialog { animation: dialog-out .16s var(--ease) forwards; } +.modal .dialog::-webkit-scrollbar { width: 0; } +body.panel .modal { padding: 16px 12px; } +@keyframes fade-in { from { opacity: 0; } } +@keyframes fade-out { to { opacity: 0; } } +@keyframes dialog-in { from { opacity: 0; transform: translateY(12px) scale(.97); } } +@keyframes dialog-out { to { opacity: 0; transform: translateY(6px) scale(.98); } } +@keyframes content-in { from { opacity: .5; transform: translateY(2px); } } + +@media (prefers-reduced-motion: reduce) { + *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } +} diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 9bca6c042..fbaa54af2 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -305,7 +305,9 @@ $("#q").addEventListener("keydown", (e) => { }); document.addEventListener("mousedown", (e) => { if (pick && !$("#pop").contains(e.target)) closePicker(); }); document.addEventListener("keydown", (e) => { - if (e.key === "Escape" && !pick && mode === "panel") api("window/hide", {}); + if (e.key !== "Escape" || pick) return; + if (editing !== null) cancelEdit(); + else if (mode === "panel") api("window/hide", {}); }); // ---------- profiles ---------- @@ -353,11 +355,12 @@ async function loadProviders() { } // One row per provider: logo, name, the agents pointed at it, key status. -// Everything else lives in the editor that opens under the row. +// Everything else lives in the editor, a dialog over the page. function renderProviders() { const list = $("#providers"); list.replaceChildren(); list.hidden = !providers.providers.length; + let dialog = null; // the editor, if one is open for (const p of providers.providers) { const open = editing === p.id; const row = el("div", "row provider" + (open ? " selected" : "")); @@ -397,11 +400,11 @@ function renderProviders() { row.append(icon(p.icon || "generic"), who, uses, key, chev); row.onclick = () => { editing = open ? null : p.id; draft = null; adding = false; renderProviders(); }; list.append(row); - if (open) list.append(renderEditor(p)); + if (open) dialog = renderEditor(p); } renderExcluded(); - renderAdd(); - (list.querySelector(".editor") || $("#addSheet .editor"))?.scrollIntoView({ block: "nearest" }); + dialog = renderAdd() || dialog; + if (dialog) openModal(dialog); else closeModal(); } // Sign-ins dial found but leaves alone (Claude Code), so nobody wonders @@ -579,11 +582,13 @@ function gatewayModels() { function segs(items, current, onPick) { const box = el("div", "segs"); + const key = items.map(([id]) => id).join("|"); for (const [id, name] of items) { const b = el("button", "opt" + (id === current ? " on" : ""), name); - b.onclick = () => onPick(id); + b.onclick = () => { for (const x of box.querySelectorAll(".opt")) x.classList.toggle("on", x === b); slide(box, key); onPick(id); }; box.append(b); } + queueMicrotask(() => slide(box, key)); // once it is in the page return box; } @@ -727,7 +732,7 @@ function renderAdd() { sheet.replaceChildren(); sheet.hidden = !adding; $("#addProvider").hidden = adding; - if (!adding) return; + if (!adding) return null; const head = el("div", "row-head"); head.append(el("span", "label", t(providers.providers.length ? "Add a provider" : "Add your first provider")), el("span", "grow")); const q = input(presetQuery, t("Find a vendor…")); @@ -775,7 +780,7 @@ function renderAdd() { } }; drawTiles(); - if (editing && typeof editing === "object") sheet.append(renderEditor(null, editing.preset)); + return editing && typeof editing === "object" ? renderEditor(null, editing.preset) : null; } function tile(pr) { @@ -817,6 +822,49 @@ function input(value, placeholder, type = "text") { } function cancelEdit() { editing = null; draft = null; renderProviders(); } +// ---------- modal ---------- +// The provider editor opens as a dialog over the page; Escape, the backdrop +// or Cancel close it. +let modalTimer = 0; +function openModal(content) { + const m = $("#modal"), d = m.firstElementChild; + clearTimeout(modalTimer); + m.classList.remove("out"); + d.classList.remove("swap"); + if (!m.hidden) { void d.offsetWidth; d.classList.add("swap"); } // content changed: a soft refresh, not a re-entrance + d.replaceChildren(content); + m.hidden = false; +} +function closeModal() { + const m = $("#modal"); + if (m.hidden || m.classList.contains("out")) return; + m.classList.add("out"); + modalTimer = setTimeout(() => { m.hidden = true; m.classList.remove("out"); m.firstElementChild.replaceChildren(); }, 170); +} +$("#modal").onclick = (e) => { if (e.target === e.currentTarget) cancelEdit(); }; + +// ---------- sliding thumb ---------- +// Pills (the nav, every segmented control) have one thumb that glides to the +// selected option instead of each option lighting up on its own. +const thumbs = new Map(); // pill key → where its thumb is, so a re-rendered pill takes over mid-slide +function slide(box, key) { + let th = box.querySelector(":scope > .thumb"); + if (!th) { th = el("span", "thumb"); box.prepend(th); } + const on = box.querySelector(":scope > .on"); + if (!on) { th.style.opacity = "0"; return; } + th.style.opacity = ""; + const to = { x: on.offsetLeft, w: on.offsetWidth }; + const last = thumbs.get(key); + const from = last && performance.now() - last.at < 300 ? last.from : last; // re-rendered mid-slide: start where the old one started + const put = (p) => { th.style.transform = `translateX(${p.x}px)`; th.style.width = p.w + "px"; }; + th.classList.add("still"); + put(from || to); + void th.offsetWidth; + th.classList.remove("still"); + put(to); + thumbs.set(key, { ...to, at: performance.now(), from: from || to }); +} + const PROTOS = [["chat", "OpenAI", "Chat Completions — most agents"], ["responses", "Responses", "OpenAI Responses — what Codex speaks"], ["anthropic", "Anthropic", "Anthropic Messages — what Claude Code speaks"]]; // renderEditor: an existing provider (p), a new preset (presetID), or custom. @@ -831,12 +879,13 @@ function renderEditor(p, presetID) { const ed = el("div", "editor" + (isNew ? " new" : "")); ed.onclick = (e) => e.stopPropagation(); - if (isNew) { + { const h = el("div", "ehead"); - h.append(icon(pr?.icon || "generic"), el("b", "", pr ? pr.name : t("Custom provider"))); + h.append(icon(p?.icon || pr?.icon || "generic"), el("b", "", p ? p.name : pr ? pr.name : t("Custom provider"))); if (pr?.note) h.append(el("span", "note", pr.note)); h.append(el("span", "grow")); - if (pr?.website) { const b = el("button", "link", hostOf(pr.website) + " ↗"); b.onclick = () => api("open", { url: pr.website }); h.append(b); } + const site = pr?.website || (p?.host ? "https://" + p.host : ""); + if (site) { const b = el("button", "link", hostOf(site) + " ↗"); b.onclick = () => api("open", { url: site }); h.append(b); } ed.append(h); } @@ -865,9 +914,10 @@ function renderEditor(p, presetID) { for (const [v, l, hint] of [["openai", "OpenAI compatible", "…/v1 — chat completions, and responses when the vendor has it"], ["anthropic", "Anthropic compatible", "the root URL, what ANTHROPIC_BASE_URL would take"]]) { const b = el("button", "opt" + (draft.api === v ? " on" : ""), t(l)); b.title = t(hint); - b.onclick = () => { draft.api = v; const u = url.value; if (v === "anthropic") { draft.anthropic = u; draft.chat = ""; } else { draft.chat = u; draft.anthropic = ""; } for (const x of seg.children) x.classList.toggle("on", x === b); url.placeholder = v === "anthropic" ? "https://…" : "https://…/v1"; }; + b.onclick = () => { draft.api = v; const u = url.value; if (v === "anthropic") { draft.anthropic = u; draft.chat = ""; } else { draft.chat = u; draft.anthropic = ""; } for (const x of seg.querySelectorAll(".opt")) x.classList.toggle("on", x === b); slide(seg, "api"); url.placeholder = v === "anthropic" ? "https://…" : "https://…/v1"; }; seg.append(b); } + queueMicrotask(() => slide(seg, "api")); url = input(draft.api === "anthropic" ? draft.anthropic : draft.chat, draft.api === "anthropic" ? "https://…" : "https://…/v1", "url"); url.oninput = () => { if (draft.api === "anthropic") draft.anthropic = url.value; else draft.chat = url.value; }; const urlWrap = el("div", "stack"); @@ -1123,9 +1173,10 @@ function renderUsage() { seg.replaceChildren(); for (const [id, name] of PERIODS) { const b = el("button", "opt" + (id === period ? " on" : ""), t(name)); - b.onclick = () => { period = id; loadUsage().catch((e) => status(e.message, "err")); }; + b.onclick = () => { for (const x of seg.querySelectorAll(".opt")) x.classList.toggle("on", x === b); slide(seg, "period"); period = id; loadUsage().catch((e) => status(e.message, "err")); }; seg.append(b); } + slide(seg, "period"); const cost = $("#usageCost"); cost.replaceChildren(); const c = fmtCost(u); @@ -1228,12 +1279,22 @@ const LOCALES = [["system", "System"], ["en", "English"], ["zh", "中文"]]; // ?locale= in the URL wins, so a forced look stays forced. function applyPrefs(s) { s = s || {}; + const root = document.documentElement; if (!params.get("theme")) { - if (!s.theme || s.theme === "system") delete document.documentElement.dataset.theme; - else document.documentElement.dataset.theme = s.theme; + const want = !s.theme || s.theme === "system" ? undefined : s.theme; + if (root.dataset.theme !== want) { + if (applyPrefs.ready) { // not on the first paint + root.classList.add("theming"); + clearTimeout(applyPrefs.t); + applyPrefs.t = setTimeout(() => root.classList.remove("theming"), 450); + } + if (want) root.dataset.theme = want; else delete root.dataset.theme; + } } + applyPrefs.ready = true; const was = locale; setLocale(s.lang); + if (was !== locale && mode === "window") queueMicrotask(() => slide($("#nav"), "nav")); return was !== locale; } @@ -1283,15 +1344,16 @@ async function savePrefs(body) { function show(v) { view = v; - if (mode === "window") for (const b of $("#nav").children) b.classList.toggle("on", b.dataset.view === v); + if (mode === "window") { for (const b of $("#nav").querySelectorAll("button")) b.classList.toggle("on", b.dataset.view === v); slide($("#nav"), "nav"); } $("#prefs").classList.toggle("on", v === "settings"); for (const id of ["agents", "providers", "gateway", "usage", "settings"]) $("#view-" + id).hidden = v !== id; closePicker(); + if (v !== "providers" && editing !== null) cancelEdit(); if (v === "providers" || v === "gateway") loadProviders().catch((e) => status(e.message, "err")); if (v === "usage") loadUsage().catch((e) => status(e.message, "err")); if (v === "settings") loadSettings().catch((e) => status(e.message, "err")); } -if (mode === "window") for (const b of $("#nav").children) b.onclick = () => { show(b.dataset.view); b.blur(); }; +if (mode === "window") for (const b of $("#nav").querySelectorAll("button")) b.onclick = () => { show(b.dataset.view); b.blur(); }; $("#prefs").onclick = () => { if (mode === "window") show("settings"); else api("window/main?view=settings", {}); $("#prefs").blur(); }; $("#sync").onclick = async () => { @@ -1319,4 +1381,5 @@ else { $("#nav").remove(); } document.addEventListener("visibilitychange", () => { if (!document.hidden) load(); }); window.addEventListener("focus", load); if (mode === "window" && ["providers", "gateway", "usage", "settings"].includes(params.get("view"))) show(params.get("view")); +else if (mode === "window") slide($("#nav"), "nav"); load(); diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html index 88ec12e6d..b29d8c6f8 100644 --- a/internal/gui/assets/index.html +++ b/internal/gui/assets/index.html @@ -99,6 +99,8 @@ +