Skip to content

armgit / bygga

Public Imported from GitHub
0

IKEA assembly, step by step: animated, manual-style 3D guides. Scan any paper manual with Together AI.

TypeScript

Instant product drawings in every list

Youssef26037477220f
diff --git a/src/app/guide.css b/src/app/guide.css
index 9695403..84e5c66 100644
--- a/src/app/guide.css
+++ b/src/app/guide.css
@@ -333,6 +333,11 @@
background: transparent;
animation: none;
}
+/* drawn on white: multiply lets the card or row colour show through */
+.drawing img {
+ mix-blend-mode: multiply;
+ animation: none;
+}
.thumb img {
position: absolute;
inset: 0;
@@ -1680,7 +1685,7 @@ input[type="range"] {
display: block;
height: 100%;
background: linear-gradient(100deg, transparent 20%, rgba(18, 18, 18, 0.05) 50%, transparent 80%) -100% 0 / 200% 100%;
- animation: shimmer 1.2s linear infinite;
+ animation: pic-shimmer 1.2s linear infinite;
}
.share-pic.ready::before {
display: none;
@@ -1694,7 +1699,7 @@ input[type="range"] {
.share-card:hover .share-pic {
transform: rotate(-1deg) scale(1.04);
}
-@keyframes shimmer {
+@keyframes pic-shimmer {
to {
background-position: 100% 0;
}
diff --git a/src/components/Drawing.tsx b/src/components/Drawing.tsx
new file mode 100644
index 0000000..b0e92fb
--- /dev/null
+++ b/src/components/Drawing.tsx
@@ -0,0 +1,30 @@
+"use client";
+
+import { useState } from "react";
+
+/**
+ * A catalog product's line drawing, drawn ahead of time by the engine
+ * (public/og, scripts/og/render.mjs). Instant and cacheable, with no WebGL,
+ * so long lists stay smooth on phones. Use <Thumb> for anything not in the catalog.
+ * `fallback` is shown if this product hasn't been drawn yet (its kind, say).
+ */
+export default function Drawing({ name, fallback, w, h, className, alt = "", eager }: { name: string; fallback?: string; w: number; h: number; className?: string; alt?: string; eager?: boolean }) {
+ const [miss, setMiss] = useState(false);
+ const src = miss && fallback ? fallback : name;
+ return (
+ <span className={"thumb ready drawing " + (className ?? "")} style={{ aspectRatio: `${w} / ${h}` }}>
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+ <img
+ key={src}
+ src={`/og/${encodeURIComponent(src)}.png`}
+ alt={alt}
+ width={w}
+ height={h}
+ loading={eager ? "eager" : "lazy"}
+ decoding="async"
+ draggable={false}
+ onError={(e) => (miss || !fallback ? ((e.target as HTMLImageElement).style.visibility = "hidden") : setMiss(true))}
+ />
+ </span>
+ );
+}
diff --git a/src/components/guide/DonePanel.tsx b/src/components/guide/DonePanel.tsx
index 2ba6ff2..0205e51 100644
--- a/src/components/guide/DonePanel.tsx
+++ b/src/components/guide/DonePanel.tsx
@@ -5,13 +5,11 @@ import Link from "next/link";
import { motion } from "motion/react";
import type { Plan } from "@/lib/types";
import { totals } from "@/lib/plan/contents";
-import { buildPlan } from "@/lib/plan";
-import { catalogSpec } from "@/lib/catalog";
import { POPULAR } from "@/lib/search";
import { getPref, setPref } from "@/lib/store";
import { Figure } from "../art/Figure";
import { IArrowLeft, IArrowRight, ICheck, ILibrary, IShare } from "../art/Icons";
-import Thumb from "../Thumb";
+import Drawing from "../Drawing";
import { fmtMin } from "./CoverPanel";
import { buildCard } from "./shareCard";
import { encodeSpec } from "@/lib/scan/share";
@@ -185,18 +183,7 @@ function NextUp({ plan }: { plan: Plan }) {
<div className="next-up">
{picks.map((p) => (
<Link key={p.slug} href={`/build/${p.slug}`} className="next-card">
- <Thumb
- id={"next-" + p.slug}
- plan={() => {
- const sp = catalogSpec(p.slug);
- return buildPlan(sp!);
- }}
- mode={{ kind: "assembled" }}
- w={200}
- h={150}
- lazy
- className="next-thumb"
- />
+ <Drawing name={p.slug} w={200} h={150} className="next-thumb" />
<span>
<b>{p.name}</b>
<span>{p.label}</span>
diff --git a/src/components/guide/GuideApp.tsx b/src/components/guide/GuideApp.tsx
index 6e25119..80d0f12 100644
--- a/src/components/guide/GuideApp.tsx
+++ b/src/components/guide/GuideApp.tsx
@@ -25,7 +25,7 @@ import DonePanel, { Confetti } from "./DonePanel";
import HelpSheet from "./HelpSheet";
import Overview from "./Overview";
import Loader from "./Loader";
-import Thumb from "../Thumb";
+import Drawing from "../Drawing";
import { haptic, speechSupported, useListener, useWakeLock, type Mic } from "./hooks";
import { playDone, playStep, playTick, setSound, soundOn } from "./sound";
import { mediaSession, voice } from "./voice";
@@ -172,7 +172,7 @@ function Shell({ title, children }: { title: string; children: React.ReactNode }
function NotFound({ query, slug, suggestions, ikea, error }: { query: string; slug: string; suggestions: string[]; ikea?: string; error: boolean }) {
const name = query.split(" ")[0].toUpperCase();
const what = ikea?.toLowerCase();
- const kinds = useMemo(() => KIND_LABELS.map((k) => ({ ...k, plan: buildPlan({ ...specForKind(k.kind, "X"), slug: "kind-" + k.kind }) })), []);
+ const kinds = KIND_LABELS;
if (error)
return (
<div className="notfound">
@@ -214,7 +214,7 @@ function NotFound({ query, slug, suggestions, ikea, error }: { query: string; sl
{kinds.map((k, i) => (
<motion.div key={k.kind} initial={{ opacity: 0, y: 10 }} animate={{ opacity: 1, y: 0 }} transition={{ delay: i * 0.025 }}>
<Link className="kind-card" href={`/build/${slug}?q=${encodeURIComponent(query)}&kind=${k.kind}`}>
- <Thumb id={"kind-" + k.kind} plan={k.plan} mode={{ kind: "assembled" }} w={200} h={150} className="kind-thumb" />
+ <Drawing name={"kind-" + k.kind} w={200} h={150} className="kind-thumb" eager />
<span>{k.label}</span>
</Link>
</motion.div>
diff --git a/src/components/home/Search.tsx b/src/components/home/Search.tsx
index cd001e4..0ad4a87 100644
--- a/src/components/home/Search.tsx
+++ b/src/components/home/Search.tsx
@@ -4,9 +4,7 @@ import { useEffect, useMemo, useRef, useState } from "react";
import { useRouter } from "next/navigation";
import { AnimatePresence, motion } from "motion/react";
import { articleNo, articlesReady, loadArticles, searchCatalog, slugify, matchCatalog } from "@/lib/search";
-import { catalogSpec } from "@/lib/catalog";
-import { buildPlan } from "@/lib/plan";
-import Thumb from "../Thumb";
+import Drawing from "../Drawing";
import { keyHeaders } from "@/lib/userKey";
import { IArrowRight, ICamera, ISearch, ISparkle } from "../art/Icons";
@@ -188,13 +186,9 @@ export default function Search({ ai, autoFocus }: { ai: boolean; autoFocus?: boo
}
function SuggestRow({ slug, name, variant, minutes, active, onPick, onHover }: { slug: string; name: string; variant: string; minutes: number; active: boolean; onPick: () => void; onHover: () => void }) {
- const plan = useMemo(() => {
- const spec = matchSlug(slug);
- return spec ? buildPlan(spec) : null;
- }, [slug]);
return (
<li role="option" aria-selected={active} className={"suggest-row" + (active ? " active" : "")} onMouseDown={(e) => e.preventDefault()} onClick={onPick} onMouseEnter={onHover}>
- <Thumb id={slug} plan={plan} mode={{ kind: "assembled" }} w={112} h={84} className="s-thumb" />
+ <Drawing name={slug} w={112} h={84} className="s-thumb" eager />
<span className="s-text">
<b>{name}</b>
<span>{variant}</span>
@@ -204,10 +198,6 @@ function SuggestRow({ slug, name, variant, minutes, active, onPick, onHover }: {
);
}
-function matchSlug(slug: string) {
- return catalogSpec(slug);
-}
-
async function shrink(file: File): Promise<string> {
const url = URL.createObjectURL(file);
try {
diff --git a/src/components/home/Sections.tsx b/src/components/home/Sections.tsx
index 28f30d2..bb2b413 100644
--- a/src/components/home/Sections.tsx
+++ b/src/components/home/Sections.tsx
@@ -5,10 +5,9 @@ import Link from "next/link";
import { AnimatePresence, motion } from "motion/react";
import { POPULAR, articleNo, fold, loadArticles, searchText } from "@/lib/search";
import { articleSlug } from "@/lib/ikea";
-import { PRODUCTS, toSpec, type CatalogEntry } from "@/lib/catalog";
-import { buildPlan } from "@/lib/plan";
+import { PRODUCTS, type CatalogEntry } from "@/lib/catalog";
import type { Kind } from "@/lib/products";
-import Thumb from "../Thumb";
+import Drawing from "../Drawing";
import { getUserKey } from "@/lib/userKey";
import { Dots } from "../guide/ui";
import { IArrowRight, IClock, ISearch } from "../art/Icons";
@@ -35,12 +34,11 @@ const inCat = (e: CatalogEntry, c: (typeof CATS)[number]) => (!c.kinds && !c.tag
const PAGE = 24;
export function ProductCard({ e, i = 0 }: { e: CatalogEntry; i?: number }) {
- const lazyPlan = useMemo(() => () => buildPlan(toSpec(e)), [e]);
return (
<motion.div layout initial={{ opacity: 0, y: 14 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, scale: 0.97 }} transition={{ duration: 0.4, delay: Math.min(0.3, (i % 12) * 0.03), ease: [0.22, 1, 0.36, 1] }}>
<Link href={`/build/${e.slug}`} className="pcard">
<span className="pcard-art">
- <Thumb id={e.slug} plan={lazyPlan} mode={{ kind: "assembled" }} w={420} h={320} className="pcard-thumb" alt={`${e.name} line drawing`} lazy />
+ <Drawing name={e.slug} fallback={e.kind ? `kind-${e.kind}` : undefined} w={420} h={320} className="pcard-thumb" alt={`${e.name} line drawing`} eager={i < 6} />
</span>
<span className="pcard-text">
<span className="pcard-top">
diff --git a/src/components/workshop/Workshop.tsx b/src/components/workshop/Workshop.tsx
index 7b9bc5d..75e70af 100644
--- a/src/components/workshop/Workshop.tsx
+++ b/src/components/workshop/Workshop.tsx
@@ -12,6 +12,7 @@ import type { Plan, ProductSpec } from "@/lib/types";
import { useMounted } from "@/lib/useMounted";
import { peekShot, shot, type Shot } from "@/engine/thumbs";
import Thumb from "../Thumb";
+import Drawing from "../Drawing";
import { Figure, ScaleFigure } from "../art/Figure";
import { IArrowRight, IBox, ICheck, IClock, IClose, ILibrary, IPeople, WarnIcon } from "../art/Icons";
@@ -265,7 +266,7 @@ function GoingRow({ r, onRemove }: { r: Row; onRemove: () => void }) {
return (
<motion.div className="going" layout initial={{ opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, height: 0, marginTop: 0 }} transition={{ duration: 0.3 }}>
<Link href={href} className="going-link">
- <Thumb id={"go-" + p.slug} plan={r.plan} mode={{ kind: "assembled" }} w={150} h={112} className="going-thumb" />
+ {r.spec.source === "catalog" ? <Drawing name={p.slug} w={150} h={112} className="going-thumb" /> : <Thumb id={"go-" + p.slug} plan={r.plan} mode={{ kind: "assembled" }} w={150} h={112} className="going-thumb" />}
<span className="going-text">
<b>{r.spec.name}</b>
<span>{r.spec.variant}</span>
@@ -294,7 +295,7 @@ function BuiltCard({ r, onRemove }: { r: Row; onRemove: () => void }) {
return (
<motion.div className="built" layout initial={{ opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, scale: 0.96 }} transition={{ duration: 0.3 }}>
<Link href={`/build/${p.slug}${p.spec ? `?q=${encodeURIComponent(p.spec.name)}` : ""}`} className="built-link">
- <Thumb id={"bt-" + p.slug} plan={r.plan} mode={{ kind: "assembled" }} w={360} h={270} className="built-thumb" />
+ {r.spec.source === "catalog" ? <Drawing name={p.slug} w={360} h={270} className="built-thumb" /> : <Thumb id={"bt-" + p.slug} plan={r.plan} mode={{ kind: "assembled" }} w={360} h={270} className="built-thumb" />}
<span className="built-text">
<b>{r.spec.name}</b>
<span>{r.spec.variant}</span>