{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "desk-prop",
  "title": "DeskProp",
  "description": "A free-standing keycap, keyboard, or mug (from above or standing, from the side) to place on a desk.",
  "registryDependencies": [
    "@jbm/tokens",
    "@jbm/scene-geometry"
  ],
  "files": [
    {
      "path": "registry/jbm/ui/desk-prop.tsx",
      "content": "import { color, stroke } from \"../lib/tokens\"\nimport { unit, type Pt } from \"../lib/geometry\"\n\n/**\n * keycap, keyboard, and mug are seen from above, like the desk they sit on; mug-side is the same\n * mug seen from the side, standing upright, for a hand that holds it.\n */\nexport type DeskPropKind = \"keycap\" | \"keyboard\" | \"mug\" | \"mug-side\"\nexport type DeskPropProps = {\n  kind: DeskPropKind\n  /** Centre of the prop's footprint, in parent SVG units. */\n  x: number\n  y: number\n  /** Uniform size multiplier; the ink stroke stays `weight` parent units. Defaults to 1. */\n  scale?: number\n  /** Ink stroke width in parent units at any scale. Default stroke.outline (3), the shared outline. A small keyboard draws its key outlines at no more than half the gap between keys. */\n  weight?: number\n  /** Rotation in degrees around the centre. Defaults to 0. */\n  rotate?: number\n  /** Key travel, 0–1: the keycap sinks, or the keyboard keys listed in `keys` do. Clamped. */\n  press?: number\n  /** Keyboard only: indices of the keys `press` applies to, row by row (see deskPropKeys). */\n  keys?: readonly number[]\n}\n\n/** Footprint at scale 1, in parent units (width × height, centred on x, y). */\nexport const deskPropSize = {\n  keycap: { w: 56, h: 56 },\n  keyboard: { w: 314, h: 100 },\n  mug: { w: 90, h: 78 },\n  \"mug-side\": { w: 90, h: 78 },\n} as const satisfies Record<DeskPropKind, { w: number; h: number }>\n\ntype Key = { x: number; y: number; w: number; h: number }\n/** Keyboard key pitch (one key unit) and the gap between neighbouring keys, in local units. */\nconst PITCH = 20,\n  GAP = 6\n/**\n * A compact keyboard's four rows in key units (15 to a row): letter rows offset by their\n * modifiers (tab, caps, shift) so no column lines up, and a modifier row around the space bar.\n */\nconst KEY_ROWS: readonly (readonly number[])[] = [\n  [1.5, ...Array(12).fill(1), 1.5], // tab, 12 letters, backslash\n  [1.75, ...Array(11).fill(1), 2.25], // caps, 11 letters, return\n  [2.25, ...Array(10).fill(1), 2.75], // shift, 10 letters, shift\n  [1.25, 1.25, 1.25, 6.25, 1.25, 1.25, 1.25, 1.25], // ctrl, alt, cmd, space, cmd, alt, fn, ctrl\n]\n/**\n * Keyboard keys in local units (centre origin), row by row from the top left: 14 on the top row,\n * 13 on the home row, 12 on the shift row, then 8 modifiers around the space bar (index 42).\n */\nexport const deskPropKeys: readonly Key[] = (() => {\n  const { w, h } = deskPropSize.keyboard\n  const left = -w / 2 + (w - (15 * PITCH - GAP)) / 2\n  const top = -h / 2 + (h - (KEY_ROWS.length * PITCH - GAP)) / 2\n  const keys: Key[] = []\n  KEY_ROWS.forEach((row, r) => {\n    let x = left\n    for (const units of row) {\n      keys.push({ x, y: top + r * PITCH, w: units * PITCH - GAP, h: PITCH - GAP })\n      x += units * PITCH\n    }\n  })\n  return keys\n})()\n/** The keyboard's home-row key nearest its centre (H), where deskPropLayout's contact lands. */\nexport const deskPropHomeKey = 20\n\n// Mug from above, like the keycap and keyboard: a round body with its rim, the handle to the right.\nconst MUG = { cx: -8, r: 36, rim: 28, handle: { x0: 20, x1: 44, half: 8 } }\n/**\n * Mug from the side, standing upright: a body a little taller than wide with rounded bottom\n * corners, the rim's ellipse across its top (filled like the top-down mug's), and a C-shaped\n * handle to the right whose ends run under the body.\n */\nconst MUG_SIDE = {\n  left: -40,\n  right: 20,\n  top: -31,\n  bottom: 36,\n  corner: 10,\n  rim: 6,\n  handle: { cy: -2, outer: 19, inner: 11 },\n}\n/** Ink wash on a pressed key face at full travel: the visual language's deepest light, 0.72. */\nconst PRESS_WASH = 0.28\n\nconst r2 = (n: number) => Math.round(n * 100) / 100\n\n/** Placement, footprint corners, and contact points in parent units. */\nexport function deskPropLayout({\n  kind,\n  x,\n  y,\n  scale = 1,\n  rotate = 0,\n  press = 0,\n}: DeskPropProps) {\n  const a = (rotate * Math.PI) / 180,\n    cos = Math.cos(a),\n    sin = Math.sin(a)\n  const toParent = (p: Pt): Pt => ({\n    x: x + scale * (p.x * cos - p.y * sin),\n    y: y + scale * (p.x * sin + p.y * cos),\n  })\n  const { w, h } = deskPropSize[kind]\n  const corners = [\n    { x: -w / 2, y: -h / 2 },\n    { x: w / 2, y: -h / 2 },\n    { x: w / 2, y: h / 2 },\n    { x: -w / 2, y: h / 2 },\n  ].map(toParent)\n  const sink = 3 * unit(press)\n  const keyCenters = deskPropKeys.map((k) =>\n    toParent({ x: k.x + k.w / 2, y: k.y + k.h / 2 })\n  )\n  const S = MUG_SIDE\n  const contact =\n    kind === \"keycap\"\n      ? toParent({ x: 0, y: -3 + sink })\n      : kind === \"keyboard\"\n        ? keyCenters[deskPropHomeKey] // the home-row key nearest the middle\n        : kind === \"mug\"\n          ? toParent({ x: (MUG.cx + MUG.r + MUG.handle.x1) / 2, y: 0 }) // on the handle\n          : toParent({ x: S.left, y: (S.top + S.bottom) / 2 }) // the body's free side\n  return {\n    kind,\n    center: { x, y } satisfies Pt,\n    size: { w: w * scale, h: h * scale },\n    corners,\n    /** Where a fingertip or grip meets the prop. */\n    contact,\n    /** mug-side only: the rim's near (left) end, where a thumb crosses over the top. Null otherwise. */\n    rim: kind === \"mug-side\" ? toParent({ x: S.left, y: S.top }) : null,\n    /** Keyboard key centres, in the order of deskPropKeys; empty for the other kinds. */\n    keys: kind === \"keyboard\" ? keyCenters : [],\n    transform: `translate(${x} ${y}) rotate(${rotate}) scale(${scale})`,\n  }\n}\n\nconst labels: Record<DeskPropKind, string> = {\n  keycap: \"Keycap\",\n  keyboard: \"Keyboard\",\n  mug: \"Mug\",\n  \"mug-side\": \"Mug, side view\",\n}\n\n/** A small free-standing desk object: a keycap, a keyboard, or a mug (from above or the side). Hands are separate. */\nexport function DeskProp({\n  scale = 1,\n  rotate = 0,\n  press = 0,\n  keys = [],\n  weight = stroke.outline,\n  ...props\n}: DeskPropProps) {\n  const { kind } = props\n  const l = deskPropLayout({ ...props, scale, rotate, press })\n  const p = unit(press)\n  // The group is scaled, so the stroke is divided by scale to stay `weight` parent units.\n  const line = weight / (scale || 1)\n  // Key outlines never take more than half the gap between keys, so a small keyboard keeps\n  // cream between its keys instead of fusing into an ink grid. The case keeps the full weight.\n  const keyLine = Math.min(line, GAP / 2)\n  const S = MUG_SIDE\n  const H = S.handle\n  return (\n    <g\n      transform={l.transform}\n      role=\"img\"\n      aria-label={labels[kind]}\n      stroke={color.ink}\n      strokeWidth={line}\n      strokeLinejoin=\"round\"\n      fill={color.card}\n    >\n      {kind === \"keycap\" && (\n        <>\n          <rect x={-28} y={-28} width={56} height={56} rx={8} />\n          {/* The dished top: set back toward the far wall, centred and shrinking as the key\n              sinks, with a light ink wash so a pressed key reads at normal size. */}\n          <rect\n            x={-19 + 4 * p}\n            y={-22 + 7 * p}\n            width={38 - 8 * p}\n            height={38 - 8 * p}\n            rx={5}\n            fill={p > 0 ? color.bg : color.card}\n          />\n          {p > 0 && (\n            <rect\n              x={-19 + 4 * p}\n              y={-22 + 7 * p}\n              width={38 - 8 * p}\n              height={38 - 8 * p}\n              rx={5}\n              fill={color.ink}\n              fillOpacity={+(PRESS_WASH * p).toFixed(3)}\n              stroke=\"none\"\n            />\n          )}\n        </>\n      )}\n      {kind === \"keyboard\" && (\n        <>\n          <rect\n            x={-deskPropSize.keyboard.w / 2}\n            y={-deskPropSize.keyboard.h / 2}\n            width={deskPropSize.keyboard.w}\n            height={deskPropSize.keyboard.h}\n            rx={10}\n          />\n          {deskPropKeys.map((k, i) => {\n            // A pressed key sinks a tenth of its short side (at most 3 units) on every side and\n            // takes a light ink wash, so it keeps the shape of its neighbours.\n            const down = keys.includes(i) ? p : 0\n            const inset = Math.min(3, 0.1 * Math.min(k.w, k.h)) * down\n            const face = {\n              x: r2(k.x + inset),\n              y: r2(k.y + inset),\n              width: r2(k.w - 2 * inset),\n              height: r2(k.h - 2 * inset),\n              rx: 3,\n            }\n            return (\n              <g key={i} data-key={i}>\n                <rect {...face} strokeWidth={keyLine < line ? r2(keyLine) : undefined} fill={down > 0 ? color.bg : color.card} />\n                {down > 0 && (\n                  <rect\n                    {...face}\n                    fill={color.ink}\n                    fillOpacity={+(PRESS_WASH * down).toFixed(3)}\n                    stroke=\"none\"\n                  />\n                )}\n              </g>\n            )\n          })}\n        </>\n      )}\n      {kind === \"mug\" && (\n        <>\n          {/* The handle runs under the body, so only its free end shows. */}\n          <rect\n            x={MUG.handle.x0}\n            y={-MUG.handle.half}\n            width={MUG.handle.x1 - MUG.handle.x0}\n            height={2 * MUG.handle.half}\n            rx={MUG.handle.half}\n          />\n          <circle cx={MUG.cx} cy={0} r={MUG.r} />\n          <circle cx={MUG.cx} cy={0} r={MUG.rim} fill={color.line} />\n        </>\n      )}\n      {kind === \"mug-side\" && (\n        <>\n          {/* One C-shaped handle: a band between two concentric half circles, its ends tucked\n              under the body so only the loop shows. */}\n          <path\n            data-part=\"handle\"\n            d={`M${S.right - 6} ${H.cy - H.outer}H${S.right}A${H.outer} ${H.outer} 0 0 1 ${S.right} ${H.cy + H.outer}H${S.right - 6}V${H.cy + H.inner}H${S.right}A${H.inner} ${H.inner} 0 0 0 ${S.right} ${H.cy - H.inner}H${S.right - 6}Z`}\n          />\n          <path\n            data-part=\"body\"\n            d={`M${S.left} ${S.top}V${S.bottom - S.corner}A${S.corner} ${S.corner} 0 0 0 ${S.left + S.corner} ${S.bottom}H${S.right - S.corner}A${S.corner} ${S.corner} 0 0 0 ${S.right} ${S.bottom - S.corner}V${S.top}Z`}\n          />\n          {/* The rim: the mouth seen slightly from above, meeting the sides at its ends. */}\n          <ellipse\n            data-part=\"rim\"\n            cx={(S.left + S.right) / 2}\n            cy={S.top}\n            rx={(S.right - S.left) / 2}\n            ry={S.rim}\n            fill={color.line}\n          />\n        </>\n      )}\n    </g>\n  )\n}\n",
      "type": "registry:component",
      "target": "src/jbm/ui/desk-prop.tsx"
    }
  ],
  "categories": [
    "UI Bits"
  ],
  "type": "registry:component"
}