The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Galleries: a tap on a card's description shows all of it on a phone
Adarsh3d78a7f5224b
diff --git a/src/components/preset-gallery.tsx b/src/components/preset-gallery.tsxindex d8df2268..01222121 100644--- a/src/components/preset-gallery.tsx+++ b/src/components/preset-gallery.tsx@@ -11,7 +11,7 @@ import { useProgressive } from "@/components/use-progressive";import { CardChip, badgeKey, parseBadgeKey } from "@/components/gpu/readiness-chip";import { useGpuBadges } from "@/hooks/use-gpu";import { useEngineMode, useViewer } from "@/lib/api";-import { matchesSearch, previewFlip, searchText, type PresetCardData } from "@/lib/preset-cards";+import { matchesSearch, previewFlip, readMoreTap, searchText, TAP_TO_READ, type PresetCardData } from "@/lib/preset-cards";import { cn } from "@/lib/utils";/** A tiny label shown on hover/focus (CSS only: a gallery has hundreds of these). */@@ -63,6 +63,7 @@ export const PresetCard = memo(function PresetCard({const badge = engine !== "cloud" ? parseBadgeKey(gpu) : null;const Icon = PRESET_ICONS[preset.icon] ?? Sparkles;const { ref, playing, asked, handlers } = usePreviewPlayback<HTMLAnchorElement>(preset.id, preset.preview);+ const [more, setMore] = useState(false);return (// Prefetched on hover or touch, not on sight: a gallery shows hundreds of these.<IntentLink@@ -99,8 +100,19 @@ export const PresetCard = memo(function PresetCard({<p className="truncate text-[13px] font-medium">{preset.name}</p>{!compact && (// Two lines hold the card's place in the grid and stay inside the card on hover (a panel over the next- // row read as broken); the full text is the tooltip and the preset's own page.- <p title={preset.description} className="line-clamp-2 text-[12px] leading-snug text-muted-foreground">+ // row read as broken); the full text is the tooltip and the preset's own page. A phone has no tooltip: a+ // tap on the text opens it in place (readMoreTap), so the gallery stays even until someone asks.+ <p+ title={preset.description}+ data-more={more || undefined}+ onClick={(e) => {+ const next = readMoreTap(e.currentTarget, more, window.matchMedia(TAP_TO_READ).matches);+ if (next === null) return;+ e.preventDefault();+ setMore(next);+ }}+ className={cn("text-[12px] leading-snug text-muted-foreground", !more && "line-clamp-2")}+ >{caption ?? preset.description}</p>)}diff --git a/src/lib/preset-cards.ts b/src/lib/preset-cards.tsindex dec32801..2fa46148 100644--- a/src/lib/preset-cards.ts+++ b/src/lib/preset-cards.ts@@ -433,19 +433,15 @@ export function lookHue(look: Preset["look"]): number {return m ? Math.round(Number(m[1])) % 360 : 282;}-/** Shorten to at most `max` characters at a word boundary (cards show two lines). */-export function clip(s: string, max: number): string {- if (s.length <= max) return s;- const cut = s.slice(0, max - 1);- return `${cut.slice(0, Math.max(cut.lastIndexOf(" "), max * 0.6)).replace(/[\s,;:.–—-]+$/, "")}…`;-}--/** What a gallery card needs, and nothing else, with the preview it shows (toPresetCard in preset-card-data.ts picks it). */+/**+ * What a gallery card needs, and nothing else, with the preview it shows (toPresetCard in preset-card-data.ts picks it).+ * The whole description: the card clamps it to two lines, and a phone opens the rest in place (readMoreTap).+ */export function presetCard(p: Preset, preview: PresetPreview): PresetCardData {return {id: p.id,name: p.name,- description: clip(p.description, 100),+ description: p.description,category: p.category,icon: p.look.icon,hue: lookHue(p.look),@@ -523,6 +519,20 @@ export function presetRouteLines(});}+/** Where a card's text has no tooltip to show the rest of it: a phone, or a screen with no mouse. */+export const TAP_TO_READ = "(max-width: 639px), (hover: none)";++/**+ * A tap on a card's two-line description where there is no tooltip (TAP_TO_READ): text cut short opens in place, and+ * a second tap closes it, in place of opening the preset. Text that fits its two lines, and every click on a desktop,+ * open the preset as before. The open state the text takes next, or null to let the click through to the card's link.+ */+export function readMoreTap(text: { scrollHeight: number; clientHeight: number }, open: boolean, tapToRead: boolean): boolean | null {+ if (!tapToRead) return null;+ if (open) return false;+ return text.scrollHeight > text.clientHeight + 1 ? true : null;+}+/** One line telling the user what to do with a preset, e.g. "Add a target photo and a face, then Generate." */export function presetHowTo(p: Pick<Preset, "inputs" | "userPrompt" | "type">): string {const needs = p.inputs.filter((i) => i.required).map((i) => article(lowerFirst(i.label)));diff --git a/tests/preset-cards.test.ts b/tests/preset-cards.test.tsindex 9a3b8c5c..2f6d9c8d 100644--- a/tests/preset-cards.test.ts+++ b/tests/preset-cards.test.ts@@ -23,7 +23,9 @@ import {presetHowTo,presetRouteLines,previewFlip,+ readMoreTap,searchText,+ TAP_TO_READ,matchesSearch,type CameraMove,type MoveSpec,@@ -229,14 +231,19 @@ describe("slim card DTOs", () => {expect(json).not.toMatch(/modelId|loras|https?:|promptTemplate|parity/);});+ it("carries the whole description, which a phone opens in place of a tooltip", () => {+ for (const p of [...APPS, ...MOTIONS, ...EFFECTS]) expect(toPresetCard(p).description, p.id).toBe(p.description);+ expect(Math.max(...EFFECTS.map((p) => p.description.length))).toBeGreaterThan(100);+ });+it("is a small fraction of the full preset payload", () => {for (const list of [APPS, MOTIONS, EFFECTS]) {const full = JSON.stringify(list).length;const slim = JSON.stringify(list.map(toPresetCard)).length;expect(slim / full).toBeLessThan(0.45);}- // The 255-card effects gallery ships well under 80 KB of card data.- expect(JSON.stringify(EFFECTS.map(toPresetCard)).length).toBeLessThan(80_000);+ // The 255-card effects gallery ships under 85 KB of card data (2.3 KB of it the descriptions' whole text).+ expect(JSON.stringify(EFFECTS.map(toPresetCard)).length).toBeLessThan(85_000);});it("reads the hue back from the preset look", () => {@@ -283,6 +290,32 @@ describe("preset route lines (details popover)", () => {});});+describe("a card's description on a phone", () => {+ const cut = { scrollHeight: 64, clientHeight: 32 };+ const fits = { scrollHeight: 32, clientHeight: 32 };++ it("opens text cut short in place, and a second tap closes it", () => {+ expect(readMoreTap(cut, false, true)).toBe(true);+ expect(readMoreTap({ scrollHeight: 64, clientHeight: 64 }, true, true)).toBe(false);+ });++ it("lets a tap on text that fits through to the preset", () => {+ expect(readMoreTap(fits, false, true)).toBeNull();+ // Sub-pixel rounding isn't text cut short.+ expect(readMoreTap({ scrollHeight: 33, clientHeight: 32 }, false, true)).toBeNull();+ });++ it("leaves the desktop as it is: a click opens the preset", () => {+ expect(readMoreTap(cut, false, false)).toBeNull();+ expect(readMoreTap(cut, true, false)).toBeNull();+ });++ it("applies on phones and on screens with no mouse", () => {+ expect(TAP_TO_READ).toContain("(max-width: 639px)");+ expect(TAP_TO_READ).toContain("(hover: none)");+ });+});+describe("preset how-to line", () => {it("names the required inputs", () => {expect(presetHowTo(byName(APPS, "Face Swap"))).toMatch(/^Add .+ and .+, then Generate\.$/);diff --git a/tests/preset-covers.test.ts b/tests/preset-covers.test.tsindex 518f7679..afd3da03 100644--- a/tests/preset-covers.test.ts+++ b/tests/preset-covers.test.ts@@ -80,15 +80,16 @@ describe("the preset covers manifest", () => {});// Every one of the 255 effects is getting a hover clip (about 60 bytes of card data each, with its version), so the- // budget is sized for all of them, not for today's count: about 97 KB then, of which the versions are 5.6 KB.- it("shows each cover on its card, and keeps the effects gallery's card data under 100 KB with them", () => {+ // budget is sized for all of them, not for today's count: about 100 KB then, of which the versions are 5.6 KB and+ // the descriptions' whole text (a phone opens it in place of a tooltip) 2.3 KB.+ it("shows each cover on its card, and keeps the effects gallery's card data under 105 KB with them", () => {for (const p of [...APPS, ...MOTIONS, ...EFFECTS]) {const c = toPresetCard(p);const e = PRESET_PREVIEWS[p.id];expect(isCover(c.preview), p.id).toBe(!!e);if (e) expect([c.preview.poster, c.preview.video], p.id).toEqual([e.poster, e.video]);}- expect(JSON.stringify(EFFECTS.map(toPresetCard)).length).toBeLessThan(100_000);+ expect(JSON.stringify(EFFECTS.map(toPresetCard)).length).toBeLessThan(105_000);});it("versions every cover URL a gallery card, the preset header or a picker shows, and each small copy's", () => {