Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.
Rust apple-notesapple-reminderscloudkitcrdtdesktop-appicloudicloud-calendaricloud-driveicloud-notesicloud-photosiphonelinuxlinux-desktoplocal-firstoffline-firstprivacyrusttauritauri-appwindows
Motion: popovers grow out of what opened them; a segmented control's thumb slides
Yashwanth Kamireddifc48b186843d
diff --git a/src/lib/fade.ts b/src/lib/fade.tsindex 0f3cf24..3ad6523 100644--- a/src/lib/fade.ts+++ b/src/lib/fade.ts@@ -77,17 +77,85 @@ export function fadeOut(el: HTMLElement | null, done: () => void, duration = 120*/export function fadeSheetsIn() {const sheets = ".modal-sheet";+ // Popovers drawn at the top of the page grow out of what opened them (`grow`); menus and+ // the search's results are simply there, as a Mac's are.+ const popovers = ".cx-popover, .format-panel";+ watchPresses();new MutationObserver((changes) => {for (const change of changes) {for (const node of change.addedNodes) {if (!(node instanceof HTMLElement)) continue;if (node.matches(sheets)) fadeIn(node, { duration: 140 });node.querySelectorAll<HTMLElement>(sheets).forEach((el) => fadeIn(el, { duration: 140 }));+ if (node.matches(popovers)) grow(node);}}}).observe(document.body, { childList: true });}+/* ---- a popover growing out of what opened it ----------------------------------------------+ *+ * As a macOS 26 popover does: from just smaller than itself, at the side nearest the control+ * or the spot that was clicked, to whole, fading in as it goes — 140ms, decelerating. Drawn by+ * the page frame by frame on opacity and `scale` only (the reasons are at the top of this+ * file), so nothing is laid out and nothing beside it moves; set before its first frame is+ * painted, so it never shows whole first. Only as it opens: moved to a new place while open,+ * it simply is there. Instant under Reduce Motion. */++/** Where the last press was, and when: what a popover opened by it grows out of. */+let lastPress: { x: number; y: number; at: number } | null = null;+let watching = false;+function watchPresses() {+ if (watching) return;+ watching = true;+ document.addEventListener("pointerdown", (e) => { lastPress = { x: e.clientX, y: e.clientY, at: performance.now() }; }, true);+}++/** What opened a popover appearing now: the press just made, or else the control with the+ keyboard's focus (a popover opened from the keyboard). */+function opener(): { x: number; y: number } | null {+ if (lastPress && performance.now() - lastPress.at < 800) return lastPress;+ const el = document.activeElement;+ if (!(el instanceof HTMLElement) || el === document.body) return null;+ const r = el.getBoundingClientRect();+ return { x: r.left + r.width / 2, y: r.top + r.height / 2 };+}++export function grow(el: HTMLElement | null, from: { x: number; y: number } | null = opener()) {+ if (!el) return;+ const duration = token("--motion-pop", 140);+ if (reduced() || duration <= 0) return;+ const start0 = token("--pop-from", 0.96);+ // Out of the point of the popover nearest what opened it: a popover below its button grows+ // down from its top edge under the button; one beside an event, out of the side facing it.+ const r = el.getBoundingClientRect();+ const ox = from ? Math.min(Math.max(from.x, r.left), r.right) - r.left : r.width / 2;+ const oy = from ? Math.min(Math.max(from.y, r.top), r.bottom) - r.top : 0;+ cancelAnimationFrame(running.get(el) ?? 0);+ el.style.transformOrigin = `${ox.toFixed(1)}px ${oy.toFixed(1)}px`;+ el.style.opacity = "0";+ el.style.scale = String(start0);+ const finish = () => {+ el.style.opacity = "";+ el.style.scale = "";+ el.style.transformOrigin = "";+ running.delete(el);+ };+ const start = performance.now();+ const step = (now: number) => {+ const t = Math.max(0, Math.min(1, (now - start) / duration));+ if (t >= 1) return finish();+ // Decelerating (cubic ease-out): most of the way at once, settling gently.+ const k = 1 - (1 - t) ** 3;+ el.style.opacity = String(Math.min(1, k * 1.4).toFixed(3));+ el.style.scale = (start0 + (1 - start0) * k).toFixed(4);+ running.set(el, requestAnimationFrame(step));+ };+ running.set(el, requestAnimationFrame(step));+ // Whole on time even where no frames are drawn (a window out of sight draws none).+ window.setTimeout(() => { if (running.has(el)) { cancelAnimationFrame(running.get(el)!); finish(); } }, duration + 250);+}+/* ---- arrival: content that came in from another device ------------------------------------** It settles in without being pointed at — no highlight, no wash, as the best apps do it —@@ -101,12 +169,12 @@ export function fadeSheetsIn() {* <ReceivingLine> the calm line while many things arrive at once (components/ReceivingLine)*/-const reduced = () =>+export const reduced = () =>typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;/** A timing token in ms (or px, for a distance), as tokens.css sets it — 0 under ReduceMotion — or `fallback`. */-function token(name: string, fallback: number): number {+export function token(name: string, fallback: number): number {const v = getComputedStyle(document.documentElement).getPropertyValue(name).trim();const n = parseFloat(v);if (!Number.isFinite(n)) return fallback;diff --git a/src/lib/thumb.ts b/src/lib/thumb.tsnew file mode 100644index 0000000..8b6c514--- /dev/null+++ b/src/lib/thumb.ts@@ -0,0 +1,92 @@+/**+ * A segmented control's thumb slides from the segment that was chosen to the one chosen now,+ * as macOS 26 draws it — so the eye follows the choice instead of watching one cap vanish+ * and another appear.+ *+ * Every segmented control in the app (kit.css .segmented) is plain buttons with aria-pressed;+ * nothing in them changes for this. One observer, on that attribute alone, sees a choice+ * change: before the frame is painted it hides the new segment's own cap and draws the thumb+ * (the group's ::before) where the old one was, then moves it, frame by frame from the page+ * (lib/fade.ts says why never the compositor), to the new one: 160ms, decelerating, by+ * `translate` and its width only. The segments' words change weight at once; only the thumb+ * moves. A choice made mid-slide sets off from where the thumb is. Instant under Reduce+ * Motion, and when the control was not on screen.+ */+import { reduced, token } from "./fade";++type Box = { x: number; w: number };+const sliding = new WeakMap<HTMLElement, { frame: number; at: Box; timer: number }>();++function boxOf(group: HTMLElement, seg: HTMLElement): Box {+ const g = group.getBoundingClientRect();+ const r = seg.getBoundingClientRect();+ return { x: r.left - g.left - group.clientLeft, w: r.width };+}++function slide(group: HTMLElement, from: HTMLElement | null, to: HTMLElement) {+ const duration = token("--motion-thumb", 160);+ const running = sliding.get(group);+ const start = running?.at ?? (from ? boxOf(group, from) : null);+ if (running) {+ cancelAnimationFrame(running.frame);+ clearTimeout(running.timer);+ }+ const end = boxOf(group, to);+ if (!start || reduced() || duration <= 0 || !group.isConnected || end.w === 0 || (start.x === end.x && start.w === end.w)) {+ stop(group);+ return;+ }+ const r = to.getBoundingClientRect();+ const g = group.getBoundingClientRect();+ group.style.setProperty("--thumb-y", `${(r.top - g.top - group.clientTop).toFixed(2)}px`);+ group.style.setProperty("--thumb-h", `${r.height.toFixed(2)}px`);+ const place = (b: Box) => {+ group.style.setProperty("--thumb-x", `${b.x.toFixed(2)}px`);+ group.style.setProperty("--thumb-w", `${b.w.toFixed(2)}px`);+ };+ place(start);+ group.classList.add("is-sliding");+ const t0 = performance.now();+ const state = { frame: 0, at: start, timer: 0 };+ const step = (now: number) => {+ const t = Math.max(0, Math.min(1, (now - t0) / duration));+ if (t >= 1) return stop(group);+ const k = 1 - (1 - t) ** 3;+ state.at = { x: start.x + (end.x - start.x) * k, w: start.w + (end.w - start.w) * k };+ place(state.at);+ state.frame = requestAnimationFrame(step);+ };+ state.frame = requestAnimationFrame(step);+ // Settled on time even where no frames are drawn (a window out of sight draws none).+ state.timer = window.setTimeout(() => stop(group), duration + 250);+ sliding.set(group, state);+}++function stop(group: HTMLElement) {+ const s = sliding.get(group);+ if (s) {+ cancelAnimationFrame(s.frame);+ clearTimeout(s.timer);+ }+ sliding.delete(group);+ group.classList.remove("is-sliding");+ for (const p of ["--thumb-x", "--thumb-w", "--thumb-y", "--thumb-h"]) group.style.removeProperty(p);+}++export function slideThumbs() {+ new MutationObserver((records) => {+ const moves = new Map<HTMLElement, { from: HTMLElement | null; to: HTMLElement | null }>();+ for (const rec of records) {+ const seg = rec.target as HTMLElement;+ if (!seg.classList?.contains("segment")) continue;+ const group = seg.parentElement;+ if (!group?.classList.contains("segmented")) continue;+ const m = moves.get(group) ?? { from: null, to: null };+ const on = seg.getAttribute("aria-pressed") === "true";+ if (on && rec.oldValue !== "true") m.to = seg;+ if (!on && rec.oldValue === "true") m.from = seg;+ moves.set(group, m);+ }+ for (const [group, { from, to }] of moves) if (to && (from || sliding.has(group))) slide(group, from, to);+ }).observe(document.body, { subtree: true, attributes: true, attributeFilter: ["aria-pressed"], attributeOldValue: true });+}diff --git a/src/main.tsx b/src/main.tsxindex efe16e6..335dbfb 100644--- a/src/main.tsx+++ b/src/main.tsx@@ -14,6 +14,7 @@ import { keepTinted } from "./lib/tint";import { fadeSheetsIn } from "./lib/fade";import { followClick } from "./lib/follow";import { markEngine } from "./lib/engine";+import { slideThumbs } from "./lib/thumb";// Before the first paint, so the window opens in the appearance chosen.markEngine();@@ -22,6 +23,7 @@ followTheme();followContrast();keepTinted();fadeSheetsIn();+slideThumbs();/** Every link goes the one way out: through `followClick` (lib/follow.ts), which checks whatdiff --git a/src/screens/photos/JumpTo.tsx b/src/screens/photos/JumpTo.tsxindex 4bd6492..15f35af 100644--- a/src/screens/photos/JumpTo.tsx+++ b/src/screens/photos/JumpTo.tsx@@ -7,7 +7,7 @@ import { useActiveRef } from "../../lib/screen";import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";import { fitSrc } from "../../lib/ipc";import { Portal } from "../../components/Portal";-import { fadeIn } from "../../lib/fade";+import { grow } from "../../lib/fade";export type MonthCover = { label: string; year: number; month: number; cover: { id: string } };@@ -35,8 +35,8 @@ export function JumpTo({const shown = months.filter((m) => m.year === year).sort((a, b) => a.month - b.month);// Once, before its first frame is painted: run after it, the picker showed whole for a frame- // and then began its fade from nothing — a flash.- useLayoutEffect(() => fadeIn(box.current, { duration: 140 }), []);+ // and then began its fade from nothing — a flash. It grows out of the button that opened it.+ useLayoutEffect(() => grow(box.current, { x: at.left + at.width / 2, y: at.top + at.height / 2 }), []);const live = useActiveRef();useEffect(() => {box.current?.focus({ preventScroll: true });diff --git a/src/styles/calendar.css b/src/styles/calendar.cssindex 7acc79e..a223800 100644--- a/src/styles/calendar.css+++ b/src/styles/calendar.css@@ -592,11 +592,11 @@-webkit-backdrop-filter: var(--glass-regular-filter);backdrop-filter: var(--glass-regular-filter);box-shadow: var(--glass-float);- /* Opacity and a small lift only, on the compositor: scaling from the corner read as a- jump toward the click, and re-ran on every re-anchor. */- /* A short fade and nothing else — no movement, no layer hint — as a macOS popover. */- /* No opening animation, as a menu has none: a fade over a large shadowed layer is what- WebKitGTK drew with a glitch. It is simply there. */+ /* Grows out of the event that opened it as it appears (lib/fade.ts grow): drawn by the+ page frame by frame, from 96% only and from the edge facing the click, once — never on a+ re-anchor. History: a compositor (CSS) fade over this large shadowed layer was what+ WebKitGTK drew with a glitch, and scaling from the corner, further and again on each+ re-anchor, read as a jump toward the click. */}@keyframes cx-pop { from { opacity: 0; } to { opacity: 1; } }@media (prefers-reduced-motion: reduce) { .cx-popover { animation: none; } }diff --git a/src/styles/kit.css b/src/styles/kit.cssindex 5d3ed01..5b1b902 100644--- a/src/styles/kit.css+++ b/src/styles/kit.css@@ -541,6 +541,9 @@ textarea.field { padding-block: 5px; resize: vertical; }/* A segmented control: one recessed track, a raised cap over the chosen segment. */.segmented {+ /* The thumb that slides between segments (lib/thumb.ts) is drawn inside it, under them. */+ position: relative;+ isolation: isolate;display: inline-flex;padding: 2px;gap: 2px;@@ -568,6 +571,25 @@ textarea.field { padding-block: 5px; resize: vertical; }box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14), 0 0 0 var(--hairline) var(--glass-edge);}.segment:focus-visible { outline: var(--focus-ring); outline-offset: 1px; }+/* The thumb on its way from one segment to the next (lib/thumb.ts): the chosen segment's cap,+ drawn by the group under the segments while the segment's own waits, hidden. */+.segmented.is-sliding > .segment { position: relative; z-index: 1; }+.segmented.is-sliding > .segment[aria-pressed="true"] { background: none; box-shadow: none; }+.segmented.is-sliding::before {+ content: "";+ position: absolute;+ z-index: 0;+ top: var(--thumb-y);+ left: 0;+ width: var(--thumb-w);+ height: var(--thumb-h);+ translate: var(--thumb-x) 0;+ border-radius: var(--r-pill);+ background: var(--sheet);+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14), 0 0 0 var(--hairline) var(--glass-edge);+ pointer-events: none;+}+.toolbar-group.segmented.is-sliding::before { background: var(--fill-selected); box-shadow: none; }/* The switch, as macOS draws it: a capsule in the accent when on, the knob sliding on thesnappy spring (a small thing moving a short way, its own layer only). */diff --git a/src/styles/notes.css b/src/styles/notes.cssindex 5b6c7e6..e39281a 100644--- a/src/styles/notes.css+++ b/src/styles/notes.css@@ -328,7 +328,8 @@ textarea.note-title::placeholder { color: var(--text-3); }/* ---- Aa ----------------------------------------------------------------------------As icloud.com and the Mac draw it: the four marks in a row, the styles beneath, each set- the way it sets a line, the current one ticked. Opens without animation, as menus do. */+ the way it sets a line, the current one ticked. A popover: it grows out of the Aa that+ opened it, drawn by the page (lib/fade.ts grow), never a CSS animation. */.format-panel {position: fixed;z-index: 60;diff --git a/src/styles/photos.css b/src/styles/photos.cssindex bacab59..e0f8615 100644--- a/src/styles/photos.css+++ b/src/styles/photos.css@@ -877,7 +877,7 @@box-shadow: var(--glass-float);overflow: hidden;outline: none;- /* Fades in frame by frame from the page (fadeIn), never a CSS animation: animated by the+ /* Grows in frame by frame from the page (grow), never a CSS animation: animated by theengine's compositor it glitched on his screen as it opened. */}.px-jump-years { display: flex; flex-direction: column; gap: 2px; padding: 10px 8px; border-right: var(--hairline) solid var(--separator); overflow-y: auto; }diff --git a/src/styles/tokens.css b/src/styles/tokens.cssindex a973b84..b2253ac 100644--- a/src/styles/tokens.css+++ b/src/styles/tokens.css@@ -185,6 +185,13 @@/* A small thing turning or sliding in answer to a click — a disclosure chevron, a switch'sknob, a progress fill: one timing for all of them. */--motion-small: 140ms;+ /* Drawn by the page frame by frame, never handed to the compositor (lib/fade.ts says why):+ a popover growing out of what opened it — from 96%, fading in (lib/fade.ts grow) — and a+ segmented control's thumb sliding to the segment chosen (lib/thumb.ts). Menus have+ neither: a Mac's menu is simply there. */+ --motion-pop: 140ms;+ --pop-from: 0.96;+ --motion-thumb: 160ms;/* Arrival: what came in from another device (lib/fade.ts arrive / leave, kit.css.receiving-line). Small elements only, opacity and transform only, no highlight — the@@ -392,7 +399,7 @@ body {@media (prefers-reduced-motion: reduce) {:root { --motion-hover: 0ms; --motion-fade: 0ms; --motion-small: 0ms; --press-out: 0ms;- --arrive-in-d: 0ms; --leave-d: 0ms; }+ --arrive-in-d: 0ms; --leave-d: 0ms; --motion-pop: 0ms; --motion-thumb: 0ms; }*, *::before, *::after {animation-duration: 0.01ms !important;transition-duration: 0.01ms !important;