Skip to content

end to end app store screenshot creation using AI

fix: font menu offers only real fonts, undo skips navigation, tidy toolbar

Parth Jadhavbee50b7b220f
diff --git a/skills/app-store-screenshots/template/src/app/globals.css b/skills/app-store-screenshots/template/src/app/globals.css
index c98257c..06e9603 100644
--- a/skills/app-store-screenshots/template/src/app/globals.css
+++ b/skills/app-store-screenshots/template/src/app/globals.css
@@ -2,16 +2,6 @@
@tailwind components;
@tailwind utilities;
-@font-face {
- font-family: "CustomScreenshotFont";
- src:
- url("/fonts/imported/custom-screenshot-font.woff2") format("woff2"),
- url("/fonts/imported/custom-screenshot-font.woff") format("woff"),
- url("/fonts/imported/custom-screenshot-font.ttf") format("truetype"),
- url("/fonts/imported/custom-screenshot-font.otf") format("opentype");
- font-display: swap;
-}
-
@layer base {
:root {
--background: 240 14% 99%;
diff --git a/skills/app-store-screenshots/template/src/components/editor/font-importer.tsx b/skills/app-store-screenshots/template/src/components/editor/font-importer.tsx
index c992721..ad9d2ee 100644
--- a/skills/app-store-screenshots/template/src/components/editor/font-importer.tsx
+++ b/skills/app-store-screenshots/template/src/components/editor/font-importer.tsx
@@ -1,13 +1,14 @@
"use client";
import * as React from "react";
-import { Upload } from "lucide-react";
-import { Button } from "@/components/ui/button";
+import { toast } from "sonner";
+import { cleanFontName } from "@/lib/clean-imported-font";
import type { ImportedFont } from "@/lib/types";
+export type FontImporterHandle = { open: () => void };
+
type Props = {
- disabled: boolean;
- importedFont?: ImportedFont;
onImported: (font: ImportedFont) => void;
+ onUploadingChange?: (uploading: boolean) => void;
};
const MAX_FONT_BYTES = 16 * 1024 * 1024;
@@ -22,14 +23,18 @@ async function fileToBase64(file: File): Promise<string> {
return dataUrl.slice(dataUrl.indexOf(",") + 1);
}
-export function FontImporter({ disabled, importedFont, onImported }: Props) {
+// Hidden file input behind the toolbar's "Import font…" menu item. The server
+// validates the file by its magic bytes and stores it under
+// public/fonts/imported/<hash>.<ext>.
+export const FontImporter = React.forwardRef<FontImporterHandle, Props>(function FontImporter(
+ { onImported, onUploadingChange },
+ ref,
+) {
const inputRef = React.useRef<HTMLInputElement>(null);
- const [uploading, setUploading] = React.useState(false);
- const [error, setError] = React.useState<string | null>(null);
+ React.useImperativeHandle(ref, () => ({ open: () => inputRef.current?.click() }), []);
async function importFont(file: File) {
- setUploading(true);
- setError(null);
+ onUploadingChange?.(true);
try {
if (file.size > MAX_FONT_BYTES) throw new Error("Font file is too large (16MB maximum).");
const response = await fetch("/api/upload-font", {
@@ -37,42 +42,37 @@ export function FontImporter({ disabled, importedFont, onImported }: Props) {
headers: { "content-type": "application/json" },
body: JSON.stringify({ data: await fileToBase64(file) }),
});
- const data = (await response.json()) as { ok: boolean; error?: string; font?: ImportedFont };
+ const data = (await response.json().catch(() => ({ ok: false }))) as {
+ ok: boolean;
+ error?: string;
+ font?: ImportedFont;
+ };
if (!data.ok || !data.font) throw new Error(data.error || "Could not import that font.");
- onImported(data.font);
+ const name = cleanFontName(file.name.replace(/\.[^.]+$/, ""));
+ onImported({ ...data.font, ...(name ? { name } : {}) });
+ toast.success(`Imported ${name ?? "font"}`);
} catch (caught) {
- setError(caught instanceof Error ? caught.message : "Could not import that font.");
+ toast.error("Font import failed", {
+ description: caught instanceof Error ? caught.message : "Could not import that font.",
+ });
} finally {
- setUploading(false);
+ onUploadingChange?.(false);
}
}
return (
- <span className="flex items-center gap-1.5">
- <input
- ref={inputRef}
- type="file"
- accept=".woff2,.woff,.ttf,.otf,font/woff2,font/woff,font/ttf,font/otf"
- className="sr-only"
- onChange={(event) => {
- const file = event.target.files?.[0];
- if (file) void importFont(file);
- event.target.value = "";
- }}
- />
- <Button
- type="button"
- variant="ghost"
- size="sm"
- className="h-8 gap-1 px-2 text-xs"
- disabled={disabled || uploading}
- onClick={() => inputRef.current?.click()}
- title="Import a WOFF2, WOFF, TTF, or OTF font"
- >
- <Upload className="h-3.5 w-3.5" />
- {uploading ? "Importing" : importedFont ? "Replace font" : "Import font"}
- </Button>
- {error && <span className="max-w-32 truncate text-[10px] text-destructive" title={error}>{error}</span>}
- </span>
+ <input
+ ref={inputRef}
+ type="file"
+ accept=".woff2,.woff,.ttf,.otf,font/woff2,font/woff,font/ttf,font/otf"
+ className="sr-only"
+ tabIndex={-1}
+ aria-hidden
+ onChange={(event) => {
+ const file = event.target.files?.[0];
+ if (file) void importFont(file);
+ event.target.value = "";
+ }}
+ />
);
-}
+});
diff --git a/skills/app-store-screenshots/template/src/components/editor/preview-stage.tsx b/skills/app-store-screenshots/template/src/components/editor/preview-stage.tsx
index ecfcdda..2aaf5a4 100644
--- a/skills/app-store-screenshots/template/src/components/editor/preview-stage.tsx
+++ b/skills/app-store-screenshots/template/src/components/editor/preview-stage.tsx
@@ -24,7 +24,6 @@ type Props = {
appName?: string;
appIcon?: string;
fontFamily: string;
- fontFaceCss?: string;
connectedCanvas: boolean;
selectedElement: SelectedElement | null;
onActiveSlideChange: (id: string) => void;
@@ -47,7 +46,6 @@ export function PreviewStage({
appName,
appIcon,
fontFamily,
- fontFaceCss,
connectedCanvas,
selectedElement,
onActiveSlideChange,
@@ -143,7 +141,6 @@ export function PreviewStage({
appName={appName}
appIcon={appIcon}
fontFamily={fontFamily}
- fontFaceCss={fontFaceCss}
connectedCanvas={connectedCanvas}
editable
previewScale={scale}
diff --git a/skills/app-store-screenshots/template/src/components/editor/screenshot-editor.tsx b/skills/app-store-screenshots/template/src/components/editor/screenshot-editor.tsx
index 0a1200a..3bbd62e 100644
--- a/skills/app-store-screenshots/template/src/components/editor/screenshot-editor.tsx
+++ b/skills/app-store-screenshots/template/src/components/editor/screenshot-editor.tsx
@@ -6,6 +6,7 @@ import {
DEFAULT_SCREENSHOT_FONT_ID,
getExportSizes,
hasTheme,
+ IMPORTED_FONT_FAMILY,
SCREENSHOT_FONTS,
supportsLandscape,
themeById,
@@ -22,6 +23,7 @@ import type {
ElementId,
ElementTransform,
ImageElement,
+ ImportedFont,
SelectedElement,
Slide,
} from "@/lib/types";
@@ -45,12 +47,9 @@ export function ScreenshotEditor() {
const activeSlide =
currentSlides.find((s) => s.id === activeSlideId) || currentSlides[0] || null;
const theme = themeById(state.themeId);
- const fontFamily = state.fontId === "self-hosted" && state.importedFont
- ? '"ImportedScreenshotFont", Georgia, serif'
- : SCREENSHOT_FONTS[state.fontId || DEFAULT_SCREENSHOT_FONT_ID].family;
- const fontFaceCss = state.importedFont
- ? `@font-face { font-family: "ImportedScreenshotFont"; src: url("${state.importedFont.src}") format("${state.importedFont.format}"); font-display: swap; }`
- : undefined;
+ const fontId = state.fontId || DEFAULT_SCREENSHOT_FONT_ID;
+ const fontFamily = SCREENSHOT_FONTS[fontId].family;
+ useImportedFontFace(state.importedFont);
React.useEffect(() => {
if (selectedElement && selectedElement.slideId !== activeSlide?.id) {
@@ -67,7 +66,7 @@ export function ScreenshotEditor() {
React.useEffect(() => {
if (!supportsLandscape(state.device) && state.orientation !== "portrait") {
- setState((p) => ({ ...p, orientation: "portrait" }));
+ setState((p) => ({ ...p, orientation: "portrait" }), { history: false });
}
}, [state.device, state.orientation, setState]);
@@ -338,11 +337,9 @@ export function ScreenshotEditor() {
React.useEffect(() => {
function onKey(e: KeyboardEvent) {
const target = e.target as HTMLElement | null;
- const inEditable =
- target &&
- (target.tagName === "INPUT" ||
- target.tagName === "TEXTAREA" ||
- (target as HTMLElement).isContentEditable);
+ const inTextField = isTextEditable(target);
+ const inControl =
+ inTextField || (!!target && (target.tagName === "INPUT" || target.tagName === "SELECT"));
if (exporting) return;
if (e.key === "Escape") {
@@ -351,21 +348,19 @@ export function ScreenshotEditor() {
return;
}
- // Let focused inputs and contenteditable text keep their native undo,
- // redo, selection, and deletion behavior.
- if (inEditable) return;
-
- if ((e.metaKey || e.ctrlKey) && (e.key === "z" || e.key === "Z")) {
+ // Undo/redo belongs to the text field while one is focused.
+ const mod = e.metaKey || e.ctrlKey;
+ if (mod && !e.altKey && (e.key === "z" || e.key === "Z" || e.key === "y" || e.key === "Y")) {
+ if (inTextField) return;
e.preventDefault();
- if (e.shiftKey) redo();
+ if (e.key === "y" || e.key === "Y" || e.shiftKey) redo();
else undo();
return;
}
- if ((e.metaKey || e.ctrlKey) && (e.key === "y" || e.key === "Y")) {
- e.preventDefault();
- redo();
- return;
- }
+
+ // Arrow keys, deletion etc. keep their native meaning inside any input.
+ if (inControl) return;
+
if (!currentSlides.length) return;
const idx = activeSlide ? currentSlides.findIndex((s) => s.id === activeSlide.id) : -1;
if (e.key === "ArrowDown" || (e.key === "j" && !e.metaKey && !e.ctrlKey)) {
@@ -450,7 +445,7 @@ export function ScreenshotEditor() {
try {
// fonts.ready only covers faces already requested; explicitly load an
// imported font so a not-yet-used face can't export as the fallback.
- if (state.fontId === "self-hosted") await document.fonts.load(`64px ${fontFamily}`);
+ if (fontId === "self-hosted") await document.fonts.load(`64px ${fontFamily}`);
await document.fonts.ready;
} catch {
/* ignore */
@@ -604,17 +599,17 @@ export function ScreenshotEditor() {
setThemeId={(v) => setState((p) => ({ ...p, themeId: v }))}
connectedCanvas={state.connectedCanvas}
setConnectedCanvas={(v) => setState((p) => ({ ...p, connectedCanvas: v }))}
- fontId={state.fontId || DEFAULT_SCREENSHOT_FONT_ID}
+ fontId={fontId}
setFontId={(v) => setState((p) => ({ ...p, fontId: v }))}
importedFont={state.importedFont}
setImportedFont={(importedFont) => setState((p) => ({ ...p, fontId: "self-hosted", importedFont }))}
locale={state.locale}
- setLocale={(v) => setState((p) => ({ ...p, locale: v }))}
+ setLocale={(v) => setState((p) => ({ ...p, locale: v }), { history: false })}
locales={state.locales}
device={state.device}
- setDevice={(v) => setState((p) => ({ ...p, device: v }))}
+ setDevice={(v) => setState((p) => ({ ...p, device: v }), { history: false })}
orientation={state.orientation}
- setOrientation={(v) => setState((p) => ({ ...p, orientation: v }))}
+ setOrientation={(v) => setState((p) => ({ ...p, orientation: v }), { history: false })}
onExport={exportAll}
onResetAll={() => {
reset();
@@ -647,6 +642,7 @@ export function ScreenshotEditor() {
locale={state.locale}
appName={state.appName}
appIcon={state.appIcon}
+ fontFamily={fontFamily}
connectedCanvas={state.connectedCanvas}
disabled={busy}
onReorder={reorderSlides}
@@ -669,7 +665,6 @@ export function ScreenshotEditor() {
appName={state.appName}
appIcon={state.appIcon}
fontFamily={fontFamily}
- fontFaceCss={fontFaceCss}
connectedCanvas={state.connectedCanvas}
selectedElement={selectedElement}
onActiveSlideChange={setActiveSlideId}
@@ -755,7 +750,6 @@ export function ScreenshotEditor() {
appName={state.appName}
appIcon={state.appIcon}
fontFamily={fontFamily}
- fontFaceCss={fontFaceCss}
connectedCanvas={state.connectedCanvas}
hideEmpty
/>
@@ -767,6 +761,32 @@ export function ScreenshotEditor() {
);
}
+// Text fields and contenteditable text keep their native undo/redo, selection,
+// and deletion. Sliders, colour pickers, checkboxes and buttons have no text
+// history of their own, so the editor's shortcuts still apply while they're focused.
+const NON_TEXT_INPUT_TYPES = new Set(["range", "color", "checkbox", "radio", "button", "submit", "reset", "file"]);
+
+function isTextEditable(target: HTMLElement | null) {
+ if (!target) return false;
+ if (target.isContentEditable || target.tagName === "TEXTAREA" || target.tagName === "SELECT") return true;
+ if (target.tagName === "INPUT") return !NON_TEXT_INPUT_TYPES.has((target as HTMLInputElement).type);
+ return false;
+}
+
+// Registers the imported font in <head>, not inside the canvases: html-to-image
+// embeds @font-face rules it finds in document.styleSheets, while a <style>
+// cloned into the export SVG would point at a URL the SVG image can't load.
+function useImportedFontFace(font: ImportedFont | undefined) {
+ React.useEffect(() => {
+ if (!font) return;
+ const style = document.createElement("style");
+ style.dataset.importedScreenshotFont = "";
+ style.textContent = `@font-face { font-family: "${IMPORTED_FONT_FAMILY}"; src: url("${font.src}") format("${font.format}"); font-display: block; }`;
+ document.head.appendChild(style);
+ return () => style.remove();
+ }, [font?.src, font?.format]);
+}
+
function slugify(s: string) {
return (
s
diff --git a/skills/app-store-screenshots/template/src/components/editor/sidebar.tsx b/skills/app-store-screenshots/template/src/components/editor/sidebar.tsx
index fee5bbd..4214b4e 100644
--- a/skills/app-store-screenshots/template/src/components/editor/sidebar.tsx
+++ b/skills/app-store-screenshots/template/src/components/editor/sidebar.tsx
@@ -30,6 +30,7 @@ type Props = {
locale: string;
appName?: string;
appIcon?: string;
+ fontFamily?: string;
connectedCanvas: boolean;
disabled?: boolean;
onReorder: (next: Slide[]) => void;
@@ -48,6 +49,7 @@ export function Sidebar({
locale,
appName,
appIcon,
+ fontFamily,
connectedCanvas,
disabled,
onReorder,
@@ -96,6 +98,7 @@ export function Sidebar({
locale={locale}
appName={appName}
appIcon={appIcon}
+ fontFamily={fontFamily}
connectedCanvas={connectedCanvas}
onSelect={() => onSelect(slide.id)}
onDelete={() => onDelete(slide.id)}
diff --git a/skills/app-store-screenshots/template/src/components/editor/slide-canvas.tsx b/skills/app-store-screenshots/template/src/components/editor/slide-canvas.tsx
index a2ff4c9..8746ec8 100644
--- a/skills/app-store-screenshots/template/src/components/editor/slide-canvas.tsx
+++ b/skills/app-store-screenshots/template/src/components/editor/slide-canvas.tsx
@@ -129,7 +129,6 @@ type Props = {
appName?: string;
appIcon?: string;
fontFamily?: string;
- fontFaceCss?: string;
editable?: boolean;
edit?: EditHandlers;
selectedElementId?: ElementId | null;
@@ -158,7 +157,6 @@ type DeckCanvasProps = {
appName?: string;
appIcon?: string;
fontFamily?: string;
- fontFaceCss?: string;
connectedCanvas?: boolean;
editable?: boolean;
edit?: DeckEditHandlers;
@@ -559,7 +557,6 @@ export function SlideCanvas({
appName,
appIcon,
fontFamily,
- fontFaceCss,
editable,
edit,
selectedElementId = null,
@@ -570,16 +567,18 @@ export function SlideCanvas({
if (slide.layout === "feature-graphic" || device === "feature-graphic") {
return (
- <FeatureGraphicCanvas
- slide={slide}
- cW={cW}
- theme={theme}
- locale={locale}
- appName={appName}
- appIcon={appIcon}
- editable={editable}
- edit={edit}
- />
+ <div style={{ width: "100%", height: "100%", fontFamily }}>
+ <FeatureGraphicCanvas
+ slide={slide}
+ cW={cW}
+ theme={theme}
+ locale={locale}
+ appName={appName}
+ appIcon={appIcon}
+ editable={editable}
+ edit={edit}
+ />
+ </div>
);
}
@@ -600,7 +599,6 @@ export function SlideCanvas({
fontFamily,
}}
>
- {fontFaceCss && <style>{fontFaceCss}</style>}
<SlideBackground slide={slide} cW={cW} cH={cH} theme={theme} />
<SlideElements
slide={slide}
@@ -633,7 +631,6 @@ export function DeckCanvas({
appName,
appIcon,
fontFamily,
- fontFaceCss,
connectedCanvas = true,
editable,
edit,
@@ -656,7 +653,6 @@ export function DeckCanvas({
fontFamily,
}}
>
- {fontFaceCss && <style>{fontFaceCss}</style>}
{slides.map((slide, index) => {
const screenX = index * cW;
const active = activeSlideId === slide.id;
diff --git a/skills/app-store-screenshots/template/src/components/editor/slide-thumb.tsx b/skills/app-store-screenshots/template/src/components/editor/slide-thumb.tsx
index 8b88ed9..87db666 100644
--- a/skills/app-store-screenshots/template/src/components/editor/slide-thumb.tsx
+++ b/skills/app-store-screenshots/template/src/components/editor/slide-thumb.tsx
@@ -21,6 +21,7 @@ type Props = {
locale: string;
appName?: string;
appIcon?: string;
+ fontFamily?: string;
connectedCanvas: boolean;
onSelect: () => void;
onDelete: () => void;
@@ -41,6 +42,7 @@ export function SlideThumb({
locale,
appName,
appIcon,
+ fontFamily,
connectedCanvas,
onSelect,
onDelete,
@@ -116,6 +118,7 @@ export function SlideThumb({
locale={locale}
appName={appName}
appIcon={appIcon}
+ fontFamily={fontFamily}
connectedCanvas
editable={false}
/>
@@ -128,6 +131,7 @@ export function SlideThumb({
locale={locale}
appName={appName}
appIcon={appIcon}
+ fontFamily={fontFamily}
editable={false}
/>
)}
diff --git a/skills/app-store-screenshots/template/src/components/editor/toolbar.tsx b/skills/app-store-screenshots/template/src/components/editor/toolbar.tsx
index 68848f9..f535220 100644
--- a/skills/app-store-screenshots/template/src/components/editor/toolbar.tsx
+++ b/skills/app-store-screenshots/template/src/components/editor/toolbar.tsx
@@ -1,6 +1,6 @@
"use client";
import * as React from "react";
-import { AlertTriangle, Check, Cloud, Download, Redo2, RotateCcw, Undo2, UnfoldHorizontal } from "lucide-react";
+import { AlertTriangle, Check, Cloud, Download, Redo2, RotateCcw, Undo2, UnfoldHorizontal, Upload } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
Dialog,
@@ -14,12 +14,14 @@ import {
Select,
SelectContent,
SelectItem,
+ SelectSeparator,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
import {
DEVICE_LABEL,
+ IMPORTED_FONT_FAMILY,
PLATFORM_DEVICES,
SCREENSHOT_FONTS,
THEMES,
@@ -28,7 +30,9 @@ import {
} from "@/lib/constants";
import { detectPlatform } from "@/lib/defaults";
import type { Device, ImportedFont, Orientation, Platform, ScreenshotFontId, Theme } from "@/lib/types";
-import { FontImporter } from "./font-importer";
+import { FontImporter, type FontImporterHandle } from "./font-importer";
+
+const IMPORT_FONT_ACTION = "__import-font__";
type Props = {
appName: string;
@@ -82,12 +86,23 @@ export function Toolbar(props: Props) {
const platformDevices = PLATFORM_DEVICES[platform];
const activeTheme = themeById(props.themeId);
+ const fontImporter = React.useRef<FontImporterHandle>(null);
+ const [importingFont, setImportingFont] = React.useState(false);
+ // "Imported font" is only a choice once a file has actually been imported.
+ const fontIds = (Object.keys(SCREENSHOT_FONTS) as ScreenshotFontId[]).filter(
+ (id) => id !== "self-hosted" || !!props.importedFont,
+ );
+ const fontLabel = (id: ScreenshotFontId) =>
+ id === "self-hosted" && props.importedFont?.name ? props.importedFont.name : SCREENSHOT_FONTS[id].name;
+ const fontPreviewFamily = (id: ScreenshotFontId) =>
+ id === "self-hosted" ? `"${IMPORTED_FONT_FAMILY}", sans-serif` : SCREENSHOT_FONTS[id].family;
+
return (
<div className="flex flex-wrap items-center gap-x-2 gap-y-1.5 border-b bg-card/40 px-4 py-2">
<Input
value={props.appName}
onChange={(e) => props.setAppName(e.target.value)}
- className="h-8 w-40 border-dashed text-sm font-semibold focus-visible:border-input focus-visible:border-solid focus-visible:bg-background"
+ className="h-8 w-36 border-dashed text-sm font-semibold focus-visible:border-input focus-visible:border-solid focus-visible:bg-background"
placeholder="App name"
aria-label="App name"
title="App name (click to edit)"
@@ -115,7 +130,7 @@ export function Toolbar(props: Props) {
</Button>
<Select value={activeTheme.id} onValueChange={props.setThemeId} disabled={props.busy}>
- <SelectTrigger className="h-8 w-48 text-xs" title="Theme" aria-label="Theme">
+ <SelectTrigger className="h-8 w-40 text-xs" title="Theme" aria-label="Theme">
<SelectValue>
<ThemeOption theme={activeTheme} />
</SelectValue>
@@ -129,19 +144,35 @@ export function Toolbar(props: Props) {
</SelectContent>
</Select>
- <Select value={props.fontId} onValueChange={(fontId) => props.setFontId(fontId as ScreenshotFontId)} disabled={props.busy}>
- <SelectTrigger className="h-8 w-44 text-xs" aria-label="Screenshot font">
- <SelectValue placeholder="Font" />
+ <Select
+ value={props.fontId}
+ onValueChange={(fontId) => {
+ if (fontId === IMPORT_FONT_ACTION) fontImporter.current?.open();
+ else props.setFontId(fontId as ScreenshotFontId);
+ }}
+ disabled={props.busy || importingFont}
+ >
+ <SelectTrigger className="h-8 w-36 text-xs" title="Screenshot font" aria-label="Screenshot font">
+ <SelectValue placeholder="Font">
+ <span className="truncate">{importingFont ? "Importing font…" : fontLabel(props.fontId)}</span>
+ </SelectValue>
</SelectTrigger>
<SelectContent>
- {Object.entries(SCREENSHOT_FONTS).map(([id, font]) => (
- <SelectItem key={id} value={id}>{font.name}</SelectItem>
+ {fontIds.map((id) => (
+ <SelectItem key={id} value={id}>
+ <span style={{ fontFamily: fontPreviewFamily(id) }}>{fontLabel(id)}</span>
+ </SelectItem>
))}
+ <SelectSeparator />
+ <SelectItem value={IMPORT_FONT_ACTION}>
+ <span className="flex items-center gap-1.5">
+ <Upload className="h-3.5 w-3.5" />
+ {props.importedFont ? "Replace imported font…" : "Import font…"}
+ </span>
+ </SelectItem>
</SelectContent>
</Select>
- {props.fontId === "self-hosted" && (
- <FontImporter disabled={props.busy} importedFont={props.importedFont} onImported={props.setImportedFont} />
- )}
+ <FontImporter ref={fontImporter} onImported={props.setImportedFont} onUploadingChange={setImportingFont} />
<span aria-hidden className="mx-1 h-5 w-px bg-border" />
@@ -173,7 +204,7 @@ export function Toolbar(props: Props) {
onValueChange={(v) => props.setDevice(v as Device)}
disabled={props.busy}
>
- <SelectTrigger className="h-8 w-44 text-xs">
+ <SelectTrigger className="h-8 w-36 text-xs" aria-label="Device" title="Device">
<SelectValue placeholder="Device">{deviceLabel}</SelectValue>
</SelectTrigger>
<SelectContent>
@@ -190,7 +221,7 @@ export function Toolbar(props: Props) {
onValueChange={(v) => props.setOrientation(v as Orientation)}
disabled={props.busy}
>
- <SelectTrigger className="h-8 w-32 text-xs">
+ <SelectTrigger className="h-8 w-28 text-xs" aria-label="Orientation">
<SelectValue />
</SelectTrigger>
<SelectContent>
@@ -202,7 +233,7 @@ export function Toolbar(props: Props) {
{showLocale && (
<Select value={props.locale} onValueChange={props.setLocale} disabled={props.busy}>
- <SelectTrigger className="h-8 w-20 text-xs">
+ <SelectTrigger className="h-8 w-20 text-xs" aria-label="Locale">
<SelectValue />
</SelectTrigger>
<SelectContent>
@@ -340,8 +371,8 @@ function SaveStatus({ savedAt, saveError }: { savedAt: number | null; saveError:
if (!savedAt) {
return (
- <span className="flex items-center gap-1 text-xs text-muted-foreground">
- <Cloud className="h-3.5 w-3.5" /> not saved yet
+ <span className="flex items-center gap-1 text-xs text-muted-foreground" title="Not saved yet">
+ <Cloud className="h-3.5 w-3.5" /> <span className="hidden 2xl:inline">not saved yet</span>
</span>
);
}
@@ -355,8 +386,8 @@ function SaveStatus({ savedAt, saveError }: { savedAt: number | null; saveError:
? `saved ${Math.round(seconds / 60)}m ago`
: `saved ${Math.round(seconds / 3600)}h ago`;
return (
- <span className="flex items-center gap-1 text-xs text-muted-foreground">
- <Check className="h-3.5 w-3.5 text-green-500" /> {label}
+ <span className="flex items-center gap-1 text-xs text-muted-foreground" title={`Project ${label}`}>
+ <Check className="h-3.5 w-3.5 text-green-500" /> <span className="hidden 2xl:inline">{label}</span>
</span>
);
}
diff --git a/skills/app-store-screenshots/template/src/components/ui/select.tsx b/skills/app-store-screenshots/template/src/components/ui/select.tsx
index b1811eb..180208e 100644
--- a/skills/app-store-screenshots/template/src/components/ui/select.tsx
+++ b/skills/app-store-screenshots/template/src/components/ui/select.tsx
@@ -80,4 +80,12 @@ const SelectItem = React.forwardRef<
));
SelectItem.displayName = SelectPrimitive.Item.displayName;
-export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectItem };
+const SelectSeparator = React.forwardRef<
+ React.ElementRef<typeof SelectPrimitive.Separator>,
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
+>(({ className, ...props }, ref) => (
+ <SelectPrimitive.Separator ref={ref} className={cn("-mx-1 my-1 h-px bg-muted", className)} {...props} />
+));
+SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
+
+export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectItem, SelectSeparator };
diff --git a/skills/app-store-screenshots/template/src/lib/clean-imported-font.ts b/skills/app-store-screenshots/template/src/lib/clean-imported-font.ts
index 08cb951..85e1430 100644
--- a/skills/app-store-screenshots/template/src/lib/clean-imported-font.ts
+++ b/skills/app-store-screenshots/template/src/lib/clean-imported-font.ts
@@ -1,10 +1,19 @@
import type { ImportedFont } from "./types";
+const FORMATS = ["woff2", "woff", "truetype", "opentype"] as const;
+
+// Display names come from the uploaded file name; keep them short and printable.
+export function cleanFontName(value: unknown): string | undefined {
+ if (typeof value !== "string") return undefined;
+ const name = value.replace(/[\u0000-\u001f\u007f]/g, "").replace(/\s+/g, " ").trim().slice(0, 60);
+ return name || undefined;
+}
+
export function cleanImportedFont(value: unknown): ImportedFont | undefined {
if (!value || typeof value !== "object") return undefined;
const font = value as Partial<ImportedFont>;
- const formats = ["woff2", "woff", "truetype", "opentype"] as const;
if (typeof font.src !== "string" || !/^\/fonts\/imported\/[a-z0-9]+\.(woff2|woff|ttf|otf)$/i.test(font.src)) return undefined;
- if (!formats.includes(font.format as ImportedFont["format"])) return undefined;
- return { src: font.src, format: font.format as ImportedFont["format"] };
+ if (!FORMATS.includes(font.format as ImportedFont["format"])) return undefined;
+ const name = cleanFontName(font.name);
+ return { src: font.src, format: font.format as ImportedFont["format"], ...(name ? { name } : {}) };
}
diff --git a/skills/app-store-screenshots/template/src/lib/constants.ts b/skills/app-store-screenshots/template/src/lib/constants.ts
index e4a4341..108a502 100644
--- a/skills/app-store-screenshots/template/src/lib/constants.ts
+++ b/skills/app-store-screenshots/template/src/lib/constants.ts
@@ -162,36 +162,31 @@ export const DEFAULT_THEME_ID: ThemeId = "clean-light";
export const DEFAULT_SCREENSHOT_FONT_ID: ScreenshotFontId = "template-default";
+// Family used for a font imported through the toolbar. The matching @font-face
+// is injected into <head> by the editor (see screenshot-editor.tsx), so it sits
+// in document.styleSheets where html-to-image can embed it into exports.
+export const IMPORTED_FONT_FAMILY = "ImportedScreenshotFont";
+
export const SCREENSHOT_FONTS: Record<ScreenshotFontId, { name: string; family: string }> = {
// Inherit the editor's Inter (next/font in app/layout.tsx), which is what the
// canvas rendered before fonts were selectable, so existing decks don't shift.
- "template-default": {
- name: "Inter (default)",
- family: "inherit",
- },
- "template-serif": {
- name: "Editorial Serif",
- family: "Georgia, 'Times New Roman', serif",
- },
+ "template-default": { name: "Inter (default)", family: "inherit" },
"system-sans": {
- name: "Modern Sans",
- family: "ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif",
- },
- "classic-serif": {
- name: "Classic Serif",
- family: "Georgia, 'Times New Roman', serif",
+ name: "System Sans",
+ family: 'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
},
+ "template-serif": { name: "Georgia", family: "Georgia, 'Times New Roman', serif" },
+ // Named system fonts ship with macOS; elsewhere they fall back to the listed
+ // alternatives, so export on the machine whose fonts you designed with.
"avenir-next": { name: "Avenir Next", family: '"Avenir Next", Avenir, sans-serif' },
"helvetica-neue": { name: "Helvetica Neue", family: '"Helvetica Neue", Helvetica, Arial, sans-serif' },
- "american-typewriter": { name: "American Typewriter", family: '"American Typewriter", Georgia, serif' },
- "baskerville": { name: "Baskerville", family: "Baskerville, Georgia, serif" },
- "optima": { name: "Optima", family: "Optima, 'Palatino Linotype', serif" },
- "palatino": { name: "Palatino", family: "Palatino, 'Palatino Linotype', serif" },
"futura": { name: "Futura", family: "Futura, 'Trebuchet MS', sans-serif" },
- "self-hosted": {
- name: "Import a font",
- family: '"CustomScreenshotFont", Georgia, serif',
- },
+ "baskerville": { name: "Baskerville", family: "Baskerville, 'Baskerville Old Face', Georgia, serif" },
+ "palatino": { name: "Palatino", family: "Palatino, 'Palatino Linotype', 'Book Antiqua', serif" },
+ "optima": { name: "Optima", family: "Optima, Candara, 'Segoe UI', sans-serif" },
+ "american-typewriter": { name: "American Typewriter", family: '"American Typewriter", "Courier New", serif' },
+ // Only offered once a font has been imported; the name shown comes from the file.
+ "self-hosted": { name: "Imported font", family: `"${IMPORTED_FONT_FAMILY}", sans-serif` },
};
export const THEMES: Record<string, Theme> = {
diff --git a/skills/app-store-screenshots/template/src/lib/storage.ts b/skills/app-store-screenshots/template/src/lib/storage.ts
index b13995a..c7b1e95 100644
--- a/skills/app-store-screenshots/template/src/lib/storage.ts
+++ b/skills/app-store-screenshots/template/src/lib/storage.ts
@@ -6,9 +6,9 @@ import { cleanImportedFont } from "./clean-imported-font";
import { DEFAULT_PROJECT } from "./defaults";
import { coerceLocalized } from "./locale";
import { cleanTypography } from "./typography";
-import type { Device, ElementTransform, ImageElement, ProjectState, Slide, TextElement } from "./types";
+import type { Device, ElementTransform, ImageElement, ProjectState, ScreenshotFontId, Slide, TextElement } from "./types";
-const HISTORY_LIMIT = 25;
+const HISTORY_LIMIT = 50;
// Coalesce rapid edits (typing, slider drags) into a single undo step.
const COALESCE_MS = 500;
// Debounce file/localStorage writes — frequent enough to feel instant, infrequent enough not to thrash disk.
@@ -82,6 +82,18 @@ function cleanImageElement(value: unknown): ImageElement | undefined {
};
}
+// Early builds had a "Classic Serif" that rendered exactly like Georgia.
+const LEGACY_FONT_IDS: Record<string, ScreenshotFontId> = { "classic-serif": "template-serif" };
+
+function cleanFontId(value: unknown, hasImportedFont: boolean): ScreenshotFontId {
+ if (typeof value !== "string") return DEFAULT_SCREENSHOT_FONT_ID;
+ const id = LEGACY_FONT_IDS[value] ?? value;
+ if (!Object.prototype.hasOwnProperty.call(SCREENSHOT_FONTS, id)) return DEFAULT_SCREENSHOT_FONT_ID;
+ // "Imported font" without a file behind it would render the fallback.
+ if (id === "self-hosted" && !hasImportedFont) return DEFAULT_SCREENSHOT_FONT_ID;
+ return id as ScreenshotFontId;
+}
+
// Migrate older projects into the current schema while keeping legacy decks
// visually stable until they explicitly opt into connected canvas.
function migrateSlide(slide: Slide): Slide {
@@ -121,11 +133,8 @@ function mergeWithDefaults(parsed: Partial<ProjectState>): ProjectState {
typeof parsed.themeId === "string" && parsed.themeId.trim()
? parsed.themeId
: DEFAULT_PROJECT.themeId;
- const fontId =
- typeof parsed.fontId === "string" && Object.prototype.hasOwnProperty.call(SCREENSHOT_FONTS, parsed.fontId)
- ? parsed.fontId
- : DEFAULT_SCREENSHOT_FONT_ID;
const importedFont = cleanImportedFont(parsed.importedFont);
+ const fontId = cleanFontId(parsed.fontId, !!importedFont);
const slidesByDevice = parsed.slidesByDevice
? Object.fromEntries(
Object.entries(parsed.slidesByDevice).map(([device, slides]) => [
@@ -294,10 +303,15 @@ export function useProject() {
};
}, [state, hydrated, fileReady]);
- const setState = useCallback((updater: Updater) => {
+ // `history: false` is for navigation (device, orientation, locale): it isn't
+ // an edit, so it neither takes an undo step nor clears redo. Undo still
+ // restores the snapshot's device, which takes you to the deck the undone
+ // edit was made on.
+ const setState = useCallback((updater: Updater, options?: { history?: boolean }) => {
_setState((prev) => {
const next = applyUpdater(updater, prev);
if (next === prev) return prev;
+ if (options?.history === false) return next;
const now = Date.now();
if (now - lastPushAt.current > COALESCE_MS) {
pastRef.current.push(prev);
diff --git a/skills/app-store-screenshots/template/src/lib/types.ts b/skills/app-store-screenshots/template/src/lib/types.ts
index b19fde4..6df454c 100644
--- a/skills/app-store-screenshots/template/src/lib/types.ts
+++ b/skills/app-store-screenshots/template/src/lib/types.ts
@@ -127,7 +127,6 @@ export type ScreenshotFontId =
| "template-default"
| "template-serif"
| "system-sans"
- | "classic-serif"
| "avenir-next"
| "helvetica-neue"
| "american-typewriter"
@@ -140,6 +139,8 @@ export type ScreenshotFontId =
export type ImportedFont = {
src: string;
format: "woff2" | "woff" | "truetype" | "opentype";
+ /** Display name, taken from the uploaded file name. */
+ name?: string;
};
export type Theme = {