{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "reminder-offer",
  "type": "registry:ui",
  "title": "Reminder Offer",
  "description": "A quiet offer of a daily nudge that the player keeps in their own calendar: pick a time, add it, done. It downloads an .ics file with one event that repeats daily (`reminder-model.ts`), so nothing is sent, no address is asked for, and the player removes it…",
  "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/reminder-offer.tsx",
      "target": "components/ui/games/reminder-offer.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/reminder-offer v1.1.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/reminder-offer\n// What changed since: https://ds.interlace.tools/c/reminder-offer#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — ReminderOffer\n *\n * A quiet offer of a daily nudge that the player keeps in their own\n * calendar: pick a time, add it, done. It downloads an .ics file with one\n * event that repeats daily (`reminder-model.ts`), so nothing is sent, no\n * address is asked for, and the player removes it from their calendar\n * whenever they like. \"Not now\" dismisses it; the app decides whether it\n * ever comes back.\n *\n * ## Anatomy\n *\n *   ReminderOffer                  (section — data-slot=\"reminder-offer\", data-state=offer|added)\n *     ├─ h3                        (data-slot=\"reminder-offer-title\")\n *     ├─ p                         (data-slot=\"reminder-offer-body\")\n *     ├─ div                       (data-slot=\"reminder-offer-controls\")\n *     │   ├─ label + input[time]   (data-slot=\"reminder-offer-time\")\n *     │   ├─ button                (data-slot=\"reminder-offer-add\")\n *     │   └─ button                (data-slot=\"reminder-offer-dismiss\", with onDismiss)\n *     └─ p aria-live=\"polite\"      (data-slot=\"reminder-offer-status\")\n *\n * ## Gentle by design\n *\n * One offer, two plain choices, no badge, no countdown, no guilt. It does\n * not ask the browser for notification permission.\n *\n * ## MIN_VIEWPORT — 320\n *\n * Controls stack below a 24rem container.\n *\n * | Rule | Concept                   | Where in this file                                 |\n * | ---- | ------------------------- | -------------------------------------------------- |\n * | R4   | Extends native el         | `React.ComponentProps<'section'>`                  |\n * | R6   | data-slot per part        | reminder-offer / -title / -body / -controls / -time / -add / -dismiss / -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, input              |\n * | R25  | Client component          | builds and downloads the file                      |\n * | R26  | A11y                      | labelled time field; live status                   |\n */\n\nimport { BellRing } from 'lucide-react';\n\nimport { cn } from '@/lib/utils';\nimport { Button } from '@/components/ui/button';\nimport { dayKey } from '@/components/ui/games/daily';\nimport { isReminderTime, reminderIcs } from '@/components/ui/games/reminder-model';\n\nexport const MIN_VIEWPORT = 320 as const;\n\ninterface ReminderOfferLabels {\n  /** @default 'A nudge each day?' */\n  title?: string;\n  /** @default 'Add a daily reminder to your own calendar. Nothing is sent to us, and you can remove it there any time.' */\n  body?: string;\n  /** @default 'Time' */\n  time?: string;\n  /** @default 'Add to my calendar' */\n  add?: string;\n  /** @default 'Not now' */\n  dismiss?: string;\n  /** @default 'Added. Open the file to save it in your calendar.' */\n  added?: string;\n}\n\ntype ReminderOfferProps = Omit<React.ComponentProps<'section'>, 'title'> & {\n  /** The calendar event's title. */\n  event: string;\n  /** A line under the event's title. */\n  eventDescription?: string;\n  /** Opens from the event. */\n  url?: string;\n  /** Stable id, so adding again updates the same event. */\n  uid: string;\n  /** \"HH:MM\". @default '18:30' */\n  defaultTime?: string;\n  /** @default 'reminder.ics' */\n  fileName?: string;\n  /** Called with the time after the file is made. */\n  onAdd?: (time: string) => void;\n  /** Shows \"Not now\" and is called when pressed. */\n  onDismiss?: () => void;\n  labels?: ReminderOfferLabels;\n};\n\nfunction ReminderOffer({\n  event,\n  eventDescription,\n  url,\n  uid,\n  defaultTime = '18:30',\n  fileName = 'reminder.ics',\n  onAdd,\n  onDismiss,\n  labels,\n  className,\n  ...props\n}: ReminderOfferProps) {\n  const id = React.useId();\n  const [time, setTime] = React.useState(isReminderTime(defaultTime) ? defaultTime : '18:30');\n  const [added, setAdded] = React.useState(false);\n\n  const add = () => {\n    const chosen = isReminderTime(time) ? time : '18:30';\n    const ics = reminderIcs({ title: event, description: eventDescription, url, uid, time: chosen, start: dayKey() });\n    const href = URL.createObjectURL(new Blob([ics], { type: 'text/calendar;charset=utf-8' }));\n    const a = document.createElement('a');\n    a.href = href;\n    a.download = fileName;\n    document.body.append(a);\n    a.click();\n    a.remove();\n    setTimeout(() => URL.revokeObjectURL(href), 1000);\n    setAdded(true);\n    onAdd?.(chosen);\n  };\n\n  return (\n    <section\n      aria-labelledby={`${id}-title`}\n      data-slot=\"reminder-offer\"\n      data-state={added ? 'added' : 'offer'}\n      data-min-viewport={String(MIN_VIEWPORT)}\n      className={cn(\n        '@container border-border bg-card text-card-foreground grid gap-3 rounded-xl border p-5',\n        className,\n      )}\n      {...props}\n    >\n      <div className=\"flex items-start gap-3\">\n        <BellRing aria-hidden className=\"text-primary mt-0.5 size-5 shrink-0\" />\n        <div className=\"grid gap-1\">\n          <h3 id={`${id}-title`} data-slot=\"reminder-offer-title\" className=\"font-heading font-semibold\">\n            {labels?.title ?? 'A nudge each day?'}\n          </h3>\n          <p data-slot=\"reminder-offer-body\" className=\"text-muted-foreground text-sm text-pretty\">\n            {labels?.body ??\n              'Add a daily reminder to your own calendar. Nothing is sent to us, and you can remove it there any time.'}\n          </p>\n        </div>\n      </div>\n      {added ? null : (\n        <div data-slot=\"reminder-offer-controls\" className=\"grid gap-2 @sm:flex @sm:flex-wrap @sm:items-end\">\n          <label className=\"grid gap-1 text-sm font-medium\" htmlFor={`${id}-time`}>\n            {labels?.time ?? 'Time'}\n            <input\n              id={`${id}-time`}\n              type=\"time\"\n              data-slot=\"reminder-offer-time\"\n              value={time}\n              onChange={(e) => setTime(e.target.value)}\n              className=\"border-input bg-background focus-visible:outline-ring h-10 rounded-md border px-3 tabular-nums focus-visible:outline-2 focus-visible:outline-offset-2\"\n            />\n          </label>\n          <Button type=\"button\" data-slot=\"reminder-offer-add\" onClick={add}>\n            {labels?.add ?? 'Add to my calendar'}\n          </Button>\n          {onDismiss ? (\n            <Button type=\"button\" variant=\"ghost\" data-slot=\"reminder-offer-dismiss\" onClick={onDismiss}>\n              {labels?.dismiss ?? 'Not now'}\n            </Button>\n          ) : null}\n        </div>\n      )}\n      <p data-slot=\"reminder-offer-status\" aria-live=\"polite\" className=\"text-sm font-medium empty:hidden\">\n        {added ? (labels?.added ?? 'Added. Open the file to save it in your calendar.') : ''}\n      </p>\n    </section>\n  );\n}\nReminderOffer.displayName = 'ReminderOffer';\n\nexport { ReminderOffer };\nexport type { ReminderOfferProps, ReminderOfferLabels };\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/reminder-model.ts",
      "target": "components/ui/games/reminder-model.ts",
      "type": "registry:ui",
      "content": "import { isDayKey, type DayKey } from '@/components/ui/games/daily';\n\n/**\n * @interlace/ui — games/reminder-model\n *\n * A daily reminder the player keeps in their own calendar: an iCalendar\n * (.ics) file with one event that repeats every day at a time they chose,\n * with an alert. Nothing is sent and nothing is stored on a server; the\n * player's calendar does the reminding, and they remove it there.\n *\n * Pure, so a server can serve the same file from a link.\n *\n * ## Local time\n *\n * The event uses floating time (no time zone), so \"6:30 PM\" stays 6:30 PM\n * wherever the player is, which is what a daily habit wants.\n *\n * ## Format\n *\n * RFC 5545: CRLF line ends, text escaped, lines folded at 75 octets.\n */\n\nexport interface ReminderInput {\n  /** The event's title, as the calendar shows it. */\n  title: string;\n  /** A line or two under the title. */\n  description?: string;\n  /** Opens from the event. */\n  url?: string;\n  /** \"HH:MM\", 24-hour, the player's local time. */\n  time: string;\n  /** The first day. */\n  start: DayKey;\n  /** Minutes the event lasts. @default 10 */\n  minutes?: number;\n  /** Stable id, so adding it again updates rather than duplicates. */\n  uid: string;\n  /** Names the app that made the file. @default '-//Interlace//Reminder//EN' */\n  prodId?: string;\n  /** When the file was made, for DTSTAMP. @default now */\n  now?: Date;\n}\n\nconst TIME = /^([01]\\d|2[0-3]):([0-5]\\d)$/;\n\n/** True for a 24-hour \"HH:MM\". */\nexport function isReminderTime(value: string): boolean {\n  return TIME.test(value);\n}\n\n/** Escapes text for an iCalendar value. */\nexport function escapeIcsText(value: string): string {\n  return value.replace(/\\\\/g, '\\\\\\\\').replace(/;/g, '\\\\;').replace(/,/g, '\\\\,').replace(/\\r?\\n/g, '\\\\n');\n}\n\n/** Folds a content line at 75 octets, continuation lines starting with a space. */\nexport function foldIcsLine(line: string): string {\n  const enc = new TextEncoder();\n  const parts: string[] = [];\n  let current = '';\n  let size = 0;\n  for (const ch of line) {\n    const n = enc.encode(ch).length;\n    const limit = parts.length === 0 ? 75 : 74;\n    if (size + n > limit) {\n      parts.push(current);\n      current = '';\n      size = 0;\n    }\n    current += ch;\n    size += n;\n  }\n  parts.push(current);\n  return parts.join('\\r\\n ');\n}\n\nconst pad = (n: number) => String(n).padStart(2, '0');\n\nfunction stampUtc(d: Date): string {\n  return `${d.getUTCFullYear()}${pad(d.getUTCMonth() + 1)}${pad(d.getUTCDate())}T${pad(d.getUTCHours())}${pad(\n    d.getUTCMinutes(),\n  )}${pad(d.getUTCSeconds())}Z`;\n}\n\n/** The .ics text for a daily reminder. Throws on a bad time or day key. */\nexport function reminderIcs(input: ReminderInput): string {\n  const match = TIME.exec(input.time);\n  if (!match) throw new RangeError(`reminderIcs: time must be \"HH:MM\", got \"${input.time}\"`);\n  if (!isDayKey(input.start)) throw new RangeError(`reminderIcs: start must be a day key, got \"${input.start}\"`);\n  const hour = Number(match[1]);\n  const minute = Number(match[2]);\n  const length = Math.max(1, Math.min(120, Math.floor(input.minutes ?? 10)));\n  const date = input.start.replace(/-/g, '');\n  const endMinutes = hour * 60 + minute + length;\n  // An event that would end after midnight ends at 23:59 instead.\n  const end = endMinutes >= 24 * 60 ? '235900' : `${pad(Math.floor(endMinutes / 60))}${pad(endMinutes % 60)}00`;\n  const lines = [\n    'BEGIN:VCALENDAR',\n    'VERSION:2.0',\n    `PRODID:${input.prodId ?? '-//Interlace//Reminder//EN'}`,\n    'CALSCALE:GREGORIAN',\n    'BEGIN:VEVENT',\n    `UID:${input.uid}`,\n    `DTSTAMP:${stampUtc(input.now ?? new Date())}`,\n    `DTSTART:${date}T${pad(hour)}${pad(minute)}00`,\n    `DTEND:${date}T${end}`,\n    'RRULE:FREQ=DAILY',\n    `SUMMARY:${escapeIcsText(input.title)}`,\n  ];\n  if (input.description) lines.push(`DESCRIPTION:${escapeIcsText(input.description)}`);\n  if (input.url) lines.push(`URL:${input.url}`);\n  lines.push(\n    'TRANSP:TRANSPARENT',\n    'BEGIN:VALARM',\n    'ACTION:DISPLAY',\n    `DESCRIPTION:${escapeIcsText(input.title)}`,\n    'TRIGGER:PT0M',\n    'END:VALARM',\n    'END:VEVENT',\n    'END:VCALENDAR',\n  );\n  return lines.map(foldIcsLine).join('\\r\\n') + '\\r\\n';\n}\n"
    }
  ],
  "meta": {
    "tier": "game",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.1.0",
    "since": "2.0.0"
  },
  "docs": "## @interlace/reminder-offer\n\nInstalled to `components/ui/games/reminder-offer.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/games/reminder-offer';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/reminder-offer\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
