A lightweight, macOS-style dock for Windows 11, with glass visuals, smooth magnification, and Genie effect.
fix(site): stabilize the Genie minimize and restore flow
CristianOlivera10de4c6aacbba
diff --git a/muelle/src/components/dock/DockThumb.astro b/muelle/src/components/dock/DockThumb.astroindex 8df16d8..70d2ed3 100644--- a/muelle/src/components/dock/DockThumb.astro+++ b/muelle/src/components/dock/DockThumb.astro@@ -1,9 +1,17 @@----// Minimized window thumbnail; the genie paints its contents at runtime.+// Minimized-window slot: it has no width until a window lands in it, so the dock+// only shows a thumbnail while something is actually minimized.----<li class="dock-item" data-dock-thumb>- <canvas width="104" height="104" class="size-full rounded-[12px]"></canvas>+<li class="dock-item dock-slot" data-dock-thumb inert>+ <button+ type="button"+ class="dock-thumb"+ data-dock-restore+ aria-label="Show the minimized Notes window"+ >+ <canvas width="104" height="104"></canvas>+ </button><span class="dock-tip" aria-hidden="true">Notes</span><i class="dock-dot" aria-hidden="true"></i></li>diff --git a/muelle/src/components/dock/NotesWindow.astro b/muelle/src/components/dock/NotesWindow.astroindex cb5fe10..3682876 100644--- a/muelle/src/components/dock/NotesWindow.astro+++ b/muelle/src/components/dock/NotesWindow.astro@@ -10,8 +10,8 @@ const folders = [const tasks = [{ label: "Magnification, smooth curve", done: true },- { label: "Genie minimize in 0.5 s", done: true },- { label: "Taskbar back in under 2 s", done: true },+ { label: "Live thumbnails when minimized", done: true },+ { label: "Taskbar always comes back", done: true },{ label: "0% CPU when idle", done: true },{ label: "Publish v0.1", done: false },];diff --git a/muelle/src/components/dock/WindowMock.astro b/muelle/src/components/dock/WindowMock.astroindex 08ac745..ea92b92 100644--- a/muelle/src/components/dock/WindowMock.astro+++ b/muelle/src/components/dock/WindowMock.astro@@ -21,7 +21,11 @@ import "@/styles/dock.css";<CursorOverlay class="top-0 left-0 opacity-0" />- <canvas data-genie class="pointer-events-none absolute inset-0 z-2 hidden" aria-hidden="true">+ <canvas+ data-genie+ class="genie-canvas pointer-events-none absolute inset-0 z-2 hidden"+ aria-hidden="true"+ ></canvas><div class="absolute inset-x-0 bottom-3 z-5">diff --git a/muelle/src/scripts/dock.ts b/muelle/src/scripts/dock.tsindex f481468..098b7a0 100644--- a/muelle/src/scripts/dock.ts+++ b/muelle/src/scripts/dock.ts@@ -31,8 +31,8 @@ const BOUNCE_REPEATS = 3;/** Below this distance the width snaps to its target and the frame loop can stop. */const SETTLE = 0.05;-/** An item that is not an app (the minimized-window thumbnail): never resized or pressed. */-const isSlot = (item: HTMLElement) => item.querySelector("[data-dock-thumb]") !== null;+/** An item that is not an app (the minimized-window slot): never resized or pressed. */+const isSlot = (item: HTMLElement) => item.hasAttribute("data-dock-thumb");export function initDock(root: HTMLElement, reduceMotion: boolean) {const dock = root.querySelector<HTMLElement>(".dock");@@ -53,10 +53,13 @@ export function initDock(root: HTMLElement, reduceMotion: boolean) {let visible = true;/** The sweep owns the pointer whenever the real one is away from the dock. */let auto = true;+ let geniePaused = false;let nextClick = 0;const rest = () => {items.forEach((item, index) => {+ // The minimized-window slot sizes itself from `--slot`; an inline width would pin it open.+ if (isSlot(item)) return;widths[index] = REST_SIZE;item.style.width = `${REST_SIZE}px`;item.style.height = `${REST_SIZE}px`;@@ -200,7 +203,7 @@ export function initDock(root: HTMLElement, reduceMotion: boolean) {root.addEventListener("pointermove",(event: PointerEvent) => {- if (event.pointerType !== "mouse") return;+ if (geniePaused || event.pointerType !== "mouse") return;const dockRect = dock.getBoundingClientRect();const near =@@ -216,6 +219,7 @@ export function initDock(root: HTMLElement, reduceMotion: boolean) {);root.addEventListener("pointerleave", () => {+ if (geniePaused) return;auto = true;nextClick = 0;if (cursor) cursor.style.opacity = "1";@@ -231,6 +235,40 @@ export function initDock(root: HTMLElement, reduceMotion: boolean) {// A narrow window scrolls the row, which moves every centre.dock.parentElement?.addEventListener("scroll", measure, { passive: true });+ // The page scroll moves the dock under a parked pointer, and no pointermove fires then.+ window.addEventListener(+ "scroll",+ () => {+ if (pointer !== null) measure();+ },+ { passive: true },+ );++ // The genie opens and closes the minimized-window slot, which reflows the row.+ window.addEventListener("muelle:slot", () => {+ measure();+ start();+ });++ // While a window is flying to the dock the demo stands still: the sweep magnifies+ // icons and would drag the slot away from where the window is heading.+ window.addEventListener("muelle:genie", (event) => {+ const { flying, minimized } = (event as CustomEvent<{+ flying: boolean;+ minimized: boolean;+ }>).detail;+ geniePaused = flying || minimized;+ auto = !geniePaused;+ nextClick = 0;+ if (geniePaused) {+ pointer = null;+ rest();+ measure();+ }+ if (cursor) cursor.style.opacity = geniePaused ? "0" : "1";+ if (!geniePaused) start();+ });+window.addEventListener("resize",() => {diff --git a/muelle/src/scripts/genie.ts b/muelle/src/scripts/genie.tsindex e7501cf..37148ea 100644--- a/muelle/src/scripts/genie.ts+++ b/muelle/src/scripts/genie.ts@@ -5,10 +5,13 @@import { gsap } from "@/lib/motion";-const SLICE = 2;+const SLICE = 1;const MAX_DPR = 2;const FLIGHT_SECONDS = 0.9;+const SCROLL_SCRUB_SECONDS = 0.6;const THUMB_SIZE = 52;+/** Resting width of a dock item, needed to measure the slot without the magnification. */+const DOCK_REST = 52;/** Rows near the bottom of the window start moving first. */const STAGGER = 0.42;const TRAVEL = 0.58;@@ -34,12 +37,23 @@ export function initGenie(root: HTMLElement, reduceMotion: boolean) {const canvas = root.querySelector<HTMLCanvasElement>("[data-genie]");const note = root.querySelector<HTMLElement>("[data-note]");const thumb = document.querySelector<HTMLCanvasElement>("[data-dock-thumb] canvas");+ const slot = document.querySelector<HTMLElement>("[data-dock-thumb]");+ const restore = slot?.querySelector<HTMLButtonElement>("[data-dock-restore]");const context = canvas?.getContext("2d");- if (!canvas || !note || !thumb || !context) return;+ if (!canvas || !note || !thumb || !slot || !context) return;- const dpr = Math.min(window.devicePixelRatio || 1, MAX_DPR);+ let dpr = Math.min(window.devicePixelRatio || 1, MAX_DPR);const state = { progress: 0 };let scene: Scene | null = null;+ let scrollProgress = 0;+ let scrollTarget: number | null = null;+ let manualTarget: number | null = null;+ let manualDirection = 0;+ let manualFlight = false;+ /** Last value written to the dock slot, so the layout is only touched when it changes. */+ let slotValue = -1;+ let flyingBefore = false;+ let minimizedBefore = false;const paint = (progress: number) => {if (!scene) return;@@ -47,9 +61,34 @@ export function initGenie(root: HTMLElement, reduceMotion: boolean) {const { x, y, width, height, targetX, targetY, targetWidth, source, slice } = scene;context.setTransform(dpr, 0, 0, dpr, 0, 0);context.clearRect(0, 0, canvas.width / dpr, canvas.height / dpr);- note.style.visibility = progress > 0.02 ? "hidden" : "";+ // Both hand over on the same threshold: for a few pixels of scroll the DOM window and+ // its canvas copy were painted at once, which read as a ghost of the text.+ const hidden = progress > 0.02;+ const minimized = progress >= 0.995;+ const flying = hidden && !minimized;+ canvas.classList.toggle("hidden", !flying);+ note.style.visibility = hidden ? "hidden" : "";++ // The dock's demo pauses while a window is in the air: a sweeping, magnified row+ // would move the slot away from the point the flight is aiming at.+ if (flying !== flyingBefore || minimized !== minimizedBefore) {+ flyingBefore = flying;+ minimizedBefore = minimized;+ window.dispatchEvent(new CustomEvent("muelle:genie", { detail: { flying, minimized } }));+ }++ // The dock opens its slot as the window arrives, so the thumbnail is not already+ // sitting there when nothing is minimized.+ const open = clamp01((progress - 0.72) / 0.28);+ if (open !== slotValue) {+ slotValue = open;+ slot.style.setProperty("--slot", String(open));+ slot.toggleAttribute("inert", open < 0.5);+ // Only the ends of the travel reflow the row; the dock asks for nothing per frame.+ if (open === 0 || open === 1) window.dispatchEvent(new CustomEvent("muelle:slot"));+ }- if (progress <= 0.001 || progress >= 0.995) return;+ if (!flying) return;const rows = Math.round(height / SLICE);const restCenter = x + width / 2;@@ -83,20 +122,34 @@ export function initGenie(root: HTMLElement, reduceMotion: boolean) {}};- // The flight is measured from the document, not from where the window happens to sit on- // load: with a tall viewport it is already above the start line, and the flight would- // begin before anyone scrolls.- let originTop = 0;let frame = 0;- const measureOrigin = () => {- originTop = note.getBoundingClientRect().top + window.scrollY;- };-const build = () => {+ dpr = Math.min(window.devicePixelRatio || 1, MAX_DPR);const rootRect = root.getBoundingClientRect();const noteRect = note.getBoundingClientRect();- const thumbRect = thumb.getBoundingClientRect();++ // Aim at the slot at rest: the dock's autoplay magnifies its icons, which moves the+ // whole row, so measuring now would fly the window to a place the slot has left.+ // The slot is opened for the measurement too, because that is where it will land.+ const dockItems = [...root.querySelectorAll<HTMLElement>(".dock-item")];+ const savedSize = dockItems.map((item) => [item.style.width, item.style.height]);+ dockItems.forEach((item) => {+ item.style.width = `${DOCK_REST}px`;+ item.style.height = `${DOCK_REST}px`;+ });++ const previousSlot = slot.style.getPropertyValue("--slot");+ slot.style.setProperty("--slot", "1");+ const thumbRect = slot.getBoundingClientRect();+ if (previousSlot) slot.style.setProperty("--slot", previousSlot);+ else slot.style.removeProperty("--slot");++ dockItems.forEach((item, index) => {+ const [width, height] = savedSize[index];+ item.style.width = width;+ item.style.height = height;+ });canvas.width = Math.round(rootRect.width * dpr);canvas.height = Math.round(rootRect.height * dpr);@@ -115,21 +168,53 @@ export function initGenie(root: HTMLElement, reduceMotion: boolean) {};renderThumbnail(thumb, source, dpr);- measureOrigin();paint(state.progress);};build();- if (reduceMotion) return;+ // The dock is wider than a phone and scrolls sideways, so the minimized slot sits off+ // screen: the flight would leave the mockup clipped at its right edge. Below 900 px the+ // window simply stays where it is.+ const wideEnough = window.matchMedia("(min-width: 900px)");+ if (reduceMotion || !wideEnough.matches) return;++ const readScrollProgress = () => {+ const top = note.getBoundingClientRect().top + window.scrollY;+ const start = Math.max(0, top - window.innerHeight * START_RATIO);+ return clamp01((window.scrollY - start) / window.innerHeight);+ };++ const syncScrollProgress = () => {+ const progress = readScrollProgress();+ scrollProgress = progress;++ // Let a manual flight finish, then let scroll take over once it catches the target.+ if (manualTarget !== null) {+ if (manualFlight || (progress - manualTarget) * manualDirection > 0) return;+ manualTarget = null;+ }++ if (progress === state.progress) {+ scrollTarget = progress;+ gsap.killTweensOf(state);+ return;+ }++ if (progress === scrollTarget) return;+ scrollTarget = progress;+ gsap.killTweensOf(state);+ gsap.to(state, {+ progress,+ duration: SCROLL_SCRUB_SECONDS,+ ease: "none",+ onUpdate: () => paint(state.progress),+ });+ };const followScroll = () => {frame = 0;- const start = Math.max(0, originTop - window.innerHeight * START_RATIO);- const progress = clamp01((window.scrollY - start) / window.innerHeight);- if (progress === state.progress) return;- state.progress = progress;- paint(progress);+ syncScrollProgress();};window.addEventListener(@@ -140,19 +225,39 @@ export function initGenie(root: HTMLElement, reduceMotion: boolean) {{ passive: true },);- root.querySelector<HTMLButtonElement>("[data-minimize]")?.addEventListener("click", () => {+ const flyTo = (progress: number) => {+ scrollProgress = readScrollProgress();+ manualTarget = progress;+ manualDirection = Math.sign(scrollProgress - progress);+ scrollTarget = null;+ gsap.killTweensOf(state);+ manualFlight = true;gsap.to(state, {- progress: state.progress > 0.5 ? 0 : 1,+ progress,duration: FLIGHT_SECONDS,ease: "power2.inOut",onUpdate: () => paint(state.progress),+ onComplete: () => {+ manualFlight = false;+ syncScrollProgress();+ },});+ };++ root.querySelector<HTMLButtonElement>("[data-minimize]")?.addEventListener("click", () => {+ flyTo(state.progress > 0.5 ? 0 : 1);});- window.addEventListener("resize", build, { passive: true });- // Fonts and icons change the layout the geometry was measured from.- document.fonts.ready.then(build);- window.addEventListener("load", build);+ restore?.addEventListener("click", () => flyTo(0));++ const refresh = () => {+ build();+ syncScrollProgress();+ };+ window.addEventListener("resize", refresh, { passive: true });+ document.fonts.ready.then(refresh);+ window.addEventListener("load", refresh);+ syncScrollProgress();}/** Draws the window at rest, mirroring the DOM mock so the flight can start from it. */@@ -175,38 +280,40 @@ function renderWindow(width: number, height: number, dpr: number) {context.fillStyle = "rgba(255, 253, 247, 0.97)";context.fillRect(0, 0, width, height);+ // These offsets mirror the CSS in `NotesWindow.astro`; the two must line up or the+ // handover from the DOM window to this copy shows as a jump.const sidebar = width >= 440 ? 158 : 0;if (sidebar) drawSidebar(context, sidebar, height);const left = sidebar + 20;const center = (left + width - 20) / 2;- drawTrafficLights(context, 18, 18);+ drawTrafficLights(context, 22, 20);context.textAlign = "center";context.fillStyle = "#1d1d1f";context.font = '700 13px "Plus Jakarta Sans", system-ui, sans-serif';- context.fillText("Notes", center, 14);+ context.fillText("Notes", center, 22);context.fillStyle = "rgba(0, 0, 0, 0.38)";context.font = '500 11px "Plus Jakarta Sans", system-ui, sans-serif';- context.fillText("Friday, November 14, 2026 at 9:41 AM", center, 36);+ context.fillText("Friday, November 14, 2026 at 9:41 AM", center, 44);context.textAlign = "left";context.fillStyle = "#1d1d1f";context.font = '800 26px "Plus Jakarta Sans", system-ui, sans-serif';- context.fillText("Ship the Dock.", left, 74);+ context.fillText("Ship the Dock.", left, 81);const tasks = [["Magnification, smooth curve", true],- ["Genie minimize in 0.5 s", true],- ["Taskbar back in under 2 s", true],+ ["Live thumbnails when minimized", true],+ ["Taskbar always comes back", true],["0% CPU when idle", true],["Publish v0.1", false],] as const;tasks.forEach(([label, done], index) => {- const y = 104 + index * 30;+ const y = 117 + index * 29;drawCheck(context, left + 8, y, done);context.fillStyle = done ? "rgba(0, 0, 0, 0.4)" : "#1d1d1f";context.font = '500 14px "Plus Jakarta Sans", system-ui, sans-serif';@@ -231,7 +338,7 @@ function drawSidebar(context.fillStyle = "rgba(0, 0, 0, 0.45)";context.font = '700 11px "Plus Jakarta Sans", system-ui, sans-serif';- context.fillText("Folders", 12, 70);+ context.fillText("Folders", 12, 60);const folders = [["All Notes", 12, false],@@ -241,7 +348,7 @@ function drawSidebar(] as const;folders.forEach(([name, count, active], index) => {- const y = 94 + index * 30;+ const y = 90 + index * 29.7;if (active) {context.fillStyle = "#0a84ff";diff --git a/muelle/src/styles/dock.css b/muelle/src/styles/dock.cssindex 1ea266a..e7332f8 100644--- a/muelle/src/styles/dock.css+++ b/muelle/src/styles/dock.css@@ -87,6 +87,10 @@box-shadow: 0 30px 60px rgb(0 0 0 / 0.38);}+.genie-canvas {+ filter: drop-shadow(0 22px 30px rgb(0 0 0 / 0.42));+}+.traffic {display: flex;gap: 8px;@@ -189,6 +193,39 @@filter: drop-shadow(0 2px 4px rgb(0 0 0 / 0.4));}+/* Minimized-window slot: `--slot` goes from 0 to 1 as the genie lands, so the dock+ makes room for it exactly when the window arrives. */+.dock-item[data-dock-thumb] {+ width: calc(52px * var(--slot, 0));+ height: calc(52px * var(--slot, 0));+ margin-inline: calc(3px * var(--slot, 0));+ opacity: var(--slot, 0);+}++.dock-thumb {+ display: block;+ width: 100%;+ height: 100%;+ padding: 0;+ border: 0;+ background: none;+ cursor: pointer;+}++.dock-thumb canvas {+ display: block;+ width: 100%;+ height: 100%;+ border: 1px solid rgb(255 255 255 / 0.6);+ border-radius: 12%;+ box-shadow: 0 3px 8px rgb(0 0 0 / 0.4);+}++.dock-thumb:focus-visible {+ outline: 2px solid var(--color-acid);+ outline-offset: 4px;+}+.dock-tip {position: absolute;left: 50%;