Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(ui): 比角标还小的图,角标让到图两边

lmliheng1319c9e8c7ab
diff --git a/changelog/unreleased/2026-10-30-lightbox-chips-beside-tiny-picture.md b/changelog/unreleased/2026-10-30-lightbox-chips-beside-tiny-picture.md
new file mode 100644
index 00000000..5eb2df59
--- /dev/null
+++ b/changelog/unreleased/2026-10-30-lightbox-chips-beside-tiny-picture.md
@@ -0,0 +1,35 @@
+# On a picture smaller than the chips, the chips step aside
+
+- **Date:** 2026-10-30
+- **Type:** fix
+- **Scope:** `ui`
+- **Breaking:** no
+
+[中文](2026-10-30-lightbox-chips-beside-tiny-picture.zh.md)
+
+The lightbox floats the size badge and the close glyph in the picture's frame, one in each top
+corner. That is right for a photograph and wrong for a 40 × 30 sprite: the two chips together are
+larger than the picture, the badge itself wraps onto three lines inside so narrow a frame, and the
+picture they describe is what disappears. The chips still take the corners **when the picture is
+big enough to hold them**; when it is not, the size moves to the picture's left and the close glyph
+to its right — same row, still over the dimmed page, and neither covers the other.
+
+## Details
+
+- `packages/ui/src/components/overlays/lightbox/image-board.ts`: a new pure function
+ `cornerChipsFit(width, height)` with `CHIP_BAND = 36` — the chips are always drawn within 36px of
+ the top edge and, side by side, need about 140px of width, so a picture under three bands tall or
+ under 160px wide has no room. An unmeasured size never fits.
+- `packages/ui/src/components/overlays/lightbox/lightbox.tsx`: the chips' placement follows that
+ answer — `right-2 top-2` / `left-2 top-2` when they fit (exactly as before), `left-full ml-1.5` /
+ `right-full mr-1.5` when they do not, the size badge additionally `whitespace-nowrap` (beside a
+ narrow picture its box has no width to wrap inside). A picture still loading, or one whose reading
+ belongs to the previous picture, keeps the corners: that is every other picture's look, and
+ jumping a line on load would be the bigger distraction.
+- Tests: four new cases in `packages/ui/test/image-board.test.ts` — a large picture fits, a sprite /
+ a banner / a column do not, both sides of the threshold, and an unmeasured size never fits.
+
+## Compatibility
+
+- No API, on-disk or protocol change. On a large picture the chips have not moved a pixel; a picture
+ bigger than the chips but under the threshold (a 1200 × 80 banner, say) takes the new placement.
diff --git a/changelog/unreleased/2026-10-30-lightbox-chips-beside-tiny-picture.zh.md b/changelog/unreleased/2026-10-30-lightbox-chips-beside-tiny-picture.zh.md
new file mode 100644
index 00000000..1105881b
--- /dev/null
+++ b/changelog/unreleased/2026-10-30-lightbox-chips-beside-tiny-picture.zh.md
@@ -0,0 +1,30 @@
+# 比角标还小的图片,角标让到图片两边
+
+- **日期:** 2026-10-30
+- **类型:** fix
+- **范围:** `ui`
+- **破坏性:** 无
+
+[English](2026-10-30-lightbox-chips-beside-tiny-picture.md)
+
+放大层把尺寸角标与关闭按钮浮在图片的框里、各自的角上 —— 对大图是对的,对一张 40 × 30 的图标就不
+成立了:两个角标加起来的面积比图片还大,角标自己还会在这么窄的框里折成三行,于是被描述的那张图反
+而看不见了。现在角标照旧落在图片的两个角上,**只有当这张图本来也放得下它们的时候**:放不下时,尺
+寸挪到图片左边、关闭按钮挪到图片右边,仍在同一行、仍在遮罩之上,谁也不压着谁。
+
+## 细节
+
+- `packages/ui/src/components/overlays/lightbox/image-board.ts`:新增纯函数
+ `cornerChipsFit(width, height)` 与 `CHIP_BAND = 36` —— 角标永远画在图片顶边 36px 之内,并排还要
+ ~140px 宽,所以图高不足三条带子、或宽不足 160px 时就是「放不下」。尺寸还没量出来时不算数。
+- `packages/ui/src/components/overlays/lightbox/lightbox.tsx`:角标的位置由这一条决定 —— 放得下时
+ `right-2 top-2` / `left-2 top-2`(与从前一样),放不下时 `left-full ml-1.5` / `right-full mr-1.5`,
+ 尺寸那一枚另加 `whitespace-nowrap`(贴着窄图时它的盒子没有宽度可折)。图片还在加载、读数还属于上
+ 一张的时候仍留在角上:那是每张图的常态,加载完再跳一行反而更扎眼。
+- 测试:`packages/ui/test/image-board.test.ts` 新增四条 —— 大图放得下、图标 / 横幅 / 竖条放不下、
+ 阈值两侧各一条、没量过尺寸时一律「放不下」。
+
+## 兼容
+
+- 不改接口、不改线上格式、不改已存数据。大图上角标的位置一个像素都没动;图片比角标大但没到阈值
+ (例如 1200 × 80 的横幅)会改用新的排布。
diff --git a/packages/ui/src/components/overlays/lightbox/image-board.ts b/packages/ui/src/components/overlays/lightbox/image-board.ts
index af659edc..70c18a19 100644
--- a/packages/ui/src/components/overlays/lightbox/image-board.ts
+++ b/packages/ui/src/components/overlays/lightbox/image-board.ts
@@ -1,7 +1,7 @@
/**
* The lightbox's arithmetic, apart from its markup so it can be read on its own: which picture of
- * a batch a step lands on, what a picture's own pixel size reads as, and what name a download
- * saves under.
+ * a batch a step lands on, what a picture's own pixel size reads as, what name a download saves
+ * under, and whether a picture is big enough to carry the two corner chips on itself.
*/
/** One picture of the lightbox's batch: what to fetch, and the words that describe it. */
@@ -29,6 +29,24 @@ export function pixelSizeLabel(width: number, height: number): string | null {
return `${Math.round(width)} × ${Math.round(height)}`;
}
+/** The height the two corner chips need from the picture's top edge: 8px in, plus the close disc. */
+export const CHIP_BAND = 36;
+
+/**
+ * Whether the two corner chips — the close disc top-right, the size badge top-left — can sit on
+ * the picture itself. They are always drawn within {@link CHIP_BAND} of the top edge and, side by
+ * side with a gap between them, need about 140px of width. A picture that cannot give them that
+ * much is smaller than the words describing it (a 40 × 30 sprite is smaller than either chip), so
+ * the lightbox moves the chips beside the picture instead of onto it: a chip that covers the
+ * picture it is describing is worse than one placed a step outside it.
+ */
+export function cornerChipsFit(width: number, height: number): boolean {
+ if (!Number.isFinite(width) || !Number.isFinite(height)) return false;
+ // Three bands of height keeps the chips under a third of the picture, and 160px leaves the two
+ // chips room side by side with a gap — narrower than that and they touch each other.
+ return height >= CHIP_BAND * 3 + 12 && width >= 160;
+}
+
/** What a `data:` URL's media type says the file is called, when it says anything. */
function dataTypeName(src: string): string | null {
const mime = /^data:([^;,]+)/.exec(src)?.[1]?.trim().toLowerCase() ?? "";
diff --git a/packages/ui/src/components/overlays/lightbox/lightbox.tsx b/packages/ui/src/components/overlays/lightbox/lightbox.tsx
index 0517f992..5fc1669d 100644
--- a/packages/ui/src/components/overlays/lightbox/lightbox.tsx
+++ b/packages/ui/src/components/overlays/lightbox/lightbox.tsx
@@ -14,6 +14,12 @@
* The bar carries only what the page can really do: save the file (a plain `download` link, no
* request of its own) and move within the batch. Editing actions a generation service would back
* have no endpoint behind them here, and a row of buttons that cannot work is worse than none.
+ *
+ * The close glyph and the size badge hang in the picture's top corners while the picture leaves
+ * room for them; on a picture smaller than either chip they are set beside it instead — the size
+ * to its left, the close glyph to its right, both over the backdrop — because there they still
+ * read while on the picture they would be the whole picture (and above it the two would collide
+ * on a picture narrower than they are).
*/
import { useState } from "react";
import type { ComponentPropsWithoutRef } from "react";
@@ -23,7 +29,7 @@ import { ICONS } from "../../icons/icons";
import { GlyphIcon } from "../../icons/glyph-icon/glyph-icon";
import { CloseIcon, DownloadIcon } from "../../icons/marks/marks";
import { useEscLayer } from "../esc-layers/esc-layers";
-import { downloadName, pixelSizeLabel, stepIndex } from "./image-board";
+import { cornerChipsFit, downloadName, pixelSizeLabel, stepIndex } from "./image-board";
import type { LightboxImage } from "./image-board";
export type { LightboxImage };
@@ -73,10 +79,17 @@ export function Lightbox({ open, src, alt, onClose, closeLabel, images }: Lightb
);
const at = Math.min(Math.max(step ?? opening, 0), batch.length - 1);
const shown = batch[at] ?? { src, alt };
- const badge =
+ /**
+ * The reading, or `null` while it does not belong to the picture on screen. Nothing has loaded
+ * yet for a picture still arriving, and then the chips stay in the corners: that is where every
+ * other picture keeps them, and jumping up a line on load would be the bigger distraction.
+ */
+ const size =
measured !== null && measured.src === shown.src
- ? pixelSizeLabel(measured.width, measured.height)
+ ? { width: measured.width, height: measured.height }
: null;
+ const badge = size === null ? null : pixelSizeLabel(size.width, size.height);
+ const chipsInCorners = size === null || cornerChipsFit(size.width, size.height);
const multi = batch.length > 1;
return createPortal(
@@ -89,12 +102,16 @@ export function Lightbox({ open, src, alt, onClose, closeLabel, images }: Lightb
>
<div className="anim-pop relative">
{/* Close glyph: top-right inside the frame, floating over the image on a translucent
- disc of the ink colour, which keeps it visible on any image. */}
+ disc of the ink colour, which keeps it visible on any image. On a picture too small
+ to hold it, it steps outside the frame's right edge — `left-full` — where the disc
+ still reads against the dimmed page and covers no part of the picture. */}
<button
type="button"
aria-label={closeLabel ?? strings.close}
onClick={close}
- className="absolute right-2 top-2 flex h-7 w-7 items-center justify-center rounded-full bg-fg/50 text-canvas transition-colors duration-150 hover:bg-fg/70"
+ className={`absolute flex h-7 w-7 items-center justify-center rounded-full bg-fg/50 text-canvas transition-colors duration-150 hover:bg-fg/70 ${
+ chipsInCorners ? "right-2 top-2" : "left-full top-0 ml-1.5"
+ }`}
>
<CloseIcon />
</button>
@@ -112,9 +129,15 @@ export function Lightbox({ open, src, alt, onClose, closeLabel, images }: Lightb
className="max-h-[85vh] max-w-[88vw] rounded-lg border border-line bg-surface"
/>
{/* The picture's own pixel size, opposite the close glyph: what the file is, not what the
- window made of it. */}
+ window made of it. It travels with the close glyph, so the two never sit on a picture
+ that is smaller than they are — `whitespace-nowrap` because beside a narrow picture its
+ box has no width to wrap inside. */}
{badge !== null && (
- <span className="absolute left-2 top-2 rounded-full bg-fg/50 px-2 py-0.5 text-xs tabular-nums text-canvas">
+ <span
+ className={`absolute whitespace-nowrap rounded-full bg-fg/50 px-2 py-0.5 text-xs tabular-nums text-canvas ${
+ chipsInCorners ? "left-2 top-2" : "right-full top-0 mr-1.5"
+ }`}
+ >
{badge}
</span>
)}
diff --git a/packages/ui/test/image-board.test.ts b/packages/ui/test/image-board.test.ts
index 764e0225..b902f8d3 100644
--- a/packages/ui/test/image-board.test.ts
+++ b/packages/ui/test/image-board.test.ts
@@ -1,10 +1,12 @@
/**
* The lightbox's arithmetic (src/components/overlays/lightbox/image-board.ts): stepping through a
- * batch wraps at both ends, the pixel badge speaks only when a picture's own size is known, and a
- * download takes the file's name from where the picture came from.
+ * batch wraps at both ends, the pixel badge speaks only when a picture's own size is known, a
+ * download takes the file's name from where the picture came from, and the corner chips only sit
+ * on a picture big enough to hold them.
*/
import { describe, expect, it } from "vitest";
import {
+ cornerChipsFit,
downloadName,
pixelSizeLabel,
stepIndex,
@@ -45,6 +47,34 @@ describe("pixelSizeLabel", () => {
});
});
+describe("cornerChipsFit", () => {
+ it("keeps the chips on a picture with room to spare", () => {
+ expect(cornerChipsFit(1600, 1000)).toBe(true);
+ expect(cornerChipsFit(1280, 860)).toBe(true);
+ });
+
+ it("puts them above the picture when the picture is smaller than the chips", () => {
+ // The thumbnail of a sprite: 40 × 30 is smaller than either chip.
+ expect(cornerChipsFit(40, 30)).toBe(false);
+ // A wide banner leaves no height for the band.
+ expect(cornerChipsFit(1200, 80)).toBe(false);
+ // A column leaves no width for the two chips side by side.
+ expect(cornerChipsFit(120, 900)).toBe(false);
+ });
+
+ it("draws the line at three bands of height and two chips of width", () => {
+ expect(cornerChipsFit(160, 120)).toBe(true);
+ expect(cornerChipsFit(159, 120)).toBe(false);
+ expect(cornerChipsFit(160, 119)).toBe(false);
+ });
+
+ it("answers no for a size that was never measured", () => {
+ expect(cornerChipsFit(0, 0)).toBe(false);
+ expect(cornerChipsFit(Number.NaN, 720)).toBe(false);
+ expect(cornerChipsFit(720, Number.POSITIVE_INFINITY)).toBe(false);
+ });
+});
+
describe("downloadName", () => {
it("takes the last segment of a URL, without its query or fragment", () => {
expect(downloadName("https://example.test/a/quarterly-report.pdf#page=2")).toBe(