Skip to content

The agent that grows with you

refactor(desktop): reuse useZoomPan for image lightbox; add pinch, pointercancel, tests

EvanProgrammingaefac127761b
diff --git a/apps/desktop/src/components/chat/zoomable-image.test.tsx b/apps/desktop/src/components/chat/zoomable-image.test.tsx
index 852b2285a1b..55556f78fc5 100644
--- a/apps/desktop/src/components/chat/zoomable-image.test.tsx
+++ b/apps/desktop/src/components/chat/zoomable-image.test.tsx
@@ -1,19 +1,220 @@
-import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
-import { afterEach, describe, expect, it } from 'vitest'
+import type { ReactNode } from 'react'
+
+import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
+import { afterEach, describe, expect, it, vi } from 'vitest'
import { I18nProvider } from '@/i18n/context'
import { resetTranscriptLightbox } from '@/store/transcript-lightbox'
import { ZoomableImage } from './zoomable-image'
-// A bounded thumbnail (what the composer/optimistic bubble paints inline) and
-// the full-resolution source (what the lightbox should enlarge). Issue #93204:
-// clicking a freshly sent image enlarged the 512px thumbnail instead of the
-// original.
-const THUMB = 'data:image/png;base64,dGh1bWJuYWls'
-const FULL = 'data:image/png;base64,ZnVsbHJlc29sdXRpb24='
+const SRC = 'https://example.com/long-detail.png'
+const ALT = 'long detail image'
+
+async function renderImage() {
+ let result!: ReturnType<typeof render>
+ await act(async () => {
+ result = render(
+ <I18nProvider configClient={{ getConfig: async () => ({}), saveConfig: async () => ({ ok: true }) }}>
+ <ZoomableImage alt={ALT} src={SRC} />
+ </I18nProvider>
+ )
+ })
+
+ return result
+}
+
+async function openLightbox() {
+ const trigger = screen.getByAltText(ALT).closest('button')
+ expect(trigger).toBeTruthy()
+ await act(async () => {
+ fireEvent.click(trigger!)
+ })
+}
+
+function lightboxImg(): HTMLImageElement {
+ const dialog = screen.getByRole('dialog')
+
+ return within(dialog).getByRole('img') as HTMLImageElement
+}
+
+function scaleOf(img: HTMLElement): number {
+ const match = img.style.transform.match(/scale\(([0-9.]+)\)/)
+
+ return match ? parseFloat(match[1]) : 1
+}
+
+function translateX(img: HTMLElement): number {
+ const match = img.style.transform.match(/translate\(([-0-9.]+)px/)
+
+ return match ? parseFloat(match[1]) : 0
+}
+
+function percentageText(): string {
+ const node = screen.getByText(/\d+%/)
+
+ return node.textContent ?? ''
+}
+
+describe('ZoomableImage lightbox', () => {
+ afterEach(() => {
+ cleanup()
+ resetTranscriptLightbox()
+ })
+
+ it('opens the lightbox when the inline image is activated', async () => {
+ await renderImage()
+ await openLightbox()
+
+ expect(screen.getByRole('dialog')).toBeTruthy()
+ expect(lightboxImg()).toBeTruthy()
+ })
+
+ it('wheel zooms toward the cursor and prevents the page from scrolling', async () => {
+ await renderImage()
+ await openLightbox()
+ const img = lightboxImg()
+
+ const wheel = new WheelEvent('wheel', { bubbles: true, cancelable: true, clientX: 10, clientY: 10, deltaY: -100 })
+ const preventDefault = vi.spyOn(wheel, 'preventDefault')
+
+ await act(async () => {
+ img.dispatchEvent(wheel)
+ })
+
+ expect(preventDefault).toHaveBeenCalled()
+ expect(scaleOf(img)).toBeGreaterThan(1)
+ })
+
+ it('zoom buttons update the zoom percentage', async () => {
+ await renderImage()
+ await openLightbox()
+
+ const zoomIn = screen.getByRole('button', { name: /zoom in/i })
+ const reset = screen.getByRole('button', { name: /reset/i })
+ const zoomOut = screen.getByRole('button', { name: /zoom out/i })
+
+ await act(async () => {
+ fireEvent.click(zoomIn)
+ })
+ expect(percentageText()).toBe('130%')
-async function renderWithI18n(ui: React.ReactNode) {
+ await act(async () => {
+ fireEvent.click(reset)
+ })
+ expect(percentageText()).toBe('100%')
+
+ await act(async () => {
+ fireEvent.click(zoomOut)
+ })
+ // 1 / 1.3 ≈ 0.769 → 77%
+ expect(percentageText()).toBe('77%')
+ })
+
+ it('pans after zoom but does not close the lightbox', async () => {
+ await renderImage()
+ await openLightbox()
+ const img = lightboxImg()
+
+ await act(async () => {
+ fireEvent.click(screen.getByRole('button', { name: /zoom in/i }))
+ })
+ expect(scaleOf(img)).toBeCloseTo(1.3, 5)
+
+ await act(async () => {
+ fireEvent.pointerDown(img, { clientX: 10, clientY: 10, pointerId: 1 })
+ })
+ await act(async () => {
+ fireEvent.pointerMove(img, { clientX: 60, clientY: 10, pointerId: 1 })
+ })
+ await act(async () => {
+ fireEvent.pointerUp(img, { clientX: 60, clientY: 10, pointerId: 1 })
+ })
+
+ expect(translateX(img)).not.toBe(0)
+ // A pan must NOT close the lightbox.
+ expect(screen.getByRole('dialog')).toBeTruthy()
+ })
+
+ it('closes the lightbox on a clean click (no pan/pinch)', async () => {
+ await renderImage()
+ await openLightbox()
+ const img = lightboxImg()
+
+ await act(async () => {
+ fireEvent.click(img)
+ })
+
+ expect(screen.queryByRole('dialog')).toBeNull()
+ })
+
+ it('pinch zooms with two pointers', async () => {
+ await renderImage()
+ await openLightbox()
+ const img = lightboxImg()
+
+ await act(async () => {
+ fireEvent.pointerDown(img, { clientX: 100, clientY: 100, pointerId: 1 })
+ })
+ await act(async () => {
+ fireEvent.pointerDown(img, { clientX: 200, clientY: 100, pointerId: 2 })
+ })
+ await act(async () => {
+ fireEvent.pointerMove(img, { clientX: 50, clientY: 100, pointerId: 1 })
+ })
+ await act(async () => {
+ fireEvent.pointerMove(img, { clientX: 250, clientY: 100, pointerId: 2 })
+ })
+
+ expect(scaleOf(img)).toBeGreaterThan(1)
+
+ await act(async () => {
+ fireEvent.pointerUp(img, { clientX: 50, clientY: 100, pointerId: 1 })
+ })
+ await act(async () => {
+ fireEvent.pointerUp(img, { clientX: 250, clientY: 100, pointerId: 2 })
+ })
+ })
+
+ it('recovers from pointercancel and treats the next single-pointer gesture as a pan, not a pinch', async () => {
+ await renderImage()
+ await openLightbox()
+ const img = lightboxImg()
+
+ // Zoom in so panning engages (pan only applies above scale 1).
+ await act(async () => {
+ fireEvent.click(screen.getByRole('button', { name: /zoom in/i }))
+ })
+ expect(scaleOf(img)).toBeCloseTo(1.3, 5)
+
+ // Start a gesture with pointer 1, then the browser cancels it (e.g. it
+ // steals the gesture for a scroll). Without cleanup the stale pointer
+ // lingers and the next pointerdown is misread as a pinch.
+ await act(async () => {
+ fireEvent.pointerDown(img, { clientX: 100, clientY: 100, pointerId: 1 })
+ })
+ await act(async () => {
+ fireEvent.pointerCancel(img, { clientX: 100, clientY: 100, pointerId: 1 })
+ })
+
+ // A fresh single pointer (id 2) should pan cleanly by 60px (100 → 160).
+ await act(async () => {
+ fireEvent.pointerDown(img, { clientX: 100, clientY: 100, pointerId: 2 })
+ })
+ await act(async () => {
+ fireEvent.pointerMove(img, { clientX: 160, clientY: 100, pointerId: 2 })
+ })
+ await act(async () => {
+ fireEvent.pointerUp(img, { clientX: 160, clientY: 100, pointerId: 2 })
+ })
+
+ // Scale is unchanged (no pinch zoom), and the image panned the expected 60px.
+ expect(scaleOf(img)).toBeCloseTo(1.3, 5)
+ expect(translateX(img)).toBeCloseTo(60, 5)
+ })
+})
+
+async function renderWithI18n(ui: ReactNode) {
let result: ReturnType<typeof render>
await act(async () => {
result = render(
@@ -26,6 +227,9 @@ async function renderWithI18n(ui: React.ReactNode) {
return result!
}
+const THUMB = 'data:image/png;base64,dGh1bWJuYWls'
+const FULL = 'data:image/png;base64,ZnVsbHJlc29sdXRpb24='
+
describe('ZoomableImage zoomSrc', () => {
afterEach(() => {
cleanup()
diff --git a/apps/desktop/src/components/chat/zoomable-image.tsx b/apps/desktop/src/components/chat/zoomable-image.tsx
index ca260298f69..35fc43eeba9 100644
--- a/apps/desktop/src/components/chat/zoomable-image.tsx
+++ b/apps/desktop/src/components/chat/zoomable-image.tsx
@@ -1,12 +1,13 @@
'use client'
import { useStore } from '@nanostores/react'
-import { type ComponentProps } from 'react'
+import { type ComponentProps, useEffect } from 'react'
+import { useZoomPan } from '@/components/ui/use-zoom-pan'
import { Dialog, DialogContent } from '@/components/ui/dialog'
import { useImageDownload } from '@/hooks/use-image-download'
import { useI18n } from '@/i18n'
-import { Download } from '@/lib/icons'
+import { Download, ZoomIn, ZoomOut } from '@/lib/icons'
import { cn } from '@/lib/utils'
import { $transcriptLightbox, closeTranscriptLightbox, openTranscriptLightbox } from '@/store/transcript-lightbox'
@@ -23,6 +24,9 @@ export interface ZoomableImageProps extends ComponentProps<'img'> {
export interface ImageActionCopy {
downloadImage: string
savingImage: string
+ zoomIn: string
+ zoomOut: string
+ resetZoom: string
}
export function ZoomableImage({
@@ -101,6 +105,30 @@ export function ImageLightbox({
saving: boolean
src: string
}) {
+ // Shared pan/zoom mechanics (wheel zoom, drag pan, pinch) come from
+ // useZoomPan — the same hook the diagram/artifact viewer uses, so there is a
+ // single source of truth for this gesture math. `moved` lets us close the
+ // lightbox on a clean click while leaving pans/pinches alone.
+ const { moved, panning, ref, reset, scale, stageProps, style, zoomIn, zoomOut } = useZoomPan<HTMLImageElement>({
+ enabled: open
+ })
+
+ // Reset zoom whenever the lightbox opens.
+ useEffect(() => {
+ if (open) {
+ reset()
+ }
+ }, [open, reset])
+
+ const onImageClick = () => {
+ // A pan/pinch gesture must not close the lightbox; only a clean click.
+ if (!moved) {
+ onOpenChange(false)
+ }
+ }
+
+ const cursor = scale > 1 ? (panning ? 'grabbing' : 'grab') : 'zoom-out'
+
return (
<Dialog onOpenChange={onOpenChange} open={open}>
<DialogContent
@@ -111,10 +139,16 @@ export function ImageLightbox({
>
<div className="group/lightbox relative inline-block">
<img
+ ref={ref}
alt={alt ?? ''}
- className="block max-h-[calc(100vh-12rem)] max-w-[calc(100vw-12rem)] cursor-zoom-out select-auto rounded-lg object-contain shadow-2xl"
- onClick={() => onOpenChange(false)}
+ className={cn(
+ 'block max-h-[calc(100vh-12rem)] max-w-[calc(100vw-12rem)] select-none rounded-lg object-contain shadow-2xl',
+ panning && 'cursor-grabbing'
+ )}
+ onClick={onImageClick}
src={src}
+ style={{ ...style, cursor, touchAction: 'none' }}
+ {...stageProps}
/>
<ImageActionButton
className="group-hover/lightbox:opacity-100"
@@ -124,6 +158,47 @@ export function ImageLightbox({
/>
</div>
</DialogContent>
+
+ {/* Zoom controls — fixed to the viewport so they stay put while the image
+ is panned/zoomed. stopPropagation keeps them from starting a pan or
+ closing the lightbox. Only mounted while the lightbox is open. */}
+ {open && (
+ <div
+ className="fixed bottom-4 left-1/2 z-50 flex -translate-x-1/2 items-center gap-1 rounded-full border border-border/70 bg-background/85 p-1 shadow-lg backdrop-blur"
+ onPointerDown={event => event.stopPropagation()}
+ onClick={event => event.stopPropagation()}
+ >
+ <button
+ aria-label={copy.zoomOut}
+ className="grid size-8 place-items-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50"
+ disabled={scale <= 0.25}
+ onClick={() => zoomOut()}
+ title={copy.zoomOut}
+ type="button"
+ >
+ <ZoomOut className="size-4" />
+ </button>
+ <button
+ aria-label={copy.resetZoom}
+ className="min-w-14 rounded-full px-2 text-center text-xs font-medium tabular-nums text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
+ onClick={() => reset()}
+ title={copy.resetZoom}
+ type="button"
+ >
+ {Math.round(scale * 100)}%
+ </button>
+ <button
+ aria-label={copy.zoomIn}
+ className="grid size-8 place-items-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50"
+ disabled={scale >= 8}
+ onClick={() => zoomIn()}
+ title={copy.zoomIn}
+ type="button"
+ >
+ <ZoomIn className="size-4" />
+ </button>
+ </div>
+ )}
</Dialog>
)
}
diff --git a/apps/desktop/src/components/ui/use-zoom-pan.ts b/apps/desktop/src/components/ui/use-zoom-pan.ts
index db95c5bc71e..980214460a2 100644
--- a/apps/desktop/src/components/ui/use-zoom-pan.ts
+++ b/apps/desktop/src/components/ui/use-zoom-pan.ts
@@ -1,8 +1,9 @@
import {
type CSSProperties,
type PointerEvent as ReactPointerEvent,
- type WheelEvent as ReactWheelEvent,
+ type RefObject,
useCallback,
+ useEffect,
useRef,
useState
} from 'react'
@@ -19,87 +20,241 @@ const MIN_SCALE = 0.25
const MAX_SCALE = 8
const WHEEL_STEP = 1.1
const BUTTON_STEP = 1.25
+// Pointer travel (px) below which a single-pointer gesture counts as a click
+// rather than a pan. Lets consumers (e.g. an image lightbox) close on a clean
+// click while still panning after a real drag.
+const DRAG_THRESHOLD = 4
-const clamp = (scale: number) => Math.min(MAX_SCALE, Math.max(MIN_SCALE, scale))
+interface UseZoomPanOptions {
+ enabled?: boolean
+ maxScale?: number
+ minScale?: number
+}
/**
- * Headless pan/zoom transform. Wheel zooms toward the cursor, drag pans, buttons
- * zoom toward centre. Returns the transform style plus the surface handlers, so
- * any content (SVG, image, canvas) can be made pan/zoomable.
+ * Headless pan/zoom transform shared by every zoomable surface (image lightbox,
+ * diagram/artifact viewer, …). Wheel zooms toward the cursor, drag pans,
+ * two-finger pinch zooms + pans, and the +/- buttons zoom toward centre.
+ *
+ * The wheel listener is attached natively (non-passive) so `preventDefault`
+ * actually stops the page/dialog from scrolling underneath, which a React
+ * `onWheel` (passive at the root) cannot do.
+ *
+ * `moved` reports whether the current gesture moved (pan/pinch) vs. a clean
+ * click, so callers can gate click-to-dismiss on it.
*/
-export function useZoomPan() {
+export function useZoomPan<T extends HTMLElement = HTMLElement>(options: UseZoomPanOptions = {}) {
+ const { enabled = true, minScale = MIN_SCALE, maxScale = MAX_SCALE } = options
+ const clamp = useCallback((scale: number) => Math.min(maxScale, Math.max(minScale, scale)), [minScale, maxScale])
+
+ const ref = useRef<T>(null)
const [transform, setTransform] = useState<Transform>({ scale: 1, x: 0, y: 0 })
- const drag = useRef<{ x: number; y: number } | null>(null)
const [panning, setPanning] = useState(false)
+ const [moved, setMoved] = useState(false)
+
+ // Track active pointers for drag (1) and pinch (2), plus the in-flight drag
+ // anchor and the pinch baseline.
+ const drag = useRef<{ x: number; y: number; startX: number; startY: number } | null>(null)
+ const pointers = useRef(new Map<number, { x: number; y: number }>())
+ const pinch = useRef<{ dist: number; midX: number; midY: number } | null>(null)
// Zoom toward (cx, cy), measured from the surface centre, keeping that point fixed.
- const zoomAt = useCallback((factor: number, cx = 0, cy = 0) => {
- setTransform(prev => {
- const scale = clamp(prev.scale * factor)
- const k = scale / prev.scale
+ const zoomAt = useCallback(
+ (factor: number, cx = 0, cy = 0) => {
+ setTransform(prev => {
+ const scale = clamp(prev.scale * factor)
+ const k = scale / prev.scale
- return { scale, x: cx - k * (cx - prev.x), y: cy - k * (cy - prev.y) }
- })
+ return { scale, x: cx - k * (cx - prev.x), y: cy - k * (cy - prev.y) }
+ })
+ },
+ [clamp]
+ )
+
+ const reset = useCallback(() => {
+ setTransform({ scale: 1, x: 0, y: 0 })
+ setMoved(false)
+ setPanning(false)
}, [])
- const onWheel = useCallback(
- (event: ReactWheelEvent) => {
+ const zoomIn = useCallback(() => {
+ const node = ref.current
+ const rect = node?.getBoundingClientRect()
+ zoomAt(BUTTON_STEP, rect ? rect.width / 2 : 0, rect ? rect.height / 2 : 0)
+ }, [zoomAt])
+
+ const zoomOut = useCallback(() => {
+ const node = ref.current
+ const rect = node?.getBoundingClientRect()
+ zoomAt(1 / BUTTON_STEP, rect ? rect.width / 2 : 0, rect ? rect.height / 2 : 0)
+ }, [zoomAt])
+
+ // Native, non-passive wheel so we can preventDefault page scroll. Attached to
+ // the surface node (ref) only while the viewer is enabled, so it never
+ // hijacks wheel events when the lightbox/dialog is closed.
+ useEffect(() => {
+ const node = ref.current
+ if (!node || !enabled) {
+ return
+ }
+
+ const onWheel = (event: WheelEvent) => {
event.preventDefault()
// macOS smart zoom (two-finger double-tap) → reset, not zoom-in.
if (isSmartZoomWheel(event)) {
setTransform({ scale: 1, x: 0, y: 0 })
+ setMoved(false)
return
}
- const rect = event.currentTarget.getBoundingClientRect()
+ const rect = node.getBoundingClientRect()
const cx = event.clientX - rect.left - rect.width / 2
const cy = event.clientY - rect.top - rect.height / 2
zoomAt(event.deltaY < 0 ? WHEEL_STEP : 1 / WHEEL_STEP, cx, cy)
- },
- [zoomAt]
- )
+ }
- const onPointerDown = useCallback((event: ReactPointerEvent) => {
- event.currentTarget.setPointerCapture(event.pointerId)
- setTransform(prev => {
- drag.current = { x: event.clientX - prev.x, y: event.clientY - prev.y }
+ node.addEventListener('wheel', onWheel, { passive: false })
- return prev
- })
- setPanning(true)
+ return () => node.removeEventListener('wheel', onWheel)
+ }, [enabled, zoomAt])
+
+ const endPan = useCallback(() => {
+ drag.current = null
+ setPanning(false)
}, [])
- const onPointerMove = useCallback((event: ReactPointerEvent) => {
- if (!drag.current) {
- return
+ const onPointerDown = useCallback((event: ReactPointerEvent<T>) => {
+ event.currentTarget.setPointerCapture?.(event.pointerId)
+ pointers.current.set(event.pointerId, { x: event.clientX, y: event.clientY })
+ setMoved(false)
+
+ if (pointers.current.size === 1) {
+ drag.current = { x: event.clientX, y: event.clientY, startX: event.clientX, startY: event.clientY }
+ pinch.current = null
+ } else if (pointers.current.size === 2) {
+ const [a, b] = [...pointers.current.values()]
+ pinch.current = {
+ dist: Math.hypot(a.x - b.x, a.y - b.y),
+ midX: (a.x + b.x) / 2,
+ midY: (a.y + b.y) / 2
+ }
+ drag.current = null
}
+ }, [])
- const start = drag.current
+ const onPointerMove = useCallback(
+ (event: ReactPointerEvent<T>) => {
+ if (!pointers.current.has(event.pointerId)) {
+ return
+ }
- setTransform(prev => ({ ...prev, x: event.clientX - start.x, y: event.clientY - start.y }))
- }, [])
+ pointers.current.set(event.pointerId, { x: event.clientX, y: event.clientY })
- const endPan = useCallback(() => {
- drag.current = null
+ const node = ref.current
+ if (!node) {
+ return
+ }
+
+ const rect = node.getBoundingClientRect()
+ const originX = rect.width / 2
+ const originY = rect.height / 2
+
+ if (pointers.current.size >= 2 && pinch.current) {
+ const [a, b] = [...pointers.current.values()]
+ const dist = Math.hypot(a.x - b.x, a.y - b.y)
+ const midX = (a.x + b.x) / 2
+ const midY = (a.y + b.y) / 2
+ const factor = dist / (pinch.current.dist || dist)
+
+ setTransform(prev => {
+ const scale = clamp(prev.scale * factor)
+ const k = scale / prev.scale
+ // Focal point relative to the surface centre; zoom about it, then add
+ // the midpoint translation so the gesture follows the fingers.
+ const fx = midX - rect.left - originX
+ const fy = midY - rect.top - originY
+
+ return {
+ scale,
+ x: prev.x + (midX - pinch.current!.midX) + (fx - k * fx),
+ y: prev.y + (midY - pinch.current!.midY) + (fy - k * fy)
+ }
+ })
+
+ pinch.current = { dist, midX, midY }
+ setMoved(true)
+
+ return
+ }
+
+ if (pointers.current.size === 1 && drag.current) {
+ const dx = event.clientX - drag.current.x
+ const dy = event.clientY - drag.current.y
+
+ if (Math.hypot(event.clientX - drag.current.startX, event.clientY - drag.current.startY) > DRAG_THRESHOLD) {
+ setMoved(true)
+ }
+
+ setTransform(prev => ({ ...prev, x: prev.x + dx, y: prev.y + dy }))
+ drag.current = { ...drag.current, x: event.clientX, y: event.clientY }
+ }
+ },
+ [clamp]
+ )
+
+ const onPointerUp = useCallback((event: ReactPointerEvent<T>) => {
+ event.currentTarget.releasePointerCapture?.(event.pointerId)
+ pointers.current.delete(event.pointerId)
setPanning(false)
+
+ if (pointers.current.size === 1) {
+ // Lifting one finger of a pinch continues as a single-finger pan.
+ const [only] = [...pointers.current.values()]
+ drag.current = { x: only.x, y: only.y, startX: only.x, startY: only.y }
+ setMoved(true)
+ pinch.current = null
+ } else if (pointers.current.size === 0) {
+ drag.current = null
+ pinch.current = null
+ }
}, [])
- const reset = useCallback(() => setTransform({ scale: 1, x: 0, y: 0 }), [])
- const zoomIn = useCallback(() => zoomAt(BUTTON_STEP), [zoomAt])
- const zoomOut = useCallback(() => zoomAt(1 / BUTTON_STEP), [zoomAt])
+ // A canceled pointer (the browser steals the gesture for scroll/selection,
+ // or a touch is interrupted) must get the same cleanup as completion. Without
+ // it the stale entry in `pointers` makes the next pointerdown look like a
+ // pinch with old coordinates.
+ const onPointerCancel = useCallback((event: ReactPointerEvent<T>) => {
+ event.currentTarget.releasePointerCapture?.(event.pointerId)
+ pointers.current.delete(event.pointerId)
+
+ if (pointers.current.size <= 1) {
+ drag.current = null
+ pinch.current = null
+ setPanning(false)
+ setMoved(false)
+ }
+ }, [])
const style: CSSProperties = {
transform: `translate(${transform.x}px, ${transform.y}px) scale(${transform.scale})`
}
return {
+ moved,
panning,
+ ref,
reset,
scale: transform.scale,
- stageProps: { onPointerDown, onPointerLeave: endPan, onPointerMove, onPointerUp: endPan, onWheel },
+ stageProps: {
+ onPointerCancel,
+ onPointerDown,
+ onPointerLeave: endPan,
+ onPointerMove,
+ onPointerUp
+ },
style,
zoomIn,
zoomOut
diff --git a/apps/desktop/src/components/ui/zoomable.tsx b/apps/desktop/src/components/ui/zoomable.tsx
index 09ed80596a1..6bed895f70d 100644
--- a/apps/desktop/src/components/ui/zoomable.tsx
+++ b/apps/desktop/src/components/ui/zoomable.tsx
@@ -69,7 +69,9 @@ function ZoomPanViewer({
onOpenChange: (open: boolean) => void
open: boolean
}) {
- const { panning, reset, stageProps, style, zoomIn, zoomOut } = useZoomPan()
+ const { panning, ref, reset, stageProps, style, zoomIn, zoomOut } = useZoomPan<HTMLDivElement>({
+ enabled: open
+ })
useEffect(() => {
if (open) {
@@ -85,6 +87,7 @@ function ZoomPanViewer({
showCloseButton={false}
>
<div
+ ref={ref}
className={cn(
'relative flex-1 touch-none select-none overflow-hidden',
panning ? 'cursor-grabbing' : 'cursor-grab'
diff --git a/apps/desktop/src/i18n/ar_chat.ts b/apps/desktop/src/i18n/ar_chat.ts
index fa35b4fed05..bd690bf80a7 100644
--- a/apps/desktop/src/i18n/ar_chat.ts
+++ b/apps/desktop/src/i18n/ar_chat.ts
@@ -454,6 +454,9 @@ export const arChat = {
openImage: 'فتح الصورة',
downloadImage: 'تنزيل الصورة',
savingImage: 'جار حفظ الصورة',
+ zoomIn: 'تكبير',
+ zoomOut: 'تصغير',
+ resetZoom: 'إعادة تعيين التكبير',
imagePreviewFailed: 'فشلت معاينة الصورة',
imageAttach: 'إرفاق الصورة',
imageWriteFailed: 'فشل كتابة الصورة',
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index a5f1a26eaf5..242b6f6dcdd 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -5593,6 +5593,9 @@ export const en: Translations = {
openImage: 'Open image',
downloadImage: 'Download image',
savingImage: 'Saving image',
+ zoomIn: 'Zoom in',
+ zoomOut: 'Zoom out',
+ resetZoom: 'Reset zoom',
imagePreviewFailed: 'Image preview failed',
imageAttach: 'Image attach',
imageWriteFailed: 'Failed to write image to disk.',
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index ca9ed62284e..8c6349ca18a 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -4188,6 +4188,9 @@ export const ja = defineLocale({
openImage: '画像を開く',
downloadImage: '画像をダウンロード',
savingImage: '画像を保存中',
+ zoomIn: '拡大',
+ zoomOut: '縮小',
+ resetZoom: 'ズームをリセット',
imagePreviewFailed: '画像のプレビューに失敗しました',
imageAttach: '画像を添付',
imageWriteFailed: '画像のディスクへの書き込みに失敗しました。',
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index e5d451f5c51..57054a40260 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -4651,6 +4651,9 @@ export interface Translations {
openImage: string
downloadImage: string
savingImage: string
+ zoomIn: string
+ zoomOut: string
+ resetZoom: string
imagePreviewFailed: string
imageAttach: string
imageWriteFailed: string
diff --git a/apps/desktop/src/i18n/zh-hant_chat.ts b/apps/desktop/src/i18n/zh-hant_chat.ts
index 15460442a4a..80537a4fec8 100644
--- a/apps/desktop/src/i18n/zh-hant_chat.ts
+++ b/apps/desktop/src/i18n/zh-hant_chat.ts
@@ -477,6 +477,9 @@ export const zhHantChat = {
openImage: '開啟圖片',
downloadImage: '下載圖片',
savingImage: '正在儲存圖片',
+ zoomIn: '放大',
+ zoomOut: '縮小',
+ resetZoom: '重設縮放',
imagePreviewFailed: '圖片預覽失敗',
imageAttach: '附加圖片',
imageWriteFailed: '無法將圖片寫入磁碟。',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 074b9542f10..e82d91a125a 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -5141,6 +5141,9 @@ export const zh = defineLocale({
openImage: '打开图片',
downloadImage: '下载图片',
savingImage: '正在保存图片',
+ zoomIn: '放大',
+ zoomOut: '缩小',
+ resetZoom: '重置缩放',
imagePreviewFailed: '图片预览失败',
imageAttach: '附加图片',
imageWriteFailed: '无法将图片写入磁盘。',