{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "share-card",
  "type": "registry:ui",
  "title": "Share Card",
  "description": "How the player did today, ready to share without spoiling it: one mark per round (a band, never the answer), the score and the streak, with a Share button that opens the device's share sheet and a Copy button that puts the same text on the clipboard. The…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "games",
    "game"
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/button.json",
    "https://ds.interlace.tools/r/cn.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/games/share-card.tsx",
      "target": "components/ui/games/share-card.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/share-card v1.2.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/share-card\n// What changed since: https://ds.interlace.tools/c/share-card#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — ShareCard\n *\n * How the player did today, ready to share without spoiling it: one mark per\n * round (a band, never the answer), the score and the streak, with a Share\n * button that opens the device's share sheet and a Copy button that puts the\n * same text on the clipboard. The text comes from `shareText` in\n * `share-model.ts`, so a server can build the same line for a link preview.\n *\n * ## Anatomy\n *\n *   ShareCard                      (div — data-slot=\"share-card\")\n *     ├─ p                         (data-slot=\"share-card-title\": name and number)\n *     ├─ p                         (data-slot=\"share-card-marks\": the marks, hidden from AT; a sentence beside them)\n *     ├─ p                         (data-slot=\"share-card-note\": one line of news, with `note`)\n *     ├─ p                         (data-slot=\"share-card-score\")\n *     ├─ div                       (data-slot=\"share-card-actions\": Share, Copy)\n *     └─ p aria-live=\"polite\"      (data-slot=\"share-card-status\": \"Copied.\")\n *\n * ## Marks and assistive tech\n *\n * A row of emoji reads as \"green square, yellow square, direct hit\". The\n * marks are `aria-hidden`, and a sentence (\"Round 1: close. Round 2: near.\")\n * carries the same thing in words, from `bandLabels`.\n *\n * ## Share, then copy\n *\n * Share shows only where `navigator.share` exists (most phones). Copy is\n * always there; without clipboard access it selects a read-only field\n * holding the text so the player can copy it by hand.\n *\n * ## MIN_VIEWPORT — 320\n *\n * | Rule | Concept                   | Where in this file                              |\n * | ---- | ------------------------- | ----------------------------------------------- |\n * | R4   | Extends native el         | `React.ComponentProps<'div'>`                   |\n * | R6   | data-slot per part        | share-card / -title / -marks / -note / -score / -actions / -status |\n * | R7   | cn + ...rest              | `cn(…, className)` + `{...props}`               |\n * | R14  | Declares min viewport     | `data-min-viewport` + exported const            |\n * | R19  | Tokens only               | card, border, muted-foreground                  |\n * | R26  | A11y                      | marks in words; live status; real buttons       |\n */\n\nimport { Copy, Share2 } from 'lucide-react';\n\nimport { cn } from '@/lib/utils';\nimport { Button } from '@/components/ui/button';\nimport { DEFAULT_SYMBOLS, shareMarks, shareText, type ShareTextInput } from '@/components/ui/games/share-model';\n\nexport const MIN_VIEWPORT = 320 as const;\n\nconst BAND_LABELS: Record<string, string> = {\n  exact: 'spot on',\n  close: 'close',\n  near: 'not far',\n  far: 'far off',\n  right: 'right',\n  wrong: 'wrong',\n};\n\ninterface ShareCardLabels {\n  share?: string;\n  copy?: string;\n  copied?: string;\n  /** When the clipboard is not available. @default 'Select the text and copy it.' */\n  copyFallback?: string;\n  /** @default (i, band) => `Round ${i}: ${band}.` */\n  round?: (index: number, band: string) => string;\n  /** @default (score, max) => `${score} of ${max} points` */\n  score?: (score: string, max?: string) => string;\n  /** @default n => `${n}-day streak` */\n  streak?: (n: string) => string;\n}\n\ntype ShareCardProps = Omit<React.ComponentProps<'div'>, 'title' | 'results'> &\n  ShareTextInput & {\n    /** Words for each result key, read in place of the marks. */\n    bandLabels?: Readonly<Record<string, string>>;\n    /** Called after a share or a copy, with how it went. */\n    onShare?: (method: 'share' | 'copy' | 'manual') => void;\n    locale?: string;\n    labels?: ShareCardLabels;\n  };\n\nfunction ShareCard({\n  title,\n  number,\n  results,\n  score,\n  maxScore,\n  note,\n  streak,\n  url,\n  symbols = DEFAULT_SYMBOLS,\n  fallback,\n  numberLabel,\n  streakSymbol,\n  bandLabels,\n  onShare,\n  locale,\n  labels,\n  className,\n  ...props\n}: ShareCardProps) {\n  const [status, setStatus] = React.useState('');\n  const [manual, setManual] = React.useState(false);\n  const [canShare, setCanShare] = React.useState(false);\n  const fieldRef = React.useRef<HTMLTextAreaElement>(null);\n  const text = shareText({ title, number, results, score, maxScore, note, streak, url, symbols, fallback, numberLabel, streakSymbol });\n  const nf = new Intl.NumberFormat(locale);\n\n  React.useEffect(() => {\n    setCanShare(typeof navigator !== 'undefined' && typeof navigator.share === 'function');\n  }, []);\n  React.useEffect(() => {\n    if (manual) fieldRef.current?.select();\n  }, [manual]);\n\n  // A live region speaks only when its text changes, so clear it first and\n  // set the message a moment later: a second copy is announced again.\n  const announceTimer = React.useRef<ReturnType<typeof setTimeout>>(undefined);\n  React.useEffect(() => () => clearTimeout(announceTimer.current), []);\n  const announce = (message: string) => {\n    setStatus('');\n    clearTimeout(announceTimer.current);\n    announceTimer.current = setTimeout(() => setStatus(message), 50);\n  };\n\n  const copy = async () => {\n    try {\n      await navigator.clipboard.writeText(text);\n      setManual(false);\n      announce(labels?.copied ?? 'Copied.');\n      onShare?.('copy');\n    } catch {\n      setManual(true);\n      announce(labels?.copyFallback ?? 'Select the text and copy it.');\n      onShare?.('manual');\n    }\n  };\n\n  const share = async () => {\n    try {\n      await navigator.share({ text });\n      onShare?.('share');\n    } catch (error) {\n      // The player closed the sheet: nothing to say. Anything else: copy instead.\n      if ((error as Error)?.name !== 'AbortError') await copy();\n    }\n  };\n\n  const words = { ...BAND_LABELS, ...bandLabels };\n  const roundWord = labels?.round ?? ((i: number, band: string) => `Round ${i}: ${band}.`);\n  const sentence = results.map((r, i) => roundWord(i + 1, words[r] ?? r)).join(' ');\n  const head = number === undefined ? title : `${title} ${(numberLabel ?? ((n: number) => `No. ${n}`))(number)}`;\n  const scoreText =\n    score === undefined\n      ? null\n      : (labels?.score ?? ((s: string, m?: string) => (m ? `${s} of ${m} points` : `${s} points`)))(\n          nf.format(score),\n          maxScore === undefined ? undefined : nf.format(maxScore),\n        );\n\n  return (\n    <div\n      data-slot=\"share-card\"\n      data-min-viewport={String(MIN_VIEWPORT)}\n      className={cn('border-border bg-card text-card-foreground grid gap-3 rounded-xl border p-5', className)}\n      {...props}\n    >\n      <p data-slot=\"share-card-title\" className=\"font-heading font-semibold\">\n        {head}\n      </p>\n      {results.length ? (\n        <p data-slot=\"share-card-marks\" className=\"text-2xl leading-none tracking-[0.2em]\">\n          <span aria-hidden>{shareMarks(results, symbols, fallback)}</span>\n          <span className=\"sr-only\">{sentence}</span>\n        </p>\n      ) : null}\n      {note ? (\n        <p data-slot=\"share-card-note\" className=\"font-medium\">\n          {note}\n        </p>\n      ) : null}\n      {scoreText || streak ? (\n        <p data-slot=\"share-card-score\" className=\"text-muted-foreground text-sm tabular-nums\">\n          {scoreText}\n          {scoreText && streak ? <span aria-hidden> · </span> : null}\n          {streak ? (labels?.streak ?? ((n: string) => `${n}-day streak`))(nf.format(streak)) : null}\n        </p>\n      ) : null}\n      <div data-slot=\"share-card-actions\" className=\"flex flex-wrap gap-2\">\n        {canShare ? (\n          <Button type=\"button\" onClick={share}>\n            <Share2 aria-hidden />\n            {labels?.share ?? 'Share'}\n          </Button>\n        ) : null}\n        <Button type=\"button\" variant={canShare ? 'outline' : 'default'} onClick={copy}>\n          <Copy aria-hidden />\n          {labels?.copy ?? 'Copy result'}\n        </Button>\n      </div>\n      {manual ? (\n        <textarea\n          ref={fieldRef}\n          readOnly\n          data-slot=\"share-card-text\"\n          aria-label={labels?.copy ?? 'Copy result'}\n          rows={text.split('\\n').length}\n          value={text}\n          className=\"border-input bg-background w-full resize-none rounded-md border p-2 font-mono text-sm\"\n        />\n      ) : null}\n      <p data-slot=\"share-card-status\" aria-live=\"polite\" className=\"text-sm font-medium empty:hidden\">\n        {status}\n      </p>\n    </div>\n  );\n}\nShareCard.displayName = 'ShareCard';\n\nexport { ShareCard };\nexport type { ShareCardProps, ShareCardLabels };\n"
    },
    {
      "path": "registry/interlace-ui/games/share-model.ts",
      "target": "components/ui/games/share-model.ts",
      "type": "registry:ui",
      "content": "export const DEFAULT_SYMBOLS: Readonly<Record<string, string>> = {\n  exact: '🎯',\n  close: '🟩',\n  near: '🟨',\n  far: '⬜',\n  right: '🟩',\n  wrong: '⬜',\n};\n\nexport interface ShareTextInput {\n  /** The game's name. */\n  title: string;\n  /** Today's puzzle number. */\n  number?: number;\n  /** One key per round, in order (`'close'`, `'right'`, …). */\n  results: readonly string[];\n  /** Points scored, and out of how many. */\n  score?: number;\n  maxScore?: number;\n  /** One line of news after the marks, for a milestone (\"7-day streak\", \"Level 5\"). */\n  note?: string;\n  /** Current streak; left out when 0 or missing. */\n  streak?: number;\n  url?: string;\n  symbols?: Readonly<Record<string, string>>;\n  /** For an unknown key. @default '⬜' */\n  fallback?: string;\n  /** @default n => `No. ${n}` */\n  numberLabel?: (n: number) => string;\n  /** @default '🔥' */\n  streakSymbol?: string;\n}\n\n/** The marks for a run of results, one character per round. */\nexport function shareMarks(\n  results: readonly string[],\n  symbols: Readonly<Record<string, string>> = DEFAULT_SYMBOLS,\n  fallback = '⬜',\n): string {\n  return results.map((r) => symbols[r] ?? fallback).join('');\n}\n\n/** The full share text, one fact per line. */\nexport function shareText(input: ShareTextInput): string {\n  const head =\n    input.number === undefined\n      ? input.title\n      : `${input.title} ${(input.numberLabel ?? ((n: number) => `No. ${n}`))(input.number)}`;\n  const marks = shareMarks(input.results, input.symbols, input.fallback);\n  const score =\n    input.score === undefined ? '' : input.maxScore === undefined ? ` ${input.score}` : ` ${input.score}/${input.maxScore}`;\n  const lines = [head, `${marks}${score}`.trimStart()];\n  if (input.note) lines.push(input.note);\n  if (input.streak) lines.push(`${input.streakSymbol ?? '🔥'} ${input.streak}`);\n  if (input.url) lines.push(input.url);\n  return lines.join('\\n');\n}\n\n/**\n * @interlace/ui — games/share-model\n *\n * The text a player shares after a daily game: how they did, without the\n * answers. One mark per round (a band, not a number), the score, the streak\n * and a link. Pure, so the same text can be built on a server for an\n * Open Graph card.\n *\n *   Sample game No. 42\n *   🟩🟨🎯 240/300\n *   🔥 6\n *   https://example.com/play\n *\n * `note` adds one line of news (\"7-day streak\") after the marks; a share\n * with no rounds (a milestone) keeps an empty marks line, so the news\n * stands apart from the title.\n *\n * ## Marks\n *\n * `symbols` maps each result key to the character that stands for it. The\n * defaults cover the Closer bands (`exact`, `close`, `near`, `far`) and\n * plain `right` / `wrong`; a game with its own keys passes its own map. An\n * unknown key falls back to `fallback` (a white square), so a typo never\n * prints the word.\n */\n"
    }
  ],
  "meta": {
    "tier": "game",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.2.0",
    "since": "2.0.0"
  },
  "docs": "## @interlace/share-card\n\nInstalled to `components/ui/games/share-card.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/games/share-card';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/share-card\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
