A lightweight, macOS-style dock for Windows 11, with glass visuals, smooth magnification, and Genie effect.
feat: enhance icon integration and improve dock functionality; add new icons and optimize clock and customize scripts
CristianOlivera10b9e88276e7c
diff --git a/muelle/src/components/showcase/Customize.astro b/muelle/src/components/showcase/Customize.astroindex 1e20e3c..7637d03 100644--- a/muelle/src/components/showcase/Customize.astro+++ b/muelle/src/components/showcase/Customize.astro@@ -3,6 +3,7 @@ import { Image } from "astro:assets";import wallpaper from "@/assets/wallpapers/desktop-02.jpg";import Section from "@/components/layout/Section.astro";import SectionIntro from "@/components/showcase/SectionIntro.astro";+import Icon from "@/components/ui/Icon.astro";import {customizeIntro,previewIcons,@@ -15,6 +16,10 @@ import "@/styles/showcase.css";const t = settingsText.en;const tx = (key: SettingsKey) => ({ "data-t": key });const checked = (on: boolean) => (on ? "true" : "false");+// Use names your Icon component knows.+const paneIcons = { dock: "app-window", system: "gear-six" } as const;+// `<` is escaped so no text can ever close the script tag early.+const textJson = JSON.stringify(settingsText).replace(/</g, "\\u003c");---<Section id="customize">@@ -26,11 +31,11 @@ const checked = (on: boolean) => (on ? "true" : "false");<div class="mac-lights" aria-hidden="true"><i></i><i></i><i></i></div><nav class="settings-nav"><button type="button" data-pane="dock" aria-current="page">- <span class="settings-glyph" aria-hidden="true">▭</span>+ <span class="settings-glyph" aria-hidden="true"><Icon name={paneIcons.dock} size={16} /></span><span {...tx("dock")}>{t.dock}</span></button><button type="button" data-pane="system">- <span class="settings-glyph" aria-hidden="true">⚙</span>+ <span class="settings-glyph" aria-hidden="true"><Icon name={paneIcons.system} size={16} /></span><span {...tx("system")}>{t.system}</span></button></nav>@@ -50,6 +55,7 @@ const checked = (on: boolean) => (on ? "true" : "false");class="mac-range"aria-label={t.size}data-setting="iconSize"+ data-label="size"min={d.iconSizeMin}max={d.iconSizeMax}value={d.iconSize}@@ -139,12 +145,12 @@ const checked = (on: boolean) => (on ? "true" : "false");</div><div class="settings-row"><span class="settings-label" {...tx("language")}>{t.language}</span>- <span class="mac-seg" role="radiogroup" aria-label={t.language}>- <button type="button" role="radio" aria-checked="true" data-lang="auto" {...tx("languageAuto")}+ <span class="mac-seg" role="radiogroup" aria-label={t.language} data-label="language">+ <button type="button" role="radio" aria-checked="false" data-lang="auto" {...tx("languageAuto")}>{t.languageAuto}</button><button type="button" role="radio" aria-checked="false" data-lang="es">Español</button>- <button type="button" role="radio" aria-checked="false" data-lang="en">English</button>+ <button type="button" role="radio" aria-checked="true" data-lang="en">English</button></span></div></div>@@ -152,7 +158,7 @@ const checked = (on: boolean) => (on ? "true" : "false");<div class="settings-row"><span class="settings-text"><span class="settings-label" {...tx("updates")}>{t.updates}</span>- <span class="settings-hint" data-update-status>{t.updatesCurrent}</span>+ <span class="settings-hint" data-update-status aria-live="polite">{t.updatesCurrent}</span></span><button type="button" class="mac-button" data-update {...tx("updatesCheck")}>{t.updatesCheck}</button></div>@@ -165,14 +171,14 @@ const checked = (on: boolean) => (on ? "true" : "false");<Image src={wallpaper} alt="" class="preview-wall" widths={[480, 960]} sizes="(min-width: 1024px) 480px, 100vw" /><div class="preview-bar" data-preview-bar><b>File Explorer</b>- <span class="tabular-nums" data-clock>9:41</span>+ <span class="tabular-nums" data-clock>9:41 AM</span></div><div class="preview-dock" data-preview-dock>{previewIcons.map((icon) => <Image src={icon} alt="" width={128} height={128} />)}</div></div>- <script type="application/json" is:inline data-settings-text set:html={JSON.stringify(settingsText)} />+ <script type="application/json" is:inline data-settings-text set:html={textJson} /></div></Section>@@ -187,4 +193,4 @@ const checked = (on: boolean) => (on ? "true" : "false");initCustomize(section);}initClock();-</script>+</script>\ No newline at end of filediff --git a/muelle/src/components/ui/IconSprite.astro b/muelle/src/components/ui/IconSprite.astroindex 289182c..5c13c35 100644--- a/muelle/src/components/ui/IconSprite.astro+++ b/muelle/src/components/ui/IconSprite.astro@@ -53,4 +53,10 @@d="M232.49,80.49l-128,128a12,12,0,0,1-17,0l-56-56a12,12,0,1,1,17-17L96,183,215.51,63.51a12,12,0,0,1,17,17Z"></path></symbol>+ <symbol id="icon-app-window" viewBox="0 0 256 256">+ <path d="M216,40H40A16,16,0,0,0,24,56V200a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V56A16,16,0,0,0,216,40ZM68,96A12,12,0,1,1,80,84,12,12,0,0,1,68,96Zm40,0a12,12,0,1,1,12-12A12,12,0,0,1,108,96Z" />+ </symbol>+ <symbol id="icon-gear-six" viewBox="0 0 256 256">+ <path d="M237.94,107.21a8,8,0,0,0-3.89-5.4l-29.83-17-.12-33.62a8,8,0,0,0-2.83-6.08,111.91,111.91,0,0,0-36.72-20.67,8,8,0,0,0-6.46.59L128,41.85,97.88,25a8,8,0,0,0-6.47-.6A111.92,111.92,0,0,0,54.73,45.15a8,8,0,0,0-2.83,6.07l-.15,33.65-29.83,17a8,8,0,0,0-3.89,5.4,106.47,106.47,0,0,0,0,41.56,8,8,0,0,0,3.89,5.4l29.83,17,.12,33.63a8,8,0,0,0,2.83,6.08,111.91,111.91,0,0,0,36.72,20.67,8,8,0,0,0,6.46-.59L128,214.15,158.12,231a7.91,7.91,0,0,0,3.9,1,8.09,8.09,0,0,0,2.57-.42,112.1,112.1,0,0,0,36.68-20.73,8,8,0,0,0,2.83-6.07l.15-33.65,29.83-17a8,8,0,0,0,3.89-5.4A106.47,106.47,0,0,0,237.94,107.21ZM128,168a40,40,0,1,1,40-40A40,40,0,0,1,128,168Z" />+ </symbol></svg>diff --git a/muelle/src/lib/icons.ts b/muelle/src/lib/icons.tsindex bfb1240..5306128 100644--- a/muelle/src/lib/icons.ts+++ b/muelle/src/lib/icons.ts@@ -1,4 +1,3 @@-/** Phosphor glyphs used by the site, kept in sync with `components/ui/IconSprite.astro`. */export type IconName =| "anchor"| "github"@@ -9,4 +8,6 @@ export type IconName =| "copy"| "check"| "menu"- | "close";+ | "close"+ | "app-window"+ | "gear-six";\ No newline at end of filediff --git a/muelle/src/scripts/clock.ts b/muelle/src/scripts/clock.tsindex df15104..20ecf29 100644--- a/muelle/src/scripts/clock.ts+++ b/muelle/src/scripts/clock.ts@@ -1,23 +1,31 @@-// The landing is written in English, so the mock clock keeps that language even on a Spanish system.const timeFormat = new Intl.DateTimeFormat("en-US", { hour: "numeric", minute: "2-digit" });const dateFormat = new Intl.DateTimeFormat("en-US", { weekday: "short", day: "numeric", month: "short" });-/** Keeps the fake menu bar clock in step with the machine, aligned to the half minute. */+let started = false;++/** Keeps every fake menu bar clock in step with the machine, ticking on the minute. */export function initClock() {- const clocks = document.querySelectorAll<HTMLElement>("[data-clock]");- const dates = document.querySelectorAll<HTMLElement>("[data-date]");- if (!clocks.length && !dates.length) return;+ if (started) return;+ started = true;const update = () => {const now = new Date();- clocks.forEach((node) => {+ document.querySelectorAll<HTMLElement>("[data-clock]").forEach((node) => {node.textContent = timeFormat.format(now);});- dates.forEach((node) => {- node.textContent = dateFormat.format(now);+ document.querySelectorAll<HTMLElement>("[data-date]").forEach((node) => {+ node.textContent = dateFormat.format(now).replace(",", "");});};- update();- window.setInterval(update, 30_000);-}+ const tick = () => {+ update();+ window.setTimeout(tick, 60_000 - (Date.now() % 60_000) + 50);+ };+ tick();++ // Timers are throttled in background tabs: catch up the moment the tab is visible again.+ document.addEventListener("visibilitychange", () => {+ if (!document.hidden) update();+ });+}\ No newline at end of filediff --git a/muelle/src/scripts/customize.ts b/muelle/src/scripts/customize.tsindex 2ebbd46..4530a73 100644--- a/muelle/src/scripts/customize.ts+++ b/muelle/src/scripts/customize.ts@@ -4,11 +4,17 @@ import { prefersReducedMotion } from "@/lib/motion";const PREVIEW_SCALE = 0.7;/** Horizontal room the dock needs besides its icons: gaps, padding, border and a margin to the desk edge. */const DOCK_CHROME = 72;-/** Width of the magnified area around the pointer, in preview pixels. */+/** Width of the magnified area around the pointer, in preview pixels at `PREVIEW_SCALE`. */const SIGMA = 46;/** How close to an edge the pointer must be to reveal an auto-hidden bar. */const EDGE = 34;+/** Extra reach that keeps a revealed dock open while the pointer travels over it. */+const DOCK_REACH = 60;const CHECK_MS = 1100;+/** How long the dock stays magnified after a magnification setting changes. */+const DEMO_MS = 1400;+/** Gap between preview icons; it must match the gap of `.preview-dock` in the stylesheet. */+const ICON_GAP = 6;type Strings = Record<string, string>;@@ -54,26 +60,30 @@ export function initCustomize(root: HTMLElement) {let pointerX: number | null = null;let nearBottom = false;let nearTop = false;+ // Stands in for the pointer while a magnification setting is being changed, so the+ // slider gives feedback even though the pointer is over the Settings window.+ let demoX: number | null = null;+ let demoTimer = 0;const layoutDock = () => {// Narrow desks (phones) shrink the dock so even the largest icon size fits.const largest = icons.length * Number(ranges.get("iconSize")?.max ?? 0);const scale = Math.min(PREVIEW_SCALE, (preview.clientWidth - DOCK_CHROME) / (largest || 1));+ const sigma = SIGMA * (scale / PREVIEW_SCALE);const size = value("iconSize") * scale;const peak = value("magnifiedSize") * scale;- const magnify = isOn("magnification") && pointerX !== null && !prefersReducedMotion();- const centers = icons.map((_, index) => {- // Centres of the resting row: the magnified widths are derived from these.- const gap = 6;- const rowWidth = icons.length * size + (icons.length - 1) * gap;- const left = preview.clientWidth / 2 - rowWidth / 2;- return left + index * (size + gap) + size / 2;- });+ const focusX = pointerX ?? demoX;+ const magnify = isOn("magnification") && focusX !== null && !prefersReducedMotion();++ // Centres of the resting row: the magnified widths are derived from these.+ const rowWidth = icons.length * size + (icons.length - 1) * ICON_GAP;+ const left = preview.clientWidth / 2 - rowWidth / 2;icons.forEach((icon, index) => {let width = size;- if (magnify && pointerX !== null) {- const distance = pointerX - centers[index];- width = size + (Math.max(peak, size) - size) * Math.exp(-(distance * distance) / (2 * SIGMA * SIGMA));+ if (magnify && focusX !== null) {+ const center = left + index * (size + ICON_GAP) + size / 2;+ const distance = focusX - center;+ width = size + (Math.max(peak, size) - size) * Math.exp(-(distance * distance) / (2 * sigma * sigma));}icon.style.width = `${width}px`;icon.style.height = `${width}px`;@@ -81,6 +91,27 @@ export function initCustomize(root: HTMLElement) {dock.style.setProperty("--rest", `${size}px`);};+ // Pointer moves arrive faster than frames; one layout per frame is enough.+ let queued = 0;+ const schedule = () => {+ if (queued) return;+ queued = requestAnimationFrame(() => {+ queued = 0;+ layoutDock();+ });+ };++ const demoMagnify = () => {+ window.clearTimeout(demoTimer);+ demoX = isOn("magnification") ? preview.clientWidth / 2 : null;+ layoutDock();+ if (demoX === null) return;+ demoTimer = window.setTimeout(() => {+ demoX = null;+ layoutDock();+ }, DEMO_MS);+ };+const applyBars = () => {const dockHidden = isOn("autoHide") && !nearBottom;const barShown = isOn("menuBar") && (!isOn("menuBarAutoHide") || nearTop);@@ -93,18 +124,21 @@ export function initCustomize(root: HTMLElement) {preview.addEventListener("pointermove", (event) => {const rect = preview.getBoundingClientRect();const y = event.clientY - rect.top;- nearBottom = rect.height - y < EDGE + (isOn("autoHide") ? 0 : 60);+ // Once revealed, the dock stays open over its whole height: otherwise it would hide+ // while the pointer climbs towards its icons.+ const reach = !isOn("autoHide") || nearBottom ? EDGE + DOCK_REACH : EDGE;+ nearBottom = rect.height - y < reach;nearTop = y < EDGE;pointerX = nearBottom ? event.clientX - rect.left : null;applyBars();- layoutDock();+ schedule();});preview.addEventListener("pointerleave", () => {pointerX = null;nearBottom = false;nearTop = false;applyBars();- layoutDock();+ schedule();});/* ---- Controls ------------------------------------------------------- */@@ -113,8 +147,9 @@ export function initCustomize(root: HTMLElement) {const magnified = ranges.get("magnifiedSize");if (!magnified) return;// As in the app: the magnified size never goes below the icon size.- magnified.min = String(value("iconSize"));- if (Number(magnified.value) < value("iconSize")) magnified.value = String(value("iconSize"));+ const floor = Math.min(value("iconSize"), Number(magnified.max));+ magnified.min = String(floor);+ if (Number(magnified.value) < floor) magnified.value = String(floor);magnified.disabled = !isOn("magnification");paintRange(magnified);};@@ -124,7 +159,8 @@ export function initCustomize(root: HTMLElement) {input.addEventListener("input", () => {paintRange(input);syncMagnified();- layoutDock();+ if (input.dataset.setting === "magnifiedSize") demoMagnify();+ else layoutDock();});});@@ -133,7 +169,8 @@ export function initCustomize(root: HTMLElement) {button.setAttribute("aria-checked", String(!isOn(button.dataset.setting ?? "")));syncMagnified();applyBars();- layoutDock();+ if (button.dataset.setting === "magnification") demoMagnify();+ else layoutDock();});});@@ -160,13 +197,14 @@ export function initCustomize(root: HTMLElement) {const setLanguage = (choice: string) => {const resolved = choice === "auto" ? (navigator.language.toLowerCase().startsWith("es") ? "es" : "en") : choice;strings = texts[resolved === "es" ? "es" : "en"];+ scene.lang = resolved === "es" ? "es" : "en";scene.querySelectorAll<HTMLElement>("[data-t]").forEach((node) => {const text = strings[node.dataset.t ?? ""];if (text) node.textContent = text;});- scene.querySelectorAll<HTMLElement>("[aria-label]").forEach((node) => {- const key = node.dataset.setting;- if (key && strings[key]) node.setAttribute("aria-label", strings[key]);+ scene.querySelectorAll<HTMLElement>("[data-label], [data-setting]").forEach((node) => {+ const key = node.dataset.label ?? node.dataset.setting ?? "";+ if (strings[key]) node.setAttribute("aria-label", strings[key]);});if (status) status.textContent = strings.updatesCurrent;scene.querySelectorAll<HTMLButtonElement>("[data-lang]").forEach((button) => {@@ -193,4 +231,4 @@ export function initCustomize(root: HTMLElement) {applyBars();layoutDock();window.addEventListener("resize", layoutDock, { passive: true });-}+}\ No newline at end of filediff --git a/muelle/src/scripts/genie.ts b/muelle/src/scripts/genie.tsindex 28abcbe..7b623f5 100644--- a/muelle/src/scripts/genie.ts+++ b/muelle/src/scripts/genie.ts@@ -1,14 +1,3 @@-/**- * Genie minimize, the same effect the Muelle app draws (`crates/muelle-core/src/genie.rs`):- * the sides of the window bend into a funnel that ends at the dock slot, and the image- * slides down through it, vanishing as it enters the slot.- *- * The window is copied once from the DOM into a canvas (same boxes, fonts, colours and- * icons), cut into thin strips, and each strip is stretched between the funnel's sides.- * It plays on a timer, like the app: when the dock comes fully into view while scrolling,- * from the yellow traffic light, or from the dock slot to restore.- */-import { gsap } from "@/lib/motion";const MINIMIZE_SECONDS = 0.6;@@ -19,6 +8,8 @@ const MAX_DPR = 2;const THUMB_SIZE = 52;/** Resting width of a dock item, needed to measure the slot without the magnification. */const DOCK_REST = 52;+/** Resize and font events arrive in bursts; the scene is rebuilt once they settle. */+const REBUILD_DELAY_MS = 120;/** Same curve parameters as the app. */const BEND_END = 0.5;@@ -46,7 +37,7 @@ interface Scene {export function initGenie(root: HTMLElement, reduceMotion: boolean) {const canvas = root.querySelector<HTMLCanvasElement>("[data-genie]");const note = root.querySelector<HTMLElement>("[data-note]");- const slot = document.querySelector<HTMLElement>("[data-dock-thumb]");+ const slot = root.querySelector<HTMLElement>("[data-dock-thumb]");const thumb = slot?.querySelector<HTMLCanvasElement>("canvas");const restore = slot?.querySelector<HTMLButtonElement>("[data-dock-restore]");const dock = root.querySelector<HTMLElement>(".dock");@@ -59,6 +50,7 @@ export function initGenie(root: HTMLElement, reduceMotion: boolean) {let slotValue = -1;let flyingBefore = false;let minimizedBefore = false;+ let version = 0;const paint = (progress: number) => {const hidden = progress > 0;@@ -89,11 +81,17 @@ export function initGenie(root: HTMLElement, reduceMotion: boolean) {};const build = async () => {+ // Builds are async and can overlap; only the newest one may write the scene.+ const mine = ++version;dpr = Math.min(window.devicePixelRatio || 1, MAX_DPR);const rootRect = root.getBoundingClientRect();const noteRect = note.getBoundingClientRect();const slotRect = measureSlot(root, slot);+ // A canvas is a replaced element: `inset-0` does not stretch it, so without an+ // explicit CSS size it draws at its backing-store size and the drawing is scaled by dpr.+ canvas.style.width = `${rootRect.width}px`;+ canvas.style.height = `${rootRect.height}px`;canvas.width = Math.round(rootRect.width * dpr);canvas.height = Math.round(rootRect.height * dpr);@@ -104,6 +102,8 @@ export function initGenie(root: HTMLElement, reduceMotion: boolean) {const copying = copyElement(note, dpr);note.style.visibility = visibility;const source = await copying;+ if (mine !== version) return;+scene = {window: {left: noteRect.left - rootRect.left,@@ -128,11 +128,15 @@ export function initGenie(root: HTMLElement, reduceMotion: boolean) {// Below 900 px the dock scrolls sideways and its slot sits off screen, so the// window simply stays where it is.const wideEnough = window.matchMedia("(min-width: 900px)");- if (reduceMotion || !wideEnough.matches) return;const play = (target: 0 | 1) => {- if (state.progress === target) return;+ if (!wideEnough.matches || state.progress === target) return;gsap.killTweensOf(state);+ if (reduceMotion) {+ state.progress = target;+ paint(target);+ return;+ }gsap.to(state, {progress: target,duration: (target ? MINIMIZE_SECONDS : RESTORE_SECONDS) * Math.abs(target - state.progress),@@ -151,6 +155,7 @@ export function initGenie(root: HTMLElement, reduceMotion: boolean) {let frame = 0;const onScroll = () => {frame = 0;+ if (reduceMotion || !wideEnough.matches) return;const rect = dock.getBoundingClientRect();const inView = rect.bottom <= window.innerHeight && rect.top >= 0;const below = rect.top > window.innerHeight;@@ -175,9 +180,24 @@ export function initGenie(root: HTMLElement, reduceMotion: boolean) {{ passive: true },);+ wideEnough.addEventListener("change", (event) => {+ if (event.matches) {+ dockInView = null;+ onScroll();+ } else {+ gsap.killTweensOf(state);+ state.progress = 0;+ paint(0);+ }+ });++ let timer = 0;const refresh = () => {- build();- onScroll();+ window.clearTimeout(timer);+ timer = window.setTimeout(() => {+ build();+ onScroll();+ }, REBUILD_DELAY_MS);};window.addEventListener("resize", refresh, { passive: true });document.fonts.ready.then(refresh);@@ -327,12 +347,15 @@ async function copyElement(element: HTMLElement, dpr: number): Promise<HTMLCanvacontext.letterSpacing = style.letterSpacing === "normal" ? "0px" : style.letterSpacing;context.fillStyle = style.color;context.textBaseline = "alphabetic";- const metrics = context.measureText(child.textContent);- context.fillText(- child.textContent.trim(),- textRect.left - box.left,- textRect.top - box.top + metrics.fontBoundingBoxAscent,- );+ const raw = child.textContent.trim();+ const text =+ style.textTransform === "uppercase"+ ? raw.toUpperCase()+ : style.textTransform === "lowercase"+ ? raw.toLowerCase()+ : raw;+ const metrics = context.measureText(text);+ context.fillText(text, textRect.left - box.left, textRect.top - box.top + metrics.fontBoundingBoxAscent);}}@@ -382,4 +405,4 @@ function renderThumbnail(canvas: HTMLCanvasElement, source: HTMLCanvasElement, dconst width = source.width * scale;context.drawImage(source, (size - width) / 2, 0, width, source.height * scale);context.restore();-}+}\ No newline at end of filediff --git a/muelle/src/scripts/reveal.ts b/muelle/src/scripts/reveal.tsindex 6f3e52a..cf040df 100644--- a/muelle/src/scripts/reveal.ts+++ b/muelle/src/scripts/reveal.ts@@ -5,6 +5,22 @@ const STAGGER = 0.08;/** Four steps is all the eye notices; a full twenty-item stagger feels slow. */const STAGGER_STEPS = 4;+let wave = 0;+let resetFrame = 0;++/** Items that enter in the same frame form one wave and stagger among themselves. */+const nextDelay = () => {+ const delay = (wave % STAGGER_STEPS) * STAGGER;+ wave += 1;+ if (!resetFrame) {+ resetFrame = requestAnimationFrame(() => {+ wave = 0;+ resetFrame = 0;+ });+ }+ return delay;+};+/*** Fades in the elements marked `data-r` once. Each element gets its own trigger:* a batch defers elements that are already on screen at load, which leaves them@@ -19,7 +35,7 @@ export function initReveal(root: HTMLElement) {gsap.set(items, { opacity: 0, y: 32 });- items.forEach((item, index) => {+ items.forEach((item) => {ScrollTrigger.create({trigger: item,start: "top 92%",@@ -29,9 +45,9 @@ export function initReveal(root: HTMLElement) {opacity: 1,y: 0,duration: DURATION,- delay: (index % STAGGER_STEPS) * STAGGER,+ delay: nextDelay(),ease: "power3.out",}),});});-}+}\ No newline at end of file