{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "eased-legal-core",
  "title": "Legal core primitive",
  "description": "Shared pieces for Eased legal blocks: the inline redline, the clause number track, deadline countdown wording, legal date and confidence formats, and the AI mark.",
  "dependencies": [],
  "registryDependencies": [
    "https://eased.dev/r/eased-tokens.json",
    "https://eased.dev/r/eased-doc-core.json"
  ],
  "files": [
    {
      "path": "src/registry/eased/_primitives/legal-core/legal-core.tsx",
      "content": "\"use client\";\n\n/**\n * legal-core: the pieces every Eased legal block shares, so a review, a version compare and an\n * obligations list read as one product: the inline redline, the clause label, the AI mark,\n * deadline wording and the legal date formats. Import from here.\n */\nimport type { ReactNode } from \"react\";\nimport type { RedlineSegment } from \"../doc-core/doc-core\";\n\n/** Default locale for every legal format. Pass your own. */\nexport const LEGAL_LOCALE = \"en-US\";\n\n/* ---------- Formats ---------------------------------------------------------------------- */\n\nconst DAY = 86_400_000;\nconst HOUR = 3_600_000;\n\n/** `Oct 27`, or `Oct 27, 2027` outside the current year. UTC unless you pass a zone. */\nexport function formatLegalDate(t: number, { now, locale = LEGAL_LOCALE, timeZone = \"UTC\" }: { now?: number; locale?: Intl.LocalesArgument; timeZone?: string } = {}) {\n  const sameYear = now === undefined || new Date(now).getUTCFullYear() === new Date(t).getUTCFullYear();\n  return new Intl.DateTimeFormat(locale, { month: \"short\", day: \"numeric\", year: sameYear ? undefined : \"numeric\", timeZone }).format(t);\n}\n\nexport type Countdown = {\n  /** Short, for a ring or a chip: `9d`, `22h`, `45m`, `2d` (overdue). */\n  short: string;\n  /** Spoken and for tooltips: \"Due in 9 days\", \"Due in 22 hours\", \"Overdue by 2 days\". */\n  long: string;\n  overdue: boolean;\n  /** Milliseconds until due (negative once overdue). */\n  remaining: number;\n};\n\n/** How far off a deadline is, in the largest whole unit that reads at a glance. */\nexport function countdown(due: number, now: number, locale: Intl.LocalesArgument = LEGAL_LOCALE): Countdown {\n  const remaining = due - now;\n  const abs = Math.abs(remaining);\n  // Days from a day and a half, hours under that. Time left counts down in whole units (10.8\n  // days left is \"10d\"); time overdue rounds, so 45 hours late reads \"2 days\".\n  const days = remaining < 0 ? Math.round(abs / DAY) : Math.floor(abs / DAY);\n  const [n, unit, letter] = abs >= 1.5 * DAY ? [days, \"day\", \"d\"] : abs >= HOUR ? [Math.floor(abs / HOUR), \"hour\", \"h\"] : [Math.max(1, Math.floor(abs / 60_000)), \"minute\", \"m\"];\n  const count = new Intl.NumberFormat(locale, { style: \"unit\", unit: unit as \"day\", unitDisplay: \"long\" }).format(n);\n  const overdue = remaining < 0;\n  return { short: `${n}${letter}`, long: overdue ? `Overdue by ${count}` : `Due in ${count}`, overdue, remaining };\n}\n\n/** `93%` for a model confidence. */\nexport const formatConfidence = (v: number, locale: Intl.LocalesArgument = LEGAL_LOCALE) => new Intl.NumberFormat(locale, { style: \"percent\", maximumFractionDigits: 0 }).format(v);\n\n/* ---------- Clause label ----------------------------------------------------------------- */\n\n/**\n * The clause number in a fixed track and its caption, for any row that cites a clause:\n * `4  Limitation of liability`. Put it in a `grid-cols-[2rem_minmax(0,1fr)]` row (or use\n * `CLAUSE_GRID`) so every number and every caption share one edge (rule 101).\n */\nexport const CLAUSE_GRID = \"grid grid-cols-[2rem_minmax(0,1fr)]\";\n\nexport function ClauseLabel({ number, title, className = \"\" }: { number?: string; title?: ReactNode; className?: string }) {\n  return (\n    <>\n      <span className={`text-ui-sm text-text-muted tabular-nums ${className}`}>{number}</span>\n      <span className={`min-w-0 truncate text-ui-sm font-medium text-text ${className}`}>{title}</span>\n    </>\n  );\n}\n\n/* ---------- Redline ---------------------------------------------------------------------- */\n\nconst count = (s: string, c: string) => s.split(c).length - 1;\n\n/**\n * Word diffs split \"thirty (30)\" → \"forty-five (45)\" around the bracket they share, leaving\n * \"thirty (30\" struck and \")\" plain. This moves a closing bracket that an edit opened back into\n * the edit (both sides), so each side reads as a whole phrase. Pure; safe in render.\n */\nexport function tidyRedline(segments: readonly RedlineSegment[]): RedlineSegment[] {\n  const out = segments.map((s) => ({ ...s }));\n  for (let i = 0; i < out.length; i++) {\n    const s = out[i];\n    if (s.kind === \"equal\" || !s.changeId) continue;\n    let j = i;\n    while (j + 1 < out.length && out[j + 1].kind !== \"equal\" && out[j + 1].changeId === s.changeId) j++;\n    const next = out[j + 1];\n    const m = next && /^[)\\]]/.exec(next.text);\n    const group = out.slice(i, j + 1);\n    if (m && group.every((g) => count(g.text, \"(\") + count(g.text, \"[\") > count(g.text, \")\") + count(g.text, \"]\"))) {\n      for (const g of group) g.text += m[0];\n      next.text = next.text.slice(1);\n    }\n    i = j;\n  }\n  return out.filter((s) => s.text);\n}\n\nexport type RedlineTextProps = {\n  segments: readonly RedlineSegment[];\n  /** Show only one side: `before` hides inserts, `after` hides deletes. Default both (a redline). */\n  side?: \"both\" | \"before\" | \"after\";\n  /** Change ids that are being rejected right now: their inserts strike through and dim. */\n  striking?: ReadonlySet<string>;\n  className?: string;\n};\n\n/**\n * A lawyer's inline redline: inserted words in success ink with an underline, deleted words\n * struck in danger ink, the rest as written. Inserts and deletes are real `<ins>`/`<del>`, so\n * screen readers and copy-paste keep the meaning. Colours change on a 150ms tween, so a\n * strike that lands mid-swap stays smooth.\n */\nexport function RedlineText({ segments, side = \"both\", striking, className = \"\" }: RedlineTextProps) {\n  return (\n    <span className={className}>\n      {segments.map((s, i) => {\n        if (s.kind === \"equal\") return <span key={i}>{s.text}</span>;\n        if (s.kind === \"insert\") {\n          if (side === \"before\") return null;\n          const struck = s.changeId && striking?.has(s.changeId);\n          // A replacement's insert sits right after its delete: keep a hair of space between them.\n          const afterDelete = side === \"both\" && segments[i - 1]?.kind === \"delete\";\n          return (\n            <ins\n              key={i}\n              className={`rounded-control-2xs no-underline transition-[color,background-color,text-decoration-color,opacity] duration-150 ease-standard ${\n                side === \"after\" ? \"bg-success-subtle text-success-text\" : \"underline decoration-success-text/40 decoration-1 underline-offset-[3px] text-success-text\"\n              } ${afterDelete ? \"ms-[0.3em]\" : \"\"} ${struck ? \"line-through decoration-danger-text opacity-60\" : \"\"}`}\n            >\n              {s.text}\n            </ins>\n          );\n        }\n        if (side === \"after\") return null;\n        return (\n          <del\n            key={i}\n            className={`rounded-control-2xs transition-colors duration-150 ease-standard ${side === \"before\" ? \"bg-danger-subtle text-danger-text no-underline\" : \"text-danger-text line-through decoration-danger-text/60\"}`}\n          >\n            {s.text}\n          </del>\n        );\n      })}\n    </span>\n  );\n}\n\n/* ---------- Icons ------------------------------------------------------------------------ */\n\n/** The Brief AI mark: a four-point spark. 16px grid, 1.5px stroke. */\nexport function SparkIcon({ className = \"size-4\" }: { className?: string }) {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.5} strokeLinejoin=\"round\" aria-hidden className={`shrink-0 ${className}`}>\n      <path d=\"M8 2.5c.4 2.9 2.1 4.6 5 5-2.9.4-4.6 2.1-5 5-.4-2.9-2.1-4.6-5-5 2.9-.4 4.6-2.1 5-5Z\" />\n    </svg>\n  );\n}\n\nexport function CheckIcon({ className = \"size-4\" }: { className?: string }) {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.5} strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden className={`shrink-0 ${className}`}>\n      <path d=\"M3.5 8.5l3 3 6-7\" />\n    </svg>\n  );\n}\n\nexport function ChevronIcon({ dir, className = \"size-4\" }: { dir: \"up\" | \"down\" | \"left\" | \"right\"; className?: string }) {\n  const d = { up: \"M4 10l4-4 4 4\", down: \"M4 6.5l4 4 4-4\", left: \"M10 4 6 8l4 4\", right: \"M6 4l4 4-4 4\" }[dir];\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.5} strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden className={`shrink-0 ${className}`}>\n      <path d={d} />\n    </svg>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/eased/_primitives/legal-core/legal-core.tsx"
    }
  ],
  "type": "registry:ui"
}