{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ejes",
  "title": "Ejes",
  "description": "Two ink axes that split an area into four named quadrants, with quiet labels and a focus quadrant.",
  "registryDependencies": [
    "@jbm/tokens",
    "@jbm/scene-geometry"
  ],
  "files": [
    {
      "path": "registry/jbm/ui/ejes.tsx",
      "content": "import { color, font, sansWidth } from \"../lib/tokens\"\nimport { unit, type Box, type Pt } from \"../lib/geometry\"\n\nexport type Quadrant = \"tl\" | \"tr\" | \"bl\" | \"br\"\nexport type EjesSide = \"top\" | \"bottom\" | \"left\" | \"right\"\n/** Half-plane names: top and bottom flank the horizontal axis, left and right the vertical one. */\nexport type EjesLabels = Record<EjesSide, string>\nexport type EjesFocusTone = \"ink\" | \"fill\" | \"accent\"\nexport type EjesProps = {\n  /** Area the axes span, in parent SVG units. */\n  box: Box\n  /**\n   * Where the axes cross. Defaults to the centre of box. Clamped to the range that keeps every\n   * label inside box and clear of the other axis (see ejesLayout's `range`); a box too small for\n   * the labels crosses at its centre.\n   */\n  center?: Pt\n  /** Horizontal axis draw progress, 0–1. Clamped. */\n  h: number\n  /** Vertical axis draw progress, 0–1. Clamped. */\n  v: number\n  labels: EjesLabels\n  /** Labels shrink to small text at the axis ends: false/0 full, true/1 quiet, between interpolates. */\n  quiet?: boolean | number\n  /** Per-label opacity 0–1. Omitted labels fade in as their axis reaches them. */\n  reveal?: Partial<Record<EjesSide, number>>\n  /** Axes grow out from the crossing (center) or from the left and top edges (start). */\n  origin?: \"center\" | \"start\"\n  /** Quadrant(s) called out: one, or several at once (all four for \"cuatro\"). */\n  focus?: Quadrant | readonly Quadrant[]\n  /**\n   * ink outline (default), fill (light ink wash), or accent: a vermilion outline, opt-in, on the\n   * first focused quadrant only (the others stay ink), so the set carries one stamp.\n   */\n  focusTone?: EjesFocusTone\n  /** Focus outline draw / fill progress, 0–1. Defaults to 1. Clamped. */\n  focusProgress?: number\n  /** Gap between a focus outline and the axes and box edges, in parent units. */\n  focusInset?: number\n  /** Axis and outline stroke width, in parent units. Default 2, the desk's line weight. */\n  weight?: number\n}\n\nexport const quadrants = [\"tl\", \"tr\", \"bl\", \"br\"] as const\n/** Label size in parent units: full, then quiet. */\nexport const EJES_TYPE = { full: 36, quiet: 22 } as const\nconst PAD = 14\nconst GAP = 12\nconst FADE = 60\n/** A focus outline smaller than this on either side is not drawn: it would read as a pill. */\nconst FOCUS_MIN = 40\n\n/** Axis, label, and quadrant geometry; everything follows from box, center, and progress. */\nexport function ejesLayout({\n  box,\n  center,\n  h,\n  v,\n  quiet = false,\n  reveal = {},\n  origin = \"center\",\n  focusInset = 16,\n  labels,\n}: Pick<\n  EjesProps,\n  \"box\" | \"center\" | \"h\" | \"v\" | \"quiet\" | \"reveal\" | \"origin\" | \"focusInset\"\n> & { labels?: Partial<EjesLabels> }) {\n  const q = unit(typeof quiet === \"boolean\" ? Number(quiet) : quiet)\n  const size = EJES_TYPE.full + (EJES_TYPE.quiet - EJES_TYPE.full) * q\n  // The crossing's valid range: the left label (right-aligned at the vertical axis) and the top\n  // and bottom labels (from the left edge) must end before the vertical axis, the right label\n  // must fit after it; the top label sits below the left and right labels and above the axis,\n  // the bottom label below it. Widths are Geist 800 estimates, so they err wide.\n  const tw = (side: EjesSide) => (labels?.[side] ? sansWidth(labels[side] as string, size) : 0)\n  const range = {\n    x: [\n      box.x + Math.max(PAD + Math.max(tw(\"top\"), tw(\"bottom\")) + GAP, GAP + tw(\"left\")),\n      box.x + box.w - GAP - tw(\"right\"),\n    ],\n    y: [box.y + PAD + size + 4 + size + GAP, box.y + box.h - GAP - size],\n  } as const\n  const pick = (want: number, [lo, hi]: readonly [number, number], mid: number) =>\n    lo <= hi ? Math.min(hi, Math.max(lo, want)) : mid\n  const c = {\n    x: pick(center?.x ?? box.x + box.w / 2, range.x, box.x + box.w / 2),\n    y: pick(center?.y ?? box.y + box.h / 2, range.y, box.y + box.h / 2),\n  }\n  const ph = unit(h),\n    pv = unit(v)\n  const right = box.x + box.w,\n    bottom = box.y + box.h\n  const horizontal =\n    origin === \"start\"\n      ? { x1: box.x, x2: box.x + ph * box.w }\n      : { x1: c.x - ph * (c.x - box.x), x2: c.x + ph * (right - c.x) }\n  const vertical =\n    origin === \"start\"\n      ? { y1: box.y, y2: box.y + pv * box.h }\n      : { y1: c.y - pv * (c.y - box.y), y2: c.y + pv * (bottom - c.y) }\n  // Labels sit at the left end of the horizontal axis and the top end of the vertical one.\n  const hx = box.x + PAD,\n    vy = box.y + PAD\n  // Labels arrive with the line: growing from the crossing, over the last FADE units before the\n  // tip reaches their end; growing from the edge, over the first FADE units drawn.\n  const hPast =\n    origin === \"start\"\n      ? horizontal.x2 - box.x\n      : box.x + FADE - horizontal.x1\n  const vPast =\n    origin === \"start\" ? vertical.y2 - box.y : box.y + FADE - vertical.y1\n  const arrived = (past: number, p: number) => (p > 0 ? unit(past / FADE) : 0)\n  const opacity = (side: EjesSide) =>\n    unit(\n      reveal[side] ??\n        (side === \"top\" || side === \"bottom\"\n          ? arrived(hPast, ph)\n          : arrived(vPast, pv))\n    )\n  const anchors = {\n    top: { x: hx, y: c.y - GAP, anchor: \"start\", baseline: \"auto\" },\n    bottom: { x: hx, y: c.y + GAP, anchor: \"start\", baseline: \"hanging\" },\n    left: { x: c.x - GAP, y: vy, anchor: \"end\", baseline: \"hanging\" },\n    right: { x: c.x + GAP, y: vy, anchor: \"start\", baseline: \"hanging\" },\n  } as const\n  const quad = {\n    tl: { x: box.x, y: box.y, w: c.x - box.x, h: c.y - box.y },\n    tr: { x: c.x, y: box.y, w: right - c.x, h: c.y - box.y },\n    bl: { x: box.x, y: c.y, w: c.x - box.x, h: bottom - c.y },\n    br: { x: c.x, y: c.y, w: right - c.x, h: bottom - c.y },\n  } satisfies Record<Quadrant, Box>\n  // Focus outlines keep clear of the labels, and stay one aligned set: both top quadrants give up\n  // the strip the left/right labels need, both give up the strip above the horizontal axis that\n  // the top label needs, and both bottom quadrants the strip below it for the bottom label.\n  const has = (side: EjesSide) => !labels || Boolean(labels[side])\n  const hStrip = (side: EjesSide) =>\n    has(side) ? Math.max(focusInset, GAP + size + 6) : focusInset\n  const vStrip = (side: EjesSide) =>\n    has(side) ? Math.max(focusInset, PAD + size + 6) : focusInset\n  const topStrip = Math.max(vStrip(\"left\"), vStrip(\"right\"))\n  // All four outlines are one size: as tall as the shorter row allows and as wide as the narrower\n  // column, each hugging the axes' crossing, so the set is symmetric about both axes.\n  const rowH = Math.max(\n    0,\n    Math.min(\n      c.y - box.y - topStrip - hStrip(\"top\"),\n      bottom - c.y - hStrip(\"bottom\") - focusInset\n    )\n  )\n  const colW = Math.max(\n    0,\n    Math.min(c.x - box.x, right - c.x) - 2 * focusInset\n  )\n  const focusBox = (q: Quadrant): Box => ({\n    x: q === \"tl\" || q === \"bl\" ? c.x - focusInset - colW : c.x + focusInset,\n    y: q === \"tl\" || q === \"tr\" ? c.y - hStrip(\"top\") - rowH : c.y + hStrip(\"bottom\"),\n    w: colW,\n    h: rowH,\n  })\n  return {\n    box,\n    center: c,\n    horizontal: { ...horizontal, y: c.y },\n    vertical: { ...vertical, x: c.x },\n    type: { size, quiet: q },\n    labels: Object.fromEntries(\n      (Object.keys(anchors) as EjesSide[]).map((side) => [\n        side,\n        { ...anchors[side], opacity: opacity(side) },\n      ])\n    ) as Record<EjesSide, (typeof anchors)[EjesSide] & { opacity: number }>,\n    /** Each quadrant's full box between the axes and the edges. */\n    quadrants: quad,\n    /** The crossing's valid range, [min, max] per axis; center is clamped into it. */\n    range,\n    /** The rounded focus outline box for each quadrant (w and h 0 when too small to draw). */\n    focus: Object.fromEntries(\n      quadrants.map((k) => {\n        const b = focusBox(k)\n        return [k, b.w < FOCUS_MIN || b.h < FOCUS_MIN ? { ...b, w: 0, h: 0 } : b]\n      })\n    ) as Record<Quadrant, Box>,\n  }\n}\n\n/** Two ink axes that split an area into four named quadrants, with an optional focus. */\nexport function Ejes({\n  labels,\n  focus,\n  focusTone = \"ink\",\n  focusProgress = 1,\n  weight = 2,\n  quiet = false,\n  origin = \"center\",\n  focusInset = 16,\n  ...props\n}: EjesProps) {\n  const l = ejesLayout({ ...props, labels, quiet, origin, focusInset })\n  const focused = (\n    focus === undefined ? [] : typeof focus === \"string\" ? [focus] : focus\n  ).filter((f, i, all) => quadrants.includes(f) && all.indexOf(f) === i)\n  const fp = unit(focusProgress)\n  // One stamp: accent marks only the first focused quadrant; any others keep the ink outline.\n  const tone = (i: number) => (focusTone === \"accent\" && i === 0 ? color.accent : color.ink)\n  // Geist is variable: the weight eases from 650 to 500 with the size, no mid-way jump.\n  const weightText = Math.round(650 - 150 * l.type.quiet)\n  return (\n    <g\n      role=\"img\"\n      aria-label={`Axes: ${labels.top} above, ${labels.bottom} below, ${labels.left} left, ${labels.right} right${focused.length ? `; focus ${focused.join(\", \")}` : \"\"}`}\n    >\n      {fp > 0 &&\n        focused.map((f, i) => {\n          const b = l.focus[f]\n          if (!(b.w > 0 && b.h > 0)) return null\n          return focusTone === \"fill\" ? (\n            <rect\n              key={f}\n              data-quadrant={f}\n              x={b.x}\n              y={b.y}\n              width={b.w}\n              height={b.h}\n              rx={12}\n              fill={color.ink}\n              fillOpacity={0.07 * fp}\n            />\n          ) : (\n            <rect\n              key={f}\n              data-quadrant={f}\n              x={b.x}\n              y={b.y}\n              width={b.w}\n              height={b.h}\n              rx={12}\n              fill=\"none\"\n              stroke={tone(i)}\n              strokeWidth={weight}\n              pathLength={1}\n              strokeDasharray={fp < 1 ? `${fp} 1` : undefined}\n            />\n          )\n        })}\n      <g stroke={color.ink} strokeWidth={weight} strokeLinecap=\"butt\">\n        {l.horizontal.x2 > l.horizontal.x1 && (\n          <line\n            x1={l.horizontal.x1}\n            x2={l.horizontal.x2}\n            y1={l.horizontal.y}\n            y2={l.horizontal.y}\n          />\n        )}\n        {l.vertical.y2 > l.vertical.y1 && (\n          <line\n            x1={l.vertical.x}\n            x2={l.vertical.x}\n            y1={l.vertical.y1}\n            y2={l.vertical.y2}\n          />\n        )}\n      </g>\n      <g\n        fontFamily={font.sans}\n        fontSize={l.type.size}\n        fontWeight={weightText}\n        fill={color.ink}\n        aria-hidden=\"true\"\n      >\n        {(Object.keys(l.labels) as EjesSide[]).map((side) => {\n          const t = l.labels[side]\n          return t.opacity > 0 && labels[side] ? (\n            <text\n              key={side}\n              x={t.x}\n              y={t.y}\n              textAnchor={t.anchor}\n              dominantBaseline={t.baseline}\n              opacity={t.opacity}\n            >\n              {labels[side]}\n            </text>\n          ) : null\n        })}\n      </g>\n    </g>\n  )\n}\n",
      "type": "registry:component",
      "target": "src/jbm/ui/ejes.tsx"
    }
  ],
  "categories": [
    "UI"
  ],
  "type": "registry:component"
}