IKEA assembly, step by step: animated, manual-style 3D guides. Scan any paper manual with Together AI.
TypeScript
Print view and a way to flag a wrong step
Youssef95c7f35780da
diff --git a/src/app/build/[slug]/print/page.tsx b/src/app/build/[slug]/print/page.tsxnew file mode 100644index 0000000..ba99224--- /dev/null+++ b/src/app/build/[slug]/print/page.tsx@@ -0,0 +1,24 @@+import { Suspense } from "react";+import type { Metadata } from "next";+import { catalogSpec } from "@/lib/catalog";+import PrintGuide from "@/components/guide/PrintGuide";++type Props = { params: Promise<{ slug: string }> };++export async function generateMetadata({ params }: Props): Promise<Metadata> {+ const s = catalogSpec(decodeURIComponent((await params).slug));+ return { title: `Print: ${s ? `${s.name} ${s.variant.toLowerCase()}` : "assembly guide"} | Bygga`, robots: { index: false } };+}++export default function Page({ params }: Props) {+ return (+ <Suspense fallback={<div className="print-doc" />}>+ <Inner params={params} />+ </Suspense>+ );+}++async function Inner({ params }: Props) {+ const { slug } = await params;+ return <PrintGuide slug={decodeURIComponent(slug)} />;+}diff --git a/src/app/guide.css b/src/app/guide.cssindex 2a5e857..9695403 100644--- a/src/app/guide.css+++ b/src/app/guide.css@@ -1052,6 +1052,11 @@.official:hover {color: var(--ink);}+.cover-links {+ display: flex;+ flex-wrap: wrap;+ gap: 0 22px;+}/* ================= tools ================= */@@ -1907,6 +1912,33 @@ input[type="range"] {/* ================= help ================= */+.report-btn {+ display: inline-flex;+ align-items: center;+ gap: 8px;+ margin: 10px 0 4px;+ padding: 8px 2px;+ border: 0;+ background: none;+ color: var(--ink-2);+ font: inherit;+ font-size: 14px;+ font-weight: 500;+ text-decoration: underline;+ text-underline-offset: 4px;+ text-decoration-color: var(--line-2);+ cursor: pointer;+}+.report-btn:hover {+ color: var(--ink);+ text-decoration-color: currentColor;+}+.report-done {+ margin: 12px 0 4px;+ font-size: 14px;+ color: var(--ink-2);+}+.sheet-back {place-items: stretch end;padding: 12px;@@ -2624,3 +2656,260 @@ input[type="range"] {justify-self: center;}}++/* ================= print: the whole guide on A4 ================= */++.print-doc {+ display: grid;+ justify-items: center;+ gap: 24px;+ padding: 0 16px 48px;+}+.print-bar {+ position: sticky;+ top: 0;+ z-index: 5;+ display: flex;+ align-items: center;+ gap: 12px;+ width: min(210mm, 100%);+ padding: 14px 0;+ background: color-mix(in srgb, var(--page) 92%, transparent);+ backdrop-filter: blur(12px);+}+.print-status {+ flex: 1;+ color: var(--ink-2);+ font-size: 15px;+}+.print-bar .btn.primary {+ height: 44px;+ padding: 0 20px;+}+.print-page {+ position: relative;+ display: flex;+ flex-direction: column;+ width: min(210mm, 100%);+ min-height: 297mm;+ padding: 14mm 14mm 10mm;+ background: #fff;+ border-radius: 6px;+ box-shadow: var(--shadow-2);+ color: var(--ink);+}+.pp-head {+ display: flex;+ align-items: center;+ gap: 10px;+ font-size: 13px;+ font-weight: 700;+ letter-spacing: 0.08em;+ text-transform: uppercase;+ color: var(--ink-2);+}+.cover-page h1 {+ margin: 10mm 0 0;+ font-family: var(--display);+ font-weight: 800;+ font-size: 64px;+ line-height: 1;+ letter-spacing: -0.04em;+}+.pp-variant {+ margin: 8px 0 0;+ font-size: 22px;+ color: var(--ink-2);+}+.pp-facts {+ margin: 10px 0 0;+ font-size: 14px;+ font-weight: 600;+}+.pp-hero {+ margin: 6mm 0 2mm;+}+.pp-hero .thumb,+.print-step .thumb {+ display: block;+ width: 100%;+}+.pp-hero .thumb img,+.print-step .thumb img {+ width: 100%;+ height: 100%;+ object-fit: contain;+}+.cover-page h2 {+ margin: 6mm 0 3mm;+ font-size: 13px;+ font-weight: 700;+ letter-spacing: 0.08em;+ text-transform: uppercase;+ color: var(--ink-2);+}+.pp-tools {+ display: flex;+ flex-wrap: wrap;+ gap: 6px 22px;+ margin: 0;+ padding: 0;+ list-style: none;+ font-size: 14px;+}+.pp-tools li {+ display: flex;+ align-items: center;+ gap: 8px;+}+.pp-cols {+ display: grid;+ grid-template-columns: 1fr 1fr;+ gap: 10mm;+}+.pp-parts,+.pp-hw {+ display: grid;+ gap: 5px;+ margin: 0;+ padding: 0;+ list-style: none;+ font-size: 13.5px;+}+.pp-parts li,+.pp-hw li {+ display: grid;+ grid-template-columns: 28px minmax(0, 1fr) auto;+ align-items: center;+ gap: 8px;+ padding-bottom: 5px;+ border-bottom: 1px solid var(--line);+}+.pp-hw li {+ grid-template-columns: 44px minmax(0, 1fr) auto;+}+.pp-label {+ display: grid;+ place-items: center;+ width: 24px;+ height: 24px;+ border-radius: 50%;+ border: 1.6px solid var(--ink);+ font-size: 12px;+}+.pp-hw-art {+ display: grid;+ place-items: center;+}+.pp-hw small {+ color: var(--ink-3);+}+.pp-parts em,+.pp-hw em {+ font-style: normal;+ font-weight: 800;+}+.pp-foot {+ display: flex;+ justify-content: space-between;+ gap: 12px;+ margin-top: auto;+ padding-top: 6mm;+ font-size: 11px;+ color: var(--ink-3);+}+.pp-grid {+ display: grid;+ grid-template-columns: 1fr 1fr;+ grid-template-rows: repeat(3, minmax(0, 1fr));+ gap: 6mm;+ flex: 1;+}+.print-step {+ display: flex;+ flex-direction: column;+ min-height: 0;+ padding: 4mm;+ border: 1.4px solid var(--line-2);+ border-radius: 4mm;+ break-inside: avoid;+}+.ps-top {+ display: flex;+ align-items: flex-start;+ gap: 10px;+}+.ps-n {+ font-family: var(--display);+ font-weight: 800;+ font-size: 40px;+ line-height: 0.9;+ letter-spacing: -0.04em;+}+.ps-hw {+ display: flex;+ gap: 6px;+ padding: 3px 6px;+ border: 1.4px solid var(--ink);+ border-radius: 8px;+}+.ps-hw > span {+ display: flex;+ flex-direction: column;+ align-items: center;+ font-size: 11px;+}+.ps-two {+ margin-left: auto;+}+.ps-art {+ flex: 1;+ min-height: 0;+}+.ps-title {+ margin: 2mm 0 0;+ font-size: 13px;+ font-weight: 600;+ line-height: 1.3;+}++@media print {+ @page {+ size: A4;+ margin: 0;+ }+ body {+ background: #fff;+ }+ .print-bar,+ nextjs-portal {+ display: none !important;+ }+ .print-doc {+ padding: 0;+ gap: 0;+ }+ .print-page {+ width: 210mm;+ height: 297mm;+ min-height: 0;+ border-radius: 0;+ box-shadow: none;+ break-after: page;+ }+}++@media (max-width: 640px) {+ .print-page {+ min-height: 0;+ padding: 18px;+ }+ .cover-page h1 {+ font-size: 44px;+ }+ .pp-cols,+ .pp-grid {+ grid-template-columns: 1fr;+ grid-template-rows: none;+ }+}diff --git a/src/components/guide/CoverPanel.tsx b/src/components/guide/CoverPanel.tsxindex 9de2674..92dd816 100644--- a/src/components/guide/CoverPanel.tsx+++ b/src/components/guide/CoverPanel.tsx@@ -4,7 +4,7 @@ import Link from "next/link";import type { Plan } from "@/lib/types";import type { Progress } from "@/lib/store";import { floorSpace, totals } from "@/lib/plan/contents";-import { IArrowRight, IBox, ICheck, IClock, IExternal, IPeople, IPerson, IRuler, ISparkle, IWrench } from "../art/Icons";+import { IArrowRight, IBox, ICheck, IClock, IExternal, IPeople, IPerson, IPrint, IRuler, ISparkle, IWrench } from "../art/Icons";import { Dots } from "./ui";import { TOOL_INFO } from "../art/Tools";import { SCAN_ENABLED } from "@/lib/site";@@ -168,11 +168,16 @@ export default function CoverPanel({</div>))}- {via !== "scan" && (- <a className="official" href={official} target="_blank" rel="noreferrer">- Official manual on ikea.com <IExternal size={15} />- </a>- )}+ <div className="cover-links">+ {via !== "scan" && (+ <a className="official" href={official} target="_blank" rel="noreferrer">+ Official manual on ikea.com <IExternal size={15} />+ </a>+ )}+ <Link className="official" href={`/build/${s.slug}/print`}>+ <IPrint size={15} /> Print this guide+ </Link>+ </div></div><div className="pane-foot">{resumable ? (diff --git a/src/components/guide/HelpSheet.tsx b/src/components/guide/HelpSheet.tsxindex 395081f..af92d77 100644--- a/src/components/guide/HelpSheet.tsx+++ b/src/components/guide/HelpSheet.tsx@@ -5,7 +5,7 @@ import { AnimatePresence, motion } from "motion/react";import type { Plan } from "@/lib/types";import { faqFor } from "@/lib/faq";import { stepContents } from "@/lib/plan/contents";-import { ICamera, IChevronDown, IClose, ISend, ISparkle } from "../art/Icons";+import { ICamera, IChevronDown, IClose, IFlag, ISend, ISparkle } from "../art/Icons";import { Figure } from "../art/Figure";import { keyHeaders } from "@/lib/userKey";@@ -195,6 +195,7 @@ export default function HelpSheet({</div>))}</div>+ {index >= 0 && <Report plan={plan} index={index} />}{ai && (<>@@ -205,7 +206,7 @@ export default function HelpSheet({</div>{msgs.length === 0 && (<div className="ask-suggest">- {["The panels don't line up", "Which screw goes where?", "Is it normal to have parts left over?"].map((s) => (+ {["Which way round does this go?", "Which screw goes where?", "Is it normal to have parts left over?"].map((s) => (<button key={s} className="chip" onClick={() => ask(s)}>{s}</button>@@ -259,3 +260,23 @@ export default function HelpSheet({</motion.div>);}++/** "This step doesn't match my box": goes to /api/feedback so wrong steps get fixed. */+function Report({ plan, index }: { plan: Plan; index: number }) {+ const [sent, setSent] = useState(false);+ const send = () => {+ setSent(true);+ fetch("/api/feedback", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ slug: plan.spec.slug, name: plan.spec.name, variant: plan.spec.variant, match: false, step: index + 1, via: "help" }),+ }).catch(() => {});+ };+ return sent ? (+ <p className="report-done">Thanks. We'll check step {index + 1} against the real box. Trust the paper manual for now.</p>+ ) : (+ <button className="report-btn" onClick={send}>+ <IFlag size={16} /> This step doesn't match my box+ </button>+ );+}diff --git a/src/components/guide/PrintGuide.tsx b/src/components/guide/PrintGuide.tsxnew file mode 100644index 0000000..f2f8584--- /dev/null+++ b/src/components/guide/PrintGuide.tsx@@ -0,0 +1,196 @@+"use client";++import { useEffect, useMemo, useRef, useState } from "react";+import Link from "next/link";+import type { Plan } from "@/lib/types";+import { catalogSpec } from "@/lib/catalog";+import { buildPlan } from "@/lib/plan";+import { stepContents, totals } from "@/lib/plan/contents";+import { cachedSpec, loadProgress } from "@/lib/store";+import { useMounted } from "@/lib/useMounted";+import Thumb from "../Thumb";+import { LogoMark } from "../Logo";+import { HwArt } from "../art/Hardware";+import { TOOL_INFO, ToolArt } from "../art/Tools";+import { IArrowLeft, IPeople, IPrint } from "../art/Icons";+import { fmtMin } from "./CoverPanel";+import { SITE_URL } from "@/lib/site";++const PER_PAGE = 6;++/** The whole guide on A4: what's in the box first, then six steps to a page, like the paper manual. */+export default function PrintGuide({ slug }: { slug: string }) {+ const mounted = useMounted();+ const plan = useMemo(() => {+ const spec = catalogSpec(slug) ?? (mounted ? (cachedSpec(slug) ?? loadProgress(slug)?.spec ?? null) : null);+ if (!spec) return null;+ try {+ return buildPlan({ ...spec, slug });+ } catch {+ return null;+ }+ }, [slug, mounted]);++ if (!plan)+ return (+ <div className="print-doc">+ <div className="print-bar">+ <Link href={`/build/${slug}`} className="btn ghost">+ <IArrowLeft size={18} /> Open the guide first+ </Link>+ </div>+ </div>+ );+ return <Doc plan={plan} slug={slug} />;+}++function Doc({ plan, slug }: { plan: Plan; slug: string }) {+ const s = plan.spec;+ const t = totals(plan);+ const root = useRef<HTMLDivElement>(null);+ const [ready, setReady] = useState(0);+ useEffect(() => {+ const el = root.current;+ if (!el) return;+ const count = () => setReady(el.querySelectorAll(".print-step .thumb.ready").length);+ const mo = new MutationObserver(count);+ mo.observe(el, { subtree: true, attributes: true, attributeFilter: ["class"] });+ count();+ return () => mo.disconnect();+ }, []);+ const pages: number[][] = [];+ for (let i = 0; i < plan.steps.length; i += PER_PAGE) pages.push(plan.steps.slice(i, i + PER_PAGE).map((_, j) => i + j));+ const total = plan.steps.length;+ const done = ready >= total;+ const tools = plan.tools.filter((x) => !x.included);+ const url = `${SITE_URL.replace(/^https?:\/\//, "")}/build/${slug}`;+ const id = "print:" + s.name + s.variant;++ return (+ <div className="print-doc" ref={root}>+ <div className="print-bar">+ <Link href={`/build/${slug}`} className="btn round small" aria-label="Back to the guide">+ <IArrowLeft size={18} />+ </Link>+ <span className="print-status">{done ? `${pages.length + 1} pages, ready to print` : `Drawing step ${Math.min(total, ready + 1)} of ${total}`}</span>+ <button className="btn primary" onClick={() => window.print()} disabled={!done}>+ <IPrint size={18} /> Print+ </button>+ </div>++ <section className="print-page cover-page">+ <header className="pp-head">+ <LogoMark size={28} />+ <span>Assembly guide</span>+ </header>+ <h1>{s.name}</h1>+ <p className="pp-variant">{s.variant}</p>+ <p className="pp-facts">+ {fmtMin(s.minutes)} · {s.people === 2 ? "two people" : "one person"} · {total} steps · {t.panels} panels · {t.fittings} fittings+ </p>+ <div className="pp-hero">+ <Thumb id={id} plan={plan} mode={{ kind: "assembled" }} w={640} h={420} />+ </div>+ {tools.length > 0 && (+ <>+ <h2>Tools</h2>+ <ul className="pp-tools">+ {tools.map((x) => (+ <li key={x.id}>+ <ToolArt id={x.id} size={44} />+ <span>+ {TOOL_INFO[x.id].name}+ {x.optional ? " (nice to have)" : ""}+ </span>+ </li>+ ))}+ </ul>+ </>+ )}+ <div className="pp-cols">+ <div>+ <h2>Panels</h2>+ <ul className="pp-parts">+ {plan.parts+ .filter((p) => !p.extra)+ .map((p) => (+ <li key={p.id}>+ <b className="pp-label">{p.label}</b>+ <span>{p.name}</span>+ <em>{p.qty}×</em>+ </li>+ ))}+ </ul>+ </div>+ <div>+ <h2>Fittings</h2>+ <ul className="pp-hw">+ {plan.hardware.map((h) => (+ <li key={h.id}>+ <span className="pp-hw-art">+ <HwArt kind={h.kind} len={h.len} dia={h.dia} fit={36} />+ </span>+ <span>+ {h.name} <small>{h.spec}</small>+ {h.notIncluded ? <small> (not in the box)</small> : null}+ </span>+ <em>{h.qty}×</em>+ </li>+ ))}+ </ul>+ </div>+ </div>+ <footer className="pp-foot">+ <span>Follow it in 3D, read out loud: {url}</span>+ <span>Not affiliated with IKEA. Check each step against the paper manual.</span>+ </footer>+ </section>++ {pages.map((idx, p) => (+ <section key={p} className="print-page steps-page">+ <div className="pp-grid">+ {idx.map((i) => {+ const st = plan.steps[i];+ const c = stepContents(plan, i);+ return (+ <article key={i} className="print-step">+ <div className="ps-top">+ <b className="ps-n">{i + 1}</b>+ {c.hardware.length > 0 && (+ <span className="ps-hw">+ {c.hardware.slice(0, 4).map(({ type, count }) => (+ <span key={type.id}>+ <HwArt kind={type.kind} len={type.len} dia={type.dia} fit={26} />+ <b>{count}×</b>+ </span>+ ))}+ </span>+ )}+ {st.people === 2 && (+ <span className="ps-two" title="Two people">+ <IPeople size={18} />+ </span>+ )}+ </div>+ <Thumb id={id} plan={plan} mode={{ kind: "step", index: i }} w={520} h={360} className="ps-art" />+ <p className="ps-title">+ {st.title}+ {st.repeat && st.repeat > 1 ? ` (do this ${st.repeat} times)` : ""}+ </p>+ </article>+ );+ })}+ </div>+ <footer className="pp-foot">+ <span>+ {s.name}, {s.variant}+ </span>+ <span>+ {p + 2} / {pages.length + 1}+ </span>+ </footer>+ </section>+ ))}+ </div>+ );+}