IKEA assembly, step by step: animated, manual-style 3D guides. Scan any paper manual with Together AI.
TypeScript
New share cards
Youssef580cf9e20252
diff --git a/next.config.ts b/next.config.tsindex ac8a608..494ac7f 100644--- a/next.config.ts+++ b/next.config.ts@@ -34,8 +34,8 @@ const nextConfig: NextConfig = {partialPrefetching: true,// the share cards read their fonts and drawings from diskoutputFileTracingIncludes: {- "/opengraph-image": ["./src/lib/og/*.woff", "./public/og/step-hero.png", "./public/og/kallax-2x2.png"],- "/twitter-image": ["./src/lib/og/*.woff", "./public/og/step-hero.png", "./public/og/kallax-2x2.png"],+ "/opengraph-image": ["./src/lib/og/*.woff", "./public/og/hero-bygga.png", "./public/og/hero-paper.png"],+ "/twitter-image": ["./src/lib/og/*.woff", "./public/og/hero-bygga.png", "./public/og/hero-paper.png"],"/build/*/opengraph-image*": ["./src/lib/og/*.woff", "./public/og/*.png"],"/build/*/twitter-image*": ["./src/lib/og/*.woff", "./public/og/*.png"],},diff --git a/public/og/hero-bygga.png b/public/og/hero-bygga.pngnew file mode 100644index 0000000..f6cf1afBinary files /dev/null and b/public/og/hero-bygga.png differdiff --git a/public/og/hero-paper.png b/public/og/hero-paper.pngnew file mode 100644index 0000000..c9de0b7Binary files /dev/null and b/public/og/hero-paper.png differdiff --git a/public/og/step-hero.png b/public/og/step-hero.pngdeleted file mode 100644index 1561796..0000000Binary files a/public/og/step-hero.png and /dev/null differdiff --git a/scripts/og/render.mjs b/scripts/og/render.mjsindex 4ec6b34..30c84da 100644--- a/scripts/og/render.mjs+++ b/scripts/og/render.mjs@@ -28,7 +28,7 @@ const page = await browser.newPage();await page.goto(`${base}/dev/og`);await page.waitForFunction(() => document.body.dataset.ready === "1", null, { timeout: 60_000 });-// --step malm-3-drawers:6:step-hero draws one step of a product instead of the whole list+// --step malm-3-drawers:6:malm-step draws one step of a product instead of the whole listconst step = arg("--step");const jobs = step? [{ slug: step.split(":")[0], mode: { kind: "step", index: Number(step.split(":")[1]) }, out: step.split(":")[2] }]diff --git a/src/app/build/[slug]/opengraph-image.tsx b/src/app/build/[slug]/opengraph-image.tsxindex 66dba86..0ecc979 100644--- a/src/app/build/[slug]/opengraph-image.tsx+++ b/src/app/build/[slug]/opengraph-image.tsx@@ -7,7 +7,7 @@ import { OG_SIZE, drawing, guideCard } from "@/lib/og/card";/** A drawing to fall back on for each archetype. */const BY_ARCH: Record<string, string> = { shelf: "bookcase", drawers: "chest", table: "dining", bed: "bed", cabinet: "cabinet", seat: "chair", sofa: "sofa", custom: "cabinet" };-export const alt = "An IKEA assembly guide on Bygga, step by step in 3D";+export const alt = "An IKEA assembly guide on Bygga: the product drawn in 3D, with every step read out loud";export const size = OG_SIZE;export const contentType = "image/png";diff --git a/src/app/build/[slug]/twitter-image.tsx b/src/app/build/[slug]/twitter-image.tsxindex 66dba86..0ecc979 100644--- a/src/app/build/[slug]/twitter-image.tsx+++ b/src/app/build/[slug]/twitter-image.tsx@@ -7,7 +7,7 @@ import { OG_SIZE, drawing, guideCard } from "@/lib/og/card";/** A drawing to fall back on for each archetype. */const BY_ARCH: Record<string, string> = { shelf: "bookcase", drawers: "chest", table: "dining", bed: "bed", cabinet: "cabinet", seat: "chair", sofa: "sofa", custom: "cabinet" };-export const alt = "An IKEA assembly guide on Bygga, step by step in 3D";+export const alt = "An IKEA assembly guide on Bygga: the product drawn in 3D, with every step read out loud";export const size = OG_SIZE;export const contentType = "image/png";diff --git a/src/app/opengraph-image.tsx b/src/app/opengraph-image.tsxindex a419ccd..9ef5d8a 100644--- a/src/app/opengraph-image.tsx+++ b/src/app/opengraph-image.tsx@@ -1,6 +1,6 @@import { OG_SIZE, siteCard } from "@/lib/og/card";-export const alt = "Bygga: IKEA assembly, step by step, in 3D. Powered by Together AI";+export const alt = "Bygga: IKEA assembly, step by step. A KALLAX step from the paper booklet, next to the same step on Bygga. Powered by Together AI";export const size = OG_SIZE;export const contentType = "image/png";diff --git a/src/app/twitter-image.tsx b/src/app/twitter-image.tsxindex a419ccd..9ef5d8a 100644--- a/src/app/twitter-image.tsx+++ b/src/app/twitter-image.tsx@@ -1,6 +1,6 @@import { OG_SIZE, siteCard } from "@/lib/og/card";-export const alt = "Bygga: IKEA assembly, step by step, in 3D. Powered by Together AI";+export const alt = "Bygga: IKEA assembly, step by step. A KALLAX step from the paper booklet, next to the same step on Bygga. Powered by Together AI";export const size = OG_SIZE;export const contentType = "image/png";diff --git a/src/components/guide/CoverPanel.tsx b/src/components/guide/CoverPanel.tsxindex cb32660..cb17e1a 100644--- a/src/components/guide/CoverPanel.tsx+++ b/src/components/guide/CoverPanel.tsx@@ -1,6 +1,7 @@"use client";import Link from "next/link";+import { spellOut } from "@/lib/shorthand";import type { Plan } from "@/lib/types";import type { Progress } from "@/lib/store";import { floorSpace, totals } from "@/lib/plan/contents";@@ -244,37 +245,10 @@ function chipLabels(labels: string[]) {}/** IKEA's shorthand in its type names, as words. */-const SHORTHAND: [RegExp, string][] = [- [/\s*\+\s*/g, " and "],- [/\b(cab|cb)\b/gi, "cabinet"],- [/\bhi\b/gi, "high"],- [/\bf\b/g, "for"],- [/\bwsh-stnd\b/gi, "wash-stand"],- [/\bstnd\b/g, "stand"],- [/\bsnk\b/g, "sink"],- [/\bov\b/g, "oven"],- [/\bextr\b/g, "extractor"],- [/\bb-in\b/g, "built-in"],- [/\bfrnts\b/g, "fronts"],- [/\bfrnt\b/g, "front"],- [/\b(drws|drwrs)\b/g, "drawers"],- [/\bdrw\b/g, "drawer"],- [/\bdr\b/g, "door"],- [/\b(\d) m\b/g, "$1 medium"],- [/\bmd\b/g, "medium"],- [/\bfr\b/g, "frame"],- [/\b(\d) h\b/g, "$1 high"],- [/\bshlf\b/g, "shelf"],- [/\bshlvs?\b/g, "shelves"],- [/\bp-out\b/g, "pull-out"],-];/** IKEA's shorthand spelled out, first letter up. */function tidy(t: string) {- const s = SHORTHAND.reduce((acc, [re, word]) => acc.replace(re, word), t)- .replace(/(^|\s)w (?=\S)/gi, "$1with ")- .replace(/\bdrs\b/g, "doors")- .replace(/(\d) seat\b/g, "$1-seat")+ const s = spellOut(t)// a size never breaks across lines.replace(/ × /g, "\u00a0×\u00a0").replace(/(\d) cm\b/g, "$1\u00a0cm");diff --git a/src/lib/og/card.tsx b/src/lib/og/card.tsxindex b8eb271..e48cf5a 100644--- a/src/lib/og/card.tsx+++ b/src/lib/og/card.tsx@@ -2,22 +2,26 @@ import { ImageResponse } from "next/og";import { existsSync } from "node:fs";import { readFile } from "node:fs/promises";import { join } from "node:path";+import { spellOut } from "../shorthand";import { TogetherStamp } from "./factory";/**- * The share cards, drawn like a page of the guide: warm paper, the product- * on a white sheet in the app's own line art, the name in its display face.- * Drawings come from public/og (scripts/og/render.mjs renders them with the- * real engine); products without one use the drawing of their kind.+ * The share cards, in the site's own look: warm paper, ink type in the+ * display face, one yellow highlight, and the app's real line art.+ *+ * - The site card stacks the KALLAX booklet page behind the same step on+ * Bygga (both captured from the home page's comparison, public/og/hero-*.png).+ * - A guide card lays the product on a white sheet that runs off the edge,+ * drawn by the real engine (public/og/{slug}.png, scripts/og/render.mjs).*/export const OG_SIZE = { width: 1200, height: 630 };const PAGE = "#f5f4f0";const INK = "#121212";-const INK_2 = "#4a4945";-const LINE = "#e8e6e0";+const INK_2 = "#55534e";const ACCENT = "#ffd21f";+const PAD = 72;const here = join(process.cwd(), "src/lib/og");let fonts: Promise<{ name: string; data: Buffer; weight: 500 | 700 | 800; style: "normal" }[]> | null = null;@@ -48,90 +52,127 @@ function Mark({ size }: { size: number }) {);}-function Frame({ left, art, corner }: { left: React.ReactNode; art: string | null; corner?: string }) {+function Logo() {return (- <div style={{ width: "100%", height: "100%", display: "flex", background: PAGE, padding: 40, fontFamily: "Sans", color: INK }}>- <div style={{ display: "flex", flexDirection: "column", width: 560, padding: "18px 36px 14px 24px" }}>- <div style={{ display: "flex", alignItems: "center", gap: 12 }}>- <Mark size={40} />- <span style={{ fontFamily: "Display", fontSize: 32, fontWeight: 800, letterSpacing: "-0.02em" }}>bygga</span>- </div>- <div style={{ display: "flex", flexDirection: "column", flex: 1, justifyContent: "center" }}>{left}</div>- <div style={{ display: "flex", alignItems: "center", gap: 10, fontSize: 19, color: INK_2 }}>- <span>Powered by</span>- <TogetherStamp height={24} color={INK} />- </div>- </div>- <div- style={{- display: "flex",- flex: 1,- position: "relative",- alignItems: "center",- justifyContent: "center",- background: "#ffffff",- borderRadius: 36,- border: `2px solid ${LINE}`,- }}- >- {/* eslint-disable-next-line @next/next/no-img-element */}- {art && <img src={art} alt="" width={520} height={455} style={{ objectFit: "contain" }} />}- {corner && (- <span style={{ position: "absolute", top: 18, left: 30, fontFamily: "Display", fontSize: 96, fontWeight: 800, letterSpacing: "-0.05em" }}>{corner}</span>- )}- </div>+ <div style={{ display: "flex", alignItems: "center", gap: 13 }}>+ <Mark size={46} />+ <span style={{ fontFamily: "Display", fontSize: 40, fontWeight: 800, letterSpacing: "-0.045em", paddingBottom: 4 }}>bygga</span>+ </div>+ );+}++function Powered() {+ return (+ <div style={{ display: "flex", alignItems: "center", gap: 11, fontSize: 20, color: INK_2 }}>+ <span>Powered by</span>+ <TogetherStamp height={25} color={INK} /></div>);}-/** Words on a yellow marker, like a highlighted line in the margin. */+/** Words with a yellow highlighter stroke behind their lower half, as in the footer credit. */function Marked({ children, size }: { children: string; size: number }) {return (- <span style={{ display: "flex", background: ACCENT, borderRadius: size * 0.16, padding: `0 ${size * 0.14}px`, marginLeft: -size * 0.1 }}>{children}</span>+ <div style={{ display: "flex", position: "relative", fontSize: size }}>+ <div style={{ position: "absolute", left: -size * 0.06, right: -size * 0.08, bottom: size * 0.1, height: size * 0.36, background: ACCENT, borderRadius: size * 0.06 }} />+ <span>{children}</span>+ </div>);}+function render(node: React.ReactElement) {+ return loadFonts().then((f) => new ImageResponse(node, { ...OG_SIZE, fonts: f }));+}+export async function siteCard() {- const art = (await drawing("step-hero")) ?? (await drawing("kallax-2x2"));- return new ImageResponse(- (- <Frame- art={art}- corner="4"- left={- <div style={{ display: "flex", flexDirection: "column", fontFamily: "Display", fontWeight: 800, fontSize: 66, lineHeight: 1.04, letterSpacing: "-0.035em" }}>- <span>IKEA assembly,</span>- <div style={{ display: "flex", marginTop: 6 }}>- <Marked size={66}>step by step.</Marked>- </div>+ const [front, back] = await Promise.all([drawing("hero-bygga"), drawing("hero-paper")]);+ const H = 84;+ return render(+ <div style={{ width: "100%", height: "100%", display: "flex", position: "relative", background: PAGE, fontFamily: "Sans", color: INK, overflow: "hidden" }}>+ {/* the booklet page, tilted back, and the same step on Bygga in front of it */}+ {back && (+ // eslint-disable-next-line @next/next/no-img-element+ <img+ src={back}+ alt=""+ width={480}+ height={419}+ style={{ position: "absolute", left: 706, top: 28, transform: "rotate(-6deg)", borderRadius: 22, boxShadow: "0 18px 40px rgba(40,34,20,0.10)" }}+ />+ )}+ {front && (+ // eslint-disable-next-line @next/next/no-img-element+ <img+ src={front}+ alt=""+ width={560}+ height={413}+ style={{ position: "absolute", left: 604, top: 176, transform: "rotate(3deg)", borderRadius: 24, boxShadow: "0 30px 70px rgba(30,26,16,0.20), 0 4px 14px rgba(30,26,16,0.08)" }}+ />+ )}+ <div style={{ display: "flex", flexDirection: "column", justifyContent: "space-between", width: 600, height: "100%", padding: `${PAD - 8}px 0 ${PAD - 12}px ${PAD}px` }}>+ <Logo />+ <div style={{ display: "flex", flexDirection: "column", fontFamily: "Display", fontWeight: 800, fontSize: H, lineHeight: 1, letterSpacing: "-0.045em" }}>+ <span>IKEA assembly,</span>+ <div style={{ display: "flex", marginTop: 4 }}>+ <Marked size={H}>step by step.</Marked></div>- }- />- ),- { ...OG_SIZE, fonts: await loadFonts() },+ </div>+ <Powered />+ </div>+ </div>,);}+// rough advance widths of the display face's capitals, in em+const WIDE: Record<string, number> = { I: 0.3, J: 0.42, L: 0.52, F: 0.54, E: 0.56, M: 0.86, W: 0.95, N: 0.72, O: 0.7, Ö: 0.7, Q: 0.7, " ": 0.24, "/": 0.4 };+const NAME_W = 428;++/** The name as big as its longest line fits the column: KALLAX huge, LINNMON / ADILS on two lines. */+function nameSize(name: string) {+ const lines = name.includes(" / ") ? name.split(" / ").map((l, i, a) => (i < a.length - 1 ? l + " /" : l)) : name.split(/\s+/);+ const em = Math.max(...lines.map((l) => [...l.toUpperCase()].reduce((a, c) => a + (WIDE[c] ?? 0.64), 0)));+ // two lines of name leave room for the rest of the column+ return Math.max(56, Math.min(lines.length > 1 ? 88 : 118, Math.floor(NAME_W / em)));+}+export async function guideCard(o: { name: string; variant: string; steps: number | null; art: string | null }) {- const long = o.name.length > 9;- return new ImageResponse(- (- <Frame- art={o.art}- left={- <div style={{ display: "flex", flexDirection: "column" }}>- <span style={{ fontSize: 24, fontWeight: 700, color: INK_2, letterSpacing: "0.08em" }}>ASSEMBLY GUIDE</span>- <span style={{ fontFamily: "Display", fontWeight: 800, fontSize: long ? 76 : 104, lineHeight: 1, letterSpacing: "-0.04em", marginTop: 10 }}>{o.name}</span>- <span style={{ fontSize: 32, fontWeight: 500, color: INK_2, marginTop: 14, lineHeight: 1.25 }}>{o.variant}</span>- <div style={{ display: "flex", marginTop: 28 }}>- <span style={{ display: "flex", background: ACCENT, borderRadius: 999, padding: "10px 22px", fontSize: 26, fontWeight: 700 }}>- {o.steps ? `${o.steps} steps, in 3D` : "Every step, in 3D"}- </span>- </div>+ const size = nameSize(o.name);+ const variant = spellOut(o.variant);+ return render(+ <div style={{ width: "100%", height: "100%", display: "flex", background: PAGE, fontFamily: "Sans", color: INK, overflow: "hidden" }}>+ <div style={{ display: "flex", flexDirection: "column", justifyContent: "space-between", width: 540, height: "100%", flex: "none", padding: `${PAD - 8}px 40px ${PAD - 12}px ${PAD}px` }}>+ <Logo />+ <div style={{ display: "flex", flexDirection: "column" }}>+ <span style={{ fontSize: 24, fontWeight: 700, color: INK_2 }}>Assembly guide</span>+ <span style={{ display: "flex", flexWrap: "wrap", fontFamily: "Display", fontWeight: 800, fontSize: size, lineHeight: 1.04, letterSpacing: "-0.045em", marginTop: 10 }}>{o.name}</span>+ <span style={{ fontSize: 30, fontWeight: 500, color: INK_2, marginTop: 16, lineHeight: 1.25, maxWidth: 420 }}>{variant}</span>+ <div style={{ display: "flex", marginTop: 30 }}>+ <span style={{ display: "flex", fontSize: 26, fontWeight: 700 }}>+ <Marked size={26}>{o.steps ? `${o.steps} steps, in 3D` : "Every step, in 3D"}</Marked>+ </span></div>- }- />- ),- { ...OG_SIZE, fonts: await loadFonts() },+ </div>+ <Powered />+ </div>+ {/* the product on a sheet of white that runs off the card */}+ <div+ style={{+ display: "flex",+ flex: 1,+ alignItems: "center",+ justifyContent: "center",+ margin: "28px -60px -60px 0",+ paddingRight: 60,+ paddingBottom: 60,+ background: "#ffffff",+ borderRadius: "36px 0 0 0",+ boxShadow: "0 24px 60px rgba(30,26,16,0.12), 0 2px 8px rgba(30,26,16,0.05)",+ }}+ >+ {/* eslint-disable-next-line @next/next/no-img-element */}+ {o.art && <img src={o.art} alt="" width={660} height={578} style={{ objectFit: "contain" }} />}+ </div>+ </div>,);}diff --git a/src/lib/shorthand.ts b/src/lib/shorthand.tsnew file mode 100644index 0000000..95c3c30--- /dev/null+++ b/src/lib/shorthand.ts@@ -0,0 +1,32 @@+/** IKEA's shorthand in product names, spelled out: "Base cab f hob/2 frnts" reads "Base cabinet for hob/2 fronts". */+const SHORTHAND: [RegExp, string][] = [+ [/\s*\+\s*/g, " and "],+ [/\b(cab|cb)\b/gi, "cabinet"],+ [/\bhi\b/gi, "high"],+ [/\bf\b/g, "for"],+ [/\bwsh-stnd\b/gi, "wash-stand"],+ [/\bstnd\b/g, "stand"],+ [/\bsnk\b/g, "sink"],+ [/\bov\b/g, "oven"],+ [/\bextr\b/g, "extractor"],+ [/\bb-in\b/g, "built-in"],+ [/\bfrnts\b/g, "fronts"],+ [/\bfrnt\b/g, "front"],+ [/\b(drws|drwrs)\b/g, "drawers"],+ [/\bdrw\b/g, "drawer"],+ [/\bdr\b/g, "door"],+ [/\b(\d) m\b/g, "$1 medium"],+ [/\bmd\b/g, "medium"],+ [/\bfr\b/g, "frame"],+ [/\b(\d) h\b/g, "$1 high"],+ [/\bshlf\b/g, "shelf"],+ [/\bshlvs?\b/g, "shelves"],+ [/\bp-out\b/g, "pull-out"],+];++export function spellOut(t: string) {+ return SHORTHAND.reduce((acc, [re, word]) => acc.replace(re, word), t)+ .replace(/(^|\s)w (?=\S)/gi, "$1with ")+ .replace(/\bdrs\b/g, "doors")+ .replace(/(\d) seat\b/g, "$1-seat");+}