{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"extruded-spec-card","type":"registry:component","title":"Extruded Spec Card","description":"A card holding a small machined dial built in CSS 3D: the card tilts toward the pointer and the dial turns to follow it one detent at a time, its copper marker lit, over a data-plate of specs.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/extruded-spec-card.tsx","content":"\"use client\";\n\nimport { useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { CSSProperties, PointerEvent as ReactPointerEvent } from \"react\";\n\n/**\n * ExtrudedSpecCard — a card that holds a small machined dial.\n *\n * The dial is built in CSS 3D (knurled discs stacked under a glass cap) on a\n * panel ringed with detent ticks. The card tilts toward the pointer and the\n * dial turns to follow it, one detent at a time on a spring, its copper\n * marker lit; focus does the same. Specs sit underneath like a data plate.\n * No WebGL.\n *\n * Part of the Spatial 3D kit: a dark studio (#0a0a0d, panels #101114 and\n * #16171b, ink #f2f1ee) with anodised copper #ff7a3d only as light, and\n * one object in three finishes (titanium, ceramic, soft-touch polymer) under\n * one rig: key, fill and rim, soft shadows, occlusion and a softbox\n * reflection. Hanken Grotesk through var(--font-hanken) for display over\n * Geist. Respects prefers-reduced-motion. No dependencies beyond React.\n * Paste it as its own file: it repeats the kit's small helpers, which would\n * clash in one module. Load Hanken Grotesk with next/font (variable:\n * \"--font-hanken\") on a parent, or from Google Fonts or @fontsource.\n */\n\nconst SANS = 'var(--font-sans, \"Geist\", \"Inter\", ui-sans-serif, system-ui, sans-serif)';\n\nconst MONO = 'var(--font-mono, \"Geist Mono\", ui-monospace, \"SFMono-Regular\", Menlo, Consolas, monospace)';\n\nconst DISPLAY = 'var(--font-hanken, \"Hanken Grotesk\", var(--font-sans, \"Geist\"), ui-sans-serif, system-ui, sans-serif)';\n\nconst EASE = \"cubic-bezier(0.22, 1, 0.36, 1)\";\n\n/** The dark studio the kit is set in. */\nconst ROOM = {\n  ground: \"#0a0a0d\",\n  panel: \"#101114\",\n  raised: \"#16171b\",\n  ink: \"rgba(242,241,238,0.92)\",\n  ink2: \"rgba(242,241,238,0.6)\",\n  ink3: \"rgba(242,241,238,0.38)\",\n  line: \"rgba(242,241,238,0.08)\",\n  line2: \"rgba(242,241,238,0.16)\",\n  copper: \"#ff7a3d\",\n} as const;\n\n/**\n * The three finishes the object can wear. `base` is the colour; the rest are\n * shader parameters: gloss (0-1), specular strength, rim, subsurface wrap, and\n * how metallic it is. `css` holds the colours the CSS-3D parts draw with.\n */\nexport const S3_FINISHES = {\n  titanium: {\n    label: \"Titanium\",\n    base: [0.725, 0.737, 0.761],\n    gloss: 0.62,\n    spec: 0.8,\n    rim: 0.3,\n    sss: 0,\n    metal: 1,\n    css: { face: \"#c9ccd2\", side: \"#8d9098\", edge: \"#e6e8ec\", shade: \"#5d6068\" },\n  },\n  ceramic: {\n    label: \"Ceramic\",\n    base: [0.925, 0.906, 0.867],\n    gloss: 0.4,\n    spec: 0.25,\n    rim: 0.18,\n    sss: 0.08,\n    metal: 0,\n    css: { face: \"#ece7dd\", side: \"#c9c2b5\", edge: \"#faf7f1\", shade: \"#9a9386\" },\n  },\n  polymer: {\n    label: \"Polymer\",\n    base: [0.106, 0.11, 0.125],\n    gloss: 0.3,\n    spec: 0.12,\n    rim: 0.22,\n    sss: 0,\n    metal: 0,\n    css: { face: \"#26272c\", side: \"#18191d\", edge: \"#3a3b41\", shade: \"#0e0f12\" },\n  },\n} as const;\n\nexport type S3Finish = keyof typeof S3_FINISHES;\n\nfunction own<T extends object>(map: T, key: string): key is Extract<keyof T, string> {\n  return Object.prototype.hasOwnProperty.call(map, key);\n}\n\nfunction finishOf(name: string) {\n  return own(S3_FINISHES, name) ? S3_FINISHES[name] : S3_FINISHES.titanium;\n}\n\n/** Links: strip tabs and newlines, refuse backslashes, allow http(s), mailto, tel and same-site paths. */\nfunction safeHref(raw: string): string {\n  const v = raw.replace(/[\\t\\n\\r]/g, \"\").trim();\n  if (!v || v.includes(\"\\\\\")) return \"#\";\n  if (/^(https?:|mailto:|tel:)/i.test(v)) return v;\n  if (/^[/#?]/.test(v) && !/^\\/\\//.test(v)) return v;\n  return \"#\";\n}\n\nfunction subscribeMotion(cb: () => void) {\n  const m = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  m.addEventListener(\"change\", cb);\n  return () => m.removeEventListener(\"change\", cb);\n}\n\n/** True when the visitor asked for reduced motion. False on the server. */\nfunction useReducedMotion(): boolean {\n  return useSyncExternalStore(\n    subscribeMotion,\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n/**\n * A spring for one number (stiffness 340, damping 26: a detent's snap,\n * settled in about 380ms). Returns the new value and velocity.\n */\nfunction spring(x: number, v: number, target: number, dt: number, k = 340, c = 26): [number, number] {\n  const steps = dt > 1 / 60 ? 2 : 1;\n  const h = dt / steps;\n  for (let i = 0; i < steps; i++) {\n    v += (k * (target - x) - c * v) * h;\n    x += v * h;\n  }\n  return [x, v];\n}\n\n// Each part carries only the CSS it needs, so any one of them works on its own.\n// Nothing is interpolated into these sheets; colours arrive as CSS variables.\n// revert-layer keeps an element's own rounded corners when a host page's focus rule flattens them.\nconst FOCUS_CSS = \".s3-scope :focus-visible,.s3-scope:focus-visible{outline:2px solid var(--s3-ring,#ff7a3d);outline-offset:3px;border-radius:revert-layer}\";\n\n/**\n * The dial in CSS 3D, for parts that ship no WebGL: nine knurled discs stacked\n * 2.2px apart form the ring's side, a finish-lit face and a dark glass cap sit\n * on top, and a copper marker turns with `angle`. Tilted in real perspective,\n * so its side and its shadow move as it turns toward you.\n */\nfunction CssDial({ finish = \"titanium\", angle = 0, size = 180, tiltX = 24, tiltY = -16, lit = false, ticks = 0 }: { finish?: S3Finish; angle?: number; size?: number; tiltX?: number; tiltY?: number; lit?: boolean; ticks?: number }) {\n  const c = finishOf(finish).css;\n  const layers = 9;\n  const turn = `rotate(${angle.toFixed(2)}deg)`;\n  return (\n    <div aria-hidden className=\"relative\" style={{ width: size, height: size, perspective: size * 4 }}>\n      <div className=\"absolute inset-0\" style={{ transformStyle: \"preserve-3d\", transform: `rotateX(${tiltX.toFixed(2)}deg) rotateY(${tiltY.toFixed(2)}deg)` }}>\n        <div className=\"absolute rounded-full\" style={{ inset: \"-9%\", transform: \"translateZ(-8px)\", background: `radial-gradient(circle at 40% 35%, ${ROOM.raised}, ${ROOM.panel} 60%, #07070a)`, boxShadow: \"0 30px 50px -20px rgba(0,0,0,0.8), inset 0 1px 0 rgba(242,241,238,0.06)\" }}>\n          {ticks > 0 ? (\n            <svg viewBox=\"-50 -50 100 100\" className=\"absolute inset-0 h-full w-full\">\n              {Array.from({ length: ticks }, (_, i) => {\n                const a = (i / ticks) * Math.PI * 2;\n                const r2 = i % 5 === 0 ? 41 : 43;\n                // Rounded, so the server and the browser draw the same numbers.\n                const at = (r: number) => [Number((Math.sin(a) * r).toFixed(2)), Number((-Math.cos(a) * r).toFixed(2))];\n                const [x1, y1] = at(45);\n                const [x2, y2] = at(r2);\n                return <line key={i} x1={x1} y1={y1} x2={x2} y2={y2} stroke={i % 5 === 0 ? \"rgba(242,241,238,0.5)\" : \"rgba(242,241,238,0.2)\"} strokeWidth={0.6} />;\n              })}\n            </svg>\n          ) : null}\n        </div>\n        {Array.from({ length: layers }, (_, i) => (\n          <div\n            key={i}\n            className=\"absolute rounded-full\"\n            style={{\n              inset: \"8%\",\n              transform: `translateZ(${(i * 2.2).toFixed(1)}px) ${turn}`,\n              background: `repeating-conic-gradient(${c.side} 0 3deg, ${i === layers - 1 ? c.edge : c.shade} 3deg 6deg)`,\n              filter: `brightness(${(0.72 + i * 0.035).toFixed(3)})`,\n            }}\n          />\n        ))}\n        <div\n          className=\"absolute rounded-full\"\n          style={{\n            inset: \"13%\",\n            transform: `translateZ(${(layers * 2.2).toFixed(1)}px) ${turn}`,\n            background: `radial-gradient(circle at 34% 28%, ${c.edge}, ${c.face} 42%, ${c.side} 100%)`,\n            boxShadow: `inset 0 0 0 1px ${c.edge}, inset 0 -6px 12px rgba(0,0,0,0.25)`,\n          }}\n        >\n          <div className=\"absolute rounded-full\" style={{ inset: \"12%\", background: \"radial-gradient(circle at 38% 30%, #2a2c33, #0d0e11 55%, #050507)\", boxShadow: \"inset 0 1px 1px rgba(255,255,255,0.14)\" }} />\n          <div\n            className=\"absolute rounded-full\"\n            style={{\n              width: \"7%\",\n              height: \"7%\",\n              left: \"46.5%\",\n              top: \"17%\",\n              background: ROOM.copper,\n              boxShadow: lit ? \"0 0 6px 1px rgba(255,122,61,0.95), 0 0 18px 3px rgba(255,122,61,0.5)\" : \"0 0 3px rgba(255,122,61,0.6)\",\n              transition: \"box-shadow 220ms\",\n            }}\n          />\n        </div>\n      </div>\n    </div>\n  );\n}\n\nexport type ExtrudedSpecCardProps = {\n  title: string;\n  kicker?: string;\n  body?: string;\n  specs?: { label: string; value: string }[];\n  finish?: S3Finish;\n  href?: string;\n  className?: string;\n};\n\n/**\n * A card that holds a small machined dial. The dial is built in CSS 3D (a\n * stack of knurled discs under a glass cap) and sits on a panel ringed with\n * detent ticks; the card tilts toward the pointer (at most 6 degrees) and the\n * dial turns to follow it, one detent at a time on a spring, its copper\n * marker lit while you're there. Focus does the same. The specs underneath\n * are set in mono, like a data plate.\n */\nexport function ExtrudedSpecCard({ title, kicker, body, specs = [], finish = \"titanium\", href, className }: ExtrudedSpecCardProps) {\n  const [pose, setPose] = useState({ rx: 0, ry: 0, turn: 0, on: false });\n  const turnRef = useRef({ x: 0, v: 0, raf: 0, last: 0 });\n  const [angle, setAngle] = useState(0);\n  const reduced = useReducedMotion();\n\n  // The dial settles on its detent with a spring (stiffness 340, damping 26).\n  useEffect(() => {\n    const t = turnRef.current;\n    const target = pose.turn;\n    if (reduced) {\n      t.x = target;\n      const id = requestAnimationFrame(() => setAngle(target));\n      return () => cancelAnimationFrame(id);\n    }\n    const step = (now: number) => {\n      const dt = t.last ? Math.min(0.05, (now - t.last) / 1000) : 1 / 60;\n      t.last = now;\n      [t.x, t.v] = spring(t.x, t.v, target, dt);\n      setAngle(t.x);\n      if (Math.abs(target - t.x) > 0.02 || Math.abs(t.v) > 0.02) t.raf = requestAnimationFrame(step);\n      else t.last = 0;\n    };\n    cancelAnimationFrame(t.raf);\n    t.raf = requestAnimationFrame(step);\n    return () => cancelAnimationFrame(t.raf);\n  }, [pose.turn, reduced]);\n\n  const onMove = (e: ReactPointerEvent<HTMLElement>) => {\n    const r = e.currentTarget.getBoundingClientRect();\n    const x = (e.clientX - r.left) / r.width - 0.5;\n    const y = (e.clientY - r.top) / r.height - 0.5;\n    setPose({ rx: reduced ? 0 : -y * 12, ry: reduced ? 0 : x * 12, turn: Math.round(x * 20) * 6, on: true });\n  };\n  const rest = () => setPose({ rx: 0, ry: 0, turn: 0, on: false });\n  const shared = {\n    onPointerMove: onMove,\n    onPointerLeave: rest,\n    onFocus: () => setPose((p) => ({ ...p, turn: 30, on: true })),\n    onBlur: rest,\n    className: \"s3-scope group block rounded-[20px] border p-5 outline-none \" + (className ?? \"\"),\n    style: {\n      background: `linear-gradient(180deg, ${ROOM.raised}, ${ROOM.panel})`,\n      borderColor: pose.on ? ROOM.line2 : ROOM.line,\n      color: ROOM.ink,\n      transform: `perspective(900px) rotateX(${pose.rx.toFixed(2)}deg) rotateY(${pose.ry.toFixed(2)}deg)`,\n      transition: `transform 380ms ${EASE}, border-color 220ms`,\n      \"--s3-ring\": ROOM.copper,\n    } as CSSProperties,\n  };\n  const inner = (\n    <>\n      <span className=\"flex items-baseline justify-between text-[11px] uppercase tracking-[0.18em]\" style={{ fontFamily: MONO, color: ROOM.ink3 }}>\n        <span>{kicker}</span>\n        <span className=\"tabular-nums\">{String(((Math.round(angle / 6) % 60) + 60) % 60).padStart(2, \"0\")}/60</span>\n      </span>\n      <span className=\"my-5 grid place-items-center\">\n        <CssDial finish={finish} angle={angle} size={148} tiltX={24 - pose.rx} tiltY={-16 + pose.ry} lit={pose.on} ticks={60} />\n      </span>\n      <span className=\"block text-[26px] font-semibold leading-[1.05] tracking-[-0.02em]\" style={{ fontFamily: DISPLAY, color: \"#f2f1ee\" }}>\n        {title}\n      </span>\n      {body ? (\n        <span className=\"mt-2 block text-[14px] leading-[1.55]\" style={{ fontFamily: SANS, color: ROOM.ink2 }}>\n          {body}\n        </span>\n      ) : null}\n      {specs.length ? (\n        <span className=\"mt-4 grid gap-1.5 border-t pt-3\" style={{ borderColor: ROOM.line }}>\n          {specs.map((s) => (\n            <span key={s.label} className=\"flex justify-between gap-4 text-[11px] uppercase tracking-[0.14em]\" style={{ fontFamily: MONO }}>\n              <span style={{ color: ROOM.ink3 }}>{s.label}</span>\n              <span className=\"tabular-nums\" style={{ color: ROOM.ink2 }}>\n                {s.value}\n              </span>\n            </span>\n          ))}\n        </span>\n      ) : null}\n    </>\n  );\n  return (\n    <>\n      <style>{FOCUS_CSS}</style>\n      {href ? (\n        <a href={safeHref(href)} {...shared}>\n          {inner}\n        </a>\n      ) : (\n        <div tabIndex={0} {...shared}>\n          {inner}\n        </div>\n      )}\n    </>\n  );\n}\n","type":"registry:component","target":"components/viberdy/extruded-spec-card.tsx"}],"meta":{"tier":"free","tags":["card","3d","css 3d","dial","tilt","product","specs"],"href":"https://viberdy.dev/library/extruded-spec-card","aiPrompt":"Build a React + Tailwind card, `ExtrudedSpecCard({ title, kicker, body, specs, finish, href, className })`.\n\nThe dial (CSS 3D): a container with perspective 4x its size and preserve-3d, tilted rotateX 24deg / rotateY -16deg; a base panel (radial gradient, a drop shadow) at translateZ(-8px) ringed with 60 SVG tick marks (every fifth longer); nine discs (inset 8%) at translateZ(i x 2.2px), each a repeating-conic-gradient of the finish's side and shade colours in 3-degree bands, brightening toward the top; a face (inset 13%) with a radial finish gradient, a dark glass cap inside it and a copper dot; every disc and the face rotateZ by the dial angle. On pointermove the card tilts (rx = -y x 12, ry = x x 12 degrees, 380ms) and the dial's target becomes round(x x 20) x 6 degrees, followed by a spring (stiffness 340, damping 26); leave or blur returns everything. A mono kicker with the current detent (n/60), the title in Hanken Grotesk 600 at 26px, the body, and mono spec rows. Radius 20px, a raised-to-panel gradient, a hairline border.\n\nSpatial 3D grammar: a dark studio, ground #0a0a0d (panels #101114, raised #16171b, ink #f2f1ee at 92/60/38%, hairlines at 8% and 16%), and one accent, anodised copper #ff7a3d, used only as light (a status arc, a detent marker, an active underglow), never as a fill. One object in three finishes, as material parameters: titanium (base #b9bcc2, gloss 0.62, specular 0.8, fully metallic), ceramic (#ece7dd, gloss 0.4, specular 0.25, a little subsurface wrap) and soft-touch polymer (#1b1c20, gloss 0.3, specular 0.12, the rim kept up so it holds against the ground). One rig for everything: a warm key from (0.55, 0.65, 0.42) at 1.15, a cool fill from (-0.4, -0.15, 0.55) at 0.3, a rim from behind at 0.65, soft shadows (k 16), five-tap occlusion and a studio reflection (a big softbox overhead left, a strip behind right), in linear light with a filmic curve and a 1/255 dither. Parts are blended with small smooth-min radii (8-15% of the smaller part) so the object reads as machined, not melted. Hanken Grotesk through var(--font-hanken, \"Hanken Grotesk\", ...) at 600-800 for display, Geist for reading, Geist Mono uppercase for readouts. Radii 24px panels, 20px cards, 14px controls, the dial full round. Motion: detent springs (stiffness 340, damping 26, ~380ms), orbit inertia that decays in ~270ms, an idle drift of 6 degrees a second on the page clock after 2.5s of stillness, hovers and presses in 90-420ms. Respect prefers-reduced-motion (a still three-quarter view you can still turn by hand; no drift, no scatter). No dependencies beyond React.","license":"https://viberdy.dev/license"}}