{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"open-passport-card-whose-visa-pages-collect-inked-entry-stamps-and-turn-over-when-the-spread-is-full","type":"registry:block","title":"Open Passport Card Whose Visa Pages Collect Inked Entry Stamps and Turn over When the Spread Is Full","description":"Passport card whose visa pages collect entry stamps in uneven ink, dip under each hit and turn over when the spread is full. Free React and HTML to copy.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/open-passport-card-whose-visa-pages-collect-inked-entry-stamps-and-turn-over-when-the-spread-is-full.tsx","type":"registry:component","content":"import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { animate, motion, useMotionValue, useReducedMotion, useSpring, useTransform } from \"framer-motion\";\n\n/** The border posts. `kind` picks the die, `ink` is its red, green and blue. */\nconst entries: { place: string; kind: \"round\" | \"box\" | \"oval\" | \"octagon\"; word: string; date: string; office: string; ink: [number, number, number] }[] = [\n  { place: \"Port Callow\", kind: \"round\", word: \"ARRIVED\", date: \"14 MAR 2026\", office: \"IMMIGRATION\", ink: [36, 58, 148] },\n  { place: \"Saint Elvary\", kind: \"box\", word: \"ENTRY\", date: \"02 APR 2026\", office: \"HARBOUR CONTROL\", ink: [186, 38, 50] },\n  { place: \"Veyra Islands\", kind: \"oval\", word: \"ADMITTED\", date: \"19 APR 2026\", office: \"FERRY PORT\", ink: [20, 112, 86] },\n  { place: \"Tarnholm\", kind: \"octagon\", word: \"DEPARTED\", date: \"23 APR 2026\", office: \"RAIL BORDER\", ink: [44, 44, 52] },\n  { place: \"Kossu Bay\", kind: \"round\", word: \"TRANSIT\", date: \"06 MAY 2026\", office: \"AIR TERMINAL\", ink: [126, 52, 146] },\n  { place: \"Marrowmere\", kind: \"box\", word: \"ARRIVED\", date: \"30 MAY 2026\", office: \"ROAD CROSSING\", ink: [22, 100, 158] },\n  { place: \"Cape Ilse\", kind: \"oval\", word: \"ENTRY\", date: \"11 JUN 2026\", office: \"SEA PORT\", ink: [188, 88, 22] },\n  { place: \"Dunmarrow\", kind: \"octagon\", word: \"ADMITTED\", date: \"27 JUN 2026\", office: \"NORTH GATE\", ink: [156, 32, 78] },\n];\nconst ISSUER = \"Laurel Sound\";\n\n// Design pixels: one page, the cover that shows round it, and the scene they sit in.\nconst PW = 300;\nconst PH = 426;\nconst EDGE = 10;\nconst SCENE_W = 900;\nconst SCENE_H = 560;\nconst TIP = 24; // degrees the booklet is tipped away\nconst TURN = -7; // degrees it is turned on the desk\nconst PER_SPREAD = 8;\nconst SIZE = { round: [122, 122], box: [136, 86], oval: [142, 94], octagon: [116, 116] } as const;\n// where stamps land on a page when nobody aims them: left page then right page\nconst SLOTS = {\n  L: [\n    { x: 96, y: 118, r: -11 },\n    { x: 204, y: 202, r: 7 },\n    { x: 100, y: 296, r: 5 },\n    { x: 210, y: 356, r: -8 },\n  ],\n  R: [\n    { x: 102, y: 108, r: 8 },\n    { x: 202, y: 176, r: -9 },\n    { x: 96, y: 262, r: -4 },\n    { x: 204, y: 338, r: 12 },\n  ],\n};\nconst ORDER: [\"L\" | \"R\", number][] = [[\"L\", 0], [\"R\", 1], [\"L\", 2], [\"L\", 1], [\"R\", 0], [\"R\", 2], [\"L\", 3], [\"R\", 3]];\nconst START = 3; // stamps already in the book when it opens\n\ntype Mark = { id: number; spread: number; side: \"L\" | \"R\"; x: number; y: number; r: number; die: number; fresh: boolean };\nconst clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));\n\n/** One impression of a die: drawn solid, then starved of ink by noise and by the lean of the hand. */\nfunction impress(i: number) {\n  const e = entries[i];\n  const [w, h] = SIZE[e.kind];\n  const K = 2;\n  const cv = document.createElement(\"canvas\");\n  cv.width = w * K;\n  cv.height = h * K;\n  const c = cv.getContext(\"2d\");\n  if (!c) return \"\";\n  c.scale(K, K);\n  c.fillStyle = \"#000\";\n  c.strokeStyle = \"#000\";\n  c.textAlign = \"center\";\n  c.textBaseline = \"middle\";\n  const cx = w / 2;\n  const cy = h / 2;\n  const sans = (px: number, wt = 800) => `${wt} ${px}px 'Arial Narrow','Helvetica Neue',Helvetica,Arial,sans-serif`;\n  const mono = (px: number) => `700 ${px}px ui-monospace,SFMono-Regular,Menlo,monospace`;\n  const spaced = (text: string, x: number, y: number, gap: number) => {\n    const ws = [...text].map((ch) => c.measureText(ch).width);\n    let pen = x - (ws.reduce((a, b) => a + b, 0) + gap * (text.length - 1)) / 2;\n    [...text].forEach((ch, k) => {\n      c.fillText(ch, pen + ws[k] / 2, y);\n      pen += ws[k] + gap;\n    });\n  };\n  const arc = (text: string, radius: number, top: boolean, gap: number) => {\n    const ws = [...text].map((ch) => c.measureText(ch).width + gap);\n    const total = ws.reduce((a, b) => a + b, 0) / radius;\n    let a = top ? -Math.PI / 2 - total / 2 : Math.PI / 2 + total / 2;\n    [...text].forEach((ch, k) => {\n      const step = ws[k] / radius;\n      const mid = top ? a + step / 2 : a - step / 2;\n      c.save();\n      c.translate(cx + Math.cos(mid) * radius, cy + Math.sin(mid) * radius);\n      c.rotate(top ? mid + Math.PI / 2 : mid - Math.PI / 2);\n      c.fillText(ch, 0, 0);\n      c.restore();\n      a = top ? a + step : a - step;\n    });\n  };\n  const plane = (x: number, y: number, s: number) => {\n    c.save();\n    c.translate(x, y);\n    c.scale(s, s);\n    c.beginPath();\n    c.moveTo(9, 0); c.lineTo(2, -1.4); c.lineTo(-2, -8); c.lineTo(-4.4, -8); c.lineTo(-2.2, -1.5); c.lineTo(-6.5, -1.2); c.lineTo(-8.4, -3.6); c.lineTo(-9.6, -3.6); c.lineTo(-8.6, 0);\n    c.lineTo(-9.6, 3.6); c.lineTo(-8.4, 3.6); c.lineTo(-6.5, 1.2); c.lineTo(-2.2, 1.5); c.lineTo(-4.4, 8); c.lineTo(-2, 8); c.lineTo(2, 1.4);\n    c.closePath();\n    c.fill();\n    c.restore();\n  };\n  const place = e.place.toUpperCase();\n\n  if (e.kind === \"round\") {\n    c.lineWidth = 3; c.beginPath(); c.arc(cx, cy, w / 2 - 3, 0, Math.PI * 2); c.stroke();\n    c.lineWidth = 1; c.beginPath(); c.arc(cx, cy, w / 2 - 8, 0, Math.PI * 2); c.stroke();\n    c.beginPath(); c.arc(cx, cy, w / 2 - 27, 0, Math.PI * 2); c.stroke();\n    c.font = sans(11.5, 900); arc(place, w / 2 - 17.5, true, 2.2);\n    c.font = sans(8.5); arc(e.office, w / 2 - 17.5, false, 2);\n    c.fillRect(cx - w / 2 + 11, cy - 1.5, 5, 3); c.fillRect(cx + w / 2 - 16, cy - 1.5, 5, 3);\n    plane(cx, cy - 17, 0.8);\n    c.font = sans(13.5, 900); spaced(e.word, cx, cy + 1, 1);\n    c.font = mono(7.2); c.fillText(e.date, cx, cy + 15);\n  } else if (e.kind === \"box\") {\n    const box = (x: number, y: number, bw: number, bh: number, r: number) => { c.beginPath(); c.moveTo(x + r, y); c.arcTo(x + bw, y, x + bw, y + bh, r); c.arcTo(x + bw, y + bh, x, y + bh, r); c.arcTo(x, y + bh, x, y, r); c.arcTo(x, y, x + bw, y, r); c.closePath(); c.stroke(); };\n    c.lineWidth = 3; box(2.5, 2.5, w - 5, h - 5, 5);\n    c.lineWidth = 1; box(7.5, 7.5, w - 15, h - 15, 2);\n    c.font = sans(10.5, 900); spaced(place, cx, 19.5, 2);\n    c.fillRect(14, 27, w - 28, 1.2);\n    c.font = sans(24, 900); spaced(e.word, cx, 43.5, 2.4);\n    c.fillRect(14, 58, w - 28, 1.2);\n    c.font = mono(7.4); c.fillText(`${e.date}  ${e.office}`, cx, 67.5, w - 30);\n  } else if (e.kind === \"oval\") {\n    c.lineWidth = 2.8; c.beginPath(); c.ellipse(cx, cy, w / 2 - 3, h / 2 - 3, 0, 0, Math.PI * 2); c.stroke();\n    c.lineWidth = 1; c.beginPath(); c.ellipse(cx, cy, w / 2 - 8, h / 2 - 8, 0, 0, Math.PI * 2); c.stroke();\n    c.font = sans(10.5, 900); spaced(place, cx, cy - 23, 1.8);\n    c.fillRect(cx - 36, cy - 14.5, 72, 1.1);\n    c.font = sans(19, 900); spaced(e.word, cx, cy - 1, 1.6);\n    c.fillRect(cx - 36, cy + 11.5, 72, 1.1);\n    c.font = mono(7.4); c.fillText(e.date, cx, cy + 20);\n    c.font = sans(7); spaced(e.office, cx, cy + 30, 1.4);\n  } else {\n    const ring = (rad: number) => { c.beginPath(); for (let k = 0; k < 8; k++) { const a = Math.PI / 8 + (k * Math.PI) / 4; c[k ? \"lineTo\" : \"moveTo\"](cx + Math.cos(a) * rad, cy + Math.sin(a) * rad); } c.closePath(); c.stroke(); };\n    c.lineWidth = 3; ring(w / 2 - 3);\n    c.lineWidth = 1; ring(w / 2 - 8.5);\n    c.font = sans(10.5, 900); spaced(place, cx, cy - 27, 1.8);\n    plane(cx, cy - 13, 0.62);\n    c.font = sans(16, 900); spaced(e.word, cx, cy + 3, 1.2);\n    c.fillRect(cx - 34, cy + 13, 68, 1.1);\n    c.font = mono(7.2); c.fillText(e.date, cx, cy + 21);\n    c.font = sans(7); spaced(e.office, cx, cy + 31, 1.2);\n  }\n\n  const seed = i * 7.31 + 2.1;\n  const hash = (x: number, y: number) => { const n = Math.sin(x * 127.1 + y * 311.7 + seed * 74.7) * 43758.5453; return n - Math.floor(n); };\n  const soft = (x: number, y: number) => { const xi = Math.floor(x), yi = Math.floor(y), fx = x - xi, fy = y - yi, ux = fx * fx * (3 - 2 * fx), uy = fy * fy * (3 - 2 * fy); return (hash(xi, yi) * (1 - ux) + hash(xi + 1, yi) * ux) * (1 - uy) + (hash(xi, yi + 1) * (1 - ux) + hash(xi + 1, yi + 1) * ux) * uy; };\n  const lean = hash(3, 9) * Math.PI * 2, lx = Math.cos(lean), ly = Math.sin(lean), rock = 0.2 + hash(5, 2) * 0.3, load = 0.86 + hash(8, 1) * 0.3;\n  const img = c.getImageData(0, 0, cv.width, cv.height), d = img.data, W = cv.width, HH = cv.height;\n  for (let y = 0; y < HH; y++) {\n    for (let x = 0; x < W; x++) {\n      const p = (y * W + x) * 4, a = d[p + 3];\n      if (!a) continue;\n      const u = x / W, v = y / HH;\n      const blotch = soft(u * 6, v * 5) * 0.6 + soft(u * 17 + 4, v * 15 + 4) * 0.4;\n      const cover = load * 1.25 - 0.4 + (blotch - 0.5) * 1.1 + (lx * (u - 0.5) * 2 + ly * (v - 0.5) * 2) * rock;\n      let t = clamp(cover / 0.5, 0, 1); t = t * t * (3 - 2 * t);\n      let alpha = t * (0.78 + 0.22 * hash(x, y));\n      if (hash(Math.floor(x / 2) + 40, Math.floor(y / 2)) < 0.05 + 0.22 * (1 - t)) alpha *= 0.25;\n      const deep = 1 - 0.2 * t * blotch;\n      d[p] = e.ink[0] * deep; d[p + 1] = e.ink[1] * deep; d[p + 2] = e.ink[2] * deep; d[p + 3] = a * alpha * 0.92;\n    }\n  }\n  c.putImageData(img, 0, 0);\n  return cv.toDataURL();\n}\n\n/** The printed background of a visa page: crossing wave lines and a lobed rosette, as on any security paper. */\nfunction Printing({ flip }: { flip: boolean }) {\n  const art = useMemo(() => {\n    const waves: string[] = [];\n    for (let k = 0; k < 16; k++) {\n      let dd = \"\";\n      for (let x = -4; x <= PW + 4; x += 6) {\n        const y = 34 + k * 24 + Math.sin(x * 0.045 + k * 0.9) * 9 + Math.sin(x * 0.11 + k) * 2.5;\n        dd += `${x === -4 ? \"M\" : \"L\"}${x} ${y.toFixed(1)}`;\n      }\n      waves.push(dd);\n    }\n    const cross: string[] = [];\n    for (let k = 0; k < 16; k++) {\n      let dd = \"\";\n      for (let x = -4; x <= PW + 4; x += 6) {\n        const y = 46 + k * 24 - Math.sin(x * 0.045 + k * 0.9 + 1.4) * 9;\n        dd += `${x === -4 ? \"M\" : \"L\"}${x} ${y.toFixed(1)}`;\n      }\n      cross.push(dd);\n    }\n    const rosette = [0, 1, 2, 3, 4, 5, 6, 7].map((n) => {\n      let dd = \"\";\n      for (let s = 0; s <= 360; s += 1) {\n        const a = (s * Math.PI) / 180;\n        const rad = 50 + (n % 4) * 7 + 13 * Math.sin(a * 14 + (n * Math.PI) / 4) * (n < 4 ? 1 : 0.45);\n        dd += `${s ? \"L\" : \"M\"}${(PW / 2 + Math.cos(a) * rad).toFixed(1)} ${(PH / 2 + 6 + Math.sin(a) * rad).toFixed(1)}`;\n      }\n      return dd + \"Z\";\n    });\n    return { waves, cross, rosette };\n  }, []);\n  return (\n    <svg aria-hidden=\"true\" viewBox={`0 0 ${PW} ${PH}`} className=\"pointer-events-none absolute inset-0 h-full w-full\" style={{ transform: flip ? \"scaleX(-1)\" : undefined }} fill=\"none\">\n      {art.waves.map((dd, k) => (\n        <path key={k} d={dd} stroke=\"#4f97a3\" strokeOpacity=\"0.3\" strokeWidth=\"0.6\" />\n      ))}\n      {art.cross.map((dd, k) => (\n        <path key={k} d={dd} stroke=\"#c9836d\" strokeOpacity=\"0.26\" strokeWidth=\"0.6\" />\n      ))}\n      {art.rosette.map((dd, k) => (\n        <path key={k} d={dd} stroke={k % 2 ? \"#c9836d\" : \"#3f8a97\"} strokeOpacity=\"0.42\" strokeWidth=\"0.45\" />\n      ))}\n    </svg>\n  );\n}\n\nfunction Page({ side, no, marks, inks, still, onAim }: { side: \"L\" | \"R\"; no: number; marks: Mark[]; inks: string[]; still: boolean; onAim?: (side: \"L\" | \"R\", x: number, y: number) => void }) {\n  const left = side === \"L\";\n  return (\n    <div\n      onClick={onAim ? (e) => onAim(side, e.nativeEvent.offsetX, e.nativeEvent.offsetY) : undefined}\n      className={`absolute inset-0 overflow-hidden bg-[#efe6d0] ${left ? \"rounded-l-[9px] rounded-r-[2px]\" : \"rounded-l-[2px] rounded-r-[9px]\"} ${onAim ? \"cursor-crosshair\" : \"\"}`}\n    >\n      <Printing flip={left} />\n      <div className={`pointer-events-none absolute top-[17px] flex items-baseline gap-[10px] font-mono text-[7.5px] font-semibold uppercase leading-none tracking-[0.3em] text-[#6b5a45] ${left ? \"left-[20px]\" : \"right-[20px] flex-row-reverse\"}`}>\n        <span>Visas</span>\n        <span className=\"text-[#93826a]\">{ISSUER}</span>\n      </div>\n      <div className={`pointer-events-none absolute bottom-[15px] font-serif text-[13px] leading-none text-[#6b5a45] ${left ? \"left-[20px]\" : \"right-[20px]\"}`}>{no}</div>\n      <div className={`pointer-events-none absolute bottom-[16px] font-mono text-[8px] font-semibold leading-none tracking-[0.34em] text-[#a3927a] ${left ? \"right-[26px]\" : \"left-[26px]\"}`}>LS 7204915</div>\n\n      {inks.length > 0 &&\n        marks.map((m) => {\n          const e = entries[m.die];\n          const [w, h] = SIZE[e.kind];\n          const move = m.fresh && !still;\n          return (\n            <div key={m.id} className=\"pointer-events-none absolute\" style={{ left: m.x - w / 2, top: m.y - h / 2, width: w, height: h, transform: `rotate(${m.r}deg)` }}>\n              <motion.img\n                src={inks[m.die]}\n                alt={`${e.word.toLowerCase()} stamp from ${e.place}, ${e.date}`}\n                draggable={false}\n                className=\"absolute inset-0 h-full w-full mix-blend-multiply\"\n                initial={move ? { opacity: 0, scale: 1.05, filter: \"saturate(1.9) brightness(0.62) blur(0.7px)\" } : false}\n                animate={{ opacity: 1, scale: 1, filter: \"saturate(1) brightness(1) blur(0px)\" }}\n                transition={{ opacity: { delay: 0.15, duration: 0.03 }, scale: { delay: 0.15, duration: 0.09 }, filter: { delay: 0.2, duration: 1.5, ease: \"easeOut\" } }}\n              />\n              {/* the shadow of the hand stamp coming down on this spot and leaving again */}\n              {move && (\n                <motion.div\n                  aria-hidden=\"true\"\n                  className=\"absolute -inset-[8px] rounded-[22px] bg-[#1b0f08]\"\n                  style={{ filter: \"blur(9px)\" }}\n                  initial={{ opacity: 0, scale: 1.9, x: 46, y: 54 }}\n                  animate={{ opacity: [0, 0.62, 0.5, 0], scale: [1.9, 1.02, 1.05, 1.8], x: [46, 2, 4, 40], y: [54, 3, 5, 46] }}\n                  transition={{ duration: 0.52, times: [0, 0.29, 0.42, 1], ease: \"easeInOut\" }}\n                />\n              )}\n            </div>\n          );\n        })}\n\n      {/* the page dips into the stitching and catches light where it rises out of it */}\n      <div\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0\"\n        style={{ background: `linear-gradient(${left ? 270 : 90}deg, rgba(40,22,8,0.5) 0%, rgba(40,22,8,0.2) 3.5%, rgba(40,22,8,0.05) 9%, rgba(255,255,255,0.3) 17%, rgba(255,255,255,0) 36%, rgba(40,22,8,0) 74%, rgba(40,22,8,0.1) 100%)` }}\n      />\n      <svg aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 h-full w-full opacity-40 mix-blend-multiply\">\n        <rect width=\"100%\" height=\"100%\" filter=\"url(#passport-stamps-fibre)\" />\n      </svg>\n    </div>\n  );\n}\n\nconst firstMarks: Mark[] = ORDER.slice(0, START).map(([side, n], i) => ({ id: i, spread: 0, side, ...SLOTS[side][n], die: i, fresh: false }));\nconst fullMarks: Mark[] = ORDER.map(([side, n], i) => ({ id: i, spread: 0, side, ...SLOTS[side][n], die: i % entries.length, fresh: false }));\nconst stack = (dir: 1 | -1) => [1, 2, 3, 4, 5].map((n) => `${dir * n * 1.1}px ${n * 0.9}px 0 ${n % 2 ? \"#cfc3a6\" : \"#f3ebd8\"}`).join(\", \");\n\nexport default function PassportStampCard() {\n  const reduce = !!useReducedMotion();\n  const wrapRef = useRef<HTMLDivElement>(null);\n  const sceneRef = useRef<HTMLDivElement>(null);\n  const live = useRef({ touched: false, paused: false, clock: 0, id: 100, die: START, used: START, spread: 0, turning: false, wait: 0 });\n  const [inks, setInks] = useState<string[]>([]);\n  const [marks, setMarks] = useState<Mark[]>(firstMarks);\n  const [spread, setSpread] = useState(0);\n  const [turning, setTurning] = useState(false);\n  const [said, setSaid] = useState(\"\");\n  const [nextDie, setNextDie] = useState(START);\n\n  const px = useMotionValue(0);\n  const py = useMotionValue(0);\n  const rz = useSpring(useTransform(px, (v) => TURN + v * 4), { stiffness: 60, damping: 14 });\n  const rx = useSpring(useTransform(py, (v) => TIP - v * 5), { stiffness: 60, damping: 14 });\n  const jolt = useMotionValue(0);\n  const dip = useTransform(jolt, (v) => -v * 9);\n  const nod = useTransform(jolt, (v) => v * 1.1);\n  const turn = useMotionValue(0);\n  const leafAngle = useTransform(turn, (v) => -180 * v);\n  const leafFront = useTransform(turn, (v) => clamp(v * 1.3, 0, 0.55));\n  const leafBack = useTransform(turn, (v) => clamp((1 - v) * 1.1, 0, 0.5));\n  const castRight = useTransform(turn, (v) => Math.sin(Math.min(1, v * 2) * Math.PI * 0.5) * (v < 0.5 ? 0.5 : 1 - v) * 1.1);\n  const castLeft = useTransform(turn, (v) => (v > 0.4 ? Math.sin(((v - 0.4) / 0.6) * Math.PI) * 0.8 : 0));\n\n  useEffect(() => {\n    setInks(entries.map((_, i) => impress(i)));\n  }, []);\n  useEffect(() => {\n    if (!reduce) return;\n    live.current.used = PER_SPREAD;\n    live.current.die = PER_SPREAD;\n    setMarks(fullMarks);\n    setNextDie(PER_SPREAD % entries.length);\n  }, [reduce]);\n\n  const leaf = useCallback(() => {\n    const s = live.current;\n    if (s.turning) return;\n    s.turning = true;\n    const land = () => {\n      s.spread += 1;\n      s.used = 0;\n      s.turning = false;\n      s.clock = 0;\n      setSpread(s.spread);\n      setMarks((all) => all.filter((m) => m.spread >= s.spread));\n      setTurning(false);\n      turn.set(0);\n    };\n    setTurning(true);\n    if (reduce) land();\n    else animate(turn, 1, { duration: 1.15, ease: [0.5, 0, 0.2, 1] }).then(land);\n  }, [reduce, turn]);\n\n  const stamp = useCallback(\n    (at?: { side: \"L\" | \"R\"; x: number; y: number }) => {\n      const s = live.current;\n      if (s.turning) return;\n      if (s.used >= PER_SPREAD + 4) return leaf();\n      const die = s.die % entries.length;\n      const [side, n] = ORDER[s.used % ORDER.length];\n      const slot = SLOTS[side][n];\n      const [w, h] = SIZE[entries[die].kind];\n      const spot = at ? { side: at.side, x: clamp(at.x, w / 2 + 4, PW - w / 2 - 4), y: clamp(at.y, h / 2 + 26, PH - h / 2 - 26), r: ((s.id * 37) % 25) - 12 } : { side, ...slot };\n      s.id += 1;\n      s.die += 1;\n      s.used += 1;\n      s.clock = 0;\n      setMarks((all) => [...all, { id: s.id, spread: s.spread, ...spot, die, fresh: true }]);\n      setNextDie(s.die % entries.length);\n      setSaid(`Stamped ${entries[die].place}: ${entries[die].word.toLowerCase()} ${entries[die].date}.`);\n      if (!reduce) animate(jolt, [0, 0, 1, -0.25, 0], { duration: 0.5, times: [0, 0.28, 0.36, 0.6, 1], ease: \"easeOut\" });\n    },\n    [jolt, leaf, reduce],\n  );\n\n  // the demo: a stamp every half second or so, and a fresh leaf once the spread is full\n  useEffect(() => {\n    if (reduce) return;\n    const s = live.current;\n    const tick = window.setInterval(() => {\n      if (s.paused || document.hidden || s.turning) return;\n      s.clock += 100;\n      if (s.used >= PER_SPREAD) {\n        if (s.clock >= (s.touched ? 1500 : 2600)) leaf();\n      } else if (!s.touched && s.clock >= (s.spread === 0 && s.used === START ? 500 : 560)) stamp();\n    }, 100);\n    return () => window.clearInterval(tick);\n  }, [leaf, reduce, stamp]);\n\n  useEffect(() => {\n    const wrap = wrapRef.current;\n    const scene = sceneRef.current;\n    if (!wrap || !scene) return;\n    const measure = () => {\n      const sc = clamp(wrap.clientWidth / (SCENE_W - 190), 0.44, 1.26);\n      wrap.style.height = `${Math.round(SCENE_H * sc + 64)}px`;\n      scene.style.transform = `translateX(-50%) scale(${sc.toFixed(4)})`;\n    };\n    measure();\n    const ro = new ResizeObserver(measure);\n    ro.observe(wrap);\n    return () => ro.disconnect();\n  }, []);\n\n  const aim = (side: \"L\" | \"R\", x: number, y: number) => {\n    live.current.touched = true;\n    stamp({ side, x, y });\n  };\n  const on = (s: number, side: \"L\" | \"R\") => marks.filter((m) => m.spread === s && m.side === side);\n  const leftNo = 8 + spread * 2;\n  const next = entries[nextDie];\n  const BW = PW * 2 + EDGE * 2;\n  const BH = PH + EDGE * 2;\n\n  return (\n    <section className=\"relative overflow-hidden bg-[#12343b]\">\n      <svg aria-hidden=\"true\" width=\"0\" height=\"0\" className=\"absolute\">\n        <filter id=\"passport-stamps-fibre\" x=\"0\" y=\"0\" width=\"100%\" height=\"100%\">\n          <feTurbulence type=\"fractalNoise\" baseFrequency=\"0.8 0.6\" numOctaves=\"3\" seed=\"11\" />\n          <feColorMatrix type=\"matrix\" values=\"0 0 0 0 0.4  0 0 0 0 0.3  0 0 0 0 0.18  0.9 0 0 0 -0.3\" />\n        </filter>\n        <filter id=\"passport-stamps-hide\" x=\"0\" y=\"0\" width=\"100%\" height=\"100%\">\n          <feTurbulence type=\"fractalNoise\" baseFrequency=\"1.3\" numOctaves=\"2\" seed=\"4\" />\n          <feColorMatrix type=\"matrix\" values=\"0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  1.5 0 0 0 -0.5\" />\n        </filter>\n      </svg>\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\" style={{ background: \"radial-gradient(66% 62% at 46% 38%, #24606a 0%, #174650 44%, #0c262c 100%)\" }} />\n      <div\n        ref={wrapRef}\n        onPointerMove={(e) => {\n          if (reduce || e.pointerType === \"touch\") return;\n          const r = e.currentTarget.getBoundingClientRect();\n          px.set(((e.clientX - r.left) / r.width) * 2 - 1);\n          py.set(((e.clientY - r.top) / r.height) * 2 - 1);\n        }}\n        onPointerEnter={(e) => {\n          if (e.pointerType !== \"touch\") live.current.paused = true;\n        }}\n        onPointerLeave={() => {\n          live.current.paused = false;\n          px.set(0);\n          py.set(0);\n        }}\n        className=\"relative mx-auto w-full overflow-hidden\"\n        style={{ height: SCENE_H * 1.26 + 64 }}\n      >\n        <div ref={sceneRef} className=\"absolute left-1/2 top-0 select-none\" style={{ width: SCENE_W, height: SCENE_H, transformOrigin: \"50% 0\", transform: \"translateX(-50%)\", perspective: \"2200px\", perspectiveOrigin: \"50% 30%\" }}>\n          <motion.div className=\"absolute\" style={{ left: SCENE_W / 2 - BW / 2, top: SCENE_H / 2 - BH / 2 - 4, width: BW, height: BH, transformStyle: \"preserve-3d\", rotateX: rx, rotateZ: rz }}>\n            {/* shadows on the desk */}\n            <div aria-hidden=\"true\" className=\"absolute rounded-[20px] bg-black\" style={{ left: 10, top: 22, width: BW + 26, height: BH + 22, filter: \"blur(26px)\", opacity: 0.5, transform: \"translateZ(-16px)\" }} />\n            <div aria-hidden=\"true\" className=\"absolute rounded-[16px] bg-black\" style={{ left: 3, top: 6, width: BW, height: BH + 2, filter: \"blur(5px)\", opacity: 0.6, transform: \"translateZ(-15px)\" }} />\n\n            <motion.div className=\"absolute inset-0\" style={{ transformStyle: \"preserve-3d\", z: dip, rotateX: nod }}>\n              {/* the cover, seen as a leather border round the pages */}\n              <div className=\"absolute inset-0 overflow-hidden rounded-[15px] bg-[#641826]\" style={{ boxShadow: \"inset 0 1px 0 rgba(255,190,190,0.35), inset 0 -2px 2px rgba(0,0,0,0.45), 0 2px 0 #3b0c15, 0 3.5px 0 #2a080f\" }}>\n                <svg aria-hidden=\"true\" className=\"absolute inset-0 h-full w-full opacity-50\">\n                  <rect width=\"100%\" height=\"100%\" filter=\"url(#passport-stamps-hide)\" />\n                </svg>\n                <div aria-hidden=\"true\" className=\"absolute inset-0\" style={{ background: \"linear-gradient(120deg, rgba(255,200,200,0.22), rgba(255,255,255,0) 30%, rgba(0,0,0,0.25) 100%)\" }} />\n              </div>\n\n              {/* left and right blocks of pages */}\n              <div className=\"absolute\" style={{ left: EDGE, top: EDGE - 3, width: PW, height: PH, borderRadius: \"9px 2px 2px 9px\", boxShadow: stack(-1), background: \"#efe6d0\" }}>\n                <Page side=\"L\" no={leftNo} marks={on(spread, \"L\")} inks={inks} still={reduce} onAim={turning ? undefined : aim} />\n                <motion.div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 rounded-l-[9px]\" style={{ opacity: castLeft, background: \"linear-gradient(270deg, rgba(20,10,4,0.75), rgba(20,10,4,0.2) 60%, rgba(20,10,4,0))\" }} />\n              </div>\n              <div className=\"absolute\" style={{ left: EDGE + PW, top: EDGE - 3, width: PW, height: PH, borderRadius: \"2px 9px 9px 2px\", boxShadow: stack(1), background: \"#efe6d0\" }}>\n                <Page side=\"R\" no={leftNo + (turning ? 3 : 1)} marks={on(spread + (turning ? 1 : 0), \"R\")} inks={inks} still={reduce} onAim={turning ? undefined : aim} />\n                <motion.div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 rounded-r-[9px]\" style={{ opacity: castRight, background: \"linear-gradient(90deg, rgba(20,10,4,0.8), rgba(20,10,4,0.25) 55%, rgba(20,10,4,0))\" }} />\n              </div>\n\n              {/* the leaf in the air while a full spread turns over */}\n              {turning && !reduce && (\n                <motion.div className=\"absolute\" style={{ left: EDGE + PW, top: EDGE - 3, width: PW, height: PH, transformOrigin: \"0% 50%\", transformStyle: \"preserve-3d\", rotateY: leafAngle, z: 1.5 }}>\n                  <div className=\"absolute inset-0\" style={{ backfaceVisibility: \"hidden\", WebkitBackfaceVisibility: \"hidden\" }}>\n                    <Page side=\"R\" no={leftNo + 1} marks={on(spread, \"R\")} inks={inks} still />\n                    <motion.div aria-hidden=\"true\" className=\"absolute inset-0 rounded-r-[9px] bg-[#1c0f06]\" style={{ opacity: leafFront }} />\n                  </div>\n                  <div className=\"absolute inset-0\" style={{ transform: \"rotateY(180deg)\", backfaceVisibility: \"hidden\", WebkitBackfaceVisibility: \"hidden\" }}>\n                    <Page side=\"L\" no={leftNo + 2} marks={[]} inks={inks} still />\n                    <motion.div aria-hidden=\"true\" className=\"absolute inset-0 rounded-l-[9px] bg-[#1c0f06]\" style={{ opacity: leafBack }} />\n                  </div>\n                </motion.div>\n              )}\n\n              {/* the stitching down the fold */}\n              <div aria-hidden=\"true\" className=\"pointer-events-none absolute\" style={{ left: BW / 2 - 1, top: EDGE + 14, width: 2, height: PH - 34, transform: \"translateZ(0.6px)\", background: \"repeating-linear-gradient(180deg, #f6eedb 0 30px, rgba(0,0,0,0) 30px 42px)\", boxShadow: \"1px 1px 1px rgba(30,15,5,0.55)\", borderRadius: 1 }} />\n            </motion.div>\n          </motion.div>\n        </div>\n\n        <p className=\"pointer-events-none absolute bottom-5 left-5 hidden font-mono text-[11px] uppercase leading-relaxed tracking-[0.18em] text-teal-100/80 sm:bottom-8 sm:left-8 sm:block\">\n          <span className=\"text-white\">\n            {ISSUER} / pages {leftNo} and {leftNo + 1}\n          </span>\n          <span className=\"block\">Click a page to stamp it there</span>\n        </p>\n        <button\n          type=\"button\"\n          onClick={() => {\n            live.current.touched = true;\n            stamp();\n          }}\n          className=\"absolute bottom-4 right-4 inline-flex min-h-[44px] items-center gap-2 rounded-full bg-[#efe6d0] px-5 text-[13px] font-semibold text-[#2a1508] shadow-[0_6px_18px_rgba(0,0,0,0.35)] outline-none transition-transform hover:-translate-y-0.5 focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-offset-2 focus-visible:ring-offset-[#12343b] active:translate-y-0 motion-reduce:transition-none sm:bottom-7 sm:right-8\"\n        >\n          <span aria-hidden=\"true\" className=\"h-2.5 w-2.5 rounded-full\" style={{ background: `rgb(${next.ink.join(\",\")})` }} />\n          Stamp {next.place}\n        </button>\n        <p aria-live=\"polite\" className=\"sr-only\">\n          {said}\n        </p>\n      </div>\n    </section>\n  );\n}\n"}]}
