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
Arrival motion for live sync: arrive, leave, and the receiving line
Yashwanth Kamireddi698bf5d391e6
diff --git a/.uiverify/design-arrival.mjs b/.uiverify/design-arrival.mjsnew file mode 100644index 0000000..92ffbe6--- /dev/null+++ b/.uiverify/design-arrival.mjs@@ -0,0 +1,157 @@+// The arrival motion set (lib/fade.ts arrive / leave, kit.css .receiving-line), which live sync+// uses when something comes in from another device:+// - arrive: a fade of 120ms or less, rising at most 4px, opacity and transform only — no+// highlight, and nothing beside the row moves+// - leave: out by opacity, then `done`; the row keeps its height until it is removed+// - Reduce Motion: both instant+// - the receiving line: one calm line in the secondary text, figures that do not jitter+// Needs the dev server (the helpers are imported from source):+// npx vite --port 4211 & DEV=http://localhost:4211 node .uiverify/design-arrival.mjs+import { engine } from "./engine.mjs";+import { SERVICES, installStub } from "./stub.mjs";++const DEV = process.env.DEV ?? "http://localhost:5173";+let failures = 0;+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };+const b = await engine.launch();++async function open(reducedMotion) {+ const ctx = await b.newContext({ viewport: { width: 1000, height: 700 }, reducedMotion });+ await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null });+ const page = await ctx.newPage();+ await page.goto(DEV, { waitUntil: "networkidle" });+ // Three rows in a plain list, the middle one the one that arrives or leaves.+ await page.evaluate(() => {+ const ul = document.createElement("ul");+ ul.id = "arrival-list";+ ul.style.cssText = "position:fixed;top:100px;left:100px;width:300px;margin:0;padding:0;list-style:none;z-index:999";+ for (const name of ["one", "two", "three"]) {+ const li = document.createElement("li");+ li.id = `row-${name}`;+ li.textContent = name;+ li.style.cssText = "height:30px;padding:4px 8px";+ ul.appendChild(li);+ }+ document.body.appendChild(ul);+ });+ return page;+}++// ---- arrive ----------------------------------------------------------------------------------+{+ const page = await open("no-preference");+ const seen = await page.evaluate(async () => {+ const { arrive } = await import("/src/lib/fade.ts");+ const row = document.getElementById("row-two");+ const below = document.getElementById("row-three");+ const belowTop = below.getBoundingClientRect().top;+ const frames = [];+ const start = performance.now();+ arrive(row);+ const first = { opacity: row.style.opacity, transform: row.style.transform };+ await new Promise((done) => {+ const look = () => {+ frames.push({+ t: performance.now() - start,+ opacity: row.style.opacity,+ transform: row.style.transform,+ belowTop: below.getBoundingClientRect().top,+ bg: getComputedStyle(row).backgroundColor,+ shadow: getComputedStyle(row).boxShadow,+ });+ if (performance.now() - start < 400) requestAnimationFrame(look);+ else done();+ };+ requestAnimationFrame(look);+ });+ return { first, frames, belowTop };+ });+ const moving = seen.frames.filter((f) => f.opacity !== "");+ const lastMoving = moving.at(-1);+ const rises = seen.frames.map((f) => Math.abs(parseFloat(/translateY\((-?[\d.]+)px\)/.exec(f.transform)?.[1] ?? "0")));+ ok(seen.first.opacity === "0", `arrive starts the row unseen, before its first frame [${JSON.stringify(seen.first)}]`);+ ok(moving.length > 0 && lastMoving.t <= 120 + 34, `it fades in within 120ms [last changing frame at ${Math.round(lastMoving?.t ?? -1)}ms]`);+ ok(Math.max(...rises, parseFloat(/-?[\d.]+/.exec(seen.first.transform)?.[0] ?? "0")) <= 4, `it rises 4px at most [${Math.max(...rises)}px]`);+ ok(seen.frames.at(-1).opacity === "" && seen.frames.at(-1).transform === "", "and leaves no style of its own behind");+ ok(seen.frames.every((f) => f.belowTop === seen.belowTop), "the row below never moves");+ ok(seen.frames.every((f) => f.bg === "rgba(0, 0, 0, 0)" && f.shadow === "none"), "nothing is highlighted: no wash, no tint");+ await page.context().close();+}++// ---- leave -----------------------------------------------------------------------------------+{+ const page = await open("no-preference");+ const seen = await page.evaluate(async () => {+ const { leave } = await import("/src/lib/fade.ts");+ const row = document.getElementById("row-two");+ const below = document.getElementById("row-three");+ const belowTop = below.getBoundingClientRect().top;+ const height = row.getBoundingClientRect().height;+ const start = performance.now();+ const tops = [];+ const heights = [];+ let doneAt = null;+ leave(row, () => { doneAt = performance.now() - start; row.remove(); });+ const sync = doneAt;+ await new Promise((done) => {+ const look = () => {+ if (row.isConnected) { tops.push(below.getBoundingClientRect().top); heights.push(Math.round(row.getBoundingClientRect().height * 100) / 100); }+ if (performance.now() - start < 500) requestAnimationFrame(look);+ else done();+ };+ requestAnimationFrame(look);+ });+ return { sync, doneAt, belowTop, tops, heights, height, opacityAtEnd: row.style.opacity };+ });+ ok(seen.sync === null, "leave lets the row go over a few frames, not at once");+ ok(seen.doneAt !== null && seen.doneAt <= 160 + 50, `then hands it over to be removed, within the small-motion limit [${Math.round(seen.doneAt ?? -1)}ms]`);+ ok(seen.tops.every((t) => t === seen.belowTop) && seen.heights.every((h) => h === seen.height), `its height never changes while it fades — no layout is animated [${seen.belowTop}: ${seen.tops.join(",")}; ${seen.height}: ${seen.heights.join(",")}]`);+ await page.context().close();+}++// ---- Reduce Motion: instant ------------------------------------------------------------------+{+ const page = await open("reduce");+ const seen = await page.evaluate(async () => {+ const { arrive, leave } = await import("/src/lib/fade.ts");+ const row = document.getElementById("row-two");+ arrive(row);+ const after = { opacity: row.style.opacity, transform: row.style.transform };+ let done = false;+ leave(document.getElementById("row-three"), () => { done = true; });+ return { after, done };+ });+ ok(seen.after.opacity === "" && seen.after.transform === "", `under Reduce Motion a new row is simply there ${JSON.stringify(seen.after)}`);+ ok(seen.done, "and a deleted one goes at once");+ await page.context().close();+}++// ---- the receiving line ----------------------------------------------------------------------+{+ const page = await open("no-preference");+ // The markup ReceivingLine draws (components/ReceivingLine), with the kit's styles.+ const look = await page.evaluate(() => {+ const p = document.createElement("p");+ p.className = "receiving-line";+ p.setAttribute("role", "status");+ p.innerHTML = '<span class="receiving-line-text">Receiving 48 photos</span><span class="progress" role="progressbar"><span style="transform:scaleX(0.25)"></span></span>';+ document.body.appendChild(p);+ const cs = getComputedStyle(p);+ const probe = document.createElement("span");+ probe.style.color = "var(--text-2)";+ document.body.appendChild(probe);+ const text2 = getComputedStyle(probe).color;+ const bar = p.querySelector(".progress").getBoundingClientRect().height;+ const w1 = p.getBoundingClientRect().width;+ p.querySelector(".receiving-line-text").textContent = "Receiving 11 photos";+ const w2 = p.getBoundingClientRect().width;+ return { colour: cs.color, text2, numeric: cs.fontVariantNumeric, bar, w1, w2, size: cs.fontSize };+ });+ ok(look.colour === look.text2, `the receiving line is quiet, in the secondary text [${look.colour}]`);+ ok(look.numeric.includes("tabular-nums") && look.w1 === look.w2, `its count changes without the line changing width [${look.w1} → ${look.w2}]`);+ ok(look.bar === 2, `its bar is a thin 2px line [${look.bar}]`);+ await page.context().close();+}++await b.close();+process.exitCode = failures ? 1 : 0;diff --git a/src/components/ReceivingLine.tsx b/src/components/ReceivingLine.tsxnew file mode 100644index 0000000..d9ccfa7--- /dev/null+++ b/src/components/ReceivingLine.tsx@@ -0,0 +1,20 @@+import { Progress, Spinner } from "./Spinner";++/**+ * Many things arriving from iCloud at once — "Receiving 48 photos" — said in place, calmly: the+ * words, and under them how far along once that is known (a thin bar), or a small spinner beside+ * them until it is. One line that keeps its place while the count changes (figures are tabular),+ * announced politely, never a sheet or a toast. The styles are kit.css's `.receiving-line`.+ */+export function ReceivingLine({ label, done, total }: { label: string; done?: number; total?: number }) {+ const known = typeof done === "number" && typeof total === "number" && total > 0;+ return (+ <p className="receiving-line" role="status" aria-live="polite">+ <span className="receiving-line-text">+ {!known && <Spinner small />}+ {label}+ </span>+ {known && <Progress value={done / total} label={label} />}+ </p>+ );+}diff --git a/src/lib/fade.ts b/src/lib/fade.tsindex 9c5b7ed..0f3cf24 100644--- a/src/lib/fade.ts+++ b/src/lib/fade.ts@@ -88,30 +88,87 @@ export function fadeSheetsIn() {}).observe(document.body, { childList: true });}+/* ---- 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 —+ * drawn by the page frame by frame (as above), on opacity and a 2px transform only, so nothing+ * is laid out and no row beside it moves; only ever on a small thing, a row or a tile, never a+ * pane or a list. Under Reduce Motion each is instant. Timings are tokens (tokens.css "Arrival").+ *+ * arrive(row) a new row: fades in over 120ms, rising 2px+ * leave(row, remove) a row deleted elsewhere: out by opacity over 140ms, lifting 2px, then+ * `remove` takes it away (the rows below close up at once)+ * <ReceivingLine> the calm line while many things arrive at once (components/ReceivingLine)+ */++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 Reduce+ Motion — or `fallback`. */+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;+ return v.endsWith("ms") ? n : v.endsWith("s") ? n * 1000 : n;+}++/** A new row arriving: a quick fade in, rising 2px. No highlight — it simply settles in. */+export function arrive(el: HTMLElement | null) {+ if (!el) return;+ const duration = token("--arrive-in-d", 120);+ if (reduced() || duration <= 0) return;+ const rise = token("--arrive-rise", 2);+ cancelAnimationFrame(running.get(el) ?? 0);+ const start = performance.now();+ el.style.opacity = "0";+ el.style.transform = `translateY(${rise}px)`;+ const finish = () => {+ el.style.opacity = "";+ el.style.transform = "";+ running.delete(el);+ };+ const step = (now: number) => {+ const t = Math.max(0, Math.min(1, (now - start) / duration));+ if (t >= 1) return finish();+ const k = 1 - (1 - t) * (1 - t);+ el.style.opacity = String(k);+ el.style.transform = `translateY(${(rise * (1 - k)).toFixed(2)}px)`;+ running.set(el, requestAnimationFrame(step));+ };+ running.set(el, requestAnimationFrame(step));+ window.setTimeout(() => { if (running.has(el)) { cancelAnimationFrame(running.get(el)!); finish(); } }, duration + 250);+}+/**- * A row folding away, drawn by the page the same way: each frame its height, padding and- * opacity set from here, so the rows below glide up. Then `done`.+ * A row deleted on another device leaving: out by opacity, lifting 2px, then `done` — which+ * removes it. Its height is never animated (a layout animation, and the flicker this file+ * exists to avoid); the rows below close up the moment it is gone.*/-export function foldAway(el: HTMLElement, done: () => void, duration = 240) {- if (typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {+export function leave(el: HTMLElement | null, done: () => void) {+ const duration = el ? token("--leave-d", 140) : 0;+ if (!el || reduced() || duration <= 0) {done();return;}- const cs = getComputedStyle(el);- const h = el.getBoundingClientRect().height;- const [pt, pb] = [parseFloat(cs.paddingTop), parseFloat(cs.paddingBottom)];- el.style.overflow = "hidden";+ cancelAnimationFrame(running.get(el) ?? 0);+ el.style.pointerEvents = "none";+ let finished = false;+ const finish = () => {+ if (finished) return;+ finished = true;+ running.delete(el);+ done();+ };+ window.setTimeout(finish, duration + 250);const start = performance.now();const step = (now: number) => {const t = Math.min(1, (now - start) / duration);- // Quick at first, settling: Apple's own curve for things leaving.- const k = 1 - (1 - t) ** 3;- el.style.height = `${h * (1 - k)}px`;- el.style.paddingTop = `${pt * (1 - k)}px`;- el.style.paddingBottom = `${pb * (1 - k)}px`;+ const k = t * t;el.style.opacity = String(1 - k);- if (t < 1) requestAnimationFrame(step);- else done();+ el.style.transform = `translateY(${(-2 * k).toFixed(2)}px)`;+ if (t >= 1) return finish();+ running.set(el, requestAnimationFrame(step));};- requestAnimationFrame(step);+ running.set(el, requestAnimationFrame(step));}diff --git a/src/styles/kit.css b/src/styles/kit.cssindex 3931a4c..e7a97b0 100644--- a/src/styles/kit.css+++ b/src/styles/kit.css@@ -593,3 +593,24 @@ span.switch::after { content: ""; }:where(svg.lucide[width="13"]) { width: 14px; height: 14px; }:where(svg.lucide[width="15"]) { width: 16px; height: 16px; }:where(svg.lucide[width="17"]) { width: 18px; height: 18px; }++/* ---- arrival: what came in from another device (lib/fade.ts arrive, leave) ---------------- */++/* A new row eases in by opacity, 2px up (arrive), a deleted one out (leave) — page-drawn, so+ there are no classes for them here; nothing is highlighted. */++/* Many things arriving at once ("Receiving 48 photos", components/ReceivingLine): one calm+ line in place, a small spinner or a thin bar under the words — never a sheet or a toast. */+.receiving-line {+ display: inline-flex;+ flex-direction: column;+ gap: 4px;+ min-width: 12ch;+ margin: 0;+ color: var(--text-2);+ font-size: var(--t-12);+ line-height: 1.35;+ font-variant-numeric: tabular-nums;+}+.receiving-line-text { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }+.receiving-line .progress { height: 2px; }