Skip to content

armgit / fuobe

Public Imported from GitHub
0

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.

Click to Ad: style tiles show their real look when one is published

Adarsh2cdd43647cc8
diff --git a/src/components/marketing/click-to-ad.tsx b/src/components/marketing/click-to-ad.tsx
index 31fea8c4..c96b7e25 100644
--- a/src/components/marketing/click-to-ad.tsx
+++ b/src/components/marketing/click-to-ad.tsx
@@ -12,12 +12,14 @@ import { areaCls, ColorList, inputCls } from "@/components/brand/fields";
import { ImageList } from "@/components/brand/image-list";
import { AddFromLink, priceText, ProductThumb, UploadProductButton } from "@/components/brand/products";
import { SelfHostNote } from "@/components/self-host-note";
+import { useCoverPlayback } from "@/components/template-cover";
import type { SlotValue } from "@/components/studio/media-slot";
import { uploadFile, useLikelyVisitor } from "@/lib/api";
-import { AD_STYLES, END_CARD, KIT_LABELS, type BrandKit, type MarketingRun, type Product, type RunEstimate } from "@/lib/catalog/marketing";
+import { AD_STYLES, END_CARD, KIT_LABELS, type AdStyle, type BrandKit, type MarketingRun, type Product, type RunEstimate } from "@/lib/catalog/marketing";
import { formatCost } from "@/lib/format";
import { cn } from "@/lib/utils";
import { toastError } from "@/lib/refusals";
+import { templateCover } from "@/lib/template-covers";
import { endCardPng, renderEndCard, siteLabel, type EndCardInput } from "./end-card";
import { addRuns, send, useBrand, useEstimate, useProductActions, useProducts, useReadingProduct, useUpdateBrand } from "./hooks";
import type { ModelInfo } from "./model-info";
@@ -65,6 +67,28 @@ function KitProgress() {
const styleScene = (presenter: boolean, dark?: boolean) => (presenter ? "selfie" : dark ? "noir" : "orbit");
+/** One ad style: its real cover when it has one (a clip plays as the template cards' do), else its drawn preview. */
+export function StyleTile({ style: s, selected, onPick }: { style: AdStyle; selected: boolean; onPick: () => void }) {
+ const cover = templateCover("marketing", `cta-${s.id}`);
+ const { ref, playing, asked, handlers } = useCoverPlayback<HTMLButtonElement>(`marketing/cta-${s.id}`, cover);
+ return (
+ <button
+ ref={ref}
+ type="button"
+ {...handlers}
+ aria-pressed={selected}
+ onClick={onPick}
+ className={cn("min-w-0 rounded-xl text-left outline-none focus-visible:ring-2 focus-visible:ring-ring", selected && "ring-2 ring-primary ring-offset-2 ring-offset-background")}
+ >
+ <div className="relative aspect-[9/14] overflow-hidden rounded-xl">
+ <TemplatePreview id={s.id} look={{ scene: styleScene(s.presenter, s.dark), hue: s.hue, hue2: (s.hue + 35) % 360, dark: s.dark }} video cover={cover} playing={playing} asked={asked} sizes="(max-width: 640px) 50vw, 200px" />
+ </div>
+ <p className="mt-1.5 truncate text-[13px] font-medium">{s.name}</p>
+ <p className="line-clamp-2 text-[11px] text-muted-foreground">{s.description}</p>
+ </button>
+ );
+}
+
/** The end card as the ad will end on it, drawn small (the same drawing as the full-size PNG). */
function EndCardPreview({ input, className }: { input: EndCardInput; className?: string }) {
const ref = useRef<HTMLCanvasElement>(null);
@@ -347,23 +371,16 @@ export function ClickToAd({ models }: { models: Record<string, ModelInfo> }) {
<Step n={3} title="Choose a style and start" hint="Pick what looks right for your product.">
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-5">
{AD_STYLES.map((s) => (
- <button
+ <StyleTile
key={s.id}
- type="button"
- aria-pressed={s.id === styleId}
- onClick={() => {
+ style={s}
+ selected={s.id === styleId}
+ onPick={() => {
setStyleId(s.id);
setPresenter(null);
setScript(null);
}}
- className={cn("min-w-0 rounded-xl text-left outline-none focus-visible:ring-2 focus-visible:ring-ring", s.id === styleId && "ring-2 ring-primary ring-offset-2 ring-offset-background")}
- >
- <div className="aspect-[9/14] overflow-hidden rounded-xl">
- <TemplatePreview id={s.id} look={{ scene: styleScene(s.presenter, s.dark), hue: s.hue, hue2: (s.hue + 35) % 360, dark: s.dark }} video />
- </div>
- <p className="mt-1.5 truncate text-[13px] font-medium">{s.name}</p>
- <p className="line-clamp-2 text-[11px] text-muted-foreground">{s.description}</p>
- </button>
+ />
))}
</div>
<div className="mt-5 grid min-w-0 gap-4 md:grid-cols-2">
diff --git a/tests/preset-covers.test.ts b/tests/preset-covers.test.ts
index 98dc5f26..fd9ff526 100644
--- a/tests/preset-covers.test.ts
+++ b/tests/preset-covers.test.ts
@@ -87,7 +87,8 @@ describe("the preset covers manifest", () => {
for (const id of Object.keys(PRESET_BEFORE_AFTER)) for (const f of beforeAfterFiles(id)) named.add(f);
const dir = path.join(root, "public", "previews");
const files = fs.existsSync(dir) ? fs.readdirSync(dir, { recursive: true, encoding: "utf8" }).filter((f) => /\.(jpg|mp4)$/.test(f)) : [];
- const orphans = files.map((f) => `/previews/${f.replaceAll("\\", "/")}`).filter((u) => !named.has(u));
+ // public/previews/templates is the template covers' (tests/template-covers.test.ts checks it).
+ const orphans = files.map((f) => `/previews/${f.replaceAll("\\", "/")}`).filter((u) => !u.startsWith("/previews/templates/") && !named.has(u));
expect(orphans).toEqual([]);
});
diff --git a/tests/template-cover-tiles.test.ts b/tests/template-cover-tiles.test.ts
index f2c6cd2e..a05225e2 100644
--- a/tests/template-cover-tiles.test.ts
+++ b/tests/template-cover-tiles.test.ts
@@ -11,6 +11,7 @@ vi.mock("@/lib/template-covers.generated", () => ({
TEMPLATE_COVERS: {
"marketing/ps-sunlit-plinth": "1a2b3c4d",
"marketing/m2-sticker-pop": ["2b3c4d5e", "3c4d5e6f"],
+ "marketing/cta-luxury": ["0a1b2c3d", "1b2c3d4e"],
"fashion/ultra-bold": { poster: "/previews/templates/fashion/ultra-bold.jpg?v=4d5e6f70", frames: ["/previews/templates/fashion/ultra-bold-2.jpg?v=5e6f7081", "/previews/templates/fashion/ultra-bold-3.jpg?v=6f708192"] },
"photodump/zen": {
poster: "/previews/templates/photodump/zen.jpg?v=708192a3",
@@ -29,13 +30,14 @@ vi.mock("@/lib/template-covers.generated", () => ({
}));
const { TemplateCard: MarketingCard } = await import("@/components/marketing/template-gallery");
+const { StyleTile } = await import("@/components/marketing/click-to-ad");
const { TemplatePreview: FashionPreview } = await import("@/components/fashion/template-preview");
const { PackCover } = await import("@/components/photodump/covers");
const { LookCard } = await import("@/components/shorts/preset-card");
const { TemplateCard: CanvasCard } = await import("@/components/canvas/canvas-list");
const { PresetTile } = await import("@/components/content-factory/parts");
const { StyleArt } = await import("@/components/faceless/style-art");
-const { TEMPLATES } = await import("@/lib/catalog/marketing");
+const { AD_STYLES, TEMPLATES } = await import("@/lib/catalog/marketing");
const { FASHION, PACKS } = await import("@/lib/catalog/packs");
const { coveredFirst, SHORTS_PRESETS, shortsPreview } = await import("@/lib/catalog/shorts");
const { MIXED_PRESETS, mixedPreview } = await import("@/lib/catalog/mixed-media");
@@ -76,6 +78,22 @@ describe("Marketing Studio's template cards", () => {
});
});
+describe("Click to Ad's styles", () => {
+ const tile = (id: string) => html(StyleTile, { style: by(AD_STYLES, id), selected: false, onPick: noop });
+
+ it("show the style's cover (its still until the clip plays), else the drawn preview", () => {
+ const h = tile("luxury");
+ expect(h).toContain('src="/previews/templates/marketing/cta-luxury.jpg?v=0a1b2c3d"');
+ expect(h).toContain("/previews/templates/marketing/thumbs/cta-luxury.jpg?v=0a1b2c3d 320w");
+ expect(h).not.toContain("<video");
+ expect(h).not.toContain("<svg viewBox=\"0 0 240 320\"");
+ expect(unversioned(h)).toEqual([]);
+ const drawn = tile("simple-ugc");
+ expect(drawn).toContain('<svg viewBox="0 0 240 320"');
+ expect(drawn).not.toContain("<img");
+ });
+});
+
describe("Fashion Factory's templates", () => {
it("show the cover's slides in the carousel (the first one only, until picked), else the drawn framings", () => {
const h = html(FashionPreview, { t: by(FASHION, "ultra-bold") });
diff --git a/tests/template-covers.test.ts b/tests/template-covers.test.ts
index 0d67ea2f..477b8239 100644
--- a/tests/template-covers.test.ts
+++ b/tests/template-covers.test.ts
@@ -8,7 +8,7 @@ import { afterAll, describe, expect, it } from "vitest";
import { CANVAS_TEMPLATES } from "@/lib/catalog/canvas";
import { PRESETS } from "@/lib/catalog/content-factory";
import { EXPLAINER_STYLE_IDS } from "@/lib/catalog/faceless";
-import { TEMPLATES } from "@/lib/catalog/marketing";
+import { AD_STYLES, TEMPLATES } from "@/lib/catalog/marketing";
import { MIXED_PRESETS } from "@/lib/catalog/mixed-media";
import { FASHION, PACKS } from "@/lib/catalog/packs";
import { SHORTS_PRESETS } from "@/lib/catalog/shorts";
@@ -37,7 +37,8 @@ const gen = (await import("../scripts/eval/lib/template-covers.mjs")) as unknown
const root = process.cwd();
/** Every tile of each group, by id: what the manifest's keys may name. */
const TILES: Record<TemplateGroup, string[]> = {
- marketing: TEMPLATES.map((t) => t.id),
+ // Marketing's templates, and Click to Ad's styles as cta-<style>.
+ marketing: [...TEMPLATES.map((t) => t.id), ...AD_STYLES.map((s) => `cta-${s.id}`)],
fashion: FASHION.map((t) => t.id),
photodump: PACKS.map((p) => p.id),
shorts: SHORTS_PRESETS.map((p) => p.id),
@@ -79,6 +80,20 @@ describe("the template covers manifest", () => {
}
});
+ it("leaves no file in public/previews/templates that no entry names (with each still's small copy)", () => {
+ const named = new Set<string>();
+ for (const key of Object.keys(TEMPLATE_COVERS)) {
+ const [group, id] = key.split("/") as [TemplateGroup, string];
+ const c = templateCover(group, id)!;
+ for (const f of c.frames) for (const u of [f.src, f.thumb]) named.add(u.split("?")[0]);
+ if (c.video) named.add(c.video.split("?")[0]);
+ }
+ const dir = path.join(root, "public", "previews", "templates");
+ const files = fs.existsSync(dir) ? fs.readdirSync(dir, { recursive: true, encoding: "utf8" }).filter((f) => /.(jpg|mp4)$/.test(f)) : [];
+ const orphans = files.map((f) => `/previews/templates/${f.replaceAll("\\", "/")}`).filter((u) => !named.has(u));
+ expect(orphans).toEqual([]);
+ });
+
it("stays small with every tile listed: it ships with the studios' pages", () => {
const pick = <T,>(list: T[], i: number) => list[i % list.length];
// A tile that shows a preset's cover rests on its peak frame where it has one (the longer entry).
@@ -104,7 +119,7 @@ describe("the template covers manifest", () => {
lines.push(` ${JSON.stringify(key)}: ${JSON.stringify(gen.slimEntry(key, { poster: e.poster, ...(e.video && { video: e.video }), ...(e.at && { at: e.at }), ...(e.frames && { frames: e.frames }) }))}`);
}
}
- expect(lines).toHaveLength(229);
+ expect(lines).toHaveLength(239);
const text = `{\n${lines.join(",\n")}\n}`;
expect(text.length).toBeLessThan(36_000);
expect(gzipSync(text).length).toBeLessThan(8_000);