Initial upload

This commit is contained in:
antonn committed 2026-06-10 17:04:11 +00:00
1 parent b0bf3b7167
commit a022f29e34
65 files changed
+46484 -4339

No files matched your search

+127 -11
View File
@@ -908,22 +908,64 @@
return els.messages.querySelectorAll(".dashboard-assistant-message--assistant").length;
}
// Minimum viewport height (in CSS pixels) required to safely open the
// assistant. Below this the UI is too cramped to be usable (matches a
// phone-sized window or an extreme browser zoom-in).
const MIN_OPEN_HEIGHT = 480;
// Minimum viewport width. Below this the layout would clip horizontally.
const MIN_OPEN_WIDTH = 360;
function canOpenMenu() {
const h = window.innerHeight;
const w = window.innerWidth;
return h >= MIN_OPEN_HEIGHT && w >= MIN_OPEN_WIDTH;
}
function positionMenu() {
if (!state.open || !els.menu || !els.trigger) return;
const triggerRect = els.trigger.getBoundingClientRect();
const margin = 12;
const topGap = 10;
// Width: keep the designed width, never scale it. Clamp to viewport.
const preferredWidth = state.configured ? 580 : 430;
const menuWidth = Math.min(preferredWidth, window.innerWidth - 24);
const leftBias = 150;
const visualW = Math.min(preferredWidth, window.innerWidth - margin * 2);
// Center on trigger, then keep the panel fully visible in viewport.
const idealLeft = triggerRect.left + (triggerRect.width / 2) - (menuWidth / 2) - leftBias;
const left = Math.max(12, Math.min(idealLeft, window.innerWidth - menuWidth - 12));
// Height: whatever fits between the trigger bottom and the viewport bottom.
// The messages area has `flex: 1` + `overflow-y: auto`, so it scrolls
// naturally when content is taller than this — no clipping at the bottom.
const availableBelow = window.innerHeight - triggerRect.bottom - topGap - margin;
const availableAbove = triggerRect.top - topGap - margin;
// Prefer placing it below the trigger; fall back to above if no room.
const useAbove = availableBelow < 260 && availableAbove > availableBelow;
const visualH = Math.max(
260,
useAbove ? availableAbove : availableBelow
);
els.menu.style.width = `${menuWidth}px`;
// Center horizontally on the trigger, then clamp to viewport.
const desiredLeft = triggerRect.left + (triggerRect.width / 2) - (visualW / 2) - 150;
const left = Math.max(margin, Math.min(desiredLeft, window.innerWidth - visualW - margin));
const top = useAbove
? Math.max(margin, triggerRect.top - visualH - topGap)
: Math.max(margin, triggerRect.bottom + topGap);
els.menu.style.width = `${visualW}px`;
els.menu.style.height = `${visualH}px`;
els.menu.style.left = `${left}px`;
els.menu.style.right = 'auto';
els.menu.style.top = `${triggerRect.bottom + 20}px`;
els.menu.style.bottom = 'auto';
els.menu.style.right = "auto";
els.menu.style.top = `${top}px`;
els.menu.style.bottom = "auto";
els.menu.style.transform = "none";
els.menu.style.setProperty("--assistant-scale", "1");
// Relax the messages area's min-height when the viewport is tight,
// so the menu can shrink to fit without clipping the composer.
if (els.messages) {
const tight = visualH < 520;
els.messages.style.minHeight = tight ? "0px" : "";
}
}
function stopSpeaking() {
@@ -1168,6 +1210,10 @@
}
function openMenu() {
if (!canOpenMenu()) {
showTooSmallNotice();
return;
}
state.open = true;
primeSpeechSynthesis();
updateButtons();
@@ -1178,6 +1224,24 @@
});
}
function showTooSmallNotice() {
// Flash a transient inline notice near the trigger so the user understands
// why the assistant didn't open. Uses the existing status pipeline.
if (els.status) {
const prevState = els.status.dataset.state;
const prevText = els.status.textContent;
els.status.dataset.state = "warning";
els.status.textContent = "Screen too small to open the assistant. Try a larger window.";
els.status.classList.remove("is-hidden");
setTimeout(() => {
if (!state.open && els.status) {
els.status.dataset.state = prevState || "idle";
els.status.textContent = prevText || "";
}
}, 3500);
}
}
function closeMenu() {
state.open = false;
updateButtons();
@@ -4696,6 +4760,11 @@
els.trigger?.addEventListener("click", (event) => {
event.stopPropagation();
if (!state.open) {
if (!canOpenMenu()) {
event.preventDefault();
showTooSmallNotice();
return;
}
openMenu();
return;
}
@@ -4860,14 +4929,61 @@
};
}
window.addEventListener("resize", positionMenu);
window.addEventListener("scroll", positionMenu, true);
// Re-position on window resize, scroll, AND browser zoom.
// `window.resize` doesn't always fire on Ctrl+/Ctrl- zoom, so we also
// listen to `visualViewport.resize` (covers pinch-zoom and most browser
// zoom cases) and fall back to a DPR poll for the rest.
let lastDpr = window.devicePixelRatio || 1;
const refit = () => {
if (!state.open) return;
if (!canOpenMenu()) {
// Viewport shrunk below the safe threshold (e.g. extreme zoom-in).
// Auto-close and inform the user.
closeMenu();
showTooSmallNotice();
return;
}
positionMenu();
};
window.addEventListener("resize", refit);
window.addEventListener("scroll", refit, true);
if (window.visualViewport) {
window.visualViewport.addEventListener("resize", refit);
window.visualViewport.addEventListener("scroll", refit);
}
// DPR poll: catches the few browsers/configs where neither resize nor
// visualViewport fires on zoom. Cheap (rAF-throttled).
const dprTick = () => {
const dpr = window.devicePixelRatio || 1;
if (dpr !== lastDpr) {
lastDpr = dpr;
refit();
}
requestAnimationFrame(dprTick);
};
requestAnimationFrame(dprTick);
window.addEventListener("beforeunload", () => {
stopSpeaking();
stopActiveStream();
cleanupAudioGraph();
cleanupRecognition();
});
// Re-position when the menu's intrinsic size changes (e.g. messages streaming,
// config panel toggling, transcript appearing). Debounced with rAF.
if (typeof ResizeObserver !== "undefined" && els.menu) {
let rafId = 0;
const ro = new ResizeObserver(() => {
if (!state.open) return;
if (rafId) cancelAnimationFrame(rafId);
rafId = requestAnimationFrame(() => {
rafId = 0;
positionMenu();
});
});
ro.observe(els.menu);
}
}
function init() {