"use client"; /** * honey.tsx — a honeycomb with live, viscous drips. * Hover and one drip stretches down; click and its neck thins, snaps and the drop falls, then the comb refills. * * Part of toy-buttons. MIT licensed. Only depends on React. */ import { useEffect, useId, useImperativeHandle, useRef, type ButtonHTMLAttributes, type MouseEvent, type ReactNode, type Ref } from "react"; type Palette = { honey: string; light: string; dark: string; cell: string }; type Props = Omit, "children"> & { children?: ReactNode; ref?: Ref; palette?: Palette; }; const W = 250; const H = 88; const PL = 20; // overflow layer: sides, top const PT = 20; const PB = 190; const CW = W + PL * 2; const CH = H + PT + PB; const FLOOR = H + PB; // button-local y of the canvas bottom const DEFAULT_PALETTE: Palette = { honey: "#f49007", light: "#f8c34d", dark: "#a95102", cell: "#d87002" }; const DRIP_X = [0.14, 0.3, 0.58, 0.84].map((f) => Math.round(f * W)); const DRIP_LEN = [14, 26, 32, 16]; const DRIP_R = [5, 8, 9, 6]; const DRIP_PERIOD = [3200, 2600, 3800, 3000]; const NODES = 10; const SAMPLES = 34; const ROOT_Y = H - 3; const HOVER_LEN = 90; const STUB_LEN = 18; const RESET_AT = 4300; const MAX_DROPS = 2; // ---------- static comb geometry (built once) ---------- const HEX_A = 13; const HEX_W = Math.sqrt(3) * HEX_A; type Cell = { d: string; hl: string; shade: number; cx: number; cy: number }; const CELLS: Cell[] = (() => { const out: Cell[] = []; const vert = (cx: number, cy: number, k: number): [number, number] => { const a = ((30 + 60 * k) * Math.PI) / 180; return [cx + HEX_A * Math.cos(a), cy + HEX_A * Math.sin(a)]; }; const f = (n: number) => n.toFixed(1); for (let row = -1; row * HEX_A * 1.5 < H + HEX_A * 2; row++) { const cy = 6 + row * HEX_A * 1.5; for (let col = -1; col * HEX_W < W + HEX_W; col++) { const cx = 4 + col * HEX_W + (row & 1 ? HEX_W / 2 : 0); if (cx < -HEX_W || cx > W + HEX_W || cy < -HEX_A || cy > H + HEX_A) continue; const v = [0, 1, 2, 3, 4, 5].map((k) => vert(cx, cy, k)); const d = `M${v.map((p) => `${f(p[0])} ${f(p[1])}`).join("L")}Z`; const hl = `M${f(v[2][0])} ${f(v[2][1])}L${f(v[3][0])} ${f(v[3][1])}L${f(v[4][0])} ${f(v[4][1])}`; const h = Math.sin(row * 12.9898 + col * 78.233) * 43758.5453; out.push({ d, hl, shade: h - Math.floor(h), cx, cy }); } } return out; })(); const CELL_D = CELLS.map((c) => c.d).join(""); const CELL_SPEC = CELLS.map((c) => `M${(c.cx - 6.5).toFixed(1)} ${(c.cy - 3.5).toFixed(1)}Q${(c.cx - 2).toFixed(1)} ${(c.cy - 8.5).toFixed(1)} ${(c.cx + 3.5).toFixed(1)} ${(c.cy - 7).toFixed(1)}`).join(""); const CELL_HL = CELLS.map((c) => c.hl).join(""); const CELL_LIGHT = CELLS.filter((c) => c.shade > 0.6).map((c) => c.d).join(""); const CELL_DARK = CELLS.filter((c) => c.shade < 0.22).map((c) => c.d).join(""); // ---------- drip model ---------- type Drip = { x: number; restL: number; restR: number; period: number; phase: number; L: number; vL: number; R: number; tL: number; tR: number; tau: number; spring: boolean; thin: number; ny: number[]; ct: number; snapped: boolean; pullTo: number; }; type Drop = { x: number; y: number; vy: number; R: number; age: number }; type Bead = { x: number; y: number; vy: number; r: number; delay: number }; const clamp = (n: number, lo = 0, hi = 1) => Math.max(lo, Math.min(hi, n)); const ease = (t: number) => { const c = clamp(t); return c * c * (3 - 2 * c); }; const centerY = (d: Drip, L: number, R: number) => H + L - R; const idealNodes = (d: Drip, L: number, R: number, out: number[]) => { const yc = centerY(d, L, R); for (let i = 0; i < NODES; i++) out[i] = ROOT_Y + (i / (NODES - 1)) * (yc - ROOT_Y); }; const makeDrips = (): Drip[] => DRIP_X.map((x, i) => { const d: Drip = { x, restL: DRIP_LEN[i], restR: DRIP_R[i], period: DRIP_PERIOD[i], phase: i * 1.7, L: DRIP_LEN[i], vL: 0, R: DRIP_R[i], tL: DRIP_LEN[i], tR: DRIP_R[i], tau: 700, spring: false, thin: 0, ny: new Array(NODES).fill(0), ct: -1, snapped: false, pullTo: 90, }; idealNodes(d, d.L, d.R, d.ny); return d; }); export function HoneyButton({ children = "sweet", palette = DEFAULT_PALETTE, onClick, className, type = "button", disabled = false, ref, ...rest }: Props) { const btnRef = useRef(null); const wrapRef = useRef(null); const canvasRef = useRef(null); const bandRef = useRef(null); const seepRef = useRef(null); const play = useRef<() => void>(() => {}); const pal = useRef(palette); pal.current = palette; const uid = `tb-honey-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`; useImperativeHandle(ref, () => btnRef.current!, []); useEffect(() => { const el = btnRef.current; const host = wrapRef.current; const cv = canvasRef.current; const band = bandRef.current; const seep = seepRef.current; if (!el || !host || !cv || !band || !seep) return; const ctx = cv.getContext("2d"); if (!ctx) return; const drips = makeDrips(); const drops: Drop[] = []; const beads: Bead[] = []; const timers = new Set(); let epoch = 0; let raf = 0; let last = 0; let visible = true; let hi = -1; let glintAt = -1e9; let seepAt = -1e9; let rmDrop = 0; let rmIdx = 2; let rect: DOMRect | undefined; let dirty = true; const media = window.matchMedia("(prefers-reduced-motion: reduce)"); const allowed = () => !disabled && visible && !document.hidden && !media.matches; let dpr = 1; let body: Animation | null = null; const setup = () => { const scale = el.getBoundingClientRect().width / (el.offsetWidth || 1) || 1; dpr = Math.min(2, (window.devicePixelRatio || 1) * scale); cv.width = Math.round(CW * dpr); cv.height = Math.round(CH * dpr); ctx.setTransform(dpr, 0, 0, dpr, 0, 0); dirty = true; }; // ---- drawing ---- const lx = new Float32Array(SAMPLES); const rx = new Float32Array(SAMPLES); const sy = new Float32Array(SAMPLES); const drawDrip = (d: Drip, alpha: number) => { const p = pal.current; for (let j = 0; j < SAMPLES; j++) { const s = j / (SAMPLES - 1); const u = s * (NODES - 1); const i = Math.min(NODES - 2, Math.floor(u)); const y = d.ny[i] + (d.ny[i + 1] - d.ny[i]) * (u - i); const neck = 1 - 0.68 * d.thin * Math.exp(-(((s - 0.4) / 0.22) ** 2)); const k = clamp((d.L - 30) / 70); const a = 0.5 - 0.3 * k; const pw = 3 + 4 * k; const fillet = 6.5 * Math.exp(-Math.max(0, y - ROOT_Y) / 4) * (1 - s * s); const r = Math.max(1.4, d.R * (a + (1 - a) * s ** pw) * neck) + fillet; sy[j] = y; lx[j] = d.x - r; rx[j] = d.x + r; } const yc = d.ny[NODES - 1]; ctx.globalAlpha = alpha; ctx.beginPath(); ctx.moveTo(lx[0], sy[0]); for (let j = 1; j < SAMPLES; j++) ctx.lineTo(lx[j], sy[j]); ctx.arc(d.x, yc, d.R, Math.PI, 0, true); for (let j = SAMPLES - 1; j >= 0; j--) ctx.lineTo(rx[j], sy[j]); ctx.closePath(); ctx.lineJoin = "round"; const g = ctx.createLinearGradient(d.x - d.R, 0, d.x + d.R, 0); g.addColorStop(0, "#8f4302"); g.addColorStop(0.16, p.dark); g.addColorStop(0.34, p.honey); g.addColorStop(0.47, p.light); g.addColorStop(0.55, "#ffd877"); g.addColorStop(0.67, p.honey); g.addColorStop(0.88, "#b85703"); g.addColorStop(1, "#8f4302"); ctx.fillStyle = g; ctx.save(); ctx.shadowColor = "rgba(255,150,20,.45)"; ctx.shadowBlur = 7 * dpr; ctx.fill(); ctx.restore(); const bg = ctx.createRadialGradient(d.x + d.R * 0.12, yc + d.R * 0.28, 0, d.x + d.R * 0.12, yc + d.R * 0.28, d.R * 0.95); bg.addColorStop(0, "rgba(255,226,140,.9)"); bg.addColorStop(0.45, "rgba(255,184,60,.45)"); bg.addColorStop(1, "rgba(255,160,30,0)"); ctx.fillStyle = bg; ctx.beginPath(); ctx.arc(d.x, yc, d.R * 0.92, 0, Math.PI * 2); ctx.fill(); let j0 = 0; while (j0 < SAMPLES - 1 && sy[j0] <= H + 1) j0++; ctx.beginPath(); ctx.moveTo(lx[j0], sy[j0]); for (let j = j0 + 1; j < SAMPLES; j++) ctx.lineTo(lx[j], sy[j]); ctx.arc(d.x, yc, d.R, Math.PI, 0, true); for (let j = SAMPLES - 1; j >= j0; j--) ctx.lineTo(rx[j], sy[j]); ctx.strokeStyle = "rgba(110,45,0,.5)"; ctx.lineWidth = 0.8; ctx.stroke(); // glossy sliver down the upper-left, along the neck if (d.L >= 20) { ctx.beginPath(); let started = false; for (let j = 0; j < SAMPLES - 1; j++) { if (sy[j] <= H + 5) continue; const s = j / (SAMPLES - 1); if (s > 0.9) break; const r = (rx[j] - lx[j]) / 2; const hx = d.x - r * 0.5; if (!started) { ctx.moveTo(hx, sy[j]); started = true; } else ctx.lineTo(hx, sy[j]); } ctx.strokeStyle = "rgba(255,241,184,.7)"; ctx.lineCap = "round"; ctx.lineWidth = Math.min(1.6, Math.max(0.7, d.R * 0.16)); ctx.globalAlpha = alpha; ctx.stroke(); } // refracted light at the bottom of the bulb ctx.globalAlpha = alpha; ctx.fillStyle = "rgba(255,230,140,.8)"; ctx.beginPath(); ctx.arc(d.x + d.R * 0.15, yc + d.R * 0.55, Math.max(2, d.R * 0.16), 0, Math.PI * 2); ctx.fill(); ctx.globalAlpha = 1; }; const drawDrop = (o: Drop, alpha: number) => { const p = pal.current; const st = 1 + 0.25 * clamp(o.vy / 600); ctx.save(); ctx.translate(o.x, o.y); ctx.scale(1, st); ctx.globalAlpha = alpha; const R = o.R; const tip = -R * (1.9 + 0.9 * Math.exp(-o.age / 110) + 0.5 * (st - 1) * 4); ctx.beginPath(); ctx.moveTo(0, tip); ctx.bezierCurveTo(R * 0.15, -R * 1.1, R, -R * 0.55, R, 0); ctx.arc(0, 0, R, 0, Math.PI, false); ctx.bezierCurveTo(-R, -R * 0.55, -R * 0.15, -R * 1.1, 0, tip); ctx.closePath(); ctx.lineJoin = "round"; const g = ctx.createLinearGradient(-R, 0, R, 0); g.addColorStop(0, "#8f4302"); g.addColorStop(0.16, p.dark); g.addColorStop(0.34, p.honey); g.addColorStop(0.47, p.light); g.addColorStop(0.55, "#ffd877"); g.addColorStop(0.67, p.honey); g.addColorStop(0.88, "#b85703"); g.addColorStop(1, "#8f4302"); ctx.fillStyle = g; ctx.save(); ctx.shadowColor = "rgba(255,150,20,.45)"; ctx.shadowBlur = 9 * dpr; ctx.fill(); ctx.restore(); const bg = ctx.createRadialGradient(R * 0.15, R * 0.35, 0, R * 0.15, R * 0.35, R * 1.05); bg.addColorStop(0, "rgba(255,238,165,.95)"); bg.addColorStop(0.4, "rgba(255,196,70,.55)"); bg.addColorStop(1, "rgba(255,160,30,0)"); ctx.fillStyle = bg; ctx.fill(); ctx.strokeStyle = "rgba(110,45,0,.55)"; ctx.lineWidth = 0.8; ctx.stroke(); ctx.beginPath(); ctx.moveTo(-R * 0.45, -R * 0.75); ctx.quadraticCurveTo(-R * 0.7, -R * 0.1, -R * 0.4, R * 0.5); ctx.strokeStyle = "#fff1b8"; ctx.lineCap = "round"; ctx.lineWidth = 2; ctx.stroke(); ctx.fillStyle = "rgba(255,230,140,.8)"; ctx.beginPath(); ctx.arc(R * 0.15, R * 0.55, Math.max(2, R * 0.16), 0, Math.PI * 2); ctx.fill(); ctx.restore(); }; const paint = () => { ctx.clearRect(0, 0, CW, CH); ctx.save(); ctx.translate(PL, PT); for (const d of drips) drawDrip(d, 1); { const p = pal.current; const pb = (x: number) => x < 44 ? 44 + Math.sqrt(1936 - (44 - x) ** 2) : x > 206 ? 44 + Math.sqrt(1936 - (x - 206) ** 2) : H; const env = (x: number) => clamp(Math.min(x - 22, 228 - x) / 16); const bumps = (x: number) => { let b = 0; for (const d of drips) b += 4.5 * Math.exp(-(((x - d.x) / 11) ** 2)); return b; }; ctx.beginPath(); ctx.moveTo(22, pb(22) - 4.5); for (let x = 22; x <= 228; x += 3) ctx.lineTo(x, pb(x) - 4.5 - env(x) * (7 + 1.5 * Math.sin(x * 0.11))); for (let x = 228; x >= 22; x -= 3) ctx.lineTo(x, pb(x) - 3 + env(x) * 3.5 + bumps(x)); ctx.closePath(); const lg = ctx.createLinearGradient(0, H - 13, 0, H + 6); lg.addColorStop(0, "rgba(255,205,90,0)"); lg.addColorStop(0.3, "rgba(248,195,77,.55)"); lg.addColorStop(0.55, p.light); lg.addColorStop(0.82, p.honey); lg.addColorStop(1, "#c56a04"); ctx.fillStyle = lg; ctx.fill(); ctx.beginPath(); ctx.moveTo(52, H - 6); ctx.lineTo(198, H - 6); ctx.strokeStyle = "rgba(255,241,184,.6)"; ctx.lineWidth = 1; ctx.lineCap = "round"; ctx.stroke(); } for (const o of drops) drawDrop(o, clamp((FLOOR - (o.y + o.R)) / 24)); if (beads.length) { for (const b of beads) { if (b.delay > 0) continue; ctx.globalAlpha = clamp((FLOOR - b.y) / 24); ctx.fillStyle = "rgba(255,170,40,.22)"; ctx.beginPath(); ctx.arc(b.x, b.y, b.r * 2.4, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = "#ffb21f"; ctx.beginPath(); ctx.arc(b.x, b.y, b.r, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = "#fff1b8"; ctx.beginPath(); ctx.arc(b.x - b.r * 0.3, b.y - b.r * 0.3, b.r * 0.4, 0, Math.PI * 2); ctx.fill(); } ctx.globalAlpha = 1; } if (rmDrop > 0) { const d = drips[rmIdx]; drawDrop({ x: d.x, y: H + d.restL + 30, vy: 0, R: 10, age: 999 }, rmDrop); } ctx.restore(); }; const setBand = (now: number) => { const t = now - glintAt; const env = t < 0 || t > 800 ? 0 : t < 60 ? t / 60 : t < 260 ? 1 : 1 - (t - 260) / 540; band.style.opacity = String(0.55 + 0.3 * env); const s = now - seepAt; seep.style.opacity = s < 0 || s > 400 ? "0" : String(Math.sin((Math.PI * s) / 400)); }; // ---- physics ---- const snap = (d: Drip, now: number) => { d.snapped = true; drops.push({ x: d.x, y: d.ny[NODES - 1], vy: 0, R: Math.max(d.R, 16), age: 0 }); const BR = [1.2, 1.6, 2.0, 2.4]; for (let i = 0; i < 4; i++) { beads.push({ x: d.x + (i % 2 ? 0.5 : -0.5), y: H + 24 + i * 8, vy: 0, r: BR[i], delay: 20 + 25 * i }); } body?.cancel(); body = el.animate([ { transform: "translateY(2px) scale(1.012,.975)" }, { transform: "translateY(-2.5px) scale(.99,1.025)", offset: 0.3 }, { transform: "translateY(.6px) scale(1.003,.995)", offset: 0.62 }, { transform: "none" }, ], { duration: 620, easing: "cubic-bezier(.22,.8,.3,1)" }); d.thin = 0; d.R = d.restR * 0.85; d.tR = d.R; d.L = 30; d.vL = -160; d.spring = true; d.tL = STUB_LEN; glintAt = now; }; const timeline = (d: Drip, now: number) => { const t = d.ct; if (!d.snapped) { if (t < 940) { d.spring = false; d.tau = t < 300 ? 100 : 300; d.tL = d.pullTo + (t > 300 ? (4 * (t - 300)) / 640 : 0); d.thin = t < 300 ? 0 : ease((t - 300) / 640); } else snap(d, now); } else if (t >= 1500 && d.spring) { d.spring = false; d.tau = 1000; d.tL = d.restL; d.tR = d.restR; const k = Math.floor(Math.random() * CELLS.length); seep.setAttribute("d", CELLS[k].d); seepAt = now; } if (t >= RESET_AT) { d.ct = -1; d.snapped = false; host.dataset.tbState = drips.some((o) => o.ct >= 0) || drops.length ? "playing" : "idle"; } }; const stepDrip = (d: Drip, i: number, dtMs: number, now: number) => { if (d.ct >= 0) { d.ct += dtMs; timeline(d, now); } else { const hot = i === hi; d.tL = hot ? HOVER_LEN : d.restL; d.tR = hot ? 7 + d.restR * 0.85 : d.restR; d.tau = hot ? 700 : 900; d.spring = false; d.thin = 0; } const f = 1 - Math.exp(-dtMs / (d.tau * 0.9)); if (d.spring) { const n = Math.max(1, Math.ceil(dtMs / 4)); const h = dtMs / n / 1000; for (let k = 0; k < n; k++) { d.vL += (-220 * (d.L - d.tL) - 11 * d.vL) * h; d.L += d.vL * h; } } else d.L += (d.tL - d.L) * f; d.R += (d.tR - d.R) * (1 - Math.exp(-dtMs / 180)); const breathe = d.ct < 0 ? 1.5 * clamp(1 - (d.L - d.restL) / 10) * Math.sin((2 * Math.PI * now) / d.period + d.phase) : 0; const yc = centerY(d, d.L + breathe, d.R); for (let k = 0; k < NODES; k++) { const s = k / (NODES - 1); const ideal = ROOT_Y + s * (yc - ROOT_Y); d.ny[k] += (ideal - d.ny[k]) * (1 - Math.exp(-dtMs / (30 + 70 * s))); } }; const stepParticles = (dtMs: number) => { const h = dtMs / 1000; for (let i = drops.length - 1; i >= 0; i--) { const o = drops[i]; o.vy += 620 * h; o.age += dtMs; o.y += o.vy * h; if (o.y - o.R > FLOOR) drops.splice(i, 1); } for (let i = beads.length - 1; i >= 0; i--) { const b = beads[i]; if (b.delay > 0) { b.delay -= dtMs; continue; } b.vy += 520 * h; b.y += b.vy * h; if (b.y > FLOOR) beads.splice(i, 1); } }; const tick = (now: number) => { raf = 0; if (!allowed()) return; const dt = last ? Math.min(48, now - last) : 16; last = now; drips.forEach((d, i) => stepDrip(d, i, dt, now)); stepParticles(dt); paint(); setBand(now); if (!drips.some((d) => d.ct >= 0) && !drops.length && !beads.length) host.dataset.tbState = "idle"; raf = requestAnimationFrame(tick); }; const wake = () => { if (!raf && allowed()) raf = requestAnimationFrame(tick); }; const reset = () => { body?.cancel(); body = null; drips.forEach((d) => { d.L = d.tL = d.restL; d.R = d.tR = d.restR; d.thin = 0; d.vL = 0; d.ct = -1; d.snapped = false; d.spring = false; idealNodes(d, d.L, d.R, d.ny); }); drops.length = 0; beads.length = 0; rmDrop = 0; band.style.opacity = "0.55"; seep.style.opacity = "0"; host.dataset.tbState = "idle"; }; const later = (fn: () => void, ms: number) => { const my = epoch; const id = window.setTimeout(() => { timers.delete(id); if (my === epoch) fn(); }, ms); timers.add(id); }; const clearTimers = () => { epoch++; timers.forEach((id) => window.clearTimeout(id)); timers.clear(); }; const sync = () => { cancelAnimationFrame(raf); raf = 0; last = 0; clearTimers(); reset(); host.dataset.tbPaused = String(disabled || !visible || document.hidden); hi = disabled || media.matches ? -1 : el.matches(":hover") ? hi : -1; paint(); wake(); }; play.current = () => { if (disabled) return; if (media.matches) { clearTimers(); const d = drips[2]; rmIdx = 2; rmDrop = 1; d.L = 6; d.tL = 6; idealNodes(d, d.L, d.R, d.ny); host.dataset.tbState = "playing"; paint(); later(() => { rmDrop = 0; paint(); }, 200); later(() => { d.L = d.tL = d.restL; idealNodes(d, d.L, d.R, d.ny); host.dataset.tbState = "idle"; paint(); }, 1200); return; } if (!allowed() || drops.length >= MAX_DROPS) return; let best = -1; drips.forEach((d, i) => { if (d.ct < 0 && (best < 0 || d.L > drips[best].L)) best = i; }); if (best < 0) return; const d = drips[best]; d.pullTo = d.L < 60 ? 90 : Math.min(96, d.L + 6); d.ct = 0; d.snapped = false; body?.cancel(); body = el.animate([ { transform: "none" }, { transform: "translateY(2.5px) scale(1.02,.955)", offset: 0.12 }, { transform: "translateY(1.5px) scale(1.008,.985)", offset: 0.35 }, { transform: "translateY(2px) scale(1.012,.975)" }, ], { duration: 940, easing: "cubic-bezier(.3,.7,.4,1)", fill: "forwards" }); host.dataset.tbState = "playing"; wake(); }; // ---- pointer ---- const localX = (e: PointerEvent) => { if (dirty || !rect) { rect = el.getBoundingClientRect(); dirty = false; } const scale = rect.width / (el.offsetWidth || 1) || 1; return (e.clientX - rect.left) / scale; }; const nearest = (x: number) => { let b = 0; DRIP_X.forEach((dx, i) => { if (Math.abs(dx - x) < Math.abs(DRIP_X[b] - x)) b = i; }); return b; }; const enter = (e: PointerEvent) => { if (!allowed()) return; dirty = true; hi = nearest(localX(e)); wake(); }; const move = (e: PointerEvent) => { if (allowed()) { hi = nearest(localX(e)); wake(); } }; const leave = () => { hi = -1; wake(); }; const invalidate = () => { dirty = true; }; const io = typeof IntersectionObserver === "undefined" ? null : new IntersectionObserver(([en]) => { visible = en.isIntersecting; sync(); }); const ro = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => { dirty = true; setup(); paint(); }); setup(); io?.observe(host); ro?.observe(el); el.addEventListener("pointerenter", enter); el.addEventListener("pointermove", move, { passive: true }); el.addEventListener("pointerleave", leave); window.addEventListener("resize", invalidate); window.addEventListener("scroll", invalidate, true); document.addEventListener("visibilitychange", sync); media.addEventListener("change", sync); sync(); return () => { play.current = () => {}; cancelAnimationFrame(raf); body?.cancel(); clearTimers(); io?.disconnect(); ro?.disconnect(); el.removeEventListener("pointerenter", enter); el.removeEventListener("pointermove", move); el.removeEventListener("pointerleave", leave); window.removeEventListener("resize", invalidate); window.removeEventListener("scroll", invalidate, true); document.removeEventListener("visibilitychange", sync); media.removeEventListener("change", sync); }; }, [disabled]); const click = (e: MouseEvent) => { if (disabled || e.currentTarget.matches(":disabled")) return; onClick?.(e); if (e.defaultPrevented) return; play.current(); }; const pill = `M44 0H206A44 44 0 0 1 206 88H44A44 44 0 0 1 44 0Z`; return ( ); } export default HoneyButton; const css = ` .tb-honey-wrap{display:inline-flex;position:relative;vertical-align:middle;width:${W}px;height:${H}px} .tb-honey-btn{position:relative;display:flex;align-items:center;justify-content:center;box-sizing:border-box;width:${W}px;height:${H}px; padding:0;border:0;border-radius:${H / 2}px;background:transparent;color:#fff0cf;cursor:pointer;overflow:visible;transform-origin:50% 30%; -webkit-tap-highlight-color:transparent; font:900 34px/1 ui-rounded,"SF Pro Rounded","Nunito","Segoe UI",system-ui,sans-serif;letter-spacing:.05em;text-transform:uppercase} .tb-honey-btn:focus-visible{outline:3px solid #ffd56a;outline-offset:5px} .tb-honey-btn:disabled{cursor:default;opacity:.6;filter:saturate(.5)} .tb-honey-shadow{position:absolute;inset:0;border-radius:inherit;box-shadow:0 12px 18px -8px rgba(0,0,0,.75),0 0 22px rgba(244,144,7,.18);pointer-events:none} .tb-honey-canvas{position:absolute;left:-${PL}px;top:-${PT}px;width:${CW}px;height:${CH}px;pointer-events:none;z-index:2} .tb-honey-comb{position:absolute;left:0;top:0;width:${W}px;height:${H}px;pointer-events:none;z-index:1} .tb-honey-label{position:relative;z-index:3;pointer-events:none;color:#fff3d6;transform:translateY(-1px); text-shadow:0 -1px 0 rgba(255,253,235,.7),0 1px 0 #e08a10,0 2px 0 #b65e04,0 3px 0 #8a4203,0 4px 1px rgba(70,28,0,.55),0 6px 10px rgba(60,24,0,.55)} .tb-honey-wrap[data-tb-paused=true] *{animation-play-state:paused!important} @media (prefers-reduced-motion:reduce){.tb-honey-wrap *,.tb-honey-wrap *::before,.tb-honey-wrap *::after{animation:none!important;transition:none!important}} `;