{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slip",
  "title": "Slip",
  "description": "Taped paper slip of out-of-register writing that peels, lifts, and travels while registers reflow around it.",
  "registryDependencies": [
    "@jbm/tokens",
    "@jbm/scene-geometry",
    "@jbm/paper",
    "@jbm/register"
  ],
  "files": [
    {
      "path": "registry/jbm/ui/slip.tsx",
      "content": "import type { CSSProperties } from \"react\"\nimport { Paper, paperShadow } from \"./paper\"\nimport { RegisterInk, type RegisterKind } from \"./register\"\nimport { color, outlineIn } from \"../lib/tokens\"\nimport { unit, type Pt } from \"../lib/geometry\"\n\n/**\n * An out-of-register block: a small paper strip carrying a few marks of one register, taped onto a\n * sheet where it does not belong. `lift` peels the tape and raises it; `offset` carries it. The\n * host owns the path, the hand, and the sheets' reflow (Register gapAt / reflow). Pure React.\n */\nexport type SlipProps = {\n  /** 0 flat on a sheet, 1 held above it: the tape flap peels by 0.4, the shadow deepens, the slip rises and tilts. */\n  lift?: number\n  /** Translation from the slip's resting place, in px. */\n  offset?: Pt\n  /** Masking tape across the top edge. */\n  tape?: boolean\n  /** Flag the slip as out of place with an ink bracket in the margin beside its left edge, like an editor's mark. */\n  flag?: boolean\n  /** @deprecated Use `flag`. Kept as an alias: it draws the same margin bracket, never a dashed outline. */\n  dashed?: boolean\n  /** Register drawn on the slip (default prose). */\n  kind?: Exclude<RegisterKind, \"mixed\">\n  /** Steps, groups, tables, or (prose) source ticks on the slip. */\n  n?: number\n  /** Slip width in px. */\n  w?: number\n  /** Slip height in px. */\n  h?: number\n  /** Resting rotation in degrees. */\n  rotate?: number\n  /** Mark scale; match the sheet it came from (Register uses w / 360). */\n  scale?: number\n  /** Writing drawn so far, 0–1. */\n  reveal?: number\n  /** Cell indices whose lead mark is vermilion. */\n  accent?: readonly number[]\n  style?: CSSProperties\n}\ntype Geometry = Required<Pick<SlipProps, \"lift\" | \"offset\" | \"w\" | \"h\" | \"rotate\" | \"scale\">>\nconst resolve = (p: SlipProps): Geometry => ({\n  lift: unit(p.lift ?? 0),\n  offset: p.offset ?? { x: 0, y: 0 },\n  w: p.w ?? 240,\n  h: p.h ?? 72,\n  rotate: p.rotate ?? -2,\n  scale: p.scale ?? 1,\n})\nconst pose = (g: Geometry) => ({\n  rise: 10 * g.scale * g.lift,\n  angle: g.rotate + 3 * g.lift,\n  zoom: 1 + 0.04 * g.lift,\n})\n\n/** A point on the slip (local px from its top-left) in the host's px, after lift and offset. */\nexport function slipPoint(props: SlipProps, local: Pt): Pt {\n  const g = resolve(props)\n  const { rise, angle, zoom } = pose(g)\n  const cx = g.w / 2,\n    cy = g.h / 2\n  const a = (angle * Math.PI) / 180\n  const dx = (local.x - cx) * zoom,\n    dy = (local.y - cy) * zoom\n  return {\n    x: g.offset.x + cx + dx * Math.cos(a) - dy * Math.sin(a),\n    y: g.offset.y - rise + cy + dx * Math.sin(a) + dy * Math.cos(a),\n  }\n}\n/** Where a pinch holds the slip: the middle of its bottom (default) or top edge, in host px. */\nexport const slipGrip = (props: SlipProps, edge: \"top\" | \"bottom\" = \"bottom\"): Pt => {\n  const g = resolve(props)\n  return slipPoint(props, { x: g.w * 0.5, y: edge === \"top\" ? 0 : g.h })\n}\n\n/**\n * Torn masking tape: a body on the slip and a flap that peels up about the fold. The flap stays\n * hinged along the whole fold line: as it lifts off the slip it foreshortens and its free end\n * rises (a shear about the fold), so no wedge ever opens between flap and body.\n */\nfunction Tape({ w, u, peel }: { w: number; u: number; peel: number }) {\n  const L = Math.min(w * 0.8, Math.max(56 * u, w * 0.34))\n  const T = 14 * u\n  const d = 2.5 * u\n  const fold = L * 0.64\n  const x0 = w * 0.56 - L / 2\n  // Torn ends: seven points down each end, alternating flush and `d` inward.\n  const torn = (x: number, dir: 1 | -1, down: boolean) =>\n    Array.from({ length: 7 }, (_, k) => {\n      const y = (k * T) / 6\n      return `L${x + (k % 2 ? dir * d : 0)} ${down ? y : T - y}`\n    }).join(\" \")\n  // Outlines stop at the fold, so flat tape reads as one strip; the crease inks in as the flap bends.\n  const body = `M${fold} ${T}H0${torn(0, 1, false)}L${fold} 0`\n  const flap = `M${fold} 0H${L}${torn(L, -1, true)}H${fold}`\n  const stroke = Math.max(1, 1.25 * u)\n  const line = { fill: \"none\", stroke: color.ink, strokeWidth: stroke, strokeLinejoin: \"round\", strokeLinecap: \"round\" } as const\n  return (\n    <svg\n      aria-hidden\n      width={L + 4 * u}\n      height={T * 3}\n      viewBox={`${-2 * u} ${-T * 2} ${L + 4 * u} ${T * 3}`}\n      style={{ position: \"absolute\", left: x0 - 2 * u, top: -T / 2 - T * 2, overflow: \"visible\", transform: \"rotate(-3deg)\" }}\n    >\n      <path d={`${body}H${fold + (peel > 0 ? 0 : 0.75 * u)}V${T}Z`} fill={color.line} />\n      <path d={body} {...line} />\n      {peel > 0 && <path d={`M${fold} 0V${T}`} {...line} strokeOpacity={Math.min(1, peel * 8)} />}\n      <g transform={flapMatrix(peel, fold, L, T)}>\n        <path d={`${flap}Z`} fill={color.line} />\n        <path d={flap} {...line} />\n        {peel > 0 && <path d={`M${fold} 0V${T}`} {...line} strokeOpacity={Math.min(1, peel * 8)} />}\n      </g>\n    </svg>\n  )\n}\n\n/** The flap's peel as an affine map that keeps the fold line (x = fold) fixed. */\nfunction flapMatrix(peel: number, fold: number, L: number, T: number) {\n  const k = 1 - 0.42 * peel\n  const rise = (0.95 * T * peel) / Math.max(1, L - fold)\n  const r = (n: number) => Math.round(n * 1000) / 1000\n  return `matrix(${r(k)} ${r(-rise)} 0 1 ${r(fold * (1 - k))} ${r(rise * fold)})`\n}\n\n/**\n * The out-of-place flag: an ink bracket in the margin left of the slip, an editor's mark rather\n * than a selection box. Its spine stands BRACKET.gap × scale px off the slip's edge and its arms\n * reach back toward the slip, a little inside its height, at the shared outline.\n */\nconst BRACKET = { gap: 15, arm: 6, inset: 4 }\nfunction MarginBracket({ h, u }: { h: number; u: number }) {\n  const x = -BRACKET.gap * u\n  const top = BRACKET.inset * u,\n    bottom = h - BRACKET.inset * u\n  const arm = BRACKET.arm * u\n  const r = (n: number) => Math.round(n * 100) / 100\n  return (\n    <path\n      data-flag=\"\"\n      d={`M${r(x + arm)} ${r(top)}H${r(x)}V${r(bottom)}H${r(x + arm)}`}\n      fill=\"none\"\n      stroke={color.ink}\n      strokeWidth={EDGE}\n      strokeLinecap=\"round\"\n      strokeLinejoin=\"round\"\n    />\n  )\n}\n\n/** The slip's ink edge, drawn inside its box: the shared outline. */\nconst EDGE = outlineIn()\n\n/** A taped paper slip carrying a few marks of one register; lift and offset are controlled. */\nexport function Slip(props: SlipProps) {\n  const { tape = true, flag, dashed = false, kind = \"prose\", n, reveal = 1, accent, style } = props\n  const flagged = flag ?? dashed\n  const g = resolve(props)\n  const { rise, angle, zoom } = pose(g)\n  const peel = unit(g.lift / 0.4)\n  const u = g.scale\n  const lift = g.lift\n  const shadow = lift\n    ? `${paperShadow}, 0 ${6 + 22 * lift}px ${10 + 30 * lift}px -${6 + 4 * lift}px rgba(32,36,31,${(0.1 + 0.12 * lift).toFixed(3)})`\n    : paperShadow\n  return (\n    <div\n      style={{\n        width: g.w,\n        height: g.h,\n        transform: `translate(${g.offset.x}px, ${g.offset.y - rise}px) rotate(${angle}deg) scale(${zoom})`,\n        transformOrigin: \"50% 50%\",\n        position: \"relative\",\n        flexShrink: 0,\n        ...style,\n      }}\n    >\n      <Paper w={g.w} h={g.h} radius={Math.max(2, 3 * u)} edge={false} style={{ boxShadow: shadow, position: \"absolute\", left: 0, top: 0 }}>\n        <svg width={g.w} height={g.h} viewBox={`0 0 ${g.w} ${g.h}`} role=\"img\" aria-label={`Slip of ${kind} writing`} style={{ display: \"block\", overflow: \"visible\" }}>\n          <RegisterInk kind={kind} n={n ?? (kind === \"prose\" ? 2 : kind === \"mono\" ? 1 : 2)} w={g.w} h={g.h} scale={u} pad={10 * u} reveal={reveal} accent={accent} />\n          <rect\n            x={EDGE / 2}\n            y={EDGE / 2}\n            width={g.w - EDGE}\n            height={g.h - EDGE}\n            rx={Math.max(1, 3 * u - EDGE / 2)}\n            fill=\"none\"\n            stroke={color.ink}\n            strokeWidth={EDGE}\n          />\n          {flagged && <MarginBracket h={g.h} u={u} />}\n        </svg>\n      </Paper>\n      {tape && <Tape w={g.w} u={u} peel={peel} />}\n    </div>\n  )\n}\n",
      "type": "registry:ui",
      "target": "src/jbm/ui/slip.tsx"
    }
  ],
  "categories": [
    "UI Bits"
  ],
  "type": "registry:ui"
}