# Image Viewer A pane for the Herdr app that shows one image file. The Files panel (files-md) opens it from the right-click item Open in Image Viewer, for a PNG, JPEG, GIF, WebP, BMP, SVG, ICO or TIFF file. The image fits the pane, or you zoom it from 10% to 800% and scroll. It never changes the file. ![Image Viewer](preview.png) ## What you see One pane with two bands, on the `canvas` background (13 px text): 1. **Bar, 42 px, 1 px bottom `border`, 12 px side padding, 8 px gap.** From the left: - `Image` in semibold. - The file line, 12 px, `muted`, one line, truncated: ` · × · `. The size reads `B`, `KB` or `MB` (`55.1 KB`). The `×` part is missing when the size is unknown. While the file loads, the line shows the file name only. - Five buttons, 24 px tall, 9 px side padding, radius 6, 12 px text, `raised` fill: `Fit`, `100%`, `−`, then the current scale in a 44 px wide label (`100%`, 12 px, `muted`), then `+` and `↻`. The active mode button (`Fit` or `100%`) has an `accent` fill and `accent_foreground` text. A disabled button uses `dim` text and has no hover. 2. **Body.** The image on the `canvas` background, 10 px padding. - In **Fit** mode the image is centered, never larger than its own pixels. - In a zoomed mode the image has its true size times the scale, in a scrolling area (both axes). - While loading, `Loading image…` in `dim`. With no file, `Open an image from the Files panel.` in `dim`. An error shows in `ansi1`. ## How it behaves - **Opening.** The mod reads the props `file` (an absolute path) and `fileOn` (a machine name, or null for this computer). It copies the file, then shows it. Opening needs no click in the viewer. - **Fit.** The scale is the smaller of 1, `visible width / image width` and `visible height / image height`. The visible area is the pane minus the bar and the padding. The scale label shows it. A pane that is larger than the image shows the image at `100%`. - **100%.** The image at its true pixel size. The area scrolls when the image is larger than the pane. - **− and +.** Move to the next step below or above the scale now on screen. The steps are 10%, 25%, 50%, 75%, 100%, 150%, 200%, 300%, 400% and 800%. From Fit they start at the fit scale. Nothing happens past the first or last step. - **↻.** Copies the file again and shows the new copy. Use it after the file changes on disk. The zoom stays. - **No size known.** SVG files, every file on macOS and Linux, and any file that `System.Drawing` cannot read have no size for the mod. Then only Fit works: `100%`, `−` and `+` are disabled, the scale label is empty, and the image fits a box of the visible area. - **Errors.** A file on another machine: `Images on another machine are not supported yet.` A name without an image extension: `This file is not an image the viewer can open.` A file larger than 64 MiB: `This image is larger than 64.0 MB.` A file that cannot be read shows the program's error. - **Optional prop `zoom`.** A number such as `1` or `0.5` opens the viewer at that scale. It has no effect on a file with no known size. - **Closing.** When the pane or dialog closes, the mod deletes its copy of the file. ## Built from - `mod.json`: `{"place": "none", "title": "Image Viewer", "overlay": {"kind": "dialog", "width": 920, "height": 0.85}}`. Create this file **before** `main.js` (see Watch out). - `main.js`: a `View` that imports `View`, `div`, `image` from `gpui-kit`, `v_flex`, `h_flex` from `gpui-base`, and `props`, `exec`, `appHome`, `window`, `theme` from `herdr`. - `init` reads `props()` once and starts the copy with `cx.spawn`. - The copy goes to `/data/image-viewer/-