{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"newsletter-signup","type":"registry:block","title":"Newsletter signup","description":"An email signup framed by a stack of past issues; subscribing drops the next issue, addressed to you, onto the front.","categories":["blocks"],"dependencies":["@radix-ui/react-switch","lucide-react","motion"],"registryDependencies":["https://ui.teamofsilicons.com/r/silicon-motion-tokens.json","https://ui.teamofsilicons.com/r/animated-counter.json","https://ui.teamofsilicons.com/r/segmented-control.json","https://ui.teamofsilicons.com/r/switch.json"],"files":[{"path":"registry/blocks/newsletter-signup/newsletter-signup.tsx","type":"registry:component","target":"@components/silicon-ui/blocks/newsletter-signup/newsletter-signup.tsx","content":"\"use client\";\n\nimport { forwardRef, useEffect, useId, useRef, useState } from \"react\";\nimport type { FormEvent, ReactNode } from \"react\";\nimport Image from \"next/image\";\nimport { AnimatePresence, motion, useAnimate, useReducedMotion } from \"motion/react\";\nimport type { Variants } from \"motion/react\";\nimport { ArrowRight } from \"lucide-react\";\nimport AnimatedCounter from \"../../animated-counter/animated-counter\";\nimport SegmentedControl from \"../../segmented-control/segmented-control\";\nimport { Switch } from \"../../switch/switch\";\nimport { motionTokens } from \"../../lib/motion-tokens\";\nimport { newsletterCopy, newsletterPublication, newsletterReaders } from \"./newsletter-signup-data\";\nimport type { NewsletterIssue, NewsletterPublication } from \"./newsletter-signup-data\";\nimport styles from \"./newsletter-signup.module.css\";\n\nexport type { NewsletterIssue, NewsletterPublication, NewsletterStory } from \"./newsletter-signup-data\";\nexport type NewsletterVariant = \"inline\" | \"card\";\n\nexport interface NewsletterSignupProps {\n  /** `inline` puts the copy and form beside the issue stack; `card` is a self-contained card with the stack in a tray on top. */\n  variant?: NewsletterVariant;\n  title?: string;\n  description?: string;\n  placeholder?: string;\n  buttonLabel?: string;\n  /** Short line under the form about frequency and privacy. */\n  privacyNote?: ReactNode;\n  /** Link after the privacy note. Pass null to hide it. */\n  privacyLink?: { label: string; href: string } | null;\n  /** Reader count and up to three faces. The count ticks up by one when someone subscribes. Pass null to hide it. */\n  readers?: { count: number; faces: string[] } | null;\n  /** The issue stack. On success the upcoming issue, addressed to the new reader, lands on top. Pass null for a form without the stack. */\n  publication?: NewsletterPublication | null;\n  /** Called with a valid, trimmed email. Reject to show an error and keep the email; resolve to show the success state. */\n  onSubscribe?: (email: string) => void | Promise<void>;\n  className?: string;\n}\n\ntype Phase = \"idle\" | \"sending\" | \"done\";\ntype Problem = { kind: \"invalid\" | \"failed\"; text: string };\ntype Bezier = [number, number, number, number];\nconst enter = [...motionTokens.ease.enter] as Bezier;\nconst standard = [...motionTokens.ease.standard] as Bezier;\nconst MESSAGES = {\n  empty: \"Enter your email address\",\n  format: \"Enter an email like name@company.com\",\n  failed: \"That didn't go through. Your email is kept, so try again.\",\n};\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/;\n/** How far each issue behind the front one peeks out above it. */\nconst STEP = 12;\n\nfunction validate(value: string): Problem | null {\n  const email = value.trim();\n  if (!email) return { kind: \"invalid\", text: MESSAGES.empty };\n  if (!EMAIL.test(email)) return { kind: \"invalid\", text: MESSAGES.format };\n  return null;\n}\n\nconst swapIn = { opacity: 0, y: 6, filter: `blur(${motionTokens.blur.subtle}px)` };\nconst swapShown = { opacity: 1, y: 0, filter: \"blur(0px)\" };\nconst swapOut = { opacity: 0, y: -6, filter: `blur(${motionTokens.blur.subtle}px)`, transition: { duration: motionTokens.duration.fast, ease: standard } };\nconst fadeIn = { opacity: 0 };\nconst fadeOut = { opacity: 0, transition: { duration: motionTokens.duration.instant } };\n\n/** A line that swaps in place: the old text lifts away and the new one rises out of a soft blur. */\nfunction Swap({ id, children, reduced, className, live }: { id: string; children: ReactNode; reduced: boolean; className?: string; live?: \"polite\" }) {\n  return <div className={className} aria-live={live}>\n    <AnimatePresence initial={false} mode=\"popLayout\">\n      <motion.div key={id} initial={reduced ? fadeIn : swapIn} animate={swapShown} exit={reduced ? fadeOut : swapOut} transition={{ duration: reduced ? motionTokens.duration.instant : motionTokens.duration.standard, ease: enter }}>{children}</motion.div>\n    </AnimatePresence>\n  </div>;\n}\n\n/** One issue: masthead, recipient line, subject, and three stories with thumbnails. */\nfunction IssueCard({ issue, name, to }: { issue: NewsletterIssue; name: string; to?: string }) {\n  return <>\n    <header className={styles.issueHead}>\n      <span className={styles.masthead}>{name}</span>\n      <span className={styles.issueNumber}>Issue {issue.number}</span>\n    </header>\n    <p className={styles.issueMeta}>\n      <span className={styles.issueDate}>{issue.date}</span>\n      {to && <><span aria-hidden=\"true\">&middot;</span><span className={styles.recipient}>To <span className={styles.recipientEmail}>{to}</span></span></>}\n    </p>\n    <h3 className={styles.subject}>{issue.subject}</h3>\n    <ul className={styles.stories}>\n      {issue.stories.slice(0, 3).map(story => <li key={story.title} className={styles.story}>\n        <Image className={styles.thumb} src={story.image} alt=\"\" width={88} height={88} sizes=\"44px\" />\n        <span className={styles.storyTitle}>{story.title}</span>\n        <span className={styles.minutes}>{story.minutes} min</span>\n      </li>)}\n    </ul>\n  </>;\n}\n\ntype Placement = { depth: number; upcoming: boolean };\n/** The front issue sits flat; each one behind steps up and shrinks a little so its top edge shows. */\nconst stackVariants: Variants = {\n  placed: ({ depth }: Placement) => ({ opacity: 1, y: -depth * STEP, scale: 1 - depth * .045 }),\n  // The upcoming issue arrives from below, where the form is; older ones slide in from behind.\n  away: ({ upcoming }: Placement) => upcoming ? { opacity: 0, y: 56, scale: 1 } : { opacity: 0, y: -3 * STEP, scale: 1 - 3 * .045 },\n};\n/** Position rides the no-overshoot spring; opacity resolves fast so two issues never read through each other. */\nconst settle = { ...motionTokens.spring.smooth, opacity: { duration: motionTokens.duration.instant, ease: standard } };\n/** Reduced motion: issues take their places at once and only fade. */\nconst still = { duration: 0, opacity: { duration: motionTokens.duration.fast } };\n\n/**\n * A stack of recent issues. When someone subscribes, the upcoming issue, addressed to them, lands on the front\n * and the older ones step back; the oldest drops away.\n */\nfunction IssueStack({ publication, delivered, to, reduced, compact }: { publication: NewsletterPublication; delivered: boolean; to: string; reduced: boolean; compact?: boolean }) {\n  const issues = (delivered ? [publication.upcoming, ...publication.recent] : publication.recent).slice(0, 3);\n  return <div className={styles.stack} data-compact={compact ? \"\" : undefined}>\n    {/* An unseen copy of the upcoming issue keeps the stack as tall as the tallest issue it will ever hold. */}\n    <div className={`${styles.issue} ${styles.issueSizer}`} aria-hidden=\"true\"><IssueCard issue={publication.upcoming} name={publication.name} to={to || \" \"} /></div>\n    <AnimatePresence initial={false}>\n      {issues.map((issue, depth) => {\n        const upcoming = issue === publication.upcoming;\n        const placement: Placement = { depth, upcoming };\n        return <motion.article\n          key={issue.number}\n          className={styles.issue}\n          data-depth={depth}\n          aria-hidden={depth > 0 ? true : undefined}\n          aria-label={depth === 0 ? `${publication.name}, issue ${issue.number}` : undefined}\n          custom={placement}\n          variants={stackVariants}\n          initial=\"away\"\n          animate=\"placed\"\n          exit=\"away\"\n          transition={reduced ? still : settle}\n          style={{ zIndex: 3 - depth }}\n        >\n          <IssueCard issue={issue} name={publication.name} to={upcoming ? to : undefined} />\n        </motion.article>;\n      })}\n    </AnimatePresence>\n  </div>;\n}\n\n/** Faces and a reader count that ticks up by one when you join. */\nfunction Readers({ readers, done, reduced }: { readers: { count: number; faces: string[] }; done: boolean; reduced: boolean }) {\n  return <div className={styles.readers}>\n    <span className={styles.faces} aria-hidden=\"true\">\n      {readers.faces.slice(0, 3).map(src => <Image key={src} src={src} alt=\"\" width={56} height={56} sizes=\"28px\" />)}\n    </span>\n    <span className={styles.readerLine}>\n      <span className={styles.count}><AnimatedCounter value={readers.count + (done ? 1 : 0)} /></span>\n      {\" \"}readers\n      <AnimatePresence initial={false}>\n        {/* The phrase opens its own width on the no-overshoot spring, so the centred line glides instead of jumping sideways. */}\n        {done && <motion.span key=\"you\" className={styles.you}\n          initial={reduced ? { opacity: 0 } : { opacity: 0, width: 0 }}\n          animate={reduced ? { opacity: 1 } : { opacity: 1, width: \"auto\" }}\n          exit={reduced ? { opacity: 0 } : { opacity: 0, width: 0 }}\n          transition={reduced ? { duration: motionTokens.duration.instant } : { width: motionTokens.spring.smooth, opacity: { duration: motionTokens.duration.standard, ease: enter, delay: .12 } }}>, including you</motion.span>}\n      </AnimatePresence>\n    </span>\n  </div>;\n}\n\n/**\n * A newsletter signup framed by the newsletter itself: a stack of recent issues. Subscribing drops the next issue,\n * addressed to the new reader, onto the front of the stack and ticks the reader count up by one.\n * Comes as an inline page section or a self-contained card.\n */\nexport const NewsletterSignup = forwardRef<HTMLElement, NewsletterSignupProps>(function NewsletterSignup({\n  variant = \"inline\",\n  title,\n  description,\n  placeholder = \"you@company.com\",\n  buttonLabel = \"Subscribe\",\n  privacyNote = newsletterCopy.privacy,\n  privacyLink = newsletterCopy.privacyLink,\n  readers = newsletterReaders,\n  publication = newsletterPublication,\n  onSubscribe,\n  className,\n}, ref) {\n  const id = useId();\n  const reduced = !!useReducedMotion();\n  const [email, setEmail] = useState(\"\");\n  const [problem, setProblem] = useState<Problem | null>(null);\n  const [tried, setTried] = useState(false);\n  const [phase, setPhase] = useState<Phase>(\"idle\");\n  const [sentTo, setSentTo] = useState(\"\");\n  const input = useRef<HTMLInputElement>(null);\n  const again = useRef<HTMLButtonElement>(null);\n  const busy = useRef(false);\n  const refocus = useRef(false);\n  const [pill, animatePill] = useAnimate<HTMLDivElement>();\n  const copy = newsletterCopy[variant];\n\n  useEffect(() => {\n    if (phase === \"idle\" && refocus.current) { refocus.current = false; input.current?.focus(); }\n    if (phase === \"done\") again.current?.focus();\n  }, [phase]);\n\n  function shake() {\n    if (reduced || !pill.current) return;\n    animatePill(pill.current, { x: [0, -6, 5, -3, 1, 0] }, { duration: .36, ease: \"easeOut\" });\n  }\n\n  async function submit(event: FormEvent) {\n    event.preventDefault();\n    if (busy.current || phase !== \"idle\") return;\n    setTried(true);\n    const found = validate(email);\n    setProblem(found);\n    if (found) { shake(); input.current?.focus(); return; }\n    const value = email.trim();\n    busy.current = true;\n    setPhase(\"sending\");\n    try {\n      await (onSubscribe ? onSubscribe(value) : new Promise(resolve => setTimeout(resolve, 1100)));\n      setSentTo(value);\n      setPhase(\"done\");\n    } catch {\n      setPhase(\"idle\");\n      setProblem({ kind: \"failed\", text: MESSAGES.failed });\n      shake();\n    } finally {\n      busy.current = false;\n    }\n  }\n\n  function reset() {\n    setEmail(\"\");\n    setProblem(null);\n    setTried(false);\n    refocus.current = true;\n    setPhase(\"idle\");\n  }\n\n  const done = phase === \"done\";\n  const sending = phase === \"sending\";\n  const messageId = `${id}-message`;\n  const labelKey = done ? \"done\" : sending ? \"sending\" : problem?.kind === \"failed\" ? \"retry\" : \"idle\";\n  const labels: Record<string, ReactNode> = {\n    idle: <>{buttonLabel}<ArrowRight size={16} strokeWidth={1.75} aria-hidden=\"true\" /></>,\n    retry: <>Try again<ArrowRight size={16} strokeWidth={1.75} aria-hidden=\"true\" /></>,\n    sending: <><span className={styles.spinner} aria-hidden=\"true\" />Subscribing</>,\n    done: <><span className={styles.check} aria-hidden=\"true\"><svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\"><motion.path d=\"M5 12.5l4.5 4.5L19 7.5\" initial={reduced ? false : { pathLength: 0 }} animate={{ pathLength: 1 }} transition={{ duration: reduced ? 0 : .34, ease: enter, delay: .12 }} /></svg></span>Subscribed</>,\n  };\n\n  const doneText = \"Check your inbox to confirm.\";\n  const note = <>{privacyNote}{privacyLink && <> <a className={styles.link} href={privacyLink.href}>{privacyLink.label}</a></>}</>;\n  // Plain copies of the note and the confirmation, used only to reserve the line's height.\n  const measures = [<>{privacyNote}{privacyLink && ` ${privacyLink.label}`}</>, `${doneText} Use a different email`, MESSAGES.empty, MESSAGES.format, MESSAGES.failed];\n  const form = <form className={styles.form} onSubmit={submit} noValidate aria-label={title ?? copy.title}>\n    <motion.div ref={pill} className={styles.pill} data-invalid={problem ? \"\" : undefined} data-done={done ? \"\" : undefined}>\n      <label htmlFor={`${id}-email`} className={styles.srOnly}>Email address</label>\n      <input\n        ref={input}\n        id={`${id}-email`}\n        className={styles.input}\n        type=\"email\"\n        name=\"email\"\n        inputMode=\"email\"\n        autoComplete=\"email\"\n        enterKeyHint=\"send\"\n        autoCapitalize=\"off\"\n        spellCheck={false}\n        placeholder={placeholder}\n        value={email}\n        readOnly={phase !== \"idle\"}\n        aria-invalid={problem?.kind === \"invalid\" ? true : undefined}\n        aria-describedby={messageId}\n        onBlur={() => { if (email.trim() && !tried && phase === \"idle\") { setTried(true); setProblem(validate(email)); } }}\n        onChange={event => { setEmail(event.target.value); if (tried) setProblem(validate(event.target.value)); else if (problem) setProblem(null); }}\n      />\n      <motion.button\n        type={done ? \"button\" : \"submit\"}\n        className={styles.submit}\n        data-state={labelKey}\n        aria-busy={sending || undefined}\n        aria-disabled={sending || done || undefined}\n        tabIndex={done ? -1 : undefined}\n        whileTap={{ scale: reduced || sending || done ? 1 : .97 }}\n        transition={motionTokens.spring.snappy}\n      >\n        <span className={styles.labels}>\n          {Object.keys(labels).map(key => <span key={key} className={styles.sizer} aria-hidden=\"true\">{key === \"done\" ? <><span className={styles.check} />Subscribed</> : labels[key]}</span>)}\n          <AnimatePresence initial={false} mode=\"popLayout\">\n            <motion.span key={labelKey} className={styles.label} initial={reduced ? fadeIn : swapIn} animate={swapShown} exit={reduced ? fadeOut : swapOut} transition={{ duration: reduced ? motionTokens.duration.instant : motionTokens.duration.standard, ease: enter }}>\n              {labels[labelKey]}\n            </motion.span>\n          </AnimatePresence>\n        </span>\n      </motion.button>\n    </motion.div>\n    <div className={styles.message}>\n      {/* Every message the line can show sits here unseen, so the line is always as tall as the longest one and nothing below it moves. */}\n      {measures.map((text, index) => <p key={index} className={`${styles.note} ${styles.sizer}`} aria-hidden=\"true\">{text}</p>)}\n      <Swap id={problem ? `problem-${problem.text}` : done ? \"done\" : \"note\"} reduced={reduced} className={styles.messageLive} live=\"polite\">\n        <p id={messageId} className={styles.note} data-tone={problem ? \"error\" : done ? \"success\" : undefined} role={problem ? \"alert\" : undefined}>\n          {problem?.text ?? (done\n            ? <>{doneText}<span className={styles.srOnly}> The link went to {sentTo}.</span> <button ref={again} type=\"button\" className={styles.textButton} onClick={reset}>Use a different email</button></>\n            : note)}\n        </p>\n      </Swap>\n    </div>\n  </form>;\n\n  const root = [styles.newsletter, className].filter(Boolean).join(\" \");\n\n  if (variant === \"card\") {\n    return <section ref={ref} className={root} data-variant=\"card\" aria-labelledby={`${id}-title`}>\n      {/* The shell spans the section so a host layout can set its gutter without reaching into the card. */}\n      <div className={styles.cardShell}>\n      <div className={styles.card}>\n        {publication && <div className={styles.tray}>\n          <IssueStack publication={publication} delivered={done} to={sentTo} reduced={reduced} compact />\n        </div>}\n        <div className={styles.cardBody}>\n          <h2 id={`${id}-title`} className={styles.cardTitle}>{title ?? copy.title}</h2>\n          <p className={styles.description}>{description ?? copy.description}</p>\n          {form}\n          {readers && <Readers readers={readers} done={done} reduced={reduced} />}\n        </div>\n      </div>\n      </div>\n    </section>;\n  }\n\n  return <section ref={ref} className={root} data-variant=\"inline\" data-aside={publication || readers ? \"\" : undefined} aria-labelledby={`${id}-title`}>\n    <div className={styles.inline}>\n      <div className={styles.intro}>\n        <h2 id={`${id}-title`} className={styles.title}>{title ?? copy.title}</h2>\n        <p className={styles.description}>{description ?? copy.description}</p>\n        {form}\n      </div>\n      {(publication || readers) && <div className={styles.aside}>\n        {publication && <IssueStack publication={publication} delivered={done} to={sentTo} reduced={reduced} />}\n        {readers && <Readers readers={readers} done={done} reduced={reduced} />}\n      </div>}\n    </div>\n  </section>;\n});\n\nNewsletterSignup.displayName = \"NewsletterSignup\";\n\nconst variantOptions = [{ value: \"inline\", label: \"Inline\" }, { value: \"card\", label: \"Card\" }];\n\n/** Preview: both layouts. Subscribing is simulated and nothing is sent; the switch makes the next send fail. */\nexport function NewsletterSignupBlock() {\n  const [variant, setVariant] = useState<NewsletterVariant>(\"inline\");\n  const [fail, setFail] = useState(false);\n  const switchId = useId();\n  const simulate = () => new Promise<void>((resolve, reject) => setTimeout(() => fail ? reject(new Error(\"Simulated failure\")) : resolve(), 1100));\n  return <div className={styles.preview}>\n    <div className={styles.controls}>\n      <SegmentedControl label=\"Newsletter layout\" options={variantOptions} value={variant} onValueChange={next => setVariant(next as NewsletterVariant)} />\n      <div className={styles.simulate}>\n        <Switch id={switchId} checked={fail} onCheckedChange={setFail} />\n        <label htmlFor={switchId}>Fail the next send</label>\n      </div>\n    </div>\n    <div className={styles.frame}>\n      <NewsletterSignup key={variant} variant={variant} onSubscribe={simulate} />\n    </div>\n    <p className={styles.caption}>Subscribing is simulated in this preview. Nothing is sent.</p>\n  </div>;\n}\n\nexport default NewsletterSignupBlock;\n"},{"path":"registry/blocks/newsletter-signup/newsletter-signup-data.ts","type":"registry:component","target":"@components/silicon-ui/blocks/newsletter-signup/newsletter-signup-data.ts","content":"import { avatar, photo, type PersonId, type PhotoId } from \"../../lib/media\";\n\n/** One story teased in an issue. `image` is a small square-cropped thumbnail. */\nexport interface NewsletterStory {\n  title: string;\n  image: string;\n  minutes: number;\n}\n\n/** One issue of the newsletter, as it appears on the stack. */\nexport interface NewsletterIssue {\n  number: number;\n  /** Send date as it should read, such as \"Friday, September 25\". */\n  date: string;\n  subject: string;\n  /** Up to three stories. */\n  stories: NewsletterStory[];\n}\n\n/** The publication shown beside the form: the next issue lands on the stack of recent ones when someone subscribes. */\nexport interface NewsletterPublication {\n  name: string;\n  /** The next issue. It is addressed to the new reader and joins the front of the stack on success. */\n  upcoming: NewsletterIssue;\n  /** Recent issues, newest first. The first three make the stack. */\n  recent: NewsletterIssue[];\n}\n\nconst story = (title: string, image: PhotoId, minutes: number): NewsletterStory => ({ title, image: photo(image).src, minutes });\n\nexport const newsletterCopy = {\n  inline: {\n    title: \"Five minutes on interface craft, every Friday\",\n    description: \"Three links worth your time and one short essay on the details that make software feel right.\",\n  },\n  card: {\n    title: \"Get the next issue on Friday\",\n    description: \"Three links and one short essay on interface craft. Five minutes, once a week.\",\n  },\n  privacy: \"No tracking pixels. Unsubscribe with one click.\",\n  privacyLink: { label: \"Privacy policy\", href: \"#privacy\" },\n};\n\n/** Sample publication. Dates follow a Friday send; images come from `public/media/photos`. */\nexport const newsletterPublication: NewsletterPublication = {\n  name: \"Margins\",\n  upcoming: {\n    number: 149,\n    date: \"Friday, October 2\",\n    subject: \"Designing for the second visit, not the first\",\n    stories: [\n      story(\"Empty states that invite a first step\", \"reading-chair\", 5),\n      story(\"Texture without noise, from a ceramics studio\", \"stacked-bowls\", 4),\n      story(\"How a concert hall seats two thousand people\", \"concert-hall\", 7),\n    ],\n  },\n  recent: [\n    {\n      number: 148,\n      date: \"Friday, September 25\",\n      subject: \"Why the best settings pages feel quiet\",\n      stories: [\n        story(\"What a sunroom teaches about contrast\", \"sunroom\", 4),\n        story(\"The case for a single accent color\", \"ceramic-lamp\", 3),\n        story(\"Lisbon tram signs and wayfinding at scale\", \"lisbon-tram\", 6),\n      ],\n    },\n    {\n      number: 147,\n      date: \"Friday, September 18\",\n      subject: \"Springs that settle instead of bounce\",\n      stories: [\n        story(\"Reading the ridge line of an animation curve\", \"mountain-ridges\", 5),\n        story(\"A table lamp and the warmth of dark mode\", \"table-lamp\", 3),\n        story(\"Curves in architecture and in corners\", \"curved-facade\", 4),\n      ],\n    },\n    {\n      number: 146,\n      date: \"Friday, September 11\",\n      subject: \"Copy that sounds like a person\",\n      stories: [\n        story(\"Error messages that take the blame\", \"glass-carafe\", 4),\n        story(\"Writing buttons as verbs\", \"home-office\", 3),\n        story(\"Tone of voice at the dinner table\", \"salmon-dinner\", 5),\n      ],\n    },\n  ],\n};\n\n/** Readers shown under the stack and in the card. */\nexport const newsletterReaders = {\n  count: 12480,\n  faces: ([\"jasmine-brooks\", \"daniel-kim\", \"ava-mitchell\"] as PersonId[]).map(id => avatar(id)),\n};\n"},{"path":"lib/media.ts","type":"registry:lib","target":"@components/silicon-ui/lib/media.ts","content":"/**\n * Shared demo media. Files live in `public/media/`, credits in `public/media/CREDITS.md`.\n * Portraits are 400 px squares; photos are 1600 px on the long side.\n */\n\nexport interface MediaPerson {\n  id: string;\n  name: string;\n  role?: string;\n  src: string;\n}\n\nexport interface MediaPhoto {\n  id: string;\n  alt: string;\n  src: string;\n  width: number;\n  height: number;\n}\n\nexport const people = [\n  { id: \"emma-collins\", name: \"Emma Collins\", role: \"Product designer\", src: \"/media/people/emma-collins.jpg\" },\n  { id: \"marcus-johnson\", name: \"Marcus Johnson\", role: \"Frontend engineer\", src: \"/media/people/marcus-johnson.jpg\" },\n  { id: \"jasmine-brooks\", name: \"Jasmine Brooks\", role: \"Design lead\", src: \"/media/people/jasmine-brooks.jpg\" },\n  { id: \"olivia-bennett\", name: \"Olivia Bennett\", role: \"Platform engineer\", src: \"/media/people/olivia-bennett.jpg\" },\n  { id: \"sofia-ramirez\", name: \"Sofia Ramirez\", role: \"Operations lead\", src: \"/media/people/sofia-ramirez.jpg\" },\n  { id: \"ryan-sullivan\", name: \"Ryan Sullivan\", role: \"Account executive\", src: \"/media/people/ryan-sullivan.jpg\" },\n  { id: \"hannah-walsh\", name: \"Hannah Walsh\", role: \"Customer success\", src: \"/media/people/hannah-walsh.jpg\" },\n  { id: \"chloe-nguyen\", name: \"Chloe Nguyen\", role: \"Data analyst\", src: \"/media/people/chloe-nguyen.jpg\" },\n  { id: \"ava-mitchell\", name: \"Ava Mitchell\", role: \"Marketing manager\", src: \"/media/people/ava-mitchell.jpg\" },\n  { id: \"daniel-kim\", name: \"Daniel Kim\", role: \"Backend engineer\", src: \"/media/people/daniel-kim.jpg\" },\n  { id: \"jordan-reyes\", name: \"Jordan Reyes\", role: \"Support specialist\", src: \"/media/people/jordan-reyes.jpg\" },\n  { id: \"mateo-alvarez\", name: \"Mateo Alvarez\", role: \"Mobile engineer\", src: \"/media/people/mateo-alvarez.jpg\" },\n  { id: \"tyler-hayes\", name: \"Tyler Hayes\", role: \"Sales lead\", src: \"/media/people/tyler-hayes.jpg\" },\n  { id: \"andre-williams\", name: \"Andre Williams\", role: \"Finance partner\", src: \"/media/people/andre-williams.jpg\" },\n  { id: \"nathan-cole\", name: \"Nathan Cole\", role: \"Engineering manager\", src: \"/media/people/nathan-cole.jpg\" },\n  { id: \"diane-foster\", name: \"Diane Foster\", role: \"Chief operating officer\", src: \"/media/people/diane-foster.jpg\" },\n] as const satisfies readonly MediaPerson[];\n\nexport const photos = [\n  { id: \"lounge-chair\", alt: \"A woven oak lounge chair with a sheepskin and linen cushion on a concrete floor\", src: \"/media/photos/lounge-chair.jpg\", width: 1280, height: 1600 },\n  { id: \"table-lamp\", alt: \"A white mushroom table lamp glowing beside books and a small vase\", src: \"/media/photos/table-lamp.jpg\", width: 1600, height: 900 },\n  { id: \"linen-throw\", alt: \"Folded natural linen throws with fringed edges in soft window light\", src: \"/media/photos/linen-throw.jpg\", width: 1067, height: 1600 },\n  { id: \"glass-carafe\", alt: \"A hand pouring water from a ribbed glass carafe into tumblers\", src: \"/media/photos/glass-carafe.jpg\", width: 1280, height: 1600 },\n  { id: \"stoneware-cups\", alt: \"Two speckled stoneware cups with a lid on a pale table\", src: \"/media/photos/stoneware-cups.jpg\", width: 1067, height: 1600 },\n  { id: \"stacked-bowls\", alt: \"Two stacked speckled ceramic bowls against a dark wall\", src: \"/media/photos/stacked-bowls.jpg\", width: 1600, height: 1067 },\n  { id: \"ceramic-lamp\", alt: \"A sculptural ceramic lamp with a linen shade on a walnut sideboard\", src: \"/media/photos/ceramic-lamp.jpg\", width: 1067, height: 1600 },\n  { id: \"living-room\", alt: \"A bright living room with timber beams, arched windows, and cream sofas\", src: \"/media/photos/living-room.jpg\", width: 1200, height: 1600 },\n  { id: \"sunroom\", alt: \"A sunroom with a round dining table, plants, and windows on three sides\", src: \"/media/photos/sunroom.jpg\", width: 1600, height: 1067 },\n  { id: \"home-office\", alt: \"A home office with a wooden desk and deep green walls\", src: \"/media/photos/home-office.jpg\", width: 1600, height: 1200 },\n  { id: \"reading-chair\", alt: \"A grey armchair and ottoman with a knit throw in a dark green room\", src: \"/media/photos/reading-chair.jpg\", width: 1600, height: 900 },\n  { id: \"bedroom\", alt: \"A made bed with striped linen pillows against an oak headboard\", src: \"/media/photos/bedroom.jpg\", width: 1067, height: 1600 },\n  { id: \"restaurant\", alt: \"A warm restaurant dining room with woven pendant lights and a tree\", src: \"/media/photos/restaurant.jpg\", width: 1067, height: 1600 },\n  { id: \"wine-bar\", alt: \"A glass carafe of red wine on a bar table in low evening light\", src: \"/media/photos/wine-bar.jpg\", width: 1600, height: 1067 },\n  { id: \"concert-hall\", alt: \"Curved stainless steel panels of the Walt Disney Concert Hall against a blue sky\", src: \"/media/photos/concert-hall.jpg\", width: 1600, height: 1143 },\n  { id: \"curved-facade\", alt: \"A white tiled building facade with curved balconies\", src: \"/media/photos/curved-facade.jpg\", width: 1600, height: 1067 },\n  { id: \"pool-house\", alt: \"A modern glass house beside a long pool under a clear sky\", src: \"/media/photos/pool-house.jpg\", width: 1600, height: 900 },\n  { id: \"terracotta-waves\", alt: \"Wavy terracotta walls rising toward a blue sky\", src: \"/media/photos/terracotta-waves.jpg\", width: 1067, height: 1600 },\n  { id: \"mountain-ridges\", alt: \"Layered mountain ridges under a warm evening sky\", src: \"/media/photos/mountain-ridges.jpg\", width: 1600, height: 1068 },\n  { id: \"alpine-lake\", alt: \"A calm alpine lake reflecting a rocky peak at golden hour\", src: \"/media/photos/alpine-lake.jpg\", width: 1067, height: 1600 },\n  { id: \"coastline\", alt: \"A long coastline with waves rolling onto a beach below green cliffs\", src: \"/media/photos/coastline.jpg\", width: 1200, height: 1600 },\n  { id: \"sea-at-dusk\", alt: \"A calm sea at dusk with a low island on the horizon\", src: \"/media/photos/sea-at-dusk.jpg\", width: 1067, height: 1600 },\n  { id: \"lisbon-tram\", alt: \"A yellow tram on a street lined with historic buildings in Lisbon\", src: \"/media/photos/lisbon-tram.jpg\", width: 1600, height: 1064 },\n  { id: \"lisbon-bridge\", alt: \"The 25 de Abril Bridge crossing the Tagus in Lisbon\", src: \"/media/photos/lisbon-bridge.jpg\", width: 1600, height: 1166 },\n  { id: \"lisbon-rooftops\", alt: \"Terracotta rooftops of Lisbon running down to the river\", src: \"/media/photos/lisbon-rooftops.jpg\", width: 1280, height: 1600 },\n  { id: \"salmon-dinner\", alt: \"Seared salmon with a bright herb salsa and a glass of red wine\", src: \"/media/photos/salmon-dinner.jpg\", width: 1067, height: 1600 },\n  { id: \"chef-plating\", alt: \"A chef spooning sauce onto a plated dish in a dark kitchen\", src: \"/media/photos/chef-plating.jpg\", width: 1600, height: 1600 },\n] as const satisfies readonly MediaPhoto[];\n\nexport type PersonId = (typeof people)[number][\"id\"];\nexport type PhotoId = (typeof photos)[number][\"id\"];\n\n/** Looks up a person by id. */\nexport function person(id: PersonId): MediaPerson {\n  return people.find(entry => entry.id === id)!;\n}\n\n/** Looks up a photo by id. */\nexport function photo(id: PhotoId): MediaPhoto {\n  return photos.find(entry => entry.id === id)!;\n}\n\n/** Square 400 px avatar path for a person id, for `src` props. */\nexport const avatar = (id: PersonId) => person(id).src;\n\n/** 800 × 1000 portrait crop of the same photo, for image-led layouts. */\nexport const portrait = (id: PersonId) => `/media/people/portrait/${id}.jpg`;\n\n/** The first `count` people, for avatar stacks and lists. */\nexport const peopleSample = (count: number) => people.slice(0, count);\n"},{"path":"registry/blocks/newsletter-signup/newsletter-signup.module.css","type":"registry:component","target":"@components/silicon-ui/blocks/newsletter-signup/newsletter-signup.module.css","content":".newsletter {\n  --paper: var(--surface-raised);\n  --paper-back: color-mix(in oklab, var(--surface-raised), var(--surface-muted) 55%);\n  --paper-far: var(--surface-muted);\n  --paper-shadow: 0 1px 1px oklch(0% 0 0 / .03), 0 10px 28px -6px oklch(0% 0 0 / .09);\n  container: newsletter / inline-size;\n  background: var(--background);\n  color: var(--foreground);\n  font-family: var(--font-body);\n  letter-spacing: var(--tracking-body);\n  text-align: start;\n}\n:global(:root[data-theme=\"dark\"]) .newsletter {\n  --paper: oklch(24.5% 0 0);\n  --paper-back: oklch(22.5% 0 0);\n  --paper-far: oklch(21% 0 0);\n  --paper-shadow: 0 1px 1px oklch(0% 0 0 / .2), 0 14px 32px -6px oklch(0% 0 0 / .45);\n}\n.newsletter *, .newsletter *::before, .newsletter *::after { box-sizing: border-box; }\n.srOnly { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n\n/* Inline: copy and form on the left, the issue stack on the right. */\n.inline { display: grid; max-width: 1120px; grid-template-columns: minmax(0, 1fr); gap: var(--space-page) var(--space-stage); margin: 0 auto; padding: var(--space-screen) var(--space-block); }\n.newsletter[data-aside] .inline { grid-template-columns: minmax(0, 1fr) minmax(0, 440px); align-items: center; }\n/* Without the stack or readers the section is the copy and form alone. */\n.newsletter[data-variant=\"inline\"]:not([data-aside]) .inline { max-width: 720px; }\n.intro { display: grid; max-width: 540px; }\n.title { margin: 0; font-family: var(--font-display); font-size: clamp(var(--text-3xl), var(--text-lg) + 3.2cqi, var(--text-4xl)); font-weight: var(--weight-medium); letter-spacing: var(--tracking-display); line-height: var(--leading-display); text-wrap: balance; }\n.description { margin: var(--space-inset) 0 0; color: var(--text-secondary); font-size: var(--text-lg); line-height: var(--leading-body); text-wrap: pretty; }\n.intro .form { margin-top: var(--space-page); }\n.aside { display: grid; justify-items: center; gap: var(--space-section); min-width: 0; }\n\n/* The stack: every issue shares one grid cell, so the stack is as tall as one issue and nothing shifts when they trade places. */\n.stack { display: grid; width: 100%; max-width: 440px; padding-top: calc(var(--space-group) * 2); }\n.issue {\n  display: grid;\n  grid-area: 1 / 1;\n  align-content: start;\n  min-width: 0;\n  border: 1px solid var(--border);\n  border-radius: var(--radius-container); corner-shape: var(--corner-shape);\n  padding: var(--space-section) var(--space-section) var(--space-comfort);\n  background: var(--paper);\n  box-shadow: var(--paper-shadow);\n  transform-origin: 50% 0;\n  transition: background-color var(--duration-considered) var(--ease-standard);\n}\n.issueSizer { visibility: hidden; box-shadow: none; }\n.issue[data-depth=\"1\"] { background: var(--paper-back); box-shadow: none; }\n.issue[data-depth=\"2\"] { background: var(--paper-far); box-shadow: none; }\n.issueHead { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-group); }\n.masthead { font-family: var(--font-display); font-size: var(--text-xl); font-weight: var(--weight-medium); letter-spacing: var(--tracking-display); line-height: var(--leading-display); }\n.issueNumber, .issueMeta { color: var(--text-muted); font-size: var(--text-xs); line-height: var(--leading-body); font-variant-numeric: tabular-nums; }\n.issueMeta { display: flex; min-width: 0; gap: var(--space-related); margin: var(--space-hair) 0 0; white-space: nowrap; }\n.issueMeta > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }\n.recipient { color: var(--text-secondary); }\n.recipientEmail { color: var(--foreground); }\n.subject { min-height: calc(2em * var(--leading-display)); margin: var(--space-comfort) 0 var(--space-inset); border-top: 1px solid var(--border); padding-top: var(--space-comfort); font-family: var(--font-display); font-size: var(--text-2xl); font-weight: var(--weight-medium); letter-spacing: var(--tracking-display); line-height: var(--leading-display); text-wrap: balance; box-sizing: content-box; }\n.stack[data-compact] .subject { font-size: var(--text-xl); }\n.stories { display: grid; gap: var(--space-group); margin: 0; padding: 0; list-style: none; }\n.story { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: var(--space-group); min-height: 44px; }\n.thumb { display: block; width: 44px; height: 44px; border-radius: var(--radius-detail); corner-shape: var(--corner-shape); object-fit: cover; background: var(--surface-muted); }\n.storyTitle { display: -webkit-box; overflow: hidden; color: var(--text-secondary); font-size: var(--text-sm); line-height: var(--leading-body); -webkit-box-orient: vertical; -webkit-line-clamp: 2; text-wrap: pretty; }\n.minutes { color: var(--text-muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; white-space: nowrap; }\n\n/* Readers: faces and a count that ticks up by one. */\n.readers { display: flex; align-items: center; gap: var(--space-group); color: var(--text-secondary); font-size: var(--text-sm); line-height: var(--leading-body); }\n.faces { display: flex; flex: none; padding-left: var(--space-related); }\n.faces img { display: block; width: 28px; height: 28px; margin-left: calc(var(--space-related) * -1); border: 2px solid var(--background); border-radius: 50%; corner-shape: round; object-fit: cover; }\n.card .faces img { border-color: var(--surface); }\n.readerLine { min-width: 0; font-variant-numeric: tabular-nums; white-space: nowrap; }\n.count { display: inline-block; color: var(--foreground); }\n.count > span { color: inherit; font-family: inherit; font-size: inherit; font-weight: var(--weight-medium); letter-spacing: inherit; line-height: inherit; vertical-align: bottom; }\n.you { display: inline-block; overflow: hidden; color: var(--text-secondary); vertical-align: bottom; white-space: nowrap; }\n\n/* Card: a self-contained card whose top is a tray holding the stack, cropped where the card body begins. */\n.newsletter[data-variant=\"card\"] { padding: var(--space-screen) var(--space-section); }\n.cardShell { display: grid; width: 100%; place-items: center; }\n.card { display: grid; width: min(100%, 460px); overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-overlay); corner-shape: var(--corner-shape); background: var(--surface); box-shadow: var(--shadow-resting); }\n.tray { display: grid; height: 248px; grid-template-rows: minmax(0, 1fr); overflow: hidden; justify-items: center; border-bottom: 1px solid var(--border); padding: var(--space-comfort) var(--space-block) 0; background: var(--surface-muted); }\n.tray .stack { height: 100%; -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 64px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 64px), transparent); }\n.tray .issue { box-shadow: none; }\n.cardBody { display: grid; padding: var(--space-block); }\n.cardTitle { margin: 0; font-family: var(--font-display); font-size: var(--text-2xl); font-weight: var(--weight-medium); letter-spacing: var(--tracking-display); line-height: var(--leading-display); text-wrap: balance; }\n.card .description { margin-top: var(--space-related); font-size: var(--text-base); }\n.card .form { margin-top: var(--space-section); }\n.card .readers { margin-top: var(--space-comfort); border-top: 1px solid var(--border-subtle); padding-top: var(--space-comfort); }\n:global(:root[data-theme=\"dark\"]) .tray { background: var(--background); }\n\n/* The pill: one field that holds the input and the button. */\n.form { container: signup / inline-size; display: grid; gap: var(--space-group); min-width: 0; }\n.pill { position: relative; display: flex; height: 58px; align-items: center; gap: var(--space-related); border: 1px solid var(--border-strong); border-radius: var(--radius-full); corner-shape: round; padding: var(--space-tight) var(--space-tight) var(--space-tight) var(--space-section); background: var(--surface); transition: border-color var(--duration-fast) var(--ease-standard), background-color var(--duration-standard) var(--ease-standard); }\n@media (hover: hover) and (pointer: fine) { .pill:not([data-done]):hover { border-color: color-mix(in oklab, var(--foreground) 32%, var(--border-strong)); } }\n.pill:focus-within { border-color: var(--foreground); }\n.pill.pill[data-invalid] { border-color: var(--danger); }\n.pill.pill[data-done] { border-color: color-mix(in oklab, var(--success) 45%, var(--border)); }\n.input { width: 100%; min-width: 0; height: 100%; flex: 1; border: 0; padding: 0; background: none; color: var(--foreground); font: inherit; font-size: var(--text-base); letter-spacing: inherit; outline: none; transition: color var(--duration-standard) var(--ease-standard); }\n.input::placeholder { color: var(--text-muted); }\n.pill[data-done] .input { color: var(--text-secondary); }\n\n.submit { position: relative; display: inline-flex; height: 100%; min-height: 44px; flex: none; align-items: center; justify-content: center; border: 0; border-radius: var(--radius-full); corner-shape: round; padding: 0 var(--space-comfort); background: var(--foreground); color: var(--background); font: inherit; font-size: var(--text-sm); font-weight: var(--weight-medium); cursor: pointer; white-space: nowrap; -webkit-tap-highlight-color: transparent; transition: background-color var(--duration-standard) var(--ease-standard), color var(--duration-standard) var(--ease-standard); }\n@media (hover: hover) and (pointer: fine) { .submit[data-state=\"idle\"]:hover, .submit[data-state=\"retry\"]:hover { background: color-mix(in oklab, var(--foreground) 84%, var(--background)); } }\n.submit[data-state=\"sending\"] { cursor: progress; }\n.submit[data-state=\"done\"] { background: color-mix(in oklab, var(--success) 13%, var(--surface)); color: var(--success); cursor: default; }\n.labels { display: inline-grid; place-items: center; }\n.sizer, .label { display: inline-flex; grid-area: 1 / 1; align-items: center; gap: var(--space-related); }\n.sizer { visibility: hidden; }\n.note.sizer { display: block; }\n.spinner { width: 14px; height: 14px; border: 2px solid color-mix(in oklab, currentColor 30%, transparent); border-top-color: currentColor; border-radius: 50%; corner-shape: round; animation: spin 700ms linear infinite; }\n@keyframes spin { to { transform: rotate(360deg); } }\n.check { display: inline-flex; width: 16px; height: 16px; }\n.check svg { width: 16px; height: 16px; }\n\n/* Two lines are reserved so the note, an error, and the confirmation never move what sits below. */\n.message { display: grid; }\n.message > * { grid-area: 1 / 1; min-width: 0; }\n.messageLive { position: relative; }\n.note { margin: 0; padding-left: var(--space-section); color: var(--text-muted); font-size: var(--text-sm); line-height: var(--leading-body); text-wrap: pretty; }\n.note[data-tone=\"error\"] { color: var(--danger); }\n.note[data-tone=\"success\"] { color: var(--text-secondary); }\n.link, .textButton { color: var(--foreground); text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; transition: text-decoration-color var(--duration-fast) var(--ease-standard); }\n.textButton { border: 0; padding: 0; background: none; font: inherit; cursor: pointer; }\n@media (hover: hover) and (pointer: fine) { .link:hover, .textButton:hover { text-decoration-color: currentColor; } }\n\n@container newsletter (max-width: 860px) {\n  .newsletter[data-variant=\"inline\"] .inline { grid-template-columns: minmax(0, 1fr); gap: var(--space-page); padding: var(--space-stage) var(--space-block); }\n  .intro { max-width: 600px; }\n}\n@container newsletter (max-width: 520px) {\n  .newsletter[data-variant=\"inline\"] .inline { padding: var(--space-page) var(--space-inset); gap: var(--space-page); }\n  .description { font-size: var(--text-base); }\n  .intro .form { margin-top: var(--space-block); }\n  .issue { border-radius: var(--radius-control); corner-shape: var(--corner-shape); padding: var(--space-comfort) var(--space-comfort) var(--space-inset); }\n  .subject, .stack[data-compact] .subject { font-size: var(--text-xl); }\n  .newsletter[data-variant=\"card\"] { padding: var(--space-page) var(--space-inset); }\n  .card { border-radius: var(--radius-container); corner-shape: var(--corner-shape); }\n  .tray { height: 232px; padding: var(--space-inset) var(--space-comfort) 0; }\n  .cardBody { padding: var(--space-section); }\n  .note { padding-left: var(--space-tight); }\n}\n@container newsletter (max-width: 400px) {\n  .minutes { display: none; }\n  /* The recipient matters more than the date once the issue is addressed. */\n  .issueMeta:has(.recipient) > :not(.recipient) { display: none; }\n  .story { grid-template-columns: 44px minmax(0, 1fr); }\n  .faces img { width: 24px; height: 24px; }\n  .readers { gap: var(--space-related); }\n}\n@container newsletter (max-width: 360px) {\n  .readers { align-items: flex-start; }\n  .readerLine { min-height: calc(2 * 1.4em); white-space: normal; }\n}\n/* On narrow phones the field and the button separate and stack, both full width. */\n@container signup (max-width: 300px) {\n  .pill { height: auto; flex-direction: column; align-items: stretch; gap: var(--space-related); border: 0; padding: 0; background: none; }\n  .input { height: 52px; flex: none; border: 1px solid var(--border-strong); border-radius: var(--radius-full); corner-shape: round; padding: 0 var(--space-comfort); background: var(--surface); transition: border-color var(--duration-fast) var(--ease-standard), color var(--duration-standard) var(--ease-standard); }\n  .input:focus { border-color: var(--foreground); }\n  .pill.pill[data-invalid] .input { border-color: var(--danger); }\n  .pill.pill[data-done] .input { border-color: color-mix(in oklab, var(--success) 45%, var(--border)); }\n  .submit { height: 48px; }\n  .note { padding-left: var(--space-tight); }\n}\n\n/* Preview chrome. */\n.preview { display: grid; width: 100%; justify-items: center; gap: var(--space-inset); }\n.controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--space-group) var(--space-section); }\n.simulate { display: inline-flex; align-items: center; gap: var(--space-group); color: var(--text-secondary); font-size: var(--text-sm); }\n.simulate label { cursor: pointer; }\n.frame { width: 100%; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-control); corner-shape: var(--corner-shape); background: var(--background); }\n.caption { margin: 0; color: var(--text-muted); font-size: var(--text-xs); line-height: var(--leading-body); text-align: center; }\n\n@media (prefers-reduced-motion: reduce) {\n  .pill, .submit, .input, .issue { transition: none; }\n  .spinner { animation-duration: 1.6s; }\n}\n"},{"path":"registry/components/switch/switch.tsx","type":"registry:component","target":"@components/silicon-ui/switch/switch.tsx","content":"\"use client\";\n\nimport { forwardRef, useEffect, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, ElementRef } from \"react\";\nimport * as SwitchPrimitive from \"@radix-ui/react-switch\";\nimport { animate, motion, useMotionValue, useReducedMotion } from \"motion/react\";\nimport type { Transition } from \"motion/react\";\nimport { motionTokens } from \"../lib/motion-tokens\";\nimport styles from \"./switch.module.css\";\n\nexport interface SwitchProps extends ComponentPropsWithoutRef<typeof SwitchPrimitive.Root> {\n  label?: string;\n}\n\n/** Track inner width (42 - 6 padding) minus the 18px thumb; keep in sync with switch.module.css. */\nconst size = 18;\nconst travel = 18;\n/** How far the thumb widens toward the other side while pressed. */\nconst stretch = 5;\n/** Critically damped: the thumb lands on its end without overshooting the state it reports. */\nconst glide: Transition = { type: \"spring\", visualDuration: motionTokens.spring.fast.visualDuration, bounce: 0 };\n\nexport const Switch = forwardRef<ElementRef<typeof SwitchPrimitive.Root>, SwitchProps>(function Switch(\n  { label, className, checked, defaultChecked, onCheckedChange, onPointerDown, onPointerUp, onPointerLeave, onPointerCancel, onKeyDown, onKeyUp, onBlur, ...props },\n  ref,\n) {\n  const reduceMotion = useReducedMotion();\n  const [internal, setInternal] = useState(defaultChecked ?? false);\n  const [pressed, setPressed] = useState(false);\n  const on = checked ?? internal;\n  // A brief stretch along the travel, so the thumb reads as moving mass rather than a sliding dot.\n  const scaleX = useMotionValue(1);\n  const shown = useRef(on);\n  // A pointer or Space press already stretched the thumb, so its release should not add a second stretch on top.\n  const releasedAt = useRef(-Infinity);\n  useEffect(() => {\n    if (shown.current === on) return;\n    shown.current = on;\n    const fromPress = performance.now() - releasedAt.current < 250;\n    if (reduceMotion || fromPress) return;\n    const controls = animate(scaleX, [1, 1.16, 1], { duration: motionTokens.duration.standard, times: [0, 0.4, 1], ease: [\"easeOut\", \"easeInOut\"] });\n    return () => controls.stop();\n  }, [on, reduceMotion, scaleX]);\n  const extra = pressed && !reduceMotion && !props.disabled ? stretch : 0;\n  const classes = [styles.switch, className].filter(Boolean).join(\" \");\n\n  return (\n    <SwitchPrimitive.Root\n      {...props}\n      ref={ref}\n      checked={on}\n      onCheckedChange={next => { if (checked === undefined) setInternal(next); onCheckedChange?.(next); }}\n      onPointerDown={event => { onPointerDown?.(event); if (event.button === 0) setPressed(true); }}\n      onPointerUp={event => { onPointerUp?.(event); if (pressed && !props.disabled) releasedAt.current = performance.now(); setPressed(false); }}\n      onPointerLeave={event => { onPointerLeave?.(event); setPressed(false); }}\n      onPointerCancel={event => { onPointerCancel?.(event); setPressed(false); }}\n      onKeyDown={event => { onKeyDown?.(event); if (event.key === \" \") setPressed(true); }}\n      onKeyUp={event => { onKeyUp?.(event); if (pressed && !props.disabled) releasedAt.current = performance.now(); setPressed(false); }}\n      onBlur={event => { onBlur?.(event); setPressed(false); }}\n      className={classes}\n      aria-label={props[\"aria-label\"] ?? label}\n    >\n      <span className={styles.track}>\n        {/* The thumb stretches like a held finger and keeps its far edge anchored, then travels on a spring. */}\n        <motion.span className={styles.thumb} style={{ scaleX }} initial={false} animate={{ x: on ? travel - extra : 0, width: size + extra }} transition={reduceMotion ? { duration: 0 } : { x: glide, width: motionTokens.spring.snappy }} />\n      </span>\n      {label ? <span className={styles.label}>{label}</span> : null}\n    </SwitchPrimitive.Root>\n  );\n});\n\nSwitch.displayName = \"Switch\";\n\nexport default Switch;\n"},{"path":"registry/components/switch/switch.module.css","type":"registry:component","target":"@components/silicon-ui/switch/switch.module.css","content":".switch { display: inline-flex; min-height: var(--control-height-md); align-items: center; gap: var(--space-group); padding: 0; border: 0; color: var(--foreground); background: transparent; font: inherit; font-size: var(--text-sm); cursor: pointer; -webkit-tap-highlight-color: transparent; }\n.switch:disabled { cursor: not-allowed; opacity: .5; }\n/* Fixed box: the thumb moves inside it with transforms, so nothing around the switch shifts. The track crossfades between the two fills. */\n.track { position: relative; box-sizing: border-box; display: flex; flex: 0 0 auto; width: 42px; height: 24px; align-items: center; padding: var(--space-tight); border-radius: var(--radius-full); corner-shape: round; background: var(--control-track); isolation: isolate; transition: background-color var(--duration-fast) var(--ease-standard); }\n.track::before { content: \"\"; position: absolute; inset: 0; z-index: -1; border-radius: inherit; corner-shape: inherit; background: var(--control-on); opacity: 0; transition: opacity var(--duration-standard) var(--ease-standard); }\n.switch[data-state=\"checked\"] .track::before { opacity: 1; }\n.thumb { flex: 0 0 auto; width: 18px; height: 18px; border-radius: var(--radius-full); corner-shape: round; background: var(--control-thumb); box-shadow: var(--control-thumb-shadow); will-change: transform; transition: background-color var(--duration-standard) var(--ease-standard); }\n.switch[data-state=\"checked\"] .thumb { background: var(--control-thumb-on); }\n@media (hover: hover) and (pointer: fine) { .switch[data-state=\"unchecked\"]:hover:not(:disabled) .track { background: var(--control-track-hover); } }\n.switch:focus-visible { outline: none; }\n.label { line-height: var(--leading-body); }\n@media (prefers-reduced-motion: reduce) { .track, .track::before, .thumb { transition: none; } }\n"},{"path":"registry/components/segmented-control/segmented-control.tsx","type":"registry:component","target":"@components/silicon-ui/segmented-control/segmented-control.tsx","content":"\"use client\";\n\nimport { useEffect, useId, useLayoutEffect, useRef, type KeyboardEvent, type ReactNode } from \"react\";\nimport { LayoutGroup, motion, useReducedMotion } from \"motion/react\";\nimport { motionTokens } from \"../lib/motion-tokens\";\nimport { FluidHoverHighlight, useFluidHover } from \"../lib/fluid-hover\";\nimport styles from \"./segmented-control.module.css\";\n\nexport interface Segment { value: string; label: string; /** Optional content after the label, such as a badge. */ accessory?: ReactNode; }\nexport interface SegmentedControlProps {\n  options: Segment[];\n  value: string;\n  onValueChange: (value: string) => void;\n  label?: string;\n  /** Called when the pointer or focus reaches an option, before it is chosen. Use it to start loading what that option shows. */\n  onOptionIntent?: (value: string) => void;\n  /** `sm` (default) or `xs`, a compact 24px control for dense UI such as an Edit/Read toggle in a toolbar. */\n  size?: \"sm\" | \"xs\";\n  className?: string;\n}\n\nexport default function SegmentedControl({ options, value, onValueChange, label, onOptionIntent, size = \"sm\", className }: SegmentedControlProps) {\n  const id = useId();\n  const reduced = useReducedMotion();\n  const track = useRef<HTMLDivElement>(null);\n  // Fluid hover: the nearest option is lit and a click in a gap picks it. Focus already moves the selection, so it leaves the fill alone.\n  const hover = useFluidHover(track, { items: \"[data-value]\", axis: \"x\", followFocus: false });\n\n  // When the options are wider than the container, the track scrolls inside itself. Edges fade only on the side with more to see.\n  useLayoutEffect(() => {\n    const node = track.current;\n    if (!node) return;\n    const edges = () => {\n      const rest = node.scrollWidth - node.clientWidth - node.scrollLeft;\n      node.toggleAttribute(\"data-fade-start\", node.scrollLeft > 1);\n      node.toggleAttribute(\"data-fade-end\", rest > 1);\n    };\n    edges();\n    node.addEventListener(\"scroll\", edges, { passive: true });\n    const observer = typeof ResizeObserver === \"undefined\" ? null : new ResizeObserver(edges);\n    observer?.observe(node);\n    return () => { node.removeEventListener(\"scroll\", edges); observer?.disconnect(); };\n  }, [options.length]);\n\n  // The selected option is always scrolled fully into view, with a little room so it clears the fade.\n  const first = useRef(true);\n  useEffect(() => {\n    const node = track.current;\n    const button = node?.querySelector<HTMLElement>('[aria-pressed=\"true\"]');\n    if (!node || !button || node.scrollWidth <= node.clientWidth) { first.current = false; return; }\n    const room = 20, start = button.offsetLeft - room, end = button.offsetLeft + button.offsetWidth + room - node.clientWidth;\n    const left = node.scrollLeft > start ? start : node.scrollLeft < end ? end : node.scrollLeft;\n    if (left !== node.scrollLeft) node.scrollTo({ left: Math.max(0, left), behavior: first.current || reduced ? \"auto\" : \"smooth\" });\n    first.current = false;\n  }, [value, reduced]);\n\n  // Arrow keys, Home and End move the selection like a tab list; only the selected option is a tab stop.\n  const selectedIndex = Math.max(0, options.findIndex(option => option.value === value));\n  const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n    const last = options.length - 1;\n    const target = event.key === \"ArrowRight\" || event.key === \"ArrowDown\" ? (selectedIndex === last ? 0 : selectedIndex + 1)\n      : event.key === \"ArrowLeft\" || event.key === \"ArrowUp\" ? (selectedIndex === 0 ? last : selectedIndex - 1)\n        : event.key === \"Home\" ? 0 : event.key === \"End\" ? last : -1;\n    if (target < 0 || !options[target]) return;\n    event.preventDefault();\n    onValueChange(options[target].value);\n    track.current?.querySelector<HTMLElement>(`[data-value=\"${CSS.escape(options[target].value)}\"]`)?.focus({ preventScroll: true });\n  };\n\n  return <div className={`${styles.root} ${className ?? \"\"}`} role=\"group\" aria-label={label} data-size={size}>\n    <LayoutGroup id={id}><motion.div ref={track} layoutScroll className={styles.track} {...hover.handlers}>\n      <FluidHoverHighlight hover={hover} className={styles.hover} />\n      {options.map((option, index) => <button key={option.value} id={`${id}-${option.value}`} className={styles.button} type=\"button\" data-value={option.value} aria-pressed={value === option.value} tabIndex={index === selectedIndex ? 0 : -1} onClick={() => onValueChange(option.value)} onKeyDown={onKeyDown} onPointerEnter={onOptionIntent ? () => onOptionIntent(option.value) : undefined} onFocus={onOptionIntent ? () => onOptionIntent(option.value) : undefined}>\n        {value === option.value && <motion.span className={styles.selection} layoutId=\"selection\" layoutDependency={value} transition={reduced ? { duration: 0 } : motionTokens.spring.morph} aria-hidden=\"true\" />}\n        <span className={styles.label}>{option.label}{option.accessory}</span>\n      </button>)}\n    </motion.div></LayoutGroup>\n  </div>;\n}\n"},{"path":"registry/components/segmented-control/segmented-control.module.css","type":"registry:component","target":"@components/silicon-ui/segmented-control/segmented-control.module.css","content":"/* The frame can shrink below its content inside flex and grid parents; the track then scrolls inside it. */\n.root { display: inline-flex; min-width: 0; max-width: 100%; flex-shrink: 1; border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--surface-muted); }\n/* The track owns the stacking context so the gliding highlight passes under every label, not over earlier ones. */\n.track { --fade-start: 0px; --fade-end: 0px; position: relative; isolation: isolate; display: flex; min-width: 0; gap: var(--space-hair); overflow-x: auto; overscroll-behavior-x: contain; padding: var(--space-hair); border-radius: inherit; corner-shape: inherit; scrollbar-width: none; -webkit-mask-image: linear-gradient(to right, transparent, #000 var(--fade-start), #000 calc(100% - var(--fade-end)), transparent); mask-image: linear-gradient(to right, transparent, #000 var(--fade-start), #000 calc(100% - var(--fade-end)), transparent); }\n.track::-webkit-scrollbar { display: none; }\n.track[data-fade-start] { --fade-start: 20px; }\n.track[data-fade-end] { --fade-end: 20px; }\n/* Items never scale or change weight; only the highlight travels and the label color follows it. */\n.button { position: relative; flex: 0 0 auto; min-height: var(--control-height-sm); border: 0; border-radius: calc(var(--radius-control) - var(--space-hair)); padding: 0 var(--space-group); background: transparent; color: var(--text-muted); font: inherit; font-size: var(--text-sm); font-weight: var(--weight-medium); white-space: nowrap; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: color var(--duration-fast) var(--ease-standard); }\n/* The frame around the options is 2px, as in Tabs: too thin to hold the keyboard ring outside an option, so it is drawn inside. */\n.button:focus-visible { --focus-outline-offset: -3px; }\n@media (hover: hover) and (pointer: fine) { .button:hover { color: var(--foreground); } }\n.button:active, .button[aria-pressed=\"true\"] { color: var(--foreground); }\n/* The hover fill glides under the options and under the selection, so the selected option never changes on hover. */\n.hover { z-index: -1; border-radius: calc(var(--radius-control) - var(--space-hair)); corner-shape: var(--corner-shape); background: color-mix(in oklab, var(--foreground) 5%, transparent); }\n.selection { position: absolute; z-index: -1; inset: 0; border: 1px solid var(--border); border-radius: inherit; corner-shape: inherit; background: var(--surface); box-shadow: var(--shadow-resting); }\n.label { position: relative; z-index: 1; display: inline-flex; align-items: center; gap: var(--space-related); }\n/* Compact: 24px segments at the small type step. */\n.root[data-size=\"xs\"] .button { min-height: var(--control-height-xs); padding: 0 var(--space-related); font-size: var(--text-xs); }\n@media (max-width: 380px) { .button { padding: 0 var(--space-group); } }\n@media (prefers-reduced-motion: reduce) { .button { transition: none; } }\n"},{"path":"registry/components/animated-counter/animated-counter.tsx","type":"registry:component","target":"@components/silicon-ui/animated-counter/animated-counter.tsx","content":"\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { AnimatePresence, animate, motion, useInView, useMotionValue, useReducedMotion, useTransform, type MotionValue, type Variants } from \"motion/react\";\nimport { motionTokens } from \"../lib/motion-tokens\";\nimport styles from \"./animated-counter.module.css\";\n\nexport interface AnimatedCounterProps {\n  value: number; label?: string; prefix?: string; suffix?: string; decimals?: number;\n  /** Roll every digit up from zero the first time the counter scrolls into view. */\n  animateOnView?: boolean;\n  /** Formatting locale. Fixed by default so server and client render the same digits. */\n  locale?: string;\n}\n\ntype Part = { key: string; digit: number; order: number } | { key: string; text: string };\n\nconst DIGITS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];\nconst rise: Variants = { hidden: { opacity: 0, y: \"0.3em\", filter: `blur(${motionTokens.blur.soft}px)` }, shown: { opacity: 1, y: 0, filter: \"blur(0px)\", transition: { duration: motionTokens.duration.standard, ease: [...motionTokens.ease.enter] } }, gone: { opacity: 0, y: \"-0.3em\", filter: `blur(${motionTokens.blur.subtle}px)`, transition: { duration: motionTokens.duration.fast, ease: [...motionTokens.ease.standard] } } };\nconst fade: Variants = { hidden: { opacity: 0, y: 0, filter: \"blur(0px)\" }, shown: { opacity: 1, y: 0, filter: \"blur(0px)\", transition: { duration: motionTokens.duration.instant } }, gone: { opacity: 0, y: 0, filter: \"blur(0px)\", transition: { duration: motionTokens.duration.instant } } };\nconst reveal = { ...motionTokens.spring.smooth, visualDuration: motionTokens.duration.expressive };\n\n/** Split a formatted number into columns keyed by place value, so 999 → 1,000 keeps the ones column the ones column. */\nfunction partsFor(value: number, decimals: number, locale: string): Part[] {\n  const parts = new Intl.NumberFormat(locale, { minimumFractionDigits: decimals, maximumFractionDigits: decimals, numberingSystem: \"latn\" }).formatToParts(value);\n  let place = parts.reduce((count, part) => count + (part.type === \"integer\" ? part.value.length : 0), 0);\n  let fraction = 0;\n  let order = 0;\n  return parts.flatMap((part, index): Part[] => {\n    if (part.type === \"integer\") return [...part.value].map(char => ({ key: `i${--place}`, digit: Number(char), order: order++ }));\n    if (part.type === \"fraction\") return [...part.value].map(char => ({ key: `f${fraction++}`, digit: Number(char), order: order++ }));\n    return [{ key: part.type === \"group\" ? `g${place}` : part.type === \"decimal\" ? \"d\" : `${part.type}${index}`, text: part.value }];\n  });\n}\n\n/** One digit on the wheel. Its offset from the wheel position decides where it sits and how visible it is. */\nfunction Glyph({ position, digit }: { position: MotionValue<number>; digit: number }) {\n  const offset = useTransform(position, current => ((((digit - current) % 10) + 15) % 10) - 5);\n  const y = useTransform(offset, current => `${current}em`);\n  const opacity = useTransform(offset, current => Math.max(0, 1 - Math.abs(current)));\n  const visibility = useTransform(offset, current => Math.abs(current) >= 1 ? \"hidden\" : \"visible\");\n  const filter = useTransform(offset, current => Math.abs(current) < .02 || Math.abs(current) >= 1 ? \"none\" : `blur(${(Math.abs(current) * motionTokens.blur.subtle).toFixed(2)}px)`);\n  return <motion.span className={styles.glyph} style={{ y, opacity, filter, visibility }}>{digit}</motion.span>;\n}\n\nconst presence = { initial: { width: 0, opacity: 0 }, animate: { width: \"auto\", opacity: 1 }, exit: { width: 0, opacity: 0 } };\n\n/** A digit wheel. It always turns in the direction the whole number moved, wrapping 9 → 0 like an odometer. */\nfunction Column({ digit, direction, armed, delay, reduceMotion }: { digit: number; direction: number; armed: boolean; delay: number; reduceMotion: boolean }) {\n  const position = useMotionValue(armed ? 0 : digit);\n  const wheel = useRef({ digit: armed ? 0 : digit, target: armed ? 0 : digit, revealed: !armed });\n  useEffect(() => {\n    const state = wheel.current;\n    if (armed || state.digit === digit) { if (!armed) state.revealed = true; return; }\n    state.target += direction < 0 && state.revealed ? -((state.digit - digit + 10) % 10) : (digit - state.digit + 10) % 10;\n    state.digit = digit;\n    if (reduceMotion) position.jump(state.target);\n    else animate(position, state.target, state.revealed ? motionTokens.spring.smooth : { ...reveal, delay });\n    state.revealed = true;\n  }, [armed, delay, digit, direction, position, reduceMotion]);\n  return <motion.span className={styles.column} {...presence} transition={reduceMotion ? { duration: 0 } : motionTokens.spring.morph}>\n    <span className={styles.sizer}>0</span>\n    {DIGITS.map(item => <Glyph key={item} position={position} digit={item} />)}\n  </motion.span>;\n}\n\nexport function AnimatedCounter({ value, label, prefix = \"\", suffix = \"\", decimals = 0, animateOnView = false, locale = \"en-US\" }: AnimatedCounterProps) {\n  const ref = useRef<HTMLSpanElement>(null);\n  const inView = useInView(ref, { once: true, amount: .6 });\n  const reduceMotion = !!useReducedMotion();\n  const [previous, setPrevious] = useState(value);\n  const [direction, setDirection] = useState(1);\n  if (value !== previous) { setPrevious(value); setDirection(value > previous ? 1 : -1); }\n  const parts = partsFor(value, decimals, locale);\n  const text = `${prefix}${parts.map(part => \"text\" in part ? part.text : part.digit).join(\"\")}${suffix}`;\n  const armed = animateOnView && !inView;\n  return <span ref={ref} className={styles.counter}>\n    {label && <span className={styles.label}><span className={styles.labelSwap}><AnimatePresence mode=\"popLayout\" initial={false}><motion.span key={label} className={styles.labelText} variants={reduceMotion ? fade : rise} initial=\"hidden\" animate=\"shown\" exit=\"gone\">{label}</motion.span></AnimatePresence></span></span>}\n    <span className={styles.srOnly}>{text}</span>\n    <span className={styles.value} aria-hidden=\"true\">\n      {prefix && <span className={styles.symbol}>{prefix}</span>}\n      <AnimatePresence initial={false}>\n        {parts.map(part => \"digit\" in part\n          ? <Column key={part.key} digit={part.digit} direction={direction} armed={armed} delay={Math.min(part.order * motionTokens.stagger.item, .25)} reduceMotion={reduceMotion} />\n          : <motion.span key={part.key} className={styles.symbol} {...presence} transition={reduceMotion ? { duration: 0 } : motionTokens.spring.morph}>{part.text}</motion.span>)}\n      </AnimatePresence>\n      {suffix && <span className={styles.symbol}>{suffix}</span>}\n    </span>\n  </span>;\n}\n\nexport default AnimatedCounter;\n"},{"path":"registry/components/animated-counter/animated-counter.module.css","type":"registry:component","target":"@components/silicon-ui/animated-counter/animated-counter.module.css","content":".counter { position: relative; display: inline-flex; flex-direction: column; color: var(--foreground); font-family: var(--font-display); font-size: var(--text-3xl); font-weight: var(--weight-medium); letter-spacing: var(--tracking-display); line-height: 1; font-variant-numeric: tabular-nums; }\n.label { margin-bottom: var(--space-related); color: var(--text-muted); font-family: var(--font-body); font-size: var(--text-xs); font-weight: var(--weight-regular); letter-spacing: var(--tracking-body); line-height: var(--leading-body); }\n/* Each digit is a clipped wheel; separators clip sideways only so a comma keeps its tail. */\n.value { display: inline-flex; align-items: flex-start; white-space: nowrap; user-select: none; }\n/* The wheel's window reaches a little past the line box and feathers out, so a turning digit fades at the edge instead of being cut. */\n.column { --feather: .16em; position: relative; display: inline-block; overflow: hidden; margin-block: calc(var(--feather) * -1); padding-block: var(--feather); mask-image: linear-gradient(to bottom, transparent, #000 calc(var(--feather) * 1.5), #000 calc(100% - var(--feather) * 1.5), transparent); }\n.sizer { visibility: hidden; }\n.glyph { position: absolute; inset: var(--feather) 0; text-align: center; }\n.labelText { display: inline-block; }\n.labelSwap { position: relative; display: block; }\n.symbol { display: inline-block; overflow-x: clip; }\n.srOnly { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n"},{"path":"lib/fluid-hover.tsx","type":"registry:lib","target":"@components/silicon-ui/lib/fluid-hover.tsx","content":"\"use client\";\n\n/**\n * Fluid hover: in a set of items (a menu, a list, tabs, a grid), the item nearest the pointer is lit, even while the\n * pointer is in a gap, the padding or past the last item, and one highlight springs between items. A click in a gap goes\n * to the lit item, so what is lit is what a click hits. A new pointer entry fades the highlight in where it lands instead\n * of sliding it over from the last item. The keyboard moves it without travel, and reduced motion keeps the fade but\n * drops the travel.\n *\n *   const list = useRef<HTMLUListElement>(null);\n *   const hover = useFluidHover(list, { items: \"[data-item]\" });\n *   <ul ref={list} className={styles.list} {...hover.handlers}>      // .list { position: relative }\n *     <FluidHoverHighlight hover={hover} className={styles.highlight} />\n *     …items…\n *   </ul>\n *\n * Adapted from Fluid Functionalism's use-fluid-hover and fluid-hover-highlight by Micka Touillaud (MIT),\n * https://github.com/mickadesign/fluid-functionalism. Items are found by a selector instead of registering themselves,\n * so a component adopts it without changing its items.\n */\nimport { useEffect, useEffectEvent, useRef, useState } from \"react\";\nimport type { FocusEvent, MouseEvent, PointerEvent, RefObject } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { motionTokens } from \"./motion-tokens\";\n\n/** An item's box in the container's own layout space (unaffected by transforms or scrolling). */\nexport interface FluidRect { top: number; left: number; width: number; height: number }\n\nexport interface FluidHoverState {\n  /** Where the highlight sits, or null when nothing is lit. */\n  rect: FluidRect | null;\n  /** The lit item. */\n  item: HTMLElement | null;\n  /** False when the highlight should jump (keyboard, a resize) rather than travel. */\n  glide: boolean;\n  /** Steps on each new pointer entry, so the highlight fades in where it lands. */\n  session: number;\n}\n\nexport interface FluidHoverOptions {\n  /** Selector for the items inside the container. */\n  items: string;\n  /** \"y\" for lists (default), \"x\" for a row of tabs, \"xy\" for grids. */\n  axis?: \"x\" | \"y\" | \"xy\";\n  /** Items the highlight skips (and a gap click never activates). Defaults to disabled or aria-disabled items. */\n  isItemDisabled?: (item: HTMLElement) => boolean;\n  /** \"skip\" (default) lights the nearest enabled item even over a disabled one; \"clear\" lights nothing over a disabled item (a calendar's unavailable days). */\n  disabled?: \"skip\" | \"clear\";\n  /** Route a click in a gap to the lit item. On by default; turn it off where empty space should stay inert. */\n  gapClick?: boolean;\n  /** Light the item that receives keyboard focus. On by default. */\n  followFocus?: boolean;\n}\n\nconst defaultDisabled = (item: HTMLElement) =>\n  item.matches(\":disabled, [aria-disabled='true'], [data-disabled]\");\n\n/** Controls that sit between items keep their own clicks. */\nconst CONTROL = \"input, textarea, select, button, a, summary, [contenteditable], [role='textbox'], [role='searchbox'], [role='button']\";\n\n/** The item's box relative to the container, summing offsets through positioned ancestors in between. */\nexport function rectOf(item: HTMLElement, container: HTMLElement): FluidRect {\n  let top = item.offsetTop, left = item.offsetLeft;\n  let parent = item.offsetParent as HTMLElement | null;\n  while (parent && parent !== container && container.contains(parent)) {\n    top += parent.offsetTop + parent.clientTop;\n    left += parent.offsetLeft + parent.clientLeft;\n    parent = parent.offsetParent as HTMLElement | null;\n  }\n  return { top, left, width: item.offsetWidth, height: item.offsetHeight };\n}\n\n/**\n * The item the pointer is inside, or else the one whose edge is nearest along the axis (both axes for a grid). Edges, not\n * centres, so a gap next to a wide item still lights the item the pointer is closer to.\n */\nexport function pickNearest(items: HTMLElement[], x: number, y: number, axis: \"x\" | \"y\" | \"xy\"): HTMLElement | null {\n  let nearest: HTMLElement | null = null, best = Infinity;\n  for (const item of items) {\n    const r = item.getBoundingClientRect();\n    if (!r.width && !r.height) continue;\n    if (x >= r.left && x <= r.right && y >= r.top && y <= r.bottom) return item;\n    const dx = Math.max(r.left - x, 0, x - r.right), dy = Math.max(r.top - y, 0, y - r.bottom);\n    const distance = axis === \"x\" ? dx : axis === \"y\" ? dy : Math.hypot(dx, dy);\n    if (distance < best) { best = distance; nearest = item; }\n  }\n  return nearest;\n}\n\n/** Hands a gap click to the item as a real mouse click (detail, modifiers and coordinates kept), so the item reads it as a pointer press, not a keyboard one. */\nfunction forwardClick(item: HTMLElement, event: MouseEvent<HTMLElement>) {\n  const { detail, clientX, clientY, screenX, screenY, ctrlKey, shiftKey, altKey, metaKey, button, buttons } = event;\n  item.dispatchEvent(new globalThis.MouseEvent(\"click\", { bubbles: true, cancelable: true, composed: true, view: window, detail, clientX, clientY, screenX, screenY, ctrlKey, shiftKey, altKey, metaKey, button, buttons }));\n}\n\n/** Whether an event happened inside the element whose handler hears it, not in a portalled child (a submenu, a tooltip). */\nconst isOwn = (event: { currentTarget: EventTarget; target: EventTarget }) =>\n  !(event.currentTarget instanceof Node) || !(event.target instanceof Node) || event.currentTarget.contains(event.target);\n\nexport function useFluidHover<T extends HTMLElement>(container: RefObject<T | null>, options: FluidHoverOptions) {\n  const { items: selector, axis = \"y\", isItemDisabled = defaultDisabled, disabled = \"skip\", gapClick = true, followFocus = true } = options;\n  const [state, setState] = useState<FluidHoverState>({ rect: null, item: null, glide: false, session: 0 });\n  const current = useRef(state);\n  const pointer = useRef(false);\n  const entering = useRef(false);\n  const frame = useRef(0);\n\n  function commit(next: FluidHoverState) {\n    const prev = current.current;\n    if (prev.item === next.item && prev.session === next.session && sameRect(prev.rect, next.rect)) return;\n    current.current = next;\n    setState(next);\n  }\n\n  function light(item: HTMLElement | null, glide: boolean) {\n    const root = container.current;\n    if (!root || !item) return commit({ ...current.current, rect: null, item: null, glide });\n    let session = current.current.session;\n    if (entering.current) { entering.current = false; session += 1; }\n    commit({ rect: rectOf(item, root), item, glide: glide && session === current.current.session, session });\n  }\n\n  const enabledItems = () => {\n    const root = container.current;\n    return root ? [...root.querySelectorAll<HTMLElement>(selector)].filter(item => !isItemDisabled(item)) : [];\n  };\n\n  // The lit item can move under a still highlight (a resize, content above it changing): follow it without travel.\n  const follow = useEffectEvent(() => { const { item } = current.current; if (item?.isConnected) light(item, false); });\n  useEffect(() => {\n    const root = container.current;\n    if (!root || typeof ResizeObserver === \"undefined\") return;\n    const observer = new ResizeObserver(() => follow());\n    observer.observe(root);\n    return () => observer.disconnect();\n  }, [container]);\n  useEffect(() => () => cancelAnimationFrame(frame.current), []);\n\n  const handlers = {\n    onMouseEnter: () => { entering.current = true; },\n    onMouseMove: (event: MouseEvent<T>) => {\n      if (!isOwn(event)) return;\n      pointer.current = true;\n      const { clientX, clientY } = event;\n      cancelAnimationFrame(frame.current);\n      frame.current = requestAnimationFrame(() => {\n        const over = disabled === \"clear\" ? document.elementFromPoint(clientX, clientY)?.closest<HTMLElement>(selector) : null;\n        light(over && isItemDisabled(over) ? null : pickNearest(enabledItems(), clientX, clientY, axis), true);\n      });\n    },\n    onMouseLeave: () => { cancelAnimationFrame(frame.current); entering.current = false; light(null, false); },\n    onKeyDownCapture: () => { pointer.current = false; },\n    onFocus: (event: FocusEvent<T>) => {\n      if (!followFocus || pointer.current || !isOwn(event)) return;\n      const item = event.target instanceof HTMLElement ? event.target.closest<HTMLElement>(selector) : null;\n      if (item && container.current?.contains(item) && !isItemDisabled(item)) light(item, false);\n    },\n    onBlur: (event: FocusEvent<T>) => {\n      if (!pointer.current && !event.currentTarget.contains(event.relatedTarget as Node | null)) light(null, false);\n    },\n    onClick: (event: MouseEvent<T>) => {\n      if (!gapClick || !isOwn(event)) return;\n      const target = event.target as Element;\n      if (!target.isConnected || target.closest(selector) || target.closest(CONTROL)) return;\n      const { item } = current.current;\n      if (item?.isConnected && !isItemDisabled(item)) forwardClick(item, event);\n    },\n  };\n\n  /** Clears the highlight at once, such as when a menu opens again. */\n  const reset = () => { cancelAnimationFrame(frame.current); entering.current = true; light(null, false); };\n\n  return { ...state, handlers, reset, light };\n}\n\nexport interface NearestItemOptions extends Omit<FluidHoverOptions, \"followFocus\"> {\n  /** Called with the nearest enabled item as the mouse moves over the container. */\n  onPick: (item: HTMLElement) => void;\n}\n\n/**\n * Fluid hover's picking without its highlight, for a list that already keeps its own active item and highlight (a listbox\n * with aria-activedescendant, a roving list): the mouse picks the nearest enabled item, gaps and padding included, and a\n * click in a gap goes to that item. Spread the result on the container.\n */\n// A hook only so callbacks that touch refs can be passed during render; it keeps no state.\nexport function useNearestItem<T extends HTMLElement>({ items: selector, axis = \"y\", isItemDisabled = defaultDisabled, gapClick = true, onPick }: NearestItemOptions) {\n  const nearest = (event: MouseEvent<T>) => {\n    if (!isOwn(event)) return null;\n    const items = [...event.currentTarget.querySelectorAll<HTMLElement>(selector)].filter(item => !isItemDisabled(item));\n    return pickNearest(items, event.clientX, event.clientY, axis);\n  };\n  return {\n    onPointerMove: (event: PointerEvent<T>) => { if (event.pointerType !== \"mouse\") return; const item = nearest(event); if (item) onPick(item); },\n    onClick: (event: MouseEvent<T>) => {\n      if (!gapClick) return;\n      const target = event.target as Element;\n      if (!target.isConnected || target.closest(selector) || target.closest(CONTROL)) return;\n      const item = nearest(event);\n      if (item) forwardClick(item, event);\n    },\n  };\n}\n\nconst sameRect = (a: FluidRect | null, b: FluidRect | null) =>\n  a === b || (!!a && !!b && a.top === b.top && a.left === b.left && a.width === b.width && a.height === b.height);\n\nexport interface FluidHoverHighlightProps {\n  /** The state from useFluidHover (or any { rect, glide, session }). */\n  hover: Pick<FluidHoverState, \"rect\" | \"glide\" | \"session\">;\n  /** Radius, fill, z-index. The container must be position: relative; the highlight is placed at its top-left corner. */\n  className?: string;\n  /** Extra attributes for styling, such as data-tone. */\n  tone?: string;\n}\n\n/** The one highlight a fluid hover set renders: it springs between items on transforms, and fades in and out. */\nexport function FluidHoverHighlight({ hover, className, tone }: FluidHoverHighlightProps) {\n  const reduced = useReducedMotion() ?? false;\n  const { rect, glide, session } = hover;\n  const place = rect ? { x: rect.left, y: rect.top, width: rect.width, height: rect.height } : undefined;\n  return (\n    <AnimatePresence initial={false}>\n      {place ? (\n        <motion.span key={session} className={className} data-tone={tone} aria-hidden=\"true\"\n          style={{ position: \"absolute\", top: 0, left: 0, pointerEvents: \"none\" }}\n          initial={{ opacity: 0, ...place }}\n          animate={{ opacity: 1, ...place }}\n          exit={{ opacity: 0, transition: motionTokens.spring.fast.exit }}\n          transition={{ default: glide && !reduced ? motionTokens.spring.fast : { duration: 0 }, opacity: { duration: motionTokens.duration.fast } }} />\n      ) : null}\n    </AnimatePresence>\n  );\n}\n"}],"docs":"Docs and live preview: https://ui.teamofsilicons.com/newsletter-signup","meta":{"tier":"free","kind":"block","docs":"https://ui.teamofsilicons.com/newsletter-signup","markdown":"https://ui.teamofsilicons.com/newsletter-signup.md","status":"stable"}}