Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.
TypeScript ai-photo-editorcomfyui-alternativegenerative-fillimage-editingimage-generationinpaintinglinuxlocal-aimacosmcpmcp-servernano-banana-alternativeofflinephoto-editorprivacyqwen-imageqwen-image-2-1stable-diffusion-cppvulkanwindows
Touch screens: swipe between images in full screen and in All images
Gabriele Lozupone72d3a4570197
diff --git a/src/components/Gallery.tsx b/src/components/Gallery.tsxindex 9636816..3b2cbaf 100644--- a/src/components/Gallery.tsx+++ b/src/components/Gallery.tsx@@ -8,7 +8,7 @@ import { MODE_LABEL, neighbourAfterRemoval, previewIndex } from "../lib/logic";import type { GenerationRecord } from "../lib/types";import { DevelopImg } from "./Develop";import { IconButton, Seg } from "./ui";-import { Fullscreen, isTyping, NavArrows, navKey, useMouseActive, ZoomImage, type ViewerNav } from "./Viewer";+import { Fullscreen, isTyping, NavArrows, navKey, SwipeNav, useMouseActive, ZoomImage, type ViewerNav } from "./Viewer";const PAGE = 60;/** Most images the server returns in one request. */@@ -344,9 +344,12 @@ function Preview(props: {<span className="muted preview-pos">{nav.pos}</span></div><div className="preview-stage" onPointerMove={wake} onMouseEnter={wake}>- <div key={g.id} className="preview-img" onDoubleClick={() => setFull(true)}>- <DevelopImg src={urls.gen(g.id)} placeholder={urls.genThumb(g.id)} alt={g.prompt} />- </div>+ <SwipeNav nav={nav} pageKey={g.id}>+ <div className="preview-img" onDoubleClick={() => setFull(true)}>+ {/* A phone shows the screen-sized preview here (full screen loads more when zoomed). */}+ <DevelopImg src={inBrowser && isNarrow() ? urls.genPreview(g.id) : urls.gen(g.id)} placeholder={urls.genThumb(g.id)} alt={g.prompt} />+ </div>+ </SwipeNav><NavArrows nav={nav} visible={active} /></div><div className="preview-bar">diff --git a/src/components/Viewer.tsx b/src/components/Viewer.tsxindex 2a7b235..fb3af93 100644--- a/src/components/Viewer.tsx+++ b/src/components/Viewer.tsx@@ -5,6 +5,7 @@ import { ChevronLeft, ChevronRight, Maximize2, X } from "lucide-react";import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";import { createPortal } from "react-dom";import { urls } from "../lib/api";+import { haptic } from "../lib/haptics";import { native } from "../lib/native";import { inBrowser } from "../lib/platform";import { ZoomPan } from "./ZoomPan";@@ -103,6 +104,76 @@ export function NavArrows({ nav, visible }: { nav: ViewerNav; visible: boolean });}+/** A horizontal swipe steps through `nav` on a touch screen: the picture follows the finger+ * (only a little past the ends) and the next one slides in from that side, as the phone's+ * versions do. Not while zoomed in, nor on a control or the comparison slider; a second+ * finger (pinch) cancels it. `pageKey` names what is shown. */+export function SwipeNav({ nav, pageKey, className = "", children }: { nav: ViewerNav; pageKey: string; className?: string; children: ReactNode }) {+ const ref = useRef<HTMLDivElement>(null);+ const touch = useRef<{ x: number; y: number; t: number; dx: number; axis: "x" | "y" | null } | null>(null);+ // The side the page just swiped to slides in from.+ const [enter, setEnter] = useState<"left" | "right" | null>(null);+ const place = (dx: number, animate: boolean) => {+ const el = ref.current;+ if (!el) return;+ el.style.transition = animate ? "transform 0.38s var(--ease), opacity 0.38s var(--ease)" : "none";+ el.style.transform = dx ? `translateX(${dx}px)` : "";+ el.style.opacity = dx ? String(1 - Math.min(0.5, Math.abs(dx) / 600)) : "";+ };+ const cancel = () => {+ if (touch.current?.axis === "x") place(0, true);+ touch.current = null;+ };+ return (+ <div+ className={`swipe-nav ${className}`}+ onTouchStart={(e) => {+ const t = e.target as HTMLElement;+ if (e.touches.length !== 1 || t.closest("button, .zoomed, .compare-box.slider, .zoom-controls, .zoom-minimap, .viewer-compare-bar")) return cancel();+ touch.current = { x: e.touches[0].clientX, y: e.touches[0].clientY, t: performance.now(), dx: 0, axis: null };+ }}+ onTouchMove={(e) => {+ const s = touch.current;+ if (!s) return;+ if (e.touches.length !== 1) return cancel();+ const dx = e.touches[0].clientX - s.x;+ const dy = e.touches[0].clientY - s.y;+ if (!s.axis && Math.hypot(dx, dy) > 8) s.axis = Math.abs(dx) > Math.abs(dy) ? "x" : "y";+ if (s.axis !== "x") return;+ s.dx = dx;+ const end = (dx > 0 && !nav.prev) || (dx < 0 && !nav.next);+ place(end ? dx * 0.22 : dx, false);+ }}+ onTouchEnd={() => {+ const s = touch.current;+ touch.current = null;+ if (!s || s.axis !== "x") return;+ const fast = Math.abs(s.dx) / Math.max(1, performance.now() - s.t) > 0.45;+ const go = Math.abs(s.dx) > 64 || fast ? (s.dx < 0 ? nav.next : nav.prev) : undefined;+ if (!go) return place(0, true);+ haptic();+ const el = ref.current;+ if (el) {+ el.style.transition = "transform 0.16s ease-in, opacity 0.16s ease-in";+ el.style.transform = `translateX(${s.dx < 0 ? -90 : 90}px)`;+ el.style.opacity = "0";+ }+ const from = s.dx < 0 ? "right" : "left";+ window.setTimeout(() => {+ go();+ setEnter(from);+ place(0, false);+ }, 140);+ }}+ onTouchCancel={cancel}+ >+ <div ref={ref} key={pageKey} className={`swipe-nav-page ${enter ? `enter-${enter}` : ""}`} onAnimationEnd={(e) => e.target === e.currentTarget && setEnter(null)}>+ {children}+ </div>+ </div>+ );+}+/** ←/↑ and →/↓ call `nav`; returns true when the key was used. */export function navKey(e: KeyboardEvent, nav: ViewerNav | undefined): boolean {if (!nav || e.ctrlKey || e.metaKey || e.altKey) return false;@@ -168,7 +239,13 @@ function FullscreenShell({ children, hint, onClose, nav }: { children: ReactNodeonDoubleClick={stop}onContextMenu={stop}>- {children}+ {nav ? (+ <SwipeNav nav={nav} pageKey={nav.pos ?? ""}>+ {children}+ </SwipeNav>+ ) : (+ children+ )}{nav && <NavArrows nav={nav} visible={active} />}<div className="viewer-bar">{nav?.pos && <span className="viewer-tag">{nav.pos}</span>}diff --git a/src/phone.css b/src/phone.cssindex e6fb9c6..c5e42b2 100644--- a/src/phone.css+++ b/src/phone.css@@ -378,5 +378,5 @@ html.keyboard .composer-wrap.phone { padding-bottom: 8px; }}@media (prefers-reduced-motion: reduce) {- .phone-screen.project, .phone-screen.library, .swipe-page.enter-right, .swipe-page.enter-left, .lib-card, .phone-empty, .popover.sheet { animation: none; }+ .phone-screen.project, .phone-screen.library, .swipe-page.enter-right, .swipe-page.enter-left, .swipe-nav-page, .lib-card, .phone-empty, .popover.sheet { animation: none; }}diff --git a/src/styles.css b/src/styles.cssindex 6f25e04..e116e5f 100644--- a/src/styles.css+++ b/src/styles.css@@ -674,6 +674,11 @@ pre.diag { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font.zoom-minimap-viewport { position: absolute; border: 1.5px solid #fff; border-radius: 3px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4); pointer-events: none; }/* comparison full screen: the frame leaves room for the view switch at the bottom */.viewer-frame { position: absolute; inset: 60px 12px 64px; display: flex; align-items: center; justify-content: center; }+/* Viewer.tsx SwipeNav: fills its place, the page in it too (children keep their own positions) */+.swipe-nav, .swipe-nav-page { position: absolute; inset: 0; }+.swipe-nav { touch-action: pan-y; }+.swipe-nav-page.enter-right { animation: page-right 0.46s var(--ease) both; }+.swipe-nav-page.enter-left { animation: page-left 0.46s var(--ease) both; }.viewer-compare-bar { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; justify-content: center; }.viewer-compare-bar .compare-bar { margin: 0; padding: 4px; border-radius: 12px; background: rgba(20, 20, 20, 0.85); }/* full screen is viewed from further away: larger view switch and zoom bar */@@ -693,6 +698,9 @@ pre.diag { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font.nav-arrow.right { right: 14px; }.nav-arrow:hover { background: rgba(0, 0, 0, 0.72); }.nav-arrow.hidden { opacity: 0; }+/* A touch screen swipes instead (Viewer.tsx SwipeNav): the hidden arrows would only catch the+ swipes that start near an edge. */+@media (hover: none) and (pointer: coarse) { .nav-arrow { display: none; } }.nav-arrow:focus-visible { opacity: 1; }/* gallery preview: one image over the grid */