{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "picture-reveal",
  "type": "registry:ui",
  "title": "Picture Reveal",
  "description": "A picture under tiles that come away a few at a time while the room guesses. The presenter moves `step`; every screen uncovers the same tiles in the same seeded order, spread across the picture. Phones guess with `TypeAnswer` (or `QuizQuestion`), and…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "games",
    "game"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/games/picture-reveal.tsx",
      "target": "components/ui/games/picture-reveal.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/picture-reveal v1.1.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/picture-reveal\n// What changed since: https://ds.interlace.tools/c/picture-reveal#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — PictureReveal\n *\n * A picture under tiles that come away a few at a time while the room\n * guesses. The presenter moves `step`; every screen uncovers the same tiles\n * in the same seeded order, spread across the picture. Phones guess with\n * `TypeAnswer` (or `QuizQuestion`), and `guessPoints` pays an early right\n * guess more.\n *\n * A picture cannot be guessed by someone who cannot see it, so the round\n * carries `clues`: one line of text per step, shown and announced as the\n * tiles come off, so a screen reader user plays the same round. The image\n * has no text alternative until the reveal, when it gets `alt` and the\n * answer is said.\n *\n * ## Anatomy\n *\n *   PictureReveal                  (figure — data-slot=\"picture-reveal\", data-state=hidden|revealing|revealed)\n *     ├─ div                       (data-slot=\"picture-reveal-frame\": the picture and its tiles)\n *     │   ├─ img                   (alt only once revealed)\n *     │   └─ div aria-hidden       (data-slot=\"picture-reveal-tiles\": span × cols·rows, data-off)\n *     ├─ ol                        (data-slot=\"picture-reveal-clues\": the clues so far)\n *     ├─ span sr-only aria-live    (data-slot=\"picture-reveal-status\": \"6 of 16 tiles off. Clue: …\")\n *     └─ figcaption                (data-slot=\"picture-reveal-answer\": on the reveal)\n *\n * ## Motion\n *\n * Tiles that come off together fade and shrink away (`--duration-base`), staggered over\n * 150ms in all, so the eye sees where the picture opened. On the reveal the\n * rest go at once. Under reduced motion they are simply gone.\n *\n * ## MIN_VIEWPORT — 320\n *\n * | Rule | Concept                   | Where in this file                                  |\n * | ---- | ------------------------- | --------------------------------------------------- |\n * | R4   | Extends native el         | `figure` props                                      |\n * | R6   | data-slot per part        | picture-reveal / -frame / -tiles / -clues / -status / -answer |\n * | R7   | cn + ...rest              | `cn(…, className)` + `{...props}`                   |\n * | R8   | Enums, not booleans       | `size`                                              |\n * | R14  | Declares min viewport     | `data-min-viewport` + exported const                |\n * | R26  | A11y                      | clues in step with the tiles; no alt until the reveal; status announced |\n */\n\nimport { cn } from '@/lib/utils';\nimport { revealOrder, tilesAt } from '@/components/ui/games/picture-reveal-model';\n\nexport const MIN_VIEWPORT = 320 as const;\n\ninterface PictureRevealLabels {\n  /** Announced as tiles come off. @default (off, total) => `${off} of ${total} tiles off.` */\n  status?: (off: number, total: number) => string;\n  /** Before a clue in the announcement. @default 'Clue:' */\n  clue?: string;\n  /** Names the clue list. @default 'Clues' */\n  clues?: string;\n  /** Announced on the reveal, before the answer. @default 'The answer:' */\n  answer?: string;\n}\n\ntype PictureRevealProps = Omit<React.ComponentProps<'figure'>, 'children'> & {\n  src: string;\n  /** The picture in words, given to the image only on the reveal. */\n  alt: string;\n  /** The answer, shown under the picture on the reveal. @default alt */\n  answer?: React.ReactNode;\n  /** How far along the round is, 0 to `steps`. */\n  step: number;\n  /** @default 8 */\n  steps?: number;\n  /** Show everything: the picture, its alt, the answer. */\n  revealed?: boolean;\n  /** @default 4 */\n  cols?: number;\n  /** @default 3 */\n  rows?: number;\n  /** Seeds the order the tiles come off. Use the round's id. */\n  seed: number | string;\n  /** One line of text per step, for everyone, and the only way to play without sight. */\n  clues?: readonly string[];\n  /** `stage` for a shared screen. @default 'default' */\n  size?: 'default' | 'stage';\n  labels?: PictureRevealLabels;\n};\n\nfunction PictureReveal({\n  src,\n  alt,\n  answer,\n  step,\n  steps = 8,\n  revealed = false,\n  cols = 4,\n  rows = 3,\n  seed,\n  clues = [],\n  size = 'default',\n  labels,\n  className,\n  ...props\n}: PictureRevealProps) {\n  const c = Math.max(1, Math.floor(cols));\n  const r = Math.max(1, Math.floor(rows));\n  const total = c * r;\n  const order = React.useMemo(() => revealOrder(total, seed), [total, seed]);\n  const off = revealed ? total : tilesAt(step, steps, total);\n  const rank = React.useMemo(() => {\n    const m: number[] = Array.from({ length: total }, () => 0);\n    order.forEach((tile, i) => {\n      m[tile] = i;\n    });\n    return m;\n  }, [order, total]);\n  const shownClues = revealed ? clues : clues.slice(0, Math.min(clues.length, Math.max(0, Math.floor(step))));\n  const prevOff = React.useRef(off);\n  const before = prevOff.current;\n  React.useEffect(() => {\n    prevOff.current = off;\n  }, [off]);\n  const stage = size === 'stage';\n  const lastClue = shownClues.at(-1);\n  const status = revealed\n    ? `${labels?.answer ?? 'The answer:'} ${alt}`\n    : off === 0 && shownClues.length === 0\n      ? ''\n      : `${(labels?.status ?? ((o: number, t: number) => `${o} of ${t} tiles off.`))(off, total)}${lastClue ? ` ${labels?.clue ?? 'Clue:'} ${lastClue}` : ''}`;\n\n  return (\n    <figure\n      data-slot=\"picture-reveal\"\n      data-state={revealed ? 'revealed' : off === 0 ? 'hidden' : 'revealing'}\n      data-min-viewport={String(MIN_VIEWPORT)}\n      className={cn('grid gap-3', className)}\n      {...props}\n    >\n      <div\n        data-slot=\"picture-reveal-frame\"\n        className=\"bg-muted relative w-full overflow-hidden rounded-xl border\"\n        style={{ aspectRatio: `${c} / ${r}` }}\n      >\n        <img\n          src={src}\n          alt={revealed ? alt : ''}\n          aria-hidden={revealed ? undefined : true}\n          draggable={false}\n          className=\"absolute inset-0 size-full object-cover select-none\"\n        />\n        <div\n          aria-hidden\n          data-slot=\"picture-reveal-tiles\"\n          className=\"absolute inset-0 grid\"\n          style={{ gridTemplateColumns: `repeat(${c}, 1fr)`, gridTemplateRows: `repeat(${r}, 1fr)` }}\n        >\n          {Array.from({ length: total }, (_, tile) => {\n            const k = rank[tile] as number;\n            const gone = k < off;\n            // Tiles leaving in this step share a 150ms stagger, in their reveal order.\n            const leaving = gone && k >= before ? k - before : 0;\n            const batch = Math.max(1, off - before);\n            return (\n              <span\n                // Tiles are fixed places on the picture: the index is their identity.\n                key={`tile-${tile}`}\n                data-off={gone ? '' : undefined}\n                className={cn(\n                  'bg-card text-muted-foreground border-background grid place-items-center border-2 font-semibold',\n                  stage ? 'text-3xl' : 'text-xl',\n                  'motion-safe:transition-[opacity,transform] motion-safe:duration-(--duration-base) motion-safe:ease-exit',\n                  gone && 'scale-90 opacity-0',\n                )}\n                style={\n                  gone && !revealed && batch > 1\n                    ? { transitionDelay: `${Math.round((leaving / batch) * 150)}ms` }\n                    : undefined\n                }\n              >\n                ?\n              </span>\n            );\n          })}\n        </div>\n      </div>\n      {clues.length > 0 ? (\n        <ol\n          data-slot=\"picture-reveal-clues\"\n          aria-label={labels?.clues ?? 'Clues'}\n          className={cn('grid gap-1 empty:hidden', stage ? 'text-lg' : 'text-sm')}\n        >\n          {shownClues.map((clue, i) => (\n            <li\n              // Clues come in a fixed order; the position is their identity.\n              key={`clue-${i}`}\n              className=\"text-muted-foreground flex gap-2\"\n            >\n              <span aria-hidden className=\"text-foreground font-semibold tabular-nums\">\n                {i + 1}.\n              </span>\n              <span>{clue}</span>\n            </li>\n          ))}\n        </ol>\n      ) : null}\n      <span data-slot=\"picture-reveal-status\" aria-live=\"polite\" className=\"sr-only\">\n        {status}\n      </span>\n      {revealed ? (\n        <figcaption\n          data-slot=\"picture-reveal-answer\"\n          className={cn('font-heading font-semibold text-balance', stage ? 'text-section' : 'text-xl')}\n        >\n          {answer ?? alt}\n        </figcaption>\n      ) : null}\n    </figure>\n  );\n}\nPictureReveal.displayName = 'PictureReveal';\n\nexport { PictureReveal };\nexport type { PictureRevealProps, PictureRevealLabels };\n"
    },
    {
      "path": "registry/interlace-ui/games/daily.ts",
      "target": "components/ui/games/daily.ts",
      "type": "registry:ui",
      "content": "export type DayKey = string;\n\nconst DAY_MS = 86_400_000;\nconst KEY_RE = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\n\n/**\n * The calendar day `date` falls on in `timeZone` (an IANA name such as\n * `\"Europe/Paris\"`). Without a time zone, the runtime's own is used, which on\n * a server is usually UTC: pass the player's zone when the page renders on\n * one.\n */\nexport function dayKey(date: Date | number = Date.now(), timeZone?: string): DayKey {\n  const parts = new Intl.DateTimeFormat('en-US', {\n    timeZone,\n    year: 'numeric',\n    month: '2-digit',\n    day: '2-digit',\n  }).formatToParts(typeof date === 'number' ? new Date(date) : date);\n  const part = Object.fromEntries(parts.map((p) => [p.type, p.value]));\n  return `${part.year}-${part.month}-${part.day}`;\n}\n\n/** True when `value` is a well-formed day key for a real date. */\nexport function isDayKey(value: unknown): value is DayKey {\n  if (typeof value !== 'string') return false;\n  const m = KEY_RE.exec(value);\n  if (!m) return false;\n  const d = new Date(Date.UTC(+m[1], +m[2] - 1, +m[3]));\n  return d.getUTCFullYear() === +m[1] && d.getUTCMonth() === +m[2] - 1 && d.getUTCDate() === +m[3];\n}\n\nfunction toUtc(key: DayKey): number {\n  const m = KEY_RE.exec(key);\n  if (!m) throw new RangeError(`Not a day key: \"${key}\" (expected YYYY-MM-DD)`);\n  return Date.UTC(+m[1], +m[2] - 1, +m[3]);\n}\n\n/** Midnight UTC of the day, as a Date: the safe way to format a key with Intl. */\nexport function dayKeyToDate(key: DayKey): Date {\n  return new Date(toUtc(key));\n}\n\n/** The key `days` after `key` (negative goes back). */\nexport function addDays(key: DayKey, days: number): DayKey {\n  return new Date(toUtc(key) + days * DAY_MS).toISOString().slice(0, 10);\n}\n\n/** Whole days from `from` to `to`; negative when `to` is earlier. */\nexport function daysBetween(from: DayKey, to: DayKey): number {\n  return Math.round((toUtc(to) - toUtc(from)) / DAY_MS);\n}\n\n/** Day of the week, 0 for Sunday to 6 for Saturday, as `Date.getDay` counts. */\nexport function weekdayOf(key: DayKey): number {\n  return new Date(toUtc(key)).getUTCDay();\n}\n\n/**\n * The puzzle's number: 1 on `firstDay`, 2 the day after. Before `firstDay`\n * it is 0 or less, which a caller should treat as \"not started\".\n */\nexport function puzzleNumber(key: DayKey, firstDay: DayKey): number {\n  return daysBetween(firstDay, key) + 1;\n}\n\n/** FNV-1a, 32-bit: a small, stable string hash for seeds. */\nexport function hashString(value: string): number {\n  let h = 0x811c9dc5;\n  for (let i = 0; i < value.length; i++) {\n    h ^= value.charCodeAt(i);\n    h = Math.imul(h, 0x01000193);\n  }\n  return h >>> 0;\n}\n\n/**\n * A seeded generator of numbers in [0, 1) (mulberry32). Good enough to deal\n * puzzles and shuffle answers the same way everywhere; not for anything\n * secret.\n */\nexport function seededRandom(seed: number | string): () => number {\n  let a = typeof seed === 'string' ? hashString(seed) : seed >>> 0;\n  return () => {\n    a = (a + 0x6d2b79f5) >>> 0;\n    let t = a;\n    t = Math.imul(t ^ (t >>> 15), t | 1);\n    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n    return ((t ^ (t >>> 14)) >>> 0) / 4_294_967_296;\n  };\n}\n\n/** A copy of `items` in a seeded order (Fisher–Yates). */\nexport function seededShuffle<T>(items: readonly T[], seed: number | string): T[] {\n  const out = items.slice();\n  const random = seededRandom(seed);\n  for (let i = out.length - 1; i > 0; i--) {\n    const j = Math.floor(random() * (i + 1));\n    [out[i], out[j]] = [out[j] as T, out[i] as T];\n  }\n  return out;\n}\n\nexport interface DailyIndexOptions {\n  /** The day puzzle 1 ran. */\n  firstDay: DayKey;\n  /** `sequence` walks the pool in order; `shuffle` deals it in a seeded order per cycle. @default 'sequence' */\n  order?: 'sequence' | 'shuffle';\n  /** Changes the shuffled order. @default 'daily' */\n  seed?: string;\n}\n\n/**\n * Which item of a pool of `size` the day gets, or -1 for an empty pool or a\n * day before `firstDay`.\n */\nexport function dailyIndex(key: DayKey, size: number, options: DailyIndexOptions): number {\n  const n = puzzleNumber(key, options.firstDay);\n  if (size <= 0 || n < 1) return -1;\n  const position = (n - 1) % size;\n  if ((options.order ?? 'sequence') === 'sequence') return position;\n  const cycle = Math.floor((n - 1) / size);\n  const order = seededShuffle(\n    Array.from({ length: size }, (_, i) => i),\n    `${options.seed ?? 'daily'}:${cycle}`,\n  );\n  return order[position] as number;\n}\n\n/** The day's item from `pool`, or undefined when there is none. */\nexport function dailyItem<T>(pool: readonly T[], key: DayKey, options: DailyIndexOptions): T | undefined {\n  const i = dailyIndex(key, pool.length, options);\n  return i < 0 ? undefined : pool[i];\n}\n\n/**\n * Milliseconds until the next day starts in `timeZone`. On a day that a\n * clock change makes 23 or 25 hours long the answer can be off by that hour,\n * which is fine for a countdown and is why it is not used to pick puzzles.\n */\nexport function msUntilNextDay(now: Date | number = Date.now(), timeZone?: string): number {\n  const date = typeof now === 'number' ? new Date(now) : now;\n  const parts = new Intl.DateTimeFormat('en-US', {\n    timeZone,\n    hour: '2-digit',\n    minute: '2-digit',\n    second: '2-digit',\n    hourCycle: 'h23',\n  }).formatToParts(date);\n  const part = Object.fromEntries(parts.map((p) => [p.type, Number(p.value)]));\n  const elapsed =\n    ((part.hour! * 60 + part.minute!) * 60 + part.second!) * 1000 + date.getMilliseconds();\n  return DAY_MS - elapsed;\n}\n\n/**\n * @interlace/ui — games/daily\n *\n * The calendar under a daily game: which day it is for a player, which\n * puzzle that day gets, its number, and how long until the next one. Pure\n * functions, no React, no storage. Every component in `games/` builds on\n * these, and a server can call them too, so the puzzle a page renders and\n * the one a score is checked against come from the same arithmetic.\n *\n * ## Day keys\n *\n * A day is an ISO date string, `\"2026-11-24\"`, read in a time zone. Keys\n * sort as strings, survive JSON and storage unchanged, and compare without\n * a Date. Arithmetic on them runs in UTC, where every day has 24 hours, so\n * daylight-saving changes never skip or repeat a day.\n *\n * ## The puzzle of the day\n *\n * `dailyIndex` maps a day to an item in a pool. `order: 'sequence'` walks\n * the pool in order and starts again at the end. `order: 'shuffle'` deals\n * the pool in a seeded order that changes every cycle, and never repeats an\n * item inside a cycle. Both are deterministic: the same day, pool size and\n * seed give the same item on every device.\n */\n\n/** An ISO calendar date, `YYYY-MM-DD`. */\n"
    },
    {
      "path": "registry/interlace-ui/games/picture-reveal-model.ts",
      "target": "components/ui/games/picture-reveal-model.ts",
      "type": "registry:ui",
      "content": "import { seededShuffle } from '@/components/ui/games/daily';\n\n/**\n * @interlace/ui — picture-reveal-model\n *\n * A picture hidden under tiles that come away a few at a time while the\n * room guesses. The order is seeded, so every screen (and a recap) uncovers\n * the same tiles in the same order, and it is spread out: a few tiles from\n * all over the picture say more, sooner, than a corner.\n *\n * `revealOrder` gives the tiles' order. `tilesAt` says how many are off\n * after a step, spread evenly so the last step shows the whole picture.\n * `guessPoints` pays an earlier right guess more: full points before any\n * tile is off, down to `floor` of them at the last step.\n */\n\n/** Every tile index, in the order the tiles come off. */\nexport function revealOrder(tiles: number, seed: number | string): number[] {\n  const n = Math.max(0, Math.floor(tiles));\n  return seededShuffle(\n    Array.from({ length: n }, (_, i) => i),\n    seed,\n  );\n}\n\n/** Tiles off after `step` of `steps` (0 shows none; `steps` shows all). */\nexport function tilesAt(step: number, steps: number, tiles: number): number {\n  const n = Math.max(0, Math.floor(tiles));\n  const s = Math.max(1, Math.floor(steps));\n  const k = Math.min(s, Math.max(0, Math.floor(step)));\n  return Math.round((k / s) * n);\n}\n\n/** Points for a right guess made at `step` of `steps`. */\nexport function guessPoints(step: number, steps: number, options: { max?: number; floor?: number } = {}): number {\n  const { max = 1000, floor = 0.2 } = options;\n  const s = Math.max(1, Math.floor(steps));\n  const k = Math.min(s, Math.max(0, step));\n  const share = 1 - (1 - Math.min(1, Math.max(0, floor))) * (k / s);\n  return Math.round(max * share);\n}\n"
    }
  ],
  "meta": {
    "tier": "game",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.1.0",
    "since": "2.0.0"
  },
  "docs": "## @interlace/picture-reveal\n\nInstalled to `components/ui/games/picture-reveal.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/games/picture-reveal';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/picture-reveal\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
