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
Photos: zoom into a photo; the next one slides in
Yashwanth Kamireddie1ba2692f834
diff --git a/.uiverify/photos.mjs b/.uiverify/photos.mjsindex c2472e5..521a1a2 100644--- a/.uiverify/photos.mjs+++ b/.uiverify/photos.mjs@@ -163,6 +163,45 @@ await page.locator(".px-source", { hasText: "Library" }).click();await page.waitForTimeout(250);ok((await page.locator(".px-tile").count()) === 5, "and it is back in the library");+// Zooming into a photo: double-click zooms to where was clicked, with the full picture+// laid over; Escape zooms back out before it closes; Ctrl+wheel zooms; the grid's own zoom+// keys are not taken while a photo is open; the next photo slides in.+await page.locator(".px-tile").nth(1).dblclick();+await page.waitForTimeout(600);+const scaleOf = () => page.locator(".px-pan").evaluate((el) => new DOMMatrix(getComputedStyle(el).transform).a);+await page.locator(".px-pan").dblclick({ position: { x: 40, y: 40 } });+await page.waitForTimeout(150);+ok((await scaleOf()) > 2, `double-click zooms in ×${(await scaleOf()).toFixed(2)}`);+ok(/full/.test((await page.locator(".px-sharp").getAttribute("src")) ?? ""), "and the full picture is laid over");+await page.keyboard.press("Escape");+await page.waitForTimeout(150);+ok((await scaleOf()) === 1 && (await page.locator(".px-viewer").count()) === 1, "Escape zooms back out first, and keeps the photo open");+const box = await page.locator(".px-pan").boundingBox();+await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);+await page.keyboard.down("Control");+await page.mouse.wheel(0, -120);+await page.keyboard.up("Control");+await page.waitForTimeout(150);+ok((await scaleOf()) > 1.5, `Ctrl + scroll zooms about the pointer ×${(await scaleOf()).toFixed(2)}`);+const gridAcross = await page.evaluate(() => getComputedStyle(document.querySelector(".px-scroll")).getPropertyValue("--across"));+await page.keyboard.press("Control+0");+await page.keyboard.press("Control+=");+await page.waitForTimeout(150);+ok((await scaleOf()) > 1.2 && (await page.evaluate(() => getComputedStyle(document.querySelector(".px-scroll")).getPropertyValue("--across"))) === gridAcross,+ "Ctrl = zooms the photo, not the grid behind it");+await page.keyboard.press("Control+0");+await page.keyboard.press("ArrowLeft");+await page.waitForTimeout(30);+ok((await page.locator(".px-pan").evaluate((el) => el.getAnimations().length)) > 0, "the photo before slides in");+await page.waitForTimeout(400);+await page.keyboard.press("ArrowRight");+await page.keyboard.press("ArrowRight");+await page.waitForTimeout(30);+ok((await page.locator(".px-video").evaluate((el) => el.getAnimations().length)) > 0, "a video slides in the same way");+await page.waitForTimeout(400);+await page.keyboard.press("Escape");+await page.waitForTimeout(650);+const across = async () => page.locator(".px-grid").first().evaluate((g) => getComputedStyle(g).gridTemplateColumns.split(" ").length);const before = await across();await page.getByRole("button", { name: "Zoom In" }).click();diff --git a/crates/quince-icloud/src/photos.rs b/crates/quince-icloud/src/photos.rsindex 86e75e0..a85f632 100644--- a/crates/quince-icloud/src/photos.rs+++ b/crates/quince-icloud/src/photos.rs@@ -50,6 +50,9 @@ pub struct Links {pub thumb: Option<String>,pub medium: Option<String>,pub original: Option<String>,+ /// The whole picture as a JPEG, for zooming in: Apple's full-size rendition, or the+ /// original itself when that is already a JPEG or PNG (a HEIC original shows nowhere here).+ pub full: Option<String>,/// A video's playable rendition, or a Live Photo's moving part.pub video: Option<String>,}@@ -71,6 +74,12 @@ pub fn links_of(master: &Value) -> Links {medium: link(f, "resJPEGMedRes", "med.jpg").or_else(|| link(f, "resJPEGFullRes", "full.jpg")),original: link(f, "resOriginalRes", "original"),+ full: link(f, "resJPEGFullRes", "full.jpg").or_else(|| {+ let kind = f.pointer("/itemType/value").and_then(Value::as_str);+ matches!(kind, Some("public.jpeg" | "public.png"))+ .then(|| link(f, "resOriginalRes", "original"))+ .flatten()+ }),video: link(f, "resVidMedRes", "video.mp4").or_else(|| link(f, "resVidSmallRes", "video.mp4")).or_else(|| link(f, "resOriginalVidComplRes", "live.mov")),diff --git a/probe/examples/photos_full_link.rs b/probe/examples/photos_full_link.rsnew file mode 100644index 0000000..f99faeb--- /dev/null+++ b/probe/examples/photos_full_link.rs@@ -0,0 +1,53 @@+//! Live, read-only: which renditions a photo's master offers, and that the "full" one Quince+//! picks for zooming downloads as a displayable image.+use anyhow::{anyhow, Result};+use quince_icloud::photos::{links_of, CONTAINER, ZONE};++#[tokio::main]+async fn main() -> Result<()> {+ let asset = std::env::args().nth(1).ok_or_else(|| anyhow!("asset id"))?;+ let dir = std::path::PathBuf::from(std::env::var("HOME")?).join(".local/share/quince-probe");+ let mut client = quince_auth::Client::new(&dir)?;+ if !client.resume().await? {+ return Err(anyhow!("no session"));+ }+ let ck = client+ .session()+ .service_url("ckdatabasews")+ .ok_or_else(|| anyhow!("no ck"))?;+ let (http, p) = (client.http().clone(), client.service_params());+ let zc = quince_icloud::cloudkit::ZoneClient::new(&http, &ck, CONTAINER, p);+ let a = zc+ .lookup_record(ZONE, &asset)+ .await?+ .ok_or_else(|| anyhow!("no asset"))?;+ let master = a+ .pointer("/fields/masterRef/value/recordName")+ .and_then(|v| v.as_str())+ .ok_or_else(|| anyhow!("no master"))?;+ let m = zc+ .lookup_record(ZONE, master)+ .await?+ .ok_or_else(|| anyhow!("no master record"))?;+ let mut keys: Vec<_> = m["fields"]+ .as_object()+ .unwrap()+ .keys()+ .filter(|k| k.starts_with("res") && k.ends_with("Res"))+ .cloned()+ .collect();+ keys.sort();+ println!(+ "itemType {:?}; renditions {keys:?}",+ m.pointer("/fields/itemType/value")+ );+ let l = links_of(&m);+ let full = l.full.ok_or_else(|| anyhow!("no full link"))?;+ let bytes = http.get(&full).send().await?.bytes().await?;+ println!(+ "full: {} bytes, starts {:02x?}",+ bytes.len(),+ &bytes[..4.min(bytes.len())]+ );+ Ok(())+}diff --git a/src-tauri/src/photos.rs b/src-tauri/src/photos.rsindex d3b16a3..1bc382a 100644--- a/src-tauri/src/photos.rs+++ b/src-tauri/src/photos.rs@@ -48,6 +48,8 @@ pub enum Size {Thumb,Medium,Original,+ /// The whole picture, displayable: for a photo zoomed in.+ Full,Video,}@@ -57,6 +59,7 @@ impl Size {Size::Thumb => "thumb",Size::Medium => "medium",Size::Original => "original",+ Size::Full => "full",Size::Video => "video",}}@@ -65,6 +68,7 @@ impl Size {Size::Thumb => l.thumb.clone(),Size::Medium => l.medium.clone().or_else(|| l.thumb.clone()),Size::Original => l.original.clone(),+ Size::Full => l.full.clone().or_else(|| l.medium.clone()),Size::Video => l.video.clone(),}}@@ -80,6 +84,7 @@ pub fn requested(path: &str) -> Option<(String, Size)> {"thumb" => Size::Thumb,"medium" => Size::Medium,"original" => Size::Original,+ "full" => Size::Full,"video" => Size::Video,_ => return None,};diff --git a/src/lib/ipc.ts b/src/lib/ipc.tsindex d7351a3..e62d847 100644--- a/src/lib/ipc.ts+++ b/src/lib/ipc.ts@@ -553,7 +553,7 @@ export function noteMediaSrc(id: string, part: "file" | "preview"): string {}/** One of a photo's pictures, served from the disk cache (fetched from Apple once). */-export function pictureSrc(id: string, size: "thumb" | "medium" | "original" | "video"): string {+export function pictureSrc(id: string, size: "thumb" | "medium" | "full" | "original" | "video"): string {return convertFileSrc(`pic/${id}/${size}`, "quince");}diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsxindex b398479..23df53f 100644--- a/src/screens/PhotosView.tsx+++ b/src/screens/PhotosView.tsx@@ -231,11 +231,85 @@ export function PhotosView() {// A finish that never comes (a hidden window stops the clock) must not leave it open.closingRun.current = { anims, timer: window.setTimeout(done, 600) };}, [open, photos]);+ // Which way the last step went, so the next photo slides in from that side.+ const stepped = useRef(0);const step = useCallback(- (by: number) => setOpen((at) => (at === null || !photos ? at : Math.max(0, Math.min(photos.length - 1, at + by)))),+ (by: number) =>+ setOpen((at) => {+ if (at === null || !photos) return at;+ const to = Math.max(0, Math.min(photos.length - 1, at + by));+ if (to !== at) stepped.current = by;+ return to;+ }),[photos],);+ /*+ * Zooming into a photo, as Photos does: double-click zooms to where was clicked and back;+ * Ctrl + scroll (a trackpad pinch arrives as that) zooms about the pointer; dragging pans.+ * One transform on the photo's frame, so it is the compositor's work. Past the fit, the+ * full picture is laid over the screen-sized one once it has loaded.+ */+ const [lens, setLens] = useState({ k: 1, x: 0, y: 0 });+ const lensRef = useRef(lens);+ lensRef.current = lens;+ const pan = useRef<HTMLDivElement | null>(null);+ const [sharp, setSharp] = useState<string | null>(null);+ const unzoom = () => setLens({ k: 1, x: 0, y: 0 });+ // Kept so the image's edge never comes in past the middle of the stage.+ const bound = (k: number, x: number, y: number) => {+ const el = pan.current;+ if (!el || k <= 1) return { k: 1, x: 0, y: 0 };+ const mx = ((k - 1) * el.offsetWidth) / 2;+ const my = ((k - 1) * el.offsetHeight) / 2;+ return { k, x: Math.max(-mx, Math.min(mx, x)), y: Math.max(-my, Math.min(my, y)) };+ };+ // Zoom to k, keeping the point under (sx, sy) — screen coordinates — where it is.+ const zoomAt = (k: number, sx: number, sy: number) => {+ const el = pan.current;+ if (!el) return;+ const box = el.getBoundingClientRect();+ const was = lensRef.current;+ const cx = box.left + box.width / 2 - was.x;+ const cy = box.top + box.height / 2 - was.y;+ const [dx, dy] = [sx - cx, sy - cy];+ const px = (dx - was.x) / was.k;+ const py = (dy - was.y) / was.k;+ const next = Math.max(1, Math.min(5, k));+ setLens(bound(next, dx - next * px, dy - next * py));+ };+ useEffect(() => {+ unzoom();+ setSharp(null);+ }, [shown?.id]);+ useEffect(() => {+ if (lens.k > 1.15 && shown && shown.kind !== "video") setSharp(shown.id);+ }, [lens.k > 1.15, shown?.id]); // eslint-disable-line react-hooks/exhaustive-deps+ // A pinch or Ctrl + wheel: the page must not zoom too, so this listener is not passive.+ useEffect(() => {+ const el = stage.current;+ if (!el) return undefined;+ const wheel = (e: WheelEvent) => {+ if (!e.ctrlKey && !e.metaKey) return;+ e.preventDefault();+ zoomAt(lensRef.current.k * Math.exp(-e.deltaY * 0.01), e.clientX, e.clientY);+ };+ el.addEventListener("wheel", wheel, { passive: false });+ return () => el.removeEventListener("wheel", wheel);+ });+ const dragging = useRef<{ x: number; y: number; lx: number; ly: number } | null>(null);+ // The next photo slides in from the side the step went to.+ useLayoutEffect(() => {+ const by = stepped.current;+ stepped.current = 0;+ const el = stage.current?.querySelector<HTMLElement>(".px-pan, .px-video");+ if (!by || !el || still() || typeof el.animate !== "function") return;+ el.animate(+ [{ transform: `translateX(${by * 56}px)`, opacity: 0.2 }, { transform: "none", opacity: 1 }],+ { duration: 300, easing: spring() },+ );+ }, [shown?.id]); // eslint-disable-line react-hooks/exhaustive-deps+// The viewer's keys: arrows to go through, Escape to close, I for the details.useEffect(() => {if (open === null) return undefined;@@ -243,7 +317,14 @@ export function PhotosView() {const onKey = (e: KeyboardEvent) => {if (e.key === "ArrowRight") step(1);else if (e.key === "ArrowLeft") step(-1);+ else if (e.key === "Escape" && lensRef.current.k > 1) unzoom();else if (e.key === "Escape") close();+ else if ((e.ctrlKey || e.metaKey) && (e.key === "=" || e.key === "+" || e.key === "-" || e.key === "0") && current?.kind !== "video") {+ const box = pan.current?.getBoundingClientRect();+ if (!box) return;+ const k = e.key === "0" ? 1 : lensRef.current.k * (e.key === "-" ? 1 / 1.5 : 1.5);+ zoomAt(k, box.left + box.width / 2, box.top + box.height / 2);+ }else if (e.key === " " && current?.kind === "video") void play(current);else if (e.key.toLowerCase() === "i" && !e.metaKey && !e.ctrlKey) setInfo((v) => !v);// As in Photos: "." favorites, Delete sends it to Recently Deleted.@@ -740,7 +821,7 @@ export function PhotosView() {// Zoom from the keys as in Photos: Ctrl and + or −.useEffect(() => {const onKey = (e: KeyboardEvent) => {- if (!(e.ctrlKey || e.metaKey) || e.altKey) return;+ if (!(e.ctrlKey || e.metaKey) || e.altKey || viewer.current) return;if (e.key === "=" || e.key === "+") setZoom((z) => Math.min(ACROSS.length - 1, z + 1));else if (e.key === "-") setZoom((z) => Math.max(0, z - 1));else return;@@ -984,7 +1065,38 @@ export function PhotosView() {</span></button>) : (- <img key={shown.id} className="px-shown" src={pictureSrc(shown.id, "medium")} alt={shown.filename ?? ""} decoding="async" style={fitted(shown)} />+ <div+ ref={pan}+ className={`px-pan${lens.k > 1 ? " is-zoomed" : ""}`}+ style={{ transform: lens.k > 1 ? `translate(${lens.x}px, ${lens.y}px) scale(${lens.k})` : undefined }}+ onDoubleClick={(e) => (lens.k > 1 ? unzoom() : zoomAt(2.5, e.clientX, e.clientY))}+ onPointerDown={(e) => {+ if (lensRef.current.k <= 1 || e.button !== 0) return;+ e.currentTarget.setPointerCapture(e.pointerId);+ dragging.current = { x: e.clientX, y: e.clientY, lx: lensRef.current.x, ly: lensRef.current.y };+ }}+ onPointerMove={(e) => {+ const d = dragging.current;+ if (!d) return;+ setLens(bound(lensRef.current.k, d.lx + e.clientX - d.x, d.ly + e.clientY - d.y));+ }}+ onPointerUp={() => (dragging.current = null)}+ onPointerCancel={() => (dragging.current = null)}+ >+ <img key={shown.id} className="px-shown" src={pictureSrc(shown.id, "medium")} alt={shown.filename ?? ""} decoding="async" draggable={false} style={fitted(shown)} />+ {sharp === shown.id && (+ <img+ key={`${shown.id}-full`}+ className="px-sharp"+ src={pictureSrc(shown.id, "full")}+ alt=""+ aria-hidden="true"+ decoding="async"+ draggable={false}+ onLoad={(e) => e.currentTarget.classList.add("is-in")}+ />+ )}+ </div>)}{open !== null && open > 0 && (<button className="px-nav is-prev" aria-label="Previous" onClick={() => step(-1)}>diff --git a/src/styles/photos.css b/src/styles/photos.cssindex 32aebd2..b130215 100644--- a/src/styles/photos.css+++ b/src/styles/photos.css@@ -267,6 +267,14 @@.px-cap[aria-pressed="true"] { background: color-mix(in srgb, var(--text) 12%, transparent); }.px-stage { position: relative; display: grid; place-items: center; min-height: 0; padding: 62px 64px 22px; }.px-stage img, .px-stage video { max-width: 100%; max-height: 100%; object-fit: contain; }+/* The photo's frame: what zooms and pans. The full picture lies over the screen-sized one,+ faded in once loaded, so zooming never shows a blank. */+.px-pan { position: relative; display: grid; transform-origin: center; will-change: transform; }+.px-pan.is-zoomed { cursor: grab; }+.px-pan.is-zoomed:active { cursor: grabbing; }+.px-pan > img { grid-area: 1 / 1; }+.px-sharp { width: 100%; height: 100%; max-width: none; max-height: none; opacity: 0; transition: opacity 180ms ease; pointer-events: none; }+.px-sharp.is-in { opacity: 1; }/* The thumbnail, already on disk, fills the photo's box until the sharper picture covers it. */.px-shown { background-size: 100% 100%; transform-origin: center; will-change: transform; }.px-nav {