{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"hand-gilded-shop-fascia-headline-where-gold-leaf-is-laid-brushed-off-and-burnished","type":"registry:component","title":"Hand-Gilded Shop Fascia Headline Where Gold Leaf Is Laid, Brushed Off and Burnished","description":"Canvas text effect: a painted shop fascia whose name is gilded as you watch, with gold leaf laid, brushed off and burnished. Free React and HTML to copy.","dependencies":[],"files":[{"path":"components/we-inc/hand-gilded-shop-fascia-headline-where-gold-leaf-is-laid-brushed-off-and-burnished.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n/** The name in gold leaf and the painted line under it. */\nconst NAME = \"MARIGOLD\";\nconst TRADE = \"CUT FLOWERS & HOUSE PLANTS\";\n/** Gloss paint of the shopfront: light, body, deep shadow. Try [\"#7a2330\", \"#571722\", \"#330c13\"] for claret. */\nconst PAINT = [\"#1f5a47\", \"#12392c\", \"#08211a\"];\nconst FACE = '\"Bodoni 72\", Didot, \"Bodoni MT\", \"Playfair Display\", Georgia, \"Times New Roman\", serif';\nconst SLUG = \"hand-gilded-shop-fascia\";\n\ntype Leaf = { x: number; y: number; rot: number; flip: number; at: number };\ntype Flake = { x: number; y: number; vx: number; vy: number; rot: number; vr: number; size: number; life: number; tone: number; phase: number };\n\nconst cleanName = (raw: string) => raw.toUpperCase().replace(/[^A-Z0-9 &'.\\-]/g, \"\").slice(0, 14);\nconst cleanTrade = (raw: string) => raw.toUpperCase().replace(/[^A-Z0-9 &'.,\\-]/g, \"\").slice(0, 34);\n\nexport default function HandGildedShopFascia() {\n  const wrap = useRef<HTMLDivElement>(null);\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const [name, setName] = useState(NAME);\n  const [trade, setTrade] = useState(TRADE);\n  const api = useRef<{ set: (name: string, trade: string) => void; again: () => void } | null>(null);\n\n  useEffect(() => {\n    const cv = canvas.current, box = wrap.current;\n    if (!cv || !box) return;\n    const ctx = cv.getContext(\"2d\");\n    if (!ctx) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const dpr = Math.min(2, window.devicePixelRatio || 1);\n    const make = () => document.createElement(\"canvas\");\n    const base = make(), mask = make(), hole = make(), gold = make(), temp = make(), loose = make();\n    let seed = 11;\n    const rand = () => { seed = (seed * 16807) % 2147483647; return seed / 2147483647; };\n    const words = { name: NAME, trade: TRADE };\n\n    // All measurements are in canvas pixels.\n    const g = { W: 0, H: 0, px: 0, py: 0, pw: 0, ph: 0, fx: 0, fy: 0, fw: 0, fh: 0, size: 0, track: 0, cy: 0, x0: 0, tw: 0, rx: 0, ry: 0, rw: 0, rh: 0, s: 0 };\n    let leaves: Leaf[] = [], flakes: Flake[] = [], specks: number[][] = [];\n    const time = { lay: 0.12, step: 0.07, wipe: 1, wipeFor: 0.55, burn: 1.6, burnFor: 0.6 };\n\n    const spaced = (c: CanvasRenderingContext2D, text: string, cx: number, y: number, track: number, stroke = false) => {\n      const widths = [...text].map((ch) => c.measureText(ch).width);\n      let x = cx - (widths.reduce((a, b) => a + b, 0) + track * (text.length - 1)) / 2;\n      c.textAlign = \"left\";\n      [...text].forEach((ch, i) => { if (stroke) c.strokeText(ch, x, y); else c.fillText(ch, x, y); x += widths[i] + track; });\n    };\n    const widthOf = (c: CanvasRenderingContext2D, text: string, track: number) => [...text].reduce((a, ch) => a + c.measureText(ch).width, 0) + track * Math.max(0, text.length - 1);\n\n    // One book-leaf of gold: thin enough to crinkle, never quite one colour.\n    const paintLeaf = (cvs: HTMLCanvasElement, s: number, crinkle: number, ragged: boolean) => {\n      cvs.width = cvs.height = Math.ceil(s);\n      const c = cvs.getContext(\"2d\"); if (!c) return;\n      const m = c.createLinearGradient(0, 0, s, s);\n      m.addColorStop(0, \"#f3d572\"); m.addColorStop(0.35, \"#dcb146\"); m.addColorStop(0.62, \"#efce66\"); m.addColorStop(1, \"#c79a30\");\n      c.fillStyle = m; c.fillRect(0, 0, s, s);\n      // Patches where the sheet lies a little off the surface, then creases: a few long folds and many short ones.\n      for (let i = 0; i < 7; i++) {\n        const x = rand() * s, y = rand() * s, rr = s * (0.14 + rand() * 0.24), tone = c.createRadialGradient(x, y, 0, x, y, rr), a = (0.1 + rand() * 0.14) * crinkle;\n        tone.addColorStop(0, rand() > 0.5 ? `rgba(255,246,196,${a})` : `rgba(122,80,10,${a})`); tone.addColorStop(1, \"rgba(200,150,40,0)\");\n        c.fillStyle = tone; c.fillRect(0, 0, s, s);\n      }\n      for (let i = 0; i < 34 * crinkle; i++) {\n        const long = i < 3, x = rand() * s, y = rand() * s, a = rand() * 6.3, len = s * (long ? 0.5 + rand() * 0.5 : 0.04 + rand() * 0.16), alpha = (long ? 0.34 : 0.12 + rand() * 0.3) * crinkle, kink = (rand() - 0.5) * len * 0.16;\n        c.lineWidth = long ? 1.4 : 0.5 + rand() * 0.9;\n        for (const [dx, col] of [[0, `rgba(255,250,214,${alpha})`], [c.lineWidth, `rgba(104,66,6,${alpha * 0.75})`]] as [number, string][]) {\n          c.strokeStyle = col; c.beginPath(); c.moveTo(x + dx, y + dx);\n          c.lineTo(x + Math.cos(a) * len * 0.5 - Math.sin(a) * kink + dx, y + Math.sin(a) * len * 0.5 + Math.cos(a) * kink + dx); c.lineTo(x + Math.cos(a) * len + dx, y + Math.sin(a) * len + dx); c.stroke();\n        }\n      }\n      for (let i = 0; i < s * 3; i++) { c.fillStyle = rand() > 0.5 ? \"rgba(255,250,210,0.14)\" : \"rgba(90,58,6,0.12)\"; c.fillRect(rand() * s, rand() * s, 1, 1); }\n      if (ragged) {\n        c.globalCompositeOperation = \"destination-out\";\n        for (let i = 0; i < 16; i++) { const side = Math.floor(rand() * 4), p = rand() * s, d = s * (0.006 + rand() * 0.02); c.beginPath(); if (side === 0) { c.moveTo(p - d, 0); c.lineTo(p, d * 1.4); c.lineTo(p + d, 0); } else if (side === 1) { c.moveTo(p - d, s); c.lineTo(p, s - d * 1.4); c.lineTo(p + d, s); } else if (side === 2) { c.moveTo(0, p - d); c.lineTo(d * 1.4, p); c.lineTo(0, p + d); } else { c.moveTo(s, p - d); c.lineTo(s - d * 1.4, p); c.lineTo(s, p + d); } c.fill(); }\n      }\n    };\n\n    const build = () => {\n      const cssW = Math.min(box.clientWidth, 1000), narrow = cssW < 560;\n      const cssH = Math.round(cssW * (narrow ? 0.8 : 0.4));\n      cv.width = Math.round(cssW * dpr); cv.height = Math.round(cssH * dpr); cv.style.height = `${cssH}px`;\n      for (const c of [base, temp]) { c.width = cv.width; c.height = cv.height; }\n      const W = (g.W = cv.width), H = (g.H = cv.height);\n      const side = W * 0.03, eave = H * 0.13, drop = H * 0.11;\n      g.px = side; g.py = eave; g.pw = W - side * 2; g.ph = H - eave - drop;\n      const mould = g.ph * 0.075;\n      g.fx = g.px + mould; g.fy = g.py + mould; g.fw = g.pw - mould * 2; g.fh = g.ph - mould * 2;\n      const c = base.getContext(\"2d\"); if (!c) return;\n      c.clearRect(0, 0, W, H);\n      seed = 11;\n\n      // Shadow on the wall, then the painted board.\n      c.save(); c.shadowColor = \"rgba(40,36,24,0.5)\"; c.shadowBlur = H * 0.06; c.shadowOffsetY = H * 0.035; c.fillStyle = \"#000\"; c.fillRect(g.px + 4, g.py + 4, g.pw - 8, g.ph - 8); c.restore();\n      const paint = c.createLinearGradient(0, g.py, 0, g.py + g.ph); paint.addColorStop(0, PAINT[0]); paint.addColorStop(0.45, PAINT[1]); paint.addColorStop(1, PAINT[2]);\n      c.fillStyle = paint; c.fillRect(g.px, g.py, g.pw, g.ph);\n      // Brush marks left in the gloss, and the sky it reflects.\n      c.save(); c.beginPath(); c.rect(g.fx, g.fy, g.fw, g.fh); c.clip();\n      for (let i = 0; i < 260; i++) { const y = g.fy + rand() * g.fh, x = g.fx + rand() * g.fw, len = g.fw * (0.1 + rand() * 0.5); c.fillStyle = rand() > 0.5 ? `rgba(255,255,255,${0.012 + rand() * 0.03})` : `rgba(0,0,0,${0.02 + rand() * 0.05})`; c.fillRect(x, y, len, Math.max(1, dpr * (0.5 + rand()))); }\n      const sky = c.createLinearGradient(g.fx, g.fy, g.fx + g.fw * 0.5, g.fy + g.fh); sky.addColorStop(0, \"rgba(214,238,226,0.2)\"); sky.addColorStop(0.3, \"rgba(214,238,226,0.05)\"); sky.addColorStop(0.6, \"rgba(214,238,226,0)\");\n      c.fillStyle = sky; c.fillRect(g.fx, g.fy, g.fw, g.fh);\n      const well = c.createLinearGradient(0, g.fy, 0, g.fy + g.fh * 0.3); well.addColorStop(0, \"rgba(0,0,0,0.5)\"); well.addColorStop(1, \"rgba(0,0,0,0)\");\n      c.fillStyle = well; c.fillRect(g.fx, g.fy, g.fw, g.fh * 0.3);\n      c.restore();\n      // The moulding round the field: four mitred lengths, each lit from above.\n      const quad = (pts: number[], fill: string | CanvasGradient) => { c.beginPath(); c.moveTo(pts[0], pts[1]); for (let i = 2; i < pts.length; i += 2) c.lineTo(pts[i], pts[i + 1]); c.closePath(); c.fillStyle = fill; c.fill(); };\n      const x0 = g.px, y0 = g.py, x1 = g.px + g.pw, y1 = g.py + g.ph, m = mould;\n      const lit = (a: string, b: string, c2: string, ax: number, ay: number, bx: number, by: number) => { const gr = c.createLinearGradient(ax, ay, bx, by); gr.addColorStop(0, a); gr.addColorStop(0.5, b); gr.addColorStop(1, c2); return gr; };\n      quad([x0, y0, x1, y0, x1 - m, y0 + m, x0 + m, y0 + m], lit(\"#4d9079\", PAINT[0], \"#0c2a20\", 0, y0, 0, y0 + m));\n      quad([x0, y1, x1, y1, x1 - m, y1 - m, x0 + m, y1 - m], lit(\"#03120d\", PAINT[2], \"#2c6e59\", 0, y1, 0, y1 - m));\n      quad([x0, y0, x0 + m, y0 + m, x0 + m, y1 - m, x0, y1], lit(\"#3f8570\", PAINT[1], \"#0a251c\", x0, 0, x0 + m, 0));\n      quad([x1, y0, x1 - m, y0 + m, x1 - m, y1 - m, x1, y1], lit(\"#04150f\", PAINT[2], \"#1f5a47\", x1, 0, x1 - m, 0));\n      c.strokeStyle = \"rgba(0,0,0,0.55)\"; c.lineWidth = dpr; c.strokeRect(g.fx - 0.5, g.fy - 0.5, g.fw + 1, g.fh + 1);\n      // A lining in gold paint with nipped corners.\n      const q = g.fh * 0.085, r = g.fh * 0.07, lx0 = g.fx + q, ly0 = g.fy + q, lx1 = g.fx + g.fw - q, ly1 = g.fy + g.fh - q;\n      const liner = (off: number) => { c.beginPath(); c.moveTo(lx0 + r, ly0 + off); c.lineTo(lx1 - r, ly0 + off); c.arc(lx1, ly0 + off, r, Math.PI, Math.PI / 2, true); c.lineTo(lx1, ly1 - r + off); c.arc(lx1, ly1 + off, r, -Math.PI / 2, Math.PI, true); c.lineTo(lx0 + r, ly1 + off); c.arc(lx0, ly1 + off, r, 0, -Math.PI / 2, true); c.lineTo(lx0, ly0 + r + off); c.arc(lx0, ly0 + off, r, Math.PI / 2, 0, true); c.stroke(); };\n      const gilt = c.createLinearGradient(g.fx, 0, g.fx + g.fw, 0);\n      ([[0, \"#b88c30\"], [0.2, \"#ecd07a\"], [0.42, \"#c39a3c\"], [0.63, \"#f3dc90\"], [0.82, \"#bf953a\"], [1, \"#e6c96f\"]] as [number, string][]).forEach(([p, col]) => gilt.addColorStop(p, col));\n      c.lineWidth = Math.max(1.5, g.fh * 0.008); c.strokeStyle = \"rgba(0,0,0,0.5)\"; liner(c.lineWidth); c.strokeStyle = gilt; liner(0);\n      // The cornice over the board and the shadow it drops, then the sill underneath.\n      const bands: [number, number, string, string][] = [[0, 0.2, \"#5a9c85\", \"#2f745f\"], [0.2, 0.62, \"#2a6c58\", \"#0e3024\"], [0.62, 0.78, \"#3d826c\", \"#1b4f3f\"], [0.78, 1, \"#143d30\", \"#06180f\"]];\n      for (const [a, b, top, bot] of bands) { const inset = a * side * 0.9, gr = c.createLinearGradient(0, eave * a, 0, eave * b); gr.addColorStop(0, top); gr.addColorStop(1, bot); c.fillStyle = gr; c.fillRect(inset, eave * a, W - inset * 2, eave * (b - a) + 1); c.fillStyle = \"rgba(190,236,214,0.3)\"; c.fillRect(inset, eave * a, W - inset * 2, dpr); c.fillStyle = \"rgba(0,0,0,0.45)\"; c.fillRect(inset, eave * b - dpr, W - inset * 2, dpr); }\n      const shade = c.createLinearGradient(0, g.py, 0, g.py + g.ph * 0.24); shade.addColorStop(0, \"rgba(0,0,0,0.62)\"); shade.addColorStop(0.35, \"rgba(0,0,0,0.26)\"); shade.addColorStop(1, \"rgba(0,0,0,0)\");\n      c.fillStyle = shade; c.fillRect(g.px, g.py, g.pw, g.ph * 0.24);\n      const sill = c.createLinearGradient(0, y1, 0, y1 + drop * 0.34); sill.addColorStop(0, \"#3f8570\"); sill.addColorStop(0.25, PAINT[1]); sill.addColorStop(1, \"#05150f\");\n      c.fillStyle = sill; c.fillRect(side * 0.45, y1, W - side * 0.9, drop * 0.34);\n\n      // Set out the lettering.\n      const tradeSize = Math.max(9 * dpr, g.fh * 0.085);\n      g.size = g.fh * 0.5; g.track = g.size * 0.07;\n      c.font = `700 ${g.size}px ${FACE}`;\n      const fitTo = (g.fw - q * 2 - r * 2.4) * 0.9, full = widthOf(c, words.name, g.track);\n      if (full > fitTo) { g.size *= fitTo / full; g.track = g.size * 0.07; c.font = `700 ${g.size}px ${FACE}`; }\n      g.tw = widthOf(c, words.name, g.track);\n      const capH = c.measureText(\"H\").actualBoundingBoxAscent || g.size * 0.68;\n      g.cy = g.fy + g.fh * (words.trade ? 0.42 : 0.5); g.x0 = g.fx + g.fw / 2 - g.tw / 2;\n      const baseY = g.cy + capH / 2;\n      g.s = capH * 1.42;\n      g.rx = Math.floor(g.x0 - g.s * 0.3); g.ry = Math.floor(g.cy - g.s * 0.62); g.rw = Math.ceil(g.tw + g.s * 0.6); g.rh = Math.ceil(g.s * 1.24);\n      // The blocked shade, then the letters in gold size, which is what the leaf sticks to.\n      c.textBaseline = \"alphabetic\";\n      const depth = Math.max(2, g.size * 0.055);\n      for (let d = depth; d >= 1; d -= 0.5) { c.fillStyle = d > depth * 0.5 ? \"#04130d\" : \"#0b2a20\"; spaced(c, words.name, g.fx + g.fw / 2 + d, baseY + d, g.track); }\n      c.lineJoin = \"round\"; c.lineWidth = Math.max(1.5, g.size * 0.022); c.strokeStyle = \"#04130d\"; spaced(c, words.name, g.fx + g.fw / 2, baseY, g.track, true);\n      c.fillStyle = \"#a98334\"; spaced(c, words.name, g.fx + g.fw / 2, baseY, g.track);\n      if (words.trade) {\n        c.font = `700 ${tradeSize}px ${FACE}`;\n        let tt = tradeSize * 0.34; const room = g.fw - q * 2 - r * 2.4, natural = widthOf(c, words.trade, tt), flourish = (room - tradeSize * 7.6) / natural > 0.85, tfit = (flourish ? room - tradeSize * 7.6 : room * 0.94) / natural;\n        if (tfit < 1) { c.font = `700 ${tradeSize * tfit}px ${FACE}`; tt *= tfit; }\n        const ty = g.fy + g.fh * 0.845, half = widthOf(c, words.trade, tt) / 2, mid = g.fx + g.fw / 2;\n        c.fillStyle = \"rgba(0,0,0,0.5)\"; spaced(c, words.trade, mid + dpr, ty + dpr, tt);\n        c.fillStyle = gilt; spaced(c, words.trade, mid, ty, tt);\n        if (flourish) for (const sgn of [-1, 1]) { const ox = mid + sgn * (half + tradeSize * 1.5), oy = ty - tradeSize * 0.34, d = tradeSize * 0.2; c.beginPath(); c.moveTo(ox - d, oy); c.lineTo(ox, oy - d); c.lineTo(ox + d, oy); c.lineTo(ox, oy + d); c.closePath(); c.fill(); c.fillRect(sgn > 0 ? ox + d * 2 : ox - d * 2 - tradeSize * 1.6, oy - dpr * 0.5, tradeSize * 1.6, dpr); }\n      }\n\n      // The letter shapes on their own, and the same shapes punched out of a sheet.\n      for (const cvs of [mask, hole, gold]) { cvs.width = g.rw; cvs.height = g.rh; }\n      const mc = mask.getContext(\"2d\"), hc = hole.getContext(\"2d\"), gc = gold.getContext(\"2d\");\n      if (!mc || !hc || !gc) return;\n      mc.font = `700 ${g.size}px ${FACE}`; mc.textBaseline = \"alphabetic\"; mc.fillStyle = \"#fff\"; spaced(mc, words.name, g.fx + g.fw / 2 - g.rx, baseY - g.ry, g.track);\n      hc.fillStyle = \"#000\"; hc.fillRect(0, 0, g.rw, g.rh); hc.globalCompositeOperation = \"destination-out\"; hc.drawImage(mask, 0, 0);\n      // Where each leaf goes: one row, each overlapping the last by an eighth.\n      const pitch = g.s * 0.87, n = Math.max(2, Math.ceil((g.tw + g.s * 0.2) / pitch));\n      time.step = Math.min(0.075, 0.66 / n); time.wipe = time.lay + n * time.step + 0.14; time.burn = time.wipe + time.wipeFor + 0.03;\n      const start = g.x0 + g.tw / 2 - ((n - 1) * pitch) / 2;\n      leaves = Array.from({ length: n }, (_, i) => ({ x: start + i * pitch + (rand() - 0.5) * g.s * 0.05, y: g.cy + (rand() - 0.5) * g.s * 0.07, rot: (rand() - 0.5) * 0.09, flip: rand() > 0.5 ? 1 : -1, at: time.lay + i * time.step }));\n      paintLeaf(loose, g.s, 1, true);\n      // The finished gilding: the same leaves pressed flat, cut to the letters, with a rounded edge worked in.\n      const flat = make(); paintLeaf(flat, g.s, 0.3, false);\n      gc.fillStyle = \"#d9ae42\"; gc.fillRect(0, 0, g.rw, g.rh);\n      leaves.forEach((lf, i) => { gc.save(); gc.translate(lf.x - g.rx, lf.y - g.ry); gc.rotate(lf.rot); gc.scale(lf.flip, 1); gc.globalAlpha = 0.86 + (i % 3) * 0.07; gc.drawImage(flat, -g.s / 2, -g.s / 2, g.s, g.s); gc.globalAlpha = 0.5; gc.strokeStyle = \"rgba(255,244,196,0.55)\"; gc.lineWidth = dpr * 0.7; gc.strokeRect(-g.s / 2, -g.s / 2, g.s, g.s); gc.restore(); });\n      gc.globalCompositeOperation = \"destination-in\"; gc.drawImage(mask, 0, 0);\n      gc.globalCompositeOperation = \"source-atop\";\n      const edge = Math.max(1.5, g.size * 0.024);\n      gc.shadowColor = \"rgba(84,50,4,0.95)\"; gc.shadowBlur = edge * 1.5; gc.shadowOffsetX = -edge; gc.shadowOffsetY = -edge; gc.drawImage(hole, 0, 0);\n      gc.shadowColor = \"rgba(255,250,214,0.95)\"; gc.shadowBlur = edge * 1.1; gc.shadowOffsetX = edge * 0.9; gc.shadowOffsetY = edge * 0.9; gc.drawImage(hole, 0, 0);\n      gc.shadowColor = \"transparent\"; gc.globalCompositeOperation = \"source-over\";\n      specks = Array.from({ length: 46 }, () => [g.rx + rand() * g.rw, g.ry + g.rh * (0.1 + rand() * 0.85), 0.6 + rand() * 1.2, 0.25 + rand() * 0.5]);\n    };\n\n    // A band of light and its darker neighbours, cut to the letters, laid over the gold.\n    const glaze = (stops: [number, string][], at: number, op: GlobalCompositeOperation, upTo: number) => {\n      const tc = temp.getContext(\"2d\"); if (!tc) return;\n      tc.globalCompositeOperation = \"source-over\"; tc.clearRect(g.rx, g.ry, g.rw, g.rh);\n      const span = g.rw * 1.6, x = g.rx + g.rw * at;\n      const gr = tc.createLinearGradient(x - span / 2, g.ry, x + span / 2 + g.rh * 0.3, g.ry + g.rh);\n      stops.forEach(([p, col]) => gr.addColorStop(p, col));\n      tc.fillStyle = gr; tc.fillRect(g.rx, g.ry, Math.max(0, Math.min(g.rw, upTo - g.rx)), g.rh);\n      tc.globalCompositeOperation = \"destination-in\"; tc.drawImage(mask, g.rx, g.ry);\n      ctx.globalCompositeOperation = op; ctx.drawImage(temp, g.rx, g.ry, g.rw, g.rh, g.rx, g.ry, g.rw, g.rh); ctx.globalCompositeOperation = \"source-over\";\n    };\n\n    let light = 0.55, lightTo = 0.55, held = -1e9;\n    const draw = (t: number) => {\n      ctx.clearRect(0, 0, g.W, g.H); ctx.drawImage(base, 0, 0);\n      const wipeAt = Math.max(0, Math.min(1, (t - time.wipe) / time.wipeFor)), burnAt = Math.max(0, Math.min(1, (t - time.burn) / time.burnFor));\n      const brush = g.rx + g.rw * (wipeAt * wipeAt * (3 - 2 * wipeAt)), front = g.rx + g.rw * burnAt;\n      if (wipeAt > 0) {\n        ctx.save(); ctx.beginPath(); ctx.rect(g.rx, g.ry, brush - g.rx, g.rh); ctx.clip(); ctx.drawImage(gold, g.rx, g.ry); ctx.restore();\n        if (burnAt > 0) {\n          glaze([[0, \"rgba(104,60,0,0.5)\"], [0.14, \"rgba(255,255,255,0)\"], [0.24, \"rgba(255,255,255,0)\"], [0.37, \"rgba(110,64,0,0.5)\"], [0.47, \"rgba(255,255,255,0)\"], [0.57, \"rgba(255,255,255,0)\"], [0.7, \"rgba(110,64,0,0.52)\"], [0.8, \"rgba(255,255,255,0)\"], [0.9, \"rgba(255,255,255,0)\"], [1, \"rgba(104,60,0,0.5)\"]], light, \"multiply\", front);\n          glaze([[0, \"rgba(255,226,130,0)\"], [0.15, \"rgba(255,226,130,0)\"], [0.19, \"rgba(255,232,150,0.5)\"], [0.23, \"rgba(255,226,130,0)\"], [0.46, \"rgba(255,226,130,0)\"], [0.505, \"rgba(255,238,160,0.55)\"], [0.525, \"rgba(255,250,214,0.95)\"], [0.545, \"rgba(255,238,160,0.4)\"], [0.59, \"rgba(255,226,130,0)\"], [0.81, \"rgba(255,226,130,0)\"], [0.85, \"rgba(255,232,150,0.5)\"], [0.89, \"rgba(255,226,130,0)\"], [1, \"rgba(255,226,130,0)\"]], light, \"screen\", front);\n        }\n        for (const sp of specks) { if (sp[0] > brush) continue; ctx.fillStyle = `rgba(240,208,110,${sp[3]})`; ctx.fillRect(sp[0], sp[1], sp[2] * dpr, sp[2] * dpr); }\n      }\n      if (wipeAt < 1) {\n        ctx.save(); ctx.beginPath(); ctx.rect(brush, 0, g.W, g.H); ctx.clip();\n        for (const lf of leaves) {\n          const a = Math.max(0, Math.min(1, (t - lf.at) / 0.16)); if (a <= 0) continue;\n          const e = 1 - Math.pow(1 - a, 3);\n          ctx.save(); ctx.translate(lf.x, lf.y - (1 - e) * g.s * 0.12); ctx.rotate(lf.rot + (1 - e) * 0.12 * lf.flip); ctx.scale(lf.flip * (1.1 - 0.1 * e), 1.1 - 0.1 * e);\n          ctx.globalAlpha = e; ctx.shadowColor = \"rgba(0,0,0,0.45)\"; ctx.shadowBlur = (1 - e) * 14 * dpr + 2 * dpr; ctx.shadowOffsetY = (1 - e) * 10 * dpr + dpr;\n          ctx.drawImage(loose, -g.s / 2, -g.s / 2, g.s, g.s); ctx.restore();\n        }\n        ctx.restore();\n      }\n      if (burnAt > 0 && burnAt < 1) glaze([[0, \"rgba(255,255,255,0)\"], [0.47, \"rgba(255,255,255,0)\"], [0.5, \"rgba(255,255,255,0.95)\"], [0.53, \"rgba(255,255,255,0)\"], [1, \"rgba(255,255,255,0)\"]], burnAt, \"screen\", g.rx + g.rw);\n      for (const f of flakes) {\n        ctx.save(); ctx.translate(f.x, f.y); ctx.rotate(f.rot); ctx.scale(1, Math.cos(f.phase));\n        ctx.globalAlpha = Math.min(1, f.life * 2.2); ctx.fillStyle = f.tone > 0.66 ? \"#fff1b4\" : f.tone > 0.33 ? \"#e8c257\" : \"#c2932c\";\n        ctx.fillRect(-f.size / 2, -f.size / 2, f.size, f.size * 0.8); ctx.restore();\n      }\n    };\n\n    let raf = 0, last = 0, t = 0, seen = true;\n    const frame = (now: number) => {\n      raf = 0;\n      const dt = Math.min(0.033, (now - last) / 1000 || 0.016); last = now; t += dt;\n      const wipeAt = (t - time.wipe) / time.wipeFor;\n      if (wipeAt > 0 && wipeAt < 1) {\n        // The mop knocks the loose gold off as it passes.\n        const brush = g.rx + g.rw * (wipeAt * wipeAt * (3 - 2 * wipeAt));\n        for (let i = 0; i < 5; i++) flakes.push({ x: brush + (rand() - 0.3) * g.s * 0.2, y: g.ry + rand() * g.rh, vx: (60 + rand() * 300) * dpr, vy: (-200 + rand() * 240) * dpr, rot: rand() * 6.3, vr: (rand() - 0.5) * 14, size: (0.8 + rand() * rand() * 4.2) * dpr, life: 0.35 + rand() * 0.6, tone: rand(), phase: rand() * 6.3 });\n      }\n      for (const f of flakes) { f.vy += 900 * dpr * dt; f.vx *= 1 - 2.6 * dt; f.vy *= 1 - 1.5 * dt; f.x += f.vx * dt; f.y += f.vy * dt; f.rot += f.vr * dt; f.phase += dt * 11; f.life -= dt; }\n      flakes = flakes.filter((f) => f.life > 0 && f.y < g.H + 20);\n      if (now - held > 2600) lightTo = 0.5 + 0.32 * Math.sin(t * 0.8 - 1.2);\n      light += (lightTo - light) * Math.min(1, dt * 5);\n      draw(t);\n      if (seen && !document.hidden) raf = requestAnimationFrame(frame);\n    };\n    const wake = () => { if (reduce) { draw(99); return; } if (!raf) { last = performance.now(); raf = requestAnimationFrame(frame); } };\n\n    build(); wake();\n    api.current = {\n      set: (n, tr) => { if (n === words.name && tr === words.trade) return; words.name = n; words.trade = tr; build(); t = 0; flakes = []; wake(); },\n      again: () => { t = 0; flakes = []; wake(); },\n    };\n    let width = box.clientWidth;\n    const ro = new ResizeObserver(() => { if (box.clientWidth === width) return; width = box.clientWidth; build(); if (t < time.burn + time.burnFor) t = 99; wake(); });\n    ro.observe(box);\n    const onMove = (ev: PointerEvent) => { const b = cv.getBoundingClientRect(); held = performance.now(); lightTo = Math.max(0.05, Math.min(0.95, (ev.clientX - b.left) / b.width)); if (reduce) { light = lightTo; draw(99); } };\n    cv.addEventListener(\"pointermove\", onMove); cv.addEventListener(\"pointerdown\", onMove);\n    const io = new IntersectionObserver(([entry]) => { seen = entry.isIntersecting; if (seen) wake(); });\n    io.observe(cv);\n    const onVis = () => { if (!document.hidden) wake(); };\n    document.addEventListener(\"visibilitychange\", onVis);\n    return () => { cancelAnimationFrame(raf); api.current = null; ro.disconnect(); io.disconnect(); cv.removeEventListener(\"pointermove\", onMove); cv.removeEventListener(\"pointerdown\", onMove); document.removeEventListener(\"visibilitychange\", onVis); };\n  }, []);\n\n  // Re-gild a moment after the typing stops, not on every key.\n  useEffect(() => {\n    const id = window.setTimeout(() => api.current?.set(name.trim() || \" \", trade.trim()), 320);\n    return () => window.clearTimeout(id);\n  }, [name, trade]);\n\n  const field = \"h-10 w-full rounded-md border border-[#a9ae9d] bg-[#f3f4ee] px-3 font-mono text-[12px] uppercase tracking-[0.14em] text-[#1c2a22] outline-none focus-visible:ring-2 focus-visible:ring-[#12392c]\";\n  return (\n    <div className=\"flex min-h-[620px] w-full flex-col items-center justify-center bg-[#d9dccf] bg-[radial-gradient(90%_80%_at_50%_30%,#e9ebe0_0%,#d9dccf_55%,#c6cabb_100%)] px-4 py-12 sm:min-h-[740px]\">\n      <h2 className=\"sr-only\">{name}{trade ? `. ${trade}` : \"\"}</h2>\n      <div ref={wrap} className=\"w-full max-w-[1000px]\">\n        <canvas ref={canvas} aria-hidden=\"true\" className=\"mx-auto block w-full touch-pan-y\" style={{ height: 400 }} />\n      </div>\n      <div className=\"mt-8 flex w-full max-w-[620px] flex-col gap-3 sm:flex-row sm:items-end\">\n        <div className=\"sm:w-[170px]\">\n          <label htmlFor={`${SLUG}-name`} className=\"mb-1.5 block font-mono text-[11px] uppercase tracking-[0.18em] text-[#4c5648]\">Name in gold</label>\n          <input id={`${SLUG}-name`} value={name} spellCheck={false} onChange={(e) => setName(cleanName(e.target.value))} className={field} />\n        </div>\n        <div className=\"flex-1\">\n          <label htmlFor={`${SLUG}-trade`} className=\"mb-1.5 block font-mono text-[11px] uppercase tracking-[0.18em] text-[#4c5648]\">Line beneath</label>\n          <input id={`${SLUG}-trade`} value={trade} spellCheck={false} onChange={(e) => setTrade(cleanTrade(e.target.value))} className={field} />\n        </div>\n        <button type=\"button\" onClick={() => api.current?.again()} className=\"h-10 shrink-0 rounded-md bg-[#12392c] px-4 font-mono text-[11px] uppercase tracking-[0.18em] text-[#f1e3b4] outline-none transition-colors hover:bg-[#1a4a3a] focus-visible:ring-2 focus-visible:ring-[#12392c] focus-visible:ring-offset-2 focus-visible:ring-offset-[#d9dccf] motion-reduce:hidden motion-reduce:transition-none\">\n          Gild again\n        </button>\n      </div>\n    </div>\n  );\n}\n"}]}
